From de513f6d4694622ff7905843a1b75f4fd1807a47 Mon Sep 17 00:00:00 2001 From: TeoV Date: Mon, 23 Apr 2018 07:23:33 -0400 Subject: [PATCH] Working on call test for kamailio --- .../kamevapi/cgrates/etc/cgrates/cgrates.json | 25 +++++- .../kamailio/etc/kamailio/kamailio.cfg | 6 +- .../cgrates/etc/cgrates/cgrates.json | 1 + .../opensips/etc/opensips/opensips.cfg | 2 +- general_tests/tut_fs_calls_test.go | 87 ++++++++++++++----- 5 files changed, 92 insertions(+), 29 deletions(-) diff --git a/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json b/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json index 4e0a042e6..d9dc1734a 100644 --- a/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json +++ b/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json @@ -30,22 +30,29 @@ "rals": { "enabled": true, "thresholds_conns": [ - {"address": "*internal"} + {"address": "127.0.0.1:2012", "transport": "*json"} ], "stats_conns": [ - {"address": "*internal"} + {"address": "127.0.0.1:2012", "transport": "*json"} ], "pubsubs_conns": [ {"address": "*internal"} ], "attributes_conns": [ - {"address": "*internal"} + {"address": "127.0.0.1:2012", "transport": "*json"} ], }, "cdrs": { "enabled": true, + "sessions_conns": [ + {"address": "127.0.0.1:2012", "transport": "*json"} + ], + "stats_conns": [ + {"address": "127.0.0.1:2012", "transport": "*json"} + ], + "sessions_cost_retries": 5, }, @@ -75,6 +82,10 @@ "evapi_conns":[ // instantiate connections to multiple Kamailio servers {"address": "127.0.0.1:8448", "reconnects": 5} ], + "sessions_conns": [ + {"address": "*internal"} // connection towards session service: <*internal> + ], + "create_cdr": true, // create CDR out of events and sends them to CDRS component }, @@ -85,6 +96,7 @@ "attributes": { "enabled": true, + "string_indexed_fields": ["Account"], }, @@ -93,6 +105,8 @@ "thresholds_conns": [ {"address": "*internal"} ], + "string_indexed_fields": ["Account"], + "prefix_indexed_fields": ["Destination"], }, @@ -101,11 +115,13 @@ "thresholds_conns": [ {"address": "*internal"} ], + "string_indexed_fields": ["Account"], }, "thresholds": { "enabled": true, + "string_indexed_fields": ["Account"], }, @@ -120,7 +136,10 @@ "stats_conns": [ {"address": "*internal"} ], + "string_indexed_fields": ["Account"], + "prefix_indexed_fields": ["Destination"], }, + } diff --git a/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio.cfg b/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio.cfg index 8dee82b80..7590f3518 100644 --- a/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio.cfg +++ b/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio.cfg @@ -52,14 +52,16 @@ loadmodule "auth.so" loadmodule "evapi.so" loadmodule "json.so" loadmodule "dialog.so" -loadmodule "xhttp.so" +# loadmodule "xhttp.so" loadmodule "jsonrpcs.so" +loadmodule "sctp.so" +loadmodule "outbound.so" # ----------------- setting module-specific parameters --------------- -modparam("evapi", "bind_addr", "10.10.10.205:8448") +modparam("evapi", "bind_addr", "127.0.0.1:8448") # ----- tm params ----- modparam("tm", "failure_reply_mode", 3) diff --git a/data/tutorials/osips_native/cgrates/etc/cgrates/cgrates.json b/data/tutorials/osips_native/cgrates/etc/cgrates/cgrates.json index 550f11016..a01f21037 100644 --- a/data/tutorials/osips_native/cgrates/etc/cgrates/cgrates.json +++ b/data/tutorials/osips_native/cgrates/etc/cgrates/cgrates.json @@ -46,6 +46,7 @@ "sessions": { "enabled": true, + "listen_bijson": "127.0.0.1:2014", // address where to listen for bidirectional JSON-RPC requests "rals_conns": [ {"address": "127.0.0.1:2012", "transport": "*json"} ], diff --git a/data/tutorials/osips_native/opensips/etc/opensips/opensips.cfg b/data/tutorials/osips_native/opensips/etc/opensips/opensips.cfg index 3e972aac8..8d514726f 100644 --- a/data/tutorials/osips_native/opensips/etc/opensips/opensips.cfg +++ b/data/tutorials/osips_native/opensips/etc/opensips/opensips.cfg @@ -23,7 +23,7 @@ children=4 auto_aliases=no -listen=udp:127.0.0.1:5060 ### CUSTOMIZE ME +listen=udp:192.168.56.203:5060 ### CUSTOMIZE ME diff --git a/general_tests/tut_fs_calls_test.go b/general_tests/tut_fs_calls_test.go index 4d5396977..20fa6bc7b 100755 --- a/general_tests/tut_fs_calls_test.go +++ b/general_tests/tut_fs_calls_test.go @@ -42,6 +42,8 @@ var tutFsCallsPjSuaListener *os.File var waitRater = flag.Int("wait_rater", 100, "Number of miliseconds to wait for rater to start and cache") var dataDir = flag.String("data_dir", "/usr/share/cgrates", "CGR data dir path here") var fsConfig = flag.String("fsConfig", "/usr/share/cgrates/tutorials/fs_evsock", "FreeSwitch tutorial folder") +var kamConfig = flag.String("kamConfig", "/usr/share/cgrates/tutorials/kamevapi", "Kamailio tutorial folder") +var optConf string var sTestsCalls = []func(t *testing.T){ testCallInitCfg, @@ -77,6 +79,14 @@ var sTestsCalls = []func(t *testing.T){ //Test start here func TestFSCall(t *testing.T) { + optConf = "freeswitch" + for _, stest := range sTestsCalls { + t.Run("", stest) + } +} + +func TestKamCall(t *testing.T) { + optConf = "kamailio" for _, stest := range sTestsCalls { t.Run("", stest) } @@ -85,10 +95,18 @@ func TestFSCall(t *testing.T) { func testCallInitCfg(t *testing.T) { // Init config first var err error - tutFsCallsCfg, err = config.NewCGRConfigFromFolder(path.Join(*dataDir, "tutorials", "fs_evsock", "cgrates", "etc", "cgrates")) - if err != nil { - t.Error(err) + if optConf == "freeswitch" { + tutFsCallsCfg, err = config.NewCGRConfigFromFolder(path.Join(*dataDir, "tutorials", "fs_evsock", "cgrates", "etc", "cgrates")) + if err != nil { + t.Error(err) + } + } else if optConf == "kamailio" { + tutFsCallsCfg, err = config.NewCGRConfigFromFolder(path.Join(*dataDir, "tutorials", "kamevapi", "cgrates", "etc", "cgrates")) + if err != nil { + t.Error(err) + } } + tutFsCallsCfg.DataFolderPath = *dataDir // Share DataFolderPath through config towards StoreDb for Flush() config.SetCgrConfig(tutFsCallsCfg) } @@ -109,24 +127,43 @@ func testCallResetStorDb(t *testing.T) { // start FS server func testCallStartFS(t *testing.T) { - engine.KillProcName("freeswitch", 5000) - if err := engine.CallScript(path.Join(*dataDir, "tutorials", "fs_evsock", "freeswitch", "etc", "init.d", "freeswitch"), "start", 3000); err != nil { - t.Fatal(err) + if optConf == "freeswitch" { + engine.KillProcName("freeswitch", 5000) + if err := engine.CallScript(path.Join(*dataDir, "tutorials", "fs_evsock", "freeswitch", "etc", "init.d", "freeswitch"), "start", 3000); err != nil { + t.Fatal(err) + } + } else if optConf == "kamailio" { + engine.KillProcName("kamailio", 5000) + if err := engine.CallScript(path.Join(*dataDir, "tutorials", "kamevapi", "kamailio", "etc", "init.d", "kamailio"), "start", 3000); err != nil { + t.Fatal(err) + } } } // Start CGR Engine func testCallStartEngine(t *testing.T) { engine.KillProcName("cgr-engine", *waitRater) - if err := engine.CallScript(path.Join(*dataDir, "tutorials", "fs_evsock", "cgrates", "etc", "init.d", "cgrates"), "start", 100); err != nil { - t.Fatal(err) + if optConf == "freeswitch" { + if err := engine.CallScript(path.Join(*dataDir, "tutorials", "fs_evsock", "cgrates", "etc", "init.d", "cgrates"), "start", 100); err != nil { + t.Fatal(err) + } + } else if optConf == "kamailio" { + if err := engine.CallScript(path.Join(*dataDir, "tutorials", "kamevapi", "cgrates", "etc", "init.d", "cgrates"), "start", 100); err != nil { + t.Fatal(err) + } } } // Restart FS so we make sure reconnects are working func testCallRestartFS(t *testing.T) { - if err := engine.CallScript(path.Join(*dataDir, "tutorials", "fs_evsock", "freeswitch", "etc", "init.d", "freeswitch"), "restart", 5000); err != nil { - t.Fatal(err) + if optConf == "freeswitch" { + if err := engine.CallScript(path.Join(*dataDir, "tutorials", "fs_evsock", "freeswitch", "etc", "init.d", "freeswitch"), "restart", 5000); err != nil { + t.Fatal(err) + } + } else if optConf == "kamailio" { + if err := engine.CallScript(path.Join(*dataDir, "tutorials", "kamevapi", "kamailio", "etc", "init.d", "kamailio"), "restart", 5000); err != nil { + t.Fatal(err) + } } } @@ -231,12 +268,12 @@ func testCallCheckThreshold1002Before(t *testing.T) { func testCallStartPjsuaListener(t *testing.T) { var err error acnts := []*engine.PjsuaAccount{ - &engine.PjsuaAccount{Id: "sip:1001@192.168.56.202", - Username: "1001", Password: "CGRateS.org", Realm: "*", Registrar: "sip:192.168.56.202:5060"}, - &engine.PjsuaAccount{Id: "sip:1002@192.168.56.202", - Username: "1002", Password: "CGRateS.org", Realm: "*", Registrar: "sip:192.168.56.202:5060"}, - &engine.PjsuaAccount{Id: "sip:1003@192.168.56.202", - Username: "1003", Password: "CGRateS.org", Realm: "*", Registrar: "sip:192.168.56.202:5060"}, + &engine.PjsuaAccount{Id: "sip:1001@192.168.56.203", + Username: "1001", Password: "CGRateS.org", Realm: "*", Registrar: "sip:192.168.56.203:5060"}, + &engine.PjsuaAccount{Id: "sip:1002@192.168.56.203", + Username: "1002", Password: "CGRateS.org", Realm: "*", Registrar: "sip:192.168.56.203:5060"}, + &engine.PjsuaAccount{Id: "sip:1003@192.168.56.203", + Username: "1003", Password: "CGRateS.org", Realm: "*", Registrar: "sip:192.168.56.203:5060"}, } if tutFsCallsPjSuaListener, err = engine.StartPjsuaListener( acnts, 5070, time.Duration(*waitRater)*time.Millisecond); err != nil { @@ -247,8 +284,8 @@ func testCallStartPjsuaListener(t *testing.T) { // Call from 1001 (prepaid) to 1002 func testCallCall1001To1002(t *testing.T) { if err := engine.PjsuaCallUri( - &engine.PjsuaAccount{Id: "sip:1001@192.168.56.202", Username: "1001", Password: "CGRateS.org", Realm: "*"}, - "sip:1002@192.168.56.202", "sip:192.168.56.202:5060", time.Duration(67)*time.Second, 5071); err != nil { + &engine.PjsuaAccount{Id: "sip:1001@192.168.56.203", Username: "1001", Password: "CGRateS.org", Realm: "*"}, + "sip:1002@192.168.56.203", "sip:192.168.56.203:5060", time.Duration(67)*time.Second, 5071); err != nil { t.Fatal(err) } time.Sleep(1 * time.Second) @@ -288,8 +325,8 @@ func testCallGetActiveSessions(t *testing.T) { // Call from 1002 (postpaid) to 1001 func testCallCall1002To1001(t *testing.T) { if err := engine.PjsuaCallUri( - &engine.PjsuaAccount{Id: "sip:1002@192.168.56.202", Username: "1002", Password: "CGRateS.org", Realm: "*"}, - "sip:1001@192.168.56.202", "sip:192.168.56.202:5060", time.Duration(65)*time.Second, 5072); err != nil { + &engine.PjsuaAccount{Id: "sip:1002@192.168.56.203", Username: "1002", Password: "CGRateS.org", Realm: "*"}, + "sip:1001@192.168.56.203", "sip:192.168.56.203:5060", time.Duration(65)*time.Second, 5072); err != nil { t.Fatal(err) } } @@ -297,8 +334,8 @@ func testCallCall1002To1001(t *testing.T) { // Call from 1001 (prepaid) to 1003 limit to 12 seconds func testCallCall1001To1003(t *testing.T) { if err := engine.PjsuaCallUri( - &engine.PjsuaAccount{Id: "sip:1001@192.168.56.202", Username: "1001", Password: "CGRateS.org", Realm: "*"}, - "sip:1003@192.168.56.202", "sip:192.168.56.202:5060", time.Duration(60)*time.Second, 5073); err != nil { + &engine.PjsuaAccount{Id: "sip:1001@192.168.56.203", Username: "1001", Password: "CGRateS.org", Realm: "*"}, + "sip:1003@192.168.56.203", "sip:192.168.56.203:5060", time.Duration(60)*time.Second, 5073); err != nil { t.Fatal(err) } } @@ -473,5 +510,9 @@ func testCallStopCgrEngine(t *testing.T) { } func testCallStopFS(t *testing.T) { - engine.KillProcName("freeswitch", 1000) + if optConf == "freeswitch" { + engine.KillProcName("freeswitch", 1000) + } else if optConf == "kamailio" { + engine.KillProcName("kamailio", 1000) + } }