======= Routing ======= This section describes authentication and routing principles. General routing algorithm is represented on the picture below: .. graphviz:: graphviz/routing.dot On the first step of general routing algorithm :ref:`authentication ` will be made. As a result of this step :ref:`Customer Auth ` record will be selected for incoming call or call will be dropped with *Disconnect Code 110 (Can't find Customer or Customer locked)*. On the second step of algorithm Yeti will check Customer's balance if :ref:`Check account balance ` flag of selected :ref:`Customer Auth ` record is enabled. If current balance is less than :ref:`Min balance ` call will dropped with **Disconnect code 8000** (No enough customer balance). On the third step of general routing algorithm Yeti makes pre-Routing numbers translations. Yeti rewrites (if necessary) Name field in the Source-number, Source-number and Destination-number for incoming call (by :ref:`using POSIX Regular Expressions `) with using :ref:`Number translation settings ` of :ref:`Customer Auth ` record that was selected. On this step Yeti also rewrites (if necessary) Source and Destination numbers which will be send to Radius-server if it's required (by :ref:`using POSIX Regular Expressions `) with using :ref:`Radius options ` of :ref:`Customer Auth ` record that was selected. On the fourth step of general routing algorithm Yeti makes processing of destination :ref:`Numberlist ` if this :ref:`Numberlist ` was setted up in the :ref:`Customer Auth ` record. Depending on chosen :ref:`mode ` Yeti is going via all related :ref:`Numberlist items ` and makes some :ref:`actions `. As a result of this step Yeti could drop the call with **Disconnect code 8001** (Destination blacklisted) or just rewrite (if necessary) Source and Destination numbers (by :ref:`using POSIX Regular Expressions `) with using :ref:`rewrite rules ` of :ref:`Numberlist items ` record or :ref:`rewrite rules ` relevant :ref:`Numberlist ` record. On the fifth step of general routing algorithm Yeti makes processing of source :ref:`Numberlist ` if this :ref:`Numberlist ` was setted up in the :ref:`Customer Auth ` record. Depending on chosen :ref:`mode ` Yeti is going via all related :ref:`Numberlist items ` and makes some :ref:`actions `. As a result of this step Yeti could drop the call with **Disconnect code 8002** (Source blacklisted) or just rewrite (if necessary) Source and Destination numbers (by :ref:`using POSIX Regular Expressions `) with using :ref:`rewrite rules ` of :ref:`Numberlist items ` record or :ref:`rewrite rules ` relevant :ref:`Numberlist ` record. On the sixth step of general routing algorithm Yeti will be looking for :ref:`Areas ` (by using :ref:`Area prefixes `) that are related to the Source number (**From name**) and Destination number (**URI name**) after them processing and translation on the previous steps. :ref:`Area ` records that were found (if any), are used for detecting :ref:`Routing Tags ` for the call on the basis :ref:`Routing Tag detection Rules `. On the seventh step of general routing algorithm Yeti will be selecting :ref:`Routing Plan ` that was chosen for :ref:`Customer Auth ` record. On the eighth step of general routing algorithm Yeti (if :ref:`Use Lnp ` flag of :ref:`Routing Plan ` that was chosen for :ref:`Customer Auth ` record is enabled) selects most preferred :ref:`Routing Plan LNP rule ` (by longest match prefix of destination number (number B)) and uses this :ref:`Routing Plan LNP rule ` for processing ported numbers of call. If required record wasn't found in the :ref:`LNP Cache ` - :ref:`LNP Database ` will be requested. In case of failing query Yeti will drop the call with **Disconnect code 8003** (No response from LNP DB). On the ninth step of general routing algorithm Yeti will be searching :ref:`Destination ` for the call that is matching **ALL** following conditions: - :ref:`Prefix ` of :ref:`Destination ` record is in the prefix range of Destination number (**URI name**); .. note:: Examples: - Prefix of :ref:`Destination ` record = ** ; **URI name** = *0662296132* => **TRUE** - Prefix of :ref:`Destination ` record = *066* ; **URI name** = *0662296132* => **TRUE** - Prefix of :ref:`Destination ` record = *066[1-3]* ; **URI name** = *0662296132* => **TRUE** - Prefix of :ref:`Destination ` record = *066[1-3]* ; **URI name** = *0665296132* => **FALSE** - Prefix of :ref:`Destination ` record = *066[1-3], 0665* ; **URI name** = *0665296132* => **TRUE** - Prefix of :ref:`Destination ` record = *066[1-3], 0665* ; **URI name** = *0666296132* => **FALSE** - Length of Destination number (**URI name**) is between Dst number min and max length values of :ref:`Destination ` record; .. note:: Examples: - Dst number min length of :ref:`Destination ` record = *3* ; Dst number max length of :ref:`Destination ` record = *15* ; **URI name** = *380662296132* => **TRUE** - Dst number min length of :ref:`Destination ` record = *7* ; Dst number max length of :ref:`Destination ` record = *7* ; **URI name** = *7050460* => **TRUE** - Dst number min length of :ref:`Destination ` record = *0* ; Dst number max length of :ref:`Destination ` record = *7* ; **URI name** = *0487050460* => **FALSE** - :ref:`Rateplan ` that is chosen for :ref:`Destination ` record is same with :ref:`Rateplan ` that is chosen for :ref:`Customer Auth ` record; - :ref:`Destination ` record is enabled; - current date&time is more than :ref:`Valid From ` value of :ref:`Destination ` record; - current date&time is less than :ref:`Valid To ` value of :ref:`Destination ` record; - at least one :ref:`Routing Tag ` (from the list of :ref:`Routing Tags ` that were chosen for the call during the sixth step of general routing algorithm) is included in the set of :ref:`Routing Tags ` that are chosen for:ref:`Destination ` record. If more than one record was found during searching of :ref:`Destination ` Yeti sorts records with following rules: records with the longest :ref:`Prefix ` of :ref:`Destination ` on the top; records with biggest amount of :ref:`Routing Tags ` that were chosen for the call (during the sixth step of general routing algorithm) and are included in the set of :ref:`Routing Tags ` that are chosen for:ref:`Destination ` record on the top. Only first record from sorted list will be chosen. If no records were found during searching of :ref:`Destination ` Yeti will drop the call with **Disconnect Code 111** (Can't find destination prefix). If :ref:`Reject Calls ` flag is enabled for the :ref:`Destination ` record that was chosen Yeti will drop the call with **Disconnect Code 112** (Rejected by destination). On the tenth step of general routing algorithm Yeti will search routes (:ref:`Dialpeers `) for a call on the basis :ref:`routing (sorting) algorithm ` that was chosen for :ref:`Routing Plan ` record. If no records were found during searching of :ref:`Dialpeers ` Yeti will drop the call with **Disconnect Code 113** (No routes). On the eleventh step of general routing algorithm Yeti will pass through list of selected :ref:`Dialpeers `) that is sorted by chosen :ref:`routing (sorting) algorithm `. For each :ref:`Dialpeer ` following actions will be applied: - Search termination :ref:`Gateways ` for selected :ref:`Dialpeer ` (Step 11.1). If :ref:`Gateway ` was chosen for :ref:`Dialpeer ` record (and this :ref:`Gateway ` is :ref:`Enabled `) Yeti will check :ref:`Vendor ` property of :ref:`Dialpeer ` and compares it with :ref:`Contractor ` property of :ref:`Gateway `. In case if :ref:`Is shared ` flag of :ref:`Gateway ` record wasn't chosen and :ref:`Vendor ` property of :ref:`Dialpeer ` record and :ref:`Contractor ` property of :ref:`Gateway ` record aren't same - Yeti will stop process this :ref:`Dialpeer ` and will go to next record in the sorted list of :ref:`Dialpeers `. Otherwise :ref:`Gateway ` that was chosen for :ref:`Dialpeer ` record will be used for attempt of the call termination. If :ref:`Gateway ` wasn't chosen for :ref:`Dialpeer ` record Yeti will select all :ref:`enabled ` :ref:`Gateways ` from :ref:`Gateway group ` that was chosen for :ref:`Dialpeer ` where :ref:`Point of Presence ` of the termination and origination :ref:`Gateways ` are same AND :ref:`Vendor ` property of :ref:`Dialpeer ` record and :ref:`Contractor ` property of :ref:`Gateway ` record are same. If :ref:`Gateways ` from the same :ref:`Point of Presence ` weren't found - Yeti will select all :ref:`enabled ` :ref:`Gateways ` from :ref:`Gateway group ` that was chosen for :ref:`Dialpeer ` regardless :ref:`Point of Presence `, but where :ref:`Vendor ` property of :ref:`Dialpeer ` record and :ref:`Contractor ` property of :ref:`Gateway ` record are same. All selected by this way :ref:`Gateways ` will be used for attempts of the call termination. The quantity of attempts of the call termination for each :ref:`Dialpeer ` record from the sorted list of :ref:`Dialpeers ` is determined by quantity of selected :ref:`Gateways ` that are sorted by following rules: :ref:`Gateways ` from the same (related to origination) :ref:`Point of Presence ` are first, :ref:`Gateways ` with higher :ref:`Priority ` are first, random :ref:`Gateway ` will be chosen first in case of equal :ref:`Priorities ` for two or more :ref:`Gateways ` in the list; - Yeti will pass through list of selected :ref:`Gateways ` that is sorted by priority (Step 11.2). For each :ref:`Gateway ` from the list following actions will be applied: - Checking if Customer's min balance will be reached during the call (Step 11.3). On this stage Yeti will check if :ref:`Connect Fee ` of :ref:`Destination ` record that was selected for this call is bigger than the result of subtracting :ref:`Balance ` of the :ref:`Customer's Account ` and :ref:`Min balance ` of the :ref:`Customer's Account `. If no enough money on :ref:`Customer's Account ` for make connection and for calling during :ref:`Initial Interval ` of :ref:`Destination ` record that was selected for this call - call will dropped with **Disconnect code 8000** (No enough customer balance); - Calculating of allowed time for the call (Step 11.4). Yeti could limit maximum time of the calls to avoid exceeding limits of money (minimum or maximum) that are available on accounts of Customer and Vendor. For this purpose Yeti has two values of allowed time: limited by Customer's Account and limited by Vendor's account: - **Allowed time that is limited by Customer's Account**. If :ref:`Next Rate ` AND :ref:`Next Interval ` of the :ref:`Destination ` record that was selected for this call are not zero: allowed time for the call will be calculated as sum of :ref:`Initial Interval ` of this :ref:`Destination ` record and length of call that can be made within amount of money available on :ref:`Customer's Account `. Otherwise value :ref:`Max Call Duration ` from :ref:`Global configuration ` will be used for setting allowed time for the call; - **Allowed time that is limited by Vendor's Account**. If :ref:`Next Rate ` AND :ref:`Next Interval ` of the :ref:`Dialpeer ` record that was selected for this call are not zero: allowed time for the call will be calculated as sum of :ref:`Initial Interval ` of this :ref:`Dialpeer ` record and length of call that can be made before reaching :ref:`Max balance ` the :ref:`Vendor's Account `. Otherwise value :ref:`Max Call Duration ` from :ref:`Global configuration ` will be used for setting allowed time for the call; - Checking if Vendor's max balance will be reached during the call (Step 11.5); On this stage Yeti will check if :ref:`Connect Fee ` of :ref:`Dialpeer ` record that was selected for this call is bigger than the result of subtracting :ref:`Max balance ` and :ref:`Balance ` of the :ref:`Vendor's Account `. If Vendor's max balance will be reached during :ref:`Initial Interval ` of :ref:`Dialpeer ` record that was selected for this call - this :ref:`Gateway ` will be ignored and next :ref:`Gateway ` will be chosen from the list on Step 11.2; - Post-routing numbers translations (Step 11.6). On this step of general routing algorithm Yeti makes post-Routing numbers translations. Yeti rewrites (if necessary) Name field in the Source-number, Source-number and Destination-number for incoming call (by :ref:`using POSIX Regular Expressions `) with using :ref:`Number translation settings ` of :ref:`Dialpeer ` record that was selected for this call; - Adding Call Profile to the Array (Step 11.7). On this step Yeti will add Call Profile to the list (array) of Call Profiles. Call Profile will be used by Yeti/SEMS node for making call on Step 12 of general routing algorithm. On the twelfth step of general routing algorithm Yeti/SEMS node will pass through list of Call Profiles that was received on previous step (Step 12). For each Call Profile following actions will be applied: - Checking Disconnect Code (Step 12.1). On this step Yeti will check if Disconnect Code for Call Profile was initialized (not NULL). If yes - Yeti will initiate disconnecting (Step 12.6) from Originator (with using received Disconnect Code) after writing CDR & statistic for route/gateway (Step 12.3a); - Trying to connect a call (Step 12.2). On this step Yeti will try to make a connection with LegB via :ref:`Gateway ` that was selected for current Call Profile. Regardless from call result (successful or not, length of call etc.) Yeti will write CDR & statistic for route/gateway (Step 12.3b) and will change customer's and vendor's balance at billing subsystem (in case of successful call with non-zero length) on Step 12.4. After the checking of call result (Step 12.5) Yeti will disconnect from Originator (Step 12.6) in case of successful call or will go the next Call Profile in the list (Step 12). Yeti will exit from the loop only when call had been made successfully or when all Call Profiles had been used; - Writing CDR + writing statistic for route/gateway (Step 12.3 (a & b)). Information about call will be stored to the :ref:`CDR Table ` and current statistical parameters (count of answered telephone calls, general length of telephone calls) will be updated for :ref:`Dialpeer ` record that was selected for this call and for :ref:`Gateway ` that was used for this call; - Change Customer's and Vendor's balance at billing subsystem (if necessary) (Step 12.4). On this step Yeti will change Customer's and Vendor's :ref:`balance ` in case of successful call with non-zero length. For calculating prices of the call for Customer and Vendor following rules are used: .. _customer_price_calc_rules: - **Customer's price calculation rules**. For calculate Customer's price for the call Yeti will summarize :ref:`Connect Fee ` (in currency units) of :ref:`Destination ` record that was selected for this call, price of initial interval of call that is calculated as multiplication of :ref:`Initial Interval ` (in seconds) of :ref:`Destination ` record to the :ref:`Initial Rate ` (in currency units per minute) that was divided on length of a minute in seconds (60 seconds), and (in case of calls that are longer than :ref:`Initial Interval `) price of next interval of call that is calculated as multiplication amount of :ref:`Next Intervals ` of :ref:`Destination ` record that was selected for this call that were placed in the duration of the call after :ref:`Initial Interval ` to the :ref:`Next Rate ` (in currency units per minute) that was divided on length of a minute in seconds (60 seconds). At the last step Customer's price that was calculated will be increased on the value of value-added tax (VAT) that was specified for the Customer's :ref:`Account `. .. _vendor_price_calc_rules: - **Vendor's price calculation rules**. For calculate Vendor's price for the call Yeti will summarize :ref:`Connect Fee ` (in currency units) of :ref:`Dialpeer ` record that was selected for this call, price of initial interval of call that is calculated as multiplication of :ref:`Initial Interval ` (in seconds) of :ref:`Dialpeer ` record to the :ref:`Initial Rate ` (in currency units per minute) that was divided on length of a minute in seconds (60 seconds), and (in case of calls that are longer than :ref:`Initial Interval `) price of next interval of call that is calculated as multiplication amount of :ref:`Next Intervals ` of :ref:`Dialpeer ` record that was selected for this call that were placed in the duration of the call after :ref:`Initial Interval ` to the :ref:`Next Rate ` (in currency units per minute) that was divided on length of a minute in seconds (60 seconds); .. note:: Important notice: In normal mode changing Customer's and Vendor's balance at billing subsystem will be made **by subtraction** of the Customer's price that was calculated on this step from the Customer's :ref:`balance ` and **by addition** Vendor's price to the Vendor's :ref:`balance `. But in case of enabling :ref:`Reverse billing ` flag of :ref:`Destination ` record that was selected for this call - Yeti **will add** Customer's price that was calculated on this step to the Customer's :ref:`balance `, and in case of enabling :ref:`Reverse billing ` flag of :ref:`Dialpeer ` record that was selected for this call - Yeti **will subtract** Vendor's price from the Vendor's :ref:`balance `. Following formula is used for calculation both Customer's and Vendor's prices: .. math:: \begin{equation} Price = (CF + II(\frac{IR}{60}) + [\frac{(CD-II)}{NI}]NI(\frac{NR}{60}))(1 + \frac{VAT}{100}) \end{equation} where: - Price - Customer's or Vendor's price; - CF - *Connect Fee* of :ref:`Destination ` (for Customer's price) or :ref:`Dialpeer ` (for Vendor's price), currency units; - II - *Initial Interval* of :ref:`Destination ` (for Customer's price) or :ref:`Dialpeer ` (for Vendor's price), seconds; - IR - *Initial Rate* of :ref:`Destination ` (for Customer's price) or :ref:`Dialpeer ` (for Vendor's price), currency units per minute; - CD - *Call duration*, seconds; - NI - *Next Interval* of :ref:`Destination ` (for Customer's price) or :ref:`Dialpeer ` (for Vendor's price), seconds; - NR - *Next Rate* of :ref:`Destination ` (for Customer's price) or :ref:`Dialpeer ` (for Vendor's price), currency units per minute; - VAT - Value-added tax, percents. VAT = 0 for calculating Vendor's price. - Disconnect from Originator (Step 12.6). YETI WEB interface - Routing menu description. .. toctree:: :maxdepth: 1 yeti-ui-routing/yeti-ui-routing-customer_auths yeti-ui-routing/yeti-ui-routing-rateplans yeti-ui-routing/yeti-ui-routing-destinations yeti-ui-routing/yeti-ui-routing-routing_groups yeti-ui-routing/yeti-ui-routing-dialpeers yeti-ui-routing/yeti-ui-routing-routing_plans yeti-ui-routing/yeti-ui-routing-routing_plan_static_routes yeti-ui-routing/yeti-ui-routing-routing_plan_lnp_rules yeti-ui-routing/yeti-ui-routing-lnp_caches yeti-ui-routing/yeti-ui-routing-numberlists yeti-ui-routing/yeti-ui-routing-numberlist_items yeti-ui-routing/yeti-ui-routing-routing_tags yeti-ui-routing/yeti-ui-routing-areas yeti-ui-routing/yeti-ui-routing-area_prefixes yeti-ui-routing/yeti-ui-routing-routing_tag_detection_rules yeti-ui-routing/yeti-ui-routing-routing_simulation yeti-ui-routing/yeti-ui-routing-tags_truth_table yeti-ui-routing/yeti-ui-routing-prefix_truth_table