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); } }
/// <summary> /// This function build a VLanTaggedFrame over Ethernet with payload packet. /// </summary> public static Packet BuildVLanTaggedFramePacket() { EthernetLayer ethernetLayer = new EthernetLayer { Source = new MacAddress(macAddressSource), Destination = new MacAddress("F4:06:69:06:DC:EF"), EtherType = EthernetType.None, // Will be filled automatically. }; VLanTaggedFrameLayer vLanTaggedFrameLayer = new VLanTaggedFrameLayer { PriorityCodePoint = ClassOfService.Background, CanonicalFormatIndicator = false, VLanIdentifier = 50, EtherType = EthernetType.IpV4, }; PayloadLayer payloadLayer = new PayloadLayer { Data = new Datagram(Encoding.ASCII.GetBytes("hello world")), }; PacketBuilder builder = new PacketBuilder(ethernetLayer, vLanTaggedFrameLayer, payloadLayer); return(builder.Build(DateTime.Now)); }
public static PacketBuilder BuildVLanTaggedFramePacketBuilder(ClassOfService CoS) { EthernetLayer ethernetLayer = new EthernetLayer { Source = new MacAddress("01:01:01:01:01:01"), Destination = new MacAddress("90:1B:0E:1B:DD:E8"), EtherType = EthernetType.None, // Will be filled automatically. }; VLanTaggedFrameLayer vLanTaggedFrameLayer = new VLanTaggedFrameLayer { PriorityCodePoint = CoS, CanonicalFormatIndicator = false, VLanIdentifier = 50, EtherType = (EthernetType)34962, }; PayloadLayer payloadLayer = new PayloadLayer { Data = new Datagram(new byte[1496]) }; return(new PacketBuilder(ethernetLayer, vLanTaggedFrameLayer, payloadLayer)); }
public static Packet BuildVLanTaggedFramePacket(int cyclecounter) { EthernetLayer ethernetLayer = new EthernetLayer { Source = new MacAddress("28:63:36:88:02:52"), Destination = new MacAddress("00:1b:1b:6b:6b:0e"), EtherType = EthernetType.None, // Will be filled automatically. }; VLanTaggedFrameLayer vLanTaggedFrameLayer = new VLanTaggedFrameLayer { PriorityCodePoint = ClassOfService.InternetworkControl, CanonicalFormatIndicator = false, VLanIdentifier = 50, EtherType = (EthernetType)34962, }; PayloadLayer payloadLayer = new PayloadLayer { Data = new Datagram(new byte[] { 0x80, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xFF, 0x80, 0xFF, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, Convert.ToByte((cyclecounter & 0xFF00) > 8), Convert.ToByte(cyclecounter & 0xFF), 0x35, 0x00 }) }; PacketBuilder builder = new PacketBuilder(ethernetLayer, vLanTaggedFrameLayer, payloadLayer); return(builder.Build(DateTime.Now)); }
/// <summary> /// This function build a VLanTaggedFrame over Ethernet with payload packet. /// </summary> public static Packet BuildVLanTaggedFramePacket() { EthernetLayer ethernetLayer = new EthernetLayer { Source = new MacAddress("01:01:01:01:01:01"), Destination = new MacAddress("02:02:02:02:02:02"), EtherType = EthernetType.None, // Will be filled automatically. }; VLanTaggedFrameLayer vLanTaggedFrameLayer = new VLanTaggedFrameLayer { PriorityCodePoint = ClassOfService.NetworkControl, CanonicalFormatIndicator = false, VLanIdentifier = 50, EtherType = (EthernetType)34962, }; PayloadLayer payloadLayer = new PayloadLayer { Data = new Datagram(new byte[] { 0x80, 0x6B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x35, 0x00 }) }; PacketBuilder builder = new PacketBuilder(ethernetLayer, vLanTaggedFrameLayer, payloadLayer); return(builder.Build(DateTime.Now)); }
public void SendIcmpEchoReply(IpV4Address TargetIP, MacAddress TargetMac, IcmpDatagram icmpRequest) { EthernetLayer ethernetLayer = new EthernetLayer { Source = _adapter.MAC, Destination = TargetMac, EtherType = EthernetType.None, // Will be filled automatically. }; VLanTaggedFrameLayer vlanLayer = new VLanTaggedFrameLayer { PriorityCodePoint = ClassOfService.BestEffort, CanonicalFormatIndicator = false, VLanIdentifier = _adapter.VLAN, EtherType = EthernetType.None, }; IpV4Layer ipV4Layer = new IpV4Layer { Source = _adapter.IP, CurrentDestination = TargetIP, Fragmentation = IpV4Fragmentation.None, HeaderChecksum = null, // Will be filled automatically. Identification = 123, Options = IpV4Options.None, Protocol = null, // Will be filled automatically. Ttl = 100, TypeOfService = 0, }; IcmpEchoReplyLayer icmpReplyLayer = new IcmpEchoReplyLayer { Identifier = (ushort)((icmpRequest.Variable >> 16) & 0xFFFF), SequenceNumber = (ushort)(icmpRequest.Variable & 0xFFFF), }; PayloadLayer payloadLayer = new PayloadLayer() { Data = icmpRequest.Payload }; if (_adapter.VLAN > 1) { VirtualNetwork.Instance.SendPacket(PacketBuilder.Build(DateTime.Now, ethernetLayer, vlanLayer, ipV4Layer, icmpReplyLayer, payloadLayer)); } else { VirtualNetwork.Instance.SendPacket(PacketBuilder.Build(DateTime.Now, ethernetLayer, ipV4Layer, icmpReplyLayer, payloadLayer)); } VirtualNetwork.Instance.PostTraceMessage("ICMP Reply: " + TargetIP.ToString()); }
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()); }
public void SendIcmpEcho(IpV4Address TargetIP, MacAddress TargetMac, ushort SequenceNumber) { EthernetLayer ethernetLayer = new EthernetLayer { Source = _adapter.MAC, Destination = TargetMac, EtherType = EthernetType.None, // Will be filled automatically. }; VLanTaggedFrameLayer vlanLayer = new VLanTaggedFrameLayer { PriorityCodePoint = ClassOfService.BestEffort, CanonicalFormatIndicator = false, VLanIdentifier = _adapter.VLAN, EtherType = EthernetType.None, }; IpV4Layer ipV4Layer = new IpV4Layer { Source = _adapter.IP, CurrentDestination = TargetIP, Fragmentation = IpV4Fragmentation.None, HeaderChecksum = null, // Will be filled automatically. Identification = SequenceNumber, Options = IpV4Options.None, Protocol = null, // Will be filled automatically. Ttl = 100, TypeOfService = 0, }; IcmpEchoLayer icmpLayer = new IcmpEchoLayer { SequenceNumber = SequenceNumber, Identifier = SequenceNumber, }; if (_adapter.VLAN > 1) { VirtualNetwork.Instance.SendPacket(PacketBuilder.Build(DateTime.Now, ethernetLayer, vlanLayer, ipV4Layer, icmpLayer)); } else { VirtualNetwork.Instance.SendPacket(PacketBuilder.Build(DateTime.Now, ethernetLayer, ipV4Layer, icmpLayer)); } }
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."); } }
public static PacketBuilder DISTURB(ClassOfService CoS) { EthernetLayer ethernetLayer = new EthernetLayer { Source = new MacAddress("90:1B:0E:1B:DD:D8"), //Destination = new MacAddress("28:63:36:53:b2:88"), Destination = new MacAddress("FF:FF:FF:FF:FF:FF"), EtherType = EthernetType.None, // Will be filled automatically. }; VLanTaggedFrameLayer vLanTaggedFrameLayer = new VLanTaggedFrameLayer { PriorityCodePoint = ClassOfService.NetworkControl, CanonicalFormatIndicator = false, VLanIdentifier = 00, EtherType = (EthernetType)34962, }; PayloadLayer PN = new PayloadLayer { Data = new Datagram(new byte[] { 0x80, 0x00 }) }; PayloadLayer payloadLayer1 = new PayloadLayer { Data = new Datagram(new byte[] { 0x80, 0x00 }) }; PayloadLayer payloadLayer2 = new PayloadLayer { Data = new Datagram(new byte[1294]) }; PayloadLayer payloadLayer3 = new PayloadLayer { Data = new Datagram(new byte[] { 0x10, 0x40, 0x35, 0x00 }) }; return(new PacketBuilder(ethernetLayer, vLanTaggedFrameLayer, payloadLayer1, payloadLayer2, payloadLayer3)); }
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()); }
public void SendReply(IpV4Address DesIP, MacAddress DesMac) { EthernetLayer ethernetLayer = new EthernetLayer { Destination = UtilityLib.BroadcastMac, Source = _adapter.MAC, EtherType = EthernetType.None }; VLanTaggedFrameLayer vlanLayer = new VLanTaggedFrameLayer { PriorityCodePoint = ClassOfService.BestEffort, CanonicalFormatIndicator = false, VLanIdentifier = _adapter.VLAN, EtherType = EthernetType.None, }; ArpLayer arpLayer = new ArpLayer { SenderHardwareAddress = _adapter.MAC.ToBytes().AsReadOnly(), SenderProtocolAddress = _adapter.IP.ToBytes().AsReadOnly(), TargetHardwareAddress = DesMac.ToBytes().AsReadOnly(), TargetProtocolAddress = DesIP.ToBytes().AsReadOnly(), ProtocolType = EthernetType.IpV4, Operation = ArpOperation.Reply, }; if (_adapter.VLAN > 1) { VirtualNetwork.Instance.SendPacket(PacketBuilder.Build(DateTime.Now, ethernetLayer, vlanLayer, arpLayer)); } else { VirtualNetwork.Instance.SendPacket(PacketBuilder.Build(DateTime.Now, ethernetLayer, arpLayer)); } VirtualNetwork.Instance.PostTraceMessage("ARP Reply: " + DesMac.ToString() + " - " + DesIP.ToString()); }
public static PacketBuilder DISTURB(ClassOfService CoS) { EthernetLayer ethernetLayer = new EthernetLayer { Source = new MacAddress("90:1B:0E:1B:DD:D8"), Destination = new MacAddress("FF:FF:FF:FF:FF:FF"), EtherType = EthernetType.None, // Will be filled automatically. }; VLanTaggedFrameLayer vLanTaggedFrameLayer = new VLanTaggedFrameLayer { PriorityCodePoint = CoS, CanonicalFormatIndicator = false, VLanIdentifier = 50, EtherType = EthernetType.Arp, }; ArpLayer arpLayer = new ArpLayer { ProtocolType = EthernetType.IpV4, Operation = ArpOperation.Request, SenderHardwareAddress = new byte[] { 144, 27, 14, 27, 221, 216 }.AsReadOnly(), // 68:05:ca:1e:94:1c SenderProtocolAddress = new byte[] { 10, 128, 24, 71 }.AsReadOnly(), // 1.2.3.4. TargetHardwareAddress = new byte[] { 255, 255, 255, 255, 255, 255 }.AsReadOnly(), // 04:04:04:04:04:04. TargetProtocolAddress = new byte[] { 10, 128, 24, 72 }.AsReadOnly(), // 11.22.33.44. }; PayloadLayer payloadLayer = new PayloadLayer { Data = new Datagram(new byte[1300]) }; return(new PacketBuilder(ethernetLayer, arpLayer, payloadLayer)); }
void SendTcpCtrlPacket(uint AcknowledgmentNumber, TcpControlBits CtrlBits, TcpOptions TcpOptions) { _last_acknowledgment_number = AcknowledgmentNumber; EthernetLayer ethernetLayer = new EthernetLayer { Source = _adapter.MAC, Destination = _remote_mac, EtherType = EthernetType.None, // Will be filled automatically. }; VLanTaggedFrameLayer vlanLayer = new VLanTaggedFrameLayer { PriorityCodePoint = ClassOfService.Background, CanonicalFormatIndicator = false, VLanIdentifier = _adapter.VLAN, EtherType = EthernetType.None, }; IpV4Layer ipV4Layer = new IpV4Layer { Source = _adapter.IP, CurrentDestination = _remote_ip, Fragmentation = new IpV4Fragmentation(IpV4FragmentationOptions.DoNotFragment, 0), HeaderChecksum = null, // Will be filled automatically. Identification = _current_ip_id++, Options = IpV4Options.None, Protocol = null, // Will be filled automatically. Ttl = TTL, TypeOfService = 0, }; TcpLayer tcpLayer = new TcpLayer { SourcePort = _local_port, DestinationPort = _remote_port, Checksum = null, // Will be filled automatically. SequenceNumber = _current_sequence_number, AcknowledgmentNumber = _last_acknowledgment_number, ControlBits = CtrlBits, Window = _local_tcp_window_size, UrgentPointer = 0, Options = TcpOptions }; if (_adapter.VLAN > 1) { VirtualNetwork.Instance.SendPacket(PacketBuilder.Build(DateTime.Now, ethernetLayer, vlanLayer, ipV4Layer, tcpLayer)); } else { VirtualNetwork.Instance.SendPacket(PacketBuilder.Build(DateTime.Now, ethernetLayer, ipV4Layer, tcpLayer)); } if (CtrlBits != TcpControlBits.Acknowledgment) { _current_sequence_number++; _next_ack_num = _current_sequence_number; } }
public void SendPacketInternal(byte[] data) { Packet packet = null; EthernetLayer ethernetLayer = new EthernetLayer { Source = _adapter.MAC, Destination = _remote_mac, EtherType = EthernetType.None, // Will be filled automatically. }; VLanTaggedFrameLayer vlanLayer = new VLanTaggedFrameLayer { PriorityCodePoint = ClassOfService.Background, CanonicalFormatIndicator = false, VLanIdentifier = _adapter.VLAN, EtherType = EthernetType.None, }; IpV4Layer ipV4Layer = new IpV4Layer { Source = _adapter.IP, CurrentDestination = _remote_ip, Fragmentation = new IpV4Fragmentation(IpV4FragmentationOptions.DoNotFragment, 0), HeaderChecksum = null, // Will be filled automatically. Identification = _current_ip_id++, Options = IpV4Options.None, Protocol = null, // Will be filled automatically. Ttl = TTL, TypeOfService = 0, }; TcpLayer tcpLayer = new TcpLayer { SourcePort = _local_port, DestinationPort = _remote_port, Checksum = null, // Will be filled automatically. SequenceNumber = _current_sequence_number, AcknowledgmentNumber = _last_acknowledgment_number, ControlBits = TcpControlBits.Push | TcpControlBits.Acknowledgment, Window = _local_tcp_window_size, UrgentPointer = 0, Options = TcpOptions.None }; PayloadLayer payloadLayer = new PayloadLayer(); if (data.Length > _remote_tcp_window_size) { uint offset = 0; uint data_to_send = (uint)data.Length; while (data_to_send > 0) { tcpLayer.SequenceNumber = _current_sequence_number; if (data_to_send > _remote_tcp_window_size && _remote_tcp_window_size > 0) { byte[] send_buffer = new byte[_remote_tcp_window_size]; Array.Copy(data, offset, send_buffer, 0, _remote_tcp_window_size); payloadLayer.Data = new Datagram(send_buffer); offset += _remote_tcp_window_size; _next_ack_num = _current_sequence_number + _remote_tcp_window_size; } else { byte[] send_buffer = new byte[data_to_send]; Array.Copy(data, offset, send_buffer, 0, data_to_send); payloadLayer.Data = new Datagram(send_buffer); offset += data_to_send; _next_ack_num = _current_sequence_number + data_to_send; } data_to_send = (uint)data.Length - offset - 1; if (_adapter.VLAN > 1) { packet = PacketBuilder.Build(DateTime.Now, ethernetLayer, vlanLayer, ipV4Layer, tcpLayer, payloadLayer); } else { VirtualNetwork.Instance.SendPacket(PacketBuilder.Build(DateTime.Now, ethernetLayer, ipV4Layer, tcpLayer, payloadLayer)); } } } else { _next_ack_num = _current_sequence_number + (uint)data.Length; payloadLayer.Data = new Datagram(data); if (_adapter.VLAN > 1) { VirtualNetwork.Instance.SendPacket(PacketBuilder.Build(DateTime.Now, ethernetLayer, vlanLayer, ipV4Layer, tcpLayer, payloadLayer)); } else { VirtualNetwork.Instance.SendPacket(PacketBuilder.Build(DateTime.Now, ethernetLayer, ipV4Layer, tcpLayer, payloadLayer)); } } }
private Packet BuildGoosePacket() { EthernetLayer ethernetLayer = new EthernetLayer { Source = new MacAddress((String)gooseParameters["maskedTextBox_srcMac"]), Destination = new MacAddress((String)gooseParameters["maskedTextBox_dstMac"]), EtherType = (EthernetType)0x88b8, }; VLanTaggedFrameLayer vlanLayer = new VLanTaggedFrameLayer { PriorityCodePoint = ClassOfService.Background, CanonicalFormatIndicator = false, VLanIdentifier = 50, EtherType = (EthernetType)0x88b8, }; StringToDataConverter StringToUtc = new StringToDataConverter(); UtcTime T = new UtcTime(StringToUtc.ConvertToTimeEntry(gooseParameters["textBox_Time"].ToString())); Pdu.GoID = (String)gooseParameters["textBox_GoID"]; Pdu.GocbRef = (String)gooseParameters["textBox_GoCBRef"]; Pdu.ConfRev = (long)Convert.ToDecimal(gooseParameters["numericUpDown_CfgRev"]); Pdu.DatSet = (String)gooseParameters["textBox_DatSet"];; Pdu.NdsCom = ((String)gooseParameters["comboBox_NdsCom"] == "1") ? true : false; Pdu.SqNum = (long)Convert.ToDecimal(gooseParameters["numericUpDown_SqNum"]); Pdu.StNum = (long)Convert.ToDecimal(gooseParameters["numericUpDown_StNum"]); Pdu.TimeAllowedtoLive = (long)Convert.ToDecimal(gooseParameters["numericUpDown_TTL"]); Pdu.Simulation = ((String)gooseParameters["comboBox_Test"] == "1") ? true : false; Pdu.T = T; Pdu.AllData = dataList; Pdu.NumDatSetEntries = dataList.Count; Goose = new GOOSE(); Goose.selectGoosePdu(Pdu); MemoryStream ms = new MemoryStream(); IEncoder encoder = CoderFactory.getInstance().newEncoder("BER"); encoder.encode <GOOSE>(Goose, ms); byte[] rawGooseData = new byte[ms.Length + 8]; // Set APPID rawGooseData[0] = (byte)(((long)Convert.ToDecimal(gooseParameters["numericUpDown_AppID"]) & 0xFF00) >> 8); rawGooseData[1] = (byte)(((long)Convert.ToDecimal(gooseParameters["numericUpDown_AppID"])) & 0xFF); // Set Length rawGooseData[2] = (byte)(((ms.Length + 8) & 0xFF00) >> 8); rawGooseData[3] = (byte)((ms.Length + 8) & 0xFF); // Set Reserved 1 and Reserved 2 rawGooseData[4] = 0; rawGooseData[5] = 0; rawGooseData[6] = 0; rawGooseData[7] = 0; ms.Position = 0; ms.Read(rawGooseData, 8, (int)ms.Length); PayloadLayer payloadLayer = new PayloadLayer { Data = new Datagram(rawGooseData), }; PacketBuilder builder; if (Convert.ToString(gooseParameters["checkBox_VlanTagEn"]) == "True") { builder = new PacketBuilder(ethernetLayer, vlanLayer, payloadLayer); ethernetLayer.EtherType = EthernetType.None; } else { builder = new PacketBuilder(ethernetLayer, payloadLayer); } return(builder.Build(DateTime.Now)); }
/// <summary> /// This function build a VLanTaggedFrame over Ethernet with payload packet. /// </summary> private static Packet BuildVLanTaggedFramePacket() { EthernetLayer ethernetLayer = new EthernetLayer { Source = new MacAddress("01:01:01:01:01:01"), Destination = new MacAddress("02:02:02:02:02:02"), EtherType = EthernetType.None, // Will be filled automatically. }; VLanTaggedFrameLayer vLanTaggedFrameLayer = new VLanTaggedFrameLayer { PriorityCodePoint = ClassOfService.Background, CanonicalFormatIndicator = false, VLanIdentifier = 50, EtherType = EthernetType.IpV4, }; PayloadLayer payloadLayer = new PayloadLayer { Data = new Datagram(Encoding.ASCII.GetBytes("hello world")), }; PacketBuilder builder = new PacketBuilder(ethernetLayer, vLanTaggedFrameLayer, payloadLayer); return builder.Build(DateTime.Now); }