Skip to content

Commit 6198aa1

Browse files
authored
Add TelemetryAtomic-related fields to IR. (#881)
1 parent dfbe14e commit 6198aa1

File tree

6 files changed

+116
-46
lines changed

6 files changed

+116
-46
lines changed

gogen/genir_test.go

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,16 +1254,18 @@ func TestGenerateIR(t *testing.T) {
12541254
IsFakeRoot: true,
12551255
},
12561256
"/openconfig-complex/example-presence": {
1257-
Name: "ExamplePresence",
1258-
Type: ygen.Container,
1259-
Path: "/openconfig-complex/example-presence",
1260-
Fields: map[string]*ygen.NodeDetails{},
1261-
PackageName: "",
1262-
ListKeys: nil,
1263-
IsFakeRoot: false,
1264-
BelongingModule: "openconfig-complex",
1265-
RootElementModule: "openconfig-complex",
1266-
DefiningModule: "openconfig-complex",
1257+
Name: "ExamplePresence",
1258+
Type: ygen.Container,
1259+
Path: "/openconfig-complex/example-presence",
1260+
Fields: map[string]*ygen.NodeDetails{},
1261+
PackageName: "",
1262+
ListKeys: nil,
1263+
IsFakeRoot: false,
1264+
BelongingModule: "openconfig-complex",
1265+
RootElementModule: "openconfig-complex",
1266+
DefiningModule: "openconfig-complex",
1267+
TelemetryAtomic: true,
1268+
CompressedTelemetryAtomic: false,
12671269
},
12681270
"/openconfig-complex/model": {
12691271
Name: "Model",
@@ -1675,12 +1677,14 @@ func TestGenerateIR(t *testing.T) {
16751677
},
16761678
},
16771679
},
1678-
ListKeyYANGNames: []string{"key"},
1679-
PackageName: "",
1680-
IsFakeRoot: false,
1681-
BelongingModule: "openconfig-complex",
1682-
RootElementModule: "openconfig-complex",
1683-
DefiningModule: "openconfig-complex",
1680+
ListKeyYANGNames: []string{"key"},
1681+
PackageName: "",
1682+
IsFakeRoot: false,
1683+
BelongingModule: "openconfig-complex",
1684+
RootElementModule: "openconfig-complex",
1685+
DefiningModule: "openconfig-complex",
1686+
TelemetryAtomic: false,
1687+
CompressedTelemetryAtomic: true,
16841688
},
16851689
"/openconfig-complex/model/b/multi-key": {
16861690
Name: "Model_MultiKey",
@@ -1756,12 +1760,14 @@ func TestGenerateIR(t *testing.T) {
17561760
LangType: &ygen.MappedType{NativeType: "E_MultiKey_Key2", IsEnumeratedValue: true, ZeroValue: "0"},
17571761
},
17581762
},
1759-
ListKeyYANGNames: []string{"key1", "key2"},
1760-
PackageName: "",
1761-
IsFakeRoot: false,
1762-
BelongingModule: "openconfig-complex",
1763-
RootElementModule: "openconfig-complex",
1764-
DefiningModule: "openconfig-complex",
1763+
ListKeyYANGNames: []string{"key1", "key2"},
1764+
PackageName: "",
1765+
IsFakeRoot: false,
1766+
BelongingModule: "openconfig-complex",
1767+
RootElementModule: "openconfig-complex",
1768+
DefiningModule: "openconfig-complex",
1769+
TelemetryAtomic: true,
1770+
CompressedTelemetryAtomic: false,
17651771
},
17661772
"/openconfig-complex/model/c/unkeyed-list": {
17671773
Name: "Model_UnkeyedList",
@@ -1905,7 +1911,10 @@ func TestGenerateIR(t *testing.T) {
19051911
},
19061912
},
19071913
},
1908-
ModelData: []*gpb.ModelData{{Name: "openconfig-complex"}},
1914+
ModelData: []*gpb.ModelData{
1915+
{Name: "openconfig-complex"},
1916+
{Name: "openconfig-extensions"},
1917+
},
19091918
},
19101919
}}
19111920

