Harald Welte | c60e840 | 2011-03-08 23:02:32 +0100 | [diff] [blame] | 1 | -module(map_codec_tests). |
| 2 | -author('Harald Welte <laforge@gnumonks.org>'). |
| 3 | |
| 4 | -include_lib("eunit/include/eunit.hrl"). |
| 5 | |
| 6 | -include("map.hrl"). |
| 7 | -include_lib("osmo_ss7/include/isup.hrl"). |
Harald Welte | 49525f8 | 2011-03-11 18:47:23 +0100 | [diff] [blame^] | 8 | -include_lib("osmo_ss7/include/m2ua.hrl"). |
| 9 | -include_lib("osmo_ss7/include/mtp3.hrl"). |
| 10 | -include_lib("osmo_ss7/include/sccp.hrl"). |
Harald Welte | c60e840 | 2011-03-08 23:02:32 +0100 | [diff] [blame] | 11 | |
| 12 | -define(TCAP_MSG_BIN, <<100,65,73,4,81,1,2,200,107,42,40,40,6,7,0,17,134,5,1,1,1,160,29,97,27,128,2,7,128,161,9,6,7,4,0,0,1,0,1,3,162,3,2,1,0,163,5,161,3,2,1,0,108,13,163,11,2,1,64,2,1,8,48,3,10,1,0>>). |
| 13 | -define(TCAP_MSG_DEC, {'end',{'MapSpecificPDUs_end',[81,1,2,200],{'EXTERNAL',{syntax,{0,0,17,773,1,1,1}},asn1_NOVALUE,[97,27,128,2,7,128,161,9,6,7,4,0,0,1,0,1,3,162,3,2,1,0,163,5,161,3,2,1,0]},[{basicROS,{returnError,{'MapSpecificPDUs_end_components_SEQOF_basicROS_returnError',{present,64},{local,8},{'RoamingNotAllowedParam',plmnRoamingNotAllowed,asn1_NOVALUE}}}}]}}). |
| 14 | |
| 15 | parse_test() -> |
| 16 | ?assertEqual(?TCAP_MSG_DEC, map_codec:parse_tcap_msg(?TCAP_MSG_BIN)). |
Harald Welte | 49525f8 | 2011-03-11 18:47:23 +0100 | [diff] [blame^] | 17 | % BER allows for different binary encodings of each message, the test below is not valid |
| 18 | %encode_test() -> |
| 19 | % ?assertEqual(?TCAP_MSG_BIN, map_codec:encode_tcap_msg(?TCAP_MSG_DEC)). |
Harald Welte | c60e840 | 2011-03-08 23:02:32 +0100 | [diff] [blame] | 20 | |
| 21 | -define(ADDR_DEC, #party_number{nature_of_addr_ind = ?ISUP_ADDR_NAT_INTERNATIONAL, |
| 22 | internal_net_num = undefined, |
| 23 | number_incompl_ind = undefined, |
| 24 | numbering_plan = 0, |
| 25 | present_restrict = undefined, |
| 26 | screening_ind = undefined, |
| 27 | phone_number = [1,2,3,4,5,6,7,8,9,0]}). |
| 28 | -define(ADDR_LIST, [144,33,67,101,135,9]). |
| 29 | |
| 30 | encode_addr_list_test() -> |
| 31 | ?assertEqual(?ADDR_LIST, map_codec:encode_addr_string(?ADDR_DEC)). |
| 32 | encode_addr_int_test() -> |
| 33 | AddrDec = ?ADDR_DEC, |
| 34 | ?assertEqual(?ADDR_LIST, map_codec:encode_addr_string(AddrDec#party_number{phone_number=1234567890})). |
| 35 | decode_addr_list_test() -> |
| 36 | ?assertEqual(?ADDR_DEC, map_codec:parse_addr_string(?ADDR_LIST)). |
| 37 | decode_addr_bin_test() -> |
| 38 | ?assertEqual(?ADDR_DEC, map_codec:parse_addr_string(list_to_binary(?ADDR_LIST))). |
Harald Welte | 49525f8 | 2011-03-11 18:47:23 +0100 | [diff] [blame^] | 39 | |
| 40 | |
| 41 | pcap_parse_test_() -> |
| 42 | { timeout, 5*60, [ fun pcap_parse_t/0 ] }. |
| 43 | |
| 44 | % parser test for real-world MAP/TCAP data |
| 45 | pcap_parse_t() -> |
| 46 | Args = [{rewrite_fn, fun pcap_cb/5}], |
| 47 | File = "../priv/map.pcap", |
| 48 | case file:read_file_info(File) of |
| 49 | {ok, _Info} -> |
| 50 | {ok, NrPkts} = ?debugTime("PCAP", osmo_ss7_pcap:pcap_apply(File, "", Args)), |
| 51 | ?debugFmt("Parsed ~p PCAP packets~n", [NrPkts]); |
| 52 | {error, _Reason} -> |
| 53 | ?debugFmt("Skipping PCAP based tests as no ~p could be found~n", |
| 54 | [File]) |
| 55 | end. |
| 56 | |
| 57 | pcap_cb(sctp, _From, _Path, 2, DataBin) -> |
| 58 | {ok, M2ua} = m2ua_codec:parse_m2ua_msg(DataBin), |
| 59 | handle_m2ua(M2ua). |
| 60 | |
| 61 | handle_m2ua(#m2ua_msg{msg_class = ?M2UA_MSGC_MAUP, |
| 62 | msg_type = ?M2UA_MAUP_MSGT_DATA, |
| 63 | parameters = Params}) -> |
| 64 | {_Len, M2uaPayload} = proplists:get_value(16#300, Params), |
| 65 | Mtp3 = mtp3_codec:parse_mtp3_msg(M2uaPayload), |
| 66 | handle_mtp3(Mtp3); |
| 67 | handle_m2ua(M2ua = #m2ua_msg{}) -> |
| 68 | M2ua. |
| 69 | |
| 70 | handle_mtp3(#mtp3_msg{service_ind = ?MTP3_SERV_SCCP, |
| 71 | payload = Payload}) -> |
| 72 | {ok, SccpDec} = sccp_codec:parse_sccp_msg(Payload), |
| 73 | SccpEnc = handle_sccp(SccpDec); |
| 74 | handle_mtp3(Mtp3 = #mtp3_msg{}) -> |
| 75 | Mtp3. |
| 76 | |
| 77 | handle_sccp(S = #sccp_msg{msg_type = ?SCCP_MSGT_UDT, parameters = Params}) -> |
| 78 | UserData = proplists:get_value(user_data, Params), |
| 79 | MapDec = map_codec:parse_tcap_msg(UserData), |
| 80 | MapReEnc = map_codec:encode_tcap_msg(MapDec), |
| 81 | S; |
| 82 | handle_sccp(S = #sccp_msg{}) -> |
| 83 | S. |