From 0685da4a6db8195d1a86f3466fcd3395b0ccb83e Mon Sep 17 00:00:00 2001 From: Ole Troan Date: Tue, 16 Oct 2018 14:42:50 +0200 Subject: PAPI: Expose API enums to tests / applications e.g: from vpp_papi import VppEnum VppEnum.vl_api_address_family_t.ADDRESS_IP4 Change-Id: I10c22d57234a1a06e98a889cf80b19085b468ed3 Signed-off-by: Ole Troan --- test/test_svs.py | 95 ++++++++++++++++++++++++++++++++------------------------ test/vpp_ip.py | 20 ++++++------ 2 files changed, 63 insertions(+), 52 deletions(-) (limited to 'test') diff --git a/test/test_svs.py b/test/test_svs.py index 550f35a489f..8429f437ae1 100644 --- a/test/test_svs.py +++ b/test/test_svs.py @@ -1,7 +1,7 @@ #!/usr/bin/env python from framework import VppTestCase, VppTestRunner -from vpp_ip import IpAddressFamily, VppIpPrefix +from vpp_ip import VppIpPrefix from vpp_ip_route import VppIpTable @@ -10,6 +10,8 @@ from scapy.layers.l2 import Ether from scapy.layers.inet import IP, UDP, ICMP from scapy.layers.inet6 import IPv6 +from vpp_papi import VppEnum + class TestSVS(VppTestCase): """ SVS Test Case """ @@ -94,7 +96,8 @@ class TestSVS(VppTestCase): table_ids = [101, 102] for table_id in table_ids: - self.vapi.svs_table_add_del(IpAddressFamily.ADDRESS_IP4, table_id) + self.vapi.svs_table_add_del( + VppEnum.vl_api_address_family_t.ADDRESS_IP4, table_id) # # map X.0.0.0/8 to each SVS table for lookup in table X @@ -108,12 +111,12 @@ class TestSVS(VppTestCase): # # Enable SVS on pg0/pg1 using table 1001/1002 # - self.vapi.svs_enable_disable(IpAddressFamily.ADDRESS_IP4, - table_ids[0], - self.pg0.sw_if_index) - self.vapi.svs_enable_disable(IpAddressFamily.ADDRESS_IP4, - table_ids[1], - self.pg1.sw_if_index) + self.vapi.svs_enable_disable( + VppEnum.vl_api_address_family_t.ADDRESS_IP4, table_ids[0], + 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) # # now all the packets should be delivered out the respective interface @@ -148,22 +151,24 @@ class TestSVS(VppTestCase): self.assertEqual(ss[0].table_id, table_ids[0]) self.assertEqual(ss[0].sw_if_index, self.pg0.sw_if_index) - self.assertEqual(ss[0].af, IpAddressFamily.ADDRESS_IP4) + self.assertEqual(ss[0].af, VppEnum.vl_api_address_family_t.ADDRESS_IP4) self.assertEqual(ss[1].table_id, table_ids[1]) self.assertEqual(ss[1].sw_if_index, self.pg1.sw_if_index) - self.assertEqual(ss[1].af, IpAddressFamily.ADDRESS_IP4) + self.assertEqual(ss[1].af, VppEnum.vl_api_address_family_t.ADDRESS_IP4) # # cleanup # - self.vapi.svs_enable_disable(IpAddressFamily.ADDRESS_IP4, - table_ids[0], - self.pg0.sw_if_index, - is_enable=0) - self.vapi.svs_enable_disable(IpAddressFamily.ADDRESS_IP4, - table_ids[1], - self.pg1.sw_if_index, - is_enable=0) + self.vapi.svs_enable_disable( + VppEnum.vl_api_address_family_t.ADDRESS_IP4, + table_ids[0], + self.pg0.sw_if_index, + is_enable=0) + self.vapi.svs_enable_disable( + VppEnum.vl_api_address_family_t.ADDRESS_IP4, + table_ids[1], + self.pg1.sw_if_index, + is_enable=0) for table_id in table_ids: for i in range(1, 4): @@ -171,9 +176,10 @@ class TestSVS(VppTestCase): table_id, VppIpPrefix("%d.0.0.0" % i, 8).encode(), 0, is_add=0) - self.vapi.svs_table_add_del(IpAddressFamily.ADDRESS_IP4, - table_id, - is_add=0) + self.vapi.svs_table_add_del( + VppEnum.vl_api_address_family_t.ADDRESS_IP4, + table_id, + is_add=0) def test_svs6(self): """ Source VRF Select IP6 """ @@ -220,7 +226,8 @@ class TestSVS(VppTestCase): table_ids = [101, 102] for table_id in table_ids: - self.vapi.svs_table_add_del(IpAddressFamily.ADDRESS_IP6, table_id) + self.vapi.svs_table_add_del( + VppEnum.vl_api_address_family_t.ADDRESS_IP6, table_id) # # map X.0.0.0/8 to each SVS table for lookup in table X @@ -234,12 +241,14 @@ class TestSVS(VppTestCase): # # Enable SVS on pg0/pg1 using table 1001/1002 # - self.vapi.svs_enable_disable(IpAddressFamily.ADDRESS_IP6, - table_ids[0], - self.pg0.sw_if_index) - self.vapi.svs_enable_disable(IpAddressFamily.ADDRESS_IP6, - table_ids[1], - self.pg1.sw_if_index) + self.vapi.svs_enable_disable( + VppEnum.vl_api_address_family_t.ADDRESS_IP6, + table_ids[0], + 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) # # now all the packets should be delivered out the respective interface @@ -274,31 +283,35 @@ class TestSVS(VppTestCase): self.assertEqual(ss[0].table_id, table_ids[0]) self.assertEqual(ss[0].sw_if_index, self.pg0.sw_if_index) - self.assertEqual(ss[0].af, IpAddressFamily.ADDRESS_IP6) + self.assertEqual(ss[0].af, VppEnum.vl_api_address_family_t.ADDRESS_IP6) self.assertEqual(ss[1].table_id, table_ids[1]) self.assertEqual(ss[1].sw_if_index, self.pg1.sw_if_index) - self.assertEqual(ss[1].af, IpAddressFamily.ADDRESS_IP6) + self.assertEqual(ss[1].af, VppEnum.vl_api_address_family_t.ADDRESS_IP6) # # cleanup # - self.vapi.svs_enable_disable(IpAddressFamily.ADDRESS_IP6, - table_ids[0], - self.pg0.sw_if_index, - is_enable=0) - self.vapi.svs_enable_disable(IpAddressFamily.ADDRESS_IP6, - table_ids[1], - self.pg1.sw_if_index, - is_enable=0) + self.vapi.svs_enable_disable( + VppEnum.vl_api_address_family_t.ADDRESS_IP6, + table_ids[0], + self.pg0.sw_if_index, + is_enable=0) + self.vapi.svs_enable_disable( + VppEnum.vl_api_address_family_t.ADDRESS_IP6, + table_ids[1], + self.pg1.sw_if_index, + is_enable=0) for table_id in table_ids: for i in range(1, 4): self.vapi.svs_route_add_del( table_id, VppIpPrefix("2001:%d::" % i, 32).encode(), 0, is_add=0) - self.vapi.svs_table_add_del(IpAddressFamily.ADDRESS_IP6, - table_id, - is_add=0) + self.vapi.svs_table_add_del( + VppEnum.vl_api_address_family_t.ADDRESS_IP6, + table_id, + is_add=0) + if __name__ == '__main__': unittest.main(testRunner=VppTestRunner) diff --git a/test/vpp_ip.py b/test/vpp_ip.py index e44e6b56e30..e92c91943db 100644 --- a/test/vpp_ip.py +++ b/test/vpp_ip.py @@ -5,11 +5,7 @@ from ipaddress import ip_address from socket import AF_INET, AF_INET6 - - -class IpAddressFamily: - ADDRESS_IP4 = 0 - ADDRESS_IP6 = 1 +from vpp_papi import VppEnum class DpoProto: @@ -86,12 +82,12 @@ class VppIpAddress(): def encode(self): if self.addr.version is 6: return { - 'af': IpAddressFamily.ADDRESS_IP6, + 'af': VppEnum.vl_api_address_family_t.ADDRESS_IP6, 'un': self.addr.encode() } else: return { - 'af': IpAddressFamily.ADDRESS_IP4, + 'af': VppEnum.vl_api_address_family_t.ADDRESS_IP4, 'un': self.addr.encode() } @@ -101,10 +97,12 @@ class VppIpAddress(): elif hasattr(other, "af") and hasattr(other, "un"): # a vp_api_address_t if 4 is self.version: - return other.af == IpAddressFamily.ADDRESS_IP4 and \ + return other.af == \ + VppEnum.vl_api_address_family_t.ADDRESS_IP4 and \ other.un == self.addr else: - return other.af == IpAddressFamily.ADDRESS_IP6 and \ + return other.af == \ + VppEnum.vl_api_address_family_t.ADDRESS_IP6 and \ other.un == self.addr else: raise Exception("Comparing VppIpAddress:%s with unknown type: %s" % @@ -202,7 +200,7 @@ class VppIpMPrefix(): if 6 is self.ip_saddr.version: prefix = { - 'af': IpAddressFamily.ADDRESS_IP6, + 'af': VppEnum.vl_api_address_family_t.ADDRESS_IP6, 'grp_address': { 'ip6': { 'address': self.ip_gaddr.packed @@ -217,7 +215,7 @@ class VppIpMPrefix(): } else: prefix = { - 'af': IpAddressFamily.ADDRESS_IP4, + 'af': VppEnum.vl_api_address_family_t.ADDRESS_IP4, 'grp_address': { 'ip4': { 'address': self.ip_gaddr.packed -- cgit 1.2.3-korg