X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=test%2Fvpp_neighbor.py;h=60fe28f76e4a66a66536f37683f92d0e0fd8ffe2;hb=4941afb4f96a20df7dc8b6688f7921a3d713b77d;hp=e8ba3b28823cad9ed1594fc0d107b7dc3aa4a557;hpb=f0404e9fb60bf98036cfe768d7e80b31ada05f81;p=vpp.git diff --git a/test/vpp_neighbor.py b/test/vpp_neighbor.py index e8ba3b28823..60fe28f76e4 100644 --- a/test/vpp_neighbor.py +++ b/test/vpp_neighbor.py @@ -4,24 +4,32 @@ object abstractions for ARP and ND """ -from socket import inet_pton, inet_ntop, AF_INET, AF_INET6 -from vpp_object import * -from util import mactobinary +from ipaddress import ip_address +from vpp_object import VppObject +from vpp_papi import VppEnum +try: + text_type = unicode +except NameError: + text_type = str -def find_nbr(test, sw_if_index, ip_addr, is_static=0, inet=AF_INET): - nbrs = test.vapi.ip_neighbor_dump(sw_if_index, - is_ipv6=1 if AF_INET6 == inet else 0) - if inet == AF_INET: - s = 4 - else: - s = 16 - nbr_addr = inet_pton(inet, ip_addr) + +def find_nbr(test, sw_if_index, nbr_addr, is_static=0, mac=None): + ip_addr = ip_address(text_type(nbr_addr)) + e = VppEnum.vl_api_ip_neighbor_flags_t + nbrs = test.vapi.ip_neighbor_dump(sw_if_index=sw_if_index, af=ip_addr.vapi_af) for n in nbrs: - if nbr_addr == n.ip_address[:s] \ - and is_static == n.is_static: - return True + if ( + sw_if_index == n.neighbor.sw_if_index + and ip_addr == n.neighbor.ip_address + and is_static == (n.neighbor.flags & e.IP_API_NEIGHBOR_FLAG_STATIC) + ): + if mac: + if mac == str(n.neighbor.mac_address): + return True + else: + return True return False @@ -30,46 +38,50 @@ class VppNeighbor(VppObject): ARP Entry """ - def __init__(self, test, sw_if_index, mac_addr, nbr_addr, - af=AF_INET, is_static=False, is_no_fib_entry=0): + def __init__( + self, + test, + sw_if_index, + mac_addr, + nbr_addr, + is_static=False, + is_no_fib_entry=False, + ): self._test = test self.sw_if_index = sw_if_index - self.mac_addr = mactobinary(mac_addr) - self.af = af - self.is_static = is_static - self.is_no_fib_entry = is_no_fib_entry + self.mac_addr = mac_addr self.nbr_addr = nbr_addr - self.nbr_addr_n = inet_pton(af, nbr_addr) + + e = VppEnum.vl_api_ip_neighbor_flags_t + self.flags = e.IP_API_NEIGHBOR_FLAG_NONE + if is_static: + self.flags |= e.IP_API_NEIGHBOR_FLAG_STATIC + if is_no_fib_entry: + self.flags |= e.IP_API_NEIGHBOR_FLAG_NO_FIB_ENTRY def add_vpp_config(self): - self._test.vapi.ip_neighbor_add_del( - self.sw_if_index, - self.mac_addr, - self.nbr_addr_n, - is_add=1, - is_ipv6=1 if AF_INET6 == self.af else 0, - is_static=self.is_static, - is_no_adj_fib=self.is_no_fib_entry) + r = self._test.vapi.ip_neighbor_add_del( + self.sw_if_index, self.mac_addr, self.nbr_addr, is_add=1, flags=self.flags + ) + self.stats_index = r.stats_index self._test.registry.register(self, self._test.logger) + return self def remove_vpp_config(self): self._test.vapi.ip_neighbor_add_del( - self.sw_if_index, - self.mac_addr, - self.nbr_addr_n, - is_ipv6=1 if AF_INET6 == self.af else 0, - is_add=0, - is_static=self.is_static) + self.sw_if_index, self.mac_addr, self.nbr_addr, is_add=0, flags=self.flags + ) - def query_vpp_config(self): - return find_nbr(self._test, - self.sw_if_index, - self.nbr_addr, - self.is_static, - self.af) + def is_static(self): + e = VppEnum.vl_api_ip_neighbor_flags_t + return self.flags & e.IP_API_NEIGHBOR_FLAG_STATIC - def __str__(self): - return self.object_id() + def query_vpp_config(self): + return find_nbr(self._test, self.sw_if_index, self.nbr_addr, self.is_static()) def object_id(self): - return ("%d:%s" % (self.sw_if_index, self.nbr_addr)) + return "%d:%s" % (self.sw_if_index, self.nbr_addr) + + def get_stats(self): + c = self._test.statistics["/net/adjacency"] + return c[0][self.stats_index]