Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 111-cli-expansion-stateful-behaviour-more-command-feedback
  • 120-integration-tests-fail
  • 138-making-gnmi-response-processing-more-error-tolerable
  • 140-refactor-pipelines
  • 156-a-setrequest-to-change-a-specific-path-of-an-ond-only-works-for-paths-with-string-values
  • 186-creating-a-device-based-on-plugin-or-csbi-is-not-possible
  • 195-requesting-changes-does-not-work-in-storemode-database
  • 223-database-pnd-store-is-missing-option-to-search-by-name
  • 225-adding-support-and-visualization-for-the-test-coverage2
  • 233-structs-like-loadeddevice-loadedsbi-loadedrole-loadeduser-are-never-passed-as-pointer
  • 242-improve-security-by-enabling-and-enforcing-more-linting-rules
  • 242-improve-security-by-enabling-and-enforcing-more-linting-rules-govet
  • 246-implement-our-own-version-to-send-gnmi-requests
  • 258-deal-with-read-only-fields-in-yang
  • 282-refactoring-of-the-current-test-setup
  • 289-quantum-safe-communication-between-rabbitmq-and-sdn-controller
  • 291-lab-vm-for-arm64-apple
  • 296-related-existing-work-about-change-logic-for-yang-models
  • 320-deadline-and-cancellation-for-grpc-calls
  • 336-add-error-handling-for-mne-watching-if-the-provided-paths-do-not-exist
  • 349-integration-test-for-lab01
  • 350-applying-a-sdn-configuration-should-also-update-the-internal-configuration-of-managed-network
  • 351-link-shadowing-of-global-variables
  • 383-re-organize-comands-in-cli
  • 392-remove-renovate
  • PSD_VGU_Logging
  • add-backup-script
  • add-dockerignore
  • add-script-with-docker-stats
  • add-sr-linux-yang-models
  • add-support-for-mtls-in-plugins
  • allow-slashes-in-branch-names
  • arm-build
  • bump-ygot-generator-to-0-0-5
  • check-unit-tests
  • ci-refactor-1337
  • cli-docs
  • create-health-check-api
  • custom-marshal-for-grpc-gateway
  • deployment-docker-compose
  • develop
  • docker-build-cache-experiments
  • fbi1478-master-patch-42436
  • fix-docker-registry-error
  • fix-linting-in-makefile
  • fix-viper
  • go-plugin-playground
  • gosdn-storage-cleanup
  • heiss_bachelor_thesis
  • hotfix-unique-list-error-from-a-device-get-request
  • integration-test-pipeline-fix
  • inventory-manager-netbox
  • istaester/add-git-hooks
  • istaester/architecture-figures
  • istaester/basic-persistance-layer
  • istaester/bump-ygot-version
  • istaester/cli-tests
  • istaester/db
  • istaester/handle-makefile-in-editorconfig
  • istaester/init-monorepo
  • istaester/plugin-registry
  • istaester/provide-pnd-service
  • istaester/tooling
  • istaester/update-readme
  • master
  • mb/plugin-registry
  • mk/benchmark-stores
  • mpsd-at-vgu
  • neil/cobra-tests
  • new-integration-test-setup-v1
  • profile
  • proto-getters
  • recursive-read-only-try-1337
  • registry-used-by-app
  • remove-stuff
  • renovate/babel-runtime-7.x-lockfile
  • renovate/buf.build-gen-go-bufbuild-protovalidate-protocolbuffers-go-1.x
  • renovate/dompurify-3.x-lockfile
  • renovate/eslint-9.x-lockfile
  • renovate/eslint-plugin-prettier-5.x-lockfile
  • renovate/eslint-plugin-react-7.x-lockfile
  • renovate/eslint-plugin-react-hooks-5.x-lockfile
  • renovate/eslint-plugin-react-refresh-0.x-lockfile
  • renovate/fortawesome-fontawesome-svg-core-6.x-lockfile
  • renovate/fortawesome-free-regular-svg-icons-6.x-lockfile
  • renovate/fortawesome-free-solid-svg-icons-6.x-lockfile
  • renovate/github.com-aristanetworks-goarista-digest
  • renovate/github.com-bufbuild-protovalidate-go-0.x
  • renovate/github.com-docker-docker-27.x
  • renovate/github.com-docker-docker-28.x
  • renovate/github.com-grpc-ecosystem-grpc-gateway-v2-2.x
  • renovate/github.com-hashicorp-go-plugin-1.x
  • renovate/github.com-lesismal-nbio-1.x
  • renovate/github.com-openconfig-gnmi-0.x
  • renovate/github.com-prometheus-client_golang-1.x
  • renovate/go.mongodb.org-mongo-driver-2.x
  • renovate/golangci-golangci-lint-1.x
  • renovate/google.golang.org-genproto-googleapis-api-digest
  • renovate/react-18.x-lockfile
  • renovate/react-bootstrap-2.x-lockfile
  • 0.1.0
101 results

Target

Select target project
  • danet/gosdn
