⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 megaco_call_flow_test.erl

📁 OTP是开放电信平台的简称
💻 ERL
📖 第 1 页 / 共 5 页
字号:
%% ``The contents of this file are subject to the Erlang Public License,%% Version 1.1, (the "License"); you may not use this file except in%% compliance with the License. You should have received a copy of the%% Erlang Public License along with this software. If not, it can be%% retrieved via the world wide web at http://www.erlang.org/.%%%% Software distributed under the License is distributed on an "AS IS"%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See%% the License for the specific language governing rights and limitations%% under the License.%%%% The Initial Developer of the Original Code is Ericsson Utvecklings AB.%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings%% AB. All Rights Reserved.''%%%%     $Id$%%%%----------------------------------------------------------------------%% Purpose: Test encoding/decoding of the sample call flows Megaco/H.248%%----------------------------------------------------------------------%% megaco_call_flow_test:pretty_text().%% megaco_call_flow_test:compact_text().%% megaco_call_flow_test:bin().%% megaco_call_flow_test:asn1_ber().%% megaco_call_flow_test:asn1_ber_bin().%% megaco_call_flow_test:asn1_per().%% megaco_call_flow_test:erl_dist().%% megaco_call_flow_test:compressed_erl_dist().%% megaco_call_flow_test:gnuplot_gif().%% megaco_call_flow_test:gnuplot_size_gif().%% megaco_call_flow_test:gnuplot_enc_time_gif().%% megaco_call_flow_test:gnuplot_dec_time_gif().%% megaco_call_flow_test:gnuplot_code_time_gif().%%-----------------------------------------------------------------------module(megaco_call_flow_test).-compile(export_all).-include_lib("megaco/include/megaco.hrl").-include_lib("megaco/include/megaco_message_v1.hrl").-include("megaco_test_lib.hrl").t()     -> megaco_test_lib:t(?MODULE).t(Case) -> megaco_test_lib:t({?MODULE, Case}).%% Test server callbacksinit_per_testcase(Case, Config) ->    megaco_test_lib:init_per_testcase(Case, Config).fin_per_testcase(Case, Config) ->    megaco_test_lib:fin_per_testcase(Case, Config).%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Top test caseall(suite) ->    [     text,     binary    ].text(suite) ->    [     pretty,     compact    ].flex(suite) ->    [     pretty_flex,     compact_flex    ].binary(suite) ->    [     bin,     ber,     ber_bin,     per    ].pretty(suite) ->    [];pretty(Config) when list(Config) ->    ?ACQUIRE_NODES(1, Config),    pretty_text().compact(suite) ->    [];compact(Config) when list(Config) ->    ?ACQUIRE_NODES(1, Config),    compact_text().pretty_flex(suite) ->    [];pretty_flex(Config) when list(Config) ->    ?ACQUIRE_NODES(1, Config),    pretty_flex().compact_flex(suite) ->    [];compact_flex(Config) when list(Config) ->    ?ACQUIRE_NODES(1, Config),    compact_flex().bin(suite) ->    [];bin(Config) when list(Config) ->    ?ACQUIRE_NODES(1, Config),    bin().ber(suite) ->    [];ber(Config) when list(Config) ->    ?ACQUIRE_NODES(1, Config),    asn1_ber().ber_bin(suite) ->    [];ber_bin(Config) when list(Config) ->    ?ACQUIRE_NODES(1, Config),    asn1_ber_bin().per(suite) ->    [];per(Config) when list(Config) ->    ?ACQUIRE_NODES(1, Config),    asn1_per().standard_erl(suite) ->    [];standard_erl(Config) when list(Config) ->    ?ACQUIRE_NODES(1, Config),    standard_erl().compressed_erl(suite) ->    [];compressed_erl(Config) when list(Config) ->    ?ACQUIRE_NODES(1, Config),    compressed_erl().%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-define(PP(Name, Val), #'PropertyParm'{name = Name, value = [Val]}).-define(SP(Name, Val), #'StatisticsParameter'{statName = Name, statValue = [Val]}) .names() ->    [     msg1, msg2, msg3, msg4, msg5a, msg5b, msg6, msg7, msg9, msg10,     msg11, msg12, msg13, msg14, msg15, msg16, msg17a, msg17b,     msg18a, msg18b, msg18c, msg18d, msg19a, msg19b, msg20, msg21,     msg22a, msg22b, msg23a, msg23b    ].%% In this example, MG1 has the IP address 124.124.124.222, MG2 is%% 125.125.125.111, and the MGC is 123.123.123.4. The default Megaco port%% is 55555 for all three.-define(DEFAULT_PORT, 55555).-define(MG1_MID_NO_PORT, {ip4Address,                          #'IP4Address'{address = [124, 124, 124, 222]}}).-define(MG1_MID, {ip4Address, #'IP4Address'{address = [124, 124, 124, 222],                                            portNumber = ?DEFAULT_PORT}}).-define(MG2_MID, {ip4Address, #'IP4Address'{address = [125, 125, 125, 111],                                            portNumber = ?DEFAULT_PORT}}).-define(MGC_MID, {ip4Address, #'IP4Address'{address = [123, 123, 123, 4],                                            portNumber = ?DEFAULT_PORT}}).-define(A4444, ["11111111", "00000000", "00000000"]).-define(A4445, ["11111111", "00000000", "11111111"]).-define(A5555, ["11111111", "11111111", "00000000"]).-define(A5556, ["11111111", "11111111", "11111111"]).%% -define(A4444, ["00000000"]).%% -define(A4445, ["00001111"]).%% -define(A5555, ["11110000"]).%% -define(A5556, ["11111111"]).request(Mid, TransId, ContextId, CmdReq) when list(CmdReq) ->    Actions = [#'ActionRequest'{contextId = ContextId,                                commandRequests = CmdReq}],    Req = {transactions,           [{transactionRequest,             #'TransactionRequest'{transactionId = TransId,                                   actions = Actions}}]},    #'MegacoMessage'{mess = #'Message'{version = 1,                                       mId = Mid,                                       messageBody = Req}}.reply(Mid, TransId, ContextId, CmdReply) when list(CmdReply) ->    Actions = [#'ActionReply'{contextId = ContextId,                              commandReply = CmdReply}],    Req = {transactions,           [{transactionReply,             #'TransactionReply'{transactionId = TransId,                                 transactionResult = {actionReplies, Actions}}}]},    #'MegacoMessage'{mess = #'Message'{version = 1,                                       mId = Mid,                                       messageBody = Req}}.%%----------------------------------------------------------------------%% 1. An MG registers with an MGC using the ServiceChange command:%%%% MG1 to MGC:%% "MEGACO/1 [124.124.124.222]%% Transaction = 9998 {%%     Context = - {%%         ServiceChange = ROOT {Services {%%             Method=Restart,%%             ServiceChangeAddress=55555, Profile=ResGW/1}%%         }%%     }%% }%%----------------------------------------------------------------------msg1() ->    msg1(?MG1_MID_NO_PORT).msg1(Mid) ->    Address = {portNumber, ?DEFAULT_PORT},    Profile = #'ServiceChangeProfile'{profileName = "resgw",                                      version = 1},    Parm = #'ServiceChangeParm'{serviceChangeMethod = restart,                                serviceChangeAddress = Address,                                serviceChangeReason  = ["901 mg cold boot"],                                %% BUGBUG: Mandatory reason missing in spec                                serviceChangeProfile = Profile},    Req = #'ServiceChangeRequest'{terminationID = [?megaco_root_termination_id],                                  serviceChangeParms = Parm},    CmdReq = #'CommandRequest'{command = {serviceChangeReq, Req}},    request(Mid, 9998, ?megaco_null_context_id, [CmdReq]).%%----------------------------------------------------------------------%%%% 2. The MGC sends a reply:%%%% MGC to MG1:%% MEGACO/1 [123.123.123.4]:55555%% Reply = 9998 {%%    Context = - {ServiceChange = ROOT {%%      Services {ServiceChangeAddress=55555, Profile=ResGW/1} } }%% }%%----------------------------------------------------------------------msg2() ->    msg2(?MGC_MID).msg2(Mid) ->    Address = {portNumber, ?DEFAULT_PORT},    Profile = #'ServiceChangeProfile'{profileName = "resgw",                                      version = 1},    Parm = #'ServiceChangeResParm'{serviceChangeAddress = Address,                                   serviceChangeProfile = Profile},    Reply = #'ServiceChangeReply'{terminationID = [?megaco_root_termination_id],                                  serviceChangeResult = {serviceChangeResParms,                                                         Parm}},    reply(Mid, 9998, ?megaco_null_context_id, [{serviceChangeReply, Reply}]).%%----------------------------------------------------------------------%% 3. The MGC programs a Termination in the NULL context. The%%    terminationId is A4444, the streamId is 1, the requestId in the%%    Events descriptor is 2222. The mId is the identifier of the sender%%    of this message, in this case, it is the IP address and port%%    [123.123.123.4]:55555. Mode for this stream is set to%%    SendReceive. "al" is the analog line supervision package.%%%% MGC to MG1:%% MEGACO/1 [123.123.123.4]:55555%% Transaction = 9999 {%%     Context = - {%%         Modify = A4444 {%%             Media { Stream = 1 {%%                      LocalControl {%%                          Mode = SendReceive,%%                          tdmc/gain=2,  ; in dB,%%                          tdmc/ec=G165%%                      },%%                      Local {%% v=0%% c=IN IP4 $%% m=audio $ RTP/AVP 0%% a=fmtp:PCMU VAD=X-NNVAD ; special voice activity%%                         ; detection algorithm%%                      }%%                  }%%             },%%             Events = 2222 {al/of}%%         }%%     }%% }%%----------------------------------------------------------------------msg3() ->    msg3(?MGC_MID).msg3(Mid) ->    msg3(Mid, ?A4444).msg3(Mid, Tid) ->    Gain = ?PP("tdmc/gain", "2"),    %% Ec   = ?PP("tdmc/ec", "G165"),    Ec   = ?PP("tdmc/ec", "g165"), %% BUGBUG: should be case insensitive    LCD = #'LocalControlDescriptor'{streamMode = sendRecv,                                    propertyParms = [Gain, Ec]},    V = ?PP("v", "0"),    C = ?PP("c", "IN IP4 $ "),    M = ?PP("m", "audio $ RTP/AVP 0"),    A = ?PP("a", "fmtp:PCMU VAD=X-NNVAD"),    LD = #'LocalRemoteDescriptor'{propGrps = [[V, C, M, A]]},    Parms = #'StreamParms'{localControlDescriptor = LCD,                           localDescriptor = LD},    StreamDesc = #'StreamDescriptor'{streamID = 1,                                     streamParms = Parms},    MediaDesc = #'MediaDescriptor'{streams = {multiStream, [StreamDesc]}},    ReqEvent = #'RequestedEvent'{pkgdName = "al/of",                                 evParList = []},    EventsDesc = #'EventsDescriptor'{requestID = 2222,                                     eventList = [ReqEvent]},    AmmReq = #'AmmRequest'{terminationID = [#megaco_term_id{id = Tid}],                           descriptors = [{mediaDescriptor, MediaDesc},                                          {eventsDescriptor, EventsDesc}]},    CmdReq = #'CommandRequest'{command = {modReq, AmmReq}},    request(Mid, 9999, ?megaco_null_context_id, [CmdReq]).%%----------------------------------------------------------------------%% The dialplan script could have been loaded into the MG previously.%% Its function would be to wait for the OffHook, turn on dialtone and%% start collecting DTMF digits. However in this example, we use the%% digit map, which is put into place after the offhook is detected (step%% 5 below).%%%%%% Note that the embedded EventsDescriptor could have been used to%% combine steps 3 and 4 with steps 8 and 9, eliminating steps 6 and 7.%%%%%% 4. The MG1 accepts the Modify with this reply:%%%% MG1 to MGC:%% MEGACO/1 [124.124.124.222]:55555%% Reply = 9999 {%%    Context = - {Modify = A4444}%% }%%----------------------------------------------------------------------msg4() ->    msg4(?MG1_MID).msg4(Mid) ->    msg4(Mid, ?A4444).msg4(Mid, Tid) ->    Reply = #'AmmsReply'{terminationID = [#megaco_term_id{id = Tid}]},    reply(Mid, 9999, ?megaco_null_context_id, [{modReply, Reply}]).%%----------------------------------------------------------------------%% 5. A similar exchange happens between MG2 and the MGC, resulting in an%%    idle Termination called A5555.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -