Skip to content

Commit

Permalink
Adding sonic-net#1170 patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Kavin Kamaraj authored and kktheballer committed Jul 20, 2021
1 parent 33f370f commit d911d41
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 68 deletions.
2 changes: 1 addition & 1 deletion cfgmgr/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
INCLUDES = -I $(top_srcdir) -I $(top_srcdir)/orchagent -I $(top_srcdir)/warmrestart
INCLUDES = -I $(top_srcdir) -I $(top_srcdir)/orchagent -I $(top_srcdir)/warmrestart -I $(top_srcdir)/orchagent/flex_counter
CFLAGS_SAI = -I /usr/include/sai
LIBNL_CFLAGS = -I/usr/include/libnl3
LIBNL_LIBS = -lnl-genl-3 -lnl-route-3 -lnl-3
Expand Down
3 changes: 1 addition & 2 deletions orchagent/debugcounterorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static const unordered_map<string, CounterType> flex_counter_type_lookup = {
// object should only be initialized once.
DebugCounterOrch::DebugCounterOrch(DBConnector *db, const vector<string>& table_names, int poll_interval) :
Orch(db, table_names),
flex_counter_manager(DEBUG_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, poll_interval),
flex_counter_manager(DEBUG_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, poll_interval, true),
m_stateDb(new DBConnector("STATE_DB", 0)),
m_debugCapabilitiesTable(new Table(m_stateDb.get(), STATE_DEBUG_COUNTER_CAPABILITIES_NAME)),
m_countersDb(new DBConnector("COUNTERS_DB", 0)),
Expand All @@ -34,7 +34,6 @@ DebugCounterOrch::DebugCounterOrch(DBConnector *db, const vector<string>& table_
{
SWSS_LOG_ENTER();
publishDropCounterCapabilities();
flex_counter_manager.enableFlexCounterGroup();
}

DebugCounterOrch::~DebugCounterOrch(void)
Expand Down
10 changes: 7 additions & 3 deletions orchagent/flex_counter/flex_counter_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@ const unordered_map<CounterType, string> FlexCounterManager::counter_id_field_lo
{
{ CounterType::PORT_DEBUG, PORT_DEBUG_COUNTER_ID_LIST },
{ CounterType::SWITCH_DEBUG, SWITCH_DEBUG_COUNTER_ID_LIST },
{ CounterType::PORT, PORT_COUNTER_ID_LIST },
{ CounterType::QUEUE, QUEUE_COUNTER_ID_LIST }
};

// This constructor will create a group that is disabled by default.
FlexCounterManager::FlexCounterManager(
const string& group_name,
const StatsMode stats_mode,
const uint polling_interval) :
const uint polling_interval,
const bool enabled) :
group_name(group_name),
stats_mode(stats_mode),
polling_interval(polling_interval),
enabled(false),
enabled(enabled),
flex_counter_db(new DBConnector("FLEX_COUNTER_DB", 0)),
flex_counter_group_table(new ProducerTable(flex_counter_db.get(), FLEX_COUNTER_GROUP_TABLE)),
flex_counter_table(new ProducerTable(flex_counter_db.get(), FLEX_COUNTER_TABLE))
Expand Down Expand Up @@ -72,6 +74,8 @@ FlexCounterManager::~FlexCounterManager()

void FlexCounterManager::applyGroupConfiguration()
{
SWSS_LOG_ENTER();

vector<FieldValueTuple> field_values =
{
FieldValueTuple(STATS_MODE_FIELD, stats_mode_lookup.at(stats_mode)),
Expand Down
5 changes: 4 additions & 1 deletion orchagent/flex_counter/flex_counter_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ enum class StatsMode

enum class CounterType
{
PORT,
QUEUE,
PORT_DEBUG,
SWITCH_DEBUG
};
Expand All @@ -33,7 +35,8 @@ class FlexCounterManager
FlexCounterManager(
const std::string& group_name,
const StatsMode stats_mode,
const uint polling_interval);
const uint polling_interval,
const bool enabled);

FlexCounterManager(const FlexCounterManager&) = delete;
FlexCounterManager& operator=(const FlexCounterManager&) = delete;
Expand Down
5 changes: 3 additions & 2 deletions orchagent/flex_counter/flex_counter_stat_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ using swss::FieldValueTuple;
FlexCounterStatManager::FlexCounterStatManager(
const string& group_name,
const StatsMode stats_mode,
const int polling_interval) :
FlexCounterManager(group_name, stats_mode, polling_interval)
const int polling_interval,
const bool enabled) :
FlexCounterManager(group_name, stats_mode, polling_interval, enabled)
{
SWSS_LOG_ENTER();
}
Expand Down
3 changes: 2 additions & 1 deletion orchagent/flex_counter/flex_counter_stat_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class FlexCounterStatManager : public FlexCounterManager
FlexCounterStatManager(
const std::string& group_name,
const StatsMode stats_mode,
const int polling_interval);
const int polling_interval,
const bool enabled);

