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