1 result
Select Git revision
  • 111-cli-expansion-stateful-behaviour-more-command-feedback
  • 120-integration-tests-fail
  • 138-making-gnmi-response-processing-more-error-tolerable
  • 140-refactor-pipelines
  • 156-a-setrequest-to-change-a-specific-path-of-an-ond-only-works-for-paths-with-string-values
  • 186-creating-a-device-based-on-plugin-or-csbi-is-not-possible
  • 195-requesting-changes-does-not-work-in-storemode-database
  • 223-database-pnd-store-is-missing-option-to-search-by-name
  • 225-adding-support-and-visualization-for-the-test-coverage2
  • 233-structs-like-loadeddevice-loadedsbi-loadedrole-loadeduser-are-never-passed-as-pointer
  • 242-improve-security-by-enabling-and-enforcing-more-linting-rules
  • 242-improve-security-by-enabling-and-enforcing-more-linting-rules-govet
  • 246-implement-our-own-version-to-send-gnmi-requests
  • 258-deal-with-read-only-fields-in-yang
  • 282-refactoring-of-the-current-test-setup
  • 289-quantum-safe-communication-between-rabbitmq-and-sdn-controller
  • 291-lab-vm-for-arm64-apple
  • 296-related-existing-work-about-change-logic-for-yang-models
  • 320-deadline-and-cancellation-for-grpc-calls
  • 336-add-error-handling-for-mne-watching-if-the-provided-paths-do-not-exist
  • 349-integration-test-for-lab01
  • 350-applying-a-sdn-configuration-should-also-update-the-internal-configuration-of-managed-network
  • 351-link-shadowing-of-global-variables
  • 383-re-organize-comands-in-cli
  • 392-remove-renovate
  • PSD_VGU_Logging
  • add-backup-script
  • add-dockerignore
  • add-script-with-docker-stats
  • add-sr-linux-yang-models
  • add-support-for-mtls-in-plugins
  • allow-slashes-in-branch-names
  • arm-build
  • bump-ygot-generator-to-0-0-5
  • check-unit-tests
  • ci-refactor-1337
  • cli-docs
  • create-health-check-api
  • custom-marshal-for-grpc-gateway
  • deployment-docker-compose
  • develop
  • docker-build-cache-experiments
  • fbi1478-master-patch-42436
  • fix-docker-registry-error
  • fix-linting-in-makefile
  • fix-viper
  • go-plugin-playground
  • gosdn-storage-cleanup
  • heiss_bachelor_thesis
  • hotfix-unique-list-error-from-a-device-get-request
  • integration-test-pipeline-fix
  • inventory-manager-netbox
  • istaester/add-git-hooks
  • istaester/architecture-figures
  • istaester/basic-persistance-layer
  • istaester/bump-ygot-version
  • istaester/cli-tests
  • istaester/db
  • istaester/handle-makefile-in-editorconfig
  • istaester/init-monorepo
  • istaester/plugin-registry
  • istaester/provide-pnd-service
  • istaester/tooling
  • istaester/update-readme
  • master
  • mb/plugin-registry
  • mk/benchmark-stores
  • mpsd-at-vgu
  • neil/cobra-tests
  • new-integration-test-setup-v1
  • profile
  • proto-getters
  • recursive-read-only-try-1337
  • registry-used-by-app
  • remove-stuff
  • renovate/babel-runtime-7.x-lockfile
  • renovate/buf.build-gen-go-bufbuild-protovalidate-protocolbuffers-go-1.x
  • renovate/dompurify-3.x-lockfile
  • renovate/eslint-9.x-lockfile
  • renovate/eslint-plugin-prettier-5.x-lockfile
  • renovate/eslint-plugin-react-7.x-lockfile
  • renovate/eslint-plugin-react-hooks-5.x-lockfile
  • renovate/eslint-plugin-react-refresh-0.x-lockfile
  • renovate/fortawesome-fontawesome-svg-core-6.x-lockfile
  • renovate/fortawesome-free-regular-svg-icons-6.x-lockfile
  • renovate/fortawesome-free-solid-svg-icons-6.x-lockfile
  • renovate/github.com-aristanetworks-goarista-digest
  • renovate/github.com-bufbuild-protovalidate-go-0.x
  • renovate/github.com-docker-docker-27.x
  • renovate/github.com-docker-docker-28.x
  • renovate/github.com-grpc-ecosystem-grpc-gateway-v2-2.x
  • renovate/github.com-hashicorp-go-plugin-1.x
  • renovate/github.com-lesismal-nbio-1.x
  • renovate/github.com-openconfig-gnmi-0.x
  • renovate/github.com-prometheus-client_golang-1.x
  • renovate/go.mongodb.org-mongo-driver-2.x
  • renovate/golangci-golangci-lint-1.x
  • renovate/google.golang.org-genproto-googleapis-api-digest
  • renovate/react-18.x-lockfile
  • renovate/react-bootstrap-2.x-lockfile
  • 0.1.0
