Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1 | |
| 2 | from vpp_interface import VppInterface |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 3 | |
| 4 | |
| 5 | class VppMPLSTunnelInterface(VppInterface): |
| 6 | """ |
| 7 | VPP MPLS Tunnel interface |
| 8 | """ |
| 9 | |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 10 | def __init__(self, test, paths, is_multicast=0, is_l2=0): |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 11 | """ Create MPLS Tunnel interface """ |
Klement Sekera | b9ef273 | 2018-06-24 22:49:33 +0200 | [diff] [blame] | 12 | super(VppMPLSTunnelInterface, self).__init__(test) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 13 | self.t_paths = paths |
| 14 | self.is_multicast = is_multicast |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 15 | self.is_l2 = is_l2 |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 16 | self.encoded_paths = [] |
| 17 | for path in self.t_paths: |
| 18 | self.encoded_paths.append(path.encode()) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 19 | |
| 20 | def add_vpp_config(self): |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 21 | reply = self.test.vapi.mpls_tunnel_add_del( |
| 22 | 0xffffffff, |
| 23 | self.encoded_paths, |
| 24 | is_multicast=self.is_multicast, |
| 25 | l2_only=self.is_l2) |
| 26 | self.set_sw_if_index(reply.sw_if_index) |
| 27 | self.tunnel_index = reply.tunnel_index |
Neale Ranns | 6a30b5f | 2018-09-25 07:22:36 -0700 | [diff] [blame] | 28 | self._test.registry.register(self, self._test.logger) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 29 | |
| 30 | def remove_vpp_config(self): |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 31 | reply = self.test.vapi.mpls_tunnel_add_del( |
| 32 | self.sw_if_index, |
| 33 | self.encoded_paths, |
| 34 | is_add=0) |
Neale Ranns | 6a30b5f | 2018-09-25 07:22:36 -0700 | [diff] [blame] | 35 | |
| 36 | def query_vpp_config(self): |
| 37 | dump = self._test.vapi.mpls_tunnel_dump() |
| 38 | for t in dump: |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 39 | if self.sw_if_index == t.mt_tunnel.mt_sw_if_index and \ |
| 40 | self.tunnel_index == t.mt_tunnel.mt_tunnel_index: |
Neale Ranns | 6a30b5f | 2018-09-25 07:22:36 -0700 | [diff] [blame] | 41 | return True |
| 42 | return False |
| 43 | |
Neale Ranns | 6a30b5f | 2018-09-25 07:22:36 -0700 | [diff] [blame] | 44 | def object_id(self): |
Neale Ranns | f5fa5ae | 2018-09-26 05:07:25 -0700 | [diff] [blame] | 45 | return ("mpls-tunnel%d-%d" % (self.tunnel_index, |
| 46 | self.sw_if_index)) |