diff --git a/main.go b/main.go index b04ddc031a21f6fa6c8d2a0ed4b9d438643f8dcb..7527c7d3e71b2c3548031f90f24772174560a41c 100644 --- a/main.go +++ b/main.go @@ -17,10 +17,12 @@ func main() { cliSocket := *cliListenAddr + ":" + *cliListenPort log.Loglevel(log.DEBUG) + + // Setup a channel to communicate if goSDN should shutdown. + IsRunningChannel := make(chan bool) + // hand off to cmd for further processing - nucleus.StartUp(cliSocket, *configFileName) - log.Info("Startup completed") - nucleus.Run() + nucleus.StartAndRun(cliSocket, *configFileName, IsRunningChannel) // nothing to see here, please move on! } diff --git a/nucleus/cli-handling.go b/nucleus/cli-handling.go index 581acceabed1423d9af20fa46322a0c9a442cd71..af0912ccd55bac6c97957911898e8af1a99f27ab 100644 --- a/nucleus/cli-handling.go +++ b/nucleus/cli-handling.go @@ -28,8 +28,8 @@ func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloRe } func (s *server) Shutdown(ctx context.Context, in *pb.ShutdownRequest) (*pb.ShutdownReply, error) { - log.Info("Received: %v", in.GetName()) - isRunning = false + log.Info("Shutdown Received: %v", in.GetName()) + s.core.IsRunning <- false return &pb.ShutdownReply{Message: "Shutdown " + in.GetName()}, nil } diff --git a/nucleus/controller.go b/nucleus/controller.go index de00cf348ba441d1d8ef8e6c4cd4c2b99eaf8d26..4e659667dee655f3da7f2fb41c8abd9ec85e576c 100644 --- a/nucleus/controller.go +++ b/nucleus/controller.go @@ -23,9 +23,10 @@ type Core struct { clients map[string]interfaces.Client database database.Database config controllerConfig + IsRunning chan bool } -func (c *Core) Init(socket, configfile string) { +func (c *Core) Init(socket, configfile string, IsRunningChannel chan bool) { if configfile == "" { configfile = "gosdn.toml" } @@ -47,8 +48,11 @@ func (c *Core) Init(socket, configfile string) { c.AttachDatabase() + c.IsRunning = IsRunningChannel + //TODO: Create client config/CLI adapter c.clients["ciena-mcp"] = ciena.NewMCPClient("141.100.70.170", "", "", &c.database) + } func (c *Core) AttachDatabase() { @@ -56,6 +60,15 @@ func (c *Core) AttachDatabase() { } func (c *Core) Shutdown() { + + stopIt := <- c.IsRunning + if(stopIt == false) { + log.Debug("Shutdown() received action to shutdown") + }else { + log.Debug("Shutdown() received something else.") + } + + f, err := os.Create(c.config.ConfigPath) if err != nil { log.Fatal(err) @@ -64,4 +77,6 @@ func (c *Core) Shutdown() { if err := enc.Encode(c.config); err != nil { log.Fatal(err) } + + os.Exit(0) } diff --git a/nucleus/nucleus-core.go b/nucleus/nucleus-core.go index faf21776d23d8b1449078ee2b4cfba2797bc72fa..20a504de5725d56ccc752bf5816c9c962bfed52d 100644 --- a/nucleus/nucleus-core.go +++ b/nucleus/nucleus-core.go @@ -11,32 +11,24 @@ import ( * This function is used to start the core of the controller and any auxiliary services. */ -// Next-up: backend database. - -func StartUp(socket, filename string) { +func StartAndRun(socket, filename string, IsRunningChannel chan bool) { log.Info("This is the network superintendent...") log.Info("Starting my ducks") + // Init the Core core := Core{ clients: make(map[string]interfaces.Client), database: database.Database{}, } - core.Init(socket, filename) + core.Init(socket, filename, IsRunningChannel) // Start the GRCP CLI go getCLIGoing(&core) - log.Info("and ready for take off") - -} + go core.Shutdown() -/* - * nucleus.Run() is the "main loop" of the controller - */ - -var isRunning = true - -func Run() { + log.Info("and ready for take off") - for isRunning { + //Just to produce some signs of vitality... + for (true) { time.Sleep(10 * time.Second) log.Debug("Still alive...") }