Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 2 | import random |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 3 | import socket |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 4 | import unittest |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 5 | |
Paul Vinciguerra | a6fe463 | 2018-11-25 11:21:50 -0800 | [diff] [blame] | 6 | from scapy.contrib.mpls import MPLS |
Takeru Hayasaka | b23c6f4 | 2023-01-17 04:45:58 +0900 | [diff] [blame] | 7 | from scapy.contrib.gtp import GTP_U_Header |
Paul Vinciguerra | a6fe463 | 2018-11-25 11:21:50 -0800 | [diff] [blame] | 8 | from scapy.layers.inet import IP, UDP, TCP, ICMP, icmptypes, icmpcodes |
Neale Ranns | aa7cfd0 | 2022-03-24 12:28:42 +0000 | [diff] [blame] | 9 | from scapy.layers.inet6 import IPv6 |
Paul Vinciguerra | a6fe463 | 2018-11-25 11:21:50 -0800 | [diff] [blame] | 10 | from scapy.layers.l2 import Ether, Dot1Q, ARP |
| 11 | from scapy.packet import Raw |
| 12 | from six import moves |
| 13 | |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 14 | from framework import VppTestCase |
| 15 | from asfframework import VppTestRunner, tag_fixme_vpp_workers |
Paul Vinciguerra | a6fe463 | 2018-11-25 11:21:50 -0800 | [diff] [blame] | 16 | from util import ppp |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 17 | from vpp_ip_route import ( |
| 18 | VppIpRoute, |
| 19 | VppRoutePath, |
| 20 | VppIpMRoute, |
| 21 | VppMRoutePath, |
| 22 | VppMplsIpBind, |
| 23 | VppMplsTable, |
| 24 | VppIpTable, |
| 25 | FibPathType, |
| 26 | find_route, |
| 27 | VppIpInterfaceAddress, |
| 28 | find_route_in_dump, |
| 29 | find_mroute_in_dump, |
| 30 | ) |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 31 | from vpp_ip import VppIpPuntPolicer, VppIpPuntRedirect, VppIpPathMtu |
Paul Vinciguerra | a6fe463 | 2018-11-25 11:21:50 -0800 | [diff] [blame] | 32 | from vpp_sub_interface import VppSubInterface, VppDot1QSubint, VppDot1ADSubint |
Klement Sekera | fd1f56a | 2021-11-22 21:25:57 +0100 | [diff] [blame] | 33 | from vpp_papi import vpp_papi, VppEnum |
Neale Ranns | 0b6a857 | 2019-10-30 17:34:14 +0000 | [diff] [blame] | 34 | from vpp_neighbor import VppNeighbor |
Neale Ranns | 9efcee6 | 2019-11-26 19:30:08 +0000 | [diff] [blame] | 35 | from vpp_lo_interface import VppLoInterface |
Brian Russell | c8f3cdf | 2021-01-19 16:57:42 +0000 | [diff] [blame] | 36 | from vpp_policer import VppPolicer, PolicerAction |
Dmitry Valter | 34fa0ce | 2024-03-11 10:38:46 +0000 | [diff] [blame] | 37 | from config import config |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 38 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 39 | NUM_PKTS = 67 |
| 40 | |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 41 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 42 | class TestIPv4(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 43 | """IPv4 Test Case""" |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 44 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 45 | @classmethod |
| 46 | def setUpClass(cls): |
| 47 | super(TestIPv4, cls).setUpClass() |
| 48 | |
| 49 | @classmethod |
| 50 | def tearDownClass(cls): |
| 51 | super(TestIPv4, cls).tearDownClass() |
| 52 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 53 | def setUp(self): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 54 | """ |
| 55 | Perform test setup before test case. |
| 56 | |
| 57 | **Config:** |
| 58 | - create 3 pg interfaces |
| 59 | - untagged pg0 interface |
| 60 | - Dot1Q subinterface on pg1 |
| 61 | - Dot1AD subinterface on pg2 |
| 62 | - setup interfaces: |
| 63 | - put it into UP state |
| 64 | - set IPv4 addresses |
| 65 | - resolve neighbor address using ARP |
| 66 | - configure 200 fib entries |
| 67 | |
| 68 | :ivar list interfaces: pg interfaces and subinterfaces. |
| 69 | :ivar dict flows: IPv4 packet flows in test. |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 70 | """ |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 71 | super(TestIPv4, self).setUp() |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 72 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 73 | # create 3 pg interfaces |
| 74 | self.create_pg_interfaces(range(3)) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 75 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 76 | # create 2 subinterfaces for pg1 and pg2 |
| 77 | self.sub_interfaces = [ |
| 78 | VppDot1QSubint(self, self.pg1, 100), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 79 | VppDot1ADSubint(self, self.pg2, 200, 300, 400), |
| 80 | ] |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 81 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 82 | # packet flows mapping pg0 -> pg1.sub, pg2.sub, etc. |
| 83 | self.flows = dict() |
| 84 | self.flows[self.pg0] = [self.pg1.sub_if, self.pg2.sub_if] |
| 85 | self.flows[self.pg1.sub_if] = [self.pg0, self.pg2.sub_if] |
| 86 | self.flows[self.pg2.sub_if] = [self.pg0, self.pg1.sub_if] |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 87 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 88 | # packet sizes |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 89 | self.pg_if_packet_sizes = [64, 1500, 9020] |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 90 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 91 | self.interfaces = list(self.pg_interfaces) |
| 92 | self.interfaces.extend(self.sub_interfaces) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 93 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 94 | # setup all interfaces |
| 95 | for i in self.interfaces: |
| 96 | i.admin_up() |
| 97 | i.config_ip4() |
| 98 | i.resolve_arp() |
| 99 | |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 100 | # config 2M FIB entries |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 101 | |
| 102 | def tearDown(self): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 103 | """Run standard test teardown and log ``show ip arp``.""" |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 104 | super(TestIPv4, self).tearDown() |
Paul Vinciguerra | 90cf21b | 2019-03-13 09:23:05 -0700 | [diff] [blame] | 105 | |
| 106 | def show_commands_at_teardown(self): |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 107 | self.logger.info(self.vapi.cli("show ip4 neighbors")) |
Paul Vinciguerra | 90cf21b | 2019-03-13 09:23:05 -0700 | [diff] [blame] | 108 | # info(self.vapi.cli("show ip fib")) # many entries |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 109 | |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 110 | def modify_packet(self, src_if, packet_size, pkt): |
| 111 | """Add load, set destination IP and extend packet to required packet |
| 112 | size for defined interface. |
| 113 | |
| 114 | :param VppInterface src_if: Interface to create packet for. |
| 115 | :param int packet_size: Required packet size. |
| 116 | :param Scapy pkt: Packet to be modified. |
| 117 | """ |
Ole Troan | 6ed154f | 2019-10-15 19:31:55 +0200 | [diff] [blame] | 118 | dst_if_idx = int(packet_size / 10 % 2) |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 119 | dst_if = self.flows[src_if][dst_if_idx] |
| 120 | info = self.create_packet_info(src_if, dst_if) |
| 121 | payload = self.info_to_payload(info) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 122 | p = pkt / Raw(payload) |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 123 | p[IP].dst = dst_if.remote_ip4 |
| 124 | info.data = p.copy() |
| 125 | if isinstance(src_if, VppSubInterface): |
| 126 | p = src_if.add_dot1_layer(p) |
| 127 | self.extend_packet(p, packet_size) |
| 128 | |
| 129 | return p |
| 130 | |
| 131 | def create_stream(self, src_if): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 132 | """Create input packet stream for defined interface. |
| 133 | |
| 134 | :param VppInterface src_if: Interface to create packet stream for. |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 135 | """ |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 136 | hdr_ext = 4 if isinstance(src_if, VppSubInterface) else 0 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 137 | pkt_tmpl = ( |
| 138 | Ether(dst=src_if.local_mac, src=src_if.remote_mac) |
| 139 | / IP(src=src_if.remote_ip4) |
| 140 | / UDP(sport=1234, dport=1234) |
| 141 | ) |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 142 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 143 | pkts = [ |
| 144 | self.modify_packet(src_if, i, pkt_tmpl) |
| 145 | for i in moves.range( |
| 146 | self.pg_if_packet_sizes[0], self.pg_if_packet_sizes[1], 10 |
| 147 | ) |
| 148 | ] |
| 149 | pkts_b = [ |
| 150 | self.modify_packet(src_if, i, pkt_tmpl) |
| 151 | for i in moves.range( |
| 152 | self.pg_if_packet_sizes[1] + hdr_ext, |
| 153 | self.pg_if_packet_sizes[2] + hdr_ext, |
| 154 | 50, |
| 155 | ) |
| 156 | ] |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 157 | pkts.extend(pkts_b) |
| 158 | |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 159 | return pkts |
| 160 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 161 | def verify_capture(self, dst_if, capture): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 162 | """Verify captured input packet stream for defined interface. |
| 163 | |
| 164 | :param VppInterface dst_if: Interface to verify captured packet stream |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 165 | for. |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 166 | :param list capture: Captured packet stream. |
| 167 | """ |
| 168 | self.logger.info("Verifying capture on interface %s" % dst_if.name) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 169 | last_info = dict() |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 170 | for i in self.interfaces: |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 171 | last_info[i.sw_if_index] = None |
| 172 | is_sub_if = False |
| 173 | dst_sw_if_index = dst_if.sw_if_index |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 174 | if hasattr(dst_if, "parent"): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 175 | is_sub_if = True |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 176 | for packet in capture: |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 177 | if is_sub_if: |
| 178 | # Check VLAN tags and Ethernet header |
| 179 | packet = dst_if.remove_dot1_layer(packet) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 180 | self.assertTrue(Dot1Q not in packet) |
| 181 | try: |
| 182 | ip = packet[IP] |
| 183 | udp = packet[UDP] |
Paul Vinciguerra | eaea421 | 2019-03-06 11:58:06 -0800 | [diff] [blame] | 184 | payload_info = self.payload_to_info(packet[Raw]) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 185 | packet_index = payload_info.index |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 186 | self.assertEqual(payload_info.dst, dst_sw_if_index) |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 187 | self.logger.debug( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 188 | "Got packet on port %s: src=%u (id=%u)" |
| 189 | % (dst_if.name, payload_info.src, packet_index) |
| 190 | ) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 191 | next_info = self.get_next_packet_info_for_interface2( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 192 | payload_info.src, dst_sw_if_index, last_info[payload_info.src] |
| 193 | ) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 194 | last_info[payload_info.src] = next_info |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 195 | self.assertTrue(next_info is not None) |
| 196 | self.assertEqual(packet_index, next_info.index) |
| 197 | saved_packet = next_info.data |
| 198 | # Check standard fields |
| 199 | self.assertEqual(ip.src, saved_packet[IP].src) |
| 200 | self.assertEqual(ip.dst, saved_packet[IP].dst) |
| 201 | self.assertEqual(udp.sport, saved_packet[UDP].sport) |
| 202 | self.assertEqual(udp.dport, saved_packet[UDP].dport) |
| 203 | except: |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 204 | self.logger.error(ppp("Unexpected or invalid packet:", packet)) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 205 | raise |
| 206 | for i in self.interfaces: |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 207 | remaining_packet = self.get_next_packet_info_for_interface2( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 208 | i.sw_if_index, dst_sw_if_index, last_info[i.sw_if_index] |
| 209 | ) |
| 210 | self.assertTrue( |
| 211 | remaining_packet is None, |
| 212 | "Interface %s: Packet expected from interface %s " |
| 213 | "didn't arrive" % (dst_if.name, i.name), |
| 214 | ) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 215 | |
| 216 | def test_fib(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 217 | """IPv4 FIB test |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 218 | |
| 219 | Test scenario: |
| 220 | |
| 221 | - Create IPv4 stream for pg0 interface |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 222 | - Create IPv4 tagged streams for pg1's and pg2's sub-interface. |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 223 | - Send and verify received packets on each interface. |
| 224 | """ |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 225 | |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 226 | pkts = self.create_stream(self.pg0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 227 | self.pg0.add_stream(pkts) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 228 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 229 | for i in self.sub_interfaces: |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 230 | pkts = self.create_stream(i) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 231 | i.parent.add_stream(pkts) |
| 232 | |
| 233 | self.pg_enable_capture(self.pg_interfaces) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 234 | self.pg_start() |
| 235 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 236 | pkts = self.pg0.get_capture() |
| 237 | self.verify_capture(self.pg0, pkts) |
| 238 | |
| 239 | for i in self.sub_interfaces: |
| 240 | pkts = i.parent.get_capture() |
| 241 | self.verify_capture(i, pkts) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 242 | |
| 243 | |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 244 | class TestIPv4RouteLookup(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 245 | """IPv4 Route Lookup Test Case""" |
| 246 | |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 247 | routes = [] |
Mohsin Kazmi | 5f69432 | 2024-04-19 09:10:46 +0000 | [diff] [blame] | 248 | tables = [] |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 249 | |
Mohsin Kazmi | 5f69432 | 2024-04-19 09:10:46 +0000 | [diff] [blame] | 250 | def route_lookup(self, prefix, exact, table_id=0): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 251 | return self.vapi.api( |
| 252 | self.vapi.papi.ip_route_lookup, |
| 253 | { |
Mohsin Kazmi | 5f69432 | 2024-04-19 09:10:46 +0000 | [diff] [blame] | 254 | "table_id": table_id, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 255 | "exact": exact, |
| 256 | "prefix": prefix, |
| 257 | }, |
| 258 | ) |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 259 | |
| 260 | @classmethod |
| 261 | def setUpClass(cls): |
| 262 | super(TestIPv4RouteLookup, cls).setUpClass() |
| 263 | |
| 264 | @classmethod |
| 265 | def tearDownClass(cls): |
| 266 | super(TestIPv4RouteLookup, cls).tearDownClass() |
| 267 | |
| 268 | def setUp(self): |
| 269 | super(TestIPv4RouteLookup, self).setUp() |
| 270 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 271 | drop_nh = VppRoutePath( |
| 272 | "127.0.0.1", 0xFFFFFFFF, type=FibPathType.FIB_PATH_TYPE_DROP |
| 273 | ) |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 274 | |
| 275 | # Add 3 routes |
| 276 | r = VppIpRoute(self, "1.1.0.0", 16, [drop_nh]) |
| 277 | r.add_vpp_config() |
| 278 | self.routes.append(r) |
| 279 | |
| 280 | r = VppIpRoute(self, "1.1.1.0", 24, [drop_nh]) |
| 281 | r.add_vpp_config() |
| 282 | self.routes.append(r) |
| 283 | |
| 284 | r = VppIpRoute(self, "1.1.1.1", 32, [drop_nh]) |
| 285 | r.add_vpp_config() |
| 286 | self.routes.append(r) |
| 287 | |
Mohsin Kazmi | 5f69432 | 2024-04-19 09:10:46 +0000 | [diff] [blame] | 288 | custom_vrf = VppIpTable(self, 200) |
| 289 | custom_vrf.add_vpp_config() |
| 290 | self.tables.append(custom_vrf) |
| 291 | |
| 292 | r = VppIpRoute(self, "2.2.0.0", 16, [drop_nh], 200) |
| 293 | r.add_vpp_config() |
| 294 | self.routes.append(r) |
| 295 | |
| 296 | r = VppIpRoute(self, "2.2.2.0", 24, [drop_nh], 200) |
| 297 | r.add_vpp_config() |
| 298 | self.routes.append(r) |
| 299 | |
| 300 | r = VppIpRoute(self, "2.2.2.2", 32, [drop_nh], 200) |
| 301 | r.add_vpp_config() |
| 302 | self.routes.append(r) |
| 303 | |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 304 | def tearDown(self): |
| 305 | # Remove the routes we added |
| 306 | for r in self.routes: |
| 307 | r.remove_vpp_config() |
| 308 | |
Mohsin Kazmi | 5f69432 | 2024-04-19 09:10:46 +0000 | [diff] [blame] | 309 | for vrf in self.tables: |
| 310 | vrf.remove_vpp_config() |
| 311 | |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 312 | super(TestIPv4RouteLookup, self).tearDown() |
| 313 | |
| 314 | def test_exact_match(self): |
| 315 | # Verify we find the host route |
| 316 | prefix = "1.1.1.1/32" |
| 317 | result = self.route_lookup(prefix, True) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 318 | assert prefix == str(result.route.prefix) |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 319 | |
| 320 | # Verify we find a middle prefix route |
| 321 | prefix = "1.1.1.0/24" |
| 322 | result = self.route_lookup(prefix, True) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 323 | assert prefix == str(result.route.prefix) |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 324 | |
| 325 | # Verify we do not find an available LPM. |
| 326 | with self.vapi.assert_negative_api_retval(): |
| 327 | self.route_lookup("1.1.1.2/32", True) |
| 328 | |
Mohsin Kazmi | 5f69432 | 2024-04-19 09:10:46 +0000 | [diff] [blame] | 329 | # Verify we find the host route |
| 330 | prefix = "2.2.2.2/32" |
| 331 | result = self.route_lookup(prefix, True, 200) |
| 332 | assert prefix == str(result.route.prefix) |
| 333 | |
| 334 | # Verify we find a middle prefix route |
| 335 | prefix = "2.2.2.0/24" |
| 336 | result = self.route_lookup(prefix, True, 200) |
| 337 | assert prefix == str(result.route.prefix) |
| 338 | |
| 339 | # Verify we do not find an available LPM. |
| 340 | with self.vapi.assert_negative_api_retval(): |
| 341 | self.route_lookup("2.2.2.1/32", True, 200) |
| 342 | |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 343 | def test_longest_prefix_match(self): |
| 344 | # verify we find lpm |
| 345 | lpm_prefix = "1.1.1.0/24" |
| 346 | result = self.route_lookup("1.1.1.2/32", False) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 347 | assert lpm_prefix == str(result.route.prefix) |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 348 | |
| 349 | # Verify we find the exact when not requested |
| 350 | result = self.route_lookup(lpm_prefix, False) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 351 | assert lpm_prefix == str(result.route.prefix) |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 352 | |
Mohsin Kazmi | 5f69432 | 2024-04-19 09:10:46 +0000 | [diff] [blame] | 353 | # verify we find lpm |
| 354 | lpm_prefix = "2.2.2.0/24" |
| 355 | result = self.route_lookup("2.2.2.1/32", False, 200) |
| 356 | assert lpm_prefix == str(result.route.prefix) |
| 357 | |
| 358 | # Verify we find the exact when not requested |
| 359 | result = self.route_lookup(lpm_prefix, False, 200) |
| 360 | assert lpm_prefix == str(result.route.prefix) |
| 361 | |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 362 | # Can't seem to delete the default route so no negative LPM test. |
| 363 | |
| 364 | |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 365 | class TestIPv4IfAddrRoute(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 366 | """IPv4 Interface Addr Route Test Case""" |
Matthew G Smith | 88d29a9 | 2019-07-17 10:01:17 -0500 | [diff] [blame] | 367 | |
| 368 | @classmethod |
| 369 | def setUpClass(cls): |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 370 | super(TestIPv4IfAddrRoute, cls).setUpClass() |
Matthew G Smith | 88d29a9 | 2019-07-17 10:01:17 -0500 | [diff] [blame] | 371 | |
| 372 | @classmethod |
| 373 | def tearDownClass(cls): |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 374 | super(TestIPv4IfAddrRoute, cls).tearDownClass() |
Matthew G Smith | 88d29a9 | 2019-07-17 10:01:17 -0500 | [diff] [blame] | 375 | |
| 376 | def setUp(self): |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 377 | super(TestIPv4IfAddrRoute, self).setUp() |
Matthew G Smith | 88d29a9 | 2019-07-17 10:01:17 -0500 | [diff] [blame] | 378 | |
| 379 | # create 1 pg interface |
| 380 | self.create_pg_interfaces(range(1)) |
| 381 | |
| 382 | for i in self.pg_interfaces: |
| 383 | i.admin_up() |
| 384 | i.config_ip4() |
| 385 | i.resolve_arp() |
| 386 | |
| 387 | def tearDown(self): |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 388 | super(TestIPv4IfAddrRoute, self).tearDown() |
Matthew G Smith | 88d29a9 | 2019-07-17 10:01:17 -0500 | [diff] [blame] | 389 | for i in self.pg_interfaces: |
| 390 | i.unconfig_ip4() |
| 391 | i.admin_down() |
| 392 | |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 393 | def test_ipv4_ifaddrs_same_prefix(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 394 | """IPv4 Interface Addresses Same Prefix test |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 395 | |
| 396 | Test scenario: |
| 397 | |
| 398 | - Verify no route in FIB for prefix 10.10.10.0/24 |
| 399 | - Configure IPv4 address 10.10.10.10/24 on an interface |
| 400 | - Verify route in FIB for prefix 10.10.10.0/24 |
| 401 | - Configure IPv4 address 10.10.10.20/24 on an interface |
| 402 | - Delete 10.10.10.10/24 from interface |
| 403 | - Verify route in FIB for prefix 10.10.10.0/24 |
| 404 | - Delete 10.10.10.20/24 from interface |
| 405 | - Verify no route in FIB for prefix 10.10.10.0/24 |
| 406 | """ |
| 407 | |
| 408 | # create two addresses, verify route not present |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 409 | if_addr1 = VppIpInterfaceAddress(self, self.pg0, "10.10.10.10", 24) |
| 410 | if_addr2 = VppIpInterfaceAddress(self, self.pg0, "10.10.10.20", 24) |
| 411 | self.assertFalse(if_addr1.query_vpp_config()) # 10.10.10.10/24 |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 412 | self.assertFalse(find_route(self, "10.10.10.10", 32)) |
| 413 | self.assertFalse(find_route(self, "10.10.10.20", 32)) |
| 414 | self.assertFalse(find_route(self, "10.10.10.255", 32)) |
| 415 | self.assertFalse(find_route(self, "10.10.10.0", 32)) |
| 416 | |
| 417 | # configure first address, verify route present |
| 418 | if_addr1.add_vpp_config() |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 419 | self.assertTrue(if_addr1.query_vpp_config()) # 10.10.10.10/24 |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 420 | self.assertTrue(find_route(self, "10.10.10.10", 32)) |
| 421 | self.assertFalse(find_route(self, "10.10.10.20", 32)) |
| 422 | self.assertTrue(find_route(self, "10.10.10.255", 32)) |
| 423 | self.assertTrue(find_route(self, "10.10.10.0", 32)) |
| 424 | |
| 425 | # configure second address, delete first, verify route not removed |
| 426 | if_addr2.add_vpp_config() |
| 427 | if_addr1.remove_vpp_config() |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 428 | self.assertFalse(if_addr1.query_vpp_config()) # 10.10.10.10/24 |
| 429 | self.assertTrue(if_addr2.query_vpp_config()) # 10.10.10.20/24 |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 430 | self.assertFalse(find_route(self, "10.10.10.10", 32)) |
| 431 | self.assertTrue(find_route(self, "10.10.10.20", 32)) |
| 432 | self.assertTrue(find_route(self, "10.10.10.255", 32)) |
| 433 | self.assertTrue(find_route(self, "10.10.10.0", 32)) |
| 434 | |
| 435 | # delete second address, verify route removed |
| 436 | if_addr2.remove_vpp_config() |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 437 | self.assertFalse(if_addr2.query_vpp_config()) # 10.10.10.20/24 |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 438 | self.assertFalse(find_route(self, "10.10.10.10", 32)) |
| 439 | self.assertFalse(find_route(self, "10.10.10.20", 32)) |
| 440 | self.assertFalse(find_route(self, "10.10.10.255", 32)) |
| 441 | self.assertFalse(find_route(self, "10.10.10.0", 32)) |
| 442 | |
Matthew G Smith | 88d29a9 | 2019-07-17 10:01:17 -0500 | [diff] [blame] | 443 | def test_ipv4_ifaddr_route(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 444 | """IPv4 Interface Address Route test |
Matthew G Smith | 88d29a9 | 2019-07-17 10:01:17 -0500 | [diff] [blame] | 445 | |
| 446 | Test scenario: |
| 447 | |
| 448 | - Create loopback |
| 449 | - Configure IPv4 address on loopback |
| 450 | - Verify that address is not in the FIB |
| 451 | - Bring loopback up |
| 452 | - Verify that address is in the FIB now |
| 453 | - Bring loopback down |
| 454 | - Verify that address is not in the FIB anymore |
| 455 | - Bring loopback up |
| 456 | - Configure IPv4 address on loopback |
| 457 | - Verify that address is in the FIB now |
| 458 | """ |
| 459 | |
| 460 | # create a loopback and configure IPv4 |
| 461 | loopbacks = self.create_loopback_interfaces(1) |
| 462 | lo_if = self.lo_interfaces[0] |
| 463 | |
| 464 | lo_if.local_ip4_prefix_len = 32 |
| 465 | lo_if.config_ip4() |
| 466 | |
| 467 | # The intf was down when addr was added -> entry not in FIB |
| 468 | fib4_dump = self.vapi.ip_route_dump(0) |
| 469 | self.assertFalse(lo_if.is_ip4_entry_in_fib_dump(fib4_dump)) |
| 470 | |
| 471 | # When intf is brought up, entry is added |
| 472 | lo_if.admin_up() |
| 473 | fib4_dump = self.vapi.ip_route_dump(0) |
| 474 | self.assertTrue(lo_if.is_ip4_entry_in_fib_dump(fib4_dump)) |
| 475 | |
| 476 | # When intf is brought down, entry is removed |
| 477 | lo_if.admin_down() |
| 478 | fib4_dump = self.vapi.ip_route_dump(0) |
| 479 | self.assertFalse(lo_if.is_ip4_entry_in_fib_dump(fib4_dump)) |
| 480 | |
| 481 | # Remove addr, bring up interface, re-add -> entry in FIB |
| 482 | lo_if.unconfig_ip4() |
| 483 | lo_if.admin_up() |
| 484 | lo_if.config_ip4() |
| 485 | fib4_dump = self.vapi.ip_route_dump(0) |
| 486 | self.assertTrue(lo_if.is_ip4_entry_in_fib_dump(fib4_dump)) |
| 487 | |
yedg | dbd366b | 2020-05-14 10:51:53 +0800 | [diff] [blame] | 488 | def test_ipv4_ifaddr_del(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 489 | """Delete an interface address that does not exist""" |
yedg | dbd366b | 2020-05-14 10:51:53 +0800 | [diff] [blame] | 490 | |
| 491 | loopbacks = self.create_loopback_interfaces(1) |
| 492 | lo = self.lo_interfaces[0] |
| 493 | |
| 494 | lo.config_ip4() |
| 495 | lo.admin_up() |
| 496 | |
| 497 | # |
| 498 | # try and remove pg0's subnet from lo |
| 499 | # |
| 500 | with self.vapi.assert_negative_api_retval(): |
| 501 | self.vapi.sw_interface_add_del_address( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 502 | sw_if_index=lo.sw_if_index, prefix=self.pg0.local_ip4_prefix, is_add=0 |
| 503 | ) |
yedg | dbd366b | 2020-05-14 10:51:53 +0800 | [diff] [blame] | 504 | |
Matthew G Smith | 88d29a9 | 2019-07-17 10:01:17 -0500 | [diff] [blame] | 505 | |
Dmitry Valter | 34fa0ce | 2024-03-11 10:38:46 +0000 | [diff] [blame] | 506 | @unittest.skipIf( |
| 507 | "ping" in config.excluded_plugins, "Exclude tests requiring Ping plugin" |
| 508 | ) |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 509 | class TestICMPEcho(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 510 | """ICMP Echo Test Case""" |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 511 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 512 | @classmethod |
| 513 | def setUpClass(cls): |
| 514 | super(TestICMPEcho, cls).setUpClass() |
| 515 | |
| 516 | @classmethod |
| 517 | def tearDownClass(cls): |
| 518 | super(TestICMPEcho, cls).tearDownClass() |
| 519 | |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 520 | def setUp(self): |
| 521 | super(TestICMPEcho, self).setUp() |
| 522 | |
| 523 | # create 1 pg interface |
| 524 | self.create_pg_interfaces(range(1)) |
| 525 | |
| 526 | for i in self.pg_interfaces: |
| 527 | i.admin_up() |
| 528 | i.config_ip4() |
| 529 | i.resolve_arp() |
| 530 | |
| 531 | def tearDown(self): |
| 532 | super(TestICMPEcho, self).tearDown() |
| 533 | for i in self.pg_interfaces: |
| 534 | i.unconfig_ip4() |
| 535 | i.admin_down() |
| 536 | |
| 537 | def test_icmp_echo(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 538 | """VPP replies to ICMP Echo Request |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 539 | |
| 540 | Test scenario: |
| 541 | |
| 542 | - Receive ICMP Echo Request message on pg0 interface. |
| 543 | - Check outgoing ICMP Echo Reply message on pg0 interface. |
| 544 | """ |
| 545 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 546 | icmp_id = 0xB |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 547 | icmp_seq = 5 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 548 | icmp_load = b"\x0a" * 18 |
| 549 | p_echo_request = ( |
| 550 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 551 | / IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) |
| 552 | / ICMP(id=icmp_id, seq=icmp_seq) |
| 553 | / Raw(load=icmp_load) |
| 554 | ) |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 555 | |
| 556 | self.pg0.add_stream(p_echo_request) |
| 557 | self.pg_enable_capture(self.pg_interfaces) |
| 558 | self.pg_start() |
| 559 | |
| 560 | rx = self.pg0.get_capture(1) |
| 561 | rx = rx[0] |
| 562 | ether = rx[Ether] |
| 563 | ipv4 = rx[IP] |
| 564 | icmp = rx[ICMP] |
| 565 | |
| 566 | self.assertEqual(ether.src, self.pg0.local_mac) |
| 567 | self.assertEqual(ether.dst, self.pg0.remote_mac) |
| 568 | |
| 569 | self.assertEqual(ipv4.src, self.pg0.local_ip4) |
| 570 | self.assertEqual(ipv4.dst, self.pg0.remote_ip4) |
| 571 | |
| 572 | self.assertEqual(icmptypes[icmp.type], "echo-reply") |
| 573 | self.assertEqual(icmp.id, icmp_id) |
| 574 | self.assertEqual(icmp.seq, icmp_seq) |
| 575 | self.assertEqual(icmp[Raw].load, icmp_load) |
| 576 | |
| 577 | |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 578 | class TestIPv4FibCrud(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 579 | """FIB - add/update/delete - ip4 routes |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 580 | |
| 581 | Test scenario: |
| 582 | - add 1k, |
| 583 | - del 100, |
| 584 | - add new 1k, |
| 585 | - del 1.5k |
| 586 | |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 587 | ..note:: Python API is too slow to add many routes, needs replacement. |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 588 | """ |
| 589 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 590 | def config_fib_many_to_one(self, start_dest_addr, next_hop_addr, count, start=0): |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 591 | """ |
| 592 | |
| 593 | :param start_dest_addr: |
| 594 | :param next_hop_addr: |
| 595 | :param count: |
| 596 | :return list: added ips with 32 prefix |
| 597 | """ |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 598 | routes = [] |
| 599 | for i in range(count): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 600 | r = VppIpRoute( |
| 601 | self, |
| 602 | start_dest_addr % (i + start), |
| 603 | 32, |
| 604 | [VppRoutePath(next_hop_addr, 0xFFFFFFFF)], |
| 605 | ) |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 606 | r.add_vpp_config() |
| 607 | routes.append(r) |
| 608 | return routes |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 609 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 610 | def unconfig_fib_many_to_one(self, start_dest_addr, next_hop_addr, count, start=0): |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 611 | routes = [] |
| 612 | for i in range(count): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 613 | r = VppIpRoute( |
| 614 | self, |
| 615 | start_dest_addr % (i + start), |
| 616 | 32, |
| 617 | [VppRoutePath(next_hop_addr, 0xFFFFFFFF)], |
| 618 | ) |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 619 | r.remove_vpp_config() |
| 620 | routes.append(r) |
| 621 | return routes |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 622 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 623 | def create_stream(self, src_if, dst_if, routes, count): |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 624 | pkts = [] |
| 625 | |
| 626 | for _ in range(count): |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 627 | dst_addr = random.choice(routes).prefix.network_address |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 628 | info = self.create_packet_info(src_if, dst_if) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 629 | payload = self.info_to_payload(info) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 630 | p = ( |
| 631 | Ether(dst=src_if.local_mac, src=src_if.remote_mac) |
| 632 | / IP(src=src_if.remote_ip4, dst=str(dst_addr)) |
| 633 | / UDP(sport=1234, dport=1234) |
| 634 | / Raw(payload) |
| 635 | ) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 636 | info.data = p.copy() |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 637 | self.extend_packet(p, random.choice(self.pg_if_packet_sizes)) |
| 638 | pkts.append(p) |
| 639 | |
| 640 | return pkts |
| 641 | |
| 642 | def _find_ip_match(self, find_in, pkt): |
| 643 | for p in find_in: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 644 | if self.payload_to_info(p[Raw]) == self.payload_to_info(pkt[Raw]): |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 645 | if p[IP].src != pkt[IP].src: |
| 646 | break |
| 647 | if p[IP].dst != pkt[IP].dst: |
| 648 | break |
| 649 | if p[UDP].sport != pkt[UDP].sport: |
| 650 | break |
| 651 | if p[UDP].dport != pkt[UDP].dport: |
| 652 | break |
| 653 | return p |
| 654 | return None |
| 655 | |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 656 | def verify_capture(self, dst_interface, received_pkts, expected_pkts): |
| 657 | self.assertEqual(len(received_pkts), len(expected_pkts)) |
| 658 | to_verify = list(expected_pkts) |
| 659 | for p in received_pkts: |
| 660 | self.assertEqual(p.src, dst_interface.local_mac) |
| 661 | self.assertEqual(p.dst, dst_interface.remote_mac) |
| 662 | x = self._find_ip_match(to_verify, p) |
| 663 | to_verify.remove(x) |
| 664 | self.assertListEqual(to_verify, []) |
| 665 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 666 | def verify_route_dump(self, routes): |
| 667 | for r in routes: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 668 | self.assertTrue( |
| 669 | find_route(self, r.prefix.network_address, r.prefix.prefixlen) |
| 670 | ) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 671 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 672 | def verify_not_in_route_dump(self, routes): |
| 673 | for r in routes: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 674 | self.assertFalse( |
| 675 | find_route(self, r.prefix.network_address, r.prefix.prefixlen) |
| 676 | ) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 677 | |
| 678 | @classmethod |
| 679 | def setUpClass(cls): |
| 680 | """ |
| 681 | #. Create and initialize 3 pg interfaces. |
| 682 | #. initialize class attributes configured_routes and deleted_routes |
| 683 | to store information between tests. |
| 684 | """ |
| 685 | super(TestIPv4FibCrud, cls).setUpClass() |
| 686 | |
| 687 | try: |
| 688 | # create 3 pg interfaces |
| 689 | cls.create_pg_interfaces(range(3)) |
| 690 | |
| 691 | cls.interfaces = list(cls.pg_interfaces) |
| 692 | |
| 693 | # setup all interfaces |
| 694 | for i in cls.interfaces: |
| 695 | i.admin_up() |
| 696 | i.config_ip4() |
| 697 | i.resolve_arp() |
| 698 | |
| 699 | cls.configured_routes = [] |
| 700 | cls.deleted_routes = [] |
| 701 | cls.pg_if_packet_sizes = [64, 512, 1518, 9018] |
| 702 | |
| 703 | except Exception: |
| 704 | super(TestIPv4FibCrud, cls).tearDownClass() |
| 705 | raise |
| 706 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 707 | @classmethod |
| 708 | def tearDownClass(cls): |
| 709 | super(TestIPv4FibCrud, cls).tearDownClass() |
| 710 | |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 711 | def setUp(self): |
| 712 | super(TestIPv4FibCrud, self).setUp() |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 713 | self.reset_packet_infos() |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 714 | |
Paul Vinciguerra | 4eed747 | 2018-12-16 14:52:36 -0800 | [diff] [blame] | 715 | self.configured_routes = [] |
| 716 | self.deleted_routes = [] |
| 717 | |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 718 | def test_1_add_routes(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 719 | """Add 1k routes""" |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 720 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 721 | # add 100 routes check with traffic script. |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 722 | self.configured_routes.extend( |
| 723 | self.config_fib_many_to_one("10.0.0.%d", self.pg0.remote_ip4, 100) |
| 724 | ) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 725 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 726 | self.verify_route_dump(self.configured_routes) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 727 | |
| 728 | self.stream_1 = self.create_stream( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 729 | self.pg1, self.pg0, self.configured_routes, 100 |
| 730 | ) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 731 | self.stream_2 = self.create_stream( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 732 | self.pg2, self.pg0, self.configured_routes, 100 |
| 733 | ) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 734 | self.pg1.add_stream(self.stream_1) |
| 735 | self.pg2.add_stream(self.stream_2) |
| 736 | |
| 737 | self.pg_enable_capture(self.pg_interfaces) |
| 738 | self.pg_start() |
| 739 | |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 740 | pkts = self.pg0.get_capture(len(self.stream_1) + len(self.stream_2)) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 741 | self.verify_capture(self.pg0, pkts, self.stream_1 + self.stream_2) |
| 742 | |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 743 | def test_2_del_routes(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 744 | """Delete 100 routes |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 745 | |
| 746 | - delete 10 routes check with traffic script. |
| 747 | """ |
Paul Vinciguerra | 4eed747 | 2018-12-16 14:52:36 -0800 | [diff] [blame] | 748 | # config 1M FIB entries |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 749 | self.configured_routes.extend( |
| 750 | self.config_fib_many_to_one("10.0.0.%d", self.pg0.remote_ip4, 100) |
| 751 | ) |
| 752 | self.deleted_routes.extend( |
| 753 | self.unconfig_fib_many_to_one( |
| 754 | "10.0.0.%d", self.pg0.remote_ip4, 10, start=10 |
| 755 | ) |
| 756 | ) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 757 | for x in self.deleted_routes: |
| 758 | self.configured_routes.remove(x) |
| 759 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 760 | self.verify_route_dump(self.configured_routes) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 761 | |
| 762 | self.stream_1 = self.create_stream( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 763 | self.pg1, self.pg0, self.configured_routes, 100 |
| 764 | ) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 765 | self.stream_2 = self.create_stream( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 766 | self.pg2, self.pg0, self.configured_routes, 100 |
| 767 | ) |
| 768 | self.stream_3 = self.create_stream(self.pg1, self.pg0, self.deleted_routes, 100) |
| 769 | self.stream_4 = self.create_stream(self.pg2, self.pg0, self.deleted_routes, 100) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 770 | self.pg1.add_stream(self.stream_1 + self.stream_3) |
| 771 | self.pg2.add_stream(self.stream_2 + self.stream_4) |
| 772 | self.pg_enable_capture(self.pg_interfaces) |
| 773 | self.pg_start() |
| 774 | |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 775 | pkts = self.pg0.get_capture(len(self.stream_1) + len(self.stream_2)) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 776 | self.verify_capture(self.pg0, pkts, self.stream_1 + self.stream_2) |
| 777 | |
| 778 | def test_3_add_new_routes(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 779 | """Add 1k routes |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 780 | |
| 781 | - re-add 5 routes check with traffic script. |
| 782 | - add 100 routes check with traffic script. |
| 783 | """ |
Paul Vinciguerra | 4eed747 | 2018-12-16 14:52:36 -0800 | [diff] [blame] | 784 | # config 1M FIB entries |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 785 | self.configured_routes.extend( |
| 786 | self.config_fib_many_to_one("10.0.0.%d", self.pg0.remote_ip4, 100) |
| 787 | ) |
| 788 | self.deleted_routes.extend( |
| 789 | self.unconfig_fib_many_to_one( |
| 790 | "10.0.0.%d", self.pg0.remote_ip4, 10, start=10 |
| 791 | ) |
| 792 | ) |
Paul Vinciguerra | 4eed747 | 2018-12-16 14:52:36 -0800 | [diff] [blame] | 793 | for x in self.deleted_routes: |
| 794 | self.configured_routes.remove(x) |
| 795 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 796 | tmp = self.config_fib_many_to_one("10.0.0.%d", self.pg0.remote_ip4, 5, start=10) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 797 | self.configured_routes.extend(tmp) |
| 798 | for x in tmp: |
| 799 | self.deleted_routes.remove(x) |
| 800 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 801 | self.configured_routes.extend( |
| 802 | self.config_fib_many_to_one("10.0.1.%d", self.pg0.remote_ip4, 100) |
| 803 | ) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 804 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 805 | self.verify_route_dump(self.configured_routes) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 806 | |
| 807 | self.stream_1 = self.create_stream( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 808 | self.pg1, self.pg0, self.configured_routes, 300 |
| 809 | ) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 810 | self.stream_2 = self.create_stream( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 811 | self.pg2, self.pg0, self.configured_routes, 300 |
| 812 | ) |
| 813 | self.stream_3 = self.create_stream(self.pg1, self.pg0, self.deleted_routes, 100) |
| 814 | self.stream_4 = self.create_stream(self.pg2, self.pg0, self.deleted_routes, 100) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 815 | |
| 816 | self.pg1.add_stream(self.stream_1 + self.stream_3) |
| 817 | self.pg2.add_stream(self.stream_2 + self.stream_4) |
| 818 | self.pg_enable_capture(self.pg_interfaces) |
| 819 | self.pg_start() |
| 820 | |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 821 | pkts = self.pg0.get_capture(len(self.stream_1) + len(self.stream_2)) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 822 | self.verify_capture(self.pg0, pkts, self.stream_1 + self.stream_2) |
| 823 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 824 | # delete 5 routes check with traffic script. |
| 825 | # add 100 routes check with traffic script. |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 826 | self.deleted_routes.extend( |
| 827 | self.unconfig_fib_many_to_one("10.0.0.%d", self.pg0.remote_ip4, 15) |
| 828 | ) |
| 829 | self.deleted_routes.extend( |
| 830 | self.unconfig_fib_many_to_one("10.0.0.%d", self.pg0.remote_ip4, 85) |
| 831 | ) |
| 832 | self.deleted_routes.extend( |
| 833 | self.unconfig_fib_many_to_one("10.0.1.%d", self.pg0.remote_ip4, 100) |
| 834 | ) |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 835 | self.verify_not_in_route_dump(self.deleted_routes) |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 836 | |
| 837 | |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 838 | class TestIPNull(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 839 | """IPv4 routes via NULL""" |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 840 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 841 | @classmethod |
| 842 | def setUpClass(cls): |
| 843 | super(TestIPNull, cls).setUpClass() |
| 844 | |
| 845 | @classmethod |
| 846 | def tearDownClass(cls): |
| 847 | super(TestIPNull, cls).tearDownClass() |
| 848 | |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 849 | def setUp(self): |
| 850 | super(TestIPNull, self).setUp() |
| 851 | |
| 852 | # create 2 pg interfaces |
Neale Ranns | 3b93be5 | 2018-09-07 01:48:54 -0700 | [diff] [blame] | 853 | self.create_pg_interfaces(range(2)) |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 854 | |
| 855 | for i in self.pg_interfaces: |
| 856 | i.admin_up() |
| 857 | i.config_ip4() |
| 858 | i.resolve_arp() |
| 859 | |
| 860 | def tearDown(self): |
| 861 | super(TestIPNull, self).tearDown() |
| 862 | for i in self.pg_interfaces: |
| 863 | i.unconfig_ip4() |
| 864 | i.admin_down() |
| 865 | |
| 866 | def test_ip_null(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 867 | """IP NULL route""" |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 868 | |
| 869 | # |
| 870 | # A route via IP NULL that will reply with ICMP unreachables |
| 871 | # |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 872 | ip_unreach = VppIpRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 873 | self, |
| 874 | "10.0.0.1", |
| 875 | 32, |
| 876 | [ |
| 877 | VppRoutePath( |
| 878 | "0.0.0.0", 0xFFFFFFFF, type=FibPathType.FIB_PATH_TYPE_ICMP_UNREACH |
| 879 | ) |
| 880 | ], |
| 881 | ) |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 882 | ip_unreach.add_vpp_config() |
| 883 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 884 | p_unreach = ( |
| 885 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 886 | / IP(src=self.pg0.remote_ip4, dst="10.0.0.1") |
| 887 | / UDP(sport=1234, dport=1234) |
| 888 | / Raw(b"\xa5" * 100) |
| 889 | ) |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 890 | self.pg0.add_stream(p_unreach) |
| 891 | self.pg_enable_capture(self.pg_interfaces) |
| 892 | self.pg_start() |
| 893 | |
| 894 | rx = self.pg0.get_capture(1) |
| 895 | rx = rx[0] |
| 896 | icmp = rx[ICMP] |
| 897 | |
| 898 | self.assertEqual(icmptypes[icmp.type], "dest-unreach") |
| 899 | self.assertEqual(icmpcodes[icmp.type][icmp.code], "host-unreachable") |
| 900 | self.assertEqual(icmp.src, self.pg0.remote_ip4) |
| 901 | self.assertEqual(icmp.dst, "10.0.0.1") |
| 902 | |
| 903 | # |
| 904 | # ICMP replies are rate limited. so sit and spin. |
| 905 | # |
| 906 | self.sleep(1) |
| 907 | |
| 908 | # |
| 909 | # A route via IP NULL that will reply with ICMP prohibited |
| 910 | # |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 911 | ip_prohibit = VppIpRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 912 | self, |
| 913 | "10.0.0.2", |
| 914 | 32, |
| 915 | [ |
| 916 | VppRoutePath( |
| 917 | "0.0.0.0", 0xFFFFFFFF, type=FibPathType.FIB_PATH_TYPE_ICMP_PROHIBIT |
| 918 | ) |
| 919 | ], |
| 920 | ) |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 921 | ip_prohibit.add_vpp_config() |
| 922 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 923 | p_prohibit = ( |
| 924 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 925 | / IP(src=self.pg0.remote_ip4, dst="10.0.0.2") |
| 926 | / UDP(sport=1234, dport=1234) |
| 927 | / Raw(b"\xa5" * 100) |
| 928 | ) |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 929 | |
| 930 | self.pg0.add_stream(p_prohibit) |
| 931 | self.pg_enable_capture(self.pg_interfaces) |
| 932 | self.pg_start() |
| 933 | |
| 934 | rx = self.pg0.get_capture(1) |
| 935 | |
| 936 | rx = rx[0] |
| 937 | icmp = rx[ICMP] |
| 938 | |
| 939 | self.assertEqual(icmptypes[icmp.type], "dest-unreach") |
| 940 | self.assertEqual(icmpcodes[icmp.type][icmp.code], "host-prohibited") |
| 941 | self.assertEqual(icmp.src, self.pg0.remote_ip4) |
| 942 | self.assertEqual(icmp.dst, "10.0.0.2") |
| 943 | |
Neale Ranns | 3b93be5 | 2018-09-07 01:48:54 -0700 | [diff] [blame] | 944 | def test_ip_drop(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 945 | """IP Drop Routes""" |
Neale Ranns | 3b93be5 | 2018-09-07 01:48:54 -0700 | [diff] [blame] | 946 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 947 | p = ( |
| 948 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 949 | / IP(src=self.pg0.remote_ip4, dst="1.1.1.1") |
| 950 | / UDP(sport=1234, dport=1234) |
| 951 | / Raw(b"\xa5" * 100) |
| 952 | ) |
Neale Ranns | 3b93be5 | 2018-09-07 01:48:54 -0700 | [diff] [blame] | 953 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 954 | r1 = VppIpRoute( |
| 955 | self, |
| 956 | "1.1.1.0", |
| 957 | 24, |
| 958 | [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index)], |
| 959 | ) |
Neale Ranns | 3b93be5 | 2018-09-07 01:48:54 -0700 | [diff] [blame] | 960 | r1.add_vpp_config() |
| 961 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 962 | rx = self.send_and_expect(self.pg0, p * NUM_PKTS, self.pg1) |
Neale Ranns | 3b93be5 | 2018-09-07 01:48:54 -0700 | [diff] [blame] | 963 | |
| 964 | # |
| 965 | # insert a more specific as a drop |
| 966 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 967 | r2 = VppIpRoute( |
| 968 | self, |
| 969 | "1.1.1.1", |
| 970 | 32, |
| 971 | [VppRoutePath("0.0.0.0", 0xFFFFFFFF, type=FibPathType.FIB_PATH_TYPE_DROP)], |
| 972 | ) |
Neale Ranns | 3b93be5 | 2018-09-07 01:48:54 -0700 | [diff] [blame] | 973 | r2.add_vpp_config() |
| 974 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 975 | self.send_and_assert_no_replies(self.pg0, p * NUM_PKTS, "Drop Route") |
Neale Ranns | 3b93be5 | 2018-09-07 01:48:54 -0700 | [diff] [blame] | 976 | r2.remove_vpp_config() |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 977 | rx = self.send_and_expect(self.pg0, p * NUM_PKTS, self.pg1) |
Neale Ranns | 3b93be5 | 2018-09-07 01:48:54 -0700 | [diff] [blame] | 978 | |
Dmitry Valter | e95687b | 2023-12-20 10:47:35 +0000 | [diff] [blame] | 979 | t = VppIpTable(self, 2, False) |
| 980 | t.add_vpp_config() |
| 981 | r3 = VppIpRoute( |
| 982 | self, |
| 983 | "1.1.1.0", |
| 984 | 31, |
| 985 | [VppRoutePath("0.0.0.0", 0xFFFFFFFF, type=FibPathType.FIB_PATH_TYPE_DROP)], |
| 986 | table_id=2, |
| 987 | ) |
| 988 | r3.add_vpp_config() |
| 989 | r3.remove_vpp_config() |
| 990 | t.remove_vpp_config() |
| 991 | |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 992 | |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 993 | class TestIPDisabled(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 994 | """IPv4 disabled""" |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 995 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 996 | @classmethod |
| 997 | def setUpClass(cls): |
| 998 | super(TestIPDisabled, cls).setUpClass() |
| 999 | |
| 1000 | @classmethod |
| 1001 | def tearDownClass(cls): |
| 1002 | super(TestIPDisabled, cls).tearDownClass() |
| 1003 | |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 1004 | def setUp(self): |
| 1005 | super(TestIPDisabled, self).setUp() |
| 1006 | |
| 1007 | # create 2 pg interfaces |
| 1008 | self.create_pg_interfaces(range(2)) |
| 1009 | |
| 1010 | # PG0 is IP enalbed |
| 1011 | self.pg0.admin_up() |
| 1012 | self.pg0.config_ip4() |
| 1013 | self.pg0.resolve_arp() |
| 1014 | |
| 1015 | # PG 1 is not IP enabled |
| 1016 | self.pg1.admin_up() |
| 1017 | |
| 1018 | def tearDown(self): |
| 1019 | super(TestIPDisabled, self).tearDown() |
| 1020 | for i in self.pg_interfaces: |
| 1021 | i.unconfig_ip4() |
| 1022 | i.admin_down() |
| 1023 | |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 1024 | def test_ip_disabled(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1025 | """IP Disabled""" |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 1026 | |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 1027 | MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t |
| 1028 | MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t |
| 1029 | |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 1030 | # |
| 1031 | # An (S,G). |
| 1032 | # one accepting interface, pg0, 2 forwarding interfaces |
| 1033 | # |
| 1034 | route_232_1_1_1 = VppIpMRoute( |
| 1035 | self, |
| 1036 | "0.0.0.0", |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1037 | "232.1.1.1", |
| 1038 | 32, |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 1039 | MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1040 | [ |
| 1041 | VppMRoutePath( |
| 1042 | self.pg1.sw_if_index, MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT |
| 1043 | ), |
| 1044 | VppMRoutePath( |
| 1045 | self.pg0.sw_if_index, MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD |
| 1046 | ), |
| 1047 | ], |
| 1048 | ) |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 1049 | route_232_1_1_1.add_vpp_config() |
| 1050 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1051 | pu = ( |
| 1052 | Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac) |
| 1053 | / IP(src="10.10.10.10", dst=self.pg0.remote_ip4) |
| 1054 | / UDP(sport=1234, dport=1234) |
| 1055 | / Raw(b"\xa5" * 100) |
| 1056 | ) |
| 1057 | pm = ( |
| 1058 | Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac) |
| 1059 | / IP(src="10.10.10.10", dst="232.1.1.1") |
| 1060 | / UDP(sport=1234, dport=1234) |
| 1061 | / Raw(b"\xa5" * 100) |
| 1062 | ) |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 1063 | |
| 1064 | # |
| 1065 | # PG1 does not forward IP traffic |
| 1066 | # |
| 1067 | self.send_and_assert_no_replies(self.pg1, pu, "IP disabled") |
| 1068 | self.send_and_assert_no_replies(self.pg1, pm, "IP disabled") |
| 1069 | |
| 1070 | # |
| 1071 | # IP enable PG1 |
| 1072 | # |
| 1073 | self.pg1.config_ip4() |
| 1074 | |
| 1075 | # |
| 1076 | # Now we get packets through |
| 1077 | # |
| 1078 | self.pg1.add_stream(pu) |
| 1079 | self.pg_enable_capture(self.pg_interfaces) |
| 1080 | self.pg_start() |
| 1081 | rx = self.pg0.get_capture(1) |
| 1082 | |
| 1083 | self.pg1.add_stream(pm) |
| 1084 | self.pg_enable_capture(self.pg_interfaces) |
| 1085 | self.pg_start() |
| 1086 | rx = self.pg0.get_capture(1) |
| 1087 | |
| 1088 | # |
| 1089 | # Disable PG1 |
| 1090 | # |
| 1091 | self.pg1.unconfig_ip4() |
| 1092 | |
| 1093 | # |
| 1094 | # PG1 does not forward IP traffic |
| 1095 | # |
| 1096 | self.send_and_assert_no_replies(self.pg1, pu, "IP disabled") |
| 1097 | self.send_and_assert_no_replies(self.pg1, pm, "IP disabled") |
| 1098 | |
| 1099 | |
Neale Ranns | 9a69a60 | 2017-03-26 10:56:33 -0700 | [diff] [blame] | 1100 | class TestIPSubNets(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1101 | """IPv4 Subnets""" |
Neale Ranns | 9a69a60 | 2017-03-26 10:56:33 -0700 | [diff] [blame] | 1102 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1103 | @classmethod |
| 1104 | def setUpClass(cls): |
| 1105 | super(TestIPSubNets, cls).setUpClass() |
| 1106 | |
| 1107 | @classmethod |
| 1108 | def tearDownClass(cls): |
| 1109 | super(TestIPSubNets, cls).tearDownClass() |
| 1110 | |
Neale Ranns | 9a69a60 | 2017-03-26 10:56:33 -0700 | [diff] [blame] | 1111 | def setUp(self): |
| 1112 | super(TestIPSubNets, self).setUp() |
| 1113 | |
| 1114 | # create a 2 pg interfaces |
| 1115 | self.create_pg_interfaces(range(2)) |
| 1116 | |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1117 | # pg0 we will use to experiment |
Neale Ranns | 9a69a60 | 2017-03-26 10:56:33 -0700 | [diff] [blame] | 1118 | self.pg0.admin_up() |
| 1119 | |
| 1120 | # pg1 is setup normally |
| 1121 | self.pg1.admin_up() |
| 1122 | self.pg1.config_ip4() |
| 1123 | self.pg1.resolve_arp() |
| 1124 | |
| 1125 | def tearDown(self): |
| 1126 | super(TestIPSubNets, self).tearDown() |
| 1127 | for i in self.pg_interfaces: |
| 1128 | i.admin_down() |
| 1129 | |
Neale Ranns | 9a69a60 | 2017-03-26 10:56:33 -0700 | [diff] [blame] | 1130 | def test_ip_sub_nets(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1131 | """IP Sub Nets""" |
Neale Ranns | 9a69a60 | 2017-03-26 10:56:33 -0700 | [diff] [blame] | 1132 | |
| 1133 | # |
| 1134 | # Configure a covering route to forward so we know |
| 1135 | # when we are dropping |
| 1136 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1137 | cover_route = VppIpRoute( |
| 1138 | self, |
| 1139 | "10.0.0.0", |
| 1140 | 8, |
| 1141 | [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index)], |
| 1142 | ) |
Neale Ranns | 9a69a60 | 2017-03-26 10:56:33 -0700 | [diff] [blame] | 1143 | cover_route.add_vpp_config() |
| 1144 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1145 | p = ( |
| 1146 | Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac) |
| 1147 | / IP(dst="10.10.10.10", src=self.pg0.local_ip4) |
| 1148 | / UDP(sport=1234, dport=1234) |
| 1149 | / Raw(b"\xa5" * 100) |
| 1150 | ) |
Neale Ranns | 9a69a60 | 2017-03-26 10:56:33 -0700 | [diff] [blame] | 1151 | |
| 1152 | self.pg1.add_stream(p) |
| 1153 | self.pg_enable_capture(self.pg_interfaces) |
| 1154 | self.pg_start() |
| 1155 | rx = self.pg1.get_capture(1) |
| 1156 | |
| 1157 | # |
| 1158 | # Configure some non-/24 subnets on an IP interface |
| 1159 | # |
| 1160 | ip_addr_n = socket.inet_pton(socket.AF_INET, "10.10.10.10") |
| 1161 | |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1162 | self.vapi.sw_interface_add_del_address( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1163 | sw_if_index=self.pg0.sw_if_index, prefix="10.10.10.10/16" |
| 1164 | ) |
Neale Ranns | 9a69a60 | 2017-03-26 10:56:33 -0700 | [diff] [blame] | 1165 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1166 | pn = ( |
| 1167 | Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac) |
| 1168 | / IP(dst="10.10.0.0", src=self.pg0.local_ip4) |
| 1169 | / UDP(sport=1234, dport=1234) |
| 1170 | / Raw(b"\xa5" * 100) |
| 1171 | ) |
| 1172 | pb = ( |
| 1173 | Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac) |
| 1174 | / IP(dst="10.10.255.255", src=self.pg0.local_ip4) |
| 1175 | / UDP(sport=1234, dport=1234) |
| 1176 | / Raw(b"\xa5" * 100) |
| 1177 | ) |
Neale Ranns | 9a69a60 | 2017-03-26 10:56:33 -0700 | [diff] [blame] | 1178 | |
| 1179 | self.send_and_assert_no_replies(self.pg1, pn, "IP Network address") |
| 1180 | self.send_and_assert_no_replies(self.pg1, pb, "IP Broadcast address") |
| 1181 | |
| 1182 | # remove the sub-net and we are forwarding via the cover again |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1183 | self.vapi.sw_interface_add_del_address( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1184 | sw_if_index=self.pg0.sw_if_index, prefix="10.10.10.10/16", is_add=0 |
| 1185 | ) |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 1186 | |
Neale Ranns | 9a69a60 | 2017-03-26 10:56:33 -0700 | [diff] [blame] | 1187 | self.pg1.add_stream(pn) |
| 1188 | self.pg_enable_capture(self.pg_interfaces) |
| 1189 | self.pg_start() |
| 1190 | rx = self.pg1.get_capture(1) |
| 1191 | self.pg1.add_stream(pb) |
| 1192 | self.pg_enable_capture(self.pg_interfaces) |
| 1193 | self.pg_start() |
| 1194 | rx = self.pg1.get_capture(1) |
| 1195 | |
| 1196 | # |
| 1197 | # A /31 is a special case where the 'other-side' is an attached host |
| 1198 | # packets to that peer generate ARP requests |
| 1199 | # |
| 1200 | ip_addr_n = socket.inet_pton(socket.AF_INET, "10.10.10.10") |
| 1201 | |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1202 | self.vapi.sw_interface_add_del_address( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1203 | sw_if_index=self.pg0.sw_if_index, prefix="10.10.10.10/31" |
| 1204 | ) |
Neale Ranns | 9a69a60 | 2017-03-26 10:56:33 -0700 | [diff] [blame] | 1205 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1206 | pn = ( |
| 1207 | Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac) |
| 1208 | / IP(dst="10.10.10.11", src=self.pg0.local_ip4) |
| 1209 | / UDP(sport=1234, dport=1234) |
| 1210 | / Raw(b"\xa5" * 100) |
| 1211 | ) |
Neale Ranns | 9a69a60 | 2017-03-26 10:56:33 -0700 | [diff] [blame] | 1212 | |
| 1213 | self.pg1.add_stream(pn) |
| 1214 | self.pg_enable_capture(self.pg_interfaces) |
| 1215 | self.pg_start() |
| 1216 | rx = self.pg0.get_capture(1) |
| 1217 | rx[ARP] |
| 1218 | |
| 1219 | # remove the sub-net and we are forwarding via the cover again |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1220 | self.vapi.sw_interface_add_del_address( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1221 | sw_if_index=self.pg0.sw_if_index, prefix="10.10.10.10/31", is_add=0 |
| 1222 | ) |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 1223 | |
Neale Ranns | 9a69a60 | 2017-03-26 10:56:33 -0700 | [diff] [blame] | 1224 | self.pg1.add_stream(pn) |
| 1225 | self.pg_enable_capture(self.pg_interfaces) |
| 1226 | self.pg_start() |
| 1227 | rx = self.pg1.get_capture(1) |
| 1228 | |
| 1229 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1230 | class TestIPLoadBalance(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1231 | """IPv4 Load-Balancing""" |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1232 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1233 | @classmethod |
| 1234 | def setUpClass(cls): |
| 1235 | super(TestIPLoadBalance, cls).setUpClass() |
| 1236 | |
| 1237 | @classmethod |
| 1238 | def tearDownClass(cls): |
| 1239 | super(TestIPLoadBalance, cls).tearDownClass() |
| 1240 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1241 | def setUp(self): |
| 1242 | super(TestIPLoadBalance, self).setUp() |
| 1243 | |
| 1244 | self.create_pg_interfaces(range(5)) |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1245 | mpls_tbl = VppMplsTable(self, 0) |
| 1246 | mpls_tbl.add_vpp_config() |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1247 | |
| 1248 | for i in self.pg_interfaces: |
| 1249 | i.admin_up() |
| 1250 | i.config_ip4() |
| 1251 | i.resolve_arp() |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1252 | i.enable_mpls() |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1253 | |
| 1254 | def tearDown(self): |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1255 | for i in self.pg_interfaces: |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1256 | i.disable_mpls() |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1257 | i.unconfig_ip4() |
| 1258 | i.admin_down() |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1259 | super(TestIPLoadBalance, self).tearDown() |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1260 | |
Neale Ranns | 3d5f08a | 2021-01-22 16:12:38 +0000 | [diff] [blame] | 1261 | def total_len(self, rxs): |
| 1262 | n = 0 |
| 1263 | for rx in rxs: |
| 1264 | n += len(rx) |
| 1265 | return n |
| 1266 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1267 | def test_ip_load_balance(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1268 | """IP Load-Balancing""" |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1269 | |
Ahmed Abdelsalam | f2984bb | 2020-11-20 18:56:09 +0000 | [diff] [blame] | 1270 | fhc = VppEnum.vl_api_ip_flow_hash_config_t |
Takeru Hayasaka | b23c6f4 | 2023-01-17 04:45:58 +0900 | [diff] [blame] | 1271 | fhcv2 = VppEnum.vl_api_ip_flow_hash_config_v2_t |
Ahmed Abdelsalam | f2984bb | 2020-11-20 18:56:09 +0000 | [diff] [blame] | 1272 | af = VppEnum.vl_api_address_family_t |
| 1273 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1274 | # |
| 1275 | # An array of packets that differ only in the destination port |
| 1276 | # |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1277 | port_ip_pkts = [] |
| 1278 | port_mpls_pkts = [] |
Takeru Hayasaka | b23c6f4 | 2023-01-17 04:45:58 +0900 | [diff] [blame] | 1279 | port_gtp_pkts = [] |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1280 | |
| 1281 | # |
| 1282 | # An array of packets that differ only in the source address |
| 1283 | # |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1284 | src_ip_pkts = [] |
| 1285 | src_mpls_pkts = [] |
Takeru Hayasaka | b23c6f4 | 2023-01-17 04:45:58 +0900 | [diff] [blame] | 1286 | src_gtp_pkts = [] |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1287 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1288 | for ii in range(NUM_PKTS): |
Takeru Hayasaka | b23c6f4 | 2023-01-17 04:45:58 +0900 | [diff] [blame] | 1289 | internal_src_ip_hdr = IP(dst="10.0.0.1", src="20.0.0.1") |
| 1290 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1291 | port_ip_hdr = ( |
Takeru Hayasaka | b23c6f4 | 2023-01-17 04:45:58 +0900 | [diff] [blame] | 1292 | internal_src_ip_hdr |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1293 | / UDP(sport=1234, dport=1234 + ii) |
| 1294 | / Raw(b"\xa5" * 100) |
| 1295 | ) |
| 1296 | port_ip_pkts.append( |
| 1297 | (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / port_ip_hdr) |
| 1298 | ) |
| 1299 | port_mpls_pkts.append( |
| 1300 | ( |
| 1301 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 1302 | / MPLS(label=66, ttl=2) |
| 1303 | / port_ip_hdr |
| 1304 | ) |
| 1305 | ) |
Takeru Hayasaka | b23c6f4 | 2023-01-17 04:45:58 +0900 | [diff] [blame] | 1306 | port_gtp_pkts.append( |
| 1307 | ( |
| 1308 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 1309 | / internal_src_ip_hdr |
| 1310 | / UDP(sport=2152, dport=2152, chksum=0) |
| 1311 | / GTP_U_Header(gtp_type="g_pdu", teid=200) |
| 1312 | / Raw(b"\xa5" * 100) |
| 1313 | ) |
| 1314 | ) |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1315 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1316 | src_ip_hdr = ( |
| 1317 | IP(dst="10.0.0.1", src="20.0.0.%d" % ii) |
| 1318 | / UDP(sport=1234, dport=1234) |
| 1319 | / Raw(b"\xa5" * 100) |
| 1320 | ) |
| 1321 | src_ip_pkts.append( |
| 1322 | (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / src_ip_hdr) |
| 1323 | ) |
| 1324 | src_mpls_pkts.append( |
| 1325 | ( |
| 1326 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 1327 | / MPLS(label=66, ttl=2) |
| 1328 | / src_ip_hdr |
| 1329 | ) |
| 1330 | ) |
Takeru Hayasaka | b23c6f4 | 2023-01-17 04:45:58 +0900 | [diff] [blame] | 1331 | src_gtp_pkts.append( |
| 1332 | ( |
| 1333 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 1334 | / IP(dst="10.0.0.1", src="20.0.0.1") |
| 1335 | / UDP(sport=2152, dport=2152, chksum=0) |
| 1336 | / GTP_U_Header(gtp_type="g_pdu", teid=ii) |
| 1337 | / Raw(b"\xa5" * 100) |
| 1338 | ) |
| 1339 | ) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1340 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1341 | route_10_0_0_1 = VppIpRoute( |
| 1342 | self, |
| 1343 | "10.0.0.1", |
| 1344 | 32, |
| 1345 | [ |
| 1346 | VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index), |
| 1347 | VppRoutePath(self.pg2.remote_ip4, self.pg2.sw_if_index), |
| 1348 | ], |
| 1349 | ) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1350 | route_10_0_0_1.add_vpp_config() |
| 1351 | |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1352 | binding = VppMplsIpBind(self, 66, "10.0.0.1", 32) |
| 1353 | binding.add_vpp_config() |
| 1354 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1355 | # |
| 1356 | # inject the packet on pg0 - expect load-balancing across the 2 paths |
| 1357 | # - since the default hash config is to use IP src,dst and port |
| 1358 | # src,dst |
| 1359 | # We are not going to ensure equal amounts of packets across each link, |
| 1360 | # since the hash algorithm is statistical and therefore this can never |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1361 | # be guaranteed. But with 64 different packets we do expect some |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1362 | # balancing. So instead just ensure there is traffic on each link. |
| 1363 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1364 | rx = self.send_and_expect_load_balancing( |
| 1365 | self.pg0, port_ip_pkts, [self.pg1, self.pg2] |
| 1366 | ) |
Neale Ranns | 3d5f08a | 2021-01-22 16:12:38 +0000 | [diff] [blame] | 1367 | n_ip_pg0 = len(rx[0]) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1368 | self.send_and_expect_load_balancing(self.pg0, src_ip_pkts, [self.pg1, self.pg2]) |
| 1369 | self.send_and_expect_load_balancing( |
| 1370 | self.pg0, port_mpls_pkts, [self.pg1, self.pg2] |
| 1371 | ) |
| 1372 | rx = self.send_and_expect_load_balancing( |
| 1373 | self.pg0, src_mpls_pkts, [self.pg1, self.pg2] |
| 1374 | ) |
Neale Ranns | 3d5f08a | 2021-01-22 16:12:38 +0000 | [diff] [blame] | 1375 | n_mpls_pg0 = len(rx[0]) |
| 1376 | |
| 1377 | # |
| 1378 | # change the router ID and expect the distribution changes |
| 1379 | # |
| 1380 | self.vapi.set_ip_flow_hash_router_id(router_id=0x11111111) |
| 1381 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1382 | rx = self.send_and_expect_load_balancing( |
| 1383 | self.pg0, port_ip_pkts, [self.pg1, self.pg2] |
| 1384 | ) |
Neale Ranns | 3d5f08a | 2021-01-22 16:12:38 +0000 | [diff] [blame] | 1385 | self.assertNotEqual(n_ip_pg0, len(rx[0])) |
| 1386 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1387 | rx = self.send_and_expect_load_balancing( |
| 1388 | self.pg0, src_mpls_pkts, [self.pg1, self.pg2] |
| 1389 | ) |
Neale Ranns | 3d5f08a | 2021-01-22 16:12:38 +0000 | [diff] [blame] | 1390 | self.assertNotEqual(n_mpls_pg0, len(rx[0])) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1391 | |
| 1392 | # |
| 1393 | # change the flow hash config so it's only IP src,dst |
| 1394 | # - now only the stream with differing source address will |
| 1395 | # load-balance |
| 1396 | # |
Ahmed Abdelsalam | f2984bb | 2020-11-20 18:56:09 +0000 | [diff] [blame] | 1397 | self.vapi.set_ip_flow_hash_v2( |
| 1398 | af=af.ADDRESS_IP4, |
| 1399 | table_id=0, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1400 | flow_hash_config=( |
| 1401 | fhc.IP_API_FLOW_HASH_SRC_IP |
| 1402 | | fhc.IP_API_FLOW_HASH_DST_IP |
| 1403 | | fhc.IP_API_FLOW_HASH_PROTO |
| 1404 | ), |
| 1405 | ) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1406 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1407 | self.send_and_expect_load_balancing(self.pg0, src_ip_pkts, [self.pg1, self.pg2]) |
| 1408 | self.send_and_expect_load_balancing( |
| 1409 | self.pg0, src_mpls_pkts, [self.pg1, self.pg2] |
| 1410 | ) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1411 | |
Neale Ranns | 699bea2 | 2022-02-17 09:22:16 +0000 | [diff] [blame] | 1412 | self.send_and_expect_only(self.pg0, port_ip_pkts, self.pg2) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1413 | |
| 1414 | # |
Takeru Hayasaka | b23c6f4 | 2023-01-17 04:45:58 +0900 | [diff] [blame] | 1415 | # this case gtp v1 teid key LB |
| 1416 | # |
| 1417 | self.vapi.set_ip_flow_hash_v3( |
| 1418 | af=af.ADDRESS_IP4, |
| 1419 | table_id=0, |
| 1420 | flow_hash_config=( |
| 1421 | fhcv2.IP_API_V2_FLOW_HASH_SRC_IP |
| 1422 | | fhcv2.IP_API_V2_FLOW_HASH_PROTO |
| 1423 | | fhcv2.IP_API_V2_FLOW_HASH_GTPV1_TEID |
| 1424 | ), |
| 1425 | ) |
| 1426 | self.logger.info(self.vapi.cli("show ip fib")) |
| 1427 | |
| 1428 | self.send_and_expect_load_balancing( |
| 1429 | self.pg0, src_gtp_pkts, [self.pg1, self.pg2] |
| 1430 | ) |
| 1431 | |
| 1432 | self.send_and_expect_only(self.pg0, port_gtp_pkts, self.pg2) |
| 1433 | |
| 1434 | # |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1435 | # change the flow hash config back to defaults |
| 1436 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1437 | self.vapi.set_ip_flow_hash(vrf_id=0, src=1, dst=1, proto=1, sport=1, dport=1) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1438 | |
| 1439 | # |
| 1440 | # Recursive prefixes |
| 1441 | # - testing that 2 stages of load-balancing occurs and there is no |
| 1442 | # polarisation (i.e. only 2 of 4 paths are used) |
| 1443 | # |
| 1444 | port_pkts = [] |
| 1445 | src_pkts = [] |
| 1446 | |
| 1447 | for ii in range(257): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1448 | port_pkts.append( |
| 1449 | ( |
| 1450 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 1451 | / IP(dst="1.1.1.1", src="20.0.0.1") |
| 1452 | / UDP(sport=1234, dport=1234 + ii) |
| 1453 | / Raw(b"\xa5" * 100) |
| 1454 | ) |
| 1455 | ) |
| 1456 | src_pkts.append( |
| 1457 | ( |
| 1458 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 1459 | / IP(dst="1.1.1.1", src="20.0.0.%d" % ii) |
| 1460 | / UDP(sport=1234, dport=1234) |
| 1461 | / Raw(b"\xa5" * 100) |
| 1462 | ) |
| 1463 | ) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1464 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1465 | route_10_0_0_2 = VppIpRoute( |
| 1466 | self, |
| 1467 | "10.0.0.2", |
| 1468 | 32, |
| 1469 | [ |
| 1470 | VppRoutePath(self.pg3.remote_ip4, self.pg3.sw_if_index), |
| 1471 | VppRoutePath(self.pg4.remote_ip4, self.pg4.sw_if_index), |
| 1472 | ], |
| 1473 | ) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1474 | route_10_0_0_2.add_vpp_config() |
| 1475 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1476 | route_1_1_1_1 = VppIpRoute( |
| 1477 | self, |
| 1478 | "1.1.1.1", |
| 1479 | 32, |
| 1480 | [ |
| 1481 | VppRoutePath("10.0.0.2", 0xFFFFFFFF), |
| 1482 | VppRoutePath("10.0.0.1", 0xFFFFFFFF), |
| 1483 | ], |
| 1484 | ) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1485 | route_1_1_1_1.add_vpp_config() |
| 1486 | |
| 1487 | # |
| 1488 | # inject the packet on pg0 - expect load-balancing across all 4 paths |
| 1489 | # |
| 1490 | self.vapi.cli("clear trace") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1491 | self.send_and_expect_load_balancing( |
| 1492 | self.pg0, port_pkts, [self.pg1, self.pg2, self.pg3, self.pg4] |
| 1493 | ) |
| 1494 | self.send_and_expect_load_balancing( |
| 1495 | self.pg0, src_pkts, [self.pg1, self.pg2, self.pg3, self.pg4] |
| 1496 | ) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1497 | |
Neale Ranns | 42e6b09 | 2017-07-31 02:56:03 -0700 | [diff] [blame] | 1498 | # |
Neale Ranns | 3d5f08a | 2021-01-22 16:12:38 +0000 | [diff] [blame] | 1499 | # bring down pg1 expect LB to adjust to use only those that are up |
Neale Ranns | 6348074 | 2019-03-13 06:41:52 -0700 | [diff] [blame] | 1500 | # |
| 1501 | self.pg1.link_down() |
| 1502 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1503 | rx = self.send_and_expect_load_balancing( |
| 1504 | self.pg0, src_pkts, [self.pg2, self.pg3, self.pg4] |
| 1505 | ) |
Neale Ranns | 3d5f08a | 2021-01-22 16:12:38 +0000 | [diff] [blame] | 1506 | self.assertEqual(len(src_pkts), self.total_len(rx)) |
Neale Ranns | 6348074 | 2019-03-13 06:41:52 -0700 | [diff] [blame] | 1507 | |
| 1508 | # |
Neale Ranns | 3d5f08a | 2021-01-22 16:12:38 +0000 | [diff] [blame] | 1509 | # bring down pg2 expect LB to adjust to use only those that are up |
Neale Ranns | 6348074 | 2019-03-13 06:41:52 -0700 | [diff] [blame] | 1510 | # |
| 1511 | self.pg2.link_down() |
| 1512 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1513 | rx = self.send_and_expect_load_balancing( |
| 1514 | self.pg0, src_pkts, [self.pg3, self.pg4] |
| 1515 | ) |
Neale Ranns | 3d5f08a | 2021-01-22 16:12:38 +0000 | [diff] [blame] | 1516 | self.assertEqual(len(src_pkts), self.total_len(rx)) |
Neale Ranns | 6348074 | 2019-03-13 06:41:52 -0700 | [diff] [blame] | 1517 | |
| 1518 | # |
| 1519 | # bring the links back up - expect LB over all again |
| 1520 | # |
| 1521 | self.pg1.link_up() |
| 1522 | self.pg2.link_up() |
| 1523 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1524 | rx = self.send_and_expect_load_balancing( |
| 1525 | self.pg0, src_pkts, [self.pg1, self.pg2, self.pg3, self.pg4] |
| 1526 | ) |
Neale Ranns | 3d5f08a | 2021-01-22 16:12:38 +0000 | [diff] [blame] | 1527 | self.assertEqual(len(src_pkts), self.total_len(rx)) |
Neale Ranns | 6348074 | 2019-03-13 06:41:52 -0700 | [diff] [blame] | 1528 | |
| 1529 | # |
| 1530 | # The same link-up/down but this time admin state |
| 1531 | # |
| 1532 | self.pg1.admin_down() |
| 1533 | self.pg2.admin_down() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1534 | rx = self.send_and_expect_load_balancing( |
| 1535 | self.pg0, src_pkts, [self.pg3, self.pg4] |
| 1536 | ) |
Neale Ranns | 3d5f08a | 2021-01-22 16:12:38 +0000 | [diff] [blame] | 1537 | self.assertEqual(len(src_pkts), self.total_len(rx)) |
Neale Ranns | 6348074 | 2019-03-13 06:41:52 -0700 | [diff] [blame] | 1538 | self.pg1.admin_up() |
| 1539 | self.pg2.admin_up() |
| 1540 | self.pg1.resolve_arp() |
| 1541 | self.pg2.resolve_arp() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1542 | rx = self.send_and_expect_load_balancing( |
| 1543 | self.pg0, src_pkts, [self.pg1, self.pg2, self.pg3, self.pg4] |
| 1544 | ) |
Neale Ranns | 3d5f08a | 2021-01-22 16:12:38 +0000 | [diff] [blame] | 1545 | self.assertEqual(len(src_pkts), self.total_len(rx)) |
Neale Ranns | 6348074 | 2019-03-13 06:41:52 -0700 | [diff] [blame] | 1546 | |
| 1547 | # |
Neale Ranns | 42e6b09 | 2017-07-31 02:56:03 -0700 | [diff] [blame] | 1548 | # Recursive prefixes |
| 1549 | # - testing that 2 stages of load-balancing, no choices |
| 1550 | # |
| 1551 | port_pkts = [] |
| 1552 | |
| 1553 | for ii in range(257): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1554 | port_pkts.append( |
| 1555 | ( |
| 1556 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 1557 | / IP(dst="1.1.1.2", src="20.0.0.2") |
| 1558 | / UDP(sport=1234, dport=1234 + ii) |
| 1559 | / Raw(b"\xa5" * 100) |
| 1560 | ) |
| 1561 | ) |
Neale Ranns | 42e6b09 | 2017-07-31 02:56:03 -0700 | [diff] [blame] | 1562 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1563 | route_10_0_0_3 = VppIpRoute( |
| 1564 | self, |
| 1565 | "10.0.0.3", |
| 1566 | 32, |
| 1567 | [VppRoutePath(self.pg3.remote_ip4, self.pg3.sw_if_index)], |
| 1568 | ) |
Neale Ranns | 42e6b09 | 2017-07-31 02:56:03 -0700 | [diff] [blame] | 1569 | route_10_0_0_3.add_vpp_config() |
| 1570 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1571 | route_1_1_1_2 = VppIpRoute( |
| 1572 | self, "1.1.1.2", 32, [VppRoutePath("10.0.0.3", 0xFFFFFFFF)] |
| 1573 | ) |
Neale Ranns | 42e6b09 | 2017-07-31 02:56:03 -0700 | [diff] [blame] | 1574 | route_1_1_1_2.add_vpp_config() |
| 1575 | |
| 1576 | # |
Neale Ranns | 6348074 | 2019-03-13 06:41:52 -0700 | [diff] [blame] | 1577 | # inject the packet on pg0 - rx only on via routes output interface |
Neale Ranns | 42e6b09 | 2017-07-31 02:56:03 -0700 | [diff] [blame] | 1578 | # |
| 1579 | self.vapi.cli("clear trace") |
Neale Ranns | 699bea2 | 2022-02-17 09:22:16 +0000 | [diff] [blame] | 1580 | self.send_and_expect_only(self.pg0, port_pkts, self.pg3) |
Neale Ranns | 42e6b09 | 2017-07-31 02:56:03 -0700 | [diff] [blame] | 1581 | |
Neale Ranns | 6348074 | 2019-03-13 06:41:52 -0700 | [diff] [blame] | 1582 | # |
| 1583 | # Add a LB route in the presence of a down link - expect no |
| 1584 | # packets over the down link |
| 1585 | # |
| 1586 | self.pg3.link_down() |
| 1587 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1588 | route_10_0_0_3 = VppIpRoute( |
| 1589 | self, |
| 1590 | "10.0.0.3", |
| 1591 | 32, |
| 1592 | [ |
| 1593 | VppRoutePath(self.pg3.remote_ip4, self.pg3.sw_if_index), |
| 1594 | VppRoutePath(self.pg4.remote_ip4, self.pg4.sw_if_index), |
| 1595 | ], |
| 1596 | ) |
Neale Ranns | 6348074 | 2019-03-13 06:41:52 -0700 | [diff] [blame] | 1597 | route_10_0_0_3.add_vpp_config() |
| 1598 | |
| 1599 | port_pkts = [] |
| 1600 | for ii in range(257): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1601 | port_pkts.append( |
| 1602 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 1603 | / IP(dst="10.0.0.3", src="20.0.0.2") |
| 1604 | / UDP(sport=1234, dport=1234 + ii) |
| 1605 | / Raw(b"\xa5" * 100) |
| 1606 | ) |
Neale Ranns | 6348074 | 2019-03-13 06:41:52 -0700 | [diff] [blame] | 1607 | |
Neale Ranns | 699bea2 | 2022-02-17 09:22:16 +0000 | [diff] [blame] | 1608 | self.send_and_expect_only(self.pg0, port_pkts, self.pg4) |
Neale Ranns | 6348074 | 2019-03-13 06:41:52 -0700 | [diff] [blame] | 1609 | |
| 1610 | # bring the link back up |
| 1611 | self.pg3.link_up() |
| 1612 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1613 | rx = self.send_and_expect_load_balancing( |
| 1614 | self.pg0, port_pkts, [self.pg3, self.pg4] |
| 1615 | ) |
Neale Ranns | 3d5f08a | 2021-01-22 16:12:38 +0000 | [diff] [blame] | 1616 | self.assertEqual(len(src_pkts), self.total_len(rx)) |
Neale Ranns | 6348074 | 2019-03-13 06:41:52 -0700 | [diff] [blame] | 1617 | |
Neale Ranns | 30d0fd4 | 2017-05-30 07:30:04 -0700 | [diff] [blame] | 1618 | |
| 1619 | class TestIPVlan0(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1620 | """IPv4 VLAN-0""" |
Neale Ranns | 30d0fd4 | 2017-05-30 07:30:04 -0700 | [diff] [blame] | 1621 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1622 | @classmethod |
| 1623 | def setUpClass(cls): |
| 1624 | super(TestIPVlan0, cls).setUpClass() |
| 1625 | |
| 1626 | @classmethod |
| 1627 | def tearDownClass(cls): |
| 1628 | super(TestIPVlan0, cls).tearDownClass() |
| 1629 | |
Neale Ranns | 30d0fd4 | 2017-05-30 07:30:04 -0700 | [diff] [blame] | 1630 | def setUp(self): |
| 1631 | super(TestIPVlan0, self).setUp() |
| 1632 | |
| 1633 | self.create_pg_interfaces(range(2)) |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1634 | mpls_tbl = VppMplsTable(self, 0) |
| 1635 | mpls_tbl.add_vpp_config() |
Neale Ranns | 30d0fd4 | 2017-05-30 07:30:04 -0700 | [diff] [blame] | 1636 | |
| 1637 | for i in self.pg_interfaces: |
| 1638 | i.admin_up() |
| 1639 | i.config_ip4() |
| 1640 | i.resolve_arp() |
| 1641 | i.enable_mpls() |
| 1642 | |
| 1643 | def tearDown(self): |
Neale Ranns | 30d0fd4 | 2017-05-30 07:30:04 -0700 | [diff] [blame] | 1644 | for i in self.pg_interfaces: |
| 1645 | i.disable_mpls() |
| 1646 | i.unconfig_ip4() |
| 1647 | i.admin_down() |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1648 | super(TestIPVlan0, self).tearDown() |
Neale Ranns | 30d0fd4 | 2017-05-30 07:30:04 -0700 | [diff] [blame] | 1649 | |
Neale Ranns | 30d0fd4 | 2017-05-30 07:30:04 -0700 | [diff] [blame] | 1650 | def test_ip_vlan_0(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1651 | """IP VLAN-0""" |
Neale Ranns | 30d0fd4 | 2017-05-30 07:30:04 -0700 | [diff] [blame] | 1652 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1653 | pkts = ( |
| 1654 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 1655 | / Dot1Q(vlan=0) |
| 1656 | / IP(dst=self.pg1.remote_ip4, src=self.pg0.remote_ip4) |
| 1657 | / UDP(sport=1234, dport=1234) |
| 1658 | / Raw(b"\xa5" * 100) |
| 1659 | ) * NUM_PKTS |
Neale Ranns | 30d0fd4 | 2017-05-30 07:30:04 -0700 | [diff] [blame] | 1660 | |
| 1661 | # |
| 1662 | # Expect that packets sent on VLAN-0 are forwarded on the |
| 1663 | # main interface. |
| 1664 | # |
| 1665 | self.send_and_expect(self.pg0, pkts, self.pg1) |
| 1666 | |
| 1667 | |
Brian Russell | 318fdb8 | 2021-01-19 16:56:32 +0000 | [diff] [blame] | 1668 | class IPPuntSetup(object): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1669 | """Setup for IPv4 Punt Police/Redirect""" |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1670 | |
Brian Russell | 318fdb8 | 2021-01-19 16:56:32 +0000 | [diff] [blame] | 1671 | def punt_setup(self): |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 1672 | self.create_pg_interfaces(range(4)) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1673 | |
| 1674 | for i in self.pg_interfaces: |
| 1675 | i.admin_up() |
| 1676 | i.config_ip4() |
| 1677 | i.resolve_arp() |
| 1678 | |
Neale Ranns | 68577d2 | 2019-06-04 13:31:23 +0000 | [diff] [blame] | 1679 | # use UDP packet that have a port we need to explicitly |
| 1680 | # register to get punted. |
| 1681 | pt_l4 = VppEnum.vl_api_punt_type_t.PUNT_API_TYPE_L4 |
| 1682 | af_ip4 = VppEnum.vl_api_address_family_t.ADDRESS_IP4 |
| 1683 | udp_proto = VppEnum.vl_api_ip_proto_t.IP_API_PROTO_UDP |
| 1684 | punt_udp = { |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1685 | "type": pt_l4, |
| 1686 | "punt": { |
| 1687 | "l4": { |
| 1688 | "af": af_ip4, |
| 1689 | "protocol": udp_proto, |
| 1690 | "port": 1234, |
Neale Ranns | 68577d2 | 2019-06-04 13:31:23 +0000 | [diff] [blame] | 1691 | } |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1692 | }, |
Neale Ranns | 68577d2 | 2019-06-04 13:31:23 +0000 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | self.vapi.set_punt(is_add=1, punt=punt_udp) |
| 1696 | |
Neale Ranns | aa7cfd0 | 2022-03-24 12:28:42 +0000 | [diff] [blame] | 1697 | af_ip6 = VppEnum.vl_api_address_family_t.ADDRESS_IP6 |
| 1698 | punt_udp = { |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1699 | "type": pt_l4, |
| 1700 | "punt": { |
| 1701 | "l4": { |
| 1702 | "af": af_ip6, |
| 1703 | "protocol": udp_proto, |
| 1704 | "port": 1236, |
Neale Ranns | aa7cfd0 | 2022-03-24 12:28:42 +0000 | [diff] [blame] | 1705 | } |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1706 | }, |
Neale Ranns | aa7cfd0 | 2022-03-24 12:28:42 +0000 | [diff] [blame] | 1707 | } |
| 1708 | |
| 1709 | self.vapi.set_punt(is_add=1, punt=punt_udp) |
| 1710 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1711 | self.pkt = ( |
| 1712 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 1713 | / IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) |
| 1714 | / UDP(sport=1234, dport=1234) |
| 1715 | / Raw(b"\xa5" * 100) |
| 1716 | ) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1717 | |
Brian Russell | 318fdb8 | 2021-01-19 16:56:32 +0000 | [diff] [blame] | 1718 | def punt_teardown(self): |
| 1719 | for i in self.pg_interfaces: |
| 1720 | i.unconfig_ip4() |
| 1721 | i.admin_down() |
| 1722 | |
| 1723 | |
| 1724 | class TestIPPunt(IPPuntSetup, VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1725 | """IPv4 Punt Police/Redirect""" |
Brian Russell | 318fdb8 | 2021-01-19 16:56:32 +0000 | [diff] [blame] | 1726 | |
| 1727 | def setUp(self): |
Klement Sekera | fd1f56a | 2021-11-22 21:25:57 +0100 | [diff] [blame] | 1728 | super().setUp() |
| 1729 | super().punt_setup() |
Brian Russell | 318fdb8 | 2021-01-19 16:56:32 +0000 | [diff] [blame] | 1730 | |
| 1731 | def tearDown(self): |
Klement Sekera | fd1f56a | 2021-11-22 21:25:57 +0100 | [diff] [blame] | 1732 | super().punt_teardown() |
| 1733 | super().tearDown() |
| 1734 | |
| 1735 | def test_ip_punt_api_validation(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1736 | """IP punt API parameter validation""" |
Klement Sekera | fd1f56a | 2021-11-22 21:25:57 +0100 | [diff] [blame] | 1737 | |
| 1738 | nh_addr = self.pg1.remote_ip4 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1739 | punt = { |
| 1740 | "rx_sw_if_index": self.pg0.sw_if_index, |
| 1741 | "af": VppEnum.vl_api_address_family_t.ADDRESS_IP4, |
| 1742 | "n_paths": 1000000, |
| 1743 | "paths": [], |
| 1744 | } |
Klement Sekera | fd1f56a | 2021-11-22 21:25:57 +0100 | [diff] [blame] | 1745 | |
| 1746 | with self.assertRaises(vpp_papi.VPPIOError): |
| 1747 | self.vapi.add_del_ip_punt_redirect_v2(punt=punt, is_add=True) |
| 1748 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1749 | punt = { |
| 1750 | "rx_sw_if_index": self.pg0.sw_if_index, |
| 1751 | "af": VppEnum.vl_api_address_family_t.ADDRESS_IP4, |
| 1752 | "n_paths": 0, |
| 1753 | "paths": [], |
| 1754 | } |
Klement Sekera | fd1f56a | 2021-11-22 21:25:57 +0100 | [diff] [blame] | 1755 | |
| 1756 | self.vapi.add_del_ip_punt_redirect_v2(punt=punt, is_add=True) |
Brian Russell | 318fdb8 | 2021-01-19 16:56:32 +0000 | [diff] [blame] | 1757 | |
| 1758 | def test_ip_punt(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1759 | """IP punt police and redirect""" |
Brian Russell | 318fdb8 | 2021-01-19 16:56:32 +0000 | [diff] [blame] | 1760 | |
| 1761 | pkts = self.pkt * 1025 |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1762 | |
| 1763 | # |
| 1764 | # Configure a punt redirect via pg1. |
| 1765 | # |
Ole Troan | 0bcad32 | 2018-12-11 13:04:01 +0100 | [diff] [blame] | 1766 | nh_addr = self.pg1.remote_ip4 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1767 | ip_punt_redirect = VppIpPuntRedirect( |
| 1768 | self, self.pg0.sw_if_index, self.pg1.sw_if_index, nh_addr |
| 1769 | ) |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 1770 | ip_punt_redirect.add_vpp_config() |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1771 | |
| 1772 | self.send_and_expect(self.pg0, pkts, self.pg1) |
| 1773 | |
| 1774 | # |
| 1775 | # add a policer |
| 1776 | # |
Jakub Grajciar | cd01fb4 | 2020-03-02 13:16:53 +0100 | [diff] [blame] | 1777 | policer = VppPolicer(self, "ip4-punt", 400, 0, 10, 0, rate_type=1) |
| 1778 | policer.add_vpp_config() |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 1779 | ip_punt_policer = VppIpPuntPolicer(self, policer.policer_index) |
| 1780 | ip_punt_policer.add_vpp_config() |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1781 | |
| 1782 | self.vapi.cli("clear trace") |
| 1783 | self.pg0.add_stream(pkts) |
| 1784 | self.pg_enable_capture(self.pg_interfaces) |
| 1785 | self.pg_start() |
| 1786 | |
| 1787 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1788 | # the number of packet received should be greater than 0, |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1789 | # but not equal to the number sent, since some were policed |
| 1790 | # |
| 1791 | rx = self.pg1._get_capture(1) |
Brian Russell | e988726 | 2021-01-27 14:45:22 +0000 | [diff] [blame] | 1792 | |
| 1793 | stats = policer.get_stats() |
| 1794 | |
| 1795 | # Single rate policer - expect conform, violate but no exceed |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1796 | self.assertGreater(stats["conform_packets"], 0) |
| 1797 | self.assertEqual(stats["exceed_packets"], 0) |
| 1798 | self.assertGreater(stats["violate_packets"], 0) |
Brian Russell | e988726 | 2021-01-27 14:45:22 +0000 | [diff] [blame] | 1799 | |
Paul Vinciguerra | 3d2df21 | 2018-11-24 23:19:53 -0800 | [diff] [blame] | 1800 | self.assertGreater(len(rx), 0) |
| 1801 | self.assertLess(len(rx), len(pkts)) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1802 | |
| 1803 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1804 | # remove the policer. back to full rx |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1805 | # |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 1806 | ip_punt_policer.remove_vpp_config() |
Jakub Grajciar | cd01fb4 | 2020-03-02 13:16:53 +0100 | [diff] [blame] | 1807 | policer.remove_vpp_config() |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1808 | self.send_and_expect(self.pg0, pkts, self.pg1) |
| 1809 | |
| 1810 | # |
| 1811 | # remove the redirect. expect full drop. |
| 1812 | # |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 1813 | ip_punt_redirect.remove_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1814 | self.send_and_assert_no_replies(self.pg0, pkts, "IP no punt config") |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1815 | |
| 1816 | # |
| 1817 | # Add a redirect that is not input port selective |
| 1818 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1819 | ip_punt_redirect = VppIpPuntRedirect( |
| 1820 | self, 0xFFFFFFFF, self.pg1.sw_if_index, nh_addr |
| 1821 | ) |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 1822 | ip_punt_redirect.add_vpp_config() |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1823 | self.send_and_expect(self.pg0, pkts, self.pg1) |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 1824 | ip_punt_redirect.remove_vpp_config() |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1825 | |
Neale Ranns | aa7cfd0 | 2022-03-24 12:28:42 +0000 | [diff] [blame] | 1826 | def test_ip_punt_vrf(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1827 | """IP punt/local with VRFs""" |
Neale Ranns | aa7cfd0 | 2022-03-24 12:28:42 +0000 | [diff] [blame] | 1828 | |
| 1829 | # use a punt redirect to test if for-us packets are accepted |
| 1830 | pkts = self.pkt * 1025 |
| 1831 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1832 | vlans_pg0 = [VppDot1QSubint(self, self.pg0, v) for v in range(100, 104)] |
| 1833 | vlans_pg1 = [VppDot1QSubint(self, self.pg1, v) for v in range(100, 104)] |
| 1834 | tbl4 = [VppIpTable(self, v).add_vpp_config() for v in range(100, 104)] |
| 1835 | tbl6 = [VppIpTable(self, v, True).add_vpp_config() for v in range(100, 104)] |
Neale Ranns | aa7cfd0 | 2022-03-24 12:28:42 +0000 | [diff] [blame] | 1836 | |
| 1837 | for v in vlans_pg0 + vlans_pg1: |
| 1838 | v.admin_up() |
| 1839 | v.set_table_ip4(v.vlan) |
| 1840 | v.set_table_ip6(v.vlan) |
| 1841 | v.config_ip4() |
| 1842 | v.config_ip6() |
| 1843 | v.resolve_arp() |
| 1844 | v.resolve_ndp() |
| 1845 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1846 | [ |
| 1847 | VppIpPuntRedirect( |
| 1848 | self, |
| 1849 | vlans_pg0[i].sw_if_index, |
| 1850 | vlans_pg1[i].sw_if_index, |
| 1851 | vlans_pg1[i].remote_ip4, |
| 1852 | ).add_vpp_config() |
| 1853 | for i in range(4) |
| 1854 | ] |
| 1855 | [ |
| 1856 | VppIpPuntRedirect( |
| 1857 | self, |
| 1858 | vlans_pg0[i].sw_if_index, |
| 1859 | vlans_pg1[i].sw_if_index, |
| 1860 | vlans_pg1[i].remote_ip6, |
| 1861 | ).add_vpp_config() |
| 1862 | for i in range(4) |
| 1863 | ] |
Neale Ranns | aa7cfd0 | 2022-03-24 12:28:42 +0000 | [diff] [blame] | 1864 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1865 | pkts = [ |
| 1866 | ( |
| 1867 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 1868 | / Dot1Q(vlan=i.vlan) |
| 1869 | / IP(src=i.remote_ip4, dst=i.local_ip4) |
| 1870 | / UDP(sport=1234, dport=1234) |
| 1871 | / Raw(b"\xa5" * 100) |
| 1872 | ) |
| 1873 | for i in vlans_pg0 |
| 1874 | ] |
Neale Ranns | aa7cfd0 | 2022-03-24 12:28:42 +0000 | [diff] [blame] | 1875 | |
| 1876 | self.send_and_expect(self.pg0, pkts, self.pg1) |
| 1877 | |
| 1878 | # |
| 1879 | # IPv4 |
| 1880 | # |
| 1881 | |
| 1882 | # we reject packets for source addresses in the wrong vlan/VRF |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1883 | pkts = [ |
| 1884 | ( |
| 1885 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 1886 | / Dot1Q(vlan=i.vlan) |
| 1887 | / IP(src="1.1.1.1", dst=i.local_ip4) |
| 1888 | / UDP(sport=1234, dport=1234) |
| 1889 | / Raw(b"\xa5" * 100) |
| 1890 | ) |
| 1891 | for i in vlans_pg0 |
| 1892 | ] |
Neale Ranns | aa7cfd0 | 2022-03-24 12:28:42 +0000 | [diff] [blame] | 1893 | # single and dual loop |
| 1894 | self.send_and_assert_no_replies(self.pg0, [pkts[0]]) |
| 1895 | self.send_and_assert_no_replies(self.pg0, pkts) |
| 1896 | |
Neale Ranns | e22a704 | 2022-08-09 03:03:29 +0000 | [diff] [blame] | 1897 | self.assert_error_counter_equal("/err/ip4-local/src_lookup_miss", len(pkts) + 1) |
Neale Ranns | aa7cfd0 | 2022-03-24 12:28:42 +0000 | [diff] [blame] | 1898 | |
| 1899 | # using the same source in different tables, should reject |
| 1900 | # for the table that the source is not present in |
| 1901 | # the first packet in the stream is drop |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1902 | pkts = [ |
| 1903 | ( |
| 1904 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 1905 | / Dot1Q(vlan=i.vlan) |
| 1906 | / IP(src=vlans_pg0[0].remote_ip4, dst=i.local_ip4) |
| 1907 | / UDP(sport=1234, dport=1234) |
| 1908 | / Raw(b"\xa5" * 100) |
| 1909 | ) |
| 1910 | for i in vlans_pg0 |
| 1911 | ] |
Neale Ranns | aa7cfd0 | 2022-03-24 12:28:42 +0000 | [diff] [blame] | 1912 | # single loop accept and drop |
| 1913 | # followed by both in the same frame/loop |
| 1914 | self.send_and_expect(self.pg0, [pkts[0]], self.pg1) |
| 1915 | self.send_and_assert_no_replies(self.pg0, [pkts[1]]) |
| 1916 | self.send_and_expect(self.pg0, pkts * 4, self.pg1, n_rx=4) |
| 1917 | |
| 1918 | # using the same source in different tables, should reject |
| 1919 | # for the table that the source is not present in |
| 1920 | # the first packet in the stream is accept |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1921 | pkts = [ |
| 1922 | ( |
| 1923 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 1924 | / Dot1Q(vlan=i.vlan) |
| 1925 | / IP(src=vlans_pg0[3].remote_ip4, dst=i.local_ip4) |
| 1926 | / UDP(sport=1234, dport=1234) |
| 1927 | / Raw(b"\xa5" * 100) |
| 1928 | ) |
| 1929 | for i in vlans_pg0 |
| 1930 | ] |
Neale Ranns | aa7cfd0 | 2022-03-24 12:28:42 +0000 | [diff] [blame] | 1931 | |
| 1932 | # single loop accept and drop |
| 1933 | # followed by both in the same frame/loop |
| 1934 | self.send_and_expect(self.pg0, [pkts[3]], self.pg1) |
| 1935 | self.send_and_assert_no_replies(self.pg0, [pkts[1]]) |
| 1936 | self.send_and_expect(self.pg0, pkts * 4, self.pg1, n_rx=4) |
| 1937 | |
| 1938 | # |
| 1939 | # IPv6 |
| 1940 | # |
| 1941 | |
| 1942 | # we reject packets for source addresses in the wrong vlan/VRF |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1943 | pkts = [ |
| 1944 | ( |
| 1945 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 1946 | / Dot1Q(vlan=i.vlan) |
| 1947 | / IPv6(src="1::1", dst=i.local_ip6) |
| 1948 | / UDP(sport=1236, dport=1236) |
| 1949 | / Raw(b"\xa5" * 100) |
| 1950 | ) |
| 1951 | for i in vlans_pg0 |
| 1952 | ] |
Neale Ranns | aa7cfd0 | 2022-03-24 12:28:42 +0000 | [diff] [blame] | 1953 | # single and dual loop |
| 1954 | self.send_and_assert_no_replies(self.pg0, [pkts[0]]) |
| 1955 | self.send_and_assert_no_replies(self.pg0, pkts) |
| 1956 | |
Neale Ranns | e22a704 | 2022-08-09 03:03:29 +0000 | [diff] [blame] | 1957 | self.assert_error_counter_equal("/err/ip6-input/src_lookup_miss", len(pkts) + 1) |
Neale Ranns | aa7cfd0 | 2022-03-24 12:28:42 +0000 | [diff] [blame] | 1958 | |
| 1959 | # using the same source in different tables, should reject |
| 1960 | # for the table that the source is not present in |
| 1961 | # the first packet in the stream is drop |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1962 | pkts = [ |
| 1963 | ( |
| 1964 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 1965 | / Dot1Q(vlan=i.vlan) |
| 1966 | / IPv6(src=vlans_pg0[0].remote_ip6, dst=i.local_ip6) |
| 1967 | / UDP(sport=1236, dport=1236) |
| 1968 | / Raw(b"\xa5" * 100) |
| 1969 | ) |
| 1970 | for i in vlans_pg0 |
| 1971 | ] |
Neale Ranns | aa7cfd0 | 2022-03-24 12:28:42 +0000 | [diff] [blame] | 1972 | # single loop accept and drop |
| 1973 | # followed by both in the same frame/loop |
| 1974 | self.send_and_expect(self.pg0, [pkts[0]], self.pg1) |
| 1975 | self.send_and_assert_no_replies(self.pg0, [pkts[1]]) |
| 1976 | self.send_and_expect(self.pg0, pkts * 4, self.pg1, n_rx=4) |
| 1977 | |
| 1978 | # using the same source in different tables, should reject |
| 1979 | # for the table that the source is not present in |
| 1980 | # the first packet in the stream is accept |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1981 | pkts = [ |
| 1982 | ( |
| 1983 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 1984 | / Dot1Q(vlan=i.vlan) |
| 1985 | / IPv6(src=vlans_pg0[3].remote_ip6, dst=i.local_ip6) |
| 1986 | / UDP(sport=1236, dport=1236) |
| 1987 | / Raw(b"\xa5" * 100) |
| 1988 | ) |
| 1989 | for i in vlans_pg0 |
| 1990 | ] |
Neale Ranns | aa7cfd0 | 2022-03-24 12:28:42 +0000 | [diff] [blame] | 1991 | |
| 1992 | # single loop accept and drop |
| 1993 | # followed by both in the same frame/loop |
| 1994 | self.send_and_expect(self.pg0, [pkts[3]], self.pg1) |
| 1995 | self.send_and_assert_no_replies(self.pg0, [pkts[1]]) |
| 1996 | self.send_and_expect(self.pg0, pkts * 4, self.pg1, n_rx=4) |
| 1997 | |
| 1998 | for v in vlans_pg0 + vlans_pg1: |
| 1999 | v.unconfig_ip4() |
| 2000 | v.unconfig_ip6() |
| 2001 | v.set_table_ip4(0) |
| 2002 | v.set_table_ip6(0) |
| 2003 | |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 2004 | def test_ip_punt_dump(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2005 | """IP4 punt redirect dump""" |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 2006 | |
| 2007 | # |
| 2008 | # Configure a punt redirects |
| 2009 | # |
Ole Troan | 0bcad32 | 2018-12-11 13:04:01 +0100 | [diff] [blame] | 2010 | nh_address = self.pg3.remote_ip4 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2011 | ipr_03 = VppIpPuntRedirect( |
| 2012 | self, self.pg0.sw_if_index, self.pg3.sw_if_index, nh_address |
| 2013 | ) |
| 2014 | ipr_13 = VppIpPuntRedirect( |
| 2015 | self, self.pg1.sw_if_index, self.pg3.sw_if_index, nh_address |
| 2016 | ) |
| 2017 | ipr_23 = VppIpPuntRedirect( |
| 2018 | self, self.pg2.sw_if_index, self.pg3.sw_if_index, "0.0.0.0" |
| 2019 | ) |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 2020 | ipr_03.add_vpp_config() |
| 2021 | ipr_13.add_vpp_config() |
| 2022 | ipr_23.add_vpp_config() |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 2023 | |
| 2024 | # |
| 2025 | # Dump pg0 punt redirects |
| 2026 | # |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 2027 | self.assertTrue(ipr_03.query_vpp_config()) |
| 2028 | self.assertTrue(ipr_13.query_vpp_config()) |
| 2029 | self.assertTrue(ipr_23.query_vpp_config()) |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 2030 | |
| 2031 | # |
| 2032 | # Dump punt redirects for all interfaces |
| 2033 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2034 | punts = self.vapi.ip_punt_redirect_dump(0xFFFFFFFF) |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 2035 | self.assertEqual(len(punts), 3) |
| 2036 | for p in punts: |
| 2037 | self.assertEqual(p.punt.tx_sw_if_index, self.pg3.sw_if_index) |
Ole Troan | 0bcad32 | 2018-12-11 13:04:01 +0100 | [diff] [blame] | 2038 | self.assertNotEqual(punts[1].punt.nh, self.pg3.remote_ip4) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2039 | self.assertEqual(str(punts[2].punt.nh), "0.0.0.0") |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 2040 | |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2041 | |
Brian Russell | c8f3cdf | 2021-01-19 16:57:42 +0000 | [diff] [blame] | 2042 | class TestIPPuntHandoff(IPPuntSetup, VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2043 | """IPv4 Punt Policer thread handoff""" |
| 2044 | |
Klement Sekera | 8d81502 | 2021-03-15 16:58:10 +0100 | [diff] [blame] | 2045 | vpp_worker_count = 2 |
Brian Russell | c8f3cdf | 2021-01-19 16:57:42 +0000 | [diff] [blame] | 2046 | |
| 2047 | def setUp(self): |
| 2048 | super(TestIPPuntHandoff, self).setUp() |
| 2049 | super(TestIPPuntHandoff, self).punt_setup() |
| 2050 | |
| 2051 | def tearDown(self): |
| 2052 | super(TestIPPuntHandoff, self).punt_teardown() |
| 2053 | super(TestIPPuntHandoff, self).tearDown() |
| 2054 | |
| 2055 | def test_ip_punt_policer_handoff(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2056 | """IP4 punt policer thread handoff""" |
Brian Russell | c8f3cdf | 2021-01-19 16:57:42 +0000 | [diff] [blame] | 2057 | pkts = self.pkt * NUM_PKTS |
| 2058 | |
| 2059 | # |
| 2060 | # Configure a punt redirect via pg1. |
| 2061 | # |
| 2062 | nh_addr = self.pg1.remote_ip4 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2063 | ip_punt_redirect = VppIpPuntRedirect( |
| 2064 | self, self.pg0.sw_if_index, self.pg1.sw_if_index, nh_addr |
| 2065 | ) |
Brian Russell | c8f3cdf | 2021-01-19 16:57:42 +0000 | [diff] [blame] | 2066 | ip_punt_redirect.add_vpp_config() |
| 2067 | |
| 2068 | action_tx = PolicerAction( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2069 | VppEnum.vl_api_sse2_qos_action_type_t.SSE2_QOS_ACTION_API_TRANSMIT, 0 |
| 2070 | ) |
Brian Russell | c8f3cdf | 2021-01-19 16:57:42 +0000 | [diff] [blame] | 2071 | # |
| 2072 | # This policer drops no packets, we are just |
| 2073 | # testing that they get to the right thread. |
| 2074 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2075 | policer = VppPolicer( |
| 2076 | self, |
| 2077 | "ip4-punt", |
| 2078 | 400, |
| 2079 | 0, |
| 2080 | 10, |
| 2081 | 0, |
| 2082 | 1, |
| 2083 | 0, |
| 2084 | 0, |
| 2085 | False, |
| 2086 | action_tx, |
| 2087 | action_tx, |
| 2088 | action_tx, |
| 2089 | ) |
Brian Russell | c8f3cdf | 2021-01-19 16:57:42 +0000 | [diff] [blame] | 2090 | policer.add_vpp_config() |
| 2091 | ip_punt_policer = VppIpPuntPolicer(self, policer.policer_index) |
| 2092 | ip_punt_policer.add_vpp_config() |
| 2093 | |
| 2094 | for worker in [0, 1]: |
| 2095 | self.send_and_expect(self.pg0, pkts, self.pg1, worker=worker) |
Brian Russell | bb98314 | 2021-02-10 13:56:06 +0000 | [diff] [blame] | 2096 | self.logger.debug(self.vapi.cli("show trace max 100")) |
Brian Russell | c8f3cdf | 2021-01-19 16:57:42 +0000 | [diff] [blame] | 2097 | |
Brian Russell | e988726 | 2021-01-27 14:45:22 +0000 | [diff] [blame] | 2098 | # Combined stats, all threads |
| 2099 | stats = policer.get_stats() |
| 2100 | |
| 2101 | # Single rate policer - expect conform, violate but no exceed |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2102 | self.assertGreater(stats["conform_packets"], 0) |
| 2103 | self.assertEqual(stats["exceed_packets"], 0) |
| 2104 | self.assertGreater(stats["violate_packets"], 0) |
Brian Russell | e988726 | 2021-01-27 14:45:22 +0000 | [diff] [blame] | 2105 | |
| 2106 | # Worker 0, should have done all the policing |
| 2107 | stats0 = policer.get_stats(worker=0) |
| 2108 | self.assertEqual(stats, stats0) |
| 2109 | |
| 2110 | # Worker 1, should have handed everything off |
| 2111 | stats1 = policer.get_stats(worker=1) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2112 | self.assertEqual(stats1["conform_packets"], 0) |
| 2113 | self.assertEqual(stats1["exceed_packets"], 0) |
| 2114 | self.assertEqual(stats1["violate_packets"], 0) |
Brian Russell | e988726 | 2021-01-27 14:45:22 +0000 | [diff] [blame] | 2115 | |
Brian Russell | bb98314 | 2021-02-10 13:56:06 +0000 | [diff] [blame] | 2116 | # Bind the policer to worker 1 and repeat |
| 2117 | policer.bind_vpp_config(1, True) |
| 2118 | for worker in [0, 1]: |
| 2119 | self.send_and_expect(self.pg0, pkts, self.pg1, worker=worker) |
| 2120 | self.logger.debug(self.vapi.cli("show trace max 100")) |
| 2121 | |
| 2122 | # The 2 workers should now have policed the same amount |
| 2123 | stats = policer.get_stats() |
| 2124 | stats0 = policer.get_stats(worker=0) |
| 2125 | stats1 = policer.get_stats(worker=1) |
| 2126 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2127 | self.assertGreater(stats0["conform_packets"], 0) |
| 2128 | self.assertEqual(stats0["exceed_packets"], 0) |
| 2129 | self.assertGreater(stats0["violate_packets"], 0) |
Brian Russell | bb98314 | 2021-02-10 13:56:06 +0000 | [diff] [blame] | 2130 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2131 | self.assertGreater(stats1["conform_packets"], 0) |
| 2132 | self.assertEqual(stats1["exceed_packets"], 0) |
| 2133 | self.assertGreater(stats1["violate_packets"], 0) |
Brian Russell | bb98314 | 2021-02-10 13:56:06 +0000 | [diff] [blame] | 2134 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2135 | self.assertEqual( |
| 2136 | stats0["conform_packets"] + stats1["conform_packets"], |
| 2137 | stats["conform_packets"], |
| 2138 | ) |
Brian Russell | bb98314 | 2021-02-10 13:56:06 +0000 | [diff] [blame] | 2139 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2140 | self.assertEqual( |
| 2141 | stats0["violate_packets"] + stats1["violate_packets"], |
| 2142 | stats["violate_packets"], |
| 2143 | ) |
Brian Russell | bb98314 | 2021-02-10 13:56:06 +0000 | [diff] [blame] | 2144 | |
| 2145 | # Unbind the policer and repeat |
| 2146 | policer.bind_vpp_config(1, False) |
| 2147 | for worker in [0, 1]: |
| 2148 | self.send_and_expect(self.pg0, pkts, self.pg1, worker=worker) |
| 2149 | self.logger.debug(self.vapi.cli("show trace max 100")) |
| 2150 | |
| 2151 | # The policer should auto-bind to worker 0 when packets arrive |
| 2152 | stats = policer.get_stats() |
| 2153 | stats0new = policer.get_stats(worker=0) |
| 2154 | stats1new = policer.get_stats(worker=1) |
| 2155 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2156 | self.assertGreater(stats0new["conform_packets"], stats0["conform_packets"]) |
| 2157 | self.assertEqual(stats0new["exceed_packets"], 0) |
| 2158 | self.assertGreater(stats0new["violate_packets"], stats0["violate_packets"]) |
Brian Russell | bb98314 | 2021-02-10 13:56:06 +0000 | [diff] [blame] | 2159 | |
| 2160 | self.assertEqual(stats1, stats1new) |
| 2161 | |
Brian Russell | c8f3cdf | 2021-01-19 16:57:42 +0000 | [diff] [blame] | 2162 | # |
| 2163 | # Clean up |
| 2164 | # |
| 2165 | ip_punt_policer.remove_vpp_config() |
| 2166 | policer.remove_vpp_config() |
| 2167 | ip_punt_redirect.remove_vpp_config() |
| 2168 | |
| 2169 | |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 2170 | class TestIPDeag(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2171 | """IPv4 Deaggregate Routes""" |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 2172 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 2173 | @classmethod |
| 2174 | def setUpClass(cls): |
| 2175 | super(TestIPDeag, cls).setUpClass() |
| 2176 | |
| 2177 | @classmethod |
| 2178 | def tearDownClass(cls): |
| 2179 | super(TestIPDeag, cls).tearDownClass() |
| 2180 | |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 2181 | def setUp(self): |
| 2182 | super(TestIPDeag, self).setUp() |
| 2183 | |
| 2184 | self.create_pg_interfaces(range(3)) |
| 2185 | |
| 2186 | for i in self.pg_interfaces: |
| 2187 | i.admin_up() |
| 2188 | i.config_ip4() |
| 2189 | i.resolve_arp() |
| 2190 | |
| 2191 | def tearDown(self): |
| 2192 | super(TestIPDeag, self).tearDown() |
| 2193 | for i in self.pg_interfaces: |
| 2194 | i.unconfig_ip4() |
| 2195 | i.admin_down() |
| 2196 | |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 2197 | def test_ip_deag(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2198 | """IP Deag Routes""" |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 2199 | |
| 2200 | # |
| 2201 | # Create a table to be used for: |
| 2202 | # 1 - another destination address lookup |
| 2203 | # 2 - a source address lookup |
| 2204 | # |
| 2205 | table_dst = VppIpTable(self, 1) |
| 2206 | table_src = VppIpTable(self, 2) |
| 2207 | table_dst.add_vpp_config() |
| 2208 | table_src.add_vpp_config() |
| 2209 | |
| 2210 | # |
| 2211 | # Add a route in the default table to point to a deag/ |
| 2212 | # second lookup in each of these tables |
| 2213 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2214 | route_to_dst = VppIpRoute( |
| 2215 | self, "1.1.1.1", 32, [VppRoutePath("0.0.0.0", 0xFFFFFFFF, nh_table_id=1)] |
| 2216 | ) |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2217 | route_to_src = VppIpRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2218 | self, |
| 2219 | "1.1.1.2", |
| 2220 | 32, |
| 2221 | [ |
| 2222 | VppRoutePath( |
| 2223 | "0.0.0.0", |
| 2224 | 0xFFFFFFFF, |
| 2225 | nh_table_id=2, |
| 2226 | type=FibPathType.FIB_PATH_TYPE_SOURCE_LOOKUP, |
| 2227 | ) |
| 2228 | ], |
| 2229 | ) |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 2230 | route_to_dst.add_vpp_config() |
| 2231 | route_to_src.add_vpp_config() |
| 2232 | |
| 2233 | # |
| 2234 | # packets to these destination are dropped, since they'll |
| 2235 | # hit the respective default routes in the second table |
| 2236 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2237 | p_dst = ( |
| 2238 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2239 | / IP(src="5.5.5.5", dst="1.1.1.1") |
| 2240 | / TCP(sport=1234, dport=1234) |
| 2241 | / Raw(b"\xa5" * 100) |
| 2242 | ) |
| 2243 | p_src = ( |
| 2244 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2245 | / IP(src="2.2.2.2", dst="1.1.1.2") |
| 2246 | / TCP(sport=1234, dport=1234) |
| 2247 | / Raw(b"\xa5" * 100) |
| 2248 | ) |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 2249 | pkts_dst = p_dst * 257 |
| 2250 | pkts_src = p_src * 257 |
| 2251 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2252 | self.send_and_assert_no_replies(self.pg0, pkts_dst, "IP in dst table") |
| 2253 | self.send_and_assert_no_replies(self.pg0, pkts_src, "IP in src table") |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 2254 | |
| 2255 | # |
| 2256 | # add a route in the dst table to forward via pg1 |
| 2257 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2258 | route_in_dst = VppIpRoute( |
| 2259 | self, |
| 2260 | "1.1.1.1", |
| 2261 | 32, |
| 2262 | [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index)], |
| 2263 | table_id=1, |
| 2264 | ) |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 2265 | route_in_dst.add_vpp_config() |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2266 | |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 2267 | self.send_and_expect(self.pg0, pkts_dst, self.pg1) |
| 2268 | |
| 2269 | # |
| 2270 | # add a route in the src table to forward via pg2 |
| 2271 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2272 | route_in_src = VppIpRoute( |
| 2273 | self, |
| 2274 | "2.2.2.2", |
| 2275 | 32, |
| 2276 | [VppRoutePath(self.pg2.remote_ip4, self.pg2.sw_if_index)], |
| 2277 | table_id=2, |
| 2278 | ) |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 2279 | route_in_src.add_vpp_config() |
| 2280 | self.send_and_expect(self.pg0, pkts_src, self.pg2) |
| 2281 | |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2282 | # |
| 2283 | # loop in the lookup DP |
| 2284 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2285 | route_loop = VppIpRoute( |
| 2286 | self, "2.2.2.3", 32, [VppRoutePath("0.0.0.0", 0xFFFFFFFF, nh_table_id=0)] |
| 2287 | ) |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2288 | route_loop.add_vpp_config() |
| 2289 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2290 | p_l = ( |
| 2291 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2292 | / IP(src="2.2.2.4", dst="2.2.2.3") |
| 2293 | / TCP(sport=1234, dport=1234) |
| 2294 | / Raw(b"\xa5" * 100) |
| 2295 | ) |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2296 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2297 | self.send_and_assert_no_replies(self.pg0, p_l * 257, "IP lookup loop") |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2298 | |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 2299 | |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2300 | class TestIPInput(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2301 | """IPv4 Input Exceptions""" |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2302 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 2303 | @classmethod |
| 2304 | def setUpClass(cls): |
| 2305 | super(TestIPInput, cls).setUpClass() |
| 2306 | |
| 2307 | @classmethod |
| 2308 | def tearDownClass(cls): |
| 2309 | super(TestIPInput, cls).tearDownClass() |
| 2310 | |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2311 | def setUp(self): |
| 2312 | super(TestIPInput, self).setUp() |
| 2313 | |
| 2314 | self.create_pg_interfaces(range(2)) |
| 2315 | |
| 2316 | for i in self.pg_interfaces: |
| 2317 | i.admin_up() |
| 2318 | i.config_ip4() |
| 2319 | i.resolve_arp() |
| 2320 | |
| 2321 | def tearDown(self): |
| 2322 | super(TestIPInput, self).tearDown() |
| 2323 | for i in self.pg_interfaces: |
| 2324 | i.unconfig_ip4() |
| 2325 | i.admin_down() |
| 2326 | |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2327 | def test_ip_input(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2328 | """IP Input Exceptions""" |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2329 | |
| 2330 | # i can't find a way in scapy to construct an IP packet |
| 2331 | # with a length less than the IP header length |
| 2332 | |
| 2333 | # |
| 2334 | # Packet too short - this is forwarded |
| 2335 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2336 | p_short = ( |
| 2337 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2338 | / IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4, len=40) |
| 2339 | / UDP(sport=1234, dport=1234) |
| 2340 | / Raw(b"\xa5" * 100) |
| 2341 | ) |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2342 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 2343 | rx = self.send_and_expect(self.pg0, p_short * NUM_PKTS, self.pg1) |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2344 | |
| 2345 | # |
| 2346 | # Packet too long - this is dropped |
| 2347 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2348 | p_long = ( |
| 2349 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2350 | / IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4, len=400) |
| 2351 | / UDP(sport=1234, dport=1234) |
| 2352 | / Raw(b"\xa5" * 100) |
| 2353 | ) |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2354 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2355 | rx = self.send_and_assert_no_replies(self.pg0, p_long * NUM_PKTS, "too long") |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2356 | |
| 2357 | # |
| 2358 | # bad chksum - this is dropped |
| 2359 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2360 | p_chksum = ( |
| 2361 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2362 | / IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4, chksum=400) |
| 2363 | / UDP(sport=1234, dport=1234) |
| 2364 | / Raw(b"\xa5" * 100) |
| 2365 | ) |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2366 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2367 | rx = self.send_and_assert_no_replies( |
| 2368 | self.pg0, p_chksum * NUM_PKTS, "bad checksum" |
| 2369 | ) |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2370 | |
| 2371 | # |
| 2372 | # bad version - this is dropped |
| 2373 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2374 | p_ver = ( |
| 2375 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2376 | / IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4, version=3) |
| 2377 | / UDP(sport=1234, dport=1234) |
| 2378 | / Raw(b"\xa5" * 100) |
| 2379 | ) |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2380 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2381 | rx = self.send_and_assert_no_replies( |
| 2382 | self.pg0, p_ver * NUM_PKTS, "funky version" |
| 2383 | ) |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2384 | |
| 2385 | # |
| 2386 | # fragment offset 1 - this is dropped |
| 2387 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2388 | p_frag = ( |
| 2389 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2390 | / IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4, frag=1) |
| 2391 | / UDP(sport=1234, dport=1234) |
| 2392 | / Raw(b"\xa5" * 100) |
| 2393 | ) |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2394 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2395 | rx = self.send_and_assert_no_replies(self.pg0, p_frag * NUM_PKTS, "frag offset") |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2396 | |
| 2397 | # |
| 2398 | # TTL expired packet |
| 2399 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2400 | p_ttl = ( |
| 2401 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2402 | / IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4, ttl=1) |
| 2403 | / UDP(sport=1234, dport=1234) |
| 2404 | / Raw(b"\xa5" * 100) |
| 2405 | ) |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2406 | |
Neale Ranns | 5c6dd17 | 2022-02-17 09:08:47 +0000 | [diff] [blame] | 2407 | rxs = self.send_and_expect_some(self.pg0, p_ttl * NUM_PKTS, self.pg0) |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2408 | |
Neale Ranns | 5c6dd17 | 2022-02-17 09:08:47 +0000 | [diff] [blame] | 2409 | for rx in rxs: |
| 2410 | icmp = rx[ICMP] |
| 2411 | self.assertEqual(icmptypes[icmp.type], "time-exceeded") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2412 | self.assertEqual(icmpcodes[icmp.type][icmp.code], "ttl-zero-during-transit") |
Neale Ranns | 5c6dd17 | 2022-02-17 09:08:47 +0000 | [diff] [blame] | 2413 | self.assertEqual(icmp.src, self.pg0.remote_ip4) |
| 2414 | self.assertEqual(icmp.dst, self.pg1.remote_ip4) |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2415 | |
Neale Ranns | ffd78d1 | 2018-02-09 06:05:16 -0800 | [diff] [blame] | 2416 | # |
| 2417 | # MTU exceeded |
| 2418 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2419 | p_mtu = ( |
| 2420 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2421 | / IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4, ttl=10, flags="DF") |
| 2422 | / UDP(sport=1234, dport=1234) |
| 2423 | / Raw(b"\xa5" * 2000) |
| 2424 | ) |
Neale Ranns | ffd78d1 | 2018-02-09 06:05:16 -0800 | [diff] [blame] | 2425 | |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 2426 | self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [1500, 0, 0, 0]) |
Neale Ranns | ffd78d1 | 2018-02-09 06:05:16 -0800 | [diff] [blame] | 2427 | |
Neale Ranns | 5c6dd17 | 2022-02-17 09:08:47 +0000 | [diff] [blame] | 2428 | rxs = self.send_and_expect_some(self.pg0, p_mtu * NUM_PKTS, self.pg0) |
Neale Ranns | ffd78d1 | 2018-02-09 06:05:16 -0800 | [diff] [blame] | 2429 | |
Neale Ranns | 5c6dd17 | 2022-02-17 09:08:47 +0000 | [diff] [blame] | 2430 | for rx in rxs: |
| 2431 | icmp = rx[ICMP] |
| 2432 | self.assertEqual(icmptypes[icmp.type], "dest-unreach") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2433 | self.assertEqual(icmpcodes[icmp.type][icmp.code], "fragmentation-needed") |
Neale Ranns | fbc633f | 2022-03-18 13:05:09 +0000 | [diff] [blame] | 2434 | self.assertEqual(icmp.nexthopmtu, 1500) |
Neale Ranns | 5c6dd17 | 2022-02-17 09:08:47 +0000 | [diff] [blame] | 2435 | self.assertEqual(icmp.src, self.pg0.remote_ip4) |
| 2436 | self.assertEqual(icmp.dst, self.pg1.remote_ip4) |
Neale Ranns | ffd78d1 | 2018-02-09 06:05:16 -0800 | [diff] [blame] | 2437 | |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 2438 | self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [2500, 0, 0, 0]) |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 2439 | rx = self.send_and_expect(self.pg0, p_mtu * NUM_PKTS, self.pg1) |
Neale Ranns | ffd78d1 | 2018-02-09 06:05:16 -0800 | [diff] [blame] | 2440 | |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 2441 | # Reset MTU for subsequent tests |
| 2442 | self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [9000, 0, 0, 0]) |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2443 | |
Neale Ranns | be2286b | 2018-12-09 12:54:51 -0800 | [diff] [blame] | 2444 | # |
| 2445 | # source address 0.0.0.0 and 25.255.255.255 and for-us |
| 2446 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2447 | p_s0 = ( |
| 2448 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2449 | / IP(src="0.0.0.0", dst=self.pg0.local_ip4) |
| 2450 | / ICMP(id=4, seq=4) |
| 2451 | / Raw(load=b"\x0a" * 18) |
| 2452 | ) |
Neale Ranns | be2286b | 2018-12-09 12:54:51 -0800 | [diff] [blame] | 2453 | rx = self.send_and_assert_no_replies(self.pg0, p_s0 * 17) |
| 2454 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2455 | p_s0 = ( |
| 2456 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2457 | / IP(src="255.255.255.255", dst=self.pg0.local_ip4) |
| 2458 | / ICMP(id=4, seq=4) |
| 2459 | / Raw(load=b"\x0a" * 18) |
| 2460 | ) |
Neale Ranns | be2286b | 2018-12-09 12:54:51 -0800 | [diff] [blame] | 2461 | rx = self.send_and_assert_no_replies(self.pg0, p_s0 * 17) |
| 2462 | |
Neale Ranns | 1855b8e | 2018-07-11 10:31:26 -0700 | [diff] [blame] | 2463 | |
| 2464 | class TestIPDirectedBroadcast(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2465 | """IPv4 Directed Broadcast""" |
Neale Ranns | 1855b8e | 2018-07-11 10:31:26 -0700 | [diff] [blame] | 2466 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 2467 | @classmethod |
| 2468 | def setUpClass(cls): |
| 2469 | super(TestIPDirectedBroadcast, cls).setUpClass() |
| 2470 | |
| 2471 | @classmethod |
| 2472 | def tearDownClass(cls): |
| 2473 | super(TestIPDirectedBroadcast, cls).tearDownClass() |
| 2474 | |
Neale Ranns | 1855b8e | 2018-07-11 10:31:26 -0700 | [diff] [blame] | 2475 | def setUp(self): |
| 2476 | super(TestIPDirectedBroadcast, self).setUp() |
| 2477 | |
| 2478 | self.create_pg_interfaces(range(2)) |
| 2479 | |
| 2480 | for i in self.pg_interfaces: |
| 2481 | i.admin_up() |
| 2482 | |
| 2483 | def tearDown(self): |
| 2484 | super(TestIPDirectedBroadcast, self).tearDown() |
| 2485 | for i in self.pg_interfaces: |
| 2486 | i.admin_down() |
| 2487 | |
| 2488 | def test_ip_input(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2489 | """IP Directed Broadcast""" |
Neale Ranns | 1855b8e | 2018-07-11 10:31:26 -0700 | [diff] [blame] | 2490 | |
| 2491 | # |
| 2492 | # set the directed broadcast on pg0 first, then config IP4 addresses |
| 2493 | # for pg1 directed broadcast is always disabled |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2494 | self.vapi.sw_interface_set_ip_directed_broadcast(self.pg0.sw_if_index, 1) |
Neale Ranns | 1855b8e | 2018-07-11 10:31:26 -0700 | [diff] [blame] | 2495 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2496 | p0 = ( |
| 2497 | Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac) |
| 2498 | / IP(src="1.1.1.1", dst=self.pg0._local_ip4_bcast) |
| 2499 | / UDP(sport=1234, dport=1234) |
| 2500 | / Raw(b"\xa5" * 2000) |
| 2501 | ) |
| 2502 | p1 = ( |
| 2503 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2504 | / IP(src="1.1.1.1", dst=self.pg1._local_ip4_bcast) |
| 2505 | / UDP(sport=1234, dport=1234) |
| 2506 | / Raw(b"\xa5" * 2000) |
| 2507 | ) |
Neale Ranns | 1855b8e | 2018-07-11 10:31:26 -0700 | [diff] [blame] | 2508 | |
| 2509 | self.pg0.config_ip4() |
| 2510 | self.pg0.resolve_arp() |
| 2511 | self.pg1.config_ip4() |
| 2512 | self.pg1.resolve_arp() |
| 2513 | |
| 2514 | # |
| 2515 | # test packet is L2 broadcast |
| 2516 | # |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 2517 | rx = self.send_and_expect(self.pg1, p0 * NUM_PKTS, self.pg0) |
Neale Ranns | 1855b8e | 2018-07-11 10:31:26 -0700 | [diff] [blame] | 2518 | self.assertTrue(rx[0][Ether].dst, "ff:ff:ff:ff:ff:ff") |
| 2519 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2520 | self.send_and_assert_no_replies( |
| 2521 | self.pg0, p1 * NUM_PKTS, "directed broadcast disabled" |
| 2522 | ) |
Neale Ranns | 1855b8e | 2018-07-11 10:31:26 -0700 | [diff] [blame] | 2523 | |
| 2524 | # |
| 2525 | # toggle directed broadcast on pg0 |
| 2526 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2527 | self.vapi.sw_interface_set_ip_directed_broadcast(self.pg0.sw_if_index, 0) |
| 2528 | self.send_and_assert_no_replies( |
| 2529 | self.pg1, p0 * NUM_PKTS, "directed broadcast disabled" |
| 2530 | ) |
Neale Ranns | 1855b8e | 2018-07-11 10:31:26 -0700 | [diff] [blame] | 2531 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2532 | self.vapi.sw_interface_set_ip_directed_broadcast(self.pg0.sw_if_index, 1) |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 2533 | rx = self.send_and_expect(self.pg1, p0 * NUM_PKTS, self.pg0) |
Neale Ranns | 1855b8e | 2018-07-11 10:31:26 -0700 | [diff] [blame] | 2534 | |
| 2535 | self.pg0.unconfig_ip4() |
| 2536 | self.pg1.unconfig_ip4() |
| 2537 | |
| 2538 | |
mu.duojiao | 59a8295 | 2018-10-11 14:27:30 +0800 | [diff] [blame] | 2539 | class TestIPLPM(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2540 | """IPv4 longest Prefix Match""" |
mu.duojiao | 59a8295 | 2018-10-11 14:27:30 +0800 | [diff] [blame] | 2541 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 2542 | @classmethod |
| 2543 | def setUpClass(cls): |
| 2544 | super(TestIPLPM, cls).setUpClass() |
| 2545 | |
| 2546 | @classmethod |
| 2547 | def tearDownClass(cls): |
| 2548 | super(TestIPLPM, cls).tearDownClass() |
| 2549 | |
mu.duojiao | 59a8295 | 2018-10-11 14:27:30 +0800 | [diff] [blame] | 2550 | def setUp(self): |
| 2551 | super(TestIPLPM, self).setUp() |
| 2552 | |
| 2553 | self.create_pg_interfaces(range(4)) |
| 2554 | |
| 2555 | for i in self.pg_interfaces: |
| 2556 | i.admin_up() |
| 2557 | i.config_ip4() |
| 2558 | i.resolve_arp() |
| 2559 | |
| 2560 | def tearDown(self): |
| 2561 | super(TestIPLPM, self).tearDown() |
| 2562 | for i in self.pg_interfaces: |
| 2563 | i.admin_down() |
| 2564 | i.unconfig_ip4() |
| 2565 | |
| 2566 | def test_ip_lpm(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2567 | """IP longest Prefix Match""" |
mu.duojiao | 59a8295 | 2018-10-11 14:27:30 +0800 | [diff] [blame] | 2568 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2569 | s_24 = VppIpRoute( |
| 2570 | self, |
| 2571 | "10.1.2.0", |
| 2572 | 24, |
| 2573 | [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index)], |
| 2574 | ) |
mu.duojiao | 59a8295 | 2018-10-11 14:27:30 +0800 | [diff] [blame] | 2575 | s_24.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2576 | s_8 = VppIpRoute( |
| 2577 | self, |
| 2578 | "10.0.0.0", |
| 2579 | 8, |
| 2580 | [VppRoutePath(self.pg2.remote_ip4, self.pg2.sw_if_index)], |
| 2581 | ) |
mu.duojiao | 59a8295 | 2018-10-11 14:27:30 +0800 | [diff] [blame] | 2582 | s_8.add_vpp_config() |
| 2583 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2584 | p_8 = ( |
| 2585 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2586 | / IP(src="1.1.1.1", dst="10.1.1.1") |
| 2587 | / UDP(sport=1234, dport=1234) |
| 2588 | / Raw(b"\xa5" * 2000) |
| 2589 | ) |
| 2590 | p_24 = ( |
| 2591 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2592 | / IP(src="1.1.1.1", dst="10.1.2.1") |
| 2593 | / UDP(sport=1234, dport=1234) |
| 2594 | / Raw(b"\xa5" * 2000) |
| 2595 | ) |
mu.duojiao | 59a8295 | 2018-10-11 14:27:30 +0800 | [diff] [blame] | 2596 | |
| 2597 | self.logger.info(self.vapi.cli("sh ip fib mtrie")) |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 2598 | rx = self.send_and_expect(self.pg0, p_8 * NUM_PKTS, self.pg2) |
| 2599 | rx = self.send_and_expect(self.pg0, p_24 * NUM_PKTS, self.pg1) |
mu.duojiao | 59a8295 | 2018-10-11 14:27:30 +0800 | [diff] [blame] | 2600 | |
| 2601 | |
Andrew Yourtchenko | 8dc0d48 | 2021-01-29 13:17:19 +0000 | [diff] [blame] | 2602 | @tag_fixme_vpp_workers |
Juraj Sloboda | 68b7cb8 | 2018-10-16 12:18:21 +0200 | [diff] [blame] | 2603 | class TestIPv4Frag(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2604 | """IPv4 fragmentation""" |
Juraj Sloboda | 68b7cb8 | 2018-10-16 12:18:21 +0200 | [diff] [blame] | 2605 | |
| 2606 | @classmethod |
| 2607 | def setUpClass(cls): |
| 2608 | super(TestIPv4Frag, cls).setUpClass() |
| 2609 | |
| 2610 | cls.create_pg_interfaces([0, 1]) |
| 2611 | cls.src_if = cls.pg0 |
| 2612 | cls.dst_if = cls.pg1 |
| 2613 | |
| 2614 | # setup all interfaces |
| 2615 | for i in cls.pg_interfaces: |
| 2616 | i.admin_up() |
| 2617 | i.config_ip4() |
| 2618 | i.resolve_arp() |
| 2619 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 2620 | @classmethod |
| 2621 | def tearDownClass(cls): |
| 2622 | super(TestIPv4Frag, cls).tearDownClass() |
| 2623 | |
Juraj Sloboda | 68b7cb8 | 2018-10-16 12:18:21 +0200 | [diff] [blame] | 2624 | def test_frag_large_packets(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2625 | """Fragmentation of large packets""" |
Juraj Sloboda | 68b7cb8 | 2018-10-16 12:18:21 +0200 | [diff] [blame] | 2626 | |
Neale Ranns | 0b6a857 | 2019-10-30 17:34:14 +0000 | [diff] [blame] | 2627 | self.vapi.cli("adjacency counters enable") |
| 2628 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2629 | p = ( |
| 2630 | Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac) |
| 2631 | / IP(src=self.src_if.remote_ip4, dst=self.dst_if.remote_ip4) |
| 2632 | / UDP(sport=1234, dport=5678) |
| 2633 | / Raw() |
| 2634 | ) |
Juraj Sloboda | 68b7cb8 | 2018-10-16 12:18:21 +0200 | [diff] [blame] | 2635 | self.extend_packet(p, 6000, "abcde") |
| 2636 | saved_payload = p[Raw].load |
| 2637 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2638 | nbr = VppNeighbor( |
| 2639 | self, |
| 2640 | self.dst_if.sw_if_index, |
| 2641 | self.dst_if.remote_mac, |
| 2642 | self.dst_if.remote_ip4, |
| 2643 | ).add_vpp_config() |
Neale Ranns | 0b6a857 | 2019-10-30 17:34:14 +0000 | [diff] [blame] | 2644 | |
Juraj Sloboda | 68b7cb8 | 2018-10-16 12:18:21 +0200 | [diff] [blame] | 2645 | # Force fragmentation by setting MTU of output interface |
| 2646 | # lower than packet size |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2647 | self.vapi.sw_interface_set_mtu(self.dst_if.sw_if_index, [5000, 0, 0, 0]) |
Juraj Sloboda | 68b7cb8 | 2018-10-16 12:18:21 +0200 | [diff] [blame] | 2648 | |
| 2649 | self.pg_enable_capture() |
| 2650 | self.src_if.add_stream(p) |
| 2651 | self.pg_start() |
| 2652 | |
| 2653 | # Expecting 3 fragments because size of created fragments currently |
| 2654 | # cannot be larger then VPP buffer size (which is 2048) |
| 2655 | packets = self.dst_if.get_capture(3) |
| 2656 | |
Neale Ranns | 0b6a857 | 2019-10-30 17:34:14 +0000 | [diff] [blame] | 2657 | # we should show 3 packets thru the neighbor |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2658 | self.assertEqual(3, nbr.get_stats()["packets"]) |
Neale Ranns | 0b6a857 | 2019-10-30 17:34:14 +0000 | [diff] [blame] | 2659 | |
Juraj Sloboda | 68b7cb8 | 2018-10-16 12:18:21 +0200 | [diff] [blame] | 2660 | # Assume VPP sends the fragments in order |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2661 | payload = b"" |
Juraj Sloboda | 68b7cb8 | 2018-10-16 12:18:21 +0200 | [diff] [blame] | 2662 | for p in packets: |
| 2663 | payload_offset = p.frag * 8 |
| 2664 | if payload_offset > 0: |
| 2665 | payload_offset -= 8 # UDP header is not in payload |
| 2666 | self.assert_equal(payload_offset, len(payload)) |
| 2667 | payload += p[Raw].load |
| 2668 | self.assert_equal(payload, saved_payload, "payload") |
| 2669 | |
| 2670 | |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 2671 | class TestIPReplace(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2672 | """IPv4 Table Replace""" |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 2673 | |
| 2674 | @classmethod |
| 2675 | def setUpClass(cls): |
| 2676 | super(TestIPReplace, cls).setUpClass() |
| 2677 | |
| 2678 | @classmethod |
| 2679 | def tearDownClass(cls): |
| 2680 | super(TestIPReplace, cls).tearDownClass() |
| 2681 | |
| 2682 | def setUp(self): |
| 2683 | super(TestIPReplace, self).setUp() |
| 2684 | |
| 2685 | self.create_pg_interfaces(range(4)) |
| 2686 | |
| 2687 | table_id = 1 |
| 2688 | self.tables = [] |
| 2689 | |
| 2690 | for i in self.pg_interfaces: |
| 2691 | i.admin_up() |
| 2692 | i.config_ip4() |
| 2693 | i.resolve_arp() |
| 2694 | i.generate_remote_hosts(2) |
| 2695 | self.tables.append(VppIpTable(self, table_id).add_vpp_config()) |
| 2696 | table_id += 1 |
| 2697 | |
| 2698 | def tearDown(self): |
| 2699 | super(TestIPReplace, self).tearDown() |
| 2700 | for i in self.pg_interfaces: |
| 2701 | i.admin_down() |
| 2702 | i.unconfig_ip4() |
| 2703 | |
| 2704 | def test_replace(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2705 | """IP Table Replace""" |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 2706 | |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 2707 | MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t |
| 2708 | MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 2709 | N_ROUTES = 20 |
| 2710 | links = [self.pg0, self.pg1, self.pg2, self.pg3] |
| 2711 | routes = [[], [], [], []] |
| 2712 | |
| 2713 | # load up the tables with some routes |
| 2714 | for ii, t in enumerate(self.tables): |
| 2715 | for jj in range(N_ROUTES): |
| 2716 | uni = VppIpRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2717 | self, |
| 2718 | "10.0.0.%d" % jj, |
| 2719 | 32, |
| 2720 | [ |
| 2721 | VppRoutePath( |
| 2722 | links[ii].remote_hosts[0].ip4, links[ii].sw_if_index |
| 2723 | ), |
| 2724 | VppRoutePath( |
| 2725 | links[ii].remote_hosts[1].ip4, links[ii].sw_if_index |
| 2726 | ), |
| 2727 | ], |
| 2728 | table_id=t.table_id, |
| 2729 | ).add_vpp_config() |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 2730 | multi = VppIpMRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2731 | self, |
| 2732 | "0.0.0.0", |
| 2733 | "239.0.0.%d" % jj, |
| 2734 | 32, |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 2735 | MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2736 | [ |
| 2737 | VppMRoutePath( |
| 2738 | self.pg0.sw_if_index, |
| 2739 | MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT, |
| 2740 | ), |
| 2741 | VppMRoutePath( |
| 2742 | self.pg1.sw_if_index, |
| 2743 | MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD, |
| 2744 | ), |
| 2745 | VppMRoutePath( |
| 2746 | self.pg2.sw_if_index, |
| 2747 | MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD, |
| 2748 | ), |
| 2749 | VppMRoutePath( |
| 2750 | self.pg3.sw_if_index, |
| 2751 | MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD, |
| 2752 | ), |
| 2753 | ], |
| 2754 | table_id=t.table_id, |
| 2755 | ).add_vpp_config() |
| 2756 | routes[ii].append({"uni": uni, "multi": multi}) |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 2757 | |
| 2758 | # |
| 2759 | # replace the tables a few times |
| 2760 | # |
| 2761 | for kk in range(3): |
| 2762 | # replace_begin each table |
| 2763 | for t in self.tables: |
| 2764 | t.replace_begin() |
| 2765 | |
| 2766 | # all the routes are still there |
| 2767 | for ii, t in enumerate(self.tables): |
| 2768 | dump = t.dump() |
| 2769 | mdump = t.mdump() |
| 2770 | for r in routes[ii]: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2771 | self.assertTrue(find_route_in_dump(dump, r["uni"], t)) |
| 2772 | self.assertTrue(find_mroute_in_dump(mdump, r["multi"], t)) |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 2773 | |
| 2774 | # redownload the even numbered routes |
| 2775 | for ii, t in enumerate(self.tables): |
| 2776 | for jj in range(0, N_ROUTES, 2): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2777 | routes[ii][jj]["uni"].add_vpp_config() |
| 2778 | routes[ii][jj]["multi"].add_vpp_config() |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 2779 | |
| 2780 | # signal each table replace_end |
| 2781 | for t in self.tables: |
| 2782 | t.replace_end() |
| 2783 | |
| 2784 | # we should find the even routes, but not the odd |
| 2785 | for ii, t in enumerate(self.tables): |
| 2786 | dump = t.dump() |
| 2787 | mdump = t.mdump() |
| 2788 | for jj in range(0, N_ROUTES, 2): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2789 | self.assertTrue(find_route_in_dump(dump, routes[ii][jj]["uni"], t)) |
| 2790 | self.assertTrue( |
| 2791 | find_mroute_in_dump(mdump, routes[ii][jj]["multi"], t) |
| 2792 | ) |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 2793 | for jj in range(1, N_ROUTES - 1, 2): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2794 | self.assertFalse(find_route_in_dump(dump, routes[ii][jj]["uni"], t)) |
| 2795 | self.assertFalse( |
| 2796 | find_mroute_in_dump(mdump, routes[ii][jj]["multi"], t) |
| 2797 | ) |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 2798 | |
| 2799 | # reload all the routes |
| 2800 | for ii, t in enumerate(self.tables): |
| 2801 | for r in routes[ii]: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2802 | r["uni"].add_vpp_config() |
| 2803 | r["multi"].add_vpp_config() |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 2804 | |
| 2805 | # all the routes are still there |
| 2806 | for ii, t in enumerate(self.tables): |
| 2807 | dump = t.dump() |
| 2808 | mdump = t.mdump() |
| 2809 | for r in routes[ii]: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2810 | self.assertTrue(find_route_in_dump(dump, r["uni"], t)) |
| 2811 | self.assertTrue(find_mroute_in_dump(mdump, r["multi"], t)) |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 2812 | |
| 2813 | # |
| 2814 | # finally flush the tables for good measure |
| 2815 | # |
| 2816 | for t in self.tables: |
| 2817 | t.flush() |
| 2818 | self.assertEqual(len(t.dump()), 5) |
Neale Ranns | 03c254e | 2020-03-17 14:25:10 +0000 | [diff] [blame] | 2819 | self.assertEqual(len(t.mdump()), 3) |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 2820 | |
| 2821 | |
Neale Ranns | 9efcee6 | 2019-11-26 19:30:08 +0000 | [diff] [blame] | 2822 | class TestIPCover(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2823 | """IPv4 Table Cover""" |
Neale Ranns | 9efcee6 | 2019-11-26 19:30:08 +0000 | [diff] [blame] | 2824 | |
| 2825 | @classmethod |
| 2826 | def setUpClass(cls): |
| 2827 | super(TestIPCover, cls).setUpClass() |
| 2828 | |
| 2829 | @classmethod |
| 2830 | def tearDownClass(cls): |
| 2831 | super(TestIPCover, cls).tearDownClass() |
| 2832 | |
| 2833 | def setUp(self): |
| 2834 | super(TestIPCover, self).setUp() |
| 2835 | |
| 2836 | self.create_pg_interfaces(range(4)) |
| 2837 | |
| 2838 | table_id = 1 |
| 2839 | self.tables = [] |
| 2840 | |
| 2841 | for i in self.pg_interfaces: |
| 2842 | i.admin_up() |
| 2843 | i.config_ip4() |
| 2844 | i.resolve_arp() |
| 2845 | i.generate_remote_hosts(2) |
| 2846 | self.tables.append(VppIpTable(self, table_id).add_vpp_config()) |
| 2847 | table_id += 1 |
| 2848 | |
| 2849 | def tearDown(self): |
| 2850 | super(TestIPCover, self).tearDown() |
| 2851 | for i in self.pg_interfaces: |
| 2852 | i.admin_down() |
| 2853 | i.unconfig_ip4() |
| 2854 | |
| 2855 | def test_cover(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2856 | """IP Table Cover""" |
Neale Ranns | 9efcee6 | 2019-11-26 19:30:08 +0000 | [diff] [blame] | 2857 | |
| 2858 | # add a loop back with a /32 prefix |
| 2859 | lo = VppLoInterface(self) |
| 2860 | lo.admin_up() |
| 2861 | a = VppIpInterfaceAddress(self, lo, "127.0.0.1", 32).add_vpp_config() |
| 2862 | |
| 2863 | # add a neighbour that matches the loopback's /32 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2864 | nbr = VppNeighbor( |
| 2865 | self, lo.sw_if_index, lo.remote_mac, "127.0.0.1" |
| 2866 | ).add_vpp_config() |
Neale Ranns | 9efcee6 | 2019-11-26 19:30:08 +0000 | [diff] [blame] | 2867 | |
| 2868 | # add the default route which will be the cover for /32 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2869 | r = VppIpRoute( |
| 2870 | self, |
| 2871 | "0.0.0.0", |
| 2872 | 0, |
| 2873 | [VppRoutePath("127.0.0.1", lo.sw_if_index)], |
| 2874 | register=False, |
| 2875 | ).add_vpp_config() |
Neale Ranns | 9efcee6 | 2019-11-26 19:30:08 +0000 | [diff] [blame] | 2876 | |
| 2877 | # add/remove/add a longer mask cover |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2878 | r8 = VppIpRoute( |
| 2879 | self, "127.0.0.0", 8, [VppRoutePath("127.0.0.1", lo.sw_if_index)] |
| 2880 | ).add_vpp_config() |
Neale Ranns | 8786603 | 2020-11-25 09:14:22 +0000 | [diff] [blame] | 2881 | r8.remove_vpp_config() |
| 2882 | r8.add_vpp_config() |
| 2883 | r8.remove_vpp_config() |
Neale Ranns | 9efcee6 | 2019-11-26 19:30:08 +0000 | [diff] [blame] | 2884 | |
| 2885 | # remove the default route |
| 2886 | r.remove_vpp_config() |
| 2887 | |
Neale Ranns | 8786603 | 2020-11-25 09:14:22 +0000 | [diff] [blame] | 2888 | # remove the interface prefix |
| 2889 | a.remove_vpp_config() |
| 2890 | |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 2891 | |
| 2892 | class TestIP4Replace(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2893 | """IPv4 Interface Address Replace""" |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 2894 | |
| 2895 | @classmethod |
| 2896 | def setUpClass(cls): |
| 2897 | super(TestIP4Replace, cls).setUpClass() |
| 2898 | |
| 2899 | @classmethod |
| 2900 | def tearDownClass(cls): |
| 2901 | super(TestIP4Replace, cls).tearDownClass() |
| 2902 | |
| 2903 | def setUp(self): |
| 2904 | super(TestIP4Replace, self).setUp() |
| 2905 | |
| 2906 | self.create_pg_interfaces(range(4)) |
| 2907 | |
| 2908 | for i in self.pg_interfaces: |
| 2909 | i.admin_up() |
| 2910 | |
| 2911 | def tearDown(self): |
| 2912 | super(TestIP4Replace, self).tearDown() |
| 2913 | for i in self.pg_interfaces: |
| 2914 | i.admin_down() |
| 2915 | |
| 2916 | def get_n_pfxs(self, intf): |
| 2917 | return len(self.vapi.ip_address_dump(intf.sw_if_index)) |
| 2918 | |
| 2919 | def test_replace(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2920 | """IP interface address replace""" |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 2921 | |
| 2922 | intf_pfxs = [[], [], [], []] |
| 2923 | |
| 2924 | # add prefixes to each of the interfaces |
| 2925 | for i in range(len(self.pg_interfaces)): |
| 2926 | intf = self.pg_interfaces[i] |
| 2927 | |
| 2928 | # 172.16.x.1/24 |
| 2929 | addr = "172.16.%d.1" % intf.sw_if_index |
| 2930 | a = VppIpInterfaceAddress(self, intf, addr, 24).add_vpp_config() |
| 2931 | intf_pfxs[i].append(a) |
| 2932 | |
| 2933 | # 172.16.x.2/24 - a different address in the same subnet as above |
| 2934 | addr = "172.16.%d.2" % intf.sw_if_index |
| 2935 | a = VppIpInterfaceAddress(self, intf, addr, 24).add_vpp_config() |
| 2936 | intf_pfxs[i].append(a) |
| 2937 | |
| 2938 | # 172.15.x.2/24 - a different address and subnet |
| 2939 | addr = "172.15.%d.2" % intf.sw_if_index |
| 2940 | a = VppIpInterfaceAddress(self, intf, addr, 24).add_vpp_config() |
| 2941 | intf_pfxs[i].append(a) |
| 2942 | |
| 2943 | # a dump should n_address in it |
| 2944 | for intf in self.pg_interfaces: |
| 2945 | self.assertEqual(self.get_n_pfxs(intf), 3) |
| 2946 | |
| 2947 | # |
| 2948 | # remove all the address thru a replace |
| 2949 | # |
| 2950 | self.vapi.sw_interface_address_replace_begin() |
| 2951 | self.vapi.sw_interface_address_replace_end() |
| 2952 | for intf in self.pg_interfaces: |
| 2953 | self.assertEqual(self.get_n_pfxs(intf), 0) |
| 2954 | |
| 2955 | # |
| 2956 | # add all the interface addresses back |
| 2957 | # |
| 2958 | for p in intf_pfxs: |
| 2959 | for v in p: |
| 2960 | v.add_vpp_config() |
| 2961 | for intf in self.pg_interfaces: |
| 2962 | self.assertEqual(self.get_n_pfxs(intf), 3) |
| 2963 | |
| 2964 | # |
| 2965 | # replace again, but this time update/re-add the address on the first |
| 2966 | # two interfaces |
| 2967 | # |
| 2968 | self.vapi.sw_interface_address_replace_begin() |
| 2969 | |
| 2970 | for p in intf_pfxs[:2]: |
| 2971 | for v in p: |
| 2972 | v.add_vpp_config() |
| 2973 | |
| 2974 | self.vapi.sw_interface_address_replace_end() |
| 2975 | |
| 2976 | # on the first two the address still exist, |
| 2977 | # on the other two they do not |
| 2978 | for intf in self.pg_interfaces[:2]: |
| 2979 | self.assertEqual(self.get_n_pfxs(intf), 3) |
| 2980 | for p in intf_pfxs[:2]: |
| 2981 | for v in p: |
| 2982 | self.assertTrue(v.query_vpp_config()) |
| 2983 | for intf in self.pg_interfaces[2:]: |
| 2984 | self.assertEqual(self.get_n_pfxs(intf), 0) |
| 2985 | |
| 2986 | # |
| 2987 | # add all the interface addresses back on the last two |
| 2988 | # |
| 2989 | for p in intf_pfxs[2:]: |
| 2990 | for v in p: |
| 2991 | v.add_vpp_config() |
| 2992 | for intf in self.pg_interfaces: |
| 2993 | self.assertEqual(self.get_n_pfxs(intf), 3) |
| 2994 | |
| 2995 | # |
| 2996 | # replace again, this time add different prefixes on all the interfaces |
| 2997 | # |
| 2998 | self.vapi.sw_interface_address_replace_begin() |
| 2999 | |
| 3000 | pfxs = [] |
| 3001 | for intf in self.pg_interfaces: |
| 3002 | # 172.18.x.1/24 |
| 3003 | addr = "172.18.%d.1" % intf.sw_if_index |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3004 | pfxs.append(VppIpInterfaceAddress(self, intf, addr, 24).add_vpp_config()) |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 3005 | |
| 3006 | self.vapi.sw_interface_address_replace_end() |
| 3007 | |
| 3008 | # only .18 should exist on each interface |
| 3009 | for intf in self.pg_interfaces: |
| 3010 | self.assertEqual(self.get_n_pfxs(intf), 1) |
| 3011 | for pfx in pfxs: |
| 3012 | self.assertTrue(pfx.query_vpp_config()) |
| 3013 | |
| 3014 | # |
| 3015 | # remove everything |
| 3016 | # |
| 3017 | self.vapi.sw_interface_address_replace_begin() |
| 3018 | self.vapi.sw_interface_address_replace_end() |
| 3019 | for intf in self.pg_interfaces: |
| 3020 | self.assertEqual(self.get_n_pfxs(intf), 0) |
| 3021 | |
| 3022 | # |
| 3023 | # add prefixes to each interface. post-begin add the prefix from |
| 3024 | # interface X onto interface Y. this would normally be an error |
| 3025 | # since it would generate a 'duplicate address' warning. but in |
| 3026 | # this case, since what is newly downloaded is sane, it's ok |
| 3027 | # |
| 3028 | for intf in self.pg_interfaces: |
| 3029 | # 172.18.x.1/24 |
| 3030 | addr = "172.18.%d.1" % intf.sw_if_index |
| 3031 | VppIpInterfaceAddress(self, intf, addr, 24).add_vpp_config() |
| 3032 | |
| 3033 | self.vapi.sw_interface_address_replace_begin() |
| 3034 | |
| 3035 | pfxs = [] |
| 3036 | for intf in self.pg_interfaces: |
| 3037 | # 172.18.x.1/24 |
| 3038 | addr = "172.18.%d.1" % (intf.sw_if_index + 1) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3039 | pfxs.append(VppIpInterfaceAddress(self, intf, addr, 24).add_vpp_config()) |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 3040 | |
| 3041 | self.vapi.sw_interface_address_replace_end() |
| 3042 | |
| 3043 | self.logger.info(self.vapi.cli("sh int addr")) |
| 3044 | |
| 3045 | for intf in self.pg_interfaces: |
| 3046 | self.assertEqual(self.get_n_pfxs(intf), 1) |
| 3047 | for pfx in pfxs: |
| 3048 | self.assertTrue(pfx.query_vpp_config()) |
| 3049 | |
| 3050 | |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3051 | class TestIPv4PathMTU(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3052 | """IPv4 Path MTU""" |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3053 | |
| 3054 | @classmethod |
| 3055 | def setUpClass(cls): |
| 3056 | super(TestIPv4PathMTU, cls).setUpClass() |
| 3057 | |
| 3058 | cls.create_pg_interfaces(range(2)) |
| 3059 | |
| 3060 | # setup all interfaces |
| 3061 | for i in cls.pg_interfaces: |
| 3062 | i.admin_up() |
| 3063 | i.config_ip4() |
| 3064 | i.resolve_arp() |
| 3065 | |
| 3066 | @classmethod |
| 3067 | def tearDownClass(cls): |
| 3068 | super(TestIPv4PathMTU, cls).tearDownClass() |
| 3069 | |
| 3070 | def test_path_mtu(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3071 | """Path MTU""" |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3072 | |
| 3073 | # |
| 3074 | # The goal here is not to test that fragmentation works correctly, |
| 3075 | # that's done elsewhere, the intent is to ensure that the Path MTU |
| 3076 | # settings are honoured. |
| 3077 | # |
| 3078 | self.vapi.cli("adjacency counters enable") |
| 3079 | |
| 3080 | # set the interface MTU to a reasonable value |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3081 | self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [1800, 0, 0, 0]) |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3082 | |
| 3083 | self.pg1.generate_remote_hosts(4) |
| 3084 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3085 | p_2k = ( |
| 3086 | Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) |
| 3087 | / IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4) |
| 3088 | / UDP(sport=1234, dport=5678) |
| 3089 | / Raw(b"0xa" * 640) |
| 3090 | ) |
| 3091 | p_1k = ( |
| 3092 | Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) |
| 3093 | / IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4) |
| 3094 | / UDP(sport=1234, dport=5678) |
| 3095 | / Raw(b"0xa" * 320) |
| 3096 | ) |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3097 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3098 | nbr = VppNeighbor( |
| 3099 | self, self.pg1.sw_if_index, self.pg1.remote_mac, self.pg1.remote_ip4 |
| 3100 | ).add_vpp_config() |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3101 | |
| 3102 | # this is now the interface MTU frags |
| 3103 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=2) |
| 3104 | self.send_and_expect(self.pg0, [p_1k], self.pg1) |
| 3105 | |
| 3106 | # drop the path MTU for this neighbour to below the interface MTU |
| 3107 | # expect more frags |
| 3108 | pmtu = VppIpPathMtu(self, self.pg1.remote_ip4, 900).add_vpp_config() |
| 3109 | |
| 3110 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3) |
| 3111 | self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2) |
| 3112 | |
| 3113 | # print/format the adj delegate |
| 3114 | self.logger.info(self.vapi.cli("sh adj 5")) |
| 3115 | |
| 3116 | # increase the path MTU to more than the interface |
| 3117 | # expect to use the interface MTU |
| 3118 | pmtu.modify(8192) |
| 3119 | |
| 3120 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=2) |
| 3121 | self.send_and_expect(self.pg0, [p_1k], self.pg1) |
| 3122 | |
| 3123 | # go back to an MTU from the path |
| 3124 | # wrap the call around mark-n-sweep to enusre updates clear stale |
| 3125 | self.vapi.ip_path_mtu_replace_begin() |
| 3126 | pmtu.modify(900) |
| 3127 | self.vapi.ip_path_mtu_replace_end() |
| 3128 | |
| 3129 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3) |
| 3130 | self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2) |
| 3131 | |
| 3132 | # raise the interface's MTU |
| 3133 | # should still use that of the path |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3134 | self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [2000, 0, 0, 0]) |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3135 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3) |
| 3136 | self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2) |
| 3137 | |
| 3138 | # set path high and interface low |
| 3139 | pmtu.modify(2000) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3140 | self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [900, 0, 0, 0]) |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3141 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3) |
| 3142 | self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2) |
| 3143 | |
| 3144 | # remove the path MTU using the mark-n-sweep semantics |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3145 | self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [1800, 0, 0, 0]) |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3146 | self.vapi.ip_path_mtu_replace_begin() |
| 3147 | self.vapi.ip_path_mtu_replace_end() |
| 3148 | |
| 3149 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=2) |
| 3150 | self.send_and_expect(self.pg0, [p_1k], self.pg1) |
| 3151 | |
| 3152 | # |
| 3153 | # set path MTU for a neighbour that doesn't exist, yet |
| 3154 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3155 | pmtu2 = VppIpPathMtu(self, self.pg1.remote_hosts[2].ip4, 900).add_vpp_config() |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3156 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3157 | p_2k = ( |
| 3158 | Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) |
| 3159 | / IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_hosts[2].ip4) |
| 3160 | / UDP(sport=1234, dport=5678) |
| 3161 | / Raw(b"0xa" * 640) |
| 3162 | ) |
| 3163 | p_1k = ( |
| 3164 | Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) |
| 3165 | / IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_hosts[2].ip4) |
| 3166 | / UDP(sport=1234, dport=5678) |
| 3167 | / Raw(b"0xa" * 320) |
| 3168 | ) |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3169 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3170 | nbr2 = VppNeighbor( |
| 3171 | self, |
| 3172 | self.pg1.sw_if_index, |
| 3173 | self.pg1.remote_hosts[2].mac, |
| 3174 | self.pg1.remote_hosts[2].ip4, |
| 3175 | ).add_vpp_config() |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3176 | |
| 3177 | # should frag to the path MTU |
| 3178 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3) |
| 3179 | self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2) |
| 3180 | |
| 3181 | # remove and re-add the neighbour |
| 3182 | nbr2.remove_vpp_config() |
| 3183 | nbr2.add_vpp_config() |
| 3184 | |
| 3185 | # should frag to the path MTU |
| 3186 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3) |
| 3187 | self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2) |
| 3188 | |
| 3189 | # |
| 3190 | # set PMTUs for many peers |
| 3191 | # |
| 3192 | N_HOSTS = 16 |
| 3193 | self.pg1.generate_remote_hosts(16) |
| 3194 | self.pg1.configure_ipv4_neighbors() |
| 3195 | |
| 3196 | for h in range(N_HOSTS): |
| 3197 | pmtu = VppIpPathMtu(self, self.pg1.remote_hosts[h].ip4, 900) |
| 3198 | pmtu.add_vpp_config() |
| 3199 | self.assertTrue(pmtu.query_vpp_config()) |
| 3200 | |
| 3201 | self.logger.info(self.vapi.cli("sh ip pmtu")) |
| 3202 | dump = list(self.vapi.vpp.details_iter(self.vapi.ip_path_mtu_get)) |
| 3203 | self.assertEqual(N_HOSTS, len(dump)) |
| 3204 | |
| 3205 | for h in range(N_HOSTS): |
| 3206 | p_2k[IP].dst = self.pg1.remote_hosts[h].ip4 |
| 3207 | p_1k[IP].dst = self.pg1.remote_hosts[h].ip4 |
| 3208 | |
| 3209 | # should frag to the path MTU |
| 3210 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3) |
| 3211 | self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2) |
| 3212 | |
| 3213 | |
Neale Ranns | 50bd1d3 | 2021-10-08 07:16:12 +0000 | [diff] [blame] | 3214 | class TestIPv4ItfRebind(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3215 | """IPv4 Interface Bind w/ attached routes""" |
Neale Ranns | 50bd1d3 | 2021-10-08 07:16:12 +0000 | [diff] [blame] | 3216 | |
| 3217 | def setUp(self): |
| 3218 | super(TestIPv4ItfRebind, self).setUp() |
| 3219 | |
| 3220 | self.create_pg_interfaces(range(3)) |
| 3221 | |
| 3222 | def tearDown(self): |
| 3223 | super(TestIPv4ItfRebind, self).tearDown() |
| 3224 | |
| 3225 | def test_rebind(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3226 | """Import to no import""" |
Neale Ranns | 50bd1d3 | 2021-10-08 07:16:12 +0000 | [diff] [blame] | 3227 | |
| 3228 | TABLE_ID = 1 |
| 3229 | tbl = VppIpTable(self, TABLE_ID).add_vpp_config() |
| 3230 | self.pg1.set_table_ip4(TABLE_ID) |
| 3231 | |
| 3232 | for i in self.pg_interfaces: |
| 3233 | i.admin_up() |
| 3234 | i.config_ip4() |
| 3235 | i.resolve_arp() |
| 3236 | |
| 3237 | # add an attached route via an pg0 |
| 3238 | # in a different table. this prefix should import |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3239 | rt = VppIpRoute( |
| 3240 | self, |
| 3241 | self.pg0.local_ip4, |
| 3242 | 24, |
| 3243 | [VppRoutePath("0.0.0.0", self.pg0.sw_if_index)], |
| 3244 | table_id=TABLE_ID, |
| 3245 | ).add_vpp_config() |
Neale Ranns | 50bd1d3 | 2021-10-08 07:16:12 +0000 | [diff] [blame] | 3246 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3247 | p = ( |
| 3248 | Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) |
| 3249 | / IP(src=self.pg1.remote_ip4, dst=self.pg0.remote_ip4) |
| 3250 | / UDP(sport=1234, dport=5678) |
| 3251 | / Raw(b"0xa" * 640) |
| 3252 | ) |
Neale Ranns | 50bd1d3 | 2021-10-08 07:16:12 +0000 | [diff] [blame] | 3253 | |
| 3254 | rx = self.send_and_expect(self.pg1, [p], self.pg0) |
| 3255 | self.assertFalse(rx[0].haslayer(ARP)) |
| 3256 | |
| 3257 | # then bind pg0 to a new table |
| 3258 | # so the prefix no longer imports |
| 3259 | self.pg0.unconfig_ip4() |
| 3260 | self.pg0.set_table_ip4(TABLE_ID) |
| 3261 | self.pg0.config_ip4() |
| 3262 | self.pg0.resolve_arp() |
| 3263 | |
| 3264 | rx = self.send_and_expect(self.pg1, [p], self.pg0) |
| 3265 | self.assertFalse(rx[0].haslayer(ARP)) |
| 3266 | |
| 3267 | # revert back to imported |
| 3268 | self.pg0.unconfig_ip4() |
| 3269 | self.pg0.set_table_ip4(0) |
| 3270 | self.pg0.config_ip4() |
| 3271 | self.pg0.resolve_arp() |
| 3272 | |
| 3273 | rx = self.send_and_expect(self.pg1, [p], self.pg0) |
| 3274 | self.assertFalse(rx[0].haslayer(ARP)) |
| 3275 | |
| 3276 | # cleanup |
| 3277 | for i in self.pg_interfaces: |
| 3278 | i.unconfig_ip4() |
| 3279 | i.set_table_ip4(0) |
| 3280 | i.admin_down() |
| 3281 | |
| 3282 | rt.remove_vpp_config() |
| 3283 | tbl.remove_vpp_config() |
| 3284 | |
| 3285 | def test_delete(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3286 | """Swap import tables""" |
Neale Ranns | 50bd1d3 | 2021-10-08 07:16:12 +0000 | [diff] [blame] | 3287 | |
| 3288 | TABLE_ID1 = 1 |
| 3289 | tbl1_4 = VppIpTable(self, TABLE_ID1).add_vpp_config() |
| 3290 | tbl1_6 = VppIpTable(self, TABLE_ID1, True).add_vpp_config() |
| 3291 | TABLE_ID2 = 2 |
| 3292 | tbl2_4 = VppIpTable(self, TABLE_ID2).add_vpp_config() |
| 3293 | tbl2_6 = VppIpTable(self, TABLE_ID2, True).add_vpp_config() |
| 3294 | |
| 3295 | # table mappings |
| 3296 | self.pg1.set_table_ip4(TABLE_ID1) |
| 3297 | self.pg1.set_table_ip6(TABLE_ID1) |
| 3298 | self.pg2.set_table_ip4(TABLE_ID2) |
| 3299 | self.pg2.set_table_ip6(TABLE_ID2) |
| 3300 | |
| 3301 | for i in self.pg_interfaces: |
| 3302 | i.admin_up() |
| 3303 | i.config_ip4() |
| 3304 | i.resolve_arp() |
| 3305 | |
| 3306 | # add an attached route in the default table via pg0 |
| 3307 | # this should import to table 1 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3308 | rt4 = VppIpRoute( |
| 3309 | self, |
| 3310 | self.pg1.local_ip4, |
| 3311 | 24, |
| 3312 | [VppRoutePath("0.0.0.0", self.pg1.sw_if_index)], |
| 3313 | ).add_vpp_config() |
| 3314 | rt6 = VppIpRoute( |
| 3315 | self, |
| 3316 | self.pg1.local_ip6, |
| 3317 | 64, |
| 3318 | [VppRoutePath("0.0.0.0", self.pg1.sw_if_index)], |
| 3319 | ).add_vpp_config() |
Neale Ranns | 50bd1d3 | 2021-10-08 07:16:12 +0000 | [diff] [blame] | 3320 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3321 | p1 = ( |
| 3322 | Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) |
| 3323 | / IP(src=self.pg1.remote_ip4, dst=self.pg1.remote_ip4) |
| 3324 | / UDP(sport=1234, dport=5678) |
| 3325 | / Raw(b"0xa" * 640) |
| 3326 | ) |
Neale Ranns | 50bd1d3 | 2021-10-08 07:16:12 +0000 | [diff] [blame] | 3327 | |
| 3328 | # inject into table 0 |
| 3329 | rx = self.send_and_expect(self.pg0, [p1], self.pg1) |
| 3330 | self.assertFalse(rx[0].haslayer(ARP)) |
| 3331 | |
| 3332 | # swap the attached interface to table 2 |
| 3333 | self.pg1.unconfig_ip4() |
| 3334 | self.pg1.unconfig_ip6() |
| 3335 | self.pg1.set_table_ip4(TABLE_ID2) |
| 3336 | self.pg1.set_table_ip6(TABLE_ID2) |
| 3337 | self.pg1.config_ip4() |
| 3338 | self.pg1.config_ip6() |
| 3339 | self.pg1.resolve_arp() |
| 3340 | |
| 3341 | # delete table 1 |
| 3342 | tbl1_4.flush() |
| 3343 | tbl1_6.flush() |
| 3344 | tbl1_4.remove_vpp_config() |
| 3345 | tbl1_6.remove_vpp_config() |
| 3346 | |
| 3347 | rx = self.send_and_expect(self.pg0, [p1], self.pg1) |
| 3348 | self.assertFalse(rx[0].haslayer(ARP)) |
| 3349 | |
| 3350 | for i in self.pg_interfaces: |
| 3351 | i.unconfig_ip4() |
| 3352 | i.unconfig_ip6() |
| 3353 | i.set_table_ip4(0) |
| 3354 | i.set_table_ip6(0) |
| 3355 | i.admin_down() |
| 3356 | |
| 3357 | |
Vladislav Grishenko | dea806d | 2024-02-20 11:58:01 +0500 | [diff] [blame] | 3358 | class TestIP4InterfaceRx(VppTestCase): |
| 3359 | """IPv4 Interface Receive""" |
| 3360 | |
| 3361 | @classmethod |
| 3362 | def setUpClass(cls): |
| 3363 | super(TestIP4InterfaceRx, cls).setUpClass() |
| 3364 | |
| 3365 | @classmethod |
| 3366 | def tearDownClass(cls): |
| 3367 | super(TestIP4InterfaceRx, cls).tearDownClass() |
| 3368 | |
| 3369 | def setUp(self): |
| 3370 | super(TestIP4InterfaceRx, self).setUp() |
| 3371 | |
| 3372 | self.create_pg_interfaces(range(3)) |
| 3373 | |
| 3374 | table_id = 0 |
| 3375 | |
| 3376 | for i in self.pg_interfaces: |
| 3377 | i.admin_up() |
| 3378 | |
| 3379 | if table_id != 0: |
| 3380 | table = VppIpTable(self, table_id) |
| 3381 | table.add_vpp_config() |
| 3382 | |
| 3383 | i.set_table_ip4(table_id) |
| 3384 | i.config_ip4() |
| 3385 | i.resolve_arp() |
| 3386 | table_id += 1 |
| 3387 | |
| 3388 | def tearDown(self): |
| 3389 | for i in self.pg_interfaces: |
| 3390 | i.unconfig_ip4() |
| 3391 | i.admin_down() |
| 3392 | i.set_table_ip4(0) |
| 3393 | |
| 3394 | super(TestIP4InterfaceRx, self).tearDown() |
| 3395 | |
| 3396 | def test_interface_rx(self): |
| 3397 | """IPv4 Interface Receive""" |
| 3398 | |
| 3399 | # |
| 3400 | # add a route in the default table to receive ... |
| 3401 | # |
| 3402 | route_to_dst = VppIpRoute( |
| 3403 | self, |
| 3404 | "1.1.1.0", |
| 3405 | 24, |
| 3406 | [ |
| 3407 | VppRoutePath( |
| 3408 | "0.0.0.0", |
| 3409 | self.pg1.sw_if_index, |
| 3410 | type=FibPathType.FIB_PATH_TYPE_INTERFACE_RX, |
| 3411 | ) |
| 3412 | ], |
| 3413 | ) |
| 3414 | route_to_dst.add_vpp_config() |
| 3415 | |
| 3416 | # |
| 3417 | # packets to these destination are dropped, since they'll |
| 3418 | # hit the respective default routes in table 1 |
| 3419 | # |
| 3420 | p_dst = ( |
| 3421 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 3422 | / IP(src="5.5.5.5", dst="1.1.1.1") |
| 3423 | / TCP(sport=1234, dport=1234) |
| 3424 | / Raw(b"\xa5" * 100) |
| 3425 | ) |
| 3426 | pkts_dst = p_dst * 10 |
| 3427 | |
| 3428 | self.send_and_assert_no_replies(self.pg0, pkts_dst, "IP in table 1") |
| 3429 | |
| 3430 | # |
| 3431 | # add a route in the dst table to forward via pg1 |
| 3432 | # |
| 3433 | route_in_dst = VppIpRoute( |
| 3434 | self, |
| 3435 | "1.1.1.1", |
| 3436 | 32, |
| 3437 | [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index)], |
| 3438 | table_id=1, |
| 3439 | ) |
| 3440 | route_in_dst.add_vpp_config() |
| 3441 | |
| 3442 | self.send_and_expect(self.pg0, pkts_dst, self.pg1) |
| 3443 | |
| 3444 | # |
| 3445 | # add a route in the default table to receive ... |
| 3446 | # |
| 3447 | route_to_dst = VppIpRoute( |
| 3448 | self, |
| 3449 | "1.1.1.0", |
| 3450 | 24, |
| 3451 | [ |
| 3452 | VppRoutePath( |
| 3453 | "0.0.0.0", |
| 3454 | self.pg2.sw_if_index, |
| 3455 | type=FibPathType.FIB_PATH_TYPE_INTERFACE_RX, |
| 3456 | ) |
| 3457 | ], |
| 3458 | table_id=1, |
| 3459 | ) |
| 3460 | route_to_dst.add_vpp_config() |
| 3461 | |
| 3462 | # |
| 3463 | # packets to these destination are dropped, since they'll |
| 3464 | # hit the respective default routes in table 2 |
| 3465 | # |
| 3466 | p_dst = ( |
| 3467 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 3468 | / IP(src="6.6.6.6", dst="1.1.1.2") |
| 3469 | / TCP(sport=1234, dport=1234) |
| 3470 | / Raw(b"\xa5" * 100) |
| 3471 | ) |
| 3472 | pkts_dst = p_dst * 10 |
| 3473 | |
| 3474 | self.send_and_assert_no_replies(self.pg0, pkts_dst, "IP in table 2") |
| 3475 | |
| 3476 | # |
| 3477 | # add a route in the table 2 to forward via pg2 |
| 3478 | # |
| 3479 | route_in_dst = VppIpRoute( |
| 3480 | self, |
| 3481 | "1.1.1.2", |
| 3482 | 32, |
| 3483 | [VppRoutePath(self.pg2.remote_ip4, self.pg2.sw_if_index)], |
| 3484 | table_id=2, |
| 3485 | ) |
| 3486 | route_in_dst.add_vpp_config() |
| 3487 | |
| 3488 | self.send_and_expect(self.pg0, pkts_dst, self.pg2) |
| 3489 | |
| 3490 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3491 | if __name__ == "__main__": |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 3492 | unittest.main(testRunner=VppTestRunner) |