Add random number generation for counter value in https-server 03/13603/2 master
authoraravind.est <aravindhan.a@est.tech>
Fri, 11 Oct 2024 14:11:03 +0000 (15:11 +0100)
committeraravind.est <aravindhan.a@est.tech>
Fri, 11 Oct 2024 14:41:57 +0000 (15:41 +0100)
Min and Max number passed through configuration and random number generated from it to replace it as counter value
RANDOM_CTR_VALUE is the string which gets replaced with the random number.

Issue-ID: NONRTRIC-1036
Change-Id: I5bc5c2fe6deb9b0ea0dac5bbaf5b0809d837b318
Signed-off-by: aravind.est <aravindhan.a@est.tech>
docker-proj/docker-compose-pm-https.yaml
https-server/README.md
https-server/main.go
install/helm/ran/pm-files/pm-template.xml.gz
install/helm/ran/pm-files/pm-template.xml2
install/helm/ran/pm-files/pm.xml.gz
install/helm/ran/templates/app-deployment.yaml

index e50da91..505d714 100644 (file)
@@ -1,5 +1,6 @@
 #  ============LICENSE_START===============================================
 #  Copyright (C) 2023 Nordix Foundation. All rights reserved.
+#  Copyright (C) 2023-2024 OpenInfra Foundation Europe. All rights reserved.
 #  ========================================================================
 #  Licensed under the Apache License, Version 2.0 (the "License");
 #  you may not use this file except in compliance with the License.
@@ -30,6 +31,8 @@ services:
       ALWAYS_RETURN: /ne-files/pm.xml.gz
       GENERATED_FILE_START_TIME: "${START_TIME}"
       GENERATED_FILE_TIMEZONE:  "+0100"
+      RANDOM_MIN_NUMBER: "2"
+      RANDOM_MAX_NUMBER: "20"
     volumes:
     - ./ne-files:/ne-files:rw
     - ./config/https/template-files:/template-files
index e5e6e93..de8982a 100644 (file)
@@ -28,6 +28,10 @@ The following env vars (all optional) may be set to control the behaviour of the
 
 - GENERATED_FILE_TIMEZONE - Time zone to be used for requested files from the url `/generatedfiles/<file-id>`. Example: "+0100"
 
+- RANDOM_MIN_NUMBER - Minimum possible random number to generate random number
+
+- RANDOM_MAX_NUMBER - Maximum possible random number to generate random number
+
 If generated files shall be used, load the file pm-template.xml.gz to the /template-files dir in the container.
 
 Configure the following for desired behaviour
@@ -59,6 +63,7 @@ Configure the following for desired behaviour
 ## License
 
 Copyright (C) 2023 Nordix Foundation. All rights reserved.
+Copyright (C) 2023-2024 OpenInfra Foundation Europe. All rights reserved.
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
index 406caf8..dbdc7b1 100644 (file)
@@ -1,5 +1,6 @@
 //  ============LICENSE_START===============================================
 //  Copyright (C) 2023 Nordix Foundation. All rights reserved.
+//  Copyright (C) 2023-2024 OpenInfra Foundation Europe. All rights reserved.
 //  ========================================================================
 //  Licensed under the Apache License, Version 2.0 (the "License");
 //  you may not use this file except in compliance with the License.
