diff options
author | Ole Troan <ot@cisco.com> | 2018-12-11 13:04:01 +0100 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2018-12-12 00:34:43 +0000 |
commit | 0bcad32b3870f9998fa1393418081cdda685272f (patch) | |
tree | 0fcb518ffa5553bbec94c219cbc33fef48dbede3 /test | |
parent | 41b25cf6380d1420b24e191cd7e95cbce1e7cfdc (diff) |
PAPI: Allow ipaddress object as argument and return values from API calls
The API calls that use any of vl_api_address_t, vl_api_ip4_address,
vl_api_ip6_address_t, vl_api_prefix_t, vl_api_ip4_prefix_t,
vl_api_ip6_prefix_t now accepts either the old style dictionary,
a text string (2001:db8::/32) or an ipaddress ojbect.
Unless it is called with '_no_type_conversion':True, it will
also return an appropriate ipaddress object.
Change-Id: I84e4a1577bd57f6b5ae725f316a523988b6a955b
Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/test_ip4.py | 12 | ||||
-rw-r--r-- | test/test_ip6.py | 12 | ||||
-rw-r--r-- | test/test_l2bd_arp_term.py | 3 | ||||
-rw-r--r-- | test/test_map.py | 16 | ||||
-rw-r--r-- | test/test_syslog.py | 6 | ||||
-rw-r--r-- | test/vpp_igmp.py | 6 | ||||
-rw-r--r-- | test/vpp_ip.py | 14 | ||||
-rw-r--r-- | test/vpp_papi_provider.py | 9 | ||||
-rw-r--r-- | test/vpp_udp_encap.py | 13 |
9 files changed, 38 insertions, 53 deletions
diff --git a/test/test_ip4.py b/test/test_ip4.py index 54090445dac..685d0894aec 100644 --- a/test/test_ip4.py +++ b/test/test_ip4.py @@ -14,7 +14,7 @@ from framework import VppTestCase, VppTestRunner from util import ppp from vpp_ip_route import VppIpRoute, VppRoutePath, VppIpMRoute, \ VppMRoutePath, MRouteItfFlags, MRouteEntryFlags, VppMplsIpBind, \ - VppMplsTable, VppIpTable, VppIpAddress + VppMplsTable, VppIpTable from vpp_sub_interface import VppSubInterface, VppDot1QSubint, VppDot1ADSubint @@ -1123,7 +1123,7 @@ class TestIPPunt(VppTestCase): # # Configure a punt redirect via pg1. # - nh_addr = VppIpAddress(self.pg1.remote_ip4).encode() + nh_addr = self.pg1.remote_ip4 self.vapi.ip_punt_redirect(self.pg0.sw_if_index, self.pg1.sw_if_index, nh_addr) @@ -1187,7 +1187,7 @@ class TestIPPunt(VppTestCase): # # Configure a punt redirects # - nh_address = VppIpAddress(self.pg3.remote_ip4).encode() + nh_address = self.pg3.remote_ip4 self.vapi.ip_punt_redirect(self.pg0.sw_if_index, self.pg3.sw_if_index, nh_address) @@ -1196,7 +1196,7 @@ class TestIPPunt(VppTestCase): nh_address) self.vapi.ip_punt_redirect(self.pg2.sw_if_index, self.pg3.sw_if_index, - VppIpAddress('0.0.0.0').encode()) + '0.0.0.0') # # Dump pg0 punt redirects @@ -1212,8 +1212,8 @@ class TestIPPunt(VppTestCase): self.assertEqual(len(punts), 3) for p in punts: self.assertEqual(p.punt.tx_sw_if_index, self.pg3.sw_if_index) - self.assertNotEqual(punts[1].punt.nh.un.ip4, self.pg3.remote_ip4) - self.assertEqual(punts[2].punt.nh.un.ip4, '\x00'*4) + self.assertNotEqual(punts[1].punt.nh, self.pg3.remote_ip4) + self.assertEqual(str(punts[2].punt.nh), '0.0.0.0') class TestIPDeag(VppTestCase): diff --git a/test/test_ip6.py b/test/test_ip6.py index 3a9e88c2bf3..6c44d79a18f 100644 --- a/test/test_ip6.py +++ b/test/test_ip6.py @@ -21,7 +21,7 @@ from util import ppp, ip6_normalize from vpp_ip import DpoProto from vpp_ip_route import VppIpRoute, VppRoutePath, find_route, VppIpMRoute, \ VppMRoutePath, MRouteItfFlags, MRouteEntryFlags, VppMplsIpBind, \ - VppMplsRoute, VppMplsTable, VppIpTable, VppIpAddress + VppMplsRoute, VppMplsTable, VppIpTable from vpp_neighbor import find_nbr, VppNeighbor from vpp_pg_interface import is_ipv6_misc from vpp_sub_interface import VppSubInterface, VppDot1QSubint @@ -1949,7 +1949,7 @@ class TestIP6Punt(VppTestCase): # # Configure a punt redirect via pg1. # - nh_addr = VppIpAddress(self.pg1.remote_ip6).encode() + nh_addr = self.pg1.remote_ip6 self.vapi.ip_punt_redirect(self.pg0.sw_if_index, self.pg1.sw_if_index, nh_addr) @@ -2013,7 +2013,7 @@ class TestIP6Punt(VppTestCase): # # Configure a punt redirects # - nh_addr = VppIpAddress(self.pg3.remote_ip6).encode() + nh_addr = self.pg3.remote_ip6 self.vapi.ip_punt_redirect(self.pg0.sw_if_index, self.pg3.sw_if_index, nh_addr) @@ -2022,7 +2022,7 @@ class TestIP6Punt(VppTestCase): nh_addr) self.vapi.ip_punt_redirect(self.pg2.sw_if_index, self.pg3.sw_if_index, - VppIpAddress('0::0').encode()) + '0::0') # # Dump pg0 punt redirects @@ -2039,8 +2039,8 @@ class TestIP6Punt(VppTestCase): self.assertEqual(len(punts), 3) for p in punts: self.assertEqual(p.punt.tx_sw_if_index, self.pg3.sw_if_index) - self.assertNotEqual(punts[1].punt.nh.un.ip6, self.pg3.remote_ip6) - self.assertEqual(punts[2].punt.nh.un.ip6, '\x00'*16) + self.assertNotEqual(punts[1].punt.nh, self.pg3.remote_ip6) + self.assertEqual(str(punts[2].punt.nh), '::') class TestIPDeag(VppTestCase): diff --git a/test/test_l2bd_arp_term.py b/test/test_l2bd_arp_term.py index ddba79b79f0..f25be57d8e4 100644 --- a/test/test_l2bd_arp_term.py +++ b/test/test_l2bd_arp_term.py @@ -21,7 +21,6 @@ from scapy.layers.inet6 import IPv6, UDP, ICMPv6ND_NS, ICMPv6ND_RS, \ from framework import VppTestCase, VppTestRunner from util import Host, ppp from vpp_mac import VppMacAddress, mactobinary -from vpp_ip import VppIpAddress class TestL2bdArpTerm(VppTestCase): @@ -74,7 +73,7 @@ class TestL2bdArpTerm(VppTestCase): ip = e.ip4 if is_ipv6 == 0 else e.ip6 self.vapi.bd_ip_mac_add_del(bd_id=bd_id, mac=VppMacAddress(e.mac).encode(), - ip=VppIpAddress(ip).encode(), + ip=ip, is_ipv6=is_ipv6, is_add=is_add) diff --git a/test/test_map.py b/test/test_map.py index 3d02853dd8b..e98532e9df7 100644 --- a/test/test_map.py +++ b/test/test_map.py @@ -6,7 +6,7 @@ import socket from framework import VppTestCase, VppTestRunner from vpp_ip import * from vpp_ip_route import VppIpRoute, VppRoutePath - +from ipaddress import IPv6Network, IPv4Network from scapy.layers.l2 import Ether, Raw from scapy.layers.inet import IP, UDP, ICMP, TCP, fragment from scapy.layers.inet6 import IPv6, ICMPv6TimeExceeded @@ -76,9 +76,9 @@ class TestMAP(VppTestCase): # # Add a domain that maps from pg0 to pg1 # - map_dst = VppIp6Prefix(map_br_pfx, map_br_pfx_len).encode() - map_src = VppIp6Prefix("3000::1", 128).encode() - client_pfx = VppIp4Prefix("192.168.0.0", 16).encode() + map_dst = '{}/{}'.format(map_br_pfx, map_br_pfx_len) + map_src = '3000::1/128' + client_pfx = '192.168.0.0/16' self.vapi.map_add_domain(map_dst, map_src, client_pfx) # @@ -168,10 +168,10 @@ class TestMAP(VppTestCase): # # Add a domain that maps from pg0 to pg1 # - map_dst = VppIp6Prefix("2001:db8::", 32).encode() - map_src = VppIp6Prefix("1234:5678:90ab:cdef::", 64).encode() - ip4_pfx = VppIp4Prefix("192.168.0.0", 24).encode() - self.vapi.map_add_domain(map_dst, map_src, ip4_pfx, 16, 6, 4, 1) + self.vapi.map_add_domain('2001:db8::/32', + '1234:5678:90ab:cdef::/64', + '192.168.0.0/24', + 16, 6, 4, 1) # Enable MAP-T on interfaces. diff --git a/test/test_syslog.py b/test/test_syslog.py index a54513027e9..9b328be3ad0 100644 --- a/test/test_syslog.py +++ b/test/test_syslog.py @@ -94,10 +94,10 @@ class TestSyslog(VppTestCase): """ Syslog Protocol test """ self.vapi.syslog_set_sender(self.pg0.remote_ip4n, self.pg0.local_ip4n) config = self.vapi.syslog_get_sender() - self.assertEqual(config.collector_address, - self.pg0.remote_ip4n) + self.assertEqual(str(config.collector_address), + self.pg0.remote_ip4) self.assertEqual(config.collector_port, 514) - self.assertEqual(config.src_address, self.pg0.local_ip4n) + self.assertEqual(str(config.src_address), self.pg0.local_ip4) self.assertEqual(config.vrf_id, 0) self.assertEqual(config.max_msg_size, 480) diff --git a/test/vpp_igmp.py b/test/vpp_igmp.py index c4cbab13a0c..2403fbfd6ca 100644 --- a/test/vpp_igmp.py +++ b/test/vpp_igmp.py @@ -16,8 +16,7 @@ class IGMP_FILTER: def find_igmp_state(states, itf, gaddr, saddr): for s in states: if s.sw_if_index == itf.sw_if_index and \ - s.gaddr == socket.inet_pton(socket.AF_INET, gaddr) and \ - s.saddr == socket.inet_pton(socket.AF_INET, saddr): + str(s.gaddr) == gaddr and str(s.saddr) == saddr: return True return False @@ -25,8 +24,7 @@ def find_igmp_state(states, itf, gaddr, saddr): def wait_for_igmp_event(test, timeout, itf, gaddr, saddr, ff): ev = test.vapi.wait_for_event(timeout, "igmp_event") if ev.sw_if_index == itf.sw_if_index and \ - ev.gaddr == socket.inet_pton(socket.AF_INET, gaddr) and \ - ev.saddr == socket.inet_pton(socket.AF_INET, saddr) and \ + str(ev.gaddr) == gaddr and str(ev.saddr) == saddr and \ ev.filter == ff: return True return False diff --git a/test/vpp_ip.py b/test/vpp_ip.py index 7f3a6b01e95..055e6d73738 100644 --- a/test/vpp_ip.py +++ b/test/vpp_ip.py @@ -192,20 +192,6 @@ class VppIpPrefix(): return False -class VppIp6Prefix(): - def __init__(self, prefix, prefixlen): - self.ip_prefix = ip_address(unicode(prefix)) - self.prefixlen = prefixlen - - def encode(self): - return {'prefix': self.ip_prefix.packed, - 'len': self.prefixlen} - - -class VppIp4Prefix(VppIp6Prefix): - pass - - class VppIpMPrefix(): def __init__(self, saddr, gaddr, len): self.saddr = saddr diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py index 26d5fcf721c..320ea12c6dc 100644 --- a/test/vpp_papi_provider.py +++ b/test/vpp_papi_provider.py @@ -2821,7 +2821,8 @@ class VppPapiProvider(object): def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff): return self.api(self.papi.vxlan_gbp_tunnel_dump, - {'sw_if_index': sw_if_index}) + {'sw_if_index': sw_if_index, + '_no_type_conversion': True}) def pppoe_add_del_session( self, @@ -3553,7 +3554,8 @@ class VppPapiProvider(object): def gbp_endpoint_dump(self): """ GBP endpoint Dump """ - return self.api(self.papi.gbp_endpoint_dump, {}) + return self.api(self.papi.gbp_endpoint_dump, + {'_no_type_conversion': True}) def gbp_endpoint_group_add(self, epg, bd, rd, uplink_sw_if_index): @@ -3665,7 +3667,8 @@ class VppPapiProvider(object): def gbp_subnet_dump(self): """ GBP Subnet Dump """ - return self.api(self.papi.gbp_subnet_dump, {}) + return self.api(self.papi.gbp_subnet_dump, + {'_no_type_conversion': True}) def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index, rules): """ GBP contract Add/Del """ diff --git a/test/vpp_udp_encap.py b/test/vpp_udp_encap.py index 209115f2c3f..5e2df7646a6 100644 --- a/test/vpp_udp_encap.py +++ b/test/vpp_udp_encap.py @@ -5,15 +5,14 @@ from vpp_object import * from socket import inet_pton, inet_ntop, AF_INET, AF_INET6 -from vpp_ip import * def find_udp_encap(test, ue): encaps = test.vapi.udp_encap_dump() for e in encaps: if ue.id == e.udp_encap.id \ - and ue.src_ip == e.udp_encap.src_ip \ - and ue.dst_ip == e.udp_encap.dst_ip \ + and ue.src_ip == str(e.udp_encap.src_ip) \ + and ue.dst_ip == str(e.udp_encap.dst_ip) \ and e.udp_encap.dst_port == ue.dst_port \ and e.udp_encap.src_port == ue.src_port: return True @@ -34,15 +33,15 @@ class VppUdpEncap(VppObject): self.table_id = table_id self.src_ip_s = src_ip self.dst_ip_s = dst_ip - self.src_ip = VppIpAddress(src_ip) - self.dst_ip = VppIpAddress(dst_ip) + self.src_ip = src_ip + self.dst_ip = dst_ip self.src_port = src_port self.dst_port = dst_port def add_vpp_config(self): r = self._test.vapi.udp_encap_add( - self.src_ip.encode(), - self.dst_ip.encode(), + self.src_ip, + self.dst_ip, self.src_port, self.dst_port, self.table_id) |