Skip to content

Commit

Permalink
add more capability-exhcnage config
Browse files Browse the repository at this point in the history
  • Loading branch information
lwlee2608 committed Nov 19, 2023
1 parent d209ff8 commit 39154c3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 33 deletions.
58 changes: 34 additions & 24 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@ import (
"time"
)

type CapacityExchangeConfig struct {
VendorID *uint32 `json:"vendorID"`
ProductName *string `json:"productName,omitempty"`
OriginHost *string `json:"originHost,omitempty"`
OriginRealm *string `json:"originRealm,omitempty"`
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"`
CapabilityExchange *CapabilityExchangeConfig `json:"capabilityExchange,omitempty"`
}

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"`
CapacityExchange *CapacityExchangeConfig `json:"capacityExchange,omitempty"`
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"`
}

func processConfig(arg map[string]interface{}) (*DiameterConfig, error) {
Expand Down Expand Up @@ -52,6 +54,8 @@ func setDiameterConfigDefaults(config *DiameterConfig) {
var defaultProductName = "xk6-diameter"
var defaultOriginHost = "origin.host"
var defaultOriginRealm = "origin.realm"
var defaultFirmwareRevision uint32 = 1
var defaultHostIPAddresses = []string{"127.0.0.1"}

// Set defaults for DiameterConfig
if config.RequestTimeout == nil {
Expand All @@ -73,21 +77,27 @@ func setDiameterConfigDefaults(config *DiameterConfig) {
config.WatchdogStream = &defaultWatchdogStream
}

// Set defaults for CapacityExchangeConfig
if config.CapacityExchange == nil {
config.CapacityExchange = &CapacityExchangeConfig{}
// Set defaults for CapabilityExchangeConfig
if config.CapabilityExchange == nil {
config.CapabilityExchange = &CapabilityExchangeConfig{}
}
if config.CapabilityExchange.VendorID == nil {
config.CapabilityExchange.VendorID = &defaultVendorID
}
if config.CapabilityExchange.ProductName == nil {
config.CapabilityExchange.ProductName = &defaultProductName
}
if config.CapacityExchange.VendorID == nil {
config.CapacityExchange.VendorID = &defaultVendorID
if config.CapabilityExchange.OriginHost == nil {
config.CapabilityExchange.OriginHost = &defaultOriginHost
}
if config.CapacityExchange.ProductName == nil {
config.CapacityExchange.ProductName = &defaultProductName
if config.CapabilityExchange.OriginRealm == nil {
config.CapabilityExchange.OriginRealm = &defaultOriginRealm
}
if config.CapacityExchange.OriginHost == nil {
config.CapacityExchange.OriginHost = &defaultOriginHost
if config.CapabilityExchange.FirmwareRevision == nil {
config.CapabilityExchange.FirmwareRevision = &defaultFirmwareRevision
}
if config.CapacityExchange.OriginRealm == nil {
config.CapacityExchange.OriginRealm = &defaultOriginRealm
if config.CapabilityExchange.HostIPAddresses == nil {
config.CapabilityExchange.HostIPAddresses = &defaultHostIPAddresses
}
}

Expand Down
21 changes: 12 additions & 9 deletions diameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,19 @@ func (*Diameter) XClient(arg map[string]interface{}) (*DiameterClient, error) {
return nil, err
}

hostIPAddresses := []datatype.Address{}
for _, ip := range *config.CapabilityExchange.HostIPAddresses {
hostIPAddresses = append(hostIPAddresses, datatype.Address(net.ParseIP(ip)))
}

cfg := &sm.Settings{
OriginHost: datatype.DiameterIdentity(*config.CapacityExchange.OriginHost),
OriginRealm: datatype.DiameterIdentity(*config.CapacityExchange.OriginRealm),
VendorID: datatype.Unsigned32(*config.CapacityExchange.VendorID),
ProductName: datatype.UTF8String(*config.CapacityExchange.ProductName),
OriginHost: datatype.DiameterIdentity(*config.CapabilityExchange.OriginHost),
OriginRealm: datatype.DiameterIdentity(*config.CapabilityExchange.OriginRealm),
VendorID: datatype.Unsigned32(*config.CapabilityExchange.VendorID),
ProductName: datatype.UTF8String(*config.CapabilityExchange.ProductName),
OriginStateID: datatype.Unsigned32(time.Now().Unix()),
FirmwareRevision: 1,
HostIPAddresses: []datatype.Address{
datatype.Address(net.ParseIP("127.0.0.1")),
},
FirmwareRevision: datatype.Unsigned32(*config.CapabilityExchange.FirmwareRevision),
HostIPAddresses: hostIPAddresses,
}
mux := sm.New(cfg)

Expand All @@ -64,7 +67,7 @@ func (*Diameter) XClient(arg map[string]interface{}) (*DiameterClient, error) {
WatchdogInterval: *&config.WatchdogInterval.Duration,
WatchdogStream: *config.WatchdogStream,
AuthApplicationID: []*diam.AVP{
diam.NewAVP(avp.AuthApplicationID, avp.Mbit, 0, datatype.Unsigned32(4)),
diam.NewAVP(avp.AuthApplicationID, avp.Mbit, 0, datatype.Unsigned32(4)), // TODO make configurable
},
}

Expand Down

0 comments on commit 39154c3

Please sign in to comment.