Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1 | |
| 2 | from vpp_interface import VppInterface |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 3 | from vpp_papi import VppEnum |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 4 | |
| 5 | |
| 6 | INDEX_INVALID = 0xffffffff |
| 7 | |
| 8 | |
| 9 | def find_vxlan_gbp_tunnel(test, src, dst, vni): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 10 | ts = test.vapi.vxlan_gbp_tunnel_dump(INDEX_INVALID) |
| 11 | for t in ts: |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 12 | if src == str(t.tunnel.src) and \ |
| 13 | dst == str(t.tunnel.dst) and \ |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 14 | t.tunnel.vni == vni: |
| 15 | return t.tunnel.sw_if_index |
| 16 | return INDEX_INVALID |
| 17 | |
| 18 | |
| 19 | class VppVxlanGbpTunnel(VppInterface): |
| 20 | """ |
| 21 | VPP VXLAN GBP interface |
| 22 | """ |
| 23 | |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 24 | def __init__(self, test, src, dst, vni, mcast_itf=None, mode=None, |
| 25 | is_ipv6=None, encap_table_id=None, instance=0xffffffff): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 26 | """ Create VXLAN-GBP Tunnel interface """ |
| 27 | super(VppVxlanGbpTunnel, self).__init__(test) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 28 | self.src = src |
| 29 | self.dst = dst |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 30 | self.vni = vni |
| 31 | self.mcast_itf = mcast_itf |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 32 | self.ipv6 = is_ipv6 |
| 33 | self.encap_table_id = encap_table_id |
| 34 | self.instance = instance |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 35 | 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 Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 40 | |
| 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 Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 46 | is_add=1, |
| 47 | tunnel={ |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 48 | 'src': self.src, |
| 49 | 'dst': self.dst, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 50 | '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 Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 56 | 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 Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 64 | is_add=0, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 65 | tunnel={ |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 66 | 'src': self.src, |
| 67 | 'dst': self.dst, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 68 | '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 Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 74 | |
| 75 | def query_vpp_config(self): |
| 76 | return (INDEX_INVALID != find_vxlan_gbp_tunnel(self._test, |
Ole Troan | 8c8acc0 | 2018-11-27 10:05:23 +0100 | [diff] [blame] | 77 | self.src, |
| 78 | self.dst, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 79 | self.vni)) |
| 80 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 81 | def object_id(self): |
| 82 | return "vxlan-gbp-%d-%d-%s-%s" % (self.sw_if_index, self.vni, |
| 83 | self.src, self.dst) |