当前位置: 首页>>代码示例>>C#>>正文


C# Random.NextEthernetLayer方法代码示例

本文整理汇总了C#中System.Random.NextEthernetLayer方法的典型用法代码示例。如果您正苦于以下问题:C# Random.NextEthernetLayer方法的具体用法?C# Random.NextEthernetLayer怎么用?C# Random.NextEthernetLayer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Random的用法示例。


在下文中一共展示了Random.NextEthernetLayer方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RandomEthernetTest

        public void RandomEthernetTest()
        {
            Random random = new Random();

            for (int i = 0; i != 1000; ++i)
            {
                EthernetLayer ethernetLayer = random.NextEthernetLayer();
                int ethernetPayloadLength = random.Next(1500);
                PayloadLayer payloadLayer = new PayloadLayer
                                                {
                                                    Data = random.NextDatagram(ethernetPayloadLength),
                                                };
                Packet packet = PacketBuilder.Build(DateTime.Now, ethernetLayer, payloadLayer);

                // Ethernet
                Assert.IsTrue(new[] {EthernetType.IpV4, EthernetType.Arp, EthernetType.VLanTaggedFrame}.Contains(packet.Ethernet.EtherType) ||
                              packet.IsValid, "IsValid - EtherType = " + packet.Ethernet.EtherType);
                Assert.AreEqual(packet.Length - EthernetDatagram.HeaderLengthValue, packet.Ethernet.PayloadLength, "PayloadLength");
                Assert.AreEqual(ethernetLayer, packet.Ethernet.ExtractLayer(), "Ethernet Layer");
                Assert.AreEqual(ethernetLayer.GetHashCode(), packet.Ethernet.ExtractLayer().GetHashCode(), "Ethernet Layer Hash Code");
                Assert.AreNotEqual(random.NextEthernetLayer().GetHashCode(), packet.Ethernet.ExtractLayer().GetHashCode(), "Ethernet Layer Hash Code");
                Assert.AreEqual(ethernetLayer.ToString(), packet.Ethernet.ExtractLayer().ToString(), "Ethernet Layer ToString()");
                Assert.AreNotEqual(random.NextEthernetLayer().ToString(), packet.Ethernet.ExtractLayer().ToString(), "Ethernet Layer ToString()");
                Assert.AreNotEqual(2, packet.Ethernet.Source, "Ethernet Source");

                Assert.AreEqual(payloadLayer.Data, packet.Ethernet.Payload);
            }
        }
开发者ID:shrknt35,项目名称:sonarlint-vs,代码行数:28,代码来源:EthernetTests.cs

示例2: RandomVLanTaggedFrameTest

        public void RandomVLanTaggedFrameTest()
        {
            Random random = new Random();

            for (int i = 0; i != 1000; ++i)
            {
                EthernetLayer ethernetLayer = random.NextEthernetLayer(EthernetType.None);
                VLanTaggedFrameLayer vLanTaggedFrameLayer = random.NextVLanTaggedFrameLayer();
                int payloadLength = random.Next(1500);
                PayloadLayer payloadLayer = new PayloadLayer
                {
                    Data = random.NextDatagram(payloadLength),
                };
                Packet packet = PacketBuilder.Build(DateTime.Now, ethernetLayer, vLanTaggedFrameLayer, payloadLayer);

                ethernetLayer.EtherType = EthernetType.VLanTaggedFrame;

                // Test output.
                Assert.AreEqual(ethernetLayer, packet.Ethernet.ExtractLayer());
                Assert.AreEqual(vLanTaggedFrameLayer, packet.Ethernet.VLanTaggedFrame.ExtractLayer());
                Assert.AreEqual(vLanTaggedFrameLayer.GetHashCode(), packet.Ethernet.VLanTaggedFrame.ExtractLayer().GetHashCode());
                Assert.AreNotEqual(random.NextVLanTaggedFrameLayer().GetHashCode(), packet.Ethernet.VLanTaggedFrame.ExtractLayer().GetHashCode());
                Assert.AreEqual(vLanTaggedFrameLayer.TagControlInformation, packet.Ethernet.VLanTaggedFrame.TagControlInformation);
                Assert.AreEqual(payloadLayer.Data, packet.Ethernet.VLanTaggedFrame.Payload);
            }
        }
开发者ID:amitla,项目名称:Pcap.Net,代码行数:26,代码来源:VLanTaggedFrameTests.cs

