Skip to content

Commit

Permalink
[macsec] Update macsec flex counter (sonic-net#2338)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jimmyzhai authored and preetham-singh committed Aug 6, 2022
1 parent dae1dde commit 6478793
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 58 deletions.
23 changes: 19 additions & 4 deletions orchagent/flexcounterorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "directory.h"
#include "copporch.h"
#include "routeorch.h"
#include "macsecorch.h"
#include "flowcounterrouteorch.h"

extern sai_port_api_t *sai_port_api;
Expand Down Expand Up @@ -52,14 +53,19 @@ unordered_map<string, string> flexCounterGroupMap =
{"TUNNEL", TUNNEL_STAT_COUNTER_FLEX_COUNTER_GROUP},
{FLOW_CNT_TRAP_KEY, HOSTIF_TRAP_COUNTER_FLEX_COUNTER_GROUP},
{FLOW_CNT_ROUTE_KEY, ROUTE_FLOW_COUNTER_FLEX_COUNTER_GROUP},
{"MACSEC_SA", COUNTERS_MACSEC_SA_GROUP},
{"MACSEC_SA_ATTR", COUNTERS_MACSEC_SA_ATTR_GROUP},
{"MACSEC_FLOW", COUNTERS_MACSEC_FLOW_GROUP},
};


