Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macsec] Refactor the logic of macsec name map #2348

Merged
merged 5 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions orchagent/macsecorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2340,10 +2340,6 @@ void MACsecOrch::installCounter(
sai_object_id_t obj_id,
const std::vector<std::string> &stats)
{
FieldValueTuple tuple(obj_name, sai_serialize_object_id(obj_id));
vector<FieldValueTuple> fields;
fields.push_back(tuple);

std::unordered_set<std::string> counter_stats;
for (const auto &stat : stats)
{
Expand All @@ -2353,12 +2349,11 @@ void MACsecOrch::installCounter(
{
case CounterType::MACSEC_SA_ATTR:
MACsecSaAttrStatManager(ctx).setCounterIdList(obj_id, counter_type, counter_stats);
MACsecCountersMap(ctx).set("", fields);
break;

case CounterType::MACSEC_SA:
MACsecSaStatManager(ctx).setCounterIdList(obj_id, counter_type, counter_stats);
MACsecCountersMap(ctx).set("", fields);
MACsecCountersMap(ctx).hset("", obj_name, sai_serialize_object_id(obj_id));
break;

case CounterType::MACSEC_FLOW:
Expand All @@ -2383,19 +2378,11 @@ void MACsecOrch::uninstallCounter(
{
case CounterType::MACSEC_SA_ATTR:
MACsecSaAttrStatManager(ctx).clearCounterIdList(obj_id);
m_counter_db.hdel(COUNTERS_MACSEC_NAME_MAP, obj_name);
break;

case CounterType::MACSEC_SA:
MACsecSaStatManager(ctx).clearCounterIdList(obj_id);
if (direction == SAI_MACSEC_DIRECTION_EGRESS)
{
m_counter_db.hdel(COUNTERS_MACSEC_SA_TX_NAME_MAP, obj_name);
}
else
{
m_counter_db.hdel(COUNTERS_MACSEC_SA_RX_NAME_MAP, obj_name);
}
MACsecCountersMap(ctx).hdel("", obj_name);
break;

case CounterType::MACSEC_FLOW:
Expand Down
53 changes: 53 additions & 0 deletions tests/test_macsec.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from swsscommon import swsscommon
from swsscommon.swsscommon import CounterTable, MacsecCounter
import conftest

import functools
import typing
import re
import time


def to_string(value):
Expand Down Expand Up @@ -389,6 +391,21 @@ def get_macsec_sa(
print(info.group(0))
return info.group(0)

@macsec_sa()
def get_macsec_xpn_counter(
self,
sai: str) -> int:
counter_table = CounterTable(self.dvs.get_counters_db().db_connection)
for i in range(3):
r, value = counter_table.hget(
MacsecCounter(),
sai,
"SAI_MACSEC_SA_ATTR_CURRENT_XPN")
if r: return int(value)
time.sleep(1) # wait a moment for polling counter

return None


class TestMACsec(object):
def init_macsec(
Expand Down Expand Up @@ -658,6 +675,18 @@ def test_macsec_term_orch(self, dvs: conftest.DockerVirtualSwitch, testlog):
peer_mac_address,
macsec_port_identifier,
0))
assert(
inspector.get_macsec_xpn_counter(
port_name,
local_mac_address,
macsec_port_identifier,
0) == packet_number)
assert(
inspector.get_macsec_xpn_counter(
port_name,
peer_mac_address,
macsec_port_identifier,
0) == packet_number)
self.rekey_macsec(
wpa,
port_name,
Expand All @@ -683,6 +712,18 @@ def test_macsec_term_orch(self, dvs: conftest.DockerVirtualSwitch, testlog):
peer_mac_address,
macsec_port_identifier,
1))
assert(
inspector.get_macsec_xpn_counter(
port_name,
local_mac_address,
macsec_port_identifier,
1) == packet_number)
assert(
inspector.get_macsec_xpn_counter(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep original checker

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

port_name,
peer_mac_address,
macsec_port_identifier,
1) == packet_number)
assert(
not inspector.get_macsec_sa(
macsec_port,
Expand All @@ -695,6 +736,18 @@ def test_macsec_term_orch(self, dvs: conftest.DockerVirtualSwitch, testlog):
peer_mac_address,
macsec_port_identifier,
0))
assert(
not inspector.get_macsec_xpn_counter(
port_name,
local_mac_address,
macsec_port_identifier,
0) == packet_number)
assert(
not inspector.get_macsec_xpn_counter(
port_name,
peer_mac_address,
macsec_port_identifier,
0) == packet_number)
# Exit MACsec port
self.deinit_macsec(
wpa,
Expand Down