diff --git a/data/tariffplans/tutorial2/ActionTriggers.csv b/data/tariffplans/tutorial2/ActionTriggers.csv index 1b235191f..a81fc6763 100644 --- a/data/tariffplans/tutorial2/ActionTriggers.csv +++ b/data/tariffplans/tutorial2/ActionTriggers.csv @@ -1,7 +1,4 @@ #ID[0],UniqueID[1],ThresholdType[2],ThresholdValue[3],Recurrent[4],MinSleep[5],ExpiryTime[6],ActivationTime[7],BalanceTag[8],BalanceType[9],BalanceCategories[10],BalanceDestinationIDs[11],BalanceRatingSubject[12],BalanceSharedGroup[13],BalanceExpiryTime[14],BalanceTimingIDs[15],BalanceWeight[16],BalanceBlocker[17],BalanceDisabled[18],ActionsID[19],Weight[20] -# STANDARD_TRIGGERS *min_balance will call the action when the monetary balance will go bellow 2 units -STANDARD_TRIGGERS,,*min_balance,2,,,,,,*monetary,,,,,,,,,,TOPUP_BONUS_10SMS,10 - # STANDARD_TRIGGERS *max_balance will call action when the monetary balance will go above 100 units STANDARD_TRIGGERS,,*max_balance,100,,,,,,*monetary,,,,,,,,,,DISABLE_ACCOUNT,10 \ No newline at end of file diff --git a/data/tariffplans/tutorial2/Attributes.csv b/data/tariffplans/tutorial2/Attributes.csv index 51b0feab1..097ba6652 100644 --- a/data/tariffplans/tutorial2/Attributes.csv +++ b/data/tariffplans/tutorial2/Attributes.csv @@ -1,11 +1,12 @@ -# Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight - -# CRG_RESELLER1 replaces Category->reseller1 and RequestType->*rated for *sessions and *cdrs events -cgrates.org,ATTR_CRG_SUPPLIER1,*sessions;*cdrs,,,,*req.Category,*constant,reseller1,false,0 -cgrates.org,ATTR_CRG_SUPPLIER1,,,,,*req.RequestType,*constant,*rated,, - -# ATTR_1001_AUTH returns the Password value for the account 1001 in context -cgrates.org,ATTR_1001_AUTH,auth,*string:~*req.Account:1001,,,*req.Password,*constant,CGRateS.org,false,20 - -cgrates.org,ATTR_1002_AUTH,auth,*string:~*req.Account:1002,,,*req.Password,*constant,CGRateS.org,false,20 -cgrates.org,ATTR_1003_AUTH,auth,*string:~*req.Account:1003,,,*req.Password,*constant,CGRateS.org,false,20 \ No newline at end of file +#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight +cgrates.org,ATTR_1001,*any,*string:~*req.Account:1001,,,,,,false,10 +cgrates.org,ATTR_1001,,,,,*req.Password,*constant,CGRateS.org,, +cgrates.org,ATTR_1001,,,,,*req.RequestType,*constant,*prepaid,, +cgrates.org,ATTR_1001,,,,,*req.PaypalAccount,*constant,cgrates@paypal.com,, +cgrates.org,ATTR_1001,,,,,*req.LCRProfile,*constant,premium_cli,, +cgrates.org,ATTR_1002,*any,*string:~*req.Account:1002,,,,,,false,10 +cgrates.org,ATTR_1002,,,,,*req.Password,*constant,CGRateS.org,, +cgrates.org,ATTR_1002,,,,,*req.RequestType,*constant,*postpaid,, +cgrates.org,ATTR_1003,*any,*string:~*req.Account:1003,,,,,CGRateS.org,false,10 +cgrates.org,ATTR_1003,,,,,*req.Password,*constant,CGRateS.org,false,10 +cgrates.org,ATTR_1003,,,,,*req.RequestType,*constant,*pseudoprepaid,, \ No newline at end of file diff --git a/data/tariffplans/tutorial2/Chargers.csv b/data/tariffplans/tutorial2/Chargers.csv index 4343b8c7a..392d9aa4b 100644 --- a/data/tariffplans/tutorial2/Chargers.csv +++ b/data/tariffplans/tutorial2/Chargers.csv @@ -1,8 +1,3 @@ -# Tenant,ID,FilterIDs,ActivationInterval,RunID,AttributeIDs,Weight - -# CGR_DEFAULT is the default charger for events -cgrates.org,CGR_DEFAULT,,,*default,*none,0 - -# CGR_RESELLER1 creates an additional CDR for calculating reseller costs -# uses ATTR_CRG_RESELLER1 to replace Category and RequestType in events -cgrates.org,CRG_RESELLER1,,,reseller1,ATTR_CRG_RESELLER1,1 +#Tenant,ID,FilterIDs,ActivationInterval,RunID,AttributeIDs,Weight +cgrates.org,CHRG_DEFAULT,,,*default,*none,0 +cgrates.org,CHRG_SUPPLIER,*exists:~*req.Supplier:,,supplier,*constant:*req.RequestType:*rated;*constant:*req.Category:~*req.Supplier,0 \ No newline at end of file diff --git a/data/tariffplans/tutorial2/DestinationRates.csv b/data/tariffplans/tutorial2/DestinationRates.csv index d50ab9a2d..237f65861 100644 --- a/data/tariffplans/tutorial2/DestinationRates.csv +++ b/data/tariffplans/tutorial2/DestinationRates.csv @@ -1,13 +1,19 @@ #ID,DestinationsID,RatesID,RoundingMethod,RoundingDecimals,MaxCost,MaxCostStrategy -DR_10_120C,DST_10,RT_120C,*up,4,, -DR_10_60C,DST_10,RT_60C,*up,4,, -DR_2030_120C,DST_2030,RT_120C,*up,4,, -DR_20_60C,DST_20,RT_60C,*up,4,, -DR_VOICEMAIL_FREE,DST_VOICEMAIL,RT_0,*up,4,, -DR_1002_60C,DST_1002,RT_60C,*up,4,, -DR_ANY_10C_CN,*any,RT_10C_CN,*up,4,, -DR_ANY_1024_1,*any,RT_1024_1,*up,4,, -DR_1002_10C1,DST_1002,RT_10C1,*up,4,, -DR_10_20C1,DST_10,RT_20C1,*up,4,, -DR_1CNT,*any,RT_1CNT,*up,4,, -DR_10CNT,*any,RT_10CNT,*up,4,, \ No newline at end of file + +DR_DEFAULT,DST_10,RT_120_20_60,*up,5,, +DR_DEFAULT,DST_20,RT_180_10_60,*up,5,, +DR_DEFAULT,*any,RT_240_30_60,*up,5,, + +DR_1001,DST_20,RT_120_10_60,*up,5,, + +DR_SMS,DST_10,RT_5_1,*up,5,, +DR_SMS,*any,RT_10_1,*up,5,, + +DR_DATA,*any,RT_10_1024,*up,5,, + +DR_SPL1,DST_10,RT_60_60,*up,5,, +DR_SPL1,DST_20,RT_120_60,*up,5,, + +DR_SPL2,DST_10,RT_30_60,*up,5,, + +DR_SPECIAL_BLC,*any,RT_15_0_1,*up,5,, \ No newline at end of file diff --git a/data/tariffplans/tutorial2/Destinations.csv b/data/tariffplans/tutorial2/Destinations.csv index fe08093df..7cb167ee2 100644 --- a/data/tariffplans/tutorial2/Destinations.csv +++ b/data/tariffplans/tutorial2/Destinations.csv @@ -1,8 +1,3 @@ #ID,Prefix DST_10,10 DST_20,20 -DST_2030,20 -DST_2030,30 -DST_VOICEMAIL,voicemail -DST_1002,1002 -DST_50,50 diff --git a/data/tariffplans/tutorial2/Filters.csv b/data/tariffplans/tutorial2/Filters.csv new file mode 100644 index 000000000..d2110781e --- /dev/null +++ b/data/tariffplans/tutorial2/Filters.csv @@ -0,0 +1,2 @@ +#Tenant[0],ID[1],Type[2],Element[3],Values[4],ActivationInterval[5] +cgrates.org,FLTR_ACNT_1001_1002,*string,~*req.Account,1001;1002,2014-07-29T15:00:00Z diff --git a/data/tariffplans/tutorial2/Rates.csv b/data/tariffplans/tutorial2/Rates.csv index 0cc47ee69..b5d9afe40 100644 --- a/data/tariffplans/tutorial2/Rates.csv +++ b/data/tariffplans/tutorial2/Rates.csv @@ -1,29 +1,37 @@ #ID,ConnectFee,Rate,RateUnit,RateIncrement,GroupIntervalStart -# RT_120C charges 0.20 units as connect fee and 1.2 in 1 minute increment in the first minute and second increments after that -RT_120C,0.2,1.2,1m,1m,0 -RT_120C,,1.2,1m,1s,1m +# RT_120_20_60 charges 0.20 units as connect fee and 1.2 in 1 minute increment in the first minute and second increments after that ,,,,, +RT_120_20_60,0.2,1.2,1m,1m,0 +RT_120_20_60,,1.2,1m,1s,1m -# RT_60C charges 0.1 connect fee and 0.01 units each second -RT_60C,0.1,0.01,1s,1s,0 +# RT_180_10_60 charges 0.10 units as connect fee and 1.8 in 1 minute increment in the first minute and second increments after that ,,,,, +RT_180_10_60,0.1,1.8,1m,1m,0 +RT_180_10_60,,1.8,1m,1s,1m -# RT_0 charges 0 units rounding each call per minute -RT_0,0,0,1m,1m,0 +# RT_240_30_60 charges 0.3 units as connect fee and 2.4 in 1 minute increment in the first minute and second increments after that ,,,,, +RT_240_30_60,0.3,2.4,1m,1m,0 +RT_240_30_60,,2.4,1m,1s,1m -# RT_10C_CN charges 0.1 units as connect/call fee -RT_10C_CN,0.1,0,0,1s,0 +# RT_120_10_60 charges 0.1 units as connect fee and 1.2 in 1 minute increment ,,,,, +RT_120_10_60,0.1,1.2,1m,1m,0 -# RT_1024_1 will be used to charge 1 unit per every 1024 of usage in increments of 1024 -RT_1024_1,0,1,1024,1024,0 +# RT_5_1 charges 0.05 units per 1 unit of usage (SMS) ,,,,, +RT_5_1,,0.05,1,1,0 -# RT_10C1 charges 0.1 units of cost every 1 unit of usage -RT_10C1,0,0.1,1,1,0 +# RT_10_1 charges 0.1 units per 1 unit of usage (SMS) ,,,,, +RT_10_1,,0.1,1,1,0 -# RT_20C1 charges 0.2 units of cost every 1 unit of usage -RT_20C1,0,0.2,1,1,0 +# RT_10_1024 charges 0.1 units per 1024 units of usage in increments of 1024 units(DATA) ,,,,, +RT_10_1024,,0.1,1024,1024,0 -# RT_1CNT charges 0.01 units of cost for each 1s of usage -RT_1CNT,0,0.01,1s,1s,0 +# RT_60_60 charges 0.6 per minute in second increments ,,,,, +RT_60_60,,0.6,1m,1s,0 -# RT_10CNT charges 0.1 units of cost for each call connected -RT_10CNT,0.1,0,1s,1s,0 +# RT_120_60 charges 1.2 per minute in second increments ,,,,, +RT_120_60,,1.2,1m,1s,0 + +# RT_30_60 charges 0.3 per minute in second increments ,,,,, +RT_30_60,,0.3,1m,1s,0 + +# RT_15_0_1 charges 0.15 per call ,,,,, +RT_15_0_1,0.15,,1s,1s,0 diff --git a/data/tariffplans/tutorial2/RatingPlans.csv b/data/tariffplans/tutorial2/RatingPlans.csv index 7220236ef..4ee6cfc06 100644 --- a/data/tariffplans/tutorial2/RatingPlans.csv +++ b/data/tariffplans/tutorial2/RatingPlans.csv @@ -1,15 +1,22 @@ -#ID,DestinationRatesID,TimingID,Weight -RP_STANDARD,DR_10_120C,PEAK,10 -RP_STANDARD,DR_10_60C,OFFPEAK_MORNING,10 -RP_STANDARD,DR_10_60C,OFFPEAK_EVENING,10 -RP_STANDARD,DR_10_60C,OFFPEAK_WEEKEND,10 -RP_STANDARD,DR_2030_120C,*any,10 -RP_STANDARD,DR_20_60C,NEW_YEAR,20 -RP_STANDARD,DR_VOICEMAIL_FREE,*any,10 -RP_1001,DR_1002_60C,*any,10 -RP_SPECIAL_BLC,DR_ANY_10C_CN,*any,10 -RP_DATA,DR_ANY_1024_1,*any,10 -RP_SMS,DR_1002_10C1,*any,10 -RP_SMS,DR_10_20C1,*any,10 -RP_1CNT,DR_1CNT,*any,0 -RP_10CNT,DR_10CNT,*any,0 \ No newline at end of file +#Id,DestinationRatesId,TimingTag,Weight + +# RP_DEFAULT definition ,,, +RP_DEFAULT,DR_DEFAULT,*any,0 + +# RP_1001 definition ,,, +RP_1001,DR_1001,*any,0 + +# RP_SMS definition ,,, +RP_SMS,DR_SMS,*any,0 + +# RP_DATA definition ,,, +RP_DATA,DR_DATA,*any,0 + +# RP_SPL1 definition ,,, +RP_SPL1,DR_SPL1,*any,0 + +# RP_SPL2 definition ,,, +RP_SPL2,DR_SPL2,*any,0 + +# RP_SPECIAL_BLC definition ,,, +RP_SPECIAL_BLC,DR_SPECIAL_BLC,*any,0 diff --git a/data/tariffplans/tutorial2/RatingProfiles.csv b/data/tariffplans/tutorial2/RatingProfiles.csv index 93893aefe..13acfc401 100644 --- a/data/tariffplans/tutorial2/RatingProfiles.csv +++ b/data/tariffplans/tutorial2/RatingProfiles.csv @@ -1,9 +1,21 @@ -#Tenant,Category,Subject,ActivationTime,RatingPlanID,FallbackSubject -cgrates.org,call,*any,2019-03-01T00:00:00Z,RP_STANDARD, -cgrates.org,call,1001,2019-03-01T00:00:00Z,RP_1001,*any -cgrates.org,call,RPF_SPECIAL_BLC,2019-03-01T00:00:00Z,RP_SPECIAL_BLC, -cgrates.org,data,*any,2019-03-01T00:00:00Z,RP_DATA, -cgrates.org,sms,*any,2019-03-01T00:00:00Z,RP_SMS, +#Tenant,Category,Subject,ActivationTime,RatingPlanId,RatesFallbackSubject + +# Standard rates for calls,,,,, +cgrates.org,call,*any,2014-01-14T00:00:00Z,RP_DEFAULT, + +# Custom rates for Subject 1001,,,,, +cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_1001,*any + +# Default rates for data and SMS,,,,, +cgrates.org,data,*any,2014-01-14T00:00:00Z,RP_DATA, +cgrates.org,sms,*any,2014-01-14T00:00:00Z,RP_SMS, + +# Supplier rates selected via CHRG_SUPPLIER or Suppliers.csv,,,,, +cgrates.org,supplier1,*any,2014-01-14T00:00:00Z,RP_SPL1, +cgrates.org,supplier2,*any,2014-01-14T00:00:00Z,RP_SPL2, + +# Special rating subject for balances paying per call,,,,, +cgrates.org,call,RPF_SPECIAL_BLC,2014-01-14T00:00:00Z,RP_SPECIAL_BLC, + + -# reseller1 will pay 0.1 per call, independent of duration -cgrates.org,reseller1,*any,2019-03-01T00:00:00Z,RP_10CNT, diff --git a/data/tariffplans/tutorial2/Resources.csv b/data/tariffplans/tutorial2/Resources.csv new file mode 100644 index 000000000..69ddf66fe --- /dev/null +++ b/data/tariffplans/tutorial2/Resources.csv @@ -0,0 +1,2 @@ +#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],TTL[4],Limit[5],AllocationMessage[6],Blocker[7],Stored[8],Weight[9],ThresholdIDs[10] +cgrates.org,ResGroup1,*prefix:~*req.Account:100,2014-07-29T15:00:00Z,-1,7,,,true,,*none \ No newline at end of file diff --git a/data/tariffplans/tutorial2/Stats.csv b/data/tariffplans/tutorial2/Stats.csv new file mode 100644 index 000000000..ec7411235 --- /dev/null +++ b/data/tariffplans/tutorial2/Stats.csv @@ -0,0 +1,4 @@ +#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],QueueLength[4],TTL[5],MinItems[6],Metrics[7],MetricFilterIDs[8],Stored[9],Blocker[10],Weight[11],ThresholdIDs[12] +cgrates.org,STATS_1,FLTR_ACNT_1001_1002,2014-07-29T15:00:00Z,100,-1,,,,,true,,*none +cgrates.org,STATS_1,,,,,,*tcc;*asr,,,,, +cgrates.org,STATS_1,,,,,,*sum:~*req.Usage,,,,, diff --git a/data/tariffplans/tutorial2/Suppliers.csv b/data/tariffplans/tutorial2/Suppliers.csv new file mode 100644 index 000000000..29a736d1b --- /dev/null +++ b/data/tariffplans/tutorial2/Suppliers.csv @@ -0,0 +1,8 @@ +#Tenant,ID,FilterIDs,ActivationInterval,Sorting,SortingParamameters,SupplierID,SupplierFilterIDs,SupplierAccountIDs,SupplierRatingPlanIDs,SupplierResourceIDs,SupplierStatIDs,SupplierWeight,SupplierBlocker,SupplierParameters,Weight +cgrates.org,SPL_ACNT_1001,*string:~*req.Account:1001,2017-11-27T00:00:00Z,*weight,,,,,,,,,,,10 +cgrates.org,SPL_ACNT_1001,,,,,supplier1,,,,,,10,,, +cgrates.org,SPL_ACNT_1001,,,,,supplier2,,,,,,20,,, +cgrates.org,SPL_ACNT_1002,*string:~*req.Account:1002,2017-11-27T00:00:00Z,*lc,,,,,,,,,,,10 +cgrates.org,SPL_ACNT_1002,,,,,supplier1,,,RP_SPL1,,,,,, +cgrates.org,SPL_ACNT_1002,,,,,supplier2,,,RP_SPL2,,,,,, + diff --git a/data/tariffplans/tutorial2/Thresholds.csv b/data/tariffplans/tutorial2/Thresholds.csv new file mode 100644 index 000000000..c37682ef2 --- /dev/null +++ b/data/tariffplans/tutorial2/Thresholds.csv @@ -0,0 +1,2 @@ +#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],MaxHits[4],MinHits[5],MinSleep[6],Blocker[7],Weight[8],ActionIDs[9],Async[10] +cgrates.org,THD_ACNT_1001,*string:~*req.Account:1001;*gte:~*req.Usage:2m,2014-07-29T15:00:00Z,1,1,1s,false,10,ACT_LOG_WARNING,true diff --git a/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio-cgrates.cfg b/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio-cgrates.cfg index 18ba8eb13..c21be1bf3 100644 --- a/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio-cgrates.cfg +++ b/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio-cgrates.cfg @@ -187,6 +187,7 @@ route[CGR_CALL_END] { \"AnswerTime\":\"$dlg(start_ts)\", \"PaypalAccount\":\"$dlg_var(paypalAccount)\", \"SetupTime\":\"$dlg_var(SetupTime)\", - \"Usage\":\"$var(callDur)\"}"); + \"Usage\":\"$var(callDur)\", + \"Supplier\":\"$dlg_var(cgrSupplier)\"}"); } diff --git a/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio.cfg b/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio.cfg index 452cd9d0d..e023121ad 100644 --- a/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio.cfg +++ b/data/tutorials/kamevapi/kamailio/etc/kamailio/kamailio.cfg @@ -15,10 +15,6 @@ debug=2 log_stderror=no -listen=udp:enp0s3:5060 -listen=udp:127.0.0.1:5080 -listen=udp:127.0.0.1:5060 -listen=udp:enp0s3:5080 memdbg=5 memlog=5 diff --git a/data/tutorials/osips/opensips/etc/opensips/opensips.cfg b/data/tutorials/osips/opensips/etc/opensips/opensips.cfg index 9be77496e..3431c1185 100644 --- a/data/tutorials/osips/opensips/etc/opensips/opensips.cfg +++ b/data/tutorials/osips/opensips/etc/opensips/opensips.cfg @@ -8,7 +8,7 @@ # re-generating the scenario with different options.# # # Please refer to the Core CookBook at: -# https://opensips.org/Resources/DocsCookbooks +# http://www.opensips.org/Resources/DocsCookbooks # for a explanation of possible statements, functions and parameters. # @@ -23,11 +23,7 @@ udp_workers=4 auto_aliases=no -listen=udp:enp0s3:5060 -listen=udp:127.0.0.1:5080 -listen=udp:127.0.0.1:5060 -listen=udp:enp0s3:5080 - +socket=udp:enp0s8:5060 ####### Modules Section ######## @@ -85,7 +81,15 @@ loadmodule "proto_udp.so" #### CGRateS module loadmodule "dialog.so" loadmodule "cgrates.so" -modparam("cgrates", "cgrates_engine", "127.0.0.1:2014") +modparam("cgrates", "cgrates_engine", "192.168.56.111:2014") + +#### MySQL module +loadmodule "db_mysql.so" + +#### Drouting module +loadmodule "drouting.so" +modparam("drouting", "db_url", + "mysql://opensips:opensipsrw@localhost/opensips") ####### Routing Logic ######## @@ -201,7 +205,7 @@ route{ # check auth with CGRateS $cgr_opt(GetMaxUsage) = 1; # also retrieve the max usage $cgr_opt(GetAttributes) = 1; - $cgr_opt(GetSuppliers) = 1; + $cgr_opt(GetRoutes) = 1; $cgr_opt(AuthorizeResources) = 1; $cgr_opt(AllocateResources) = 1; $cgr_opt(ReleaseResources) = 1; @@ -218,29 +222,96 @@ route{ } route [resume_cgr_auth] { - if ($rc != 1) { - xlog("Call not authorized: code=$cgrret!\n"); + $var(rc) = $rc; + # with GetMaxUsage == false, cgrates_auth() returns -2 on success + if ($var(rc) < 0 && ($cgr_ret(MaxUsage) != 0 || $var(rc) != -2)) { + xlog("L_NOTICE", "[$ci] CGRateS auth failed: rc=$var(rc), code=$cgr_ret\n"); send_reply(403, "Forbidden"); exit; } + + # Set the returned attributes from CGRateS as script pseudovariables $var(idx) = 0; while ($(cgr_ret(AttributesDigest){s.select,$var(idx),,}) != NULL) { $avp($(cgr_ret(AttributesDigest){s.select,$var(idx),,}{s.select,0,:})) = $(cgr_ret(AttributesDigest){s.select,$var(idx),,}{s.select,1,:}); $var(idx) = $var(idx) + 1; } - cgrates_acc("cdr|missed", "$fU", "$rU"); - xlog("### Have authorized the call and it should go through"); - route(relay); + + # Enable CDRs being sent to CGRateS + cgrates_acc("cdr|missed", "$fU", "$rU"); + + if ( $cgr_ret(RoutesDigest)==NULL ) { # no routing requested + route(relay); + } + + xlog("L_INFO", "[$ci] CGRateS auth OK, with routes: <$cgr_ret(RoutesDigest)>\n"); + $avp(carriers) := $cgr_ret(RoutesDigest); + $avp(carriers_idx) := 0; + + route( to_carriers ); } +route[to_carriers] { + + xlog("L_INFO", "[$ci] routing to carrier IDX $avp(carriers_idx)\n"); + + $var(carrier) = $(avp(carriers){s.select,$avp(carriers_idx),,}); + if ( $var(carrier) == NULL) { + send_reply( 404 , "No route available to route"); + exit; + } + $cgr(RouteID) = $var(carrier); + + xlog("L_INFO", "[$ci] routing to carrier <$var(carrier)>\n"); + $avp(carriers_idx) := $avp(carriers_idx) + 1; + + #if ( !route_to_carrier("$var(carrier)") ) { + # xlog("L_INFO", "[$ci] failed to route to carrier, skipping>\n"); + # route( to_carriers ); + # exit; + #} + + t_on_failure("gw_failure"); + t_relay(); + + #end; + +} + +failure_route[gw_failure] { + xlog("L_INFO", "[$ci] GW call failed to established with $T_reply_code code\n"); + + if (t_was_cancelled()) { + exit; + } + + # failure indication about GWs? + if ( t_check_status("(408)|([56][0-9][0-9])") ) { + xlog("L_INFO", "[$ci] GW $rd failed with $T_reply_code -> retry\n"); + if ( use_next_gw() ) { + xlog("L_INFO", "[$ci] using new GW <$rd>\n"); + t_on_failure("gw_failure"); + t_relay(); + #end + } + + # no more GWs for the carrier, try the next carrier + route( to_carriers ); + } + +} + + + + route[relay] { # for INVITEs enable some additional helper routes if (is_method("INVITE")) { t_on_branch("per_branch_ops"); - t_on_reply("handle_nat"); - t_on_failure("missed_call"); + t_on_reply("handle_reply"); + t_on_failure("handle_failure"); } if (!t_relay()) { @@ -257,13 +328,13 @@ branch_route[per_branch_ops] { } -onreply_route[handle_nat] { +onreply_route[handle_reply] { xlog("incoming reply\n"); } -failure_route[missed_call] { +failure_route[handle_failure] { if (t_was_cancelled()) { exit; } -} +} \ No newline at end of file diff --git a/docs/tut_kamailio.rst b/docs/tut_kamailio.rst index 18efca663..cd6e690be 100644 --- a/docs/tut_kamailio.rst +++ b/docs/tut_kamailio.rst @@ -2,13 +2,13 @@ Kamailio_ Integration Tutorials =============================== In these tutorials we exemplify a few cases of integration between Kamailio_ and CGRateS_. We start with common steps, installation and postinstall processes, then we dive into particular configurations, depending on the case we run. +Together with the server side installation we describe here, one should consider installing the preferred SIP UA which is not part of this tutorial. .. toctree:: :maxdepth: 2 tut_kamailio_installs - tut_jitsi_installs tut_kamailio_evapi tut_cgrates_usage diff --git a/docs/tut_kamailio_evapi.rst b/docs/tut_kamailio_evapi.rst index 4f4738e52..31ac4e3b4 100644 --- a/docs/tut_kamailio_evapi.rst +++ b/docs/tut_kamailio_evapi.rst @@ -6,7 +6,7 @@ Scenario - Kamailio default configuration modified for **CGRateS** interaction. For script maintainability and simplicity we have separated CGRateS specific routes in *kamailio-cgrates.cfg* file which is included in main *kamailio.cfg* via include directive. - - Considering the following users (with configs hardcoded in the *kamailio.cfg* configuration script and loaded in htable): 1001-prepaid, 1002-postpaid, 1003-pseudoprepaid, 1004-rated, 1005-rated, 1006-prepaid, 1007-prepaid. + - Considering the following users: 1001-prepaid, 1002-postpaid, 1003-pseudoprepaid, stored within CGRateS AttributeS directly. - **CGRateS** with following components: diff --git a/docs/tut_kamailio_installs.rst b/docs/tut_kamailio_installs.rst index 3c6bb40b9..8d27f836b 100644 --- a/docs/tut_kamailio_installs.rst +++ b/docs/tut_kamailio_installs.rst @@ -1,7 +1,7 @@ Software installation ===================== -We have chosen Debian Jessie as operating system, since all the software components we use provide packaging for it. +We have chosen Debian Bullseye as operating system, since all the software components we use provide packaging for it. CGRateS -------- @@ -13,14 +13,15 @@ CGRateS Kamailio_ --------- -We got Kamailio_ installed via following commands: +We got Kamailio_ installed via following commands, documented in KamailioDebianInstallation_ section: :: - wget -O- http://deb.kamailio.org/kamailiodebkey.gpg | sudo apt-key add - - echo "deb http://deb.kamailio.org/kamailio56 stretch main" > /etc/apt/sources.list.d/kamailio.list + wget -O- https://deb.kamailio.org/kamailiodebkey.gpg | sudo apt-key add - + echo "deb http://deb.kamailio.org/kamailio56 bullseye main" > /etc/apt/sources.list.d/kamailio.list apt-get update apt-get install kamailio kamailio-extra-modules kamailio-json-modules Once installed we proceed with loading the configuration out of specific tutorial cases bellow. .. _Kamailio: https://www.kamailio.org/w/ +.. _KamailioDebianInstallation: https://www.kamailio.org/wiki/packages/debs diff --git a/docs/tut_opensips.rst b/docs/tut_opensips.rst index 62f14dd0c..ee196bd7e 100644 --- a/docs/tut_opensips.rst +++ b/docs/tut_opensips.rst @@ -8,8 +8,7 @@ In these tutorials we exemplify a few cases of integration between OpenSIPS_ and :maxdepth: 2 tut_opensips_installs - tut_jitsi_installs - tut_opensips_event + tut_osips_native tut_cgrates_usage .. _OpenSIPS: https://opensips.org/ diff --git a/docs/tut_opensips_installs.rst b/docs/tut_opensips_installs.rst index 444fb94e4..8772bde57 100644 --- a/docs/tut_opensips_installs.rst +++ b/docs/tut_opensips_installs.rst @@ -1,7 +1,7 @@ Software installation ===================== -We have chosen Debian Jessie as operating system, since all the software components we use provide packaging for it. +We have chosen Debian Buster as operating system, since all the software components we use provide packaging for it. CGRateS -------- @@ -16,9 +16,10 @@ We got OpenSIPS_ installed via following commands: :: apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 049AD65B - echo "deb http://apt.opensips.org jessie 2.4-nightly" >/etc/apt/sources.list.d/opensips.list + echo "deb https://apt.opensips.org buster 3.3-releases" >/etc/apt/sources.list.d/opensips.list + echo "deb https://apt.opensips.org buster cli-nightly" >/etc/apt/sources.list.d/opensips-cli.list apt-get update - apt-get install opensips opensips-cgrates-module + sudo apt-get install opensips opensips-mysql-module opensips-cgrates-module opensips-cli Once installed we proceed with loading the configuration out of specific tutorial cases bellow. diff --git a/docs/tut_opensips_event.rst b/docs/tut_opensips_native.rst similarity index 53% rename from docs/tut_opensips_event.rst rename to docs/tut_opensips_native.rst index 2b399318d..5ec066213 100644 --- a/docs/tut_opensips_event.rst +++ b/docs/tut_opensips_native.rst @@ -1,24 +1,36 @@ -OpenSIPS_ interaction via *event_datagram* -=========================================== +OpenSIPS_ interaction via own *cgrates* module +=============================================== Scenario -------- - OpenSIPS out of *residential* configuration generated. - - Considering the following users (with configs hardcoded in the *opensips.cfg* configuration script): 1002-postpaid, 1003-pseudoprepaid, 1004-rated, 1007-rated. + - The users are all defined within CGRateS. - For simplicity we configure no authentication (WARNING: Not for production usage). -- **CGRateS** with following components: +- **CGRateS** with following subsystems: - - CGR-SM started as translator between OpenSIPS_ and **cgr-rater** for both authorization events (pseudoprepaid) as well as CDR ones. - - CGR-CDRS component processing raw CDRs from CGR-SM component and storing them inside CGR StorDB. - - CGR-CDRE exporting rated CDRs from CGR StorDB (export path: */tmp*). - - CGR-History component keeping the archive of the rates modifications (path browsable with git client at */tmp/cgr_history*). + - **SM**: (SessionManager) started as gateway between OpenSIPS_ and rest of CGRateS subsystems. + - **ChargerS**: used to decide the number of billing runs for customer/supplier charging. + - **AttributeS**: used to populate extra data to requests (ie: prepaid/postpaid, passwords, paypal account, LCR profile). + - **RALs**: used to calculate costs as well as account bundle management. + - **SupplierS**: selection of suppliers for each session. This will work in tandem with OpenSIPS_'s DRouting module. + - **StatS**: computing statistics in real-time regarding sessions and their charging. + - **ThresholdS**: monitoring and reacting to events coming from above subsystems. + - **CDRe**: exporting rated CDRs from CGR StorDB (export path: */tmp*). + + +Creating OpenSIPS_ database for DRouting module +----------------------------------------------- + +:: + + opensips-cli -x database create Starting OpenSIPS_ with custom configuration ----------------------------------------------- +-------------------------------------------- ::