mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
added multiple listeners for diameter agent
This commit is contained in:
committed by
Dan Christian Bogos
parent
897d6f0da1
commit
e859be8806
@@ -772,8 +772,12 @@ const CGRATES_CFG_JSON = `
|
||||
|
||||
"diameter_agent": {
|
||||
"enabled": false, // enables the diameter agent: <true|false>
|
||||
"listen": "127.0.0.1:3868", // address where to listen for diameter requests <x.y.z.y/x1.y1.z1.y1:1234>
|
||||
"listen_net": "tcp", // transport type for diameter <tcp|sctp>
|
||||
"listeners": [
|
||||
{
|
||||
"address": "127.0.0.1:3868", // address where to listen for diameter requests <x.y.z.y/x1.y1.z1.y1:1234>
|
||||
"network": "tcp", // transport type for diameter <tcp|sctp>
|
||||
}
|
||||
],
|
||||
"dictionaries_path": "/usr/share/cgrates/diameter/dict/", // path towards directory holding additional dictionaries to load
|
||||
// "ce_applications": [], // list of applications in dictionaries wanted to be included in Capability-Exchange. Needed either "app name", "app ID", or "vendor name.app name/ID"
|
||||
"sessions_conns": ["*birpc_internal"],
|
||||
|
||||
@@ -1079,9 +1079,12 @@ func TestAsteriskAgentJsonCfg(t *testing.T) {
|
||||
|
||||
func TestDiameterAgentJsonCfg(t *testing.T) {
|
||||
eCfg := &DiameterAgentJsonCfg{
|
||||
Enabled: utils.BoolPointer(false),
|
||||
Listen: utils.StringPointer("127.0.0.1:3868"),
|
||||
ListenNet: utils.StringPointer(utils.TCP),
|
||||
Enabled: utils.BoolPointer(false),
|
||||
Listeners: &[]*DiamListenerJsnCfg{
|
||||
{
|
||||
Address: utils.StringPointer("127.0.0.1:3868"),
|
||||
Network: utils.StringPointer(utils.TCP),
|
||||
}},
|
||||
DictionariesPath: utils.StringPointer("/usr/share/cgrates/diameter/dict/"),
|
||||
SessionSConns: &[]string{rpcclient.BiRPCInternal},
|
||||
StatSConns: &[]string{},
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -26,11 +26,15 @@ import (
|
||||
"github.com/cgrates/rpcclient"
|
||||
)
|
||||
|
||||
type DiameterListener struct {
|
||||
Network string // sctp or tcp
|
||||
Address string // address where to listen for diameter requests <x.y.z.y:1234>
|
||||
}
|
||||
|
||||
// DiameterAgentCfg the config section that describes the Diameter Agent
|
||||
type DiameterAgentCfg struct {
|
||||
Enabled bool // enables the diameter agent: <true|false>
|
||||
ListenNet string // sctp or tcp
|
||||
Listen string // address where to listen for diameter requests <x.y.z.y:1234>
|
||||
Enabled bool // enables the diameter agent: <true|false>
|
||||
Listeners []DiameterListener
|
||||
DictionariesPath string
|
||||
CeApplications []string
|
||||
SessionSConns []string
|
||||
@@ -57,11 +61,18 @@ func (da *DiameterAgentCfg) loadFromJSONCfg(jc *DiameterAgentJsonCfg, separator
|
||||
if jc.Enabled != nil {
|
||||
da.Enabled = *jc.Enabled
|
||||
}
|
||||
if jc.Listen != nil {
|
||||
da.Listen = *jc.Listen
|
||||
}
|
||||
if jc.ListenNet != nil {
|
||||
da.ListenNet = *jc.ListenNet
|
||||
if jc.Listeners != nil {
|
||||
da.Listeners = make([]DiameterListener, 0, len(*jc.Listeners))
|
||||
for _, listnr := range *jc.Listeners {
|
||||
var ls DiameterListener
|
||||
if listnr.Address != nil {
|
||||
ls.Address = *listnr.Address
|
||||
}
|
||||
if listnr.Network != nil {
|
||||
ls.Network = *listnr.Network
|
||||
}
|
||||
da.Listeners = append(da.Listeners, ls)
|
||||
}
|
||||
}
|
||||
if jc.DictionariesPath != nil {
|
||||
da.DictionariesPath = *jc.DictionariesPath
|
||||
@@ -145,12 +156,24 @@ func (da *DiameterAgentCfg) loadFromJSONCfg(jc *DiameterAgentJsonCfg, separator
|
||||
return
|
||||
}
|
||||
|
||||
// AsMapInterface returns the config as a map[string]any
|
||||
func (lstn *DiameterListener) AsMapInterface() map[string]any {
|
||||
return map[string]any{
|
||||
utils.NetworkCfg: lstn.Network,
|
||||
utils.AddressCfg: lstn.Address,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// AsMapInterface returns the config as a map[string]any
|
||||
func (da *DiameterAgentCfg) AsMapInterface(separator string) map[string]any {
|
||||
listeners := make([]map[string]any, len(da.Listeners))
|
||||
for i, item := range da.Listeners {
|
||||
listeners[i] = item.AsMapInterface()
|
||||
}
|
||||
m := map[string]any{
|
||||
utils.EnabledCfg: da.Enabled,
|
||||
utils.ListenNetCfg: da.ListenNet,
|
||||
utils.ListenCfg: da.Listen,
|
||||
utils.ListenersCfg: listeners,
|
||||
utils.DictionariesPathCfg: da.DictionariesPath,
|
||||
utils.OriginHostCfg: da.OriginHost,
|
||||
utils.OriginRealmCfg: da.OriginRealm,
|
||||
@@ -198,8 +221,7 @@ func (da *DiameterAgentCfg) AsMapInterface(separator string) map[string]any {
|
||||
func (da DiameterAgentCfg) Clone() *DiameterAgentCfg {
|
||||
clone := &DiameterAgentCfg{
|
||||
Enabled: da.Enabled,
|
||||
ListenNet: da.ListenNet,
|
||||
Listen: da.Listen,
|
||||
Listeners: slices.Clone(da.Listeners),
|
||||
DictionariesPath: da.DictionariesPath,
|
||||
CeApplications: slices.Clone(da.CeApplications),
|
||||
SessionSConns: slices.Clone(da.SessionSConns),
|
||||
|
||||
@@ -27,9 +27,12 @@ import (
|
||||
|
||||
func TestDiameterAgentCfgloadFromJsonCfg(t *testing.T) {
|
||||
jsonCFG := &DiameterAgentJsonCfg{
|
||||
Enabled: utils.BoolPointer(true),
|
||||
ListenNet: utils.StringPointer("tcp"),
|
||||
Listen: utils.StringPointer("127.0.0.1:3868"),
|
||||
Enabled: utils.BoolPointer(true),
|
||||
Listeners: &[]*DiamListenerJsnCfg{
|
||||
{Network: utils.StringPointer("tcp"),
|
||||
Address: utils.StringPointer("127.0.0.1:3868")},
|
||||
},
|
||||
|
||||
CeApplications: utils.SliceStringPointer([]string{"Base"}),
|
||||
DictionariesPath: utils.StringPointer("/usr/share/cgrates/diameter/dict/"),
|
||||
SessionSConns: &[]string{utils.MetaInternal, "*conn1"},
|
||||
@@ -51,9 +54,14 @@ func TestDiameterAgentCfgloadFromJsonCfg(t *testing.T) {
|
||||
},
|
||||
}
|
||||
expected := &DiameterAgentCfg{
|
||||
Enabled: true,
|
||||
ListenNet: "tcp",
|
||||
Listen: "127.0.0.1:3868",
|
||||
Enabled: true,
|
||||
Listeners: []DiameterListener{
|
||||
{
|
||||
Network: "tcp",
|
||||
Address: "127.0.0.1:3868",
|
||||
},
|
||||
},
|
||||
|
||||
CeApplications: []string{"Base"},
|
||||
DictionariesPath: "/usr/share/cgrates/diameter/dict/",
|
||||
SessionSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS), "*conn1"},
|
||||
@@ -157,13 +165,17 @@ func TestDiameterAgentCfgAsMapInterface(t *testing.T) {
|
||||
},
|
||||
}`
|
||||
eMap := map[string]any{
|
||||
utils.ASRTemplateCfg: "",
|
||||
utils.CeApplicationsCfg: []string{"Base"},
|
||||
utils.DictionariesPathCfg: "/usr/share/cgrates/diameter/dict/",
|
||||
utils.EnabledCfg: false,
|
||||
utils.ForcedDisconnectCfg: "*none",
|
||||
utils.ListenCfg: "127.0.0.1:3868",
|
||||
utils.ListenNetCfg: "tcp",
|
||||
utils.ASRTemplateCfg: "",
|
||||
utils.CeApplicationsCfg: []string{"Base"},
|
||||
utils.DictionariesPathCfg: "/usr/share/cgrates/diameter/dict/",
|
||||
utils.EnabledCfg: false,
|
||||
utils.ForcedDisconnectCfg: "*none",
|
||||
utils.ListenersCfg: []map[string]any{
|
||||
{
|
||||
utils.AddressCfg: "127.0.0.1:3868",
|
||||
utils.NetworkCfg: "tcp",
|
||||
},
|
||||
},
|
||||
utils.OriginHostCfg: "CGR-DA",
|
||||
utils.OriginRealmCfg: "cgrates.org",
|
||||
utils.ProductNameCfg: "CGRateS",
|
||||
@@ -228,13 +240,17 @@ func TestDiameterAgentCfgAsMapInterface1(t *testing.T) {
|
||||
},
|
||||
}`
|
||||
eMap := map[string]any{
|
||||
utils.ASRTemplateCfg: "",
|
||||
utils.CeApplicationsCfg: []string{"Nokia.4"},
|
||||
utils.DictionariesPathCfg: "/usr/share/cgrates/diameter",
|
||||
utils.EnabledCfg: true,
|
||||
utils.ForcedDisconnectCfg: "*none",
|
||||
utils.ListenCfg: "127.0.0.1:3868",
|
||||
utils.ListenNetCfg: "tcp",
|
||||
utils.ASRTemplateCfg: "",
|
||||
utils.CeApplicationsCfg: []string{"Nokia.4"},
|
||||
utils.DictionariesPathCfg: "/usr/share/cgrates/diameter",
|
||||
utils.EnabledCfg: true,
|
||||
utils.ForcedDisconnectCfg: "*none",
|
||||
utils.ListenersCfg: []map[string]any{
|
||||
{
|
||||
utils.AddressCfg: "127.0.0.1:3868",
|
||||
utils.NetworkCfg: "tcp",
|
||||
},
|
||||
},
|
||||
utils.OriginHostCfg: "CGR-DA",
|
||||
utils.OriginRealmCfg: "cgrates.org",
|
||||
utils.ProductNameCfg: "CGRateS",
|
||||
@@ -258,9 +274,11 @@ func TestDiameterAgentCfgAsMapInterface1(t *testing.T) {
|
||||
|
||||
func TestDiameterAgentCfgClone(t *testing.T) {
|
||||
ban := &DiameterAgentCfg{
|
||||
Enabled: true,
|
||||
ListenNet: "tcp",
|
||||
Listen: "127.0.0.1:3868",
|
||||
Enabled: true,
|
||||
Listeners: []DiameterListener{
|
||||
{Network: "tcp",
|
||||
Address: "127.0.0.1:3868"},
|
||||
},
|
||||
CeApplications: []string{"Base"},
|
||||
DictionariesPath: "/usr/share/cgrates/diameter/dict/",
|
||||
SessionSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS), "*conn1"},
|
||||
|
||||
@@ -557,11 +557,15 @@ type OsipsConnJsonCfg struct {
|
||||
Reconnects *int
|
||||
}
|
||||
|
||||
type DiamListenerJsnCfg struct {
|
||||
Address *string `json:"address"`
|
||||
Network *string `json:"network"`
|
||||
}
|
||||
|
||||
// DiameterAgent configuration
|
||||
type DiameterAgentJsonCfg struct {
|
||||
Enabled *bool `json:"enabled"`
|
||||
Listen *string `json:"listen"`
|
||||
ListenNet *string `json:"listen_net"`
|
||||
Listeners *[]*DiamListenerJsnCfg `json:"listeners"`
|
||||
DictionariesPath *string `json:"dictionaries_path"`
|
||||
CeApplications *[]string `json:"ce_applications"`
|
||||
SessionSConns *[]string `json:"sessions_conns"`
|
||||
|
||||
Reference in New Issue
Block a user