FlexCounterOrch::FlexCounterOrch(DBConnector *db, vector<string> &tableNames):
Orch(db, tableNames),
m_flexCounterConfigTable(db, CFG_FLEX_COUNTER_TABLE_NAME),
m_flexCounterDb(new DBConnector("FLEX_COUNTER_DB", 0)),
m_flexCounterGroupTable(new ProducerTable(m_flexCounterDb.get(), FLEX_COUNTER_GROUP_TABLE))
m_flexCounterGroupTable(new ProducerTable(m_flexCounterDb.get(), FLEX_COUNTER_GROUP_TABLE)),
m_gbflexCounterDb(new DBConnector("GB_FLEX_COUNTER_DB", 0)),
m_gbflexCounterGroupTable(new ProducerTable(m_gbflexCounterDb.get(), FLEX_COUNTER_GROUP_TABLE))
{
SWSS_LOG_ENTER();
}
Expand Down Expand Up @@ -119,6 +125,13 @@ void FlexCounterOrch::doTask(Consumer &consumer)
vector<FieldValueTuple> fieldValues;
fieldValues.emplace_back(POLL_INTERVAL_FIELD, value);
m_flexCounterGroupTable->set(flexCounterGroupMap[key], fieldValues);
if (gPortsOrch && gPortsOrch->isGearboxEnabled())
{
if (key == PORT_KEY || key.rfind("MACSEC", 0) == 0)
{
m_gbflexCounterGroupTable->set(flexCounterGroupMap[key], fieldValues);
}
}
}
else if(field == FLEX_COUNTER_STATUS_FIELD)
{
Expand Down Expand Up @@ -197,10 +210,12 @@ void FlexCounterOrch::doTask(Consumer &consumer)
fieldValues.emplace_back(FLEX_COUNTER_STATUS_FIELD, value);
m_flexCounterGroupTable->set(flexCounterGroupMap[key], fieldValues);

// Update FLEX_COUNTER_STATUS for gearbox port
if (key == PORT_KEY && gPortsOrch && gPortsOrch->isGearboxEnabled())
if (gPortsOrch && gPortsOrch->isGearboxEnabled())
{
gPortsOrch->setGearboxFlexCounterStatus(value == "enable");
if (key == PORT_KEY || key.rfind("MACSEC", 0) == 0)
{
m_gbflexCounterGroupTable->set(flexCounterGroupMap[key], fieldValues);
}
}
}
else if(field == FLEX_COUNTER_DELAY_STATUS_FIELD)
Expand Down
2 changes: 2 additions & 0 deletions orchagent/flexcounterorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class FlexCounterOrch: public Orch
private:
std::shared_ptr<swss::DBConnector> m_flexCounterDb = nullptr;
std::shared_ptr<swss::ProducerTable> m_flexCounterGroupTable = nullptr;
std::shared_ptr<swss::DBConnector> m_gbflexCounterDb = nullptr;
shared_ptr<ProducerTable> m_gbflexCounterGroupTable = nullptr;
bool m_port_counter_enabled = false;
bool m_port_buffer_drop_counter_enabled = false;
bool m_hostif_trap_counter_enabled = false;
Expand Down
42 changes: 19 additions & 23 deletions orchagent/macsecorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
#define AVAILABLE_ACL_PRIORITIES_LIMITATION (32)
#define EAPOL_ETHER_TYPE (0x888e)
#define PAUSE_ETHER_TYPE (0x8808)
#define MACSEC_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS (1000)
#define COUNTERS_MACSEC_SA_ATTR_GROUP "COUNTERS_MACSEC_SA_ATTR"
#define COUNTERS_MACSEC_SA_GROUP "COUNTERS_MACSEC_SA"
#define COUNTERS_MACSEC_FLOW_GROUP "COUNTERS_MACSEC_FLOW"
#define MACSEC_STAT_XPN_POLLING_INTERVAL_MS (1000)
#define MACSEC_STAT_POLLING_INTERVAL_MS (10000)
#define PFC_MODE_BYPASS "bypass"
#define PFC_MODE_ENCRYPT "encrypt"
#define PFC_MODE_STRICT_ENCRYPT "strict_encrypt"
Expand Down Expand Up @@ -608,37 +606,35 @@ MACsecOrch::MACsecOrch(
m_applPortTable(app_db, APP_PORT_TABLE_NAME),
m_counter_db("COUNTERS_DB", 0),
m_macsec_counters_map(&m_counter_db, COUNTERS_MACSEC_NAME_MAP),
m_macsec_flow_tx_counters_map(&m_counter_db, COUNTERS_MACSEC_FLOW_TX_NAME_MAP),
m_macsec_flow_rx_counters_map(&m_counter_db, COUNTERS_MACSEC_FLOW_RX_NAME_MAP),
m_macsec_sa_tx_counters_map(&m_counter_db, COUNTERS_MACSEC_SA_TX_NAME_MAP),
m_macsec_sa_rx_counters_map(&m_counter_db, COUNTERS_MACSEC_SA_RX_NAME_MAP),
m_gb_counter_db("GB_COUNTERS_DB", 0),
m_gb_macsec_counters_map(&m_gb_counter_db, COUNTERS_MACSEC_NAME_MAP),
m_macsec_sa_attr_manager(
COUNTERS_MACSEC_SA_ATTR_GROUP,
StatsMode::READ,
MACSEC_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true),
MACSEC_STAT_XPN_POLLING_INTERVAL_MS, true),
m_macsec_sa_stat_manager(
COUNTERS_MACSEC_SA_GROUP,
StatsMode::READ,
MACSEC_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true),
MACSEC_STAT_POLLING_INTERVAL_MS, true),
m_macsec_flow_stat_manager(
COUNTERS_MACSEC_FLOW_GROUP,
StatsMode::READ,
MACSEC_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true),
MACSEC_STAT_POLLING_INTERVAL_MS, true),
m_gb_macsec_sa_attr_manager(
"GB_FLEX_COUNTER_DB",
COUNTERS_MACSEC_SA_ATTR_GROUP,
StatsMode::READ,
MACSEC_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true),
MACSEC_STAT_XPN_POLLING_INTERVAL_MS, true),
m_gb_macsec_sa_stat_manager(
"GB_FLEX_COUNTER_DB",
COUNTERS_MACSEC_SA_GROUP,
StatsMode::READ,
MACSEC_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true),
MACSEC_STAT_POLLING_INTERVAL_MS, true),
m_gb_macsec_flow_stat_manager(
"GB_FLEX_COUNTER_DB",
COUNTERS_MACSEC_FLOW_GROUP,
StatsMode::READ,
MACSEC_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true)
MACSEC_STAT_POLLING_INTERVAL_MS, true)
{
SWSS_LOG_ENTER();
}
Expand Down Expand Up @@ -2329,6 +2325,13 @@ FlexCounterManager& MACsecOrch::MACsecFlowStatManager(MACsecOrchContext &ctx)
return m_macsec_flow_stat_manager;
}

