blob: 22555858d1270729cbc2819d5e1425c4c854c519 [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
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(
Paul Vinciguerra1b534f52019-06-15 20:31:31 -040046 is_add=1,
47 tunnel={
Neale Rannsefd7bc22019-11-11 08:32:34 +000048 'src': self.src,
49 'dst': self.dst,
Paul Vinciguerra1b534f52019-06-15 20:31:31 -040050 'mode': self.mode,
51 'vni': self.vni,
52 'mcast_sw_if_index': mcast_sw_if_index,
53 'encap_table_id': self.encap_table_id,
54 'instance': self.instance
55 })
Neale Ranns93cc3ee2018-10-10 07:22:51 -070056 self.set_sw_if_index(reply.sw_if_index)
57 self._test.registry.register(self, self._test.logger)
58
59 def remove_vpp_config(self):
60 mcast_sw_if_index = INDEX_INVALID
61 if (self.mcast_itf):
62 mcast_sw_if_index = self.mcast_itf.sw_if_index
63 self.test.vapi.vxlan_gbp_tunnel_add_del(
Neale Ranns93cc3ee2018-10-10 07:22:51 -070064 is_add=0,
Paul Vinciguerra1b534f52019-06-15 20:31:31 -040065 tunnel={
Neale Rannsefd7bc22019-11-11 08:32:34 +000066 'src': self.src,
67 'dst': self.dst,
Paul Vinciguerra1b534f52019-06-15 20:31:31 -040068 'mode': self.mode,
69 'vni': self.vni,
70 'mcast_sw_if_index': mcast_sw_if_index,
71 'encap_table_id': self.encap_table_id,
72 'instance': self.instance,
73 })
Neale Ranns93cc3ee2018-10-10 07:22:51 -070074
75 def query_vpp_config(self):
76 return (INDEX_INVALID != find_vxlan_gbp_tunnel(self._test,
Ole Troan8c8acc02018-11-27 10:05:23 +010077 self.src,
78 self.dst,
Neale Ranns93cc3ee2018-10-10 07:22:51 -070079 self.vni))
80
Neale Ranns93cc3ee2018-10-10 07:22:51 -070081 def object_id(self):
82 return "vxlan-gbp-%d-%d-%s-%s" % (self.sw_if_index, self.vni,
83 self.src, self.dst)