Skip to content

Commit f91a477

Browse files
kktheballeranish-n
authored andcommitted
Adding sonic-net#1170 patch
1 parent 5aa80a0 commit f91a477

8 files changed

Lines changed: 143 additions & 68 deletions

File tree

cfgmgr/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
INCLUDES = -I $(top_srcdir) -I $(top_srcdir)/orchagent -I $(top_srcdir)/warmrestart
1+
INCLUDES = -I $(top_srcdir) -I $(top_srcdir)/orchagent -I $(top_srcdir)/warmrestart -I $(top_srcdir)/orchagent/flex_counter
22
CFLAGS_SAI = -I /usr/include/sai
33
LIBNL_CFLAGS = -I/usr/include/libnl3
44
LIBNL_LIBS = -lnl-genl-3 -lnl-route-3 -lnl-3

orchagent/debugcounterorch.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static const unordered_map<string, CounterType> flex_counter_type_lookup = {
2525
// object should only be initialized once.
2626
DebugCounterOrch::DebugCounterOrch(DBConnector *db, const vector<string>& table_names, int poll_interval) :
2727
Orch(db, table_names),
28-
flex_counter_manager(DEBUG_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, poll_interval),
28+
flex_counter_manager(DEBUG_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, poll_interval, true),
2929
m_stateDb(new DBConnector("STATE_DB", 0)),
3030
m_debugCapabilitiesTable(new Table(m_stateDb.get(), STATE_DEBUG_COUNTER_CAPABILITIES_NAME)),
3131
m_countersDb(new DBConnector("COUNTERS_DB", 0)),
@@ -34,7 +34,6 @@ DebugCounterOrch::DebugCounterOrch(DBConnector *db, const vector<string>& table_
3434
{
3535
SWSS_LOG_ENTER();
3636
publishDropCounterCapabilities();
37-
flex_counter_manager.enableFlexCounterGroup();
3837
}
3938

4039
DebugCounterOrch::~DebugCounterOrch(void)

orchagent/flex_counter/flex_counter_manager.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,19 @@ const unordered_map<CounterType, string> FlexCounterManager::counter_id_field_lo
3434
{
3535
{ CounterType::PORT_DEBUG, PORT_DEBUG_COUNTER_ID_LIST },
3636
{ CounterType::SWITCH_DEBUG, SWITCH_DEBUG_COUNTER_ID_LIST },
37+
{ CounterType::PORT, PORT_COUNTER_ID_LIST },
38+
{ CounterType::QUEUE, QUEUE_COUNTER_ID_LIST }
3739
};
3840

39-
// This constructor will create a group that is disabled by default.
4041
FlexCounterManager::FlexCounterManager(
4142
const string& group_name,
4243
const StatsMode stats_mode,
43-
const uint polling_interval) :
44+
const uint polling_interval,
45+
const bool enabled) :
4446
group_name(group_name),
4547
stats_mode(stats_mode),
4648
polling_interval(polling_interval),
47-
enabled(false),
49+
enabled(enabled),
4850
flex_counter_db(new DBConnector("FLEX_COUNTER_DB", 0)),
4951
flex_counter_group_table(new ProducerTable(flex_counter_db.get(), FLEX_COUNTER_GROUP_TABLE)),
5052
flex_counter_table(new ProducerTable(flex_counter_db.get(), FLEX_COUNTER_TABLE))
@@ -72,6 +74,8 @@ FlexCounterManager::~FlexCounterManager()
7274

7375
void FlexCounterManager::applyGroupConfiguration()
7476
{
77+
SWSS_LOG_ENTER();
78+
7579
vector<FieldValueTuple> field_values =
7680
{
7781
FieldValueTuple(STATS_MODE_FIELD, stats_mode_lookup.at(stats_mode)),

orchagent/flex_counter/flex_counter_manager.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ enum class StatsMode
1818

1919
enum class CounterType
2020
{
21+
PORT,
22+
QUEUE,
2123
PORT_DEBUG,
2224
SWITCH_DEBUG
2325
};
@@ -33,7 +35,8 @@ class FlexCounterManager
3335
FlexCounterManager(
3436
const std::string& group_name,
3537
const StatsMode stats_mode,
36-
const uint polling_interval);
38+
const uint polling_interval,
39+
const bool enabled);
3740

3841
FlexCounterManager(const FlexCounterManager&) = delete;
3942
FlexCounterManager& operator=(const FlexCounterManager&) = delete;

orchagent/flex_counter/flex_counter_stat_manager.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ using swss::FieldValueTuple;
1313
FlexCounterStatManager::FlexCounterStatManager(
1414
const string& group_name,
1515
const StatsMode stats_mode,
16-
const int polling_interval) :
17-
FlexCounterManager(group_name, stats_mode, polling_interval)
16+
const int polling_interval,
17+
const bool enabled) :
18+
FlexCounterManager(group_name, stats_mode, polling_interval, enabled)
1819
{
1920
SWSS_LOG_ENTER();
2021
}

orchagent/flex_counter/flex_counter_stat_manager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class FlexCounterStatManager : public FlexCounterManager
1111
FlexCounterStatManager(
1212
const std::string& group_name,
1313
const StatsMode stats_mode,
14-
const int polling_interval);
14+
const int polling_interval,
15+
const bool enabled);
1516

