From dcc474646f092c41541ef8a977e63e3b8c47578c Mon Sep 17 00:00:00 2001 From: DanB Date: Mon, 11 May 2015 08:59:34 +0200 Subject: [PATCH] Completing opensips_async tutorial, remove debug info in sessionmanager --- .../opensips/etc/opensips/opensips.cfg | 82 +++++++++++-------- general_tests/tutorial_osips_calls_test.go | 12 +-- sessionmanager/osipsevent.go | 1 - 3 files changed, 53 insertions(+), 42 deletions(-) diff --git a/data/tutorials/osips_async/opensips/etc/opensips/opensips.cfg b/data/tutorials/osips_async/opensips/etc/opensips/opensips.cfg index 96b5d7d74..f46b98f8f 100644 --- a/data/tutorials/osips_async/opensips/etc/opensips/opensips.cfg +++ b/data/tutorials/osips_async/opensips/etc/opensips/opensips.cfg @@ -128,8 +128,39 @@ local_route { } } -# main request routing logic +## Send AUTH request to CGRateS engine +route[CGR_AUTH_REQ] { + # Code to produce the json + $json(cgr_auth) := "{}"; + $json(cgr_auth/id) = "1"; + $json(cgr_auth/method) = "ApierV1.GetMaxSessionTime"; + $json(cgr_auth/params) := "[{}]"; + $json(cgr_auth/params[0]/ReqType) = $avp(cgr_reqtype); + $json(cgr_auth/params[0]/Account) = $avp(cgr_account); + $json(cgr_auth/params[0]/Destination) = $avp(cgr_destination); + $json(cgr_auth/params[0]/DialogId) = $DLG_did; + async(rest_post("http://127.0.0.1:2080/jsonrpc", "$json(cgr_auth)", "application/json", "$avp(cgr_auth_reply)", "$var(ct)", "$var(rcode)"), CGR_AUTH_REPLY); +} +## Process answer received from CGRateS engine +route[CGR_AUTH_REPLY] { + $json(cgr_auth_reply) := $avp(cgr_auth_reply); + xlog("In CGR_AUTH_REPLY, reply received: $json(cgr_auth_reply)"); + if $json(cgr_auth_reply/error) != NULL { + xlog("Error received from CGRateS: $json(cgr_auth_reply/error)"); + sl_send_reply("503","Charging controller error"); + exit; + } else if $json(cgr_auth_reply/result) == 0 { + sl_send_reply("403","Payment required"); + exit; + } else if $json(cgr_auth_reply/result) > -1 { + $DLG_timeout=$json(cgr_auth_reply/result); + } + route(location); + route(relay); +} + +# main request routing logic route{ @@ -222,7 +253,21 @@ route{ send_reply("500","Internal Server Error"); exit; } - $avp(cgr_reqtype)="*prepaid"; + switch ($fU) { + case "1001": + case "1006": + case "1007": + $avp(cgr_reqtype) = "*prepaid"; + break; + case "1002": + $avp(cgr_reqtype) = "*postpaid"; + break; + case "1003": + $avp(cgr_reqtype) = "*pseudoprepaid"; + break; + default: + $avp(cgr_reqtype) = "*rated"; + } $avp(cgr_account)=$fU; $avp(cgr_destination)=$rU; $avp(cgr_supplier)="supplier1"; @@ -262,39 +307,6 @@ route{ route(relay); } -## Send AUTH request to CGRateS engine -route[CGR_AUTH_REQ] { - # Code to produce the json - $json(cgr_auth) := "{}"; - $json(cgr_auth/id) = "1"; - $json(cgr_auth/method) = "ApierV1.GetMaxSessionTime"; - $json(cgr_auth/params) := "[{}]"; - $json(cgr_auth/params[0]/ReqType) = $avp(cgr_reqtype); - $json(cgr_auth/params[0]/Account) = $avp(cgr_account); - $json(cgr_auth/params[0]/Destination) = $avp(cgr_destination); - $json(cgr_auth/params[0]/DialogId) = $DLG_did; - async(rest_post("http://127.0.0.1:2080/jsonrpc", "$json(cgr_auth)", "application/json", "$avp(cgr_auth_reply)", "$var(ct)", "$var(rcode)"), CGR_AUTH_REPLY); -} - -## Process answer received from CGRateS engine -route[CGR_AUTH_REPLY] { - $json(cgr_auth_reply) := $avp(cgr_auth_reply); - xlog("In CGR_AUTH_REPLY, reply received: $json(cgr_auth_reply)"); - if $json(cgr_auth_reply/error) != NULL { - xlog("Error received from CGRateS: $json(cgr_auth_reply/error)"); - sl_send_reply("503","Charging controller error"); - exit; - } else if $json(cgr_auth_reply/result) == 0 { - sl_send_reply("403","Payment required"); - exit; - } else if $json(cgr_auth_reply/result) > -1 { - $DLG_timeout=$json(cgr_auth_reply/result); - } - route(location); - route(relay); -} - - route[relay] { # for INVITEs enable some additional helper routes if (is_method("INVITE") && !has_totag()) { diff --git a/general_tests/tutorial_osips_calls_test.go b/general_tests/tutorial_osips_calls_test.go index 9328beeb5..d5faf1ea1 100644 --- a/general_tests/tutorial_osips_calls_test.go +++ b/general_tests/tutorial_osips_calls_test.go @@ -293,7 +293,7 @@ func TestTutOsipsCallsCdrs(t *testing.T) { } else if len(reply) != 1 { t.Error("Unexpected number of CDRs returned: ", len(reply)) } else { - if reply[0].CdrSource != "KAMAILIO_CGR_CALL_END" { + if reply[0].CdrSource != "OSIPS_E_ACC_EVENT" { t.Errorf("Unexpected CdrSource for CDR: %+v", reply[0]) } if reply[0].ReqType != utils.META_PREPAID { @@ -322,7 +322,7 @@ func TestTutOsipsCallsCdrs(t *testing.T) { } else if len(reply) != 1 { t.Error("Unexpected number of CDRs returned: ", len(reply)) } else { - if reply[0].CdrSource != "KAMAILIO_CGR_CALL_END" { + if reply[0].CdrSource != "OSIPS_E_ACC_EVENT" { t.Errorf("Unexpected CdrSource for CDR: %+v", reply[0]) } if reply[0].ReqType != utils.META_POSTPAID { @@ -341,7 +341,7 @@ func TestTutOsipsCallsCdrs(t *testing.T) { } else if len(reply) != 1 { t.Error("Unexpected number of CDRs returned: ", len(reply)) } else { - if reply[0].CdrSource != "KAMAILIO_CGR_CALL_END" { + if reply[0].CdrSource != "OSIPS_E_ACC_EVENT" { t.Errorf("Unexpected CdrSource for CDR: %+v", reply[0]) } if reply[0].ReqType != utils.META_PSEUDOPREPAID { @@ -360,7 +360,7 @@ func TestTutOsipsCallsCdrs(t *testing.T) { } else if len(reply) != 1 { t.Error("Unexpected number of CDRs returned: ", len(reply)) } else { - if reply[0].CdrSource != "KAMAILIO_CGR_CALL_END" { + if reply[0].CdrSource != "OSIPS_E_ACC_EVENT" { t.Errorf("Unexpected CdrSource for CDR: %+v", reply[0]) } if reply[0].ReqType != utils.META_RATED { @@ -379,7 +379,7 @@ func TestTutOsipsCallsCdrs(t *testing.T) { } else if len(reply) != 1 { t.Error("Unexpected number of CDRs returned: ", len(reply)) } else { - if reply[0].CdrSource != "KAMAILIO_CGR_CALL_END" { + if reply[0].CdrSource != "OSIPS_E_ACC_EVENT" { t.Errorf("Unexpected CdrSource for CDR: %+v", reply[0]) } if reply[0].ReqType != utils.META_PREPAID { @@ -398,7 +398,7 @@ func TestTutOsipsCallsCdrs(t *testing.T) { } else if len(reply) != 1 { t.Error("Unexpected number of CDRs returned: ", len(reply)) } else { - if reply[0].CdrSource != "KAMAILIO_CGR_CALL_END" { + if reply[0].CdrSource != "OSIPS_E_ACC_EVENT" { t.Errorf("Unexpected CdrSource for CDR: %+v", reply[0]) } if reply[0].ReqType != utils.META_PREPAID { diff --git a/sessionmanager/osipsevent.go b/sessionmanager/osipsevent.go index 017261db3..d73c156f9 100644 --- a/sessionmanager/osipsevent.go +++ b/sessionmanager/osipsevent.go @@ -188,7 +188,6 @@ func (osipsEv *OsipsEvent) GetOriginatorIP(fieldName string) string { return osipsEv.osipsEvent.OriginatorAddress.IP.String() } func (osipsev *OsipsEvent) MissingParameter() bool { - engine.Logger.Debug(fmt.Sprintf("Missing parameters on: %+v", osipsev.osipsEvent)) var nilTime time.Time if osipsev.GetName() == "E_ACC_EVENT" && osipsev.osipsEvent.AttrValues["method"] == "INVITE" { return len(osipsev.GetUUID()) == 0 ||