Ole Troan | 46c1c11 | 2018-03-14 20:39:40 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | """ 6RD RFC5969 functional tests """ |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 3 | |
| 4 | import unittest |
Ole Troan | 46c1c11 | 2018-03-14 20:39:40 +0100 | [diff] [blame] | 5 | from scapy.layers.inet import IP, UDP, Ether |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 6 | from scapy.layers.inet6 import IPv6 |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 7 | from scapy.packet import Raw |
Ole Troan | 46c1c11 | 2018-03-14 20:39:40 +0100 | [diff] [blame] | 8 | from framework import VppTestCase, VppTestRunner |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 9 | from vpp_ip import DpoProto |
| 10 | from vpp_ip_route import VppIpRoute, VppRoutePath, VppIpTable |
Ole Troan | 46c1c11 | 2018-03-14 20:39:40 +0100 | [diff] [blame] | 11 | from socket import AF_INET, AF_INET6, inet_pton |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 12 | |
| 13 | """ Test6rd is a subclass of VPPTestCase classes. |
| 14 | |
| 15 | 6RD tests. |
| 16 | |
| 17 | """ |
| 18 | |
| 19 | |
| 20 | class Test6RD(VppTestCase): |
| 21 | """ 6RD Test Case """ |
| 22 | |
| 23 | @classmethod |
| 24 | def setUpClass(cls): |
| 25 | super(Test6RD, cls).setUpClass() |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 26 | cls.create_pg_interfaces(range(4)) |
Ole Troan | 46c1c11 | 2018-03-14 20:39:40 +0100 | [diff] [blame] | 27 | cls.interfaces = list(cls.pg_interfaces) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 28 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 29 | @classmethod |
| 30 | def tearDownClass(cls): |
| 31 | super(Test6RD, cls).tearDownClass() |
| 32 | |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 33 | def setUp(self): |
| 34 | super(Test6RD, self).setUp() |
| 35 | t4 = VppIpTable(self, 10) |
| 36 | t6 = VppIpTable(self, 20, True) |
| 37 | |
| 38 | t4.add_vpp_config() |
| 39 | t6.add_vpp_config() |
| 40 | |
| 41 | for n in range(4): |
| 42 | i = self.pg_interfaces[n] |
Ole Troan | 46c1c11 | 2018-03-14 20:39:40 +0100 | [diff] [blame] | 43 | i.admin_up() |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 44 | if (n > 1): |
| 45 | i.set_table_ip4(10) |
| 46 | i.set_table_ip6(20) |
Ole Troan | 46c1c11 | 2018-03-14 20:39:40 +0100 | [diff] [blame] | 47 | i.config_ip4() |
| 48 | i.config_ip6() |
| 49 | i.disable_ipv6_ra() |
| 50 | i.resolve_arp() |
| 51 | i.resolve_ndp() |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 52 | |
| 53 | def tearDown(self): |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 54 | for i in self.pg_interfaces: |
| 55 | i.unconfig_ip4() |
| 56 | i.unconfig_ip6() |
| 57 | i.set_table_ip4(0) |
| 58 | i.set_table_ip6(0) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 59 | super(Test6RD, self).tearDown() |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 60 | |
| 61 | def validate_6in4(self, rx, expected): |
| 62 | if IP not in rx: |
| 63 | self.fail() |
| 64 | if IPv6 not in rx: |
| 65 | self.fail() |
| 66 | |
| 67 | self.assertEqual(rx[IP].src, expected[IP].src) |
| 68 | self.assertEqual(rx[IP].dst, expected[IP].dst) |
| 69 | self.assertEqual(rx[IP].proto, expected[IP].proto) |
| 70 | self.assertEqual(rx[IPv6].src, expected[IPv6].src) |
| 71 | self.assertEqual(rx[IPv6].dst, expected[IPv6].dst) |
| 72 | |
| 73 | def validate_4in6(self, rx, expected): |
| 74 | if IPv6 not in rx: |
| 75 | self.fail() |
| 76 | if IP in rx: |
| 77 | self.fail() |
| 78 | |
Paul Vinciguerra | 3d2df21 | 2018-11-24 23:19:53 -0800 | [diff] [blame] | 79 | self.assertEqual(rx[IPv6].src, expected[IPv6].src) |
| 80 | self.assertEqual(rx[IPv6].dst, expected[IPv6].dst) |
| 81 | self.assertEqual(rx[IPv6].nh, expected[IPv6].nh) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 82 | |
| 83 | def payload(self, len): |
| 84 | return 'x' * len |
| 85 | |
| 86 | def test_6rd_ip6_to_ip4(self): |
| 87 | """ ip6 -> ip4 (encap) 6rd test """ |
| 88 | p_ether = Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 89 | p_ip6 = IPv6(src="1::1", dst="2002:AC10:0202::1", nh='UDP') |
| 90 | |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 91 | rv = self.vapi.ipip_6rd_add_tunnel(0, 0, inet_pton(AF_INET6, '2002::'), |
| 92 | inet_pton(AF_INET, '0.0.0.0'), |
| 93 | self.pg0.local_ip4n, 16, 0, True) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 94 | self.tunnel_index = rv.sw_if_index |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 95 | |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 96 | self.vapi.cli("show ip6 fib") |
| 97 | p_payload = UDP(sport=1234, dport=1234) |
| 98 | p = (p_ether / p_ip6 / p_payload) |
| 99 | |
| 100 | p_reply = (IP(src=self.pg0.local_ip4, dst=self.pg1.remote_ip4, |
| 101 | proto='ipv6') / p_ip6) |
| 102 | |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 103 | rx = self.send_and_expect(self.pg0, p * 10, self.pg1) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 104 | for p in rx: |
| 105 | self.validate_6in4(p, p_reply) |
| 106 | |
| 107 | # MTU tests (default is 1480) |
| 108 | plen = 1481 - 40 - 8 |
| 109 | p_ip6 = IPv6(src="1::1", dst="2002:AC10:0202::1") |
| 110 | p_payload = UDP(sport=1234, dport=1234) / Raw(self.payload(plen)) |
| 111 | p = (p_ether / p_ip6 / p_payload) |
| 112 | |
| 113 | p_reply = (IP(src=self.pg0.local_ip4, dst=self.pg1.remote_ip4, |
| 114 | proto='ipv6') / p_ip6) |
| 115 | |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 116 | rx = self.send_and_assert_no_replies(self.pg0, p * 10) |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 117 | self.vapi.ipip_6rd_del_tunnel(self.tunnel_index) |
| 118 | |
| 119 | def test_6rd_ip6_to_ip4_vrf(self): |
| 120 | """ ip6 -> ip4 (encap) 6rd VRF test """ |
| 121 | p_ether = Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
| 122 | p_ip6 = IPv6(src="1::1", dst="2002:AC10:0402::1", nh='UDP') |
| 123 | |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 124 | rv = self.vapi.ipip_6rd_add_tunnel(20, 10, |
| 125 | inet_pton(AF_INET6, '2002::'), |
| 126 | inet_pton(AF_INET, '0.0.0.0'), |
| 127 | self.pg2.local_ip4n, 16, 0, True) |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 128 | self.tunnel_index = rv.sw_if_index |
| 129 | |
| 130 | self.vapi.cli("show ip6 fib") |
| 131 | p_payload = UDP(sport=1234, dport=1234) |
| 132 | p = (p_ether / p_ip6 / p_payload) |
| 133 | |
| 134 | p_reply = (IP(src=self.pg2.local_ip4, dst=self.pg3.remote_ip4, |
| 135 | proto='ipv6') / p_ip6) |
| 136 | |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 137 | rx = self.send_and_expect(self.pg2, p * 10, self.pg3) |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 138 | for p in rx: |
| 139 | self.validate_6in4(p, p_reply) |
| 140 | |
| 141 | # MTU tests (default is 1480) |
| 142 | plen = 1481 - 40 - 8 |
| 143 | p_ip6 = IPv6(src="1::1", dst="2002:AC10:0402::1") |
| 144 | p_payload = UDP(sport=1234, dport=1234) / Raw(self.payload(plen)) |
| 145 | p = (p_ether / p_ip6 / p_payload) |
| 146 | |
| 147 | p_reply = (IP(src=self.pg2.local_ip4, dst=self.pg3.remote_ip4, |
| 148 | proto='ipv6') / p_ip6) |
| 149 | |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 150 | rx = self.send_and_assert_no_replies(self.pg0, p * 10) |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 151 | self.vapi.ipip_6rd_del_tunnel(self.tunnel_index) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 152 | |
| 153 | def test_6rd_ip4_to_ip6(self): |
| 154 | """ ip4 -> ip6 (decap) 6rd test """ |
| 155 | |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 156 | rv = self.vapi.ipip_6rd_add_tunnel(0, 0, inet_pton(AF_INET6, '2002::'), |
| 157 | inet_pton(AF_INET, '0.0.0.0'), |
| 158 | self.pg0.local_ip4n, 16, 0, True) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 159 | self.tunnel_index = rv.sw_if_index |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 160 | rv = self.vapi.ipip_6rd_del_tunnel(rv.sw_if_index) |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 161 | rv = self.vapi.ipip_6rd_add_tunnel(0, 0, inet_pton(AF_INET6, '2002::'), |
| 162 | inet_pton(AF_INET, '0.0.0.0'), |
| 163 | self.pg0.local_ip4n, 16, 0, True) |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 164 | self.tunnel_index = rv.sw_if_index |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 165 | |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 166 | p_ip6 = (IPv6(src="2002:AC10:0202::1", dst=self.pg1.remote_ip6) / |
| 167 | UDP(sport=1234, dport=1234)) |
| 168 | |
| 169 | p = (Ether(src=self.pg0.remote_mac, |
| 170 | dst=self.pg0.local_mac) / |
| 171 | IP(src=self.pg1.remote_ip4, dst=self.pg0.local_ip4) / |
| 172 | p_ip6) |
| 173 | |
| 174 | p_reply = p_ip6 |
| 175 | |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 176 | rx = self.send_and_expect(self.pg0, p * 10, self.pg1) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 177 | for p in rx: |
| 178 | self.validate_4in6(p, p_reply) |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 179 | self.vapi.ipip_6rd_del_tunnel(self.tunnel_index) |
| 180 | |
| 181 | def test_6rd_ip4_to_ip6_vrf(self): |
| 182 | """ ip4 -> ip6 (decap) 6rd VRF test """ |
| 183 | |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 184 | rv = self.vapi.ipip_6rd_add_tunnel(20, 10, |
| 185 | inet_pton(AF_INET6, '2002::'), |
| 186 | inet_pton(AF_INET, '0.0.0.0'), |
| 187 | self.pg2.local_ip4n, 16, 0, True) |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 188 | self.tunnel_index = rv.sw_if_index |
| 189 | rv = self.vapi.ipip_6rd_del_tunnel(rv.sw_if_index) |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 190 | rv = self.vapi.ipip_6rd_add_tunnel(20, 10, |
| 191 | inet_pton(AF_INET6, '2002::'), |
| 192 | inet_pton(AF_INET, '0.0.0.0'), |
| 193 | self.pg2.local_ip4n, 16, 0, True) |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 194 | self.tunnel_index = rv.sw_if_index |
| 195 | self.vapi.sw_interface_set_table(self.tunnel_index, 1, 20) |
| 196 | |
| 197 | p_ip6 = (IPv6(src="2002:AC10:0402::1", dst=self.pg3.remote_ip6) / |
| 198 | UDP(sport=1234, dport=1234)) |
| 199 | |
| 200 | p = (Ether(src=self.pg2.remote_mac, |
| 201 | dst=self.pg2.local_mac) / |
| 202 | IP(src=self.pg3.remote_ip4, dst=self.pg2.local_ip4) / |
| 203 | p_ip6) |
| 204 | |
| 205 | p_reply = p_ip6 |
| 206 | |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 207 | rx = self.send_and_expect(self.pg2, p * 10, self.pg3) |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 208 | for p in rx: |
| 209 | self.validate_4in6(p, p_reply) |
| 210 | self.vapi.sw_interface_set_table(self.tunnel_index, 1, 0) |
| 211 | self.vapi.ipip_6rd_del_tunnel(self.tunnel_index) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 212 | |
| 213 | def test_6rd_ip4_to_ip6_multiple(self): |
| 214 | """ ip4 -> ip6 (decap) 6rd test """ |
| 215 | |
| 216 | self.tunnel_index = [] |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 217 | rv = self.vapi.ipip_6rd_add_tunnel(0, 0, inet_pton(AF_INET6, '2002::'), |
| 218 | inet_pton(AF_INET, '0.0.0.0'), |
| 219 | self.pg0.local_ip4n, 16, 0, True) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 220 | self.tunnel_index.append(rv.sw_if_index) |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 221 | |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 222 | rv = self.vapi.ipip_6rd_add_tunnel(0, 0, inet_pton(AF_INET6, '2003::'), |
| 223 | inet_pton(AF_INET, '0.0.0.0'), |
| 224 | self.pg1.local_ip4n, 16, 0, True) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 225 | self.tunnel_index.append(rv.sw_if_index) |
| 226 | |
| 227 | self.vapi.cli("show ip6 fib") |
| 228 | p_ether = Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 229 | p_ip4 = IP(src=self.pg1.remote_ip4, dst=self.pg0.local_ip4) |
| 230 | p_ip6_1 = (IPv6(src="2002:AC10:0202::1", dst=self.pg1.remote_ip6) / |
| 231 | UDP(sport=1234, dport=1234)) |
| 232 | p_ip6_2 = (IPv6(src="2003:AC10:0202::1", dst=self.pg1.remote_ip6) / |
| 233 | UDP(sport=1234, dport=1234)) |
| 234 | |
| 235 | p = (p_ether / p_ip4 / p_ip6_1) |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 236 | rx = self.send_and_expect(self.pg0, p * 10, self.pg1) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 237 | for p in rx: |
| 238 | self.validate_4in6(p, p_ip6_1) |
| 239 | |
| 240 | p = (p_ether / p_ip4 / p_ip6_2) |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 241 | rx = self.send_and_expect(self.pg0, p * 10, self.pg1) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 242 | for p in rx: |
| 243 | self.validate_4in6(p, p_ip6_2) |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 244 | for i in self.tunnel_index: |
| 245 | self.vapi.ipip_6rd_del_tunnel(i) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 246 | |
| 247 | def test_6rd_ip4_to_ip6_suffix(self): |
| 248 | """ ip4 -> ip6 (decap) 6rd test """ |
| 249 | |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 250 | rv = self.vapi.ipip_6rd_add_tunnel(0, 0, inet_pton(AF_INET6, '2002::'), |
| 251 | inet_pton(AF_INET, '172.0.0.0'), |
| 252 | self.pg0.local_ip4n, 16, 8, True) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 253 | |
| 254 | self.tunnel_index = rv.sw_if_index |
| 255 | |
| 256 | self.vapi.cli("show ip6 fib") |
| 257 | p_ether = Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 258 | p_ip4 = IP(src=self.pg1.remote_ip4, dst=self.pg0.local_ip4) |
| 259 | p_ip6 = (IPv6(src="2002:1002:0200::1", dst=self.pg1.remote_ip6) / |
| 260 | UDP(sport=1234, dport=1234)) |
| 261 | |
| 262 | p = (p_ether / p_ip4 / p_ip6) |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 263 | rx = self.send_and_expect(self.pg0, p * 10, self.pg1) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 264 | for p in rx: |
| 265 | self.validate_4in6(p, p_ip6) |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 266 | self.vapi.ipip_6rd_del_tunnel(self.tunnel_index) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 267 | |
| 268 | def test_6rd_ip4_to_ip6_sec_check(self): |
| 269 | """ ip4 -> ip6 (decap) security check 6rd test """ |
| 270 | |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 271 | rv = self.vapi.ipip_6rd_add_tunnel(0, 0, inet_pton(AF_INET6, '2002::'), |
| 272 | inet_pton(AF_INET, '0.0.0.0'), |
| 273 | self.pg0.local_ip4n, 16, 0, True) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 274 | self.tunnel_index = rv.sw_if_index |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 275 | |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 276 | self.vapi.cli("show ip6 fib") |
| 277 | p_ip6 = (IPv6(src="2002:AC10:0202::1", dst=self.pg1.remote_ip6) / |
| 278 | UDP(sport=1234, dport=1234)) |
| 279 | p_ip6_fail = (IPv6(src="2002:DEAD:0202::1", dst=self.pg1.remote_ip6) / |
| 280 | UDP(sport=1234, dport=1234)) |
| 281 | |
| 282 | p = (Ether(src=self.pg0.remote_mac, |
| 283 | dst=self.pg0.local_mac) / |
| 284 | IP(src=self.pg1.remote_ip4, dst=self.pg0.local_ip4) / |
| 285 | p_ip6) |
| 286 | |
| 287 | p_reply = p_ip6 |
| 288 | |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 289 | rx = self.send_and_expect(self.pg0, p * 10, self.pg1) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 290 | for p in rx: |
| 291 | self.validate_4in6(p, p_reply) |
| 292 | |
| 293 | p = (Ether(src=self.pg0.remote_mac, |
| 294 | dst=self.pg0.local_mac) / |
| 295 | IP(src=self.pg1.remote_ip4, dst=self.pg0.local_ip4) / |
| 296 | p_ip6_fail) |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 297 | rx = self.send_and_assert_no_replies(self.pg0, p * 10) |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 298 | self.vapi.ipip_6rd_del_tunnel(self.tunnel_index) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 299 | |
| 300 | def test_6rd_bgp_tunnel(self): |
| 301 | """ 6rd BGP tunnel """ |
| 302 | |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 303 | rv = self.vapi.ipip_6rd_add_tunnel(0, 0, inet_pton(AF_INET6, '2002::'), |
| 304 | inet_pton(AF_INET, '0.0.0.0'), |
| 305 | self.pg0.local_ip4n, 16, 0, False) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 306 | self.tunnel_index = rv.sw_if_index |
| 307 | |
| 308 | default_route = VppIpRoute( |
| 309 | self, "DEAD::", 16, [VppRoutePath("2002:0808:0808::", |
| 310 | self.tunnel_index, |
| 311 | proto=DpoProto.DPO_PROTO_IP6)], |
| 312 | is_ip6=1) |
| 313 | default_route.add_vpp_config() |
| 314 | |
| 315 | ip4_route = VppIpRoute(self, "8.0.0.0", 8, |
| 316 | [VppRoutePath(self.pg1.remote_ip4, 0xFFFFFFFF)]) |
| 317 | ip4_route.add_vpp_config() |
| 318 | |
| 319 | # Via recursive route 6 -> 4 |
| 320 | p = (Ether(src=self.pg0.remote_mac, |
| 321 | dst=self.pg0.local_mac) / |
| 322 | IPv6(src="1::1", dst="DEAD:BEEF::1") / |
| 323 | UDP(sport=1234, dport=1234)) |
| 324 | |
| 325 | p_reply = (IP(src=self.pg0.local_ip4, dst="8.8.8.8", |
| 326 | proto='ipv6') / |
| 327 | IPv6(src='1::1', dst='DEAD:BEEF::1', nh='UDP')) |
| 328 | |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 329 | rx = self.send_and_expect(self.pg0, p * 10, self.pg1) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 330 | for p in rx: |
| 331 | self.validate_6in4(p, p_reply) |
| 332 | |
| 333 | # Via recursive route 4 -> 6 (Security check must be disabled) |
| 334 | p_ip6 = (IPv6(src="DEAD:BEEF::1", dst=self.pg1.remote_ip6) / |
| 335 | UDP(sport=1234, dport=1234)) |
| 336 | p = (Ether(src=self.pg0.remote_mac, |
| 337 | dst=self.pg0.local_mac) / |
| 338 | IP(src="8.8.8.8", dst=self.pg0.local_ip4) / |
| 339 | p_ip6) |
| 340 | |
| 341 | p_reply = p_ip6 |
| 342 | |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 343 | rx = self.send_and_expect(self.pg0, p * 10, self.pg1) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 344 | for p in rx: |
| 345 | self.validate_4in6(p, p_reply) |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 346 | ip4_route.remove_vpp_config() |
| 347 | default_route.remove_vpp_config() |
| 348 | self.vapi.ipip_6rd_del_tunnel(self.tunnel_index) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 349 | |
| 350 | |
| 351 | if __name__ == '__main__': |
| 352 | unittest.main(testRunner=VppTestRunner) |