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.
22 "e2mgr/e2managererrors"
29 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
30 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
31 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
35 X2_RESET_ACTIVITY_NAME = "X2_RESET"
37 type X2ResetRequestHandler struct {
38 readerProvider func() reader.RNibReader
39 writerProvider func() rNibWriter.RNibWriter
40 rmrService *services.RmrService
41 config *configuration.Configuration
45 func NewX2ResetRequestHandler(rmrService *services.RmrService, config *configuration.Configuration, writerProvider func() rNibWriter.RNibWriter,
46 readerProvider func() reader.RNibReader) *X2ResetRequestHandler {
47 return &X2ResetRequestHandler{
48 readerProvider: readerProvider,
49 writerProvider: writerProvider,
50 rmrService: rmrService,
55 func (handler *X2ResetRequestHandler) Handle(logger *logger.Logger, request models.Request) error {
56 resetRequest := request.(models.ResetRequest)
58 if len(resetRequest.Cause) == 0 {
59 resetRequest.Cause = e2pdus.OmInterventionCause
61 payload, ok:= e2pdus.KnownCausesToX2ResetPDU(resetRequest.Cause)
63 logger.Errorf("#reset_request_handler.Handle - Unknown cause (%s)", resetRequest.Cause)
64 return e2managererrors.NewRequestValidationError()
67 nodeb, err := handler.readerProvider().GetNodeb(resetRequest.RanName)
69 logger.Errorf("#reset_request_handler.Handle - failed to get status of RAN: %s from RNIB. Error: %s", resetRequest.RanName, err.Error())
70 if err.GetCode() == common.RESOURCE_NOT_FOUND {
71 return e2managererrors.NewResourceNotFoundError()
73 return e2managererrors.NewRnibDbError()
76 if nodeb.ConnectionStatus != entities.ConnectionStatus_CONNECTED {
77 logger.Errorf("#reset_request_handler.Handle - RAN: %s in wrong state (%s)", resetRequest.RanName, entities.ConnectionStatus_name[int32(nodeb.ConnectionStatus)])
78 return e2managererrors.NewWrongStateError(X2_RESET_ACTIVITY_NAME,entities.ConnectionStatus_name[int32(nodeb.ConnectionStatus)])
81 response := models.NotificationResponse{MgsType: rmrCgo.RIC_X2_RESET, RanName: resetRequest.RanName, Payload: payload}
82 if err:= handler.rmrService.SendRmrMessage(&response); err != nil {
83 logger.Errorf("#reset_request_handler.Handle - failed to send reset message to RMR: %s", err)
84 return e2managererrors.NewRmrError()
87 logger.Infof("#reset_request_handler.Handle - sent x2 reset to RAN: %s with cause: %s", resetRequest.RanName, resetRequest.Cause)