aboutsummaryrefslogtreecommitdiffstats
path: root/test/vpp_neighbor.py
blob: d7940266605bf289b8da49b5ba2116dcf714940b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"""
  Neighbour Entries

  object abstractions for ARP and ND
"""

from ipaddress import ip_address
from vpp_object import VppObject
from vpp_papi import mac_pton, VppEnum

try:
    text_type = unicode
except NameError:
    text_type = str


def find_nbr(test, sw_if_index, nbr_addr, is_static=0, mac=None):
    ip_addr = ip_address(text_type(nbr_addr))
    e = VppEnum.vl_api_ip_neighbor_flags_t
    nbrs = test.vapi.ip_neighbor_dump(sw_if_index=sw_if_index, af=ip_addr.vapi_af)

    for n in nbrs:
        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)
        ):
            if mac:
                if mac == str(n.neighbor.mac_address):
                    return True
            else:
                return True
    return False


class VppNeighbor(VppObject):
    """
    ARP Entry
    """

    def __init__(
        self,
        test,
        sw_if_index,
        mac_addr,
        nbr_addr,
        is_static=False,
        is_no_fib_entry=False,
    ):
        self._test = test
        self.sw_if_index = sw_if_index
        self.mac_addr = mac_addr
        self.nbr_addr = 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, is_add=1, flags=self.flags
        )
        self.stats_index = r.stats_index
        self._test.registry.register(self, self._test.logger)
        return self

    def remove_vpp_config(self):
        self._test.vapi.ip_neighbor_add_del(
            self.sw_if_index, self.mac_addr, self.nbr_addr, is_add=0, 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())

    def object_id(self):
        return "%d:%s" % (self.sw_if_index, self.nbr_addr)

    def get_stats(self):
        c = self._test.statistics["/net/adjacency"]
        return c[0][self.stats_index]
n> data); extern int vnet_set_ip6_ethernet_neighbor (vlib_main_t * vm, u32 sw_if_index, const ip6_address_t * a, const u8 * link_layer_address, uword n_bytes_link_layer_address, int is_static, int is_no_fib_entry); extern int vnet_unset_ip6_ethernet_neighbor (vlib_main_t * vm, u32 sw_if_index, const ip6_address_t * a); extern int ip6_neighbor_proxy_add_del (u32 sw_if_index, ip6_address_t * addr, u8 is_add); u32 ip6_neighbor_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add); typedef struct { u32 sw_if_index; ip6_address_t ip6; u8 mac[6]; } wc_nd_report_t; void wc_nd_set_publisher_node (uword node_index, uword event_type); typedef struct { u32 irt; u32 mrt; u32 mrc; u32 mrd; } icmp6_send_router_solicitation_params_t; void icmp6_send_router_solicitation (vlib_main_t * vm, u32 sw_if_index, u8 stop, icmp6_send_router_solicitation_params_t * params); typedef struct { ip6_address_t dst_address; u8 dst_address_length; u8 flags; u32 valid_time; u32 preferred_time; } ra_report_prefix_info_t; typedef struct { u32 sw_if_index; u8 router_address[16]; u8 current_hop_limit; u8 flags; u16 router_lifetime_in_sec; u32 neighbor_reachable_time_in_msec; u32 time_in_msec_between_retransmitted_neighbor_solicitations; u8 slla[6]; u32 mtu; ra_report_prefix_info_t *prefixes; } ra_report_t; void ra_set_publisher_node (uword node_index, uword event_type); typedef struct _vnet_ip6_neighbor_function_list_elt { struct _vnet_ip6_neighbor_function_list_elt *next_ip6_neighbor_function; clib_error_t *(*fp) (void *data); } _vnet_ip6_neighbor_function_list_elt_t; typedef struct { _vnet_ip6_neighbor_function_list_elt_t *ra_report_functions; } ip6_neighbor_public_main_t; extern ip6_neighbor_public_main_t ip6_neighbor_public_main; #define _VNET_IP6_NEIGHBOR_FUNCTION_DECL(f,tag) \ \ static void __vnet_ip6_neighbor_function_init_##tag##_##f (void) \ __attribute__((__constructor__)) ; \ \ static void __vnet_ip6_neighbor_function_init_##tag##_##f (void) \ { \ ip6_neighbor_public_main_t * nm = &ip6_neighbor_public_main; \ static _vnet_ip6_neighbor_function_list_elt_t init_function; \ init_function.next_ip6_neighbor_function = nm->tag##_functions; \ nm->tag##_functions = &init_function; \ init_function.fp = (void *) &f; \ } \ \ static void __vnet_ip6_neighbor_function_deinit_##tag##_##f (void) \ __attribute__((__destructor__)) ; \ \ static void __vnet_ip6_neighbor_function_deinit_##tag##_##f (void) \ { \ ip6_neighbor_public_main_t * nm = &ip6_neighbor_public_main; \ _vnet_ip6_neighbor_function_list_elt_t *next; \ if (nm->tag##_functions->fp == (void *) &f) \ { \ nm->tag##_functions = \ nm->tag##_functions->next_ip6_neighbor_function; \ return; \ } \ next = nm->tag##_functions; \ while (next->next_ip6_neighbor_function) \ { \ if (next->next_ip6_neighbor_function->fp == (void *) &f) \ { \ next->next_ip6_neighbor_function = \ next->next_ip6_neighbor_function->next_ip6_neighbor_function; \ return; \ } \ next = next->next_ip6_neighbor_function; \ } \ } #define VNET_IP6_NEIGHBOR_RA_FUNCTION(f) \ _VNET_IP6_NEIGHBOR_FUNCTION_DECL(f,ra_report) clib_error_t *call_ip6_neighbor_callbacks (void *data, _vnet_ip6_neighbor_function_list_elt_t * elt); #endif /* included_ip6_neighbor_h */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */