from vpp_interface import VppInterface class VppMPLSTunnelInterface(VppInterface): """ VPP MPLS Tunnel interface """ def __init__(self, test, paths, is_multicast=0, is_l2=0): """ Create MPLS Tunnel interface """ super(VppMPLSTunnelInterface, self).__init__(test) self.t_paths = paths self.is_multicast = is_multicast self.is_l2 = is_l2 self.encoded_paths = [] for path in self.t_paths: self.encoded_paths.append(path.encode()) def add_vpp_config(self): reply = self.test.vapi.mpls_tunnel_add_del( 0xffffffff, self.encoded_paths, is_multicast=self.is_multicast, l2_only=self.is_l2) self.set_sw_if_index(reply.sw_if_index) @media only all and (prefers-color-scheme: dark) { .highlight .hll { background-color: #49483e } .highlight .c { color: #75715e } /* Comment */ .highlight .err { color: #960050; background-color: #1e0010 } /* Error */ .highlight .k { color: #66d9ef } /* Keyword */ .highlight .l { color: #ae81ff } /* Literal */ .highlight .n { color: #f8f8f2 } /* Name */ .highlight .o { color: #f92672 } /* Operator */ .highlight .p { color: #f8f8f2 } /* Punctuation */ .highlight .ch { color: #75715e } /* Comment.Hashbang */ .highlight .cm { color: #75715e } /* Comment.Multiline */ .highlight .cp { color: #75715e } /* Comment.Preproc */ .highlight .cpf { color: #75715e } /* Comment.PreprocFile */ .highlight .c1 { color: #75715e } /* Comment.Single */ .highlight .cs { color: #75715e } /* Comment.Special */ .highlight .gd { color: #f92672 } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gi { color: #a6e22e } /* Generic.Inserted */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #75715e } /* Generic.Subheading */ .highlight .kc { color: #66d9ef } /* Keyword.Constant */ .highlight .kd { color: #66d9ef } /* Keyword.Declaration */ .highlight .kn { color: #f92672 } /* Keyword.Namespace */ .highlight .kp { color: #66d9ef } /* Keyword.Pseudo */ .highlight .kr { color: #66d9ef } /* Keyword.Reserved */ .highlight .kt { color: #66d9ef } /* Keyword.Type */ .highlight .ld { color: #e6db74 } /* Literal.Date */ .highlight .m { color: #ae81ff } /* Literal.Number */ .highlight .s { color: #e6db74 } /* Literal.String */ .highlight .na { color: #a6e22e } /* Name.Attribute */ .highlight .nb { color: #f8f8f2 } /* Name.Builtin */ .highlight .nc { color: #a6e22e } /* Name.Class */ .highlight .no { color: #66d9ef } /* Name.Constant */ .highlight .nd { color: #a6e22e } /* Name.Decorator */ .highlight .ni { color: #f8f8f2 } /* Name.Entity */ .highlight .ne { color: #a6e22e } /* Name.Exception */ .highlight .nf { color: #a6e22e } /* Name.Function */ .highlight .nl { color: #f8f8f2 } /* Name.Label */ .highlight .nn { color: #f8f8f2 } /* Name.Namespace */ .highlight .nx { color: #a6e22e } /* Name.Other */ .highlight .py { color: #f8f8f2 } /* Name.Property */ .highlight .nt { color: #f92672 } /* Name.Tag */ .highlight .nv { color: #f8f8f2 } /* Name.Variable */ .highlight .ow { color: #f92672 } /* Operator.Word */ .highlight .w { color: #f8f8f2 } /* Text.Whitespace */ .highlight .mb { color: #ae81ff } /* Literal.Number.Bin */ .highlight .mf { color: #ae81ff } /* Literal.Number.Float */ .highlight .mh { color: #ae81ff } /* Literal.Number.Hex */ .highlight .mi { color: #ae81ff } /* Literal.Number.Integer */ .highlight .mo { color: #ae81ff } /* Literal.Number.Oct */ .highlight .sa { color: #e6db74 } /* Literal.String.Affix */ .highlight .sb { color: #e6db74 } /* Literal.String.Backtick */ .highlight .sc { color: #e6db74 } /* Literal.String.Char */ .highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */ .highlight .sd { color: #e6db74 } /* Literal.String.Doc */ .highlight .s2 { color: #e6db74 } /* Literal.String.Double */ .highlight .se { color: #ae81ff } /* Literal.String.Escape */ .highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */ .highlight .si { color: #e6db74 } /* Literal.String.Interpol */ .highlight .sx { color: #e6db74 } /* Literal.String.Other */ .highlight .sr { color: #e6db74 } /* Literal.String.Regex */ .highlight .s1 { color: #e6db74 } /* Literal.String.Single */ .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */ .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #a6e22e } /* Name.Function.Magic */ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */ } @media (prefers-color-scheme: light) { .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ } #!/usr/bin/env python # Copyright (c) 2016 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Traffic script that sends an IP ICMPv4/ICMPv6 packet from one interface to the other. Source and destination IP addresses and source and destination MAC addresses are checked in received packet. """ import sys import ipaddress from scapy.layers.inet import IP, ICMP, ARP from scapy.layers.inet6 import IPv6, ICMPv6EchoRequest, ICMPv6ND_NS from scapy.layers.l2 import Ether from resources.libraries.python.PacketVerifier import RxQueue, TxQueue, auto_pad from resources.libraries.python.TrafficScriptArg import TrafficScriptArg def valid_ipv4(address): """Check if IP address has the correct IPv4 address format. :param address: IP address. :type address: str :return: True in case of correct IPv4 address format, otherwise return false. :rtype: bool """ try: ipaddress.IPv4Address(unicode(address)) return True except (AttributeError, ipaddress.AddressValueError): return False def valid_ipv6(address): """Check if IP address has the correct IPv6 address format. :param address: IP address. :type address: str :return: True in case of correct IPv6 address format, otherwise return false. :rtype: bool """ try: ipaddress.IPv6Address(unicode(address)) return True except (AttributeError, ipaddress.AddressValueError): return False def main(): """Send a simple L2 or ICMP packet from one TG interface to DUT, then receive a copy of the packet on the second TG interface, and a copy of the ICMP reply.""" args = TrafficScriptArg(['tg_src_mac', 'src_ip', 'dst_ip', 'dut_if1_mac', 'ptype']) src_mac = args.get_arg('tg_src_mac') dst_mac = args.get_arg('dut_if1_mac') src_ip = args.get_arg('src_ip') dst_ip = args.get_arg('dst_ip') tx_if = args.get_arg('tx_if') rx_if = args.get_arg('rx_if') ptype = args.get_arg('ptype') rxq_mirrored = RxQueue(rx_if) rxq_tx = RxQueue(tx_if) txq = TxQueue(tx_if) sent = [] if ptype == "ARP": pkt_raw = (Ether(src=src_mac, dst=dst_mac) / ARP(hwsrc=src_mac, hwdst="00:00:00:00:00:00", psrc=src_ip, pdst=dst_ip, op="who-has")) elif ptype == "ICMP": if valid_ipv4(src_ip) and valid_ipv4(dst_ip): pkt_raw = (Ether(src=src_mac, dst=dst_mac) / IP(src=src_ip, dst=dst_ip) / ICMP(type="echo-request")) else: raise ValueError("IP addresses not in correct format") elif ptype == "ICMPv6": if valid_ipv6(src_ip) and valid_ipv6(dst_ip): pkt_raw = (Ether(src=src_mac, dst=dst_mac) / IPv6(src=src_ip, dst=dst_ip) / ICMPv6EchoRequest()) else: raise ValueError("IPv6 addresses not in correct format") else: raise RuntimeError("Unexpected payload type.") txq.send(pkt_raw) sent.append(auto_pad(pkt_raw)) # Receive copy of Rx packet. while True: ether = rxq_mirrored.recv(2) if ether is None: raise RuntimeError("Rx timeout of mirrored Rx packet") if ether.haslayer(ICMPv6ND_NS): # read another packet in the queue if the current one is ICMPv6ND_NS continue else: # otherwise process the current packet break pkt = auto_pad(pkt_raw) if str(ether) != str(pkt): print("Mirrored Rx packet doesn't match the original Rx packet.") if ether.src != src_mac or ether.dst != dst_mac: raise RuntimeError("MAC mismatch in mirrored Rx packet.") if ptype == "ARP": if not ether.haslayer(ARP): raise RuntimeError("Mirrored Rx packet is not an ARP packet.") if ether['ARP'].op != 1: # 1=who-has raise RuntimeError("Mirrored Rx packet is not an ARP request.") if ether['ARP'].hwsrc != src_mac or ether['ARP'].hwdst != dst_mac: raise RuntimeError("MAC mismatch in mirrored Rx ARP packet.") if ether['ARP'].psrc != src_ip or ether['ARP'].pdst != dst_ip: raise RuntimeError("IP address mismatch in mirrored " "Rx ARP packet.") elif ptype == "ICMP": if not ether.haslayer(IP): raise RuntimeError("Mirrored Rx packet is not an IPv4 packet.") if ether['IP'].src != src_ip or ether['IP'].dst != dst_ip: raise RuntimeError("IP address mismatch in mirrored " "Rx IPv4 packet.") if not ether.haslayer(ICMP): raise RuntimeError("Mirrored Rx packet is not an ICMP packet.") if ether['ICMP'].type != 8: # 8=echo-request raise RuntimeError("Mirrored Rx packet is not an ICMP " "echo request.") elif ptype == "ICMPv6": if not ether.haslayer(IPv6): raise RuntimeError("Mirrored Rx packet is not an IPv6 packet.") if ether['IPv6'].src != src_ip or ether['IPv6'].dst != dst_ip: raise RuntimeError("IP address mismatch in mirrored " "Rx IPv6 packet.") if not ether.haslayer(ICMPv6EchoRequest): raise RuntimeError("Mirrored Rx packet is not an ICMPv6 " "echo request.") print("Mirrored Rx packet check OK.\n") # Receive reply on TG Tx port. ether_repl = rxq_tx.recv(2, sent) if ether_repl is None: raise RuntimeError("Reply not received on TG Tx port.") print("Reply received on TG Tx port.\n") # Receive copy of Tx packet. ether = rxq_mirrored.recv(2) if ether is None: raise RuntimeError("Rx timeout of mirrored Tx packet") if str(ether) != str(ether_repl): print("Mirrored Tx packet doesn't match the received Tx packet.") if ether.src != ether_repl.src or ether.dst != ether_repl.dst: raise RuntimeError("MAC mismatch in mirrored Tx packet.") if ptype == "ARP": if not ether.haslayer(ARP): raise RuntimeError("Mirrored Tx packet is not an ARP packet.") if ether['ARP'].op != ether_repl['ARP'].op: # 2=is_at raise RuntimeError("ARP operational code mismatch " "in mirrored Tx packet.") if ether['ARP'].hwsrc != ether_repl['ARP'].hwsrc\ or ether['ARP'].hwdst != ether_repl['ARP'].hwdst: raise RuntimeError("MAC mismatch in mirrored Tx ARP packet.") if ether['ARP'].psrc != ether_repl['ARP'].psrc\ or ether['ARP'].pdst != ether_repl['ARP'].pdst: raise RuntimeError("IP address mismatch in mirrored " "Tx ARP packet.") elif ptype == "ICMP": if not ether.haslayer(IP): raise RuntimeError("Mirrored Tx packet is not an IPv4 packet.") if ether['IP'].src != ether_repl['IP'].src\ or ether['IP'].dst != ether_repl['IP'].dst: raise RuntimeError("IP address mismatch in mirrored " "Tx IPv4 packet.") if not ether.haslayer(ICMP): raise RuntimeError("Mirrored Tx packet is not an ICMP packet.") if ether['ICMP'].type != ether_repl['ICMP'].type: # 0=echo-reply raise RuntimeError("ICMP packet type mismatch " "in mirrored Tx packet.") elif ptype == "ICMPv6": if not ether.haslayer(IPv6): raise RuntimeError("Mirrored Tx packet is not an IPv6 packet.") if ether['IPv6'].src != ether_repl['IPv6'].src\ or ether['IPv6'].dst != ether_repl['IPv6'].dst: raise RuntimeError("IP address mismatch in mirrored " "Tx IPv6 packet.") if ether[2].name != ether_repl[2].name: raise RuntimeError("ICMPv6 message type mismatch " "in mirrored Tx packet.") print("Mirrored Tx packet check OK.\n") sys.exit(0) if __name__ == "__main__": main()
#!/usr/bin/env python # Copyright (c) 2016 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Traffic script that sends an IP ICMPv4/ICMPv6 packet from one interface to the other. Source and destination IP addresses and source and destination MAC addresses are checked in received packet. """ import sys import ipaddress from scapy.layers.inet import IP, ICMP, ARP from scapy.layers.inet6 import IPv6, ICMPv6EchoRequest, ICMPv6ND_NS from scapy.layers.l2 import Ether from resources.libraries.python.PacketVerifier import RxQueue, TxQueue, auto_pad from resources.libraries.python.TrafficScriptArg import TrafficScriptArg def valid_ipv4(address): """Check if IP address has the correct IPv4 address format. :param address: IP address. :type address: str :return: True in case of correct IPv4 address format, otherwise return false. :rtype: bool """ try: ipaddress.IPv4Address(unicode(address)) return True except (AttributeError, ipaddress.AddressValueError): return False def valid_ipv6(address): """Check if IP address has the correct IPv6 address format. :param address: IP address. :type address: str :return: True in case of correct IPv6 address format, otherwise return false. :rtype: bool """ try: ipaddress.IPv6Address(unicode(address)) return True except (AttributeError, ipaddress.AddressValueError): return False def main(): """Send a simple L2 or ICMP packet from one TG interface to DUT, then receive a copy of the packet on the second TG interface, and a copy of the ICMP reply.""" args = TrafficScriptArg(['tg_src_mac', 'src_ip', 'dst_ip', 'dut_if1_mac', 'ptype']) src_mac = args.get_arg('tg_src_mac') dst_mac = args.get_arg('dut_if1_mac') src_ip = args.get_arg('src_ip') dst_ip = args.get_arg('dst_ip') tx_if = args.get_arg('tx_if') rx_if = args.get_arg('rx_if') ptype = args.get_arg('ptype') rxq_mirrored = RxQueue(rx_if) rxq_tx = RxQueue(tx_if) txq = TxQueue(tx_if) sent = [] if ptype == "ARP": pkt_raw = (Ether(src=src_mac, dst=dst_mac) / ARP(hwsrc=src_mac, hwdst="00:00:00:00:00:00", psrc=src_ip, pdst=dst_ip, op="who-has")) elif ptype == "ICMP": if valid_ipv4(src_ip) and valid_ipv4(dst_ip): pkt_raw = (Ether(src=src_mac, dst=dst_mac) / IP(src=src_ip, dst=dst_ip) / ICMP(type="echo-request")) else: raise ValueError("IP addresses not in correct format") elif ptype == "ICMPv6": if valid_ipv6(src_ip) and valid_ipv6(dst_ip): pkt_raw = (Ether(src=src_mac, dst=dst_mac) / IPv6(src=src_ip, dst=dst_ip) / ICMPv6EchoRequest()) else: raise ValueError("IPv6 addresses not in correct format") else: raise RuntimeError("Unexpected payload type.") txq.send(pkt_raw) sent.append(auto_pad(pkt_raw)) # Receive copy of Rx packet. while True: ether = rxq_mirrored.recv(2) if ether is None: raise RuntimeError("Rx timeout of mirrored Rx packet") if ether.haslayer(ICMPv6ND_NS): # read another packet in the queue if the current one is ICMPv6ND_NS continue else: # otherwise process the current packet break pkt = auto_pad(pkt_raw) if str(ether) != str(pkt): print("Mirrored Rx packet doesn't match the original Rx packet.") if ether.src != src_mac or ether.dst != dst_mac: raise RuntimeError("MAC mismatch in mirrored Rx packet.") if ptype == "ARP": if not ether.haslayer(ARP): raise RuntimeError("Mirrored Rx packet is not an ARP packet.") if ether['ARP'].op != 1: # 1=who-has raise RuntimeError("Mirrored Rx packet is not an ARP request.") if ether['ARP'].hwsrc != src_mac or ether['ARP'].hwdst != dst_mac: raise RuntimeError("MAC mismatch in mirrored Rx ARP packet.") if ether['ARP'].psrc != src_ip or ether['ARP'].pdst != dst_ip: raise RuntimeError("IP address mismatch in mirrored " "Rx ARP packet.") elif ptype == "ICMP": if not ether.haslayer(IP): raise RuntimeError("Mirrored Rx packet is not an IPv4 packet.") if ether['IP'].src != src_ip or ether['IP'].dst != dst_ip: raise RuntimeError("IP address mismatch in mirrored " "Rx IPv4 packet.") if not ether.haslayer(ICMP): raise RuntimeError("Mirrored Rx packet is not an ICMP packet.") if ether['ICMP'].type != 8: # 8=echo-request raise RuntimeError("Mirrored Rx packet is not an ICMP " "echo request.") elif ptype == "ICMPv6": if not ether.haslayer(IPv6): raise RuntimeError("Mirrored Rx packet is not an IPv6 packet.") if ether['IPv6'].src != src_ip or ether['IPv6'].dst != dst_ip: raise RuntimeError("IP address mismatch in mirrored " "Rx IPv6 packet.") if not ether.haslayer(ICMPv6EchoRequest): raise RuntimeError("Mirrored Rx packet is not an ICMPv6 " "echo request.") print("Mirrored Rx packet check OK.\n") # Receive reply on TG Tx port. ether_repl = rxq_tx.recv(2, sent) if ether_repl is None: raise RuntimeError("Reply not received on TG Tx port.") print("Reply received on TG Tx port.\n") # Receive copy of Tx packet. ether = rxq_mirrored.recv(2) if ether is None: raise RuntimeError("Rx timeout of mirrored Tx packet") if str(ether) != str(ether_repl): print("Mirrored Tx packet doesn't match the received Tx packet.") if ether.src != ether_repl.src or ether.dst != ether_repl.dst: raise RuntimeError("MAC mismatch in mirrored Tx packet.") if ptype == "ARP": if not ether.haslayer(ARP): raise RuntimeError("Mirrored Tx packet is not an ARP packet.") if ether['ARP'].op != ether_repl['ARP'].op: # 2=is_at raise RuntimeError("ARP operational code mismatch " "in mirrored Tx packet.") if ether['ARP'].hwsrc != ether_repl['ARP'].hwsrc\ or ether['ARP'].hwdst != ether_repl['ARP'].hwdst: raise RuntimeError("MAC mismatch in mirrored Tx ARP packet.") if ether['ARP'].psrc != ether_repl['ARP'].psrc\ or ether['ARP'].pdst != ether_repl['ARP'].pdst: raise RuntimeError("IP address mismatch in mirrored " "Tx ARP packet.") elif ptype == "ICMP": if not ether.haslayer(IP): raise RuntimeError("Mirrored Tx packet is not an IPv4 packet.") if ether['IP'].src != ether_repl['IP'].src\ or ether['IP'].dst != ether_repl['IP'].dst: raise RuntimeError("IP address mismatch in mirrored " "Tx IPv4 packet.") if not ether.haslayer(ICMP): raise RuntimeError("Mirrored Tx packet is not an ICMP packet.") if ether['ICMP'].type != ether_repl['ICMP'].type: # 0=echo-reply raise RuntimeError("ICMP packet type mismatch " "in mirrored Tx packet.") elif ptype == "ICMPv6": if not ether.haslayer(IPv6): raise RuntimeError("Mirrored Tx packet is not an IPv6 packet.") if ether['IPv6'].src != ether_repl['IPv6'].src\ or ether['IPv6'].dst != ether_repl['IPv6'].dst: raise RuntimeError("IP address mismatch in mirrored " "Tx IPv6 packet.") if ether[2].name != ether_repl[2].name: raise RuntimeError("ICMPv6 message type mismatch " "in mirrored Tx packet.") print("Mirrored Tx packet check OK.\n") sys.exit(0) if __name__ == "__main__": main()