Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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"
"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.AristaOC{}
transport := &nucleus.Gnmi{
SetNode: sbi.SetNode(),
RespChan: make(chan *gpb.SubscribeResponse),
}
device := nucleus.Device{
Device: &schema.Device{},
SBI: sbi,
Config: nucleus.DeviceConfig{
Uuid: uuid.New(),
Address: "[fdfd::ce05]:6030",
Username: "admin",
Password: "arista",
},
Transport: transport,
}
pnd := nucleus.NewPND("openconfig", sbi)
if err := pnd.AddDevice(device); err != nil {
log.Fatal(err)
}
cfg := &gnmi.Config{
Addr: device.Config.Address,
Password: device.Config.Password,
Username: device.Config.Username,
}
ctx := gnmi.NewContext(context.Background(), cfg)
ctx = context.WithValue(ctx, "config", 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(ctx, "opts", opts)
go func() {
if err := transport.Subscribe(ctx); err != nil {
log.Fatal(err)
}
}()
fmt.Println("awaiting signal")
<-done
fmt.Println("exiting")
}