1617
FlexCounterStatManager(const FlexCounterStatManager&) = delete;
1718
FlexCounterStatManager& operator=(const FlexCounterStatManager&) = delete;

orchagent/portsorch.cpp

Lines changed: 120 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <algorithm>
1212
#include <tuple>
1313
#include <sstream>
14+
#include <unordered_set>
1415

1516
#include <netinet/if_ether.h>
1617
#include "net/if.h"
@@ -48,6 +49,9 @@ extern FdbOrch *gFdbOrch;
4849
#define QUEUE_FLEX_STAT_COUNTER_POLL_MSECS "10000"
4950
#define QUEUE_WATERMARK_FLEX_STAT_COUNTER_POLL_MSECS "10000"
5051
#define PG_WATERMARK_FLEX_STAT_COUNTER_POLL_MSECS "10000"
52+
#define PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS 1000
53+
#define QUEUE_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS 10000
54+
5155

5256

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

80+
const vector<sai_port_stat_t> port_stat_ids =
81+
{
82+
SAI_PORT_STAT_IF_IN_OCTETS,
83+
SAI_PORT_STAT_IF_IN_UCAST_PKTS,
84+
SAI_PORT_STAT_IF_IN_NON_UCAST_PKTS,
85+
SAI_PORT_STAT_IF_IN_DISCARDS,
86+
SAI_PORT_STAT_IF_IN_ERRORS,
87+
SAI_PORT_STAT_IF_IN_UNKNOWN_PROTOS,
88+
SAI_PORT_STAT_IF_OUT_OCTETS,
89+
SAI_PORT_STAT_IF_OUT_UCAST_PKTS,
90+
SAI_PORT_STAT_IF_OUT_NON_UCAST_PKTS,
91+
SAI_PORT_STAT_IF_OUT_DISCARDS,
92+
SAI_PORT_STAT_IF_OUT_ERRORS,
93+
SAI_PORT_STAT_IF_OUT_QLEN,
94+
SAI_PORT_STAT_IF_IN_MULTICAST_PKTS,
95+
SAI_PORT_STAT_IF_IN_BROADCAST_PKTS,
96+
SAI_PORT_STAT_IF_OUT_MULTICAST_PKTS,
97+
SAI_PORT_STAT_IF_OUT_BROADCAST_PKTS,
98+
SAI_PORT_STAT_ETHER_RX_OVERSIZE_PKTS,
99+
SAI_PORT_STAT_ETHER_TX_OVERSIZE_PKTS,
100+
SAI_PORT_STAT_PFC_0_TX_PKTS,
101+
SAI_PORT_STAT_PFC_1_TX_PKTS,
102+
SAI_PORT_STAT_PFC_2_TX_PKTS,
103+
SAI_PORT_STAT_PFC_3_TX_PKTS,
104+
SAI_PORT_STAT_PFC_4_TX_PKTS,
105+
SAI_PORT_STAT_PFC_5_TX_PKTS,
106+
SAI_PORT_STAT_PFC_6_TX_PKTS,
107+
SAI_PORT_STAT_PFC_7_TX_PKTS,
108+
SAI_PORT_STAT_PFC_0_RX_PKTS,
109+
SAI_PORT_STAT_PFC_1_RX_PKTS,
110+
SAI_PORT_STAT_PFC_2_RX_PKTS,
111+
SAI_PORT_STAT_PFC_3_RX_PKTS,
112+
SAI_PORT_STAT_PFC_4_RX_PKTS,
113+
SAI_PORT_STAT_PFC_5_RX_PKTS,
114+
SAI_PORT_STAT_PFC_6_RX_PKTS,
115+
SAI_PORT_STAT_PFC_7_RX_PKTS,
116+
SAI_PORT_STAT_PAUSE_RX_PKTS,
117+
SAI_PORT_STAT_PAUSE_TX_PKTS,
118+
SAI_PORT_STAT_ETHER_STATS_TX_NO_ERRORS,
119+
SAI_PORT_STAT_IP_IN_UCAST_PKTS,
120+
SAI_PORT_STAT_ETHER_IN_PKTS_128_TO_255_OCTETS,
121+
};
122+
123+
//in any case
76124
const vector<sai_port_stat_t> portStatIds =
77125
{
78126
SAI_PORT_STAT_IF_IN_OCTETS,
@@ -116,12 +164,22 @@ const vector<sai_port_stat_t> portStatIds =
116164
SAI_PORT_STAT_ETHER_IN_PKTS_128_TO_255_OCTETS,
117165
};
118166

