blob: 47817ed168f5b52329331d354009aa0555686ecc [file] [log] [blame]
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001
2from vpp_interface import VppInterface
3from vpp_ip import VppIpAddress
Neale Ranns4dd4cf42019-03-27 05:06:47 -07004from vpp_papi import VppEnum
Neale Ranns93cc3ee2018-10-10 07:22:51 -07005
6
7INDEX_INVALID = 0xffffffff
8
9
10def find_vxlan_gbp_tunnel(test, src, dst, vni):
11 vsrc = VppIpAddress(src)
12 vdst = VppIpAddress(dst)
13
14 ts = test.vapi.vxlan_gbp_tunnel_dump(INDEX_INVALID)
15 for t in ts:
16 if vsrc == t.tunnel.src and \
17 vdst == t.tunnel.dst and \
18 t.tunnel.vni == vni:
19 return t.tunnel.sw_if_index
20 return INDEX_INVALID
21
22
23class VppVxlanGbpTunnel(VppInterface):
24 """
25 VPP VXLAN GBP interface
26 """
27
Neale Ranns4dd4cf42019-03-27 05:06:47 -070028 def __init__(self, test, src, dst, vni, mcast_itf=None, mode=None):
Neale Ranns93cc3ee2018-10-10 07:22:51 -070029 """ Create VXLAN-GBP Tunnel interface """
30 super(VppVxlanGbpTunnel, self).__init__(test)
31 self.src = VppIpAddress(src)
32 self.dst = VppIpAddress(dst)
33 self.vni = vni
34 self.mcast_itf = mcast_itf
Neale Ranns4dd4cf42019-03-27 05:06:47 -070035 if not mode:
36 self.mode = (VppEnum.vl_api_vxlan_gbp_api_tunnel_mode_t.
37 VXLAN_GBP_API_TUNNEL_MODE_L2)
38 else:
39 self.mode = mode
Neale Ranns93cc3ee2018-10-10 07:22:51 -070040
41 def add_vpp_config(self):
42 mcast_sw_if_index = INDEX_INVALID
43 if (self.mcast_itf):
44 mcast_sw_if_index = self.mcast_itf.sw_if_index
45 reply = self.test.vapi.vxlan_gbp_tunnel_add_del(
46 self.src.encode(),
47 self.dst.encode(),
Neale Ranns4dd4cf42019-03-27 05:06:47 -070048 mode=self.mode,
Neale Ranns93cc3ee2018-10-10 07:22:51 -070049 vni=self.vni,
50 mcast_sw_if_index=mcast_sw_if_index)
51 self.set_sw_if_index(reply.sw_if_index)
52 self._test.registry.register(self, self._test.logger)
53
54 def remove_vpp_config(self):
55 mcast_sw_if_index = INDEX_INVALID
56 if (self.mcast_itf):
57 mcast_sw_if_index = self.mcast_itf.sw_if_index
58 self.test.vapi.vxlan_gbp_tunnel_add_del(
59 self.src.encode(),
60 self.dst.encode(),
61 vni=self.vni,
62 is_add=0,
63 mcast_sw_if_index=mcast_sw_if_index)
64
65 def query_vpp_config(self):
66 return (INDEX_INVALID != find_vxlan_gbp_tunnel(self._test,
Ole Troan8c8acc02018-11-27 10:05:23 +010067 self.src,
68 self.dst,
Neale Ranns93cc3ee2018-10-10 07:22:51 -070069 self.vni))
70
Neale Ranns93cc3ee2018-10-10 07:22:51 -070071 def object_id(self):
72 return "vxlan-gbp-%d-%d-%s-%s" % (self.sw_if_index, self.vni,
73 self.src, self.dst)