From f3a396a709050993952946f973d8578e58bfeae7 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Mon, 20 Nov 2023 10:31:03 +0800 Subject: [PATCH] Handle all Application Id --- cmd/dict_generator/main.go | 11 +++++++++++ diameter.go | 4 ++-- example/diam/const.js | 7 +++++++ example/example.js | 4 ++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/cmd/dict_generator/main.go b/cmd/dict_generator/main.go index dba25a7..7f8c7ec 100644 --- a/cmd/dict_generator/main.go +++ b/cmd/dict_generator/main.go @@ -41,11 +41,22 @@ func main() { defer w.Close() PrintCmd(w) + PrintAppId(w) PrintFlags(w) PrintAvpCode(w, parser) PrintVendorId(w, parser) } +func PrintAppId(w io.Writer) { + fmt.Fprintf(w, "export const appId = {\n") + fmt.Fprintf(w, " %-35s %d,\n", "Accounting:", 3) + fmt.Fprintf(w, " %-35s %d,\n", "ChargingControl:", 4) + fmt.Fprintf(w, " %-35s %d,\n", "Gx:", 16777238) + fmt.Fprintf(w, " %-35s %d,\n", "Sy:", 16777302) + fmt.Fprintf(w, "}\n") + fmt.Fprintf(w, "\n") +} + func PrintCmd(w io.Writer) { fmt.Fprintf(w, "export const cmd = {\n") fmt.Fprintf(w, " %-35s %d,\n", "AA:", 265) diff --git a/diameter.go b/diameter.go index 00d382c..453de69 100644 --- a/diameter.go +++ b/diameter.go @@ -147,9 +147,9 @@ func (c *DiameterClient) Send(msg *DiameterMessage) (uint32, error) { return uint32(resultCode), nil } -func (*Diameter) NewMessage(cmd uint32) *DiameterMessage { +func (*Diameter) NewMessage(cmd uint32, appid uint32) *DiameterMessage { return &DiameterMessage{ - diamMsg: diam.NewRequest(cmd, 4, dict.Default), + diamMsg: diam.NewRequest(cmd, appid, dict.Default), } } diff --git a/example/diam/const.js b/example/diam/const.js index f4cac4b..56df682 100644 --- a/example/diam/const.js +++ b/example/diam/const.js @@ -7,6 +7,13 @@ export const cmd = { SpendingLimit: 8388635, } +export const appId = { + Accounting: 3, + ChargingControl: 4, + Gx: 16777238, + Sy: 16777302, +} + export const flags = { Vbit: 0x80, Mbit: 0x40, diff --git a/example/example.js b/example/example.js index 311090f..7649543 100644 --- a/example/example.js +++ b/example/example.js @@ -1,7 +1,7 @@ import diam from 'k6/x/diameter' import avp from 'k6/x/diameter/avp' import dict from 'k6/x/diameter/dict' -import { cmd, avpCode, flags, vendorId } from './diam/const.js' +import { cmd, appId, avpCode, flags, vendorId } from './diam/const.js' import { check } from 'k6' @@ -22,7 +22,7 @@ let dataType = diam.DataType() export default function () { client.connect("localhost:3868") - let msg = diam.newMessage(cmd.CreditControl); + let msg = diam.newMessage(cmd.CreditControl, appId.ChargingControl); msg.AVP(avpCode.OriginHost, 0, 0, dataType.DiameterIdentity("origin.host")) msg.AVP(avpCode.OriginRealm, 0, 0, dataType.DiameterIdentity("origin.realm"))