Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2 | |
| 3 | import unittest |
| 4 | import socket |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 5 | import struct |
Ole Troan | 12966a7 | 2019-10-18 14:33:54 +0200 | [diff] [blame] | 6 | import six |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 7 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 8 | from framework import VppTestCase, VppTestRunner, running_extended_tests |
Andrew Yourtchenko | 06f3281 | 2021-01-14 10:19:08 +0000 | [diff] [blame] | 9 | from framework import tag_run_solo |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 10 | from vpp_neighbor import VppNeighbor |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 11 | from vpp_ip_route import find_route, VppIpTable |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 12 | from util import mk_ll_addr |
Paul Vinciguerra | a7427ec | 2019-03-10 10:04:23 -0700 | [diff] [blame] | 13 | import scapy.compat |
Neale Ranns | 038e1df | 2019-07-19 14:01:02 +0000 | [diff] [blame] | 14 | from scapy.layers.l2 import Ether, getmacbyip, ARP, Dot1Q |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 15 | from scapy.layers.inet import IP, UDP, ICMP |
Neale Ranns | 2bc9402 | 2018-02-25 12:27:18 -0800 | [diff] [blame] | 16 | from scapy.layers.inet6 import IPv6, in6_getnsmac |
| 17 | from scapy.utils6 import in6_mactoifaceid |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 18 | from scapy.layers.dhcp import DHCP, BOOTP, DHCPTypes |
| 19 | from scapy.layers.dhcp6 import DHCP6, DHCP6_Solicit, DHCP6_RelayForward, \ |
| 20 | DHCP6_RelayReply, DHCP6_Advertise, DHCP6OptRelayMsg, DHCP6OptIfaceId, \ |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 21 | DHCP6OptStatusCode, DHCP6OptVSS, DHCP6OptClientLinkLayerAddr, DHCP6_Request |
snaramre | 5d4b891 | 2019-12-13 23:39:35 +0000 | [diff] [blame] | 22 | from socket import AF_INET, AF_INET6, inet_pton, inet_ntop |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 23 | from scapy.utils6 import in6_ptop |
Neale Ranns | 038e1df | 2019-07-19 14:01:02 +0000 | [diff] [blame] | 24 | from vpp_papi import mac_pton, VppEnum |
| 25 | from vpp_sub_interface import VppDot1QSubint |
| 26 | from vpp_qos import VppQosEgressMap, VppQosMark |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 27 | from vpp_dhcp import VppDHCPClient, VppDHCPProxy |
Neale Ranns | 038e1df | 2019-07-19 14:01:02 +0000 | [diff] [blame] | 28 | |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 29 | |
| 30 | DHCP4_CLIENT_PORT = 68 |
| 31 | DHCP4_SERVER_PORT = 67 |
| 32 | DHCP6_CLIENT_PORT = 547 |
| 33 | DHCP6_SERVER_PORT = 546 |
| 34 | |
| 35 | |
Andrew Yourtchenko | 06f3281 | 2021-01-14 10:19:08 +0000 | [diff] [blame] | 36 | @tag_run_solo |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 37 | class TestDHCP(VppTestCase): |
| 38 | """ DHCP Test Case """ |
| 39 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 40 | @classmethod |
| 41 | def setUpClass(cls): |
| 42 | super(TestDHCP, cls).setUpClass() |
| 43 | |
| 44 | @classmethod |
| 45 | def tearDownClass(cls): |
| 46 | super(TestDHCP, cls).tearDownClass() |
| 47 | |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 48 | def setUp(self): |
| 49 | super(TestDHCP, self).setUp() |
| 50 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 51 | # create 6 pg interfaces for pg0 to pg5 |
| 52 | self.create_pg_interfaces(range(6)) |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 53 | self.tables = [] |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 54 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 55 | # pg0 to 2 are IP configured in VRF 0, 1 and 2. |
| 56 | # pg3 to 5 are non IP-configured in VRF 0, 1 and 2. |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 57 | table_id = 0 |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 58 | for table_id in range(1, 4): |
| 59 | tbl4 = VppIpTable(self, table_id) |
| 60 | tbl4.add_vpp_config() |
| 61 | self.tables.append(tbl4) |
| 62 | tbl6 = VppIpTable(self, table_id, is_ip6=1) |
| 63 | tbl6.add_vpp_config() |
| 64 | self.tables.append(tbl6) |
| 65 | |
| 66 | table_id = 0 |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 67 | for i in self.pg_interfaces[:3]: |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 68 | i.admin_up() |
| 69 | i.set_table_ip4(table_id) |
| 70 | i.set_table_ip6(table_id) |
| 71 | i.config_ip4() |
| 72 | i.resolve_arp() |
| 73 | i.config_ip6() |
| 74 | i.resolve_ndp() |
| 75 | table_id += 1 |
| 76 | |
| 77 | table_id = 0 |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 78 | for i in self.pg_interfaces[3:]: |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 79 | i.admin_up() |
| 80 | i.set_table_ip4(table_id) |
| 81 | i.set_table_ip6(table_id) |
| 82 | table_id += 1 |
| 83 | |
Neale Ranns | 4008ac9 | 2017-02-13 23:20:04 -0800 | [diff] [blame] | 84 | def tearDown(self): |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 85 | for i in self.pg_interfaces[:3]: |
Neale Ranns | 4008ac9 | 2017-02-13 23:20:04 -0800 | [diff] [blame] | 86 | i.unconfig_ip4() |
| 87 | i.unconfig_ip6() |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 88 | |
| 89 | for i in self.pg_interfaces: |
| 90 | i.set_table_ip4(0) |
| 91 | i.set_table_ip6(0) |
Neale Ranns | 4008ac9 | 2017-02-13 23:20:04 -0800 | [diff] [blame] | 92 | i.admin_down() |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 93 | super(TestDHCP, self).tearDown() |
Neale Ranns | 4008ac9 | 2017-02-13 23:20:04 -0800 | [diff] [blame] | 94 | |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 95 | def verify_dhcp_has_option(self, pkt, option, value): |
| 96 | dhcp = pkt[DHCP] |
| 97 | found = False |
| 98 | |
| 99 | for i in dhcp.options: |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 100 | if isinstance(i, tuple): |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 101 | if i[0] == option: |
| 102 | self.assertEqual(i[1], value) |
| 103 | found = True |
| 104 | |
| 105 | self.assertTrue(found) |
| 106 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 107 | def validate_relay_options(self, pkt, intf, ip_addr, vpn_id, fib_id, oui): |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 108 | dhcp = pkt[DHCP] |
| 109 | found = 0 |
| 110 | data = [] |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 111 | id_len = len(vpn_id) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 112 | |
| 113 | for i in dhcp.options: |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 114 | if isinstance(i, tuple): |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 115 | if i[0] == "relay_agent_Information": |
| 116 | # |
| 117 | # There are two sb-options present - each of length 6. |
| 118 | # |
| 119 | data = i[1] |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 120 | if oui != 0: |
| 121 | self.assertEqual(len(data), 24) |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 122 | elif len(vpn_id) > 0: |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 123 | self.assertEqual(len(data), len(vpn_id) + 17) |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 124 | else: |
| 125 | self.assertEqual(len(data), 12) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 126 | |
| 127 | # |
| 128 | # First sub-option is ID 1, len 4, then encoded |
| 129 | # sw_if_index. This test uses low valued indicies |
| 130 | # so [2:4] are 0. |
| 131 | # The ID space is VPP internal - so no matching value |
| 132 | # scapy |
| 133 | # |
Ole Troan | 12966a7 | 2019-10-18 14:33:54 +0200 | [diff] [blame] | 134 | self.assertEqual(six.byte2int(data[0:1]), 1) |
| 135 | self.assertEqual(six.byte2int(data[1:2]), 4) |
| 136 | self.assertEqual(six.byte2int(data[2:3]), 0) |
| 137 | self.assertEqual(six.byte2int(data[3:4]), 0) |
| 138 | self.assertEqual(six.byte2int(data[4:5]), 0) |
| 139 | self.assertEqual(six.byte2int(data[5:6]), |
| 140 | intf._sw_if_index) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 141 | |
| 142 | # |
| 143 | # next sub-option is the IP address of the client side |
| 144 | # interface. |
| 145 | # sub-option ID=5, length (of a v4 address)=4 |
| 146 | # |
| 147 | claddr = socket.inet_pton(AF_INET, ip_addr) |
| 148 | |
Ole Troan | 12966a7 | 2019-10-18 14:33:54 +0200 | [diff] [blame] | 149 | self.assertEqual(six.byte2int(data[6:7]), 5) |
| 150 | self.assertEqual(six.byte2int(data[7:8]), 4) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 151 | self.assertEqual(data[8], claddr[0]) |
| 152 | self.assertEqual(data[9], claddr[1]) |
| 153 | self.assertEqual(data[10], claddr[2]) |
| 154 | self.assertEqual(data[11], claddr[3]) |
| 155 | |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 156 | if oui != 0: |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 157 | # sub-option 151 encodes vss_type 1, |
| 158 | # the 3 byte oui and the 4 byte fib_id |
| 159 | self.assertEqual(id_len, 0) |
Ole Troan | 12966a7 | 2019-10-18 14:33:54 +0200 | [diff] [blame] | 160 | self.assertEqual(six.byte2int(data[12:13]), 151) |
| 161 | self.assertEqual(six.byte2int(data[13:14]), 8) |
| 162 | self.assertEqual(six.byte2int(data[14:15]), 1) |
| 163 | self.assertEqual(six.byte2int(data[15:16]), 0) |
| 164 | self.assertEqual(six.byte2int(data[16:17]), 0) |
| 165 | self.assertEqual(six.byte2int(data[17:18]), oui) |
| 166 | self.assertEqual(six.byte2int(data[18:19]), 0) |
| 167 | self.assertEqual(six.byte2int(data[19:20]), 0) |
| 168 | self.assertEqual(six.byte2int(data[20:21]), 0) |
| 169 | self.assertEqual(six.byte2int(data[21:22]), fib_id) |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 170 | |
| 171 | # VSS control sub-option |
Ole Troan | 12966a7 | 2019-10-18 14:33:54 +0200 | [diff] [blame] | 172 | self.assertEqual(six.byte2int(data[22:23]), 152) |
| 173 | self.assertEqual(six.byte2int(data[23:24]), 0) |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 174 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 175 | if id_len > 0: |
| 176 | # sub-option 151 encode vss_type of 0 |
| 177 | # followerd by vpn_id in ascii |
| 178 | self.assertEqual(oui, 0) |
Ole Troan | 12966a7 | 2019-10-18 14:33:54 +0200 | [diff] [blame] | 179 | self.assertEqual(six.byte2int(data[12:13]), 151) |
| 180 | self.assertEqual(six.byte2int(data[13:14]), id_len + 1) |
| 181 | self.assertEqual(six.byte2int(data[14:15]), 0) |
| 182 | self.assertEqual(data[15:15 + id_len].decode('ascii'), |
| 183 | vpn_id) |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 184 | |
| 185 | # VSS control sub-option |
Ole Troan | 12966a7 | 2019-10-18 14:33:54 +0200 | [diff] [blame] | 186 | self.assertEqual(six.byte2int(data[15 + len(vpn_id): |
| 187 | 16 + len(vpn_id)]), |
| 188 | 152) |
| 189 | self.assertEqual(six.byte2int(data[16 + len(vpn_id): |
| 190 | 17 + len(vpn_id)]), |
| 191 | 0) |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 192 | |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 193 | found = 1 |
| 194 | self.assertTrue(found) |
| 195 | |
| 196 | return data |
| 197 | |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 198 | def verify_dhcp_msg_type(self, pkt, name): |
| 199 | dhcp = pkt[DHCP] |
| 200 | found = False |
| 201 | for o in dhcp.options: |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 202 | if isinstance(o, tuple): |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 203 | if o[0] == "message-type" \ |
| 204 | and DHCPTypes[o[1]] == name: |
| 205 | found = True |
| 206 | self.assertTrue(found) |
| 207 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 208 | def verify_dhcp_offer(self, pkt, intf, vpn_id="", fib_id=0, oui=0): |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 209 | ether = pkt[Ether] |
| 210 | self.assertEqual(ether.dst, "ff:ff:ff:ff:ff:ff") |
| 211 | self.assertEqual(ether.src, intf.local_mac) |
| 212 | |
| 213 | ip = pkt[IP] |
| 214 | self.assertEqual(ip.dst, "255.255.255.255") |
| 215 | self.assertEqual(ip.src, intf.local_ip4) |
| 216 | |
| 217 | udp = pkt[UDP] |
| 218 | self.assertEqual(udp.dport, DHCP4_CLIENT_PORT) |
| 219 | self.assertEqual(udp.sport, DHCP4_SERVER_PORT) |
| 220 | |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 221 | self.verify_dhcp_msg_type(pkt, "offer") |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 222 | data = self.validate_relay_options(pkt, intf, intf.local_ip4, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 223 | vpn_id, fib_id, oui) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 224 | |
Neale Ranns | 038e1df | 2019-07-19 14:01:02 +0000 | [diff] [blame] | 225 | def verify_orig_dhcp_pkt(self, pkt, intf, dscp, l2_bc=True): |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 226 | ether = pkt[Ether] |
Neale Ranns | 99536f4 | 2019-07-25 06:11:58 -0700 | [diff] [blame] | 227 | if l2_bc: |
| 228 | self.assertEqual(ether.dst, "ff:ff:ff:ff:ff:ff") |
| 229 | else: |
| 230 | self.assertEqual(ether.dst, intf.remote_mac) |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 231 | self.assertEqual(ether.src, intf.local_mac) |
| 232 | |
| 233 | ip = pkt[IP] |
Neale Ranns | 99536f4 | 2019-07-25 06:11:58 -0700 | [diff] [blame] | 234 | |
| 235 | if (l2_bc): |
| 236 | self.assertEqual(ip.dst, "255.255.255.255") |
| 237 | self.assertEqual(ip.src, "0.0.0.0") |
| 238 | else: |
| 239 | self.assertEqual(ip.dst, intf.remote_ip4) |
| 240 | self.assertEqual(ip.src, intf.local_ip4) |
Neale Ranns | 038e1df | 2019-07-19 14:01:02 +0000 | [diff] [blame] | 241 | self.assertEqual(ip.tos, dscp) |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 242 | |
| 243 | udp = pkt[UDP] |
| 244 | self.assertEqual(udp.dport, DHCP4_SERVER_PORT) |
| 245 | self.assertEqual(udp.sport, DHCP4_CLIENT_PORT) |
| 246 | |
Neale Ranns | 54c6dc4 | 2018-01-17 10:29:10 -0800 | [diff] [blame] | 247 | def verify_orig_dhcp_discover(self, pkt, intf, hostname, client_id=None, |
Neale Ranns | 038e1df | 2019-07-19 14:01:02 +0000 | [diff] [blame] | 248 | broadcast=True, dscp=0): |
| 249 | self.verify_orig_dhcp_pkt(pkt, intf, dscp) |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 250 | |
| 251 | self.verify_dhcp_msg_type(pkt, "discover") |
Ole Troan | 12966a7 | 2019-10-18 14:33:54 +0200 | [diff] [blame] | 252 | self.verify_dhcp_has_option(pkt, "hostname", |
| 253 | hostname.encode('ascii')) |
Neale Ranns | 51822bf | 2017-07-18 09:26:53 -0700 | [diff] [blame] | 254 | if client_id: |
Dave Barach | 211b9f6 | 2019-11-13 17:12:47 -0500 | [diff] [blame] | 255 | client_id = '\x00' + client_id |
Ole Troan | 12966a7 | 2019-10-18 14:33:54 +0200 | [diff] [blame] | 256 | self.verify_dhcp_has_option(pkt, "client_id", |
| 257 | client_id.encode('ascii')) |
Neale Ranns | 808c5b2 | 2017-08-02 05:15:07 -0700 | [diff] [blame] | 258 | bootp = pkt[BOOTP] |
| 259 | self.assertEqual(bootp.ciaddr, "0.0.0.0") |
| 260 | self.assertEqual(bootp.giaddr, "0.0.0.0") |
Neale Ranns | 54c6dc4 | 2018-01-17 10:29:10 -0800 | [diff] [blame] | 261 | if broadcast: |
| 262 | self.assertEqual(bootp.flags, 0x8000) |
| 263 | else: |
| 264 | self.assertEqual(bootp.flags, 0x0000) |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 265 | |
Neale Ranns | 54c6dc4 | 2018-01-17 10:29:10 -0800 | [diff] [blame] | 266 | def verify_orig_dhcp_request(self, pkt, intf, hostname, ip, |
Neale Ranns | 99536f4 | 2019-07-25 06:11:58 -0700 | [diff] [blame] | 267 | broadcast=True, |
Neale Ranns | 038e1df | 2019-07-19 14:01:02 +0000 | [diff] [blame] | 268 | l2_bc=True, |
| 269 | dscp=0): |
| 270 | self.verify_orig_dhcp_pkt(pkt, intf, dscp, l2_bc=l2_bc) |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 271 | |
| 272 | self.verify_dhcp_msg_type(pkt, "request") |
Ole Troan | 12966a7 | 2019-10-18 14:33:54 +0200 | [diff] [blame] | 273 | self.verify_dhcp_has_option(pkt, "hostname", |
| 274 | hostname.encode('ascii')) |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 275 | self.verify_dhcp_has_option(pkt, "requested_addr", ip) |
Neale Ranns | 808c5b2 | 2017-08-02 05:15:07 -0700 | [diff] [blame] | 276 | bootp = pkt[BOOTP] |
Neale Ranns | 99536f4 | 2019-07-25 06:11:58 -0700 | [diff] [blame] | 277 | |
| 278 | if l2_bc: |
| 279 | self.assertEqual(bootp.ciaddr, "0.0.0.0") |
| 280 | else: |
| 281 | self.assertEqual(bootp.ciaddr, intf.local_ip4) |
Neale Ranns | 808c5b2 | 2017-08-02 05:15:07 -0700 | [diff] [blame] | 282 | self.assertEqual(bootp.giaddr, "0.0.0.0") |
Neale Ranns | 99536f4 | 2019-07-25 06:11:58 -0700 | [diff] [blame] | 283 | |
Neale Ranns | 54c6dc4 | 2018-01-17 10:29:10 -0800 | [diff] [blame] | 284 | if broadcast: |
| 285 | self.assertEqual(bootp.flags, 0x8000) |
| 286 | else: |
| 287 | self.assertEqual(bootp.flags, 0x0000) |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 288 | |
| 289 | def verify_relayed_dhcp_discover(self, pkt, intf, src_intf=None, |
| 290 | fib_id=0, oui=0, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 291 | vpn_id="", |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 292 | dst_mac=None, dst_ip=None): |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 293 | if not dst_mac: |
| 294 | dst_mac = intf.remote_mac |
| 295 | if not dst_ip: |
| 296 | dst_ip = intf.remote_ip4 |
| 297 | |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 298 | ether = pkt[Ether] |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 299 | self.assertEqual(ether.dst, dst_mac) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 300 | self.assertEqual(ether.src, intf.local_mac) |
| 301 | |
| 302 | ip = pkt[IP] |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 303 | self.assertEqual(ip.dst, dst_ip) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 304 | self.assertEqual(ip.src, intf.local_ip4) |
| 305 | |
| 306 | udp = pkt[UDP] |
| 307 | self.assertEqual(udp.dport, DHCP4_SERVER_PORT) |
| 308 | self.assertEqual(udp.sport, DHCP4_CLIENT_PORT) |
| 309 | |
| 310 | dhcp = pkt[DHCP] |
| 311 | |
| 312 | is_discover = False |
| 313 | for o in dhcp.options: |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 314 | if isinstance(o, tuple): |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 315 | if o[0] == "message-type" \ |
| 316 | and DHCPTypes[o[1]] == "discover": |
| 317 | is_discover = True |
| 318 | self.assertTrue(is_discover) |
| 319 | |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 320 | data = self.validate_relay_options(pkt, src_intf, |
| 321 | src_intf.local_ip4, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 322 | vpn_id, |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 323 | fib_id, oui) |
| 324 | return data |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 325 | |
| 326 | def verify_dhcp6_solicit(self, pkt, intf, |
| 327 | peer_ip, peer_mac, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 328 | vpn_id="", |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 329 | fib_id=0, |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 330 | oui=0, |
| 331 | dst_mac=None, |
| 332 | dst_ip=None): |
| 333 | if not dst_mac: |
| 334 | dst_mac = intf.remote_mac |
| 335 | if not dst_ip: |
| 336 | dst_ip = in6_ptop(intf.remote_ip6) |
| 337 | |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 338 | ether = pkt[Ether] |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 339 | self.assertEqual(ether.dst, dst_mac) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 340 | self.assertEqual(ether.src, intf.local_mac) |
| 341 | |
| 342 | ip = pkt[IPv6] |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 343 | self.assertEqual(in6_ptop(ip.dst), dst_ip) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 344 | self.assertEqual(in6_ptop(ip.src), in6_ptop(intf.local_ip6)) |
| 345 | |
| 346 | udp = pkt[UDP] |
| 347 | self.assertEqual(udp.dport, DHCP6_CLIENT_PORT) |
| 348 | self.assertEqual(udp.sport, DHCP6_SERVER_PORT) |
| 349 | |
| 350 | relay = pkt[DHCP6_RelayForward] |
| 351 | self.assertEqual(in6_ptop(relay.peeraddr), in6_ptop(peer_ip)) |
| 352 | oid = pkt[DHCP6OptIfaceId] |
| 353 | cll = pkt[DHCP6OptClientLinkLayerAddr] |
| 354 | self.assertEqual(cll.optlen, 8) |
| 355 | self.assertEqual(cll.lltype, 1) |
| 356 | self.assertEqual(cll.clladdr, peer_mac) |
| 357 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 358 | id_len = len(vpn_id) |
| 359 | |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 360 | if fib_id != 0: |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 361 | self.assertEqual(id_len, 0) |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 362 | vss = pkt[DHCP6OptVSS] |
| 363 | self.assertEqual(vss.optlen, 8) |
| 364 | self.assertEqual(vss.type, 1) |
| 365 | # the OUI and FIB-id are really 3 and 4 bytes resp. |
| 366 | # but the tested range is small |
Ole Troan | 12966a7 | 2019-10-18 14:33:54 +0200 | [diff] [blame] | 367 | self.assertEqual(six.byte2int(vss.data[0:1]), 0) |
| 368 | self.assertEqual(six.byte2int(vss.data[1:2]), 0) |
| 369 | self.assertEqual(six.byte2int(vss.data[2:3]), oui) |
| 370 | self.assertEqual(six.byte2int(vss.data[3:4]), 0) |
| 371 | self.assertEqual(six.byte2int(vss.data[4:5]), 0) |
| 372 | self.assertEqual(six.byte2int(vss.data[5:6]), 0) |
| 373 | self.assertEqual(six.byte2int(vss.data[6:7]), fib_id) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 374 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 375 | if id_len > 0: |
| 376 | self.assertEqual(oui, 0) |
| 377 | vss = pkt[DHCP6OptVSS] |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 378 | self.assertEqual(vss.optlen, id_len + 1) |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 379 | self.assertEqual(vss.type, 0) |
Ole Troan | 12966a7 | 2019-10-18 14:33:54 +0200 | [diff] [blame] | 380 | self.assertEqual(vss.data[0:id_len].decode('ascii'), |
| 381 | vpn_id) |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 382 | |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 383 | # the relay message should be an encoded Solicit |
| 384 | msg = pkt[DHCP6OptRelayMsg] |
| 385 | sol = DHCP6_Solicit() |
Ole Troan | 12966a7 | 2019-10-18 14:33:54 +0200 | [diff] [blame] | 386 | self.assertEqual(msg.optlen, len(sol)) |
| 387 | self.assertEqual(sol, msg[1]) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 388 | |
| 389 | def verify_dhcp6_advert(self, pkt, intf, peer): |
| 390 | ether = pkt[Ether] |
| 391 | self.assertEqual(ether.dst, "ff:ff:ff:ff:ff:ff") |
| 392 | self.assertEqual(ether.src, intf.local_mac) |
| 393 | |
| 394 | ip = pkt[IPv6] |
| 395 | self.assertEqual(in6_ptop(ip.dst), in6_ptop(peer)) |
| 396 | self.assertEqual(in6_ptop(ip.src), in6_ptop(intf.local_ip6)) |
| 397 | |
| 398 | udp = pkt[UDP] |
| 399 | self.assertEqual(udp.dport, DHCP6_SERVER_PORT) |
| 400 | self.assertEqual(udp.sport, DHCP6_CLIENT_PORT) |
| 401 | |
| 402 | # not sure why this is not decoding |
| 403 | # adv = pkt[DHCP6_Advertise] |
| 404 | |
Neale Ranns | f6e9b01 | 2019-01-25 06:37:15 -0800 | [diff] [blame] | 405 | def wait_for_no_route(self, address, length, |
| 406 | n_tries=50, s_time=1): |
| 407 | while (n_tries): |
| 408 | if not find_route(self, address, length): |
| 409 | return True |
| 410 | n_tries = n_tries - 1 |
| 411 | self.sleep(s_time) |
| 412 | |
| 413 | return False |
| 414 | |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 415 | def test_dhcp_proxy(self): |
| 416 | """ DHCPv4 Proxy """ |
| 417 | |
| 418 | # |
| 419 | # Verify no response to DHCP request without DHCP config |
| 420 | # |
| 421 | p_disc_vrf0 = (Ether(dst="ff:ff:ff:ff:ff:ff", |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 422 | src=self.pg3.remote_mac) / |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 423 | IP(src="0.0.0.0", dst="255.255.255.255") / |
| 424 | UDP(sport=DHCP4_CLIENT_PORT, |
| 425 | dport=DHCP4_SERVER_PORT) / |
| 426 | BOOTP(op=1) / |
| 427 | DHCP(options=[('message-type', 'discover'), ('end')])) |
| 428 | pkts_disc_vrf0 = [p_disc_vrf0] |
| 429 | p_disc_vrf1 = (Ether(dst="ff:ff:ff:ff:ff:ff", |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 430 | src=self.pg4.remote_mac) / |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 431 | IP(src="0.0.0.0", dst="255.255.255.255") / |
| 432 | UDP(sport=DHCP4_CLIENT_PORT, |
| 433 | dport=DHCP4_SERVER_PORT) / |
| 434 | BOOTP(op=1) / |
| 435 | DHCP(options=[('message-type', 'discover'), ('end')])) |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 436 | pkts_disc_vrf1 = [p_disc_vrf1] |
| 437 | p_disc_vrf2 = (Ether(dst="ff:ff:ff:ff:ff:ff", |
| 438 | src=self.pg5.remote_mac) / |
| 439 | IP(src="0.0.0.0", dst="255.255.255.255") / |
| 440 | UDP(sport=DHCP4_CLIENT_PORT, |
| 441 | dport=DHCP4_SERVER_PORT) / |
| 442 | BOOTP(op=1) / |
| 443 | DHCP(options=[('message-type', 'discover'), ('end')])) |
| 444 | pkts_disc_vrf2 = [p_disc_vrf2] |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 445 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 446 | self.send_and_assert_no_replies(self.pg3, pkts_disc_vrf0, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 447 | "DHCP with no configuration") |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 448 | self.send_and_assert_no_replies(self.pg4, pkts_disc_vrf1, |
| 449 | "DHCP with no configuration") |
| 450 | self.send_and_assert_no_replies(self.pg5, pkts_disc_vrf2, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 451 | "DHCP with no configuration") |
| 452 | |
| 453 | # |
| 454 | # Enable DHCP proxy in VRF 0 |
| 455 | # |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 456 | server_addr = self.pg0.remote_ip4 |
| 457 | src_addr = self.pg0.local_ip4 |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 458 | |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 459 | Proxy = VppDHCPProxy(self, server_addr, src_addr, rx_vrf_id=0) |
| 460 | Proxy.add_vpp_config() |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 461 | |
| 462 | # |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 463 | # Discover packets from the client are dropped because there is no |
| 464 | # IP address configured on the client facing interface |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 465 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 466 | self.send_and_assert_no_replies(self.pg3, pkts_disc_vrf0, |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 467 | "Discover DHCP no relay address") |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 468 | |
| 469 | # |
| 470 | # Inject a response from the server |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 471 | # dropped, because there is no IP addrees on the |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 472 | # client interfce to fill in the option. |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 473 | # |
| 474 | p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
| 475 | IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) / |
| 476 | UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) / |
| 477 | BOOTP(op=1) / |
| 478 | DHCP(options=[('message-type', 'offer'), ('end')])) |
| 479 | pkts = [p] |
| 480 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 481 | self.send_and_assert_no_replies(self.pg3, pkts, |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 482 | "Offer DHCP no relay address") |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 483 | |
| 484 | # |
| 485 | # configure an IP address on the client facing interface |
| 486 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 487 | self.pg3.config_ip4() |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 488 | |
| 489 | # |
| 490 | # Try again with a discover packet |
| 491 | # Rx'd packet should be to the server address and from the configured |
| 492 | # source address |
| 493 | # UDP source ports are unchanged |
| 494 | # we've no option 82 config so that should be absent |
| 495 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 496 | self.pg3.add_stream(pkts_disc_vrf0) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 497 | self.pg_enable_capture(self.pg_interfaces) |
| 498 | self.pg_start() |
| 499 | |
| 500 | rx = self.pg0.get_capture(1) |
| 501 | rx = rx[0] |
| 502 | |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 503 | option_82 = self.verify_relayed_dhcp_discover(rx, self.pg0, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 504 | src_intf=self.pg3) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 505 | |
| 506 | # |
| 507 | # Create an DHCP offer reply from the server with a correctly formatted |
| 508 | # option 82. i.e. send back what we just captured |
| 509 | # The offer, sent mcast to the client, still has option 82. |
| 510 | # |
| 511 | p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
| 512 | IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) / |
| 513 | UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) / |
| 514 | BOOTP(op=1) / |
| 515 | DHCP(options=[('message-type', 'offer'), |
| 516 | ('relay_agent_Information', option_82), |
| 517 | ('end')])) |
| 518 | pkts = [p] |
| 519 | |
| 520 | self.pg0.add_stream(pkts) |
| 521 | self.pg_enable_capture(self.pg_interfaces) |
| 522 | self.pg_start() |
| 523 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 524 | rx = self.pg3.get_capture(1) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 525 | rx = rx[0] |
| 526 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 527 | self.verify_dhcp_offer(rx, self.pg3) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 528 | |
| 529 | # |
| 530 | # Bogus Option 82: |
| 531 | # |
| 532 | # 1. not our IP address = not checked by VPP? so offer is replayed |
| 533 | # to client |
Paul Vinciguerra | a7427ec | 2019-03-10 10:04:23 -0700 | [diff] [blame] | 534 | bad_ip = option_82[0:8] + scapy.compat.chb(33) + option_82[9:] |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 535 | |
| 536 | p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
| 537 | IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) / |
| 538 | UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) / |
| 539 | BOOTP(op=1) / |
| 540 | DHCP(options=[('message-type', 'offer'), |
| 541 | ('relay_agent_Information', bad_ip), |
| 542 | ('end')])) |
| 543 | pkts = [p] |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 544 | self.send_and_assert_no_replies(self.pg0, pkts, |
| 545 | "DHCP offer option 82 bad address") |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 546 | |
| 547 | # 2. Not a sw_if_index VPP knows |
Paul Vinciguerra | a7427ec | 2019-03-10 10:04:23 -0700 | [diff] [blame] | 548 | bad_if_index = option_82[0:2] + scapy.compat.chb(33) + option_82[3:] |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 549 | |
| 550 | p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
| 551 | IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) / |
| 552 | UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) / |
| 553 | BOOTP(op=1) / |
| 554 | DHCP(options=[('message-type', 'offer'), |
| 555 | ('relay_agent_Information', bad_if_index), |
| 556 | ('end')])) |
| 557 | pkts = [p] |
| 558 | self.send_and_assert_no_replies(self.pg0, pkts, |
| 559 | "DHCP offer option 82 bad if index") |
| 560 | |
| 561 | # |
| 562 | # Send a DHCP request in VRF 1. should be dropped. |
| 563 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 564 | self.send_and_assert_no_replies(self.pg4, pkts_disc_vrf1, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 565 | "DHCP with no configuration VRF 1") |
| 566 | |
| 567 | # |
| 568 | # Delete the DHCP config in VRF 0 |
| 569 | # Should now drop requests. |
| 570 | # |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 571 | Proxy.remove_vpp_config() |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 572 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 573 | self.send_and_assert_no_replies(self.pg3, pkts_disc_vrf0, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 574 | "DHCP config removed VRF 0") |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 575 | self.send_and_assert_no_replies(self.pg4, pkts_disc_vrf1, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 576 | "DHCP config removed VRF 1") |
| 577 | |
| 578 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 579 | # Add DHCP config for VRF 1 & 2 |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 580 | # |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 581 | server_addr1 = self.pg1.remote_ip4 |
| 582 | src_addr1 = self.pg1.local_ip4 |
| 583 | Proxy1 = VppDHCPProxy( |
| 584 | self, |
| 585 | server_addr1, |
| 586 | src_addr1, |
| 587 | rx_vrf_id=1, |
| 588 | server_vrf_id=1) |
| 589 | Proxy1.add_vpp_config() |
| 590 | |
| 591 | server_addr2 = self.pg2.remote_ip4 |
| 592 | src_addr2 = self.pg2.local_ip4 |
| 593 | Proxy2 = VppDHCPProxy( |
| 594 | self, |
| 595 | server_addr2, |
| 596 | src_addr2, |
| 597 | rx_vrf_id=2, |
| 598 | server_vrf_id=2) |
| 599 | Proxy2.add_vpp_config() |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 600 | |
| 601 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 602 | # Confim DHCP requests ok in VRF 1 & 2. |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 603 | # - dropped on IP config on client interface |
| 604 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 605 | self.send_and_assert_no_replies(self.pg4, pkts_disc_vrf1, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 606 | "DHCP config removed VRF 1") |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 607 | self.send_and_assert_no_replies(self.pg5, pkts_disc_vrf2, |
| 608 | "DHCP config removed VRF 2") |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 609 | |
| 610 | # |
| 611 | # configure an IP address on the client facing interface |
| 612 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 613 | self.pg4.config_ip4() |
| 614 | self.pg4.add_stream(pkts_disc_vrf1) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 615 | self.pg_enable_capture(self.pg_interfaces) |
| 616 | self.pg_start() |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 617 | rx = self.pg1.get_capture(1) |
| 618 | rx = rx[0] |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 619 | self.verify_relayed_dhcp_discover(rx, self.pg1, src_intf=self.pg4) |
| 620 | |
| 621 | self.pg5.config_ip4() |
| 622 | self.pg5.add_stream(pkts_disc_vrf2) |
| 623 | self.pg_enable_capture(self.pg_interfaces) |
| 624 | self.pg_start() |
| 625 | rx = self.pg2.get_capture(1) |
| 626 | rx = rx[0] |
| 627 | self.verify_relayed_dhcp_discover(rx, self.pg2, src_intf=self.pg5) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 628 | |
| 629 | # |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 630 | # Add VSS config |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 631 | # table=1, vss_type=1, vpn_index=1, oui=4 |
| 632 | # table=2, vss_type=0, vpn_id = "ip4-table-2" |
Neale Ranns | 02bfd64 | 2019-10-07 00:39:28 -0700 | [diff] [blame] | 633 | self.vapi.dhcp_proxy_set_vss(tbl_id=1, vss_type=1, |
| 634 | vpn_index=1, oui=4, is_add=1) |
| 635 | self.vapi.dhcp_proxy_set_vss(tbl_id=2, vss_type=0, |
| 636 | vpn_ascii_id="ip4-table-2", is_add=1) |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 637 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 638 | self.pg4.add_stream(pkts_disc_vrf1) |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 639 | self.pg_enable_capture(self.pg_interfaces) |
| 640 | self.pg_start() |
| 641 | |
| 642 | rx = self.pg1.get_capture(1) |
| 643 | rx = rx[0] |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 644 | self.verify_relayed_dhcp_discover(rx, self.pg1, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 645 | src_intf=self.pg4, |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 646 | fib_id=1, oui=4) |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 647 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 648 | self.pg5.add_stream(pkts_disc_vrf2) |
| 649 | self.pg_enable_capture(self.pg_interfaces) |
| 650 | self.pg_start() |
| 651 | |
| 652 | rx = self.pg2.get_capture(1) |
| 653 | rx = rx[0] |
| 654 | self.verify_relayed_dhcp_discover(rx, self.pg2, |
| 655 | src_intf=self.pg5, |
| 656 | vpn_id="ip4-table-2") |
| 657 | |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 658 | # |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 659 | # Add a second DHCP server in VRF 1 |
| 660 | # expect clients messages to be relay to both configured servers |
| 661 | # |
| 662 | self.pg1.generate_remote_hosts(2) |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 663 | server_addr12 = self.pg1.remote_hosts[1].ip4 |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 664 | |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 665 | Proxy12 = VppDHCPProxy( |
| 666 | self, |
| 667 | server_addr12, |
| 668 | src_addr, |
| 669 | rx_vrf_id=1, |
| 670 | server_vrf_id=1) |
| 671 | Proxy12.add_vpp_config() |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 672 | |
| 673 | # |
| 674 | # We'll need an ARP entry for the server to send it packets |
| 675 | # |
| 676 | arp_entry = VppNeighbor(self, |
| 677 | self.pg1.sw_if_index, |
| 678 | self.pg1.remote_hosts[1].mac, |
| 679 | self.pg1.remote_hosts[1].ip4) |
| 680 | arp_entry.add_vpp_config() |
| 681 | |
| 682 | # |
| 683 | # Send a discover from the client. expect two relayed messages |
| 684 | # The frist packet is sent to the second server |
| 685 | # We're not enforcing that here, it's just the way it is. |
| 686 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 687 | self.pg4.add_stream(pkts_disc_vrf1) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 688 | self.pg_enable_capture(self.pg_interfaces) |
| 689 | self.pg_start() |
| 690 | |
| 691 | rx = self.pg1.get_capture(2) |
| 692 | |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 693 | option_82 = self.verify_relayed_dhcp_discover( |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 694 | rx[0], self.pg1, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 695 | src_intf=self.pg4, |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 696 | dst_mac=self.pg1.remote_hosts[1].mac, |
| 697 | dst_ip=self.pg1.remote_hosts[1].ip4, |
| 698 | fib_id=1, oui=4) |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 699 | self.verify_relayed_dhcp_discover(rx[1], self.pg1, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 700 | src_intf=self.pg4, |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 701 | fib_id=1, oui=4) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 702 | |
| 703 | # |
| 704 | # Send both packets back. Client gets both. |
| 705 | # |
| 706 | p1 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) / |
| 707 | IP(src=self.pg1.remote_ip4, dst=self.pg1.local_ip4) / |
| 708 | UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) / |
| 709 | BOOTP(op=1) / |
| 710 | DHCP(options=[('message-type', 'offer'), |
| 711 | ('relay_agent_Information', option_82), |
| 712 | ('end')])) |
| 713 | p2 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) / |
| 714 | IP(src=self.pg1.remote_hosts[1].ip4, dst=self.pg1.local_ip4) / |
| 715 | UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) / |
| 716 | BOOTP(op=1) / |
| 717 | DHCP(options=[('message-type', 'offer'), |
| 718 | ('relay_agent_Information', option_82), |
| 719 | ('end')])) |
| 720 | pkts = [p1, p2] |
| 721 | |
| 722 | self.pg1.add_stream(pkts) |
| 723 | self.pg_enable_capture(self.pg_interfaces) |
| 724 | self.pg_start() |
| 725 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 726 | rx = self.pg4.get_capture(2) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 727 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 728 | self.verify_dhcp_offer(rx[0], self.pg4, fib_id=1, oui=4) |
| 729 | self.verify_dhcp_offer(rx[1], self.pg4, fib_id=1, oui=4) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 730 | |
| 731 | # |
| 732 | # Ensure offers from non-servers are dropeed |
| 733 | # |
| 734 | p2 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) / |
| 735 | IP(src="8.8.8.8", dst=self.pg1.local_ip4) / |
| 736 | UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_SERVER_PORT) / |
| 737 | BOOTP(op=1) / |
| 738 | DHCP(options=[('message-type', 'offer'), |
| 739 | ('relay_agent_Information', option_82), |
| 740 | ('end')])) |
| 741 | self.send_and_assert_no_replies(self.pg1, p2, |
| 742 | "DHCP offer from non-server") |
| 743 | |
| 744 | # |
| 745 | # Ensure only the discover is sent to multiple servers |
| 746 | # |
| 747 | p_req_vrf1 = (Ether(dst="ff:ff:ff:ff:ff:ff", |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 748 | src=self.pg4.remote_mac) / |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 749 | IP(src="0.0.0.0", dst="255.255.255.255") / |
| 750 | UDP(sport=DHCP4_CLIENT_PORT, |
| 751 | dport=DHCP4_SERVER_PORT) / |
| 752 | BOOTP(op=1) / |
| 753 | DHCP(options=[('message-type', 'request'), |
| 754 | ('end')])) |
| 755 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 756 | self.pg4.add_stream(p_req_vrf1) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 757 | self.pg_enable_capture(self.pg_interfaces) |
| 758 | self.pg_start() |
| 759 | |
| 760 | rx = self.pg1.get_capture(1) |
| 761 | |
| 762 | # |
| 763 | # Remove the second DHCP server |
| 764 | # |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 765 | Proxy12.remove_vpp_config() |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 766 | |
| 767 | # |
| 768 | # Test we can still relay with the first |
| 769 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 770 | self.pg4.add_stream(pkts_disc_vrf1) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 771 | self.pg_enable_capture(self.pg_interfaces) |
| 772 | self.pg_start() |
| 773 | |
| 774 | rx = self.pg1.get_capture(1) |
| 775 | rx = rx[0] |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 776 | self.verify_relayed_dhcp_discover(rx, self.pg1, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 777 | src_intf=self.pg4, |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 778 | fib_id=1, oui=4) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 779 | |
| 780 | # |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 781 | # Remove the VSS config |
| 782 | # relayed DHCP has default vlaues in the option. |
| 783 | # |
Neale Ranns | 02bfd64 | 2019-10-07 00:39:28 -0700 | [diff] [blame] | 784 | self.vapi.dhcp_proxy_set_vss(tbl_id=1, is_add=0) |
| 785 | self.vapi.dhcp_proxy_set_vss(tbl_id=2, is_add=0) |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 786 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 787 | self.pg4.add_stream(pkts_disc_vrf1) |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 788 | self.pg_enable_capture(self.pg_interfaces) |
| 789 | self.pg_start() |
| 790 | |
| 791 | rx = self.pg1.get_capture(1) |
| 792 | rx = rx[0] |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 793 | self.verify_relayed_dhcp_discover(rx, self.pg1, src_intf=self.pg4) |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 794 | |
| 795 | # |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 796 | # remove DHCP config to cleanup |
| 797 | # |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 798 | Proxy1.remove_vpp_config() |
| 799 | Proxy2.remove_vpp_config() |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 800 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 801 | self.send_and_assert_no_replies(self.pg3, pkts_disc_vrf0, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 802 | "DHCP cleanup VRF 0") |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 803 | self.send_and_assert_no_replies(self.pg4, pkts_disc_vrf1, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 804 | "DHCP cleanup VRF 1") |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 805 | self.send_and_assert_no_replies(self.pg5, pkts_disc_vrf2, |
| 806 | "DHCP cleanup VRF 2") |
| 807 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 808 | self.pg3.unconfig_ip4() |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 809 | self.pg4.unconfig_ip4() |
| 810 | self.pg5.unconfig_ip4() |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 811 | |
| 812 | def test_dhcp6_proxy(self): |
| 813 | """ DHCPv6 Proxy""" |
| 814 | # |
| 815 | # Verify no response to DHCP request without DHCP config |
| 816 | # |
| 817 | dhcp_solicit_dst = "ff02::1:2" |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 818 | dhcp_solicit_src_vrf0 = mk_ll_addr(self.pg3.remote_mac) |
| 819 | dhcp_solicit_src_vrf1 = mk_ll_addr(self.pg4.remote_mac) |
| 820 | dhcp_solicit_src_vrf2 = mk_ll_addr(self.pg5.remote_mac) |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 821 | server_addr_vrf0 = self.pg0.remote_ip6 |
| 822 | src_addr_vrf0 = self.pg0.local_ip6 |
| 823 | server_addr_vrf1 = self.pg1.remote_ip6 |
| 824 | src_addr_vrf1 = self.pg1.local_ip6 |
| 825 | server_addr_vrf2 = self.pg2.remote_ip6 |
| 826 | src_addr_vrf2 = self.pg2.local_ip6 |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 827 | |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 828 | dmac = in6_getnsmac(inet_pton(socket.AF_INET6, dhcp_solicit_dst)) |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 829 | p_solicit_vrf0 = (Ether(dst=dmac, src=self.pg3.remote_mac) / |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 830 | IPv6(src=dhcp_solicit_src_vrf0, |
| 831 | dst=dhcp_solicit_dst) / |
| 832 | UDP(sport=DHCP6_SERVER_PORT, |
| 833 | dport=DHCP6_CLIENT_PORT) / |
| 834 | DHCP6_Solicit()) |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 835 | p_solicit_vrf1 = (Ether(dst=dmac, src=self.pg4.remote_mac) / |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 836 | IPv6(src=dhcp_solicit_src_vrf1, |
| 837 | dst=dhcp_solicit_dst) / |
| 838 | UDP(sport=DHCP6_SERVER_PORT, |
| 839 | dport=DHCP6_CLIENT_PORT) / |
| 840 | DHCP6_Solicit()) |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 841 | p_solicit_vrf2 = (Ether(dst=dmac, src=self.pg5.remote_mac) / |
| 842 | IPv6(src=dhcp_solicit_src_vrf2, |
| 843 | dst=dhcp_solicit_dst) / |
| 844 | UDP(sport=DHCP6_SERVER_PORT, |
| 845 | dport=DHCP6_CLIENT_PORT) / |
| 846 | DHCP6_Solicit()) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 847 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 848 | self.send_and_assert_no_replies(self.pg3, p_solicit_vrf0, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 849 | "DHCP with no configuration") |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 850 | self.send_and_assert_no_replies(self.pg4, p_solicit_vrf1, |
| 851 | "DHCP with no configuration") |
| 852 | self.send_and_assert_no_replies(self.pg5, p_solicit_vrf2, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 853 | "DHCP with no configuration") |
| 854 | |
| 855 | # |
| 856 | # DHCPv6 config in VRF 0. |
| 857 | # Packets still dropped because the client facing interface has no |
| 858 | # IPv6 config |
| 859 | # |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 860 | Proxy = VppDHCPProxy( |
| 861 | self, |
| 862 | server_addr_vrf0, |
| 863 | src_addr_vrf0, |
| 864 | rx_vrf_id=0, |
| 865 | server_vrf_id=0) |
| 866 | Proxy.add_vpp_config() |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 867 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 868 | self.send_and_assert_no_replies(self.pg3, p_solicit_vrf0, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 869 | "DHCP with no configuration") |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 870 | self.send_and_assert_no_replies(self.pg4, p_solicit_vrf1, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 871 | "DHCP with no configuration") |
| 872 | |
| 873 | # |
| 874 | # configure an IP address on the client facing interface |
| 875 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 876 | self.pg3.config_ip6() |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 877 | |
| 878 | # |
| 879 | # Now the DHCP requests are relayed to the server |
| 880 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 881 | self.pg3.add_stream(p_solicit_vrf0) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 882 | self.pg_enable_capture(self.pg_interfaces) |
| 883 | self.pg_start() |
| 884 | |
| 885 | rx = self.pg0.get_capture(1) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 886 | |
| 887 | self.verify_dhcp6_solicit(rx[0], self.pg0, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 888 | dhcp_solicit_src_vrf0, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 889 | self.pg3.remote_mac) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 890 | |
| 891 | # |
| 892 | # Exception cases for rejected relay responses |
| 893 | # |
| 894 | |
| 895 | # 1 - not a relay reply |
| 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) / |
| 899 | DHCP6_Advertise()) |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 900 | self.send_and_assert_no_replies(self.pg3, p_adv_vrf0, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 901 | "DHCP6 not a relay reply") |
| 902 | |
| 903 | # 2 - no relay message option |
| 904 | p_adv_vrf0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
| 905 | IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) / |
| 906 | UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) / |
| 907 | DHCP6_RelayReply() / |
| 908 | DHCP6_Advertise()) |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 909 | self.send_and_assert_no_replies(self.pg3, p_adv_vrf0, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 910 | "DHCP not a relay message") |
| 911 | |
| 912 | # 3 - no circuit ID |
| 913 | p_adv_vrf0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
| 914 | IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) / |
| 915 | UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) / |
| 916 | DHCP6_RelayReply() / |
| 917 | DHCP6OptRelayMsg(optlen=0) / |
| 918 | DHCP6_Advertise()) |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 919 | self.send_and_assert_no_replies(self.pg3, p_adv_vrf0, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 920 | "DHCP6 no circuit ID") |
| 921 | # 4 - wrong circuit ID |
| 922 | p_adv_vrf0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
| 923 | IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) / |
| 924 | UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) / |
| 925 | DHCP6_RelayReply() / |
| 926 | DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x05') / |
| 927 | DHCP6OptRelayMsg(optlen=0) / |
| 928 | DHCP6_Advertise()) |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 929 | self.send_and_assert_no_replies(self.pg3, p_adv_vrf0, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 930 | "DHCP6 wrong circuit ID") |
| 931 | |
| 932 | # |
| 933 | # Send the relay response (the advertisement) |
| 934 | # - no peer address |
| 935 | p_adv_vrf0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
| 936 | IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) / |
| 937 | UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) / |
| 938 | DHCP6_RelayReply() / |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 939 | DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x04') / |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 940 | DHCP6OptRelayMsg(optlen=0) / |
| 941 | DHCP6_Advertise(trid=1) / |
| 942 | DHCP6OptStatusCode(statuscode=0)) |
| 943 | pkts_adv_vrf0 = [p_adv_vrf0] |
| 944 | |
| 945 | self.pg0.add_stream(pkts_adv_vrf0) |
| 946 | self.pg_enable_capture(self.pg_interfaces) |
| 947 | self.pg_start() |
| 948 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 949 | rx = self.pg3.get_capture(1) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 950 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 951 | self.verify_dhcp6_advert(rx[0], self.pg3, "::") |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 952 | |
| 953 | # |
| 954 | # Send the relay response (the advertisement) |
| 955 | # - with peer address |
| 956 | p_adv_vrf0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
| 957 | IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) / |
| 958 | UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) / |
| 959 | DHCP6_RelayReply(peeraddr=dhcp_solicit_src_vrf0) / |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 960 | DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x04') / |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 961 | DHCP6OptRelayMsg(optlen=0) / |
| 962 | DHCP6_Advertise(trid=1) / |
| 963 | DHCP6OptStatusCode(statuscode=0)) |
| 964 | pkts_adv_vrf0 = [p_adv_vrf0] |
| 965 | |
| 966 | self.pg0.add_stream(pkts_adv_vrf0) |
| 967 | self.pg_enable_capture(self.pg_interfaces) |
| 968 | self.pg_start() |
| 969 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 970 | rx = self.pg3.get_capture(1) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 971 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 972 | self.verify_dhcp6_advert(rx[0], self.pg3, dhcp_solicit_src_vrf0) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 973 | |
| 974 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 975 | # Add all the config for VRF 1 & 2 |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 976 | # |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 977 | Proxy1 = VppDHCPProxy( |
| 978 | self, |
| 979 | server_addr_vrf1, |
| 980 | src_addr_vrf1, |
| 981 | rx_vrf_id=1, |
| 982 | server_vrf_id=1) |
| 983 | Proxy1.add_vpp_config() |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 984 | self.pg4.config_ip6() |
| 985 | |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 986 | Proxy2 = VppDHCPProxy( |
| 987 | self, |
| 988 | server_addr_vrf2, |
| 989 | src_addr_vrf2, |
| 990 | rx_vrf_id=2, |
| 991 | server_vrf_id=2) |
| 992 | Proxy2.add_vpp_config() |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 993 | self.pg5.config_ip6() |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 994 | |
| 995 | # |
| 996 | # VRF 1 solicit |
| 997 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 998 | self.pg4.add_stream(p_solicit_vrf1) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 999 | self.pg_enable_capture(self.pg_interfaces) |
| 1000 | self.pg_start() |
| 1001 | |
| 1002 | rx = self.pg1.get_capture(1) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 1003 | |
| 1004 | self.verify_dhcp6_solicit(rx[0], self.pg1, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1005 | dhcp_solicit_src_vrf1, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1006 | self.pg4.remote_mac) |
| 1007 | |
| 1008 | # |
| 1009 | # VRF 2 solicit |
| 1010 | # |
| 1011 | self.pg5.add_stream(p_solicit_vrf2) |
| 1012 | self.pg_enable_capture(self.pg_interfaces) |
| 1013 | self.pg_start() |
| 1014 | |
| 1015 | rx = self.pg2.get_capture(1) |
| 1016 | |
| 1017 | self.verify_dhcp6_solicit(rx[0], self.pg2, |
| 1018 | dhcp_solicit_src_vrf2, |
| 1019 | self.pg5.remote_mac) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1020 | |
| 1021 | # |
| 1022 | # VRF 1 Advert |
| 1023 | # |
| 1024 | p_adv_vrf1 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) / |
| 1025 | IPv6(dst=self.pg1.local_ip6, src=self.pg1.remote_ip6) / |
| 1026 | UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) / |
| 1027 | DHCP6_RelayReply(peeraddr=dhcp_solicit_src_vrf1) / |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1028 | DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x05') / |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1029 | DHCP6OptRelayMsg(optlen=0) / |
| 1030 | DHCP6_Advertise(trid=1) / |
| 1031 | DHCP6OptStatusCode(statuscode=0)) |
| 1032 | pkts_adv_vrf1 = [p_adv_vrf1] |
| 1033 | |
| 1034 | self.pg1.add_stream(pkts_adv_vrf1) |
| 1035 | self.pg_enable_capture(self.pg_interfaces) |
| 1036 | self.pg_start() |
| 1037 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1038 | rx = self.pg4.get_capture(1) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 1039 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1040 | self.verify_dhcp6_advert(rx[0], self.pg4, dhcp_solicit_src_vrf1) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1041 | |
| 1042 | # |
| 1043 | # Add VSS config |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 1044 | # |
| 1045 | self.vapi.dhcp_proxy_set_vss( |
Neale Ranns | 02bfd64 | 2019-10-07 00:39:28 -0700 | [diff] [blame] | 1046 | tbl_id=1, vss_type=1, oui=4, vpn_index=1, is_ipv6=1, is_add=1) |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 1047 | self.vapi.dhcp_proxy_set_vss( |
| 1048 | tbl_id=2, |
| 1049 | vss_type=0, |
| 1050 | vpn_ascii_id="IPv6-table-2", |
Neale Ranns | 02bfd64 | 2019-10-07 00:39:28 -0700 | [diff] [blame] | 1051 | is_ipv6=1, |
| 1052 | is_add=1) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1053 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1054 | self.pg4.add_stream(p_solicit_vrf1) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1055 | self.pg_enable_capture(self.pg_interfaces) |
| 1056 | self.pg_start() |
| 1057 | |
| 1058 | rx = self.pg1.get_capture(1) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 1059 | |
| 1060 | self.verify_dhcp6_solicit(rx[0], self.pg1, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1061 | dhcp_solicit_src_vrf1, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1062 | self.pg4.remote_mac, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1063 | fib_id=1, |
| 1064 | oui=4) |
| 1065 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1066 | self.pg5.add_stream(p_solicit_vrf2) |
| 1067 | self.pg_enable_capture(self.pg_interfaces) |
| 1068 | self.pg_start() |
| 1069 | |
| 1070 | rx = self.pg2.get_capture(1) |
| 1071 | |
| 1072 | self.verify_dhcp6_solicit(rx[0], self.pg2, |
| 1073 | dhcp_solicit_src_vrf2, |
| 1074 | self.pg5.remote_mac, |
| 1075 | vpn_id="IPv6-table-2") |
| 1076 | |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1077 | # |
| 1078 | # Remove the VSS config |
| 1079 | # relayed DHCP has default vlaues in the option. |
| 1080 | # |
Neale Ranns | 02bfd64 | 2019-10-07 00:39:28 -0700 | [diff] [blame] | 1081 | self.vapi.dhcp_proxy_set_vss(tbl_id=1, is_ipv6=1, is_add=0) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1082 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1083 | self.pg4.add_stream(p_solicit_vrf1) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1084 | self.pg_enable_capture(self.pg_interfaces) |
| 1085 | self.pg_start() |
| 1086 | |
| 1087 | rx = self.pg1.get_capture(1) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 1088 | |
| 1089 | self.verify_dhcp6_solicit(rx[0], self.pg1, |
| 1090 | dhcp_solicit_src_vrf1, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1091 | self.pg4.remote_mac) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 1092 | |
| 1093 | # |
| 1094 | # Add a second DHCP server in VRF 1 |
| 1095 | # expect clients messages to be relay to both configured servers |
| 1096 | # |
| 1097 | self.pg1.generate_remote_hosts(2) |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 1098 | server_addr12 = self.pg1.remote_hosts[1].ip6 |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 1099 | |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 1100 | Proxy12 = VppDHCPProxy( |
| 1101 | self, |
| 1102 | server_addr12, |
| 1103 | src_addr_vrf1, |
| 1104 | rx_vrf_id=1, |
| 1105 | server_vrf_id=1) |
| 1106 | Proxy12.add_vpp_config() |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 1107 | |
| 1108 | # |
| 1109 | # We'll need an ND entry for the server to send it packets |
| 1110 | # |
| 1111 | nd_entry = VppNeighbor(self, |
| 1112 | self.pg1.sw_if_index, |
| 1113 | self.pg1.remote_hosts[1].mac, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1114 | self.pg1.remote_hosts[1].ip6) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 1115 | nd_entry.add_vpp_config() |
| 1116 | |
| 1117 | # |
| 1118 | # Send a discover from the client. expect two relayed messages |
| 1119 | # The frist packet is sent to the second server |
| 1120 | # We're not enforcing that here, it's just the way it is. |
| 1121 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1122 | self.pg4.add_stream(p_solicit_vrf1) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 1123 | self.pg_enable_capture(self.pg_interfaces) |
| 1124 | self.pg_start() |
| 1125 | |
| 1126 | rx = self.pg1.get_capture(2) |
| 1127 | |
| 1128 | self.verify_dhcp6_solicit(rx[0], self.pg1, |
| 1129 | dhcp_solicit_src_vrf1, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1130 | self.pg4.remote_mac) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 1131 | self.verify_dhcp6_solicit(rx[1], self.pg1, |
| 1132 | dhcp_solicit_src_vrf1, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1133 | self.pg4.remote_mac, |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 1134 | dst_mac=self.pg1.remote_hosts[1].mac, |
| 1135 | dst_ip=self.pg1.remote_hosts[1].ip6) |
| 1136 | |
| 1137 | # |
| 1138 | # Send both packets back. Client gets both. |
| 1139 | # |
| 1140 | p1 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) / |
| 1141 | IPv6(dst=self.pg1.local_ip6, src=self.pg1.remote_ip6) / |
| 1142 | UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) / |
| 1143 | DHCP6_RelayReply(peeraddr=dhcp_solicit_src_vrf1) / |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1144 | DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x05') / |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 1145 | DHCP6OptRelayMsg(optlen=0) / |
| 1146 | DHCP6_Advertise(trid=1) / |
| 1147 | DHCP6OptStatusCode(statuscode=0)) |
| 1148 | p2 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_hosts[1].mac) / |
| 1149 | IPv6(dst=self.pg1.local_ip6, src=self.pg1._remote_hosts[1].ip6) / |
| 1150 | UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) / |
| 1151 | DHCP6_RelayReply(peeraddr=dhcp_solicit_src_vrf1) / |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1152 | DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x05') / |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 1153 | DHCP6OptRelayMsg(optlen=0) / |
| 1154 | DHCP6_Advertise(trid=1) / |
| 1155 | DHCP6OptStatusCode(statuscode=0)) |
| 1156 | |
| 1157 | pkts = [p1, p2] |
| 1158 | |
| 1159 | self.pg1.add_stream(pkts) |
| 1160 | self.pg_enable_capture(self.pg_interfaces) |
| 1161 | self.pg_start() |
| 1162 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1163 | rx = self.pg4.get_capture(2) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 1164 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1165 | self.verify_dhcp6_advert(rx[0], self.pg4, dhcp_solicit_src_vrf1) |
| 1166 | self.verify_dhcp6_advert(rx[1], self.pg4, dhcp_solicit_src_vrf1) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 1167 | |
| 1168 | # |
| 1169 | # Ensure only solicit messages are duplicated |
| 1170 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1171 | p_request_vrf1 = (Ether(dst=dmac, src=self.pg4.remote_mac) / |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 1172 | IPv6(src=dhcp_solicit_src_vrf1, |
| 1173 | dst=dhcp_solicit_dst) / |
| 1174 | UDP(sport=DHCP6_SERVER_PORT, |
| 1175 | dport=DHCP6_CLIENT_PORT) / |
| 1176 | DHCP6_Request()) |
| 1177 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1178 | self.pg4.add_stream(p_request_vrf1) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 1179 | self.pg_enable_capture(self.pg_interfaces) |
| 1180 | self.pg_start() |
| 1181 | |
| 1182 | rx = self.pg1.get_capture(1) |
| 1183 | |
| 1184 | # |
| 1185 | # Test we drop DHCP packets from addresses that are not configured as |
| 1186 | # DHCP servers |
| 1187 | # |
| 1188 | p2 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_hosts[1].mac) / |
| 1189 | IPv6(dst=self.pg1.local_ip6, src="3001::1") / |
| 1190 | UDP(sport=DHCP6_SERVER_PORT, dport=DHCP6_SERVER_PORT) / |
| 1191 | DHCP6_RelayReply(peeraddr=dhcp_solicit_src_vrf1) / |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1192 | DHCP6OptIfaceId(optlen=4, ifaceid='\x00\x00\x00\x05') / |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 1193 | DHCP6OptRelayMsg(optlen=0) / |
| 1194 | DHCP6_Advertise(trid=1) / |
| 1195 | DHCP6OptStatusCode(statuscode=0)) |
| 1196 | self.send_and_assert_no_replies(self.pg1, p2, |
| 1197 | "DHCP6 not from server") |
| 1198 | |
| 1199 | # |
| 1200 | # Remove the second DHCP server |
| 1201 | # |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 1202 | Proxy12.remove_vpp_config() |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 1203 | |
| 1204 | # |
| 1205 | # Test we can still relay with the first |
| 1206 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1207 | self.pg4.add_stream(p_solicit_vrf1) |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 1208 | self.pg_enable_capture(self.pg_interfaces) |
| 1209 | self.pg_start() |
| 1210 | |
| 1211 | rx = self.pg1.get_capture(1) |
| 1212 | |
| 1213 | self.verify_dhcp6_solicit(rx[0], self.pg1, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1214 | dhcp_solicit_src_vrf1, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1215 | self.pg4.remote_mac) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1216 | |
| 1217 | # |
| 1218 | # Cleanup |
| 1219 | # |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 1220 | Proxy.remove_vpp_config() |
| 1221 | Proxy1.remove_vpp_config() |
| 1222 | Proxy2.remove_vpp_config() |
Neale Ranns | 3466c30 | 2017-02-16 07:45:03 -0800 | [diff] [blame] | 1223 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1224 | self.pg3.unconfig_ip6() |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1225 | self.pg4.unconfig_ip6() |
| 1226 | self.pg5.unconfig_ip6() |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1227 | |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1228 | def test_dhcp_client(self): |
| 1229 | """ DHCP Client""" |
| 1230 | |
Neale Ranns | 038e1df | 2019-07-19 14:01:02 +0000 | [diff] [blame] | 1231 | vdscp = VppEnum.vl_api_ip_dscp_t |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1232 | hostname = 'universal-dp' |
| 1233 | |
| 1234 | self.pg_enable_capture(self.pg_interfaces) |
| 1235 | |
| 1236 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1237 | # Configure DHCP client on PG3 and capture the discover sent |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1238 | # |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 1239 | Client = VppDHCPClient(self, self.pg3.sw_if_index, hostname) |
| 1240 | Client.add_vpp_config() |
| 1241 | self.assertTrue(Client.query_vpp_config()) |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1242 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1243 | rx = self.pg3.get_capture(1) |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1244 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1245 | self.verify_orig_dhcp_discover(rx[0], self.pg3, hostname) |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1246 | |
| 1247 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1248 | # Send back on offer, expect the request |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1249 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1250 | p_offer = (Ether(dst=self.pg3.local_mac, src=self.pg3.remote_mac) / |
| 1251 | IP(src=self.pg3.remote_ip4, dst="255.255.255.255") / |
Neale Ranns | 808c5b2 | 2017-08-02 05:15:07 -0700 | [diff] [blame] | 1252 | UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) / |
Neale Ranns | 1f2f4b7 | 2018-03-23 11:53:12 -0700 | [diff] [blame] | 1253 | BOOTP(op=1, |
| 1254 | yiaddr=self.pg3.local_ip4, |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 1255 | chaddr=mac_pton(self.pg3.local_mac)) / |
Neale Ranns | 808c5b2 | 2017-08-02 05:15:07 -0700 | [diff] [blame] | 1256 | DHCP(options=[('message-type', 'offer'), |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1257 | ('server_id', self.pg3.remote_ip4), |
Jan Gelety | 2a3fb1a | 2018-06-27 10:56:17 +0200 | [diff] [blame] | 1258 | 'end'])) |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1259 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1260 | self.pg3.add_stream(p_offer) |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1261 | self.pg_enable_capture(self.pg_interfaces) |
| 1262 | self.pg_start() |
| 1263 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1264 | rx = self.pg3.get_capture(1) |
| 1265 | self.verify_orig_dhcp_request(rx[0], self.pg3, hostname, |
| 1266 | self.pg3.local_ip4) |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1267 | |
| 1268 | # |
Jan Gelety | 2a3fb1a | 2018-06-27 10:56:17 +0200 | [diff] [blame] | 1269 | # Send an acknowledgment |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1270 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1271 | p_ack = (Ether(dst=self.pg3.local_mac, src=self.pg3.remote_mac) / |
| 1272 | IP(src=self.pg3.remote_ip4, dst="255.255.255.255") / |
Neale Ranns | 808c5b2 | 2017-08-02 05:15:07 -0700 | [diff] [blame] | 1273 | UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) / |
Neale Ranns | 1f2f4b7 | 2018-03-23 11:53:12 -0700 | [diff] [blame] | 1274 | BOOTP(op=1, yiaddr=self.pg3.local_ip4, |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 1275 | chaddr=mac_pton(self.pg3.local_mac)) / |
Neale Ranns | 808c5b2 | 2017-08-02 05:15:07 -0700 | [diff] [blame] | 1276 | DHCP(options=[('message-type', 'ack'), |
| 1277 | ('subnet_mask', "255.255.255.0"), |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1278 | ('router', self.pg3.remote_ip4), |
| 1279 | ('server_id', self.pg3.remote_ip4), |
Neale Ranns | 808c5b2 | 2017-08-02 05:15:07 -0700 | [diff] [blame] | 1280 | ('lease_time', 43200), |
Jan Gelety | 2a3fb1a | 2018-06-27 10:56:17 +0200 | [diff] [blame] | 1281 | 'end'])) |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1282 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1283 | self.pg3.add_stream(p_ack) |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1284 | self.pg_enable_capture(self.pg_interfaces) |
| 1285 | self.pg_start() |
| 1286 | |
| 1287 | # |
Neale Ranns | 51822bf | 2017-07-18 09:26:53 -0700 | [diff] [blame] | 1288 | # We'll get an ARP request for the router address |
| 1289 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1290 | rx = self.pg3.get_capture(1) |
Neale Ranns | 51822bf | 2017-07-18 09:26:53 -0700 | [diff] [blame] | 1291 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1292 | self.assertEqual(rx[0][ARP].pdst, self.pg3.remote_ip4) |
Neale Ranns | 51822bf | 2017-07-18 09:26:53 -0700 | [diff] [blame] | 1293 | self.pg_enable_capture(self.pg_interfaces) |
| 1294 | |
| 1295 | # |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1296 | # At the end of this procedure there should be a connected route |
| 1297 | # in the FIB |
| 1298 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1299 | self.assertTrue(find_route(self, self.pg3.local_ip4, 24)) |
| 1300 | self.assertTrue(find_route(self, self.pg3.local_ip4, 32)) |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1301 | |
| 1302 | # |
| 1303 | # remove the DHCP config |
| 1304 | # |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 1305 | Client.remove_vpp_config() |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1306 | |
| 1307 | # |
| 1308 | # and now the route should be gone |
| 1309 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1310 | self.assertFalse(find_route(self, self.pg3.local_ip4, 32)) |
| 1311 | self.assertFalse(find_route(self, self.pg3.local_ip4, 24)) |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1312 | |
Neale Ranns | 51822bf | 2017-07-18 09:26:53 -0700 | [diff] [blame] | 1313 | # |
Neale Ranns | 808c5b2 | 2017-08-02 05:15:07 -0700 | [diff] [blame] | 1314 | # Start the procedure again. this time have VPP send the client-ID |
Neale Ranns | 038e1df | 2019-07-19 14:01:02 +0000 | [diff] [blame] | 1315 | # and set the DSCP value |
Neale Ranns | 51822bf | 2017-07-18 09:26:53 -0700 | [diff] [blame] | 1316 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1317 | self.pg3.admin_down() |
Neale Ranns | 808c5b2 | 2017-08-02 05:15:07 -0700 | [diff] [blame] | 1318 | self.sleep(1) |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1319 | self.pg3.admin_up() |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 1320 | Client.set_client(self.pg3.sw_if_index, hostname, |
| 1321 | id=self.pg3.local_mac, |
| 1322 | dscp=vdscp.IP_API_DSCP_EF) |
| 1323 | Client.add_vpp_config() |
Neale Ranns | 51822bf | 2017-07-18 09:26:53 -0700 | [diff] [blame] | 1324 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1325 | rx = self.pg3.get_capture(1) |
Neale Ranns | 51822bf | 2017-07-18 09:26:53 -0700 | [diff] [blame] | 1326 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1327 | self.verify_orig_dhcp_discover(rx[0], self.pg3, hostname, |
Neale Ranns | 038e1df | 2019-07-19 14:01:02 +0000 | [diff] [blame] | 1328 | self.pg3.local_mac, |
| 1329 | dscp=vdscp.IP_API_DSCP_EF) |
Neale Ranns | 51822bf | 2017-07-18 09:26:53 -0700 | [diff] [blame] | 1330 | |
Jan Gelety | 2a3fb1a | 2018-06-27 10:56:17 +0200 | [diff] [blame] | 1331 | # TODO: VPP DHCP client should not accept DHCP OFFER message with |
| 1332 | # the XID (Transaction ID) not matching the XID of the most recent |
| 1333 | # DHCP DISCOVERY message. |
| 1334 | # Such DHCP OFFER message must be silently discarded - RFC2131. |
| 1335 | # Reported in Jira ticket: VPP-99 |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1336 | self.pg3.add_stream(p_offer) |
Neale Ranns | 808c5b2 | 2017-08-02 05:15:07 -0700 | [diff] [blame] | 1337 | self.pg_enable_capture(self.pg_interfaces) |
| 1338 | self.pg_start() |
| 1339 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1340 | rx = self.pg3.get_capture(1) |
| 1341 | self.verify_orig_dhcp_request(rx[0], self.pg3, hostname, |
Neale Ranns | 038e1df | 2019-07-19 14:01:02 +0000 | [diff] [blame] | 1342 | self.pg3.local_ip4, |
| 1343 | dscp=vdscp.IP_API_DSCP_EF) |
Neale Ranns | 808c5b2 | 2017-08-02 05:15:07 -0700 | [diff] [blame] | 1344 | |
| 1345 | # |
| 1346 | # unicast the ack to the offered address |
| 1347 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1348 | p_ack = (Ether(dst=self.pg3.local_mac, src=self.pg3.remote_mac) / |
| 1349 | IP(src=self.pg3.remote_ip4, dst=self.pg3.local_ip4) / |
Neale Ranns | 808c5b2 | 2017-08-02 05:15:07 -0700 | [diff] [blame] | 1350 | UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) / |
Neale Ranns | 1f2f4b7 | 2018-03-23 11:53:12 -0700 | [diff] [blame] | 1351 | BOOTP(op=1, yiaddr=self.pg3.local_ip4, |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 1352 | chaddr=mac_pton(self.pg3.local_mac)) / |
Neale Ranns | 808c5b2 | 2017-08-02 05:15:07 -0700 | [diff] [blame] | 1353 | DHCP(options=[('message-type', 'ack'), |
| 1354 | ('subnet_mask', "255.255.255.0"), |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1355 | ('router', self.pg3.remote_ip4), |
| 1356 | ('server_id', self.pg3.remote_ip4), |
Neale Ranns | 808c5b2 | 2017-08-02 05:15:07 -0700 | [diff] [blame] | 1357 | ('lease_time', 43200), |
Jan Gelety | 2a3fb1a | 2018-06-27 10:56:17 +0200 | [diff] [blame] | 1358 | 'end'])) |
Neale Ranns | 808c5b2 | 2017-08-02 05:15:07 -0700 | [diff] [blame] | 1359 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1360 | self.pg3.add_stream(p_ack) |
Neale Ranns | 808c5b2 | 2017-08-02 05:15:07 -0700 | [diff] [blame] | 1361 | self.pg_enable_capture(self.pg_interfaces) |
| 1362 | self.pg_start() |
| 1363 | |
| 1364 | # |
Neale Ranns | 54c6dc4 | 2018-01-17 10:29:10 -0800 | [diff] [blame] | 1365 | # We'll get an ARP request for the router address |
| 1366 | # |
| 1367 | rx = self.pg3.get_capture(1) |
| 1368 | |
| 1369 | self.assertEqual(rx[0][ARP].pdst, self.pg3.remote_ip4) |
| 1370 | self.pg_enable_capture(self.pg_interfaces) |
| 1371 | |
| 1372 | # |
Neale Ranns | 808c5b2 | 2017-08-02 05:15:07 -0700 | [diff] [blame] | 1373 | # At the end of this procedure there should be a connected route |
| 1374 | # in the FIB |
| 1375 | # |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1376 | self.assertTrue(find_route(self, self.pg3.local_ip4, 32)) |
| 1377 | self.assertTrue(find_route(self, self.pg3.local_ip4, 24)) |
Neale Ranns | 808c5b2 | 2017-08-02 05:15:07 -0700 | [diff] [blame] | 1378 | |
Neale Ranns | 51822bf | 2017-07-18 09:26:53 -0700 | [diff] [blame] | 1379 | # |
| 1380 | # remove the DHCP config |
| 1381 | # |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 1382 | Client.remove_vpp_config() |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1383 | |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1384 | self.assertFalse(find_route(self, self.pg3.local_ip4, 32)) |
| 1385 | self.assertFalse(find_route(self, self.pg3.local_ip4, 24)) |
Neale Ranns | 808c5b2 | 2017-08-02 05:15:07 -0700 | [diff] [blame] | 1386 | |
Neale Ranns | 54c6dc4 | 2018-01-17 10:29:10 -0800 | [diff] [blame] | 1387 | # |
| 1388 | # Rince and repeat, this time with VPP configured not to set |
| 1389 | # the braodcast flag in the discover and request messages, |
| 1390 | # and for the server to unicast the responses. |
| 1391 | # |
| 1392 | # Configure DHCP client on PG3 and capture the discover sent |
| 1393 | # |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 1394 | Client.set_client( |
| 1395 | self.pg3.sw_if_index, |
| 1396 | hostname, |
| 1397 | set_broadcast_flag=False) |
| 1398 | Client.add_vpp_config() |
Neale Ranns | 54c6dc4 | 2018-01-17 10:29:10 -0800 | [diff] [blame] | 1399 | |
| 1400 | rx = self.pg3.get_capture(1) |
| 1401 | |
| 1402 | self.verify_orig_dhcp_discover(rx[0], self.pg3, hostname, |
Neale Ranns | 99536f4 | 2019-07-25 06:11:58 -0700 | [diff] [blame] | 1403 | broadcast=False) |
Neale Ranns | 54c6dc4 | 2018-01-17 10:29:10 -0800 | [diff] [blame] | 1404 | |
| 1405 | # |
| 1406 | # Send back on offer, unicasted to the offered address. |
| 1407 | # Expect the request. |
| 1408 | # |
| 1409 | p_offer = (Ether(dst=self.pg3.local_mac, src=self.pg3.remote_mac) / |
| 1410 | IP(src=self.pg3.remote_ip4, dst=self.pg3.local_ip4) / |
| 1411 | UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) / |
Neale Ranns | 1f2f4b7 | 2018-03-23 11:53:12 -0700 | [diff] [blame] | 1412 | BOOTP(op=1, yiaddr=self.pg3.local_ip4, |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 1413 | chaddr=mac_pton(self.pg3.local_mac)) / |
Neale Ranns | 54c6dc4 | 2018-01-17 10:29:10 -0800 | [diff] [blame] | 1414 | DHCP(options=[('message-type', 'offer'), |
| 1415 | ('server_id', self.pg3.remote_ip4), |
Jan Gelety | 2a3fb1a | 2018-06-27 10:56:17 +0200 | [diff] [blame] | 1416 | 'end'])) |
Neale Ranns | 54c6dc4 | 2018-01-17 10:29:10 -0800 | [diff] [blame] | 1417 | |
| 1418 | self.pg3.add_stream(p_offer) |
| 1419 | self.pg_enable_capture(self.pg_interfaces) |
| 1420 | self.pg_start() |
| 1421 | |
| 1422 | rx = self.pg3.get_capture(1) |
| 1423 | self.verify_orig_dhcp_request(rx[0], self.pg3, hostname, |
| 1424 | self.pg3.local_ip4, |
Neale Ranns | 99536f4 | 2019-07-25 06:11:58 -0700 | [diff] [blame] | 1425 | broadcast=False) |
Neale Ranns | 54c6dc4 | 2018-01-17 10:29:10 -0800 | [diff] [blame] | 1426 | |
| 1427 | # |
Neale Ranns | 99536f4 | 2019-07-25 06:11:58 -0700 | [diff] [blame] | 1428 | # Send an acknowledgment, the lease renewal time is 2 seconds |
| 1429 | # so we should expect the renew straight after |
Neale Ranns | 54c6dc4 | 2018-01-17 10:29:10 -0800 | [diff] [blame] | 1430 | # |
| 1431 | p_ack = (Ether(dst=self.pg3.local_mac, src=self.pg3.remote_mac) / |
| 1432 | IP(src=self.pg3.remote_ip4, dst=self.pg3.local_ip4) / |
| 1433 | UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) / |
Neale Ranns | 1f2f4b7 | 2018-03-23 11:53:12 -0700 | [diff] [blame] | 1434 | BOOTP(op=1, yiaddr=self.pg3.local_ip4, |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 1435 | chaddr=mac_pton(self.pg3.local_mac)) / |
Neale Ranns | 54c6dc4 | 2018-01-17 10:29:10 -0800 | [diff] [blame] | 1436 | DHCP(options=[('message-type', 'ack'), |
| 1437 | ('subnet_mask', "255.255.255.0"), |
| 1438 | ('router', self.pg3.remote_ip4), |
| 1439 | ('server_id', self.pg3.remote_ip4), |
| 1440 | ('lease_time', 43200), |
Neale Ranns | 99536f4 | 2019-07-25 06:11:58 -0700 | [diff] [blame] | 1441 | ('renewal_time', 2), |
Jan Gelety | 2a3fb1a | 2018-06-27 10:56:17 +0200 | [diff] [blame] | 1442 | 'end'])) |
Neale Ranns | 54c6dc4 | 2018-01-17 10:29:10 -0800 | [diff] [blame] | 1443 | |
| 1444 | self.pg3.add_stream(p_ack) |
| 1445 | self.pg_enable_capture(self.pg_interfaces) |
| 1446 | self.pg_start() |
| 1447 | |
| 1448 | # |
| 1449 | # We'll get an ARP request for the router address |
| 1450 | # |
| 1451 | rx = self.pg3.get_capture(1) |
| 1452 | |
| 1453 | self.assertEqual(rx[0][ARP].pdst, self.pg3.remote_ip4) |
| 1454 | self.pg_enable_capture(self.pg_interfaces) |
| 1455 | |
| 1456 | # |
| 1457 | # At the end of this procedure there should be a connected route |
| 1458 | # in the FIB |
| 1459 | # |
| 1460 | self.assertTrue(find_route(self, self.pg3.local_ip4, 24)) |
| 1461 | self.assertTrue(find_route(self, self.pg3.local_ip4, 32)) |
| 1462 | |
Neale Ranns | 99536f4 | 2019-07-25 06:11:58 -0700 | [diff] [blame] | 1463 | # |
Neale Ranns | 6bcc6a4 | 2019-10-15 15:47:55 +0000 | [diff] [blame] | 1464 | # read the DHCP client details from a dump |
| 1465 | # |
| 1466 | clients = self.vapi.dhcp_client_dump() |
| 1467 | |
| 1468 | self.assertEqual(clients[0].client.sw_if_index, |
| 1469 | self.pg3.sw_if_index) |
| 1470 | self.assertEqual(clients[0].lease.sw_if_index, |
| 1471 | self.pg3.sw_if_index) |
| 1472 | self.assertEqual(clients[0].client.hostname, hostname) |
| 1473 | self.assertEqual(clients[0].lease.hostname, hostname) |
| 1474 | # 0 = DISCOVER, 1 = REQUEST, 2 = BOUND |
| 1475 | self.assertEqual(clients[0].lease.state, 2) |
| 1476 | self.assertEqual(clients[0].lease.mask_width, 24) |
| 1477 | self.assertEqual(str(clients[0].lease.router_address), |
| 1478 | self.pg3.remote_ip4) |
| 1479 | self.assertEqual(str(clients[0].lease.host_address), |
| 1480 | self.pg3.local_ip4) |
| 1481 | |
| 1482 | # |
Neale Ranns | 99536f4 | 2019-07-25 06:11:58 -0700 | [diff] [blame] | 1483 | # wait for the unicasted renewal |
| 1484 | # the first attempt will be an ARP packet, since we have not yet |
| 1485 | # responded to VPP's request |
| 1486 | # |
| 1487 | self.logger.info(self.vapi.cli("sh dhcp client intfc pg3 verbose")) |
| 1488 | rx = self.pg3.get_capture(1, timeout=10) |
| 1489 | |
| 1490 | self.assertEqual(rx[0][ARP].pdst, self.pg3.remote_ip4) |
| 1491 | |
| 1492 | # respond to the arp |
| 1493 | p_arp = (Ether(dst=self.pg3.local_mac, src=self.pg3.remote_mac) / |
| 1494 | ARP(op="is-at", |
| 1495 | hwdst=self.pg3.local_mac, |
| 1496 | hwsrc=self.pg3.remote_mac, |
| 1497 | pdst=self.pg3.local_ip4, |
| 1498 | psrc=self.pg3.remote_ip4)) |
| 1499 | self.pg3.add_stream(p_arp) |
| 1500 | self.pg_enable_capture(self.pg_interfaces) |
| 1501 | self.pg_start() |
| 1502 | |
| 1503 | # the next packet is the unicasted renewal |
| 1504 | rx = self.pg3.get_capture(1, timeout=10) |
| 1505 | self.verify_orig_dhcp_request(rx[0], self.pg3, hostname, |
| 1506 | self.pg3.local_ip4, |
| 1507 | l2_bc=False, |
| 1508 | broadcast=False) |
Neale Ranns | daff178 | 2018-05-16 04:12:18 -0700 | [diff] [blame] | 1509 | |
Neale Ranns | 6bcc6a4 | 2019-10-15 15:47:55 +0000 | [diff] [blame] | 1510 | # send an ACK with different data from the original offer * |
| 1511 | self.pg3.generate_remote_hosts(4) |
| 1512 | p_ack = (Ether(dst=self.pg3.local_mac, src=self.pg3.remote_mac) / |
| 1513 | IP(src=self.pg3.remote_ip4, dst=self.pg3.local_ip4) / |
| 1514 | UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) / |
| 1515 | BOOTP(op=1, yiaddr=self.pg3.remote_hosts[3].ip4, |
| 1516 | chaddr=mac_pton(self.pg3.local_mac)) / |
| 1517 | DHCP(options=[('message-type', 'ack'), |
| 1518 | ('subnet_mask', "255.255.255.0"), |
| 1519 | ('router', self.pg3.remote_hosts[1].ip4), |
| 1520 | ('server_id', self.pg3.remote_hosts[2].ip4), |
| 1521 | ('lease_time', 43200), |
| 1522 | ('renewal_time', 2), |
| 1523 | 'end'])) |
| 1524 | |
| 1525 | self.pg3.add_stream(p_ack) |
| 1526 | self.pg_enable_capture(self.pg_interfaces) |
| 1527 | self.pg_start() |
| 1528 | |
Neale Ranns | daff178 | 2018-05-16 04:12:18 -0700 | [diff] [blame] | 1529 | # |
| 1530 | # read the DHCP client details from a dump |
| 1531 | # |
| 1532 | clients = self.vapi.dhcp_client_dump() |
| 1533 | |
| 1534 | self.assertEqual(clients[0].client.sw_if_index, |
| 1535 | self.pg3.sw_if_index) |
| 1536 | self.assertEqual(clients[0].lease.sw_if_index, |
| 1537 | self.pg3.sw_if_index) |
Neale Ranns | 6bcc6a4 | 2019-10-15 15:47:55 +0000 | [diff] [blame] | 1538 | self.assertEqual(clients[0].client.hostname, hostname) |
| 1539 | self.assertEqual(clients[0].lease.hostname, hostname) |
Neale Ranns | daff178 | 2018-05-16 04:12:18 -0700 | [diff] [blame] | 1540 | # 0 = DISCOVER, 1 = REQUEST, 2 = BOUND |
| 1541 | self.assertEqual(clients[0].lease.state, 2) |
| 1542 | self.assertEqual(clients[0].lease.mask_width, 24) |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 1543 | self.assertEqual(str(clients[0].lease.router_address), |
Neale Ranns | 6bcc6a4 | 2019-10-15 15:47:55 +0000 | [diff] [blame] | 1544 | self.pg3.remote_hosts[1].ip4) |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 1545 | self.assertEqual(str(clients[0].lease.host_address), |
Neale Ranns | 6bcc6a4 | 2019-10-15 15:47:55 +0000 | [diff] [blame] | 1546 | self.pg3.remote_hosts[3].ip4) |
Neale Ranns | 99536f4 | 2019-07-25 06:11:58 -0700 | [diff] [blame] | 1547 | |
Neale Ranns | 54c6dc4 | 2018-01-17 10:29:10 -0800 | [diff] [blame] | 1548 | # |
| 1549 | # remove the DHCP config |
| 1550 | # |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 1551 | Client.remove_vpp_config() |
Neale Ranns | 54c6dc4 | 2018-01-17 10:29:10 -0800 | [diff] [blame] | 1552 | |
| 1553 | # |
| 1554 | # and now the route should be gone |
| 1555 | # |
| 1556 | self.assertFalse(find_route(self, self.pg3.local_ip4, 32)) |
| 1557 | self.assertFalse(find_route(self, self.pg3.local_ip4, 24)) |
| 1558 | |
Jan Gelety | 2a3fb1a | 2018-06-27 10:56:17 +0200 | [diff] [blame] | 1559 | # |
| 1560 | # Start the procedure again. Use requested lease time option. |
Neale Ranns | 6bcc6a4 | 2019-10-15 15:47:55 +0000 | [diff] [blame] | 1561 | # this time wait for the lease to expire and the client to |
| 1562 | # self-destruct |
Jan Gelety | 2a3fb1a | 2018-06-27 10:56:17 +0200 | [diff] [blame] | 1563 | # |
Neale Ranns | 99536f4 | 2019-07-25 06:11:58 -0700 | [diff] [blame] | 1564 | hostname += "-2" |
Jan Gelety | 2a3fb1a | 2018-06-27 10:56:17 +0200 | [diff] [blame] | 1565 | self.pg3.admin_down() |
| 1566 | self.sleep(1) |
| 1567 | self.pg3.admin_up() |
Neale Ranns | 99536f4 | 2019-07-25 06:11:58 -0700 | [diff] [blame] | 1568 | self.pg_enable_capture(self.pg_interfaces) |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 1569 | Client.set_client(self.pg3.sw_if_index, hostname) |
| 1570 | Client.add_vpp_config() |
Jan Gelety | 2a3fb1a | 2018-06-27 10:56:17 +0200 | [diff] [blame] | 1571 | |
| 1572 | rx = self.pg3.get_capture(1) |
| 1573 | |
| 1574 | self.verify_orig_dhcp_discover(rx[0], self.pg3, hostname) |
| 1575 | |
| 1576 | # |
| 1577 | # Send back on offer with requested lease time, expect the request |
| 1578 | # |
| 1579 | lease_time = 1 |
| 1580 | p_offer = (Ether(dst=self.pg3.local_mac, src=self.pg3.remote_mac) / |
| 1581 | IP(src=self.pg3.remote_ip4, dst='255.255.255.255') / |
| 1582 | UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) / |
| 1583 | BOOTP(op=1, |
| 1584 | yiaddr=self.pg3.local_ip4, |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 1585 | chaddr=mac_pton(self.pg3.local_mac)) / |
Jan Gelety | 2a3fb1a | 2018-06-27 10:56:17 +0200 | [diff] [blame] | 1586 | DHCP(options=[('message-type', 'offer'), |
| 1587 | ('server_id', self.pg3.remote_ip4), |
| 1588 | ('lease_time', lease_time), |
| 1589 | 'end'])) |
| 1590 | |
| 1591 | self.pg3.add_stream(p_offer) |
| 1592 | self.pg_enable_capture(self.pg_interfaces) |
| 1593 | self.pg_start() |
| 1594 | |
| 1595 | rx = self.pg3.get_capture(1) |
| 1596 | self.verify_orig_dhcp_request(rx[0], self.pg3, hostname, |
| 1597 | self.pg3.local_ip4) |
| 1598 | |
| 1599 | # |
| 1600 | # Send an acknowledgment |
| 1601 | # |
| 1602 | p_ack = (Ether(dst=self.pg3.local_mac, src=self.pg3.remote_mac) / |
| 1603 | IP(src=self.pg3.remote_ip4, dst='255.255.255.255') / |
| 1604 | UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) / |
| 1605 | BOOTP(op=1, yiaddr=self.pg3.local_ip4, |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 1606 | chaddr=mac_pton(self.pg3.local_mac)) / |
Jan Gelety | 2a3fb1a | 2018-06-27 10:56:17 +0200 | [diff] [blame] | 1607 | DHCP(options=[('message-type', 'ack'), |
| 1608 | ('subnet_mask', '255.255.255.0'), |
| 1609 | ('router', self.pg3.remote_ip4), |
| 1610 | ('server_id', self.pg3.remote_ip4), |
| 1611 | ('lease_time', lease_time), |
| 1612 | 'end'])) |
| 1613 | |
| 1614 | self.pg3.add_stream(p_ack) |
| 1615 | self.pg_enable_capture(self.pg_interfaces) |
| 1616 | self.pg_start() |
| 1617 | |
| 1618 | # |
| 1619 | # We'll get an ARP request for the router address |
| 1620 | # |
| 1621 | rx = self.pg3.get_capture(1) |
| 1622 | |
| 1623 | self.assertEqual(rx[0][ARP].pdst, self.pg3.remote_ip4) |
| 1624 | |
| 1625 | # |
| 1626 | # At the end of this procedure there should be a connected route |
| 1627 | # in the FIB |
| 1628 | # |
| 1629 | self.assertTrue(find_route(self, self.pg3.local_ip4, 32)) |
| 1630 | self.assertTrue(find_route(self, self.pg3.local_ip4, 24)) |
| 1631 | |
Jan Gelety | 2a3fb1a | 2018-06-27 10:56:17 +0200 | [diff] [blame] | 1632 | # |
Neale Ranns | f6e9b01 | 2019-01-25 06:37:15 -0800 | [diff] [blame] | 1633 | # the route should be gone after the lease expires |
Jan Gelety | 2a3fb1a | 2018-06-27 10:56:17 +0200 | [diff] [blame] | 1634 | # |
Neale Ranns | f6e9b01 | 2019-01-25 06:37:15 -0800 | [diff] [blame] | 1635 | self.assertTrue(self.wait_for_no_route(self.pg3.local_ip4, 32)) |
| 1636 | self.assertTrue(self.wait_for_no_route(self.pg3.local_ip4, 24)) |
Jan Gelety | 2a3fb1a | 2018-06-27 10:56:17 +0200 | [diff] [blame] | 1637 | |
| 1638 | # |
| 1639 | # remove the DHCP config |
| 1640 | # |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 1641 | Client.remove_vpp_config() |
Jan Gelety | 2a3fb1a | 2018-06-27 10:56:17 +0200 | [diff] [blame] | 1642 | |
Neale Ranns | 038e1df | 2019-07-19 14:01:02 +0000 | [diff] [blame] | 1643 | def test_dhcp_client_vlan(self): |
| 1644 | """ DHCP Client w/ VLAN""" |
| 1645 | |
| 1646 | vdscp = VppEnum.vl_api_ip_dscp_t |
| 1647 | vqos = VppEnum.vl_api_qos_source_t |
| 1648 | hostname = 'universal-dp' |
| 1649 | |
| 1650 | self.pg_enable_capture(self.pg_interfaces) |
| 1651 | |
| 1652 | vlan_100 = VppDot1QSubint(self, self.pg3, 100) |
| 1653 | vlan_100.admin_up() |
| 1654 | |
| 1655 | output = [scapy.compat.chb(4)] * 256 |
| 1656 | os = b''.join(output) |
| 1657 | rows = [{'outputs': os}, |
| 1658 | {'outputs': os}, |
| 1659 | {'outputs': os}, |
| 1660 | {'outputs': os}] |
| 1661 | |
| 1662 | qem1 = VppQosEgressMap(self, 1, rows).add_vpp_config() |
| 1663 | qm1 = VppQosMark(self, vlan_100, qem1, |
| 1664 | vqos.QOS_API_SOURCE_VLAN).add_vpp_config() |
| 1665 | |
| 1666 | # |
| 1667 | # Configure DHCP client on PG3 and capture the discover sent |
| 1668 | # |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 1669 | Client = VppDHCPClient( |
| 1670 | self, |
| 1671 | vlan_100.sw_if_index, |
| 1672 | hostname, |
| 1673 | dscp=vdscp.IP_API_DSCP_EF) |
| 1674 | Client.add_vpp_config() |
Neale Ranns | 038e1df | 2019-07-19 14:01:02 +0000 | [diff] [blame] | 1675 | |
| 1676 | rx = self.pg3.get_capture(1) |
| 1677 | |
| 1678 | self.assertEqual(rx[0][Dot1Q].vlan, 100) |
Prashant Maheshwari | 3bcf1a9 | 2019-07-31 21:37:33 +0530 | [diff] [blame] | 1679 | self.assertEqual(rx[0][Dot1Q].prio, 2) |
Neale Ranns | 038e1df | 2019-07-19 14:01:02 +0000 | [diff] [blame] | 1680 | |
| 1681 | self.verify_orig_dhcp_discover(rx[0], self.pg3, hostname, |
| 1682 | dscp=vdscp.IP_API_DSCP_EF) |
| 1683 | |
Neale Ranns | 808c5b2 | 2017-08-02 05:15:07 -0700 | [diff] [blame] | 1684 | |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1685 | if __name__ == '__main__': |
| 1686 | unittest.main(testRunner=VppTestRunner) |