blob: 4c0bfadaccb915842f989404cbe449b09e65d387 [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
Klement Sekeraf62ae122016-10-11 11:47:09 +020012
13""" TestLB is a subclass of VPPTestCase classes.
14
15 TestLB class defines Load Balancer test cases for:
Hongjun Ni219cc902018-06-28 20:14:19 +080016 - IP4 to GRE4 encap on per-port vip case
17 - IP4 to GRE6 encap on per-port vip case
18 - IP6 to GRE4 encap on per-port vip case
19 - IP6 to GRE6 encap on per-port vip case
20 - IP4 to L3DSR encap on vip case
21 - IP4 to L3DSR encap on per-port vip case
22 - IP4 to NAT4 encap on per-port vip case
23 - IP6 to NAT6 encap on per-port vip case
Klement Sekeraf62ae122016-10-11 11:47:09 +020024
25 As stated in comments below, GRE has issues with IPv6.
26 All test cases involving IPv6 are executed, but
27 received packets are not parsed and checked.
28
29"""
30
31
32class TestLB(VppTestCase):
Pierre Pfisterf588f352016-10-07 16:31:57 +010033 """ Load Balancer Test Case """
34
35 @classmethod
36 def setUpClass(cls):
37 super(TestLB, cls).setUpClass()
38
39 cls.ass = range(5)
Hongjun Ni219cc902018-06-28 20:14:19 +080040 cls.packets = range(1)
Pierre Pfisterf588f352016-10-07 16:31:57 +010041
42 try:
Klement Sekeraf62ae122016-10-11 11:47:09 +020043 cls.create_pg_interfaces(range(2))
44 cls.interfaces = list(cls.pg_interfaces)
Pierre Pfisterf588f352016-10-07 16:31:57 +010045
Klement Sekeraf62ae122016-10-11 11:47:09 +020046 for i in cls.interfaces:
47 i.admin_up()
48 i.config_ip4()
49 i.config_ip6()
50 i.disable_ipv6_ra()
51 i.resolve_arp()
52 i.resolve_ndp()
53 dst4 = socket.inet_pton(socket.AF_INET, "10.0.0.0")
54 dst6 = socket.inet_pton(socket.AF_INET6, "2002::")
Ole Troana5b2eec2019-03-11 19:23:25 +010055 cls.vapi.ip_add_del_route(dst_address=dst4, dst_address_length=24,
56 next_hop_address=cls.pg1.remote_ip4n)
57 cls.vapi.ip_add_del_route(dst_address=dst6, dst_address_length=16,
58 next_hop_address=cls.pg1.remote_ip6n,
59 is_ipv6=1)
Paul Vinciguerraf7f13342019-03-19 11:54:39 -070060 cls.vapi.lb_conf(ip4_src_address="39.40.41.42",
61 ip6_src_address="2004::1")
Klement Sekeraf62ae122016-10-11 11:47:09 +020062 except Exception:
Pierre Pfisterf588f352016-10-07 16:31:57 +010063 super(TestLB, cls).tearDownClass()
64 raise
65
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070066 @classmethod
67 def tearDownClass(cls):
68 super(TestLB, cls).tearDownClass()
69
Pierre Pfisterf588f352016-10-07 16:31:57 +010070 def tearDown(self):
Klement Sekeraf62ae122016-10-11 11:47:09 +020071 super(TestLB, self).tearDown()
72 if not self.vpp_dead:
Klement Sekera7bb873a2016-11-18 07:38:42 +010073 self.logger.info(self.vapi.cli("show lb vip verbose"))
Pierre Pfisterf588f352016-10-07 16:31:57 +010074
75 def getIPv4Flow(self, id):
76 return (IP(dst="90.0.%u.%u" % (id / 255, id % 255),
Klement Sekeraf62ae122016-10-11 11:47:09 +020077 src="40.0.%u.%u" % (id / 255, id % 255)) /
Hongjun Ni219cc902018-06-28 20:14:19 +080078 UDP(sport=10000 + id, dport=20000))
Pierre Pfisterf588f352016-10-07 16:31:57 +010079
80 def getIPv6Flow(self, id):
81 return (IPv6(dst="2001::%u" % (id), src="fd00:f00d:ffff::%u" % (id)) /
Hongjun Ni219cc902018-06-28 20:14:19 +080082 UDP(sport=10000 + id, dport=20000))
Pierre Pfisterf588f352016-10-07 16:31:57 +010083
Klement Sekeraf62ae122016-10-11 11:47:09 +020084 def generatePackets(self, src_if, isv4):
Klement Sekeradab231a2016-12-21 08:50:14 +010085 self.reset_packet_infos()
Pierre Pfisterf588f352016-10-07 16:31:57 +010086 pkts = []
87 for pktid in self.packets:
Klement Sekeradab231a2016-12-21 08:50:14 +010088 info = self.create_packet_info(src_if, self.pg1)
Pierre Pfisterf588f352016-10-07 16:31:57 +010089 payload = self.info_to_payload(info)
90 ip = self.getIPv4Flow(pktid) if isv4 else self.getIPv6Flow(pktid)
Klement Sekeraf62ae122016-10-11 11:47:09 +020091 packet = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
92 ip /
93 Raw(payload))
Pierre Pfisterf588f352016-10-07 16:31:57 +010094 self.extend_packet(packet, 128)
95 info.data = packet.copy()
96 pkts.append(packet)
97 return pkts
98
99 def checkInner(self, gre, isv4):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200100 IPver = IP if isv4 else IPv6
Pierre Pfisterf588f352016-10-07 16:31:57 +0100101 self.assertEqual(gre.proto, 0x0800 if isv4 else 0x86DD)
102 self.assertEqual(gre.flags, 0)
103 self.assertEqual(gre.version, 0)
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700104 inner = IPver(scapy.compat.raw(gre.payload))
Paul Vinciguerraeaea4212019-03-06 11:58:06 -0800105 payload_info = self.payload_to_info(inner[Raw])
Klement Sekeradab231a2016-12-21 08:50:14 +0100106 self.info = self.packet_infos[payload_info.index]
107 self.assertEqual(payload_info.src, self.pg0.sw_if_index)
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700108 self.assertEqual(scapy.compat.raw(inner),
109 scapy.compat.raw(self.info.data[IPver]))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100110
Hongjun Ni647f6092018-01-23 19:17:23 +0800111 def checkCapture(self, encap, isv4):
Klement Sekera65cc8c02016-12-18 15:49:54 +0100112 self.pg0.assert_nothing_captured()
Klement Sekeradab231a2016-12-21 08:50:14 +0100113 out = self.pg1.get_capture(len(self.packets))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100114
115 load = [0] * len(self.ass)
116 self.info = None
117 for p in out:
118 try:
119 asid = 0
120 gre = None
Hongjun Ni647f6092018-01-23 19:17:23 +0800121 if (encap == 'gre4'):
Pierre Pfisterf588f352016-10-07 16:31:57 +0100122 ip = p[IP]
Pierre Pfisterf588f352016-10-07 16:31:57 +0100123 asid = int(ip.dst.split(".")[3])
124 self.assertEqual(ip.version, 4)
125 self.assertEqual(ip.flags, 0)
126 self.assertEqual(ip.src, "39.40.41.42")
127 self.assertEqual(ip.dst, "10.0.0.%u" % asid)
128 self.assertEqual(ip.proto, 47)
129 self.assertEqual(len(ip.options), 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200130 gre = p[GRE]
Hongjun Ni647f6092018-01-23 19:17:23 +0800131 self.checkInner(gre, isv4)
132 elif (encap == 'gre6'):
Pierre Pfisterf588f352016-10-07 16:31:57 +0100133 ip = p[IPv6]
Pierre Pfisterf588f352016-10-07 16:31:57 +0100134 asid = ip.dst.split(":")
135 asid = asid[len(asid) - 1]
Klement Sekeraf62ae122016-10-11 11:47:09 +0200136 asid = 0 if asid == "" else int(asid)
Pierre Pfisterf588f352016-10-07 16:31:57 +0100137 self.assertEqual(ip.version, 6)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200138 self.assertEqual(ip.tc, 0)
139 self.assertEqual(ip.fl, 0)
140 self.assertEqual(ip.src, "2004::1")
141 self.assertEqual(
142 socket.inet_pton(socket.AF_INET6, ip.dst),
143 socket.inet_pton(socket.AF_INET6, "2002::%u" % asid)
144 )
145 self.assertEqual(ip.nh, 47)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200146 # self.assertEqual(len(ip.options), 0)
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700147 gre = GRE(scapy.compat.raw(p[IPv6].payload))
Hongjun Ni647f6092018-01-23 19:17:23 +0800148 self.checkInner(gre, isv4)
Hongjun Nid92a0b52018-02-06 23:00:22 +0800149 elif (encap == 'l3dsr'):
Hongjun Ni647f6092018-01-23 19:17:23 +0800150 ip = p[IP]
151 asid = int(ip.dst.split(".")[3])
152 self.assertEqual(ip.version, 4)
153 self.assertEqual(ip.flags, 0)
154 self.assertEqual(ip.dst, "10.0.0.%u" % asid)
155 self.assertEqual(ip.tos, 0x1c)
156 self.assertEqual(len(ip.options), 0)
Hongjun Ni6fb0d9b2018-06-08 07:12:05 +0800157 self.assert_ip_checksum_valid(p)
158 if ip.proto == IP_PROTOS.tcp:
159 self.assert_tcp_checksum_valid(p)
160 elif ip.proto == IP_PROTOS.udp:
161 self.assert_udp_checksum_valid(p)
Hongjun Nid92a0b52018-02-06 23:00:22 +0800162 elif (encap == 'nat4'):
163 ip = p[IP]
164 asid = int(ip.dst.split(".")[3])
165 self.assertEqual(ip.version, 4)
166 self.assertEqual(ip.flags, 0)
167 self.assertEqual(ip.dst, "10.0.0.%u" % asid)
168 self.assertEqual(ip.proto, 17)
169 self.assertEqual(len(ip.options), 0)
Hongjun Nid92a0b52018-02-06 23:00:22 +0800170 udp = p[UDP]
171 self.assertEqual(udp.dport, 3307)
172 elif (encap == 'nat6'):
173 ip = p[IPv6]
174 asid = ip.dst.split(":")
175 asid = asid[len(asid) - 1]
176 asid = 0 if asid == "" else int(asid)
177 self.assertEqual(ip.version, 6)
178 self.assertEqual(ip.tc, 0)
179 self.assertEqual(ip.fl, 0)
180 self.assertEqual(
181 socket.inet_pton(socket.AF_INET6, ip.dst),
182 socket.inet_pton(socket.AF_INET6, "2002::%u" % asid)
183 )
184 self.assertEqual(ip.nh, 17)
185 self.assertGreaterEqual(ip.hlim, 63)
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700186 udp = UDP(scapy.compat.raw(p[IPv6].payload))
Hongjun Nid92a0b52018-02-06 23:00:22 +0800187 self.assertEqual(udp.dport, 3307)
Pierre Pfisterf588f352016-10-07 16:31:57 +0100188 load[asid] += 1
189 except:
Klement Sekera7bb873a2016-11-18 07:38:42 +0100190 self.logger.error(ppp("Unexpected or invalid packet:", p))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100191 raise
192
Paul Vinciguerraf7f13342019-03-19 11:54:39 -0700193 # This is just to roughly check that the balancing algorithm
194 # is not completely biased.
Pierre Pfisterf588f352016-10-07 16:31:57 +0100195 for asid in self.ass:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200196 if load[asid] < len(self.packets) / (len(self.ass) * 2):
Gabriel Ganne8e66b9b2017-12-14 16:20:37 +0100197 self.logger.error(
Klement Sekeraf62ae122016-10-11 11:47:09 +0200198 "ASS is not balanced: load[%d] = %d" % (asid, load[asid]))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100199 raise Exception("Load Balancer algorithm is biased")
200
Pierre Pfisterf588f352016-10-07 16:31:57 +0100201 def test_lb_ip4_gre4(self):
Hongjun Ni219cc902018-06-28 20:14:19 +0800202 """ Load Balancer IP4 GRE4 on vip case """
Klement Sekeraf62ae122016-10-11 11:47:09 +0200203 try:
Hongjun Ni219cc902018-06-28 20:14:19 +0800204 self.vapi.cli(
205 "lb vip 90.0.0.0/8 encap gre4")
Klement Sekeraf62ae122016-10-11 11:47:09 +0200206 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800207 self.vapi.cli(
208 "lb as 90.0.0.0/8 10.0.0.%u"
209 % (asid))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100210
Klement Sekeraf62ae122016-10-11 11:47:09 +0200211 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
212 self.pg_enable_capture(self.pg_interfaces)
213 self.pg_start()
Hongjun Ni647f6092018-01-23 19:17:23 +0800214 self.checkCapture(encap='gre4', isv4=True)
Pierre Pfisterf588f352016-10-07 16:31:57 +0100215
Klement Sekeraf62ae122016-10-11 11:47:09 +0200216 finally:
217 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800218 self.vapi.cli(
219 "lb as 90.0.0.0/8 10.0.0.%u del"
220 % (asid))
221 self.vapi.cli(
222 "lb vip 90.0.0.0/8 encap gre4 del")
Gabriel Ganneb3d1b202017-10-30 15:44:31 +0100223 self.vapi.cli("test lb flowtable flush")
Pierre Pfisterf588f352016-10-07 16:31:57 +0100224
225 def test_lb_ip6_gre4(self):
Hongjun Ni219cc902018-06-28 20:14:19 +0800226 """ Load Balancer IP6 GRE4 on vip case """
Pierre Pfisterf588f352016-10-07 16:31:57 +0100227
Klement Sekeraf62ae122016-10-11 11:47:09 +0200228 try:
Hongjun Ni219cc902018-06-28 20:14:19 +0800229 self.vapi.cli(
230 "lb vip 2001::/16 encap gre4")
Klement Sekeraf62ae122016-10-11 11:47:09 +0200231 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800232 self.vapi.cli(
233 "lb as 2001::/16 10.0.0.%u"
234 % (asid))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100235
Klement Sekeraf62ae122016-10-11 11:47:09 +0200236 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
237 self.pg_enable_capture(self.pg_interfaces)
238 self.pg_start()
Pierre Pfisterf588f352016-10-07 16:31:57 +0100239
Hongjun Ni647f6092018-01-23 19:17:23 +0800240 self.checkCapture(encap='gre4', isv4=False)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200241 finally:
242 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800243 self.vapi.cli(
244 "lb as 2001::/16 10.0.0.%u del"
245 % (asid))
246 self.vapi.cli(
247 "lb vip 2001::/16 encap gre4 del")
Gabriel Ganneb3d1b202017-10-30 15:44:31 +0100248 self.vapi.cli("test lb flowtable flush")
Pierre Pfisterf588f352016-10-07 16:31:57 +0100249
250 def test_lb_ip4_gre6(self):
Hongjun Ni219cc902018-06-28 20:14:19 +0800251 """ Load Balancer IP4 GRE6 on vip case """
Klement Sekeraf62ae122016-10-11 11:47:09 +0200252 try:
Hongjun Ni219cc902018-06-28 20:14:19 +0800253 self.vapi.cli(
254 "lb vip 90.0.0.0/8 encap gre6")
Klement Sekeraf62ae122016-10-11 11:47:09 +0200255 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800256 self.vapi.cli(
257 "lb as 90.0.0.0/8 2002::%u"
258 % (asid))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100259
Klement Sekeraf62ae122016-10-11 11:47:09 +0200260 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
261 self.pg_enable_capture(self.pg_interfaces)
262 self.pg_start()
Pierre Pfisterf588f352016-10-07 16:31:57 +0100263
Hongjun Ni647f6092018-01-23 19:17:23 +0800264 self.checkCapture(encap='gre6', isv4=True)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200265 finally:
266 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800267 self.vapi.cli(
268 "lb as 90.0.0.0/8 2002::%u del"
269 % (asid))
270 self.vapi.cli(
271 "lb vip 90.0.0.0/8 encap gre6 del")
Gabriel Ganneb3d1b202017-10-30 15:44:31 +0100272 self.vapi.cli("test lb flowtable flush")
Pierre Pfisterf588f352016-10-07 16:31:57 +0100273
274 def test_lb_ip6_gre6(self):
Hongjun Ni219cc902018-06-28 20:14:19 +0800275 """ Load Balancer IP6 GRE6 on vip case """
Klement Sekeraf62ae122016-10-11 11:47:09 +0200276 try:
Hongjun Ni219cc902018-06-28 20:14:19 +0800277 self.vapi.cli(
278 "lb vip 2001::/16 encap gre6")
Klement Sekeraf62ae122016-10-11 11:47:09 +0200279 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800280 self.vapi.cli(
281 "lb as 2001::/16 2002::%u"
282 % (asid))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100283
Klement Sekeraf62ae122016-10-11 11:47:09 +0200284 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
285 self.pg_enable_capture(self.pg_interfaces)
286 self.pg_start()
Pierre Pfisterf588f352016-10-07 16:31:57 +0100287
Hongjun Ni647f6092018-01-23 19:17:23 +0800288 self.checkCapture(encap='gre6', isv4=False)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200289 finally:
290 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800291 self.vapi.cli(
292 "lb as 2001::/16 2002::%u del"
293 % (asid))
294 self.vapi.cli(
295 "lb vip 2001::/16 encap gre6 del")
296 self.vapi.cli("test lb flowtable flush")
297
298 def test_lb_ip4_gre4_port(self):
299 """ Load Balancer IP4 GRE4 on per-port-vip case """
300 try:
301 self.vapi.cli(
302 "lb vip 90.0.0.0/8 protocol udp port 20000 encap gre4")
303 for asid in self.ass:
304 self.vapi.cli(
305 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u"
306 % (asid))
307
308 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
309 self.pg_enable_capture(self.pg_interfaces)
310 self.pg_start()
311 self.checkCapture(encap='gre4', isv4=True)
312
313 finally:
314 for asid in self.ass:
315 self.vapi.cli(
316 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u del"
317 % (asid))
318 self.vapi.cli(
319 "lb vip 90.0.0.0/8 protocol udp port 20000 encap gre4 del")
320 self.vapi.cli("test lb flowtable flush")
321
322 def test_lb_ip6_gre4_port(self):
323 """ Load Balancer IP6 GRE4 on per-port-vip case """
324
325 try:
326 self.vapi.cli(
327 "lb vip 2001::/16 protocol udp port 20000 encap gre4")
328 for asid in self.ass:
329 self.vapi.cli(
330 "lb as 2001::/16 protocol udp port 20000 10.0.0.%u"
331 % (asid))
332
333 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
334 self.pg_enable_capture(self.pg_interfaces)
335 self.pg_start()
336
337 self.checkCapture(encap='gre4', isv4=False)
338 finally:
339 for asid in self.ass:
340 self.vapi.cli(
341 "lb as 2001::/16 protocol udp port 20000 10.0.0.%u del"
342 % (asid))
343 self.vapi.cli(
344 "lb vip 2001::/16 protocol udp port 20000 encap gre4 del")
345 self.vapi.cli("test lb flowtable flush")
346
347 def test_lb_ip4_gre6_port(self):
348 """ Load Balancer IP4 GRE6 on per-port-vip case """
349 try:
350 self.vapi.cli(
351 "lb vip 90.0.0.0/8 protocol udp port 20000 encap gre6")
352 for asid in self.ass:
353 self.vapi.cli(
354 "lb as 90.0.0.0/8 protocol udp port 20000 2002::%u"
355 % (asid))
356
357 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
358 self.pg_enable_capture(self.pg_interfaces)
359 self.pg_start()
360
361 self.checkCapture(encap='gre6', isv4=True)
362 finally:
363 for asid in self.ass:
364 self.vapi.cli(
365 "lb as 90.0.0.0/8 protocol udp port 20000 2002::%u del"
366 % (asid))
367 self.vapi.cli(
368 "lb vip 90.0.0.0/8 protocol udp port 20000 encap gre6 del")
369 self.vapi.cli("test lb flowtable flush")
370
371 def test_lb_ip6_gre6_port(self):
372 """ Load Balancer IP6 GRE6 on per-port-vip case """
373 try:
374 self.vapi.cli(
375 "lb vip 2001::/16 protocol udp port 20000 encap gre6")
376 for asid in self.ass:
377 self.vapi.cli(
378 "lb as 2001::/16 protocol udp port 20000 2002::%u"
379 % (asid))
380
381 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
382 self.pg_enable_capture(self.pg_interfaces)
383 self.pg_start()
384
385 self.checkCapture(encap='gre6', isv4=False)
386 finally:
387 for asid in self.ass:
388 self.vapi.cli(
389 "lb as 2001::/16 protocol udp port 20000 2002::%u del"
390 % (asid))
391 self.vapi.cli(
392 "lb vip 2001::/16 protocol udp port 20000 encap gre6 del")
Gabriel Ganneb3d1b202017-10-30 15:44:31 +0100393 self.vapi.cli("test lb flowtable flush")
Hongjun Ni647f6092018-01-23 19:17:23 +0800394
395 def test_lb_ip4_l3dsr(self):
Hongjun Ni219cc902018-06-28 20:14:19 +0800396 """ Load Balancer IP4 L3DSR on vip case """
Hongjun Ni647f6092018-01-23 19:17:23 +0800397 try:
Hongjun Ni219cc902018-06-28 20:14:19 +0800398 self.vapi.cli(
399 "lb vip 90.0.0.0/8 encap l3dsr dscp 7")
Hongjun Ni647f6092018-01-23 19:17:23 +0800400 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800401 self.vapi.cli(
402 "lb as 90.0.0.0/8 10.0.0.%u"
403 % (asid))
Hongjun Ni647f6092018-01-23 19:17:23 +0800404
405 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
406 self.pg_enable_capture(self.pg_interfaces)
407 self.pg_start()
408 self.checkCapture(encap='l3dsr', isv4=True)
409
410 finally:
411 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800412 self.vapi.cli(
413 "lb as 90.0.0.0/8 10.0.0.%u del"
414 % (asid))
415 self.vapi.cli(
416 "lb vip 90.0.0.0/8 encap l3dsr"
417 " dscp 7 del")
Hongjun Ni647f6092018-01-23 19:17:23 +0800418 self.vapi.cli("test lb flowtable flush")
Hongjun Nid92a0b52018-02-06 23:00:22 +0800419
Hongjun Ni219cc902018-06-28 20:14:19 +0800420 def test_lb_ip4_l3dsr_port(self):
421 """ Load Balancer IP4 L3DSR on per-port-vip case """
Hongjun Nid92a0b52018-02-06 23:00:22 +0800422 try:
Hongjun Ni219cc902018-06-28 20:14:19 +0800423 self.vapi.cli(
424 "lb vip 90.0.0.0/8 protocol udp port 20000 encap l3dsr dscp 7")
Hongjun Nid92a0b52018-02-06 23:00:22 +0800425 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800426 self.vapi.cli(
427 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u"
428 % (asid))
429
430 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
431 self.pg_enable_capture(self.pg_interfaces)
432 self.pg_start()
433 self.checkCapture(encap='l3dsr', isv4=True)
434
435 finally:
436 for asid in self.ass:
437 self.vapi.cli(
438 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u del"
439 % (asid))
440 self.vapi.cli(
441 "lb vip 90.0.0.0/8 protocol udp port 20000 encap l3dsr"
442 " dscp 7 del")
443 self.vapi.cli("test lb flowtable flush")
444
445 def test_lb_ip4_nat4_port(self):
446 """ Load Balancer IP4 NAT4 on per-port-vip case """
447 try:
448 self.vapi.cli(
449 "lb vip 90.0.0.0/8 protocol udp port 20000 encap nat4"
450 " type clusterip target_port 3307")
451 for asid in self.ass:
452 self.vapi.cli(
453 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u"
454 % (asid))
Hongjun Nid92a0b52018-02-06 23:00:22 +0800455
456 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
457 self.pg_enable_capture(self.pg_interfaces)
458 self.pg_start()
459 self.checkCapture(encap='nat4', isv4=True)
460
461 finally:
462 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800463 self.vapi.cli(
464 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u del"
465 % (asid))
466 self.vapi.cli(
467 "lb vip 90.0.0.0/8 protocol udp port 20000 encap nat4"
468 " type clusterip target_port 3307 del")
Hongjun Nid92a0b52018-02-06 23:00:22 +0800469 self.vapi.cli("test lb flowtable flush")
470
Hongjun Ni219cc902018-06-28 20:14:19 +0800471 def test_lb_ip6_nat6_port(self):
472 """ Load Balancer IP6 NAT6 on per-port-vip case """
Hongjun Nid92a0b52018-02-06 23:00:22 +0800473 try:
Hongjun Ni219cc902018-06-28 20:14:19 +0800474 self.vapi.cli(
475 "lb vip 2001::/16 protocol udp port 20000 encap nat6"
476 " type clusterip target_port 3307")
Hongjun Nid92a0b52018-02-06 23:00:22 +0800477 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800478 self.vapi.cli(
479 "lb as 2001::/16 protocol udp port 20000 2002::%u"
480 % (asid))
Hongjun Nid92a0b52018-02-06 23:00:22 +0800481
482 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
483 self.pg_enable_capture(self.pg_interfaces)
484 self.pg_start()
485 self.checkCapture(encap='nat6', isv4=False)
486
487 finally:
488 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800489 self.vapi.cli(
490 "lb as 2001::/16 protocol udp port 20000 2002::%u del"
491 % (asid))
492 self.vapi.cli(
493 "lb vip 2001::/16 protocol udp port 20000 encap nat6"
494 " type clusterip target_port 3307 del")
Hongjun Nid92a0b52018-02-06 23:00:22 +0800495 self.vapi.cli("test lb flowtable flush")