6c1146722819ac482be8f0e7002581765075147b
[ric-plt/e2mgr.git] / E2Manager / handlers / rmrmsghandlers / x2Setup_failure_response_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
18 package rmrmsghandlers
19
20 import (
21         "e2mgr/converters"
22         "e2mgr/e2pdus"
23         "e2mgr/logger"
24         "e2mgr/models"
25         "e2mgr/rNibWriter"
26         "e2mgr/sessions"
27         "fmt"
28         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
29 )
30
31 type X2SetupFailureResponseNotificationHandler struct{}
32
33 func (src X2SetupFailureResponseNotificationHandler) Handle(logger *logger.Logger, e2Sessions sessions.E2Sessions,
34         request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) {
35
36         e2session, ok := e2Sessions[request.TransactionId]
37
38         failureResponse, err := converters.UnpackX2SetupFailureResponseAndExtract(logger, e2pdus.MaxAsn1CodecAllocationBufferSize, request.Len, request.Payload, e2pdus.MaxAsn1CodecMessageBufferSize)
39         if err != nil {
40                 logger.Errorf("#x2Setup_failure_response_notification_handler.Handle - unpack failed. Error: %v", err)
41         }
42
43         printHandlingSetupResponseElapsedTimeInMs(logger, fmt.Sprintf("#x2Setup_failure_response_notification_handler.handle - transactionId %s: Summary: Elapsed time for receiving and handling setup response from E2 terminator", request.TransactionId), request.StartTime)
44         if ok {
45                 if failureResponse != nil {
46                         nb := &entities.NodebInfo{}
47                         nbIdentity := &entities.NbIdentity{}
48
49                         nb.RanName = e2session.Request.RanName
50                         nb.ConnectionStatus = entities.ConnectionStatus_CONNECTED_SETUP_FAILED
51                         nb.E2ApplicationProtocol = entities.E2ApplicationProtocol_X2_SETUP_REQUEST
52                         nb.Ip = e2session.Request.RanIp
53                         nb.Port = uint32(e2session.Request.RanPort)
54                         nb.SetupFailure = failureResponse
55                         nb.FailureType = entities.Failure_X2_SETUP_FAILURE
56                         nbIdentity.InventoryName = e2session.Request.RanName
57
58                         //insert/update database
59                         if rNibErr := rNibWriter.GetRNibWriter().SaveNodeb(nbIdentity, nb); rNibErr != nil {
60                                 logger.Errorf("#x2Setup_failure_response_notification_handler.Handle - transactionId %s: rNibWriter failed to save failure response data. Error: %s", request.TransactionId, rNibErr.Error())
61                         } else {
62                                 logger.Infof("#x2Setup_failure_response_notification_handler.Handle - transactionId %s: saved to rNib", request.TransactionId)
63                                 if logger.DebugEnabled() {
64                                         logger.Debugf("x2Setup_failure_response_notification_handler.Handle - transactionId %s: saved to rNib , value:[%s]", request.TransactionId, fmt.Sprintf("%s %s", nb.ConnectionStatus, failureResponse))
65                                 }
66                         }
67                 }
68                 printHandlingSetupResponseElapsedTimeInMs(logger, fmt.Sprintf("#x2Setup_failure_response_notification_handler.handle - transactionId %s: Summary: Total roundtrip elapsed time", request.TransactionId), e2session.SessionStart)
69                 delete(e2Sessions, request.TransactionId) // Avoid pinning memory (help GC)
70         }
71 }