Skip to content

Commit

Permalink
Merge branch 'sonic-net:master' into sag-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
superchild authored Feb 22, 2024
2 parents 69c34c3 + 1221eae commit 2139a2e
Show file tree
Hide file tree
Showing 19 changed files with 548 additions and 62 deletions.
3 changes: 2 additions & 1 deletion .azure-pipelines/test-docker-sonic-vs-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
variables:
DIFF_COVER_CHECK_THRESHOLD: 80
DIFF_COVER_ENABLE: 'true'
DIFF_COVER_COVERAGE_FILES: Cobertura.xml

pool: sonic-common-test

Expand Down Expand Up @@ -142,7 +143,7 @@ jobs:
# Run the tests in parallel and retry
retry=3
IMAGE_NAME=docker-sonic-vs:$(Build.DefinitionName).$(Build.BuildNumber).asan-${{ parameters.asan }}
echo $all_tests | xargs -n 1 | xargs -P 8 -I TEST_MODULE sudo ./run-tests.py "$IMAGE_NAME" "$params" "TEST_MODULE" 3
echo $all_tests | xargs -n 1 | xargs -P 8 -I TEST_MODULE sudo ./run-tests.sh "$IMAGE_NAME" "$params" "TEST_MODULE" 3
rm -rf $(Build.ArtifactStagingDirectory)/download
displayName: "Run vs tests"
Expand Down
3 changes: 2 additions & 1 deletion orchagent/aclorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2202,9 +2202,10 @@ bool AclTable::addStageMandatoryRangeFields()
SWSS_LOG_ENTER();

string platform = getenv("platform") ? getenv("platform") : "";
string sub_platform = getenv("sub_platform") ? getenv("sub_platform") : "";
auto match = SAI_ACL_TABLE_ATTR_FIELD_ACL_RANGE_TYPE;

