blob: 0898bd9f8106b579c84d152fd2b7721a21409ce5 [file] [log] [blame]
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001
2from vpp_interface import VppInterface
Neale Ranns4dd4cf42019-03-27 05:06:47 -07003from vpp_papi import VppEnum
Neale Ranns93cc3ee2018-10-10 07:22:51 -07004
5
6INDEX_INVALID = 0xffffffff
7
8
9def find_vxlan_gbp_tunnel(test, src, dst, vni):
Neale Ranns93cc3ee2018-10-10 07:22:51 -070010 ts = test.vapi.vxlan_gbp_tunnel_dump(INDEX_INVALID)
11 for t in ts:
Neale Rannsefd7bc22019-11-11 08:32:34 +000012 if src == str(t.tunnel.src) and \
13 dst == str(t.tunnel.dst) and \
Neale Ranns93cc3ee2018-10-10 07:22:51 -070014 t.tunnel.vni == vni:
15 return t.tunnel.sw_if_index
16 return INDEX_INVALID
17
18
19class VppVxlanGbpTunnel(VppInterface):
20 """
21 VPP VXLAN GBP interface
22 """
23
Paul Vinciguerra1b534f52019-06-15 20:31:31 -040024 def __init__(self, test, src, dst, vni, mcast_itf=None, mode=None,
25 is_ipv6=None, encap_table_id=None, instance=0xffffffff):
Neale Ranns93cc3ee2018-10-10 07:22:51 -070026 """ Create VXLAN-GBP Tunnel interface """
27 super(VppVxlanGbpTunnel, self).__init__(test)
Neale Rannsefd7bc22019-11-11 08:32:34 +000028 self.src = src
29 self.dst = dst
Neale Ranns93cc3ee2018-10-10 07:22:51 -070030 self.vni = vni
31 self.mcast_itf = mcast_itf
Paul Vinciguerra1b534f52019-06-15 20:31:31 -040032 self.ipv6 = is_ipv6
33 self.encap_table_id = encap_table_id
34 self.instance = instance
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
Paul Vinciguerradc22c832021-04-25 21:50:38 -040041 def encode(self):
42 return {
43 'src': self.src,
44 'dst': self.dst,
45 'mode': self.mode,
46 'vni': self.vni,
47 'mcast_sw_if_index': self.mcast_itf.sw_if_index
48 if self.mcast_itf else INDEX_INVALID,
49 'encap_table_id': self.encap_table_id,
50 'instance': self.instance,
51 }
52
Neale Ranns93cc3ee2018-10-10 07:22:51 -070053 def add_vpp_config(self):
Neale Ranns93cc3ee2018-10-10 07:22:51 -070054 reply = self.test.vapi.vxlan_gbp_tunnel_add_del(
Paul Vinciguerra1b534f52019-06-15 20:31:31 -040055 is_add=1,
Paul Vinciguerradc22c832021-04-25 21:50:38 -040056 tunnel=self.encode(),
57 )
Neale Ranns93cc3ee2018-10-10 07:22:51 -070058 self.set_sw_if_index(reply.sw_if_index)
59 self._test.registry.register(self, self._test.logger)
60
61 def remove_vpp_config(self):
Neale Ranns93cc3ee2018-10-10 07:22:51 -070062 self.test.vapi.vxlan_gbp_tunnel_add_del(
Neale Ranns93cc3ee2018-10-10 07:22:51 -070063 is_add=0,
Paul Vinciguerradc22c832021-04-25 21:50:38 -040064 tunnel=self.encode(),
65 )
Neale Ranns93cc3ee2018-10-10 07:22:51 -070066
67 def query_vpp_config(self):
68 return (INDEX_INVALID != find_vxlan_gbp_tunnel(self._test,
Ole Troan8c8acc02018-11-27 10:05:23 +010069 self.src,
70 self.dst,
Neale Ranns93cc3ee2018-10-10 07:22:51 -070071 self.vni))
72
Neale Ranns93cc3ee2018-10-10 07:22:51 -070073 def object_id(self):
74 return "vxlan-gbp-%d-%d-%s-%s" % (self.sw_if_index, self.vni,
75 self.src, self.dst)