Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vnet] Add ref_count of router interfaces for vnet #1425

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion orchagent/intfsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ bool IntfsOrch::removeIntf(const string& alias, sai_object_id_t vrf_id, const Ip
gPortsOrch->decreasePortRefCount(alias);
m_syncdIntfses.erase(alias);
m_vrfOrch->decreaseVrfRefCount(vrf_id);
m_vnetInfses.erase(alias);

if (port.m_type == Port::SUBPORT)
{
Expand Down Expand Up @@ -841,7 +842,6 @@ void IntfsOrch::doTask(Consumer &consumer)

if (vnet_orch->delIntf(alias, vnet_name, ip_prefix_in_key ? &ip_prefix : nullptr))
{
m_vnetInfses.erase(alias);
it = consumer.m_toSync.erase(it);
}
else
Expand Down
31 changes: 31 additions & 0 deletions orchagent/vnetorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ bool VNetVrfObject::createObj(vector<sai_attribute_t>& attrs)
}
}

ref_count = 0;
SWSS_LOG_INFO("VNET '%s' router object created ", vnet_name_.c_str());
return true;
}
Expand Down Expand Up @@ -1348,6 +1349,18 @@ bool VNetOrch::setIntf(const string& alias, const string name, const IpPrefix *p
auto *vnet_obj = getTypePtr<VNetVrfObject>(name);
sai_object_id_t vrf_id = vnet_obj->getVRidIngress();

if (!prefix )
{
if (gIntfsOrch->setIntf(alias, vrf_id, prefix, adminUp, mtu))
{
vnet_obj->increaseVnetRefCount();
return true;
}
else
{
return false;
}
}
return gIntfsOrch->setIntf(alias, vrf_id, prefix, adminUp, mtu);
}
else
Expand All @@ -1374,6 +1387,18 @@ bool VNetOrch::delIntf(const string& alias, const string name, const IpPrefix *p
auto *vnet_obj = getTypePtr<VNetVrfObject>(name);
sai_object_id_t vrf_id = vnet_obj->getVRidIngress();

if (!prefix )
{
if (gIntfsOrch->removeIntf(alias, vrf_id, prefix))
{
vnet_obj->decreaseVnetRefCount();
return true;
}
else
{
return false;
}
}
return gIntfsOrch->removeIntf(alias, vrf_id, prefix);
}
else
Expand Down Expand Up @@ -1537,6 +1562,12 @@ bool VNetOrch::delOperation(const Request& request)
return false;
}

if (vrf_obj->getRefCount())
{
SWSS_LOG_ERROR("VNET '%s': Interfaces are still present", vnet_name.c_str());
return false;
}

if (!vxlan_orch->removeVxlanTunnelMap(vrf_obj->getTunnelName(), vrf_obj->getVni()))
{
SWSS_LOG_ERROR("VNET '%s' map delete failed", vnet_name.c_str());
Expand Down
15 changes: 15 additions & 0 deletions orchagent/vnetorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,20 @@ class VNetVrfObject : public VNetObject
void increaseNextHopRefCount(const nextHop&);
void decreaseNextHopRefCount(const nextHop&);

void increaseVnetRefCount()
{
ref_count++;
}
void decreaseVnetRefCount()
{
if(ref_count > 0)
ref_count--;
}
int getRefCount()
{
return ref_count;
}

~VNetVrfObject();

private:
Expand All @@ -185,6 +199,7 @@ class VNetVrfObject : public VNetObject

TunnelRoutes tunnels_;
RouteMap routes_;
int ref_count;
};

struct VnetBridgeInfo
Expand Down