2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
17 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 // platform project (RICP).
26 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
29 type E2TAssociationManager struct {
31 rnibDataService services.RNibDataService
32 e2tInstanceManager IE2TInstancesManager
33 rmClient clients.IRoutingManagerClient
36 func NewE2TAssociationManager(logger *logger.Logger, rnibDataService services.RNibDataService, e2tInstanceManager IE2TInstancesManager, rmClient clients.IRoutingManagerClient) *E2TAssociationManager {
37 return &E2TAssociationManager{
39 rnibDataService: rnibDataService,
40 e2tInstanceManager: e2tInstanceManager,
45 func (m *E2TAssociationManager) AssociateRan(e2tAddress string, nodebInfo *entities.NodebInfo) error {
46 ranName := nodebInfo.RanName
47 m.logger.Infof("#E2TAssociationManager.AssociateRan - Associating RAN %s to E2T Instance address: %s", ranName, e2tAddress)
49 err := m.rmClient.AssociateRanToE2TInstance(e2tAddress, ranName)
51 m.logger.Errorf("#E2TAssociationManager.AssociateRan - RoutingManager failure: Failed to associate RAN %s to E2T %s. Error: %s", ranName, e2tAddress, err)
55 nodebInfo.AssociatedE2TInstanceAddress = e2tAddress
56 nodebInfo.ConnectionAttempts = 0
57 rnibErr := m.rnibDataService.UpdateNodebInfo(nodebInfo)
59 m.logger.Errorf("#E2TAssociationManager.AssociateRan - RAN name: %s - Failed to update RAN.AssociatedE2TInstanceAddress in rNib. Error: %s", ranName, rnibErr)
63 err = m.e2tInstanceManager.AddRanToInstance(ranName, e2tAddress)
65 m.logger.Errorf("#E2TAssociationManager.AssociateRan - RAN name: %s - Failed to add RAN to E2T instance %s. Error: %s", ranName, e2tAddress, err)
68 m.logger.Infof("#E2TAssociationManager.AssociateRan - successfully associated RAN %s with E2T %s", ranName, e2tAddress)
72 func (m *E2TAssociationManager) DissociateRan(e2tAddress string, ranName string) error {
73 m.logger.Infof("#E2TAssociationManager.DissociateRan - Dissociating RAN %s from E2T Instance address: %s", ranName, e2tAddress)
75 nodebInfo, rnibErr := m.rnibDataService.GetNodeb(ranName)
77 m.logger.Errorf("#E2TAssociationManager.DissociateRan - RAN name: %s - Failed fetching RAN from rNib. Error: %s", ranName, rnibErr)
81 nodebInfo.AssociatedE2TInstanceAddress = ""
82 rnibErr = m.rnibDataService.UpdateNodebInfo(nodebInfo)
84 m.logger.Errorf("#E2TAssociationManager.DissociateRan - RAN name: %s - Failed to update RAN.AssociatedE2TInstanceAddress in rNib. Error: %s", ranName, rnibErr)
88 err := m.e2tInstanceManager.RemoveRanFromInstance(ranName, e2tAddress)
90 m.logger.Errorf("#E2TAssociationManager.DissociateRan - RAN name: %s - Failed to remove RAN from E2T instance %s. Error: %s", ranName, e2tAddress, err)
94 err = m.rmClient.DissociateRanE2TInstance(e2tAddress, ranName)
96 m.logger.Errorf("#E2TAssociationManager.DissociateRan - RoutingManager failure: Failed to dissociate RAN %s from E2T %s. Error: %s", ranName, e2tAddress, err)
98 m.logger.Infof("#E2TAssociationManager.DissociateRan - successfully dissociated RAN %s from E2T %s", ranName, e2tAddress)