Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add tls support #16

Merged
merged 2 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Configurations
| 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 |
Expand All @@ -122,6 +123,13 @@ Configurations
| 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.

Expand Down
22 changes: 18 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ type DiameterConfig struct {
AcctApplicationID *[]uint32 `json:"acctApplicationId,omitempty"`
AuthApplicationId *[]uint32 `json:"authApplicationId,omitempty"`
VendorSpecificApplicationID *[]VendorSpecificApplicationIDConfig `json:"vendorSpecificApplicationId,omitempty"`
TransportProtocol *string `josn:"transportProtocol,omitempty"`
CapabilityExchange *CapabilityExchangeConfig `json:"capabilityExchange,omitempty"`
TransportProtocol *string `josn:"transportProtocol,omitempty"`
TLS *TLSConfig `json:"tls,omitempty"`
}

type VendorSpecificApplicationIDConfig struct {
Expand All @@ -36,6 +37,12 @@ type CapabilityExchangeConfig struct {
HostIPAddresses *[]string `json:"hostIPAddresses,omitempty"`
}

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

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

var config DiameterConfig
Expand Down Expand Up @@ -104,9 +111,6 @@ func setDiameterConfigDefaults(config *DiameterConfig) {
if config.VendorSpecificApplicationID == nil {
config.VendorSpecificApplicationID = &defaultVendorSpecificApplicationID
}
if config.TransportProtocol == nil {
config.TransportProtocol = &defaultTransportProtocol
}

// Set defaults for CapabilityExchangeConfig
if config.CapabilityExchange == nil {
Expand All @@ -130,6 +134,16 @@ func setDiameterConfigDefaults(config *DiameterConfig) {
if config.CapabilityExchange.HostIPAddresses == nil {
config.CapabilityExchange.HostIPAddresses = &defaultHostIPAddresses
}

if config.TransportProtocol == nil {
config.TransportProtocol = &defaultTransportProtocol
}

// Set defaults for TLSConfig
if config.TLS == nil {
config.TLS = &TLSConfig{}
}

}

type Duration struct {
Expand Down
14 changes: 13 additions & 1 deletion diameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ type DiameterClient struct {
transportProtocol string
metrics DiameterMetrics
vu modules.VU
tls bool
tlsCert string
tlsKey string
}

type DiameterMessage struct {
Expand Down Expand Up @@ -126,6 +129,9 @@ func (d *Diameter) XClient(arg map[string]interface{}) (*DiameterClient, error)
transportProtocol: *config.TransportProtocol,
metrics: d.metrics,
vu: d.vu,
tls: config.TLS.Enable,
tlsCert: config.TLS.Cert,
tlsKey: config.TLS.Key,
}, nil
}

Expand All @@ -146,7 +152,13 @@ func (c *DiameterClient) Connect(address string) error {
return nil
}

conn, err := c.client.DialNetwork(c.transportProtocol, address)
var conn diam.Conn
var err error
if c.tls {
conn, err = c.client.DialNetworkTLS(c.transportProtocol, address, c.tlsCert, c.tlsKey, nil)
} else {
conn, err = c.client.DialNetwork(c.transportProtocol, address)
}
if err != nil {
log.Errorf("Error connecting to %s, %v\n", address, err)
return err
Expand Down
46 changes: 30 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,51 @@ module github.com/matrixxsoftware/xk6-diameter

go 1.21.1

require go.k6.io/k6 v0.37.0
require go.k6.io/k6 v0.50.0

require (
github.com/fiorix/go-diameter v3.0.2+incompatible
github.com/fiorix/go-diameter/v4 v4.0.5-0.20231116194707-845be291bb4b
)
require github.com/fiorix/go-diameter/v4 v4.0.5-0.20231116194707-845be291bb4b

require (
golang.org/x/crypto v0.14.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd // indirect
go.opentelemetry.io/otel v1.21.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.21.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
go.opentelemetry.io/otel/sdk v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.21.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
golang.org/x/net v0.21.0 // indirect
google.golang.org/genproto v0.0.0-20231127180814-3a041ad873d4 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/grpc v1.60.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)

require (
github.com/dlclark/regexp2 v1.9.0 // indirect
github.com/dop251/goja v0.0.0-20230919151941-fc55792775de
github.com/fatih/color v1.15.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.4-0.20211119122758-180fcef48034+incompatible // indirect
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
github.com/dop251/goja v0.0.0-20240220182346-e401ed450204 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
github.com/google/pprof v0.0.0-20230728192033-2ba5b33183c6 // indirect
github.com/ishidawataru/sctp v0.0.0-20230406120618-7ff4192f6ff2 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/gomega v1.29.0 // indirect
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e // indirect
github.com/sirupsen/logrus v1.9.3
github.com/spf13/afero v1.1.2 // indirect
github.com/stretchr/testify v1.8.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
gopkg.in/guregu/null.v3 v3.3.0 // indirect
)
Loading
Loading