Skip to content
Snippets Groups Projects

Resolve "gNMI proto encoding"

Merged Ghost User requested to merge 70-gnmi-proto-encoding into 67-overhaul-architecture
6 files
+ 72
44
Compare changes
  • Side-by-side
  • Inline
Files
6
+ 9
14
@@ -3,8 +3,6 @@ package main
import (
"code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi"
"code.fbi.h-da.de/cocsn/gosdn/nucleus"
schema "code.fbi.h-da.de/cocsn/yang-models/generated/arista"
"context"
"github.com/google/uuid"
gpb "github.com/openconfig/gnmi/proto/gnmi"
log "github.com/sirupsen/logrus"
@@ -12,50 +10,47 @@ import (
/*
Simple gnmi request program. Use with cauton and leaf paths only.
Bootstrapping of pnd, device and transport simplified not idiomatic
*/
func main() {
log.SetLevel(log.DebugLevel)
sbi := &nucleus.AristaOC{}
transport := &nucleus.Gnmi{SetNode: sbi.SetNode()}
device := nucleus.Device{
Device: &schema.Device{},
SBI: sbi,
device := &nucleus.Device{
SBI: sbi,
Config: nucleus.DeviceConfig{
Uuid: uuid.New(),
Address: "localhost:9339",
Username: "admin",
Password: "arista",
},
Transport: transport,
Encoding: gpb.Encoding_PROTO,
}
pnd := nucleus.NewPND("openconfig", sbi)
if err := pnd.AddDevice(device); err != nil {
log.Fatal(err)
}
transport := &nucleus.Gnmi{SetNode: sbi.SetNode()}
cfg := &gnmi.Config{
Addr: device.Config.Address,
Password: device.Config.Password,
Username: device.Config.Username,
Encoding: gpb.Encoding_PROTO,
}
ctx := gnmi.NewContext(context.Background(), cfg)
ctx = context.WithValue(ctx, "config", cfg)
transport.SetConfig(cfg)
device.Transport = transport
p := []string{"/interfaces/interface[name=en0]/state/name"}
errors := 0
for _, path := range p {
resp, err := device.Transport.Get(ctx, path)
err := pnd.RequestAll(path)
if err != nil {
log.Debug(err)
errors++
break
}
if err := device.Add(resp); err != nil {
log.Debug(err)
errors++
}
}
percentage := float64(errors) / float64(len(p)) * 100.0
Loading