blob: 0fe733388e37e2a58f00477452022ba6c824a415 [file] [log] [blame]
Neale Ranns5f8f6172019-04-18 10:23:56 +00001#!/usr/bin/env python
2"""
Neale Ranns28287212019-12-16 00:53:11 +00003 TEIB objects
Neale Ranns5f8f6172019-04-18 10:23:56 +00004"""
5
6from vpp_object import VppObject
7
8
Neale Ranns03ce4622020-02-03 10:55:09 +00009def find_teib(test, ne):
10 ns = test.vapi.teib_dump()
Neale Ranns5f8f6172019-04-18 10:23:56 +000011 for n in ns:
12 if ne.peer == str(n.entry.peer) \
13 and ne.itf._sw_if_index == n.entry.sw_if_index:
14 return True
15 return False
16
17
Neale Ranns28287212019-12-16 00:53:11 +000018class VppTeib(VppObject):
Neale Ranns5f8f6172019-04-18 10:23:56 +000019
20 def __init__(self, test, itf, peer, nh, table_id=0):
21 self._test = test
22 self.table_id = table_id
23 self.peer = peer
24 self.itf = itf
25 self.nh = nh
26
27 def add_vpp_config(self):
Neale Ranns03ce4622020-02-03 10:55:09 +000028 r = self._test.vapi.teib_entry_add_del(
Neale Ranns5f8f6172019-04-18 10:23:56 +000029 is_add=1,
30 entry={
31 'nh_table_id': self.table_id,
32 'sw_if_index': self.itf.sw_if_index,
33 'peer': self.peer,
34 'nh': self.nh,
35 })
36 self._test.registry.register(self, self._test.logger)
Neale Ranns28287212019-12-16 00:53:11 +000037 return self
Neale Ranns5f8f6172019-04-18 10:23:56 +000038
39 def remove_vpp_config(self):
Neale Ranns03ce4622020-02-03 10:55:09 +000040 r = self._test.vapi.teib_entry_add_del(
Neale Ranns5f8f6172019-04-18 10:23:56 +000041 is_add=0,
42 entry={
43 'nh_table_id': self.table_id,
44 'sw_if_index': self.itf.sw_if_index,
45 'peer': self.peer,
46 })
47
48 def query_vpp_config(self):
Neale Ranns03ce4622020-02-03 10:55:09 +000049 return find_teib(self._test, self)
Neale Ranns5f8f6172019-04-18 10:23:56 +000050
51 def object_id(self):
Neale Ranns03ce4622020-02-03 10:55:09 +000052 return ("teib-%s-%s" % (self.itf, self.peer))