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 | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 16 | |
| 17 | def add_vpp_config(self): |
Klement Sekera | ff4ba35 | 2018-05-30 10:32:21 +0200 | [diff] [blame] | 18 | sw_if_index = 0xffffffff |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 19 | for path in self.t_paths: |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 20 | lstack = path.encode_labels() |
| 21 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 22 | reply = self.test.vapi.mpls_tunnel_add_del( |
Klement Sekera | ff4ba35 | 2018-05-30 10:32:21 +0200 | [diff] [blame] | 23 | sw_if_index, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 24 | 1, # IPv4 next-hop |
| 25 | path.nh_addr, |
| 26 | path.nh_itf, |
| 27 | path.nh_table_id, |
| 28 | path.weight, |
Neale Ranns | 7c922dc | 2018-08-30 06:12:27 -0700 | [diff] [blame] | 29 | next_hop_via_label=path.nh_via_label, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 30 | next_hop_out_label_stack=lstack, |
| 31 | next_hop_n_out_labels=len(lstack), |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 32 | is_multicast=self.is_multicast, |
| 33 | l2_only=self.is_l2) |
Klement Sekera | ff4ba35 | 2018-05-30 10:32:21 +0200 | [diff] [blame] | 34 | sw_if_index = reply.sw_if_index |
Neale Ranns | f5fa5ae | 2018-09-26 05:07:25 -0700 | [diff] [blame] | 35 | self.tunnel_index = reply.tunnel_index |
Klement Sekera | b9ef273 | 2018-06-24 22:49:33 +0200 | [diff] [blame] | 36 | self.set_sw_if_index(sw_if_index) |
Neale Ranns | 6a30b5f | 2018-09-25 07:22:36 -0700 | [diff] [blame] | 37 | self._test.registry.register(self, self._test.logger) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 38 | |
| 39 | def remove_vpp_config(self): |
| 40 | for path in self.t_paths: |
Neale Ranns | 6a30b5f | 2018-09-25 07:22:36 -0700 | [diff] [blame] | 41 | lstack = path.encode_labels() |
| 42 | |
Klement Sekera | ff4ba35 | 2018-05-30 10:32:21 +0200 | [diff] [blame] | 43 | self.test.vapi.mpls_tunnel_add_del( |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 44 | self.sw_if_index, |
| 45 | 1, # IPv4 next-hop |
| 46 | path.nh_addr, |
| 47 | path.nh_itf, |
| 48 | path.nh_table_id, |
| 49 | path.weight, |
Neale Ranns | 7c922dc | 2018-08-30 06:12:27 -0700 | [diff] [blame] | 50 | next_hop_via_label=path.nh_via_label, |
Neale Ranns | 6a30b5f | 2018-09-25 07:22:36 -0700 | [diff] [blame] | 51 | next_hop_out_label_stack=lstack, |
| 52 | next_hop_n_out_labels=len(lstack), |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 53 | is_add=0) |
Neale Ranns | 6a30b5f | 2018-09-25 07:22:36 -0700 | [diff] [blame] | 54 | |
| 55 | def query_vpp_config(self): |
| 56 | dump = self._test.vapi.mpls_tunnel_dump() |
| 57 | for t in dump: |
Neale Ranns | f5fa5ae | 2018-09-26 05:07:25 -0700 | [diff] [blame] | 58 | if self.sw_if_index == t.mt_sw_if_index and \ |
| 59 | self.tunnel_index == t.mt_tunnel_index: |
Neale Ranns | 6a30b5f | 2018-09-25 07:22:36 -0700 | [diff] [blame] | 60 | return True |
| 61 | return False |
| 62 | |
Neale Ranns | 6a30b5f | 2018-09-25 07:22:36 -0700 | [diff] [blame] | 63 | def object_id(self): |
Neale Ranns | f5fa5ae | 2018-09-26 05:07:25 -0700 | [diff] [blame] | 64 | return ("mpls-tunnel%d-%d" % (self.tunnel_index, |
| 65 | self.sw_if_index)) |