FlexCounterStatManager(const FlexCounterStatManager&) = delete;
FlexCounterStatManager& operator=(const FlexCounterStatManager&) = delete;
Expand Down
178 changes: 120 additions & 58 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <algorithm>
#include <tuple>
#include <sstream>
#include <unordered_set>

#include <netinet/if_ether.h>
#include "net/if.h"
Expand Down Expand Up @@ -48,6 +49,9 @@ extern FdbOrch *gFdbOrch;
#define QUEUE_FLEX_STAT_COUNTER_POLL_MSECS "10000"
#define QUEUE_WATERMARK_FLEX_STAT_COUNTER_POLL_MSECS "10000"
#define PG_WATERMARK_FLEX_STAT_COUNTER_POLL_MSECS "10000"
#define PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS 1000
#define QUEUE_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS 10000



static map<string, sai_port_fec_mode_t> fec_mode_map =
Expand All @@ -73,6 +77,50 @@ static map<string, sai_bridge_port_fdb_learning_mode_t> learn_mode_map =
{ "notification", SAI_BRIDGE_PORT_FDB_LEARNING_MODE_FDB_NOTIFICATION}
};

const vector<sai_port_stat_t> port_stat_ids =
{
SAI_PORT_STAT_IF_IN_OCTETS,
SAI_PORT_STAT_IF_IN_UCAST_PKTS,
SAI_PORT_STAT_IF_IN_NON_UCAST_PKTS,
SAI_PORT_STAT_IF_IN_DISCARDS,
SAI_PORT_STAT_IF_IN_ERRORS,
SAI_PORT_STAT_IF_IN_UNKNOWN_PROTOS,
SAI_PORT_STAT_IF_OUT_OCTETS,
SAI_PORT_STAT_IF_OUT_UCAST_PKTS,
SAI_PORT_STAT_IF_OUT_NON_UCAST_PKTS,
SAI_PORT_STAT_IF_OUT_DISCARDS,
SAI_PORT_STAT_IF_OUT_ERRORS,
SAI_PORT_STAT_IF_OUT_QLEN,
SAI_PORT_STAT_IF_IN_MULTICAST_PKTS,
SAI_PORT_STAT_IF_IN_BROADCAST_PKTS,
SAI_PORT_STAT_IF_OUT_MULTICAST_PKTS,
SAI_PORT_STAT_IF_OUT_BROADCAST_PKTS,
SAI_PORT_STAT_ETHER_RX_OVERSIZE_PKTS,
SAI_PORT_STAT_ETHER_TX_OVERSIZE_PKTS,
SAI_PORT_STAT_PFC_0_TX_PKTS,
SAI_PORT_STAT_PFC_1_TX_PKTS,
SAI_PORT_STAT_PFC_2_TX_PKTS,
SAI_PORT_STAT_PFC_3_TX_PKTS,
SAI_PORT_STAT_PFC_4_TX_PKTS,
SAI_PORT_STAT_PFC_5_TX_PKTS,
SAI_PORT_STAT_PFC_6_TX_PKTS,
SAI_PORT_STAT_PFC_7_TX_PKTS,
SAI_PORT_STAT_PFC_0_RX_PKTS,
SAI_PORT_STAT_PFC_1_RX_PKTS,
SAI_PORT_STAT_PFC_2_RX_PKTS,
SAI_PORT_STAT_PFC_3_RX_PKTS,
SAI_PORT_STAT_PFC_4_RX_PKTS,
SAI_PORT_STAT_PFC_5_RX_PKTS,
SAI_PORT_STAT_PFC_6_RX_PKTS,
SAI_PORT_STAT_PFC_7_RX_PKTS,
SAI_PORT_STAT_PAUSE_RX_PKTS,
SAI_PORT_STAT_PAUSE_TX_PKTS,
SAI_PORT_STAT_ETHER_STATS_TX_NO_ERRORS,
SAI_PORT_STAT_IP_IN_UCAST_PKTS,
SAI_PORT_STAT_ETHER_IN_PKTS_128_TO_255_OCTETS,
};

//in any case
const vector<sai_port_stat_t> portStatIds =
{
SAI_PORT_STAT_IF_IN_OCTETS,
Expand Down Expand Up @@ -116,12 +164,22 @@ const vector<sai_port_stat_t> portStatIds =
SAI_PORT_STAT_ETHER_IN_PKTS_128_TO_255_OCTETS,
};


