Harald Welte | 2cefa1c | 2011-04-03 01:54:32 +0200 | [diff] [blame] | 1 | -module(m3ua_codec_tests). |
| 2 | -author('Harald Welte <laforge@gnumonks.org>'). |
| 3 | |
| 4 | -include_lib("eunit/include/eunit.hrl"). |
| 5 | |
| 6 | -include("m3ua.hrl"). |
| 7 | -include("mtp3.hrl"). |
| 8 | |
| 9 | |
| 10 | % individual message encode/decode tests |
| 11 | |
| 12 | -define(MSG_ENC, <<1,0,1,1,0,0,0,168,2,0,0,8,1,171,205,239,0,6,0,8,17,34,51,68,2,16,0,136, 0,1,3,5,0,1,1,1,3,2,8,14,9,1,3,14,25,11,146,6,0,18,4,25,153,150,118,57, 152,11,18,8,0,18,4,25,137,150,146,153,41,90,98,88,72,4,134,18,5,114,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,5,3,108, 52,161,50,2,1,128,2,1,22,48,42,128,7,145,25,153,150,118,57,152,131,1,0, 133,1,1,134,7,145,25,137,150,146,153,41,135,8,155,172,3,185,8,16,174, 125,171,6,3,2,6,192,5,0,0,19,0,8,252,220,18,152>>). |
| 13 | -define(MSG_DEC, {m3ua_msg,1,1,1,164,[{512,<<1,171,205,239>>},{6,<<17,34,51,68>>},{528,{mtp3_msg,2,3,{mtp3_routing_label,14,65793,66309},8,<<9,1,3,14,25,11,146,6,0,18,4,25,153,150,118,57,152,11,18,8,0,18,4,25,137,150,146,153,41,90,98,88,72,4,134,18,5,114,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,5,3,108,52,161,50,2,1,128,2,1,22,48,42,128,7,145,25,153,150,118,57,152,131,1,0,133,1,1,134,7,145,25,137,150,146,153,41,135,8,155,172,3,185,8,16,174,125,171,6,3,2,6,192,5,0>>}},{19,<<252,220,18,152>>}]}). |
| 14 | |
| 15 | %dec_test() -> |
| 16 | % ?assertEqual(?MSG_DEC, m3ua_codec:parse_m3ua_msg(?MSG_ENC)). |
| 17 | %enc_test() -> |
| 18 | % ?assertEqual(?MSG_ENC, m3ua_codec:encode_m3ua_msg(?MSG_DEC)). |
| 19 | |
| 20 | |
| 21 | % parser test for real-world ISUP data |
| 22 | pcap_parse_test() -> |
| 23 | Args = [{rewrite_fn, fun pcap_cb/5}], |
| 24 | File = "../priv/m3ua.pcap", |
| 25 | case file:read_file_info(File) of |
| 26 | {ok, _Info} -> |
| 27 | {ok, NrPkts} = osmo_ss7_pcap:pcap_apply(File, "", Args), |
| 28 | ?debugFmt("Parsed ~p PCAP packets~n", [NrPkts]); |
| 29 | {error, _Reason} -> |
| 30 | ?debugFmt("Skipping PCAP based tests as no ~p could be found~n", |
| 31 | [File]) |
| 32 | end. |
| 33 | |
| 34 | pcap_cb(sctp, _From, _Path, 3, DataBin) -> |
| 35 | %?debugFmt("PCAP ~p~n", [DataBin]), |
| 36 | M3ua = m3ua_codec:parse_m3ua_msg(DataBin), |
| 37 | NewBin = m3ua_codec:encode_m3ua_msg(M3ua), |
| 38 | handle_m3ua(M3ua), |
| 39 | ?assertEqual(DataBin, NewBin). |
| 40 | |
| 41 | handle_m3ua(#m3ua_msg{msg_class = ?M3UA_MSGC_TRANSFER, msg_type = ?M3UA_MSGT_XFR_DATA, |
| 42 | payload = OptList}) -> |
| 43 | %?debugFmt("TRANSFER OptList ~p~n", [OptList]), |
| 44 | Mtp3 = proplists:get_value(?M3UA_IEI_PROTOCOL_DATA, OptList), |
| 45 | handle_mtp3(Mtp3); |
| 46 | handle_m3ua(#m3ua_msg{}) -> |
| 47 | ok. |
| 48 | |
| 49 | handle_mtp3(Mtp3 = #mtp3_msg{service_ind = ?MTP3_SERV_SCCP, payload = Payload}) -> |
| 50 | {ok, SccpDec} = sccp_codec:parse_sccp_msg(Payload), |
| 51 | SccpEnc = sccp_codec:encode_sccp_msg(SccpDec), |
| 52 | ?assertEqual(Payload, SccpEnc); |
| 53 | handle_mtp3(#mtp3_msg{}) -> |
| 54 | ok. |