snmp_agent_test.erl
来自「OTP是开放电信平台的简称」· ERL 代码 · 共 2,194 行 · 第 1/5 页
ERL
2,194 行
?line unload_master("TestTrapv2"), ?P1("stop subagent..."), ?line stop_subagent(SA).v3_trap(X) -> ?P(v3_trap), v2_trap(X).v2_inform(suite) -> {req, [], {conf, init_v2_inform, [v2_inform_i], finish_v2_inform}}.v3_inform(_X) -> %% v2_inform(X). {req, [], {conf, init_v3_inform, [v3_inform_i], finish_v3_inform}}. init_v2_inform(Config) when list(Config) -> _Dir = ?config(agent_dir, Config), %% snmp_internal_mib:configure(Dir), Config.init_v3_inform(X) -> init_v2_inform(X).finish_v2_inform(Config) when list(Config) -> _Dir = ?config(agent_dir, Config), %% snmp_internal_mib:configure(Dir), Config.finish_v3_inform(X) -> finish_v2_inform(X).v2_inform_i(suite) -> [];v2_inform_i(Config) when list(Config) -> ?P(v2_inform_i), init_case(Config), MA = whereis(snmp_master_agent), ?P1("load TestTrap & TestTrapv2..."), ?line load_master("TestTrap"), ?line load_master("TestTrapv2"), ?P1("Testing inform sending from master agent... " "~nNOTE! This test takes a few minutes (5) to complete."), try_test(ma_v2_inform1, [MA]), ?P1("unload TestTrap & TestTrapv2..."), ?line unload_master("TestTrap"), ?line unload_master("TestTrapv2").v3_inform_i(X) -> ?P(v3_inform_i), v2_inform_i(X).sa_error(suite) -> [];sa_error(Config) when list(Config) -> ?P(sa_error), {SaNode, _MgrNode, _MibDir} = init_case(Config), ?P1("load OLD-SNMPEA-MIB..."), ?line load_master("OLD-SNMPEA-MIB"), ?line init_old(), ?P1("start subagent..."), ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), ?P1("Testing sa bad value (is_set_ok)..."), try_test(sa_errs_bad_value), ?P1("Testing sa gen err (set)..."), try_test(sa_errs_gen_err), ?P1("Testing too big..."), try_test(sa_too_big), ?P1("unload OLD-SNMPEA-MIB..."), ?line unload_master("OLD-SNMPEA-MIB"), ?P1("stop subagent..."), stop_subagent(SA).sa_error_2(X) -> ?P(sa_error_2), sa_error(X).sa_error_3(X) -> ?P(sa_error_3), sa_error(X).next_across_sa(suite) -> [];next_across_sa(Config) when list(Config) -> ?P(next_across_sa), {SaNode, _MgrNode, MibDir} = init_case(Config), MA = whereis(snmp_master_agent), ?P1("start subagent (1)..."), ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), ?P1("Loading another subagent mib (Klas1)..."), ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas1"]), ?P1("register subagent..."), rpc:call(SaNode, snmp, register_subagent, [MA, ?klas1, SA]), ?P1("Load test subagent..."), try_test(load_test_sa), ?P1("Testing next across subagent (endOfMibView from SA)..."), try_test(next_across_sa), ?P1("Unloading mib (Klas1)"), snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), try_test(unreg_test), ?P1("Starting another subagent (2) "), ?line {ok, SA2} = start_subagent(SaNode, ?klas1, "Klas1"), ?P1("Testing next across subagent (wrong prefix from SA)..."), try_test(next_across_sa), ?P1("stop subagent (1)..."), stop_subagent(SA), ?P1("stop subagent (2)..."), stop_subagent(SA2).next_across_sa_2(X) -> ?P(next_across_sa_2), next_across_sa(X).next_across_sa_3(X) -> ?P(next_across_sa_3), next_across_sa(X).undo(suite) -> [];undo(Config) when list(Config) -> ?P(undo), {SaNode, _MgrNode, MibDir} = init_case(Config), MA = whereis(snmp_master_agent), ?P1("start subagent (1)..."), ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), ?P1("Load Klas3 & Klas4..."), ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas3"]), ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas4"]), ?P1("Testing undo phase at master agent..."), try_test(undo_test), try_test(api_test2), ?P1("Unload Klas3..."), ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas3"]), ?P1("Testing bad return values from instrum. funcs..."), try_test(bad_return), ?P1("Unload Klas4..."), ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas4"]), ?P1("Testing undo phase at subagent..."), ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas3"]), ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas4"]), ?line ok = snmpa:register_subagent(MA, ?klas3, SA), ?line ok = snmpa:register_subagent(MA, ?klas4, SA), try_test(undo_test), try_test(api_test3), ?P1("Testing undo phase across master/subagents..."), try_test(undo_test), try_test(api_test3), ?P1("stop subagent..."), stop_subagent(SA).undo_2(X) -> ?P(undo_2), undo(X).undo_3(X) -> ?P(undo_3), undo(X).%% Req. Test2v1_processing(suite) -> [];v1_processing(Config) when list(Config) -> ?P(v1_processing), ?DBG("v1_processing -> entry", []), init_case(Config), ?P1("Load Test2..."), ?line load_master("Test2"), try_test(v1_proc), ?P1("Unload Test2..."), ?line unload_master("Test2").%% Req. Test2v2_processing(suite) -> [];v2_processing(Config) when list(Config) -> ?P(v2_processing), init_case(Config), ?P1("Load Test2..."), ?line load_master("Test2"), try_test(v2_proc), ?P1("Unload Test2..."), ?line unload_master("Test2").%% Req. Test2v3_processing(suite) -> [];v3_processing(Config) when list(Config) -> ?P(v3_processing), init_case(Config), ?P1("Load Test2..."), ?line load_master("Test2"), try_test(v2_proc), % same as v2! ?P1("Unload Test2..."), ?line unload_master("Test2").%% We'll try get/set/trap and inform for all the auth & priv protocols.%% For informs, the mgr is auth-engine. The agent has to sync. This is%% accomplished by the first inform sent. That one will generate a%% report, which makes it in sync. The notification-generating%% application times out, and send again. This time it'll work.v3_security(suite) -> [ v3_crypto_basic, v3_md5_auth, v3_sha_auth, v3_des_priv ].v3_crypto_basic(suite) -> [];v3_crypto_basic(_Config) -> ?P(v3_crypto_basic), EID = [0,0,0,0,0,0,0,0,0,0,0,2], %% From rfc2274 appendix A.3.1 ?line KMd5_1 = snmp:passwd2localized_key(md5, "maplesyrup", EID), ?line [16#52,16#6f,16#5e,16#ed,16#9f,16#cc,16#e2,16#6f, 16#89,16#64,16#c2,16#93,16#07,16#87,16#d8,16#2b] = KMd5_1, %% From rfc2274 appendix A.3.2 ?line KSHA_1 = snmp:passwd2localized_key(sha, "maplesyrup", EID), ?line [16#66,16#95,16#fe,16#bc,16#92,16#88,16#e3,16#62,16#82,16#23, 16#5f,16#c7,16#15,16#1f,16#12,16#84,16#97,16#b3,16#8f,16#3f] = KSHA_1, %% From rfc2274, appendix A.5.1 ?line KMd5_2 = snmp:passwd2localized_key(md5, "newsyrup", EID), ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, 16#88,16#05,16#61,16#51,16#41,16#67,16#6c,16#c9, 16#19,16#61,16#74,16#e7,16#42,16#a3,16#25,16#51] = snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2, 16, [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), %% From rfc2274, appendix A.5.2 ?line KSHA_2 = snmp:passwd2localized_key(sha, "newsyrup", EID), ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, 16#00,16#00,16#00,16#00,16#9c,16#10,16#17,16#f4, 16#fd,16#48,16#3d,16#2d,16#e8,16#d5,16#fa,16#db, 16#f8,16#43,16#92,16#cb,16#06,16#45,16#70,16#51] = snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2, 20, [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), KSHA_1t = lists:sublist(KSHA_1, 16), KSHA_2t = lists:sublist(KSHA_2, 16), ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, 16#7e,16#f8,16#d8,16#a4,16#c9,16#cd,16#b2,16#6b, 16#47,16#59,16#1c,16#d8,16#52,16#ff,16#88,16#b5] = snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1t, KSHA_2t, 16, [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), %% Try with correct random ?line Kc1 = snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2), ?line KMd5_2 = snmp_user_based_sm_mib:extract_new_key(md5, KMd5_1, Kc1), ?line Kc2 = snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2), ?line KSHA_2 = snmp_user_based_sm_mib:extract_new_key(sha, KSHA_1, Kc2), ok. v3_md5_auth(suite) -> [];v3_md5_auth(Config) when list(Config) -> ?P(v3_md5_auth), init_case(Config), ?P1("Testing MD5 authentication...takes a few seconds..."), AgentDir = ?config(agent_dir, Config), ?line rewrite_target_params_conf(AgentDir, "authMD5", authNoPriv), ?line snmp_target_mib:reconfigure(AgentDir), MA = whereis(snmp_master_agent), ?line load_master("Test2"), ?line load_master("TestTrap"), ?line load_master("TestTrapv2"), try_test(v3_sync, [[{v2_proc, []}, {ma_v2_trap1, [MA]}, {v3_inform_sync, [MA]}]], [{sec_level, authNoPriv}, {user, "authMD5"}]), ?line unload_master("TestTrapv2"), ?line unload_master("TestTrap"), ?line unload_master("Test2"), ?line reset_target_params_conf(AgentDir).v3_sha_auth(suite) -> [];v3_sha_auth(Config) when list(Config) -> ?P(v3_sha_auth), init_case(Config), ?P1("Testing SHA authentication...takes a few seconds..."), AgentDir = ?config(agent_dir, Config), ?line rewrite_target_params_conf(AgentDir, "authSHA", authNoPriv), ?line snmp_target_mib:reconfigure(AgentDir), MA = whereis(snmp_master_agent), ?line load_master("Test2"), ?line load_master("TestTrap"), ?line load_master("TestTrapv2"), try_test(v3_sync, [[{v2_proc, []}, {ma_v2_trap1, [MA]}, {v3_inform_sync, [MA]}]], [{sec_level, authNoPriv}, {user, "authSHA"}]), ?line unload_master("TestTrapv2"), ?line unload_master("TestTrap"), ?line unload_master("Test2"), ?line reset_target_params_conf(AgentDir).v3_des_priv(suite) -> [];v3_des_priv(Config) when list(Config) -> ?P(v3_des_priv), init_case(Config), ?P1("Testing DES encryption...takes a few seconds..."), AgentDir = ?config(agent_dir, Config), ?line rewrite_target_params_conf(AgentDir, "privDES", authPriv), ?line snmp_target_mib:reconfigure(AgentDir), MA = whereis(snmp_master_agent), ?line load_master("Test2"), ?line load_master("TestTrap"), ?line load_master("TestTrapv2"), try_test(v3_sync, [[{v2_proc, []}, {ma_v2_trap1, [MA]}, {v3_inform_sync, [MA]}]], [{sec_level, authPriv}, {user, "privDES"}]), ?line unload_master("TestTrapv2"), ?line unload_master("TestTrap"), ?line unload_master("Test2"), ?line reset_target_params_conf(AgentDir).%% -define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]).%% Make sure mgr is in sync with agentv3_sync(Funcs) -> ?DBG("v3_sync -> entry with Funcs: ~p",[Funcs]), g([[sysDescr, 0]]), expect(432, report, [{?usmStatsNotInTimeWindows_instance, any}]), g([[sysDescr, 0]]), expect(433, [{[sysDescr,0], any}]), lists:foreach(fun({Func, Args}) -> apply(?MODULE, Func, Args) end, Funcs).v3_inform_sync(MA) -> ?DBG("v3_sync -> entry with MA: ~p => Send notification",[MA]), ?line snmpa:send_notification(MA, testTrapv22, no_receiver, "standard inform", []), %% Make sure agent is in sync with mgr... ?DBG("v3_sync -> wait some time: ",[]), ?SLEEP(20000), % more than 1500*10 in target_addr.conf ?DBG("v3_sync -> await response",[]), ?line expect(1, {inform, true}, [{[sysUpTime, 0], any}, {[snmpTrapOID, 0], ?system ++ [0,1]}]).v2_caps(suite) -> [];v2_caps(Config) when list(Config) -> ?P(v2_caps), init_case(Config), try_test(v2_caps_i, [node()]).v2_caps_3(X) -> ?P(v2_caps_3), v2_caps(X).v2_caps_i(Node) -> ?line Idx = rpc:call(Node, snmp, add_agent_caps, [[1,2,3,4,5], "test cap"]), g([[sysORID, Idx], [sysORDescr, Idx]]), ?line expect(1, [{[sysORID, Idx], [1,2,3,4,5]}, {[sysORDescr, Idx], "test cap"}]), ?line rpc:call(Node, snmp, del_agent_caps, [Idx]), g([[sysORID, Idx]]), ?line expect(2, [{[sysORID, Idx], noSuchInstance}]). %% Req. Test2v1_proc() -> ?DBG("v1_proc -> entry", []), %% According to RFC1157. %% Template: <Section>:<list no> v1_get_p(), v1_get_next_p(), v1_set_p(). v1_get_p() -> %% 4.1.2:1 g([[test2]]), ?line expect(10, noSuchName, 1, [{[test2], 'NULL'}]), g([[tDescr]]), ?line expect(11, noSuchName, 1, [{[tDescr], 'NULL'}]), g([[tDescr2,0]]), ?line expect(12, noSuchName, 1, [{[tDescr2,0], 'NULL'}]), g([[tDescr3,0]]), ?line expect(131, noSuchName, 1, [{[tDescr3,0], 'NULL'}]), g([[tDescr4,0]]), ?line expect(132, noSuchName, 1, [{[tDescr4,0], 'NULL'}]), g([[sysDescr, 0], [tDescr,0]]), % Outside mibview ?line expect(14, noSuchName, 2, [{[sysDescr, 0], 'NULL'}, {[tDescr,0], 'NULL'}]), g([[sysDescr,3]]), ?line expect(15, noSuchName, 1, [{[sysDescr, 3], 'NULL'}]), %% 4.1.2:2 g([
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?