Table& MACsecOrch::MACsecCountersMap(MACsecOrchContext &ctx)
{
if (ctx.get_gearbox_phy() != nullptr)
return m_gb_macsec_counters_map;
return m_macsec_counters_map;
}

void MACsecOrch::installCounter(
MACsecOrchContext &ctx,
CounterType counter_type,
Expand All @@ -2350,19 +2353,12 @@ void MACsecOrch::installCounter(
{
case CounterType::MACSEC_SA_ATTR:
MACsecSaAttrStatManager(ctx).setCounterIdList(obj_id, counter_type, counter_stats);
m_macsec_counters_map.set("", fields);
MACsecCountersMap(ctx).set("", fields);
break;

case CounterType::MACSEC_SA:
MACsecSaStatManager(ctx).setCounterIdList(obj_id, counter_type, counter_stats);
if (direction == SAI_MACSEC_DIRECTION_EGRESS)
{
m_macsec_sa_tx_counters_map.set("", fields);
}
else
{
m_macsec_sa_rx_counters_map.set("", fields);
}
MACsecCountersMap(ctx).set("", fields);
break;

case CounterType::MACSEC_FLOW:
Expand Down
12 changes: 8 additions & 4 deletions orchagent/macsecorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

using namespace swss;

#define COUNTERS_MACSEC_SA_ATTR_GROUP "COUNTERS_MACSEC_SA_ATTR"
#define COUNTERS_MACSEC_SA_GROUP "COUNTERS_MACSEC_SA"
#define COUNTERS_MACSEC_FLOW_GROUP "COUNTERS_MACSEC_FLOW"

// AN is a 2 bit number, it can only be 0, 1, 2 or 3
#define MAX_SA_NUMBER (3)

Expand Down Expand Up @@ -63,10 +67,8 @@ class MACsecOrch : public Orch

DBConnector m_counter_db;
Table m_macsec_counters_map;
Table m_macsec_flow_tx_counters_map;
Table m_macsec_flow_rx_counters_map;
Table m_macsec_sa_tx_counters_map;
Table m_macsec_sa_rx_counters_map;
DBConnector m_gb_counter_db;
Table m_gb_macsec_counters_map;
Table m_applPortTable;
FlexCounterManager m_macsec_sa_attr_manager;
FlexCounterManager m_macsec_sa_stat_manager;
Expand Down Expand Up @@ -226,6 +228,8 @@ class MACsecOrch : public Orch
const std::string &obj_name,
sai_object_id_t obj_id);

Table& MACsecCountersMap(MACsecOrchContext &ctx);

/* Flex Counter Manager */
FlexCounterManager& MACsecSaStatManager(MACsecOrchContext &ctx);
FlexCounterManager& MACsecSaAttrStatManager(MACsecOrchContext &ctx);
Expand Down
34 changes: 10 additions & 24 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ const vector<sai_port_stat_t> port_stat_ids =
const vector<sai_port_stat_t> gbport_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_OUT_OCTETS,
SAI_PORT_STAT_IF_OUT_UCAST_PKTS,
SAI_PORT_STAT_IF_OUT_NON_UCAST_PKTS,
SAI_PORT_STAT_IF_IN_DISCARDS,
SAI_PORT_STAT_IF_OUT_DISCARDS,
SAI_PORT_STAT_IF_IN_ERRORS,
Expand Down Expand Up @@ -324,7 +328,7 @@ PortsOrch::PortsOrch(DBConnector *db, DBConnector *stateDb, vector<table_name_wi
m_portStateTable(stateDb, STATE_PORT_TABLE_NAME),
port_stat_manager(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, false),
gb_port_stat_manager("GB_FLEX_COUNTER_DB",
GBPORT_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ,
PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ,
PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, false),
port_buffer_drop_stat_manager(PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_BUFFER_DROP_STAT_POLLING_INTERVAL_MS, false),
queue_stat_manager(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, QUEUE_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, false)
Expand Down Expand Up @@ -2443,7 +2447,7 @@ bool PortsOrch::initPort(const string &alias, const string &role, const int inde
auto port_counter_stats = generateCounterStats(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP);
port_stat_manager.setCounterIdList(p.m_port_id,
CounterType::PORT, port_counter_stats);
auto gbport_counter_stats = generateCounterStats(GBPORT_STAT_COUNTER_FLEX_COUNTER_GROUP);
auto gbport_counter_stats = generateCounterStats(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, true);
if (p.m_system_side_id)
gb_port_stat_manager.setCounterIdList(p.m_system_side_id,
CounterType::PORT, gbport_counter_stats);
Expand Down Expand Up @@ -5713,7 +5717,7 @@ void PortsOrch::generatePortCounterMap()
}

auto port_counter_stats = generateCounterStats(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP);
auto gbport_counter_stats = generateCounterStats(GBPORT_STAT_COUNTER_FLEX_COUNTER_GROUP);
auto gbport_counter_stats = generateCounterStats(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, true);
for (const auto& it: m_portList)
{
// 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.
Expand Down Expand Up @@ -6955,19 +6959,13 @@ void PortsOrch::voqSyncDelLagMember(Port &lag, Port &port)
m_tableVoqSystemLagMemberTable->del(key);
}

std::unordered_set<std::string> PortsOrch::generateCounterStats(const string& type)
std::unordered_set<std::string> PortsOrch::generateCounterStats(const string& type, bool gearbox)
{
std::unordered_set<std::string> counter_stats;
if (type == PORT_STAT_COUNTER_FLEX_COUNTER_GROUP)
{
for (const auto& it: port_stat_ids)
{
counter_stats.emplace(sai_serialize_port_stat(it));
}
}
else if (type == GBPORT_STAT_COUNTER_FLEX_COUNTER_GROUP)
{
for (const auto& it: gbport_stat_ids)
auto& stat_ids = gearbox ? gbport_stat_ids : port_stat_ids;
for (const auto& it: stat_ids)
{
counter_stats.emplace(sai_serialize_port_stat(it));
}
Expand All @@ -6982,18 +6980,6 @@ std::unordered_set<std::string> PortsOrch::generateCounterStats(const string& ty
return counter_stats;
}

void PortsOrch::setGearboxFlexCounterStatus(bool enabled)
{
if (enabled)
{
gb_port_stat_manager.enableFlexCounterGroup();
}
else
{
gb_port_stat_manager.disableFlexCounterGroup();
}
}

void PortsOrch::updateGearboxPortOperStatus(const Port& port)
{
if (!isGearboxEnabled())
Expand Down
4 changes: 1 addition & 3 deletions orchagent/portsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#define VLAN_TAG_LEN 4
#define PORT_STAT_COUNTER_FLEX_COUNTER_GROUP "PORT_STAT_COUNTER"
#define PORT_RATE_COUNTER_FLEX_COUNTER_GROUP "PORT_RATE_COUNTER"
#define GBPORT_STAT_COUNTER_FLEX_COUNTER_GROUP "GBPORT_STAT_COUNTER"
#define PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP "PORT_BUFFER_DROP_STAT"
#define QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP "QUEUE_STAT_COUNTER"
#define QUEUE_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP "QUEUE_WATERMARK_STAT_COUNTER"
Expand Down Expand Up @@ -170,7 +169,6 @@ class PortsOrch : public Orch, public Subject

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

void setGearboxFlexCounterStatus(bool enabled);
void updateGearboxPortOperStatus(const Port& port);

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

std::unordered_set<std::string> generateCounterStats(const string& type);
std::unordered_set<std::string> generateCounterStats(const string& type, bool gearbox = false);

};
#endif /* SWSS_PORTSORCH_H */

0 comments on commit 6478793

Please sign in to comment.