Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | import random |
| 3 | import unittest |
| 4 | import datetime |
| 5 | import re |
| 6 | |
| 7 | from scapy.packet import Raw |
| 8 | from scapy.layers.l2 import Ether |
| 9 | from scapy.layers.inet import IP, UDP |
| 10 | from scapy.layers.inet6 import IPv6 |
| 11 | |
Gabriel Ganne | 7e665d6 | 2017-11-17 09:18:53 +0100 | [diff] [blame] | 12 | from framework import VppTestCase, VppTestRunner |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 13 | from vpp_sub_interface import VppP2PSubint |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 14 | from vpp_ip import DpoProto |
| 15 | from vpp_ip_route import VppIpRoute, VppRoutePath |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 16 | from vpp_papi import mac_pton |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 17 | |
| 18 | |
| 19 | class P2PEthernetAPI(VppTestCase): |
| 20 | """P2P Ethernet tests""" |
| 21 | |
| 22 | p2p_sub_ifs = [] |
| 23 | |
| 24 | @classmethod |
| 25 | def setUpClass(cls): |
| 26 | super(P2PEthernetAPI, cls).setUpClass() |
| 27 | |
| 28 | # Create pg interfaces |
| 29 | cls.create_pg_interfaces(range(4)) |
| 30 | |
| 31 | # Set up all interfaces |
| 32 | for i in cls.pg_interfaces: |
| 33 | i.admin_up() |
| 34 | |
| 35 | def create_p2p_ethernet(self, parent_if, sub_id, remote_mac): |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 36 | p2p = VppP2PSubint(self, parent_if, sub_id, mac_pton(remote_mac)) |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 37 | self.p2p_sub_ifs.append(p2p) |
| 38 | |
| 39 | def delete_p2p_ethernet(self, parent_if, remote_mac): |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 40 | self.vapi.p2p_ethernet_del(parent_if.sw_if_index, |
| 41 | mac_pton(remote_mac)) |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 42 | |
| 43 | def test_api(self): |
| 44 | """delete/create p2p subif""" |
| 45 | self.logger.info("FFP_TEST_START_0000") |
| 46 | |
| 47 | self.create_p2p_ethernet(self.pg0, 1, "de:ad:00:00:00:01") |
| 48 | self.create_p2p_ethernet(self.pg0, 2, "de:ad:00:00:00:02") |
| 49 | intfs = self.vapi.cli("show interface") |
| 50 | |
Paul Vinciguerra | 9a6dafd | 2019-03-06 15:11:28 -0800 | [diff] [blame^] | 51 | self.assertIn('pg0.1', intfs) |
| 52 | self.assertIn('pg0.2', intfs) |
| 53 | self.assertNotIn('pg0.5', intfs) |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 54 | |
| 55 | # create pg2.5 subif |
| 56 | self.create_p2p_ethernet(self.pg0, 5, "de:ad:00:00:00:ff") |
| 57 | intfs = self.vapi.cli("show interface") |
Paul Vinciguerra | 9a6dafd | 2019-03-06 15:11:28 -0800 | [diff] [blame^] | 58 | self.assertIn('pg0.5', intfs) |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 59 | # delete pg2.5 subif |
| 60 | self.delete_p2p_ethernet(self.pg0, "de:ad:00:00:00:ff") |
| 61 | |
| 62 | intfs = self.vapi.cli("show interface") |
| 63 | |
Paul Vinciguerra | 9a6dafd | 2019-03-06 15:11:28 -0800 | [diff] [blame^] | 64 | self.assertIn('pg0.1', intfs) |
| 65 | self.assertIn('pg0.2', intfs) |
| 66 | self.assertNotIn('pg0.5', intfs) |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 67 | |
| 68 | self.logger.info("FFP_TEST_FINISH_0000") |
| 69 | |
| 70 | def test_p2p_subif_creation_1k(self): |
| 71 | """create 1k of p2p subifs""" |
| 72 | self.logger.info("FFP_TEST_START_0001") |
| 73 | |
| 74 | macs = [] |
| 75 | clients = 1000 |
| 76 | mac = int("dead00000000", 16) |
| 77 | |
| 78 | for i in range(1, clients+1): |
| 79 | try: |
Paul Vinciguerra | ea2450f | 2019-03-06 08:23:58 -0800 | [diff] [blame] | 80 | macs.append(':'.join(re.findall('..', '{:02x}'.format( |
| 81 | mac+i)))) |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 82 | self.vapi.p2p_ethernet_add(self.pg2.sw_if_index, |
| 83 | mac_pton(macs[i-1]), |
| 84 | i) |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 85 | except Exception: |
Paul Vinciguerra | 661f91f | 2018-11-28 19:06:41 -0800 | [diff] [blame] | 86 | self.logger.info("Failed to create subif %d %s" % ( |
| 87 | i, macs[i-1])) |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 88 | raise |
| 89 | |
| 90 | intfs = self.vapi.cli("show interface").split("\n") |
| 91 | count = 0 |
| 92 | for intf in intfs: |
| 93 | if intf.startswith('pg2.'): |
| 94 | count += 1 |
| 95 | self.assertEqual(count, clients) |
| 96 | |
| 97 | self.logger.info("FFP_TEST_FINISH_0001") |
| 98 | |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 99 | |
| 100 | class P2PEthernetIPV6(VppTestCase): |
| 101 | """P2P Ethernet IPv6 tests""" |
| 102 | |
| 103 | p2p_sub_ifs = [] |
| 104 | packets = [] |
| 105 | |
| 106 | @classmethod |
| 107 | def setUpClass(cls): |
| 108 | super(P2PEthernetIPV6, cls).setUpClass() |
| 109 | |
| 110 | # Create pg interfaces |
| 111 | cls.create_pg_interfaces(range(3)) |
| 112 | |
| 113 | # Packet sizes |
| 114 | cls.pg_if_packet_sizes = [64, 512, 1518, 9018] |
| 115 | |
| 116 | # Set up all interfaces |
| 117 | for i in cls.pg_interfaces: |
| 118 | i.admin_up() |
| 119 | |
| 120 | cls.pg0.generate_remote_hosts(3) |
| 121 | cls.pg0.configure_ipv6_neighbors() |
| 122 | |
| 123 | cls.pg1.config_ip6() |
| 124 | cls.pg1.generate_remote_hosts(3) |
| 125 | cls.pg1.configure_ipv6_neighbors() |
| 126 | cls.pg1.disable_ipv6_ra() |
| 127 | |
| 128 | def setUp(self): |
| 129 | super(P2PEthernetIPV6, self).setUp() |
| 130 | for p in self.packets: |
| 131 | self.packets.remove(p) |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 132 | self.p2p_sub_ifs.append( |
| 133 | self.create_p2p_ethernet(self.pg0, 1, |
| 134 | self.pg0._remote_hosts[0].mac)) |
| 135 | self.p2p_sub_ifs.append( |
| 136 | self.create_p2p_ethernet(self.pg0, 2, |
| 137 | self.pg0._remote_hosts[1].mac)) |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 138 | self.vapi.cli("trace add p2p-ethernet-input 50") |
| 139 | |
| 140 | def tearDown(self): |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 141 | while len(self.p2p_sub_ifs): |
| 142 | p2p = self.p2p_sub_ifs.pop() |
| 143 | self.delete_p2p_ethernet(p2p) |
| 144 | |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 145 | super(P2PEthernetIPV6, self).tearDown() |
| 146 | |
| 147 | def create_p2p_ethernet(self, parent_if, sub_id, remote_mac): |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 148 | p2p = VppP2PSubint(self, parent_if, sub_id, mac_pton(remote_mac)) |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 149 | p2p.admin_up() |
| 150 | p2p.config_ip6() |
| 151 | p2p.disable_ipv6_ra() |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 152 | return p2p |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 153 | |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 154 | def delete_p2p_ethernet(self, p2p): |
| 155 | p2p.unconfig_ip6() |
| 156 | p2p.admin_down() |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 157 | self.vapi.p2p_ethernet_del(p2p.parent.sw_if_index, |
| 158 | p2p.p2p_remote_mac) |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 159 | |
| 160 | def create_stream(self, src_mac=None, dst_mac=None, |
| 161 | src_ip=None, dst_ip=None, size=None): |
| 162 | pkt_size = size |
| 163 | if size is None: |
| 164 | pkt_size = random.choice(self.pg_if_packet_sizes) |
| 165 | p = Ether(src=src_mac, dst=dst_mac) |
| 166 | p /= IPv6(src=src_ip, dst=dst_ip) |
| 167 | p /= (UDP(sport=1234, dport=4321) / Raw('\xa5' * 20)) |
| 168 | self.extend_packet(p, pkt_size) |
| 169 | return p |
| 170 | |
| 171 | def send_packets(self, src_if=None, dst_if=None, packets=None, count=None): |
| 172 | self.pg_enable_capture([dst_if]) |
| 173 | if packets is None: |
| 174 | packets = self.packets |
| 175 | src_if.add_stream(packets) |
| 176 | self.pg_start() |
| 177 | if count is None: |
| 178 | count = len(packets) |
| 179 | return dst_if.get_capture(count) |
| 180 | |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 181 | def test_no_p2p_subif(self): |
| 182 | """standard routing without p2p subinterfaces""" |
| 183 | self.logger.info("FFP_TEST_START_0001") |
| 184 | |
| 185 | route_8000 = VppIpRoute(self, "8000::", 64, |
| 186 | [VppRoutePath(self.pg0.remote_ip6, |
| 187 | self.pg0.sw_if_index, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 188 | proto=DpoProto.DPO_PROTO_IP6)], |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 189 | is_ip6=1) |
| 190 | route_8000.add_vpp_config() |
| 191 | |
| 192 | self.packets = [(Ether(dst=self.pg1.local_mac, |
| 193 | src=self.pg1.remote_mac) / |
| 194 | IPv6(src="3001::1", dst="8000::100") / |
| 195 | UDP(sport=1234, dport=1234) / |
| 196 | Raw('\xa5' * 100))] |
| 197 | self.send_packets(self.pg1, self.pg0) |
| 198 | |
| 199 | self.logger.info("FFP_TEST_FINISH_0001") |
| 200 | |
| 201 | def test_ip6_rx_p2p_subif(self): |
| 202 | """receive ipv6 packet via p2p subinterface""" |
| 203 | self.logger.info("FFP_TEST_START_0002") |
| 204 | |
| 205 | route_9001 = VppIpRoute(self, "9001::", 64, |
| 206 | [VppRoutePath(self.pg1.remote_ip6, |
| 207 | self.pg1.sw_if_index, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 208 | proto=DpoProto.DPO_PROTO_IP6)], |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 209 | is_ip6=1) |
| 210 | route_9001.add_vpp_config() |
| 211 | |
| 212 | self.packets.append( |
| 213 | self.create_stream(src_mac=self.pg0._remote_hosts[0].mac, |
| 214 | dst_mac=self.pg0.local_mac, |
| 215 | src_ip=self.p2p_sub_ifs[0].remote_ip6, |
| 216 | dst_ip="9001::100")) |
| 217 | |
| 218 | self.send_packets(self.pg0, self.pg1, self.packets) |
Klement Sekera | f37c3ba | 2018-11-08 11:24:34 +0100 | [diff] [blame] | 219 | self.assert_packet_counter_equal('p2p-ethernet-input', 1) |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 220 | |
| 221 | route_9001.remove_vpp_config() |
| 222 | self.logger.info("FFP_TEST_FINISH_0002") |
| 223 | |
| 224 | def test_ip6_rx_p2p_subif_route(self): |
| 225 | """route rx ip6 packet not matching p2p subinterface""" |
| 226 | self.logger.info("FFP_TEST_START_0003") |
| 227 | |
| 228 | self.pg0.config_ip6() |
| 229 | |
| 230 | route_3 = VppIpRoute(self, "9000::", 64, |
| 231 | [VppRoutePath(self.pg1._remote_hosts[0].ip6, |
| 232 | self.pg1.sw_if_index, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 233 | proto=DpoProto.DPO_PROTO_IP6)], |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 234 | is_ip6=1) |
| 235 | route_3.add_vpp_config() |
| 236 | |
| 237 | self.packets.append( |
| 238 | self.create_stream(src_mac="02:03:00:00:ff:ff", |
| 239 | dst_mac=self.pg0.local_mac, |
| 240 | src_ip="a000::100", |
| 241 | dst_ip="9000::100")) |
| 242 | |
| 243 | self.send_packets(self.pg0, self.pg1) |
| 244 | |
| 245 | self.pg0.unconfig_ip6() |
| 246 | |
| 247 | route_3.remove_vpp_config() |
| 248 | |
| 249 | self.logger.info("FFP_TEST_FINISH_0003") |
| 250 | |
| 251 | def test_ip6_rx_p2p_subif_drop(self): |
| 252 | """drop rx packet not matching p2p subinterface""" |
| 253 | self.logger.info("FFP_TEST_START_0004") |
| 254 | |
| 255 | route_9001 = VppIpRoute(self, "9000::", 64, |
| 256 | [VppRoutePath(self.pg1._remote_hosts[0].ip6, |
| 257 | self.pg1.sw_if_index, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 258 | proto=DpoProto.DPO_PROTO_IP6)], |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 259 | is_ip6=1) |
| 260 | route_9001.add_vpp_config() |
| 261 | |
| 262 | self.packets.append( |
| 263 | self.create_stream(src_mac="02:03:00:00:ff:ff", |
| 264 | dst_mac=self.pg0.local_mac, |
| 265 | src_ip="a000::100", |
| 266 | dst_ip="9000::100")) |
| 267 | |
| 268 | # no packet received |
| 269 | self.send_packets(self.pg0, self.pg1, count=0) |
| 270 | self.logger.info("FFP_TEST_FINISH_0004") |
| 271 | |
| 272 | def test_ip6_tx_p2p_subif(self): |
| 273 | """send packet via p2p subinterface""" |
| 274 | self.logger.info("FFP_TEST_START_0005") |
| 275 | |
| 276 | route_8000 = VppIpRoute(self, "8000::", 64, |
| 277 | [VppRoutePath(self.pg0.remote_ip6, |
| 278 | self.pg0.sw_if_index, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 279 | proto=DpoProto.DPO_PROTO_IP6)], |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 280 | is_ip6=1) |
| 281 | route_8000.add_vpp_config() |
| 282 | route_8001 = VppIpRoute(self, "8001::", 64, |
| 283 | [VppRoutePath(self.p2p_sub_ifs[0].remote_ip6, |
| 284 | self.p2p_sub_ifs[0].sw_if_index, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 285 | proto=DpoProto.DPO_PROTO_IP6)], |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 286 | is_ip6=1) |
| 287 | route_8001.add_vpp_config() |
| 288 | route_8002 = VppIpRoute(self, "8002::", 64, |
| 289 | [VppRoutePath(self.p2p_sub_ifs[1].remote_ip6, |
| 290 | self.p2p_sub_ifs[1].sw_if_index, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 291 | proto=DpoProto.DPO_PROTO_IP6)], |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 292 | is_ip6=1) |
| 293 | route_8002.add_vpp_config() |
| 294 | |
| 295 | for i in range(0, 3): |
| 296 | self.packets.append( |
| 297 | self.create_stream(src_mac=self.pg1.remote_mac, |
| 298 | dst_mac=self.pg1.local_mac, |
| 299 | src_ip=self.pg1.remote_ip6, |
| 300 | dst_ip="800%d::100" % i)) |
| 301 | |
| 302 | self.send_packets(self.pg1, self.pg0, count=3) |
| 303 | |
| 304 | route_8000.remove_vpp_config() |
| 305 | route_8001.remove_vpp_config() |
| 306 | route_8002.remove_vpp_config() |
| 307 | |
| 308 | self.logger.info("FFP_TEST_FINISH_0005") |
| 309 | |
| 310 | def test_ip6_tx_p2p_subif_drop(self): |
| 311 | """drop tx ip6 packet not matching p2p subinterface""" |
| 312 | self.logger.info("FFP_TEST_START_0006") |
| 313 | |
| 314 | self.packets.append( |
| 315 | self.create_stream(src_mac="02:03:00:00:ff:ff", |
| 316 | dst_mac=self.pg0.local_mac, |
| 317 | src_ip="a000::100", |
| 318 | dst_ip="9000::100")) |
| 319 | |
| 320 | # no packet received |
| 321 | self.send_packets(self.pg0, self.pg1, count=0) |
| 322 | self.logger.info("FFP_TEST_FINISH_0006") |
| 323 | |
| 324 | |
| 325 | class P2PEthernetIPV4(VppTestCase): |
| 326 | """P2P Ethernet IPv4 tests""" |
| 327 | |
| 328 | p2p_sub_ifs = [] |
| 329 | packets = [] |
| 330 | |
| 331 | @classmethod |
| 332 | def setUpClass(cls): |
| 333 | super(P2PEthernetIPV4, cls).setUpClass() |
| 334 | |
| 335 | # Create pg interfaces |
| 336 | cls.create_pg_interfaces(range(3)) |
| 337 | |
| 338 | # Packet sizes |
| 339 | cls.pg_if_packet_sizes = [64, 512, 1518, 9018] |
| 340 | |
| 341 | # Set up all interfaces |
| 342 | for i in cls.pg_interfaces: |
| 343 | i.admin_up() |
| 344 | |
| 345 | cls.pg0.config_ip4() |
| 346 | cls.pg0.generate_remote_hosts(5) |
| 347 | cls.pg0.configure_ipv4_neighbors() |
| 348 | |
| 349 | cls.pg1.config_ip4() |
| 350 | cls.pg1.generate_remote_hosts(5) |
| 351 | cls.pg1.configure_ipv4_neighbors() |
| 352 | |
| 353 | def setUp(self): |
| 354 | super(P2PEthernetIPV4, self).setUp() |
| 355 | for p in self.packets: |
| 356 | self.packets.remove(p) |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 357 | self.p2p_sub_ifs.append( |
| 358 | self.create_p2p_ethernet(self.pg0, 1, |
| 359 | self.pg0._remote_hosts[0].mac)) |
| 360 | self.p2p_sub_ifs.append( |
| 361 | self.create_p2p_ethernet(self.pg0, 2, |
| 362 | self.pg0._remote_hosts[1].mac)) |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 363 | self.vapi.cli("trace add p2p-ethernet-input 50") |
| 364 | |
| 365 | def tearDown(self): |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 366 | while len(self.p2p_sub_ifs): |
| 367 | p2p = self.p2p_sub_ifs.pop() |
| 368 | self.delete_p2p_ethernet(p2p) |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 369 | super(P2PEthernetIPV4, self).tearDown() |
| 370 | |
| 371 | def create_stream(self, src_mac=None, dst_mac=None, |
| 372 | src_ip=None, dst_ip=None, size=None): |
| 373 | pkt_size = size |
| 374 | if size is None: |
| 375 | pkt_size = random.choice(self.pg_if_packet_sizes) |
| 376 | p = Ether(src=src_mac, dst=dst_mac) |
| 377 | p /= IP(src=src_ip, dst=dst_ip) |
| 378 | p /= (UDP(sport=1234, dport=4321) / Raw('\xa5' * 20)) |
| 379 | self.extend_packet(p, pkt_size) |
| 380 | return p |
| 381 | |
| 382 | def send_packets(self, src_if=None, dst_if=None, packets=None, count=None): |
| 383 | self.pg_enable_capture([dst_if]) |
| 384 | if packets is None: |
| 385 | packets = self.packets |
| 386 | src_if.add_stream(packets) |
| 387 | self.pg_start() |
| 388 | if count is None: |
| 389 | count = len(packets) |
| 390 | return dst_if.get_capture(count) |
| 391 | |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 392 | def create_p2p_ethernet(self, parent_if, sub_id, remote_mac): |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 393 | p2p = VppP2PSubint(self, parent_if, sub_id, mac_pton(remote_mac)) |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 394 | p2p.admin_up() |
| 395 | p2p.config_ip4() |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 396 | return p2p |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 397 | |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 398 | def delete_p2p_ethernet(self, p2p): |
| 399 | p2p.unconfig_ip4() |
| 400 | p2p.admin_down() |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 401 | self.vapi.p2p_ethernet_del(p2p.parent.sw_if_index, |
| 402 | p2p.p2p_remote_mac) |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 403 | |
| 404 | def test_ip4_rx_p2p_subif(self): |
| 405 | """receive ipv4 packet via p2p subinterface""" |
| 406 | self.logger.info("FFP_TEST_START_0002") |
| 407 | |
| 408 | route_9000 = VppIpRoute(self, "9.0.0.0", 16, |
| 409 | [VppRoutePath(self.pg1.remote_ip4, |
| 410 | self.pg1.sw_if_index)]) |
| 411 | route_9000.add_vpp_config() |
| 412 | |
| 413 | self.packets.append( |
| 414 | self.create_stream(src_mac=self.pg0._remote_hosts[0].mac, |
| 415 | dst_mac=self.pg0.local_mac, |
| 416 | src_ip=self.p2p_sub_ifs[0].remote_ip4, |
| 417 | dst_ip="9.0.0.100")) |
| 418 | |
| 419 | self.send_packets(self.pg0, self.pg1, self.packets) |
| 420 | |
Klement Sekera | f37c3ba | 2018-11-08 11:24:34 +0100 | [diff] [blame] | 421 | self.assert_packet_counter_equal('p2p-ethernet-input', 1) |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 422 | |
| 423 | route_9000.remove_vpp_config() |
| 424 | self.logger.info("FFP_TEST_FINISH_0002") |
| 425 | |
| 426 | def test_ip4_rx_p2p_subif_route(self): |
| 427 | """route rx packet not matching p2p subinterface""" |
| 428 | self.logger.info("FFP_TEST_START_0003") |
| 429 | |
| 430 | route_9001 = VppIpRoute(self, "9.0.0.0", 24, |
| 431 | [VppRoutePath(self.pg1.remote_ip4, |
| 432 | self.pg1.sw_if_index)]) |
| 433 | route_9001.add_vpp_config() |
| 434 | |
| 435 | self.packets.append( |
| 436 | self.create_stream(src_mac="02:01:00:00:ff:ff", |
| 437 | dst_mac=self.pg0.local_mac, |
| 438 | src_ip="8.0.0.100", |
| 439 | dst_ip="9.0.0.100")) |
| 440 | |
| 441 | self.send_packets(self.pg0, self.pg1) |
| 442 | |
| 443 | route_9001.remove_vpp_config() |
| 444 | |
| 445 | self.logger.info("FFP_TEST_FINISH_0003") |
| 446 | |
| 447 | def test_ip4_tx_p2p_subif(self): |
| 448 | """send ip4 packet via p2p subinterface""" |
| 449 | self.logger.info("FFP_TEST_START_0005") |
| 450 | |
| 451 | route_9100 = VppIpRoute(self, "9.1.0.100", 24, |
| 452 | [VppRoutePath(self.pg0.remote_ip4, |
| 453 | self.pg0.sw_if_index, |
| 454 | )]) |
| 455 | route_9100.add_vpp_config() |
| 456 | route_9200 = VppIpRoute(self, "9.2.0.100", 24, |
| 457 | [VppRoutePath(self.p2p_sub_ifs[0].remote_ip4, |
| 458 | self.p2p_sub_ifs[0].sw_if_index, |
| 459 | )]) |
| 460 | route_9200.add_vpp_config() |
| 461 | route_9300 = VppIpRoute(self, "9.3.0.100", 24, |
| 462 | [VppRoutePath(self.p2p_sub_ifs[1].remote_ip4, |
| 463 | self.p2p_sub_ifs[1].sw_if_index |
| 464 | )]) |
| 465 | route_9300.add_vpp_config() |
| 466 | |
| 467 | for i in range(0, 3): |
| 468 | self.packets.append( |
| 469 | self.create_stream(src_mac=self.pg1.remote_mac, |
| 470 | dst_mac=self.pg1.local_mac, |
| 471 | src_ip=self.pg1.remote_ip4, |
| 472 | dst_ip="9.%d.0.100" % (i+1))) |
| 473 | |
| 474 | self.send_packets(self.pg1, self.pg0) |
| 475 | |
| 476 | # route_7000.remove_vpp_config() |
| 477 | route_9100.remove_vpp_config() |
| 478 | route_9200.remove_vpp_config() |
| 479 | route_9300.remove_vpp_config() |
| 480 | |
| 481 | self.logger.info("FFP_TEST_FINISH_0005") |
| 482 | |
| 483 | def test_ip4_tx_p2p_subif_drop(self): |
| 484 | """drop tx ip4 packet not matching p2p subinterface""" |
| 485 | self.logger.info("FFP_TEST_START_0006") |
| 486 | |
| 487 | self.packets.append( |
| 488 | self.create_stream(src_mac="02:01:00:00:ff:ff", |
| 489 | dst_mac=self.pg0.local_mac, |
| 490 | src_ip="8.0.0.100", |
| 491 | dst_ip="9.0.0.100")) |
| 492 | |
| 493 | # no packet received |
| 494 | self.send_packets(self.pg0, self.pg1, count=0) |
| 495 | self.logger.info("FFP_TEST_FINISH_0006") |
| 496 | |
| 497 | |
| 498 | if __name__ == '__main__': |
| 499 | unittest.main(testRunner=VppTestRunner) |