1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 2005-2016. All Rights Reserved. 5%% 6%% Licensed under the Apache License, Version 2.0 (the "License"); 7%% you may not use this file except in compliance with the License. 8%% You may obtain a copy of the License at 9%% 10%% http://www.apache.org/licenses/LICENSE-2.0 11%% 12%% Unless required by applicable law or agreed to in writing, software 13%% distributed under the License is distributed on an "AS IS" BASIS, 14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15%% See the License for the specific language governing permissions and 16%% limitations under the License. 17%% 18%% %CopyrightEnd% 19%% 20 21-module(snmp_agent_ms_test). 22 23%% TODO 24%% * Test fault-tolerance (kill master etc) 25%% 26 27-compile(export_all). 28 29-define(application, snmp). 30 31-include_lib("kernel/include/file.hrl"). 32-include_lib("common_test/include/ct.hrl"). 33-include("snmp_test_lib.hrl"). 34-define(SNMP_USE_V3, true). 35-include_lib("snmp/include/snmp_types.hrl"). 36%% -include_lib("snmp/include/SNMP-COMMUNITY-MIB.hrl"). 37%% -include_lib("snmp/include/SNMP-VIEW-BASED-ACM-MIB.hrl"). 38%% -include_lib("snmp/include/SNMP-USER-BASED-SM-MIB.hrl"). 39 40 41-define(klas1, [1,3,6,1,2,1,7]). 42-define(klas2, [1,3,6,1,2,1,9]). 43-define(klas3, [1,3,6,1,2,1,8,1]). 44-define(klas4, [1,3,6,1,2,1,8,4]). 45-define(sa, [1,3,6,1,4,1,193,2]). 46-define(system, [1,3,6,1,2,1,1]). 47-define(snmp, [1,3,6,1,2,1,11]). 48-define(snmpTraps, [1,3,6,1,6,3,1,1,5]). 49-define(ericsson, [1,3,6,1,4,1,193]). 50-define(testTrap, [1,3,6,1,2,1,15,0]). 51-define(xDescr, [1,3,6,1,2,1,17,1]). 52-define(xDescr2, [1,3,6,1,2,1,17,2]). 53 54-define(active, 1). 55-define(notInService, 2). 56-define(notReady, 3). 57-define(createAndGo, 4). 58-define(createAndWait, 5). 59-define(destroy, 6). 60 61-define(TRAP_UDP, 5000). 62 63-define(tooBigStr, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"). 64 65-define(str(X), snmp_pdus:bits_to_str(X)). 66 67-define(break(), begin io:format(user, "break at line ~w: pid: ~p\n", 68 [?LINE, self()]), 69 receive cont -> ok end 70 end). 71 72 73-import(snmp_test_mgr, [gn/1, g/1, s/1, gb/3]). 74-define(v1_2(V1,V2), 75 case get(vsn) of 76 v1 -> V1; 77 _ -> V2 78 end). 79 80-define(v1_2_3(V1,V2,V3), 81 case get(vsn) of 82 v1 -> V1; 83 v2 -> V2; 84 _ -> V3 85 end). 86 87all() -> 88[cases()]. 89 90groups() -> 91 [{mib_storage, [], 92 [{group, mib_storage_ets}, {group, mib_storage_dets}, 93 {group, mib_storage_mnesia}, 94 {group, mib_storage_size_check_ets}, 95 {group, mib_storage_size_check_dets}, 96 {group, mib_storage_size_check_mnesia}, 97 {group, mib_storage_varm_dets}, 98 {group, mib_storage_varm_mnesia}]}, 99 {mib_storage_ets, [], mib_storage_ets_cases()}, 100 {mib_storage_dets, [], mib_storage_dets_cases()}, 101 {mib_storage_mnesia, [], mib_storage_mnesia_cases()}, 102 {mib_storage_size_check_ets, [], 103 mse_size_check_cases()}, 104 {mib_storage_size_check_dets, [], 105 msd_size_check_cases()}, 106 {mib_storage_size_check_mnesia, [], 107 msm_size_check_cases()}, 108 {mib_storage_varm_dets, [], 109 varm_mib_storage_dets_cases()}, 110 {mib_storage_varm_mnesia, [], 111 varm_mib_storage_mnesia_cases()}, 112 {test_v1, [], v1_cases()}, {test_v2, [], v2_cases()}, 113 {test_v1_v2, [], v1_v2_cases()}, 114 {test_v3, [], v3_cases()}, 115 {test_multi_threaded, [], mt_cases()}, 116 {multiple_reqs, [], mul_cases()}, 117 {multiple_reqs_2, [], mul_cases_2()}, 118 {v2_inform, [], [v2_inform_i]}, 119 {v3_security, [], 120 [v3_crypto_basic, v3_md5_auth, v3_sha_auth, 121 v3_des_priv]}, 122 {standard_mibs, [], 123 [snmp_standard_mib, snmp_community_mib, 124 snmp_framework_mib, snmp_target_mib, 125 snmp_notification_mib, snmp_view_based_acm_mib]}, 126 {standard_mibs_2, [], 127 [snmpv2_mib_2, snmp_community_mib_2, 128 snmp_framework_mib_2, snmp_target_mib_2, 129 snmp_notification_mib_2, snmp_view_based_acm_mib_2]}, 130 {standard_mibs_3, [], 131 [snmpv2_mib_3, snmp_framework_mib_3, snmp_mpd_mib_3, 132 snmp_target_mib_3, snmp_notification_mib_3, 133 snmp_view_based_acm_mib_3, snmp_user_based_sm_mib_3]}, 134 {reported_bugs, [], 135 [otp_1128, otp_1129, otp_1131, otp_1162, otp_1222, 136 otp_1298, otp_1331, otp_1338, otp_1342, otp_2776, 137 otp_2979, otp_3187, otp_3725]}, 138 {reported_bugs_2, [], 139 [otp_1128_2, otp_1129_2, otp_1131_2, otp_1162_2, 140 otp_1222_2, otp_1298_2, otp_1331_2, otp_1338_2, 141 otp_1342_2, otp_2776_2, otp_2979_2, otp_3187_2]}, 142 {reported_bugs_3, [], 143 [otp_1128_3, otp_1129_3, otp_1131_3, otp_1162_3, 144 otp_1222_3, otp_1298_3, otp_1331_3, otp_1338_3, 145 otp_1342_3, otp_2776_3, otp_2979_3, otp_3187_3, 146 otp_3542]}, 147 {tickets, [], [{group, otp_4394}]}, 148 {otp_4394, [], [otp_4394_test]}]. 149 150init_per_group(otp_4394, Config) -> 151 init_otp_4394(Config); 152init_per_group(v2_inform, Config) -> 153 init_v2_inform(Config); 154init_per_group(multiple_reqs_2, Config) -> 155 init_mul(Config); 156init_per_group(multiple_reqs, Config) -> 157 init_mul(Config); 158init_per_group(test_multi_threaded, Config) -> 159 init_mt(Config); 160init_per_group(test_v3, Config) -> 161 init_v3(Config); 162init_per_group(test_v1_v2, Config) -> 163 init_v1_v2(Config); 164init_per_group(test_v2, Config) -> 165 init_v2(Config); 166init_per_group(test_v1, Config) -> 167 init_v1(Config); 168init_per_group(mib_storage_varm_mnesia, Config) -> 169 init_varm_mib_storage_mnesia(Config); 170init_per_group(mib_storage_varm_dets, Config) -> 171 init_varm_mib_storage_dets(Config); 172init_per_group(mib_storage_size_check_mnesia, Config) -> 173 init_size_check_msm(Config); 174init_per_group(mib_storage_size_check_dets, Config) -> 175 init_size_check_msd(Config); 176init_per_group(mib_storage_size_check_ets, Config) -> 177 init_size_check_mse(Config); 178init_per_group(mib_storage_mnesia, Config) -> 179 init_mib_storage_mnesia(Config); 180init_per_group(mib_storage_dets, Config) -> 181 init_mib_storage_dets(Config); 182init_per_group(mib_storage_ets, Config) -> 183 init_mib_storage_ets(Config); 184init_per_group(_GroupName, Config) -> 185 Config. 186 187end_per_group(otp_4394, Config) -> 188 finish_otp_4394(Config); 189end_per_group(v2_inform, Config) -> 190 finish_v2_inform(Config); 191end_per_group(multiple_reqs_2, Config) -> 192 finish_mul(Config); 193end_per_group(multiple_reqs, Config) -> 194 finish_mul(Config); 195end_per_group(test_multi_threaded, Config) -> 196 finish_mt(Config); 197end_per_group(test_v3, Config) -> 198 finish_v3(Config); 199end_per_group(test_v1_v2, Config) -> 200 finish_v1_v2(Config); 201end_per_group(test_v2, Config) -> 202 finish_v2(Config); 203end_per_group(test_v1, Config) -> 204 finish_v1(Config); 205end_per_group(mib_storage_varm_mnesia, Config) -> 206 finish_varm_mib_storage_mnesia(Config); 207end_per_group(mib_storage_varm_dets, Config) -> 208 finish_varm_mib_storage_dets(Config); 209end_per_group(mib_storage_size_check_mnesia, Config) -> 210 finish_size_check_msm(Config); 211end_per_group(mib_storage_size_check_dets, Config) -> 212 finish_size_check_msd(Config); 213end_per_group(mib_storage_size_check_ets, Config) -> 214 finish_size_check_mse(Config); 215end_per_group(mib_storage_mnesia, Config) -> 216 finish_mib_storage_mnesia(Config); 217end_per_group(mib_storage_dets, Config) -> 218 finish_mib_storage_dets(Config); 219end_per_group(mib_storage_ets, Config) -> 220 finish_mib_storage_ets(Config); 221end_per_group(_GroupName, Config) -> 222 Config. 223 224 225init_per_testcase(_Case, Config) when list(Config) -> 226 Dog = ?t:timetrap(?t:minutes(6)), 227 [{watchdog, Dog}|Config]. 228 229end_per_testcase(_Case, Config) when list(Config) -> 230 Dog = ?config(watchdog, Config), 231 ?t:timetrap_cancel(Dog), 232 Config. 233 234cases() -> 235 [ 236 app_info, 237 {group, test_v1}, {group, test_v2}, 238 {group, test_v1_v2}, {group, test_v3}, 239 {group, test_multi_threaded}, {group, mib_storage}, 240 {group, tickets} 241 ]. 242 243 244%%%----------------------------------------------------------------- 245%%% The test case structure is as follows: 246%%% 247%%% init_all - starts mnesia, 248%%% 249%%% init_v1 - starts agent 250%%% simple 251%%% big - e.g. starts/stops subagent, load/unloads mibs 252%%% init_mul 253%%% mul_get 254%%% mul_set 255%%% <etc> 256%%% finish_mul 257%%% <etc> 258%%% finish_v1 259%%% 260%%% init_v2 - starts agent 261%%% finish_v2 262%%% 263%%% init_bilingual - starts agent 264%%% finish_bilingual 265%%% 266%%% finish_all 267%%% 268%%% There is still one problem with these testsuites. If one test 269%%% fails, it may not be possible to run some other cases, as it 270%%% may have e.g. created some row or loaded some table, that it 271%%% didn't undo (since it failed). 272%%%----------------------------------------------------------------- 273 274init_all(Config0) when list(Config0) -> 275 ?LOG("init_all -> entry with" 276 "~n Config0: ~p",[Config0]), 277 278 %% -- 279 %% Fix config: 280 %% 281 282 DataDir0 = ?config(data_dir, Config0), 283 DataDir1 = filename:split(filename:absname(DataDir0)), 284 [_|DataDir2] = lists:reverse(DataDir1), 285 DataDir3 = filename:join(lists:reverse(DataDir2) ++ [?snmp_test_data]), 286 Config1 = lists:keydelete(data_dir, 1, Config0), 287 Config = [{data_dir, DataDir3 ++ "/"}|Config1], 288 289 %% -- 290 %% Start nodes 291 %% 292 293 ?line {ok, SaNode} = start_node(snmp_sa), 294 ?line {ok, MgrNode} = start_node(snmp_mgr), 295 296 297 %% -- 298 %% Create necessary files 299 %% 300 301 Dir = ?config(priv_dir, Config), 302 ?DBG("init_all -> Dir ~p", [Dir]), 303 304 DataDir = ?config(data_dir, Config), 305 ?DBG("init_all -> DataDir ~p", [DataDir]), 306 307 file:make_dir(MgrDir = filename:join(Dir, "mgr_dir/")), 308 ?DBG("init_all -> MgrDir ~p", [MgrDir]), 309 310 file:make_dir(AgentDir = filename:join(Dir, "agent_dir/")), 311 ?DBG("init_all -> AgentDir ~p", [AgentDir]), 312 313 file:make_dir(SaDir = filename:join(Dir, "sa_dir/")), 314 ?DBG("init_all -> SaDir ~p", [SaDir]), 315 316 317 %% -- 318 %% Start and initiate mnesia 319 %% 320 321 ?DBG("init_all -> load application mnesia", []), 322 ?line ok = application:load(mnesia), 323 324 ?DBG("init_all -> load application mnesia on node ~p", [SaNode]), 325 ?line ok = rpc:call(SaNode, application, load, [mnesia]), 326 327 ?DBG("init_all -> application mnesia: set_env dir",[]), 328 ?line application_controller:set_env(mnesia, dir, 329 filename:join(Dir, "Mnesia1")), 330 331 ?DBG("init_all -> application mnesia: set_env dir on node ~p",[SaNode]), 332 ?line rpc:call(SaNode, application_controller, set_env, 333 [mnesia, dir, filename:join(Dir, "Mnesia2")]), 334 335 ?DBG("init_all -> create mnesia schema",[]), 336 ?line ok = mnesia:create_schema([SaNode, node()]), 337 338 ?DBG("init_all -> start application mnesia",[]), 339 ?line ok = application:start(mnesia), 340 341 ?DBG("init_all -> start application mnesia on ~p",[SaNode]), 342 ?line ok = rpc:call(SaNode, application, start, [mnesia]), 343 Ip = ?LOCALHOST(), 344 [{snmp_sa, SaNode}, 345 {snmp_mgr, MgrNode}, 346 {agent_dir, AgentDir ++ "/"}, 347 {mgr_dir, MgrDir ++ "/"}, 348 {sa_dir, SaDir ++ "/"}, 349 {mib_dir, DataDir}, 350 {ip, Ip} | 351 Config]. 352 353finish_all(Config) when list(Config) -> 354 SaNode = ?config(snmp_sa, Config), 355 MgrNode = ?config(snmp_mgr, Config), 356 stop_node(SaNode), 357 stop_node(MgrNode), 358 application:stop(mnesia). 359 360start_v1_agent(Config) when list(Config) -> 361 start_agent(Config, [v1]). 362 363start_v1_agent(Config,Opts) when list(Config), list(Opts) -> 364 start_agent(Config, [v1], Opts). 365 366start_v2_agent(Config) when list(Config) -> 367 start_agent(Config, [v2]). 368 369start_v3_agent(Config) when list(Config) -> 370 start_agent(Config, [v3]). 371 372start_bilingual_agent(Config) when list(Config) -> 373 start_agent(Config, [v1,v2]). 374 375start_multi_threaded_agent(Config) when list(Config) -> 376 start_agent(Config, [v2], [{snmp_multi_threaded, true}]). 377 378stop_agent(Config) when list(Config) -> 379 ?LOG("stop_agent -> entry with" 380 "~n Config: ~p",[Config]), 381 382 {Sup, Par} = ?config(snmp_sup, Config), 383 ?DBG("stop_agent -> attempt to stop (sup) ~p" 384 "~n Sup: ~p" 385 "~n Par: ~p", 386 [Sup, 387 (catch process_info(Sup)), 388 (catch process_info(Par))]), 389 stop_sup(Sup, Par), 390 391 {Sup2, Par2} = ?config(snmp_sub, Config), 392 ?DBG("stop_agent -> attempt to stop (sub) ~p" 393 "~n Sup2: ~p" 394 "~n Par2: ~p", 395 [Sup2, 396 (catch process_info(Sup2)), 397 (catch process_info(Par2))]), 398 stop_sup(Sup2, Par2), 399 400 ?DBG("stop_agent -> done - now cleanup config", []), 401 C1 = lists:keydelete(snmp_sup, 1, Config), 402 lists:keydelete(snmp_sub, 1, C1). 403 404 405stop_sup(Pid, _) when node(Pid) == node() -> 406 case (catch process_info(Pid)) of 407 PI when list(PI) -> 408 ?LOG("stop_sup -> attempt to stop ~p", [Pid]), 409 Ref = erlang:monitor(process, Pid), 410 exit(Pid, kill), 411 await_stopped(Pid, Ref); 412 {'EXIT', _Reason} -> 413 ?LOG("stop_sup -> ~p not running", [Pid]), 414 ok 415 end; 416stop_sup(Pid, _) -> 417 ?LOG("stop_sup -> attempt to stop ~p", [Pid]), 418 Ref = erlang:monitor(process, Pid), 419 ?LOG("stop_sup -> Ref: ~p", [Ref]), 420 %% Pid ! {'EXIT', Parent, shutdown}, % usch 421 exit(Pid, kill), 422 await_stopped(Pid, Ref). 423 424await_stopped(Pid, Ref) -> 425 receive 426 {'DOWN', Ref, process, Pid, _Reason} -> 427 ?DBG("received down message for ~p", [Pid]), 428 ok 429 after 10000 -> 430 ?INF("await_stopped -> timeout for ~p",[Pid]), 431 erlang:demonitor(Ref), 432 ?FAIL({failed_stop,Pid}) 433 end. 434 435 436start_agent(Config, Vsn) -> 437 start_agent(Config, Vsn, []). 438start_agent(Config, Vsn, Opts) -> 439 ?LOG("start_agent -> entry (~p) with" 440 "~n Config: ~p" 441 "~n Vsn: ~p" 442 "~n Opts: ~p",[node(), Config, Vsn, Opts]), 443 444 ?line AgentDir = ?config(agent_dir, Config), 445 ?line SaNode = ?config(snmp_sa, Config), 446 447 snmp_app_env_init(vsn_init(Vsn) ++ 448 [{audit_trail_log, read_write_log}, 449 {audit_trail_log_dir, AgentDir}, 450 {audit_trail_log_size, {10240, 10}}, 451 {force_config_reload, false}, 452 {snmp_agent_type, master}, 453 {snmp_config_dir, AgentDir}, 454 {snmp_db_dir, AgentDir}, 455 {snmp_local_db_auto_repair, true}, 456 {snmp_master_agent_verbosity, trace}, 457 {snmp_supervisor_verbosity, trace}, 458 {snmp_mibserver_verbosity, trace}, 459 {snmp_symbolic_store_verbosity, trace}, 460 {snmp_note_store_verbosity, trace}, 461 {snmp_net_if_verbosity, trace}], 462 Opts), 463 464 465 process_flag(trap_exit,true), 466 467 {ok, AppSup} = snmp_app_sup:start_link(), 468 unlink(AppSup), 469 ?DBG("start_agent -> snmp app supervisor: ~p",[AppSup]), 470 471 ?DBG("start_agent -> start master agent (old style)",[]), 472 Sup = case (catch snmpa_app:start(normal)) of 473 {ok, S} -> 474 ?DBG("start_agent -> started, Sup: ~p",[S]), 475 S; 476 477 Else -> 478 ?DBG("start_agent -> unknown result: ~n~p",[Else]), 479 %% Get info about the apps we depend on 480 MnesiaInfo = mnesia_running(), 481 ?FAIL({start_failed,Else,MnesiaInfo}) 482 end, 483 484 ?DBG("start_agent -> unlink from supervisor",[]), 485 ?line unlink(Sup), 486 ?line SaDir = ?config(sa_dir, Config), 487 ?DBG("start_agent -> (rpc) start sub on ~p",[SaNode]), 488 ?line {ok, Sub} = rpc:call(SaNode, ?MODULE, start_sub, [SaDir]), 489 ?DBG("start_agent -> done",[]), 490 ?line [{snmp_sup, {Sup, self()}}, {snmp_sub, Sub} | Config]. 491 492 493vsn_init(Vsn) -> 494 vsn_init([v1,v2,v3], Vsn, []). 495 496vsn_init([], _Vsn, Acc) -> 497 Acc; 498vsn_init([V|Vsns], Vsn, Acc) -> 499 case lists:member(V, Vsn) of 500 true -> 501 vsn_init(Vsns, Vsn, [{V, true}|Acc]); 502 false -> 503 vsn_init(Vsns, Vsn, [{V, false}|Acc]) 504 end. 505 506snmp_app_env_init(Env0, Opts) -> 507 ?DBG("snmp_app_env_init -> unload snmp",[]), 508 ?line application:unload(snmp), 509 ?DBG("snmp_app_env_init -> load snmp",[]), 510 ?line application:load(snmp), 511 ?DBG("snmp_app_env_init -> initiate (snmp) application env",[]), 512 F1 = fun({Key,Val} = New, Acc0) -> 513 ?DBG("snmp_app_env_init -> " 514 "updating setting ~p to ~p", [Key, Val]), 515 case lists:keyreplace(Key, 1, Acc0, New) of 516 Acc0 -> 517 [New|Acc0]; 518 Acc -> 519 Acc 520 end 521 end, 522 Env = lists:foldr(F1, Env0, Opts), 523 ?DBG("snmp_app_env_init -> Env: ~p",[Env]), 524 F2 = fun({Key,Val}) -> 525 ?DBG("snmp_app_env_init -> setting ~p to ~p",[Key, Val]), 526 application_controller:set_env(snmp, Key, Val) 527 end, 528 lists:foreach(F2, Env). 529 530 531 532 533%% Test if application is running 534mnesia_running() -> ?IS_MNESIA_RUNNING(). 535crypto_running() -> ?IS_CRYPTO_RUNNING(). 536 537 538start_sub(Dir) -> 539 ?DBG("start_sub -> entry",[]), 540 Opts = [{db_dir, Dir}, 541 {supervisor, [{verbosity, trace}]}], 542 %% BMK BMK 543% {ok, P} = snmp_supervisor:start_sub(Dir), 544 {ok, P} = snmpa_supervisor:start_sub_sup(Opts), 545 unlink(P), 546 {ok, {P, self()}}. 547 548create_tables(SaNode) -> 549 ?line {atomic, ok} = mnesia:create_table([{name, friendsTable2}, 550 {ram_copies, [SaNode]}, 551 {snmp, [{key, integer}]}, 552 {attributes, [a1,a2,a3]}]), 553 ?line {atomic, ok} = mnesia:create_table([{name, kompissTable2}, 554 {ram_copies, [SaNode]}, 555 {snmp, [{key, integer}]}, 556 {attributes, [a1,a2,a3]}]), 557 ?line {atomic, ok} = mnesia:create_table([{name, snmp_variables}, 558 {attributes, [a1,a2]}]). 559 560delete_tables() -> 561 mnesia:delete_table(friendsTable2), 562 mnesia:delete_table(kompissTable2), 563 mnesia:delete_table(snmp_variables). 564 565%% Creation is done in runtime! 566delete_mib_storage_mnesia_tables() -> 567 mnesia:delete_table(snmpa_mib_data), 568 mnesia:delete_table(snmpa_mib_tree), 569 mnesia:delete_table(snmpa_symbolic_store). 570 571%%----------------------------------------------------------------- 572%% A test case is always one of: 573%% - v1 specific case 574%% - v2 specific case 575%% - v1 and v2 case 576%% All v1 specific cases are prefixed with v1_, and all v2 with 577%% v2_. E.g. v1_trap/v2_trap. 578%% 579%% All other cases are shared. However, the testserver uses the name 580%% of the case to generate a file for that case. The same case cannot 581%% be used in different configurations in the same suite. Therefore 582%% all these functions exists in two variants, the base function 583%% <base>, and a second version <base>_2. There may be several 584%% versions as well, <base>_N. 585%%----------------------------------------------------------------- 586 587 588 589 590 591 592 593 594 595mib_storage_ets_cases() -> 596[mse_simple, mse_v1_processing, mse_big, mse_big2, 597 mse_loop_mib, mse_api, mse_sa_register, mse_v1_trap, 598 mse_sa_error, mse_next_across_sa, mse_undo, 599 mse_standard_mib, mse_community_mib, mse_framework_mib, 600 mse_target_mib, mse_notification_mib, 601 mse_view_based_acm_mib, mse_sparse_table, mse_me_of, 602 mse_mib_of]. 603 604mib_storage_dets_cases() -> 605[msd_simple, msd_v1_processing, msd_big, msd_big2, 606 msd_loop_mib, msd_api, msd_sa_register, msd_v1_trap, 607 msd_sa_error, msd_next_across_sa, msd_undo, 608 msd_standard_mib, msd_community_mib, msd_framework_mib, 609 msd_target_mib, msd_notification_mib, 610 msd_view_based_acm_mib, msd_sparse_table, msd_me_of, 611 msd_mib_of]. 612 613mib_storage_mnesia_cases() -> 614[msm_simple, msm_v1_processing, msm_big, msm_big2, 615 msm_loop_mib, msm_api, msm_sa_register, msm_v1_trap, 616 msm_sa_error, msm_next_across_sa, msm_undo, 617 msm_standard_mib, msm_community_mib, msm_framework_mib, 618 msm_target_mib, msm_notification_mib, 619 msm_view_based_acm_mib, msm_sparse_table, msm_me_of, 620 msm_mib_of]. 621 622mse_size_check_cases() -> 623[mse_size_check]. 624 625msd_size_check_cases() -> 626[msd_size_check]. 627 628msm_size_check_cases() -> 629[msm_size_check]. 630 631varm_mib_storage_dets_cases() -> 632[msd_varm_mib_start]. 633 634varm_mib_storage_mnesia_cases() -> 635[msm_varm_mib_start]. 636 637init_mib_storage_ets(Config) when list(Config) -> 638 ?LOG("init_mib_storage_ets -> entry", []), 639 MibStorage = {snmp_mib_storage,ets}, 640 init_ms(Config, [MibStorage]). 641 642init_mib_storage_dets(Config) when list(Config) -> 643 ?LOG("init_mib_storage_ets -> entry", []), 644 ?line AgentDir = ?GCONF(agent_dir, Config), 645 MibStorage = {snmp_mib_storage,{dets,AgentDir}}, 646 init_ms(Config, [MibStorage]). 647 648init_mib_storage_mnesia(Config) when list(Config) -> 649 ?LOG("init_mib_storage_ets -> entry", []), 650 MibStorage = {snmp_mib_storage,{mnesia,[]}}, 651 init_ms(Config, [MibStorage]). 652 653init_ms(Config, Opts) when list(Config) -> 654 ?LOG("init_mib_storage_ets -> entry", []), 655 ?line SaNode = ?GCONF(snmp_sa, Config), 656 ?line create_tables(SaNode), 657 ?line AgentDir = ?GCONF(agent_dir, Config), 658 ?line MgrDir = ?GCONF(mgr_dir, Config), 659 ?line Ip = ?GCONF(ip, Config), 660 ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), 661 MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, 662 MibsVerbosity = {snmp_mibserver_verbosity, trace}, 663 SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, 664 Opts1 = [MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity|Opts], 665 [{vsn, v1} | start_v1_agent(Config,Opts1)]. 666 667init_size_check_mse(Config) when list(Config) -> 668 MibStorage = {snmp_mib_storage, ets}, 669 init_size_check_ms(Config, [MibStorage]). 670 671init_size_check_msd(Config) when list(Config) -> 672 AgentDir = ?GCONF(agent_dir, Config), 673 MibStorage = {snmp_mib_storage, {dets, AgentDir}}, 674 init_size_check_ms(Config, [MibStorage]). 675 676init_size_check_msm(Config) when list(Config) -> 677 MibStorage = {snmp_mib_storage, {mnesia,[]}}, 678 init_size_check_ms(Config, [MibStorage]). 679 680init_size_check_ms(Config, Opts) when list(Config) -> 681 SaNode = ?GCONF(snmp_sa, Config), 682 %% We are using v3 here, so crypto must be supported or else... 683 case ?CRYPTO_START() of 684 ok -> 685 case ?CRYPTO_SUPPORT() of 686 {no, Reason} -> 687 ?SKIP({unsupported_encryption, Reason}); 688 yes -> 689 ok 690 end; 691 {error, Reason} -> 692 ?SKIP({failed_starting_crypto, Reason}) 693 end, 694 create_tables(SaNode), 695 AgentDir = ?GCONF(agent_dir, Config), 696 MgrDir = ?GCONF(mgr_dir, Config), 697 Ip = ?GCONF(ip, Config), 698 ?line ok = 699 config([v3], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), 700 [{vsn, v3} | start_agent(Config, [v3], Opts)]. 701 702init_varm_mib_storage_dets(Config) when list(Config) -> 703 ?LOG("init_varm_mib_storage_dets -> entry", []), 704 ?line SaNode = ?GCONF(snmp_sa, Config), 705 ?line create_tables(SaNode), 706 ?line AgentDir = ?GCONF(agent_dir, Config), 707 ?line MgrDir = ?GCONF(mgr_dir, Config), 708 ?line Ip = ?GCONF(ip, Config), 709 ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), 710 MibStorage = {snmp_mib_storage,{dets,AgentDir}}, 711 MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, 712 MibsVerbosity = {snmp_mibserver_verbosity, trace}, 713 SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, 714 Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity], 715 [{vsn, v1}, {agent_opts,Opts} | Config]. 716 717init_varm_mib_storage_mnesia(Config) when list(Config) -> 718 ?LOG("init_varm_mib_storage_mnesia -> entry", []), 719 ?line SaNode = ?GCONF(snmp_sa, Config), 720 ?line create_tables(SaNode), 721 ?line AgentDir = ?GCONF(agent_dir, Config), 722 ?line MgrDir = ?GCONF(mgr_dir, Config), 723 ?line Ip = ?GCONF(ip, Config), 724 ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), 725 MibStorage = {snmp_mib_storage,{mnesia,[]}}, 726 MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, 727 MibsVerbosity = {snmp_mibserver_verbosity, trace}, 728 SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, 729 Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity], 730 [{vsn, v1}, {agent_opts,Opts} | Config]. 731 732finish_mib_storage_ets(Config) when list(Config) -> 733 ?LOG("finish_mib_storage_ets -> entry", []), 734 delete_tables(), 735 C1 = stop_agent(Config), 736 delete_files(C1), 737 C2 = lists:keydelete(vsn, 1, C1), 738 lists:keydelete(agent_opts, 1, C2). 739 740finish_mib_storage_dets(Config) when list(Config) -> 741 ?LOG("finish_mib_storage_dets -> entry", []), 742 delete_tables(), 743 C1 = stop_agent(Config), 744 delete_files(C1), 745 C2 = lists:keydelete(vsn, 1, C1), 746 lists:keydelete(agent_opts, 1, C2). 747 748finish_mib_storage_mnesia(Config) when list(Config) -> 749 ?LOG("finish_mib_storage_mnesia -> entry", []), 750 delete_tables(), 751 delete_mib_storage_mnesia_tables(), 752 C1 = stop_agent(Config), 753 delete_files(C1), 754 C2 = lists:keydelete(vsn, 1, C1), 755 lists:keydelete(agent_opts, 1, C2). 756 757finish_varm_mib_storage_dets(Config) when list(Config) -> 758 ?LOG("finish_varm_mib_storage_dets -> entry", []), 759 delete_tables(), 760 %% C1 = stop_agent(Config), % In case something went wrong... 761 delete_files(Config), 762 C2 = lists:keydelete(vsn, 1, Config), 763 lists:keydelete(agent_opts, 1, C2). 764 765finish_varm_mib_storage_mnesia(Config) when list(Config) -> 766 ?LOG("finish_varm_mib_storage_mnesia -> entry", []), 767 delete_tables(), 768 delete_mib_storage_mnesia_tables(), 769 %% C1 = stop_agent(Config), % In case something went wrong... 770 delete_files(Config), 771 C2 = lists:keydelete(vsn, 1, Config), 772 lists:keydelete(agent_opts, 1, C2). 773 774finish_size_check_mse(Config) when list(Config) -> 775 finish_size_check_ms(Config). 776 777finish_size_check_msd(Config) when list(Config) -> 778 finish_size_check_ms(Config). 779 780finish_size_check_msm(Config) when list(Config) -> 781 finish_size_check_ms(Config). 782 783finish_size_check_ms(Config) when list(Config) -> 784 delete_tables(), 785 C1 = stop_agent(Config), 786 delete_files(C1), 787 lists:keydelete(vsn, 1, C1). 788 789 790%% These are just interface functions to fool the test server 791mse_simple(X) -> simple(X). 792mse_v1_processing(X) -> v1_processing(X). 793mse_big(X) -> big(X). 794mse_big2(X) -> big2(X). 795mse_loop_mib(X) -> loop_mib(X). 796mse_api(X) -> api(X). 797mse_sa_register(X) -> sa_register(X). 798mse_v1_trap(X) -> v1_trap(X). 799mse_sa_error(X) -> sa_error(X). 800mse_next_across_sa(X) -> next_across_sa(X). 801mse_undo(X) -> undo(X). 802mse_standard_mib(X) -> snmp_standard_mib(X). 803mse_community_mib(X) -> snmp_community_mib(X). 804mse_framework_mib(X) -> snmp_framework_mib(X). 805mse_target_mib(X) -> snmp_target_mib(X). 806mse_notification_mib(X) -> snmp_notification_mib(X). 807mse_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). 808mse_sparse_table(X) -> sparse_table(X). 809mse_me_of(X) -> ms_me_of(X). 810mse_mib_of(X) -> ms_mib_of(X). 811 812msd_simple(X) -> simple(X). 813msd_v1_processing(X) -> v1_processing(X). 814msd_big(X) -> big(X). 815msd_big2(X) -> big2(X). 816msd_loop_mib(X) -> loop_mib(X). 817msd_api(X) -> api(X). 818msd_sa_register(X) -> sa_register(X). 819msd_v1_trap(X) -> v1_trap(X). 820msd_sa_error(X) -> sa_error(X). 821msd_next_across_sa(X) -> next_across_sa(X). 822msd_undo(X) -> undo(X). 823msd_standard_mib(X) -> snmp_standard_mib(X). 824msd_community_mib(X) -> snmp_community_mib(X). 825msd_framework_mib(X) -> snmp_framework_mib(X). 826msd_target_mib(X) -> snmp_target_mib(X). 827msd_notification_mib(X) -> snmp_notification_mib(X). 828msd_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). 829msd_sparse_table(X) -> sparse_table(X). 830msd_me_of(X) -> ms_me_of(X). 831msd_mib_of(X) -> ms_mib_of(X). 832 833msm_simple(X) -> simple(X). 834msm_v1_processing(X) -> v1_processing(X). 835msm_big(X) -> big(X). 836msm_big2(X) -> big2(X). 837msm_loop_mib(X) -> loop_mib(X). 838msm_api(X) -> api(X). 839msm_sa_register(X) -> sa_register(X). 840msm_v1_trap(X) -> v1_trap(X). 841msm_sa_error(X) -> sa_error(X). 842msm_next_across_sa(X) -> next_across_sa(X). 843msm_undo(X) -> undo(X). 844msm_standard_mib(X) -> snmp_standard_mib(X). 845msm_community_mib(X) -> snmp_community_mib(X). 846msm_framework_mib(X) -> snmp_framework_mib(X). 847msm_target_mib(X) -> snmp_target_mib(X). 848msm_notification_mib(X) -> snmp_notification_mib(X). 849msm_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). 850msm_sparse_table(X) -> sparse_table(X). 851msm_me_of(X) -> ms_me_of(X). 852msm_mib_of(X) -> ms_mib_of(X). 853 854 855mse_size_check(X) -> p("mse_size_check..."), ms_size_check(X). 856msd_size_check(X) -> p("msd_size_check..."), ms_size_check(X). 857msm_size_check(X) -> p("msm_size_check..."), ms_size_check(X). 858 859msd_varm_mib_start(X) -> p("msd_varm_mib_start..."), varm_mib_start(X). 860msm_varm_mib_start(X) -> p("msm_varm_mib_start..."), varm_mib_start(X). 861 862ms_size_check(suite) -> []; 863ms_size_check(Config) when list(Config) -> 864 p("ms_size_check..."), 865 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 866 ?LOG("mib server size check...", []), 867 868 ?line load_master("Test2"), 869 ?line load_master("TestTrap"), 870 ?line load_master("TestTrapv2"), 871 ?line load_master_std("OTP-SNMPEA-MIB"), 872 ?line load_master_std("SNMP-COMMUNITY-MIB"), 873 ?line load_master_std("SNMP-FRAMEWORK-MIB"), 874 ?line load_master_std("SNMP-MPD-MIB"), 875 ?line load_master_std("SNMP-NOTIFICATION-MIB"), 876 ?line load_master_std("SNMP-TARGET-MIB"), 877 ?line load_master_std("SNMP-USER-BASED-SM-MIB"), 878 ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), 879 ?line load_master_std("SNMPv2-MIB"), 880 ?line load_master_std("SNMPv2-TM"), 881 882 ?SLEEP(2000), 883 884 ?line display_memory_usage(), 885 886 ?line unload_master("OTP-SNMPEA-MIB"), 887 ?line unload_master("SNMP-COMMUNITY-MIB"), 888 ?line unload_master("SNMP-FRAMEWORK-MIB"), 889 ?line unload_master("SNMP-MPD-MIB"), 890 ?line unload_master("SNMP-NOTIFICATION-MIB"), 891 ?line unload_master("SNMP-TARGET-MIB"), 892 ?line unload_master("SNMP-USER-BASED-SM-MIB"), 893 ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), 894 ?line unload_master("SNMPv2-MIB"), 895 ?line unload_master("SNMPv2-TM"), 896 897 ?line unload_master("TestTrapv2"), 898 ?line unload_master("TestTrap"), 899 ?line unload_master("Test2"), 900 901 ok. 902 903 904varm_mib_start(suite) -> []; 905varm_mib_start(Config) when list(Config) -> 906 p("varm_mib_start..."), 907 ?LOG("varm_mib_start -> entry", []), 908 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 909 910 %% Start the agent 911 Opts = ?GCONF(agent_opts, Config), 912 Config1 = start_v1_agent(Config, Opts), 913 914 %% Sleep some in order for the agent to start properly 915 ?DBG("varm_mib_start -> sleep some (before loading mobs)", []), 916 ?SLEEP(5000), 917 918 %% Load all the mibs 919 HardwiredMibs = loaded_mibs(), 920 ?DBG("varm_mib_start -> load all mibs", []), 921 ?line load_master_std("SNMP-COMMUNITY-MIB"), 922 ?line load_master_std("SNMP-FRAMEWORK-MIB"), 923 ?line load_master_std("SNMP-TARGET-MIB"), 924 ?line load_master_std("SNMP-NOTIFICATION-MIB"), 925 926 %% Unload the hardwired mibs 927 ?DBG("varm_mib_start -> sleep some (before unloading hardwired mibs)", []), 928 ?SLEEP(1000), 929 ?DBG("varm_mib_start -> unload (hardwired) mibs", []), 930 ?line unload_mibs(HardwiredMibs), %% unload hardwired 931 932 ?DBG("varm_mib_start -> sleep some (before stopping agent)", []), 933 ?SLEEP(1000), 934 935 %% Stop the agent (without deleting the stored files) 936 ?DBG("varm_mib_start -> stop the agent", []), 937 Config2 = stop_agent(Config1), 938 939 %% Sleep some in order for the agent to stop properly 940 ?DBG("varm_mib_start -> sleep some (before re-starting the agent)", []), 941 ?SLEEP(5000), 942 943 %% Start the agent (again) 944 ?DBG("varm_mib_start -> start the agent", []), 945 Config3 = start_v1_agent(Config2, Opts), 946 947 ?DBG("varm_mib_start -> sleep some (before starting tests)", []), 948 ?SLEEP(5000), 949 950 %% Perform the test(s) 951 ?DBG("varm_mib_start -> perform the tests", []), 952 try_test(snmp_community_mib), 953 try_test(snmp_framework_mib), 954 try_test(snmp_target_mib), 955 try_test(snmp_notification_mib), 956 957 %% Stop the agent (without deleting the stored files) 958 ?DBG("varm_mib_start -> stop the agent", []), 959 stop_agent(Config3), 960 ok. 961 962 963-define(snmpTrapCommunity_instance, [1,3,6,1,6,3,18,1,4,0]). 964-define(vacmViewSpinLock_instance, [1,3,6,1,6,3,16,1,5,1,0]). 965-define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). 966 967ms_me_of(suite) -> []; 968ms_me_of(Config) when list(Config) -> 969 p("ms_me_of..."), 970 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 971 972 ?line load_master("Test2"), 973 ?line load_master("TestTrap"), 974 ?line load_master("TestTrapv2"), 975 ?line load_master_std("OTP-SNMPEA-MIB"), 976 ?line load_master_std("SNMP-COMMUNITY-MIB"), 977 ?line load_master_std("SNMP-FRAMEWORK-MIB"), 978 ?line load_master_std("SNMP-MPD-MIB"), 979 ?line load_master_std("SNMP-NOTIFICATION-MIB"), 980 ?line load_master_std("SNMP-TARGET-MIB"), 981 ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), 982 983 ?SLEEP(2000), 984 985 ?line display_memory_usage(), 986 987 988 ?DBG("ms_me_of -> find ~w from SNMP-COMMUNITY-MIB", 989 [?snmpTrapCommunity_instance]), 990 ?line ok = me_of(?snmpTrapCommunity_instance), 991 992 ?DBG("ms_me_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", 993 [?vacmViewSpinLock_instance]), 994 ?line ok = me_of(?vacmViewSpinLock_instance), 995 996 ?DBG("ms_me_of -> find ~w from SNMP-USER-BASED-SM-MIB", 997 [?usmStatsNotInTimeWindows_instance]), 998 ?line {error, _} = me_of(?usmStatsNotInTimeWindows_instance), 999 1000 1001 ?line unload_master("OTP-SNMPEA-MIB"), 1002 ?line unload_master("SNMP-COMMUNITY-MIB"), 1003 ?line unload_master("SNMP-FRAMEWORK-MIB"), 1004 ?line unload_master("SNMP-MPD-MIB"), 1005 ?line unload_master("SNMP-NOTIFICATION-MIB"), 1006 ?line unload_master("SNMP-TARGET-MIB"), 1007 ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), 1008 1009 ?line unload_master("TestTrapv2"), 1010 ?line unload_master("TestTrap"), 1011 ?line unload_master("Test2"), 1012 1013 ok. 1014 1015me_of(Oid) -> 1016 case snmpa:me_of(Oid) of 1017 {ok, #me{oid = Oid}} -> 1018 ok; 1019 {ok, #me{oid = OtherOid}} -> 1020 case lists:reverse(Oid) of 1021 [0|Rest] -> 1022 case lists:reverse(Rest) of 1023 OtherOid -> 1024 ok; 1025 AnotherOid -> 1026 {error, {invalid_oid, Oid, AnotherOid}} 1027 end; 1028 _ -> 1029 {error, {invalid_oid, Oid, OtherOid}} 1030 end; 1031 {error, Reason} -> 1032 {error, Reason}; 1033 Else -> 1034 {error, Else} 1035 end. 1036 1037 1038ms_mib_of(suite) -> []; 1039ms_mib_of(Config) when list(Config) -> 1040 p("ms_mib_of..."), 1041 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 1042 1043 ?line load_master("Test2"), 1044 ?line load_master("TestTrap"), 1045 ?line load_master("TestTrapv2"), 1046 ?line load_master_std("OTP-SNMPEA-MIB"), 1047 ?line load_master_std("SNMP-COMMUNITY-MIB"), 1048 ?line load_master_std("SNMP-FRAMEWORK-MIB"), 1049 ?line load_master_std("SNMP-MPD-MIB"), 1050 ?line load_master_std("SNMP-NOTIFICATION-MIB"), 1051 ?line load_master_std("SNMP-TARGET-MIB"), 1052 ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), 1053 1054 ?SLEEP(2000), 1055 1056 ?line display_memory_usage(), 1057 1058 1059 ?DBG("ms_mib_of -> find ~w from SNMP-COMMUNITY-MIB", 1060 [?snmpTrapCommunity_instance]), 1061 ?line ok = mib_of(?snmpTrapCommunity_instance, 'SNMP-COMMUNITY-MIB'), 1062 1063 ?DBG("ms_mib_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", 1064 [?vacmViewSpinLock_instance]), 1065 ?line ok = mib_of(?vacmViewSpinLock_instance, 'SNMP-VIEW-BASED-ACM-MIB'), 1066 1067 ?DBG("ms_mib_of -> find ~w from SNMP-USER-BASED-SM-MIB", 1068 [?usmStatsNotInTimeWindows_instance]), 1069 ?line {error, _} = mib_of(?usmStatsNotInTimeWindows_instance, 1070 'SNMP-USER-BASED-SM-MIB'), 1071 1072 1073 ?line unload_master("OTP-SNMPEA-MIB"), 1074 ?line unload_master("SNMP-COMMUNITY-MIB"), 1075 ?line unload_master("SNMP-FRAMEWORK-MIB"), 1076 ?line unload_master("SNMP-MPD-MIB"), 1077 ?line unload_master("SNMP-NOTIFICATION-MIB"), 1078 ?line unload_master("SNMP-TARGET-MIB"), 1079 ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), 1080 1081 ?line unload_master("TestTrapv2"), 1082 ?line unload_master("TestTrap"), 1083 ?line unload_master("Test2"), 1084 1085 ok. 1086 1087mib_of(Oid, ExpectedMibName) -> 1088 ?DBG("mib_of -> entry with" 1089 "~n Oid: ~p" 1090 "~n ExpectedMibName: ~p", [Oid, ExpectedMibName]), 1091 %% case snmpa:mib_of(Oid) of 1092 MibOf = snmpa:mib_of(Oid), 1093 ?DBG("mib_of -> MibOf: ~n~p", [MibOf]), 1094 case MibOf of 1095 {ok, ExpectedMibName} -> 1096 ok; 1097 {ok, OtherMibName} -> 1098 {error, {invalid_mib, ExpectedMibName, OtherMibName}}; 1099 {error, Reason} -> 1100 {error, Reason}; 1101 Else -> 1102 ?DBG("mib_of -> Else: ~n~p", [Else]), 1103 {error, Else} 1104 end. 1105 1106 1107app_info(suite) -> []; 1108app_info(Config) when list(Config) -> 1109 SnmpDir = app_dir(snmp), 1110 SslDir = app_dir(ssl), 1111 CryptoDir = app_dir(crypto), 1112 Attr = snmp:module_info(attributes), 1113 AppVsn = 1114 case lists:keysearch(app_vsn, 1, Attr) of 1115 {value, {app_vsn, V}} -> 1116 V; 1117 false -> 1118 "undefined" 1119 end, 1120 io:format("Root dir: ~s~n" 1121 "SNMP: Application dir: ~s~n" 1122 " Application ver: ~s~n" 1123 "SSL: Application dir: ~s~n" 1124 "CRYPTO: Application dir: ~s~n", 1125 [code:root_dir(), SnmpDir, AppVsn, SslDir, CryptoDir]), 1126 ok. 1127 1128app_dir(App) -> 1129 case code:lib_dir(App) of 1130 D when list(D) -> 1131 filename:basename(D); 1132 {error, _Reason} -> 1133 "undefined" 1134 end. 1135 1136 1137 1138%v1_cases() -> [loop_mib]; 1139v1_cases() -> 1140[simple, db_notify_client, v1_processing, big, big2, 1141 loop_mib, api, subagent, mnesia, {group, multiple_reqs}, 1142 sa_register, v1_trap, sa_error, next_across_sa, undo, 1143 {group, reported_bugs}, {group, standard_mibs}, 1144 sparse_table, cnt_64, opaque, change_target_addr_config]. 1145 1146init_v1(Config) when list(Config) -> 1147 ?line SaNode = ?config(snmp_sa, Config), 1148 ?line create_tables(SaNode), 1149 ?line AgentDir = ?config(agent_dir, Config), 1150 ?line MgrDir = ?config(mgr_dir, Config), 1151 ?line Ip = ?config(ip, Config), 1152 ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), 1153 [{vsn, v1} | start_v1_agent(Config)]. 1154 1155finish_v1(Config) when list(Config) -> 1156 delete_tables(), 1157 C1 = stop_agent(Config), 1158 delete_files(C1), 1159 lists:keydelete(vsn, 1, C1). 1160 1161 1162%v2_cases() -> [loop_mib_2]; 1163v2_cases() -> 1164[simple_2, v2_processing, big_2, big2_2, loop_mib_2, 1165 api_2, subagent_2, mnesia_2, {group, multiple_reqs_2}, 1166 sa_register_2, v2_trap, {group, v2_inform}, sa_error_2, 1167 next_across_sa_2, undo_2, {group, reported_bugs_2}, 1168 {group, standard_mibs_2}, v2_types, implied, 1169 sparse_table_2, cnt_64_2, opaque_2, v2_caps]. 1170 1171init_v2(Config) when list(Config) -> 1172 SaNode = ?config(snmp_sa, Config), 1173 create_tables(SaNode), 1174 AgentDir = ?config(agent_dir, Config), 1175 MgrDir = ?config(mgr_dir, Config), 1176 Ip = ?config(ip, Config), 1177 config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), 1178 [{vsn, v2} | start_v2_agent(Config)]. 1179 1180finish_v2(Config) when list(Config) -> 1181 delete_tables(), 1182 C1 = stop_agent(Config), 1183 delete_files(C1), 1184 lists:keydelete(vsn, 1, C1). 1185 1186 1187v1_v2_cases() -> 1188[simple_bi]. 1189 1190init_v1_v2(Config) when list(Config) -> 1191 SaNode = ?config(snmp_sa, Config), 1192 create_tables(SaNode), 1193 AgentDir = ?config(agent_dir, Config), 1194 MgrDir = ?config(mgr_dir, Config), 1195 Ip = ?config(ip, Config), 1196 config([v1,v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), 1197 [{vsn, bilingual} | start_bilingual_agent(Config)]. 1198 1199finish_v1_v2(Config) when list(Config) -> 1200 delete_tables(), 1201 C1 = stop_agent(Config), 1202 delete_files(C1), 1203 lists:keydelete(vsn, 1, C1). 1204 1205 1206%v3_cases() -> [loop_mib_3]; 1207v3_cases() -> 1208[simple_3, v3_processing, big_3, big2_3, api_3, 1209 subagent_3, mnesia_3, loop_mib_3, multiple_reqs_3, 1210 sa_register_3, v3_trap, v3_inform, sa_error_3, 1211 next_across_sa_3, undo_3, {group, reported_bugs_3}, 1212 {group, standard_mibs_3}, {group, v3_security}, 1213 v2_types_3, implied_3, sparse_table_3, cnt_64_3, 1214 opaque_3, v2_caps_3]. 1215 1216init_v3(Config) when list(Config) -> 1217 %% Make sure crypto works, otherwise start_agent will fail 1218 %% and we will be stuck with a bunch of mnesia tables for 1219 %% the rest of this suite... 1220 ?DBG("start_agent -> start crypto app",[]), 1221 case ?CRYPTO_START() of 1222 ok -> 1223 case ?CRYPTO_SUPPORT() of 1224 {no, Reason} -> 1225 ?SKIP({unsupported_encryption, Reason}); 1226 yes -> 1227 ok 1228 end; 1229 {error, Reason} -> 1230 ?SKIP({failed_starting_crypto, Reason}) 1231 end, 1232 SaNode = ?config(snmp_sa, Config), 1233 create_tables(SaNode), 1234 AgentDir = ?config(agent_dir, Config), 1235 MgrDir = ?config(mgr_dir, Config), 1236 Ip = ?config(ip, Config), 1237 ?line ok = config([v3], MgrDir, AgentDir, 1238 tuple_to_list(Ip), tuple_to_list(Ip)), 1239 [{vsn, v3} | start_v3_agent(Config)]. 1240 1241finish_v3(Config) when list(Config) -> 1242 delete_tables(), 1243 C1 = stop_agent(Config), 1244 delete_files(C1), 1245 lists:keydelete(vsn, 1, C1). 1246 1247 1248mt_cases() -> 1249[multi_threaded, mt_trap]. 1250 1251init_mt(Config) when list(Config) -> 1252 SaNode = ?config(snmp_sa, Config), 1253 create_tables(SaNode), 1254 AgentDir = ?config(agent_dir, Config), 1255 MgrDir = ?config(mgr_dir, Config), 1256 Ip = ?config(ip, Config), 1257 ?line ok = config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), 1258 [{vsn, v2} | start_multi_threaded_agent(Config)]. 1259 1260finish_mt(Config) when list(Config) -> 1261 delete_tables(), 1262 C1 = stop_agent(Config), 1263 delete_files(C1), 1264 lists:keydelete(vsn, 1, C1). 1265 1266%% This one *must* be run first in each case. 1267init_case(Config) when list(Config) -> 1268 ?DBG("init_case -> entry with" 1269 "~n Config: ~p", [Config]), 1270 SaNode = ?config(snmp_sa, Config), 1271 MgrNode = ?config(snmp_mgr, Config), 1272 MasterNode = node(), 1273 1274 SaHost = ?HOSTNAME(SaNode), 1275 MgrHost = ?HOSTNAME(MgrNode), 1276 MasterHost = ?HOSTNAME(MasterNode), 1277 {ok, MasterIP} = snmp_misc:ip(MasterHost), 1278 {ok, MIP} = snmp_misc:ip(MgrHost), 1279 {ok, SIP} = snmp_misc:ip(SaHost), 1280 1281 1282 put(mgr_node, MgrNode), 1283 put(sa_node, SaNode), 1284 put(master_node, MasterNode), 1285 put(sa_host, SaHost), 1286 put(mgr_host, MgrHost), 1287 put(master_host, MasterHost), 1288 put(mip, tuple_to_list(MIP)), 1289 put(masterip , tuple_to_list(MasterIP)), 1290 put(sip, tuple_to_list(SIP)), 1291 1292 MibDir = ?config(mib_dir, Config), 1293 put(mib_dir, MibDir), 1294 StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", 1295 put(std_mib_dir, StdM), 1296 1297 MgrDir = ?config(mgr_dir, Config), 1298 put(mgr_dir, MgrDir), 1299 1300 put(vsn, ?config(vsn, Config)), 1301 ?DBG("init_case -> exit with" 1302 "~n MasterNode: ~p" 1303 "~n SaNode: ~p" 1304 "~n MgrNode: ~p" 1305 "~n MibDir: ~p", [MasterNode, SaNode, MgrNode, MibDir]), 1306 {SaNode, MgrNode, MibDir}. 1307 1308load_master(Mib) -> 1309 ?DBG("load_master -> entry with" 1310 "~n Mib: ~p", [Mib]), 1311 snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety 1312 ok = snmpa:load_mibs(snmp_master_agent, [get(mib_dir) ++ Mib]). 1313 1314load_master_std(Mib) -> 1315 ?DBG("load_master_std -> entry with" 1316 "~n Mib: ~p", [Mib]), 1317 snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety 1318 ok = snmpa:load_mibs(snmp_master_agent, [get(std_mib_dir) ++ Mib]). 1319 1320unload_master(Mib) -> 1321 ?DBG("unload_master -> entry with" 1322 "~n Mib: ~p", [Mib]), 1323 ok = snmpa:unload_mibs(snmp_master_agent, [Mib]). 1324 1325loaded_mibs() -> 1326 ?DBG("loaded_mibs -> entry",[]), 1327 Info = snmpa:info(snmp_master_agent), 1328 {value, {loaded_mibs, Mibs}} = lists:keysearch(loaded_mibs, 1, Info), 1329 [atom_to_list(Mib) || {Mib,_,_} <- Mibs]. 1330 1331unload_mibs(Mibs) -> 1332 ?DBG("unload_mibs -> entry with" 1333 "~n Mibs: ~p", [Mibs]), 1334 ok = snmpa:unload_mibs(snmp_master_agent, Mibs). 1335 1336start_subagent(SaNode, RegTree, Mib) -> 1337 ?DBG("start_subagent -> entry with" 1338 "~n SaNode: ~p" 1339 "~n RegTree: ~p" 1340 "~n Mib: ~p", [SaNode, RegTree, Mib]), 1341 MA = whereis(snmp_master_agent), 1342 ?DBG("start_subagent -> MA: ~p", [MA]), 1343 MibDir = get(mib_dir), 1344 Mib1 = join(MibDir,Mib), 1345 %% BMK BMK 1346% case rpc:call(SaNode,snmp_supervisor,start_subagent,[MA,RegTree,[Mib1]]) of 1347 case rpc:call(SaNode, snmpa_supervisor, 1348 start_sub_agent, [MA, RegTree, [Mib1]]) of 1349 {ok, SA} -> 1350 ?DBG("start_subagent -> SA: ~p", [SA]), 1351 {ok, SA}; 1352 Error -> 1353 ?FAIL({subagent_start_failed, SaNode, Error, [MA, RegTree, Mib1]}) 1354 end. 1355 1356stop_subagent(SA) -> 1357 ?DBG("stop_subagent -> entry with" 1358 "~n SA: ~p", [SA]), 1359 %% BNK BMK 1360 %% rpc:call(node(SA), snmp_supervisor, stop_subagent, [SA]). 1361 rpc:call(node(SA), snmpa_supervisor, stop_sub_agent, [SA]). 1362 1363%%----------------------------------------------------------------- 1364%% This function takes care of the old OTP-SNMPEA-MIB. 1365%% Unfortunately, the testcases were written to use the data in the 1366%% internal tables, and these table are now obsolete and not used 1367%% by the agent. Therefore, we emulate them by using 1368%% OLD-SNMPEA-MIB, which uses the default impl. of all tables. 1369%% 1370%% These two rows must exist in intCommunityTable 1371%% {[147,214,36,45], "public", 2, readWrite}. 1372%% {[147,214,36,45], "standard trap", 2, read}. 1373%% (But with the manager's IP address) 1374%% 1375%%----------------------------------------------------------------- 1376init_old() -> 1377 snmpa_local_db:table_create_row(intCommunityTable, 1378 get(mip) ++ [6 | "public"], 1379 {get(mip), "public", 2, 2}), 1380 snmpa_local_db:table_create_row(intCommunityTable, 1381 get(mip) ++ [13 | "standard trap"], 1382 {get(mip), "standard trap", 2, 1}), 1383 snmpa_local_db:variable_set(intAgentIpAddress, [127,0,0,1]). 1384 1385 1386 1387simple(suite) -> []; 1388simple(Config) when list(Config) -> 1389 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 1390 1391 try_test(simple_standard_test). 1392 1393simple_2(X) -> simple(X). 1394 1395simple_bi(suite) -> []; 1396simple_bi(Config) when list(Config) -> 1397 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 1398 1399 put(vsn, v1), % First, try v1 manager 1400 try_test(simple_standard_test), 1401 1402 put(vsn, v2), % Then, try v2 manager 1403 try_test(simple_standard_test). 1404 1405simple_3(X) -> 1406 simple(X). 1407 1408big(suite) -> []; 1409big(Config) when list(Config) -> 1410 ?DBG("big -> entry", []), 1411 {SaNode, _MgrNode, _MibDir} = init_case(Config), 1412 1413 p("Starting subagent..."), 1414 ?line pong = net_adm:ping(SaNode), 1415 1416 ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), 1417 ?DBG("big -> SA: ~p", [SA]), 1418 ?line load_master("OLD-SNMPEA-MIB"), 1419 ?line init_old(), 1420 try_test(big_test), 1421 ?line stop_subagent(SA), 1422 ?line unload_master("OLD-SNMPEA-MIB"). 1423 1424big_2(X) -> big(X). 1425 1426big_3(X) -> big(X). 1427 1428 1429big2(suite) -> []; 1430big2(Config) when list(Config) -> 1431 %% This is exactly the same tests as 'big', but with the 1432 %% v2 equivalent of the mibs. 1433 {SaNode, _MgrNode, _MibDir} = init_case(Config), 1434 1435 p("Starting subagent..."), 1436 ?line pong = net_adm:ping(SaNode), 1437 1438 ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1-v2"), 1439 ?line load_master("OLD-SNMPEA-MIB-v2"), 1440 ?line init_old(), 1441 try_test(big_test), 1442 ?line stop_subagent(SA), 1443 ?line unload_master("OLD-SNMPEA-MIB-v2"). 1444 1445big2_2(X) -> big2(X). 1446 1447big2_3(X) -> big2(X). 1448 1449 1450multi_threaded(suite) -> []; 1451multi_threaded(Config) when list(Config) -> 1452 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 1453 1454 ?line load_master("Test1"), 1455 try_test(multi_threaded_test), 1456 ?line unload_master("Test1"). 1457 1458mt_trap(suite) -> []; 1459mt_trap(Config) when list(Config) -> 1460 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 1461 MA = whereis(snmp_master_agent), 1462 1463 ?line load_master("Test1"), 1464 ?line load_master("TestTrapv2"), 1465 try_test(mt_trap_test, [MA]), 1466 ?line unload_master("TestTrapv2"), 1467 ?line unload_master("Test1"). 1468 1469v2_types(suite) -> []; 1470v2_types(Config) when list(Config) -> 1471 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 1472 1473 ?line load_master("Test1"), 1474 try_test(types_v2_test), 1475 ?line unload_master("Test1"). 1476 1477v2_types_3(X) -> v2_types(X). 1478 1479 1480implied(suite) -> []; 1481implied(Config) when list(Config) -> 1482 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 1483 MA = whereis(snmp_master_agent), 1484 1485 ?line load_master("Test1"), 1486 try_test(implied_test,[MA]), 1487 ?line unload_master("Test1"). 1488 1489implied_3(X) -> implied(X). 1490 1491 1492sparse_table(suite) -> []; 1493sparse_table(Config) when list(Config) -> 1494 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 1495 1496 ?line load_master("Test1"), 1497 try_test(sparse_table_test), 1498 ?line unload_master("Test1"). 1499 1500sparse_table_2(X) -> sparse_table(X). 1501 1502sparse_table_3(X) -> sparse_table(X). 1503 1504cnt_64(suite) -> []; 1505cnt_64(Config) when list(Config) -> 1506 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 1507 MA = whereis(snmp_master_agent), 1508 1509 ?line load_master("Test1"), 1510 try_test(cnt_64_test, [MA]), 1511 ?line unload_master("Test1"). 1512 1513cnt_64_2(X) -> cnt_64(X). 1514 1515cnt_64_3(X) -> cnt_64(X). 1516 1517opaque(suite) -> []; 1518opaque(Config) when list(Config) -> 1519 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 1520 1521 ?line load_master("Test1"), 1522 try_test(opaque_test), 1523 ?line unload_master("Test1"). 1524 1525opaque_2(X) -> opaque(X). 1526 1527opaque_3(X) -> opaque(X). 1528 1529 1530change_target_addr_config(suite) -> []; 1531change_target_addr_config(Config) when list(Config) -> 1532 p("Testing changing target address config..."), 1533 ?LOG("change_target_addr_config -> entry",[]), 1534 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 1535 1536 put(sname,snmp_suite), 1537 put(verbosity,trace), 1538 1539 MA = whereis(snmp_master_agent), 1540 1541 ?LOG("change_target_addr_config -> load TestTrap",[]), 1542 ?line load_master("TestTrap"), 1543 1544 ?LOG("change_target_addr_config -> set trace verbosity for local_db",[]), 1545 ?line snmpa:verbosity(local_db,trace), 1546 1547 %% First send some traps that will arive att the original manager 1548 ?LOG("change_target_addr_config -> send trap",[]), 1549 try_test(ma_trap1, [MA]), 1550 1551 ?LOG("change_target_addr_config -> set silence verbosity for local_db",[]), 1552 ?line snmpa:verbosity(local_db,silence), 1553 1554 %% Start new dummy listener 1555 ?LOG("change_target_addr_config -> start dummy manager",[]), 1556 ?line {ok,Pid,NewPort} = dummy_manager_start(MA), 1557 1558 %% Reconfigure 1559 ?LOG("change_target_addr_config -> reconfigure",[]), 1560 AgentDir = ?config(agent_dir, Config), 1561 ?line rewrite_target_addr_conf(AgentDir, NewPort), 1562 ?line snmp_target_mib:reconfigure(AgentDir), 1563 1564 %% Send the trap again 1565 ?LOG("change_target_addr_config -> send trap again",[]), 1566 catch dummy_manager_send_trap2(Pid), 1567 1568 ?LOG("change_target_addr_config -> await trap ack",[]), 1569 catch dummy_manager_await_trap2_ack(), 1570 1571 ?LOG("change_target_addr_config -> stop dummy manager",[]), 1572 ?line ok = dummy_manager_stop(Pid), 1573 1574 ?LOG("change_target_addr_config -> reset target address config",[]), 1575 ?line reset_target_addr_conf(AgentDir), 1576 1577 ?LOG("change_target_addr_config -> unload TestTrap",[]), 1578 ?line unload_master("TestTrap"). 1579 1580 1581dummy_manager_start(MA) -> 1582 ?DBG("dummy_manager_start -> entry",[]), 1583 Pid = spawn(get(mgr_node), ?MODULE,dummy_manager_init,[self(),MA]), 1584 ?DBG("dummy_manager_start -> Pid: ~p",[Pid]), 1585 await_dummy_manager_started(Pid). 1586 1587await_dummy_manager_started(Pid) -> 1588 receive 1589 {dummy_manager_started,Pid,Port} -> 1590 ?DBG("dummy_manager_start -> acknowledge received with" 1591 "~n Port: ~p",[Port]), 1592 {ok,Pid,Port}; 1593 {'EXIT', Pid, Reason} -> 1594 {error, Pid, Reason}; 1595 O -> 1596 ?LOG("dummy_manager_start -> received unknown message:" 1597 "~n ~p",[O]), 1598 await_dummy_manager_started(Pid) 1599 end. 1600 1601dummy_manager_stop(Pid) -> 1602 ?DBG("dummy_manager_stop -> entry with Pid: ~p",[Pid]), 1603 Pid ! stop, 1604 receive 1605 {dummy_manager_stopping, Pid} -> 1606 ?DBG("dummy_manager_stop -> acknowledge received",[]), 1607 ok 1608 after 10000 -> 1609 ?ERR("dummy_manager_stop -> timeout",[]), 1610 timeout 1611 end. 1612 1613dummy_manager_send_trap2(Pid) -> 1614 ?DBG("dummy_manager_send_trap2 -> entry",[]), 1615 Pid ! {send_trap,testTrap2}. 1616 1617dummy_manager_await_trap2_ack() -> 1618 ?DBG("dummy_manager_await_trap2 -> entry",[]), 1619 receive 1620 {received_trap,Trap} -> 1621 ?LOG("dummy_manager_await_trap2 -> received trap: ~p",[Trap]), 1622 %% Note: 1623 %% Without this sleep the v2_inform_i testcase failes! There 1624 %% is no relation between these two test cases as far as I 1625 %% able to figure out... 1626 sleep(60000), 1627 ok; 1628 O -> 1629 ?ERR("dummy_manager_await_trap2 -> unexpected message: ~p",[O]), 1630 ok 1631 after 10000 -> 1632 ?ERR("dummy_manager_await_trap2 -> timeout",[]), 1633 timeout 1634 end. 1635 1636dummy_manager_init(Parent,MA) -> 1637 ?DBG("dummy_manager_init -> entry with" 1638 "~n Parent: ~p" 1639 "~n MA: ~p",[Parent,MA]), 1640 {ok,S} = gen_udp:open(0,[{recbuf,65535}]), 1641 ?DBG("dummy_manager_init -> S: ~p",[S]), 1642 {ok,Port} = inet:port(S), 1643 ?DBG("dummy_manager_init -> Port: ~p",[Port]), 1644 Parent ! {dummy_manager_started,self(),Port}, 1645 dummy_manager_loop(Parent,S,MA). 1646 1647dummy_manager_loop(P,S,MA) -> 1648 ?LOG("dummy_manager_loop -> ready for receive",[]), 1649 receive 1650 {send_trap,Trap} -> 1651 ?LOG("dummy_manager_loop -> received trap send request" 1652 "~n Trap: ~p",[Trap]), 1653 snmpa:send_trap(MA, Trap, "standard trap"), 1654 dummy_manager_loop(P,S,MA); 1655 {udp, _UdpId, Ip, UdpPort, Bytes} -> 1656 ?LOG("dummy_manager_loop -> received upd message" 1657 "~n from: ~p:~p" 1658 "~n size: ~p", 1659 [Ip, UdpPort, dummy_manager_message_sz(Bytes)]), 1660 R = dummy_manager_handle_message(Bytes), 1661 ?DBG("dummy_manager_loop -> R: ~p",[R]), 1662 P ! R, 1663 dummy_manager_loop(P,S,MA); 1664 stop -> 1665 ?DBG("dummy_manager_loop -> received stop request",[]), 1666 P ! {dummy_manager_stopping, self()}, 1667 gen_udp:close(S), 1668 exit(normal); 1669 O -> 1670 ?LOG("dummy_manager_loop -> received unknown message:" 1671 "~n ~p",[O]), 1672 dummy_manager_loop(P,S,MA) 1673 end. 1674 1675dummy_manager_message_sz(B) when binary(B) -> 1676 size(B); 1677dummy_manager_message_sz(L) when list(L) -> 1678 length(L); 1679dummy_manager_message_sz(_) -> 1680 undefined. 1681 1682dummy_manager_handle_message(Bytes) -> 1683 case (catch snmp_pdus:dec_message(Bytes)) of 1684 {'EXIT',Reason} -> 1685 ?ERR("dummy_manager_handle_message -> " 1686 "failed decoding message only:~n ~p",[Reason]), 1687 {error,Reason}; 1688 M -> 1689 ?DBG("dummy_manager_handle_message -> decoded message:" 1690 "~n ~p",[M]), 1691 {received_trap,M} 1692 end. 1693 1694 1695api(suite) -> []; 1696api(Config) when list(Config) -> 1697 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 1698 1699 ?line load_master("OLD-SNMPEA-MIB"), 1700 ?line init_old(), 1701 try_test(api_test, [node()]), 1702 ?line unload_master("OLD-SNMPEA-MIB"). 1703 1704api_2(X) -> api(X). 1705 1706api_3(X) -> api(X). 1707 1708 1709subagent(suite) -> []; 1710subagent(Config) when list(Config) -> 1711 {SaNode, _MgrNode, MibDir} = init_case(Config), 1712 1713 ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), 1714 try_test(load_test_sa), 1715 1716 p("Testing unregister subagent..."), 1717 MA = whereis(snmp_master_agent), 1718 rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), 1719 try_test(unreg_test), 1720 1721 p("Loading previous subagent mib in master and testing..."), 1722 ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas1"]), 1723 try_test(load_test), 1724 1725 p("Unloading previous subagent mib in master and testing..."), 1726 ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas1"]), 1727 try_test(unreg_test), 1728 p("Testing register subagent..."), 1729 rpc:call(SaNode, snmp, register_subagent, 1730 [MA, ?klas1, SA]), 1731 try_test(load_test_sa), 1732 1733 ?line stop_subagent(SA), 1734 try_test(unreg_test). 1735 1736subagent_2(X) -> subagent(X). 1737 1738subagent_3(X) -> subagent(X). 1739 1740 1741mnesia(suite) -> []; 1742mnesia(Config) when list(Config) -> 1743 {SaNode, _MgrNode, _MibDir} = init_case(Config), 1744 1745 p("Starting subagent with mnesia impl..."), 1746 {ok, SA} = start_subagent(SaNode, ?klas2, "Klas2"), 1747 ?line load_master("OLD-SNMPEA-MIB"), 1748 ?line init_old(), 1749 1750 try_test(big_test_2), 1751 1752 p("Testing unregister subagent..."), 1753 MA = whereis(snmp_master_agent), 1754 rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), 1755 try_test(unreg_test), 1756 ?line unload_master("OLD-SNMPEA-MIB"), 1757 ?line stop_subagent(SA). 1758 1759mnesia_2(X) -> mnesia(X). 1760 1761mnesia_3(X) -> mnesia(X). 1762 1763 1764 1765mul_cases() -> 1766[mul_get, mul_get_err, mul_next, mul_next_err, 1767 mul_set_err]. 1768 1769 1770multiple_reqs_3(_X) -> 1771 {req, [], {conf, init_mul, mul_cases_3(), finish_mul}}. 1772 1773 1774mul_cases_2() -> 1775[mul_get_2, mul_get_err_2, mul_next_2, mul_next_err_2, 1776 mul_set_err_2]. 1777 1778 1779mul_cases_3() -> 1780 [mul_get_3, mul_get_err_3, mul_next_3, mul_next_err_3, mul_set_err_3]. 1781 1782 1783init_mul(Config) when list(Config) -> 1784 {SaNode, _MgrNode, _MibDir} = init_case(Config), 1785 1786 ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), 1787 ?line load_master("OLD-SNMPEA-MIB"), 1788 ?line init_old(), 1789 [{mul_sub, SA} | Config]. 1790 1791finish_mul(Config) when list(Config) -> 1792 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 1793 1794 SA = ?config(mul_sub, Config), 1795 1796 ?line unload_master("OLD-SNMPEA-MIB"), 1797 ?line stop_subagent(SA), 1798 lists:keydelete(mul_sub, 1, Config). 1799 1800mul_get(suite) -> []; 1801mul_get(Config) when list(Config) -> 1802 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 1803 1804 p("Testing multiple get..."), 1805 try_test(do_mul_get). 1806 1807mul_get_2(X) -> mul_get(X). 1808 1809mul_get_3(X) -> mul_get(X). 1810 1811 1812mul_get_err(suite) -> []; 1813mul_get_err(Config) when list(Config) -> 1814 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 1815 1816 p("Testing multiple get with error..."), 1817 try_test(do_mul_get_err). 1818 1819mul_get_err_2(X) -> mul_get_err(X). 1820 1821mul_get_err_3(X) -> mul_get_err(X). 1822 1823 1824mul_next(suite) -> []; 1825mul_next(Config) when list(Config) -> 1826 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 1827 1828 p("Testing multiple next..."), 1829 try_test(do_mul_next). 1830 1831mul_next_2(X) -> mul_next(X). 1832 1833mul_next_3(X) -> mul_next(X). 1834 1835 1836mul_next_err(suite) -> []; 1837mul_next_err(Config) when list(Config) -> 1838 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 1839 1840 p("Testing multiple next..."), 1841 try_test(do_mul_next_err). 1842 1843mul_next_err_2(X) -> mul_next_err(X). 1844 1845mul_next_err_3(X) -> mul_next_err(X). 1846 1847 1848mul_set(suite) -> []; 1849mul_set(Config) when list(Config) -> 1850 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 1851 1852 p("Testing multiple set..."), 1853 try_test(do_mul_set). 1854 1855mul_set_2(X) -> mul_set(X). 1856 1857mul_set_3(X) -> mul_set(X). 1858 1859 1860mul_set_err(suite) -> []; 1861mul_set_err(Config) when list(Config) -> 1862 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 1863 1864 p("Testing multiple set with error..."), 1865 try_test(do_mul_set_err). 1866 1867mul_set_err_2(X) -> mul_set_err(X). 1868 1869mul_set_err_3(X) -> mul_set_err(X). 1870 1871 1872sa_register(suite) -> []; 1873sa_register(Config) when list(Config) -> 1874 ?DBG("sa_register -> entry", []), 1875 {SaNode, _MgrNode, MibDir} = init_case(Config), 1876 1877 ?DBG("sa_register -> start subagent", []), 1878 ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), 1879 1880 ?DBG("sa_register -> unregister subagent", []), 1881 p("Testing unregister subagent (2)..."), 1882 MA = whereis(snmp_master_agent), 1883 rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), 1884 try_test(unreg_test), 1885 1886 p("Loading SA-MIB..."), 1887 ?DBG("sa_register -> unload mibs", []), 1888 snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), 1889 ?DBG("sa_register -> unload mibs", []), 1890 snmpa:load_mibs(SA, [MibDir ++ "SA-MIB"]), 1891 ?DBG("sa_register -> register subagent", []), 1892 rpc:call(SaNode, snmp, register_subagent, [MA,?sa,SA]), 1893 try_test(sa_mib), 1894 1895 ?DBG("sa_register -> stop subagent", []), 1896 ?line stop_subagent(SA). 1897 1898sa_register_2(X) -> sa_register(X). 1899 1900sa_register_3(X) -> sa_register(X). 1901 1902 1903v1_trap(suite) -> []; 1904v1_trap(Config) when list(Config) -> 1905 {SaNode, _MgrNode, _MibDir} = init_case(Config), 1906 1907 ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), 1908 1909 p("Testing trap sending from master agent..."), 1910 MA = whereis(snmp_master_agent), 1911 1912 ?line load_master("TestTrap"), 1913 ?line load_master("TestTrapv2"), 1914 1915 try_test(ma_trap1, [MA]), 1916 try_test(ma_trap2, [MA]), 1917 try_test(ma_v2_2_v1_trap, [MA]), 1918 try_test(ma_v2_2_v1_trap2, [MA]), 1919 1920 p("Testing trap sending from subagent..."), 1921 try_test(sa_trap1, [SA]), 1922 try_test(sa_trap2, [SA]), 1923 try_test(sa_trap3, [SA]), 1924 1925 ?line unload_master("TestTrap"), 1926 ?line unload_master("TestTrapv2"), 1927 1928 ?line stop_subagent(SA). 1929 1930v2_trap(suite) -> []; 1931v2_trap(Config) when list(Config) -> 1932 {SaNode, _MgrNode, _MibDir} = init_case(Config), 1933 1934 ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), 1935 1936 p("Testing trap sending from master agent..."), 1937 MA = whereis(snmp_master_agent), 1938 1939 ?line load_master("TestTrap"), 1940 ?line load_master("TestTrapv2"), 1941 1942 1943 try_test(ma_v2_trap1, [MA]), 1944 try_test(ma_v2_trap2, [MA]), 1945 try_test(ma_v1_2_v2_trap, [MA]), 1946 try_test(ma_v1_2_v2_trap2, [MA]), 1947 1948 try_test(sa_mib), 1949 p("Testing trap sending from subagent..."), 1950 try_test(sa_v1_2_v2_trap1, [SA]), 1951 try_test(sa_v1_2_v2_trap2, [SA]), 1952 try_test(sa_v1_2_v2_trap3, [SA]), 1953 1954 ?line unload_master("TestTrap"), 1955 ?line unload_master("TestTrapv2"), 1956 1957 ?line stop_subagent(SA). 1958 1959v3_trap(X) -> 1960 v2_trap(X). 1961 1962 1963v3_inform(_X) -> 1964 %% v2_inform(X). 1965 {req, [], {conf, init_v3_inform, [v3_inform_i], finish_v3_inform}}. 1966 1967init_v2_inform(Config) when list(Config) -> 1968 _Dir = ?config(agent_dir, Config), 1969% snmp_internal_mib:configure(Dir), 1970 Config. 1971 1972init_v3_inform(X) -> 1973 init_v2_inform(X). 1974 1975finish_v2_inform(Config) when list(Config) -> 1976 _Dir = ?config(agent_dir, Config), 1977% snmp_internal_mib:configure(Dir), 1978 Config. 1979 1980finish_v3_inform(X) -> 1981 finish_v2_inform(X). 1982 1983 1984 1985v2_inform_i(suite) -> []; 1986v2_inform_i(Config) when list(Config) -> 1987 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 1988 1989 p("Testing inform sending from master agent... NOTE! This test\ntakes a " 1990 "few minutes (5) to complete."), 1991 MA = whereis(snmp_master_agent), 1992 1993 ?line load_master("TestTrap"), 1994 ?line load_master("TestTrapv2"), 1995 1996 try_test(ma_v2_inform1, [MA]), 1997 1998 ?line unload_master("TestTrap"), 1999 ?line unload_master("TestTrapv2"). 2000 2001v3_inform_i(X) -> v2_inform_i(X). 2002 2003 2004sa_error(suite) -> []; 2005sa_error(Config) when list(Config) -> 2006 {SaNode, _MgrNode, _MibDir} = init_case(Config), 2007 2008 ?line load_master("OLD-SNMPEA-MIB"), 2009 ?line init_old(), 2010 ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), 2011 2012 p("Testing sa bad value (is_set_ok)..."), 2013 try_test(sa_errs_bad_value), 2014 2015 p("Testing sa gen err (set)..."), 2016 try_test(sa_errs_gen_err), 2017 2018 p("Testing too big..."), 2019 try_test(sa_too_big), 2020 2021 ?line unload_master("OLD-SNMPEA-MIB"), 2022 stop_subagent(SA). 2023 2024sa_error_2(X) -> sa_error(X). 2025 2026sa_error_3(X) -> sa_error(X). 2027 2028 2029next_across_sa(suite) -> []; 2030next_across_sa(Config) when list(Config) -> 2031 {SaNode, _MgrNode, MibDir} = init_case(Config), 2032 MA = whereis(snmp_master_agent), 2033 2034 ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), 2035 2036 p("Loading another subagent mib..."), 2037 ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas1"]), 2038 2039 rpc:call(SaNode, snmp, register_subagent, [MA, ?klas1, SA]), 2040 try_test(load_test_sa), 2041 2042 p("Testing next across subagent (endOfMibView from SA)..."), 2043 try_test(next_across_sa), 2044 2045 p("Unloading mib"), 2046 snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), 2047 rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), 2048 try_test(unreg_test), 2049 2050 p("Starting another subagent"), 2051 ?line {ok, SA2} = start_subagent(SaNode, ?klas1, "Klas1"), 2052 p("Testing next across subagent (wrong prefix from SA)..."), 2053 try_test(next_across_sa), 2054 2055 stop_subagent(SA), 2056 stop_subagent(SA2). 2057 2058next_across_sa_2(X) -> next_across_sa(X). 2059 2060next_across_sa_3(X) -> next_across_sa(X). 2061 2062 2063undo(suite) -> []; 2064undo(Config) when list(Config) -> 2065 {SaNode, _MgrNode, MibDir} = init_case(Config), 2066 MA = whereis(snmp_master_agent), 2067 2068 ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), 2069 2070 p("Testing undo phase at master agent..."), 2071 ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas3"]), 2072 ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas4"]), 2073 try_test(undo_test), 2074 try_test(api_test2), 2075 ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas3"]), 2076 2077 p("Testing bad return values from instrum. funcs..."), 2078 try_test(bad_return), 2079 2080 ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas4"]), 2081 2082 p("Testing undo phase at subagent..."), 2083 ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas3"]), 2084 ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas4"]), 2085 ?line ok = snmpa:register_subagent(MA, ?klas3, SA), 2086 ?line ok = snmpa:register_subagent(MA, ?klas4, SA), 2087 try_test(undo_test), 2088 try_test(api_test3), 2089 2090 p("Testing undo phase across master/subagents..."), 2091 try_test(undo_test), 2092 try_test(api_test3), 2093 stop_subagent(SA). 2094 2095undo_2(X) -> undo(X). 2096 2097undo_3(X) -> undo(X). 2098 2099%% Req. Test2 2100v1_processing(suite) -> []; 2101v1_processing(Config) when list(Config) -> 2102 ?DBG("v1_processing -> entry", []), 2103 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 2104 2105 ?line load_master("Test2"), 2106 try_test(v1_proc), 2107 ?line unload_master("Test2"). 2108 2109%% Req. Test2 2110v2_processing(suite) -> []; 2111v2_processing(Config) when list(Config) -> 2112 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 2113 2114 ?line load_master("Test2"), 2115 try_test(v2_proc), 2116 ?line unload_master("Test2"). 2117 2118%% Req. Test2 2119v3_processing(suite) -> []; 2120v3_processing(Config) when list(Config) -> 2121 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 2122 2123 ?line load_master("Test2"), 2124 try_test(v2_proc), % same as v2! 2125 ?line unload_master("Test2"). 2126 2127 2128%% We'll try get/set/trap and inform for all the auth & priv protocols. 2129%% For informs, the mgr is auth-engine. The agent has to sync. This is 2130%% accomplished by the first inform sent. That one will generate a 2131%% report, which makes it in sync. The notification-generating 2132%% application times out, and send again. This time it'll work. 2133 2134v3_crypto_basic(suite) -> []; 2135v3_crypto_basic(_Config) -> 2136 EID = [0,0,0,0,0,0,0,0,0,0,0,2], 2137 %% From rfc2274 appendix A.3.1 2138 ?line KMd5_1 = snmp:passwd2localized_key(md5, "maplesyrup", EID), 2139 ?line [16#52,16#6f,16#5e,16#ed,16#9f,16#cc,16#e2,16#6f, 2140 16#89,16#64,16#c2,16#93,16#07,16#87,16#d8,16#2b] = 2141 KMd5_1, 2142 %% From rfc2274 appendix A.3.2 2143 ?line KSHA_1 = snmp:passwd2localized_key(sha, "maplesyrup", EID), 2144 ?line [16#66,16#95,16#fe,16#bc,16#92,16#88,16#e3,16#62,16#82,16#23, 2145 16#5f,16#c7,16#15,16#1f,16#12,16#84,16#97,16#b3,16#8f,16#3f] = 2146 KSHA_1, 2147 %% From rfc2274, appendix A.5.1 2148 ?line KMd5_2 = snmp:passwd2localized_key(md5, "newsyrup", EID), 2149 ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, 2150 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, 2151 16#88,16#05,16#61,16#51,16#41,16#67,16#6c,16#c9, 2152 16#19,16#61,16#74,16#e7,16#42,16#a3,16#25,16#51] = 2153 snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2, 16, 2154 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), 2155 %% From rfc2274, appendix A.5.2 2156 ?line KSHA_2 = snmp:passwd2localized_key(sha, "newsyrup", EID), 2157 ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, 2158 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, 2159 16#00,16#00,16#00,16#00,16#9c,16#10,16#17,16#f4, 2160 16#fd,16#48,16#3d,16#2d,16#e8,16#d5,16#fa,16#db, 2161 16#f8,16#43,16#92,16#cb,16#06,16#45,16#70,16#51] = 2162 snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2, 20, 2163 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), 2164 KSHA_1t = lists:sublist(KSHA_1, 16), 2165 KSHA_2t = lists:sublist(KSHA_2, 16), 2166 ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, 2167 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, 2168 16#7e,16#f8,16#d8,16#a4,16#c9,16#cd,16#b2,16#6b, 2169 16#47,16#59,16#1c,16#d8,16#52,16#ff,16#88,16#b5] = 2170 snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1t, KSHA_2t, 16, 2171 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), 2172 2173 %% Try with correct random 2174 ?line Kc1 = snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2), 2175 ?line KMd5_2 = snmp_user_based_sm_mib:extract_new_key(md5, KMd5_1, Kc1), 2176 ?line Kc2 = snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2), 2177 ?line KSHA_2 = snmp_user_based_sm_mib:extract_new_key(sha, KSHA_1, Kc2), 2178 ok. 2179 2180 2181 2182v3_md5_auth(suite) -> []; 2183v3_md5_auth(Config) when list(Config) -> 2184 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 2185 p("Testing MD5 authentication...takes a few seconds..."), 2186 2187 AgentDir = ?config(agent_dir, Config), 2188 ?line rewrite_target_params_conf(AgentDir, "authMD5", authNoPriv), 2189 ?line snmp_target_mib:reconfigure(AgentDir), 2190 2191 MA = whereis(snmp_master_agent), 2192 2193 ?line load_master("Test2"), 2194 ?line load_master("TestTrap"), 2195 ?line load_master("TestTrapv2"), 2196 2197 try_test(v3_sync, [[{v2_proc, []}, 2198 {ma_v2_trap1, [MA]}, 2199 {v3_inform_sync, [MA]}]], 2200 [{sec_level, authNoPriv}, {user, "authMD5"}]), 2201 2202 ?line unload_master("TestTrapv2"), 2203 ?line unload_master("TestTrap"), 2204 ?line unload_master("Test2"), 2205 ?line reset_target_params_conf(AgentDir). 2206 2207v3_sha_auth(suite) -> []; 2208v3_sha_auth(Config) when list(Config) -> 2209 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 2210 p("Testing SHA authentication...takes a few seconds..."), 2211 2212 AgentDir = ?config(agent_dir, Config), 2213 ?line rewrite_target_params_conf(AgentDir, "authSHA", authNoPriv), 2214 ?line snmp_target_mib:reconfigure(AgentDir), 2215 2216 MA = whereis(snmp_master_agent), 2217 2218 ?line load_master("Test2"), 2219 ?line load_master("TestTrap"), 2220 ?line load_master("TestTrapv2"), 2221 2222 try_test(v3_sync, [[{v2_proc, []}, 2223 {ma_v2_trap1, [MA]}, 2224 {v3_inform_sync, [MA]}]], 2225 [{sec_level, authNoPriv}, {user, "authSHA"}]), 2226 2227 ?line unload_master("TestTrapv2"), 2228 ?line unload_master("TestTrap"), 2229 ?line unload_master("Test2"), 2230 ?line reset_target_params_conf(AgentDir). 2231 2232v3_des_priv(suite) -> []; 2233v3_des_priv(Config) when list(Config) -> 2234 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 2235 p("Testing DES encryption...takes a few seconds..."), 2236 2237 AgentDir = ?config(agent_dir, Config), 2238 ?line rewrite_target_params_conf(AgentDir, "privDES", authPriv), 2239 ?line snmp_target_mib:reconfigure(AgentDir), 2240 2241 MA = whereis(snmp_master_agent), 2242 2243 ?line load_master("Test2"), 2244 ?line load_master("TestTrap"), 2245 ?line load_master("TestTrapv2"), 2246 2247 try_test(v3_sync, [[{v2_proc, []}, 2248 {ma_v2_trap1, [MA]}, 2249 {v3_inform_sync, [MA]}]], 2250 [{sec_level, authPriv}, {user, "privDES"}]), 2251 2252 ?line unload_master("TestTrapv2"), 2253 ?line unload_master("TestTrap"), 2254 ?line unload_master("Test2"), 2255 ?line reset_target_params_conf(AgentDir). 2256 2257%% -define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). 2258 2259%% Make sure mgr is in sync with agent 2260v3_sync(Funcs) -> 2261 ?DBG("v3_sync -> entry with Funcs: ~p",[Funcs]), 2262 g([[sysDescr, 0]]), 2263 expect(432, report, [{?usmStatsNotInTimeWindows_instance, any}]), 2264 g([[sysDescr, 0]]), 2265 expect(433, [{[sysDescr,0], any}]), 2266 lists:foreach(fun({Func, Args}) -> apply(?MODULE, Func, Args) end, Funcs). 2267 2268v3_inform_sync(MA) -> 2269 ?DBG("v3_sync -> entry with MA: ~p => Send notification",[MA]), 2270 ?line snmpa:send_notification(MA, testTrapv22, no_receiver, 2271 "standard inform", []), 2272 %% Make sure agent is in sync with mgr... 2273 ?DBG("v3_sync -> wait some time: ",[]), 2274 sleep(20000), % more than 1500*10 in target_addr.conf 2275 ?DBG("v3_sync -> await response",[]), 2276 ?line expect(1, {inform, true}, 2277 [{[sysUpTime, 0], any}, 2278 {[snmpTrapOID, 0], ?system ++ [0,1]}]). 2279 2280 2281v2_caps(suite) -> []; 2282v2_caps(Config) when list(Config) -> 2283 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 2284 2285 try_test(v2_caps_i, [node()]). 2286 2287v2_caps_3(X) -> v2_caps(X). 2288 2289 2290v2_caps_i(Node) -> 2291 ?line Idx = rpc:call(Node, snmp, add_agent_caps, [[1,2,3,4,5], "test cap"]), 2292 g([[sysORID, Idx], [sysORDescr, Idx]]), 2293 ?line expect(1, [{[sysORID, Idx], [1,2,3,4,5]}, 2294 {[sysORDescr, Idx], "test cap"}]), 2295 ?line rpc:call(Node, snmp, del_agent_caps, [Idx]), 2296 g([[sysORID, Idx]]), 2297 ?line expect(2, [{[sysORID, Idx], noSuchInstance}]). 2298 2299 2300%% Req. Test2 2301v1_proc() -> 2302 ?DBG("v1_proc -> entry", []), 2303 %% According to RFC1157. 2304 %% Template: <Section>:<list no> 2305 v1_get_p(), 2306 v1_get_next_p(), 2307 v1_set_p(). 2308 2309 2310v1_get_p() -> 2311 %% 4.1.2:1 2312 g([[test2]]), 2313 ?line expect(10, noSuchName, 1, [{[test2], 'NULL'}]), 2314 g([[tDescr]]), 2315 ?line expect(11, noSuchName, 1, [{[tDescr], 'NULL'}]), 2316 g([[tDescr2,0]]), 2317 ?line expect(12, noSuchName, 1, [{[tDescr2,0], 'NULL'}]), 2318 g([[tDescr3,0]]), 2319 ?line expect(131, noSuchName, 1, [{[tDescr3,0], 'NULL'}]), 2320 g([[tDescr4,0]]), 2321 ?line expect(132, noSuchName, 1, [{[tDescr4,0], 'NULL'}]), 2322 g([[sysDescr, 0], [tDescr,0]]), % Outside mibview 2323 ?line expect(14, noSuchName, 2, [{[sysDescr, 0], 'NULL'}, 2324 {[tDescr,0], 'NULL'}]), 2325 g([[sysDescr,3]]), 2326 ?line expect(15, noSuchName, 1, [{[sysDescr, 3], 'NULL'}]), 2327 2328 %% 4.1.2:2 2329 g([[tTable]]), 2330 ?line expect(20, noSuchName, 1, [{[tTable], 'NULL'}]), 2331 g([[tEntry]]), 2332 ?line expect(21, noSuchName, 1, [{[tEntry], 'NULL'}]), 2333 2334 %% 4.1.2:3 2335 g([[tTooBig, 0]]), 2336 ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), 2337 2338 %% 4.1.2:4 2339 g([[tGenErr1, 0]]), 2340 ?line expect(40, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), 2341 g([[tGenErr2, 0]]), 2342 ?line expect(41, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), 2343 g([[sysDescr, 0], [tGenErr3, 0]]), 2344 ?line expect(42, genErr, 2, [{[sysDescr, 0], 'NULL'}, 2345 {[tGenErr3, 0], 'NULL'}]). 2346 2347 2348v1_get_next_p() -> 2349 %% 4.1.3:1 2350 gn([[1,3,7,1]]), 2351 ?line expect(10, noSuchName, 1, [{[1,3,7,1], 'NULL'}]), 2352 gn([[tDescr2]]), 2353 ?line expect(11, tooBig, 0, any), 2354 2355 %% 4.1.3:2 2356 gn([[tTooBig]]), 2357 io:format("We currently don't handle tooBig correct!!!\n"), 2358% ?line expect(20, tooBig, 0, [{[tTooBig], 'NULL'}]), 2359 ?line expect(20, tooBig, 0, any), 2360 2361 %% 4.1.3:3 2362 gn([[tGenErr1]]), 2363% ?line expect(40, genErr, 1, [{[tGenErr1], 'NULL'}]), 2364 ?line expect(40, genErr, 1, any), 2365 gn([[tGenErr2]]), 2366% ?line expect(41, genErr, 1, [{[tGenErr2], 'NULL'}]), 2367 ?line expect(41, genErr, 1, any), 2368 gn([[sysDescr], [tGenErr3]]), 2369% ?line expect(42, genErr, 2, [{[sysDescr], 'NULL'}, 2370% {[tGenErr3], 'NULL'}]). 2371 ?line expect(42, genErr, 2, any). 2372 2373v1_set_p() -> 2374 %% 4.1.5:1 2375 s([{[1,3,7,0], i, 4}]), 2376 ?line expect(10, noSuchName, 1, [{[1,3,7,0], 4}]), 2377 s([{[tDescr,0], s, "outside mibview"}]), 2378 ?line expect(11, noSuchName, 1, [{[tDescr,0], "outside mibview"}]), 2379 s([{[tDescr3,0], s, "read-only"}]), 2380 ?line expect(12, noSuchName, 1, [{[tDescr3,0], "read-only"}]), 2381 s([{[tDescr3], s, "noSuchObject"}]), 2382 ?line expect(13, noSuchName, 1, [{[tDescr3], "noSuchObject"}]), 2383 s([{[tDescr3,1], s, "noSuchInstance"}]), 2384 ?line expect(14, noSuchName, 1, [{[tDescr3,1], "noSuchInstance"}]), 2385 s([{[tDescr2,0], s, "inconsistentName"}]), 2386 ?line expect(15, noSuchName, 1, [{[tDescr2,0], "inconsistentName"}]), 2387 2388 %% 4.1.5:2 2389 s([{[tDescr2, 0], i, 4}]), 2390 ?line expect(20, badValue, 1, [{[tDescr2, 0], 4}]), 2391 s([{[tDescr2, 0], s, "badValue"}]), 2392 ?line expect(21, badValue, 1, [{[tDescr2, 0], "badValue"}]), 2393 2394 %% 4.1.5:3 2395 %% The standard is quite incorrect here. The resp pdu was too big. In 2396 %% the resp pdu, we have the original vbs. In the tooBig pdu we still 2397 %% have to original vbs => the tooBig pdu is too big as well!!! It 2398 %% may not get it to the manager, unless the agent uses 'NULL' instead 2399 %% of the std-like original value. 2400 s([{[tTooBig, 0], s, ?tooBigStr}]), 2401 %% according to std: 2402% ?line expect(30, tooBig, 0, [{[tTooBig, 0], ?tooBigStr}]), 2403 ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), 2404 2405 %% 4.1.5:4 2406 s([{[tDescr2, 0], s, "is_set_ok_fail"}]), 2407 ?line expect(40, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]), 2408 s([{[tDescr2, 0], s, "commit_fail"}]), 2409 ?line expect(41, genErr, 1, [{[tDescr2, 0], "commit_fail"}]). 2410 2411%% Req. Test2 2412v2_proc() -> 2413 %% According to RFC1905. 2414 %% Template: <Section>:<list no> 2415 ?DBG("v2_proc -> entry",[]), 2416 v2_get_p(), 2417 v2_get_next_p(), 2418 v2_get_bulk_p(), 2419 v2_set_p(). 2420 2421v2_get_p() -> 2422 %% 4.2.1:2 2423 ?DBG("v2_get_p -> entry",[]), 2424 g([[test2]]), 2425 ?line expect(10, [{[test2], noSuchObject}]), 2426 g([[tDescr]]), 2427 ?line expect(11, [{[tDescr], noSuchObject}]), 2428 g([[tDescr4,0]]), 2429 ?line expect(12, [{[tDescr4,0], noSuchObject}]), 2430 g([[sysDescr, 0], [tDescr,0]]), % Outside mibview 2431 ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}, 2432 {[tDescr,0], noSuchObject}]), 2433 g([[tTable]]), 2434 ?line expect(14, [{[tTable], noSuchObject}]), 2435 g([[tEntry]]), 2436 ?line expect(15, [{[tEntry], noSuchObject}]), 2437 2438 %% 4.2.1:3 2439 g([[tDescr2,0]]), %% instrum ret noSuchName!!! 2440 ?line expect(20, [{[tDescr2,0], noSuchInstance}]), 2441 g([[tDescr3,0]]), 2442 ?line expect(21, [{[tDescr3,0], noSuchInstance}]), 2443 g([[sysDescr,3]]), 2444 ?line expect(22, [{[sysDescr, 3], noSuchInstance}]), 2445 g([[tIndex,1]]), 2446 ?line expect(23, [{[tIndex, 1], noSuchInstance}]), 2447 2448 %% 4.2.1 - any other error: genErr 2449 g([[tGenErr1, 0]]), 2450 ?line expect(30, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), 2451 g([[tGenErr2, 0]]), 2452 ?line expect(31, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), 2453 g([[sysDescr, 0], [tGenErr3, 0]]), 2454 ?line expect(32, genErr, 2, [{[sysDescr, 0], 'NULL'}, 2455 {[tGenErr3, 0], 'NULL'}]), 2456 2457 %% 4.2.1 - tooBig 2458 g([[tTooBig, 0]]), 2459 ?line expect(40, tooBig, 0, []). 2460 2461 2462v2_get_next_p() -> 2463 %% 4.2.2:2 2464 ?DBG("v2_get_next_p -> entry",[]), 2465 gn([[1,3,7,1]]), 2466 ?line expect(10, [{[1,3,7,1], endOfMibView}]), 2467 gn([[sysDescr], [1,3,7,1]]), 2468 ?line expect(11, [{[sysDescr, 0], "Erlang SNMP agent"}, 2469 {[1,3,7,1], endOfMibView}]), 2470 gn([[tCnt2, 1]]), 2471 ?line expect(12, [{[tCnt2,2], 100}]), 2472 gn([[tCnt2, 2]]), 2473 ?line expect(12, [{[tCnt2,2], endOfMibView}]), 2474 2475 %% 4.2.2 - any other error: genErr 2476 gn([[tGenErr1]]), 2477 ?line expect(20, genErr, 1, [{[tGenErr1], 'NULL'}]), 2478 gn([[tGenErr2]]), 2479 ?line expect(21, genErr, 1, [{[tGenErr2], 'NULL'}]), 2480 gn([[sysDescr], [tGenErr3]]), 2481 ?line expect(22, genErr, 2, [{[sysDescr], 'NULL'}, 2482 {[tGenErr3], 'NULL'}]), 2483 2484 %% 4.2.2 - tooBig 2485 gn([[tTooBig]]), 2486 ?line expect(20, tooBig, 0, []). 2487 2488v2_get_bulk_p() -> 2489 %% 4.2.3 2490 ?DBG("v2_get_bulk_p -> entry",[]), 2491 gb(1, 1, []), 2492 ?line expect(10, []), 2493 gb(-1, 1, []), 2494 ?line expect(11, []), 2495 gb(-1, -1, []), 2496 ?line expect(12, []), 2497 gb(-1, -1, []), 2498 ?line expect(13, []), 2499 gb(2, 0, [[sysDescr], [1,3,7,1]]), 2500 ?line expect(14, [{[sysDescr, 0], "Erlang SNMP agent"}, 2501 {[1,3,7,1], endOfMibView}]), 2502 gb(1, 2, [[sysDescr], [1,3,7,1]]), 2503 ?line expect(15, [{[sysDescr, 0], "Erlang SNMP agent"}, 2504 {[1,3,7,1], endOfMibView}]), 2505 gb(0, 2, [[sysDescr], [1,3,7,1]]), 2506 ?line expect(16, [{[sysDescr, 0], "Erlang SNMP agent"}, 2507 {[1,3,7,1], endOfMibView}, 2508 {[sysObjectID, 0], [1,2,3]}, 2509 {[1,3,7,1], endOfMibView}]), 2510 2511 gb(2, 2, [[sysDescr], [1,3,7,1], [sysDescr], [1,3,7,1]]), 2512 ?line expect(17, [{[sysDescr, 0], "Erlang SNMP agent"}, 2513 {[1,3,7,1], endOfMibView}, 2514 {[sysDescr, 0], "Erlang SNMP agent"}, 2515 {[1,3,7,1], endOfMibView}, 2516 {[sysObjectID, 0], [1,2,3]}, 2517 {[1,3,7,1], endOfMibView}]), 2518 2519 gb(1, 2, [[sysDescr], [sysDescr], [tTooBig]]), 2520 ?line expect(18, [{[sysDescr, 0], "Erlang SNMP agent"}, 2521 {[sysDescr, 0], "Erlang SNMP agent"}]), 2522 2523 gb(1,12, [[tDescr2], [sysDescr]]), % next one after tDescr2 is tTooBig. 2524 ?line expect(19, []), 2525 2526 gb(2,2, [[sysDescr], [sysObjectID], [tGenErr1], [sysDescr]]), 2527 ?line expect(20, genErr, 3, [{[sysDescr], 'NULL'}, 2528 {[sysObjectID], 'NULL'}, 2529 {[tGenErr1], 'NULL'}, 2530 {[sysDescr], 'NULL'}]), 2531 gb(0, 2, [[tCnt2, 1]]), 2532 ?line expect(21, [{[tCnt2,2], 100}, 2533 {[tCnt2,2], endOfMibView}]). 2534 2535 2536v2_set_p() -> 2537 %% 4.2.5:1 2538 ?DBG("v2_set_p -> entry",[]), 2539 s([{[1,3,7,0], i, 4}]), 2540 ?line expect(10, noAccess, 1, [{[1,3,7,0], 4}]), 2541 s([{[tDescr,0], s, "outside mibview"}]), 2542 ?line expect(11, noAccess, 1, [{[tDescr,0], "outside mibview"}]), 2543 2544 %% 4.2.5:2 2545 s([{[1,3,6,1,0], s, "noSuchObject"}]), 2546 ?line expect(20, notWritable, 1, [{[1,3,6,1,0], "noSuchObject"}]), 2547 2548 %% 4.2.5:3 2549 s([{[tDescr2, 0], i, 4}]), 2550 ?line expect(30, wrongType, 1, [{[tDescr2, 0], 4}]), 2551 s([{[tDescr2, 0], s, "badValue"}]), 2552 ?line expect(31, badValue, 1, [{[tDescr2, 0], "badValue"}]), 2553 2554 %% 4.2.5:4 2555 s([{[tStr, 0], s, ""}]), 2556 ?line expect(40, wrongLength, 1, [{[tStr, 0], ""}]), 2557 s([{[tStr, 0], s, "12345"}]), 2558 ?line expect(40, wrongLength, 1, [{[tStr, 0], "12345"}]), 2559 2560 %% 4.2.5:5 - N/A 2561 2562 %% 4.2.5:6 2563 s([{[tInt1, 0], i, 0}]), 2564 ?line expect(60, wrongValue, 1, [{[tInt1, 0], 0}]), 2565 s([{[tInt1, 0], i, 5}]), 2566 ?line expect(61, wrongValue, 1, [{[tInt1, 0], 5}]), 2567 s([{[tInt2, 0], i, 0}]), 2568 ?line expect(62, wrongValue, 1, [{[tInt2, 0], 0}]), 2569 s([{[tInt2, 0], i, 5}]), 2570 ?line expect(63, wrongValue, 1, [{[tInt2, 0], 5}]), 2571 s([{[tInt3, 0], i, 5}]), 2572 ?line expect(64, wrongValue, 1, [{[tInt3, 0], 5}]), 2573 2574 %% 4.2.5:7 2575 s([{[tDescrX, 1, 1], s, "noCreation"}]), 2576 ?line expect(70, noCreation, 1, [{[tDescrX, 1, 1], "noCreation"}]), 2577 2578 %% 4.2.5:8 2579 s([{[tDescrX, 1, 2], s, "inconsistentName"}]), 2580 ?line expect(80, inconsistentName, 1, 2581 [{[tDescrX, 1, 2], "inconsistentName"}]), 2582 2583 %% 4.2.5:9 2584 s([{[tCnt, 1, 2], i, 5}]), 2585 ?line expect(90, notWritable, 1, [{[tCnt, 1, 2], 5}]), 2586 s([{[tDescr3,0], s, "read-only"}]), 2587 ?line expect(90, notWritable, 1, [{[tDescr3,0], "read-only"}]), 2588 2589 %% 4.2.5:10 2590 s([{[tDescr2,0], s, "inconsistentValue"}]), 2591 ?line expect(100, inconsistentValue, 1, 2592 [{[tDescr2,0], "inconsistentValue"}]), 2593 2594 %% 4.2.5:11 2595 s([{[tDescr2,0], s, "resourceUnavailable"}]), 2596 ?line expect(110, resourceUnavailable, 1, 2597 [{[tDescr2,0],"resourceUnavailable"}]), 2598 2599 %% 4.2.5:12 2600 s([{[tDescr2, 0], s, "is_set_ok_fail"}]), 2601 ?line expect(120, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]). 2602 2603 %% commitFailed and undoFailed is tested by the 'undo' case. 2604 2605 2606%% Req. OLD-SNMPEA-MIB 2607table_test() -> 2608 io:format("Testing simple get, next and set on communityTable...~n"), 2609%% {[147,214,36,45], "public", 2, readWrite}. 2610%% {[147,214,36,45], "standard trap", 2, read}. 2611 Key1c3 = [intCommunityViewIndex,get(mip),is("public")], 2612 Key2c3 = [intCommunityViewIndex,get(mip),is("standard trap")], 2613 Key1c4 = [intCommunityAccess,get(mip),is("public")], 2614 EndKey = [intCommunityEntry,[9],get(mip),is("public")], 2615 gn([[intCommunityEntry]]), 2616 ?line expect(7, [{Key1c3, 2}]), 2617 gn([[intCommunityTable]]), 2618 ?line expect(71, [{Key1c3, 2}]), 2619 gn([[community]]), 2620 ?line expect(72, [{Key1c3, 2}]), 2621 gn([[otpSnmpeaMIB]]), 2622 ?line expect(73, [{Key1c3, 2}]), 2623 gn([[ericsson]]), 2624 ?line expect(74, [{Key1c3, 2}]), 2625 gn([Key1c3]), 2626 ?line expect(8, [{Key2c3, 2}]), 2627 gn([Key2c3]), 2628 ?line expect(9, [{Key1c4, 2}]), 2629 gn([EndKey]), 2630 AgentIp = [intAgentIpAddress,0], 2631 ?line expect(10, [{AgentIp, any}]), 2632 g([Key1c3]), 2633 ?line expect(11, [{Key1c3, 2}]), 2634 g([EndKey]), 2635 ?line ?v1_2(expect(12, noSuchName, 1, any), 2636 expect(12, [{EndKey, noSuchObject}])), 2637 2638 io:format("Testing row creation/deletion on communityTable...~n"), 2639 NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], 2640 NewKeyc4 = [intCommunityAccess,get(mip),is("test")], 2641 NewKeyc5 = [intCommunityStatus,get(mip),is("test")], 2642 s([{NewKeyc5, ?createAndGo}]), 2643 ?line expect(14, ?v1_2(badValue, inconsistentValue), 1,any), 2644 s([{NewKeyc5, ?createAndGo}, {NewKeyc3, 2}, {NewKeyc4, 2}]), 2645 ?line expect(15, [{NewKeyc5, ?createAndGo},{NewKeyc3, 2}, {NewKeyc4, 2}]), 2646 g([NewKeyc4]), 2647 ?line expect(16, [{NewKeyc4, 2}]), 2648 s([{NewKeyc5, ?destroy}]), 2649 ?line expect(17, [{NewKeyc5, ?destroy}]), 2650 s([{NewKeyc4, 2}]), 2651 ?line expect(18, ?v1_2(noSuchName, inconsistentName), 1,[{NewKeyc4, 2}]), 2652 s([{NewKeyc5, ?createAndWait}]), 2653 ?line expect(19, [{NewKeyc5, ?createAndWait}]), 2654 g([NewKeyc5]), 2655 ?line expect(20, [{NewKeyc5, ?notReady}]), 2656 s([{NewKeyc4, 2}]), 2657 ?line expect(21, [{NewKeyc4, 2}]), 2658 g([NewKeyc5]), 2659 ?line expect(22, [{NewKeyc5, ?notReady}]), 2660 s([{NewKeyc3, 2}]), 2661 ?line expect(23, [{NewKeyc3, 2}]), 2662 g([NewKeyc5]), 2663 ?line expect(24, [{NewKeyc5, ?notInService}]), 2664 s([{NewKeyc5, ?active}]), 2665 ?line expect(25, [{NewKeyc5, ?active}]), 2666 s([{NewKeyc5, ?destroy}]), 2667 ?line expect(26, [{NewKeyc5, ?destroy}]), 2668 s([{NewKeyc3, 3}]), 2669 ?line expect(27, ?v1_2(noSuchName, inconsistentName), 1,[{NewKeyc3, 3}]), 2670 otp_1128(). 2671 2672%% Req. system group 2673simple_standard_test() -> 2674 ?DBG("simple_standard_test -> entry",[]), 2675 gn([[1,1]]), 2676 ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]), 2677 gn([[1,3]]), 2678 ?line expect(11, [{[sysDescr,0], "Erlang SNMP agent"}]), 2679 gn([[1,3,6]]), 2680 ?line expect(12, [{[sysDescr,0], "Erlang SNMP agent"}]), 2681 gn([[1,3,6,1]]), 2682 ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}]), 2683 gn([[1,3,6,1,2]]), 2684 ?line expect(14, [{[sysDescr,0], "Erlang SNMP agent"}]), 2685 gn([[1,3,6,1,2,1]]), 2686 ?line expect(15, [{[sysDescr,0], "Erlang SNMP agent"}]), 2687 gn([[1,3,6,1,2,1,1]]), 2688 ?line expect(16, [{[sysDescr,0], "Erlang SNMP agent"}]), 2689 gn([[sysDescr]]), 2690 ?line expect(17, [{[sysDescr,0], "Erlang SNMP agent"}]), 2691 g([[sysDescr,0]]), 2692 ?line expect(2, [{[sysDescr,0], "Erlang SNMP agent"}]), 2693 g([[sysDescr]]), 2694 ?line ?v1_2(expect(3, noSuchName, 1, any), 2695 expect(3, [{[sysDescr], noSuchObject}])), 2696 g([[1,6,7,0]]), 2697 ?line ?v1_2(expect(41, noSuchName, 1, any), 2698 expect(3, [{[1,6,7,0], noSuchObject}])), 2699 gn([[1,13]]), 2700 ?line ?v1_2(expect(4, noSuchName,1, any), 2701 expect(4, [{[1,13], endOfMibView}])), 2702 s([{[sysLocation, 0], "new_value"}]), 2703 ?line expect(5, [{[sysLocation, 0], "new_value"}]), 2704 g([[sysLocation, 0]]), 2705 ?line expect(6, [{[sysLocation, 0], "new_value"}]), 2706 io:format("Testing noSuchName and badValue...~n"), 2707 s([{[sysServices,0], 3}]), 2708 ?line expect(61, ?v1_2(noSuchName, notWritable), 1, any), 2709 s([{[sysLocation, 0], i, 3}]), 2710 ?line expect(62, ?v1_2(badValue, wrongType), 1, any), 2711 ?DBG("simple_standard_test -> done",[]), 2712 ok. 2713 2714%% This is run in the agent node 2715db_notify_client(suite) -> []; 2716db_notify_client(Config) when list(Config) -> 2717 {SaNode, MgrNode, MibDir} = init_case(Config), 2718 ?DBG("~n\tSaNode: ~p~n\tMgrNode: ~p~n\tMibDir: ~p", 2719 [SaNode,MgrNode,MibDir]), 2720 snmpa_local_db:register_notify_client(self(),?MODULE), 2721 2722 %% This call (the manager) will issue to set operations, so 2723 %% we expect to receive to notify(insert) calls. 2724 try_test(db_notify_client_test), 2725 2726 ?DBG("await first notify",[]), 2727 receive 2728 {db_notify_test_reply,insert} -> ?DBG("first notify received",[]),ok 2729 end, 2730 2731 ?DBG("await second notify",[]), 2732 receive 2733 {db_notify_test_reply,insert} -> ?DBG("second notify received",[]),ok 2734 end, 2735 2736 snmpa_local_db:unregister_notify_client(self()). 2737 2738 2739%% This is run in the manager node 2740db_notify_client_test() -> 2741 ?DBG("set first new sysLocation",[]), 2742 s([{[sysLocation, 0], "new_value"}]), 2743 ?line expect(5, [{[sysLocation, 0], "new_value"}]), 2744 2745 ?DBG("set second new sysLocation",[]), 2746 s([{[sysLocation, 0], "new_value"}]), 2747 ?line expect(5, [{[sysLocation, 0], "new_value"}]). 2748 2749notify(Pid,What) -> 2750 ?DBG("notify(~p,~p) -> called",[Pid,What]), 2751 Pid ! {db_notify_test_reply,What}. 2752 2753 2754%% Req: system group, OLD-SNMPEA-MIB, Klas1 2755big_test() -> 2756 ?DBG("big_test -> testing simple next/get/set @ master agent...",[]), 2757 simple_standard_test(), 2758 2759 ?DBG("big_test -> testing simple next/get/set @ subagent...",[]), 2760 gn([[klas1]]), 2761 ?line expect(1, [{[fname,0], ""}]), 2762 g([[fname,0]]), 2763 ?line expect(2, [{[fname,0], ""}]), 2764 s([{[fname,0], s, "test set"}]), 2765 ?line expect(3, [{[fname,0], "test set"}]), 2766 g([[fname,0]]), 2767 ?line expect(4, [{[fname,0], "test set"}]), 2768 2769 ?DBG("big_test -> " 2770 "testing next from last instance in master to subagent...",[]), 2771 gn([[?v1_2(sysServices, sysORLastChange),0]]), 2772 ?line expect(5, [{[fname,0], "test set"}]), 2773 gn([[1,1], 2774 [?v1_2(sysServices, sysORLastChange),0]]), 2775 ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, 2776 {[fname,0], "test set"}]), 2777 s([{[fname,0], s, ""}]), 2778 ?line expect(52, [{[fname,0], ""}]), 2779 2780 table_test(), 2781 2782 ?DBG("big_test -> adding one row in subagent table",[]), 2783 _FTab = [friendsEntry], 2784 s([{[friendsEntry, [2, 3]], s, "kompis3"}, 2785 {[friendsEntry, [3, 3]], i, ?createAndGo}]), 2786 ?line expect(6, [{[friendsEntry, [2, 3]], "kompis3"}, 2787 {[friendsEntry, [3, 3]], ?createAndGo}]), 2788 g([[friendsEntry, [2, 3]], 2789 [friendsEntry, [3, 3]]]), 2790 ?line expect(7, [{[friendsEntry, [2, 3]], "kompis3"}, 2791 {[friendsEntry, [3, 3]], ?active}]), 2792 s([{[friendsEntry, [3, 3]], i, ?destroy}]), 2793 ?line expect(8, [{[friendsEntry, [3, 3]], ?destroy}]), 2794 2795 otp_1131(), 2796 2797 ?DBG("big_test -> adding two rows in subagent table with special INDEX", 2798 []), 2799 s([{[kompissEntry, [1, 3]], s, "kompis3"}, 2800 {[kompissEntry, [2, 3]], i, ?createAndGo}]), 2801 ?line expect(9, [{[kompissEntry, [1, 3]], "kompis3"}, 2802 {[kompissEntry, [2, 3]], ?createAndGo}]), 2803 g([[kompissEntry, [1, 3]], 2804 [kompissEntry, [2, 3]]]), 2805 ?line expect(10, [{[kompissEntry, [1, 3]], "kompis3"}, 2806 {[kompissEntry, [2, 3]], ?active}]), 2807 gn([[kompissEntry, [1]], 2808 [kompissEntry, [2]]]), 2809 ?line expect(11, [{[kompissEntry, [1, 3]], "kompis3"}, 2810 {[kompissEntry, [2, 3]], ?active}]), 2811 s([{[kompissEntry, [1, 2]], s, "kompis3"}, 2812 {[kompissEntry, [2, 2]], i, ?createAndGo}]), 2813 ?line expect(12, [{[kompissEntry, [1, 2]], "kompis3"}, 2814 {[kompissEntry, [2, 2]], ?createAndGo}]), 2815 gn([[kompissEntry, [1, 1]], 2816 [kompissEntry, [2, 1]]]), 2817 ?line expect(13, [{[kompissEntry, [1, 2]], "kompis3"}, 2818 {[kompissEntry, [2, 2]], ?active}]), 2819 s([{[kompissEntry, [2, 3]], i, ?destroy}]), 2820 ?line expect(14, [{[kompissEntry, [2, 3]], ?destroy}]), 2821 s([{[kompissEntry, [2, 2]], i, ?destroy}]), 2822 ?line expect(15, [{[kompissEntry, [2, 2]], ?destroy}]), 2823 ?DBG("big_test -> done",[]), 2824 ok. 2825 2826%% Req. system group, Klas2, OLD-SNMPEA-MIB 2827big_test_2() -> 2828 p("Testing simple next/get/set @ master agent (2)..."), 2829 simple_standard_test(), 2830 2831 p("Testing simple next/get/set @ subagent (2)..."), 2832 gn([[klas2]]), 2833 ?line expect(1, [{[fname2,0], ""}]), 2834 g([[fname2,0]]), 2835 ?line expect(2, [{[fname2,0], ""}]), 2836 s([{[fname2,0], s, "test set"}]), 2837 ?line expect(3, [{[fname2,0], "test set"}]), 2838 g([[fname2,0]]), 2839 ?line expect(4, [{[fname2,0], "test set"}]), 2840 2841 otp_1298(), 2842 2843 p("Testing next from last object in master to subagent (2)..."), 2844 gn([[?v1_2(sysServices, sysORLastChange),0]]), 2845 ?line expect(5, [{[fname2,0], "test set"}]), 2846 gn([[1,1], 2847 [?v1_2(sysServices, sysORLastChange),0]]), 2848 ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, 2849 {[fname2,0], "test set"}]), 2850 2851 table_test(), 2852 2853 p("Adding one row in subagent table (2)"), 2854 _FTab = [friendsEntry2], 2855 s([{[friendsEntry2, [2, 3]], s, "kompis3"}, 2856 {[friendsEntry2, [3, 3]], i, ?createAndGo}]), 2857 ?line expect(6, [{[friendsEntry2, [2, 3]], "kompis3"}, 2858 {[friendsEntry2, [3, 3]], ?createAndGo}]), 2859 g([[friendsEntry2, [2, 3]], 2860 [friendsEntry2, [3, 3]]]), 2861 ?line expect(7, [{[friendsEntry2, [2, 3]], "kompis3"}, 2862 {[friendsEntry2, [3, 3]], ?active}]), 2863 s([{[friendsEntry2, [3, 3]], i, ?destroy}]), 2864 ?line expect(8, [{[friendsEntry2, [3, 3]], ?destroy}]), 2865 2866 p("Adding two rows in subagent table with special INDEX (2)"), 2867 s([{[kompissEntry2, [1, 3]], s, "kompis3"}, 2868 {[kompissEntry2, [2, 3]], i, ?createAndGo}]), 2869 ?line expect(9, [{[kompissEntry2, [1, 3]], "kompis3"}, 2870 {[kompissEntry2, [2, 3]], ?createAndGo}]), 2871 g([[kompissEntry2, [1, 3]], 2872 [kompissEntry2, [2, 3]]]), 2873 ?line expect(10, [{[kompissEntry2, [1, 3]], "kompis3"}, 2874 {[kompissEntry2, [2, 3]], ?active}]), 2875 gn([[kompissEntry2, [1]], 2876 [kompissEntry2, [2]]]), 2877 ?line expect(11, [{[kompissEntry2, [1, 3]], "kompis3"}, 2878 {[kompissEntry2, [2, 3]], ?active}]), 2879 s([{[kompissEntry2, [1, 2]], s, "kompis3"}, 2880 {[kompissEntry2, [2, 2]], i, ?createAndGo}]), 2881 ?line expect(12, [{[kompissEntry2, [1, 2]], "kompis3"}, 2882 {[kompissEntry2, [2, 2]], ?createAndGo}]), 2883 gn([[kompissEntry2, [1, 1]], 2884 [kompissEntry2, [2, 1]]]), 2885 ?line expect(13, [{[kompissEntry2, [1, 2]], "kompis3"}, 2886 {[kompissEntry2, [2, 2]], ?active}]), 2887 s([{[kompissEntry2, [2, 3]], i, ?destroy}]), 2888 ?line expect(14, [{[kompissEntry2, [2, 3]], ?destroy}]), 2889 s([{[kompissEntry2, [2, 2]], i, ?destroy}]), 2890 ?line expect(15, [{[kompissEntry2, [2, 2]], ?destroy}]), 2891 ok. 2892 2893%% Req. Test1 2894multi_threaded_test() -> 2895 p("Testing multi threaded agent..."), 2896 g([[multiStr,0]]), 2897 Pid = get_multi_pid(), 2898 g([[sysUpTime,0]]), 2899 ?line expect(1, [{[sysUpTime,0], any}]), 2900 s([{[sysLocation, 0], s, "pelle"}]), 2901 ?line expect(2, [{[sysLocation, 0], "pelle"}]), 2902 Pid ! continue, 2903 ?line expect(3, [{[multiStr,0], "ok"}]), 2904 2905 s([{[multiStr, 0], s, "block"}]), 2906 Pid2 = get_multi_pid(), 2907 g([[sysUpTime,0]]), 2908 ?line expect(4, [{[sysUpTime,0], any}]), 2909 g([[multiStr,0]]), 2910 Pid3 = get_multi_pid(), 2911 g([[sysUpTime,0]]), 2912 ?line expect(5, [{[sysUpTime,0], any}]), 2913 s([{[sysLocation, 0], s, "kalle"}]), 2914 Pid3 ! continue, 2915 ?line expect(6, [{[multiStr,0], "ok"}]), 2916 Pid2 ! continue, 2917 ?line expect(7, [{[multiStr,0], "block"}]), 2918 ?line expect(8, [{[sysLocation,0], "kalle"}]). 2919 2920%% Req. Test1, TestTrapv2 2921mt_trap_test(MA) -> 2922 snmpa:send_trap(MA, testTrapv22, "standard trap"), 2923 ?line expect(1, v2trap, [{[sysUpTime, 0], any}, 2924 {[snmpTrapOID, 0], ?system ++ [0,1]}]), 2925 2926 snmpa:send_trap(MA, mtTrap, "standard trap"), 2927 Pid = get_multi_pid(), 2928 g([[sysUpTime,0]]), 2929 ?line expect(2, [{[sysUpTime,0], any}]), 2930 snmpa:send_trap(MA, testTrapv22, "standard trap"), 2931 ?line expect(3, v2trap, [{[sysUpTime, 0], any}, 2932 {[snmpTrapOID, 0], ?system ++ [0,1]}]), 2933 Pid ! continue, 2934 ?line expect(4, v2trap, [{[sysUpTime, 0], any}, 2935 {[snmpTrapOID, 0], ?testTrap ++ [2]}, 2936 {[multiStr,0], "ok"}]). 2937 2938 2939get_multi_pid() -> 2940 get_multi_pid(10). 2941get_multi_pid(0) -> 2942 ?line ?FAIL(no_global_name); 2943get_multi_pid(N) -> 2944 sleep(1000), 2945 case global:whereis_name(snmp_multi_tester) of 2946 Pid when pid(Pid) -> Pid; 2947 _ -> get_multi_pid(N-1) 2948 end. 2949 2950%% Req. Test1 2951types_v2_test() -> 2952 p("Testing v2 types..."), 2953 2954 s([{[bits1,0], 2#10}]), 2955 ?line expect(1, [{[bits1,0], ?str(2#10)}]), 2956 g([[bits1,0]]), 2957 ?line expect(2, [{[bits1,0], ?str(2#101)}]), 2958 2959 s([{[bits2,0], 2#11000000110}]), 2960 ?line expect(3, [{[bits2,0], ?str(2#11000000110)}]), 2961 g([[bits2,0]]), 2962 ?line expect(4, [{[bits2,0], ?str(2#11000000110)}]), 2963 2964 g([[bits3,0]]), 2965 ?line expect(50, genErr, 1, any), 2966 2967 g([[bits4,0]]), 2968 ?line expect(51, genErr, 1, any), 2969 2970 s([{[bits1,0], s, [2#10]}]), 2971 ?line expect(6, ?v1_2(badValue, wrongValue), 1, any), 2972 2973 s([{[bits2,0], 2#11001001101010011}]), 2974 ?line expect(7, ?v1_2(badValue, wrongValue), 1, any). 2975 2976 2977%% Req. Test1 2978implied_test(MA) -> 2979 ?LOG("implied_test -> start",[]), 2980 p("Testing IMPLIED..."), 2981 2982 snmpa:verbosity(MA,trace), 2983 snmpa:verbosity(MA,trace), 2984 2985 %% Create two rows, check that they are get-nexted in correct order. 2986 Idx1 = "apa", 2987 Idx2 = "qq", 2988 ?DBG("implied_test -> (send) create row 1 '~s' in table 1",[Idx1]), 2989 s([{[testStatus, Idx1], i, ?createAndGo}, {[testDescr, Idx1],s,"row 1"}]), 2990 ?line expect(1, [{[testStatus, Idx1], ?createAndGo}, 2991 {[testDescr, Idx1], "row 1"}]), 2992 ?DBG("implied_test -> (send) create row 2 '~s' in table 1",[Idx2]), 2993 s([{[testStatus, Idx2], i, ?createAndGo}, {[testDescr, Idx2],s,"row 2"}]), 2994 ?line expect(2, [{[testStatus, Idx2], ?createAndGo}, 2995 {[testDescr, Idx2], "row 2"}]), 2996 ?DBG("implied_test -> get-next(testDescr)",[]), 2997 gn([[testDescr]]), 2998 ?line expect(3, [{[testDescr,Idx1], "row 1"}]), 2999 ?DBG("implied_test -> get-next(testDescr) of row 1",[]), 3000 gn([[testDescr,Idx1]]), 3001 ?line expect(4, [{[testDescr,Idx2], "row 2"}]), 3002 3003 % Delete the rows 3004 ?DBG("implied_test -> (send) delete row 1 '~s' from table 1",[Idx1]), 3005 s([{[testStatus, Idx1], i, ?destroy}]), 3006 ?line expect(5, [{[testStatus, Idx1], ?destroy}]), 3007 ?DBG("implied_test -> (send) delete row 2 '~s' from table 1",[Idx2]), 3008 s([{[testStatus, Idx2], i, ?destroy}]), 3009 ?line expect(6, [{[testStatus, Idx2], ?destroy}]), 3010 3011 %% Try the same in other table 3012 Idx3 = [1, "apa"], 3013 Idx4 = [1, "qq"], 3014 ?DBG("implied_test -> (send) create row 1 '~s' in table 2",[Idx3]), 3015 s([{[testStatus2, Idx3], i, ?createAndGo}, {[testDescr2,Idx3],s,"row 1"}]), 3016 ?line expect(1, [{[testStatus2, Idx3], ?createAndGo}, 3017 {[testDescr2, Idx3], "row 1"}]), 3018 ?DBG("implied_test -> (send) create row 2 '~s' in table 2",[Idx4]), 3019 s([{[testStatus2, Idx4], i, ?createAndGo}, {[testDescr2,Idx4],s,"row 2"}]), 3020 ?line expect(2, [{[testStatus2, Idx4], ?createAndGo}, 3021 {[testDescr2, Idx4], "row 2"}]), 3022 ?DBG("implied_test -> get-next(testDescr2)",[]), 3023 gn([[testDescr2]]), 3024 ?line expect(3, [{[testDescr2,Idx3], "row 1"}]), 3025 ?DBG("implied_test -> get-next(testDescr2) of row 1",[]), 3026 gn([[testDescr2,Idx3]]), 3027 ?line expect(4, [{[testDescr2,Idx4], "row 2"}]), 3028 3029 % Delete the rows 3030 ?DBG("implied_test -> (send) delete row 1 '~s' from table 2",[Idx3]), 3031 s([{[testStatus2, Idx3], i, ?destroy}]), 3032 ?line expect(5, [{[testStatus2, Idx3], ?destroy}]), 3033 ?DBG("implied_test -> (send) delete row 2 '~s' from table 2",[Idx4]), 3034 s([{[testStatus2, Idx4], i, ?destroy}]), 3035 ?line expect(6, [{[testStatus2, Idx4], ?destroy}]), 3036 3037 snmpa:verbosity(MA,log), 3038 3039 ?LOG("implied_test -> done",[]). 3040 3041 3042 3043%% Req. Test1 3044sparse_table_test() -> 3045 p("Testing sparse table..."), 3046 3047 %% Create two rows, check that they are get-nexted in correct order. 3048 Idx1 = 1, 3049 Idx2 = 2, 3050 s([{[sparseStatus, Idx1], i, ?createAndGo}, 3051 {[sparseDescr, Idx1], s, "row 1"}]), 3052 ?line expect(1, [{[sparseStatus, Idx1], ?createAndGo}, 3053 {[sparseDescr, Idx1], "row 1"}]), 3054 s([{[sparseStatus, Idx2], i, ?createAndGo}, 3055 {[sparseDescr, Idx2], s, "row 2"}]), 3056 ?line expect(2, [{[sparseStatus, Idx2], ?createAndGo}, 3057 {[sparseDescr, Idx2], "row 2"}]), 3058 ?v1_2(gn([[sparseIndex], [sparseDescr,Idx1], [sparseDescr,Idx2], 3059 [sparseStatus,Idx1], [sparseStatus,Idx2]]), 3060 gb(0,5,[[sparseIndex]])), 3061 ?line expect(3, [{[sparseDescr,Idx1], "row 1"}, 3062 {[sparseDescr,Idx2], "row 2"}, 3063 {[sparseStatus,Idx1], ?active}, 3064 {[sparseStatus,Idx2], ?active}, 3065 {[sparseStr,0], "slut"}]), 3066 % Delete the rows 3067 s([{[sparseStatus, Idx1], i, ?destroy}]), 3068 ?line expect(4, [{[sparseStatus, Idx1], ?destroy}]), 3069 s([{[sparseStatus, Idx2], i, ?destroy}]), 3070 ?line expect(5, [{[sparseStatus, Idx2], ?destroy}]). 3071 3072 3073%% Req. Test1 3074cnt_64_test(MA) -> 3075 ?LOG("start cnt64 test (~p)",[MA]), 3076 snmpa:verbosity(MA,trace), 3077 ?LOG("start cnt64 test",[]), 3078 p("Testing Counter64, and at the same time, RowStatus is not last column"), 3079 3080 ?DBG("get cnt64",[]), 3081 g([[cnt64,0]]), 3082 ?DBG("await response",[]), 3083 ?line ?v1_2(expect(1, noSuchName, 1, any), 3084 expect(1, [{[cnt64,0],18446744073709551615}])), 3085 ?DBG("get-next cnt64",[]), 3086 gn([[cnt64]]), 3087 ?DBG("await response",[]), 3088 ?line ?v1_2(expect(2, [{[cnt64Str,0], "after cnt64"}]), 3089 expect(2, [{[cnt64,0],18446744073709551615}])), 3090 ?DBG("send cntTrap",[]), 3091 snmpa:send_trap(MA,cntTrap,"standard trap",[{sysContact,"pelle"}, 3092 {cnt64, 10}, 3093 {sysLocation, "here"}]), 3094 ?DBG("await response",[]), 3095 ?line ?v1_2(expect(3, trap, [test], 6, 1, [{[sysContact,0], "pelle"}, 3096 {[sysLocation,0], "here"}]), 3097 expect(3, v2trap, [{[sysUpTime, 0], any}, 3098 {[snmpTrapOID, 0], ?testTrap ++ [1]}, 3099 {[sysContact,0], "pelle"}, 3100 {[cnt64,0], 10}, 3101 {[sysLocation,0], "here"}])), 3102 3103 %% Create two rows, check that they are get-nexted in correct order. 3104 Idx1 = 1, 3105 Idx2 = 2, 3106 ?DBG("create row (cntStatus): ~p",[Idx1]), 3107 s([{[cntStatus, Idx1], i, ?createAndGo}]), 3108 ?DBG("await response",[]), 3109 ?line expect(1, [{[cntStatus, Idx1], ?createAndGo}]), 3110 ?DBG("create row (cntStatus): ~p",[Idx2]), 3111 s([{[cntStatus, Idx2], i, ?createAndGo}]), 3112 ?DBG("await response",[]), 3113 ?line expect(2, [{[cntStatus, Idx2], ?createAndGo}]), 3114 3115 ?DBG("get-next (cntIndex)",[]), 3116 gn([[cntIndex]]), 3117 ?DBG("await response",[]), 3118 ?line ?v1_2(expect(3, [{[cntStatus,Idx1], ?active}]), 3119 expect(3, [{[cntCnt,Idx1], 0}])), 3120 % Delete the rows 3121 ?DBG("delete row (cntStatus): ~p",[Idx1]), 3122 s([{[cntStatus, Idx1], i, ?destroy}]), 3123 ?DBG("await response",[]), 3124 ?line expect(4, [{[cntStatus, Idx1], ?destroy}]), 3125 ?DBG("delete row (cntStatus): ~p",[Idx2]), 3126 s([{[cntStatus, Idx2], i, ?destroy}]), 3127 ?DBG("await response",[]), 3128 ?line expect(5, [{[cntStatus, Idx2], ?destroy}]), 3129 catch snmpa:verbosity(MA,log), 3130 ?DBG("done",[]), 3131 ok. 3132 3133%% Req. Test1 3134opaque_test() -> 3135 p("Testing Opaque datatype..."), 3136 g([[opaqueObj,0]]), 3137 ?line expect(1, [{[opaqueObj,0], "opaque-data"}]). 3138 3139%% Req. OLD-SNMPEA-MIB 3140api_test(MaNode) -> 3141 ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, 3142 [intAgentIpAddress]), 3143 ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, 3144 oid_to_name, [OID]), 3145 ?line false = rpc:call(MaNode, snmp, name_to_oid, [intAgentIpAddres]), 3146 ?line false = rpc:call(MaNode, snmp, oid_to_name, 3147 [[1,5,32,3,54,3,3,34,4]]), 3148 ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, 3149 [intViewType, excluded]), 3150 ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, 3151 [intViewType, 2]), 3152 ?line false = rpc:call(MaNode, snmp, enum_to_int, [intViewType, exclude]), 3153 ?line false = rpc:call(MaNode, snmp, enum_to_int, 3154 [intAgentIpAddress, exclude]), 3155 ?line false = rpc:call(MaNode, snmp, enum_to_int, 3156 [intAgentIpAddre, exclude]), 3157 ?line false = rpc:call(MaNode, snmp, int_to_enum, [intViewType, 3]), 3158 ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddress, 2]), 3159 ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddre, 2]), 3160 ?line {value, active} = rpc:call(MaNode, snmp, 3161 int_to_enum, ['RowStatus', ?active]), 3162 ?line {value, ?destroy} = rpc:call(MaNode, snmp, 3163 enum_to_int, ['RowStatus', destroy]), 3164 ?line false = rpc:call(MaNode, snmp, 3165 enum_to_int, ['RowStatus', xxxdestroy]), 3166 ?line false = rpc:call(MaNode, snmp, 3167 enum_to_int, ['xxRowStatus', destroy]), 3168 ?line false = rpc:call(MaNode, snmp, int_to_enum, ['RowStatus', 25]), 3169 ?line false = rpc:call(MaNode, snmp, int_to_enum, ['xxRowStatus', 1]), 3170 ?line case snmp:date_and_time() of 3171 List when list(List), length(List) == 8 -> ok; 3172 List when list(List), length(List) == 11 -> ok 3173 end. 3174 3175%% Req. Klas3 3176api_test2() -> 3177 g([[fname3,0]]), 3178 ?line expect(1, [{[fname3,0], "ok"}]), 3179 g([[fname4,0]]), 3180 ?line expect(2, [{[fname4,0], 1}]). 3181 3182api_test3() -> 3183 g([[fname3,0]]), 3184 ?line expect(1, [{[fname3,0], "ok"}]). 3185 3186 3187unreg_test() -> 3188 gn([[?v1_2(sysServices, sysORLastChange),0]]), 3189 ?line expect(1, [{[snmpInPkts, 0], any}]). 3190 3191load_test() -> 3192 gn([[?v1_2(sysServices, sysORLastChange),0]]), 3193 ?line expect(1, [{[fname,0], ""}]). 3194 3195%% Req. Klas1 3196load_test_sa() -> 3197 gn([[?v1_2(sysServices,sysORLastChange), 0]]), 3198 ?line expect(1, [{[fname,0], any}]). 3199 3200%% Req. system group, Klas1, OLD-SNMPEA-MIB 3201do_mul_get() -> 3202 Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], 3203 Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], 3204 s([{[fname,0], s, "test set"}]), 3205 ?line expect(3, [{[fname,0], "test set"}]), 3206 g([[sysDescr,0], Key1c4, [fname,0],Key1c3, 3207 [sysName,0]]), 3208 ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, 3209 {Key1c4, 2}, 3210 {[fname,0], "test set"}, 3211 {Key1c3, 2}, 3212 {[sysName,0], "test"}]), 3213 g([[1,3,7,1], Key1c4, [sysDescr,0], [1,3,7,2], Key1c3, [sysDescr,0]]), 3214 ?line ?v1_2(expect(2, noSuchName, [1,4], any), 3215 expect(2, [{[1,3,7,1], noSuchObject}, 3216 {Key1c4, 2}, 3217 {[sysDescr,0], "Erlang SNMP agent"}, 3218 {[1,3,7,2], noSuchObject}, 3219 {Key1c3, 2}, 3220 {[sysDescr,0], "Erlang SNMP agent"}])). 3221 3222%% Req. v1, system group, Klas1, OLD-SNMPEA-MIB, *ej* Klas3. 3223do_mul_get_err() -> 3224 Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], 3225 Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], 3226 s([{[fname,0], s, "test set"}]), 3227 ?line expect(3, [{[fname,0], "test set"}]), 3228 g([[sysDescr,0],Key1c4,[fname,0], Key1c3, [sysName,2]]), 3229 ?line ?v1_2(expect(1, noSuchName, 5, any), 3230 expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, 3231 {Key1c4, 2}, 3232 {[fname,0], "test set"}, 3233 {Key1c3, 2}, 3234 {[sysName,2], noSuchInstance}])), 3235 g([[sysDescr,0],Key1c4,[fname3,0], Key1c3, [sysName,1]]), 3236 ?line ?v1_2(expect(1, noSuchName, [3,5], any), 3237 expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, 3238 {Key1c4, 2}, 3239 {[fname3,0], noSuchObject}, 3240 {Key1c3, 2}, 3241 {[sysName,1], noSuchInstance}])). 3242 3243 3244%% Req. system group, Klas1, OLD-SNMPEA-MIB 3245do_mul_next() -> 3246 Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], 3247 Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], 3248 Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], 3249 Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], 3250 s([{[fname,0], s, "test set"}]), 3251 ?line expect(3, [{[fname,0], "test set"}]), 3252 gn([[sysDescr], Key1c4s, [fname],Key1c3s,[sysName]]), 3253 ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, 3254 {Key1c4, 2}, {[fname,0], "test set"}, 3255 {Key1c3, 2}, {[sysName,0], "test"}]). 3256 3257%% Req. system group, Klas1, OLD-SNMPEA-MIB 3258do_mul_next_err() -> 3259 Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], 3260 Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], 3261 Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], 3262 Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], 3263 s([{[fname,0], s, "test set"}]), 3264 ?line expect(3, [{[fname,0], "test set"}]), 3265 gn([[sysDescr], Key1c4s, [1,3,6,999], [fname],[1,3,90], Key1c3s,[sysName]]), 3266 ?line ?v1_2(expect(1, noSuchName, [3,5], any), 3267 expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, 3268 {Key1c4, 2}, 3269 {[1,3,6,999], endOfMibView}, 3270 {[fname,0], "test set"}, 3271 {[1,3,90], endOfMibView}, 3272 {Key1c3, 2}, 3273 {[sysName,0], "test"}])). 3274 3275 3276%% Req. system group, Klas1, OLD-SNMPEA-MIB 3277do_mul_set() -> 3278 p("Adding one row in subagent table, and one in master table"), 3279 NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], 3280 NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], 3281 NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], 3282 s([{[friendsEntry, [2, 3]], "kompis3"}, 3283 {NewKeyc3, 2}, 3284 {[sysLocation,0], "new_value"}, 3285 {NewKeyc5, ?createAndGo}, 3286 {NewKeyc4, 2}, 3287 {[friendsEntry, [3, 3]], ?createAndGo}]), 3288 ?line expect(1, [{[friendsEntry, [2, 3]], "kompis3"}, 3289 {NewKeyc3, 2}, 3290 {[sysLocation,0], "new_value"}, 3291 {NewKeyc5, ?createAndGo}, 3292 {NewKeyc4, 2}, 3293 {[friendsEntry, [3, 3]], ?createAndGo}]), 3294 g([[friendsEntry, [2, 3]], 3295 [sysLocation,0], 3296 [friendsEntry, [3, 3]]]), 3297 ?line expect(2, [{[friendsEntry, [2, 3]], "kompis3"}, 3298 {[sysLocation,0], "new_value"}, 3299 {[friendsEntry, [3, 3]], ?active}]), 3300 g([NewKeyc4]), 3301 ?line expect(3, [{NewKeyc4, 2}]), 3302 s([{[friendsEntry, [3, 3]], ?destroy}, 3303 {NewKeyc5, ?destroy}]), 3304 ?line expect(4, [{[friendsEntry, [3, 3]], ?destroy}, 3305 {NewKeyc5, ?destroy}]). 3306 3307%% Req. system group, Klas1, OLD-SNMPEA-MIB 3308do_mul_set_err() -> 3309 NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], 3310 NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], 3311 NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], 3312 p("Adding one row in subagent table, and one in master table"), 3313 s([{[friendsEntry, [2, 3]], s, "kompis3"}, 3314 {NewKeyc3, 2}, 3315 {[sysUpTime,0], 45}, % sysUpTime (readOnly) 3316 {NewKeyc5, ?createAndGo}, 3317 {NewKeyc4, 2}, 3318 {[friendsEntry, [3, 3]], ?createAndGo}]), 3319 ?line expect(1, ?v1_2(noSuchName, notWritable), 3, any), 3320 g([[friendsEntry, [2, 3]]]), 3321 ?line ?v1_2(expect(2, noSuchName, 1, any), 3322 expect(2, [{[friendsEntry, [2,3]], noSuchInstance}])), 3323 g([NewKeyc4]), 3324 ?line ?v1_2(expect(3, noSuchName, 1, any), 3325 expect(3, [{NewKeyc4, noSuchInstance}])). 3326 3327%% Req. SA-MIB 3328sa_mib() -> 3329 g([[sa, [2,0]]]), 3330 ?line expect(1, [{[sa, [2,0]], 3}]), 3331 s([{[sa, [1,0]], s, "sa_test"}]), 3332 ?line expect(2, [{[sa, [1,0]], "sa_test"}]). 3333 3334ma_trap1(MA) -> 3335 snmpa:send_trap(MA, testTrap2, "standard trap"), 3336 ?line expect(1, trap, [system], 6, 1, [{[system, [4,0]], 3337 "{mbj,eklas}@erlang.ericsson.se"}]), 3338 snmpa:send_trap(MA, testTrap1, "standard trap"), 3339 ?line expect(2, trap, [1,2,3] , 1, 0, [{[system, [4,0]], 3340 "{mbj,eklas}@erlang.ericsson.se"}]). 3341 3342ma_trap2(MA) -> 3343 snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), 3344 ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). 3345 3346ma_v2_2_v1_trap(MA) -> 3347 snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), 3348 ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). 3349 3350ma_v2_2_v1_trap2(MA) -> 3351 snmpa:send_trap(MA,linkUp,"standard trap",[{ifIndex, [1], 1}, 3352 {ifAdminStatus, [1], 1}, 3353 {ifOperStatus, [1], 2}]), 3354 ?line expect(3, trap, [1,2,3], 3, 0, [{[ifIndex, 1], 1}, 3355 {[ifAdminStatus, 1], 1}, 3356 {[ifOperStatus, 1], 2}]). 3357 3358sa_trap1(SA) -> 3359 snmpa:send_trap(SA, saTrap, "standard trap"), 3360 ?line expect(4, trap, [ericsson], 6, 1, [{[system, [4,0]], 3361 "{mbj,eklas}@erlang.ericsson.se"}, 3362 {[sa, [1,0]], "sa_test"}]). 3363 3364sa_trap2(SA) -> 3365 snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), 3366 ?line expect(5, trap, [ericsson], 6, 1, [{[system, [4,0]], 3367 "pelle"}, 3368 {[sa, [1,0]], "sa_test"}]). 3369 3370sa_trap3(SA) -> 3371 snmpa:send_trap(SA, saTrap2, "standard trap", 3372 [{intViewSubtree, [4], [1,2,3,4]}]), 3373 ?line expect(6, trap, [ericsson], 6, 2, [{[system, [4,0]], 3374 "{mbj,eklas}@erlang.ericsson.se"}, 3375 {[sa, [1,0]], "sa_test"}, 3376 {[intViewSubtree,4],[1,2,3,4]}]). 3377 3378ma_v2_trap1(MA) -> 3379 ?DBG("ma_v2_traps -> entry with MA = ~p => " 3380 "send standard trap: testTrapv22",[MA]), 3381 snmpa:send_trap(MA, testTrapv22, "standard trap"), 3382 ?line expect(1, v2trap, [{[sysUpTime, 0], any}, 3383 {[snmpTrapOID, 0], ?system ++ [0,1]}]), 3384 ?DBG("ma_v2_traps -> send standard trap: testTrapv21",[]), 3385 snmpa:send_trap(MA, testTrapv21, "standard trap"), 3386 ?line expect(2, v2trap, [{[sysUpTime, 0], any}, 3387 {[snmpTrapOID, 0], ?snmp ++ [1]}]). 3388 3389ma_v2_trap2(MA) -> 3390 snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), 3391 ?line expect(3, v2trap, [{[sysUpTime, 0], any}, 3392 {[snmpTrapOID, 0], ?system ++ [0,1]}, 3393 {[system, [4,0]], "pelle"}]). 3394 3395%% Note: This test case takes a while... actually a couple of minutes. 3396ma_v2_inform1(MA) -> 3397 ?DBG("ma_v2_inform -> entry with MA = ~p => " 3398 "send notification: testTrapv22",[MA]), 3399 ?line snmpa:send_notification(MA, testTrapv22, no_receiver, "standard inform", []), 3400 ?line expect(1, {inform, true}, 3401 [{[sysUpTime, 0], any}, 3402 {[snmpTrapOID, 0], ?system ++ [0,1]}]), 3403 3404 ?DBG("ma_v2_inform -> send notification: testTrapv22",[]), 3405 snmpa:send_notification(MA, testTrapv22, {tag1, self()}, 3406 "standard inform", []), 3407 ?line expect(1, {inform, true}, 3408 [{[sysUpTime, 0], any}, 3409 {[snmpTrapOID, 0], ?system ++ [0,1]}]), 3410 ?DBG("ma_v2_inform -> await targets",[]), 3411 receive 3412 {snmp_targets, tag1, [_]} -> 3413 ok; 3414 {snmp_targets, tag1, Addrs1} -> 3415 ?line ?FAIL({bad_addrs, Addrs1}) 3416 after 3417 5000 -> 3418 ?ERR("ma_v2_inform1 -> awaiting snmp_targets(tag1) timeout",[]), 3419 ?line ?FAIL(nothing_at_all) 3420 end, 3421 ?DBG("ma_v2_inform -> await notification",[]), 3422 receive 3423 {snmp_notification, tag1, {got_response, _}} -> 3424 ok; 3425 {snmp_notification, tag1, {no_response, _}} -> 3426 ?line ?FAIL(no_response) 3427 after 3428 20000 -> 3429 ?ERR("ma_v2_inform1 -> " 3430 "awaiting snmp_notification(tag1) timeout",[]), 3431 ?line ?FAIL(nothing_at_all) 3432 end, 3433 3434 %% 3435 %% -- The rest is possibly erroneous... 3436 %% 3437 3438 ?DBG("ma_v2_inform -> send notification: testTrapv22",[]), 3439 snmpa:send_notification(MA, testTrapv22, {tag2, self()}, 3440 "standard inform", []), 3441 ?line expect(2, {inform, false}, 3442 [{[sysUpTime, 0], any}, 3443 {[snmpTrapOID, 0], ?system ++ [0,1]}]), 3444 ?DBG("ma_v2_inform -> await targets",[]), 3445 receive 3446 {snmp_targets, tag2, [_]} -> 3447 ok; 3448 {snmp_targets, tag2, Addrs2} -> 3449 ?ERR("ma_v2_inform1 -> awaiting snmp_targets(tag2) timeout",[]), 3450 ?line ?FAIL({bad_addrs, Addrs2}) 3451 after 3452 5000 -> 3453 ?line ?FAIL(nothing_at_all) 3454 end, 3455 ?DBG("ma_v2_inform -> await notification",[]), 3456 receive 3457 {snmp_notification, tag2, {got_response, _}} -> 3458 ?line ?FAIL(got_response); 3459 {snmp_notification, tag2, {no_response, _}} -> 3460 ok 3461 after 3462 240000 -> 3463 ?ERR("ma_v2_inform1 -> " 3464 "awaiting snmp_notification(tag2) timeout",[]), 3465 ?line ?FAIL(nothing_at_all) 3466 end. 3467 3468 3469ma_v1_2_v2_trap(MA) -> 3470 snmpa:send_trap(MA,linkDown,"standard trap",[{ifIndex, [1], 1}]), 3471 ?line expect(2, v2trap, [{[sysUpTime, 0], any}, 3472 {[snmpTrapOID, 0], ?snmpTraps ++ [3]}, 3473 {[ifIndex, 1], 1}, 3474 {[snmpTrapEnterprise, 0], [1,2,3]}]). 3475 3476 3477ma_v1_2_v2_trap2(MA) -> 3478 snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), 3479 ?line expect(3, v2trap, [{[sysUpTime, 0], any}, 3480 {[snmpTrapOID, 0], ?system ++ [0,1]}, 3481 {[system, [4,0]], "pelle"}, 3482 {[snmpTrapEnterprise, 0], ?system}]). 3483 3484 3485sa_v1_2_v2_trap1(SA) -> 3486 snmpa:send_trap(SA, saTrap, "standard trap"), 3487 ?line expect(4, v2trap, [{[sysUpTime, 0], any}, 3488 {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, 3489 {[system, [4,0]], 3490 "{mbj,eklas}@erlang.ericsson.se"}, 3491 {[sa, [1,0]], "sa_test"}, 3492 {[snmpTrapEnterprise, 0], ?ericsson}]). 3493 3494sa_v1_2_v2_trap2(SA) -> 3495 snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), 3496 ?line expect(4, v2trap, [{[sysUpTime, 0], any}, 3497 {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, 3498 {[system, [4,0]], "pelle"}, 3499 {[sa, [1,0]], "sa_test"}, 3500 {[snmpTrapEnterprise, 0], ?ericsson}]). 3501 3502 3503sa_v1_2_v2_trap3(SA) -> 3504 snmpa:send_trap(SA, saTrap2, "standard trap", 3505 [{intViewSubtree, [4], [1,2,3,4]}]), 3506 ?line expect(4, v2trap, [{[sysUpTime, 0], any}, 3507 {[snmpTrapOID, 0], ?ericsson ++ [0, 2]}, 3508 {[system, [4,0]], 3509 "{mbj,eklas}@erlang.ericsson.se"}, 3510 {[sa, [1,0]], "sa_test"}, 3511 {[intViewSubtree,4],[1,2,3,4]}, 3512 {[snmpTrapEnterprise, 0], ?ericsson}]). 3513 3514 3515%% Req. SA-MIB, OLD-SNMPEA-MIB 3516sa_errs_bad_value() -> 3517 NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], 3518 NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], 3519 NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], 3520 s([{NewKeyc3, 2}, 3521 {[sa, [2,0]], 5}, % badValue (i is_set_ok) 3522 {NewKeyc5, ?createAndGo}, 3523 {NewKeyc4, 2}]), 3524 ?line expect(1, badValue, 2, any), 3525 s([{NewKeyc3, 2}, 3526 {[sa, [2,0]], 6}, % wrongValue (i is_set_ok) 3527 {NewKeyc5, ?createAndGo}, 3528 {NewKeyc4, 2}]), 3529 ?line expect(1, ?v1_2(badValue, wrongValue), 2, any), 3530 g([NewKeyc4]), 3531 ?line ?v1_2(expect(2, noSuchName, 1, any), 3532 expect(2, [{NewKeyc4, noSuchInstance}])). 3533 3534%% Req. SA-MIB, OLD-SNMPEA-MIB 3535sa_errs_gen_err() -> 3536 NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], 3537 NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], 3538 NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], 3539 s([{NewKeyc3, 2},{NewKeyc4, 2}, 3540 {NewKeyc5, ?createAndGo}, {[sa, [3,0]], 5}]), 3541 ?line expect(1, genErr, 4, any), 3542% The row might have been added; we don't know. 3543% (as a matter of fact we do - it is added, because the agent 3544% first sets its own vars, and then th SAs. Lets destroy it. 3545 s([{NewKeyc5, ?destroy}]), 3546 ?line expect(2, [{NewKeyc5, ?destroy}]). 3547 3548%% Req. SA-MIB, OLD-SNMPEA-MIB 3549sa_too_big() -> 3550 g([[sa, [4,0]]]), 3551 ?line expect(1, tooBig). 3552 3553%% Req. Klas1, system group, snmp group (v1/v2) 3554next_across_sa() -> 3555 gn([[sysDescr],[klas1,5]]), 3556 ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, 3557 {[snmpInPkts, 0], any}]). 3558 3559%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]). -> noError 3560%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]). -> {badValue, 2} 3561%% snmp_test_mgr:s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]). -> {genErr, 1} 3562%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]). -> {genErr, 1} 3563%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]). -> {genErr, 1} 3564%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]). -> {genErr, 2} 3565%% Req. Klas3, Klas4 3566undo_test() -> 3567 s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), 3568 ?line expect(1, [{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), 3569 s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]), 3570 ?line expect(2, ?v1_2(badValue, inconsistentValue), 2, any), 3571 s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]), 3572 ?line expect(3, ?v1_2(genErr, undoFailed), 1, any), 3573 s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]), 3574 ?line expect(4, ?v1_2(genErr, commitFailed), 1, any), 3575% unfortunatly we don't know if we'll get undoFailed or commitFailed. 3576% it depends on which order the agent traverses the varbind list. 3577% s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]), 3578% ?line expect(5, ?v1_2(genErr, undoFailed), 1, any), 3579 s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]), 3580 ?line expect(6, genErr, 2, any). 3581 3582%% Req. Klas3, Klas4 3583bad_return() -> 3584 g([[fStatus4,4], 3585 [fName4,4]]), 3586 ?line expect(4, genErr, 2, any), 3587 g([[fStatus4,5], 3588 [fName4,5]]), 3589 ?line expect(5, genErr, 1, any), 3590 g([[fStatus4,6], 3591 [fName4,6]]), 3592 ?line expect(6, genErr, 2, any), 3593 gn([[fStatus4,7], 3594 [fName4,7]]), 3595 ?line expect(7, genErr, 2, any), 3596 gn([[fStatus4,8], 3597 [fName4,8]]), 3598 ?line expect(8, genErr, 1, any), 3599 gn([[fStatus4,9], 3600 [fName4,9]]), 3601 ?line expect(9, genErr, 2, any). 3602 3603 3604%%%----------------------------------------------------------------- 3605%%% Test the implementation of standard mibs. 3606%%% We should *at least* try to GET all variables, just to make 3607%%% sure the instrumentation functions work. 3608%%% Note that many of the functions in the standard mib is 3609%%% already tested by the normal tests. 3610%%%----------------------------------------------------------------- 3611 3612 3613 3614%%----------------------------------------------------------------- 3615%% For this test, the agent is configured for v1. 3616%% o Test the counters and control objects in SNMP-STANDARD-MIB 3617%%----------------------------------------------------------------- 3618snmp_standard_mib(suite) -> []; 3619snmp_standard_mib(Config) when list(Config) -> 3620 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 3621 ?DBG("snmp_standard_mib -> std_mib_init", []), 3622 try_test(std_mib_init), 3623 3624 ?DBG("snmp_standard_mib -> std_mib_a", []), 3625 InBadVsns = try_test(std_mib_a), 3626 put(vsn, v2), 3627 ?DBG("snmp_standard_mib -> std_mib_read", []), 3628 try_test(std_mib_read), 3629 put(vsn, v1), 3630 3631 ?DBG("snmp_standard_mib -> std_mib_b (~w)", [InBadVsns]), 3632 Bad = try_test(std_mib_b, [InBadVsns]), 3633 ?DBG("snmp_standard_mib -> std_mib_read (community: 'bad community')", []), 3634 try_test(std_mib_read, [], [{community, "bad community"}]), 3635 ?DBG("snmp_standard_mib -> std_mib_write (community: 'public')", []), 3636 try_test(std_mib_write, [], [{community, "public"}]), 3637 ?DBG("snmp_standard_mib -> std_mib_asn_err", []), 3638 try_test(std_mib_asn_err), 3639 ?DBG("snmp_standard_mib -> std_mib_c (~w)", [Bad]), 3640 try_test(std_mib_c, [Bad]), 3641 ?DBG("snmp_standard_mib -> std_mib_a", []), 3642 try_test(standard_mib_a), 3643 3644 ?DBG("snmp_standard_mib -> std_mib_finish", []), 3645 try_test(std_mib_finish), 3646 ?DBG("snmp_standard_mib -> std_mib_test_finish", []), 3647 try_test(standard_mib_test_finish, [], [{community, "bad community"}]). 3648 3649%% Req. SNMP-STANDARD-MIB 3650standard_mib_a() -> 3651 ?line [OutPkts] = get_req(2, [[snmpOutPkts,0]]), 3652 ?line [OutPkts2] = get_req(3, [[snmpOutPkts,0]]), 3653 ?line OutPkts2 = OutPkts + 1, 3654 %% There are some more counters we could test here, but it's not that 3655 %% important, since they are removed from SNMPv2-MIB. 3656 ok. 3657 3658%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB 3659std_mib_init() -> 3660 %% disable authentication failure traps. (otherwise w'd get many of 3661 %% them - this is also a test to see that it works). 3662 s([{[snmpEnableAuthenTraps,0], 2}]), 3663 ?line expect(1, [{[snmpEnableAuthenTraps, 0], 2}]). 3664 3665%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB 3666std_mib_finish() -> 3667 %% enable again 3668 s([{[snmpEnableAuthenTraps,0], 1}]), 3669 ?line expect(1, [{[snmpEnableAuthenTraps, 0], 1}]). 3670 3671%% Req. SNMP-STANDARD-MIB 3672standard_mib_test_finish() -> 3673 %% force a authenticationFailure 3674 std_mib_write(), 3675 %% check that we got a trap 3676 ?line expect(2, trap, [1,2,3], 4, 0, []). 3677 3678%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB 3679std_mib_read() -> 3680 ?DBG("std_mib_read -> entry", []), 3681 g([[sysUpTime,0]]), % try a bad <something>; msg dropped, no reply 3682 ?DBG("std_mib_read -> await timeout (i.e. no reply)", []), 3683 ?line expect(1, timeout). % make sure we don't get a trap! 3684 3685 3686%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB 3687std_mib_write() -> 3688 ?DBG("std_mib_write -> entry", []), 3689 s([{[sysLocation, 0], "new_value"}]). 3690 3691%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB 3692std_mib_asn_err() -> 3693 snmp_test_mgr:send_bytes([48,99,67,12,0,0,0,0,0,0,5]). 3694 3695%%----------------------------------------------------------------- 3696%% For this test, the agent is configured for v2 and v3. 3697%% o Test the counters and control objects in SNMPv2-MIB 3698%%----------------------------------------------------------------- 3699snmpv2_mib_2(suite) -> []; 3700snmpv2_mib_2(Config) when list(Config) -> 3701 ?LOG("snmpv2_mib_2 -> start",[]), 3702 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 3703 3704 ?DBG("snmpv2_mib_2 -> standard mib init",[]), 3705 try_test(std_mib_init), 3706 3707 ?DBG("snmpv2_mib_2 -> get number of (so far) bad versions",[]), 3708 InBadVsns = try_test(std_mib_a), 3709 3710 ?DBG("snmpv2_mib_2 -> make a bad version read",[]), 3711 put(vsn, v1), 3712 try_test(std_mib_read), 3713 3714 ?DBG("snmpv2_mib_2 -> bad version read",[]), 3715 put(vsn, v2), 3716 Bad = try_test(std_mib_b, [InBadVsns]), 3717 3718 ?DBG("snmpv2_mib_2 -> read with bad community",[]), 3719 try_test(std_mib_read, [], [{community, "bad community"}]), 3720 3721 ?DBG("snmpv2_mib_2 -> write with public community",[]), 3722 try_test(std_mib_write, [], [{community, "public"}]), 3723 3724 ?DBG("snmpv2_mib_2 -> asn err",[]), 3725 try_test(std_mib_asn_err), 3726 3727 ?DBG("snmpv2_mib_2 -> check counters",[]), 3728 try_test(std_mib_c, [Bad]), 3729 3730 ?DBG("snmpv2_mib_2 -> get som counters",[]), 3731 try_test(snmpv2_mib_a), 3732 3733 ?DBG("snmpv2_mib_2 -> enable auth traps, and await some",[]), 3734 try_test(std_mib_finish), 3735 3736 ?DBG("snmpv2_mib_2 -> force auth failure, and await trap, " 3737 "then disable auth traps",[]), 3738 try_test(snmpv2_mib_test_finish, [], [{community, "bad community"}]), 3739 3740 ?LOG("snmpv2_mib_2 -> done",[]). 3741 3742%% Req. SNMPv2-MIB 3743snmpv2_mib_3(suite) -> []; 3744snmpv2_mib_3(Config) when list(Config) -> 3745 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 3746 3747 InBadVsns = try_test(std_mib_a), 3748 put(vsn, v1), 3749 try_test(std_mib_read), 3750 put(vsn, v3), 3751 _Bad = try_test(std_mib_b, [InBadVsns]), 3752 try_test(snmpv2_mib_a), 3753 3754 try_test(std_mib_finish). 3755 3756-define(authenticationFailure, [1,3,6,1,6,3,1,1,5,5]). 3757 3758%% Req. SNMPv2-MIB 3759snmpv2_mib_test_finish() -> 3760 %% force a authenticationFailure 3761 ?DBG("ma_v2_inform -> write to std mib",[]), 3762 std_mib_write(), 3763 3764 %% check that we got a trap 3765 ?DBG("ma_v2_inform -> await trap",[]), 3766 ?line expect(2, v2trap, [{[sysUpTime,0], any}, 3767 {[snmpTrapOID,0], ?authenticationFailure}]), 3768 3769 %% and the the inform 3770 ?DBG("ma_v2_inform -> await inform",[]), 3771 ?line expect(2, {inform,true}, [{[sysUpTime,0], any}, 3772 {[snmpTrapOID,0],?authenticationFailure}]). 3773 3774%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB 3775std_mib_a() -> 3776 ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), 3777 ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), 3778 ?line InPkts2 = InPkts + 1, 3779 3780 ?line [InBadVsns] = get_req(4, [[snmpInBadVersions,0]]), 3781 InBadVsns. 3782 3783%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB 3784std_mib_b(InBadVsns) -> 3785 ?line [InBadVsns2] = get_req(1, [[snmpInBadVersions,0]]), 3786 ?line InBadVsns2 = InBadVsns + 1, 3787 ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), 3788 ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), 3789 ?line InPkts2 = InPkts + 1, 3790 ?line [InBadCommunityNames, InBadCommunityUses, InASNErrs] = 3791 get_req(4, [[snmpInBadCommunityNames,0], 3792 [snmpInBadCommunityUses,0], 3793 [snmpInASNParseErrs, 0]]), 3794 {InBadCommunityNames, InBadCommunityUses, InASNErrs}. 3795 3796%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB 3797std_mib_c({InBadCommunityNames, InBadCommunityUses, InASNErrs}) -> 3798 ?line [InBadCommunityNames2, InBadCommunityUses2, InASNErrs2] = 3799 get_req(1, [[snmpInBadCommunityNames,0], 3800 [snmpInBadCommunityUses,0], 3801 [snmpInASNParseErrs, 0]]), 3802 ?line InBadCommunityNames2 = InBadCommunityNames + 1, 3803 ?line InBadCommunityUses2 = InBadCommunityUses + 1, 3804 ?line InASNErrs2 = InASNErrs + 1. 3805 3806%% Req. SNMPv2-MIB 3807snmpv2_mib_a() -> 3808 ?line [SetSerial] = get_req(2, [[snmpSetSerialNo,0]]), 3809 s([{[snmpSetSerialNo,0], SetSerial}, {[sysLocation, 0], "val2"}]), 3810 ?line expect(3, [{[snmpSetSerialNo,0], SetSerial}, 3811 {[sysLocation, 0], "val2"}]), 3812 s([{[sysLocation, 0], "val3"}, {[snmpSetSerialNo,0], SetSerial}]), 3813 ?line expect(4, inconsistentValue, 2, 3814 [{[sysLocation, 0], "val3"}, 3815 {[snmpSetSerialNo,0], SetSerial}]), 3816 ?line ["val2"] = get_req(5, [[sysLocation,0]]). 3817 3818 3819%%----------------------------------------------------------------- 3820%% o Bad community uses/name is tested already 3821%% in SNMPv2-MIB and STANDARD-MIB. 3822%% o Test add/deletion of rows. 3823%%----------------------------------------------------------------- 3824snmp_community_mib(suite) -> []; 3825snmp_community_mib(Config) when list(Config) -> 3826 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 3827 ?line load_master_std("SNMP-COMMUNITY-MIB"), 3828 try_test(snmp_community_mib), 3829 ?line unload_master("SNMP-COMMUNITY-MIB"). 3830 3831snmp_community_mib_2(X) -> snmp_community_mib(X). 3832 3833%% Req. SNMP-COMMUNITY-MIB 3834snmp_community_mib() -> 3835 ?INF("NOT YET IMPLEMENTED", []), 3836 nyi. 3837 3838%%----------------------------------------------------------------- 3839%% o Test engine boots / time 3840%%----------------------------------------------------------------- 3841snmp_framework_mib(suite) -> []; 3842snmp_framework_mib(Config) when list(Config) -> 3843 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 3844 ?line load_master_std("SNMP-FRAMEWORK-MIB"), 3845 try_test(snmp_framework_mib), 3846 ?line unload_master("SNMP-FRAMEWORK-MIB"). 3847 3848snmp_framework_mib_2(X) -> snmp_framework_mib(X). 3849 3850snmp_framework_mib_3(suite) -> []; 3851snmp_framework_mib_3(Config) when list(Config) -> 3852 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 3853 try_test(snmp_framework_mib). 3854 3855 3856%% Req. SNMP-FRAMEWORK-MIB 3857snmp_framework_mib() -> 3858 ?line ["agentEngine"] = get_req(1, [[snmpEngineID,0]]), 3859 ?line [EngineTime] = get_req(2, [[snmpEngineTime,0]]), 3860 sleep(5000), 3861 ?line [EngineTime2] = get_req(3, [[snmpEngineTime,0]]), 3862 if 3863 EngineTime+7 < EngineTime2 -> 3864 ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); 3865 EngineTime+4 > EngineTime2 -> 3866 ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); 3867 true -> ok 3868 end, 3869 ?line case get_req(4, [[snmpEngineBoots,0]]) of 3870 [Boots] when integer(Boots) -> ok; 3871 Else -> ?FAIL(Else) 3872 end, 3873 ok. 3874 3875%%----------------------------------------------------------------- 3876%% o Test the counters 3877%%----------------------------------------------------------------- 3878snmp_mpd_mib_3(suite) -> []; 3879snmp_mpd_mib_3(Config) when list(Config) -> 3880 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 3881 UnknownPDUHs = try_test(snmp_mpd_mib_a), 3882 try_test(snmp_mpd_mib_b, [], [{context_engine_id, "bad engine"}]), 3883 try_test(snmp_mpd_mib_c, [UnknownPDUHs]). 3884 3885 3886%% Req. SNMP-MPD-MIB 3887snmp_mpd_mib_a() -> 3888 ?line [UnknownSecs, InvalidMsgs] = 3889 get_req(1, [[snmpUnknownSecurityModels,0], 3890 [snmpInvalidMsgs,0]]), 3891 Pdu = #pdu{type = 'get-request', 3892 request_id = 23, 3893 error_status = noError, 3894 error_index = 0, 3895 varbinds = []}, 3896 SPdu = #scopedPdu{contextEngineID = "agentEngine", 3897 contextName = "", 3898 data = Pdu}, 3899 ?line SPDUBytes = snmp_pdus:enc_scoped_pdu(SPdu), 3900 V3Hdr1 = #v3_hdr{msgID = 21, 3901 msgMaxSize = 484, 3902 msgFlags = [7], 3903 msgSecurityModel = 23, % bad sec model 3904 msgSecurityParameters = []}, 3905 V3Hdr2 = #v3_hdr{msgID = 21, 3906 msgMaxSize = 484, 3907 msgFlags = [6], % bad flag combination 3908 msgSecurityModel = 3, 3909 msgSecurityParameters = []}, 3910 Message1 = #message{version = 'version-3', vsn_hdr = V3Hdr1, 3911 data = SPDUBytes}, 3912 Message2 = #message{version = 'version-3', vsn_hdr = V3Hdr2, 3913 data = SPDUBytes}, 3914 ?line MsgBytes1 = snmp_pdus:enc_message_only(Message1), 3915 ?line MsgBytes2 = snmp_pdus:enc_message_only(Message2), 3916 snmp_test_mgr:send_bytes(MsgBytes1), 3917 snmp_test_mgr:send_bytes(MsgBytes2), 3918 3919 ?line [UnknownSecs2, InvalidMsgs2, UnknownPDUHs] = 3920 get_req(1, [[snmpUnknownSecurityModels,0], 3921 [snmpInvalidMsgs,0], 3922 [snmpUnknownPDUHandlers, 0]]), 3923 ?line UnknownSecs2 = UnknownSecs + 1, 3924 ?line InvalidMsgs2 = InvalidMsgs + 1, 3925 UnknownPDUHs. 3926 3927-define(snmpUnknownPDUHandlers_instance, [1,3,6,1,6,3,11,2,1,3,0]). 3928snmp_mpd_mib_b() -> 3929 g([[sysUpTime,0]]), 3930 ?line expect(1, report, [{?snmpUnknownPDUHandlers_instance, any}]). 3931 3932 3933snmp_mpd_mib_c(UnknownPDUHs) -> 3934 ?line [UnknownPDUHs2] = get_req(1, [[snmpUnknownPDUHandlers, 0]]), 3935 ?line UnknownPDUHs2 = UnknownPDUHs + 1. 3936 3937 3938snmp_target_mib(suite) -> []; 3939snmp_target_mib(Config) when list(Config) -> 3940 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 3941 ?line load_master_std("SNMP-TARGET-MIB"), 3942 try_test(snmp_target_mib), 3943 ?line unload_master("SNMP-TARGET-MIB"). 3944 3945snmp_target_mib_2(X) -> snmp_target_mib(X). 3946 3947snmp_target_mib_3(X) -> snmp_target_mib(X). 3948 3949snmp_target_mib() -> 3950 ?INF("NOT YET IMPLEMENTED", []), 3951 nyi. 3952 3953snmp_notification_mib(suite) -> []; 3954snmp_notification_mib(Config) when list(Config) -> 3955 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 3956 ?line load_master_std("SNMP-NOTIFICATION-MIB"), 3957 try_test(snmp_notification_mib), 3958 ?line unload_master("SNMP-NOTIFICATION-MIB"). 3959 3960snmp_notification_mib_2(X) -> snmp_notification_mib(X). 3961 3962snmp_notification_mib_3(X) -> snmp_notification_mib(X). 3963 3964snmp_notification_mib() -> 3965 ?INF("NOT YET IMPLEMENTED", []), 3966 nyi. 3967 3968%%----------------------------------------------------------------- 3969%% o add/delete views and try them 3970%% o try boundaries 3971%%----------------------------------------------------------------- 3972snmp_view_based_acm_mib(suite) -> []; 3973snmp_view_based_acm_mib(Config) when list(Config) -> 3974 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 3975 ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), 3976 ?line load_master("Test2"), 3977 snmp_view_based_acm_mib(), 3978 ?line unload_master("Test2"), 3979 ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). 3980 3981snmp_view_based_acm_mib_2(X) -> snmp_view_based_acm_mib(X). 3982 3983snmp_view_based_acm_mib_3(X) -> snmp_view_based_acm_mib(X). 3984 3985snmp_view_based_acm_mib() -> 3986 snmpa:verbosity(net_if,trace), 3987 snmpa:verbosity(master_agent,trace), 3988 ?LOG("start snmp_view_based_acm_mib test",[]), 3989 %% The user "no-rights" is present in USM, and is mapped to security 3990 %% name 'no-rights", which is not present in VACM. 3991 %% So, we'll add rights for it, try them and delete them. 3992 %% We'll give "no-rights" write access to tDescr.0 and read access 3993 %% to tDescr2.0 3994 %% These are the options we'll use to the mgr 3995 Opts = [{user, "no-rights"}, {community, "no-rights"}], 3996 %% Find the valid secmodel, and one invalid secmodel. 3997 {SecMod, InvSecMod} = 3998 case get(vsn) of 3999 v1 -> {?SEC_V1, ?SEC_V2C}; 4000 v2 -> {?SEC_V2C, ?SEC_USM}; 4001 v3 -> {?SEC_USM, ?SEC_V1} 4002 end, 4003 ?DBG("assign rights for 'no-rights'",[]), 4004 ?line try_test(use_no_rights, [], Opts), 4005 4006 %% Now, add a mapping from "no-rights" -> "no-rights-group" 4007 GRow1Status = [vacmSecurityToGroupStatus,[SecMod, 9,"no-rights"]], 4008 GRow1 = 4009 [{[vacmGroupName, [SecMod, 9,"no-rights"]], "no-rights-group"}, 4010 {GRow1Status, ?createAndGo}], 4011 ?DBG("set '~p'",[GRow1]), 4012 ?line try_test(do_set, [GRow1]), 4013 4014 ?DBG("assign rights for 'no-rights'",[]), 4015 ?line try_test(use_no_rights, [], Opts), 4016 4017 %% Create a mapping for another sec model, and make sure it dosn't 4018 %% give us access 4019 GRow2Status = [vacmSecurityToGroupStatus,[InvSecMod, 9,"no-rights"]], 4020 GRow2 = [{[vacmGroupName, [InvSecMod, 9, "no-rights"]], "initial"}, 4021 {GRow2Status, ?createAndGo}], 4022 4023 ?DBG("set '~p'",[GRow2]), 4024 ?line try_test(do_set, [GRow2]), 4025 4026 ?DBG("assign rights for 'no-rights'",[]), 4027 ?line try_test(use_no_rights, [], Opts), 4028 4029 %% Delete that row 4030 ?line try_test(del_row, [GRow2Status]), 4031 4032 RVName = "rv_name", 4033 WVName = "wv_name", 4034 4035 %% Access row 4036 ARow1Idx = [15 | "no-rights-group"] ++ [0, ?SEC_ANY, 1], 4037 ARow1Status = [vacmAccessStatus, ARow1Idx], 4038 ARow1 = [{[vacmAccessContextMatch, ARow1Idx], 1}, 4039 {[vacmAccessReadViewName, ARow1Idx], RVName}, 4040 {[vacmAccessWriteViewName, ARow1Idx], WVName}, 4041 {ARow1Status, ?createAndGo}], 4042 4043 %% This access row would give acces, if InvSecMod was valid. 4044 ARow2Idx = [15 | "no-rights-group"] ++ [0, InvSecMod, 1], 4045 ARow2Status = [vacmAccessStatus, ARow2Idx], 4046 ARow2 = [{[vacmAccessContextMatch, ARow2Idx], 1}, 4047 {[vacmAccessReadViewName, ARow2Idx], "internet"}, 4048 {[vacmAccessWriteViewName, ARow2Idx], "internet"}, 4049 {ARow2Status, ?createAndGo}], 4050 4051 ?line try_test(do_set, [ARow2]), 4052 4053 ?line try_test(use_no_rights, [], Opts), 4054 4055 %% Delete that row 4056 ?line try_test(del_row, [ARow2Status]), 4057 4058 4059 %% Add valid row 4060 ?line try_test(do_set, [ARow1]), 4061 4062 ?line try_test(use_no_rights, [], Opts), 4063 4064 %% Create the view family 4065 VRow1Idx = mk_ln(RVName) ++ mk_ln(?xDescr), % object access 4066 VRow2Idx = mk_ln(RVName) ++ mk_ln(?xDescr2 ++ [0]), % instance access 4067 VRow3Idx = mk_ln(WVName) ++ mk_ln(?xDescr), % object access 4068 VRow4Idx = mk_ln(WVName) ++ mk_ln(?xDescr ++ [0]), % instance access 4069 VRow1Status = [vacmViewTreeFamilyStatus, VRow1Idx], 4070 VRow2Status = [vacmViewTreeFamilyStatus, VRow2Idx], 4071 VRow3Status = [vacmViewTreeFamilyStatus, VRow3Idx], 4072 VRow4Status = [vacmViewTreeFamilyStatus, VRow4Idx], 4073 4074 ?line try_test(add_row, [VRow1Status]), 4075 ?line try_test(add_row, [VRow2Status]), 4076 ?line try_test(add_row, [VRow3Status]), 4077 4078 %% We're supposed to have access now... 4079 ?line try_test(use_rights, [], Opts), 4080 4081 %% Change Row3 to Row4 4082 ?line try_test(del_row, [VRow3Status]), 4083 ?line try_test(add_row, [VRow4Status]), 4084 4085 %% We should still have access... 4086 ?line try_test(use_rights, [], Opts), 4087 4088 %% Delete rows 4089 ?line try_test(del_row, [GRow1Status]), 4090 4091 ?line try_test(use_no_rights, [], Opts), 4092 4093 %% Delete rest of rows 4094 ?line try_test(del_row, [ARow1Status]), 4095 ?line try_test(del_row, [VRow1Status]), 4096 ?line try_test(del_row, [VRow2Status]), 4097 ?line try_test(del_row, [VRow4Status]), 4098 4099 ?line try_test(use_no_rights, [], Opts), 4100 snmpa:verbosity(master_agent,log). 4101 4102do_set(Row) -> 4103 s(Row), 4104 expect(1, Row). 4105 4106add_row(RowStatus) -> 4107 s([{RowStatus, ?createAndGo}]), 4108 expect(1, [{RowStatus, ?createAndGo}]). 4109 4110del_row(RowStatus) -> 4111 s([{RowStatus, ?destroy}]), 4112 expect(1, [{RowStatus, ?destroy}]). 4113 4114 4115 4116use_no_rights() -> 4117 g([[xDescr,0]]), 4118 ?v1_2_3(expect(11, noSuchName, 1, any), 4119 expect(12, [{[xDescr,0], noSuchObject}]), 4120 expect(13, authorizationError, 1, any)), 4121 g([[xDescr2,0]]), 4122 ?v1_2_3(expect(21, noSuchName, 1, any), 4123 expect(22, [{[xDescr2,0], noSuchObject}]), 4124 expect(23, authorizationError, 1, any)), 4125 gn([[xDescr]]), 4126 ?v1_2_3(expect(31, noSuchName, 1, any), 4127 expect(32, [{[xDescr], endOfMibView}]), 4128 expect(33, authorizationError, 1, any)), 4129 s([{[xDescr,0], "tryit"}]), 4130 ?v1_2_3(expect(41, noSuchName, 1, any), 4131 expect(42, noAccess, 1, any), 4132 expect(43, authorizationError, 1, any)). 4133 4134 4135use_rights() -> 4136 g([[xDescr,0]]), 4137 expect(1, [{[xDescr,0], any}]), 4138 g([[xDescr2,0]]), 4139 expect(2, [{[xDescr2,0], any}]), 4140 s([{[xDescr,0], "tryit"}]), 4141 expect(3, noError, 0, any), 4142 g([[xDescr,0]]), 4143 expect(4, [{[xDescr,0], "tryit"}]). 4144 4145mk_ln(X) -> 4146 [length(X) | X]. 4147 4148%%----------------------------------------------------------------- 4149%% o add/delete users and try them 4150%% o test all secLevels 4151%% o test all combinations of protocols 4152%% o try bad ops; check counters 4153%%----------------------------------------------------------------- 4154snmp_user_based_sm_mib_3(suite) -> []; 4155snmp_user_based_sm_mib_3(Config) when list(Config) -> 4156 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 4157 _AgentDir = ?config(agent_dir, Config), 4158 ?line load_master_std("SNMP-USER-BASED-SM-MIB"), 4159 4160 %% The newUser used here already has VACM access. 4161 4162 %% Add a new user in the simplest way; just createAndGo 4163 try_test(v3_sync, [[{usm_add_user1, []}]], 4164 [{sec_level, authPriv}, {user, "privDES"}]), 4165 4166 %% Try to use the new user 4167 ?line load_master("Test2"), 4168 try_test(v3_sync, [[{usm_use_user, []}]], 4169 [{sec_level, authPriv}, {user, "newUser"}]), 4170 ?line unload_master("Test2"), 4171 4172 ShaKey1 = snmp:passwd2localized_key(sha, "new sha password", "agentEngine"), 4173 DesKey1 = lists:sublist(ShaKey1, 16), 4174 4175 %% Change the new user's keys - 1 4176 try_test(v3_sync, [[{usm_key_change1, [ShaKey1, DesKey1]}]], 4177 [{sec_level, authPriv}, {user, "newUser"}]), 4178 4179 %% Try to use the new keys 4180 MgrDir = ?config(mgr_dir, Config), 4181 ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), 4182 ?line load_master("Test2"), 4183 try_test(v3_sync, [[{usm_use_user, []}]], 4184 [{sec_level, authPriv}, {user, "newUser"}]), 4185 ?line unload_master("Test2"), 4186 4187 ShaKey2 = snmp:passwd2localized_key(sha, "newer password", "agentEngine"), 4188 DesKey2 = lists:sublist(ShaKey2, 16), 4189 4190 %% Change the new user's keys - 2 4191 ?line try_test(v3_sync, 4192 [[{usm_key_change2, [ShaKey1, DesKey1, ShaKey2, DesKey2]}]], 4193 [{sec_level, authPriv}, {user, "newUser"}]), 4194 4195 %% Try to use the new keys 4196 reset_usm_mgr(MgrDir), 4197 ?line rewrite_usm_mgr(MgrDir, ShaKey2, DesKey2), 4198 ?line load_master("Test2"), 4199 ?line try_test(v3_sync, [[{usm_use_user, []}]], 4200 [{sec_level, authPriv}, {user, "newUser"}]), 4201 ?line unload_master("Test2"), 4202 reset_usm_mgr(MgrDir), 4203 4204 %% Change the new user's keys - 3 4205 ?line try_test(v3_sync, 4206 [[{usm_key_change3, [ShaKey2, DesKey2, ShaKey1, DesKey1]}]], 4207 [{sec_level, authPriv}, {user, "privDES"}]), 4208 4209 %% Try to use the new keys 4210 ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), 4211 ?line load_master("Test2"), 4212 try_test(v3_sync, [[{usm_use_user, []}]], 4213 [{sec_level, authPriv}, {user, "newUser"}]), 4214 ?line unload_master("Test2"), 4215 reset_usm_mgr(MgrDir), 4216 4217 %% Try some read requests 4218 ?line try_test(v3_sync, [[{usm_read, []}]], 4219 [{sec_level, authPriv}, {user, "privDES"}]), 4220 4221 %% Delete the new user 4222 ?line try_test(v3_sync, [[{usm_del_user, []}]], 4223 [{sec_level, authPriv}, {user, "privDES"}]), 4224 4225 %% Try some bad requests 4226 ?line try_test(v3_sync, [[{usm_bad, []}]], 4227 [{sec_level, authPriv}, {user, "privDES"}]), 4228 4229 ?line unload_master("SNMP-USER-BASED-SM-MIB"). 4230 4231-define(usmUserSecurityName, [1,3,6,1,6,3,15,1,2,2,1,3]). 4232 4233usm_add_user1() -> 4234 NewRowIndex = [11,"agentEngine", 7, "newUser"], 4235 RowPointer = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], 4236 Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer}, 4237 {[usmUserStatus, NewRowIndex], ?createAndGo}], 4238 ?line s(Vbs1), 4239 ?line expect(1, Vbs1), 4240 ok. 4241 4242usm_use_user() -> 4243 v2_proc(). 4244 4245 4246%% Change own public keys 4247usm_key_change1(ShaKey, DesKey) -> 4248 NewRowIndex = [11,"agentEngine", 7, "newUser"], 4249 ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, 4250 "passwd_shaxxxxxxxxxx", 4251 ShaKey), 4252 DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, 4253 "passwd_desxxxxxx", 4254 DesKey), 4255 Vbs1 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, 4256 {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], 4257 s(Vbs1), 4258 ?line expect(1, Vbs1). 4259 4260%% Change own private keys 4261usm_key_change2(OldShaKey, OldDesKey, ShaKey, DesKey) -> 4262 NewRowIndex = [11,"agentEngine", 7, "newUser"], 4263 ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, 4264 OldShaKey, 4265 ShaKey), 4266 DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, 4267 OldDesKey, 4268 DesKey), 4269 Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}, 4270 {[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], 4271 s(Vbs1), 4272 ?line expect(1, Vbs1). 4273 4274%% Change other's public keys 4275usm_key_change3(OldShaKey, OldDesKey, ShaKey, DesKey) -> 4276 NewRowIndex = [11,"agentEngine", 7, "newUser"], 4277 ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, 4278 OldShaKey, 4279 ShaKey), 4280 DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, 4281 OldDesKey, 4282 DesKey), 4283 Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}], 4284 s(Vbs1), 4285 ?line expect(1, noAccess, 1, any), 4286 Vbs2 = [{[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], 4287 s(Vbs2), 4288 ?line expect(2, noAccess, 1, any), 4289 4290 4291 Vbs3 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, 4292 {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], 4293 s(Vbs3), 4294 ?line expect(1, Vbs3). 4295 4296usm_read() -> 4297 NewRowIndex = [11,"agentEngine", 7, "newUser"], 4298 ?line g([[usmUserSecurityName, NewRowIndex], 4299 [usmUserCloneFrom, NewRowIndex], 4300 [usmUserAuthKeyChange, NewRowIndex], 4301 [usmUserOwnAuthKeyChange, NewRowIndex], 4302 [usmUserPrivKeyChange, NewRowIndex], 4303 [usmUserOwnPrivKeyChange, NewRowIndex]]), 4304 ?line expect(1, 4305 [{[usmUserSecurityName, NewRowIndex], "newUser"}, 4306 {[usmUserCloneFrom, NewRowIndex], [0,0]}, 4307 {[usmUserAuthKeyChange, NewRowIndex], ""}, 4308 {[usmUserOwnAuthKeyChange, NewRowIndex], ""}, 4309 {[usmUserPrivKeyChange, NewRowIndex], ""}, 4310 {[usmUserOwnPrivKeyChange, NewRowIndex], ""}]), 4311 ok. 4312 4313 4314 4315usm_del_user() -> 4316 NewRowIndex = [11,"agentEngine", 7, "newUser"], 4317 Vbs1 = [{[usmUserStatus, NewRowIndex], ?destroy}], 4318 ?line s(Vbs1), 4319 ?line expect(1, Vbs1), 4320 ok. 4321 4322-define(usmUserCloneFrom, [1,3,6,1,6,3,15,1,2,2,1,4]). 4323 4324-define(usmNoAuthProtocol, [1,3,6,1,6,3,10,1,1,1]). 4325 4326-define(usmHMACMD5AuthProtocol, [1,3,6,1,6,3,10,1,1,2]). 4327 4328-define(usmHMACSHAAuthProtocol, [1,3,6,1,6,3,10,1,1,3]). 4329 4330-define(usmNoPrivProtocol, [1,3,6,1,6,3,10,1,2,1]). 4331 4332-define(usmDESPrivProtocol, [1,3,6,1,6,3,10,1,2,2]). 4333 4334usm_bad() -> 4335 NewRowIndex = [11,"agentEngine", 7, "newUser"], 4336 RowPointer1 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDOS"], 4337 Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer1}, 4338 {[usmUserStatus, NewRowIndex], ?createAndGo}], 4339 ?line s(Vbs1), 4340 ?line expect(1, inconsistentName, 1, any), 4341 4342 RowPointer2 = ?usmUserCloneFrom ++ [11|"agentEngine"] ++ [7|"privDES"], 4343 Vbs2 = [{[usmUserCloneFrom, NewRowIndex], RowPointer2}, 4344 {[usmUserStatus, NewRowIndex], ?createAndGo}], 4345 ?line s(Vbs2), 4346 ?line expect(2, wrongValue, 1, any), 4347 4348 RowPointer3 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], 4349 Vbs3 = [{[usmUserCloneFrom, NewRowIndex], RowPointer3}, 4350 {[usmUserStatus, NewRowIndex], ?createAndGo}], 4351 ?line s(Vbs3), 4352 ?line expect(3, Vbs3), 4353 ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmNoAuthProtocol}]), 4354 ?line expect(4, inconsistentValue, 1, any), 4355 ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmHMACMD5AuthProtocol}]), 4356 ?line expect(5, inconsistentValue, 1, any), 4357 ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmDESPrivProtocol}]), 4358 ?line expect(6, wrongValue, 1, any), 4359 ?line s([{[usmUserPrivProtocol, NewRowIndex], ?usmHMACSHAAuthProtocol}]), 4360 ?line expect(7, wrongValue, 1, any), 4361 4362 Vbs4 = [{[usmUserStatus, NewRowIndex], ?destroy}], 4363 ?line s(Vbs4), 4364 ?line expect(1, Vbs4), 4365 4366 ok. 4367 4368 4369%%----------------------------------------------------------------- 4370%% Loop through entire MIB, to make sure that all instrum. funcs 4371%% works. 4372%% Load all std mibs that are not loaded by default. 4373%%----------------------------------------------------------------- 4374loop_mib(suite) -> []; 4375loop_mib(Config) when list(Config) -> 4376 ?LOG("loop_mib -> initiate case",[]), 4377 %% snmpa:verbosity(master_agent,debug), 4378 %% snmpa:verbosity(mib_server,info), 4379 {SaNode, MgrNode, MibDir} = init_case(Config), 4380 ?DBG("loop_mib -> ~n" 4381 "\tSaNode: ~p~n" 4382 "\tMgrNode: ~p~n" 4383 "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), 4384 ?DBG("loop_mib -> load mib SNMP-COMMUNITY-MIB",[]), 4385 ?line load_master_std("SNMP-COMMUNITY-MIB"), 4386 ?DBG("loop_mib -> load mib SNMP-MPD-MIB",[]), 4387 ?line load_master_std("SNMP-MPD-MIB"), 4388 ?DBG("loop_mib -> load mib SNMP-TARGET-MIB",[]), 4389 ?line load_master_std("SNMP-TARGET-MIB"), 4390 ?DBG("loop_mib -> load mib SNMP-NOTIFICATION-MIB",[]), 4391 ?line load_master_std("SNMP-NOTIFICATION-MIB"), 4392 ?DBG("loop_mib -> load mib SNMP-FRAMEWORK-MIB",[]), 4393 ?line load_master_std("SNMP-FRAMEWORK-MIB"), 4394 ?DBG("loop_mib -> load mib SNMP-VIEW-BASED-ACM-MIB",[]), 4395 ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), 4396 ?DBG("loop_mib -> try",[]), 4397 try_test(loop_mib_1), 4398 ?DBG("loop_mib -> unload mib SNMP-COMMUNITY-MIB",[]), 4399 ?line unload_master("SNMP-COMMUNITY-MIB"), 4400 ?DBG("loop_mib -> unload mib SNMP-MPD-MIB",[]), 4401 ?line unload_master("SNMP-MPD-MIB"), 4402 ?DBG("loop_mib -> unload mib SNMP-TARGET-MIB",[]), 4403 ?line unload_master("SNMP-TARGET-MIB"), 4404 ?DBG("loop_mib -> unload mib SNMP-NOTIFICATION-MIB",[]), 4405 ?line unload_master("SNMP-NOTIFICATION-MIB"), 4406 ?DBG("loop_mib -> unload mib SNMP-FRAMEWORK-MIB",[]), 4407 ?line unload_master("SNMP-FRAMEWORK-MIB"), 4408 ?DBG("loop_mib -> unload mib SNMP-VIEW-BASED-ACM-MIB",[]), 4409 ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), 4410 %% snmpa:verbosity(master_agent,log), 4411 %% snmpa:verbosity(mib_server,silence), 4412 ?LOG("loop_mib -> done",[]). 4413 4414 4415loop_mib_2(suite) -> []; 4416loop_mib_2(Config) when list(Config) -> 4417 ?LOG("loop_mib_2 -> initiate case",[]), 4418 {SaNode, MgrNode, MibDir} = init_case(Config), 4419 ?DBG("loop_mib_2 -> ~n" 4420 "\tSaNode: ~p~n" 4421 "\tMgrNode: ~p~n" 4422 "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), 4423 ?DBG("loop_mib_2 -> load mibs",[]), 4424 ?line load_master_std("SNMP-COMMUNITY-MIB"), 4425 ?line load_master_std("SNMP-MPD-MIB"), 4426 ?line load_master_std("SNMP-TARGET-MIB"), 4427 ?line load_master_std("SNMP-NOTIFICATION-MIB"), 4428 ?line load_master_std("SNMP-FRAMEWORK-MIB"), 4429 ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), 4430 try_test(loop_mib_2), 4431 ?DBG("loop_mib_2 -> unload mibs",[]), 4432 ?line unload_master("SNMP-COMMUNITY-MIB"), 4433 ?line unload_master("SNMP-MPD-MIB"), 4434 ?line unload_master("SNMP-TARGET-MIB"), 4435 ?line unload_master("SNMP-NOTIFICATION-MIB"), 4436 ?line unload_master("SNMP-FRAMEWORK-MIB"), 4437 ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), 4438 ?LOG("loop_mib_2 -> done",[]). 4439 4440 4441loop_mib_3(suite) -> []; 4442loop_mib_3(Config) when list(Config) -> 4443 ?LOG("loop_mib_3 -> initiate case",[]), 4444 {SaNode, MgrNode, MibDir} = init_case(Config), 4445 ?DBG("loop_mib_3 -> ~n" 4446 "\tSaNode: ~p~n" 4447 "\tMgrNode: ~p~n" 4448 "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), 4449 ?DBG("loop_mib_3 -> load mibs",[]), 4450 ?line load_master_std("SNMP-TARGET-MIB"), 4451 ?line load_master_std("SNMP-NOTIFICATION-MIB"), 4452 ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), 4453 ?line load_master_std("SNMP-USER-BASED-SM-MIB"), 4454 try_test(loop_mib_2), 4455 ?DBG("loop_mib_3 -> unload mibs",[]), 4456 ?line unload_master("SNMP-TARGET-MIB"), 4457 ?line unload_master("SNMP-NOTIFICATION-MIB"), 4458 ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), 4459 ?line unload_master("SNMP-USER-BASED-SM-MIB"), 4460 ?LOG("loop_mib_3 -> done",[]). 4461 4462 4463%% Req. As many mibs all possible 4464loop_mib_1() -> 4465 ?DBG("loop_mib_1 -> entry",[]), 4466 N = loop_it_1([1,1], 0), 4467 io:format(user, "found ~w varibles\n", [N]), 4468 ?line N = if N < 100 -> 100; 4469 true -> N 4470 end. 4471 4472 4473loop_it_1(Oid, N) -> 4474 ?DBG("loop_it_1 -> entry with~n" 4475 "\tOid: ~p~n" 4476 "\tN: ~p",[Oid,N]), 4477 case get_next_req([Oid]) of 4478 #pdu{type='get-response', error_status=noError, error_index=0, 4479 varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> 4480 ?DBG("loop_it_1 -> ~n" 4481 "\tNOid: ~p~n" 4482 "\tValue: ~p",[NOid,Value]), 4483 ?line [Value2] = get_req(1, [NOid]), % must not be same 4484 ?DBG("loop_it_1 -> ~n" 4485 "\tValue2: ~p",[Value2]), 4486 loop_it_1(NOid, N+1); 4487 #pdu{type='get-response', error_status=noSuchName, error_index=1, 4488 varbinds=[_]} -> 4489 ?DBG("loop_it_1 -> done",[]), 4490 N; 4491 4492 #pdu{type = Type, error_status = Err, error_index = Idx, 4493 varbinds = Vbs} -> 4494 exit({unexpected_pdu, ?LINE, Type, Err, Idx, Vbs}) 4495 end. 4496 4497%% Req. As many mibs all possible 4498loop_mib_2() -> 4499 ?DBG("loop_mib_1 -> entry",[]), 4500 N = loop_it_2([1,1], 0), 4501 io:format(user, "found ~w varibles\n", [N]), 4502 ?line N = if N < 100 -> 100; 4503 true -> N 4504 end. 4505 4506 4507loop_it_2(Oid, N) -> 4508 ?DBG("loop_it_2 -> entry with~n" 4509 "\tOid: ~p~n" 4510 "\tN: ~p",[Oid,N]), 4511 case get_next_req([Oid]) of 4512 #pdu{type='get-response', error_status=noError, error_index=0, 4513 varbinds=[#varbind{oid = NOid, value = endOfMibView}]} -> 4514 ?DBG("loop_it_2 -> ~n" 4515 "\tNOid: ~p",[NOid]), 4516 N; 4517 #pdu{type='get-response', error_status=noError, error_index=0, 4518 varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> 4519 ?DBG("loop_it_2 -> ~n" 4520 "\tNOid: ~p~n" 4521 "\tValue: ~p",[NOid,Value]), 4522 ?line [Value2] = get_req(1, [NOid]), % must not be same 4523 ?DBG("loop_it_2 -> ~n" 4524 "\tValue2: ~p",[Value2]), 4525 loop_it_2(NOid, N+1) 4526 end. 4527 4528 4529%%%----------------------------------------------------------------- 4530%%% Testing of reported bugs and other tickets. 4531%%%----------------------------------------------------------------- 4532 4533 4534 4535 4536 4537%% These are (ticket) test cases where the initiation has to be done 4538%% individually. 4539 4540%%----------------------------------------------------------------- 4541%% Ticket: OTP-1128 4542%% Slogan: Bug in handling of createAndWait set-requests. 4543%%----------------------------------------------------------------- 4544otp_1128(suite) -> []; 4545otp_1128(Config) when list(Config) -> 4546 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 4547 ?line load_master("OLD-SNMPEA-MIB"), 4548 ?line init_old(), 4549 try_test(otp_1128), 4550 ?line unload_master("OLD-SNMPEA-MIB"). 4551 4552otp_1128_2(X) -> otp_1128(X). 4553 4554otp_1128_3(X) -> otp_1128(X). 4555 4556otp_1128() -> 4557 io:format("Testing bug reported in ticket OTP-1128...~n"), 4558 4559 NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], 4560 NewKeyc4 = [intCommunityAccess,get(mip),is("test")], 4561 NewKeyc5 = [intCommunityStatus,get(mip),is("test")], 4562 4563 s([{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), 4564 ?line expect(28, [{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), 4565 g([NewKeyc5]), 4566 ?line expect(29, [{NewKeyc5, ?notReady}]), 4567 s([{NewKeyc5, ?active}, {NewKeyc3, 2}]), 4568 ?line expect(30, [{NewKeyc5, ?active}, {NewKeyc3, 2}]), 4569 g([NewKeyc5]), 4570 ?line expect(31, [{NewKeyc5, ?active}]), 4571 s([{NewKeyc5, ?destroy}]), 4572 ?line expect(32, [{NewKeyc5, ?destroy}]). 4573 4574%%----------------------------------------------------------------- 4575%% Ticket: OTP-1129, OTP-1169 4576%% Slogan: snmpa:int_to_enum crashes on bad oids 4577%%----------------------------------------------------------------- 4578otp_1129(suite) -> []; 4579otp_1129(Config) when list(Config) -> 4580 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 4581 ?line load_master("Klas3"), 4582 try_test(otp_1129_i, [node()]), 4583 ?line unload_master("Klas3"). 4584 4585otp_1129_2(X) -> otp_1129(X). 4586 4587otp_1129_3(X) -> otp_1129(X). 4588 4589otp_1129_i(MaNode) -> 4590 io:format("Testing bug reported in ticket OTP-1129...~n"), 4591 false = rpc:call(MaNode, snmp, int_to_enum, [iso, 1]), 4592 false = rpc:call(MaNode, snmp, int_to_enum, [isox, 1]). 4593 4594%%----------------------------------------------------------------- 4595%% Ticket: OTP-1131 4596%% Slogan: Agent crashes / erlang node halts if RowIndex in a 4597%% setrequest is of bad type, e.g. an INDEX {INTEGER}, 4598%% and RowIdenx [3,2]. 4599%%----------------------------------------------------------------- 4600otp_1131(suite) -> []; 4601otp_1131(Config) when list(Config) -> 4602 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 4603 ?line load_master("Klas1"), 4604 try_test(otp_1131), 4605 ?line unload_master("Klas1"). 4606 4607otp_1131_2(X) -> otp_1131(X). 4608 4609otp_1131_3(X) -> otp_1131(X). 4610 4611otp_1131() -> 4612 io:format("Testing bug reported in ticket OTP-1131...~n"), 4613 s([{[friendsEntry, [2, 3, 1]], s, "kompis3"}, 4614 {[friendsEntry, [3, 3, 1]], i, ?createAndGo}]), 4615 ?line expect(1, ?v1_2(noSuchName, noCreation), 2, any). 4616 4617 4618%%----------------------------------------------------------------- 4619%% Ticket: OTP-1162 4620%% Slogan: snmp_agent can't handle wrongValue from instrum.func 4621%%----------------------------------------------------------------- 4622otp_1162(suite) -> []; 4623otp_1162(Config) when list(Config) -> 4624 {SaNode, _MgrNode, _MibDir} = init_case(Config), 4625 ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), 4626 try_test(otp_1162), 4627 stop_subagent(SA). 4628 4629otp_1162_2(X) -> otp_1162(X). 4630 4631otp_1162_3(X) -> otp_1162(X). 4632 4633otp_1162() -> 4634 s([{[sa, [2,0]], 6}]), % wrongValue (i is_set_ok) 4635 ?line expect(1, ?v1_2(badValue, wrongValue), 1, any). 4636 4637 4638%%----------------------------------------------------------------- 4639%% Ticket: OTP-1222 4640%% Slogan: snmp agent crash if faulty index is returned from instrum 4641%%----------------------------------------------------------------- 4642otp_1222(suite) -> []; 4643otp_1222(Config) when list(Config) -> 4644 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 4645 ?line load_master("Klas3"), 4646 ?line load_master("Klas4"), 4647 try_test(otp_1222), 4648 ?line unload_master("Klas3"), 4649 ?line unload_master("Klas4"). 4650 4651otp_1222_2(X) -> otp_1222(X). 4652 4653otp_1222_3(X) -> otp_1222(X). 4654 4655otp_1222() -> 4656 io:format("Testing bug reported in ticket OTP-1222...~n"), 4657 s([{[fStatus4,1], 4}, {[fName4,1], 1}]), 4658 ?line expect(1, genErr, 0, any), 4659 s([{[fStatus4,2], 4}, {[fName4,2], 1}]), 4660 ?line expect(2, genErr, 0, any). 4661 4662%%----------------------------------------------------------------- 4663%% Ticket: OTP-1298 4664%% Slogan: Negative INTEGER values are treated as positive. 4665%%----------------------------------------------------------------- 4666otp_1298(suite) -> []; 4667otp_1298(Config) when list(Config) -> 4668 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 4669 ?line load_master("Klas2"), 4670 try_test(otp_1298), 4671 ?line unload_master("Klas2"). 4672 4673otp_1298_2(X) -> otp_1298(X). 4674 4675otp_1298_3(X) -> otp_1298(X). 4676 4677otp_1298() -> 4678 io:format("Testing bug reported in ticket OTP-1298...~n"), 4679 s([{[fint,0], -1}]), 4680 ?line expect(1298, [{[fint,0], -1}]). 4681 4682 4683%%----------------------------------------------------------------- 4684%% Ticket: OTP-1331 4685%% Slogan: snmp_generic should return noError when deleting non-ex row 4686%%----------------------------------------------------------------- 4687otp_1331(suite) -> []; 4688otp_1331(Config) when list(Config) -> 4689 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 4690 ?line load_master("OLD-SNMPEA-MIB"), 4691 ?line init_old(), 4692 try_test(otp_1331), 4693 ?line unload_master("OLD-SNMPEA-MIB"). 4694 4695otp_1331_2(X) -> otp_1331(X). 4696 4697otp_1331_3(X) -> otp_1331(X). 4698 4699otp_1331() -> 4700 NewKeyc5 = [intCommunityStatus,[127,32,0,0],is("test")], 4701 s([{NewKeyc5, ?destroy}]), 4702 ?line expect(1, [{NewKeyc5, ?destroy}]). 4703 4704 4705%%----------------------------------------------------------------- 4706%% Ticket: OTP-1338 4707%% Slogan: snmp bug in initialisation of default values for mnesia tabs 4708%%----------------------------------------------------------------- 4709otp_1338(suite) -> []; 4710otp_1338(Config) when list(Config) -> 4711 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 4712 ?line load_master("Klas2"), 4713 try_test(otp_1338), 4714 ?line unload_master("Klas2"). 4715 4716otp_1338_2(X) -> otp_1338(X). 4717 4718otp_1338_3(X) -> otp_1338(X). 4719 4720otp_1338() -> 4721 s([{[kStatus2, 7], i, ?createAndGo}]), 4722 ?line expect(1, [{[kStatus2, 7], ?createAndGo}]), 4723 g([[kName2, 7]]), 4724 ?line expect(2, [{[kName2, 7], "JJJ"}]). 4725 4726%%----------------------------------------------------------------- 4727%% Ticket: OTP-1342 4728%% Slogan: default impl of snmp table can't handle bad index access, 4729%% Set when INDEX is read-write gets into an infinite loop! 4730%%----------------------------------------------------------------- 4731otp_1342(suite) -> []; 4732otp_1342(Config) when list(Config) -> 4733 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 4734 ?line load_master("Klas4"), 4735 try_test(otp_1342), 4736 ?line unload_master("Klas4"). 4737 4738otp_1342_2(X) -> otp_1342(X). 4739 4740otp_1342_3(X) -> otp_1342(X). 4741 4742otp_1342() -> 4743 s([{[fIndex5, 1], i, 1}, 4744 {[fName5, 1], i, 3}, 4745 {[fStatus5, 1], i, ?createAndGo}]), 4746 ?line expect(1, ?v1_2(noSuchName, noCreation), 3, any). 4747 4748 4749%%----------------------------------------------------------------- 4750%% Ticket: OTP-1366 4751%% Slogan: snmp traps not sent to all managers 4752%% Note: NYI! We need a way to tell the test server that we need 4753%% mgrs on two different machines. 4754%%----------------------------------------------------------------- 4755otp_1366(suite) -> []; 4756otp_1366(Config) when list(Config) -> 4757 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 4758 ?line load_master("OLD-SNMPEA-MIB"), 4759 ?line init_old(), 4760 try_test(otp_1366), 4761 ?line unload_master("OLD-SNMPEA-MIB"). 4762 4763otp_1366_2(X) -> otp_1366(X). 4764 4765otp_1366_3(X) -> otp_1366(X). 4766 4767otp_1366() -> 4768 ?INF("NOT YET IMPLEMENTED", []), 4769 'NYI'. 4770 4771%%----------------------------------------------------------------- 4772%% Ticket: OTP-2776 4773%% Slogan: snmp:validate_date_and_time() fails when time is 00:00 4774%%----------------------------------------------------------------- 4775otp_2776(suite) -> []; 4776otp_2776(Config) when list(Config) -> 4777 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 4778 try_test(otp_2776). 4779 4780otp_2776_2(X) -> otp_2776(X). 4781 4782otp_2776_3(X) -> otp_2776(X). 4783 4784otp_2776() -> 4785 io:format("Testing bug reported in ticket OTP-2776...~n"), 4786 4787 Dt01_valid = [19,98,9,1,1,0,23,0,43,0,0], 4788 Dt02_valid = [19,98,9,1,0,0,0,0,43,0,0], % This is what is fixed: 00:00 4789 Dt03_valid = [19,98,2,28,1,0,23,0,43,0,0], 4790 Dt04_invalid = [19,98,2,29,1,0,23,0,43,0,0], 4791 Dt05_valid = [19,96,2,29,1,0,23,0,43,0,0], 4792 Dt06_valid = [20,0,2,29,1,0,23,0,43,0,0], 4793 Dt07_invalid = [19,96,2,30,1,0,23,0,43,0,0], % This is also fixed: 30/2 4794 Dt08_valid = [19,98,4,30,1,0,23,0,43,0,0], 4795 Dt09_invalid = [19,98,4,31,1,0,23,0,43,0,0], % This is also fixed: 31/4 4796 Dt10_invalid = [], 4797 Dt11_invalid = [kalle,hobbe], 4798 L = [{ 1, true, Dt01_valid}, 4799 { 2, true, Dt02_valid}, 4800 { 3, true, Dt03_valid}, 4801 { 4, false, Dt04_invalid}, 4802 { 5, true, Dt05_valid}, 4803 { 6, true, Dt06_valid}, 4804 { 7, false, Dt07_invalid}, 4805 { 8, true, Dt08_valid}, 4806 { 9, false, Dt09_invalid}, 4807 {10, false, Dt10_invalid}, 4808 {11, false, Dt11_invalid}], 4809 4810 ?line ok = validate_dat(L). 4811 4812 4813validate_dat(L) -> validate_dat(L,[]). 4814 4815validate_dat([],V) -> 4816 Fun = fun({_,X}) -> case X of 4817 ok -> false; 4818 _ -> true 4819 end 4820 end, 4821 validate_dat1( lists:reverse( lists:filter(Fun,V) ) ); 4822validate_dat([{Id,E,Dat}|T],V) -> 4823 validate_dat(T,[validate_dat2(Id,E,Dat) | V]). 4824 4825validate_dat1([]) -> ok; 4826validate_dat1(L) -> {error,L}. 4827 4828validate_dat2(Id, E, Dat) -> 4829 Res = case {E,snmp:validate_date_and_time(Dat)} of 4830 {E,E} -> ok; 4831 {E,A} -> {E,A} 4832 end, 4833 {Id, Res}. 4834 4835 4836%%----------------------------------------------------------------- 4837%% Ticket: OTP-2979 4838%% Slogan: get-next on more than 1 column in an empty table 4839%% returns bad response. 4840%%----------------------------------------------------------------- 4841otp_2979(suite) -> []; 4842otp_2979(Config) when list(Config) -> 4843 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 4844 ?line load_master("Test1"), 4845 ?line init_old(), 4846 try_test(otp_2979), 4847 ?line unload_master("Test1"). 4848 4849otp_2979_2(X) -> otp_2979(X). 4850 4851otp_2979_3(X) -> otp_2979(X). 4852 4853otp_2979() -> 4854 gn([[sparseDescr], [sparseStatus]]), 4855 ?line expect(1, [{[sparseStr,0], "slut"}, 4856 {[sparseStr,0], "slut"}]). 4857 4858%%----------------------------------------------------------------- 4859%% Ticket: OTP-3187 4860%% Slogan: get-next on vacmAccessTable for colums > 5 returns 4861%% endOfTable - should return value. 4862%%----------------------------------------------------------------- 4863otp_3187(suite) -> []; 4864otp_3187(Config) when list(Config) -> 4865 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 4866 ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), 4867 otp_3187(), 4868 ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). 4869 4870otp_3187_2(X) -> otp_3187(X). 4871 4872otp_3187_3(X) -> otp_3187(X). 4873 4874otp_3187() -> 4875 ?line Elements = 4876 snmp_view_based_acm_mib:vacmAccessTable(get_next,[],[4,5,6]), 4877 lists:foreach(fun(E) -> 4878 ?line if E == endOfTable -> 4879 ?FAIL(endOfTable); 4880 true -> ok 4881 end 4882 end, Elements). 4883 4884%%----------------------------------------------------------------- 4885%% Ticket: OTP-3542 4886%% Slogan: 4887%%----------------------------------------------------------------- 4888otp_3542(suite) -> []; 4889otp_3542(Config) when list(Config) -> 4890 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 4891 try_test(otp_3542). 4892 4893otp_3542() -> 4894 io:format("SNMP v3 discovery...~n"), 4895 ?line Res = snmp_test_mgr:d(), 4896 io:format("SNMP v3 discovery result: ~p~n",[Res]). 4897 4898 4899%%----------------------------------------------------------------- 4900%% Ticket: OTP-3725 4901%% Slogan: Slow response time on snmpa:int_to_enum 4902%%----------------------------------------------------------------- 4903otp_3725(suite) -> []; 4904otp_3725(Config) when list(Config) -> 4905 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 4906 4907 ?line load_master("OLD-SNMPEA-MIB"), 4908 ?line init_old(), 4909 try_test(otp_3725_test, [node()]), 4910 ?line unload_master("OLD-SNMPEA-MIB"). 4911 4912%% Req. OLD-SNMPEA-MIB 4913otp_3725_test(MaNode) -> 4914 io:format("Testing feature requested in ticket OTP-3725...~n"), 4915 ?line rpc:call(MaNode,snmpa,verbosity,[symbolic_store,trace]), 4916 ?line Db = rpc:call(MaNode,snmp,get_symbolic_store_db,[]), 4917 ?DBG("otp_3725_test -> Db = ~p",[Db]), 4918 4919 ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, 4920 [Db, intAgentIpAddress]), 4921 ?DBG("otp_3725_test -> name_to_oid for ~p: ~p",[intAgentIpAddress,OID]), 4922 ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, oid_to_name, 4923 [Db,OID]), 4924 ?DBG("otp_3725_test -> oid_to_name for ~p: ~p",[OID,intAgentIpAddress]), 4925 ?line false = rpc:call(MaNode, snmp, name_to_oid, [Db, intAgentIpAddres]), 4926 ?line false = rpc:call(MaNode, snmp, oid_to_name, 4927 [Db, [1,5,32,3,54,3,3,34,4]]), 4928 ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, 4929 [Db, intViewType, excluded]), 4930 ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, 4931 [Db, intViewType, 2]), 4932 ?line false = rpc:call(MaNode, snmp, enum_to_int, 4933 [Db, intViewType, exclude]), 4934 ?line false = rpc:call(MaNode, snmp, enum_to_int, 4935 [Db, intAgentIpAddress, exclude]), 4936 ?line false = rpc:call(MaNode, snmp, enum_to_int, 4937 [Db, intAgentIpAddre, exclude]), 4938 ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, intViewType, 3]), 4939 ?line false = rpc:call(MaNode, snmp, int_to_enum, 4940 [Db, intAgentIpAddress, 2]), 4941 ?line false = rpc:call(MaNode, snmp, int_to_enum, 4942 [Db, intAgentIpAddre, 2]), 4943 ?line {value, active} = rpc:call(MaNode, snmp, int_to_enum, 4944 [Db, 'RowStatus', ?active]), 4945 ?line {value, ?destroy} = rpc:call(MaNode, snmp, enum_to_int, 4946 [Db, 'RowStatus', destroy]), 4947 ?line false = rpc:call(MaNode, snmp, enum_to_int, 4948 [Db, 'RowStatus', xxxdestroy]), 4949 ?line false = rpc:call(MaNode, snmp, enum_to_int, 4950 [Db, 'xxRowStatus', destroy]), 4951 ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'RowStatus', 25]), 4952 ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'xxRowStatus', 1]), 4953 ok. 4954 4955 4956%%----------------------------------------------------------------- 4957%% Ticket: OTP-4394 4958%% Slogan: Target mib tag list check invalid 4959%%----------------------------------------------------------------- 4960 4961 4962 4963init_otp_4394(Config) when list(Config) -> 4964 ?DBG("init_otp_4394 -> entry with" 4965 "~n Config: ~p", [Config]), 4966 ?line AgentDir = ?config(agent_dir, Config), 4967 ?line MgrDir = ?config(mgr_dir, Config), 4968 ?line Ip = ?config(ip, Config), 4969 ?line otp_4394_config(AgentDir, MgrDir, Ip), 4970 MasterAgentVerbosity = {master_agent_verbosity, trace}, 4971 NetIfVerbosity = {net_if_verbosity, trace}, 4972 Opts = [MasterAgentVerbosity,NetIfVerbosity], 4973 [{vsn, v1} | start_v1_agent(Config,Opts)]. 4974 4975otp_4394_config(AgentDir, MgrDir, Ip0) -> 4976 ?DBG("otp_4394_config -> entry with" 4977 "~n AgentDir: ~p" 4978 "~n MgrDir: ~p" 4979 "~n Ip0: ~p", [AgentDir, MgrDir, Ip0]), 4980 Vsn = [v1], 4981 Ip = tuple_to_list(Ip0), 4982 ?line snmp_config:write_agent_snmp_files(AgentDir, Vsn, Ip, 4983 ?TRAP_UDP, Ip, 4000, 4984 "OTP-4394 test"), 4985 ?line case update_usm(Vsn, AgentDir) of 4986 true -> 4987 ?line copy_file(filename:join(AgentDir, "usm.conf"), 4988 filename:join(MgrDir, "usm.conf")), 4989 ?line update_usm_mgr(Vsn, MgrDir); 4990 false -> 4991 ?line ok 4992 end, 4993 C1 = {"a", "all-rights", "initial", "", "pc"}, 4994 C2 = {"c", "secret", "secret_name", "", "secret_tag"}, 4995 ?line write_community_conf(AgentDir, [C1, C2]), 4996 ?line update_vacm(Vsn, AgentDir), 4997 Ta1 = {"shelob v1", 4998 [134,138,177,177], 5000, 1500, 3, %% Anv�nd Ip och modda 4999 "pc1", 5000 "target_v1", "", 5001 %% [255,255,255,255,0,0], 5002 [], 5003 2048}, 5004 Ta2 = {"bifur v1", 5005 [134,138,177,75], 5000, 1500, 3, %% Anv�nd Ip 5006 "pc2", 5007 "target_v1", "", 5008 %% [255,255,255,255,0,0], 5009 [], 2048}, 5010 ?line write_target_addr_conf(AgentDir, [Ta1, Ta2]), 5011 ?line write_target_params_conf(AgentDir, Vsn), 5012 ?line write_notify_conf(AgentDir), 5013 ok. 5014 5015 5016 5017finish_otp_4394(Config) when list(Config) -> 5018 ?DBG("finish_otp_4394 -> entry", []), 5019 C1 = stop_agent(Config), 5020 delete_files(C1), 5021 erase(mgr_node), 5022 lists:keydelete(vsn, 1, C1). 5023 5024otp_4394_test(suite) -> []; 5025otp_4394_test(Config) -> 5026 ?DBG("otp_4394_test -> entry", []), 5027 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 5028 try_test(otp_4394_test1), 5029 ?DBG("otp_4394_test -> done", []), 5030 ok. 5031 5032otp_4394_test1() -> 5033 ?DBG("otp_4394_test1 -> entry", []), 5034 gn([[1,1]]), 5035 Res = 5036 case snmp_test_mgr:expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]) of 5037 %% {error, 1, {"?",[]}, {"~w",[timeout]}} 5038 {error, 1, _, {_, [timeout]}} -> 5039 ?DBG("otp_4394_test1 -> expected result: timeout", []), 5040 ok; 5041 Else -> 5042 Else 5043 end, 5044 ?DBG("otp_4394_test1 -> done with: ~p", [Res]), 5045 Res. 5046 5047 5048%%%-------------------------------------------------- 5049%%% Used to test the standard mib with our 5050%%% configuration. 5051%%%-------------------------------------------------- 5052run(F, A, Opts) -> 5053 M = get(mib_dir), 5054 Dir = get(mgr_dir), 5055 User = snmp_misc:get_option(user, Opts, "all-rights"), 5056 SecLevel = snmp_misc:get_option(sec_level, Opts, noAuthNoPriv), 5057 EngineID = snmp_misc:get_option(engine_id, Opts, "agentEngine"), 5058 CtxEngineID = snmp_misc:get_option(context_engine_id, Opts, EngineID), 5059 Community = snmp_misc:get_option(community, Opts, "all-rights"), 5060 ?DBG("run -> start crypto app",[]), 5061 Crypto = ?CRYPTO_START(), 5062 ?DBG("run -> Crypto: ~p",[Crypto]), 5063 catch snmp_test_mgr:stop(), % If we had a running mgr from a failed case 5064 StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", 5065 ?DBG("run -> config:~n" 5066 "\tM: ~p~n" 5067 "\tDir: ~p~n" 5068 "\tUser: ~p~n" 5069 "\tSecLevel: ~p~n" 5070 "\tEngineID: ~p~n" 5071 "\tCtxEngineID: ~p~n" 5072 "\tCommunity: ~p~n" 5073 "\tStdM: ~p", 5074 [M,Dir,User,SecLevel,EngineID,CtxEngineID,Community,StdM]), 5075 case snmp_test_mgr:start([%% {agent, snmp_test_lib:hostname()}, 5076 {packet_server_debug,true}, 5077 {debug,true}, 5078 {agent, get(master_host)}, 5079 {agent_udp, 4000}, 5080 {trap_udp, 5000}, 5081 {recbuf,65535}, 5082 quiet, 5083 get(vsn), 5084 {community, Community}, 5085 {user, User}, 5086 {sec_level, SecLevel}, 5087 {engine_id, EngineID}, 5088 {context_engine_id, CtxEngineID}, 5089 {dir, Dir}, 5090 {mibs, mibs(StdM, M)}]) of 5091 {ok, _Pid} -> 5092 Res = apply(?MODULE, F, A), 5093 catch snmp_test_mgr:stop(), 5094 Res; 5095 Err -> 5096 io:format("Error starting manager: ~p\n", [Err]), 5097 catch snmp_test_mgr:stop(), 5098 ?line exit({mgr_start, Err}) 5099 end. 5100 5101 5102mibs(StdMibDir,MibDir) -> 5103 [join(StdMibDir, ?v1_2("STANDARD-MIB.bin", "SNMPv2-MIB.bin")), 5104 join(MibDir, "OLD-SNMPEA-MIB.bin"), 5105 join(StdMibDir, "SNMP-FRAMEWORK-MIB"), 5106 join(StdMibDir, "SNMP-MPD-MIB"), 5107 join(StdMibDir, "SNMP-VIEW-BASED-ACM-MIB"), 5108 join(StdMibDir, "SNMP-USER-BASED-SM-MIB"), 5109 join(StdMibDir, "SNMP-TARGET-MIB"), 5110 join(StdMibDir, "SNMP-NOTIFICATION-MIB"), 5111 join(MibDir, "Klas1.bin"), 5112 join(MibDir, "Klas2.bin"), 5113 join(MibDir, "Klas3.bin"), 5114 join(MibDir, "Klas4.bin"), 5115 join(MibDir, "SA-MIB.bin"), 5116 join(MibDir, "TestTrap.bin"), 5117 join(MibDir, "Test1.bin"), 5118 join(MibDir, "Test2.bin"), 5119 join(MibDir, "TestTrapv2.bin")]. 5120 5121join(D,F) -> 5122 filename:join(D,F). 5123 5124%% string used in index 5125is(S) -> [length(S) | S]. 5126 5127try_test(Func) -> 5128 call(get(mgr_node), ?MODULE, run, [Func, [], []]). 5129 5130try_test(Func, A) -> 5131 call(get(mgr_node), ?MODULE, run, [Func, A, []]). 5132 5133try_test(Func, A, Opts) -> 5134 call(get(mgr_node), ?MODULE, run, [Func, A, Opts]). 5135 5136call(N,M,F,A) -> 5137 ?DBG("call -> entry with~n" 5138 " N: ~p~n" 5139 " M: ~p~n" 5140 " F: ~p~n" 5141 " A: ~p~n" 5142 " when~n" 5143 " get(): ~p", 5144 [N,M,F,A,get()]), 5145 spawn(N, ?MODULE, wait, [self(),get(),M,F,A]), 5146 receive 5147 {done, {'EXIT', Rn}, Loc} -> 5148 ?DBG("call -> returned ~p",[{done, {'EXIT', Rn}, Loc}]), 5149 put(test_server_loc, Loc), 5150 exit(Rn); 5151 {done, Ret, Zed} -> 5152 ?DBG("call -> returned ~p~n",[{done, Ret, Zed}]), 5153 Ret 5154 end. 5155 5156wait(From, Env, M, F, A) -> 5157 ?DBG("wait -> entry with ~n" 5158 "\tFrom: ~p~n" 5159 "\tEnv: ~p",[From,Env]), 5160 lists:foreach(fun({K,V}) -> put(K,V) end, Env), 5161 Rn = (catch apply(M, F, A)), 5162 ?DBG("wait -> Rn: ~n~p", [Rn]), 5163 From ! {done, Rn, get(test_server_loc)}, 5164 exit(Rn). 5165 5166expect(A,B) -> ok = snmp_test_mgr:expect(A,B). 5167expect(A,B,C) -> ok = snmp_test_mgr:expect(A,B,C). 5168expect(A,B,C,D) -> ok = snmp_test_mgr:expect(A,B,C,D). 5169expect(A,B,C,D,E,F) -> ok = snmp_test_mgr:expect(A,B,C,D,E,F). 5170 5171get_req(Id, Vars) -> 5172 ?DBG("get_req -> entry with~n" 5173 "\tId: ~p~n" 5174 "\tVars: ~p",[Id,Vars]), 5175 g(Vars), 5176 ?DBG("get_req -> await response",[]), 5177 {ok, Val} = snmp_test_mgr:get_response(Id, Vars), 5178 ?DBG("get_req -> response: ~p",[Val]), 5179 Val. 5180 5181get_next_req(Vars) -> 5182 ?DBG("get_next_req -> entry with Vars '~p', send request",[Vars]), 5183 gn(Vars), 5184 ?DBG("get_next_req -> await response",[]), 5185 Response = snmp_test_mgr:receive_response(), 5186 ?DBG("get_next_req -> response: ~p",[Response]), 5187 Response. 5188 5189 5190 5191start_node(Name) -> 5192 ?LOG("start_node -> entry with Name: ~p",[Name]), 5193 M = list_to_atom(?HOSTNAME(node())), 5194 ?DBG("start_node -> M: ~p",[M]), 5195 Pa = filename:dirname(code:which(?MODULE)), 5196 ?DBG("start_node -> Pa: ~p",[Pa]), 5197 5198 Args = case init:get_argument('CC_TEST') of 5199 {ok, [[]]} -> 5200 " -pa /clearcase/otp/libraries/snmp/ebin "; 5201 {ok, [[Path]]} -> 5202 " -pa " ++ Path; 5203 error -> 5204 "" 5205 end, 5206 %% Do not use start_link!!! (the proc that calls this one is tmp) 5207 ?DBG("start_node -> Args: ~p~n",[Args]), 5208 A = Args ++ " -pa " ++ Pa, 5209 case (catch ?START_NODE(Name, A)) of 5210 {ok, Node} -> 5211 %% Tell the test_server to not clean up things it never started. 5212 ?DBG("start_node -> Node: ~p",[Node]), 5213 {ok, Node}; 5214 Else -> 5215 ?ERR("start_node -> failed with(other): Else: ~p",[Else]), 5216 ?line ?FAIL(Else) 5217 end. 5218 5219 5220stop_node(Node) -> 5221 ?LOG("stop_node -> Node: ~p",[Node]), 5222 rpc:cast(Node, erlang, halt, []). 5223 5224p(X) -> 5225 io:format(user, X++"\n", []). 5226 5227sleep(X) -> 5228 receive 5229 after 5230 X -> ok 5231 end. 5232 5233%%%----------------------------------------------------------------- 5234%%% Configuration 5235%%%----------------------------------------------------------------- 5236config(Vsns, MgrDir, AgentDir, MIp, AIp) -> 5237 ?line snmp_config:write_agent_snmp_files(AgentDir, Vsns, MIp, 5238 ?TRAP_UDP, AIp, 4000, 5239 "test"), 5240 ?line case update_usm(Vsns, AgentDir) of 5241 true -> 5242 ?line copy_file(filename:join(AgentDir, "usm.conf"), 5243 filename:join(MgrDir, "usm.conf")), 5244 ?line update_usm_mgr(Vsns, MgrDir); 5245 false -> 5246 ?line ok 5247 end, 5248 ?line update_community(Vsns, AgentDir), 5249 ?line update_vacm(Vsns, AgentDir), 5250 ?line write_target_addr_conf(AgentDir, MIp, ?TRAP_UDP, Vsns), 5251 ?line write_target_params_conf(AgentDir, Vsns), 5252 ?line write_notify_conf(AgentDir), 5253 ok. 5254 5255delete_files(Config) -> 5256 Dir = ?config(agent_dir, Config), 5257 {ok, List} = file:list_dir(Dir), 5258 lists:foreach(fun(FName) -> file:delete(filename:join(Dir, FName)) end, 5259 List). 5260 5261update_usm(Vsns, Dir) -> 5262 case lists:member(v3, Vsns) of 5263 true -> 5264 {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),[read,write]), 5265 file:position(Fid, eof), 5266 ok = io:format(Fid, "{\"agentEngine\", \"all-rights\", " 5267 "\"all-rights\", zeroDotZero, " 5268 "usmNoAuthProtocol, \"\", \"\", " 5269 "usmNoPrivProtocol, \"\", \"\", \"\", " 5270 "\"\", \"\"}.\n", []), 5271 ok = io:format(Fid, "{\"agentEngine\", \"no-rights\", " 5272 "\"no-rights\", zeroDotZero, " 5273 "usmNoAuthProtocol, \"\", \"\", " 5274 "usmNoPrivProtocol, \"\", \"\", \"\", " 5275 "\"\", \"\"}.\n", []), 5276 ok = io:format(Fid, "{\"agentEngine\", \"authMD5\", " 5277 "\"authMD5\", zeroDotZero, " 5278 "usmHMACMD5AuthProtocol, \"\", \"\", " 5279 "usmNoPrivProtocol, \"\", \"\", \"\", " 5280 "\"passwd_md5xxxxxx\", \"\"}.\n", []), 5281 ok = io:format(Fid, "{\"agentEngine\", \"authSHA\", " 5282 "\"authSHA\", zeroDotZero, " 5283 "usmHMACSHAAuthProtocol, \"\", \"\", " 5284 "usmNoPrivProtocol, \"\", \"\", \"\", " 5285 "\"passwd_shaxxxxxxxxxx\", \"\"}.\n", []), 5286 ok = io:format(Fid, "{\"agentEngine\", \"privDES\", " 5287 "\"privDES\", zeroDotZero, " 5288 "usmHMACSHAAuthProtocol, \"\", \"\", " 5289 "usmDESPrivProtocol, \"\", \"\", \"\", " 5290 "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", 5291 []), 5292 ok = io:format(Fid, "{\"mgrEngine\", \"all-rights\", " 5293 "\"all-rights\", zeroDotZero, " 5294 "usmNoAuthProtocol, \"\", \"\", " 5295 "usmNoPrivProtocol, \"\", \"\", \"\", " 5296 "\"\", \"\"}.\n", []), 5297 ok = io:format(Fid, "{\"mgrEngine\", \"no-rights\", " 5298 "\"no-rights\", zeroDotZero, " 5299 "usmNoAuthProtocol, \"\", \"\", " 5300 "usmNoPrivProtocol, \"\", \"\", \"\", " 5301 "\"\", \"\"}.\n", []), 5302 ok = io:format(Fid, "{\"mgrEngine\", \"authMD5\", " 5303 "\"authMD5\", zeroDotZero, " 5304 "usmHMACMD5AuthProtocol, \"\", \"\", " 5305 "usmNoPrivProtocol, \"\", \"\", \"\", " 5306 "\"passwd_md5xxxxxx\", \"\"}.\n", []), 5307 ok = io:format(Fid, "{\"mgrEngine\", \"authSHA\", " 5308 "\"authSHA\", zeroDotZero, " 5309 "usmHMACSHAAuthProtocol, \"\", \"\", " 5310 "usmNoPrivProtocol, \"\", \"\", \"\", " 5311 "\"passwd_shaxxxxxxxxxx\", \"\"}.\n", []), 5312 ok = io:format(Fid, "{\"mgrEngine\", \"privDES\", " 5313 "\"privDES\", zeroDotZero, " 5314 "usmHMACSHAAuthProtocol, \"\", \"\", " 5315 "usmDESPrivProtocol, \"\", \"\", \"\", " 5316 "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", 5317 []), 5318 file:close(Fid), 5319 true; 5320 false -> 5321 false 5322 end. 5323 5324update_usm_mgr(Vsns, Dir) -> 5325 case lists:member(v3, Vsns) of 5326 true -> 5327 {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),[read,write]), 5328 file:position(Fid, eof), 5329 ok = io:format(Fid, "{\"agentEngine\", \"newUser\", " 5330 "\"newUser\", zeroDotZero, " 5331 "usmHMACSHAAuthProtocol, \"\", \"\", " 5332 "usmDESPrivProtocol, \"\", \"\", \"\", " 5333 "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", 5334 []), 5335 ok = io:format(Fid, "{\"mgrEngine\", \"newUser\", " 5336 "\"newUser\", zeroDotZero, " 5337 "usmHMACSHAAuthProtocol, \"\", \"\", " 5338 "usmDESPrivProtocol, \"\", \"\", \"\", " 5339 "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", 5340 []), 5341 file:close(Fid), 5342 true; 5343 false -> 5344 false 5345 end. 5346 5347rewrite_usm_mgr(Dir, ShaKey, DesKey) -> 5348 ?line ok = file:rename(filename:join(Dir,"usm.conf"), 5349 filename:join(Dir,"usm.old")), 5350 ?line {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),write), 5351 ok = io:format(Fid, "{\"agentEngine\", \"newUser\", " 5352 "\"newUser\", zeroDotZero, " 5353 "usmHMACSHAAuthProtocol, \"\", \"\", " 5354 "usmDESPrivProtocol, \"\", \"\", \"\", " 5355 "\"~s\", \"~s\"}.\n", 5356 [ShaKey, DesKey]), 5357 ok = io:format(Fid, "{\"mgrEngine\", \"newUser\", " 5358 "\"newUser\", zeroDotZero, " 5359 "usmHMACSHAAuthProtocol, \"\", \"\", " 5360 "usmDESPrivProtocol, \"\", \"\", \"\", " 5361 "\"~s\", \"~s\"}.\n", 5362 [ShaKey, DesKey]), 5363 file:close(Fid). 5364 5365reset_usm_mgr(Dir) -> 5366 ?line ok = file:rename(filename:join(Dir,"usm.old"), 5367 filename:join(Dir,"usm.conf")). 5368 5369 5370update_community([v3], _Dir) -> ok; 5371update_community(_, Dir) -> 5372 {ok, Fid} = file:open(filename:join(Dir,"community.conf"),[read,write]), 5373 file:position(Fid, eof), 5374 ok=io:format(Fid,"{\"no-rights\",\"no-rights\",\"no-rights\",\"\",\"\"}.\n", 5375 []), 5376 file:close(Fid). 5377 5378 5379-define(tDescr_instance, [1,3,6,1,2,1,16,1,0]). 5380update_vacm(_Vsn, Dir) -> 5381 {ok, Fid} = file:open(filename:join(Dir,"vacm.conf"),[read,write]), 5382 file:position(Fid, eof), 5383 ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"authMD5\",\"initial\"}.\n",[]), 5384 ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"authSHA\",\"initial\"}.\n",[]), 5385 ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"privDES\",\"initial\"}.\n",[]), 5386 ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"newUser\",\"initial\"}.\n",[]), 5387 ok = io:format(Fid, "{vacmViewTreeFamily, \"internet\", " 5388 "~w, excluded, null}.\n", [?tDescr_instance]), 5389 file:close(Fid). 5390 5391 5392vacm_ver(v1) -> v1; 5393vacm_ver(v2) -> v2c; 5394vacm_ver(v3) -> usm. 5395 5396 5397write_community_conf(Dir, Confs) -> 5398 {ok, Fid} = file:open(filename:join(Dir,"community.conf"),write), 5399 ok = write_community_conf1(Fid, Confs), 5400 file:close(Fid). 5401 5402write_community_conf1(_, []) -> 5403 ok; 5404write_community_conf1(Fid, [{ComIdx, ComName, SecName, CtxName, TransTag}|Confs]) -> 5405 ok = io:format(Fid, "{\"~s\", \"~s\", \"~s\", \"~s\", \"~s\"}.~n", 5406 [ComIdx, ComName, SecName, CtxName, TransTag]), 5407 write_community_conf1(Fid, Confs). 5408 5409 5410write_target_addr_conf(Dir, Confs) -> 5411 {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), 5412 ok = write_target_addr_conf1(Fid, Confs), 5413 file:close(Fid). 5414 5415 5416write_target_addr_conf1(_, []) -> 5417 ok; 5418write_target_addr_conf1(Fid, 5419 [{Name, Ip, Port, Timeout, Retry, TagList, ParamName, 5420 EngineId, TMask, MaxMsgSz}|Confs]) -> 5421 ok = io:format(Fid, "{\"~s\", ~w, ~w, ~w, ~w, \"~s\", \"~s\", \"~s\", ~w, ~w}.~n", 5422 [Name, Ip, Port, Timeout, Retry, TagList, ParamName, 5423 EngineId, TMask, MaxMsgSz]), 5424 write_target_addr_conf1(Fid, Confs). 5425 5426write_target_addr_conf(Dir, ManagerIp, UDP, Vsns) -> 5427 {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), 5428 lists:foreach(fun(Vsn) -> 5429 ok = io:format(Fid, 5430 "{\"~s\", ~w, ~w, 1500, 3, " 5431 "\"std_trap\", \"~s\"}.~n", 5432 [mk_ip(ManagerIp, Vsn), 5433 ManagerIp, UDP, mk_param(Vsn)]), 5434 case Vsn of 5435 v1 -> ok; 5436 v2 -> 5437 ok = io:format(Fid, 5438 "{\"~s.2\",~w,~w,1500,3, " 5439 "\"std_inform\", \"~s\"}.~n", 5440 [mk_ip(ManagerIp, Vsn), 5441 ManagerIp, UDP, 5442 mk_param(Vsn)]); 5443 v3 -> 5444 ok = io:format(Fid, 5445 "{\"~s.3\",~w,~w,1500,3, " 5446 "\"std_inform\", \"~s\", " 5447 "\"mgrEngine\", [], 1024}.~n", 5448 [mk_ip(ManagerIp, Vsn), 5449 ManagerIp, UDP, 5450 mk_param(Vsn)]) 5451 end 5452 end, 5453 Vsns), 5454 file:close(Fid). 5455 5456mk_param(v1) -> "target_v1"; 5457mk_param(v2) -> "target_v2"; 5458mk_param(v3) -> "target_v3". 5459 5460mk_ip([A,B,C,D], Vsn) -> 5461 io_lib:format("~w.~w.~w.~w ~w", [A,B,C,D,Vsn]). 5462 5463 5464rewrite_target_addr_conf(Dir,NewPort) -> 5465 TAFile = filename:join(Dir, "target_addr.conf"), 5466 ?DBG("rewrite_target_addr_conf -> read target file info of address config file",[]), 5467 case file:read_file_info(TAFile) of 5468 {ok, _} -> ok; 5469 {error, R} -> ?ERR("failure reading file info of " 5470 "target address config file: ~p",[R]), 5471 ok 5472 end, 5473 5474 ?line [TrapAddr|Addrs] = 5475 snmp_conf:read(TAFile,fun(R) -> rewrite_target_addr_conf1(R) end), 5476 5477 ?DBG("rewrite_target_addr_conf -> TrapAddr: ~p",[TrapAddr]), 5478 5479 NewAddrs = [rewrite_target_addr_conf2(NewPort,TrapAddr)|Addrs], 5480 5481 ?DBG("rewrite_target_addr_conf -> NewAddrs: ~p",[NewAddrs]), 5482 5483 ?line ok = file:rename(filename:join(Dir,"target_addr.conf"), 5484 filename:join(Dir,"target_addr.old")), 5485 ?line {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), 5486 5487 ?line ok = rewrite_target_addr_conf3(Fid,NewAddrs), 5488 5489 file:close(Fid). 5490 5491rewrite_target_addr_conf1(O) -> 5492 {ok,O}. 5493 5494rewrite_target_addr_conf2(NewPort,{Name,Ip,_Port,Timeout,Retry, 5495 "std_trap",EngineId}) -> 5496 ?LOG("rewrite_target_addr_conf2 -> entry with std_trap",[]), 5497 {Name,Ip,NewPort,Timeout,Retry,"std_trap",EngineId}; 5498rewrite_target_addr_conf2(_NewPort,O) -> 5499 ?LOG("rewrite_target_addr_conf2 -> entry with " 5500 "~n O: ~p",[O]), 5501 O. 5502 5503 5504rewrite_target_addr_conf3(_,[]) -> ok; 5505rewrite_target_addr_conf3(Fid,[{Name,Ip,Port,Timeout,Retry, 5506 ParamName,EngineId}|T]) -> 5507 ?LOG("rewrite_target_addr_conf3 -> write(1) ~s",[ParamName]), 5508 io:format(Fid, 5509 "{\"~s\", " % Name 5510 "~p, " % Ip 5511 "~p, " % Port 5512 "~p, " % Timeout 5513 "~p, " % Retry 5514 "\"~s\", " % ParamsName 5515 "\"~s\"}.", % EngineId 5516 [Name,Ip,Port,Timeout,Retry,ParamName,EngineId]), 5517 rewrite_target_addr_conf3(Fid,T); 5518rewrite_target_addr_conf3(Fid,[{Name,Ip,Port,Timeout,Retry,TagList, 5519 ParamName,EngineId,TMask,MMS}|T]) -> 5520 ?LOG("rewrite_target_addr_conf3 -> write(2) ~s",[ParamName]), 5521 io:format(Fid, 5522 "{\"~s\", " % Name 5523 "~p, " % Ip 5524 "~p, " % Port 5525 "~p, " % Timeout 5526 "~p, " % Retry 5527 "\"~s\", " % TagList 5528 "\"~s\", " % ParamsName 5529 "\"~s\"," % EngineId 5530 "~p, " % TMask 5531 "~p}.", % MMS 5532 [Name,Ip,Port,Timeout,Retry,TagList,ParamName, 5533 EngineId,TMask,MMS]), 5534 rewrite_target_addr_conf3(Fid,T). 5535 5536reset_target_addr_conf(Dir) -> 5537 ?line ok = file:rename(filename:join(Dir,"target_addr.old"), 5538 filename:join(Dir,"target_addr.conf")). 5539 5540write_target_params_conf(Dir, Vsns) -> 5541 {ok, Fid} = file:open(filename:join(Dir,"target_params.conf"),write), 5542 lists:foreach(fun(Vsn) -> 5543 MP = if Vsn == v1 -> v1; 5544 Vsn == v2 -> v2c; 5545 Vsn == v3 -> v3 5546 end, 5547 SM = if Vsn == v1 -> v1; 5548 Vsn == v2 -> v2c; 5549 Vsn == v3 -> usm 5550 end, 5551 ok = io:format(Fid, "{\"target_~w\", ~w, ~w, " 5552 "\"all-rights\", noAuthNoPriv}.~n", 5553 [Vsn, MP, SM]) 5554 end, 5555 Vsns), 5556 file:close(Fid). 5557 5558rewrite_target_params_conf(Dir, SecName, SecLevel) -> 5559 ?line ok = file:rename(filename:join(Dir,"target_params.conf"), 5560 filename:join(Dir,"target_params.old")), 5561 ?line {ok, Fid} = file:open(filename:join(Dir,"target_params.conf"),write), 5562 ?line ok = io:format(Fid, "{\"target_v3\", v3, usm, \"~s\", ~w}.~n", 5563 [SecName, SecLevel]), 5564 file:close(Fid). 5565 5566reset_target_params_conf(Dir) -> 5567 ?line ok = file:rename(filename:join(Dir,"target_params.old"), 5568 filename:join(Dir,"target_params.conf")). 5569 5570write_notify_conf(Dir) -> 5571 {ok, Fid} = file:open(filename:join(Dir,"notify.conf"),write), 5572 ok = io:format(Fid, "{\"standard trap\", \"std_trap\", trap}.~n", []), 5573 ok = io:format(Fid, "{\"standard inform\", \"std_inform\",inform}.~n", []), 5574 file:close(Fid). 5575 5576ver_to_trap_str([v1]) -> "v1"; 5577ver_to_trap_str([v2]) -> "v2"; 5578% default is to use the latest snmp version 5579ver_to_trap_str([v1,v2]) -> "v2". 5580 5581 5582 5583write_view_conf(Dir) -> 5584 {ok, Fid} = file:open(a(Dir,"view.conf"),write), 5585 ok = io:format(Fid, "{2, [1,3,6], included, null}.~n", []), 5586 ok = io:format(Fid, "{2, ~w, excluded, null}.~n", [?tDescr_instance]), 5587 file:close(Fid). 5588 5589a(A,B) -> lists:append(A,B). 5590 5591 5592%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5593 5594copy_file(From, To) -> 5595 {ok, Bin} = file:read_file(From), 5596 ok = file:write_file(To, Bin). 5597 5598 5599 5600%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5601 5602display_memory_usage() -> 5603 Info = snmpa:info(snmp_master_agent), 5604 TreeSize = lists_key1search(tree_size_bytes, Info), 5605 ProcMem = lists_key1search(process_memory, Info), 5606 MibDbSize = lists_key1search([db_memory,mib], Info), 5607 NodeDbSize = lists_key1search([db_memory,node], Info), 5608 TreeDbSize = lists_key1search([db_memory,tree], Info), 5609 ?INF("Memory usage: " 5610 "~n Tree size: ~p" 5611 "~n Process memory size: ~p" 5612 "~n Mib db size: ~p" 5613 "~n Node db size: ~p" 5614 "~n Tree db size: ~p", 5615 [TreeSize, ProcMem, MibDbSize, NodeDbSize, TreeDbSize]). 5616 5617lists_key1search([], Res) -> 5618 Res; 5619lists_key1search([Key|Keys], List) when atom(Key), list(List) -> 5620 case lists:keysearch(Key, 1, List) of 5621 {value, {Key, Val}} -> 5622 lists_key1search(Keys, Val); 5623 false -> 5624 undefined 5625 end; 5626lists_key1search(Key, List) when atom(Key) -> 5627 case lists:keysearch(Key, 1, List) of 5628 {value, {Key, Val}} -> 5629 Val; 5630 false -> 5631 undefined 5632 end. 5633 5634 5635regs() -> 5636 lists:sort(registered()). 5637