blob: b0ea5cfe4f4ed940e6a81d28674860945e679e80 [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002
Paul Vinciguerraa279d9c2019-02-28 09:00:09 -08003import socket
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08004import unittest
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08005
6from scapy.packet import Raw
7from scapy.layers.l2 import Ether
8from scapy.layers.ppp import PPPoE, PPPoED, PPP
Paul Vinciguerraa279d9c2019-02-28 09:00:09 -08009from scapy.layers.inet import IP
10
Dave Wallace8800f732023-08-31 00:47:44 -040011from framework import VppTestCase
12from asfframework import VppTestRunner
Paul Vinciguerraa279d9c2019-02-28 09:00:09 -080013from vpp_ip_route import VppIpRoute, VppRoutePath
14from vpp_pppoe_interface import VppPppoeInterface
Dave Wallace8800f732023-08-31 00:47:44 -040015from util import ppp
Dmitry Valter34fa0ce2024-03-11 10:38:46 +000016from config import config
Hongjun Ni62f9cdd2017-07-04 20:11:57 +080017
18
Dmitry Valter34fa0ce2024-03-11 10:38:46 +000019@unittest.skipIf("pppoe" in config.excluded_plugins, "Exclude PPPoE plugin tests")
Hongjun Ni62f9cdd2017-07-04 20:11:57 +080020class TestPPPoE(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020021 """PPPoE Test Case"""
Hongjun Ni62f9cdd2017-07-04 20:11:57 +080022
23 @classmethod
24 def setUpClass(cls):
25 super(TestPPPoE, cls).setUpClass()
26
27 cls.session_id = 1
28 cls.dst_ip = "100.1.1.100"
29 cls.dst_ipn = socket.inet_pton(socket.AF_INET, cls.dst_ip)
30
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070031 @classmethod
32 def tearDownClass(cls):
33 super(TestPPPoE, cls).tearDownClass()
34
Hongjun Ni62f9cdd2017-07-04 20:11:57 +080035 def setUp(self):
36 super(TestPPPoE, self).setUp()
37
38 # create 2 pg interfaces
39 self.create_pg_interfaces(range(3))
40
41 for i in self.pg_interfaces:
42 i.admin_up()
43 i.config_ip4()
44 i.resolve_arp()
45
46 def tearDown(self):
47 super(TestPPPoE, self).tearDown()
48
Paul Vinciguerra90cf21b2019-03-13 09:23:05 -070049 for i in self.pg_interfaces:
50 i.unconfig_ip4()
51 i.admin_down()
52
53 def show_commands_at_teardown(self):
Hongjun Ni62f9cdd2017-07-04 20:11:57 +080054 self.logger.info(self.vapi.cli("show int"))
55 self.logger.info(self.vapi.cli("show pppoe fib"))
56 self.logger.info(self.vapi.cli("show pppoe session"))
57 self.logger.info(self.vapi.cli("show ip fib"))
58 self.logger.info(self.vapi.cli("show trace"))
59
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020060 def create_stream_pppoe_discovery(self, src_if, dst_if, client_mac, count=1):
Hongjun Ni62f9cdd2017-07-04 20:11:57 +080061 packets = []
62 for i in range(count):
63 # create packet info stored in the test case instance
64 info = self.create_packet_info(src_if, dst_if)
65 # convert the info into packet payload
66 payload = self.info_to_payload(info)
67 # create the packet itself
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020068 p = (
69 Ether(dst=src_if.local_mac, src=client_mac)
70 / PPPoED(sessionid=0)
71 / Raw(payload)
72 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +080073 # store a copy of the packet in the packet info
74 info.data = p.copy()
75 # append the packet to the list
76 packets.append(p)
77
78 # return the created packet list
79 return packets
80
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020081 def create_stream_pppoe_lcp(self, src_if, dst_if, client_mac, session_id, count=1):
Hongjun Ni62f9cdd2017-07-04 20:11:57 +080082 packets = []
83 for i in range(count):
84 # create packet info stored in the test case instance
85 info = self.create_packet_info(src_if, dst_if)
86 # convert the info into packet payload
87 payload = self.info_to_payload(info)
88 # create the packet itself
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020089 p = (
90 Ether(dst=src_if.local_mac, src=client_mac)
91 / PPPoE(sessionid=session_id)
92 / PPP(proto=0xC021)
93 / Raw(payload)
94 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +080095 # store a copy of the packet in the packet info
96 info.data = p.copy()
97 # append the packet to the list
98 packets.append(p)
99
100 # return the created packet list
101 return packets
102
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200103 def create_stream_pppoe_ip4(
104 self, src_if, dst_if, client_mac, session_id, client_ip, count=1
105 ):
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800106 packets = []
107 for i in range(count):
108 # create packet info stored in the test case instance
109 info = self.create_packet_info(src_if, dst_if)
110 # convert the info into packet payload
111 payload = self.info_to_payload(info)
112 # create the packet itself
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200113 p = (
114 Ether(dst=src_if.local_mac, src=client_mac)
115 / PPPoE(sessionid=session_id)
116 / PPP(proto=0x0021)
117 / IP(src=client_ip, dst=self.dst_ip)
118 / Raw(payload)
119 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800120 # store a copy of the packet in the packet info
121 info.data = p.copy()
122 # append the packet to the list
123 packets.append(p)
124
125 # return the created packet list
126 return packets
127
128 def create_stream_ip4(self, src_if, dst_if, client_ip, dst_ip, count=1):
129 pkts = []
130 for i in range(count):
131 # create packet info stored in the test case instance
132 info = self.create_packet_info(src_if, dst_if)
133 # convert the info into packet payload
134 payload = self.info_to_payload(info)
135 # create the packet itself
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200136 p = (
137 Ether(dst=src_if.local_mac, src=src_if.remote_mac)
138 / IP(src=dst_ip, dst=client_ip)
139 / Raw(payload)
140 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800141 # store a copy of the packet in the packet info
142 info.data = p.copy()
143 # append the packet to the list
144 pkts.append(p)
145
146 # return the created packet list
147 return pkts
148
149 def verify_decapped_pppoe(self, src_if, capture, sent):
150 self.assertEqual(len(capture), len(sent))
151
152 for i in range(len(capture)):
153 try:
154 tx = sent[i]
155 rx = capture[i]
156
157 tx_ip = tx[IP]
158 rx_ip = rx[IP]
159
160 self.assertEqual(rx_ip.src, tx_ip.src)
161 self.assertEqual(rx_ip.dst, tx_ip.dst)
162
163 except:
164 self.logger.error(ppp("Rx:", rx))
165 self.logger.error(ppp("Tx:", tx))
166 raise
167
168 def verify_encaped_pppoe(self, src_if, capture, sent, session_id):
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800169 self.assertEqual(len(capture), len(sent))
170
171 for i in range(len(capture)):
172 try:
173 tx = sent[i]
174 rx = capture[i]
175
176 tx_ip = tx[IP]
177 rx_ip = rx[IP]
178
179 self.assertEqual(rx_ip.src, tx_ip.src)
180 self.assertEqual(rx_ip.dst, tx_ip.dst)
181
182 rx_pppoe = rx[PPPoE]
183
184 self.assertEqual(rx_pppoe.sessionid, session_id)
185
186 except:
187 self.logger.error(ppp("Rx:", rx))
188 self.logger.error(ppp("Tx:", tx))
189 raise
190
191 def test_PPPoE_Decap(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200192 """PPPoE Decap Test"""
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800193
194 self.vapi.cli("clear trace")
195
196 #
197 # Add a route that resolves the server's destination
198 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200199 route_sever_dst = VppIpRoute(
200 self,
201 "100.1.1.100",
202 32,
203 [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index)],
204 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800205 route_sever_dst.add_vpp_config()
206
207 # Send PPPoE Discovery
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200208 tx0 = self.create_stream_pppoe_discovery(
209 self.pg0, self.pg1, self.pg0.remote_mac
210 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800211 self.pg0.add_stream(tx0)
212 self.pg_start()
213
214 # Send PPPoE PPP LCP
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200215 tx1 = self.create_stream_pppoe_lcp(
216 self.pg0, self.pg1, self.pg0.remote_mac, self.session_id
217 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800218 self.pg0.add_stream(tx1)
219 self.pg_start()
220
221 # Create PPPoE session
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200222 pppoe_if = VppPppoeInterface(
223 self, self.pg0.remote_ip4, self.pg0.remote_mac, self.session_id
224 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800225 pppoe_if.add_vpp_config()
Stanislav Zaikin938af5e2020-12-03 19:09:53 +0000226 pppoe_if.set_unnumbered(self.pg0.sw_if_index)
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800227 #
228 # Send tunneled packets that match the created tunnel and
229 # are decapped and forwarded
230 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200231 tx2 = self.create_stream_pppoe_ip4(
232 self.pg0,
233 self.pg1,
234 self.pg0.remote_mac,
235 self.session_id,
236 self.pg0.remote_ip4,
237 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800238 self.pg0.add_stream(tx2)
239
240 self.pg_enable_capture(self.pg_interfaces)
241 self.pg_start()
242
243 rx2 = self.pg1.get_capture(len(tx2))
244 self.verify_decapped_pppoe(self.pg0, rx2, tx2)
245
246 self.logger.info(self.vapi.cli("show pppoe fib"))
247 self.logger.info(self.vapi.cli("show pppoe session"))
248 self.logger.info(self.vapi.cli("show ip fib"))
249
250 #
251 # test case cleanup
252 #
253
254 # Delete PPPoE session
255 pppoe_if.remove_vpp_config()
256
257 # Delete a route that resolves the server's destination
258 route_sever_dst.remove_vpp_config()
259
260 def test_PPPoE_Encap(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200261 """PPPoE Encap Test"""
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800262
263 self.vapi.cli("clear trace")
264
265 #
266 # Add a route that resolves the server's destination
267 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200268 route_sever_dst = VppIpRoute(
269 self,
270 "100.1.1.100",
271 32,
272 [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index)],
273 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800274 route_sever_dst.add_vpp_config()
275
276 # Send PPPoE Discovery
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200277 tx0 = self.create_stream_pppoe_discovery(
278 self.pg0, self.pg1, self.pg0.remote_mac
279 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800280 self.pg0.add_stream(tx0)
281 self.pg_start()
282
283 # Send PPPoE PPP LCP
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200284 tx1 = self.create_stream_pppoe_lcp(
285 self.pg0, self.pg1, self.pg0.remote_mac, self.session_id
286 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800287 self.pg0.add_stream(tx1)
288 self.pg_start()
289
290 # Create PPPoE session
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200291 pppoe_if = VppPppoeInterface(
292 self, self.pg0.remote_ip4, self.pg0.remote_mac, self.session_id
293 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800294 pppoe_if.add_vpp_config()
Stanislav Zaikin938af5e2020-12-03 19:09:53 +0000295 pppoe_if.set_unnumbered(self.pg0.sw_if_index)
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800296
297 #
298 # Send a packet stream that is routed into the session
299 # - packets are PPPoE encapped
300 #
301 self.vapi.cli("clear trace")
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200302 tx2 = self.create_stream_ip4(
303 self.pg1, self.pg0, self.pg0.remote_ip4, self.dst_ip, 65
304 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800305 self.pg1.add_stream(tx2)
306
307 self.pg_enable_capture(self.pg_interfaces)
308 self.pg_start()
309
310 rx2 = self.pg0.get_capture(len(tx2))
311 self.verify_encaped_pppoe(self.pg1, rx2, tx2, self.session_id)
312
313 self.logger.info(self.vapi.cli("show pppoe fib"))
314 self.logger.info(self.vapi.cli("show pppoe session"))
315 self.logger.info(self.vapi.cli("show ip fib"))
Neale Ranns43161a82017-08-12 02:12:00 -0700316 self.logger.info(self.vapi.cli("show adj"))
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800317
318 #
319 # test case cleanup
320 #
321
322 # Delete PPPoE session
323 pppoe_if.remove_vpp_config()
324
325 # Delete a route that resolves the server's destination
326 route_sever_dst.remove_vpp_config()
327
328 def test_PPPoE_Add_Twice(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200329 """PPPoE Add Same Session Twice Test"""
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800330
331 self.vapi.cli("clear trace")
332
333 #
334 # Add a route that resolves the server's destination
335 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200336 route_sever_dst = VppIpRoute(
337 self,
338 "100.1.1.100",
339 32,
340 [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index)],
341 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800342 route_sever_dst.add_vpp_config()
343
344 # Send PPPoE Discovery
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200345 tx0 = self.create_stream_pppoe_discovery(
346 self.pg0, self.pg1, self.pg0.remote_mac
347 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800348 self.pg0.add_stream(tx0)
349 self.pg_start()
350
351 # Send PPPoE PPP LCP
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200352 tx1 = self.create_stream_pppoe_lcp(
353 self.pg0, self.pg1, self.pg0.remote_mac, self.session_id
354 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800355 self.pg0.add_stream(tx1)
356 self.pg_start()
357
358 # Create PPPoE session
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200359 pppoe_if = VppPppoeInterface(
360 self, self.pg0.remote_ip4, self.pg0.remote_mac, self.session_id
361 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800362 pppoe_if.add_vpp_config()
Stanislav Zaikin938af5e2020-12-03 19:09:53 +0000363 pppoe_if.set_unnumbered(self.pg0.sw_if_index)
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800364
365 #
366 # The double create (create the same session twice) should fail,
367 # and we should still be able to use the original
368 #
369 try:
Hongjun Niad2ddb12017-11-17 23:43:11 +0800370 pppoe_if.add_vpp_config()
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800371 except Exception:
372 pass
373 else:
374 self.fail("Double GRE tunnel add does not fail")
375
376 #
377 # test case cleanup
378 #
379
380 # Delete PPPoE session
381 pppoe_if.remove_vpp_config()
382
383 # Delete a route that resolves the server's destination
384 route_sever_dst.remove_vpp_config()
385
386 def test_PPPoE_Del_Twice(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200387 """PPPoE Delete Same Session Twice Test"""
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800388
389 self.vapi.cli("clear trace")
390
391 #
392 # Add a route that resolves the server's destination
393 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200394 route_sever_dst = VppIpRoute(
395 self,
396 "100.1.1.100",
397 32,
398 [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index)],
399 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800400 route_sever_dst.add_vpp_config()
401
402 # Send PPPoE Discovery
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200403 tx0 = self.create_stream_pppoe_discovery(
404 self.pg0, self.pg1, self.pg0.remote_mac
405 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800406 self.pg0.add_stream(tx0)
407 self.pg_start()
408
409 # Send PPPoE PPP LCP
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200410 tx1 = self.create_stream_pppoe_lcp(
411 self.pg0, self.pg1, self.pg0.remote_mac, self.session_id
412 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800413 self.pg0.add_stream(tx1)
414 self.pg_start()
415
416 # Create PPPoE session
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200417 pppoe_if = VppPppoeInterface(
418 self, self.pg0.remote_ip4, self.pg0.remote_mac, self.session_id
419 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800420 pppoe_if.add_vpp_config()
421
422 # Delete PPPoE session
423 pppoe_if.remove_vpp_config()
424
425 #
426 # The double del (del the same session twice) should fail,
427 # and we should still be able to use the original
428 #
429 try:
Hongjun Niad2ddb12017-11-17 23:43:11 +0800430 pppoe_if.remove_vpp_config()
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800431 except Exception:
432 pass
433 else:
434 self.fail("Double GRE tunnel del does not fail")
435
436 #
437 # test case cleanup
438 #
439
440 # Delete a route that resolves the server's destination
441 route_sever_dst.remove_vpp_config()
442
443 def test_PPPoE_Decap_Multiple(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200444 """PPPoE Decap Multiple Sessions Test"""
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800445
446 self.vapi.cli("clear trace")
447
448 #
449 # Add a route that resolves the server's destination
450 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200451 route_sever_dst = VppIpRoute(
452 self,
453 "100.1.1.100",
454 32,
455 [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index)],
456 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800457 route_sever_dst.add_vpp_config()
458
459 # Send PPPoE Discovery 1
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200460 tx0 = self.create_stream_pppoe_discovery(
461 self.pg0, self.pg1, self.pg0.remote_mac
462 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800463 self.pg0.add_stream(tx0)
464 self.pg_start()
465
466 # Send PPPoE PPP LCP 1
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200467 tx1 = self.create_stream_pppoe_lcp(
468 self.pg0, self.pg1, self.pg0.remote_mac, self.session_id
469 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800470 self.pg0.add_stream(tx1)
471 self.pg_start()
472
473 # Create PPPoE session 1
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200474 pppoe_if1 = VppPppoeInterface(
475 self, self.pg0.remote_ip4, self.pg0.remote_mac, self.session_id
476 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800477 pppoe_if1.add_vpp_config()
Stanislav Zaikin938af5e2020-12-03 19:09:53 +0000478 pppoe_if1.set_unnumbered(self.pg0.sw_if_index)
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800479
480 # Send PPPoE Discovery 2
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200481 tx3 = self.create_stream_pppoe_discovery(
482 self.pg2, self.pg1, self.pg2.remote_mac
483 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800484 self.pg2.add_stream(tx3)
485 self.pg_start()
486
487 # Send PPPoE PPP LCP 2
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200488 tx4 = self.create_stream_pppoe_lcp(
489 self.pg2, self.pg1, self.pg2.remote_mac, self.session_id + 1
490 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800491 self.pg2.add_stream(tx4)
492 self.pg_start()
493
494 # Create PPPoE session 2
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200495 pppoe_if2 = VppPppoeInterface(
496 self, self.pg2.remote_ip4, self.pg2.remote_mac, self.session_id + 1
497 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800498 pppoe_if2.add_vpp_config()
Stanislav Zaikin938af5e2020-12-03 19:09:53 +0000499 pppoe_if2.set_unnumbered(self.pg0.sw_if_index)
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800500
501 #
502 # Send tunneled packets that match the created tunnel and
503 # are decapped and forwarded
504 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200505 tx2 = self.create_stream_pppoe_ip4(
506 self.pg0,
507 self.pg1,
508 self.pg0.remote_mac,
509 self.session_id,
510 self.pg0.remote_ip4,
511 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800512 self.pg0.add_stream(tx2)
513
514 self.pg_enable_capture(self.pg_interfaces)
515 self.pg_start()
516
517 rx2 = self.pg1.get_capture(len(tx2))
518 self.verify_decapped_pppoe(self.pg0, rx2, tx2)
519
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200520 tx5 = self.create_stream_pppoe_ip4(
521 self.pg2,
522 self.pg1,
523 self.pg2.remote_mac,
524 self.session_id + 1,
525 self.pg2.remote_ip4,
526 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800527 self.pg2.add_stream(tx5)
528
529 self.pg_enable_capture(self.pg_interfaces)
530 self.pg_start()
531
532 rx5 = self.pg1.get_capture(len(tx5))
533 self.verify_decapped_pppoe(self.pg2, rx5, tx5)
534
535 self.logger.info(self.vapi.cli("show pppoe fib"))
536 self.logger.info(self.vapi.cli("show pppoe session"))
537 self.logger.info(self.vapi.cli("show ip fib"))
538
539 #
540 # test case cleanup
541 #
542
543 # Delete PPPoE session
544 pppoe_if1.remove_vpp_config()
545 pppoe_if2.remove_vpp_config()
546
547 # Delete a route that resolves the server's destination
548 route_sever_dst.remove_vpp_config()
549
550 def test_PPPoE_Encap_Multiple(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200551 """PPPoE Encap Multiple Sessions Test"""
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800552
553 self.vapi.cli("clear trace")
554
555 #
556 # Add a route that resolves the server's destination
557 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200558 route_sever_dst = VppIpRoute(
559 self,
560 "100.1.1.100",
561 32,
562 [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index)],
563 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800564 route_sever_dst.add_vpp_config()
565
566 # Send PPPoE Discovery 1
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200567 tx0 = self.create_stream_pppoe_discovery(
568 self.pg0, self.pg1, self.pg0.remote_mac
569 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800570 self.pg0.add_stream(tx0)
571 self.pg_start()
572
573 # Send PPPoE PPP LCP 1
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200574 tx1 = self.create_stream_pppoe_lcp(
575 self.pg0, self.pg1, self.pg0.remote_mac, self.session_id
576 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800577 self.pg0.add_stream(tx1)
578 self.pg_start()
579
580 # Create PPPoE session 1
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200581 pppoe_if1 = VppPppoeInterface(
582 self, self.pg0.remote_ip4, self.pg0.remote_mac, self.session_id
583 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800584 pppoe_if1.add_vpp_config()
585
586 # Send PPPoE Discovery 2
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200587 tx3 = self.create_stream_pppoe_discovery(
588 self.pg2, self.pg1, self.pg2.remote_mac
589 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800590 self.pg2.add_stream(tx3)
591 self.pg_start()
592
593 # Send PPPoE PPP LCP 2
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200594 tx4 = self.create_stream_pppoe_lcp(
595 self.pg2, self.pg1, self.pg2.remote_mac, self.session_id + 1
596 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800597 self.pg2.add_stream(tx4)
598 self.pg_start()
599
600 # Create PPPoE session 2
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200601 pppoe_if2 = VppPppoeInterface(
602 self, self.pg2.remote_ip4, self.pg2.remote_mac, self.session_id + 1
603 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800604 pppoe_if2.add_vpp_config()
605
606 #
607 # Send a packet stream that is routed into the session
608 # - packets are PPPoE encapped
609 #
610 self.vapi.cli("clear trace")
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200611 tx2 = self.create_stream_ip4(
612 self.pg1, self.pg0, self.pg0.remote_ip4, self.dst_ip
613 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800614 self.pg1.add_stream(tx2)
615
616 self.pg_enable_capture(self.pg_interfaces)
617 self.pg_start()
618
619 rx2 = self.pg0.get_capture(len(tx2))
620 self.verify_encaped_pppoe(self.pg1, rx2, tx2, self.session_id)
621
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200622 tx5 = self.create_stream_ip4(
623 self.pg1, self.pg2, self.pg2.remote_ip4, self.dst_ip
624 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800625 self.pg1.add_stream(tx5)
626
627 self.pg_enable_capture(self.pg_interfaces)
628 self.pg_start()
629
630 rx5 = self.pg2.get_capture(len(tx5))
631 self.verify_encaped_pppoe(self.pg1, rx5, tx5, self.session_id + 1)
632
633 self.logger.info(self.vapi.cli("show pppoe fib"))
634 self.logger.info(self.vapi.cli("show pppoe session"))
635 self.logger.info(self.vapi.cli("show ip fib"))
636
637 #
638 # test case cleanup
639 #
640
641 # Delete PPPoE session
642 pppoe_if1.remove_vpp_config()
643 pppoe_if2.remove_vpp_config()
644
645 # Delete a route that resolves the server's destination
646 route_sever_dst.remove_vpp_config()
647
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200648
649if __name__ == "__main__":
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800650 unittest.main(testRunner=VppTestRunner)