blob: 9ebdd604f5b275fe1c1d2973a00ca4a32a116088 [file] [log] [blame]
Amichai804065d2019-12-24 14:52:24 +02001//
2// Copyright 2019 AT&T Intellectual Property
3// Copyright 2019 Nokia
4//
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
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
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.
16
17// This source code is part of the near-RT RIC (RAN Intelligent Controller)
18// platform project (RICP).
19
20package managers
21
22import (
23 "e2mgr/clients"
ns019tb3805a92020-04-13 16:57:59 +030024 "e2mgr/e2managererrors"
Amichai804065d2019-12-24 14:52:24 +020025 "e2mgr/logger"
26 "e2mgr/services"
Amichai1f62f4c2019-12-29 17:48:44 +020027 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
Amichai804065d2019-12-24 14:52:24 +020028)
29
30type E2TAssociationManager struct {
idanshal76709202020-06-17 14:53:06 +030031 logger *logger.Logger
32 rnibDataService services.RNibDataService
33 e2tInstanceManager IE2TInstancesManager
34 rmClient clients.IRoutingManagerClient
35 ranConnectStatusChangeManager IRanConnectStatusChangeManager
Amichai804065d2019-12-24 14:52:24 +020036}
37
idanshal76709202020-06-17 14:53:06 +030038func NewE2TAssociationManager(logger *logger.Logger, rnibDataService services.RNibDataService, e2tInstanceManager IE2TInstancesManager, rmClient clients.IRoutingManagerClient, ranConnectStatusChangeManager IRanConnectStatusChangeManager) *E2TAssociationManager {
Amichai804065d2019-12-24 14:52:24 +020039 return &E2TAssociationManager{
idanshal76709202020-06-17 14:53:06 +030040 logger: logger,
41 rnibDataService: rnibDataService,
42 e2tInstanceManager: e2tInstanceManager,
43 rmClient: rmClient,
44 ranConnectStatusChangeManager: ranConnectStatusChangeManager,
Amichai804065d2019-12-24 14:52:24 +020045 }
46}
47
idanshal69f12112020-07-27 14:58:18 +000048func (m *E2TAssociationManager) AssociateRan(e2tAddress string, nodebInfo *entities.NodebInfo) (bool, error) {
Amichai1f62f4c2019-12-29 17:48:44 +020049 ranName := nodebInfo.RanName
Amichai804065d2019-12-24 14:52:24 +020050 m.logger.Infof("#E2TAssociationManager.AssociateRan - Associating RAN %s to E2T Instance address: %s", ranName, e2tAddress)
51
idanshal69f12112020-07-27 14:58:18 +000052 ranStatusChangePublished, err := m.associateRanAndUpdateNodeb(e2tAddress, nodebInfo)
Amichai804065d2019-12-24 14:52:24 +020053 if err != nil {
ns019tb3805a92020-04-13 16:57:59 +030054 m.logger.Errorf("#E2TAssociationManager.AssociateRan - RoutingManager failure: Failed to associate RAN %s to E2T %s. Error: %s", nodebInfo, e2tAddress, err)
idanshal69f12112020-07-27 14:58:18 +000055 return ranStatusChangePublished, err
Amichai804065d2019-12-24 14:52:24 +020056 }
ns019tb3805a92020-04-13 16:57:59 +030057 err = m.e2tInstanceManager.AddRansToInstance(e2tAddress, []string{ranName})
ns019t25ffe732020-04-07 12:53:40 +030058 if err != nil {
ns019tb3805a92020-04-13 16:57:59 +030059 m.logger.Errorf("#E2TAssociationManager.AssociateRan - RAN name: %s - Failed to add RAN to E2T instance %s. Error: %s", ranName, e2tAddress, err)
idanshal69f12112020-07-27 14:58:18 +000060 return ranStatusChangePublished, e2managererrors.NewRnibDbError()
ns019t25ffe732020-04-07 12:53:40 +030061 }
Amichai804065d2019-12-24 14:52:24 +020062 m.logger.Infof("#E2TAssociationManager.AssociateRan - successfully associated RAN %s with E2T %s", ranName, e2tAddress)
idanshal69f12112020-07-27 14:58:18 +000063 return ranStatusChangePublished, nil
Amichai804065d2019-12-24 14:52:24 +020064}
Amichai0c747ac2019-12-25 14:06:40 +020065
idanshal69f12112020-07-27 14:58:18 +000066func (m *E2TAssociationManager) associateRanAndUpdateNodeb(e2tAddress string, nodebInfo *entities.NodebInfo) (bool, error) {
ns019tb3805a92020-04-13 16:57:59 +030067
68 rmErr := m.rmClient.AssociateRanToE2TInstance(e2tAddress, nodebInfo.RanName)
idanshal76709202020-06-17 14:53:06 +030069
ns019tb3805a92020-04-13 16:57:59 +030070 if rmErr != nil {
idanshal69f12112020-07-27 14:58:18 +000071 ranStatusChangePublished, _ := m.ranConnectStatusChangeManager.ChangeStatus(nodebInfo, entities.ConnectionStatus_DISCONNECTED)
72 return ranStatusChangePublished, e2managererrors.NewRoutingManagerError()
ns019tb3805a92020-04-13 16:57:59 +030073 }
idanshal76709202020-06-17 14:53:06 +030074
idanshal69f12112020-07-27 14:58:18 +000075 ranStatusChangePublished, rnibErr := m.ranConnectStatusChangeManager.ChangeStatus(nodebInfo, entities.ConnectionStatus_CONNECTED)
idanshal76709202020-06-17 14:53:06 +030076
77 if rnibErr != nil {
idanshal69f12112020-07-27 14:58:18 +000078 return ranStatusChangePublished, e2managererrors.NewRnibDbError()
ns019tb3805a92020-04-13 16:57:59 +030079 }
idanshal76709202020-06-17 14:53:06 +030080
81 nodebInfo.AssociatedE2TInstanceAddress = e2tAddress
82 rnibErr = m.rnibDataService.UpdateNodebInfo(nodebInfo)
83
84 if rnibErr != nil {
85 m.logger.Errorf("#E2TAssociationManager.associateRanAndUpdateNodeb - RAN name: %s - Failed updating nodeb. Error: %s", nodebInfo.RanName, rnibErr)
idanshal69f12112020-07-27 14:58:18 +000086 return ranStatusChangePublished, e2managererrors.NewRnibDbError()
ns019tb3805a92020-04-13 16:57:59 +030087 }
idanshal76709202020-06-17 14:53:06 +030088
idanshal69f12112020-07-27 14:58:18 +000089 return ranStatusChangePublished, nil
ns019tb3805a92020-04-13 16:57:59 +030090}
91
Amichai0c747ac2019-12-25 14:06:40 +020092func (m *E2TAssociationManager) DissociateRan(e2tAddress string, ranName string) error {
93 m.logger.Infof("#E2TAssociationManager.DissociateRan - Dissociating RAN %s from E2T Instance address: %s", ranName, e2tAddress)
94
95 nodebInfo, rnibErr := m.rnibDataService.GetNodeb(ranName)
96 if rnibErr != nil {
97 m.logger.Errorf("#E2TAssociationManager.DissociateRan - RAN name: %s - Failed fetching RAN from rNib. Error: %s", ranName, rnibErr)
98 return rnibErr
99 }
100
101 nodebInfo.AssociatedE2TInstanceAddress = ""
102 rnibErr = m.rnibDataService.UpdateNodebInfo(nodebInfo)
103 if rnibErr != nil {
104 m.logger.Errorf("#E2TAssociationManager.DissociateRan - RAN name: %s - Failed to update RAN.AssociatedE2TInstanceAddress in rNib. Error: %s", ranName, rnibErr)
105 return rnibErr
106 }
107
108 err := m.e2tInstanceManager.RemoveRanFromInstance(ranName, e2tAddress)
109 if err != nil {
110 m.logger.Errorf("#E2TAssociationManager.DissociateRan - RAN name: %s - Failed to remove RAN from E2T instance %s. Error: %s", ranName, e2tAddress, err)
111 return err
112 }
113
114 err = m.rmClient.DissociateRanE2TInstance(e2tAddress, ranName)
idanshalab8f0392020-06-21 11:05:02 +0300115
Amichai0c747ac2019-12-25 14:06:40 +0200116 if err != nil {
117 m.logger.Errorf("#E2TAssociationManager.DissociateRan - RoutingManager failure: Failed to dissociate RAN %s from E2T %s. Error: %s", ranName, e2tAddress, err)
118 } else {
119 m.logger.Infof("#E2TAssociationManager.DissociateRan - successfully dissociated RAN %s from E2T %s", ranName, e2tAddress)
120 }
121 return nil
122}
Amichaif846c592020-01-08 16:45:07 +0200123
ss412g011bb912020-03-17 18:34:42 +0200124func (m *E2TAssociationManager) RemoveE2tInstance(e2tInstance *entities.E2TInstance) error {
125 m.logger.Infof("#E2TAssociationManager.RemoveE2tInstance - Removing E2T %s and dessociating its associated RANs.", e2tInstance.Address)
Amichaif846c592020-01-08 16:45:07 +0200126
ss412g011bb912020-03-17 18:34:42 +0200127 err := m.rmClient.DeleteE2TInstance(e2tInstance.Address, e2tInstance.AssociatedRanList)
Amichaif846c592020-01-08 16:45:07 +0200128 if err != nil {
ss412g011bb912020-03-17 18:34:42 +0200129 m.logger.Warnf("#E2TAssociationManager.RemoveE2tInstance - RoutingManager failure: Failed to delete E2T %s. Error: %s", e2tInstance.Address, err)
130 // log and continue
Amichaif846c592020-01-08 16:45:07 +0200131 }
132
Amichai380b7a22020-01-14 16:38:06 +0200133 err = m.e2tInstanceManager.RemoveE2TInstance(e2tInstance.Address)
Amichaif846c592020-01-08 16:45:07 +0200134 if err != nil {
Amichai380b7a22020-01-14 16:38:06 +0200135 m.logger.Errorf("#E2TAssociationManager.RemoveE2tInstance - Failed to remove E2T %s. Error: %s", e2tInstance.Address, err)
Amichaif846c592020-01-08 16:45:07 +0200136 return err
137 }
138
Amichai380b7a22020-01-14 16:38:06 +0200139 m.logger.Infof("#E2TAssociationManager.RemoveE2tInstance - E2T %s successfully removed.", e2tInstance.Address)
Amichaif846c592020-01-08 16:45:07 +0200140 return nil
141}