mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
cfg: add stats/thresholds_conns to diameter_agent
This commit is contained in:
committed by
Dan Christian Bogos
parent
3c11cddb0d
commit
7264957fee
@@ -1022,6 +1022,8 @@ const CGRATES_CFG_JSON = `
|
||||
"listen_net": "tcp", // transport type for diameter <tcp|sctp>
|
||||
"dictionaries_path": "/usr/share/cgrates/diameter/dict/", // path towards directory holding additional dictionaries to load
|
||||
"sessions_conns": ["*birpc_internal"],
|
||||
"stats_conns": [], // connections to StatS, empty to disable: <""|*internal|$rpc_conns_id>
|
||||
"thresholds_conns": [], // connections to ThresholdS, empty to disable: <""|*internal|$rpc_conns_id>
|
||||
"origin_host": "CGR-DA", // diameter Origin-Host AVP used in replies
|
||||
"origin_realm": "cgrates.org", // diameter Origin-Realm AVP used in replies
|
||||
"vendor_id": 0, // diameter Vendor-Id AVP used in replies
|
||||
|
||||
@@ -730,20 +730,22 @@ func TestAsteriskAgentJsonCfg(t *testing.T) {
|
||||
|
||||
func TestDiameterAgentJsonCfg(t *testing.T) {
|
||||
eCfg := &DiameterAgentJsonCfg{
|
||||
Enabled: utils.BoolPointer(false),
|
||||
Listen: utils.StringPointer("127.0.0.1:3868"),
|
||||
Listen_net: utils.StringPointer(utils.TCP),
|
||||
Dictionaries_path: utils.StringPointer("/usr/share/cgrates/diameter/dict/"),
|
||||
Sessions_conns: &[]string{rpcclient.BiRPCInternal},
|
||||
Origin_host: utils.StringPointer("CGR-DA"),
|
||||
Origin_realm: utils.StringPointer("cgrates.org"),
|
||||
Vendor_id: utils.IntPointer(0),
|
||||
Product_name: utils.StringPointer("CGRateS"),
|
||||
Synced_conn_requests: utils.BoolPointer(false),
|
||||
Asr_template: utils.StringPointer(""),
|
||||
Rar_template: utils.StringPointer(""),
|
||||
Forced_disconnect: utils.StringPointer(utils.MetaNone),
|
||||
Request_processors: &[]*ReqProcessorJsnCfg{},
|
||||
Enabled: utils.BoolPointer(false),
|
||||
Listen: utils.StringPointer("127.0.0.1:3868"),
|
||||
ListenNet: utils.StringPointer(utils.TCP),
|
||||
DictionariesPath: utils.StringPointer("/usr/share/cgrates/diameter/dict/"),
|
||||
SessionSConns: &[]string{rpcclient.BiRPCInternal},
|
||||
StatSConns: &[]string{},
|
||||
ThresholdSConns: &[]string{},
|
||||
OriginHost: utils.StringPointer("CGR-DA"),
|
||||
OriginRealm: utils.StringPointer("cgrates.org"),
|
||||
VendorID: utils.IntPointer(0),
|
||||
ProductName: utils.StringPointer("CGRateS"),
|
||||
SyncedConnRequests: utils.BoolPointer(false),
|
||||
ASRTemplate: utils.StringPointer(""),
|
||||
RARTemplate: utils.StringPointer(""),
|
||||
ForcedDisconnect: utils.StringPointer(utils.MetaNone),
|
||||
RequestProcessors: &[]*ReqProcessorJsnCfg{},
|
||||
}
|
||||
dfCgrJSONCfg, err := NewCgrJsonCfgFromBytes([]byte(CGRATES_CFG_JSON))
|
||||
if err != nil {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -282,6 +282,24 @@ func (cfg *CGRConfig) checkConfigSanity() error {
|
||||
return fmt.Errorf("<%s> connection with id: <%s> not defined", utils.DiameterAgent, connID)
|
||||
}
|
||||
}
|
||||
for _, connID := range cfg.diameterAgentCfg.StatSConns {
|
||||
isInternal := strings.HasPrefix(connID, utils.MetaInternal) || strings.HasPrefix(connID, rpcclient.BiRPCInternal)
|
||||
if isInternal && !cfg.statsCfg.Enabled {
|
||||
return fmt.Errorf("<%s> not enabled but requested by <%s> component", utils.StatS, utils.DiameterAgent)
|
||||
}
|
||||
if _, has := cfg.rpcConns[connID]; !has && !isInternal {
|
||||
return fmt.Errorf("<%s> connection with id: <%s> not defined", utils.DiameterAgent, connID)
|
||||
}
|
||||
}
|
||||
for _, connID := range cfg.diameterAgentCfg.ThresholdSConns {
|
||||
isInternal := strings.HasPrefix(connID, utils.MetaInternal) || strings.HasPrefix(connID, rpcclient.BiRPCInternal)
|
||||
if isInternal && !cfg.thresholdSCfg.Enabled {
|
||||
return fmt.Errorf("<%s> not enabled but requested by <%s> component", utils.ThresholdS, utils.DiameterAgent)
|
||||
}
|
||||
if _, has := cfg.rpcConns[connID]; !has && !isInternal {
|
||||
return fmt.Errorf("<%s> connection with id: <%s> not defined", utils.DiameterAgent, connID)
|
||||
}
|
||||
}
|
||||
for prf, tmp := range cfg.templates {
|
||||
for _, field := range tmp {
|
||||
if field.Type != utils.MetaNone && field.Path == utils.EmptyString {
|
||||
|
||||
239
config/diameter.go
Normal file
239
config/diameter.go
Normal file
@@ -0,0 +1,239 @@
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
// 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>
|
||||
DictionariesPath string
|
||||
SessionSConns []string
|
||||
StatSConns []string
|
||||
ThresholdSConns []string
|
||||
OriginHost string
|
||||
OriginRealm string
|
||||
VendorID int
|
||||
ProductName string
|
||||
SyncedConnReqs bool
|
||||
ASRTemplate string
|
||||
RARTemplate string
|
||||
ForcedDisconnect string
|
||||
RequestProcessors []*RequestProcessor
|
||||
}
|
||||
|
||||
// loadDiameterAgentCfg loads the DiameterAgent section of the configuration
|
||||
func (da *DiameterAgentCfg) Load(ctx *context.Context, jsnCfg ConfigDB, cfg *CGRConfig) (err error) {
|
||||
jsnDACfg := new(DiameterAgentJsonCfg)
|
||||
if err = jsnCfg.GetSection(ctx, DiameterAgentJSON, jsnDACfg); err != nil {
|
||||
return
|
||||
}
|
||||
return da.loadFromJSONCfg(jsnDACfg)
|
||||
}
|
||||
|
||||
func (da *DiameterAgentCfg) loadFromJSONCfg(jsnCfg *DiameterAgentJsonCfg) (err error) {
|
||||
if jsnCfg == nil {
|
||||
return nil
|
||||
}
|
||||
if jsnCfg.Enabled != nil {
|
||||
da.Enabled = *jsnCfg.Enabled
|
||||
}
|
||||
if jsnCfg.Listen != nil {
|
||||
da.Listen = *jsnCfg.Listen
|
||||
}
|
||||
if jsnCfg.ListenNet != nil {
|
||||
da.ListenNet = *jsnCfg.ListenNet
|
||||
}
|
||||
if jsnCfg.DictionariesPath != nil {
|
||||
da.DictionariesPath = *jsnCfg.DictionariesPath
|
||||
}
|
||||
if jsnCfg.SessionSConns != nil {
|
||||
da.SessionSConns = updateBiRPCInternalConns(*jsnCfg.SessionSConns, utils.MetaSessionS)
|
||||
}
|
||||
if jsnCfg.StatSConns != nil {
|
||||
da.StatSConns = updateBiRPCInternalConns(*jsnCfg.StatSConns, utils.MetaStats)
|
||||
}
|
||||
if jsnCfg.ThresholdSConns != nil {
|
||||
da.ThresholdSConns = updateBiRPCInternalConns(*jsnCfg.ThresholdSConns, utils.MetaThresholds)
|
||||
}
|
||||
if jsnCfg.OriginHost != nil {
|
||||
da.OriginHost = *jsnCfg.OriginHost
|
||||
}
|
||||
if jsnCfg.OriginRealm != nil {
|
||||
da.OriginRealm = *jsnCfg.OriginRealm
|
||||
}
|
||||
if jsnCfg.VendorID != nil {
|
||||
da.VendorID = *jsnCfg.VendorID
|
||||
}
|
||||
if jsnCfg.ProductName != nil {
|
||||
da.ProductName = *jsnCfg.ProductName
|
||||
}
|
||||
if jsnCfg.SyncedConnRequests != nil {
|
||||
da.SyncedConnReqs = *jsnCfg.SyncedConnRequests
|
||||
}
|
||||
if jsnCfg.ASRTemplate != nil {
|
||||
da.ASRTemplate = *jsnCfg.ASRTemplate
|
||||
}
|
||||
if jsnCfg.RARTemplate != nil {
|
||||
da.RARTemplate = *jsnCfg.RARTemplate
|
||||
}
|
||||
if jsnCfg.ForcedDisconnect != nil {
|
||||
da.ForcedDisconnect = *jsnCfg.ForcedDisconnect
|
||||
}
|
||||
da.RequestProcessors, err = appendRequestProcessors(da.RequestProcessors, jsnCfg.RequestProcessors)
|
||||
return
|
||||
}
|
||||
|
||||
// AsMapInterface returns the config as a map[string]any
|
||||
func (da DiameterAgentCfg) AsMapInterface() any {
|
||||
requestProcessors := make([]map[string]any, len(da.RequestProcessors))
|
||||
for i, item := range da.RequestProcessors {
|
||||
requestProcessors[i] = item.AsMapInterface()
|
||||
}
|
||||
mp := map[string]any{
|
||||
utils.EnabledCfg: da.Enabled,
|
||||
utils.ListenNetCfg: da.ListenNet,
|
||||
utils.ListenCfg: da.Listen,
|
||||
utils.DictionariesPathCfg: da.DictionariesPath,
|
||||
utils.SessionSConnsCfg: getBiRPCInternalJSONConns(da.SessionSConns),
|
||||
utils.StatSConnsCfg: getBiRPCInternalJSONConns(da.StatSConns),
|
||||
utils.ThresholdSConnsCfg: getBiRPCInternalJSONConns(da.ThresholdSConns),
|
||||
utils.OriginHostCfg: da.OriginHost,
|
||||
utils.OriginRealmCfg: da.OriginRealm,
|
||||
utils.VendorIDCfg: da.VendorID,
|
||||
utils.ProductNameCfg: da.ProductName,
|
||||
utils.SyncedConnReqsCfg: da.SyncedConnReqs,
|
||||
utils.ASRTemplateCfg: da.ASRTemplate,
|
||||
utils.RARTemplateCfg: da.RARTemplate,
|
||||
utils.ForcedDisconnectCfg: da.ForcedDisconnect,
|
||||
utils.RequestProcessorsCfg: requestProcessors,
|
||||
}
|
||||
return mp
|
||||
}
|
||||
|
||||
func (DiameterAgentCfg) SName() string { return DiameterAgentJSON }
|
||||
func (da DiameterAgentCfg) CloneSection() Section { return da.Clone() }
|
||||
|
||||
// Clone returns a deep copy of DiameterAgentCfg
|
||||
func (da DiameterAgentCfg) Clone() *DiameterAgentCfg {
|
||||
clone := &DiameterAgentCfg{
|
||||
Enabled: da.Enabled,
|
||||
ListenNet: da.ListenNet,
|
||||
Listen: da.Listen,
|
||||
DictionariesPath: da.DictionariesPath,
|
||||
SessionSConns: slices.Clone(da.SessionSConns),
|
||||
StatSConns: slices.Clone(da.StatSConns),
|
||||
ThresholdSConns: slices.Clone(da.ThresholdSConns),
|
||||
OriginHost: da.OriginHost,
|
||||
OriginRealm: da.OriginRealm,
|
||||
VendorID: da.VendorID,
|
||||
ProductName: da.ProductName,
|
||||
SyncedConnReqs: da.SyncedConnReqs,
|
||||
ASRTemplate: da.ASRTemplate,
|
||||
RARTemplate: da.RARTemplate,
|
||||
ForcedDisconnect: da.ForcedDisconnect,
|
||||
}
|
||||
if da.RequestProcessors != nil {
|
||||
clone.RequestProcessors = make([]*RequestProcessor, len(da.RequestProcessors))
|
||||
for i, req := range da.RequestProcessors {
|
||||
clone.RequestProcessors[i] = req.Clone()
|
||||
}
|
||||
}
|
||||
return clone
|
||||
}
|
||||
|
||||
// DiameterAgent configuration
|
||||
type DiameterAgentJsonCfg struct {
|
||||
Enabled *bool `json:"enabled"`
|
||||
Listen *string `json:"listen"`
|
||||
ListenNet *string `json:"listen_net"`
|
||||
DictionariesPath *string `json:"dictionaries_path"`
|
||||
SessionSConns *[]string `json:"sessions_conns"`
|
||||
StatSConns *[]string `json:"stats_conns"`
|
||||
ThresholdSConns *[]string `json:"thresholds_conns"`
|
||||
OriginHost *string `json:"origin_host"`
|
||||
OriginRealm *string `json:"origin_realm"`
|
||||
VendorID *int `json:"vendor_id"`
|
||||
ProductName *string `json:"product_name"`
|
||||
SyncedConnRequests *bool `json:"synced_conn_requests"`
|
||||
ASRTemplate *string `json:"asr_template"`
|
||||
RARTemplate *string `json:"rar_template"`
|
||||
ForcedDisconnect *string `json:"forced_disconnect"`
|
||||
RequestProcessors *[]*ReqProcessorJsnCfg `json:"request_processors"`
|
||||
}
|
||||
|
||||
func diffDiameterAgentJsonCfg(d *DiameterAgentJsonCfg, v1, v2 *DiameterAgentCfg) *DiameterAgentJsonCfg {
|
||||
if d == nil {
|
||||
d = new(DiameterAgentJsonCfg)
|
||||
}
|
||||
if v1.Enabled != v2.Enabled {
|
||||
d.Enabled = utils.BoolPointer(v2.Enabled)
|
||||
}
|
||||
if v1.ListenNet != v2.ListenNet {
|
||||
d.ListenNet = utils.StringPointer(v2.ListenNet)
|
||||
}
|
||||
if v1.Listen != v2.Listen {
|
||||
d.Listen = utils.StringPointer(v2.Listen)
|
||||
}
|
||||
if v1.DictionariesPath != v2.DictionariesPath {
|
||||
d.DictionariesPath = utils.StringPointer(v2.DictionariesPath)
|
||||
}
|
||||
if !slices.Equal(v1.SessionSConns, v2.SessionSConns) {
|
||||
d.SessionSConns = utils.SliceStringPointer(getBiRPCInternalJSONConns(v2.SessionSConns))
|
||||
}
|
||||
if !slices.Equal(v1.StatSConns, v2.StatSConns) {
|
||||
d.StatSConns = utils.SliceStringPointer(getBiRPCInternalJSONConns(v2.StatSConns))
|
||||
}
|
||||
if !slices.Equal(v1.ThresholdSConns, v2.ThresholdSConns) {
|
||||
d.ThresholdSConns = utils.SliceStringPointer(getBiRPCInternalJSONConns(v2.ThresholdSConns))
|
||||
}
|
||||
if v1.OriginHost != v2.OriginHost {
|
||||
d.OriginHost = utils.StringPointer(v2.OriginHost)
|
||||
}
|
||||
if v1.OriginRealm != v2.OriginRealm {
|
||||
d.OriginRealm = utils.StringPointer(v2.OriginRealm)
|
||||
}
|
||||
if v1.VendorID != v2.VendorID {
|
||||
d.VendorID = utils.IntPointer(v2.VendorID)
|
||||
}
|
||||
if v1.ProductName != v2.ProductName {
|
||||
d.ProductName = utils.StringPointer(v2.ProductName)
|
||||
}
|
||||
if v1.SyncedConnReqs != v2.SyncedConnReqs {
|
||||
d.SyncedConnRequests = utils.BoolPointer(v2.SyncedConnReqs)
|
||||
}
|
||||
if v1.ASRTemplate != v2.ASRTemplate {
|
||||
d.ASRTemplate = utils.StringPointer(v2.ASRTemplate)
|
||||
}
|
||||
if v1.RARTemplate != v2.RARTemplate {
|
||||
d.RARTemplate = utils.StringPointer(v2.RARTemplate)
|
||||
}
|
||||
if v1.ForcedDisconnect != v2.ForcedDisconnect {
|
||||
d.ForcedDisconnect = utils.StringPointer(v2.ForcedDisconnect)
|
||||
}
|
||||
d.RequestProcessors = diffReqProcessorsJsnCfg(d.RequestProcessors, v1.RequestProcessors, v2.RequestProcessors)
|
||||
return d
|
||||
}
|
||||
@@ -27,20 +27,22 @@ import (
|
||||
|
||||
func TestDiameterAgentCfgloadFromJsonCfg(t *testing.T) {
|
||||
jsonCFG := &DiameterAgentJsonCfg{
|
||||
Enabled: utils.BoolPointer(true),
|
||||
Listen_net: utils.StringPointer("tcp"),
|
||||
Listen: utils.StringPointer("127.0.0.1:3868"),
|
||||
Dictionaries_path: utils.StringPointer("/usr/share/cgrates/diameter/dict/"),
|
||||
Sessions_conns: &[]string{utils.MetaInternal, "*conn1"},
|
||||
Origin_host: utils.StringPointer("CGR-DA"),
|
||||
Origin_realm: utils.StringPointer("cgrates.org"),
|
||||
Vendor_id: utils.IntPointer(0),
|
||||
Product_name: utils.StringPointer("randomName"),
|
||||
Synced_conn_requests: utils.BoolPointer(true),
|
||||
Asr_template: utils.StringPointer("randomTemplate"),
|
||||
Rar_template: utils.StringPointer("randomTemplate"),
|
||||
Forced_disconnect: utils.StringPointer("forced"),
|
||||
Request_processors: &[]*ReqProcessorJsnCfg{
|
||||
Enabled: utils.BoolPointer(true),
|
||||
ListenNet: utils.StringPointer("tcp"),
|
||||
Listen: utils.StringPointer("127.0.0.1:3868"),
|
||||
DictionariesPath: utils.StringPointer("/usr/share/cgrates/diameter/dict/"),
|
||||
SessionSConns: &[]string{utils.MetaInternal, "*conn1"},
|
||||
StatSConns: &[]string{utils.MetaInternal, "*conn1"},
|
||||
ThresholdSConns: &[]string{utils.MetaInternal, "*conn1"},
|
||||
OriginHost: utils.StringPointer("CGR-DA"),
|
||||
OriginRealm: utils.StringPointer("cgrates.org"),
|
||||
VendorID: utils.IntPointer(0),
|
||||
ProductName: utils.StringPointer("randomName"),
|
||||
SyncedConnRequests: utils.BoolPointer(true),
|
||||
ASRTemplate: utils.StringPointer("randomTemplate"),
|
||||
RARTemplate: utils.StringPointer("randomTemplate"),
|
||||
ForcedDisconnect: utils.StringPointer("forced"),
|
||||
RequestProcessors: &[]*ReqProcessorJsnCfg{
|
||||
{
|
||||
ID: utils.StringPointer(utils.CGRateSLwr),
|
||||
Timezone: utils.StringPointer("Local"),
|
||||
@@ -53,6 +55,8 @@ func TestDiameterAgentCfgloadFromJsonCfg(t *testing.T) {
|
||||
Listen: "127.0.0.1:3868",
|
||||
DictionariesPath: "/usr/share/cgrates/diameter/dict/",
|
||||
SessionSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS), "*conn1"},
|
||||
StatSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats), "*conn1"},
|
||||
ThresholdSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds), "*conn1"},
|
||||
OriginHost: "CGR-DA",
|
||||
OriginRealm: "cgrates.org",
|
||||
VendorID: 0,
|
||||
@@ -83,7 +87,7 @@ func TestDiameterAgentCfgloadFromJsonCfg(t *testing.T) {
|
||||
|
||||
func TestRequestProcessorloadFromJsonCfg1(t *testing.T) {
|
||||
cfgJSON := &DiameterAgentJsonCfg{
|
||||
Request_processors: &[]*ReqProcessorJsnCfg{
|
||||
RequestProcessors: &[]*ReqProcessorJsnCfg{
|
||||
{
|
||||
Tenant: utils.StringPointer("a{*"),
|
||||
},
|
||||
@@ -107,7 +111,7 @@ func TestRequestProcessorloadFromJsonCfg2(t *testing.T) {
|
||||
}
|
||||
}`
|
||||
cfgJSON := &DiameterAgentJsonCfg{
|
||||
Request_processors: &[]*ReqProcessorJsnCfg{
|
||||
RequestProcessors: &[]*ReqProcessorJsnCfg{
|
||||
{
|
||||
ID: utils.StringPointer("random"),
|
||||
},
|
||||
@@ -127,6 +131,8 @@ func TestDiameterAgentCfgAsMapInterface(t *testing.T) {
|
||||
"listen": "127.0.0.1:3868",
|
||||
"dictionaries_path": "/usr/share/cgrates/diameter/dict/",
|
||||
"sessions_conns": ["*birpc_internal","*internal", "*conn1"],
|
||||
"stats_conns": ["*birpc_internal","*internal", "*conn1"],
|
||||
"thresholds_conns": ["*birpc_internal","*internal", "*conn1"],
|
||||
"origin_host": "CGR-DA",
|
||||
"origin_realm": "cgrates.org",
|
||||
"vendor_id": 0,
|
||||
@@ -160,6 +166,8 @@ func TestDiameterAgentCfgAsMapInterface(t *testing.T) {
|
||||
utils.ProductNameCfg: "CGRateS",
|
||||
utils.RARTemplateCfg: "",
|
||||
utils.SessionSConnsCfg: []string{rpcclient.BiRPCInternal, utils.MetaInternal, "*conn1"},
|
||||
utils.StatSConnsCfg: []string{rpcclient.BiRPCInternal, utils.MetaInternal, "*conn1"},
|
||||
utils.ThresholdSConnsCfg: []string{rpcclient.BiRPCInternal, utils.MetaInternal, "*conn1"},
|
||||
utils.SyncedConnReqsCfg: true,
|
||||
utils.VendorIDCfg: 0,
|
||||
utils.RequestProcessorsCfg: []map[string]any{
|
||||
@@ -220,6 +228,8 @@ func TestDiameterAgentCfgAsMapInterface1(t *testing.T) {
|
||||
utils.ProductNameCfg: "CGRateS",
|
||||
utils.RARTemplateCfg: "",
|
||||
utils.SessionSConnsCfg: []string{rpcclient.BiRPCInternal},
|
||||
utils.StatSConnsCfg: []string{},
|
||||
utils.ThresholdSConnsCfg: []string{},
|
||||
utils.SyncedConnReqsCfg: false,
|
||||
utils.VendorIDCfg: 0,
|
||||
utils.RequestProcessorsCfg: []map[string]any{},
|
||||
@@ -238,6 +248,8 @@ func TestDiameterAgentCfgClone(t *testing.T) {
|
||||
Listen: "127.0.0.1:3868",
|
||||
DictionariesPath: "/usr/share/cgrates/diameter/dict/",
|
||||
SessionSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS), "*conn1"},
|
||||
StatSConns: []string{},
|
||||
ThresholdSConns: []string{},
|
||||
OriginHost: "CGR-DA",
|
||||
OriginRealm: "cgrates.org",
|
||||
VendorID: 0,
|
||||
@@ -274,6 +286,8 @@ func TestDiffDiameterAgentJsonCfg(t *testing.T) {
|
||||
Listen: "localhost:8080",
|
||||
DictionariesPath: "/path/",
|
||||
SessionSConns: []string{"*localhost"},
|
||||
StatSConns: []string{"*localhost"},
|
||||
ThresholdSConns: []string{"*localhost"},
|
||||
OriginHost: "originHost",
|
||||
OriginRealm: "originRealm",
|
||||
VendorID: 2,
|
||||
@@ -290,7 +304,9 @@ func TestDiffDiameterAgentJsonCfg(t *testing.T) {
|
||||
ListenNet: "udp",
|
||||
Listen: "localhost:8037",
|
||||
DictionariesPath: "/path/different",
|
||||
SessionSConns: []string{"*birpc"},
|
||||
SessionSConns: []string{"*birpc_internal"},
|
||||
StatSConns: []string{"*internal"},
|
||||
ThresholdSConns: []string{"*internal"},
|
||||
OriginHost: "diffOriginHost",
|
||||
OriginRealm: "diffOriginRealm",
|
||||
VendorID: 5,
|
||||
@@ -307,20 +323,22 @@ func TestDiffDiameterAgentJsonCfg(t *testing.T) {
|
||||
}
|
||||
|
||||
expected := &DiameterAgentJsonCfg{
|
||||
Enabled: utils.BoolPointer(true),
|
||||
Listen_net: utils.StringPointer("udp"),
|
||||
Listen: utils.StringPointer("localhost:8037"),
|
||||
Dictionaries_path: utils.StringPointer("/path/different"),
|
||||
Sessions_conns: &[]string{"*birpc"},
|
||||
Origin_host: utils.StringPointer("diffOriginHost"),
|
||||
Origin_realm: utils.StringPointer("diffOriginRealm"),
|
||||
Vendor_id: utils.IntPointer(5),
|
||||
Product_name: utils.StringPointer("diffProductName"),
|
||||
Synced_conn_requests: utils.BoolPointer(true),
|
||||
Asr_template: utils.StringPointer("diffASRTemplate"),
|
||||
Rar_template: utils.StringPointer("diffRARTemplate"),
|
||||
Forced_disconnect: utils.StringPointer("diffForcedDisconnect"),
|
||||
Request_processors: &[]*ReqProcessorJsnCfg{
|
||||
Enabled: utils.BoolPointer(true),
|
||||
ListenNet: utils.StringPointer("udp"),
|
||||
Listen: utils.StringPointer("localhost:8037"),
|
||||
DictionariesPath: utils.StringPointer("/path/different"),
|
||||
SessionSConns: &[]string{"*birpc_internal"},
|
||||
StatSConns: &[]string{"*internal"},
|
||||
ThresholdSConns: &[]string{"*internal"},
|
||||
OriginHost: utils.StringPointer("diffOriginHost"),
|
||||
OriginRealm: utils.StringPointer("diffOriginRealm"),
|
||||
VendorID: utils.IntPointer(5),
|
||||
ProductName: utils.StringPointer("diffProductName"),
|
||||
SyncedConnRequests: utils.BoolPointer(true),
|
||||
ASRTemplate: utils.StringPointer("diffASRTemplate"),
|
||||
RARTemplate: utils.StringPointer("diffRARTemplate"),
|
||||
ForcedDisconnect: utils.StringPointer("diffForcedDisconnect"),
|
||||
RequestProcessors: &[]*ReqProcessorJsnCfg{
|
||||
{
|
||||
ID: utils.StringPointer("id"),
|
||||
},
|
||||
@@ -334,7 +352,7 @@ func TestDiffDiameterAgentJsonCfg(t *testing.T) {
|
||||
|
||||
v1 = v2
|
||||
expected = &DiameterAgentJsonCfg{
|
||||
Request_processors: &[]*ReqProcessorJsnCfg{
|
||||
RequestProcessors: &[]*ReqProcessorJsnCfg{
|
||||
{},
|
||||
},
|
||||
}
|
||||
@@ -1,225 +0,0 @@
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
// 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>
|
||||
DictionariesPath string
|
||||
SessionSConns []string
|
||||
OriginHost string
|
||||
OriginRealm string
|
||||
VendorID int
|
||||
ProductName string
|
||||
SyncedConnReqs bool
|
||||
ASRTemplate string
|
||||
RARTemplate string
|
||||
ForcedDisconnect string
|
||||
RequestProcessors []*RequestProcessor
|
||||
}
|
||||
|
||||
// loadDiameterAgentCfg loads the DiameterAgent section of the configuration
|
||||
func (da *DiameterAgentCfg) Load(ctx *context.Context, jsnCfg ConfigDB, cfg *CGRConfig) (err error) {
|
||||
jsnDACfg := new(DiameterAgentJsonCfg)
|
||||
if err = jsnCfg.GetSection(ctx, DiameterAgentJSON, jsnDACfg); err != nil {
|
||||
return
|
||||
}
|
||||
return da.loadFromJSONCfg(jsnDACfg)
|
||||
}
|
||||
|
||||
func (da *DiameterAgentCfg) loadFromJSONCfg(jsnCfg *DiameterAgentJsonCfg) (err error) {
|
||||
if jsnCfg == nil {
|
||||
return nil
|
||||
}
|
||||
if jsnCfg.Enabled != nil {
|
||||
da.Enabled = *jsnCfg.Enabled
|
||||
}
|
||||
if jsnCfg.Listen != nil {
|
||||
da.Listen = *jsnCfg.Listen
|
||||
}
|
||||
if jsnCfg.Listen_net != nil {
|
||||
da.ListenNet = *jsnCfg.Listen_net
|
||||
}
|
||||
if jsnCfg.Dictionaries_path != nil {
|
||||
da.DictionariesPath = *jsnCfg.Dictionaries_path
|
||||
}
|
||||
if jsnCfg.Sessions_conns != nil {
|
||||
da.SessionSConns = updateBiRPCInternalConns(*jsnCfg.Sessions_conns, utils.MetaSessionS)
|
||||
}
|
||||
if jsnCfg.Origin_host != nil {
|
||||
da.OriginHost = *jsnCfg.Origin_host
|
||||
}
|
||||
if jsnCfg.Origin_realm != nil {
|
||||
da.OriginRealm = *jsnCfg.Origin_realm
|
||||
}
|
||||
if jsnCfg.Vendor_id != nil {
|
||||
da.VendorID = *jsnCfg.Vendor_id
|
||||
}
|
||||
if jsnCfg.Product_name != nil {
|
||||
da.ProductName = *jsnCfg.Product_name
|
||||
}
|
||||
if jsnCfg.Synced_conn_requests != nil {
|
||||
da.SyncedConnReqs = *jsnCfg.Synced_conn_requests
|
||||
}
|
||||
if jsnCfg.Asr_template != nil {
|
||||
da.ASRTemplate = *jsnCfg.Asr_template
|
||||
}
|
||||
if jsnCfg.Rar_template != nil {
|
||||
da.RARTemplate = *jsnCfg.Rar_template
|
||||
}
|
||||
if jsnCfg.Forced_disconnect != nil {
|
||||
da.ForcedDisconnect = *jsnCfg.Forced_disconnect
|
||||
}
|
||||
da.RequestProcessors, err = appendRequestProcessors(da.RequestProcessors, jsnCfg.Request_processors)
|
||||
return
|
||||
}
|
||||
|
||||
// AsMapInterface returns the config as a map[string]any
|
||||
func (da DiameterAgentCfg) AsMapInterface() any {
|
||||
mp := map[string]any{
|
||||
utils.EnabledCfg: da.Enabled,
|
||||
utils.ListenNetCfg: da.ListenNet,
|
||||
utils.ListenCfg: da.Listen,
|
||||
utils.DictionariesPathCfg: da.DictionariesPath,
|
||||
utils.OriginHostCfg: da.OriginHost,
|
||||
utils.OriginRealmCfg: da.OriginRealm,
|
||||
utils.VendorIDCfg: da.VendorID,
|
||||
utils.ProductNameCfg: da.ProductName,
|
||||
utils.SyncedConnReqsCfg: da.SyncedConnReqs,
|
||||
utils.ASRTemplateCfg: da.ASRTemplate,
|
||||
utils.RARTemplateCfg: da.RARTemplate,
|
||||
utils.ForcedDisconnectCfg: da.ForcedDisconnect,
|
||||
}
|
||||
|
||||
requestProcessors := make([]map[string]any, len(da.RequestProcessors))
|
||||
for i, item := range da.RequestProcessors {
|
||||
requestProcessors[i] = item.AsMapInterface()
|
||||
}
|
||||
mp[utils.RequestProcessorsCfg] = requestProcessors
|
||||
|
||||
if da.SessionSConns != nil {
|
||||
mp[utils.SessionSConnsCfg] = getBiRPCInternalJSONConns(da.SessionSConns)
|
||||
}
|
||||
return mp
|
||||
}
|
||||
|
||||
func (DiameterAgentCfg) SName() string { return DiameterAgentJSON }
|
||||
func (da DiameterAgentCfg) CloneSection() Section { return da.Clone() }
|
||||
|
||||
// Clone returns a deep copy of DiameterAgentCfg
|
||||
func (da DiameterAgentCfg) Clone() (cln *DiameterAgentCfg) {
|
||||
cln = &DiameterAgentCfg{
|
||||
Enabled: da.Enabled,
|
||||
ListenNet: da.ListenNet,
|
||||
Listen: da.Listen,
|
||||
DictionariesPath: da.DictionariesPath,
|
||||
OriginHost: da.OriginHost,
|
||||
OriginRealm: da.OriginRealm,
|
||||
VendorID: da.VendorID,
|
||||
ProductName: da.ProductName,
|
||||
SyncedConnReqs: da.SyncedConnReqs,
|
||||
ASRTemplate: da.ASRTemplate,
|
||||
RARTemplate: da.RARTemplate,
|
||||
ForcedDisconnect: da.ForcedDisconnect,
|
||||
}
|
||||
if da.SessionSConns != nil {
|
||||
cln.SessionSConns = slices.Clone(da.SessionSConns)
|
||||
}
|
||||
if da.RequestProcessors != nil {
|
||||
cln.RequestProcessors = make([]*RequestProcessor, len(da.RequestProcessors))
|
||||
for i, req := range da.RequestProcessors {
|
||||
cln.RequestProcessors[i] = req.Clone()
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DiameterAgent configuration
|
||||
type DiameterAgentJsonCfg struct {
|
||||
Enabled *bool
|
||||
Listen *string
|
||||
Listen_net *string
|
||||
Dictionaries_path *string
|
||||
Sessions_conns *[]string
|
||||
Origin_host *string
|
||||
Origin_realm *string
|
||||
Vendor_id *int
|
||||
Product_name *string
|
||||
Synced_conn_requests *bool
|
||||
Asr_template *string
|
||||
Rar_template *string
|
||||
Forced_disconnect *string
|
||||
Request_processors *[]*ReqProcessorJsnCfg
|
||||
}
|
||||
|
||||
func diffDiameterAgentJsonCfg(d *DiameterAgentJsonCfg, v1, v2 *DiameterAgentCfg) *DiameterAgentJsonCfg {
|
||||
if d == nil {
|
||||
d = new(DiameterAgentJsonCfg)
|
||||
}
|
||||
if v1.Enabled != v2.Enabled {
|
||||
d.Enabled = utils.BoolPointer(v2.Enabled)
|
||||
}
|
||||
if v1.ListenNet != v2.ListenNet {
|
||||
d.Listen_net = utils.StringPointer(v2.ListenNet)
|
||||
}
|
||||
if v1.Listen != v2.Listen {
|
||||
d.Listen = utils.StringPointer(v2.Listen)
|
||||
}
|
||||
if v1.DictionariesPath != v2.DictionariesPath {
|
||||
d.Dictionaries_path = utils.StringPointer(v2.DictionariesPath)
|
||||
}
|
||||
if !slices.Equal(v1.SessionSConns, v2.SessionSConns) {
|
||||
d.Sessions_conns = utils.SliceStringPointer(getBiRPCInternalJSONConns(v2.SessionSConns))
|
||||
}
|
||||
if v1.OriginHost != v2.OriginHost {
|
||||
d.Origin_host = utils.StringPointer(v2.OriginHost)
|
||||
}
|
||||
if v1.OriginRealm != v2.OriginRealm {
|
||||
d.Origin_realm = utils.StringPointer(v2.OriginRealm)
|
||||
}
|
||||
if v1.VendorID != v2.VendorID {
|
||||
d.Vendor_id = utils.IntPointer(v2.VendorID)
|
||||
}
|
||||
if v1.ProductName != v2.ProductName {
|
||||
d.Product_name = utils.StringPointer(v2.ProductName)
|
||||
}
|
||||
if v1.SyncedConnReqs != v2.SyncedConnReqs {
|
||||
d.Synced_conn_requests = utils.BoolPointer(v2.SyncedConnReqs)
|
||||
}
|
||||
if v1.ASRTemplate != v2.ASRTemplate {
|
||||
d.Asr_template = utils.StringPointer(v2.ASRTemplate)
|
||||
}
|
||||
if v1.RARTemplate != v2.RARTemplate {
|
||||
d.Rar_template = utils.StringPointer(v2.RARTemplate)
|
||||
}
|
||||
if v1.ForcedDisconnect != v2.ForcedDisconnect {
|
||||
d.Forced_disconnect = utils.StringPointer(v2.ForcedDisconnect)
|
||||
}
|
||||
d.Request_processors = diffReqProcessorsJsnCfg(d.Request_processors, v1.RequestProcessors, v2.RequestProcessors)
|
||||
return d
|
||||
}
|
||||
Reference in New Issue
Block a user