Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add charging check function in ulcl ti test #2

Merged
merged 4 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/ULCL/smfCfg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ configuration:
nrfUri: http://nrf.free5gc.org:8000 # a valid URI of NRF
nrfCertPem: cert/nrf.pem # NRF Certificate
urrPeriod: 10 # default usage report period in seconds
urrThreshold: 1000 # default usage report threshold in bytes
urrThreshold: 300 # default usage report threshold in bytes
requestedUnit: 1000
ulcl: true
logger: # log output setting
Expand Down
4 changes: 1 addition & 3 deletions config/ULCL/ueRoutingCfg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ ueRoutingInfo: # the list of UE routing information
- A: I-UPF
B: PSA-UPF
specificPath:
- dest: 10.100.50.10/32 # n6gw
path: [I-UPF]
- dest: 10.100.100.10/32 # mec
- dest: 1.0.0.1/32
path: [I-UPF]

pfdDataForApp: # PFDs for an Application
Expand Down
55 changes: 55 additions & 0 deletions test/api-webconsole-charging-record.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

##########################
#
# usage:
# ./api-webconsole-charging-record.sh <action> <login_json_path>
#
# e.g. ./api-webconsole-charging-record.sh [get] json/webconsole-login-data.json
#
##########################

set -e

# get token
echo "Getting token..."

LOGIN_RESPONSE=$(curl -s -X POST http://webui:5000/api/login \
-H "Content-Type: application/json" \
-d @"$2")

TOKEN=$(echo "$LOGIN_RESPONSE" | jq -r '.access_token')

if [ -z "$TOKEN" ] || [ "$TOKEN" = "null" ]; then
echo "Failed to get token!"
echo "Server response: $LOGIN_RESPONSE"
exit 1
fi

if [[ ! "$TOKEN" =~ ^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$ ]]; then
echo "Invalid token format!"
echo "Token: $TOKEN"
exit 1
fi

echo "Token obtained successfully!"

# get charging record
echo "Getting charging record..."

TOKEN=$(echo -n "$TOKEN" | tr -d '\n' | tr -d ' ')

case "$1" in
"get")
CHARGING_RECORD_RESPONSE=$(curl -s -X GET "http://webui:5000/api/charging-record" \
-H "Token: $TOKEN")
;;
*)
echo "error: invalid parameter"
echo "usage: $0 [get]"
exit 1
;;
esac

echo "Charging record obtained successfully!"
echo "$CHARGING_RECORD_RESPONSE"
8 changes: 4 additions & 4 deletions test/api-webconsole-subscribtion-data-action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
##########################
#
# usage:
# ./api-webconsole-subscribtion-data-action.sh <action>
# ./api-webconsole-subscribtion-data-action.sh <action> <json_file>
#
# e.g. ./api-webconsole-subscribtion-data-action.sh [post|delete]
# e.g. ./api-webconsole-subscribtion-data-action.sh [post|delete] json/webconsole-subscription-data-[offline|online].json
#
##########################

Expand Down Expand Up @@ -44,13 +44,13 @@ case "$1" in
SUBSCRIBE_RESPONSE=$(curl -s -X POST "http://webui:5000/api/subscriber/imsi-208930000000001/20893" \
-H "Content-Type: application/json" \
-H "Token: $TOKEN" \
-d @json/webconsole-subscription-data.json)
-d @"$2")
;;
"delete")
SUBSCRIBE_RESPONSE=$(curl -s -X DELETE "http://webui:5000/api/subscriber/imsi-208930000000001/20893" \
-H "Content-Type: application/json" \
-H "Token: $TOKEN" \
-d @json/webconsole-subscription-data.json)
-d @"$2")
;;
*)
echo "error: invalid parameter"
Expand Down
7 changes: 5 additions & 2 deletions test/goTest/packetRusher/packetRusher.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package packetrusher

import (
"os"
"os/exec"
)

Expand Down Expand Up @@ -44,8 +45,10 @@ func (pr *PacketRusher) Deactivate() {
return
}

pr.done <- true
close(pr.done)
if pr.cmd != nil && pr.cmd.Process != nil {
pr.cmd.Process.Signal(os.Interrupt)
pr.cmd.Wait()
}
pr.isActive = false
}

Expand Down
6 changes: 3 additions & 3 deletions test/goTest/pinger/pinger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import (
)

func Pinger(dstIP string, nic string) error {
cmd := exec.Command("ping", "-I", nic, "-c", "3", dstIP)
cmd := exec.Command("ping", "-I", nic, "-c", "3", "-s", "300", dstIP)

output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("ping failed: %v, output: %s", err, output)
}

