test: encode test program

This commit is contained in:
2024-03-06 19:10:54 +08:00
parent 4fda8a86e3
commit bf3b97c788
4 changed files with 379 additions and 0 deletions

70
tools/encode/encyaml.go Normal file
View File

@@ -0,0 +1,70 @@
package main
import (
"fmt"
"gopkg.in/yaml.v3"
)
func printYAML(node *yaml.Node) {
switch node.Kind {
case yaml.MappingNode:
fmt.Print(node.HeadComment)
fmt.Print("{")
for i := 0; i < len(node.Content)/2; i++ {
key := node.Content[i*2]
value := node.Content[i*2+1]
printYAML(key)
fmt.Print(": ")
printYAML(value)
if i < len(node.Content)/2-1 {
fmt.Print(", ")
}
}
fmt.Print("}")
fmt.Print(node.FootComment)
case yaml.SequenceNode:
fmt.Print("[")
for i, n := range node.Content {
printYAML(n)
if i < len(node.Content)-1 {
fmt.Print(", ")
}
}
fmt.Print("]")
default:
fmt.Print(node.Value)
}
}
func main() {
data := `
test:
smfSystem:
display: "SMF System"
list:
- name: "sbiIpAddr"
type: "string"
value: "172.16.5.150"
access: "read-write"
filter: ''
display: "SBI IP"
comment: ""
amf:
smfSystem:
display: "SMF System"
list:
- name: "sbiIpAddr"
type: "string"
value: "172.16.5.150"
access: "read-write"
filter: ''
display: "SBI IP"
comment: ""
`
var node yaml.Node
if err := yaml.Unmarshal([]byte(data), &node); err != nil {
panic(err)
}
printYAML(&node)
}

View File

309
tools/encode/test.yaml Normal file
View File