167+
119168
static const vector<sai_port_stat_t> port_buffer_drop_stat_ids =
120169
{
121170
SAI_PORT_STAT_IN_DROPPED_PKTS,
122171
SAI_PORT_STAT_OUT_DROPPED_PKTS
123172
};
124173

174+
175+
static const vector<sai_queue_stat_t> queue_stat_ids =
176+
{
177+
SAI_QUEUE_STAT_PACKETS,
178+
SAI_QUEUE_STAT_BYTES,
179+
SAI_QUEUE_STAT_DROPPED_PACKETS,
180+
SAI_QUEUE_STAT_DROPPED_BYTES,
181+
};
182+
125183
static const vector<sai_queue_stat_t> queueStatIds =
126184
{
127185
SAI_QUEUE_STAT_PACKETS,
@@ -160,7 +218,9 @@ static char* hostif_vlan_tag[] = {
160218
* default VLAN and all ports removed from .1Q bridge.
161219
*/
162220
PortsOrch::PortsOrch(DBConnector *db, vector<table_name_with_pri_t> &tableNames) :
163-
Orch(db, tableNames)
221+
Orch(db, tableNames),
222+
port_stat_manager(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true),
223+
queue_stat_manager(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, QUEUE_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true)
164224
{
165225
SWSS_LOG_ENTER();
166226

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

195-
vector<FieldValueTuple> fields;
196-
fields.emplace_back(POLL_INTERVAL_FIELD, PORT_FLEX_STAT_COUNTER_POLL_MSECS);
197-
fields.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ);
198-
m_flexCounterGroupTable->set(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, fields);
255+
//NOTE: master 1170 commit does not have the below lines.
256+
//vector<FieldValueTuple> fields;
257+
//fields.emplace_back(POLL_INTERVAL_FIELD, PORT_FLEX_STAT_COUNTER_POLL_MSECS);
258+
//fields.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ);
259+
//m_flexCounterGroupTable->set(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, fields);
199260

200-
fields.clear();
201-
fields.emplace_back(POLL_INTERVAL_FIELD, PORT_BUFFER_DROP_STAT_POLLING_INTERVAL_MS);
202-
fields.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ);
203-
m_flexCounterGroupTable->set(PORT_DROP_STAT_COUNTER_FLEX_COUNTER_GROUP, fields);
261+
//fields.clear();
262+
//fields.emplace_back(POLL_INTERVAL_FIELD, PORT_BUFFER_DROP_STAT_POLLING_INTERVAL_MS);
263+
//fields.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ);
264+
//m_flexCounterGroupTable->set(PORT_DROP_STAT_COUNTER_FLEX_COUNTER_GROUP, fields);
204265

205-
fields.clear();
206-
fields.emplace_back(POLL_INTERVAL_FIELD, QUEUE_FLEX_STAT_COUNTER_POLL_MSECS);
207-
fields.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ);
208-
m_flexCounterGroupTable->set(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP, fields);
266+
//fields.clear();
267+
//fields.emplace_back(POLL_INTERVAL_FIELD, QUEUE_FLEX_STAT_COUNTER_POLL_MSECS);
268+
//fields.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ);
269+
//m_flexCounterGroupTable->set(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP, fields);
209270

