blob: 78ae6d767af6775bc64c8242bd14b549cb26c471 [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"
24 "e2mgr/logger"
25 "e2mgr/services"
26)
27
28type E2TAssociationManager struct {
29 logger *logger.Logger
30 rnibDataService services.RNibDataService
31 e2tInstanceManager IE2TInstancesManager
32 rmClient clients.IRoutingManagerClient
33}
34
35func NewE2TAssociationManager(logger *logger.Logger, rnibDataService services.RNibDataService, e2tInstanceManager IE2TInstancesManager, rmClient clients.IRoutingManagerClient) *E2TAssociationManager {
36 return &E2TAssociationManager{
37 logger: logger,
38 rnibDataService: rnibDataService,
39 e2tInstanceManager: e2tInstanceManager,
40 rmClient: rmClient,
41 }
42}
43
44func (m *E2TAssociationManager) AssociateRan(e2tAddress string, ranName string) error {
45 m.logger.Infof("#E2TAssociationManager.AssociateRan - Associating RAN %s to E2T Instance address: %s", ranName, e2tAddress)
46
47 err := m.rmClient.AssociateRanToE2TInstance(e2tAddress, ranName)
48 if err != nil {
49 m.logger.Errorf("#E2TAssociationManager.AssociateRan - RoutingManager failure: Failed to associate RAN %s to E2T %s. Error: %s", ranName, e2tAddress, err)
50 return err
51 }
52
53 nodebInfo, rnibErr := m.rnibDataService.GetNodeb(ranName)
54
55 if rnibErr != nil {
56 m.logger.Errorf("#E2TAssociationManager.AssociateRan - RAN name: %s - Failed fetching RAN from rNib. Error: %s", ranName, rnibErr)
57 return rnibErr
58 }
59
60 nodebInfo.AssociatedE2TInstanceAddress = e2tAddress
61 nodebInfo.ConnectionAttempts = 0
62 rnibErr = m.rnibDataService.UpdateNodebInfo(nodebInfo)
63 if rnibErr != nil {
64 m.logger.Errorf("#E2TAssociationManager.AssociateRan - RAN name: %s - Failed to update RAN.AssociatedE2TInstanceAddress in rNib. Error: %s", ranName, rnibErr)
65 return rnibErr
66 }
67
68 err = m.e2tInstanceManager.AddRanToInstance(ranName, e2tAddress)
69 if err != nil {
70 m.logger.Errorf("#E2TAssociationManager.AssociateRan - RAN name: %s - Failed to add RAN to E2T instance %s. Error: %s", ranName, e2tAddress, err)
71 return err
72 }
73 m.logger.Infof("#E2TAssociationManager.AssociateRan - successfully associated RAN %s with E2T %s", ranName, e2tAddress)
74 return nil
75}
Amichai0c747ac2019-12-25 14:06:40 +020076
77func (m *E2TAssociationManager) DissociateRan(e2tAddress string, ranName string) error {
78 m.logger.Infof("#E2TAssociationManager.DissociateRan - Dissociating RAN %s from E2T Instance address: %s", ranName, e2tAddress)
79
80 nodebInfo, rnibErr := m.rnibDataService.GetNodeb(ranName)
81 if rnibErr != nil {
82 m.logger.Errorf("#E2TAssociationManager.DissociateRan - RAN name: %s - Failed fetching RAN from rNib. Error: %s", ranName, rnibErr)
83 return rnibErr
84 }
85
86 nodebInfo.AssociatedE2TInstanceAddress = ""
87 rnibErr = m.rnibDataService.UpdateNodebInfo(nodebInfo)
88 if rnibErr != nil {
89 m.logger.Errorf("#E2TAssociationManager.DissociateRan - RAN name: %s - Failed to update RAN.AssociatedE2TInstanceAddress in rNib. Error: %s", ranName, rnibErr)
90 return rnibErr
91 }
92
93 err := m.e2tInstanceManager.RemoveRanFromInstance(ranName, e2tAddress)
94 if err != nil {
95 m.logger.Errorf("#E2TAssociationManager.DissociateRan - RAN name: %s - Failed to remove RAN from E2T instance %s. Error: %s", ranName, e2tAddress, err)
96 return err
97 }
98
99 err = m.rmClient.DissociateRanE2TInstance(e2tAddress, ranName)
100 if err != nil {
101 m.logger.Errorf("#E2TAssociationManager.DissociateRan - RoutingManager failure: Failed to dissociate RAN %s from E2T %s. Error: %s", ranName, e2tAddress, err)
102 } else {
103 m.logger.Infof("#E2TAssociationManager.DissociateRan - successfully dissociated RAN %s from E2T %s", ranName, e2tAddress)
104 }
105 return nil
106}