7 from framework import VppTestCase, VppTestRunner, running_extended_tests
8 from vpp_neighbor import VppNeighbor
9 from vpp_ip_route import find_route, VppIpTable
10 from util import mk_ll_addr
11 from scapy.layers.l2 import Ether, getmacbyip, ARP
12 from scapy.layers.inet import IP, UDP, ICMP
13 from scapy.layers.inet6 import IPv6, in6_getnsmac
14 from scapy.utils6 import in6_mactoifaceid
15 from scapy.layers.dhcp import DHCP, BOOTP, DHCPTypes
16 from scapy.layers.dhcp6 import DHCP6, DHCP6_Solicit, DHCP6_RelayForward, \
17 DHCP6_RelayReply, DHCP6_Advertise, DHCP6OptRelayMsg, DHCP6OptIfaceId, \
18 DHCP6OptStatusCode, DHCP6OptVSS, DHCP6OptClientLinkLayerAddr, DHCP6_Request
19 from socket import AF_INET, AF_INET6
20 from scapy.utils import inet_pton, inet_ntop
21 from scapy.utils6 import in6_ptop
22 from vpp_papi import mac_pton
24 DHCP4_CLIENT_PORT = 68
25 DHCP4_SERVER_PORT = 67
26 DHCP6_CLIENT_PORT = 547
27 DHCP6_SERVER_PORT = 546
30 class TestDHCP(VppTestCase):
31 """ DHCP Test Case """
34 super(TestDHCP, self).setUp()
36 # create 6 pg interfaces for pg0 to pg5
37 self.create_pg_interfaces(range(6))
40 # pg0 to 2 are IP configured in VRF 0, 1 and 2.
41 # pg3 to 5 are non IP-configured in VRF 0, 1 and 2.
43 for table_id in range(1, 4):
44 tbl4 = VppIpTable(self, table_id)
46 self.tables.append(tbl4)
47 tbl6 = VppIpTable(self, table_id, is_ip6=1)
49 self.tables.append(tbl6)
52 for i in self.pg_interfaces[:3]:
54 i.set_table_ip4(table_id)
55 i.set_table_ip6(table_id)
63 for i in self.pg_interfaces[3:]:
65 i.set_table_ip4(table_id)
66 i.set_table_ip6(table_id)
70 for i in self.pg_interfaces[:3]:
74 for i in self.pg_interfaces:
78 super(TestDHCP, self).tearDown()
80 def verify_dhcp_has_option(self, pkt, option, value):
84 for i in dhcp.options:
87 self.assertEqual(i[1], value)
90 self.assertTrue(found)
92 def validate_relay_options(self, pkt, intf, ip_addr, vpn_id, fib_id, oui):
98 for i in dhcp.options:
100 if i[0] == "relay_agent_Information":
102 # There are two sb-options present - each of length 6.
106 self.assertEqual(len(data), 24)
107 elif len(vpn_id) > 0:
108 self.assertEqual(len(data), len(vpn_id)+17)
110 self.assertEqual(len(data), 12)
113 # First sub-option is ID 1, len 4, then encoded
114 # sw_if_index. This test uses low valued indicies
116 # The ID space is VPP internal - so no matching value
119 self.assertEqual(ord(data[0]), 1)
120 self.assertEqual(ord(data[1]), 4)
121 self.assertEqual(ord(data[2]), 0)
122 self.assertEqual(ord(data[3]), 0)
123 self.assertEqual(ord(data[4]), 0)
124 self.assertEqual(ord(data[5]), intf._sw_if_index)
127 # next sub-option is the IP address of the client side
129 # sub-option ID=5, length (of a v4 address)=4
131 claddr = socket.inet_pton(AF_INET, ip_addr)
133 self.assertEqual(ord(data[6]), 5)
134 self.assertEqual(ord(data[7]), 4)
135 self.assertEqual(data[8], claddr[0])
136 self.assertEqual(data[9], claddr[1])
137 self.assertEqual(data[10], claddr[2])
138 self.assertEqual(data[11], claddr[3])
141 # sub-option 151 encodes vss_type 1,
142 # the 3 byte oui and the 4 byte fib_id
143 self.assertEqual(id_len, 0)
144 self.assertEqual(ord(data[12]), 151)
145 self.assertEqual(ord(data[13]), 8)
146 self.assertEqual(ord(data[14]), 1)
147 self.assertEqual(ord(data[15]), 0)
148 self.assertEqual(ord(data[16]), 0)
149 self.assertEqual(ord(data[17]), oui)
150 self.assertEqual(ord(data[18]), 0)
151 self.assertEqual(ord(data[19]), 0)
152 self.assertEqual(ord(data[20]), 0)
153 self.assertEqual(ord(data[21]), fib_id)
155 # VSS control sub-option
156 self.assertEqual(ord(data[22]), 152)
157 self.assertEqual(ord(data[23]), 0)
160 # sub-option 151 encode vss_type of 0
161 # followerd by vpn_id in ascii
162 self.assertEqual(oui, 0)
163 self.assertEqual(ord(data[12]), 151)
164 self.assertEqual(ord(data[13]), id_len+1)
165 self.assertEqual(ord(data[14]), 0)
166 self.assertEqual(data[15:15+id_len], vpn_id)
168 # VSS control sub-option
169 self.assertEqual(ord(data[15+len(vpn_id)]), 152)
170 self.assertEqual(ord(data[16+len(vpn_id)]), 0)
173 self.assertTrue(found)
177 def verify_dhcp_msg_type(self, pkt, name):
180 for o in dhcp.options:
182 if o[0] == "message-type" \
183 and DHCPTypes[o[1]] == name:
185 self.assertTrue(found)
187 def verify_dhcp_offer(self, pkt, intf, vpn_id="", fib_id=0, oui=0):
189 self.assertEqual(ether.dst, "ff:ff:ff:ff:ff:ff")
190 self.assertEqual(ether.src, intf.local_mac)
193 self.assertEqual(ip.dst, "255.255.255.255")
194 self.assertEqual(ip.src, intf.local_ip4)
197 self.assertEqual(udp.dport, DHCP4_CLIENT_PORT)
198 self.assertEqual(udp.sport, DHCP4_SERVER_PORT)
200 self.verify_dhcp_msg_type(pkt, "offer")
201 data = self.validate_relay_options(pkt, intf, intf.local_ip4,
204 def verify_orig_dhcp_pkt(self, pkt, intf):
206 self.assertEqual(ether.dst, "ff:ff:ff:ff:ff:ff")
207 self.assertEqual(ether.src, intf.local_mac)
210 self.assertEqual(ip.dst, "255.255.255.255")
211 self.assertEqual(ip.src, "0.0.0.0")
214 self.assertEqual(udp.dport, DHCP4_SERVER_PORT)
215 self.assertEqual(udp.sport, DHCP4_CLIENT_PORT)
217 def verify_orig_dhcp_discover(self, pkt, intf, hostname, client_id=None,
219 self.verify_orig_dhcp_pkt(pkt, intf)
221 self.verify_dhcp_msg_type(pkt, "discover")
222 self.verify_dhcp_has_option(pkt, "hostname", hostname)
224 self.verify_dhcp_has_option(pkt, "client_id", client_id)
226 self.assertEqual(bootp.ciaddr, "0.0.0.0")
227 self.assertEqual(bootp.giaddr, "0.0.0.0")
229 self.assertEqual(bootp.flags, 0x8000)
231 self.assertEqual(bootp.flags, 0x0000)
233 def verify_orig_dhcp_request(self, pkt, intf, hostname, ip,
235 self.verify_orig_dhcp_pkt(pkt, intf)
237 self.verify_dhcp_msg_type(pkt, "request")
238 self.verify_dhcp_has_option(pkt, "hostname", hostname)
239 self.verify_dhcp_has_option(pkt, "requested_addr", ip)
241 self.assertEqual(bootp.ciaddr, "0.0.0.0")
242 self.assertEqual(bootp.giaddr, "0.0.0.0")
244 self.assertEqual(bootp.flags, 0x8000)
246 self.assertEqual(bootp.flags, 0x0000)
248 def verify_relayed_dhcp_discover(self, pkt, intf, src_intf=None,
251 dst_mac=None, dst_ip=None):
253 dst_mac = intf.remote_mac
255 dst_ip = intf.remote_ip4
258 self.assertEqual(ether.dst, dst_mac)
259 self.assertEqual(ether.src, intf.local_mac)
262 self.assertEqual(ip.dst, dst_ip)
263 self.assertEqual(ip.src, intf.local_ip4)
266 self.assertEqual(udp.dport, DHCP4_SERVER_PORT)
267 self.assertEqual(udp.sport, DHCP4_CLIENT_PORT)
272 for o in dhcp.options:
274 if o[0] == "message-type" \
275 and DHCPTypes[o[1]] == "discover":
277 self.assertTrue(is_discover)
279 data = self.validate_relay_options(pkt, src_intf,
285 def verify_dhcp6_solicit(self, pkt, intf,
293 dst_mac = intf.remote_mac
295 dst_ip = in6_ptop(intf.remote_ip6)
298 self.assertEqual(ether.dst, dst_mac)
299 self.assertEqual(ether.src, intf.local_mac)
302 self.assertEqual(in6_ptop(ip.dst), dst_ip)
303 self.assertEqual(in6_ptop(ip.src), in6_ptop(intf.local_ip6))
306 self.assertEqual(udp.dport, DHCP6_CLIENT_PORT)
307 self.assertEqual(udp.sport, DHCP6_SERVER_PORT)
309 relay = pkt[DHCP6_RelayForward]
310 self.assertEqual(in6_ptop(relay.peeraddr), in6_ptop(peer_ip))
311 oid = pkt[DHCP6OptIfaceId]
312 cll = pkt[DHCP6OptClientLinkLayerAddr]
313 self.assertEqual(cll.optlen, 8)
314 self.assertEqual(cll.lltype, 1)
315 self.assertEqual(cll.clladdr, peer_mac)
320 self.assertEqual(id_len, 0)
321 vss = pkt[DHCP6OptVSS]
322 self.assertEqual(vss.optlen, 8)
323 self.assertEqual(vss.type, 1)
324 # the OUI and FIB-id are really 3 and 4 bytes resp.
325 # but the tested range is small
326 self.assertEqual(ord(vss.data[0]), 0)
327 self.assertEqual(ord(vss.data[1]), 0)
328 self.assertEqual(ord(vss.data[2]), oui)
329 self.assertEqual(ord(vss.data[3]), 0)
330 self.assertEqual(ord(vss.data[4]), 0)
331 self.assertEqual(ord(vss.data[5]), 0)
332 self.assertEqual(ord(vss.data[6]), fib_id)
335 self.assertEqual(oui, 0)
336 vss = pkt[DHCP6OptVSS]
337 self.assertEqual(vss.optlen, id_len+1)
338 self.assertEqual(vss.type, 0)
339 self.assertEqual(vss.data[0:id_len], vpn_id)
341 # the relay message should be an encoded Solicit
342 msg = pkt[DHCP6OptRelayMsg]
343 sol = DHCP6_Solicit()
344 self.assertEqual(msg.optlen, len(str(sol)))
345 self.assertEqual(str(sol), (str(msg[1]))[:msg.optlen])
347 def verify_dhcp6_advert(self, pkt, intf, peer):
349 self.assertEqual(ether.dst, "ff:ff:ff:ff:ff:ff")
350 self.assertEqual(ether.src, intf.local_mac)
353 self.assertEqual(in6_ptop(ip.dst), in6_ptop(peer))
354 self.assertEqual(in6_ptop(ip.src), in6_ptop(intf.local_ip6))
357 self.assertEqual(udp.dport, DHCP6_SERVER_PORT)
358 self.assertEqual(udp.sport, DHCP6_CLIENT_PORT)
360 # not sure why this is not decoding
361 # adv = pkt[DHCP6_Advertise]
363 def wait_for_no_route(self, address, length,
364 n_tries=50, s_time=1):
366 if not find_route(self, address, length):
368 n_tries = n_tries - 1
373 def test_dhcp_proxy(self):
377 # Verify no response to DHCP request without DHCP config
379 p_disc_vrf0 = (Ether(dst="ff:ff:ff:ff:ff:ff",
380 src=self.pg3.remote_mac) /
381 IP(src="0.0.0.0", dst="255.255.255.255") /
382 UDP(sport=DHCP4_CLIENT_PORT,
383 dport=DHCP4_SERVER_PORT) /
385 DHCP(options=[('message-type', 'discover'), ('end')]))
386 pkts_disc_vrf0 = [p_disc_vrf0]
387 p_disc_vrf1 = (Ether(dst="ff:ff:ff:ff:ff:ff",
388 src=self.pg4.remote_mac) /
389 IP(src="0.0.0.0", dst="255.255.255.255") /
390 UDP(sport=DHCP4_CLIENT_PORT,
391 dport=DHCP4_SERVER_PORT) /
393 DHCP(options=[('message-type', 'discover'), ('end')]))
394 pkts_disc_vrf1 = [p_disc_vrf1]
395 p_disc_vrf2 = (Ether(dst="ff:ff:ff:ff:ff:ff",
396 src=self.pg5.remote_mac) /
397 IP(src="0.0.0.0", dst="255.255.255.255") /
398 UDP(sport=DHCP4_CLIENT_PORT,
399 dport=DHCP4_SERVER_PORT) /
401 DHCP(options=[('message-type', 'discover'), ('end')]))
402 pkts_disc_vrf2 = [p_disc_vrf2]
404 self.send_and_assert_no_replies(self.pg3, pkts_disc_vrf0,
405 "DHCP with no configuration")
406 self.send_and_assert_no_replies(self.pg4, pkts_disc_vrf1,
407 "DHCP with no configuration")
408 self.send_and_assert_no_replies(self.pg5, pkts_disc_vrf2,
409 "DHCP with no configuration")
412 # Enable DHCP proxy in VRF 0
414 server_addr = self.pg0.remote_ip4n
415 src_addr = self.pg0.local_ip4n
417 self.vapi.dhcp_proxy_config(server_addr,
422 # Discover packets from the client are dropped because there is no
423 # IP address configured on the client facing interface
425 self.send_and_assert_no_replies(self.pg3, pkts_disc_vrf0,
426 "Discover DHCP no relay address")
429 # Inject a response from the server
430 # dropped, because there is no IP addrees on the
431 # client interfce to fill in the option.
433 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
434 IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) /
435 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) /
437 DHCP(options=[('message-type', 'offer'), ('end')]))
440 self.send_and_assert_no_replies(self.pg3, pkts,
441 "Offer DHCP no relay address")
444 # configure an IP address on the client facing interface
446 self.pg3.config_ip4()
449 # Try again with a discover packet
450 # Rx'd packet should be to the server address and from the configured
452 # UDP source ports are unchanged
453 # we've no option 82 config so that should be absent
455 self.pg3.add_stream(pkts_disc_vrf0)
456 self.pg_enable_capture(self.pg_interfaces)
459 rx = self.pg0.get_capture(1)
462 option_82 = self.verify_relayed_dhcp_discover(rx, self.pg0,
466 # Create an DHCP offer reply from the server with a correctly formatted
467 # option 82. i.e. send back what we just captured
468 # The offer, sent mcast to the client, still has option 82.
470 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
471 IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) /
472 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) /
474 DHCP(options=[('message-type', 'offer'),
475 ('relay_agent_Information', option_82),
479 self.pg0.add_stream(pkts)
480 self.pg_enable_capture(self.pg_interfaces)
483 rx = self.pg3.get_capture(1)
486 self.verify_dhcp_offer(rx, self.pg3)
491 # 1. not our IP address = not checked by VPP? so offer is replayed
493 bad_ip = option_82[0:8] + chr(33) + option_82[9:]
495 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
496 IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) /
497 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) /
499 DHCP(options=[('message-type', 'offer'),
500 ('relay_agent_Information', bad_ip),
503 self.send_and_assert_no_replies(self.pg0, pkts,
504 "DHCP offer option 82 bad address")
506 # 2. Not a sw_if_index VPP knows
507 bad_if_index = option_82[0:2] + chr(33) + option_82[3:]
509 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
510 IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) /
511 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) /
513 DHCP(options=[('message-type', 'offer'),
514 ('relay_agent_Information', bad_if_index),
517 self.send_and_assert_no_replies(self.pg0, pkts,
518 "DHCP offer option 82 bad if index")
521 # Send a DHCP request in VRF 1. should be dropped.
523 self.send_and_assert_no_replies(self.pg4, pkts_disc_vrf1,
524 "DHCP with no configuration VRF 1")
527 # Delete the DHCP config in VRF 0
528 # Should now drop requests.
530 self.vapi.dhcp_proxy_config(server_addr,
535 self.send_and_assert_no_replies(self.pg3, pkts_disc_vrf0,
536 "DHCP config removed VRF 0")
537 self.send_and_assert_no_replies(self.pg4, pkts_disc_vrf1,
538 "DHCP config removed VRF 1")
541 # Add DHCP config for VRF 1 & 2
543 server_addr1 = self.pg1.remote_ip4n
544 src_addr1 = self.pg1.local_ip4n
545 self.vapi.dhcp_proxy_config(server_addr1,
549 server_addr2 = self.pg2.remote_ip4n
550 src_addr2 = self.pg2.local_ip4n
551 self.vapi.dhcp_proxy_config(server_addr2,
557 # Confim DHCP requests ok in VRF 1 & 2.
558 # - dropped on IP config on client interface
560 self.send_and_assert_no_replies(self.pg4, pkts_disc_vrf1,
561 "DHCP config removed VRF 1")
562 self.send_and_assert_no_replies(self.pg5, pkts_disc_vrf2,
563 "DHCP config removed VRF 2")
566 # configure an IP address on the client facing interface
568 self.pg4.config_ip4()
569 self.pg4.add_stream(pkts_disc_vrf1)
570 self.pg_enable_capture(self.pg_interfaces)
572 rx = self.pg1.get_capture(1)
574 self.verify_relayed_dhcp_discover(rx, self.pg1, src_intf=self.pg4)
576 self.pg5.config_ip4()
577 self.pg5.add_stream(pkts_disc_vrf2)
578 self.pg_enable_capture(self.pg_interfaces)
580 rx = self.pg2.get_capture(1)
582 self.verify_relayed_dhcp_discover(rx, self.pg2, src_intf=self.pg5)
586 # table=1, vss_type=1, vpn_index=1, oui=4
587 # table=2, vss_type=0, vpn_id = "ip4-table-2"
588 self.vapi.dhcp_proxy_set_vss(1, 1, vpn_index=1, oui=4, is_add=1)
589 self.vapi.dhcp_proxy_set_vss(2, 0, "ip4-table-2", is_add=1)
591 self.pg4.add_stream(pkts_disc_vrf1)
592 self.pg_enable_capture(self.pg_interfaces)
595 rx = self.pg1.get_capture(1)
597 self.verify_relayed_dhcp_discover(rx, self.pg1,
601 self.pg5.add_stream(pkts_disc_vrf2)
602 self.pg_enable_capture(self.pg_interfaces)
605 rx = self.pg2.get_capture(1)
607 self.verify_relayed_dhcp_discover(rx, self.pg2,
609 vpn_id="ip4-table-2")
612 # Add a second DHCP server in VRF 1
613 # expect clients messages to be relay to both configured servers
615 self.pg1.generate_remote_hosts(2)
616 server_addr12 = socket.inet_pton(AF_INET, self.pg1.remote_hosts[1].ip4)
618 self.vapi.dhcp_proxy_config(server_addr12,
625 # We'll need an ARP entry for the server to send it packets
627 arp_entry = VppNeighbor(self,
628 self.pg1.sw_if_index,
629 self.pg1.remote_hosts[1].mac,
630 self.pg1.remote_hosts[1].ip4)
631 arp_entry.add_vpp_config()
634 # Send a discover from the client. expect two relayed messages
635 # The frist packet is sent to the second server
636 # We're not enforcing that here, it's just the way it is.
638 self.pg4.add_stream(pkts_disc_vrf1)
639 self.pg_enable_capture(self.pg_interfaces)
642 rx = self.pg1.get_capture(2)
644 option_82 = self.verify_relayed_dhcp_discover(
647 dst_mac=self.pg1.remote_hosts[1].mac,
648 dst_ip=self.pg1.remote_hosts[1].ip4,
650 self.verify_relayed_dhcp_discover(rx[1], self.pg1,
655 # Send both packets back. Client gets both.
657 p1 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
658 IP(src=self.pg1.remote_ip4, dst=self.pg1.local_ip4) /
659 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) /
661 DHCP(options=[('message-type', 'offer'),
662 ('relay_agent_Information', option_82),
664 p2 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
665 IP(src=self.pg1.remote_hosts[1].ip4, dst=self.pg1.local_ip4) /
666 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) /
668 DHCP(options=[('message-type', 'offer'),
669 ('relay_agent_Information', option_82),
673 self.pg1.add_stream(pkts)
674 self.pg_enable_capture(self.pg_interfaces)
677 rx = self.pg4.get_capture(2)
679 self.verify_dhcp_offer(rx[0], self.pg4, fib_id=1, oui=4)
680 self.verify_dhcp_offer(rx[1], self.pg4, fib_id=1, oui=4)
683 # Ensure offers from non-servers are dropeed
685 p2 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
686 IP(src="8.8.8.8", dst=self.pg1.local_ip4) /
687 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) /
689 DHCP(options=[('message-type', 'offer'),
690 ('relay_agent_Information', option_82),
692 self.send_and_assert_no_replies(self.pg1, p2,
693 "DHCP offer from non-server")
696 # Ensure only the discover is sent to multiple servers
698 p_req_vrf1 = (Ether(dst="ff:ff:ff:ff:ff:ff",
699 src=self.pg4.remote_mac) /
700 IP(src="0.0.0.0", dst="255.255.255.255") /
701 UDP(sport=DHCP4_CLIENT_PORT,
702 dport=DHCP4_SERVER_PORT) /
704 DHCP(options=[('message-type', 'request'),
707 self.pg4.add_stream(p_req_vrf1)
708 self.pg_enable_capture(self.pg_interfaces)
711 rx = self.pg1.get_capture(1)
714 # Remove the second DHCP server
716 self.vapi.dhcp_proxy_config(server_addr12,
723 # Test we can still relay with the first
725 self.pg4.add_stream(pkts_disc_vrf1)
726 self.pg_enable_capture(self.pg_interfaces)
729 rx = self.pg1.get_capture(1)
731 self.verify_relayed_dhcp_discover(rx, self.pg1,
736 # Remove the VSS config
737 # relayed DHCP has default vlaues in the option.
739 self.vapi.dhcp_proxy_set_vss(1, is_add=0)
740 self.vapi.dhcp_proxy_set_vss(2, is_add=0)
742 self.pg4.add_stream(pkts_disc_vrf1)
743 self.pg_enable_capture(self.pg_interfaces)
746 rx = self.pg1.get_capture(1)
748 self.verify_relayed_dhcp_discover(rx, self.pg1, src_intf=self.pg4)
751 # remove DHCP config to cleanup
753 self.vapi.dhcp_proxy_config(server_addr1,
758 self.vapi.dhcp_proxy_config(server_addr2,
764 self.send_and_assert_no_replies(self.pg3, pkts_disc_vrf0,
765 "DHCP cleanup VRF 0")
766 self.send_and_assert_no_replies(self.pg4, pkts_disc_vrf1,
767 "DHCP cleanup VRF 1")
768 self.send_and_assert_no_replies(self.pg5, pkts_disc_vrf2,
769 "DHCP cleanup VRF 2")
771 self.pg3.unconfig_ip4()
772 self.pg4.unconfig_ip4()
773 self.pg5.unconfig_ip4()
775 def test_dhcp6_proxy(self):
778 # Verify no response to DHCP request without DHCP config
780 dhcp_solicit_dst = "ff02::1:2"
781 dhcp_solicit_src_vrf0 = mk_ll_addr(self.pg3.remote_mac)
782 dhcp_solicit_src_vrf1 = mk_ll_addr(self.pg4.remote_mac)
783 dhcp_solicit_src_vrf2 = mk_ll_addr(self.pg5.remote_mac)
784 server_addr_vrf0 = self.pg0.remote_ip6n
785 src_addr_vrf0 = self.pg0.local_ip6n
786 server_addr_vrf1 = self.pg1.remote_ip6n
787 src_addr_vrf1 = self.pg1.local_ip6n
788 server_addr_vrf2 = self.pg2.remote_ip6n
789 src_addr_vrf2 = self.pg2.local_ip6n
791 dmac = in6_getnsmac(inet_pton(socket.AF_INET6, dhcp_solicit_dst))
792 p_solicit_vrf0 = (Ether(dst=dmac, src=self.pg3.remote_mac) /
793 IPv6(src=dhcp_solicit_src_vrf0,
794 dst=dhcp_solicit_dst) /
795 UDP(sport=DHCP6_SERVER_PORT,
796 dport=DHCP6_CLIENT_PORT) /
798 p_solicit_vrf1 = (Ether(dst=dmac, src=self.pg4.remote_mac) /
799 IPv6(src=dhcp_solicit_src_vrf1,
800 dst=dhcp_solicit_dst) /
801 UDP(sport=DHCP6_SERVER_PORT,
802 dport=DHCP6_CLIENT_PORT) /
804 p_solicit_vrf2 = (Ether(dst=dmac, src=self.pg5.remote_mac) /
805 IPv6(src=dhcp_solicit_src_vrf2,
806 dst=dhcp_solicit_dst) /
807 UDP(sport=DHCP6_SERVER_PORT,
808 dport=DHCP6_CLIENT_PORT) /
811 self.send_and_assert_no_replies(self.pg3, p_solicit_vrf0,
812 "DHCP with no configuration")
813 self.send_and_assert_no_replies(self.pg4, p_solicit_vrf1,
814 "DHCP with no configuration")
815 self.send_and_assert_no_replies(self.pg5, p_solicit_vrf2,
816 "DHCP with no configuration")
819 # DHCPv6 config in VRF 0.
820 # Packets still dropped because the client facing interface has no
823 self.vapi.dhcp_proxy_config(server_addr_vrf0,
829 self.send_and_assert_no_replies(self.pg3, p_solicit_vrf0,
830 "DHCP with no configuration")
831 self.send_and_assert_no_replies(self.pg4, p_solicit_vrf1,
832 "DHCP with no configuration")
835 # configure an IP address on the client facing interface
837 self.pg3.config_ip6()
840 # Now the DHCP requests are relayed to the server
842 self.pg3.add_stream(p_solicit_vrf0)
843 self.pg_enable_capture(self.pg_interfaces)
846 rx = self.pg0.get_capture(1)
848 self.verify_dhcp6_solicit(rx[0], self.pg0,
849 dhcp_solicit_src_vrf0,
853 # Exception cases for rejected relay responses
856 # 1 - not a relay reply
857 p_adv_vrf0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
858 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
859 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
861 self.send_and_assert_no_replies(self.pg3, p_adv_vrf0,
862 "DHCP6 not a relay reply")
864 # 2 - no relay message option
865 p_adv_vrf0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
866 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
867 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
870 self.send_and_assert_no_replies(self.pg3, p_adv_vrf0,
871 "DHCP not a relay message")
874 p_adv_vrf0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
875 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
876 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
878 DHCP6OptRelayMsg(optlen=0) /
880 self.send_and_assert_no_replies(self.pg3, p_adv_vrf0,
881 "DHCP6 no circuit ID")
882 # 4 - wrong circuit ID
883 p_adv_vrf0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
884 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
885 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
887 DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x05') /
888 DHCP6OptRelayMsg(optlen=0) /
890 self.send_and_assert_no_replies(self.pg3, p_adv_vrf0,
891 "DHCP6 wrong circuit ID")
894 # Send the relay response (the advertisement)
896 p_adv_vrf0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
897 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
898 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
900 DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x04') /
901 DHCP6OptRelayMsg(optlen=0) /
902 DHCP6_Advertise(trid=1) /
903 DHCP6OptStatusCode(statuscode=0))
904 pkts_adv_vrf0 = [p_adv_vrf0]
906 self.pg0.add_stream(pkts_adv_vrf0)
907 self.pg_enable_capture(self.pg_interfaces)
910 rx = self.pg3.get_capture(1)
912 self.verify_dhcp6_advert(rx[0], self.pg3, "::")
915 # Send the relay response (the advertisement)
916 # - with peer address
917 p_adv_vrf0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
918 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
919 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
920 DHCP6_RelayReply(peeraddr=dhcp_solicit_src_vrf0) /
921 DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x04') /
922 DHCP6OptRelayMsg(optlen=0) /
923 DHCP6_Advertise(trid=1) /
924 DHCP6OptStatusCode(statuscode=0))
925 pkts_adv_vrf0 = [p_adv_vrf0]
927 self.pg0.add_stream(pkts_adv_vrf0)
928 self.pg_enable_capture(self.pg_interfaces)
931 rx = self.pg3.get_capture(1)
933 self.verify_dhcp6_advert(rx[0], self.pg3, dhcp_solicit_src_vrf0)
936 # Add all the config for VRF 1 & 2
938 self.vapi.dhcp_proxy_config(server_addr_vrf1,
943 self.pg4.config_ip6()
945 self.vapi.dhcp_proxy_config(server_addr_vrf2,
950 self.pg5.config_ip6()
955 self.pg4.add_stream(p_solicit_vrf1)
956 self.pg_enable_capture(self.pg_interfaces)
959 rx = self.pg1.get_capture(1)
961 self.verify_dhcp6_solicit(rx[0], self.pg1,
962 dhcp_solicit_src_vrf1,
968 self.pg5.add_stream(p_solicit_vrf2)
969 self.pg_enable_capture(self.pg_interfaces)
972 rx = self.pg2.get_capture(1)
974 self.verify_dhcp6_solicit(rx[0], self.pg2,
975 dhcp_solicit_src_vrf2,
981 p_adv_vrf1 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
982 IPv6(dst=self.pg1.local_ip6, src=self.pg1.remote_ip6) /
983 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
984 DHCP6_RelayReply(peeraddr=dhcp_solicit_src_vrf1) /
985 DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x05') /
986 DHCP6OptRelayMsg(optlen=0) /
987 DHCP6_Advertise(trid=1) /
988 DHCP6OptStatusCode(statuscode=0))
989 pkts_adv_vrf1 = [p_adv_vrf1]
991 self.pg1.add_stream(pkts_adv_vrf1)
992 self.pg_enable_capture(self.pg_interfaces)
995 rx = self.pg4.get_capture(1)
997 self.verify_dhcp6_advert(rx[0], self.pg4, dhcp_solicit_src_vrf1)
1001 # table=1, vss_type=1, vpn_index=1, oui=4
1002 # table=2, vss_type=0, vpn_id = "ip6-table-2"
1003 self.vapi.dhcp_proxy_set_vss(1, 1, oui=4, vpn_index=1, is_ip6=1)
1004 self.vapi.dhcp_proxy_set_vss(2, 0, "IPv6-table-2", is_ip6=1)
1006 self.pg4.add_stream(p_solicit_vrf1)
1007 self.pg_enable_capture(self.pg_interfaces)
1010 rx = self.pg1.get_capture(1)
1012 self.verify_dhcp6_solicit(rx[0], self.pg1,
1013 dhcp_solicit_src_vrf1,
1014 self.pg4.remote_mac,
1018 self.pg5.add_stream(p_solicit_vrf2)
1019 self.pg_enable_capture(self.pg_interfaces)
1022 rx = self.pg2.get_capture(1)
1024 self.verify_dhcp6_solicit(rx[0], self.pg2,
1025 dhcp_solicit_src_vrf2,
1026 self.pg5.remote_mac,
1027 vpn_id="IPv6-table-2")
1030 # Remove the VSS config
1031 # relayed DHCP has default vlaues in the option.
1033 self.vapi.dhcp_proxy_set_vss(1, is_ip6=1, is_add=0)
1035 self.pg4.add_stream(p_solicit_vrf1)
1036 self.pg_enable_capture(self.pg_interfaces)
1039 rx = self.pg1.get_capture(1)
1041 self.verify_dhcp6_solicit(rx[0], self.pg1,
1042 dhcp_solicit_src_vrf1,
1043 self.pg4.remote_mac)
1046 # Add a second DHCP server in VRF 1
1047 # expect clients messages to be relay to both configured servers
1049 self.pg1.generate_remote_hosts(2)
1050 server_addr12 = socket.inet_pton(AF_INET6,
1051 self.pg1.remote_hosts[1].ip6)
1053 self.vapi.dhcp_proxy_config(server_addr12,
1060 # We'll need an ND entry for the server to send it packets
1062 nd_entry = VppNeighbor(self,
1063 self.pg1.sw_if_index,
1064 self.pg1.remote_hosts[1].mac,
1065 self.pg1.remote_hosts[1].ip6)
1066 nd_entry.add_vpp_config()
1069 # Send a discover from the client. expect two relayed messages
1070 # The frist packet is sent to the second server
1071 # We're not enforcing that here, it's just the way it is.
1073 self.pg4.add_stream(p_solicit_vrf1)
1074 self.pg_enable_capture(self.pg_interfaces)
1077 rx = self.pg1.get_capture(2)
1079 self.verify_dhcp6_solicit(rx[0], self.pg1,
1080 dhcp_solicit_src_vrf1,
1081 self.pg4.remote_mac)
1082 self.verify_dhcp6_solicit(rx[1], self.pg1,
1083 dhcp_solicit_src_vrf1,
1084 self.pg4.remote_mac,
1085 dst_mac=self.pg1.remote_hosts[1].mac,
1086 dst_ip=self.pg1.remote_hosts[1].ip6)
1089 # Send both packets back. Client gets both.
1091 p1 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
1092 IPv6(dst=self.pg1.local_ip6, src=self.pg1.remote_ip6) /
1093 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
1094 DHCP6_RelayReply(peeraddr=dhcp_solicit_src_vrf1) /
1095 DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x05') /
1096 DHCP6OptRelayMsg(optlen=0) /
1097 DHCP6_Advertise(trid=1) /
1098 DHCP6OptStatusCode(statuscode=0))
1099 p2 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_hosts[1].mac) /
1100 IPv6(dst=self.pg1.local_ip6, src=self.pg1._remote_hosts[1].ip6) /
1101 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
1102 DHCP6_RelayReply(peeraddr=dhcp_solicit_src_vrf1) /
1103 DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x05') /
1104 DHCP6OptRelayMsg(optlen=0) /
1105 DHCP6_Advertise(trid=1) /
1106 DHCP6OptStatusCode(statuscode=0))
1110 self.pg1.add_stream(pkts)
1111 self.pg_enable_capture(self.pg_interfaces)
1114 rx = self.pg4.get_capture(2)
1116 self.verify_dhcp6_advert(rx[0], self.pg4, dhcp_solicit_src_vrf1)
1117 self.verify_dhcp6_advert(rx[1], self.pg4, dhcp_solicit_src_vrf1)
1120 # Ensure only solicit messages are duplicated
1122 p_request_vrf1 = (Ether(dst=dmac, src=self.pg4.remote_mac) /
1123 IPv6(src=dhcp_solicit_src_vrf1,
1124 dst=dhcp_solicit_dst) /
1125 UDP(sport=DHCP6_SERVER_PORT,
1126 dport=DHCP6_CLIENT_PORT) /
1129 self.pg4.add_stream(p_request_vrf1)
1130 self.pg_enable_capture(self.pg_interfaces)
1133 rx = self.pg1.get_capture(1)
1136 # Test we drop DHCP packets from addresses that are not configured as
1139 p2 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_hosts[1].mac) /
1140 IPv6(dst=self.pg1.local_ip6, src="3001::1") /
1141 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
1142 DHCP6_RelayReply(peeraddr=dhcp_solicit_src_vrf1) /
1143 DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x05') /
1144 DHCP6OptRelayMsg(optlen=0) /
1145 DHCP6_Advertise(trid=1) /
1146 DHCP6OptStatusCode(statuscode=0))
1147 self.send_and_assert_no_replies(self.pg1, p2,
1148 "DHCP6 not from server")
1151 # Remove the second DHCP server
1153 self.vapi.dhcp_proxy_config(server_addr12,
1161 # Test we can still relay with the first
1163 self.pg4.add_stream(p_solicit_vrf1)
1164 self.pg_enable_capture(self.pg_interfaces)
1167 rx = self.pg1.get_capture(1)
1169 self.verify_dhcp6_solicit(rx[0], self.pg1,
1170 dhcp_solicit_src_vrf1,
1171 self.pg4.remote_mac)
1176 self.vapi.dhcp_proxy_config(server_addr_vrf2,
1182 self.vapi.dhcp_proxy_config(server_addr_vrf1,
1188 self.vapi.dhcp_proxy_config(server_addr_vrf0,
1196 self.vapi.dhcp_proxy_config(server_addr_vrf0,
1202 self.pg3.unconfig_ip6()
1203 self.pg4.unconfig_ip6()
1204 self.pg5.unconfig_ip6()
1206 def test_dhcp_client(self):
1209 hostname = 'universal-dp'
1211 self.pg_enable_capture(self.pg_interfaces)
1214 # Configure DHCP client on PG3 and capture the discover sent
1216 self.vapi.dhcp_client(self.pg3.sw_if_index, hostname)
1218 rx = self.pg3.get_capture(1)
1220 self.verify_orig_dhcp_discover(rx[0], self.pg3, hostname)
1223 # Send back on offer, expect the request
1225 p_offer = (Ether(dst=self.pg3.local_mac, src=self.pg3.remote_mac) /
1226 IP(src=self.pg3.remote_ip4, dst="255.255.255.255") /
1227 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) /
1229 yiaddr=self.pg3.local_ip4,
1230 chaddr=mac_pton(self.pg3.local_mac)) /
1231 DHCP(options=[('message-type', 'offer'),
1232 ('server_id', self.pg3.remote_ip4),
1235 self.pg3.add_stream(p_offer)
1236 self.pg_enable_capture(self.pg_interfaces)
1239 rx = self.pg3.get_capture(1)
1240 self.verify_orig_dhcp_request(rx[0], self.pg3, hostname,
1244 # Send an acknowledgment
1246 p_ack = (Ether(dst=self.pg3.local_mac, src=self.pg3.remote_mac) /
1247 IP(src=self.pg3.remote_ip4, dst="255.255.255.255") /
1248 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) /
1249 BOOTP(op=1, yiaddr=self.pg3.local_ip4,
1250 chaddr=mac_pton(self.pg3.local_mac)) /
1251 DHCP(options=[('message-type', 'ack'),
1252 ('subnet_mask', "255.255.255.0"),
1253 ('router', self.pg3.remote_ip4),
1254 ('server_id', self.pg3.remote_ip4),
1255 ('lease_time', 43200),
1258 self.pg3.add_stream(p_ack)
1259 self.pg_enable_capture(self.pg_interfaces)
1263 # We'll get an ARP request for the router address
1265 rx = self.pg3.get_capture(1)
1267 self.assertEqual(rx[0][ARP].pdst, self.pg3.remote_ip4)
1268 self.pg_enable_capture(self.pg_interfaces)
1271 # At the end of this procedure there should be a connected route
1274 self.assertTrue(find_route(self, self.pg3.local_ip4, 24))
1275 self.assertTrue(find_route(self, self.pg3.local_ip4, 32))
1277 # remove the left over ARP entry
1278 self.vapi.ip_neighbor_add_del(self.pg3.sw_if_index,
1279 self.pg3.remote_mac,
1280 self.pg3.remote_ip4,
1284 # remove the DHCP config
1286 self.vapi.dhcp_client(self.pg3.sw_if_index, hostname, is_add=0)
1289 # and now the route should be gone
1291 self.assertFalse(find_route(self, self.pg3.local_ip4, 32))
1292 self.assertFalse(find_route(self, self.pg3.local_ip4, 24))
1295 # Start the procedure again. this time have VPP send the client-ID
1297 self.pg3.admin_down()
1300 self.vapi.dhcp_client(self.pg3.sw_if_index, hostname,
1301 client_id=self.pg3.local_mac)
1303 rx = self.pg3.get_capture(1)
1305 self.verify_orig_dhcp_discover(rx[0], self.pg3, hostname,
1308 # TODO: VPP DHCP client should not accept DHCP OFFER message with
1309 # the XID (Transaction ID) not matching the XID of the most recent
1310 # DHCP DISCOVERY message.
1311 # Such DHCP OFFER message must be silently discarded - RFC2131.
1312 # Reported in Jira ticket: VPP-99
1313 self.pg3.add_stream(p_offer)
1314 self.pg_enable_capture(self.pg_interfaces)
1317 rx = self.pg3.get_capture(1)
1318 self.verify_orig_dhcp_request(rx[0], self.pg3, hostname,
1322 # unicast the ack to the offered address
1324 p_ack = (Ether(dst=self.pg3.local_mac, src=self.pg3.remote_mac) /
1325 IP(src=self.pg3.remote_ip4, dst=self.pg3.local_ip4) /
1326 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) /
1327 BOOTP(op=1, yiaddr=self.pg3.local_ip4,
1328 chaddr=mac_pton(self.pg3.local_mac)) /
1329 DHCP(options=[('message-type', 'ack'),
1330 ('subnet_mask', "255.255.255.0"),
1331 ('router', self.pg3.remote_ip4),
1332 ('server_id', self.pg3.remote_ip4),
1333 ('lease_time', 43200),
1336 self.pg3.add_stream(p_ack)
1337 self.pg_enable_capture(self.pg_interfaces)
1341 # We'll get an ARP request for the router address
1343 rx = self.pg3.get_capture(1)
1345 self.assertEqual(rx[0][ARP].pdst, self.pg3.remote_ip4)
1346 self.pg_enable_capture(self.pg_interfaces)
1349 # At the end of this procedure there should be a connected route
1352 self.assertTrue(find_route(self, self.pg3.local_ip4, 32))
1353 self.assertTrue(find_route(self, self.pg3.local_ip4, 24))
1356 # remove the DHCP config
1358 self.vapi.dhcp_client(self.pg3.sw_if_index, hostname, is_add=0)
1360 self.assertFalse(find_route(self, self.pg3.local_ip4, 32))
1361 self.assertFalse(find_route(self, self.pg3.local_ip4, 24))
1364 # Rince and repeat, this time with VPP configured not to set
1365 # the braodcast flag in the discover and request messages,
1366 # and for the server to unicast the responses.
1368 # Configure DHCP client on PG3 and capture the discover sent
1370 self.vapi.dhcp_client(self.pg3.sw_if_index, hostname,
1371 set_broadcast_flag=0)
1373 rx = self.pg3.get_capture(1)
1375 self.verify_orig_dhcp_discover(rx[0], self.pg3, hostname,
1379 # Send back on offer, unicasted to the offered address.
1380 # Expect the request.
1382 p_offer = (Ether(dst=self.pg3.local_mac, src=self.pg3.remote_mac) /
1383 IP(src=self.pg3.remote_ip4, dst=self.pg3.local_ip4) /
1384 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) /
1385 BOOTP(op=1, yiaddr=self.pg3.local_ip4,
1386 chaddr=mac_pton(self.pg3.local_mac)) /
1387 DHCP(options=[('message-type', 'offer'),
1388 ('server_id', self.pg3.remote_ip4),
1391 self.pg3.add_stream(p_offer)
1392 self.pg_enable_capture(self.pg_interfaces)
1395 rx = self.pg3.get_capture(1)
1396 self.verify_orig_dhcp_request(rx[0], self.pg3, hostname,
1401 # Send an acknowledgment
1403 p_ack = (Ether(dst=self.pg3.local_mac, src=self.pg3.remote_mac) /
1404 IP(src=self.pg3.remote_ip4, dst=self.pg3.local_ip4) /
1405 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) /
1406 BOOTP(op=1, yiaddr=self.pg3.local_ip4,
1407 chaddr=mac_pton(self.pg3.local_mac)) /
1408 DHCP(options=[('message-type', 'ack'),
1409 ('subnet_mask', "255.255.255.0"),
1410 ('router', self.pg3.remote_ip4),
1411 ('server_id', self.pg3.remote_ip4),
1412 ('lease_time', 43200),
1415 self.pg3.add_stream(p_ack)
1416 self.pg_enable_capture(self.pg_interfaces)
1420 # We'll get an ARP request for the router address
1422 rx = self.pg3.get_capture(1)
1424 self.assertEqual(rx[0][ARP].pdst, self.pg3.remote_ip4)
1425 self.pg_enable_capture(self.pg_interfaces)
1428 # At the end of this procedure there should be a connected route
1431 self.assertTrue(find_route(self, self.pg3.local_ip4, 24))
1432 self.assertTrue(find_route(self, self.pg3.local_ip4, 32))
1434 # remove the left over ARP entry
1435 self.vapi.ip_neighbor_add_del(self.pg3.sw_if_index,
1436 self.pg3.remote_mac,
1437 self.pg3.remote_ip4,
1441 # read the DHCP client details from a dump
1443 clients = self.vapi.dhcp_client_dump()
1445 self.assertEqual(clients[0].client.sw_if_index,
1446 self.pg3.sw_if_index)
1447 self.assertEqual(clients[0].lease.sw_if_index,
1448 self.pg3.sw_if_index)
1449 self.assertEqual(clients[0].client.hostname.rstrip('\0'),
1451 self.assertEqual(clients[0].lease.hostname.rstrip('\0'),
1453 self.assertEqual(clients[0].lease.is_ipv6, 0)
1454 # 0 = DISCOVER, 1 = REQUEST, 2 = BOUND
1455 self.assertEqual(clients[0].lease.state, 2)
1456 self.assertEqual(clients[0].lease.mask_width, 24)
1457 self.assertEqual(clients[0].lease.router_address.rstrip('\0'),
1458 self.pg3.remote_ip4n)
1459 self.assertEqual(clients[0].lease.host_address.rstrip('\0'),
1460 self.pg3.local_ip4n)
1463 # remove the DHCP config
1465 self.vapi.dhcp_client(self.pg3.sw_if_index, hostname, is_add=0)
1468 # and now the route should be gone
1470 self.assertFalse(find_route(self, self.pg3.local_ip4, 32))
1471 self.assertFalse(find_route(self, self.pg3.local_ip4, 24))
1474 # Start the procedure again. Use requested lease time option.
1476 self.pg3.admin_down()
1479 self.vapi.dhcp_client(self.pg3.sw_if_index, hostname)
1481 rx = self.pg3.get_capture(1)
1483 self.verify_orig_dhcp_discover(rx[0], self.pg3, hostname)
1486 # Send back on offer with requested lease time, expect the request
1489 p_offer = (Ether(dst=self.pg3.local_mac, src=self.pg3.remote_mac) /
1490 IP(src=self.pg3.remote_ip4, dst='255.255.255.255') /
1491 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) /
1493 yiaddr=self.pg3.local_ip4,
1494 chaddr=mac_pton(self.pg3.local_mac)) /
1495 DHCP(options=[('message-type', 'offer'),
1496 ('server_id', self.pg3.remote_ip4),
1497 ('lease_time', lease_time),
1500 self.pg3.add_stream(p_offer)
1501 self.pg_enable_capture(self.pg_interfaces)
1504 rx = self.pg3.get_capture(1)
1505 self.verify_orig_dhcp_request(rx[0], self.pg3, hostname,
1509 # Send an acknowledgment
1511 p_ack = (Ether(dst=self.pg3.local_mac, src=self.pg3.remote_mac) /
1512 IP(src=self.pg3.remote_ip4, dst='255.255.255.255') /
1513 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) /
1514 BOOTP(op=1, yiaddr=self.pg3.local_ip4,
1515 chaddr=mac_pton(self.pg3.local_mac)) /
1516 DHCP(options=[('message-type', 'ack'),
1517 ('subnet_mask', '255.255.255.0'),
1518 ('router', self.pg3.remote_ip4),
1519 ('server_id', self.pg3.remote_ip4),
1520 ('lease_time', lease_time),
1523 self.pg3.add_stream(p_ack)
1524 self.pg_enable_capture(self.pg_interfaces)
1528 # We'll get an ARP request for the router address
1530 rx = self.pg3.get_capture(1)
1532 self.assertEqual(rx[0][ARP].pdst, self.pg3.remote_ip4)
1535 # At the end of this procedure there should be a connected route
1538 self.assertTrue(find_route(self, self.pg3.local_ip4, 32))
1539 self.assertTrue(find_route(self, self.pg3.local_ip4, 24))
1541 # remove the left over ARP entry
1542 self.vapi.ip_neighbor_add_del(self.pg3.sw_if_index,
1543 self.pg3.remote_mac,
1544 self.pg3.remote_ip4,
1548 # the route should be gone after the lease expires
1550 self.assertTrue(self.wait_for_no_route(self.pg3.local_ip4, 32))
1551 self.assertTrue(self.wait_for_no_route(self.pg3.local_ip4, 24))
1554 # remove the DHCP config
1556 self.vapi.dhcp_client(self.pg3.sw_if_index, hostname, is_add=0)
1559 if __name__ == '__main__':
1560 unittest.main(testRunner=VppTestRunner)