if ((platform == BRCM_PLATFORM_SUBSTRING) &&
if ((platform == BRCM_PLATFORM_SUBSTRING) && (sub_platform != BRCM_DNX_PLATFORM_SUBSTRING) &&
(stage == ACL_STAGE_EGRESS))
{
return false;
Expand Down
187 changes: 180 additions & 7 deletions orchagent/bfdorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ BfdOrch::~BfdOrch(void)
void BfdOrch::doTask(Consumer &consumer)
{
SWSS_LOG_ENTER();

BgpGlobalStateOrch* bgp_global_state_orch = gDirectory.get<BgpGlobalStateOrch*>();
bool tsa_enabled = false;
if (bgp_global_state_orch)
{
tsa_enabled = bgp_global_state_orch->getTsaState();
}
auto it = consumer.m_toSync.begin();
while (it != consumer.m_toSync.end())
{
Expand All @@ -96,18 +101,66 @@ void BfdOrch::doTask(Consumer &consumer)

if (op == SET_COMMAND)
{
if (!create_bfd_session(key, data))
bool tsa_shutdown_enabled = false;
for (auto i : data)
{
it++;
continue;
auto value = fvValue(i);
//shutdown_bfd_during_tsa parameter is used by the BFD session creator to ensure that the the
//specified session gets removed when the device goes into TSA state.
//if this parameter is not specified or set to false for a session, the
// corrosponding BFD session would be maintained even in TSA state.
if (fvField(i) == "shutdown_bfd_during_tsa" && value == "true" )
{
tsa_shutdown_enabled = true;
break;
}
}
if (tsa_shutdown_enabled)
{
bfd_session_cache[key] = data;
if (!tsa_enabled)
{
if (!create_bfd_session(key, data))
{
it++;
continue;
}
}
else
{
notify_session_state_down(key);
}
}
else
{
if (!create_bfd_session(key, data))
{
it++;
continue;
}
}
}
else if (op == DEL_COMMAND)
{
if (!remove_bfd_session(key))
if (bfd_session_cache.find(key) != bfd_session_cache.end() )
{
it++;
continue;
bfd_session_cache.erase(key);
if (!tsa_enabled)
{
if (!remove_bfd_session(key))
{
it++;
continue;
}
}
}
else
{
if (!remove_bfd_session(key))
{
it++;
continue;
}
}
}
else
Expand Down Expand Up @@ -298,6 +351,12 @@ bool BfdOrch::create_bfd_session(const string& key, const vector<FieldValueTuple
{
tos = to_uint<uint8_t>(value);
}
else if (fvField(i) == "shutdown_bfd_during_tsa")
{
//since we are handling shutdown_bfd_during_tsa in the caller function, we need to ignore it here.
//failure to ignore this parameter would cause error log.
continue;
}
else
SWSS_LOG_ERROR("Unsupported BFD attribute %s\n", fvField(i).c_str());
}
Expand Down Expand Up @@ -551,3 +610,117 @@ uint32_t BfdOrch::bfd_src_port(void)
return (port++);
}

void BfdOrch::notify_session_state_down(const string& key)
{
SWSS_LOG_ENTER();
size_t found_vrf = key.find(delimiter);
if (found_vrf == string::npos)
{
SWSS_LOG_ERROR("Failed to parse key %s, no vrf is given", key.c_str());
return;
}

size_t found_ifname = key.find(delimiter, found_vrf + 1);
if (found_ifname == string::npos)
{
SWSS_LOG_ERROR("Failed to parse key %s, no ifname is given", key.c_str());
return;
}
string vrf_name = key.substr(0, found_vrf);
string alias = key.substr(found_vrf + 1, found_ifname - found_vrf - 1);
IpAddress peer_address(key.substr(found_ifname + 1));
BfdUpdate update;
update.peer = get_state_db_key(vrf_name, alias, peer_address);
update.state = SAI_BFD_SESSION_STATE_DOWN;
notify(SUBJECT_TYPE_BFD_SESSION_STATE_CHANGE, static_cast<void *>(&update));
}

void BfdOrch::handleTsaStateChange(bool tsaState)
{
SWSS_LOG_ENTER();
for (auto it : bfd_session_cache)
{
if (tsaState == true)
{
if (bfd_session_map.find(it.first) != bfd_session_map.end())
{
notify_session_state_down(it.first);
remove_bfd_session(it.first);
}
}
else
{
if (bfd_session_map.find(it.first) == bfd_session_map.end())
{
create_bfd_session(it.first, it.second);
}
}
}
}

BgpGlobalStateOrch::BgpGlobalStateOrch(DBConnector *db, string tableName):
Orch(db, tableName)
{
SWSS_LOG_ENTER();
tsa_enabled = false;
}

BgpGlobalStateOrch::~BgpGlobalStateOrch(void)
{
SWSS_LOG_ENTER();
}

bool BgpGlobalStateOrch::getTsaState()
{
SWSS_LOG_ENTER();
return tsa_enabled;
}
void BgpGlobalStateOrch::doTask(Consumer &consumer)
{
SWSS_LOG_ENTER();

auto it = consumer.m_toSync.begin();
while (it != consumer.m_toSync.end())
{
KeyOpFieldsValuesTuple t = it->second;

string key = kfvKey(t);
string op = kfvOp(t);
auto data = kfvFieldsValues(t);

if (op == SET_COMMAND)
{
for (auto i : data)
{
auto value = fvValue(i);
auto type = fvField(i);
SWSS_LOG_INFO("SET on key %s, data T %s, V %s\n", key.c_str(), type.c_str(), value.c_str());
if (type == "tsa_enabled")
{
bool state = true ? value == "true" : false;
if (tsa_enabled != state)
{
SWSS_LOG_NOTICE("BgpGlobalStateOrch TSA state Changed to %d from %d.\n", int(state), int(tsa_enabled));
tsa_enabled = state;

BfdOrch* bfd_orch = gDirectory.get<BfdOrch*>();
if (bfd_orch)
{
bfd_orch->handleTsaStateChange(state);
}
}
}
}
}
else if (op == DEL_COMMAND)
{
SWSS_LOG_ERROR("DEL on key %s is not expected.\n", key.c_str());
}
else
{
SWSS_LOG_ERROR("Unknown operation type %s\n", op.c_str());
}
it = consumer.m_toSync.erase(it);
}
}

16 changes: 16 additions & 0 deletions orchagent/bfdorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class BfdOrch: public Orch, public Subject
void doTask(swss::NotificationConsumer &consumer);
BfdOrch(swss::DBConnector *db, std::string tableName, TableConnector stateDbBfdSessionTable);
virtual ~BfdOrch(void);
void handleTsaStateChange(bool tsaState);

private:
bool create_bfd_session(const std::string& key, const std::vector<swss::FieldValueTuple>& data);
Expand All @@ -26,6 +27,7 @@ class BfdOrch: public Orch, public Subject
uint32_t bfd_gen_id(void);
uint32_t bfd_src_port(void);

void notify_session_state_down(const std::string& key);
bool register_bfd_state_change_notification(void);
void update_port_number(std::vector<sai_attribute_t> &attrs);
sai_status_t retry_create_bfd_session(sai_object_id_t &bfd_session_id, vector<sai_attribute_t> attrs);
Expand All @@ -37,6 +39,20 @@ class BfdOrch: public Orch, public Subject

swss::NotificationConsumer* m_bfdStateNotificationConsumer;
bool register_state_change_notif;
std::map<std::string, vector<FieldValueTuple>> bfd_session_cache;

};

class BgpGlobalStateOrch : public Orch
{
public:
void doTask(Consumer &consumer);
BgpGlobalStateOrch(swss::DBConnector *db, std::string tableName);
virtual ~BgpGlobalStateOrch(void);
bool getTsaState();

private:
bool tsa_enabled;

};
#endif /* SWSS_BFDORCH_H */
4 changes: 2 additions & 2 deletions orchagent/fabricportsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ void FabricPortsOrch::updateFabricPortState()

string key = FABRIC_PORT_PREFIX + to_string(lane);
std::vector<FieldValueTuple> values;
uint32_t remote_peer;
uint32_t remote_port;
uint32_t remote_peer = 0;
uint32_t remote_port = 0;

attr.id = SAI_PORT_ATTR_FABRIC_ATTACHED;
status = sai_port_api->get_port_attribute(port, 1, &attr);
Expand Down
4 changes: 2 additions & 2 deletions orchagent/fdborch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ FdbOrch::FdbOrch(DBConnector* applDbConnector, vector<table_name_with_pri_t> app
Orch::addExecutor(flushNotifier);

/* Add FDB notifications support from ASIC */
DBConnector *notificationsDb = new DBConnector("ASIC_DB", 0);
m_fdbNotificationConsumer = new swss::NotificationConsumer(notificationsDb, "NOTIFICATIONS");
m_notificationsDb = make_shared<DBConnector>("ASIC_DB", 0);
m_fdbNotificationConsumer = new swss::NotificationConsumer(m_notificationsDb.get(), "NOTIFICATIONS");
auto fdbNotifier = new Notifier(m_fdbNotificationConsumer, this, "FDB_NOTIFICATIONS");
Orch::addExecutor(fdbNotifier);
}
Expand Down
1 change: 1 addition & 0 deletions orchagent/fdborch.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class FdbOrch: public Orch, public Subject, public Observer
Table m_mclagFdbStateTable;
NotificationConsumer* m_flushNotificationsConsumer;
NotificationConsumer* m_fdbNotificationConsumer;
shared_ptr<DBConnector> m_notificationsDb;

void doTask(Consumer& consumer);
void doTask(NotificationConsumer& consumer);
Expand Down
4 changes: 2 additions & 2 deletions orchagent/mirrororch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ bool MirrorOrch::validateSrcPortList(const string& srcPortList)
vector<Port> portv;
int portCount = 0;
m_portsOrch->getLagMember(port, portv);
for (const auto p : portv)
for (const auto &p : portv)
{
if (checkPortExistsInSrcPortList(p.m_alias, srcPortList))
{
Expand Down Expand Up @@ -828,7 +828,7 @@ bool MirrorOrch::setUnsetPortMirror(Port port,
{
vector<Port> portv;
m_portsOrch->getLagMember(port, portv);
for (const auto p : portv)
for (const auto &p : portv)
{
if (p.m_type != Port::PHY)
{
Expand Down
2 changes: 1 addition & 1 deletion orchagent/neighorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ bool NeighOrch::addNextHop(const NextHopKey &nh)
next_hop_entry.nh_flags = 0;
m_syncdNextHops[nexthop] = next_hop_entry;

m_intfsOrch->increaseRouterIntfsRefCount(nexthop.alias);
m_intfsOrch->increaseRouterIntfsRefCount(nh.alias);

if (nexthop.isMplsNextHop())
{
Expand Down
2 changes: 1 addition & 1 deletion orchagent/orch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ set<string> Orch::generateIdListFromMap(unsigned long idsMap, sai_uint32_t maxId
{
unsigned long currentIdMask = 1;
bool started = false, needGenerateMap = false;
sai_uint32_t lower, upper;
sai_uint32_t lower = 0, upper = 0;
set<string> idStringList;
for (sai_uint32_t id = 0; id <= maxId; id ++)
{
Expand Down
10 changes: 8 additions & 2 deletions orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,15 @@ bool OrchDaemon::init()
TableConnector stateDbFdb(m_stateDb, STATE_FDB_TABLE_NAME);
TableConnector stateMclagDbFdb(m_stateDb, STATE_MCLAG_REMOTE_FDB_TABLE_NAME);
gFdbOrch = new FdbOrch(m_applDb, app_fdb_tables, stateDbFdb, stateMclagDbFdb, gPortsOrch);

TableConnector stateDbBfdSessionTable(m_stateDb, STATE_BFD_SESSION_TABLE_NAME);
gBfdOrch = new BfdOrch(m_applDb, APP_BFD_SESSION_TABLE_NAME, stateDbBfdSessionTable);

BgpGlobalStateOrch* bgp_global_state_orch;
bgp_global_state_orch = new BgpGlobalStateOrch(m_configDb, CFG_BGP_DEVICE_GLOBAL_TABLE_NAME);
gDirectory.set(bgp_global_state_orch);

gBfdOrch = new BfdOrch(m_applDb, APP_BFD_SESSION_TABLE_NAME, stateDbBfdSessionTable);
gDirectory.set(gBfdOrch);
static const vector<string> route_pattern_tables = {
CFG_FLOW_COUNTER_ROUTE_PATTERN_TABLE_NAME,
};
Expand Down Expand Up @@ -404,7 +410,7 @@ bool OrchDaemon::init()
* when iterating ConsumerMap. This is ensured implicitly by the order of keys in ordered map.
* For cases when Orch has to process tables in specific order, like PortsOrch during warm start, it has to override Orch::doTask()
*/
m_orchList = { gSwitchOrch, gCrmOrch, gPortsOrch, gBufferOrch, gFlowCounterRouteOrch, gIntfsOrch, gNeighOrch, gNhgMapOrch, gNhgOrch, gCbfNhgOrch, gRouteOrch, gCoppOrch, gQosOrch, wm_orch, gPolicerOrch, tunnel_decap_orch, sflow_orch, gDebugCounterOrch, gMacsecOrch, gBfdOrch, gSrv6Orch, mux_orch, mux_cb_orch, gMonitorOrch};
m_orchList = { gSwitchOrch, gCrmOrch, gPortsOrch, gBufferOrch, gFlowCounterRouteOrch, gIntfsOrch, gNeighOrch, gNhgMapOrch, gNhgOrch, gCbfNhgOrch, gRouteOrch, gCoppOrch, gQosOrch, wm_orch, gPolicerOrch, tunnel_decap_orch, sflow_orch, gDebugCounterOrch, gMacsecOrch, bgp_global_state_orch, gBfdOrch, gSrv6Orch, mux_orch, mux_cb_orch, gMonitorOrch};

bool initialize_dtel = false;
if (platform == BFN_PLATFORM_SUBSTRING || platform == VS_PLATFORM_SUBSTRING)
Expand Down
Loading

0 comments on commit 2139a2e

Please sign in to comment.