blob: 14688181582862c1a418c240b37e0739fe29405e [file] [log] [blame]
Dave Wallace54a77802020-11-30 16:56:43 -05001#!/usr/bin/env python3
Neale Ranns5f8f6172019-04-18 10:23:56 +00002"""
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:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020012 if ne.peer == str(n.entry.peer) and ne.itf._sw_if_index == n.entry.sw_if_index:
Neale Ranns5f8f6172019-04-18 10:23:56 +000013 return True
14 return False
15
16
Neale Ranns28287212019-12-16 00:53:11 +000017class VppTeib(VppObject):
Neale Ranns5f8f6172019-04-18 10:23:56 +000018 def __init__(self, test, itf, peer, nh, table_id=0):
19 self._test = test
20 self.table_id = table_id
21 self.peer = peer
22 self.itf = itf
23 self.nh = nh
24
25 def add_vpp_config(self):
Neale Ranns03ce4622020-02-03 10:55:09 +000026 r = self._test.vapi.teib_entry_add_del(
Neale Ranns5f8f6172019-04-18 10:23:56 +000027 is_add=1,
28 entry={
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020029 "nh_table_id": self.table_id,
30 "sw_if_index": self.itf.sw_if_index,
31 "peer": self.peer,
32 "nh": self.nh,
33 },
34 )
Neale Ranns5f8f6172019-04-18 10:23:56 +000035 self._test.registry.register(self, self._test.logger)
Neale Ranns28287212019-12-16 00:53:11 +000036 return self
Neale Ranns5f8f6172019-04-18 10:23:56 +000037
38 def remove_vpp_config(self):
Neale Ranns03ce4622020-02-03 10:55:09 +000039 r = self._test.vapi.teib_entry_add_del(
Neale Ranns5f8f6172019-04-18 10:23:56 +000040 is_add=0,
41 entry={
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020042 "nh_table_id": self.table_id,
43 "sw_if_index": self.itf.sw_if_index,
44 "peer": self.peer,
45 },
46 )
Neale Ranns5f8f6172019-04-18 10:23:56 +000047
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):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020052 return "teib-%s-%s" % (self.itf, self.peer)