blob: 7ae98e8e83b551caa5f098c02144a763eeab2671 [file] [log] [blame]
Neale Rannsfca0c242017-01-13 07:57:46 -08001#!/usr/bin/env python
2
3import unittest
4import socket
Neale Ranns3466c302017-02-16 07:45:03 -08005import struct
Neale Rannsfca0c242017-01-13 07:57:46 -08006
John Lo70bfcaf2017-11-14 13:19:26 -05007from framework import VppTestCase, VppTestRunner, running_extended_tests
Neale Ranns3466c302017-02-16 07:45:03 -08008from vpp_neighbor import VppNeighbor
Neale Ranns15002542017-09-10 04:39:11 -07009from vpp_ip_route import find_route, VppIpTable
Neale Ranns2a3ea492017-04-19 05:24:40 -070010from util import mk_ll_addr
Neale Rannsfca0c242017-01-13 07:57:46 -080011
Neale Ranns51822bf2017-07-18 09:26:53 -070012from scapy.layers.l2 import Ether, getmacbyip, ARP
Neale Rannsfca0c242017-01-13 07:57:46 -080013from scapy.layers.inet import IP, UDP, ICMP
14from scapy.layers.inet6 import IPv6, in6_getnsmac, in6_mactoifaceid
15from scapy.layers.dhcp import DHCP, BOOTP, DHCPTypes
16from scapy.layers.dhcp6 import DHCP6, DHCP6_Solicit, DHCP6_RelayForward, \
17 DHCP6_RelayReply, DHCP6_Advertise, DHCP6OptRelayMsg, DHCP6OptIfaceId, \
Neale Ranns3466c302017-02-16 07:45:03 -080018 DHCP6OptStatusCode, DHCP6OptVSS, DHCP6OptClientLinkLayerAddr, DHCP6_Request
Neale Rannsfca0c242017-01-13 07:57:46 -080019from socket import AF_INET, AF_INET6
20from scapy.utils import inet_pton, inet_ntop
21from scapy.utils6 import in6_ptop
Ole Troan895b6e82017-10-20 13:28:20 +020022from util import mactobinary
Neale Rannsfca0c242017-01-13 07:57:46 -080023
24DHCP4_CLIENT_PORT = 68
25DHCP4_SERVER_PORT = 67
26DHCP6_CLIENT_PORT = 547
27DHCP6_SERVER_PORT = 546
28
29
Neale Rannsfca0c242017-01-13 07:57:46 -080030class TestDHCP(VppTestCase):
31 """ DHCP Test Case """
32
33 def setUp(self):
34 super(TestDHCP, self).setUp()
35
John Lo70bfcaf2017-11-14 13:19:26 -050036 # create 6 pg interfaces for pg0 to pg5
37 self.create_pg_interfaces(range(6))
Neale Ranns15002542017-09-10 04:39:11 -070038 self.tables = []
Neale Rannsfca0c242017-01-13 07:57:46 -080039
John Lo70bfcaf2017-11-14 13:19:26 -050040 # 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.
Neale Rannsfca0c242017-01-13 07:57:46 -080042 table_id = 0
Neale Ranns15002542017-09-10 04:39:11 -070043 for table_id in range(1, 4):
44 tbl4 = VppIpTable(self, table_id)
45 tbl4.add_vpp_config()
46 self.tables.append(tbl4)
47 tbl6 = VppIpTable(self, table_id, is_ip6=1)
48 tbl6.add_vpp_config()
49 self.tables.append(tbl6)
50
51 table_id = 0
John Lo70bfcaf2017-11-14 13:19:26 -050052 for i in self.pg_interfaces[:3]:
Neale Rannsfca0c242017-01-13 07:57:46 -080053 i.admin_up()
54 i.set_table_ip4(table_id)
55 i.set_table_ip6(table_id)
56 i.config_ip4()
57 i.resolve_arp()
58 i.config_ip6()
59 i.resolve_ndp()
60 table_id += 1
61
62 table_id = 0
John Lo70bfcaf2017-11-14 13:19:26 -050063 for i in self.pg_interfaces[3:]:
Neale Rannsfca0c242017-01-13 07:57:46 -080064 i.admin_up()
65 i.set_table_ip4(table_id)
66 i.set_table_ip6(table_id)
67 table_id += 1
68
Neale Ranns4008ac92017-02-13 23:20:04 -080069 def tearDown(self):
John Lo70bfcaf2017-11-14 13:19:26 -050070 for i in self.pg_interfaces[:3]:
Neale Ranns4008ac92017-02-13 23:20:04 -080071 i.unconfig_ip4()
72 i.unconfig_ip6()
Neale Ranns15002542017-09-10 04:39:11 -070073
74 for i in self.pg_interfaces:
75 i.set_table_ip4(0)
76 i.set_table_ip6(0)
Neale Ranns4008ac92017-02-13 23:20:04 -080077 i.admin_down()
Neale Ranns15002542017-09-10 04:39:11 -070078 super(TestDHCP, self).tearDown()
Neale Ranns4008ac92017-02-13 23:20:04 -080079
Neale Rannsfca0c242017-01-13 07:57:46 -080080 def send_and_assert_no_replies(self, intf, pkts, remark):
81 intf.add_stream(pkts)
82 self.pg_enable_capture(self.pg_interfaces)
83 self.pg_start()
84 for i in self.pg_interfaces:
85 i.assert_nothing_captured(remark=remark)
86
Neale Rannsa2fbf6b2017-07-18 08:23:32 -070087 def verify_dhcp_has_option(self, pkt, option, value):
88 dhcp = pkt[DHCP]
89 found = False
90
91 for i in dhcp.options:
92 if type(i) is tuple:
93 if i[0] == option:
94 self.assertEqual(i[1], value)
95 found = True
96
97 self.assertTrue(found)
98
John Lo70bfcaf2017-11-14 13:19:26 -050099 def validate_relay_options(self, pkt, intf, ip_addr, vpn_id, fib_id, oui):
Neale Rannsfca0c242017-01-13 07:57:46 -0800100 dhcp = pkt[DHCP]
101 found = 0
102 data = []
John Lo70bfcaf2017-11-14 13:19:26 -0500103 id_len = len(vpn_id)
Neale Rannsfca0c242017-01-13 07:57:46 -0800104
105 for i in dhcp.options:
106 if type(i) is tuple:
107 if i[0] == "relay_agent_Information":
108 #
109 # There are two sb-options present - each of length 6.
110 #
111 data = i[1]
Neale Ranns20a175a2017-02-14 07:28:41 -0800112 if oui != 0:
113 self.assertEqual(len(data), 24)
John Lo70bfcaf2017-11-14 13:19:26 -0500114 elif len(vpn_id) > 0:
115 self.assertEqual(len(data), len(vpn_id)+17)
Neale Ranns20a175a2017-02-14 07:28:41 -0800116 else:
117 self.assertEqual(len(data), 12)
Neale Rannsfca0c242017-01-13 07:57:46 -0800118
119 #
120 # First sub-option is ID 1, len 4, then encoded
121 # sw_if_index. This test uses low valued indicies
122 # so [2:4] are 0.
123 # The ID space is VPP internal - so no matching value
124 # scapy
125 #
126 self.assertEqual(ord(data[0]), 1)
127 self.assertEqual(ord(data[1]), 4)
128 self.assertEqual(ord(data[2]), 0)
129 self.assertEqual(ord(data[3]), 0)
130 self.assertEqual(ord(data[4]), 0)
131 self.assertEqual(ord(data[5]), intf._sw_if_index)
132
133 #
134 # next sub-option is the IP address of the client side
135 # interface.
136 # sub-option ID=5, length (of a v4 address)=4
137 #
138 claddr = socket.inet_pton(AF_INET, ip_addr)
139
140 self.assertEqual(ord(data[6]), 5)
141 self.assertEqual(ord(data[7]), 4)
142 self.assertEqual(data[8], claddr[0])
143 self.assertEqual(data[9], claddr[1])
144 self.assertEqual(data[10], claddr[2])
145 self.assertEqual(data[11], claddr[3])
146
Neale Ranns20a175a2017-02-14 07:28:41 -0800147 if oui != 0:
John Lo70bfcaf2017-11-14 13:19:26 -0500148 # sub-option 151 encodes vss_type 1,
149 # the 3 byte oui and the 4 byte fib_id
150 self.assertEqual(id_len, 0)
Neale Ranns20a175a2017-02-14 07:28:41 -0800151 self.assertEqual(ord(data[12]), 151)
152 self.assertEqual(ord(data[13]), 8)
153 self.assertEqual(ord(data[14]), 1)
154 self.assertEqual(ord(data[15]), 0)
155 self.assertEqual(ord(data[16]), 0)
156 self.assertEqual(ord(data[17]), oui)
157 self.assertEqual(ord(data[18]), 0)
158 self.assertEqual(ord(data[19]), 0)
159 self.assertEqual(ord(data[20]), 0)
160 self.assertEqual(ord(data[21]), fib_id)
161
162 # VSS control sub-option
163 self.assertEqual(ord(data[22]), 152)
164 self.assertEqual(ord(data[23]), 0)
165
John Lo70bfcaf2017-11-14 13:19:26 -0500166 if id_len > 0:
167 # sub-option 151 encode vss_type of 0
168 # followerd by vpn_id in ascii
169 self.assertEqual(oui, 0)
170 self.assertEqual(ord(data[12]), 151)
171 self.assertEqual(ord(data[13]), id_len+1)
172 self.assertEqual(ord(data[14]), 0)
173 self.assertEqual(data[15:15+id_len], vpn_id)
174
175 # VSS control sub-option
176 self.assertEqual(ord(data[15+len(vpn_id)]), 152)
177 self.assertEqual(ord(data[16+len(vpn_id)]), 0)
178
Neale Rannsfca0c242017-01-13 07:57:46 -0800179 found = 1
180 self.assertTrue(found)
181
182 return data
183
Neale Rannsa2fbf6b2017-07-18 08:23:32 -0700184 def verify_dhcp_msg_type(self, pkt, name):
185 dhcp = pkt[DHCP]
186 found = False
187 for o in dhcp.options:
188 if type(o) is tuple:
189 if o[0] == "message-type" \
190 and DHCPTypes[o[1]] == name:
191 found = True
192 self.assertTrue(found)
193
John Lo70bfcaf2017-11-14 13:19:26 -0500194 def verify_dhcp_offer(self, pkt, intf, vpn_id="", fib_id=0, oui=0):
Neale Rannsfca0c242017-01-13 07:57:46 -0800195 ether = pkt[Ether]
196 self.assertEqual(ether.dst, "ff:ff:ff:ff:ff:ff")
197 self.assertEqual(ether.src, intf.local_mac)
198
199 ip = pkt[IP]
200 self.assertEqual(ip.dst, "255.255.255.255")
201 self.assertEqual(ip.src, intf.local_ip4)
202
203 udp = pkt[UDP]
204 self.assertEqual(udp.dport, DHCP4_CLIENT_PORT)
205 self.assertEqual(udp.sport, DHCP4_SERVER_PORT)
206
Neale Rannsa2fbf6b2017-07-18 08:23:32 -0700207 self.verify_dhcp_msg_type(pkt, "offer")
Neale Ranns3466c302017-02-16 07:45:03 -0800208 data = self.validate_relay_options(pkt, intf, intf.local_ip4,
John Lo70bfcaf2017-11-14 13:19:26 -0500209 vpn_id, fib_id, oui)
Neale Rannsfca0c242017-01-13 07:57:46 -0800210
Neale Rannsa2fbf6b2017-07-18 08:23:32 -0700211 def verify_orig_dhcp_pkt(self, pkt, intf):
212 ether = pkt[Ether]
213 self.assertEqual(ether.dst, "ff:ff:ff:ff:ff:ff")
214 self.assertEqual(ether.src, intf.local_mac)
215
216 ip = pkt[IP]
217 self.assertEqual(ip.dst, "255.255.255.255")
218 self.assertEqual(ip.src, "0.0.0.0")
219
220 udp = pkt[UDP]
221 self.assertEqual(udp.dport, DHCP4_SERVER_PORT)
222 self.assertEqual(udp.sport, DHCP4_CLIENT_PORT)
223
Neale Ranns51822bf2017-07-18 09:26:53 -0700224 def verify_orig_dhcp_discover(self, pkt, intf, hostname, client_id=None):
Neale Rannsa2fbf6b2017-07-18 08:23:32 -0700225 self.verify_orig_dhcp_pkt(pkt, intf)
226
227 self.verify_dhcp_msg_type(pkt, "discover")
228 self.verify_dhcp_has_option(pkt, "hostname", hostname)
Neale Ranns51822bf2017-07-18 09:26:53 -0700229 if client_id:
230 self.verify_dhcp_has_option(pkt, "client_id", client_id)
Neale Ranns808c5b22017-08-02 05:15:07 -0700231 bootp = pkt[BOOTP]
232 self.assertEqual(bootp.ciaddr, "0.0.0.0")
233 self.assertEqual(bootp.giaddr, "0.0.0.0")
234 self.assertEqual(bootp.flags, 0x8000)
Neale Rannsa2fbf6b2017-07-18 08:23:32 -0700235
236 def verify_orig_dhcp_request(self, pkt, intf, hostname, ip):
237 self.verify_orig_dhcp_pkt(pkt, intf)
238
239 self.verify_dhcp_msg_type(pkt, "request")
240 self.verify_dhcp_has_option(pkt, "hostname", hostname)
241 self.verify_dhcp_has_option(pkt, "requested_addr", ip)
Neale Ranns808c5b22017-08-02 05:15:07 -0700242 bootp = pkt[BOOTP]
243 self.assertEqual(bootp.ciaddr, "0.0.0.0")
244 self.assertEqual(bootp.giaddr, "0.0.0.0")
245 self.assertEqual(bootp.flags, 0x8000)
Neale Rannsa2fbf6b2017-07-18 08:23:32 -0700246
247 def verify_relayed_dhcp_discover(self, pkt, intf, src_intf=None,
248 fib_id=0, oui=0,
John Lo70bfcaf2017-11-14 13:19:26 -0500249 vpn_id="",
Neale Rannsa2fbf6b2017-07-18 08:23:32 -0700250 dst_mac=None, dst_ip=None):
Neale Ranns3466c302017-02-16 07:45:03 -0800251 if not dst_mac:
252 dst_mac = intf.remote_mac
253 if not dst_ip:
254 dst_ip = intf.remote_ip4
255
Neale Rannsfca0c242017-01-13 07:57:46 -0800256 ether = pkt[Ether]
Neale Ranns3466c302017-02-16 07:45:03 -0800257 self.assertEqual(ether.dst, dst_mac)
Neale Rannsfca0c242017-01-13 07:57:46 -0800258 self.assertEqual(ether.src, intf.local_mac)
259
260 ip = pkt[IP]
Neale Ranns3466c302017-02-16 07:45:03 -0800261 self.assertEqual(ip.dst, dst_ip)
Neale Rannsfca0c242017-01-13 07:57:46 -0800262 self.assertEqual(ip.src, intf.local_ip4)
263
264 udp = pkt[UDP]
265 self.assertEqual(udp.dport, DHCP4_SERVER_PORT)
266 self.assertEqual(udp.sport, DHCP4_CLIENT_PORT)
267
268 dhcp = pkt[DHCP]
269
270 is_discover = False
271 for o in dhcp.options:
272 if type(o) is tuple:
273 if o[0] == "message-type" \
274 and DHCPTypes[o[1]] == "discover":
275 is_discover = True
276 self.assertTrue(is_discover)
277
Neale Ranns20a175a2017-02-14 07:28:41 -0800278 data = self.validate_relay_options(pkt, src_intf,
279 src_intf.local_ip4,
John Lo70bfcaf2017-11-14 13:19:26 -0500280 vpn_id,
Neale Ranns20a175a2017-02-14 07:28:41 -0800281 fib_id, oui)
282 return data
Neale Rannsfca0c242017-01-13 07:57:46 -0800283
284 def verify_dhcp6_solicit(self, pkt, intf,
285 peer_ip, peer_mac,
John Lo70bfcaf2017-11-14 13:19:26 -0500286 vpn_id="",
Neale Rannsfca0c242017-01-13 07:57:46 -0800287 fib_id=0,
Neale Ranns3466c302017-02-16 07:45:03 -0800288 oui=0,
289 dst_mac=None,
290 dst_ip=None):
291 if not dst_mac:
292 dst_mac = intf.remote_mac
293 if not dst_ip:
294 dst_ip = in6_ptop(intf.remote_ip6)
295
Neale Rannsfca0c242017-01-13 07:57:46 -0800296 ether = pkt[Ether]
Neale Ranns3466c302017-02-16 07:45:03 -0800297 self.assertEqual(ether.dst, dst_mac)
Neale Rannsfca0c242017-01-13 07:57:46 -0800298 self.assertEqual(ether.src, intf.local_mac)
299
300 ip = pkt[IPv6]
Neale Ranns3466c302017-02-16 07:45:03 -0800301 self.assertEqual(in6_ptop(ip.dst), dst_ip)
Neale Rannsfca0c242017-01-13 07:57:46 -0800302 self.assertEqual(in6_ptop(ip.src), in6_ptop(intf.local_ip6))
303
304 udp = pkt[UDP]
305 self.assertEqual(udp.dport, DHCP6_CLIENT_PORT)
306 self.assertEqual(udp.sport, DHCP6_SERVER_PORT)
307
308 relay = pkt[DHCP6_RelayForward]
309 self.assertEqual(in6_ptop(relay.peeraddr), in6_ptop(peer_ip))
310 oid = pkt[DHCP6OptIfaceId]
311 cll = pkt[DHCP6OptClientLinkLayerAddr]
312 self.assertEqual(cll.optlen, 8)
313 self.assertEqual(cll.lltype, 1)
314 self.assertEqual(cll.clladdr, peer_mac)
315
John Lo70bfcaf2017-11-14 13:19:26 -0500316 id_len = len(vpn_id)
317
Neale Ranns20a175a2017-02-14 07:28:41 -0800318 if fib_id != 0:
John Lo70bfcaf2017-11-14 13:19:26 -0500319 self.assertEqual(id_len, 0)
Neale Ranns20a175a2017-02-14 07:28:41 -0800320 vss = pkt[DHCP6OptVSS]
321 self.assertEqual(vss.optlen, 8)
322 self.assertEqual(vss.type, 1)
323 # the OUI and FIB-id are really 3 and 4 bytes resp.
324 # but the tested range is small
325 self.assertEqual(ord(vss.data[0]), 0)
326 self.assertEqual(ord(vss.data[1]), 0)
327 self.assertEqual(ord(vss.data[2]), oui)
328 self.assertEqual(ord(vss.data[3]), 0)
329 self.assertEqual(ord(vss.data[4]), 0)
330 self.assertEqual(ord(vss.data[5]), 0)
331 self.assertEqual(ord(vss.data[6]), fib_id)
Neale Rannsfca0c242017-01-13 07:57:46 -0800332
John Lo70bfcaf2017-11-14 13:19:26 -0500333 if id_len > 0:
334 self.assertEqual(oui, 0)
335 vss = pkt[DHCP6OptVSS]
336 self.assertEqual(vss.optlen, id_len+1)
337 self.assertEqual(vss.type, 0)
338 self.assertEqual(vss.data[0:id_len], vpn_id)
339
Neale Rannsfca0c242017-01-13 07:57:46 -0800340 # the relay message should be an encoded Solicit
341 msg = pkt[DHCP6OptRelayMsg]
342 sol = DHCP6_Solicit()
343 self.assertEqual(msg.optlen, len(str(sol)))
344 self.assertEqual(str(sol), (str(msg[1]))[:msg.optlen])
345
346 def verify_dhcp6_advert(self, pkt, intf, peer):
347 ether = pkt[Ether]
348 self.assertEqual(ether.dst, "ff:ff:ff:ff:ff:ff")
349 self.assertEqual(ether.src, intf.local_mac)
350
351 ip = pkt[IPv6]
352 self.assertEqual(in6_ptop(ip.dst), in6_ptop(peer))
353 self.assertEqual(in6_ptop(ip.src), in6_ptop(intf.local_ip6))
354
355 udp = pkt[UDP]
356 self.assertEqual(udp.dport, DHCP6_SERVER_PORT)
357 self.assertEqual(udp.sport, DHCP6_CLIENT_PORT)
358
359 # not sure why this is not decoding
360 # adv = pkt[DHCP6_Advertise]
361
362 def test_dhcp_proxy(self):
363 """ DHCPv4 Proxy """
364
365 #
366 # Verify no response to DHCP request without DHCP config
367 #
368 p_disc_vrf0 = (Ether(dst="ff:ff:ff:ff:ff:ff",
John Lo70bfcaf2017-11-14 13:19:26 -0500369 src=self.pg3.remote_mac) /
Neale Rannsfca0c242017-01-13 07:57:46 -0800370 IP(src="0.0.0.0", dst="255.255.255.255") /
371 UDP(sport=DHCP4_CLIENT_PORT,
372 dport=DHCP4_SERVER_PORT) /
373 BOOTP(op=1) /
374 DHCP(options=[('message-type', 'discover'), ('end')]))
375 pkts_disc_vrf0 = [p_disc_vrf0]
376 p_disc_vrf1 = (Ether(dst="ff:ff:ff:ff:ff:ff",
John Lo70bfcaf2017-11-14 13:19:26 -0500377 src=self.pg4.remote_mac) /
Neale Rannsfca0c242017-01-13 07:57:46 -0800378 IP(src="0.0.0.0", dst="255.255.255.255") /
379 UDP(sport=DHCP4_CLIENT_PORT,
380 dport=DHCP4_SERVER_PORT) /
381 BOOTP(op=1) /
382 DHCP(options=[('message-type', 'discover'), ('end')]))
John Lo70bfcaf2017-11-14 13:19:26 -0500383 pkts_disc_vrf1 = [p_disc_vrf1]
384 p_disc_vrf2 = (Ether(dst="ff:ff:ff:ff:ff:ff",
385 src=self.pg5.remote_mac) /
386 IP(src="0.0.0.0", dst="255.255.255.255") /
387 UDP(sport=DHCP4_CLIENT_PORT,
388 dport=DHCP4_SERVER_PORT) /
389 BOOTP(op=1) /
390 DHCP(options=[('message-type', 'discover'), ('end')]))
391 pkts_disc_vrf2 = [p_disc_vrf2]
Neale Rannsfca0c242017-01-13 07:57:46 -0800392
John Lo70bfcaf2017-11-14 13:19:26 -0500393 self.send_and_assert_no_replies(self.pg3, pkts_disc_vrf0,
Neale Rannsfca0c242017-01-13 07:57:46 -0800394 "DHCP with no configuration")
John Lo70bfcaf2017-11-14 13:19:26 -0500395 self.send_and_assert_no_replies(self.pg4, pkts_disc_vrf1,
396 "DHCP with no configuration")
397 self.send_and_assert_no_replies(self.pg5, pkts_disc_vrf2,
Neale Rannsfca0c242017-01-13 07:57:46 -0800398 "DHCP with no configuration")
399
400 #
401 # Enable DHCP proxy in VRF 0
402 #
403 server_addr = self.pg0.remote_ip4n
404 src_addr = self.pg0.local_ip4n
405
406 self.vapi.dhcp_proxy_config(server_addr,
407 src_addr,
408 rx_table_id=0)
409
410 #
Neale Ranns20a175a2017-02-14 07:28:41 -0800411 # Discover packets from the client are dropped because there is no
412 # IP address configured on the client facing interface
Neale Rannsfca0c242017-01-13 07:57:46 -0800413 #
John Lo70bfcaf2017-11-14 13:19:26 -0500414 self.send_and_assert_no_replies(self.pg3, pkts_disc_vrf0,
Neale Ranns20a175a2017-02-14 07:28:41 -0800415 "Discover DHCP no relay address")
Neale Rannsfca0c242017-01-13 07:57:46 -0800416
417 #
418 # Inject a response from the server
Neale Ranns20a175a2017-02-14 07:28:41 -0800419 # dropped, because there is no IP addrees on the
Neale Ranns2dd68522017-02-16 03:38:59 -0800420 # client interfce to fill in the option.
Neale Rannsfca0c242017-01-13 07:57:46 -0800421 #
422 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
423 IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) /
424 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) /
425 BOOTP(op=1) /
426 DHCP(options=[('message-type', 'offer'), ('end')]))
427 pkts = [p]
428
John Lo70bfcaf2017-11-14 13:19:26 -0500429 self.send_and_assert_no_replies(self.pg3, pkts,
Neale Ranns20a175a2017-02-14 07:28:41 -0800430 "Offer DHCP no relay address")
Neale Rannsfca0c242017-01-13 07:57:46 -0800431
432 #
433 # configure an IP address on the client facing interface
434 #
John Lo70bfcaf2017-11-14 13:19:26 -0500435 self.pg3.config_ip4()
Neale Rannsfca0c242017-01-13 07:57:46 -0800436
437 #
438 # Try again with a discover packet
439 # Rx'd packet should be to the server address and from the configured
440 # source address
441 # UDP source ports are unchanged
442 # we've no option 82 config so that should be absent
443 #
John Lo70bfcaf2017-11-14 13:19:26 -0500444 self.pg3.add_stream(pkts_disc_vrf0)
Neale Rannsfca0c242017-01-13 07:57:46 -0800445 self.pg_enable_capture(self.pg_interfaces)
446 self.pg_start()
447
448 rx = self.pg0.get_capture(1)
449 rx = rx[0]
450
Neale Rannsa2fbf6b2017-07-18 08:23:32 -0700451 option_82 = self.verify_relayed_dhcp_discover(rx, self.pg0,
John Lo70bfcaf2017-11-14 13:19:26 -0500452 src_intf=self.pg3)
Neale Rannsfca0c242017-01-13 07:57:46 -0800453
454 #
455 # Create an DHCP offer reply from the server with a correctly formatted
456 # option 82. i.e. send back what we just captured
457 # The offer, sent mcast to the client, still has option 82.
458 #
459 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
460 IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) /
461 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) /
462 BOOTP(op=1) /
463 DHCP(options=[('message-type', 'offer'),
464 ('relay_agent_Information', option_82),
465 ('end')]))
466 pkts = [p]
467
468 self.pg0.add_stream(pkts)
469 self.pg_enable_capture(self.pg_interfaces)
470 self.pg_start()
471
John Lo70bfcaf2017-11-14 13:19:26 -0500472 rx = self.pg3.get_capture(1)
Neale Rannsfca0c242017-01-13 07:57:46 -0800473 rx = rx[0]
474
John Lo70bfcaf2017-11-14 13:19:26 -0500475 self.verify_dhcp_offer(rx, self.pg3)
Neale Rannsfca0c242017-01-13 07:57:46 -0800476
477 #
478 # Bogus Option 82:
479 #
480 # 1. not our IP address = not checked by VPP? so offer is replayed
481 # to client
482 bad_ip = option_82[0:8] + chr(33) + option_82[9:]
483
484 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
485 IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) /
486 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) /
487 BOOTP(op=1) /
488 DHCP(options=[('message-type', 'offer'),
489 ('relay_agent_Information', bad_ip),
490 ('end')]))
491 pkts = [p]
Neale Ranns20a175a2017-02-14 07:28:41 -0800492 self.send_and_assert_no_replies(self.pg0, pkts,
493 "DHCP offer option 82 bad address")
Neale Rannsfca0c242017-01-13 07:57:46 -0800494
495 # 2. Not a sw_if_index VPP knows
496 bad_if_index = option_82[0:2] + chr(33) + option_82[3:]
497
498 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
499 IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) /
500 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) /
501 BOOTP(op=1) /
502 DHCP(options=[('message-type', 'offer'),
503 ('relay_agent_Information', bad_if_index),
504 ('end')]))
505 pkts = [p]
506 self.send_and_assert_no_replies(self.pg0, pkts,
507 "DHCP offer option 82 bad if index")
508
509 #
510 # Send a DHCP request in VRF 1. should be dropped.
511 #
John Lo70bfcaf2017-11-14 13:19:26 -0500512 self.send_and_assert_no_replies(self.pg4, pkts_disc_vrf1,
Neale Rannsfca0c242017-01-13 07:57:46 -0800513 "DHCP with no configuration VRF 1")
514
515 #
516 # Delete the DHCP config in VRF 0
517 # Should now drop requests.
518 #
519 self.vapi.dhcp_proxy_config(server_addr,
520 src_addr,
521 rx_table_id=0,
Neale Ranns20a175a2017-02-14 07:28:41 -0800522 is_add=0)
Neale Rannsfca0c242017-01-13 07:57:46 -0800523
John Lo70bfcaf2017-11-14 13:19:26 -0500524 self.send_and_assert_no_replies(self.pg3, pkts_disc_vrf0,
Neale Rannsfca0c242017-01-13 07:57:46 -0800525 "DHCP config removed VRF 0")
John Lo70bfcaf2017-11-14 13:19:26 -0500526 self.send_and_assert_no_replies(self.pg4, pkts_disc_vrf1,
Neale Rannsfca0c242017-01-13 07:57:46 -0800527 "DHCP config removed VRF 1")
528
529 #
John Lo70bfcaf2017-11-14 13:19:26 -0500530 # Add DHCP config for VRF 1 & 2
Neale Rannsfca0c242017-01-13 07:57:46 -0800531 #
John Lo70bfcaf2017-11-14 13:19:26 -0500532 server_addr1 = self.pg1.remote_ip4n
533 src_addr1 = self.pg1.local_ip4n
534 self.vapi.dhcp_proxy_config(server_addr1,
535 src_addr1,
Neale Rannsfca0c242017-01-13 07:57:46 -0800536 rx_table_id=1,
Neale Ranns20a175a2017-02-14 07:28:41 -0800537 server_table_id=1)
John Lo70bfcaf2017-11-14 13:19:26 -0500538 server_addr2 = self.pg2.remote_ip4n
539 src_addr2 = self.pg2.local_ip4n
540 self.vapi.dhcp_proxy_config(server_addr2,
541 src_addr2,
542 rx_table_id=2,
543 server_table_id=2)
Neale Rannsfca0c242017-01-13 07:57:46 -0800544
545 #
John Lo70bfcaf2017-11-14 13:19:26 -0500546 # Confim DHCP requests ok in VRF 1 & 2.
Neale Rannsfca0c242017-01-13 07:57:46 -0800547 # - dropped on IP config on client interface
548 #
John Lo70bfcaf2017-11-14 13:19:26 -0500549 self.send_and_assert_no_replies(self.pg4, pkts_disc_vrf1,
Neale Rannsfca0c242017-01-13 07:57:46 -0800550 "DHCP config removed VRF 1")
John Lo70bfcaf2017-11-14 13:19:26 -0500551 self.send_and_assert_no_replies(self.pg5, pkts_disc_vrf2,
552 "DHCP config removed VRF 2")
Neale Rannsfca0c242017-01-13 07:57:46 -0800553
554 #
555 # configure an IP address on the client facing interface
556 #
John Lo70bfcaf2017-11-14 13:19:26 -0500557 self.pg4.config_ip4()
558 self.pg4.add_stream(pkts_disc_vrf1)
Neale Rannsfca0c242017-01-13 07:57:46 -0800559 self.pg_enable_capture(self.pg_interfaces)
560 self.pg_start()
Neale Rannsfca0c242017-01-13 07:57:46 -0800561 rx = self.pg1.get_capture(1)
562 rx = rx[0]
John Lo70bfcaf2017-11-14 13:19:26 -0500563 self.verify_relayed_dhcp_discover(rx, self.pg1, src_intf=self.pg4)
564
565 self.pg5.config_ip4()
566 self.pg5.add_stream(pkts_disc_vrf2)
567 self.pg_enable_capture(self.pg_interfaces)
568 self.pg_start()
569 rx = self.pg2.get_capture(1)
570 rx = rx[0]
571 self.verify_relayed_dhcp_discover(rx, self.pg2, src_intf=self.pg5)
Neale Rannsfca0c242017-01-13 07:57:46 -0800572
573 #
Neale Ranns20a175a2017-02-14 07:28:41 -0800574 # Add VSS config
John Lo70bfcaf2017-11-14 13:19:26 -0500575 # table=1, vss_type=1, vpn_index=1, oui=4
576 # table=2, vss_type=0, vpn_id = "ip4-table-2"
577 self.vapi.dhcp_proxy_set_vss(1, 1, vpn_index=1, oui=4, is_add=1)
578 self.vapi.dhcp_proxy_set_vss(2, 0, "ip4-table-2", is_add=1)
Neale Ranns20a175a2017-02-14 07:28:41 -0800579
John Lo70bfcaf2017-11-14 13:19:26 -0500580 self.pg4.add_stream(pkts_disc_vrf1)
Neale Ranns20a175a2017-02-14 07:28:41 -0800581 self.pg_enable_capture(self.pg_interfaces)
582 self.pg_start()
583
584 rx = self.pg1.get_capture(1)
585 rx = rx[0]
Neale Rannsa2fbf6b2017-07-18 08:23:32 -0700586 self.verify_relayed_dhcp_discover(rx, self.pg1,
John Lo70bfcaf2017-11-14 13:19:26 -0500587 src_intf=self.pg4,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -0700588 fib_id=1, oui=4)
Neale Ranns20a175a2017-02-14 07:28:41 -0800589
John Lo70bfcaf2017-11-14 13:19:26 -0500590 self.pg5.add_stream(pkts_disc_vrf2)
591 self.pg_enable_capture(self.pg_interfaces)
592 self.pg_start()
593
594 rx = self.pg2.get_capture(1)
595 rx = rx[0]
596 self.verify_relayed_dhcp_discover(rx, self.pg2,
597 src_intf=self.pg5,
598 vpn_id="ip4-table-2")
599
Neale Ranns20a175a2017-02-14 07:28:41 -0800600 #
Neale Ranns3466c302017-02-16 07:45:03 -0800601 # Add a second DHCP server in VRF 1
602 # expect clients messages to be relay to both configured servers
603 #
604 self.pg1.generate_remote_hosts(2)
John Lo70bfcaf2017-11-14 13:19:26 -0500605 server_addr12 = socket.inet_pton(AF_INET, self.pg1.remote_hosts[1].ip4)
Neale Ranns3466c302017-02-16 07:45:03 -0800606
John Lo70bfcaf2017-11-14 13:19:26 -0500607 self.vapi.dhcp_proxy_config(server_addr12,
608 src_addr1,
Neale Ranns3466c302017-02-16 07:45:03 -0800609 rx_table_id=1,
610 server_table_id=1,
611 is_add=1)
612
613 #
614 # We'll need an ARP entry for the server to send it packets
615 #
616 arp_entry = VppNeighbor(self,
617 self.pg1.sw_if_index,
618 self.pg1.remote_hosts[1].mac,
619 self.pg1.remote_hosts[1].ip4)
620 arp_entry.add_vpp_config()
621
622 #
623 # Send a discover from the client. expect two relayed messages
624 # The frist packet is sent to the second server
625 # We're not enforcing that here, it's just the way it is.
626 #
John Lo70bfcaf2017-11-14 13:19:26 -0500627 self.pg4.add_stream(pkts_disc_vrf1)
Neale Ranns3466c302017-02-16 07:45:03 -0800628 self.pg_enable_capture(self.pg_interfaces)
629 self.pg_start()
630
631 rx = self.pg1.get_capture(2)
632
Neale Rannsa2fbf6b2017-07-18 08:23:32 -0700633 option_82 = self.verify_relayed_dhcp_discover(
Neale Ranns3466c302017-02-16 07:45:03 -0800634 rx[0], self.pg1,
John Lo70bfcaf2017-11-14 13:19:26 -0500635 src_intf=self.pg4,
Neale Ranns3466c302017-02-16 07:45:03 -0800636 dst_mac=self.pg1.remote_hosts[1].mac,
637 dst_ip=self.pg1.remote_hosts[1].ip4,
638 fib_id=1, oui=4)
Neale Rannsa2fbf6b2017-07-18 08:23:32 -0700639 self.verify_relayed_dhcp_discover(rx[1], self.pg1,
John Lo70bfcaf2017-11-14 13:19:26 -0500640 src_intf=self.pg4,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -0700641 fib_id=1, oui=4)
Neale Ranns3466c302017-02-16 07:45:03 -0800642
643 #
644 # Send both packets back. Client gets both.
645 #
646 p1 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
647 IP(src=self.pg1.remote_ip4, dst=self.pg1.local_ip4) /
648 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) /
649 BOOTP(op=1) /
650 DHCP(options=[('message-type', 'offer'),
651 ('relay_agent_Information', option_82),
652 ('end')]))
653 p2 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
654 IP(src=self.pg1.remote_hosts[1].ip4, dst=self.pg1.local_ip4) /
655 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) /
656 BOOTP(op=1) /
657 DHCP(options=[('message-type', 'offer'),
658 ('relay_agent_Information', option_82),
659 ('end')]))
660 pkts = [p1, p2]
661
662 self.pg1.add_stream(pkts)
663 self.pg_enable_capture(self.pg_interfaces)
664 self.pg_start()
665
John Lo70bfcaf2017-11-14 13:19:26 -0500666 rx = self.pg4.get_capture(2)
Neale Ranns3466c302017-02-16 07:45:03 -0800667
John Lo70bfcaf2017-11-14 13:19:26 -0500668 self.verify_dhcp_offer(rx[0], self.pg4, fib_id=1, oui=4)
669 self.verify_dhcp_offer(rx[1], self.pg4, fib_id=1, oui=4)
Neale Ranns3466c302017-02-16 07:45:03 -0800670
671 #
672 # Ensure offers from non-servers are dropeed
673 #
674 p2 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
675 IP(src="8.8.8.8", dst=self.pg1.local_ip4) /
676 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) /
677 BOOTP(op=1) /
678 DHCP(options=[('message-type', 'offer'),
679 ('relay_agent_Information', option_82),
680 ('end')]))
681 self.send_and_assert_no_replies(self.pg1, p2,
682 "DHCP offer from non-server")
683
684 #
685 # Ensure only the discover is sent to multiple servers
686 #
687 p_req_vrf1 = (Ether(dst="ff:ff:ff:ff:ff:ff",
John Lo70bfcaf2017-11-14 13:19:26 -0500688 src=self.pg4.remote_mac) /
Neale Ranns3466c302017-02-16 07:45:03 -0800689 IP(src="0.0.0.0", dst="255.255.255.255") /
690 UDP(sport=DHCP4_CLIENT_PORT,
691 dport=DHCP4_SERVER_PORT) /
692 BOOTP(op=1) /
693 DHCP(options=[('message-type', 'request'),
694 ('end')]))
695
John Lo70bfcaf2017-11-14 13:19:26 -0500696 self.pg4.add_stream(p_req_vrf1)
Neale Ranns3466c302017-02-16 07:45:03 -0800697 self.pg_enable_capture(self.pg_interfaces)
698 self.pg_start()
699
700 rx = self.pg1.get_capture(1)
701
702 #
703 # Remove the second DHCP server
704 #
John Lo70bfcaf2017-11-14 13:19:26 -0500705 self.vapi.dhcp_proxy_config(server_addr12,
706 src_addr1,
Neale Ranns3466c302017-02-16 07:45:03 -0800707 rx_table_id=1,
708 server_table_id=1,
709 is_add=0)
710
711 #
712 # Test we can still relay with the first
713 #
John Lo70bfcaf2017-11-14 13:19:26 -0500714 self.pg4.add_stream(pkts_disc_vrf1)
Neale Ranns3466c302017-02-16 07:45:03 -0800715 self.pg_enable_capture(self.pg_interfaces)
716 self.pg_start()
717
718 rx = self.pg1.get_capture(1)
719 rx = rx[0]
Neale Rannsa2fbf6b2017-07-18 08:23:32 -0700720 self.verify_relayed_dhcp_discover(rx, self.pg1,
John Lo70bfcaf2017-11-14 13:19:26 -0500721 src_intf=self.pg4,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -0700722 fib_id=1, oui=4)
Neale Ranns3466c302017-02-16 07:45:03 -0800723
724 #
Neale Ranns20a175a2017-02-14 07:28:41 -0800725 # Remove the VSS config
726 # relayed DHCP has default vlaues in the option.
727 #
John Lo70bfcaf2017-11-14 13:19:26 -0500728 self.vapi.dhcp_proxy_set_vss(1, is_add=0)
729 self.vapi.dhcp_proxy_set_vss(2, is_add=0)
Neale Ranns20a175a2017-02-14 07:28:41 -0800730
John Lo70bfcaf2017-11-14 13:19:26 -0500731 self.pg4.add_stream(pkts_disc_vrf1)
Neale Ranns20a175a2017-02-14 07:28:41 -0800732 self.pg_enable_capture(self.pg_interfaces)
733 self.pg_start()
734
735 rx = self.pg1.get_capture(1)
736 rx = rx[0]
John Lo70bfcaf2017-11-14 13:19:26 -0500737 self.verify_relayed_dhcp_discover(rx, self.pg1, src_intf=self.pg4)
Neale Ranns20a175a2017-02-14 07:28:41 -0800738
739 #
Neale Rannsfca0c242017-01-13 07:57:46 -0800740 # remove DHCP config to cleanup
741 #
John Lo70bfcaf2017-11-14 13:19:26 -0500742 self.vapi.dhcp_proxy_config(server_addr1,
743 src_addr1,
Neale Rannsfca0c242017-01-13 07:57:46 -0800744 rx_table_id=1,
Neale Ranns3466c302017-02-16 07:45:03 -0800745 server_table_id=1,
Neale Rannsfca0c242017-01-13 07:57:46 -0800746 is_add=0)
John Lo70bfcaf2017-11-14 13:19:26 -0500747 self.vapi.dhcp_proxy_config(server_addr2,
748 src_addr2,
749 rx_table_id=2,
750 server_table_id=2,
751 is_add=0)
Neale Rannsfca0c242017-01-13 07:57:46 -0800752
John Lo70bfcaf2017-11-14 13:19:26 -0500753 self.send_and_assert_no_replies(self.pg3, pkts_disc_vrf0,
Neale Rannsfca0c242017-01-13 07:57:46 -0800754 "DHCP cleanup VRF 0")
John Lo70bfcaf2017-11-14 13:19:26 -0500755 self.send_and_assert_no_replies(self.pg4, pkts_disc_vrf1,
Neale Rannsfca0c242017-01-13 07:57:46 -0800756 "DHCP cleanup VRF 1")
John Lo70bfcaf2017-11-14 13:19:26 -0500757 self.send_and_assert_no_replies(self.pg5, pkts_disc_vrf2,
758 "DHCP cleanup VRF 2")
759
Neale Ranns15002542017-09-10 04:39:11 -0700760 self.pg3.unconfig_ip4()
John Lo70bfcaf2017-11-14 13:19:26 -0500761 self.pg4.unconfig_ip4()
762 self.pg5.unconfig_ip4()
Neale Rannsfca0c242017-01-13 07:57:46 -0800763
764 def test_dhcp6_proxy(self):
765 """ DHCPv6 Proxy"""
766 #
767 # Verify no response to DHCP request without DHCP config
768 #
769 dhcp_solicit_dst = "ff02::1:2"
John Lo70bfcaf2017-11-14 13:19:26 -0500770 dhcp_solicit_src_vrf0 = mk_ll_addr(self.pg3.remote_mac)
771 dhcp_solicit_src_vrf1 = mk_ll_addr(self.pg4.remote_mac)
772 dhcp_solicit_src_vrf2 = mk_ll_addr(self.pg5.remote_mac)
Neale Rannsfca0c242017-01-13 07:57:46 -0800773 server_addr_vrf0 = self.pg0.remote_ip6n
774 src_addr_vrf0 = self.pg0.local_ip6n
775 server_addr_vrf1 = self.pg1.remote_ip6n
776 src_addr_vrf1 = self.pg1.local_ip6n
John Lo70bfcaf2017-11-14 13:19:26 -0500777 server_addr_vrf2 = self.pg2.remote_ip6n
778 src_addr_vrf2 = self.pg2.local_ip6n
Neale Rannsfca0c242017-01-13 07:57:46 -0800779
Neale Rannsfca0c242017-01-13 07:57:46 -0800780 dmac = in6_getnsmac(inet_pton(socket.AF_INET6, dhcp_solicit_dst))
John Lo70bfcaf2017-11-14 13:19:26 -0500781 p_solicit_vrf0 = (Ether(dst=dmac, src=self.pg3.remote_mac) /
Neale Rannsfca0c242017-01-13 07:57:46 -0800782 IPv6(src=dhcp_solicit_src_vrf0,
783 dst=dhcp_solicit_dst) /
784 UDP(sport=DHCP6_SERVER_PORT,
785 dport=DHCP6_CLIENT_PORT) /
786 DHCP6_Solicit())
John Lo70bfcaf2017-11-14 13:19:26 -0500787 p_solicit_vrf1 = (Ether(dst=dmac, src=self.pg4.remote_mac) /
Neale Rannsfca0c242017-01-13 07:57:46 -0800788 IPv6(src=dhcp_solicit_src_vrf1,
789 dst=dhcp_solicit_dst) /
790 UDP(sport=DHCP6_SERVER_PORT,
791 dport=DHCP6_CLIENT_PORT) /
792 DHCP6_Solicit())
John Lo70bfcaf2017-11-14 13:19:26 -0500793 p_solicit_vrf2 = (Ether(dst=dmac, src=self.pg5.remote_mac) /
794 IPv6(src=dhcp_solicit_src_vrf2,
795 dst=dhcp_solicit_dst) /
796 UDP(sport=DHCP6_SERVER_PORT,
797 dport=DHCP6_CLIENT_PORT) /
798 DHCP6_Solicit())
Neale Rannsfca0c242017-01-13 07:57:46 -0800799
John Lo70bfcaf2017-11-14 13:19:26 -0500800 self.send_and_assert_no_replies(self.pg3, p_solicit_vrf0,
Neale Rannsfca0c242017-01-13 07:57:46 -0800801 "DHCP with no configuration")
John Lo70bfcaf2017-11-14 13:19:26 -0500802 self.send_and_assert_no_replies(self.pg4, p_solicit_vrf1,
803 "DHCP with no configuration")
804 self.send_and_assert_no_replies(self.pg5, p_solicit_vrf2,
Neale Rannsfca0c242017-01-13 07:57:46 -0800805 "DHCP with no configuration")
806
807 #
808 # DHCPv6 config in VRF 0.
809 # Packets still dropped because the client facing interface has no
810 # IPv6 config
811 #
812 self.vapi.dhcp_proxy_config(server_addr_vrf0,
813 src_addr_vrf0,
814 rx_table_id=0,
815 server_table_id=0,
Neale Rannsfca0c242017-01-13 07:57:46 -0800816 is_ipv6=1)
817
John Lo70bfcaf2017-11-14 13:19:26 -0500818 self.send_and_assert_no_replies(self.pg3, p_solicit_vrf0,
Neale Rannsfca0c242017-01-13 07:57:46 -0800819 "DHCP with no configuration")
John Lo70bfcaf2017-11-14 13:19:26 -0500820 self.send_and_assert_no_replies(self.pg4, p_solicit_vrf1,
Neale Rannsfca0c242017-01-13 07:57:46 -0800821 "DHCP with no configuration")
822
823 #
824 # configure an IP address on the client facing interface
825 #
John Lo70bfcaf2017-11-14 13:19:26 -0500826 self.pg3.config_ip6()
Neale Rannsfca0c242017-01-13 07:57:46 -0800827
828 #
829 # Now the DHCP requests are relayed to the server
830 #
John Lo70bfcaf2017-11-14 13:19:26 -0500831 self.pg3.add_stream(p_solicit_vrf0)
Neale Rannsfca0c242017-01-13 07:57:46 -0800832 self.pg_enable_capture(self.pg_interfaces)
833 self.pg_start()
834
835 rx = self.pg0.get_capture(1)
Neale Ranns3466c302017-02-16 07:45:03 -0800836
837 self.verify_dhcp6_solicit(rx[0], self.pg0,
Neale Rannsfca0c242017-01-13 07:57:46 -0800838 dhcp_solicit_src_vrf0,
John Lo70bfcaf2017-11-14 13:19:26 -0500839 self.pg3.remote_mac)
Neale Rannsfca0c242017-01-13 07:57:46 -0800840
841 #
842 # Exception cases for rejected relay responses
843 #
844
845 # 1 - not a relay reply
846 p_adv_vrf0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
847 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
848 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
849 DHCP6_Advertise())
John Lo70bfcaf2017-11-14 13:19:26 -0500850 self.send_and_assert_no_replies(self.pg3, p_adv_vrf0,
Neale Rannsfca0c242017-01-13 07:57:46 -0800851 "DHCP6 not a relay reply")
852
853 # 2 - no relay message option
854 p_adv_vrf0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
855 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
856 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
857 DHCP6_RelayReply() /
858 DHCP6_Advertise())
John Lo70bfcaf2017-11-14 13:19:26 -0500859 self.send_and_assert_no_replies(self.pg3, p_adv_vrf0,
Neale Rannsfca0c242017-01-13 07:57:46 -0800860 "DHCP not a relay message")
861
862 # 3 - no circuit ID
863 p_adv_vrf0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
864 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
865 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
866 DHCP6_RelayReply() /
867 DHCP6OptRelayMsg(optlen=0) /
868 DHCP6_Advertise())
John Lo70bfcaf2017-11-14 13:19:26 -0500869 self.send_and_assert_no_replies(self.pg3, p_adv_vrf0,
Neale Rannsfca0c242017-01-13 07:57:46 -0800870 "DHCP6 no circuit ID")
871 # 4 - wrong circuit ID
872 p_adv_vrf0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
873 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
874 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
875 DHCP6_RelayReply() /
876 DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x05') /
877 DHCP6OptRelayMsg(optlen=0) /
878 DHCP6_Advertise())
John Lo70bfcaf2017-11-14 13:19:26 -0500879 self.send_and_assert_no_replies(self.pg3, p_adv_vrf0,
Neale Rannsfca0c242017-01-13 07:57:46 -0800880 "DHCP6 wrong circuit ID")
881
882 #
883 # Send the relay response (the advertisement)
884 # - no peer address
885 p_adv_vrf0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
886 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
887 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
888 DHCP6_RelayReply() /
John Lo70bfcaf2017-11-14 13:19:26 -0500889 DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x04') /
Neale Rannsfca0c242017-01-13 07:57:46 -0800890 DHCP6OptRelayMsg(optlen=0) /
891 DHCP6_Advertise(trid=1) /
892 DHCP6OptStatusCode(statuscode=0))
893 pkts_adv_vrf0 = [p_adv_vrf0]
894
895 self.pg0.add_stream(pkts_adv_vrf0)
896 self.pg_enable_capture(self.pg_interfaces)
897 self.pg_start()
898
John Lo70bfcaf2017-11-14 13:19:26 -0500899 rx = self.pg3.get_capture(1)
Neale Ranns3466c302017-02-16 07:45:03 -0800900
John Lo70bfcaf2017-11-14 13:19:26 -0500901 self.verify_dhcp6_advert(rx[0], self.pg3, "::")
Neale Rannsfca0c242017-01-13 07:57:46 -0800902
903 #
904 # Send the relay response (the advertisement)
905 # - with peer address
906 p_adv_vrf0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
907 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
908 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
909 DHCP6_RelayReply(peeraddr=dhcp_solicit_src_vrf0) /
John Lo70bfcaf2017-11-14 13:19:26 -0500910 DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x04') /
Neale Rannsfca0c242017-01-13 07:57:46 -0800911 DHCP6OptRelayMsg(optlen=0) /
912 DHCP6_Advertise(trid=1) /
913 DHCP6OptStatusCode(statuscode=0))
914 pkts_adv_vrf0 = [p_adv_vrf0]
915
916 self.pg0.add_stream(pkts_adv_vrf0)
917 self.pg_enable_capture(self.pg_interfaces)
918 self.pg_start()
919
John Lo70bfcaf2017-11-14 13:19:26 -0500920 rx = self.pg3.get_capture(1)
Neale Ranns3466c302017-02-16 07:45:03 -0800921
John Lo70bfcaf2017-11-14 13:19:26 -0500922 self.verify_dhcp6_advert(rx[0], self.pg3, dhcp_solicit_src_vrf0)
Neale Rannsfca0c242017-01-13 07:57:46 -0800923
924 #
John Lo70bfcaf2017-11-14 13:19:26 -0500925 # Add all the config for VRF 1 & 2
Neale Rannsfca0c242017-01-13 07:57:46 -0800926 #
927 self.vapi.dhcp_proxy_config(server_addr_vrf1,
928 src_addr_vrf1,
929 rx_table_id=1,
930 server_table_id=1,
Neale Rannsfca0c242017-01-13 07:57:46 -0800931 is_ipv6=1)
John Lo70bfcaf2017-11-14 13:19:26 -0500932 self.pg4.config_ip6()
933
934 self.vapi.dhcp_proxy_config(server_addr_vrf2,
935 src_addr_vrf2,
936 rx_table_id=2,
937 server_table_id=2,
938 is_ipv6=1)
939 self.pg5.config_ip6()
Neale Rannsfca0c242017-01-13 07:57:46 -0800940
941 #
942 # VRF 1 solicit
943 #
John Lo70bfcaf2017-11-14 13:19:26 -0500944 self.pg4.add_stream(p_solicit_vrf1)
Neale Rannsfca0c242017-01-13 07:57:46 -0800945 self.pg_enable_capture(self.pg_interfaces)
946 self.pg_start()
947
948 rx = self.pg1.get_capture(1)
Neale Ranns3466c302017-02-16 07:45:03 -0800949
950 self.verify_dhcp6_solicit(rx[0], self.pg1,
Neale Rannsfca0c242017-01-13 07:57:46 -0800951 dhcp_solicit_src_vrf1,
John Lo70bfcaf2017-11-14 13:19:26 -0500952 self.pg4.remote_mac)
953
954 #
955 # VRF 2 solicit
956 #
957 self.pg5.add_stream(p_solicit_vrf2)
958 self.pg_enable_capture(self.pg_interfaces)
959 self.pg_start()
960
961 rx = self.pg2.get_capture(1)
962
963 self.verify_dhcp6_solicit(rx[0], self.pg2,
964 dhcp_solicit_src_vrf2,
965 self.pg5.remote_mac)
Neale Rannsfca0c242017-01-13 07:57:46 -0800966
967 #
968 # VRF 1 Advert
969 #
970 p_adv_vrf1 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
971 IPv6(dst=self.pg1.local_ip6, src=self.pg1.remote_ip6) /
972 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
973 DHCP6_RelayReply(peeraddr=dhcp_solicit_src_vrf1) /
John Lo70bfcaf2017-11-14 13:19:26 -0500974 DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x05') /
Neale Rannsfca0c242017-01-13 07:57:46 -0800975 DHCP6OptRelayMsg(optlen=0) /
976 DHCP6_Advertise(trid=1) /
977 DHCP6OptStatusCode(statuscode=0))
978 pkts_adv_vrf1 = [p_adv_vrf1]
979
980 self.pg1.add_stream(pkts_adv_vrf1)
981 self.pg_enable_capture(self.pg_interfaces)
982 self.pg_start()
983
John Lo70bfcaf2017-11-14 13:19:26 -0500984 rx = self.pg4.get_capture(1)
Neale Ranns3466c302017-02-16 07:45:03 -0800985
John Lo70bfcaf2017-11-14 13:19:26 -0500986 self.verify_dhcp6_advert(rx[0], self.pg4, dhcp_solicit_src_vrf1)
Neale Rannsfca0c242017-01-13 07:57:46 -0800987
988 #
989 # Add VSS config
John Lo70bfcaf2017-11-14 13:19:26 -0500990 # table=1, vss_type=1, vpn_index=1, oui=4
991 # table=2, vss_type=0, vpn_id = "ip6-table-2"
992 self.vapi.dhcp_proxy_set_vss(1, 1, oui=4, vpn_index=1, is_ip6=1)
993 self.vapi.dhcp_proxy_set_vss(2, 0, "IPv6-table-2", is_ip6=1)
Neale Rannsfca0c242017-01-13 07:57:46 -0800994
John Lo70bfcaf2017-11-14 13:19:26 -0500995 self.pg4.add_stream(p_solicit_vrf1)
Neale Rannsfca0c242017-01-13 07:57:46 -0800996 self.pg_enable_capture(self.pg_interfaces)
997 self.pg_start()
998
999 rx = self.pg1.get_capture(1)
Neale Ranns3466c302017-02-16 07:45:03 -08001000
1001 self.verify_dhcp6_solicit(rx[0], self.pg1,
Neale Rannsfca0c242017-01-13 07:57:46 -08001002 dhcp_solicit_src_vrf1,
John Lo70bfcaf2017-11-14 13:19:26 -05001003 self.pg4.remote_mac,
Neale Rannsfca0c242017-01-13 07:57:46 -08001004 fib_id=1,
1005 oui=4)
1006
John Lo70bfcaf2017-11-14 13:19:26 -05001007 self.pg5.add_stream(p_solicit_vrf2)
1008 self.pg_enable_capture(self.pg_interfaces)
1009 self.pg_start()
1010
1011 rx = self.pg2.get_capture(1)
1012
1013 self.verify_dhcp6_solicit(rx[0], self.pg2,
1014 dhcp_solicit_src_vrf2,
1015 self.pg5.remote_mac,
1016 vpn_id="IPv6-table-2")
1017
Neale Rannsfca0c242017-01-13 07:57:46 -08001018 #
1019 # Remove the VSS config
1020 # relayed DHCP has default vlaues in the option.
1021 #
John Lo70bfcaf2017-11-14 13:19:26 -05001022 self.vapi.dhcp_proxy_set_vss(1, is_ip6=1, is_add=0)
Neale Rannsfca0c242017-01-13 07:57:46 -08001023
John Lo70bfcaf2017-11-14 13:19:26 -05001024 self.pg4.add_stream(p_solicit_vrf1)
Neale Rannsfca0c242017-01-13 07:57:46 -08001025 self.pg_enable_capture(self.pg_interfaces)
1026 self.pg_start()
1027
1028 rx = self.pg1.get_capture(1)
Neale Ranns3466c302017-02-16 07:45:03 -08001029
1030 self.verify_dhcp6_solicit(rx[0], self.pg1,
1031 dhcp_solicit_src_vrf1,
John Lo70bfcaf2017-11-14 13:19:26 -05001032 self.pg4.remote_mac)
Neale Ranns3466c302017-02-16 07:45:03 -08001033
1034 #
1035 # Add a second DHCP server in VRF 1
1036 # expect clients messages to be relay to both configured servers
1037 #
1038 self.pg1.generate_remote_hosts(2)
John Lo70bfcaf2017-11-14 13:19:26 -05001039 server_addr12 = socket.inet_pton(AF_INET6,
1040 self.pg1.remote_hosts[1].ip6)
Neale Ranns3466c302017-02-16 07:45:03 -08001041
John Lo70bfcaf2017-11-14 13:19:26 -05001042 self.vapi.dhcp_proxy_config(server_addr12,
Neale Ranns3466c302017-02-16 07:45:03 -08001043 src_addr_vrf1,
1044 rx_table_id=1,
1045 server_table_id=1,
1046 is_ipv6=1)
1047
1048 #
1049 # We'll need an ND entry for the server to send it packets
1050 #
1051 nd_entry = VppNeighbor(self,
1052 self.pg1.sw_if_index,
1053 self.pg1.remote_hosts[1].mac,
1054 self.pg1.remote_hosts[1].ip6,
1055 af=AF_INET6)
1056 nd_entry.add_vpp_config()
1057
1058 #
1059 # Send a discover from the client. expect two relayed messages
1060 # The frist packet is sent to the second server
1061 # We're not enforcing that here, it's just the way it is.
1062 #
John Lo70bfcaf2017-11-14 13:19:26 -05001063 self.pg4.add_stream(p_solicit_vrf1)
Neale Ranns3466c302017-02-16 07:45:03 -08001064 self.pg_enable_capture(self.pg_interfaces)
1065 self.pg_start()
1066
1067 rx = self.pg1.get_capture(2)
1068
1069 self.verify_dhcp6_solicit(rx[0], self.pg1,
1070 dhcp_solicit_src_vrf1,
John Lo70bfcaf2017-11-14 13:19:26 -05001071 self.pg4.remote_mac)
Neale Ranns3466c302017-02-16 07:45:03 -08001072 self.verify_dhcp6_solicit(rx[1], self.pg1,
1073 dhcp_solicit_src_vrf1,
John Lo70bfcaf2017-11-14 13:19:26 -05001074 self.pg4.remote_mac,
Neale Ranns3466c302017-02-16 07:45:03 -08001075 dst_mac=self.pg1.remote_hosts[1].mac,
1076 dst_ip=self.pg1.remote_hosts[1].ip6)
1077
1078 #
1079 # Send both packets back. Client gets both.
1080 #
1081 p1 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
1082 IPv6(dst=self.pg1.local_ip6, src=self.pg1.remote_ip6) /
1083 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
1084 DHCP6_RelayReply(peeraddr=dhcp_solicit_src_vrf1) /
John Lo70bfcaf2017-11-14 13:19:26 -05001085 DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x05') /
Neale Ranns3466c302017-02-16 07:45:03 -08001086 DHCP6OptRelayMsg(optlen=0) /
1087 DHCP6_Advertise(trid=1) /
1088 DHCP6OptStatusCode(statuscode=0))
1089 p2 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_hosts[1].mac) /
1090 IPv6(dst=self.pg1.local_ip6, src=self.pg1._remote_hosts[1].ip6) /
1091 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
1092 DHCP6_RelayReply(peeraddr=dhcp_solicit_src_vrf1) /
John Lo70bfcaf2017-11-14 13:19:26 -05001093 DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x05') /
Neale Ranns3466c302017-02-16 07:45:03 -08001094 DHCP6OptRelayMsg(optlen=0) /
1095 DHCP6_Advertise(trid=1) /
1096 DHCP6OptStatusCode(statuscode=0))
1097
1098 pkts = [p1, p2]
1099
1100 self.pg1.add_stream(pkts)
1101 self.pg_enable_capture(self.pg_interfaces)
1102 self.pg_start()
1103
John Lo70bfcaf2017-11-14 13:19:26 -05001104 rx = self.pg4.get_capture(2)
Neale Ranns3466c302017-02-16 07:45:03 -08001105
John Lo70bfcaf2017-11-14 13:19:26 -05001106 self.verify_dhcp6_advert(rx[0], self.pg4, dhcp_solicit_src_vrf1)
1107 self.verify_dhcp6_advert(rx[1], self.pg4, dhcp_solicit_src_vrf1)
Neale Ranns3466c302017-02-16 07:45:03 -08001108
1109 #
1110 # Ensure only solicit messages are duplicated
1111 #
John Lo70bfcaf2017-11-14 13:19:26 -05001112 p_request_vrf1 = (Ether(dst=dmac, src=self.pg4.remote_mac) /
Neale Ranns3466c302017-02-16 07:45:03 -08001113 IPv6(src=dhcp_solicit_src_vrf1,
1114 dst=dhcp_solicit_dst) /
1115 UDP(sport=DHCP6_SERVER_PORT,
1116 dport=DHCP6_CLIENT_PORT) /
1117 DHCP6_Request())
1118
John Lo70bfcaf2017-11-14 13:19:26 -05001119 self.pg4.add_stream(p_request_vrf1)
Neale Ranns3466c302017-02-16 07:45:03 -08001120 self.pg_enable_capture(self.pg_interfaces)
1121 self.pg_start()
1122
1123 rx = self.pg1.get_capture(1)
1124
1125 #
1126 # Test we drop DHCP packets from addresses that are not configured as
1127 # DHCP servers
1128 #
1129 p2 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_hosts[1].mac) /
1130 IPv6(dst=self.pg1.local_ip6, src="3001::1") /
1131 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
1132 DHCP6_RelayReply(peeraddr=dhcp_solicit_src_vrf1) /
John Lo70bfcaf2017-11-14 13:19:26 -05001133 DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x05') /
Neale Ranns3466c302017-02-16 07:45:03 -08001134 DHCP6OptRelayMsg(optlen=0) /
1135 DHCP6_Advertise(trid=1) /
1136 DHCP6OptStatusCode(statuscode=0))
1137 self.send_and_assert_no_replies(self.pg1, p2,
1138 "DHCP6 not from server")
1139
1140 #
1141 # Remove the second DHCP server
1142 #
John Lo70bfcaf2017-11-14 13:19:26 -05001143 self.vapi.dhcp_proxy_config(server_addr12,
Neale Ranns3466c302017-02-16 07:45:03 -08001144 src_addr_vrf1,
1145 rx_table_id=1,
1146 server_table_id=1,
1147 is_ipv6=1,
1148 is_add=0)
1149
1150 #
1151 # Test we can still relay with the first
1152 #
John Lo70bfcaf2017-11-14 13:19:26 -05001153 self.pg4.add_stream(p_solicit_vrf1)
Neale Ranns3466c302017-02-16 07:45:03 -08001154 self.pg_enable_capture(self.pg_interfaces)
1155 self.pg_start()
1156
1157 rx = self.pg1.get_capture(1)
1158
1159 self.verify_dhcp6_solicit(rx[0], self.pg1,
Neale Rannsfca0c242017-01-13 07:57:46 -08001160 dhcp_solicit_src_vrf1,
John Lo70bfcaf2017-11-14 13:19:26 -05001161 self.pg4.remote_mac)
Neale Rannsfca0c242017-01-13 07:57:46 -08001162
1163 #
1164 # Cleanup
1165 #
John Lo70bfcaf2017-11-14 13:19:26 -05001166 self.vapi.dhcp_proxy_config(server_addr_vrf2,
1167 src_addr_vrf2,
1168 rx_table_id=2,
1169 server_table_id=2,
1170 is_ipv6=1,
1171 is_add=0)
Neale Rannsfca0c242017-01-13 07:57:46 -08001172 self.vapi.dhcp_proxy_config(server_addr_vrf1,
1173 src_addr_vrf1,
1174 rx_table_id=1,
1175 server_table_id=1,
Neale Rannsfca0c242017-01-13 07:57:46 -08001176 is_ipv6=1,
1177 is_add=0)
Neale Ranns3466c302017-02-16 07:45:03 -08001178 self.vapi.dhcp_proxy_config(server_addr_vrf0,
1179 src_addr_vrf0,
1180 rx_table_id=0,
1181 server_table_id=0,
1182 is_ipv6=1,
1183 is_add=0)
1184
1185 # duplicate delete
1186 self.vapi.dhcp_proxy_config(server_addr_vrf0,
1187 src_addr_vrf0,
Neale Rannsfca0c242017-01-13 07:57:46 -08001188 rx_table_id=0,
1189 server_table_id=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08001190 is_ipv6=1,
1191 is_add=0)
Neale Ranns15002542017-09-10 04:39:11 -07001192 self.pg3.unconfig_ip6()
John Lo70bfcaf2017-11-14 13:19:26 -05001193 self.pg4.unconfig_ip6()
1194 self.pg5.unconfig_ip6()
Neale Rannsfca0c242017-01-13 07:57:46 -08001195
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001196 def test_dhcp_client(self):
1197 """ DHCP Client"""
1198
1199 hostname = 'universal-dp'
1200
1201 self.pg_enable_capture(self.pg_interfaces)
1202
1203 #
John Lo70bfcaf2017-11-14 13:19:26 -05001204 # Configure DHCP client on PG3 and capture the discover sent
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001205 #
John Lo70bfcaf2017-11-14 13:19:26 -05001206 self.vapi.dhcp_client(self.pg3.sw_if_index, hostname)
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001207
John Lo70bfcaf2017-11-14 13:19:26 -05001208 rx = self.pg3.get_capture(1)
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001209
John Lo70bfcaf2017-11-14 13:19:26 -05001210 self.verify_orig_dhcp_discover(rx[0], self.pg3, hostname)
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001211
1212 #
John Lo70bfcaf2017-11-14 13:19:26 -05001213 # Send back on offer, expect the request
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001214 #
John Lo70bfcaf2017-11-14 13:19:26 -05001215 p_offer = (Ether(dst=self.pg3.local_mac, src=self.pg3.remote_mac) /
1216 IP(src=self.pg3.remote_ip4, dst="255.255.255.255") /
Neale Ranns808c5b22017-08-02 05:15:07 -07001217 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) /
John Lo70bfcaf2017-11-14 13:19:26 -05001218 BOOTP(op=1, yiaddr=self.pg3.local_ip4) /
Neale Ranns808c5b22017-08-02 05:15:07 -07001219 DHCP(options=[('message-type', 'offer'),
John Lo70bfcaf2017-11-14 13:19:26 -05001220 ('server_id', self.pg3.remote_ip4),
Neale Ranns808c5b22017-08-02 05:15:07 -07001221 ('end')]))
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001222
John Lo70bfcaf2017-11-14 13:19:26 -05001223 self.pg3.add_stream(p_offer)
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001224 self.pg_enable_capture(self.pg_interfaces)
1225 self.pg_start()
1226
John Lo70bfcaf2017-11-14 13:19:26 -05001227 rx = self.pg3.get_capture(1)
1228 self.verify_orig_dhcp_request(rx[0], self.pg3, hostname,
1229 self.pg3.local_ip4)
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001230
1231 #
1232 # Send an acknowloedgement
1233 #
John Lo70bfcaf2017-11-14 13:19:26 -05001234 p_ack = (Ether(dst=self.pg3.local_mac, src=self.pg3.remote_mac) /
1235 IP(src=self.pg3.remote_ip4, dst="255.255.255.255") /
Neale Ranns808c5b22017-08-02 05:15:07 -07001236 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) /
John Lo70bfcaf2017-11-14 13:19:26 -05001237 BOOTP(op=1, yiaddr=self.pg3.local_ip4) /
Neale Ranns808c5b22017-08-02 05:15:07 -07001238 DHCP(options=[('message-type', 'ack'),
1239 ('subnet_mask', "255.255.255.0"),
John Lo70bfcaf2017-11-14 13:19:26 -05001240 ('router', self.pg3.remote_ip4),
1241 ('server_id', self.pg3.remote_ip4),
Neale Ranns808c5b22017-08-02 05:15:07 -07001242 ('lease_time', 43200),
1243 ('end')]))
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001244
John Lo70bfcaf2017-11-14 13:19:26 -05001245 self.pg3.add_stream(p_ack)
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001246 self.pg_enable_capture(self.pg_interfaces)
1247 self.pg_start()
1248
1249 #
Neale Ranns51822bf2017-07-18 09:26:53 -07001250 # We'll get an ARP request for the router address
1251 #
John Lo70bfcaf2017-11-14 13:19:26 -05001252 rx = self.pg3.get_capture(1)
Neale Ranns51822bf2017-07-18 09:26:53 -07001253
John Lo70bfcaf2017-11-14 13:19:26 -05001254 self.assertEqual(rx[0][ARP].pdst, self.pg3.remote_ip4)
Neale Ranns51822bf2017-07-18 09:26:53 -07001255 self.pg_enable_capture(self.pg_interfaces)
1256
1257 #
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001258 # At the end of this procedure there should be a connected route
1259 # in the FIB
1260 #
John Lo70bfcaf2017-11-14 13:19:26 -05001261 self.assertTrue(find_route(self, self.pg3.local_ip4, 24))
1262 self.assertTrue(find_route(self, self.pg3.local_ip4, 32))
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001263
Neale Ranns51822bf2017-07-18 09:26:53 -07001264 # remove the left over ARP entry
John Lo70bfcaf2017-11-14 13:19:26 -05001265 self.vapi.ip_neighbor_add_del(self.pg3.sw_if_index,
1266 mactobinary(self.pg3.remote_mac),
1267 self.pg3.remote_ip4,
Neale Ranns51822bf2017-07-18 09:26:53 -07001268 is_add=0)
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001269 #
1270 # remove the DHCP config
1271 #
John Lo70bfcaf2017-11-14 13:19:26 -05001272 self.vapi.dhcp_client(self.pg3.sw_if_index, hostname, is_add=0)
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001273
1274 #
1275 # and now the route should be gone
1276 #
John Lo70bfcaf2017-11-14 13:19:26 -05001277 self.assertFalse(find_route(self, self.pg3.local_ip4, 32))
1278 self.assertFalse(find_route(self, self.pg3.local_ip4, 24))
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001279
Neale Ranns51822bf2017-07-18 09:26:53 -07001280 #
Neale Ranns808c5b22017-08-02 05:15:07 -07001281 # Start the procedure again. this time have VPP send the client-ID
Neale Ranns51822bf2017-07-18 09:26:53 -07001282 #
John Lo70bfcaf2017-11-14 13:19:26 -05001283 self.pg3.admin_down()
Neale Ranns808c5b22017-08-02 05:15:07 -07001284 self.sleep(1)
John Lo70bfcaf2017-11-14 13:19:26 -05001285 self.pg3.admin_up()
1286 self.vapi.dhcp_client(self.pg3.sw_if_index, hostname,
1287 client_id=self.pg3.local_mac)
Neale Ranns51822bf2017-07-18 09:26:53 -07001288
John Lo70bfcaf2017-11-14 13:19:26 -05001289 rx = self.pg3.get_capture(1)
Neale Ranns51822bf2017-07-18 09:26:53 -07001290
John Lo70bfcaf2017-11-14 13:19:26 -05001291 self.verify_orig_dhcp_discover(rx[0], self.pg3, hostname,
1292 self.pg3.local_mac)
Neale Ranns51822bf2017-07-18 09:26:53 -07001293
John Lo70bfcaf2017-11-14 13:19:26 -05001294 self.pg3.add_stream(p_offer)
Neale Ranns808c5b22017-08-02 05:15:07 -07001295 self.pg_enable_capture(self.pg_interfaces)
1296 self.pg_start()
1297
John Lo70bfcaf2017-11-14 13:19:26 -05001298 rx = self.pg3.get_capture(1)
1299 self.verify_orig_dhcp_request(rx[0], self.pg3, hostname,
1300 self.pg3.local_ip4)
Neale Ranns808c5b22017-08-02 05:15:07 -07001301
1302 #
1303 # unicast the ack to the offered address
1304 #
John Lo70bfcaf2017-11-14 13:19:26 -05001305 p_ack = (Ether(dst=self.pg3.local_mac, src=self.pg3.remote_mac) /
1306 IP(src=self.pg3.remote_ip4, dst=self.pg3.local_ip4) /
Neale Ranns808c5b22017-08-02 05:15:07 -07001307 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) /
John Lo70bfcaf2017-11-14 13:19:26 -05001308 BOOTP(op=1, yiaddr=self.pg3.local_ip4) /
Neale Ranns808c5b22017-08-02 05:15:07 -07001309 DHCP(options=[('message-type', 'ack'),
1310 ('subnet_mask', "255.255.255.0"),
John Lo70bfcaf2017-11-14 13:19:26 -05001311 ('router', self.pg3.remote_ip4),
1312 ('server_id', self.pg3.remote_ip4),
Neale Ranns808c5b22017-08-02 05:15:07 -07001313 ('lease_time', 43200),
1314 ('end')]))
1315
John Lo70bfcaf2017-11-14 13:19:26 -05001316 self.pg3.add_stream(p_ack)
Neale Ranns808c5b22017-08-02 05:15:07 -07001317 self.pg_enable_capture(self.pg_interfaces)
1318 self.pg_start()
1319
1320 #
1321 # At the end of this procedure there should be a connected route
1322 # in the FIB
1323 #
John Lo70bfcaf2017-11-14 13:19:26 -05001324 self.assertTrue(find_route(self, self.pg3.local_ip4, 32))
1325 self.assertTrue(find_route(self, self.pg3.local_ip4, 24))
Neale Ranns808c5b22017-08-02 05:15:07 -07001326
Neale Ranns51822bf2017-07-18 09:26:53 -07001327 #
1328 # remove the DHCP config
1329 #
John Lo70bfcaf2017-11-14 13:19:26 -05001330 self.vapi.dhcp_client(self.pg3.sw_if_index, hostname, is_add=0)
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001331
John Lo70bfcaf2017-11-14 13:19:26 -05001332 self.assertFalse(find_route(self, self.pg3.local_ip4, 32))
1333 self.assertFalse(find_route(self, self.pg3.local_ip4, 24))
Neale Ranns808c5b22017-08-02 05:15:07 -07001334
1335
Neale Rannsfca0c242017-01-13 07:57:46 -08001336if __name__ == '__main__':
1337 unittest.main(testRunner=VppTestRunner)