blob: 6e8d82dfe40f480b77cea044ec717c4d7f9e4dca [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
Nobuhiro MIKI613e6dc2022-09-28 15:53:17 +090024 - IP4 to L3DSR encap on per-port vip with src_ip_sticky case
Hongjun Ni219cc902018-06-28 20:14:19 +080025 - IP4 to NAT4 encap on per-port vip case
26 - IP6 to NAT6 encap on per-port vip case
Klement Sekeraf62ae122016-10-11 11:47:09 +020027
28 As stated in comments below, GRE has issues with IPv6.
29 All test cases involving IPv6 are executed, but
30 received packets are not parsed and checked.
31
32"""
33
34
35class TestLB(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020036 """Load Balancer Test Case"""
Pierre Pfisterf588f352016-10-07 16:31:57 +010037
38 @classmethod
39 def setUpClass(cls):
40 super(TestLB, cls).setUpClass()
41
42 cls.ass = range(5)
Nobuhiro MIKI613e6dc2022-09-28 15:53:17 +090043 cls.packets = range(100)
Pierre Pfisterf588f352016-10-07 16:31:57 +010044
45 try:
Klement Sekeraf62ae122016-10-11 11:47:09 +020046 cls.create_pg_interfaces(range(2))
47 cls.interfaces = list(cls.pg_interfaces)
Pierre Pfisterf588f352016-10-07 16:31:57 +010048
Klement Sekeraf62ae122016-10-11 11:47:09 +020049 for i in cls.interfaces:
50 i.admin_up()
51 i.config_ip4()
52 i.config_ip6()
53 i.disable_ipv6_ra()
54 i.resolve_arp()
55 i.resolve_ndp()
Neale Ranns097fa662018-05-01 05:17:55 -070056
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020057 dst4 = VppIpRoute(
58 cls,
59 "10.0.0.0",
60 24,
61 [VppRoutePath(cls.pg1.remote_ip4, INVALID_INDEX)],
62 register=False,
63 )
Neale Ranns097fa662018-05-01 05:17:55 -070064 dst4.add_vpp_config()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020065 dst6 = VppIpRoute(
66 cls,
67 "2002::",
68 16,
69 [VppRoutePath(cls.pg1.remote_ip6, INVALID_INDEX)],
70 register=False,
71 )
Neale Ranns097fa662018-05-01 05:17:55 -070072 dst6.add_vpp_config()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020073 cls.vapi.lb_conf(ip4_src_address="39.40.41.42", ip6_src_address="2004::1")
Klement Sekeraf62ae122016-10-11 11:47:09 +020074 except Exception:
Pierre Pfisterf588f352016-10-07 16:31:57 +010075 super(TestLB, cls).tearDownClass()
76 raise
77
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070078 @classmethod
79 def tearDownClass(cls):
80 super(TestLB, cls).tearDownClass()
81
Pierre Pfisterf588f352016-10-07 16:31:57 +010082 def tearDown(self):
Klement Sekeraf62ae122016-10-11 11:47:09 +020083 super(TestLB, self).tearDown()
Paul Vinciguerra90cf21b2019-03-13 09:23:05 -070084
85 def show_commands_at_teardown(self):
86 self.logger.info(self.vapi.cli("show lb vip verbose"))
Pierre Pfisterf588f352016-10-07 16:31:57 +010087
88 def getIPv4Flow(self, id):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020089 return IP(
90 dst="90.0.%u.%u" % (id / 255, id % 255),
91 src="40.0.%u.%u" % (id / 255, id % 255),
92 ) / UDP(sport=10000 + id, dport=20000)
Pierre Pfisterf588f352016-10-07 16:31:57 +010093
94 def getIPv6Flow(self, id):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020095 return IPv6(dst="2001::%u" % (id), src="fd00:f00d:ffff::%u" % (id)) / UDP(
96 sport=10000 + id, dport=20000
97 )
Pierre Pfisterf588f352016-10-07 16:31:57 +010098
Klement Sekeraf62ae122016-10-11 11:47:09 +020099 def generatePackets(self, src_if, isv4):
Klement Sekeradab231a2016-12-21 08:50:14 +0100100 self.reset_packet_infos()
Pierre Pfisterf588f352016-10-07 16:31:57 +0100101 pkts = []
102 for pktid in self.packets:
Klement Sekeradab231a2016-12-21 08:50:14 +0100103 info = self.create_packet_info(src_if, self.pg1)
Pierre Pfisterf588f352016-10-07 16:31:57 +0100104 payload = self.info_to_payload(info)
105 ip = self.getIPv4Flow(pktid) if isv4 else self.getIPv6Flow(pktid)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200106 packet = (
107 Ether(dst=src_if.local_mac, src=src_if.remote_mac) / ip / Raw(payload)
108 )
Pierre Pfisterf588f352016-10-07 16:31:57 +0100109 self.extend_packet(packet, 128)
110 info.data = packet.copy()
111 pkts.append(packet)
112 return pkts
113
114 def checkInner(self, gre, isv4):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200115 IPver = IP if isv4 else IPv6
Pierre Pfisterf588f352016-10-07 16:31:57 +0100116 self.assertEqual(gre.proto, 0x0800 if isv4 else 0x86DD)
117 self.assertEqual(gre.flags, 0)
118 self.assertEqual(gre.version, 0)
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700119 inner = IPver(scapy.compat.raw(gre.payload))
Paul Vinciguerraeaea4212019-03-06 11:58:06 -0800120 payload_info = self.payload_to_info(inner[Raw])
Klement Sekeradab231a2016-12-21 08:50:14 +0100121 self.info = self.packet_infos[payload_info.index]
122 self.assertEqual(payload_info.src, self.pg0.sw_if_index)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200123 self.assertEqual(
124 scapy.compat.raw(inner), scapy.compat.raw(self.info.data[IPver])
125 )
Pierre Pfisterf588f352016-10-07 16:31:57 +0100126
Nobuhiro MIKI613e6dc2022-09-28 15:53:17 +0900127 def checkCapture(self, encap, isv4, src_ip_sticky=False):
Klement Sekera65cc8c02016-12-18 15:49:54 +0100128 self.pg0.assert_nothing_captured()
Klement Sekeradab231a2016-12-21 08:50:14 +0100129 out = self.pg1.get_capture(len(self.packets))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100130
131 load = [0] * len(self.ass)
Nobuhiro MIKI613e6dc2022-09-28 15:53:17 +0900132 sticky_as = {}
Pierre Pfisterf588f352016-10-07 16:31:57 +0100133 self.info = None
134 for p in out:
135 try:
136 asid = 0
137 gre = None
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200138 if encap == "gre4":
Pierre Pfisterf588f352016-10-07 16:31:57 +0100139 ip = p[IP]
Pierre Pfisterf588f352016-10-07 16:31:57 +0100140 asid = int(ip.dst.split(".")[3])
141 self.assertEqual(ip.version, 4)
142 self.assertEqual(ip.flags, 0)
143 self.assertEqual(ip.src, "39.40.41.42")
144 self.assertEqual(ip.dst, "10.0.0.%u" % asid)
145 self.assertEqual(ip.proto, 47)
146 self.assertEqual(len(ip.options), 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200147 gre = p[GRE]
Hongjun Ni647f6092018-01-23 19:17:23 +0800148 self.checkInner(gre, isv4)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200149 elif encap == "gre6":
Pierre Pfisterf588f352016-10-07 16:31:57 +0100150 ip = p[IPv6]
Pierre Pfisterf588f352016-10-07 16:31:57 +0100151 asid = ip.dst.split(":")
152 asid = asid[len(asid) - 1]
Klement Sekeraf62ae122016-10-11 11:47:09 +0200153 asid = 0 if asid == "" else int(asid)
Pierre Pfisterf588f352016-10-07 16:31:57 +0100154 self.assertEqual(ip.version, 6)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200155 self.assertEqual(ip.tc, 0)
156 self.assertEqual(ip.fl, 0)
157 self.assertEqual(ip.src, "2004::1")
158 self.assertEqual(
159 socket.inet_pton(socket.AF_INET6, ip.dst),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200160 socket.inet_pton(socket.AF_INET6, "2002::%u" % asid),
Klement Sekeraf62ae122016-10-11 11:47:09 +0200161 )
162 self.assertEqual(ip.nh, 47)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200163 # self.assertEqual(len(ip.options), 0)
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700164 gre = GRE(scapy.compat.raw(p[IPv6].payload))
Hongjun Ni647f6092018-01-23 19:17:23 +0800165 self.checkInner(gre, isv4)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200166 elif encap == "l3dsr":
Hongjun Ni647f6092018-01-23 19:17:23 +0800167 ip = p[IP]
168 asid = int(ip.dst.split(".")[3])
169 self.assertEqual(ip.version, 4)
170 self.assertEqual(ip.flags, 0)
171 self.assertEqual(ip.dst, "10.0.0.%u" % asid)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200172 self.assertEqual(ip.tos, 0x1C)
Hongjun Ni647f6092018-01-23 19:17:23 +0800173 self.assertEqual(len(ip.options), 0)
Hongjun Ni6fb0d9b2018-06-08 07:12:05 +0800174 self.assert_ip_checksum_valid(p)
175 if ip.proto == IP_PROTOS.tcp:
176 self.assert_tcp_checksum_valid(p)
177 elif ip.proto == IP_PROTOS.udp:
178 self.assert_udp_checksum_valid(p)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200179 elif encap == "nat4":
Hongjun Nid92a0b52018-02-06 23:00:22 +0800180 ip = p[IP]
181 asid = int(ip.dst.split(".")[3])
182 self.assertEqual(ip.version, 4)
183 self.assertEqual(ip.flags, 0)
184 self.assertEqual(ip.dst, "10.0.0.%u" % asid)
185 self.assertEqual(ip.proto, 17)
186 self.assertEqual(len(ip.options), 0)
Hongjun Nid92a0b52018-02-06 23:00:22 +0800187 udp = p[UDP]
188 self.assertEqual(udp.dport, 3307)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200189 elif encap == "nat6":
Hongjun Nid92a0b52018-02-06 23:00:22 +0800190 ip = p[IPv6]
191 asid = ip.dst.split(":")
192 asid = asid[len(asid) - 1]
193 asid = 0 if asid == "" else int(asid)
194 self.assertEqual(ip.version, 6)
195 self.assertEqual(ip.tc, 0)
196 self.assertEqual(ip.fl, 0)
197 self.assertEqual(
198 socket.inet_pton(socket.AF_INET6, ip.dst),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200199 socket.inet_pton(socket.AF_INET6, "2002::%u" % asid),
Hongjun Nid92a0b52018-02-06 23:00:22 +0800200 )
201 self.assertEqual(ip.nh, 17)
202 self.assertGreaterEqual(ip.hlim, 63)
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700203 udp = UDP(scapy.compat.raw(p[IPv6].payload))
Hongjun Nid92a0b52018-02-06 23:00:22 +0800204 self.assertEqual(udp.dport, 3307)
Pierre Pfisterf588f352016-10-07 16:31:57 +0100205 load[asid] += 1
Nobuhiro MIKI613e6dc2022-09-28 15:53:17 +0900206
207 # In case of source ip sticky, check that packets with same
208 # src_ip are routed to same as.
209 if src_ip_sticky and sticky_as.get(ip.src, asid) != asid:
210 raise Exception("Packets with same src_ip are routed to another as")
211 sticky_as[ip.src] = asid
212
Pierre Pfisterf588f352016-10-07 16:31:57 +0100213 except:
Klement Sekera7bb873a2016-11-18 07:38:42 +0100214 self.logger.error(ppp("Unexpected or invalid packet:", p))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100215 raise
216
Paul Vinciguerraf7f13342019-03-19 11:54:39 -0700217 # This is just to roughly check that the balancing algorithm
218 # is not completely biased.
Pierre Pfisterf588f352016-10-07 16:31:57 +0100219 for asid in self.ass:
snaramreec44e262019-10-16 22:36:47 +0000220 if load[asid] < int(len(self.packets) / (len(self.ass) * 2)):
Gabriel Ganne8e66b9b2017-12-14 16:20:37 +0100221 self.logger.error(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200222 "ASS is not balanced: load[%d] = %d" % (asid, load[asid])
223 )
Pierre Pfisterf588f352016-10-07 16:31:57 +0100224 raise Exception("Load Balancer algorithm is biased")
225
Pierre Pfisterf588f352016-10-07 16:31:57 +0100226 def test_lb_ip4_gre4(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200227 """Load Balancer IP4 GRE4 on vip case"""
Klement Sekeraf62ae122016-10-11 11:47:09 +0200228 try:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200229 self.vapi.cli("lb vip 90.0.0.0/8 encap gre4")
Klement Sekeraf62ae122016-10-11 11:47:09 +0200230 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" % (asid))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100232
Klement Sekeraf62ae122016-10-11 11:47:09 +0200233 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
234 self.pg_enable_capture(self.pg_interfaces)
235 self.pg_start()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200236 self.checkCapture(encap="gre4", isv4=True)
Pierre Pfisterf588f352016-10-07 16:31:57 +0100237
Klement Sekeraf62ae122016-10-11 11:47:09 +0200238 finally:
239 for asid in self.ass:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200240 self.vapi.cli("lb as 90.0.0.0/8 10.0.0.%u del" % (asid))
241 self.vapi.cli("lb vip 90.0.0.0/8 encap gre4 del")
Gabriel Ganneb3d1b202017-10-30 15:44:31 +0100242 self.vapi.cli("test lb flowtable flush")
Pierre Pfisterf588f352016-10-07 16:31:57 +0100243
244 def test_lb_ip6_gre4(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200245 """Load Balancer IP6 GRE4 on vip case"""
Pierre Pfisterf588f352016-10-07 16:31:57 +0100246
Klement Sekeraf62ae122016-10-11 11:47:09 +0200247 try:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200248 self.vapi.cli("lb vip 2001::/16 encap gre4")
Klement Sekeraf62ae122016-10-11 11:47:09 +0200249 for asid in self.ass:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200250 self.vapi.cli("lb as 2001::/16 10.0.0.%u" % (asid))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100251
Klement Sekeraf62ae122016-10-11 11:47:09 +0200252 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
253 self.pg_enable_capture(self.pg_interfaces)
254 self.pg_start()
Pierre Pfisterf588f352016-10-07 16:31:57 +0100255
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200256 self.checkCapture(encap="gre4", isv4=False)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200257 finally:
258 for asid in self.ass:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200259 self.vapi.cli("lb as 2001::/16 10.0.0.%u del" % (asid))
260 self.vapi.cli("lb vip 2001::/16 encap gre4 del")
Gabriel Ganneb3d1b202017-10-30 15:44:31 +0100261 self.vapi.cli("test lb flowtable flush")
Pierre Pfisterf588f352016-10-07 16:31:57 +0100262
263 def test_lb_ip4_gre6(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200264 """Load Balancer IP4 GRE6 on vip case"""
Klement Sekeraf62ae122016-10-11 11:47:09 +0200265 try:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200266 self.vapi.cli("lb vip 90.0.0.0/8 encap gre6")
Klement Sekeraf62ae122016-10-11 11:47:09 +0200267 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" % (asid))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100269
Klement Sekeraf62ae122016-10-11 11:47:09 +0200270 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
271 self.pg_enable_capture(self.pg_interfaces)
272 self.pg_start()
Pierre Pfisterf588f352016-10-07 16:31:57 +0100273
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200274 self.checkCapture(encap="gre6", isv4=True)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200275 finally:
276 for asid in self.ass:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200277 self.vapi.cli("lb as 90.0.0.0/8 2002::%u del" % (asid))
278 self.vapi.cli("lb vip 90.0.0.0/8 encap gre6 del")
Gabriel Ganneb3d1b202017-10-30 15:44:31 +0100279 self.vapi.cli("test lb flowtable flush")
Pierre Pfisterf588f352016-10-07 16:31:57 +0100280
281 def test_lb_ip6_gre6(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200282 """Load Balancer IP6 GRE6 on vip case"""
Klement Sekeraf62ae122016-10-11 11:47:09 +0200283 try:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200284 self.vapi.cli("lb vip 2001::/16 encap gre6")
Klement Sekeraf62ae122016-10-11 11:47:09 +0200285 for asid in self.ass:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200286 self.vapi.cli("lb as 2001::/16 2002::%u" % (asid))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100287
Klement Sekeraf62ae122016-10-11 11:47:09 +0200288 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
289 self.pg_enable_capture(self.pg_interfaces)
290 self.pg_start()
Pierre Pfisterf588f352016-10-07 16:31:57 +0100291
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200292 self.checkCapture(encap="gre6", isv4=False)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200293 finally:
294 for asid in self.ass:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200295 self.vapi.cli("lb as 2001::/16 2002::%u del" % (asid))
296 self.vapi.cli("lb vip 2001::/16 encap gre6 del")
Hongjun Ni219cc902018-06-28 20:14:19 +0800297 self.vapi.cli("test lb flowtable flush")
298
299 def test_lb_ip4_gre4_port(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200300 """Load Balancer IP4 GRE4 on per-port-vip case"""
Hongjun Ni219cc902018-06-28 20:14:19 +0800301 try:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200302 self.vapi.cli("lb vip 90.0.0.0/8 protocol udp port 20000 encap gre4")
Hongjun Ni219cc902018-06-28 20:14:19 +0800303 for asid in self.ass:
304 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200305 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u" % (asid)
306 )
Hongjun Ni219cc902018-06-28 20:14:19 +0800307
308 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
309 self.pg_enable_capture(self.pg_interfaces)
310 self.pg_start()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200311 self.checkCapture(encap="gre4", isv4=True)
Hongjun Ni219cc902018-06-28 20:14:19 +0800312
313 finally:
314 for asid in self.ass:
315 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200316 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u del" % (asid)
317 )
318 self.vapi.cli("lb vip 90.0.0.0/8 protocol udp port 20000 encap gre4 del")
Hongjun Ni219cc902018-06-28 20:14:19 +0800319 self.vapi.cli("test lb flowtable flush")
320
321 def test_lb_ip6_gre4_port(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200322 """Load Balancer IP6 GRE4 on per-port-vip case"""
Hongjun Ni219cc902018-06-28 20:14:19 +0800323
324 try:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200325 self.vapi.cli("lb vip 2001::/16 protocol udp port 20000 encap gre4")
Hongjun Ni219cc902018-06-28 20:14:19 +0800326 for asid in self.ass:
327 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200328 "lb as 2001::/16 protocol udp port 20000 10.0.0.%u" % (asid)
329 )
Hongjun Ni219cc902018-06-28 20:14:19 +0800330
331 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
332 self.pg_enable_capture(self.pg_interfaces)
333 self.pg_start()
334
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200335 self.checkCapture(encap="gre4", isv4=False)
Hongjun Ni219cc902018-06-28 20:14:19 +0800336 finally:
337 for asid in self.ass:
338 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200339 "lb as 2001::/16 protocol udp port 20000 10.0.0.%u del" % (asid)
340 )
341 self.vapi.cli("lb vip 2001::/16 protocol udp port 20000 encap gre4 del")
Hongjun Ni219cc902018-06-28 20:14:19 +0800342 self.vapi.cli("test lb flowtable flush")
343
344 def test_lb_ip4_gre6_port(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200345 """Load Balancer IP4 GRE6 on per-port-vip case"""
Hongjun Ni219cc902018-06-28 20:14:19 +0800346 try:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200347 self.vapi.cli("lb vip 90.0.0.0/8 protocol udp port 20000 encap gre6")
Hongjun Ni219cc902018-06-28 20:14:19 +0800348 for asid in self.ass:
349 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200350 "lb as 90.0.0.0/8 protocol udp port 20000 2002::%u" % (asid)
351 )
Hongjun Ni219cc902018-06-28 20:14:19 +0800352
353 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
354 self.pg_enable_capture(self.pg_interfaces)
355 self.pg_start()
356
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200357 self.checkCapture(encap="gre6", isv4=True)
Hongjun Ni219cc902018-06-28 20:14:19 +0800358 finally:
359 for asid in self.ass:
360 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200361 "lb as 90.0.0.0/8 protocol udp port 20000 2002::%u del" % (asid)
362 )
363 self.vapi.cli("lb vip 90.0.0.0/8 protocol udp port 20000 encap gre6 del")
Hongjun Ni219cc902018-06-28 20:14:19 +0800364 self.vapi.cli("test lb flowtable flush")
365
366 def test_lb_ip6_gre6_port(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200367 """Load Balancer IP6 GRE6 on per-port-vip case"""
Hongjun Ni219cc902018-06-28 20:14:19 +0800368 try:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200369 self.vapi.cli("lb vip 2001::/16 protocol udp port 20000 encap gre6")
Hongjun Ni219cc902018-06-28 20:14:19 +0800370 for asid in self.ass:
371 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200372 "lb as 2001::/16 protocol udp port 20000 2002::%u" % (asid)
373 )
Hongjun Ni219cc902018-06-28 20:14:19 +0800374
375 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
376 self.pg_enable_capture(self.pg_interfaces)
377 self.pg_start()
378
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200379 self.checkCapture(encap="gre6", isv4=False)
Hongjun Ni219cc902018-06-28 20:14:19 +0800380 finally:
381 for asid in self.ass:
382 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200383 "lb as 2001::/16 protocol udp port 20000 2002::%u del" % (asid)
384 )
385 self.vapi.cli("lb vip 2001::/16 protocol udp port 20000 encap gre6 del")
Gabriel Ganneb3d1b202017-10-30 15:44:31 +0100386 self.vapi.cli("test lb flowtable flush")
Hongjun Ni647f6092018-01-23 19:17:23 +0800387
388 def test_lb_ip4_l3dsr(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200389 """Load Balancer IP4 L3DSR on vip case"""
Hongjun Ni647f6092018-01-23 19:17:23 +0800390 try:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200391 self.vapi.cli("lb vip 90.0.0.0/8 encap l3dsr dscp 7")
Hongjun Ni647f6092018-01-23 19:17:23 +0800392 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" % (asid))
Hongjun Ni647f6092018-01-23 19:17:23 +0800394
395 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
396 self.pg_enable_capture(self.pg_interfaces)
397 self.pg_start()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200398 self.checkCapture(encap="l3dsr", isv4=True)
Hongjun Ni647f6092018-01-23 19:17:23 +0800399
400 finally:
401 for asid in self.ass:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200402 self.vapi.cli("lb as 90.0.0.0/8 10.0.0.%u del" % (asid))
403 self.vapi.cli("lb vip 90.0.0.0/8 encap l3dsr dscp 7 del")
Hongjun Ni647f6092018-01-23 19:17:23 +0800404 self.vapi.cli("test lb flowtable flush")
Hongjun Nid92a0b52018-02-06 23:00:22 +0800405
Hongjun Ni219cc902018-06-28 20:14:19 +0800406 def test_lb_ip4_l3dsr_port(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200407 """Load Balancer IP4 L3DSR on per-port-vip case"""
Hongjun Nid92a0b52018-02-06 23:00:22 +0800408 try:
Hongjun Ni219cc902018-06-28 20:14:19 +0800409 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200410 "lb vip 90.0.0.0/8 protocol udp port 20000 encap l3dsr dscp 7"
411 )
Hongjun Nid92a0b52018-02-06 23:00:22 +0800412 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800413 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200414 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u" % (asid)
415 )
Hongjun Ni219cc902018-06-28 20:14:19 +0800416
417 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
418 self.pg_enable_capture(self.pg_interfaces)
419 self.pg_start()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200420 self.checkCapture(encap="l3dsr", isv4=True)
Hongjun Ni219cc902018-06-28 20:14:19 +0800421
422 finally:
423 for asid in self.ass:
424 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200425 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u del" % (asid)
426 )
Hongjun Ni219cc902018-06-28 20:14:19 +0800427 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200428 "lb vip 90.0.0.0/8 protocol udp port 20000 encap l3dsr dscp 7 del"
429 )
Hongjun Ni219cc902018-06-28 20:14:19 +0800430 self.vapi.cli("test lb flowtable flush")
431
Nobuhiro MIKI613e6dc2022-09-28 15:53:17 +0900432 def test_lb_ip4_l3dsr_port_src_ip_sticky(self):
433 """Load Balancer IP4 L3DSR on per-port-vip with src_ip_sticky case"""
434 try:
435 self.vapi.cli(
436 "lb vip 90.0.0.0/8 protocol udp port 20000 encap l3dsr dscp 7 src_ip_sticky"
437 )
438 for asid in self.ass:
439 self.vapi.cli(
440 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u" % (asid)
441 )
442
443 # Generate duplicated packets
444 pkts = self.generatePackets(self.pg0, isv4=True)
445 pkts = pkts[: len(pkts) // 2]
446 pkts = pkts + pkts
447
448 self.pg0.add_stream(pkts)
449 self.pg_enable_capture(self.pg_interfaces)
450 self.pg_start()
451 self.checkCapture(encap="l3dsr", isv4=True, src_ip_sticky=True)
452
453 finally:
454 for asid in self.ass:
455 self.vapi.cli(
456 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u del" % (asid)
457 )
458 self.vapi.cli(
459 "lb vip 90.0.0.0/8 protocol udp port 20000 encap l3dsr dscp 7 src_ip_sticky del"
460 )
461 self.vapi.cli("test lb flowtable flush")
462
Hongjun Ni219cc902018-06-28 20:14:19 +0800463 def test_lb_ip4_nat4_port(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200464 """Load Balancer IP4 NAT4 on per-port-vip case"""
Hongjun Ni219cc902018-06-28 20:14:19 +0800465 try:
466 self.vapi.cli(
467 "lb vip 90.0.0.0/8 protocol udp port 20000 encap nat4"
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200468 " type clusterip target_port 3307"
469 )
Hongjun Ni219cc902018-06-28 20:14:19 +0800470 for asid in self.ass:
471 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200472 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u" % (asid)
473 )
Hongjun Nid92a0b52018-02-06 23:00:22 +0800474
475 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
476 self.pg_enable_capture(self.pg_interfaces)
477 self.pg_start()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200478 self.checkCapture(encap="nat4", isv4=True)
Hongjun Nid92a0b52018-02-06 23:00:22 +0800479
480 finally:
481 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800482 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200483 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u del" % (asid)
484 )
Hongjun Ni219cc902018-06-28 20:14:19 +0800485 self.vapi.cli(
486 "lb vip 90.0.0.0/8 protocol udp port 20000 encap nat4"
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200487 " type clusterip target_port 3307 del"
488 )
Hongjun Nid92a0b52018-02-06 23:00:22 +0800489 self.vapi.cli("test lb flowtable flush")
490
Hongjun Ni219cc902018-06-28 20:14:19 +0800491 def test_lb_ip6_nat6_port(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200492 """Load Balancer IP6 NAT6 on per-port-vip case"""
Hongjun Nid92a0b52018-02-06 23:00:22 +0800493 try:
Hongjun Ni219cc902018-06-28 20:14:19 +0800494 self.vapi.cli(
495 "lb vip 2001::/16 protocol udp port 20000 encap nat6"
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200496 " type clusterip target_port 3307"
497 )
Hongjun Nid92a0b52018-02-06 23:00:22 +0800498 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800499 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200500 "lb as 2001::/16 protocol udp port 20000 2002::%u" % (asid)
501 )
Hongjun Nid92a0b52018-02-06 23:00:22 +0800502
503 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
504 self.pg_enable_capture(self.pg_interfaces)
505 self.pg_start()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200506 self.checkCapture(encap="nat6", isv4=False)
Hongjun Nid92a0b52018-02-06 23:00:22 +0800507
508 finally:
509 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800510 self.vapi.cli(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200511 "lb as 2001::/16 protocol udp port 20000 2002::%u del" % (asid)
512 )
Hongjun Ni219cc902018-06-28 20:14:19 +0800513 self.vapi.cli(
514 "lb vip 2001::/16 protocol udp port 20000 encap nat6"
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200515 " type clusterip target_port 3307 del"
516 )
Hongjun Nid92a0b52018-02-06 23:00:22 +0800517 self.vapi.cli("test lb flowtable flush")