Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 2 | import random |
| 3 | import socket |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 4 | import os |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 5 | import threading |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 6 | import copy |
Andrew Yourtchenko | 3f8c871 | 2019-11-05 19:38:08 +0100 | [diff] [blame] | 7 | import fcntl |
| 8 | import time |
| 9 | |
Paul Vinciguerra | 22ab6f7 | 2019-03-07 17:55:33 -0800 | [diff] [blame] | 10 | try: |
| 11 | import unittest2 as unittest |
| 12 | except ImportError: |
| 13 | import unittest |
| 14 | |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 15 | from scapy.packet import Raw |
| 16 | from scapy.layers.l2 import Ether |
Andrew Yourtchenko | feb7742 | 2023-03-17 01:47:58 +0000 | [diff] [blame] | 17 | from scapy.layers.l2 import Dot1Q |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 18 | from scapy.layers.inet import IP, UDP, ICMP |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 19 | from scapy.layers.ipsec import ESP |
Paul Vinciguerra | 22ab6f7 | 2019-03-07 17:55:33 -0800 | [diff] [blame] | 20 | import scapy.layers.inet6 as inet6 |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 21 | from scapy.layers.inet6 import IPv6 |
Neale Ranns | b538dd8 | 2019-05-21 06:54:54 -0700 | [diff] [blame] | 22 | from scapy.contrib.ospf import OSPF_Hdr, OSPFv3_Hello |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 23 | from framework import VppTestCase |
| 24 | from asfframework import VppTestRunner, tag_fixme_vpp_workers |
| 25 | from vpp_sub_interface import VppDot1QSubint |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 26 | |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 27 | from vpp_ip import DpoProto |
| 28 | from vpp_ip_route import VppIpRoute, VppRoutePath |
Neale Ranns | a9e2774 | 2020-12-23 16:22:28 +0000 | [diff] [blame] | 29 | from vpp_ipsec import VppIpsecSA, VppIpsecTunProtect, VppIpsecInterface |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 30 | from vpp_papi import VppEnum |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 31 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 32 | NUM_PKTS = 67 |
| 33 | |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 34 | |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 35 | class serverSocketThread(threading.Thread): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 36 | """Socket server thread""" |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 37 | |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 38 | def __init__(self, threadID, sockName): |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 39 | threading.Thread.__init__(self) |
| 40 | self.threadID = threadID |
| 41 | self.sockName = sockName |
| 42 | self.sock = None |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 43 | self.rx_pkts = [] |
Dave Wallace | c44402f | 2021-05-07 21:40:54 -0400 | [diff] [blame] | 44 | self.stop_running = False |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 45 | |
| 46 | def rx_packets(self): |
| 47 | # Wait for some packets on socket |
Dave Wallace | c44402f | 2021-05-07 21:40:54 -0400 | [diff] [blame] | 48 | while True: |
Andrew Yourtchenko | 3f8c871 | 2019-11-05 19:38:08 +0100 | [diff] [blame] | 49 | try: |
| 50 | data = self.sock.recv(65536) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 51 | |
Andrew Yourtchenko | 3f8c871 | 2019-11-05 19:38:08 +0100 | [diff] [blame] | 52 | # punt socket metadata |
| 53 | # packet_desc = data[0:8] |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 54 | |
Andrew Yourtchenko | 3f8c871 | 2019-11-05 19:38:08 +0100 | [diff] [blame] | 55 | # Ethernet |
| 56 | self.rx_pkts.append(Ether(data[8:])) |
| 57 | except IOError as e: |
| 58 | if e.errno == 11: |
Dave Wallace | c44402f | 2021-05-07 21:40:54 -0400 | [diff] [blame] | 59 | # nothing to receive, stop running or sleep a little |
| 60 | if self.stop_running: |
| 61 | break |
Andrew Yourtchenko | 3f8c871 | 2019-11-05 19:38:08 +0100 | [diff] [blame] | 62 | time.sleep(0.1) |
| 63 | pass |
| 64 | else: |
| 65 | raise |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 66 | |
| 67 | def run(self): |
| 68 | self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) |
| 69 | try: |
| 70 | os.unlink(self.sockName) |
| 71 | except: |
| 72 | pass |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 73 | self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 65536) |
| 74 | self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 65536) |
Andrew Yourtchenko | 3f8c871 | 2019-11-05 19:38:08 +0100 | [diff] [blame] | 75 | fcntl.fcntl(self.sock, fcntl.F_SETFL, os.O_NONBLOCK) |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 76 | self.sock.bind(self.sockName) |
| 77 | |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 78 | self.rx_packets() |
| 79 | |
| 80 | def close(self): |
Dave Wallace | c44402f | 2021-05-07 21:40:54 -0400 | [diff] [blame] | 81 | self.stop_running = True |
Dave Wallace | f4d338f | 2021-05-06 15:59:59 -0400 | [diff] [blame] | 82 | threading.Thread.join(self) |
Dave Wallace | c44402f | 2021-05-07 21:40:54 -0400 | [diff] [blame] | 83 | self.sock.close() |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 84 | return self.rx_pkts |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 85 | |
| 86 | |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 87 | class TestPuntSocket(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 88 | """Punt Socket""" |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 89 | |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 90 | ports = [1111, 2222, 3333, 4444] |
| 91 | sock_servers = list() |
Andrew Yourtchenko | cb265c6 | 2019-07-25 10:03:51 +0000 | [diff] [blame] | 92 | # FIXME: nr_packets > 3 results in failure |
| 93 | # nr_packets = 3 makes the test unstable |
| 94 | nr_packets = 2 |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 95 | |
| 96 | @classmethod |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 97 | def setUpClass(cls): |
| 98 | super(TestPuntSocket, cls).setUpClass() |
| 99 | |
| 100 | @classmethod |
| 101 | def tearDownClass(cls): |
| 102 | super(TestPuntSocket, cls).tearDownClass() |
| 103 | |
| 104 | @classmethod |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 105 | def setUpConstants(cls): |
Klement Sekera | d3e0d10 | 2023-01-26 12:35:35 +0100 | [diff] [blame] | 106 | cls.extra_vpp_config = [ |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 107 | "punt", |
| 108 | "{", |
| 109 | "socket", |
| 110 | cls.tempdir + "/socket_punt", |
| 111 | "}", |
| 112 | ] |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 113 | super(TestPuntSocket, cls).setUpConstants() |
| 114 | |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 115 | def setUp(self): |
| 116 | super(TestPuntSocket, self).setUp() |
| 117 | random.seed() |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 118 | |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 119 | self.create_pg_interfaces(range(2)) |
| 120 | for i in self.pg_interfaces: |
| 121 | i.admin_up() |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 122 | |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 123 | def tearDown(self): |
| 124 | del self.sock_servers[:] |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 125 | super(TestPuntSocket, self).tearDown() |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 126 | |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 127 | def socket_client_create(self, sock_name, id=None): |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 128 | thread = serverSocketThread(id, sock_name) |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 129 | self.sock_servers.append(thread) |
| 130 | thread.start() |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 131 | return thread |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 132 | |
| 133 | def socket_client_close(self): |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 134 | rx_pkts = [] |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 135 | for thread in self.sock_servers: |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 136 | rx_pkts += thread.close() |
| 137 | return rx_pkts |
| 138 | |
| 139 | def verify_port(self, pr, vpr): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 140 | self.assertEqual(vpr.punt.type, pr["type"]) |
| 141 | self.assertEqual(vpr.punt.punt.l4.port, pr["punt"]["l4"]["port"]) |
| 142 | self.assertEqual(vpr.punt.punt.l4.protocol, pr["punt"]["l4"]["protocol"]) |
| 143 | self.assertEqual(vpr.punt.punt.l4.af, pr["punt"]["l4"]["af"]) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 144 | |
| 145 | def verify_exception(self, pr, vpr): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 146 | self.assertEqual(vpr.punt.type, pr["type"]) |
| 147 | self.assertEqual(vpr.punt.punt.exception.id, pr["punt"]["exception"]["id"]) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 148 | |
Neale Ranns | b538dd8 | 2019-05-21 06:54:54 -0700 | [diff] [blame] | 149 | def verify_ip_proto(self, pr, vpr): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 150 | self.assertEqual(vpr.punt.type, pr["type"]) |
| 151 | self.assertEqual(vpr.punt.punt.ip_proto.af, pr["punt"]["ip_proto"]["af"]) |
| 152 | self.assertEqual( |
| 153 | vpr.punt.punt.ip_proto.protocol, pr["punt"]["ip_proto"]["protocol"] |
| 154 | ) |
Neale Ranns | b538dd8 | 2019-05-21 06:54:54 -0700 | [diff] [blame] | 155 | |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 156 | def verify_udp_pkts(self, rxs, n_rx, port): |
| 157 | n_match = 0 |
| 158 | for rx in rxs: |
| 159 | self.assertTrue(rx.haslayer(UDP)) |
| 160 | if rx[UDP].dport == port: |
| 161 | n_match += 1 |
| 162 | self.assertEqual(n_match, n_rx) |
| 163 | |
| 164 | |
| 165 | def set_port(pr, port): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 166 | pr["punt"]["l4"]["port"] = port |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 167 | return pr |
| 168 | |
| 169 | |
| 170 | def set_reason(pr, reason): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 171 | pr["punt"]["exception"]["id"] = reason |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 172 | return pr |
| 173 | |
| 174 | |
| 175 | def mk_vpp_cfg4(): |
| 176 | pt_l4 = VppEnum.vl_api_punt_type_t.PUNT_API_TYPE_L4 |
| 177 | af_ip4 = VppEnum.vl_api_address_family_t.ADDRESS_IP4 |
| 178 | udp_proto = VppEnum.vl_api_ip_proto_t.IP_API_PROTO_UDP |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 179 | punt_l4 = {"type": pt_l4, "punt": {"l4": {"af": af_ip4, "protocol": udp_proto}}} |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 180 | return punt_l4 |
| 181 | |
| 182 | |
| 183 | def mk_vpp_cfg6(): |
| 184 | pt_l4 = VppEnum.vl_api_punt_type_t.PUNT_API_TYPE_L4 |
| 185 | af_ip6 = VppEnum.vl_api_address_family_t.ADDRESS_IP6 |
| 186 | udp_proto = VppEnum.vl_api_ip_proto_t.IP_API_PROTO_UDP |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 187 | punt_l4 = {"type": pt_l4, "punt": {"l4": {"af": af_ip6, "protocol": udp_proto}}} |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 188 | return punt_l4 |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 189 | |
| 190 | |
| 191 | class TestIP4PuntSocket(TestPuntSocket): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 192 | """Punt Socket for IPv4 UDP""" |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 193 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 194 | @classmethod |
| 195 | def setUpClass(cls): |
| 196 | super(TestIP4PuntSocket, cls).setUpClass() |
| 197 | |
| 198 | @classmethod |
| 199 | def tearDownClass(cls): |
| 200 | super(TestIP4PuntSocket, cls).tearDownClass() |
| 201 | |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 202 | def setUp(self): |
| 203 | super(TestIP4PuntSocket, self).setUp() |
| 204 | |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 205 | for i in self.pg_interfaces: |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 206 | i.config_ip4() |
| 207 | i.resolve_arp() |
| 208 | |
| 209 | def tearDown(self): |
| 210 | super(TestIP4PuntSocket, self).tearDown() |
| 211 | for i in self.pg_interfaces: |
| 212 | i.unconfig_ip4() |
| 213 | i.admin_down() |
| 214 | |
| 215 | def test_punt_socket_dump(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 216 | """Punt socket registration/deregistration""" |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 217 | |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 218 | pt_l4 = VppEnum.vl_api_punt_type_t.PUNT_API_TYPE_L4 |
| 219 | af_ip4 = VppEnum.vl_api_address_family_t.ADDRESS_IP4 |
| 220 | udp_proto = VppEnum.vl_api_ip_proto_t.IP_API_PROTO_UDP |
| 221 | |
| 222 | punts = self.vapi.punt_socket_dump(type=pt_l4) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 223 | self.assertEqual(len(punts), 0) |
| 224 | |
| 225 | # |
| 226 | # configure a punt socket |
| 227 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 228 | punt_l4 = mk_vpp_cfg4() |
| 229 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 230 | self.vapi.punt_socket_register( |
| 231 | set_port(punt_l4, 1111), "%s/socket_punt_1111" % self.tempdir |
| 232 | ) |
| 233 | self.vapi.punt_socket_register( |
| 234 | set_port(punt_l4, 2222), "%s/socket_punt_2222" % self.tempdir |
| 235 | ) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 236 | punts = self.vapi.punt_socket_dump(type=pt_l4) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 237 | self.assertEqual(len(punts), 2) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 238 | self.verify_port(set_port(punt_l4, 1111), punts[0]) |
| 239 | self.verify_port(set_port(punt_l4, 2222), punts[1]) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 240 | |
| 241 | # |
| 242 | # deregister a punt socket |
| 243 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 244 | self.vapi.punt_socket_deregister(set_port(punt_l4, 1111)) |
| 245 | punts = self.vapi.punt_socket_dump(type=pt_l4) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 246 | self.assertEqual(len(punts), 1) |
| 247 | |
| 248 | # |
| 249 | # configure a punt socket again |
| 250 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 251 | self.vapi.punt_socket_register( |
| 252 | set_port(punt_l4, 1111), "%s/socket_punt_1111" % self.tempdir |
| 253 | ) |
| 254 | self.vapi.punt_socket_register( |
| 255 | set_port(punt_l4, 3333), "%s/socket_punt_3333" % self.tempdir |
| 256 | ) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 257 | punts = self.vapi.punt_socket_dump(type=pt_l4) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 258 | self.assertEqual(len(punts), 3) |
| 259 | |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 260 | self.logger.info(self.vapi.cli("sh punt sock reg")) |
| 261 | |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 262 | # |
| 263 | # deregister all punt socket |
| 264 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 265 | self.vapi.punt_socket_deregister(set_port(punt_l4, 1111)) |
| 266 | self.vapi.punt_socket_deregister(set_port(punt_l4, 2222)) |
| 267 | self.vapi.punt_socket_deregister(set_port(punt_l4, 3333)) |
| 268 | punts = self.vapi.punt_socket_dump(type=pt_l4) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 269 | self.assertEqual(len(punts), 0) |
| 270 | |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 271 | def test_punt_socket_traffic_single_port_single_socket(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 272 | """Punt socket traffic single port single socket""" |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 273 | |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 274 | port = self.ports[0] |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 275 | pt_l4 = VppEnum.vl_api_punt_type_t.PUNT_API_TYPE_L4 |
| 276 | punt_l4 = set_port(mk_vpp_cfg4(), port) |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 277 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 278 | p = ( |
| 279 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 280 | / IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) |
| 281 | / UDP(sport=9876, dport=port) |
| 282 | / Raw(b"\xa5" * 100) |
| 283 | ) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 284 | |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 285 | pkts = p * self.nr_packets |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 286 | |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 287 | punts = self.vapi.punt_socket_dump(type=pt_l4) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 288 | self.assertEqual(len(punts), 0) |
| 289 | |
| 290 | # |
| 291 | # expect ICMP - port unreachable for all packets |
| 292 | # |
Neale Ranns | 5c6dd17 | 2022-02-17 09:08:47 +0000 | [diff] [blame] | 293 | rx = self.send_and_expect_some(self.pg0, pkts, self.pg0) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 294 | |
| 295 | for p in rx: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 296 | self.assertEqual(int(p[IP].proto), 1) # ICMP |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 297 | self.assertEqual(int(p[ICMP].code), 3) # unreachable |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 298 | |
| 299 | # |
| 300 | # configure a punt socket |
| 301 | # |
Ole Troan | 9cd8f33 | 2019-10-18 15:57:56 +0200 | [diff] [blame] | 302 | self.socket_client_create("%s/socket_%d" % (self.tempdir, port)) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 303 | self.vapi.punt_socket_register(punt_l4, "%s/socket_%d" % (self.tempdir, port)) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 304 | punts = self.vapi.punt_socket_dump(type=pt_l4) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 305 | self.assertEqual(len(punts), 1) |
| 306 | |
| 307 | # |
| 308 | # expect punt socket and no packets on pg0 |
| 309 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 310 | self.send_and_assert_no_replies(self.pg0, pkts) |
| 311 | rx = self.socket_client_close() |
| 312 | self.verify_udp_pkts(rx, len(pkts), port) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 313 | |
| 314 | # |
| 315 | # remove punt socket. expect ICMP - port unreachable for all packets |
| 316 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 317 | self.vapi.punt_socket_deregister(punt_l4) |
| 318 | punts = self.vapi.punt_socket_dump(type=pt_l4) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 319 | self.assertEqual(len(punts), 0) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 320 | |
Neale Ranns | 5c6dd17 | 2022-02-17 09:08:47 +0000 | [diff] [blame] | 321 | rx = self.send_and_expect_some(self.pg0, pkts, self.pg0) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 322 | for p in rx: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 323 | self.assertEqual(int(p[IP].proto), 1) # ICMP |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 324 | self.assertEqual(int(p[ICMP].code), 3) # unreachable |
| 325 | |
| 326 | def test_punt_socket_traffic_multi_ports_multi_sockets(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 327 | """Punt socket traffic multi ports and multi sockets""" |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 328 | |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 329 | punt_l4 = mk_vpp_cfg4() |
| 330 | |
| 331 | # configuration for each UDP port |
| 332 | cfgs = dict() |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 333 | |
| 334 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 335 | # create stream of packets for each port |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 336 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 337 | for port in self.ports: |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 338 | # choose port from port list |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 339 | cfgs[port] = {} |
| 340 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 341 | pkt = ( |
| 342 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 343 | / IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) |
| 344 | / UDP(sport=9876, dport=port) |
| 345 | / Raw(b"\xa5" * 100) |
| 346 | ) |
| 347 | cfgs[port]["pkts"] = pkt * self.nr_packets |
| 348 | cfgs[port]["port"] = port |
| 349 | cfgs[port]["vpp"] = copy.deepcopy(set_port(punt_l4, port)) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 350 | |
| 351 | # configure punt sockets |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 352 | cfgs[port]["sock"] = self.socket_client_create( |
| 353 | "%s/socket_%d" % (self.tempdir, port) |
| 354 | ) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 355 | self.vapi.punt_socket_register( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 356 | cfgs[port]["vpp"], "%s/socket_%d" % (self.tempdir, port) |
| 357 | ) |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 358 | |
| 359 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 360 | # send the packets that get punted |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 361 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 362 | for cfg in cfgs.values(): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 363 | self.send_and_assert_no_replies(self.pg0, cfg["pkts"]) |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 364 | |
| 365 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 366 | # test that we got the excepted packets on the expected socket |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 367 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 368 | for cfg in cfgs.values(): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 369 | rx = cfg["sock"].close() |
| 370 | self.verify_udp_pkts(rx, len(cfg["pkts"]), cfg["port"]) |
| 371 | self.vapi.punt_socket_deregister(cfg["vpp"]) |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 372 | |
| 373 | def test_punt_socket_traffic_multi_ports_single_socket(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 374 | """Punt socket traffic multi ports and single socket""" |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 375 | |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 376 | pt_l4 = VppEnum.vl_api_punt_type_t.PUNT_API_TYPE_L4 |
| 377 | punt_l4 = mk_vpp_cfg4() |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 378 | |
| 379 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 380 | # create stream of packets with each port |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 381 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 382 | pkts = [] |
| 383 | for port in self.ports: |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 384 | # choose port from port list |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 385 | pkt = ( |
| 386 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 387 | / IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) |
| 388 | / UDP(sport=9876, dport=port) |
| 389 | / Raw(b"\xa5" * 100) |
| 390 | ) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 391 | pkts += pkt * self.nr_packets |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 392 | |
| 393 | # |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 394 | # configure a punt socket |
| 395 | # |
Ole Troan | 9cd8f33 | 2019-10-18 15:57:56 +0200 | [diff] [blame] | 396 | self.socket_client_create("%s/socket_multi" % self.tempdir) |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 397 | for p in self.ports: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 398 | self.vapi.punt_socket_register( |
| 399 | set_port(punt_l4, p), "%s/socket_multi" % self.tempdir |
| 400 | ) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 401 | punts = self.vapi.punt_socket_dump(type=pt_l4) |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 402 | self.assertEqual(len(punts), len(self.ports)) |
| 403 | |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 404 | # |
| 405 | # expect punt socket and no packets on pg0 |
| 406 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 407 | self.send_and_assert_no_replies(self.pg0, pkts) |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 408 | self.logger.info(self.vapi.cli("show trace")) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 409 | rx = self.socket_client_close() |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 410 | |
| 411 | for p in self.ports: |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 412 | self.verify_udp_pkts(rx, self.nr_packets, p) |
| 413 | self.vapi.punt_socket_deregister(set_port(punt_l4, p)) |
| 414 | punts = self.vapi.punt_socket_dump(type=pt_l4) |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 415 | self.assertEqual(len(punts), 0) |
| 416 | |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 417 | |
| 418 | class TestIP6PuntSocket(TestPuntSocket): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 419 | """Punt Socket for IPv6 UDP""" |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 420 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 421 | @classmethod |
| 422 | def setUpClass(cls): |
| 423 | super(TestIP6PuntSocket, cls).setUpClass() |
| 424 | |
| 425 | @classmethod |
| 426 | def tearDownClass(cls): |
| 427 | super(TestIP6PuntSocket, cls).tearDownClass() |
| 428 | |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 429 | def setUp(self): |
| 430 | super(TestIP6PuntSocket, self).setUp() |
| 431 | |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 432 | for i in self.pg_interfaces: |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 433 | i.config_ip6() |
| 434 | i.resolve_ndp() |
| 435 | |
| 436 | def tearDown(self): |
| 437 | super(TestIP6PuntSocket, self).tearDown() |
| 438 | for i in self.pg_interfaces: |
| 439 | i.unconfig_ip6() |
| 440 | i.admin_down() |
| 441 | |
| 442 | def test_punt_socket_dump(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 443 | """Punt socket registration""" |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 444 | |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 445 | pt_l4 = VppEnum.vl_api_punt_type_t.PUNT_API_TYPE_L4 |
| 446 | af_ip6 = VppEnum.vl_api_address_family_t.ADDRESS_IP6 |
| 447 | udp_proto = VppEnum.vl_api_ip_proto_t.IP_API_PROTO_UDP |
| 448 | # |
| 449 | # configure a punt socket |
| 450 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 451 | punt_l4 = {"type": pt_l4, "punt": {"l4": {"af": af_ip6, "protocol": udp_proto}}} |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 452 | |
| 453 | punts = self.vapi.punt_socket_dump(type=pt_l4) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 454 | self.assertEqual(len(punts), 0) |
| 455 | |
| 456 | # |
| 457 | # configure a punt socket |
| 458 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 459 | self.vapi.punt_socket_register( |
| 460 | set_port(punt_l4, 1111), "%s/socket_1111" % self.tempdir |
| 461 | ) |
| 462 | self.vapi.punt_socket_register( |
| 463 | set_port(punt_l4, 2222), "%s/socket_2222" % self.tempdir |
| 464 | ) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 465 | punts = self.vapi.punt_socket_dump(type=pt_l4) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 466 | self.assertEqual(len(punts), 2) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 467 | self.verify_port(set_port(punt_l4, 1111), punts[0]) |
| 468 | self.verify_port(set_port(punt_l4, 2222), punts[1]) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 469 | |
| 470 | # |
| 471 | # deregister a punt socket |
| 472 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 473 | self.vapi.punt_socket_deregister(set_port(punt_l4, 1111)) |
| 474 | punts = self.vapi.punt_socket_dump(type=pt_l4) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 475 | self.assertEqual(len(punts), 1) |
| 476 | |
| 477 | # |
| 478 | # configure a punt socket again |
| 479 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 480 | self.vapi.punt_socket_register( |
| 481 | set_port(punt_l4, 1111), "%s/socket_1111" % self.tempdir |
| 482 | ) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 483 | punts = self.vapi.punt_socket_dump(type=pt_l4) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 484 | self.assertEqual(len(punts), 2) |
| 485 | |
| 486 | # |
| 487 | # deregister all punt socket |
| 488 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 489 | self.vapi.punt_socket_deregister(set_port(punt_l4, 1111)) |
| 490 | self.vapi.punt_socket_deregister(set_port(punt_l4, 2222)) |
| 491 | self.vapi.punt_socket_deregister(set_port(punt_l4, 3333)) |
| 492 | punts = self.vapi.punt_socket_dump(type=pt_l4) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 493 | self.assertEqual(len(punts), 0) |
| 494 | |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 495 | def test_punt_socket_traffic_single_port_single_socket(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 496 | """Punt socket traffic single port single socket""" |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 497 | |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 498 | port = self.ports[0] |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 499 | pt_l4 = VppEnum.vl_api_punt_type_t.PUNT_API_TYPE_L4 |
| 500 | af_ip6 = VppEnum.vl_api_address_family_t.ADDRESS_IP6 |
| 501 | udp_proto = VppEnum.vl_api_ip_proto_t.IP_API_PROTO_UDP |
| 502 | punt_l4 = { |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 503 | "type": pt_l4, |
| 504 | "punt": { |
| 505 | "l4": { |
| 506 | "af": af_ip6, |
| 507 | "protocol": udp_proto, |
| 508 | "port": port, |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 509 | } |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 510 | }, |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 511 | } |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 512 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 513 | p = ( |
| 514 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 515 | / IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6) |
| 516 | / inet6.UDP(sport=9876, dport=port) |
| 517 | / Raw(b"\xa5" * 100) |
| 518 | ) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 519 | |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 520 | pkts = p * self.nr_packets |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 521 | |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 522 | punts = self.vapi.punt_socket_dump(type=pt_l4) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 523 | self.assertEqual(len(punts), 0) |
| 524 | |
| 525 | # |
| 526 | # expect ICMPv6 - destination unreachable for all packets |
| 527 | # |
| 528 | self.vapi.cli("clear trace") |
| 529 | self.pg0.add_stream(pkts) |
| 530 | self.pg_enable_capture(self.pg_interfaces) |
| 531 | self.pg_start() |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 532 | # FIXME - when punt socket deregister is implemented |
| 533 | # rx = self.pg0.get_capture(self.nr_packets) |
| 534 | # for p in rx: |
| 535 | # self.assertEqual(int(p[IPv6].nh), 58) # ICMPv6 |
| 536 | # self.assertEqual(int(p[ICMPv6DestUnreach].code),4) # unreachable |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 537 | |
| 538 | # |
| 539 | # configure a punt socket |
| 540 | # |
Ole Troan | 9cd8f33 | 2019-10-18 15:57:56 +0200 | [diff] [blame] | 541 | self.socket_client_create("%s/socket_%d" % (self.tempdir, port)) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 542 | self.vapi.punt_socket_register(punt_l4, "%s/socket_%d" % (self.tempdir, port)) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 543 | punts = self.vapi.punt_socket_dump(type=pt_l4) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 544 | self.assertEqual(len(punts), 1) |
| 545 | |
| 546 | # |
| 547 | # expect punt socket and no packets on pg0 |
| 548 | # |
| 549 | self.vapi.cli("clear errors") |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 550 | self.vapi.cli("clear trace") |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 551 | self.pg0.add_stream(pkts) |
| 552 | self.pg_enable_capture(self.pg_interfaces) |
| 553 | self.pg_start() |
| 554 | self.pg0.get_capture(0) |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 555 | self.logger.info(self.vapi.cli("show trace")) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 556 | rx = self.socket_client_close() |
| 557 | self.verify_udp_pkts(rx, len(pkts), port) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 558 | |
| 559 | # |
| 560 | # remove punt socket. expect ICMP - dest. unreachable for all packets |
| 561 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 562 | self.vapi.punt_socket_deregister(punt_l4) |
| 563 | punts = self.vapi.punt_socket_dump(type=pt_l4) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 564 | self.assertEqual(len(punts), 0) |
| 565 | self.pg0.add_stream(pkts) |
| 566 | self.pg_enable_capture(self.pg_interfaces) |
| 567 | self.pg_start() |
| 568 | # FIXME - when punt socket deregister is implemented |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 569 | # self.pg0.get_capture(nr_packets) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 570 | |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 571 | def test_punt_socket_traffic_multi_ports_multi_sockets(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 572 | """Punt socket traffic multi ports and multi sockets""" |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 573 | |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 574 | punt_l4 = mk_vpp_cfg6() |
| 575 | |
| 576 | # configuration for each UDP port |
| 577 | cfgs = dict() |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 578 | |
| 579 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 580 | # create stream of packets for each port |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 581 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 582 | for port in self.ports: |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 583 | # choose port from port list |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 584 | cfgs[port] = {} |
| 585 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 586 | pkt = ( |
| 587 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 588 | / IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6) |
| 589 | / UDP(sport=9876, dport=port) |
| 590 | / Raw(b"\xa5" * 100) |
| 591 | ) |
| 592 | cfgs[port]["pkts"] = pkt * self.nr_packets |
| 593 | cfgs[port]["port"] = port |
| 594 | cfgs[port]["vpp"] = copy.deepcopy(set_port(punt_l4, port)) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 595 | |
| 596 | # configure punt sockets |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 597 | cfgs[port]["sock"] = self.socket_client_create( |
| 598 | "%s/socket_%d" % (self.tempdir, port) |
| 599 | ) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 600 | self.vapi.punt_socket_register( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 601 | cfgs[port]["vpp"], "%s/socket_%d" % (self.tempdir, port) |
| 602 | ) |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 603 | |
| 604 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 605 | # send the packets that get punted |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 606 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 607 | for cfg in cfgs.values(): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 608 | self.send_and_assert_no_replies(self.pg0, cfg["pkts"]) |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 609 | |
| 610 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 611 | # test that we got the excepted packets on the expected socket |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 612 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 613 | for cfg in cfgs.values(): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 614 | rx = cfg["sock"].close() |
| 615 | self.verify_udp_pkts(rx, len(cfg["pkts"]), cfg["port"]) |
| 616 | self.vapi.punt_socket_deregister(cfg["vpp"]) |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 617 | |
| 618 | def test_punt_socket_traffic_multi_ports_single_socket(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 619 | """Punt socket traffic multi ports and single socket""" |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 620 | |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 621 | pt_l4 = VppEnum.vl_api_punt_type_t.PUNT_API_TYPE_L4 |
| 622 | af_ip6 = VppEnum.vl_api_address_family_t.ADDRESS_IP6 |
| 623 | udp_proto = VppEnum.vl_api_ip_proto_t.IP_API_PROTO_UDP |
| 624 | punt_l4 = { |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 625 | "type": pt_l4, |
| 626 | "punt": { |
| 627 | "l4": { |
| 628 | "af": af_ip6, |
| 629 | "protocol": udp_proto, |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 630 | } |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 631 | }, |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 632 | } |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 633 | |
| 634 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 635 | # create stream of packets with each port |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 636 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 637 | pkts = [] |
| 638 | for port in self.ports: |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 639 | # choose port from port list |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 640 | pkt = ( |
| 641 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 642 | / IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6) |
| 643 | / UDP(sport=9876, dport=port) |
| 644 | / Raw(b"\xa5" * 100) |
| 645 | ) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 646 | pkts += pkt * self.nr_packets |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 647 | |
| 648 | # |
| 649 | # no punt socket |
| 650 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 651 | punts = self.vapi.punt_socket_dump(type=pt_l4) |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 652 | self.assertEqual(len(punts), 0) |
| 653 | |
| 654 | # |
| 655 | # configure a punt socket |
| 656 | # |
Ole Troan | 9cd8f33 | 2019-10-18 15:57:56 +0200 | [diff] [blame] | 657 | self.socket_client_create("%s/socket_multi" % self.tempdir) |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 658 | for p in self.ports: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 659 | self.vapi.punt_socket_register( |
| 660 | set_port(punt_l4, p), "%s/socket_multi" % self.tempdir |
| 661 | ) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 662 | punts = self.vapi.punt_socket_dump(type=pt_l4) |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 663 | self.assertEqual(len(punts), len(self.ports)) |
| 664 | |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 665 | # |
| 666 | # expect punt socket and no packets on pg0 |
| 667 | # |
| 668 | self.vapi.cli("clear errors") |
| 669 | self.vapi.cli("clear trace") |
| 670 | self.pg0.add_stream(pkts) |
| 671 | self.pg_enable_capture(self.pg_interfaces) |
| 672 | self.pg_start() |
Andrew Yourtchenko | cb265c6 | 2019-07-25 10:03:51 +0000 | [diff] [blame] | 673 | # give a chance to punt socket to collect all packets |
| 674 | self.sleep(1) |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 675 | self.pg0.get_capture(0) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 676 | rx = self.socket_client_close() |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 677 | |
| 678 | for p in self.ports: |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 679 | self.verify_udp_pkts(rx, self.nr_packets, p) |
| 680 | self.vapi.punt_socket_deregister(set_port(punt_l4, p)) |
| 681 | punts = self.vapi.punt_socket_dump(type=pt_l4) |
Pavel Kotucek | 9edb83a | 2018-12-11 16:57:25 +0100 | [diff] [blame] | 682 | self.assertEqual(len(punts), 0) |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 683 | |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 684 | |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 685 | class TestExceptionPuntSocket(TestPuntSocket): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 686 | """Punt Socket for Exceptions""" |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 687 | |
| 688 | @classmethod |
| 689 | def setUpClass(cls): |
| 690 | super(TestExceptionPuntSocket, cls).setUpClass() |
| 691 | |
| 692 | @classmethod |
| 693 | def tearDownClass(cls): |
| 694 | super(TestExceptionPuntSocket, cls).tearDownClass() |
| 695 | |
| 696 | def setUp(self): |
| 697 | super(TestExceptionPuntSocket, self).setUp() |
| 698 | |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 699 | self.create_pg_interfaces(range(2)) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 700 | for i in self.pg_interfaces: |
| 701 | i.config_ip4() |
| 702 | i.resolve_arp() |
| 703 | |
| 704 | def tearDown(self): |
| 705 | super(TestExceptionPuntSocket, self).tearDown() |
| 706 | for i in self.pg_interfaces: |
| 707 | i.unconfig_ip4() |
| 708 | i.admin_down() |
| 709 | |
| 710 | def test_registration(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 711 | """Punt socket registration/deregistration""" |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 712 | |
| 713 | pt_ex = VppEnum.vl_api_punt_type_t.PUNT_API_TYPE_EXCEPTION |
| 714 | |
| 715 | punts = self.vapi.punt_socket_dump(type=pt_ex) |
| 716 | self.assertEqual(len(punts), 0) |
| 717 | |
| 718 | # |
| 719 | # configure a punt socket |
| 720 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 721 | punt_ex = {"type": pt_ex, "punt": {"exception": {}}} |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 722 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 723 | self.vapi.punt_socket_register( |
| 724 | set_reason(punt_ex, 1), "%s/socket_punt_1" % self.tempdir |
| 725 | ) |
| 726 | self.vapi.punt_socket_register( |
| 727 | set_reason(punt_ex, 2), "%s/socket_punt_2" % self.tempdir |
| 728 | ) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 729 | punts = self.vapi.punt_socket_dump(type=pt_ex) |
| 730 | self.assertEqual(len(punts), 2) |
| 731 | self.verify_exception(set_reason(punt_ex, 1), punts[0]) |
| 732 | self.verify_exception(set_reason(punt_ex, 2), punts[1]) |
| 733 | |
| 734 | # |
| 735 | # deregister a punt socket |
| 736 | # |
| 737 | self.vapi.punt_socket_deregister(set_reason(punt_ex, 1)) |
| 738 | punts = self.vapi.punt_socket_dump(type=pt_ex) |
| 739 | self.assertEqual(len(punts), 1) |
| 740 | |
| 741 | # |
| 742 | # configure a punt socket again |
| 743 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 744 | self.vapi.punt_socket_register( |
| 745 | set_reason(punt_ex, 1), "%s/socket_punt_1" % self.tempdir |
| 746 | ) |
| 747 | self.vapi.punt_socket_register( |
| 748 | set_reason(punt_ex, 3), "%s/socket_punt_3" % self.tempdir |
| 749 | ) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 750 | punts = self.vapi.punt_socket_dump(type=pt_ex) |
| 751 | self.assertEqual(len(punts), 3) |
| 752 | |
| 753 | self.logger.info(self.vapi.cli("sh punt sock reg exception")) |
| 754 | |
| 755 | # |
| 756 | # deregister all punt socket |
| 757 | # |
| 758 | self.vapi.punt_socket_deregister(set_reason(punt_ex, 1)) |
| 759 | self.vapi.punt_socket_deregister(set_reason(punt_ex, 2)) |
| 760 | self.vapi.punt_socket_deregister(set_reason(punt_ex, 3)) |
| 761 | punts = self.vapi.punt_socket_dump(type=pt_ex) |
| 762 | self.assertEqual(len(punts), 0) |
| 763 | |
Neale Ranns | a6bee0a | 2019-06-14 01:13:25 -0700 | [diff] [blame] | 764 | def verify_esp_pkts(self, rxs, n_sent, spi, has_udp): |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 765 | self.assertEqual(len(rxs), n_sent) |
| 766 | for rx in rxs: |
Neale Ranns | a6bee0a | 2019-06-14 01:13:25 -0700 | [diff] [blame] | 767 | self.assertTrue(rx.haslayer(IP)) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 768 | self.assertTrue(rx.haslayer(ESP)) |
| 769 | self.assertEqual(rx[ESP].spi, spi) |
Neale Ranns | a6bee0a | 2019-06-14 01:13:25 -0700 | [diff] [blame] | 770 | if has_udp: |
| 771 | self.assertTrue(rx.haslayer(UDP)) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 772 | |
| 773 | def test_traffic(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 774 | """Punt socket traffic""" |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 775 | |
| 776 | port = self.ports[0] |
| 777 | pt_ex = VppEnum.vl_api_punt_type_t.PUNT_API_TYPE_EXCEPTION |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 778 | punt_ex = {"type": pt_ex, "punt": {"exception": {}}} |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 779 | |
| 780 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 781 | # we're dealing with IPSec tunnels punting for no-such-tunnel |
Filip Tehlar | 4362baa | 2020-04-02 13:13:39 +0000 | [diff] [blame] | 782 | # (SPI=0 goes to ikev2) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 783 | # |
| 784 | cfgs = dict() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 785 | cfgs["ipsec4-no-such-tunnel"] = {"spi": 99, "udp": False, "itf": self.pg0} |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 786 | |
| 787 | # |
| 788 | # find the VPP ID for these punt exception reasin |
| 789 | # |
| 790 | rs = self.vapi.punt_reason_dump() |
| 791 | for key in cfgs: |
| 792 | for r in rs: |
Jakub Grajciar | 2dbee93 | 2020-02-07 11:30:26 +0100 | [diff] [blame] | 793 | print(r.reason.name) |
| 794 | print(key) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 795 | if r.reason.name == key: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 796 | cfgs[key]["id"] = r.reason.id |
| 797 | cfgs[key]["vpp"] = copy.deepcopy( |
| 798 | set_reason(punt_ex, cfgs[key]["id"]) |
| 799 | ) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 800 | break |
| 801 | |
| 802 | # |
Neale Ranns | a6bee0a | 2019-06-14 01:13:25 -0700 | [diff] [blame] | 803 | # configure punt sockets |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 804 | # |
| 805 | for cfg in cfgs.values(): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 806 | cfg["sock"] = self.socket_client_create( |
| 807 | "%s/socket_%d" % (self.tempdir, cfg["id"]) |
| 808 | ) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 809 | self.vapi.punt_socket_register( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 810 | cfg["vpp"], "%s/socket_%d" % (self.tempdir, cfg["id"]) |
| 811 | ) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 812 | |
| 813 | # |
Neale Ranns | a6bee0a | 2019-06-14 01:13:25 -0700 | [diff] [blame] | 814 | # create packet streams for 'no-such-tunnel' exception |
| 815 | # |
| 816 | for cfg in cfgs.values(): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 817 | pkt = Ether(src=cfg["itf"].remote_mac, dst=cfg["itf"].local_mac) / IP( |
| 818 | src=cfg["itf"].remote_ip4, dst=cfg["itf"].local_ip4 |
| 819 | ) |
| 820 | if cfg["udp"]: |
Neale Ranns | a6bee0a | 2019-06-14 01:13:25 -0700 | [diff] [blame] | 821 | pkt = pkt / UDP(sport=666, dport=4500) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 822 | pkt = pkt / ESP(spi=cfg["spi"], seq=3) / Raw(b"\xa5" * 100) |
| 823 | cfg["pkts"] = [pkt] |
Neale Ranns | a6bee0a | 2019-06-14 01:13:25 -0700 | [diff] [blame] | 824 | |
| 825 | # |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 826 | # send packets for each SPI we expect to be punted |
| 827 | # |
| 828 | for cfg in cfgs.values(): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 829 | self.send_and_assert_no_replies(cfg["itf"], cfg["pkts"]) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 830 | |
| 831 | # |
| 832 | # verify the punted packets arrived on the associated socket |
| 833 | # |
| 834 | for cfg in cfgs.values(): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 835 | rx = cfg["sock"].close() |
| 836 | self.verify_esp_pkts(rx, len(cfg["pkts"]), cfg["spi"], cfg["udp"]) |
Neale Ranns | a6bee0a | 2019-06-14 01:13:25 -0700 | [diff] [blame] | 837 | |
| 838 | # |
Neale Ranns | 8d6d74c | 2020-02-20 09:45:16 +0000 | [diff] [blame] | 839 | # add some tunnels, make sure it still punts |
| 840 | # |
Neale Ranns | a9e2774 | 2020-12-23 16:22:28 +0000 | [diff] [blame] | 841 | tun = VppIpsecInterface(self).add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 842 | sa_in = VppIpsecSA( |
| 843 | self, |
| 844 | 11, |
| 845 | 11, |
| 846 | (VppEnum.vl_api_ipsec_integ_alg_t.IPSEC_API_INTEG_ALG_SHA1_96), |
| 847 | b"0123456701234567", |
| 848 | (VppEnum.vl_api_ipsec_crypto_alg_t.IPSEC_API_CRYPTO_ALG_AES_CBC_128), |
| 849 | b"0123456701234567", |
| 850 | 50, |
| 851 | self.pg0.local_ip4, |
| 852 | self.pg0.remote_ip4, |
| 853 | ).add_vpp_config() |
| 854 | sa_out = VppIpsecSA( |
| 855 | self, |
| 856 | 22, |
| 857 | 22, |
| 858 | (VppEnum.vl_api_ipsec_integ_alg_t.IPSEC_API_INTEG_ALG_SHA1_96), |
| 859 | b"0123456701234567", |
| 860 | (VppEnum.vl_api_ipsec_crypto_alg_t.IPSEC_API_CRYPTO_ALG_AES_CBC_128), |
| 861 | b"0123456701234567", |
| 862 | 50, |
| 863 | self.pg0.local_ip4, |
| 864 | self.pg0.remote_ip4, |
| 865 | ).add_vpp_config() |
| 866 | protect = VppIpsecTunProtect(self, tun, sa_out, [sa_in]).add_vpp_config() |
Neale Ranns | 8d6d74c | 2020-02-20 09:45:16 +0000 | [diff] [blame] | 867 | |
| 868 | # |
| 869 | # send packets for each SPI we expect to be punted |
| 870 | # |
| 871 | for cfg in cfgs.values(): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 872 | self.send_and_assert_no_replies(cfg["itf"], cfg["pkts"]) |
Neale Ranns | 8d6d74c | 2020-02-20 09:45:16 +0000 | [diff] [blame] | 873 | |
| 874 | # |
| 875 | # verify the punted packets arrived on the associated socket |
| 876 | # |
| 877 | for cfg in cfgs.values(): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 878 | rx = cfg["sock"].close() |
| 879 | self.verify_esp_pkts(rx, len(cfg["pkts"]), cfg["spi"], cfg["udp"]) |
Neale Ranns | 8d6d74c | 2020-02-20 09:45:16 +0000 | [diff] [blame] | 880 | # |
Neale Ranns | a6bee0a | 2019-06-14 01:13:25 -0700 | [diff] [blame] | 881 | # socket deregister |
| 882 | # |
| 883 | for cfg in cfgs.values(): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 884 | self.vapi.punt_socket_deregister(cfg["vpp"]) |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 885 | |
| 886 | |
Neale Ranns | b538dd8 | 2019-05-21 06:54:54 -0700 | [diff] [blame] | 887 | class TestIpProtoPuntSocket(TestPuntSocket): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 888 | """Punt Socket for IP packets""" |
Neale Ranns | b538dd8 | 2019-05-21 06:54:54 -0700 | [diff] [blame] | 889 | |
| 890 | @classmethod |
| 891 | def setUpClass(cls): |
| 892 | super(TestIpProtoPuntSocket, cls).setUpClass() |
| 893 | |
| 894 | @classmethod |
| 895 | def tearDownClass(cls): |
| 896 | super(TestIpProtoPuntSocket, cls).tearDownClass() |
| 897 | |
| 898 | def setUp(self): |
| 899 | super(TestIpProtoPuntSocket, self).setUp() |
| 900 | |
| 901 | for i in self.pg_interfaces: |
| 902 | i.config_ip4() |
| 903 | i.resolve_arp() |
| 904 | |
| 905 | def tearDown(self): |
| 906 | super(TestIpProtoPuntSocket, self).tearDown() |
| 907 | for i in self.pg_interfaces: |
| 908 | i.unconfig_ip4() |
| 909 | i.admin_down() |
| 910 | |
| 911 | def test_registration(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 912 | """Punt socket registration/deregistration""" |
Neale Ranns | b538dd8 | 2019-05-21 06:54:54 -0700 | [diff] [blame] | 913 | |
| 914 | af_ip4 = VppEnum.vl_api_address_family_t.ADDRESS_IP4 |
| 915 | pt_ip = VppEnum.vl_api_punt_type_t.PUNT_API_TYPE_IP_PROTO |
| 916 | proto_ospf = VppEnum.vl_api_ip_proto_t.IP_API_PROTO_OSPF |
| 917 | proto_eigrp = VppEnum.vl_api_ip_proto_t.IP_API_PROTO_EIGRP |
| 918 | |
| 919 | punts = self.vapi.punt_socket_dump(type=pt_ip) |
| 920 | self.assertEqual(len(punts), 0) |
| 921 | |
| 922 | # |
| 923 | # configure a punt socket |
| 924 | # |
| 925 | punt_ospf = { |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 926 | "type": pt_ip, |
| 927 | "punt": {"ip_proto": {"af": af_ip4, "protocol": proto_ospf}}, |
Neale Ranns | b538dd8 | 2019-05-21 06:54:54 -0700 | [diff] [blame] | 928 | } |
| 929 | punt_eigrp = { |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 930 | "type": pt_ip, |
| 931 | "punt": {"ip_proto": {"af": af_ip4, "protocol": proto_eigrp}}, |
Neale Ranns | b538dd8 | 2019-05-21 06:54:54 -0700 | [diff] [blame] | 932 | } |
| 933 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 934 | self.vapi.punt_socket_register(punt_ospf, "%s/socket_punt_1" % self.tempdir) |
| 935 | self.vapi.punt_socket_register(punt_eigrp, "%s/socket_punt_2" % self.tempdir) |
Neale Ranns | b538dd8 | 2019-05-21 06:54:54 -0700 | [diff] [blame] | 936 | self.logger.info(self.vapi.cli("sh punt sock reg ip")) |
| 937 | punts = self.vapi.punt_socket_dump(type=pt_ip) |
| 938 | self.assertEqual(len(punts), 2) |
| 939 | self.verify_ip_proto(punt_ospf, punts[0]) |
| 940 | self.verify_ip_proto(punt_eigrp, punts[1]) |
| 941 | |
| 942 | # |
| 943 | # deregister a punt socket |
| 944 | # |
| 945 | self.vapi.punt_socket_deregister(punt_ospf) |
| 946 | punts = self.vapi.punt_socket_dump(type=pt_ip) |
| 947 | self.assertEqual(len(punts), 1) |
| 948 | |
| 949 | # |
| 950 | # configure a punt socket again |
| 951 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 952 | self.vapi.punt_socket_register(punt_ospf, "%s/socket_punt_3" % self.tempdir) |
Neale Ranns | b538dd8 | 2019-05-21 06:54:54 -0700 | [diff] [blame] | 953 | punts = self.vapi.punt_socket_dump(type=pt_ip) |
| 954 | self.assertEqual(len(punts), 2) |
| 955 | |
| 956 | self.logger.info(self.vapi.cli("sh punt sock reg exception")) |
| 957 | |
| 958 | # |
| 959 | # deregister all punt socket |
| 960 | # |
| 961 | self.vapi.punt_socket_deregister(punt_eigrp) |
| 962 | self.vapi.punt_socket_deregister(punt_ospf) |
| 963 | punts = self.vapi.punt_socket_dump(type=pt_ip) |
| 964 | self.assertEqual(len(punts), 0) |
| 965 | |
| 966 | def verify_ospf_pkts(self, rxs, n_sent): |
| 967 | self.assertEqual(len(rxs), n_sent) |
| 968 | for rx in rxs: |
| 969 | self.assertTrue(rx.haslayer(OSPF_Hdr)) |
| 970 | |
| 971 | def test_traffic(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 972 | """Punt socket traffic""" |
Neale Ranns | b538dd8 | 2019-05-21 06:54:54 -0700 | [diff] [blame] | 973 | |
| 974 | af_ip4 = VppEnum.vl_api_address_family_t.ADDRESS_IP4 |
| 975 | pt_ip = VppEnum.vl_api_punt_type_t.PUNT_API_TYPE_IP_PROTO |
| 976 | proto_ospf = VppEnum.vl_api_ip_proto_t.IP_API_PROTO_OSPF |
| 977 | |
| 978 | # |
| 979 | # configure a punt socket to capture OSPF packets |
| 980 | # |
| 981 | punt_ospf = { |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 982 | "type": pt_ip, |
| 983 | "punt": {"ip_proto": {"af": af_ip4, "protocol": proto_ospf}}, |
Neale Ranns | b538dd8 | 2019-05-21 06:54:54 -0700 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | # |
| 987 | # create packet streams and configure a punt sockets |
| 988 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 989 | pkt = ( |
| 990 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 991 | / IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) |
| 992 | / OSPF_Hdr() |
| 993 | / OSPFv3_Hello() |
| 994 | ) |
Neale Ranns | b538dd8 | 2019-05-21 06:54:54 -0700 | [diff] [blame] | 995 | pkts = pkt * 7 |
| 996 | |
Ole Troan | 9cd8f33 | 2019-10-18 15:57:56 +0200 | [diff] [blame] | 997 | sock = self.socket_client_create("%s/socket_1" % self.tempdir) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 998 | self.vapi.punt_socket_register(punt_ospf, "%s/socket_1" % self.tempdir) |
Neale Ranns | b538dd8 | 2019-05-21 06:54:54 -0700 | [diff] [blame] | 999 | |
| 1000 | # |
| 1001 | # send packets for each SPI we expect to be punted |
| 1002 | # |
| 1003 | self.send_and_assert_no_replies(self.pg0, pkts) |
| 1004 | |
| 1005 | # |
| 1006 | # verify the punted packets arrived on the associated socket |
| 1007 | # |
| 1008 | rx = sock.close() |
| 1009 | self.verify_ospf_pkts(rx, len(pkts)) |
| 1010 | self.vapi.punt_socket_deregister(punt_ospf) |
| 1011 | |
| 1012 | |
Andrew Yourtchenko | feb7742 | 2023-03-17 01:47:58 +0000 | [diff] [blame] | 1013 | class TestDot1QPuntSocket(TestPuntSocket): |
| 1014 | """Punt Socket for 802.1Q (dot1q)""" |
| 1015 | |
| 1016 | def setUp(self): |
| 1017 | super(TestDot1QPuntSocket, self).setUp() |
| 1018 | |
| 1019 | for i in self.pg_interfaces: |
| 1020 | i.admin_up() |
| 1021 | i.config_ip4() |
| 1022 | i.resolve_arp() |
| 1023 | |
| 1024 | def tearDown(self): |
| 1025 | super(TestDot1QPuntSocket, self).tearDown() |
| 1026 | for i in self.pg_interfaces: |
| 1027 | i.unconfig_ip4() |
| 1028 | i.admin_down() |
| 1029 | |
| 1030 | def test_dot1q_header_punt(self): |
| 1031 | """Punt socket traffic with Dot1q header""" |
| 1032 | |
| 1033 | port = self.ports[0] |
| 1034 | pt_l4 = VppEnum.vl_api_punt_type_t.PUNT_API_TYPE_L4 |
| 1035 | punt_l4 = set_port(mk_vpp_cfg4(), port) |
| 1036 | |
| 1037 | # VLAN ID |
| 1038 | vlan_id = 100 |
| 1039 | |
| 1040 | # Create a subinterface with the VLAN ID |
| 1041 | subif = VppDot1QSubint(self, self.pg0, vlan_id) |
| 1042 | subif.admin_up() |
| 1043 | subif.config_ip4() |
| 1044 | |
| 1045 | # Configure an IP address on the subinterface |
| 1046 | subif_ip4 = subif.local_ip4 |
| 1047 | |
| 1048 | p = ( |
| 1049 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 1050 | / Dot1Q(vlan=vlan_id) |
| 1051 | / IP(src=self.pg0.remote_ip4, dst=subif_ip4) |
| 1052 | / UDP(sport=9876, dport=port) |
| 1053 | / Raw(b"\xa5" * 100) |
| 1054 | ) |
| 1055 | |
| 1056 | pkts = p * self.nr_packets |
| 1057 | |
| 1058 | # Expect ICMP - port unreachable for all packets |
| 1059 | rx = self.send_and_expect_some(self.pg0, pkts, self.pg0) |
| 1060 | |
| 1061 | for p in rx: |
| 1062 | self.assertEqual(int(p[IP].proto), 1) # ICMP |
| 1063 | self.assertEqual(int(p[ICMP].code), 3) # unreachable |
| 1064 | |
| 1065 | # Configure a punt socket |
| 1066 | self.socket_client_create("%s/socket_%d" % (self.tempdir, port)) |
| 1067 | self.vapi.punt_socket_register(punt_l4, "%s/socket_%d" % (self.tempdir, port)) |
| 1068 | punts = self.vapi.punt_socket_dump(type=pt_l4) |
| 1069 | self.assertEqual(len(punts), 1) |
| 1070 | |
| 1071 | # Expect punt socket and no packets on pg0 |
| 1072 | self.send_and_assert_no_replies(self.pg0, pkts) |
| 1073 | rx = self.socket_client_close() |
| 1074 | self.logger.info("RXPKT") |
| 1075 | self.logger.info(rx) |
| 1076 | self.verify_udp_pkts(rx, len(pkts), port) |
| 1077 | for pkt in rx: |
| 1078 | self.assertEqual(pkt[Ether].src, self.pg0.remote_mac) |
| 1079 | self.assertEqual(pkt[Ether].dst, self.pg0.local_mac) |
| 1080 | self.assertEqual(pkt[Dot1Q].vlan, 100) |
| 1081 | |
| 1082 | # Remove punt socket. Expect ICMP - port unreachable for all packets |
| 1083 | self.vapi.punt_socket_deregister(punt_l4) |
| 1084 | punts = self.vapi.punt_socket_dump(type=pt_l4) |
| 1085 | self.assertEqual(len(punts), 0) |
| 1086 | |
| 1087 | rx = self.send_and_expect_some(self.pg0, pkts, self.pg0) |
| 1088 | for p in rx: |
| 1089 | self.assertEqual(int(p[IP].proto), 1) # ICMP |
| 1090 | self.assertEqual(int(p[ICMP].code), 3) # unreachable |
| 1091 | |
| 1092 | |
Andrew Yourtchenko | 8dc0d48 | 2021-01-29 13:17:19 +0000 | [diff] [blame] | 1093 | @tag_fixme_vpp_workers |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 1094 | class TestPunt(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1095 | """Exception Punt Test Case""" |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 1096 | |
| 1097 | @classmethod |
| 1098 | def setUpClass(cls): |
| 1099 | super(TestPunt, cls).setUpClass() |
| 1100 | |
| 1101 | @classmethod |
| 1102 | def tearDownClass(cls): |
| 1103 | super(TestPunt, cls).tearDownClass() |
| 1104 | |
| 1105 | def setUp(self): |
| 1106 | super(TestPunt, self).setUp() |
| 1107 | |
| 1108 | self.create_pg_interfaces(range(4)) |
| 1109 | |
| 1110 | for i in self.pg_interfaces: |
| 1111 | i.admin_up() |
| 1112 | i.config_ip4() |
| 1113 | i.resolve_arp() |
| 1114 | i.config_ip6() |
| 1115 | i.resolve_ndp() |
| 1116 | |
| 1117 | def tearDown(self): |
| 1118 | for i in self.pg_interfaces: |
| 1119 | i.unconfig_ip4() |
| 1120 | i.unconfig_ip6() |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 1121 | i.admin_down() |
| 1122 | super(TestPunt, self).tearDown() |
| 1123 | |
| 1124 | def test_punt(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1125 | """Exception Path testing""" |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 1126 | |
| 1127 | # |
Neale Ranns | 719beb7 | 2019-07-10 07:10:25 +0000 | [diff] [blame] | 1128 | # dump the punt registered reasons |
| 1129 | # search for a few we know should be there |
| 1130 | # |
| 1131 | rs = self.vapi.punt_reason_dump() |
| 1132 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1133 | reasons = [ |
| 1134 | "ipsec6-no-such-tunnel", |
| 1135 | "ipsec4-no-such-tunnel", |
| 1136 | "ipsec4-spi-o-udp-0", |
| 1137 | ] |
Neale Ranns | 719beb7 | 2019-07-10 07:10:25 +0000 | [diff] [blame] | 1138 | |
| 1139 | for reason in reasons: |
| 1140 | found = False |
| 1141 | for r in rs: |
| 1142 | if r.reason.name == reason: |
| 1143 | found = True |
| 1144 | break |
| 1145 | self.assertTrue(found) |
| 1146 | |
| 1147 | # |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 1148 | # Using the test CLI we will hook in a exception path to |
| 1149 | # send ACL deny packets out of pg0 and pg1. |
| 1150 | # the ACL is src,dst = 1.1.1.1,1.1.1.2 |
| 1151 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1152 | ip_1_1_1_2 = VppIpRoute( |
| 1153 | self, |
| 1154 | "1.1.1.2", |
| 1155 | 32, |
| 1156 | [VppRoutePath(self.pg3.remote_ip4, self.pg3.sw_if_index)], |
| 1157 | ) |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 1158 | ip_1_1_1_2.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1159 | ip_1_2 = VppIpRoute( |
| 1160 | self, |
| 1161 | "1::2", |
| 1162 | 128, |
| 1163 | [ |
| 1164 | VppRoutePath( |
| 1165 | self.pg3.remote_ip6, |
| 1166 | self.pg3.sw_if_index, |
| 1167 | proto=DpoProto.DPO_PROTO_IP6, |
| 1168 | ) |
| 1169 | ], |
| 1170 | ) |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 1171 | ip_1_2.add_vpp_config() |
| 1172 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1173 | p4 = ( |
| 1174 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
| 1175 | / IP(src="1.1.1.1", dst="1.1.1.2") |
| 1176 | / UDP(sport=1234, dport=1234) |
| 1177 | / Raw(b"\xa5" * 100) |
| 1178 | ) |
| 1179 | p6 = ( |
| 1180 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
| 1181 | / IPv6(src="1::1", dst="1::2") |
| 1182 | / UDP(sport=1234, dport=1234) |
| 1183 | / Raw(b"\xa5" * 100) |
| 1184 | ) |
| 1185 | self.send_and_expect(self.pg2, p4 * 1, self.pg3) |
| 1186 | self.send_and_expect(self.pg2, p6 * 1, self.pg3) |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 1187 | |
| 1188 | # |
| 1189 | # apply the punting features |
| 1190 | # |
| 1191 | self.vapi.cli("test punt pg2") |
| 1192 | |
| 1193 | # |
Neale Ranns | 719beb7 | 2019-07-10 07:10:25 +0000 | [diff] [blame] | 1194 | # dump the punt reasons to learn the IDs assigned |
| 1195 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1196 | rs = self.vapi.punt_reason_dump(reason={"name": "reason-v4"}) |
Neale Ranns | 719beb7 | 2019-07-10 07:10:25 +0000 | [diff] [blame] | 1197 | r4 = rs[0].reason.id |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1198 | rs = self.vapi.punt_reason_dump(reason={"name": "reason-v6"}) |
Neale Ranns | 719beb7 | 2019-07-10 07:10:25 +0000 | [diff] [blame] | 1199 | r6 = rs[0].reason.id |
| 1200 | |
| 1201 | # |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 1202 | # pkts now dropped |
| 1203 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1204 | self.send_and_assert_no_replies(self.pg2, p4 * NUM_PKTS) |
| 1205 | self.send_and_assert_no_replies(self.pg2, p6 * NUM_PKTS) |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 1206 | |
| 1207 | # |
| 1208 | # Check state: |
| 1209 | # 1 - node error counters |
| 1210 | # 2 - per-reason counters |
| 1211 | # 2, 3 are the index of the assigned punt reason |
| 1212 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1213 | stats = self.statistics.get_err_counter("/err/punt-dispatch/No registrations") |
| 1214 | self.assertEqual(stats, 2 * NUM_PKTS) |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 1215 | |
| 1216 | stats = self.statistics.get_counter("/net/punt") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1217 | self.assertEqual(stats[0][r4]["packets"], NUM_PKTS) |
| 1218 | self.assertEqual(stats[0][r6]["packets"], NUM_PKTS) |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 1219 | |
| 1220 | # |
| 1221 | # use the test CLI to test a client that punts exception |
| 1222 | # packets out of pg0 |
| 1223 | # |
| 1224 | self.vapi.cli("test punt pg0 %s" % self.pg0.remote_ip4) |
| 1225 | self.vapi.cli("test punt pg0 %s" % self.pg0.remote_ip6) |
| 1226 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1227 | rx4s = self.send_and_expect(self.pg2, p4 * NUM_PKTS, self.pg0) |
| 1228 | rx6s = self.send_and_expect(self.pg2, p6 * NUM_PKTS, self.pg0) |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 1229 | |
| 1230 | # |
| 1231 | # check the packets come out IP unmodified but destined to pg0 host |
| 1232 | # |
| 1233 | for rx in rx4s: |
| 1234 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 1235 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 1236 | self.assertEqual(p4[IP].dst, rx[IP].dst) |
| 1237 | self.assertEqual(p4[IP].ttl, rx[IP].ttl) |
| 1238 | for rx in rx6s: |
| 1239 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 1240 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 1241 | self.assertEqual(p6[IPv6].dst, rx[IPv6].dst) |
| 1242 | self.assertEqual(p6[IPv6].hlim, rx[IPv6].hlim) |
| 1243 | |
| 1244 | stats = self.statistics.get_counter("/net/punt") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1245 | self.assertEqual(stats[0][r4]["packets"], 2 * NUM_PKTS) |
| 1246 | self.assertEqual(stats[0][r6]["packets"], 2 * NUM_PKTS) |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 1247 | |
| 1248 | # |
| 1249 | # add another registration for the same reason to send packets |
| 1250 | # out of pg1 |
| 1251 | # |
| 1252 | self.vapi.cli("test punt pg1 %s" % self.pg1.remote_ip4) |
| 1253 | self.vapi.cli("test punt pg1 %s" % self.pg1.remote_ip6) |
| 1254 | |
| 1255 | self.vapi.cli("clear trace") |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1256 | self.pg2.add_stream(p4 * NUM_PKTS) |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 1257 | self.pg_enable_capture(self.pg_interfaces) |
| 1258 | self.pg_start() |
| 1259 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1260 | rxd = self.pg0.get_capture(NUM_PKTS) |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 1261 | for rx in rxd: |
| 1262 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 1263 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 1264 | self.assertEqual(p4[IP].dst, rx[IP].dst) |
| 1265 | self.assertEqual(p4[IP].ttl, rx[IP].ttl) |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1266 | rxd = self.pg1.get_capture(NUM_PKTS) |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 1267 | for rx in rxd: |
| 1268 | self.assertEqual(rx[Ether].dst, self.pg1.remote_mac) |
| 1269 | self.assertEqual(rx[Ether].src, self.pg1.local_mac) |
| 1270 | self.assertEqual(p4[IP].dst, rx[IP].dst) |
| 1271 | self.assertEqual(p4[IP].ttl, rx[IP].ttl) |
| 1272 | |
| 1273 | self.vapi.cli("clear trace") |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1274 | self.pg2.add_stream(p6 * NUM_PKTS) |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 1275 | self.pg_enable_capture(self.pg_interfaces) |
| 1276 | self.pg_start() |
| 1277 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1278 | rxd = self.pg0.get_capture(NUM_PKTS) |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 1279 | for rx in rxd: |
| 1280 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 1281 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 1282 | self.assertEqual(p6[IPv6].dst, rx[IPv6].dst) |
| 1283 | self.assertEqual(p6[IPv6].hlim, rx[IPv6].hlim) |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1284 | rxd = self.pg1.get_capture(NUM_PKTS) |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 1285 | for rx in rxd: |
| 1286 | self.assertEqual(rx[Ether].dst, self.pg1.remote_mac) |
| 1287 | self.assertEqual(rx[Ether].src, self.pg1.local_mac) |
| 1288 | self.assertEqual(p6[IPv6].dst, rx[IPv6].dst) |
| 1289 | self.assertEqual(p6[IPv6].hlim, rx[IPv6].hlim) |
| 1290 | |
| 1291 | stats = self.statistics.get_counter("/net/punt") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1292 | self.assertEqual(stats[0][r4]["packets"], 3 * NUM_PKTS) |
| 1293 | self.assertEqual(stats[0][r6]["packets"], 3 * NUM_PKTS) |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 1294 | |
| 1295 | self.logger.info(self.vapi.cli("show vlib graph punt-dispatch")) |
| 1296 | self.logger.info(self.vapi.cli("show punt client")) |
| 1297 | self.logger.info(self.vapi.cli("show punt reason")) |
| 1298 | self.logger.info(self.vapi.cli("show punt stats")) |
| 1299 | self.logger.info(self.vapi.cli("show punt db")) |
| 1300 | |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame] | 1301 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1302 | if __name__ == "__main__": |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 1303 | unittest.main(testRunner=VppTestRunner) |