blob: 2826c29c6b397d84cdcd67fd17d00e97c685aa3e [file] [log] [blame]
Artem Glazychevea962922021-05-28 19:09:14 +07001from vpp_interface import VppInterface
2from vpp_papi import VppEnum
3
4
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02005INDEX_INVALID = 0xFFFFFFFF
Artem Glazychevea962922021-05-28 19:09:14 +07006DEFAULT_PORT = 4790
7UNDEFINED_PORT = 0
8
9
10def find_vxlan_gpe_tunnel(test, src, dst, s_port, d_port, vni):
11 ts = test.vapi.vxlan_gpe_tunnel_v2_dump(INDEX_INVALID)
12
13 src_port = DEFAULT_PORT
14 if s_port != UNDEFINED_PORT:
15 src_port = s_port
16
17 dst_port = DEFAULT_PORT
18 if d_port != UNDEFINED_PORT:
19 dst_port = d_port
20
21 for t in ts:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020022 if (
23 src == str(t.local)
24 and dst == str(t.remote)
25 and src_port == t.local_port
26 and dst_port == t.remote_port
27 and t.vni == vni
28 ):
Artem Glazychevea962922021-05-28 19:09:14 +070029 return t.sw_if_index
30 return INDEX_INVALID
31
32
33class VppVxlanGpeTunnel(VppInterface):
34 """
35 VPP VXLAN GPE interface
36 """
37
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020038 def __init__(
39 self,
40 test,
41 src_addr,
42 dst_addr,
43 vni,
44 src_port=UNDEFINED_PORT,
45 dst_port=UNDEFINED_PORT,
46 mcast_sw_if_index=INDEX_INVALID,
47 encap_vrf_id=None,
48 decap_vrf_id=None,
49 protocol=3,
50 ):
51 """Create VXLAN GPE Tunnel interface"""
Artem Glazychevea962922021-05-28 19:09:14 +070052 super(VppVxlanGpeTunnel, self).__init__(test)
53 self.src = src_addr
54 self.dst = dst_addr
55 self.vni = vni
56 self.src_port = src_port
57 self.dst_port = dst_port
58 self.mcast_sw_if_index = mcast_sw_if_index
59 self.encap_vrf_id = encap_vrf_id
60 self.decap_vrf_id = decap_vrf_id
61 self.protocol = 3
62
63 def add_vpp_config(self):
64 reply = self.test.vapi.vxlan_gpe_add_del_tunnel_v2(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020065 is_add=1,
66 local=self.src,
67 remote=self.dst,
68 vni=self.vni,
69 local_port=self.src_port,
70 remote_port=self.dst_port,
Artem Glazychevea962922021-05-28 19:09:14 +070071 mcast_sw_if_index=self.mcast_sw_if_index,
72 encap_vrf_id=self.encap_vrf_id,
73 decap_vrf_id=self.decap_vrf_id,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020074 protocol=self.protocol,
75 )
Artem Glazychevea962922021-05-28 19:09:14 +070076 self.set_sw_if_index(reply.sw_if_index)
77 self._test.registry.register(self, self._test.logger)
78
79 def remove_vpp_config(self):
80 self.test.vapi.vxlan_gpe_add_del_tunnel_v2(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020081 is_add=0,
82 local=self.src,
83 remote=self.dst,
84 vni=self.vni,
85 local_port=self.src_port,
86 remote_port=self.dst_port,
Artem Glazychevea962922021-05-28 19:09:14 +070087 mcast_sw_if_index=self.mcast_sw_if_index,
88 encap_vrf_id=self.encap_vrf_id,
89 decap_vrf_id=self.decap_vrf_id,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020090 protocol=self.protocol,
91 )
Artem Glazychevea962922021-05-28 19:09:14 +070092
93 def query_vpp_config(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020094 return INDEX_INVALID != find_vxlan_gpe_tunnel(
95 self._test, self.src, self.dst, self.src_port, self.dst_port, self.vni
96 )
Artem Glazychevea962922021-05-28 19:09:14 +070097
98 def object_id(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020099 return "vxlan-%d-%d-%s-%s" % (self.sw_if_index, self.vni, self.src, self.dst)