blob: dce5ab86c078eb8b7e3efd50855caa566d97a9b2 [file] [log] [blame]
Jakub Grajciar7c0eb562020-03-02 13:55:31 +01001from vpp_interface import VppInterface
2from vpp_papi import VppEnum
3
4
5INDEX_INVALID = 0xffffffff
Artem Glazychev839dcc02020-12-01 02:39:21 +07006DEFAULT_PORT = 4789
7UNDEFINED_PORT = 0
Jakub Grajciar7c0eb562020-03-02 13:55:31 +01008
9
Artem Glazychev839dcc02020-12-01 02:39:21 +070010def find_vxlan_tunnel(test, src, dst, s_port, d_port, vni):
11 ts = test.vapi.vxlan_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
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010021 for t in ts:
22 if src == str(t.src_address) and \
23 dst == str(t.dst_address) and \
Artem Glazychev839dcc02020-12-01 02:39:21 +070024 src_port == t.src_port and \
25 dst_port == t.dst_port and \
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010026 t.vni == vni:
27 return t.sw_if_index
28 return INDEX_INVALID
29
30
31class VppVxlanTunnel(VppInterface):
32 """
33 VPP VXLAN interface
34 """
35
Artem Glazychev839dcc02020-12-01 02:39:21 +070036 def __init__(self, test, src, dst, vni,
37 src_port=UNDEFINED_PORT, dst_port=UNDEFINED_PORT,
38 mcast_itf=None,
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010039 mcast_sw_if_index=INDEX_INVALID,
40 decap_next_index=INDEX_INVALID,
41 encap_vrf_id=None, instance=0xffffffff):
42 """ Create VXLAN Tunnel interface """
43 super(VppVxlanTunnel, self).__init__(test)
44 self.src = src
45 self.dst = dst
46 self.vni = vni
Artem Glazychev839dcc02020-12-01 02:39:21 +070047 self.src_port = src_port
48 self.dst_port = dst_port
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010049 self.mcast_itf = mcast_itf
50 self.mcast_sw_if_index = mcast_sw_if_index
51 self.encap_vrf_id = encap_vrf_id
52 self.decap_next_index = decap_next_index
53 self.instance = instance
54
55 if (self.mcast_itf):
56 self.mcast_sw_if_index = self.mcast_itf.sw_if_index
57
58 def add_vpp_config(self):
Artem Glazychev839dcc02020-12-01 02:39:21 +070059 reply = self.test.vapi.vxlan_add_del_tunnel_v2(
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010060 is_add=1, src_address=self.src, dst_address=self.dst, vni=self.vni,
Artem Glazychev839dcc02020-12-01 02:39:21 +070061 src_port=self.src_port, dst_port=self.dst_port,
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010062 mcast_sw_if_index=self.mcast_sw_if_index,
63 encap_vrf_id=self.encap_vrf_id,
64 instance=self.instance, decap_next_index=self.decap_next_index)
65 self.set_sw_if_index(reply.sw_if_index)
66 self._test.registry.register(self, self._test.logger)
67
68 def remove_vpp_config(self):
Artem Glazychev839dcc02020-12-01 02:39:21 +070069 self.test.vapi.vxlan_add_del_tunnel_v2(
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010070 is_add=0, src_address=self.src, dst_address=self.dst, vni=self.vni,
Artem Glazychev839dcc02020-12-01 02:39:21 +070071 src_port=self.src_port, dst_port=self.dst_port,
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010072 mcast_sw_if_index=self.mcast_sw_if_index,
73 encap_vrf_id=self.encap_vrf_id, instance=self.instance,
74 decap_next_index=self.decap_next_index)
75
76 def query_vpp_config(self):
77 return (INDEX_INVALID != find_vxlan_tunnel(self._test,
78 self.src,
79 self.dst,
Artem Glazychev839dcc02020-12-01 02:39:21 +070080 self.src_port,
81 self.dst_port,
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010082 self.vni))
83
84 def object_id(self):
85 return "vxlan-%d-%d-%s-%s" % (self.sw_if_index, self.vni,
86 self.src, self.dst)