blob: 4603bd10db8dcec48b53aea9fe4f2aba6f741c49 [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):
Pierre Pfisterf588f352016-10-07 16:31:57 +010035 """ Load Balancer Test Case """
36
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
56 dst4 = VppIpRoute(cls, "10.0.0.0", 24,
57 [VppRoutePath(cls.pg1.remote_ip4,
58 INVALID_INDEX)],
59 register=False)
60 dst4.add_vpp_config()
61 dst6 = VppIpRoute(cls, "2002::", 16,
62 [VppRoutePath(cls.pg1.remote_ip6,
63 INVALID_INDEX)],
64 register=False)
65 dst6.add_vpp_config()
Paul Vinciguerraf7f13342019-03-19 11:54:39 -070066 cls.vapi.lb_conf(ip4_src_address="39.40.41.42",
67 ip6_src_address="2004::1")
Klement Sekeraf62ae122016-10-11 11:47:09 +020068 except Exception:
Pierre Pfisterf588f352016-10-07 16:31:57 +010069 super(TestLB, cls).tearDownClass()
70 raise
71
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070072 @classmethod
73 def tearDownClass(cls):
74 super(TestLB, cls).tearDownClass()
75
Pierre Pfisterf588f352016-10-07 16:31:57 +010076 def tearDown(self):
Klement Sekeraf62ae122016-10-11 11:47:09 +020077 super(TestLB, self).tearDown()
Paul Vinciguerra90cf21b2019-03-13 09:23:05 -070078
79 def show_commands_at_teardown(self):
80 self.logger.info(self.vapi.cli("show lb vip verbose"))
Pierre Pfisterf588f352016-10-07 16:31:57 +010081
82 def getIPv4Flow(self, id):
83 return (IP(dst="90.0.%u.%u" % (id / 255, id % 255),
Klement Sekeraf62ae122016-10-11 11:47:09 +020084 src="40.0.%u.%u" % (id / 255, id % 255)) /
Hongjun Ni219cc902018-06-28 20:14:19 +080085 UDP(sport=10000 + id, dport=20000))
Pierre Pfisterf588f352016-10-07 16:31:57 +010086
87 def getIPv6Flow(self, id):
88 return (IPv6(dst="2001::%u" % (id), src="fd00:f00d:ffff::%u" % (id)) /
Hongjun Ni219cc902018-06-28 20:14:19 +080089 UDP(sport=10000 + id, dport=20000))
Pierre Pfisterf588f352016-10-07 16:31:57 +010090
Klement Sekeraf62ae122016-10-11 11:47:09 +020091 def generatePackets(self, src_if, isv4):
Klement Sekeradab231a2016-12-21 08:50:14 +010092 self.reset_packet_infos()
Pierre Pfisterf588f352016-10-07 16:31:57 +010093 pkts = []
94 for pktid in self.packets:
Klement Sekeradab231a2016-12-21 08:50:14 +010095 info = self.create_packet_info(src_if, self.pg1)
Pierre Pfisterf588f352016-10-07 16:31:57 +010096 payload = self.info_to_payload(info)
97 ip = self.getIPv4Flow(pktid) if isv4 else self.getIPv6Flow(pktid)
Klement Sekeraf62ae122016-10-11 11:47:09 +020098 packet = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
99 ip /
100 Raw(payload))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100101 self.extend_packet(packet, 128)
102 info.data = packet.copy()
103 pkts.append(packet)
104 return pkts
105
106 def checkInner(self, gre, isv4):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200107 IPver = IP if isv4 else IPv6
Pierre Pfisterf588f352016-10-07 16:31:57 +0100108 self.assertEqual(gre.proto, 0x0800 if isv4 else 0x86DD)
109 self.assertEqual(gre.flags, 0)
110 self.assertEqual(gre.version, 0)
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700111 inner = IPver(scapy.compat.raw(gre.payload))
Paul Vinciguerraeaea4212019-03-06 11:58:06 -0800112 payload_info = self.payload_to_info(inner[Raw])
Klement Sekeradab231a2016-12-21 08:50:14 +0100113 self.info = self.packet_infos[payload_info.index]
114 self.assertEqual(payload_info.src, self.pg0.sw_if_index)
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700115 self.assertEqual(scapy.compat.raw(inner),
116 scapy.compat.raw(self.info.data[IPver]))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100117
Hongjun Ni647f6092018-01-23 19:17:23 +0800118 def checkCapture(self, encap, isv4):
Klement Sekera65cc8c02016-12-18 15:49:54 +0100119 self.pg0.assert_nothing_captured()
Klement Sekeradab231a2016-12-21 08:50:14 +0100120 out = self.pg1.get_capture(len(self.packets))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100121
122 load = [0] * len(self.ass)
123 self.info = None
124 for p in out:
125 try:
126 asid = 0
127 gre = None
Hongjun Ni647f6092018-01-23 19:17:23 +0800128 if (encap == 'gre4'):
Pierre Pfisterf588f352016-10-07 16:31:57 +0100129 ip = p[IP]
Pierre Pfisterf588f352016-10-07 16:31:57 +0100130 asid = int(ip.dst.split(".")[3])
131 self.assertEqual(ip.version, 4)
132 self.assertEqual(ip.flags, 0)
133 self.assertEqual(ip.src, "39.40.41.42")
134 self.assertEqual(ip.dst, "10.0.0.%u" % asid)
135 self.assertEqual(ip.proto, 47)
136 self.assertEqual(len(ip.options), 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200137 gre = p[GRE]
Hongjun Ni647f6092018-01-23 19:17:23 +0800138 self.checkInner(gre, isv4)
139 elif (encap == 'gre6'):
Pierre Pfisterf588f352016-10-07 16:31:57 +0100140 ip = p[IPv6]
Pierre Pfisterf588f352016-10-07 16:31:57 +0100141 asid = ip.dst.split(":")
142 asid = asid[len(asid) - 1]
Klement Sekeraf62ae122016-10-11 11:47:09 +0200143 asid = 0 if asid == "" else int(asid)
Pierre Pfisterf588f352016-10-07 16:31:57 +0100144 self.assertEqual(ip.version, 6)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200145 self.assertEqual(ip.tc, 0)
146 self.assertEqual(ip.fl, 0)
147 self.assertEqual(ip.src, "2004::1")
148 self.assertEqual(
149 socket.inet_pton(socket.AF_INET6, ip.dst),
150 socket.inet_pton(socket.AF_INET6, "2002::%u" % asid)
151 )
152 self.assertEqual(ip.nh, 47)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200153 # self.assertEqual(len(ip.options), 0)
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700154 gre = GRE(scapy.compat.raw(p[IPv6].payload))
Hongjun Ni647f6092018-01-23 19:17:23 +0800155 self.checkInner(gre, isv4)
Hongjun Nid92a0b52018-02-06 23:00:22 +0800156 elif (encap == 'l3dsr'):
Hongjun Ni647f6092018-01-23 19:17:23 +0800157 ip = p[IP]
158 asid = int(ip.dst.split(".")[3])
159 self.assertEqual(ip.version, 4)
160 self.assertEqual(ip.flags, 0)
161 self.assertEqual(ip.dst, "10.0.0.%u" % asid)
162 self.assertEqual(ip.tos, 0x1c)
163 self.assertEqual(len(ip.options), 0)
Hongjun Ni6fb0d9b2018-06-08 07:12:05 +0800164 self.assert_ip_checksum_valid(p)
165 if ip.proto == IP_PROTOS.tcp:
166 self.assert_tcp_checksum_valid(p)
167 elif ip.proto == IP_PROTOS.udp:
168 self.assert_udp_checksum_valid(p)
Hongjun Nid92a0b52018-02-06 23:00:22 +0800169 elif (encap == 'nat4'):
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)
175 self.assertEqual(ip.proto, 17)
176 self.assertEqual(len(ip.options), 0)
Hongjun Nid92a0b52018-02-06 23:00:22 +0800177 udp = p[UDP]
178 self.assertEqual(udp.dport, 3307)
179 elif (encap == 'nat6'):
180 ip = p[IPv6]
181 asid = ip.dst.split(":")
182 asid = asid[len(asid) - 1]
183 asid = 0 if asid == "" else int(asid)
184 self.assertEqual(ip.version, 6)
185 self.assertEqual(ip.tc, 0)
186 self.assertEqual(ip.fl, 0)
187 self.assertEqual(
188 socket.inet_pton(socket.AF_INET6, ip.dst),
189 socket.inet_pton(socket.AF_INET6, "2002::%u" % asid)
190 )
191 self.assertEqual(ip.nh, 17)
192 self.assertGreaterEqual(ip.hlim, 63)
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700193 udp = UDP(scapy.compat.raw(p[IPv6].payload))
Hongjun Nid92a0b52018-02-06 23:00:22 +0800194 self.assertEqual(udp.dport, 3307)
Pierre Pfisterf588f352016-10-07 16:31:57 +0100195 load[asid] += 1
196 except:
Klement Sekera7bb873a2016-11-18 07:38:42 +0100197 self.logger.error(ppp("Unexpected or invalid packet:", p))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100198 raise
199
Paul Vinciguerraf7f13342019-03-19 11:54:39 -0700200 # This is just to roughly check that the balancing algorithm
201 # is not completely biased.
Pierre Pfisterf588f352016-10-07 16:31:57 +0100202 for asid in self.ass:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200203 if load[asid] < len(self.packets) / (len(self.ass) * 2):
Gabriel Ganne8e66b9b2017-12-14 16:20:37 +0100204 self.logger.error(
Klement Sekeraf62ae122016-10-11 11:47:09 +0200205 "ASS is not balanced: load[%d] = %d" % (asid, load[asid]))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100206 raise Exception("Load Balancer algorithm is biased")
207
Pierre Pfisterf588f352016-10-07 16:31:57 +0100208 def test_lb_ip4_gre4(self):
Hongjun Ni219cc902018-06-28 20:14:19 +0800209 """ Load Balancer IP4 GRE4 on vip case """
Klement Sekeraf62ae122016-10-11 11:47:09 +0200210 try:
Hongjun Ni219cc902018-06-28 20:14:19 +0800211 self.vapi.cli(
212 "lb vip 90.0.0.0/8 encap gre4")
Klement Sekeraf62ae122016-10-11 11:47:09 +0200213 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800214 self.vapi.cli(
215 "lb as 90.0.0.0/8 10.0.0.%u"
216 % (asid))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100217
Klement Sekeraf62ae122016-10-11 11:47:09 +0200218 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
219 self.pg_enable_capture(self.pg_interfaces)
220 self.pg_start()
Hongjun Ni647f6092018-01-23 19:17:23 +0800221 self.checkCapture(encap='gre4', isv4=True)
Pierre Pfisterf588f352016-10-07 16:31:57 +0100222
Klement Sekeraf62ae122016-10-11 11:47:09 +0200223 finally:
224 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800225 self.vapi.cli(
226 "lb as 90.0.0.0/8 10.0.0.%u del"
227 % (asid))
228 self.vapi.cli(
229 "lb vip 90.0.0.0/8 encap gre4 del")
Gabriel Ganneb3d1b202017-10-30 15:44:31 +0100230 self.vapi.cli("test lb flowtable flush")
Pierre Pfisterf588f352016-10-07 16:31:57 +0100231
232 def test_lb_ip6_gre4(self):
Hongjun Ni219cc902018-06-28 20:14:19 +0800233 """ Load Balancer IP6 GRE4 on vip case """
Pierre Pfisterf588f352016-10-07 16:31:57 +0100234
Klement Sekeraf62ae122016-10-11 11:47:09 +0200235 try:
Hongjun Ni219cc902018-06-28 20:14:19 +0800236 self.vapi.cli(
237 "lb vip 2001::/16 encap gre4")
Klement Sekeraf62ae122016-10-11 11:47:09 +0200238 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800239 self.vapi.cli(
240 "lb as 2001::/16 10.0.0.%u"
241 % (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
Hongjun Ni647f6092018-01-23 19:17:23 +0800247 self.checkCapture(encap='gre4', isv4=False)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200248 finally:
249 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800250 self.vapi.cli(
251 "lb as 2001::/16 10.0.0.%u del"
252 % (asid))
253 self.vapi.cli(
254 "lb vip 2001::/16 encap gre4 del")
Gabriel Ganneb3d1b202017-10-30 15:44:31 +0100255 self.vapi.cli("test lb flowtable flush")
Pierre Pfisterf588f352016-10-07 16:31:57 +0100256
257 def test_lb_ip4_gre6(self):
Hongjun Ni219cc902018-06-28 20:14:19 +0800258 """ Load Balancer IP4 GRE6 on vip case """
Klement Sekeraf62ae122016-10-11 11:47:09 +0200259 try:
Hongjun Ni219cc902018-06-28 20:14:19 +0800260 self.vapi.cli(
261 "lb vip 90.0.0.0/8 encap gre6")
Klement Sekeraf62ae122016-10-11 11:47:09 +0200262 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800263 self.vapi.cli(
264 "lb as 90.0.0.0/8 2002::%u"
265 % (asid))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100266
Klement Sekeraf62ae122016-10-11 11:47:09 +0200267 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
268 self.pg_enable_capture(self.pg_interfaces)
269 self.pg_start()
Pierre Pfisterf588f352016-10-07 16:31:57 +0100270
Hongjun Ni647f6092018-01-23 19:17:23 +0800271 self.checkCapture(encap='gre6', isv4=True)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200272 finally:
273 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800274 self.vapi.cli(
275 "lb as 90.0.0.0/8 2002::%u del"
276 % (asid))
277 self.vapi.cli(
278 "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):
Hongjun Ni219cc902018-06-28 20:14:19 +0800282 """ Load Balancer IP6 GRE6 on vip case """
Klement Sekeraf62ae122016-10-11 11:47:09 +0200283 try:
Hongjun Ni219cc902018-06-28 20:14:19 +0800284 self.vapi.cli(
285 "lb vip 2001::/16 encap gre6")
Klement Sekeraf62ae122016-10-11 11:47:09 +0200286 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800287 self.vapi.cli(
288 "lb as 2001::/16 2002::%u"
289 % (asid))
Pierre Pfisterf588f352016-10-07 16:31:57 +0100290
Klement Sekeraf62ae122016-10-11 11:47:09 +0200291 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
292 self.pg_enable_capture(self.pg_interfaces)
293 self.pg_start()
Pierre Pfisterf588f352016-10-07 16:31:57 +0100294
Hongjun Ni647f6092018-01-23 19:17:23 +0800295 self.checkCapture(encap='gre6', isv4=False)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200296 finally:
297 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800298 self.vapi.cli(
299 "lb as 2001::/16 2002::%u del"
300 % (asid))
301 self.vapi.cli(
302 "lb vip 2001::/16 encap gre6 del")
303 self.vapi.cli("test lb flowtable flush")
304
305 def test_lb_ip4_gre4_port(self):
306 """ Load Balancer IP4 GRE4 on per-port-vip case """
307 try:
308 self.vapi.cli(
309 "lb vip 90.0.0.0/8 protocol udp port 20000 encap gre4")
310 for asid in self.ass:
311 self.vapi.cli(
312 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u"
313 % (asid))
314
315 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
316 self.pg_enable_capture(self.pg_interfaces)
317 self.pg_start()
318 self.checkCapture(encap='gre4', isv4=True)
319
320 finally:
321 for asid in self.ass:
322 self.vapi.cli(
323 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u del"
324 % (asid))
325 self.vapi.cli(
326 "lb vip 90.0.0.0/8 protocol udp port 20000 encap gre4 del")
327 self.vapi.cli("test lb flowtable flush")
328
329 def test_lb_ip6_gre4_port(self):
330 """ Load Balancer IP6 GRE4 on per-port-vip case """
331
332 try:
333 self.vapi.cli(
334 "lb vip 2001::/16 protocol udp port 20000 encap gre4")
335 for asid in self.ass:
336 self.vapi.cli(
337 "lb as 2001::/16 protocol udp port 20000 10.0.0.%u"
338 % (asid))
339
340 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
341 self.pg_enable_capture(self.pg_interfaces)
342 self.pg_start()
343
344 self.checkCapture(encap='gre4', isv4=False)
345 finally:
346 for asid in self.ass:
347 self.vapi.cli(
348 "lb as 2001::/16 protocol udp port 20000 10.0.0.%u del"
349 % (asid))
350 self.vapi.cli(
351 "lb vip 2001::/16 protocol udp port 20000 encap gre4 del")
352 self.vapi.cli("test lb flowtable flush")
353
354 def test_lb_ip4_gre6_port(self):
355 """ Load Balancer IP4 GRE6 on per-port-vip case """
356 try:
357 self.vapi.cli(
358 "lb vip 90.0.0.0/8 protocol udp port 20000 encap gre6")
359 for asid in self.ass:
360 self.vapi.cli(
361 "lb as 90.0.0.0/8 protocol udp port 20000 2002::%u"
362 % (asid))
363
364 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
365 self.pg_enable_capture(self.pg_interfaces)
366 self.pg_start()
367
368 self.checkCapture(encap='gre6', isv4=True)
369 finally:
370 for asid in self.ass:
371 self.vapi.cli(
372 "lb as 90.0.0.0/8 protocol udp port 20000 2002::%u del"
373 % (asid))
374 self.vapi.cli(
375 "lb vip 90.0.0.0/8 protocol udp port 20000 encap gre6 del")
376 self.vapi.cli("test lb flowtable flush")
377
378 def test_lb_ip6_gre6_port(self):
379 """ Load Balancer IP6 GRE6 on per-port-vip case """
380 try:
381 self.vapi.cli(
382 "lb vip 2001::/16 protocol udp port 20000 encap gre6")
383 for asid in self.ass:
384 self.vapi.cli(
385 "lb as 2001::/16 protocol udp port 20000 2002::%u"
386 % (asid))
387
388 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
389 self.pg_enable_capture(self.pg_interfaces)
390 self.pg_start()
391
392 self.checkCapture(encap='gre6', isv4=False)
393 finally:
394 for asid in self.ass:
395 self.vapi.cli(
396 "lb as 2001::/16 protocol udp port 20000 2002::%u del"
397 % (asid))
398 self.vapi.cli(
399 "lb vip 2001::/16 protocol udp port 20000 encap gre6 del")
Gabriel Ganneb3d1b202017-10-30 15:44:31 +0100400 self.vapi.cli("test lb flowtable flush")
Hongjun Ni647f6092018-01-23 19:17:23 +0800401
402 def test_lb_ip4_l3dsr(self):
Hongjun Ni219cc902018-06-28 20:14:19 +0800403 """ Load Balancer IP4 L3DSR on vip case """
Hongjun Ni647f6092018-01-23 19:17:23 +0800404 try:
Hongjun Ni219cc902018-06-28 20:14:19 +0800405 self.vapi.cli(
406 "lb vip 90.0.0.0/8 encap l3dsr dscp 7")
Hongjun Ni647f6092018-01-23 19:17:23 +0800407 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800408 self.vapi.cli(
409 "lb as 90.0.0.0/8 10.0.0.%u"
410 % (asid))
Hongjun Ni647f6092018-01-23 19:17:23 +0800411
412 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
413 self.pg_enable_capture(self.pg_interfaces)
414 self.pg_start()
415 self.checkCapture(encap='l3dsr', isv4=True)
416
417 finally:
418 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800419 self.vapi.cli(
420 "lb as 90.0.0.0/8 10.0.0.%u del"
421 % (asid))
422 self.vapi.cli(
423 "lb vip 90.0.0.0/8 encap l3dsr"
424 " dscp 7 del")
Hongjun Ni647f6092018-01-23 19:17:23 +0800425 self.vapi.cli("test lb flowtable flush")
Hongjun Nid92a0b52018-02-06 23:00:22 +0800426
Hongjun Ni219cc902018-06-28 20:14:19 +0800427 def test_lb_ip4_l3dsr_port(self):
428 """ Load Balancer IP4 L3DSR on per-port-vip case """
Hongjun Nid92a0b52018-02-06 23:00:22 +0800429 try:
Hongjun Ni219cc902018-06-28 20:14:19 +0800430 self.vapi.cli(
431 "lb vip 90.0.0.0/8 protocol udp port 20000 encap l3dsr dscp 7")
Hongjun Nid92a0b52018-02-06 23:00:22 +0800432 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800433 self.vapi.cli(
434 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u"
435 % (asid))
436
437 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
438 self.pg_enable_capture(self.pg_interfaces)
439 self.pg_start()
440 self.checkCapture(encap='l3dsr', isv4=True)
441
442 finally:
443 for asid in self.ass:
444 self.vapi.cli(
445 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u del"
446 % (asid))
447 self.vapi.cli(
448 "lb vip 90.0.0.0/8 protocol udp port 20000 encap l3dsr"
449 " dscp 7 del")
450 self.vapi.cli("test lb flowtable flush")
451
452 def test_lb_ip4_nat4_port(self):
453 """ Load Balancer IP4 NAT4 on per-port-vip case """
454 try:
455 self.vapi.cli(
456 "lb vip 90.0.0.0/8 protocol udp port 20000 encap nat4"
457 " type clusterip target_port 3307")
458 for asid in self.ass:
459 self.vapi.cli(
460 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u"
461 % (asid))
Hongjun Nid92a0b52018-02-06 23:00:22 +0800462
463 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
464 self.pg_enable_capture(self.pg_interfaces)
465 self.pg_start()
466 self.checkCapture(encap='nat4', isv4=True)
467
468 finally:
469 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800470 self.vapi.cli(
471 "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u del"
472 % (asid))
473 self.vapi.cli(
474 "lb vip 90.0.0.0/8 protocol udp port 20000 encap nat4"
475 " type clusterip target_port 3307 del")
Hongjun Nid92a0b52018-02-06 23:00:22 +0800476 self.vapi.cli("test lb flowtable flush")
477
Hongjun Ni219cc902018-06-28 20:14:19 +0800478 def test_lb_ip6_nat6_port(self):
479 """ Load Balancer IP6 NAT6 on per-port-vip case """
Hongjun Nid92a0b52018-02-06 23:00:22 +0800480 try:
Hongjun Ni219cc902018-06-28 20:14:19 +0800481 self.vapi.cli(
482 "lb vip 2001::/16 protocol udp port 20000 encap nat6"
483 " type clusterip target_port 3307")
Hongjun Nid92a0b52018-02-06 23:00:22 +0800484 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800485 self.vapi.cli(
486 "lb as 2001::/16 protocol udp port 20000 2002::%u"
487 % (asid))
Hongjun Nid92a0b52018-02-06 23:00:22 +0800488
489 self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
490 self.pg_enable_capture(self.pg_interfaces)
491 self.pg_start()
492 self.checkCapture(encap='nat6', isv4=False)
493
494 finally:
495 for asid in self.ass:
Hongjun Ni219cc902018-06-28 20:14:19 +0800496 self.vapi.cli(
497 "lb as 2001::/16 protocol udp port 20000 2002::%u del"
498 % (asid))
499 self.vapi.cli(
500 "lb vip 2001::/16 protocol udp port 20000 encap nat6"
501 " type clusterip target_port 3307 del")
Hongjun Nid92a0b52018-02-06 23:00:22 +0800502 self.vapi.cli("test lb flowtable flush")