Skip to content
Snippets Groups Projects
controller.go 1.48 KiB
Newer Older
  • Learn to ignore specific revisions
  • package nucleus
    
    import (
    
    	"code.fbi.h-da.de/cocsn/gosdn/database"
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	"context"
    	"github.com/google/uuid"
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	log "github.com/sirupsen/logrus"
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	"time"
    
    // Core is the representation of the controllers core
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    type Core struct {
    
    	// deprecated
    	database database.Database
    
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	pndc pndStore
    	sbic sbiStore
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    }
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    var c *Core
    
    
    //Initialize does start-up housekeeping like reading controller config files
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    func initialize(ctx context.Context) error {
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	c = &Core{
    		database: database.Database{},
    		pndc:     pndStore{},
    		sbic:     sbiStore{},
    	}
    
    	c.sbic = sbiStore{
    		store{},
    	}
    	c.pndc = pndStore{
    		store{},
    	}
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	if err := createSouthboundInterfaces(); err != nil {
    
    Martin Stiemerling's avatar
    Martin Stiemerling committed
    	}
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	// TODO: Start grpc listener here
    
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	if err := httpApi(ctx); err != nil {
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	attachDatabase()
    
    
    // AttachDatabase connects to the database and passes the connection to the controller core
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    func attachDatabase() {
    
    	c.database = database.NewDatabaseClient()
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    }
    
    
    // CreateSouthboundInterfaces initializes the controller with its supported SBIs
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    func createSouthboundInterfaces() error {
    
    	if err := c.sbic.add(&OpenConfig{id: uuid.New()}); err != nil {
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    func Run(ctx context.Context) error {
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	if err := initialize(ctx); err != nil {
    		log.WithFields(log.Fields{}).Error(err)
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    		return err
    	}
    	log.WithFields(log.Fields{}).Info("initialisation finished")
    	for {
    		select {
    		case <-ctx.Done():
    			return nil
    		case <-time.Tick(time.Minute):
    			log.Debug("up and running")
    		}
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	}