Skip to content
Snippets Groups Projects
principalNetworkDomain.go 1.52 KiB
Newer Older
  • Learn to ignore specific revisions
  • package nucleus
    
    import (
    	"github.com/google/uuid"
    )
    
    // PrincipalNetworkDomain provides an
    // interface for PND implementations
    type PrincipalNetworkDomain interface {
    	Destroy() error
    	AddSbi() error
    	RemoveSbi() error
    	AddDevice(Device) error
    	RemoveDevice(uuid uuid.UUID) error
    }
    
    type pndImplementation struct {
    	name    string
    	sbi     map[string]SouthboundInterface
    	devices map[uuid.UUID]Device
    }
    
    //NewPND creates a Principle Network Domain
    func NewPND(name string, sbi SouthboundInterface) PrincipalNetworkDomain {
    	sbic := make(map[string]SouthboundInterface)
    	sbic["default"] = sbi
    	devices := make(map[uuid.UUID]Device)
    	return &pndImplementation{
    		name:    name,
    		sbi:     sbic,
    		devices: devices,
    	}
    }
    
    // Interface satisfaction
    func (pnd *pndImplementation) Destroy() error {
    	return destroy()
    }
    
    func (pnd *pndImplementation) AddSbi() error {
    	return addSbi()
    }
    
    func (pnd *pndImplementation) RemoveSbi() error {
    	return removeSbi()
    }
    
    func (pnd *pndImplementation) AddDevice(device Device) error {
    	return pnd.addDevice(device)
    }
    
    func (pnd *pndImplementation) RemoveDevice(uuid uuid.UUID) error {
    	return pnd.removeDevice(uuid)
    }
    
    // Actual implementation, bind to struct if
    // neccessary
    func destroy() error {
    	return nil
    }
    
    func addSbi() error {
    	return nil
    }
    
    func removeSbi() error {
    	return nil
    }
    
    func (pnd *pndImplementation) addDevice(device Device) error {
    	pnd.devices[device.Config.Uuid] = device
    	return nil
    }
    
    func (pnd *pndImplementation) removeDevice(uuid uuid.UUID) error {
    	delete(pnd.devices, uuid)
    	return nil
    }