210271
string queueWmSha, pgWmSha;
211272
string queueWmPluginName = "watermark_queue.lua";
@@ -1494,20 +1555,22 @@ bool PortsOrch::removePort(sai_object_id_t port_id)
14941555
return true;
14951556
}
14961557

1497-
string PortsOrch::getPortFlexCounterTableKey(string key)
1498-
{
1499-
return string(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP) + ":" + key;
1500-
}
1558+
1559+
//NOTE: commenting out below because 1170 master did this...
1560+
//string PortsOrch::getPortFlexCounterTableKey(string key)
1561+
//{
1562+
// return string(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP) + ":" + key;
1563+
//}
15011564

15021565
string PortsOrch::getPortBuffDropFlexCounterTableKey(string key)
15031566
{
15041567
return string(PORT_DROP_STAT_COUNTER_FLEX_COUNTER_GROUP) + ":" + key;
15051568
}
15061569

1507-
string PortsOrch::getQueueFlexCounterTableKey(string key)
1508-
{
1509-
return string(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP) + ":" + key;
1510-
}
1570+
//string PortsOrch::getQueueFlexCounterTableKey(string key)
1571+
//{
1572+
// return string(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP) + ":" + key;
1573+
//}
15111574

15121575
string PortsOrch::getQueueWatermarkFlexCounterTableKey(string key)
15131576
{
@@ -1553,32 +1616,39 @@ bool PortsOrch::initPort(const string &alias, const set<int> &lane_set)
15531616
m_counterTable->set("", fields);
15541617

15551618
/* Add port to flex_counter for updating stat counters */
1556-
string key = getPortFlexCounterTableKey(sai_serialize_object_id(p.m_port_id));
1557-
std::string delimiter = "";
1558-
std::ostringstream counters_stream;
1559-
for (const auto &id: portStatIds)
1619+
//string key = getPortFlexCounterTableKey(sai_serialize_object_id(p.m_port_id));
1620+
//std::string delimiter = "";
1621+
//std::ostringstream counters_stream;
1622+
//for (const auto &id: portStatIds)
1623+
//{
1624+
// counters_stream << delimiter << sai_serialize_port_stat(id);
1625+
// delimiter = comma;
1626+
//}
1627+
1628+
std::unordered_set<std::string> counter_stats;
1629+
for (const auto& it: port_stat_ids)
15601630
{
1561-
counters_stream << delimiter << sai_serialize_port_stat(id);
1562-
delimiter = comma;
1631+
counter_stats.emplace(sai_serialize_port_stat(it));
15631632
}
1633+
port_stat_manager.setCounterIdList(p.m_port_id, CounterType::PORT, counter_stats);
15641634

1565-
fields.clear();
1566-
fields.emplace_back(PORT_COUNTER_ID_LIST, counters_stream.str());
1635+
//fields.clear();
1636+
//fields.emplace_back(PORT_COUNTER_ID_LIST, counters_stream.str());
15671637

1568-
m_flexCounterTable->set(key, fields);
1638+
//m_flexCounterTable->set(key, fields);
15691639

1570-
delimiter = "";
1571-
string port_drop_key = getPortBuffDropFlexCounterTableKey(sai_serialize_object_id(p.m_port_id));
1572-
std::ostringstream port_buffer_drop_stream;
1573-
for (const auto& it: port_buffer_drop_stat_ids)
1574-
{
1575-
port_buffer_drop_stream << delimiter << sai_serialize_port_stat(it);
1576-
delimiter = comma;
1577-
}
1640+
//delimiter = "";
1641+
//string port_drop_key = getPortBuffDropFlexCounterTableKey(sai_serialize_object_id(p.m_port_id));
1642+
//std::ostringstream port_buffer_drop_stream;
1643+
//for (const auto& it: port_buffer_drop_stat_ids)
1644+
//{
1645+
// port_buffer_drop_stream << delimiter << sai_serialize_port_stat(it);
1646+
// delimiter = comma;
1647+
//}
15781648

1579-
fields.clear();
1580-
fields.emplace_back(PORT_COUNTER_ID_LIST, port_buffer_drop_stream.str());
1581-
m_flexCounterTable->set(port_drop_key, fields);
1649+
//fields.clear();
1650+
//fields.emplace_back(PORT_COUNTER_ID_LIST, port_buffer_drop_stream.str());
1651+
//m_flexCounterTable->set(port_drop_key, fields);
15821652

15831653
PortUpdate update = {p, true };
15841654
notify(SUBJECT_TYPE_PORT_CHANGE, static_cast<void *>(&update));
@@ -3559,34 +3629,26 @@ void PortsOrch::generateQueueMapPerPort(const Port& port)
35593629
queueIndexVector.emplace_back(id, to_string(queueRealIndex));
35603630
}
35613631

