Artem Glazychev | ea96292 | 2021-05-28 19:09:14 +0700 | [diff] [blame] | 1 | from vpp_interface import VppInterface |
| 2 | from vpp_papi import VppEnum |
| 3 | |
| 4 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame^] | 5 | INDEX_INVALID = 0xFFFFFFFF |
Artem Glazychev | ea96292 | 2021-05-28 19:09:14 +0700 | [diff] [blame] | 6 | DEFAULT_PORT = 4790 |
| 7 | UNDEFINED_PORT = 0 |
| 8 | |
| 9 | |
| 10 | def find_vxlan_gpe_tunnel(test, src, dst, s_port, d_port, vni): |
| 11 | ts = test.vapi.vxlan_gpe_tunnel_v2_dump(INDEX_INVALID) |
| 12 | |
| 13 | src_port = DEFAULT_PORT |
| 14 | if s_port != UNDEFINED_PORT: |
| 15 | src_port = s_port |
| 16 | |
| 17 | dst_port = DEFAULT_PORT |
| 18 | if d_port != UNDEFINED_PORT: |
| 19 | dst_port = d_port |
| 20 | |
| 21 | for t in ts: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame^] | 22 | if ( |
| 23 | src == str(t.local) |
| 24 | and dst == str(t.remote) |
| 25 | and src_port == t.local_port |
| 26 | and dst_port == t.remote_port |
| 27 | and t.vni == vni |
| 28 | ): |
Artem Glazychev | ea96292 | 2021-05-28 19:09:14 +0700 | [diff] [blame] | 29 | return t.sw_if_index |
| 30 | return INDEX_INVALID |
| 31 | |
| 32 | |
| 33 | class VppVxlanGpeTunnel(VppInterface): |
| 34 | """ |
| 35 | VPP VXLAN GPE interface |
| 36 | """ |
| 37 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame^] | 38 | def __init__( |
| 39 | self, |
| 40 | test, |
| 41 | src_addr, |
| 42 | dst_addr, |
| 43 | vni, |
| 44 | src_port=UNDEFINED_PORT, |
| 45 | dst_port=UNDEFINED_PORT, |
| 46 | mcast_sw_if_index=INDEX_INVALID, |
| 47 | encap_vrf_id=None, |
| 48 | decap_vrf_id=None, |
| 49 | protocol=3, |
| 50 | ): |
| 51 | """Create VXLAN GPE Tunnel interface""" |
Artem Glazychev | ea96292 | 2021-05-28 19:09:14 +0700 | [diff] [blame] | 52 | super(VppVxlanGpeTunnel, self).__init__(test) |
| 53 | self.src = src_addr |
| 54 | self.dst = dst_addr |
| 55 | self.vni = vni |
| 56 | self.src_port = src_port |
| 57 | self.dst_port = dst_port |
| 58 | self.mcast_sw_if_index = mcast_sw_if_index |
| 59 | self.encap_vrf_id = encap_vrf_id |
| 60 | self.decap_vrf_id = decap_vrf_id |
| 61 | self.protocol = 3 |
| 62 | |
| 63 | def add_vpp_config(self): |
| 64 | reply = self.test.vapi.vxlan_gpe_add_del_tunnel_v2( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame^] | 65 | is_add=1, |
| 66 | local=self.src, |
| 67 | remote=self.dst, |
| 68 | vni=self.vni, |
| 69 | local_port=self.src_port, |
| 70 | remote_port=self.dst_port, |
Artem Glazychev | ea96292 | 2021-05-28 19:09:14 +0700 | [diff] [blame] | 71 | mcast_sw_if_index=self.mcast_sw_if_index, |
| 72 | encap_vrf_id=self.encap_vrf_id, |
| 73 | decap_vrf_id=self.decap_vrf_id, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame^] | 74 | protocol=self.protocol, |
| 75 | ) |
Artem Glazychev | ea96292 | 2021-05-28 19:09:14 +0700 | [diff] [blame] | 76 | self.set_sw_if_index(reply.sw_if_index) |
| 77 | self._test.registry.register(self, self._test.logger) |
| 78 | |
| 79 | def remove_vpp_config(self): |
| 80 | self.test.vapi.vxlan_gpe_add_del_tunnel_v2( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame^] | 81 | is_add=0, |
| 82 | local=self.src, |
| 83 | remote=self.dst, |
| 84 | vni=self.vni, |
| 85 | local_port=self.src_port, |
| 86 | remote_port=self.dst_port, |
Artem Glazychev | ea96292 | 2021-05-28 19:09:14 +0700 | [diff] [blame] | 87 | mcast_sw_if_index=self.mcast_sw_if_index, |
| 88 | encap_vrf_id=self.encap_vrf_id, |
| 89 | decap_vrf_id=self.decap_vrf_id, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame^] | 90 | protocol=self.protocol, |
| 91 | ) |
Artem Glazychev | ea96292 | 2021-05-28 19:09:14 +0700 | [diff] [blame] | 92 | |
| 93 | def query_vpp_config(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame^] | 94 | return INDEX_INVALID != find_vxlan_gpe_tunnel( |
| 95 | self._test, self.src, self.dst, self.src_port, self.dst_port, self.vni |
| 96 | ) |
Artem Glazychev | ea96292 | 2021-05-28 19:09:14 +0700 | [diff] [blame] | 97 | |
| 98 | def object_id(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame^] | 99 | return "vxlan-%d-%d-%s-%s" % (self.sw_if_index, self.vni, self.src, self.dst) |