Skip to content
Open
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
8 changes: 8 additions & 0 deletions sonic_data_client/virtual_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,11 @@ func v2rAclRuleStats(paths []string) ([]tablePath, error) {
func v2rPortPhyAttrStats(paths []string) ([]tablePath, error) {
var tblPaths []tablePath
if strings.HasSuffix(paths[KeyIdx], "*") { // All Ethernet ports
Comment thread
FengPan-Frank marked this conversation as resolved.
keyPrefix := strings.TrimSuffix(paths[KeyIdx], "*")
for port, oid := range countersPortNameMap {
if !strings.HasPrefix(port, keyPrefix) {
continue
}
namespace, ok := port2namespaceMap[port]
if !ok {
return nil, fmt.Errorf("%v does not have namespace associated", port)
Expand Down Expand Up @@ -1005,7 +1009,11 @@ func v2rPortPhyAttrStats(paths []string) ([]tablePath, error) {
func v2rPortPhyAttrFieldStats(paths []string) ([]tablePath, error) {
var tblPaths []tablePath
if strings.HasSuffix(paths[KeyIdx], "*") {
keyPrefix := strings.TrimSuffix(paths[KeyIdx], "*")
for port, oid := range countersPortNameMap {
if !strings.HasPrefix(port, keyPrefix) {
continue
}
namespace, ok := port2namespaceMap[port]
if !ok {
return nil, fmt.Errorf("%v does not have namespace associated", port)
Expand Down
70 changes: 70 additions & 0 deletions sonic_data_client/virtual_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,41 @@ func TestV2rPortPhyAttrStats_Wildcard(t *testing.T) {
}
}

func TestV2rPortPhyAttrStats_WildcardPrefixFilter(t *testing.T) {
sdcfg.Init()
restore := setupPortMaps(t)
defer restore()

countersPortNameMap = map[string]string{
"etp0": "oid:0x1000000000001",
"etp1": "oid:0x1000000000002",
}
port2namespaceMap = map[string]string{
"etp0": "",
"etp1": "",
}

// Query Ethernet* should not match etp* keys.
paths := []string{"COUNTERS_DB", "PORT_PHY_ATTR", "Ethernet*"}
tblPaths, err := v2rPortPhyAttrStats(paths)
if err != nil {
t.Fatalf("v2rPortPhyAttrStats returned error: %v", err)
}
if len(tblPaths) != 0 {
t.Fatalf("expected 0 table paths for Ethernet* against etp* map, got %d", len(tblPaths))
}

// Query etp* should match etp keys.
paths = []string{"COUNTERS_DB", "PORT_PHY_ATTR", "etp*"}
tblPaths, err = v2rPortPhyAttrStats(paths)
if err != nil {
t.Fatalf("v2rPortPhyAttrStats returned error: %v", err)
}
if len(tblPaths) != 2 {
t.Fatalf("expected 2 table paths for etp* wildcard, got %d", len(tblPaths))
}
}

func TestV2rPortPhyAttrStats_SinglePort(t *testing.T) {
sdcfg.Init()
restore := setupPortMaps(t)
Expand Down Expand Up @@ -254,6 +289,41 @@ func TestV2rPortPhyAttrFieldStats_Wildcard(t *testing.T) {
}
}

func TestV2rPortPhyAttrFieldStats_WildcardPrefixFilter(t *testing.T) {
sdcfg.Init()
restore := setupPortMaps(t)
defer restore()

countersPortNameMap = map[string]string{
"etp0": "oid:0x1000000000001",
"etp1": "oid:0x1000000000002",
}
port2namespaceMap = map[string]string{
"etp0": "",
"etp1": "",
}

// Query Ethernet* should not match etp* keys.
paths := []string{"COUNTERS_DB", "PORT_PHY_ATTR", "Ethernet*", "phy_rx_signal_detect"}
tblPaths, err := v2rPortPhyAttrFieldStats(paths)
if err != nil {
t.Fatalf("v2rPortPhyAttrFieldStats returned error: %v", err)
}
if len(tblPaths) != 0 {
t.Fatalf("expected 0 table paths for Ethernet* against etp* map, got %d", len(tblPaths))
}

// Query etp* should match etp keys.
paths = []string{"COUNTERS_DB", "PORT_PHY_ATTR", "etp*", "phy_rx_signal_detect"}
tblPaths, err = v2rPortPhyAttrFieldStats(paths)
if err != nil {
t.Fatalf("v2rPortPhyAttrFieldStats returned error: %v", err)
}
if len(tblPaths) != 2 {
t.Fatalf("expected 2 table paths for etp* wildcard, got %d", len(tblPaths))
}
}

func TestV2rPortPhyAttrFieldStats_SinglePort(t *testing.T) {
sdcfg.Init()
restore := setupPortMaps(t)
Expand Down
Loading