From d4129d1c775e433f72a558464d2be8419715e4c0 Mon Sep 17 00:00:00 2001 From: TeoV Date: Mon, 3 Dec 2018 04:30:34 -0500 Subject: [PATCH] Add test for diameter maximum number of diam req --- agents/diam_it_test.go | 82 +++++++++++++++++- .../samples/diamagentmaxconn/cgrates.json | 86 +++++++++++++++++++ 2 files changed, 166 insertions(+), 2 deletions(-) create mode 100755 data/conf/samples/diamagentmaxconn/cgrates.json diff --git a/agents/diam_it_test.go b/agents/diam_it_test.go index aded2d18c..02af5f0ef 100644 --- a/agents/diam_it_test.go +++ b/agents/diam_it_test.go @@ -77,6 +77,15 @@ func TestDiamItSctp(t *testing.T) { } } +func TestDiamItMaxConn(t *testing.T) { + diamConfigDIR = "diamagentmaxconn" + for _, stest := range sTestsDiam[:7] { + t.Run(diamConfigDIR, stest) + } + t.Run(diamConfigDIR, testDiamItDryRunMaxConn) + t.Run(diamConfigDIR, testDiamItKillEngine) +} + func testDiamItInitCfg(t *testing.T) { daCfgPath = path.Join(*dataDir, "conf", "samples", diamConfigDIR) // Init config first @@ -112,7 +121,7 @@ func testDiamItStartEngine(t *testing.T) { } func testDiamItConnectDiameterClient(t *testing.T) { - if diamConfigDIR == "diamsctpagent" { + if diamConfigDIR == "diamsctpagent" || diamConfigDIR == "diamagentmaxconn" { daCfg.DiameterAgentCfg().DictionariesPath = "" } diamClnt, err = NewDiameterClient(daCfg.DiameterAgentCfg().Listen, "INTEGRATION_TESTS", @@ -345,6 +354,75 @@ func testDiamItDryRun(t *testing.T) { } } +func testDiamItDryRunMaxConn(t *testing.T) { + ccr := diam.NewRequest(diam.CreditControl, 4, nil) + ccr.NewAVP(avp.SessionID, avp.Mbit, 0, datatype.UTF8String("cgrates;1451911932;00082")) + ccr.NewAVP(avp.OriginHost, avp.Mbit, 0, datatype.DiameterIdentity("CGR-DA")) + ccr.NewAVP(avp.OriginRealm, avp.Mbit, 0, datatype.DiameterIdentity("cgrates.org")) + ccr.NewAVP(avp.DestinationRealm, avp.Mbit, 0, datatype.DiameterIdentity("cgrates.org")) + ccr.NewAVP(avp.DestinationHost, avp.Mbit, 0, datatype.DiameterIdentity("CGR-DA")) + ccr.NewAVP(avp.UserName, avp.Mbit, 0, datatype.UTF8String("CGR-DA")) + ccr.NewAVP(avp.AuthApplicationID, avp.Mbit, 0, datatype.Unsigned32(4)) + ccr.NewAVP(avp.ServiceContextID, avp.Mbit, 0, datatype.UTF8String("TestDiamItDryRun")) // Match specific DryRun profile + ccr.NewAVP(avp.CCRequestType, avp.Mbit, 0, datatype.Enumerated(1)) + ccr.NewAVP(avp.CCRequestNumber, avp.Mbit, 0, datatype.Unsigned32(1)) + ccr.NewAVP(avp.EventTimestamp, avp.Mbit, 0, datatype.Time(time.Date(2016, 1, 5, 11, 30, 10, 0, time.UTC))) + ccr.NewAVP(avp.TerminationCause, avp.Mbit, 0, datatype.Enumerated(1)) + if _, err := ccr.NewAVP("Framed-IP-Address", avp.Mbit, 0, datatype.UTF8String("10.228.16.4")); err != nil { + t.Error(err) + } + for i := 0; i < *interations; i++ { + if err := diamClnt.SendMessage(ccr); err != nil { + t.Error(err) + } + msg := diamClnt.ReceivedMessage(rplyTimeout) + if msg == nil { + t.Fatal("No message returned") + } + // Result-Code + eVal := "5012" + if avps, err := msg.FindAVPsWithPath([]interface{}{"Result-Code"}, dict.UndefinedVendorID); err != nil { + t.Error(err) + } else if len(avps) == 0 { + t.Error("Missing AVP") + } else if val, err := diamAVPAsString(avps[0]); err != nil { + t.Error(err) + } else if val != eVal { + t.Errorf("expecting: %s, received: <%s>", eVal, val) + } + eVal = "cgrates;1451911932;00082" + if avps, err := msg.FindAVPsWithPath([]interface{}{"Session-Id"}, dict.UndefinedVendorID); err != nil { + t.Error(err) + } else if len(avps) == 0 { + t.Error("Missing AVP") + } else if val, err := diamAVPAsString(avps[0]); err != nil { + t.Error(err) + } else if val != eVal { + t.Errorf("expecting: %s, received: <%s>", eVal, val) + } + eVal = "CGR-DA" + if avps, err := msg.FindAVPsWithPath([]interface{}{"Origin-Host"}, dict.UndefinedVendorID); err != nil { + t.Error(err) + } else if len(avps) == 0 { + t.Error("Missing AVP") + } else if val, err := diamAVPAsString(avps[0]); err != nil { + t.Error(err) + } else if val != eVal { + t.Errorf("expecting: %s, received: <%s>", eVal, val) + } + eVal = "cgrates.org" + if avps, err := msg.FindAVPsWithPath([]interface{}{"Origin-Realm"}, dict.UndefinedVendorID); err != nil { + t.Error(err) + } else if len(avps) == 0 { + t.Error("Missing AVP") + } else if val, err := diamAVPAsString(avps[0]); err != nil { + t.Error(err) + } else if val != eVal { + t.Errorf("expecting: %s, received: <%s>", eVal, val) + } + } +} + func testDiamItCCRInit(t *testing.T) { m := diam.NewRequest(diam.CreditControl, 4, nil) m.NewAVP(avp.SessionID, avp.Mbit, 0, datatype.UTF8String("bb97be2b9f37c2be9614fff71c8b1d08b1acbff8")) @@ -639,7 +717,7 @@ func testDiamItCCRSMS(t *testing.T) { } func testDiamItKillEngine(t *testing.T) { - if err := engine.KillEngine(4000); err != nil { + if err := engine.KillEngine(1000); err != nil { t.Error(err) } } diff --git a/data/conf/samples/diamagentmaxconn/cgrates.json b/data/conf/samples/diamagentmaxconn/cgrates.json new file mode 100755 index 000000000..8bb164d72 --- /dev/null +++ b/data/conf/samples/diamagentmaxconn/cgrates.json @@ -0,0 +1,86 @@ +{ +// CGRateS Configuration file +// +// Used for cgradmin +// Starts rater, scheduler + +"general": { + "log_level": 7, +}, + +"listen": { + "rpc_json": ":2012", // RPC JSON listening address + "rpc_gob": ":2013", // RPC GOB listening address + "http": ":2080", // HTTP listening address +}, + +"data_db": { // database used to store runtime data (eg: accounts, cdr stats) + "db_type": "mongo", // stor database type to use: + "db_port": 27017, // the port to reach the stordb + "db_name": "datadb", + "db_password": "", +}, + +"stor_db": { + "db_type": "mongo", // stor database type to use: + "db_port": 27017, // the port to reach the stordb + "db_name": "stordb", + "db_password": "", +}, + +"rals": { + "enabled": true, +}, + +"scheduler": { + "enabled": true, +}, + +"cdrs": { + "enabled": true, +}, + +"attributes": { + "enabled": true, +}, + +"chargers": { + "enabled": true, +}, + + +"sessions": { + "enabled": true, + "attributes_conns": [ + {"address": "127.0.0.1:2012","transport":"*json"} + ], + "chargers_conns": [ + {"address": "127.0.0.1:2012","transport":"*json"} + ], + "rals_conns": [ + {"address": "127.0.0.1:2012","transport":"*json"} + ], + "cdrs_conns": [ + {"address": "127.0.0.1:2012","transport":"*json"} + ], +}, + +"diameter_agent": { + "enabled": true, + "max_active_requests": 0, + "sessions_conns": [ + {"address": "127.0.0.1:2012","transport":"*json"} + ], + "request_processors": [ + { + "id": "maxconn", + "filters": ["*string:*vars.*cmd:CCR", "*string:*req.Service-Context-Id:TestDiamItDryRun"], + "flags": ["*dryrun"], + "continue_on_success": true, + "request_fields":[], + "reply_fields":[], + }, + ], +}, + +}