blob: 8c993b091963250db4cdeda37960579ff92aa31c [file] [log] [blame]
Jakub Grajciar7c0eb562020-03-02 13:55:31 +01001from vpp_interface import VppInterface
2from vpp_papi import VppEnum
3
4
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02005INDEX_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:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020022 if (
23 src == str(t.src_address)
24 and dst == str(t.dst_address)
25 and src_port == t.src_port
26 and dst_port == t.dst_port
27 and t.vni == vni
28 ):
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010029 return t.sw_if_index
30 return INDEX_INVALID
31
32
33class VppVxlanTunnel(VppInterface):
34 """
35 VPP VXLAN interface
36 """
37
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020038 def __init__(
39 self,
40 test,
41 src,
42 dst,
43 vni,
44 src_port=UNDEFINED_PORT,
45 dst_port=UNDEFINED_PORT,
46 mcast_itf=None,
47 mcast_sw_if_index=INDEX_INVALID,
48 decap_next_index=INDEX_INVALID,
49 encap_vrf_id=None,
50 instance=0xFFFFFFFF,
51 is_l3=False,
52 ):
53 """Create VXLAN Tunnel interface"""
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010054 super(VppVxlanTunnel, self).__init__(test)
55 self.src = src
56 self.dst = dst
57 self.vni = vni
Artem Glazychev839dcc02020-12-01 02:39:21 +070058 self.src_port = src_port
59 self.dst_port = dst_port
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010060 self.mcast_itf = mcast_itf
61 self.mcast_sw_if_index = mcast_sw_if_index
62 self.encap_vrf_id = encap_vrf_id
63 self.decap_next_index = decap_next_index
64 self.instance = instance
Nathan Skrzypczak3e384222021-04-21 19:56:34 +020065 self.is_l3 = is_l3
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010066
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020067 if self.mcast_itf:
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010068 self.mcast_sw_if_index = self.mcast_itf.sw_if_index
69
70 def add_vpp_config(self):
Nathan Skrzypczak3e384222021-04-21 19:56:34 +020071 reply = self.test.vapi.vxlan_add_del_tunnel_v3(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020072 is_add=1,
73 src_address=self.src,
74 dst_address=self.dst,
75 vni=self.vni,
76 src_port=self.src_port,
77 dst_port=self.dst_port,
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010078 mcast_sw_if_index=self.mcast_sw_if_index,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020079 encap_vrf_id=self.encap_vrf_id,
80 is_l3=self.is_l3,
81 instance=self.instance,
82 decap_next_index=self.decap_next_index,
83 )
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010084 self.set_sw_if_index(reply.sw_if_index)
85 self._test.registry.register(self, self._test.logger)
86
87 def remove_vpp_config(self):
Artem Glazychev839dcc02020-12-01 02:39:21 +070088 self.test.vapi.vxlan_add_del_tunnel_v2(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020089 is_add=0,
90 src_address=self.src,
91 dst_address=self.dst,
92 vni=self.vni,
93 src_port=self.src_port,
94 dst_port=self.dst_port,
Jakub Grajciar7c0eb562020-03-02 13:55:31 +010095 mcast_sw_if_index=self.mcast_sw_if_index,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020096 encap_vrf_id=self.encap_vrf_id,
97 instance=self.instance,
98 decap_next_index=self.decap_next_index,
99 )
Jakub Grajciar7c0eb562020-03-02 13:55:31 +0100100
101 def query_vpp_config(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200102 return INDEX_INVALID != find_vxlan_tunnel(
103 self._test, self.src, self.dst, self.src_port, self.dst_port, self.vni
104 )
Jakub Grajciar7c0eb562020-03-02 13:55:31 +0100105
106 def object_id(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200107 return "vxlan-%d-%d-%s-%s" % (self.sw_if_index, self.vni, self.src, self.dst)