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