X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=test%2Ftest_ip_ecmp.py;h=1d3e872e45ef5bf18cfda205c58dbbcc23b57b95;hb=61717cc38;hp=60673ea6f3a539fc702e37688e764ffdb1646f25;hpb=e8b68a3da28aa0a2c5f2b7db8e4a59b787c3c4d1;p=vpp.git diff --git a/test/test_ip_ecmp.py b/test/test_ip_ecmp.py index 60673ea6f3a..1d3e872e45e 100644 --- a/test/test_ip_ecmp.py +++ b/test/test_ip_ecmp.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import unittest import random @@ -12,6 +12,12 @@ from scapy.packet import Raw from scapy.layers.l2 import Ether from scapy.layers.inet import IP, UDP from scapy.layers.inet6 import IPv6 +from vpp_ip_route import VppIpRoute, VppRoutePath + +try: + text_type = unicode +except NameError: + text_type = str # # The number of packets to sent. @@ -67,9 +73,10 @@ class TestECMP(VppTestCase): Show various debug prints after each test. """ super(TestECMP, self).tearDown() - if not self.vpp_dead: - self.logger.info(self.vapi.ppcli("show ip arp")) - self.logger.info(self.vapi.ppcli("show ip6 neighbors")) + + def show_commands_at_teardown(self): + self.logger.info(self.vapi.ppcli("show ip4 neighbors")) + self.logger.info(self.vapi.ppcli("show ip6 neighbors")) def get_ip_address(self, ip_addr_start, ip_prefix_len): """ @@ -79,10 +86,10 @@ class TestECMP(VppTestCase): :return: Random IPv4 or IPv6 address from required range. """ try: - ip_addr = IPv4Address(unicode(ip_addr_start)) + ip_addr = IPv4Address(text_type(ip_addr_start)) ip_max_len = 32 except (AttributeError, AddressValueError): - ip_addr = IPv6Address(unicode(ip_addr_start)) + ip_addr = IPv6Address(text_type(ip_addr_start)) ip_max_len = 128 return str(ip_addr + @@ -132,7 +139,7 @@ class TestECMP(VppTestCase): for packet in capture: try: ip_received = packet[ip_l] - payload_info = self.payload_to_info(str(packet[Raw])) + payload_info = self.payload_to_info(packet[Raw]) packet_index = payload_info.index ip_sent = self._packet_infos[packet_index].data[ip_l] self.logger.debug("Got packet on port %s: src=%u (id=%u)" % @@ -172,20 +179,18 @@ class TestECMP(VppTestCase): :param int dst_prefix_len: IP address prefix length. :param int is_ipv6: 0 if an ip4 route, else ip6 """ - af = socket.AF_INET if is_ipv6 == 0 else socket.AF_INET6 - dst_ip = socket.inet_pton(af, dst_ip_net) + paths = [] for pg_if in self.pg_interfaces[1:]: for nh_host in pg_if.remote_hosts: nh_host_ip = nh_host.ip4 if is_ipv6 == 0 else nh_host.ip6 - next_hop_address = socket.inet_pton(af, nh_host_ip) - next_hop_sw_if_index = pg_if.sw_if_index - self.vapi.ip_add_del_route( - dst_ip, dst_prefix_len, next_hop_address, - next_hop_sw_if_index=next_hop_sw_if_index, - is_ipv6=is_ipv6, is_multipath=1) - self.logger.info("Route via %s on %s created" % - (nh_host_ip, pg_if.name)) + paths.append(VppRoutePath(nh_host_ip, + pg_if.sw_if_index)) + + rip = VppIpRoute(self, dst_ip_net, dst_prefix_len, paths) + rip.add_vpp_config() + self.logger.info("Route via %s on %s created" % + (nh_host_ip, pg_if.name)) self.logger.debug(self.vapi.ppcli("show ip fib")) self.logger.debug(self.vapi.ppcli("show ip6 fib"))