Skip to content

Commit 18ea840

Browse files
qbdwlrPterosaur
andauthored
[macsec]: MACsec statistics support (#1867)
Co-authored-by: Ze Gan <[email protected]>
1 parent 0c46242 commit 18ea840

File tree

4 files changed

+158
-13
lines changed

4 files changed

+158
-13
lines changed

orchagent/flex_counter/flex_counter_manager.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const unordered_map<CounterType, string> FlexCounterManager::counter_id_field_lo
3939
{ CounterType::PORT, PORT_COUNTER_ID_LIST },
4040
{ CounterType::QUEUE, QUEUE_COUNTER_ID_LIST },
4141
{ CounterType::MACSEC_SA_ATTR, MACSEC_SA_ATTR_ID_LIST },
42+
{ CounterType::MACSEC_SA, MACSEC_SA_COUNTER_ID_LIST },
43+
{ CounterType::MACSEC_FLOW, MACSEC_FLOW_COUNTER_ID_LIST },
4244
{ CounterType::ACL_COUNTER, ACL_COUNTER_ATTR_ID_LIST },
4345
{ CounterType::TUNNEL, TUNNEL_COUNTER_ID_LIST },
4446
};

orchagent/flex_counter/flex_counter_manager.h

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ enum class CounterType
2626
PORT_DEBUG,
2727
SWITCH_DEBUG,
2828
MACSEC_SA_ATTR,
29+
MACSEC_SA,
30+
MACSEC_FLOW,
2931
ACL_COUNTER,
3032
TUNNEL,
3133
};

orchagent/macsecorch.cpp

+141-11
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
#define AVAILABLE_ACL_PRIORITIES_LIMITATION (32)
2020
#define EAPOL_ETHER_TYPE (0x888e)
2121
#define MACSEC_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS (1000)
22-
#define COUNTERS_MACSEC_ATTR_GROUP "COUNTERS_MACSEC_ATTR"
22+
#define COUNTERS_MACSEC_SA_ATTR_GROUP "COUNTERS_MACSEC_SA_ATTR"
23+
#define COUNTERS_MACSEC_SA_GROUP "COUNTERS_MACSEC_SA"
24+
#define COUNTERS_MACSEC_FLOW_GROUP "COUNTERS_MACSEC_FLOW"
2325

