Merge "RIC-1044: Add array size checks"
[ric-plt/e2mgr.git] / E2Manager / handlers / rmrmsghandlers / enb_load_information_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 //  This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 //  platform project (RICP).
20
21 package rmrmsghandlers
22
23 /*import (
24         "e2mgr/converters"
25         "e2mgr/e2pdus"
26         "e2mgr/logger"
27         "e2mgr/models"
28         "e2mgr/services"
29         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
30         "time"
31 )
32
33 type EnbLoadInformationNotificationHandler struct {
34         logger          *logger.Logger
35         rnibDataService services.RNibDataService
36         //extractor       converters.IEnbLoadInformationExtractor
37 }
38
39 func NewEnbLoadInformationNotificationHandler(logger *logger.Logger, rnibDataService services.RNibDataService, extractor converters.IEnbLoadInformationExtractor) EnbLoadInformationNotificationHandler {
40         return EnbLoadInformationNotificationHandler{
41                 logger:          logger,
42                 rnibDataService: rnibDataService,
43                 extractor: extractor,
44         }
45 }
46
47 func elapsed(startTime time.Time) float64 {
48         return float64(time.Since(startTime)) / float64(time.Millisecond)
49 }
50
51 func (h EnbLoadInformationNotificationHandler) Handle(request *models.NotificationRequest) {
52
53         pdu, err := converters.UnpackX2apPdu(h.logger, e2pdus.MaxAsn1CodecAllocationBufferSize, request.Len, request.Payload, e2pdus.MaxAsn1CodecMessageBufferSize)
54
55         if err != nil {
56                 h.logger.Errorf("#EnbLoadInformationNotificationHandler.Handle - RAN name: %s - Unpack failed. Error: %v", request.RanName, err)
57                 return
58         }
59
60         h.logger.Debugf("#EnbLoadInformationNotificationHandler.Handle - RAN name: %s - Unpacked message successfully", request.RanName)
61
62         ranLoadInformation := &entities.RanLoadInformation{LoadTimestamp: uint64(request.StartTime.UnixNano())}
63
64         err = h.extractor.ExtractAndBuildRanLoadInformation(pdu, ranLoadInformation)
65
66         if err != nil {
67                 h.logger.Errorf("#EnbLoadInformationNotificationHandler.Handle - RAN name: %s - Failed at ExtractAndBuildRanLoadInformation. Error: %v", request.RanName, err)
68                 return
69         }
70
71         h.logger.Debugf("#EnbLoadInformationNotificationHandler.Handle - RAN name: %s - Successfully done with extracting and building RAN load information. elapsed: %f ms", request.RanName, elapsed(request.StartTime))
72
73         rnibErr := h.rnibDataService.SaveRanLoadInformation(request.RanName, ranLoadInformation)
74
75         if rnibErr != nil {
76                 h.logger.Errorf("#EnbLoadInformationNotificationHandler.Handle - RAN name: %s - Failed saving RAN load information. Error: %v", request.RanName, rnibErr)
77                 return
78         }
79
80         h.logger.Infof("#EnbLoadInformationNotificationHandler.Handle - RAN name: %s - Successfully saved RAN load information to RNIB. elapsed: %f ms", request.RanName, elapsed(request.StartTime))
81 }*/