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
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
package commands
import (
pb "code.fbi.h-da.de/cocsn/gosdn/api/proto"
"code.fbi.h-da.de/cocsn/gosdn/log"
"context"
grpc "google.golang.org/grpc"
"time"
)
type commandType int
const (
GoSDN commandType = iota
Database
)
const (
defaultName = "gosdn-cli"
)
type command struct {
Name string
Description string
//CommandType commandType
Function func(conn *grpc.ClientConn)
}
var CommandList = []command{
{"hello", "test connection to goSDN controller", goSDNSayHello},
{"shutdown", "request goSDN controller to shutdown", goSDNShutdown},
{"testdb", "test all database connections", goSDNTestDB},
{"tapigetedge", "get list of edges", TAPIGetEdge},
{"tapigetedgenode", "get list of edgenodes", TAPIGetEdgeNode},
{"tapigetlink", "get list of links", TAPIGetLink},
}
func Connect() *grpc.ClientConn {
address := "localhost:55055"
conn, err := grpc.Dial(address, grpc.WithInsecure(), grpc.WithBlock())
if err != nil {
log.Fatal(err)
}
log.Info("Connected to " + conn.Target())
return conn
}
func goSDNSayHello(conn *grpc.ClientConn) {
c := pb.NewGrpcCliClient(conn)
// Contact the server and print out its response.
name := defaultName
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
r, err := c.SayHello(ctx, &pb.HelloRequest{Name: name})
if err != nil {
log.Fatal(err)
}
log.Info("Greeting: ", r.String())
}
func goSDNShutdown(conn *grpc.ClientConn) {
c := pb.NewGrpcCliClient(conn)
// Contact the server and print out its response.
name := defaultName
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
r, err := c.Shutdown(ctx, &pb.ShutdownRequest{Name: name})
if err != nil {
log.Fatal(err)
}
log.Info("Greeting: ", r.GetMessage())
}
func goSDNTestDB(conn *grpc.ClientConn) {
// TODO: fill with code and also see if grpc interface has this stub implemented.
}
// TAPIGetEdge triggers the GetEdge function of the Ciena
// flavoured TAPI client
func TAPIGetEdge(conn *grpc.ClientConn) {
c := pb.NewGrpcCliClient(conn)
// Contact the server and print out its response.
name := defaultName
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
r, err := c.TAPIGetEdge(ctx, &pb.TAPIRequest{Name: name})
if err != nil {
log.Fatal(err)
}
log.Info("TAPIGetEdge said: ", r.GetMessage())
}
// TAPIGetEdgeNode triggers the GetEdgeNode function of the Ciena
// flavoured TAPI client
func TAPIGetEdgeNode(conn *grpc.ClientConn) {
c := pb.NewGrpcCliClient(conn)
// Contact the server and print out its response.
name := defaultName
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
r, err := c.TAPIGetEdgeNode(ctx, &pb.TAPIRequest{Name: name})
if err != nil {
log.Fatal(err)
}
log.Info("TAPIGetEdgeNode said: ", r.GetMessage())
}
// TAPIGetLink triggers the GetLink function of the Ciena
// flavoured TAPI client
func TAPIGetLink(conn *grpc.ClientConn) {
c := pb.NewGrpcCliClient(conn)
// Contact the server and print out its response.
name := defaultName
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
r, err := c.TAPIGetLink(ctx, &pb.TAPIRequest{Name: name})
if err != nil {
log.Fatal(err)
}
log.Info("TAPIGetLink said: ", r.GetMessage())
}