Skip to content

Commit

Permalink
Handle all CMD code
Browse files Browse the repository at this point in the history
  • Loading branch information
lwlee2608 committed Nov 20, 2023
1 parent 5aeb6b7 commit 80601d9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 34 deletions.
24 changes: 19 additions & 5 deletions cmd/dict_generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,29 @@ func main() {
}
defer w.Close()

PrintCmd(w)
PrintFlags(w)
PrintAvpCode(w, parser)
PrintVendorId(w, parser)
}

func PrintCmd(w io.Writer) {
fmt.Fprintf(w, "export const cmd = {\n")
fmt.Fprintf(w, " %-35s %d,\n", "AA:", 265)
fmt.Fprintf(w, " %-35s %d,\n", "Accounting:", 271)
fmt.Fprintf(w, " %-35s %d,\n", "CreditControl:", 272)
fmt.Fprintf(w, " %-35s %d,\n", "ReAuth:", 258)
fmt.Fprintf(w, " %-35s %d,\n", "SessionTermination:", 275)
fmt.Fprintf(w, " %-35s %d,\n", "SpendingLimit:", 8388635)
fmt.Fprintf(w, "}\n")
fmt.Fprintf(w, "\n")
}

func PrintFlags(w io.Writer) {
fmt.Fprintf(w, "export const flags = {\n")
fmt.Fprintf(w, " Vbit: 0x80,\n")
fmt.Fprintf(w, " Mbit: 0x40,\n")
fmt.Fprintf(w, " Pbit: 0x20,\n")
fmt.Fprintf(w, " %-35s 0x%x,\n", "Vbit:", 0x80)
fmt.Fprintf(w, " %-35s 0x%x,\n", "Mbit:", 0x40)
fmt.Fprintf(w, " %-35s 0x%x,\n", "Pbit:", 0x20)
fmt.Fprintf(w, "}\n")
fmt.Fprintf(w, "\n")
}
Expand All @@ -60,7 +73,7 @@ func PrintAvpCode(w io.Writer, parser *dict.Parser) {
fmt.Fprintf(w, " // %s\n", app.Name)
for _, avp := range app.AVP {
name := strings.ReplaceAll(avp.Name, "-", "")
fmt.Fprintf(w, " %s: %d,\n", name, avp.Code)
fmt.Fprintf(w, " %-35s %d,\n", name+":", avp.Code)
}
}
fmt.Fprintf(w, "}\n")
Expand All @@ -82,7 +95,8 @@ func PrintVendorId(w io.Writer, parser *dict.Parser) {
}
vendorIds[vendor.ID] = exists

fmt.Fprintf(w, " %s: %d,\n", vendor.Name, vendor.ID)
fmt.Fprintf(w, " %-35s %d,\n", vendor.Name+":", vendor.ID)
// fmt.Fprintf(w, " %s: %d,\n", vendor.Name, vendor.ID)
}
}
fmt.Fprintf(w, "}\n")
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type CapabilityExchangeConfig struct {
HostIPAddresses *[]string `json:"hostIPAddresses,omitempty"`
}

func processConfig(arg map[string]interface{}) (*DiameterConfig, error) {
func parseConfig(arg map[string]interface{}) (*DiameterConfig, error) {

var config DiameterConfig
if b, err := json.Marshal(arg); err != nil {
Expand Down
13 changes: 4 additions & 9 deletions diameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type DiameterClient struct {
}

type DiameterMessage struct {
name string // not exactly useful
diamMsg *diam.Message
}

Expand All @@ -34,7 +33,7 @@ type Dict struct{}

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

config, err := processConfig(arg)
config, err := parseConfig(arg)
if err != nil {
return nil, err
}
Expand All @@ -56,7 +55,7 @@ func (*Diameter) XClient(arg map[string]interface{}) (*DiameterClient, error) {
mux := sm.New(cfg)

hopIds := make(map[uint32]chan *diam.Message)
mux.Handle("CCA", handleCCA(hopIds))
mux.Handle("ALL", handleCCA(hopIds))

client := &sm.Client{
Dict: dict.Default,
Expand Down Expand Up @@ -148,13 +147,9 @@ func (c *DiameterClient) Send(msg *DiameterMessage) (uint32, error) {
return uint32(resultCode), nil
}

func (*Diameter) NewMessage(name string) *DiameterMessage {

diamMsg := diam.NewRequest(diam.CreditControl, 4, dict.Default)

func (*Diameter) NewMessage(cmd uint32) *DiameterMessage {
return &DiameterMessage{
name: name,
diamMsg: diamMsg,
diamMsg: diam.NewRequest(cmd, 4, dict.Default),
}
}

Expand Down
43 changes: 26 additions & 17 deletions example/diam/const.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
export const cmd = {
AA: 265,
Accounting: 271,
CreditControl: 272,
ReAuth: 258,
SessionTermination: 275,
SpendingLimit: 8388635,
}

export const flags = {
Vbit: 0x80,
Mbit: 0x40,
Pbit: 0x20,
Vbit: 0x80,
Mbit: 0x40,
Pbit: 0x20,
}

export const avpCode = {
DestinationHost: 293,
DestinationRealm: 283,
OriginHost: 264,
OriginRealm: 296,
OriginStateId: 278,
SessionId: 263,
CCRequestNumber: 415,
CCRequestType: 416,
SubscriptionId: 443,
SubscriptionIdData: 444,
SubscriptionIdType: 450,
DestinationHost: 293,
DestinationRealm: 283,
OriginHost: 264,
OriginRealm: 296,
OriginStateId: 278,
SessionId: 263,
CCRequestNumber: 415,
CCRequestType: 416,
SubscriptionId: 443,
SubscriptionIdData: 444,
SubscriptionIdType: 450,
// Extra
EventNameCode: 13001,
EventNameCode: 13001,
}

export const vendorId = {
TGPP: 10415,
Matrixxsoftware: 35838,
TGPP: 10415,
Matrixxsoftware: 35838,
}

4 changes: 2 additions & 2 deletions example/example.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import diam from 'k6/x/diameter'
import avp from 'k6/x/diameter/avp'
import dict from 'k6/x/diameter/dict'
import { avpCode, flags, vendorId } from './diam/const.js'
import { cmd, avpCode, flags, vendorId } from './diam/const.js'

import { check } from 'k6'

Expand All @@ -22,7 +22,7 @@ let dataType = diam.DataType()
export default function () {
client.connect("localhost:3868")

let msg = diam.newMessage("CCR");
let msg = diam.newMessage(cmd.CreditControl);

msg.AVP(avpCode.OriginHost, 0, 0, dataType.DiameterIdentity("origin.host"))
msg.AVP(avpCode.OriginRealm, 0, 0, dataType.DiameterIdentity("origin.realm"))
Expand Down

0 comments on commit 80601d9

Please sign in to comment.