diameter

package module
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2024 License: MIT Imports: 15 Imported by: 0

README

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 --logformat=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 Name Type Description
RequestTimeout duration Timeout for each request
MaxRetransmits number Maximum number of message retransmissions
RetransmitInterval duration Interval between message retransmissions
EnableWatchdog boolean Flag to enable automatic DWR (Diameter Watchdog Request)
WatchdogInterval duration Interval between sending DWRs
WatchdogStream number Stream ID for sending DWRs (for multistreaming protocols)
SupportedVendorID number array List of supported vendor IDs
AcctApplicationID number array List of accounting application IDs
AuthApplicationID number array List of authentication application IDs
VendorSpecificApplicationID object List of vendor-specific application IDs
CapabilityExchange object Configuration for capability exchange
TransportProtocol string Transport layer protocol to use, either "tcp" or "sctp". Defaults to "tcp"
TLS object TLS Configuration
Vendor Specific Application Id Config
Field Name Type Description
VendorID number Vendor ID
AuthApplicationID number Auth Application ID
AcctApplicationID number Acct Application ID
Capability Exchange Config
Field Name Type Description
VendorID number Vendor ID
ProductName string Name of the product
OriginHost string Host name of the origin
OriginRealm string Realm of the origin
FirmwareRevision number Firmware revision number
HostIPAddresses string array List of host IP addresses
TLS Config
Field Name Type Description
Enable boolean Use TLS encrypted connection
Cert String TLS certificate file, can be empty
Key String TLS 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,
    },
})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AVP

type AVP struct{}

func (*AVP) XNew

func (a *AVP) XNew(code uint32, vendor uint32, flags uint8, data datatype.Type) *diam.AVP

type CapabilityExchangeConfig

type CapabilityExchangeConfig struct {
	VendorID         *uint32   `json:"vendorID"`
	ProductName      *string   `json:"productName,omitempty"`
	OriginHost       *string   `json:"originHost,omitempty"`
	OriginRealm      *string   `json:"originRealm,omitempty"`
	FirmwareRevision *uint32   `json:"firmwareRevision,omitempty"`
	HostIPAddresses  *[]string `json:"hostIPAddresses,omitempty"`
}

type DataType

type DataType struct{}

func (*DataType) XAddress

func (d *DataType) XAddress(value string) datatype.Type

func (*DataType) XDiameterIdentity

func (d *DataType) XDiameterIdentity(value string) datatype.Type

func (*DataType) XDiameterURI

func (d *DataType) XDiameterURI(value string) datatype.Type

func (*DataType) XEnumerated

func (d *DataType) XEnumerated(value int32) datatype.Type

func (*DataType) XFloat32

func (d *DataType) XFloat32(value float32) datatype.Type

func (*DataType) XFloat64

func (d *DataType) XFloat64(value float64) datatype.Type

func (*DataType) XGrouped

func (d *DataType) XGrouped(avps []*diam.AVP) datatype.Type

func (*DataType) XIPFilterRule

func (d *DataType) XIPFilterRule(value string) datatype.Type

func (*DataType) XIPv4

func (d *DataType) XIPv4(value string) datatype.Type

func (*DataType) XIPv6

func (d *DataType) XIPv6(value string) datatype.Type

func (*DataType) XInteger32

func (d *DataType) XInteger32(value int32) datatype.Type

func (*DataType) XInteger64

func (d *DataType) XInteger64(value int64) datatype.Type

func (*DataType) XOctetString

func (d *DataType) XOctetString(value string) datatype.Type

func (*DataType) XQoSFilterRule

func (d *DataType) XQoSFilterRule(value string) datatype.Type

func (*DataType) XTime

func (d *DataType) XTime(value time.Time) datatype.Type

func (*DataType) XUTF8String

func (d *DataType) XUTF8String(value string) datatype.Type

func (*DataType) XUnsigned32

func (d *DataType) XUnsigned32(value uint32) datatype.Type

func (*DataType) XUnsigned64

