Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 1 | import socket |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 2 | |
Paul Vinciguerra | a7427ec | 2019-03-10 10:04:23 -0700 | [diff] [blame] | 3 | import scapy.compat |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 4 | from scapy.layers.inet import IP, UDP |
Klement Sekera | 65cc8c0 | 2016-12-18 15:49:54 +0100 | [diff] [blame] | 5 | from scapy.layers.inet6 import IPv6 |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 6 | from scapy.layers.l2 import Ether, GRE |
| 7 | from scapy.packet import Raw |
Hongjun Ni | 6fb0d9b | 2018-06-08 07:12:05 +0800 | [diff] [blame] | 8 | from scapy.data import IP_PROTOS |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 9 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 10 | from framework import VppTestCase |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 11 | from util import ppp |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 12 | from vpp_ip_route import VppIpRoute, VppRoutePath |
| 13 | from vpp_ip import INVALID_INDEX |
Dmitry Valter | 34fa0ce | 2024-03-11 10:38:46 +0000 | [diff] [blame] | 14 | from config import config |
| 15 | import unittest |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 16 | |
| 17 | """ TestLB is a subclass of VPPTestCase classes. |
| 18 | |
| 19 | TestLB class defines Load Balancer test cases for: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 20 | - IP4 to GRE4 encap on per-port vip case |
| 21 | - IP4 to GRE6 encap on per-port vip case |
| 22 | - IP6 to GRE4 encap on per-port vip case |
| 23 | - IP6 to GRE6 encap on per-port vip case |
| 24 | - IP4 to L3DSR encap on vip case |
| 25 | - IP4 to L3DSR encap on per-port vip case |
Nobuhiro MIKI | 613e6dc | 2022-09-28 15:53:17 +0900 | [diff] [blame] | 26 | - IP4 to L3DSR encap on per-port vip with src_ip_sticky case |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 27 | - IP4 to NAT4 encap on per-port vip case |
| 28 | - IP6 to NAT6 encap on per-port vip case |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 29 | |
| 30 | As stated in comments below, GRE has issues with IPv6. |
| 31 | All test cases involving IPv6 are executed, but |
| 32 | received packets are not parsed and checked. |
| 33 | |
| 34 | """ |
| 35 | |
| 36 | |
Dmitry Valter | 34fa0ce | 2024-03-11 10:38:46 +0000 | [diff] [blame] | 37 | @unittest.skipIf("lb" in config.excluded_plugins, "Exclude LB plugin tests") |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 38 | class TestLB(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 39 | """Load Balancer Test Case""" |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 40 | |
| 41 | @classmethod |
| 42 | def setUpClass(cls): |
| 43 | super(TestLB, cls).setUpClass() |
| 44 | |
| 45 | cls.ass = range(5) |
Nobuhiro MIKI | 613e6dc | 2022-09-28 15:53:17 +0900 | [diff] [blame] | 46 | cls.packets = range(100) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 47 | |
| 48 | try: |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 49 | cls.create_pg_interfaces(range(2)) |
| 50 | cls.interfaces = list(cls.pg_interfaces) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 51 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 52 | for i in cls.interfaces: |
| 53 | i.admin_up() |
| 54 | i.config_ip4() |
| 55 | i.config_ip6() |
| 56 | i.disable_ipv6_ra() |
| 57 | i.resolve_arp() |
| 58 | i.resolve_ndp() |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 59 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 60 | dst4 = VppIpRoute( |
| 61 | cls, |
| 62 | "10.0.0.0", |
| 63 | 24, |
| 64 | [VppRoutePath(cls.pg1.remote_ip4, INVALID_INDEX)], |
| 65 | register=False, |
| 66 | ) |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 67 | dst4.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 68 | dst6 = VppIpRoute( |
| 69 | cls, |
| 70 | "2002::", |
| 71 | 16, |
| 72 | [VppRoutePath(cls.pg1.remote_ip6, INVALID_INDEX)], |
| 73 | register=False, |
| 74 | ) |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 75 | dst6.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 76 | cls.vapi.lb_conf(ip4_src_address="39.40.41.42", ip6_src_address="2004::1") |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 77 | except Exception: |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 78 | super(TestLB, cls).tearDownClass() |
| 79 | raise |
| 80 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 81 | @classmethod |
| 82 | def tearDownClass(cls): |
| 83 | super(TestLB, cls).tearDownClass() |
| 84 | |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 85 | def tearDown(self): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 86 | super(TestLB, self).tearDown() |
Paul Vinciguerra | 90cf21b | 2019-03-13 09:23:05 -0700 | [diff] [blame] | 87 | |
| 88 | def show_commands_at_teardown(self): |
| 89 | self.logger.info(self.vapi.cli("show lb vip verbose")) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 90 | |
| 91 | def getIPv4Flow(self, id): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 92 | return IP( |
| 93 | dst="90.0.%u.%u" % (id / 255, id % 255), |
| 94 | src="40.0.%u.%u" % (id / 255, id % 255), |
| 95 | ) / UDP(sport=10000 + id, dport=20000) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 96 | |
| 97 | def getIPv6Flow(self, id): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 98 | return IPv6(dst="2001::%u" % (id), src="fd00:f00d:ffff::%u" % (id)) / UDP( |
| 99 | sport=10000 + id, dport=20000 |
| 100 | ) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 101 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 102 | def generatePackets(self, src_if, isv4): |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 103 | self.reset_packet_infos() |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 104 | pkts = [] |
| 105 | for pktid in self.packets: |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 106 | info = self.create_packet_info(src_if, self.pg1) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 107 | payload = self.info_to_payload(info) |
| 108 | ip = self.getIPv4Flow(pktid) if isv4 else self.getIPv6Flow(pktid) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 109 | packet = ( |
| 110 | Ether(dst=src_if.local_mac, src=src_if.remote_mac) / ip / Raw(payload) |
| 111 | ) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 112 | self.extend_packet(packet, 128) |
| 113 | info.data = packet.copy() |
| 114 | pkts.append(packet) |
| 115 | return pkts |
| 116 | |
| 117 | def checkInner(self, gre, isv4): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 118 | IPver = IP if isv4 else IPv6 |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 119 | self.assertEqual(gre.proto, 0x0800 if isv4 else 0x86DD) |
| 120 | self.assertEqual(gre.flags, 0) |
| 121 | self.assertEqual(gre.version, 0) |
Paul Vinciguerra | a7427ec | 2019-03-10 10:04:23 -0700 | [diff] [blame] | 122 | inner = IPver(scapy.compat.raw(gre.payload)) |
Paul Vinciguerra | eaea421 | 2019-03-06 11:58:06 -0800 | [diff] [blame] | 123 | payload_info = self.payload_to_info(inner[Raw]) |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 124 | self.info = self.packet_infos[payload_info.index] |
| 125 | self.assertEqual(payload_info.src, self.pg0.sw_if_index) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 126 | self.assertEqual( |
| 127 | scapy.compat.raw(inner), scapy.compat.raw(self.info.data[IPver]) |
| 128 | ) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 129 | |
Nobuhiro MIKI | 613e6dc | 2022-09-28 15:53:17 +0900 | [diff] [blame] | 130 | def checkCapture(self, encap, isv4, src_ip_sticky=False): |
Klement Sekera | 65cc8c0 | 2016-12-18 15:49:54 +0100 | [diff] [blame] | 131 | self.pg0.assert_nothing_captured() |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 132 | out = self.pg1.get_capture(len(self.packets)) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 133 | |
| 134 | load = [0] * len(self.ass) |
Nobuhiro MIKI | 613e6dc | 2022-09-28 15:53:17 +0900 | [diff] [blame] | 135 | sticky_as = {} |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 136 | self.info = None |
| 137 | for p in out: |
| 138 | try: |
| 139 | asid = 0 |
| 140 | gre = None |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 141 | if encap == "gre4": |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 142 | ip = p[IP] |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 143 | asid = int(ip.dst.split(".")[3]) |
| 144 | self.assertEqual(ip.version, 4) |
| 145 | self.assertEqual(ip.flags, 0) |
| 146 | self.assertEqual(ip.src, "39.40.41.42") |
| 147 | self.assertEqual(ip.dst, "10.0.0.%u" % asid) |
| 148 | self.assertEqual(ip.proto, 47) |
| 149 | self.assertEqual(len(ip.options), 0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 150 | gre = p[GRE] |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 151 | self.checkInner(gre, isv4) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 152 | elif encap == "gre6": |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 153 | ip = p[IPv6] |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 154 | asid = ip.dst.split(":") |
| 155 | asid = asid[len(asid) - 1] |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 156 | asid = 0 if asid == "" else int(asid) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 157 | self.assertEqual(ip.version, 6) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 158 | self.assertEqual(ip.tc, 0) |
| 159 | self.assertEqual(ip.fl, 0) |
| 160 | self.assertEqual(ip.src, "2004::1") |
| 161 | self.assertEqual( |
| 162 | socket.inet_pton(socket.AF_INET6, ip.dst), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 163 | socket.inet_pton(socket.AF_INET6, "2002::%u" % asid), |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 164 | ) |
| 165 | self.assertEqual(ip.nh, 47) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 166 | # self.assertEqual(len(ip.options), 0) |
Paul Vinciguerra | a7427ec | 2019-03-10 10:04:23 -0700 | [diff] [blame] | 167 | gre = GRE(scapy.compat.raw(p[IPv6].payload)) |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 168 | self.checkInner(gre, isv4) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 169 | elif encap == "l3dsr": |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 170 | ip = p[IP] |
| 171 | asid = int(ip.dst.split(".")[3]) |
| 172 | self.assertEqual(ip.version, 4) |
| 173 | self.assertEqual(ip.flags, 0) |
| 174 | self.assertEqual(ip.dst, "10.0.0.%u" % asid) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 175 | self.assertEqual(ip.tos, 0x1C) |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 176 | self.assertEqual(len(ip.options), 0) |
Hongjun Ni | 6fb0d9b | 2018-06-08 07:12:05 +0800 | [diff] [blame] | 177 | self.assert_ip_checksum_valid(p) |
| 178 | if ip.proto == IP_PROTOS.tcp: |
| 179 | self.assert_tcp_checksum_valid(p) |
| 180 | elif ip.proto == IP_PROTOS.udp: |
| 181 | self.assert_udp_checksum_valid(p) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 182 | elif encap == "nat4": |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 183 | ip = p[IP] |
| 184 | asid = int(ip.dst.split(".")[3]) |
| 185 | self.assertEqual(ip.version, 4) |
| 186 | self.assertEqual(ip.flags, 0) |
| 187 | self.assertEqual(ip.dst, "10.0.0.%u" % asid) |
| 188 | self.assertEqual(ip.proto, 17) |
| 189 | self.assertEqual(len(ip.options), 0) |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 190 | udp = p[UDP] |
| 191 | self.assertEqual(udp.dport, 3307) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 192 | elif encap == "nat6": |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 193 | ip = p[IPv6] |
| 194 | asid = ip.dst.split(":") |
| 195 | asid = asid[len(asid) - 1] |
| 196 | asid = 0 if asid == "" else int(asid) |
| 197 | self.assertEqual(ip.version, 6) |
| 198 | self.assertEqual(ip.tc, 0) |
| 199 | self.assertEqual(ip.fl, 0) |
| 200 | self.assertEqual( |
| 201 | socket.inet_pton(socket.AF_INET6, ip.dst), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 202 | socket.inet_pton(socket.AF_INET6, "2002::%u" % asid), |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 203 | ) |
| 204 | self.assertEqual(ip.nh, 17) |
| 205 | self.assertGreaterEqual(ip.hlim, 63) |
Paul Vinciguerra | a7427ec | 2019-03-10 10:04:23 -0700 | [diff] [blame] | 206 | udp = UDP(scapy.compat.raw(p[IPv6].payload)) |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 207 | self.assertEqual(udp.dport, 3307) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 208 | load[asid] += 1 |
Nobuhiro MIKI | 613e6dc | 2022-09-28 15:53:17 +0900 | [diff] [blame] | 209 | |
| 210 | # In case of source ip sticky, check that packets with same |
| 211 | # src_ip are routed to same as. |
| 212 | if src_ip_sticky and sticky_as.get(ip.src, asid) != asid: |
| 213 | raise Exception("Packets with same src_ip are routed to another as") |
| 214 | sticky_as[ip.src] = asid |
| 215 | |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 216 | except: |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 217 | self.logger.error(ppp("Unexpected or invalid packet:", p)) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 218 | raise |
| 219 | |
Paul Vinciguerra | f7f1334 | 2019-03-19 11:54:39 -0700 | [diff] [blame] | 220 | # This is just to roughly check that the balancing algorithm |
| 221 | # is not completely biased. |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 222 | for asid in self.ass: |
snaramre | ec44e26 | 2019-10-16 22:36:47 +0000 | [diff] [blame] | 223 | if load[asid] < int(len(self.packets) / (len(self.ass) * 2)): |
Gabriel Ganne | 8e66b9b | 2017-12-14 16:20:37 +0100 | [diff] [blame] | 224 | self.logger.error( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 225 | "ASS is not balanced: load[%d] = %d" % (asid, load[asid]) |
| 226 | ) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 227 | raise Exception("Load Balancer algorithm is biased") |
| 228 | |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 229 | def test_lb_ip4_gre4(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 230 | """Load Balancer IP4 GRE4 on vip case""" |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 231 | try: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 232 | self.vapi.cli("lb vip 90.0.0.0/8 encap gre4") |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 233 | for asid in self.ass: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 234 | self.vapi.cli("lb as 90.0.0.0/8 10.0.0.%u" % (asid)) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 235 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 236 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True)) |
| 237 | self.pg_enable_capture(self.pg_interfaces) |
| 238 | self.pg_start() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 239 | self.checkCapture(encap="gre4", isv4=True) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 240 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 241 | finally: |
| 242 | for asid in self.ass: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 243 | self.vapi.cli("lb as 90.0.0.0/8 10.0.0.%u del" % (asid)) |
| 244 | self.vapi.cli("lb vip 90.0.0.0/8 encap gre4 del") |
Gabriel Ganne | b3d1b20 | 2017-10-30 15:44:31 +0100 | [diff] [blame] | 245 | self.vapi.cli("test lb flowtable flush") |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 246 | |
| 247 | def test_lb_ip6_gre4(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 248 | """Load Balancer IP6 GRE4 on vip case""" |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 249 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 250 | try: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 251 | self.vapi.cli("lb vip 2001::/16 encap gre4") |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 252 | for asid in self.ass: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 253 | self.vapi.cli("lb as 2001::/16 10.0.0.%u" % (asid)) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 254 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 255 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False)) |
| 256 | self.pg_enable_capture(self.pg_interfaces) |
| 257 | self.pg_start() |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 258 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 259 | self.checkCapture(encap="gre4", isv4=False) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 260 | finally: |
| 261 | for asid in self.ass: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 262 | self.vapi.cli("lb as 2001::/16 10.0.0.%u del" % (asid)) |
| 263 | self.vapi.cli("lb vip 2001::/16 encap gre4 del") |
Gabriel Ganne | b3d1b20 | 2017-10-30 15:44:31 +0100 | [diff] [blame] | 264 | self.vapi.cli("test lb flowtable flush") |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 265 | |
| 266 | def test_lb_ip4_gre6(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 267 | """Load Balancer IP4 GRE6 on vip case""" |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 268 | try: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 269 | self.vapi.cli("lb vip 90.0.0.0/8 encap gre6") |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 270 | for asid in self.ass: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 271 | self.vapi.cli("lb as 90.0.0.0/8 2002::%u" % (asid)) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 272 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 273 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True)) |
| 274 | self.pg_enable_capture(self.pg_interfaces) |
| 275 | self.pg_start() |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 276 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 277 | self.checkCapture(encap="gre6", isv4=True) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 278 | finally: |
| 279 | for asid in self.ass: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 280 | self.vapi.cli("lb as 90.0.0.0/8 2002::%u del" % (asid)) |
| 281 | self.vapi.cli("lb vip 90.0.0.0/8 encap gre6 del") |
Gabriel Ganne | b3d1b20 | 2017-10-30 15:44:31 +0100 | [diff] [blame] | 282 | self.vapi.cli("test lb flowtable flush") |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 283 | |
| 284 | def test_lb_ip6_gre6(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 285 | """Load Balancer IP6 GRE6 on vip case""" |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 286 | try: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 287 | self.vapi.cli("lb vip 2001::/16 encap gre6") |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 288 | for asid in self.ass: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 289 | self.vapi.cli("lb as 2001::/16 2002::%u" % (asid)) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 290 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 291 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False)) |
| 292 | self.pg_enable_capture(self.pg_interfaces) |
| 293 | self.pg_start() |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 294 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 295 | self.checkCapture(encap="gre6", isv4=False) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 296 | finally: |
| 297 | for asid in self.ass: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 298 | self.vapi.cli("lb as 2001::/16 2002::%u del" % (asid)) |
| 299 | self.vapi.cli("lb vip 2001::/16 encap gre6 del") |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 300 | self.vapi.cli("test lb flowtable flush") |
| 301 | |
| 302 | def test_lb_ip4_gre4_port(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 303 | """Load Balancer IP4 GRE4 on per-port-vip case""" |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 304 | try: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 305 | self.vapi.cli("lb vip 90.0.0.0/8 protocol udp port 20000 encap gre4") |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 306 | for asid in self.ass: |
| 307 | self.vapi.cli( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 308 | "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u" % (asid) |
| 309 | ) |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 310 | |
| 311 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True)) |
| 312 | self.pg_enable_capture(self.pg_interfaces) |
| 313 | self.pg_start() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 314 | self.checkCapture(encap="gre4", isv4=True) |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 315 | |
| 316 | finally: |
| 317 | for asid in self.ass: |
| 318 | self.vapi.cli( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 319 | "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u del" % (asid) |
| 320 | ) |
| 321 | self.vapi.cli("lb vip 90.0.0.0/8 protocol udp port 20000 encap gre4 del") |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 322 | self.vapi.cli("test lb flowtable flush") |
| 323 | |
| 324 | def test_lb_ip6_gre4_port(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 325 | """Load Balancer IP6 GRE4 on per-port-vip case""" |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 326 | |
| 327 | try: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 328 | self.vapi.cli("lb vip 2001::/16 protocol udp port 20000 encap gre4") |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 329 | for asid in self.ass: |
| 330 | self.vapi.cli( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 331 | "lb as 2001::/16 protocol udp port 20000 10.0.0.%u" % (asid) |
| 332 | ) |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 333 | |
| 334 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False)) |
| 335 | self.pg_enable_capture(self.pg_interfaces) |
| 336 | self.pg_start() |
| 337 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 338 | self.checkCapture(encap="gre4", isv4=False) |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 339 | finally: |
| 340 | for asid in self.ass: |
| 341 | self.vapi.cli( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 342 | "lb as 2001::/16 protocol udp port 20000 10.0.0.%u del" % (asid) |
| 343 | ) |
| 344 | self.vapi.cli("lb vip 2001::/16 protocol udp port 20000 encap gre4 del") |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 345 | self.vapi.cli("test lb flowtable flush") |
| 346 | |
| 347 | def test_lb_ip4_gre6_port(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 348 | """Load Balancer IP4 GRE6 on per-port-vip case""" |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 349 | try: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 350 | self.vapi.cli("lb vip 90.0.0.0/8 protocol udp port 20000 encap gre6") |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 351 | for asid in self.ass: |
| 352 | self.vapi.cli( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 353 | "lb as 90.0.0.0/8 protocol udp port 20000 2002::%u" % (asid) |
| 354 | ) |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 355 | |
| 356 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True)) |
| 357 | self.pg_enable_capture(self.pg_interfaces) |
| 358 | self.pg_start() |
| 359 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 360 | self.checkCapture(encap="gre6", isv4=True) |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 361 | finally: |
| 362 | for asid in self.ass: |
| 363 | self.vapi.cli( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 364 | "lb as 90.0.0.0/8 protocol udp port 20000 2002::%u del" % (asid) |
| 365 | ) |
| 366 | self.vapi.cli("lb vip 90.0.0.0/8 protocol udp port 20000 encap gre6 del") |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 367 | self.vapi.cli("test lb flowtable flush") |
| 368 | |
| 369 | def test_lb_ip6_gre6_port(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 370 | """Load Balancer IP6 GRE6 on per-port-vip case""" |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 371 | try: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 372 | self.vapi.cli("lb vip 2001::/16 protocol udp port 20000 encap gre6") |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 373 | for asid in self.ass: |
| 374 | self.vapi.cli( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 375 | "lb as 2001::/16 protocol udp port 20000 2002::%u" % (asid) |
| 376 | ) |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 377 | |
| 378 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False)) |
| 379 | self.pg_enable_capture(self.pg_interfaces) |
| 380 | self.pg_start() |
| 381 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 382 | self.checkCapture(encap="gre6", isv4=False) |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 383 | finally: |
| 384 | for asid in self.ass: |
| 385 | self.vapi.cli( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 386 | "lb as 2001::/16 protocol udp port 20000 2002::%u del" % (asid) |
| 387 | ) |
| 388 | self.vapi.cli("lb vip 2001::/16 protocol udp port 20000 encap gre6 del") |
Gabriel Ganne | b3d1b20 | 2017-10-30 15:44:31 +0100 | [diff] [blame] | 389 | self.vapi.cli("test lb flowtable flush") |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 390 | |
| 391 | def test_lb_ip4_l3dsr(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 392 | """Load Balancer IP4 L3DSR on vip case""" |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 393 | try: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 394 | self.vapi.cli("lb vip 90.0.0.0/8 encap l3dsr dscp 7") |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 395 | for asid in self.ass: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 396 | self.vapi.cli("lb as 90.0.0.0/8 10.0.0.%u" % (asid)) |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 397 | |
| 398 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True)) |
| 399 | self.pg_enable_capture(self.pg_interfaces) |
| 400 | self.pg_start() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 401 | self.checkCapture(encap="l3dsr", isv4=True) |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 402 | |
| 403 | finally: |
| 404 | for asid in self.ass: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 405 | self.vapi.cli("lb as 90.0.0.0/8 10.0.0.%u del" % (asid)) |
| 406 | self.vapi.cli("lb vip 90.0.0.0/8 encap l3dsr dscp 7 del") |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 407 | self.vapi.cli("test lb flowtable flush") |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 408 | |
Nobuhiro MIKI | 95c2da7 | 2023-06-28 15:15:58 +0900 | [diff] [blame] | 409 | def test_lb_ip4_l3dsr_src_ip_sticky(self): |
| 410 | """Load Balancer IP4 L3DSR on vip with src_ip_sticky case""" |
| 411 | try: |
| 412 | self.vapi.cli("lb vip 90.0.0.0/8 encap l3dsr dscp 7 src_ip_sticky") |
| 413 | for asid in self.ass: |
| 414 | self.vapi.cli("lb as 90.0.0.0/8 10.0.0.%u" % (asid)) |
| 415 | |
| 416 | # Generate duplicated packets |
| 417 | pkts = self.generatePackets(self.pg0, isv4=True) |
| 418 | pkts = pkts[: len(pkts) // 2] |
| 419 | pkts = pkts + pkts |
| 420 | |
| 421 | self.pg0.add_stream(pkts) |
| 422 | self.pg_enable_capture(self.pg_interfaces) |
| 423 | self.pg_start() |
| 424 | self.checkCapture(encap="l3dsr", isv4=True, src_ip_sticky=True) |
| 425 | |
| 426 | finally: |
| 427 | for asid in self.ass: |
| 428 | self.vapi.cli("lb as 90.0.0.0/8 10.0.0.%u del" % (asid)) |
| 429 | self.vapi.cli("lb vip 90.0.0.0/8 encap l3dsr dscp 7 src_ip_sticky del") |
| 430 | self.vapi.cli("test lb flowtable flush") |
| 431 | |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 432 | def test_lb_ip4_l3dsr_port(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 433 | """Load Balancer IP4 L3DSR on per-port-vip case""" |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 434 | try: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 435 | self.vapi.cli( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 436 | "lb vip 90.0.0.0/8 protocol udp port 20000 encap l3dsr dscp 7" |
| 437 | ) |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 438 | for asid in self.ass: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 439 | self.vapi.cli( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 440 | "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u" % (asid) |
| 441 | ) |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 442 | |
| 443 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True)) |
| 444 | self.pg_enable_capture(self.pg_interfaces) |
| 445 | self.pg_start() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 446 | self.checkCapture(encap="l3dsr", isv4=True) |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 447 | |
| 448 | finally: |
| 449 | for asid in self.ass: |
| 450 | self.vapi.cli( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 451 | "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u del" % (asid) |
| 452 | ) |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 453 | self.vapi.cli( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 454 | "lb vip 90.0.0.0/8 protocol udp port 20000 encap l3dsr dscp 7 del" |
| 455 | ) |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 456 | self.vapi.cli("test lb flowtable flush") |
| 457 | |
Nobuhiro MIKI | 613e6dc | 2022-09-28 15:53:17 +0900 | [diff] [blame] | 458 | def test_lb_ip4_l3dsr_port_src_ip_sticky(self): |
| 459 | """Load Balancer IP4 L3DSR on per-port-vip with src_ip_sticky case""" |
| 460 | try: |
Nobuhiro MIKI | 95c2da7 | 2023-06-28 15:15:58 +0900 | [diff] [blame] | 461 | # This VIP at port 1000 does not receive packets, but is defined |
| 462 | # as a dummy to verify that the src_ip_sticky flag can be set |
| 463 | # independently for each port. |
| 464 | self.vapi.cli( |
| 465 | "lb vip 90.0.0.0/8 protocol udp port 10000 encap l3dsr dscp 7" |
| 466 | ) |
Nobuhiro MIKI | 613e6dc | 2022-09-28 15:53:17 +0900 | [diff] [blame] | 467 | self.vapi.cli( |
| 468 | "lb vip 90.0.0.0/8 protocol udp port 20000 encap l3dsr dscp 7 src_ip_sticky" |
| 469 | ) |
| 470 | for asid in self.ass: |
| 471 | self.vapi.cli( |
| 472 | "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u" % (asid) |
| 473 | ) |
| 474 | |
| 475 | # Generate duplicated packets |
| 476 | pkts = self.generatePackets(self.pg0, isv4=True) |
| 477 | pkts = pkts[: len(pkts) // 2] |
| 478 | pkts = pkts + pkts |
| 479 | |
| 480 | self.pg0.add_stream(pkts) |
| 481 | self.pg_enable_capture(self.pg_interfaces) |
| 482 | self.pg_start() |
| 483 | self.checkCapture(encap="l3dsr", isv4=True, src_ip_sticky=True) |
| 484 | |
| 485 | finally: |
| 486 | for asid in self.ass: |
| 487 | self.vapi.cli( |
| 488 | "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u del" % (asid) |
| 489 | ) |
| 490 | self.vapi.cli( |
| 491 | "lb vip 90.0.0.0/8 protocol udp port 20000 encap l3dsr dscp 7 src_ip_sticky del" |
| 492 | ) |
Nobuhiro MIKI | 95c2da7 | 2023-06-28 15:15:58 +0900 | [diff] [blame] | 493 | self.vapi.cli( |
| 494 | "lb vip 90.0.0.0/8 protocol udp port 10000 encap l3dsr dscp 7 del" |
| 495 | ) |
Nobuhiro MIKI | 613e6dc | 2022-09-28 15:53:17 +0900 | [diff] [blame] | 496 | self.vapi.cli("test lb flowtable flush") |
| 497 | |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 498 | def test_lb_ip4_nat4_port(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 499 | """Load Balancer IP4 NAT4 on per-port-vip case""" |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 500 | try: |
| 501 | self.vapi.cli( |
| 502 | "lb vip 90.0.0.0/8 protocol udp port 20000 encap nat4" |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 503 | " type clusterip target_port 3307" |
| 504 | ) |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 505 | for asid in self.ass: |
| 506 | self.vapi.cli( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 507 | "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u" % (asid) |
| 508 | ) |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 509 | |
| 510 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True)) |
| 511 | self.pg_enable_capture(self.pg_interfaces) |
| 512 | self.pg_start() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 513 | self.checkCapture(encap="nat4", isv4=True) |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 514 | |
| 515 | finally: |
| 516 | for asid in self.ass: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 517 | self.vapi.cli( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 518 | "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u del" % (asid) |
| 519 | ) |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 520 | self.vapi.cli( |
| 521 | "lb vip 90.0.0.0/8 protocol udp port 20000 encap nat4" |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 522 | " type clusterip target_port 3307 del" |
| 523 | ) |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 524 | self.vapi.cli("test lb flowtable flush") |
| 525 | |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 526 | def test_lb_ip6_nat6_port(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 527 | """Load Balancer IP6 NAT6 on per-port-vip case""" |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 528 | try: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 529 | self.vapi.cli( |
| 530 | "lb vip 2001::/16 protocol udp port 20000 encap nat6" |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 531 | " type clusterip target_port 3307" |
| 532 | ) |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 533 | for asid in self.ass: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 534 | self.vapi.cli( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 535 | "lb as 2001::/16 protocol udp port 20000 2002::%u" % (asid) |
| 536 | ) |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 537 | |
| 538 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False)) |
| 539 | self.pg_enable_capture(self.pg_interfaces) |
| 540 | self.pg_start() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 541 | self.checkCapture(encap="nat6", isv4=False) |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 542 | |
| 543 | finally: |
| 544 | for asid in self.ass: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 545 | self.vapi.cli( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 546 | "lb as 2001::/16 protocol udp port 20000 2002::%u del" % (asid) |
| 547 | ) |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 548 | self.vapi.cli( |
| 549 | "lb vip 2001::/16 protocol udp port 20000 encap nat6" |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 550 | " type clusterip target_port 3307 del" |
| 551 | ) |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 552 | self.vapi.cli("test lb flowtable flush") |