protogen/genir_test.go

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,18 @@ func protoIR(nestedDirectories bool) *ygen.IR {
9090
PackageName: "",
9191
},
9292
"/openconfig-complex/example-presence": {
93-
Name: "ExamplePresence",
94-
Type: ygen.Container,
95-
Path: "/openconfig-complex/example-presence",
96-
Fields: map[string]*ygen.NodeDetails{},
97-
PackageName: "",
98-
ListKeys: nil,
99-
IsFakeRoot: false,
100-
BelongingModule: "openconfig-complex",
101-
RootElementModule: "openconfig-complex",
102-
DefiningModule: "openconfig-complex",
93+
Name: "ExamplePresence",
94+
Type: ygen.Container,
95+
Path: "/openconfig-complex/example-presence",
96+
Fields: map[string]*ygen.NodeDetails{},
97+
PackageName: "",
98+
ListKeys: nil,
99+
IsFakeRoot: false,
100+
BelongingModule: "openconfig-complex",
101+
RootElementModule: "openconfig-complex",
102+
DefiningModule: "openconfig-complex",
103+
TelemetryAtomic: true,
104+
CompressedTelemetryAtomic: false,
103105
},
104106
"/openconfig-complex/model": {
105107
Name: "Model",
@@ -675,12 +677,14 @@ func protoIR(nestedDirectories bool) *ygen.IR {
675677
},
676678
},
677679
},
678-
ListKeyYANGNames: []string{"key"},
679-
PackageName: packageName,
680-
IsFakeRoot: false,
681-
BelongingModule: "openconfig-complex",
682-
RootElementModule: "openconfig-complex",
683-
DefiningModule: "openconfig-complex",
680+
ListKeyYANGNames: []string{"key"},
681+
PackageName: packageName,
682+
IsFakeRoot: false,
683+
BelongingModule: "openconfig-complex",
684+
RootElementModule: "openconfig-complex",
685+
DefiningModule: "openconfig-complex",
686+
TelemetryAtomic: false,
687+
CompressedTelemetryAtomic: true,
684688
},
685689
"/openconfig-complex/model/b/multi-key": {
686690
Name: "MultiKey",
@@ -810,12 +814,14 @@ func protoIR(nestedDirectories bool) *ygen.IR {
810814
},
811815
},
812816
},
813-
ListKeyYANGNames: []string{"key1", "key2"},
814-
PackageName: packageName,
815-
IsFakeRoot: false,
816-
BelongingModule: "openconfig-complex",
817-
RootElementModule: "openconfig-complex",
818-
DefiningModule: "openconfig-complex",
817+
ListKeyYANGNames: []string{"key1", "key2"},
818+
PackageName: packageName,
819+
IsFakeRoot: false,
820+
BelongingModule: "openconfig-complex",
821+
RootElementModule: "openconfig-complex",
822+
DefiningModule: "openconfig-complex",
823+
TelemetryAtomic: true,
824+
CompressedTelemetryAtomic: false,
819825
},
820826
"/openconfig-complex/model/c/unkeyed-list": {
821827
Name: "UnkeyedList",
@@ -960,7 +966,10 @@ func protoIR(nestedDirectories bool) *ygen.IR {
960966
},
961967
},
962968
},
963-
ModelData: []*gpb.ModelData{{Name: "openconfig-complex"}},
969+
ModelData: []*gpb.ModelData{
970+
{Name: "openconfig-complex"},
971+
{Name: "openconfig-extensions"},
972+
},
964973
}
965974
}
966975