func (d *DataType) XUnsigned64(value uint64) datatype.Type

type Diameter

type Diameter struct {
	// contains filtered or unexported fields
}

func (*Diameter) Exports added in v0.1.2

func (d *Diameter) Exports() modules.Exports

func (*Diameter) NewMessage

func (*Diameter) NewMessage(cmd uint32, appid uint32) *DiameterMessage

func (*Diameter) XClient

func (d *Diameter) XClient(arg map[string]interface{}) (*DiameterClient, error)

func (*Diameter) XDataType

func (*Diameter) XDataType() DataType

type DiameterClient

type DiameterClient struct {
	// contains filtered or unexported fields
}

func (*DiameterClient) Connect

func (c *DiameterClient) Connect(address string) error

func (*DiameterClient) Send

type DiameterConfig

type DiameterConfig struct {
	RequestTimeout              *Duration                            `json:"requestTimeout,omitempty"`
	MaxRetransmits              *uint                                `json:"maxRetransmits,omitempty"`
	RetransmitInterval          *Duration                            `json:"retransmitInterval,omitempty"`
	EnableWatchdog              *bool                                `json:"enableWatchdog,omitempty"`
	WatchdogInterval            *Duration                            `json:"watchdogInterval,omitempty"`
	WatchdogStream              *uint                                `json:"watchdogStream,omitempty"`
	SupportedVendorID           *[]uint32                            `json:"supportedVendorID,omitempty"`
	AcctApplicationID           *[]uint32                            `json:"acctApplicationId,omitempty"`
	AuthApplicationId           *[]uint32                            `json:"authApplicationId,omitempty"`
	VendorSpecificApplicationID *[]VendorSpecificApplicationIDConfig `json:"vendorSpecificApplicationId,omitempty"`
	CapabilityExchange          *CapabilityExchangeConfig            `json:"capabilityExchange,omitempty"`
	TransportProtocol           *string                              `josn:"transportProtocol,omitempty"`
	TLS                         *TLSConfig                           `json:"tls,omitempty"`
}

type DiameterMessage

type DiameterMessage struct {
	// contains filtered or unexported fields
}

func (*DiameterMessage) Add

func (m *DiameterMessage) Add(a *diam.AVP)

func (*DiameterMessage) FindAVP

func (m *DiameterMessage) FindAVP(code uint32, vendor uint32) (interface{}, error)

func (*DiameterMessage) String

func (m *DiameterMessage) String() string

func (*DiameterMessage) XAVP

func (m *DiameterMessage) XAVP(code uint32, vendor uint32, flags uint8, data datatype.Type)

deprecated

type DiameterMetrics added in v0.1.2

type DiameterMetrics struct {
	RequestDuration    *metrics.Metric
	RequestCount       *metrics.Metric
	FailedRequestCount *metrics.Metric
}

type Dict

type Dict struct{}

func (*Dict) Load

func (*Dict) Load(dictionary string) error

type Duration

type Duration struct {
	time.Duration
}

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

type GroupedAVP

type GroupedAVP struct {
	// contains filtered or unexported fields
}

func (*GroupedAVP) FindAVP

func (g *GroupedAVP) FindAVP(code uint32, vendor uint32) (interface{}, error)

type RootModule

type RootModule struct{}

func New added in v0.1.2

func New() *RootModule

func (*RootModule) NewModuleInstance added in v0.1.2

func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance

type TLSConfig added in v0.1.3

type TLSConfig struct {
	Enable bool   `json:"enable"`
	Cert   string `json:"cert,omitempty"`
	Key    string `json:"key,omitempty"`
}

type VendorSpecificApplicationIDConfig added in v0.1.1

type VendorSpecificApplicationIDConfig struct {
	VendorID          *uint32 `json:"vendorId,omitempty"`
	AuthApplicationID *uint32 `json:"authApplicationId,omitempty"`
	AcctApplicationID *uint32 `json:"acctApplicationId,omitempty"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL