diff --git a/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json b/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json index 25d2715ef..1ced3cd15 100644 --- a/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json +++ b/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json @@ -147,5 +147,4 @@ }, - } diff --git a/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio-cgrates.cfg b/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio-cgrates.cfg index c3d3e5adf..65ac77a90 100644 --- a/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio-cgrates.cfg +++ b/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio-cgrates.cfg @@ -29,11 +29,6 @@ event_route[dialog:end] { route(CGR_CALL_END); } -# Called by Kamailio on local disconnect -event_route[tm:local-request] { - route(CGR_CALL_END); -} - # CGRateS request for session disconnect route[CGR_SESSION_DISCONNECT] { json_get_field("$evapi(msg)", "HashEntry", "$var(HashEntry)"); diff --git a/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio.cfg b/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio.cfg index 7590f3518..db75768bd 100644 --- a/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio.cfg +++ b/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio.cfg @@ -28,6 +28,10 @@ dns_retr_no=1 dns_servers_no=1 dns_use_search_list=no +listen=udp:eth0:5060 +listen=udp:127.0.0.1:5080 +listen=tcp:127.0.0.1:5060 + ####### Modules Section ######## mpath="/usr/lib/x86_64-linux-gnu/kamailio/modules/" @@ -52,10 +56,7 @@ loadmodule "auth.so" loadmodule "evapi.so" loadmodule "json.so" loadmodule "dialog.so" -# loadmodule "xhttp.so" loadmodule "jsonrpcs.so" -loadmodule "sctp.so" -loadmodule "outbound.so" diff --git a/data/tutorials/osips_native/cgrates/etc/cgrates/cgrates.json b/data/tutorials/osips_native/cgrates/etc/cgrates/cgrates.json index a01f21037..77013e107 100644 --- a/data/tutorials/osips_native/cgrates/etc/cgrates/cgrates.json +++ b/data/tutorials/osips_native/cgrates/etc/cgrates/cgrates.json @@ -25,22 +25,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, }, @@ -62,6 +69,12 @@ "attributes_conns": [ {"address": "127.0.0.1:2012", "transport": "*json"} ], + "stats_conns": [ + {"address": "127.0.0.1:2012", "transport": "*json"} + ], + "thresholds_conns": [ + {"address": "127.0.0.1:2012", "transport": "*json"} + ], "debit_interval": "10s", }, @@ -73,6 +86,7 @@ "attributes": { "enabled": true, + "string_indexed_fields": ["Account"], }, @@ -81,6 +95,8 @@ "thresholds_conns": [ {"address": "*internal"} ], + "string_indexed_fields": ["Account"], + "prefix_indexed_fields": ["Destination"], }, @@ -89,11 +105,13 @@ "thresholds_conns": [ {"address": "*internal"} ], + "string_indexed_fields": ["Account"], }, "thresholds": { "enabled": true, + "string_indexed_fields": ["Account"], }, @@ -108,6 +126,8 @@ "stats_conns": [ {"address": "*internal"} ], + "string_indexed_fields": ["Account"], + "prefix_indexed_fields": ["Destination"], }, diff --git a/data/tutorials/osips_native/opensips/etc/opensips/opensips.cfg b/data/tutorials/osips_native/opensips/etc/opensips/opensips.cfg index 8d514726f..147bafac8 100644 --- a/data/tutorials/osips_native/opensips/etc/opensips/opensips.cfg +++ b/data/tutorials/osips_native/opensips/etc/opensips/opensips.cfg @@ -23,7 +23,10 @@ children=4 auto_aliases=no -listen=udp:192.168.56.203:5060 ### CUSTOMIZE ME +listen=udp:eth0:5060 +listen=udp:127.0.0.1:5080 +listen=udp:127.0.0.1:5060 +listen=udp:eth0:5080 @@ -200,18 +203,26 @@ route{ } # check auth with CGRateS - if (!async(cgrates_auth("$fU", "$rU"), resume_cgr_auth)) { - sl_send_reply("503", "Service Unavailable"); - exit; - } + $cgr_opt(GetMaxUsage) = 1; # also retrieve the max usage + $cgr_opt(GetAttributes) = 1; + $cgr_opt(GetSuppliers) = 1; + $cgr_opt(AuthorizeResources) = 1; + $cgr_opt(ProcessThresholds) = 1; + $cgr_opt(ProcessStatQueues) = 1; + $cgr(RequestType) = "*prepaid"; + + if (!async(cgrates_auth("$fU", "$rU"), resume_cgr_auth)) { + sl_send_reply("503", "Service Unavailable"); + exit; + } } route [resume_cgr_auth] { - if ($rc < 0) { - xlog("Call not authorized: code=$cgrret!\n"); - send_reply("403", "Forbidden"); - exit; - } + if ($rc == 0) { + xlog("Call not authorized: code=$cgrret!\n"); + send_reply("403", "Forbidden"); + exit; + } $var(idx) = 0; while ($(cgr_ret(AttributesDigest){s.select,$var(idx),,}) != NULL) { $avp($(cgr_ret(AttributesDigest){s.select,$var(idx),,}{s.select,0,:})) diff --git a/docs/tut_jitsi_installs.rst b/docs/tut_jitsi_installs.rst index 892756ab7..b09801a55 100644 --- a/docs/tut_jitsi_installs.rst +++ b/docs/tut_jitsi_installs.rst @@ -1,6 +1,6 @@ SIP UA - Jitsi_ --------------- -On our ubuntu desktop host, we have installed Jitsi_ to be used as SIP UA, out of stable provided packages on `Jitsi download `_ and had Jitsi_ configured with 4 accounts: 1001/1234, 1002/1234, 1003/1234 and 1004/1234. +On our ubuntu desktop host, we have installed Jitsi_ to be used as SIP UA, out of stable provided packages on `Jitsi download `_ and had Jitsi_ configured with 4 accounts: 1001/CGRateS.org, 1002/CGRateS.org, 1003/CGRateS.org and 1004/CGRateS.org. .. _Jitsi: http://www.jitsi.org/ \ No newline at end of file diff --git a/docs/tut_kamailio_installs.rst b/docs/tut_kamailio_installs.rst index bbbf41c1e..5da498055 100644 --- a/docs/tut_kamailio_installs.rst +++ b/docs/tut_kamailio_installs.rst @@ -10,7 +10,7 @@ We got Kamailio_ installed via following commands: :: apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xfb40d3e6508ea4c8 - echo "deb http://deb.kamailio.org/kamailio44 jessie main" > /etc/apt/sources.list.d/kamailio.list + echo "deb http://deb.kamailio.org/kamailio51 jessie main" > /etc/apt/sources.list.d/kamailio.list apt-get update apt-get install kamailio kamailio-extra-modules kamailio-json-modules diff --git a/docs/tut_opensips_event.rst b/docs/tut_opensips_event.rst index 9f7473a35..4ee61648e 100644 --- a/docs/tut_opensips_event.rst +++ b/docs/tut_opensips_event.rst @@ -22,7 +22,7 @@ Starting OpenSIPS_ with custom configuration :: - /usr/share/cgrates/tutorials/osips_async/opensips/etc/init.d/opensips start + /usr/share/cgrates/tutorials/osips_native/opensips/etc/init.d/opensips start To verify that OpenSIPS_ is running we run the console command: @@ -36,7 +36,7 @@ Starting **CGRateS** with custom configuration :: - /usr/share/cgrates/tutorials/osips_async/cgrates/etc/init.d/cgrates start + /usr/share/cgrates/tutorials/osips_native/cgrates/etc/init.d/cgrates start Make sure that cgrates is running diff --git a/docs/tut_opensips_installs.rst b/docs/tut_opensips_installs.rst index 61889d844..95cc7d43d 100644 --- a/docs/tut_opensips_installs.rst +++ b/docs/tut_opensips_installs.rst @@ -10,7 +10,7 @@ We got OpenSIPS_ installed via following commands: :: apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 049AD65B - echo "deb http://apt.opensips.org stretch 2.4-releases" >>/etc/apt/sources.list + echo "deb http://apt.opensips.org jessie 2.4-nightly" >/etc/apt/sources.list.d/opensips.list apt-get update apt-get install opensips opensips-cgrates-module diff --git a/general_tests/tut_fs_calls_test.go b/general_tests/tut_fs_calls_test.go index 9497b61d2..b6d59008f 100755 --- a/general_tests/tut_fs_calls_test.go +++ b/general_tests/tut_fs_calls_test.go @@ -22,6 +22,7 @@ package general_tests import ( "flag" + "fmt" "net/rpc" "net/rpc/jsonrpc" "os" @@ -43,6 +44,7 @@ var waitRater = flag.Int("wait_rater", 100, "Number of miliseconds to wait for r 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 oSipsConfig = flag.String("osConfig", "/usr/share/cgrates/tutorials/osips_native", "OpenSips tutorial folder") var optConf string var sTestsCalls = []func(t *testing.T){ @@ -78,15 +80,22 @@ var sTestsCalls = []func(t *testing.T){ } //Test start here -func TestFSCall(t *testing.T) { - optConf = "freeswitch" +func TestFSCalls(t *testing.T) { + optConf = utils.Freeswitch for _, stest := range sTestsCalls { t.Run("", stest) } } -func TestKamCall(t *testing.T) { - optConf = "kamailio" +func TestKamCalls(t *testing.T) { + optConf = utils.Kamailio + for _, stest := range sTestsCalls { + t.Run("", stest) + } +} + +func TestOSCalls(t *testing.T) { + optConf = utils.Opensips for _, stest := range sTestsCalls { t.Run("", stest) } @@ -95,13 +104,18 @@ func TestKamCall(t *testing.T) { func testCallInitCfg(t *testing.T) { // Init config first var err error - if optConf == "freeswitch" { - tutFsCallsCfg, err = config.NewCGRConfigFromFolder(path.Join(*dataDir, "tutorials", "fs_evsock", "cgrates", "etc", "cgrates")) + if optConf == utils.Freeswitch { + tutFsCallsCfg, err = config.NewCGRConfigFromFolder(path.Join(*fsConfig, "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")) + } else if optConf == utils.Kamailio { + tutFsCallsCfg, err = config.NewCGRConfigFromFolder(path.Join(*kamConfig, "cgrates", "etc", "cgrates")) + if err != nil { + t.Error(err) + } + } else if optConf == utils.Opensips { + tutFsCallsCfg, err = config.NewCGRConfigFromFolder(path.Join(*oSipsConfig, "cgrates", "etc", "cgrates")) if err != nil { t.Error(err) } @@ -127,14 +141,19 @@ func testCallResetStorDb(t *testing.T) { // start FS server func testCallStartFS(t *testing.T) { - 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 { + if optConf == utils.Freeswitch { + engine.KillProcName(utils.Freeswitch, 5000) + if err := engine.CallScript(path.Join(*fsConfig, "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 { + } else if optConf == utils.Kamailio { + engine.KillProcName(utils.Kamailio, 5000) + if err := engine.CallScript(path.Join(*kamConfig, "kamailio", "etc", "init.d", "kamailio"), "start", 3000); err != nil { + t.Fatal(err) + } + } else if optConf == utils.Opensips { + engine.KillProcName(utils.Kamailio, 5000) + if err := engine.CallScript(path.Join(*oSipsConfig, "opensips", "etc", "init.d", "opensips"), "start", 3000); err != nil { t.Fatal(err) } } @@ -143,12 +162,16 @@ func testCallStartFS(t *testing.T) { // Start CGR Engine func testCallStartEngine(t *testing.T) { engine.KillProcName("cgr-engine", *waitRater) - if optConf == "freeswitch" { - if err := engine.CallScript(path.Join(*dataDir, "tutorials", "fs_evsock", "cgrates", "etc", "init.d", "cgrates"), "start", 100); err != nil { + if optConf == utils.Freeswitch { + if err := engine.CallScript(path.Join(*fsConfig, "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 { + } else if optConf == utils.Kamailio { + if err := engine.CallScript(path.Join(*kamConfig, "cgrates", "etc", "init.d", "cgrates"), "start", 100); err != nil { + t.Fatal(err) + } + } else if optConf == utils.Opensips { + if err := engine.CallScript(path.Join(*oSipsConfig, "cgrates", "etc", "init.d", "cgrates"), "start", 100); err != nil { t.Fatal(err) } } @@ -156,12 +179,16 @@ func testCallStartEngine(t *testing.T) { // Restart FS so we make sure reconnects are working func testCallRestartFS(t *testing.T) { - if optConf == "freeswitch" { - if err := engine.CallScript(path.Join(*dataDir, "tutorials", "fs_evsock", "freeswitch", "etc", "init.d", "freeswitch"), "restart", 5000); err != nil { + if optConf == utils.Freeswitch { + if err := engine.CallScript(path.Join(*fsConfig, "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 { + } else if optConf == utils.Kamailio { + if err := engine.CallScript(path.Join(*kamConfig, "kamailio", "etc", "init.d", "kamailio"), "restart", 5000); err != nil { + t.Fatal(err) + } + } else if optConf == utils.Opensips { + if err := engine.CallScript(path.Join(*oSipsConfig, "opensips", "etc", "init.d", "opensips"), "restart", 5000); err != nil { t.Fatal(err) } } @@ -269,12 +296,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.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"}, + &engine.PjsuaAccount{Id: "sip:1001@127.0.0.1", + Username: "1001", Password: "CGRateS.org", Realm: "*", Registrar: "sip:127.0.0.1:5080"}, + &engine.PjsuaAccount{Id: "sip:1002@127.0.0.1", + Username: "1002", Password: "CGRateS.org", Realm: "*", Registrar: "sip:127.0.0.1:5080"}, + &engine.PjsuaAccount{Id: "sip:1003@127.0.0.1", + Username: "1003", Password: "CGRateS.org", Realm: "*", Registrar: "sip:127.0.0.1:5080"}, } if tutFsCallsPjSuaListener, err = engine.StartPjsuaListener( acnts, 5070, time.Duration(*waitRater)*time.Millisecond); err != nil { @@ -285,8 +312,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.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 { + &engine.PjsuaAccount{Id: "sip:1001@127.0.0.1", Username: "1001", Password: "CGRateS.org", Realm: "*"}, + "sip:1002@127.0.0.1", "sip:127.0.0.1:5080", time.Duration(67)*time.Second, 5071); err != nil { t.Fatal(err) } time.Sleep(1 * time.Second) @@ -297,7 +324,6 @@ func testCallGetActiveSessions(t *testing.T) { var reply *[]*sessions.ActiveSession expected := &[]*sessions.ActiveSession{ &sessions.ActiveSession{ - TOR: "*voice", ReqType: "*prepaid", Tenant: "cgrates.org", Category: "call", @@ -306,14 +332,12 @@ func testCallGetActiveSessions(t *testing.T) { Destination: "1002", }, } - if err := tutFsCallsRpc.Call("SessionSv1.GetActiveSessions", + if err := tutFsCallsRpc.Call(utils.SessionSv1GetActiveSessions, &map[string]string{}, &reply); err != nil { t.Error("Got error on SessionSv1.GetActiveSessions: ", err.Error()) } else { // compare some fields (eg. CGRId is generated) - if !reflect.DeepEqual((*expected)[0].TOR, (*reply)[0].TOR) { - t.Errorf("Expected: %s, received: %s", (*expected)[0].TOR, (*reply)[0].TOR) - } else if !reflect.DeepEqual((*expected)[0].ReqType, (*reply)[0].ReqType) { + if !reflect.DeepEqual((*expected)[0].ReqType, (*reply)[0].ReqType) { t.Errorf("Expected: %s, received: %s", (*expected)[0].ReqType, (*reply)[0].ReqType) } else if !reflect.DeepEqual((*expected)[0].Account, (*reply)[0].Account) { t.Errorf("Expected: %s, received: %s", (*expected)[0].Account, (*reply)[0].Account) @@ -326,8 +350,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.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 { + &engine.PjsuaAccount{Id: "sip:1002@127.0.0.1", Username: "1002", Password: "CGRateS.org", Realm: "*"}, + "sip:1001@127.0.0.1", "sip:127.0.0.1:5080", time.Duration(65)*time.Second, 5072); err != nil { t.Fatal(err) } } @@ -335,8 +359,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.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 { + &engine.PjsuaAccount{Id: "sip:1001@127.0.0.1", Username: "1001", Password: "CGRateS.org", Realm: "*"}, + "sip:1003@127.0.0.1", "sip:127.0.0.1:5080", time.Duration(60)*time.Second, 5073); err != nil { t.Fatal(err) } } @@ -359,6 +383,7 @@ func testCallCheckResourceAllocation(t *testing.T) { t.Errorf("Resources: %+v", utils.ToJSON(rs)) } for _, r := range *rs { + utils.Logger.Debug(fmt.Sprintf("Resource : %+v\n", r)) if r.ID == "ResGroup1" && (len(r.Usages) != 1 || len(r.TTLIdx) != 1) { t.Errorf("Unexpected resource: %+v", utils.ToJSON(r)) @@ -390,7 +415,7 @@ func testCall1001Cdrs(t *testing.T) { t.Error("Unexpected number of CDRs returned: ", len(reply)) } else { for _, cdr := range reply { - if cdr.Source != "freeswitch_json" { + if cdr.Source != "freeswitch_json" && cdr.Source != "SMG_KamailioAgent" { t.Errorf("Unexpected Source for CDR: %+v", cdr.Source) } if cdr.RequestType != utils.META_PREPAID { @@ -424,7 +449,7 @@ func testCall1002Cdrs(t *testing.T) { } else if len(reply) != 1 { t.Error("Unexpected number of CDRs returned: ", len(reply)) } else { - if reply[0].Source != "freeswitch_json" { + if reply[0].Source != "freeswitch_json" && reply[0].Source != "SMG_KamailioAgent" { t.Errorf("Unexpected Source for CDR: %+v", reply[0].Source) } if reply[0].RequestType != utils.META_POSTPAID { @@ -441,15 +466,20 @@ func testCall1002Cdrs(t *testing.T) { func testCallStatMetrics(t *testing.T) { var metrics map[string]string - expectedMetrics := map[string]string{ + expectedMetrics1 := map[string]string{ utils.MetaTCC: "1.35009", utils.MetaTCD: "2m25s", } + expectedMetrics2 := map[string]string{ + utils.MetaTCC: "1.34009", + utils.MetaTCD: "2m24s", + } if err := tutFsCallsRpc.Call(utils.StatSv1GetQueueStringMetrics, &utils.TenantID{Tenant: "cgrates.org", ID: "Stats2"}, &metrics); err != nil { t.Error(err) - } else if !reflect.DeepEqual(expectedMetrics, metrics) { - t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics) + } else if !reflect.DeepEqual(expectedMetrics1, metrics) && + !reflect.DeepEqual(expectedMetrics2, metrics) { + t.Errorf("expecting: %+v, received reply: %s", expectedMetrics1, metrics) } } @@ -513,9 +543,11 @@ func testCallStopCgrEngine(t *testing.T) { } func testCallStopFS(t *testing.T) { - if optConf == "freeswitch" { - engine.KillProcName("freeswitch", 1000) - } else if optConf == "kamailio" { - engine.KillProcName("kamailio", 1000) + if optConf == utils.Freeswitch { + engine.KillProcName(utils.Freeswitch, 1000) + } else if optConf == utils.Kamailio { + engine.KillProcName(utils.Kamailio, 1000) + } else if optConf == utils.Opensips { + engine.KillProcName(utils.Opensips, 1000) } } diff --git a/sessions/sessions.go b/sessions/sessions.go index 252c84bf2..126904e32 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -730,7 +730,7 @@ func (smg *SMGeneric) InitiateSession(gev SMGenericEvent, clnt rpcclient.RpcClie return } if smg.cgrCfg.SessionSCfg().DebitInterval != 0 { // Session handled by debit loop - maxUsage = time.Duration(-1 * time.Second) + maxUsage = time.Duration(-1) return } maxUsage, err = smg.UpdateSession(gev, clnt) @@ -793,7 +793,7 @@ func (smg *SMGeneric) UpdateSession(gev SMGenericEvent, clnt rpcclient.RpcClient defer smg.replicateSessionsWithID(gev.GetCGRID(utils.META_DEFAULT), false, smg.smgReplConns) for _, s := range aSessions[cgrID] { if s.RunID == utils.META_NONE { - maxUsage = time.Duration(-1 * time.Second) + maxUsage = time.Duration(-1) continue } var maxDur time.Duration @@ -1358,6 +1358,12 @@ func (smg *SMGeneric) BiRPCv1AuthorizeEvent(clnt rpcclient.RpcClientConnection, !args.GetMaxUsage && !args.GetSuppliers { return utils.NewErrMandatoryIeMissing("subsystems") } + if args.CGREvent.Tenant == "" { + args.CGREvent.Tenant = smg.cgrCfg.DefaultTenant + } + if args.CGREvent.ID == "" { + args.CGREvent.ID = utils.GenUUID() + } if args.GetAttributes { if smg.attrS == nil { return utils.NewErrNotConnected(utils.AttributeS) @@ -1479,6 +1485,7 @@ func (smg *SMGeneric) BiRPCv1AuthorizeEventWithDigest(clnt rpcclient.RpcClientCo !args.GetMaxUsage && !args.GetSuppliers { return utils.NewErrMandatoryIeMissing("subsystems") } + var initAuthRply V1AuthorizeReply if err = smg.BiRPCv1AuthorizeEvent(clnt, args, &initAuthRply); err != nil { return @@ -1490,7 +1497,10 @@ func (smg *SMGeneric) BiRPCv1AuthorizeEventWithDigest(clnt rpcclient.RpcClientCo authReply.ResourceAllocation = initAuthRply.ResourceAllocation } if args.GetMaxUsage { - authReply.MaxUsage = utils.Float64Pointer(initAuthRply.MaxUsage.Seconds()) + authReply.MaxUsage = utils.Float64Pointer(-1.0) + if *initAuthRply.MaxUsage != time.Duration(-1) { + authReply.MaxUsage = utils.Float64Pointer(initAuthRply.MaxUsage.Seconds()) + } } if args.GetSuppliers { authReply.SuppliersDigest = utils.StringPointer(initAuthRply.Suppliers.Digest()) @@ -1544,6 +1554,12 @@ func (smg *SMGeneric) BiRPCv1InitiateSession(clnt rpcclient.RpcClientConnection, if !args.GetAttributes && !args.AllocateResources && !args.InitSession { return utils.NewErrMandatoryIeMissing("subsystems") } + if args.CGREvent.Tenant == "" { + args.CGREvent.Tenant = smg.cgrCfg.DefaultTenant + } + if args.CGREvent.ID == "" { + args.CGREvent.ID = utils.GenUUID() + } if args.GetAttributes { if smg.attrS == nil { return utils.NewErrNotConnected(utils.AttributeS) @@ -1662,6 +1678,12 @@ func (smg *SMGeneric) BiRPCv1UpdateSession(clnt rpcclient.RpcClientConnection, if !args.GetAttributes && !args.UpdateSession { return utils.NewErrMandatoryIeMissing("subsystems") } + if args.CGREvent.Tenant == "" { + args.CGREvent.Tenant = smg.cgrCfg.DefaultTenant + } + if args.CGREvent.ID == "" { + args.CGREvent.ID = utils.GenUUID() + } if args.GetAttributes { if smg.attrS == nil { return utils.NewErrNotConnected(utils.AttributeS) @@ -1705,6 +1727,12 @@ func (smg *SMGeneric) BiRPCv1TerminateSession(clnt rpcclient.RpcClientConnection if !args.TerminateSession && !args.ReleaseResources { return utils.NewErrMandatoryIeMissing("subsystems") } + if args.CGREvent.Tenant == "" { + args.CGREvent.Tenant = smg.cgrCfg.DefaultTenant + } + if args.CGREvent.ID == "" { + args.CGREvent.ID = utils.GenUUID() + } if args.TerminateSession { if smg.rals == nil { return utils.NewErrNotConnected(utils.RALService) @@ -1795,6 +1823,12 @@ type V1ProcessEventReply struct { // Called on session end, should send the CDR to CDRS func (smg *SMGeneric) BiRPCv1ProcessEvent(clnt rpcclient.RpcClientConnection, args *V1ProcessEventArgs, rply *V1ProcessEventReply) (err error) { + if args.CGREvent.Tenant == "" { + args.CGREvent.Tenant = smg.cgrCfg.DefaultTenant + } + if args.CGREvent.ID == "" { + args.CGREvent.ID = utils.GenUUID() + } if args.AllocateResources { if smg.resS == nil { return utils.NewErrNotConnected(utils.ResourceS) diff --git a/utils/consts.go b/utils/consts.go index 31644265d..ec8ab428d 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -516,11 +516,7 @@ const ( Cost = "Cost" RatingPlanID = "RatingPlanID" MetaSessionS = "*sessions" - FreeSWITCHAgent = "FreeSWITCHAgent" MetaDefault = "*default" - KamailioAgent = "KamailioAgent" - RadiusAgent = "RadiusAgent" - DiameterAgent = "DiameterAgent" Error = "Error" MetaCGRReply = "*cgrReply" CacheS = "CacheS" @@ -531,14 +527,16 @@ const ( Substitute = "Substitute" Append = "Append" MetaRound = "*round" - LoaderS = "LoaderS" Pong = "Pong" MetaEventCost = "*event_cost" MetaSuppliersEventCost = "*suppliers_event_cost" MetaSuppliersIgnoreErrors = "*suppliers_ignore_errors" + Freeswitch = "freeswitch" + Kamailio = "kamailio" + Opensips = "opensips" ) -//MetaMetrics +// MetaMetrics const ( MetaASR = "*asr" MetaACD = "*acd" @@ -551,7 +549,7 @@ const ( MetaAverage = "*average" ) -//Services +// Services const ( SessionS = "SessionS" AttributeS = "AttributeS" @@ -561,6 +559,7 @@ const ( FilterS = "FilterS" ThresholdS = "ThresholdS" DispatcherS = "DispatcherS" + LoaderS = "LoaderS" ) // Lower service names @@ -575,7 +574,7 @@ const ( LoaderLow = "loader" ) -//Migrator Metas +// Migrator Metas const ( MetaSetVersions = "*set_versions" MetaTpRatingPlans = "*tp_rating_plans" @@ -702,13 +701,11 @@ const ( ) // Scheduler - const ( SchedulerPing = "Scheduler.Ping" ) // Cdrc - const ( CdrcPing = "Cdrc.Ping" ) @@ -739,7 +736,7 @@ const ( AttributesCsv = "Attributes.csv" ) -//Table Name +// Table Name const ( TBLTPTimings = "tp_timings" TBLTPDestinations = "tp_destinations" @@ -768,7 +765,7 @@ const ( TBLVersions = "versions" ) -//Cache Name +// Cache Name const ( CacheDestinations = "destinations" CacheReverseDestinations = "reverse_destinations" @@ -809,7 +806,7 @@ const ( MetaReady = "*ready" ) -//Prefix for indexing +// Prefix for indexing const ( ResourceFilterIndexes = "rfi_" ResourceFilterRevIndexes = "rfr_" @@ -823,6 +820,14 @@ const ( AttributeFilterRevIndexes = "afr_" ) +// Agents +const ( + KamailioAgent = "KamailioAgent" + RadiusAgent = "RadiusAgent" + DiameterAgent = "DiameterAgent" + FreeSWITCHAgent = "FreeSWITCHAgent" +) + func buildCacheInstRevPrefixes() { CachePrefixToInstance = make(map[string]string) for k, v := range CacheInstanceToPrefix {