Skip to content
Snippets Groups Projects
Commit c9e49137 authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

parse notification

parent 09b42989
No related branches found
No related tags found
2 merge requests!91"Overhaul Architecture",!90Develop
...@@ -3,6 +3,7 @@ package main ...@@ -3,6 +3,7 @@ package main
import ( import (
"code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi" "code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi"
"code.fbi.h-da.de/cocsn/gosdn/nucleus" "code.fbi.h-da.de/cocsn/gosdn/nucleus"
"code.fbi.h-da.de/cocsn/yang-models/generated/openconfig"
"context" "context"
"fmt" "fmt"
"github.com/google/uuid" "github.com/google/uuid"
...@@ -12,6 +13,7 @@ import ( ...@@ -12,6 +13,7 @@ import (
func main() { func main() {
sbi := &nucleus.OpenConfig{} sbi := &nucleus.OpenConfig{}
device := nucleus.Device{ device := nucleus.Device{
Device: &openconfig.Device{},
SBI: sbi, SBI: sbi,
Config: nucleus.DeviceConfig{ Config: nucleus.DeviceConfig{
Uuid: uuid.New(), Uuid: uuid.New(),
...@@ -33,11 +35,15 @@ func main() { ...@@ -33,11 +35,15 @@ func main() {
ctx := gnmi.NewContext(context.Background(), cfg) ctx := gnmi.NewContext(context.Background(), cfg)
ctx = context.WithValue(ctx, "config", cfg) ctx = context.WithValue(ctx, "config", cfg)
paths := []string{"interfaces/interface"} paths := []string{""}
req, err := gnmi.NewGetRequest(gnmi.SplitPaths(paths), "") req, err := gnmi.NewGetRequest(gnmi.SplitPaths(paths), "")
resp, err := nucleus.GetWithRequest(ctx, req) resp, err := nucleus.GetWithRequest(ctx, req)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
fmt.Printf("%v", resp) fmt.Println(resp)
if err := device.Add(resp); err != nil {
log.Fatal(err)
}
fmt.Println(device.Config)
} }
package nucleus package nucleus
import ( import (
"code.fbi.h-da.de/cocsn/yang-models/generated/openconfig"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/openconfig/gnmi/proto/gnmi" pb "github.com/openconfig/gnmi/proto/gnmi"
"github.com/openconfig/ygot/ygot" "github.com/openconfig/ygot/ygot"
log "github.com/sirupsen/logrus" "github.com/openconfig/ygot/ytypes"
) )
type Device struct { type Device struct {
...@@ -18,27 +17,15 @@ type Device struct { ...@@ -18,27 +17,15 @@ type Device struct {
// Add adds a property to a device. Please // Add adds a property to a device. Please
// 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{}) { func (d Device) Add(resp interface{}) error {
r := resp.(*gnmi.GetResponse) r := resp.(*pb.GetResponse)
log.Debug(r) rn := r.Notification
device := d.Device.(*openconfig.Device) for _,msg := range rn {
ifaces := make(map[string]*openconfig.OpenconfigInterfaces_Interfaces_Interface) if err := ytypes.SetNode(nil, d.Device, msg.Prefix ,msg); err != nil {
ifaces["test"] = &openconfig.OpenconfigInterfaces_Interfaces_Interface{ return err
Aggregation: nil, }
Config: nil,
Ethernet: nil,
HoldTime: nil,
Name: nil,
RoutedVlan: nil,
State: nil,
Subinterfaces: nil,
} }
// It's possible that the gnmi response already is too Arista-fied to be used w/YGOT return nil
ifs := &openconfig.OpenconfigInterfaces_Interfaces{
Interface: ifaces,
}
device.Interfaces = ifs
d.Device = device
} }
type DeviceConfig struct { type DeviceConfig struct {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment