blob: dca9ea3f7ef6ea72cba90d38337d8150c2c574fd [file] [log] [blame]
Pierre Pfisterf588f352016-10-07 16:31:57 +01001import socket
Pierre Pfisterf588f352016-10-07 16:31:57 +01002
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -07003import scapy.compat
Pierre Pfisterf588f352016-10-07 16:31:57 +01004from scapy.layers.inet import IP, UDP
Klement Sekera65cc8c02016-12-18 15:49:54 +01005from scapy.layers.inet6 import IPv6
Klement Sekeraf62ae122016-10-11 11:47:09 +02006from scapy.layers.l2 import Ether, GRE
7from scapy.packet import Raw
Hongjun Ni6fb0d9b2018-06-08 07:12:05 +08008from scapy.data import IP_PROTOS
Pierre Pfisterf588f352016-10-07 16:31:57 +01009
Klement Sekeraf62ae122016-10-11 11:47:09 +020010from framework import VppTestCase
Klement Sekera7bb873a2016-11-18 07:38:42 +010011from util import ppp
Neale Ranns097fa662018-05-01 05:17:55 -070012from vpp_ip_route import VppIpRoute, VppRoutePath
13from vpp_ip import INVALID_INDEX
Klement Sekeraf62ae122016-10-11 11:47:09 +020014
15""" TestLB is a subclass of VPPTestCase classes.
16
17 TestLB class defines Load Balancer test cases for:
Hongjun Ni219cc902018-06-28 20:14:19 +080018 - IP4 to GRE4 encap on per-port vip case
19 - IP4 to GRE6 encap on per-port vip case
20 - IP6 to GRE4 encap on per-port vip case
21 - IP6 to GRE6 encap on per-port vip case
22 - IP4 to L3DSR encap on vip case
23 - IP4 to L3DSR encap on per-port vip case
24 - IP4 to NAT4 encap on per-port vip case
25 - IP6 to NAT6 encap on per-port vip case
Klement Sekeraf62ae122016-10-11 11:47:09 +020026
27 As stated in comments below, GRE has issues with IPv6.
28 All test cases involving IPv6 are executed, but
29 received packets are not parsed and checked.
30
31"""
32
33
34class TestLB(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020035 """Load Balancer Test Case"""
Pierre Pfisterf588f352016-10-07 16:31:57 +010036
37 @classmethod
38 def setUpClass(cls):
39 super(TestLB, cls).setUpClass()
40
41 cls.ass = range(5)
Hongjun Ni219cc902018-06-28 20:14:19 +080042 cls.packets = range(1)
Pierre Pfisterf588f352016-10-07 16:31:57 +010043
44 try:
Klement Sekeraf62ae122016-10-11 11:47:09 +020045 cls.create_pg_interfaces(range(2))
46 cls.interfaces = list(cls.pg_interfaces)
Pierre Pfisterf588f352016-10-07 16:31:57 +010047
Klement Sekeraf62ae122016-10-11 11:47:09 +020048 for i in cls.interfaces:
49 i.admin_up()
50 i.config_ip4()
51 i.config_ip6()
52 i.disable_ipv6_ra()
53 i.resolve_arp()
54 i.resolve_ndp()
Neale Ranns097fa662018-05-01 05:17:55 -070055
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020056 dst4 = VppIpRoute(
57 cls,
58 "10.0.0.0",
59 24,
60 [VppRoutePath(cls.pg1.remote_ip4, INVALID_INDEX)],
61 register=False,
62 )
Neale Ranns097fa662018-05-01 05:17:55 -070063 dst4.add_vpp_config()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020064 dst6 = VppIpRoute(
65 cls,
66 "2002::",
67 16,
68 [VppRoutePath(cls.pg1.remote_ip6, INVALID_INDEX)],
69 register=False,
70 )
Neale Ranns097fa662018-05-01 05:17:55 -070071 dst6.add_vpp_config()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020072 cls.vapi.lb_conf(ip4_src_address="39.40.41.42", ip6_src_address="2004::1")
Klement Sekeraf62ae122016-10-11 11:47:09 +020073 except Exception:
Pierre Pfisterf588f352016-10-07 16:31:57 +010074 super(TestLB, cls).tearDownClass()
75 raise
76
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070077 @classmethod
78 def tearDownClass(cls):
79 super(TestLB, cls).tearDownClass()
80
Pierre Pfisterf588f352016-10-07 16:31:57 +010081 def tearDown(self):
Klement Sekeraf62ae122016-10-11 11:47:09 +020082 super(TestLB, self).tearDown()
Paul Vinciguerra90cf21b2019-03-13 09:23:05 -070083
84 def show_commands_at_teardown(self):
85 self.logger.info(self.vapi.cli("show lb vip verbose"))
Pierre Pfisterf588f352016-10-07 16:31:57 +010086
87 def getIPv4Flow(self, id):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020088 return IP(
89 dst="90.0.%u.%u" % (id / 255, id % 255),
90 src="40.0.%u.%u" % (id / 255, id % 255),
91 ) / UDP(sport=10000 + id, dport=20000)
Pierre Pfisterf588f352016-10-07 16:31:57 +010092
93 def getIPv6Flow(self, id):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020094 return IPv6(dst="2001::%u" % (id), src="fd00:f00d:ffff::%u" % (id)) / UDP(
95 sport=10000 + id, dport=20000
96 )
Pierre Pfisterf588f352016-10-07 16:31:57 +010097
Klement Sekeraf62ae122016-10-11 11:47:09 +020098 def generatePackets(self, src_if, isv4):
Klement Sekeradab231a2016-12-21 08:50:14 +010099 self.reset_packet_infos()
Pierre Pfisterf588f352016-10-07 16:31:57 +0100100 pkts = []
101 for pktid in self.packets:
Klement Sekeradab231a2016-12-21 08:50:14 +0100102 info = self.create_packet_info(src_if, self.pg1)
Pierre Pfisterf588f352016-10-07 16:31:57 +0100103 payload = self.info_to_payload(info)
104 ip = self.getIPv4Flow(pktid) if isv4 else self.getIPv6Flow(pktid)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200105 packet = (
106 Ether(dst=src_if.local_mac, src=src_if.remote_mac) / ip / Raw(payload)
107 )
Pierre Pfisterf588f352016-10-07 16:31:57 +0100108 self.extend_packet(packet, 128)
109 info.data = packet.copy()
110 pkts.append(packet)
111 return pkts
112
113 def checkInner(self, gre, isv4):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200114 IPver = IP if isv4 else IPv6
Pierre Pfisterf588f352016-10-07 16:31:57 +0100115 self.assertEqual(gre.proto, 0x0800 if isv4 else 0x86DD)
116 self.assertEqual(gre.flags, 0)
117 self.assertEqual(gre.version, 0)
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700118 inner = IPver(scapy.compat.raw(gre.payload))
Paul Vinciguerraeaea4212019-03-06 11:58:06 -0800119 payload_info = self.payload_to_info(inner[Raw])
Klement Sekeradab231a2016-12-21 08:50:14 +0100120 self.info = self.packet_infos[payload_info.index]
121 self.assertEqual(payload_info.src, self.pg0.sw_if_index)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200122 self.assertEqual(
123 scapy.compat.raw(inner), scapy.compat.raw(self.info.data[IPver])
124 )
Pierre Pfisterf588f352016-10-07 16:31:57 +0100125
Hongjun Ni647f6092018-01-23 19:17:23 +0800126 def checkCapture(self, encap, isv4):
Klement Sekera65cc8c02016-12-18 15:49:54 +0100127 self.pg0.assert_nothing_captured()
Klement Sekeradab231a2016-12-21 08:50:14 +0100128 out = self.pg1.get_capture(len(self.packets))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100129
130 load = [0] * len(self.ass)
131 self.info = None
132 for p in out:
133 try:
134 asid = 0
135 gre = None
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200136 if encap == "gre4":
Pierre Pfisterf588f352016-10-07 16:31:57 +0100137 ip = p[IP]
Pierre Pfisterf588f352016-10-07 16:31:57 +0100138 asid = int(ip.dst.split(".")[3])
139 self.assertEqual(ip.version, 4)
140 self.assertEqual(ip.flags, 0)
141 self.assertEqual(ip.src, "39.40.41.42")
142 self.assertEqual(ip.dst, "10.0.0.%u" % asid)
143 self.assertEqual(ip.proto, 47)
144 self.assertEqual(len(ip.options), 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200145 gre = p[GRE]
Hongjun Ni647f6092018-01-23 19:17:23 +0800146 self.checkInner(gre, isv4)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200147 elif encap == "gre6":
Pierre Pfisterf588f352016-10-07 16:31:57 +0100148 ip = p[IPv6]
Pierre Pfisterf588f352016-10-07 16:31:57 +0100149 asid = ip.dst.split(":")
150 asid = asid[len(asid) - 1]
Klement Sekeraf62ae122016-10-11 11:47:09 +0200151 asid = 0 if asid == "" else int(asid)
Pierre Pfisterf588f352016-10-07 16:31:57 +0100152 self.assertEqual(ip.version, 6)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200153 self.assertEqual(ip.tc, 0)
154 self.assertEqual(ip.fl, 0)
155 self.assertEqual(ip.src, "2004::1")
156 self.assertEqual(
157 socket.inet_pton(socket.AF_INET6, ip.dst),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200158 socket.inet_pton(socket.AF_INET6, "2002::%u" % asid),
Klement Sekeraf62ae122016-10-11 11:47:09 +0200159 )
160 self.assertEqual(ip.nh, 47)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200161 # self.assertEqual(len(ip.options), 0)
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700162 gre = GRE(scapy.compat.raw(p[IPv6].payload))
Hongjun Ni647f6092018-01-23 19:17:23 +0800163 self.checkInner(gre, isv4)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200164 elif encap == "l3dsr":
Hongjun Ni647f6092018-01-23 19:17:23 +0800165 ip = p[IP]
166 asid = int(ip.dst.split(".")[3])
167 self.assertEqual(ip.version, 4)
168 self.assertEqual(ip.flags, 0)
169 self.assertEqual(ip.dst, "10.0.0.%u" % asid)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200170 self.assertEqual(ip.tos, 0x1C)
Hongjun Ni647f6092018-01-23 19:17:23 +0800171 self.assertEqual(len(ip.options), 0)
Hongjun Ni6fb0d9b2018-06-08 07:12:05 +0800172 self.assert_ip_checksum_valid(p)
173 if ip.proto == IP_PROTOS.tcp:
174 self.assert_tcp_checksum_valid(p)
175 elif ip.proto == IP_PROTOS.udp:
176 self.assert_udp_checksum_valid(p)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200177 elif encap == "nat4":
Hongjun Nid92a0b52018-02-06 23:00:22 +0800178 ip = p[IP]
179 asid = int(ip.dst.split(".")[3])
180 self.assertEqual(ip.version, 4)
181 self.assertEqual(ip.flags, 0)
182 self.assertEqual(ip.dst, "10.0.0.%u" % asid)
183 self.assertEqual(ip.proto, 17)
184 self.assertEqual(len(ip.options), 0)
Hongjun Nid92a0b52018-02-06 23:00:22 +0800185 udp = p[UDP]
186 self.assertEqual(udp.dport, 3307)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200187 elif encap == "nat6":
Hongjun Nid92a0b52018-02-06 23:00:22 +0800188 ip = p[IPv6]
189 asid = ip.dst.split(":")
190 asid = asid[len(asid) - 1]
191 asid = 0 if asid == "" else int(asid)
192 self.assertEqual(ip.version, 6)
193 self.assertEqual(ip.tc, 0)
194 self.assertEqual(ip.fl, 0)
195 self.assertEqual(
196 socket.inet_pton(socket.AF_INET6, ip.dst),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200197 socket.inet_pton(socket.AF_INET6, "2002::%u" % asid),
Hongjun Nid92a0b52018-02-06 23:00:22 +0800198 )
199 self.assertEqual(ip.nh, 17)
200 self.assertGreaterEqual(ip.hlim, 63)
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700201 udp = UDP(scapy.compat.raw(p[IPv6].payload))
Hongjun Nid92a0b52018-02-06 23:00:22 +0800202 self.assertEqual(udp.dport, 3307)
Pierre Pfisterf588f352016-10-07 16:31:57 +0100203 load[asid] += 1
204 except:
Klement Sekera7bb873a2016-11-18 07:38:42 +0100205 self.logger.error(ppp("Unexpected or invalid packet:", p))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100206 raise
207
Paul Vinciguerraf7f13342019-03-19 11:54:39 -0700208 # This is just to roughly check that the balancing algorithm
209 # is not completely biased.
Pierre Pfisterf588f352016-10-07 16:31:57 +0100210 for asid in self.ass:
snaramreec44e262019-10-16 22:36:47 +0000211 if load[asid] < int(len(self.packets) / (len(self.ass) * 2)):
Gabriel Ganne8e66b9b2017-12-14 16:20:37 +0100212 self.logger.error(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200213 "ASS is not balanced: load[%d] = %d" % (asid, load[asid])
214 )
Pierre Pfisterf588f352016-10-07 16:31:57 +0100215 raise Exception("Load Balancer algorithm is biased")
216
Pierre Pfisterf588f352016-10-07 16:31:57 +0100217 def test_lb_ip4_gre4(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200218 """Load Balancer IP4 GRE4 on vip case"""
Klement Sekeraf62ae122016-10-11 11:47:09 +0200219 try:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200220 self.vapi.cli("lb vip 90.0.0.0/8 encap gre4")
Klement Sekeraf62ae122016-10-11 11:47:09 +0200221 for asid in self.ass:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200222 self.vapi.cli("lb as 90.0.0.0/8 10.0.0.%u" % (asid))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100223
Klement Sekeraf62ae122016-10-11 11:47:09 +0200224 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
225 self.pg_enable_capture(self.pg_interfaces)
226 self.pg_start()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200227 self.checkCapture(encap="gre4", isv4=True)
Pierre Pfisterf588f352016-10-07 16:31:57 +0100228
Klement Sekeraf62ae122016-10-11 11:47:09 +0200229 finally:
230 for asid in self.ass:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200231 self.vapi.cli("lb as 90.0.0.0/8 10.0.0.%u del" % (asid))
232 self.vapi.cli("lb vip 90.0.0.0/8 encap gre4 del")
Gabriel Ganneb3d1b202017-10-30 15:44:31 +0100233 self.vapi.cli("test lb flowtable flush")
Pierre Pfisterf588f352016-10-07 16:31:57 +0100234
235 def test_lb_ip6_gre4(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200236 """Load Balancer IP6 GRE4 on vip case"""
Pierre Pfisterf588f352016-10-07 16:31:57 +0100237
Klement Sekeraf62ae122016-10-11 11:47:09 +0200238 try:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200239 self.vapi.cli("lb vip 2001::/16 encap gre4")
Klement Sekeraf62ae122016-10-11 11:47:09 +0200240 for asid in self.ass:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200241 self.vapi.cli("lb as 2001::/16 10.0.0.%u" % (asid))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100242
Klement Sekeraf62ae122016-10-11 11:47:09 +0200243 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
244 self.pg_enable_capture(self.pg_interfaces)
245 self.pg_start()
Pierre Pfisterf588f352016-10-07 16:31:57 +0100246
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200247 self.checkCapture(encap="gre4", isv4=False)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200248 finally:
249 for asid in self.ass:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200250 self.vapi.cli("lb as 2001::/16 10.0.0.%u del" % (asid))
251 self.vapi.cli("lb vip 2001::/16 encap gre4 del")
Gabriel Ganneb3d1b202017-10-30 15:44:31 +0100252 self.vapi.cli("test lb flowtable flush")
Pierre Pfisterf588f352016-10-07 16:31:57 +0100253
254 def test_lb_ip4_gre6(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200255 """Load Balancer IP4 GRE6 on vip case"""
Klement Sekeraf62ae122016-10-11 11:47:09 +0200256 try:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200257 self.vapi.cli("lb vip 90.0.0.0/8 encap gre6")
Klement Sekeraf62ae122016-10-11 11:47:09 +0200258 for asid in self.ass:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200259 self.vapi.cli("lb as 90.0.0.0/8 2002::%u" % (asid))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100260
Klement Sekeraf62ae122016-10-11 11:47:09 +0200261 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
262 self.pg_enable_capture(self.pg_interfaces)
263 self.pg_start()
Pierre Pfisterf588f352016-10-07 16:31:57 +0100264
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200265 self.checkCapture(encap="gre6", isv4=True)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200266 finally:
267 for asid in self.ass:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200268 self.vapi.cli("lb as 90.0.0.0/8 2002::%u del" % (asid))
269 self.vapi.cli("lb vip 90.0.0.0/8 encap gre6 del")
Gabriel Ganneb3d1b202017-10-30 15:44:31 +0100270 self.vapi.cli("test lb flowtable flush")
Pierre Pfisterf588f352016-10-07 16:31:57 +0100271
272 def test_lb_ip6_gre6(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200273 """Load Balancer IP6 GRE6 on vip case"""
Klement Sekeraf62ae122016-10-11 11:47:09 +0200274 try:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200275 self.vapi.cli("lb vip 2001::/16 encap gre6")
Klement Sekeraf62ae122016-10-11 11:47:09 +0200276 for asid in self.ass:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200277 self.vapi.cli("lb as 2001::/16 2002::%u" % (asid))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100278
Klement Sekeraf62ae122016-10-11 11:47:09 +0200279 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
280 self.pg_enable_capture(self.pg_interfaces)
281 self.pg_start()
Pierre Pfisterf588f352016-10-07 16:31:57 +0100282
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200283 self.checkCapture(encap="gre6", isv4=False)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200284 finally:
285 for asid in self.ass:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200286 self.vapi.cli("lb as 2001::/16 2002::%u del" % (asid))
287 self.vapi.cli("lb vip 2001::/16 encap gre6 del")
Hongjun Ni219cc902018-06-28 20:14:19 +0800288 self.vapi.cli("test lb flowtable flush")
289
290 def test_lb_ip4_gre4_port(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200291 """Load Balancer IP4 GRE4 on per-port-vip case"""
Hongjun Ni219cc902018-06-28 20:14:19 +0800292 try:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200293 self.vapi.cli("lb vip 90.0.0.0/8 protocol udp port 20000 encap gre4")
Hongjun Ni219cc902018-06-28 20:14:19 +0800294 for asid in self.ass:
295 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200296 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u" % (asid)
297 )
Hongjun Ni219cc902018-06-28 20:14:19 +0800298
299 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
300 self.pg_enable_capture(self.pg_interfaces)
301 self.pg_start()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200302 self.checkCapture(encap="gre4", isv4=True)
Hongjun Ni219cc902018-06-28 20:14:19 +0800303
304 finally:
305 for asid in self.ass:
306 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200307 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u del" % (asid)
308 )
309 self.vapi.cli("lb vip 90.0.0.0/8 protocol udp port 20000 encap gre4 del")
Hongjun Ni219cc902018-06-28 20:14:19 +0800310 self.vapi.cli("test lb flowtable flush")
311
312 def test_lb_ip6_gre4_port(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200313 """Load Balancer IP6 GRE4 on per-port-vip case"""
Hongjun Ni219cc902018-06-28 20:14:19 +0800314
315 try:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200316 self.vapi.cli("lb vip 2001::/16 protocol udp port 20000 encap gre4")
Hongjun Ni219cc902018-06-28 20:14:19 +0800317 for asid in self.ass:
318 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200319 "lb as 2001::/16 protocol udp port 20000 10.0.0.%u" % (asid)
320 )
Hongjun Ni219cc902018-06-28 20:14:19 +0800321
322 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
323 self.pg_enable_capture(self.pg_interfaces)
324 self.pg_start()
325
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200326 self.checkCapture(encap="gre4", isv4=False)
Hongjun Ni219cc902018-06-28 20:14:19 +0800327 finally:
328 for asid in self.ass:
329 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200330 "lb as 2001::/16 protocol udp port 20000 10.0.0.%u del" % (asid)
331 )
332 self.vapi.cli("lb vip 2001::/16 protocol udp port 20000 encap gre4 del")
Hongjun Ni219cc902018-06-28 20:14:19 +0800333 self.vapi.cli("test lb flowtable flush")
334
335 def test_lb_ip4_gre6_port(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200336 """Load Balancer IP4 GRE6 on per-port-vip case"""
Hongjun Ni219cc902018-06-28 20:14:19 +0800337 try:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200338 self.vapi.cli("lb vip 90.0.0.0/8 protocol udp port 20000 encap gre6")
Hongjun Ni219cc902018-06-28 20:14:19 +0800339 for asid in self.ass:
340 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200341 "lb as 90.0.0.0/8 protocol udp port 20000 2002::%u" % (asid)
342 )
Hongjun Ni219cc902018-06-28 20:14:19 +0800343
344 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
345 self.pg_enable_capture(self.pg_interfaces)
346 self.pg_start()
347
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200348 self.checkCapture(encap="gre6", isv4=True)
Hongjun Ni219cc902018-06-28 20:14:19 +0800349 finally:
350 for asid in self.ass:
351 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200352 "lb as 90.0.0.0/8 protocol udp port 20000 2002::%u del" % (asid)
353 )
354 self.vapi.cli("lb vip 90.0.0.0/8 protocol udp port 20000 encap gre6 del")
Hongjun Ni219cc902018-06-28 20:14:19 +0800355 self.vapi.cli("test lb flowtable flush")
356
357 def test_lb_ip6_gre6_port(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200358 """Load Balancer IP6 GRE6 on per-port-vip case"""
Hongjun Ni219cc902018-06-28 20:14:19 +0800359 try:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200360 self.vapi.cli("lb vip 2001::/16 protocol udp port 20000 encap gre6")
Hongjun Ni219cc902018-06-28 20:14:19 +0800361 for asid in self.ass:
362 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200363 "lb as 2001::/16 protocol udp port 20000 2002::%u" % (asid)
364 )
Hongjun Ni219cc902018-06-28 20:14:19 +0800365
366 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
367 self.pg_enable_capture(self.pg_interfaces)
368 self.pg_start()
369
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200370 self.checkCapture(encap="gre6", isv4=False)
Hongjun Ni219cc902018-06-28 20:14:19 +0800371 finally:
372 for asid in self.ass:
373 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200374 "lb as 2001::/16 protocol udp port 20000 2002::%u del" % (asid)
375 )
376 self.vapi.cli("lb vip 2001::/16 protocol udp port 20000 encap gre6 del")
Gabriel Ganneb3d1b202017-10-30 15:44:31 +0100377 self.vapi.cli("test lb flowtable flush")
Hongjun Ni647f6092018-01-23 19:17:23 +0800378
379 def test_lb_ip4_l3dsr(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200380 """Load Balancer IP4 L3DSR on vip case"""
Hongjun Ni647f6092018-01-23 19:17:23 +0800381 try:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200382 self.vapi.cli("lb vip 90.0.0.0/8 encap l3dsr dscp 7")
Hongjun Ni647f6092018-01-23 19:17:23 +0800383 for asid in self.ass:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200384 self.vapi.cli("lb as 90.0.0.0/8 10.0.0.%u" % (asid))
Hongjun Ni647f6092018-01-23 19:17:23 +0800385
386 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
387 self.pg_enable_capture(self.pg_interfaces)
388 self.pg_start()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200389 self.checkCapture(encap="l3dsr", isv4=True)
Hongjun Ni647f6092018-01-23 19:17:23 +0800390
391 finally:
392 for asid in self.ass:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200393 self.vapi.cli("lb as 90.0.0.0/8 10.0.0.%u del" % (asid))
394 self.vapi.cli("lb vip 90.0.0.0/8 encap l3dsr dscp 7 del")
Hongjun Ni647f6092018-01-23 19:17:23 +0800395 self.vapi.cli("test lb flowtable flush")
Hongjun Nid92a0b52018-02-06 23:00:22 +0800396
Hongjun Ni219cc902018-06-28 20:14:19 +0800397 def test_lb_ip4_l3dsr_port(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200398 """Load Balancer IP4 L3DSR on per-port-vip case"""
Hongjun Nid92a0b52018-02-06 23:00:22 +0800399 try:
Hongjun Ni219cc902018-06-28 20:14:19 +0800400 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200401 "lb vip 90.0.0.0/8 protocol udp port 20000 encap l3dsr dscp 7"
402 )
Hongjun Nid92a0b52018-02-06 23:00:22 +0800403 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800404 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200405 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u" % (asid)
406 )
Hongjun Ni219cc902018-06-28 20:14:19 +0800407
408 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
409 self.pg_enable_capture(self.pg_interfaces)
410 self.pg_start()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200411 self.checkCapture(encap="l3dsr", isv4=True)
Hongjun Ni219cc902018-06-28 20:14:19 +0800412
413 finally:
414 for asid in self.ass:
415 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200416 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u del" % (asid)
417 )
Hongjun Ni219cc902018-06-28 20:14:19 +0800418 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200419 "lb vip 90.0.0.0/8 protocol udp port 20000 encap l3dsr dscp 7 del"
420 )
Hongjun Ni219cc902018-06-28 20:14:19 +0800421 self.vapi.cli("test lb flowtable flush")
422
423 def test_lb_ip4_nat4_port(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200424 """Load Balancer IP4 NAT4 on per-port-vip case"""
Hongjun Ni219cc902018-06-28 20:14:19 +0800425 try:
426 self.vapi.cli(
427 "lb vip 90.0.0.0/8 protocol udp port 20000 encap nat4"
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200428 " type clusterip target_port 3307"
429 )
Hongjun Ni219cc902018-06-28 20:14:19 +0800430 for asid in self.ass:
431 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200432 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u" % (asid)
433 )
Hongjun Nid92a0b52018-02-06 23:00:22 +0800434
435 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
436 self.pg_enable_capture(self.pg_interfaces)
437 self.pg_start()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200438 self.checkCapture(encap="nat4", isv4=True)
Hongjun Nid92a0b52018-02-06 23:00:22 +0800439
440 finally:
441 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800442 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200443 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u del" % (asid)
444 )
Hongjun Ni219cc902018-06-28 20:14:19 +0800445 self.vapi.cli(
446 "lb vip 90.0.0.0/8 protocol udp port 20000 encap nat4"
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200447 " type clusterip target_port 3307 del"
448 )
Hongjun Nid92a0b52018-02-06 23:00:22 +0800449 self.vapi.cli("test lb flowtable flush")
450
Hongjun Ni219cc902018-06-28 20:14:19 +0800451 def test_lb_ip6_nat6_port(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200452 """Load Balancer IP6 NAT6 on per-port-vip case"""
Hongjun Nid92a0b52018-02-06 23:00:22 +0800453 try:
Hongjun Ni219cc902018-06-28 20:14:19 +0800454 self.vapi.cli(
455 "lb vip 2001::/16 protocol udp port 20000 encap nat6"
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200456 " type clusterip target_port 3307"
457 )
Hongjun Nid92a0b52018-02-06 23:00:22 +0800458 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800459 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200460 "lb as 2001::/16 protocol udp port 20000 2002::%u" % (asid)
461 )
Hongjun Nid92a0b52018-02-06 23:00:22 +0800462
463 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
464 self.pg_enable_capture(self.pg_interfaces)
465 self.pg_start()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200466 self.checkCapture(encap="nat6", isv4=False)
Hongjun Nid92a0b52018-02-06 23:00:22 +0800467
468 finally:
469 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800470 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200471 "lb as 2001::/16 protocol udp port 20000 2002::%u del" % (asid)
472 )
Hongjun Ni219cc902018-06-28 20:14:19 +0800473 self.vapi.cli(
474 "lb vip 2001::/16 protocol udp port 20000 encap nat6"
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200475 " type clusterip target_port 3307 del"
476 )
Hongjun Nid92a0b52018-02-06 23:00:22 +0800477 self.vapi.cli("test lb flowtable flush")