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 super(TestPPPoE, self).setUp()
31 # create 2 pg interfaces
32 self.create_pg_interfaces(range(3))
34 for i in self.pg_interfaces:
40 super(TestPPPoE, self).tearDown()
42 self.logger.info(self.vapi.cli("show int"))
43 self.logger.info(self.vapi.cli("show pppoe fib"))
44 self.logger.info(self.vapi.cli("show pppoe session"))
45 self.logger.info(self.vapi.cli("show ip fib"))
46 self.logger.info(self.vapi.cli("show trace"))
48 for i in self.pg_interfaces:
52 def create_stream_pppoe_discovery(self, src_if, dst_if,
55 for i in range(count):
56 # create packet info stored in the test case instance
57 info = self.create_packet_info(src_if, dst_if)
58 # convert the info into packet payload
59 payload = self.info_to_payload(info)
60 # create the packet itself
61 p = (Ether(dst=src_if.local_mac, src=client_mac) /
64 # store a copy of the packet in the packet info
66 # append the packet to the list
69 # return the created packet list
72 def create_stream_pppoe_lcp(self, src_if, dst_if,
73 client_mac, session_id, count=1):
75 for i in range(count):
76 # create packet info stored in the test case instance
77 info = self.create_packet_info(src_if, dst_if)
78 # convert the info into packet payload
79 payload = self.info_to_payload(info)
80 # create the packet itself
81 p = (Ether(dst=src_if.local_mac, src=client_mac) /
82 PPPoE(sessionid=session_id) /
85 # store a copy of the packet in the packet info
87 # append the packet to the list
90 # return the created packet list
93 def create_stream_pppoe_ip4(self, src_if, dst_if,
94 client_mac, session_id, client_ip, count=1):
96 for i in range(count):
97 # create packet info stored in the test case instance
98 info = self.create_packet_info(src_if, dst_if)
99 # convert the info into packet payload
100 payload = self.info_to_payload(info)
101 # create the packet itself
102 p = (Ether(dst=src_if.local_mac, src=client_mac) /
103 PPPoE(sessionid=session_id) /
105 IP(src=client_ip, dst=self.dst_ip) /
107 # store a copy of the packet in the packet info
109 # append the packet to the list
112 # return the created packet list
115 def create_stream_ip4(self, src_if, dst_if, client_ip, dst_ip, count=1):
117 for i in range(count):
118 # create packet info stored in the test case instance
119 info = self.create_packet_info(src_if, dst_if)
120 # convert the info into packet payload
121 payload = self.info_to_payload(info)
122 # create the packet itself
123 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
124 IP(src=dst_ip, dst=client_ip) /
126 # store a copy of the packet in the packet info
128 # append the packet to the list
131 # return the created packet list
134 def verify_decapped_pppoe(self, src_if, capture, sent):
135 self.assertEqual(len(capture), len(sent))
137 for i in range(len(capture)):
145 self.assertEqual(rx_ip.src, tx_ip.src)
146 self.assertEqual(rx_ip.dst, tx_ip.dst)
149 self.logger.error(ppp("Rx:", rx))
150 self.logger.error(ppp("Tx:", tx))
153 def verify_encaped_pppoe(self, src_if, capture, sent, session_id):
155 self.assertEqual(len(capture), len(sent))
157 for i in range(len(capture)):
165 self.assertEqual(rx_ip.src, tx_ip.src)
166 self.assertEqual(rx_ip.dst, tx_ip.dst)
170 self.assertEqual(rx_pppoe.sessionid, session_id)
173 self.logger.error(ppp("Rx:", rx))
174 self.logger.error(ppp("Tx:", tx))
177 def test_PPPoE_Decap(self):
178 """ PPPoE Decap Test """
180 self.vapi.cli("clear trace")
183 # Add a route that resolves the server's destination
185 route_sever_dst = VppIpRoute(self, "100.1.1.100", 32,
186 [VppRoutePath(self.pg1.remote_ip4,
187 self.pg1.sw_if_index)])
188 route_sever_dst.add_vpp_config()
190 # Send PPPoE Discovery
191 tx0 = self.create_stream_pppoe_discovery(self.pg0, self.pg1,
193 self.pg0.add_stream(tx0)
197 tx1 = self.create_stream_pppoe_lcp(self.pg0, self.pg1,
200 self.pg0.add_stream(tx1)
203 # Create PPPoE session
204 pppoe_if = VppPppoeInterface(self,
208 pppoe_if.add_vpp_config()
211 # Send tunneled packets that match the created tunnel and
212 # are decapped and forwarded
214 tx2 = self.create_stream_pppoe_ip4(self.pg0, self.pg1,
218 self.pg0.add_stream(tx2)
220 self.pg_enable_capture(self.pg_interfaces)
223 rx2 = self.pg1.get_capture(len(tx2))
224 self.verify_decapped_pppoe(self.pg0, rx2, tx2)
226 self.logger.info(self.vapi.cli("show pppoe fib"))
227 self.logger.info(self.vapi.cli("show pppoe session"))
228 self.logger.info(self.vapi.cli("show ip fib"))
234 # Delete PPPoE session
235 pppoe_if.remove_vpp_config()
237 # Delete a route that resolves the server's destination
238 route_sever_dst.remove_vpp_config()
240 def test_PPPoE_Encap(self):
241 """ PPPoE Encap Test """
243 self.vapi.cli("clear trace")
246 # Add a route that resolves the server's destination
248 route_sever_dst = VppIpRoute(self, "100.1.1.100", 32,
249 [VppRoutePath(self.pg1.remote_ip4,
250 self.pg1.sw_if_index)])
251 route_sever_dst.add_vpp_config()
253 # Send PPPoE Discovery
254 tx0 = self.create_stream_pppoe_discovery(self.pg0, self.pg1,
256 self.pg0.add_stream(tx0)
260 tx1 = self.create_stream_pppoe_lcp(self.pg0, self.pg1,
263 self.pg0.add_stream(tx1)
266 # Create PPPoE session
267 pppoe_if = VppPppoeInterface(self,
271 pppoe_if.add_vpp_config()
274 # Send a packet stream that is routed into the session
275 # - packets are PPPoE encapped
277 self.vapi.cli("clear trace")
278 tx2 = self.create_stream_ip4(self.pg1, self.pg0,
279 self.pg0.remote_ip4, self.dst_ip, 65)
280 self.pg1.add_stream(tx2)
282 self.pg_enable_capture(self.pg_interfaces)
285 rx2 = self.pg0.get_capture(len(tx2))
286 self.verify_encaped_pppoe(self.pg1, rx2, tx2, self.session_id)
288 self.logger.info(self.vapi.cli("show pppoe fib"))
289 self.logger.info(self.vapi.cli("show pppoe session"))
290 self.logger.info(self.vapi.cli("show ip fib"))
291 self.logger.info(self.vapi.cli("show adj"))
297 # Delete PPPoE session
298 pppoe_if.remove_vpp_config()
300 # Delete a route that resolves the server's destination
301 route_sever_dst.remove_vpp_config()
303 def test_PPPoE_Add_Twice(self):
304 """ PPPoE Add Same Session Twice Test """
306 self.vapi.cli("clear trace")
309 # Add a route that resolves the server's destination
311 route_sever_dst = VppIpRoute(self, "100.1.1.100", 32,
312 [VppRoutePath(self.pg1.remote_ip4,
313 self.pg1.sw_if_index)])
314 route_sever_dst.add_vpp_config()
316 # Send PPPoE Discovery
317 tx0 = self.create_stream_pppoe_discovery(self.pg0, self.pg1,
319 self.pg0.add_stream(tx0)
323 tx1 = self.create_stream_pppoe_lcp(self.pg0, self.pg1,
326 self.pg0.add_stream(tx1)
329 # Create PPPoE session
330 pppoe_if = VppPppoeInterface(self,
334 pppoe_if.add_vpp_config()
337 # The double create (create the same session twice) should fail,
338 # and we should still be able to use the original
341 pppoe_if.add_vpp_config()
345 self.fail("Double GRE tunnel add does not fail")
351 # Delete PPPoE session
352 pppoe_if.remove_vpp_config()
354 # Delete a route that resolves the server's destination
355 route_sever_dst.remove_vpp_config()
357 def test_PPPoE_Del_Twice(self):
358 """ PPPoE Delete Same Session Twice Test """
360 self.vapi.cli("clear trace")
363 # Add a route that resolves the server's destination
365 route_sever_dst = VppIpRoute(self, "100.1.1.100", 32,
366 [VppRoutePath(self.pg1.remote_ip4,
367 self.pg1.sw_if_index)])
368 route_sever_dst.add_vpp_config()
370 # Send PPPoE Discovery
371 tx0 = self.create_stream_pppoe_discovery(self.pg0, self.pg1,
373 self.pg0.add_stream(tx0)
377 tx1 = self.create_stream_pppoe_lcp(self.pg0, self.pg1,
380 self.pg0.add_stream(tx1)
383 # Create PPPoE session
384 pppoe_if = VppPppoeInterface(self,
388 pppoe_if.add_vpp_config()
390 # Delete PPPoE session
391 pppoe_if.remove_vpp_config()
394 # The double del (del the same session twice) should fail,
395 # and we should still be able to use the original
398 pppoe_if.remove_vpp_config()
402 self.fail("Double GRE tunnel del does not fail")
408 # Delete a route that resolves the server's destination
409 route_sever_dst.remove_vpp_config()
411 def test_PPPoE_Decap_Multiple(self):
412 """ PPPoE Decap Multiple Sessions Test """
414 self.vapi.cli("clear trace")
417 # Add a route that resolves the server's destination
419 route_sever_dst = VppIpRoute(self, "100.1.1.100", 32,
420 [VppRoutePath(self.pg1.remote_ip4,
421 self.pg1.sw_if_index)])
422 route_sever_dst.add_vpp_config()
424 # Send PPPoE Discovery 1
425 tx0 = self.create_stream_pppoe_discovery(self.pg0, self.pg1,
427 self.pg0.add_stream(tx0)
430 # Send PPPoE PPP LCP 1
431 tx1 = self.create_stream_pppoe_lcp(self.pg0, self.pg1,
434 self.pg0.add_stream(tx1)
437 # Create PPPoE session 1
438 pppoe_if1 = VppPppoeInterface(self,
442 pppoe_if1.add_vpp_config()
444 # Send PPPoE Discovery 2
445 tx3 = self.create_stream_pppoe_discovery(self.pg2, self.pg1,
447 self.pg2.add_stream(tx3)
450 # Send PPPoE PPP LCP 2
451 tx4 = self.create_stream_pppoe_lcp(self.pg2, self.pg1,
454 self.pg2.add_stream(tx4)
457 # Create PPPoE session 2
458 pppoe_if2 = VppPppoeInterface(self,
462 pppoe_if2.add_vpp_config()
465 # Send tunneled packets that match the created tunnel and
466 # are decapped and forwarded
468 tx2 = self.create_stream_pppoe_ip4(self.pg0, self.pg1,
472 self.pg0.add_stream(tx2)
474 self.pg_enable_capture(self.pg_interfaces)
477 rx2 = self.pg1.get_capture(len(tx2))
478 self.verify_decapped_pppoe(self.pg0, rx2, tx2)
480 tx5 = self.create_stream_pppoe_ip4(self.pg2, self.pg1,
484 self.pg2.add_stream(tx5)
486 self.pg_enable_capture(self.pg_interfaces)
489 rx5 = self.pg1.get_capture(len(tx5))
490 self.verify_decapped_pppoe(self.pg2, rx5, tx5)
492 self.logger.info(self.vapi.cli("show pppoe fib"))
493 self.logger.info(self.vapi.cli("show pppoe session"))
494 self.logger.info(self.vapi.cli("show ip fib"))
500 # Delete PPPoE session
501 pppoe_if1.remove_vpp_config()
502 pppoe_if2.remove_vpp_config()
504 # Delete a route that resolves the server's destination
505 route_sever_dst.remove_vpp_config()
507 def test_PPPoE_Encap_Multiple(self):
508 """ PPPoE Encap Multiple Sessions Test """
510 self.vapi.cli("clear trace")
513 # Add a route that resolves the server's destination
515 route_sever_dst = VppIpRoute(self, "100.1.1.100", 32,
516 [VppRoutePath(self.pg1.remote_ip4,
517 self.pg1.sw_if_index)])
518 route_sever_dst.add_vpp_config()
520 # Send PPPoE Discovery 1
521 tx0 = self.create_stream_pppoe_discovery(self.pg0, self.pg1,
523 self.pg0.add_stream(tx0)
526 # Send PPPoE PPP LCP 1
527 tx1 = self.create_stream_pppoe_lcp(self.pg0, self.pg1,
530 self.pg0.add_stream(tx1)
533 # Create PPPoE session 1
534 pppoe_if1 = VppPppoeInterface(self,
538 pppoe_if1.add_vpp_config()
540 # Send PPPoE Discovery 2
541 tx3 = self.create_stream_pppoe_discovery(self.pg2, self.pg1,
543 self.pg2.add_stream(tx3)
546 # Send PPPoE PPP LCP 2
547 tx4 = self.create_stream_pppoe_lcp(self.pg2, self.pg1,
550 self.pg2.add_stream(tx4)
553 # Create PPPoE session 2
554 pppoe_if2 = VppPppoeInterface(self,
558 pppoe_if2.add_vpp_config()
561 # Send a packet stream that is routed into the session
562 # - packets are PPPoE encapped
564 self.vapi.cli("clear trace")
565 tx2 = self.create_stream_ip4(self.pg1, self.pg0,
566 self.pg0.remote_ip4, self.dst_ip)
567 self.pg1.add_stream(tx2)
569 self.pg_enable_capture(self.pg_interfaces)
572 rx2 = self.pg0.get_capture(len(tx2))
573 self.verify_encaped_pppoe(self.pg1, rx2, tx2, self.session_id)
575 tx5 = self.create_stream_ip4(self.pg1, self.pg2,
576 self.pg2.remote_ip4, self.dst_ip)
577 self.pg1.add_stream(tx5)
579 self.pg_enable_capture(self.pg_interfaces)
582 rx5 = self.pg2.get_capture(len(tx5))
583 self.verify_encaped_pppoe(self.pg1, rx5, tx5, self.session_id + 1)
585 self.logger.info(self.vapi.cli("show pppoe fib"))
586 self.logger.info(self.vapi.cli("show pppoe session"))
587 self.logger.info(self.vapi.cli("show ip fib"))
593 # Delete PPPoE session
594 pppoe_if1.remove_vpp_config()
595 pppoe_if2.remove_vpp_config()
597 # Delete a route that resolves the server's destination
598 route_sever_dst.remove_vpp_config()
600 if __name__ == '__main__':
601 unittest.main(testRunner=VppTestRunner)