X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=test%2Ftest_ip4.py;h=589c668a45662121ddfc67732f3189a0c33b4318;hb=3d5f08a82;hp=b93241b652d3195b6a95b0a71d14081cd46d6cd8;hpb=2df2f75ec52003e3b6addbde5f2e8254a9aee800;p=vpp.git diff --git a/test/test_ip4.py b/test/test_ip4.py index b93241b652d..589c668a456 100644 --- a/test/test_ip4.py +++ b/test/test_ip4.py @@ -1118,6 +1118,7 @@ class TestIPLoadBalance(VppTestCase): super(TestIPLoadBalance, self).tearDown() def send_and_expect_load_balancing(self, input, pkts, outputs): + self.vapi.cli("clear trace") input.add_stream(pkts) self.pg_enable_capture(self.pg_interfaces) self.pg_start() @@ -1125,8 +1126,7 @@ class TestIPLoadBalance(VppTestCase): for oo in outputs: rx = oo._get_capture(1) self.assertNotEqual(0, len(rx)) - for r in rx: - rxs.append(r) + rxs.append(rx) return rxs def send_and_expect_one_itf(self, input, pkts, itf): @@ -1135,9 +1135,18 @@ class TestIPLoadBalance(VppTestCase): self.pg_start() rx = itf.get_capture(len(pkts)) + def total_len(self, rxs): + n = 0 + for rx in rxs: + n += len(rx) + return n + def test_ip_load_balance(self): """ IP Load-Balancing """ + fhc = VppEnum.vl_api_ip_flow_hash_config_t + af = VppEnum.vl_api_address_family_t + # # An array of packets that differ only in the destination port # @@ -1192,21 +1201,41 @@ class TestIPLoadBalance(VppTestCase): # be guaranteed. But with 64 different packets we do expect some # balancing. So instead just ensure there is traffic on each link. # - self.send_and_expect_load_balancing(self.pg0, port_ip_pkts, - [self.pg1, self.pg2]) + rx = self.send_and_expect_load_balancing(self.pg0, port_ip_pkts, + [self.pg1, self.pg2]) + n_ip_pg0 = len(rx[0]) self.send_and_expect_load_balancing(self.pg0, src_ip_pkts, [self.pg1, self.pg2]) self.send_and_expect_load_balancing(self.pg0, port_mpls_pkts, [self.pg1, self.pg2]) - self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts, - [self.pg1, self.pg2]) + rx = self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts, + [self.pg1, self.pg2]) + n_mpls_pg0 = len(rx[0]) + + # + # change the router ID and expect the distribution changes + # + self.vapi.set_ip_flow_hash_router_id(router_id=0x11111111) + + rx = self.send_and_expect_load_balancing(self.pg0, port_ip_pkts, + [self.pg1, self.pg2]) + self.assertNotEqual(n_ip_pg0, len(rx[0])) + + rx = self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts, + [self.pg1, self.pg2]) + self.assertNotEqual(n_mpls_pg0, len(rx[0])) # # change the flow hash config so it's only IP src,dst # - now only the stream with differing source address will # load-balance # - self.vapi.set_ip_flow_hash(vrf_id=0, src=1, dst=1, sport=0, dport=0) + self.vapi.set_ip_flow_hash_v2( + af=af.ADDRESS_IP4, + table_id=0, + flow_hash_config=(fhc.IP_API_FLOW_HASH_SRC_IP | + fhc.IP_API_FLOW_HASH_DST_IP | + fhc.IP_API_FLOW_HASH_PROTO)) self.send_and_expect_load_balancing(self.pg0, src_ip_pkts, [self.pg1, self.pg2]) @@ -1218,7 +1247,8 @@ class TestIPLoadBalance(VppTestCase): # # change the flow hash config back to defaults # - self.vapi.set_ip_flow_hash(vrf_id=0, src=1, dst=1, sport=1, dport=1) + self.vapi.set_ip_flow_hash(vrf_id=0, src=1, dst=1, + proto=1, sport=1, dport=1) # # Recursive prefixes @@ -1264,23 +1294,23 @@ class TestIPLoadBalance(VppTestCase): self.pg3, self.pg4]) # - # bring down pg1 expect LB to adjust to use only those that are pu + # bring down pg1 expect LB to adjust to use only those that are up # self.pg1.link_down() rx = self.send_and_expect_load_balancing(self.pg0, src_pkts, [self.pg2, self.pg3, self.pg4]) - self.assertEqual(len(src_pkts), len(rx)) + self.assertEqual(len(src_pkts), self.total_len(rx)) # - # bring down pg2 expect LB to adjust to use only those that are pu + # bring down pg2 expect LB to adjust to use only those that are up # self.pg2.link_down() rx = self.send_and_expect_load_balancing(self.pg0, src_pkts, [self.pg3, self.pg4]) - self.assertEqual(len(src_pkts), len(rx)) + self.assertEqual(len(src_pkts), self.total_len(rx)) # # bring the links back up - expect LB over all again @@ -1291,7 +1321,7 @@ class TestIPLoadBalance(VppTestCase): rx = self.send_and_expect_load_balancing(self.pg0, src_pkts, [self.pg1, self.pg2, self.pg3, self.pg4]) - self.assertEqual(len(src_pkts), len(rx)) + self.assertEqual(len(src_pkts), self.total_len(rx)) # # The same link-up/down but this time admin state @@ -1300,7 +1330,7 @@ class TestIPLoadBalance(VppTestCase): self.pg2.admin_down() rx = self.send_and_expect_load_balancing(self.pg0, src_pkts, [self.pg3, self.pg4]) - self.assertEqual(len(src_pkts), len(rx)) + self.assertEqual(len(src_pkts), self.total_len(rx)) self.pg1.admin_up() self.pg2.admin_up() self.pg1.resolve_arp() @@ -1308,7 +1338,7 @@ class TestIPLoadBalance(VppTestCase): rx = self.send_and_expect_load_balancing(self.pg0, src_pkts, [self.pg1, self.pg2, self.pg3, self.pg4]) - self.assertEqual(len(src_pkts), len(rx)) + self.assertEqual(len(src_pkts), self.total_len(rx)) # # Recursive prefixes @@ -1366,7 +1396,7 @@ class TestIPLoadBalance(VppTestCase): rx = self.send_and_expect_load_balancing(self.pg0, port_pkts, [self.pg3, self.pg4]) - self.assertEqual(len(src_pkts), len(rx)) + self.assertEqual(len(src_pkts), self.total_len(rx)) class TestIPVlan0(VppTestCase):