@@ -0,0 +1,309 @@
smf:
smfSystem:
display: "SMF System"
list:
- name: "sbiIpAddr"
type: "string"
value: "172.16.5.150"
access: "read-write"
filter: ''
display: "SBI IP"
comment: ""
- name: "sbiPort"
type: "int"
value: "8080"
access: "read-write"
filter: "0~65535"
display: "SBI Port"
comment: "0~65535"
- name: "sbiScheme"
type: "enum"
value: "http"
access: "read-write"
filter: "{\"0\":\"http\", \"1\":\"https\"}"
display: "SBI Scheme"
comment: ""
- name: "n4Ipv4"
type: "ipv4"
value: "172.16.5.150"
access: "read-write"
filter: ''
display: "N4 IPv4"
comment: ""
- name: "n4Ipv6"
type: "ipv6"
value: ""
access: "read-write"
filter: ''
display: "N4 IPv6"
comment: ""
- name: "n4UIpv4"
type: "ipv4"
value: ""
access: "read-write"
filter: ''
display: "N4U IPv4"
comment: ""
- name: "n4UIpv6"
type: "ipv6"
value: ""
access: "read-write"
filter: ''
display: "N4U IPv6"
comment: ""
- name: "amfUri"
type: "string"
value: "http://172.16.5.120:8080"
access: "read-write"
filter: ''
display: "AMF URI"
comment: ""
- name: "pcfUri"
type: "string"
value: "http://172.16.5.160:8080"
access: "read-write"
filter: ''
display: "PCF URI"
comment: ""
- name: "udmUri"
type: "string"
value: "http://172.16.5.140:8080"
access: "read-write"
filter: ''
display: "UDM URI"
comment: ""
- name: "nrfEnable"
type: "bool"
value: "false"
access: "read-write"
filter: "{\"0\":\"false\", \"1\":\"true\"}"
display: "NRF Enable"
comment: ""
- name: "nrfUri"
type: "string"
value: "http://172.16.5.180:8080"
access: "read-write"
filter: ''
display: "NRF URI"
comment: ""
- name: "primaryDnsIpv4"
type: "ipv4"
value: "114.114.114.114"
access: "read-write"
filter: ""
display: "Primary DNS IPv4"
comment: ""
- name: "secondaryDnsIpv4"
type: "ipv4"
value: ""
access: "read-write"
filter: ""
display: "Secondary DNS IPv4"
comment: ""
- name: "primaryDnsIpv6"
type: "ipv6"
value: ""
access: "read-write"
filter: ""
display: "Primary DNS IPv6"
comment: ""
- name: "secondaryDnsIpv6"
type: "ipv6"
value: ""
access: "read-write"
filter: ""
display: "Secondary DNS IPv6"
comment: ""
- name: "primaryPcscfIpv4"
type: "ipv4"
value: "172.16.5.110"
access: "read-write"
filter: ""
display: "Primary PCSCF IPv4"
comment: ""
- name: "secondaryPcscfIpv4"
type: "ipv4"
value: ""
access: "read-write"
filter: ""
display: "Secondary PCSCF IPv4"
comment: ""
- name: "primaryPcscfIpv6"
type: "ipv6"
value: ""
access: "read-write"
filter: ""
display: "Primary PCSCF IPv6"
comment: ""
- name: "secondaryPcscfIpv6"
type: "ipv6"
value: ""
access: "read-write"
filter: ""
display: "Secondary PCSCF IPv6"
comment: ""
- name: "ueMtu"
type: "int"
value: ""
access: "read-write"
filter: "0~65535"
display: "UE MTU"
comment: ""
upfConfig:
display: "UPF Config"
array:
- name: "index"
type: "int"
value: ""
access: "read-write"
filter: '0~65535'
display: "Index"
comment: ""
- name: "id"
type: "string"
value: ""
access: "read-write"
filter: '1~64'
display: "UPF ID"
comment: ""
- name: "addr"
type: "string"
value: ""
access: "read-write"
filter: '7~45'
display: "Address"
comment: "e.g. ip:port"
- name: "ipv4Pools"
type: "string"
value: ""
access: "read-write"
filter: '10~256'
display: "IPv4 Pools"
comment: "CIDR format, e.g. 192.168.1.0/24"
- name: "ipv6Pools"
type: "string"
value: ""
access: "read-write"
filter: '5~512'
display: "IPv6 Pools"
comment: "CIDR format, e.g. fe80::20c:29ff:fee4:dab7/50"
- name: "staticIpv4Enable"
type: "bool"
value: ""
access: "read-write"
filter: "{\"0\":\"false\", \"1\":\"true\"}"
display: "Static IPv4 Enable"
comment: ""
- name: "staticIpv4Start"
type: "ipv4"
value: ""
access: "read-write"
filter: ''
display: "Static IPv4 Start"
comment: "ipv4 format"
- name: "staticIpv4End"
type: "ipv4"
value: ""
access: "read-write"
filter: ''
display: "Static IPv4 End"
comment: "ipv4 format"
- name: "staticIpv6Enable"
type: "bool"
value: ""
access: "read-write"
filter: "{\"0\":\"false\", \"1\":\"true\"}"
display: "Static IPv6 Enable"
comment: ""
- name: "staticIpv6Start"
type: "ipv6"
value: ""
access: "read-write"
filter: ''
display: "Static IPv6 Start"
comment: "ipv6 format"
- name: "staticIpv6End"
type: "ipv6"
value: ""
access: "read-write"
filter: ''
display: "Static IPv6 End"
comment: "ipv6 format"
dnnSelectUpf:
display: "DNN Select UPF"
array:
- name: "index"
type: "int"
value: "0"
access: "read-write"
filter: '0~65535'
display: "Index"
comment: ""
- name: "dnn"
type: "string"
value: ""
access: "read-write"
filter: '1~64'
display: "DNN"
comment: ""
- name: "upfId"
type: "string"
value: ""
access: "read-write"
filter: '1~64'
display: "UPF ID"
comment: "UPF ID"
dnnTaiSelectUpf:
display: "DNN TAI Select UPF"
array:
- name: "index"
type: "int"
value: ""
access: "read-write"
filter: '0~65535'
display: "Index"
comment: ""
- name: "dnn"
type: "string"
value: ""
access: "read-write"
filter: '1~64'
display: "DNN"
comment: ""
- name: "tai"
type: "string"
value: ""
access: "read-write"
filter: '1~64'
display: "TAI"
comment: "MCC+MNC+TAC"
- name: "upfId"
type: "string"
value: "upf2-Id"
access: "read-write"
filter: '1~64'
display: "UPF ID"
comment: ""
test:
smfSystem:
display: "SMF System"
list:
- name: "sbiIpAddr"
type: "string"
value: "172.16.5.150"
access: "read-write"
filter: ''
display: "SBI IP"
comment: ""
amf:
smfSystem:
display: "SMF System"
list:
- name: "sbiIpAddr"
type: "string"
value: "172.16.5.150"
access: "read-write"
filter: ''
display: "SBI IP"
comment: ""

View File