testdata/modules/openconfig-complex.yang

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ module openconfig-complex {
33
namespace "urn:occomplex";
44
prefix "oc";
55

6+
import openconfig-extensions { prefix "oc-ext"; }
7+
68
description
79
"A complex test module that is used to verify code generation for a variety
810
of different schema features";
@@ -127,11 +129,13 @@ module openconfig-complex {
127129

128130
grouping top {
129131
container example-presence {
132+
oc-ext:telemetry-atomic;
130133
presence "This is an example presence container";
131134
}
132135

133136
container model {
134137
container a {
138+
oc-ext:telemetry-atomic;
135139
list single-key {
136140
key "key";
137141

@@ -164,6 +168,7 @@ module openconfig-complex {
164168

165169
container b {
166170
list multi-key {
171+
oc-ext:telemetry-atomic;
167172
key "key1
168173
169174
key2"; // Test for irregular spacing

testdata/modules/openconfig-enumcamelcase.yang

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module openconfig-enumcamelcase {
22
prefix "occ";
33
namespace "urn:occ";
44

5+
import openconfig-codegen-extensions { prefix "ocgenext"; }
6+
57
ocgenext:camelcase-name "OpenConfigCamelCase";
68

79
container foo {

ygen/directory.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ func getOrderedDirDetails(langMapper LangMapper, directory map[string]*Directory
167167
if definingModule := yang.RootNode(dir.Entry.Node); definingModule != nil {
168168
definingModuleName = definingModule.Name
169169
}
170+
170171
pd := &ParsedDirectory{
171172
Name: dir.Name,
172173
Path: util.SlicePathToString(dir.Path),
@@ -191,6 +192,29 @@ func getOrderedDirDetails(langMapper LangMapper, directory map[string]*Directory
191192
pd.Type = Container
192193
}
193194

195+
for i, entry := 0, dir.Entry; ; i++ {
196+
exts, err := yang.MatchingEntryExtensions(entry, "openconfig-extensions", "telemetry-atomic")
197+
if err != nil {
198+
return nil, fmt.Errorf("cannot retrieve OpenConfig extensions: %v", err)
199+
}
200+
if len(exts) > 0 {
201+
if i == 0 {
202+
pd.TelemetryAtomic = true
203+
} else {
204+
pd.CompressedTelemetryAtomic = true
205+
}
206+
}
207+
208+
if entry.Parent == nil {
209+
// The very first element is the module -- skip it.
210+
break
211+
}
212+
entry = entry.Parent
213+
if _, ok := directory[entry.Path()]; ok {
214+
break
215+
}
216+
}
217+
194218
pd.Fields = make(map[string]*NodeDetails, len(dir.Fields))
195219
for _, fn := range GetOrderedFieldNames(dir) {
196220
field := dir.Fields[fn]

ygen/ir.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,27 @@ type ParsedDirectory struct {
443443
// statement in YANG:
444444
// https://datatracker.ietf.org/doc/html/rfc7950#section-7.21.1
445445
ConfigFalse bool
446+
// TelemetryAtomic indicates that the node has been modified with the
447+
// OpenConfig extension "telemetry-atomic".
448+
// https://github.com/openconfig/public/blob/master/release/models/openconfig-extensions.yang#L154
449+
//
450+
// For example in the relative path /subinterfaces/subinterface, this
451+
// field be true if and only if the second element, /interface, is
452+
// marked "telemetry-atomic" in the YANG schema.
453+
TelemetryAtomic bool
454+
// CompressedTelemetryAtomic indicates that a parent of the node which
455+
// has been compressed out has been modified with the OpenConfig
456+
// extension "telemetry-atomic".
457+
//
458+
// For example, /interfaces/interface/subinterfaces/subinterface may be
459+
// a path where the /subinterfaces element within the relative path
460+
// /subinterfaces/subinterface is marked "telemetry-atomic". In this
461+
// case, this field will be marked true since the relative path from
462+
// the parent ParsedDirectory contains a compressed-out element that's
463+
// marked "telemetry-atomic".
464+
//
465+
// https://github.com/openconfig/public/blob/master/release/models/openconfig-extensions.yang#L154
466+
CompressedTelemetryAtomic bool
446467
}
447468

448469
// OrderedFieldNames returns the YANG name of all fields belonging to the

0 commit comments

Comments
 (0)