MGW NAT: add option to 'internationalize' a national number that's prefixed with 00
This commit is contained in:
parent
7c406d31d7
commit
8b79ebea5a
|
@ -1,4 +1,4 @@
|
|||
%
|
||||
% MGW NAT core routines as well as ISUP + SCCP Rewriting
|
||||
|
||||
% (C) 2011 by Harald Welte <laforge@gnumonks.org>
|
||||
% (C) 2011 OnWaves
|
||||
|
@ -28,7 +28,8 @@
|
|||
-export([mangle_rx_sccp/4, mangle_rx_isup/4]).
|
||||
|
||||
% exports belwo needed by map_masq.erl
|
||||
-export([isup_party_internationalize/2, isup_party_nationalize/2, isup_party_replace_prefix/3]).
|
||||
-export([isup_party_internationalize/2, isup_party_nationalize/2, isup_party_replace_prefix/3,
|
||||
isup_party_nat00_internationalize/1]).
|
||||
|
||||
%-include_lib("kernel/include/inet.hrl").
|
||||
%-include_lib("kernel/include/inet_sctp.hrl").
|
||||
|
@ -229,6 +230,8 @@ mangle_isup_number(from_stp, ?ISUP_MSGT_IAM, NumType, PartyNum) ->
|
|||
Num1 = isup_party_internationalize(PartyNum, InternPfx),
|
||||
io:format("IAM MSRN rewrite (STP->MSC): "),
|
||||
isup_party_replace_prefix(Num1, MsrnPfxStp, MsrnPfxMsc);
|
||||
?ISUP_PAR_CALLING_P_NUM ->
|
||||
isup_party_nat00_internationalize(PartyNum);
|
||||
_ ->
|
||||
PartyNum
|
||||
end;
|
||||
|
@ -301,6 +304,27 @@ isup_party_internationalize(PartyNum, CountryCodeInt) ->
|
|||
end,
|
||||
PartyNum#party_number{phone_number = DigitsOut, nature_of_addr_ind = NatureOut}.
|
||||
|
||||
% take something like {national, 00493024033902} and make {intl, 493024033902}
|
||||
isup_party_nat00_internationalize(PartyNum) ->
|
||||
#party_number{phone_number = DigitsIn, nature_of_addr_ind = Nature} = PartyNum,
|
||||
case Nature of
|
||||
?ISUP_ADDR_NAT_NATIONAL ->
|
||||
{Pfx, Remain} = lists:split(2, DigitsIn),
|
||||
if Pfx == [0, 0] ->
|
||||
DigitsOut = Remain,
|
||||
NatureOut = ?ISUP_ADDR_NAT_INTERNATIONAL,
|
||||
io:format("National+00 -> International: ~p -> ~p~n",
|
||||
[DigitsIn, DigitsOut]);
|
||||
true ->
|
||||
DigitsOut = DigitsIn,
|
||||
NatureOut = Nature
|
||||
end;
|
||||
_ ->
|
||||
DigitsOut = DigitsIn,
|
||||
NatureOut = Nature
|
||||
end,
|
||||
PartyNum#party_number{phone_number = DigitsOut, nature_of_addr_ind = NatureOut}.
|
||||
|
||||
isup_party_nationalize(PartyNum, CountryCodeInt) ->
|
||||
#party_number{phone_number = DigitsIn, nature_of_addr_ind = Nature} = PartyNum,
|
||||
CountryCode = osmo_util:int2digit_list(CountryCodeInt),
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
-module(mgw_nat_tests).
|
||||
-author('Harald Welte <laforge@gnumonks.org>').
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-include_lib("osmo_map/include/map.hrl").
|
||||
-include_lib("osmo_ss7/include/isup.hrl").
|
||||
|
||||
-define(PARTY_NUM_NAT, #party_number{phone_number = [9,1,1,4,8,5,3,2,1],
|
||||
nature_of_addr_ind = ?ISUP_ADDR_NAT_NATIONAL}).
|
||||
|
||||
-define(PARTY_NUM_INT, #party_number{phone_number = [4,9,9,1,1,4,8,5,3,2,1],
|
||||
nature_of_addr_ind = ?ISUP_ADDR_NAT_INTERNATIONAL}).
|
||||
internationalize_test() ->
|
||||
?assertEqual(?PARTY_NUM_INT, mgw_nat:isup_party_internationalize(?PARTY_NUM_NAT, 49)).
|
||||
|
||||
nationalize_test() ->
|
||||
?assertEqual(?PARTY_NUM_NAT, mgw_nat:isup_party_nationalize(?PARTY_NUM_INT, 49)).
|
||||
|
||||
-define (PARTY_NUM_00_NAT, #party_number{phone_number = [0,0,4,9,9,1,1,4,8,5,3,2,1],
|
||||
nature_of_addr_ind = ?ISUP_ADDR_NAT_NATIONAL}).
|
||||
|
||||
nat00_internationalize_test() ->
|
||||
?assertEqual(?PARTY_NUM_INT, mgw_nat:isup_party_nat00_internationalize(?PARTY_NUM_00_NAT)).
|
Loading…
Reference in New Issue