summaryrefslogtreecommitdiffstats
path: root/test/vpp_teib.py
blob: e117ac39302b5ac0205c60349f4fb8bbc8c88b0a (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
#!/usr/bin/env python
"""
  NHRP objects
"""

from vpp_object import VppObject


def find_teib(test, ne):
    ns = test.vapi.teib_dump()
    for n in ns:
        if ne.peer == str(n.entry.peer) \
           and ne.itf._sw_if_index == n.entry.sw_if_index:
            return True
    return False


class VppNhrp(VppObject):

    def __init__(self, test, itf, peer, nh, table_id=0):
        self._test = test
        self.table_id = table_id
        self.peer = peer
        self.itf = itf
        self.nh = nh

    def add_vpp_config(self):
        r = self._test.vapi.teib_entry_add_del(
            is_add=1,
            entry={
                'nh_table_id': self.table_id,
                'sw_if_index': self.itf.sw_if_index,
                'peer': self.peer,
                'nh': self.nh,
            })
        self._test.registry.register(self, self._test.logger)

    def remove_vpp_config(self):
        r = self._test.vapi.teib_entry_add_del(
            is_add=0,
            entry={
                'nh_table_id': self.table_id,
                'sw_if_index': self.itf.sw_if_index,
                'peer': self.peer,
            })

    def query_vpp_config(self):
        return find_teib(self._test, self)

    def object_id(self):
        return ("teib-%s-%s" % (self.itf, self.peer))