Skip to content

Commit

Permalink
ADD VOQ COUNTERS(SAI_SWITCH_STAT_PACKET_INTEGRITY_DROP, SAI_QUEUE_ST……
Browse files Browse the repository at this point in the history
…T_CREDIT_WD_DELETED_PACKETS) support for VOQ/Fabric switches (sonic-net#3152)

What I did
Added support for SAI_SWITCH_STAT_PACKET_INTEGRITY_DROP, SAI_QUEUE_STAT_CREDIT_WD_DELETED_PACKETS stats counters for VOQ and Fabric type switches.

Why I did it
To read the drop counters
  • Loading branch information
saksarav-nokia authored Jun 10, 2024
1 parent f497c4a commit 70eb766
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 2 deletions.
39 changes: 38 additions & 1 deletion orchagent/fabricportsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
#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 500
#define FABRIC_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 @@ -43,6 +47,7 @@ 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 @@ -63,6 +68,11 @@ 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),
Expand All @@ -86,6 +96,15 @@ FabricPortsOrch::FabricPortsOrch(DBConnector *appl_db, vector<table_name_with_pr
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));

// Create Switch level drop counters for voq & fabric switch.
if ((gMySwitchType == "voq") || (gMySwitchType == "fabric"))
{
auto timer = ((gMySwitchType == "voq") ? SWITCH_DEBUG_COUNTER_POLLING_INTERVAL_MS : FABRIC_SWITCH_DEBUG_COUNTER_POLLING_INTERVAL_MS);
switch_drop_counter_manager = new FlexCounterManager(SWITCH_DEBUG_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ,
timer, 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));
m_applMonitorConstTable = unique_ptr<Table>(new Table(m_appl_db.get(), APP_FABRIC_MONITOR_DATA_TABLE_NAME));
Expand Down Expand Up @@ -1461,7 +1480,11 @@ void FabricPortsOrch::doTask(swss::SelectableTimer &timer)
{
updateFabricPortState();
}

if (((gMySwitchType == "voq") || (gMySwitchType == "fabric")) && (!m_isSwitchStatsGenerated))
{
createSwitchDropCounters();
m_isSwitchStatsGenerated = true;
}
if (checkFabricPortMonState() && !m_debugTimerEnabled)
{
m_debugTimer->start();
Expand Down Expand Up @@ -1496,3 +1519,17 @@ void FabricPortsOrch::doTask(swss::SelectableTimer &timer)
}
}
}

void FabricPortsOrch::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);
}
4 changes: 4 additions & 0 deletions orchagent/fabricportsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ class FabricPortsOrch : public Orch, public Subject
unique_ptr<Table> m_fabricCapacityTable;
unique_ptr<Table> m_applMonitorConstTable;
unique_ptr<ProducerTable> m_flexCounterTable;
shared_ptr<Table> m_counterNameToSwitchStatMap;

swss::SelectableTimer *m_timer = nullptr;
swss::SelectableTimer *m_debugTimer = nullptr;

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

sai_uint32_t m_fabricPortCount;
map<int, sai_object_id_t> m_fabricLanePortMap;
Expand All @@ -52,6 +54,7 @@ class FabricPortsOrch : public Orch, public Subject
bool m_getFabricPortListDone = false;
bool m_isQueueStatsGenerated = false;
bool m_debugTimerEnabled = false;
bool m_isSwitchStatsGenerated = false;

string m_defaultPollWithErrors = "0";
string m_defaultPollWithNoErrors = "8";
Expand All @@ -68,6 +71,7 @@ class FabricPortsOrch : public Orch, public Subject
void updateFabricCapacity();
bool checkFabricPortMonState();
void updateFabricRate();
void createSwitchDropCounters();

void doTask() override;
void doTask(Consumer &consumer);
Expand Down
1 change: 1 addition & 0 deletions orchagent/port/port_capabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extern "C" {
#include <saiobject.h>
#include <saitypes.h>
#include <saiport.h>
#include <saiqueue.h>
}

class PortCapabilities final
Expand Down
9 changes: 9 additions & 0 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ static const vector<sai_queue_stat_t> queue_stat_ids =
SAI_QUEUE_STAT_DROPPED_PACKETS,
SAI_QUEUE_STAT_DROPPED_BYTES,
};
static const vector<sai_queue_stat_t> voq_stat_ids =
{
SAI_QUEUE_STAT_CREDIT_WD_DELETED_PACKETS
};


static const vector<sai_queue_stat_t> queueWatermarkStatIds =
{
Expand Down Expand Up @@ -7415,6 +7420,10 @@ void PortsOrch::addQueueFlexCountersPerPortPerQueueIndex(const Port& port, size_
}
if (voq)
{
for (const auto& voq_it: voq_stat_ids)
{
counter_stats.emplace(sai_serialize_queue_stat(voq_it));
}
queue_ids = m_port_voq_ids[port.m_alias];
}
else
Expand Down
46 changes: 45 additions & 1 deletion tests/test_virtual_chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,51 @@ def test_remote_port_down(self, vct):
# Cleanup inband if configuration
self.del_inbandif_port(vct, inband_port)


def test_voq_drop_counters(self, vct):
"""Test VOQ switch drop counters.
This test validates VOQ Switch counters for Voq/fabric switches - packet integrity counters
"""

if vct is None:
return

dvss = vct.dvss
for name in dvss.keys():
dvs = dvss[name]
# Get the config info
config_db = dvs.get_config_db()
metatbl = config_db.get_entry("DEVICE_METADATA", "localhost")

cfg_switch_type = metatbl.get("switch_type")

# Test only for voq or fabric
if cfg_switch_type == "voq" or cfg_switch_type == "fabric":
print("VOQ drop counters test for {}".format(name))

# Verify that a counter has been created FLEX_COUNTER_DB and COUNTERS_DB. We will verify the state of
# the counter in the next step.
flex_db = dvs.get_flex_db()
keys = flex_db.get_keys("FLEX_COUNTER_TABLE")
assert len(keys), "No FLEX_COUNTER_TABLE in FLEX_COUNTER_DB"
for key in keys:
if "SWITCH_DEBUG_COUNTER" in key:
drop_entry = flex_db.get_entry("FLEX_COUNTER_TABLE", key)
value = drop_entry.get("SWITCH_DEBUG_COUNTER_ID_LIST")
assert value == "SAI_SWITCH_STAT_PACKET_INTEGRITY_DROP", "Got error in getting Voq Switch Drop counter from FLEX_COUNTER_DB"

cntr_db = dvs.get_counters_db()
stat_name_entry = cntr_db.get_entry("COUNTERS_DEBUG_NAME_SWITCH_STAT_MAP", "")
value = stat_name_entry.get("SWITCH_STD_DROP_COUNTER-SAI_SWITCH_STAT_PACKET_INTEGRITY_DROP")
assert value == "SAI_SWITCH_STAT_PACKET_INTEGRITY_DROP", "Got error in getting Voq Switch Drop counter name map from COUNTERS_DB"

asic_db = dvs.get_asic_db()
keys = asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_SWITCH")
switch_oid_key = keys[0]
stat_entry = cntr_db.get_entry("COUNTERS", switch_oid_key)
value = stat_entry.get("SAI_SWITCH_STAT_PACKET_INTEGRITY_DROP")
assert value == "0", "SAI_SWITCH_STAT_PACKET_INTEGRITY_DROP is non zero in COUNTERS_DB"

# Add Dummy always-pass test at end as workaroud
# for issue when Flaky fail on final test it invokes module tear-down before retrying
def test_nonflaky_dummy():
Expand Down

0 comments on commit 70eb766

Please sign in to comment.