mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
Add ability to modify diameter CE answer & replace go-diameter lib
This commit is contained in:
committed by
Dan Christian Bogos
parent
d04cf1df44
commit
83e8ce3adc
@@ -32,10 +32,10 @@ import (
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/go-diameter/diam"
|
||||
"github.com/cgrates/go-diameter/diam/avp"
|
||||
"github.com/cgrates/go-diameter/diam/datatype"
|
||||
"github.com/cgrates/radigo"
|
||||
"github.com/fiorix/go-diameter/v4/diam"
|
||||
"github.com/fiorix/go-diameter/v4/diam/avp"
|
||||
"github.com/fiorix/go-diameter/v4/diam/datatype"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
)
|
||||
|
||||
|
||||
@@ -31,11 +31,11 @@ import (
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/go-diameter/diam"
|
||||
"github.com/cgrates/go-diameter/diam/avp"
|
||||
"github.com/cgrates/go-diameter/diam/datatype"
|
||||
"github.com/cgrates/go-diameter/diam/dict"
|
||||
"github.com/cgrates/radigo"
|
||||
"github.com/fiorix/go-diameter/v4/diam"
|
||||
"github.com/fiorix/go-diameter/v4/diam/avp"
|
||||
"github.com/fiorix/go-diameter/v4/diam/datatype"
|
||||
"github.com/fiorix/go-diameter/v4/diam/dict"
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
|
||||
114
agents/diam_empty_ce_it_test.go
Normal file
114
agents/diam_empty_ce_it_test.go
Normal file
@@ -0,0 +1,114 @@
|
||||
//go:build integration
|
||||
// +build integration
|
||||
|
||||
/*
|
||||
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 agents
|
||||
|
||||
import (
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
daCfgPathND, diamConfigDIRND string
|
||||
daCfgND *config.CGRConfig
|
||||
diamClntND *DiameterClient
|
||||
|
||||
sTestsDiamND = []func(t *testing.T){
|
||||
testDiamEmptyCEItInitCfg,
|
||||
testDiamEmptyCEItDataDb,
|
||||
testDiamEmptyCEItResetStorDb,
|
||||
testDiamEmptyCEItStartEngine,
|
||||
testDiamEmptyCEItConnectDiameterClient,
|
||||
testDiamEmptyCEItKillEngine,
|
||||
}
|
||||
)
|
||||
|
||||
// Test start here
|
||||
func TestDiamEmptyCEItTcp(t *testing.T) {
|
||||
switch *utils.DBType {
|
||||
case utils.MetaInternal:
|
||||
diamConfigDIRND = "diamagent_internal_empty_apps"
|
||||
case utils.MetaMySQL, utils.MetaMongo, utils.MetaPostgres:
|
||||
t.SkipNow()
|
||||
default:
|
||||
t.Fatal("Unknown Database type")
|
||||
}
|
||||
for _, stest := range sTestsDiamND {
|
||||
t.Run(diamConfigDIRND, stest)
|
||||
}
|
||||
}
|
||||
|
||||
func testDiamEmptyCEItInitCfg(t *testing.T) {
|
||||
daCfgPathND = path.Join(*utils.DataDir, "conf", "samples", diamConfigDIRND)
|
||||
// Init config first
|
||||
var err error
|
||||
daCfgND, err = config.NewCGRConfigFromPath(daCfgPathND)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
daCfgND.DataFolderPath = *utils.DataDir // Share DataFolderPath through config towards StoreDb for Flush()
|
||||
rplyTimeout, _ = utils.ParseDurationWithSecs(*replyTimeout)
|
||||
if isDispatcherActive {
|
||||
daCfgND.ListenCfg().RPCJSONListen = ":6012"
|
||||
}
|
||||
}
|
||||
|
||||
// Remove data in both rating and accounting db
|
||||
func testDiamEmptyCEItDataDb(t *testing.T) {
|
||||
if err := engine.InitDataDb(daCfgND); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Wipe out the cdr database
|
||||
func testDiamEmptyCEItResetStorDb(t *testing.T) {
|
||||
if err := engine.InitStorDb(daCfgND); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Start CGR Engine
|
||||
func testDiamEmptyCEItStartEngine(t *testing.T) {
|
||||
if _, err := engine.StartEngine(daCfgPathND, 500); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testDiamEmptyCEItConnectDiameterClient(t *testing.T) {
|
||||
diamClntND, err = NewDiameterClient(daCfgND.DiameterAgentCfg().Listen,
|
||||
"INTEGRATION_TESTS",
|
||||
daCfgND.DiameterAgentCfg().OriginRealm, daCfgND.DiameterAgentCfg().VendorID,
|
||||
daCfgND.DiameterAgentCfg().ProductName, utils.DiameterFirmwareRevision,
|
||||
daCfgND.DiameterAgentCfg().DictionariesPath, daCfgND.DiameterAgentCfg().ListenNet)
|
||||
if err.Error() != "missing application" {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testDiamEmptyCEItKillEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(1000); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
@@ -39,10 +39,10 @@ import (
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/fiorix/go-diameter/v4/diam"
|
||||
"github.com/fiorix/go-diameter/v4/diam/avp"
|
||||
"github.com/fiorix/go-diameter/v4/diam/datatype"
|
||||
"github.com/fiorix/go-diameter/v4/diam/dict"
|
||||
"github.com/cgrates/go-diameter/diam"
|
||||
"github.com/cgrates/go-diameter/diam/avp"
|
||||
"github.com/cgrates/go-diameter/diam/datatype"
|
||||
"github.com/cgrates/go-diameter/diam/dict"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -106,6 +106,20 @@ func TestDiamItTcp(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiamItTcpNoDefaults(t *testing.T) {
|
||||
switch *utils.DBType {
|
||||
case utils.MetaInternal:
|
||||
diamConfigDIR = "diamagent_internal_supp_apps"
|
||||
case utils.MetaMySQL, utils.MetaMongo, utils.MetaPostgres:
|
||||
t.SkipNow()
|
||||
default:
|
||||
t.Fatal("Unknown Database type")
|
||||
}
|
||||
for _, stest := range sTestsDiam {
|
||||
t.Run(diamConfigDIR, stest)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiamItDispatcher(t *testing.T) {
|
||||
if *utils.Encoding == utils.MetaGOB {
|
||||
t.SkipNow()
|
||||
|
||||
@@ -32,12 +32,12 @@ import (
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/sessions"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/fiorix/go-diameter/v4/diam"
|
||||
"github.com/fiorix/go-diameter/v4/diam/avp"
|
||||
"github.com/fiorix/go-diameter/v4/diam/datatype"
|
||||
"github.com/fiorix/go-diameter/v4/diam/dict"
|
||||
"github.com/fiorix/go-diameter/v4/diam/sm"
|
||||
"github.com/fiorix/go-diameter/v4/diam/sm/smpeer"
|
||||
"github.com/cgrates/go-diameter/diam"
|
||||
"github.com/cgrates/go-diameter/diam/avp"
|
||||
"github.com/cgrates/go-diameter/diam/datatype"
|
||||
"github.com/cgrates/go-diameter/diam/dict"
|
||||
"github.com/cgrates/go-diameter/diam/sm"
|
||||
"github.com/cgrates/go-diameter/diam/sm/smpeer"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -135,6 +135,7 @@ func (da *DiameterAgent) ListenAndServe(stopChan <-chan struct{}) (err error) {
|
||||
// Creates the message handlers
|
||||
func (da *DiameterAgent) handlers() diam.Handler {
|
||||
settings := &sm.Settings{
|
||||
SupportedApps: da.cgrCfg.DiameterAgentCfg().CeApplications,
|
||||
OriginHost: datatype.DiameterIdentity(da.cgrCfg.DiameterAgentCfg().OriginHost),
|
||||
OriginRealm: datatype.DiameterIdentity(da.cgrCfg.DiameterAgentCfg().OriginRealm),
|
||||
VendorID: datatype.Unsigned32(da.cgrCfg.DiameterAgentCfg().VendorID),
|
||||
|
||||
@@ -29,8 +29,8 @@ import (
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/sessions"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/go-diameter/diam"
|
||||
"github.com/cgrates/rpcclient"
|
||||
"github.com/fiorix/go-diameter/v4/diam"
|
||||
)
|
||||
|
||||
func TestDAsSessionSClientIface(t *testing.T) {
|
||||
|
||||
@@ -32,10 +32,10 @@ import (
|
||||
"github.com/cgrates/birpc/context"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/fiorix/go-diameter/v4/diam"
|
||||
"github.com/fiorix/go-diameter/v4/diam/avp"
|
||||
"github.com/fiorix/go-diameter/v4/diam/datatype"
|
||||
"github.com/fiorix/go-diameter/v4/diam/dict"
|
||||
"github.com/cgrates/go-diameter/diam"
|
||||
"github.com/cgrates/go-diameter/diam/avp"
|
||||
"github.com/cgrates/go-diameter/diam/datatype"
|
||||
"github.com/cgrates/go-diameter/diam/dict"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -26,10 +26,10 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/fiorix/go-diameter/v4/diam"
|
||||
"github.com/fiorix/go-diameter/v4/diam/avp"
|
||||
"github.com/fiorix/go-diameter/v4/diam/datatype"
|
||||
"github.com/fiorix/go-diameter/v4/diam/sm"
|
||||
"github.com/cgrates/go-diameter/diam"
|
||||
"github.com/cgrates/go-diameter/diam/avp"
|
||||
"github.com/cgrates/go-diameter/diam/datatype"
|
||||
"github.com/cgrates/go-diameter/diam/sm"
|
||||
)
|
||||
|
||||
var dictOnce sync.Once
|
||||
|
||||
@@ -31,10 +31,10 @@ import (
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/fiorix/go-diameter/v4/diam"
|
||||
"github.com/fiorix/go-diameter/v4/diam/avp"
|
||||
"github.com/fiorix/go-diameter/v4/diam/datatype"
|
||||
"github.com/fiorix/go-diameter/v4/diam/dict"
|
||||
"github.com/cgrates/go-diameter/diam"
|
||||
"github.com/cgrates/go-diameter/diam/avp"
|
||||
"github.com/cgrates/go-diameter/diam/datatype"
|
||||
"github.com/cgrates/go-diameter/diam/dict"
|
||||
)
|
||||
|
||||
func loadDictionaries(dictsDir, componentID string) error {
|
||||
|
||||
@@ -30,9 +30,9 @@ import (
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/fiorix/go-diameter/v4/diam"
|
||||
"github.com/fiorix/go-diameter/v4/diam/avp"
|
||||
"github.com/fiorix/go-diameter/v4/diam/datatype"
|
||||
"github.com/cgrates/go-diameter/diam"
|
||||
"github.com/cgrates/go-diameter/diam/avp"
|
||||
"github.com/cgrates/go-diameter/diam/datatype"
|
||||
)
|
||||
|
||||
func TestLibDiamDPFieldAsInterface(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user