From d504ef53d18dd36280be8acde14fe5ad7f2d07cd Mon Sep 17 00:00:00 2001 From: Fabian Seidl <fabian.b.seidl@stud.h-da.de> Date: Mon, 11 Jul 2022 09:43:54 +0200 Subject: [PATCH] added optional, configurable subscribe options --- controller/controller.go | 2 +- controller/nucleus/deviceWatcher.go | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/controller/controller.go b/controller/controller.go index 99a57a180..9f655c3e7 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -82,7 +82,7 @@ func initialize() error { c.deviceWatcher = nucleus.NewDeviceWatcher(c.pndStore) //TODO: Just an example for testing purposes, remove these calls after complete implementation of subscription handling! - c.deviceWatcher.SubToDevices([][]string{{"system", "config", "hostname"}}) + c.deviceWatcher.SubToDevices([][]string{{"system", "config", "hostname"}}, nil) go func() { time.Sleep(5 * time.Second) c.deviceWatcher.StopAndRemoveAllDeviceSubscriptions() diff --git a/controller/nucleus/deviceWatcher.go b/controller/nucleus/deviceWatcher.go index d27e98cb8..eb53357f5 100644 --- a/controller/nucleus/deviceWatcher.go +++ b/controller/nucleus/deviceWatcher.go @@ -42,15 +42,17 @@ func NewDeviceWatcher(pndStore networkdomain.PndStore) *DeviceWatcher { } } -// SubToDevices subscribes to every available device in each network domain with fixed gNMI subscription options (streaming in sample mode each second). +// SubToDevices subscribes to every available device in each network domain according to provided SubscribeOptions. // Paths should be provided in the following format [][]string{{"system", "config", "hostname"}} -func (d *DeviceWatcher) SubToDevices(paths [][]string) { - // TODO: think about passing opts as parameter for more configurability - opts := &gnmi.SubscribeOptions{ - Mode: gNMISubscribeMode, - StreamMode: gNMIStreamMode, - Paths: paths, - SampleInterval: subscribeSampleInterval, +// SubscribeOptions can be nil. Use nil for a fixed, pre-defined set of gNMI subscription options (streaming in sample mode each second). +func (d *DeviceWatcher) SubToDevices(paths [][]string, opts *gnmi.SubscribeOptions) { + if opts == nil { + opts = &gnmi.SubscribeOptions{ + Mode: gNMISubscribeMode, + StreamMode: gNMIStreamMode, + Paths: paths, + SampleInterval: subscribeSampleInterval, + } } pnds, err := d.pndStore.GetAll() -- GitLab