Skip to content
Snippets Groups Projects
controller.go 1.75 KiB
Newer Older
  • Learn to ignore specific revisions
  • package nucleus
    
    import (
    
    	"os"
    
    	"code.fbi.h-da.de/cocsn/gosdn/database"
    
    	"github.com/google/uuid"
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	log "github.com/sirupsen/logrus"
    
    	"github.com/spf13/viper"
    
    // Core is the representation of the controllers core
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    type Core struct {
    
    	southboundInterfaces    map[string]SouthboundInterface
    
    	principalNetworkDomains map[uuid.UUID]PrincipalNetworkDomain
    
    	database                database.Database
    	IsRunning               chan bool
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    }
    
    //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))
    
    Martin Stiemerling's avatar
    Martin Stiemerling committed
    	}
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	c.AttachDatabase()
    
    	c.CreateSouthboundInterfaces()
    
    // AttachDatabase connects to the database and passes the connection to the controller core
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    func (c *Core) AttachDatabase() {
    
    	c.database = database.NewDatabaseClient()
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    }
    
    
    Malte Bauch's avatar
    Malte Bauch committed
    // CreateSouthboundInterfaces initializes the controller with his supported SBIs
    
    func (c *Core) CreateSouthboundInterfaces() {
    
    	arista := &AristaOC{}
    	c.southboundInterfaces[arista.SbiIdentifier()] = arista
    	openconfig := &OpenConfig{}
    	c.southboundInterfaces[openconfig.SbiIdentifier()] = openconfig
    
    // Shutdown waits for the shutdown signal and gracefully shuts down once it arrived
    
    func (c *Core) Shutdown() {
    
    	<-c.IsRunning
    
    	log.Info("Received shutdown signal. Shutting down")
    
    	err := viper.WriteConfig()
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	if err != nil {
    		log.Fatal(err)
    	}