static const vector<sai_port_stat_t> port_buffer_drop_stat_ids =
{
SAI_PORT_STAT_IN_DROPPED_PKTS,
SAI_PORT_STAT_OUT_DROPPED_PKTS
};


static const vector<sai_queue_stat_t> queue_stat_ids =
{
SAI_QUEUE_STAT_PACKETS,
SAI_QUEUE_STAT_BYTES,
SAI_QUEUE_STAT_DROPPED_PACKETS,
SAI_QUEUE_STAT_DROPPED_BYTES,
};

static const vector<sai_queue_stat_t> queueStatIds =
{
SAI_QUEUE_STAT_PACKETS,
Expand Down Expand Up @@ -160,7 +218,9 @@ static char* hostif_vlan_tag[] = {
* default VLAN and all ports removed from .1Q bridge.
*/
PortsOrch::PortsOrch(DBConnector *db, vector<table_name_with_pri_t> &tableNames) :
Orch(db, tableNames)
Orch(db, tableNames),
port_stat_manager(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true),
queue_stat_manager(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, QUEUE_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true)
{
SWSS_LOG_ENTER();

Expand Down Expand Up @@ -192,20 +252,21 @@ PortsOrch::PortsOrch(DBConnector *db, vector<table_name_with_pri_t> &tableNames)
m_flexCounterTable = unique_ptr<ProducerTable>(new ProducerTable(m_flex_db.get(), FLEX_COUNTER_TABLE));
m_flexCounterGroupTable = unique_ptr<ProducerTable>(new ProducerTable(m_flex_db.get(), FLEX_COUNTER_GROUP_TABLE));

vector<FieldValueTuple> fields;
fields.emplace_back(POLL_INTERVAL_FIELD, PORT_FLEX_STAT_COUNTER_POLL_MSECS);
fields.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ);
m_flexCounterGroupTable->set(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, fields);
//NOTE: master 1170 commit does not have the below lines.
//vector<FieldValueTuple> fields;
//fields.emplace_back(POLL_INTERVAL_FIELD, PORT_FLEX_STAT_COUNTER_POLL_MSECS);
//fields.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ);
//m_flexCounterGroupTable->set(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, fields);

fields.clear();
fields.emplace_back(POLL_INTERVAL_FIELD, PORT_BUFFER_DROP_STAT_POLLING_INTERVAL_MS);
fields.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ);
m_flexCounterGroupTable->set(PORT_DROP_STAT_COUNTER_FLEX_COUNTER_GROUP, fields);
//fields.clear();
//fields.emplace_back(POLL_INTERVAL_FIELD, PORT_BUFFER_DROP_STAT_POLLING_INTERVAL_MS);
//fields.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ);
//m_flexCounterGroupTable->set(PORT_DROP_STAT_COUNTER_FLEX_COUNTER_GROUP, fields);

fields.clear();
fields.emplace_back(POLL_INTERVAL_FIELD, QUEUE_FLEX_STAT_COUNTER_POLL_MSECS);
fields.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ);
m_flexCounterGroupTable->set(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP, fields);
//fields.clear();
//fields.emplace_back(POLL_INTERVAL_FIELD, QUEUE_FLEX_STAT_COUNTER_POLL_MSECS);
//fields.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ);
//m_flexCounterGroupTable->set(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP, fields);

string queueWmSha, pgWmSha;
string queueWmPluginName = "watermark_queue.lua";
Expand Down Expand Up @@ -1543,20 +1604,22 @@ bool PortsOrch::removePort(sai_object_id_t port_id)
return true;
}

string PortsOrch::getPortFlexCounterTableKey(string key)
{
return string(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP) + ":" + key;
}

//NOTE: commenting out below because 1170 master did this...
//string PortsOrch::getPortFlexCounterTableKey(string key)
//{
// return string(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP) + ":" + key;
//}

string PortsOrch::getPortBuffDropFlexCounterTableKey(string key)
{
return string(PORT_DROP_STAT_COUNTER_FLEX_COUNTER_GROUP) + ":" + key;
}

string PortsOrch::getQueueFlexCounterTableKey(string key)
{
return string(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP) + ":" + key;
}
//string PortsOrch::getQueueFlexCounterTableKey(string key)
//{
// return string(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP) + ":" + key;
//}

