Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
lwlee2608 committed Nov 11, 2023
1 parent 0a9d917 commit 31d73c5
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
23 changes: 23 additions & 0 deletions example/diam.js
Original file line number Diff line number Diff line change
@@ -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,
}
38 changes: 38 additions & 0 deletions example/example.js
Original file line number Diff line number Diff line change
@@ -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,})
}

0 comments on commit 31d73c5

Please sign in to comment.