Skip to content

Commit

Permalink
Merge branch 'sonic-net:master' into dbarashi_align_watermark
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarashinvd authored Nov 15, 2022
2 parents 49f744b + 28aa309 commit 50281fb
Show file tree
Hide file tree
Showing 27 changed files with 1,671 additions and 834 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ swssconfig/swssplayer
tlm_teamd/tlm_teamd
teamsyncd/teamsyncd
tests/tests
tests/mock_tests/tests_fpmsyncd


# Test Files #
Expand Down
1 change: 0 additions & 1 deletion fdbsyncd/fdbsyncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ int main(int argc, char **argv)
DBConnector appDb(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
RedisPipeline pipelineAppDB(&appDb);
DBConnector stateDb(STATE_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector log_db(LOGLEVEL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector config_db(CONFIG_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);

FdbSync sync(&pipelineAppDB, &stateDb, &config_db);
Expand Down
82 changes: 50 additions & 32 deletions fpmsyncd/fpmlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,52 +210,70 @@ uint64_t FpmLink::readData()
hdr = reinterpret_cast<fpm_msg_hdr_t *>(static_cast<void *>(m_messageBuffer + start));
left = m_pos - start;
if (left < FPM_MSG_HDR_LEN)
{
break;
}

/* fpm_msg_len includes header size */
msg_len = fpm_msg_len(hdr);
if (left < msg_len)
{
break;
}

if (!fpm_msg_ok(hdr, left))
throw system_error(make_error_code(errc::bad_message), "Malformed FPM message received");

if (hdr->msg_type == FPM_MSG_TYPE_NETLINK)
{
bool isRaw = false;

nlmsghdr *nl_hdr = (nlmsghdr *)fpm_msg_data(hdr);

/*
* EVPN Type5 Add Routes need to be process in Raw mode as they contain
* RMAC, VLAN and L3VNI information.
* Where as all other route will be using rtnl api to extract information
* from the netlink msg.
* */
isRaw = isRawProcessing(nl_hdr);

nl_msg *msg = nlmsg_convert(nl_hdr);
if (msg == NULL)
{
throw system_error(make_error_code(errc::bad_message), "Unable to convert nlmsg");
}
throw system_error(make_error_code(errc::bad_message), "Malformed FPM message received");
}

nlmsg_set_proto(msg, NETLINK_ROUTE);
processFpmMessage(hdr);

if (isRaw)
{
/* EVPN Type5 Add route processing */
processRawMsg(nl_hdr);
}
else
{
NetDispatcher::getInstance().onNetlinkMessage(msg);
}
nlmsg_free(msg);
}
start += msg_len;
}

memmove(m_messageBuffer, m_messageBuffer + start, m_pos - start);
m_pos = m_pos - (uint32_t)start;
return 0;
}

void FpmLink::processFpmMessage(fpm_msg_hdr_t* hdr)
{
size_t msg_len = fpm_msg_len(hdr);

if (hdr->msg_type != FPM_MSG_TYPE_NETLINK)
{
return;
}
nlmsghdr *nl_hdr = (nlmsghdr *)fpm_msg_data(hdr);

/* Read all netlink messages inside FPM message */
for (; NLMSG_OK (nl_hdr, msg_len); nl_hdr = NLMSG_NEXT(nl_hdr, msg_len))
{
/*
* EVPN Type5 Add Routes need to be process in Raw mode as they contain
* RMAC, VLAN and L3VNI information.
* Where as all other route will be using rtnl api to extract information
* from the netlink msg.
*/
bool isRaw = isRawProcessing(nl_hdr);

nl_msg *msg = nlmsg_convert(nl_hdr);
if (msg == NULL)
{
throw system_error(make_error_code(errc::bad_message), "Unable to convert nlmsg");
}

nlmsg_set_proto(msg, NETLINK_ROUTE);

if (isRaw)
{
/* EVPN Type5 Add route processing */
processRawMsg(nl_hdr);
}
else
{
NetDispatcher::getInstance().onNetlinkMessage(msg);
}
nlmsg_free(msg);
}
}
2 changes: 2 additions & 0 deletions fpmsyncd/fpmlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class FpmLink : public Selectable {
m_routesync->onMsgRaw(h);
};

