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

Add v2r mapping for Fabric Counters in Packet Chassis #341

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8ff0269
Add multi-asic support for Fabric port counters
SuvarnaMeenakshi Jan 15, 2025
316a491
Modify Fabric port name to append asic namespace
SuvarnaMeenakshi Jan 21, 2025
76314e3
Merge remote-tracking branch 'origin/master' into fabric_masic
SuvarnaMeenakshi Jan 21, 2025
65187b8
Modify to work for single asic linecard
SuvarnaMeenakshi Jan 22, 2025
e90e6cd
Add unit-test
SuvarnaMeenakshi Jan 30, 2025
3246434
Revert "Add unit-test"
SuvarnaMeenakshi Jan 30, 2025
728c3d9
Add unit test
SuvarnaMeenakshi Jan 30, 2025
4555836
Fix whitespace
SuvarnaMeenakshi Jan 30, 2025
583707b
Fix white space add comment as per review comment
SuvarnaMeenakshi Jan 30, 2025
c3fa03d
Remove debug prints
SuvarnaMeenakshi Jan 30, 2025
4c38c8d
Remove empty line
SuvarnaMeenakshi Jan 30, 2025
5820035
Update to reset countersFabricPortNameMap
SuvarnaMeenakshi Jan 30, 2025
e12240c
Add comment
SuvarnaMeenakshi Jan 30, 2025
8440cdb
Fix comment
SuvarnaMeenakshi Jan 30, 2025
29ffb43
Fix whitespace
SuvarnaMeenakshi Jan 30, 2025
c2fae6d
Revert "Fix whitespace"
SuvarnaMeenakshi Jan 30, 2025
697005d
Fix white space
SuvarnaMeenakshi Jan 30, 2025
5d7586d
Fix incorrect char and space
SuvarnaMeenakshi Jan 30, 2025
bad1f4a
Remove clean up added for debug
SuvarnaMeenakshi Jan 30, 2025
c4fe5c4
Merge remote-tracking branch 'origin/master' into HEAD
SuvarnaMeenakshi Jan 30, 2025
812b1d0
Use global variable UnitTest as a flag to reinit
SuvarnaMeenakshi Feb 5, 2025
d7b74a5
Modify to use environment variable to specify unit test
SuvarnaMeenakshi Feb 5, 2025
d3261f6
Fix as per review comment
SuvarnaMeenakshi Feb 7, 2025
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
4 changes: 4 additions & 0 deletions sonic_data_client/db_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,10 @@ func populateDbtablePath(prefix, path *gnmipb.Path, pathG2S *map[*gnmipb.Path][]
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we can log errorf instead of returning error, if map is unable to be created. If we are unable to create this map all COUNTERS_DB queries will fail.

}
err = initCountersFabricPortNameMap()
if err != nil {
return err
SuvarnaMeenakshi marked this conversation as resolved.
Show resolved Hide resolved
}
}


Expand Down
98 changes: 97 additions & 1 deletion sonic_data_client/virtual_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ var (
// SONiC interface name to their PFC-WD enabled queues, then to oid map
countersPfcwdNameMap = make(map[string]map[string]string)

// SONiC interface name to their Fabric port name map, then to oid map
countersFabricPortNameMap = make(map[string]string)

// path2TFuncTbl is used to populate trie tree which is reponsible
// for virtual path to real data path translation
pathTransFuncTbl = []pathTransFunc{
Expand All @@ -59,7 +62,10 @@ var (
}, { // PFC WD stats for one or all Ethernet ports
path: []string{"COUNTERS_DB", "COUNTERS", "Ethernet*", "Pfcwd"},
transFunc: v2rTranslate(v2rEthPortPfcwdStats),
},
}, { // stats for one or all Fabric ports
path: []string{"COUNTERS_DB", "COUNTERS", "PORT*"},
transFunc: v2rTranslate(v2rFabricPortStats),
},
}
)

