diff --git a/controller/northbound/server/submanagement.go b/controller/northbound/server/submanagement.go index bdc67e4e13f8ce3327ebd3a812f0af54fc6e4131..eb75420e7a482e753895e46d11ae687d7f10adee 100644 --- a/controller/northbound/server/submanagement.go +++ b/controller/northbound/server/submanagement.go @@ -27,8 +27,7 @@ func (s *SubManagementServer) ResetAllSubscriptions(ctx context.Context, request s.networkElementWatchter.StopAndRemoveAllNetworkElementSubscriptions() - // Requires some rework of current way how paths/options are provided to the watcher. - s.networkElementWatchter.SubscribeToNetworkElements(subscriptions[0].Opts) + s.networkElementWatchter.SubscribeToNetworkElements(subscriptions) return &subpb.ResetAllSubscriptionsResponse{ Timestamp: time.Now().UnixNano(), @@ -42,7 +41,6 @@ func (s *SubManagementServer) GetAll(ctx context.Context, request *subpb.GetAllR subInfosToReturn := make([]*subpb.Subscription, 0) for _, info := range subInfos { - tmpPaths := make([]*subpb.Path, 0) for _, path := range info.Opts.Paths { tmpPaths = append(tmpPaths, &subpb.Path{ diff --git a/controller/nucleus/networkElementWatcher.go b/controller/nucleus/networkElementWatcher.go index bbe19684bc7e2b5719556b1863d0fddbd12c20d3..dd7a8cd685cd86825c10892d918333283df2345b 100644 --- a/controller/nucleus/networkElementWatcher.go +++ b/controller/nucleus/networkElementWatcher.go @@ -60,9 +60,10 @@ func NewNetworkElementWatcher(mneService networkelement.Service, eventService ev // SubscribeToNetworkElements subscribes to every available network element in each network domain according to provided SubscribeOptions. // SubscribeOptions can be nil. Use nil for a fixed, pre-defined set of gNMI subscription options (streaming in sample mode each second). -func (n *NetworkElementWatcher) SubscribeToNetworkElements(opts *gnmi.SubscribeOptions) { - if opts == nil { - opts = &gnmi.SubscribeOptions{ +func (n *NetworkElementWatcher) SubscribeToNetworkElements(subScriptionInfos []*networkelementSubscriptionHelper) { + var tmpOpts *gnmi.SubscribeOptions + if len(subScriptionInfos) == 0 { + tmpOpts = &gnmi.SubscribeOptions{ Mode: gNMISubscribeMode, StreamMode: gNMIStreamMode, SampleInterval: subscribeSampleInterval, @@ -76,7 +77,15 @@ func (n *NetworkElementWatcher) SubscribeToNetworkElements(opts *gnmi.SubscribeO } for _, mne := range mnes { - n.subscribeToNetworkElement(mne, opts) + if len(subScriptionInfos) > 0 { + tmpOpts, err = getOptionsForMne(mne.ID().String(), subScriptionInfos) + if err != nil { + log.Infof("Couldn't find options for mne %s, reason: %v. \n Skipping subscription.", mne.Name(), err) + continue + } + } + + n.subscribeToNetworkElement(mne, tmpOpts) } } @@ -141,7 +150,6 @@ func (n *NetworkElementWatcher) callSubscribe(stopContext context.Context, mne n } func (n *NetworkElementWatcher) addToNetworkElementSubscriptions(subID uuid.UUID, devSub *networkelementSubscriptionHelper) { - //TODO: improve handling of subscriptions, like be able to expose to apps so specific subscriptions instead of only all can be stopped in the future n.networkelementSubcriptions[subID] = devSub } @@ -262,3 +270,15 @@ func (n *NetworkElementWatcher) GetSubscriptionInformations(subID uuid.UUID) (*n return information, nil } + +// getOptionsForMne checks if there is a match of the mneID with all the mne IDs provided in the slice of subscription +// information and returns the related subscribe options or an error. +func getOptionsForMne(mneID string, subInfos []*networkelementSubscriptionHelper) (*gnmi.SubscribeOptions, error) { + for _, subInfo := range subInfos { + if subInfo.MneID == mneID { + return subInfo.Opts, nil + } + } + + return nil, fmt.Errorf("error: did not find subscription infos matching to provided mne ID: %s", mneID) +}