summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_dhcp.py109
1 files changed, 102 insertions, 7 deletions
diff --git a/test/test_dhcp.py b/test/test_dhcp.py
index 39133a35bd1..179221d6584 100644
--- a/test/test_dhcp.py
+++ b/test/test_dhcp.py
@@ -1222,7 +1222,7 @@ class TestDHCP(VppTestCase):
chaddr=mactobinary(self.pg3.local_mac)) /
DHCP(options=[('message-type', 'offer'),
('server_id', self.pg3.remote_ip4),
- ('end')]))
+ 'end']))
self.pg3.add_stream(p_offer)
self.pg_enable_capture(self.pg_interfaces)
@@ -1233,7 +1233,7 @@ class TestDHCP(VppTestCase):
self.pg3.local_ip4)
#
- # Send an acknowloedgement
+ # Send an acknowledgment
#
p_ack = (Ether(dst=self.pg3.local_mac, src=self.pg3.remote_mac) /
IP(src=self.pg3.remote_ip4, dst="255.255.255.255") /
@@ -1245,7 +1245,7 @@ class TestDHCP(VppTestCase):
('router', self.pg3.remote_ip4),
('server_id', self.pg3.remote_ip4),
('lease_time', 43200),
- ('end')]))
+ 'end']))
self.pg3.add_stream(p_ack)
self.pg_enable_capture(self.pg_interfaces)
@@ -1296,6 +1296,11 @@ class TestDHCP(VppTestCase):
self.verify_orig_dhcp_discover(rx[0], self.pg3, hostname,
self.pg3.local_mac)
+ # TODO: VPP DHCP client should not accept DHCP OFFER message with
+ # the XID (Transaction ID) not matching the XID of the most recent
+ # DHCP DISCOVERY message.
+ # Such DHCP OFFER message must be silently discarded - RFC2131.
+ # Reported in Jira ticket: VPP-99
self.pg3.add_stream(p_offer)
self.pg_enable_capture(self.pg_interfaces)
self.pg_start()
@@ -1317,7 +1322,7 @@ class TestDHCP(VppTestCase):
('router', self.pg3.remote_ip4),
('server_id', self.pg3.remote_ip4),
('lease_time', 43200),
- ('end')]))
+ 'end']))
self.pg3.add_stream(p_ack)
self.pg_enable_capture(self.pg_interfaces)
@@ -1372,7 +1377,7 @@ class TestDHCP(VppTestCase):
chaddr=mactobinary(self.pg3.local_mac)) /
DHCP(options=[('message-type', 'offer'),
('server_id', self.pg3.remote_ip4),
- ('end')]))
+ 'end']))
self.pg3.add_stream(p_offer)
self.pg_enable_capture(self.pg_interfaces)
@@ -1384,7 +1389,7 @@ class TestDHCP(VppTestCase):
broadcast=0)
#
- # Send an acknowloedgement
+ # Send an acknowledgment
#
p_ack = (Ether(dst=self.pg3.local_mac, src=self.pg3.remote_mac) /
IP(src=self.pg3.remote_ip4, dst=self.pg3.local_ip4) /
@@ -1396,7 +1401,7 @@ class TestDHCP(VppTestCase):
('router', self.pg3.remote_ip4),
('server_id', self.pg3.remote_ip4),
('lease_time', 43200),
- ('end')]))
+ 'end']))
self.pg3.add_stream(p_ack)
self.pg_enable_capture(self.pg_interfaces)
@@ -1456,6 +1461,96 @@ class TestDHCP(VppTestCase):
self.assertFalse(find_route(self, self.pg3.local_ip4, 32))
self.assertFalse(find_route(self, self.pg3.local_ip4, 24))
+ #
+ # Start the procedure again. Use requested lease time option.
+ #
+ self.pg3.admin_down()
+ self.sleep(1)
+ self.pg3.admin_up()
+ self.vapi.dhcp_client(self.pg3.sw_if_index, hostname)
+
+ rx = self.pg3.get_capture(1)
+
+ self.verify_orig_dhcp_discover(rx[0], self.pg3, hostname)
+
+ #
+ # Send back on offer with requested lease time, expect the request
+ #
+ lease_time = 1
+ p_offer = (Ether(dst=self.pg3.local_mac, src=self.pg3.remote_mac) /
+ IP(src=self.pg3.remote_ip4, dst='255.255.255.255') /
+ UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) /
+ BOOTP(op=1,
+ yiaddr=self.pg3.local_ip4,
+ chaddr=mactobinary(self.pg3.local_mac)) /
+ DHCP(options=[('message-type', 'offer'),
+ ('server_id', self.pg3.remote_ip4),
+ ('lease_time', lease_time),
+ 'end']))
+
+ self.pg3.add_stream(p_offer)
+ self.pg_enable_capture(self.pg_interfaces)
+ self.pg_start()
+
+ rx = self.pg3.get_capture(1)
+ self.verify_orig_dhcp_request(rx[0], self.pg3, hostname,
+ self.pg3.local_ip4)
+
+ #
+ # Send an acknowledgment
+ #
+ p_ack = (Ether(dst=self.pg3.local_mac, src=self.pg3.remote_mac) /
+ IP(src=self.pg3.remote_ip4, dst='255.255.255.255') /
+ UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) /
+ BOOTP(op=1, yiaddr=self.pg3.local_ip4,
+ chaddr=mactobinary(self.pg3.local_mac)) /
+ DHCP(options=[('message-type', 'ack'),
+ ('subnet_mask', '255.255.255.0'),
+ ('router', self.pg3.remote_ip4),
+ ('server_id', self.pg3.remote_ip4),
+ ('lease_time', lease_time),
+ 'end']))
+
+ self.pg3.add_stream(p_ack)
+ self.pg_enable_capture(self.pg_interfaces)
+ self.pg_start()
+
+ #
+ # We'll get an ARP request for the router address
+ #
+ rx = self.pg3.get_capture(1)
+
+ self.assertEqual(rx[0][ARP].pdst, self.pg3.remote_ip4)
+
+ #
+ # At the end of this procedure there should be a connected route
+ # in the FIB
+ #
+ self.assertTrue(find_route(self, self.pg3.local_ip4, 32))
+ self.assertTrue(find_route(self, self.pg3.local_ip4, 24))
+
+ # remove the left over ARP entry
+ self.vapi.ip_neighbor_add_del(self.pg3.sw_if_index,
+ mactobinary(self.pg3.remote_mac),
+ self.pg3.remote_ip4,
+ is_add=0)
+
+ #
+ # Sleep for the lease time
+ #
+ self.sleep(lease_time+1)
+
+ #
+ # And now the route should be gone
+ #
+ self.assertFalse(find_route(self, self.pg3.local_ip4, 32))
+ self.assertFalse(find_route(self, self.pg3.local_ip4, 24))
+
+ #
+ # remove the DHCP config
+ #
+ self.vapi.dhcp_client(self.pg3.sw_if_index, hostname, is_add=0)
+
if __name__ == '__main__':
unittest.main(testRunner=VppTestRunner)