diff --git a/cmd/gosdn-tview/grpc/commands.go b/cmd/gosdn-tview/grpc/commands.go index 74d2b09558e9e5a51a1ee3427623c96ca7006dfd..1ce55dd37b4b70e2cce9fa5aa0b4a1f24d42d9a8 100644 --- a/cmd/gosdn-tview/grpc/commands.go +++ b/cmd/gosdn-tview/grpc/commands.go @@ -22,17 +22,16 @@ type command struct { //CommandList contains the specific goSDN gRPC calls var CommandList = []command{ - {"hello", "test connection to goSDN controller", goSDNSayHello}, - {"shutdown", "request goSDN controller to shutdown", goSDNShutdown}, + {"hello", "test connection to controller", goSDNSayHello}, {"testdb", "test all database connections", goSDNTestDB}, - {"tapigetedge", "get list of edges", TAPIGetEdge}, - {"tapigetedgenode", "get list of edgenodes", TAPIGetEdgeNode}, - {"tapigetlink", "get list of links", TAPIGetLink}, + {"tapiGetDevices", "creates devices", TAPIGetEdge}, + {"tapiGetInterfaces", "creates interfaces", TAPIGetEdgeNode}, + {"tapiGetLinks", "creates links between devices", TAPIGetLink}, + {"shutdown", "request controller to shutdown", goSDNShutdown}, } //Connect creates a new connection to the gRPC server -func Connect() (*grpc.ClientConn, error) { - address := "141.100.70.170:55066" +func Connect(address string) (*grpc.ClientConn, error) { return grpc.Dial(address, grpc.WithInsecure(), grpc.WithTimeout(5*time.Second), grpc.WithBlock()) } @@ -51,7 +50,7 @@ func GoSDNLogStream(conn *grpc.ClientConn, clv *tview.TextView) error { streamError = err break } - response := []byte(msg.Log + "\n") + response := []byte(msg.Log) clv.Write(response) } }(stream) diff --git a/cmd/gosdn-tview/main.go b/cmd/gosdn-tview/main.go index 7f7368547959d5f92ebb922528b79d4214a2420b..4191524b856526f9d6d13cd2fb3db654127a80f9 100644 --- a/cmd/gosdn-tview/main.go +++ b/cmd/gosdn-tview/main.go @@ -1,6 +1,10 @@ package main import ( + "flag" + "strconv" + "strings" + "code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/app" grpc "code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/grpc" "code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/views" @@ -8,7 +12,13 @@ import ( ) func main() { - conn, err := grpc.Connect() + addrIPv4 := flag.String("addr", "localhost", "IPv4 server adress to connect to") + port := flag.Int("port", 55055, "Port of gRPC") + flag.Parse() + + addr := strings.Join([]string{*addrIPv4, strconv.Itoa(*port)}, ":") + conn, err := grpc.Connect(addr) + if err != nil { log.Fatal(err) } diff --git a/cmd/gosdn-tview/views/commandsListView.go b/cmd/gosdn-tview/views/commandsListView.go index 761a171fa89346ea2c53a4334e55bfa2a3df6da6..b9e42b9049d960c097ec2a383d5df0f947641a66 100644 --- a/cmd/gosdn-tview/views/commandsListView.go +++ b/cmd/gosdn-tview/views/commandsListView.go @@ -35,7 +35,7 @@ func (cv *CommandListView) GetContent() tview.Primitive { func (cv *CommandListView) GetCommands(app *app.App, rv *ResultAndInputView, conn *grpc.ClientConn) { //TODO: create own command in grpc -> commands - cv.commandsList.AddItem("AddPND", "closes the application", 'a', func() { + cv.commandsList.AddItem("addPND", "closes the application", 'a', func() { rv.ChangeContentView("addPND") app.SetFocus(rv.GetContent()) }) @@ -50,7 +50,7 @@ func (cv *CommandListView) GetCommands(app *app.App, rv *ResultAndInputView, }) } - cv.commandsList.AddItem("Show Log", "shows the log of goSDN", 'l', func() { + cv.commandsList.AddItem("log", "shows the log of goSDN", 'l', func() { rv.ChangeContentView("log") }) diff --git a/cmd/gosdn-tview/views/datbaseStatusView.go b/cmd/gosdn-tview/views/datbaseStatusView.go index 6c217b416779ecb7ea7232ee0b310298a27d8ce2..3c8e3c36689e893a3b812dce3386779340e34aa4 100644 --- a/cmd/gosdn-tview/views/datbaseStatusView.go +++ b/cmd/gosdn-tview/views/datbaseStatusView.go @@ -3,7 +3,7 @@ package views import ( "code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/app" "github.com/rivo/tview" - "time" + //"time" ) //DatabaseStatusView is an application view to display the current status of @@ -24,8 +24,9 @@ func NewDatabaseStatusView(app *app.App) *DatabaseStatusView { SetBorder(true). SetTitle("Database") - // run the periodical refresh in a new go routine - go databaseTicker(dv) + //TODO: dummy text at the moment. database status check has to be initilized + //here + dv.databaseStatusView.SetText("[green]" + "connected") return dv } @@ -40,11 +41,3 @@ func (dv *DatabaseStatusView) SetContent(s string) { dv.databaseStatusView.Clear() dv.databaseStatusView.SetText(s) } - -func databaseTicker(dv *DatabaseStatusView) { - //TODO see gRPCStatusView! - ticker := time.NewTicker(5 * time.Second) - for t := range ticker.C { - dv.SetContent(t.String()) - } -} diff --git a/cmd/gosdn-tview/views/gRPCStatusView.go b/cmd/gosdn-tview/views/gRPCStatusView.go index ef024aecc34363bc3a8edf67ff51ac574dab4e65..836c06a167173fe23f283a6dcfc04edfb7dd47b0 100644 --- a/cmd/gosdn-tview/views/gRPCStatusView.go +++ b/cmd/gosdn-tview/views/gRPCStatusView.go @@ -49,13 +49,17 @@ func (sv *GRPCStatusView) SetContent(s string) { } func gRPCTicker(sv *GRPCStatusView, conn *grpc.ClientConn) { + sv.SetContent(checkStatus(conn)) //TODO: refactor -> get rid of hardcoded values ticker := time.NewTicker(5 * time.Second) for range ticker.C { - if str := conn.GetState().String(); str == "READY" || str == "IDLE" { - sv.SetContent("[green]" + "connected") - } else { - sv.SetContent("[red]" + "disconnected") - } + sv.SetContent(checkStatus(conn)) } } + +func checkStatus(conn *grpc.ClientConn) string { + if str := conn.GetState().String(); str == "READY" || str == "IDLE" { + return "[green]" + "connected" + } + return "[red]" + "disconnected" +} diff --git a/cmd/gosdn-tview/views/headerView.go b/cmd/gosdn-tview/views/headerView.go index 7c68ef2b74442cd30e21ba7fc71bdcbc0a4203b0..8f7198383324722f84e80ccb0cb81dcc15b100fc 100644 --- a/cmd/gosdn-tview/views/headerView.go +++ b/cmd/gosdn-tview/views/headerView.go @@ -2,12 +2,12 @@ package views import "github.com/rivo/tview" -var goSDNAscii = ` ____ ____ _ _ _ _ _ _ _ ____ _ _ _ - __ _ ___/ ___|| _ \| \ | | | | | | ___ ___| |__ ___ ___| |__ _ _| | ___ | _ \ __ _ _ __ _ __ ___ ___| |_ __ _ __| | |_ - / _ |/ _ \___ \| | | | \| | _____ | |_| |/ _ \ / __| '_ \/ __|/ __| '_ \| | | | |/ _ \ | | | |/ _ | '__| '_ _ \/ __| __/ _ |/ _ | __| -| (_| | (_) |__) | |_| | |\ | |_____| | _ | (_) | (__| | | \__ \ (__| | | | |_| | | __/ | |_| | (_| | | | | | | | \__ \ || (_| | (_| | |_ - \__ |\___/____/|____/|_| \_| |_| |_|\___/ \___|_| |_|___/\___|_| |_|\__,_|_|\___| |____/ \__,_|_| |_| |_| |_|___/\__\__,_|\__,_|\__| - |___/ ` +var goSDNAscii = ` ____ ____ _ _ _ __ _ _ _ + __ _ ___/ ___|| _ \| \ | | __| | __ _ / / __ ___| |_ | |__ __| | __ _ + / _ |/ _ \___ \| | | | \| | _____ / _ |/ _ | / / _ \ / _ \ __| _____ | _ \ / _ |/ _ | +| (_| | (_) |__) | |_| | |\ | |_____| | (_| | (_| |/ /| | | | __/ |_ |_____| | | | | | (_| | (_| | + \__, |\___/____/|____/|_| \_| \__,_|\__,_/_/ |_| |_|\___|\__| |_| |_|___\__,_|\__,_| + |___/ |_____| ` //HeaderView is an application view to display the header of the application type HeaderView struct {