Skip to content

Commit

Permalink
Move the Switch Level drop counter to switchorch for voq switches
Browse files Browse the repository at this point in the history
Signed-off-by: saksarav <[email protected]>
  • Loading branch information
saksarav-nokia committed May 31, 2024
1 parent cd2dc3c commit 62e7b8d
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 25 deletions.
49 changes: 28 additions & 21 deletions orchagent/fabricportsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
#define FABRIC_PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS 10000
#define FABRIC_QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP "FABRIC_QUEUE_STAT_COUNTER"
#define FABRIC_QUEUE_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS 100000
#define SWITCH_DEBUG_COUNTER_FLEX_COUNTER_GROUP "SWITCH_DEBUG_COUNTER"
#define SWITCH_DEBUG_COUNTER_POLLING_INTERVAL_MS 100000
#define FABRIC_DEBUG_POLLING_INTERVAL_DEFAULT (60)
#define FABRIC_MONITOR_DATA "FABRIC_MONITOR_DATA"
#define APPL_FABRIC_PORT_PREFIX "Fabric"
#define SWITCH_DEBUG_COUNTER_FLEX_COUNTER_GROUP "SWITCH_DEBUG_COUNTER"
#define SWITCH_DEBUG_COUNTER_POLLING_INTERVAL_MS 60000
#define SWITCH_STANDARD_DROP_COUNTERS "SWITCH_STD_DROP_COUNTER-"

// constants for link monitoring
#define MAX_SKIP_CRCERR_ON_LNKUP_POLLS 20
Expand All @@ -41,15 +42,11 @@
#define ERROR_RATE_RX_CELLS_CFG 61035156
#define FABRIC_LINK_RATE 44316

const vector<sai_switch_stat_t> switch_voq_counter_ids =
{
SAI_SWITCH_STAT_PACKET_INTEGRITY_DROP
};

extern sai_object_id_t gSwitchId;
extern sai_switch_api_t *sai_switch_api;
extern sai_port_api_t *sai_port_api;
extern sai_queue_api_t *sai_queue_api;
extern string gMySwitchType;

const vector<sai_port_stat_t> port_stat_ids =
{
Expand All @@ -70,15 +67,18 @@ static const vector<sai_queue_stat_t> queue_stat_ids =
SAI_QUEUE_STAT_CURR_OCCUPANCY_LEVEL,
};

const vector<sai_switch_stat_t> switch_drop_counter_ids =
{
SAI_SWITCH_STAT_PACKET_INTEGRITY_DROP
};

FabricPortsOrch::FabricPortsOrch(DBConnector *appl_db, vector<table_name_with_pri_t> &tableNames,
bool fabricPortStatEnabled, bool fabricQueueStatEnabled) :
Orch(appl_db, tableNames),
port_stat_manager(FABRIC_PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ,
FABRIC_PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true),
queue_stat_manager(FABRIC_QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ,
FABRIC_QUEUE_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true),
switch_drop_counter_manager(SWITCH_DEBUG_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ,
SWITCH_DEBUG_COUNTER_POLLING_INTERVAL_MS, true),
m_timer(new SelectableTimer(timespec { .tv_sec = FABRIC_POLLING_INTERVAL_DEFAULT, .tv_nsec = 0 })),
m_debugTimer(new SelectableTimer(timespec { .tv_sec = FABRIC_DEBUG_POLLING_INTERVAL_DEFAULT, .tv_nsec = 0 }))
{
Expand All @@ -94,7 +94,14 @@ FabricPortsOrch::FabricPortsOrch(DBConnector *appl_db, vector<table_name_with_pr
m_portNameQueueCounterTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_FABRIC_QUEUE_NAME_MAP));
m_portNamePortCounterTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_FABRIC_PORT_NAME_MAP));
m_fabricCounterTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_TABLE));
m_counterNameToSwitchStatMap = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_DEBUG_NAME_SWITCH_STAT_MAP));

// Create Switch level drop counters for fabric switch. switchorch adds for other switch types
if (gMySwitchType == "fabric")
{
switch_drop_counter_manager = new FlexCounterManager(SWITCH_DEBUG_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ,
SWITCH_DEBUG_COUNTER_POLLING_INTERVAL_MS, true);
m_counterNameToSwitchStatMap = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_DEBUG_NAME_SWITCH_STAT_MAP));
}

m_appl_db = shared_ptr<DBConnector>(new DBConnector("APPL_DB", 0));
m_applTable = unique_ptr<Table>(new Table(m_appl_db.get(), APP_FABRIC_MONITOR_PORT_TABLE_NAME));
Expand Down Expand Up @@ -1514,24 +1521,24 @@ void FabricPortsOrch::doTask(swss::SelectableTimer &timer)
updateFabricCapacity();
updateFabricRate();
}
if (!m_isSwitchStatsGenerated)
if ((gMySwitchType == "fabric") && (!m_isSwitchStatsGenerated))
{
createSwitchVoqCounters();
createSwitchDropCounters();
m_isSwitchStatsGenerated = true;
}
}
}

