diff --git a/api/initialise_test.go b/api/initialise_test.go index 34f0f705506b8892c3091078c6ff4d7554ea4d14..cc90b5709b6bd4d17bbfdc4cbf44545a32cd48d3 100644 --- a/api/initialise_test.go +++ b/api/initialise_test.go @@ -36,6 +36,7 @@ const sbiID = "f6fd4b35-f039-4111-9156-5e4501bb8a5a" const ondID = "7e0ed8cc-ebf5-46fa-9794-741494914883" var pndStore *nucleus.PndStore +var sbiStore *nucleus.SbiStore var lis *bufconn.Listener var pndUUID uuid.UUID var sbiUUID uuid.UUID @@ -48,6 +49,7 @@ func bootstrapUnitTest() { lis = bufconn.Listen(bufSize) s := grpc.NewServer() pndStore = nucleus.NewPndStore() + sbiStore = nucleus.NewSbiStore() changeUUID, err := uuid.Parse(changeID) if err != nil { @@ -83,6 +85,8 @@ func bootstrapUnitTest() { }, nil) mockPnd.On("Commit", mock.Anything).Return(nil) mockPnd.On("Confirm", mock.Anything).Return(nil) + mockPnd.On("Devices").Return([]uuid.UUID{deviceUUID}) + mockPnd.On("GetSBIs").Return(sbiStore) mockPnd.On("ChangeOND", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) if err := pndStore.Add(&mockPnd); err != nil { diff --git a/api/pnd.go b/api/pnd.go index 86d2b09713152d43920912fcf9b3b2ea346f7019..f396625163114d0454ca10b57ec23908ca2afb6a 100644 --- a/api/pnd.go +++ b/api/pnd.go @@ -13,11 +13,15 @@ import ( log "github.com/sirupsen/logrus" ) +// PrincipalNetworkDomainAdapter is an API adapter to reflect the NetworkDomain +// interface type PrincipalNetworkDomainAdapter struct { id uuid.UUID endpoint string } +// NewAdapter creates a PND Adapter. It requires a valid PND UUID and a reachable +// goSDN endpoint. func NewAdapter(id, endpoint string) (networkdomain.NetworkDomain, error) { pid, err := uuid.Parse(id) if err != nil { @@ -29,14 +33,17 @@ func NewAdapter(id, endpoint string) (networkdomain.NetworkDomain, error) { }, nil } +// Destroy destroys the PND Adapter. Currently not implemented func (p *PrincipalNetworkDomainAdapter) Destroy() error { return &errors.ErrNotYetImplemented{} } +// AddSbi adds an SBI to the PND Adapter. Currently not implemented func (p *PrincipalNetworkDomainAdapter) AddSbi(s southbound.SouthboundInterface) error { return &errors.ErrNotYetImplemented{} } +// RemoveSbi removes an SBI from the PND Adapter. Currently not implemented func (p *PrincipalNetworkDomainAdapter) RemoveSbi(uuid.UUID) error { return &errors.ErrNotYetImplemented{} } @@ -65,6 +72,7 @@ func (p *PrincipalNetworkDomainAdapter) GetDevice(identifier string) (device.Dev return nil, nil } +// RemoveDevice removes a device from the PND Adapter func (p *PrincipalNetworkDomainAdapter) RemoveDevice(did uuid.UUID) error { resp, err := deleteDevice(p.endpoint, p.id.String(), did.String()) if err != nil { @@ -74,10 +82,15 @@ func (p *PrincipalNetworkDomainAdapter) RemoveDevice(did uuid.UUID) error { return nil } +// Devices sends an API call to the controller requesting the UUIDs of all +// registered devices. Returns nil. func (p *PrincipalNetworkDomainAdapter) Devices() []uuid.UUID { return nil } +// ChangeOND sends an API call to the controller requesting the creation of +// a change from the provided Operation, path and value. The Change is marked +// as Pending and times out after the specified timeout period func (p *PrincipalNetworkDomainAdapter) ChangeOND(uuid uuid.UUID, operation ppb.ApiOperation, path string, value ...string) error { var v string if len(value) != 0 { @@ -91,6 +104,8 @@ func (p *PrincipalNetworkDomainAdapter) ChangeOND(uuid uuid.UUID, operation ppb. return err } +// Request sends an API call to the controller requesting the specified path +// for the specified device func (p *PrincipalNetworkDomainAdapter) Request(did uuid.UUID, path string) error { resp, err := getPath(p.endpoint, p.id.String(), did.String(), path) if err != nil { @@ -100,34 +115,47 @@ func (p *PrincipalNetworkDomainAdapter) Request(did uuid.UUID, path string) erro return nil } +// RequestAll sends an API call to the controller requesting the specified path +// for all registered devices. Not yet implemented. func (p *PrincipalNetworkDomainAdapter) RequestAll(string) error { return &errors.ErrNotYetImplemented{} } +// GetName returns the PND Adapter's name func (p *PrincipalNetworkDomainAdapter) GetName() string { - return "" + return "PND Adapter" } +// GetDescription returns the PND Adapter's description func (p *PrincipalNetworkDomainAdapter) GetDescription() string { - return "" + return "PND Adapter" } +// MarshalDevice sends an API call to the controller requesting the specified +// device as JSON representation. Not yet implemented func (p *PrincipalNetworkDomainAdapter) MarshalDevice(string) (string, error) { return "", &errors.ErrNotYetImplemented{} } +// ContainsDevice sends an API call to the controller checking if a device +// with the given UUID is present. Not implemented, always returns false func (p *PrincipalNetworkDomainAdapter) ContainsDevice(uuid.UUID) bool { return false } +// GetSBIs sends an API call to the controller requesting the +// registered SBIs. Not implemented, always returns nil func (p *PrincipalNetworkDomainAdapter) GetSBIs() store.Store { return nil } +// ID returns the PND Adapter's UUID func (p *PrincipalNetworkDomainAdapter) ID() uuid.UUID { return p.id } +// PendingChanges sends an API call to the controller requesting +// the UUIDs of all pending changes func (p *PrincipalNetworkDomainAdapter) PendingChanges() []uuid.UUID { resp, err := getChanges(p.endpoint, p.id.String()) if err != nil { @@ -137,6 +165,8 @@ func (p *PrincipalNetworkDomainAdapter) PendingChanges() []uuid.UUID { return filterChanges(ppb.Change_PENDING, resp) } +// CommittedChanges sends an API call to the controller requesting +// the UUIDs of all committed changes func (p *PrincipalNetworkDomainAdapter) CommittedChanges() []uuid.UUID { resp, err := getChanges(p.endpoint, p.id.String()) if err != nil { @@ -146,10 +176,12 @@ func (p *PrincipalNetworkDomainAdapter) CommittedChanges() []uuid.UUID { return filterChanges(ppb.Change_COMMITTED, resp) } +// GetChange sends an API call to the controller requesting the specified change func (p *PrincipalNetworkDomainAdapter) GetChange(uuid.UUID, ...int) (change.Change, error) { return nil, &errors.ErrNotYetImplemented{} } +// Commit sends an API call to the controller committing the specified change func (p *PrincipalNetworkDomainAdapter) Commit(cuid uuid.UUID) error { resp, err := commit(p.endpoint, p.id.String(), cuid.String()) if err != nil { @@ -159,6 +191,7 @@ func (p *PrincipalNetworkDomainAdapter) Commit(cuid uuid.UUID) error { return nil } +// Confirm sends an API call to the controller confirming the specified change func (p *PrincipalNetworkDomainAdapter) Confirm(cuid uuid.UUID) error { resp, err := confirm(p.endpoint, p.id.String(), cuid.String()) if err != nil { diff --git a/nucleus/principalNetworkDomain.go b/nucleus/principalNetworkDomain.go index a5b61317957211f195525ab4a6f7745245f4dd24..82912dcbef3cf8af1606480634c6af950751df3c 100644 --- a/nucleus/principalNetworkDomain.go +++ b/nucleus/principalNetworkDomain.go @@ -321,7 +321,8 @@ func (pnd *pndImplementation) RequestAll(path string) error { return nil } -// ChangeOND creates a change from the provided Operation, path and value. The Change is Pending and +// ChangeOND creates a change from the provided Operation, path and value. +// The Change is Pending and times out after the specified timeout period func (pnd *pndImplementation) ChangeOND(uuid uuid.UUID, operation ppb.ApiOperation, path string, value ...string) error { d, err := pnd.devices.GetDevice(uuid) if err != nil {