Skip to content

Commit 3036d3a

Browse files
Apply goyang patch xfmr memory optimization (sonic-net#79)
* Transformer Infra memory usage enhancement using optimized yang schema generated by goyang during ocbinds build time. * Add yang extensions to transformer annotations --------- Co-authored-by: amrutasali <[email protected]> Co-authored-by: amrutasali <[email protected]>
1 parent 160001d commit 3036d3a

File tree

2 files changed

+152
-67
lines changed

2 files changed

+152
-67
lines changed

models/yang/annotations/sonic-extensions.yang

+35-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ module sonic-extensions {
2525

2626
revision "2019-07-26" {
2727
description
28-
"Add extensionis for redis DB mappings for table, table-keys, table-fields and corresponding transformer methods.";
28+
"Add extensions for redis DB mappings for table, table-keys, table-fields and corresponding transformer methods.";
2929
}
3030

31+
revision "2023-05-20" {
32+
description
33+
"Add extensions for pre transformer, virtual table support, rpc-callback, cascade-delete, value-transformer, table-owner ";
34+
}
3135

3236
// extension statements
3337
extension table-name {
@@ -85,4 +89,34 @@ module sonic-extensions {
8589
description "Db table transformer name.This can be applied to either transform yang value to some different format
8690
or choose a specific DB table based on the type.";
8791
}
92+
93+
extension cascade-delete {
94+
argument "cascade-delete";
95+
description "Cascade delete extension";
96+
}
97+
98+
extension rpc-callback {
99+
argument "callback";
100+
description "RPC callback to be invoked for action";
101+
}
102+
103+
extension value-transformer {
104+
argument "value-transformer-name";
105+
description "Db table field/key value transformer name. This can be applied to transform yang value to some different format.";
106+
}
107+
108+
extension table-owner {
109+
argument "table-owner-flag";
110+
description "Owner of the redis-db table.";
111+
}
112+
113+
extension virtual-table {
114+
argument "virtual-table-flag";
115+
description "Table not present in redis-db.";
116+
}
117+
118+
extension pre-transformer {
119+
argument "pre-transformer-name";
120+
description "Transformer name that will perform pre-translation tasks.";
121+
}
88122
}

patches/goyang/goyang.patch

+117-66
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
1-
diff --git a/README.md b/README.md
2-
index 4d22c1e..805adb5 100644
3-
--- a/README.md
4-
+++ b/README.md
5-
@@ -14,6 +14,7 @@ The forms include:
6-
7-
* tree - a simple tree representation
8-
* types - list understood types extracted from the schema
9-
+* annotate - a template file to annotate the yang modules
10-
11-
The yang package, and the goyang program, are not complete and are a work in
12-
progress.
13-
diff --git a/annotate.go b/annotate.go
14-
new file mode 100644
15-
index 0000000..286a29c
16-
--- /dev/null
17-
+++ b/annotate.go
1+
diff -ruN goyang-dir-orig/annotate.go goyang-dir/annotate.go
2+
--- goyang-dir-orig/annotate.go 1969-12-31 16:00:00.000000000 -0800
3+
+++ goyang-dir/annotate.go 2022-01-17 23:55:14.303340837 -0800
184
@@ -0,0 +1,395 @@
195
+// Copyright 2015 Google Inc.
206
+//
@@ -411,55 +397,111 @@ index 0000000..286a29c
411397
+ }
412398
+}
413399
+
414-
diff --git a/pkg/yang/entry.go b/pkg/yang/entry.go
415-
index dfd4525..cdf6eb1 100644
416-
--- a/pkg/yang/entry.go
417-
+++ b/pkg/yang/entry.go
418-
@@ -29,6 +29,7 @@ import (
400+
diff -ruN goyang-dir-orig/pkg/yang/ast.go goyang-dir/pkg/yang/ast.go
401+
--- goyang-dir-orig/pkg/yang/ast.go 2022-01-17 23:53:09.174875206 -0800
402+
+++ goyang-dir/pkg/yang/ast.go 2022-01-18 14:03:49.606900799 -0800
403+
@@ -391,6 +391,11 @@
404+
descend(name, f.Type)
405+
406+
fn = func(s *Statement, v, p reflect.Value) error {
407+
+ if s.Keyword == "yang-version" ||
408+
+ s.Keyword == "import" {
409+
+ // unset for optimization
410+
+ return nil
411+
+ }
412+
if v.Type() != at {
413+
panic(fmt.Sprintf("given type %s, need type %s", v.Type(), at))
414+
}
415+
diff -ruN goyang-dir-orig/pkg/yang/entry.go goyang-dir/pkg/yang/entry.go
416+
--- goyang-dir-orig/pkg/yang/entry.go 2022-01-17 23:53:09.174875206 -0800
417+
+++ goyang-dir/pkg/yang/entry.go 2022-01-18 15:32:08.428212781 -0800
418+
@@ -29,6 +29,7 @@
419419
"sort"
420420
"strconv"
421421
"strings"
422422
+ "sync"
423423

424424
"github.com/openconfig/goyang/pkg/indent"
425425
)
426-
@@ -80,6 +81,7 @@ type Entry struct {
426+
@@ -79,8 +80,9 @@
427+
Mandatory TriState `json:",omitempty"` // whether this entry is mandatory in the tree
427428

428429
// Fields associated with directory nodes
429-
Dir map[string]*Entry `json:",omitempty"`
430-
+ DirOKeys []string // Ordered Keys list in Dir
431-
Key string `json:",omitempty"` // Optional key name for lists (i.e., maps)
430+
- Dir map[string]*Entry `json:",omitempty"`
431+
- Key string `json:",omitempty"` // Optional key name for lists (i.e., maps)
432+
+ Dir map[string]*Entry `json:",omitempty"`
433+
+ DirOKeys []string // Ordered Keys list in Dir
434+
+ Key string `json:",omitempty"` // Optional key name for lists (i.e., maps)
432435

433436
// Fields associated with leaf nodes
434-
@@ -115,6 +117,11 @@ type Entry struct {
437+
Type *YangType `json:",omitempty"`
438+
@@ -115,6 +117,11 @@
435439
// the augmenting entity per RFC6020 Section 7.15.2. The namespace
436440
// of the Entry should be accessed using the Namespace function.
437441
namespace *Value
438442
+
439443
+ ChildSchemaCache map[reflect.StructTag]*Entry `json:"-"`
440-
+ ChildSchemaMutex sync.RWMutex `json:"-"`
441-
+
444+
+ ChildSchemaMutex sync.RWMutex `json:"-"`
445+
+
442446
+ IsSchemaValidated bool `json:"-"`
443447
}
444448

445449
// An RPCEntry contains information related to an RPC Node.
446-
@@ -264,6 +271,7 @@ func newDirectory(n Node) *Entry {
450+
@@ -262,11 +269,12 @@
451+
// newDirectory returns an empty directory Entry.
452+
func newDirectory(n Node) *Entry {
447453
return &Entry{
448-
Kind: DirectoryEntry,
449-
Dir: make(map[string]*Entry),
454+
- Kind: DirectoryEntry,
455+
- Dir: make(map[string]*Entry),
456+
- Node: n,
457+
- Name: n.NName(),
458+
- Extra: map[string][]interface{}{},
459+
+ Kind: DirectoryEntry,
460+
+ Dir: make(map[string]*Entry),
450461
+ DirOKeys: make([]string, 0),
451-
Node: n,
452-
Name: n.NName(),
453-
Extra: map[string][]interface{}{},
454-
@@ -360,6 +368,7 @@ func (e *Entry) add(key string, value *Entry) *Entry {
462+
+ Node: n,
463+
+ Name: n.NName(),
464+
+ Extra: map[string][]interface{}{},
465+
}
466+
}
467+
468+
@@ -360,6 +368,7 @@
455469
return e
456470
}
457471
e.Dir[key] = value
458472
+ e.DirOKeys = append(e.DirOKeys, key)
459473
return e
460474
}
461475

462-
@@ -999,7 +1008,7 @@ func (e *Entry) ApplyDeviate() []error {
476+
@@ -540,6 +549,7 @@
477+
e.Config, err = tristateValue(s.Config)
478+
e.addError(err)
479+
e.Prefix = getRootPrefix(e)
480+
+ e.Description = ""
481+
return e
482+
case *LeafList:
483+
// Create the equivalent leaf element that we are a list of.
484+
@@ -567,6 +577,7 @@
485+
OrderedBy: s.OrderedBy,
486+
}
487+
e.Prefix = getRootPrefix(e)
488+
+ e.Description = ""
489+
return e
490+
case *Uses:
491+
g := FindGrouping(s, s.Name, map[string]bool{})
492+
@@ -932,6 +943,11 @@
493+
e.Prefix = getRootPrefix(e)
494+
}
495+
496+
+ // unset for optimization
497+
+ e.Description = ""
498+
+ e.Extra = nil
499+
+ e.Augmented = nil
500+
+
501+
return e
502+
}
503+
504+
@@ -999,7 +1015,7 @@
463505
}
464506

