85255eb4a58c555f1bd05019178ddb83ee91111e
[ric-plt/e2mgr.git] / E2Manager / handlers / rmrmsghandlers / x2_reset_request_notification_handler.go
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
21 package rmrmsghandlers
22
23 // #cgo CFLAGS: -I../../3rdparty/asn1codec/inc/  -I../../3rdparty/asn1codec/e2ap_engine/
24 // #cgo LDFLAGS: -L ../../3rdparty/asn1codec/lib/ -L../../3rdparty/asn1codec/e2ap_engine/ -le2ap_codec -lasncodec
25 // #include <asn1codec_utils.h>
26 // #include <x2reset_response_wrapper.h>
27 import "C"
28 import (
29         "e2mgr/e2pdus"
30         "e2mgr/enums"
31         "e2mgr/logger"
32         "e2mgr/managers"
33         "e2mgr/models"
34         "e2mgr/rmrCgo"
35         "e2mgr/services"
36         "e2mgr/services/rmrsender"
37         "e2mgr/utils"
38         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
39 )
40
41 type X2ResetRequestNotificationHandler struct {
42         logger                 *logger.Logger
43         rnibDataService        services.RNibDataService
44         ranStatusChangeManager managers.IRanStatusChangeManager
45         rmrSender              *rmrsender.RmrSender
46 }
47
48 func NewX2ResetRequestNotificationHandler(logger *logger.Logger, rnibDataService services.RNibDataService, ranStatusChangeManager managers.IRanStatusChangeManager, rmrSender *rmrsender.RmrSender) X2ResetRequestNotificationHandler {
49         return X2ResetRequestNotificationHandler{
50                 logger:                 logger,
51                 rnibDataService:        rnibDataService,
52                 ranStatusChangeManager: ranStatusChangeManager,
53                 rmrSender:              rmrSender,
54         }
55 }
56
57 func (h X2ResetRequestNotificationHandler) Handle(request *models.NotificationRequest) {
58
59         h.logger.Infof("#X2ResetRequestNotificationHandler.Handle - Ran name: %s", request.RanName)
60
61         nb, rNibErr := h.rnibDataService.GetNodeb(request.RanName)
62         if rNibErr != nil {
63                 h.logger.Errorf("#X2ResetRequestNotificationHandler.Handle - failed to retrieve nodeB entity. RanName: %s. Error: %s", request.RanName, rNibErr.Error())
64                 h.logger.Infof("#X2ResetRequestNotificationHandler.Handle - Summary: elapsed time for receiving and handling reset request message from E2 terminator: %f ms", utils.ElapsedTime(request.StartTime))
65                 return
66         }
67
68         h.logger.Debugf("#X2ResetRequestNotificationHandler.Handle - nodeB entity retrieved. RanName %s, ConnectionStatus %s", nb.RanName, nb.ConnectionStatus)
69
70         if nb.ConnectionStatus == entities.ConnectionStatus_SHUTTING_DOWN {
71                 h.logger.Warnf("#X2ResetRequestNotificationHandler.Handle - nodeB entity in incorrect state. RanName %s, ConnectionStatus %s", nb.RanName, nb.ConnectionStatus)
72                 h.logger.Infof("#X2ResetRequestNotificationHandler.Handle - Summary: elapsed time for receiving and handling reset request message from E2 terminator: %f ms", utils.ElapsedTime(request.StartTime))
73                 return
74         }
75
76         if nb.ConnectionStatus != entities.ConnectionStatus_CONNECTED {
77                 h.logger.Errorf("#X2ResetRequestNotificationHandler.Handle - nodeB entity in incorrect state. RanName %s, ConnectionStatus %s", nb.RanName, nb.ConnectionStatus)
78                 h.logger.Infof("#X2ResetRequestNotificationHandler.Handle - Summary: elapsed time for receiving and handling reset request message from E2 terminator: %f ms", utils.ElapsedTime(request.StartTime))
79                 return
80         }
81
82         msg := models.NewRmrMessage(rmrCgo.RIC_X2_RESET_RESP, request.RanName, e2pdus.PackedX2ResetResponse, request.TransactionId, request.GetMsgSrc())
83
84         _ = h.rmrSender.Send(msg)
85         h.logger.Infof("#X2ResetRequestNotificationHandler.Handle - Summary: elapsed time for receiving and handling reset request message from E2 terminator: %f ms", utils.ElapsedTime(request.StartTime))
86         _ = h.ranStatusChangeManager.Execute(rmrCgo.RAN_RESTARTED, enums.RAN_TO_RIC, nb)
87 }