From 2c1bb039f1e7b3ce74c86893ea2634abbcad2adf Mon Sep 17 00:00:00 2001 From: Junhua Zhai Date: Mon, 20 Jun 2022 11:54:48 +0000 Subject: [PATCH 1/2] Update macsec flex counter --- orchagent/flexcounterorch.cpp | 23 +++++++++++++++---- orchagent/flexcounterorch.h | 2 ++ orchagent/macsecorch.cpp | 42 ++++++++++++++++------------------- orchagent/macsecorch.h | 12 ++++++---- 4 files changed, 48 insertions(+), 31 deletions(-) diff --git a/orchagent/flexcounterorch.cpp b/orchagent/flexcounterorch.cpp index 29563d90a5..ffaac6daaf 100644 --- a/orchagent/flexcounterorch.cpp +++ b/orchagent/flexcounterorch.cpp @@ -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; @@ -52,6 +53,9 @@ unordered_map 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}, }; @@ -59,7 +63,9 @@ FlexCounterOrch::FlexCounterOrch(DBConnector *db, vector &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(); } @@ -119,6 +125,13 @@ void FlexCounterOrch::doTask(Consumer &consumer) vector 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) { @@ -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) diff --git a/orchagent/flexcounterorch.h b/orchagent/flexcounterorch.h index 4f9734c0e2..c00a435b68 100644 --- a/orchagent/flexcounterorch.h +++ b/orchagent/flexcounterorch.h @@ -25,6 +25,8 @@ class FlexCounterOrch: public Orch private: std::shared_ptr m_flexCounterDb = nullptr; std::shared_ptr m_flexCounterGroupTable = nullptr; + std::shared_ptr m_gbflexCounterDb = nullptr; + shared_ptr m_gbflexCounterGroupTable = nullptr; bool m_port_counter_enabled = false; bool m_port_buffer_drop_counter_enabled = false; bool m_hostif_trap_counter_enabled = false; diff --git a/orchagent/macsecorch.cpp b/orchagent/macsecorch.cpp index 70721979d2..ac56fcbd5d 100644 --- a/orchagent/macsecorch.cpp +++ b/orchagent/macsecorch.cpp @@ -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" @@ -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(); } @@ -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, @@ -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: diff --git a/orchagent/macsecorch.h b/orchagent/macsecorch.h index 2472d8c0ef..9c6e2be636 100644 --- a/orchagent/macsecorch.h +++ b/orchagent/macsecorch.h @@ -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) @@ -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; @@ -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); From ab1a75b57840c46bdeda77d0c3f93b6009fd5ddf Mon Sep 17 00:00:00 2001 From: Junhua Zhai Date: Tue, 21 Jun 2022 08:00:52 +0000 Subject: [PATCH 2/2] Not use GBPORT_STAT_COUNTER_FLEX_COUNTER_GROUP --- orchagent/portsorch.cpp | 34 ++++++++++------------------------ orchagent/portsorch.h | 4 +--- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 6d06c6318f..7b90254287 100755 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -248,7 +248,11 @@ const vector port_stat_ids = const vector 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, @@ -324,7 +328,7 @@ PortsOrch::PortsOrch(DBConnector *db, DBConnector *stateDb, vectordel(key); } -std::unordered_set PortsOrch::generateCounterStats(const string& type) +std::unordered_set PortsOrch::generateCounterStats(const string& type, bool gearbox) { std::unordered_set 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)); } @@ -6982,18 +6980,6 @@ std::unordered_set 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()) diff --git a/orchagent/portsorch.h b/orchagent/portsorch.h index ab35277d80..c820d6969d 100755 --- a/orchagent/portsorch.h +++ b/orchagent/portsorch.h @@ -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" @@ -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); @@ -376,7 +374,7 @@ class PortsOrch : public Orch, public Subject void voqSyncDelLagMember(Port &lag, Port &port); unique_ptr m_lagIdAllocator; - std::unordered_set generateCounterStats(const string& type); + std::unordered_set generateCounterStats(const string& type, bool gearbox = false); }; #endif /* SWSS_PORTSORCH_H */