Skip to content

Commit ec57bf1

Browse files
authored
[macsec] Update macsec flex counter (#2338)
* Default macsec poll interval 10s, except of xpn1s * Correct COUNTERS_MACSEC_NAME_MAP entry in GB_COUNTERS_DB for gearbox macsec * Support macsec flex couner config * Correct port flex counter config for gearbox * Add IN_UCAST_PKTS/IN_NON_UCAST_PKTS/OUT_UCAST_PKTS/OUT_NON_UCAST_PKTS in gearbox port counter list
1 parent 6e0fc85 commit ec57bf1

File tree

6 files changed

+59
-58
lines changed

6 files changed

+59
-58
lines changed

orchagent/flexcounterorch.cpp

+19-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "directory.h"
1212
#include "copporch.h"
1313
#include "routeorch.h"
14+
#include "macsecorch.h"
1415
#include "flowcounterrouteorch.h"
1516

1617
extern sai_port_api_t *sai_port_api;
@@ -52,14 +53,19 @@ unordered_map<string, string> flexCounterGroupMap =
5253
{"TUNNEL", TUNNEL_STAT_COUNTER_FLEX_COUNTER_GROUP},
5354
{FLOW_CNT_TRAP_KEY, HOSTIF_TRAP_COUNTER_FLEX_COUNTER_GROUP},
5455
{FLOW_CNT_ROUTE_KEY, ROUTE_FLOW_COUNTER_FLEX_COUNTER_GROUP},
56+
{"MACSEC_SA", COUNTERS_MACSEC_SA_GROUP},
57+
{"MACSEC_SA_ATTR", COUNTERS_MACSEC_SA_ATTR_GROUP},
58+
{"MACSEC_FLOW", COUNTERS_MACSEC_FLOW_GROUP},
5559
};
5660

5761

5862
FlexCounterOrch::FlexCounterOrch(DBConnector *db, vector<string> &tableNames):
5963
Orch(db, tableNames),
6064
m_flexCounterConfigTable(db, CFG_FLEX_COUNTER_TABLE_NAME),
6165
m_flexCounterDb(new DBConnector("FLEX_COUNTER_DB", 0)),
62-
m_flexCounterGroupTable(new ProducerTable(m_flexCounterDb.get(), FLEX_COUNTER_GROUP_TABLE))
66+
m_flexCounterGroupTable(new ProducerTable(m_flexCounterDb.get(), FLEX_COUNTER_GROUP_TABLE)),
67+
m_gbflexCounterDb(new DBConnector("GB_FLEX_COUNTER_DB", 0)),
68+
m_gbflexCounterGroupTable(new ProducerTable(m_gbflexCounterDb.get(), FLEX_COUNTER_GROUP_TABLE))
6369
{
6470
SWSS_LOG_ENTER();
6571
}
@@ -119,6 +125,13 @@ void FlexCounterOrch::doTask(Consumer &consumer)
119125
vector<FieldValueTuple> fieldValues;
120126
fieldValues.emplace_back(POLL_INTERVAL_FIELD, value);
121127
m_flexCounterGroupTable->set(flexCounterGroupMap[key], fieldValues);
128+
if (gPortsOrch && gPortsOrch->isGearboxEnabled())
129+
{
130+
if (key == PORT_KEY || key.rfind("MACSEC", 0) == 0)
131+
{
132+
m_gbflexCounterGroupTable->set(flexCounterGroupMap[key], fieldValues);
133+
}
134+
}
122135
}
123136
else if(field == FLEX_COUNTER_STATUS_FIELD)
124137
{
@@ -197,10 +210,12 @@ void FlexCounterOrch::doTask(Consumer &consumer)
197210
fieldValues.emplace_back(FLEX_COUNTER_STATUS_FIELD, value);
198211
m_flexCounterGroupTable->set(flexCounterGroupMap[key], fieldValues);
199212

200-
// Update FLEX_COUNTER_STATUS for gearbox port
201-
if (key == PORT_KEY && gPortsOrch && gPortsOrch->isGearboxEnabled())
213+
if (gPortsOrch && gPortsOrch->isGearboxEnabled())
202214
{
203-
gPortsOrch->setGearboxFlexCounterStatus(value == "enable");
215+
if (key == PORT_KEY || key.rfind("MACSEC", 0) == 0)
216+
{
217+
m_gbflexCounterGroupTable->set(flexCounterGroupMap[key], fieldValues);
218+
}
204219
}
205220
}
206221
else if(field == FLEX_COUNTER_DELAY_STATUS_FIELD)

