blob: 858d9436384e32d25b1cf7bee8a4c92807fc169a [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Neale Ranns177bbdc2016-11-15 09:46:51 +00002
3import unittest
Neale Ranns177bbdc2016-11-15 09:46:51 +00004
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -07005import scapy.compat
Neale Ranns177bbdc2016-11-15 09:46:51 +00006from scapy.packet import Raw
Klement Sekera9225dee2016-12-12 08:36:58 +01007from scapy.layers.l2 import Ether, Dot1Q, GRE
Neale Ranns177bbdc2016-11-15 09:46:51 +00008from scapy.layers.inet import IP, UDP
Klement Sekera65cc8c02016-12-18 15:49:54 +01009from scapy.layers.inet6 import IPv6
Neale Ranns177bbdc2016-11-15 09:46:51 +000010from scapy.volatile import RandMAC, RandIP
11
Paul Vinciguerraa279d9c2019-02-28 09:00:09 -080012from framework import VppTestCase, VppTestRunner
Paul Vinciguerra95c0ca42019-03-28 13:07:00 -070013from vpp_sub_interface import L2_VTR_OP, VppDot1QSubint
Neale Ranns5a8844b2019-04-16 07:15:35 +000014from vpp_gre_interface import VppGreInterface
Neale Ranns28287212019-12-16 00:53:11 +000015from vpp_teib import VppTeib
Paul Vinciguerraa279d9c2019-02-28 09:00:09 -080016from vpp_ip import DpoProto
Neale Ranns097fa662018-05-01 05:17:55 -070017from vpp_ip_route import VppIpRoute, VppRoutePath, VppIpTable, FibPathProto
Klement Sekera9225dee2016-12-12 08:36:58 +010018from util import ppp, ppc
Neale Ranns5a8844b2019-04-16 07:15:35 +000019from vpp_papi import VppEnum
John Loa43ccae2018-02-13 17:15:23 -050020
21
Jakub Grajciarf03beca2019-05-24 08:25:03 +020022class TestGREInputNodes(VppTestCase):
23 """ GRE Input Nodes Test Case """
24
25 def setUp(self):
26 super(TestGREInputNodes, self).setUp()
27
28 # create 3 pg interfaces - set one in a non-default table.
29 self.create_pg_interfaces(range(1))
30
31 for i in self.pg_interfaces:
32 i.admin_up()
33 i.config_ip4()
34
35 def tearDown(self):
36 for i in self.pg_interfaces:
37 i.unconfig_ip4()
38 i.admin_down()
39 super(TestGREInputNodes, self).tearDown()
40
41 def test_gre_input_node(self):
42 """ GRE gre input nodes not registerd unless configured """
43 pkt = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
44 IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) /
45 GRE())
46
47 self.pg0.add_stream(pkt)
48 self.pg_start()
49 # no tunnel created, gre-input not registered
50 err = self.statistics.get_counter(
Florin Corasfa2a3162020-02-11 03:01:19 +000051 '/err/ip4-local/unknown ip protocol')[0]
Jakub Grajciarf03beca2019-05-24 08:25:03 +020052 self.assertEqual(err, 1)
53 err_count = err
54
55 # create gre tunnel
56 gre_if = VppGreInterface(self, self.pg0.local_ip4, "1.1.1.2")
57 gre_if.add_vpp_config()
58
59 self.pg0.add_stream(pkt)
60 self.pg_start()
61 # tunnel created, gre-input registered
62 err = self.statistics.get_counter(
Florin Corasfa2a3162020-02-11 03:01:19 +000063 '/err/ip4-local/unknown ip protocol')[0]
Jakub Grajciarf03beca2019-05-24 08:25:03 +020064 # expect no new errors
65 self.assertEqual(err, err_count)
66
67
Neale Ranns177bbdc2016-11-15 09:46:51 +000068class TestGRE(VppTestCase):
69 """ GRE Test Case """
70
71 @classmethod
72 def setUpClass(cls):
73 super(TestGRE, cls).setUpClass()
74
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070075 @classmethod
76 def tearDownClass(cls):
77 super(TestGRE, cls).tearDownClass()
78
Neale Ranns177bbdc2016-11-15 09:46:51 +000079 def setUp(self):
80 super(TestGRE, self).setUp()
81
Ciara Loftus7eac9162016-09-30 15:47:03 +010082 # create 3 pg interfaces - set one in a non-default table.
Neale Ranns5f8f6172019-04-18 10:23:56 +000083 self.create_pg_interfaces(range(5))
Neale Ranns15002542017-09-10 04:39:11 -070084
85 self.tbl = VppIpTable(self, 1)
86 self.tbl.add_vpp_config()
Neale Ranns177bbdc2016-11-15 09:46:51 +000087 self.pg1.set_table_ip4(1)
Ciara Loftus7eac9162016-09-30 15:47:03 +010088
Neale Ranns177bbdc2016-11-15 09:46:51 +000089 for i in self.pg_interfaces:
90 i.admin_up()
Ciara Loftus7eac9162016-09-30 15:47:03 +010091
92 self.pg0.config_ip4()
93 self.pg0.resolve_arp()
94 self.pg1.config_ip4()
95 self.pg1.resolve_arp()
96 self.pg2.config_ip6()
97 self.pg2.resolve_ndp()
Neale Ranns5f8f6172019-04-18 10:23:56 +000098 self.pg3.config_ip4()
99 self.pg3.resolve_arp()
100 self.pg4.config_ip4()
101 self.pg4.resolve_arp()
Neale Ranns177bbdc2016-11-15 09:46:51 +0000102
103 def tearDown(self):
Neale Ranns4008ac92017-02-13 23:20:04 -0800104 for i in self.pg_interfaces:
105 i.unconfig_ip4()
106 i.unconfig_ip6()
107 i.admin_down()
Neale Ranns15002542017-09-10 04:39:11 -0700108 self.pg1.set_table_ip4(0)
109 super(TestGRE, self).tearDown()
Neale Ranns177bbdc2016-11-15 09:46:51 +0000110
Neale Rannse5b94dd2019-12-31 05:13:14 +0000111 def create_stream_ip4(self, src_if, src_ip, dst_ip, dscp=0, ecn=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000112 pkts = []
Neale Rannse5b94dd2019-12-31 05:13:14 +0000113 tos = (dscp << 2) | ecn
Neale Ranns177bbdc2016-11-15 09:46:51 +0000114 for i in range(0, 257):
Klement Sekeradab231a2016-12-21 08:50:14 +0100115 info = self.create_packet_info(src_if, src_if)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000116 payload = self.info_to_payload(info)
117 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
Neale Rannse5b94dd2019-12-31 05:13:14 +0000118 IP(src=src_ip, dst=dst_ip, tos=tos) /
Neale Ranns177bbdc2016-11-15 09:46:51 +0000119 UDP(sport=1234, dport=1234) /
120 Raw(payload))
121 info.data = p.copy()
122 pkts.append(p)
123 return pkts
124
Neale Rannse5b94dd2019-12-31 05:13:14 +0000125 def create_stream_ip6(self, src_if, src_ip, dst_ip, dscp=0, ecn=0):
Ciara Loftus7eac9162016-09-30 15:47:03 +0100126 pkts = []
Neale Rannse5b94dd2019-12-31 05:13:14 +0000127 tc = (dscp << 2) | ecn
Ciara Loftus7eac9162016-09-30 15:47:03 +0100128 for i in range(0, 257):
129 info = self.create_packet_info(src_if, src_if)
130 payload = self.info_to_payload(info)
131 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
Neale Rannse5b94dd2019-12-31 05:13:14 +0000132 IPv6(src=src_ip, dst=dst_ip, tc=tc) /
Ciara Loftus7eac9162016-09-30 15:47:03 +0100133 UDP(sport=1234, dport=1234) /
134 Raw(payload))
135 info.data = p.copy()
136 pkts.append(p)
137 return pkts
138
Neale Ranns177bbdc2016-11-15 09:46:51 +0000139 def create_tunnel_stream_4o4(self, src_if,
140 tunnel_src, tunnel_dst,
141 src_ip, dst_ip):
142 pkts = []
143 for i in range(0, 257):
Klement Sekeradab231a2016-12-21 08:50:14 +0100144 info = self.create_packet_info(src_if, src_if)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000145 payload = self.info_to_payload(info)
146 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
147 IP(src=tunnel_src, dst=tunnel_dst) /
148 GRE() /
149 IP(src=src_ip, dst=dst_ip) /
150 UDP(sport=1234, dport=1234) /
151 Raw(payload))
152 info.data = p.copy()
153 pkts.append(p)
154 return pkts
155
156 def create_tunnel_stream_6o4(self, src_if,
157 tunnel_src, tunnel_dst,
158 src_ip, dst_ip):
159 pkts = []
160 for i in range(0, 257):
Klement Sekeradab231a2016-12-21 08:50:14 +0100161 info = self.create_packet_info(src_if, src_if)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000162 payload = self.info_to_payload(info)
163 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
164 IP(src=tunnel_src, dst=tunnel_dst) /
165 GRE() /
166 IPv6(src=src_ip, dst=dst_ip) /
167 UDP(sport=1234, dport=1234) /
168 Raw(payload))
169 info.data = p.copy()
170 pkts.append(p)
171 return pkts
172
Ciara Loftus7eac9162016-09-30 15:47:03 +0100173 def create_tunnel_stream_6o6(self, src_if,
174 tunnel_src, tunnel_dst,
175 src_ip, dst_ip):
176 pkts = []
177 for i in range(0, 257):
178 info = self.create_packet_info(src_if, src_if)
179 payload = self.info_to_payload(info)
180 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
181 IPv6(src=tunnel_src, dst=tunnel_dst) /
182 GRE() /
183 IPv6(src=src_ip, dst=dst_ip) /
184 UDP(sport=1234, dport=1234) /
185 Raw(payload))
186 info.data = p.copy()
187 pkts.append(p)
188 return pkts
189
Neale Ranns177bbdc2016-11-15 09:46:51 +0000190 def create_tunnel_stream_l2o4(self, src_if,
191 tunnel_src, tunnel_dst):
192 pkts = []
193 for i in range(0, 257):
Klement Sekeradab231a2016-12-21 08:50:14 +0100194 info = self.create_packet_info(src_if, src_if)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000195 payload = self.info_to_payload(info)
196 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
197 IP(src=tunnel_src, dst=tunnel_dst) /
198 GRE() /
199 Ether(dst=RandMAC('*:*:*:*:*:*'),
200 src=RandMAC('*:*:*:*:*:*')) /
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700201 IP(src=scapy.compat.raw(RandIP()),
202 dst=scapy.compat.raw(RandIP())) /
Neale Ranns177bbdc2016-11-15 09:46:51 +0000203 UDP(sport=1234, dport=1234) /
204 Raw(payload))
205 info.data = p.copy()
206 pkts.append(p)
207 return pkts
208
209 def create_tunnel_stream_vlano4(self, src_if,
210 tunnel_src, tunnel_dst, vlan):
211 pkts = []
212 for i in range(0, 257):
Klement Sekeradab231a2016-12-21 08:50:14 +0100213 info = self.create_packet_info(src_if, src_if)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000214 payload = self.info_to_payload(info)
215 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
216 IP(src=tunnel_src, dst=tunnel_dst) /
217 GRE() /
218 Ether(dst=RandMAC('*:*:*:*:*:*'),
219 src=RandMAC('*:*:*:*:*:*')) /
220 Dot1Q(vlan=vlan) /
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700221 IP(src=scapy.compat.raw(RandIP()),
222 dst=scapy.compat.raw(RandIP())) /
Neale Ranns177bbdc2016-11-15 09:46:51 +0000223 UDP(sport=1234, dport=1234) /
224 Raw(payload))
225 info.data = p.copy()
226 pkts.append(p)
227 return pkts
228
Neale Ranns177bbdc2016-11-15 09:46:51 +0000229 def verify_tunneled_4o4(self, src_if, capture, sent,
Neale Rannse5b94dd2019-12-31 05:13:14 +0000230 tunnel_src, tunnel_dst,
231 dscp=0, ecn=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000232
Neale Ranns177bbdc2016-11-15 09:46:51 +0000233 self.assertEqual(len(capture), len(sent))
Neale Rannse5b94dd2019-12-31 05:13:14 +0000234 tos = (dscp << 2) | ecn
Neale Ranns177bbdc2016-11-15 09:46:51 +0000235
236 for i in range(len(capture)):
237 try:
238 tx = sent[i]
239 rx = capture[i]
240
241 tx_ip = tx[IP]
242 rx_ip = rx[IP]
243
244 self.assertEqual(rx_ip.src, tunnel_src)
245 self.assertEqual(rx_ip.dst, tunnel_dst)
Neale Rannse5b94dd2019-12-31 05:13:14 +0000246 self.assertEqual(rx_ip.tos, tos)
Aloys Augustincf86740a2020-07-16 11:01:01 +0200247 self.assertEqual(rx_ip.len, len(rx_ip))
Neale Ranns177bbdc2016-11-15 09:46:51 +0000248
249 rx_gre = rx[GRE]
250 rx_ip = rx_gre[IP]
251
252 self.assertEqual(rx_ip.src, tx_ip.src)
253 self.assertEqual(rx_ip.dst, tx_ip.dst)
254 # IP processing post pop has decremented the TTL
255 self.assertEqual(rx_ip.ttl + 1, tx_ip.ttl)
256
257 except:
Klement Sekera9225dee2016-12-12 08:36:58 +0100258 self.logger.error(ppp("Rx:", rx))
259 self.logger.error(ppp("Tx:", tx))
Neale Ranns177bbdc2016-11-15 09:46:51 +0000260 raise
261
Ciara Loftus7eac9162016-09-30 15:47:03 +0100262 def verify_tunneled_6o6(self, src_if, capture, sent,
Neale Rannse5b94dd2019-12-31 05:13:14 +0000263 tunnel_src, tunnel_dst,
264 dscp=0, ecn=0):
Ciara Loftus7eac9162016-09-30 15:47:03 +0100265
266 self.assertEqual(len(capture), len(sent))
Neale Rannse5b94dd2019-12-31 05:13:14 +0000267 tc = (dscp << 2) | ecn
Ciara Loftus7eac9162016-09-30 15:47:03 +0100268
269 for i in range(len(capture)):
270 try:
271 tx = sent[i]
272 rx = capture[i]
273
274 tx_ip = tx[IPv6]
275 rx_ip = rx[IPv6]
276
277 self.assertEqual(rx_ip.src, tunnel_src)
278 self.assertEqual(rx_ip.dst, tunnel_dst)
Neale Rannse5b94dd2019-12-31 05:13:14 +0000279 self.assertEqual(rx_ip.tc, tc)
Ciara Loftus7eac9162016-09-30 15:47:03 +0100280
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700281 rx_gre = GRE(scapy.compat.raw(rx_ip[IPv6].payload))
Aloys Augustincf86740a2020-07-16 11:01:01 +0200282
283 self.assertEqual(rx_ip.plen, len(rx_gre))
284
Ciara Loftus7eac9162016-09-30 15:47:03 +0100285 rx_ip = rx_gre[IPv6]
286
287 self.assertEqual(rx_ip.src, tx_ip.src)
288 self.assertEqual(rx_ip.dst, tx_ip.dst)
289
290 except:
291 self.logger.error(ppp("Rx:", rx))
292 self.logger.error(ppp("Tx:", tx))
293 raise
294
Neale Ranns2646c802018-09-19 04:55:32 -0700295 def verify_tunneled_4o6(self, src_if, capture, sent,
296 tunnel_src, tunnel_dst):
297
298 self.assertEqual(len(capture), len(sent))
299
300 for i in range(len(capture)):
301 try:
302 tx = sent[i]
303 rx = capture[i]
304
305 rx_ip = rx[IPv6]
306
307 self.assertEqual(rx_ip.src, tunnel_src)
308 self.assertEqual(rx_ip.dst, tunnel_dst)
309
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700310 rx_gre = GRE(scapy.compat.raw(rx_ip[IPv6].payload))
Aloys Augustincf86740a2020-07-16 11:01:01 +0200311
312 self.assertEqual(rx_ip.plen, len(rx_gre))
313
Neale Ranns2646c802018-09-19 04:55:32 -0700314 tx_ip = tx[IP]
315 rx_ip = rx_gre[IP]
316
317 self.assertEqual(rx_ip.src, tx_ip.src)
318 self.assertEqual(rx_ip.dst, tx_ip.dst)
319
320 except:
321 self.logger.error(ppp("Rx:", rx))
322 self.logger.error(ppp("Tx:", tx))
323 raise
324
325 def verify_tunneled_6o4(self, src_if, capture, sent,
326 tunnel_src, tunnel_dst):
327
328 self.assertEqual(len(capture), len(sent))
329
330 for i in range(len(capture)):
331 try:
332 tx = sent[i]
333 rx = capture[i]
334
335 rx_ip = rx[IP]
336
337 self.assertEqual(rx_ip.src, tunnel_src)
338 self.assertEqual(rx_ip.dst, tunnel_dst)
Aloys Augustincf86740a2020-07-16 11:01:01 +0200339 self.assertEqual(rx_ip.len, len(rx_ip))
Neale Ranns2646c802018-09-19 04:55:32 -0700340
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700341 rx_gre = GRE(scapy.compat.raw(rx_ip[IP].payload))
Neale Ranns2646c802018-09-19 04:55:32 -0700342 rx_ip = rx_gre[IPv6]
343 tx_ip = tx[IPv6]
344
345 self.assertEqual(rx_ip.src, tx_ip.src)
346 self.assertEqual(rx_ip.dst, tx_ip.dst)
347
348 except:
349 self.logger.error(ppp("Rx:", rx))
350 self.logger.error(ppp("Tx:", tx))
351 raise
352
Neale Ranns177bbdc2016-11-15 09:46:51 +0000353 def verify_tunneled_l2o4(self, src_if, capture, sent,
354 tunnel_src, tunnel_dst):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000355 self.assertEqual(len(capture), len(sent))
356
357 for i in range(len(capture)):
358 try:
359 tx = sent[i]
360 rx = capture[i]
361
362 tx_ip = tx[IP]
363 rx_ip = rx[IP]
364
365 self.assertEqual(rx_ip.src, tunnel_src)
366 self.assertEqual(rx_ip.dst, tunnel_dst)
Aloys Augustincf86740a2020-07-16 11:01:01 +0200367 self.assertEqual(rx_ip.len, len(rx_ip))
Neale Ranns177bbdc2016-11-15 09:46:51 +0000368
369 rx_gre = rx[GRE]
370 rx_l2 = rx_gre[Ether]
371 rx_ip = rx_l2[IP]
372 tx_gre = tx[GRE]
373 tx_l2 = tx_gre[Ether]
374 tx_ip = tx_l2[IP]
375
376 self.assertEqual(rx_ip.src, tx_ip.src)
377 self.assertEqual(rx_ip.dst, tx_ip.dst)
378 # bridged, not L3 forwarded, so no TTL decrement
379 self.assertEqual(rx_ip.ttl, tx_ip.ttl)
380
381 except:
Klement Sekera9225dee2016-12-12 08:36:58 +0100382 self.logger.error(ppp("Rx:", rx))
383 self.logger.error(ppp("Tx:", tx))
Neale Ranns177bbdc2016-11-15 09:46:51 +0000384 raise
385
386 def verify_tunneled_vlano4(self, src_if, capture, sent,
387 tunnel_src, tunnel_dst, vlan):
388 try:
Neale Ranns177bbdc2016-11-15 09:46:51 +0000389 self.assertEqual(len(capture), len(sent))
390 except:
Klement Sekera9225dee2016-12-12 08:36:58 +0100391 ppc("Unexpected packets captured:", capture)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000392 raise
393
394 for i in range(len(capture)):
395 try:
396 tx = sent[i]
397 rx = capture[i]
398
399 tx_ip = tx[IP]
400 rx_ip = rx[IP]
401
402 self.assertEqual(rx_ip.src, tunnel_src)
403 self.assertEqual(rx_ip.dst, tunnel_dst)
404
405 rx_gre = rx[GRE]
406 rx_l2 = rx_gre[Ether]
407 rx_vlan = rx_l2[Dot1Q]
408 rx_ip = rx_l2[IP]
409
410 self.assertEqual(rx_vlan.vlan, vlan)
411
412 tx_gre = tx[GRE]
413 tx_l2 = tx_gre[Ether]
414 tx_ip = tx_l2[IP]
415
416 self.assertEqual(rx_ip.src, tx_ip.src)
417 self.assertEqual(rx_ip.dst, tx_ip.dst)
418 # bridged, not L3 forwarded, so no TTL decrement
419 self.assertEqual(rx_ip.ttl, tx_ip.ttl)
420
421 except:
Klement Sekera9225dee2016-12-12 08:36:58 +0100422 self.logger.error(ppp("Rx:", rx))
423 self.logger.error(ppp("Tx:", tx))
Neale Ranns177bbdc2016-11-15 09:46:51 +0000424 raise
425
426 def verify_decapped_4o4(self, src_if, capture, sent):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000427 self.assertEqual(len(capture), len(sent))
428
429 for i in range(len(capture)):
430 try:
431 tx = sent[i]
432 rx = capture[i]
433
434 tx_ip = tx[IP]
435 rx_ip = rx[IP]
436 tx_gre = tx[GRE]
437 tx_ip = tx_gre[IP]
438
439 self.assertEqual(rx_ip.src, tx_ip.src)
440 self.assertEqual(rx_ip.dst, tx_ip.dst)
441 # IP processing post pop has decremented the TTL
442 self.assertEqual(rx_ip.ttl + 1, tx_ip.ttl)
443
444 except:
Klement Sekera9225dee2016-12-12 08:36:58 +0100445 self.logger.error(ppp("Rx:", rx))
446 self.logger.error(ppp("Tx:", tx))
Neale Ranns177bbdc2016-11-15 09:46:51 +0000447 raise
448
449 def verify_decapped_6o4(self, src_if, capture, sent):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000450 self.assertEqual(len(capture), len(sent))
451
452 for i in range(len(capture)):
453 try:
454 tx = sent[i]
455 rx = capture[i]
456
457 tx_ip = tx[IP]
458 rx_ip = rx[IPv6]
459 tx_gre = tx[GRE]
460 tx_ip = tx_gre[IPv6]
461
462 self.assertEqual(rx_ip.src, tx_ip.src)
463 self.assertEqual(rx_ip.dst, tx_ip.dst)
464 self.assertEqual(rx_ip.hlim + 1, tx_ip.hlim)
465
466 except:
Klement Sekera9225dee2016-12-12 08:36:58 +0100467 self.logger.error(ppp("Rx:", rx))
468 self.logger.error(ppp("Tx:", tx))
Neale Ranns177bbdc2016-11-15 09:46:51 +0000469 raise
470
Neale Ranns4c16d802019-12-17 20:15:03 +0000471 def verify_decapped_6o6(self, src_if, capture, sent):
472 self.assertEqual(len(capture), len(sent))
473
474 for i in range(len(capture)):
475 try:
476 tx = sent[i]
477 rx = capture[i]
478
479 tx_ip = tx[IPv6]
480 rx_ip = rx[IPv6]
481 tx_gre = tx[GRE]
482 tx_ip = tx_gre[IPv6]
483
484 self.assertEqual(rx_ip.src, tx_ip.src)
485 self.assertEqual(rx_ip.dst, tx_ip.dst)
486 self.assertEqual(rx_ip.hlim + 1, tx_ip.hlim)
487
488 except:
489 self.logger.error(ppp("Rx:", rx))
490 self.logger.error(ppp("Tx:", tx))
491 raise
492
Neale Ranns177bbdc2016-11-15 09:46:51 +0000493 def test_gre(self):
Ciara Loftus7eac9162016-09-30 15:47:03 +0100494 """ GRE IPv4 tunnel Tests """
Neale Ranns177bbdc2016-11-15 09:46:51 +0000495
496 #
497 # Create an L3 GRE tunnel.
498 # - set it admin up
499 # - assign an IP Addres
500 # - Add a route via the tunnel
501 #
502 gre_if = VppGreInterface(self,
503 self.pg0.local_ip4,
504 "1.1.1.2")
505 gre_if.add_vpp_config()
506
507 #
508 # The double create (create the same tunnel twice) should fail,
509 # and we should still be able to use the original
510 #
511 try:
512 gre_if.add_vpp_config()
513 except Exception:
514 pass
515 else:
516 self.fail("Double GRE tunnel add does not fail")
517
518 gre_if.admin_up()
519 gre_if.config_ip4()
520
Neale Ranns5a8123b2017-01-26 01:18:23 -0800521 route_via_tun = VppIpRoute(self, "4.4.4.4", 32,
522 [VppRoutePath("0.0.0.0",
523 gre_if.sw_if_index)])
Neale Ranns177bbdc2016-11-15 09:46:51 +0000524
525 route_via_tun.add_vpp_config()
526
527 #
528 # Send a packet stream that is routed into the tunnel
Jim Thompsonf324dec2019-04-08 03:22:21 -0500529 # - they are all dropped since the tunnel's destintation IP
Neale Ranns177bbdc2016-11-15 09:46:51 +0000530 # is unresolved - or resolves via the default route - which
531 # which is a drop.
532 #
533 tx = self.create_stream_ip4(self.pg0, "5.5.5.5", "4.4.4.4")
Neale Ranns177bbdc2016-11-15 09:46:51 +0000534
Neale Ranns55882252018-11-29 08:48:37 +0000535 self.send_and_assert_no_replies(self.pg0, tx)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000536
537 #
538 # Add a route that resolves the tunnel's destination
539 #
Neale Ranns5a8123b2017-01-26 01:18:23 -0800540 route_tun_dst = VppIpRoute(self, "1.1.1.2", 32,
541 [VppRoutePath(self.pg0.remote_ip4,
542 self.pg0.sw_if_index)])
Neale Ranns177bbdc2016-11-15 09:46:51 +0000543 route_tun_dst.add_vpp_config()
544
545 #
546 # Send a packet stream that is routed into the tunnel
547 # - packets are GRE encapped
548 #
Neale Ranns177bbdc2016-11-15 09:46:51 +0000549 tx = self.create_stream_ip4(self.pg0, "5.5.5.5", "4.4.4.4")
Neale Ranns55882252018-11-29 08:48:37 +0000550 rx = self.send_and_expect(self.pg0, tx, self.pg0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000551 self.verify_tunneled_4o4(self.pg0, rx, tx,
552 self.pg0.local_ip4, "1.1.1.2")
553
554 #
555 # Send tunneled packets that match the created tunnel and
556 # are decapped and forwarded
557 #
Neale Ranns177bbdc2016-11-15 09:46:51 +0000558 tx = self.create_tunnel_stream_4o4(self.pg0,
559 "1.1.1.2",
560 self.pg0.local_ip4,
561 self.pg0.local_ip4,
562 self.pg0.remote_ip4)
Neale Ranns55882252018-11-29 08:48:37 +0000563 rx = self.send_and_expect(self.pg0, tx, self.pg0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000564 self.verify_decapped_4o4(self.pg0, rx, tx)
565
566 #
567 # Send tunneled packets that do not match the tunnel's src
568 #
569 self.vapi.cli("clear trace")
570 tx = self.create_tunnel_stream_4o4(self.pg0,
571 "1.1.1.3",
572 self.pg0.local_ip4,
573 self.pg0.local_ip4,
574 self.pg0.remote_ip4)
Neale Ranns55882252018-11-29 08:48:37 +0000575 self.send_and_assert_no_replies(
576 self.pg0, tx,
Klement Sekera9225dee2016-12-12 08:36:58 +0100577 remark="GRE packets forwarded despite no SRC address match")
Neale Ranns177bbdc2016-11-15 09:46:51 +0000578
579 #
580 # Configure IPv6 on the PG interface so we can route IPv6
581 # packets
582 #
583 self.pg0.config_ip6()
584 self.pg0.resolve_ndp()
585
586 #
587 # Send IPv6 tunnel encapslated packets
588 # - dropped since IPv6 is not enabled on the tunnel
589 #
Neale Ranns177bbdc2016-11-15 09:46:51 +0000590 tx = self.create_tunnel_stream_6o4(self.pg0,
591 "1.1.1.2",
592 self.pg0.local_ip4,
593 self.pg0.local_ip6,
594 self.pg0.remote_ip6)
Neale Ranns55882252018-11-29 08:48:37 +0000595 self.send_and_assert_no_replies(self.pg0, tx,
596 "IPv6 GRE packets forwarded "
597 "despite IPv6 not enabled on tunnel")
Neale Ranns177bbdc2016-11-15 09:46:51 +0000598
599 #
600 # Enable IPv6 on the tunnel
601 #
602 gre_if.config_ip6()
603
604 #
605 # Send IPv6 tunnel encapslated packets
606 # - forwarded since IPv6 is enabled on the tunnel
607 #
Neale Ranns177bbdc2016-11-15 09:46:51 +0000608 tx = self.create_tunnel_stream_6o4(self.pg0,
609 "1.1.1.2",
610 self.pg0.local_ip4,
611 self.pg0.local_ip6,
612 self.pg0.remote_ip6)
Neale Ranns55882252018-11-29 08:48:37 +0000613 rx = self.send_and_expect(self.pg0, tx, self.pg0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000614 self.verify_decapped_6o4(self.pg0, rx, tx)
615
616 #
Neale Ranns2646c802018-09-19 04:55:32 -0700617 # Send v6 packets for v4 encap
618 #
619 route6_via_tun = VppIpRoute(
620 self, "2001::1", 128,
621 [VppRoutePath("::",
622 gre_if.sw_if_index,
Neale Ranns097fa662018-05-01 05:17:55 -0700623 proto=DpoProto.DPO_PROTO_IP6)])
Neale Ranns2646c802018-09-19 04:55:32 -0700624 route6_via_tun.add_vpp_config()
625
626 tx = self.create_stream_ip6(self.pg0, "2001::2", "2001::1")
627 rx = self.send_and_expect(self.pg0, tx, self.pg0)
628
629 self.verify_tunneled_6o4(self.pg0, rx, tx,
630 self.pg0.local_ip4, "1.1.1.2")
631
632 #
Neale Ranns177bbdc2016-11-15 09:46:51 +0000633 # test case cleanup
634 #
635 route_tun_dst.remove_vpp_config()
636 route_via_tun.remove_vpp_config()
Neale Ranns2646c802018-09-19 04:55:32 -0700637 route6_via_tun.remove_vpp_config()
Neale Ranns177bbdc2016-11-15 09:46:51 +0000638 gre_if.remove_vpp_config()
639
640 self.pg0.unconfig_ip6()
641
Ciara Loftus7eac9162016-09-30 15:47:03 +0100642 def test_gre6(self):
643 """ GRE IPv6 tunnel Tests """
644
Neale Ranns8716e6b2017-12-13 02:47:27 -0800645 self.pg1.config_ip6()
646 self.pg1.resolve_ndp()
647
Ciara Loftus7eac9162016-09-30 15:47:03 +0100648 #
649 # Create an L3 GRE tunnel.
650 # - set it admin up
651 # - assign an IP Address
652 # - Add a route via the tunnel
653 #
Neale Ranns5a8844b2019-04-16 07:15:35 +0000654 gre_if = VppGreInterface(self,
655 self.pg2.local_ip6,
656 "1002::1")
Ciara Loftus7eac9162016-09-30 15:47:03 +0100657 gre_if.add_vpp_config()
658 gre_if.admin_up()
659 gre_if.config_ip6()
660
Neale Ranns097fa662018-05-01 05:17:55 -0700661 route_via_tun = VppIpRoute(self, "4004::1", 128,
662 [VppRoutePath("0::0",
663 gre_if.sw_if_index)])
Ciara Loftus7eac9162016-09-30 15:47:03 +0100664
665 route_via_tun.add_vpp_config()
666
667 #
668 # Send a packet stream that is routed into the tunnel
Jim Thompsonf324dec2019-04-08 03:22:21 -0500669 # - they are all dropped since the tunnel's destintation IP
Ciara Loftus7eac9162016-09-30 15:47:03 +0100670 # is unresolved - or resolves via the default route - which
671 # which is a drop.
672 #
673 tx = self.create_stream_ip6(self.pg2, "5005::1", "4004::1")
Neale Ranns55882252018-11-29 08:48:37 +0000674 self.send_and_assert_no_replies(
675 self.pg2, tx,
676 "GRE packets forwarded without DIP resolved")
Ciara Loftus7eac9162016-09-30 15:47:03 +0100677
678 #
679 # Add a route that resolves the tunnel's destination
680 #
Neale Ranns097fa662018-05-01 05:17:55 -0700681 route_tun_dst = VppIpRoute(self, "1002::1", 128,
682 [VppRoutePath(self.pg2.remote_ip6,
683 self.pg2.sw_if_index)])
Ciara Loftus7eac9162016-09-30 15:47:03 +0100684 route_tun_dst.add_vpp_config()
685
686 #
687 # Send a packet stream that is routed into the tunnel
688 # - packets are GRE encapped
689 #
Ciara Loftus7eac9162016-09-30 15:47:03 +0100690 tx = self.create_stream_ip6(self.pg2, "5005::1", "4004::1")
Neale Ranns55882252018-11-29 08:48:37 +0000691 rx = self.send_and_expect(self.pg2, tx, self.pg2)
Ciara Loftus7eac9162016-09-30 15:47:03 +0100692 self.verify_tunneled_6o6(self.pg2, rx, tx,
693 self.pg2.local_ip6, "1002::1")
694
695 #
Neale Ranns8716e6b2017-12-13 02:47:27 -0800696 # Test decap. decapped packets go out pg1
697 #
698 tx = self.create_tunnel_stream_6o6(self.pg2,
699 "1002::1",
700 self.pg2.local_ip6,
701 "2001::1",
702 self.pg1.remote_ip6)
Neale Ranns55882252018-11-29 08:48:37 +0000703 rx = self.send_and_expect(self.pg2, tx, self.pg1)
Neale Ranns8716e6b2017-12-13 02:47:27 -0800704
705 #
706 # RX'd packet is UDP over IPv6, test the GRE header is gone.
707 #
708 self.assertFalse(rx[0].haslayer(GRE))
709 self.assertEqual(rx[0][IPv6].dst, self.pg1.remote_ip6)
710
711 #
Neale Ranns2646c802018-09-19 04:55:32 -0700712 # Send v4 over v6
713 #
714 route4_via_tun = VppIpRoute(self, "1.1.1.1", 32,
715 [VppRoutePath("0.0.0.0",
716 gre_if.sw_if_index)])
717 route4_via_tun.add_vpp_config()
718
719 tx = self.create_stream_ip4(self.pg0, "1.1.1.2", "1.1.1.1")
720 rx = self.send_and_expect(self.pg0, tx, self.pg2)
721
722 self.verify_tunneled_4o6(self.pg0, rx, tx,
723 self.pg2.local_ip6, "1002::1")
724
725 #
Ciara Loftus7eac9162016-09-30 15:47:03 +0100726 # test case cleanup
727 #
728 route_tun_dst.remove_vpp_config()
729 route_via_tun.remove_vpp_config()
Neale Ranns2646c802018-09-19 04:55:32 -0700730 route4_via_tun.remove_vpp_config()
Ciara Loftus7eac9162016-09-30 15:47:03 +0100731 gre_if.remove_vpp_config()
732
733 self.pg2.unconfig_ip6()
Neale Ranns8716e6b2017-12-13 02:47:27 -0800734 self.pg1.unconfig_ip6()
Ciara Loftus7eac9162016-09-30 15:47:03 +0100735
Neale Ranns177bbdc2016-11-15 09:46:51 +0000736 def test_gre_vrf(self):
737 """ GRE tunnel VRF Tests """
738
Neale Rannse5b94dd2019-12-31 05:13:14 +0000739 e = VppEnum.vl_api_tunnel_encap_decap_flags_t
740
Neale Ranns177bbdc2016-11-15 09:46:51 +0000741 #
742 # Create an L3 GRE tunnel whose destination is in the non-default
743 # table. The underlay is thus non-default - the overlay is still
744 # the default.
745 # - set it admin up
746 # - assign an IP Addres
747 #
Neale Rannse5b94dd2019-12-31 05:13:14 +0000748 gre_if = VppGreInterface(
749 self, self.pg1.local_ip4,
750 "2.2.2.2",
751 outer_table_id=1,
752 flags=(e.TUNNEL_API_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP |
753 e.TUNNEL_API_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN))
754
Neale Ranns177bbdc2016-11-15 09:46:51 +0000755 gre_if.add_vpp_config()
756 gre_if.admin_up()
757 gre_if.config_ip4()
758
759 #
760 # Add a route via the tunnel - in the overlay
761 #
Neale Ranns5a8123b2017-01-26 01:18:23 -0800762 route_via_tun = VppIpRoute(self, "9.9.9.9", 32,
763 [VppRoutePath("0.0.0.0",
764 gre_if.sw_if_index)])
Neale Ranns177bbdc2016-11-15 09:46:51 +0000765 route_via_tun.add_vpp_config()
766
767 #
768 # Add a route that resolves the tunnel's destination - in the
769 # underlay table
770 #
Neale Ranns5a8123b2017-01-26 01:18:23 -0800771 route_tun_dst = VppIpRoute(self, "2.2.2.2", 32, table_id=1,
772 paths=[VppRoutePath(self.pg1.remote_ip4,
773 self.pg1.sw_if_index)])
Neale Ranns177bbdc2016-11-15 09:46:51 +0000774 route_tun_dst.add_vpp_config()
775
776 #
777 # Send a packet stream that is routed into the tunnel
778 # packets are sent in on pg0 which is in the default table
779 # - packets are GRE encapped
780 #
781 self.vapi.cli("clear trace")
Neale Rannse5b94dd2019-12-31 05:13:14 +0000782 tx = self.create_stream_ip4(self.pg0, "5.5.5.5", "9.9.9.9",
783 dscp=5, ecn=3)
Neale Ranns55882252018-11-29 08:48:37 +0000784 rx = self.send_and_expect(self.pg0, tx, self.pg1)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000785 self.verify_tunneled_4o4(self.pg1, rx, tx,
Neale Rannse5b94dd2019-12-31 05:13:14 +0000786 self.pg1.local_ip4, "2.2.2.2",
787 dscp=5, ecn=3)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000788
789 #
790 # Send tunneled packets that match the created tunnel and
791 # are decapped and forwarded. This tests the decap lookup
792 # does not happen in the encap table
793 #
794 self.vapi.cli("clear trace")
795 tx = self.create_tunnel_stream_4o4(self.pg1,
796 "2.2.2.2",
797 self.pg1.local_ip4,
798 self.pg0.local_ip4,
799 self.pg0.remote_ip4)
Neale Ranns55882252018-11-29 08:48:37 +0000800 rx = self.send_and_expect(self.pg1, tx, self.pg0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000801 self.verify_decapped_4o4(self.pg0, rx, tx)
802
803 #
Neale Ranns743ee3e2018-11-29 08:24:38 +0000804 # Send tunneled packets that match the created tunnel
Neale Ranns33ce60d2017-12-14 08:51:32 -0800805 # but arrive on an interface that is not in the tunnel's
Neale Ranns743ee3e2018-11-29 08:24:38 +0000806 # encap VRF, these are dropped.
807 # IP enable the interface so they aren't dropped due to
808 # IP not being enabled.
Neale Ranns33ce60d2017-12-14 08:51:32 -0800809 #
Neale Ranns743ee3e2018-11-29 08:24:38 +0000810 self.pg2.config_ip4()
Neale Ranns33ce60d2017-12-14 08:51:32 -0800811 self.vapi.cli("clear trace")
812 tx = self.create_tunnel_stream_4o4(self.pg2,
813 "2.2.2.2",
814 self.pg1.local_ip4,
815 self.pg0.local_ip4,
816 self.pg0.remote_ip4)
Neale Ranns55882252018-11-29 08:48:37 +0000817 rx = self.send_and_assert_no_replies(
818 self.pg2, tx,
819 "GRE decap packets in wrong VRF")
Neale Ranns33ce60d2017-12-14 08:51:32 -0800820
Neale Ranns743ee3e2018-11-29 08:24:38 +0000821 self.pg2.unconfig_ip4()
822
Neale Ranns33ce60d2017-12-14 08:51:32 -0800823 #
Neale Ranns177bbdc2016-11-15 09:46:51 +0000824 # test case cleanup
825 #
826 route_tun_dst.remove_vpp_config()
827 route_via_tun.remove_vpp_config()
828 gre_if.remove_vpp_config()
829
830 def test_gre_l2(self):
831 """ GRE tunnel L2 Tests """
832
833 #
834 # Add routes to resolve the tunnel destinations
835 #
Neale Ranns5a8123b2017-01-26 01:18:23 -0800836 route_tun1_dst = VppIpRoute(self, "2.2.2.2", 32,
837 [VppRoutePath(self.pg0.remote_ip4,
838 self.pg0.sw_if_index)])
839 route_tun2_dst = VppIpRoute(self, "2.2.2.3", 32,
840 [VppRoutePath(self.pg0.remote_ip4,
841 self.pg0.sw_if_index)])
Neale Ranns177bbdc2016-11-15 09:46:51 +0000842
843 route_tun1_dst.add_vpp_config()
844 route_tun2_dst.add_vpp_config()
845
846 #
847 # Create 2 L2 GRE tunnels and x-connect them
848 #
849 gre_if1 = VppGreInterface(self, self.pg0.local_ip4,
850 "2.2.2.2",
Neale Ranns5a8844b2019-04-16 07:15:35 +0000851 type=(VppEnum.vl_api_gre_tunnel_type_t.
852 GRE_API_TUNNEL_TYPE_TEB))
Neale Ranns177bbdc2016-11-15 09:46:51 +0000853 gre_if2 = VppGreInterface(self, self.pg0.local_ip4,
854 "2.2.2.3",
Neale Ranns5a8844b2019-04-16 07:15:35 +0000855 type=(VppEnum.vl_api_gre_tunnel_type_t.
856 GRE_API_TUNNEL_TYPE_TEB))
Neale Ranns177bbdc2016-11-15 09:46:51 +0000857 gre_if1.add_vpp_config()
858 gre_if2.add_vpp_config()
859
860 gre_if1.admin_up()
861 gre_if2.admin_up()
862
863 self.vapi.sw_interface_set_l2_xconnect(gre_if1.sw_if_index,
864 gre_if2.sw_if_index,
865 enable=1)
866 self.vapi.sw_interface_set_l2_xconnect(gre_if2.sw_if_index,
867 gre_if1.sw_if_index,
868 enable=1)
869
870 #
871 # Send in tunnel encapped L2. expect out tunnel encapped L2
872 # in both directions
873 #
Neale Ranns177bbdc2016-11-15 09:46:51 +0000874 tx = self.create_tunnel_stream_l2o4(self.pg0,
875 "2.2.2.2",
876 self.pg0.local_ip4)
Neale Ranns55882252018-11-29 08:48:37 +0000877 rx = self.send_and_expect(self.pg0, tx, self.pg0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000878 self.verify_tunneled_l2o4(self.pg0, rx, tx,
879 self.pg0.local_ip4,
880 "2.2.2.3")
881
Neale Ranns177bbdc2016-11-15 09:46:51 +0000882 tx = self.create_tunnel_stream_l2o4(self.pg0,
883 "2.2.2.3",
884 self.pg0.local_ip4)
Neale Ranns55882252018-11-29 08:48:37 +0000885 rx = self.send_and_expect(self.pg0, tx, self.pg0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000886 self.verify_tunneled_l2o4(self.pg0, rx, tx,
887 self.pg0.local_ip4,
888 "2.2.2.2")
889
890 self.vapi.sw_interface_set_l2_xconnect(gre_if1.sw_if_index,
891 gre_if2.sw_if_index,
892 enable=0)
893 self.vapi.sw_interface_set_l2_xconnect(gre_if2.sw_if_index,
894 gre_if1.sw_if_index,
895 enable=0)
896
897 #
898 # Create a VLAN sub-interfaces on the GRE TEB interfaces
899 # then x-connect them
900 #
901 gre_if_11 = VppDot1QSubint(self, gre_if1, 11)
902 gre_if_12 = VppDot1QSubint(self, gre_if2, 12)
903
904 # gre_if_11.add_vpp_config()
905 # gre_if_12.add_vpp_config()
906
907 gre_if_11.admin_up()
908 gre_if_12.admin_up()
909
910 self.vapi.sw_interface_set_l2_xconnect(gre_if_11.sw_if_index,
911 gre_if_12.sw_if_index,
912 enable=1)
913 self.vapi.sw_interface_set_l2_xconnect(gre_if_12.sw_if_index,
914 gre_if_11.sw_if_index,
915 enable=1)
916
917 #
918 # Configure both to pop thier respective VLAN tags,
919 # so that during the x-coonect they will subsequently push
920 #
Ole Troana5b2eec2019-03-11 19:23:25 +0100921 self.vapi.l2_interface_vlan_tag_rewrite(
922 sw_if_index=gre_if_12.sw_if_index, vtr_op=L2_VTR_OP.L2_POP_1,
923 push_dot1q=12)
924 self.vapi.l2_interface_vlan_tag_rewrite(
925 sw_if_index=gre_if_11.sw_if_index, vtr_op=L2_VTR_OP.L2_POP_1,
926 push_dot1q=11)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000927
928 #
929 # Send traffic in both directiond - expect the VLAN tags to
930 # be swapped.
931 #
Neale Ranns177bbdc2016-11-15 09:46:51 +0000932 tx = self.create_tunnel_stream_vlano4(self.pg0,
933 "2.2.2.2",
934 self.pg0.local_ip4,
935 11)
Neale Ranns55882252018-11-29 08:48:37 +0000936 rx = self.send_and_expect(self.pg0, tx, self.pg0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000937 self.verify_tunneled_vlano4(self.pg0, rx, tx,
938 self.pg0.local_ip4,
939 "2.2.2.3",
940 12)
941
Neale Ranns177bbdc2016-11-15 09:46:51 +0000942 tx = self.create_tunnel_stream_vlano4(self.pg0,
943 "2.2.2.3",
944 self.pg0.local_ip4,
945 12)
Neale Ranns55882252018-11-29 08:48:37 +0000946 rx = self.send_and_expect(self.pg0, tx, self.pg0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000947 self.verify_tunneled_vlano4(self.pg0, rx, tx,
948 self.pg0.local_ip4,
949 "2.2.2.2",
950 11)
951
952 #
953 # Cleanup Test resources
954 #
955 gre_if_11.remove_vpp_config()
956 gre_if_12.remove_vpp_config()
957 gre_if1.remove_vpp_config()
958 gre_if2.remove_vpp_config()
959 route_tun1_dst.add_vpp_config()
960 route_tun2_dst.add_vpp_config()
961
Neale Ranns521a8d72018-12-06 13:46:49 +0000962 def test_gre_loop(self):
963 """ GRE tunnel loop Tests """
964
965 #
966 # Create an L3 GRE tunnel.
967 # - set it admin up
968 # - assign an IP Addres
969 #
970 gre_if = VppGreInterface(self,
971 self.pg0.local_ip4,
972 "1.1.1.2")
973 gre_if.add_vpp_config()
974 gre_if.admin_up()
975 gre_if.config_ip4()
976
977 #
978 # add a route to the tunnel's destination that points
979 # through the tunnel, hence forming a loop in the forwarding
980 # graph
981 #
982 route_dst = VppIpRoute(self, "1.1.1.2", 32,
983 [VppRoutePath("0.0.0.0",
984 gre_if.sw_if_index)])
985 route_dst.add_vpp_config()
986
987 #
988 # packets to the tunnels destination should be dropped
989 #
990 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "1.1.1.2")
991 self.send_and_assert_no_replies(self.pg2, tx)
992
993 self.logger.info(self.vapi.ppcli("sh adj 7"))
994
995 #
996 # break the loop
997 #
998 route_dst.modify([VppRoutePath(self.pg1.remote_ip4,
999 self.pg1.sw_if_index)])
1000 route_dst.add_vpp_config()
1001
1002 rx = self.send_and_expect(self.pg0, tx, self.pg1)
1003
1004 #
1005 # a good route throught the tunnel to check it restacked
1006 #
1007 route_via_tun_2 = VppIpRoute(self, "2.2.2.2", 32,
1008 [VppRoutePath("0.0.0.0",
1009 gre_if.sw_if_index)])
1010 route_via_tun_2.add_vpp_config()
1011
1012 tx = self.create_stream_ip4(self.pg0, "2.2.2.3", "2.2.2.2")
1013 rx = self.send_and_expect(self.pg0, tx, self.pg1)
1014 self.verify_tunneled_4o4(self.pg1, rx, tx,
1015 self.pg0.local_ip4, "1.1.1.2")
1016
1017 #
1018 # cleanup
1019 #
1020 route_via_tun_2.remove_vpp_config()
1021 gre_if.remove_vpp_config()
1022
Neale Ranns5f8f6172019-04-18 10:23:56 +00001023 def test_mgre(self):
1024 """ mGRE IPv4 tunnel Tests """
1025
1026 for itf in self.pg_interfaces[3:]:
1027 #
1028 # one underlay nh for each overlay/tunnel peer
1029 #
1030 itf.generate_remote_hosts(4)
1031 itf.configure_ipv4_neighbors()
1032
1033 #
1034 # Create an L3 GRE tunnel.
1035 # - set it admin up
1036 # - assign an IP Addres
1037 # - Add a route via the tunnel
1038 #
1039 gre_if = VppGreInterface(self,
1040 itf.local_ip4,
1041 "0.0.0.0",
Neale Ranns59ff9182019-12-29 23:55:18 +00001042 mode=(VppEnum.vl_api_tunnel_mode_t.
1043 TUNNEL_API_MODE_MP))
Neale Ranns5f8f6172019-04-18 10:23:56 +00001044 gre_if.add_vpp_config()
1045 gre_if.admin_up()
1046 gre_if.config_ip4()
1047 gre_if.generate_remote_hosts(4)
1048
Neale Ranns3fd99042019-12-16 00:53:11 +00001049 self.logger.info(self.vapi.cli("sh adj"))
1050 self.logger.info(self.vapi.cli("sh ip fib"))
1051
Neale Ranns5f8f6172019-04-18 10:23:56 +00001052 #
Neale Ranns4c16d802019-12-17 20:15:03 +00001053 # ensure we don't match to the tunnel if the source address
1054 # is all zeros
1055 #
1056 tx = self.create_tunnel_stream_4o4(self.pg0,
1057 "0.0.0.0",
1058 itf.local_ip4,
1059 self.pg0.local_ip4,
1060 self.pg0.remote_ip4)
1061 self.send_and_assert_no_replies(self.pg0, tx)
1062
1063 #
Neale Ranns5f8f6172019-04-18 10:23:56 +00001064 # for-each peer
1065 #
1066 for ii in range(1, 4):
1067 route_addr = "4.4.4.%d" % ii
1068
1069 #
1070 # route traffic via the peer
1071 #
1072 route_via_tun = VppIpRoute(
1073 self, route_addr, 32,
1074 [VppRoutePath(gre_if._remote_hosts[ii].ip4,
1075 gre_if.sw_if_index)])
1076 route_via_tun.add_vpp_config()
1077
1078 #
Neale Ranns28287212019-12-16 00:53:11 +00001079 # Add a TEIB entry resolves the peer
Neale Ranns5f8f6172019-04-18 10:23:56 +00001080 #
Neale Ranns28287212019-12-16 00:53:11 +00001081 teib = VppTeib(self, gre_if,
Neale Ranns5f8f6172019-04-18 10:23:56 +00001082 gre_if._remote_hosts[ii].ip4,
1083 itf._remote_hosts[ii].ip4)
Neale Ranns03ce4622020-02-03 10:55:09 +00001084 teib.add_vpp_config()
Neale Ranns5f8f6172019-04-18 10:23:56 +00001085
1086 #
1087 # Send a packet stream that is routed into the tunnel
1088 # - packets are GRE encapped
1089 #
Neale Ranns4c16d802019-12-17 20:15:03 +00001090 tx_e = self.create_stream_ip4(self.pg0, "5.5.5.5", route_addr)
1091 rx = self.send_and_expect(self.pg0, tx_e, itf)
1092 self.verify_tunneled_4o4(self.pg0, rx, tx_e,
Neale Ranns5f8f6172019-04-18 10:23:56 +00001093 itf.local_ip4,
Neale Ranns14053c92019-12-29 23:55:18 +00001094 itf._remote_hosts[ii].ip4)
Neale Ranns5f8f6172019-04-18 10:23:56 +00001095
Neale Ranns4c16d802019-12-17 20:15:03 +00001096 tx_i = self.create_tunnel_stream_4o4(self.pg0,
1097 itf._remote_hosts[ii].ip4,
1098 itf.local_ip4,
1099 self.pg0.local_ip4,
1100 self.pg0.remote_ip4)
1101 rx = self.send_and_expect(self.pg0, tx_i, self.pg0)
1102 self.verify_decapped_4o4(self.pg0, rx, tx_i)
1103
Neale Ranns5f8f6172019-04-18 10:23:56 +00001104 #
Neale Ranns28287212019-12-16 00:53:11 +00001105 # delete and re-add the TEIB
Neale Ranns5f8f6172019-04-18 10:23:56 +00001106 #
Neale Ranns03ce4622020-02-03 10:55:09 +00001107 teib.remove_vpp_config()
Neale Ranns4c16d802019-12-17 20:15:03 +00001108 self.send_and_assert_no_replies(self.pg0, tx_e)
1109 self.send_and_assert_no_replies(self.pg0, tx_i)
Neale Ranns5f8f6172019-04-18 10:23:56 +00001110
Neale Ranns03ce4622020-02-03 10:55:09 +00001111 teib.add_vpp_config()
Neale Ranns4c16d802019-12-17 20:15:03 +00001112 rx = self.send_and_expect(self.pg0, tx_e, itf)
1113 self.verify_tunneled_4o4(self.pg0, rx, tx_e,
Neale Ranns5f8f6172019-04-18 10:23:56 +00001114 itf.local_ip4,
Neale Ranns14053c92019-12-29 23:55:18 +00001115 itf._remote_hosts[ii].ip4)
Neale Ranns4c16d802019-12-17 20:15:03 +00001116 rx = self.send_and_expect(self.pg0, tx_i, self.pg0)
1117 self.verify_decapped_4o4(self.pg0, rx, tx_i)
Neale Ranns5f8f6172019-04-18 10:23:56 +00001118
Neale Ranns3fd99042019-12-16 00:53:11 +00001119 gre_if.admin_down()
1120 gre_if.unconfig_ip4()
1121
Neale Rannse11dce22019-12-17 00:14:26 +00001122 def test_mgre6(self):
1123 """ mGRE IPv6 tunnel Tests """
1124
Neale Ranns4c16d802019-12-17 20:15:03 +00001125 self.pg0.config_ip6()
1126 self.pg0.resolve_ndp()
Neale Rannse11dce22019-12-17 00:14:26 +00001127
Neale Rannse5b94dd2019-12-31 05:13:14 +00001128 e = VppEnum.vl_api_tunnel_encap_decap_flags_t
1129
Neale Rannse11dce22019-12-17 00:14:26 +00001130 for itf in self.pg_interfaces[3:]:
1131 #
1132 # one underlay nh for each overlay/tunnel peer
1133 #
1134 itf.config_ip6()
1135 itf.generate_remote_hosts(4)
1136 itf.configure_ipv6_neighbors()
1137
1138 #
1139 # Create an L3 GRE tunnel.
1140 # - set it admin up
1141 # - assign an IP Addres
1142 # - Add a route via the tunnel
1143 #
Neale Rannse5b94dd2019-12-31 05:13:14 +00001144 gre_if = VppGreInterface(
1145 self,
1146 itf.local_ip6,
1147 "::",
1148 mode=(VppEnum.vl_api_tunnel_mode_t.
1149 TUNNEL_API_MODE_MP),
1150 flags=e.TUNNEL_API_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
1151
Neale Rannse11dce22019-12-17 00:14:26 +00001152 gre_if.add_vpp_config()
1153 gre_if.admin_up()
1154 gre_if.config_ip6()
1155 gre_if.generate_remote_hosts(4)
1156
1157 #
1158 # for-each peer
1159 #
1160 for ii in range(1, 4):
1161 route_addr = "4::%d" % ii
1162
1163 #
Neale Ranns28287212019-12-16 00:53:11 +00001164 # Add a TEIB entry resolves the peer
Neale Ranns14053c92019-12-29 23:55:18 +00001165 #
Neale Ranns28287212019-12-16 00:53:11 +00001166 teib = VppTeib(self, gre_if,
Neale Ranns14053c92019-12-29 23:55:18 +00001167 gre_if._remote_hosts[ii].ip6,
1168 itf._remote_hosts[ii].ip6)
Neale Ranns03ce4622020-02-03 10:55:09 +00001169 teib.add_vpp_config()
Neale Ranns14053c92019-12-29 23:55:18 +00001170
1171 #
Neale Rannse11dce22019-12-17 00:14:26 +00001172 # route traffic via the peer
1173 #
1174 route_via_tun = VppIpRoute(
1175 self, route_addr, 128,
1176 [VppRoutePath(gre_if._remote_hosts[ii].ip6,
1177 gre_if.sw_if_index)])
1178 route_via_tun.add_vpp_config()
1179
1180 #
Neale Rannse11dce22019-12-17 00:14:26 +00001181 # Send a packet stream that is routed into the tunnel
1182 # - packets are GRE encapped
1183 #
Neale Rannse5b94dd2019-12-31 05:13:14 +00001184 tx_e = self.create_stream_ip6(self.pg0, "5::5", route_addr,
1185 dscp=2, ecn=1)
Neale Ranns4c16d802019-12-17 20:15:03 +00001186 rx = self.send_and_expect(self.pg0, tx_e, itf)
1187 self.verify_tunneled_6o6(self.pg0, rx, tx_e,
Neale Rannse11dce22019-12-17 00:14:26 +00001188 itf.local_ip6,
Neale Rannse5b94dd2019-12-31 05:13:14 +00001189 itf._remote_hosts[ii].ip6,
1190 dscp=2)
Neale Ranns4c16d802019-12-17 20:15:03 +00001191 tx_i = self.create_tunnel_stream_6o6(self.pg0,
1192 itf._remote_hosts[ii].ip6,
1193 itf.local_ip6,
1194 self.pg0.local_ip6,
1195 self.pg0.remote_ip6)
1196 rx = self.send_and_expect(self.pg0, tx_i, self.pg0)
1197 self.verify_decapped_6o6(self.pg0, rx, tx_i)
Neale Rannse11dce22019-12-17 00:14:26 +00001198
1199 #
Neale Ranns28287212019-12-16 00:53:11 +00001200 # delete and re-add the TEIB
Neale Rannse11dce22019-12-17 00:14:26 +00001201 #
Neale Ranns03ce4622020-02-03 10:55:09 +00001202 teib.remove_vpp_config()
Neale Ranns4c16d802019-12-17 20:15:03 +00001203 self.send_and_assert_no_replies(self.pg0, tx_e)
Neale Rannse11dce22019-12-17 00:14:26 +00001204
Neale Ranns03ce4622020-02-03 10:55:09 +00001205 teib.add_vpp_config()
Neale Ranns4c16d802019-12-17 20:15:03 +00001206 rx = self.send_and_expect(self.pg0, tx_e, itf)
1207 self.verify_tunneled_6o6(self.pg0, rx, tx_e,
Neale Rannse11dce22019-12-17 00:14:26 +00001208 itf.local_ip6,
Neale Rannse5b94dd2019-12-31 05:13:14 +00001209 itf._remote_hosts[ii].ip6,
1210 dscp=2)
Neale Ranns4c16d802019-12-17 20:15:03 +00001211 rx = self.send_and_expect(self.pg0, tx_i, self.pg0)
1212 self.verify_decapped_6o6(self.pg0, rx, tx_i)
1213
Neale Rannse11dce22019-12-17 00:14:26 +00001214 gre_if.admin_down()
1215 gre_if.unconfig_ip4()
1216 itf.unconfig_ip6()
Neale Ranns4c16d802019-12-17 20:15:03 +00001217 self.pg0.unconfig_ip6()
Neale Rannse11dce22019-12-17 00:14:26 +00001218
Neale Ranns177bbdc2016-11-15 09:46:51 +00001219
1220if __name__ == '__main__':
1221 unittest.main(testRunner=VppTestRunner)