@@ -22,6 +23,7 @@ import (
        "bytes"
        "compress/gzip"
        "io"
+       "math/rand"
        "net/http"
        "os"
        "runtime"
@@ -48,6 +50,8 @@ const file_template = "pm-template.xml.gz"
 var always_return_file = os.Getenv("ALWAYS_RETURN")
 var generated_files_start_time = os.Getenv("GENERATED_FILE_START_TIME")
 var generated_files_timezone = os.Getenv("GENERATED_FILE_TIMEZONE")
+var random_min_value, min_value_error = strconv.Atoi(os.Getenv("RANDOM_MIN_NUMBER"))
+var random_max_value, max_value_error = strconv.Atoi(os.Getenv("RANDOM_MAX_NUMBER"))
 
 var unzipped_template = ""
 
@@ -211,16 +215,21 @@ func generatedfiles(w http.ResponseWriter, req *http.Request) {
                nodename := id[30:]
                nodename = strings.Split(nodename, ".")[0]
 
+               //Generating random number
+               random_value := rand.Intn(random_max_value-random_min_value+1) + random_min_value
+
                template_string := strings.Clone(unzipped_template)
 
                log.Debug("Replacing BEGINTIME with: ", begintime)
                log.Debug("Replacing ENDTIME with: ", endtime)
+               log.Debug("Replacing RANDOM_CTR_VALUE with: ", strconv.Itoa(int(random_value)))
                log.Debug("Replacing CTR_VALUE with: ", strconv.Itoa(int(file_index)))
                log.Debug("Replacing NODE_NAME with: ", nodename)
 
                template_string = strings.Replace(template_string, "BEGINTIME", begintime, -1)
                template_string = strings.Replace(template_string, "ENDTIME", endtime, -1)
 
+               template_string = strings.Replace(template_string, "RANDOM_CTR_VALUE", strconv.Itoa(int(random_value)), -1)
                template_string = strings.Replace(template_string, "CTR_VALUE", strconv.Itoa(int(file_index)), -1)
 
                template_string = strings.Replace(template_string, "NODE_NAME", nodename, -1)
@@ -257,6 +266,13 @@ func main() {
 
        log.Info("Server starting...")
 
+       if min_value_error != nil {
+               random_min_value = 1
+       }
+       if max_value_error != nil {
+               random_max_value = 10
+       }
+
        rtr := mux.NewRouter()
        rtr.HandleFunc("/files/{fileid}", files)
        rtr.HandleFunc("/generatedfiles/{fileid}", generatedfiles)
index 517be24..0e3be9c 100644 (file)
Binary files a/install/helm/ran/pm-files/pm-template.xml.gz and b/install/helm/ran/pm-files/pm-template.xml.gz differ
index 3d95954..c8d77af 100644 (file)
       <measType p="162">pmCounterNumber252Qos</measType>
       <measType p="163">pmCounterNumber254</measType>
       <measType p="164">pmCounterNumber254Qos</measType>
+      <measType p="165">pmRadioThpVolUl</measType>
       <measValue measObjLdn="ManagedElement=NODE_NAME,GNBDUFunction=1,NRCellDU=32">
         <r p="1">CTR_VALUE</r>
         <r p="2">CTR_VALUE</r>
         <r p="162">CTR_VALUE</r>
         <r p="163">CTR_VALUE</r>
         <r p="164">CTR_VALUE</r>
+        <r p="165">RANDOM_CTR_VALUE</r>
       </measValue>
       <measValue measObjLdn="ManagedElement=NODE_NAME,GNBDUFunction=1,NRCellDU=31">
         <r p="1">CTR_VALUE</r>
         <r p="162">CTR_VALUE</r>
         <r p="163">CTR_VALUE</r>
         <r p="164">CTR_VALUE</r>
+        <r p="165">RANDOM_CTR_VALUE</r>
       </measValue>
       <measValue measObjLdn="ManagedElement=NODE_NAME,GNBDUFunction=1,NRCellDU=2">
         <r p="1">CTR_VALUE</r>
         <r p="162">CTR_VALUE</r>
         <r p="163">CTR_VALUE</r>
         <r p="164">CTR_VALUE</r>
+        <r p="165">RANDOM_CTR_VALUE</r>
       </measValue>
       <measValue measObjLdn="ManagedElement=NODE_NAME,GNBDUFunction=1,NRCellDU=1">
         <r p="1">CTR_VALUE</r>
         <r p="162">CTR_VALUE</r>
         <r p="163">CTR_VALUE</r>
         <r p="164">CTR_VALUE</r>
+        <r p="165">RANDOM_CTR_VALUE</r>
       </measValue>
     </measInfo>
     <measInfo measInfoId="PM=1,PmGroup=NRSectorCarrier_GNBDU">
index df90359..ee22685 100644 (file)
Binary files a/install/helm/ran/pm-files/pm.xml.gz and b/install/helm/ran/pm-files/pm.xml.gz differ
index 88e219a..5242a55 100644 (file)
@@ -86,6 +86,12 @@ spec:
         # Shall include +/- sign for the timezone value
         - name: GENERATED_FILE_TIMEZONE
           value: "+0100"
+        # Minimum random number to get generated
+        - name: RANDOM_MIN_NUMBER
+          value: "2"
+        # Maximum random number to get generated
+        - name: RANDOM_MAX_NUMBER
+          value: "20"
         volumeMounts:
         - name: cert-vol
           mountPath: /certs