orchagent/flexcounterorch.h

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class FlexCounterOrch: public Orch
2525
private:
2626
std::shared_ptr<swss::DBConnector> m_flexCounterDb = nullptr;
2727
std::shared_ptr<swss::ProducerTable> m_flexCounterGroupTable = nullptr;
28+
std::shared_ptr<swss::DBConnector> m_gbflexCounterDb = nullptr;
29+
shared_ptr<ProducerTable> m_gbflexCounterGroupTable = nullptr;
2830
bool m_port_counter_enabled = false;
2931
bool m_port_buffer_drop_counter_enabled = false;
3032
bool m_hostif_trap_counter_enabled = false;

orchagent/macsecorch.cpp

+19-23
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222
#define AVAILABLE_ACL_PRIORITIES_LIMITATION (32)
2323
#define EAPOL_ETHER_TYPE (0x888e)
2424
#define PAUSE_ETHER_TYPE (0x8808)
25-
#define MACSEC_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS (1000)
26-
#define COUNTERS_MACSEC_SA_ATTR_GROUP "COUNTERS_MACSEC_SA_ATTR"
27-
#define COUNTERS_MACSEC_SA_GROUP "COUNTERS_MACSEC_SA"
28-
#define COUNTERS_MACSEC_FLOW_GROUP "COUNTERS_MACSEC_FLOW"
25+
#define MACSEC_STAT_XPN_POLLING_INTERVAL_MS (1000)
26+
#define MACSEC_STAT_POLLING_INTERVAL_MS (10000)
2927
#define PFC_MODE_BYPASS "bypass"
3028
#define PFC_MODE_ENCRYPT "encrypt"
3129
#define PFC_MODE_STRICT_ENCRYPT "strict_encrypt"
@@ -608,37 +606,35 @@ MACsecOrch::MACsecOrch(
608606
m_applPortTable(app_db, APP_PORT_TABLE_NAME),
609607
m_counter_db("COUNTERS_DB", 0),
610608
m_macsec_counters_map(&m_counter_db, COUNTERS_MACSEC_NAME_MAP),
611-
m_macsec_flow_tx_counters_map(&m_counter_db, COUNTERS_MACSEC_FLOW_TX_NAME_MAP),
612-
m_macsec_flow_rx_counters_map(&m_counter_db, COUNTERS_MACSEC_FLOW_RX_NAME_MAP),
613-
m_macsec_sa_tx_counters_map(&m_counter_db, COUNTERS_MACSEC_SA_TX_NAME_MAP),
614-
m_macsec_sa_rx_counters_map(&m_counter_db, COUNTERS_MACSEC_SA_RX_NAME_MAP),
609+
m_gb_counter_db("GB_COUNTERS_DB", 0),
610+
m_gb_macsec_counters_map(&m_gb_counter_db, COUNTERS_MACSEC_NAME_MAP),
615611
m_macsec_sa_attr_manager(
616612
COUNTERS_MACSEC_SA_ATTR_GROUP,
617613
StatsMode::READ,
618-
MACSEC_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true),
614+
MACSEC_STAT_XPN_POLLING_INTERVAL_MS, true),
619615
m_macsec_sa_stat_manager(
620616
COUNTERS_MACSEC_SA_GROUP,
621617
StatsMode::READ,
622-
MACSEC_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true),
618+
MACSEC_STAT_POLLING_INTERVAL_MS, true),
623619
m_macsec_flow_stat_manager(
624620
COUNTERS_MACSEC_FLOW_GROUP,
625621
StatsMode::READ,
626-
MACSEC_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true),
622+
MACSEC_STAT_POLLING_INTERVAL_MS, true),
627623
m_gb_macsec_sa_attr_manager(
628624
"GB_FLEX_COUNTER_DB",
629625
COUNTERS_MACSEC_SA_ATTR_GROUP,
630626
StatsMode::READ,
631-
MACSEC_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true),
627+
MACSEC_STAT_XPN_POLLING_INTERVAL_MS, true),
632628
m_gb_macsec_sa_stat_manager(
633629
"GB_FLEX_COUNTER_DB",
634630
COUNTERS_MACSEC_SA_GROUP,
635631
StatsMode::READ,
636-
MACSEC_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true),
632+
MACSEC_STAT_POLLING_INTERVAL_MS, true),
637633
m_gb_macsec_flow_stat_manager(
638634
"GB_FLEX_COUNTER_DB",
639635
COUNTERS_MACSEC_FLOW_GROUP,
640636
StatsMode::READ,
641-
MACSEC_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true)
637+
MACSEC_STAT_POLLING_INTERVAL_MS, true)
642638
{
643639
SWSS_LOG_ENTER();
644640
}
@@ -2329,6 +2325,13 @@ FlexCounterManager& MACsecOrch::MACsecFlowStatManager(MACsecOrchContext &ctx)
23292325
return m_macsec_flow_stat_manager;
23302326
}
23312327