void FabricPortsOrch::createSwitchVoqCounters(void)
void FabricPortsOrch::createSwitchDropCounters(void)
{
std::unordered_set<std::string> counter_stats;
for (const auto& it: switch_voq_counter_ids)
for (const auto& it: switch_drop_counter_ids)
{
counter_stats.emplace(sai_serialize_switch_stat(it));
std::string drop_stats = sai_serialize_switch_stat(it);
counter_stats.emplace(drop_stats);
vector<FieldValueTuple> switchNameSwitchCounterMap;
switchNameSwitchCounterMap.emplace_back((SWITCH_STANDARD_DROP_COUNTERS + drop_stats), drop_stats);
m_counterNameToSwitchStatMap->set("", switchNameSwitchCounterMap);
}
switch_drop_counter_manager.setCounterIdList(gSwitchId, CounterType::SWITCH_DEBUG, counter_stats);

vector<FieldValueTuple> switchNameSwitchCounterMap;
switchNameSwitchCounterMap.emplace_back("SWITCH_ID", sai_serialize_object_id(gSwitchId));
m_counterNameToSwitchStatMap->set("", switchNameSwitchCounterMap);
m_isSwitchStatsGenerated = true;
switch_drop_counter_manager->setCounterIdList(gSwitchId, CounterType::SWITCH_DEBUG, counter_stats);
}
4 changes: 2 additions & 2 deletions orchagent/fabricportsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class FabricPortsOrch : public Orch, public Subject
bool fabricPortStatEnabled=true, bool fabricQueueStatEnabled=true);
bool allPortsReady();
void generateQueueStats();
void createSwitchVoqCounters(void);

private:
bool m_fabricPortStatEnabled;
Expand All @@ -44,7 +43,7 @@ class FabricPortsOrch : public Orch, public Subject

FlexCounterManager port_stat_manager;
FlexCounterManager queue_stat_manager;
FlexCounterManager switch_drop_counter_manager;
FlexCounterManager *switch_drop_counter_manager = nullptr;

sai_uint32_t m_fabricPortCount;
map<int, sai_object_id_t> m_fabricLanePortMap;
Expand All @@ -71,6 +70,7 @@ class FabricPortsOrch : public Orch, public Subject
void updateFabricCapacity();
bool checkFabricPortMonState();
void updateFabricRate();
void createSwitchDropCounters();

void doTask() override;
void doTask(Consumer &consumer);
Expand Down
42 changes: 40 additions & 2 deletions orchagent/switchorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extern MacAddress gVxlanMacAddress;
extern CrmOrch *gCrmOrch;
extern event_handle_t g_events_handle;
extern string gMyAsicName;
extern string gMySwitchType;

const map<string, sai_switch_attr_t> switch_attribute_map =
{
Expand Down Expand Up @@ -92,6 +93,10 @@ const std::set<sai_switch_asic_sdk_health_category_t> switch_asic_sdk_health_eve
SAI_SWITCH_ASIC_SDK_HEALTH_CATEGORY_CPU_HW,
SAI_SWITCH_ASIC_SDK_HEALTH_CATEGORY_ASIC_HW
};
const vector<sai_switch_stat_t> switch_drop_counter_ids =
{
SAI_SWITCH_STAT_PACKET_INTEGRITY_DROP
};

const std::set<std::string> switch_non_sai_attribute_set = {"ordered_ecmp"};

Expand Down Expand Up @@ -124,7 +129,11 @@ SwitchOrch::SwitchOrch(DBConnector *db, vector<TableConnector>& connectors, Tabl
m_asicSensorsTable(new Table(m_stateDb.get(), ASIC_TEMPERATURE_INFO_TABLE_NAME)),
m_sensorsPollerTimer (new SelectableTimer((timespec { .tv_sec = DEFAULT_ASIC_SENSORS_POLLER_INTERVAL, .tv_nsec = 0 }))),
m_stateDbForNotification(new DBConnector(STATE_DB, DBConnector::DEFAULT_UNIXSOCKET, 0)),
m_asicSdkHealthEventTable(new Table(m_stateDbForNotification.get(), STATE_ASIC_SDK_HEALTH_EVENT_TABLE_NAME))
m_asicSdkHealthEventTable(new Table(m_stateDbForNotification.get(), STATE_ASIC_SDK_HEALTH_EVENT_TABLE_NAME)),
switch_drop_counter_manager(SWITCH_DEBUG_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ,
SWITCH_DEBUG_COUNTER_POLLING_INTERVAL_MS, true),
m_switchDropCntrPollEnableTimer (new SelectableTimer((timespec { .tv_sec = DEFAULT_SWITCH_DROP_COUNTER_POLL_ENABLE_TIMER_INTERVAL,
.tv_nsec = 0 })))
{
m_restartCheckNotificationConsumer = new NotificationConsumer(db, "RESTARTCHECK");
auto restartCheckNotifier = new Notifier(m_restartCheckNotificationConsumer, this, "RESTARTCHECK");
Expand All @@ -139,6 +148,16 @@ SwitchOrch::SwitchOrch(DBConnector *db, vector<TableConnector>& connectors, Tabl

auto executorT = new ExecutableTimer(m_sensorsPollerTimer, this, "ASIC_SENSORS_POLL_TIMER");
Orch::addExecutor(executorT);

// Add Switch level drop counters to FLEX_COUNTER_DB only for VOQ switch type since it is supported by only VOQ/fabric switches now.
if(gMySwitchType == "voq")
{
m_counter_db = shared_ptr<DBConnector>(new DBConnector("COUNTERS_DB", 0));
m_counterNameToSwitchStatMap = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_DEBUG_NAME_SWITCH_STAT_MAP));
auto executorSwitchT = new ExecutableTimer(m_switchDropCntrPollEnableTimer, this, "SWITCH_DROP_COUNTER_TIMER");
Orch::addExecutor(executorSwitchT);
m_switchDropCntrPollEnableTimer->start();
}
}