3562-
/* add ordinary Queue stat counters */
3563-
string key = getQueueFlexCounterTableKey(id);
3564-
3565-
std::string delimiter = "";
3566-
std::ostringstream counters_stream;
3567-
for (const auto& it: queueStatIds)
3632+
// Install a flex counter for this queue to track stats
3633+
std::unordered_set<string> counter_stats;
3634+
for (const auto& it: queue_stat_ids)
35683635
{
3569-
counters_stream << delimiter << sai_serialize_queue_stat(it);
3570-
delimiter = comma;
3636+
counter_stats.emplace(sai_serialize_queue_stat(it));
35713637
}
3572-
3573-
vector<FieldValueTuple> fieldValues;
3574-
fieldValues.emplace_back(QUEUE_COUNTER_ID_LIST, counters_stream.str());
3575-
3576-
m_flexCounterTable->set(key, fieldValues);
3638+
queue_stat_manager.setCounterIdList(port.m_queue_ids[queueIndex], CounterType::QUEUE, counter_stats);
35773639

35783640
/* add watermark queue counters */
3579-
key = getQueueWatermarkFlexCounterTableKey(id);
3641+
string key = getQueueWatermarkFlexCounterTableKey(id);
35803642

3581-
delimiter = "";
3582-
counters_stream.str("");
3643+
string delimiter("");
3644+
std::ostringstream counters_stream;
35833645
for (const auto& it: queueWatermarkStatIds)
35843646
{
35853647
counters_stream << delimiter << sai_serialize_queue_stat(it);
35863648
delimiter = comma;
35873649
}
35883650

3589-
fieldValues.clear();
3651+
vector<FieldValueTuple> fieldValues;
35903652
fieldValues.emplace_back(QUEUE_COUNTER_ID_LIST, counters_stream.str());
35913653

35923654
m_flexCounterTable->set(key, fieldValues);

orchagent/portsorch.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "observer.h"
1010
#include "macaddress.h"
1111
#include "producertable.h"
12+
#include "flex_counter_manager.h"
1213

1314
#define FCS_LEN 4
1415
#define VLAN_TAG_LEN 4
@@ -115,6 +116,10 @@ class PortsOrch : public Orch, public Subject
115116
shared_ptr<DBConnector> m_counter_db;
116117
shared_ptr<DBConnector> m_flex_db;
117118

119+
FlexCounterManager port_stat_manager;
120+
FlexCounterManager queue_stat_manager;
121+
122+
118123
std::map<sai_object_id_t, PortSupportedSpeeds> m_portSupportedSpeeds;
119124

120125
bool m_initDone = false;

0 commit comments

Comments
 (0)