示例3: DontAutoSetEthernetDestinationTest

        public void DontAutoSetEthernetDestinationTest()
        {
            Random random = new Random();
            EthernetLayer ethernetLayer = random.NextEthernetLayer(EthernetType.None);
            ethernetLayer.Destination = MacAddress.Zero;
            VLanTaggedFrameLayer vLanTaggedFrameLayer = random.NextVLanTaggedFrameLayer();
            Packet packet = PacketBuilder.Build(DateTime.Now, ethernetLayer, vLanTaggedFrameLayer);

            ethernetLayer.EtherType = EthernetType.VLanTaggedFrame;

            // Test equality.
            Assert.AreEqual(ethernetLayer, packet.Ethernet.ExtractLayer());
            Assert.AreEqual(vLanTaggedFrameLayer, packet.Ethernet.VLanTaggedFrame.ExtractLayer());
        }
开发者ID:JackWangCUMT,项目名称:WiFiSpy,代码行数:14,代码来源:VLanTaggedFrameTests.cs

示例4: AutoSetEtherTypeTest

        public void AutoSetEtherTypeTest()
        {
            Random random = new Random();
            EthernetLayer ethernetLayer = random.NextEthernetLayer(EthernetType.None);
            VLanTaggedFrameLayer vLanTaggedFrameLayer = random.NextVLanTaggedFrameLayer(EthernetType.None);
            IpV4Layer ipV4Layer = random.NextIpV4Layer();
            Packet packet = PacketBuilder.Build(DateTime.Now, ethernetLayer, vLanTaggedFrameLayer, ipV4Layer);

            ethernetLayer.EtherType = EthernetType.VLanTaggedFrame;
            vLanTaggedFrameLayer.EtherType = EthernetType.IpV4;

            // Test equality.
            Assert.AreEqual(ethernetLayer, packet.Ethernet.ExtractLayer());
            Assert.AreEqual(EthernetType.IpV4, packet.Ethernet.VLanTaggedFrame.EtherType);
            Assert.AreEqual(vLanTaggedFrameLayer, packet.Ethernet.VLanTaggedFrame.ExtractLayer());
            ipV4Layer.HeaderChecksum = packet.Ethernet.VLanTaggedFrame.IpV4.HeaderChecksum;
            Assert.AreEqual(ipV4Layer, packet.Ethernet.VLanTaggedFrame.IpV4.ExtractLayer());
        }
开发者ID:amitla,项目名称:Pcap.Net,代码行数:18,代码来源:VLanTaggedFrameTests.cs

