-
Notifications
You must be signed in to change notification settings - Fork 56
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
8ff0269
316a491
76314e3
65187b8
e90e6cd
3246434
728c3d9
4555836
583707b
c3fa03d
4c38c8d
5820035
e12240c
8440cdb
29ffb43
c2fae6d
697005d
5d7586d
bad1f4a
c4fe5c4
812b1d0
d7b74a5
d3261f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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{ | ||
|
@@ -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), | ||
}, | ||
} | ||
) | ||
|
||
|
@@ -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) { | ||
|
@@ -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 | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add some comment what are we doing here. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add UT for this scenario ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added unit-test to check testGnmiGet for single and multi-namespace scenarios. |
||
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) { | ||
|
There was a problem hiding this comment.
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.