blob: 4247a396d246d422e2d3c5cb45ec140cf2dbc262 [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Damjan Marionf56b77a2016-10-03 19:44:57 +02002
Eyal Baric4aaee12016-12-20 18:36:46 +02003import socket
Paul Vinciguerra2f156312020-05-02 22:34:40 -04004from util import ip4_range, reassemble4
Damjan Marionf56b77a2016-10-03 19:44:57 +02005import unittest
6from framework import VppTestCase, VppTestRunner
Damjan Marionf56b77a2016-10-03 19:44:57 +02007from template_bd import BridgeDomain
8
snaramre5d4b8912019-12-13 23:39:35 +00009from scapy.layers.l2 import Ether
Artem Glazychev23e5f092022-02-21 17:51:29 +070010from scapy.layers.l2 import ARP
Artem Glazychev839dcc02020-12-01 02:39:21 +070011from scapy.packet import Raw, bind_layers
Damjan Marionf56b77a2016-10-03 19:44:57 +020012from scapy.layers.inet import IP, UDP
Matej Klottondeb69842016-12-09 15:05:46 +010013from scapy.layers.vxlan import VXLAN
Paul Vinciguerra2f156312020-05-02 22:34:40 -040014
15import util
Neale Ranns097fa662018-05-01 05:17:55 -070016from vpp_ip_route import VppIpRoute, VppRoutePath
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010017from vpp_vxlan_tunnel import VppVxlanTunnel
Neale Ranns097fa662018-05-01 05:17:55 -070018from vpp_ip import INVALID_INDEX
Artem Glazychev23e5f092022-02-21 17:51:29 +070019from vpp_neighbor import VppNeighbor
Damjan Marionf56b77a2016-10-03 19:44:57 +020020
21
Klement Sekeraf62ae122016-10-11 11:47:09 +020022class TestVxlan(BridgeDomain, VppTestCase):
Damjan Marionf56b77a2016-10-03 19:44:57 +020023 """ VXLAN Test Case """
24
Damjan Marionf56b77a2016-10-03 19:44:57 +020025 def __init__(self, *args):
26 BridgeDomain.__init__(self)
Damjan Marionf56b77a2016-10-03 19:44:57 +020027 VppTestCase.__init__(self, *args)
28
Eyal Baric4aaee12016-12-20 18:36:46 +020029 def encapsulate(self, pkt, vni):
Klement Sekeraf62ae122016-10-11 11:47:09 +020030 """
31 Encapsulate the original payload frame by adding VXLAN header with its
32 UDP, IP and Ethernet fields
33 """
34 return (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) /
35 IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) /
36 UDP(sport=self.dport, dport=self.dport, chksum=0) /
Eyal Baric4aaee12016-12-20 18:36:46 +020037 VXLAN(vni=vni, flags=self.flags) /
38 pkt)
39
Eyal Baricef1e2a2018-06-18 13:01:59 +030040 def ip_range(self, start, end):
41 """ range of remote ip's """
42 return ip4_range(self.pg0.remote_ip4, start, end)
43
Eyal Baric4aaee12016-12-20 18:36:46 +020044 def encap_mcast(self, pkt, src_ip, src_mac, vni):
45 """
46 Encapsulate the original payload frame by adding VXLAN header with its
47 UDP, IP and Ethernet fields
48 """
Eyal Barid81da8c2017-01-11 13:39:54 +020049 return (Ether(src=src_mac, dst=self.mcast_mac) /
Eyal Baric4aaee12016-12-20 18:36:46 +020050 IP(src=src_ip, dst=self.mcast_ip4) /
51 UDP(sport=self.dport, dport=self.dport, chksum=0) /
52 VXLAN(vni=vni, flags=self.flags) /
Damjan Marionf56b77a2016-10-03 19:44:57 +020053 pkt)
54
Damjan Marionf56b77a2016-10-03 19:44:57 +020055 def decapsulate(self, pkt):
Klement Sekeraf62ae122016-10-11 11:47:09 +020056 """
57 Decapsulate the original payload frame by removing VXLAN header
58 """
Matej Klottondeb69842016-12-09 15:05:46 +010059 # check if is set I flag
60 self.assertEqual(pkt[VXLAN].flags, int('0x8', 16))
Damjan Marionf56b77a2016-10-03 19:44:57 +020061 return pkt[VXLAN].payload
62
Klement Sekeraf62ae122016-10-11 11:47:09 +020063 # Method for checking VXLAN encapsulation.
Damjan Marionf56b77a2016-10-03 19:44:57 +020064 #
Eyal Bari6ae5ee72017-03-23 09:53:51 +020065 def check_encapsulation(self, pkt, vni, local_only=False, mcast_pkt=False):
Damjan Marionf56b77a2016-10-03 19:44:57 +020066 # TODO: add error messages
Klement Sekeraf62ae122016-10-11 11:47:09 +020067 # Verify source MAC is VPP_MAC and destination MAC is MY_MAC resolved
Damjan Marionf56b77a2016-10-03 19:44:57 +020068 # by VPP using ARP.
Klement Sekeraf62ae122016-10-11 11:47:09 +020069 self.assertEqual(pkt[Ether].src, self.pg0.local_mac)
Eyal Baric4aaee12016-12-20 18:36:46 +020070 if not local_only:
Eyal Bari6ae5ee72017-03-23 09:53:51 +020071 if not mcast_pkt:
72 self.assertEqual(pkt[Ether].dst, self.pg0.remote_mac)
73 else:
74 self.assertEqual(pkt[Ether].dst, type(self).mcast_mac)
Klement Sekeraf62ae122016-10-11 11:47:09 +020075 # Verify VXLAN tunnel source IP is VPP_IP and destination IP is MY_IP.
76 self.assertEqual(pkt[IP].src, self.pg0.local_ip4)
Eyal Baric4aaee12016-12-20 18:36:46 +020077 if not local_only:
Eyal Bari6ae5ee72017-03-23 09:53:51 +020078 if not mcast_pkt:
79 self.assertEqual(pkt[IP].dst, self.pg0.remote_ip4)
80 else:
81 self.assertEqual(pkt[IP].dst, type(self).mcast_ip4)
Klement Sekeraf62ae122016-10-11 11:47:09 +020082 # Verify UDP destination port is VXLAN 4789, source UDP port could be
Damjan Marionf56b77a2016-10-03 19:44:57 +020083 # arbitrary.
Artem Glazychev839dcc02020-12-01 02:39:21 +070084 self.assertEqual(pkt[UDP].dport, self.dport)
Vladimir Isaev698eb872020-05-21 16:34:17 +030085 # Verify UDP checksum
86 self.assert_udp_checksum_valid(pkt)
Eyal Baric4aaee12016-12-20 18:36:46 +020087 # Verify VNI
88 self.assertEqual(pkt[VXLAN].vni, vni)
89
Eyal Baric4aaee12016-12-20 18:36:46 +020090 @classmethod
Artem Glazychev839dcc02020-12-01 02:39:21 +070091 def create_vxlan_flood_test_bd(cls, vni, n_ucast_tunnels, port):
Eyal Baric4aaee12016-12-20 18:36:46 +020092 # Create 10 ucast vxlan tunnels under bd
93 ip_range_start = 10
Eyal Barid81da8c2017-01-11 13:39:54 +020094 ip_range_end = ip_range_start + n_ucast_tunnels
Neale Ranns097fa662018-05-01 05:17:55 -070095 next_hop_address = cls.pg0.remote_ip4
96 for dest_ip4 in ip4_range(next_hop_address, ip_range_start,
97 ip_range_end):
Paul Vinciguerra2f156312020-05-02 22:34:40 -040098 # add host route so dest_ip4 will not be resolved
Neale Ranns097fa662018-05-01 05:17:55 -070099 rip = VppIpRoute(cls, dest_ip4, 32,
100 [VppRoutePath(next_hop_address,
101 INVALID_INDEX)],
102 register=False)
103 rip.add_vpp_config()
Neale Ranns097fa662018-05-01 05:17:55 -0700104
Jakub Grajciar7c0eb562020-03-02 13:55:31 +0100105 r = VppVxlanTunnel(cls, src=cls.pg0.local_ip4,
Artem Glazychev839dcc02020-12-01 02:39:21 +0700106 src_port=port, dst_port=port,
Jakub Grajciar7c0eb562020-03-02 13:55:31 +0100107 dst=dest_ip4, vni=vni)
108 r.add_vpp_config()
Neale Ranns097fa662018-05-01 05:17:55 -0700109 cls.vapi.sw_interface_set_l2_bridge(r.sw_if_index, bd_id=vni)
Eyal Baric4aaee12016-12-20 18:36:46 +0200110
111 @classmethod
Artem Glazychev839dcc02020-12-01 02:39:21 +0700112 def add_del_shared_mcast_dst_load(cls, port, is_add):
Eyal Bari4bce2902017-01-16 12:02:46 +0200113 """
114 add or del tunnels sharing the same mcast dst
115 to test vxlan ref_count mechanism
116 """
Gabriel Ganne7e665d62017-11-17 09:18:53 +0100117 n_shared_dst_tunnels = 20
Eyal Bari4bce2902017-01-16 12:02:46 +0200118 vni_start = 10000
119 vni_end = vni_start + n_shared_dst_tunnels
120 for vni in range(vni_start, vni_end):
Jakub Grajciar7c0eb562020-03-02 13:55:31 +0100121 r = VppVxlanTunnel(cls, src=cls.pg0.local_ip4,
Artem Glazychev839dcc02020-12-01 02:39:21 +0700122 src_port=port, dst_port=port,
Jakub Grajciar7c0eb562020-03-02 13:55:31 +0100123 dst=cls.mcast_ip4, mcast_sw_if_index=1, vni=vni)
124 if is_add:
125 r.add_vpp_config()
126 if r.sw_if_index == 0xffffffff:
127 raise ValueError("bad sw_if_index: ~0")
128 else:
129 r.remove_vpp_config()
Eyal Bari4bce2902017-01-16 12:02:46 +0200130
131 @classmethod
Artem Glazychev839dcc02020-12-01 02:39:21 +0700132 def add_shared_mcast_dst_load(cls, port):
133 cls.add_del_shared_mcast_dst_load(port=port, is_add=1)
Eyal Bari4bce2902017-01-16 12:02:46 +0200134
135 @classmethod
Artem Glazychev839dcc02020-12-01 02:39:21 +0700136 def del_shared_mcast_dst_load(cls, port):
137 cls.add_del_shared_mcast_dst_load(port=port, is_add=0)
Eyal Bari4bce2902017-01-16 12:02:46 +0200138
139 @classmethod
Artem Glazychev839dcc02020-12-01 02:39:21 +0700140 def add_del_mcast_tunnels_load(cls, port, is_add):
Eyal Bari4bce2902017-01-16 12:02:46 +0200141 """
142 add or del tunnels to test vxlan stability
143 """
144 n_distinct_dst_tunnels = 200
Eyal Baric4aaee12016-12-20 18:36:46 +0200145 ip_range_start = 10
Eyal Bari4bce2902017-01-16 12:02:46 +0200146 ip_range_end = ip_range_start + n_distinct_dst_tunnels
Jakub Grajciar7c0eb562020-03-02 13:55:31 +0100147 for dest_ip4 in ip4_range(cls.mcast_ip4, ip_range_start,
148 ip_range_end):
149 vni = bytearray(socket.inet_pton(socket.AF_INET, dest_ip4))[3]
150 r = VppVxlanTunnel(cls, src=cls.pg0.local_ip4,
Artem Glazychev839dcc02020-12-01 02:39:21 +0700151 src_port=port, dst_port=port,
Jakub Grajciar7c0eb562020-03-02 13:55:31 +0100152 dst=dest_ip4, mcast_sw_if_index=1, vni=vni)
153 if is_add:
154 r.add_vpp_config()
155 else:
156 r.remove_vpp_config()
Eyal Baric4aaee12016-12-20 18:36:46 +0200157
158 @classmethod
Artem Glazychev839dcc02020-12-01 02:39:21 +0700159 def add_mcast_tunnels_load(cls, port):
160 cls.add_del_mcast_tunnels_load(port=port, is_add=1)
Eyal Baric4aaee12016-12-20 18:36:46 +0200161
162 @classmethod
Artem Glazychev839dcc02020-12-01 02:39:21 +0700163 def del_mcast_tunnels_load(cls, port):
164 cls.add_del_mcast_tunnels_load(port=port, is_add=0)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200165
Klement Sekeraf62ae122016-10-11 11:47:09 +0200166 # Class method to start the VXLAN test case.
Damjan Marionf56b77a2016-10-03 19:44:57 +0200167 # Overrides setUpClass method in VppTestCase class.
168 # Python try..except statement is used to ensure that the tear down of
169 # the class will be executed even if exception is raised.
170 # @param cls The class pointer.
171 @classmethod
172 def setUpClass(cls):
173 super(TestVxlan, cls).setUpClass()
Damjan Marionf56b77a2016-10-03 19:44:57 +0200174
Klement Sekeraf62ae122016-10-11 11:47:09 +0200175 try:
Matej Klottondeb69842016-12-09 15:05:46 +0100176 cls.flags = 0x8
Klement Sekeraf62ae122016-10-11 11:47:09 +0200177
178 # Create 2 pg interfaces.
Eyal Baric4aaee12016-12-20 18:36:46 +0200179 cls.create_pg_interfaces(range(4))
180 for pg in cls.pg_interfaces:
181 pg.admin_up()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200182
183 # Configure IPv4 addresses on VPP pg0.
184 cls.pg0.config_ip4()
185
186 # Resolve MAC address for VPP's IP address on pg0.
187 cls.pg0.resolve_arp()
188
Eyal Baric4aaee12016-12-20 18:36:46 +0200189 # Our Multicast address
190 cls.mcast_ip4 = '239.1.1.1'
Paul Vinciguerra2f156312020-05-02 22:34:40 -0400191 cls.mcast_mac = util.mcast_ip_to_mac(cls.mcast_ip4)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200192 except Exception:
Paul Vinciguerra2f156312020-05-02 22:34:40 -0400193 cls.tearDownClass()
Damjan Marionf56b77a2016-10-03 19:44:57 +0200194 raise
195
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700196 @classmethod
197 def tearDownClass(cls):
198 super(TestVxlan, cls).tearDownClass()
199
Jakub Grajciar7c0eb562020-03-02 13:55:31 +0100200 def setUp(self):
201 super(TestVxlan, self).setUp()
Artem Glazychev839dcc02020-12-01 02:39:21 +0700202
203 def createVxLANInterfaces(self, port=4789):
Jakub Grajciar7c0eb562020-03-02 13:55:31 +0100204 # Create VXLAN VTEP on VPP pg0, and put vxlan_tunnel0 and pg1
205 # into BD.
Artem Glazychev839dcc02020-12-01 02:39:21 +0700206 self.dport = port
207
Neale Ranns91fd9102020-04-03 07:46:28 +0000208 self.single_tunnel_vni = 0x12345
Jakub Grajciar7c0eb562020-03-02 13:55:31 +0100209 self.single_tunnel_bd = 1
210 r = VppVxlanTunnel(self, src=self.pg0.local_ip4,
Neale Ranns91fd9102020-04-03 07:46:28 +0000211 dst=self.pg0.remote_ip4,
Artem Glazychev839dcc02020-12-01 02:39:21 +0700212 src_port=self.dport, dst_port=self.dport,
Neale Ranns91fd9102020-04-03 07:46:28 +0000213 vni=self.single_tunnel_vni)
Jakub Grajciar7c0eb562020-03-02 13:55:31 +0100214 r.add_vpp_config()
215 self.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index,
216 bd_id=self.single_tunnel_bd)
217 self.vapi.sw_interface_set_l2_bridge(
218 rx_sw_if_index=self.pg1.sw_if_index, bd_id=self.single_tunnel_bd)
219
220 # Setup vni 2 to test multicast flooding
221 self.n_ucast_tunnels = 10
222 self.mcast_flood_bd = 2
223 self.create_vxlan_flood_test_bd(self.mcast_flood_bd,
Artem Glazychev839dcc02020-12-01 02:39:21 +0700224 self.n_ucast_tunnels,
225 self.dport)
Jakub Grajciar7c0eb562020-03-02 13:55:31 +0100226 r = VppVxlanTunnel(self, src=self.pg0.local_ip4, dst=self.mcast_ip4,
Artem Glazychev839dcc02020-12-01 02:39:21 +0700227 src_port=self.dport, dst_port=self.dport,
Jakub Grajciar7c0eb562020-03-02 13:55:31 +0100228 mcast_sw_if_index=1, vni=self.mcast_flood_bd)
229 r.add_vpp_config()
230 self.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index,
231 bd_id=self.mcast_flood_bd)
232 self.vapi.sw_interface_set_l2_bridge(
233 rx_sw_if_index=self.pg2.sw_if_index, bd_id=self.mcast_flood_bd)
234
235 # Add and delete mcast tunnels to check stability
Artem Glazychev839dcc02020-12-01 02:39:21 +0700236 self.add_shared_mcast_dst_load(self.dport)
237 self.add_mcast_tunnels_load(self.dport)
238 self.del_shared_mcast_dst_load(self.dport)
239 self.del_mcast_tunnels_load(self.dport)
Jakub Grajciar7c0eb562020-03-02 13:55:31 +0100240
241 # Setup vni 3 to test unicast flooding
242 self.ucast_flood_bd = 3
243 self.create_vxlan_flood_test_bd(self.ucast_flood_bd,
Artem Glazychev839dcc02020-12-01 02:39:21 +0700244 self.n_ucast_tunnels,
245 self.dport)
Jakub Grajciar7c0eb562020-03-02 13:55:31 +0100246 self.vapi.sw_interface_set_l2_bridge(
247 rx_sw_if_index=self.pg3.sw_if_index, bd_id=self.ucast_flood_bd)
248
Artem Glazychev839dcc02020-12-01 02:39:21 +0700249 # Set scapy listen custom port for VxLAN
250 bind_layers(UDP, VXLAN, dport=self.dport)
Jakub Grajciar7c0eb562020-03-02 13:55:31 +0100251
Artem Glazychev839dcc02020-12-01 02:39:21 +0700252 def encap_big_packet(self):
Ole Troanb3655e52018-08-16 22:08:49 +0200253 self.vapi.sw_interface_set_mtu(self.pg0.sw_if_index, [1500, 0, 0, 0])
254
255 frame = (Ether(src='00:00:00:00:00:02', dst='00:00:00:00:00:01') /
256 IP(src='4.3.2.1', dst='1.2.3.4') /
257 UDP(sport=20000, dport=10000) /
Ole Troan770a0de2019-11-07 13:52:21 +0100258 Raw(b'\xa5' * 1450))
Ole Troanb3655e52018-08-16 22:08:49 +0200259
260 self.pg1.add_stream([frame])
261
262 self.pg0.enable_capture()
263
264 self.pg_start()
265
266 # Pick first received frame and check if it's correctly encapsulated.
267 out = self.pg0.get_capture(2)
268 ether = out[0]
Ole Troan7f991832018-12-06 17:35:12 +0100269 pkt = reassemble4(out)
Ole Troanb3655e52018-08-16 22:08:49 +0200270 pkt = ether / pkt
Neale Ranns91fd9102020-04-03 07:46:28 +0000271 self.check_encapsulation(pkt, self.single_tunnel_vni)
Ole Troanb3655e52018-08-16 22:08:49 +0200272
273 payload = self.decapsulate(pkt)
274 # TODO: Scapy bug?
275 # self.assert_eq_pkts(payload, frame)
276
Artem Glazychev839dcc02020-12-01 02:39:21 +0700277 """
278 Tests with default port (4789)
279 """
280 def test_decap(self):
281 """ Decapsulation test
282 from BridgeDoman
283 """
284 self.createVxLANInterfaces()
285 super(TestVxlan, self).test_decap()
286
287 def test_encap(self):
288 """ Encapsulation test
289 from BridgeDoman
290 """
291 self.createVxLANInterfaces()
292 super(TestVxlan, self).test_encap()
293
294 def test_encap_big_packet(self):
295 """ Encapsulation test send big frame from pg1
296 Verify receipt of encapsulated frames on pg0
297 """
298 self.createVxLANInterfaces()
299 self.encap_big_packet()
300
301 def test_ucast_flood(self):
302 """ Unicast flood test
303 from BridgeDoman
304 """
305 self.createVxLANInterfaces()
306 super(TestVxlan, self).test_ucast_flood()
307
308 def test_mcast_flood(self):
309 """ Multicast flood test
310 from BridgeDoman
311 """
312 self.createVxLANInterfaces()
313 super(TestVxlan, self).test_mcast_flood()
314
315 def test_mcast_rcv(self):
316 """ Multicast receive test
317 from BridgeDoman
318 """
319 self.createVxLANInterfaces()
320 super(TestVxlan, self).test_mcast_rcv()
321
322 """
323 Tests with custom port
324 """
325 def test_decap_custom_port(self):
326 """ Decapsulation test custom port
327 from BridgeDoman
328 """
329 self.createVxLANInterfaces(1111)
330 super(TestVxlan, self).test_decap()
331
332 def test_encap_custom_port(self):
333 """ Encapsulation test custom port
334 from BridgeDoman
335 """
336 self.createVxLANInterfaces(1111)
337 super(TestVxlan, self).test_encap()
338
339 def test_ucast_flood_custom_port(self):
340 """ Unicast flood test custom port
341 from BridgeDoman
342 """
343 self.createVxLANInterfaces(1111)
344 super(TestVxlan, self).test_ucast_flood()
345
346 def test_mcast_flood_custom_port(self):
347 """ Multicast flood test custom port
348 from BridgeDoman
349 """
350 self.createVxLANInterfaces(1111)
351 super(TestVxlan, self).test_mcast_flood()
352
353 def test_mcast_rcv_custom_port(self):
354 """ Multicast receive test custom port
355 from BridgeDoman
356 """
357 self.createVxLANInterfaces(1111)
358 super(TestVxlan, self).test_mcast_rcv()
359
Klement Sekeraf62ae122016-10-11 11:47:09 +0200360 # Method to define VPP actions before tear down of the test case.
Damjan Marionf56b77a2016-10-03 19:44:57 +0200361 # Overrides tearDown method in VppTestCase class.
362 # @param self The object pointer.
Artem Glazychev839dcc02020-12-01 02:39:21 +0700363
Damjan Marionf56b77a2016-10-03 19:44:57 +0200364 def tearDown(self):
365 super(TestVxlan, self).tearDown()
Paul Vinciguerra90cf21b2019-03-13 09:23:05 -0700366
367 def show_commands_at_teardown(self):
368 self.logger.info(self.vapi.cli("show bridge-domain 1 detail"))
369 self.logger.info(self.vapi.cli("show bridge-domain 2 detail"))
370 self.logger.info(self.vapi.cli("show bridge-domain 3 detail"))
371 self.logger.info(self.vapi.cli("show vxlan tunnel"))
Damjan Marionf56b77a2016-10-03 19:44:57 +0200372
Matej Klottondeb69842016-12-09 15:05:46 +0100373
Neale Ranns1b5ca982020-12-16 13:06:58 +0000374class TestVxlan2(VppTestCase):
375 """ VXLAN Test Case """
376 def setUp(self):
377 super(TestVxlan2, self).setUp()
378
379 # Create 2 pg interfaces.
380 self.create_pg_interfaces(range(4))
381 for pg in self.pg_interfaces:
382 pg.admin_up()
383
384 # Configure IPv4 addresses on VPP pg0.
385 self.pg0.config_ip4()
386 self.pg0.resolve_arp()
387
388 def tearDown(self):
389 super(TestVxlan2, self).tearDown()
390
391 def test_xconnect(self):
392 """ VXLAN source address not local """
393
394 #
395 # test the broken configuration of a VXLAN tunnel whose
396 # source address is not local ot the box. packets sent
397 # through the tunnel should be dropped
398 #
399 t = VppVxlanTunnel(self,
400 src="10.0.0.5",
401 dst=self.pg0.local_ip4,
402 vni=1000)
403 t.add_vpp_config()
404 t.admin_up()
405
406 self.vapi.sw_interface_set_l2_xconnect(t.sw_if_index,
407 self.pg1.sw_if_index,
408 enable=1)
409 self.vapi.sw_interface_set_l2_xconnect(self.pg1.sw_if_index,
410 t.sw_if_index,
411 enable=1)
412
413 p = (Ether(src="00:11:22:33:44:55",
414 dst="00:00:00:11:22:33") /
415 IP(src="4.3.2.1", dst="1.2.3.4") /
416 UDP(sport=20000, dport=10000) /
417 Raw(b'\xa5' * 1450))
418
419 rx = self.send_and_assert_no_replies(self.pg1, [p])
420
421
Artem Glazychev23e5f092022-02-21 17:51:29 +0700422class TestVxlanL2Mode(VppTestCase):
423 """ VXLAN Test Case """
424 def setUp(self):
425 super(TestVxlanL2Mode, self).setUp()
426
427 # Create 2 pg interfaces.
428 self.create_pg_interfaces(range(2))
429 for pg in self.pg_interfaces:
430 pg.admin_up()
431
432 # Configure IPv4 addresses on VPP pg0.
433 self.pg0.config_ip4()
434 self.pg0.resolve_arp()
435
436 # Configure IPv4 addresses on VPP pg1.
437 self.pg1.config_ip4()
438
439 def tearDown(self):
440 super(TestVxlanL2Mode, self).tearDown()
441
442 def test_l2_mode(self):
443 """ VXLAN L2 mode """
444 t = VppVxlanTunnel(self,
445 src=self.pg0.local_ip4,
446 dst=self.pg0.remote_ip4,
447 vni=1000, is_l3=False)
448 t.add_vpp_config()
449 t.config_ip4()
450 t.admin_up()
451
452 dstIP = t.local_ip4[:-1] + "2"
453
454 # Create a packet to send
455 p = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
456 IP(src=self.pg1.local_ip4, dst=dstIP) /
457 UDP(sport=555, dport=556) /
458 Raw(b'\x00' * 80))
459
460 # Expect ARP request
461 rx = self.send_and_expect(self.pg1, [p], self.pg0)
462 for p in rx:
463 self.assertEqual(p[Ether].dst, self.pg0.remote_mac)
464 self.assertEqual(p[Ether].src, self.pg0.local_mac)
465 self.assertEqual(p[ARP].op, 1)
466 self.assertEqual(p[ARP].pdst, dstIP)
467
468 # Resolve ARP
469 VppNeighbor(self, t.sw_if_index,
470 self.pg1.remote_mac,
471 dstIP).add_vpp_config()
472
473 # Send packets
474 NUM_PKTS = 128
475 rx = self.send_and_expect(self.pg1, p * NUM_PKTS, self.pg0)
476 self.assertEqual(NUM_PKTS, len(rx))
477
478
Damjan Marionf56b77a2016-10-03 19:44:57 +0200479if __name__ == '__main__':
480 unittest.main(testRunner=VppTestRunner)