ip: add API to retrieve IPv6 link-layer address

Type: feature

Change-Id: I5739869490155b0b9674b4faf61882d97e66a4ed
Signed-off-by: Benoît Ganne <bganne@cisco.com>
This commit is contained in:
Benoît Ganne
2021-01-18 19:24:34 +01:00
committed by Neale Ranns
parent b2525922cd
commit 58a1915b50
3 changed files with 89 additions and 37 deletions

View File

@ -20,7 +20,7 @@
called through a shared memory interface. called through a shared memory interface.
*/ */
option version = "3.0.1"; option version = "3.0.2";
import "vnet/interface_types.api"; import "vnet/interface_types.api";
import "vnet/fib/fib_types.api"; import "vnet/fib/fib_types.api";
@ -549,6 +549,29 @@ autoreply define sw_interface_ip6_set_link_local_address
vl_api_ip6_address_t ip; vl_api_ip6_address_t ip;
}; };
/** \brief IPv6 get link local address on interface request
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
@param sw_if_index - interface to set link local on
*/
define sw_interface_ip6_get_link_local_address
{
u32 client_index;
u32 context;
vl_api_interface_index_t sw_if_index;
};
/** \brief IPv6 link local address detail
@param context - sender context, to match reply w/ request
@param ip - the link local address
*/
define sw_interface_ip6_get_link_local_address_reply
{
u32 context;
i32 retval;
vl_api_ip6_address_t ip;
};
/** \brief IOAM enable : Enable in-band OAM /** \brief IOAM enable : Enable in-band OAM
@param id - profile id @param id - profile id
@param seqno - To enable Seqno Processing @param seqno - To enable Seqno Processing

View File

@ -97,6 +97,8 @@ _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
ip_source_and_port_range_check_interface_add_del) \ ip_source_and_port_range_check_interface_add_del) \
_ (SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \ _ (SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
sw_interface_ip6_set_link_local_address) \ sw_interface_ip6_set_link_local_address) \
_ (SW_INTERFACE_IP6_GET_LINK_LOCAL_ADDRESS, \
sw_interface_ip6_get_link_local_address) \
_ (IP_REASSEMBLY_SET, ip_reassembly_set) \ _ (IP_REASSEMBLY_SET, ip_reassembly_set) \
_ (IP_REASSEMBLY_GET, ip_reassembly_get) \ _ (IP_REASSEMBLY_GET, ip_reassembly_get) \
_ (IP_REASSEMBLY_ENABLE_DISABLE, ip_reassembly_enable_disable) \ _ (IP_REASSEMBLY_ENABLE_DISABLE, ip_reassembly_enable_disable) \
@ -1363,6 +1365,30 @@ static void
REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY); REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
} }
static void
vl_api_sw_interface_ip6_get_link_local_address_t_handler (
vl_api_sw_interface_ip6_get_link_local_address_t *mp)
{
vl_api_sw_interface_ip6_get_link_local_address_reply_t *rmp;
const ip6_address_t *ip = NULL;
int rv = 0;
VALIDATE_SW_IF_INDEX (mp);
ip = ip6_get_link_local_address (ntohl (mp->sw_if_index));
if (NULL == ip)
rv = VNET_API_ERROR_IP6_NOT_ENABLED;
BAD_SW_IF_INDEX_LABEL;
/* clang-format off */
REPLY_MACRO2 (VL_API_SW_INTERFACE_IP6_GET_LINK_LOCAL_ADDRESS_REPLY,
({
if (!rv)
ip6_address_encode (ip, rmp->ip);
}))
/* clang-format on */
}
static void static void
vl_api_ip_table_replace_begin_t_handler (vl_api_ip_table_replace_begin_t * mp) vl_api_ip_table_replace_begin_t_handler (vl_api_ip_table_replace_begin_t * mp)
{ {

View File

@ -97,6 +97,10 @@ class VppInterface(metaclass=abc.ABCMeta):
@property @property
def local_ip6_ll(self): def local_ip6_ll(self):
"""Local IPv6 link-local address on VPP interface (string).""" """Local IPv6 link-local address on VPP interface (string)."""
if not self._local_ip6_ll:
self._local_ip6_ll = str(
self.test.vapi.sw_interface_ip6_get_link_local_address(
self.sw_if_index).ip)
return self._local_ip6_ll return self._local_ip6_ll
@property @property
@ -192,7 +196,6 @@ class VppInterface(metaclass=abc.ABCMeta):
def set_mac(self, mac): def set_mac(self, mac):
self._local_mac = str(mac) self._local_mac = str(mac)
self._local_ip6_ll = mk_ll_addr(self._local_mac)
self.test.vapi.sw_interface_set_mac_address( self.test.vapi.sw_interface_set_mac_address(
self.sw_if_index, mac.packed) self.sw_if_index, mac.packed)
return self return self
@ -234,8 +237,8 @@ class VppInterface(metaclass=abc.ABCMeta):
"Could not find interface with sw_if_index %d " "Could not find interface with sw_if_index %d "
"in interface dump %s" % "in interface dump %s" %
(self.sw_if_index, moves.reprlib.repr(r))) (self.sw_if_index, moves.reprlib.repr(r)))
self._local_ip6_ll = mk_ll_addr(self.local_mac)
self._remote_ip6_ll = mk_ll_addr(self.remote_mac) self._remote_ip6_ll = mk_ll_addr(self.remote_mac)
self._local_ip6_ll = None
def config_ip4(self): def config_ip4(self):
"""Configure IPv4 address on the VPP interface.""" """Configure IPv4 address on the VPP interface."""