X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=test%2Ftest_ip6_nd_mirror_proxy.py;h=9214e32b4472ea647c44fd2623c2166e66078993;hb=d9b0c6fbf7aa5bd9af84264105b39c82028a4a29;hp=fa9880122fcef6ebaca13bff9733e645112417e7;hpb=f90348bcb4afd0af2611cefc43b17ef3042b511c;p=vpp.git diff --git a/test/test_ip6_nd_mirror_proxy.py b/test/test_ip6_nd_mirror_proxy.py index fa9880122fc..9214e32b447 100644 --- a/test/test_ip6_nd_mirror_proxy.py +++ b/test/test_ip6_nd_mirror_proxy.py @@ -7,8 +7,15 @@ from socket import AF_INET6, inet_pton, inet_ntop from framework import tag_fixme_vpp_workers from framework import VppTestCase, VppTestRunner from vpp_neighbor import VppNeighbor, find_nbr -from vpp_ip_route import VppIpRoute, VppRoutePath, find_route, \ - VppIpTable, DpoProto, FibPathType, VppIpInterfaceAddress +from vpp_ip_route import ( + VppIpRoute, + VppRoutePath, + find_route, + VppIpTable, + DpoProto, + FibPathType, + VppIpInterfaceAddress, +) from vpp_papi import VppEnum from vpp_ip import VppIpPuntRedirect @@ -16,14 +23,21 @@ import scapy.compat from scapy.packet import Raw from scapy.layers.l2 import Ether, ARP, Dot1Q from scapy.layers.inet import IP, UDP, TCP -from scapy.layers.inet6 import IPv6, ipv6nh, ICMPv6ND_NS, ICMPv6ND_NA, \ - ICMPv6NDOptSrcLLAddr, ICMPv6NDOptDstLLAddr, ICMPv6EchoRequest, \ - ICMPv6EchoReply +from scapy.layers.inet6 import ( + IPv6, + ipv6nh, + ICMPv6ND_NS, + ICMPv6ND_NA, + ICMPv6NDOptSrcLLAddr, + ICMPv6NDOptDstLLAddr, + ICMPv6EchoRequest, + ICMPv6EchoReply, +) from scapy.utils6 import in6_ptop, in6_getnsma, in6_getnsmac, in6_ismaddr class TestNDPROXY(VppTestCase): - """ IP6 ND (mirror) Proxy Test Case """ + """IP6 ND (mirror) Proxy Test Case""" @classmethod def setUpClass(self): @@ -49,7 +63,7 @@ class TestNDPROXY(VppTestCase): i.admin_down() def test_nd_mirror_proxy(self): - """ Interface (Mirror) Proxy ND """ + """Interface (Mirror) Proxy ND""" # # When VPP has an interface whose address is also applied to a TAP @@ -70,17 +84,19 @@ class TestNDPROXY(VppTestCase): # # Enable ND proxy on pg1 # - self.vapi.ip6nd_proxy_enable_disable(sw_if_index=self.pg1.sw_if_index, - is_enable=1) + self.vapi.ip6nd_proxy_enable_disable( + sw_if_index=self.pg1.sw_if_index, is_enable=1 + ) # # Send the ND request with an originating address that # is VPP's own address # - nd_req_from_host = (Ether(src=self.pg1.remote_mac, - dst=in6_getnsmac(nsma)) / - IPv6(dst=d, src=self.pg0.local_ip6) / - ICMPv6ND_NS(tgt=addr) / - ICMPv6NDOptSrcLLAddr(lladdr=self.pg1.remote_mac)) + nd_req_from_host = ( + Ether(src=self.pg1.remote_mac, dst=in6_getnsmac(nsma)) + / IPv6(dst=d, src=self.pg0.local_ip6) + / ICMPv6ND_NS(tgt=addr) + / ICMPv6NDOptSrcLLAddr(lladdr=self.pg1.remote_mac) + ) rx = self.send_and_expect(self.pg1, [nd_req_from_host], self.pg1) self.assertEqual(rx[0][Ether].src, self.pg1.local_mac) @@ -90,22 +106,19 @@ class TestNDPROXY(VppTestCase): self.assertEqual(ipv6nh[rx[0][IPv6].nh], "ICMPv6") self.assertEqual(rx[0][ICMPv6ND_NA].tgt, self.pg0.remote_ip6) self.assertTrue(rx[0].haslayer(ICMPv6NDOptDstLLAddr)) - self.assertEqual(rx[0][ICMPv6NDOptDstLLAddr].lladdr, - self.pg1.local_mac) + self.assertEqual(rx[0][ICMPv6NDOptDstLLAddr].lladdr, self.pg1.local_mac) # # Send the unicast ND request # - unicast_nd_req_from_host = (Ether(src=self.pg1.remote_mac, - dst=self.pg1.local_mac) / - IPv6(dst=self.pg0.remote_ip6, - src=self.pg1.remote_ip6_ll) / - ICMPv6ND_NS(tgt=self.pg0.remote_ip6) / - ICMPv6NDOptSrcLLAddr( - lladdr=self.pg1.remote_mac)) + unicast_nd_req_from_host = ( + Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac) + / IPv6(dst=self.pg0.remote_ip6, src=self.pg1.remote_ip6_ll) + / ICMPv6ND_NS(tgt=self.pg0.remote_ip6) + / ICMPv6NDOptSrcLLAddr(lladdr=self.pg1.remote_mac) + ) - rx = self.send_and_expect(self.pg1, [unicast_nd_req_from_host], - self.pg0) + rx = self.send_and_expect(self.pg1, [unicast_nd_req_from_host], self.pg0) self.assertEqual(rx[0][Ether].src, self.pg0.local_mac) self.assertEqual(rx[0][Ether].dst, in6_getnsmac(nsma)) self.assertEqual(rx[0][IPv6].src, self.pg0.local_ip6) @@ -113,8 +126,7 @@ class TestNDPROXY(VppTestCase): self.assertEqual(ipv6nh[rx[0][IPv6].nh], "ICMPv6") self.assertEqual(rx[0][ICMPv6ND_NS].tgt, self.pg0.remote_ip6) self.assertTrue(rx[0].haslayer(ICMPv6NDOptSrcLLAddr)) - self.assertEqual(rx[0][ICMPv6NDOptSrcLLAddr].lladdr, - self.pg0.local_mac) + self.assertEqual(rx[0][ICMPv6NDOptSrcLLAddr].lladdr, self.pg0.local_mac) # Resolve the NDs on the uplink self.pg0.resolve_ndp() @@ -123,28 +135,26 @@ class TestNDPROXY(VppTestCase): # Again send the unicast ND request, this time dst address should be # in local cache # - rx = self.send_and_expect(self.pg1, [unicast_nd_req_from_host], - self.pg1) + rx = self.send_and_expect(self.pg1, [unicast_nd_req_from_host], self.pg1) self.assertEqual(rx[0][Ether].src, self.pg1.local_mac) self.assertEqual(rx[0][Ether].dst, self.pg1.remote_mac) self.assertEqual(rx[0][IPv6].src, self.pg0.remote_ip6) - self.assertEqual(in6_ptop(rx[0][IPv6].dst), - in6_ptop(self.pg1.remote_ip6_ll)) + self.assertEqual(in6_ptop(rx[0][IPv6].dst), in6_ptop(self.pg1.remote_ip6_ll)) self.assertEqual(ipv6nh[rx[0][IPv6].nh], "ICMPv6") self.assertEqual(rx[0][ICMPv6ND_NA].tgt, self.pg0.remote_ip6) self.assertTrue(rx[0].haslayer(ICMPv6NDOptDstLLAddr)) - self.assertEqual(rx[0][ICMPv6NDOptDstLLAddr].lladdr, - self.pg1.local_mac) + self.assertEqual(rx[0][ICMPv6NDOptDstLLAddr].lladdr, self.pg1.local_mac) # # Send the Echo Request from host to remote (of uplink) # id = self.pg1.sw_if_index seq = 0x1 - echo_request = (Ether(dst=self.pg1.local_mac, - src=self.pg1.remote_mac) / - IPv6(dst=self.pg0.remote_ip6, src=self.pg0.local_ip6) / - ICMPv6EchoRequest(seq=seq, id=id)) + echo_request = ( + Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) + / IPv6(dst=self.pg0.remote_ip6, src=self.pg0.local_ip6) + / ICMPv6EchoRequest(seq=seq, id=id) + ) rx = self.send_and_expect(self.pg1, [echo_request], self.pg0) self.assertEqual(rx[0][Ether].src, self.pg0.local_mac) @@ -159,13 +169,16 @@ class TestNDPROXY(VppTestCase): # # setup a punt redirect so packets from the uplink go to the tap # - redirect = VppIpPuntRedirect(self, self.pg0.sw_if_index, - self.pg1.sw_if_index, self.pg0.local_ip6) + redirect = VppIpPuntRedirect( + self, self.pg0.sw_if_index, self.pg1.sw_if_index, self.pg0.local_ip6 + ) redirect.add_vpp_config() - echo_reply = (Ether(dst=self.pg0.remote_mac, src=self.pg0.local_mac) / - IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) / - ICMPv6EchoReply(seq=1, id=id)) + echo_reply = ( + Ether(dst=self.pg0.remote_mac, src=self.pg0.local_mac) + / IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) + / ICMPv6EchoReply(seq=1, id=id) + ) rx = self.send_and_expect(self.pg0, [echo_reply], self.pg1) self.assertEqual(rx[0][Ether].src, self.pg1.local_mac) @@ -180,9 +193,11 @@ class TestNDPROXY(VppTestCase): # # cleanup # - self.vapi.ip6nd_proxy_enable_disable(sw_if_index=self.pg1.sw_if_index, - is_enable=0) + self.vapi.ip6nd_proxy_enable_disable( + sw_if_index=self.pg1.sw_if_index, is_enable=0 + ) redirect.remove_vpp_config() -if __name__ == '__main__': + +if __name__ == "__main__": unittest.main(testRunner=VppTestRunner)