📄 megaco_mib_test.erl
字号:
%% ``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: Verify the application specifics of the Megaco application%%-----------------------------------------------------------------------module(megaco_mib_test).-compile(export_all).-include("megaco_test_lib.hrl").-include_lib("megaco/include/megaco.hrl").-include_lib("megaco/include/megaco_message_v1.hrl").-define(TEST_VERBOSITY, info). % silence | info | debug-define(MGC_VERBOSITY, info).-define(MG_VERBOSITY, info).-define(LOAD_COUNTER_START, 100).-define(A4444, ["11111111", "00000000", "00000000"]).-record(mgc, {parent = undefined, tcp_sup = undefined, udp_sup = undefined, mid = undefined, mg = []}).-record(mg, {parent = undefined, mid = undefined, conn_handle = undefined, state = initiated, load_counter = 0}).t() -> megaco_test_lib:t(?MODULE).t(Case) -> megaco_test_lib:t({?MODULE, Case}).%% Test server callbacksinit_per_testcase(Case, Config) -> process_flag(trap_exit, true), case Case of traffic -> Conf0 = lists:keydelete(tc_timeout, 1, Config), Conf = [{tc_timeout, timer:minutes(5)}|Conf0], megaco_test_lib:init_per_testcase(Case, Conf); _ -> megaco_test_lib:init_per_testcase(Case, Config) end.fin_per_testcase(Case, Config) -> process_flag(trap_exit, false), megaco_test_lib:fin_per_testcase(Case, Config).%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%all(suite) -> Cases = [ connect, traffic ], Cases.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%connect(suite) -> [];connect(doc) -> [];connect(Config) when list(Config) -> put(verbosity, ?TEST_VERBOSITY), put(sname, "TEST"), i("connect -> starting"), MgcNode = make_node_name(mgc), Mg1Node = make_node_name(mg1), Mg2Node = make_node_name(mg2), d("connect -> Nodes: " "~n MgcNode: ~p" "~n Mg1Node: ~p" "~n Mg2Node: ~p", [MgcNode, Mg1Node, Mg2Node]), ok = megaco_test_lib:start_nodes([MgcNode, Mg1Node, Mg2Node], ?FILE, ?LINE), %% Start the MGC and MGs ET = [{text,tcp}, {text,udp}, {binary,tcp}, {binary,udp}], {ok, Mgc} = start_mgc(MgcNode, {deviceName, "ctrl"}, ET, ?MGC_VERBOSITY), {ok, Mg1} = start_mg(Mg1Node, {deviceName, "mg1"}, text, tcp, ?MG_VERBOSITY), {ok, Mg2} = start_mg(Mg2Node, {deviceName, "mg2"}, binary, udp, ?MG_VERBOSITY), %% Collect the initial statistics (should be zero if anything) {ok, Mg1Stats0} = get_stats(Mg1, 1), d("connect -> stats for Mg1: ~n~p", [Mg1Stats0]), {ok, Mg2Stats0} = get_stats(Mg2, 1), d("connect -> stats for Mg2: ~n~p", [Mg2Stats0]), {ok, MgcStats0} = get_stats(Mgc, 1), d("connect -> stats for Mgc: ~n~p", [MgcStats0]), %% Ask Mg1 to do a service change {ok, Res1} = service_change(Mg1), d("connect -> (Mg1) service change result: ~p", [Res1]), %% Collect the statistics {ok, Mg1Stats1} = get_stats(Mg1, 1), d("connect -> stats for Mg1: ~n~p", [Mg1Stats1]), {ok, MgcStats1} = get_stats(Mgc, 1), d("connect -> stats (1) for Mgc: ~n~p", [MgcStats1]), {ok, MgcStats2} = get_stats(Mgc, 2), d("connect -> stats (2) for Mgc: ~n~p", [MgcStats2]), %% Ask Mg2 to do a service change {ok, Res2} = service_change(Mg2), d("connect -> (Mg2) service change result: ~p", [Res2]), %% Collect the statistics {ok, Mg2Stats1} = get_stats(Mg2, 1), d("connect -> stats for Mg1: ~n~p", [Mg2Stats1]), {ok, MgcStats3} = get_stats(Mgc, 1), d("connect -> stats (1) for Mgc: ~n~p", [MgcStats3]), {ok, MgcStats4} = get_stats(Mgc, 2), d("connect -> stats (2) for Mgc: ~n~p", [MgcStats4]), %% Tell Mg1 to stop stop(Mg1), %% Collect the statistics {ok, MgcStats5} = get_stats(Mgc, 1), d("connect -> stats (1) for Mgc: ~n~p", [MgcStats5]), {ok, MgcStats6} = get_stats(Mgc, 2), d("connect -> stats (2) for Mgc: ~n~p", [MgcStats6]), %% Tell Mg2 to stop stop(Mg2), %% Collect the statistics {ok, MgcStats7} = get_stats(Mgc, 1), d("connect -> stats (1) for Mgc: ~n~p", [MgcStats7]), {ok, MgcStats8} = get_stats(Mgc, 2), d("connect -> stats (2) for Mgc: ~n~p", [MgcStats8]), %% Tell Mgc to stop stop(Mgc), i("connect -> done", []), ok.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%traffic(suite) -> [];traffic(doc) -> [];traffic(Config) when list(Config) -> put(verbosity, ?TEST_VERBOSITY), put(sname, "TEST"), i("traffic -> starting"), MgcNode = make_node_name(mgc), Mg1Node = make_node_name(mg1), Mg2Node = make_node_name(mg2), Mg3Node = make_node_name(mg3), Mg4Node = make_node_name(mg4), d("traffic -> Nodes: " "~n MgcNode: ~p" "~n Mg1Node: ~p" "~n Mg2Node: ~p" "~n Mg3Node: ~p" "~n Mg4Node: ~p", [MgcNode, Mg1Node, Mg2Node, Mg3Node, Mg4Node]), ok = megaco_test_lib:start_nodes([MgcNode, Mg1Node, Mg2Node, Mg3Node, Mg4Node], ?FILE, ?LINE), %% Start the MGC and MGs i("traffic -> start the MGC"), ET = [{text,tcp}, {text,udp}, {binary,tcp}, {binary,udp}], {ok, Mgc} = start_mgc(MgcNode, {deviceName, "ctrl"}, ET, ?MGC_VERBOSITY), i("traffic -> start and connect the MGs"), MgConf0 = [{Mg1Node, "mg1", text, tcp}, {Mg2Node, "mg2", text, udp}, {Mg3Node, "mg3", binary, tcp}, {Mg4Node, "mg4", binary, udp}], MgConf = traffic_connect_mg(MgConf0, []), %% Collect and check the MGs statistics i("traffic -> collect and check the MGs stats"), traffic_verify_mg_stats(MgConf, 1, 1), %% Collect and check the MGC statistics i("traffic -> collect and check the MGC stats"), {ok, MgcStats1} = get_stats(Mgc, 1), d("traffic -> stats (1) for Mgc: ~n~p~n", [MgcStats1]), traffic_verify_mgc_stats(Mgc, 1, 1), sleep(1000), %% And apply some load i("traffic -> apply traffic load"), ok = traffic_apply_load(MgConf), %% Await completion of load part and the collect traffic i("traffic -> await load competion"), ok = traffic_await_load_complete(MgConf), sleep(1000), i("traffic -> collect and check the MGs statistics"), traffic_verify_mg_stats(MgConf, 1 + ?LOAD_COUNTER_START, 1 + ?LOAD_COUNTER_START), i("traffic -> collect and check the MGC statistics"), {ok, MgcStats3} = get_stats(Mgc, 1), d("traffic -> stats (1) for Mgc: ~n~p~n", [MgcStats3]), traffic_verify_mgc_stats(Mgc, 1 + ?LOAD_COUNTER_START, 1 + ?LOAD_COUNTER_START), sleep(1000), %% Reset counters i("traffic -> reset the MGs statistics"), traffic_reset_mg_stats(MgConf), i("traffic -> collect and check the MGs statistics"), traffic_verify_mg_stats(MgConf, 0, 0), i("traffic -> reset the MGC statistics"), traffic_reset_mgc_stats(Mgc), i("traffic -> collect and check the MGC statistics"), traffic_verify_mgc_stats(Mgc, 0, 0), sleep(1000), %% And apply some load i("traffic -> apply traffic load"), ok = traffic_apply_load(MgConf), %% Await completion of load part and the collect traffic i("traffic -> await load competion"), ok = traffic_await_load_complete(MgConf), sleep(1000), i("traffic -> collect and check the MGs statistics"), traffic_verify_mg_stats(MgConf, ?LOAD_COUNTER_START, ?LOAD_COUNTER_START), i("traffic -> collect and check the MGC statistics"), traffic_verify_mgc_stats(Mgc, ?LOAD_COUNTER_START, ?LOAD_COUNTER_START), sleep(1000), %% Tell MGs to stop i("traffic -> stop the MGs"), traffic_stop_mg(MgConf), sleep(1000), %% Collect the statistics i("traffic -> collect the MGC statistics"), {ok, MgcStats7} = get_stats(Mgc, 1), d("traffic -> stats (1) for Mgc: ~n~p~n", [MgcStats7]), {ok, MgcStats8} = get_stats(Mgc, 2), d("traffic -> stats (2) for Mgc: ~n~p~n", [MgcStats8]), %% Tell Mgc to stop i("traffic -> stop the MGC"), stop(Mgc), i("traffic -> done", []), ok.traffic_verify_mgc_stats(Pid, Out, In) when pid(Pid), integer(Out), integer(In) -> d("traffic_verify_mgc_stats -> entry with" "~n Out: ~p" "~n In: ~p", [Out, In]), {ok, Stats} = get_stats(Pid, 2), d("traffic_verify_mgc_stats -> stats (2) for Mgc: ~n~p~n", [Stats]), traffic_verify_mgc_stats(Stats, Out, In); traffic_verify_mgc_stats(Stats, Out, In) when list(Stats) -> d("traffic_verify_mgc_stats -> checking stats"), Gen = traffic_verify_get_stats(gen, Stats), Trans = traffic_verify_get_stats(trans, Stats), traffic_verify_mgc_stats_gen(Gen), traffic_verify_mgc_stats_trans(Trans, Out, In).traffic_verify_mgc_stats_gen([]) -> d("traffic_verify_mgc_stats_gen -> done"), ok;traffic_verify_mgc_stats_gen([{medGwyGatewayNumErrors, 0}|Stats]) -> traffic_verify_mgc_stats_gen(Stats);traffic_verify_mgc_stats_gen([{medGwyGatewayNumErrors, Val}|_]) -> exit({global_error_counter, Val, mgc});traffic_verify_mgc_stats_gen([{Handle, Counters}|Stats]) -> N = {mgc, Handle, Handle}, traffic_verify_counter(N, medGwyGatewayNumErrors, Counters, 0), traffic_verify_mgc_stats_gen(Stats).traffic_verify_mgc_stats_trans([], _Out, _In) -> ok;traffic_verify_mgc_stats_trans([{Mod, Stats}|MgcStats], Out, In) -> d("traffic_verify_mgc_stats_trans -> entry with" "~n Mod: ~p" "~n Stats: ~p", [Mod, Stats]), traffic_verify_mgc_stats_trans(Mod, Stats, Out, In), traffic_verify_mgc_stats_trans(MgcStats, Out, In).traffic_verify_mgc_stats_trans(_Mod, [], _Out, _In) -> ok;traffic_verify_mgc_stats_trans(Mod, [{Handle,Counters}|Stats], Out, In) -> N = {mgc, Mod, Handle}, traffic_verify_counter(N, medGwyGatewayNumErrors, Counters, 0), traffic_verify_counter(N, medGwyGatewayNumOutMessages, Counters, Out), traffic_verify_counter(N, medGwyGatewayNumInMessages, Counters, In), traffic_verify_mgc_stats_trans(Mod, Stats, Out, In). traffic_verify_mg_stats(MgConf, Out, In) when integer(Out), integer(In) -> d("traffic_verify_mg_stats -> entry with" "~n Out: ~p" "~n In: ~p", [Out, In]), Stats = traffic_get_mg_stats(MgConf, []), d("traffic_verify_mg_stats -> stats for MGs: ~n~p", [Stats]), traffic_verify_mg_stats1(Stats, Out, In). traffic_verify_mg_stats1([], _, _) -> ok;traffic_verify_mg_stats1([{Name, Stats}|MgStats], Out, In) -> d("traffic_verify_mg_stats1 -> entry with" "~n Name: ~s" "~n Stats: ~p", [Name, Stats]),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -