Skip to content

Commit

Permalink
replace DiameterMessage.AVP() with DiameterMessage.add()
Browse files Browse the repository at this point in the history
  • Loading branch information
lwlee2608 committed Nov 21, 2023
1 parent 5ff7e44 commit 503a366
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 39 deletions.
37 changes: 18 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,28 @@ import { cmd, app, code, flag, vendor } from './diam/const.js'
import { check } from 'k6'

let client = diam.Client()
let dataType = diam.DataType()
let data = diam.DataType()

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

let msg = diam.newMessage(cmd.CreditControl, app.ChargingControl);

msg.AVP(code.OriginHost, 0, 0, dataType.DiameterIdentity("origin.host"))
msg.AVP(code.OriginRealm, 0, 0, dataType.DiameterIdentity("origin.realm"))
msg.AVP(code.DestinationHost, 0, 0, dataType.DiameterIdentity("dest.host"))
msg.AVP(code.DestinationRealm, 0, 0, dataType.DiameterIdentity("dest.realm"))
msg.AVP(code.SessionId, 0, flag.M, dataType.UTF8String("Session-8888"))
msg.AVP(code.CCRequestType, 0, flag.M, dataType.Enumerated(1))
msg.AVP(code.CCRequestNumber, 0, flag.M, dataType.Unsigned32(1000))
msg.AVP(code.SubscriptionId, 0, flag.M, dataType.Grouped([
avp.New(code.SubscriptionIdData, 0, flag.M, dataType.UTF8String("subs-data")),
avp.New(code.SubscriptionIdType, 0, flag.M, dataType.Enumerated(1))
]))

const response = client.send(msg)
console.log("Response: ", response.dump())

const resultCode = response.findAVP(code.ResultCode, 0)
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))
])))

const cca = client.send(msg)
console.log("cca: ", cca.dump())

const resultCode = cca.findAVP(code.ResultCode, 0)
check(resultCode, {'Result-Code == 2001': r => r == 2001,})
}
```
Expand Down
1 change: 0 additions & 1 deletion cmd/dict_generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ func PrintVendorId(w io.Writer, parser *dict.Parser) {
vendorIds[vendor.ID] = exists

fmt.Fprintf(w, " %-20s %d,\n", vendor.Name+":", vendor.ID)
// fmt.Fprintf(w, " %s: %d,\n", vendor.Name, vendor.ID)
}
}
fmt.Fprintf(w, "}\n")
Expand Down
5 changes: 5 additions & 0 deletions diameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,15 @@ func (*Diameter) NewMessage(cmd uint32, appid uint32) *DiameterMessage {
}
}

// deprecated
func (m *DiameterMessage) XAVP(code uint32, vendor uint32, flags uint8, data datatype.Type) {
m.diamMsg.NewAVP(code, flags, vendor, data)
}

func (m *DiameterMessage) Add(a *diam.AVP) {
m.diamMsg.AddAVP(a)
}

func (m *DiameterMessage) Dump() string {
return m.diamMsg.PrettyDump()
}
Expand Down
37 changes: 18 additions & 19 deletions example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,27 @@ dict.load("dict/extra.xml")
let client = diam.Client({
requestTimeout: "50ms",
})
let dataType = diam.DataType()
let data = diam.DataType()

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

let msg = diam.newMessage(cmd.CreditControl, app.ChargingControl);

msg.AVP(code.OriginHost, 0, 0, dataType.DiameterIdentity("origin.host"))
msg.AVP(code.OriginRealm, 0, 0, dataType.DiameterIdentity("origin.realm"))
msg.AVP(code.DestinationHost, 0, 0, dataType.DiameterIdentity("dest.host"))
msg.AVP(code.DestinationRealm, 0, 0, dataType.DiameterIdentity("dest.realm"))
msg.AVP(code.SessionId, 0, flag.M, dataType.UTF8String("Session-8888"))
msg.AVP(code.CCRequestType, 0, flag.M, dataType.Enumerated(1))
msg.AVP(code.CCRequestNumber, 0, flag.M, dataType.Unsigned32(1000))
msg.AVP(code.SubscriptionId, 0, flag.M, dataType.Grouped([
avp.New(code.SubscriptionIdData, 0, flag.M, dataType.UTF8String("subs-data")),
avp.New(code.SubscriptionIdType, 0, flag.M, dataType.Enumerated(1))
]))

const response = client.send(msg)
console.log("Response: ", response.dump())

const resultCode = response.findAVP(code.ResultCode, 0)
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))
])))

const cca = client.send(ccr)
console.log("CCA: ", cca.dump())

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

0 comments on commit 503a366

Please sign in to comment.