void processFpmMessage(fpm_msg_hdr_t* hdr);

private:
RouteSync *m_routesync;
unsigned int m_bufSize;
Expand Down
35 changes: 0 additions & 35 deletions orchagent/intfsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,6 @@ bool IntfsOrch::removeRouterIntfs(Port &port)

const auto id = sai_serialize_object_id(port.m_rif_id);
removeRifFromFlexCounter(id, port.m_alias);
cleanUpRifFromCounterDb(id, port.m_alias);

sai_status_t status = sai_router_intfs_api->remove_router_interface(port.m_rif_id);
if (status != SAI_STATUS_SUCCESS)
Expand Down Expand Up @@ -1500,45 +1499,11 @@ void IntfsOrch::removeRifFromFlexCounter(const string &id, const string &name)
SWSS_LOG_DEBUG("Unregistered interface %s from Flex counter", name.c_str());
}

/*
TODO A race condition can exist when swss removes the counter from COUNTERS DB
and at the same time syncd is inserting a new entry in COUNTERS DB. Therefore
all the rif counters cleanup code should move to syncd
*/
void IntfsOrch::cleanUpRifFromCounterDb(const string &id, const string &name)
{
SWSS_LOG_ENTER();
string counter_key = getRifCounterTableKey(id);
string rate_key = getRifRateTableKey(id);
string rate_init_key = getRifRateInitTableKey(id);
m_counter_db->del(counter_key);
m_counter_db->del(rate_key);
m_counter_db->del(rate_init_key);
SWSS_LOG_NOTICE("CleanUp interface %s oid %s from counter db", name.c_str(),id.c_str());
}

string IntfsOrch::getRifFlexCounterTableKey(string key)
{
return string(RIF_STAT_COUNTER_FLEX_COUNTER_GROUP) + ":" + key;
}

string IntfsOrch::getRifCounterTableKey(string key)
{
return "COUNTERS:" + key;
}

string IntfsOrch::getRifRateTableKey(string key)
{
return "RATES:" + key;
}

string IntfsOrch::getRifRateInitTableKey(string key)
{
return "RATES:" + key + ":RIF";
}



void IntfsOrch::generateInterfaceMap()
{
m_updateMapsTimer->start();
Expand Down
4 changes: 0 additions & 4 deletions orchagent/intfsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ class IntfsOrch : public Orch
unique_ptr<ProducerTable> m_flexCounterGroupTable;

std::string getRifFlexCounterTableKey(std::string s);
std::string getRifCounterTableKey(std::string s);
std::string getRifRateTableKey(std::string s);
std::string getRifRateInitTableKey(std::string s);
void cleanUpRifFromCounterDb(const string &id, const string &name);

bool addRouterIntfs(sai_object_id_t vrf_id, Port &port, string loopbackAction);
bool removeRouterIntfs(Port &port);
Expand Down
22 changes: 16 additions & 6 deletions orchagent/p4orch/gre_tunnel_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ std::vector<sai_attribute_t> getSaiAttrs(const P4GreTunnelEntry &gre_tunnel_entr
} // namespace

P4GreTunnelEntry::P4GreTunnelEntry(const std::string &tunnel_id, const std::string &router_interface_id,
const swss::IpAddress &encap_src_ip, const swss::IpAddress &encap_dst_ip)
const swss::IpAddress &encap_src_ip, const swss::IpAddress &encap_dst_ip,
const swss::IpAddress &neighbor_id)
: tunnel_id(tunnel_id), router_interface_id(router_interface_id), encap_src_ip(encap_src_ip),
encap_dst_ip(encap_dst_ip)
encap_dst_ip(encap_dst_ip), neighbor_id(neighbor_id)
{
SWSS_LOG_ENTER();
tunnel_key = KeyGenerator::generateTunnelKey(tunnel_id);
Expand Down Expand Up @@ -188,7 +189,7 @@ P4GreTunnelEntry *GreTunnelManager::getGreTunnelEntry(const std::string &tunnel_
}
};