string PortsOrch::getQueueWatermarkFlexCounterTableKey(string key)
{
Expand Down Expand Up @@ -1602,32 +1665,39 @@ bool PortsOrch::initPort(const string &alias, const set<int> &lane_set)
m_counterTable->set("", fields);

/* Add port to flex_counter for updating stat counters */
string key = getPortFlexCounterTableKey(sai_serialize_object_id(p.m_port_id));
std::string delimiter = "";
std::ostringstream counters_stream;
for (const auto &id: portStatIds)
//string key = getPortFlexCounterTableKey(sai_serialize_object_id(p.m_port_id));
//std::string delimiter = "";
//std::ostringstream counters_stream;
//for (const auto &id: portStatIds)
//{
// counters_stream << delimiter << sai_serialize_port_stat(id);
// delimiter = comma;
//}

std::unordered_set<std::string> counter_stats;
for (const auto& it: port_stat_ids)
{
counters_stream << delimiter << sai_serialize_port_stat(id);
delimiter = comma;
counter_stats.emplace(sai_serialize_port_stat(it));
}
port_stat_manager.setCounterIdList(p.m_port_id, CounterType::PORT, counter_stats);

fields.clear();
fields.emplace_back(PORT_COUNTER_ID_LIST, counters_stream.str());
//fields.clear();
//fields.emplace_back(PORT_COUNTER_ID_LIST, counters_stream.str());

m_flexCounterTable->set(key, fields);
//m_flexCounterTable->set(key, fields);

delimiter = "";
string port_drop_key = getPortBuffDropFlexCounterTableKey(sai_serialize_object_id(p.m_port_id));
std::ostringstream port_buffer_drop_stream;
for (const auto& it: port_buffer_drop_stat_ids)
{
port_buffer_drop_stream << delimiter << sai_serialize_port_stat(it);
delimiter = comma;
}
//delimiter = "";
//string port_drop_key = getPortBuffDropFlexCounterTableKey(sai_serialize_object_id(p.m_port_id));
//std::ostringstream port_buffer_drop_stream;
//for (const auto& it: port_buffer_drop_stat_ids)
//{
// port_buffer_drop_stream << delimiter << sai_serialize_port_stat(it);
// delimiter = comma;
//}

fields.clear();
fields.emplace_back(PORT_COUNTER_ID_LIST, port_buffer_drop_stream.str());
m_flexCounterTable->set(port_drop_key, fields);
//fields.clear();
//fields.emplace_back(PORT_COUNTER_ID_LIST, port_buffer_drop_stream.str());
//m_flexCounterTable->set(port_drop_key, fields);

PortUpdate update = {p, true };
notify(SUBJECT_TYPE_PORT_CHANGE, static_cast<void *>(&update));
Expand Down Expand Up @@ -3630,34 +3700,26 @@ void PortsOrch::generateQueueMapPerPort(const Port& port)
queueIndexVector.emplace_back(id, to_string(queueRealIndex));
}

/* add ordinary Queue stat counters */
string key = getQueueFlexCounterTableKey(id);

std::string delimiter = "";
std::ostringstream counters_stream;
for (const auto& it: queueStatIds)
// Install a flex counter for this queue to track stats
std::unordered_set<string> counter_stats;
for (const auto& it: queue_stat_ids)
{
counters_stream << delimiter << sai_serialize_queue_stat(it);
delimiter = comma;
counter_stats.emplace(sai_serialize_queue_stat(it));
}

vector<FieldValueTuple> fieldValues;
fieldValues.emplace_back(QUEUE_COUNTER_ID_LIST, counters_stream.str());

m_flexCounterTable->set(key, fieldValues);
queue_stat_manager.setCounterIdList(port.m_queue_ids[queueIndex], CounterType::QUEUE, counter_stats);

/* add watermark queue counters */
key = getQueueWatermarkFlexCounterTableKey(id);
string key = getQueueWatermarkFlexCounterTableKey(id);

delimiter = "";
counters_stream.str("");
string delimiter("");
std::ostringstream counters_stream;
for (const auto& it: queueWatermarkStatIds)
{
counters_stream << delimiter << sai_serialize_queue_stat(it);
delimiter = comma;
}

fieldValues.clear();
vector<FieldValueTuple> fieldValues;
fieldValues.emplace_back(QUEUE_COUNTER_ID_LIST, counters_stream.str());

m_flexCounterTable->set(key, fieldValues);
Expand Down
5 changes: 5 additions & 0 deletions orchagent/portsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "observer.h"
#include "macaddress.h"
#include "producertable.h"
#include "flex_counter_manager.h"

#define FCS_LEN 4
#define VLAN_TAG_LEN 4
Expand Down Expand Up @@ -118,6 +119,10 @@ class PortsOrch : public Orch, public Subject
shared_ptr<DBConnector> m_counter_db;
shared_ptr<DBConnector> m_flex_db;

FlexCounterManager port_stat_manager;
FlexCounterManager queue_stat_manager;


std::map<sai_object_id_t, PortSupportedSpeeds> m_portSupportedSpeeds;

bool m_initDone = false;
Expand Down

0 comments on commit d911d41

Please sign in to comment.