diff --git a/cmd/path-traversal/path_traversal.go b/cmd/path-traversal/path_traversal.go index e24c58abb3b7dd9605a769841282afd449229f97..5275f794b6ae4711c91fe94e8db55d79f751cb19 100644 --- a/cmd/path-traversal/path_traversal.go +++ b/cmd/path-traversal/path_traversal.go @@ -2,20 +2,17 @@ package main import ( "code.fbi.h-da.de/cocsn/gosdn/nucleus/util" - schema "code.fbi.h-da.de/cocsn/yang-models/generated/arista" + "code.fbi.h-da.de/cocsn/yang-models/generated/arista" ) func main() { - tree := schema.SchemaTree + schema,_ := arista.Schema() paths := util.NewPaths() - for _,v := range tree { - if v.Parent != nil { - if v.Parent.Name == "device" { - pathElement := paths.ProcessEntry(v) - pathElement.Print() - } - } + paths.ParseSchema(schema, "device") + + for _,v := range paths { + v.Print() } } diff --git a/nucleus/util/path_traversal.go b/nucleus/util/path_traversal.go index 36ba100e1dbdd2b1cf9fb0cc66f8e37695f2c2ea..713f05f7cf038aa21800b72d905a51ea8739d13b 100644 --- a/nucleus/util/path_traversal.go +++ b/nucleus/util/path_traversal.go @@ -3,6 +3,7 @@ package util import ( "fmt" "github.com/openconfig/goyang/pkg/yang" + "github.com/openconfig/ygot/ytypes" ) type PathElement struct { @@ -32,7 +33,7 @@ func NewPaths() Paths { type Paths map[string]*PathElement -func (p Paths)ProcessEntry(e *yang.Entry) *PathElement { +func (p Paths) processEntry(e *yang.Entry) *PathElement { if e.Dir != nil { elem := &PathElement{ Children: make([]*PathElement, len(e.Dir)), @@ -40,7 +41,7 @@ func (p Paths)ProcessEntry(e *yang.Entry) *PathElement { } i := 0 for _,v := range e.Dir { - elem.Children[i] = p.ProcessEntry(v) + elem.Children[i] = p.processEntry(v) i++ } p[e.Name] = elem @@ -50,4 +51,16 @@ func (p Paths)ProcessEntry(e *yang.Entry) *PathElement { Name: e.Name, } return leaf +} + +func (p Paths) ParseSchema(schema *ytypes.Schema, root string) error { + tree := schema.SchemaTree + for _,v := range tree { + if v.Parent != nil { + if v.Parent.Name == root { + p.processEntry(v) + } + } + } + return nil } \ No newline at end of file