Home

Awesome

k6 Extension for Diameter

Overview

This extension adds support for the Diameter protocol to k6.

Build

make

The Makefile will automatically download xk6, which is required to compile this project.

Example

import diam from 'k6/x/diameter'
import avp from 'k6/x/diameter/avp'
import dict from 'k6/x/diameter/dict'
import { cmd, app, code, flag, vendor } from './diam/const.js'
import { check } from 'k6'

let data = diam.DataType()

let client = diam.Client({
    authApplicationId: [app.ChargingControl],
})

export default function () {
    client.connect("localhost:3868")

    let ccr = diam.newMessage(cmd.CreditControl, app.ChargingControl);
    ccr.add(avp.New(code.OriginHost,         0,     0,       data.DiameterIdentity("origin.host")))
    ccr.add(avp.New(code.OriginRealm,        0,     0,       data.DiameterIdentity("origin.realm")))
    ccr.add(avp.New(code.DestinationHost,    0,     0,       data.DiameterIdentity("dest.host")))
    ccr.add(avp.New(code.DestinationRealm,   0,     0,       data.DiameterIdentity("dest.realm")))
    ccr.add(avp.New(code.SessionId,          0,     flag.M,  data.UTF8String("Session-8888")))
    ccr.add(avp.New(code.CCRequestType,      0,     flag.M,  data.Enumerated(1)))
    ccr.add(avp.New(code.CCRequestNumber,    0,     flag.M,  data.Unsigned32(1000)))
    ccr.add(avp.New(code.SubscriptionId,     0,     flag.M,  data.Grouped([
        avp.New(code.SubscriptionIdData,     0,     flag.M,  data.UTF8String("subs-data")),
        avp.New(code.SubscriptionIdType,     0,     flag.M,  data.Enumerated(1))
    ])))
    ccr.add(avp.New(code.ServiceInformation, 10415, flag.M,  data.Grouped([
        avp.New(code.PSInformation,          10415, flag.M,  data.Grouped([
            avp.New(code.CalledStationId,    0,     flag.M,  data.UTF8String("10099"))
        ]))
    ])))

    const cca = client.send(ccr)
    console.log(`CCA: ${cca}`)

    const resultCode = cca.findAVP(code.ResultCode, 0)
    check(resultCode, {'Result-Code == 2001': r => r == 2001,})
}

Use your custom k6 binary to run an example k6 script.

./bin/k6 run example/example.js

Docker

Alternatively, you may run xk6-diameter packaged in Docker using the following command:

docker run \
  --net=host \
  -v $(pwd)/example:/mnt/example \
  ghcr.io/matrixxsoftware/xk6-diameter run --log-format=raw /mnt/example/example.js  

Generator

There are thousands of AVPs, each with a unique avp-code and vendor-id. To aid readability and enhance the developer experience, we recommend defining them as constants in a separate file, for example, using diam/const.js.

You can either create the constant yourself or use the bin/dict_generator CLI tool to generate a full list of AVPs for you. Use the following command:

./bin/dict_generator -output example/diam/const.js

The CLI also supports generating additional AVPs that are not defined in the default list. Simply add the -dictionary flag to include the additional AVP definition:

./bin/dict_generator -output example/diam/const.js -dictionary dict/extra.xml

Configurations

Configuration Options

Diameter Config

Field NameTypeDescription
RequestTimeoutdurationTimeout for each request
MaxRetransmitsnumberMaximum number of message retransmissions
RetransmitIntervaldurationInterval between message retransmissions
EnableWatchdogbooleanFlag to enable automatic DWR (Diameter Watchdog Request)
WatchdogIntervaldurationInterval between sending DWRs
WatchdogStreamnumberStream ID for sending DWRs (for multistreaming protocols)
SupportedVendorIDnumber arrayList of supported vendor IDs
AcctApplicationIDnumber arrayList of accounting application IDs
AuthApplicationIDnumber arrayList of authentication application IDs
VendorSpecificApplicationIDobjectList of vendor-specific application IDs
CapabilityExchangeobjectConfiguration for capability exchange
TransportProtocolstringTransport layer protocol to use, either "tcp" or "sctp". Defaults to "tcp"
TLSobjectTLS Configuration

Vendor Specific Application Id Config

Field NameTypeDescription
VendorIDnumberVendor ID
AuthApplicationIDnumberAuth Application ID
AcctApplicationIDnumberAcct Application ID

Capability Exchange Config

Field NameTypeDescription
VendorIDnumberVendor ID
ProductNamestringName of the product
OriginHoststringHost name of the origin
OriginRealmstringRealm of the origin
FirmwareRevisionnumberFirmware revision number
HostIPAddressesstring arrayList of host IP addresses

TLS Config

Field NameTypeDescription
EnablebooleanUse TLS encrypted connection
CertStringTLS certificate file, can be empty
KeyStringTLS private key file, can be empty

Example

The following example demonstrates how to create a Diameter client in k6 with various configuration options.

let client = diam.Client({
    requestTimeout: "50ms",
    enableWatchdog: false,
    authApplicationId: [app.ChargingControl],
    vendorSpecificApplicationId: [
        {
            authApplicationId: app.ChargingControl,
            vendorId: vendor.TGPP,
        }
    ],
    capabilityExchange: {
        vendorId: 35838,
    },
})