blob: 4a6a0251b9f7c2bf7f26a47f59239a7b24d37850 [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 #
229 # Send tunneled packets that match the created tunnel and
230 # are decapped and forwarded
231 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200232 tx2 = self.create_stream_pppoe_ip4(
233 self.pg0,
234 self.pg1,
235 self.pg0.remote_mac,
236 self.session_id,
237 self.pg0.remote_ip4,
238 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800239 self.pg0.add_stream(tx2)
240
241 self.pg_enable_capture(self.pg_interfaces)
242 self.pg_start()
243
244 rx2 = self.pg1.get_capture(len(tx2))
245 self.verify_decapped_pppoe(self.pg0, rx2, tx2)
246
247 self.logger.info(self.vapi.cli("show pppoe fib"))
248 self.logger.info(self.vapi.cli("show pppoe session"))
249 self.logger.info(self.vapi.cli("show ip fib"))
250
251 #
252 # test case cleanup
253 #
254
255 # Delete PPPoE session
256 pppoe_if.remove_vpp_config()
257
258 # Delete a route that resolves the server's destination
259 route_sever_dst.remove_vpp_config()
260
261 def test_PPPoE_Encap(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200262 """PPPoE Encap Test"""
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800263
264 self.vapi.cli("clear trace")
265
266 #
267 # Add a route that resolves the server's destination
268 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200269 route_sever_dst = VppIpRoute(
270 self,
271 "100.1.1.100",
272 32,
273 [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index)],
274 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800275 route_sever_dst.add_vpp_config()
276
277 # Send PPPoE Discovery
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200278 tx0 = self.create_stream_pppoe_discovery(
279 self.pg0, self.pg1, self.pg0.remote_mac
280 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800281 self.pg0.add_stream(tx0)
282 self.pg_start()
283
284 # Send PPPoE PPP LCP
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200285 tx1 = self.create_stream_pppoe_lcp(
286 self.pg0, self.pg1, self.pg0.remote_mac, self.session_id
287 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800288 self.pg0.add_stream(tx1)
289 self.pg_start()
290
291 # Create PPPoE session
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200292 pppoe_if = VppPppoeInterface(
293 self, self.pg0.remote_ip4, self.pg0.remote_mac, self.session_id
294 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800295 pppoe_if.add_vpp_config()
Stanislav Zaikin938af5e2020-12-03 19:09:53 +0000296 pppoe_if.set_unnumbered(self.pg0.sw_if_index)
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800297
298 #
299 # Send a packet stream that is routed into the session
300 # - packets are PPPoE encapped
301 #
302 self.vapi.cli("clear trace")
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200303 tx2 = self.create_stream_ip4(
304 self.pg1, self.pg0, self.pg0.remote_ip4, self.dst_ip, 65
305 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800306 self.pg1.add_stream(tx2)
307
308 self.pg_enable_capture(self.pg_interfaces)
309 self.pg_start()
310
311 rx2 = self.pg0.get_capture(len(tx2))
312 self.verify_encaped_pppoe(self.pg1, rx2, tx2, self.session_id)
313
314 self.logger.info(self.vapi.cli("show pppoe fib"))
315 self.logger.info(self.vapi.cli("show pppoe session"))
316 self.logger.info(self.vapi.cli("show ip fib"))
Neale Ranns43161a82017-08-12 02:12:00 -0700317 self.logger.info(self.vapi.cli("show adj"))
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800318
319 #
320 # test case cleanup
321 #
322
323 # Delete PPPoE session
324 pppoe_if.remove_vpp_config()
325
326 # Delete a route that resolves the server's destination
327 route_sever_dst.remove_vpp_config()
328
329 def test_PPPoE_Add_Twice(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200330 """PPPoE Add Same Session Twice Test"""
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800331
332 self.vapi.cli("clear trace")
333
334 #
335 # Add a route that resolves the server's destination
336 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200337 route_sever_dst = VppIpRoute(
338 self,
339 "100.1.1.100",
340 32,
341 [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index)],
342 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800343 route_sever_dst.add_vpp_config()
344
345 # Send PPPoE Discovery
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200346 tx0 = self.create_stream_pppoe_discovery(
347 self.pg0, self.pg1, self.pg0.remote_mac
348 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800349 self.pg0.add_stream(tx0)
350 self.pg_start()
351
352 # Send PPPoE PPP LCP
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200353 tx1 = self.create_stream_pppoe_lcp(
354 self.pg0, self.pg1, self.pg0.remote_mac, self.session_id
355 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800356 self.pg0.add_stream(tx1)
357 self.pg_start()
358
359 # Create PPPoE session
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200360 pppoe_if = VppPppoeInterface(
361 self, self.pg0.remote_ip4, self.pg0.remote_mac, self.session_id
362 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800363 pppoe_if.add_vpp_config()
Stanislav Zaikin938af5e2020-12-03 19:09:53 +0000364 pppoe_if.set_unnumbered(self.pg0.sw_if_index)
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800365
366 #
367 # The double create (create the same session twice) should fail,
368 # and we should still be able to use the original
369 #
370 try:
Hongjun Niad2ddb12017-11-17 23:43:11 +0800371 pppoe_if.add_vpp_config()
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800372 except Exception:
373 pass
374 else:
375 self.fail("Double GRE tunnel add does not fail")
376
377 #
378 # test case cleanup
379 #
380
381 # Delete PPPoE session
382 pppoe_if.remove_vpp_config()
383
384 # Delete a route that resolves the server's destination
385 route_sever_dst.remove_vpp_config()
386
387 def test_PPPoE_Del_Twice(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200388 """PPPoE Delete Same Session Twice Test"""
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800389
390 self.vapi.cli("clear trace")
391
392 #
393 # Add a route that resolves the server's destination
394 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200395 route_sever_dst = VppIpRoute(
396 self,
397 "100.1.1.100",
398 32,
399 [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index)],
400 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800401 route_sever_dst.add_vpp_config()
402
403 # Send PPPoE Discovery
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200404 tx0 = self.create_stream_pppoe_discovery(
405 self.pg0, self.pg1, self.pg0.remote_mac
406 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800407 self.pg0.add_stream(tx0)
408 self.pg_start()
409
410 # Send PPPoE PPP LCP
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200411 tx1 = self.create_stream_pppoe_lcp(
412 self.pg0, self.pg1, self.pg0.remote_mac, self.session_id
413 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800414 self.pg0.add_stream(tx1)
415 self.pg_start()
416
417 # Create PPPoE session
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200418 pppoe_if = VppPppoeInterface(
419 self, self.pg0.remote_ip4, self.pg0.remote_mac, self.session_id
420 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800421 pppoe_if.add_vpp_config()
422
423 # Delete PPPoE session
424 pppoe_if.remove_vpp_config()
425
426 #
427 # The double del (del the same session twice) should fail,
428 # and we should still be able to use the original
429 #
430 try:
Hongjun Niad2ddb12017-11-17 23:43:11 +0800431 pppoe_if.remove_vpp_config()
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800432 except Exception:
433 pass
434 else:
435 self.fail("Double GRE tunnel del does not fail")
436
437 #
438 # test case cleanup
439 #
440
441 # Delete a route that resolves the server's destination
442 route_sever_dst.remove_vpp_config()
443
444 def test_PPPoE_Decap_Multiple(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200445 """PPPoE Decap Multiple Sessions Test"""
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800446
447 self.vapi.cli("clear trace")
448
449 #
450 # Add a route that resolves the server's destination
451 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200452 route_sever_dst = VppIpRoute(
453 self,
454 "100.1.1.100",
455 32,
456 [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index)],
457 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800458 route_sever_dst.add_vpp_config()
459
460 # Send PPPoE Discovery 1
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200461 tx0 = self.create_stream_pppoe_discovery(
462 self.pg0, self.pg1, self.pg0.remote_mac
463 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800464 self.pg0.add_stream(tx0)
465 self.pg_start()
466
467 # Send PPPoE PPP LCP 1
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200468 tx1 = self.create_stream_pppoe_lcp(
469 self.pg0, self.pg1, self.pg0.remote_mac, self.session_id
470 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800471 self.pg0.add_stream(tx1)
472 self.pg_start()
473
474 # Create PPPoE session 1
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200475 pppoe_if1 = VppPppoeInterface(
476 self, self.pg0.remote_ip4, self.pg0.remote_mac, self.session_id
477 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800478 pppoe_if1.add_vpp_config()
Stanislav Zaikin938af5e2020-12-03 19:09:53 +0000479 pppoe_if1.set_unnumbered(self.pg0.sw_if_index)
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800480
481 # Send PPPoE Discovery 2
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200482 tx3 = self.create_stream_pppoe_discovery(
483 self.pg2, self.pg1, self.pg2.remote_mac
484 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800485 self.pg2.add_stream(tx3)
486 self.pg_start()
487
488 # Send PPPoE PPP LCP 2
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200489 tx4 = self.create_stream_pppoe_lcp(
490 self.pg2, self.pg1, self.pg2.remote_mac, self.session_id + 1
491 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800492 self.pg2.add_stream(tx4)
493 self.pg_start()
494
495 # Create PPPoE session 2
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200496 pppoe_if2 = VppPppoeInterface(
497 self, self.pg2.remote_ip4, self.pg2.remote_mac, self.session_id + 1
498 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800499 pppoe_if2.add_vpp_config()
Stanislav Zaikin938af5e2020-12-03 19:09:53 +0000500 pppoe_if2.set_unnumbered(self.pg0.sw_if_index)
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800501
502 #
503 # Send tunneled packets that match the created tunnel and
504 # are decapped and forwarded
505 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200506 tx2 = self.create_stream_pppoe_ip4(
507 self.pg0,
508 self.pg1,
509 self.pg0.remote_mac,
510 self.session_id,
511 self.pg0.remote_ip4,
512 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800513 self.pg0.add_stream(tx2)
514
515 self.pg_enable_capture(self.pg_interfaces)
516 self.pg_start()
517
518 rx2 = self.pg1.get_capture(len(tx2))
519 self.verify_decapped_pppoe(self.pg0, rx2, tx2)
520
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200521 tx5 = self.create_stream_pppoe_ip4(
522 self.pg2,
523 self.pg1,
524 self.pg2.remote_mac,
525 self.session_id + 1,
526 self.pg2.remote_ip4,
527 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800528 self.pg2.add_stream(tx5)
529
530 self.pg_enable_capture(self.pg_interfaces)
531 self.pg_start()
532
533 rx5 = self.pg1.get_capture(len(tx5))
534 self.verify_decapped_pppoe(self.pg2, rx5, tx5)
535
536 self.logger.info(self.vapi.cli("show pppoe fib"))
537 self.logger.info(self.vapi.cli("show pppoe session"))
538 self.logger.info(self.vapi.cli("show ip fib"))
539
540 #
541 # test case cleanup
542 #
543
544 # Delete PPPoE session
545 pppoe_if1.remove_vpp_config()
546 pppoe_if2.remove_vpp_config()
547
548 # Delete a route that resolves the server's destination
549 route_sever_dst.remove_vpp_config()
550
551 def test_PPPoE_Encap_Multiple(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200552 """PPPoE Encap Multiple Sessions Test"""
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800553
554 self.vapi.cli("clear trace")
555
556 #
557 # Add a route that resolves the server's destination
558 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200559 route_sever_dst = VppIpRoute(
560 self,
561 "100.1.1.100",
562 32,
563 [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index)],
564 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800565 route_sever_dst.add_vpp_config()
566
567 # Send PPPoE Discovery 1
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200568 tx0 = self.create_stream_pppoe_discovery(
569 self.pg0, self.pg1, self.pg0.remote_mac
570 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800571 self.pg0.add_stream(tx0)
572 self.pg_start()
573
574 # Send PPPoE PPP LCP 1
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200575 tx1 = self.create_stream_pppoe_lcp(
576 self.pg0, self.pg1, self.pg0.remote_mac, self.session_id
577 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800578 self.pg0.add_stream(tx1)
579 self.pg_start()
580
581 # Create PPPoE session 1
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200582 pppoe_if1 = VppPppoeInterface(
583 self, self.pg0.remote_ip4, self.pg0.remote_mac, self.session_id
584 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800585 pppoe_if1.add_vpp_config()
586
587 # Send PPPoE Discovery 2
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200588 tx3 = self.create_stream_pppoe_discovery(
589 self.pg2, self.pg1, self.pg2.remote_mac
590 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800591 self.pg2.add_stream(tx3)
592 self.pg_start()
593
594 # Send PPPoE PPP LCP 2
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200595 tx4 = self.create_stream_pppoe_lcp(
596 self.pg2, self.pg1, self.pg2.remote_mac, self.session_id + 1
597 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800598 self.pg2.add_stream(tx4)
599 self.pg_start()
600
601 # Create PPPoE session 2
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200602 pppoe_if2 = VppPppoeInterface(
603 self, self.pg2.remote_ip4, self.pg2.remote_mac, self.session_id + 1
604 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800605 pppoe_if2.add_vpp_config()
606
607 #
608 # Send a packet stream that is routed into the session
609 # - packets are PPPoE encapped
610 #
611 self.vapi.cli("clear trace")
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200612 tx2 = self.create_stream_ip4(
613 self.pg1, self.pg0, self.pg0.remote_ip4, self.dst_ip
614 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800615 self.pg1.add_stream(tx2)
616
617 self.pg_enable_capture(self.pg_interfaces)
618 self.pg_start()
619
620 rx2 = self.pg0.get_capture(len(tx2))
621 self.verify_encaped_pppoe(self.pg1, rx2, tx2, self.session_id)
622
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200623 tx5 = self.create_stream_ip4(
624 self.pg1, self.pg2, self.pg2.remote_ip4, self.dst_ip
625 )
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800626 self.pg1.add_stream(tx5)
627
628 self.pg_enable_capture(self.pg_interfaces)
629 self.pg_start()
630
631 rx5 = self.pg2.get_capture(len(tx5))
632 self.verify_encaped_pppoe(self.pg1, rx5, tx5, self.session_id + 1)
633
634 self.logger.info(self.vapi.cli("show pppoe fib"))
635 self.logger.info(self.vapi.cli("show pppoe session"))
636 self.logger.info(self.vapi.cli("show ip fib"))
637
638 #
639 # test case cleanup
640 #
641
642 # Delete PPPoE session
643 pppoe_if1.remove_vpp_config()
644 pppoe_if2.remove_vpp_config()
645
646 # Delete a route that resolves the server's destination
647 route_sever_dst.remove_vpp_config()
648
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200649
650if __name__ == "__main__":
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800651 unittest.main(testRunner=VppTestRunner)