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 | # Send tunneled packets that match the created tunnel and |
| 229 | # are decapped and forwarded |
| 230 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 231 | 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 Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 238 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 261 | """PPPoE Encap Test""" |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 262 | |
| 263 | self.vapi.cli("clear trace") |
| 264 | |
| 265 | # |
| 266 | # Add a route that resolves the server's destination |
| 267 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 268 | 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 Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 274 | route_sever_dst.add_vpp_config() |
| 275 | |
| 276 | # Send PPPoE Discovery |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 277 | tx0 = self.create_stream_pppoe_discovery( |
| 278 | self.pg0, self.pg1, self.pg0.remote_mac |
| 279 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 280 | self.pg0.add_stream(tx0) |
| 281 | self.pg_start() |
| 282 | |
| 283 | # Send PPPoE PPP LCP |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 284 | tx1 = self.create_stream_pppoe_lcp( |
| 285 | self.pg0, self.pg1, self.pg0.remote_mac, self.session_id |
| 286 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 287 | self.pg0.add_stream(tx1) |
| 288 | self.pg_start() |
| 289 | |
| 290 | # Create PPPoE session |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 291 | pppoe_if = VppPppoeInterface( |
| 292 | self, self.pg0.remote_ip4, self.pg0.remote_mac, self.session_id |
| 293 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 294 | pppoe_if.add_vpp_config() |
Stanislav Zaikin | 938af5e | 2020-12-03 19:09:53 +0000 | [diff] [blame] | 295 | pppoe_if.set_unnumbered(self.pg0.sw_if_index) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 296 | |
| 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 302 | tx2 = self.create_stream_ip4( |
| 303 | self.pg1, self.pg0, self.pg0.remote_ip4, self.dst_ip, 65 |
| 304 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 305 | 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 Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 316 | self.logger.info(self.vapi.cli("show adj")) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 317 | |
| 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 329 | """PPPoE Add Same Session Twice Test""" |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 330 | |
| 331 | self.vapi.cli("clear trace") |
| 332 | |
| 333 | # |
| 334 | # Add a route that resolves the server's destination |
| 335 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 336 | 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 Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 342 | route_sever_dst.add_vpp_config() |
| 343 | |
| 344 | # Send PPPoE Discovery |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 345 | tx0 = self.create_stream_pppoe_discovery( |
| 346 | self.pg0, self.pg1, self.pg0.remote_mac |
| 347 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 348 | self.pg0.add_stream(tx0) |
| 349 | self.pg_start() |
| 350 | |
| 351 | # Send PPPoE PPP LCP |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 352 | tx1 = self.create_stream_pppoe_lcp( |
| 353 | self.pg0, self.pg1, self.pg0.remote_mac, self.session_id |
| 354 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 355 | self.pg0.add_stream(tx1) |
| 356 | self.pg_start() |
| 357 | |
| 358 | # Create PPPoE session |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 359 | pppoe_if = VppPppoeInterface( |
| 360 | self, self.pg0.remote_ip4, self.pg0.remote_mac, self.session_id |
| 361 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 362 | pppoe_if.add_vpp_config() |
Stanislav Zaikin | 938af5e | 2020-12-03 19:09:53 +0000 | [diff] [blame] | 363 | pppoe_if.set_unnumbered(self.pg0.sw_if_index) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 364 | |
| 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 Ni | ad2ddb1 | 2017-11-17 23:43:11 +0800 | [diff] [blame] | 370 | pppoe_if.add_vpp_config() |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 371 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 387 | """PPPoE Delete Same Session Twice Test""" |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 388 | |
| 389 | self.vapi.cli("clear trace") |
| 390 | |
| 391 | # |
| 392 | # Add a route that resolves the server's destination |
| 393 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 394 | 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 Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 400 | route_sever_dst.add_vpp_config() |
| 401 | |
| 402 | # Send PPPoE Discovery |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 403 | tx0 = self.create_stream_pppoe_discovery( |
| 404 | self.pg0, self.pg1, self.pg0.remote_mac |
| 405 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 406 | self.pg0.add_stream(tx0) |
| 407 | self.pg_start() |
| 408 | |
| 409 | # Send PPPoE PPP LCP |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 410 | tx1 = self.create_stream_pppoe_lcp( |
| 411 | self.pg0, self.pg1, self.pg0.remote_mac, self.session_id |
| 412 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 413 | self.pg0.add_stream(tx1) |
| 414 | self.pg_start() |
| 415 | |
| 416 | # Create PPPoE session |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 417 | pppoe_if = VppPppoeInterface( |
| 418 | self, self.pg0.remote_ip4, self.pg0.remote_mac, self.session_id |
| 419 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 420 | 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 Ni | ad2ddb1 | 2017-11-17 23:43:11 +0800 | [diff] [blame] | 430 | pppoe_if.remove_vpp_config() |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 431 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 444 | """PPPoE Decap Multiple Sessions Test""" |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 445 | |
| 446 | self.vapi.cli("clear trace") |
| 447 | |
| 448 | # |
| 449 | # Add a route that resolves the server's destination |
| 450 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 451 | 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 Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 457 | route_sever_dst.add_vpp_config() |
| 458 | |
| 459 | # Send PPPoE Discovery 1 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 460 | tx0 = self.create_stream_pppoe_discovery( |
| 461 | self.pg0, self.pg1, self.pg0.remote_mac |
| 462 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 463 | self.pg0.add_stream(tx0) |
| 464 | self.pg_start() |
| 465 | |
| 466 | # Send PPPoE PPP LCP 1 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 467 | tx1 = self.create_stream_pppoe_lcp( |
| 468 | self.pg0, self.pg1, self.pg0.remote_mac, self.session_id |
| 469 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 470 | self.pg0.add_stream(tx1) |
| 471 | self.pg_start() |
| 472 | |
| 473 | # Create PPPoE session 1 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 474 | pppoe_if1 = VppPppoeInterface( |
| 475 | self, self.pg0.remote_ip4, self.pg0.remote_mac, self.session_id |
| 476 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 477 | pppoe_if1.add_vpp_config() |
Stanislav Zaikin | 938af5e | 2020-12-03 19:09:53 +0000 | [diff] [blame] | 478 | pppoe_if1.set_unnumbered(self.pg0.sw_if_index) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 479 | |
| 480 | # Send PPPoE Discovery 2 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 481 | tx3 = self.create_stream_pppoe_discovery( |
| 482 | self.pg2, self.pg1, self.pg2.remote_mac |
| 483 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 484 | self.pg2.add_stream(tx3) |
| 485 | self.pg_start() |
| 486 | |
| 487 | # Send PPPoE PPP LCP 2 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 488 | tx4 = self.create_stream_pppoe_lcp( |
| 489 | self.pg2, self.pg1, self.pg2.remote_mac, self.session_id + 1 |
| 490 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 491 | self.pg2.add_stream(tx4) |
| 492 | self.pg_start() |
| 493 | |
| 494 | # Create PPPoE session 2 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 495 | pppoe_if2 = VppPppoeInterface( |
| 496 | self, self.pg2.remote_ip4, self.pg2.remote_mac, self.session_id + 1 |
| 497 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 498 | pppoe_if2.add_vpp_config() |
Stanislav Zaikin | 938af5e | 2020-12-03 19:09:53 +0000 | [diff] [blame] | 499 | pppoe_if2.set_unnumbered(self.pg0.sw_if_index) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 500 | |
| 501 | # |
| 502 | # Send tunneled packets that match the created tunnel and |
| 503 | # are decapped and forwarded |
| 504 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 505 | 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 Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 512 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 520 | 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 Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 527 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 551 | """PPPoE Encap Multiple Sessions Test""" |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 552 | |
| 553 | self.vapi.cli("clear trace") |
| 554 | |
| 555 | # |
| 556 | # Add a route that resolves the server's destination |
| 557 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 558 | 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 Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 564 | route_sever_dst.add_vpp_config() |
| 565 | |
| 566 | # Send PPPoE Discovery 1 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 567 | tx0 = self.create_stream_pppoe_discovery( |
| 568 | self.pg0, self.pg1, self.pg0.remote_mac |
| 569 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 570 | self.pg0.add_stream(tx0) |
| 571 | self.pg_start() |
| 572 | |
| 573 | # Send PPPoE PPP LCP 1 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 574 | tx1 = self.create_stream_pppoe_lcp( |
| 575 | self.pg0, self.pg1, self.pg0.remote_mac, self.session_id |
| 576 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 577 | self.pg0.add_stream(tx1) |
| 578 | self.pg_start() |
| 579 | |
| 580 | # Create PPPoE session 1 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 581 | pppoe_if1 = VppPppoeInterface( |
| 582 | self, self.pg0.remote_ip4, self.pg0.remote_mac, self.session_id |
| 583 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 584 | pppoe_if1.add_vpp_config() |
| 585 | |
| 586 | # Send PPPoE Discovery 2 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 587 | tx3 = self.create_stream_pppoe_discovery( |
| 588 | self.pg2, self.pg1, self.pg2.remote_mac |
| 589 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 590 | self.pg2.add_stream(tx3) |
| 591 | self.pg_start() |
| 592 | |
| 593 | # Send PPPoE PPP LCP 2 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 594 | tx4 = self.create_stream_pppoe_lcp( |
| 595 | self.pg2, self.pg1, self.pg2.remote_mac, self.session_id + 1 |
| 596 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 597 | self.pg2.add_stream(tx4) |
| 598 | self.pg_start() |
| 599 | |
| 600 | # Create PPPoE session 2 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 601 | pppoe_if2 = VppPppoeInterface( |
| 602 | self, self.pg2.remote_ip4, self.pg2.remote_mac, self.session_id + 1 |
| 603 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 604 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 611 | tx2 = self.create_stream_ip4( |
| 612 | self.pg1, self.pg0, self.pg0.remote_ip4, self.dst_ip |
| 613 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 614 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 622 | tx5 = self.create_stream_ip4( |
| 623 | self.pg1, self.pg2, self.pg2.remote_ip4, self.dst_ip |
| 624 | ) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 625 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 648 | |
| 649 | if __name__ == "__main__": |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 650 | unittest.main(testRunner=VppTestRunner) |