void SwitchOrch::initAsicSdkHealthEventNotification()
Expand Down Expand Up @@ -1297,7 +1316,12 @@ void SwitchOrch::doTask(SelectableTimer &timer)
SWSS_LOG_INFO("Eliminate ASIC/SDK health %s", str.c_str());
}
}
}
else if (&timer == m_switchDropCntrPollEnableTimer)
{
createSwitchDropCounters();
m_switchDropCntrPollEnableTimer->stop();
}
}

void SwitchOrch::initSensorsTable()
{
Expand Down Expand Up @@ -1515,3 +1539,17 @@ bool SwitchOrch::querySwitchCapability(sai_object_type_t sai_object, sai_attr_id
}
}
}

void SwitchOrch::createSwitchDropCounters(void)
{
std::unordered_set<std::string> counter_stats;
for (const auto& it: switch_drop_counter_ids)
{
std::string drop_stats = sai_serialize_switch_stat(it);
counter_stats.emplace(drop_stats);
vector<FieldValueTuple> switchNameSwitchCounterMap;
switchNameSwitchCounterMap.emplace_back((SWITCH_STANDARD_DROP_COUNTERS + drop_stats), drop_stats);
m_counterNameToSwitchStatMap->set("", switchNameSwitchCounterMap);
}
switch_drop_counter_manager.setCounterIdList(gSwitchId, CounterType::SWITCH_DEBUG, counter_stats);
}
12 changes: 12 additions & 0 deletions orchagent/switchorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
#include "timer.h"
#include "switch/switch_capabilities.h"
#include "switch/switch_helper.h"
#include "flex_counter_manager.h"

#define DEFAULT_ASIC_SENSORS_POLLER_INTERVAL 60
#define ASIC_SENSORS_POLLER_STATUS "ASIC_SENSORS_POLLER_STATUS"
#define ASIC_SENSORS_POLLER_INTERVAL "ASIC_SENSORS_POLLER_INTERVAL"

#define DEFAULT_SWITCH_DROP_COUNTER_POLL_ENABLE_TIMER_INTERVAL 180
#define SWITCH_DEBUG_COUNTER_FLEX_COUNTER_GROUP "SWITCH_DEBUG_COUNTER"
#define SWITCH_STANDARD_DROP_COUNTERS "SWITCH_STD_DROP_COUNTER-"
#define SWITCH_DEBUG_COUNTER_POLLING_INTERVAL_MS 60000

#define SWITCH_CAPABILITY_TABLE_PORT_TPID_CAPABLE "PORT_TPID_CAPABLE"
#define SWITCH_CAPABILITY_TABLE_LAG_TPID_CAPABLE "LAG_TPID_CAPABLE"
#define SWITCH_CAPABILITY_TABLE_ORDERED_ECMP_CAPABLE "ORDERED_ECMP_CAPABLE"
Expand Down Expand Up @@ -75,6 +81,7 @@ class SwitchOrch : public Orch
void initSensorsTable();
void querySwitchTpidCapability();
void querySwitchPortEgressSampleCapability();
void createSwitchDropCounters(void);

// Switch hash
bool setSwitchHashFieldListSai(const SwitchHash &hash, bool isEcmpHash) const;
Expand Down Expand Up @@ -110,6 +117,11 @@ class SwitchOrch : public Orch
std::shared_ptr<swss::DBConnector> m_stateDb = nullptr;
std::shared_ptr<swss::Table> m_asicSensorsTable= nullptr;
swss::SelectableTimer* m_sensorsPollerTimer = nullptr;
std::shared_ptr<swss::DBConnector> m_counter_db;
FlexCounterManager switch_drop_counter_manager;
std::shared_ptr<swss::Table> m_counterNameToSwitchStatMap;
swss::SelectableTimer* m_switchDropCntrPollEnableTimer = nullptr;

bool m_sensorsPollerEnabled = false;
time_t m_sensorsPollerInterval = DEFAULT_ASIC_SENSORS_POLLER_INTERVAL;
bool m_sensorsPollerIntervalChanged = false;
Expand Down

0 comments on commit 62e7b8d

Please sign in to comment.