4 object abstractions for ARP and ND
7 from ipaddress import ip_address
8 from vpp_object import VppObject
9 from vpp_papi import VppEnum
17 def find_nbr(test, sw_if_index, nbr_addr, is_static=0, mac=None):
18 ip_addr = ip_address(text_type(nbr_addr))
19 e = VppEnum.vl_api_ip_neighbor_flags_t
20 nbrs = test.vapi.ip_neighbor_dump(sw_if_index=sw_if_index, af=ip_addr.vapi_af)
24 sw_if_index == n.neighbor.sw_if_index
25 and ip_addr == n.neighbor.ip_address
26 and is_static == (n.neighbor.flags & e.IP_API_NEIGHBOR_FLAG_STATIC)
29 if mac == str(n.neighbor.mac_address):
36 class VppNeighbor(VppObject):
48 is_no_fib_entry=False,
51 self.sw_if_index = sw_if_index
52 self.mac_addr = mac_addr
53 self.nbr_addr = nbr_addr
55 e = VppEnum.vl_api_ip_neighbor_flags_t
56 self.flags = e.IP_API_NEIGHBOR_FLAG_NONE
58 self.flags |= e.IP_API_NEIGHBOR_FLAG_STATIC
60 self.flags |= e.IP_API_NEIGHBOR_FLAG_NO_FIB_ENTRY
62 def add_vpp_config(self):
63 r = self._test.vapi.ip_neighbor_add_del(
64 self.sw_if_index, self.mac_addr, self.nbr_addr, is_add=1, flags=self.flags
66 self.stats_index = r.stats_index
67 self._test.registry.register(self, self._test.logger)
70 def remove_vpp_config(self):
71 self._test.vapi.ip_neighbor_add_del(
72 self.sw_if_index, self.mac_addr, self.nbr_addr, is_add=0, flags=self.flags
76 e = VppEnum.vl_api_ip_neighbor_flags_t
77 return self.flags & e.IP_API_NEIGHBOR_FLAG_STATIC
79 def query_vpp_config(self):
80 return find_nbr(self._test, self.sw_if_index, self.nbr_addr, self.is_static())
83 return "%d:%s" % (self.sw_if_index, self.nbr_addr)
86 c = self._test.statistics["/net/adjacency"]
87 return c[0][self.stats_index]