Skip to content

Commit

Permalink
Merge branch 'Azure:master' into barefoot-add-port-isoloation-group
Browse files Browse the repository at this point in the history
  • Loading branch information
novikauanton authored Oct 4, 2021
2 parents 83fedd4 + da49332 commit 96a640e
Show file tree
Hide file tree
Showing 12 changed files with 399 additions and 126 deletions.
37 changes: 1 addition & 36 deletions orchagent/orch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,42 +330,7 @@ bool Orch::parseReference(type_map &type_maps, string &ref_in, const string &typ
if ((ref_in[0] == ref_start) || (ref_in[ref_in.size()-1] == ref_end))
{
SWSS_LOG_ERROR("malformed reference:%s. Must not be surrounded by [ ]\n", ref_in.c_str());
/*
* Accepting old format until sonic-buildimage changes merged, swss tests depends on
* generate qos configs which are with old format. If we skip the old format
* isPortAllReady() will fail whcih is set ready by checking buffer config exists in CONFIG_DB are
* applied to ASIC_DB or not.
* Due to this All swss test cases are failing.
* This to avoid test case failures until merge happens.
*
*/
if (ref_in.size() == 2)
{
// value set by user is "[]"
// Deem it as a valid format
// clear both type_name and object_name
// as an indication to the caller that
// such a case has been encountered
// type_name.clear();
object_name.clear();
return true;
}
string ref_content = ref_in.substr(1, ref_in.size() - 2);
vector<string> tokens;
tokens = tokenize(ref_content, delimiter);
if (tokens.size() != 2)
{
tokens = tokenize(ref_content, config_db_key_delimiter);
if (tokens.size() != 2)
{
SWSS_LOG_ERROR("malformed reference:%s. Must contain 2 tokens\n", ref_content.c_str());
return false;
}
}
object_name = tokens[1];
SWSS_LOG_ERROR("parsed: type_name:%s, object_name:%s", type_name.c_str(), object_name.c_str());

return true;
return false;
}
auto type_it = type_maps.find(type_name);
if (type_it == type_maps.end())
Expand Down
122 changes: 94 additions & 28 deletions orchagent/routeorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1317,47 +1317,94 @@ bool RouteOrch::removeNextHopGroup(const NextHopGroupKey &nexthops)
return true;
}

void RouteOrch::addNextHopRoute(const NextHopKey& nextHop, const RouteKey& routeKey)
{
auto it = m_nextHops.find((nextHop));

if (it != m_nextHops.end())
{
if (it->second.find(routeKey) != it->second.end())
{
SWSS_LOG_INFO("Route already present in nh table %s",
routeKey.prefix.to_string().c_str());
return;
}

it->second.insert(routeKey);
}
else
{
set<RouteKey> routes;
routes.insert(routeKey);
m_nextHops.insert(make_pair(nextHop, routes));
}
}

void RouteOrch::removeNextHopRoute(const NextHopKey& nextHop, const RouteKey& routeKey)
{
auto it = m_nextHops.find((nextHop));

if (it != m_nextHops.end())
{
if (it->second.find(routeKey) == it->second.end())
{
SWSS_LOG_INFO("Route not present in nh table %s", routeKey.prefix.to_string().c_str());
return;
}

it->second.erase(routeKey);
if (it->second.empty())
{
m_nextHops.erase(nextHop);
}
}
else
{
SWSS_LOG_INFO("Nexthop %s not found in nexthop table", nextHop.to_string().c_str());
}
}

bool RouteOrch::updateNextHopRoutes(const NextHopKey& nextHop, uint32_t& numRoutes)
{
numRoutes = 0;
auto it = m_nextHops.find((nextHop));

if (it == m_nextHops.end())
{
SWSS_LOG_INFO("No routes found for NH %s", nextHop.ip_address.to_string().c_str());
return true;
}

sai_route_entry_t route_entry;
sai_attribute_t route_attr;
sai_object_id_t next_hop_id;

for (auto rt_table : m_syncdRoutes)
auto rt = it->second.begin();
while(rt != it->second.end())
{
for (auto rt_entry : rt_table.second)
{
// Skip routes with ecmp nexthops
if (rt_entry.second.getSize() > 1)
{
continue;
}
SWSS_LOG_INFO("Updating route %s", (*rt).prefix.to_string().c_str());
next_hop_id = m_neighOrch->getNextHopId(nextHop);

if (rt_entry.second.contains(nextHop))
{
SWSS_LOG_INFO("Updating route %s during nexthop status change",
rt_entry.first.to_string().c_str());
next_hop_id = m_neighOrch->getNextHopId(nextHop);

route_entry.vr_id = rt_table.first;
route_entry.switch_id = gSwitchId;
copy(route_entry.destination, rt_entry.first);
route_entry.vr_id = (*rt).vrf_id;
route_entry.switch_id = gSwitchId;
copy(route_entry.destination, (*rt).prefix);

route_attr.id = SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID;
route_attr.value.oid = next_hop_id;
route_attr.id = SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID;
route_attr.value.oid = next_hop_id;

sai_status_t status = sai_route_api->set_route_entry_attribute(&route_entry, &route_attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to update route %s, rv:%d",
rt_entry.first.to_string().c_str(), status);
return false;
}

++numRoutes;
sai_status_t status = sai_route_api->set_route_entry_attribute(&route_entry, &route_attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to update route %s, rv:%d", (*rt).prefix.to_string().c_str(), status);
task_process_status handle_status = handleSaiSetStatus(SAI_API_ROUTE, status);
if (handle_status != task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}

++numRoutes;
++rt;
}

return true;
Expand Down Expand Up @@ -1856,6 +1903,12 @@ bool RouteOrch::addRoutePost(const RouteBulkContext& ctx, const NextHopGroupKey
SWSS_LOG_NOTICE("Update overlay Nexthop %s", ol_nextHops.to_string().c_str());
m_bulkNhgReducedRefCnt.emplace(ol_nextHops, vrf_id);
}
else if (ol_nextHops.getSize() == 1)
{
RouteKey r_key = { vrf_id, ipPrefix };
auto nexthop = NextHopKey(ol_nextHops.to_string());
removeNextHopRoute(nexthop, r_key);
}
}

if (blackhole)
Expand All @@ -1878,6 +1931,16 @@ bool RouteOrch::addRoutePost(const RouteBulkContext& ctx, const NextHopGroupKey
ipPrefix.to_string().c_str(), nextHops.to_string().c_str());
}

if (nextHops.getSize() == 1 && !nextHops.is_overlay_nexthop())
{
RouteKey r_key = { vrf_id, ipPrefix };
auto nexthop = NextHopKey(nextHops.to_string());
if (!nexthop.ip_address.isZero())
{
addNextHopRoute(nexthop, r_key);
}
}

m_syncdRoutes[vrf_id][ipPrefix] = nextHops;

notifyNextHopChangeObservers(vrf_id, ipPrefix, nextHops, true);
Expand Down Expand Up @@ -2048,6 +2111,9 @@ bool RouteOrch::removeRoutePost(const RouteBulkContext& ctx)
{
m_neighOrch->removeMplsNextHop(nexthop);
}

RouteKey r_key = { vrf_id, ipPrefix };
removeNextHopRoute(nexthop, r_key);
}
}

