blob: 6299975b869a86533c52f958c1fbdda09eb1bfc1 [file] [log] [blame]
Neale Rannsfca0c242017-01-13 07:57:46 -08001#!/usr/bin/env python
2
3import unittest
4import socket
5
6from framework import VppTestCase, VppTestRunner
Neale Rannsfca0c242017-01-13 07:57:46 -08007
8from scapy.layers.l2 import Ether, getmacbyip
9from scapy.layers.inet import IP, UDP, ICMP
10from scapy.layers.inet6 import IPv6, in6_getnsmac, in6_mactoifaceid
11from scapy.layers.dhcp import DHCP, BOOTP, DHCPTypes
12from scapy.layers.dhcp6 import DHCP6, DHCP6_Solicit, DHCP6_RelayForward, \
13 DHCP6_RelayReply, DHCP6_Advertise, DHCP6OptRelayMsg, DHCP6OptIfaceId, \
14 DHCP6OptStatusCode, DHCP6OptVSS, DHCP6OptClientLinkLayerAddr
15from socket import AF_INET, AF_INET6
16from scapy.utils import inet_pton, inet_ntop
17from scapy.utils6 import in6_ptop
18
19DHCP4_CLIENT_PORT = 68
20DHCP4_SERVER_PORT = 67
21DHCP6_CLIENT_PORT = 547
22DHCP6_SERVER_PORT = 546
23
24
25def mk_ll_addr(mac):
26
27 euid = in6_mactoifaceid(mac)
28 addr = "fe80::" + euid
29 return addr
30
31
32class TestDHCP(VppTestCase):
33 """ DHCP Test Case """
34
35 def setUp(self):
36 super(TestDHCP, self).setUp()
37
38 # create 3 pg interfaces
39 self.create_pg_interfaces(range(4))
40
41 # pg0 and 1 are IP configured in VRF 0 and 1.
42 # pg2 and 3 are non IP-configured in VRF 0 and 1
43 table_id = 0
44 for i in self.pg_interfaces[:2]:
45 i.admin_up()
46 i.set_table_ip4(table_id)
47 i.set_table_ip6(table_id)
48 i.config_ip4()
49 i.resolve_arp()
50 i.config_ip6()
51 i.resolve_ndp()
52 table_id += 1
53
54 table_id = 0
55 for i in self.pg_interfaces[2:]:
56 i.admin_up()
57 i.set_table_ip4(table_id)
58 i.set_table_ip6(table_id)
59 table_id += 1
60
61 def send_and_assert_no_replies(self, intf, pkts, remark):
62 intf.add_stream(pkts)
63 self.pg_enable_capture(self.pg_interfaces)
64 self.pg_start()
65 for i in self.pg_interfaces:
66 i.assert_nothing_captured(remark=remark)
67
Neale Ranns20a175a2017-02-14 07:28:41 -080068 def validate_relay_options(self, pkt, intf, ip_addr, fib_id, oui):
Neale Rannsfca0c242017-01-13 07:57:46 -080069 dhcp = pkt[DHCP]
70 found = 0
71 data = []
72
73 for i in dhcp.options:
74 if type(i) is tuple:
75 if i[0] == "relay_agent_Information":
76 #
77 # There are two sb-options present - each of length 6.
78 #
79 data = i[1]
Neale Ranns20a175a2017-02-14 07:28:41 -080080 if oui != 0:
81 self.assertEqual(len(data), 24)
82 else:
83 self.assertEqual(len(data), 12)
Neale Rannsfca0c242017-01-13 07:57:46 -080084
85 #
86 # First sub-option is ID 1, len 4, then encoded
87 # sw_if_index. This test uses low valued indicies
88 # so [2:4] are 0.
89 # The ID space is VPP internal - so no matching value
90 # scapy
91 #
92 self.assertEqual(ord(data[0]), 1)
93 self.assertEqual(ord(data[1]), 4)
94 self.assertEqual(ord(data[2]), 0)
95 self.assertEqual(ord(data[3]), 0)
96 self.assertEqual(ord(data[4]), 0)
97 self.assertEqual(ord(data[5]), intf._sw_if_index)
98
99 #
100 # next sub-option is the IP address of the client side
101 # interface.
102 # sub-option ID=5, length (of a v4 address)=4
103 #
104 claddr = socket.inet_pton(AF_INET, ip_addr)
105
106 self.assertEqual(ord(data[6]), 5)
107 self.assertEqual(ord(data[7]), 4)
108 self.assertEqual(data[8], claddr[0])
109 self.assertEqual(data[9], claddr[1])
110 self.assertEqual(data[10], claddr[2])
111 self.assertEqual(data[11], claddr[3])
112
Neale Ranns20a175a2017-02-14 07:28:41 -0800113 if oui != 0:
114 # sub-option 151 encodes the 3 byte oui
115 # and the 4 byte fib_id
116 self.assertEqual(ord(data[12]), 151)
117 self.assertEqual(ord(data[13]), 8)
118 self.assertEqual(ord(data[14]), 1)
119 self.assertEqual(ord(data[15]), 0)
120 self.assertEqual(ord(data[16]), 0)
121 self.assertEqual(ord(data[17]), oui)
122 self.assertEqual(ord(data[18]), 0)
123 self.assertEqual(ord(data[19]), 0)
124 self.assertEqual(ord(data[20]), 0)
125 self.assertEqual(ord(data[21]), fib_id)
126
127 # VSS control sub-option
128 self.assertEqual(ord(data[22]), 152)
129 self.assertEqual(ord(data[23]), 0)
130
Neale Rannsfca0c242017-01-13 07:57:46 -0800131 found = 1
132 self.assertTrue(found)
133
134 return data
135
Neale Ranns20a175a2017-02-14 07:28:41 -0800136 def verify_dhcp_offer(self, pkt, intf):
Neale Rannsfca0c242017-01-13 07:57:46 -0800137 ether = pkt[Ether]
138 self.assertEqual(ether.dst, "ff:ff:ff:ff:ff:ff")
139 self.assertEqual(ether.src, intf.local_mac)
140
141 ip = pkt[IP]
142 self.assertEqual(ip.dst, "255.255.255.255")
143 self.assertEqual(ip.src, intf.local_ip4)
144
145 udp = pkt[UDP]
146 self.assertEqual(udp.dport, DHCP4_CLIENT_PORT)
147 self.assertEqual(udp.sport, DHCP4_SERVER_PORT)
148
149 dhcp = pkt[DHCP]
150 is_offer = False
151 for o in dhcp.options:
152 if type(o) is tuple:
153 if o[0] == "message-type" \
154 and DHCPTypes[o[1]] == "offer":
155 is_offer = True
156 self.assertTrue(is_offer)
157
Neale Ranns20a175a2017-02-14 07:28:41 -0800158 data = self.validate_relay_options(pkt, intf, intf.local_ip4, 0, 0)
Neale Rannsfca0c242017-01-13 07:57:46 -0800159
Neale Ranns20a175a2017-02-14 07:28:41 -0800160 def verify_dhcp_discover(self, pkt, intf, src_intf=None, fib_id=0, oui=0):
Neale Rannsfca0c242017-01-13 07:57:46 -0800161 ether = pkt[Ether]
162 self.assertEqual(ether.dst, intf.remote_mac)
163 self.assertEqual(ether.src, intf.local_mac)
164
165 ip = pkt[IP]
166 self.assertEqual(ip.dst, intf.remote_ip4)
167 self.assertEqual(ip.src, intf.local_ip4)
168
169 udp = pkt[UDP]
170 self.assertEqual(udp.dport, DHCP4_SERVER_PORT)
171 self.assertEqual(udp.sport, DHCP4_CLIENT_PORT)
172
173 dhcp = pkt[DHCP]
174
175 is_discover = False
176 for o in dhcp.options:
177 if type(o) is tuple:
178 if o[0] == "message-type" \
179 and DHCPTypes[o[1]] == "discover":
180 is_discover = True
181 self.assertTrue(is_discover)
182
Neale Ranns20a175a2017-02-14 07:28:41 -0800183 data = self.validate_relay_options(pkt, src_intf,
184 src_intf.local_ip4,
185 fib_id, oui)
186 return data
Neale Rannsfca0c242017-01-13 07:57:46 -0800187
188 def verify_dhcp6_solicit(self, pkt, intf,
189 peer_ip, peer_mac,
190 fib_id=0,
191 oui=0):
192 ether = pkt[Ether]
193 self.assertEqual(ether.dst, intf.remote_mac)
194 self.assertEqual(ether.src, intf.local_mac)
195
196 ip = pkt[IPv6]
197 self.assertEqual(in6_ptop(ip.dst), in6_ptop(intf.remote_ip6))
198 self.assertEqual(in6_ptop(ip.src), in6_ptop(intf.local_ip6))
199
200 udp = pkt[UDP]
201 self.assertEqual(udp.dport, DHCP6_CLIENT_PORT)
202 self.assertEqual(udp.sport, DHCP6_SERVER_PORT)
203
204 relay = pkt[DHCP6_RelayForward]
205 self.assertEqual(in6_ptop(relay.peeraddr), in6_ptop(peer_ip))
206 oid = pkt[DHCP6OptIfaceId]
207 cll = pkt[DHCP6OptClientLinkLayerAddr]
208 self.assertEqual(cll.optlen, 8)
209 self.assertEqual(cll.lltype, 1)
210 self.assertEqual(cll.clladdr, peer_mac)
211
Neale Ranns20a175a2017-02-14 07:28:41 -0800212 if fib_id != 0:
213 vss = pkt[DHCP6OptVSS]
214 self.assertEqual(vss.optlen, 8)
215 self.assertEqual(vss.type, 1)
216 # the OUI and FIB-id are really 3 and 4 bytes resp.
217 # but the tested range is small
218 self.assertEqual(ord(vss.data[0]), 0)
219 self.assertEqual(ord(vss.data[1]), 0)
220 self.assertEqual(ord(vss.data[2]), oui)
221 self.assertEqual(ord(vss.data[3]), 0)
222 self.assertEqual(ord(vss.data[4]), 0)
223 self.assertEqual(ord(vss.data[5]), 0)
224 self.assertEqual(ord(vss.data[6]), fib_id)
Neale Rannsfca0c242017-01-13 07:57:46 -0800225
226 # the relay message should be an encoded Solicit
227 msg = pkt[DHCP6OptRelayMsg]
228 sol = DHCP6_Solicit()
229 self.assertEqual(msg.optlen, len(str(sol)))
230 self.assertEqual(str(sol), (str(msg[1]))[:msg.optlen])
231
232 def verify_dhcp6_advert(self, pkt, intf, peer):
233 ether = pkt[Ether]
234 self.assertEqual(ether.dst, "ff:ff:ff:ff:ff:ff")
235 self.assertEqual(ether.src, intf.local_mac)
236
237 ip = pkt[IPv6]
238 self.assertEqual(in6_ptop(ip.dst), in6_ptop(peer))
239 self.assertEqual(in6_ptop(ip.src), in6_ptop(intf.local_ip6))
240
241 udp = pkt[UDP]
242 self.assertEqual(udp.dport, DHCP6_SERVER_PORT)
243 self.assertEqual(udp.sport, DHCP6_CLIENT_PORT)
244
245 # not sure why this is not decoding
246 # adv = pkt[DHCP6_Advertise]
247
248 def test_dhcp_proxy(self):
249 """ DHCPv4 Proxy """
250
251 #
252 # Verify no response to DHCP request without DHCP config
253 #
254 p_disc_vrf0 = (Ether(dst="ff:ff:ff:ff:ff:ff",
255 src=self.pg2.remote_mac) /
256 IP(src="0.0.0.0", dst="255.255.255.255") /
257 UDP(sport=DHCP4_CLIENT_PORT,
258 dport=DHCP4_SERVER_PORT) /
259 BOOTP(op=1) /
260 DHCP(options=[('message-type', 'discover'), ('end')]))
261 pkts_disc_vrf0 = [p_disc_vrf0]
262 p_disc_vrf1 = (Ether(dst="ff:ff:ff:ff:ff:ff",
263 src=self.pg3.remote_mac) /
264 IP(src="0.0.0.0", dst="255.255.255.255") /
265 UDP(sport=DHCP4_CLIENT_PORT,
266 dport=DHCP4_SERVER_PORT) /
267 BOOTP(op=1) /
268 DHCP(options=[('message-type', 'discover'), ('end')]))
269 pkts_disc_vrf1 = [p_disc_vrf0]
270
271 self.send_and_assert_no_replies(self.pg2, pkts_disc_vrf0,
272 "DHCP with no configuration")
273 self.send_and_assert_no_replies(self.pg3, pkts_disc_vrf1,
274 "DHCP with no configuration")
275
276 #
277 # Enable DHCP proxy in VRF 0
278 #
279 server_addr = self.pg0.remote_ip4n
280 src_addr = self.pg0.local_ip4n
281
282 self.vapi.dhcp_proxy_config(server_addr,
283 src_addr,
284 rx_table_id=0)
285
286 #
Neale Ranns20a175a2017-02-14 07:28:41 -0800287 # Discover packets from the client are dropped because there is no
288 # IP address configured on the client facing interface
Neale Rannsfca0c242017-01-13 07:57:46 -0800289 #
Neale Ranns20a175a2017-02-14 07:28:41 -0800290 self.send_and_assert_no_replies(self.pg2, pkts_disc_vrf0,
291 "Discover DHCP no relay address")
Neale Rannsfca0c242017-01-13 07:57:46 -0800292
293 #
294 # Inject a response from the server
Neale Ranns20a175a2017-02-14 07:28:41 -0800295 # dropped, because there is no IP addrees on the
Neale Ranns2dd68522017-02-16 03:38:59 -0800296 # client interfce to fill in the option.
Neale Rannsfca0c242017-01-13 07:57:46 -0800297 #
298 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
299 IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) /
300 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) /
301 BOOTP(op=1) /
302 DHCP(options=[('message-type', 'offer'), ('end')]))
303 pkts = [p]
304
Neale Ranns20a175a2017-02-14 07:28:41 -0800305 self.send_and_assert_no_replies(self.pg2, pkts,
306 "Offer DHCP no relay address")
Neale Rannsfca0c242017-01-13 07:57:46 -0800307
308 #
309 # configure an IP address on the client facing interface
310 #
311 self.pg2.config_ip4()
312
313 #
314 # Try again with a discover packet
315 # Rx'd packet should be to the server address and from the configured
316 # source address
317 # UDP source ports are unchanged
318 # we've no option 82 config so that should be absent
319 #
320 self.pg2.add_stream(pkts_disc_vrf0)
321 self.pg_enable_capture(self.pg_interfaces)
322 self.pg_start()
323
324 rx = self.pg0.get_capture(1)
325 rx = rx[0]
326
327 option_82 = self.verify_dhcp_discover(rx, self.pg0, src_intf=self.pg2)
328
329 #
330 # Create an DHCP offer reply from the server with a correctly formatted
331 # option 82. i.e. send back what we just captured
332 # The offer, sent mcast to the client, still has option 82.
333 #
334 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
335 IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) /
336 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) /
337 BOOTP(op=1) /
338 DHCP(options=[('message-type', 'offer'),
339 ('relay_agent_Information', option_82),
340 ('end')]))
341 pkts = [p]
342
343 self.pg0.add_stream(pkts)
344 self.pg_enable_capture(self.pg_interfaces)
345 self.pg_start()
346
347 rx = self.pg2.get_capture(1)
348 rx = rx[0]
349
350 self.verify_dhcp_offer(rx, self.pg2)
351
352 #
353 # Bogus Option 82:
354 #
355 # 1. not our IP address = not checked by VPP? so offer is replayed
356 # to client
357 bad_ip = option_82[0:8] + chr(33) + option_82[9:]
358
359 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
360 IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) /
361 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) /
362 BOOTP(op=1) /
363 DHCP(options=[('message-type', 'offer'),
364 ('relay_agent_Information', bad_ip),
365 ('end')]))
366 pkts = [p]
Neale Ranns20a175a2017-02-14 07:28:41 -0800367 self.send_and_assert_no_replies(self.pg0, pkts,
368 "DHCP offer option 82 bad address")
Neale Rannsfca0c242017-01-13 07:57:46 -0800369
370 # 2. Not a sw_if_index VPP knows
371 bad_if_index = option_82[0:2] + chr(33) + option_82[3:]
372
373 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
374 IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) /
375 UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) /
376 BOOTP(op=1) /
377 DHCP(options=[('message-type', 'offer'),
378 ('relay_agent_Information', bad_if_index),
379 ('end')]))
380 pkts = [p]
381 self.send_and_assert_no_replies(self.pg0, pkts,
382 "DHCP offer option 82 bad if index")
383
384 #
385 # Send a DHCP request in VRF 1. should be dropped.
386 #
387 self.send_and_assert_no_replies(self.pg3, pkts_disc_vrf1,
388 "DHCP with no configuration VRF 1")
389
390 #
391 # Delete the DHCP config in VRF 0
392 # Should now drop requests.
393 #
394 self.vapi.dhcp_proxy_config(server_addr,
395 src_addr,
396 rx_table_id=0,
Neale Ranns20a175a2017-02-14 07:28:41 -0800397 is_add=0)
Neale Rannsfca0c242017-01-13 07:57:46 -0800398
399 self.send_and_assert_no_replies(self.pg2, pkts_disc_vrf0,
400 "DHCP config removed VRF 0")
401 self.send_and_assert_no_replies(self.pg3, pkts_disc_vrf1,
402 "DHCP config removed VRF 1")
403
404 #
405 # Add DHCP config for VRF 1
406 #
407 server_addr = self.pg1.remote_ip4n
408 src_addr = self.pg1.local_ip4n
409 self.vapi.dhcp_proxy_config(server_addr,
410 src_addr,
411 rx_table_id=1,
Neale Ranns20a175a2017-02-14 07:28:41 -0800412 server_table_id=1)
Neale Rannsfca0c242017-01-13 07:57:46 -0800413
414 #
415 # Confim DHCP requests ok in VRF 1.
416 # - dropped on IP config on client interface
417 #
418 self.send_and_assert_no_replies(self.pg3, pkts_disc_vrf1,
419 "DHCP config removed VRF 1")
420
421 #
422 # configure an IP address on the client facing interface
423 #
424 self.pg3.config_ip4()
425
426 self.pg3.add_stream(pkts_disc_vrf1)
427 self.pg_enable_capture(self.pg_interfaces)
428 self.pg_start()
429
430 rx = self.pg1.get_capture(1)
431 rx = rx[0]
432 self.verify_dhcp_discover(rx, self.pg1, src_intf=self.pg3)
433
434 #
Neale Ranns20a175a2017-02-14 07:28:41 -0800435 # Add VSS config
436 # table=1, fib=id=1, oui=4
437 self.vapi.dhcp_proxy_set_vss(1, 1, 4)
438
439 self.pg3.add_stream(pkts_disc_vrf1)
440 self.pg_enable_capture(self.pg_interfaces)
441 self.pg_start()
442
443 rx = self.pg1.get_capture(1)
444 rx = rx[0]
445 self.verify_dhcp_discover(rx, self.pg1, src_intf=self.pg3,
446 fib_id=1, oui=4)
447
448 #
449 # Remove the VSS config
450 # relayed DHCP has default vlaues in the option.
451 #
452 self.vapi.dhcp_proxy_set_vss(1, 1, 4, is_add=0)
453
454 self.pg3.add_stream(pkts_disc_vrf1)
455 self.pg_enable_capture(self.pg_interfaces)
456 self.pg_start()
457
458 rx = self.pg1.get_capture(1)
459 rx = rx[0]
460 self.verify_dhcp_discover(rx, self.pg1, src_intf=self.pg3)
461
462 #
Neale Rannsfca0c242017-01-13 07:57:46 -0800463 # remove DHCP config to cleanup
464 #
465 self.vapi.dhcp_proxy_config(server_addr,
466 src_addr,
467 rx_table_id=1,
Neale Ranns20a175a2017-02-14 07:28:41 -0800468 server_table_id=11,
Neale Rannsfca0c242017-01-13 07:57:46 -0800469 is_add=0)
470
471 self.send_and_assert_no_replies(self.pg2, pkts_disc_vrf0,
472 "DHCP cleanup VRF 0")
473 self.send_and_assert_no_replies(self.pg3, pkts_disc_vrf1,
474 "DHCP cleanup VRF 1")
475
476 def test_dhcp6_proxy(self):
477 """ DHCPv6 Proxy"""
478 #
479 # Verify no response to DHCP request without DHCP config
480 #
481 dhcp_solicit_dst = "ff02::1:2"
482 dhcp_solicit_src_vrf0 = mk_ll_addr(self.pg2.remote_mac)
483 dhcp_solicit_src_vrf1 = mk_ll_addr(self.pg3.remote_mac)
484 server_addr_vrf0 = self.pg0.remote_ip6n
485 src_addr_vrf0 = self.pg0.local_ip6n
486 server_addr_vrf1 = self.pg1.remote_ip6n
487 src_addr_vrf1 = self.pg1.local_ip6n
488
Neale Rannsfca0c242017-01-13 07:57:46 -0800489 dmac = in6_getnsmac(inet_pton(socket.AF_INET6, dhcp_solicit_dst))
490 p_solicit_vrf0 = (Ether(dst=dmac, src=self.pg2.remote_mac) /
491 IPv6(src=dhcp_solicit_src_vrf0,
492 dst=dhcp_solicit_dst) /
493 UDP(sport=DHCP6_SERVER_PORT,
494 dport=DHCP6_CLIENT_PORT) /
495 DHCP6_Solicit())
496 pkts_solicit_vrf0 = [p_solicit_vrf0]
497 p_solicit_vrf1 = (Ether(dst=dmac, src=self.pg3.remote_mac) /
498 IPv6(src=dhcp_solicit_src_vrf1,
499 dst=dhcp_solicit_dst) /
500 UDP(sport=DHCP6_SERVER_PORT,
501 dport=DHCP6_CLIENT_PORT) /
502 DHCP6_Solicit())
503 pkts_solicit_vrf1 = [p_solicit_vrf1]
504
505 self.send_and_assert_no_replies(self.pg2, pkts_solicit_vrf0,
506 "DHCP with no configuration")
507 self.send_and_assert_no_replies(self.pg3, pkts_solicit_vrf1,
508 "DHCP with no configuration")
509
510 #
511 # DHCPv6 config in VRF 0.
512 # Packets still dropped because the client facing interface has no
513 # IPv6 config
514 #
515 self.vapi.dhcp_proxy_config(server_addr_vrf0,
516 src_addr_vrf0,
517 rx_table_id=0,
518 server_table_id=0,
Neale Rannsfca0c242017-01-13 07:57:46 -0800519 is_ipv6=1)
520
521 self.send_and_assert_no_replies(self.pg2, pkts_solicit_vrf0,
522 "DHCP with no configuration")
523 self.send_and_assert_no_replies(self.pg3, pkts_solicit_vrf1,
524 "DHCP with no configuration")
525
526 #
527 # configure an IP address on the client facing interface
528 #
529 self.pg2.config_ip6()
530
531 #
532 # Now the DHCP requests are relayed to the server
533 #
534 self.pg2.add_stream(pkts_solicit_vrf0)
535 self.pg_enable_capture(self.pg_interfaces)
536 self.pg_start()
537
538 rx = self.pg0.get_capture(1)
539 rx = rx[0]
540 self.verify_dhcp6_solicit(rx, self.pg0,
541 dhcp_solicit_src_vrf0,
542 self.pg2.remote_mac)
543
544 #
545 # Exception cases for rejected relay responses
546 #
547
548 # 1 - not a relay reply
549 p_adv_vrf0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
550 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
551 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
552 DHCP6_Advertise())
553 pkts_adv_vrf0 = [p_adv_vrf0]
554 self.send_and_assert_no_replies(self.pg2, pkts_adv_vrf0,
555 "DHCP6 not a relay reply")
556
557 # 2 - no relay message option
558 p_adv_vrf0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
559 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
560 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
561 DHCP6_RelayReply() /
562 DHCP6_Advertise())
563 pkts_adv_vrf0 = [p_adv_vrf0]
564 self.send_and_assert_no_replies(self.pg2, pkts_adv_vrf0,
565 "DHCP not a relay message")
566
567 # 3 - no circuit ID
568 p_adv_vrf0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
569 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
570 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
571 DHCP6_RelayReply() /
572 DHCP6OptRelayMsg(optlen=0) /
573 DHCP6_Advertise())
574 pkts_adv_vrf0 = [p_adv_vrf0]
575 self.send_and_assert_no_replies(self.pg2, pkts_adv_vrf0,
576 "DHCP6 no circuit ID")
577 # 4 - wrong circuit ID
578 p_adv_vrf0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
579 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
580 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
581 DHCP6_RelayReply() /
582 DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x05') /
583 DHCP6OptRelayMsg(optlen=0) /
584 DHCP6_Advertise())
585 pkts_adv_vrf0 = [p_adv_vrf0]
586 self.send_and_assert_no_replies(self.pg2, pkts_adv_vrf0,
587 "DHCP6 wrong circuit ID")
588
589 #
590 # Send the relay response (the advertisement)
591 # - no peer address
592 p_adv_vrf0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
593 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
594 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
595 DHCP6_RelayReply() /
596 DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x03') /
597 DHCP6OptRelayMsg(optlen=0) /
598 DHCP6_Advertise(trid=1) /
599 DHCP6OptStatusCode(statuscode=0))
600 pkts_adv_vrf0 = [p_adv_vrf0]
601
602 self.pg0.add_stream(pkts_adv_vrf0)
603 self.pg_enable_capture(self.pg_interfaces)
604 self.pg_start()
605
606 rx = self.pg2.get_capture(1)
607 rx = rx[0]
608 self.verify_dhcp6_advert(rx, self.pg2, "::")
609
610 #
611 # Send the relay response (the advertisement)
612 # - with peer address
613 p_adv_vrf0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
614 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
615 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
616 DHCP6_RelayReply(peeraddr=dhcp_solicit_src_vrf0) /
617 DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x03') /
618 DHCP6OptRelayMsg(optlen=0) /
619 DHCP6_Advertise(trid=1) /
620 DHCP6OptStatusCode(statuscode=0))
621 pkts_adv_vrf0 = [p_adv_vrf0]
622
623 self.pg0.add_stream(pkts_adv_vrf0)
624 self.pg_enable_capture(self.pg_interfaces)
625 self.pg_start()
626
627 rx = self.pg2.get_capture(1)
628 rx = rx[0]
629 self.verify_dhcp6_advert(rx, self.pg2, dhcp_solicit_src_vrf0)
630
631 #
632 # Add all the config for VRF 1
633 #
634 self.vapi.dhcp_proxy_config(server_addr_vrf1,
635 src_addr_vrf1,
636 rx_table_id=1,
637 server_table_id=1,
Neale Rannsfca0c242017-01-13 07:57:46 -0800638 is_ipv6=1)
639 self.pg3.config_ip6()
640
641 #
642 # VRF 1 solicit
643 #
644 self.pg3.add_stream(pkts_solicit_vrf1)
645 self.pg_enable_capture(self.pg_interfaces)
646 self.pg_start()
647
648 rx = self.pg1.get_capture(1)
649 rx = rx[0]
650 self.verify_dhcp6_solicit(rx, self.pg1,
651 dhcp_solicit_src_vrf1,
652 self.pg3.remote_mac)
653
654 #
655 # VRF 1 Advert
656 #
657 p_adv_vrf1 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
658 IPv6(dst=self.pg1.local_ip6, src=self.pg1.remote_ip6) /
659 UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) /
660 DHCP6_RelayReply(peeraddr=dhcp_solicit_src_vrf1) /
661 DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x04') /
662 DHCP6OptRelayMsg(optlen=0) /
663 DHCP6_Advertise(trid=1) /
664 DHCP6OptStatusCode(statuscode=0))
665 pkts_adv_vrf1 = [p_adv_vrf1]
666
667 self.pg1.add_stream(pkts_adv_vrf1)
668 self.pg_enable_capture(self.pg_interfaces)
669 self.pg_start()
670
671 rx = self.pg3.get_capture(1)
672 rx = rx[0]
673 self.verify_dhcp6_advert(rx, self.pg3, dhcp_solicit_src_vrf1)
674
675 #
676 # Add VSS config
677 # table=1, fib=id=1, oui=4
678 self.vapi.dhcp_proxy_set_vss(1, 1, 4, is_ip6=1)
679
680 self.pg3.add_stream(pkts_solicit_vrf1)
681 self.pg_enable_capture(self.pg_interfaces)
682 self.pg_start()
683
684 rx = self.pg1.get_capture(1)
685 rx = rx[0]
686 self.verify_dhcp6_solicit(rx, self.pg1,
687 dhcp_solicit_src_vrf1,
688 self.pg3.remote_mac,
689 fib_id=1,
690 oui=4)
691
692 #
693 # Remove the VSS config
694 # relayed DHCP has default vlaues in the option.
695 #
696 self.vapi.dhcp_proxy_set_vss(1, 1, 4, is_ip6=1, is_add=0)
697
698 self.pg3.add_stream(pkts_solicit_vrf1)
699 self.pg_enable_capture(self.pg_interfaces)
700 self.pg_start()
701
702 rx = self.pg1.get_capture(1)
703 rx = rx[0]
704 self.verify_dhcp6_solicit(rx, self.pg1,
705 dhcp_solicit_src_vrf1,
706 self.pg3.remote_mac)
707
708 #
709 # Cleanup
710 #
711 self.vapi.dhcp_proxy_config(server_addr_vrf1,
712 src_addr_vrf1,
713 rx_table_id=1,
714 server_table_id=1,
Neale Rannsfca0c242017-01-13 07:57:46 -0800715 is_ipv6=1,
716 is_add=0)
717 self.vapi.dhcp_proxy_config(server_addr_vrf1,
718 src_addr_vrf1,
719 rx_table_id=0,
720 server_table_id=0,
Neale Rannsfca0c242017-01-13 07:57:46 -0800721 is_ipv6=1,
722 is_add=0)
723
Neale Rannsfca0c242017-01-13 07:57:46 -0800724if __name__ == '__main__':
725 unittest.main(testRunner=VppTestRunner)