summaryrefslogtreecommitdiffstats
path: root/test/test_dhcp.py
diff options
context:
space:
mode:
authorJakub Grajciar <jgrajcia@cisco.com>2019-10-01 11:30:56 +0200
committerOle Trøan <otroan@employees.org>2019-10-03 10:07:21 +0000
commit103ba6ba9ecd1d65bcbd3bb4edc115beb9ee7671 (patch)
treeeca605b6a3860425958b501b9eb215f8ac84326c /test/test_dhcp.py
parentd6d50cebde647f9a5ee7251a7fef977506f315d7 (diff)
dhcp: API cleanup
Use consistent API types. Type: fix Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com> Change-Id: Ia63d920788add2584060a240321acced7a471640
Diffstat (limited to 'test/test_dhcp.py')
-rw-r--r--test/test_dhcp.py263
1 files changed, 123 insertions, 140 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)