diff --git a/controller/interfaces/transport/transport.go b/controller/interfaces/transport/transport.go index a20aa2a553a50400403b8802b7e400df7a9f75d5..d4e5c724b19f9ec1076e2f06be6f5bb78776bede 100644 --- a/controller/interfaces/transport/transport.go +++ b/controller/interfaces/transport/transport.go @@ -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 diff --git a/controller/mocks/Transport.go b/controller/mocks/Transport.go index c02d9afa93019d1378ac2e2f758ff652cef3c783..fc30aa3e0b02308d928e1fefcdab262b80c7974e 100644 --- a/controller/mocks/Transport.go +++ b/controller/mocks/Transport.go @@ -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() diff --git a/controller/nucleus/deviceWatcher.go b/controller/nucleus/deviceWatcher.go index 9ce1fe696aa3fa473d2b16ba048ef734f0a5b6ae..1808d6af5a9771bdb91077df8b63bf2a12ce30d3 100644 --- a/controller/nucleus/deviceWatcher.go +++ b/controller/nucleus/deviceWatcher.go @@ -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) } diff --git a/controller/nucleus/gnmi_transport.go b/controller/nucleus/gnmi_transport.go index 6b8e4a90b13d822468385171342fa1187042871b..d2f0a6c0a4a116e4e347432926e135adfca7ac56 100644 --- a/controller/nucleus/gnmi_transport.go +++ b/controller/nucleus/gnmi_transport.go @@ -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)