summaryrefslogtreecommitdiffstats
path: root/test/vpp_neighbor.py
blob: 5919cf8e48ba80d212985d95c7a5e0a65fcadce4 (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
"""
  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=False, is_no_fib_entry=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.is_no_fib_entry = is_no_fib_entry
        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,
            is_no_adj_fib=self.is_no_fib_entry)
        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)))
n class="n">u32 eir_pps; u64 cb_ms; u64 eb_ms; } pps; } rb; /* rate burst config */ u8 rate_type; /* sse2_qos_rate_type_en */ u8 rnd_type; /* sse2_qos_round_type_en */ u8 rfc; /* sse2_qos_policer_type_en */ u8 color_aware; u8 overwrite_bucket; /* for debugging purposes */ u32 current_bucket; /* for debugging purposes */ u32 extended_bucket; /* for debugging purposes */ sse2_qos_pol_action_params_st conform_action; sse2_qos_pol_action_params_st exceed_action; sse2_qos_pol_action_params_st violate_action; } sse2_qos_pol_cfg_params_st; typedef struct sse2_qos_pol_hw_params_st_ { u8 rfc; u8 allow_negative; u8 rate_exp; u16 avg_rate_man; u16 peak_rate_man; u8 comm_bkt_limit_exp; u8 comm_bkt_limit_man; u8 extd_bkt_limit_exp; u8 extd_bkt_limit_man; u32 comm_bkt; u32 extd_bkt; } sse2_qos_pol_hw_params_st; int sse2_pol_logical_2_physical (sse2_qos_pol_cfg_params_st * cfg, policer_read_response_type_st * phys); #endif /* __included_xlate_h__ */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */