Dave Wallace | 54a7780 | 2020-11-30 16:56:43 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 2 | """ |
Neale Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 3 | TEIB objects |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 4 | """ |
| 5 | |
| 6 | from vpp_object import VppObject |
| 7 | |
| 8 | |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 9 | def find_teib(test, ne): |
| 10 | ns = test.vapi.teib_dump() |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 11 | for n in ns: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 12 | if ne.peer == str(n.entry.peer) and ne.itf._sw_if_index == n.entry.sw_if_index: |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 13 | return True |
| 14 | return False |
| 15 | |
| 16 | |
Neale Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 17 | class VppTeib(VppObject): |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 18 | 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 Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 26 | r = self._test.vapi.teib_entry_add_del( |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 27 | is_add=1, |
| 28 | entry={ |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 29 | "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 Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 35 | self._test.registry.register(self, self._test.logger) |
Neale Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 36 | return self |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 37 | |
| 38 | def remove_vpp_config(self): |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 39 | r = self._test.vapi.teib_entry_add_del( |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 40 | is_add=0, |
| 41 | entry={ |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 42 | "nh_table_id": self.table_id, |
| 43 | "sw_if_index": self.itf.sw_if_index, |
| 44 | "peer": self.peer, |
| 45 | }, |
| 46 | ) |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 47 | |
| 48 | def query_vpp_config(self): |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 49 | return find_teib(self._test, self) |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 50 | |
| 51 | def object_id(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 52 | return "teib-%s-%s" % (self.itf, self.peer) |