Expand Down Expand Up @@ -117,6 +123,17 @@ func initCountersPfcwdNameMap() error {
}
return nil
}
func initCountersFabricPortNameMap() error {
var err error
fmt.Errorf("in initCountersFabricPortNameMap")
if len(countersFabricPortNameMap) == 0 {
countersFabricPortNameMap, err = getFabricCountersMap("COUNTERS_FABRIC_PORT_NAME_MAP")
if err != nil {
return err
}
}
return nil
}

// Get the mapping between sonic interface name and oids of their PFC-WD enabled queues in COUNTERS_DB
func getPfcwdMap() (map[string]map[string]string, error) {
Expand Down Expand Up @@ -284,6 +301,85 @@ func getCountersMap(tableName string) (map[string]string, error) {
return counter_map, nil
}


// Get the mapping between objects in counters DB, Ex. port name to oid in "COUNTERS_PORT_NAME_MAP" table.
// Aussuming static port name to oid map in COUNTERS table
func getFabricCountersMap(tableName string) (map[string]string, error) {
counter_map := make(map[string]string)
dbName := "COUNTERS_DB"
redis_client_map, err := GetRedisClientsForDb(dbName)
if err != nil {
return nil, err
}
for namespace, redisDb := range redis_client_map {
fv, err := redisDb.HGetAll(tableName).Result()
if err != nil {
log.V(2).Infof("redis HGetAll failed for COUNTERS_DB in namespace %v, tableName: %s", namespace, tableName)
return nil, err
}
namespaceFv := make(map[string]string)
for k, v := range fv {
var namespace_str = ""
if len(namespace) != 0 {
namespace_str = string('-') + namespace
}
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add some comment what are we doing here.

Copy link
Author

Choose a reason for hiding this comment

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

added comments

namespaceFv[k + namespace_str] = v
}
addmap(counter_map, namespaceFv)
log.V(6).Infof("tableName: %s in namespace %v, map %v", tableName, namespace, namespaceFv)
}
return counter_map, nil
}

// Populate real data paths from paths like
// [COUNTER_DB COUNTERS Ethernet*] or [COUNTER_DB COUNTERS Ethernet68]
func v2rFabricPortStats(paths []string) ([]tablePath, error) {
var tblPaths []tablePath
fmt.Errorf("in v2rFabricPortStats")
if strings.HasSuffix(paths[KeyIdx], "*") { // All Ethernet ports
for port, oid := range countersFabricPortNameMap {
var namespace string
if strings.Contains(port, "-"){
namespace = strings.Split(port, "-")[1]
} else {
namespace = ""
}
separator, _ := GetTableKeySeparator(paths[DbIdx], namespace)
tblPath := tablePath{
dbNamespace: namespace,
dbName: paths[DbIdx],
tableName: paths[TblIdx],
tableKey: oid,
delimitor: separator,
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add UT for this scenario ?

Copy link
Author

Choose a reason for hiding this comment

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

Added unit-test to check testGnmiGet for single and multi-namespace scenarios.
This checks if PORT0-asic0 is present for multi-ns and PORT0 is present for single asic.
Also checks for COUNTERS/PORT*

jsonTableKey: port,
}
tblPaths = append(tblPaths, tblPath)
}
} else { //single port
var port, namespace string
port = paths[KeyIdx]
oid, ok := countersFabricPortNameMap[port]
if !ok {
return nil, fmt.Errorf("%v not a valid sonic fabric interface.", port)
}
if strings.Contains(port, "-"){
namespace = strings.Split(port, "-")[1]
} else {
namespace = ""
}
separator, _ := GetTableKeySeparator(paths[DbIdx], namespace)
tblPaths = []tablePath{{
dbNamespace: namespace,
dbName: paths[DbIdx],
tableName: paths[TblIdx],
tableKey: oid,
delimitor: separator,
}}
}
log.V(6).Infof("v2rFabricPortStats: %v", tblPaths)
return tblPaths, nil
}

// Populate real data paths from paths like
// [COUNTER_DB COUNTERS Ethernet*] or [COUNTER_DB COUNTERS Ethernet68]
func v2rEthPortStats(paths []string) ([]tablePath, error) {
Expand Down
Loading