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 | |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 41 | 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 Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 53 | def add_vpp_config(self): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 54 | reply = self.test.vapi.vxlan_gbp_tunnel_add_del( |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 55 | is_add=1, |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 56 | tunnel=self.encode(), |
| 57 | ) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 58 | 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 Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 62 | self.test.vapi.vxlan_gbp_tunnel_add_del( |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 63 | is_add=0, |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 64 | tunnel=self.encode(), |
| 65 | ) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 66 | |
| 67 | def query_vpp_config(self): |
| 68 | return (INDEX_INVALID != find_vxlan_gbp_tunnel(self._test, |
Ole Troan | 8c8acc0 | 2018-11-27 10:05:23 +0100 | [diff] [blame] | 69 | self.src, |
| 70 | self.dst, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 71 | self.vni)) |
| 72 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 73 | def object_id(self): |
| 74 | return "vxlan-gbp-%d-%d-%s-%s" % (self.sw_if_index, self.vni, |
| 75 | self.src, self.dst) |