Skip to content
Snippets Groups Projects

"Overhaul Architecture"

Merged Ghost User requested to merge 67-overhaul-architecture into develop
4 files
+ 39
3
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 138
15
@@ -8,13 +8,18 @@ package nucleus
import (
"context"
"errors"
"io"
"net"
"os"
"sync"
"github.com/google/uuid"
"github.com/spf13/viper"
pb "code.fbi.h-da.de/cocsn/gosdn/api/proto"
"code.fbi.h-da.de/cocsn/gosdn/sbi/restconf/client/ciena"
"code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi"
gpb "github.com/openconfig/gnmi/proto/gnmi"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/health"
@@ -34,6 +39,7 @@ type server struct {
pb.UnimplementedGrpcCliServer
core *Core
logConnections []*logConnection
devices map[uuid.UUID]Device
}
var srv *server
@@ -52,7 +58,7 @@ func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloRe
return &pb.HelloReply{Message: "Hello " + in.GetName(), GoSDNInfo: "goSDN in version: DEVELOP"}, nil
}
//GetLog creates a continuous stream between client and server to send goSDN logs
//GetLog creates a continuous stream between ciena and server to send goSDN logs
func (s *server) CreateLogStream(req *emptypb.Empty, stream pb.GrpcCli_CreateLogStreamServer) error {
conn := &logConnection{
stream: stream,
@@ -109,7 +115,7 @@ func getCLIGoing(core *Core) {
log.Info("Starting: GetCLIGoing")
// Boot-up the control interface for the cli
cliControlListener, err := net.Listen("tcp", core.config.CliSocket)
cliControlListener, err := net.Listen("tcp", viper.GetString("socket"))
if err != nil {
log.Fatal(err)
}
@@ -135,27 +141,144 @@ func getCLIGoing(core *Core) {
// SBI specific calls, by now TAPI only
func (s *server) TAPIGetEdge(ctx context.Context, in *pb.TAPIRequest) (*pb.TAPIReply, error) {
log.Info("Received: ", in.GetName())
if err := s.core.clients["ciena-mcp"].(*ciena.MCPClient).GetNodes(); err != nil {
log.Error(err)
return &pb.TAPIReply{Message: "TAPI error"}, nil
}
// TODO: Implement
return &pb.TAPIReply{Message: "Done"}, nil
}
func (s *server) TAPIGetEdgeNode(ctx context.Context, in *pb.TAPIRequest) (*pb.TAPIReply, error) {
log.Info("Received: ", in.GetName())
if err := s.core.clients["ciena-mcp"].(*ciena.MCPClient).GetNodeEdgePoints(); err != nil {
log.Error(err)
return &pb.TAPIReply{Message: "TAPI error"}, nil
}
// TODO: Implement
return &pb.TAPIReply{Message: "Done"}, nil
}
func (s *server) TAPIGetLink(ctx context.Context, in *pb.TAPIRequest) (*pb.TAPIReply, error) {
log.Info("Received: ", in.GetName())
if err := s.core.clients["ciena-mcp"].(*ciena.MCPClient).GetLinks(); err != nil {
log.Error(err)
return &pb.TAPIReply{Message: "TAPI error"}, nil
}
// TODO: Implement
return &pb.TAPIReply{Message: "Done"}, nil
}
//CreatePND creates a new PND and adds it to the principalNetworkDomain map of
//the core
func (s *server) CreatePND(ctx context.Context, in *pb.CreatePNDRequest) (*pb.CreatePNDReply, error) {
log.Info("Received: Create a PND with the name", in.GetName())
sbi := s.core.southboundInterfaces[in.GetSbi()]
id := uuid.New()
s.core.principalNetworkDomains[id] = NewPND(in.GetName(), in.GetDescription(), sbi)
return &pb.CreatePNDReply{Message: "Created new PND: " + id.String()}, nil
}
//GetAllPNDs is a request to get all current registered PNDs and returns a slim
//variant of PNDs and their respective devices
func (s *server) GetAllPNDs(ctx context.Context, in *emptypb.Empty) (*pb.AllPNDsReply, error) {
log.Info("Received: Get all PNDs")
var pnds []*pb.PND
for uuidPND, pnd := range s.core.principalNetworkDomains {
var devices []*pb.Device
for uuidDevice, device := range pnd.(*pndImplementation).devices {
tmpDevice := pb.Device{
Uuid: uuidDevice.String(),
Address: device.Config.Address,
Username: device.Config.Username,
Password: device.Config.Password}
devices = append(devices, &tmpDevice)
}
tmpPND := pb.PND{
Uuid: uuidPND.String(),
Name: pnd.GetName(),
Description: pnd.GetDescription(),
Sbi: pnd.GetSBIs()["default"].SbiIdentifier(),
Devices: devices,
}
pnds = append(pnds, &tmpPND)
}
return &pb.AllPNDsReply{Pnds: pnds}, nil
}
//GetAllSBINames returns all registered SBIs from core.
func (s *server) GetAllSBINames(ctx context.Context, in *emptypb.Empty) (*pb.AllSBINamesReply, error) {
var sbiNames []string
for _, s := range s.core.southboundInterfaces {
sbiNames = append(sbiNames, s.SbiIdentifier())
}
return &pb.AllSBINamesReply{SbiNames: sbiNames}, nil
}
//AddDevice adds a new Device to a specific PND
//currently this is only working with gnmi transports
func (s *server) AddDevice(ctx context.Context, in *pb.AddDeviceRequest) (*pb.AddDeviceReply, error) {
log.Info("Received: AddDevice")
uuidPND, err := uuid.Parse(in.UuidPND)
if err != nil {
return &pb.AddDeviceReply{Message: err.Error()}, err
}
pnd, exists := s.core.principalNetworkDomains[uuidPND]
if exists != true {
log.Info(err)
return &pb.AddDeviceReply{Message: err.Error()}, err
}
sbi := s.core.principalNetworkDomains[uuidPND].GetSBIs()["default"]
//TODO: could the transport and the related config be created in device?
transport := &Gnmi{SetNode: sbi.SetNode()}
cfg := &gnmi.Config{
Addr: in.Device.Address,
Username: in.Device.Username,
Password: in.Device.Password,
Encoding: gpb.Encoding_JSON_IETF,
}
transport.SetConfig(cfg)
newDevice := NewDevice(sbi, in.Device.Address, in.Device.Username,
in.Device.Password, transport)
err = pnd.AddDevice(newDevice)
if err != nil {
log.Info(err)
return &pb.AddDeviceReply{Message: err.Error()}, err
}
return &pb.AddDeviceReply{Message: "Added new Device: " + newDevice.Config.Uuid.String()}, err
}
//HandleDeviceGetRequest handles a GET request via pnd.Request()
func (s *server) HandleDeviceGetRequest(ctx context.Context, in *pb.DeviceGetRequest) (*pb.DeviceGetReply, error) {
log.Info("Received: HandleDeviceGetRequest")
uuidPND, err := uuid.Parse(in.GetUuidPND())
if err != nil {
log.Info(err)
return &pb.DeviceGetReply{Message: err.Error()}, err
}
uuidDevice, err := uuid.Parse(in.GetUuidDevice())
if err != nil {
log.Info(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")
log.Info(err)
return &pb.DeviceGetReply{Message: err.Error()}, err
}
//check if the device exists
if !pnd.ContainsDevice(uuidDevice) {
err := errors.New("Couldnt find device: UUID is wrong")
log.Info(err)
return &pb.DeviceGetReply{Message: err.Error()}, err
}
//GET request for the provided path
err = pnd.Request(uuidDevice, in.GetPath())
if err != nil {
log.Info(err)
return &pb.DeviceGetReply{Message: err.Error()}, err
}
d, err := pnd.MarshalDevice(uuidDevice)
if err != nil {
log.Info(err)
return &pb.DeviceGetReply{Message: err.Error()}, err
}
return &pb.DeviceGetReply{Message: d}, nil
}
Loading