[macsec] CLI Supports display of gearbox macsec counter (#11113)
Why I did it To support gearbox macsec counter display, following Azure/sonic-swss-common#622. How I did it Use swsscommon CounterTable API
This commit is contained in:
parent
8035e3d9a7
commit
477ed2c344
@ -115,6 +115,19 @@ class SwssSyncClient(mockredis.MockRedis):
|
||||
return [key for key in self.redis if regex.match(key)]
|
||||
|
||||
|
||||
class MacsecCounter:
|
||||
pass
|
||||
|
||||
|
||||
class CounterTable:
|
||||
def __init__(self, db):
|
||||
self.db = db
|
||||
|
||||
def get(self, macsec, name):
|
||||
key = self.db.hget("COUNTERS_MACSEC_NAME_MAP", name)
|
||||
return self.db.get("COUNTERS:" + key)
|
||||
|
||||
|
||||
swsssdk.interface.DBInterface._subscribe_keyspace_notification = _subscribe_keyspace_notification
|
||||
mockredis.MockRedis.config_set = config_set
|
||||
redis.StrictRedis = SwssSyncClient
|
||||
@ -122,3 +135,5 @@ SonicV2Connector.connect = connect_SonicV2Connector
|
||||
swsscommon.SonicV2Connector = SonicV2Connector
|
||||
swsscommon.ConfigDBConnector = ConfigDBConnector
|
||||
swsscommon.ConfigDBPipeConnector = ConfigDBPipeConnector
|
||||
swsscommon.CounterTable = CounterTable
|
||||
swsscommon.MacsecCounter = MacsecCounter
|
||||
|
@ -5,11 +5,13 @@ import click
|
||||
from tabulate import tabulate
|
||||
|
||||
from swsscommon.swsscommon import SonicV2Connector
|
||||
from swsscommon.swsscommon import CounterTable, MacsecCounter
|
||||
|
||||
|
||||
DB_CONNECTOR = SonicV2Connector(use_unix_socket_path=False)
|
||||
DB_CONNECTOR.connect(DB_CONNECTOR.APPL_DB)
|
||||
DB_CONNECTOR.connect(DB_CONNECTOR.COUNTERS_DB)
|
||||
COUNTER_TABLE = CounterTable(DB_CONNECTOR.get_redis_client(DB_CONNECTOR.COUNTERS_DB))
|
||||
|
||||
|
||||
class MACsecAppMeta(object):
|
||||
@ -28,12 +30,8 @@ class MACsecAppMeta(object):
|
||||
|
||||
class MACsecCounters(object):
|
||||
def __init__(self, *args) -> None:
|
||||
key = ":".join(args)
|
||||
counters_id = DB_CONNECTOR.get(
|
||||
DB_CONNECTOR.COUNTERS_DB, self.__class__.get_counter_table_name(), key)
|
||||
counter_key = "COUNTERS:" + counters_id
|
||||
self.counters = DB_CONNECTOR.get_all(
|
||||
DB_CONNECTOR.COUNTERS_DB, counter_key)
|
||||
_, fvs = COUNTER_TABLE.get(MacsecCounter(), ":".join(args))
|
||||
self.counters = dict(fvs)
|
||||
|
||||
|
||||
class MACsecSA(MACsecAppMeta, MACsecCounters):
|
||||
@ -61,10 +59,6 @@ class MACsecIngressSA(MACsecSA):
|
||||
def get_appl_table_name(cls) -> str:
|
||||
return "MACSEC_INGRESS_SA_TABLE"
|
||||
|
||||
@classmethod
|
||||
def get_counter_table_name(cls) -> str:
|
||||
return "COUNTERS_MACSEC_SA_RX_NAME_MAP"
|
||||
|
||||
def get_header(self):
|
||||
return "MACsec Ingress SA ({})\n".format(self.an)
|
||||
|
||||
@ -77,10 +71,6 @@ class MACsecEgressSA(MACsecSA):
|
||||
def get_appl_table_name(cls) -> str:
|
||||
return "MACSEC_EGRESS_SA_TABLE"
|
||||
|
||||
@classmethod
|
||||
def get_counter_table_name(cls) -> str:
|
||||
return "COUNTERS_MACSEC_SA_TX_NAME_MAP"
|
||||
|
||||
def get_header(self):
|
||||
return "MACsec Egress SA ({})\n".format(self.an)
|
||||
|
||||
|
Reference in New Issue
Block a user