-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
150 lines (145 loc) · 3.11 KB
/
main.go
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package main
import (
"context"
"log"
"os"
"sync"
"time"
srlndk "github.com/srl-wim/protos"
"github.com/srl-wim/srl-ndk-git/agent"
"google.golang.org/grpc/metadata"
)
func main() {
log.SetFlags(log.LstdFlags | log.Llongfile)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx = metadata.AppendToOutgoingContext(ctx, "agent_name", "ndk-git")
a, err := agent.NewAgent(ctx, "ndk-git")
if err != nil {
log.Printf("failed to create agent: %v", err)
os.Exit(1)
}
go agent.StartJSONRPCServer(a)
log.Printf("test")
wg := new(sync.WaitGroup)
wg.Add(1)
go a.KeepAlive(ctx, time.Minute)
// Config notifications
wg.Add(1)
go func() {
defer wg.Done()
appIDChan := a.StartConfigNotificationStream(ctx)
for {
select {
case event := <-appIDChan:
log.Printf("Config notification: %+v", event)
for _, item := range event.Notification {
switch x := item.SubscriptionTypes.(type) {
case *srlndk.Notification_Config:
resp := item.GetConfig()
if resp.Data != nil {
a.HandleConfigEvent(resp.Op, resp.Key, &resp.Data.Json)
} else {
a.HandleConfigEvent(resp.Op, resp.Key, nil)
}
default:
log.Printf("\nGot unhandled message %s ", x)
}
}
case <-ctx.Done():
return
}
}
}()
//time.Sleep(time.Second)
// AppId notifications
wg.Add(1)
go func() {
defer wg.Done()
appIDChan := a.StartAppIDNotificationStream(ctx, 0)
for {
select {
case event := <-appIDChan:
log.Printf("appID notification: %+v", event)
case <-ctx.Done():
return
}
}
}()
//time.Sleep(time.Second)
// BFDSession notifications
wg.Add(1)
go func() {
defer wg.Done()
appIDChan := a.StartBFDSessionNotificationStream(ctx, nil, nil, 0)
for {
select {
case event := <-appIDChan:
log.Printf("BFDSession notification: %+v", event)
case <-ctx.Done():
return
}
}
}()
//time.Sleep(time.Second)
// NwInst notifications
wg.Add(1)
go func() {
defer wg.Done()
appIDChan := a.StartNwInstNotificationStream(ctx)
for {
select {
case event := <-appIDChan:
log.Printf("NwInst notification: %+v", event)
case <-ctx.Done():
return
}
}
}()
//time.Sleep(time.Second)
// Interface notifications
wg.Add(1)
go func() {
defer wg.Done()
appIDChan := a.StartInterfaceNotificationStream(ctx, "")
for {
select {
case event := <-appIDChan:
log.Printf("Interface notification: %+v", event)
case <-ctx.Done():
return
}
}
}()
//time.Sleep(time.Second)
// LLDPNeighbor notifications
wg.Add(1)
go func() {
defer wg.Done()
appIDChan := a.StartLLDPNeighNotificationStream(ctx, "", "", "")
for {
select {
case event := <-appIDChan:
log.Printf("LLDPNeighbor notification: %+v", event)
case <-ctx.Done():
return
}
}
}()
//time.Sleep(time.Second)
// Route notifications
// wg.Add(1)
// go func() {
// defer wg.Done()
// appIdChan := app.StartRouteNotificationStream(ctx, "", nil, 0)
// for {
// select {
// case event := <-appIdChan:
// log.Printf("Route notification: %+v", event)
// case <-ctx.Done():
// return
// }
// }
// }()
wg.Wait()
}