MPLS Unifom mode
[vpp.git] / test / vpp_mpls_tunnel_interface.py
1
2 from vpp_interface import VppInterface
3 from vpp_ip_route import VppRoutePath, VppMplsLabel
4 import socket
5
6
7 class VppMPLSTunnelInterface(VppInterface):
8     """
9     VPP MPLS Tunnel interface
10     """
11
12     def __init__(self, test, paths, is_multicast=0, is_l2=0):
13         """ Create MPLS Tunnel interface """
14         self._sw_if_index = 0
15         super(VppMPLSTunnelInterface, self).__init__(test)
16         self._test = test
17         self.t_paths = paths
18         self.is_multicast = is_multicast
19         self.is_l2 = is_l2
20
21     def add_vpp_config(self):
22         self._sw_if_index = 0xffffffff
23         for path in self.t_paths:
24             lstack = path.encode_labels()
25
26             reply = self.test.vapi.mpls_tunnel_add_del(
27                 self._sw_if_index,
28                 1,  # IPv4 next-hop
29                 path.nh_addr,
30                 path.nh_itf,
31                 path.nh_table_id,
32                 path.weight,
33                 next_hop_out_label_stack=lstack,
34                 next_hop_n_out_labels=len(lstack),
35                 is_multicast=self.is_multicast,
36                 l2_only=self.is_l2)
37             self._sw_if_index = reply.sw_if_index
38
39     def remove_vpp_config(self):
40         for path in self.t_paths:
41             reply = self.test.vapi.mpls_tunnel_add_del(
42                 self.sw_if_index,
43                 1,  # IPv4 next-hop
44                 path.nh_addr,
45                 path.nh_itf,
46                 path.nh_table_id,
47                 path.weight,
48                 next_hop_out_label_stack=path.nh_labels,
49                 next_hop_n_out_labels=len(path.nh_labels),
50                 is_add=0)