本文整理汇总了C#中System.Random.NextVLanTaggedFrameLayer方法的典型用法代码示例。如果您正苦于以下问题:C# Random.NextVLanTaggedFrameLayer方法的具体用法?C# Random.NextVLanTaggedFrameLayer怎么用?C# Random.NextVLanTaggedFrameLayer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Random
的用法示例。
在下文中一共展示了Random.NextVLanTaggedFrameLayer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: 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());
}
示例3: 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());
}
示例4: CreateRandomEthernetPayload
private static void CreateRandomEthernetPayload(Random random, EthernetBaseLayer ethernetBaseLayer, List<ILayer> layers)
{
if (random.NextBool(20))
{
// Finish with payload.
PayloadLayer payloadLayer = random.NextPayloadLayer(random.Next(100));
layers.Add(payloadLayer);
return;
}
ethernetBaseLayer.EtherType = EthernetType.None;
switch (random.NextInt(0, 7))
{
case 0: // VLanTaggedFrame.
case 1:
VLanTaggedFrameLayer vLanTaggedFrameLayer = random.NextVLanTaggedFrameLayer();
layers.Add(vLanTaggedFrameLayer);
CreateRandomEthernetPayload(random, vLanTaggedFrameLayer, layers);
return;
case 2: // ARP.
EthernetLayer ethernetLayer = (ethernetBaseLayer as EthernetLayer);
if (ethernetLayer != null)
ethernetLayer.Destination = MacAddress.Zero;
layers.Add(random.NextArpLayer());
return;
case 3: // IPv4.
case 4:
IpV4Layer ipV4Layer = random.NextIpV4Layer();
layers.Add(ipV4Layer);
CreateRandomIpPayload(random, ipV4Layer, layers);
return;
case 5: // IPv6
case 6:
IpV6Layer ipV6Layer = random.NextIpV6Layer(random.NextBool(20));
layers.Add(ipV6Layer);
CreateRandomIpPayload(random, ipV6Layer, layers);
return;
default:
throw new InvalidOperationException("Invalid value.");
}
}