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
|
2018-08-10 05:30:06 -07:00
|
|
|
from vpp_papi import mac_pton, VppEnum
|
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
|
2020-04-28 00:27:38 -04: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:
|
2020-09-23 11:25:21 +00:00
|
|
|
if sw_if_index == n.neighbor.sw_if_index and \
|
|
|
|
ip_addr == n.neighbor.ip_address and \
|
2018-08-10 05:30:06 -07:00
|
|
|
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
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, test, sw_if_index, mac_addr, nbr_addr,
|
2018-08-10 05:30:06 -07:00
|
|
|
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(
|
2017-02-16 21:57:05 -08:00
|
|
|
self.sw_if_index,
|
|
|
|
self.mac_addr,
|
2018-08-10 05:30:06 -07:00
|
|
|
self.nbr_addr,
|
2017-02-16 21:57:05 -08:00
|
|
|
is_add=1,
|
2018-08-10 05:30:06 -07:00
|
|
|
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(
|
|
|
|
self.sw_if_index,
|
|
|
|
self.mac_addr,
|
2018-08-10 05:30:06 -07:00
|
|
|
self.nbr_addr,
|
2017-02-16 21:57:05 -08:00
|
|
|
is_add=0,
|
2018-08-10 05:30:06 -07:00
|
|
|
flags=self.flags)
|
|
|
|
|
|
|
|
def is_static(self):
|
|
|
|
e = VppEnum.vl_api_ip_neighbor_flags_t
|
|
|
|
return (self.flags & e.IP_API_NEIGHBOR_FLAG_STATIC)
|
2017-02-16 21:57:05 -08:00
|
|
|
|
|
|
|
def query_vpp_config(self):
|
2018-03-27 13:25:17 -07:00
|
|
|
return find_nbr(self._test,
|
|
|
|
self.sw_if_index,
|
|
|
|
self.nbr_addr,
|
2018-08-10 05:30:06 -07:00
|
|
|
self.is_static())
|
2017-02-16 21:57:05 -08:00
|
|
|
|
|
|
|
def object_id(self):
|
2018-03-27 13:25:17 -07: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]
|