diff --git a/controller/controller.go b/controller/controller.go index aadd8206d5ba61390bae3896717990c389e11dd4..6ea0fb68c34168df90896266c35353811ef7196a 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -128,7 +128,7 @@ func initialize() error { } c.networkElementWatcher = nucleus.NewNetworkElementWatcher(c.pndStore) - c.networkElementWatcher.SubToDevices(config.GetGnmiSubscriptionPaths(), nil) + c.networkElementWatcher.SubToNetworkElements(config.GetGnmiSubscriptionPaths(), nil) err = ensureDefaultRoleExists() if err != nil { diff --git a/controller/customerrs/errors.go b/controller/customerrs/errors.go index d5197bd0ce948fd7a735ba8b4181c49f213a4ab6..9873f10b3ac2e5beba60331361c19fedc6881bdb 100644 --- a/controller/customerrs/errors.go +++ b/controller/customerrs/errors.go @@ -35,7 +35,7 @@ func (e *AlreadyExistsError) Error() string { // InvalidUUIDError implements the Error interface and is called if a UUID is not valid. type InvalidUUIDError struct { - DeviceName string + NetworkElementName string } func (e *InvalidUUIDError) Error() string { @@ -255,24 +255,24 @@ func (e AMQPMessageFailError) Error() string { // SubscribeResponseError implements the Error interface and is called if there is an issue during a ongoing // gNMI Subscription. type SubscribeResponseError struct { - PndID string - DeviceID string - DeviceName string - Err string + PndID string + NetworkElementID string + NetworkElementName string + Err string } func (e SubscribeResponseError) Error() string { - return fmt.Sprintf("Subscribe failed, PndID: %s, DeviceID: %s, DeviceName: %s, Internal error: %s", e.PndID, e.DeviceID, e.DeviceName, e.Err) + return fmt.Sprintf("Subscribe failed, PndID: %s, NetworkElementID: %s, NetworkElementName: %s, Internal error: %s", e.PndID, e.NetworkElementID, e.NetworkElementName, e.Err) } // SubscribeSyncResponseError implements the Error interface and is called if there is an issue syncing a // gNMI Subscription. type SubscribeSyncResponseError struct { - PndID string - DeviceID string - DeviceName string + PndID string + NetworkElementID string + NetworkElementName string } func (e SubscribeSyncResponseError) Error() string { - return fmt.Sprintf("Sync failed, PndID: %s, DeviceID: %s, DeviceName: %s", e.PndID, e.DeviceID, e.DeviceName) + return fmt.Sprintf("Sync failed, PndID: %s, NetworkElementID: %s, NetworkElementName: %s", e.PndID, e.NetworkElementID, e.NetworkElementName) } diff --git a/controller/interfaces/transport/transport.go b/controller/interfaces/transport/transport.go index c5b969a1b041d06e2a9f949cd888bd0c11a76a91..e5d1f807a95a9665cb33f6bbffed325f0611863c 100644 --- a/controller/interfaces/transport/transport.go +++ b/controller/interfaces/transport/transport.go @@ -32,8 +32,8 @@ type ( // for distinguishing from which network element the information is from, to stop subscriptions and // error handling. type SubscriptionInformation struct { - PndID string - DeviceID string - DeviceName string - StopContext context.Context + PndID string + NetworkElementID string + NetworkElementName string + StopContext context.Context } diff --git a/controller/nucleus/networkElementWatcher.go b/controller/nucleus/networkElementWatcher.go index efbc97b3da1c84563ad78da31ed7559588565233..d3d0cc20c66e5da30923ffaf2e9f8f476bac9e3a 100644 --- a/controller/nucleus/networkElementWatcher.go +++ b/controller/nucleus/networkElementWatcher.go @@ -23,15 +23,15 @@ const ( gNMIStreamMode string = "on_change" ) -// NetworkElementWatcher is a component that subscribes to devices via gNMI from within the controller and handles +// NetworkElementWatcher is a component that subscribes to network elements via gNMI from within the controller and handles // responses by triggering the internal event process. type NetworkElementWatcher struct { - pndStore networkdomain.PndStore - deviceSubcriptions map[uuid.UUID]*deviceSubscriptionHelper + pndStore networkdomain.PndStore + networkelementSubcriptions map[uuid.UUID]*networkelementSubscriptionHelper } -// deviceSubscriptionHelper is used to store information to stop a running subscribe go routine. -type deviceSubscriptionHelper struct { +// networkelementSubscriptionHelper is used to store information to stop a running subscribe go routine. +type networkelementSubscriptionHelper struct { stopSubscribeCtx context.Context stopFunc context.CancelFunc } @@ -39,15 +39,15 @@ type deviceSubscriptionHelper struct { // NewNetworkElementWatcher takes a pndStore to subscribe to network element paths. func NewNetworkElementWatcher(pndStore networkdomain.PndStore) *NetworkElementWatcher { return &NetworkElementWatcher{ - pndStore: pndStore, - deviceSubcriptions: make(map[uuid.UUID]*deviceSubscriptionHelper), + pndStore: pndStore, + networkelementSubcriptions: make(map[uuid.UUID]*networkelementSubscriptionHelper), } } -// SubToDevices subscribes to every available network element in each network domain according to provided SubscribeOptions. +// SubToNetworkElements subscribes to every available network element 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). -func (d *NetworkElementWatcher) SubToDevices(paths [][]string, opts *gnmi.SubscribeOptions) { +func (n *NetworkElementWatcher) SubToNetworkElements(paths [][]string, opts *gnmi.SubscribeOptions) { if opts == nil { opts = &gnmi.SubscribeOptions{ Mode: gNMISubscribeMode, @@ -57,102 +57,102 @@ func (d *NetworkElementWatcher) SubToDevices(paths [][]string, opts *gnmi.Subscr } } - pnds, err := d.pndStore.GetAll() + pnds, err := n.pndStore.GetAll() if err != nil { log.Error(err) } for _, pnd := range pnds { - d.subscribeToPndDevices(pnd.ID().String(), pnd, opts) + n.subscribeToPndNetworkElements(pnd.ID().String(), pnd, opts) } } -func (d *NetworkElementWatcher) subscribeToPndDevices(pndID string, pnd networkdomain.NetworkDomain, opts *gnmi.SubscribeOptions) { +func (n *NetworkElementWatcher) subscribeToPndNetworkElements(pndID string, pnd networkdomain.NetworkDomain, opts *gnmi.SubscribeOptions) { for _, mne := range pnd.NetworkElements() { subID := uuid.New() stopContext, cancel := context.WithCancel(context.Background()) - d.addToDeviceSubscriptions(subID, &deviceSubscriptionHelper{ + n.addToNetworkElementSubscriptions(subID, &networkelementSubscriptionHelper{ stopSubscribeCtx: stopContext, stopFunc: cancel, }) - go d.callSubscribe(stopContext, pndID, mne, opts) + go n.callSubscribe(stopContext, pndID, mne, opts) } } -func (d *NetworkElementWatcher) callSubscribe(stopContext context.Context, pndID string, mne networkelement.NetworkElement, opts *gnmi.SubscribeOptions) { +func (n *NetworkElementWatcher) callSubscribe(stopContext context.Context, pndID string, mne networkelement.NetworkElement, opts *gnmi.SubscribeOptions) { gNMIOptionsCtx := context.Background() gNMIOptionsCtx = context.WithValue(gNMIOptionsCtx, types.CtxKeyOpts, opts) // SubscriptionInformation contains pnd ID, network element ID and name to be used in the internal subscribe to check // from which network element a response was sent - if err := mne.Transport().ControlPlaneSubscribe(gNMIOptionsCtx, d.handleSubscribeResponse, &transport.SubscriptionInformation{ - PndID: pndID, - DeviceID: mne.ID().String(), - DeviceName: mne.Name(), - StopContext: stopContext, + if err := mne.Transport().ControlPlaneSubscribe(gNMIOptionsCtx, n.handleSubscribeResponse, &transport.SubscriptionInformation{ + PndID: pndID, + NetworkElementID: mne.ID().String(), + NetworkElementName: mne.Name(), + StopContext: stopContext, }); err != nil { log.Error(err) } } -func (d *NetworkElementWatcher) addToDeviceSubscriptions(subID uuid.UUID, devSub *deviceSubscriptionHelper) { +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 - d.deviceSubcriptions[subID] = devSub + n.networkelementSubcriptions[subID] = devSub } -// StopAndRemoveAllDeviceSubscriptions stops and removes all the available running subscriptions. -func (d *NetworkElementWatcher) StopAndRemoveAllDeviceSubscriptions() { - for key := range d.deviceSubcriptions { - d.StopAndRemoveDeviceSubscription(key) +// StopAndRemoveAllNetworkElementSubscriptions stops and removes all the available running subscriptions. +func (n *NetworkElementWatcher) StopAndRemoveAllNetworkElementSubscriptions() { + for key := range n.networkelementSubcriptions { + n.StopAndRemoveNetworkElementSubscription(key) } } -// StopAndRemoveDeviceSubscription passes a subscription uuid to stop the running subscription go routing and removes the entry from the map +// StopAndRemoveNetworkElementSubscription passes a subscription uuid to stop the running subscription go routing and removes the entry from the map // of network element subscriptions. -func (d *NetworkElementWatcher) StopAndRemoveDeviceSubscription(subID uuid.UUID) { - d.deviceSubcriptions[subID].stopFunc() - delete(d.deviceSubcriptions, subID) +func (n *NetworkElementWatcher) StopAndRemoveNetworkElementSubscription(subID uuid.UUID) { + n.networkelementSubcriptions[subID].stopFunc() + delete(n.networkelementSubcriptions, subID) } // handleSubscribeResponse takes the subscribe response and additional information about the network element to distinguish // from which network element a subscribe response was sent including improved error handling. -func (d *NetworkElementWatcher) handleSubscribeResponse(resp *gpb.SubscribeResponse, subscriptionInfo *transport.SubscriptionInformation) { +func (n *NetworkElementWatcher) handleSubscribeResponse(resp *gpb.SubscribeResponse, subscriptionInfo *transport.SubscriptionInformation) { switch resp := resp.Response.(type) { case *gpb.SubscribeResponse_Error: log.Error(&customerrs.SubscribeResponseError{ - PndID: subscriptionInfo.PndID, - DeviceID: subscriptionInfo.DeviceID, - DeviceName: subscriptionInfo.DeviceName, - Err: fmt.Sprint("SubscribeResponse_Error"), + PndID: subscriptionInfo.PndID, + NetworkElementID: subscriptionInfo.NetworkElementID, + NetworkElementName: subscriptionInfo.NetworkElementName, + Err: fmt.Sprint("SubscribeResponse_Error"), }) case *gpb.SubscribeResponse_SyncResponse: if !resp.SyncResponse { log.Error(&customerrs.SubscribeSyncResponseError{ - PndID: subscriptionInfo.PndID, - DeviceID: subscriptionInfo.DeviceID, - DeviceName: subscriptionInfo.DeviceName, + PndID: subscriptionInfo.PndID, + NetworkElementID: subscriptionInfo.NetworkElementID, + NetworkElementName: subscriptionInfo.NetworkElementName, }) } case *gpb.SubscribeResponse_Update: - d.handleSubscribeResponseUpdate(resp, subscriptionInfo) + n.handleSubscribeResponseUpdate(resp, subscriptionInfo) default: log.Infof("Invalid SubscribeResponse, %v", resp) } } -func (d *NetworkElementWatcher) handleSubscribeResponseUpdate(resp *gpb.SubscribeResponse_Update, subscriptionInfo *transport.SubscriptionInformation) { +func (n *NetworkElementWatcher) handleSubscribeResponseUpdate(resp *gpb.SubscribeResponse_Update, subscriptionInfo *transport.SubscriptionInformation) { pndID, err := uuid.Parse(subscriptionInfo.PndID) if err != nil { log.Error(err) } - pnd, err := d.pndStore.Get(store.Query{ID: pndID}) + pnd, err := n.pndStore.Get(store.Query{ID: pndID}) if err != nil { log.Error(err) } - mne, err := pnd.GetNetworkElement(subscriptionInfo.DeviceID) + mne, err := pnd.GetNetworkElement(subscriptionInfo.NetworkElementID) if err != nil { log.Error(err) } diff --git a/controller/store/utils.go b/controller/store/utils.go index 09746a91b72c123be7d8e8db14b426de9c2cf4b7..be2a8c5c610408ea7f1ab72fb9761ee303af9955 100644 --- a/controller/store/utils.go +++ b/controller/store/utils.go @@ -21,7 +21,7 @@ func FromString(id string) (uuid.UUID, error) { log.WithFields(log.Fields{ "identifier": id, }).Debug(err) - return uuid.Nil, &customerrs.InvalidUUIDError{DeviceName: id} + return uuid.Nil, &customerrs.InvalidUUIDError{NetworkElementName: id} } return idAsUUID, nil