Skip to content

Commit

Permalink
Update README.md and Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
lwlee2608 committed Nov 13, 2023
1 parent fe79df8 commit 571c261
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 13 deletions.
20 changes: 13 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
XK6 = $(shell which xk6 2>/dev/null)
GO = $(shell which go 2>/dev/null)

BIN := bin/k6
.PHONY: all clean xk6 build generator

all: clean xk6-diameter
all: clean build generator

clean:
$(RM) $(BIN)
xk6:
go install go.k6.io/xk6/cmd/xk6@latest

generator:
$(GO) build -o bin/dict_generator cmd/dict_generator/main.go

xk6-diameter:
$(XK6) build v0.37.0 --with github.com/matrixxsoftware/xk6-diameter=. --output $(BIN)
build: xk6
xk6 build v0.37.0 --with github.com/matrixxsoftware/xk6-diameter=. --output bin/k6

clean:
$(RM) bin/k6 bin/dict_generator
49 changes: 45 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,56 @@

## Overview

This extension add Diameter protocol support to [k6](https://k6.io/).
This extension adds support for the Diameter protocol to [k6](https://k6.io/).

## Build

Install `xk6`
```bash
go install go.k6.io/xk6/cmd/xk6@latest
make
```
The Makefile will automatically download [xk6](https://github.com/grafana/xk6), which is required to compile this project.

## Generator
`bin/dict_generator` is used to generate `diam/const.js`, which contains a list of AVP codes and vendor IDs.

```bash
make
./bin/dict_generator -output example/diam/const.js
```

## Example

```js
import diam from 'k6/x/diameter'
import avp from 'k6/x/diameter/avp'
import { avpCode, flags, vendorId } from './diam/const.js'

let client = diam.Client()
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)

check(response, {'Result-Code == 2001': r => r == 2001,})
}
```

Use your custom k6 binary to run an example k6 script.
```bash
./bin/k6 run example/example.js
```
2 changes: 0 additions & 2 deletions example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ export default function () {
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))
Expand Down

0 comments on commit 571c261

Please sign in to comment.