rename sua_codec to generic xua_codec
SUA/M3UA/M2UA/M2PA actaully all uses almost the same message format, so it makes sense to write one generic xua_codec and derive from that. The current SUA implementation didn't actually contain anything SUA specific, so we can just rename it and use xua_codec directly from the users.
This commit is contained in:
parent
7aff8fb62b
commit
92e783d109
|
@ -11,7 +11,7 @@
|
|||
m2pa_codec, sctp_m2pa,
|
||||
m3ua_codec, m3ua_core, m3ua_example, m3ua_asp,
|
||||
mtp3_codec, mtp3_hmdt, mtp3_sltc,
|
||||
sua_codec, sua_sccp_conv, sua_asp, sctp_sua,
|
||||
xua_codec, sua_sccp_conv, sua_asp, sctp_sua,
|
||||
xua_asp_fsm,
|
||||
sccp_codec,
|
||||
osmo_ss7_sup, osmo_ss7_app,
|
||||
|
|
|
@ -114,11 +114,3 @@
|
|||
-define(SUA_RI_SSN_PC, 2).
|
||||
-define(SUA_RI_HOST, 3).
|
||||
-define(SUA_RI_SSN_IP, 4).
|
||||
|
||||
-record(sua_msg, {
|
||||
version :: 0..255,
|
||||
msg_class :: 0..255,
|
||||
msg_type :: 0..255,
|
||||
payload
|
||||
}).
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
-record(xua_msg, {
|
||||
version :: 0..255,
|
||||
msg_class :: 0..255,
|
||||
msg_type :: 0..255,
|
||||
payload
|
||||
}).
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
-include_lib("kernel/include/inet_sctp.hrl").
|
||||
-include("osmo_util.hrl").
|
||||
-include("xua.hrl").
|
||||
-include("sua.hrl").
|
||||
-include("m3ua.hrl").
|
||||
|
||||
|
@ -77,29 +78,29 @@ prim_up(Prim, State, LoopDat) ->
|
|||
% sctp_core indicates that ew have received some data...
|
||||
rx_sctp(#sctp_sndrcvinfo{ppid = ?SUA_PPID}, Data, State, LoopDat) ->
|
||||
Asp = LoopDat#sua_state.asp_pid,
|
||||
Sua = sua_codec:parse_msg(Data),
|
||||
Sua = xua_codec:parse_msg(Data),
|
||||
case Sua of
|
||||
#sua_msg{msg_class = ?M3UA_MSGC_MGMT,
|
||||
#xua_msg{msg_class = ?M3UA_MSGC_MGMT,
|
||||
msg_type = ?M3UA_MSGT_MGMT_NTFY} ->
|
||||
Prim = osmo_util:make_prim('M','NOTIFY',indication,Sua),
|
||||
{ok, Prim, LoopDat};
|
||||
#sua_msg{msg_class = ?M3UA_MSGC_MGMT,
|
||||
#xua_msg{msg_class = ?M3UA_MSGC_MGMT,
|
||||
msg_type = ?M3UA_MSGT_MGMT_ERR} ->
|
||||
Prim = osmo_util:make_prim('M','ERROR',indication,Sua),
|
||||
{ok, Prim, LoopDat};
|
||||
#sua_msg{msg_class = ?M3UA_MSGC_SSNM} ->
|
||||
#xua_msg{msg_class = ?M3UA_MSGC_SSNM} ->
|
||||
% FIXME
|
||||
{ignore, LoopDat};
|
||||
#sua_msg{msg_class = ?M3UA_MSGC_ASPSM} ->
|
||||
#xua_msg{msg_class = ?M3UA_MSGC_ASPSM} ->
|
||||
gen_fsm:send_event(Asp, Sua),
|
||||
{ignore, LoopDat};
|
||||
#sua_msg{msg_class = ?M3UA_MSGC_ASPTM} ->
|
||||
#xua_msg{msg_class = ?M3UA_MSGC_ASPTM} ->
|
||||
gen_fsm:send_event(Asp, Sua),
|
||||
{ignore, LoopDat};
|
||||
#sua_msg{msg_class = ?SUA_MSGC_CL} ->
|
||||
#xua_msg{msg_class = ?SUA_MSGC_CL} ->
|
||||
Prim = sua_to_prim(Sua, LoopDat),
|
||||
{ok, Prim, LoopDat};
|
||||
%#sua_msg{msg_class = ?SUA_MSGC_C0} ->
|
||||
%#xua_msg{msg_class = ?SUA_MSGC_C0} ->
|
||||
_ ->
|
||||
% do something with link related msgs
|
||||
io:format("SUA Unknown message ~p in state ~p~n", [Sua, State]),
|
||||
|
@ -107,8 +108,8 @@ rx_sctp(#sctp_sndrcvinfo{ppid = ?SUA_PPID}, Data, State, LoopDat) ->
|
|||
end.
|
||||
|
||||
% MTP-TRANSFER.req has arrived at sctp_core, encapsulate+tx it
|
||||
mtp_xfer(Sua, LoopDat) when is_record(Sua, sua_msg) ->
|
||||
SuaBin = sua_codec:encode_msg(Sua),
|
||||
mtp_xfer(Sua, LoopDat) when is_record(Sua, xua_msg) ->
|
||||
SuaBin = xua_codec:encode_msg(Sua),
|
||||
tx_sctp(1, SuaBin),
|
||||
LoopDat.
|
||||
|
||||
|
@ -137,6 +138,6 @@ asp_prim_to_user(Prim, [SctpPid]) ->
|
|||
gen_fsm:send_event(SctpPid, Prim).
|
||||
|
||||
|
||||
sua_to_prim(Sua, LoopDat) when is_record(Sua, sua_msg) ->
|
||||
sua_to_prim(Sua, LoopDat) when is_record(Sua, xua_msg) ->
|
||||
Sccp = sua_sccp_conv:sua_to_sccp(Sua),
|
||||
osmo_util:make_prim('N','UNITADATA',indication, Sccp).
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
-include("osmo_util.hrl").
|
||||
-include("m3ua.hrl").
|
||||
-include("sua.hrl").
|
||||
-include("xua.hrl").
|
||||
|
||||
-export([init/1]).
|
||||
|
||||
|
@ -33,44 +34,44 @@ init([]) ->
|
|||
{ok, we_have_no_state}.
|
||||
|
||||
gen_xua_msg(MsgClass, MsgType, Params) ->
|
||||
#sua_msg{version = 1, msg_class = MsgClass, msg_type = MsgType, payload = Params}.
|
||||
#xua_msg{version = 1, msg_class = MsgClass, msg_type = MsgType, payload = Params}.
|
||||
|
||||
asp_down(#sua_msg{version = 1, msg_class = MsgClass, msg_type = MsgType},
|
||||
asp_down(#xua_msg{version = 1, msg_class = MsgClass, msg_type = MsgType},
|
||||
LoopDat, Mld) when MsgClass == ?M3UA_MSGC_ASPSM; MsgClass == ?M3UA_MSGC_ASPTM ->
|
||||
% convert from SUA to xua_msg and call into master module
|
||||
xua_asp_fsm:asp_down({xua_msg, MsgClass, MsgType}, Mld);
|
||||
asp_down(SuaMsg, LoopDat, Mld) when is_record(SuaMsg, sua_msg) ->
|
||||
asp_down(SuaMsg, LoopDat, Mld) when is_record(SuaMsg, xua_msg) ->
|
||||
rx_sua(SuaMsg, asp_down, Mld).
|
||||
|
||||
asp_inactive(#sua_msg{version = 1, msg_class = MsgClass, msg_type = MsgType},
|
||||
asp_inactive(#xua_msg{version = 1, msg_class = MsgClass, msg_type = MsgType},
|
||||
LoopDat, Mld) when MsgClass == ?M3UA_MSGC_ASPSM; MsgClass == ?M3UA_MSGC_ASPTM ->
|
||||
% convert from SUA to xua_msg and call into master module
|
||||
xua_asp_fsm:asp_inactive({xua_msg, MsgClass, MsgType}, Mld);
|
||||
asp_inactive(SuaMsg, LoopDat, Mld) when is_record(SuaMsg, sua_msg) ->
|
||||
asp_inactive(SuaMsg, LoopDat, Mld) when is_record(SuaMsg, xua_msg) ->
|
||||
rx_sua(SuaMsg, asp_inactive, Mld).
|
||||
|
||||
asp_active(#sua_msg{version = 1, msg_class = MsgClass, msg_type = MsgType},
|
||||
asp_active(#xua_msg{version = 1, msg_class = MsgClass, msg_type = MsgType},
|
||||
LoopDat, Mld) when MsgClass == ?M3UA_MSGC_ASPSM; MsgClass == ?M3UA_MSGC_ASPTM ->
|
||||
% convert from SUA to xua_msg and call into master module
|
||||
xua_asp_fsm:asp_active({xua_msg, MsgClass, MsgType}, Mld);
|
||||
asp_active(SuaMsg, LoopDat, Mld) when is_record(SuaMsg, sua_msg) ->
|
||||
asp_active(SuaMsg, LoopDat, Mld) when is_record(SuaMsg, xua_msg) ->
|
||||
rx_sua(SuaMsg, asp_active, Mld).
|
||||
|
||||
|
||||
|
||||
rx_sua(Msg = #sua_msg{version = 1, msg_class = ?M3UA_MSGC_ASPSM,
|
||||
rx_sua(Msg = #xua_msg{version = 1, msg_class = ?M3UA_MSGC_ASPSM,
|
||||
msg_type = ?M3UA_MSGT_ASPSM_BEAT}, State, LoopDat) ->
|
||||
% Send BEAT_ACK using the same payload as the BEAT msg
|
||||
xua_asp_fsm:send_sctp_to_peer(LoopDat, Msg#sua_msg{msg_type = ?M3UA_MSGT_ASPSM_BEAT_ACK}),
|
||||
xua_asp_fsm:send_sctp_to_peer(LoopDat, Msg#xua_msg{msg_type = ?M3UA_MSGT_ASPSM_BEAT_ACK}),
|
||||
{next_state, State, LoopDat};
|
||||
|
||||
%rx_sua(Msg = #sua_msg{version = 1, msg_class = ?M3UA_MSGC_SSNM,
|
||||
%rx_sua(Msg = #xua_msg{version = 1, msg_class = ?M3UA_MSGC_SSNM,
|
||||
%msg_type = MsgType, payload = Params}, State, LoopDat) ->
|
||||
% transform to classic MTP primitive and send up to the user
|
||||
%Mtp = map_ssnm_to_mtp_prim(MsgType),
|
||||
%send_prim_to_user(LoopDat, Mtp),
|
||||
%{next_state, State, LoopDat};
|
||||
|
||||
rx_sua(Msg = #sua_msg{}, State, LoopDat) ->
|
||||
rx_sua(Msg = #xua_msg{}, State, LoopDat) ->
|
||||
io:format("SUA Unknown messge ~p in state ~p~n", [Msg, State]),
|
||||
{next_state, State, LoopDat}.
|
||||
|
|
|
@ -23,11 +23,12 @@
|
|||
-author('Harald Welte <laforge@gnumonks.org>').
|
||||
|
||||
-include("sua.hrl").
|
||||
-include("xua.hrl").
|
||||
-include("sccp.hrl").
|
||||
|
||||
-export([sua_to_sccp/1, sccp_to_sua/1]).
|
||||
|
||||
sua_to_sccp(M=#sua_msg{msg_class = Class, msg_type = Type}) ->
|
||||
sua_to_sccp(M=#xua_msg{msg_class = Class, msg_type = Type}) ->
|
||||
sua_to_sccp(Class, Type, M).
|
||||
sua_to_sccp(?SUA_MSGC_CL, ?SUA_CL_CLDT, Sua) ->
|
||||
Params = sua_to_sccp_params(Sua),
|
||||
|
@ -44,13 +45,13 @@ sccp_to_sua(Type, Params) when Type == ?SCCP_MSGT_UDT;
|
|||
Type == ?SCCP_MSGT_XUDT;
|
||||
Type == ?SCCP_MSGT_LUDT ->
|
||||
Opts = sccp_to_sua_params(Type, Params),
|
||||
#sua_msg{version = 1, msg_class = ?SUA_MSGC_CL,
|
||||
#xua_msg{version = 1, msg_class = ?SUA_MSGC_CL,
|
||||
msg_type = ?SUA_CL_CLDT, payload = Opts};
|
||||
sccp_to_sua(Type, Params) when Type == ?SCCP_MSGT_UDTS;
|
||||
Type == ?SCCP_MSGT_XUDTS;
|
||||
Type == ?SCCP_MSGT_LUDTS ->
|
||||
Opts = sccp_to_sua_params(Params),
|
||||
#sua_msg{version=1, msg_class = ?SUA_MSGC_CL,
|
||||
#xua_msg{version=1, msg_class = ?SUA_MSGC_CL,
|
||||
msg_type = ?SUA_CL_CLDR, payload = Opts}.
|
||||
|
||||
|
||||
|
@ -60,7 +61,7 @@ sccp_to_sua(Type, Params) when Type == ?SCCP_MSGT_UDTS;
|
|||
% ?SUA_IEI_IMPORTANCE, ?SUA_IEI_MSG_PRIO, ?SUA_IEI_CORR_ID,
|
||||
% ?SUA_IEI_SEGMENTATION, ?SUA_IEI_DATA
|
||||
|
||||
sua_to_sccp_params(#sua_msg{msg_class=Class, msg_type=Type, payload=Payload}) ->
|
||||
sua_to_sccp_params(#xua_msg{msg_class=Class, msg_type=Type, payload=Payload}) ->
|
||||
sua_to_sccp_params(Class, Type, Payload).
|
||||
sua_to_sccp_params(Class, Type, Payload) ->
|
||||
sua_to_sccp_params(Class, Type, Payload, []).
|
||||
|
@ -154,7 +155,7 @@ sua_to_sccp_addr(SuaBin) ->
|
|||
#sccp_addr{route_on_ssn = RoutSSN, point_code = PC, ssn = SSN, global_title = GT}.
|
||||
|
||||
addr_pars_to_list(Bin) ->
|
||||
sua_codec:parse_xua_opts(Bin).
|
||||
xua_codec:parse_xua_opts(Bin).
|
||||
|
||||
sccp_to_sua_addr(Addr) when is_record(Addr, sccp_addr) ->
|
||||
#sccp_addr{route_on_ssn = RoutOnSsn, point_code = PC, ssn = SSN,
|
||||
|
@ -189,7 +190,7 @@ sccp_to_sua_addr(Addr) when is_record(Addr, sccp_addr) ->
|
|||
1 ->
|
||||
RoutInd = ?SUA_RI_SSN_PC
|
||||
end,
|
||||
Tail = sua_codec:encode_xua_opts(GTopt ++ PCopt ++ SSNopt),
|
||||
Tail = xua_codec:encode_xua_opts(GTopt ++ PCopt ++ SSNopt),
|
||||
<<RoutInd:16, 0:13, GTinc:1, PCinc:1, SSNinc:1, Tail/binary>>.
|
||||
|
||||
parse_sua_gt(Bin) ->
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
% You should have received a copy of the GNU Affero General Public License
|
||||
% along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
-module(sua_codec).
|
||||
-module(xua_codec).
|
||||
-author('Harald Welte <laforge@gnumonks.org>').
|
||||
-include("sua.hrl").
|
||||
-include("xua.hrl").
|
||||
|
||||
-export([parse_msg/1, encode_msg/1, parse_xua_opts/1, encode_xua_opts/1]).
|
||||
|
||||
|
@ -27,7 +27,7 @@ parse_msg(DataBin) when is_binary(DataBin) ->
|
|||
<<Version:8, _Reserved:8, MsgClass:8, MsgType:8, MsgLen:32/big, Remain/binary>> = DataBin,
|
||||
RemainLen = MsgLen - 4,
|
||||
OptList = parse_xua_opts(Remain),
|
||||
#sua_msg{version = Version, msg_class = MsgClass, msg_type = MsgType,
|
||||
#xua_msg{version = Version, msg_class = MsgClass, msg_type = MsgType,
|
||||
payload = OptList};
|
||||
parse_msg(Data) when is_list(Data) ->
|
||||
parse_msg(list_to_binary(Data)).
|
||||
|
@ -60,7 +60,7 @@ parse_xua_opts(OptBin, OptList) when is_binary(OptBin), is_list(OptList) ->
|
|||
|
||||
|
||||
|
||||
encode_msg(#sua_msg{version = Version, msg_class = MsgClass,
|
||||
encode_msg(#xua_msg{version = Version, msg_class = MsgClass,
|
||||
msg_type = MsgType, payload = OptList}) ->
|
||||
OptBin = encode_xua_opts(OptList),
|
||||
MsgLen = byte_size(OptBin) + 8,
|
|
@ -3,14 +3,15 @@
|
|||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-include("xua.hrl").
|
||||
-include("sua.hrl").
|
||||
|
||||
|
||||
-define(MSG_ENC, <<1,0,7,1,0,0,0,208,0,6,0,8,0,0,0,3,1,21,0,8,0,0,0,1,1,2,0,44,0,1,0,7,128,1,0,20,0,0,0,4,12,0,1,4,68,119,121,7,22,0,0,0,128,2,0,8,0,0,8,21,128,3,0,8,0,0,0,7,1,3,0,44,0,1,0,7,128,1,0,20,0,0,0,4,15,0,7,4,8,18,17,9,97,16,81,1,128,2,0,8,0,0,8,22,128,3,0,8,0,0,0,6,1,22,0,8,0,0,0,0,1,11,0,86,98,80,72,4,0,0,32,64,107,26,40,24,6,7,0,17,134,5,1,1,1,160,13,96,11,161,9,6,7,4,0,0,1,0,1,3,108,44,161,42,2,1,0,2,1,2,48,34,4,8,0,1,17,9,97,16,81,241,129,7,145,8,18,1,0,0,242,4,7,145,68,119,121,7,22,0,166,4,128,2,6,192,0,0>>).
|
||||
-define(MSG_DEC, {sua_msg,1,7,1,[{6,{4,<<0,0,0,3>>}},{277,{4,<<0,0,0,1>>}},{258,{40,<<0,1,0,7,128,1,0,20,0,0,0,4,12,0,1,4,68,119,121,7,22,0,0,0,128,2,0,8,0,0,8,21,128,3,0,8,0,0,0,7>>}},{259,{40,<<0,1,0,7,128,1,0,20,0,0,0,4,15,0,7,4,8,18,17,9,97,16,81,1,128,2,0,8,0,0,8,22,128,3,0,8,0,0,0,6>>}},{278,{4,<<0,0,0,0>>}},{267,{82,<<98,80,72,4,0,0,32,64,107,26,40,24,6,7,0,17,134,5,1,1,1,160,13,96,11,161,9,6,7,4,0,0,1,0,1,3,108,44,161,42,2,1,0,2,1,2,48,34,4,8,0,1,17,9,97,16,81,241,129,7,145,8,18,1,0,0,242,4,7,145,68,119,121,7,22,0,166,4,128,2,6,192>>}}]}).
|
||||
-define(MSG_DEC, {xua_msg,1,7,1,[{6,{4,<<0,0,0,3>>}},{277,{4,<<0,0,0,1>>}},{258,{40,<<0,1,0,7,128,1,0,20,0,0,0,4,12,0,1,4,68,119,121,7,22,0,0,0,128,2,0,8,0,0,8,21,128,3,0,8,0,0,0,7>>}},{259,{40,<<0,1,0,7,128,1,0,20,0,0,0,4,15,0,7,4,8,18,17,9,97,16,81,1,128,2,0,8,0,0,8,22,128,3,0,8,0,0,0,6>>}},{278,{4,<<0,0,0,0>>}},{267,{82,<<98,80,72,4,0,0,32,64,107,26,40,24,6,7,0,17,134,5,1,1,1,160,13,96,11,161,9,6,7,4,0,0,1,0,1,3,108,44,161,42,2,1,0,2,1,2,48,34,4,8,0,1,17,9,97,16,81,241,129,7,145,8,18,1,0,0,242,4,7,145,68,119,121,7,22,0,166,4,128,2,6,192>>}}]}).
|
||||
|
||||
|
||||
dec_test() ->
|
||||
?assertEqual(?MSG_DEC, sua_codec:parse_msg(?MSG_ENC)).
|
||||
?assertEqual(?MSG_DEC, xua_codec:parse_msg(?MSG_ENC)).
|
||||
enc_test() ->
|
||||
?assertEqual(?MSG_ENC, sua_codec:encode_msg(?MSG_DEC)).
|
||||
?assertEqual(?MSG_ENC, xua_codec:encode_msg(?MSG_DEC)).
|
||||
|
|
Loading…
Reference in New Issue