2328+
Table& MACsecOrch::MACsecCountersMap(MACsecOrchContext &ctx)
2329+
{
2330+
if (ctx.get_gearbox_phy() != nullptr)
2331+
return m_gb_macsec_counters_map;
2332+
return m_macsec_counters_map;
2333+
}
2334+
23322335
void MACsecOrch::installCounter(
23332336
MACsecOrchContext &ctx,
23342337
CounterType counter_type,
@@ -2350,19 +2353,12 @@ void MACsecOrch::installCounter(
23502353
{
23512354
case CounterType::MACSEC_SA_ATTR:
23522355
MACsecSaAttrStatManager(ctx).setCounterIdList(obj_id, counter_type, counter_stats);
2353-
m_macsec_counters_map.set("", fields);
2356+
MACsecCountersMap(ctx).set("", fields);
23542357
break;
23552358

23562359
case CounterType::MACSEC_SA:
23572360
MACsecSaStatManager(ctx).setCounterIdList(obj_id, counter_type, counter_stats);
2358-
if (direction == SAI_MACSEC_DIRECTION_EGRESS)
2359-
{
2360-
m_macsec_sa_tx_counters_map.set("", fields);
2361-
}
2362-
else
2363-
{
2364-
m_macsec_sa_rx_counters_map.set("", fields);
2365-
}
2361+
MACsecCountersMap(ctx).set("", fields);
23662362
break;
23672363

23682364
case CounterType::MACSEC_FLOW:

orchagent/macsecorch.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
using namespace swss;
1818

19+
#define COUNTERS_MACSEC_SA_ATTR_GROUP "COUNTERS_MACSEC_SA_ATTR"
20+
#define COUNTERS_MACSEC_SA_GROUP "COUNTERS_MACSEC_SA"
21+
#define COUNTERS_MACSEC_FLOW_GROUP "COUNTERS_MACSEC_FLOW"
22+
1923
// AN is a 2 bit number, it can only be 0, 1, 2 or 3
2024
#define MAX_SA_NUMBER (3)
2125

@@ -63,10 +67,8 @@ class MACsecOrch : public Orch
6367

6468
DBConnector m_counter_db;
6569
Table m_macsec_counters_map;
66-
Table m_macsec_flow_tx_counters_map;
67-
Table m_macsec_flow_rx_counters_map;
68-
Table m_macsec_sa_tx_counters_map;
69-
Table m_macsec_sa_rx_counters_map;
70+
DBConnector m_gb_counter_db;
71+
Table m_gb_macsec_counters_map;
7072
Table m_applPortTable;
7173
FlexCounterManager m_macsec_sa_attr_manager;
7274
FlexCounterManager m_macsec_sa_stat_manager;
@@ -226,6 +228,8 @@ class MACsecOrch : public Orch
226228
const std::string &obj_name,
227229
sai_object_id_t obj_id);
228230

231+
Table& MACsecCountersMap(MACsecOrchContext &ctx);
232+
229233
/* Flex Counter Manager */
230234
FlexCounterManager& MACsecSaStatManager(MACsecOrchContext &ctx);
231235
FlexCounterManager& MACsecSaAttrStatManager(MACsecOrchContext &ctx);

orchagent/portsorch.cpp

+10-24
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,11 @@ const vector<sai_port_stat_t> port_stat_ids =
248248
const vector<sai_port_stat_t> gbport_stat_ids =
249249
{
250250
SAI_PORT_STAT_IF_IN_OCTETS,
251+
SAI_PORT_STAT_IF_IN_UCAST_PKTS,
252+
SAI_PORT_STAT_IF_IN_NON_UCAST_PKTS,
251253
SAI_PORT_STAT_IF_OUT_OCTETS,
254+
SAI_PORT_STAT_IF_OUT_UCAST_PKTS,
255+
SAI_PORT_STAT_IF_OUT_NON_UCAST_PKTS,
252256
SAI_PORT_STAT_IF_IN_DISCARDS,
253257
SAI_PORT_STAT_IF_OUT_DISCARDS,
254258
SAI_PORT_STAT_IF_IN_ERRORS,
@@ -324,7 +328,7 @@ PortsOrch::PortsOrch(DBConnector *db, DBConnector *stateDb, vector<table_name_wi
324328
m_portStateTable(stateDb, STATE_PORT_TABLE_NAME),
325329
port_stat_manager(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, false),
326330
gb_port_stat_manager("GB_FLEX_COUNTER_DB",
327-
GBPORT_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ,
331+
PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ,
328332
PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, false),
329333
port_buffer_drop_stat_manager(PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_BUFFER_DROP_STAT_POLLING_INTERVAL_MS, false),
330334
queue_stat_manager(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, QUEUE_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, false)
@@ -2443,7 +2447,7 @@ bool PortsOrch::initPort(const string &alias, const string &role, const int inde
24432447
auto port_counter_stats = generateCounterStats(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP);
24442448
port_stat_manager.setCounterIdList(p.m_port_id,
24452449
CounterType::PORT, port_counter_stats);
2446-
auto gbport_counter_stats = generateCounterStats(GBPORT_STAT_COUNTER_FLEX_COUNTER_GROUP);
2450+
auto gbport_counter_stats = generateCounterStats(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, true);
24472451
if (p.m_system_side_id)
24482452
gb_port_stat_manager.setCounterIdList(p.m_system_side_id,
24492453
CounterType::PORT, gbport_counter_stats);
@@ -5713,7 +5717,7 @@ void PortsOrch::generatePortCounterMap()
57135717
}
57145718

57155719
auto port_counter_stats = generateCounterStats(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP);
5716-
auto gbport_counter_stats = generateCounterStats(GBPORT_STAT_COUNTER_FLEX_COUNTER_GROUP);
5720+
auto gbport_counter_stats = generateCounterStats(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, true);
57175721
for (const auto& it: m_portList)
57185722
{
57195723
// Set counter stats only for PHY ports to ensure syncd will not try to query the counter statistics from the HW for non-PHY ports.
@@ -6955,19 +6959,13 @@ void PortsOrch::voqSyncDelLagMember(Port &lag, Port &port)
69556959
m_tableVoqSystemLagMemberTable->del(key);
69566960
}
69576961

6958-
std::unordered_set<std::string> PortsOrch::generateCounterStats(const string& type)
6962+
std::unordered_set<std::string> PortsOrch::generateCounterStats(const string& type, bool gearbox)
69596963
{
69606964
std::unordered_set<std::string> counter_stats;
69616965
if (type == PORT_STAT_COUNTER_FLEX_COUNTER_GROUP)
69626966
{
6963-
for (const auto& it: port_stat_ids)
6964-
{
6965-
counter_stats.emplace(sai_serialize_port_stat(it));
6966-
}
6967-
}
6968-
else if (type == GBPORT_STAT_COUNTER_FLEX_COUNTER_GROUP)
6969-
{
6970-
for (const auto& it: gbport_stat_ids)
6967+
auto& stat_ids = gearbox ? gbport_stat_ids : port_stat_ids;
6968+
for (const auto& it: stat_ids)
69716969
{
69726970
counter_stats.emplace(sai_serialize_port_stat(it));
69736971
}
@@ -6982,18 +6980,6 @@ std::unordered_set<std::string> PortsOrch::generateCounterStats(const string& ty
69826980
return counter_stats;
69836981
}
69846982

6985-
void PortsOrch::setGearboxFlexCounterStatus(bool enabled)
6986-
{
6987-
if (enabled)
6988-
{
6989-
gb_port_stat_manager.enableFlexCounterGroup();
6990-
}
6991-
else
6992-
{
6993-
gb_port_stat_manager.disableFlexCounterGroup();
6994-
}
6995-
}
6996-
69976983
void PortsOrch::updateGearboxPortOperStatus(const Port& port)
69986984
{
69996985
if (!isGearboxEnabled())

orchagent/portsorch.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#define VLAN_TAG_LEN 4
2121
#define PORT_STAT_COUNTER_FLEX_COUNTER_GROUP "PORT_STAT_COUNTER"
2222
#define PORT_RATE_COUNTER_FLEX_COUNTER_GROUP "PORT_RATE_COUNTER"
23-
#define GBPORT_STAT_COUNTER_FLEX_COUNTER_GROUP "GBPORT_STAT_COUNTER"
2423
#define PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP "PORT_BUFFER_DROP_STAT"
2524
#define QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP "QUEUE_STAT_COUNTER"
2625
#define QUEUE_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP "QUEUE_WATERMARK_STAT_COUNTER"
@@ -170,7 +169,6 @@ class PortsOrch : public Orch, public Subject
170169

171170
bool getPortOperStatus(const Port& port, sai_port_oper_status_t& status) const;
172171

173-
void setGearboxFlexCounterStatus(bool enabled);
174172
void updateGearboxPortOperStatus(const Port& port);
175173

176174
bool decrFdbCount(const string& alias, int count);
@@ -376,7 +374,7 @@ class PortsOrch : public Orch, public Subject
376374
void voqSyncDelLagMember(Port &lag, Port &port);
377375
unique_ptr<LagIdAllocator> m_lagIdAllocator;
378376

379-
std::unordered_set<std::string> generateCounterStats(const string& type);
377+
std::unordered_set<std::string> generateCounterStats(const string& type, bool gearbox = false);
380378

381379
};
382380
#endif /* SWSS_PORTSORCH_H */

0 commit comments

Comments
 (0)