diff options
author | Paul Vinciguerra <pvinci@vinciconsulting.com> | 2018-11-24 22:19:12 -0800 |
---|---|---|
committer | Ole Trøan <otroan@employees.org> | 2018-11-30 07:43:05 +0000 |
commit | 978aa643ca32ab220be940290039eb11e068bb73 (patch) | |
tree | 4573250d3c0fe7a814cdd55647f2e1d86ebf770e /test | |
parent | fa76a76bf3388f09d55d0c83e7aea507c44f9619 (diff) |
Tests: Fix traceback.
self.assertTrue(packet.haslayer(msg_type))
File "/usr/lib/python2.7/unittest/case.py", line 422, in assertTrue
raise self.failureException(msg)
AssertionError: 0 is not true
* Scapy packet.haslayer() returns 1 or 0.
Replace with assertEqual(packet.haslayer(), 1) to fix tracebacks.
* Scapy has multiple layers called TCP/UDP
Specify the module name to prevent namespace collisions.
* Remove duplicate import.
Change-Id: I600f9f330075cd40e1da50f8b2ceb24f645f2c20
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/test_dhcp6.py | 12 | ||||
-rw-r--r-- | test/test_ip6.py | 270 | ||||
-rw-r--r-- | test/test_nat.py | 29 |
3 files changed, 182 insertions, 129 deletions
diff --git a/test/test_dhcp6.py b/test/test_dhcp6.py index fe06f986bf5..6c203868673 100644 --- a/test/test_dhcp6.py +++ b/test/test_dhcp6.py @@ -61,8 +61,8 @@ class TestDHCPv6DataPlane(VppTestCase): self.assertEqual(len(rx_list), 1) packet = rx_list[0] - self.assertTrue(packet.haslayer(IPv6)) - self.assertTrue(packet[IPv6].haslayer(DHCP6_Solicit)) + self.assertEqual(packet.haslayer(IPv6), 1) + self.assertEqual(packet[IPv6].haslayer(DHCP6_Solicit), 1) client_duid = packet[DHCP6OptClientId].duid trid = packet[DHCP6_Solicit].trid @@ -137,8 +137,8 @@ class TestDHCPv6DataPlane(VppTestCase): self.assertEqual(len(rx_list), 1) packet = rx_list[0] - self.assertTrue(packet.haslayer(IPv6)) - self.assertTrue(packet[IPv6].haslayer(DHCP6_Solicit)) + self.assertEqual(packet.haslayer(IPv6), 1) + self.assertEqual(packet[IPv6].haslayer(DHCP6_Solicit), 1) client_duid = packet[DHCP6OptClientId].duid trid = packet[DHCP6_Solicit].trid @@ -256,7 +256,7 @@ class TestDHCPv6IANAControlPlane(VppTestCase): def validate_packet(self, packet, msg_type, is_resend=False): try: - self.assertTrue(packet.haslayer(msg_type)) + self.assertEqual(packet.haslayer(msg_type), 1) client_duid = packet[DHCP6OptClientId].duid if self.client_duid is None: self.client_duid = client_duid @@ -508,7 +508,7 @@ class TestDHCPv6PDControlPlane(VppTestCase): def validate_packet(self, packet, msg_type, is_resend=False): try: - self.assertTrue(packet.haslayer(msg_type)) + self.assertEqual(packet.haslayer(msg_type), 1) client_duid = packet[DHCP6OptClientId].duid if self.client_duid is None: self.client_duid = client_duid diff --git a/test/test_ip6.py b/test/test_ip6.py index 1d7fa766d14..849e9f73a41 100644 --- a/test/test_ip6.py +++ b/test/test_ip6.py @@ -15,8 +15,9 @@ from vpp_neighbor import find_nbr, VppNeighbor from scapy.packet import Raw from scapy.layers.l2 import Ether, Dot1Q -from scapy.layers.inet6 import IPv6, UDP, TCP, ICMPv6ND_NS, ICMPv6ND_RS, \ - ICMPv6ND_RA, ICMPv6NDOptSrcLLAddr, getmacbyip6, ICMPv6MRD_Solicitation, \ +import scapy.layers.inet6 as inet6 +from scapy.layers.inet6 import IPv6, ICMPv6ND_NS, ICMPv6ND_RS, \ + ICMPv6ND_RA, getmacbyip6, ICMPv6MRD_Solicitation, \ ICMPv6NDOptMTU, ICMPv6NDOptSrcLLAddr, ICMPv6NDOptPrefixInfo, \ ICMPv6ND_NA, ICMPv6NDOptDstLLAddr, ICMPv6DestUnreach, icmp6types, \ ICMPv6TimeExceeded, ICMPv6EchoRequest, ICMPv6EchoReply @@ -25,7 +26,6 @@ from scapy.utils6 import in6_getnsma, in6_getnsmac, in6_ptop, in6_islladdr, \ from scapy.utils import inet_pton, inet_ntop from scapy.contrib.mpls import MPLS - AF_INET6 = socket.AF_INET6 @@ -74,7 +74,8 @@ class TestIPv6ND(VppTestCase): in6_ptop(dst_ip)) # and come from the target address - self.assertEqual(in6_ptop(rx[IPv6].src), in6_ptop(tgt_ip)) + self.assertEqual( + in6_ptop(rx[IPv6].src), in6_ptop(tgt_ip)) # Dest link-layer options should have the router's MAC dll = rx[ICMPv6NDOptDstLLAddr] @@ -92,14 +93,16 @@ class TestIPv6ND(VppTestCase): # the rx'd NS should be addressed to an mcast address # derived from the target address - self.assertEqual(in6_ptop(rx[IPv6].dst), in6_ptop(dst_ip)) + self.assertEqual( + in6_ptop(rx[IPv6].dst), in6_ptop(dst_ip)) # expect the tgt IP in the NS header ns = rx[ICMPv6ND_NS] self.assertEqual(in6_ptop(ns.tgt), in6_ptop(tgt_ip)) # packet is from the router's local address - self.assertEqual(in6_ptop(rx[IPv6].src), intf.local_ip6) + self.assertEqual( + in6_ptop(rx[IPv6].src), intf.local_ip6) # Src link-layer options should have the router's MAC sll = rx[ICMPv6NDOptSrcLLAddr] @@ -261,7 +264,7 @@ class TestIPv6(TestIPv6ND): dst_if = self.flows[src_if][dst_if_idx] info = self.create_packet_info(src_if, dst_if) payload = self.info_to_payload(info) - p = pkt/Raw(payload) + p = pkt / Raw(payload) p[IPv6].dst = dst_if.remote_ip6 info.data = p.copy() if isinstance(src_if, VppSubInterface): @@ -278,7 +281,7 @@ class TestIPv6(TestIPv6ND): hdr_ext = 4 if isinstance(src_if, VppSubInterface) else 0 pkt_tmpl = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) / IPv6(src=src_if.remote_ip6) / - UDP(sport=1234, dport=1234)) + inet6.UDP(sport=1234, dport=1234)) pkts = [self.modify_packet(src_if, i, pkt_tmpl) for i in xrange(self.pg_if_packet_sizes[0], @@ -312,7 +315,7 @@ class TestIPv6(TestIPv6ND): self.assertTrue(Dot1Q not in packet) try: ip = packet[IPv6] - udp = packet[UDP] + udp = packet[inet6.UDP] payload_info = self.payload_to_info(str(packet[Raw])) packet_index = payload_info.index self.assertEqual(payload_info.dst, dst_sw_if_index) @@ -327,10 +330,14 @@ class TestIPv6(TestIPv6ND): self.assertEqual(packet_index, next_info.index) saved_packet = next_info.data # Check standard fields - self.assertEqual(ip.src, saved_packet[IPv6].src) - self.assertEqual(ip.dst, saved_packet[IPv6].dst) - self.assertEqual(udp.sport, saved_packet[UDP].sport) - self.assertEqual(udp.dport, saved_packet[UDP].dport) + self.assertEqual( + ip.src, saved_packet[IPv6].src) + self.assertEqual( + ip.dst, saved_packet[IPv6].dst) + self.assertEqual( + udp.sport, saved_packet[inet6.UDP].sport) + self.assertEqual( + udp.dport, saved_packet[inet6.UDP].dport) except: self.logger.error(ppp("Unexpected or invalid packet:", packet)) raise @@ -385,7 +392,8 @@ class TestIPv6(TestIPv6ND): p = (Ether(dst=in6_getnsmac(nsma)) / IPv6(dst=d, src="2002::2") / ICMPv6ND_NS(tgt=self.pg0.local_ip6) / - ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac)) + ICMPv6NDOptSrcLLAddr( + lladdr=self.pg0.remote_mac)) pkts = [p] self.send_and_assert_no_replies( @@ -403,7 +411,8 @@ class TestIPv6(TestIPv6ND): p = (Ether(dst=in6_getnsmac(nsma)) / IPv6(dst=d, src=self.pg0.remote_ip6) / ICMPv6ND_NS(tgt=self.pg0.local_ip6) / - ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac)) + ICMPv6NDOptSrcLLAddr( + lladdr=self.pg0.remote_mac)) pkts = [p] self.send_and_assert_no_replies( @@ -419,7 +428,8 @@ class TestIPv6(TestIPv6ND): p = (Ether(dst=in6_getnsmac(nsma)) / IPv6(dst=d, src=self.pg0.remote_ip6) / ICMPv6ND_NS(tgt="fd::ffff") / - ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac)) + ICMPv6NDOptSrcLLAddr( + lladdr=self.pg0.remote_mac)) pkts = [p] self.send_and_assert_no_replies(self.pg0, pkts, @@ -454,9 +464,11 @@ class TestIPv6(TestIPv6ND): # address # p = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) / - IPv6(dst=d, src=self.pg0._remote_hosts[2].ip6_ll) / + IPv6( + dst=d, src=self.pg0._remote_hosts[2].ip6_ll) / ICMPv6ND_NS(tgt=self.pg0.local_ip6) / - ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac)) + ICMPv6NDOptSrcLLAddr( + lladdr=self.pg0.remote_mac)) self.send_and_expect_na(self.pg0, p, "NS from link-local", @@ -480,9 +492,11 @@ class TestIPv6(TestIPv6ND): # An NS to the router's own Link-local # p = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) / - IPv6(dst=d, src=self.pg0._remote_hosts[3].ip6_ll) / + IPv6( + dst=d, src=self.pg0._remote_hosts[3].ip6_ll) / ICMPv6ND_NS(tgt=self.pg0.local_ip6_ll) / - ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac)) + ICMPv6NDOptSrcLLAddr( + lladdr=self.pg0.remote_mac)) self.send_and_expect_na(self.pg0, p, "NS to/from link-local", @@ -533,7 +547,7 @@ class TestIPv6(TestIPv6ND): src=self.pg0.remote_mac) / IPv6(src=self.pg0.remote_ip6, dst=self.pg1.remote_hosts[1].ip6) / - UDP(sport=1234, dport=1234) / + inet6.UDP(sport=1234, dport=1234) / Raw()) self.pg0.add_stream(p) @@ -604,7 +618,8 @@ class TestIPv6(TestIPv6ND): if not pi_opt: # the RA should not contain prefix information - self.assertFalse(ra.haslayer(ICMPv6NDOptPrefixInfo)) + self.assertFalse(ra.haslayer( + ICMPv6NDOptPrefixInfo)) else: raos = rx.getlayer(ICMPv6NDOptPrefixInfo, 1) @@ -613,14 +628,16 @@ class TestIPv6(TestIPv6ND): # nested classes, so a direct obj1=obj2 comparison always fails. # however, the getlayer(.., 2) does give one instnace. # so we cheat here and construct a new opt instnace for comparison - rd = ICMPv6NDOptPrefixInfo(prefixlen=raos.prefixlen, - prefix=raos.prefix, - L=raos.L, - A=raos.A) + rd = ICMPv6NDOptPrefixInfo( + prefixlen=raos.prefixlen, + prefix=raos.prefix, + L=raos.L, + A=raos.A) if type(pi_opt) is list: for ii in range(len(pi_opt)): self.assertEqual(pi_opt[ii], rd) - rd = rx.getlayer(ICMPv6NDOptPrefixInfo, ii+2) + rd = rx.getlayer( + ICMPv6NDOptPrefixInfo, ii + 2) else: self.assertEqual(pi_opt, raos) @@ -657,7 +674,8 @@ class TestIPv6(TestIPv6ND): # - expect an RA in return # p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / - IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) / + IPv6( + dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) / ICMPv6ND_RS()) pkts = [p] self.send_and_expect_ra(self.pg0, pkts, "Genuine RS") @@ -680,7 +698,8 @@ class TestIPv6(TestIPv6ND): # self.pg0.ip6_ra_config(send_unicast=1) p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / - IPv6(dst=self.pg0.local_ip6, src="2002::ffff") / + IPv6(dst=self.pg0.local_ip6, + src="2002::ffff") / ICMPv6ND_RS()) pkts = [p] self.send_and_assert_no_replies(self.pg0, pkts, @@ -740,10 +759,11 @@ class TestIPv6(TestIPv6ND): # # RAs should now contain the prefix information option # - opt = ICMPv6NDOptPrefixInfo(prefixlen=self.pg0.local_ip6_prefix_len, - prefix=self.pg0.local_ip6, - L=1, - A=1) + opt = ICMPv6NDOptPrefixInfo( + prefixlen=self.pg0.local_ip6_prefix_len, + prefix=self.pg0.local_ip6, + L=1, + A=1) self.pg0.ip6_ra_config(send_unicast=1) ll = mk_ll_addr(self.pg0.remote_mac) @@ -763,10 +783,11 @@ class TestIPv6(TestIPv6ND): self.pg0.local_ip6_prefix_len, off_link=1) - opt = ICMPv6NDOptPrefixInfo(prefixlen=self.pg0.local_ip6_prefix_len, - prefix=self.pg0.local_ip6, - L=0, - A=1) + opt = ICMPv6NDOptPrefixInfo( + prefixlen=self.pg0.local_ip6_prefix_len, + prefix=self.pg0.local_ip6, + L=0, + A=1) self.pg0.ip6_ra_config(send_unicast=1) self.send_and_expect_ra(self.pg0, p, @@ -783,10 +804,11 @@ class TestIPv6(TestIPv6ND): off_link=1, no_autoconfig=1) - opt = ICMPv6NDOptPrefixInfo(prefixlen=self.pg0.local_ip6_prefix_len, - prefix=self.pg0.local_ip6, - L=0, - A=0) + opt = ICMPv6NDOptPrefixInfo( + prefixlen=self.pg0.local_ip6_prefix_len, + prefix=self.pg0.local_ip6, + L=0, + A=0) self.pg0.ip6_ra_config(send_unicast=1) self.send_and_expect_ra(self.pg0, p, @@ -801,10 +823,11 @@ class TestIPv6(TestIPv6ND): self.pg0.ip6_ra_prefix(self.pg0.local_ip6n, self.pg0.local_ip6_prefix_len) - opt = ICMPv6NDOptPrefixInfo(prefixlen=self.pg0.local_ip6_prefix_len, - prefix=self.pg0.local_ip6, - L=1, - A=1) + opt = ICMPv6NDOptPrefixInfo( + prefixlen=self.pg0.local_ip6_prefix_len, + prefix=self.pg0.local_ip6, + L=1, + A=1) self.pg0.ip6_ra_config(send_unicast=1) self.send_and_expect_ra(self.pg0, p, @@ -821,10 +844,11 @@ class TestIPv6(TestIPv6ND): off_link=1, no_autoconfig=1) - opt = ICMPv6NDOptPrefixInfo(prefixlen=self.pg0.local_ip6_prefix_len, - prefix=self.pg0.local_ip6, - L=0, - A=0) + opt = ICMPv6NDOptPrefixInfo( + prefixlen=self.pg0.local_ip6_prefix_len, + prefix=self.pg0.local_ip6, + L=0, + A=0) self.pg0.ip6_ra_config(send_unicast=1) self.send_and_expect_ra(self.pg0, p, @@ -840,10 +864,11 @@ class TestIPv6(TestIPv6ND): self.pg0.local_ip6_prefix_len, use_default=1) - opt = ICMPv6NDOptPrefixInfo(prefixlen=self.pg0.local_ip6_prefix_len, - prefix=self.pg0.local_ip6, - L=1, - A=1) + opt = ICMPv6NDOptPrefixInfo( + prefixlen=self.pg0.local_ip6_prefix_len, + prefix=self.pg0.local_ip6, + L=1, + A=1) self.pg0.ip6_ra_config(send_unicast=1) self.send_and_expect_ra(self.pg0, p, @@ -859,14 +884,16 @@ class TestIPv6(TestIPv6ND): off_link=1, no_autoconfig=1) - opt = [ICMPv6NDOptPrefixInfo(prefixlen=self.pg0.local_ip6_prefix_len, - prefix=self.pg0.local_ip6, - L=1, - A=1), - ICMPv6NDOptPrefixInfo(prefixlen=self.pg1.local_ip6_prefix_len, - prefix=self.pg1.local_ip6, - L=0, - A=0)] + opt = [ICMPv6NDOptPrefixInfo( + prefixlen=self.pg0.local_ip6_prefix_len, + prefix=self.pg0.local_ip6, + L=1, + A=1), + ICMPv6NDOptPrefixInfo( + prefixlen=self.pg1.local_ip6_prefix_len, + prefix=self.pg1.local_ip6, + L=0, + A=0)] self.pg0.ip6_ra_config(send_unicast=1) ll = mk_ll_addr(self.pg0.remote_mac) @@ -886,10 +913,11 @@ class TestIPv6(TestIPv6ND): self.pg0.local_ip6_prefix_len, is_no=1) - opt = ICMPv6NDOptPrefixInfo(prefixlen=self.pg1.local_ip6_prefix_len, - prefix=self.pg1.local_ip6, - L=0, - A=0) + opt = ICMPv6NDOptPrefixInfo( + prefixlen=self.pg1.local_ip6_prefix_len, + prefix=self.pg1.local_ip6, + L=0, + A=0) self.pg0.ip6_ra_config(send_unicast=1) self.send_and_expect_ra(self.pg0, p, @@ -952,8 +980,10 @@ class TestICMPv6Echo(VppTestCase): dst=self.pg0.local_mac) / IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6) / - ICMPv6EchoRequest(id=icmpv6_id, seq=icmpv6_seq, - data=icmpv6_data)) + ICMPv6EchoRequest( + id=icmpv6_id, + seq=icmpv6_seq, + data=icmpv6_data)) self.pg0.add_stream(p_echo_request) self.pg_enable_capture(self.pg_interfaces) @@ -971,7 +1001,8 @@ class TestICMPv6Echo(VppTestCase): self.assertEqual(ipv6.src, self.pg0.local_ip6) self.assertEqual(ipv6.dst, self.pg0.remote_ip6) - self.assertEqual(icmp6types[icmpv6.type], "Echo Reply") + self.assertEqual( + icmp6types[icmpv6.type], "Echo Reply") self.assertEqual(icmpv6.id, icmpv6_id) self.assertEqual(icmpv6.seq, icmpv6_seq) self.assertEqual(icmpv6.data, icmpv6_data) @@ -1014,17 +1045,21 @@ class TestIPv6RD(TestIPv6ND): rx_list = self.pg1.get_capture(count, timeout=3) self.assertEqual(len(rx_list), count) for packet in rx_list: - self.assertTrue(packet.haslayer(IPv6)) - self.assertTrue(packet[IPv6].haslayer(ICMPv6ND_RS)) + self.assertEqual(packet.haslayer(IPv6), 1) + self.assertEqual(packet[IPv6].haslayer( + ICMPv6ND_RS), 1) dst = ip6_normalize(packet[IPv6].dst) dst2 = ip6_normalize("ff02::2") self.assert_equal(dst, dst2) src = ip6_normalize(packet[IPv6].src) src2 = ip6_normalize(self.pg1.local_ip6_ll) self.assert_equal(src, src2) - self.assertTrue(packet[ICMPv6ND_RS].haslayer(ICMPv6NDOptSrcLLAddr)) - self.assert_equal(packet[ICMPv6NDOptSrcLLAddr].lladdr, - self.pg1.local_mac) + self.assertTrue( + bool(packet[ICMPv6ND_RS].haslayer( + ICMPv6NDOptSrcLLAddr))) + self.assert_equal( + packet[ICMPv6NDOptSrcLLAddr].lladdr, + self.pg1.local_mac) def verify_prefix_info(self, reported_prefix, prefix_option): prefix = socket.inet_pton(socket.AF_INET6, @@ -1160,7 +1195,8 @@ class TestIPv6RDControlPlane(TestIPv6ND): self.sleep(0.1) # send RA - packet = (self.create_ra_packet(self.pg0) / ICMPv6NDOptPrefixInfo( + packet = (self.create_ra_packet( + self.pg0) / ICMPv6NDOptPrefixInfo( prefix="1::", prefixlen=64, validlifetime=2, @@ -1300,9 +1336,11 @@ class IPv6NDProxyTest(TestIPv6ND): # on the link that has the prefix configured # ns_pg1 = (Ether(dst=in6_getnsmac(nsma), src=self.pg1.remote_mac) / - IPv6(dst=d, src=self.pg0._remote_hosts[2].ip6) / + IPv6(dst=d, + src=self.pg0._remote_hosts[2].ip6) / ICMPv6ND_NS(tgt=self.pg0.local_ip6) / - ICMPv6NDOptSrcLLAddr(lladdr=self.pg0._remote_hosts[2].mac)) + ICMPv6NDOptSrcLLAddr( + lladdr=self.pg0._remote_hosts[2].mac)) self.send_and_assert_no_replies(self.pg1, ns_pg1, "Off link NS") @@ -1335,7 +1373,7 @@ class IPv6NDProxyTest(TestIPv6ND): t = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / IPv6(dst=self.pg0._remote_hosts[2].ip6, src=self.pg0.remote_ip6) / - UDP(sport=10000, dport=20000) / + inet6.UDP(sport=10000, dport=20000) / Raw('\xa5' * 100)) self.pg0.add_stream(t) @@ -1347,16 +1385,20 @@ class IPv6NDProxyTest(TestIPv6ND): self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac) self.assertEqual(rx[Ether].src, self.pg1.local_mac) - self.assertEqual(rx[IPv6].src, t[IPv6].src) - self.assertEqual(rx[IPv6].dst, t[IPv6].dst) + self.assertEqual(rx[IPv6].src, + t[IPv6].src) + self.assertEqual(rx[IPv6].dst, + t[IPv6].dst) # # Test we proxy for the host on the main interface # ns_pg0 = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) / IPv6(dst=d, src=self.pg0.remote_ip6) / - ICMPv6ND_NS(tgt=self.pg0._remote_hosts[2].ip6) / - ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac)) + ICMPv6ND_NS( + tgt=self.pg0._remote_hosts[2].ip6) / + ICMPv6NDOptSrcLLAddr( + lladdr=self.pg0.remote_mac)) self.send_and_expect_na(self.pg0, ns_pg0, "NS to proxy entry on main", @@ -1367,9 +1409,11 @@ class IPv6NDProxyTest(TestIPv6ND): # Setup and resolve proxy for another host on another interface # ns_pg2 = (Ether(dst=in6_getnsmac(nsma), src=self.pg2.remote_mac) / - IPv6(dst=d, src=self.pg0._remote_hosts[3].ip6) / + IPv6(dst=d, + src=self.pg0._remote_hosts[3].ip6) / ICMPv6ND_NS(tgt=self.pg0.local_ip6) / - ICMPv6NDOptSrcLLAddr(lladdr=self.pg0._remote_hosts[2].mac)) + ICMPv6NDOptSrcLLAddr( + lladdr=self.pg0._remote_hosts[2].mac)) self.vapi.ip6_nd_proxy( inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6), @@ -1392,7 +1436,7 @@ class IPv6NDProxyTest(TestIPv6ND): src=self.pg0.remote_hosts[3].mac) / IPv6(dst=self.pg0._remote_hosts[2].ip6, src=self.pg0._remote_hosts[3].ip6) / - UDP(sport=10000, dport=20000) / + inet6.UDP(sport=10000, dport=20000) / Raw('\xa5' * 100)) self.pg2.add_stream(t2) @@ -1404,8 +1448,10 @@ class IPv6NDProxyTest(TestIPv6ND): self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac) self.assertEqual(rx[Ether].src, self.pg1.local_mac) - self.assertEqual(rx[IPv6].src, t2[IPv6].src) - self.assertEqual(rx[IPv6].dst, t2[IPv6].dst) + self.assertEqual(rx[IPv6].src, + t2[IPv6].src) + self.assertEqual(rx[IPv6].dst, + t2[IPv6].dst) # # remove the proxy configs @@ -1474,7 +1520,7 @@ class TestIPNull(VppTestCase): p = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / IPv6(src=self.pg0.remote_ip6, dst="2001::1") / - UDP(sport=1234, dport=1234) / + inet6.UDP(sport=1234, dport=1234) / Raw('\xa5' * 100)) # @@ -1561,12 +1607,12 @@ class TestIPDisabled(VppTestCase): pu = (Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac) / IPv6(src="2001::1", dst=self.pg0.remote_ip6) / - UDP(sport=1234, dport=1234) / + inet6.UDP(sport=1234, dport=1234) / Raw('\xa5' * 100)) pm = (Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac) / IPv6(src="2001::1", dst="ffef::1") / - UDP(sport=1234, dport=1234) / + inet6.UDP(sport=1234, dport=1234) / Raw('\xa5' * 100)) # @@ -1667,9 +1713,10 @@ class TestIP6LoadBalance(VppTestCase): src_mpls_pkts = [] for ii in range(65): - port_ip_hdr = (IPv6(dst="3000::1", src="3000:1::1") / - UDP(sport=1234, dport=1234 + ii) / - Raw('\xa5' * 100)) + port_ip_hdr = ( + IPv6(dst="3000::1", src="3000:1::1") / + inet6.UDP(sport=1234, dport=1234 + ii) / + Raw('\xa5' * 100)) port_ip_pkts.append((Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / port_ip_hdr)) @@ -1688,9 +1735,10 @@ class TestIP6LoadBalance(VppTestCase): MPLS(label=14, ttl=2) / MPLS(label=999, ttl=2) / port_ip_hdr)) - src_ip_hdr = (IPv6(dst="3000::1", src="3000:1::%d" % ii) / - UDP(sport=1234, dport=1234) / - Raw('\xa5' * 100)) + src_ip_hdr = ( + IPv6(dst="3000::1", src="3000:1::%d" % ii) / + inet6.UDP(sport=1234, dport=1234) / + Raw('\xa5' * 100)) src_ip_pkts.append((Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / src_ip_hdr)) @@ -1787,13 +1835,16 @@ class TestIP6LoadBalance(VppTestCase): for ii in range(257): port_pkts.append((Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / - IPv6(dst="4000::1", src="4000:1::1") / - UDP(sport=1234, dport=1234 + ii) / + IPv6(dst="4000::1", + src="4000:1::1") / + inet6.UDP(sport=1234, + dport=1234 + ii) / Raw('\xa5' * 100))) src_pkts.append((Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / - IPv6(dst="4000::1", src="4000:1::%d" % ii) / - UDP(sport=1234, dport=1234) / + IPv6(dst="4000::1", + src="4000:1::%d" % ii) / + inet6.UDP(sport=1234, dport=1234) / Raw('\xa5' * 100))) route_3000_2 = VppIpRoute(self, "3000::2", 128, @@ -1836,8 +1887,10 @@ class TestIP6LoadBalance(VppTestCase): for ii in range(257): port_pkts.append((Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / - IPv6(dst="6000::1", src="6000:1::1") / - UDP(sport=1234, dport=1234 + ii) / + IPv6(dst="6000::1", + src="6000:1::1") / + inet6.UDP(sport=1234, + dport=1234 + ii) / Raw('\xa5' * 100))) route_5000_2 = VppIpRoute(self, "5000::2", 128, @@ -1885,8 +1938,9 @@ class TestIP6Punt(VppTestCase): p = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / - IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6) / - TCP(sport=1234, dport=1234) / + IPv6(src=self.pg0.remote_ip6, + dst=self.pg0.local_ip6) / + inet6.TCP(sport=1234, dport=1234) / Raw('\xa5' * 100)) pkts = p * 1025 @@ -2047,12 +2101,12 @@ class TestIPDeag(VppTestCase): p_dst = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / IPv6(src="5::5", dst="1::1") / - TCP(sport=1234, dport=1234) / + inet6.TCP(sport=1234, dport=1234) / Raw('\xa5' * 100)) p_src = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / IPv6(src="2::2", dst="1::2") / - TCP(sport=1234, dport=1234) / + inet6.TCP(sport=1234, dport=1234) / Raw('\xa5' * 100)) pkts_dst = p_dst * 257 pkts_src = p_src * 257 @@ -2100,7 +2154,7 @@ class TestIPDeag(VppTestCase): p_l = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / IPv6(src="3::4", dst="3::3") / - TCP(sport=1234, dport=1234) / + inet6.TCP(sport=1234, dport=1234) / Raw('\xa5' * 100)) self.send_and_assert_no_replies(self.pg0, p_l * 257, @@ -2137,7 +2191,7 @@ class TestIP6Input(VppTestCase): IPv6(src=self.pg0.remote_ip6, dst=self.pg1.remote_ip6, version=3) / - UDP(sport=1234, dport=1234) / + inet6.UDP(sport=1234, dport=1234) / Raw('\xa5' * 100)) self.send_and_assert_no_replies(self.pg0, p_version * 65, @@ -2151,7 +2205,7 @@ class TestIP6Input(VppTestCase): IPv6(src=self.pg0.remote_ip6, dst=self.pg1.remote_ip6, hlim=1) / - UDP(sport=1234, dport=1234) / + inet6.UDP(sport=1234, dport=1234) / Raw('\xa5' * 100)) rx = self.send_and_expect(self.pg0, p_version * 65, self.pg0) diff --git a/test/test_nat.py b/test/test_nat.py index b7b80c95c2a..c03cf08323b 100644 --- a/test/test_nat.py +++ b/test/test_nat.py @@ -10,12 +10,11 @@ from framework import VppTestCase, VppTestRunner, running_extended_tests from scapy.layers.inet import IP, TCP, UDP, ICMP from scapy.layers.inet import IPerror, TCPerror, UDPerror, ICMPerror from scapy.layers.inet6 import IPv6, ICMPv6EchoRequest, ICMPv6EchoReply, \ - ICMPv6ND_NS, ICMPv6ND_NA, ICMPv6NDOptDstLLAddr + ICMPv6ND_NS, ICMPv6ND_NA, ICMPv6NDOptDstLLAddr, fragment6 from scapy.layers.inet6 import ICMPv6DestUnreach, IPerror6, IPv6ExtHdrFragment from scapy.layers.l2 import Ether, ARP, GRE from scapy.data import IP_PROTOS from scapy.packet import bind_layers, Raw -from scapy.all import fragment6 from util import ppp from ipfix import IPFIX, Set, Template, Data, IPFIXDecoder from time import sleep @@ -579,7 +578,7 @@ class MethodHolder(VppTestCase): for packet in capture: try: self.assertEqual(packet[IP].src, src_ip) - self.assertTrue(packet.haslayer(ICMP)) + self.assertEqual(packet.haslayer(ICMP), 1) icmp = packet[ICMP] self.assertEqual(icmp.type, icmp_type) self.assertTrue(icmp.haslayer(IPerror)) @@ -609,7 +608,7 @@ class MethodHolder(VppTestCase): for packet in capture: try: self.assertEqual(packet[IP].dst, in_if.remote_ip4) - self.assertTrue(packet.haslayer(ICMP)) + self.assertEqual(packet.haslayer(ICMP), 1) icmp = packet[ICMP] self.assertEqual(icmp.type, icmp_type) self.assertTrue(icmp.haslayer(IPerror)) @@ -3073,7 +3072,7 @@ class TestNAT44(MethodHolder): try: self.assertEqual(packet[IP].src, nat_ip) self.assertEqual(packet[IP].dst, self.pg1.remote_ip4) - self.assertTrue(packet.haslayer(GRE)) + self.assertEqual(packet.haslayer(GRE), 1) self.assert_packet_checksums_valid(packet) except: self.logger.error(ppp("Unexpected or invalid packet:", packet)) @@ -3093,7 +3092,7 @@ class TestNAT44(MethodHolder): try: self.assertEqual(packet[IP].src, self.pg1.remote_ip4) self.assertEqual(packet[IP].dst, self.pg0.remote_ip4) - self.assertTrue(packet.haslayer(GRE)) + self.assertEqual(packet.haslayer(GRE), 1) self.assert_packet_checksums_valid(packet) except: self.logger.error(ppp("Unexpected or invalid packet:", packet)) @@ -3128,7 +3127,7 @@ class TestNAT44(MethodHolder): try: self.assertEqual(packet[IP].src, host_nat_ip) self.assertEqual(packet[IP].dst, server.ip4) - self.assertTrue(packet.haslayer(GRE)) + self.assertEqual(packet.haslayer(GRE), 1) self.assert_packet_checksums_valid(packet) except: self.logger.error(ppp("Unexpected or invalid packet:", packet)) @@ -3148,7 +3147,7 @@ class TestNAT44(MethodHolder): try: self.assertEqual(packet[IP].src, server_nat_ip) self.assertEqual(packet[IP].dst, host.ip4) - self.assertTrue(packet.haslayer(GRE)) + self.assertEqual(packet.haslayer(GRE), 1) self.assert_packet_checksums_valid(packet) except: self.logger.error(ppp("Unexpected or invalid packet:", packet)) @@ -4428,7 +4427,7 @@ class TestNAT44EndpointDependent(MethodHolder): try: self.assertEqual(packet[IP].src, self.nat_addr) self.assertEqual(packet[IP].dst, self.pg1.remote_ip4) - self.assertTrue(packet.haslayer(GRE)) + self.assertEqual(packet.haslayer(GRE), 1) self.assert_packet_checksums_valid(packet) except: self.logger.error(ppp("Unexpected or invalid packet:", packet)) @@ -4448,7 +4447,7 @@ class TestNAT44EndpointDependent(MethodHolder): try: self.assertEqual(packet[IP].src, self.pg1.remote_ip4) self.assertEqual(packet[IP].dst, self.pg0.remote_ip4) - self.assertTrue(packet.haslayer(GRE)) + self.assertEqual(packet.haslayer(GRE), 1) self.assert_packet_checksums_valid(packet) except: self.logger.error(ppp("Unexpected or invalid packet:", packet)) @@ -4492,7 +4491,7 @@ class TestNAT44EndpointDependent(MethodHolder): try: self.assertEqual(packet[IP].src, self.nat_addr) self.assertEqual(packet[IP].dst, server.ip4) - self.assertTrue(packet.haslayer(GRE)) + self.assertEqual(packet.haslayer(GRE), 1) self.assert_packet_checksums_valid(packet) except: self.logger.error(ppp("Unexpected or invalid packet:", packet)) @@ -4512,7 +4511,7 @@ class TestNAT44EndpointDependent(MethodHolder): try: self.assertEqual(packet[IP].src, server_nat_ip) self.assertEqual(packet[IP].dst, host.ip4) - self.assertTrue(packet.haslayer(GRE)) + self.assertEqual(packet.haslayer(GRE), 1) self.assert_packet_checksums_valid(packet) except: self.logger.error(ppp("Unexpected or invalid packet:", packet)) @@ -6693,7 +6692,7 @@ class TestNAT64(MethodHolder): packet = capture[0] try: self.assertEqual(packet[IPv6].src, self.pg5.local_ip6) - self.assertTrue(packet.haslayer(ICMPv6ND_NS)) + self.assertEqual(packet.haslayer(ICMPv6ND_NS), 1) tgt = packet[ICMPv6ND_NS].tgt except: self.logger.error(ppp("Unexpected or invalid packet:", packet)) @@ -6721,7 +6720,7 @@ class TestNAT64(MethodHolder): try: self.assertEqual(packet[IPv6].src, self.pg5.local_ip6) self.assertEqual(packet[IPv6].dst, self.pg5.remote_ip6) - self.assertTrue(packet.haslayer(ICMPv6EchoReply)) + self.assertEqual(packet.haslayer(ICMPv6EchoReply), 1) except: self.logger.error(ppp("Unexpected or invalid packet:", packet)) raise @@ -7300,7 +7299,7 @@ class TestNAT64(MethodHolder): try: self.assertEqual(packet[IP].src, self.nat_addr) self.assertEqual(packet[IP].dst, self.pg1.remote_ip4) - self.assertTrue(packet.haslayer(GRE)) + self.assertEqual(packet.haslayer(GRE), 1) self.assert_packet_checksums_valid(packet) except: self.logger.error(ppp("Unexpected or invalid packet:", packet)) |