Rewriting CLI and CLD with external script

S
Written by Sergiiy
Updated 1 year ago

The Flysip B2BUA can use external script to do custom CLI, CLD rewriting. For this purpose the B2BUA uses /var/env<I_ENVIRONMENT>/scripts/external_translator (for <=4.5 versions /home/ssp/scripts/external_translator.<I_ENVIRONMENT>) script if it exists.

The B2BUA sends to the standard input of the script the CLI, CLD and i_account, for example:

CLI=1234\n
CLD=4321\n
ORIG_CLI=81234\n
ORIG_CLD=94321\n
I_ACCOUNT=123\n
\n

Full list of supplied fields see below.

After receiving the empty line, the script is free to use some algorithm to rewrite the CLI and CLD and then it MUST send them in separate lines of text - CLI, CLD and empty line. For example:

CLI=123\n
CLD=432\n
\n

If the script is not configured to rewrite anything then it must send back the CLI and CLD unchanged.

There are several optional action script can apply:

  • FAIL=<yes|no> - you can use this field to signal that the call should fail. Example: FAIL=yes
  • RESULT=<integer> - the result to be responded to the calling party. Possible values are 400 through 699 excluding 401 and 407, default is 500. This field is used when the FAIL=yes. Example: RESULT=403
  • COST=<float> - this value will be added to overall cost of the call. Example: COST=0.01


WARNING! To achieve maximum performance the script should never exit but continue to process next portion of data.
The SSP distribution comes with sample script /home/ssp/scripts/external_translator.sample, which you can customize to your purposes:

#!/bin/sh
while true; do
  read LINE || exit
  case "$LINE" in
  CLI=*) CLI=${LINE#CLI=}
  ;;
  CLD=*) CLD=${LINE#CLD=}
  ;;
  ORIG_CLI=*) ORIG_CLI=${LINE#ORIG_CLI=}
  ;;
  ORIG_CLD=*) ORIG_CLD=${LINE#ORIG_CLD=}
  ;;
  "")
  echo "CLI=$CLI"
  echo "CLD=$CLD"
  echo
  CLI=""
  CLD=""
  ;;
  esac
done

Translator is applied after authentication of the call. Translation rules are applied in the following order:

  • Case call was authenticated to Account:

1. CLI/CLD translation rules from Authentication Rule (if present)

2. CLI/CLD translation rules from Account (if present)

3. external_translator is triggered and processes the fields supplied to it by Flysip (see the list below)

4. Based on the output from external_translator Flysip performs call authorization (rating, routing, selection of tariff, route, etc)

5. Before sending the call outside the translation rules from Connection/Trunk are applied.

  • Case call was authenticated to DID

1. CLI/CLD translation rules from DID Authentication Rule and DID (if present)

2. CLI/CLD translation rules from Account assigned to DID are ignored

3. external_translator is triggered and processes the fields supplied to it by Flysip (see the list below)

4. Based on the output from external_translator Flysip performs call authorization (rating, routing, selection of tariff, route, etc)

5. Before sending the call outside the translation rules from Connection/Trunk are applied.

Fields supplied by Flysip to external_translator script:

I_ACCOUNT
ORIG_CLI
ORIG_CLD
CLI
CLD
CALLER_NAME
P_ASSERTED_ID
REMOTE_PARTY_ID
REMOTE_IP
DIVERSION
Did this answer your question?