[RICPLT-2146] Remove E2Sessions......
[ric-plt/e2mgr.git] / E2Manager / handlers / rmrmsghandlers / enb_load_information_notification_handler.go
1 package rmrmsghandlers
2
3 import "C"
4 import (
5         "e2mgr/converters"
6         "e2mgr/e2pdus"
7         "e2mgr/logger"
8         "e2mgr/models"
9         "e2mgr/rNibWriter"
10         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
11         "time"
12 )
13
14 type EnbLoadInformationNotificationHandler struct {
15         rnibWriterProvider func() rNibWriter.RNibWriter
16 }
17
18 func NewEnbLoadInformationNotificationHandler(rnibWriterProvider func() rNibWriter.RNibWriter) EnbLoadInformationNotificationHandler {
19         return EnbLoadInformationNotificationHandler{
20                 rnibWriterProvider: rnibWriterProvider,
21         }
22 }
23
24 func elapsed(startTime time.Time) float64 {
25         return float64(time.Since(startTime)) / float64(time.Millisecond)
26 }
27
28 func (src EnbLoadInformationNotificationHandler) Handle(logger *logger.Logger, request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) {
29
30         pdu, err := converters.UnpackX2apPdu(logger, e2pdus.MaxAsn1CodecAllocationBufferSize, request.Len, request.Payload, e2pdus.MaxAsn1CodecMessageBufferSize)
31
32         if err != nil {
33                 logger.Errorf("#EnbLoadInformationNotificationHandler.Handle - RAN name: %s - Unpack failed. Error: %v", request.RanName, err)
34                 return
35         }
36
37         logger.Debugf("#EnbLoadInformationNotificationHandler.Handle - RAN name: %s - Unpacked message successfully", request.RanName)
38
39         ranLoadInformation := &entities.RanLoadInformation{LoadTimestamp: uint64(request.StartTime.UnixNano())}
40
41         err = converters.ExtractAndBuildRanLoadInformation(pdu, ranLoadInformation)
42
43         if (err != nil) {
44                 logger.Errorf("#EnbLoadInformationNotificationHandler.Handle - RAN name: %s - Failed at ExtractAndBuildRanLoadInformation. Error: %v", request.RanName, err)
45                 return
46         }
47
48         logger.Debugf("#EnbLoadInformationNotificationHandler.Handle - RAN name: %s - Successfully done with extracting and building RAN load information. elapsed: %f ms", request.RanName, elapsed(request.StartTime))
49
50         rnibErr := src.rnibWriterProvider().SaveRanLoadInformation(request.RanName, ranLoadInformation)
51
52         if rnibErr != nil {
53                 logger.Errorf("#EnbLoadInformationNotificationHandler.Handle - RAN name: %s - Failed saving RAN load information. Error: %v", request.RanName, rnibErr)
54                 return
55         }
56
57         logger.Infof("#EnbLoadInformationNotificationHandler.Handle - RAN name: %s - Successfully saved RAN load information to RNIB. elapsed: %f ms", request.RanName, elapsed(request.StartTime))
58 }