Skip to content
Snippets Groups Projects
Commit bbd295f7 authored by Malte Bauch's avatar Malte Bauch
Browse files

Merge branch '67-overhaul-architecture' of ssh://code.fbi.h-da.de/cocsn/gosdn...

Merge branch '67-overhaul-architecture' of ssh://code.fbi.h-da.de/cocsn/gosdn into 67-overhaul-architecture
parents cbc0d7a6 e3045ef7
No related branches found
No related tags found
3 merge requests!97Resolve "PND handling via CLI and database",!91"Overhaul Architecture",!90Develop
This commit is part of merge request !91. Comments created here will be created in the context of that merge request.
package main package main
import ( import (
schema "code.fbi.h-da.de/cocsn/yang-models/generated/arista" "code.fbi.h-da.de/cocsn/gosdn/nucleus/util"
"fmt" "code.fbi.h-da.de/cocsn/yang-models/generated/arista"
"github.com/openconfig/goyang/pkg/yang" log "github.com/sirupsen/logrus"
) )
type PathElement struct {
Children []*PathElement
Name string
}
func (p *PathElement)Print() {
printPE(0, p)
}
func printPE(indent int, pe *PathElement) {
for i := 0; i < indent; i++ {
fmt.Print(" ")
}
fmt.Println(pe.Name)
if len(pe.Children) > 0 {
for _,p := range pe.Children {
printPE(indent+1, p)
}
}
}
func main() { func main() {
tree := schema.SchemaTree log.SetLevel(log.DebugLevel)
paths := make(map[string]*PathElement) schema, _ := arista.Schema()
paths := util.NewPaths()
paths.ParseSchema(schema, "device")
for k,v := range tree { for _, v := range paths {
if v.Parent != nil { v.Print()
if v.Parent.Name == "device" {
pathElement := processEntry(v)
pathElement.Print()
paths[k] = pathElement
}
}
} }
}
func processEntry(e *yang.Entry) *PathElement { p := paths.StringBuilder()
if e.Dir != nil { log.Debug(p)
elem := &PathElement{ }
Children: make([]*PathElement, len(e.Dir)),
Name: e.Name,
}
i := 0
for _,v := range e.Dir {
elem.Children[i] = processEntry(v)
i++
}
return elem
}
leaf := &PathElement{
Name: e.Name,
}
return leaf
}
\ No newline at end of file
...@@ -20,7 +20,7 @@ type Device struct { ...@@ -20,7 +20,7 @@ type Device struct {
// use better naming in further develop // use better naming in further develop
// Also all that Interface Call specific logic belongs to SBI! // Also all that Interface Call specific logic belongs to SBI!
func (d Device) Add(resp interface{}) error { func (d Device) Add(resp interface{}) error {
s, err := openconfig.Schema() s, err := d.SBI.Schema()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -34,4 +34,4 @@ func TestDevice_Add(t *testing.T) { ...@@ -34,4 +34,4 @@ func TestDevice_Add(t *testing.T) {
log.Debug(d.SBI.SbiIdentifier()) log.Debug(d.SBI.SbiIdentifier())
}) })
} }
} }
\ No newline at end of file
package nucleus package nucleus
import (
"code.fbi.h-da.de/cocsn/gosdn/nucleus/util"
"code.fbi.h-da.de/cocsn/yang-models/generated/openconfig"
"github.com/openconfig/ygot/ytypes"
)
// SouthboundInterface provides an // SouthboundInterface provides an
// interface for SBI implementations // interface for SBI implementations
type SouthboundInterface interface { type SouthboundInterface interface {
// Deprecated
SbiIdentifier() string SbiIdentifier() string
Schema() (*ytypes.Schema, error)
} }
type Tapi struct { type Tapi struct {
...@@ -11,12 +20,17 @@ type Tapi struct { ...@@ -11,12 +20,17 @@ type Tapi struct {
type OpenConfig struct { type OpenConfig struct {
Transport Transport Transport Transport
schema *ytypes.Schema
} }
func (oc *OpenConfig) SbiIdentifier() string { func (oc *OpenConfig) SbiIdentifier() string {
return "openconfig" return "openconfig"
} }
func (oc *OpenConfig) Schema() (*ytypes.Schema, error) {
return openconfig.Schema()
}
func (oc *OpenConfig) OpenconfigInterfaces(device Device) { func (oc *OpenConfig) OpenconfigInterfaces(device Device) {
resp, err := oc.Transport.Get(nil, nil...) resp, err := oc.Transport.Get(nil, nil...)
if err != nil { if err != nil {
...@@ -24,3 +38,10 @@ func (oc *OpenConfig) OpenconfigInterfaces(device Device) { ...@@ -24,3 +38,10 @@ func (oc *OpenConfig) OpenconfigInterfaces(device Device) {
} }
device.Add(resp) device.Add(resp)
} }
func (oc *OpenConfig) GetFullDeviceInfo(device Device) error {
paths := util.NewPaths()
paths.ParseSchema(oc.schema, "device")
return nil
}
package util
import (
"fmt"
"github.com/openconfig/goyang/pkg/yang"
"github.com/openconfig/ygot/ytypes"
log "github.com/sirupsen/logrus"
"strings"
)
const DELIM = "/"
type PathElement struct {
Children []*PathElement
Name string
}
func (p *PathElement) Print() {
printPE(0, p)
}
func printPE(indent int, pe *PathElement) {
for i := 0; i < indent; i++ {
fmt.Print(" ")
}
fmt.Println(pe.Name)
if len(pe.Children) > 0 {
for _, p := range pe.Children {
printPE(indent+1, p)
}
}
}
func NewPaths() Paths {
return make(map[string]*PathElement)
}
type Paths map[string]*PathElement
func processEntry(e *yang.Entry) *PathElement {
if e.Dir != nil {
elem := &PathElement{
Children: make([]*PathElement, len(e.Dir)),
Name: e.Name,
}
i := 0
for _, v := range e.Dir {
elem.Children[i] = processEntry(v)
i++
}
return elem
}
leaf := &PathElement{
Name: e.Name,
}
return leaf
}
func (p Paths) ParseSchema(schema *ytypes.Schema, root string) error {
tree := schema.SchemaTree
for k, v := range tree {
if v.Parent != nil {
if v.Parent.Name == root {
path := processEntry(v)
p[k] = path
}
}
}
return nil
}
func (p Paths) StringBuilder() []string {
paths := make([]string, 0)
ch := make(chan string)
stop := make(chan bool)
val := make(chan []string)
go appendix(ch, stop, val)
for _, v := range p {
var b strings.Builder
stringBuilder(ch, &b, v)
}
stop <- true
paths = <-val
return paths
}
func appendix(c chan string, stop chan bool,p chan []string) {
paths := make([]string, 0)
var sig bool
for {
select {
case path := <-c:
paths = append(paths, path)
log.Debug(path)
case sig = <-stop:
log.Debug("Signal received: %v", sig)
}
if sig {break}
}
p <- paths
}
func stringBuilder(ch chan string, b *strings.Builder, v *PathElement) {
if b.Len() == 0 {
b.WriteString(DELIM)
}
b.WriteString(v.Name)
if v.Children != nil {
b.WriteString(DELIM)
for _, c := range v.Children {
var b_cpy strings.Builder
b_cpy.WriteString(b.String())
stringBuilder(ch, &b_cpy, c)
}
} else {
log.Debug("leaf")
ch <- b.String()
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment