Skip to content

Commit

Permalink
Add support of VXLAN tunnel removal (#931)
Browse files Browse the repository at this point in the history
* Add support of vxlan removal
  • Loading branch information
pavel-shirshov authored Jun 14, 2019
1 parent 7a1a97c commit 4a67378
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 4 deletions.
95 changes: 91 additions & 4 deletions orchagent/vxlanorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -658,15 +688,47 @@ bool VxlanTunnelOrch::addOperation(const Request& request)

vxlan_tunnel_table_[tunnel_name] = std::unique_ptr<VxlanTunnel>(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;
}

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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions orchagent/vxlanorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4a67378

Please sign in to comment.