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

adjustments for the last merge

parent ffc3fc3b
Branches
No related tags found
3 merge requests!97Resolve "PND handling via CLI and database",!91"Overhaul Architecture",!90Develop
...@@ -3,7 +3,6 @@ package main ...@@ -3,7 +3,6 @@ package main
import ( import (
"code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi" "code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi"
"code.fbi.h-da.de/cocsn/gosdn/nucleus" "code.fbi.h-da.de/cocsn/gosdn/nucleus"
schema "code.fbi.h-da.de/cocsn/yang-models/generated/arista"
"context" "context"
"fmt" "fmt"
"github.com/google/uuid" "github.com/google/uuid"
...@@ -23,8 +22,7 @@ func main() { ...@@ -23,8 +22,7 @@ func main() {
RespChan: make(chan *gpb.SubscribeResponse), RespChan: make(chan *gpb.SubscribeResponse),
} }
device := nucleus.Device{ device := nucleus.Device{
Device: &schema.Device{}, SBI: sbi,
SBI: sbi,
Config: nucleus.DeviceConfig{ Config: nucleus.DeviceConfig{
Uuid: uuid.New(), Uuid: uuid.New(),
Address: "localhost:9339", Address: "localhost:9339",
...@@ -33,8 +31,8 @@ func main() { ...@@ -33,8 +31,8 @@ func main() {
}, },
Transport: transport, Transport: transport,
} }
pnd := nucleus.NewPND("openconfig", sbi) pnd := nucleus.NewPND("openconfig", "a simple openconfig PND", sbi)
if err := pnd.AddDevice(device); err != nil { if err := pnd.AddDevice(&device); err != nil {
log.Fatal(err) log.Fatal(err)
} }
......
...@@ -206,25 +206,35 @@ func (s *server) AddDevice(ctx context.Context, in *pb.AddDeviceRequest) (*pb.Ad ...@@ -206,25 +206,35 @@ func (s *server) AddDevice(ctx context.Context, in *pb.AddDeviceRequest) (*pb.Ad
if err != nil { if err != nil {
return &pb.AddDeviceReply{Message: err.Error()}, err return &pb.AddDeviceReply{Message: err.Error()}, err
} }
pnd := s.core.principalNetworkDomains[uuidPND] pnd, exists := s.core.principalNetworkDomains[uuidPND]
if exists != true {
return &pb.AddDeviceReply{Message: err.Error()}, err
}
sbi := s.core.principalNetworkDomains[uuidPND].GetSBIs()["default"] sbi := s.core.principalNetworkDomains[uuidPND].GetSBIs()["default"]
transport := &Gnmi{SetNode: sbi.SetNode()}
cfg := &gnmi.Config{
Addr: in.Device.Address,
Username: in.Device.Username,
Password: in.Device.Password,
}
transport.SetConfig(cfg)
newDevice := Device{ newDevice := Device{
Uuid: uuid.New(), SBI: sbi,
Device: sbi.Schema().Root,
SBI: sbi,
Config: DeviceConfig{ Config: DeviceConfig{
Uuid: uuid.New(),
Address: in.Device.Address, Address: in.Device.Address,
Username: in.Device.Username, Username: in.Device.Username,
Password: in.Device.Password, Password: in.Device.Password,
}, },
Transport: sbi.GetTransport(), Transport: transport,
} }
devicesMap := pnd.GetDevices() devicesMap := pnd.GetDevices()
devicesMap[newDevice.Uuid] = newDevice devicesMap[newDevice.Config.Uuid] = &newDevice
s.core.MarshallPNDs() s.core.MarshallPNDs()
return &pb.AddDeviceReply{Message: "Added new Device: " + newDevice.Uuid.String()}, err return &pb.AddDeviceReply{Message: "Added new Device: " + newDevice.Config.Uuid.String()}, err
} }
func (s *server) HandleDeviceGetRequest(ctx context.Context, in *pb.DeviceGetRequest) (*pb.DeviceGetReply, error) { func (s *server) HandleDeviceGetRequest(ctx context.Context, in *pb.DeviceGetRequest) (*pb.DeviceGetReply, error) {
...@@ -237,32 +247,25 @@ func (s *server) HandleDeviceGetRequest(ctx context.Context, in *pb.DeviceGetReq ...@@ -237,32 +247,25 @@ func (s *server) HandleDeviceGetRequest(ctx context.Context, in *pb.DeviceGetReq
if err != nil { if err != nil {
return &pb.DeviceGetReply{Message: err.Error()}, err return &pb.DeviceGetReply{Message: err.Error()}, err
} }
pnd, exists := s.core.principalNetworkDomains[uuidPND]
if exists != true {
err := errors.New("Couldnt find PND: UUID is wrong")
return &pb.DeviceGetReply{Message: err.Error()}, err
}
device, exists := s.core.principalNetworkDomains[uuidPND].GetDevices()[uuidDevice] device, exists := s.core.principalNetworkDomains[uuidPND].GetDevices()[uuidDevice]
if exists != true { if exists != true {
err := errors.New("Couldnt find device: UUID is wrong") err := errors.New("Couldnt find device: UUID is wrong")
return &pb.DeviceGetReply{Message: err.Error()}, err return &pb.DeviceGetReply{Message: err.Error()}, err
} }
cfg := &gnmi.Config{
Addr: device.Config.Address,
Password: device.Config.Password,
Username: device.Config.Username,
}
ctxGnmi := gnmi.NewContext(context.Background(), cfg)
ctxGnmi = context.WithValue(ctxGnmi, "config", cfg)
paths := []string{in.GetPath()} err = pnd.Request(uuidDevice, in.GetPath())
req, err := gnmi.NewGetRequest(gnmi.SplitPaths(paths), "")
resp, err := GetWithRequest(ctxGnmi, req)
if err != nil { if err != nil {
return &pb.DeviceGetReply{Message: err.Error()}, err return &pb.DeviceGetReply{Message: err.Error()}, err
} }
if err := device.Add(resp); err != nil {
return &pb.DeviceGetReply{Message: err.Error()}, err d, err := json.MarshalIndent(device, "", "\t")
}
d, err := json.MarshalIndent(device.Device, "", "\t")
if err != nil { if err != nil {
return &pb.DeviceGetReply{Message: err.Error()}, err return &pb.DeviceGetReply{Message: err.Error()}, err
} }
return &pb.DeviceGetReply{Message: string(d)}, nil return &pb.DeviceGetReply{Message: string(d)}, nil
......
...@@ -35,12 +35,15 @@ func (c *Core) Initialize(IsRunningChannel chan bool) { ...@@ -35,12 +35,15 @@ func (c *Core) Initialize(IsRunningChannel chan bool) {
} }
c.AttachDatabase() c.AttachDatabase()
c.CreateSouthboundInterfaces() c.CreateSouthboundInterfaces()
for sbi := range c.southboundInterfaces {
err = c.UnMarshallPNDs() log.Info(sbi)
if err != nil {
log.Info(err)
} }
// err = c.UnMarshallPNDs()
// if err != nil {
// log.Info(err)
// }
c.IsRunning = IsRunningChannel c.IsRunning = IsRunningChannel
} }
...@@ -78,12 +81,10 @@ func (c *Core) UnMarshallPNDs() error { ...@@ -78,12 +81,10 @@ func (c *Core) UnMarshallPNDs() error {
// CreateSouthboundInterfaces initializes the controller with his SBIs // CreateSouthboundInterfaces initializes the controller with his SBIs
func (c *Core) CreateSouthboundInterfaces() { func (c *Core) CreateSouthboundInterfaces() {
if len(c.southboundInterfaces) == 0 { arista := &AristaOC{}
arista := GetAristaOCInstance() c.southboundInterfaces[arista.SbiIdentifier()] = arista
c.southboundInterfaces[arista.SbiIdentifier()] = arista openconfig := &OpenConfig{}
openconfig := GetOpenconfigInstance() c.southboundInterfaces[openconfig.SbiIdentifier()] = openconfig
c.southboundInterfaces[openconfig.SbiIdentifier()] = openconfig
}
} }
// 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
......
...@@ -48,10 +48,10 @@ func getSouthboundInterfaceFromJSONMap(m map[string]interface{}) SouthboundInter ...@@ -48,10 +48,10 @@ func getSouthboundInterfaceFromJSONMap(m map[string]interface{}) SouthboundInter
switch sbi := m["name"]; sbi { switch sbi := m["name"]; sbi {
case "arista": case "arista":
newSBI = GetAristaOCInstance() newSBI = &AristaOC{}
case "openconfig": case "openconfig":
newSBI = GetOpenconfigInstance() newSBI = &OpenConfig{}
} }
return newSBI return newSBI
} }
...@@ -20,8 +20,6 @@ type SouthboundInterface interface { ...@@ -20,8 +20,6 @@ type SouthboundInterface interface {
// Needed for type assertion. // Needed for type assertion.
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
Schema() *ytypes.Schema Schema() *ytypes.Schema
SetTransport(t Transport)
GetTransport() Transport
} }
type Tapi struct { type Tapi struct {
...@@ -31,7 +29,6 @@ type Tapi struct { ...@@ -31,7 +29,6 @@ type Tapi struct {
// The struct holds the YANG schema and a function that // The struct holds the YANG schema and a function that
// returns an SBI specific SetNode function. // returns an SBI specific SetNode function.
type OpenConfig struct { type OpenConfig struct {
Name string `json:"name"`
// deprecated // deprecated
transport Transport transport Transport
...@@ -42,7 +39,7 @@ type OpenConfig struct { ...@@ -42,7 +39,7 @@ type OpenConfig struct {
// the SBI // the SBI
// deprecated // deprecated
func (oc *OpenConfig) SbiIdentifier() string { func (oc *OpenConfig) SbiIdentifier() string {
return oc.Name return "openconfig"
} }
func (oc *OpenConfig) Schema() *ytypes.Schema { func (oc *OpenConfig) Schema() *ytypes.Schema {
...@@ -65,16 +62,7 @@ func (oc *OpenConfig) SetNode() func(schema *yang.Entry, root interface{}, path ...@@ -65,16 +62,7 @@ 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 { type AristaOC struct {
Name string `json:"name"`
// deprecated // deprecated
transport Transport transport Transport
...@@ -82,7 +70,7 @@ type AristaOC struct { ...@@ -82,7 +70,7 @@ type AristaOC struct {
} }
func (oc *AristaOC) SbiIdentifier() string { func (oc *AristaOC) SbiIdentifier() string {
return oc.Name return "arista"
} }
func (oc *AristaOC) Schema() *ytypes.Schema { func (oc *AristaOC) Schema() *ytypes.Schema {
...@@ -104,11 +92,3 @@ func (oc *AristaOC) SetNode() func(schema *yang.Entry, root interface{}, path *g ...@@ -104,11 +92,3 @@ func (oc *AristaOC) SetNode() func(schema *yang.Entry, root interface{}, path *g
return nil 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