Skip to content

Commit 4a67378

Browse files
Add support of VXLAN tunnel removal (#931)
* Add support of vxlan removal
1 parent 7a1a97c commit 4a67378

File tree

2 files changed

+97
-4
lines changed

2 files changed

+97
-4
lines changed

orchagent/vxlanorch.cpp

+91-4
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ create_tunnel_map(MAP_T map_t)
106106
return tunnel_map_id;
107107
}
108108

109+
void
110+
remove_tunnel_map(sai_object_id_t tunnel_map_id)
111+
{
112+
sai_status_t status = sai_tunnel_api->remove_tunnel_map(tunnel_map_id);
113+
if (status != SAI_STATUS_SUCCESS)
114+
{
115+
throw std::runtime_error("Can't remove a tunnel map object");
116+
}
117+
}
118+
109119
static sai_object_id_t create_tunnel_map_entry(
110120
MAP_T map_t,
111121
sai_object_id_t tunnel_map_id,
@@ -269,6 +279,16 @@ create_tunnel(
269279
return tunnel_id;
270280
}
271281

282+
void
283+
remove_tunnel(sai_object_id_t tunnel_id)
284+
{
285+
sai_status_t status = sai_tunnel_api->remove_tunnel(tunnel_id);
286+
if (status != SAI_STATUS_SUCCESS)
287+
{
288+
throw std::runtime_error("Can't remove a tunnel object");
289+
}
290+
}
291+
272292
// Create tunnel termination
273293
static sai_object_id_t
274294
create_tunnel_termination(
@@ -328,6 +348,16 @@ create_tunnel_termination(
328348
return term_table_id;
329349
}
330350

351+
void
352+
remove_tunnel_termination(sai_object_id_t term_table_id)
353+
{
354+
sai_status_t status = sai_tunnel_api->remove_tunnel_term_table_entry(term_table_id);
355+
if (status != SAI_STATUS_SUCCESS)
356+
{
357+
throw std::runtime_error("Can't remove a tunnel term table object");
358+
}
359+
}
360+
331361
bool VxlanTunnel::createTunnel(MAP_T encap, MAP_T decap)
332362
{
333363
try
@@ -368,7 +398,7 @@ bool VxlanTunnel::createTunnel(MAP_T encap, MAP_T decap)
368398
return false;
369399
}
370400

371-
SWSS_LOG_INFO("Vxlan tunnel '%s' was created", tunnel_name_.c_str());
401+
SWSS_LOG_NOTICE("Vxlan tunnel '%s' was created", tunnel_name_.c_str());
372402
return true;
373403
}
374404

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

659689
vxlan_tunnel_table_[tunnel_name] = std::unique_ptr<VxlanTunnel>(new VxlanTunnel(tunnel_name, src_ip, dst_ip));
660690

661-
SWSS_LOG_INFO("Vxlan tunnel '%s' was added", tunnel_name.c_str());
691+
SWSS_LOG_NOTICE("Vxlan tunnel '%s' was added", tunnel_name.c_str());
662692
return true;
663693
}
664694

665695
bool VxlanTunnelOrch::delOperation(const Request& request)
666696
{
667697
SWSS_LOG_ENTER();
668698

669-
SWSS_LOG_ERROR("DEL operation is not implemented");
699+
const auto& tunnel_name = request.getKeyString(0);
700+
701+
if(!isTunnelExists(tunnel_name))
702+
{
703+
SWSS_LOG_ERROR("Vxlan tunnel '%s' doesn't exist", tunnel_name.c_str());
704+
return true;
705+
}
706+
707+
auto tunnel_term_id = vxlan_tunnel_table_[tunnel_name].get()->getTunnelTermId();
708+
try
709+
{
710+
remove_tunnel_termination(tunnel_term_id);
711+
}
712+
catch(const std::runtime_error& error)
713+
{
714+
SWSS_LOG_ERROR("Error removing tunnel term entry. Tunnel: %s. Error: %s", tunnel_name.c_str(), error.what());
715+
return false;
716+
}
717+
718+
auto tunnel_id = vxlan_tunnel_table_[tunnel_name].get()->getTunnelId();
719+
try
720+
{
721+
remove_tunnel(tunnel_id);
722+
}
723+
catch(const std::runtime_error& error)
724+
{
725+
SWSS_LOG_ERROR("Error removing tunnel entry. Tunnel: %s. Error: %s", tunnel_name.c_str(), error.what());
726+
return false;
727+
}
728+
729+
vxlan_tunnel_table_.erase(tunnel_name);
730+
731+
SWSS_LOG_NOTICE("Vxlan tunnel '%s' was removed", tunnel_name.c_str());
670732

671733
return true;
672734
}
@@ -738,7 +800,32 @@ bool VxlanTunnelMapOrch::delOperation(const Request& request)
738800
{
739801
SWSS_LOG_ENTER();
740802

741-
SWSS_LOG_ERROR("DEL operation is not implemented");
803+
const auto& tunnel_name = request.getKeyString(0);
804+
const auto& tunnel_map_entry_name = request.getKeyString(1);
805+
const auto& full_tunnel_map_entry_name = request.getFullKey();
806+
807+
808+
if (!isTunnelMapExists(full_tunnel_map_entry_name))
809+
{
810+
SWSS_LOG_WARN("Vxlan tunnel map '%s' doesn't exist", full_tunnel_map_entry_name.c_str());
811+
return true;
812+
}
813+
814+
auto tunnel_map_entry_id = vxlan_tunnel_map_table_[full_tunnel_map_entry_name];
815+
try
816+
{
817+
remove_tunnel_map_entry(tunnel_map_entry_id);
818+
}
819+
catch (const std::runtime_error& error)
820+
{
821+
SWSS_LOG_ERROR("Error removing tunnel map %s: %s", full_tunnel_map_entry_name.c_str(), error.what());
822+
return false;
823+
}
824+
825+
vxlan_tunnel_map_table_.erase(full_tunnel_map_entry_name);
826+
827+
SWSS_LOG_NOTICE("Vxlan tunnel map entry '%s' for tunnel '%s' was removed",
828+
tunnel_map_entry_name.c_str(), tunnel_name.c_str());
742829

743830
return true;
744831
}

orchagent/vxlanorch.h

+6
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ class VxlanTunnel
104104
return ids_.tunnel_encap_id;
105105
}
106106

107+
sai_object_id_t getTunnelTermId() const
108+
{
109+
return ids_.tunnel_term_id;
110+
}
111+
112+
107113
void updateNextHop(IpAddress& ipAddr, MacAddress macAddress, uint32_t vni, sai_object_id_t nhId);
108114
bool removeNextHop(IpAddress& ipAddr, MacAddress macAddress, uint32_t vni);
109115
sai_object_id_t getNextHop(IpAddress& ipAddr, MacAddress macAddress, uint32_t vni) const;

0 commit comments

Comments
 (0)