Skip to content
Snippets Groups Projects
Commit 5c920a6f authored by Malte Bauch's avatar Malte Bauch
Browse files

pnds can be stored and loaded via gub

also added createPND for cli
parent 2b98e54a
No related branches found
No related tags found
3 merge requests!97Resolve "PND handling via CLI and database",!91"Overhaul Architecture",!90Develop
This commit is part of merge request !91. Comments created here will be created in the context of that merge request.
...@@ -3,3 +3,4 @@ db.socket = "bolt://172.17.0.4:7687" ...@@ -3,3 +3,4 @@ db.socket = "bolt://172.17.0.4:7687"
db.user = "" db.user = ""
db.password = "" db.password = ""
db.crypto = false db.crypto = false
pnd.path = "./pnds.gob"
...@@ -152,3 +152,12 @@ func (s *server) TAPIGetLink(ctx context.Context, in *pb.TAPIRequest) (*pb.TAPIR ...@@ -152,3 +152,12 @@ func (s *server) TAPIGetLink(ctx context.Context, in *pb.TAPIRequest) (*pb.TAPIR
// TODO: Implement // TODO: Implement
return &pb.TAPIReply{Message: "Done"}, nil return &pb.TAPIReply{Message: "Done"}, nil
} }
func (s *server) CreatePND(ctx context.Context, in *pb.PNDRequest) (*pb.PNDReply, error) {
log.Info("Received: ", in.GetName())
path := viper.GetString("pnd.path")
//TODO: change sbi
s.core.principalNetworkDomains[uuid.New()] = NewPND(in.GetName(), in.GetDescription(), s.core.southboundInterfaces["test"])
s.core.savePNDs(path)
return &pb.PNDReply{Message: "Created new PND: " + in.GetName()}, nil
}
package nucleus package nucleus
import ( import (
"code.fbi.h-da.de/cocsn/gosdn/database" "encoding/gob"
"fmt" "fmt"
"os"
"code.fbi.h-da.de/cocsn/gosdn/database"
"github.com/google/uuid" "github.com/google/uuid"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/viper" "github.com/spf13/viper"
"os"
) )
// Core is the representation of the controllers core // Core is the representation of the controllers core
type Core struct { type Core struct {
southboundInterfaces map[string]SouthboundInterface southboundInterfaces map[string]SouthboundInterface
prinipalNetworkDomains map[uuid.UUID]PrincipalNetworkDomain principalNetworkDomains map[uuid.UUID]PrincipalNetworkDomain
database database.Database database database.Database
IsRunning chan bool IsRunning chan bool
} }
//Initialize does start-up housekeeping like reading controller config files //Initialize does start-up housekeeping like reading controller config files
...@@ -31,16 +33,45 @@ func (c *Core) Initialize(IsRunningChannel chan bool) { ...@@ -31,16 +33,45 @@ func (c *Core) Initialize(IsRunningChannel chan bool) {
if err != nil { if err != nil {
log.Fatal(fmt.Errorf("Fatal error config file: %s \n", err)) log.Fatal(fmt.Errorf("Fatal error config file: %s \n", err))
} }
path := viper.GetString("pnd.path")
gob.Register(&pndImplementation{})
c.AttachDatabase() c.AttachDatabase()
if err := c.loadPNDs(path); err != nil {
log.Info(err)
}
c.IsRunning = IsRunningChannel c.IsRunning = IsRunningChannel
} }
// AttachDatabase connects to the database and passes the connectio to the controller core // AttachDatabase connects to the database and passes the connection to the controller core
func (c *Core) AttachDatabase() { func (c *Core) AttachDatabase() {
c.database = database.NewDatabaseClient() c.database = database.NewDatabaseClient()
} }
// TODO: the load and save functions for pnds are just temporary and should be
// moved to the database
// 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 // Shutdown waits for the shutdown signal and gracefully shuts down once it arrived
func (c *Core) Shutdown() { func (c *Core) Shutdown() {
<-c.IsRunning <-c.IsRunning
...@@ -52,4 +83,4 @@ func (c *Core) Shutdown() { ...@@ -52,4 +83,4 @@ func (c *Core) Shutdown() {
} }
log.Info("Shutdown complete") log.Info("Shutdown complete")
os.Exit(0) os.Exit(0)
} }
\ No newline at end of file
package nucleus package nucleus
import ( import (
"time"
"code.fbi.h-da.de/cocsn/gosdn/database" "code.fbi.h-da.de/cocsn/gosdn/database"
"github.com/google/uuid"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"time"
) )
//StartAndRun is used to start the core of the controller and any auxiliary services. //StartAndRun is used to start the core of the controller and any auxiliary services.
...@@ -13,7 +15,9 @@ func StartAndRun(IsRunningChannel chan bool) { ...@@ -13,7 +15,9 @@ func StartAndRun(IsRunningChannel chan bool) {
// Initialize the Core // Initialize the Core
core := Core{ core := Core{
database: database.Database{}, principalNetworkDomains: make(map[uuid.UUID]PrincipalNetworkDomain),
southboundInterfaces: make(map[string]SouthboundInterface),
database: database.Database{},
} }
core.Initialize(IsRunningChannel) core.Initialize(IsRunningChannel)
// Start the GRCP CLI // Start the GRCP CLI
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment