3cbf856dfc501b28519b369f2f72d71c7a12a46a
[vpp.git] / test / vpp_mpls_tunnel_interface.py
1
2 from vpp_interface import VppInterface
3
4
5 class VppMPLSTunnelInterface(VppInterface):
6     """
7     VPP MPLS Tunnel interface
8     """
9
10     def __init__(self, test, paths, is_multicast=0, is_l2=0):
11         """ Create MPLS Tunnel interface """
12         super(VppMPLSTunnelInterface, self).__init__(test)
13         self.t_paths = paths
14         self.is_multicast = is_multicast
15         self.is_l2 = is_l2
16
17     def add_vpp_config(self):
18         sw_if_index = 0xffffffff
19         for path in self.t_paths:
20             lstack = path.encode_labels()
21
22             reply = self.test.vapi.mpls_tunnel_add_del(
23                 sw_if_index,
24                 1,  # IPv4 next-hop
25                 path.nh_addr,
26                 path.nh_itf,
27                 path.nh_table_id,
28                 path.weight,
29                 next_hop_via_label=path.nh_via_label,
30                 next_hop_out_label_stack=lstack,
31                 next_hop_n_out_labels=len(lstack),
32                 is_multicast=self.is_multicast,
33                 l2_only=self.is_l2)
34             sw_if_index = reply.sw_if_index
35         self.set_sw_if_index(sw_if_index)
36         self._test.registry.register(self, self._test.logger)
37
38     def remove_vpp_config(self):
39         for path in self.t_paths:
40             lstack = path.encode_labels()
41
42             self.test.vapi.mpls_tunnel_add_del(
43                 self.sw_if_index,
44                 1,  # IPv4 next-hop
45                 path.nh_addr,
46                 path.nh_itf,
47                 path.nh_table_id,
48                 path.weight,
49                 next_hop_via_label=path.nh_via_label,
50                 next_hop_out_label_stack=lstack,
51                 next_hop_n_out_labels=len(lstack),
52                 is_add=0)
53
54     def query_vpp_config(self):
55         dump = self._test.vapi.mpls_tunnel_dump()
56         for t in dump:
57             if self.sw_if_index == t.mt_sw_if_index:
58                 return True
59         return False
60
61     def __str__(self):
62         return self.object_id()
63
64     def object_id(self):
65         return ("mpls-tunnel%d" % self.sw_if_index)