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 package rmrmsghandlers
27 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
30 type SetupResponseNotificationHandler struct {
32 rnibDataService services.RNibDataService
33 setupResponseManager managers.ISetupResponseManager
34 ranStatusChangeManager managers.IRanStatusChangeManager
38 var msgTypeToMsgName = map[int]string{
39 rmrCgo.RIC_X2_SETUP_RESP: "X2 Setup Response",
40 rmrCgo.RIC_X2_SETUP_FAILURE: "X2 Setup Failure Response",
41 rmrCgo.RIC_ENDC_X2_SETUP_RESP: "ENDC Setup Response",
42 rmrCgo.RIC_ENDC_X2_SETUP_FAILURE: "ENDC Setup Failure Response",
45 func NewSetupResponseNotificationHandler(logger *logger.Logger, rnibDataService services.RNibDataService, setupResponseManager managers.ISetupResponseManager, ranStatusChangeManager managers.IRanStatusChangeManager, msgType int) SetupResponseNotificationHandler {
46 return SetupResponseNotificationHandler{
48 rnibDataService: rnibDataService,
49 setupResponseManager: setupResponseManager,
50 ranStatusChangeManager: ranStatusChangeManager,
55 func (h SetupResponseNotificationHandler) Handle(request *models.NotificationRequest) {
56 msgName := msgTypeToMsgName[h.msgType]
57 h.logger.Infof("#SetupResponseNotificationHandler - RAN name: %s - Received %s notification", request.RanName, msgName)
59 inventoryName := request.RanName
61 nodebInfo, rnibErr := h.rnibDataService.GetNodeb(inventoryName)
64 h.logger.Errorf("#SetupResponseNotificationHandler - RAN name: %s - Error fetching RAN from rNib: %v", request.RanName, rnibErr)
68 if !isConnectionStatusValid(nodebInfo.ConnectionStatus) {
69 h.logger.Errorf("#SetupResponseNotificationHandler - RAN name: %s - Invalid RAN connection status: %s", request.RanName, nodebInfo.ConnectionStatus)
73 nodebInfo.ConnectionAttempts = 0
74 nbIdentity := &entities.NbIdentity{InventoryName: inventoryName}
75 err := h.setupResponseManager.PopulateNodebByPdu(h.logger, nbIdentity, nodebInfo, request.Payload)
81 rnibErr = h.rnibDataService.SaveNodeb(nbIdentity, nodebInfo)
84 h.logger.Errorf("#SetupResponseNotificationHandler - RAN name: %s - Error saving RAN to rNib: %v", request.RanName, rnibErr)
88 h.logger.Infof("#SetupResponseNotificationHandler - RAN name: %s - Successfully saved RAN to rNib", request.RanName)
89 h.logger.Infof("#SetupResponseNotificationHandler - Summary: elapsed time for receiving and handling setup response message from E2 terminator: %f ms", utils.ElapsedTime(request.StartTime))
91 if !isSuccessSetupResponseMessage(h.msgType) {
95 _ = h.ranStatusChangeManager.Execute(rmrCgo.RAN_CONNECTED, enums.RIC_TO_RAN, nodebInfo)
98 func isConnectionStatusValid(connectionStatus entities.ConnectionStatus) bool {
99 return connectionStatus == entities.ConnectionStatus_CONNECTING || connectionStatus == entities.ConnectionStatus_CONNECTED
102 func isSuccessSetupResponseMessage(msgType int) bool {
103 return msgType == rmrCgo.RIC_X2_SETUP_RESP || msgType == rmrCgo.RIC_ENDC_X2_SETUP_RESP