2426
extern sai_object_id_t gSwitchId;
2527
extern sai_macsec_api_t *sai_macsec_api;
@@ -35,6 +37,62 @@ static const std::vector<std::string> macsec_sa_attrs =
3537
{
3638
"SAI_MACSEC_SA_ATTR_CURRENT_XPN",
3739
};
40+
static const std::vector<std::string> macsec_sa_ingress_stats =
41+
{
42+
"SAI_MACSEC_SA_STAT_OCTETS_ENCRYPTED",
43+
"SAI_MACSEC_SA_STAT_OCTETS_PROTECTED",
44+
"SAI_MACSEC_SA_STAT_IN_PKTS_UNCHECKED",
45+
"SAI_MACSEC_SA_STAT_IN_PKTS_DELAYED",
46+
"SAI_MACSEC_SA_STAT_IN_PKTS_LATE",
47+
"SAI_MACSEC_SA_STAT_IN_PKTS_INVALID",
48+
"SAI_MACSEC_SA_STAT_IN_PKTS_NOT_VALID",
49+
"SAI_MACSEC_SA_STAT_IN_PKTS_NOT_USING_SA",
50+
"SAI_MACSEC_SA_STAT_IN_PKTS_UNUSED_SA",
51+
"SAI_MACSEC_SA_STAT_IN_PKTS_OK",
52+
};
53+
static const std::vector<std::string> macsec_sa_egress_stats =
54+
{
55+
"SAI_MACSEC_SA_STAT_OCTETS_ENCRYPTED",
56+
"SAI_MACSEC_SA_STAT_OCTETS_PROTECTED",
57+
"SAI_MACSEC_SA_STAT_OUT_PKTS_ENCRYPTED",
58+
"SAI_MACSEC_SA_STAT_OUT_PKTS_PROTECTED",
59+
};
60+
static const std::vector<std::string> macsec_flow_ingress_stats =
61+
{
62+
"SAI_MACSEC_FLOW_STAT_OTHER_ERR",
63+
"SAI_MACSEC_FLOW_STAT_OCTETS_UNCONTROLLED",
64+
"SAI_MACSEC_FLOW_STAT_OCTETS_CONTROLLED",
65+
"SAI_MACSEC_FLOW_STAT_UCAST_PKTS_UNCONTROLLED",
66+
"SAI_MACSEC_FLOW_STAT_UCAST_PKTS_CONTROLLED",
67+
"SAI_MACSEC_FLOW_STAT_MULTICAST_PKTS_UNCONTROLLED",
68+
"SAI_MACSEC_FLOW_STAT_MULTICAST_PKTS_CONTROLLED",
69+
"SAI_MACSEC_FLOW_STAT_BROADCAST_PKTS_UNCONTROLLED",
70+
"SAI_MACSEC_FLOW_STAT_BROADCAST_PKTS_CONTROLLED",
71+
"SAI_MACSEC_FLOW_STAT_CONTROL_PKTS",
72+
"SAI_MACSEC_FLOW_STAT_PKTS_UNTAGGED",
73+
"SAI_MACSEC_FLOW_STAT_IN_TAGGED_CONTROL_PKTS",
74+
"SAI_MACSEC_FLOW_STAT_IN_PKTS_NO_TAG",
75+
"SAI_MACSEC_FLOW_STAT_IN_PKTS_BAD_TAG",
76+
"SAI_MACSEC_FLOW_STAT_IN_PKTS_NO_SCI",
77+
"SAI_MACSEC_FLOW_STAT_IN_PKTS_UNKNOWN_SCI",
78+
"SAI_MACSEC_FLOW_STAT_IN_PKTS_OVERRUN",
79+
};
80+
static const std::vector<std::string> macsec_flow_egress_stats =
81+
{
82+
"SAI_MACSEC_FLOW_STAT_OTHER_ERR",
83+
"SAI_MACSEC_FLOW_STAT_OCTETS_UNCONTROLLED",
84+
"SAI_MACSEC_FLOW_STAT_OCTETS_CONTROLLED",
85+
"SAI_MACSEC_FLOW_STAT_OUT_OCTETS_COMMON",
86+
"SAI_MACSEC_FLOW_STAT_UCAST_PKTS_UNCONTROLLED",
87+
"SAI_MACSEC_FLOW_STAT_UCAST_PKTS_CONTROLLED",
88+
"SAI_MACSEC_FLOW_STAT_MULTICAST_PKTS_UNCONTROLLED",
89+
"SAI_MACSEC_FLOW_STAT_MULTICAST_PKTS_CONTROLLED",
90+
"SAI_MACSEC_FLOW_STAT_BROADCAST_PKTS_UNCONTROLLED",
91+
"SAI_MACSEC_FLOW_STAT_BROADCAST_PKTS_CONTROLLED",
92+
"SAI_MACSEC_FLOW_STAT_CONTROL_PKTS",
93+
"SAI_MACSEC_FLOW_STAT_PKTS_UNTAGGED",
94+
"SAI_MACSEC_FLOW_STAT_OUT_PKTS_TOO_LONG",
95+
};
3896