465507
if devSpec.Default != "" {
@@ -468,53 +510,53 @@ index dfd4525..cdf6eb1 100644
468510
}
469511

470512
if devSpec.Mandatory != TSUnset {
471-
@@ -1082,6 +1091,7 @@ func (e *Entry) FixChoice() {
513+
@@ -1082,6 +1098,7 @@
472514
}
473515
ce.Parent = ne
474516
e.Dir[k] = ne
475517
+ e.DirOKeys = append(e.DirOKeys, k)
476518
}
477519
}
478520
}
479-
@@ -1252,6 +1262,14 @@ func (e *Entry) shallowDup() *Entry {
521+
@@ -1252,6 +1269,14 @@
480522
// copied we will have to explicitly uncopy them.
481523
ne := *e
482524

483-
+ //Copy the ordered Dir keys to new entry
484-
+ if len(e.DirOKeys) > 0 {
485-
+ ne.DirOKeys = make([]string, 0)
486-
+ for _, key := range e.DirOKeys {
487-
+ ne.DirOKeys = append(ne.DirOKeys, key)
488-
+ }
525+
+ //Copy the ordered Dir keys to new entry
526+
+ if len(e.DirOKeys) > 0 {
527+
+ ne.DirOKeys = make([]string, 0)
528+
+ for _, key := range e.DirOKeys {
529+
+ ne.DirOKeys = append(ne.DirOKeys, key)
530+
+ }
489531
+ }
490532
+
491533
// Now only copy direct children, clear their Dir, and fix up
492534
// Parent pointers.
493535
if e.Dir != nil {
494-
@@ -1275,6 +1293,14 @@ func (e *Entry) dup() *Entry {
536+
@@ -1275,6 +1300,14 @@
495537
// to do that.
496538
ne := *e
497539

498-
+ //Copy the ordered Dir keys to new entry
499-
+ if len(e.DirOKeys) > 0 {
500-
+ ne.DirOKeys = make([]string, 0)
501-
+ for _, key := range e.DirOKeys {
502-
+ ne.DirOKeys = append(ne.DirOKeys, key)
503-
+ }
504-
+ }
540+
+ //Copy the ordered Dir keys to new entry
541+
+ if len(e.DirOKeys) > 0 {
542+
+ ne.DirOKeys = make([]string, 0)
543+
+ for _, key := range e.DirOKeys {
544+
+ ne.DirOKeys = append(ne.DirOKeys, key)
545+
+ }
546+
+ }
505547
+
506548
// Now recurse down to all of our children, fixing up Parent
507549
// pointers as we go.
508550
if e.Dir != nil {
509-
@@ -1310,6 +1336,7 @@ func (e *Entry) merge(prefix *Value, namespace *Value, oe *Entry) {
551+
@@ -1310,6 +1343,7 @@
510552
v.Parent = e
511553
v.Exts = append(v.Exts, oe.Exts...)
512554
e.Dir[k] = v
513555
+ e.DirOKeys = append(e.DirOKeys, k)
514556
}
515557
}
516558
}
517-
@@ -1371,8 +1398,8 @@ func (s sortedErrors) Less(i, j int) bool {
559+
@@ -1371,8 +1405,8 @@
518560
}
519561
return nless(fi[x], fj[x])
520562
}
@@ -525,10 +567,9 @@ index dfd4525..cdf6eb1 100644
525567
case -1:
526568
return true
527569
case 1:
528-
diff --git a/pkg/yang/types.go b/pkg/yang/types.go
529-
index 307610a..ffb59a6 100644
530-
--- a/pkg/yang/types.go
531-
+++ b/pkg/yang/types.go
570+
diff -ruN goyang-dir-orig/pkg/yang/types.go goyang-dir/pkg/yang/types.go
571+
--- goyang-dir-orig/pkg/yang/types.go 2022-01-17 23:53:09.174875206 -0800
572+
+++ goyang-dir/pkg/yang/types.go 2022-01-17 23:55:14.303340837 -0800
532573
@@ -12,6 +12,9 @@
533574
// See the License for the specific language governing permissions and
534575
// limitations under the License.
@@ -539,7 +580,7 @@ index 307610a..ffb59a6 100644
539580
package yang
540581

541582
// This file implements the functions relating to types and typedefs.
542-
@@ -69,6 +72,12 @@ func (d *typeDictionary) findExternal(n Node, prefix, name string) (*Typedef, er
583+
@@ -69,6 +72,12 @@
543584
}
544585
if td := d.find(root, name); td != nil {
545586
return td, nil
@@ -552,19 +593,29 @@ index 307610a..ffb59a6 100644
552593
}
553594
if prefix != "" {
554595
name = prefix + ":" + name
555-
diff --git a/yang.go b/yang.go
556-
index 2480a4e..515d1b3 100644
557-
--- a/yang.go
558-
+++ b/yang.go
559-
@@ -58,6 +58,7 @@ import (
596+
diff -ruN goyang-dir-orig/README.md goyang-dir/README.md
597+
--- goyang-dir-orig/README.md 2022-01-17 23:53:09.174875206 -0800
598+
+++ goyang-dir/README.md 2022-01-17 23:55:14.303340837 -0800
599+
@@ -14,6 +14,7 @@
600+
601+
* tree - a simple tree representation
602+
* types - list understood types extracted from the schema
603+
+* annotate - a template file to annotate the yang modules
604+
605+
The yang package, and the goyang program, are not complete and are a work in
606+
progress.
607+
diff -ruN goyang-dir-orig/yang.go goyang-dir/yang.go
608+
--- goyang-dir-orig/yang.go 2022-01-17 23:53:09.174875206 -0800
609+
+++ goyang-dir/yang.go 2022-01-17 23:55:14.303340837 -0800
610+
@@ -58,6 +58,7 @@
560611
type formatter struct {
561612
name string
562613
f func(io.Writer, []*yang.Entry)
563614
+ utilf func([]string, map[string]*yang.Module)
564615
help string
565616
flags *getopt.Set
566617
}
567-
@@ -208,5 +209,8 @@ Formats:
618+
@@ -208,5 +209,8 @@
568619
entries[x] = yang.ToEntry(mods[n])
569620
}
570621

0 commit comments

Comments
 (0)