Expand Down
17 changes: 17 additions & 0 deletions orchagent/routeorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ struct NextHopUpdate

struct NextHopObserverEntry;

/* Route destination key for a nexthop */
struct RouteKey
{
sai_object_id_t vrf_id;
IpPrefix prefix;

bool operator < (const RouteKey& rhs) const
{
return (vrf_id <= rhs.vrf_id && prefix < rhs.prefix);
}
};

/* NextHopGroupTable: NextHopGroupKey, NextHopGroupEntry */
typedef std::map<NextHopGroupKey, NextHopGroupEntry> NextHopGroupTable;
/* RouteTable: destination network, NextHopGroupKey */
Expand All @@ -56,6 +68,8 @@ typedef std::map<sai_object_id_t, LabelRouteTable> LabelRouteTables;
typedef std::pair<sai_object_id_t, IpAddress> Host;
/* NextHopObserverTable: Host, next hop observer entry */
typedef std::map<Host, NextHopObserverEntry> NextHopObserverTable;
/* Single Nexthop to Routemap */
typedef std::map<NextHopKey, std::set<RouteKey>> NextHopRouteTable;

struct NextHopObserverEntry
{
Expand Down Expand Up @@ -138,6 +152,8 @@ class RouteOrch : public Orch, public Subject
bool addNextHopGroup(const NextHopGroupKey&);
bool removeNextHopGroup(const NextHopGroupKey&);

void addNextHopRoute(const NextHopKey&, const RouteKey&);
void removeNextHopRoute(const NextHopKey&, const RouteKey&);
bool updateNextHopRoutes(const NextHopKey&, uint32_t&);

bool validnexthopinNextHopGroup(const NextHopKey&, uint32_t&);
Expand Down Expand Up @@ -170,6 +186,7 @@ class RouteOrch : public Orch, public Subject
RouteTables m_syncdRoutes;
LabelRouteTables m_syncdLabelRoutes;
NextHopGroupTable m_syncdNextHopGroups;
NextHopRouteTable m_nextHops;

std::set<std::pair<NextHopGroupKey, sai_object_id_t>> m_bulkNhgReducedRefCnt;
/* m_bulkNhgReducedRefCnt: nexthop, vrf_id */
Expand Down
15 changes: 5 additions & 10 deletions portsyncd/portsyncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void usage()
}

void handlePortConfigFile(ProducerStateTable &p, string file, bool warm);
bool handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, bool warm);
void handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, bool warm);
void handleVlanIntfFile(string file);
void handlePortConfig(ProducerStateTable &p, map<string, KeyOpFieldsValuesTuple> &port_cfg_map);
void checkPortInitDone(DBConnector *appl_db);
Expand Down Expand Up @@ -86,11 +86,7 @@ int main(int argc, char **argv)
netlink.dumpRequest(RTM_GETLINK);
cout << "Listen to link messages..." << endl;

if (!handlePortConfigFromConfigDB(p, cfgDb, warm))
{
SWSS_LOG_NOTICE("ConfigDB does not have port information, "
"however ports can be added later on, continuing...");
}
handlePortConfigFromConfigDB(p, cfgDb, warm);

LinkSync sync(&appl_db, &state_db);
NetDispatcher::getInstance().registerMessageHandler(RTM_NEWLINK, &sync);
Expand Down Expand Up @@ -191,7 +187,7 @@ static void notifyPortConfigDone(ProducerStateTable &p)
p.set("PortConfigDone", attrs);
}

bool handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, bool warm)
void handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, bool warm)
{
SWSS_LOG_ENTER();

Expand All @@ -204,8 +200,8 @@ bool handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, boo

if (keys.empty())
{
cout << "No port configuration in ConfigDB" << endl;
return false;
SWSS_LOG_NOTICE("ConfigDB does not have port information, "
"however ports can be added later on, continuing...");
}

for ( auto &k : keys )
Expand All @@ -228,7 +224,6 @@ bool handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, boo
notifyPortConfigDone(p);
}

return true;
}

void handlePortConfig(ProducerStateTable &p, map<string, KeyOpFieldsValuesTuple> &port_cfg_map)
Expand Down
Loading

0 comments on commit 96a640e

Please sign in to comment.