Skip to content

Commit 4daf930

Browse files
committed
add gNMI wildcard subscription support for OTN devices
1 parent 7c46649 commit 4daf930

4 files changed

Lines changed: 90 additions & 17 deletions

File tree

models/yang/annotations/openconfig-channel-monitor-annot.yang

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module openconfig-channel-monitor-annot {
1818
deviation /oc-chan-monitor:channel-monitors/oc-chan-monitor:channel-monitor {
1919
deviate add {
2020
sonic-ext:key-transformer "oc_name_key_xfmr";
21+
sonic-ext:table-transformer "otn_table_xfmr";
2122
}
2223
}
2324

@@ -60,13 +61,15 @@ module openconfig-channel-monitor-annot {
6061

6162
deviation /oc-chan-monitor:channel-monitors/oc-chan-monitor:channel-monitor/oc-chan-monitor:channels {
6263
deviate add {
63-
sonic-ext:db-name "STATE_DB";
64-
sonic-ext:table-name "OTN_OCM_CHANNEL_TABLE";
64+
sonic-ext:table-transformer "otn_table_xfmr";
6565
}
6666
}
6767

6868
deviation /oc-chan-monitor:channel-monitors/oc-chan-monitor:channel-monitor/oc-chan-monitor:channels/oc-chan-monitor:channel {
6969
deviate add {
70+
sonic-ext:db-name "STATE_DB";
71+
sonic-ext:table-name "OTN_OCM_CHANNEL_TABLE";
72+
sonic-ext:table-transformer "otn_table_xfmr";
7073
sonic-ext:key-transformer "ocm_channel_key_xfmr";
7174
}
7275
}

models/yang/annotations/openconfig-optical-amplifier-annot.yang

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module openconfig-optical-amplifier-annot {
2222
deviation /oc-opt-amp:optical-amplifier/oc-opt-amp:amplifiers/oc-opt-amp:amplifier {
2323
deviate add {
2424
sonic-ext:key-transformer "oc_name_key_xfmr";
25+
sonic-ext:table-transformer "otn_table_xfmr";
2526
}
2627
}
2728

@@ -325,6 +326,7 @@ module openconfig-optical-amplifier-annot {
325326
deviation /oc-opt-amp:optical-amplifier/oc-opt-amp:supervisory-channels/oc-opt-amp:supervisory-channel {
326327
deviate add {
327328
sonic-ext:key-transformer "osc_key_xfmr";
329+
sonic-ext:table-transformer "otn_table_xfmr";
328330
}
329331
}
330332

models/yang/annotations/openconfig-optical-attenuator-annot.yang

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module openconfig-optical-attenuator-annot {
2222
deviation /oc-opt-att:optical-attenuator/oc-opt-att:attenuators/oc-opt-att:attenuator {
2323
deviate add {
2424
sonic-ext:key-transformer "oc_name_key_xfmr";
25+
sonic-ext:table-transformer "otn_table_xfmr";
2526
}
2627
}
2728

translib/transformer/xfmr_otn_openconfig.go

Lines changed: 82 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package transformer
22

33
import (
4+
"errors"
5+
"github.com/Azure/sonic-mgmt-common/translib/db"
46
log "github.com/golang/glog"
57
"strings"
68
)
@@ -17,6 +19,7 @@ func init() {
1719
XlateFuncBind("DbToYang_osc_key_xfmr", DbToYang_osc_key_xfmr)
1820
XlateFuncBind("YangToDb_osc_interface_xfmr", YangToDb_osc_interface_xfmr)
1921
XlateFuncBind("DbToYang_osc_interface_xfmr", DbToYang_osc_interface_xfmr)
22+
XlateFuncBind("otn_table_xfmr", otn_table_xfmr)
2023
}
2124

2225
// Generic KeyXfmr for openconfig "name"
@@ -74,30 +77,48 @@ var YangToDb_ocm_channel_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (s
7477
}
7578

7679
var DbToYang_ocm_channel_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) {
77-
var err error
7880
rmap := make(map[string]interface{})
79-
key := inParams.key
80-
TableKeys := strings.Split(key, "|")
81+
tableKeys := strings.Split(inParams.key, "|")
82+
83+
if len(tableKeys) >= 2 {
84+
rmap["lower-frequency"] = tableKeys[1]
85+
}
8186

82-
if len(TableKeys) >= 2 {
83-
//TableKeys[0] = name, TableKeys[1] = lower-frequency
84-
rmap["lower-frequency"] = TableKeys[1]
87+
tableName := ""
88+
if strings.Contains(inParams.uri, "channels/channel") {
89+
tableName = "OTN_OCM_CHANNEL_TABLE"
8590
}
8691

87-
// Find the row for this key in the cached DB data
88-
data := (*inParams.dbDataMap)[inParams.curDb] // map[string]TblData
92+
upperFreq := ""
8993

90-
for _, tbl := range data {
91-
if row, ok := tbl[inParams.key]; ok {
92-
if val, ok2 := row.Field["upper-frequency"]; ok2 {
93-
rmap["upper-frequency"] = val
94+
// 1. Try Cache
95+
if inParams.dbDataMap != nil && tableName != "" {
96+
if tblData, ok := (*inParams.dbDataMap)[inParams.curDb][tableName]; ok {
97+
if row, ok2 := tblData[inParams.key]; ok2 {
98+
upperFreq = row.Field["upper-frequency"]
9499
}
95-
break
96100
}
97101
}
98-
log.Info("DbToYang_ocm_channel_key_xfmr : - ", rmap)
99102

100-
return rmap, err
103+
// 2. Direct Redis Fetch (fixes the undefined: db error and the type mismatch)
104+
if upperFreq == "" && tableName != "" {
105+
ts := &db.TableSpec{Name: tableName}
106+
// Using Comp for composite keys allows the driver to handle the '|' separator correctly
107+
rowKey := db.Key{Comp: strings.Split(inParams.key, "|")}
108+
109+
entry, err := inParams.dbs[inParams.curDb].GetEntry(ts, rowKey)
110+
if err == nil {
111+
upperFreq = entry.Field["upper-frequency"]
112+
}
113+
}
114+
115+
if upperFreq != "" {
116+
rmap["upper-frequency"] = upperFreq
117+
} else {
118+
log.Warningf("DbToYang_ocm_channel_key_xfmr: Could not resolve upper-frequency for %s", inParams.key)
119+
}
120+
121+
return rmap, nil
101122
}
102123

103124
var YangToDb_ocm_lower_frequency_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) {
@@ -147,3 +168,49 @@ var DbToYang_osc_interface_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (m
147168

148169
return rmap, err
149170
}
171+
172+
var otn_table_xfmr TableXfmrFunc = func(inParams XfmrParams) ([]string, error) {
173+
174+
// Check for nil
175+
if inParams.uri == "" {
176+
log.Error("otn_table_xfmr: uri is empty!")
177+
return nil, errors.New("otn_table_xfmr: uri is empty")
178+
}
179+
180+
pathInfo := NewPathInfo(inParams.uri)
181+
targetUriPath := pathInfo.YangPath
182+
183+
tblList := []string{}
184+
185+
switch {
186+
case strings.HasPrefix(targetUriPath, "/openconfig-optical-attenuator:optical-attenuator/attenuators/attenuator"):
187+
tblList = append(tblList, "OTN_ATTENUATOR")
188+
189+
// 1. Check the specific LIST first (Longer path)
190+
case strings.HasPrefix(targetUriPath, "/openconfig-channel-monitor:channel-monitors/channel-monitor/channels/channel"):
191+
tblList = append(tblList, "OTN_OCM_CHANNEL_TABLE")
192+
193+
// 2. Check the CONTAINER next (Shorter path)
194+
case strings.HasPrefix(targetUriPath, "/openconfig-channel-monitor:channel-monitors/channel-monitor/channels"):
195+
// Returning empty here forces the framework to recurse
196+
// down to the 'channel' list where it will find the table above.
197+
return tblList, nil
198+
199+
// 3. Check the PARENT MONITOR
200+
case strings.HasPrefix(targetUriPath, "/openconfig-channel-monitor:channel-monitors/channel-monitor"):
201+
tblList = append(tblList, "OTN_OCM")
202+
203+
case strings.HasPrefix(targetUriPath, "/openconfig-optical-amplifier:optical-amplifier/amplifiers/amplifier"):
204+
tblList = append(tblList, "OTN_OA")
205+
206+
case strings.HasPrefix(targetUriPath, "/openconfig-optical-amplifier:optical-amplifier/supervisory-channels/supervisory-channel"):
207+
tblList = append(tblList, "OTN_OSC")
208+
}
209+
210+
if len(tblList) == 0 {
211+
log.Errorf("otn_table_xfmr: NO MATCHING TABLE for yangPath=%s", targetUriPath)
212+
return nil, errors.New("otn_table_xfmr: no matching table")
213+
}
214+
215+
return tblList, nil
216+
}

0 commit comments

Comments
 (0)