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