Skip to content

Commit

Permalink
Updated SipAgent template
Browse files Browse the repository at this point in the history
  • Loading branch information
Trial97 authored and danbogos committed May 20, 2020
1 parent 24b2206 commit c5b472c
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 40 deletions.
2 changes: 1 addition & 1 deletion agents/sipagent_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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\" <sip:[email protected]>;q=0.7; expires=3600,\"1002\" <sip:[email protected]>;q=0.1"; recived["Contact"] != expected {
if expected := "\"1002\" <sip:[email protected]>;q=0.7; expires=3600;cgr_cost=0.3;cgr_maxusage=60000000000,\"1002\" <sip:[email protected]>;q=0.2;cgr_cost=0.6;cgr_maxusage=60000000000,\"1002\" <sip:[email protected]>;q=0.1;cgr_cost=0.01;cgr_maxusage=60000000000"; recived["Contact"] != expected {
t.Errorf("Expected %q, received: %q", expected, recived["Contact"])
}
}
37 changes: 26 additions & 11 deletions data/conf/samples/sipagent_internal/redirect.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
]
},
{
"id": "NAPTRRoutesQuery",
"id": "RoutesQuery",
"filters": ["*string:~*vars.Method:INVITE"],
"flags": ["*event", "*routes","*continue"],
"request_fields":[
Expand All @@ -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":[
Expand All @@ -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":[
Expand All @@ -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":[
Expand All @@ -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"}
]
}
]
Expand Down
37 changes: 26 additions & 11 deletions data/conf/samples/sipagent_mongo/redirect.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
]
},
{
"id": "NAPTRRoutesQuery",
"id": "RoutesQuery",
"filters": ["*string:~*vars.Method:INVITE"],
"flags": ["*event", "*routes","*continue"],
"request_fields":[
Expand All @@ -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":[
Expand All @@ -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":[
Expand All @@ -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":[
Expand All @@ -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"}
]
}
]
Expand Down
37 changes: 26 additions & 11 deletions data/conf/samples/sipagent_mysql/redirect.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
]
},
{
"id": "NAPTRRoutesQuery",
"id": "RoutesQuery",
"filters": ["*string:~*vars.Method:INVITE"],
"flags": ["*event", "*routes","*continue"],
"request_fields":[
Expand All @@ -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":[
Expand All @@ -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":[
Expand All @@ -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":[
Expand All @@ -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"}
]
}
]
Expand Down
2 changes: 2 additions & 0 deletions data/tariffplans/sipagent/AccountActions.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Tenant,Account,ActionPlanId,ActionTriggersId,AllowNegative,Disabled
cgrates.org,1001,AP_PACKAGE_10,,,
2 changes: 2 additions & 0 deletions data/tariffplans/sipagent/ActionPlans.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Id,ActionsId,TimingId,Weight
AP_PACKAGE_10,ACT_TOPUP_RST_10,*asap,10
2 changes: 2 additions & 0 deletions data/tariffplans/sipagent/Actions.csv
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions data/tariffplans/sipagent/RatingProfiles.csv
Original file line number Diff line number Diff line change
@@ -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,

6 changes: 3 additions & 3 deletions data/tariffplans/sipagent/Routes.csv
Original file line number Diff line number Diff line change
@@ -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

5 changes: 3 additions & 2 deletions engine/responder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion engine/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit c5b472c

Please sign in to comment.