2020-03-02 13:55:31 +01:00
|
|
|
from vpp_interface import VppInterface
|
|
|
|
from vpp_papi import VppEnum
|
|
|
|
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
INDEX_INVALID = 0xFFFFFFFF
|
2020-12-01 02:39:21 +07:00
|
|
|
DEFAULT_PORT = 4789
|
|
|
|
UNDEFINED_PORT = 0
|
2020-03-02 13:55:31 +01:00
|
|
|
|
|
|
|
|
2020-12-01 02:39:21 +07:00
|
|
|
def find_vxlan_tunnel(test, src, dst, s_port, d_port, vni):
|
|
|
|
ts = test.vapi.vxlan_tunnel_v2_dump(INDEX_INVALID)
|
|
|
|
|
|
|
|
src_port = DEFAULT_PORT
|
|
|
|
if s_port != UNDEFINED_PORT:
|
|
|
|
src_port = s_port
|
|
|
|
|
|
|
|
dst_port = DEFAULT_PORT
|
|
|
|
if d_port != UNDEFINED_PORT:
|
|
|
|
dst_port = d_port
|
|
|
|
|
2020-03-02 13:55:31 +01:00
|
|
|
for t in ts:
|
2022-04-26 19:02:15 +02:00
|
|
|
if (
|
|
|
|
src == str(t.src_address)
|
|
|
|
and dst == str(t.dst_address)
|
|
|
|
and src_port == t.src_port
|
|
|
|
and dst_port == t.dst_port
|
|
|
|
and t.vni == vni
|
|
|
|
):
|
2020-03-02 13:55:31 +01:00
|
|
|
return t.sw_if_index
|
|
|
|
return INDEX_INVALID
|
|
|
|
|
|
|
|
|
|
|
|
class VppVxlanTunnel(VppInterface):
|
|
|
|
"""
|
|
|
|
VPP VXLAN interface
|
|
|
|
"""
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
test,
|
|
|
|
src,
|
|
|
|
dst,
|
|
|
|
vni,
|
|
|
|
src_port=UNDEFINED_PORT,
|
|
|
|
dst_port=UNDEFINED_PORT,
|
|
|
|
mcast_itf=None,
|
|
|
|
mcast_sw_if_index=INDEX_INVALID,
|
|
|
|
decap_next_index=INDEX_INVALID,
|
|
|
|
encap_vrf_id=None,
|
|
|
|
instance=0xFFFFFFFF,
|
|
|
|
is_l3=False,
|
|
|
|
):
|
|
|
|
"""Create VXLAN Tunnel interface"""
|
2020-03-02 13:55:31 +01:00
|
|
|
super(VppVxlanTunnel, self).__init__(test)
|
|
|
|
self.src = src
|
|
|
|
self.dst = dst
|
|
|
|
self.vni = vni
|
2020-12-01 02:39:21 +07:00
|
|
|
self.src_port = src_port
|
|
|
|
self.dst_port = dst_port
|
2020-03-02 13:55:31 +01:00
|
|
|
self.mcast_itf = mcast_itf
|
|
|
|
self.mcast_sw_if_index = mcast_sw_if_index
|
|
|
|
self.encap_vrf_id = encap_vrf_id
|
|
|
|
self.decap_next_index = decap_next_index
|
|
|
|
self.instance = instance
|
2021-04-21 19:56:34 +02:00
|
|
|
self.is_l3 = is_l3
|
2020-03-02 13:55:31 +01:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
if self.mcast_itf:
|
2020-03-02 13:55:31 +01:00
|
|
|
self.mcast_sw_if_index = self.mcast_itf.sw_if_index
|
|
|
|
|
|
|
|
def add_vpp_config(self):
|
2021-04-21 19:56:34 +02:00
|
|
|
reply = self.test.vapi.vxlan_add_del_tunnel_v3(
|
2022-04-26 19:02:15 +02:00
|
|
|
is_add=1,
|
|
|
|
src_address=self.src,
|
|
|
|
dst_address=self.dst,
|
|
|
|
vni=self.vni,
|
|
|
|
src_port=self.src_port,
|
|
|
|
dst_port=self.dst_port,
|
2020-03-02 13:55:31 +01:00
|
|
|
mcast_sw_if_index=self.mcast_sw_if_index,
|
2022-04-26 19:02:15 +02:00
|
|
|
encap_vrf_id=self.encap_vrf_id,
|
|
|
|
is_l3=self.is_l3,
|
|
|
|
instance=self.instance,
|
|
|
|
decap_next_index=self.decap_next_index,
|
|
|
|
)
|
2020-03-02 13:55:31 +01:00
|
|
|
self.set_sw_if_index(reply.sw_if_index)
|
|
|
|
self._test.registry.register(self, self._test.logger)
|
|
|
|
|
|
|
|
def remove_vpp_config(self):
|
2020-12-01 02:39:21 +07:00
|
|
|
self.test.vapi.vxlan_add_del_tunnel_v2(
|
2022-04-26 19:02:15 +02:00
|
|
|
is_add=0,
|
|
|
|
src_address=self.src,
|
|
|
|
dst_address=self.dst,
|
|
|
|
vni=self.vni,
|
|
|
|
src_port=self.src_port,
|
|
|
|
dst_port=self.dst_port,
|
2020-03-02 13:55:31 +01:00
|
|
|
mcast_sw_if_index=self.mcast_sw_if_index,
|
2022-04-26 19:02:15 +02:00
|
|
|
encap_vrf_id=self.encap_vrf_id,
|
|
|
|
instance=self.instance,
|
|
|
|
decap_next_index=self.decap_next_index,
|
|
|
|
)
|
2020-03-02 13:55:31 +01:00
|
|
|
|
|
|
|
def query_vpp_config(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
return INDEX_INVALID != find_vxlan_tunnel(
|
|
|
|
self._test, self.src, self.dst, self.src_port, self.dst_port, self.vni
|
|
|
|
)
|
2020-03-02 13:55:31 +01:00
|
|
|
|
|
|
|
def object_id(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
return "vxlan-%d-%d-%s-%s" % (self.sw_if_index, self.vni, self.src, self.dst)
|