示例5: RandomHttpTest

        public void RandomHttpTest()
        {
            int seed = new Random().Next();
            Console.WriteLine("Seed: " + seed);
            Random random = new Random(seed);

            for (int i = 0; i != 200; ++i)
            {
                EthernetLayer ethernetLayer = random.NextEthernetLayer(EthernetType.None);
                IpV4Layer ipV4Layer = random.NextIpV4Layer(null);
                ipV4Layer.HeaderChecksum = null;
                Layer ipLayer = random.NextBool() ? (Layer)ipV4Layer : random.NextIpV6Layer(true);
                TcpLayer tcpLayer = random.NextTcpLayer();
                tcpLayer.Checksum = null;
                HttpLayer httpLayer = random.NextHttpLayer();

                Packet packet = PacketBuilder.Build(DateTime.Now, ethernetLayer, ipLayer, tcpLayer, httpLayer);
                Assert.IsTrue(packet.IsValid, "IsValid");

                HttpDatagram httpDatagram = packet.Ethernet.Ip.Tcp.Http;
                Assert.AreEqual(httpLayer.Version, httpDatagram.Version);
                if (httpLayer.Version != null)
                    Assert.AreEqual(httpLayer.Version.GetHashCode(), httpDatagram.Version.GetHashCode());
                if (httpLayer is HttpRequestLayer)
                {
                    Assert.IsTrue(httpDatagram.IsRequest);
                    Assert.IsTrue(httpLayer.IsRequest);
                    Assert.IsFalse(httpDatagram.IsResponse);
                    Assert.IsFalse(httpLayer.IsResponse);

                    HttpRequestLayer httpRequestLayer = (HttpRequestLayer)httpLayer;
                    HttpRequestDatagram httpRequestDatagram = (HttpRequestDatagram)httpDatagram;
                    Assert.AreEqual(httpRequestLayer.Method, httpRequestDatagram.Method);
                    if (httpRequestLayer.Method != null)
                    {
                        Assert.AreEqual(httpRequestLayer.Method.GetHashCode(), httpRequestDatagram.Method.GetHashCode());
                        Assert.AreEqual(httpRequestLayer.Method.KnownMethod, httpRequestDatagram.Method.KnownMethod);
                    }
                    Assert.AreEqual(httpRequestLayer.Uri, httpRequestDatagram.Uri);
                }
                else
                {
                    Assert.IsFalse(httpDatagram.IsRequest);
                    Assert.IsFalse(httpLayer.IsRequest);
                    Assert.IsTrue(httpDatagram.IsResponse);
                    Assert.IsTrue(httpLayer.IsResponse);

                    HttpResponseLayer httpResponseLayer = (HttpResponseLayer)httpLayer;
                    HttpResponseDatagram httpResponseDatagram = (HttpResponseDatagram)httpDatagram;
                    Assert.AreEqual(httpResponseLayer.StatusCode, httpResponseDatagram.StatusCode);
                    Assert.AreEqual(httpResponseLayer.ReasonPhrase, httpResponseDatagram.ReasonPhrase);
                }
                Assert.AreEqual(httpLayer.Header, httpDatagram.Header);
                if (httpLayer.Header != null)
                {
                    Assert.AreEqual(httpLayer.Header.GetHashCode(), httpDatagram.Header.GetHashCode());

                    foreach (var field in httpLayer.Header)
                        Assert.IsFalse(field.Equals("abc"));
                    foreach (var field in (IEnumerable)httpLayer.Header)
                        Assert.IsFalse(field.Equals("abc"));

                    MoreAssert.AreSequenceEqual(httpLayer.Header.Select(field => field.GetHashCode()), httpDatagram.Header.Select(field => field.GetHashCode()));

                    if (httpLayer.Header.ContentType != null)
                    {
                        var parameters = httpLayer.Header.ContentType.Parameters;
                        Assert.IsNotNull(((IEnumerable)parameters).GetEnumerator());
                        Assert.AreEqual<object>(parameters, httpDatagram.Header.ContentType.Parameters);
                        Assert.AreEqual(parameters.GetHashCode(), httpDatagram.Header.ContentType.Parameters.GetHashCode());
                        Assert.AreEqual(parameters.Count, httpDatagram.Header.ContentType.Parameters.Count);
                        int maxParameterNameLength = parameters.Any() ? parameters.Max(pair => pair.Key.Length) : 0;
                        Assert.IsNull(parameters[new string('a', maxParameterNameLength + 1)]);
                    }
                }
                Assert.AreEqual(httpLayer.Body, httpDatagram.Body);
                Assert.AreEqual(httpLayer, httpDatagram.ExtractLayer(), "HTTP Layer");
                Assert.AreEqual(httpLayer.Length, httpDatagram.Length);
            }
        }
开发者ID:JackWangCUMT,项目名称:WiFiSpy,代码行数:80,代码来源:HttpTests.cs

示例6: CreateRandomPacket

        private static Packet CreateRandomPacket(Random random)
        {
            Packet packet;
            do
            {
                DateTime packetTimestamp =
                    random.NextDateTime(PacketTimestamp.MinimumPacketTimestamp, PacketTimestamp.MaximumPacketTimestamp).ToUniversalTime().ToLocalTime();

                List<ILayer> layers = new List<ILayer>();
                EthernetLayer ethernetLayer = random.NextEthernetLayer();
                layers.Add(ethernetLayer);
                CreateRandomEthernetPayload(random, ethernetLayer, layers);
                packet = PacketBuilder.Build(packetTimestamp, layers);
            } while (packet.Length > 65536);
            return packet;
        }
开发者ID:rokugasenpai,项目名称:Pcap.Net,代码行数:16,代码来源:WiresharkCompareTests.cs

示例7: CreateRandomPacket

        private static Packet CreateRandomPacket(Random random)
        {
            Packet packet;
            do
            {
                // TODO. BUG: Limited timestamp due to Windows bug: https://connect.microsoft.com/VisualStudio/feedback/details/559198/net-4-datetime-tolocaltime-is-sometimes-wrong
                DateTime packetTimestamp =
                    random.NextDateTime(new DateTime(2010, 1, 1), new DateTime(2010, 12, 31)).ToUniversalTime().ToLocalTime();
                //random.NextDateTime(PacketTimestamp.MinimumPacketTimestamp, PacketTimestamp.MaximumPacketTimestamp).ToUniversalTime().ToLocalTime();

                List<ILayer> layers = new List<ILayer>();
                EthernetLayer ethernetLayer = random.NextEthernetLayer();
                layers.Add(ethernetLayer);
                CreateRandomEthernetPayload(random, ethernetLayer, layers);
                packet = PacketBuilder.Build(packetTimestamp, layers);
            } while (packet.Length > 65536);
            return packet;
        }
开发者ID:shrknt35,项目名称:sonarlint-vs,代码行数:18,代码来源:WiresharkCompareTests.cs


注:本文中的System.Random.NextEthernetLayer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。