101 results
Show changes
Commits on Source (3)
Showing
with 203 additions and 138 deletions
......@@ -16,6 +16,7 @@ report.xml
# artifacts
controller/gosdn
cli/gosdnc
csbi/resources/csbi
# testing and configs
controller/configs/testing-gosdn.toml
......
......@@ -11,6 +11,7 @@ run:
- controller/mocks
- models/generated/openconfig
- forks/
- clab-gosdn_csbi_arista_base/
skip-dirs-default: true
skip-files:
- http.go
......
......@@ -22,7 +22,8 @@ install-tools:
export GOBIN=$(GOSDN_PRG) && go install gotest.tools/gotestsum@v1.7.0 &&\
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.1 &&\
go install github.com/vektra/mockery/v2@v2.11.0 &&\
go install github.com/openconfig/ygot/generator@v0.18.1
go install github.com/openconfig/ygot/generator@v0.20.0 &&\
go install github.com/andresterba/go-ygot-generator-generator@v0.0.1
@echo Finished installing development tooling
ci-install-tools:
......@@ -42,6 +43,13 @@ generate-controller-mocks: install-tools
generate-yang-models: install-tools
cd models/generated/openconfig &&\
go-ygot-generator-generator config.yaml openconfig.go &&\
go generate &&\
cat additions.patch >> yang.go
generate-csbi-yang-models: install-tools
cd csbi/resources &&\
go-ygot-generator-generator config.yaml gostructs.go &&\
go generate
build: pre
......
......@@ -55,7 +55,7 @@ Change UUID must be specified as positional argument.`,
pterm.Error.Println(err)
}
for _, r := range resp.GetResponses() {
pterm.Info.Println(r.String())
pterm.Info.Printfln("Change with ID: %s has been committed.", r.GetId())
}
},
}
......
......@@ -56,7 +56,7 @@ Change UUID must be specified as positional argument`,
pterm.Error.Println(err)
}
for _, r := range resp.GetResponses() {
pterm.Info.Println(r.String())
pterm.Info.Printfln("Change with ID: %s has been confirmed.", r.GetId())
}
},
}
......
......@@ -39,6 +39,7 @@ import (
)
var replace bool
var forcePush bool
// deviceSetCmd represents the set command
var deviceSetCmd = &cobra.Command{
......@@ -73,15 +74,16 @@ To enable replacing behaviour (destructive!), set the --replace flag."`,
args[1],
args[2],
)
if err != nil {
spinner.Fail(err)
}
for _, r := range resp.GetResponses() {
if r.Status == ppb.Status_STATUS_OK {
spinner.Success("A change for Device: ", did.String(), "has been created -> Change ID: ", r.GetId())
} else {
spinner.Fail("An error occured while creating a path set request for Device with ID: ", r.GetId(), r.GetStatus())
spinner.Success("A change for Device: ", did.String(), "has been created -> Change ID: ", r.GetId())
if forcePush {
executeFunc("change commit " + r.GetId())
executeFunc("change confirm " + r.GetId())
}
}
},
......@@ -90,4 +92,5 @@ To enable replacing behaviour (destructive!), set the --replace flag."`,
func init() {
deviceCmd.AddCommand(deviceSetCmd)
deviceSetCmd.Flags().BoolVarP(&replace, "replace", "r", false, "enables replace behaviour")
deviceSetCmd.Flags().BoolVarP(&forcePush, "force-push", "f", false, "enables the possibility to instantly push the set without commit/confirm")
}
......@@ -67,16 +67,21 @@ var loginCmd = &cobra.Command{
spinner.Success("Authentication for ", nbUserName, " was successful.")
userToken = resp.Token
viper.Set("USER_TOKEN", userToken)
err = viper.WriteConfig()
if err != nil {
pterm.Error.Println(err)
return err
}
pterm.Info.Println("Authentication-User-Token:", userToken)
return nil
},
}
var nbUserName string
var nbUserPwd string
var controllerAPIEndpoint string
func init() {
rootCmd.AddCommand(loginCmd)
......
......@@ -32,7 +32,6 @@ POSSIBILITY OF SUCH DAMAGE.
package cmd
import (
"fmt"
"os"
"strings"
......@@ -104,7 +103,7 @@ func executeFunc(s string) {
err := rootCmd.Execute()
if err != nil {
fmt.Fprintln(os.Stderr, "Could not execute:", err)
pterm.Error.Println("Could not execute:", err)
}
}
......
......@@ -48,6 +48,10 @@ var loglevel string
var grpcPort string
var cliPnd string
var cliSbi string
var controllerAPIEndpoint string
var nbUserName string
var nbUserPwd string
var userToken string
var pndAdapter *adapter.PndAdapter
......@@ -120,10 +124,9 @@ func initConfig() {
}
}
viper.SetDefault("socket", ":"+grpcPort)
cliPnd = viper.GetString("CLI_PND")
cliSbi = viper.GetString("CLI_SBI")
userToken = viper.GetString("USER_TOKEN")
ll := viper.GetString("GOSDN_LOG")
if ll != "" {
......
......@@ -39,8 +39,6 @@ import (
"google.golang.org/grpc/metadata"
)
var userToken string
func checkIPPort(string) error {
// check if address is in the format <IP>:<port>
ip, _, err := net.SplitHostPort(address)
......
......@@ -237,7 +237,7 @@ func ensureDefaultUserExists() error {
log.Fatal(err)
}
fmt.Printf("########\n Generated admin password: %s\n ########\n", generatedPassword)
fmt.Printf("########\n Generated admin password: %s\n########\n", generatedPassword)
err = c.userService.Add(rbacImpl.NewUser(uuid.New(), defaultUserName, map[string]string{config.BasePndUUID.String(): "admin"}, generatedPassword, ""))
if err != nil {
......
......@@ -14,11 +14,12 @@ import (
// nucleus
type Device interface {
ID() uuid.UUID
GetModel() ygot.ValidatedGoStruct
GetModel() ygot.GoStruct
Transport() transport.Transport
Name() string
SBI() southbound.SouthboundInterface
ProcessResponse(proto.Message) error
IsTransportValid() bool
}
// Details contains details of a device used by the cSBI mechanism
......
......@@ -22,7 +22,7 @@ type SouthboundInterface interface { // nolint
ID() uuid.UUID
SetID(id uuid.UUID)
Type() spb.Type
Unmarshal([]byte, *gpb.Path, ygot.ValidatedGoStruct, ...ytypes.UnmarshalOpt) error
Unmarshal([]byte, *gpb.Path, ygot.GoStruct, ...ytypes.UnmarshalOpt) error
Name() string
}
......
......@@ -541,7 +541,9 @@ func (p pndServer) SetChangeList(ctx context.Context, request *ppb.SetChangeList
return nil, handleRPCError(labels, err)
}
for _, r := range request.Change {
responses := make([]*ppb.SetResponse, len(request.Change))
for i, r := range request.Change {
cuid, err := uuid.Parse(r.Cuid)
if err != nil {
log.Error(err)
......@@ -563,15 +565,16 @@ func (p pndServer) SetChangeList(ctx context.Context, request *ppb.SetChangeList
Param: r.Op,
}
}
responses[i] = &ppb.SetResponse{
Id: cuid.String(),
Status: ppb.Status_STATUS_OK,
}
}
return &ppb.SetChangeListResponse{
Timestamp: time.Now().UnixNano(),
Status: ppb.Status_STATUS_OK,
Responses: []*ppb.SetResponse{
{
Status: ppb.Status_STATUS_OK,
},
},
Responses: responses,
}, nil
}
......@@ -589,27 +592,29 @@ func (p pndServer) SetPathList(ctx context.Context, request *ppb.SetPathListRequ
return nil, handleRPCError(labels, err)
}
for _, r := range request.ChangeRequest {
responses := make([]*ppb.SetResponse, len(request.ChangeRequest))
for i, r := range request.ChangeRequest {
did, err := uuid.Parse(r.Did)
if err != nil {
log.Error(err)
return nil, status.Errorf(codes.Aborted, "%v", err)
}
// TODO: Return CUID in API
_, err = pnd.ChangeOND(did, r.ApiOp, r.Path, r.Value)
cid, err := pnd.ChangeOND(did, r.ApiOp, r.Path, r.Value)
if err != nil {
log.Error(err)
return nil, status.Errorf(codes.Aborted, "%v", err)
}
responses[i] = &ppb.SetResponse{
Status: ppb.Status_STATUS_OK,
Id: cid.String(),
}
}
return &ppb.SetPathListResponse{
Timestamp: time.Now().UnixNano(),
Status: ppb.Status_STATUS_OK,
Responses: []*ppb.SetResponse{
{
Status: ppb.Status_STATUS_OK,
},
},
Responses: responses,
}, nil
}
......
package nucleus
import (
"fmt"
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/device"
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/networkdomain"
......@@ -189,8 +187,6 @@ func (s *DatabasePndStore) getCsbiClient() (cpb.CsbiServiceClient, error) {
}
s.csbiClient = cpb.NewCsbiServiceClient(conn)
fmt.Println("creating new csbi client")
}
return s.csbiClient, nil
......
......@@ -40,7 +40,7 @@ func NewDevice(name string, uuidInput uuid.UUID, opt *tpb.TransportOption, sbi s
if err != nil {
return nil, err
}
validatedDeepCopy, ok := root.(ygot.ValidatedGoStruct)
ygotDeepCopy, ok := root.(ygot.GoStruct)
if !ok {
return nil, &errors.ErrInvalidTypeAssertion{
Value: root,
......@@ -52,7 +52,7 @@ func NewDevice(name string, uuidInput uuid.UUID, opt *tpb.TransportOption, sbi s
return &CsbiDevice{
CommonDevice: CommonDevice{
UUID: uuidInput,
Model: validatedDeepCopy,
Model: ygotDeepCopy,
sbi: sbi,
transport: t,
name: name,
......@@ -63,7 +63,7 @@ func NewDevice(name string, uuidInput uuid.UUID, opt *tpb.TransportOption, sbi s
return &CommonDevice{
UUID: uuidInput,
Model: validatedDeepCopy,
Model: ygotDeepCopy,
sbi: sbi,
transport: t,
name: name,
......@@ -77,7 +77,7 @@ type CommonDevice struct {
UUID uuid.UUID
// Device embeds a ygot.GoStruct containing the device details
Model ygot.ValidatedGoStruct
Model ygot.GoStruct
// SBI is the device's southbound interface implementation
sbi southbound.SouthboundInterface
......@@ -97,7 +97,7 @@ func (d *CommonDevice) ID() uuid.UUID {
}
// GetModel returns the ygot representation of the Device
func (d *CommonDevice) GetModel() ygot.ValidatedGoStruct {
func (d *CommonDevice) GetModel() ygot.GoStruct {
return d.Model
}
......@@ -136,6 +136,15 @@ func (d *CommonDevice) ProcessResponse(resp proto.Message) error {
return d.transport.ProcessResponse(resp, d.Model, d.sbi.Schema())
}
// IsTransportValid returns a boolean if the transport of a device is valid
func (d *CommonDevice) IsTransportValid() bool {
if d.transportOptions != nil && d.transportOptions.Address != "" {
return true
}
return false
}
// CsbiDevice is used for the cSBI functionality.
type CsbiDevice struct {
CommonDevice
......@@ -147,7 +156,7 @@ func (d *CsbiDevice) ID() uuid.UUID {
}
// GetModel returns the ygot representation of the Device
func (d *CsbiDevice) GetModel() ygot.ValidatedGoStruct {
func (d *CsbiDevice) GetModel() ygot.GoStruct {
return d.Model
}
......@@ -172,6 +181,15 @@ func (d *CsbiDevice) ProcessResponse(resp proto.Message) error {
return d.transport.ProcessResponse(resp, d.Model, d.sbi.Schema())
}
// IsTransportValid returns a boolean if the transport of a device is valid
func (d *CsbiDevice) IsTransportValid() bool {
if d.transportOptions != nil && d.transportOptions.Address != "" {
return true
}
return false
}
// MarshalJSON implements the MarshalJSON interface to store a device as JSON
func (d *CommonDevice) MarshalJSON() ([]byte, error) {
var transportType string
......@@ -288,8 +306,9 @@ func (d *CommonDevice) MarshalBSON() ([]byte, error) {
func (d *CommonDevice) getYgotEmitJSONConfig() *ygot.EmitJSONConfig {
return &ygot.EmitJSONConfig{
Format: ygot.RFC7951,
Indent: "",
Format: ygot.RFC7951,
Indent: "",
SkipValidation: true,
RFC7951Config: &ygot.RFC7951JSONConfig{
AppendModuleName: true,
}}
......
......@@ -27,7 +27,7 @@ import (
type Gnmi struct {
SetNode func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error
RespChan chan *gpb.SubscribeResponse
Unmarshal func([]byte, *gpb.Path, ygot.ValidatedGoStruct, ...ytypes.UnmarshalOpt) error
Unmarshal func([]byte, *gpb.Path, ygot.GoStruct, ...ytypes.UnmarshalOpt) error
Options *tpb.TransportOption
client gpb.GNMIClient
config *gnmi.Config
......
......@@ -158,11 +158,11 @@ func newPnd() pndImplementation {
)
return pndImplementation{
Name: "default",
Description: "default test pnd",
sbic: sbiService,
devices: deviceService,
changes: store.NewChangeStore(),
Id: defaultPndID,
Name: "default",
Description: "default test pnd",
southboundService: sbiService,
deviceService: deviceService,
changes: store.NewChangeStore(),
Id: defaultPndID,
}
}
......@@ -68,12 +68,12 @@ func NewPND(
}
pnd := &pndImplementation{
Name: name,
Description: description,
sbic: sbiService,
devices: deviceService,
changes: changeStore,
Id: id,
Name: name,
Description: description,
southboundService: sbiService,
deviceService: deviceService,
changes: changeStore,
Id: id,
csbiClient: c,
callback: callback,
......@@ -86,8 +86,7 @@ func NewPND(
if len(existingSBIs) == 0 {
newSBI, _ := NewSBI(spb.Type_TYPE_OPENCONFIG)
err = pnd.sbic.Add(newSBI)
err = pnd.southboundService.Add(newSBI)
if err != nil {
return nil, err
}
......@@ -97,11 +96,11 @@ func NewPND(
}
type pndImplementation struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
sbic southbound.Service
devices device.Service
changes *store.ChangeStore
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
southboundService southbound.Service
deviceService device.Service
changes *store.ChangeStore
//nolint
Id uuid.UUID `json:"id,omitempty"`
......@@ -146,7 +145,7 @@ func (pnd *pndImplementation) ID() uuid.UUID {
}
func (pnd *pndImplementation) Devices() []device.Device {
allDevices, _ := pnd.devices.GetAll()
allDevices, _ := pnd.deviceService.GetAll()
return allDevices
}
......@@ -163,7 +162,7 @@ func (pnd *pndImplementation) GetDescription() string {
// GetSBIs returns the registered SBIs
func (pnd *pndImplementation) GetSBIs() ([]southbound.SouthboundInterface, error) {
sbis, err := pnd.sbic.GetAll()
sbis, err := pnd.southboundService.GetAll()
if err != nil {
return nil, err
}
......@@ -172,7 +171,7 @@ func (pnd *pndImplementation) GetSBIs() ([]southbound.SouthboundInterface, error
// GetSBIs returns the registered SBIs
func (pnd *pndImplementation) GetSBI(sbiUUID uuid.UUID) (southbound.SouthboundInterface, error) {
sbis, err := pnd.sbic.Get(store.Query{ID: sbiUUID})
sbis, err := pnd.southboundService.Get(store.Query{ID: sbiUUID})
if err != nil {
return nil, err
}
......@@ -194,7 +193,7 @@ func (pnd *pndImplementation) AddSbi(s southbound.SouthboundInterface) error {
func (pnd *pndImplementation) RemoveSbi(sid uuid.UUID) error {
var associatedDevices []device.Device
allExistingDevices, err := pnd.devices.GetAll()
allExistingDevices, err := pnd.deviceService.GetAll()
if err != nil {
return err
}
......@@ -235,7 +234,8 @@ func (pnd *pndImplementation) AddDevice(name string, opt *tpb.TransportOption, s
return uuid.Nil, err
}
default:
sbi, err = pnd.sbic.Get(store.Query{ID: sid})
var err error
sbi, err = pnd.southboundService.Get(store.Query{ID: sid})
if err != nil {
return uuid.Nil, err
}
......@@ -255,7 +255,7 @@ func (pnd *pndImplementation) GetDevice(identifier string) (device.Device, error
id = uuid.Nil
}
d, err := pnd.devices.Get(store.Query{
d, err := pnd.deviceService.Get(store.Query{
ID: id,
Name: identifier,
})
......@@ -289,12 +289,12 @@ func destroy() error {
// addSbi adds a SBI to the PND's SBI store.
func (pnd *pndImplementation) addSbi(sbi southbound.SouthboundInterface) error {
return pnd.sbic.Add(sbi)
return pnd.southboundService.Add(sbi)
}
// removeSbi removes an SBI based on the given ID from the PND's SBI store.
func (pnd *pndImplementation) removeSbi(id uuid.UUID) error {
sbi, err := pnd.sbic.Get(store.Query{ID: id})
sbi, err := pnd.southboundService.Get(store.Query{ID: id})
if sbi == nil {
return fmt.Errorf("no sbi found")
}
......@@ -302,21 +302,29 @@ func (pnd *pndImplementation) removeSbi(id uuid.UUID) error {
return err
}
return pnd.sbic.Delete(sbi)
return pnd.southboundService.Delete(sbi)
}
// addDevice adds a device to the PND's device store.
func (pnd *pndImplementation) addDevice(device device.Device) (uuid.UUID, error) {
err := pnd.devices.Add(device)
err := pnd.deviceService.Add(device)
if err != nil {
return uuid.Nil, err
}
if device.IsTransportValid() {
_, err = pnd.Request(device.ID(), "/interfaces")
if err != nil {
fmt.Printf("ERROR: %s\n", err)
return uuid.Nil, err
}
}
return device.ID(), nil
}
func (pnd *pndImplementation) removeDevice(id uuid.UUID) error {
d, err := pnd.devices.Get(store.Query{
d, err := pnd.deviceService.Get(store.Query{
ID: id,
Name: id.String(),
})
......@@ -335,12 +343,12 @@ func (pnd *pndImplementation) removeDevice(id uuid.UUID) error {
case *CsbiDevice:
return pnd.handleCsbiDeletion(id)
default:
return pnd.devices.Delete(d)
return pnd.deviceService.Delete(d)
}
}
func (pnd *pndImplementation) MarshalDevice(identifier string) (string, error) {
foundDevice, err := pnd.devices.Get(store.Query{
foundDevice, err := pnd.deviceService.Get(store.Query{
ID: uuid.MustParse(identifier),
Name: identifier,
})
......@@ -363,7 +371,7 @@ func (pnd *pndImplementation) MarshalDevice(identifier string) (string, error) {
// Request sends a get request to a specific device
func (pnd *pndImplementation) Request(uuid uuid.UUID, path string) (proto.Message, error) {
d, err := pnd.devices.Get(store.Query{
d, err := pnd.deviceService.Get(store.Query{
ID: uuid,
Name: uuid.String(),
})
......@@ -390,7 +398,7 @@ func (pnd *pndImplementation) Request(uuid uuid.UUID, path string) (proto.Messag
return nil, err
}
err = pnd.devices.Update(d)
err = pnd.deviceService.Update(d)
if err != nil {
return nil, err
}
......@@ -400,7 +408,7 @@ func (pnd *pndImplementation) Request(uuid uuid.UUID, path string) (proto.Messag
// RequestAll sends a request for all registered devices
func (pnd *pndImplementation) RequestAll(path string) error {
allDevices, err := pnd.devices.GetAll()
allDevices, err := pnd.deviceService.GetAll()
if err != nil {
return err
}
......@@ -421,7 +429,7 @@ func (pnd *pndImplementation) RequestAll(path string) error {
// 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(duid uuid.UUID, operation ppb.ApiOperation, path string, value ...string) (uuid.UUID, error) {
d, err := pnd.devices.Get(store.Query{
d, err := pnd.deviceService.Get(store.Query{
ID: duid,
})
if err != nil {
......@@ -598,7 +606,7 @@ func (pnd *pndImplementation) createCsbiDevice(
if err != nil {
return uuid.Nil, err
}
err = pnd.sbic.Add(csbi)
err = pnd.southboundService.Add(csbi)
if err != nil {
return uuid.Nil, err
}
......@@ -608,7 +616,7 @@ func (pnd *pndImplementation) createCsbiDevice(
}
d.(*CsbiDevice).UUID = id
ch <- device.Details{TransportOption: opt}
if err := pnd.devices.Add(d); err != nil {
if err := pnd.deviceService.Add(d); err != nil {
return uuid.Nil, err
}
return id, nil
......@@ -665,7 +673,7 @@ func (pnd *pndImplementation) requestPlugin(name string, opt *tpb.TransportOptio
if err != nil {
return nil, err
}
err = pnd.sbic.Add(sbi)
err = pnd.southboundService.Add(sbi)
if err != nil {
return nil, err
}
......
......@@ -122,7 +122,7 @@ func Test_pndImplementation_AddDevice(t *testing.T) {
if tt.name != "fails wrong type" {
if err == nil {
d, err := pnd.devices.Get(store.Query{Name: tt.args.name})
d, err := pnd.deviceService.Get(store.Query{Name: tt.args.name})
if err != nil {
t.Errorf("AddDevice() error = %v", err)
return
......@@ -130,7 +130,7 @@ func Test_pndImplementation_AddDevice(t *testing.T) {
if d.Name() != tt.args.name {
t.Errorf("AddDevice() got = %v, want %v", d.Name(), tt.args.name)
}
if err := pnd.devices.Delete(d); err != nil {
if err := pnd.deviceService.Delete(d); err != nil {
t.Error(err)
}
}
......@@ -177,12 +177,12 @@ func Test_pndImplementation_AddSbi(t *testing.T) {
}
if tt.name != "fails wrong type" {
if err == nil {
sbi, err := pnd.sbic.Get(store.Query{ID: defaultSbiID})
sbi, err := pnd.southboundService.Get(store.Query{ID: defaultSbiID})
if err != nil {
t.Errorf("AddSbi() SBI %v not in device store %v",
tt.args.sbi, sbi)
}
if err := pnd.sbic.Delete(sbi); err != nil {
if err := pnd.southboundService.Delete(sbi); err != nil {
t.Error(err)
}
}
......@@ -208,10 +208,10 @@ func Test_pndImplementation_Destroy(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
pnd := &pndImplementation{
Name: tt.fields.name,
Description: tt.fields.description,
sbic: tt.fields.sbi,
devices: tt.fields.devices,
Name: tt.fields.name,
Description: tt.fields.description,
southboundService: tt.fields.sbi,
deviceService: tt.fields.devices,
}
if err := pnd.Destroy(); (err != nil) != tt.wantErr {
t.Errorf("Destroy() error = %v, wantErr %v", err, tt.wantErr)
......@@ -302,7 +302,7 @@ func Test_pndImplementation_MarshalDevice(t *testing.T) {
if got != tt.want {
t.Errorf("MarshalDevice() got = %v, want %v", got, tt.want)
}
if err := pnd.devices.Delete(d); err != nil {
if err := pnd.deviceService.Delete(d); err != nil {
t.Error(err)
}
})
......@@ -371,11 +371,11 @@ func Test_pndImplementation_RemoveSbi(t *testing.T) {
deviceService := NewDeviceService(deviceStore, sbiService)
pnd := &pndImplementation{
Name: "test-remove-sbi",
Description: "test-remove-sbi",
sbic: sbiService,
devices: deviceService,
Id: defaultPndID,
Name: "test-remove-sbi",
Description: "test-remove-sbi",
southboundService: sbiService,
deviceService: deviceService,
Id: defaultPndID,
}
sbi, err := NewSBI(spb.Type_TYPE_OPENCONFIG, defaultSbiID)
......@@ -392,18 +392,18 @@ func Test_pndImplementation_RemoveSbi(t *testing.T) {
t.Errorf("RemoveSbi() error = %v, wantErr %v", err, tt.wantErr)
}
foundSbi, _ := pnd.sbic.Get(store.Query{ID: tt.args.id})
foundSbi, _ := pnd.southboundService.Get(store.Query{ID: tt.args.id})
if foundSbi != nil {
t.Errorf("RemoveSbi() SBI still in SBI store %v", pnd.sbic)
t.Errorf("RemoveSbi() SBI still in SBI store %v", pnd.southboundService)
}
if tt.name == "exclusively remove associated devices" {
allDevices, _ := pnd.devices.GetAll()
allDevices, _ := pnd.deviceService.GetAll()
if len(allDevices) != 1 {
t.Errorf("RemoveSbi() non associated devices should remain in the storage %v", allDevices)
}
} else {
allDevices, _ := pnd.devices.GetAll()
allDevices, _ := pnd.deviceService.GetAll()
if len(allDevices) != 0 {
t.Errorf("RemoveSbi() associated devices have not been removed correctly %v", len(allDevices))
}
......@@ -436,11 +436,11 @@ func Test_pndImplementation_RemoveSbiWithAssociatedDevices(t *testing.T) {
deviceService := NewDeviceService(deviceStore, sbiService)
pnd := &pndImplementation{
Name: "test-remove-sbi",
Description: "test-remove-sbi",
sbic: sbiService,
devices: deviceService,
Id: defaultPndID,
Name: "test-remove-sbi",
Description: "test-remove-sbi",
southboundService: sbiService,
deviceService: deviceService,
Id: defaultPndID,
}
sbi, err := NewSBI(spb.Type_TYPE_OPENCONFIG, defaultSbiID)
......@@ -479,18 +479,18 @@ func Test_pndImplementation_RemoveSbiWithAssociatedDevices(t *testing.T) {
t.Errorf("RemoveSbi() error = %v, wantErr %v", err, tt.wantErr)
}
foundSbi, _ := pnd.sbic.Get(store.Query{ID: tt.args.id})
foundSbi, _ := pnd.southboundService.Get(store.Query{ID: tt.args.id})
if foundSbi != nil {
t.Errorf("RemoveSbi() SBI still in SBI store %v", pnd.sbic)
t.Errorf("RemoveSbi() SBI still in SBI store %v", pnd.southboundService)
}
if tt.name == "exclusively remove associated devices" {
allDevices, _ := pnd.devices.GetAll()
allDevices, _ := pnd.southboundService.GetAll()
if len(allDevices) != 1 {
t.Errorf("RemoveSbi() non associated devices should remain in the storage %v", allDevices)
}
} else {
allDevices, _ := pnd.devices.GetAll()
allDevices, _ := pnd.southboundService.GetAll()
if len(allDevices) != 0 {
t.Errorf("RemoveSbi() associated devices have not been removed correctly %v", len(allDevices))
}
......@@ -536,12 +536,12 @@ func Test_pndImplementation_Request(t *testing.T) {
deviceService := NewGenericService[device.Device]()
pnd := pndImplementation{
Name: "default",
Description: "default test pnd",
sbic: &sbiService,
devices: &deviceService,
changes: store.NewChangeStore(),
Id: defaultPndID,
Name: "default",
Description: "default test pnd",
southboundService: &sbiService,
deviceService: &deviceService,
changes: store.NewChangeStore(),
Id: defaultPndID,
}
sbi, err := NewSBI(spb.Type_TYPE_OPENCONFIG)
......@@ -572,11 +572,11 @@ func Test_pndImplementation_Request(t *testing.T) {
t.Errorf("Request() error = %v, wantErr %v", err, tt.wantErr)
}
device, _ := pnd.devices.Get(store.Query{ID: mdid})
device, _ := pnd.deviceService.Get(store.Query{ID: mdid})
if device == nil {
return
}
if err := pnd.devices.Delete(device); err != nil {
if err := pnd.deviceService.Delete(device); err != nil {
t.Error(err)
}
})
......@@ -620,12 +620,12 @@ func Test_pndImplementation_RequestAll(t *testing.T) {
deviceService := NewGenericService[device.Device]()
pnd := pndImplementation{
Name: "default",
Description: "default test pnd",
sbic: &sbiService,
devices: &deviceService,
changes: store.NewChangeStore(),
Id: defaultPndID,
Name: "default",
Description: "default test pnd",
southboundService: &sbiService,
deviceService: &deviceService,
changes: store.NewChangeStore(),
Id: defaultPndID,
}
sbi, err := NewSBI(spb.Type_TYPE_OPENCONFIG)
......@@ -651,11 +651,11 @@ func Test_pndImplementation_RequestAll(t *testing.T) {
_, _ = pnd.addDevice(deviceWithMockTransport)
device, _ := pnd.devices.Get(store.Query{ID: mdid})
device, _ := pnd.deviceService.Get(store.Query{ID: mdid})
if device == nil {
return
}
if err := pnd.devices.Delete(device); err != nil {
if err := pnd.deviceService.Delete(device); err != nil {
t.Error(err)
}
})
......@@ -767,7 +767,7 @@ func Test_pndImplementation_ChangeOND(t *testing.T) {
return
}
devices, err := pnd.devices.GetAll()
devices, err := pnd.deviceService.GetAll()
if err != nil {
err := errors.New("error fetching device")
t.Error(err)
......@@ -789,6 +789,15 @@ func Test_pndImplementation_ChangeOND(t *testing.T) {
}
func Test_pndImplementation_GetDevice(t *testing.T) {
opts := &tpb.TransportOption{
Address: "",
Username: "test",
Password: "test",
TransportOption: &tpb.TransportOption_GnmiTransportOption{
GnmiTransportOption: &tpb.GnmiTransportOption{},
},
}
pnd := newPnd()
sbi, err := NewSBI(spb.Type_TYPE_OPENCONFIG)
if err != nil {
......@@ -800,7 +809,7 @@ func Test_pndImplementation_GetDevice(t *testing.T) {
t.Error(err)
return
}
d, err := NewDevice("default", did, newGnmiTransportOptions(), sbi)
d, err := NewDevice("default", did, opts, sbi)
if err != nil {
t.Error(err)
return
......@@ -850,6 +859,15 @@ func Test_pndImplementation_GetDevice(t *testing.T) {
}
func Test_pndImplementation_GetDeviceByName(t *testing.T) {
opts := &tpb.TransportOption{
Address: "",
Username: "test",
Password: "test",
TransportOption: &tpb.TransportOption_GnmiTransportOption{
GnmiTransportOption: &tpb.GnmiTransportOption{},
},
}
pnd := newPnd()
sbi, err := NewSBI(spb.Type_TYPE_OPENCONFIG)
if err != nil {
......@@ -861,7 +879,7 @@ func Test_pndImplementation_GetDeviceByName(t *testing.T) {
t.Error(err)
return
}
d, err := NewDevice("my-device", did, newGnmiTransportOptions(), sbi)
d, err := NewDevice("my-device", did, opts, sbi)
if err != nil {
t.Error(err)
return
......@@ -930,12 +948,12 @@ func Test_pndImplementation_Confirm(t *testing.T) {
deviceService := NewGenericService[device.Device]()
pnd := pndImplementation{
Name: "default",
Description: "default test pnd",
sbic: &sbiService,
devices: &deviceService,
changes: store.NewChangeStore(),
Id: defaultPndID,
Name: "default",
Description: "default test pnd",
southboundService: &sbiService,
deviceService: &deviceService,
changes: store.NewChangeStore(),
Id: defaultPndID,
}
d := mockDevice()
......