[1704] - Reset Response Handler, UT
[ric-plt/e2mgr.git] / E2Manager / handlers / ric_enb_load_information_notification_handler.go
1 package handlers
2
3 import "C"
4 import (
5         "e2mgr/logger"
6         "e2mgr/models"
7         "e2mgr/rNibWriter"
8         "e2mgr/sessions"
9         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
10         "time"
11 )
12
13 type RicEnbLoadInformationNotificationHandler struct{}
14
15 func elapsed(startTime time.Time) float64 {
16         return float64(time.Since(startTime)) / float64(time.Millisecond)
17 }
18
19 func (src RicEnbLoadInformationNotificationHandler) Handle(logger *logger.Logger, e2Sessions sessions.E2Sessions, request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) {
20
21         pdu, err := unpackX2apPdu(logger, MaxAsn1CodecAllocationBufferSize, request.Len, request.Payload, MaxAsn1CodecMessageBufferSize)
22
23         //packedExampleString := "004c07080004001980da0100075bde017c148003d5a8205000017c180003d5a875555403331420000012883a0003547400cd20002801ea16007c1f07c1f107c1f0781e007c80800031a02c000c88199040a00352083669190000d8908020000be0c4001ead4016e007ab50100002f8320067ab5005b8c1ead5070190c00001d637805f220000f56a081400005f020000f56a1d555400ccc508002801ea16007c1f07c1f107c1f0781e007c80800031a02c000c88199040a00352083669190000d8908020000be044001ead4016e007ab50100002f8120067ab5005b8c1ead5070190c00000"
24         //
25         //var packedExampleByteSlice []byte
26         //
27         //_, err := fmt.Sscanf(packedExampleString, "%x", &packedExampleByteSlice)
28         //
29         //pdu, err := unpackX2apPduUPer(logger, MaxAsn1CodecAllocationBufferSize, len(packedExampleByteSlice), packedExampleByteSlice, MaxAsn1CodecMessageBufferSize)
30
31
32         if err != nil {
33                 logger.Errorf("#RicEnbLoadInformationNotificationHandler.Handle - RAN name: %s - Unpack failed. Error: %v", request.RanName, err)
34                 return
35         }
36
37         logger.Debugf("#RicEnbLoadInformationNotificationHandler.Handle - RAN name: %s - Unpacked message successfully", request.RanName)
38
39         ranLoadInformation := &entities.RanLoadInformation{LoadTimestamp: uint64(request.StartTime.UnixNano())}
40
41         err = extractAndBuildRanLoadInformation(pdu, ranLoadInformation)
42
43         if (err != nil) {
44                 logger.Errorf("#RicEnbLoadInformationNotificationHandler.Handle - RAN name: %s - Failed at extractAndBuildRanLoadInformation. Error: %v", request.RanName, err)
45                 return
46         }
47
48         logger.Debugf("#RicEnbLoadInformationNotificationHandler.Handle - RAN name: %s - Successfully done with extracting and building RAN load information. elapsed: %f ms", request.RanName, elapsed(request.StartTime))
49
50         rnibErr := rNibWriter.GetRNibWriter().SaveRanLoadInformation(request.RanName, ranLoadInformation) // TODO: Should inject RnibWriter
51
52         if rnibErr != nil {
53                 logger.Errorf("#RicEnbLoadInformationNotificationHandler.Handle - RAN name: %s - Failed saving RAN load information. Error: %v", request.RanName, rnibErr)
54                 return
55         }
56
57         logger.Debugf("#RicEnbLoadInformationNotificationHandler.Handle - RAN name: %s - Successfully saved RAN load information to RNIB. elapsed: %f ms", request.RanName, elapsed(request.StartTime))
58 }