diff --git a/README.md b/README.md index f5e4489..7da6878 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,8 @@ More information about Black, you find at The following software is required to run PTF: * Python 2.7 or 3.x - * Scapy 2.4.5 * six 1.16.0 + * Scapy 2.4.5 (unless you provide another packet manipulation module) * pypcap (optional - VLAN tests will fail without this) * tcpdump (optional - Scapy will complain if it's missing) @@ -54,6 +54,11 @@ To install minimal requirements execute: pip install -r requirements.txt ``` +The default packet manipulator tool for `ptf` is `Scapy`. To install it use: +```text +pip install scapy==2.4.5 +``` + To enable VLAN tests, you need to install `pypcap`: ```text pip install pypcap @@ -187,6 +192,30 @@ error. A timeout can also be specified for each individual test case, using the `@testtimeout` decorator, which needs to be imported from `ptf.testutils`. This timeout takes precedence over the global timeout passed on the command line. +## Pluggable packet manipulation module + +By default, `ptf` uses `Scapy` as the packet manipulation module, but it can +also operate on a different one. + +Such module **must define/implement the same symbols**, as defined in `Scapy` +implementation of packet. Most of them are just names of most common frame +headers (Ether, IP, TCP, UDP, ...). + +The default implementation can be found in file +[/src/ptf/packet_scapy.py](/src/ptf/packet_scapy.py). It can be used as a +reference when implementing your own version. + +To use another packet manipulation module, one needs to +provide it as argument `-pmm` or `--packet-manipulation-module` when running the +`ptf` binary. + +```text +sudo ./ptf -pmm foo.packet_foo +``` + +Please make sure that this module is loaded into the runtime before running +any tests. + --- # Configuring PTF diff --git a/example/mytests/switch.py b/example/mytests/switch.py index a393ae0..cb67669 100644 --- a/example/mytests/switch.py +++ b/example/mytests/switch.py @@ -380,7 +380,7 @@ def runTest(self): # illustrates how to use a mask even if no impact here m = Mask(exp_pkt) - m.set_do_not_care_scapy(IP, 'ttl') + m.set_do_not_care_packet(IP, 'ttl') try: send_packet(self, 2, pkt) verify_packets(self, m, [1]) diff --git a/ptf b/ptf index 8d0e97b..a0cb7a8 100755 --- a/ptf +++ b/ptf @@ -95,6 +95,8 @@ config_default = { "test_case_timeout": None, # Socket options "socket_recv_size": 4096, + # Packet manipulation provider module + "packet_manipulation_module": "ptf.packet_scapy", # Other configuration "port_map": None, } @@ -239,6 +241,14 @@ be subtracted from the result by prefixing them with the '^' character. """ parser.add_argument("--pypath", dest="pypath", action="append") + parser.add_argument( + "-pmm", + "--packet-manipulation-module", + type=str, + help="Provide packet manipulation module which should be used " + "as a 'packet' one for other PTF modules", + ) + group = parser.add_argument_group("Test selection options") group.add_argument("-f", "--test-file", help="File of tests to run, one per line") group.add_argument( diff --git a/ptf_nn/ptf_nn_test/test.py b/ptf_nn/ptf_nn_test/test.py index 36f6ce8..598bda0 100644 --- a/ptf_nn/ptf_nn_test/test.py +++ b/ptf_nn/ptf_nn_test/test.py @@ -105,7 +105,7 @@ def runTest(self): pkt1 = testutils.simple_udp_packet(eth_dst="00:11:11:11:11:11") pkt2 = testutils.simple_udp_packet(eth_dst="00:22:22:22:22:22") exp_pkt = Mask(pkt2) - exp_pkt.set_do_not_care_scapy(Ether, 'dst') + exp_pkt.set_do_not_care_packet(Ether, 'dst') testutils.send_packet(self, (0, 1), pkt1) print("Packet sent") diff --git a/requirements.txt b/requirements.txt index 9b2344e..3b370b7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1 @@ -scapy==2.4.5 six==1.16.0 diff --git a/src/ptf/dataplane.py b/src/ptf/dataplane.py index 97282ee..511c7d8 100644 --- a/src/ptf/dataplane.py +++ b/src/ptf/dataplane.py @@ -30,8 +30,7 @@ from . import ptfutils from . import netutils from . import mask -import scapy.packet -import scapy.utils +from . import packet from .pcap_writer import PcapWriter from six import StringIO @@ -802,12 +801,12 @@ def format(self): sys.stdout = StringIO() print("========== RECEIVED ==========") - if isinstance(self.expected_packet, scapy.packet.Packet): + if isinstance(self.expected_packet, packet.Packet): # Dissect this packet as if it were an instance of # the expected packet's class. - scapy.packet.ls(self.expected_packet.__class__(self.packet)) + packet.ls(self.expected_packet.__class__(self.packet)) print("--") - scapy.utils.hexdump(self.packet) + packet.hexdump(self.packet) print("==============================") return sys.stdout.getvalue() @@ -850,15 +849,15 @@ def format(self): if self.expected_packet is not None: print("========== EXPECTED ==========") - if isinstance(self.expected_packet, scapy.packet.Packet): - scapy.packet.ls(self.expected_packet) + if isinstance(self.expected_packet, packet.Packet): + packet.ls(self.expected_packet) print("--") - scapy.utils.hexdump(self.expected_packet) + packet.hexdump(self.expected_packet) elif isinstance(self.expected_packet, mask.Mask): print("Mask:") print(self.expected_packet) else: - scapy.utils.hexdump(self.expected_packet) + packet.hexdump(self.expected_packet) print("========== RECEIVED ==========") if self.recent_packets: @@ -866,14 +865,14 @@ def format(self): "%d total packets. Displaying most recent %d packets:" % (self.packet_count, len(self.recent_packets)) ) - for packet in self.recent_packets: + for recent_packet in self.recent_packets: print("------------------------------") - if isinstance(self.expected_packet, scapy.packet.Packet): + if isinstance(self.expected_packet, packet.Packet): # Dissect this packet as if it were an instance of # the expected packet's class. - scapy.packet.ls(self.expected_packet.__class__(packet)) + packet.ls(self.expected_packet.__class__(recent_packet)) print("--") - scapy.utils.hexdump(packet) + packet.hexdump(recent_packet) else: print("%d total packets." % self.packet_count) print("==============================") diff --git a/src/ptf/mask.py b/src/ptf/mask.py index 490097c..7d75a29 100644 --- a/src/ptf/mask.py +++ b/src/ptf/mask.py @@ -1,8 +1,8 @@ from __future__ import print_function +import warnings from six import StringIO import sys -from scapy.utils import hexdump -from . import packet as scapy +from . import packet class Mask: @@ -21,7 +21,7 @@ def set_do_not_care(self, offset, bitwidth): offsetb = idx % 8 self.mask[offsetB] = self.mask[offsetB] & (~(1 << (7 - offsetb))) - def set_do_not_care_scapy(self, hdr_type, field_name): + def set_do_not_care_packet(self, hdr_type, field_name): if hdr_type not in self.exp_pkt: self.valid = False print("Unknown header type") @@ -46,6 +46,14 @@ def set_do_not_care_scapy(self, hdr_type, field_name): offset += bits self.set_do_not_care(hdr_offset * 8 + offset, bitwidth) + def set_do_not_care_scapy(self, hdr_type, field_name): + warnings.warn( + '"set_do_not_care_scapy" is going to be deprecated, please ' + 'switch to the new one: "set_do_not_care_packet"', + DeprecationWarning, + ) + self.set_do_not_care_packet(hdr_type, field_name) + def set_ignore_extra_bytes(self): self.ignore_extra_bytes = True @@ -71,7 +79,7 @@ def __str__(self): assert self.valid old_stdout = sys.stdout sys.stdout = buffer = StringIO() - hexdump(self.exp_pkt) + packet.hexdump(self.exp_pkt) print("mask =", end=" ") for i in range(0, len(self.mask), 16): if i > 0: @@ -84,14 +92,14 @@ def __str__(self): def utest(): - p = scapy.Ether() / scapy.IP() / scapy.TCP() + p = packet.Ether() / packet.IP() / packet.TCP() m = Mask(p) assert m.pkt_match(p) - p1 = scapy.Ether() / scapy.IP() / scapy.TCP(sport=97) + p1 = packet.Ether() / packet.IP() / packet.TCP(sport=97) assert not m.pkt_match(p1) - m.set_do_not_care_scapy(scapy.TCP, "sport") + m.set_do_not_care_packet(packet.TCP, "sport") assert not m.pkt_match(p1) - m.set_do_not_care_scapy(scapy.TCP, "chksum") + m.set_do_not_care_packet(packet.TCP, "chksum") assert m.pkt_match(p1) exp_pkt = "\x01\x02\x03\x04\x05\x06" pkt = "\x01\x00\x00\x04\x05\x06\x07\x08" diff --git a/src/ptf/packet.py b/src/ptf/packet.py index 6f2d6c5..9aadc55 100644 --- a/src/ptf/packet.py +++ b/src/ptf/packet.py @@ -1,146 +1,24 @@ -# Distributed under the OpenFlow Software License (see LICENSE) -# Copyright (c) 2010 The Board of Trustees of The Leland Stanford Junior University -# Copyright (c) 2012, 2013 Big Switch Networks, Inc. -""" -Wrap scapy to satisfy pylint +""" A pluggable packet module + +This module dynamically imports definitions from packet manipulation module, +specified in config or provided as an agrument. +The default one is Scapy, but one can develop its own packet manipulation framework and +then, create an implementation of packet module for it (for Scapy it is packet_scapy.py) """ -import ptf +from __future__ import print_function from ptf import config -import sys -import logging - -try: - import scapy.config - import scapy.route - import scapy.layers.l2 - import scapy.layers.inet - import scapy.layers.dhcp - import scapy.layers.vxlan - import scapy.packet - import scapy.main - import scapy.fields - - if not config.get("disable_ipv6", False): - import scapy.route6 - import scapy.layers.inet6 -except ImportError: - sys.exit("Need to install scapy for packet parsing") - -Ether = scapy.layers.l2.Ether -LLC = scapy.layers.l2.LLC -SNAP = scapy.layers.l2.SNAP -Dot1Q = scapy.layers.l2.Dot1Q -GRE = scapy.layers.l2.GRE -IP = scapy.layers.inet.IP -IPOption = scapy.layers.inet.IPOption -try: - ARP = scapy.layers.inet.ARP -except AttributeError: - # Works with more recent versions of Scapy - ARP = scapy.layers.l2.ARP -TCP = scapy.layers.inet.TCP -UDP = scapy.layers.inet.UDP -ICMP = scapy.layers.inet.ICMP -DHCP = scapy.layers.dhcp.DHCP -BOOTP = scapy.layers.dhcp.BOOTP -PADDING = scapy.packet.Padding -VXLAN = scapy.layers.vxlan.VXLAN - -BTH = None -if not config.get("disable_rocev2", False): - try: - ptf.disable_logging() - scapy.main.load_contrib("roce") - BTH = scapy.contrib.roce.BTH - ptf.enable_logging() - logging.info("ROCEv2 support found in Scapy") - except: - ptf.enable_logging() - logging.warn("ROCEv2 support not found in Scapy") - pass - -if not config.get("disable_ipv6", False): - IPv6 = scapy.layers.inet6.IPv6 - IPv6ExtHdrRouting = scapy.layers.inet6.IPv6ExtHdrRouting - ICMPv6Unknown = scapy.layers.inet6.ICMPv6Unknown - ICMPv6EchoRequest = scapy.layers.inet6.ICMPv6EchoRequest - ICMPv6MLReport = scapy.layers.inet6.ICMPv6MLReport - -ERSPAN = None -ERSPAN_III = None -PlatformSpecific = None -if not config.get("disable_erspan", False): - try: - ptf.disable_logging() - scapy.main.load_contrib("erspan") - ERSPAN = scapy.contrib.erspan.ERSPAN - ERSPAN_III = scapy.contrib.erspan.ERSPAN_III - PlatformSpecific = scapy.contrib.erspan.ERSPAN_PlatformSpecific - ptf.enable_logging() - logging.info("ERSPAN support found in Scapy") - except: - ptf.enable_logging() - logging.warn("ERSPAN support not found in Scapy") - pass - -GENEVE = None -if not config.get("disable_geneve", False): - try: - ptf.disable_logging() - scapy.main.load_contrib("geneve") - GENEVE = scapy.contrib.geneve.GENEVE - ptf.enable_logging() - logging.info("GENEVE support found in Scapy") - except: - ptf.enable_logging() - logging.warn("GENEVE support not found in Scapy") - pass - -MPLS = None -if not config.get("disable_mpls", False): - try: - ptf.disable_logging() - scapy.main.load_contrib("mpls") - MPLS = scapy.contrib.mpls.MPLS - ptf.enable_logging() - logging.info("MPLS support found in Scapy") - except: - ptf.enable_logging() - logging.warn("MPLS support not found in Scapy") - pass - -NVGRE = None -if not config.get("disable_nvgre", False): - - class NVGRE(scapy.packet.Packet): - name = "NVGRE" - fields_desc = [ - scapy.fields.BitField("chksum_present", 0, 1), - scapy.fields.BitField("routing_present", 0, 1), - scapy.fields.BitField("key_present", 1, 1), - scapy.fields.BitField("seqnum_present", 0, 1), - scapy.fields.BitField("reserved", 0, 9), - scapy.fields.BitField("version", 0, 3), - scapy.fields.XShortField("proto", 0x6558), - scapy.fields.ThreeBytesField("vsid", 0), - scapy.fields.XByteField("flowid", 0), - ] - def mysummary(self): - return self.sprintf("NVGRE (vni=%NVGRE.vsid%)") +__module = __import__( + config.get("packet_manipulation_module", "ptf.packet_scapy"), fromlist=["*"] +) +__keys = [] - scapy.packet.bind_layers(IP, NVGRE, proto=47) - scapy.packet.bind_layers(NVGRE, Ether) +# import logic - everything from __all__ if provided, otherwise everything not starting +# with underscore +print("Using packet manipulation module: %s" % __module.__name__) +if "__all__" in __module.__dict__: + __keys = __module.__dict__["__all__"] +else: + __keys = [k for k in __module.__dict__ if not k.startswith("_")] -IGMP = None -if not config.get("disable_igmp", False): - try: - ptf.disable_logging() - scapy.main.load_contrib("igmp") - IGMP = scapy.contrib.igmp.IGMP - ptf.enable_logging() - logging.info("IGMP support found in Scapy") - except: - ptf.enable_logging() - logging.warn("IGMP support not found in Scapy") - pass +locals().update({k: getattr(__module, k) for k in __keys}) diff --git a/src/ptf/packet_scapy.py b/src/ptf/packet_scapy.py new file mode 100644 index 0000000..a8a43b9 --- /dev/null +++ b/src/ptf/packet_scapy.py @@ -0,0 +1,153 @@ +# Distributed under the OpenFlow Software License (see LICENSE) +# Copyright (c) 2010 The Board of Trustees of The Leland Stanford Junior University +# Copyright (c) 2012, 2013 Big Switch Networks, Inc. +""" +Scapy implementation of packet manipulation module +""" +import ptf +from ptf import config +import sys +import logging + +try: + import scapy.config + import scapy.route + import scapy.layers.l2 + import scapy.layers.inet + import scapy.layers.dhcp + import scapy.layers.vxlan + import scapy.packet + import scapy.main + import scapy.fields + import scapy.utils + + if not config.get("disable_ipv6", False): + import scapy.route6 + import scapy.layers.inet6 +except ImportError: + sys.exit("Need to install scapy for packet parsing") + +Packet = scapy.packet.Packet +Ether = scapy.layers.l2.Ether +LLC = scapy.layers.l2.LLC +SNAP = scapy.layers.l2.SNAP +Dot1Q = scapy.layers.l2.Dot1Q +GRE = scapy.layers.l2.GRE +IP = scapy.layers.inet.IP +IPOption = scapy.layers.inet.IPOption +try: + ARP = scapy.layers.inet.ARP +except AttributeError: + # Works with more recent versions of Scapy + ARP = scapy.layers.l2.ARP +TCP = scapy.layers.inet.TCP +UDP = scapy.layers.inet.UDP +ICMP = scapy.layers.inet.ICMP +DHCP = scapy.layers.dhcp.DHCP +BOOTP = scapy.layers.dhcp.BOOTP +PADDING = scapy.packet.Padding +VXLAN = scapy.layers.vxlan.VXLAN + +BTH = None +if not config.get("disable_rocev2", False): + try: + ptf.disable_logging() + scapy.main.load_contrib("roce") + BTH = scapy.contrib.roce.BTH + ptf.enable_logging() + logging.info("ROCEv2 support found in Scapy") + except: + ptf.enable_logging() + logging.warn("ROCEv2 support not found in Scapy") + pass + +if not config.get("disable_ipv6", False): + IPv6 = scapy.layers.inet6.IPv6 + IPv6ExtHdrRouting = scapy.layers.inet6.IPv6ExtHdrRouting + ICMPv6Unknown = scapy.layers.inet6.ICMPv6Unknown + ICMPv6EchoRequest = scapy.layers.inet6.ICMPv6EchoRequest + ICMPv6MLReport = scapy.layers.inet6.ICMPv6MLReport + +ERSPAN = None +ERSPAN_III = None +PlatformSpecific = None +if not config.get("disable_erspan", False): + try: + ptf.disable_logging() + scapy.main.load_contrib("erspan") + ERSPAN = scapy.contrib.erspan.ERSPAN + ERSPAN_III = scapy.contrib.erspan.ERSPAN_III + PlatformSpecific = scapy.contrib.erspan.ERSPAN_PlatformSpecific + ptf.enable_logging() + logging.info("ERSPAN support found in Scapy") + except: + ptf.enable_logging() + logging.warn("ERSPAN support not found in Scapy") + pass + +GENEVE = None +if not config.get("disable_geneve", False): + try: + ptf.disable_logging() + scapy.main.load_contrib("geneve") + GENEVE = scapy.contrib.geneve.GENEVE + ptf.enable_logging() + logging.info("GENEVE support found in Scapy") + except: + ptf.enable_logging() + logging.warn("GENEVE support not found in Scapy") + pass + +MPLS = None +if not config.get("disable_mpls", False): + try: + ptf.disable_logging() + scapy.main.load_contrib("mpls") + MPLS = scapy.contrib.mpls.MPLS + ptf.enable_logging() + logging.info("MPLS support found in Scapy") + except: + ptf.enable_logging() + logging.warn("MPLS support not found in Scapy") + pass + +NVGRE = None +if not config.get("disable_nvgre", False): + + class NVGRE(Packet): + name = "NVGRE" + fields_desc = [ + scapy.fields.BitField("chksum_present", 0, 1), + scapy.fields.BitField("routing_present", 0, 1), + scapy.fields.BitField("key_present", 1, 1), + scapy.fields.BitField("seqnum_present", 0, 1), + scapy.fields.BitField("reserved", 0, 9), + scapy.fields.BitField("version", 0, 3), + scapy.fields.XShortField("proto", 0x6558), + scapy.fields.ThreeBytesField("vsid", 0), + scapy.fields.XByteField("flowid", 0), + ] + + def mysummary(self): + return self.sprintf("NVGRE (vni=%NVGRE.vsid%)") + + scapy.packet.bind_layers(IP, NVGRE, proto=47) + scapy.packet.bind_layers(NVGRE, Ether) + +IGMP = None +if not config.get("disable_igmp", False): + try: + ptf.disable_logging() + scapy.main.load_contrib("igmp") + IGMP = scapy.contrib.igmp.IGMP + ptf.enable_logging() + logging.info("IGMP support found in Scapy") + except: + ptf.enable_logging() + logging.warn("IGMP support not found in Scapy") + pass + + +# Scapy has its own hexdump +hexdump = scapy.utils.hexdump +ls = scapy.packet.ls diff --git a/src/ptf/testutils.py b/src/ptf/testutils.py index fd8c536..c84f217 100755 --- a/src/ptf/testutils.py +++ b/src/ptf/testutils.py @@ -4,7 +4,7 @@ import types import time import re -from . import packet as scapy +from . import packet import ptf import ptf.dataplane @@ -46,7 +46,7 @@ def get_filters(): def ether_filter(pkt_str): try: - pkt = scapy.Ether(pkt_str) + pkt = packet.Ether(pkt_str) return True except: return False @@ -54,8 +54,8 @@ def ether_filter(pkt_str): def ipv6_filter(pkt_str): try: - pkt = scapy.Ether(pkt_str) - return scapy.IPv6 in pkt + pkt = packet.Ether(pkt_str) + return packet.IPv6 in pkt except: return False @@ -133,38 +133,40 @@ def simple_tcp_packet_ext_taglist( pktlen = MINSIZE if with_tcp_chksum: - tcp_hdr = scapy.TCP(sport=tcp_sport, dport=tcp_dport, flags=tcp_flags) + tcp_hdr = packet.TCP(sport=tcp_sport, dport=tcp_dport, flags=tcp_flags) else: - tcp_hdr = scapy.TCP(sport=tcp_sport, dport=tcp_dport, flags=tcp_flags, chksum=0) + tcp_hdr = packet.TCP( + sport=tcp_sport, dport=tcp_dport, flags=tcp_flags, chksum=0 + ) ip_tos = ip_make_tos(ip_tos, ip_ecn, ip_dscp) # Note Dot1Q.id is really CFI if dl_taglist_enable: - pkt = scapy.Ether(dst=eth_dst, src=eth_src) + pkt = packet.Ether(dst=eth_dst, src=eth_src) for i in range(0, len(dl_vlanid_list)): - pkt = pkt / scapy.Dot1Q( + pkt = pkt / packet.Dot1Q( prio=dl_vlan_pcp_list[i], id=dl_vlan_cfi_list[i], vlan=dl_vlanid_list[i] ) pkt = ( pkt - / scapy.IP( + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, id=ip_id, ihl=ip_ihl ) / tcp_hdr ) for i in range(1, len(dl_tpid_list)): - pkt[scapy.Dot1Q : i].type = dl_tpid_list[i] + pkt[packet.Dot1Q : i].type = dl_tpid_list[i] pkt.type = dl_tpid_list[0] else: if not ip_options: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -177,8 +179,8 @@ def simple_tcp_packet_ext_taglist( ) else: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -334,13 +336,13 @@ def simple_tcpv6_packet( ipv6_tc = ip_make_tos(ipv6_tc, ipv6_ecn, ipv6_dscp) - pkt = scapy.Ether(dst=eth_dst, src=eth_src) + pkt = packet.Ether(dst=eth_dst, src=eth_src) if dl_vlan_enable or vlan_vid or vlan_pcp: - pkt /= scapy.Dot1Q(vlan=vlan_vid, prio=vlan_pcp) - pkt /= scapy.IPv6( + pkt /= packet.Dot1Q(vlan=vlan_vid, prio=vlan_pcp) + pkt /= packet.IPv6( src=ipv6_src, dst=ipv6_dst, fl=ipv6_fl, tc=ipv6_tc, hlim=ipv6_hlim ) - pkt /= scapy.TCP(sport=tcp_sport, dport=tcp_dport, flags=tcp_flags) + pkt /= packet.TCP(sport=tcp_sport, dport=tcp_dport, flags=tcp_flags) pkt /= "D" * (pktlen - len(pkt)) return pkt @@ -398,18 +400,18 @@ def simple_udp_packet( pktlen = MINSIZE if with_udp_chksum: - udp_hdr = scapy.UDP(sport=udp_sport, dport=udp_dport) + udp_hdr = packet.UDP(sport=udp_sport, dport=udp_dport) else: - udp_hdr = scapy.UDP(sport=udp_sport, dport=udp_dport, chksum=0) + udp_hdr = packet.UDP(sport=udp_sport, dport=udp_dport, chksum=0) ip_tos = ip_make_tos(ip_tos, ip_ecn, ip_dscp) # Note Dot1Q.id is really CFI if dl_vlan_enable: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl, id=ip_id ) / udp_hdr @@ -417,8 +419,8 @@ def simple_udp_packet( else: if not ip_options: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -431,8 +433,8 @@ def simple_udp_packet( ) else: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -488,8 +490,8 @@ def simple_ipv6_sr_packet( @param srh_nh IPV6 SRH next header """ - pkt = scapy.Ether(dst=eth_dst, src=eth_src) - pkt /= scapy.IPv6( + pkt = packet.Ether(dst=eth_dst, src=eth_src) + pkt /= packet.IPv6( src=ipv6_src, dst=ipv6_dst, fl=ipv6_fl, @@ -499,7 +501,7 @@ def simple_ipv6_sr_packet( plen=ipv6_plen, ) reserved = (srh_first_seg << 24) + (srh_flags << 8) - pkt /= scapy.IPv6ExtHdrRouting( + pkt /= packet.IPv6ExtHdrRouting( nh=srh_nh, type=4, segleft=srh_seg_left, @@ -564,7 +566,7 @@ def simple_geneve_packet( @param geneve_reserved2 reserved field @param inner_frame The inner Ethernet frame """ - if scapy.GENEVE is None: + if packet.GENEVE is None: logging.error( "A GENEVE packet was requested but GENEVE is not supported by your Scapy. See README for more information" ) @@ -576,18 +578,18 @@ def simple_geneve_packet( pktlen = MINSIZE if with_udp_chksum: - udp_hdr = scapy.UDP(sport=udp_sport, dport=udp_dport) + udp_hdr = packet.UDP(sport=udp_sport, dport=udp_dport) else: - udp_hdr = scapy.UDP(sport=udp_sport, dport=udp_dport, chksum=0) + udp_hdr = packet.UDP(sport=udp_sport, dport=udp_dport, chksum=0) ip_tos = ip_make_tos(ip_tos, ip_ecn, ip_dscp) # Note Dot1Q.id is really CFI if dl_vlan_enable: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -601,8 +603,8 @@ def simple_geneve_packet( else: if not ip_options: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -615,8 +617,8 @@ def simple_geneve_packet( ) else: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -629,7 +631,7 @@ def simple_geneve_packet( / udp_hdr ) - pkt = pkt / scapy.GENEVE(vni=geneve_vni, proto=geneve_proto) + pkt = pkt / packet.GENEVE(vni=geneve_vni, proto=geneve_proto) if inner_frame: pkt = pkt / inner_frame @@ -688,7 +690,7 @@ def simple_nvgre_packet( Generates a simple GRE packet. Users shouldn't assume anything about this packet other than that it is a valid ethernet/IP/NVGRE frame. """ - if scapy.NVGRE is None: + if packet.NVGRE is None: logging.error( "A NVGRE packet was requested but NVGRE is not supported by your Scapy. See README for more information" ) @@ -697,16 +699,16 @@ def simple_nvgre_packet( if MINSIZE > pktlen: pktlen = MINSIZE - nvgre_hdr = scapy.NVGRE(vsid=nvgre_tni, flowid=nvgre_flowid) + nvgre_hdr = packet.NVGRE(vsid=nvgre_tni, flowid=nvgre_flowid) ip_tos = ip_make_tos(ip_tos, ip_ecn, ip_dscp) # Note Dot1Q.id is really CFI if dl_vlan_enable: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -720,8 +722,8 @@ def simple_nvgre_packet( else: if not ip_options: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -734,8 +736,8 @@ def simple_nvgre_packet( ) else: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -751,7 +753,7 @@ def simple_nvgre_packet( if inner_frame: pkt = pkt / inner_frame else: - pkt = pkt / scapy.IP() + pkt = pkt / packet.IP() pkt = pkt / ("D" * (pktlen - len(pkt))) return pkt @@ -813,7 +815,7 @@ def simple_vxlan_packet( Generates a simple VXLAN packet. Users shouldn't assume anything about this packet other than that it is a valid ethernet/IP/UDP/VXLAN frame. """ - if scapy.VXLAN is None: + if packet.VXLAN is None: logging.error( "A VXLAN packet was requested but VXLAN is not supported by your Scapy. See README for more information" ) @@ -823,18 +825,18 @@ def simple_vxlan_packet( pktlen = MINSIZE if with_udp_chksum: - udp_hdr = scapy.UDP(sport=udp_sport, dport=udp_dport) + udp_hdr = packet.UDP(sport=udp_sport, dport=udp_dport) else: - udp_hdr = scapy.UDP(sport=udp_sport, dport=udp_dport, chksum=0) + udp_hdr = packet.UDP(sport=udp_sport, dport=udp_dport, chksum=0) ip_tos = ip_make_tos(ip_tos, ip_ecn, ip_dscp) # Note Dot1Q.id is really CFI if dl_vlan_enable: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -848,8 +850,8 @@ def simple_vxlan_packet( else: if not ip_options: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -862,8 +864,8 @@ def simple_vxlan_packet( ) else: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -876,7 +878,7 @@ def simple_vxlan_packet( / udp_hdr ) - pkt = pkt / scapy.VXLAN( + pkt = pkt / packet.VXLAN( flags=vxlan_flags, vni=vxlan_vni, reserved1=vxlan_reserved1, @@ -948,32 +950,32 @@ def simple_vxlanv6_packet( pktlen = MINSIZE if with_udp_chksum: - udp_hdr = scapy.UDP(sport=udp_sport, dport=udp_dport) + udp_hdr = packet.UDP(sport=udp_sport, dport=udp_dport) else: - udp_hdr = scapy.UDP(sport=udp_sport, dport=udp_dport, chksum=0) + udp_hdr = packet.UDP(sport=udp_sport, dport=udp_dport, chksum=0) ipv6_tc = ip_make_tos(ipv6_tc, ipv6_ecn, ipv6_dscp) # Note Dot1Q.id is really CFI if dl_vlan_enable: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) - / scapy.IPv6( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) + / packet.IPv6( src=ipv6_src, dst=ipv6_dst, fl=ipv6_fl, tc=ipv6_tc, hlim=ipv6_hlim ) / udp_hdr ) else: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.IPv6( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.IPv6( src=ipv6_src, dst=ipv6_dst, fl=ipv6_fl, tc=ipv6_tc, hlim=ipv6_hlim ) / udp_hdr ) - pkt = pkt / scapy.VXLAN( + pkt = pkt / packet.VXLAN( flags=vxlan_flags, vni=vxlan_vni, reserved1=vxlan_reserved1, @@ -1056,7 +1058,7 @@ def simple_gre_packet( pktlen = MINSIZE # proto (ethertype) is set by Scapy based on the payload - gre_hdr = scapy.GRE( + gre_hdr = packet.GRE( chksum_present=gre_chksum_present, routing_present=gre_routing_present, key_present=gre_key_present, @@ -1074,9 +1076,9 @@ def simple_gre_packet( # Note Dot1Q.id is really CFI if dl_vlan_enable: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -1090,8 +1092,8 @@ def simple_gre_packet( else: if not ip_options: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -1104,8 +1106,8 @@ def simple_gre_packet( ) else: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -1124,7 +1126,7 @@ def simple_gre_packet( if (inner_frame_bytes[0] & 0xF0) == 0x60: pkt["GRE"].proto = 0x86DD else: - pkt = pkt / scapy.IP() + pkt = pkt / packet.IP() pkt = pkt / ("D" * (pktlen - len(pkt))) return pkt @@ -1194,7 +1196,7 @@ def simple_grev6_packet( pktlen = MINSIZE # proto (ethertype) is set by Scapy based on the payload - gre_hdr = scapy.GRE( + gre_hdr = packet.GRE( chksum_present=gre_chksum_present, routing_present=gre_routing_present, key_present=gre_key_present, @@ -1212,9 +1214,9 @@ def simple_grev6_packet( # Note Dot1Q.id is really CFI if dl_vlan_enable: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) - / scapy.IPv6( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) + / packet.IPv6( src=ipv6_src, dst=ipv6_dst, fl=ipv6_fl, @@ -1226,8 +1228,8 @@ def simple_grev6_packet( ) else: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.IPv6( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.IPv6( src=ipv6_src, dst=ipv6_dst, fl=ipv6_fl, @@ -1244,7 +1246,7 @@ def simple_grev6_packet( if (inner_frame_bytes[0] & 0xF0) == 0x60: pkt["GRE"].proto = 0x86DD else: - pkt = pkt / scapy.IP() + pkt = pkt / packet.IP() pkt = pkt / ("D" * (pktlen - len(pkt))) return pkt @@ -1325,7 +1327,7 @@ def simple_gre_erspan_packet( Generates a simple GRE/ERSPAN packet. Users shouldn't assume anything about this packet other than that it is a valid ethernet/IP/GRE/ERSPAN frame. """ - if scapy.GRE is None or scapy.ERSPAN is None: + if packet.GRE is None or packet.ERSPAN is None: logging.error( "A GRE/ERSPAN packet was requested but GRE or ERSPAN is not supported by your Scapy. See README for more information" ) @@ -1335,7 +1337,7 @@ def simple_gre_erspan_packet( pktlen = MINSIZE # proto (ethertype) is set by Scapy based on the payload - gre_hdr = scapy.GRE( + gre_hdr = packet.GRE( chksum_present=gre_chksum_present, routing_present=gre_routing_present, key_present=gre_key_present, @@ -1348,7 +1350,7 @@ def simple_gre_erspan_packet( sequence_number=gre_sequence_number, ) - erspan_hdr = scapy.ERSPAN( + erspan_hdr = packet.ERSPAN( vlan=erspan_vlan, cos=erspan_cos, en=erspan_en, @@ -1362,9 +1364,9 @@ def simple_gre_erspan_packet( # Note Dot1Q.id is really CFI if dl_vlan_enable: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -1379,8 +1381,8 @@ def simple_gre_erspan_packet( else: if not ip_options: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -1394,8 +1396,8 @@ def simple_gre_erspan_packet( ) else: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -1412,7 +1414,7 @@ def simple_gre_erspan_packet( if inner_frame: pkt = pkt / inner_frame else: - pkt = pkt / scapy.IP() + pkt = pkt / packet.IP() pkt = pkt / ("D" * (pktlen - len(pkt))) return pkt @@ -1463,7 +1465,7 @@ def ipv4_erspan_pkt( @param span_id (mirror_session_id) @param inner_frame payload of the GRE packet """ - if scapy.GRE is None or scapy.ERSPAN is None or scapy.ERSPAN_III is None: + if packet.GRE is None or packet.ERSPAN is None or packet.ERSPAN_III is None: logging.error( "A GRE/ERSPAN packet was requested but GRE or ERSPAN is not supported by your Scapy. See README for more information" ) @@ -1473,20 +1475,20 @@ def ipv4_erspan_pkt( pktlen = MINSIZE if version == 2: - erspan_hdr = scapy.GRE(proto=0x22EB) / scapy.ERSPAN_III( + erspan_hdr = packet.GRE(proto=0x22EB) / packet.ERSPAN_III( session_id=mirror_id, sgt_other=sgt_other ) else: - erspan_hdr = scapy.GRE(proto=0x88BE) / scapy.ERSPAN(session_id=mirror_id) + erspan_hdr = packet.GRE(proto=0x88BE) / packet.ERSPAN(session_id=mirror_id) ip_tos = ip_make_tos(ip_tos, ip_ecn, ip_dscp) # Note Dot1Q.id is really CFI if dl_vlan_enable: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -1500,8 +1502,8 @@ def ipv4_erspan_pkt( else: if not ip_options: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -1514,8 +1516,8 @@ def ipv4_erspan_pkt( ) else: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -1531,7 +1533,7 @@ def ipv4_erspan_pkt( if inner_frame: pkt = pkt / inner_frame else: - pkt = pkt / scapy.IP() + pkt = pkt / packet.IP() pkt = pkt / ("D" * (pktlen - len(pkt))) return pkt @@ -1589,10 +1591,10 @@ def ipv4_erspan_platform_pkt( @param inner_frame payload of the GRE packet """ if ( - scapy.GRE is None - or scapy.ERSPAN is None - or scapy.ERSPAN_III is None - or scapy.PlatformSpecific is None + packet.GRE is None + or packet.ERSPAN is None + or packet.ERSPAN_III is None + or packet.PlatformSpecific is None ): logging.error( "A GRE/ERSPAN packet was requested but GRE or ERSPAN is not supported by your Scapy. See README for more information" @@ -1603,24 +1605,24 @@ def ipv4_erspan_platform_pkt( pktlen = MINSIZE if version == 2: - erspan_hdr = scapy.GRE(proto=0x22EB) / scapy.ERSPAN_III( + erspan_hdr = packet.GRE(proto=0x22EB) / packet.ERSPAN_III( session_id=mirror_id, sgt_other=sgt_other ) if sgt_other & 0x01 == 1: - erspan_hdr = erspan_hdr / ERSPAN_PlatformSpecific( + erspan_hdr = erspan_hdr / packet.PlatformSpecific( platf_id=platf_id, info1=info1, info2=info2 ) else: - erspan_hdr = scapy.GRE(proto=0x88BE) / scapy.ERSPAN(session_id=mirror_id) + erspan_hdr = packet.GRE(proto=0x88BE) / packet.ERSPAN(session_id=mirror_id) ip_tos = ip_make_tos(ip_tos, ip_ecn, ip_dscp) # Note Dot1Q.id is really CFI if dl_vlan_enable: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -1634,8 +1636,8 @@ def ipv4_erspan_platform_pkt( else: if not ip_options: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -1648,8 +1650,8 @@ def ipv4_erspan_platform_pkt( ) else: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -1665,7 +1667,7 @@ def ipv4_erspan_platform_pkt( if inner_frame: pkt = pkt / inner_frame else: - pkt = pkt / scapy.IP() + pkt = pkt / packet.IP() pkt = pkt / ("D" * (pktlen - len(pkt))) return pkt @@ -1719,16 +1721,16 @@ def simple_udpv6_packet( pktlen = MINSIZE ipv6_tc = ip_make_tos(ipv6_tc, ipv6_ecn, ipv6_dscp) - pkt = scapy.Ether(dst=eth_dst, src=eth_src) + pkt = packet.Ether(dst=eth_dst, src=eth_src) if dl_vlan_enable or vlan_vid or vlan_pcp: - pkt /= scapy.Dot1Q(vlan=vlan_vid, prio=vlan_pcp) - pkt /= scapy.IPv6( + pkt /= packet.Dot1Q(vlan=vlan_vid, prio=vlan_pcp) + pkt /= packet.IPv6( src=ipv6_src, dst=ipv6_dst, fl=ipv6_fl, tc=ipv6_tc, hlim=ipv6_hlim ) if with_udp_chksum: - pkt /= scapy.UDP(sport=udp_sport, dport=udp_dport) + pkt /= packet.UDP(sport=udp_sport, dport=udp_dport) else: - pkt /= scapy.UDP(sport=udp_sport, dport=udp_dport, chksum=0) + pkt /= packet.UDP(sport=udp_sport, dport=udp_dport, chksum=0) if udp_payload: pkt = pkt / udp_payload pkt /= "D" * (pktlen - len(pkt)) @@ -1787,9 +1789,9 @@ def simple_ipv4ip_packet( # Note Dot1Q.id is really CFI if dl_vlan_enable: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -1801,7 +1803,7 @@ def simple_ipv4ip_packet( ) else: if not ip_options: - pkt = scapy.Ether(dst=eth_dst, src=eth_src) / scapy.IP( + pkt = packet.Ether(dst=eth_dst, src=eth_src) / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -1811,7 +1813,7 @@ def simple_ipv4ip_packet( ihl=ip_ihl, ) else: - pkt = scapy.Ether(dst=eth_dst, src=eth_src) / scapy.IP( + pkt = packet.Ether(dst=eth_dst, src=eth_src) / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -1830,7 +1832,7 @@ def simple_ipv4ip_packet( elif (inner_frame_bytes[0] & 0xF0) == 0x60: pkt["IP"].proto = 41 else: - pkt = pkt / scapy.IP() + pkt = pkt / packet.IP() pkt = pkt / ("D" * (pktlen - len(pkt))) pkt["IP"].proto = 4 @@ -1884,14 +1886,14 @@ def simple_ipv6ip_packet( # Note Dot1Q.id is really CFI if dl_vlan_enable: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) - / scapy.IPv6( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) + / packet.IPv6( src=ipv6_src, dst=ipv6_dst, fl=ipv6_fl, tc=ipv6_tc, hlim=ipv6_hlim ) ) else: - pkt = scapy.Ether(dst=eth_dst, src=eth_src) / scapy.IPv6( + pkt = packet.Ether(dst=eth_dst, src=eth_src) / packet.IPv6( src=ipv6_src, dst=ipv6_dst, fl=ipv6_fl, tc=ipv6_tc, hlim=ipv6_hlim ) @@ -1903,7 +1905,7 @@ def simple_ipv6ip_packet( elif (inner_frame_bytes[0] & 0xF0) == 0x60: pkt["IPv6"].nh = 41 else: - pkt = pkt / scapy.IP() + pkt = pkt / packet.IP() pkt = pkt / ("D" * (pktlen - len(pkt))) pkt["IPv6"].nh = 4 @@ -1961,17 +1963,17 @@ def simple_icmp_packet( if dl_vlan_enable: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.Dot1Q(prio=vlan_pcp, id=0, vlan=vlan_vid) - / scapy.IP(src=ip_src, dst=ip_dst, ttl=ip_ttl, tos=ip_tos, id=ip_id) - / scapy.ICMP(type=icmp_type, code=icmp_code) + packet.Ether(dst=eth_dst, src=eth_src) + / packet.Dot1Q(prio=vlan_pcp, id=0, vlan=vlan_vid) + / packet.IP(src=ip_src, dst=ip_dst, ttl=ip_ttl, tos=ip_tos, id=ip_id) + / packet.ICMP(type=icmp_type, code=icmp_code) / icmp_data ) else: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.IP(src=ip_src, dst=ip_dst, ttl=ip_ttl, tos=ip_tos, id=ip_id) - / scapy.ICMP(type=icmp_type, code=icmp_code) + packet.Ether(dst=eth_dst, src=eth_src) + / packet.IP(src=ip_src, dst=ip_dst, ttl=ip_ttl, tos=ip_tos, id=ip_id) + / packet.ICMP(type=icmp_type, code=icmp_code) / icmp_data ) @@ -2026,13 +2028,13 @@ def simple_icmpv6_packet( ipv6_tc = ip_make_tos(ipv6_tc, ipv6_ecn, ipv6_dscp) - pkt = scapy.Ether(dst=eth_dst, src=eth_src) + pkt = packet.Ether(dst=eth_dst, src=eth_src) if dl_vlan_enable or vlan_vid or vlan_pcp: - pkt /= scapy.Dot1Q(vlan=vlan_vid, prio=vlan_pcp) - pkt /= scapy.IPv6( + pkt /= packet.Dot1Q(vlan=vlan_vid, prio=vlan_pcp) + pkt /= packet.IPv6( src=ipv6_src, dst=ipv6_dst, fl=ipv6_fl, tc=ipv6_tc, hlim=ipv6_hlim ) - pkt /= scapy.ICMPv6Unknown(type=icmp_type, code=icmp_code) + pkt /= packet.ICMPv6Unknown(type=icmp_type, code=icmp_code) pkt /= "D" * (pktlen - len(pkt)) return pkt @@ -2094,9 +2096,9 @@ def simple_ipv6_mld_packet( # Note Dot1Q.id is really CFI if dl_vlan_enable: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) - / scapy.IPv6( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) + / packet.IPv6( src=ipv6_src, dst=ipv6_dst, fl=ipv6_fl, @@ -2106,7 +2108,7 @@ def simple_ipv6_mld_packet( ) ) else: - pkt = scapy.Ether(dst=eth_dst, src=eth_src) / scapy.IPv6( + pkt = packet.Ether(dst=eth_dst, src=eth_src) / packet.IPv6( src=ipv6_src, dst=ipv6_dst, fl=ipv6_fl, @@ -2115,7 +2117,7 @@ def simple_ipv6_mld_packet( nh=next_header, ) - pkt = pkt / scapy.ICMPv6MLReport(type=mld_type, mladdr=mld_mladdr, mrd=mld_mrd) + pkt = pkt / packet.ICMPv6MLReport(type=mld_type, mladdr=mld_mladdr, mrd=mld_mrd) if inner_frame: pkt = pkt / inner_frame @@ -2158,10 +2160,10 @@ def simple_arp_packet( if MINSIZE > pktlen: pktlen = MINSIZE - pkt = scapy.Ether(dst=eth_dst, src=eth_src) + pkt = packet.Ether(dst=eth_dst, src=eth_src) if vlan_vid or vlan_pcp: - pkt /= scapy.Dot1Q(vlan=vlan_vid, prio=vlan_pcp) - pkt /= scapy.ARP(hwsrc=hw_snd, hwdst=hw_tgt, pdst=ip_tgt, psrc=ip_snd, op=arp_op) + pkt /= packet.Dot1Q(vlan=vlan_vid, prio=vlan_pcp) + pkt /= packet.ARP(hwsrc=hw_snd, hwdst=hw_tgt, pdst=ip_tgt, psrc=ip_snd, op=arp_op) pkt = pkt / ("\0" * (pktlen - len(pkt))) @@ -2175,7 +2177,7 @@ def simple_eth_packet( if MINSIZE > pktlen: pktlen = MINSIZE - pkt = scapy.Ether(dst=eth_dst, src=eth_src, type=eth_type) + pkt = packet.Ether(dst=eth_dst, src=eth_src, type=eth_type) pkt = pkt / ("0" * (pktlen - len(pkt))) @@ -2213,18 +2215,18 @@ def simple_eth_raw_packet_with_taglist( if MINSIZE > pktlen: pktlen = MINSIZE - pkt = scapy.Ether(dst=eth_dst, src=eth_src) + pkt = packet.Ether(dst=eth_dst, src=eth_src) if dl_taglist_enable: for i in range(0, len(dl_vlanid_list)): - pkt = pkt / scapy.Dot1Q( + pkt = pkt / packet.Dot1Q( prio=dl_vlan_pcp_list[i], id=dl_vlan_cfi_list[i], vlan=dl_vlanid_list[i] ) for i in range(1, len(dl_tpid_list)): - pkt[scapy.Dot1Q : i].type = dl_tpid_list[i] + pkt[packet.Dot1Q : i].type = dl_tpid_list[i] pkt.type = dl_tpid_list[0] - pkt[scapy.Dot1Q : len(dl_tpid_list)].type = pktlen - len(pkt) + pkt[packet.Dot1Q : len(dl_tpid_list)].type = pktlen - len(pkt) else: pkt.type = pktlen - len(pkt) @@ -2285,9 +2287,9 @@ def simple_ip_packet( # Note Dot1Q.id is really CFI if dl_vlan_enable: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -2299,7 +2301,7 @@ def simple_ip_packet( ) else: if not ip_options: - pkt = scapy.Ether(dst=eth_dst, src=eth_src) / scapy.IP( + pkt = packet.Ether(dst=eth_dst, src=eth_src) / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -2309,7 +2311,7 @@ def simple_ip_packet( proto=ip_proto, ) else: - pkt = scapy.Ether(dst=eth_dst, src=eth_src) / scapy.IP( + pkt = packet.Ether(dst=eth_dst, src=eth_src) / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -2365,22 +2367,24 @@ def simple_ip_only_packet( pktlen = MINSIZE if with_tcp_chksum: - tcp_hdr = scapy.TCP(sport=tcp_sport, dport=tcp_dport, flags=tcp_flags) + tcp_hdr = packet.TCP(sport=tcp_sport, dport=tcp_dport, flags=tcp_flags) else: - tcp_hdr = scapy.TCP(sport=tcp_sport, dport=tcp_dport, flags=tcp_flags, chksum=0) + tcp_hdr = packet.TCP( + sport=tcp_sport, dport=tcp_dport, flags=tcp_flags, chksum=0 + ) ip_tos = ip_make_tos(ip_tos, ip_ecn, ip_dscp) if not ip_options: pkt = ( - scapy.IP( + packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, id=ip_id, ihl=ip_ihl ) / tcp_hdr ) else: pkt = ( - scapy.IP( + packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -2425,7 +2429,7 @@ def simple_mpls_packet( @param inner_frame The inner frame """ - if scapy.MPLS is None: + if packet.MPLS is None: logging.error( "A MPLS packet was requested but MPLS is not supported by your Scapy. See README for more information" ) @@ -2434,17 +2438,17 @@ def simple_mpls_packet( if MINSIZE > pktlen: pktlen = MINSIZE - pkt = scapy.Ether(dst=eth_dst, src=eth_src) - pkt[scapy.Ether].setfieldval("type", mpls_type) + pkt = packet.Ether(dst=eth_dst, src=eth_src) + pkt[packet.Ether].setfieldval("type", mpls_type) if dl_vlan_enable: - pkt / scapy.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) - pkt[scapy.Dot1Q].setfieldval("type", mpls_type) + pkt / packet.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) + pkt[packet.Dot1Q].setfieldval("type", mpls_type) mpls_tags = list(mpls_tags) while len(mpls_tags): tag = mpls_tags.pop(0) - mpls = scapy.MPLS() + mpls = packet.MPLS() if "label" in tag: mpls.label = tag["label"] if "tc" in tag: @@ -2517,11 +2521,11 @@ def simple_qinq_tcp_packet( # Note Dot1Q.id is really CFI pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.Dot1Q(prio=dl_vlan_pcp_outer, id=dl_vlan_cfi_outer, vlan=dl_vlan_outer) - / scapy.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) - / scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl) - / scapy.TCP(sport=tcp_sport, dport=tcp_dport) + packet.Ether(dst=eth_dst, src=eth_src) + / packet.Dot1Q(prio=dl_vlan_pcp_outer, id=dl_vlan_cfi_outer, vlan=dl_vlan_outer) + / packet.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) + / packet.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl) + / packet.TCP(sport=tcp_sport, dport=tcp_dport) ) pkt = pkt / codecs.decode( @@ -2578,7 +2582,7 @@ def simple_igmp_packet( Generates a simple IGMP packet. Users shouldn't assume anything about this packet other than that it is a valid ethernet/IP/IGMP frame. """ - if scapy.IGMP is None: + if packet.IGMP is None: logging.error( "An IGMP packet was requested but IGMP is not supported by your Scapy. See README for more information" ) @@ -2592,19 +2596,19 @@ def simple_igmp_packet( # Note Dot1Q.id is really CFI if dl_vlan_enable: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, id=ip_id, ihl=ip_ihl ) ) else: if not ip_options: - pkt = scapy.Ether(dst=eth_dst, src=eth_src) / scapy.IP( + pkt = packet.Ether(dst=eth_dst, src=eth_src) / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, id=ip_id, ihl=ip_ihl ) else: - pkt = scapy.Ether(dst=eth_dst, src=eth_src) / scapy.IP( + pkt = packet.Ether(dst=eth_dst, src=eth_src) / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -2614,7 +2618,7 @@ def simple_igmp_packet( options=ip_options, ) - pkt = pkt / scapy.IGMP(type=igmp_type, gaddr=igmp_gaddr, mrtime=igmp_mrtime) + pkt = pkt / packet.IGMP(type=igmp_type, gaddr=igmp_gaddr, mrtime=igmp_mrtime) if inner_frame: pkt = pkt / inner_frame @@ -2689,10 +2693,10 @@ def dhcp_discover_packet(eth_client="00:01:02:03:04:05", set_broadcast_bit=False """ - pkt = scapy.Ether(dst=DHCP_MAC_BROADCAST, src=eth_client, type=DHCP_ETHER_TYPE_IP) - pkt /= scapy.IP(src=DHCP_IP_DEFAULT_ROUTE, dst=DHCP_IP_BROADCAST) - pkt /= scapy.UDP(sport=DHCP_PORT_CLIENT, dport=DHCP_PORT_SERVER) - pkt /= scapy.BOOTP( + pkt = packet.Ether(dst=DHCP_MAC_BROADCAST, src=eth_client, type=DHCP_ETHER_TYPE_IP) + pkt /= packet.IP(src=DHCP_IP_DEFAULT_ROUTE, dst=DHCP_IP_BROADCAST) + pkt /= packet.UDP(sport=DHCP_PORT_CLIENT, dport=DHCP_PORT_SERVER) + pkt /= packet.BOOTP( op=DHCP_BOOTP_OP_REQUEST, htype=DHCP_BOOTP_HTYPE_ETHERNET, hlen=DHCP_BOOTP_HLEN_ETHERNET, @@ -2706,7 +2710,7 @@ def dhcp_discover_packet(eth_client="00:01:02:03:04:05", set_broadcast_bit=False giaddr=DHCP_IP_DEFAULT_ROUTE, chaddr=__dhcp_mac_to_chaddr(eth_client), ) - pkt /= scapy.DHCP(options=[("message-type", "discover"), ("end")]) + pkt /= packet.DHCP(options=[("message-type", "discover"), ("end")]) return pkt @@ -2749,10 +2753,10 @@ def dhcp_offer_packet( ip_tos = ip_make_tos(tos=16, ecn=None, dscp=None) - pkt = scapy.Ether(dst=eth_dst, src=eth_server, type=DHCP_ETHER_TYPE_IP) - pkt /= scapy.IP(src=ip_server, dst=ip_dst, tos=ip_tos, ttl=128, id=0) - pkt /= scapy.UDP(sport=DHCP_PORT_SERVER, dport=port_dst) - pkt /= scapy.BOOTP( + pkt = packet.Ether(dst=eth_dst, src=eth_server, type=DHCP_ETHER_TYPE_IP) + pkt /= packet.IP(src=ip_server, dst=ip_dst, tos=ip_tos, ttl=128, id=0) + pkt /= packet.UDP(sport=DHCP_PORT_SERVER, dport=port_dst) + pkt /= packet.BOOTP( op=DHCP_BOOTP_OP_REPLY, htype=DHCP_BOOTP_HTYPE_ETHERNET, hlen=DHCP_BOOTP_HLEN_ETHERNET, @@ -2766,7 +2770,7 @@ def dhcp_offer_packet( giaddr=ip_gateway, chaddr=__dhcp_mac_to_chaddr(eth_client), ) - pkt /= scapy.DHCP( + pkt /= packet.DHCP( options=[ ("message-type", "offer"), ("server_id", ip_server), @@ -2775,7 +2779,7 @@ def dhcp_offer_packet( ("end"), ] ) - pkt /= scapy.PADDING("\x00" * padding_bytes) + pkt /= packet.PADDING("\x00" * padding_bytes) return pkt @@ -2802,10 +2806,10 @@ def dhcp_request_packet( """ - pkt = scapy.Ether(dst=DHCP_MAC_BROADCAST, src=eth_client, type=DHCP_ETHER_TYPE_IP) - pkt /= scapy.IP(src=DHCP_IP_DEFAULT_ROUTE, dst=DHCP_IP_BROADCAST) - pkt /= scapy.UDP(sport=DHCP_PORT_CLIENT, dport=DHCP_PORT_SERVER) - pkt /= scapy.BOOTP( + pkt = packet.Ether(dst=DHCP_MAC_BROADCAST, src=eth_client, type=DHCP_ETHER_TYPE_IP) + pkt /= packet.IP(src=DHCP_IP_DEFAULT_ROUTE, dst=DHCP_IP_BROADCAST) + pkt /= packet.UDP(sport=DHCP_PORT_CLIENT, dport=DHCP_PORT_SERVER) + pkt /= packet.BOOTP( op=DHCP_BOOTP_OP_REQUEST, htype=DHCP_BOOTP_HTYPE_ETHERNET, hlen=DHCP_BOOTP_HLEN_ETHERNET, @@ -2819,7 +2823,7 @@ def dhcp_request_packet( giaddr=DHCP_IP_DEFAULT_ROUTE, chaddr=__dhcp_mac_to_chaddr(eth_client), ) - pkt /= scapy.DHCP( + pkt /= packet.DHCP( options=[ ("message-type", "request"), ("requested_addr", ip_requested), @@ -2869,10 +2873,10 @@ def dhcp_ack_packet( ip_tos = ip_make_tos(tos=16, ecn=None, dscp=None) - pkt = scapy.Ether(dst=eth_dst, src=eth_server, type=DHCP_ETHER_TYPE_IP) - pkt /= scapy.IP(src=ip_server, dst=ip_dst, tos=ip_tos, ttl=128, id=0) - pkt /= scapy.UDP(sport=DHCP_PORT_SERVER, dport=port_dst) - pkt /= scapy.BOOTP( + pkt = packet.Ether(dst=eth_dst, src=eth_server, type=DHCP_ETHER_TYPE_IP) + pkt /= packet.IP(src=ip_server, dst=ip_dst, tos=ip_tos, ttl=128, id=0) + pkt /= packet.UDP(sport=DHCP_PORT_SERVER, dport=port_dst) + pkt /= packet.BOOTP( op=DHCP_BOOTP_OP_REPLY, htype=DHCP_BOOTP_HTYPE_ETHERNET, hlen=DHCP_BOOTP_HLEN_ETHERNET, @@ -2886,7 +2890,7 @@ def dhcp_ack_packet( giaddr=ip_gateway, chaddr=__dhcp_mac_to_chaddr(eth_client), ) - pkt /= scapy.DHCP( + pkt /= packet.DHCP( options=[ ("message-type", "ack"), ("server_id", ip_server), @@ -2895,7 +2899,7 @@ def dhcp_ack_packet( ("end"), ] ) - pkt /= scapy.PADDING("\x00" * padding_bytes) + pkt /= packet.PADDING("\x00" * padding_bytes) return pkt @@ -2919,11 +2923,11 @@ def dhcp_release_packet( """ - pkt = scapy.Ether(dst=DHCP_MAC_BROADCAST, src=eth_client, type=DHCP_ETHER_TYPE_IP) - pkt /= scapy.IP(src=DHCP_IP_DEFAULT_ROUTE, dst=DHCP_IP_BROADCAST) - pkt /= scapy.UDP(sport=DHCP_PORT_CLIENT, dport=DHCP_PORT_SERVER) - pkt /= scapy.BOOTP(ciaddr=ip_client, chaddr=__dhcp_mac_to_chaddr(eth_client)) - pkt /= scapy.DHCP( + pkt = packet.Ether(dst=DHCP_MAC_BROADCAST, src=eth_client, type=DHCP_ETHER_TYPE_IP) + pkt /= packet.IP(src=DHCP_IP_DEFAULT_ROUTE, dst=DHCP_IP_BROADCAST) + pkt /= packet.UDP(sport=DHCP_PORT_CLIENT, dport=DHCP_PORT_SERVER) + pkt /= packet.BOOTP(ciaddr=ip_client, chaddr=__dhcp_mac_to_chaddr(eth_client)) + pkt /= packet.DHCP( options=[("message-type", "release"), ("server_id", ip_server), ("end")] ) return pkt @@ -3704,7 +3708,7 @@ def simple_rocev2_packet( this packet other than that it is a valid ethernet/IP/UDP/ROCEv2 frame. """ - if scapy.BTH is None: + if packet.BTH is None: logging.error( "A ROCEv2 packet was requested but ROCEv2 is not supported by your Scapy. See README for more information" ) @@ -3713,7 +3717,7 @@ def simple_rocev2_packet( if MINSIZE > pktlen: pktlen = MINSIZE - bth_hdr = scapy.BTH( + bth_hdr = packet.BTH( opcode=bth_opcode, solicited=bth_se, migreq=bth_migration_req, @@ -3727,16 +3731,16 @@ def simple_rocev2_packet( psn=bth_psn, ) - udp_hdr = scapy.UDP(sport=udp_sport, dport=udp_dport) + udp_hdr = packet.UDP(sport=udp_sport, dport=udp_dport) ip_tos = ip_make_tos(ip_tos, ip_ecn, ip_dscp) # Note Dot1Q.id is really CFI if dl_vlan_enable: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.Dot1Q(prio=vlan_pcp, id=dl_vlan_cfi, vlan=vlan_vid) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl, id=ip_id ) / udp_hdr @@ -3745,8 +3749,8 @@ def simple_rocev2_packet( else: if not ip_options: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -3760,8 +3764,8 @@ def simple_rocev2_packet( ) else: pkt = ( - scapy.Ether(dst=eth_dst, src=eth_src) - / scapy.IP( + packet.Ether(dst=eth_dst, src=eth_src) + / packet.IP( src=ip_src, dst=ip_dst, tos=ip_tos, @@ -3854,7 +3858,7 @@ def simple_rocev2v6_packet( this packet other than that it is a valid ethernet/IP/UDP/ROCEv2 frame. """ - if scapy.BTH is None: + if packet.BTH is None: logging.error( "A ROCEv2 packet was requested but ROCEv2 is not supported by your Scapy. See README for more information" ) @@ -3863,7 +3867,7 @@ def simple_rocev2v6_packet( if MINSIZE > pktlen: pktlen = MINSIZE - bth_hdr = scapy.BTH( + bth_hdr = packet.BTH( opcode=bth_opcode, solicited=bth_se, migreq=bth_migration_req, @@ -3878,13 +3882,13 @@ def simple_rocev2v6_packet( ) ipv6_tc = ip_make_tos(ipv6_tc, ipv6_ecn, ipv6_dscp) - pkt = scapy.Ether(dst=eth_dst, src=eth_src) + pkt = packet.Ether(dst=eth_dst, src=eth_src) if dl_vlan_enable or vlan_vid or vlan_pcp: - pkt /= scapy.Dot1Q(vlan=vlan_vid, prio=vlan_pcp) - pkt /= scapy.IPv6( + pkt /= packet.Dot1Q(vlan=vlan_vid, prio=vlan_pcp) + pkt /= packet.IPv6( src=ipv6_src, dst=ipv6_dst, fl=ipv6_fl, tc=ipv6_tc, hlim=ipv6_hlim ) - pkt /= scapy.UDP(sport=udp_sport, dport=udp_dport) + pkt /= packet.UDP(sport=udp_sport, dport=udp_dport) pkt /= bth_hdr if rocev2_payload: