Skip to content

Commit

Permalink
[vnet]: Fix double route installation for BITMAP VNET interface (soni…
Browse files Browse the repository at this point in the history
…c-net#1114)

* [vnet]: Fix double route installation for BITMAP VNET interface
  • Loading branch information
Volodymyr Samotiy authored Apr 3, 2020
1 parent ae1daf3 commit fc25f82
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 88 deletions.
84 changes: 4 additions & 80 deletions orchagent/vnetorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,60 +715,7 @@ bool VNetBitmapObject::addIntf(const string& alias, const IpPrefix *prefix)

if (prefix)
{
auto& intf = intfMap_.at(alias);

if (intf.pfxMap.find(*prefix) != intf.pfxMap.end())
{
SWSS_LOG_WARN("VNET '%s' interface '%s' prefix '%s' already exists",
getVnetName().c_str(), alias.c_str(), prefix->getIp().to_string().c_str());
return true;
}

RouteInfo intfPfxInfo;

sai_ip_prefix_t saiPrefix;
copy(saiPrefix, *prefix);

gIntfsOrch->addIp2MeRoute(gVirtualRouterId, *prefix);

attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_ACTION;
attr.value.s32 = SAI_TABLE_BITMAP_ROUTER_ENTRY_ACTION_TO_LOCAL;
route_attrs.push_back(attr);

intfPfxInfo.offset = getFreeTunnelRouteTableOffset();
attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_PRIORITY;
attr.value.u32 = intfPfxInfo.offset;
route_attrs.push_back(attr);

attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_IN_RIF_METADATA_KEY;
attr.value.u64 = 0;
route_attrs.push_back(attr);

attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_IN_RIF_METADATA_MASK;
attr.value.u64 = ~peerBitmap;
route_attrs.push_back(attr);

attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_DST_IP_KEY;
attr.value.ipprefix = saiPrefix;
route_attrs.push_back(attr);

attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_ROUTER_INTERFACE;
attr.value.oid = gIntfsOrch->getRouterIntfsId(alias);
route_attrs.push_back(attr);

status = sai_bmtor_api->create_table_bitmap_router_entry(
&intfPfxInfo.routeTableEntryId,
gSwitchId,
(uint32_t)route_attrs.size(),
route_attrs.data());

if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create local VNET route entry, SAI rc: %d", status);
throw std::runtime_error("VNet interface creation failed");
}

intf.pfxMap.emplace(*prefix, intfPfxInfo);
}

return true;
Expand All @@ -790,37 +737,14 @@ bool VNetBitmapObject::removeIntf(const string& alias, const IpPrefix *prefix)

if (prefix)
{
if (intf.pfxMap.find(*prefix) == intf.pfxMap.end())
{
SWSS_LOG_ERROR("VNET '%s' interface '%s' prefix '%s' doesn't exist",
getVnetName().c_str(), alias.c_str(), prefix->getIp().to_string().c_str());
return true;
}

auto& pfx = intf.pfxMap.at(*prefix);

status = sai_bmtor_api->remove_table_bitmap_router_entry(pfx.routeTableEntryId);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to remove VNET local route entry, SAI rc: %d", status);
throw std::runtime_error("VNET interface removal failed");
}

gIntfsOrch->removeIp2MeRoute(gVirtualRouterId, *prefix);

recycleTunnelRouteTableOffset(pfx.offset);

intf.pfxMap.erase(*prefix);
}

if (intf.pfxMap.size() == 0)
status = sai_bmtor_api->remove_table_bitmap_classification_entry(intf.vnetTableEntryId);
if (status != SAI_STATUS_SUCCESS)
{
status = sai_bmtor_api->remove_table_bitmap_classification_entry(intf.vnetTableEntryId);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to remove VNET table entry, SAI rc: %d", status);
throw std::runtime_error("VNET interface removal failed");
}
SWSS_LOG_ERROR("Failed to remove VNET table entry, SAI rc: %d", status);
throw std::runtime_error("VNET interface removal failed");
}

if (!prefix)
Expand Down
1 change: 0 additions & 1 deletion orchagent/vnetorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ struct RouteInfo
struct VnetIntfInfo
{
sai_object_id_t vnetTableEntryId;
map<IpPrefix, RouteInfo> pfxMap;
};


Expand Down
7 changes: 0 additions & 7 deletions tests/test_vnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,12 +859,9 @@ def check_router_interface(self, dvs, name, vlan_oid=0):
new_rif = get_created_entry(asic_db, self.ASIC_RIF_TABLE, self.rifs)
check_object(asic_db, self.ASIC_RIF_TABLE, new_rif, expected_attrs)

new_bitmap_route = get_created_entries(asic_db, self.ASIC_BITMAP_ROUTER_ENTRY, self.vnet_bitmap_route_ids, 1)

new_bitmap_class_id = get_created_entries(asic_db, self.ASIC_BITMAP_CLASS_ENTRY, self.vnet_bitmap_class_ids, 1)

self.rifs.add(new_rif)
self.vnet_bitmap_route_ids.update(new_bitmap_route)
self.vnet_bitmap_class_ids.update(new_bitmap_class_id)

def check_del_router_interface(self, dvs, name):
Expand All @@ -876,12 +873,8 @@ def check_del_router_interface(self, dvs, name):
old_bitmap_class_id = get_deleted_entries(asic_db, self.ASIC_BITMAP_CLASS_ENTRY, self.vnet_bitmap_class_ids, 1)
check_deleted_object(asic_db, self.ASIC_BITMAP_CLASS_ENTRY, old_bitmap_class_id[0])

old_bitmap_route_id = get_deleted_entries(asic_db, self.ASIC_BITMAP_ROUTER_ENTRY, self.vnet_bitmap_route_ids, 1)
check_deleted_object(asic_db, self.ASIC_BITMAP_ROUTER_ENTRY, old_bitmap_route_id[0])

self.rifs.remove(old_rif[0])
self.vnet_bitmap_class_ids.remove(old_bitmap_class_id[0])
self.vnet_bitmap_route_ids.remove(old_bitmap_route_id[0])

def check_vnet_local_routes(self, dvs, name):
asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)
Expand Down

0 comments on commit fc25f82

Please sign in to comment.