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: |
| 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 Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 18 | class VppTeib(VppObject): |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 19 | |
| 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 Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 28 | r = self._test.vapi.teib_entry_add_del( |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 29 | 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 Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 37 | return self |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 38 | |
| 39 | def remove_vpp_config(self): |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 40 | r = self._test.vapi.teib_entry_add_del( |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 41 | 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 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): |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 52 | return ("teib-%s-%s" % (self.itf, self.peer)) |