Newer
Older
"os"
"code.fbi.h-da.de/cocsn/gosdn/database"
// Core is the representation of the controllers core
southboundInterfaces map[string]SouthboundInterface
principalNetworkDomains map[uuid.UUID]PrincipalNetworkDomain
database database.Database
IsRunning chan bool
//Initialize does start-up housekeeping like reading controller config files
func (c *Core) Initialize(IsRunningChannel chan bool) {
// Set config defaults
viper.SetDefault("socket", "localhost:55055")
// Set config path and read config
viper.SetConfigName("gosdn")
viper.SetConfigType("toml")
viper.AddConfigPath("/usr/local/etc/gosdn/")
viper.AddConfigPath("./configs/")
err := viper.ReadInConfig()
if err != nil {
log.Fatal(fmt.Errorf("Fatal error config file: %s \n", err))
path := viper.GetString("pnd.path")
gob.Register(&pndImplementation{})
if err := c.loadPNDs(path); err != nil {
log.Info(err)
}
c.IsRunning = IsRunningChannel
// AttachDatabase connects to the database and passes the connection to the controller core
// TODO: the load and save functions for pnds are just temporary and should be
// SavePNDs imports the PNDs from last session
func (c *Core) savePNDs(path string) error {
f, err := os.Create(path)
if err != nil {
return err
}
defer f.Close()
return gob.NewEncoder(f).Encode(c.principalNetworkDomains)
}
// loadPNDs imports the PNDs from last session
func (c *Core) loadPNDs(path string) error {
f, err := os.Open(path)
if err != nil {
return err
}
defer f.Close()
return gob.NewDecoder(f).Decode(&c.principalNetworkDomains)
}
// Shutdown waits for the shutdown signal and gracefully shuts down once it arrived
log.Info("Received shutdown signal. Shutting down")
log.Info("Shutdown complete")
os.Exit(0)