diff --git a/controller/interfaces/networkelement/networkElement.go b/controller/interfaces/networkelement/networkElement.go index 54d1b6b65856e85e955442a16e57126f6fbc7e28..a1529a8f1642be1a7eef809e0a5822e26c4044a2 100644 --- a/controller/interfaces/networkelement/networkElement.go +++ b/controller/interfaces/networkelement/networkElement.go @@ -67,7 +67,7 @@ type LoadedNetworkElement struct { // EnsureIntendedConfigurationIsAppliedOnNetworkElement pushes the stored // configuration to a network element. -// TODO: find a better place for this function +// TODO: find a better place for this function. func EnsureIntendedConfigurationIsAppliedOnNetworkElement(mne NetworkElement) error { model, err := mne.GetModelAsFilteredCopy() if err != nil { diff --git a/controller/northbound/server/configurationmanagement.go b/controller/northbound/server/configurationmanagement.go index 7ada43b6cfca8a789771eea6e9ae77135746f766..8e5ed7791c5f18375b41060dc8a66880f5401871 100644 --- a/controller/northbound/server/configurationmanagement.go +++ b/controller/northbound/server/configurationmanagement.go @@ -336,7 +336,6 @@ func (c ConfigurationManagementServer) createNetworkElements(sdnConfig *loadedSD if err := networkelement.EnsureIntendedConfigurationIsAppliedOnNetworkElement(networkElement); err != nil { return err } - } return nil } diff --git a/controller/northbound/server/core_test.go b/controller/northbound/server/core_test.go index a6b0121448eb93035ded2a207c8b8956c48ce445..2a0853ea266405dc8db20be2cf48d18692c47229 100644 --- a/controller/northbound/server/core_test.go +++ b/controller/northbound/server/core_test.go @@ -89,7 +89,7 @@ func getTestCoreServer(t *testing.T) *CoreServer { regsitryClient := rpb.NewPluginRegistryServiceClient(&grpc.ClientConn{}) - c := NewCoreServer(pndService, regsitryClient, nucleus.NewPluginService(pluginStore, eventService, nucleus.NewPluginThroughReattachConfig, regsitryClient), func(u uuid.UUID, c chan networkelement.Details) {}, cpb.NewCsbiServiceClient(&grpc.ClientConn{})) + c := NewCoreServer(pndService, nucleus.NewPluginService(pluginStore, eventService, nucleus.NewPluginThroughReattachConfig, regsitryClient), func(u uuid.UUID, c chan networkelement.Details) {}, cpb.NewCsbiServiceClient(&grpc.ClientConn{})) return c } diff --git a/controller/northbound/server/networkElement.go b/controller/northbound/server/networkElement.go index edb6e7cbadbca7988ceff497f0c0b4fe5c5e23a7..bd3904bb0c641a100ea32349344f24f108191660 100644 --- a/controller/northbound/server/networkElement.go +++ b/controller/northbound/server/networkElement.go @@ -403,23 +403,23 @@ func fillMneBySpecificPath(nme networkelement.NetworkElement, path string) (*mne return mne, nil } -func genGnmiNotification(path *gpb.Path, val any) (*gpb.Notification, error) { - typedVal, err := ygot.EncodeTypedValue(val, gpb.Encoding_JSON_IETF) - if err != nil { - return nil, err - } - return &gpb.Notification{ - Timestamp: time.Now().UnixNano(), - Update: []*gpb.Update{ - { - Path: &gpb.Path{ - Elem: path.GetElem(), - }, - Val: typedVal, - }, - }, - }, nil -} +// func genGnmiNotification(path *gpb.Path, val any) (*gpb.Notification, error) { +// typedVal, err := ygot.EncodeTypedValue(val, gpb.Encoding_JSON_IETF) +// if err != nil { +// return nil, err +// } +// return &gpb.Notification{ +// Timestamp: time.Now().UnixNano(), +// Update: []*gpb.Update{ +// { +// Path: &gpb.Path{ +// Elem: path.GetElem(), +// }, +// Val: typedVal, +// }, +// }, +// }, nil +// } // GetPath gets a path on a mne. func (n *NetworkElementServer) GetPath(ctx context.Context, request *mnepb.GetPathRequest) (*mnepb.GetPathResponse, error) { diff --git a/controller/northbound/server/test_util_test.go b/controller/northbound/server/test_util_test.go index 4a1e7aadad934edf543bc0eda4e088befa780c8f..72ded5bc087c580b3829a1daff782eb86b23d2b0 100644 --- a/controller/northbound/server/test_util_test.go +++ b/controller/northbound/server/test_util_test.go @@ -3,26 +3,19 @@ package server import ( "bytes" "encoding/base64" - "fmt" "log" - "os" - "path/filepath" "testing" "code.fbi.h-da.de/danet/gosdn/controller/conflict" - eventservice "code.fbi.h-da.de/danet/gosdn/controller/eventService" - "code.fbi.h-da.de/danet/gosdn/controller/interfaces/networkdomain" "code.fbi.h-da.de/danet/gosdn/controller/interfaces/networkelement" "code.fbi.h-da.de/danet/gosdn/controller/interfaces/plugin" rbacInterfaces "code.fbi.h-da.de/danet/gosdn/controller/interfaces/rbac" "code.fbi.h-da.de/danet/gosdn/controller/mocks" - "code.fbi.h-da.de/danet/gosdn/controller/nucleus" "code.fbi.h-da.de/danet/gosdn/controller/rbac" "code.fbi.h-da.de/danet/gosdn/controller/store" "github.com/google/uuid" "github.com/sethvargo/go-password/password" - "github.com/stretchr/testify/mock" "golang.org/x/crypto/argon2" ) @@ -207,31 +200,31 @@ func createHashedAndSaltedPassword(plainPWD, salt string) string { return base64.RawStdEncoding.EncodeToString(argon2.IDKey([]byte(plainPWD), []byte(salt), 1, 64*1024, 4, 32)) } -func getMockPnd(t *testing.T) networkdomain.NetworkDomain { - mockNetworkElement = &nucleus.CommonNetworkElement{ - Plugin: &mocks.Plugin{}, - UUID: mneUUID, - } - - mockNetworkElement.(*nucleus.CommonNetworkElement).SetTransport(&mocks.Transport{}) - mockNetworkElement.(*nucleus.CommonNetworkElement).SetName(hostname) - - mockPnd = &mocks.NetworkDomain{} - mockPnd.On("ID").Return(pndUUID) - mockPnd.On("GetName").Return("test") - mockPnd.On("GetDescription").Return("test") - mockPnd.On("NetworkElements").Return([]uuid.UUID{mneUUID}) - mockPnd.On("PendingChanges").Return([]uuid.UUID{pendingChangeUUID}) - mockPnd.On("CommittedChanges").Return([]uuid.UUID{committedChangeUUID}) - mockPnd.On("AddNetworkElement", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - mockPnd.On("GetNetworkElement", mock.Anything).Return(mockNetworkElement, nil) - mockPnd.On("Commit", mock.Anything).Return(nil) - mockPnd.On("Confirm", mock.Anything).Return(nil) - mockPnd.On("ChangeMNE", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(uuid.Nil, nil) - mockPnd.On("Request", mock.Anything, mock.Anything).Return(nil, nil) - - return mockPnd -} +// func getMockPnd(t *testing.T) networkdomain.NetworkDomain { +// mockNetworkElement = &nucleus.CommonNetworkElement{ +// Plugin: &mocks.Plugin{}, +// UUID: mneUUID, +// } + +// mockNetworkElement.(*nucleus.CommonNetworkElement).SetTransport(&mocks.Transport{}) +// mockNetworkElement.(*nucleus.CommonNetworkElement).SetName(hostname) + +// mockPnd = &mocks.NetworkDomain{} +// mockPnd.On("ID").Return(pndUUID) +// mockPnd.On("GetName").Return("test") +// mockPnd.On("GetDescription").Return("test") +// mockPnd.On("NetworkElements").Return([]uuid.UUID{mneUUID}) +// mockPnd.On("PendingChanges").Return([]uuid.UUID{pendingChangeUUID}) +// mockPnd.On("CommittedChanges").Return([]uuid.UUID{committedChangeUUID}) +// mockPnd.On("AddNetworkElement", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) +// mockPnd.On("GetNetworkElement", mock.Anything).Return(mockNetworkElement, nil) +// mockPnd.On("Commit", mock.Anything).Return(nil) +// mockPnd.On("Confirm", mock.Anything).Return(nil) +// mockPnd.On("ChangeMNE", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(uuid.Nil, nil) +// mockPnd.On("Request", mock.Anything, mock.Anything).Return(nil, nil) + +// return mockPnd +// } func getMockPlugin(t *testing.T) plugin.Plugin { mockPlugin := &mocks.Plugin{} @@ -269,44 +262,44 @@ func initUUIDs(t *testing.T) { } } -func createTestNetworkElementServer(t *testing.T, mneServer *NetworkElementServer) { - initUUIDs(t) +// func createTestNetworkElementServer(t *testing.T, mneServer *NetworkElementServer) { +// initUUIDs(t) - eventService := eventservice.NewMockEventService() +// eventService := eventservice.NewMockEventService() - pluginService := nucleus.NewPluginServiceMock() +// pluginService := nucleus.NewPluginServiceMock() - pndStore := nucleus.NewPndStore(pluginService) - pndService := nucleus.NewPndService(pndStore) +// pndStore := nucleus.NewPndStore(pluginService) +// pndService := nucleus.NewPndService(pndStore) - mneStore := nucleus.NewNetworkElementStore() - mneService := nucleus.NewNetworkElementService(mneStore, pluginService, eventService) +// mneStore := nucleus.NewNetworkElementStore() +// mneService := nucleus.NewNetworkElementService(mneStore, pluginService, eventService) - changeStore := store.NewChangeStore() +// changeStore := store.NewChangeStore() - *mneServer = *NewNetworkElementServer(mneService, pndService, pluginService, *changeStore) +// *mneServer = *NewNetworkElementServer(mneService, pndService, pluginService, *changeStore) - //t.Cleanup(removeTestStores) -} +// //t.Cleanup(removeTestStores) +// } -func removeTestStores() { - ex, err := os.Executable() - if err != nil { - log.Println(err) - } - exPath := filepath.Dir(ex) +// func removeTestStores() { +// ex, err := os.Executable() +// if err != nil { +// log.Println(err) +// } +// exPath := filepath.Dir(ex) - fmt.Println(exPath) +// fmt.Println(exPath) - err = os.RemoveAll(exPath + "/stores_testing") - if err != nil { - log.Println(err) - } -} +// err = os.RemoveAll(exPath + "/stores_testing") +// if err != nil { +// log.Println(err) +// } +// } -func cleanMneAndSbiTestStore(mneServer *NetworkElementServer) { - mneToDelete, _ := mneServer.mneService.GetAll() - for _, mne := range mneToDelete { - _ = mneServer.mneService.Delete(mne) - } -} +// func cleanMneAndSbiTestStore(mneServer *NetworkElementServer) { +// mneToDelete, _ := mneServer.mneService.GetAll() +// for _, mne := range mneToDelete { +// _ = mneServer.mneService.Delete(mne) +// } +// } diff --git a/controller/nucleus/databasePndStore.go b/controller/nucleus/databasePndStore.go index 47ef691dc1192ed22ff4daff373149fef975e0b0..c5497a000e130713c4b1cc20ce7103ed5d259081 100644 --- a/controller/nucleus/databasePndStore.go +++ b/controller/nucleus/databasePndStore.go @@ -7,27 +7,20 @@ import ( "code.fbi.h-da.de/danet/gosdn/controller/interfaces/networkelement" "code.fbi.h-da.de/danet/gosdn/controller/interfaces/plugin" - cpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/csbi" - plugin_registry "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/plugin-registry" "code.fbi.h-da.de/danet/gosdn/controller/customerrs" "code.fbi.h-da.de/danet/gosdn/controller/nucleus/database" "code.fbi.h-da.de/danet/gosdn/controller/store" "github.com/google/uuid" log "github.com/sirupsen/logrus" - "github.com/spf13/viper" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials/insecure" ) // DatabasePndStore is used to store PrincipalNetworkDomains. type DatabasePndStore struct { - pndStoreName string - pendingChannels map[uuid.UUID]chan networkelement.Details - pluginService plugin.Service - csbiClient cpb.CsbiServiceClient - pluginRegistryClient plugin_registry.PluginRegistryServiceClient + pndStoreName string + pendingChannels map[uuid.UUID]chan networkelement.Details + pluginService plugin.Service } // Get takes a PrincipalNetworkDomain's UUID or name and returns the PrincipalNetworkDomain. If the requested @@ -49,7 +42,7 @@ func (s *DatabasePndStore) Get(query store.Query) (newPnd networkdomain.LoadedPn return loadedPND, err } - // Note: add this if using cSBI agian + // Note: add this if using cSBI again // csbiClient, err := s.getCsbiClient() // if err != nil { // return loadedPND, err @@ -238,40 +231,26 @@ func (s *DatabasePndStore) RemovePendingChannel(id uuid.UUID) { delete(s.pendingChannels, id) } -func (s *DatabasePndStore) callback(id uuid.UUID, ch chan networkelement.Details) { - if ch != nil { - s.AddPendingChannel(id, ch) - log.Infof("pending channel %v added", id) - } else { - s.RemovePendingChannel(id) - log.Infof("pending channel %v removed", id) - } -} - -func (s *DatabasePndStore) getCsbiClient() (cpb.CsbiServiceClient, error) { - if s.csbiClient == nil { - orchestrator := viper.GetString("csbi-orchestrator") - conn, err := grpc.Dial(orchestrator, grpc.WithTransportCredentials(insecure.NewCredentials())) - if err != nil { - return nil, err - } - - s.csbiClient = cpb.NewCsbiServiceClient(conn) - } - - return s.csbiClient, nil -} - -func (s *DatabasePndStore) getPluginRegistryClient() (plugin_registry.PluginRegistryServiceClient, error) { - if s.pluginRegistryClient == nil { - pluginRegistry := viper.GetString("plugin-registry") - conn, err := grpc.Dial(pluginRegistry, grpc.WithTransportCredentials(insecure.NewCredentials())) - if err != nil { - return nil, err - } - - s.pluginRegistryClient = plugin_registry.NewPluginRegistryServiceClient(conn) - } - - return s.pluginRegistryClient, nil -} +// func (s *DatabasePndStore) callback(id uuid.UUID, ch chan networkelement.Details) { +// if ch != nil { +// s.AddPendingChannel(id, ch) +// log.Infof("pending channel %v added", id) +// } else { +// s.RemovePendingChannel(id) +// log.Infof("pending channel %v removed", id) +// } +// } + +// func (s *DatabasePndStore) getCsbiClient() (cpb.CsbiServiceClient, error) { +// if s.csbiClient == nil { +// orchestrator := viper.GetString("csbi-orchestrator") +// conn, err := grpc.Dial(orchestrator, grpc.WithTransportCredentials(insecure.NewCredentials())) +// if err != nil { +// return nil, err +// } + +// s.csbiClient = cpb.NewCsbiServiceClient(conn) +// } + +// return s.csbiClient, nil +// } diff --git a/controller/nucleus/initialise_test.go b/controller/nucleus/initialise_test.go index 9fe43d02d7391cf764bb34cd7c692562eb17176a..ac99f917528780d9baa85b0f2ddab2cb36185ade 100644 --- a/controller/nucleus/initialise_test.go +++ b/controller/nucleus/initialise_test.go @@ -6,8 +6,6 @@ import ( "path/filepath" "testing" - eventservice "code.fbi.h-da.de/danet/gosdn/controller/eventService" - "code.fbi.h-da.de/danet/gosdn/controller/interfaces/networkelement" "code.fbi.h-da.de/danet/gosdn/controller/store" tpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/transport" @@ -152,54 +150,54 @@ func readTestUUIDs() { } } -func mockNetworkElement() networkelement.NetworkElement { - mockPlugin := &mocks.Plugin{} - mockPlugin.On("ID").Return(defaultPluginID) - mockPlugin.On("Unmarshal", mock.Anything, mock.Anything).Return(nil) - mockPlugin.On("Model", mock.Anything).Return([]byte( - "{\n\t\"Acl\": null,\n\t\"Bfd\": null,\n\t\"Components\": null,\n\t\"Interfaces\": null,\n\t\"Keychains\": null,\n\t\"Lldp\": null,\n\t\"Messages\": null,\n\t\"NetworkInstances\": null,\n\t\"RoutingPolicy\": null,\n\t\"System\": null\n}"), - nil, - ) +// func mockNetworkElement() networkelement.NetworkElement { +// mockPlugin := &mocks.Plugin{} +// mockPlugin.On("ID").Return(defaultPluginID) +// mockPlugin.On("Unmarshal", mock.Anything, mock.Anything).Return(nil) +// mockPlugin.On("Model", mock.Anything).Return([]byte( +// "{\n\t\"Acl\": null,\n\t\"Bfd\": null,\n\t\"Components\": null,\n\t\"Interfaces\": null,\n\t\"Keychains\": null,\n\t\"Lldp\": null,\n\t\"Messages\": null,\n\t\"NetworkInstances\": null,\n\t\"RoutingPolicy\": null,\n\t\"System\": null\n}"), +// nil, +// ) - return &CommonNetworkElement{ - UUID: mdid, - Plugin: mockPlugin, - transport: &mocks.Transport{}, - name: "mockNetworkElement", - } -} +// return &CommonNetworkElement{ +// UUID: mdid, +// Plugin: mockPlugin, +// transport: &mocks.Transport{}, +// name: "mockNetworkElement", +// } +// } -func newPnd() (*pndImplementation, error) { - mockPlugin := &mocks.Plugin{} - mockPlugin.On("ID").Return(defaultPluginID) - mockPlugin.On("Unmarshal", mock.Anything, mock.Anything).Return(nil) - mockPlugin.On("Model", mock.Anything).Return([]byte( - "{\n\t\"Acl\": null,\n\t\"Bfd\": null,\n\t\"Components\": null,\n\t\"Interfaces\": null,\n\t\"Keychains\": null,\n\t\"Lldp\": null,\n\t\"Messages\": null,\n\t\"NetworkInstances\": null,\n\t\"RoutingPolicy\": null,\n\t\"System\": null\n}"), - nil, - ) +// func newPnd() (*pndImplementation, error) { +// mockPlugin := &mocks.Plugin{} +// mockPlugin.On("ID").Return(defaultPluginID) +// mockPlugin.On("Unmarshal", mock.Anything, mock.Anything).Return(nil) +// mockPlugin.On("Model", mock.Anything).Return([]byte( +// "{\n\t\"Acl\": null,\n\t\"Bfd\": null,\n\t\"Components\": null,\n\t\"Interfaces\": null,\n\t\"Keychains\": null,\n\t\"Lldp\": null,\n\t\"Messages\": null,\n\t\"NetworkInstances\": null,\n\t\"RoutingPolicy\": null,\n\t\"System\": null\n}"), +// nil, +// ) - eventService := eventservice.NewMockEventService() +// eventService := eventservice.NewMockEventService() - deviceStore := NewMemoryNetworkElementStore() - pluginService := NewPluginServiceMock() - err := pluginService.Add(mockPlugin) - if err != nil { - return nil, err - } - deviceService := NewNetworkElementService( - deviceStore, - pluginService, - eventService, - ) +// deviceStore := NewMemoryNetworkElementStore() +// pluginService := NewPluginServiceMock() +// err := pluginService.Add(mockPlugin) +// if err != nil { +// return nil, err +// } +// deviceService := NewNetworkElementService( +// deviceStore, +// pluginService, +// eventService, +// ) - return &pndImplementation{ - Name: "default", - Description: "default test pnd", - pluginService: pluginService, - networkElementService: deviceService, - Id: defaultPndID, - }, nil -} +// return &pndImplementation{ +// Name: "default", +// Description: "default test pnd", +// pluginService: pluginService, +// networkElementService: deviceService, +// Id: defaultPndID, +// }, nil +// } // removeTestGoStructs removes the plugins created during running the test in the current directory based on their name consisting of a uuid // and the time since they`ve been created. diff --git a/controller/nucleus/pluginServiceMock.go b/controller/nucleus/pluginServiceMock.go index d9a44d58739775725e10a4267c77c0aaa8530133..a580657fcd7c203ea0bcbb51260c021f3f71d124 100644 --- a/controller/nucleus/pluginServiceMock.go +++ b/controller/nucleus/pluginServiceMock.go @@ -60,7 +60,7 @@ func (t *PluginServiceMock) GetAll() ([]plugin.Plugin, error) { } // RequestPlugin is a mock for requesting a plugin from the registry. -// TODO: add plugin mock here +// TODO: add plugin mock here. func (t *PluginServiceMock) RequestPlugin(uuid.UUID) (plugin.Plugin, error) { return nil, nil } diff --git a/controller/nucleus/principalNetworkDomain.go b/controller/nucleus/principalNetworkDomain.go index 4b4741a1573b4276bcdac43c66eae5ad8b65fe42..87e69a8cf55e957723974d0545dfaeef2ba1adbe 100644 --- a/controller/nucleus/principalNetworkDomain.go +++ b/controller/nucleus/principalNetworkDomain.go @@ -1,13 +1,9 @@ package nucleus import ( - "context" - "time" - "go.mongodb.org/mongo-driver/bson" cpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/csbi" - rpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/plugin-registry" eventservice "code.fbi.h-da.de/danet/gosdn/controller/eventService" @@ -16,16 +12,10 @@ import ( "code.fbi.h-da.de/danet/gosdn/controller/interfaces/networkelement" "code.fbi.h-da.de/danet/gosdn/controller/interfaces/plugin" - "code.fbi.h-da.de/danet/gosdn/controller/store" - "github.com/google/uuid" log "github.com/sirupsen/logrus" ) -// NOTE: Until we've added database support for changes, we will hold -// changeStores in memory for now. -var changeStoreMap = make(map[uuid.UUID]*store.ChangeStore) - // NewPND creates a Principle Network Domain. func NewPND( name string, @@ -80,10 +70,9 @@ type pndImplementation struct { //nolint Id uuid.UUID `json:"id,omitempty"` - csbiClient cpb.CsbiServiceClient - pluginRegistryClient rpb.PluginRegistryServiceClient - callback func(uuid.UUID, chan networkelement.Details) - eventService eventInterfaces.Service + csbiClient cpb.CsbiServiceClient + callback func(uuid.UUID, chan networkelement.Details) + eventService eventInterfaces.Service } func (pnd *pndImplementation) ID() uuid.UUID { @@ -107,24 +96,24 @@ func handleRollbackError(id uuid.UUID, err error) { // TODO: Notion of invalid state needed. } -func (pnd *pndImplementation) handleCsbiDeletion(mne networkelement.NetworkElement) error { - log.Infof("csbi deletion triggered for %v", mne.ID().String()) - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) - defer cancel() - req := &cpb.DeleteRequest{ - Timestamp: time.Now().UnixNano(), - Did: []string{mne.ID().String()}, - } - resp, err := pnd.csbiClient.Delete(ctx, req) - if err != nil { - return err - } - log.WithFields(log.Fields{ - "uuid": mne.ID().String(), - "status": resp.Status, - }).Info("csbi deleted") - return nil -} +// func (pnd *pndImplementation) handleCsbiDeletion(mne networkelement.NetworkElement) error { +// log.Infof("csbi deletion triggered for %v", mne.ID().String()) +// ctx, cancel := context.WithTimeout(context.Background(), time.Minute) +// defer cancel() +// req := &cpb.DeleteRequest{ +// Timestamp: time.Now().UnixNano(), +// Did: []string{mne.ID().String()}, +// } +// resp, err := pnd.csbiClient.Delete(ctx, req) +// if err != nil { +// return err +// } +// log.WithFields(log.Fields{ +// "uuid": mne.ID().String(), +// "status": resp.Status, +// }).Info("csbi deleted") +// return nil +// } //NOTE: csbi is currently not support; will be removed in the near future. //func (pnd *pndImplementation) handleCsbiEnrolment(name string, opt *tpb.TransportOption) (uuid.UUID, error) {