ReturnCodeOr<const std::string> GreTunnelManager::getUnderlayIfFromGreTunnelEntry(const std::string &tunnel_key)
ReturnCodeOr<const P4GreTunnelEntry> GreTunnelManager::getConstGreTunnelEntry(const std::string &tunnel_key)
{
SWSS_LOG_ENTER();

Expand All @@ -200,7 +201,7 @@ ReturnCodeOr<const std::string> GreTunnelManager::getUnderlayIfFromGreTunnelEntr
}
else
{
return tunnel->router_interface_id;
return *tunnel;
}
}

Expand Down Expand Up @@ -274,7 +275,7 @@ ReturnCode GreTunnelManager::processAddRequest(const P4GreTunnelAppDbEntry &app_
SWSS_LOG_ENTER();

P4GreTunnelEntry gre_tunnel_entry(app_db_entry.tunnel_id, app_db_entry.router_interface_id,
app_db_entry.encap_src_ip, app_db_entry.encap_dst_ip);
app_db_entry.encap_src_ip, app_db_entry.encap_dst_ip, app_db_entry.encap_dst_ip);
auto status = createGreTunnel(gre_tunnel_entry);
if (!status.ok())
{
Expand Down Expand Up @@ -570,6 +571,15 @@ std::string GreTunnelManager::verifyStateCache(const P4GreTunnelAppDbEntry &app_
return msg.str();
}

if (gre_tunnel_entry->neighbor_id.to_string() != app_db_entry.encap_dst_ip.to_string())
{
std::stringstream msg;
msg << "GreTunnel " << QuotedVar(app_db_entry.tunnel_id) << " with destination IP "
<< QuotedVar(app_db_entry.encap_dst_ip.to_string()) << " does not match internal cache "
<< QuotedVar(gre_tunnel_entry->neighbor_id.to_string()) << " fo neighbor_id in GreTunnel manager.";
return msg.str();
}

return m_p4OidMapper->verifyOIDMapping(SAI_OBJECT_TYPE_TUNNEL, gre_tunnel_entry->tunnel_key,
gre_tunnel_entry->tunnel_oid);
}
Expand Down Expand Up @@ -616,4 +626,4 @@ std::string GreTunnelManager::verifyStateAsicDb(const P4GreTunnelEntry *gre_tunn

return verifyAttrs(values, exp, std::vector<swss::FieldValueTuple>{},
/*allow_unknown=*/false);
}
}
8 changes: 6 additions & 2 deletions orchagent/p4orch/gre_tunnel_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ struct P4GreTunnelEntry
std::string router_interface_id;
swss::IpAddress encap_src_ip;
swss::IpAddress encap_dst_ip;
// neighbor_id is required to be equal to encap_dst_ip by BRCM. And the
// neighbor entry needs to be created before GRE tunnel object
swss::IpAddress neighbor_id;

// SAI OID associated with this entry.
sai_object_id_t tunnel_oid = SAI_NULL_OBJECT_ID;
Expand All @@ -45,7 +48,8 @@ struct P4GreTunnelEntry
sai_object_id_t underlay_if_oid = SAI_NULL_OBJECT_ID;

P4GreTunnelEntry(const std::string &tunnel_id, const std::string &router_interface_id,
const swss::IpAddress &encap_src_ip, const swss::IpAddress &encap_dst_ip);
const swss::IpAddress &encap_src_ip, const swss::IpAddress &encap_dst_ip,
const swss::IpAddress &neighbor_id);
};

// GreTunnelManager listens to changes in table APP_P4RT_TUNNEL_TABLE_NAME and
Expand All @@ -69,7 +73,7 @@ class GreTunnelManager : public ObjectManagerInterface
void drain() override;
std::string verifyState(const std::string &key, const std::vector<swss::FieldValueTuple> &tuple) override;

ReturnCodeOr<const std::string> getUnderlayIfFromGreTunnelEntry(const std::string &gre_tunnel_key);
ReturnCodeOr<const P4GreTunnelEntry> getConstGreTunnelEntry(const std::string &gre_tunnel_key);

private:
// Gets the internal cached GRE tunnel entry by its key.
Expand Down
Loading

0 comments on commit 50281fb

Please sign in to comment.