Difference between revisions of "Mobile Number Portability Addon"

From Kolmisoft Wiki
Jump to navigationJump to search
 
(48 intermediate revisions by 10 users not shown)
Line 1: Line 1:
''This addon is available starting from MOR 8''
<!---This functionality is available from MOR 8--->
 
[http://en.wikipedia.org/wiki/Mobile_number_portability Mobile number portability (MNP)] enables mobile telephone users to retain their mobile telephone numbers when changing from one mobile network operator to another.
[http://en.wikipedia.org/wiki/Mobile_number_portability Mobile number portability (MNP)] enables mobile telephone users to retain their mobile telephone numbers when changing from one mobile network operator to another.


Line 7: Line 6:
MNP Addon for MOR allows system owner to check number if it belongs to other network and if so - route it through different providers or bill it with different price.
MNP Addon for MOR allows system owner to check number if it belongs to other network and if so - route it through different providers or bill it with different price.


Current implementation allows to save numbers in MySQL database on any server (possible not on local server).
Current implementation allows to save numbers in MySQL database on any server (possible not necessarily on local server).


Before each call MOR MNP Addon checks dialed number and if number is found in database - some prefix is added in front of it.
Before each call MOR MNP Addon checks dialed number and if number is found in database - some prefix is added in front of it.
Line 14: Line 13:


Detailed technique is described here: [[LCR/Tariff change based on call prefix]]
Detailed technique is described here: [[LCR/Tariff change based on call prefix]]
MNP Addon for MOR is available from MOR v8


As Kolmisoft cannot make one unique database for all MNP services in all countries all over the world. MOR admin has to
As Kolmisoft cannot make one unique database for all MNP services in all countries all over the world. MOR admin has to
Line 24: Line 21:


<br><br>
<br><br>
NOTE: It is important to take care of various number formats user can use to dial a number. As a solution to it is to insert MNP number into DB in several possible formats.
= Installation =
 
Do such steps:
 
1. Update MOR scripts:
rm -fr /usr/src/mor
svn co http://svn.kolmisoft.com/mor/install_script/trunk/ /usr/src/mor
2. Run MNP installation script:
/usr/src/mor/sh_scripts/install_mnp.sh
3. Depending on MOR version:<br><br>
 
'''MOR X16 (or older)'''
 
Run script which will update Asterisk extlines to work with MNP database:
/usr/src/mor/test/scripts/asterisk/mnp_cfgs.sh
 
'''MOR X17 (or later)'''
 
Starting from MOR X17, enable MNP in /etc/asterisk/mor.conf
 
mnp_enabled = 1
asterisk -rx "mor reload"


<br><br>
<br><br>
= Installation =
== How to see if MNP works ==
 
Open Asterisk CLI. During the call check the very first lines shown in CLI. In about the 10th line you should be able to see lines like that:
 
'''MOR X16 (or older)'''
 
    -- Launched AGI Script /var/lib/asterisk/agi-bin/mor_mnp
mor_mnp:
mor_mnp: MOR MNP AGI script started.
mor_mnp: Successfully connected to the database.
mor_mnp: Extension: 37012312345
mor_mnp: New extension: 37012312345
mor_mnp: MOR MNP AGI script stopped.
mor_mnp:
 
'''MOR X17 (or later)'''
 
In call log, the following line should be visible:
 
[2023-01-17 15:32:03] NOTICE[10659][C-00000007]: app_mor_various.c:4088 _mor_log: Checking number 37012312345 in MNP database
 
Also, check the output of '''asterisk -rx "mor show status"''', you should see MNP status:
 
MNP enabled: 1, MNP active: 1


Do such steps:
MNP enabled - shows if MOR core is aware of MNP existence.<br>
MNP active - shows if MOR core successfully connected to MNP database.<br><br>


  1. [[Upgrade_MOR_GUI |Upgrade MOR]]
If you cannot see it. Something is wrong with the configuration.
  2. cd /usr/src/mor/sh_scripts
  3. ./install_mnp.sh


<br><br>
<br><br>
= Upgrade =


After [[Upgrade_MOR_GUI |Upgrade MOR]] run /usr/src/mor/upgrade/9/mnp_reenable.sh
= Upgrade/Update =


After [[Upgrade_MOR_GUI |MOR Upgrade]] or Update run /usr/src/mor/test/scripts/asterisk/mnp_cfgs.sh
<br><br>
<br><br>
= Database =
= Database =


Line 75: Line 116:
To manage mor_mnp database you can use PhpMyAdmin:
To manage mor_mnp database you can use PhpMyAdmin:


<nowiki>http://<your server IP>/phpmyadmin</nowiki>
<nowiki>http://<your server IP>/mordbadmin</nowiki>


PhpMyAdmin login details can be found in file /root/phpMyAdminPassword
PhpMyAdmin login details can be found in file /root/phpMyAdminPassword
<br><br>
<br><br>
After login to PhpMyAdmin, MySQL login page will appear.
If after loging in to PhpMyAdmin, MySQL login page will appear, use these details to login to MySQL:
 
Use these details to login MySQL:


username: mor
username: mor
Line 100: Line 139:


Done!
Done!
<br><br>
<br><br>
= Number localization =
In situations when a number can be dialed in multiple ways you can set '''mnp_prefixes''' variable in '''/usr/local/mor/mor_mnp.conf'''.<br>
For example, if number 123456789 can be dialed with the following prefixes '''00370'''123456789, '''370'''123456789, '''8'''123456789 then you can set '''mnp_prefixes''' variable with the following prefixes:
mnp_prefixes = 00370,370,8
then you will be able to upload only a single number 123456789 into the MNP database and this number will be matched when the client dials '''00370'''123456789, '''370'''123456789 or '''8'''123456789.
<br><br>
= MNP tags in SIP INVITE =
MNP tags (npdi and rn) can be enabled by setting '''Enable MNP tags''' to '''yes''' in Provider configuration.<br>
If MNP tags are enabled and MNP lookup was successful, then npdi and rn tags will be added to SIP INVITE:
INVITE sip:DST_NUMBER;npdi;rn=MNP_NUMBER@IP SIP/2.0
here:
* DST_NUMBER - localized destination number, for example, +370123456789
* MNP_NUMBER - localized destination number with MNP prefix, for example +370'''999'''123456789
If the number is not found in the MNP database, then only npdi tag will be added to SIP INVITE:
INVITE sip:DST_NUMBER;npdi@IP SIP/2.0
here:
* DST_NUMBER - localized destination number, for example, +370123456
'''Note''' that only SIP INVITE requests will be modified. Other SIP headers (such as TO, FROM) are not affected by '''Enable MNP tags''' setting.
<br><br>
<br><br>
= How to import numbers from CSV =
= How to import numbers from CSV =


There is no such option to import numbers from CSV in MOR GUI, but numbers can be imported directly to MNP database.
There is no such option to import numbers from CSV in MOR GUI, but numbers can be imported directly to the MNP database.


This procedure is described here:
This procedure is described here:


1. You need to have CSV file on your server and file should look like:
1. You need to have a CSV file on your server and the file should look like this:


  ...
  ...
Line 120: Line 197:
  mysql mor_mnp
  mysql mor_mnp


3. Create temporary table and import CSV file to it:
3. Create a temporary table and import a CSV file to it:


  CREATE TABLE temp (col_1 VARCHAR(50) default NULL , col_2 VARCHAR(20) default NULL);
  CREATE TABLE temp (col_1 VARCHAR(50) default NULL , col_2 VARCHAR(20) default NULL);
Line 126: Line 203:
  LOAD DATA LOCAL INFILE '/home/mnpnumbers.csv' IGNORE INTO TABLE temp FIELDS TERMINATED BY ';' ;
  LOAD DATA LOCAL INFILE '/home/mnpnumbers.csv' IGNORE INTO TABLE temp FIELDS TERMINATED BY ';' ;


4. Copy data from temporary table to 'numbers' table:
4. Copy data from the temporary table to 'numbers' table:
 
<nowiki>INSERT INTO numbers (number,prefix) SELECT TRIM(REPLACE(col_1, '\r', '')), TRIM(REPLACE(col_2, '\r', '')) FROM temp
WHERE ( TRIM(REPLACE(col_1, '\r', '')) REGEXP '^[0-9]+$' = 1) and (TRIM(REPLACE(col_2, '\r', '')) REGEXP '^[0-9]+$' = 1) ;</nowiki>
 


INSERT INTO numbers (number,prefix) SELECT REPLACE(col_1, '\r', ''), REPLACE(col_2, '\r', '') FROM temp
WHERE (REPLACE(col_1, '\r', '') REGEXP '^[0-9]+$' = 1) and (REPLACE(col_2, '\r', '') REGEXP '^[0-9]+$' = 1) ;


NOTE: this query skips values which contains non-numerical characters.
NOTE: This query skips values that contain non-numerical characters.


For example: row
For example row


  ...
  ...
Line 146: Line 225:


Done. Numbers are imported to 'numbers' table.  
Done. Numbers are imported to 'numbers' table.  
<br><br>
== Automatic import script ==
Script downloads compressed (ZIP) CSV with a list of numbers from the SFTP server and imports in with default prefix to the MNP database. Current ZIP file required. Only SFTP is supported. The script does not import prefixes from CSV. CSV should contain an only list of numbers.
The script is located in /usr/src/mor/sh_scripts/mnp_numbers_import.sh
Script uses same configuration file /usr/local/mor/mor_mnp.conf . Options which are specific to this script:
download_url = sftp.server.com:/path/to/file.zip  #some remote location of a number file (for sftp)
username = ftpuser                                #user name to connect to a remote server
password = ftppassword                            #password for a user to connect to a remote server
default_prefix = 0009                            #default prefix for numbers (current version does not support prefix import)
'''Note:'''<br>
If you are using MOR X18 version on Rocky Linux 9 and FTP server on older operating system then these errors can occur using the script:
Unable to negotiate with xxx.xxx.xxx.xxx port 22: no matching host key type found. Their offer: ssh-rsa,ssh-dss
ssh_dispatch_run_fatal: Connection to xxx.xxx.xxx.xxx port 22: error in libcrypto
The best way is to upgrade the FTP server to a new operating system. If you do not want to upgrade your FTP server, then you can use another option to run this command on the MOR Rocky Linux 9 server:
update-crypto-policies --set DEFAULT:SHA1
<br><br>
<br><br>


= How to configure external MNP database =
= How to configure external MNP database =
<br>
 
Skip this step if your MOR billing installation is on one server.<br>
Skip this step if your MOR billing installation is on one server.<br>


locate mor_mnp.conf file<br>
Locate mor_mnp.conf file<br>


  cd /usr/local/mor<br>
  cd /usr/local/mor<br>


edit the file with your favorite text editor, for example:<br>
Edit the file with your favorite text editor, for example:<br>


  medit mor_mrnp.conf<br>
  mcedit mor_mnp.conf<br>


You should see similar values:<br>
You should see similar values, '''mind the gaps in the file, they should be exactly the same as in the example below''':<br>


  host = localhost
  host = localhost
Line 170: Line 273:
  show_sql = 0
  show_sql = 0
  debug = 1
  debug = 1
mnp_prefixes = 00370,370,8


Change the values to the ones you need:<br>
Change the values to the ones you need:<br>


host - your database IP address
host - your database IP address<br>
server_id - your Asterisk server id, same as in /etc/asterisk/mor.conf
server_id - your Asterisk server id, same as in /etc/asterisk/mor.conf
<br><br>
= How can I add a specific prefix on a call to the ported number? =
It's possible to add a specific prefix on the call in this way:
* Create a duplicated provider (for example, you have "Provider A (no MNP) and "Provider A (with MNP)")
* Create [[Provider_Rules | Provider Rules]] for that provider by adding a prefix 060
* MOR will route numbers in the MNP database through that provider according to the [[Provider_Rules | Provider Rules]].
<br><br>
<br><br>


=See also=
=See also=
* [[MOR Addons]]
* [[MOR Addons]]
<br><br>
* [http://en.wikipedia.org/wiki/Least-cost_routing#Impact_of_mobile-number_portability_in_VOIP_and_LCR_environments Impact of MNP in VOIP and LCR environments]

Latest revision as of 11:10, 13 September 2024

Mobile number portability (MNP) enables mobile telephone users to retain their mobile telephone numbers when changing from one mobile network operator to another.


MNP Addon for MOR allows system owner to check number if it belongs to other network and if so - route it through different providers or bill it with different price.

Current implementation allows to save numbers in MySQL database on any server (possible not necessarily on local server).

Before each call MOR MNP Addon checks dialed number and if number is found in database - some prefix is added in front of it.

By prefix MOR can set different routing(LCR) or billing(Tariff) for this number. Localization rules should be used to perform these actions.

Detailed technique is described here: LCR/Tariff change based on call prefix

As Kolmisoft cannot make one unique database for all MNP services in all countries all over the world. MOR admin has to

manually enter numbers in MNP database (process described below) in order for this solution to work. mor_mnp database has

to contain only the necessary data (telephone numbers).



Installation

Do such steps:

1. Update MOR scripts:

rm -fr /usr/src/mor
svn co http://svn.kolmisoft.com/mor/install_script/trunk/ /usr/src/mor

2. Run MNP installation script:

/usr/src/mor/sh_scripts/install_mnp.sh

3. Depending on MOR version:

MOR X16 (or older)

Run script which will update Asterisk extlines to work with MNP database:

/usr/src/mor/test/scripts/asterisk/mnp_cfgs.sh

MOR X17 (or later)

Starting from MOR X17, enable MNP in /etc/asterisk/mor.conf

mnp_enabled = 1
asterisk -rx "mor reload"



How to see if MNP works

Open Asterisk CLI. During the call check the very first lines shown in CLI. In about the 10th line you should be able to see lines like that:

MOR X16 (or older)

    -- Launched AGI Script /var/lib/asterisk/agi-bin/mor_mnp
mor_mnp: 
mor_mnp: MOR MNP AGI script started.
mor_mnp: Successfully connected to the database.
mor_mnp: Extension: 37012312345
mor_mnp: New extension: 37012312345
mor_mnp: MOR MNP AGI script stopped.
mor_mnp: 

MOR X17 (or later)

In call log, the following line should be visible:

[2023-01-17 15:32:03] NOTICE[10659][C-00000007]: app_mor_various.c:4088 _mor_log: Checking number 37012312345 in MNP database

Also, check the output of asterisk -rx "mor show status", you should see MNP status:

MNP enabled: 1, MNP active: 1

MNP enabled - shows if MOR core is aware of MNP existence.
MNP active - shows if MOR core successfully connected to MNP database.

If you cannot see it. Something is wrong with the configuration.



Upgrade/Update

After MOR Upgrade or Update run /usr/src/mor/test/scripts/asterisk/mnp_cfgs.sh

Database

Config to DB in: /usr/local/mor/mor_mnp.conf

It should be MySQL database mor_mnp:

DROP TABLE IF EXISTS `numbers`;
CREATE TABLE `numbers` (
 `number` varchar(50) NOT NULL,
 `prefix` varchar(20) NOT NULL,
 PRIMARY KEY  (`number`),
 UNIQUE KEY `number` (`number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;




Make sure you have set correct MySQL permissions for mor_mnp database and also local or remote asterisk must have correct settings in /usr/local/mor/mor_mnp.conf . If your number is still not recognized, double check if you have it in your mor_mnp database!

An example how to set MySQL permissions:


GRANT REPLICATION SLAVE , REPLICATION CLIENT ON * . * TO 'mor'@'localhost' IDENTIFIED BY 'mor' WITH MAX_QUERIES_PER_HOUR 0
MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
GRANT ALL PRIVILEGES ON `mor_mnp` . * TO 'mor'@'localhost' WITH GRANT OPTION ;



How to use MNP

You need to insert two values in mor_mnp database. These values are number and prefix.

To manage mor_mnp database you can use PhpMyAdmin:

http://<your server IP>/mordbadmin

PhpMyAdmin login details can be found in file /root/phpMyAdminPassword

If after loging in to PhpMyAdmin, MySQL login page will appear, use these details to login to MySQL:

username: mor

password: mor

Now click "_mnp (1)" menu item on the left to select mor_mnp database.

"numbers" menu item will appear after that.

Click on "numbers" menu item to manage number table.

Now click on "Insert" tab at the top of page.

Fields number and prefix will appear.

Enter desired values and click "Go" to insert these values.

Done!



Number localization

In situations when a number can be dialed in multiple ways you can set mnp_prefixes variable in /usr/local/mor/mor_mnp.conf.

For example, if number 123456789 can be dialed with the following prefixes 00370123456789, 370123456789, 8123456789 then you can set mnp_prefixes variable with the following prefixes:

mnp_prefixes = 00370,370,8

then you will be able to upload only a single number 123456789 into the MNP database and this number will be matched when the client dials 00370123456789, 370123456789 or 8123456789.



MNP tags in SIP INVITE

MNP tags (npdi and rn) can be enabled by setting Enable MNP tags to yes in Provider configuration.

If MNP tags are enabled and MNP lookup was successful, then npdi and rn tags will be added to SIP INVITE:

INVITE sip:DST_NUMBER;npdi;rn=MNP_NUMBER@IP SIP/2.0

here:

  • DST_NUMBER - localized destination number, for example, +370123456789
  • MNP_NUMBER - localized destination number with MNP prefix, for example +370999123456789

If the number is not found in the MNP database, then only npdi tag will be added to SIP INVITE:

INVITE sip:DST_NUMBER;npdi@IP SIP/2.0

here:

  • DST_NUMBER - localized destination number, for example, +370123456


Note that only SIP INVITE requests will be modified. Other SIP headers (such as TO, FROM) are not affected by Enable MNP tags setting.



How to import numbers from CSV

There is no such option to import numbers from CSV in MOR GUI, but numbers can be imported directly to the MNP database.

This procedure is described here:

1. You need to have a CSV file on your server and the file should look like this:

...
37012312345;9991
37012312344;9991
37112312343;9992
37112354321;9992
...

2. Open MySQL CLI:

mysql mor_mnp

3. Create a temporary table and import a CSV file to it:

CREATE TABLE temp (col_1 VARCHAR(50) default NULL , col_2 VARCHAR(20) default NULL);
LOAD DATA LOCAL INFILE '/home/mnpnumbers.csv' IGNORE INTO TABLE temp FIELDS TERMINATED BY ';' ;

4. Copy data from the temporary table to 'numbers' table:

INSERT INTO numbers (number,prefix) SELECT TRIM(REPLACE(col_1, '\r', '')), TRIM(REPLACE(col_2, '\r', '')) FROM temp 
 WHERE ( TRIM(REPLACE(col_1, '\r', '')) REGEXP '^[0-9]+$' = 1) and (TRIM(REPLACE(col_2, '\r', '')) REGEXP '^[0-9]+$' = 1) ;


NOTE: This query skips values that contain non-numerical characters.

For example row

...
+370123123456;9997
...

will not be imported to 'numbers' table.

5. Detele temporary table:

DROP TABLE temp;

Done. Numbers are imported to 'numbers' table.

Automatic import script

Script downloads compressed (ZIP) CSV with a list of numbers from the SFTP server and imports in with default prefix to the MNP database. Current ZIP file required. Only SFTP is supported. The script does not import prefixes from CSV. CSV should contain an only list of numbers.

The script is located in /usr/src/mor/sh_scripts/mnp_numbers_import.sh

Script uses same configuration file /usr/local/mor/mor_mnp.conf . Options which are specific to this script:

download_url = sftp.server.com:/path/to/file.zip  #some remote location of a number file (for sftp)
username = ftpuser                                #user name to connect to a remote server
password = ftppassword                            #password for a user to connect to a remote server
default_prefix = 0009                             #default prefix for numbers (current version does not support prefix import)

Note:
If you are using MOR X18 version on Rocky Linux 9 and FTP server on older operating system then these errors can occur using the script:

Unable to negotiate with xxx.xxx.xxx.xxx port 22: no matching host key type found. Their offer: ssh-rsa,ssh-dss
ssh_dispatch_run_fatal: Connection to xxx.xxx.xxx.xxx port 22: error in libcrypto

The best way is to upgrade the FTP server to a new operating system. If you do not want to upgrade your FTP server, then you can use another option to run this command on the MOR Rocky Linux 9 server:

update-crypto-policies --set DEFAULT:SHA1



How to configure external MNP database

Skip this step if your MOR billing installation is on one server.

Locate mor_mnp.conf file

cd /usr/local/mor

Edit the file with your favorite text editor, for example:

mcedit mor_mnp.conf

You should see similar values, mind the gaps in the file, they should be exactly the same as in the example below:

host = localhost
db = mor_mnp
user = mor
secret = mor
port = 3306
server_id = 1
show_sql = 0
debug = 1
mnp_prefixes = 00370,370,8

Change the values to the ones you need:

host - your database IP address
server_id - your Asterisk server id, same as in /etc/asterisk/mor.conf

How can I add a specific prefix on a call to the ported number?

It's possible to add a specific prefix on the call in this way:

  • Create a duplicated provider (for example, you have "Provider A (no MNP) and "Provider A (with MNP)")
  • Create Provider Rules for that provider by adding a prefix 060
  • MOR will route numbers in the MNP database through that provider according to the Provider Rules.



See also