Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 1 | import socket |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 2 | |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 3 | from scapy.layers.inet import IP, UDP |
Klement Sekera | 65cc8c0 | 2016-12-18 15:49:54 +0100 | [diff] [blame] | 4 | from scapy.layers.inet6 import IPv6 |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 5 | from scapy.layers.l2 import Ether, GRE |
| 6 | from scapy.packet import Raw |
Hongjun Ni | 6fb0d9b | 2018-06-08 07:12:05 +0800 | [diff] [blame] | 7 | from scapy.data import IP_PROTOS |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 8 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 9 | from framework import VppTestCase |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 10 | from util import ppp |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 11 | |
| 12 | """ TestLB is a subclass of VPPTestCase classes. |
| 13 | |
| 14 | TestLB class defines Load Balancer test cases for: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 15 | - IP4 to GRE4 encap on per-port vip case |
| 16 | - IP4 to GRE6 encap on per-port vip case |
| 17 | - IP6 to GRE4 encap on per-port vip case |
| 18 | - IP6 to GRE6 encap on per-port vip case |
| 19 | - IP4 to L3DSR encap on vip case |
| 20 | - IP4 to L3DSR encap on per-port vip case |
| 21 | - IP4 to NAT4 encap on per-port vip case |
| 22 | - IP6 to NAT6 encap on per-port vip case |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 23 | |
| 24 | As stated in comments below, GRE has issues with IPv6. |
| 25 | All test cases involving IPv6 are executed, but |
| 26 | received packets are not parsed and checked. |
| 27 | |
| 28 | """ |
| 29 | |
| 30 | |
| 31 | class TestLB(VppTestCase): |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 32 | """ Load Balancer Test Case """ |
| 33 | |
| 34 | @classmethod |
| 35 | def setUpClass(cls): |
| 36 | super(TestLB, cls).setUpClass() |
| 37 | |
| 38 | cls.ass = range(5) |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 39 | cls.packets = range(1) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 40 | |
| 41 | try: |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 42 | cls.create_pg_interfaces(range(2)) |
| 43 | cls.interfaces = list(cls.pg_interfaces) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 44 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 45 | for i in cls.interfaces: |
| 46 | i.admin_up() |
| 47 | i.config_ip4() |
| 48 | i.config_ip6() |
| 49 | i.disable_ipv6_ra() |
| 50 | i.resolve_arp() |
| 51 | i.resolve_ndp() |
| 52 | dst4 = socket.inet_pton(socket.AF_INET, "10.0.0.0") |
| 53 | dst6 = socket.inet_pton(socket.AF_INET6, "2002::") |
| 54 | cls.vapi.ip_add_del_route(dst4, 24, cls.pg1.remote_ip4n) |
| 55 | cls.vapi.ip_add_del_route(dst6, 16, cls.pg1.remote_ip6n, is_ipv6=1) |
| 56 | cls.vapi.cli("lb conf ip4-src-address 39.40.41.42") |
| 57 | cls.vapi.cli("lb conf ip6-src-address 2004::1") |
| 58 | except Exception: |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 59 | super(TestLB, cls).tearDownClass() |
| 60 | raise |
| 61 | |
| 62 | def tearDown(self): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 63 | super(TestLB, self).tearDown() |
| 64 | if not self.vpp_dead: |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 65 | self.logger.info(self.vapi.cli("show lb vip verbose")) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 66 | |
| 67 | def getIPv4Flow(self, id): |
| 68 | return (IP(dst="90.0.%u.%u" % (id / 255, id % 255), |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 69 | src="40.0.%u.%u" % (id / 255, id % 255)) / |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 70 | UDP(sport=10000 + id, dport=20000)) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 71 | |
| 72 | def getIPv6Flow(self, id): |
| 73 | return (IPv6(dst="2001::%u" % (id), src="fd00:f00d:ffff::%u" % (id)) / |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 74 | UDP(sport=10000 + id, dport=20000)) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 75 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 76 | def generatePackets(self, src_if, isv4): |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 77 | self.reset_packet_infos() |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 78 | pkts = [] |
| 79 | for pktid in self.packets: |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 80 | info = self.create_packet_info(src_if, self.pg1) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 81 | payload = self.info_to_payload(info) |
| 82 | ip = self.getIPv4Flow(pktid) if isv4 else self.getIPv6Flow(pktid) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 83 | packet = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) / |
| 84 | ip / |
| 85 | Raw(payload)) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 86 | self.extend_packet(packet, 128) |
| 87 | info.data = packet.copy() |
| 88 | pkts.append(packet) |
| 89 | return pkts |
| 90 | |
| 91 | def checkInner(self, gre, isv4): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 92 | IPver = IP if isv4 else IPv6 |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 93 | self.assertEqual(gre.proto, 0x0800 if isv4 else 0x86DD) |
| 94 | self.assertEqual(gre.flags, 0) |
| 95 | self.assertEqual(gre.version, 0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 96 | inner = IPver(str(gre.payload)) |
| 97 | payload_info = self.payload_to_info(str(inner[Raw])) |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 98 | self.info = self.packet_infos[payload_info.index] |
| 99 | self.assertEqual(payload_info.src, self.pg0.sw_if_index) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 100 | self.assertEqual(str(inner), str(self.info.data[IPver])) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 101 | |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 102 | def checkCapture(self, encap, isv4): |
Klement Sekera | 65cc8c0 | 2016-12-18 15:49:54 +0100 | [diff] [blame] | 103 | self.pg0.assert_nothing_captured() |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 104 | out = self.pg1.get_capture(len(self.packets)) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 105 | |
| 106 | load = [0] * len(self.ass) |
| 107 | self.info = None |
| 108 | for p in out: |
| 109 | try: |
| 110 | asid = 0 |
| 111 | gre = None |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 112 | if (encap == 'gre4'): |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 113 | ip = p[IP] |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 114 | asid = int(ip.dst.split(".")[3]) |
| 115 | self.assertEqual(ip.version, 4) |
| 116 | self.assertEqual(ip.flags, 0) |
| 117 | self.assertEqual(ip.src, "39.40.41.42") |
| 118 | self.assertEqual(ip.dst, "10.0.0.%u" % asid) |
| 119 | self.assertEqual(ip.proto, 47) |
| 120 | self.assertEqual(len(ip.options), 0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 121 | gre = p[GRE] |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 122 | self.checkInner(gre, isv4) |
| 123 | elif (encap == 'gre6'): |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 124 | ip = p[IPv6] |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 125 | asid = ip.dst.split(":") |
| 126 | asid = asid[len(asid) - 1] |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 127 | asid = 0 if asid == "" else int(asid) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 128 | self.assertEqual(ip.version, 6) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 129 | self.assertEqual(ip.tc, 0) |
| 130 | self.assertEqual(ip.fl, 0) |
| 131 | self.assertEqual(ip.src, "2004::1") |
| 132 | self.assertEqual( |
| 133 | socket.inet_pton(socket.AF_INET6, ip.dst), |
| 134 | socket.inet_pton(socket.AF_INET6, "2002::%u" % asid) |
| 135 | ) |
| 136 | self.assertEqual(ip.nh, 47) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 137 | # self.assertEqual(len(ip.options), 0) |
| 138 | gre = GRE(str(p[IPv6].payload)) |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 139 | self.checkInner(gre, isv4) |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 140 | elif (encap == 'l3dsr'): |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 141 | ip = p[IP] |
| 142 | asid = int(ip.dst.split(".")[3]) |
| 143 | self.assertEqual(ip.version, 4) |
| 144 | self.assertEqual(ip.flags, 0) |
| 145 | self.assertEqual(ip.dst, "10.0.0.%u" % asid) |
| 146 | self.assertEqual(ip.tos, 0x1c) |
| 147 | self.assertEqual(len(ip.options), 0) |
Hongjun Ni | 6fb0d9b | 2018-06-08 07:12:05 +0800 | [diff] [blame] | 148 | self.assert_ip_checksum_valid(p) |
| 149 | if ip.proto == IP_PROTOS.tcp: |
| 150 | self.assert_tcp_checksum_valid(p) |
| 151 | elif ip.proto == IP_PROTOS.udp: |
| 152 | self.assert_udp_checksum_valid(p) |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 153 | elif (encap == 'nat4'): |
| 154 | ip = p[IP] |
| 155 | asid = int(ip.dst.split(".")[3]) |
| 156 | self.assertEqual(ip.version, 4) |
| 157 | self.assertEqual(ip.flags, 0) |
| 158 | self.assertEqual(ip.dst, "10.0.0.%u" % asid) |
| 159 | self.assertEqual(ip.proto, 17) |
| 160 | self.assertEqual(len(ip.options), 0) |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 161 | udp = p[UDP] |
| 162 | self.assertEqual(udp.dport, 3307) |
| 163 | elif (encap == 'nat6'): |
| 164 | ip = p[IPv6] |
| 165 | asid = ip.dst.split(":") |
| 166 | asid = asid[len(asid) - 1] |
| 167 | asid = 0 if asid == "" else int(asid) |
| 168 | self.assertEqual(ip.version, 6) |
| 169 | self.assertEqual(ip.tc, 0) |
| 170 | self.assertEqual(ip.fl, 0) |
| 171 | self.assertEqual( |
| 172 | socket.inet_pton(socket.AF_INET6, ip.dst), |
| 173 | socket.inet_pton(socket.AF_INET6, "2002::%u" % asid) |
| 174 | ) |
| 175 | self.assertEqual(ip.nh, 17) |
| 176 | self.assertGreaterEqual(ip.hlim, 63) |
| 177 | udp = UDP(str(p[IPv6].payload)) |
| 178 | self.assertEqual(udp.dport, 3307) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 179 | load[asid] += 1 |
| 180 | except: |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 181 | self.logger.error(ppp("Unexpected or invalid packet:", p)) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 182 | raise |
| 183 | |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 184 | # This is just to 1roughly check that the balancing algorithm |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 185 | # is not completly biased. |
| 186 | for asid in self.ass: |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 187 | if load[asid] < len(self.packets) / (len(self.ass) * 2): |
Gabriel Ganne | 8e66b9b | 2017-12-14 16:20:37 +0100 | [diff] [blame] | 188 | self.logger.error( |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 189 | "ASS is not balanced: load[%d] = %d" % (asid, load[asid])) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 190 | raise Exception("Load Balancer algorithm is biased") |
| 191 | |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 192 | def test_lb_ip4_gre4(self): |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 193 | """ Load Balancer IP4 GRE4 on vip case """ |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 194 | try: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 195 | self.vapi.cli( |
| 196 | "lb vip 90.0.0.0/8 encap gre4") |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 197 | for asid in self.ass: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 198 | self.vapi.cli( |
| 199 | "lb as 90.0.0.0/8 10.0.0.%u" |
| 200 | % (asid)) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 201 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 202 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True)) |
| 203 | self.pg_enable_capture(self.pg_interfaces) |
| 204 | self.pg_start() |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 205 | self.checkCapture(encap='gre4', isv4=True) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 206 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 207 | finally: |
| 208 | for asid in self.ass: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 209 | self.vapi.cli( |
| 210 | "lb as 90.0.0.0/8 10.0.0.%u del" |
| 211 | % (asid)) |
| 212 | self.vapi.cli( |
| 213 | "lb vip 90.0.0.0/8 encap gre4 del") |
Gabriel Ganne | b3d1b20 | 2017-10-30 15:44:31 +0100 | [diff] [blame] | 214 | self.vapi.cli("test lb flowtable flush") |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 215 | |
| 216 | def test_lb_ip6_gre4(self): |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 217 | """ Load Balancer IP6 GRE4 on vip case """ |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 218 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 219 | try: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 220 | self.vapi.cli( |
| 221 | "lb vip 2001::/16 encap gre4") |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 222 | for asid in self.ass: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 223 | self.vapi.cli( |
| 224 | "lb as 2001::/16 10.0.0.%u" |
| 225 | % (asid)) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 226 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 227 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False)) |
| 228 | self.pg_enable_capture(self.pg_interfaces) |
| 229 | self.pg_start() |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 230 | |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 231 | self.checkCapture(encap='gre4', isv4=False) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 232 | finally: |
| 233 | for asid in self.ass: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 234 | self.vapi.cli( |
| 235 | "lb as 2001::/16 10.0.0.%u del" |
| 236 | % (asid)) |
| 237 | self.vapi.cli( |
| 238 | "lb vip 2001::/16 encap gre4 del") |
Gabriel Ganne | b3d1b20 | 2017-10-30 15:44:31 +0100 | [diff] [blame] | 239 | self.vapi.cli("test lb flowtable flush") |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 240 | |
| 241 | def test_lb_ip4_gre6(self): |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 242 | """ Load Balancer IP4 GRE6 on vip case """ |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 243 | try: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 244 | self.vapi.cli( |
| 245 | "lb vip 90.0.0.0/8 encap gre6") |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 246 | for asid in self.ass: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 247 | self.vapi.cli( |
| 248 | "lb as 90.0.0.0/8 2002::%u" |
| 249 | % (asid)) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 250 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 251 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True)) |
| 252 | self.pg_enable_capture(self.pg_interfaces) |
| 253 | self.pg_start() |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 254 | |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 255 | self.checkCapture(encap='gre6', isv4=True) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 256 | finally: |
| 257 | for asid in self.ass: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 258 | self.vapi.cli( |
| 259 | "lb as 90.0.0.0/8 2002::%u del" |
| 260 | % (asid)) |
| 261 | self.vapi.cli( |
| 262 | "lb vip 90.0.0.0/8 encap gre6 del") |
Gabriel Ganne | b3d1b20 | 2017-10-30 15:44:31 +0100 | [diff] [blame] | 263 | self.vapi.cli("test lb flowtable flush") |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 264 | |
| 265 | def test_lb_ip6_gre6(self): |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 266 | """ Load Balancer IP6 GRE6 on vip case """ |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 267 | try: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 268 | self.vapi.cli( |
| 269 | "lb vip 2001::/16 encap gre6") |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 270 | for asid in self.ass: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 271 | self.vapi.cli( |
| 272 | "lb as 2001::/16 2002::%u" |
| 273 | % (asid)) |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 274 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 275 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False)) |
| 276 | self.pg_enable_capture(self.pg_interfaces) |
| 277 | self.pg_start() |
Pierre Pfister | f588f35 | 2016-10-07 16:31:57 +0100 | [diff] [blame] | 278 | |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 279 | self.checkCapture(encap='gre6', isv4=False) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 280 | finally: |
| 281 | for asid in self.ass: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 282 | self.vapi.cli( |
| 283 | "lb as 2001::/16 2002::%u del" |
| 284 | % (asid)) |
| 285 | self.vapi.cli( |
| 286 | "lb vip 2001::/16 encap gre6 del") |
| 287 | self.vapi.cli("test lb flowtable flush") |
| 288 | |
| 289 | def test_lb_ip4_gre4_port(self): |
| 290 | """ Load Balancer IP4 GRE4 on per-port-vip case """ |
| 291 | try: |
| 292 | self.vapi.cli( |
| 293 | "lb vip 90.0.0.0/8 protocol udp port 20000 encap gre4") |
| 294 | for asid in self.ass: |
| 295 | self.vapi.cli( |
| 296 | "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u" |
| 297 | % (asid)) |
| 298 | |
| 299 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True)) |
| 300 | self.pg_enable_capture(self.pg_interfaces) |
| 301 | self.pg_start() |
| 302 | self.checkCapture(encap='gre4', isv4=True) |
| 303 | |
| 304 | finally: |
| 305 | for asid in self.ass: |
| 306 | self.vapi.cli( |
| 307 | "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u del" |
| 308 | % (asid)) |
| 309 | self.vapi.cli( |
| 310 | "lb vip 90.0.0.0/8 protocol udp port 20000 encap gre4 del") |
| 311 | self.vapi.cli("test lb flowtable flush") |
| 312 | |
| 313 | def test_lb_ip6_gre4_port(self): |
| 314 | """ Load Balancer IP6 GRE4 on per-port-vip case """ |
| 315 | |
| 316 | try: |
| 317 | self.vapi.cli( |
| 318 | "lb vip 2001::/16 protocol udp port 20000 encap gre4") |
| 319 | for asid in self.ass: |
| 320 | self.vapi.cli( |
| 321 | "lb as 2001::/16 protocol udp port 20000 10.0.0.%u" |
| 322 | % (asid)) |
| 323 | |
| 324 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False)) |
| 325 | self.pg_enable_capture(self.pg_interfaces) |
| 326 | self.pg_start() |
| 327 | |
| 328 | self.checkCapture(encap='gre4', isv4=False) |
| 329 | finally: |
| 330 | for asid in self.ass: |
| 331 | self.vapi.cli( |
| 332 | "lb as 2001::/16 protocol udp port 20000 10.0.0.%u del" |
| 333 | % (asid)) |
| 334 | self.vapi.cli( |
| 335 | "lb vip 2001::/16 protocol udp port 20000 encap gre4 del") |
| 336 | self.vapi.cli("test lb flowtable flush") |
| 337 | |
| 338 | def test_lb_ip4_gre6_port(self): |
| 339 | """ Load Balancer IP4 GRE6 on per-port-vip case """ |
| 340 | try: |
| 341 | self.vapi.cli( |
| 342 | "lb vip 90.0.0.0/8 protocol udp port 20000 encap gre6") |
| 343 | for asid in self.ass: |
| 344 | self.vapi.cli( |
| 345 | "lb as 90.0.0.0/8 protocol udp port 20000 2002::%u" |
| 346 | % (asid)) |
| 347 | |
| 348 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True)) |
| 349 | self.pg_enable_capture(self.pg_interfaces) |
| 350 | self.pg_start() |
| 351 | |
| 352 | self.checkCapture(encap='gre6', isv4=True) |
| 353 | finally: |
| 354 | for asid in self.ass: |
| 355 | self.vapi.cli( |
| 356 | "lb as 90.0.0.0/8 protocol udp port 20000 2002::%u del" |
| 357 | % (asid)) |
| 358 | self.vapi.cli( |
| 359 | "lb vip 90.0.0.0/8 protocol udp port 20000 encap gre6 del") |
| 360 | self.vapi.cli("test lb flowtable flush") |
| 361 | |
| 362 | def test_lb_ip6_gre6_port(self): |
| 363 | """ Load Balancer IP6 GRE6 on per-port-vip case """ |
| 364 | try: |
| 365 | self.vapi.cli( |
| 366 | "lb vip 2001::/16 protocol udp port 20000 encap gre6") |
| 367 | for asid in self.ass: |
| 368 | self.vapi.cli( |
| 369 | "lb as 2001::/16 protocol udp port 20000 2002::%u" |
| 370 | % (asid)) |
| 371 | |
| 372 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False)) |
| 373 | self.pg_enable_capture(self.pg_interfaces) |
| 374 | self.pg_start() |
| 375 | |
| 376 | self.checkCapture(encap='gre6', isv4=False) |
| 377 | finally: |
| 378 | for asid in self.ass: |
| 379 | self.vapi.cli( |
| 380 | "lb as 2001::/16 protocol udp port 20000 2002::%u del" |
| 381 | % (asid)) |
| 382 | self.vapi.cli( |
| 383 | "lb vip 2001::/16 protocol udp port 20000 encap gre6 del") |
Gabriel Ganne | b3d1b20 | 2017-10-30 15:44:31 +0100 | [diff] [blame] | 384 | self.vapi.cli("test lb flowtable flush") |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 385 | |
| 386 | def test_lb_ip4_l3dsr(self): |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 387 | """ Load Balancer IP4 L3DSR on vip case """ |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 388 | try: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 389 | self.vapi.cli( |
| 390 | "lb vip 90.0.0.0/8 encap l3dsr dscp 7") |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 391 | for asid in self.ass: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 392 | self.vapi.cli( |
| 393 | "lb as 90.0.0.0/8 10.0.0.%u" |
| 394 | % (asid)) |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 395 | |
| 396 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True)) |
| 397 | self.pg_enable_capture(self.pg_interfaces) |
| 398 | self.pg_start() |
| 399 | self.checkCapture(encap='l3dsr', isv4=True) |
| 400 | |
| 401 | finally: |
| 402 | for asid in self.ass: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 403 | self.vapi.cli( |
| 404 | "lb as 90.0.0.0/8 10.0.0.%u del" |
| 405 | % (asid)) |
| 406 | self.vapi.cli( |
| 407 | "lb vip 90.0.0.0/8 encap l3dsr" |
| 408 | " dscp 7 del") |
Hongjun Ni | 647f609 | 2018-01-23 19:17:23 +0800 | [diff] [blame] | 409 | self.vapi.cli("test lb flowtable flush") |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 410 | |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 411 | def test_lb_ip4_l3dsr_port(self): |
| 412 | """ Load Balancer IP4 L3DSR on per-port-vip case """ |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 413 | try: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 414 | self.vapi.cli( |
| 415 | "lb vip 90.0.0.0/8 protocol udp port 20000 encap l3dsr dscp 7") |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 416 | for asid in self.ass: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 417 | self.vapi.cli( |
| 418 | "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u" |
| 419 | % (asid)) |
| 420 | |
| 421 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True)) |
| 422 | self.pg_enable_capture(self.pg_interfaces) |
| 423 | self.pg_start() |
| 424 | self.checkCapture(encap='l3dsr', isv4=True) |
| 425 | |
| 426 | finally: |
| 427 | for asid in self.ass: |
| 428 | self.vapi.cli( |
| 429 | "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u del" |
| 430 | % (asid)) |
| 431 | self.vapi.cli( |
| 432 | "lb vip 90.0.0.0/8 protocol udp port 20000 encap l3dsr" |
| 433 | " dscp 7 del") |
| 434 | self.vapi.cli("test lb flowtable flush") |
| 435 | |
| 436 | def test_lb_ip4_nat4_port(self): |
| 437 | """ Load Balancer IP4 NAT4 on per-port-vip case """ |
| 438 | try: |
| 439 | self.vapi.cli( |
| 440 | "lb vip 90.0.0.0/8 protocol udp port 20000 encap nat4" |
| 441 | " type clusterip target_port 3307") |
| 442 | for asid in self.ass: |
| 443 | self.vapi.cli( |
| 444 | "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u" |
| 445 | % (asid)) |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 446 | |
| 447 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=True)) |
| 448 | self.pg_enable_capture(self.pg_interfaces) |
| 449 | self.pg_start() |
| 450 | self.checkCapture(encap='nat4', isv4=True) |
| 451 | |
| 452 | finally: |
| 453 | for asid in self.ass: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 454 | self.vapi.cli( |
| 455 | "lb as 90.0.0.0/8 protocol udp port 20000 10.0.0.%u del" |
| 456 | % (asid)) |
| 457 | self.vapi.cli( |
| 458 | "lb vip 90.0.0.0/8 protocol udp port 20000 encap nat4" |
| 459 | " type clusterip target_port 3307 del") |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 460 | self.vapi.cli("test lb flowtable flush") |
| 461 | |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 462 | def test_lb_ip6_nat6_port(self): |
| 463 | """ Load Balancer IP6 NAT6 on per-port-vip case """ |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 464 | try: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 465 | self.vapi.cli( |
| 466 | "lb vip 2001::/16 protocol udp port 20000 encap nat6" |
| 467 | " type clusterip target_port 3307") |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 468 | for asid in self.ass: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 469 | self.vapi.cli( |
| 470 | "lb as 2001::/16 protocol udp port 20000 2002::%u" |
| 471 | % (asid)) |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 472 | |
| 473 | self.pg0.add_stream(self.generatePackets(self.pg0, isv4=False)) |
| 474 | self.pg_enable_capture(self.pg_interfaces) |
| 475 | self.pg_start() |
| 476 | self.checkCapture(encap='nat6', isv4=False) |
| 477 | |
| 478 | finally: |
| 479 | for asid in self.ass: |
Hongjun Ni | 219cc90 | 2018-06-28 20:14:19 +0800 | [diff] [blame] | 480 | self.vapi.cli( |
| 481 | "lb as 2001::/16 protocol udp port 20000 2002::%u del" |
| 482 | % (asid)) |
| 483 | self.vapi.cli( |
| 484 | "lb vip 2001::/16 protocol udp port 20000 encap nat6" |
| 485 | " type clusterip target_port 3307 del") |
Hongjun Ni | d92a0b5 | 2018-02-06 23:00:22 +0800 | [diff] [blame] | 486 | self.vapi.cli("test lb flowtable flush") |