Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 2 | |
Paul Vinciguerra | a279d9c | 2019-02-28 09:00:09 -0800 | [diff] [blame] | 3 | import socket |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 4 | import unittest |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 5 | |
| 6 | from scapy.packet import Raw |
| 7 | from scapy.layers.l2 import Ether |
| 8 | from scapy.layers.ppp import PPPoE, PPPoED, PPP |
Paul Vinciguerra | a279d9c | 2019-02-28 09:00:09 -0800 | [diff] [blame] | 9 | from scapy.layers.inet import IP |
| 10 | |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 11 | from framework import VppTestCase |
| 12 | from asfframework import VppTestRunner |
Paul Vinciguerra | a279d9c | 2019-02-28 09:00:09 -0800 | [diff] [blame] | 13 | from vpp_ip_route import VppIpRoute, VppRoutePath |
| 14 | from vpp_pppoe_interface import VppPppoeInterface |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 15 | from util import ppp |
Dmitry Valter | 34fa0ce | 2024-03-11 10:38:46 +0000 | [diff] [blame] | 16 | from config import config |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 17 | |
| 18 | |
Dmitry Valter | 34fa0ce | 2024-03-11 10:38:46 +0000 | [diff] [blame] | 19 | @unittest.skipIf("pppoe" in config.excluded_plugins, "Exclude PPPoE plugin tests") |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 20 | class TestPPPoE(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 21 | """PPPoE Test Case""" |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 22 | |
| 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 Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 31 | @classmethod |
| 32 | def tearDownClass(cls): |
| 33 | super(TestPPPoE, cls).tearDownClass() |
| 34 | |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 35 | 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 Vinciguerra | 90cf21b | 2019-03-13 09:23:05 -0700 | [diff] [blame] | 49 | for i in self.pg_interfaces: |
| 50 | i.unconfig_ip4() |
| 51 | i.admin_down() |
| 52 | |
| 53 | def show_commands_at_teardown(self): |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 54 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 60 | def create_stream_pppoe_discovery(self, src_if, dst_if, client_mac, count=1): |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 61 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 68 | p = ( |
| 69 | Ether(dst=src_if.local_mac, src=client_mac) |
| 70 | / PPPoED(sessionid=0) |
| 71 | / Raw(payload) |
| 72 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 73 | # 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 81 | def create_stream_pppoe_lcp(self, src_if, dst_if, client_mac, session_id, count=1): |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 82 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 89 | 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 Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 95 | # 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 103 | def create_stream_pppoe_ip4( |
| 104 | self, src_if, dst_if, client_mac, session_id, client_ip, count=1 |
| 105 | ): |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 106 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 113 | 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 Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 120 | # 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 136 | 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 Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 141 | # 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 Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 169 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 192 | """PPPoE Decap Test""" |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 193 | |
| 194 | self.vapi.cli("clear trace") |
| 195 | |
| 196 | # |
| 197 | # Add a route that resolves the server's destination |
| 198 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 199 | 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 Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 205 | route_sever_dst.add_vpp_config() |
| 206 | |
| 207 | # Send PPPoE Discovery |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 208 | tx0 = self.create_stream_pppoe_discovery( |
| 209 | self.pg0, self.pg1, self.pg0.remote_mac |
| 210 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 211 | self.pg0.add_stream(tx0) |
| 212 | self.pg_start() |
| 213 | |
| 214 | # Send PPPoE PPP LCP |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 215 | tx1 = self.create_stream_pppoe_lcp( |
| 216 | self.pg0, self.pg1, self.pg0.remote_mac, self.session_id |
| 217 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 218 | self.pg0.add_stream(tx1) |
| 219 | self.pg_start() |
| 220 | |
| 221 | # Create PPPoE session |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 222 | pppoe_if = VppPppoeInterface( |
| 223 | self, self.pg0.remote_ip4, self.pg0.remote_mac, self.session_id |
| 224 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 225 | pppoe_if.add_vpp_config() |
Stanislav Zaikin | 938af5e | 2020-12-03 19:09:53 +0000 | [diff] [blame] | 226 | pppoe_if.set_unnumbered(self.pg0.sw_if_index) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 227 | |
| 228 | # |
| 229 | # Send tunneled packets that match the created tunnel and |
| 230 | # are decapped and forwarded |
| 231 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 232 | 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 Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 239 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 262 | """PPPoE Encap Test""" |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 263 | |
| 264 | self.vapi.cli("clear trace") |
| 265 | |
| 266 | # |
| 267 | # Add a route that resolves the server's destination |
| 268 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 269 | 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 Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 275 | route_sever_dst.add_vpp_config() |
| 276 | |
| 277 | # Send PPPoE Discovery |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 278 | tx0 = self.create_stream_pppoe_discovery( |
| 279 | self.pg0, self.pg1, self.pg0.remote_mac |
| 280 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 281 | self.pg0.add_stream(tx0) |
| 282 | self.pg_start() |
| 283 | |
| 284 | # Send PPPoE PPP LCP |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 285 | tx1 = self.create_stream_pppoe_lcp( |
| 286 | self.pg0, self.pg1, self.pg0.remote_mac, self.session_id |
| 287 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 288 | self.pg0.add_stream(tx1) |
| 289 | self.pg_start() |
| 290 | |
| 291 | # Create PPPoE session |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 292 | pppoe_if = VppPppoeInterface( |
| 293 | self, self.pg0.remote_ip4, self.pg0.remote_mac, self.session_id |
| 294 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 295 | pppoe_if.add_vpp_config() |
Stanislav Zaikin | 938af5e | 2020-12-03 19:09:53 +0000 | [diff] [blame] | 296 | pppoe_if.set_unnumbered(self.pg0.sw_if_index) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 297 | |
| 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 303 | tx2 = self.create_stream_ip4( |
| 304 | self.pg1, self.pg0, self.pg0.remote_ip4, self.dst_ip, 65 |
| 305 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 306 | 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 Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 317 | self.logger.info(self.vapi.cli("show adj")) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 318 | |
| 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 330 | """PPPoE Add Same Session Twice Test""" |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 331 | |
| 332 | self.vapi.cli("clear trace") |
| 333 | |
| 334 | # |
| 335 | # Add a route that resolves the server's destination |
| 336 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 337 | 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 Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 343 | route_sever_dst.add_vpp_config() |
| 344 | |
| 345 | # Send PPPoE Discovery |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 346 | tx0 = self.create_stream_pppoe_discovery( |
| 347 | self.pg0, self.pg1, self.pg0.remote_mac |
| 348 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 349 | self.pg0.add_stream(tx0) |
| 350 | self.pg_start() |
| 351 | |
| 352 | # Send PPPoE PPP LCP |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 353 | tx1 = self.create_stream_pppoe_lcp( |
| 354 | self.pg0, self.pg1, self.pg0.remote_mac, self.session_id |
| 355 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 356 | self.pg0.add_stream(tx1) |
| 357 | self.pg_start() |
| 358 | |
| 359 | # Create PPPoE session |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 360 | pppoe_if = VppPppoeInterface( |
| 361 | self, self.pg0.remote_ip4, self.pg0.remote_mac, self.session_id |
| 362 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 363 | pppoe_if.add_vpp_config() |
Stanislav Zaikin | 938af5e | 2020-12-03 19:09:53 +0000 | [diff] [blame] | 364 | pppoe_if.set_unnumbered(self.pg0.sw_if_index) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 365 | |
| 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 Ni | ad2ddb1 | 2017-11-17 23:43:11 +0800 | [diff] [blame] | 371 | pppoe_if.add_vpp_config() |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 372 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 388 | """PPPoE Delete Same Session Twice Test""" |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 389 | |
| 390 | self.vapi.cli("clear trace") |
| 391 | |
| 392 | # |
| 393 | # Add a route that resolves the server's destination |
| 394 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 395 | 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 Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 401 | route_sever_dst.add_vpp_config() |
| 402 | |
| 403 | # Send PPPoE Discovery |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 404 | tx0 = self.create_stream_pppoe_discovery( |
| 405 | self.pg0, self.pg1, self.pg0.remote_mac |
| 406 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 407 | self.pg0.add_stream(tx0) |
| 408 | self.pg_start() |
| 409 | |
| 410 | # Send PPPoE PPP LCP |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 411 | tx1 = self.create_stream_pppoe_lcp( |
| 412 | self.pg0, self.pg1, self.pg0.remote_mac, self.session_id |
| 413 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 414 | self.pg0.add_stream(tx1) |
| 415 | self.pg_start() |
| 416 | |
| 417 | # Create PPPoE session |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 418 | pppoe_if = VppPppoeInterface( |
| 419 | self, self.pg0.remote_ip4, self.pg0.remote_mac, self.session_id |
| 420 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 421 | 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 Ni | ad2ddb1 | 2017-11-17 23:43:11 +0800 | [diff] [blame] | 431 | pppoe_if.remove_vpp_config() |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 432 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 445 | """PPPoE Decap Multiple Sessions Test""" |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 446 | |
| 447 | self.vapi.cli("clear trace") |
| 448 | |
| 449 | # |
| 450 | # Add a route that resolves the server's destination |
| 451 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 452 | 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 Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 458 | route_sever_dst.add_vpp_config() |
| 459 | |
| 460 | # Send PPPoE Discovery 1 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 461 | tx0 = self.create_stream_pppoe_discovery( |
| 462 | self.pg0, self.pg1, self.pg0.remote_mac |
| 463 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 464 | self.pg0.add_stream(tx0) |
| 465 | self.pg_start() |
| 466 | |
| 467 | # Send PPPoE PPP LCP 1 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 468 | tx1 = self.create_stream_pppoe_lcp( |
| 469 | self.pg0, self.pg1, self.pg0.remote_mac, self.session_id |
| 470 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 471 | self.pg0.add_stream(tx1) |
| 472 | self.pg_start() |
| 473 | |
| 474 | # Create PPPoE session 1 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 475 | pppoe_if1 = VppPppoeInterface( |
| 476 | self, self.pg0.remote_ip4, self.pg0.remote_mac, self.session_id |
| 477 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 478 | pppoe_if1.add_vpp_config() |
Stanislav Zaikin | 938af5e | 2020-12-03 19:09:53 +0000 | [diff] [blame] | 479 | pppoe_if1.set_unnumbered(self.pg0.sw_if_index) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 480 | |
| 481 | # Send PPPoE Discovery 2 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 482 | tx3 = self.create_stream_pppoe_discovery( |
| 483 | self.pg2, self.pg1, self.pg2.remote_mac |
| 484 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 485 | self.pg2.add_stream(tx3) |
| 486 | self.pg_start() |
| 487 | |
| 488 | # Send PPPoE PPP LCP 2 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 489 | tx4 = self.create_stream_pppoe_lcp( |
| 490 | self.pg2, self.pg1, self.pg2.remote_mac, self.session_id + 1 |
| 491 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 492 | self.pg2.add_stream(tx4) |
| 493 | self.pg_start() |
| 494 | |
| 495 | # Create PPPoE session 2 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 496 | pppoe_if2 = VppPppoeInterface( |
| 497 | self, self.pg2.remote_ip4, self.pg2.remote_mac, self.session_id + 1 |
| 498 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 499 | pppoe_if2.add_vpp_config() |
Stanislav Zaikin | 938af5e | 2020-12-03 19:09:53 +0000 | [diff] [blame] | 500 | pppoe_if2.set_unnumbered(self.pg0.sw_if_index) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 501 | |
| 502 | # |
| 503 | # Send tunneled packets that match the created tunnel and |
| 504 | # are decapped and forwarded |
| 505 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 506 | 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 Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 513 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 521 | 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 Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 528 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 552 | """PPPoE Encap Multiple Sessions Test""" |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 553 | |
| 554 | self.vapi.cli("clear trace") |
| 555 | |
| 556 | # |
| 557 | # Add a route that resolves the server's destination |
| 558 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 559 | 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 Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 565 | route_sever_dst.add_vpp_config() |
| 566 | |
| 567 | # Send PPPoE Discovery 1 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 568 | tx0 = self.create_stream_pppoe_discovery( |
| 569 | self.pg0, self.pg1, self.pg0.remote_mac |
| 570 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 571 | self.pg0.add_stream(tx0) |
| 572 | self.pg_start() |
| 573 | |
| 574 | # Send PPPoE PPP LCP 1 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 575 | tx1 = self.create_stream_pppoe_lcp( |
| 576 | self.pg0, self.pg1, self.pg0.remote_mac, self.session_id |
| 577 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 578 | self.pg0.add_stream(tx1) |
| 579 | self.pg_start() |
| 580 | |
| 581 | # Create PPPoE session 1 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 582 | pppoe_if1 = VppPppoeInterface( |
| 583 | self, self.pg0.remote_ip4, self.pg0.remote_mac, self.session_id |
| 584 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 585 | pppoe_if1.add_vpp_config() |
| 586 | |
| 587 | # Send PPPoE Discovery 2 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 588 | tx3 = self.create_stream_pppoe_discovery( |
| 589 | self.pg2, self.pg1, self.pg2.remote_mac |
| 590 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 591 | self.pg2.add_stream(tx3) |
| 592 | self.pg_start() |
| 593 | |
| 594 | # Send PPPoE PPP LCP 2 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 595 | tx4 = self.create_stream_pppoe_lcp( |
| 596 | self.pg2, self.pg1, self.pg2.remote_mac, self.session_id + 1 |
| 597 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 598 | self.pg2.add_stream(tx4) |
| 599 | self.pg_start() |
| 600 | |
| 601 | # Create PPPoE session 2 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 602 | pppoe_if2 = VppPppoeInterface( |
| 603 | self, self.pg2.remote_ip4, self.pg2.remote_mac, self.session_id + 1 |
| 604 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 605 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 612 | tx2 = self.create_stream_ip4( |
| 613 | self.pg1, self.pg0, self.pg0.remote_ip4, self.dst_ip |
| 614 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 615 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 623 | tx5 = self.create_stream_ip4( |
| 624 | self.pg1, self.pg2, self.pg2.remote_ip4, self.dst_ip |
| 625 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 626 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 649 | |
| 650 | if __name__ == "__main__": |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 651 | unittest.main(testRunner=VppTestRunner) |