[RICPLT-1853] Couple of adjustments.........
[ric-plt/e2mgr.git] / E2Manager / handlers / x2apSetup_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 handlers
19
20 import (
21         "e2mgr/models"
22         "e2mgr/rNibWriter"
23         "fmt"
24         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
25
26         "e2mgr/logger"
27         "e2mgr/sessions"
28 )
29
30 type X2SetupResponseNotificationHandler struct{}
31
32 func (src X2SetupResponseNotificationHandler) Handle(logger *logger.Logger, e2Sessions sessions.E2Sessions,
33         request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) {
34
35         e2session, ok := e2Sessions[request.TransactionId]
36
37         enbId, enb, err := unpackX2SetupResponseAndExtract(logger, MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, request.Len, request.Payload, MaxAsn1CodecMessageBufferSize /*message buffer*/)
38         if err != nil {
39                 logger.Errorf("#x2apSetup_response_notification_handler.Handle - unpack failed. Error: %v", err)
40         }
41
42         printHandlingSetupResponseElapsedTimeInMs(logger, fmt.Sprintf("#x2apSetup_response_notification_handler.handle - transactionId %s: Summary: Elapsed time for receiving and handling setup response from E2 terminator", request.TransactionId), request.StartTime)
43         //TODO if !ok exit
44         if ok {
45                 if enb != nil {
46                         nb := &entities.NodebInfo{}
47                         nbIdentity := &entities.NbIdentity{}
48
49                         nbIdentity.InventoryName = e2session.Request.RanName
50                         nbIdentity.GlobalNbId = enbId
51                         nb.GlobalNbId = nbIdentity.GlobalNbId
52                         nb.RanName = e2session.Request.RanName
53                         nb.ConnectionStatus = entities.ConnectionStatus_CONNECTED
54                         nb.E2ApplicationProtocol = entities.E2ApplicationProtocol_X2_SETUP_REQUEST
55                         nb.Ip = e2session.Request.RanIp
56                         nb.Port = uint32(e2session.Request.RanPort)
57                         nb.NodeType = entities.Node_ENB
58                         nb.Configuration = &entities.NodebInfo_Enb{Enb: enb}
59
60                         //insert/update database
61                         if rNibErr := rNibWriter.GetRNibWriter().SaveNodeb(nbIdentity, nb); rNibErr != nil {
62                                 logger.Errorf("#x2apSetup_response_notification_handler.Handle - transactionId %s: rNibWriter failed to save ENB data for enbId: %v. Error: %s", request.TransactionId, enbId, rNibErr.Error())
63                         } else {
64                                 logger.Infof("#x2apSetup_response_notification_handler.Handle - transactionId %s: saved to rNib enbId: %v", request.TransactionId, enbId)
65                                 if logger.DebugEnabled() {
66                                         logger.Debugf("#x2apSetup_response_notification_handler.Handle - transactionId %s: saved to rNib enbId: %v, v:[%s]", request.TransactionId, enbId, fmt.Sprintf("%s %s %s %s", nb.ConnectionStatus, enb.EnbType, enb.ServedCells, enb.GuGroupIds))
67                                 }
68                         }
69                 }
70                 printHandlingSetupResponseElapsedTimeInMs(logger, fmt.Sprintf("#x2apSetup_response_notification_handler.handle - transactionId %s: Summary: Total roundtrip elapsed time", request.TransactionId), e2session.SessionStart)
71                 delete(e2Sessions, request.TransactionId) // Avoid pinning memory (help GC)
72         }
73
74
75
76 }