From: aravind.est Date: Fri, 11 Oct 2024 14:11:03 +0000 (+0100) Subject: Add random number generation for counter value in https-server X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F03%2F13603%2F2;p=nonrtric%2Fplt%2Franpm.git Add random number generation for counter value in https-server 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 --- diff --git a/docker-proj/docker-compose-pm-https.yaml b/docker-proj/docker-compose-pm-https.yaml index e50da91..505d714 100644 --- a/docker-proj/docker-compose-pm-https.yaml +++ b/docker-proj/docker-compose-pm-https.yaml @@ -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 diff --git a/https-server/README.md b/https-server/README.md index e5e6e93..de8982a 100644 --- a/https-server/README.md +++ b/https-server/README.md @@ -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/`. 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 diff --git a/https-server/main.go b/https-server/main.go index 406caf8..dbdc7b1 100644 --- a/https-server/main.go +++ b/https-server/main.go @@ -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) diff --git a/install/helm/ran/pm-files/pm-template.xml.gz b/install/helm/ran/pm-files/pm-template.xml.gz index 517be24..0e3be9c 100644 Binary files a/install/helm/ran/pm-files/pm-template.xml.gz and b/install/helm/ran/pm-files/pm-template.xml.gz differ diff --git a/install/helm/ran/pm-files/pm-template.xml2 b/install/helm/ran/pm-files/pm-template.xml2 index 3d95954..c8d77af 100644 --- a/install/helm/ran/pm-files/pm-template.xml2 +++ b/install/helm/ran/pm-files/pm-template.xml2 @@ -656,6 +656,7 @@ pmCounterNumber252Qos pmCounterNumber254 pmCounterNumber254Qos + pmRadioThpVolUl CTR_VALUE CTR_VALUE @@ -821,6 +822,7 @@ CTR_VALUE CTR_VALUE CTR_VALUE + RANDOM_CTR_VALUE CTR_VALUE @@ -987,6 +989,7 @@ CTR_VALUE CTR_VALUE CTR_VALUE + RANDOM_CTR_VALUE CTR_VALUE @@ -1153,6 +1156,7 @@ CTR_VALUE CTR_VALUE CTR_VALUE + RANDOM_CTR_VALUE CTR_VALUE @@ -1319,6 +1323,7 @@ CTR_VALUE CTR_VALUE CTR_VALUE + RANDOM_CTR_VALUE diff --git a/install/helm/ran/pm-files/pm.xml.gz b/install/helm/ran/pm-files/pm.xml.gz index df90359..ee22685 100644 Binary files a/install/helm/ran/pm-files/pm.xml.gz and b/install/helm/ran/pm-files/pm.xml.gz differ diff --git a/install/helm/ran/templates/app-deployment.yaml b/install/helm/ran/templates/app-deployment.yaml index 88e219a..5242a55 100644 --- a/install/helm/ran/templates/app-deployment.yaml +++ b/install/helm/ran/templates/app-deployment.yaml @@ -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