snmp_agent_test.erl

来自「OTP是开放电信平台的简称」· ERL 代码 · 共 2,194 行 · 第 1/5 页

ERL
2,194
字号
    MasterAgentVerbosity = {snmp_master_agent_verbosity,   trace},    MibsVerbosity        = {snmp_mibserver_verbosity,      trace},    SymStoreVerbosity    = {snmp_symbolic_store_verbosity, trace},    Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity],    [{vsn, v1}, {agent_opts,Opts} | Config].init_varm_mib_storage_mnesia(Config) when list(Config) ->    ?LOG("init_varm_mib_storage_mnesia -> entry", []),    ?line SaNode   = ?GCONF(snmp_sa, Config),    ?line create_tables(SaNode),    ?line AgentDir = ?GCONF(agent_dir, Config),    ?line MgrDir   = ?GCONF(mgr_dir, Config),    ?line Ip       = ?GCONF(ip, Config),    ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)),    MibStorage           = {snmp_mib_storage,{mnesia,[]}},    MasterAgentVerbosity = {snmp_master_agent_verbosity,   trace},    MibsVerbosity        = {snmp_mibserver_verbosity,      trace},    SymStoreVerbosity    = {snmp_symbolic_store_verbosity, trace},    Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity],    [{vsn, v1}, {agent_opts,Opts} | Config].finish_mib_storage_ets(Config) when list(Config) ->    ?LOG("finish_mib_storage_ets -> entry", []),    delete_tables(),    C1 = stop_agent(Config),    delete_files(C1),    C2 = lists:keydelete(vsn, 1, C1),    lists:keydelete(agent_opts, 1, C2).finish_mib_storage_dets(Config) when list(Config) ->    ?LOG("finish_mib_storage_dets -> entry", []),    delete_tables(),    C1 = stop_agent(Config),    delete_files(C1),    C2 = lists:keydelete(vsn, 1, C1),    lists:keydelete(agent_opts, 1, C2).finish_mib_storage_mnesia(Config) when list(Config) ->    ?LOG("finish_mib_storage_mnesia -> entry", []),    delete_tables(),    delete_mib_storage_mnesia_tables(),    C1 = stop_agent(Config),    delete_files(C1),    C2 = lists:keydelete(vsn, 1, C1),    lists:keydelete(agent_opts, 1, C2).finish_varm_mib_storage_dets(Config) when list(Config) ->    ?LOG("finish_varm_mib_storage_dets -> entry", []),    delete_tables(),    %% C1 = stop_agent(Config), % In case something went wrong...    delete_files(Config),    C2 = lists:keydelete(vsn, 1, Config),    lists:keydelete(agent_opts, 1, C2).finish_varm_mib_storage_mnesia(Config) when list(Config) ->    ?LOG("finish_varm_mib_storage_mnesia -> entry", []),    delete_tables(),    delete_mib_storage_mnesia_tables(),    %% C1 = stop_agent(Config), % In case something went wrong...    delete_files(Config),    C2 = lists:keydelete(vsn, 1, Config),    lists:keydelete(agent_opts, 1, C2).finish_size_check_mse(Config) when list(Config) ->    finish_size_check_ms(Config).finish_size_check_msd(Config) when list(Config) ->    finish_size_check_ms(Config).finish_size_check_msm(Config) when list(Config) ->    finish_size_check_ms(Config).finish_size_check_ms(Config) when list(Config) ->    delete_tables(),    C1 = stop_agent(Config),    delete_files(C1),    lists:keydelete(vsn, 1, C1).%% These are just interface functions to fool the test servermse_simple(X)         -> ?P(mse_simple), simple(X).mse_v1_processing(X)  -> ?P(mse_v1_processing), v1_processing(X).mse_big(X)            -> ?P(mse_big), big(X).mse_big2(X)           -> ?P(mse_big2), big2(X).mse_loop_mib(X)       -> ?P(mse_loop_mib), loop_mib(X).mse_api(X)            -> ?P(mse_api), api(X).mse_sa_register(X)    -> ?P(mse_sa_register), sa_register(X).mse_v1_trap(X)        -> ?P(mse_v1_trap), v1_trap(X).mse_sa_error(X)       -> ?P(mse_sa_error), sa_error(X).mse_next_across_sa(X) -> ?P(mse_next_across_sa), next_across_sa(X).mse_undo(X)           -> ?P(mse_undo), undo(X).mse_standard_mib(X)   -> ?P(mse_standard_mib), snmp_standard_mib(X).mse_community_mib(X)  -> ?P(mse_community_mib), snmp_community_mib(X).mse_framework_mib(X)  -> ?P(mse_framework_mib), snmp_framework_mib(X).mse_target_mib(X)       -> ?P(mse_target_mib), snmp_target_mib(X).mse_notification_mib(X) -> ?P(mse_notification_mib), snmp_notification_mib(X).mse_view_based_acm_mib(X) -> ?P(mse_view_based_acm_mib), snmp_view_based_acm_mib(X).mse_sparse_table(X)   -> ?P(mse_sparse_table), sparse_table(X).mse_me_of(X)          -> ?P(mse_me_of), ms_me_of(X).mse_mib_of(X)         -> ?P(mse_mib_of), ms_mib_of(X).msd_simple(X)         -> ?P(msd_simple), simple(X).msd_v1_processing(X)  -> ?P(msd_v1_processing), v1_processing(X).msd_big(X)            -> ?P(msd_big), big(X).msd_big2(X)           -> ?P(msd_big2), big2(X).msd_loop_mib(X)       -> ?P(msd_loop_mib), loop_mib(X).msd_api(X)            -> ?P(msd_api), api(X).msd_sa_register(X)    -> ?P(msd_sa_register), sa_register(X).msd_v1_trap(X)        -> ?P(msd_v1_trap), v1_trap(X).msd_sa_error(X)       -> ?P(msd_sa_error), sa_error(X).msd_next_across_sa(X) -> ?P(msd_next_across_sa), next_across_sa(X).msd_undo(X)           -> ?P(msd_undo), undo(X).msd_standard_mib(X)   -> ?P(msd_standard_mib), snmp_standard_mib(X).msd_community_mib(X)  -> ?P(msd_community_mib), snmp_community_mib(X).msd_framework_mib(X)  -> ?P(msd_framework_mib), snmp_framework_mib(X).msd_target_mib(X)       -> ?P(msd_target_mib), snmp_target_mib(X).msd_notification_mib(X) -> ?P(msd_notification_mib), snmp_notification_mib(X).msd_view_based_acm_mib(X) -> ?P(msd_view_based_acm_mib), snmp_view_based_acm_mib(X).msd_sparse_table(X)   -> ?P(msd_sparse_table), sparse_table(X).msd_me_of(X)          -> ?P(msd_me_of), ms_me_of(X).msd_mib_of(X)         -> ?P(msd_mib_of), ms_mib_of(X).msm_simple(X)         -> ?P(msm_simple), simple(X).msm_v1_processing(X)  -> ?P(msm_v1_processing), v1_processing(X).msm_big(X)            -> ?P(msm_big2), big(X).msm_big2(X)           -> ?P(msm_loop_mib), big2(X).msm_loop_mib(X)       -> ?P(msm_loop_mib), loop_mib(X).msm_api(X)            -> ?P(msm_api), api(X).msm_sa_register(X)    -> ?P(msm_sa_register), sa_register(X).msm_v1_trap(X)        -> ?P(msm_v1_trap), v1_trap(X).msm_sa_error(X)       -> ?P(msm_sa_error), sa_error(X).msm_next_across_sa(X) -> ?P(msm_next_across_sa), next_across_sa(X).msm_undo(X)           -> ?P(msm_undo), undo(X).msm_standard_mib(X)   -> ?P(msm_standard_mib), snmp_standard_mib(X).msm_community_mib(X)  -> ?P(msm_community_mib), snmp_community_mib(X).msm_framework_mib(X)  -> ?P(msm_framework_mib), snmp_framework_mib(X).msm_target_mib(X)       -> ?P(msm_target_mib), snmp_target_mib(X).msm_notification_mib(X) -> ?P(msm_notification_mib), snmp_notification_mib(X).msm_view_based_acm_mib(X) -> ?P(msm_view_based_acm_mib), snmp_view_based_acm_mib(X).msm_sparse_table(X)   -> ?P(msm_sparse_table), sparse_table(X).msm_me_of(X)          -> ?P(msm_me_of), ms_me_of(X).msm_mib_of(X)         -> ?P(msm_mib_of), ms_mib_of(X).mse_size_check(X)     -> ?P(mse_size_check), ms_size_check(X).msd_size_check(X)     -> ?P(msd_size_check), ms_size_check(X).msm_size_check(X)     -> ?P(msm_size_check), ms_size_check(X).msd_varm_mib_start(X) -> ?P(msd_varm_mib_start), varm_mib_start(X).msm_varm_mib_start(X) -> ?P(msm_varm_mib_start), varm_mib_start(X).ms_size_check(suite) -> [];ms_size_check(Config) when list(Config) ->    ?P(ms_size_check),    init_case(Config),    ?LOG("mib server size check...", []),    ?line load_master("Test2"),    ?line load_master("TestTrap"),    ?line load_master("TestTrapv2"),    ?line load_master_std("OTP-SNMPEA-MIB"),    ?line load_master_std("SNMP-COMMUNITY-MIB"),    ?line load_master_std("SNMP-FRAMEWORK-MIB"),    ?line load_master_std("SNMP-MPD-MIB"),    ?line load_master_std("SNMP-NOTIFICATION-MIB"),    ?line load_master_std("SNMP-TARGET-MIB"),    ?line load_master_std("SNMP-USER-BASED-SM-MIB"),    ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"),    ?line load_master_std("SNMPv2-MIB"),    ?line load_master_std("SNMPv2-TM"),    ?SLEEP(2000),    ?line display_memory_usage(),    ?line unload_master("OTP-SNMPEA-MIB"),    ?line unload_master("SNMP-COMMUNITY-MIB"),    ?line unload_master("SNMP-FRAMEWORK-MIB"),    ?line unload_master("SNMP-MPD-MIB"),    ?line unload_master("SNMP-NOTIFICATION-MIB"),    ?line unload_master("SNMP-TARGET-MIB"),    ?line unload_master("SNMP-USER-BASED-SM-MIB"),    ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"),    ?line unload_master("SNMPv2-MIB"),    ?line unload_master("SNMPv2-TM"),    ?line unload_master("TestTrapv2"),    ?line unload_master("TestTrap"),    ?line unload_master("Test2"),    ok.varm_mib_start(suite) -> [];varm_mib_start(Config) when list(Config) ->    ?P(varm_mib_start),    ?LOG("varm_mib_start -> entry", []),    init_case(Config),    %% Start the agent    Opts    = ?GCONF(agent_opts, Config),    Config1 = start_v1_agent(Config, Opts),    %% Sleep some in order for the agent to start properly    ?DBG("varm_mib_start -> sleep some (before loading mobs)", []),    ?SLEEP(5000),    %% Load all the mibs    HardwiredMibs = loaded_mibs(),    ?DBG("varm_mib_start -> load all mibs", []),    ?line load_master_std("SNMP-COMMUNITY-MIB"),    ?line load_master_std("SNMP-FRAMEWORK-MIB"),    ?line load_master_std("SNMP-TARGET-MIB"),    ?line load_master_std("SNMP-NOTIFICATION-MIB"),    %% Unload the hardwired mibs    ?DBG("varm_mib_start -> sleep some (before unloading hardwired mibs)", []),    ?SLEEP(1000),    ?DBG("varm_mib_start -> unload (hardwired) mibs", []),    ?line unload_mibs(HardwiredMibs),    %% unload hardwired    ?DBG("varm_mib_start -> sleep some (before stopping agent)", []),    ?SLEEP(1000),    %% Stop the agent (without deleting the stored files)    ?DBG("varm_mib_start -> stop the agent", []),    Config2 = stop_agent(Config1),    %% Sleep some in order for the agent to stop properly    ?DBG("varm_mib_start -> sleep some (before re-starting the agent)", []),    ?SLEEP(5000),    %% Start the agent (again)    ?DBG("varm_mib_start -> start the agent", []),    Config3 = start_v1_agent(Config2, Opts),    ?DBG("varm_mib_start -> sleep some (before starting tests)", []),    ?SLEEP(5000),    %% Perform the test(s)    ?DBG("varm_mib_start -> perform the tests", []),    try_test(snmp_community_mib),    try_test(snmp_framework_mib),    try_test(snmp_target_mib),    try_test(snmp_notification_mib),    %% Stop the agent (without deleting the stored files)    ?DBG("varm_mib_start -> stop the agent", []),    stop_agent(Config3),    ok.-define(snmpTrapCommunity_instance, [1,3,6,1,6,3,18,1,4,0]).-define(vacmViewSpinLock_instance, [1,3,6,1,6,3,16,1,5,1,0]).-define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]).ms_me_of(suite) -> [];ms_me_of(Config) when list(Config) ->    ?P(ms_me_of),    init_case(Config),    ?line load_master("Test2"),    ?line load_master("TestTrap"),    ?line load_master("TestTrapv2"),    ?line load_master_std("OTP-SNMPEA-MIB"),    ?line load_master_std("SNMP-COMMUNITY-MIB"),    ?line load_master_std("SNMP-FRAMEWORK-MIB"),    ?line load_master_std("SNMP-MPD-MIB"),    ?line load_master_std("SNMP-NOTIFICATION-MIB"),    ?line load_master_std("SNMP-TARGET-MIB"),    ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"),    ?SLEEP(2000),    ?line display_memory_usage(),    ?DBG("ms_me_of -> find ~w from SNMP-COMMUNITY-MIB",	[?snmpTrapCommunity_instance]),    ?line ok = me_of(?snmpTrapCommunity_instance),        ?DBG("ms_me_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB",         [?vacmViewSpinLock_instance]),    ?line ok = me_of(?vacmViewSpinLock_instance),        ?DBG("ms_me_of -> find ~w from SNMP-USER-BASED-SM-MIB",         [?usmStatsNotInTimeWindows_instance]),    ?line {error, _} = me_of(?usmStatsNotInTimeWindows_instance),        ?line unload_master("OTP-SNMPEA-MIB"),    ?line unload_master("SNMP-COMMUNITY-MIB"),    ?line unload_master("SNMP-FRAMEWORK-MIB"),    ?line unload_master("SNMP-MPD-MIB"),    ?line unload_master("SNMP-NOTIFICATION-MIB"),    ?line unload_master("SNMP-TARGET-MIB"),    ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"),    ?line unload_master("TestTrapv2"),    ?line unload_master("TestTrap"),    ?line unload_master("Test2"),    ok.me_of(Oid) ->    case snmpa:me_of(Oid) of	{ok, #me{oid = Oid}} ->            ok;	{ok, #me{oid = OtherOid}} ->            case lists:reverse(Oid) of                [0|Rest] ->                    case lists:reverse(Rest) of                        OtherOid ->                            ok;                        AnotherOid ->                            {error, {invalid_oid, Oid, AnotherOid}}                    end;                _ ->                    {error, {invalid_oid, Oid, OtherOid}}            end;	{error, Reason} ->	    {error, Reason};	Else ->	    {error, Else}    end.ms_mib_of(suite) -> [];ms_mib_of(Config) when list(Config) ->    ?P(ms_mib_of),    init_case(Config),    ?line load_master("Test2"),    ?line load_master("TestTrap"),    ?line load_master("TestTrapv2"),    ?line load_master_std("OTP-SNMPEA-MIB"),    ?line load_master_std("SNMP-COMMUNITY-MIB"),    ?line load_master_std("SNMP-FRAMEWORK-MIB"),    ?line load_master_std("SNMP-MPD-MIB"),    ?line load_master_std("SNMP-NOTIFICATION-MIB"),    ?line load_master_std("SNMP-TARGET-MIB"),    ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"),    ?SLEEP(2000),    ?line display_memory_usage(),    ?DBG("ms_mib_of -> find ~w from SNMP-COMMUNITY-MIB",	[?snmpTrapCommunity_instance]),    ?line ok = mib_of(?snmpTrapCommunity_instance, 'SNMP-COMMUNITY-MIB'),        ?DBG("ms_mib_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB",         [?vacmViewSpinLock_instance]),    ?line ok = mib_of(?vacmViewSpinLock_instance, 'SNMP-VIEW-BASED-ACM-MIB'),        ?DBG("ms_mib_of -> find ~w from SNMP-USER-BASED-SM-MIB",         [?usmStatsNotInTimeWindows_instance]),    ?line {error, _} = mib_of(?usmStatsNotInTimeWindows_instance,			      'SNMP-USER-BASED-SM-MIB'),        ?line unload_master("OTP-SNMPEA-MIB"),    ?line unload_master("SNMP-COMMUNITY-MIB"),    ?line unload_master("SNMP-FRAMEWORK-MIB"),    ?line unload_master("SNMP-MPD-MIB"),    ?line unload_master("SNMP-NOTIFICATION-MIB"),    ?line unload_master("SNMP-TARGET-MIB"),    ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"),    ?line unload_master("TestTrapv2"),    ?line unload_master("TestTrap"),    ?line unload_master("Test2"),    ok.mib_of(Oid, ExpectedMibName) ->    ?DBG("mib_of -> entry with"	 "~n   Oid:          ~p"	 "~n   ExpectedMibName: ~p", [Oid, ExpectedMibName]),    %% case snmpa:mib_of(Oid) of    MibOf = snmpa:mib_of(Oid),    ?DBG("mib_of -> MibOf: ~n~p", [MibOf]),    case MibOf of	{ok, ExpectedMibName} ->            ok;	{ok, OtherMibName} ->	    {error, {invalid_mib, ExpectedMibName, OtherMibName}};	{error, Reason} ->	    {error, Reason};	Else ->	    ?DBG("mib_of -> Else: ~n~p", [Else]),	    {error, Else}    end.misc(suite) ->    {req, [], {conf, init_misc, misc_cases(), finish_misc}}.init_misc(Config) ->    init_v1(Config).finish_misc(Config) ->    finish_v1(Config).misc_cases() ->    [     app_info,     info_test    ].app_info(suite) -> [];app_info(Config) when list(Config) ->    ?P(app_info),    SnmpDir   = app_dir(snmp),    SslDir    = app_dir(ssl),    CryptoDir = app_dir(crypto),    Attr = snmp:module_info(attributes),    AppVsn = 	case lists:keysearch(app_vsn, 1, Attr) of	    {value, {app_vsn, V}} ->		V;	    false ->		"undefined"	end,    io:format("Root dir: ~s~n"	      "SNMP:   Application dir: ~s~n"	      "        Application ver: ~s~n"	      "SSL:    Application dir: ~s~n"	      "CRYPTO: Application dir: ~s~n", 	      [code:root_dir(), SnmpDir, AppVsn, SslDir, CryptoDir]),    ok.app_dir(App) ->    case code:lib_dir(App) of	D when list(D) ->	    filename:basename(D);	{error, _Reason} ->	    "undefined"

⌨️ 快捷键说明

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