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