blob: 5352d6ebf31912d9bfdfb25ce139e11414b65aa0 [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
Paul Vinciguerra1b534f52019-06-15 20:31:31 -040028 def __init__(self, test, src, dst, vni, mcast_itf=None, mode=None,
29 is_ipv6=None, encap_table_id=None, instance=0xffffffff):
Neale Ranns93cc3ee2018-10-10 07:22:51 -070030 """ Create VXLAN-GBP Tunnel interface """
31 super(VppVxlanGbpTunnel, self).__init__(test)
32 self.src = VppIpAddress(src)
33 self.dst = VppIpAddress(dst)
34 self.vni = vni
35 self.mcast_itf = mcast_itf
Paul Vinciguerra1b534f52019-06-15 20:31:31 -040036 self.ipv6 = is_ipv6
37 self.encap_table_id = encap_table_id
38 self.instance = instance
Neale Ranns4dd4cf42019-03-27 05:06:47 -070039 if not mode:
40 self.mode = (VppEnum.vl_api_vxlan_gbp_api_tunnel_mode_t.
41 VXLAN_GBP_API_TUNNEL_MODE_L2)
42 else:
43 self.mode = mode
Neale Ranns93cc3ee2018-10-10 07:22:51 -070044
45 def add_vpp_config(self):
46 mcast_sw_if_index = INDEX_INVALID
47 if (self.mcast_itf):
48 mcast_sw_if_index = self.mcast_itf.sw_if_index
49 reply = self.test.vapi.vxlan_gbp_tunnel_add_del(
Paul Vinciguerra1b534f52019-06-15 20:31:31 -040050 is_add=1,
51 tunnel={
52 'src': self.src.encode(),
53 'dst': self.dst.encode(),
54 'mode': self.mode,
55 'vni': self.vni,
56 'mcast_sw_if_index': mcast_sw_if_index,
57 'encap_table_id': self.encap_table_id,
58 'instance': self.instance
59 })
Neale Ranns93cc3ee2018-10-10 07:22:51 -070060 self.set_sw_if_index(reply.sw_if_index)
61 self._test.registry.register(self, self._test.logger)
62
63 def remove_vpp_config(self):
64 mcast_sw_if_index = INDEX_INVALID
65 if (self.mcast_itf):
66 mcast_sw_if_index = self.mcast_itf.sw_if_index
67 self.test.vapi.vxlan_gbp_tunnel_add_del(
Neale Ranns93cc3ee2018-10-10 07:22:51 -070068 is_add=0,
Paul Vinciguerra1b534f52019-06-15 20:31:31 -040069 tunnel={
70 'src': self.src.encode(),
71 'dst': self.dst.encode(),
72 'mode': self.mode,
73 'vni': self.vni,
74 'mcast_sw_if_index': mcast_sw_if_index,
75 'encap_table_id': self.encap_table_id,
76 'instance': self.instance,
77 })
Neale Ranns93cc3ee2018-10-10 07:22:51 -070078
79 def query_vpp_config(self):
80 return (INDEX_INVALID != find_vxlan_gbp_tunnel(self._test,
Ole Troan8c8acc02018-11-27 10:05:23 +010081 self.src,
82 self.dst,
Neale Ranns93cc3ee2018-10-10 07:22:51 -070083 self.vni))
84
Neale Ranns93cc3ee2018-10-10 07:22:51 -070085 def object_id(self):
86 return "vxlan-gbp-%d-%d-%s-%s" % (self.sw_if_index, self.vni,
87 self.src, self.dst)