summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_dhcp.py263
-rw-r--r--test/test_dhcp6.py46
-rw-r--r--test/vpp_dhcp.py128
-rw-r--r--test/vpp_papi_provider.py100
4 files changed, 283 insertions, 254 deletions
diff --git a/test/test_dhcp.py b/test/test_dhcp.py
index 175f6493eb7..39b0af77f9d 100644
--- a/test/test_dhcp.py
+++ b/test/test_dhcp.py
@@ -23,6 +23,7 @@ from scapy.utils6 import in6_ptop
from vpp_papi import mac_pton, VppEnum
from vpp_sub_interface import VppDot1QSubint
from vpp_qos import VppQosEgressMap, VppQosMark
+from vpp_dhcp import VppDHCPClient, VppDHCPProxy
DHCP4_CLIENT_PORT = 68
@@ -94,7 +95,7 @@ class TestDHCP(VppTestCase):
found = False
for i in dhcp.options:
- if type(i) is tuple:
+ if isinstance(i, tuple):
if i[0] == option:
self.assertEqual(i[1], value)
found = True
@@ -108,7 +109,7 @@ class TestDHCP(VppTestCase):
id_len = len(vpn_id)
for i in dhcp.options:
- if type(i) is tuple:
+ if isinstance(i, tuple):
if i[0] == "relay_agent_Information":
#
# There are two sb-options present - each of length 6.
@@ -117,7 +118,7 @@ class TestDHCP(VppTestCase):
if oui != 0:
self.assertEqual(len(data), 24)
elif len(vpn_id) > 0:
- self.assertEqual(len(data), len(vpn_id)+17)
+ self.assertEqual(len(data), len(vpn_id) + 17)
else:
self.assertEqual(len(data), 12)
@@ -173,13 +174,13 @@ class TestDHCP(VppTestCase):
# followerd by vpn_id in ascii
self.assertEqual(oui, 0)
self.assertEqual(ord(data[12]), 151)
- self.assertEqual(ord(data[13]), id_len+1)
+ self.assertEqual(ord(data[13]), id_len + 1)
self.assertEqual(ord(data[14]), 0)
- self.assertEqual(data[15:15+id_len], vpn_id)
+ self.assertEqual(data[15:15 + id_len], vpn_id)
# VSS control sub-option
- self.assertEqual(ord(data[15+len(vpn_id)]), 152)
- self.assertEqual(ord(data[16+len(vpn_id)]), 0)
+ self.assertEqual(ord(data[15 + len(vpn_id)]), 152)
+ self.assertEqual(ord(data[16 + len(vpn_id)]), 0)
found = 1
self.assertTrue(found)
@@ -190,7 +191,7 @@ class TestDHCP(VppTestCase):
dhcp = pkt[DHCP]
found = False
for o in dhcp.options:
- if type(o) is tuple:
+ if isinstance(o, tuple):
if o[0] == "message-type" \
and DHCPTypes[o[1]] == name:
found = True
@@ -298,7 +299,7 @@ class TestDHCP(VppTestCase):
is_discover = False
for o in dhcp.options:
- if type(o) is tuple:
+ if isinstance(o, tuple):
if o[0] == "message-type" \
and DHCPTypes[o[1]] == "discover":
is_discover = True
@@ -362,7 +363,7 @@ class TestDHCP(VppTestCase):
if id_len > 0:
self.assertEqual(oui, 0)
vss = pkt[DHCP6OptVSS]
- self.assertEqual(vss.optlen, id_len+1)
+ self.assertEqual(vss.optlen, id_len + 1)
self.assertEqual(vss.type, 0)
self.assertEqual(vss.data[0:id_len], vpn_id)
@@ -439,12 +440,11 @@ class TestDHCP(VppTestCase):
#
# Enable DHCP proxy in VRF 0
#
- server_addr = self.pg0.remote_ip4n
- src_addr = self.pg0.local_ip4n
+ server_addr = self.pg0.remote_ip4
+ src_addr = self.pg0.local_ip4
- self.vapi.dhcp_proxy_config(server_addr,
- src_addr,
- rx_table_id=0)
+ Proxy = VppDHCPProxy(self, server_addr, src_addr, rx_vrf_id=0)
+ Proxy.add_vpp_config()
#
# Discover packets from the client are dropped because there is no
@@ -555,10 +555,7 @@ class TestDHCP(VppTestCase):
# Delete the DHCP config in VRF 0
# Should now drop requests.
#
- self.vapi.dhcp_proxy_config(server_addr,
- src_addr,
- rx_table_id=0,
- is_add=0)
+ Proxy.remove_vpp_config()
self.send_and_assert_no_replies(self.pg3, pkts_disc_vrf0,
"DHCP config removed VRF 0")
@@ -568,18 +565,25 @@ class TestDHCP(VppTestCase):
#
# Add DHCP config for VRF 1 & 2
#
- server_addr1 = self.pg1.remote_ip4n
- src_addr1 = self.pg1.local_ip4n
- self.vapi.dhcp_proxy_config(server_addr1,
- src_addr1,
- rx_table_id=1,
- server_table_id=1)
- server_addr2 = self.pg2.remote_ip4n
- src_addr2 = self.pg2.local_ip4n
- self.vapi.dhcp_proxy_config(server_addr2,
- src_addr2,
- rx_table_id=2,
- server_table_id=2)
+ server_addr1 = self.pg1.remote_ip4
+ src_addr1 = self.pg1.local_ip4
+ Proxy1 = VppDHCPProxy(
+ self,
+ server_addr1,
+ src_addr1,
+ rx_vrf_id=1,
+ server_vrf_id=1)
+ Proxy1.add_vpp_config()
+
+ server_addr2 = self.pg2.remote_ip4
+ src_addr2 = self.pg2.local_ip4
+ Proxy2 = VppDHCPProxy(
+ self,
+ server_addr2,
+ src_addr2,
+ rx_vrf_id=2,
+ server_vrf_id=2)
+ Proxy2.add_vpp_config()
#
# Confim DHCP requests ok in VRF 1 & 2.
@@ -641,13 +645,15 @@ class TestDHCP(VppTestCase):
# expect clients messages to be relay to both configured servers
#
self.pg1.generate_remote_hosts(2)
- server_addr12 = socket.inet_pton(AF_INET, self.pg1.remote_hosts[1].ip4)
+ server_addr12 = self.pg1.remote_hosts[1].ip4
- self.vapi.dhcp_proxy_config(server_addr12,
- src_addr1,
- rx_table_id=1,
- server_table_id=1,
- is_add=1)
+ Proxy12 = VppDHCPProxy(
+ self,
+ server_addr12,
+ src_addr,
+ rx_vrf_id=1,
+ server_vrf_id=1)
+ Proxy12.add_vpp_config()
#
# We'll need an ARP entry for the server to send it packets
@@ -741,11 +747,7 @@ class TestDHCP(VppTestCase):
#
# Remove the second DHCP server
#
- self.vapi.dhcp_proxy_config(server_addr12,
- src_addr1,
- rx_table_id=1,
- server_table_id=1,
- is_add=0)
+ Proxy12.remove_vpp_config()
#
# Test we can still relay with the first
@@ -778,16 +780,8 @@ class TestDHCP(VppTestCase):
#
# remove DHCP config to cleanup
#
- self.vapi.dhcp_proxy_config(server_addr1,
- src_addr1,
- rx_table_id=1,
- server_table_id=1,
- is_add=0)
- self.vapi.dhcp_proxy_config(server_addr2,
- src_addr2,
- rx_table_id=2,
- server_table_id=2,
- is_add=0)
+ Proxy1.remove_vpp_config()
+ Proxy2.remove_vpp_config()
self.send_and_assert_no_replies(self.pg3, pkts_disc_vrf0,
"DHCP cleanup VRF 0")
@@ -809,12 +803,12 @@ class TestDHCP(VppTestCase):
dhcp_solicit_src_vrf0 = mk_ll_addr(self.pg3.remote_mac)
dhcp_solicit_src_vrf1 = mk_ll_addr(self.pg4.remote_mac)
dhcp_solicit_src_vrf2 = mk_ll_addr(self.pg5.remote_mac)
- server_addr_vrf0 = self.pg0.remote_ip6n
- src_addr_vrf0 = self.pg0.local_ip6n
- server_addr_vrf1 = self.pg1.remote_ip6n
- src_addr_vrf1 = self.pg1.local_ip6n
- server_addr_vrf2 = self.pg2.remote_ip6n
- src_addr_vrf2 = self.pg2.local_ip6n
+ server_addr_vrf0 = self.pg0.remote_ip6
+ src_addr_vrf0 = self.pg0.local_ip6
+ server_addr_vrf1 = self.pg1.remote_ip6
+ src_addr_vrf1 = self.pg1.local_ip6
+ server_addr_vrf2 = self.pg2.remote_ip6
+ src_addr_vrf2 = self.pg2.local_ip6
dmac = in6_getnsmac(inet_pton(socket.AF_INET6, dhcp_solicit_dst))
p_solicit_vrf0 = (Ether(dst=dmac, src=self.pg3.remote_mac) /
@@ -848,11 +842,13 @@ class TestDHCP(VppTestCase):
# Packets still dropped because the client facing interface has no
# IPv6 config
#
- self.vapi.dhcp_proxy_config(server_addr_vrf0,
- src_addr_vrf0,
- rx_table_id=0,
- server_table_id=0,
- is_ipv6=1)
+ Proxy = VppDHCPProxy(
+ self,
+ server_addr_vrf0,
+ src_addr_vrf0,
+ rx_vrf_id=0,
+ server_vrf_id=0)
+ Proxy.add_vpp_config()
self.send_and_assert_no_replies(self.pg3, p_solicit_vrf0,
"DHCP with no configuration")
@@ -963,18 +959,22 @@ class TestDHCP(VppTestCase):
#
# Add all the config for VRF 1 & 2
#
- self.vapi.dhcp_proxy_config(server_addr_vrf1,
- src_addr_vrf1,
- rx_table_id=1,
- server_table_id=1,
- is_ipv6=1)
+ Proxy1 = VppDHCPProxy(
+ self,
+ server_addr_vrf1,
+ src_addr_vrf1,
+ rx_vrf_id=1,
+ server_vrf_id=1)
+ Proxy1.add_vpp_config()
self.pg4.config_ip6()
- self.vapi.dhcp_proxy_config(server_addr_vrf2,
- src_addr_vrf2,
- rx_table_id=2,
- server_table_id=2,
- is_ipv6=1)
+ Proxy2 = VppDHCPProxy(
+ self,
+ server_addr_vrf2,
+ src_addr_vrf2,
+ rx_vrf_id=2,
+ server_vrf_id=2)
+ Proxy2.add_vpp_config()
self.pg5.config_ip6()
#
@@ -1026,10 +1026,14 @@ class TestDHCP(VppTestCase):
#
# Add VSS config
- # table=1, vss_type=1, vpn_index=1, oui=4
- # table=2, vss_type=0, vpn_id = "ip6-table-2"
- self.vapi.dhcp_proxy_set_vss(1, 1, oui=4, vpn_index=1, is_ip6=1)
- self.vapi.dhcp_proxy_set_vss(2, 0, "IPv6-table-2", is_ip6=1)
+ #
+ self.vapi.dhcp_proxy_set_vss(
+ tbl_id=1, vss_type=1, oui=4, vpn_index=1, is_ipv6=1)
+ self.vapi.dhcp_proxy_set_vss(
+ tbl_id=2,
+ vss_type=0,
+ vpn_ascii_id="IPv6-table-2",
+ is_ipv6=1)
self.pg4.add_stream(p_solicit_vrf1)
self.pg_enable_capture(self.pg_interfaces)
@@ -1058,7 +1062,7 @@ class TestDHCP(VppTestCase):
# Remove the VSS config
# relayed DHCP has default vlaues in the option.
#
- self.vapi.dhcp_proxy_set_vss(1, is_ip6=1, is_add=0)
+ self.vapi.dhcp_proxy_set_vss(1, is_ipv6=1, is_add=0)
self.pg4.add_stream(p_solicit_vrf1)
self.pg_enable_capture(self.pg_interfaces)
@@ -1075,14 +1079,15 @@ class TestDHCP(VppTestCase):
# expect clients messages to be relay to both configured servers
#
self.pg1.generate_remote_hosts(2)
- server_addr12 = socket.inet_pton(AF_INET6,
- self.pg1.remote_hosts[1].ip6)
+ server_addr12 = self.pg1.remote_hosts[1].ip6
- self.vapi.dhcp_proxy_config(server_addr12,
- src_addr_vrf1,
- rx_table_id=1,
- server_table_id=1,
- is_ipv6=1)
+ Proxy12 = VppDHCPProxy(
+ self,
+ server_addr12,
+ src_addr_vrf1,
+ rx_vrf_id=1,
+ server_vrf_id=1)
+ Proxy12.add_vpp_config()
#
# We'll need an ND entry for the server to send it packets
@@ -1178,12 +1183,7 @@ class TestDHCP(VppTestCase):
#
# Remove the second DHCP server
#
- self.vapi.dhcp_proxy_config(server_addr12,
- src_addr_vrf1,
- rx_table_id=1,
- server_table_id=1,
- is_ipv6=1,
- is_add=0)
+ Proxy12.remove_vpp_config()
#
# Test we can still relay with the first
@@ -1201,32 +1201,10 @@ class TestDHCP(VppTestCase):
#
# Cleanup
#
- self.vapi.dhcp_proxy_config(server_addr_vrf2,
- src_addr_vrf2,
- rx_table_id=2,
- server_table_id=2,
- is_ipv6=1,
- is_add=0)
- self.vapi.dhcp_proxy_config(server_addr_vrf1,
- src_addr_vrf1,
- rx_table_id=1,
- server_table_id=1,
- is_ipv6=1,
- is_add=0)
- self.vapi.dhcp_proxy_config(server_addr_vrf0,
- src_addr_vrf0,
- rx_table_id=0,
- server_table_id=0,
- is_ipv6=1,
- is_add=0)
-
- # duplicate delete
- self.vapi.dhcp_proxy_config(server_addr_vrf0,
- src_addr_vrf0,
- rx_table_id=0,
- server_table_id=0,
- is_ipv6=1,
- is_add=0)
+ Proxy.remove_vpp_config()
+ Proxy1.remove_vpp_config()
+ Proxy2.remove_vpp_config()
+
self.pg3.unconfig_ip6()
self.pg4.unconfig_ip6()
self.pg5.unconfig_ip6()
@@ -1242,7 +1220,9 @@ class TestDHCP(VppTestCase):
#
# Configure DHCP client on PG3 and capture the discover sent
#
- self.vapi.dhcp_client_config(self.pg3.sw_if_index, hostname)
+ Client = VppDHCPClient(self, self.pg3.sw_if_index, hostname)
+ Client.add_vpp_config()
+ self.assertTrue(Client.query_vpp_config())
rx = self.pg3.get_capture(1)
@@ -1312,7 +1292,7 @@ class TestDHCP(VppTestCase):
#
# remove the DHCP config
#
- self.vapi.dhcp_client_config(self.pg3.sw_if_index, hostname, is_add=0)
+ Client.remove_vpp_config()
#
# and now the route should be gone
@@ -1327,9 +1307,10 @@ class TestDHCP(VppTestCase):
self.pg3.admin_down()
self.sleep(1)
self.pg3.admin_up()
- self.vapi.dhcp_client_config(self.pg3.sw_if_index, hostname,
- client_id=self.pg3.local_mac,
- dscp=vdscp.IP_API_DSCP_EF)
+ Client.set_client(self.pg3.sw_if_index, hostname,
+ id=self.pg3.local_mac,
+ dscp=vdscp.IP_API_DSCP_EF)
+ Client.add_vpp_config()
rx = self.pg3.get_capture(1)
@@ -1388,7 +1369,7 @@ class TestDHCP(VppTestCase):
#
# remove the DHCP config
#
- self.vapi.dhcp_client_config(self.pg3.sw_if_index, hostname, is_add=0)
+ Client.remove_vpp_config()
self.assertFalse(find_route(self, self.pg3.local_ip4, 32))
self.assertFalse(find_route(self, self.pg3.local_ip4, 24))
@@ -1400,8 +1381,11 @@ class TestDHCP(VppTestCase):
#
# Configure DHCP client on PG3 and capture the discover sent
#
- self.vapi.dhcp_client_config(self.pg3.sw_if_index, hostname,
- set_broadcast_flag=0)
+ Client.set_client(
+ self.pg3.sw_if_index,
+ hostname,
+ set_broadcast_flag=False)
+ Client.add_vpp_config()
rx = self.pg3.get_capture(1)
@@ -1507,14 +1491,13 @@ class TestDHCP(VppTestCase):
hostname)
self.assertEqual(clients[0].lease.hostname.rstrip('\0'),
hostname)
- self.assertEqual(clients[0].lease.is_ipv6, 0)
# 0 = DISCOVER, 1 = REQUEST, 2 = BOUND
self.assertEqual(clients[0].lease.state, 2)
self.assertEqual(clients[0].lease.mask_width, 24)
- self.assertEqual(clients[0].lease.router_address.rstrip('\0'),
- self.pg3.remote_ip4n)
- self.assertEqual(clients[0].lease.host_address.rstrip('\0'),
- self.pg3.local_ip4n)
+ self.assertEqual(str(clients[0].lease.router_address),
+ self.pg3.remote_ip4)
+ self.assertEqual(str(clients[0].lease.host_address),
+ self.pg3.local_ip4)
# remove the left over ARP entry
self.vapi.ip_neighbor_add_del(self.pg3.sw_if_index,
@@ -1525,7 +1508,7 @@ class TestDHCP(VppTestCase):
#
# remove the DHCP config
#
- self.vapi.dhcp_client_config(self.pg3.sw_if_index, hostname, is_add=0)
+ Client.remove_vpp_config()
#
# and now the route should be gone
@@ -1541,7 +1524,8 @@ class TestDHCP(VppTestCase):
self.sleep(1)
self.pg3.admin_up()
self.pg_enable_capture(self.pg_interfaces)
- self.vapi.dhcp_client_config(self.pg3.sw_if_index, hostname)
+ Client.set_client(self.pg3.sw_if_index, hostname)
+ Client.add_vpp_config()
rx = self.pg3.get_capture(1)
@@ -1618,7 +1602,7 @@ class TestDHCP(VppTestCase):
#
# remove the DHCP config
#
- self.vapi.dhcp_client_config(self.pg3.sw_if_index, hostname, is_add=0)
+ Client.remove_vpp_config()
def test_dhcp_client_vlan(self):
""" DHCP Client w/ VLAN"""
@@ -1646,9 +1630,12 @@ class TestDHCP(VppTestCase):
#
# Configure DHCP client on PG3 and capture the discover sent
#
- self.vapi.dhcp_client_config(vlan_100.sw_if_index,
- hostname,
- dscp=vdscp.IP_API_DSCP_EF)
+ Client = VppDHCPClient(
+ self,
+ vlan_100.sw_if_index,
+ hostname,
+ dscp=vdscp.IP_API_DSCP_EF)
+ Client.add_vpp_config()
rx = self.pg3.get_capture(1)
@@ -1658,10 +1645,6 @@ class TestDHCP(VppTestCase):
self.verify_orig_dhcp_discover(rx[0], self.pg3, hostname,
dscp=vdscp.IP_API_DSCP_EF)
- self.vapi.dhcp_client_config(vlan_100.sw_if_index,
- hostname,
- is_add=0)
-
if __name__ == '__main__':
unittest.main(testRunner=VppTestRunner)
diff --git a/test/test_dhcp6.py b/test/test_dhcp6.py
index 2037e62e9ea..4c6b7d3ca8b 100644
--- a/test/test_dhcp6.py
+++ b/test/test_dhcp6.py
@@ -10,6 +10,7 @@ from scapy.utils6 import in6_mactoifaceid
from scapy.utils import inet_ntop, inet_pton
from framework import VppTestCase
+from vpp_papi import VppEnum
import util
@@ -52,14 +53,17 @@ class TestDHCPv6DataPlane(VppTestCase):
self.pg_enable_capture(self.pg_interfaces)
self.pg_start()
- address_bin = '\00\01\00\02\00\03' + '\00' * 8 + '\00\05'
- address = {'address': address_bin,
+ address = {'address': '1:2:3::5',
'preferred_time': 60,
'valid_time': 120}
- self.vapi.dhcp6_send_client_message(msg_type=1,
- sw_if_index=self.pg0.sw_if_index,
- T1=20, T2=40, addresses=[address],
- n_addresses=len([address]))
+ self.vapi.dhcp6_send_client_message(
+ msg_type=VppEnum.vl_api_dhcpv6_msg_type_t.DHCPV6_MSG_API_SOLICIT,
+ sw_if_index=self.pg0.sw_if_index,
+ T1=20,
+ T2=40,
+ addresses=[address],
+ n_addresses=len(
+ [address]))
rx_list = self.pg0.get_capture(1)
self.assertEqual(len(rx_list), 1)
packet = rx_list[0]
@@ -112,8 +116,8 @@ class TestDHCPv6DataPlane(VppTestCase):
self.assert_equal(ev.T2, 40)
reported_address = ev.addresses[0]
- address = inet_pton(AF_INET6, ia_na_opts.getfieldval("addr"))
- self.assert_equal(reported_address.address, address)
+ address = ia_na_opts.getfieldval("addr")
+ self.assert_equal(str(reported_address.address), address)
self.assert_equal(reported_address.preferred_time,
ia_na_opts.getfieldval("preflft"))
self.assert_equal(reported_address.valid_time,
@@ -129,13 +133,18 @@ class TestDHCPv6DataPlane(VppTestCase):
self.pg_enable_capture(self.pg_interfaces)
self.pg_start()
- prefix_bin = '\00\01\00\02\00\03' + '\00' * 10
- prefix = {'prefix': prefix_bin,
- 'prefix_length': 50,
+
+ prefix = {'prefix': {'address': '1:2:3::', 'len': 50},
'preferred_time': 60,
'valid_time': 120}
- self.vapi.dhcp6_pd_send_client_message(1, self.pg0.sw_if_index,
- T1=20, T2=40, prefixes=[prefix])
+ prefixes = [prefix]
+ self.vapi.dhcp6_pd_send_client_message(
+ msg_type=VppEnum.vl_api_dhcpv6_msg_type_t.DHCPV6_MSG_API_SOLICIT,
+ sw_if_index=self.pg0.sw_if_index,
+ T1=20,
+ T2=40,
+ prefixes=prefixes,
+ n_prefixes=len(prefixes))
rx_list = self.pg0.get_capture(1)
self.assertEqual(len(rx_list), 1)
packet = rx_list[0]
@@ -189,9 +198,10 @@ class TestDHCPv6DataPlane(VppTestCase):
self.assert_equal(ev.T2, 40)
reported_prefix = ev.prefixes[0]
- prefix = inet_pton(AF_INET6, ia_pd_opts.getfieldval("prefix"))
- self.assert_equal(reported_prefix.prefix, prefix)
- self.assert_equal(reported_prefix.prefix_length,
+ prefix = ia_pd_opts.getfieldval("prefix")
+ self.assert_equal(
+ str(reported_prefix.prefix).split('/')[0], prefix)
+ self.assert_equal(int(str(reported_prefix.prefix).split('/')[1]),
ia_pd_opts.getfieldval("plen"))
self.assert_equal(reported_prefix.preferred_time,
ia_pd_opts.getfieldval("preflft"))
@@ -288,7 +298,7 @@ class TestDHCPv6IANAControlPlane(VppTestCase):
self.assertNotEqual(elapsed_time.elapsedtime, 0)
else:
self.assertEqual(elapsed_time.elapsedtime, 0)
- except:
+ except BaseException:
packet.show()
raise
@@ -544,7 +554,7 @@ class TestDHCPv6PDControlPlane(VppTestCase):
self.assertNotEqual(elapsed_time.elapsedtime, 0)
else:
self.assertEqual(elapsed_time.elapsedtime, 0)
- except:
+ except BaseException:
packet.show()
raise
diff --git a/test/vpp_dhcp.py b/test/vpp_dhcp.py
new file mode 100644
index 00000000000..54448810042
--- /dev/null
+++ b/test/vpp_dhcp.py
@@ -0,0 +1,128 @@
+from vpp_object import VppObject
+
+
+class VppDHCPProxy(VppObject):
+
+ def __init__(
+ self,
+ test,
+ dhcp_server,
+ dhcp_src_address,
+ rx_vrf_id=0,
+ server_vrf_id=0,
+ ):
+ self._test = test
+ self._rx_vrf_id = rx_vrf_id
+ self._server_vrf_id = server_vrf_id
+ self._dhcp_server = dhcp_server
+ self._dhcp_src_address = dhcp_src_address
+
+ def set_proxy(
+ self,
+ dhcp_server,
+ dhcp_src_address,
+ rx_vrf_id=0,
+ server_vrf_id=0):
+ if self.query_vpp_config():
+ raise Exception('Vpp config present')
+ self._rx_vrf_id = rx_vrf_id
+ self._server_vrf_id = server_vrf_id
+ self._dhcp_server = dhcp_server
+ self._dhcp_src_address = dhcp_src_address
+
+ def add_vpp_config(self):
+ self._test.vapi.dhcp_proxy_config(
+ rx_vrf_id=self._rx_vrf_id,
+ server_vrf_id=self._server_vrf_id,
+ dhcp_server=self._dhcp_server,
+ dhcp_src_address=self._dhcp_src_address)
+ self._test.registry.register(self, self._test.logger)
+
+ def remove_vpp_config(self):
+ self._test.vapi.dhcp_proxy_config(
+ rx_vrf_id=self._rx_vrf_id,
+ server_vrf_id=self._server_vrf_id,
+ dhcp_server=self._dhcp_server,
+ dhcp_src_address=self._dhcp_src_address,
+ is_add=0)
+
+ def get_vpp_dump(self):
+ dump = self._test.vapi.dhcp_proxy_dump()
+ for entry in dump:
+ if entry.rx_vrf_id == self._rx_vrf_id:
+ return entry
+
+ def query_vpp_config(self):
+ dump = self.get_vpp_dump()
+ return True if dump else False
+
+ def object_id(self):
+ return "dhcp-proxy-%d" % self._rx_vrf_id
+
+
+class VppDHCPClient(VppObject):
+
+ def __init__(
+ self,
+ test,
+ sw_if_index,
+ hostname,
+ id=None,
+ want_dhcp_event=False,
+ set_broadcast_flag=True,
+ dscp=None,
+ pid=None):
+ self._test = test
+ self._sw_if_index = sw_if_index
+ self._hostname = hostname
+ self._id = id
+ self._want_dhcp_event = want_dhcp_event
+ self._set_broadcast_flag = set_broadcast_flag
+ self._dscp = dscp
+ self._pid = pid
+
+ def set_client(
+ self,
+ sw_if_index,
+ hostname,
+ id=None,
+ want_dhcp_event=False,
+ set_broadcast_flag=True,
+ dscp=None,
+ pid=None):
+ if self.query_vpp_config():
+ raise Exception('Vpp config present')
+ self._sw_if_index = sw_if_index
+ self._hostname = hostname
+ self._id = id
+ self._want_dhcp_event = want_dhcp_event
+ self._set_broadcast_flag = set_broadcast_flag
+ self._dscp = dscp
+ self._pid = pid
+
+ def add_vpp_config(self):
+ client = {'sw_if_index': self._sw_if_index, 'hostname': self._hostname,
+ 'id': self._id, 'want_dhcp_event': self._want_dhcp_event,
+ 'set_broadcast_flag': self._set_broadcast_flag,
+ 'dscp': self._dscp, 'pid': self._pid}
+ self._test.vapi.dhcp_client_config(client=client)
+ self._test.registry.register(self, self._test.logger)
+
+ def remove_vpp_config(self):
+ client = client = {
+ 'sw_if_index': self._sw_if_index,
+ 'hostname': self._hostname}
+ self._test.vapi.dhcp_client_config(client=client, is_add=0)
+
+ def get_vpp_dump(self):
+ dump = self._test.vapi.dhcp_client_dump()
+ for entry in dump:
+ if entry.client.sw_if_index == self._sw_if_index:
+ return entry
+
+ def query_vpp_config(self):
+ dump = self.get_vpp_dump()
+ return True if dump else False
+
+ def object_id(self):
+ return "dhcp-client-%s/%d" % (self._hostname, self._sw_if_index)
diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py
index 13babf28a51..0ba8af1f800 100644
--- a/test/vpp_papi_provider.py
+++ b/test/vpp_papi_provider.py
@@ -50,7 +50,8 @@ defaultmapping = {
'dhcp6_clients_enable_disable': {'enable': 1, },
'dhcp6_pd_client_enable_disable': {'enable': 1, },
'dhcp6_send_client_message': {'server_index': 4294967295, 'mrc': 1, },
- 'dhcp_client_config': {'is_add': 1, 'set_broadcast_flag': 1, },
+ 'dhcp6_pd_send_client_message': {'server_index': 0xFFFFFFFF, 'mrc': 1},
+ 'dhcp_client_config': {'is_add': 1, 'client': {'set_broadcast_flag': 1}, },
'dhcp_proxy_config': {'is_add': 1, },
'dhcp_proxy_set_vss': {'vss_type': 255, 'is_add': 1, },
'gbp_subnet_add_del': {'sw_if_index': 4294967295, 'epg_id': 65535, },
@@ -147,6 +148,8 @@ defaultmapping = {
'want_ip6_nd_events': {'enable_disable': 1, 'ip': '::', },
'want_ip6_ra_events': {'enable_disable': 1, },
'want_l2_macs_events': {'enable_disable': 1, },
+ 'want_dhcp6_reply_events': {'enable_disable': 1, 'pid': os.getpid(), },
+ 'want_dhcp6_pd_reply_events': {'enable_disable': 1, 'pid': os.getpid(), },
}
@@ -409,41 +412,6 @@ class VppPapiProvider(object):
'learn_limit': learn_limit,
'pid': os.getpid(), })
- def want_dhcp6_reply_events(self, enable_disable=1):
- return self.api(self.papi.want_dhcp6_reply_events,
- {'enable_disable': enable_disable,
- 'pid': os.getpid()})
-
- def want_dhcp6_pd_reply_events(self, enable_disable=1):
- return self.api(self.papi.want_dhcp6_pd_reply_events,
- {'enable_disable': enable_disable,
- 'pid': os.getpid()})
-
- def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
- prefixes, server_index=0xFFFFFFFF,
- irt=0, mrt=0, mrc=1, mrd=0, stop=0,
- ):
- return self.api(self.papi.dhcp6_pd_send_client_message,
- {'sw_if_index': sw_if_index,
- 'server_index': server_index,
- 'irt': irt,
- 'mrt': mrt,
- 'mrc': mrc,
- 'mrd': mrd,
- 'stop': stop,
- 'msg_type': msg_type,
- 'T1': T1,
- 'T2': T2,
- 'n_prefixes': len(prefixes),
- 'prefixes': prefixes})
-
- def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
- enable=1):
- return self.api(self.papi.dhcp6_pd_client_enable_disable,
- {'sw_if_index': sw_if_index,
- 'prefix_group': prefix_group,
- 'enable': enable})
-
def ip6_add_del_address_using_prefix(self, sw_if_index, address,
prefix_length, prefix_group,
is_add=1):
@@ -907,66 +875,6 @@ class VppPapiProvider(object):
'udp_checksum': udp_checksum,
})
- def dhcp_proxy_config(self,
- dhcp_server,
- dhcp_src_address,
- rx_table_id=0,
- server_table_id=0,
- is_add=1,
- is_ipv6=0):
- return self.api(
- self.papi.dhcp_proxy_config,
- {
- 'rx_vrf_id': rx_table_id,
- 'server_vrf_id': server_table_id,
- 'is_ipv6': is_ipv6,
- 'is_add': is_add,
- 'dhcp_server': dhcp_server,
- 'dhcp_src_address': dhcp_src_address,
- })
-
- def dhcp_proxy_set_vss(self,
- table_id,
- vss_type=255,
- vpn_ascii_id="",
- oui=0,
- vpn_index=0,
- is_add=1,
- is_ip6=0):
- return self.api(
- self.papi.dhcp_proxy_set_vss,
- {
- 'tbl_id': table_id,
- 'vss_type': vss_type,
- 'vpn_ascii_id': vpn_ascii_id,
- 'oui': oui,
- 'vpn_index': vpn_index,
- 'is_add': is_add,
- 'is_ipv6': is_ip6,
- })
-
- def dhcp_client_config(self,
- sw_if_index,
- hostname,
- client_id='',
- is_add=1,
- set_broadcast_flag=1,
- want_dhcp_events=0,
- dscp=0):
- return self.api(
- self.papi.dhcp_client_config,
- {
- 'is_add': is_add,
- 'client': {
- 'sw_if_index': sw_if_index,
- 'hostname': hostname,
- 'id': client_id,
- 'want_dhcp_event': want_dhcp_events,
- 'set_broadcast_flag': set_broadcast_flag,
- 'dscp': dscp,
- 'pid': os.getpid()}
- })
-
def ip_mroute_add_del(self,
table_id,
prefix,