X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=test%2Ftest_svs.py;h=916039664534bb1bd83cff535a93f8be6fa59ebc;hb=a6b1a7d809e746325fe712b9de9ff086e55772dd;hp=563ed1ad0cb61ee6766a971fd3974adcd742502f;hpb=8feeaff56fa9a4fbdfc06131f28a1060ffd9645d;p=vpp.git diff --git a/test/test_svs.py b/test/test_svs.py index 563ed1ad0cb..91603966453 100644 --- a/test/test_svs.py +++ b/test/test_svs.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import unittest @@ -12,9 +12,19 @@ from scapy.layers.inet6 import IPv6 from vpp_papi import VppEnum +NUM_PKTS = 67 + class TestSVS(VppTestCase): - """ SVS Test Case """ + """SVS Test Case""" + + @classmethod + def setUpClass(cls): + super(TestSVS, cls).setUpClass() + + @classmethod + def tearDownClass(cls): + super(TestSVS, cls).tearDownClass() def setUp(self): super(TestSVS, self).setUp() @@ -45,42 +55,57 @@ class TestSVS(VppTestCase): for i in self.pg_interfaces: i.unconfig_ip4() i.unconfig_ip6() - i.ip6_disable() i.set_table_ip4(0) i.set_table_ip6(0) i.admin_down() super(TestSVS, self).tearDown() def test_svs4(self): - """ Source VRF Select IP4 """ + """Source VRF Select IP4""" # # packets destined out of the 3 non-default table interfaces # - pkts_0 = [(Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / - IP(src="1.1.1.1", dst=self.pg1.remote_ip4) / - UDP(sport=1234, dport=1234) / - Raw('\xa5' * 100)), - (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / - IP(src="2.2.2.2", dst=self.pg2.remote_ip4) / - UDP(sport=1234, dport=1234) / - Raw('\xa5' * 100)), - (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / - IP(src="3.3.3.3", dst=self.pg3.remote_ip4) / - UDP(sport=1234, dport=1234) / - Raw('\xa5' * 100))] - pkts_1 = [(Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) / - IP(src="1.1.1.1", dst=self.pg1.remote_ip4) / - UDP(sport=1234, dport=1234) / - Raw('\xa5' * 100)), - (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) / - IP(src="2.2.2.2", dst=self.pg2.remote_ip4) / - UDP(sport=1234, dport=1234) / - Raw('\xa5' * 100)), - (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) / - IP(src="3.3.3.3", dst=self.pg3.remote_ip4) / - UDP(sport=1234, dport=1234) / - Raw('\xa5' * 100))] + pkts_0 = [ + ( + Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) + / IP(src="1.1.1.1", dst=self.pg1.remote_ip4) + / UDP(sport=1234, dport=1234) + / Raw(b"\xa5" * 100) + ), + ( + Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) + / IP(src="2.2.2.2", dst=self.pg2.remote_ip4) + / UDP(sport=1234, dport=1234) + / Raw(b"\xa5" * 100) + ), + ( + Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) + / IP(src="3.3.3.3", dst=self.pg3.remote_ip4) + / UDP(sport=1234, dport=1234) + / Raw(b"\xa5" * 100) + ), + ] + pkts_1 = [ + ( + Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) + / IP(src="1.1.1.1", dst=self.pg1.remote_ip4) + / UDP(sport=1234, dport=1234) + / Raw(b"\xa5" * 100) + ), + ( + Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) + / IP(src="2.2.2.2", dst=self.pg2.remote_ip4) + / UDP(sport=1234, dport=1234) + / Raw(b"\xa5" * 100) + ), + ( + Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) + / IP(src="3.3.3.3", dst=self.pg3.remote_ip4) + / UDP(sport=1234, dport=1234) + / Raw(b"\xa5" * 100) + ), + ] # # before adding the SVS config all these packets are dropped when @@ -97,50 +122,67 @@ class TestSVS(VppTestCase): for table_id in table_ids: self.vapi.svs_table_add_del( - VppEnum.vl_api_address_family_t.ADDRESS_IP4, table_id) + is_add=1, + af=VppEnum.vl_api_address_family_t.ADDRESS_IP4, + table_id=table_id, + ) # # map X.0.0.0/8 to each SVS table for lookup in table X # for i in range(1, 4): self.vapi.svs_route_add_del( - table_id, "%d.0.0.0/8" % i, i) + is_add=1, + prefix="%d.0.0.0/8" % i, + table_id=table_id, + source_table_id=i, + ) # # Enable SVS on pg0/pg1 using table 1001/1002 # self.vapi.svs_enable_disable( - VppEnum.vl_api_address_family_t.ADDRESS_IP4, table_ids[0], - self.pg0.sw_if_index) + is_enable=1, + af=VppEnum.vl_api_address_family_t.ADDRESS_IP4, + table_id=table_ids[0], + sw_if_index=self.pg0.sw_if_index, + ) self.vapi.svs_enable_disable( - VppEnum.vl_api_address_family_t.ADDRESS_IP4, table_ids[1], - self.pg1.sw_if_index) + is_enable=1, + af=VppEnum.vl_api_address_family_t.ADDRESS_IP4, + table_id=table_ids[1], + sw_if_index=self.pg1.sw_if_index, + ) # # now all the packets should be delivered out the respective interface # - self.send_and_expect(self.pg0, pkts_0[0] * 65, self.pg1) - self.send_and_expect(self.pg0, pkts_0[1] * 65, self.pg2) - self.send_and_expect(self.pg0, pkts_0[2] * 65, self.pg3) - self.send_and_expect(self.pg1, pkts_1[0] * 65, self.pg1) - self.send_and_expect(self.pg1, pkts_1[1] * 65, self.pg2) - self.send_and_expect(self.pg1, pkts_1[2] * 65, self.pg3) + self.send_and_expect(self.pg0, pkts_0[0] * NUM_PKTS, self.pg1) + self.send_and_expect(self.pg0, pkts_0[1] * NUM_PKTS, self.pg2) + self.send_and_expect(self.pg0, pkts_0[2] * NUM_PKTS, self.pg3) + self.send_and_expect(self.pg1, pkts_1[0] * NUM_PKTS, self.pg1) + self.send_and_expect(self.pg1, pkts_1[1] * NUM_PKTS, self.pg2) + self.send_and_expect(self.pg1, pkts_1[2] * NUM_PKTS, self.pg3) # # check that if the SVS lookup does not match a route the packet # is forwarded using the interface's routing table # - p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / - IP(src=self.pg0.remote_ip4, dst=self.pg0.remote_ip4) / - UDP(sport=1234, dport=1234) / - Raw('\xa5' * 100)) - self.send_and_expect(self.pg0, p * 65, self.pg0) + p = ( + Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) + / IP(src=self.pg0.remote_ip4, dst=self.pg0.remote_ip4) + / UDP(sport=1234, dport=1234) + / Raw(b"\xa5" * 100) + ) + self.send_and_expect(self.pg0, p * NUM_PKTS, self.pg0) - p = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) / - IP(src=self.pg1.remote_ip4, dst=self.pg1.remote_ip4) / - UDP(sport=1234, dport=1234) / - Raw('\xa5' * 100)) - self.send_and_expect(self.pg1, p * 65, self.pg1) + p = ( + Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) + / IP(src=self.pg1.remote_ip4, dst=self.pg1.remote_ip4) + / UDP(sport=1234, dport=1234) + / Raw(b"\xa5" * 100) + ) + self.send_and_expect(self.pg1, p * NUM_PKTS, self.pg1) # # dump the SVS configs @@ -158,56 +200,79 @@ class TestSVS(VppTestCase): # cleanup # self.vapi.svs_enable_disable( - VppEnum.vl_api_address_family_t.ADDRESS_IP4, - table_ids[0], - self.pg0.sw_if_index, - is_enable=0) + is_enable=0, + af=VppEnum.vl_api_address_family_t.ADDRESS_IP4, + table_id=table_ids[0], + sw_if_index=self.pg0.sw_if_index, + ) self.vapi.svs_enable_disable( - VppEnum.vl_api_address_family_t.ADDRESS_IP4, - table_ids[1], - self.pg1.sw_if_index, - is_enable=0) + is_enable=0, + af=VppEnum.vl_api_address_family_t.ADDRESS_IP4, + table_id=table_ids[1], + sw_if_index=self.pg1.sw_if_index, + ) for table_id in table_ids: for i in range(1, 4): self.vapi.svs_route_add_del( - table_id, "%d.0.0.0/8" % i, - 0, is_add=0) + is_add=0, + prefix="%d.0.0.0/8" % i, + table_id=table_id, + source_table_id=0, + ) + self.vapi.svs_table_add_del( - VppEnum.vl_api_address_family_t.ADDRESS_IP4, - table_id, - is_add=0) + is_add=0, + af=VppEnum.vl_api_address_family_t.ADDRESS_IP4, + table_id=table_id, + ) def test_svs6(self): - """ Source VRF Select IP6 """ + """Source VRF Select IP6""" # # packets destined out of the 3 non-default table interfaces # - pkts_0 = [(Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / - IPv6(src="2001:1::1", dst=self.pg1.remote_ip6) / - UDP(sport=1234, dport=1234) / - Raw('\xa5' * 100)), - (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / - IPv6(src="2001:2::1", dst=self.pg2.remote_ip6) / - UDP(sport=1234, dport=1234) / - Raw('\xa5' * 100)), - (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / - IPv6(src="2001:3::1", dst=self.pg3.remote_ip6) / - UDP(sport=1234, dport=1234) / - Raw('\xa5' * 100))] - pkts_1 = [(Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) / - IPv6(src="2001:1::1", dst=self.pg1.remote_ip6) / - UDP(sport=1234, dport=1234) / - Raw('\xa5' * 100)), - (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) / - IPv6(src="2001:2::1", dst=self.pg2.remote_ip6) / - UDP(sport=1234, dport=1234) / - Raw('\xa5' * 100)), - (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) / - IPv6(src="2001:3::1", dst=self.pg3.remote_ip6) / - UDP(sport=1234, dport=1234) / - Raw('\xa5' * 100))] + pkts_0 = [ + ( + Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) + / IPv6(src="2001:1::1", dst=self.pg1.remote_ip6) + / UDP(sport=1234, dport=1234) + / Raw(b"\xa5" * 100) + ), + ( + Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) + / IPv6(src="2001:2::1", dst=self.pg2.remote_ip6) + / UDP(sport=1234, dport=1234) + / Raw(b"\xa5" * 100) + ), + ( + Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) + / IPv6(src="2001:3::1", dst=self.pg3.remote_ip6) + / UDP(sport=1234, dport=1234) + / Raw(b"\xa5" * 100) + ), + ] + pkts_1 = [ + ( + Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) + / IPv6(src="2001:1::1", dst=self.pg1.remote_ip6) + / UDP(sport=1234, dport=1234) + / Raw(b"\xa5" * 100) + ), + ( + Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) + / IPv6(src="2001:2::1", dst=self.pg2.remote_ip6) + / UDP(sport=1234, dport=1234) + / Raw(b"\xa5" * 100) + ), + ( + Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) + / IPv6(src="2001:3::1", dst=self.pg3.remote_ip6) + / UDP(sport=1234, dport=1234) + / Raw(b"\xa5" * 100) + ), + ] # # before adding the SVS config all these packets are dropped when @@ -224,53 +289,67 @@ class TestSVS(VppTestCase): for table_id in table_ids: self.vapi.svs_table_add_del( - VppEnum.vl_api_address_family_t.ADDRESS_IP6, table_id) + is_add=1, + af=VppEnum.vl_api_address_family_t.ADDRESS_IP6, + table_id=table_id, + ) # # map X.0.0.0/8 to each SVS table for lookup in table X # for i in range(1, 4): self.vapi.svs_route_add_del( - table_id, "2001:%d::/32" % i, - i) + is_add=1, + prefix="2001:%d::/32" % i, + table_id=table_id, + source_table_id=i, + ) # # Enable SVS on pg0/pg1 using table 1001/1002 # self.vapi.svs_enable_disable( - VppEnum.vl_api_address_family_t.ADDRESS_IP6, - table_ids[0], - self.pg0.sw_if_index) + is_enable=1, + af=VppEnum.vl_api_address_family_t.ADDRESS_IP6, + table_id=table_ids[0], + sw_if_index=self.pg0.sw_if_index, + ) self.vapi.svs_enable_disable( - VppEnum.vl_api_address_family_t.ADDRESS_IP6, - table_ids[1], - self.pg1.sw_if_index) + is_enable=1, + af=VppEnum.vl_api_address_family_t.ADDRESS_IP6, + table_id=table_ids[1], + sw_if_index=self.pg1.sw_if_index, + ) # # now all the packets should be delivered out the respective interface # - self.send_and_expect(self.pg0, pkts_0[0] * 65, self.pg1) - self.send_and_expect(self.pg0, pkts_0[1] * 65, self.pg2) - self.send_and_expect(self.pg0, pkts_0[2] * 65, self.pg3) - self.send_and_expect(self.pg1, pkts_1[0] * 65, self.pg1) - self.send_and_expect(self.pg1, pkts_1[1] * 65, self.pg2) - self.send_and_expect(self.pg1, pkts_1[2] * 65, self.pg3) + self.send_and_expect(self.pg0, pkts_0[0] * NUM_PKTS, self.pg1) + self.send_and_expect(self.pg0, pkts_0[1] * NUM_PKTS, self.pg2) + self.send_and_expect(self.pg0, pkts_0[2] * NUM_PKTS, self.pg3) + self.send_and_expect(self.pg1, pkts_1[0] * NUM_PKTS, self.pg1) + self.send_and_expect(self.pg1, pkts_1[1] * NUM_PKTS, self.pg2) + self.send_and_expect(self.pg1, pkts_1[2] * NUM_PKTS, self.pg3) # # check that if the SVS lookup does not match a route the packet # is forwarded using the interface's routing table # - p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / - IPv6(src=self.pg0.remote_ip6, dst=self.pg0.remote_ip6) / - UDP(sport=1234, dport=1234) / - Raw('\xa5' * 100)) - self.send_and_expect(self.pg0, p * 65, self.pg0) + p = ( + Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) + / IPv6(src=self.pg0.remote_ip6, dst=self.pg0.remote_ip6) + / UDP(sport=1234, dport=1234) + / Raw(b"\xa5" * 100) + ) + self.send_and_expect(self.pg0, p * NUM_PKTS, self.pg0) - p = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) / - IPv6(src=self.pg1.remote_ip6, dst=self.pg1.remote_ip6) / - UDP(sport=1234, dport=1234) / - Raw('\xa5' * 100)) - self.send_and_expect(self.pg1, p * 65, self.pg1) + p = ( + Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) + / IPv6(src=self.pg1.remote_ip6, dst=self.pg1.remote_ip6) + / UDP(sport=1234, dport=1234) + / Raw(b"\xa5" * 100) + ) + self.send_and_expect(self.pg1, p * NUM_PKTS, self.pg1) # # dump the SVS configs @@ -288,25 +367,33 @@ class TestSVS(VppTestCase): # cleanup # self.vapi.svs_enable_disable( - VppEnum.vl_api_address_family_t.ADDRESS_IP6, - table_ids[0], - self.pg0.sw_if_index, - is_enable=0) + is_enable=0, + af=VppEnum.vl_api_address_family_t.ADDRESS_IP6, + table_id=table_ids[0], + sw_if_index=self.pg0.sw_if_index, + ) self.vapi.svs_enable_disable( - VppEnum.vl_api_address_family_t.ADDRESS_IP6, - table_ids[1], - self.pg1.sw_if_index, - is_enable=0) + is_enable=0, + af=VppEnum.vl_api_address_family_t.ADDRESS_IP6, + table_id=table_ids[1], + sw_if_index=self.pg1.sw_if_index, + ) + for table_id in table_ids: for i in range(1, 4): self.vapi.svs_route_add_del( - table_id, "2001:%d::/32" % i, - 0, is_add=0) + is_add=0, + prefix="2001:%d::/32" % i, + table_id=table_id, + source_table_id=0, + ) + self.vapi.svs_table_add_del( - VppEnum.vl_api_address_family_t.ADDRESS_IP6, - table_id, - is_add=0) + is_add=0, + af=VppEnum.vl_api_address_family_t.ADDRESS_IP6, + table_id=table_id, + ) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main(testRunner=VppTestRunner)