Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 1 | from vpp_object import VppObject |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 2 | from vpp_interface import VppInterface |
| 3 | |
| 4 | |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 5 | class VppLoInterface(VppInterface, VppObject): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 6 | """VPP loopback interface.""" |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 7 | |
| 8 | def __init__(self, test, lo_index): |
| 9 | """ Create VPP loopback interface """ |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 10 | self._test = test |
| 11 | self.add_vpp_config() |
Matej Klotton | c5bf07f | 2016-11-23 15:27:17 +0100 | [diff] [blame] | 12 | super(VppLoInterface, self).__init__(test) |
| 13 | self._lo_index = lo_index |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 14 | |
| 15 | def add_vpp_config(self): |
| 16 | r = self.test.vapi.create_loopback() |
| 17 | self._sw_if_index = r.sw_if_index |
| 18 | |
| 19 | def remove_vpp_config(self): |
| 20 | self.test.vapi.delete_loopback(self.sw_if_index) |
| 21 | |
| 22 | def query_vpp_config(self): |
| 23 | dump = self.vapi.sw_interface_dump() |
| 24 | return self.is_interface_config_in_dump(dump) |
| 25 | |
| 26 | def is_interface_config_in_dump(self, dump): |
| 27 | for i in dump: |
| 28 | if i.interface_name.rstrip(' \t\r\n\0') == self.name and \ |
| 29 | i.sw_if_index == self.sw_if_index: |
| 30 | return True |
| 31 | else: |
| 32 | return False |
| 33 | |
| 34 | def object_id(self): |
| 35 | return "loopback-%d" % self._sw_if_index |