+ #
+ # Start the procedure again. Use requested lease time option.
+ # this time wait for the lease to expire and the client to
+ # self-destruct
+ #
+ hostname += "-2"
+ self.pg3.admin_down()
+ self.sleep(1)
+ self.pg3.admin_up()
+ self.pg_enable_capture(self.pg_interfaces)
+ Client.set_client(self.pg3.sw_if_index, hostname)
+ Client.add_vpp_config()
+
+ 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=mac_pton(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=mac_pton(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))
+
+ #
+ # the route should be gone after the lease expires
+ #
+ self.assertTrue(self.wait_for_no_route(self.pg3.local_ip4, 32))
+ self.assertTrue(self.wait_for_no_route(self.pg3.local_ip4, 24))
+
+ #
+ # remove the DHCP config
+ #
+ Client.remove_vpp_config()
+
+ def test_dhcp_client_vlan(self):
+ """DHCP Client w/ VLAN"""
+
+ vdscp = VppEnum.vl_api_ip_dscp_t
+ vqos = VppEnum.vl_api_qos_source_t
+ hostname = "universal-dp"
+
+ self.pg_enable_capture(self.pg_interfaces)
+
+ vlan_100 = VppDot1QSubint(self, self.pg3, 100)
+ vlan_100.admin_up()
+
+ output = [scapy.compat.chb(4)] * 256
+ os = b"".join(output)
+ rows = [{"outputs": os}, {"outputs": os}, {"outputs": os}, {"outputs": os}]
+
+ qem1 = VppQosEgressMap(self, 1, rows).add_vpp_config()
+ qm1 = VppQosMark(
+ self, vlan_100, qem1, vqos.QOS_API_SOURCE_VLAN
+ ).add_vpp_config()
+
+ #
+ # Configure DHCP client on PG3 and capture the discover sent
+ #
+ 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)
+
+ self.assertEqual(rx[0][Dot1Q].vlan, 100)
+ self.assertEqual(rx[0][Dot1Q].prio, 2)
+
+ self.verify_orig_dhcp_discover(
+ rx[0], self.pg3, hostname, dscp=vdscp.IP_API_DSCP_EF
+ )
+