Skip to content
Snippets Groups Projects
configurationmanagement.go 1.86 KiB
Newer Older
  • Learn to ignore specific revisions
  • Neil Schark's avatar
    wip
    Neil Schark committed
    package server
    
    import (
    	"context"
    	"time"
    
    	cm "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/configurationmanagement"
    	ne "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/networkelement"
    
    Neil Schark's avatar
    Neil Schark committed
    	"code.fbi.h-da.de/danet/gosdn/controller/interfaces/networkelement"
    
    Neil Schark's avatar
    wip
    Neil Schark committed
    	log "github.com/sirupsen/logrus"
    	"google.golang.org/grpc/codes"
    	"google.golang.org/grpc/status"
    )
    
    // ConfigurationManagementServer represents a core server.
    type ConfigurationManagementServer struct {
    
    Neil Schark's avatar
    Neil Schark committed
    	networkElementStore networkelement.Store
    
    Neil Schark's avatar
    wip
    Neil Schark committed
    }
    
    // ConfigurationManagementServer receives a pndStore and returns a new coreServer.
    
    Neil Schark's avatar
    Neil Schark committed
    func NewConfigurationManagementServer(networkElementStore networkelement.Store) *ConfigurationManagementServer {
    	return &ConfigurationManagementServer{networkElementStore: networkElementStore}
    
    Neil Schark's avatar
    wip
    Neil Schark committed
    }
    
    // ExportSDNConfig returns the SDN configuration.
    func (c ConfigurationManagementServer) ExportSDNConfig(ctx context.Context, request *cm.ExportSDNConfigRequest) (*cm.ExportSDNConfigResponse, error) {
    
    	//pnd := request.Pid
    
    	networkElements := c.networkDomain.NetworkElements()
    
    	convertedNetworkelements := []*ne.NetworkElement{}
    	for _, networkElement := range networkElements {
    		ygotStructAsJSON, err := networkElement.GetModelAsString()
    		if err != nil {
    			log.Error(err)
    			return nil, status.Errorf(codes.Aborted, "%v", err)
    		}
    
    		convertedNetworkelements = append(convertedNetworkelements, &ne.NetworkElement{
    			Id:    networkElement.ID().String(),
    			Name:  networkElement.Name(),
    			Model: ygotStructAsJSON,
    		})
    	}
    
    	return &cm.ExportSDNConfigResponse{
    		Timestamp: time.Now().UnixNano(),
    		SdnConfig: "nothing yet"}, nil
    }
    
    // ImportSDNConfig receives an SDN configuration and imports it.
    func (s *NetworkElementServer) ImportSDNConfig(ctx context.Context, request *cm.ImportSDNConfigRequest) (*cm.ImportSDNConfigResponse, error) {
    	return &cm.ImportSDNConfigResponse{
    		Timestamp: time.Now().UnixNano()}, nil
    }