[Proxy] ARP tests

Change-Id: I40d6d763b55a26cdee0afef85d1acdd19dd10dd6
Signed-off-by: Neale Ranns <nranns@cisco.com>
This commit is contained in:
Neale Ranns
2017-02-16 21:57:05 -08:00
committed by Damjan Marion
parent 3e7b569361
commit 39f9d8bd22
5 changed files with 587 additions and 0 deletions

425
test/test_neighbor.py Normal file

File diff suppressed because it is too large Load Diff

View File

@ -47,6 +47,11 @@ def ip4n_range(ip4n, s, e):
for ip in ip4_range(ip4, s, e))
def mactobinary(mac):
""" Convert the : separated format into binary packet data for the API """
return mac.replace(':', '').decode('hex')
class NumericConstant(object):
__metaclass__ = ABCMeta

View File

@ -2,6 +2,7 @@ from abc import abstractmethod, ABCMeta
import socket
from util import Host
from vpp_neighbor import VppNeighbor
class VppInterface(object):
@ -316,3 +317,15 @@ class VppInterface(object):
i.table_id == self.ip4_table_id:
return True
return False
def set_unnumbered(self, ip_sw_if_index):
""" Set the interface to unnumbered via ip_sw_if_index """
self.test.vapi.sw_interface_set_unnumbered(
self.sw_if_index,
ip_sw_if_index)
def set_proxy_arp(self, enable=1):
""" Set the interface to enable/disable Proxy ARP """
self.test.vapi.proxy_arp_intfc_enable_disable(
self.sw_if_index,
enable)

77
test/vpp_neighbor.py Normal file
View File

@ -0,0 +1,77 @@
"""
Neighbour Entries
object abstractions for ARP and ND
"""
from socket import inet_pton, inet_ntop, AF_INET, AF_INET6
from vpp_object import *
from util import mactobinary
def find_nbr(test, sw_if_index, ip_addr, is_static=0, inet=AF_INET):
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)
for n in nbrs:
if nbr_addr == n.ip_address[:s] \
and is_static == n.is_static:
return True
return False
class VppNeighbor(VppObject):
"""
ARP Entry
"""
def __init__(self, test, sw_if_index, mac_addr, nbr_addr,
af=AF_INET, is_static=0):
self._test = test
self.sw_if_index = sw_if_index
self.mac_addr = mactobinary(mac_addr)
self.af = af
self.is_static = is_static
self.nbr_addr = inet_pton(af, nbr_addr)
def add_vpp_config(self):
self._test.vapi.ip_neighbor_add_del(
self.sw_if_index,
self.mac_addr,
self.nbr_addr,
is_add=1,
is_ipv6=1 if AF_INET6 == self.af else 0,
is_static=self.is_static)
self._test.registry.register(self, self._test.logger)
def remove_vpp_config(self):
self._test.vapi.ip_neighbor_add_del(
self.sw_if_index,
self.mac_addr,
self.nbr_addr,
is_ipv6=1 if AF_INET6 == self.af else 0,
is_add=0,
is_static=self.is_static)
def query_vpp_config(self):
dump = self._test.vapi.ip_neighbor_dump(
self.sw_if_index,
is_ipv6=1 if AF_INET6 == self.af else 0)
for n in dump:
if self.nbr_addr == n.ip_address \
and self.is_static == n.is_static:
return True
return False
def __str__(self):
return self.object_id()
def object_id(self):
return ("%d:%s"
% (self.sw_if_index,
inet_ntop(self.af, self.nbr_addr)))

View File

@ -240,6 +240,20 @@ class VppPapiProvider(object):
'address_length': addr_len,
'address': addr})
def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index,
is_add=1):
""" Set the Interface to be unnumbered
:param is_add: (Default value = 1)
:param sw_if_index - interface That will be unnumbered
:param ip_sw_if_index - interface with an IP addres
"""
return self.api(self.papi.sw_interface_set_unnumbered,
{'sw_if_index': ip_sw_if_index,
'unnumbered_sw_if_index': sw_if_index,
'is_add': is_add})
def sw_interface_enable_disable_mpls(self, sw_if_index,
is_enable=1):
"""
@ -638,6 +652,59 @@ class VppPapiProvider(object):
}
)
def ip_neighbor_dump(self,
sw_if_index,
is_ipv6=0):
""" Return IP neighbor dump.
:param sw_if_index:
:param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
"""
return self.api(
self.papi.ip_neighbor_dump,
{'is_ipv6': is_ipv6,
'sw_if_index': sw_if_index
}
)
def proxy_arp_add_del(self,
low_address,
hi_address,
vrf_id=0,
is_add=1):
""" Config Proxy Arp Range.
:param low_address: Start address in the rnage to Proxy for
:param hi_address: End address in the rnage to Proxy for
:param vrf_id: The VRF/table in which to proxy
"""
return self.api(
self.papi.proxy_arp_add_del,
{'vrf_id': vrf_id,
'is_add': is_add,
'low_address': low_address,
'hi_address': hi_address,
}
)
def proxy_arp_intfc_enable_disable(self,
sw_if_index,
is_enable=1):
""" Enable/Disable an interface for proxy ARP requests
:param sw_if_index: Interface
:param enable_disable: Enable/Disable
"""
return self.api(
self.papi.proxy_arp_intfc_enable_disable,
{'sw_if_index': sw_if_index,
'enable_disable': is_enable
}
)
def reset_vrf(self,
vrf_id,
is_ipv6=0,