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