2018-10-10 07:22:51 -07:00
|
|
|
|
|
|
|
from vpp_interface import VppInterface
|
|
|
|
from vpp_ip import VppIpAddress
|
2019-03-27 05:06:47 -07:00
|
|
|
from vpp_papi import VppEnum
|
2018-10-10 07:22:51 -07:00
|
|
|
|
|
|
|
|
|
|
|
INDEX_INVALID = 0xffffffff
|
|
|
|
|
|
|
|
|
|
|
|
def find_vxlan_gbp_tunnel(test, src, dst, vni):
|
|
|
|
vsrc = VppIpAddress(src)
|
|
|
|
vdst = VppIpAddress(dst)
|
|
|
|
|
|
|
|
ts = test.vapi.vxlan_gbp_tunnel_dump(INDEX_INVALID)
|
|
|
|
for t in ts:
|
|
|
|
if vsrc == t.tunnel.src and \
|
|
|
|
vdst == t.tunnel.dst and \
|
|
|
|
t.tunnel.vni == vni:
|
|
|
|
return t.tunnel.sw_if_index
|
|
|
|
return INDEX_INVALID
|
|
|
|
|
|
|
|
|
|
|
|
class VppVxlanGbpTunnel(VppInterface):
|
|
|
|
"""
|
|
|
|
VPP VXLAN GBP interface
|
|
|
|
"""
|
|
|
|
|
2019-06-15 20:31:31 -04:00
|
|
|
def __init__(self, test, src, dst, vni, mcast_itf=None, mode=None,
|
|
|
|
is_ipv6=None, encap_table_id=None, instance=0xffffffff):
|
2018-10-10 07:22:51 -07:00
|
|
|
""" Create VXLAN-GBP Tunnel interface """
|
|
|
|
super(VppVxlanGbpTunnel, self).__init__(test)
|
|
|
|
self.src = VppIpAddress(src)
|
|
|
|
self.dst = VppIpAddress(dst)
|
|
|
|
self.vni = vni
|
|
|
|
self.mcast_itf = mcast_itf
|
2019-06-15 20:31:31 -04:00
|
|
|
self.ipv6 = is_ipv6
|
|
|
|
self.encap_table_id = encap_table_id
|
|
|
|
self.instance = instance
|
2019-03-27 05:06:47 -07:00
|
|
|
if not mode:
|
|
|
|
self.mode = (VppEnum.vl_api_vxlan_gbp_api_tunnel_mode_t.
|
|
|
|
VXLAN_GBP_API_TUNNEL_MODE_L2)
|
|
|
|
else:
|
|
|
|
self.mode = mode
|
2018-10-10 07:22:51 -07:00
|
|
|
|
|
|
|
def add_vpp_config(self):
|
|
|
|
mcast_sw_if_index = INDEX_INVALID
|
|
|
|
if (self.mcast_itf):
|
|
|
|
mcast_sw_if_index = self.mcast_itf.sw_if_index
|
|
|
|
reply = self.test.vapi.vxlan_gbp_tunnel_add_del(
|
2019-06-15 20:31:31 -04:00
|
|
|
is_add=1,
|
|
|
|
tunnel={
|
|
|
|
'src': self.src.encode(),
|
|
|
|
'dst': self.dst.encode(),
|
|
|
|
'mode': self.mode,
|
|
|
|
'vni': self.vni,
|
|
|
|
'mcast_sw_if_index': mcast_sw_if_index,
|
|
|
|
'encap_table_id': self.encap_table_id,
|
|
|
|
'instance': self.instance
|
|
|
|
})
|
2018-10-10 07:22:51 -07:00
|
|
|
self.set_sw_if_index(reply.sw_if_index)
|
|
|
|
self._test.registry.register(self, self._test.logger)
|
|
|
|
|
|
|
|
def remove_vpp_config(self):
|
|
|
|
mcast_sw_if_index = INDEX_INVALID
|
|
|
|
if (self.mcast_itf):
|
|
|
|
mcast_sw_if_index = self.mcast_itf.sw_if_index
|
|
|
|
self.test.vapi.vxlan_gbp_tunnel_add_del(
|
|
|
|
is_add=0,
|
2019-06-15 20:31:31 -04:00
|
|
|
tunnel={
|
|
|
|
'src': self.src.encode(),
|
|
|
|
'dst': self.dst.encode(),
|
|
|
|
'mode': self.mode,
|
|
|
|
'vni': self.vni,
|
|
|
|
'mcast_sw_if_index': mcast_sw_if_index,
|
|
|
|
'encap_table_id': self.encap_table_id,
|
|
|
|
'instance': self.instance,
|
|
|
|
})
|
2018-10-10 07:22:51 -07:00
|
|
|
|
|
|
|
def query_vpp_config(self):
|
|
|
|
return (INDEX_INVALID != find_vxlan_gbp_tunnel(self._test,
|
2018-11-27 10:05:23 +01:00
|
|
|
self.src,
|
|
|
|
self.dst,
|
2018-10-10 07:22:51 -07:00
|
|
|
self.vni))
|
|
|
|
|
|
|
|
def object_id(self):
|
|
|
|
return "vxlan-gbp-%d-%d-%s-%s" % (self.sw_if_index, self.vni,
|
|
|
|
self.src, self.dst)
|