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

removed gob for persisting and changed:

- added initial sbis in controller
- added getter/setter transport in southbound
- added multiple geeter in principalNetworkDomain
parent 51b7cdab
No related branches found
No related tags found
3 merge requests!97Resolve "PND handling via CLI and database",!91"Overhaul Architecture",!90Develop
package nucleus
import (
"encoding/gob"
"fmt"
"os"
......@@ -33,14 +32,8 @@ func (c *Core) Initialize(IsRunningChannel chan bool) {
if err != nil {
log.Fatal(fmt.Errorf("Fatal error config file: %s \n", err))
}
path := viper.GetString("pnd.path")
gob.Register(&pndImplementation{})
gob.Register(&OpenConfig{})
c.AttachDatabase()
if err := c.loadPNDs(path); err != nil {
log.Info(err)
}
c.CreateSouthboundInterfaces()
c.IsRunning = IsRunningChannel
}
......@@ -50,27 +43,14 @@ func (c *Core) AttachDatabase() {
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
// CreateSouthboundInterfaces initializes the controller with his SBIs
func (c *Core) CreateSouthboundInterfaces() {
if len(c.southboundInterfaces) == 0 {
sbi := &AristaOC{}
t := &Gnmi{SetNode: sbi.SetNode()}
sbi.SetTransport(t)
c.southboundInterfaces[sbi.SbiIdentifier()] = sbi
}
defer f.Close()
return gob.NewDecoder(f).Decode(&c.principalNetworkDomains)
}
// Shutdown waits for the shutdown signal and gracefully shuts down once it arrived
......
......@@ -11,7 +11,7 @@ import (
)
type Gnmi struct {
SetNode func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error
SetNode func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error
RespChan chan *gpb.SubscribeResponse
}
......@@ -25,17 +25,17 @@ func (g *Gnmi) GetConfig() interface{} {
// interface satisfaction for now
// TODO: Convert to meaningfiul calls
func (g *Gnmi)Get(ctx context.Context, params ...string) (interface{}, error){return nil, nil}
func (g *Gnmi)Set(ctx context.Context, params ...string) (interface{}, error){return nil, nil}
func (g *Gnmi)Subscribe(ctx context.Context, params ...string) error{
func (g *Gnmi) Get(ctx context.Context, params ...string) (interface{}, error) { return nil, nil }
func (g *Gnmi) Set(ctx context.Context, params ...string) (interface{}, error) { return nil, nil }
func (g *Gnmi) Subscribe(ctx context.Context, params ...string) error {
return g.subscribe(ctx)
}
func (g *Gnmi)Type() string {
func (g *Gnmi) Type() string {
return "gnmi"
}
func (g *Gnmi)ProcessResponse(resp interface{},root interface{}, s *ytypes.Schema) error {
func (g *Gnmi) ProcessResponse(resp interface{}, root interface{}, s *ytypes.Schema) error {
models := s.SchemaTree
opts := []ytypes.SetNodeOpt{&ytypes.InitMissingElements{}, &ytypes.TolerateJSONInconsistencies{}}
r := resp.(*gpb.GetResponse)
......@@ -105,8 +105,8 @@ func (g *Gnmi) subscribe(ctx context.Context) error {
}
opts := ctx.Value("opts").(*gnmi.SubscribeOptions)
go func() {
for {
resp := <- g.RespChan
for {
resp := <-g.RespChan
if err := gnmi.LogSubscribeResponse(resp); err != nil {
log.Fatal(err)
}
......
......@@ -9,7 +9,8 @@ import (
type PrincipalNetworkDomain interface {
GetName() string
GetDescription() string
GetDefaultSBIName() string
GetDevices() map[uuid.UUID]Device
GetSBIs() map[string]SouthboundInterface
Destroy() error
AddSbi(SouthboundInterface) error
RemoveSbi(string) error
......@@ -41,12 +42,16 @@ func (pnd *pndImplementation) GetName() string {
return pnd.Name
}
func (pnd *pndImplementation) GetDevices() map[uuid.UUID]Device {
return pnd.Devices
}
func (pnd *pndImplementation) GetDescription() string {
return pnd.Description
}
func (pnd *pndImplementation) GetDefaultSBIName() string {
return pnd.Sbi["default"].SbiIdentifier()
func (pnd *pndImplementation) GetSBIs() map[string]SouthboundInterface {
return pnd.Sbi
}
// Interface satisfaction
......
......@@ -17,6 +17,8 @@ type SouthboundInterface interface {
SetNode() func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error
Schema() *ytypes.Schema
SetTransport(t Transport)
GetTransport() Transport
}
type Tapi struct {
......@@ -48,8 +50,16 @@ func (oc *OpenConfig) SetNode() func(schema *yang.Entry, root interface{}, path
}
}
func (oc *OpenConfig) GetTransport() Transport {
return oc.Transport
}
func (oc *OpenConfig) SetTransport(t Transport) {
oc.Transport = t
}
type AristaOC struct {
transport Transport
Transport Transport
schema *ytypes.Schema
}
......@@ -73,3 +83,11 @@ func (oc *AristaOC) SetNode() func(schema *yang.Entry, root interface{}, path *g
return nil
}
}
func (oc *AristaOC) GetTransport() Transport {
return oc.Transport
}
func (oc *AristaOC) SetTransport(t Transport) {
oc.Transport = t
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment