diff --git a/controller/controller.go b/controller/controller.go index 99a57a18071db6fdac0bcb5644243ee26b9c866c..9f655c3e7b997c05ead5f78929bf4a848377ceeb 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 d27e98cb8e688fcef6c4ddb1a99513024d714b03..eb53357f512061baaaf859567a9d9fc6e256874b 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()