Amichai | 804065d | 2019-12-24 14:52:24 +0200 | [diff] [blame] | 1 | // |
| 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 | |
| 20 | package managers |
| 21 | |
| 22 | import ( |
| 23 | "e2mgr/clients" |
| 24 | "e2mgr/logger" |
| 25 | "e2mgr/services" |
Amichai | 1f62f4c | 2019-12-29 17:48:44 +0200 | [diff] [blame] | 26 | "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" |
Amichai | 804065d | 2019-12-24 14:52:24 +0200 | [diff] [blame] | 27 | ) |
| 28 | |
| 29 | type E2TAssociationManager struct { |
| 30 | logger *logger.Logger |
| 31 | rnibDataService services.RNibDataService |
| 32 | e2tInstanceManager IE2TInstancesManager |
| 33 | rmClient clients.IRoutingManagerClient |
| 34 | } |
| 35 | |
| 36 | func NewE2TAssociationManager(logger *logger.Logger, rnibDataService services.RNibDataService, e2tInstanceManager IE2TInstancesManager, rmClient clients.IRoutingManagerClient) *E2TAssociationManager { |
| 37 | return &E2TAssociationManager{ |
| 38 | logger: logger, |
| 39 | rnibDataService: rnibDataService, |
| 40 | e2tInstanceManager: e2tInstanceManager, |
| 41 | rmClient: rmClient, |
| 42 | } |
| 43 | } |
| 44 | |
Amichai | 1f62f4c | 2019-12-29 17:48:44 +0200 | [diff] [blame] | 45 | func (m *E2TAssociationManager) AssociateRan(e2tAddress string, nodebInfo *entities.NodebInfo) error { |
| 46 | ranName := nodebInfo.RanName |
Amichai | 804065d | 2019-12-24 14:52:24 +0200 | [diff] [blame] | 47 | m.logger.Infof("#E2TAssociationManager.AssociateRan - Associating RAN %s to E2T Instance address: %s", ranName, e2tAddress) |
| 48 | |
| 49 | err := m.rmClient.AssociateRanToE2TInstance(e2tAddress, ranName) |
| 50 | if err != nil { |
| 51 | m.logger.Errorf("#E2TAssociationManager.AssociateRan - RoutingManager failure: Failed to associate RAN %s to E2T %s. Error: %s", ranName, e2tAddress, err) |
| 52 | return err |
| 53 | } |
| 54 | |
Amichai | 804065d | 2019-12-24 14:52:24 +0200 | [diff] [blame] | 55 | nodebInfo.AssociatedE2TInstanceAddress = e2tAddress |
| 56 | nodebInfo.ConnectionAttempts = 0 |
is005q | e3de46b | 2019-12-30 16:35:19 +0200 | [diff] [blame] | 57 | |
Amichai | 1f62f4c | 2019-12-29 17:48:44 +0200 | [diff] [blame] | 58 | rnibErr := m.rnibDataService.UpdateNodebInfo(nodebInfo) |
Amichai | 804065d | 2019-12-24 14:52:24 +0200 | [diff] [blame] | 59 | if rnibErr != nil { |
| 60 | m.logger.Errorf("#E2TAssociationManager.AssociateRan - RAN name: %s - Failed to update RAN.AssociatedE2TInstanceAddress in rNib. Error: %s", ranName, rnibErr) |
| 61 | return rnibErr |
| 62 | } |
| 63 | |
Amichai | 380b7a2 | 2020-01-14 16:38:06 +0200 | [diff] [blame] | 64 | err = m.e2tInstanceManager.AddRansToInstance(e2tAddress, []string{ranName}) |
Amichai | 804065d | 2019-12-24 14:52:24 +0200 | [diff] [blame] | 65 | if err != nil { |
| 66 | m.logger.Errorf("#E2TAssociationManager.AssociateRan - RAN name: %s - Failed to add RAN to E2T instance %s. Error: %s", ranName, e2tAddress, err) |
| 67 | return err |
| 68 | } |
| 69 | m.logger.Infof("#E2TAssociationManager.AssociateRan - successfully associated RAN %s with E2T %s", ranName, e2tAddress) |
| 70 | return nil |
| 71 | } |
Amichai | 0c747ac | 2019-12-25 14:06:40 +0200 | [diff] [blame] | 72 | |
| 73 | func (m *E2TAssociationManager) DissociateRan(e2tAddress string, ranName string) error { |
| 74 | m.logger.Infof("#E2TAssociationManager.DissociateRan - Dissociating RAN %s from E2T Instance address: %s", ranName, e2tAddress) |
| 75 | |
| 76 | nodebInfo, rnibErr := m.rnibDataService.GetNodeb(ranName) |
| 77 | if rnibErr != nil { |
| 78 | m.logger.Errorf("#E2TAssociationManager.DissociateRan - RAN name: %s - Failed fetching RAN from rNib. Error: %s", ranName, rnibErr) |
| 79 | return rnibErr |
| 80 | } |
| 81 | |
| 82 | nodebInfo.AssociatedE2TInstanceAddress = "" |
| 83 | rnibErr = m.rnibDataService.UpdateNodebInfo(nodebInfo) |
| 84 | if rnibErr != nil { |
| 85 | m.logger.Errorf("#E2TAssociationManager.DissociateRan - RAN name: %s - Failed to update RAN.AssociatedE2TInstanceAddress in rNib. Error: %s", ranName, rnibErr) |
| 86 | return rnibErr |
| 87 | } |
| 88 | |
| 89 | err := m.e2tInstanceManager.RemoveRanFromInstance(ranName, e2tAddress) |
| 90 | if err != nil { |
| 91 | m.logger.Errorf("#E2TAssociationManager.DissociateRan - RAN name: %s - Failed to remove RAN from E2T instance %s. Error: %s", ranName, e2tAddress, err) |
| 92 | return err |
| 93 | } |
| 94 | |
| 95 | err = m.rmClient.DissociateRanE2TInstance(e2tAddress, ranName) |
| 96 | if err != nil { |
| 97 | m.logger.Errorf("#E2TAssociationManager.DissociateRan - RoutingManager failure: Failed to dissociate RAN %s from E2T %s. Error: %s", ranName, e2tAddress, err) |
| 98 | } else { |
| 99 | m.logger.Infof("#E2TAssociationManager.DissociateRan - successfully dissociated RAN %s from E2T %s", ranName, e2tAddress) |
| 100 | } |
| 101 | return nil |
| 102 | } |
Amichai | f846c59 | 2020-01-08 16:45:07 +0200 | [diff] [blame] | 103 | |
Amichai | 380b7a2 | 2020-01-14 16:38:06 +0200 | [diff] [blame] | 104 | func (m *E2TAssociationManager) RemoveE2tInstance(e2tInstance *entities.E2TInstance, ransToBeDissociated []string, ranAssociationList map[string][]string) error { |
| 105 | m.logger.Infof("#E2TAssociationManager.RemoveE2tInstance - Removing E2T %s and re-associating its associated RANs.", e2tInstance.Address) |
Amichai | f846c59 | 2020-01-08 16:45:07 +0200 | [diff] [blame] | 106 | |
Amichai | 380b7a2 | 2020-01-14 16:38:06 +0200 | [diff] [blame] | 107 | err := m.rmClient.DeleteE2TInstance(e2tInstance.Address, ransToBeDissociated, ranAssociationList) |
Amichai | f846c59 | 2020-01-08 16:45:07 +0200 | [diff] [blame] | 108 | if err != nil { |
Amichai | 380b7a2 | 2020-01-14 16:38:06 +0200 | [diff] [blame] | 109 | _ = m.setStateToRoutingManagerFailure(e2tInstance) |
| 110 | m.logger.Errorf("#E2TAssociationManager.RemoveE2tInstance - RoutingManager failure: Failed to delete E2T %s. Error: %s", e2tInstance.Address, err) |
Amichai | f846c59 | 2020-01-08 16:45:07 +0200 | [diff] [blame] | 111 | return err |
| 112 | } |
| 113 | |
Amichai | 380b7a2 | 2020-01-14 16:38:06 +0200 | [diff] [blame] | 114 | err = m.e2tInstanceManager.RemoveE2TInstance(e2tInstance.Address) |
Amichai | f846c59 | 2020-01-08 16:45:07 +0200 | [diff] [blame] | 115 | if err != nil { |
Amichai | 380b7a2 | 2020-01-14 16:38:06 +0200 | [diff] [blame] | 116 | m.logger.Errorf("#E2TAssociationManager.RemoveE2tInstance - Failed to remove E2T %s. Error: %s", e2tInstance.Address, err) |
Amichai | f846c59 | 2020-01-08 16:45:07 +0200 | [diff] [blame] | 117 | return err |
| 118 | } |
| 119 | |
Amichai | 380b7a2 | 2020-01-14 16:38:06 +0200 | [diff] [blame] | 120 | for e2tAddress, associatedRans := range ranAssociationList { |
| 121 | err = m.e2tInstanceManager.AddRansToInstance(e2tAddress, associatedRans) |
| 122 | if err != nil { |
| 123 | m.logger.Errorf("#E2TAssociationManager.RemoveE2tInstance - Failed to add RANs %s to E2T %s. Error: %s", associatedRans, e2tAddress, err) |
| 124 | return err |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | m.logger.Infof("#E2TAssociationManager.RemoveE2tInstance - E2T %s successfully removed.", e2tInstance.Address) |
Amichai | f846c59 | 2020-01-08 16:45:07 +0200 | [diff] [blame] | 129 | return nil |
| 130 | } |
| 131 | |
Amichai | 380b7a2 | 2020-01-14 16:38:06 +0200 | [diff] [blame] | 132 | func (m *E2TAssociationManager) setStateToRoutingManagerFailure(e2tInstance *entities.E2TInstance) error { |
| 133 | |
| 134 | err := m.e2tInstanceManager.SetE2tInstanceState(e2tInstance.Address, e2tInstance.State, entities.RoutingManagerFailure) |
Amichai | f846c59 | 2020-01-08 16:45:07 +0200 | [diff] [blame] | 135 | if err != nil { |
| 136 | return err |
| 137 | } |
| 138 | return nil |
| 139 | } |