3997
template <typename T, typename... Args>
4098
static bool extract_variables(const std::string &input, char delimiter, T &output, Args &... args)
@@ -479,8 +537,20 @@ MACsecOrch::MACsecOrch(
479537
m_state_macsec_ingress_sa(state_db, STATE_MACSEC_INGRESS_SA_TABLE_NAME),
480538
m_counter_db("COUNTERS_DB", 0),
481539
m_macsec_counters_map(&m_counter_db, COUNTERS_MACSEC_NAME_MAP),
482-
m_macsec_flex_counter_manager(
483-
COUNTERS_MACSEC_ATTR_GROUP,
540+
m_macsec_flow_tx_counters_map(&m_counter_db, COUNTERS_MACSEC_FLOW_TX_NAME_MAP),
541+
m_macsec_flow_rx_counters_map(&m_counter_db, COUNTERS_MACSEC_FLOW_RX_NAME_MAP),
542+
m_macsec_sa_tx_counters_map(&m_counter_db, COUNTERS_MACSEC_SA_TX_NAME_MAP),
543+
m_macsec_sa_rx_counters_map(&m_counter_db, COUNTERS_MACSEC_SA_RX_NAME_MAP),
544+
m_macsec_sa_attr_manager(
545+
COUNTERS_MACSEC_SA_ATTR_GROUP,
546+
StatsMode::READ,
547+
MACSEC_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true),
548+
m_macsec_sa_stat_manager(
549+
COUNTERS_MACSEC_SA_GROUP,
550+
StatsMode::READ,
551+
MACSEC_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true),
552+
m_macsec_flow_stat_manager(
553+
COUNTERS_MACSEC_FLOW_GROUP,
484554
StatsMode::READ,
485555
MACSEC_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true)
486556
{
@@ -1139,7 +1209,7 @@ bool MACsecOrch::updateMACsecPort(MACsecPort &macsec_port, const TaskArgs &port_
11391209
}
11401210
else
11411211
{
1142-
SWSS_LOG_WARN("Unknow Cipher Suite %s", cipher_suite.c_str());
1212+
SWSS_LOG_WARN("Unknown Cipher Suite %s", cipher_suite.c_str());
11431213
return false;
11441214
}
11451215
}
@@ -1793,15 +1863,17 @@ task_process_status MACsecOrch::createMACsecSA(
17931863
sc->m_sa_ids.erase(an);
17941864
});
17951865

1796-
installCounter(CounterType::MACSEC_SA_ATTR, port_sci_an, sc->m_sa_ids[an], macsec_sa_attrs);
1866+
installCounter(CounterType::MACSEC_SA_ATTR, direction, port_sci_an, sc->m_sa_ids[an], macsec_sa_attrs);
17971867
std::vector<FieldValueTuple> fvVector;
17981868
fvVector.emplace_back("state", "ok");
17991869
if (direction == SAI_MACSEC_DIRECTION_EGRESS)
18001870
{
1871+
installCounter(CounterType::MACSEC_SA, direction, port_sci_an, sc->m_sa_ids[an], macsec_sa_egress_stats);
18011872
m_state_macsec_egress_sa.set(swss::join('|', port_name, sci, an), fvVector);
18021873
}
18031874
else
18041875
{
1876+
installCounter(CounterType::MACSEC_SA, direction, port_sci_an, sc->m_sa_ids[an], macsec_sa_ingress_stats);
18051877
m_state_macsec_ingress_sa.set(swss::join('|', port_name, sci, an), fvVector);
18061878
}
18071879

@@ -1836,7 +1908,8 @@ task_process_status MACsecOrch::deleteMACsecSA(
18361908

18371909
auto result = task_success;
18381910

1839-
uninstallCounter(port_sci_an, ctx.get_macsec_sc()->m_sa_ids[an]);
1911+
uninstallCounter(CounterType::MACSEC_SA_ATTR, direction, port_sci_an, ctx.get_macsec_sc()->m_sa_ids[an]);
1912+
uninstallCounter(CounterType::MACSEC_SA, direction, port_sci_an, ctx.get_macsec_sc()->m_sa_ids[an]);
18401913
if (!deleteMACsecSA(ctx.get_macsec_sc()->m_sa_ids[an]))
18411914
{
18421915
SWSS_LOG_WARN("Cannot delete the MACsec SA %s.", port_sci_an.c_str());
@@ -1963,28 +2036,85 @@ bool MACsecOrch::deleteMACsecSA(sai_object_id_t sa_id)
19632036

19642037
void MACsecOrch::installCounter(
19652038
CounterType counter_type,
2039+
sai_macsec_direction_t direction,
19662040
const std::string &obj_name,
19672041
sai_object_id_t obj_id,
19682042
const std::vector<std::string> &stats)
19692043
{
19702044
FieldValueTuple tuple(obj_name, sai_serialize_object_id(obj_id));
19712045
vector<FieldValueTuple> fields;
19722046
fields.push_back(tuple);
1973-
m_macsec_counters_map.set("", fields);
19742047

19752048
std::unordered_set<std::string> counter_stats;
19762049
for (const auto &stat : stats)
19772050
{
19782051
counter_stats.emplace(stat);
19792052
}
1980-
m_macsec_flex_counter_manager.setCounterIdList(obj_id, counter_type, counter_stats);
2053+
switch(counter_type)
2054+
{
2055+
case CounterType::MACSEC_SA_ATTR:
2056+
m_macsec_sa_attr_manager.setCounterIdList(obj_id, counter_type, counter_stats);
2057+
m_macsec_counters_map.set("", fields);
2058+
break;
2059+
2060+
case CounterType::MACSEC_SA:
2061+
m_macsec_sa_stat_manager.setCounterIdList(obj_id, counter_type, counter_stats);
2062+
if (direction == SAI_MACSEC_DIRECTION_EGRESS)
2063+
{
2064+
m_macsec_sa_tx_counters_map.set("", fields);
2065+
}
2066+
else
2067+
{
2068+
m_macsec_sa_rx_counters_map.set("", fields);
2069+
}
2070+
break;
2071+
2072+
case CounterType::MACSEC_FLOW:
2073+
m_macsec_flow_stat_manager.setCounterIdList(obj_id, counter_type, counter_stats);
2074+
break;
2075+
2076+
default:
2077+
SWSS_LOG_ERROR("Failed to install unknown counter type %u.\n",
2078+
static_cast<uint32_t>(counter_type));
2079+
break;
2080+
}
19812081
}
19822082

1983-
void MACsecOrch::uninstallCounter(const std::string &obj_name, sai_object_id_t obj_id)
2083+
void MACsecOrch::uninstallCounter(
2084+
CounterType counter_type,
2085+
sai_macsec_direction_t direction,
2086+
const std::string &obj_name,
2087+
sai_object_id_t obj_id)
19842088
{
1985-
m_macsec_flex_counter_manager.clearCounterIdList(obj_id);
2089+
switch(counter_type)
2090+
{
2091+
case CounterType::MACSEC_SA_ATTR:
2092+
m_macsec_sa_attr_manager.clearCounterIdList(obj_id);
2093+
m_counter_db.hdel(COUNTERS_MACSEC_NAME_MAP, obj_name);
2094+
break;
2095+
2096+
case CounterType::MACSEC_SA:
2097+
m_macsec_sa_stat_manager.clearCounterIdList(obj_id);
2098+
if (direction == SAI_MACSEC_DIRECTION_EGRESS)
2099+
{
2100+
m_counter_db.hdel(COUNTERS_MACSEC_SA_TX_NAME_MAP, obj_name);
2101+
}
2102+
else
2103+
{
2104+
m_counter_db.hdel(COUNTERS_MACSEC_SA_RX_NAME_MAP, obj_name);
2105+
}
2106+
break;
2107+
2108+
case CounterType::MACSEC_FLOW:
2109+
m_macsec_flow_stat_manager.clearCounterIdList(obj_id);
2110+
break;
2111+
2112+
default:
2113+
SWSS_LOG_ERROR("Failed to uninstall unknown counter type %u.\n",
2114+
static_cast<uint32_t>(counter_type));
2115+
break;
2116+
}
19862117

1987-
m_counter_db.hdel(COUNTERS_MACSEC_NAME_MAP, obj_name);
19882118
}
19892119

19902120
bool MACsecOrch::initMACsecACLTable(

orchagent/macsecorch.h

+13-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ class MACsecOrch : public Orch
6363

6464
DBConnector m_counter_db;
6565
Table m_macsec_counters_map;
66-
FlexCounterManager m_macsec_flex_counter_manager;
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+
FlexCounterManager m_macsec_sa_attr_manager;
71+
FlexCounterManager m_macsec_sa_stat_manager;
72+
FlexCounterManager m_macsec_flow_stat_manager;
6773

6874
struct MACsecACLTable
6975
{
@@ -197,10 +203,15 @@ class MACsecOrch : public Orch
197203
/* Counter */
198204
void installCounter(
199205
CounterType counter_type,
206+
sai_macsec_direction_t direction,
200207
const std::string &obj_name,
201208
sai_object_id_t obj_id,
202209
const std::vector<std::string> &stats);
203-
void uninstallCounter(const std::string &obj_name, sai_object_id_t obj_id);
210+
void uninstallCounter(
211+
CounterType counter_type,
212+
sai_macsec_direction_t direction,
213+
const std::string &obj_name,
214+
sai_object_id_t obj_id);
204215

205216
/* MACsec ACL */
206217
bool initMACsecACLTable(

0 commit comments

Comments
 (0)