Skip to content

Commit

Permalink
Single VRF for ingress and egress flows, skip route replication (soni…
Browse files Browse the repository at this point in the history
…c-net#1045)

* Single VRF approach for VNets, no egress replication
  • Loading branch information
prsunny authored Oct 10, 2019
1 parent 953474a commit 3461710
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
14 changes: 11 additions & 3 deletions orchagent/intfsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,17 @@ void IntfsOrch::removeSubnetRoute(const Port &port, const IpPrefix &ip_prefix)
sai_status_t status = sai_route_api->remove_route_entry(&unicast_route_entry);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to remove subnet route to %s from %s, rv:%d",
ip_prefix.to_string().c_str(), port.m_alias.c_str(), status);
throw runtime_error("Failed to remove subnet route.");
if (status == SAI_STATUS_ITEM_NOT_FOUND)
{
SWSS_LOG_ERROR("No subnet route found for %s", ip_prefix.to_string().c_str());
return;
}
else
{
SWSS_LOG_ERROR("Failed to remove subnet route to %s from %s, rv:%d",
ip_prefix.to_string().c_str(), port.m_alias.c_str(), status);
throw runtime_error("Failed to remove subnet route.");
}
}

SWSS_LOG_NOTICE("Remove subnet route to %s from %s",
Expand Down
20 changes: 13 additions & 7 deletions orchagent/vnetorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ VNetOrch::VNetOrch(DBConnector *db, const std::string& tableName, VNET_EXEC op)

if (op == VNET_EXEC::VNET_EXEC_VRF)
{
vr_cntxt = { VR_TYPE::ING_VR_VALID, VR_TYPE::EGR_VR_VALID };
vr_cntxt = { VR_TYPE::ING_VR_VALID };
}
else
{
Expand Down Expand Up @@ -1647,8 +1647,9 @@ bool VNetRouteOrch::doRouteTask<VNetVrfObject>(const string& vnet, IpPrefix& ipP

if (!vnet_orch_->isVnetExists(vnet))
{
SWSS_LOG_WARN("VNET %s doesn't exist", vnet.c_str());
return false;
SWSS_LOG_WARN("VNET %s doesn't exist for prefix %s, op %s",
vnet.c_str(), ipPrefix.to_string().c_str(), op.c_str());
return (op == DEL_COMMAND)?true:false;
}

set<sai_object_id_t> vr_set;
Expand Down Expand Up @@ -1710,8 +1711,9 @@ bool VNetRouteOrch::doRouteTask<VNetVrfObject>(const string& vnet, IpPrefix& ipP

if (!vnet_orch_->isVnetExists(vnet))
{
SWSS_LOG_WARN("VNET %s doesn't exist", vnet.c_str());
return false;
SWSS_LOG_WARN("VNET %s doesn't exist for prefix %s, op %s",
vnet.c_str(), ipPrefix.to_string().c_str(), op.c_str());
return (op == DEL_COMMAND)?true:false;
}

auto *vrf_obj = vnet_orch_->getTypePtr<VNetVrfObject>(vnet);
Expand Down Expand Up @@ -1799,14 +1801,18 @@ bool VNetRouteOrch::doRouteTask<VNetVrfObject>(const string& vnet, IpPrefix& ipP

for (auto vr_id : vr_set)
{
if (vr_id == SAI_NULL_OBJECT_ID)
{
continue;
}
if (op == SET_COMMAND && !add_route(vr_id, pfx, nh_id))
{
SWSS_LOG_ERROR("Route add failed for %s", ipPrefix.to_string().c_str());
SWSS_LOG_INFO("Route add failed for %s", ipPrefix.to_string().c_str());
break;
}
else if (op == DEL_COMMAND && !del_route(vr_id, pfx))
{
SWSS_LOG_ERROR("Route del failed for %s", ipPrefix.to_string().c_str());
SWSS_LOG_INFO("Route del failed for %s", ipPrefix.to_string().c_str());
break;
}
}
Expand Down
9 changes: 8 additions & 1 deletion orchagent/vnetorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,14 @@ class VNetVrfObject : public VNetObject

sai_object_id_t getDecapMapId() const
{
return getVRidEgress();
if (std::find(vr_cntxt.begin(), vr_cntxt.end(), VR_TYPE::EGR_VR_VALID) != vr_cntxt.end())
{
return getVRidEgress();
}
else
{
return getVRidIngress();
}
}

sai_object_id_t getVRid() const
Expand Down
17 changes: 9 additions & 8 deletions tests/test_vnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get_all_created_entries(db, table, existed_entries):
tbl = swsscommon.Table(db, table)
entries = set(tbl.getKeys())
new_entries = list(entries - existed_entries)
assert len(new_entries) > 0, "No created entries."
assert len(new_entries) >= 0, "Get all could be no new created entries."
new_entries.sort()
return new_entries

Expand Down Expand Up @@ -521,13 +521,13 @@ def check_vxlan_tunnel_entry(self, dvs, tunnel_name, vnet_name, vni_id):
def check_vnet_entry(self, dvs, name, peer_list=[]):
asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)
#Check virtual router objects
assert how_many_entries_exist(asic_db, self.ASIC_VRF_TABLE) == (len(self.vnet_vr_ids) + 2),\
assert how_many_entries_exist(asic_db, self.ASIC_VRF_TABLE) == (len(self.vnet_vr_ids) + 1),\
"The VR objects are not created"

new_vr_ids = get_created_entries(asic_db, self.ASIC_VRF_TABLE, self.vnet_vr_ids, 2)
new_vr_ids = get_created_entries(asic_db, self.ASIC_VRF_TABLE, self.vnet_vr_ids, 1)

self.vnet_vr_ids.update(new_vr_ids)
self.vr_map[name] = { 'ing':new_vr_ids[0], 'egr':new_vr_ids[1], 'peer':peer_list }
self.vr_map[name] = { 'ing':new_vr_ids[0], 'egr':new_vr_ids[0], 'peer':peer_list }

def check_default_vnet_entry(self, dvs, name):
asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)
Expand All @@ -544,9 +544,7 @@ def check_del_vnet_entry(self, dvs, name):
def vnet_route_ids(self, dvs, name, local=False):
vr_set = set()

if local:
vr_set.add(self.vr_map[name].get('egr'))
else:
if not local:
vr_set.add(self.vr_map[name].get('ing'))

try:
Expand Down Expand Up @@ -599,7 +597,10 @@ def check_vnet_local_routes(self, dvs, name):

new_route = get_created_entries(asic_db, self.ASIC_ROUTE_ENTRY, self.routes, count)

#Check if the route is duplicated to egress VRF
#Routes are not replicated to egress VRF, return if count is 0, else check peering
if not count:
return

asic_vrs = set()
for idx in range(count):
rt_key = json.loads(new_route[idx])
Expand Down

0 comments on commit 3461710

Please sign in to comment.