6 from scapy.packet import Raw
7 from scapy.layers.l2 import Ether
8 from scapy.layers.ppp import PPPoE, PPPoED, PPP
9 from scapy.layers.inet import IP
11 from framework import VppTestCase, VppTestRunner
12 from vpp_ip_route import VppIpRoute, VppRoutePath
13 from vpp_pppoe_interface import VppPppoeInterface
14 from util import ppp, ppc
17 class TestPPPoE(VppTestCase):
18 """ PPPoE Test Case """
22 super(TestPPPoE, cls).setUpClass()
25 cls.dst_ip = "100.1.1.100"
26 cls.dst_ipn = socket.inet_pton(socket.AF_INET, cls.dst_ip)
29 def tearDownClass(cls):
30 super(TestPPPoE, cls).tearDownClass()
33 super(TestPPPoE, self).setUp()
35 # create 2 pg interfaces
36 self.create_pg_interfaces(range(3))
38 for i in self.pg_interfaces:
44 super(TestPPPoE, self).tearDown()
46 for i in self.pg_interfaces:
50 def show_commands_at_teardown(self):
51 self.logger.info(self.vapi.cli("show int"))
52 self.logger.info(self.vapi.cli("show pppoe fib"))
53 self.logger.info(self.vapi.cli("show pppoe session"))
54 self.logger.info(self.vapi.cli("show ip fib"))
55 self.logger.info(self.vapi.cli("show trace"))
57 def create_stream_pppoe_discovery(self, src_if, dst_if,
60 for i in range(count):
61 # create packet info stored in the test case instance
62 info = self.create_packet_info(src_if, dst_if)
63 # convert the info into packet payload
64 payload = self.info_to_payload(info)
65 # create the packet itself
66 p = (Ether(dst=src_if.local_mac, src=client_mac) /
69 # store a copy of the packet in the packet info
71 # append the packet to the list
74 # return the created packet list
77 def create_stream_pppoe_lcp(self, src_if, dst_if,
78 client_mac, session_id, count=1):
80 for i in range(count):
81 # create packet info stored in the test case instance
82 info = self.create_packet_info(src_if, dst_if)
83 # convert the info into packet payload
84 payload = self.info_to_payload(info)
85 # create the packet itself
86 p = (Ether(dst=src_if.local_mac, src=client_mac) /
87 PPPoE(sessionid=session_id) /
90 # store a copy of the packet in the packet info
92 # append the packet to the list
95 # return the created packet list
98 def create_stream_pppoe_ip4(self, src_if, dst_if,
99 client_mac, session_id, client_ip, count=1):
101 for i in range(count):
102 # create packet info stored in the test case instance
103 info = self.create_packet_info(src_if, dst_if)
104 # convert the info into packet payload
105 payload = self.info_to_payload(info)
106 # create the packet itself
107 p = (Ether(dst=src_if.local_mac, src=client_mac) /
108 PPPoE(sessionid=session_id) /
110 IP(src=client_ip, dst=self.dst_ip) /
112 # store a copy of the packet in the packet info
114 # append the packet to the list
117 # return the created packet list
120 def create_stream_ip4(self, src_if, dst_if, client_ip, dst_ip, count=1):
122 for i in range(count):
123 # create packet info stored in the test case instance
124 info = self.create_packet_info(src_if, dst_if)
125 # convert the info into packet payload
126 payload = self.info_to_payload(info)
127 # create the packet itself
128 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
129 IP(src=dst_ip, dst=client_ip) /
131 # store a copy of the packet in the packet info
133 # append the packet to the list
136 # return the created packet list
139 def verify_decapped_pppoe(self, src_if, capture, sent):
140 self.assertEqual(len(capture), len(sent))
142 for i in range(len(capture)):
150 self.assertEqual(rx_ip.src, tx_ip.src)
151 self.assertEqual(rx_ip.dst, tx_ip.dst)
154 self.logger.error(ppp("Rx:", rx))
155 self.logger.error(ppp("Tx:", tx))
158 def verify_encaped_pppoe(self, src_if, capture, sent, session_id):
160 self.assertEqual(len(capture), len(sent))
162 for i in range(len(capture)):
170 self.assertEqual(rx_ip.src, tx_ip.src)
171 self.assertEqual(rx_ip.dst, tx_ip.dst)
175 self.assertEqual(rx_pppoe.sessionid, session_id)
178 self.logger.error(ppp("Rx:", rx))
179 self.logger.error(ppp("Tx:", tx))
182 def test_PPPoE_Decap(self):
183 """ PPPoE Decap Test """
185 self.vapi.cli("clear trace")
188 # Add a route that resolves the server's destination
190 route_sever_dst = VppIpRoute(self, "100.1.1.100", 32,
191 [VppRoutePath(self.pg1.remote_ip4,
192 self.pg1.sw_if_index)])
193 route_sever_dst.add_vpp_config()
195 # Send PPPoE Discovery
196 tx0 = self.create_stream_pppoe_discovery(self.pg0, self.pg1,
198 self.pg0.add_stream(tx0)
202 tx1 = self.create_stream_pppoe_lcp(self.pg0, self.pg1,
205 self.pg0.add_stream(tx1)
208 # Create PPPoE session
209 pppoe_if = VppPppoeInterface(self,
213 pppoe_if.add_vpp_config()
214 pppoe_if.set_unnumbered(self.pg0.sw_if_index)
217 # Send tunneled packets that match the created tunnel and
218 # are decapped and forwarded
220 tx2 = self.create_stream_pppoe_ip4(self.pg0, self.pg1,
224 self.pg0.add_stream(tx2)
226 self.pg_enable_capture(self.pg_interfaces)
229 rx2 = self.pg1.get_capture(len(tx2))
230 self.verify_decapped_pppoe(self.pg0, rx2, tx2)
232 self.logger.info(self.vapi.cli("show pppoe fib"))
233 self.logger.info(self.vapi.cli("show pppoe session"))
234 self.logger.info(self.vapi.cli("show ip fib"))
240 # Delete PPPoE session
241 pppoe_if.remove_vpp_config()
243 # Delete a route that resolves the server's destination
244 route_sever_dst.remove_vpp_config()
246 def test_PPPoE_Encap(self):
247 """ PPPoE Encap Test """
249 self.vapi.cli("clear trace")
252 # Add a route that resolves the server's destination
254 route_sever_dst = VppIpRoute(self, "100.1.1.100", 32,
255 [VppRoutePath(self.pg1.remote_ip4,
256 self.pg1.sw_if_index)])
257 route_sever_dst.add_vpp_config()
259 # Send PPPoE Discovery
260 tx0 = self.create_stream_pppoe_discovery(self.pg0, self.pg1,
262 self.pg0.add_stream(tx0)
266 tx1 = self.create_stream_pppoe_lcp(self.pg0, self.pg1,
269 self.pg0.add_stream(tx1)
272 # Create PPPoE session
273 pppoe_if = VppPppoeInterface(self,
277 pppoe_if.add_vpp_config()
278 pppoe_if.set_unnumbered(self.pg0.sw_if_index)
281 # Send a packet stream that is routed into the session
282 # - packets are PPPoE encapped
284 self.vapi.cli("clear trace")
285 tx2 = self.create_stream_ip4(self.pg1, self.pg0,
286 self.pg0.remote_ip4, self.dst_ip, 65)
287 self.pg1.add_stream(tx2)
289 self.pg_enable_capture(self.pg_interfaces)
292 rx2 = self.pg0.get_capture(len(tx2))
293 self.verify_encaped_pppoe(self.pg1, rx2, tx2, self.session_id)
295 self.logger.info(self.vapi.cli("show pppoe fib"))
296 self.logger.info(self.vapi.cli("show pppoe session"))
297 self.logger.info(self.vapi.cli("show ip fib"))
298 self.logger.info(self.vapi.cli("show adj"))
304 # Delete PPPoE session
305 pppoe_if.remove_vpp_config()
307 # Delete a route that resolves the server's destination
308 route_sever_dst.remove_vpp_config()
310 def test_PPPoE_Add_Twice(self):
311 """ PPPoE Add Same Session Twice Test """
313 self.vapi.cli("clear trace")
316 # Add a route that resolves the server's destination
318 route_sever_dst = VppIpRoute(self, "100.1.1.100", 32,
319 [VppRoutePath(self.pg1.remote_ip4,
320 self.pg1.sw_if_index)])
321 route_sever_dst.add_vpp_config()
323 # Send PPPoE Discovery
324 tx0 = self.create_stream_pppoe_discovery(self.pg0, self.pg1,
326 self.pg0.add_stream(tx0)
330 tx1 = self.create_stream_pppoe_lcp(self.pg0, self.pg1,
333 self.pg0.add_stream(tx1)
336 # Create PPPoE session
337 pppoe_if = VppPppoeInterface(self,
341 pppoe_if.add_vpp_config()
342 pppoe_if.set_unnumbered(self.pg0.sw_if_index)
345 # The double create (create the same session twice) should fail,
346 # and we should still be able to use the original
349 pppoe_if.add_vpp_config()
353 self.fail("Double GRE tunnel add does not fail")
359 # Delete PPPoE session
360 pppoe_if.remove_vpp_config()
362 # Delete a route that resolves the server's destination
363 route_sever_dst.remove_vpp_config()
365 def test_PPPoE_Del_Twice(self):
366 """ PPPoE Delete Same Session Twice Test """
368 self.vapi.cli("clear trace")
371 # Add a route that resolves the server's destination
373 route_sever_dst = VppIpRoute(self, "100.1.1.100", 32,
374 [VppRoutePath(self.pg1.remote_ip4,
375 self.pg1.sw_if_index)])
376 route_sever_dst.add_vpp_config()
378 # Send PPPoE Discovery
379 tx0 = self.create_stream_pppoe_discovery(self.pg0, self.pg1,
381 self.pg0.add_stream(tx0)
385 tx1 = self.create_stream_pppoe_lcp(self.pg0, self.pg1,
388 self.pg0.add_stream(tx1)
391 # Create PPPoE session
392 pppoe_if = VppPppoeInterface(self,
396 pppoe_if.add_vpp_config()
398 # Delete PPPoE session
399 pppoe_if.remove_vpp_config()
402 # The double del (del the same session twice) should fail,
403 # and we should still be able to use the original
406 pppoe_if.remove_vpp_config()
410 self.fail("Double GRE tunnel del does not fail")
416 # Delete a route that resolves the server's destination
417 route_sever_dst.remove_vpp_config()
419 def test_PPPoE_Decap_Multiple(self):
420 """ PPPoE Decap Multiple Sessions Test """
422 self.vapi.cli("clear trace")
425 # Add a route that resolves the server's destination
427 route_sever_dst = VppIpRoute(self, "100.1.1.100", 32,
428 [VppRoutePath(self.pg1.remote_ip4,
429 self.pg1.sw_if_index)])
430 route_sever_dst.add_vpp_config()
432 # Send PPPoE Discovery 1
433 tx0 = self.create_stream_pppoe_discovery(self.pg0, self.pg1,
435 self.pg0.add_stream(tx0)
438 # Send PPPoE PPP LCP 1
439 tx1 = self.create_stream_pppoe_lcp(self.pg0, self.pg1,
442 self.pg0.add_stream(tx1)
445 # Create PPPoE session 1
446 pppoe_if1 = VppPppoeInterface(self,
450 pppoe_if1.add_vpp_config()
451 pppoe_if1.set_unnumbered(self.pg0.sw_if_index)
453 # Send PPPoE Discovery 2
454 tx3 = self.create_stream_pppoe_discovery(self.pg2, self.pg1,
456 self.pg2.add_stream(tx3)
459 # Send PPPoE PPP LCP 2
460 tx4 = self.create_stream_pppoe_lcp(self.pg2, self.pg1,
463 self.pg2.add_stream(tx4)
466 # Create PPPoE session 2
467 pppoe_if2 = VppPppoeInterface(self,
471 pppoe_if2.add_vpp_config()
472 pppoe_if2.set_unnumbered(self.pg0.sw_if_index)
475 # Send tunneled packets that match the created tunnel and
476 # are decapped and forwarded
478 tx2 = self.create_stream_pppoe_ip4(self.pg0, self.pg1,
482 self.pg0.add_stream(tx2)
484 self.pg_enable_capture(self.pg_interfaces)
487 rx2 = self.pg1.get_capture(len(tx2))
488 self.verify_decapped_pppoe(self.pg0, rx2, tx2)
490 tx5 = self.create_stream_pppoe_ip4(self.pg2, self.pg1,
494 self.pg2.add_stream(tx5)
496 self.pg_enable_capture(self.pg_interfaces)
499 rx5 = self.pg1.get_capture(len(tx5))
500 self.verify_decapped_pppoe(self.pg2, rx5, tx5)
502 self.logger.info(self.vapi.cli("show pppoe fib"))
503 self.logger.info(self.vapi.cli("show pppoe session"))
504 self.logger.info(self.vapi.cli("show ip fib"))
510 # Delete PPPoE session
511 pppoe_if1.remove_vpp_config()
512 pppoe_if2.remove_vpp_config()
514 # Delete a route that resolves the server's destination
515 route_sever_dst.remove_vpp_config()
517 def test_PPPoE_Encap_Multiple(self):
518 """ PPPoE Encap Multiple Sessions Test """
520 self.vapi.cli("clear trace")
523 # Add a route that resolves the server's destination
525 route_sever_dst = VppIpRoute(self, "100.1.1.100", 32,
526 [VppRoutePath(self.pg1.remote_ip4,
527 self.pg1.sw_if_index)])
528 route_sever_dst.add_vpp_config()
530 # Send PPPoE Discovery 1
531 tx0 = self.create_stream_pppoe_discovery(self.pg0, self.pg1,
533 self.pg0.add_stream(tx0)
536 # Send PPPoE PPP LCP 1
537 tx1 = self.create_stream_pppoe_lcp(self.pg0, self.pg1,
540 self.pg0.add_stream(tx1)
543 # Create PPPoE session 1
544 pppoe_if1 = VppPppoeInterface(self,
548 pppoe_if1.add_vpp_config()
550 # Send PPPoE Discovery 2
551 tx3 = self.create_stream_pppoe_discovery(self.pg2, self.pg1,
553 self.pg2.add_stream(tx3)
556 # Send PPPoE PPP LCP 2
557 tx4 = self.create_stream_pppoe_lcp(self.pg2, self.pg1,
560 self.pg2.add_stream(tx4)
563 # Create PPPoE session 2
564 pppoe_if2 = VppPppoeInterface(self,
568 pppoe_if2.add_vpp_config()
571 # Send a packet stream that is routed into the session
572 # - packets are PPPoE encapped
574 self.vapi.cli("clear trace")
575 tx2 = self.create_stream_ip4(self.pg1, self.pg0,
576 self.pg0.remote_ip4, self.dst_ip)
577 self.pg1.add_stream(tx2)
579 self.pg_enable_capture(self.pg_interfaces)
582 rx2 = self.pg0.get_capture(len(tx2))
583 self.verify_encaped_pppoe(self.pg1, rx2, tx2, self.session_id)
585 tx5 = self.create_stream_ip4(self.pg1, self.pg2,
586 self.pg2.remote_ip4, self.dst_ip)
587 self.pg1.add_stream(tx5)
589 self.pg_enable_capture(self.pg_interfaces)
592 rx5 = self.pg2.get_capture(len(tx5))
593 self.verify_encaped_pppoe(self.pg1, rx5, tx5, self.session_id + 1)
595 self.logger.info(self.vapi.cli("show pppoe fib"))
596 self.logger.info(self.vapi.cli("show pppoe session"))
597 self.logger.info(self.vapi.cli("show ip fib"))
603 # Delete PPPoE session
604 pppoe_if1.remove_vpp_config()
605 pppoe_if2.remove_vpp_config()
607 # Delete a route that resolves the server's destination
608 route_sever_dst.remove_vpp_config()
610 if __name__ == '__main__':
611 unittest.main(testRunner=VppTestRunner)