Newer
Older
package main
import (
"code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi"
"code.fbi.h-da.de/cocsn/gosdn/nucleus"
"context"
"fmt"
"github.com/google/uuid"
gpb "github.com/openconfig/gnmi/proto/gnmi"
log "github.com/sirupsen/logrus"
"os"
"os/signal"
"syscall"
"time"
)
func main() {
log.SetLevel(log.DebugLevel)
sbi := &nucleus.Arista{}
GoStruct: sbi.Schema().Root,
SBI: sbi,
pnd, err := nucleus.NewPND("openconfig", "a simple openconfig PND", uuid.New(), sbi)
if err != nil {
log.Fatal(err)
}
if err := pnd.AddDevice(&device); err != nil {
Addr: "[2003:e6:1722:fed0:0:242:ac11:5]:6030",
Username: "admin",
Password: "arista",
Encoding: gpb.Encoding_JSON_IETF,
transport,_ := nucleus.NewGnmiTransport(cfg)
paths := []string{"/interfaces/interface/name"}
opts := &gnmi.SubscribeOptions{
UpdatesOnly: false,
Prefix: "",
Mode: "stream",
StreamMode: "sample",
SampleInterval: uint64(10 * time.Second.Nanoseconds()),
SuppressRedundant: false,
HeartbeatInterval: uint64(time.Second.Nanoseconds()),
Paths: gnmi.SplitPaths(paths),
Origin: "",
Target: device.Config.Address,
}
done := make(chan os.Signal, 1)
signal.Notify(done, syscall.SIGILL, syscall.SIGTERM)
ctx := context.WithValue(context.Background(), "opts", opts)
go func() {
if err := transport.Subscribe(ctx); err != nil {
log.Fatal(err)
}
}()
fmt.Println("awaiting signal")
<-done
fmt.Println("exiting")