diff --git a/example/diam.js b/example/diam.js new file mode 100644 index 0000000..49f6c6f --- /dev/null +++ b/example/diam.js @@ -0,0 +1,23 @@ + +export const flags = { + Vbit: 0x80, + Mbit: 0x40, + Pbit: 0x20, +} + +export const avpCode = { + OriginHost: 264, + OriginRealm: 296, + DestinationHost: 283, + DestinationRealm: 293, + SessionId: 263, + CCRequestType: 416, + CCRequestNumber: 415, + SubscriptionId: 443, + SubscriptionIdData: 444, + SubscriptionIdType: 450, +} + +export const vendorId = { + TGPP: 10415, +} diff --git a/example/example.js b/example/example.js new file mode 100644 index 0000000..cdbd5ef --- /dev/null +++ b/example/example.js @@ -0,0 +1,38 @@ +import diam from 'k6/x/diameter' +import avp from 'k6/x/diameter/avp' +import { avpCode, flags, vendorId } from './diam.js' + +import { check } from 'k6' + +export let options = { + iterations: 1, + vus: 1, +} + +let client = diam.newClient() +let dataType = diam.DataType() + +export default function () { + client.connect("localhost:3868") + + let msg = diam.newMessage("CCR"); + + msg.AVP(avpCode.OriginHost, 0, 0, dataType.DiameterIdentity("origin.host")) + msg.AVP(avpCode.OriginRealm, 0, 0, dataType.DiameterIdentity("origin.realm")) + msg.AVP(avpCode.DestinationHost, 0, 0, dataType.DiameterIdentity("dest.host")) + msg.AVP(avpCode.DestinationRealm, 0, 0, dataType.DiameterIdentity("dest.realm")) + + msg.AVP(avpCode.SessionId, 0, flags.Mbit, dataType.UTF8String("Session-8888")) + msg.AVP(avpCode.CCRequestType, 0, flags.Mbit, dataType.Enumerated(1)) + msg.AVP(avpCode.CCRequestNumber, 0, flags.Mbit, dataType.Unsigned32(1000)) + + msg.AVP(avpCode.SubscriptionId, 0, flags.Mbit, dataType.Grouped([ + avp.New(avpCode.SubscriptionIdData, 0, flags.Mbit, dataType.UTF8String("subs-data")), + avp.New(avpCode.SubscriptionIdType, 0, flags.Mbit, dataType.Enumerated(1)) + ])) + + const response = diam.send(client, msg) + console.log("Result Code:", response) + + check(response, {'Result-Code == 2001': r => r == 2001,}) +}