summaryrefslogtreecommitdiffstats
path: root/test/vpp_neighbor.py
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2018-08-10 05:30:06 -0700
committerDamjan Marion <dmarion@me.com>2019-01-30 19:47:53 +0000
commit37029305c671f4e2d091d6f6c22142634e409043 (patch)
treef47257c77b860213fcd1901686874dee43ad1f73 /test/vpp_neighbor.py
parent13b2ba2ad5527c8185dce368993a3877e7daf7a2 (diff)
Use IP and MAC API types for neighbors
use address_t and mac_address_t for IPv6 and ARP entries and all other API calls in ip.api aprat from the route ones, that will follow in a separate commit Change-Id: I67161737c2184d3f8fc1e79ebd2b55121c5b0191 Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'test/vpp_neighbor.py')
-rw-r--r--test/vpp_neighbor.py54
1 files changed, 27 insertions, 27 deletions
diff --git a/test/vpp_neighbor.py b/test/vpp_neighbor.py
index 7815a286fef..7391447ff9b 100644
--- a/test/vpp_neighbor.py
+++ b/test/vpp_neighbor.py
@@ -4,25 +4,22 @@
object abstractions for ARP and ND
"""
-from socket import inet_pton, inet_ntop, AF_INET, AF_INET6
+from ipaddress import ip_address
from vpp_object import *
-from vpp_papi import mac_pton
+from vpp_papi import mac_pton, VppEnum
-def find_nbr(test, sw_if_index, ip_addr, is_static=0, inet=AF_INET, mac=None):
+def find_nbr(test, sw_if_index, nbr_addr, is_static=0, mac=None):
+ ip_addr = ip_address(unicode(nbr_addr))
+ e = VppEnum.vl_api_ip_neighbor_flags_t
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)
+ is_ipv6=(6 is ip_addr.version))
for n in nbrs:
- if nbr_addr == n.ip_address[:s] \
- and is_static == n.is_static:
+ if ip_addr == n.neighbor.ip_address and \
+ is_static == (n.neighbor.flags & e.IP_API_NEIGHBOR_FLAG_STATIC):
if mac:
- if n.mac_address == mac_pton(mac):
+ if mac == str(n.neighbor.mac_address):
return True
else:
return True
@@ -35,25 +32,26 @@ class VppNeighbor(VppObject):
"""
def __init__(self, test, sw_if_index, mac_addr, nbr_addr,
- af=AF_INET, is_static=False, is_no_fib_entry=0):
+ is_static=False, is_no_fib_entry=False):
self._test = test
self.sw_if_index = sw_if_index
- self.mac_addr = mac_pton(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):
r = self._test.vapi.ip_neighbor_add_del(
self.sw_if_index,
self.mac_addr,
- self.nbr_addr_n,
+ self.nbr_addr,
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)
+ flags=self.flags)
self.stats_index = r.stats_index
self._test.registry.register(self, self._test.logger)
@@ -61,17 +59,19 @@ class VppNeighbor(VppObject):
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,
+ self.nbr_addr,
is_add=0,
- is_static=self.is_static)
+ flags=self.flags)
+
+ def is_static(self):
+ e = VppEnum.vl_api_ip_neighbor_flags_t
+ return (self.flags & e.IP_API_NEIGHBOR_FLAG_STATIC)
def query_vpp_config(self):
return find_nbr(self._test,
self.sw_if_index,
self.nbr_addr,
- self.is_static,
- self.af)
+ self.is_static())
def __str__(self):
return self.object_id()