From 4a67378e86853efd497323c65b4b26f170dcae7a Mon Sep 17 00:00:00 2001 From: pavel-shirshov Date: Thu, 13 Jun 2019 19:45:53 -0700 Subject: [PATCH] Add support of VXLAN tunnel removal (#931) * Add support of vxlan removal --- orchagent/vxlanorch.cpp | 95 +++++++++++++++++++++++++++++++++++++++-- orchagent/vxlanorch.h | 6 +++ 2 files changed, 97 insertions(+), 4 deletions(-) diff --git a/orchagent/vxlanorch.cpp b/orchagent/vxlanorch.cpp index c45c7e83594e..5263a5072777 100644 --- a/orchagent/vxlanorch.cpp +++ b/orchagent/vxlanorch.cpp @@ -106,6 +106,16 @@ create_tunnel_map(MAP_T map_t) return tunnel_map_id; } +void +remove_tunnel_map(sai_object_id_t tunnel_map_id) +{ + sai_status_t status = sai_tunnel_api->remove_tunnel_map(tunnel_map_id); + if (status != SAI_STATUS_SUCCESS) + { + throw std::runtime_error("Can't remove a tunnel map object"); + } +} + static sai_object_id_t create_tunnel_map_entry( MAP_T map_t, sai_object_id_t tunnel_map_id, @@ -269,6 +279,16 @@ create_tunnel( return tunnel_id; } +void +remove_tunnel(sai_object_id_t tunnel_id) +{ + sai_status_t status = sai_tunnel_api->remove_tunnel(tunnel_id); + if (status != SAI_STATUS_SUCCESS) + { + throw std::runtime_error("Can't remove a tunnel object"); + } +} + // Create tunnel termination static sai_object_id_t create_tunnel_termination( @@ -328,6 +348,16 @@ create_tunnel_termination( return term_table_id; } +void +remove_tunnel_termination(sai_object_id_t term_table_id) +{ + sai_status_t status = sai_tunnel_api->remove_tunnel_term_table_entry(term_table_id); + if (status != SAI_STATUS_SUCCESS) + { + throw std::runtime_error("Can't remove a tunnel term table object"); + } +} + bool VxlanTunnel::createTunnel(MAP_T encap, MAP_T decap) { try @@ -368,7 +398,7 @@ bool VxlanTunnel::createTunnel(MAP_T encap, MAP_T decap) return false; } - SWSS_LOG_INFO("Vxlan tunnel '%s' was created", tunnel_name_.c_str()); + SWSS_LOG_NOTICE("Vxlan tunnel '%s' was created", tunnel_name_.c_str()); return true; } @@ -658,7 +688,7 @@ bool VxlanTunnelOrch::addOperation(const Request& request) vxlan_tunnel_table_[tunnel_name] = std::unique_ptr(new VxlanTunnel(tunnel_name, src_ip, dst_ip)); - SWSS_LOG_INFO("Vxlan tunnel '%s' was added", tunnel_name.c_str()); + SWSS_LOG_NOTICE("Vxlan tunnel '%s' was added", tunnel_name.c_str()); return true; } @@ -666,7 +696,39 @@ bool VxlanTunnelOrch::delOperation(const Request& request) { SWSS_LOG_ENTER(); - SWSS_LOG_ERROR("DEL operation is not implemented"); + const auto& tunnel_name = request.getKeyString(0); + + if(!isTunnelExists(tunnel_name)) + { + SWSS_LOG_ERROR("Vxlan tunnel '%s' doesn't exist", tunnel_name.c_str()); + return true; + } + + auto tunnel_term_id = vxlan_tunnel_table_[tunnel_name].get()->getTunnelTermId(); + try + { + remove_tunnel_termination(tunnel_term_id); + } + catch(const std::runtime_error& error) + { + SWSS_LOG_ERROR("Error removing tunnel term entry. Tunnel: %s. Error: %s", tunnel_name.c_str(), error.what()); + return false; + } + + auto tunnel_id = vxlan_tunnel_table_[tunnel_name].get()->getTunnelId(); + try + { + remove_tunnel(tunnel_id); + } + catch(const std::runtime_error& error) + { + SWSS_LOG_ERROR("Error removing tunnel entry. Tunnel: %s. Error: %s", tunnel_name.c_str(), error.what()); + return false; + } + + vxlan_tunnel_table_.erase(tunnel_name); + + SWSS_LOG_NOTICE("Vxlan tunnel '%s' was removed", tunnel_name.c_str()); return true; } @@ -738,7 +800,32 @@ bool VxlanTunnelMapOrch::delOperation(const Request& request) { SWSS_LOG_ENTER(); - SWSS_LOG_ERROR("DEL operation is not implemented"); + const auto& tunnel_name = request.getKeyString(0); + const auto& tunnel_map_entry_name = request.getKeyString(1); + const auto& full_tunnel_map_entry_name = request.getFullKey(); + + + if (!isTunnelMapExists(full_tunnel_map_entry_name)) + { + SWSS_LOG_WARN("Vxlan tunnel map '%s' doesn't exist", full_tunnel_map_entry_name.c_str()); + return true; + } + + auto tunnel_map_entry_id = vxlan_tunnel_map_table_[full_tunnel_map_entry_name]; + try + { + remove_tunnel_map_entry(tunnel_map_entry_id); + } + catch (const std::runtime_error& error) + { + SWSS_LOG_ERROR("Error removing tunnel map %s: %s", full_tunnel_map_entry_name.c_str(), error.what()); + return false; + } + + vxlan_tunnel_map_table_.erase(full_tunnel_map_entry_name); + + SWSS_LOG_NOTICE("Vxlan tunnel map entry '%s' for tunnel '%s' was removed", + tunnel_map_entry_name.c_str(), tunnel_name.c_str()); return true; } diff --git a/orchagent/vxlanorch.h b/orchagent/vxlanorch.h index 7b10315b192a..99387a3d5601 100644 --- a/orchagent/vxlanorch.h +++ b/orchagent/vxlanorch.h @@ -104,6 +104,12 @@ class VxlanTunnel return ids_.tunnel_encap_id; } + sai_object_id_t getTunnelTermId() const + { + return ids_.tunnel_term_id; + } + + void updateNextHop(IpAddress& ipAddr, MacAddress macAddress, uint32_t vni, sai_object_id_t nhId); bool removeNextHop(IpAddress& ipAddr, MacAddress macAddress, uint32_t vni); sai_object_id_t getNextHop(IpAddress& ipAddr, MacAddress macAddress, uint32_t vni) const;