2017-02-16 21:57:05 -08:00
|
|
|
"""
|
|
|
|
Neighbour Entries
|
|
|
|
|
|
|
|
object abstractions for ARP and ND
|
|
|
|
"""
|
|
|
|
|
2018-08-10 05:30:06 -07:00
|
|
|
from ipaddress import ip_address
|
2019-02-28 09:00:09 -08:00
|
|
|
from vpp_object import VppObject
|
2023-08-31 00:47:44 -04:00
|
|
|
from vpp_papi import VppEnum
|
2022-04-26 19:02:15 +02:00
|
|
|
|
2018-11-25 16:09:26 -08:00
|
|
|
try:
|
|
|
|
text_type = unicode
|
|
|
|
except NameError:
|
|
|
|
text_type = str
|
2017-02-16 21:57:05 -08:00
|
|
|
|
|
|
|
|
2018-08-10 05:30:06 -07:00
|
|
|
def find_nbr(test, sw_if_index, nbr_addr, is_static=0, mac=None):
|
2018-11-25 16:09:26 -08:00
|
|
|
ip_addr = ip_address(text_type(nbr_addr))
|
2018-08-10 05:30:06 -07:00
|
|
|
e = VppEnum.vl_api_ip_neighbor_flags_t
|
2022-04-26 19:02:15 +02:00
|
|
|
nbrs = test.vapi.ip_neighbor_dump(sw_if_index=sw_if_index, af=ip_addr.vapi_af)
|
2017-02-16 21:57:05 -08:00
|
|
|
|
|
|
|
for n in nbrs:
|
2022-04-26 19:02:15 +02:00
|
|
|
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)
|
|
|
|
):
|
2018-06-07 18:09:49 -07:00
|
|
|
if mac:
|
2018-08-10 05:30:06 -07:00
|
|
|
if mac == str(n.neighbor.mac_address):
|
2018-06-07 18:09:49 -07:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return True
|
2017-02-16 21:57:05 -08:00
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
class VppNeighbor(VppObject):
|
|
|
|
"""
|
|
|
|
ARP Entry
|
|
|
|
"""
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
test,
|
|
|
|
sw_if_index,
|
|
|
|
mac_addr,
|
|
|
|
nbr_addr,
|
|
|
|
is_static=False,
|
|
|
|
is_no_fib_entry=False,
|
|
|
|
):
|
2017-02-16 21:57:05 -08:00
|
|
|
self._test = test
|
|
|
|
self.sw_if_index = sw_if_index
|
2018-08-10 05:30:06 -07:00
|
|
|
self.mac_addr = mac_addr
|
2018-03-27 13:25:17 -07:00
|
|
|
self.nbr_addr = nbr_addr
|
2018-08-10 05:30:06 -07:00
|
|
|
|
|
|
|
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
|
2017-02-16 21:57:05 -08:00
|
|
|
|
|
|
|
def add_vpp_config(self):
|
2018-09-28 05:00:57 -07:00
|
|
|
r = self._test.vapi.ip_neighbor_add_del(
|
2022-04-26 19:02:15 +02:00
|
|
|
self.sw_if_index, self.mac_addr, self.nbr_addr, is_add=1, flags=self.flags
|
|
|
|
)
|
2018-09-28 05:00:57 -07:00
|
|
|
self.stats_index = r.stats_index
|
2017-02-16 21:57:05 -08:00
|
|
|
self._test.registry.register(self, self._test.logger)
|
2019-10-30 17:34:14 +00:00
|
|
|
return self
|
2017-02-16 21:57:05 -08:00
|
|
|
|
|
|
|
def remove_vpp_config(self):
|
|
|
|
self._test.vapi.ip_neighbor_add_del(
|
2022-04-26 19:02:15 +02:00
|
|
|
self.sw_if_index, self.mac_addr, self.nbr_addr, is_add=0, flags=self.flags
|
|
|
|
)
|
2018-08-10 05:30:06 -07:00
|
|
|
|
|
|
|
def is_static(self):
|
|
|
|
e = VppEnum.vl_api_ip_neighbor_flags_t
|
2022-04-26 19:02:15 +02:00
|
|
|
return self.flags & e.IP_API_NEIGHBOR_FLAG_STATIC
|
2017-02-16 21:57:05 -08:00
|
|
|
|
|
|
|
def query_vpp_config(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
return find_nbr(self._test, self.sw_if_index, self.nbr_addr, self.is_static())
|
2017-02-16 21:57:05 -08:00
|
|
|
|
|
|
|
def object_id(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
return "%d:%s" % (self.sw_if_index, self.nbr_addr)
|
2018-09-28 05:00:57 -07:00
|
|
|
|
|
|
|
def get_stats(self):
|
2021-03-18 11:12:01 +01:00
|
|
|
c = self._test.statistics["/net/adjacency"]
|
2018-09-28 05:00:57 -07:00
|
|
|
return c[0][self.stats_index]
|