4 object abstractions for ARP and ND
7 from ipaddress import ip_address
8 from vpp_object import VppObject
9 from vpp_papi import mac_pton, VppEnum
16 def find_nbr(test, sw_if_index, nbr_addr, is_static=0, mac=None):
17 ip_addr = ip_address(text_type(nbr_addr))
18 e = VppEnum.vl_api_ip_neighbor_flags_t
19 nbrs = test.vapi.ip_neighbor_dump(sw_if_index,
20 is_ipv6=(6 == ip_addr.version))
23 if ip_addr == n.neighbor.ip_address and \
24 is_static == (n.neighbor.flags & e.IP_API_NEIGHBOR_FLAG_STATIC):
26 if mac == str(n.neighbor.mac_address):
33 class VppNeighbor(VppObject):
38 def __init__(self, test, sw_if_index, mac_addr, nbr_addr,
39 is_static=False, is_no_fib_entry=False):
41 self.sw_if_index = sw_if_index
42 self.mac_addr = mac_addr
43 self.nbr_addr = nbr_addr
45 e = VppEnum.vl_api_ip_neighbor_flags_t
46 self.flags = e.IP_API_NEIGHBOR_FLAG_NONE
48 self.flags |= e.IP_API_NEIGHBOR_FLAG_STATIC
50 self.flags |= e.IP_API_NEIGHBOR_FLAG_NO_FIB_ENTRY
52 def add_vpp_config(self):
53 r = self._test.vapi.ip_neighbor_add_del(
59 self.stats_index = r.stats_index
60 self._test.registry.register(self, self._test.logger)
62 def remove_vpp_config(self):
63 self._test.vapi.ip_neighbor_add_del(
71 e = VppEnum.vl_api_ip_neighbor_flags_t
72 return (self.flags & e.IP_API_NEIGHBOR_FLAG_STATIC)
74 def query_vpp_config(self):
75 return find_nbr(self._test,
81 return self.object_id()
84 return ("%d:%s" % (self.sw_if_index, self.nbr_addr))
87 c = self._test.statistics.get_counter("/net/adjacency")
88 return c[0][self.stats_index]