Skip to content
Snippets Groups Projects
Commit 98c85cce authored by Fabian Seidl's avatar Fabian Seidl
Browse files

change way paths/opts are provided for subscriptions

parent 05a8db89
No related branches found
No related tags found
No related merge requests found
...@@ -27,8 +27,7 @@ func (s *SubManagementServer) ResetAllSubscriptions(ctx context.Context, request ...@@ -27,8 +27,7 @@ func (s *SubManagementServer) ResetAllSubscriptions(ctx context.Context, request
s.networkElementWatchter.StopAndRemoveAllNetworkElementSubscriptions() s.networkElementWatchter.StopAndRemoveAllNetworkElementSubscriptions()
// Requires some rework of current way how paths/options are provided to the watcher. s.networkElementWatchter.SubscribeToNetworkElements(subscriptions)
s.networkElementWatchter.SubscribeToNetworkElements(subscriptions[0].Opts)
return &subpb.ResetAllSubscriptionsResponse{ return &subpb.ResetAllSubscriptionsResponse{
Timestamp: time.Now().UnixNano(), Timestamp: time.Now().UnixNano(),
...@@ -42,7 +41,6 @@ func (s *SubManagementServer) GetAll(ctx context.Context, request *subpb.GetAllR ...@@ -42,7 +41,6 @@ func (s *SubManagementServer) GetAll(ctx context.Context, request *subpb.GetAllR
subInfosToReturn := make([]*subpb.Subscription, 0) subInfosToReturn := make([]*subpb.Subscription, 0)
for _, info := range subInfos { for _, info := range subInfos {
tmpPaths := make([]*subpb.Path, 0) tmpPaths := make([]*subpb.Path, 0)
for _, path := range info.Opts.Paths { for _, path := range info.Opts.Paths {
tmpPaths = append(tmpPaths, &subpb.Path{ tmpPaths = append(tmpPaths, &subpb.Path{
......
...@@ -60,9 +60,10 @@ func NewNetworkElementWatcher(mneService networkelement.Service, eventService ev ...@@ -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. // 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). // 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) { func (n *NetworkElementWatcher) SubscribeToNetworkElements(subScriptionInfos []*networkelementSubscriptionHelper) {
if opts == nil { var tmpOpts *gnmi.SubscribeOptions
opts = &gnmi.SubscribeOptions{ if len(subScriptionInfos) == 0 {
tmpOpts = &gnmi.SubscribeOptions{
Mode: gNMISubscribeMode, Mode: gNMISubscribeMode,
StreamMode: gNMIStreamMode, StreamMode: gNMIStreamMode,
SampleInterval: subscribeSampleInterval, SampleInterval: subscribeSampleInterval,
...@@ -76,7 +77,15 @@ func (n *NetworkElementWatcher) SubscribeToNetworkElements(opts *gnmi.SubscribeO ...@@ -76,7 +77,15 @@ func (n *NetworkElementWatcher) SubscribeToNetworkElements(opts *gnmi.SubscribeO
} }
for _, mne := range mnes { 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 ...@@ -141,7 +150,6 @@ func (n *NetworkElementWatcher) callSubscribe(stopContext context.Context, mne n
} }
func (n *NetworkElementWatcher) addToNetworkElementSubscriptions(subID uuid.UUID, devSub *networkelementSubscriptionHelper) { 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 n.networkelementSubcriptions[subID] = devSub
} }
...@@ -262,3 +270,15 @@ func (n *NetworkElementWatcher) GetSubscriptionInformations(subID uuid.UUID) (*n ...@@ -262,3 +270,15 @@ func (n *NetworkElementWatcher) GetSubscriptionInformations(subID uuid.UUID) (*n
return information, nil 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)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment