2016-10-07 16:31:57 +01:00
|
|
|
import socket
|
|
|
|
|
2019-03-10 10:04:23 -07:00
|
|
|
import scapy.compat
|
2016-10-07 16:31:57 +01:00
|
|
|
from scapy.layers.inet import IP, UDP
|
2016-12-18 15:49:54 +01:00
|
|
|
from scapy.layers.inet6 import IPv6
|
2016-10-11 11:47:09 +02:00
|
|
|
from scapy.layers.l2 import Ether, GRE
|
|
|
|
from scapy.packet import Raw
|
2018-06-08 07:12:05 +08:00
|
|
|
from scapy.data import IP_PROTOS
|
2016-10-11 11:47:09 +02:00
|
|
|
|
|
|
|
from framework import VppTestCase
|
2016-11-18 07:38:42 +01:00
|
|
|
from util import ppp
|
2016-10-11 11:47:09 +02:00
|
|
|
|
|
|
|
""" TestLB is a subclass of VPPTestCase classes.
|
|
|
|
|
|
|
|
TestLB class defines Load Balancer test cases for:
|
2018-06-28 20:14:19 +08:00
|
|
|
- IP4 to GRE4 encap on per-port vip case
|
|
|
|
- IP4 to GRE6 encap on per-port vip case
|
|
|
|
- IP6 to GRE4 encap on per-port vip case
|
|
|
|
- IP6 to GRE6 encap on per-port vip case
|
|
|
|
- IP4 to L3DSR encap on vip case
|
|
|
|
- IP4 to L3DSR encap on per-port vip case
|
|
|
|
- IP4 to NAT4 encap on per-port vip case
|
|
|
|
- IP6 to NAT6 encap on per-port vip case
|
2016-10-11 11:47:09 +02:00
|
|
|
|
|
|
|
As stated in comments below, GRE has issues with IPv6.
|
|
|
|
All test cases involving IPv6 are executed, but
|
|
|
|
received packets are not parsed and checked.
|
|
|
|
|
|
|
|
"""
|
2016-10-07 16:31:57 +01:00
|
|
|
|
2016-10-11 11:47:09 +02:00
|
|
|
|
|
|
|
class TestLB(VppTestCase):
|
2016-10-07 16:31:57 +01:00
|
|
|
""" Load Balancer Test Case """
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super(TestLB, cls).setUpClass()
|
|
|
|
|
|
|
|
cls.ass = range(5)
|
2018-06-28 20:14:19 +08:00
|
|
|
cls.packets = range(1)
|
2016-10-07 16:31:57 +01:00
|
|
|
|
|
|
|
try:
|
2016-10-11 11:47:09 +02:00
|
|
|
cls.create_pg_interfaces(range(2))
|
|
|
|
cls.interfaces = list(cls.pg_interfaces)
|
|
|
|
|
|
|
|
for i in cls.interfaces:
|
|
|
|
i.admin_up()
|
|
|
|
i.config_ip4()
|
|
|
|
i.config_ip6()
|
|
|
|
i.disable_ipv6_ra()
|
|
|
|
i.resolve_arp()
|
|
|
|
i.resolve_ndp()
|
|
|
|
dst4 = socket.inet_pton(socket.AF_INET, "10.0.0.0")
|
|
|
|
dst6 = socket.inet_pton(socket.AF_INET6, "2002::")
|
2019-03-11 19:23:25 +01:00
|
|
|
cls.vapi.ip_add_del_route(dst_address=dst4, dst_address_length=24,
|
|
|
|
next_hop_address=cls.pg1.remote_ip4n)
|
|
|
|
cls.vapi.ip_add_del_route(dst_address=dst6, dst_address_length=16,
|
|
|
|
next_hop_address=cls.pg1.remote_ip6n,
|
|
|
|
is_ipv6=1)
|
2019-03-19 11:54:39 -07:00
|
|
|
cls.vapi.lb_conf(ip4_src_address="39.40.41.42",
|
|
|
|
ip6_src_address="2004::1")
|
2016-10-11 11:47:09 +02:00
|
|
|
except Exception:
|
2016-10-07 16:31:57 +01:00
|
|
|
super(TestLB, cls).tearDownClass()
|
|
|
|
raise
|
|
|
|
|
2019-03-12 19:23:27 -07:00
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(TestLB, cls).tearDownClass()
|
|
|
|
|
2016-10-07 16:31:57 +01:00
|
|
|
def tearDown(self):
|
2016-10-11 11:47:09 +02:00
|
|
|
super(TestLB, self).tearDown()
|
|
|
|
if not self.vpp_dead:
|
2016-11-18 07:38:42 +01:00
|
|
|
self.logger.info(self.vapi.cli("show lb vip verbose"))
|
2016-10-07 16:31:57 +01:00
|
|
|
|
|
|
|
def getIPv4Flow(self, id):
|
|
|
|
return (IP(dst="90.0.%u.%u" % (id / 255, id % 255),
|
2016-10-11 11:47:09 +02:00
|
|
|
src="40.0.%u.%u" % (id / 255, id % 255)) /
|
2018-06-28 20:14:19 +08:00
|
|
|
UDP(sport=10000 + id, dport=20000))
|
2016-10-07 16:31:57 +01:00
|
|
|
|
|
|
|
def getIPv6Flow(self, id):
|
|
|
|
return (IPv6(dst="2001::%u" % (id), src="fd00:f00d:ffff::%u" % (id)) /
|
2018-06-28 20:14:19 +08:00
|
|
|
UDP(sport=10000 + id, dport=20000))
|
2016-10-07 16:31:57 +01:00
|
|
|
|
2016-10-11 11:47:09 +02:00
|
|
|
def generatePackets(self, src_if, isv4):
|
2016-12-21 08:50:14 +01:00
|
|
|
self.reset_packet_infos()
|
2016-10-07 16:31:57 +01:00
|
|
|
pkts = []
|
|
|
|
for pktid in self.packets:
|
2016-12-21 08:50:14 +01:00
|
|
|
info = self.create_packet_info(src_if, self.pg1)
|
2016-10-07 16:31:57 +01:00
|
|
|
payload = self.info_to_payload(info)
|
|
|
|
ip = self.getIPv4Flow(pktid) if isv4 else self.getIPv6Flow(pktid)
|
2016-10-11 11:47:09 +02:00
|
|
|
packet = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
|
|
|
|
ip /
|
|
|
|
Raw(payload))
|
2016-10-07 16:31:57 +01:00
|
|
|
self.extend_packet(packet, 128)
|
|
|
|
info.data = packet.copy()
|
|
|
|
pkts.append(packet)
|
|
|
|
return pkts
|
|
|
|
|
|
|
|
def checkInner(self, gre, isv4):
|
2016-10-11 11:47:09 +02:00
|
|
|
IPver = IP if isv4 else IPv6
|
2016-10-07 16:31:57 +01:00
|
|
|
self.assertEqual(gre.proto, 0x0800 if isv4 else 0x86DD)
|
|
|
|
self.assertEqual(gre.flags, 0)
|
|
|
|
self.assertEqual(gre.version, 0)
|
2019-03-10 10:04:23 -07:00
|
|
|
inner = IPver(scapy.compat.raw(gre.payload))
|
2019-03-06 11:58:06 -08:00
|
|
|
payload_info = self.payload_to_info(inner[Raw])
|
2016-12-21 08:50:14 +01:00
|
|
|
self.info = self.packet_infos[payload_info.index]
|
|
|
|
self.assertEqual(payload_info.src, self.pg0.sw_if_index)
|
2019-03-10 10:04:23 -07:00
|
|
|
self.assertEqual(scapy.compat.raw(inner),
|
|
|
|
scapy.compat.raw(self.info.data[IPver]))
|
2016-10-07 16:31:57 +01:00
|
|
|
|
2018-01-23 19:17:23 +08:00
|
|
|
def checkCapture(self, encap, isv4):
|
2016-12-18 15:49:54 +01:00
|
|
|
self.pg0.assert_nothing_captured()
|
2016-12-21 08:50:14 +01:00
|
|
|
out = self.pg1.get_capture(len(self.packets))
|
2016-10-07 16:31:57 +01:00
|
|
|
|
|
|
|
load = [0] * len(self.ass)
|
|
|
|
self.info = None
|
|
|
|
for p in out:
|
|
|
|
try:
|
|
|
|
asid = 0
|
|
|
|
gre = None
|
2018-01-23 19:17:23 +08:00
|
|
|
if (encap == 'gre4'):
|
2016-10-07 16:31:57 +01:00
|
|
|
ip = p[IP]
|
|
|
|
asid = int(ip.dst.split(".")[3])
|
|
|
|
self.assertEqual(ip.version, 4)
|
|
|
|
self.assertEqual(ip.flags, 0)
|
|
|
|
self.assertEqual(ip.src, "39.40.41.42")
|
|
|
|
self.assertEqual(ip.dst, "10.0.0.%u" % asid)
|
|
|
|
self.assertEqual(ip.proto, 47)
|
|
|
|
self.assertEqual(len(ip.options), 0)
|
2016-10-11 11:47:09 +02:00
|
|
|
gre = p[GRE]
|
2018-01-23 19:17:23 +08:00
|
|
|
self.checkInner(gre, isv4)
|
|
|
|
elif (encap == 'gre6'):
|
2016-10-07 16:31:57 +01:00
|
|
|
ip = p[IPv6]
|
|
|
|
asid = ip.dst.split(":")
|
|
|
|
asid = asid[len(asid) - 1]
|
2016-10-11 11:47:09 +02:00
|
|
|
asid = 0 if asid == "" else int(asid)
|
2016-10-07 16:31:57 +01:00
|
|
|
self.assertEqual(ip.version, 6)
|
2016-10-11 11:47:09 +02:00
|
|
|
self.assertEqual(ip.tc, 0)
|
|
|
|
self.assertEqual(ip.fl, 0)
|
|
|
|
self.assertEqual(ip.src, "2004::1")
|
|
|
|
self.assertEqual(
|
|
|
|
socket.inet_pton(socket.AF_INET6, ip.dst),
|
|
|
|
socket.inet_pton(socket.AF_INET6, "2002::%u" % asid)
|
|
|
|
)
|
|
|
|
self.assertEqual(ip.nh, 47)
|
|
|
|
# self.assertEqual(len(ip.options), 0)
|
2019-03-10 10:04:23 -07:00
|
|
|
gre = GRE(scapy.compat.raw(p[IPv6].payload))
|
2018-01-23 19:17:23 +08:00
|
|
|
self.checkInner(gre, isv4)
|
2018-02-06 23:00:22 +08:00
|
|
|
elif (encap == 'l3dsr'):
|
2018-01-23 19:17:23 +08:00
|
|
|
ip = p[IP]
|
|
|
|
asid = int(ip.dst.split(".")[3])
|
|
|
|
self.assertEqual(ip.version, 4)
|
|
|
|
self.assertEqual(ip.flags, 0)
|
|
|
|
self.assertEqual(ip.dst, "10.0.0.%u" % asid)
|
|
|
|
self.assertEqual(ip.tos, 0x1c)
|
|
|
|
self.assertEqual(len(ip.options), 0)
|
2018-06-08 07:12:05 +08:00
|
|
|
self.assert_ip_checksum_valid(p)
|
|
|
|
if ip.proto == IP_PROTOS.tcp:
|
|
|
|
self.assert_tcp_checksum_valid(p)
|
|
|
|
elif ip.proto == IP_PROTOS.udp:
|
|
|
|
self.assert_udp_checksum_valid(p)
|
2018-02-06 23:00:22 +08:00
|
|
|
elif (encap == 'nat4'):
|
|
|
|
ip = p[IP]
|
|
|
|
asid = int(ip.dst.split(".")[3])
|
|
|
|
self.assertEqual(ip.version, 4)
|
|
|
|
self.assertEqual(ip.flags, 0)
|
|
|
|
self.assertEqual(ip.dst, "10.0.0.%u" % asid)
|
|
|
|
self.assertEqual(ip.proto, 17)
|
|
|
|
self.assertEqual(len(ip.options), 0)
|
|
|
|
udp = p[UDP]
|
|
|
|
self.assertEqual(udp.dport, 3307)
|
|
|
|
elif (encap == 'nat6'):
|
|
|
|
ip = p[IPv6]
|
|
|
|
asid = ip.dst.split(":")
|
|
|
|
asid = asid[len(asid) - 1]
|
|
|
|
asid = 0 if asid == "" else int(asid)
|
|
|
|
self.assertEqual(ip.version, 6)
|
|
|
|
self.assertEqual(ip.tc, 0)
|
|
|
|
self.assertEqual(ip.fl, 0)
|
|
|
|
self.assertEqual(
|
|
|
|
socket.inet_pton(socket.AF_INET6, ip.dst),
|
|
|
|
socket.inet_pton(socket.AF_INET6, "2002::%u" % asid)
|
|
|
|
)
|
|
|
|
self.assertEqual(ip.nh, 17)
|
|
|
|
self.assertGreaterEqual(ip.hlim, 63)
|
2019-03-10 10:04:23 -07:00
|
|
|
udp = UDP(scapy.compat.raw(p[IPv6].payload))
|
2018-02-06 23:00:22 +08:00
|
|
|
self.assertEqual(udp.dport, 3307)
|
2016-10-07 16:31:57 +01:00
|
|
|
load[asid] += 1
|
|
|
|
except:
|
2016-11-18 07:38:42 +01:00
|
|
|
self.logger.error(ppp("Unexpected or invalid packet:", p))
|
2016-10-07 16:31:57 +01:00
|
|
|
raise
|
|
|
|
|
2019-03-19 11:54:39 -07:00
|
|
|
# This is just to roughly check that the balancing algorithm
|
|
|
|
# is not completely biased.
|
2016-10-07 16:31:57 +01:00
|
|
|
for asid in self.ass:
|
2016-10-11 11:47:09 +02:00
|
|
|
if load[asid] < len(self.packets) / (len(self.ass) * 2):
|
2017-12-14 16:20:37 +01:00
|
|
|
self.logger.error(
|
2016-10-11 11:47:09 +02:00
|
|
|
"ASS is not balanced: load[%d] = %d" % (asid, load[asid]))
|
2016-10-07 16:31:57 +01:00
|
|
|
raise Exception("Load Balancer algorithm is biased")
|
|
|
|
|
|
|
|
def test_lb_ip4_gre4(self):
|
2018-06-28 20:14:19 +08:00
|
|
|
""" Load Balancer IP4 GRE4 on vip case """
|
2016-10-11 11:47:09 +02:00
|
|
|
try:
|
2018-06-28 20:14:19 +08:00
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 90.0.0.0/8 encap gre4")
|
2016-10-11 11:47:09 +02:00
|
|
|
for asid in self.ass:
|
2018-06-28 20:14:19 +08:00
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 90.0.0.0/8 10.0.0.%u"
|
|
|
|
% (asid))
|
2016-10-07 16:31:57 +01:00
|
|
|
|
2016-10-11 11:47:09 +02:00
|
|
|
self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pg_start()
|
2018-01-23 19:17:23 +08:00
|
|
|
self.checkCapture(encap='gre4', isv4=True)
|
2016-10-07 16:31:57 +01:00
|
|
|
|
2016-10-11 11:47:09 +02:00
|
|
|
finally:
|
|
|
|
for asid in self.ass:
|
2018-06-28 20:14:19 +08:00
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 90.0.0.0/8 10.0.0.%u del"
|
|
|
|
% (asid))
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 90.0.0.0/8 encap gre4 del")
|
2017-10-30 15:44:31 +01:00
|
|
|
self.vapi.cli("test lb flowtable flush")
|
2016-10-07 16:31:57 +01:00
|
|
|
|
|
|
|
def test_lb_ip6_gre4(self):
|
2018-06-28 20:14:19 +08:00
|
|
|
""" Load Balancer IP6 GRE4 on vip case """
|
2016-10-07 16:31:57 +01:00
|
|
|
|
2016-10-11 11:47:09 +02:00
|
|
|
try:
|
2018-06-28 20:14:19 +08:00
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 2001::/16 encap gre4")
|
2016-10-11 11:47:09 +02:00
|
|
|
for asid in self.ass:
|
2018-06-28 20:14:19 +08:00
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 2001::/16 10.0.0.%u"
|
|
|
|
% (asid))
|
2016-10-07 16:31:57 +01:00
|
|
|
|
2016-10-11 11:47:09 +02:00
|
|
|
self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pg_start()
|
2016-10-07 16:31:57 +01:00
|
|
|
|
2018-01-23 19:17:23 +08:00
|
|
|
self.checkCapture(encap='gre4', isv4=False)
|
2016-10-11 11:47:09 +02:00
|
|
|
finally:
|
|
|
|
for asid in self.ass:
|
2018-06-28 20:14:19 +08:00
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 2001::/16 10.0.0.%u del"
|
|
|
|
% (asid))
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 2001::/16 encap gre4 del")
|
2017-10-30 15:44:31 +01:00
|
|
|
self.vapi.cli("test lb flowtable flush")
|
2016-10-07 16:31:57 +01:00
|
|
|
|
|
|
|
def test_lb_ip4_gre6(self):
|
2018-06-28 20:14:19 +08:00
|
|
|
""" Load Balancer IP4 GRE6 on vip case """
|
2016-10-11 11:47:09 +02:00
|
|
|
try:
|
2018-06-28 20:14:19 +08:00
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 90.0.0.0/8 encap gre6")
|
2016-10-11 11:47:09 +02:00
|
|
|
for asid in self.ass:
|
2018-06-28 20:14:19 +08:00
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 90.0.0.0/8 2002::%u"
|
|
|
|
% (asid))
|
2016-10-11 11:47:09 +02:00
|
|
|
|
|
|
|
self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pg_start()
|
|
|
|
|
2018-01-23 19:17:23 +08:00
|
|
|
self.checkCapture(encap='gre6', isv4=True)
|
2016-10-11 11:47:09 +02:00
|
|
|
finally:
|
|
|
|
for asid in self.ass:
|
2018-06-28 20:14:19 +08:00
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 90.0.0.0/8 2002::%u del"
|
|
|
|
% (asid))
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 90.0.0.0/8 encap gre6 del")
|
2017-10-30 15:44:31 +01:00
|
|
|
self.vapi.cli("test lb flowtable flush")
|
2016-10-07 16:31:57 +01:00
|
|
|
|
|
|
|
def test_lb_ip6_gre6(self):
|
2018-06-28 20:14:19 +08:00
|
|
|
""" Load Balancer IP6 GRE6 on vip case """
|
2016-10-11 11:47:09 +02:00
|
|
|
try:
|
2018-06-28 20:14:19 +08:00
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 2001::/16 encap gre6")
|
2016-10-11 11:47:09 +02:00
|
|
|
for asid in self.ass:
|
2018-06-28 20:14:19 +08:00
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 2001::/16 2002::%u"
|
|
|
|
% (asid))
|
2016-10-11 11:47:09 +02:00
|
|
|
|
|
|
|
self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pg_start()
|
|
|
|
|
2018-01-23 19:17:23 +08:00
|
|
|
self.checkCapture(encap='gre6', isv4=False)
|
2016-10-11 11:47:09 +02:00
|
|
|
finally:
|
|
|
|
for asid in self.ass:
|
2018-06-28 20:14:19 +08:00
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 2001::/16 2002::%u del"
|
|
|
|
% (asid))
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 2001::/16 encap gre6 del")
|
|
|
|
self.vapi.cli("test lb flowtable flush")
|
|
|
|
|
|
|
|
def test_lb_ip4_gre4_port(self):
|
|
|
|
""" Load Balancer IP4 GRE4 on per-port-vip case """
|
|
|
|
try:
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 90.0.0.0/8 protocol udp port 20000 encap gre4")
|
|
|
|
for asid in self.ass:
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u"
|
|
|
|
% (asid))
|
|
|
|
|
|
|
|
self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pg_start()
|
|
|
|
self.checkCapture(encap='gre4', isv4=True)
|
|
|
|
|
|
|
|
finally:
|
|
|
|
for asid in self.ass:
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u del"
|
|
|
|
% (asid))
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 90.0.0.0/8 protocol udp port 20000 encap gre4 del")
|
|
|
|
self.vapi.cli("test lb flowtable flush")
|
|
|
|
|
|
|
|
def test_lb_ip6_gre4_port(self):
|
|
|
|
""" Load Balancer IP6 GRE4 on per-port-vip case """
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 2001::/16 protocol udp port 20000 encap gre4")
|
|
|
|
for asid in self.ass:
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 2001::/16 protocol udp port 20000 10.0.0.%u"
|
|
|
|
% (asid))
|
|
|
|
|
|
|
|
self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pg_start()
|
|
|
|
|
|
|
|
self.checkCapture(encap='gre4', isv4=False)
|
|
|
|
finally:
|
|
|
|
for asid in self.ass:
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 2001::/16 protocol udp port 20000 10.0.0.%u del"
|
|
|
|
% (asid))
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 2001::/16 protocol udp port 20000 encap gre4 del")
|
|
|
|
self.vapi.cli("test lb flowtable flush")
|
|
|
|
|
|
|
|
def test_lb_ip4_gre6_port(self):
|
|
|
|
""" Load Balancer IP4 GRE6 on per-port-vip case """
|
|
|
|
try:
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 90.0.0.0/8 protocol udp port 20000 encap gre6")
|
|
|
|
for asid in self.ass:
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 90.0.0.0/8 protocol udp port 20000 2002::%u"
|
|
|
|
% (asid))
|
|
|
|
|
|
|
|
self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pg_start()
|
|
|
|
|
|
|
|
self.checkCapture(encap='gre6', isv4=True)
|
|
|
|
finally:
|
|
|
|
for asid in self.ass:
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 90.0.0.0/8 protocol udp port 20000 2002::%u del"
|
|
|
|
% (asid))
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 90.0.0.0/8 protocol udp port 20000 encap gre6 del")
|
|
|
|
self.vapi.cli("test lb flowtable flush")
|
|
|
|
|
|
|
|
def test_lb_ip6_gre6_port(self):
|
|
|
|
""" Load Balancer IP6 GRE6 on per-port-vip case """
|
|
|
|
try:
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 2001::/16 protocol udp port 20000 encap gre6")
|
|
|
|
for asid in self.ass:
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 2001::/16 protocol udp port 20000 2002::%u"
|
|
|
|
% (asid))
|
|
|
|
|
|
|
|
self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pg_start()
|
|
|
|
|
|
|
|
self.checkCapture(encap='gre6', isv4=False)
|
|
|
|
finally:
|
|
|
|
for asid in self.ass:
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 2001::/16 protocol udp port 20000 2002::%u del"
|
|
|
|
% (asid))
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 2001::/16 protocol udp port 20000 encap gre6 del")
|
2017-10-30 15:44:31 +01:00
|
|
|
self.vapi.cli("test lb flowtable flush")
|
2018-01-23 19:17:23 +08:00
|
|
|
|
|
|
|
def test_lb_ip4_l3dsr(self):
|
2018-06-28 20:14:19 +08:00
|
|
|
""" Load Balancer IP4 L3DSR on vip case """
|
|
|
|
try:
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 90.0.0.0/8 encap l3dsr dscp 7")
|
|
|
|
for asid in self.ass:
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 90.0.0.0/8 10.0.0.%u"
|
|
|
|
% (asid))
|
|
|
|
|
|
|
|
self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pg_start()
|
|
|
|
self.checkCapture(encap='l3dsr', isv4=True)
|
|
|
|
|
|
|
|
finally:
|
|
|
|
for asid in self.ass:
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 90.0.0.0/8 10.0.0.%u del"
|
|
|
|
% (asid))
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 90.0.0.0/8 encap l3dsr"
|
|
|
|
" dscp 7 del")
|
|
|
|
self.vapi.cli("test lb flowtable flush")
|
|
|
|
|
|
|
|
def test_lb_ip4_l3dsr_port(self):
|
|
|
|
""" Load Balancer IP4 L3DSR on per-port-vip case """
|
2018-01-23 19:17:23 +08:00
|
|
|
try:
|
2018-06-28 20:14:19 +08:00
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 90.0.0.0/8 protocol udp port 20000 encap l3dsr dscp 7")
|
2018-01-23 19:17:23 +08:00
|
|
|
for asid in self.ass:
|
2018-06-28 20:14:19 +08:00
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u"
|
|
|
|
% (asid))
|
2018-01-23 19:17:23 +08:00
|
|
|
|
|
|
|
self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pg_start()
|
|
|
|
self.checkCapture(encap='l3dsr', isv4=True)
|
|
|
|
|
|
|
|
finally:
|
|
|
|
for asid in self.ass:
|
2018-06-28 20:14:19 +08:00
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u del"
|
|
|
|
% (asid))
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 90.0.0.0/8 protocol udp port 20000 encap l3dsr"
|
|
|
|
" dscp 7 del")
|
2018-01-23 19:17:23 +08:00
|
|
|
self.vapi.cli("test lb flowtable flush")
|
2018-02-06 23:00:22 +08:00
|
|
|
|
2018-06-28 20:14:19 +08:00
|
|
|
def test_lb_ip4_nat4_port(self):
|
|
|
|
""" Load Balancer IP4 NAT4 on per-port-vip case """
|
2018-02-06 23:00:22 +08:00
|
|
|
try:
|
2018-06-28 20:14:19 +08:00
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 90.0.0.0/8 protocol udp port 20000 encap nat4"
|
|
|
|
" type clusterip target_port 3307")
|
2018-02-06 23:00:22 +08:00
|
|
|
for asid in self.ass:
|
2018-06-28 20:14:19 +08:00
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u"
|
|
|
|
% (asid))
|
2018-02-06 23:00:22 +08:00
|
|
|
|
|
|
|
self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True))
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pg_start()
|
|
|
|
self.checkCapture(encap='nat4', isv4=True)
|
|
|
|
|
|
|
|
finally:
|
|
|
|
for asid in self.ass:
|
2018-06-28 20:14:19 +08:00
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u del"
|
|
|
|
% (asid))
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 90.0.0.0/8 protocol udp port 20000 encap nat4"
|
|
|
|
" type clusterip target_port 3307 del")
|
2018-02-06 23:00:22 +08:00
|
|
|
self.vapi.cli("test lb flowtable flush")
|
|
|
|
|
2018-06-28 20:14:19 +08:00
|
|
|
def test_lb_ip6_nat6_port(self):
|
|
|
|
""" Load Balancer IP6 NAT6 on per-port-vip case """
|
2018-02-06 23:00:22 +08:00
|
|
|
try:
|
2018-06-28 20:14:19 +08:00
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 2001::/16 protocol udp port 20000 encap nat6"
|
|
|
|
" type clusterip target_port 3307")
|
2018-02-06 23:00:22 +08:00
|
|
|
for asid in self.ass:
|
2018-06-28 20:14:19 +08:00
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 2001::/16 protocol udp port 20000 2002::%u"
|
|
|
|
% (asid))
|
2018-02-06 23:00:22 +08:00
|
|
|
|
|
|
|
self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False))
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pg_start()
|
|
|
|
self.checkCapture(encap='nat6', isv4=False)
|
|
|
|
|
|
|
|
finally:
|
|
|
|
for asid in self.ass:
|
2018-06-28 20:14:19 +08:00
|
|
|
self.vapi.cli(
|
|
|
|
"lb as 2001::/16 protocol udp port 20000 2002::%u del"
|
|
|
|
% (asid))
|
|
|
|
self.vapi.cli(
|
|
|
|
"lb vip 2001::/16 protocol udp port 20000 encap nat6"
|
|
|
|
" type clusterip target_port 3307 del")
|
2018-02-06 23:00:22 +08:00
|
|
|
self.vapi.cli("test lb flowtable flush")
|