if !strings.Contains(string(output), " 0% packet loss") {
if strings.Contains(string(output), "0 reveived") {
return fmt.Errorf("no response from %s: %s", dstIP, string(output))
}

return nil
}
44 changes: 43 additions & 1 deletion test/goTest/ulclTrafficInfluence_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package test

import (
"encoding/json"
"os/exec"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -61,7 +63,7 @@ func TestULCLTrafficInfluence(t *testing.T) {
if err != nil {
t.Errorf("Delete ti data failed: expected delete success, but got %v, output: %s", err, output)
}
time.Sleep(500 * time.Millisecond)
time.Sleep(3 * time.Millisecond)

// reset TI
t.Run("Reset TI", func(t *testing.T) {
Expand All @@ -75,6 +77,46 @@ func TestULCLTrafficInfluence(t *testing.T) {
}
})

// check charging record
t.Run("Check Charging Record", func(t *testing.T) {
checkChargingRecord(t)
})

// deactivate PacketRusher
pr.Deactivate()
}

func checkChargingRecord(t *testing.T) {
cmd := exec.Command("bash", "../api-webconsole-charging-record.sh", "get", "../json/webconsole-login-data.json")
output, err := cmd.CombinedOutput()
if err != nil {
t.Errorf("Get charging record failed: %v, output: %s", err, output)
return
}

outputStr := string(output)

lines := strings.Split(outputStr, "\n")
var jsonLine string
for i := len(lines) - 1; i >= 0; i-- {
if strings.TrimSpace(lines[i]) != "" {
jsonLine = lines[i]
break
}
}

var chargingRecords []map[string]interface{}
if err := json.Unmarshal([]byte(jsonLine), &chargingRecords); err != nil {
t.Errorf("Failed to parse charging record JSON: %v\nJSON content: %s", err, jsonLine)
return
}

if len(chargingRecords) == 0 {
t.Error("No charging records found")
return
}

if chargingRecords[0]["TotalVol"].(float64) == 0 {
t.Error("Charging record is empty")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,8 @@
"sst": 1,
"sd": "010203",
"isDefault": true
},
{
"sst": 1,
"sd": "112233",
"isDefault": false
}
],
"singleNssais": []
]
},
"subscribedUeAmbr": {
"downlink": "2 Gbps",
Expand Down Expand Up @@ -81,40 +75,6 @@
}
}
}
},
{
"singleNssai": {
"sst": 1,
"sd": "112233"
},
"dnnConfigurations": {
"internet": {
"sscModes": {
"defaultSscMode": "SSC_MODE_1",
"allowedSscModes": [
"SSC_MODE_2",
"SSC_MODE_3"
]
},
"pduSessionTypes": {
"defaultSessionType": "IPV4",
"allowedSessionTypes": [
"IPV4"
]
},
"sessionAmbr": {
"uplink": "200 Mbps",
"downlink": "100 Mbps"
},
"5gQosProfile": {
"5qi": 8,
"arp": {
"priorityLevel": 8
},
"priorityLevel": 8
}
}
}
}
],
"SmfSelectionSubscriptionData": {
Expand All @@ -125,13 +85,6 @@
"dnn": "internet"
}
]
},
"01112233": {
"dnnInfos": [
{
"dnn": "internet"
}
]
}
}
},
Expand All @@ -152,17 +105,6 @@
"dnn": "internet"
}
}
},
"01112233": {
"snssai": {
"sst": 1,
"sd": "112233"
},
"smPolicyDnnData": {
"internet": {
"dnn": "internet"
}
}
}
}
},
Expand All @@ -173,13 +115,6 @@
"snssai": "01010203",
"dnn": "internet",
"qosRef": 1
},
{
"filter": "1.1.1.1/32",
"precedence": 127,
"snssai": "01112233",
"dnn": "internet",
"qosRef": 2
}
],
"QosFlows": [
Expand All @@ -192,16 +127,6 @@
"mbrDL": "208 Mbps",
"gbrUL": "108 Mbps",
"gbrDL": "108 Mbps"
},
{
"snssai": "01112233",
"dnn": "internet",
"qosRef": 2,
"5qi": 7,
"mbrUL": "407 Mbps",
"mbrDL": "407 Mbps",
"gbrUL": "207 Mbps",
"gbrDL": "207 Mbps"
}
],
"ChargingDatas": [
Expand All @@ -221,23 +146,6 @@
"chargingMethod": "Offline",
"quota": "100000",
"unitCost": "1"
},
{
"snssai": "01112233",
"dnn": "",
"filter": "",
"chargingMethod": "Online",
"quota": "100000",
"unitCost": "1"
},
{
"snssai": "01112233",
"dnn": "internet",
"qosRef": 2,
"filter": "1.1.1.1/32",
"chargingMethod": "Online",
"quota": "5000",
"unitCost": "1"
}
]
}
Loading