Skip to content

Commit

Permalink
ygot related enhancements and fixes (sonic-net#34)
Browse files Browse the repository at this point in the history
Enhanced the unmarshaling method to update the existing list entries instead of replacing it, and by providing this as one more option in the method.
Optimized the EmitJson method to improve the performance of the Marshaling of object into json data
Fixed the issue in finding the type, if the type is defined as typedf which got included as part of Include statement.
Added the support to synchronize the access of the pathToSchema, ChildSchema, regexp maps
Fixed the issue in MergeStruct method by comparing with src. object and updating the content of the dest. object properly
Added the lint:ignore statment to avoid static check on the methods getNodeName, getObjectFieldName
Fixed the issue to only skip the validation for sonic yang model, since the validation is handled in the CVL.
  • Loading branch information
mbalachandar authored Oct 30, 2020
1 parent 51224de commit 49e5a22
Show file tree
Hide file tree
Showing 5 changed files with 660 additions and 83 deletions.
62 changes: 49 additions & 13 deletions patches/goyang/goyang.patch
Original file line number Diff line number Diff line change
Expand Up @@ -412,45 +412,54 @@ index 0000000..286a29c
+}
+
diff --git a/pkg/yang/entry.go b/pkg/yang/entry.go
index ef658d6..cd3b046 100644
index dfd4525..cdf6eb1 100644
--- a/pkg/yang/entry.go
+++ b/pkg/yang/entry.go
@@ -80,6 +80,7 @@ type Entry struct {
@@ -29,6 +29,7 @@ import (
"sort"
"strconv"
"strings"
+ "sync"

"github.com/openconfig/goyang/pkg/indent"
)
@@ -80,6 +81,7 @@ type Entry struct {

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

// Fields associated with leaf nodes
@@ -115,6 +116,10 @@ type Entry struct {
@@ -115,6 +117,11 @@ type Entry struct {
// the augmenting entity per RFC6020 Section 7.15.2. The namespace
// of the Entry should be accessed using the Namespace function.
namespace *Value
+
+ ChildSchemaCache map[reflect.StructTag]*Entry `json:"-"`
+
+ ChildSchemaMutex sync.RWMutex `json:"-"`
+
+ IsSchemaValidated bool `json:"-"`
}

// An RPCEntry contains information related to an RPC Node.
@@ -264,6 +269,7 @@ func newDirectory(n Node) *Entry {
@@ -264,6 +271,7 @@ func newDirectory(n Node) *Entry {
return &Entry{
Kind: DirectoryEntry,
Dir: make(map[string]*Entry),
+ DirOKeys: make([]string, 0),
Node: n,
Name: n.NName(),
Extra: map[string][]interface{}{},
@@ -366,6 +372,7 @@ func (e *Entry) add(key string, value *Entry) *Entry {
@@ -360,6 +368,7 @@ func (e *Entry) add(key string, value *Entry) *Entry {
return e
}
e.Dir[key] = value
+ e.DirOKeys = append(e.DirOKeys, key)
return e
}

@@ -1007,7 +1014,7 @@ func (e *Entry) ApplyDeviate() []error {
@@ -999,7 +1008,7 @@ func (e *Entry) ApplyDeviate() []error {
}

if devSpec.Default != "" {
Expand All @@ -459,15 +468,15 @@ index ef658d6..cd3b046 100644
}

if devSpec.Mandatory != TSUnset {
@@ -1090,6 +1097,7 @@ func (e *Entry) FixChoice() {
@@ -1082,6 +1091,7 @@ func (e *Entry) FixChoice() {
}
ce.Parent = ne
e.Dir[k] = ne
+ e.DirOKeys = append(e.DirOKeys, k)
}
}
}
@@ -1260,6 +1268,14 @@ func (e *Entry) shallowDup() *Entry {
@@ -1252,6 +1262,14 @@ func (e *Entry) shallowDup() *Entry {
// copied we will have to explicitly uncopy them.
ne := *e

Expand All @@ -482,7 +491,7 @@ index ef658d6..cd3b046 100644
// Now only copy direct children, clear their Dir, and fix up
// Parent pointers.
if e.Dir != nil {
@@ -1283,6 +1299,14 @@ func (e *Entry) dup() *Entry {
@@ -1275,6 +1293,14 @@ func (e *Entry) dup() *Entry {
// to do that.
ne := *e

Expand All @@ -497,15 +506,15 @@ index ef658d6..cd3b046 100644
// Now recurse down to all of our children, fixing up Parent
// pointers as we go.
if e.Dir != nil {
@@ -1317,6 +1341,7 @@ func (e *Entry) merge(prefix *Value, namespace *Value, oe *Entry) {
} else {
@@ -1310,6 +1336,7 @@ func (e *Entry) merge(prefix *Value, namespace *Value, oe *Entry) {
v.Parent = e
v.Exts = append(v.Exts, oe.Exts...)
e.Dir[k] = v
+ e.DirOKeys = append(e.DirOKeys, k)
}
}
}
@@ -1378,8 +1403,8 @@ func (s sortedErrors) Less(i, j int) bool {
@@ -1371,8 +1398,8 @@ func (s sortedErrors) Less(i, j int) bool {
}
return nless(fi[x], fj[x])
}
Expand All @@ -516,6 +525,33 @@ index ef658d6..cd3b046 100644
case -1:
return true
case 1:
diff --git a/pkg/yang/types.go b/pkg/yang/types.go
index 307610a..ffb59a6 100644
--- a/pkg/yang/types.go
+++ b/pkg/yang/types.go
@@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

+// This file is changed by Broadcom.
+// Modifications - Copyright 2019 Broadcom. The term Broadcom refers to Broadcom Inc. and/or its subsidiaries.
+
package yang

// This file implements the functions relating to types and typedefs.
@@ -69,6 +72,12 @@ func (d *typeDictionary) findExternal(n Node, prefix, name string) (*Typedef, er
}
if td := d.find(root, name); td != nil {
return td, nil
+ } else {
+ for _, in := range root.Include {
+ if td := typeDict.find(in.Module, name); td != nil {
+ return td, nil
+ }
+ }
}
if prefix != "" {
name = prefix + ":" + name
diff --git a/yang.go b/yang.go
index 2480a4e..515d1b3 100644
--- a/yang.go
Expand Down
Loading

0 comments on commit 49e5a22

Please sign in to comment.