From c5b472c93a82377984b529d7f9db3c67a8d4493b Mon Sep 17 00:00:00 2001 From: Trial97 Date: Tue, 19 May 2020 09:05:17 +0300 Subject: [PATCH] Updated SipAgent template --- agents/sipagent_it_test.go | 2 +- .../samples/sipagent_internal/redirect.json | 37 +++++++++++++------ .../conf/samples/sipagent_mongo/redirect.json | 37 +++++++++++++------ .../conf/samples/sipagent_mysql/redirect.json | 37 +++++++++++++------ data/tariffplans/sipagent/AccountActions.csv | 2 + data/tariffplans/sipagent/ActionPlans.csv | 2 + data/tariffplans/sipagent/Actions.csv | 2 + data/tariffplans/sipagent/RatingProfiles.csv | 4 ++ data/tariffplans/sipagent/Routes.csv | 6 +-- engine/responder.go | 5 ++- engine/routes.go | 2 +- 11 files changed, 96 insertions(+), 40 deletions(-) create mode 100644 data/tariffplans/sipagent/AccountActions.csv create mode 100644 data/tariffplans/sipagent/ActionPlans.csv create mode 100644 data/tariffplans/sipagent/Actions.csv create mode 100644 data/tariffplans/sipagent/RatingProfiles.csv diff --git a/agents/sipagent_it_test.go b/agents/sipagent_it_test.go index 6f24ba37b5..edac52eeca 100644 --- a/agents/sipagent_it_test.go +++ b/agents/sipagent_it_test.go @@ -183,7 +183,7 @@ func testSAitSIPInvite(t *testing.T) { if expected := "SIP/2.0 302 Moved Temporarily"; recived["Request"] != expected { t.Errorf("Expected %q, received: %q", expected, recived["Request"]) } - if expected := "\"1002\" ;q=0.7; expires=3600,\"1002\" ;q=0.1"; recived["Contact"] != expected { + if expected := "\"1002\" ;q=0.7; expires=3600;cgr_cost=0.3;cgr_maxusage=60000000000,\"1002\" ;q=0.2;cgr_cost=0.6;cgr_maxusage=60000000000,\"1002\" ;q=0.1;cgr_cost=0.01;cgr_maxusage=60000000000"; recived["Contact"] != expected { t.Errorf("Expected %q, received: %q", expected, recived["Contact"]) } } diff --git a/data/conf/samples/sipagent_internal/redirect.json b/data/conf/samples/sipagent_internal/redirect.json index 268ab9c8b3..a879764102 100644 --- a/data/conf/samples/sipagent_internal/redirect.json +++ b/data/conf/samples/sipagent_internal/redirect.json @@ -13,7 +13,7 @@ ] }, { - "id": "NAPTRRoutesQuery", + "id": "RoutesQuery", "filters": ["*string:~*vars.Method:INVITE"], "flags": ["*event", "*routes","*continue"], "request_fields":[ @@ -30,10 +30,9 @@ ] }, { - "id": "NAPTRSuppliersOneSupplier", + "id": "RoutesQueryOneRoute", "filters": ["*string:~*vars.Method:INVITE", "*gte:~*cgrep.Routes.Count:1", - "*gte:~*cgrep.Routes.SortedRoutes[0].SortingData.Cost:0.1", ], "flags": ["*none","*continue"], // do not send request to CGRateS "reply_fields":[ @@ -52,14 +51,19 @@ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value": "~*cgrep.Routes.SortedRoutes[0].RouteParameters"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"*constant:>;q=0.7; expires=3600"} + "value":"*constant:>;q=0.7; expires=3600;cgr_cost="}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"~*cgrep.Routes.SortedRoutes[0].SortingData.Cost"}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"*constant:;cgr_maxusage="}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"~*cgrep.Routes.SortedRoutes[0].SortingData.MaxUsage"} ] }, { - "id": "NAPTRSuppliersTwoSuppliers", + "id": "RoutesQueryTwoRoutes", "filters": ["*string:~*vars.Method:INVITE", "*gte:~*cgrep.Routes.Count:2", - "*gte:~*cgrep.Routes.SortedRoutes[1].SortingData.Cost:0.1", ], "flags": ["*none","*continue"], "reply_fields":[ @@ -76,14 +80,19 @@ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value": "~*cgrep.Routes.SortedRoutes[1].RouteParameters"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"*constant:>;q=0.1"} + "value":"*constant:>;q=0.2;cgr_cost="}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"~*cgrep.Routes.SortedRoutes[1].SortingData.Cost"}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"*constant:;cgr_maxusage="}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"~*cgrep.Routes.SortedRoutes[1].SortingData.MaxUsage"} ] }, { - "id": "NAPTRSuppliersThreeSuppliers", + "id": "RoutesQueryThreeRoutes", "filters": ["*string:~*vars.Method:INVITE", "*gte:~*cgrep.Routes.Count:3", - "*gte:~*cgrep.Routes.SortedRoutes[2].SortingData.Cost:0.1", ], "flags": ["*none","*continue"], "reply_fields":[ @@ -98,9 +107,15 @@ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"@"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value": "~*cgrep.Routes.SortedRoutes[2].RouteParameters"}, + "value": "~*cgrep.Routes.SortedRoutes[2].RouteParameters"}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"*constant:>;q=0.1;cgr_cost="}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"~*cgrep.Routes.SortedRoutes[2].SortingData.Cost"}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"*constant:;cgr_maxusage="}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"*constant:>;q=0.1"} + "value":"~*cgrep.Routes.SortedRoutes[2].SortingData.MaxUsage"} ] } ] diff --git a/data/conf/samples/sipagent_mongo/redirect.json b/data/conf/samples/sipagent_mongo/redirect.json index 268ab9c8b3..a879764102 100644 --- a/data/conf/samples/sipagent_mongo/redirect.json +++ b/data/conf/samples/sipagent_mongo/redirect.json @@ -13,7 +13,7 @@ ] }, { - "id": "NAPTRRoutesQuery", + "id": "RoutesQuery", "filters": ["*string:~*vars.Method:INVITE"], "flags": ["*event", "*routes","*continue"], "request_fields":[ @@ -30,10 +30,9 @@ ] }, { - "id": "NAPTRSuppliersOneSupplier", + "id": "RoutesQueryOneRoute", "filters": ["*string:~*vars.Method:INVITE", "*gte:~*cgrep.Routes.Count:1", - "*gte:~*cgrep.Routes.SortedRoutes[0].SortingData.Cost:0.1", ], "flags": ["*none","*continue"], // do not send request to CGRateS "reply_fields":[ @@ -52,14 +51,19 @@ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value": "~*cgrep.Routes.SortedRoutes[0].RouteParameters"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"*constant:>;q=0.7; expires=3600"} + "value":"*constant:>;q=0.7; expires=3600;cgr_cost="}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"~*cgrep.Routes.SortedRoutes[0].SortingData.Cost"}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"*constant:;cgr_maxusage="}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"~*cgrep.Routes.SortedRoutes[0].SortingData.MaxUsage"} ] }, { - "id": "NAPTRSuppliersTwoSuppliers", + "id": "RoutesQueryTwoRoutes", "filters": ["*string:~*vars.Method:INVITE", "*gte:~*cgrep.Routes.Count:2", - "*gte:~*cgrep.Routes.SortedRoutes[1].SortingData.Cost:0.1", ], "flags": ["*none","*continue"], "reply_fields":[ @@ -76,14 +80,19 @@ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value": "~*cgrep.Routes.SortedRoutes[1].RouteParameters"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"*constant:>;q=0.1"} + "value":"*constant:>;q=0.2;cgr_cost="}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"~*cgrep.Routes.SortedRoutes[1].SortingData.Cost"}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"*constant:;cgr_maxusage="}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"~*cgrep.Routes.SortedRoutes[1].SortingData.MaxUsage"} ] }, { - "id": "NAPTRSuppliersThreeSuppliers", + "id": "RoutesQueryThreeRoutes", "filters": ["*string:~*vars.Method:INVITE", "*gte:~*cgrep.Routes.Count:3", - "*gte:~*cgrep.Routes.SortedRoutes[2].SortingData.Cost:0.1", ], "flags": ["*none","*continue"], "reply_fields":[ @@ -98,9 +107,15 @@ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"@"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value": "~*cgrep.Routes.SortedRoutes[2].RouteParameters"}, + "value": "~*cgrep.Routes.SortedRoutes[2].RouteParameters"}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"*constant:>;q=0.1;cgr_cost="}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"~*cgrep.Routes.SortedRoutes[2].SortingData.Cost"}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"*constant:;cgr_maxusage="}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"*constant:>;q=0.1"} + "value":"~*cgrep.Routes.SortedRoutes[2].SortingData.MaxUsage"} ] } ] diff --git a/data/conf/samples/sipagent_mysql/redirect.json b/data/conf/samples/sipagent_mysql/redirect.json index 268ab9c8b3..a879764102 100644 --- a/data/conf/samples/sipagent_mysql/redirect.json +++ b/data/conf/samples/sipagent_mysql/redirect.json @@ -13,7 +13,7 @@ ] }, { - "id": "NAPTRRoutesQuery", + "id": "RoutesQuery", "filters": ["*string:~*vars.Method:INVITE"], "flags": ["*event", "*routes","*continue"], "request_fields":[ @@ -30,10 +30,9 @@ ] }, { - "id": "NAPTRSuppliersOneSupplier", + "id": "RoutesQueryOneRoute", "filters": ["*string:~*vars.Method:INVITE", "*gte:~*cgrep.Routes.Count:1", - "*gte:~*cgrep.Routes.SortedRoutes[0].SortingData.Cost:0.1", ], "flags": ["*none","*continue"], // do not send request to CGRateS "reply_fields":[ @@ -52,14 +51,19 @@ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value": "~*cgrep.Routes.SortedRoutes[0].RouteParameters"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"*constant:>;q=0.7; expires=3600"} + "value":"*constant:>;q=0.7; expires=3600;cgr_cost="}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"~*cgrep.Routes.SortedRoutes[0].SortingData.Cost"}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"*constant:;cgr_maxusage="}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"~*cgrep.Routes.SortedRoutes[0].SortingData.MaxUsage"} ] }, { - "id": "NAPTRSuppliersTwoSuppliers", + "id": "RoutesQueryTwoRoutes", "filters": ["*string:~*vars.Method:INVITE", "*gte:~*cgrep.Routes.Count:2", - "*gte:~*cgrep.Routes.SortedRoutes[1].SortingData.Cost:0.1", ], "flags": ["*none","*continue"], "reply_fields":[ @@ -76,14 +80,19 @@ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value": "~*cgrep.Routes.SortedRoutes[1].RouteParameters"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"*constant:>;q=0.1"} + "value":"*constant:>;q=0.2;cgr_cost="}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"~*cgrep.Routes.SortedRoutes[1].SortingData.Cost"}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"*constant:;cgr_maxusage="}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"~*cgrep.Routes.SortedRoutes[1].SortingData.MaxUsage"} ] }, { - "id": "NAPTRSuppliersThreeSuppliers", + "id": "RoutesQueryThreeRoutes", "filters": ["*string:~*vars.Method:INVITE", "*gte:~*cgrep.Routes.Count:3", - "*gte:~*cgrep.Routes.SortedRoutes[2].SortingData.Cost:0.1", ], "flags": ["*none","*continue"], "reply_fields":[ @@ -98,9 +107,15 @@ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"@"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value": "~*cgrep.Routes.SortedRoutes[2].RouteParameters"}, + "value": "~*cgrep.Routes.SortedRoutes[2].RouteParameters"}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"*constant:>;q=0.1;cgr_cost="}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"~*cgrep.Routes.SortedRoutes[2].SortingData.Cost"}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"*constant:;cgr_maxusage="}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"*constant:>;q=0.1"} + "value":"~*cgrep.Routes.SortedRoutes[2].SortingData.MaxUsage"} ] } ] diff --git a/data/tariffplans/sipagent/AccountActions.csv b/data/tariffplans/sipagent/AccountActions.csv new file mode 100644 index 0000000000..44fa1907f3 --- /dev/null +++ b/data/tariffplans/sipagent/AccountActions.csv @@ -0,0 +1,2 @@ +#Tenant,Account,ActionPlanId,ActionTriggersId,AllowNegative,Disabled +cgrates.org,1001,AP_PACKAGE_10,,, \ No newline at end of file diff --git a/data/tariffplans/sipagent/ActionPlans.csv b/data/tariffplans/sipagent/ActionPlans.csv new file mode 100644 index 0000000000..b10e827b50 --- /dev/null +++ b/data/tariffplans/sipagent/ActionPlans.csv @@ -0,0 +1,2 @@ +#Id,ActionsId,TimingId,Weight +AP_PACKAGE_10,ACT_TOPUP_RST_10,*asap,10 \ No newline at end of file diff --git a/data/tariffplans/sipagent/Actions.csv b/data/tariffplans/sipagent/Actions.csv new file mode 100644 index 0000000000..deebe11934 --- /dev/null +++ b/data/tariffplans/sipagent/Actions.csv @@ -0,0 +1,2 @@ +#ActionsId[0],Action[1],ExtraParameters[2],Filter[3],BalanceId[4],BalanceType[5],Categories[6],DestinationIds[7],RatingSubject[8],SharedGroup[9],ExpiryTime[10],TimingIds[11],Units[12],BalanceWeight[13],BalanceBlocker[14],BalanceDisabled[15],Weight[16] +ACT_TOPUP_RST_10,*topup_reset,,,test,*monetary,,*any,,,*unlimited,,10,10,false,false,10 \ No newline at end of file diff --git a/data/tariffplans/sipagent/RatingProfiles.csv b/data/tariffplans/sipagent/RatingProfiles.csv new file mode 100644 index 0000000000..e92b3cf6f7 --- /dev/null +++ b/data/tariffplans/sipagent/RatingProfiles.csv @@ -0,0 +1,4 @@ +#Tenant,Category,Subject,ActivationTime,RatingPlanId,RatesFallbackSubject +cgrates.org,*routes,1001,2014-01-14T00:00:00Z,RP_10CNT, +cgrates.org,*routes,1002,2014-01-14T00:00:00Z,RP_10CNT, + diff --git a/data/tariffplans/sipagent/Routes.csv b/data/tariffplans/sipagent/Routes.csv index 2afc6f1c8a..d3d0d4197e 100644 --- a/data/tariffplans/sipagent/Routes.csv +++ b/data/tariffplans/sipagent/Routes.csv @@ -1,5 +1,5 @@ #Tenant,ID,FilterIDs,ActivationInterval,Sorting,SortingParameters,RouteID,RouteFilterIDs,RouteAccountIDs,RouteRatingPlanIDs,RouteResourceIDs,RouteStatIDs,RouteWeight,RouteBlocker,RouteParameters,Weight -cgrates.org,SPL_ACNT_1001,*string:~*req.Account:1001,2017-11-27T00:00:00Z,*weight,,supplier1,,,RP_10CNT,,,20,,cgrates.org,20 -cgrates.org,SPL_ACNT_1001,,,,,supplier2,,,RP_20CNT,,,10,,cgrates.net,10 -cgrates.org,SPL_ACNT_1001,,,,,supplier3,,,RP_1CNT,,,5,,cgrates.com,5 +cgrates.org,SPL_ACNT_1001,*string:~*req.Account:1001,2017-11-27T00:00:00Z,*weight,,supplier1,,1001,RP_10CNT,,,20,,cgrates.org,20 +cgrates.org,SPL_ACNT_1001,,,,,supplier2,,1001,RP_20CNT,,,10,,cgrates.net,10 +cgrates.org,SPL_ACNT_1001,,,,,supplier3,,1001,RP_1CNT,,,5,,cgrates.com,5 diff --git a/engine/responder.go b/engine/responder.go index ea66570b1b..57b13972b8 100644 --- a/engine/responder.go +++ b/engine/responder.go @@ -332,8 +332,9 @@ func (rs *Responder) GetMaxSessionTimeOnAccounts(arg *utils.GetMaxSessionTimeOnA utils.Responder, anctID, err.Error())) } else if maxDur >= arg.Usage { *reply = map[string]interface{}{ - utils.Cost: 0.0, - utils.Account: anctID, + utils.CapMaxUsage: maxDur, + utils.Cost: 0.0, + utils.Account: anctID, } return nil } diff --git a/engine/routes.go b/engine/routes.go index 884482fc25..6bba811f4e 100644 --- a/engine/routes.go +++ b/engine/routes.go @@ -220,7 +220,7 @@ func (rpS *RouteService) costForEvent(ev *utils.CGREvent, if acnt, err = ev.FieldAsString(utils.Account); err != nil { return } - if subj, err = ev.FieldAsString(utils.Account); err != nil { + if subj, err = ev.FieldAsString(utils.Subject); err != nil { if err != utils.ErrNotFound { return }