Skip to content
Snippets Groups Projects
principalNetworkDomain.go 2.37 KiB
Newer Older
  • Learn to ignore specific revisions
  • package nucleus
    
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    import (
    	"github.com/google/uuid"
    )
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    // PrincipalNetworkDomain provides an
    // interface for PND implementations
    type PrincipalNetworkDomain interface {
    
    Malte Bauch's avatar
    Malte Bauch committed
    	GetName() string
    
    	GetDescription() string
    
    	GetDevices() map[uuid.UUID]Device
    	GetSBIs() map[string]SouthboundInterface
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	Destroy() error
    
    Malte Bauch's avatar
    Malte Bauch committed
    	AddSbi(SouthboundInterface) error
    	RemoveSbi(string) error
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	AddDevice(Device) error
    	RemoveDevice(uuid uuid.UUID) error
    }
    
    
    type pndImplementation struct {
    
    	Name        string                 `json:"name"`
    	Description string                 `json:"description"`
    	Sbi         SouthboundInterfaceMap `json:"sbis"`
    	Devices     map[uuid.UUID]Device   `json:"devices"`
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    //NewPND creates a Principle Network Domain
    
    Malte Bauch's avatar
    Malte Bauch committed
    func NewPND(name, description string, sbi SouthboundInterface) PrincipalNetworkDomain {
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	sbic := make(map[string]SouthboundInterface)
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	sbic["default"] = sbi
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	devices := make(map[uuid.UUID]Device)
    
    	return &pndImplementation{
    
    Malte Bauch's avatar
    Malte Bauch committed
    		Name:        name,
    		Description: description,
    		Sbi:         sbic,
    		Devices:     devices,
    
    Malte Bauch's avatar
    Malte Bauch committed
    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) GetSBIs() map[string]SouthboundInterface {
    	return pnd.Sbi
    
    // Interface satisfaction
    func (pnd *pndImplementation) Destroy() error {
    	return destroy()
    }
    
    
    Malte Bauch's avatar
    Malte Bauch committed
    func (pnd *pndImplementation) AddSbi(sbi SouthboundInterface) error {
    	return pnd.addSbi(sbi)
    
    Malte Bauch's avatar
    Malte Bauch committed
    func (pnd *pndImplementation) RemoveSbi(sbiIdentifier string) error {
    	return pnd.removeSbi(sbiIdentifier)
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    func (pnd *pndImplementation) AddDevice(device Device) error {
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	return pnd.addDevice(device)
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    }
    
    func (pnd *pndImplementation) RemoveDevice(uuid uuid.UUID) error {
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	return pnd.removeDevice(uuid)
    
    // Actual implementation, bind to struct if
    // neccessary
    func destroy() error {
    	return nil
    }
    
    
    Malte Bauch's avatar
    Malte Bauch committed
    func (pnd *pndImplementation) addSbi(sbi SouthboundInterface) error {
    	pnd.Sbi[sbi.SbiIdentifier()] = sbi
    
    Malte Bauch's avatar
    Malte Bauch committed
    func (pnd *pndImplementation) removeSbi(sbiIdentifier string) error {
    	delete(pnd.Sbi, sbiIdentifier)
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    func (pnd *pndImplementation) addDevice(device Device) error {
    
    	pnd.Devices[device.Uuid] = device
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	return nil
    }
    
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    func (pnd *pndImplementation) removeDevice(uuid uuid.UUID) error {
    
    Malte Bauch's avatar
    Malte Bauch committed
    	delete(pnd.Devices, uuid)
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	return nil
    }