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

added more feedback changes

parent 18b45dcd
Branches
Tags
3 merge requests!376Add additional example application hostname-checker,!343Add basic application framework and example application to show interaction between events an NBI,!342Resolve "Add an option to send gNMI Subscribe requests via SBI"
Pipeline #108635 passed
This commit is part of merge request !342. Comments created here will be created in the context of that merge request.
......@@ -15,7 +15,7 @@ type Transport interface {
Get(ctx context.Context, params ...string) (interface{}, error)
Set(ctx context.Context, payload change.Payload, path string, schema *ytypes.Schema) error
Subscribe(ctx context.Context, params ...string) error
SubscribeInternal(ctx context.Context, subscribeCallbackFunc HandleSubscribeResponse,
ControlPlaneSubscribe(ctx context.Context, subscribeCallbackFunc HandleSubscribeResponse,
subscriptionInfo *SubscriptionInformation) error
Type() string
ProcessResponse(resp interface{}, root interface{}, models *ytypes.Schema) error
......
......@@ -21,6 +21,20 @@ type Transport struct {
mock.Mock
}
// ControlPlaneSubscribe provides a mock function with given fields: ctx, subscribeCallbackFunc, subscriptionInfo
func (_m *Transport) ControlPlaneSubscribe(ctx context.Context, subscribeCallbackFunc transport.HandleSubscribeResponse, subscriptionInfo *transport.SubscriptionInformation) error {
ret := _m.Called(ctx, subscribeCallbackFunc, subscriptionInfo)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, transport.HandleSubscribeResponse, *transport.SubscriptionInformation) error); ok {
r0 = rf(ctx, subscribeCallbackFunc, subscriptionInfo)
} else {
r0 = ret.Error(0)
}
return r0
}
// Get provides a mock function with given fields: ctx, params
func (_m *Transport) Get(ctx context.Context, params ...string) (interface{}, error) {
_va := make([]interface{}, len(params))
......@@ -100,20 +114,6 @@ func (_m *Transport) Subscribe(ctx context.Context, params ...string) error {
return r0
}
// SubscribeInternal provides a mock function with given fields: ctx, subscribeCallbackFunc, subscriptionInfo
func (_m *Transport) SubscribeInternal(ctx context.Context, subscribeCallbackFunc transport.HandleSubscribeResponse, subscriptionInfo *transport.SubscriptionInformation) error {
ret := _m.Called(ctx, subscribeCallbackFunc, subscriptionInfo)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, transport.HandleSubscribeResponse, *transport.SubscriptionInformation) error); ok {
r0 = rf(ctx, subscribeCallbackFunc, subscriptionInfo)
} else {
r0 = ret.Error(0)
}
return r0
}
// Type provides a mock function with given fields:
func (_m *Transport) Type() string {
ret := _m.Called()
......
......@@ -8,7 +8,6 @@ import (
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/transport"
"code.fbi.h-da.de/danet/gosdn/controller/nucleus/errors"
"code.fbi.h-da.de/danet/gosdn/controller/nucleus/types"
"code.fbi.h-da.de/danet/gosdn/controller/store"
"code.fbi.h-da.de/danet/gosdn/forks/goarista/gnmi"
"github.com/google/uuid"
gpb "github.com/openconfig/gnmi/proto/gnmi"
......@@ -43,10 +42,6 @@ func NewDeviceWatcher(pndStore networkdomain.PndStore) *DeviceWatcher {
}
}
func (d *DeviceWatcher) GetDeviceWatcher() *DeviceWatcher {
return d
}
// 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"}}
// SubscribeOptions can be nil. Use nil for a fixed, pre-defined set of gNMI subscription options (streaming in sample mode each second).
......@@ -89,7 +84,7 @@ func (d *DeviceWatcher) callSubscribe(stopContext context.Context, pndID string,
// SubscriptionInformation contains pnd ID, device ID and name to be used in the internal subscribe to check
// from which device a response was sent
if err := device.Transport().SubscribeInternal(gNMIOptionsCtx, d.handleSubscribeResponse, &transport.SubscriptionInformation{
if err := device.Transport().ControlPlaneSubscribe(gNMIOptionsCtx, d.handleSubscribeResponse, &transport.SubscriptionInformation{
PndID: pndID,
DeviceID: device.ID().String(),
DeviceName: device.Name(),
......@@ -100,7 +95,7 @@ func (d *DeviceWatcher) callSubscribe(stopContext context.Context, pndID string,
}
func (d *DeviceWatcher) addToDeviceSubscriptions(subID uuid.UUID, devSub *deviceSubscriptionHelper) {
//TODO: improve handling of subscriptions, like be able to expose to apps instead of just printing in controller!
//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
d.deviceSubcriptions[subID] = devSub
}
......@@ -147,6 +142,4 @@ func (d *DeviceWatcher) handleSubscribeResponse(resp *gpb.SubscribeResponse, sub
func (d *DeviceWatcher) handleSubscribeResponseUpdate(resp *gpb.SubscribeResponse_Update, subscriptionInfo *transport.SubscriptionInformation) {
// Not fully implemented yet, just a simple log to see if this works for now
log.Infof("Pnd: %s, Device: %s, Message: %s", subscriptionInfo.PndID, subscriptionInfo.DeviceID, resp.Update.String())
pnd, _ := d.pndStore.Get(store.Query{ID: uuid.MustParse(subscriptionInfo.PndID)})
log.Infof("Pnd from storage %v", pnd)
}
......@@ -200,14 +200,14 @@ func (g *Gnmi) Subscribe(ctx context.Context, params ...string) error {
return g.subscribe(ctx)
}
// SubscribeInternal is used to subscribe to devices from within the controller. gNMI SubscribeOptions need to be provided in the context,
// ControlPlaneSubscribe is used to subscribe to devices from within the controller. gNMI SubscribeOptions need to be provided in the context,
// the callback function handles the responses received from the subscription.
func (g *Gnmi) SubscribeInternal(ctx context.Context, subscribeCallbackFunc tpInterface.HandleSubscribeResponse, subscriptionInfo *tpInterface.SubscriptionInformation) error {
func (g *Gnmi) ControlPlaneSubscribe(ctx context.Context, subscribeCallbackFunc tpInterface.HandleSubscribeResponse, subscriptionInfo *tpInterface.SubscriptionInformation) error {
if g.client == nil {
return &errors.ErrNilClient{}
}
return g.subscribeInternal(ctx, subscribeCallbackFunc, subscriptionInfo)
return g.controlPlaneSubscribe(ctx, subscribeCallbackFunc, subscriptionInfo)
}
// Type returns the gNMI transport type
......@@ -338,9 +338,9 @@ func (g *Gnmi) subscribe(ctx context.Context) error {
return gnmi.SubscribeErr(ctx, g.client, opts, g.RespChan)
}
// subscribeInternal calls gNMI subscribe with a callback for responses and additional device information including
// controlPlaneSubscribe calls gNMI subscribe with a callback for responses and additional device information including
// an option to stop the subscription.
func (g *Gnmi) subscribeInternal(ctx context.Context, subcribeCallbackFunc func(*gpb.SubscribeResponse,
func (g *Gnmi) controlPlaneSubscribe(ctx context.Context, subcribeCallbackFunc func(*gpb.SubscribeResponse,
*tpInterface.SubscriptionInformation), subscriptionInfo *tpInterface.SubscriptionInformation) error {
ctx = gnmi.NewContext(ctx, g.config)
opts, ok := ctx.Value(types.CtxKeyOpts).(*gnmi.SubscribeOptions)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment