1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 2003-2020. 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_SUITE). 22 23-export([ 24 suite/0, all/0, groups/0, 25 init_per_suite/1, end_per_suite/1, 26 init_per_group/2, end_per_group/2, 27 init_per_testcase/2, end_per_testcase/2, 28 29 %% all_tcs - misc 30 app_info/1, 31 info_test/1, 32 create_local_db_dir/1, 33 34 %% all_tcs - test_v1 35 simple/1, 36 db_notify_client/1, 37 v1_processing/1, 38 big/1, 39 big2/1, 40 loop_mib_1/1, 41 api/1, 42 subagent/1, 43 mnesia/1, 44 sa_register/1, 45 v1_trap/1, 46 sa_error/1, 47 next_across_sa/1, 48 undo/1, 49 sparse_table/1, 50 cnt_64/1, 51 opaque/1, 52 change_target_addr_config/1, 53 54 %% all_tcs - test_v1 - multiple_reqs 55 mul_get/1, 56 mul_get_err/1, 57 mul_next/1, 58 mul_next_err/1, 59 mul_set/1, 60 mul_set_err/1, 61 62 %% all_tcs - test_v1 - reported_bugs 63 otp_1128/1, 64 otp_1129/1, 65 otp_1131/1, 66 otp_1162/1, 67 otp_1222/1, 68 otp_1298/1, 69 otp_1331/1, 70 otp_1338/1, 71 otp_1342/1, 72 otp_1366/1, 73 otp_2776/1, 74 otp_2979/1, 75 otp_3187/1, 76 otp_3725/1, 77 78 %% all_tcs - test_v1 - standard_mibs 79 snmp_standard_mib/1, 80 snmp_community_mib/1, 81 snmp_framework_mib/1, 82 snmp_target_mib/1, 83 snmp_notification_mib/1, 84 snmp_view_based_acm_mib/1, 85 86 %% all_tcs - test_v2 87 simple_2/1, 88 v2_processing/1, 89 big_2/1, 90 big2_2/1, 91 loop_mib_2/1, 92 api_2/1, 93 subagent_2/1, 94 mnesia_2/1, 95 sa_register_2/1, 96 v2_trap/1, 97 sa_error_2/1, 98 next_across_sa_2/1, 99 undo_2/1, 100 v2_types/1, 101 implied/1, 102 sparse_table_2/1, 103 cnt_64_2/1, 104 opaque_2/1, 105 v2_caps/1, 106 107 %% all_tcs - test_v2 - multiple_reqs_2 108 mul_get_2/1, 109 mul_get_err_2/1, 110 mul_next_2/1, 111 mul_next_err_2/1, 112 mul_set_2/1, 113 mul_set_err_2/1, 114 115 %% all_tcs - test_v2 - v2_inform 116 v2_inform_i/1, 117 118 %% all_tcs - test_v2 - reported_bugs_2 119 otp_1128_2/1, 120 otp_1129_2/1, 121 otp_1131_2/1, 122 otp_1162_2/1, 123 otp_1222_2/1, 124 otp_1298_2/1, 125 otp_1331_2/1, 126 otp_1338_2/1, 127 otp_1342_2/1, 128 otp_1366_2/1, 129 otp_2776_2/1, 130 otp_2979_2/1, 131 otp_3187_2/1, 132 133 %% all_tcs - test_v2 - standard_mibs_2 134 snmpv2_mib_2/1, 135 snmp_community_mib_2/1, 136 snmp_framework_mib_2/1, 137 snmp_target_mib_2/1, 138 snmp_notification_mib_2/1, 139 snmp_view_based_acm_mib_2/1, 140 141 %% all_tcs - test_v1_v2 142 simple_bi/1, 143 144 %% all_tcs - test_v3 145 simple_3/1, 146 v3_processing/1, 147 big_3/1, 148 big2_3/1, 149 api_3/1, 150 subagent_3/1, 151 mnesia_3/1, 152 loop_mib_3/1, 153 sa_register_3/1, 154 v3_trap/1, 155 sa_error_3/1, 156 next_across_sa_3/1, 157 undo_3/1, 158 v2_types_3/1, 159 implied_3/1, 160 sparse_table_3/1, 161 cnt_64_3/1, 162 opaque_3/1, 163 v2_caps_3/1, 164 165 %% all_tcs - test_v3 - multiple_reqs_3 166 mul_get_3/1, 167 mul_get_err_3/1, 168 mul_next_3/1, 169 mul_next_err_3/1, 170 mul_set_3/1, 171 mul_set_err_3/1, 172 173 %% all_tcs - test_v3 - v3_inform 174 v3_inform_i/1, 175 176 %% all_tcs - test_v3 - reported_bugs_3 177 otp_1128_3/1, 178 otp_1129_3/1, 179 otp_1131_3/1, 180 otp_1162_3/1, 181 otp_1222_3/1, 182 otp_1298_3/1, 183 otp_1331_3/1, 184 otp_1338_3/1, 185 otp_1342_3/1, 186 otp_1366_3/1, 187 otp_2776_3/1, 188 otp_2979_3/1, 189 otp_3187_3/1, 190 otp_3542/1, 191 192 %% all_tcs - test_v3 - standard_mibs_3 193 snmpv2_mib_3/1, 194 snmp_framework_mib_3/1, 195 snmp_mpd_mib_3/1, 196 snmp_target_mib_3/1, 197 snmp_notification_mib_3/1, 198 snmp_view_based_acm_mib_3/1, 199 snmp_user_based_sm_mib_3/1, 200 201 %% all_tcs - test_v3 - v3_security 202 v3_crypto_basic/1, 203 v3_md5_auth/1, 204 v3_sha_auth/1, 205 v3_des_priv/1, 206 207 %% all_tcs - test_multi_threaded, test_multi_threaded_ext 208 multi_threaded/1, 209 mt_trap/1, 210 211 %% all_tcs - mib_storage - mib_storage_ets 212 mse_simple/1, 213 mse_v1_processing/1, 214 mse_big/1, 215 mse_big2/1, 216 mse_loop_mib/1, 217 mse_api/1, 218 mse_sa_register/1, 219 mse_v1_trap/1, 220 mse_sa_error/1, 221 mse_next_across_sa/1, 222 mse_undo/1, 223 mse_standard_mib/1, 224 mse_community_mib/1, 225 mse_framework_mib/1, 226 mse_target_mib/1, 227 mse_notification_mib/1, 228 mse_view_based_acm_mib/1, 229 mse_sparse_table/1, 230 mse_me_of/1, 231 mse_mib_of/1, 232 233 %% all_tcs - mib_storage - mib_storage_dets 234 msd_simple/1, 235 msd_v1_processing/1, 236 msd_big/1, 237 msd_big2/1, 238 msd_loop_mib/1, 239 msd_api/1, 240 msd_sa_register/1, 241 msd_v1_trap/1, 242 msd_sa_error/1, 243 msd_next_across_sa/1, 244 msd_undo/1, 245 msd_standard_mib/1, 246 msd_community_mib/1, 247 msd_framework_mib/1, 248 msd_target_mib/1, 249 msd_notification_mib/1, 250 msd_view_based_acm_mib/1, 251 msd_sparse_table/1, 252 msd_me_of/1, 253 msd_mib_of/1, 254 255 %% all_tcs - mib_storage - mib_storage_mnesia 256 msm_simple/1, 257 msm_v1_processing/1, 258 msm_big/1, 259 msm_big2/1, 260 msm_loop_mib/1, 261 msm_api/1, 262 msm_sa_register/1, 263 msm_v1_trap/1, 264 msm_sa_error/1, 265 msm_next_across_sa/1, 266 msm_undo/1, 267 msm_standard_mib/1, 268 msm_community_mib/1, 269 msm_framework_mib/1, 270 msm_target_mib/1, 271 msm_notification_mib/1, 272 msm_view_based_acm_mib/1, 273 msm_sparse_table/1, 274 msm_me_of/1, 275 msm_mib_of/1, 276 277 %% all_tcs - mib_storage - mse_size_check 278 mse_size_check/1, 279 280 %% all_tcs - mib_storage - msd_size_check 281 msd_size_check/1, 282 283 %% all_tcs - mib_storage - msm_size_check 284 msm_size_check/1, 285 286 %% all_tcs - mib_storage - varm_mib_storage_dets 287 msd_varm_mib_start/1, 288 289 %% all_tcs - mib_storage - varm_mib_storage_mnesia 290 msm_varm_mib_start/1, 291 292 %% all_tcs - tickets1 - otp4394 293 otp_4394/1, 294 295 %% all_tcs - tickets1 - otp7157 296 otp_7157/1, 297 298 %% all_tcs - tickets1 - otp16092 299 otp_16092_simple_start_and_stop1/1, 300 otp_16092_simple_start_and_stop2/1, 301 otp_16092_simple_start_and_stop3/1, 302 otp_16092_simple_start_and_stop4/1, 303 304 %% tickets2 305 otp8395/1, 306 otp9884/1 307 ]). 308 309%% Internal exports 310-export([dummy_manager_init/2, 311 v3_sync/1, 312 v3_inform_sync/1, 313 v2_caps_i/1, 314 v1_proc/0, 315 v2_proc/0, 316 big_test/0, 317 big_test_2/0, 318 simple_standard_test/0, 319 db_notify_client_test/0, 320 notify/2, 321 multi_threaded_test/0, 322 mt_trap_test/2, 323 types_v2_test/0, 324 implied_test/1, 325 sparse_table_test/0, 326 cnt_64_test/1, 327 opaque_test/0, 328 api_test/1, 329 unreg_test/0, 330 load_test/0, 331 load_test_sa/0, 332 api_test2/0, 333 api_test3/0, 334 do_mul_get/0, 335 do_mul_get_err/0, 336 do_mul_next/0, 337 do_mul_next_err/0, 338 do_mul_set/0, 339 do_mul_set_err/0, 340 sa_mib/0, 341 ma_trap1/1, 342 ma_trap2/1, 343 ma_v2_2_v1_trap/1, 344 ma_v2_2_v1_trap2/1, 345 sa_trap1/1, 346 sa_trap2/1, 347 sa_trap3/1, 348 ma_v2_trap1/1, 349 ma_v2_trap2/1, 350 ma_v2_inform1/1, 351 ma_v2_inform2/1, 352 ma_v2_inform3/1, 353 delivery_targets/3, 354 delivery_info/4, 355 ma_v1_2_v2_trap/1, 356 ma_v1_2_v2_trap2/1, 357 sa_v1_2_v2_trap1/1, 358 sa_v1_2_v2_trap2/1, 359 sa_v1_2_v2_trap3/1, 360 sa_errs_bad_value/0, 361 sa_errs_gen_err/0, 362 sa_too_big/0, 363 next_across_sa_test/0, 364 undo_test/0, 365 bad_return/0, 366 standard_mib_a/0, 367 std_mib_read/0, 368 std_mib_write/0, 369 std_mib_init/0, 370 std_mib_finish/0, 371 standard_mib_test_finish/0, 372 std_mib_asn_err/0, 373 snmpv2_mib_test_finish/0, 374 std_mib_a/0, 375 std_mib_b/1, 376 std_mib_c/1, 377 snmpv2_mib_a/0, 378 snmp_community_mib_test/0, 379 snmp_framework_mib_test/0, 380 snmp_mpd_mib_a/0, 381 snmp_mpd_mib_b/0, 382 snmp_mpd_mib_c/1, 383 snmp_target_mib_test/0, 384 snmp_notification_mib_test/0, 385 do_set/1, 386 add_row/1, 387 del_row/1, 388 use_no_rights/0, 389 use_rights/0, 390 usm_add_user1/0, 391 usm_use_user/0, 392 usm_key_change1/2, 393 usm_key_change2/4, 394 usm_key_change3/4, 395 usm_read/0, 396 usm_del_user/0, 397 usm_bad/0, 398 loop_mib_1_test/0, 399 loop_mib_2_test/0, 400 loop_mib_3_test/0, 401 otp_1129_i/1, 402 otp_1162_test/0, 403 otp_1131_test/0, 404 otp_1222_test/0, 405 otp_1298_test/0, 406 otp_1331_test/0, 407 otp_1338_test/0, 408 otp_1342_test/0, 409 otp_1366_test/0, 410 otp_1128_test/0, 411 otp_2776_test/0, 412 otp_2979_test/0, 413 otp_3542_test/0, 414 otp_3725_test/1, 415 otp_4394_test/0, 416 otp_7157_test/1, 417 otp9884_backup/4, 418 agent_log_validation/0, 419 mnesia_init/1, 420 mnesia_start/0, 421 mnesia_stop/0, 422 start_standalone_agent/1, 423 do_info/1 424 ]). 425 426-define(application, snmp). 427 428-include_lib("kernel/include/file.hrl"). 429-include_lib("common_test/include/ct.hrl"). 430-include("snmp_test_lib.hrl"). 431-define(SNMP_USE_V3, true). 432-include_lib("snmp/include/snmp_types.hrl"). 433-include_lib("snmp/src/agent/snmpa_atl.hrl"). 434 435-define(ALIB, snmp_agent_test_lib). 436 437-define(klas1, [1,3,6,1,2,1,7]). 438-define(klas2, [1,3,6,1,2,1,9]). 439-define(klas3, [1,3,6,1,2,1,8,1]). 440-define(klas4, [1,3,6,1,2,1,8,4]). 441-define(sa, [1,3,6,1,4,1,193,2]). 442-define(system, [1,3,6,1,2,1,1]). 443-define(snmp, [1,3,6,1,2,1,11]). 444-define(snmpTraps, [1,3,6,1,6,3,1,1,5]). 445-define(ericsson, [1,3,6,1,4,1,193]). 446-define(testTrap, [1,3,6,1,2,1,15,0]). 447-define(xDescr, [1,3,6,1,2,1,17,1]). 448-define(xDescr2, [1,3,6,1,2,1,17,2]). 449 450-define(active, 1). 451-define(notInService, 2). 452-define(notReady, 3). 453-define(createAndGo, 4). 454-define(createAndWait, 5). 455-define(destroy, 6). 456 457-define(TRAP_UDP, 5000). 458 459-define(tooBigStr, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"). 460 461-define(str(X), snmp_pdus:bits_to_str(X)). 462 463-define(break(), begin io:format(user, "break at line ~w: pid: ~p\n", 464 [?LINE, self()]), 465 receive cont -> ok end 466 end). 467 468 469-define(v1_2(V1,V2), 470 case get(vsn) of 471 v1 -> V1; 472 _ -> V2 473 end). 474 475-define(v1_2_3(V1,V2,V3), 476 case get(vsn) of 477 v1 -> V1; 478 v2 -> V2; 479 _ -> V3 480 end). 481 482 483-define(expect1(What), 484 ?ALIB:expect(?MODULE, ?LINE, 485 What)). 486-define(expect2(What, ExpVBs), 487 ?ALIB:expect(?MODULE, ?LINE, 488 What, ExpVBs)). 489-define(expect3(Err, Idx, ExpVBs), 490 ?ALIB:expect(?MODULE, ?LINE, 491 Err, Idx, ExpVBs)). 492-define(expect4(Err, Idx, ExpVBs, To), 493 ?ALIB:expect(?MODULE, ?LINE, 494 Err, Idx, ExpVBs, To)). 495-define(expect5(Type, Ent, Gen, Spec, ExpVBs), 496 ?ALIB:expect(?MODULE, ?LINE, 497 Type, Ent, Gen, Spec, ExpVBs)). 498-define(expect6(Type, Ent, Gen, Spec, ExpVBs, To), 499 ?ALIB:expect(?MODULE, ?LINE, 500 Type, Ent, Gen, Spec, ExpVBs, To)). 501 502 503%%====================================================================== 504%% Common Test interface functions 505%%====================================================================== 506 507suite() -> 508 [{ct_hooks, [ts_install_cth]}]. 509 510all() -> 511 %% Reqs = [mnesia, distribution, {local_slave_nodes, 2}, {time, 360}], 512 Conf1 = [{group, all_tcs}], 513 Conf2 = [{group, tickets2}], 514 Conf1 ++ Conf2. 515 516groups() -> 517 [ 518 {all_tcs, [], all_cases()}, 519 {mib_storage, [], mib_storage_cases()}, 520 {mib_storage_ets, [], mib_storage_ets_cases()}, 521 {mib_storage_dets, [], mib_storage_dets_cases()}, 522 {mib_storage_mnesia, [], mib_storage_mnesia_cases()}, 523 {mib_storage_size_check_ets, [], mse_size_check_cases()}, 524 {mib_storage_size_check_dets, [], msd_size_check_cases()}, 525 {mib_storage_size_check_mnesia, [], msm_size_check_cases()}, 526 {mib_storage_varm_dets, [], varm_mib_storage_dets_cases()}, 527 {mib_storage_varm_mnesia, [], varm_mib_storage_mnesia_cases()}, 528 {misc, [], misc_cases()}, 529 {test_v1, [], v1_cases()}, 530 {test_v1_ipv6, [], v1_cases_ipv6()}, 531 {test_v2, [], v2_cases()}, 532 {test_v2_ipv6, [], v2_cases_ipv6()}, 533 {test_v1_v2, [], v1_v2_cases()}, 534 {test_v1_v2_ipv6, [], v1_v2_cases()}, 535 {test_v3, [], v3_cases()}, 536 {test_v3_ipv6, [], v3_cases_ipv6()}, 537 {test_multi_threaded, [], mt_cases()}, 538 {test_multi_threaded_ext, [], mt_cases()}, 539 {multiple_reqs, [], mul_cases()}, 540 {multiple_reqs_2, [], mul_cases_2()}, 541 {multiple_reqs_3, [], mul_cases_3()}, 542 {v2_inform, [], v2_inform_cases()}, 543 {v3_inform, [], v3_inform_cases()}, 544 {v3_security, [], v3_security_cases()}, 545 {standard_mibs, [], standard_mibs_cases()}, 546 {standard_mibs_ipv6, [], standard_mibs_cases_ipv6()}, 547 {standard_mibs_2, [], standard_mibs2_cases()}, 548 {standard_mibs_3, [], standard_mibs3_cases()}, 549 {reported_bugs, [], reported_bugs_cases()}, 550 {reported_bugs_2, [], reported_bugs2_cases()}, 551 {reported_bugs_3, [], reported_bugs3_cases()}, 552 {tickets1, [], tickets1_cases()}, 553 {tickets2, [], tickets2_cases()}, 554 {otp4394, [], [otp_4394]}, 555 {otp7157, [], [otp_7157]}, 556 {otp16092, [], otp16092_cases()} 557 ]. 558 559 560all_cases() -> 561 [ 562 {group, misc}, 563 {group, test_v1}, 564 {group, test_v2}, 565 {group, test_v1_v2}, 566 {group, test_v3}, 567 {group, test_v1_ipv6}, 568 {group, test_v2_ipv6}, 569 {group, test_v1_v2_ipv6}, 570 {group, test_v3_ipv6}, 571 {group, test_multi_threaded}, 572 {group, test_multi_threaded_ext}, 573 {group, mib_storage}, 574 {group, tickets1} 575 ]. 576 577%% 578%% ----- 579%% 580 581init_per_suite(Config0) when is_list(Config0) -> 582 583 ?IPRINT("init_per_suite -> entry with" 584 "~n Config: ~p" 585 "~n Nodes: ~p", [Config0, erlang:nodes()]), 586 587 case ?LIB:init_per_suite(Config0) of 588 {skip, _} = SKIP -> 589 SKIP; 590 591 Config1 when is_list(Config1) -> 592 Config2 = ?LIB:init_suite_top_dir(?MODULE, Config1), 593 Config3 = ?LIB:fix_data_dir(Config2), 594 595 %% Mib-dirs 596 MibDir = ?LIB:lookup(data_dir, Config3), 597 StdMibDir = join([code:priv_dir(snmp), "mibs"]), 598 599 Config4 = [{mib_dir, MibDir}, {std_mib_dir, StdMibDir} | Config3], 600 601 %% We need a monitor on this node also 602 snmp_test_sys_monitor:start(), 603 604 snmp_test_mgr_counter_server:start(), 605 606 ?IPRINT("init_per_suite -> end when" 607 "~n Config: ~p" 608 "~n Nodes: ~p", [Config4, erlang:nodes()]), 609 610 Config4 611 end. 612 613end_per_suite(Config0) when is_list(Config0) -> 614 615 ?IPRINT("end_per_suite -> entry with" 616 "~n Config0: ~p" 617 "~n Nodes: ~p", [Config0, erlang:nodes()]), 618 619 case snmp_test_mgr_counter_server:stop() of 620 {ok, Counters} -> 621 ?IPRINT("end_per_suite -> sucessfully stopped counter server" 622 "~n Counters: ~p", [Counters]); 623 624 {error, Reason} -> 625 ?IPRINT("end_per_suite -> failed stopping counter server" 626 "~n Reason: ~p", [Reason]) 627 end, 628 snmp_test_sys_monitor:stop(), 629 Config1 = ?LIB:end_per_suite(Config0), 630 631 ?IPRINT("end_per_suite -> end when" 632 "~n Nodes: ~p", [erlang:nodes()]), 633 634 Config1. 635 636 637 638%% 639%% ----- 640%% 641 642init_per_group(all_tcs = GroupName, Config) -> 643 init_all(snmp_test_lib:init_group_top_dir(GroupName, Config)); 644init_per_group(otp7157 = GroupName, Config) -> 645 otp_7157_init(snmp_test_lib:init_group_top_dir(GroupName, Config)); 646init_per_group(otp4394 = GroupName, Config) -> 647 otp_4394_init(snmp_test_lib:init_group_top_dir(GroupName, Config)); 648init_per_group(v2_inform = GroupName, Config) -> 649 init_v2_inform(snmp_test_lib:init_group_top_dir(GroupName, Config)); 650init_per_group(v3_inform = GroupName, Config) -> 651 init_v3_inform(snmp_test_lib:init_group_top_dir(GroupName, Config)); 652init_per_group(multiple_reqs = GroupName, Config) -> 653 init_mul(snmp_test_lib:init_group_top_dir(GroupName, Config)); 654init_per_group(multiple_reqs_2 = GroupName, Config) -> 655 init_mul(snmp_test_lib:init_group_top_dir(GroupName, Config)); 656init_per_group(multiple_reqs_3 = GroupName, Config) -> 657 init_mul(snmp_test_lib:init_group_top_dir(GroupName, Config)); 658init_per_group(test_multi_threaded = GroupName, Config) -> 659 init_mt(snmp_test_lib:init_group_top_dir(GroupName, Config), true); 660init_per_group(test_multi_threaded_ext = GroupName, Config) -> 661 init_mt(snmp_test_lib:init_group_top_dir(GroupName, Config), extended); 662init_per_group(test_v3 = GroupName, Config) -> 663 case snmp_test_lib:crypto_start() of 664 ok -> 665 init_v3(snmp_test_lib:init_group_top_dir(GroupName, Config)); 666 _ -> 667 {skip, "Crypto did not start"} 668 end; 669init_per_group(test_v1_v2 = GroupName, Config) -> 670 init_v1_v2(snmp_test_lib:init_group_top_dir(GroupName, Config)); 671init_per_group(test_v2 = GroupName, Config) -> 672 init_v2(snmp_test_lib:init_group_top_dir(GroupName, Config)); 673init_per_group(test_v1 = GroupName, Config) -> 674 init_v1(snmp_test_lib:init_group_top_dir(GroupName, Config)); 675init_per_group(test_v1_ipv6 = GroupName, Config) -> 676 init_per_group_ipv6(GroupName, Config, fun init_v1/1); 677init_per_group(test_v2_ipv6 = GroupName, Config) -> 678 init_per_group_ipv6(GroupName, Config, fun init_v2/1); 679init_per_group(test_v1_v2_ipv6 = GroupName, Config) -> 680 init_per_group_ipv6(GroupName, Config, fun init_v1_v2/1); 681init_per_group(test_v3_ipv6 = GroupName, Config) -> 682 init_per_group_ipv6(GroupName, Config, fun init_v3/1); 683init_per_group(misc = GroupName, Config) -> 684 init_misc(snmp_test_lib:init_group_top_dir(GroupName, Config)); 685init_per_group(mib_storage_varm_mnesia = GroupName, Config) -> 686 init_varm_mib_storage_mnesia(snmp_test_lib:init_group_top_dir(GroupName, 687 Config)); 688init_per_group(mib_storage_varm_dets = GroupName, Config) -> 689 ?DBG("init_per_group(mib_storage_varm_dets) -> entry with" 690 "~n Config: ~p", [Config]), 691 init_varm_mib_storage_dets( 692 snmp_test_lib:init_group_top_dir(GroupName, Config)); 693init_per_group(mib_storage_size_check_mnesia = GroupName, Config) -> 694 case snmp_test_lib:crypto_start() of 695 ok -> 696 init_size_check_msm(snmp_test_lib:init_group_top_dir(GroupName, Config)); 697 _ -> 698 {skip, "Crypto did not start"} 699 end; 700init_per_group(mib_storage_size_check_dets = GroupName, Config) -> 701 case snmp_test_lib:crypto_start() of 702 ok -> 703 init_size_check_msm(snmp_test_lib:init_group_top_dir(GroupName, Config)); 704 _ -> 705 {skip, "Crypto did not start"} 706 end; 707init_per_group(mib_storage_size_check_ets = GroupName, Config) -> 708 case snmp_test_lib:crypto_start() of 709 ok -> 710 init_size_check_msm(snmp_test_lib:init_group_top_dir(GroupName, Config)); 711 _ -> 712 {skip, "Crypto did not start"} 713 end; 714init_per_group(mib_storage_mnesia = GroupName, Config) -> 715 init_mib_storage_mnesia(snmp_test_lib:init_group_top_dir(GroupName, 716 Config)); 717init_per_group(mib_storage_dets = GroupName, Config) -> 718 init_mib_storage_dets(snmp_test_lib:init_group_top_dir(GroupName, Config)); 719init_per_group(mib_storage_ets = GroupName, Config) -> 720 init_mib_storage_ets(snmp_test_lib:init_group_top_dir(GroupName, Config)); 721init_per_group(GroupName, Config) -> 722 snmp_test_lib:init_group_top_dir(GroupName, Config). 723 724init_per_group_ipv6(GroupName, Config, Init) -> 725 %% <OS-CONDITIONAL-SKIP> 726 %% This is a higly questionable test. 727 %% But until we have time to figure out what IPv6 issues 728 %% are actually causing the failures... 729 OSSkipable = [{unix, 730 [ 731 {darwin, fun(V) when (V > {9, 8, 0}) -> 732 %% This version is OK: No Skip 733 false; 734 (_) -> 735 %% This version is *not* ok: Skip 736 true 737 end} 738 ] 739 }], 740 %% </OS-CONDITIONAL-SKIP> 741 case ?OS_BASED_SKIP(OSSkipable) of 742 true -> 743 {skip, "Host *may* not *properly* support IPV6"}; 744 false -> 745 %% Even if this host supports IPv6 we don't use it unless its 746 %% one of the configured/supported IPv6 hosts... 747 case ?HAS_SUPPORT_IPV6() of 748 true -> 749 Init( 750 snmp_test_lib:init_group_top_dir( 751 GroupName, 752 [{ipfamily, inet6}, 753 {ip, ?LOCALHOST(inet6)} 754 | lists:keydelete(ip, 1, Config)])); 755 false -> 756 {skip, "Host does not support IPv6"} 757 end 758 end. 759 760end_per_group(all_tcs, Config) -> 761 finish_all(Config); 762end_per_group(otp7157, Config) -> 763 otp_7157_finish(Config); 764end_per_group(otp4394, Config) -> 765 otp_4394_finish(Config); 766end_per_group(v2_inform, Config) -> 767 finish_v2_inform(Config); 768end_per_group(v3_inform, Config) -> 769 finish_v3_inform(Config); 770end_per_group(multiple_reqs, Config) -> 771 finish_mul(Config); 772end_per_group(multiple_reqs_2, Config) -> 773 finish_mul(Config); 774end_per_group(multiple_reqs_3, Config) -> 775 finish_mul(Config); 776end_per_group(test_multi_threaded, Config) -> 777 finish_mt(Config); 778end_per_group(test_multi_threaded_ext, Config) -> 779 finish_mt(Config); 780end_per_group(test_v3_ipv6, Config) -> 781 finish_v3(Config); 782end_per_group(test_v1_v2_ipv6, Config) -> 783 finish_v1_v2(Config); 784end_per_group(test_v2_ipv6, Config) -> 785 finish_v2(Config); 786end_per_group(test_v1_ipv6, Config) -> 787 finish_v1(Config); 788end_per_group(test_v3, Config) -> 789 finish_v3(Config); 790end_per_group(test_v1_v2, Config) -> 791 finish_v1_v2(Config); 792end_per_group(test_v2, Config) -> 793 finish_v2(Config); 794end_per_group(test_v1, Config) -> 795 finish_v1(Config); 796end_per_group(misc, Config) -> 797 finish_misc(Config); 798end_per_group(mib_storage_varm_mnesia, Config) -> 799 finish_varm_mib_storage_mnesia(Config); 800end_per_group(mib_storage_varm_dets, Config) -> 801 finish_varm_mib_storage_dets(Config); 802end_per_group(mib_storage_size_check_mnesia, Config) -> 803 finish_size_check_msm(Config); 804end_per_group(mib_storage_size_check_dets, Config) -> 805 finish_size_check_msd(Config); 806end_per_group(mib_storage_size_check_ets, Config) -> 807 finish_size_check_mse(Config); 808end_per_group(mib_storage_mnesia, Config) -> 809 finish_mib_storage_mnesia(Config); 810end_per_group(mib_storage_dets, Config) -> 811 finish_mib_storage_dets(Config); 812end_per_group(mib_storage_ets, Config) -> 813 finish_mib_storage_ets(Config); 814end_per_group(_GroupName, Config) -> 815 Config. 816 817 818 819%% 820%% ----- Init Per TestCase ----- 821%% 822 823%% T is in number of minutes 824wd_start(T, Config) -> 825 Factor = case ?config(snmp_factor, Config) of 826 F when (F > 0) -> 827 F-1; 828 _ -> 829 0 830 end, 831 Dog = ?WD_START(?MINS(T + Factor)), 832 [{watchdog, Dog} | Config ]. 833 834 835wd_stop(Config) -> 836 Dog = ?config(watchdog, Config), 837 ?WD_STOP(Dog), 838 lists:keydelete(Dog, 2, Config). 839 840init_per_testcase(Case, Config) when is_list(Config) -> 841 ?IPRINT("init_per_testcase -> entry with" 842 "~n Config: ~p" 843 "~n Nodes: ~p", [Config, erlang:nodes()]), 844 845 Result = init_per_testcase1(Case, Config), 846 847 snmp_test_global_sys_monitor:reset_events(), 848 849 ?IPRINT("init_per_testcase -> done when" 850 "~n Result: ~p" 851 "~n Nodes: ~p", [Result, erlang:nodes()]), 852 Result. 853 854init_per_testcase1(otp8395 = Case, Config) when is_list(Config) -> 855 ?DBG("init_per_testcase1 -> entry with" 856 "~n Case: ~p" 857 "~n Config: ~p", [Case, Config]), 858 otp8395({init, init_per_testcase2(Case, Config)}); 859init_per_testcase1(otp9884 = Case, Config) when is_list(Config) -> 860 ?DBG("init_per_testcase1 -> entry with" 861 "~n Case: ~p" 862 "~n Config: ~p", [Case, Config]), 863 otp9884({init, init_per_testcase2(Case, Config)}); 864init_per_testcase1(otp_7157 = _Case, Config) when is_list(Config) -> 865 ?DBG("init_per_testcase1 -> entry with" 866 "~n Case: ~p" 867 "~n Config: ~p", [_Case, Config]), 868 wd_start(1, Config); 869init_per_testcase1(Case, Config) 870 when ((Case =:= otp_16092_simple_start_and_stop1) orelse 871 (Case =:= otp_16092_simple_start_and_stop2) orelse 872 (Case =:= otp_16092_simple_start_and_stop3) orelse 873 (Case =:= otp_16092_simple_start_and_stop4)) andalso 874 is_list(Config) -> 875 ?DBG("init_per_testcase1 -> entry with" 876 "~n Case: ~p" 877 "~n Config: ~p", [_Case, Config]), 878 init_per_testcase2(Case, wd_start(1, Config)); 879init_per_testcase1(v2_inform_i = _Case, Config) when is_list(Config) -> 880 ?DBG("init_per_testcase1 -> entry with" 881 "~n Case: ~p" 882 "~n Config: ~p", [_Case, Config]), 883 wd_start(10, Config); 884init_per_testcase1(v3_inform_i = _Case, Config) when is_list(Config) -> 885 ?DBG("init_per_testcase1 -> entry with" 886 "~n Case: ~p" 887 "~n Config: ~p", [_Case, Config]), 888 wd_start(10, Config); 889init_per_testcase1(_Case, Config) when is_list(Config) -> 890 ?DBG("init_per_testcase -> entry with" 891 "~n Case: ~p" 892 "~n Config: ~p", [_Case, Config]), 893 wd_start(6, Config). 894 895init_per_testcase2(Case, Config) -> 896 897 ?DBG("init_per_testcase2 -> entry with" 898 "~n Case: ~p" 899 "~n Config: ~p", [Case, Config]), 900 901 CaseTopDir = snmp_test_lib:init_testcase_top_dir(Case, Config), 902 903 %% Create agent top-dir(s) 904 AgentTopDir = join([CaseTopDir, agent]), 905 ok = file:make_dir(AgentTopDir), 906 AgentConfDir = join([AgentTopDir, config]), 907 ok = file:make_dir(AgentConfDir), 908 AgentDbDir = join([AgentTopDir, db]), 909 ok = file:make_dir(AgentDbDir), 910 AgentLogDir = join([AgentTopDir, log]), 911 ok = file:make_dir(AgentLogDir), 912 913 %% Create sub-agent top-dir(s) 914 SubAgentTopDir = join([CaseTopDir, sub_agent]), 915 ok = file:make_dir(SubAgentTopDir), 916 917 %% Create manager top-dir(s) 918 ManagerTopDir = join([CaseTopDir, manager]), 919 ok = file:make_dir(ManagerTopDir), 920 921 [{case_top_dir, CaseTopDir}, 922 {agent_top_dir, AgentTopDir}, 923 {agent_conf_dir, AgentConfDir}, 924 {agent_db_dir, AgentDbDir}, 925 {agent_log_dir, AgentLogDir}, 926 {sub_agent_top_dir, SubAgentTopDir}, 927 {manager_top_dir, ManagerTopDir} | Config]. 928 929 930%% ---- End Per TestCase ---- 931 932end_per_testcase(Case, Config) when is_list(Config) -> 933 934 ?IPRINT("end_per_testcase -> entry with" 935 "~n Config: ~p" 936 "~n Nodes: ~p", 937 [Config, erlang:nodes()]), 938 939 ?IPRINT("system events during test: " 940 "~n ~p", [snmp_test_global_sys_monitor:events()]), 941 942 %% On some hosts, this operation can take a long time. 943 %% So long, that the timetrap expires and the test case 944 %% will be "failed". 945 %% So, wrap it in a process and for a successful test case, 946 %% give it 30 seconds, then kill it. If the test case has 947 %% already failed, we will want to get as much of the logs 948 %% as possible. So, set no timeout (infinity) and let the 949 %% test framework take care of things... 950 DisplayLogTimeout = 951 case ?config(tc_status, Config) of 952 ok -> 953 ?SECS(30); 954 _ -> 955 infinity 956 end, 957 Flag = process_flag(trap_exit, true), 958 Pid = spawn_link(fun() -> display_log(Config), exit(normal) end), 959 receive 960 {'EXIT', Pid, _} -> 961 process_flag(trap_exit, Flag), 962 ok 963 after DisplayLogTimeout -> 964 ?WPRINT("Display Log process fail to complete in time (~w msec): " 965 "kill it", [DisplayLogTimeout]), 966 process_flag(trap_exit, Flag), 967 exit(Pid, kill) 968 end, 969 970 Result = end_per_testcase1(Case, Config), 971 972 ?IPRINT("end_per_testcase -> done with" 973 "~n Result: ~p" 974 "~n Nodes: ~p", [Result, erlang:nodes()]), 975 Result. 976 977end_per_testcase1(otp8395, Config) when is_list(Config) -> 978 otp8395({fin, Config}); 979end_per_testcase1(otp9884, Config) when is_list(Config) -> 980 otp9884({fin, Config}); 981end_per_testcase1(_Case, Config) when is_list(Config) -> 982 ?DBG("end_per_testcase1 -> entry with" 983 "~n Case: ~p" 984 "~n Config: ~p", [_Case, Config]), 985 wd_stop(Config). 986 987 988 989 990 991%%%----------------------------------------------------------------- 992%%% The test case structure is as follows: 993%%% 994%%% init_all - starts mnesia, 995%%% 996%%% init_v1 - starts agent 997%%% simple 998%%% big - e.g. starts/stops subagent, load/unloads mibs 999%%% init_mul 1000%%% mul_get 1001%%% mul_set 1002%%% <etc> 1003%%% finish_mul 1004%%% <etc> 1005%%% finish_v1 1006%%% 1007%%% init_v2 - starts agent 1008%%% finish_v2 1009%%% 1010%%% init_bilingual - starts agent 1011%%% finish_bilingual 1012%%% 1013%%% finish_all 1014%%% 1015%%% There is still one problem with these testsuites. If one test 1016%%% fails, it may not be possible to run some other cases, as it 1017%%% may have e.g. created some row or loaded some table, that it 1018%%% didn't undo (since it failed). 1019%%%----------------------------------------------------------------- 1020 1021init_all(Conf) -> 1022 ?DISPLAY_SUITE_INFO(), 1023 ?ALIB:init_all(Conf). 1024 1025finish_all(Conf) -> 1026 ?ALIB:finish_all(Conf). 1027 1028start_v1_agent(Config) -> 1029 ?ALIB:start_v1_agent(Config). 1030 1031start_v1_agent(Config, Opts) -> 1032 ?ALIB:start_v1_agent(Config, Opts). 1033 1034start_v2_agent(Config) -> 1035 ?ALIB:start_v2_agent(Config). 1036 1037start_v2_agent(Config, Opts) -> 1038 ?ALIB:start_v2_agent(Config, Opts). 1039 1040%% start_v3_agent(Config) -> 1041%% ?ALIB:start_v3_agent(Config). 1042 1043start_v3_agent(Config, Opts) -> 1044 ?ALIB:start_v3_agent(Config, Opts). 1045 1046start_bilingual_agent(Config) -> 1047 ?ALIB:start_bilingual_agent(Config). 1048 1049start_multi_threaded_agent(Config, MT) when is_list(Config) -> 1050 [{multi_threaded, MT} | ?ALIB:start_mt_agent(Config, MT)]. 1051 1052stop_agent(Config) -> 1053 ?ALIB:stop_agent(Config). 1054 1055 1056create_tables(SaNode) -> 1057 ?line {atomic, ok} = mnesia:create_table([{name, friendsTable2}, 1058 {ram_copies, [SaNode]}, 1059 {snmp, [{key, integer}]}, 1060 {attributes, [a1,a2,a3]}]), 1061 ?line {atomic, ok} = mnesia:create_table([{name, kompissTable2}, 1062 {ram_copies, [SaNode]}, 1063 {snmp, [{key, integer}]}, 1064 {attributes, [a1,a2,a3]}]), 1065 ?line {atomic, ok} = mnesia:create_table([{name, snmp_variables}, 1066 {attributes, [a1,a2]}]). 1067 1068delete_tables() -> 1069 mnesia:delete_table(friendsTable2), 1070 mnesia:delete_table(kompissTable2), 1071 mnesia:delete_table(snmp_variables). 1072 1073%% Tables are created in runtime! 1074delete_mib_storage_mnesia_tables() -> 1075 mnesia:delete_table(snmpa_mib_data), 1076 mnesia:delete_table(snmpa_mib_tree), 1077 mnesia:delete_table(snmpa_symbolic_store). 1078 1079 1080%%----------------------------------------------------------------- 1081%% A test case is always one of: 1082%% - v1 specific case 1083%% - v2 specific case 1084%% - v1 and v2 case 1085%% All v1 specific cases are prefixed with v1_, and all v2 with 1086%% v2_. E.g. v1_trap/v2_trap. 1087%% 1088%% All other cases are shared. However, the testserver uses the name 1089%% of the case to generate a file for that case. The same case cannot 1090%% be used in different configurations in the same suite. Therefore 1091%% all these functions exists in two variants, the base function 1092%% <base>, and a second version <base>_2. There may be several 1093%% versions as well, <base>_N. 1094%%----------------------------------------------------------------- 1095 1096mib_storage_cases() -> 1097 [ 1098 {group, mib_storage_ets}, 1099 {group, mib_storage_dets}, 1100 {group, mib_storage_mnesia}, 1101 {group, mib_storage_size_check_ets}, 1102 {group, mib_storage_size_check_dets}, 1103 {group, mib_storage_size_check_mnesia}, 1104 {group, mib_storage_varm_dets}, 1105 {group, mib_storage_varm_mnesia} 1106 ]. 1107 1108mib_storage_ets_cases() -> 1109 [ 1110 mse_simple, 1111 mse_v1_processing, 1112 mse_big, 1113 mse_big2, 1114 mse_loop_mib, 1115 mse_api, 1116 mse_sa_register, 1117 mse_v1_trap, 1118 mse_sa_error, 1119 mse_next_across_sa, 1120 mse_undo, 1121 mse_standard_mib, 1122 mse_community_mib, 1123 mse_framework_mib, 1124 mse_target_mib, 1125 mse_notification_mib, 1126 mse_view_based_acm_mib, 1127 mse_sparse_table, 1128 mse_me_of, 1129 mse_mib_of 1130 ]. 1131 1132mib_storage_dets_cases() -> 1133 [ 1134 msd_simple, 1135 msd_v1_processing, 1136 msd_big, 1137 msd_big2, 1138 msd_loop_mib, 1139 msd_api, 1140 msd_sa_register, 1141 msd_v1_trap, 1142 msd_sa_error, 1143 msd_next_across_sa, 1144 msd_undo, 1145 msd_standard_mib, 1146 msd_community_mib, 1147 msd_framework_mib, 1148 msd_target_mib, 1149 msd_notification_mib, 1150 msd_view_based_acm_mib, 1151 msd_sparse_table, 1152 msd_me_of, 1153 msd_mib_of 1154 ]. 1155 1156mib_storage_mnesia_cases() -> 1157 [ 1158 msm_simple, 1159 msm_v1_processing, 1160 msm_big, 1161 msm_big2, 1162 msm_loop_mib, 1163 msm_api, 1164 msm_sa_register, 1165 msm_v1_trap, 1166 msm_sa_error, 1167 msm_next_across_sa, 1168 msm_undo, 1169 msm_standard_mib, 1170 msm_community_mib, 1171 msm_framework_mib, 1172 msm_target_mib, 1173 msm_notification_mib, 1174 msm_view_based_acm_mib, 1175 msm_sparse_table, 1176 msm_me_of, 1177 msm_mib_of 1178 ]. 1179 1180mse_size_check_cases() -> 1181 [mse_size_check]. 1182 1183msd_size_check_cases() -> 1184 [msd_size_check]. 1185 1186msm_size_check_cases() -> 1187 [msm_size_check]. 1188 1189varm_mib_storage_dets_cases() -> 1190 [msd_varm_mib_start]. 1191 1192varm_mib_storage_mnesia_cases() -> 1193 [msm_varm_mib_start]. 1194 1195init_mib_storage_ets(Config) when is_list(Config) -> 1196 ?IPRINT("init_mib_storage_ets -> entry"), 1197 MibStorage = {mib_storage, [{module, snmpa_mib_storage_ets}]}, 1198 init_ms(Config, [MibStorage]). 1199 1200init_mib_storage_dets(Config) when is_list(Config) -> 1201 ?IPRINT("init_mib_storage_dets -> entry"), 1202 ?line AgentDbDir = ?GCONF(agent_db_dir, Config), 1203 MibStorage = {mib_storage, [{module, snmpa_mib_storage_dets}, 1204 {options, [{dir, AgentDbDir}]}]}, 1205 init_ms(Config, [MibStorage]). 1206 1207init_mib_storage_mnesia(Config) when is_list(Config) -> 1208 ?IPRINT("init_mib_storage_mnesia -> entry"), 1209 ?line AgentNode = ?GCONF(snmp_master, Config), 1210 MibStorage = {mib_storage, [{module, snmpa_mib_storage_mnesia}, 1211 {options, [{nodes, [AgentNode]}]}]}, 1212 init_ms(Config, [MibStorage]). 1213 1214init_ms(Config, Opts) when is_list(Config) -> 1215 ?IPRINT("init_ms -> entry with" 1216 "~n Config: ~p" 1217 "~n Opts: ~p", [Config, Opts]), 1218 ?line SaNode = ?GCONF(snmp_sa, Config), 1219 ?line create_tables(SaNode), 1220 ?line AgentConfDir = ?GCONF(agent_conf_dir, Config), 1221 ?line MgrDir = ?GCONF(mgr_dir, Config), 1222 ?line Ip = ?GCONF(ip, Config), 1223 ?line config([v1], MgrDir, AgentConfDir, 1224 tuple_to_list(Ip), tuple_to_list(Ip)), 1225 MasterAgentVerbosity = {agent_verbosity, trace}, 1226 MibsVerbosity = {mib_server, [{verbosity, trace}]}, 1227 SymStoreVerbosity = {symbolic_store, [{verbosity, trace}]}, 1228 Opts1 = [MasterAgentVerbosity, MibsVerbosity, SymStoreVerbosity | Opts], 1229 [{vsn, v1} | start_v1_agent(Config, Opts1)]. 1230 1231%% init_size_check_mse(Config) when is_list(Config) -> 1232%% MibStorage = {mib_storage, [{module, snmpa_mib_storage_ets}]}, 1233%% init_size_check_ms(Config, [MibStorage]). 1234 1235%% init_size_check_msd(Config) when is_list(Config) -> 1236%% AgentDbDir = ?GCONF(agent_db_dir, Config), 1237%% MibStorage = {mib_storage, [{module, snmpa_mib_storage_dets}, 1238%% {options, [{dir, AgentDbDir}]}]}, 1239%% init_size_check_ms(Config, [MibStorage]). 1240 1241init_size_check_msm(Config) when is_list(Config) -> 1242 ?line AgentNode = ?GCONF(snmp_master, Config), 1243 MibStorage = {mib_storage, [{module, snmpa_mib_storage_mnesia}, 1244 {options, [{nodes, [AgentNode]}]}]}, 1245 init_size_check_ms(Config, [MibStorage]). 1246 1247init_size_check_ms(Config, Opts) when is_list(Config) -> 1248 SaNode = ?GCONF(snmp_sa, Config), 1249 %% We are using v3 here, so crypto must be supported or else... 1250 case ?CRYPTO_START() of 1251 ok -> 1252 case ?CRYPTO_SUPPORT() of 1253 {no, Reason} -> 1254 ?WPRINT("crypto support not sufficient:" 1255 "~n ~p", [Reason]), 1256 ?SKIP({unsupported_encryption, Reason}); 1257 yes -> 1258 ?IPRINT("crypto started"), 1259 ok 1260 end; 1261 {error, Reason} -> 1262 ?IPRINT("crypto not started:" 1263 "~n ~p", [Reason]), 1264 ?SKIP({failed_starting_crypto, Reason}) 1265 end, 1266 create_tables(SaNode), 1267 AgentConfDir = ?GCONF(agent_conf_dir, Config), 1268 MgrDir = ?GCONF(mgr_dir, Config), 1269 Ip = ?GCONF(ip, Config), 1270 ?line ok = config([v3], MgrDir, AgentConfDir, 1271 tuple_to_list(Ip), tuple_to_list(Ip)), 1272 [{vsn, v3} | start_v3_agent(Config, Opts)]. 1273 1274init_varm_mib_storage_dets(Config) when is_list(Config) -> 1275 ?IPRINT("init_varm_mib_storage_dets -> entry"), 1276 ?line SaNode = ?GCONF(snmp_sa, Config), 1277 ?line create_tables(SaNode), 1278 ?line AgentDbDir = ?GCONF(agent_db_dir, Config), 1279 ?line AgentConfDir = ?GCONF(agent_conf_dir, Config), 1280 ?line MgrDir = ?GCONF(mgr_dir, Config), 1281 ?line Ip = ?GCONF(ip, Config), 1282 ?line config([v1], MgrDir, AgentConfDir, 1283 tuple_to_list(Ip), tuple_to_list(Ip)), 1284 MibStorage = {mib_storage, [{module, snmpa_mib_storage_dets}, 1285 {options, [{dir, AgentDbDir}]}]}, 1286 MasterAgentVerbosity = {agent_verbosity, trace}, 1287 MibsVerbosity = {mib_server, [{verbosity, trace}]}, 1288 SymStoreVerbosity = {symbolic_store, [{verbosity, trace}]}, 1289 Opts = [MibStorage, 1290 MasterAgentVerbosity, 1291 MibsVerbosity, 1292 SymStoreVerbosity], 1293 [{vsn, v1}, {agent_opts, Opts} | Config]. 1294 1295init_varm_mib_storage_mnesia(Config) when is_list(Config) -> 1296 ?IPRINT("init_varm_mib_storage_mnesia -> entry"), 1297 ?line SaNode = ?GCONF(snmp_sa, Config), 1298 ?line create_tables(SaNode), 1299 ?line AgentConfDir = ?GCONF(agent_conf_dir, Config), 1300 ?line MgrDir = ?GCONF(mgr_dir, Config), 1301 ?line Ip = ?GCONF(ip, Config), 1302 ?line config([v1], MgrDir, AgentConfDir, 1303 tuple_to_list(Ip), tuple_to_list(Ip)), 1304 ?line AgentNode = ?GCONF(snmp_master, Config), 1305 MibStorage = {mib_storage, [{module, snmpa_mib_storage_mnesia}, 1306 {options, [{nodes, [AgentNode]}]}]}, 1307 MasterAgentVerbosity = {agent_verbosity, trace}, 1308 MibsVerbosity = {mib_server, [{verbosity, trace}]}, 1309 SymStoreVerbosity = {symbolic_store, [{verbosity, trace}]}, 1310 Opts = [MibStorage, 1311 MasterAgentVerbosity, 1312 MibsVerbosity, 1313 SymStoreVerbosity], 1314 [{vsn, v1}, {agent_opts, Opts} | Config]. 1315 1316finish_mib_storage_ets(Config) when is_list(Config) -> 1317 ?IPRINT("finish_mib_storage_ets -> entry"), 1318 delete_tables(), 1319 C1 = stop_agent(Config), 1320 delete_files(C1), 1321 C2 = lists:keydelete(vsn, 1, C1), 1322 lists:keydelete(agent_opts, 1, C2). 1323 1324finish_mib_storage_dets(Config) when is_list(Config) -> 1325 ?IPRINT("finish_mib_storage_dets -> entry"), 1326 delete_tables(), 1327 C1 = stop_agent(Config), 1328 delete_files(C1), 1329 C2 = lists:keydelete(vsn, 1, C1), 1330 lists:keydelete(agent_opts, 1, C2). 1331 1332finish_mib_storage_mnesia(Config) when is_list(Config) -> 1333 ?IPRINT("finish_mib_storage_mnesia -> entry"), 1334 delete_tables(), 1335 delete_mib_storage_mnesia_tables(), 1336 C1 = stop_agent(Config), 1337 delete_files(C1), 1338 C2 = lists:keydelete(vsn, 1, C1), 1339 lists:keydelete(agent_opts, 1, C2). 1340 1341finish_varm_mib_storage_dets(Config) when is_list(Config) -> 1342 ?IPRINT("finish_varm_mib_storage_dets -> entry"), 1343 delete_tables(), 1344 %% C1 = stop_agent(Config), % In case something went wrong... 1345 delete_files(Config), 1346 C2 = lists:keydelete(vsn, 1, Config), 1347 lists:keydelete(agent_opts, 1, C2). 1348 1349finish_varm_mib_storage_mnesia(Config) when is_list(Config) -> 1350 ?IPRINT("finish_varm_mib_storage_mnesia -> entry"), 1351 delete_tables(), 1352 delete_mib_storage_mnesia_tables(), 1353 %% C1 = stop_agent(Config), % In case something went wrong... 1354 delete_files(Config), 1355 C2 = lists:keydelete(vsn, 1, Config), 1356 lists:keydelete(agent_opts, 1, C2). 1357 1358finish_size_check_mse(Config) when is_list(Config) -> 1359 finish_size_check_ms(Config). 1360 1361finish_size_check_msd(Config) when is_list(Config) -> 1362 finish_size_check_ms(Config). 1363 1364finish_size_check_msm(Config) when is_list(Config) -> 1365 finish_size_check_ms(Config). 1366 1367finish_size_check_ms(Config) when is_list(Config) -> 1368 delete_tables(), 1369 C1 = stop_agent(Config), 1370 delete_files(C1), 1371 lists:keydelete(vsn, 1, C1). 1372 1373 1374%% These are just interface functions to fool the test server 1375mse_simple(X) -> ?P(mse_simple), simple(X). 1376mse_v1_processing(X) -> ?P(mse_v1_processing), v1_processing(X). 1377mse_big(X) -> ?P(mse_big), big(X). 1378mse_big2(X) -> ?P(mse_big2), big2(X). 1379mse_loop_mib(X) -> ?P(mse_loop_mib), loop_mib_1(X). 1380mse_api(X) -> ?P(mse_api), api(X). 1381mse_sa_register(X) -> ?P(mse_sa_register), sa_register(X). 1382mse_v1_trap(X) -> ?P(mse_v1_trap), v1_trap(X). 1383mse_sa_error(X) -> ?P(mse_sa_error), sa_error(X). 1384mse_next_across_sa(X) -> ?P(mse_next_across_sa), next_across_sa(X). 1385mse_undo(X) -> ?P(mse_undo), undo(X). 1386mse_standard_mib(X) -> ?P(mse_standard_mib), snmp_standard_mib(X). 1387mse_community_mib(X) -> ?P(mse_community_mib), snmp_community_mib(X). 1388mse_framework_mib(X) -> ?P(mse_framework_mib), snmp_framework_mib(X). 1389mse_target_mib(X) -> ?P(mse_target_mib), snmp_target_mib(X). 1390mse_notification_mib(X) -> ?P(mse_notification_mib), snmp_notification_mib(X). 1391mse_view_based_acm_mib(X) -> ?P(mse_view_based_acm_mib), snmp_view_based_acm_mib(X). 1392mse_sparse_table(X) -> ?P(mse_sparse_table), sparse_table(X). 1393mse_me_of(X) -> ?P(mse_me_of), ms_me_of(X). 1394mse_mib_of(X) -> ?P(mse_mib_of), ms_mib_of(X). 1395 1396msd_simple(X) -> ?P(msd_simple), simple(X). 1397msd_v1_processing(X) -> ?P(msd_v1_processing), v1_processing(X). 1398msd_big(X) -> ?P(msd_big), big(X). 1399msd_big2(X) -> ?P(msd_big2), big2(X). 1400msd_loop_mib(X) -> ?P(msd_loop_mib), loop_mib_1(X). 1401msd_api(X) -> ?P(msd_api), api(X). 1402msd_sa_register(X) -> ?P(msd_sa_register), sa_register(X). 1403msd_v1_trap(X) -> ?P(msd_v1_trap), v1_trap(X). 1404msd_sa_error(X) -> ?P(msd_sa_error), sa_error(X). 1405msd_next_across_sa(X) -> ?P(msd_next_across_sa), next_across_sa(X). 1406msd_undo(X) -> ?P(msd_undo), undo(X). 1407msd_standard_mib(X) -> ?P(msd_standard_mib), snmp_standard_mib(X). 1408msd_community_mib(X) -> ?P(msd_community_mib), snmp_community_mib(X). 1409msd_framework_mib(X) -> ?P(msd_framework_mib), snmp_framework_mib(X). 1410msd_target_mib(X) -> ?P(msd_target_mib), snmp_target_mib(X). 1411msd_notification_mib(X) -> ?P(msd_notification_mib), snmp_notification_mib(X). 1412msd_view_based_acm_mib(X) -> ?P(msd_view_based_acm_mib), snmp_view_based_acm_mib(X). 1413msd_sparse_table(X) -> ?P(msd_sparse_table), sparse_table(X). 1414msd_me_of(X) -> ?P(msd_me_of), ms_me_of(X). 1415msd_mib_of(X) -> ?P(msd_mib_of), ms_mib_of(X). 1416 1417msm_simple(X) -> ?P(msm_simple), simple(X). 1418msm_v1_processing(X) -> ?P(msm_v1_processing), v1_processing(X). 1419msm_big(X) -> ?P(msm_big2), big(X). 1420msm_big2(X) -> ?P(msm_loop_mib), big2(X). 1421msm_loop_mib(X) -> ?P(msm_loop_mib), loop_mib_1(X). 1422msm_api(X) -> ?P(msm_api), api(X). 1423msm_sa_register(X) -> ?P(msm_sa_register), sa_register(X). 1424msm_v1_trap(X) -> ?P(msm_v1_trap), v1_trap(X). 1425msm_sa_error(X) -> ?P(msm_sa_error), sa_error(X). 1426msm_next_across_sa(X) -> ?P(msm_next_across_sa), next_across_sa(X). 1427msm_undo(X) -> ?P(msm_undo), undo(X). 1428msm_standard_mib(X) -> ?P(msm_standard_mib), snmp_standard_mib(X). 1429msm_community_mib(X) -> ?P(msm_community_mib), snmp_community_mib(X). 1430msm_framework_mib(X) -> ?P(msm_framework_mib), snmp_framework_mib(X). 1431msm_target_mib(X) -> ?P(msm_target_mib), snmp_target_mib(X). 1432msm_notification_mib(X) -> ?P(msm_notification_mib), snmp_notification_mib(X). 1433msm_view_based_acm_mib(X) -> ?P(msm_view_based_acm_mib), snmp_view_based_acm_mib(X). 1434msm_sparse_table(X) -> ?P(msm_sparse_table), sparse_table(X). 1435msm_me_of(X) -> ?P(msm_me_of), ms_me_of(X). 1436msm_mib_of(X) -> ?P(msm_mib_of), ms_mib_of(X). 1437 1438 1439mse_size_check(X) -> ?P(mse_size_check), ms_size_check(X). 1440msd_size_check(X) -> ?P(msd_size_check), ms_size_check(X). 1441msm_size_check(X) -> ?P(msm_size_check), ms_size_check(X). 1442 1443msd_varm_mib_start(X) -> 1444 ?P(msd_varm_mib_start), 1445 varm_mib_start(X). 1446 1447msm_varm_mib_start(X) -> 1448 %% <CONDITIONAL-SKIP> 1449 Skippable = [win32], 1450 Condition = fun() -> ?OS_BASED_SKIP(Skippable) end, 1451 ?NON_PC_TC_MAYBE_SKIP(X, Condition), 1452 %% </CONDITIONAL-SKIP> 1453 1454 ?P(msm_varm_mib_start), 1455 varm_mib_start(X). 1456 1457ms_size_check(suite) -> []; 1458ms_size_check(Config) when is_list(Config) -> 1459 ?P(ms_size_check), 1460 init_case(Config), 1461 ?IPRINT("mib server size check..."), 1462 1463 ?line load_master("Test2"), 1464 ?line load_master("TestTrap"), 1465 ?line load_master("TestTrapv2"), 1466 ?line load_master_std("OTP-SNMPEA-MIB"), 1467 ?line load_master_std("SNMP-COMMUNITY-MIB"), 1468 ?line load_master_std("SNMP-FRAMEWORK-MIB"), 1469 ?line load_master_std("SNMP-MPD-MIB"), 1470 ?line load_master_std("SNMP-NOTIFICATION-MIB"), 1471 ?line load_master_std("SNMP-TARGET-MIB"), 1472 ?line load_master_std("SNMP-USER-BASED-SM-MIB"), 1473 ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), 1474 ?line load_master_std("SNMPv2-MIB"), 1475 ?line load_master_std("SNMPv2-TM"), 1476 1477 ?SLEEP(2000), 1478 1479 ?line display_memory_usage(), 1480 1481 ?line unload_master("OTP-SNMPEA-MIB"), 1482 ?line unload_master("SNMP-COMMUNITY-MIB"), 1483 ?line unload_master("SNMP-FRAMEWORK-MIB"), 1484 ?line unload_master("SNMP-MPD-MIB"), 1485 ?line unload_master("SNMP-NOTIFICATION-MIB"), 1486 ?line unload_master("SNMP-TARGET-MIB"), 1487 ?line unload_master("SNMP-USER-BASED-SM-MIB"), 1488 ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), 1489 ?line unload_master("SNMPv2-MIB"), 1490 ?line unload_master("SNMPv2-TM"), 1491 1492 ?line unload_master("TestTrapv2"), 1493 ?line unload_master("TestTrap"), 1494 ?line unload_master("Test2"), 1495 1496 ok. 1497 1498 1499varm_mib_start(suite) -> []; 1500varm_mib_start(Config) when is_list(Config) -> 1501 ?P(varm_mib_start), 1502 ?IPRINT("varm_mib_start -> entry"), 1503 init_case(Config), 1504 1505 %% Start the agent 1506 Opts = ?GCONF(agent_opts, Config), 1507 Config1 = start_v1_agent(Config, Opts), 1508 1509 %% Sleep some in order for the agent to start properly 1510 ?DBG("varm_mib_start -> sleep some (before loading mobs)", []), 1511 ?SLEEP(5000), 1512 1513 %% Load all the mibs 1514 HardwiredMibs = loaded_mibs(), 1515 ?DBG("varm_mib_start -> load all mibs", []), 1516 ?line load_master_std("SNMP-COMMUNITY-MIB"), 1517 ?line load_master_std("SNMP-FRAMEWORK-MIB"), 1518 ?line load_master_std("SNMP-TARGET-MIB"), 1519 ?line load_master_std("SNMP-NOTIFICATION-MIB"), 1520 1521 %% Unload the hardwired mibs 1522 ?DBG("varm_mib_start -> sleep some (before unloading hardwired mibs)", []), 1523 ?SLEEP(1000), 1524 ?DBG("varm_mib_start -> unload (hardwired) mibs", []), 1525 ?line unload_mibs(HardwiredMibs), %% unload hardwired 1526 1527 ?DBG("varm_mib_start -> sleep some (before stopping agent)", []), 1528 ?SLEEP(1000), 1529 1530 %% Stop the agent (without deleting the stored files) 1531 ?DBG("varm_mib_start -> stop the agent", []), 1532 Config2 = stop_agent(Config1), 1533 1534 %% Sleep some in order for the agent to stop properly 1535 ?DBG("varm_mib_start -> sleep some (before re-starting the agent)", []), 1536 ?SLEEP(5000), 1537 1538 %% Start the agent (again) 1539 ?DBG("varm_mib_start -> start the agent", []), 1540 Config3 = start_v1_agent(Config2, Opts), 1541 1542 ?DBG("varm_mib_start -> sleep some (before starting tests)", []), 1543 ?SLEEP(5000), 1544 1545 %% Perform the test(s) 1546 ?DBG("varm_mib_start -> perform the tests", []), 1547 try_test(snmp_community_mib_test), 1548 try_test(snmp_framework_mib_test), 1549 try_test(snmp_target_mib_test), 1550 try_test(snmp_notification_mib_test), 1551 1552 %% Stop the agent (without deleting the stored files) 1553 ?DBG("varm_mib_start -> stop the agent", []), 1554 stop_agent(Config3), 1555 ok. 1556 1557 1558-define(snmpTrapCommunity_instance, [1,3,6,1,6,3,18,1,4,0]). 1559-define(vacmViewSpinLock_instance, [1,3,6,1,6,3,16,1,5,1,0]). 1560-define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). 1561 1562ms_me_of(suite) -> []; 1563ms_me_of(Config) when is_list(Config) -> 1564 ?P(ms_me_of), 1565 init_case(Config), 1566 1567 ?line load_master("Test2"), 1568 ?line load_master("TestTrap"), 1569 ?line load_master("TestTrapv2"), 1570 ?line load_master_std("OTP-SNMPEA-MIB"), 1571 ?line load_master_std("SNMP-COMMUNITY-MIB"), 1572 ?line load_master_std("SNMP-FRAMEWORK-MIB"), 1573 ?line load_master_std("SNMP-MPD-MIB"), 1574 ?line load_master_std("SNMP-NOTIFICATION-MIB"), 1575 ?line load_master_std("SNMP-TARGET-MIB"), 1576 ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), 1577 1578 ?SLEEP(2000), 1579 1580 ?line display_memory_usage(), 1581 1582 1583 ?DBG("ms_me_of -> find ~w from SNMP-COMMUNITY-MIB", 1584 [?snmpTrapCommunity_instance]), 1585 ?line ok = me_of(?snmpTrapCommunity_instance), 1586 1587 ?DBG("ms_me_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", 1588 [?vacmViewSpinLock_instance]), 1589 ?line ok = me_of(?vacmViewSpinLock_instance), 1590 1591 ?DBG("ms_me_of -> find ~w from SNMP-USER-BASED-SM-MIB", 1592 [?usmStatsNotInTimeWindows_instance]), 1593 ?line {error, _} = me_of(?usmStatsNotInTimeWindows_instance), 1594 1595 1596 ?line unload_master("OTP-SNMPEA-MIB"), 1597 ?line unload_master("SNMP-COMMUNITY-MIB"), 1598 ?line unload_master("SNMP-FRAMEWORK-MIB"), 1599 ?line unload_master("SNMP-MPD-MIB"), 1600 ?line unload_master("SNMP-NOTIFICATION-MIB"), 1601 ?line unload_master("SNMP-TARGET-MIB"), 1602 ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), 1603 1604 ?line unload_master("TestTrapv2"), 1605 ?line unload_master("TestTrap"), 1606 ?line unload_master("Test2"), 1607 1608 ok. 1609 1610me_of(Oid) -> 1611 case snmpa:me_of(Oid) of 1612 {ok, #me{oid = Oid}} -> 1613 ok; 1614 {ok, #me{oid = OtherOid}} -> 1615 case lists:reverse(Oid) of 1616 [0|Rest] -> 1617 case lists:reverse(Rest) of 1618 OtherOid -> 1619 ok; 1620 AnotherOid -> 1621 {error, {invalid_oid, Oid, AnotherOid}} 1622 end; 1623 _ -> 1624 {error, {invalid_oid, Oid, OtherOid}} 1625 end; 1626 {error, Reason} -> 1627 {error, Reason}; 1628 Else -> 1629 {error, Else} 1630 end. 1631 1632 1633ms_mib_of(suite) -> []; 1634ms_mib_of(Config) when is_list(Config) -> 1635 ?P(ms_mib_of), 1636 init_case(Config), 1637 1638 ?line load_master("Test2"), 1639 ?line load_master("TestTrap"), 1640 ?line load_master("TestTrapv2"), 1641 ?line load_master_std("OTP-SNMPEA-MIB"), 1642 ?line load_master_std("SNMP-COMMUNITY-MIB"), 1643 ?line load_master_std("SNMP-FRAMEWORK-MIB"), 1644 ?line load_master_std("SNMP-MPD-MIB"), 1645 ?line load_master_std("SNMP-NOTIFICATION-MIB"), 1646 ?line load_master_std("SNMP-TARGET-MIB"), 1647 ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), 1648 1649 ?SLEEP(2000), 1650 1651 ?line display_memory_usage(), 1652 1653 1654 ?DBG("ms_mib_of -> find ~w from SNMP-COMMUNITY-MIB", 1655 [?snmpTrapCommunity_instance]), 1656 ?line ok = mib_of(?snmpTrapCommunity_instance, 'SNMP-COMMUNITY-MIB'), 1657 1658 ?DBG("ms_mib_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", 1659 [?vacmViewSpinLock_instance]), 1660 ?line ok = mib_of(?vacmViewSpinLock_instance, 'SNMP-VIEW-BASED-ACM-MIB'), 1661 1662 ?DBG("ms_mib_of -> find ~w from SNMP-USER-BASED-SM-MIB", 1663 [?usmStatsNotInTimeWindows_instance]), 1664 ?line {error, _} = mib_of(?usmStatsNotInTimeWindows_instance, 1665 'SNMP-USER-BASED-SM-MIB'), 1666 1667 1668 ?line unload_master("OTP-SNMPEA-MIB"), 1669 ?line unload_master("SNMP-COMMUNITY-MIB"), 1670 ?line unload_master("SNMP-FRAMEWORK-MIB"), 1671 ?line unload_master("SNMP-MPD-MIB"), 1672 ?line unload_master("SNMP-NOTIFICATION-MIB"), 1673 ?line unload_master("SNMP-TARGET-MIB"), 1674 ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), 1675 1676 ?line unload_master("TestTrapv2"), 1677 ?line unload_master("TestTrap"), 1678 ?line unload_master("Test2"), 1679 1680 ok. 1681 1682mib_of(Oid, ExpectedMibName) -> 1683 ?DBG("mib_of -> entry with" 1684 "~n Oid: ~p" 1685 "~n ExpectedMibName: ~p", [Oid, ExpectedMibName]), 1686 %% case snmpa:mib_of(Oid) of 1687 MibOf = snmpa:mib_of(Oid), 1688 ?DBG("mib_of -> MibOf: ~n~p", [MibOf]), 1689 case MibOf of 1690 {ok, ExpectedMibName} -> 1691 ok; 1692 {ok, OtherMibName} -> 1693 {error, {invalid_mib, ExpectedMibName, OtherMibName}}; 1694 {error, Reason} -> 1695 {error, Reason}; 1696 Else -> 1697 ?DBG("mib_of -> Else: ~n~p", [Else]), 1698 {error, Else} 1699 end. 1700 1701 1702 1703init_misc(Config) -> 1704 init_v1(Config). 1705 1706finish_misc(Config) -> 1707 finish_v1(Config). 1708 1709misc_cases() -> 1710 [ 1711 app_info, 1712 info_test, 1713 create_local_db_dir 1714 ]. 1715 1716app_info(suite) -> []; 1717app_info(Config) when is_list(Config) -> 1718 ?P(app_info), 1719 SnmpDir = app_dir(snmp), 1720 SslDir = app_dir(ssl), 1721 CryptoDir = app_dir(crypto), 1722 Attr = snmp:module_info(attributes), 1723 AppVsn = 1724 case lists:keysearch(app_vsn, 1, Attr) of 1725 {value, {app_vsn, V}} -> 1726 V; 1727 false -> 1728 "undefined" 1729 end, 1730 io:format("Root dir: ~ts~n" 1731 "SNMP: Application dir: ~ts~n" 1732 " Application ver: ~ts~n" 1733 "SSL: Application dir: ~ts~n" 1734 "CRYPTO: Application dir: ~ts~n", 1735 [code:root_dir(), SnmpDir, AppVsn, SslDir, CryptoDir]), 1736 ok. 1737 1738app_dir(App) -> 1739 case code:lib_dir(App) of 1740 D when is_list(D) -> 1741 filename:basename(D); 1742 {error, _Reason} -> 1743 "undefined" 1744 end. 1745 1746create_local_db_dir(Config) when is_list(Config) -> 1747 Pre = fun() -> 1748 DataDir = snmp_test_lib:lookup(data_dir, Config), 1749 T = {erlang:unique_integer([positive]), 1750 erlang:unique_integer([positive]), 1751 erlang:unique_integer([positive])}, 1752 [As,Bs,Cs] = [integer_to_list(I) || I <- tuple_to_list(T)], 1753 DbDir = filename:join([DataDir, As, Bs, Cs]), 1754 Name = list_to_atom(atom_to_list(create_local_db_dir) 1755 ++"_"++As++"_"++Bs++"_"++Cs), 1756 ?IPRINT("try ensuring db-dir does not exist"), 1757 try del_dir(DbDir, 3) of 1758 ok -> 1759 ok 1760 catch 1761 C:E:S -> 1762 ?WPRINT("Failed pre db-dir delete: " 1763 "~n Class: ~p" 1764 "~n Error: ~p" 1765 "~n Stack: ~p", [C, E, S]), 1766 throw({skip, "Failed pre db-dir cleanup"}) 1767 end, 1768 ?IPRINT("try start node ~p", [Name]), 1769 case ?ALIB:start_node(Name) of 1770 {ok, Node} -> 1771 {DbDir, Node}; 1772 {error, Reason} -> 1773 ?WPRINT("Failed starting node ~p:" 1774 "~n ~p", [Reason]), 1775 throw({skip, ?F("Failed starting node ~p", [Name])}) 1776 end 1777 end, 1778 Case = fun do_create_local_db_dir/1, 1779 Post = fun({DbDir, Node}) -> 1780 ?IPRINT("try stop node ~p", [Node]), 1781 ?ALIB:stop_node(Node), 1782 ?IPRINT("try delete db-dir"), 1783 try del_dir(DbDir, 3) 1784 catch 1785 C:E:S -> 1786 ?WPRINT("Failed post db-dir delete: " 1787 "~n DbDir ~s" 1788 "~n Class: ~p" 1789 "~n Error: ~p" 1790 "~n Stack: ~p", [DbDir, C, E, S]), 1791 ok 1792 end 1793 end, 1794 ?TC_TRY(create_local_db_dir, Pre, Case, Post). 1795 1796do_create_local_db_dir({DbDir, Node}) -> 1797 ?P(create_local_db_dir), 1798 %% first start with a nonexisting DbDir 1799 Fun1 = fun() -> 1800 false = filelib:is_dir(DbDir), 1801 process_flag(trap_exit,true), 1802 {error, {error, {failed_open_dets, {file_error, _, _}}}} = 1803 snmpa_local_db:start_link(normal, DbDir, 1804 [{verbosity, trace}]), 1805 false = filelib:is_dir(DbDir), 1806 {ok, not_found} 1807 end, 1808 {ok, not_found} = nodecall(Node, Fun1), 1809 %% now start with a nonexisting DbDir but pass the 1810 %% create_local_db_dir option as well 1811 Fun2 = fun() -> 1812 false = filelib:is_dir(DbDir), 1813 process_flag(trap_exit,true), 1814 {ok, _Pid} = 1815 snmpa_local_db:start_link(normal, DbDir, 1816 create_db_and_dir, [{verbosity,trace}]), 1817 snmpa_local_db:stop(), 1818 true = filelib:is_dir(DbDir), 1819 {ok, found} 1820 end, 1821 {ok, found} = nodecall(Node, Fun2), 1822 ok. 1823 1824nodecall(Node, Fun) -> 1825 Parent = self(), 1826 Ref = make_ref(), 1827 Pid = spawn_link(Node, 1828 fun() -> 1829 Res = Fun(), 1830 unlink(Parent), 1831 Parent ! {Ref, Res} 1832 end), 1833 receive 1834 %% Just so we are not left hanging 1835 {'EXIT', Pid, Reason} -> 1836 Reason; 1837 {Ref, Res} -> 1838 Res 1839 end. 1840 1841del_dir(_Dir, 0) -> 1842 ok; 1843del_dir(Dir, Depth) -> 1844 case filelib:is_dir(Dir) of 1845 true -> 1846 {ok, Files} = file:list_dir(Dir), 1847 lists:map(fun(F) -> 1848 Nm = filename:join(Dir,F), 1849 ok = file:delete(Nm) 1850 end, Files), 1851 ok = file:del_dir(Dir), 1852 del_dir(filename:dirname(Dir), Depth-1); 1853 false -> 1854 ok 1855 end. 1856 1857%v1_cases() -> [loop_mib_1]; 1858v1_cases() -> 1859 [ 1860 simple, 1861 db_notify_client, 1862 v1_processing, 1863 big, 1864 big2, 1865 loop_mib_1, 1866 api, 1867 subagent, 1868 mnesia, 1869 {group, multiple_reqs}, 1870 sa_register, 1871 v1_trap, 1872 sa_error, 1873 next_across_sa, 1874 undo, 1875 {group, reported_bugs}, 1876 {group, standard_mibs}, 1877 sparse_table, 1878 cnt_64, 1879 opaque, 1880 change_target_addr_config 1881 ]. 1882 1883v1_cases_ipv6() -> 1884 [ 1885 simple, 1886 v1_processing, 1887 loop_mib_1, 1888%% big, 1889%% big2, 1890 api, 1891 subagent, 1892%% mnesia, 1893%% {group, multiple_reqs}, 1894 sa_register, 1895%% v1_trap, % sends v1 trap 1896%% sa_error, 1897 next_across_sa, 1898 undo, 1899%% {group, reported_bugs}, 1900 {group, standard_mibs_ipv6}, 1901 sparse_table, 1902%% cnt_64, % sends v1 trap 1903 opaque 1904%% change_target_addr_config % sends v1 trap 1905 ]. 1906 1907init_v1(Config) when is_list(Config) -> 1908 ?line SaNode = ?config(snmp_sa, Config), 1909 ?line create_tables(SaNode), 1910 ?line AgentConfDir = ?config(agent_conf_dir, Config), 1911 ?line MgrDir = ?config(mgr_dir, Config), 1912 ?line Ip = ?config(ip, Config), 1913 ?line IpFamily = config_ipfamily(Config), 1914 ?line config( 1915 [v1], MgrDir, AgentConfDir, 1916 tuple_to_list(Ip), tuple_to_list(Ip), IpFamily), 1917 [{vsn, v1} | start_v1_agent(Config)]. 1918 1919finish_v1(Config) when is_list(Config) -> 1920 delete_tables(), 1921 C1 = stop_agent(Config), 1922 delete_files(C1), 1923 lists:keydelete(vsn, 1, C1). 1924 1925 1926v2_cases() -> 1927 [ 1928 simple_2, 1929 v2_processing, 1930 big_2, 1931 big2_2, 1932 loop_mib_2, 1933 api_2, 1934 subagent_2, 1935 mnesia_2, 1936 {group, multiple_reqs_2}, 1937 sa_register_2, 1938 v2_trap, 1939 {group, v2_inform}, 1940 sa_error_2, 1941 next_across_sa_2, 1942 undo_2, 1943 {group, reported_bugs_2}, 1944 {group, standard_mibs_2}, 1945 v2_types, 1946 implied, 1947 sparse_table_2, 1948 cnt_64_2, 1949 opaque_2, 1950 v2_caps 1951 ]. 1952 1953v2_cases_ipv6() -> 1954 [ 1955 simple_2, 1956 v2_processing, 1957%% big_2, 1958%% big2_2, 1959 loop_mib_2, 1960 api_2, 1961 subagent_2, 1962%% mnesia_2, 1963%% {group, multiple_reqs_2}, 1964 sa_register_2, 1965 v2_trap, 1966 {group, v2_inform}, 1967%% sa_error_2, 1968 next_across_sa_2, 1969 undo_2, 1970%% {group, reported_bugs_2}, 1971 {group, standard_mibs_2}, 1972 v2_types, 1973 implied, 1974 sparse_table_2, 1975 cnt_64_2, 1976 opaque_2, 1977 v2_caps 1978 ]. 1979 1980init_v2(Config) when is_list(Config) -> 1981 SaNode = ?config(snmp_sa, Config), 1982 create_tables(SaNode), 1983 AgentConfDir = ?config(agent_conf_dir, Config), 1984 MgrDir = ?config(mgr_dir, Config), 1985 Ip = ?config(ip, Config), 1986 IpFamily = config_ipfamily(Config), 1987 config( 1988 [v2], MgrDir, AgentConfDir, 1989 tuple_to_list(Ip), tuple_to_list(Ip), IpFamily), 1990 [{vsn, v2} | start_v2_agent(Config)]. 1991 1992finish_v2(Config) when is_list(Config) -> 1993 delete_tables(), 1994 C1 = stop_agent(Config), 1995 delete_files(C1), 1996 lists:keydelete(vsn, 1, C1). 1997 1998 1999v1_v2_cases() -> 2000 [simple_bi]. 2001 2002init_v1_v2(Config) when is_list(Config) -> 2003 SaNode = ?config(snmp_sa, Config), 2004 create_tables(SaNode), 2005 AgentConfDir = ?config(agent_conf_dir, Config), 2006 MgrDir = ?config(mgr_dir, Config), 2007 Ip = ?config(ip, Config), 2008 IpFamily = config_ipfamily(Config), 2009 config([v1,v2], MgrDir, AgentConfDir, 2010 tuple_to_list(Ip), tuple_to_list(Ip), IpFamily), 2011 [{vsn, bilingual} | start_bilingual_agent(Config)]. 2012 2013finish_v1_v2(Config) when is_list(Config) -> 2014 delete_tables(), 2015 C1 = stop_agent(Config), 2016 delete_files(C1), 2017 lists:keydelete(vsn, 1, C1). 2018 2019 2020v3_cases() -> 2021 [ 2022 simple_3, 2023 v3_processing, 2024 big_3, 2025 big2_3, 2026 api_3, 2027 subagent_3, 2028 mnesia_3, 2029 loop_mib_3, 2030 {group, multiple_reqs_3}, 2031 sa_register_3, 2032 v3_trap, 2033 {group, v3_inform}, 2034 sa_error_3, 2035 next_across_sa_3, 2036 undo_3, 2037 {group, reported_bugs_3}, 2038 {group, standard_mibs_3}, 2039 {group, v3_security}, 2040 v2_types_3, 2041 implied_3, 2042 sparse_table_3, 2043 cnt_64_3, 2044 opaque_3, 2045 v2_caps_3 2046 ]. 2047 2048v3_cases_ipv6() -> 2049 [ 2050 simple_3, 2051 v3_processing, 2052%% big_3, 2053%% big2_3, 2054 api_3, 2055 subagent_3, 2056%% mnesia_3, 2057 loop_mib_3, 2058%% {group, multiple_reqs_3}, 2059 sa_register_3, 2060 v3_trap, 2061 {group, v3_inform}, 2062%% sa_error_3, 2063 next_across_sa_3, 2064 undo_3, 2065%% {group, reported_bugs_3}, 2066 {group, standard_mibs_3}, 2067 {group, v3_security}, 2068 v2_types_3, 2069 implied_3, 2070 sparse_table_3, 2071 cnt_64_3, 2072 opaque_3, 2073 v2_caps_3 2074 ]. 2075 2076init_v3(Config) when is_list(Config) -> 2077 %% Make sure crypto works, otherwise start_agent will fail 2078 %% and we will be stuck with a bunch of mnesia tables for 2079 %% the rest of this suite... 2080 ?DBG("start_agent -> start crypto app",[]), 2081 case ?CRYPTO_START() of 2082 ok -> 2083 case ?CRYPTO_SUPPORT() of 2084 {no, Reason} -> 2085 ?WPRINT("crypto support not sufficient:" 2086 "~n ~p", [Reason]), 2087 ?SKIP({unsupported_encryption, Reason}); 2088 yes -> 2089 ?IPRINT("crypto started"), 2090 ok 2091 end; 2092 {error, Reason} -> 2093 ?IPRINT("crypto not started:" 2094 "~n ~p", [Reason]), 2095 ?SKIP({failed_starting_crypto, Reason}) 2096 end, 2097 SaNode = ?config(snmp_sa, Config), 2098 create_tables(SaNode), 2099 AgentConfDir = ?config(agent_conf_dir, Config), 2100 MgrDir = ?config(mgr_dir, Config), 2101 Ip = ?config(ip, Config), 2102 IpFamily = config_ipfamily(Config), 2103 ?line ok = 2104 config( 2105 [v3], MgrDir, AgentConfDir, 2106 tuple_to_list(Ip), tuple_to_list(Ip), IpFamily), 2107 Opts = 2108 [{master_agent_verbosity, trace}, 2109 {agent_verbosity, trace}, 2110 {net_if_verbosity, trace}], 2111 [{vsn, v3} | start_v3_agent(Config, Opts)]. 2112 2113finish_v3(Config) when is_list(Config) -> 2114 delete_tables(), 2115 C1 = stop_agent(Config), 2116 delete_files(C1), 2117 lists:keydelete(vsn, 1, C1). 2118 2119 2120mt_cases() -> 2121 [ 2122 multi_threaded, 2123 mt_trap 2124 ]. 2125 2126init_mt(Config, MT) when is_list(Config) -> 2127 SaNode = ?config(snmp_sa, Config), 2128 create_tables(SaNode), 2129 AgentConfDir = ?config(agent_conf_dir, Config), 2130 MgrDir = ?config(mgr_dir, Config), 2131 Ip = ?config(ip, Config), 2132 ?line ok = config([v2], MgrDir, AgentConfDir, 2133 tuple_to_list(Ip), tuple_to_list(Ip)), 2134 [{vsn, v2} | start_multi_threaded_agent(Config, MT)]. 2135 2136finish_mt(Config) when is_list(Config) -> 2137 delete_tables(), 2138 C1 = stop_agent(Config), 2139 delete_files(C1), 2140 lists:keydelete(vsn, 1, C1). 2141 2142%% This one *must* be run first in each case. 2143init_case(Config) -> 2144 ?ALIB:init_case(Config). 2145 2146 2147load_master(Mib) -> 2148 ?DBG("load_master -> entry with" 2149 "~n Mib: ~p", [Mib]), 2150 snmpa:unload_mib(snmp_master_agent, Mib), % Unload for safety 2151 ok = snmpa:load_mib(snmp_master_agent, join(get(mib_dir), Mib)). 2152 2153load_master_std(Mib) -> 2154 ?DBG("load_master_std -> entry with" 2155 "~n Mib: ~p", [Mib]), 2156 snmpa:unload_mib(snmp_master_agent, Mib), % Unload for safety 2157 ok = snmpa:load_mib(snmp_master_agent, join(get(std_mib_dir), Mib)). 2158 2159unload_master(Mib) -> 2160 ?DBG("unload_master -> entry with" 2161 "~n Mib: ~p", [Mib]), 2162 ok = snmpa:unload_mib(snmp_master_agent, Mib). 2163 2164loaded_mibs() -> 2165 ?DBG("loaded_mibs -> entry",[]), 2166 Info = snmpa:info(snmp_master_agent), 2167 {value, {mib_server, MibInfo}} = lists:keysearch(mib_server, 1, Info), 2168 {value, {loaded_mibs, Mibs}} = lists:keysearch(loaded_mibs, 1, MibInfo), 2169 [atom_to_list(Mib) || {Mib,_,_} <- Mibs]. 2170 2171unload_mibs(Mibs) -> 2172 ?DBG("unload_mibs -> entry with" 2173 "~n Mibs: ~p", [Mibs]), 2174 ok = snmpa:unload_mibs(snmp_master_agent, Mibs). 2175 2176start_subagent(SaNode, RegTree, Mib) -> 2177 ?ALIB:start_subagent(SaNode, RegTree, Mib). 2178 2179stop_subagent(SA) -> 2180 ?ALIB:stop_subagent(SA). 2181 2182 2183%%----------------------------------------------------------------- 2184%% This function takes care of the old OTP-SNMPEA-MIB. 2185%% Unfortunately, the testcases were written to use the data in the 2186%% internal tables, and these table are now obsolete and not used 2187%% by the agent. Therefore, we emulate them by using 2188%% OLD-SNMPEA-MIB, which uses the default impl. of all tables. 2189%% 2190%% These two rows must exist in intCommunityTable 2191%% {[147,214,36,45], "public", 2, readWrite}. 2192%% {[147,214,36,45], "standard trap", 2, read}. 2193%% (But with the manager's IP address) 2194%% 2195%%----------------------------------------------------------------- 2196init_old() -> 2197 snmpa_local_db:table_create_row(intCommunityTable, 2198 get(mip) ++ [6 | "public"], 2199 {get(mip), "public", 2, 2}), 2200 snmpa_local_db:table_create_row(intCommunityTable, 2201 get(mip) ++ [13 | "standard trap"], 2202 {get(mip), "standard trap", 2, 1}), 2203 snmpa_local_db:variable_set(intAgentIpAddress, [127,0,0,1]). 2204 2205 2206 2207simple(suite) -> []; 2208simple(Config) when is_list(Config) -> 2209 ?P(simple), 2210 init_case(Config), 2211 2212 try_test(simple_standard_test), 2213 2214 ?IPRINT("done"), 2215 ok. 2216 2217simple_2(X) -> ?P(simple_2), simple(X). 2218 2219simple_bi(suite) -> []; 2220simple_bi(Config) when is_list(Config) -> 2221 ?P(simple_bi), 2222 init_case(Config), 2223 2224 put(vsn, v1), % First, try v1 manager 2225 try_test(simple_standard_test), 2226 2227 put(vsn, v2), % Then, try v2 manager 2228 try_test(simple_standard_test). 2229 2230simple_3(X) -> 2231 ?P(simple_3), simple(X). 2232 2233big(suite) -> []; 2234big(Config) when is_list(Config) -> 2235 ?P(big), 2236 %% put(sname, {?MODULE, big}), 2237 %% put(verbosity, trace), 2238 2239 {SaNode, _MgrNode, _MibDir} = init_case(Config), 2240 2241 ?NPRINT("Starting subagent..."), 2242 ?line pong = net_adm:ping(SaNode), 2243 2244 ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), 2245 ?DBG("big -> SA: ~p", [SA]), 2246 ?line load_master("OLD-SNMPEA-MIB"), 2247 ?line init_old(), 2248 2249 snmpa:dump_mibs(), 2250 snmpa:dump_mibs("dumped_mibs.txt"), 2251 io:format("Local DB: ~n~p~n", [snmpa_local_db:print()]), 2252 2253 try_test(big_test), 2254 2255 ?line stop_subagent(SA), 2256 ?line unload_master("OLD-SNMPEA-MIB"). 2257 2258big_2(X) -> ?P(big_2), big(X). 2259 2260big_3(X) -> ?P(big_3), big(X). 2261 2262 2263big2(suite) -> []; 2264big2(Config) when is_list(Config) -> 2265 ?P(big2), 2266 %% This is exactly the same tests as 'big', but with the 2267 %% v2 equivalent of the mibs. 2268 {SaNode, _MgrNode, _MibDir} = init_case(Config), 2269 2270 ?NPRINT("Starting subagent..."), 2271 ?line pong = net_adm:ping(SaNode), 2272 2273 ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1-v2"), 2274 ?line load_master("OLD-SNMPEA-MIB-v2"), 2275 ?line init_old(), 2276 try_test(big_test), 2277 ?line stop_subagent(SA), 2278 ?line unload_master("OLD-SNMPEA-MIB-v2"). 2279 2280big2_2(X) -> ?P(big2_2), big2(X). 2281 2282big2_3(X) -> ?P(big2_3), big2(X). 2283 2284 2285multi_threaded(suite) -> []; 2286multi_threaded(Config) when is_list(Config) -> 2287 ?P(multi_threaded), 2288 init_case(Config), 2289 2290 ?line load_master("Test1"), 2291 try_test(multi_threaded_test), 2292 ?line unload_master("Test1"). 2293 2294mt_trap(suite) -> []; 2295mt_trap(Config) when is_list(Config) -> 2296 ?P(mt_trap), 2297 init_case(Config), 2298 MA = whereis(snmp_master_agent), 2299 MT = ?config(multi_threaded, Config), 2300 2301 ?line load_master("Test1"), 2302 ?line load_master("TestTrapv2"), 2303 try_test(mt_trap_test, [MA, MT]), 2304 ?line unload_master("TestTrapv2"), 2305 ?line unload_master("Test1"), 2306 ok. 2307 2308v2_types(suite) -> []; 2309v2_types(Config) when is_list(Config) -> 2310 ?P(v2_types), 2311 init_case(Config), 2312 2313 ?line load_master("Test1"), 2314 try_test(types_v2_test), 2315 ?line unload_master("Test1"). 2316 2317v2_types_3(X) -> ?P(v2_types_3), v2_types(X). 2318 2319 2320implied(suite) -> []; 2321implied(Config) when is_list(Config) -> 2322 ?P(implied), 2323 init_case(Config), 2324 MA = whereis(snmp_master_agent), 2325 2326 ?line load_master("Test1"), 2327 try_test(implied_test,[MA]), 2328 ?line unload_master("Test1"). 2329 2330implied_3(X) -> ?P(implied_3), implied(X). 2331 2332 2333sparse_table(suite) -> []; 2334sparse_table(Config) when is_list(Config) -> 2335 ?P(sparse_table), 2336 init_case(Config), 2337 2338 ?line load_master("Test1"), 2339 try_test(sparse_table_test), 2340 ?line unload_master("Test1"). 2341 2342sparse_table_2(X) -> ?P(sparse_table_2), sparse_table(X). 2343 2344sparse_table_3(X) -> ?P(sparse_table_3), sparse_table(X). 2345 2346cnt_64(suite) -> []; 2347cnt_64(Config) when is_list(Config) -> 2348 ?P(cnt_64), 2349 init_case(Config), 2350 MA = whereis(snmp_master_agent), 2351 2352 ?line load_master("Test1"), 2353 try_test(cnt_64_test, [MA]), 2354 ?line unload_master("Test1"). 2355 2356cnt_64_2(X) -> ?P(cnt_64_2), cnt_64(X). 2357 2358cnt_64_3(X) -> ?P(cnt_64_3), cnt_64(X). 2359 2360opaque(suite) -> []; 2361opaque(Config) when is_list(Config) -> 2362 ?P(opaque), 2363 init_case(Config), 2364 2365 ?line load_master("Test1"), 2366 try_test(opaque_test), 2367 ?line unload_master("Test1"). 2368 2369opaque_2(X) -> ?P(opaque_2), opaque(X). 2370 2371opaque_3(X) -> ?P(opaque_2), opaque(X). 2372 2373 2374change_target_addr_config(suite) -> []; 2375change_target_addr_config(Config) when is_list(Config) -> 2376 ?P(change_target_addr_config), 2377 ?IPRINT("change_target_addr_config -> entry"), 2378 init_case(Config), 2379 2380 put(sname,snmp_suite), 2381 put(verbosity,trace), 2382 2383 MA = whereis(snmp_master_agent), 2384 2385 ?IPRINT("change_target_addr_config -> load TestTrap"), 2386 ?line load_master("TestTrap"), 2387 2388 ?IPRINT("change_target_addr_config -> set trace verbosity for local_db"), 2389 ?line snmpa:verbosity(local_db,trace), 2390 2391 %% First send some traps that will arive att the original manager 2392 ?IPRINT("change_target_addr_config -> send trap"), 2393 try_test(ma_trap1, [MA]), 2394 2395 ?IPRINT("change_target_addr_config -> set silence verbosity for local_db"), 2396 ?line snmpa:verbosity(local_db, silence), 2397 2398 %% Start new dummy listener 2399 ?IPRINT("change_target_addr_config -> start dummy manager"), 2400 ?line {ok,Pid,NewPort} = dummy_manager_start(MA), 2401 2402 %% Reconfigure 2403 ?IPRINT("change_target_addr_config -> reconfigure"), 2404 AgentConfDir = ?config(agent_conf_dir, Config), 2405 ?line rewrite_target_addr_conf(AgentConfDir, NewPort), 2406 ?line snmp_target_mib:reconfigure(AgentConfDir), 2407 2408 %% Send the trap again 2409 ?IPRINT("change_target_addr_config -> send trap again"), 2410 catch dummy_manager_send_trap2(Pid), 2411 2412 ?IPRINT("change_target_addr_config -> await trap ack"), 2413 catch dummy_manager_await_trap2_ack(), 2414 2415 ?IPRINT("change_target_addr_config -> stop dummy manager"), 2416 ?line ok = dummy_manager_stop(Pid), 2417 2418 ?IPRINT("change_target_addr_config -> reset target address config"), 2419 ?line reset_target_addr_conf(AgentConfDir), 2420 2421 ?IPRINT("change_target_addr_config -> unload TestTrap"), 2422 ?line unload_master("TestTrap"). 2423 2424 2425dummy_manager_start(MA) -> 2426 ?DBG("dummy_manager_start -> entry",[]), 2427 Pid = spawn(get(mgr_node), ?MODULE, dummy_manager_init, [self(), MA]), 2428 ?DBG("dummy_manager_start -> Pid: ~p",[Pid]), 2429 await_dummy_manager_started(Pid). 2430 2431await_dummy_manager_started(Pid) -> 2432 receive 2433 {dummy_manager_started,Pid,Port} -> 2434 ?DBG("dummy_manager_start -> acknowledge received with" 2435 "~n Port: ~p",[Port]), 2436 {ok,Pid,Port}; 2437 2438 {'EXIT', Pid, Reason} -> 2439 ?EPRINT("dummy manager terminated: " 2440 "~n ~p", [Reason]), 2441 {error, Pid, Reason}; 2442 2443 _O -> 2444 ?NPRINT("dummy_manager_start -> received unknown message:" 2445 "~n ~p", [_O]), 2446 await_dummy_manager_started(Pid) 2447 end. 2448 2449dummy_manager_stop(Pid) -> 2450 ?DBG("dummy_manager_stop -> entry with Pid: ~p",[Pid]), 2451 Pid ! stop, 2452 receive 2453 {dummy_manager_stopping, Pid} -> 2454 ?DBG("dummy_manager_stop -> acknowledge received",[]), 2455 ok 2456 after 10000 -> 2457 ?EPRINT("dummy_manager_stop -> timeout"), 2458 timeout 2459 end. 2460 2461dummy_manager_send_trap2(Pid) -> 2462 ?DBG("dummy_manager_send_trap2 -> entry",[]), 2463 Pid ! {send_trap,testTrap2}. 2464 2465dummy_manager_await_trap2_ack() -> 2466 ?DBG("dummy_manager_await_trap2 -> entry",[]), 2467 receive 2468 {received_trap, _Trap} -> 2469 ?IPRINT("dummy_manager_await_trap2 -> received trap: ~p", [_Trap]), 2470 %% Note: 2471 %% Without this sleep the v2_inform_i testcase failes! There 2472 %% is no relation between these two test cases as far as I 2473 %% able to figure out... 2474 ?SLEEP(60000), 2475 ok; 2476 _O -> 2477 ?WPRINT("dummy_manager_await_trap2 -> unexpected message: ~p",[_O]), 2478 ok 2479 after 10000 -> 2480 ?EPRINT("dummy_manager_await_trap2 -> timeout",[]), 2481 timeout 2482 end. 2483 2484dummy_manager_init(Parent,MA) -> 2485 ?DBG("dummy_manager_init -> entry with" 2486 "~n Parent: ~p" 2487 "~n MA: ~p",[Parent,MA]), 2488 {ok,S} = gen_udp:open(0,[{recbuf,65535}]), 2489 ?DBG("dummy_manager_init -> S: ~p",[S]), 2490 {ok,Port} = inet:port(S), 2491 ?DBG("dummy_manager_init -> Port: ~p",[Port]), 2492 Parent ! {dummy_manager_started,self(),Port}, 2493 dummy_manager_loop(Parent,S,MA). 2494 2495dummy_manager_loop(P,S,MA) -> 2496 ?IPRINT("dummy_manager_loop -> ready for receive"), 2497 receive 2498 {send_trap,Trap} -> 2499 ?IPRINT("dummy_manager_loop -> received trap send request" 2500 "~n Trap: ~p", [Trap]), 2501 snmpa:send_trap(MA, Trap, "standard trap"), 2502 dummy_manager_loop(P,S,MA); 2503 {udp, _UdpId, _Ip, _UdpPort, Bytes} -> 2504 ?IPRINT("dummy_manager_loop -> received upd message" 2505 "~n from: ~p:~p" 2506 "~n size: ~p", 2507 [_Ip, _UdpPort, dummy_manager_message_sz(Bytes)]), 2508 R = dummy_manager_handle_message(Bytes), 2509 ?DBG("dummy_manager_loop -> R: ~p", [R]), 2510 P ! R, 2511 dummy_manager_loop(P, S, MA); 2512 stop -> 2513 ?DBG("dummy_manager_loop -> received stop request",[]), 2514 P ! {dummy_manager_stopping, self()}, 2515 gen_udp:close(S), 2516 exit(normal); 2517 _O -> 2518 ?WPRINT("dummy_manager_loop -> received unknown message:" 2519 "~n ~p", [_O]), 2520 dummy_manager_loop(P, S, MA) 2521 end. 2522 2523%% -ifdef(snmp_log). 2524dummy_manager_message_sz(B) when is_binary(B) -> 2525 size(B); 2526dummy_manager_message_sz(L) when is_list(L) -> 2527 length(L); 2528dummy_manager_message_sz(_) -> 2529 undefined. 2530%% -endif. 2531 2532dummy_manager_handle_message(Bytes) -> 2533 case (catch snmp_pdus:dec_message(Bytes)) of 2534 {'EXIT',Reason} -> 2535 ?EPRINT("dummy_manager_handle_message -> " 2536 "failed decoding message only:" 2537 "~n ~p", [Reason]), 2538 {error, Reason}; 2539 M -> 2540 ?DBG("dummy_manager_handle_message -> decoded message:" 2541 "~n ~p", [M]), 2542 {received_trap, M} 2543 end. 2544 2545 2546api(suite) -> []; 2547api(Config) when is_list(Config) -> 2548 ?P(api), 2549 init_case(Config), 2550 2551 ?line load_master("OLD-SNMPEA-MIB"), 2552 ?line init_old(), 2553 try_test(api_test, [node()]), 2554 ?line unload_master("OLD-SNMPEA-MIB"). 2555 2556api_2(X) -> ?P(api_2), api(X). 2557 2558api_3(X) -> ?P(api_3), api(X). 2559 2560 2561subagent(suite) -> []; 2562subagent(Config) when is_list(Config) -> 2563 ?P(subagent), 2564 {SaNode, _MgrNode, MibDir} = init_case(Config), 2565 2566 ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), 2567 try_test(load_test_sa), 2568 2569 ?NPRINT("Testing unregister subagent..."), 2570 MA = whereis(snmp_master_agent), 2571 rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), 2572 try_test(unreg_test), 2573 2574 ?NPRINT("Loading previous subagent mib in master and testing..."), 2575 ?line ok = snmpa:load_mib(MA, join(MibDir, "Klas1")), 2576 try_test(load_test), 2577 2578 ?NPRINT("Unloading previous subagent mib in master and testing..."), 2579 ?line ok = snmpa:unload_mib(MA, join(MibDir, "Klas1")), 2580 try_test(unreg_test), 2581 2582 ?NPRINT("Testing register subagent..."), 2583 rpc:call(SaNode, snmp, register_subagent, 2584 [MA, ?klas1, SA]), 2585 try_test(load_test_sa), 2586 2587 ?line stop_subagent(SA), 2588 try_test(unreg_test). 2589 2590subagent_2(X) -> ?P(subagent_2), subagent(X). 2591 2592subagent_3(X) -> 2593 %% <CONDITIONAL-SKIP> 2594 Skippable = [{unix, [darwin]}], 2595 Condition = fun() -> ?OS_BASED_SKIP(Skippable) end, 2596 ?NON_PC_TC_MAYBE_SKIP(X, Condition), 2597 %% </CONDITIONAL-SKIP> 2598 2599 ?P(subagent_3), 2600 subagent(X). 2601 2602 2603mnesia(suite) -> []; 2604mnesia(Config) when is_list(Config) -> 2605 ?P(mnesia), 2606 {SaNode, _MgrNode, _MibDir} = init_case(Config), 2607 2608 ?NPRINT("Starting subagent with mnesia impl..."), 2609 {ok, SA} = start_subagent(SaNode, ?klas2, "Klas2"), 2610 ?line load_master("OLD-SNMPEA-MIB"), 2611 ?line init_old(), 2612 2613 try_test(big_test_2), 2614 2615 ?NPRINT("Testing unregister subagent..."), 2616 MA = whereis(snmp_master_agent), 2617 rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), 2618 try_test(unreg_test), 2619 ?line unload_master("OLD-SNMPEA-MIB"), 2620 ?line stop_subagent(SA). 2621 2622mnesia_2(X) -> ?P(mnesia_2), mnesia(X). 2623 2624mnesia_3(X) -> ?P(mnesia_3), mnesia(X). 2625 2626 2627mul_cases() -> 2628 [ 2629 mul_get, 2630 mul_get_err, 2631 mul_next, 2632 mul_next_err, 2633 mul_set, 2634 mul_set_err 2635 ]. 2636 2637 2638mul_cases_2() -> 2639 [ 2640 mul_get_2, 2641 mul_get_err_2, 2642 mul_next_2, 2643 mul_next_err_2, 2644 mul_set_2, 2645 mul_set_err_2 2646 ]. 2647 2648 2649mul_cases_3() -> 2650 [ 2651 mul_get_3, 2652 mul_get_err_3, 2653 mul_next_3, 2654 mul_next_err_3, 2655 mul_set_3, 2656 mul_set_err_3 2657 ]. 2658 2659 2660init_mul(Config) when is_list(Config) -> 2661 {SaNode, _MgrNode, _MibDir} = init_case(Config), 2662 2663 ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), 2664 ?line load_master("OLD-SNMPEA-MIB"), 2665 ?line init_old(), 2666 [{mul_sub, SA} | Config]. 2667 2668finish_mul(Config) when is_list(Config) -> 2669 init_case(Config), 2670 2671 SA = ?config(mul_sub, Config), 2672 2673 ?line unload_master("OLD-SNMPEA-MIB"), 2674 ?line stop_subagent(SA), 2675 lists:keydelete(mul_sub, 1, Config). 2676 2677mul_get(suite) -> []; 2678mul_get(Config) when is_list(Config) -> 2679 ?P(mul_get), 2680 init_case(Config), 2681 2682 ?NPRINT("Testing multiple get..."), 2683 try_test(do_mul_get). 2684 2685mul_get_2(X) -> ?P(mul_get_2), mul_get(X). 2686 2687mul_get_3(X) -> ?P(mul_get_3), mul_get(X). 2688 2689 2690mul_get_err(suite) -> []; 2691mul_get_err(Config) when is_list(Config) -> 2692 ?P(mul_get_err), 2693 init_case(Config), 2694 2695 ?NPRINT("Testing multiple get with error..."), 2696 try_test(do_mul_get_err). 2697 2698mul_get_err_2(X) -> ?P(mul_get_err_2), mul_get_err(X). 2699 2700mul_get_err_3(X) -> ?P(mul_get_err_3), mul_get_err(X). 2701 2702 2703mul_next(suite) -> []; 2704mul_next(Config) when is_list(Config) -> 2705 ?P(mul_next), 2706 init_case(Config), 2707 2708 ?NPRINT("Testing multiple next..."), 2709 try_test(do_mul_next). 2710 2711mul_next_2(X) -> ?P(mul_next_2), mul_next(X). 2712 2713mul_next_3(X) -> ?P(mul_next_3), mul_next(X). 2714 2715 2716mul_next_err(suite) -> []; 2717mul_next_err(Config) when is_list(Config) -> 2718 ?P(mul_next_err), 2719 init_case(Config), 2720 2721 ?NPRINT("Testing multiple next..."), 2722 try_test(do_mul_next_err). 2723 2724mul_next_err_2(X) -> ?P(mul_next_err_2), mul_next_err(X). 2725 2726mul_next_err_3(X) -> ?P(mul_next_err_3), mul_next_err(X). 2727 2728 2729mul_set(suite) -> []; 2730mul_set(Config) when is_list(Config) -> 2731 ?P(mul_set), 2732 init_case(Config), 2733 2734 ?NPRINT("Testing multiple set..."), 2735 try_test(do_mul_set). 2736 2737mul_set_2(X) -> ?P(mul_set_2), mul_set(X). 2738 2739mul_set_3(X) -> ?P(mul_set_3), mul_set(X). 2740 2741 2742mul_set_err(suite) -> []; 2743mul_set_err(Config) when is_list(Config) -> 2744 ?P(mul_set_err), 2745 init_case(Config), 2746 2747 ?NPRINT("Testing multiple set with error..."), 2748 try_test(do_mul_set_err). 2749 2750mul_set_err_2(X) -> ?P(mul_set_err_2), mul_set_err(X). 2751 2752mul_set_err_3(X) -> ?P(mul_set_err_3), mul_set_err(X). 2753 2754 2755sa_register(suite) -> []; 2756sa_register(Config) when is_list(Config) -> 2757 ?P(sa_register), 2758 {SaNode, _MgrNode, MibDir} = init_case(Config), 2759 2760 ?DBG("sa_register -> start subagent", []), 2761 ?NPRINT("start subagent..."), 2762 ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), 2763 2764 ?DBG("sa_register -> unregister subagent", []), 2765 ?NPRINT("Testing unregister subagent (2)..."), 2766 MA = whereis(snmp_master_agent), 2767 rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), 2768 try_test(unreg_test), 2769 2770 ?NPRINT("Unloading Klas1..."), 2771 ?DBG("sa_register -> unload mibs", []), 2772 snmpa:unload_mib(SA, join(MibDir, "Klas1")), 2773 2774 ?NPRINT("Loading SA-MIB..."), 2775 ?DBG("sa_register -> unload mibs", []), 2776 snmpa:load_mib(SA, join(MibDir, "SA-MIB")), 2777 2778 ?NPRINT("register subagent..."), 2779 ?DBG("sa_register -> register subagent", []), 2780 rpc:call(SaNode, snmp, register_subagent, [MA, ?sa, SA]), 2781 2782 try_test(sa_mib), 2783 2784 ?NPRINT("stop subagent..."), 2785 ?DBG("sa_register -> stop subagent", []), 2786 ?line stop_subagent(SA). 2787 2788sa_register_2(X) -> ?P(sa_register_2), sa_register(X). 2789 2790sa_register_3(X) -> ?P(sa_register_3), sa_register(X). 2791 2792 2793v1_trap(suite) -> []; 2794v1_trap(Config) when is_list(Config) -> 2795 ?P(v1_trap), 2796 trap1(Config). 2797 2798trap1(Config) -> 2799 {SaNode, _MgrNode, _MibDir} = init_case(Config), 2800 2801 ?NPRINT("start subagent..."), 2802 ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), 2803 2804 ?NPRINT("Testing trap sending from master agent..."), 2805 MA = whereis(snmp_master_agent), 2806 2807 ?NPRINT("load TestTrap & TestTrapv2..."), 2808 ?line load_master("TestTrap"), 2809 ?line load_master("TestTrapv2"), 2810 2811 ?NPRINT("Testing trap sending from master-agent..."), 2812 try_test(ma_trap1, [MA]), 2813 try_test(ma_trap2, [MA]), 2814 try_test(ma_v2_2_v1_trap, [MA]), 2815 try_test(ma_v2_2_v1_trap2, [MA]), 2816 2817 ?NPRINT("Testing trap sending from subagent..."), 2818 try_test(sa_trap1, [SA]), 2819 try_test(sa_trap2, [SA]), 2820 try_test(sa_trap3, [SA]), 2821 2822 ?NPRINT("unload TestTrap & TestTrapv2..."), 2823 ?line unload_master("TestTrap"), 2824 ?line unload_master("TestTrapv2"), 2825 2826 ?NPRINT("stop subagent..."), 2827 ?line stop_subagent(SA). 2828 2829v2_trap(suite) -> []; 2830v2_trap(Config) when is_list(Config) -> 2831 ?P(v2_trap), 2832 trap2(Config). 2833 2834trap2(Config) -> 2835 {SaNode, _MgrNode, _MibDir} = init_case(Config), 2836 2837 ?NPRINT("start subagent..."), 2838 ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), 2839 2840 ?NPRINT("Testing trap sending from master agent..."), 2841 MA = whereis(snmp_master_agent), 2842 2843 ?NPRINT("load TestTrap & TestTrapv2..."), 2844 ?line load_master("TestTrap"), 2845 ?line load_master("TestTrapv2"), 2846 2847 ?NPRINT("Testing trap sending from master-agent..."), 2848 try_test(ma_v2_trap1, [MA]), 2849 try_test(ma_v2_trap2, [MA]), 2850 try_test(ma_v1_2_v2_trap, [MA]), 2851 try_test(ma_v1_2_v2_trap2, [MA]), 2852 2853 try_test(sa_mib), 2854 2855 ?NPRINT("Testing trap sending from subagent..."), 2856 try_test(sa_v1_2_v2_trap1, [SA]), 2857 try_test(sa_v1_2_v2_trap2, [SA]), 2858 try_test(sa_v1_2_v2_trap3, [SA]), 2859 2860 ?NPRINT("unload TestTrap & TestTrapv2..."), 2861 ?line unload_master("TestTrap"), 2862 ?line unload_master("TestTrapv2"), 2863 2864 ?NPRINT("stop subagent..."), 2865 ?line stop_subagent(SA). 2866 2867v3_trap(suite) -> []; 2868v3_trap(Config) when is_list(Config) -> 2869 %% <CONDITIONAL-SKIP> 2870 Skippable = [{unix, [darwin]}], 2871 Condition = fun() -> ?OS_BASED_SKIP(Skippable) end, 2872 ?NON_PC_TC_MAYBE_SKIP(Config, Condition), 2873 %% </CONDITIONAL-SKIP> 2874 2875 ?P(v3_trap), 2876 trap2(Config). 2877 2878 2879v3_inform_cases() -> 2880 [ 2881 v3_inform_i 2882 ]. 2883 2884init_v3_inform(X) -> 2885 init_v2_inform(X). 2886 2887finish_v3_inform(X) -> 2888 finish_v2_inform(X). 2889 2890 2891init_v2_inform(Config) when is_list(Config) -> 2892 _Dir = ?config(agent_conf_dir, Config), 2893 %% snmp_internal_mib:configure(Dir), 2894 Config. 2895 2896finish_v2_inform(Config) when is_list(Config) -> 2897 _Dir = ?config(agent_conf_dir, Config), 2898 %% snmp_internal_mib:configure(Dir), 2899 Config. 2900 2901v2_inform_cases() -> 2902 [ 2903 v2_inform_i 2904 ]. 2905 2906v2_inform_i(suite) -> []; 2907v2_inform_i(Config) when is_list(Config) -> 2908 ?P(v2_inform_i), 2909 inform_i(Config). 2910 2911inform_i(Config) -> 2912 init_case(Config), 2913 2914 MA = whereis(snmp_master_agent), 2915 2916 ?NPRINT("load TestTrap & TestTrapv2..."), 2917 ?line load_master("TestTrap"), 2918 ?line load_master("TestTrapv2"), 2919 2920 ?NPRINT("Testing inform sending from master agent... " 2921 "~nNOTE! This test takes a few minutes (10) to complete."), 2922 2923 try_test(ma_v2_inform1, [MA]), 2924 try_test(ma_v2_inform2, [MA]), 2925 try_test(ma_v2_inform3, [MA]), 2926 2927 ?NPRINT("unload TestTrap & TestTrapv2..."), 2928 ?line unload_master("TestTrap"), 2929 ?line unload_master("TestTrapv2"), 2930 ok. 2931 2932v3_inform_i(X) -> 2933 %% <CONDITIONAL-SKIP> 2934 Skippable = [{unix, [darwin]}], 2935 Condition = fun() -> ?OS_BASED_SKIP(Skippable) end, 2936 ?NON_PC_TC_MAYBE_SKIP(X, Condition), 2937 %% </CONDITIONAL-SKIP> 2938 2939 ?P(v3_inform_i), 2940 inform_i(X). 2941 2942 2943sa_error(suite) -> []; 2944sa_error(Config) when is_list(Config) -> 2945 ?P(sa_error), 2946 {SaNode, _MgrNode, _MibDir} = init_case(Config), 2947 2948 ?NPRINT("load OLD-SNMPEA-MIB..."), 2949 ?line load_master("OLD-SNMPEA-MIB"), 2950 ?line init_old(), 2951 2952 ?NPRINT("start subagent..."), 2953 ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), 2954 2955 ?NPRINT("Testing sa bad value (is_set_ok)..."), 2956 try_test(sa_errs_bad_value), 2957 2958 ?NPRINT("Testing sa gen err (set)..."), 2959 try_test(sa_errs_gen_err), 2960 2961 ?NPRINT("Testing too big..."), 2962 try_test(sa_too_big), 2963 2964 ?NPRINT("unload OLD-SNMPEA-MIB..."), 2965 ?line unload_master("OLD-SNMPEA-MIB"), 2966 2967 ?NPRINT("stop subagent..."), 2968 stop_subagent(SA). 2969 2970sa_error_2(X) -> 2971 ?P(sa_error_2), 2972 sa_error(X). 2973 2974sa_error_3(X) -> 2975 %% <CONDITIONAL-SKIP> 2976 Skippable = [{unix, [darwin]}], 2977 Condition = fun() -> ?OS_BASED_SKIP(Skippable) end, 2978 ?NON_PC_TC_MAYBE_SKIP(X, Condition), 2979 %% </CONDITIONAL-SKIP> 2980 2981 ?P(sa_error_3), 2982 sa_error(X). 2983 2984 2985next_across_sa(suite) -> []; 2986next_across_sa(Config) when is_list(Config) -> 2987 ?P(next_across_sa), 2988 {SaNode, _MgrNode, MibDir} = init_case(Config), 2989 MA = whereis(snmp_master_agent), 2990 2991 ?NPRINT("start subagent (1)..."), 2992 ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), 2993 2994 ?NPRINT("Loading another subagent mib (Klas1)..."), 2995 ?line ok = snmpa:load_mib(SA, MibDir ++ "Klas1"), 2996 2997 ?NPRINT("register subagent..."), 2998 rpc:call(SaNode, snmp, register_subagent, [MA, ?klas1, SA]), 2999 3000 ?NPRINT("Load test subagent..."), 3001 try_test(load_test_sa), 3002 3003 ?NPRINT("Testing next across subagent (endOfMibView from SA)..."), 3004 try_test(next_across_sa_test), 3005 3006 ?NPRINT("Unloading mib (Klas1)"), 3007 snmpa:unload_mib(SA, join(MibDir, "Klas1")), 3008 rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), 3009 try_test(unreg_test), 3010 3011 ?NPRINT("Starting another subagent (2) "), 3012 ?line {ok, SA2} = start_subagent(SaNode, ?klas1, "Klas1"), 3013 ?NPRINT("Testing next across subagent (wrong prefix from SA)..."), 3014 try_test(next_across_sa_test), 3015 3016 ?NPRINT("stop subagent (1)..."), 3017 stop_subagent(SA), 3018 3019 ?NPRINT("stop subagent (2)..."), 3020 stop_subagent(SA2). 3021 3022next_across_sa_2(X) -> 3023 ?P(next_across_sa_2), 3024 next_across_sa(X). 3025 3026next_across_sa_3(X) -> 3027 %% <CONDITIONAL-SKIP> 3028 Skippable = [{unix, [darwin]}], 3029 Condition = fun() -> ?OS_BASED_SKIP(Skippable) end, 3030 ?NON_PC_TC_MAYBE_SKIP(X, Condition), 3031 %% </CONDITIONAL-SKIP> 3032 3033 ?P(next_across_sa_3), 3034 next_across_sa(X). 3035 3036 3037undo(suite) -> []; 3038undo(Config) when is_list(Config) -> 3039 ?P(undo), 3040 {SaNode, _MgrNode, MibDir} = init_case(Config), 3041 3042 MA = whereis(snmp_master_agent), 3043 3044 ?NPRINT("start subagent (1)..."), 3045 ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), 3046 3047 ?NPRINT("Load Klas3 & Klas4..."), 3048 ?line ok = snmpa:load_mib(MA, join(MibDir, "Klas3")), 3049 ?line ok = snmpa:load_mib(MA, join(MibDir, "Klas4")), 3050 3051 ?NPRINT("Testing undo phase at master agent..."), 3052 try_test(undo_test), 3053 try_test(api_test2), 3054 3055 ?NPRINT("Unload Klas3..."), 3056 ?line ok = snmpa:unload_mib(MA, join(MibDir, "Klas3")), 3057 3058 ?NPRINT("Testing bad return values from instrum. funcs..."), 3059 try_test(bad_return), 3060 3061 ?NPRINT("Unload Klas4..."), 3062 ?line ok = snmpa:unload_mib(MA, join(MibDir, "Klas4")), 3063 3064 ?NPRINT("Testing undo phase at subagent..."), 3065 ?line ok = snmpa:load_mib(SA, join(MibDir, "Klas3")), 3066 ?line ok = snmpa:load_mib(SA, join(MibDir, "Klas4")), 3067 ?line ok = snmpa:register_subagent(MA, ?klas3, SA), 3068 ?line ok = snmpa:register_subagent(MA, ?klas4, SA), 3069 try_test(undo_test), 3070 try_test(api_test3), 3071 3072 ?NPRINT("Testing undo phase across master/subagents..."), 3073 try_test(undo_test), 3074 try_test(api_test3), 3075 3076 ?NPRINT("stop subagent..."), 3077 stop_subagent(SA). 3078 3079undo_2(X) -> 3080 ?P(undo_2), 3081 undo(X). 3082 3083undo_3(X) -> 3084 %% <CONDITIONAL-SKIP> 3085 Skippable = [{unix, [darwin]}], 3086 Condition = fun() -> ?OS_BASED_SKIP(Skippable) end, 3087 ?NON_PC_TC_MAYBE_SKIP(X, Condition), 3088 %% </CONDITIONAL-SKIP> 3089 3090 ?P(undo_3), 3091 undo(X). 3092 3093%% Req. Test2 3094v1_processing(suite) -> []; 3095v1_processing(Config) when is_list(Config) -> 3096 ?P(v1_processing), 3097 ?DBG("v1_processing -> entry", []), 3098 init_case(Config), 3099 3100 ?NPRINT("Load Test2..."), 3101 ?line load_master("Test2"), 3102 3103 try_test(v1_proc), 3104 3105 ?NPRINT("Unload Test2..."), 3106 ?line unload_master("Test2"). 3107 3108%% Req. Test2 3109v2_processing(suite) -> []; 3110v2_processing(Config) when is_list(Config) -> 3111 ?P(v2_processing), 3112 init_case(Config), 3113 3114 ?NPRINT("Load Test2..."), 3115 ?line load_master("Test2"), 3116 3117 try_test(v2_proc), 3118 3119 ?NPRINT("Unload Test2..."), 3120 ?line unload_master("Test2"). 3121 3122%% Req. Test2 3123v3_processing(suite) -> []; 3124v3_processing(Config) when is_list(Config) -> 3125 ?P(v3_processing), 3126 init_case(Config), 3127 3128 ?NPRINT("Load Test2..."), 3129 ?line load_master("Test2"), 3130 3131 try_test(v2_proc), % same as v2! 3132 3133 ?NPRINT("Unload Test2..."), 3134 ?line unload_master("Test2"). 3135 3136 3137%% We'll try get/set/trap and inform for all the auth & priv protocols. 3138%% For informs, the mgr is auth-engine. The agent has to sync. This is 3139%% accomplished by the first inform sent. That one will generate a 3140%% report, which makes it in sync. The notification-generating 3141%% application times out, and send again. This time it'll work. 3142 3143v3_security_cases() -> 3144 [ 3145 v3_crypto_basic, 3146 v3_md5_auth, 3147 v3_sha_auth, 3148 v3_des_priv 3149 ]. 3150 3151 3152v3_crypto_basic(suite) -> []; 3153v3_crypto_basic(_Config) -> 3154 ?P(v3_crypto_basic), 3155 EID = [0,0,0,0,0,0,0,0,0,0,0,2], 3156 %% From rfc2274 appendix A.3.1 3157 ?line KMd5_1 = snmp:passwd2localized_key(md5, "maplesyrup", EID), 3158 ?line [16#52,16#6f,16#5e,16#ed,16#9f,16#cc,16#e2,16#6f, 3159 16#89,16#64,16#c2,16#93,16#07,16#87,16#d8,16#2b] = 3160 KMd5_1, 3161 %% From rfc2274 appendix A.3.2 3162 ?line KSHA_1 = snmp:passwd2localized_key(sha, "maplesyrup", EID), 3163 ?line [16#66,16#95,16#fe,16#bc,16#92,16#88,16#e3,16#62,16#82,16#23, 3164 16#5f,16#c7,16#15,16#1f,16#12,16#84,16#97,16#b3,16#8f,16#3f] = 3165 KSHA_1, 3166 %% From rfc2274, appendix A.5.1 3167 ?line KMd5_2 = snmp:passwd2localized_key(md5, "newsyrup", EID), 3168 ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, 3169 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, 3170 16#88,16#05,16#61,16#51,16#41,16#67,16#6c,16#c9, 3171 16#19,16#61,16#74,16#e7,16#42,16#a3,16#25,16#51] = 3172 snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2, 16, 3173 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), 3174 %% From rfc2274, appendix A.5.2 3175 ?line KSHA_2 = snmp:passwd2localized_key(sha, "newsyrup", EID), 3176 ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, 3177 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, 3178 16#00,16#00,16#00,16#00,16#9c,16#10,16#17,16#f4, 3179 16#fd,16#48,16#3d,16#2d,16#e8,16#d5,16#fa,16#db, 3180 16#f8,16#43,16#92,16#cb,16#06,16#45,16#70,16#51] = 3181 snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2, 20, 3182 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), 3183 KSHA_1t = lists:sublist(KSHA_1, 16), 3184 KSHA_2t = lists:sublist(KSHA_2, 16), 3185 ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, 3186 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, 3187 16#7e,16#f8,16#d8,16#a4,16#c9,16#cd,16#b2,16#6b, 3188 16#47,16#59,16#1c,16#d8,16#52,16#ff,16#88,16#b5] = 3189 snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1t, KSHA_2t, 16, 3190 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), 3191 3192 %% Try with correct random 3193 ?line Kc1 = snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2), 3194 ?line KMd5_2 = snmp_user_based_sm_mib:extract_new_key(md5, KMd5_1, Kc1), 3195 ?line Kc2 = snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2), 3196 ?line KSHA_2 = snmp_user_based_sm_mib:extract_new_key(sha, KSHA_1, Kc2), 3197 ok. 3198 3199 3200 3201v3_md5_auth(suite) -> []; 3202v3_md5_auth(Config) when is_list(Config) -> 3203 ?P(v3_md5_auth), 3204 init_case(Config), 3205 3206 ?NPRINT("Testing MD5 authentication...takes a few seconds..."), 3207 3208 AgentConfDir = ?config(agent_conf_dir, Config), 3209 ?line rewrite_target_params_conf(AgentConfDir, "authMD5", authNoPriv), 3210 ?line snmp_target_mib:reconfigure(AgentConfDir), 3211 3212 MA = whereis(snmp_master_agent), 3213 3214 ?line load_master("Test2"), 3215 ?line load_master("TestTrap"), 3216 ?line load_master("TestTrapv2"), 3217 3218 try_test(v3_sync, [[{v2_proc, []}, 3219 {ma_v2_trap1, [MA]}, 3220 {v3_inform_sync, [MA]}]], 3221 [{sec_level, authNoPriv}, {user, "authMD5"}]), 3222 3223 ?line unload_master("TestTrapv2"), 3224 ?line unload_master("TestTrap"), 3225 ?line unload_master("Test2"), 3226 ?line reset_target_params_conf(AgentConfDir). 3227 3228v3_sha_auth(suite) -> []; 3229v3_sha_auth(Config) when is_list(Config) -> 3230 ?P(v3_sha_auth), 3231 init_case(Config), 3232 3233 ?NPRINT("Testing SHA authentication...takes a few seconds..."), 3234 3235 AgentConfDir = ?config(agent_conf_dir, Config), 3236 ?line rewrite_target_params_conf(AgentConfDir, "authSHA", authNoPriv), 3237 ?line snmp_target_mib:reconfigure(AgentConfDir), 3238 3239 MA = whereis(snmp_master_agent), 3240 3241 ?line load_master("Test2"), 3242 ?line load_master("TestTrap"), 3243 ?line load_master("TestTrapv2"), 3244 3245 try_test(v3_sync, [[{v2_proc, []}, 3246 {ma_v2_trap1, [MA]}, 3247 {v3_inform_sync, [MA]}]], 3248 [{sec_level, authNoPriv}, {user, "authSHA"}]), 3249 3250 ?line unload_master("TestTrapv2"), 3251 ?line unload_master("TestTrap"), 3252 ?line unload_master("Test2"), 3253 ?line reset_target_params_conf(AgentConfDir). 3254 3255v3_des_priv(suite) -> []; 3256v3_des_priv(Config) when is_list(Config) -> 3257 ?P(v3_des_priv), 3258 init_case(Config), 3259 3260 ?NPRINT("Testing DES encryption...takes a few seconds..."), 3261 3262 AgentConfDir = ?config(agent_conf_dir, Config), 3263 ?line rewrite_target_params_conf(AgentConfDir, "privDES", authPriv), 3264 ?line snmp_target_mib:reconfigure(AgentConfDir), 3265 3266 MA = whereis(snmp_master_agent), 3267 3268 snmp_user_based_sm_mib:usmUserTable(print), 3269 3270 ?line load_master("Test2"), 3271 ?line load_master("TestTrap"), 3272 ?line load_master("TestTrapv2"), 3273 3274 try_test(v3_sync, [[{v2_proc, []}, 3275 {ma_v2_trap1, [MA]}, 3276 {v3_inform_sync, [MA]}]], 3277 [{sec_level, authPriv}, {user, "privDES"}]), 3278 3279 ?line unload_master("TestTrapv2"), 3280 ?line unload_master("TestTrap"), 3281 ?line unload_master("Test2"), 3282 ?line reset_target_params_conf(AgentConfDir). 3283 3284%% -define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). 3285 3286%% Make sure mgr is in sync with agent 3287v3_sync(Funcs) -> 3288 ?DBG("v3_sync -> entry with Funcs: ~p",[Funcs]), 3289 g([[sysDescr, 0]]), 3290 ?expect2(report, [{?usmStatsNotInTimeWindows_instance, any}]), 3291 g([[sysDescr, 0]]), 3292 ?expect1([{[sysDescr,0], any}]), 3293 lists:foreach(fun({Func, Args}) -> apply(?MODULE, Func, Args) end, Funcs). 3294 3295v3_inform_sync(MA) -> 3296 ?DBG("v3_sync -> entry with MA: ~p => Send notification",[MA]), 3297 ?line snmpa:send_notification(MA, testTrapv22, no_receiver, 3298 "standard inform", []), 3299 %% Make sure agent is in sync with mgr... 3300 ?DBG("v3_sync -> wait some time: ",[]), 3301 ?SLEEP(20000), % more than 1500*10 in target_addr.conf 3302 ?DBG("v3_sync -> await response",[]), 3303 ?line ?expect2({inform, true}, 3304 [{[sysUpTime, 0], any}, 3305 {[snmpTrapOID, 0], ?system ++ [0,1]}]). 3306 3307 3308v2_caps(suite) -> []; 3309v2_caps(Config) when is_list(Config) -> 3310 ?P(v2_caps), 3311 init_case(Config), 3312 3313 try_test(v2_caps_i, [node()]). 3314 3315v2_caps_3(X) -> ?P(v2_caps_3), v2_caps(X). 3316 3317 3318v2_caps_i(Node) -> 3319 ?line Idx = rpc:call(Node, snmp, add_agent_caps, [[1,2,3,4,5], "test cap"]), 3320 g([[sysORID, Idx], [sysORDescr, Idx]]), 3321 ?line ?expect1([{[sysORID, Idx], [1,2,3,4,5]}, 3322 {[sysORDescr, Idx], "test cap"}]), 3323 ?line rpc:call(Node, snmp, del_agent_caps, [Idx]), 3324 g([[sysORID, Idx]]), 3325 ?line ?expect1([{[sysORID, Idx], noSuchInstance}]). 3326 3327 3328%% Req. Test2 3329v1_proc() -> 3330 ?DBG("v1_proc -> entry", []), 3331 %% According to RFC1157. 3332 %% Template: <Section>:<list no> 3333 v1_get_p(), 3334 v1_get_next_p(), 3335 v1_set_p(). 3336 3337 3338v1_get_p() -> 3339 %% 4.1.2:1 3340 g([[test2]]), 3341 ?line ?expect3(noSuchName, 1, [{[test2], 'NULL'}]), 3342 g([[tDescr]]), 3343 ?line ?expect3(noSuchName, 1, [{[tDescr], 'NULL'}]), 3344 g([[tDescr2,0]]), 3345 ?line ?expect3(noSuchName, 1, [{[tDescr2,0], 'NULL'}]), 3346 g([[tDescr3,0]]), 3347 ?line ?expect3(noSuchName, 1, [{[tDescr3,0], 'NULL'}]), 3348 g([[tDescr4,0]]), 3349 ?line ?expect3(noSuchName, 1, [{[tDescr4,0], 'NULL'}]), 3350 g([[sysDescr, 0], [tDescr,0]]), % Outside mibview 3351 ?line ?expect3(noSuchName, 2, [{[sysDescr, 0], 'NULL'}, 3352 {[tDescr,0], 'NULL'}]), 3353 g([[sysDescr,3]]), 3354 ?line ?expect3(noSuchName, 1, [{[sysDescr, 3], 'NULL'}]), 3355 3356 %% 4.1.2:2 3357 g([[tTable]]), 3358 ?line ?expect3(noSuchName, 1, [{[tTable], 'NULL'}]), 3359 g([[tEntry]]), 3360 ?line ?expect3(noSuchName, 1, [{[tEntry], 'NULL'}]), 3361 3362 %% 4.1.2:3 3363 g([[tTooBig, 0]]), 3364 ?line ?expect3(tooBig, 0, [{[tTooBig, 0], 'NULL'}]), 3365 3366 %% 4.1.2:4 3367 g([[tGenErr1, 0]]), 3368 ?line ?expect3(genErr, 1, [{[tGenErr1, 0], 'NULL'}]), 3369 g([[tGenErr2, 0]]), 3370 ?line ?expect3(genErr, 1, [{[tGenErr2, 0], 'NULL'}]), 3371 g([[sysDescr, 0], [tGenErr3, 0]]), 3372 ?line ?expect3(genErr, 2, [{[sysDescr, 0], 'NULL'}, 3373 {[tGenErr3, 0], 'NULL'}]). 3374 3375 3376v1_get_next_p() -> 3377 %% 4.1.3:1 3378 gn([[1,3,7,1]]), 3379 ?line ?expect3(noSuchName, 1, [{[1,3,7,1], 'NULL'}]), 3380 gn([[tDescr2]]), 3381 ?line ?expect3(tooBig, 0, any), 3382 3383 %% 4.1.3:2 3384 gn([[tTooBig]]), 3385 io:format("We currently don't handle tooBig correct!!!\n"), 3386 3387 ?line ?expect3(tooBig, 0, any), 3388 3389 %% 4.1.3:3 3390 gn([[tGenErr1]]), 3391 3392 ?line ?expect3(genErr, 1, any), 3393 gn([[tGenErr2]]), 3394 3395 ?line ?expect3(genErr, 1, any), 3396 gn([[sysDescr], [tGenErr3]]), 3397 3398 ?line ?expect3(genErr, 2, any). 3399 3400v1_set_p() -> 3401 %% 4.1.5:1 3402 s([{[1,3,7,0], i, 4}]), 3403 ?line ?expect3(noSuchName, 1, [{[1,3,7,0], 4}]), 3404 s([{[tDescr,0], s, "outside mibview"}]), 3405 ?line ?expect3(noSuchName, 1, [{[tDescr,0], "outside mibview"}]), 3406 s([{[tDescr3,0], s, "read-only"}]), 3407 ?line ?expect3(noSuchName, 1, [{[tDescr3,0], "read-only"}]), 3408 s([{[tDescr3], s, "noSuchObject"}]), 3409 ?line ?expect3(noSuchName, 1, [{[tDescr3], "noSuchObject"}]), 3410 s([{[tDescr3,1], s, "noSuchInstance"}]), 3411 ?line ?expect3(noSuchName, 1, [{[tDescr3,1], "noSuchInstance"}]), 3412 s([{[tDescr2,0], s, "inconsistentName"}]), 3413 ?line ?expect3(noSuchName, 1, [{[tDescr2,0], "inconsistentName"}]), 3414 3415 %% 4.1.5:2 3416 s([{[tDescr2, 0], i, 4}]), 3417 ?line ?expect3(badValue, 1, [{[tDescr2, 0], 4}]), 3418 s([{[tDescr2, 0], s, "badValue"}]), 3419 ?line ?expect3(badValue, 1, [{[tDescr2, 0], "badValue"}]), 3420 3421 %% 4.1.5:3 3422 %% The standard is quite incorrect here. The resp pdu was too big. In 3423 %% the resp pdu, we have the original vbs. In the tooBig pdu we still 3424 %% have to original vbs => the tooBig pdu is too big as well!!! It 3425 %% may not get it to the manager, unless the agent uses 'NULL' instead 3426 %% of the std-like original value. 3427 s([{[tTooBig, 0], s, ?tooBigStr}]), 3428 %% according to std: 3429% ?line ?expect3(tooBig, 0, [{[tTooBig, 0], ?tooBigStr}]), 3430 ?line ?expect3(tooBig, 0, [{[tTooBig, 0], 'NULL'}]), 3431 3432 %% 4.1.5:4 3433 s([{[tDescr2, 0], s, "is_set_ok_fail"}]), 3434 ?line ?expect3(genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]), 3435 s([{[tDescr2, 0], s, "commit_fail"}]), 3436 ?line ?expect3(genErr, 1, [{[tDescr2, 0], "commit_fail"}]). 3437 3438%% Req. Test2 3439v2_proc() -> 3440 %% According to RFC1905. 3441 %% Template: <Section>:<list no> 3442 ?DBG("v2_proc -> entry",[]), 3443 v2_get_p(), 3444 v2_get_next_p(), 3445 v2_get_bulk_p(), 3446 v2_set_p(). 3447 3448v2_get_p() -> 3449 %% 4.2.1:2 3450 ?DBG("v2_get_p -> entry",[]), 3451 g([[test2]]), 3452 ?line ?expect1([{[test2], noSuchObject}]), 3453 g([[tDescr]]), 3454 ?line ?expect1([{[tDescr], noSuchObject}]), 3455 g([[tDescr4,0]]), 3456 ?line ?expect1([{[tDescr4,0], noSuchObject}]), 3457 g([[sysDescr, 0], [tDescr,0]]), % Outside mibview 3458 ?line ?expect1([{[sysDescr,0], "Erlang SNMP agent"}, 3459 {[tDescr,0], noSuchObject}]), 3460 g([[tTable]]), 3461 ?line ?expect1([{[tTable], noSuchObject}]), 3462 g([[tEntry]]), 3463 ?line ?expect1([{[tEntry], noSuchObject}]), 3464 3465 %% 4.2.1:3 3466 g([[tDescr2,0]]), %% instrum ret noSuchName!!! 3467 ?line ?expect1([{[tDescr2,0], noSuchInstance}]), 3468 g([[tDescr3,0]]), 3469 ?line ?expect1([{[tDescr3,0], noSuchInstance}]), 3470 g([[sysDescr,3]]), 3471 ?line ?expect1([{[sysDescr, 3], noSuchInstance}]), 3472 g([[tIndex,1]]), 3473 ?line ?expect1([{[tIndex, 1], noSuchInstance}]), 3474 3475 %% 4.2.1 - any other error: genErr 3476 g([[tGenErr1, 0]]), 3477 ?line ?expect3(genErr, 1, [{[tGenErr1, 0], 'NULL'}]), 3478 g([[tGenErr2, 0]]), 3479 ?line ?expect3(genErr, 1, [{[tGenErr2, 0], 'NULL'}]), 3480 g([[sysDescr, 0], [tGenErr3, 0]]), 3481 ?line ?expect3(genErr, 2, [{[sysDescr, 0], 'NULL'}, 3482 {[tGenErr3, 0], 'NULL'}]), 3483 3484 %% 4.2.1 - tooBig 3485 g([[tTooBig, 0]]), 3486 ?line ?expect3(tooBig, 0, []). 3487 3488 3489v2_get_next_p() -> 3490 %% 4.2.2:2 3491 ?DBG("v2_get_next_p -> entry",[]), 3492 gn([[1,3,7,1]]), 3493 ?line ?expect1([{[1,3,7,1], endOfMibView}]), 3494 gn([[sysDescr], [1,3,7,1]]), 3495 ?line ?expect1([{[sysDescr, 0], "Erlang SNMP agent"}, 3496 {[1,3,7,1], endOfMibView}]), 3497 gn([[tCnt2, 1]]), 3498 ?line ?expect1([{[tCnt2,2], 100}]), 3499 gn([[tCnt2, 2]]), 3500 ?line ?expect1([{[tCnt2,2], endOfMibView}]), 3501 3502 %% 4.2.2 - any other error: genErr 3503 gn([[tGenErr1]]), 3504 ?line ?expect3(genErr, 1, [{[tGenErr1], 'NULL'}]), 3505 gn([[tGenErr2]]), 3506 ?line ?expect3(genErr, 1, [{[tGenErr2], 'NULL'}]), 3507 gn([[sysDescr], [tGenErr3]]), 3508 ?line ?expect3(genErr, 2, [{[sysDescr], 'NULL'}, 3509 {[tGenErr3], 'NULL'}]), 3510 3511 %% 4.2.2 - tooBig 3512 gn([[tTooBig]]), 3513 ?line ?expect3(tooBig, 0, []). 3514 3515v2_get_bulk_p() -> 3516 %% 4.2.3 3517 ?DBG("v2_get_bulk_p -> entry",[]), 3518 gb(1, 1, []), 3519 ?line ?expect1([]), 3520 gb(-1, 1, []), 3521 ?line ?expect1([]), 3522 gb(-1, -1, []), 3523 ?line ?expect1([]), 3524 gb(-1, -1, []), 3525 ?line ?expect1([]), 3526 gb(2, 0, [[sysDescr], [1,3,7,1]]), 3527 ?line ?expect1([{[sysDescr, 0], "Erlang SNMP agent"}, 3528 {[1,3,7,1], endOfMibView}]), 3529 gb(1, 2, [[sysDescr], [1,3,7,1]]), 3530 ?line ?expect1([{[sysDescr, 0], "Erlang SNMP agent"}, 3531 {[1,3,7,1], endOfMibView}]), 3532 gb(0, 2, [[sysDescr], [1,3,7,1]]), 3533 ?line ?expect1([{[sysDescr, 0], "Erlang SNMP agent"}, 3534 {[1,3,7,1], endOfMibView}, 3535 {[sysObjectID, 0], [1,2,3]}, 3536 {[1,3,7,1], endOfMibView}]), 3537 3538 gb(2, 2, [[sysDescr], [1,3,7,1], [sysDescr], [1,3,7,1]]), 3539 ?line ?expect1([{[sysDescr, 0], "Erlang SNMP agent"}, 3540 {[1,3,7,1], endOfMibView}, 3541 {[sysDescr, 0], "Erlang SNMP agent"}, 3542 {[1,3,7,1], endOfMibView}, 3543 {[sysObjectID, 0], [1,2,3]}, 3544 {[1,3,7,1], endOfMibView}]), 3545 3546 gb(1, 2, [[sysDescr], [sysDescr], [tTooBig]]), 3547 ?line ?expect1([{[sysDescr, 0], "Erlang SNMP agent"}, 3548 {[sysDescr, 0], "Erlang SNMP agent"}]), 3549 3550 gb(1,12, [[tDescr2], [sysDescr]]), % next one after tDescr2 is tTooBig. 3551 ?line ?expect1([]), 3552 3553 gb(2,2, [[sysDescr], [sysObjectID], [tGenErr1], [sysDescr]]), 3554 ?line ?expect3(genErr, 3, [{[sysDescr], 'NULL'}, 3555 {[sysObjectID], 'NULL'}, 3556 {[tGenErr1], 'NULL'}, 3557 {[sysDescr], 'NULL'}]), 3558 gb(0, 2, [[tCnt2, 1]]), 3559 ?line ?expect1([{[tCnt2,2], 100}, 3560 {[tCnt2,2], endOfMibView}]). 3561 3562 3563v2_set_p() -> 3564 %% 4.2.5:1 3565 ?DBG("v2_set_p -> entry",[]), 3566 s([{[1,3,7,0], i, 4}]), 3567 ?line ?expect3(noAccess, 1, [{[1,3,7,0], 4}]), 3568 s([{[tDescr,0], s, "outside mibview"}]), 3569 ?line ?expect3(noAccess, 1, [{[tDescr,0], "outside mibview"}]), 3570 3571 %% 4.2.5:2 3572 s([{[1,3,6,1,0], s, "noSuchObject"}]), 3573 ?line ?expect3(notWritable, 1, [{[1,3,6,1,0], "noSuchObject"}]), 3574 3575 %% 4.2.5:3 3576 s([{[tDescr2, 0], i, 4}]), 3577 ?line ?expect3(wrongType, 1, [{[tDescr2, 0], 4}]), 3578 s([{[tDescr2, 0], s, "badValue"}]), 3579 ?line ?expect3(badValue, 1, [{[tDescr2, 0], "badValue"}]), 3580 3581 %% 4.2.5:4 3582 s([{[tStr, 0], s, ""}]), 3583 ?line ?expect3(wrongLength, 1, [{[tStr, 0], ""}]), 3584 s([{[tStr, 0], s, "12345"}]), 3585 ?line ?expect3(wrongLength, 1, [{[tStr, 0], "12345"}]), 3586 3587 %% 4.2.5:5 - N/A 3588 3589 %% 4.2.5:6 3590 s([{[tInt1, 0], i, 0}]), 3591 ?line ?expect3(wrongValue, 1, [{[tInt1, 0], 0}]), 3592 s([{[tInt1, 0], i, 5}]), 3593 ?line ?expect3(wrongValue, 1, [{[tInt1, 0], 5}]), 3594 s([{[tInt2, 0], i, 0}]), 3595 ?line ?expect3(wrongValue, 1, [{[tInt2, 0], 0}]), 3596 s([{[tInt2, 0], i, 5}]), 3597 ?line ?expect3(wrongValue, 1, [{[tInt2, 0], 5}]), 3598 s([{[tInt3, 0], i, 5}]), 3599 ?line ?expect3(wrongValue, 1, [{[tInt3, 0], 5}]), 3600 3601 %% 4.2.5:7 3602 s([{[tDescrX, 1, 1], s, "noCreation"}]), 3603 ?line ?expect3(noCreation, 1, [{[tDescrX, 1, 1], "noCreation"}]), 3604 3605 %% 4.2.5:8 3606 s([{[tDescrX, 1, 2], s, "inconsistentName"}]), 3607 ?line ?expect3(inconsistentName, 1, 3608 [{[tDescrX, 1, 2], "inconsistentName"}]), 3609 3610 %% 4.2.5:9 3611 s([{[tCnt, 1, 2], i, 5}]), 3612 ?line ?expect3(notWritable, 1, [{[tCnt, 1, 2], 5}]), 3613 s([{[tDescr3,0], s, "read-only"}]), 3614 ?line ?expect3(notWritable, 1, [{[tDescr3,0], "read-only"}]), 3615 3616 %% 4.2.5:10 3617 s([{[tDescr2,0], s, "inconsistentValue"}]), 3618 ?line ?expect3(inconsistentValue, 1, 3619 [{[tDescr2,0], "inconsistentValue"}]), 3620 3621 %% 4.2.5:11 3622 s([{[tDescr2,0], s, "resourceUnavailable"}]), 3623 ?line ?expect3(resourceUnavailable, 1, 3624 [{[tDescr2,0],"resourceUnavailable"}]), 3625 3626 %% 4.2.5:12 3627 s([{[tDescr2, 0], s, "is_set_ok_fail"}]), 3628 ?line ?expect3(genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]). 3629 3630 %% commitFailed and undoFailed is tested by the 'undo' case. 3631 3632 3633%% Req. OLD-SNMPEA-MIB 3634table_test() -> 3635 io:format("Testing simple get, next and set on communityTable...~n"), 3636 3637 Key1c3 = [intCommunityViewIndex,get(mip),is("public")], 3638 Key2c3 = [intCommunityViewIndex,get(mip),is("standard trap")], 3639 Key1c4 = [intCommunityAccess,get(mip),is("public")], 3640 EndKey = [intCommunityEntry,[9],get(mip),is("public")], 3641 gn([[intCommunityEntry]]), 3642 ?line ?expect1([{Key1c3, 2}]), 3643 gn([[intCommunityTable]]), 3644 ?line ?expect1([{Key1c3, 2}]), 3645 gn([[community]]), 3646 ?line ?expect1([{Key1c3, 2}]), 3647 gn([[otpSnmpeaMIB]]), 3648 ?line ?expect1([{Key1c3, 2}]), 3649 gn([[ericsson]]), 3650 ?line ?expect1([{Key1c3, 2}]), 3651 gn([Key1c3]), 3652 ?line ?expect1([{Key2c3, 2}]), 3653 gn([Key2c3]), 3654 ?line ?expect1([{Key1c4, 2}]), 3655 gn([EndKey]), 3656 AgentIp = [intAgentIpAddress,0], 3657 ?line ?expect1([{AgentIp, any}]), 3658 g([Key1c3]), 3659 ?line ?expect1([{Key1c3, 2}]), 3660 g([EndKey]), 3661 ?line ?v1_2(?expect3(noSuchName, 1, any), 3662 ?expect1([{EndKey, noSuchObject}])), 3663 3664 io:format("Testing row creation/deletion on communityTable...~n"), 3665 NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], 3666 NewKeyc4 = [intCommunityAccess,get(mip),is("test")], 3667 NewKeyc5 = [intCommunityStatus,get(mip),is("test")], 3668 s([{NewKeyc5, ?createAndGo}]), 3669 ?line ?expect3(?v1_2(badValue, inconsistentValue), 1, any), 3670 s([{NewKeyc5, ?createAndGo}, {NewKeyc3, 2}, {NewKeyc4, 2}]), 3671 ?line ?expect1([{NewKeyc5, ?createAndGo},{NewKeyc3, 2}, {NewKeyc4, 2}]), 3672 g([NewKeyc4]), 3673 ?line ?expect1([{NewKeyc4, 2}]), 3674 s([{NewKeyc5, ?destroy}]), 3675 ?line ?expect1([{NewKeyc5, ?destroy}]), 3676 s([{NewKeyc4, 2}]), 3677 ?line ?expect3(?v1_2(noSuchName, inconsistentName), 1, [{NewKeyc4, 2}]), 3678 s([{NewKeyc5, ?createAndWait}]), 3679 ?line ?expect1([{NewKeyc5, ?createAndWait}]), 3680 g([NewKeyc5]), 3681 ?line ?expect1([{NewKeyc5, ?notReady}]), 3682 s([{NewKeyc4, 2}]), 3683 ?line ?expect1([{NewKeyc4, 2}]), 3684 g([NewKeyc5]), 3685 ?line ?expect1([{NewKeyc5, ?notReady}]), 3686 s([{NewKeyc3, 2}]), 3687 ?line ?expect1([{NewKeyc3, 2}]), 3688 g([NewKeyc5]), 3689 ?line ?expect1([{NewKeyc5, ?notInService}]), 3690 s([{NewKeyc5, ?active}]), 3691 ?line ?expect1([{NewKeyc5, ?active}]), 3692 s([{NewKeyc5, ?destroy}]), 3693 ?line ?expect1([{NewKeyc5, ?destroy}]), 3694 s([{NewKeyc3, 3}]), 3695 ?line ?expect3(?v1_2(noSuchName, inconsistentName), 1, [{NewKeyc3, 3}]), 3696 otp_1128_test(), 3697 ok. 3698 3699%% Req. system group 3700simple_standard_test() -> 3701 ?DBG("simple_standard_test -> entry",[]), 3702 gn([[1,1]]), 3703 ?line ?expect1([{[sysDescr,0], "Erlang SNMP agent"}]), 3704 gn([[1,3]]), 3705 ?line ?expect1([{[sysDescr,0], "Erlang SNMP agent"}]), 3706 gn([[1,3,6]]), 3707 ?line ?expect1([{[sysDescr,0], "Erlang SNMP agent"}]), 3708 gn([[1,3,6,1]]), 3709 ?line ?expect1([{[sysDescr,0], "Erlang SNMP agent"}]), 3710 gn([[1,3,6,1,2]]), 3711 ?line ?expect1([{[sysDescr,0], "Erlang SNMP agent"}]), 3712 gn([[1,3,6,1,2,1]]), 3713 ?line ?expect1([{[sysDescr,0], "Erlang SNMP agent"}]), 3714 gn([[1,3,6,1,2,1,1]]), 3715 ?line ?expect1([{[sysDescr,0], "Erlang SNMP agent"}]), 3716 gn([[sysDescr]]), 3717 ?line ?expect1([{[sysDescr,0], "Erlang SNMP agent"}]), 3718 g([[sysDescr,0]]), 3719 ?line ?expect1([{[sysDescr,0], "Erlang SNMP agent"}]), 3720 g([[sysDescr]]), 3721 ?line ?v1_2(?expect3(noSuchName, 1, any), 3722 ?expect1([{[sysDescr], noSuchObject}])), 3723 g([[1,6,7,0]]), 3724 ?line ?v1_2(?expect3(noSuchName, 1, any), 3725 ?expect1([{[1,6,7,0], noSuchObject}])), 3726 gn([[1,13]]), 3727 ?line ?v1_2(?expect3(noSuchName,1, any), 3728 ?expect1([{[1,13], endOfMibView}])), 3729 s([{[sysLocation, 0], "new_value"}]), 3730 ?line ?expect1([{[sysLocation, 0], "new_value"}]), 3731 g([[sysLocation, 0]]), 3732 ?line ?expect1([{[sysLocation, 0], "new_value"}]), 3733 io:format("Testing noSuchName and badValue...~n"), 3734 s([{[sysServices,0], 3}]), 3735 ?line ?expect3(?v1_2(noSuchName, notWritable), 1, any), 3736 s([{[sysLocation, 0], i, 3}]), 3737 ?line ?expect3(?v1_2(badValue, wrongType), 1, any), 3738 ?DBG("simple_standard_test -> done",[]), 3739 ok. 3740 3741%% This is run in the agent node 3742db_notify_client(suite) -> []; 3743db_notify_client(Config) when is_list(Config) -> 3744 ?P(db_notify_client), 3745 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 3746 ?DBG("db_notify_client -> case initiated: " 3747 "~n SaNode: ~p" 3748 "~n MgrNode: ~p" 3749 "~n MibDir: ~p", [_SaNode, _MgrNode, _MibDir]), 3750 ?DBG("db_notify_client -> maximize verbosity", []), 3751 snmpa_local_db:verbosity(trace), 3752 Self = self(), 3753 ?DBG("db_notify_client -> register self (~p) notify client", [Self]), 3754 snmpa_local_db:register_notify_client(Self, ?MODULE), 3755 3756 %% This call (to the manager) will issue to set operations, so 3757 %% we expect to receive to notify(insert) calls. 3758 try_test(db_notify_client_test), 3759 3760 ?DBG("db_notify_client -> await first notify",[]), 3761 receive 3762 {db_notify_test_reply, insert} -> 3763 ?DBG("db_notify_client -> first notify received",[]), 3764 ok 3765 after 10000 -> 3766 ?FAIL({timeout, waiting_for_first_event}) 3767 end, 3768 3769 ?DBG("db_notify_client -> await second notify",[]), 3770 receive 3771 {db_notify_test_reply, insert} -> 3772 ?DBG("db_notify_client -> second notify received",[]), 3773 ok 3774 after 10000 -> 3775 ?FAIL({timeout, waiting_for_second_event}) 3776 end, 3777 3778 ?DBG("db_notify_client -> unregister self (~p) notify client", [Self]), 3779 snmpa_local_db:unregister_notify_client(Self), 3780 ?DBG("db_notify_client -> minimize verbosity", []), 3781 snmpa_local_db:verbosity(silence), 3782 3783 ?DBG("db_notify_client -> done", []), 3784 ok. 3785 3786 3787%% This is run in the manager node 3788db_notify_client_test() -> 3789 ?DBG("set first new sysLocation",[]), 3790 s([{[sysLocation, 0], "new_value"}]), 3791 ?line ?expect1([{[sysLocation, 0], "new_value"}]), 3792 3793 ?DBG("set second new sysLocation",[]), 3794 s([{[sysLocation, 0], "new_value"}]), 3795 ?line ?expect1([{[sysLocation, 0], "new_value"}]). 3796 3797%% Callback function 3798notify(Pid, What) -> 3799 ?DBG("notify(~p,~p) -> called",[Pid,What]), 3800 Pid ! {db_notify_test_reply, What}. 3801 3802 3803%% Req: system group, OLD-SNMPEA-MIB, Klas1 3804big_test() -> 3805 3806 ?DBG("big_test -> testing simple next/get/set @ master agent...",[]), 3807 simple_standard_test(), 3808 3809 ?DBG("big_test -> testing simple next/get/set @ subagent...",[]), 3810 gn([[klas1]]), 3811 ?line ?expect1([{[fname,0], ""}]), 3812 g([[fname,0]]), 3813 ?line ?expect1([{[fname,0], ""}]), 3814 s([{[fname,0], s, "test set"}]), 3815 ?line ?expect1([{[fname,0], "test set"}]), 3816 g([[fname,0]]), 3817 ?line ?expect1([{[fname,0], "test set"}]), 3818 3819 ?DBG("big_test -> " 3820 "testing next from last instance in master to subagent...",[]), 3821 gn([[?v1_2(sysServices, sysORLastChange),0]]), 3822 ?line ?expect1([{[fname,0], "test set"}]), 3823 gn([[1,1], [?v1_2(sysServices, sysORLastChange),0]]), 3824 ?line ?expect1([{[sysDescr,0], "Erlang SNMP agent"}, 3825 {[fname,0], "test set"}]), 3826 s([{[fname,0], s, ""}]), 3827 ?line ?expect1([{[fname,0], ""}]), 3828 3829 table_test(), 3830 3831 ?DBG("big_test -> adding one row in subagent table",[]), 3832 _FTab = [friendsEntry], 3833 s([{[friendsEntry, [2, 3]], s, "kompis3"}, 3834 {[friendsEntry, [3, 3]], i, ?createAndGo}]), 3835 ?line ?expect1([{[friendsEntry, [2, 3]], "kompis3"}, 3836 {[friendsEntry, [3, 3]], ?createAndGo}]), 3837 g([[friendsEntry, [2, 3]], 3838 [friendsEntry, [3, 3]]]), 3839 ?line ?expect1([{[friendsEntry, [2, 3]], "kompis3"}, 3840 {[friendsEntry, [3, 3]], ?active}]), 3841 s([{[friendsEntry, [3, 3]], i, ?destroy}]), 3842 ?line ?expect1([{[friendsEntry, [3, 3]], ?destroy}]), 3843 3844 otp_1131_test(), 3845 3846 ?DBG("big_test -> adding two rows in subagent table with special INDEX", 3847 []), 3848 s([{[kompissEntry, [1, 3]], s, "kompis3"}, 3849 {[kompissEntry, [2, 3]], i, ?createAndGo}]), 3850 ?line ?expect1([{[kompissEntry, [1, 3]], "kompis3"}, 3851 {[kompissEntry, [2, 3]], ?createAndGo}]), 3852 g([[kompissEntry, [1, 3]], 3853 [kompissEntry, [2, 3]]]), 3854 ?line ?expect1([{[kompissEntry, [1, 3]], "kompis3"}, 3855 {[kompissEntry, [2, 3]], ?active}]), 3856 gn([[kompissEntry, [1]], 3857 [kompissEntry, [2]]]), 3858 ?line ?expect1([{[kompissEntry, [1, 3]], "kompis3"}, 3859 {[kompissEntry, [2, 3]], ?active}]), 3860 s([{[kompissEntry, [1, 2]], s, "kompis3"}, 3861 {[kompissEntry, [2, 2]], i, ?createAndGo}]), 3862 ?line ?expect1([{[kompissEntry, [1, 2]], "kompis3"}, 3863 {[kompissEntry, [2, 2]], ?createAndGo}]), 3864 gn([[kompissEntry, [1, 1]], 3865 [kompissEntry, [2, 1]]]), 3866 ?line ?expect1([{[kompissEntry, [1, 2]], "kompis3"}, 3867 {[kompissEntry, [2, 2]], ?active}]), 3868 s([{[kompissEntry, [2, 3]], i, ?destroy}]), 3869 ?line ?expect1([{[kompissEntry, [2, 3]], ?destroy}]), 3870 s([{[kompissEntry, [2, 2]], i, ?destroy}]), 3871 ?line ?expect1([{[kompissEntry, [2, 2]], ?destroy}]), 3872 ?DBG("big_test -> done",[]), 3873 ok. 3874 3875%% Req. system group, Klas2, OLD-SNMPEA-MIB 3876big_test_2() -> 3877 ?NPRINT("Testing simple next/get/set @ master agent (2)..."), 3878 simple_standard_test(), 3879 3880 ?NPRINT("Testing simple next/get/set @ subagent (2)..."), 3881 gn([[klas2]]), 3882 ?line ?expect1([{[fname2,0], ""}]), 3883 g([[fname2,0]]), 3884 ?line ?expect1([{[fname2,0], ""}]), 3885 s([{[fname2,0], s, "test set"}]), 3886 ?line ?expect1([{[fname2,0], "test set"}]), 3887 g([[fname2,0]]), 3888 ?line ?expect1([{[fname2,0], "test set"}]), 3889 3890 otp_1298_test(), 3891 3892 ?NPRINT("Testing next from last object in master to subagent (2)..."), 3893 gn([[?v1_2(sysServices, sysORLastChange),0]]), 3894 ?line ?expect1([{[fname2,0], "test set"}]), 3895 gn([[1,1], [?v1_2(sysServices, sysORLastChange),0]]), 3896 ?line ?expect1([{[sysDescr,0], "Erlang SNMP agent"}, 3897 {[fname2,0], "test set"}]), 3898 3899 table_test(), 3900 3901 ?NPRINT("Adding one row in subagent table (2)"), 3902 _FTab = [friendsEntry2], 3903 s([{[friendsEntry2, [2, 3]], s, "kompis3"}, 3904 {[friendsEntry2, [3, 3]], i, ?createAndGo}]), 3905 ?line ?expect1([{[friendsEntry2, [2, 3]], "kompis3"}, 3906 {[friendsEntry2, [3, 3]], ?createAndGo}]), 3907 g([[friendsEntry2, [2, 3]], 3908 [friendsEntry2, [3, 3]]]), 3909 ?line ?expect1([{[friendsEntry2, [2, 3]], "kompis3"}, 3910 {[friendsEntry2, [3, 3]], ?active}]), 3911 s([{[friendsEntry2, [3, 3]], i, ?destroy}]), 3912 ?line ?expect1([{[friendsEntry2, [3, 3]], ?destroy}]), 3913 3914 ?NPRINT("Adding two rows in subagent table with special INDEX (2)"), 3915 s([{[kompissEntry2, [1, 3]], s, "kompis3"}, 3916 {[kompissEntry2, [2, 3]], i, ?createAndGo}]), 3917 ?line ?expect1([{[kompissEntry2, [1, 3]], "kompis3"}, 3918 {[kompissEntry2, [2, 3]], ?createAndGo}]), 3919 g([[kompissEntry2, [1, 3]], 3920 [kompissEntry2, [2, 3]]]), 3921 ?line ?expect1([{[kompissEntry2, [1, 3]], "kompis3"}, 3922 {[kompissEntry2, [2, 3]], ?active}]), 3923 gn([[kompissEntry2, [1]], 3924 [kompissEntry2, [2]]]), 3925 ?line ?expect1([{[kompissEntry2, [1, 3]], "kompis3"}, 3926 {[kompissEntry2, [2, 3]], ?active}]), 3927 s([{[kompissEntry2, [1, 2]], s, "kompis3"}, 3928 {[kompissEntry2, [2, 2]], i, ?createAndGo}]), 3929 ?line ?expect1([{[kompissEntry2, [1, 2]], "kompis3"}, 3930 {[kompissEntry2, [2, 2]], ?createAndGo}]), 3931 gn([[kompissEntry2, [1, 1]], 3932 [kompissEntry2, [2, 1]]]), 3933 ?line ?expect1([{[kompissEntry2, [1, 2]], "kompis3"}, 3934 {[kompissEntry2, [2, 2]], ?active}]), 3935 s([{[kompissEntry2, [2, 3]], i, ?destroy}]), 3936 ?line ?expect1([{[kompissEntry2, [2, 3]], ?destroy}]), 3937 s([{[kompissEntry2, [2, 2]], i, ?destroy}]), 3938 ?line ?expect1([{[kompissEntry2, [2, 2]], ?destroy}]), 3939 ok. 3940 3941%% Req. Test1 3942multi_threaded_test() -> 3943 ?NPRINT("Testing multi threaded agent..."), 3944 g([[multiStr,0]]), 3945 Pid = get_multi_pid(), 3946 g([[sysUpTime,0]]), 3947 ?line ?expect1([{[sysUpTime,0], any}]), 3948 s([{[sysLocation, 0], s, "pelle"}]), 3949 ?line ?expect1([{[sysLocation, 0], "pelle"}]), 3950 Pid ! continue, 3951 ?line ?expect1([{[multiStr,0], "ok"}]), 3952 3953 s([{[multiStr, 0], s, "block"}]), 3954 Pid2 = get_multi_pid(), 3955 g([[sysUpTime,0]]), 3956 ?line ?expect1([{[sysUpTime,0], any}]), 3957 g([[multiStr,0]]), 3958 Pid3 = get_multi_pid(), 3959 g([[sysUpTime,0]]), 3960 ?line ?expect1([{[sysUpTime,0], any}]), 3961 s([{[sysLocation, 0], s, "kalle"}]), 3962 Pid3 ! continue, 3963 ?line ?expect1([{[multiStr,0], "ok"}]), 3964 Pid2 ! continue, 3965 ?line ?expect1([{[multiStr,0], "block"}]), 3966 ?line ?expect1([{[sysLocation,0], "kalle"}]). 3967 3968%% Req. Test1, TestTrapv2 3969mt_trap_test(MA, MT) -> 3970 ?NPRINT("Testing trap-sending with multi threaded (~w) agent...", [MT]), 3971 ?IPRINT("mt_trap_test(01) -> issue testTrapv22 (standard trap)", []), 3972 snmpa:send_trap(MA, testTrapv22, "standard trap"), 3973 ?IPRINT("mt_trap_test(02) -> await v2trap", []), 3974 ?line ?expect2(v2trap, [{[sysUpTime, 0], any}, 3975 {[snmpTrapOID, 0], ?system ++ [0,1]}]), 3976 3977 %% multi-threaded = true 3978 %% This will *lock* the 'main thread' of a multi-threaded agent, 3979 %% the worker state will be 'busy'. Therefor when a new request 3980 %% arrives a new *temporary* worker will be spawned. 3981 ?IPRINT("mt_trap_test(03) -> issue mtTrap (standard trap)", []), 3982 snmpa:send_trap(MA, mtTrap, "standard trap"), 3983 Pid = get_multi_pid(), 3984 ?IPRINT("mt_trap_test(04) -> multi pid: ~p. Now request sysUpTime...", [Pid]), 3985 g([[sysUpTime,0]]), 3986 3987 ?IPRINT("mt_trap_test(06) -> await sysUpTime", []), 3988 ?line ?expect1([{[sysUpTime,0], any}]), 3989 3990 %% This will *only* work if multi-threaded is 'true', not 'extended' 3991 %% since in the latter case all notifications are serialized through 3992 %% a dedicated worker, which is now locked (see above). 3993 3994 if 3995 (MT =:= true) -> 3996 ?IPRINT("mt_trap_test(07) -> issue testTrapv22 (standard trap)", []), 3997 snmpa:send_trap(MA, testTrapv22, "standard trap"), 3998 ?IPRINT("mt_trap_test(08) -> await v2trap", []), 3999 ?line ?expect2(v2trap, 4000 [{[sysUpTime, 0], any}, 4001 {[snmpTrapOID, 0], ?system ++ [0,1]}]); 4002 true -> 4003 ok 4004 end, 4005 4006 ?IPRINT("mt_trap_test(09) -> send continue to multi-pid", []), 4007 Pid ! continue, 4008 4009 ?IPRINT("mt_trap_test(10) -> await v2trap", []), 4010 ?line ?expect2(v2trap, [{[sysUpTime, 0], any}, 4011 {[snmpTrapOID, 0], ?testTrap ++ [2]}, 4012 {[multiStr,0], "ok"}]), 4013 ?IPRINT("mt_trap_test(11) -> done", []), 4014 ok. 4015 4016 4017get_multi_pid() -> 4018 get_multi_pid(10). 4019get_multi_pid(0) -> 4020 ?line ?FAIL(no_global_name); 4021get_multi_pid(N) -> 4022 ?SLEEP(1000), 4023 case global:whereis_name(snmp_multi_tester) of 4024 Pid when is_pid(Pid) -> Pid; 4025 _ -> get_multi_pid(N-1) 4026 end. 4027 4028%% Req. Test1 4029types_v2_test() -> 4030 ?NPRINT("Testing v2 types..."), 4031 4032 s([{[bits1,0], 2#10}]), 4033 ?line ?expect1([{[bits1,0], ?str(2#10)}]), 4034 g([[bits1,0]]), 4035 ?line ?expect1([{[bits1,0], ?str(2#101)}]), 4036 4037 s([{[bits2,0], 2#11000000110}]), 4038 ?line ?expect1([{[bits2,0], ?str(2#11000000110)}]), 4039 g([[bits2,0]]), 4040 ?line ?expect1([{[bits2,0], ?str(2#11000000110)}]), 4041 4042 g([[bits3,0]]), 4043 ?line ?expect3(genErr, 1, any), 4044 4045 g([[bits4,0]]), 4046 ?line ?expect3(genErr, 1, any), 4047 4048 s([{[bits1,0], s, [2#10]}]), 4049 ?line ?expect3(?v1_2(badValue, wrongValue), 1, any), 4050 4051 s([{[bits2,0], 2#11001001101010011}]), 4052 ?line ?expect3(?v1_2(badValue, wrongValue), 1, any). 4053 4054 4055%% Req. Test1 4056implied_test(MA) -> 4057 ?IPRINT("implied_test -> start"), 4058 4059 ?NPRINT("Testing IMPLIED..."), 4060 4061 snmpa:verbosity(MA, trace), 4062 4063 %% Create two rows, check that they are get-nexted in correct order. 4064 Idx1 = "apa", 4065 Idx2 = "qq", 4066 ?DBG("implied_test -> (send) create row 1 '~s' in table 1",[Idx1]), 4067 s([{[testStatus, Idx1], i, ?createAndGo}, {[testDescr, Idx1],s,"row 1"}]), 4068 ?line ?expect1([{[testStatus, Idx1], ?createAndGo}, 4069 {[testDescr, Idx1], "row 1"}]), 4070 ?DBG("implied_test -> (send) create row 2 '~s' in table 1",[Idx2]), 4071 s([{[testStatus, Idx2], i, ?createAndGo}, {[testDescr, Idx2],s,"row 2"}]), 4072 ?line ?expect1([{[testStatus, Idx2], ?createAndGo}, 4073 {[testDescr, Idx2], "row 2"}]), 4074 ?DBG("implied_test -> get-next(testDescr)",[]), 4075 gn([[testDescr]]), 4076 ?line ?expect1([{[testDescr,Idx1], "row 1"}]), 4077 ?DBG("implied_test -> get-next(testDescr) of row 1",[]), 4078 gn([[testDescr,Idx1]]), 4079 ?line ?expect1([{[testDescr,Idx2], "row 2"}]), 4080 4081 % Delete the rows 4082 ?DBG("implied_test -> (send) delete row 1 '~s' from table 1",[Idx1]), 4083 s([{[testStatus, Idx1], i, ?destroy}]), 4084 ?line ?expect1([{[testStatus, Idx1], ?destroy}]), 4085 ?DBG("implied_test -> (send) delete row 2 '~s' from table 1",[Idx2]), 4086 s([{[testStatus, Idx2], i, ?destroy}]), 4087 ?line ?expect1([{[testStatus, Idx2], ?destroy}]), 4088 4089 %% Try the same in other table 4090 Idx3 = [1, "apa"], 4091 Idx4 = [1, "qq"], 4092 ?DBG("implied_test -> (send) create row 1 '~s' in table 2",[Idx3]), 4093 s([{[testStatus2, Idx3], i, ?createAndGo}, {[testDescr2,Idx3],s,"row 1"}]), 4094 ?line ?expect1([{[testStatus2, Idx3], ?createAndGo}, 4095 {[testDescr2, Idx3], "row 1"}]), 4096 ?DBG("implied_test -> (send) create row 2 '~s' in table 2",[Idx4]), 4097 s([{[testStatus2, Idx4], i, ?createAndGo}, {[testDescr2,Idx4],s,"row 2"}]), 4098 ?line ?expect1([{[testStatus2, Idx4], ?createAndGo}, 4099 {[testDescr2, Idx4], "row 2"}]), 4100 ?DBG("implied_test -> get-next(testDescr2)",[]), 4101 gn([[testDescr2]]), 4102 ?line ?expect1([{[testDescr2,Idx3], "row 1"}]), 4103 ?DBG("implied_test -> get-next(testDescr2) of row 1",[]), 4104 gn([[testDescr2,Idx3]]), 4105 ?line ?expect1([{[testDescr2,Idx4], "row 2"}]), 4106 4107 % Delete the rows 4108 ?DBG("implied_test -> (send) delete row 1 '~s' from table 2",[Idx3]), 4109 s([{[testStatus2, Idx3], i, ?destroy}]), 4110 ?line ?expect1([{[testStatus2, Idx3], ?destroy}]), 4111 ?DBG("implied_test -> (send) delete row 2 '~s' from table 2",[Idx4]), 4112 s([{[testStatus2, Idx4], i, ?destroy}]), 4113 ?line ?expect1([{[testStatus2, Idx4], ?destroy}]), 4114 4115 snmpa:verbosity(MA, log), 4116 4117 ?IPRINT("implied_test -> done", []), 4118 ok. 4119 4120 4121 4122%% Req. Test1 4123sparse_table_test() -> 4124 ?NPRINT("Testing sparse table..."), 4125 4126 %% Create two rows, check that they are get-nexted in correct order. 4127 Idx1 = 1, 4128 Idx2 = 2, 4129 s([{[sparseStatus, Idx1], i, ?createAndGo}, 4130 {[sparseDescr, Idx1], s, "row 1"}]), 4131 ?line ?expect1([{[sparseStatus, Idx1], ?createAndGo}, 4132 {[sparseDescr, Idx1], "row 1"}]), 4133 s([{[sparseStatus, Idx2], i, ?createAndGo}, 4134 {[sparseDescr, Idx2], s, "row 2"}]), 4135 ?line ?expect1([{[sparseStatus, Idx2], ?createAndGo}, 4136 {[sparseDescr, Idx2], "row 2"}]), 4137 ?v1_2(gn([[sparseIndex], [sparseDescr,Idx1], [sparseDescr,Idx2], 4138 [sparseStatus,Idx1], [sparseStatus,Idx2]]), 4139 gb(0,5,[[sparseIndex]])), 4140 ?line ?expect1([{[sparseDescr,Idx1], "row 1"}, 4141 {[sparseDescr,Idx2], "row 2"}, 4142 {[sparseStatus,Idx1], ?active}, 4143 {[sparseStatus,Idx2], ?active}, 4144 {[sparseStr,0], "slut"}]), 4145 %% Delete the rows 4146 s([{[sparseStatus, Idx1], i, ?destroy}]), 4147 ?line ?expect1([{[sparseStatus, Idx1], ?destroy}]), 4148 s([{[sparseStatus, Idx2], i, ?destroy}]), 4149 ?line ?expect1([{[sparseStatus, Idx2], ?destroy}]). 4150 4151 4152%% Req. Test1 4153cnt_64_test(MA) -> 4154 ?IPRINT("start cnt64 test (~p)", [MA]), 4155 snmpa:verbosity(MA, trace), 4156 ?IPRINT("start cnt64 test"), 4157 4158 ?NPRINT("Testing Counter64, and at the same time, " 4159 "RowStatus is not last column"), 4160 4161 ?DBG("get cnt64",[]), 4162 g([[cnt64,0]]), 4163 ?DBG("await response",[]), 4164 ?line ?v1_2(?expect3(noSuchName, 1, any), 4165 ?expect1([{[cnt64,0],18446744073709551615}])), 4166 ?DBG("get-next cnt64",[]), 4167 gn([[cnt64]]), 4168 ?DBG("await response",[]), 4169 ?line ?v1_2(?expect1([{[cnt64Str,0], "after cnt64"}]), 4170 ?expect1([{[cnt64,0],18446744073709551615}])), 4171 ?DBG("send cntTrap",[]), 4172 snmpa:send_trap(MA,cntTrap,"standard trap",[ 4173 {sysContact, "pelle"}, 4174 {cnt64, 10}, 4175 {sysLocation, "here"} 4176 ]), 4177 ?DBG("await response",[]), 4178 ?line ?v1_2(?expect5(trap, [test], 6, 1, [{[sysContact,0], "pelle"}, 4179 {[sysLocation,0], "here"}]), 4180 ?expect2(v2trap, [{[sysUpTime, 0], any}, 4181 {[snmpTrapOID, 0], ?testTrap ++ [1]}, 4182 {[sysContact,0], "pelle"}, 4183 {[cnt64,0], 10}, 4184 {[sysLocation,0], "here"}])), 4185 4186 %% Create two rows, check that they are get-nexted in correct order. 4187 Idx1 = 1, 4188 Idx2 = 2, 4189 ?DBG("create row (cntStatus): ~p",[Idx1]), 4190 s([{[cntStatus, Idx1], i, ?createAndGo}]), 4191 ?DBG("await response",[]), 4192 ?line ?expect1([{[cntStatus, Idx1], ?createAndGo}]), 4193 ?DBG("create row (cntStatus): ~p",[Idx2]), 4194 s([{[cntStatus, Idx2], i, ?createAndGo}]), 4195 ?DBG("await response",[]), 4196 ?line ?expect1([{[cntStatus, Idx2], ?createAndGo}]), 4197 4198 ?DBG("get-next (cntIndex)",[]), 4199 gn([[cntIndex]]), 4200 ?DBG("await response",[]), 4201 ?line ?v1_2(?expect1([{[cntStatus,Idx1], ?active}]), 4202 ?expect1([{[cntCnt,Idx1], 0}])), 4203 % Delete the rows 4204 ?DBG("delete row (cntStatus): ~p",[Idx1]), 4205 s([{[cntStatus, Idx1], i, ?destroy}]), 4206 ?DBG("await response",[]), 4207 ?line ?expect1([{[cntStatus, Idx1], ?destroy}]), 4208 ?DBG("delete row (cntStatus): ~p",[Idx2]), 4209 s([{[cntStatus, Idx2], i, ?destroy}]), 4210 ?DBG("await response",[]), 4211 ?line ?expect1([{[cntStatus, Idx2], ?destroy}]), 4212 catch snmpa:verbosity(MA, log), 4213 ?DBG("done",[]), 4214 ok. 4215 4216%% Req. Test1 4217opaque_test() -> 4218 ?NPRINT("Testing Opaque datatype..."), 4219 g([[opaqueObj,0]]), 4220 ?line ?expect1([{[opaqueObj,0], "opaque-data"}]). 4221 4222%% Req. OLD-SNMPEA-MIB 4223api_test(MaNode) -> 4224 ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, 4225 [intAgentIpAddress]), 4226 ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, 4227 oid_to_name, [OID]), 4228 ?line false = rpc:call(MaNode, snmp, name_to_oid, [intAgentIpAddres]), 4229 ?line false = rpc:call(MaNode, snmp, oid_to_name, 4230 [[1,5,32,3,54,3,3,34,4]]), 4231 ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, 4232 [intViewType, excluded]), 4233 ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, 4234 [intViewType, 2]), 4235 ?line false = rpc:call(MaNode, snmp, enum_to_int, [intViewType, exclude]), 4236 ?line false = rpc:call(MaNode, snmp, enum_to_int, 4237 [intAgentIpAddress, exclude]), 4238 ?line false = rpc:call(MaNode, snmp, enum_to_int, 4239 [intAgentIpAddre, exclude]), 4240 ?line false = rpc:call(MaNode, snmp, int_to_enum, [intViewType, 3]), 4241 ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddress, 2]), 4242 ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddre, 2]), 4243 ?line {value, active} = rpc:call(MaNode, snmp, 4244 int_to_enum, ['RowStatus', ?active]), 4245 ?line {value, ?destroy} = rpc:call(MaNode, snmp, 4246 enum_to_int, ['RowStatus', destroy]), 4247 ?line false = rpc:call(MaNode, snmp, 4248 enum_to_int, ['RowStatus', xxxdestroy]), 4249 ?line false = rpc:call(MaNode, snmp, 4250 enum_to_int, ['xxRowStatus', destroy]), 4251 ?line false = rpc:call(MaNode, snmp, int_to_enum, ['RowStatus', 25]), 4252 ?line false = rpc:call(MaNode, snmp, int_to_enum, ['xxRowStatus', 1]), 4253 ?line case snmp:date_and_time() of 4254 List when is_list(List), length(List) == 8 -> ok; 4255 List when is_list(List), length(List) == 11 -> ok 4256 end. 4257 4258%% Req. Klas3 4259api_test2() -> 4260 g([[fname3,0]]), 4261 ?line ?expect1([{[fname3,0], "ok"}]), 4262 g([[fname4,0]]), 4263 ?line ?expect1([{[fname4,0], 1}]). 4264 4265api_test3() -> 4266 g([[fname3,0]]), 4267 ?line ?expect1([{[fname3,0], "ok"}]). 4268 4269 4270unreg_test() -> 4271 gn([[?v1_2(sysServices, sysORLastChange),0]]), 4272 ?line ?expect1([{[snmpInPkts, 0], any}]). 4273 4274load_test() -> 4275 gn([[?v1_2(sysServices, sysORLastChange),0]]), 4276 ?line ?expect1([{[fname,0], ""}]). 4277 4278%% Req. Klas1 4279load_test_sa() -> 4280 gn([[?v1_2(sysServices,sysORLastChange), 0]]), 4281 ?line ?expect1([{[fname,0], any}]). 4282 4283%% Req. system group, Klas1, OLD-SNMPEA-MIB 4284do_mul_get() -> 4285 Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], 4286 Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], 4287 s([{[fname,0], s, "test set"}]), 4288 ?line ?expect1([{[fname,0], "test set"}]), 4289 g([[sysDescr,0], Key1c4, [fname,0],Key1c3,[sysName,0]]), 4290 ?line ?expect1([{[sysDescr,0], "Erlang SNMP agent"}, 4291 {Key1c4, 2}, 4292 {[fname,0], "test set"}, 4293 {Key1c3, 2}, 4294 {[sysName,0], "test"}]), 4295 g([[1,3,7,1], Key1c4, [sysDescr,0], [1,3,7,2], Key1c3, [sysDescr,0]]), 4296 ?line ?v1_2(?expect3(noSuchName, [1,4], any), 4297 ?expect1([{[1,3,7,1], noSuchObject}, 4298 {Key1c4, 2}, 4299 {[sysDescr,0], "Erlang SNMP agent"}, 4300 {[1,3,7,2], noSuchObject}, 4301 {Key1c3, 2}, 4302 {[sysDescr,0], "Erlang SNMP agent"}])). 4303 4304%% Req. v1, system group, Klas1, OLD-SNMPEA-MIB, *ej* Klas3. 4305do_mul_get_err() -> 4306 Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], 4307 Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], 4308 s([{[fname,0], s, "test set"}]), 4309 ?line ?expect1([{[fname,0], "test set"}]), 4310 g([[sysDescr,0],Key1c4,[fname,0], Key1c3, [sysName,2]]), 4311 ?line ?v1_2(?expect3(noSuchName, 5, any), 4312 ?expect1([{[sysDescr,0], "Erlang SNMP agent"}, 4313 {Key1c4, 2}, 4314 {[fname,0], "test set"}, 4315 {Key1c3, 2}, 4316 {[sysName,2], noSuchInstance}])), 4317 g([[sysDescr,0],Key1c4,[fname3,0], Key1c3, [sysName,1]]), 4318 ?line ?v1_2(?expect3(noSuchName, [3,5], any), 4319 ?expect1([{[sysDescr,0], "Erlang SNMP agent"}, 4320 {Key1c4, 2}, 4321 {[fname3,0], noSuchObject}, 4322 {Key1c3, 2}, 4323 {[sysName,1], noSuchInstance}])). 4324 4325 4326%% Req. system group, Klas1, OLD-SNMPEA-MIB 4327do_mul_next() -> 4328 Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], 4329 Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], 4330 Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], 4331 Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], 4332 s([{[fname,0], s, "test set"}]), 4333 ?line ?expect1([{[fname,0], "test set"}]), 4334 gn([[sysDescr], Key1c4s, [fname],Key1c3s,[sysName]]), 4335 ?line ?expect1([{[sysDescr,0], "Erlang SNMP agent"}, 4336 {Key1c4, 2}, {[fname,0], "test set"}, 4337 {Key1c3, 2}, {[sysName,0], "test"}]). 4338 4339%% Req. system group, Klas1, OLD-SNMPEA-MIB 4340do_mul_next_err() -> 4341 Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], 4342 Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], 4343 Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], 4344 Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], 4345 s([{[fname,0], s, "test set"}]), 4346 ?line ?expect1([{[fname,0], "test set"}]), 4347 gn([[sysDescr], Key1c4s, [1,3,6,999], [fname],[1,3,90], Key1c3s,[sysName]]), 4348 ?line ?v1_2(?expect3(noSuchName, [3,5], any), 4349 ?expect1([{[sysDescr,0], "Erlang SNMP agent"}, 4350 {Key1c4, 2}, 4351 {[1,3,6,999], endOfMibView}, 4352 {[fname,0], "test set"}, 4353 {[1,3,90], endOfMibView}, 4354 {Key1c3, 2}, 4355 {[sysName,0], "test"}])). 4356 4357 4358%% Req. system group, Klas1, OLD-SNMPEA-MIB 4359do_mul_set() -> 4360 ?NPRINT("Adding one row in subagent table, and one in master table"), 4361 NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], 4362 NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], 4363 NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], 4364 s([{[friendsEntry, [2, 3]], "kompis3"}, 4365 {NewKeyc3, 2}, 4366 {[sysLocation,0], "new_value"}, 4367 {NewKeyc5, ?createAndGo}, 4368 {NewKeyc4, 2}, 4369 {[friendsEntry, [3, 3]], ?createAndGo}]), 4370 ?line ?expect1([{[friendsEntry, [2, 3]], "kompis3"}, 4371 {NewKeyc3, 2}, 4372 {[sysLocation,0], "new_value"}, 4373 {NewKeyc5, ?createAndGo}, 4374 {NewKeyc4, 2}, 4375 {[friendsEntry, [3, 3]], ?createAndGo}]), 4376 g([[friendsEntry, [2, 3]], 4377 [sysLocation,0], 4378 [friendsEntry, [3, 3]]]), 4379 ?line ?expect1([{[friendsEntry, [2, 3]], "kompis3"}, 4380 {[sysLocation,0], "new_value"}, 4381 {[friendsEntry, [3, 3]], ?active}]), 4382 g([NewKeyc4]), 4383 ?line ?expect1([{NewKeyc4, 2}]), 4384 s([{[friendsEntry, [3, 3]], ?destroy}, 4385 {NewKeyc5, ?destroy}]), 4386 ?line ?expect1([{[friendsEntry, [3, 3]], ?destroy}, 4387 {NewKeyc5, ?destroy}]). 4388 4389%% Req. system group, Klas1, OLD-SNMPEA-MIB 4390do_mul_set_err() -> 4391 NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], 4392 NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], 4393 NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], 4394 ?NPRINT("Adding one row in subagent table, and one in master table"), 4395 s([{[friendsEntry, [2, 3]], s, "kompis3"}, 4396 {NewKeyc3, 2}, 4397 {[sysUpTime,0], 45}, % sysUpTime (readOnly) 4398 {NewKeyc5, ?createAndGo}, 4399 {NewKeyc4, 2}, 4400 {[friendsEntry, [3, 3]], ?createAndGo}]), 4401 ?line ?expect3(?v1_2(noSuchName, notWritable), 3, any), 4402 g([[friendsEntry, [2, 3]]]), 4403 ?line ?v1_2(?expect3(noSuchName, 1, any), 4404 ?expect1([{[friendsEntry, [2,3]], noSuchInstance}])), 4405 g([NewKeyc4]), 4406 ?line ?v1_2(?expect3(noSuchName, 1, any), 4407 ?expect1([{NewKeyc4, noSuchInstance}])). 4408 4409%% Req. SA-MIB 4410sa_mib() -> 4411 g([[sa, [2,0]]]), 4412 ?line ?expect1([{[sa, [2,0]], 3}]), 4413 s([{[sa, [1,0]], s, "sa_test"}]), 4414 ?line ?expect1([{[sa, [1,0]], "sa_test"}]), 4415 ok. 4416 4417ma_trap1(MA) -> 4418 ok = snmpa:send_trap(MA, testTrap2, "standard trap"), 4419 ?line ?expect5(trap, [system], 6, 1, [{[system, [4,0]], 4420 "{mbj,eklas}@erlang.ericsson.se"}]), 4421 ok = snmpa:send_trap(MA, testTrap1, "standard trap"), 4422 ?line ?expect5(trap, [1,2,3] , 1, 0, [{[system, [4,0]], 4423 "{mbj,eklas}@erlang.ericsson.se"}]), 4424 ok. 4425 4426ma_trap2(MA) -> 4427 snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), 4428 ?line ?expect5(trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]), 4429 ok. 4430 4431ma_v2_2_v1_trap(MA) -> 4432 snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), 4433 ?line ?expect5(trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]), 4434 ok. 4435 4436ma_v2_2_v1_trap2(MA) -> 4437 snmpa:send_trap(MA,linkUp,"standard trap",[{ifIndex, [1], 1}, 4438 {ifAdminStatus, [1], 1}, 4439 {ifOperStatus, [1], 2}]), 4440 ?line ?expect5(trap, [1,2,3], 3, 0, [{[ifIndex, 1], 1}, 4441 {[ifAdminStatus, 1], 1}, 4442 {[ifOperStatus, 1], 2}]), 4443 ok. 4444 4445sa_trap1(SA) -> 4446 %% io:format("sa_trap1 -> entry with" 4447 %% "~n SA: ~p" 4448 %% "~n node(SA): ~p" 4449 %% "~n self(): ~p" 4450 %% "~n node(): ~p" 4451 %% "~n", [SA, node(SA), self(), node()]), 4452 _VRes = (catch snmpa:verbosity(SA, {subagents, trace})), 4453 %% io:format("sa_trap1 -> SA verbosity set: " 4454 %% "~n VRes: ~p" 4455 %% "~n", [VRes]), 4456 _TSRes = (catch snmpa:send_trap(SA, saTrap, "standard trap")), 4457 %% io:format("sa_trap1 -> SA trap send: " 4458 %% "~n TSRes: ~p" 4459 %% "~n", [TSRes]), 4460 ?line ?expect5(trap, [ericsson], 6, 1, [{[system, [4,0]], 4461 "{mbj,eklas}@erlang.ericsson.se"}, 4462 {[sa, [1,0]], "sa_test"}]), 4463 snmpa:verbosity(SA, {subagents, silence}), 4464 ok. 4465 4466sa_trap2(SA) -> 4467 snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), 4468 ?line ?expect5(trap, [ericsson], 6, 1, [{[system, [4,0]], "pelle"}, 4469 {[sa, [1,0]], "sa_test"}]), 4470 ok. 4471 4472sa_trap3(SA) -> 4473 snmpa:send_trap(SA, saTrap2, "standard trap", 4474 [{intViewSubtree, [4], [1,2,3,4]}]), 4475 ?line ?expect5(trap, [ericsson], 6, 2, [{[system, [4,0]], 4476 "{mbj,eklas}@erlang.ericsson.se"}, 4477 {[sa, [1,0]], "sa_test"}, 4478 {[intViewSubtree,4],[1,2,3,4]}]), 4479 ok. 4480 4481ma_v2_trap1(MA) -> 4482 ?DBG("ma_v2_traps -> entry with MA = ~p => " 4483 "send standard trap: testTrapv22",[MA]), 4484 snmpa:send_trap(MA, testTrapv22, "standard trap"), 4485 ?line ?expect2(v2trap, [{[sysUpTime, 0], any}, 4486 {[snmpTrapOID, 0], ?system ++ [0,1]}]), 4487 ?DBG("ma_v2_traps -> send standard trap: testTrapv21",[]), 4488 snmpa:send_trap(MA, testTrapv21, "standard trap"), 4489 ?line ?expect2(v2trap, [{[sysUpTime, 0], any}, 4490 {[snmpTrapOID, 0], ?snmp ++ [1]}]), 4491 ok. 4492 4493ma_v2_trap2(MA) -> 4494 snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), 4495 ?line ?expect2(v2trap, [{[sysUpTime, 0], any}, 4496 {[snmpTrapOID, 0], ?system ++ [0,1]}, 4497 {[system, [4,0]], "pelle"}]). 4498 4499%% Note: This test case takes a while... actually a couple of minutes. 4500ma_v2_inform1(MA) -> 4501 ?DBG("ma_v2_inform1 -> entry with" 4502 "~n MA = ~p => " 4503 "~n send notification: testTrapv22", [MA]), 4504 4505 CmdExpectInform = 4506 fun(_No, Response) -> 4507 ?expect2({inform, Response}, 4508 [{[sysUpTime, 0], any}, 4509 {[snmpTrapOID, 0], ?system ++ [0,1]}]) 4510 end, 4511 4512 CmdExp = 4513 fun(ok) -> 4514 ok; 4515 ({ok, _Val}) -> 4516 ?DBG("ma_v2_inform -> [cmd2] Val: ~p", [_Val]), 4517 ok; 4518 ({error, Id, Extra}) -> 4519 {error, {unexpected, Id, Extra}}; 4520 (Error) -> 4521 Error 4522 end, 4523 4524 Cmd01 = 4525 fun() -> 4526 snmpa:send_notification(MA, testTrapv22, no_receiver, 4527 "standard inform", []), 4528 ok 4529 end, 4530 Cmd02 = 4531 fun() -> 4532 Res = CmdExpectInform(1, true), 4533 CmdExp(Res) 4534 end, 4535 4536 Tag03 = tag11, 4537 Cmd03 = 4538 fun() -> 4539 snmpa:send_notification(MA, testTrapv22, {Tag03, self()}, 4540 "standard inform", []), 4541 ok 4542 end, 4543 Cmd04 = 4544 fun() -> 4545 Res = CmdExpectInform(2, true), 4546 CmdExp(Res) 4547 end, 4548 CmdSnmpTargets = 4549 fun(T) -> 4550 receive 4551 {snmp_targets, T, [_Addr]} -> 4552 ?DBG("ma_v2_inform1 -> " 4553 "received expected snmp_targets " 4554 "~n with receiver: ~p", [_Addr]), 4555 ok; 4556 {snmp_targets, T, Addrs} -> 4557 ?EPRINT("ma_v2_inform1 -> " 4558 "received unexpected snmp_targets" 4559 "~n with receivers: ~n ~p",[Addrs]), 4560 {error, {bad_addrs, Addrs}} 4561 after 4562 5000 -> 4563 ?EPRINT("ma_v2_inform1 -> " 4564 "timeout awaiting snmp_targets [~w]",[T]), 4565 {error, snmp_targets_timeout} 4566 end 4567 end, 4568 Cmd05 = fun() -> CmdSnmpTargets(Tag03) end, 4569 Cmd06 = 4570 fun() -> 4571 receive 4572 {snmp_notification, Tag03, {got_response, _Addr}} -> 4573 ?DBG("ma_v2_inform1 -> " 4574 "received expected snmp_notification " 4575 "[with manager response] from: ~n ~p", [_Addr]), 4576 ok; 4577 {snmp_notification, Tag03, {no_response, _Addr}} -> 4578 ?EPRINT("ma_v2_inform1 -> " 4579 "received unexpected snmp_notification " 4580 "[without manager response] from: ~n ~p", 4581 [_Addr]), 4582 {error, no_response} 4583 after 4584 20000 -> 4585 ?EPRINT("ma_v2_inform1 -> " 4586 "timeout awaiting snmp_notification [~p]", 4587 [Tag03]), 4588 {error, snmp_notification_timeout} 4589 end 4590 end, 4591 4592 Tag07 = tag12, 4593 Cmd07 = 4594 fun() -> 4595 snmpa:send_notification(MA, testTrapv22, {Tag07, self()}, 4596 "standard inform", []), 4597 ok 4598 end, 4599 Cmd08 = 4600 fun() -> 4601 Res = CmdExpectInform(3, false), 4602 CmdExp(Res) 4603 end, 4604 Cmd09 = 4605 fun() -> 4606 CmdSnmpTargets(Tag07) 4607 end, 4608 Cmd10 = 4609 fun() -> 4610 receive 4611 {snmp_notification, Tag07, {got_response, _Addr}} -> 4612 ?EPRINT("ma_v2_inform1 -> " 4613 "received unexpected snmp_notification " 4614 "[with manager response] from: ~n ~p", [_Addr]), 4615 {error, got_response}; 4616 {snmp_notification, Tag07, {no_response, _Addr}} -> 4617 ?DBG("ma_v2_inform1 -> " 4618 "received expected snmp_notification " 4619 "[without manager response] from: ~n ~p", 4620 [_Addr]), 4621 ok 4622 after 4623 240000 -> 4624 ?EPRINT("ma_v2_inform1 -> " 4625 "timeout awaiting snmp_notification [~p]", 4626 [Tag07]), 4627 {error, snmp_notification_timeout} 4628 end 4629 end, 4630 4631 Commands = 4632 [ 4633 { 1, "Send notification [no receiver]", Cmd01}, 4634 { 2, "Expect inform [send response]", Cmd02}, 4635 { 3, "Send notification [tag1]", Cmd03}, 4636 { 4, "Expect inform [send response]", Cmd04}, 4637 { 5, "Expect snmp_targets message [from trap sender]", Cmd05}, 4638 { 6, "Expect snmp_notification [got_response] message [from trap sender]", Cmd06}, 4639 { 7, "Send notification [tag2]", Cmd07}, 4640 { 8, "Expect inform [don't send response]", Cmd08}, 4641 { 9, "Expect snmp_targets message [from trap sender]", Cmd09}, 4642 {10, "Expect snmp_notification [no_response] message [from trap sender]", Cmd10} 4643 ], 4644 4645 command_handler(Commands). 4646 4647 4648%% Note: This test case takes a while... actually a couple of minutes. 4649ma_v2_inform2(MA) -> 4650 ?DBG("ma_v2_inform2 -> entry with" 4651 "~n MA = ~p => " 4652 "~n send notification: testTrapv22", [MA]), 4653 4654 CmdExpectInform = 4655 fun(_No, Response) -> 4656 ?expect2({inform, Response}, 4657 [{[sysUpTime, 0], any}, 4658 {[snmpTrapOID, 0], ?system ++ [0,1]}]) 4659 end, 4660 4661 CmdExp = 4662 fun(ok) -> 4663 ok; 4664 ({ok, _Val}) -> 4665 ?DBG("ma_v2_inform -> [cmd2] Val: ~p", [_Val]), 4666 ok; 4667 ({error, Id, Extra}) -> 4668 {error, {unexpected, Id, Extra}}; 4669 (Error) -> 4670 Error 4671 end, 4672 4673 %% Await callback(s) 4674 CmdAwaitDeliveryCallback = 4675 fun(Kind, Ref, Tag) -> 4676 ?IPRINT("CmdAwaitDeliveryCallback -> entry with" 4677 "~n Kind: ~p" 4678 "~n Ref: ~p" 4679 "~n Tag: ~p", [Kind, Ref, Tag]), 4680 receive 4681 {Kind, Ref, ok} -> 4682 ?IPRINT("CmdAwaitDeliveryCallback(~p,~p) -> " 4683 "received expected result: ok" 4684 "~n", [Tag, Ref]), 4685 ok; 4686 {Kind, Ref, Error} -> 4687 ?IPRINT("CmdAwaitDeliveryCallback(~p,~p) -> " 4688 "received unexpected result: " 4689 "~n Error: ~p" 4690 "~n", [Tag, Ref, Error]), 4691 {error, {unexpected_response, Error}} 4692 after 4693 240000 -> 4694 ?EPRINT("ma_v2_inform2 -> " 4695 "timeout awaiting got_response for " 4696 "snmp_notification [~p]", 4697 [Tag]), 4698 {error, snmp_notification_timeout} 4699 end 4700 end, 4701 4702 Tag11 = tag21, 4703 Ref11 = make_ref(), 4704 Extra11 = [{tag, Tag11}, 4705 {ref, Ref11}, 4706 {recv, self()}, 4707 {targets, []}, 4708 {address, dummy}, 4709 {expected_delivery_result, got_response}], 4710 Recv11 = #snmpa_notification_delivery_info{tag = Tag11, 4711 mod = ?MODULE, 4712 extra = Extra11}, 4713 Cmd11 = 4714 fun() -> 4715 snmpa:send_notification(MA, testTrapv22, 4716 Recv11, 4717 "standard inform", []), 4718 ok 4719 end, 4720 Cmd12 = 4721 fun() -> 4722 Res = CmdExpectInform(4, true), 4723 CmdExp(Res) 4724 end, 4725 4726 Cmd13 = fun() -> CmdAwaitDeliveryCallback(targets, Ref11, Tag11) end, 4727 Cmd14 = fun() -> CmdAwaitDeliveryCallback(info, Ref11, Tag11) end, 4728 4729 Commands = 4730 [ 4731 {11, "Send notification [tag3]", Cmd11}, 4732 {12, "Expect notification message [tag3]", Cmd12}, 4733 {13, "Expect targets message [tag3]", Cmd13}, 4734 {14, "Expect notification response message [tag3]", Cmd14} 4735 ], 4736 4737 command_handler(Commands). 4738 4739 4740%% Note: This test case takes a while... actually a couple of minutes. 4741ma_v2_inform3(MA) -> 4742 ?DBG("ma_v2_inform3 -> entry with" 4743 "~n MA = ~p => " 4744 "~n send notification: testTrapv22", [MA]), 4745 4746 CmdExpectInform = 4747 fun(_No, Response) -> 4748 ?DBG("CmdExpectInform -> ~p: ~n~p", [_No, Response]), 4749 ?expect2({inform, Response}, 4750 [{[sysUpTime, 0], any}, 4751 {[snmpTrapOID, 0], ?system ++ [0,1]}]) 4752 end, 4753 4754 CmdExp = 4755 fun(ok) -> 4756 ok; 4757 ({ok, _Val}) -> 4758 ?DBG("CmdExp -> Val: ~p", [_Val]), 4759 ok; 4760 ({error, Id, Extra}) -> 4761 {error, {unexpected, Id, Extra}}; 4762 (Error) -> 4763 Error 4764 end, 4765 4766 %% Await callback(s) 4767 CmdAwaitDeliveryCallback = 4768 fun(Kind, Ref, Tag) -> 4769 ?IPRINT("CmdAwaitDeliveryCallback -> entry with" 4770 "~n Kind: ~p" 4771 "~n Ref: ~p" 4772 "~n Tag: ~p", [Kind, Ref, Tag]), 4773 receive 4774 {Kind, Ref, ok} -> 4775 ?IPRINT("CmdAwaitDeliveryCallback(~p,~p) -> " 4776 "received expected result: ok" 4777 "~n", [Tag, Ref]), 4778 ok; 4779 {Kind, Ref, Error} -> 4780 ?IPRINT("CmdAwaitDeliveryCallback(~p,~p) -> " 4781 "received unexpected result: " 4782 "~n Error: ~p" 4783 "~n", [Tag, Ref, Error]), 4784 {error, {unexpected_response, Error}} 4785 after 4786 240000 -> 4787 ?EPRINT("ma_v2_inform3 -> " 4788 "timeout awaiting got_response for " 4789 "snmp_notification [~p]", 4790 [Tag]), 4791 {error, snmp_notification_timeout} 4792 end 4793 end, 4794 4795 Tag15 = tag31, 4796 Ref15 = make_ref(), 4797 Extra15 = [{tag, Tag15}, 4798 {ref, Ref15}, 4799 {recv, self()}, 4800 {targets, []}, 4801 {address, dummy}, 4802 {expected_delivery_result, no_response}], 4803 Recv15 = #snmpa_notification_delivery_info{tag = Tag15, 4804 mod = ?MODULE, 4805 extra = Extra15}, 4806 Cmd15 = 4807 fun() -> 4808 snmpa:send_notification(MA, testTrapv22, 4809 Recv15, 4810 "standard inform", []), 4811 ok 4812 end, 4813 Cmd16 = 4814 fun() -> 4815 Res = CmdExpectInform(5, false), 4816 CmdExp(Res) 4817 end, 4818 4819 Cmd17 = fun() -> CmdAwaitDeliveryCallback(targets, Ref15, Tag15) end, 4820 Cmd18 = fun() -> CmdAwaitDeliveryCallback(info, Ref15, Tag15) end, 4821 4822 Commands = 4823 [ 4824 {15, "Send notification [" ++ atom_to_list(Tag15) ++ "]", Cmd15}, 4825 {16, "Expect notification message [" ++ atom_to_list(Tag15) ++ "]", Cmd16}, 4826 {17, "Expect targets message [" ++ atom_to_list(Tag15) ++ "]", Cmd17}, 4827 {18, "Expect notification (no) response message [" ++ atom_to_list(Tag15) ++ "]", Cmd18} 4828 ], 4829 4830 command_handler(Commands). 4831 4832 4833%% snmpa_notification_delivery_info_receiver callback function 4834delivery_targets(Tag, Addresses, Extra) -> 4835 io:format("~w:delivery_targets -> entry with" 4836 "~n Tag: ~p" 4837 "~n Addresses: ~p" 4838 "~n Extra: ~p" 4839 "~n", [?MODULE, Tag, Addresses, Extra]), 4840 {value, {_, Pid}} = lists:keysearch(recv, 1, Extra), 4841 {value, {_, Ref}} = lists:keysearch(ref, 1, Extra), 4842 case lists:keysearch(tag, 1, Extra) of 4843 {value, {_, Tag}} -> 4844 Pid ! {targets, Ref, ok}; 4845 {value, {_, OtherTag}} -> 4846 Pid ! {targets, Ref, {error, {wrong_tag, Tag, OtherTag}}} 4847 end, 4848 ok. 4849 4850%% snmpa_notification_delivery_info_receiver callback function 4851delivery_info(Tag, Address, DeliveryResult, Extra) -> 4852 io:format("~w:delivery_info -> entry with" 4853 "~n Tag: ~p" 4854 "~n Address: ~p" 4855 "~n DeliveryResult: ~p" 4856 "~n Extra: ~p" 4857 "~n", [?MODULE, Tag, Address, DeliveryResult, Extra]), 4858 {value, {_, Pid}} = lists:keysearch(recv, 1, Extra), 4859 {value, {_, Ref}} = lists:keysearch(ref, 1, Extra), 4860 case lists:keysearch(tag, 1, Extra) of 4861 {value, {_, Tag}} -> 4862 Pid ! {info, Ref, ok}; 4863 {value, {_, OtherTag}} -> 4864 Pid ! {info, Ref, {error, {wrong_tag, Tag, OtherTag}}} 4865 end, 4866 ok. 4867 4868 4869command_handler([]) -> 4870 ok; 4871command_handler([{_No, _Desc, Cmd}|Rest]) -> 4872 ?IPRINT("command_handler -> command ~w: ~n ~s", [_No, _Desc]), 4873 case (catch Cmd()) of 4874 ok -> 4875 ?IPRINT("command_handler -> ~w: ok", [_No]), 4876 command_handler(Rest); 4877 {error, Reason} -> 4878 ?EPRINT("command_handler -> ~w error: ~n~p", [_No, Reason]), 4879 ?line ?FAIL(Reason); 4880 Error -> 4881 ?EPRINT("command_handler -> ~w unexpected: ~n~p", [_No, Error]), 4882 ?line ?FAIL({unexpected_command_result, Error}) 4883 end. 4884 4885 4886ma_v1_2_v2_trap(MA) -> 4887 snmpa:send_trap(MA,linkDown,"standard trap",[{ifIndex, [1], 1}]), 4888 ?line ?expect2(v2trap, [{[sysUpTime, 0], any}, 4889 {[snmpTrapOID, 0], ?snmpTraps ++ [3]}, 4890 {[ifIndex, 1], 1}, 4891 {[snmpTrapEnterprise, 0], [1,2,3]}]). 4892 4893 4894ma_v1_2_v2_trap2(MA) -> 4895 snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), 4896 ?line ?expect2(v2trap, [{[sysUpTime, 0], any}, 4897 {[snmpTrapOID, 0], ?system ++ [0,1]}, 4898 {[system, [4,0]], "pelle"}, 4899 {[snmpTrapEnterprise, 0], ?system}]). 4900 4901 4902sa_v1_2_v2_trap1(SA) -> 4903 snmpa:verbosity(SA, {subagents, trace}), 4904 snmpa:send_trap(SA, saTrap, "standard trap"), 4905 ?line ?expect2(v2trap, [{[sysUpTime, 0], any}, 4906 {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, 4907 {[system, [4,0]], 4908 "{mbj,eklas}@erlang.ericsson.se"}, 4909 {[sa, [1,0]], "sa_test"}, 4910 {[snmpTrapEnterprise, 0], ?ericsson}]), 4911 snmpa:verbosity(SA, {subagents, silence}), 4912 ok. 4913 4914sa_v1_2_v2_trap2(SA) -> 4915 snmpa:verbosity(SA, {subagents, trace}), 4916 snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), 4917 ?line ?expect2(v2trap, [{[sysUpTime, 0], any}, 4918 {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, 4919 {[system, [4,0]], "pelle"}, 4920 {[sa, [1,0]], "sa_test"}, 4921 {[snmpTrapEnterprise, 0], ?ericsson}]), 4922 snmpa:verbosity(SA, {subagents, silence}), 4923 ok. 4924 4925 4926sa_v1_2_v2_trap3(SA) -> 4927 snmpa:verbosity(SA, {subagents, trace}), 4928 snmpa:send_trap(SA, saTrap2, "standard trap", 4929 [{intViewSubtree, [4], [1,2,3,4]}]), 4930 ?line ?expect2(v2trap, [{[sysUpTime, 0], any}, 4931 {[snmpTrapOID, 0], ?ericsson ++ [0, 2]}, 4932 {[system, [4,0]], 4933 "{mbj,eklas}@erlang.ericsson.se"}, 4934 {[sa, [1,0]], "sa_test"}, 4935 {[intViewSubtree,4],[1,2,3,4]}, 4936 {[snmpTrapEnterprise, 0], ?ericsson}]), 4937 snmpa:verbosity(SA, {subagents, silence}), 4938 ok. 4939 4940 4941%% Req. SA-MIB, OLD-SNMPEA-MIB 4942sa_errs_bad_value() -> 4943 NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], 4944 NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], 4945 NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], 4946 s([{NewKeyc3, 2}, 4947 {[sa, [2,0]], 5}, % badValue (i is_set_ok) 4948 {NewKeyc5, ?createAndGo}, 4949 {NewKeyc4, 2}]), 4950 ?line ?expect3(badValue, 2, any), 4951 s([{NewKeyc3, 2}, 4952 {[sa, [2,0]], 6}, % wrongValue (i is_set_ok) 4953 {NewKeyc5, ?createAndGo}, 4954 {NewKeyc4, 2}]), 4955 ?line ?expect3(?v1_2(badValue, wrongValue), 2, any), 4956 g([NewKeyc4]), 4957 ?line ?v1_2(?expect3(noSuchName, 1, any), 4958 ?expect1([{NewKeyc4, noSuchInstance}])). 4959 4960%% Req. SA-MIB, OLD-SNMPEA-MIB 4961sa_errs_gen_err() -> 4962 NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], 4963 NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], 4964 NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], 4965 s([{NewKeyc3, 2},{NewKeyc4, 2}, 4966 {NewKeyc5, ?createAndGo}, {[sa, [3,0]], 5}]), 4967 ?line ?expect3(genErr, 4, any), 4968% The row might have been added; we don't know. 4969% (as a matter of fact we do - it is added, because the agent 4970% first sets its own vars, and then th SAs. Lets destroy it. 4971 s([{NewKeyc5, ?destroy}]), 4972 ?line ?expect1([{NewKeyc5, ?destroy}]). 4973 4974%% Req. SA-MIB, OLD-SNMPEA-MIB 4975sa_too_big() -> 4976 g([[sa, [4,0]]]), 4977 ?line ?expect1(tooBig). 4978 4979%% Req. Klas1, system group, snmp group (v1/v2) 4980next_across_sa_test() -> 4981 gn([[sysDescr],[klas1,5]]), 4982 ?line ?expect1([{[sysDescr,0], "Erlang SNMP agent"}, 4983 {[snmpInPkts, 0], any}]). 4984 4985%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]). -> noError 4986%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]). -> {badValue, 2} 4987%% snmp_test_mgr:s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]). -> {genErr, 1} 4988%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]). -> {genErr, 1} 4989%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]). -> {genErr, 1} 4990%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]). -> {genErr, 2} 4991%% Req. Klas3, Klas4 4992undo_test() -> 4993 s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), 4994 ?line ?expect1([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), 4995 s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]), 4996 ?line ?expect3(?v1_2(badValue, inconsistentValue), 2, any), 4997 s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]), 4998 ?line ?expect3(?v1_2(genErr, undoFailed), 1, any), 4999 s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]), 5000 ?line ?expect3(?v1_2(genErr, commitFailed), 1, any), 5001% unfortunatly we don't know if we'll get undoFailed or commitFailed. 5002% it depends on which order the agent traverses the varbind list. 5003% s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]), 5004% ?line expect(5, ?v1_2(genErr, undoFailed), 1, any), 5005 s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]), 5006 ?line ?expect3(genErr, 2, any). 5007 5008%% Req. Klas3, Klas4 5009bad_return() -> 5010 g([[fStatus4,4], 5011 [fName4,4]]), 5012 ?line ?expect3(genErr, 2, any), 5013 g([[fStatus4,5], 5014 [fName4,5]]), 5015 ?line ?expect3(genErr, 1, any), 5016 g([[fStatus4,6], 5017 [fName4,6]]), 5018 ?line ?expect3(genErr, 2, any), 5019 gn([[fStatus4,7], 5020 [fName4,7]]), 5021 ?line ?expect3(genErr, 2, any), 5022 gn([[fStatus4,8], 5023 [fName4,8]]), 5024 ?line ?expect3(genErr, 1, any), 5025 gn([[fStatus4,9], 5026 [fName4,9]]), 5027 ?line ?expect3(genErr, 2, any). 5028 5029 5030%%%----------------------------------------------------------------- 5031%%% Test the implementation of standard mibs. 5032%%% We should *at least* try to GET all variables, just to make 5033%%% sure the instrumentation functions work. 5034%%% Note that many of the functions in the standard mib is 5035%%% already tested by the normal tests. 5036%%%----------------------------------------------------------------- 5037 5038standard_mibs_cases() -> 5039 [ 5040 snmp_standard_mib, 5041 snmp_community_mib, 5042 snmp_framework_mib, 5043 snmp_target_mib, 5044 snmp_notification_mib, 5045 snmp_view_based_acm_mib 5046 ]. 5047 5048standard_mibs_cases_ipv6() -> 5049 [ 5050 %% snmp_standard_mib, % Sending v1 traps does not work over IPv6 5051 snmp_community_mib, 5052 snmp_framework_mib, 5053 snmp_target_mib, 5054 snmp_notification_mib, 5055 snmp_view_based_acm_mib 5056 ]. 5057 5058%%----------------------------------------------------------------- 5059%% For this test, the agent is configured for v1. 5060%% o Test the counters and control objects in SNMP-STANDARD-MIB 5061%%----------------------------------------------------------------- 5062snmp_standard_mib(suite) -> []; 5063snmp_standard_mib(Config) when is_list(Config) -> 5064 ?P(snmp_standard_mib), 5065 init_case(Config), 5066 ?DBG("snmp_standard_mib -> std_mib_init", []), 5067 try_test(std_mib_init), 5068 5069 ?DBG("snmp_standard_mib -> std_mib_a", []), 5070 InBadVsns = try_test(std_mib_a), 5071 put(vsn, v2), 5072 ?DBG("snmp_standard_mib -> std_mib_read", []), 5073 try_test(std_mib_read), 5074 put(vsn, v1), 5075 5076 ?DBG("snmp_standard_mib -> std_mib_b (~w)", [InBadVsns]), 5077 Bad = try_test(std_mib_b, [InBadVsns]), 5078 ?DBG("snmp_standard_mib -> std_mib_read (community: 'bad community')", []), 5079 try_test(std_mib_read, [], [{community, "bad community"}]), 5080 ?DBG("snmp_standard_mib -> std_mib_write (community: 'public')", []), 5081 try_test(std_mib_write, [], [{community, "public"}]), 5082 ?DBG("snmp_standard_mib -> std_mib_asn_err", []), 5083 try_test(std_mib_asn_err), 5084 ?DBG("snmp_standard_mib -> std_mib_c (~w)", [Bad]), 5085 try_test(std_mib_c, [Bad]), 5086 ?DBG("snmp_standard_mib -> std_mib_a", []), 5087 try_test(standard_mib_a), 5088 5089 ?DBG("snmp_standard_mib -> std_mib_finish", []), 5090 try_test(std_mib_finish), 5091 ?DBG("snmp_standard_mib -> std_mib_test_finish", []), 5092 try_test(standard_mib_test_finish, [], [{community, "bad community"}]). 5093 5094%% Req. SNMP-STANDARD-MIB 5095standard_mib_a() -> 5096 ?line [OutPkts] = get_req(2, [[snmpOutPkts,0]]), 5097 ?line [OutPkts2] = get_req(3, [[snmpOutPkts,0]]), 5098 ?line OutPkts2 = OutPkts + 1, 5099 %% There are some more counters we could test here, but it's not that 5100 %% important, since they are removed from SNMPv2-MIB. 5101 ok. 5102 5103%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB 5104std_mib_init() -> 5105 %% disable authentication failure traps. (otherwise w'd get many of 5106 %% them - this is also a test to see that it works). 5107 s([{[snmpEnableAuthenTraps,0], 2}]), 5108 ?line ?expect1([{[snmpEnableAuthenTraps, 0], 2}]). 5109 5110%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB 5111std_mib_finish() -> 5112 %% enable again 5113 s([{[snmpEnableAuthenTraps,0], 1}]), 5114 ?line ?expect1([{[snmpEnableAuthenTraps, 0], 1}]). 5115 5116%% Req. SNMP-STANDARD-MIB 5117standard_mib_test_finish() -> 5118 %% force a authenticationFailure (should result in a trap) 5119 std_mib_write(), 5120 %% check that we got a trap 5121 ?line ?expect5(trap, [1,2,3], 4, 0, []). 5122 5123%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB 5124std_mib_read() -> 5125 ?DBG("std_mib_read -> entry", []), 5126 g([[sysUpTime,0]]), % try a bad <something>; msg dropped, no reply 5127 ?DBG("std_mib_read -> await timeout (i.e. no reply)", []), 5128 ?line ?expect1(timeout). % make sure we don't get a trap! 5129 5130 5131%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB 5132std_mib_write() -> 5133 ?DBG("std_mib_write -> entry", []), 5134 s([{[sysLocation, 0], "new_value"}]). 5135 5136%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB 5137std_mib_asn_err() -> 5138 snmp_test_mgr:send_bytes([48,99,67,12,0,0,0,0,0,0,5]). 5139 5140 5141standard_mibs2_cases() -> 5142 [ 5143 snmpv2_mib_2, 5144 snmp_community_mib_2, 5145 snmp_framework_mib_2, 5146 snmp_target_mib_2, 5147 snmp_notification_mib_2, 5148 snmp_view_based_acm_mib_2 5149 ]. 5150 5151 5152%%----------------------------------------------------------------- 5153%% For this test, the agent is configured for v2 and v3. 5154%% o Test the counters and control objects in SNMPv2-MIB 5155%%----------------------------------------------------------------- 5156snmpv2_mib_2(suite) -> []; 5157snmpv2_mib_2(Config) when is_list(Config) -> 5158 ?P(snmpv2_mib_2), 5159 ?IPRINT("snmpv2_mib_2 -> start"), 5160 init_case(Config), 5161 5162 ?DBG("snmpv2_mib_2 -> standard mib init",[]), 5163 try_test(std_mib_init), 5164 5165 ?DBG("snmpv2_mib_2 -> get number of (so far) bad versions",[]), 5166 InBadVsns = try_test(std_mib_a), 5167 5168 ?DBG("snmpv2_mib_2 -> make a bad version read",[]), 5169 put(vsn, v1), 5170 try_test(std_mib_read), 5171 5172 ?DBG("snmpv2_mib_2 -> bad version read",[]), 5173 put(vsn, v2), 5174 Bad = try_test(std_mib_b, [InBadVsns]), 5175 5176 ?DBG("snmpv2_mib_2 -> read with bad community",[]), 5177 try_test(std_mib_read, [], [{community, "bad community"}]), 5178 5179 ?DBG("snmpv2_mib_2 -> write with public community",[]), 5180 try_test(std_mib_write, [], [{community, "public"}]), 5181 5182 ?DBG("snmpv2_mib_2 -> asn err",[]), 5183 try_test(std_mib_asn_err), 5184 5185 ?DBG("snmpv2_mib_2 -> check counters",[]), 5186 try_test(std_mib_c, [Bad]), 5187 5188 ?DBG("snmpv2_mib_2 -> get som counters",[]), 5189 try_test(snmpv2_mib_a), 5190 5191 ?DBG("snmpv2_mib_2 -> enable auth traps, and await some",[]), 5192 try_test(std_mib_finish), 5193 5194 ?DBG("snmpv2_mib_2 -> force auth failure, and await trap, " 5195 "then disable auth traps",[]), 5196 try_test(snmpv2_mib_test_finish, [], [{community, "bad community"}]), 5197 5198 ?IPRINT("snmpv2_mib_2 -> done"), 5199 ok. 5200 5201 5202standard_mibs3_cases() -> 5203 [ 5204 snmpv2_mib_3, 5205 snmp_framework_mib_3, 5206 snmp_mpd_mib_3, 5207 snmp_target_mib_3, 5208 snmp_notification_mib_3, 5209 snmp_view_based_acm_mib_3, 5210 snmp_user_based_sm_mib_3 5211 ]. 5212 5213 5214%% Req. SNMPv2-MIB 5215snmpv2_mib_3(suite) -> []; 5216snmpv2_mib_3(Config) when is_list(Config) -> 5217 %% <CONDITIONAL-SKIP> 5218 Skippable = [{unix, [darwin]}], 5219 Condition = fun() -> ?OS_BASED_SKIP(Skippable) end, 5220 ?NON_PC_TC_MAYBE_SKIP(Config, Condition), 5221 %% </CONDITIONAL-SKIP> 5222 5223 ?P(snmpv2_mib_3), 5224 init_case(Config), 5225 5226 InBadVsns = try_test(std_mib_a), 5227 put(vsn, v1), 5228 try_test(std_mib_read), 5229 put(vsn, v3), 5230 _Bad = try_test(std_mib_b, [InBadVsns]), 5231 try_test(snmpv2_mib_a), 5232 5233 try_test(std_mib_finish). 5234 5235-define(authenticationFailure, [1,3,6,1,6,3,1,1,5,5]). 5236 5237%% Req. SNMPv2-MIB 5238snmpv2_mib_test_finish() -> 5239 %% force a authenticationFailure 5240 ?DBG("ma_v2_inform -> write to std mib",[]), 5241 std_mib_write(), 5242 5243 %% check that we got a trap 5244 ?DBG("ma_v2_inform -> await trap",[]), 5245 ?line ?expect2(v2trap, [{[sysUpTime,0], any}, 5246 {[snmpTrapOID,0], ?authenticationFailure}]), 5247 5248 %% and the the inform 5249 ?DBG("ma_v2_inform -> await inform",[]), 5250 ?line ?expect2({inform,true}, [{[sysUpTime,0], any}, 5251 {[snmpTrapOID,0],?authenticationFailure}]). 5252 5253%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB 5254std_mib_a() -> 5255 ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), 5256 ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), 5257 ?line InPkts2 = InPkts + 1, 5258 5259 ?line [InBadVsns] = get_req(4, [[snmpInBadVersions,0]]), 5260 InBadVsns. 5261 5262%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB 5263std_mib_b(InBadVsns) -> 5264 ?line [InBadVsns2] = get_req(1, [[snmpInBadVersions,0]]), 5265 ?line InBadVsns2 = InBadVsns + 1, 5266 ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), 5267 ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), 5268 ?line InPkts2 = InPkts + 1, 5269 ?line [InBadCommunityNames, InBadCommunityUses, InASNErrs] = 5270 get_req(4, [[snmpInBadCommunityNames,0], 5271 [snmpInBadCommunityUses,0], 5272 [snmpInASNParseErrs, 0]]), 5273 {InBadCommunityNames, InBadCommunityUses, InASNErrs}. 5274 5275%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB 5276std_mib_c({InBadCommunityNames, InBadCommunityUses, InASNErrs}) -> 5277 ?line [InBadCommunityNames2, InBadCommunityUses2, InASNErrs2] = 5278 get_req(1, [[snmpInBadCommunityNames,0], 5279 [snmpInBadCommunityUses,0], 5280 [snmpInASNParseErrs, 0]]), 5281 ?line InBadCommunityNames2 = InBadCommunityNames + 1, 5282 ?line InBadCommunityUses2 = InBadCommunityUses + 1, 5283 ?line InASNErrs2 = InASNErrs + 1. 5284 5285%% Req. SNMPv2-MIB 5286snmpv2_mib_a() -> 5287 ?line [SetSerial] = get_req(2, [[snmpSetSerialNo,0]]), 5288 s([{[snmpSetSerialNo,0], SetSerial}, {[sysLocation, 0], "val2"}]), 5289 ?line ?expect1([{[snmpSetSerialNo,0], SetSerial}, 5290 {[sysLocation, 0], "val2"}]), 5291 s([{[sysLocation, 0], "val3"}, {[snmpSetSerialNo,0], SetSerial}]), 5292 ?line ?expect3(inconsistentValue, 2, 5293 [{[sysLocation, 0], "val3"}, 5294 {[snmpSetSerialNo,0], SetSerial}]), 5295 ?line ["val2"] = get_req(5, [[sysLocation,0]]), 5296 ok. 5297 5298 5299%%----------------------------------------------------------------- 5300%% o Bad community uses/name is tested already 5301%% in SNMPv2-MIB and STANDARD-MIB. 5302%% o Test add/deletion of rows. 5303%%----------------------------------------------------------------- 5304snmp_community_mib(suite) -> []; 5305snmp_community_mib(Config) when is_list(Config) -> 5306 ?P(snmp_community_mib), 5307 init_case(Config), 5308 ?line load_master_std("SNMP-COMMUNITY-MIB"), 5309 try_test(snmp_community_mib_test), 5310 ?line unload_master("SNMP-COMMUNITY-MIB"). 5311 5312snmp_community_mib_2(X) -> ?P(snmp_community_mib_2), snmp_community_mib(X). 5313 5314%% Req. SNMP-COMMUNITY-MIB 5315snmp_community_mib_test() -> 5316 ?NPRINT("NOT YET IMPLEMENTED"), 5317 nyi. 5318 5319 5320%%----------------------------------------------------------------- 5321%% o Test engine boots / time 5322%%----------------------------------------------------------------- 5323snmp_framework_mib(suite) -> []; 5324snmp_framework_mib(Config) when is_list(Config) -> 5325 ?P(snmp_framework_mib), 5326 init_case(Config), 5327 ?line load_master_std("SNMP-FRAMEWORK-MIB"), 5328 try_test(snmp_framework_mib_test), 5329 ?line unload_master("SNMP-FRAMEWORK-MIB"). 5330 5331snmp_framework_mib_2(X) -> ?P(snmp_framework_mib_2), snmp_framework_mib(X). 5332 5333snmp_framework_mib_3(suite) -> []; 5334snmp_framework_mib_3(Config) when is_list(Config) -> 5335 ?P(snmp_framework_mib_3), 5336 init_case(Config), 5337 try_test(snmp_framework_mib_test). 5338 5339 5340%% Req. SNMP-FRAMEWORK-MIB 5341%% snmpEngineID in number of seconds. 5342%% In theory, the Engine Time diff of the engine, should be exactly 5343%% the same as the number of seconds we sleep (5 in this case). 5344%% But because, on some (slow or/and high loaded) hosts, the actual 5345%% time we sleep could be a lot larger (due to, for instance, scheduling). 5346%% Therefor we must take that into account when we check if the 5347%% Engine Time diff (between the two checks) is acceptably. 5348snmp_framework_mib_test() -> 5349 Sleep = 5, 5350 ?line ["agentEngine"] = get_req(1, [[snmpEngineID,0]]), 5351 T1 = snmp_misc:now(ms), 5352 ?line [EngineTime] = get_req(2, [[snmpEngineTime,0]]), 5353 T2 = snmp_misc:now(ms), 5354 ?SLEEP(?SECS(Sleep)), 5355 T3 = snmp_misc:now(ms), 5356 ?line [EngineTime2] = get_req(3, [[snmpEngineTime,0]]), 5357 T4 = snmp_misc:now(ms), 5358 5359 %% Ok, we tried to sleep 5 seconds, but how long did we actually sleep 5360 ASleep = ((T3-T2) + 500) div 1000, 5361 EngineTimeDiff = EngineTime2 - EngineTime, 5362 HighEngineTime = EngineTime + ASleep + 2, 5363 LowEngineTime = EngineTime + ASleep - 1, 5364 5365 ?IPRINT("snmp_framework_mib -> time(s): " 5366 "~n EngineTime 1: ~p" 5367 "~n Time to acquire: ~w msec" 5368 "~n EngineTime 2: ~p" 5369 "~n Time to acquire: ~w msec" 5370 "~n => Total time to acquire: ~w msec" 5371 "~n Sleep between get(snmpEngineTime): ~w (~w) sec" 5372 "~n Engine Time Diff: ~w sec" 5373 "~n Success if:" 5374 "~n ~w (low) =< Engine Time 2 =< ~w (high)", 5375 [EngineTime, T2-T1, 5376 EngineTime2, T4-T3, 5377 T4-T1, ASleep, Sleep, EngineTimeDiff, LowEngineTime, HighEngineTime]), 5378 5379 if 5380 (HighEngineTime < EngineTime2) -> 5381 ?EPRINT("snmp_framework_mib -> (High) Engine Time diff (~w) too large: " 5382 "~n ~w < ~w", 5383 [EngineTimeDiff, HighEngineTime, EngineTime2]), 5384 ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); 5385 (LowEngineTime > EngineTime2) -> 5386 ?EPRINT("snmp_framework_mib -> (Low) Engine Time diff (~w) too large: " 5387 "~n ~w > ~w", 5388 [EngineTimeDiff, LowEngineTime, EngineTime2]), 5389 ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); 5390 true -> 5391 ok 5392 end, 5393 5394 T5 = snmp_misc:now(ms), 5395 ?line case get_req(4, [[snmpEngineBoots,0]]) of 5396 [Boots] when is_integer(Boots) -> 5397 T6 = snmp_misc:now(ms), 5398 ?IPRINT("snmp_framework_mib -> " 5399 "~n boots: ~p" 5400 "~n Time to acquire: ~w ms", [Boots, T6-T5]), 5401 ok; 5402 Else -> 5403 ?EPRINT("snmp_framework_mib -> failed get proper boots:" 5404 "~n ~p", [Else]), 5405 ?FAIL({invalid_boots, Else}) 5406 end, 5407 ok. 5408 5409%%----------------------------------------------------------------- 5410%% o Test the counters 5411%%----------------------------------------------------------------- 5412snmp_mpd_mib_3(suite) -> []; 5413snmp_mpd_mib_3(Config) when is_list(Config) -> 5414 %% <CONDITIONAL-SKIP> 5415 Skippable = [{unix, [darwin]}], 5416 Condition = fun() -> ?OS_BASED_SKIP(Skippable) end, 5417 ?NON_PC_TC_MAYBE_SKIP(Config, Condition), 5418 %% </CONDITIONAL-SKIP> 5419 5420 ?P(snmp_mpd_mib_3), 5421 init_case(Config), 5422 UnknownPDUHs = try_test(snmp_mpd_mib_a), 5423 try_test(snmp_mpd_mib_b, [], [{context_engine_id, "bad engine"}]), 5424 try_test(snmp_mpd_mib_c, [UnknownPDUHs]). 5425 5426 5427%% Req. SNMP-MPD-MIB 5428snmp_mpd_mib_a() -> 5429 ?line [UnknownSecs, InvalidMsgs] = 5430 get_req(1, [[snmpUnknownSecurityModels,0], 5431 [snmpInvalidMsgs,0]]), 5432 Pdu = #pdu{type = 'get-request', 5433 request_id = 23, 5434 error_status = noError, 5435 error_index = 0, 5436 varbinds = []}, 5437 SPdu = #scopedPdu{contextEngineID = "agentEngine", 5438 contextName = "", 5439 data = Pdu}, 5440 ?line SPDUBytes = snmp_pdus:enc_scoped_pdu(SPdu), 5441 V3Hdr1 = #v3_hdr{msgID = 21, 5442 msgMaxSize = 484, 5443 msgFlags = [7], 5444 msgSecurityModel = 23, % bad sec model 5445 msgSecurityParameters = []}, 5446 V3Hdr2 = #v3_hdr{msgID = 21, 5447 msgMaxSize = 484, 5448 msgFlags = [6], % bad flag combination 5449 msgSecurityModel = 3, 5450 msgSecurityParameters = []}, 5451 Message1 = #message{version = 'version-3', vsn_hdr = V3Hdr1, 5452 data = SPDUBytes}, 5453 Message2 = #message{version = 'version-3', vsn_hdr = V3Hdr2, 5454 data = SPDUBytes}, 5455 ?line MsgBytes1 = snmp_pdus:enc_message_only(Message1), 5456 ?line MsgBytes2 = snmp_pdus:enc_message_only(Message2), 5457 snmp_test_mgr:send_bytes(MsgBytes1), 5458 snmp_test_mgr:send_bytes(MsgBytes2), 5459 5460 ?line [UnknownSecs2, InvalidMsgs2, UnknownPDUHs] = 5461 get_req(1, [[snmpUnknownSecurityModels,0], 5462 [snmpInvalidMsgs,0], 5463 [snmpUnknownPDUHandlers, 0]]), 5464 ?line UnknownSecs2 = UnknownSecs + 1, 5465 ?line InvalidMsgs2 = InvalidMsgs + 1, 5466 UnknownPDUHs. 5467 5468-define(snmpUnknownPDUHandlers_instance, [1,3,6,1,6,3,11,2,1,3,0]). 5469snmp_mpd_mib_b() -> 5470 g([[sysUpTime,0]]), 5471 ?line ?expect2(report, [{?snmpUnknownPDUHandlers_instance, any}]). 5472 5473 5474snmp_mpd_mib_c(UnknownPDUHs) -> 5475 ?line [UnknownPDUHs2] = get_req(1, [[snmpUnknownPDUHandlers, 0]]), 5476 ?line UnknownPDUHs2 = UnknownPDUHs + 1, 5477 ok. 5478 5479 5480snmp_target_mib(suite) -> []; 5481snmp_target_mib(Config) when is_list(Config) -> 5482 ?P(snmp_target_mib), 5483 init_case(Config), 5484 ?line load_master_std("SNMP-TARGET-MIB"), 5485 try_test(snmp_target_mib_test), 5486 ?line unload_master("SNMP-TARGET-MIB"). 5487 5488snmp_target_mib_2(X) -> ?P(snmp_target_mib_2), snmp_target_mib(X). 5489 5490snmp_target_mib_3(X) -> ?P(snmp_target_mib_3), snmp_target_mib(X). 5491 5492snmp_target_mib_test() -> 5493 ?NPRINT("NOT YET IMPLEMENTED"), 5494 nyi. 5495 5496snmp_notification_mib(suite) -> []; 5497snmp_notification_mib(Config) when is_list(Config) -> 5498 ?P(snmp_notification_mib), 5499 init_case(Config), 5500 ?line load_master_std("SNMP-NOTIFICATION-MIB"), 5501 try_test(snmp_notification_mib_test), 5502 ?line unload_master("SNMP-NOTIFICATION-MIB"). 5503 5504snmp_notification_mib_2(X) -> ?P(snmp_notification_mib_2), 5505 snmp_notification_mib(X). 5506 5507snmp_notification_mib_3(X) -> ?P(snmp_notification_mib_3), 5508 snmp_notification_mib(X). 5509 5510snmp_notification_mib_test() -> 5511 ?NPRINT("NOT YET IMPLEMENTED"), 5512 nyi. 5513 5514 5515%%----------------------------------------------------------------- 5516%% o add/delete views and try them 5517%% o try boundaries 5518%%----------------------------------------------------------------- 5519snmp_view_based_acm_mib(suite) -> []; 5520snmp_view_based_acm_mib(Config) when is_list(Config) -> 5521 ?P(snmp_view_based_acm_mib), 5522 init_case(Config), 5523 5524 ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), 5525 ?line load_master("Test2"), 5526 snmp_view_based_acm_mib(), 5527 ?line unload_master("Test2"), 5528 ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). 5529 5530snmp_view_based_acm_mib_2(X) -> 5531 ?P(snmp_view_based_acm_mib_2), 5532 snmp_view_based_acm_mib(X). 5533 5534snmp_view_based_acm_mib_3(X) -> 5535 %% <CONDITIONAL-SKIP> 5536 Skippable = [{unix, [darwin]}], 5537 Condition = fun() -> ?OS_BASED_SKIP(Skippable) end, 5538 ?NON_PC_TC_MAYBE_SKIP(X, Condition), 5539 %% </CONDITIONAL-SKIP> 5540 5541 ?P(snmp_view_based_acm_mib_3), 5542 snmp_view_based_acm_mib(X). 5543 5544snmp_view_based_acm_mib() -> 5545 snmpa:verbosity(net_if,trace), 5546 snmpa:verbosity(master_agent,trace), 5547 ?IPRINT("start snmp_view_based_acm_mib test"), 5548 %% The user "no-rights" is present in USM, and is mapped to security 5549 %% name 'no-rights", which is not present in VACM. 5550 %% So, we'll add rights for it, try them and delete them. 5551 %% We'll give "no-rights" write access to tDescr.0 and read access 5552 %% to tDescr2.0 5553 %% These are the options we'll use to the mgr 5554 Opts = [{user, "no-rights"}, {community, "no-rights"}], 5555 %% Find the valid secmodel, and one invalid secmodel. 5556 {SecMod, InvSecMod} = 5557 case get(vsn) of 5558 v1 -> {?SEC_V1, ?SEC_V2C}; 5559 v2 -> {?SEC_V2C, ?SEC_USM}; 5560 v3 -> {?SEC_USM, ?SEC_V1} 5561 end, 5562 ?DBG("assign rights for 'no-rights'",[]), 5563 ?line try_test(use_no_rights, [], Opts), 5564 5565 %% Now, add a mapping from "no-rights" -> "no-rights-group" 5566 GRow1Status = [vacmSecurityToGroupStatus,[SecMod, 9,"no-rights"]], 5567 GRow1 = 5568 [{[vacmGroupName, [SecMod, 9,"no-rights"]], "no-rights-group"}, 5569 {GRow1Status, ?createAndGo}], 5570 ?DBG("set '~p'",[GRow1]), 5571 ?line try_test(do_set, [GRow1]), 5572 5573 ?DBG("assign rights for 'no-rights'",[]), 5574 ?line try_test(use_no_rights, [], Opts), 5575 5576 %% Create a mapping for another sec model, and make sure it dosn't 5577 %% give us access 5578 GRow2Status = [vacmSecurityToGroupStatus,[InvSecMod, 9,"no-rights"]], 5579 GRow2 = [{[vacmGroupName, [InvSecMod, 9, "no-rights"]], "initial"}, 5580 {GRow2Status, ?createAndGo}], 5581 5582 ?DBG("set '~p'",[GRow2]), 5583 ?line try_test(do_set, [GRow2]), 5584 5585 ?DBG("assign rights for 'no-rights'",[]), 5586 ?line try_test(use_no_rights, [], Opts), 5587 5588 %% Delete that row 5589 ?line try_test(del_row, [GRow2Status]), 5590 5591 RVName = "rv_name", 5592 WVName = "wv_name", 5593 5594 %% Access row 5595 ARow1Idx = [15 | "no-rights-group"] ++ [0, ?SEC_ANY, 1], 5596 ARow1Status = [vacmAccessStatus, ARow1Idx], 5597 ARow1 = [{[vacmAccessContextMatch, ARow1Idx], 1}, 5598 {[vacmAccessReadViewName, ARow1Idx], RVName}, 5599 {[vacmAccessWriteViewName, ARow1Idx], WVName}, 5600 {ARow1Status, ?createAndGo}], 5601 5602 %% This access row would give acces, if InvSecMod was valid. 5603 ARow2Idx = [15 | "no-rights-group"] ++ [0, InvSecMod, 1], 5604 ARow2Status = [vacmAccessStatus, ARow2Idx], 5605 ARow2 = [{[vacmAccessContextMatch, ARow2Idx], 1}, 5606 {[vacmAccessReadViewName, ARow2Idx], "internet"}, 5607 {[vacmAccessWriteViewName, ARow2Idx], "internet"}, 5608 {ARow2Status, ?createAndGo}], 5609 5610 ?line try_test(do_set, [ARow2]), 5611 5612 ?line try_test(use_no_rights, [], Opts), 5613 5614 %% Delete that row 5615 ?line try_test(del_row, [ARow2Status]), 5616 5617 5618 %% Add valid row 5619 ?line try_test(do_set, [ARow1]), 5620 5621 ?line try_test(use_no_rights, [], Opts), 5622 5623 %% Create the view family 5624 VRow1Idx = mk_ln(RVName) ++ mk_ln(?xDescr), % object access 5625 VRow2Idx = mk_ln(RVName) ++ mk_ln(?xDescr2 ++ [0]), % instance access 5626 VRow3Idx = mk_ln(WVName) ++ mk_ln(?xDescr), % object access 5627 VRow4Idx = mk_ln(WVName) ++ mk_ln(?xDescr ++ [0]), % instance access 5628 VRow1Status = [vacmViewTreeFamilyStatus, VRow1Idx], 5629 VRow2Status = [vacmViewTreeFamilyStatus, VRow2Idx], 5630 VRow3Status = [vacmViewTreeFamilyStatus, VRow3Idx], 5631 VRow4Status = [vacmViewTreeFamilyStatus, VRow4Idx], 5632 5633 ?line try_test(add_row, [VRow1Status]), 5634 ?line try_test(add_row, [VRow2Status]), 5635 ?line try_test(add_row, [VRow3Status]), 5636 5637 %% We're supposed to have access now... 5638 ?line try_test(use_rights, [], Opts), 5639 5640 %% Change Row3 to Row4 5641 ?line try_test(del_row, [VRow3Status]), 5642 ?line try_test(add_row, [VRow4Status]), 5643 5644 %% We should still have access... 5645 ?line try_test(use_rights, [], Opts), 5646 5647 %% Delete rows 5648 ?line try_test(del_row, [GRow1Status]), 5649 5650 ?line try_test(use_no_rights, [], Opts), 5651 5652 %% Delete rest of rows 5653 ?line try_test(del_row, [ARow1Status]), 5654 ?line try_test(del_row, [VRow1Status]), 5655 ?line try_test(del_row, [VRow2Status]), 5656 ?line try_test(del_row, [VRow4Status]), 5657 5658 ?line try_test(use_no_rights, [], Opts), 5659 snmpa:verbosity(master_agent,log). 5660 5661do_set(Row) -> 5662 s(Row), 5663 ?expect1(Row). 5664 5665add_row(RowStatus) -> 5666 s([{RowStatus, ?createAndGo}]), 5667 ?expect1([{RowStatus, ?createAndGo}]). 5668 5669del_row(RowStatus) -> 5670 s([{RowStatus, ?destroy}]), 5671 ?expect1([{RowStatus, ?destroy}]). 5672 5673 5674 5675use_no_rights() -> 5676 g([[xDescr,0]]), 5677 ?v1_2_3(?expect3(noSuchName, 1, any), 5678 ?expect1([{[xDescr,0], noSuchObject}]), 5679 ?expect3(authorizationError, 1, any)), 5680 g([[xDescr2,0]]), 5681 ?v1_2_3(?expect3(noSuchName, 1, any), 5682 ?expect1([{[xDescr2,0], noSuchObject}]), 5683 ?expect3(authorizationError, 1, any)), 5684 gn([[xDescr]]), 5685 ?v1_2_3(?expect3(noSuchName, 1, any), 5686 ?expect1([{[xDescr], endOfMibView}]), 5687 ?expect3(authorizationError, 1, any)), 5688 s([{[xDescr,0], "tryit"}]), 5689 ?v1_2_3(?expect3(noSuchName, 1, any), 5690 ?expect3(noAccess, 1, any), 5691 ?expect3(authorizationError, 1, any)). 5692 5693 5694use_rights() -> 5695 g([[xDescr,0]]), 5696 ?expect1([{[xDescr,0], any}]), 5697 g([[xDescr2,0]]), 5698 ?expect1([{[xDescr2,0], any}]), 5699 s([{[xDescr,0], "tryit"}]), 5700 ?expect3(noError, 0, any), 5701 g([[xDescr,0]]), 5702 ?expect1([{[xDescr,0], "tryit"}]). 5703 5704mk_ln(X) -> 5705 [length(X) | X]. 5706 5707 5708%%----------------------------------------------------------------- 5709%% o add/delete users and try them 5710%% o test all secLevels 5711%% o test all combinations of protocols 5712%% o try bad ops; check counters 5713%%----------------------------------------------------------------- 5714snmp_user_based_sm_mib_3(suite) -> []; 5715snmp_user_based_sm_mib_3(Config) when is_list(Config) -> 5716 %% <CONDITIONAL-SKIP> 5717 Skippable = [{unix, [darwin]}], 5718 Condition = fun() -> ?OS_BASED_SKIP(Skippable) end, 5719 ?NON_PC_TC_MAYBE_SKIP(Config, Condition), 5720 %% </CONDITIONAL-SKIP> 5721 5722 ?P(snmp_user_based_sm_mib_3), 5723 init_case(Config), 5724 5725 _AgentDir = ?config(agent_conf_dir, Config), 5726 ?line load_master_std("SNMP-USER-BASED-SM-MIB"), 5727 5728 %% The newUser used here already has VACM access. 5729 5730 %% Add a new user in the simplest way; just createAndGo 5731 try_test(v3_sync, [[{usm_add_user1, []}]], 5732 [{sec_level, authPriv}, {user, "privDES"}]), 5733 5734 %% Try to use the new user 5735 ?line load_master("Test2"), 5736 try_test(v3_sync, [[{usm_use_user, []}]], 5737 [{sec_level, authPriv}, {user, "newUser"}]), 5738 ?line unload_master("Test2"), 5739 5740 ShaKey1 = snmp:passwd2localized_key(sha, "new sha password", "agentEngine"), 5741 DesKey1 = lists:sublist(ShaKey1, 16), 5742 5743 %% Change the new user's keys - 1 5744 try_test(v3_sync, [[{usm_key_change1, [ShaKey1, DesKey1]}]], 5745 [{sec_level, authPriv}, {user, "newUser"}]), 5746 5747 %% Try to use the new keys 5748 MgrDir = ?config(mgr_dir, Config), 5749 ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), 5750 ?line load_master("Test2"), 5751 try_test(v3_sync, [[{usm_use_user, []}]], 5752 [{sec_level, authPriv}, {user, "newUser"}]), 5753 ?line unload_master("Test2"), 5754 5755 ShaKey2 = snmp:passwd2localized_key(sha, "newer password", "agentEngine"), 5756 DesKey2 = lists:sublist(ShaKey2, 16), 5757 5758 %% Change the new user's keys - 2 5759 ?line try_test(v3_sync, 5760 [[{usm_key_change2, [ShaKey1, DesKey1, ShaKey2, DesKey2]}]], 5761 [{sec_level, authPriv}, {user, "newUser"}]), 5762 5763 %% Try to use the new keys 5764 reset_usm_mgr(MgrDir), 5765 ?line rewrite_usm_mgr(MgrDir, ShaKey2, DesKey2), 5766 ?line load_master("Test2"), 5767 ?line try_test(v3_sync, [[{usm_use_user, []}]], 5768 [{sec_level, authPriv}, {user, "newUser"}]), 5769 ?line unload_master("Test2"), 5770 reset_usm_mgr(MgrDir), 5771 5772 %% Change the new user's keys - 3 5773 ?line try_test(v3_sync, 5774 [[{usm_key_change3, [ShaKey2, DesKey2, ShaKey1, DesKey1]}]], 5775 [{sec_level, authPriv}, {user, "privDES"}]), 5776 5777 %% Try to use the new keys 5778 ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), 5779 ?line load_master("Test2"), 5780 try_test(v3_sync, [[{usm_use_user, []}]], 5781 [{sec_level, authPriv}, {user, "newUser"}]), 5782 ?line unload_master("Test2"), 5783 reset_usm_mgr(MgrDir), 5784 5785 %% Try some read requests 5786 ?line try_test(v3_sync, [[{usm_read, []}]], 5787 [{sec_level, authPriv}, {user, "privDES"}]), 5788 5789 %% Delete the new user 5790 ?line try_test(v3_sync, [[{usm_del_user, []}]], 5791 [{sec_level, authPriv}, {user, "privDES"}]), 5792 5793 %% Try some bad requests 5794 ?line try_test(v3_sync, [[{usm_bad, []}]], 5795 [{sec_level, authPriv}, {user, "privDES"}]), 5796 5797 ?line unload_master("SNMP-USER-BASED-SM-MIB"). 5798 5799-define(usmUserSecurityName, [1,3,6,1,6,3,15,1,2,2,1,3]). 5800 5801usm_add_user1() -> 5802 NewRowIndex = [11,"agentEngine", 7, "newUser"], 5803 RowPointer = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], 5804 Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer}, 5805 {[usmUserStatus, NewRowIndex], ?createAndGo}], 5806 ?line s(Vbs1), 5807 ?line ?expect1(Vbs1), 5808 ok. 5809 5810usm_use_user() -> 5811 v2_proc(). 5812 5813 5814%% Change own public keys 5815usm_key_change1(ShaKey, DesKey) -> 5816 NewRowIndex = [11,"agentEngine", 7, "newUser"], 5817 ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, 5818 "passwd_shaxxxxxxxxxx", 5819 ShaKey), 5820 DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, 5821 "passwd_desxxxxxx", 5822 DesKey), 5823 Vbs1 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, 5824 {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], 5825 s(Vbs1), 5826 ?line ?expect1(Vbs1). 5827 5828%% Change own private keys 5829usm_key_change2(OldShaKey, OldDesKey, ShaKey, DesKey) -> 5830 NewRowIndex = [11,"agentEngine", 7, "newUser"], 5831 ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, 5832 OldShaKey, 5833 ShaKey), 5834 DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, 5835 OldDesKey, 5836 DesKey), 5837 Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}, 5838 {[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], 5839 s(Vbs1), 5840 ?line ?expect1(Vbs1). 5841 5842%% Change other's public keys 5843usm_key_change3(OldShaKey, OldDesKey, ShaKey, DesKey) -> 5844 NewRowIndex = [11,"agentEngine", 7, "newUser"], 5845 ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, 5846 OldShaKey, 5847 ShaKey), 5848 DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, 5849 OldDesKey, 5850 DesKey), 5851 Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}], 5852 s(Vbs1), 5853 ?line ?expect3(noAccess, 1, any), 5854 Vbs2 = [{[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], 5855 s(Vbs2), 5856 ?line ?expect3(noAccess, 1, any), 5857 5858 5859 Vbs3 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, 5860 {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], 5861 s(Vbs3), 5862 ?line ?expect1(Vbs3), 5863 ok. 5864 5865usm_read() -> 5866 NewRowIndex = [11,"agentEngine", 7, "newUser"], 5867 ?line g([[usmUserSecurityName, NewRowIndex], 5868 [usmUserCloneFrom, NewRowIndex], 5869 [usmUserAuthKeyChange, NewRowIndex], 5870 [usmUserOwnAuthKeyChange, NewRowIndex], 5871 [usmUserPrivKeyChange, NewRowIndex], 5872 [usmUserOwnPrivKeyChange, NewRowIndex]]), 5873 ?line ?expect1([{[usmUserSecurityName, NewRowIndex], "newUser"}, 5874 {[usmUserCloneFrom, NewRowIndex], [0,0]}, 5875 {[usmUserAuthKeyChange, NewRowIndex], ""}, 5876 {[usmUserOwnAuthKeyChange, NewRowIndex], ""}, 5877 {[usmUserPrivKeyChange, NewRowIndex], ""}, 5878 {[usmUserOwnPrivKeyChange, NewRowIndex], ""}]), 5879 ok. 5880 5881 5882 5883usm_del_user() -> 5884 NewRowIndex = [11,"agentEngine", 7, "newUser"], 5885 Vbs1 = [{[usmUserStatus, NewRowIndex], ?destroy}], 5886 ?line s(Vbs1), 5887 ?line ?expect1(Vbs1), 5888 ok. 5889 5890-define(usmUserCloneFrom, [1,3,6,1,6,3,15,1,2,2,1,4]). 5891 5892-define(usmNoAuthProtocol, [1,3,6,1,6,3,10,1,1,1]). 5893 5894-define(usmHMACMD5AuthProtocol, [1,3,6,1,6,3,10,1,1,2]). 5895 5896-define(usmHMACSHAAuthProtocol, [1,3,6,1,6,3,10,1,1,3]). 5897 5898-define(usmNoPrivProtocol, [1,3,6,1,6,3,10,1,2,1]). 5899 5900-define(usmDESPrivProtocol, [1,3,6,1,6,3,10,1,2,2]). 5901 5902usm_bad() -> 5903 NewRowIndex = [11,"agentEngine", 7, "newUser"], 5904 RowPointer1 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDOS"], 5905 Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer1}, 5906 {[usmUserStatus, NewRowIndex], ?createAndGo}], 5907 ?line s(Vbs1), 5908 ?line ?expect3(inconsistentName, 1, any), 5909 5910 RowPointer2 = ?usmUserCloneFrom ++ [11|"agentEngine"] ++ [7|"privDES"], 5911 Vbs2 = [{[usmUserCloneFrom, NewRowIndex], RowPointer2}, 5912 {[usmUserStatus, NewRowIndex], ?createAndGo}], 5913 ?line s(Vbs2), 5914 ?line ?expect3(wrongValue, 1, any), 5915 5916 RowPointer3 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], 5917 Vbs3 = [{[usmUserCloneFrom, NewRowIndex], RowPointer3}, 5918 {[usmUserStatus, NewRowIndex], ?createAndGo}], 5919 ?line s(Vbs3), 5920 ?line ?expect1(Vbs3), 5921 ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmNoAuthProtocol}]), 5922 ?line ?expect3(inconsistentValue, 1, any), 5923 ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmHMACMD5AuthProtocol}]), 5924 ?line ?expect3(inconsistentValue, 1, any), 5925 ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmDESPrivProtocol}]), 5926 ?line ?expect3(wrongValue, 1, any), 5927 ?line s([{[usmUserPrivProtocol, NewRowIndex], ?usmHMACSHAAuthProtocol}]), 5928 ?line ?expect3(wrongValue, 1, any), 5929 5930 Vbs4 = [{[usmUserStatus, NewRowIndex], ?destroy}], 5931 ?line s(Vbs4), 5932 ?line ?expect1(Vbs4), 5933 ok. 5934 5935 5936%%----------------------------------------------------------------- 5937%% Loop through entire MIB, to make sure that all instrum. funcs 5938%% works. 5939%% Load all std mibs that are not loaded by default. 5940%%----------------------------------------------------------------- 5941loop_mib_1(suite) -> []; 5942loop_mib_1(Config) when is_list(Config) -> 5943 ?P(loop_mib_1), 5944 ?IPRINT("loop_mib_1 -> initiate case"), 5945 5946 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 5947 ?DBG("loop_mib_1 -> ~n" 5948 "\tSaNode: ~p~n" 5949 "\tMgrNode: ~p~n" 5950 "\tMibDir: ~p",[_SaNode, _MgrNode, _MibDir]), 5951 ?DBG("loop_mib_1 -> load mib SNMP-COMMUNITY-MIB",[]), 5952 ?line load_master_std("SNMP-COMMUNITY-MIB"), 5953 ?DBG("loop_mib_1 -> load mib SNMP-MPD-MIB",[]), 5954 ?line load_master_std("SNMP-MPD-MIB"), 5955 ?DBG("loop_mib_1 -> load mib SNMP-TARGET-MIB",[]), 5956 ?line load_master_std("SNMP-TARGET-MIB"), 5957 ?DBG("loop_mib_1 -> load mib SNMP-NOTIFICATION-MIB",[]), 5958 ?line load_master_std("SNMP-NOTIFICATION-MIB"), 5959 ?DBG("loop_mib_1 -> load mib SNMP-FRAMEWORK-MIB",[]), 5960 ?line load_master_std("SNMP-FRAMEWORK-MIB"), 5961 ?DBG("loop_mib_1 -> load mib SNMP-VIEW-BASED-ACM-MIB",[]), 5962 ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), 5963 ?DBG("loop_mib_1 -> try",[]), 5964 5965 try_test(loop_mib_1_test), 5966 5967 ?DBG("loop_mib_1 -> unload mib SNMP-COMMUNITY-MIB",[]), 5968 ?line unload_master("SNMP-COMMUNITY-MIB"), 5969 ?DBG("loop_mib_1 -> unload mib SNMP-MPD-MIB",[]), 5970 ?line unload_master("SNMP-MPD-MIB"), 5971 ?DBG("loop_mib_1 -> unload mib SNMP-TARGET-MIB",[]), 5972 ?line unload_master("SNMP-TARGET-MIB"), 5973 ?DBG("loop_mib_1 -> unload mib SNMP-NOTIFICATION-MIB",[]), 5974 ?line unload_master("SNMP-NOTIFICATION-MIB"), 5975 ?DBG("loop_mib_1 -> unload mib SNMP-FRAMEWORK-MIB",[]), 5976 ?line unload_master("SNMP-FRAMEWORK-MIB"), 5977 ?DBG("loop_mib_1 -> unload mib SNMP-VIEW-BASED-ACM-MIB",[]), 5978 ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), 5979 %% snmpa:verbosity(master_agent,log), 5980 %% snmpa:verbosity(mib_server,silence), 5981 ?IPRINT("loop_mib_1 -> done"), 5982 ok. 5983 5984 5985loop_mib_2(suite) -> []; 5986loop_mib_2(Config) when is_list(Config) -> 5987 ?P(loop_mib_2), 5988 ?IPRINT("loop_mib_2 -> initiate case"), 5989 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 5990 ?DBG("do_loop_mib_2 -> ~n" 5991 "\tSaNode: ~p~n" 5992 "\tMgrNode: ~p~n" 5993 "\tMibDir: ~p", [_SaNode, _MgrNode, _MibDir]), 5994 ?DBG("loop_mib_2 -> load mibs",[]), 5995 ?line load_master_std("SNMP-COMMUNITY-MIB"), 5996 ?line load_master_std("SNMP-MPD-MIB"), 5997 ?line load_master_std("SNMP-TARGET-MIB"), 5998 ?line load_master_std("SNMP-NOTIFICATION-MIB"), 5999 ?line load_master_std("SNMP-FRAMEWORK-MIB"), 6000 ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), 6001 6002 try_test(loop_mib_2_test), 6003 6004 ?DBG("loop_mib_2 -> unload mibs",[]), 6005 ?line unload_master("SNMP-COMMUNITY-MIB"), 6006 ?line unload_master("SNMP-MPD-MIB"), 6007 ?line unload_master("SNMP-TARGET-MIB"), 6008 ?line unload_master("SNMP-NOTIFICATION-MIB"), 6009 ?line unload_master("SNMP-FRAMEWORK-MIB"), 6010 ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), 6011 ?IPRINT("loop_mib_2 -> done"), 6012 ok. 6013 6014 6015loop_mib_3(suite) -> []; 6016loop_mib_3(Config) when is_list(Config) -> 6017 ?P(loop_mib_3), 6018 ?IPRINT("loop_mib_3 -> initiate case"), 6019 {_SaNode, _MgrNode, _MibDir} = init_case(Config), 6020 ?DBG("loop_mib_3 -> ~n" 6021 "\tSaNode: ~p~n" 6022 "\tMgrNode: ~p~n" 6023 "\tMibDir: ~p", [_SaNode, _MgrNode, _MibDir]), 6024 ?DBG("loop_mib_3 -> load mibs",[]), 6025 ?line load_master_std("SNMP-TARGET-MIB"), 6026 ?line load_master_std("SNMP-NOTIFICATION-MIB"), 6027 ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), 6028 ?line load_master_std("SNMP-USER-BASED-SM-MIB"), 6029 6030 try_test(loop_mib_3_test), 6031 6032 ?DBG("loop_mib_3 -> unload mibs",[]), 6033 ?line unload_master("SNMP-TARGET-MIB"), 6034 ?line unload_master("SNMP-NOTIFICATION-MIB"), 6035 ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), 6036 ?line unload_master("SNMP-USER-BASED-SM-MIB"), 6037 ?IPRINT("loop_mib_3 -> done"), 6038 ok. 6039 6040 6041%% Req. As many mibs all possible 6042loop_mib_1_test() -> 6043 ?DBG("loop_mib_1_test -> entry",[]), 6044 N = loop_it_1([1,1], 0), 6045 io:format(user, "found ~w varibles\n", [N]), 6046 ?line N = if N < 100 -> 100; 6047 true -> N 6048 end. 6049 6050loop_it_1(Oid, N) -> 6051 ?DBG("loop_it_1_test -> entry with~n" 6052 "\tOid: ~p~n" 6053 "\tN: ~p",[Oid,N]), 6054 case get_next_req([Oid]) of 6055 #pdu{type = 'get-response', 6056 error_status = noError, 6057 error_index = 0, 6058 varbinds = [#varbind{oid = NOid, 6059 value = _Value}]} when NOid > Oid -> 6060 ?DBG("loop_it_1_test -> " 6061 "~n NOid: ~p" 6062 "~n Value: ~p", [NOid, _Value]), 6063 ?line [_Value2] = get_req(1, [NOid]), % must not be same 6064 ?DBG("loop_it_1_test -> " 6065 "~n Value2: ~p", [_Value2]), 6066 loop_it_1(NOid, N+1); 6067 6068 #pdu{type = 'get-response', 6069 error_status = noError, 6070 error_index = 0, 6071 varbinds = Vbs} -> 6072 exit({unexpected_vbs, ?LINE, Vbs}); 6073 6074 #pdu{type = 'get-response', 6075 error_status = noSuchName, 6076 error_index = 1, 6077 varbinds = [_]} -> 6078 ?DBG("loop_it_1_test -> done: ~p",[N]), 6079 N; 6080 6081 #pdu{type = 'get-response', 6082 error_status = Err, 6083 error_index = Idx, 6084 varbinds = Vbs} -> 6085 exit({unexpected_pdu, ?LINE, Err, Idx, Vbs}); 6086 6087 #pdu{type = Type, 6088 error_status = Err, 6089 error_index = Idx, 6090 varbinds = Vbs} -> 6091 exit({unexpected_pdu, ?LINE, Type, Err, Idx, Vbs}); 6092 6093 {error, Reason} -> 6094 exit({error, Reason, ?LINE}) 6095 end. 6096 6097 6098%% Req. As many mibs all possible 6099loop_mib_2_test() -> 6100 ?DBG("loop_mib_2_test -> entry",[]), 6101 N = loop_it_2([1,1], 0), 6102 io:format(user, "found ~w varibles\n", [N]), 6103 ?line N = if N < 100 -> 100; 6104 true -> N 6105 end. 6106 6107loop_it_2(Oid, N) -> 6108 ?DBG("loop_it_2 -> entry with" 6109 "~n Oid: ~p" 6110 "~n N: ~p",[Oid, N]), 6111 case get_next_req([Oid]) of 6112 #pdu{type = 'get-response', 6113 error_status = noError, 6114 error_index = 0, 6115 varbinds = [#varbind{oid = _NOid, value = endOfMibView}]} -> 6116 ?DBG("loop_it_2 -> " 6117 "~n NOid: ~p", [_NOid]), 6118 N; 6119 6120 #pdu{type = 'get-response', 6121 error_status = noError, 6122 error_index = 0, 6123 varbinds = [#varbind{oid = NOid, 6124 value = _Value}]} when NOid > Oid -> 6125 ?DBG("loop_it_2 -> " 6126 "~n NOid: ~p" 6127 "~n Value: ~p", [NOid, _Value]), 6128 ?line [_Value2] = get_req(1, [NOid]), % must not be same 6129 ?DBG("loop_it_2 -> " 6130 "~n Value2: ~p", [_Value2]), 6131 loop_it_2(NOid, N+1); 6132 6133 #pdu{type = 'get-response', 6134 error_status = noError, 6135 error_index = 0, 6136 varbinds = Vbs} -> 6137 exit({unexpected_pdu, ?LINE, 6138 [{varbinds, Vbs}, 6139 {get_next_oid, Oid}, 6140 {counter, N}]}); 6141 6142 #pdu{type = 'get-response', 6143 error_status = ES, 6144 error_index = EI, 6145 varbinds = Vbs} -> 6146 exit({unexpected_pdu, ?LINE, 6147 [{error_status, ES}, 6148 {error_index, EI}, 6149 {varbinds, Vbs}, 6150 {get_next_oid, Oid}, 6151 {counter, N}]}); 6152 6153 #pdu{type = Type, 6154 error_status = ES, 6155 error_index = EI, 6156 varbinds = Vbs} -> 6157 exit({unexpected_pdu, ?LINE, 6158 [{type, Type}, 6159 {error_status, ES}, 6160 {error_index, EI}, 6161 {varbinds, Vbs}, 6162 {get_next_oid, Oid}, 6163 {counter, N}]}); 6164 6165 {error, Reason} -> 6166 exit({unexpected_result, ?LINE, 6167 [{reason, Reason}, 6168 {get_next_oid, Oid}, 6169 {counter, N}]}) 6170 6171 end. 6172 6173loop_mib_3_test() -> 6174 ?DBG("loop_mib_3_test -> entry",[]), 6175 loop_mib_2_test(). 6176 6177 6178%%%----------------------------------------------------------------- 6179%%% Testing of reported bugs and other tickets. 6180%%%----------------------------------------------------------------- 6181 6182reported_bugs_cases() -> 6183 [ 6184 otp_1128, 6185 otp_1129, 6186 otp_1131, 6187 otp_1162, 6188 otp_1222, 6189 otp_1298, 6190 otp_1331, 6191 otp_1338, 6192 otp_1342, 6193 otp_1366, 6194 otp_2776, 6195 otp_2979, 6196 otp_3187, 6197 otp_3725 6198 ]. 6199 6200reported_bugs2_cases() -> 6201 [ 6202 otp_1128_2, 6203 otp_1129_2, 6204 otp_1131_2, 6205 otp_1162_2, 6206 otp_1222_2, 6207 otp_1298_2, 6208 otp_1331_2, 6209 otp_1338_2, 6210 otp_1342_2, 6211 otp_1366_2, 6212 otp_2776_2, 6213 otp_2979_2, 6214 otp_3187_2 6215 ]. 6216 6217reported_bugs3_cases() -> 6218 [ 6219 otp_1128_3, 6220 otp_1129_3, 6221 otp_1131_3, 6222 otp_1162_3, 6223 otp_1222_3, 6224 otp_1298_3, 6225 otp_1331_3, 6226 otp_1338_3, 6227 otp_1342_3, 6228 otp_1366_3, 6229 otp_2776_3, 6230 otp_2979_3, 6231 otp_3187_3, 6232 otp_3542 6233 ]. 6234 6235 6236%%----------------------------------------------------------------- 6237%% Ticket: OTP-1128 6238%% Slogan: Bug in handling of createAndWait set-requests. 6239%%----------------------------------------------------------------- 6240otp_1128(suite) -> []; 6241otp_1128(Config) when is_list(Config) -> 6242 ?P(otp_1128), 6243 init_case(Config), 6244 6245 ?line load_master("OLD-SNMPEA-MIB"), 6246 ?line init_old(), 6247 try_test(otp_1128_test), 6248 ?line unload_master("OLD-SNMPEA-MIB"), 6249 ok. 6250 6251otp_1128_2(X) -> ?P(otp_1128_2), otp_1128(X). 6252 6253otp_1128_3(X) -> ?P(otp_1128_3), otp_1128(X). 6254 6255otp_1128_test() -> 6256 io:format("Testing bug reported in ticket OTP-1128...~n"), 6257 6258 NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], 6259 NewKeyc4 = [intCommunityAccess,get(mip),is("test")], 6260 NewKeyc5 = [intCommunityStatus,get(mip),is("test")], 6261 6262 s([{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), 6263 ?line ?expect1([{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), 6264 g([NewKeyc5]), 6265 ?line ?expect1([{NewKeyc5, ?notReady}]), 6266 s([{NewKeyc5, ?active}, {NewKeyc3, 2}]), 6267 ?line ?expect1([{NewKeyc5, ?active}, {NewKeyc3, 2}]), 6268 g([NewKeyc5]), 6269 ?line ?expect1([{NewKeyc5, ?active}]), 6270 s([{NewKeyc5, ?destroy}]), 6271 ?line ?expect1([{NewKeyc5, ?destroy}]), 6272 ok. 6273 6274 6275%%----------------------------------------------------------------- 6276%% Ticket: OTP-1129, OTP-1169 6277%% Slogan: snmpa:int_to_enum crashes on bad oids 6278%%----------------------------------------------------------------- 6279otp_1129(suite) -> []; 6280otp_1129(Config) when is_list(Config) -> 6281 ?P(otp_1129), 6282 init_case(Config), 6283 ?line load_master("Klas3"), 6284 try_test(otp_1129_i, [node()]), 6285 ?line unload_master("Klas3"), 6286 ok. 6287 6288otp_1129_2(X) -> ?P(otp_1129_2), otp_1129(X). 6289 6290otp_1129_3(X) -> ?P(otp_1129_3), otp_1129(X). 6291 6292otp_1129_i(MaNode) -> 6293 io:format("Testing bug reported in ticket OTP-1129...~n"), 6294 false = rpc:call(MaNode, snmp, int_to_enum, [iso, 1]), 6295 false = rpc:call(MaNode, snmp, int_to_enum, [isox, 1]). 6296 6297 6298%%----------------------------------------------------------------- 6299%% Ticket: OTP-1131 6300%% Slogan: Agent crashes / erlang node halts if RowIndex in a 6301%% setrequest is of bad type, e.g. an INDEX {INTEGER}, 6302%% and RowIdenx [3,2]. 6303%%----------------------------------------------------------------- 6304otp_1131(suite) -> []; 6305otp_1131(Config) when is_list(Config) -> 6306 ?P(otp_1131), 6307 init_case(Config), 6308 6309 ?line load_master("Klas1"), 6310 try_test(otp_1131_test), 6311 ?line unload_master("Klas1"). 6312 6313otp_1131_2(X) -> ?P(otp_1131_2), otp_1131(X). 6314 6315otp_1131_3(X) -> 6316 %% <CONDITIONAL-SKIP> 6317 %% This is intended to catch Montavista Linux 4.0/ppc (2.6.5) 6318 %% Montavista Linux looks like a Debian distro (/etc/issue) 6319 LinuxVersionVerify = 6320 fun() -> 6321 case os:cmd("uname -m") of 6322 "ppc" ++ _ -> 6323 case file:read_file_info("/etc/issue") of 6324 {ok, _} -> 6325 case os:cmd("grep -i montavista /etc/issue") of 6326 Info when (is_list(Info) andalso 6327 (length(Info) > 0)) -> 6328 case os:version() of 6329 {2, 6, 10} -> 6330 true; 6331 _ -> 6332 false 6333 end; 6334 _ -> % Maybe plain Debian or Ubuntu 6335 false 6336 end; 6337 _ -> 6338 %% Not a Debian based distro 6339 false 6340 end; 6341 _ -> 6342 false 6343 end 6344 end, 6345 Skippable = [{unix, [darwin, {linux, LinuxVersionVerify}]}], 6346 Condition = fun() -> ?OS_BASED_SKIP(Skippable) end, 6347 ?NON_PC_TC_MAYBE_SKIP(X, Condition), 6348 %% </CONDITIONAL-SKIP> 6349 6350 ?P(otp_1131_3), 6351 otp_1131(X). 6352 6353otp_1131_test() -> 6354 io:format("Testing bug reported in ticket OTP-1131...~n"), 6355 s([{[friendsEntry, [2, 3, 1]], s, "kompis3"}, 6356 {[friendsEntry, [3, 3, 1]], i, ?createAndGo}]), 6357 ?line ?expect3(?v1_2(noSuchName, noCreation), 2, any), 6358 ok. 6359 6360 6361%%----------------------------------------------------------------- 6362%% Ticket: OTP-1162 6363%% Slogan: snmp_agent can't handle wrongValue from instrum.func 6364%%----------------------------------------------------------------- 6365otp_1162(suite) -> []; 6366otp_1162(Config) when is_list(Config) -> 6367 ?P(otp_1162), 6368 {SaNode, _MgrNode, _MibDir} = init_case(Config), 6369 ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), 6370 try_test(otp_1162_test), 6371 stop_subagent(SA). 6372 6373otp_1162_2(X) -> ?P(otp_1162_2), otp_1162(X). 6374 6375otp_1162_3(X) -> ?P(otp_1162_3), otp_1162(X). 6376 6377otp_1162_test() -> 6378 s([{[sa, [2,0]], 6}]), % wrongValue (i is_set_ok) 6379 ?line ?expect3(?v1_2(badValue, wrongValue), 1, any), 6380 ok. 6381 6382 6383%%----------------------------------------------------------------- 6384%% Ticket: OTP-1222 6385%% Slogan: snmp agent crash if faulty index is returned from instrum 6386%%----------------------------------------------------------------- 6387otp_1222(suite) -> []; 6388otp_1222(Config) when is_list(Config) -> 6389 ?P(otp_1222), 6390 init_case(Config), 6391 ?line load_master("Klas3"), 6392 ?line load_master("Klas4"), 6393 try_test(otp_1222_test), 6394 ?line unload_master("Klas3"), 6395 ?line unload_master("Klas4"), 6396 ok. 6397 6398otp_1222_2(X) -> ?P(otp_1222_2), otp_1222(X). 6399 6400otp_1222_3(X) -> ?P(otp_1222_3), otp_1222(X). 6401 6402otp_1222_test() -> 6403 io:format("Testing bug reported in ticket OTP-1222...~n"), 6404 s([{[fStatus4,1], 4}, {[fName4,1], 1}]), 6405 ?line ?expect3(genErr, 0, any), 6406 s([{[fStatus4,2], 4}, {[fName4,2], 1}]), 6407 ?line ?expect3(genErr, 0, any), 6408 ok. 6409 6410 6411%%----------------------------------------------------------------- 6412%% Ticket: OTP-1298 6413%% Slogan: Negative INTEGER values are treated as positive. 6414%%----------------------------------------------------------------- 6415otp_1298(suite) -> []; 6416otp_1298(Config) when is_list(Config) -> 6417 ?P(otp_1298), 6418 init_case(Config), 6419 6420 ?line load_master("Klas2"), 6421 try_test(otp_1298_test), 6422 ?line unload_master("Klas2"), 6423 ok. 6424 6425otp_1298_2(X) -> ?P(otp_1298_2), otp_1298(X). 6426 6427otp_1298_3(X) -> ?P(otp_1298_3), otp_1298(X). 6428 6429otp_1298_test() -> 6430 io:format("Testing bug reported in ticket OTP-1298...~n"), 6431 s([{[fint,0], -1}]), 6432 ?line ?expect1([{[fint,0], -1}]), 6433 ok. 6434 6435 6436%%----------------------------------------------------------------- 6437%% Ticket: OTP-1331 6438%% Slogan: snmp_generic should return noError when deleting non-ex row 6439%%----------------------------------------------------------------- 6440otp_1331(suite) -> []; 6441otp_1331(Config) when is_list(Config) -> 6442 ?P(otp_1331), 6443 init_case(Config), 6444 ?line load_master("OLD-SNMPEA-MIB"), 6445 ?line init_old(), 6446 try_test(otp_1331_test), 6447 ?line unload_master("OLD-SNMPEA-MIB"), 6448 ok. 6449 6450otp_1331_2(X) -> ?P(otp_1331_2), otp_1331(X). 6451 6452otp_1331_3(X) -> ?P(otp_1331_3), otp_1331(X). 6453 6454otp_1331_test() -> 6455 NewKeyc5 = [intCommunityStatus,[127,32,0,0],is("test")], 6456 s([{NewKeyc5, ?destroy}]), 6457 ?line ?expect1([{NewKeyc5, ?destroy}]), 6458 ok. 6459 6460 6461%%----------------------------------------------------------------- 6462%% Ticket: OTP-1338 6463%% Slogan: snmp bug in initialisation of default values for mnesia tabs 6464%%----------------------------------------------------------------- 6465otp_1338(suite) -> []; 6466otp_1338(Config) when is_list(Config) -> 6467 ?P(otp_1338), 6468 init_case(Config), 6469 6470 ?line load_master("Klas2"), 6471 try_test(otp_1338_test), 6472 ?line unload_master("Klas2"). 6473 6474otp_1338_2(X) -> ?P(otp_1338_2), otp_1338(X). 6475 6476otp_1338_3(X) -> ?P(otp_1338_3), otp_1338(X). 6477 6478otp_1338_test() -> 6479 s([{[kStatus2, 7], i, ?createAndGo}]), 6480 ?line ?expect1([{[kStatus2, 7], ?createAndGo}]), 6481 g([[kName2, 7]]), 6482 ?line ?expect1([{[kName2, 7], "JJJ"}]). 6483 6484 6485%%----------------------------------------------------------------- 6486%% Ticket: OTP-1342 6487%% Slogan: default impl of snmp table can't handle bad index access, 6488%% Set when INDEX is read-write gets into an infinite loop! 6489%%----------------------------------------------------------------- 6490otp_1342(suite) -> []; 6491otp_1342(Config) when is_list(Config) -> 6492 ?P(otp_1342), 6493 init_case(Config), 6494 ?line load_master("Klas4"), 6495 try_test(otp_1342_test), 6496 ?line unload_master("Klas4"), 6497 ok. 6498 6499otp_1342_2(X) -> ?P(otp_1342_2), otp_1342(X). 6500 6501otp_1342_3(X) -> ?P(otp_1342_3), otp_1342(X). 6502 6503otp_1342_test() -> 6504 s([{[fIndex5, 1], i, 1}, 6505 {[fName5, 1], i, 3}, 6506 {[fStatus5, 1], i, ?createAndGo}]), 6507 ?line ?expect3(?v1_2(noSuchName, noCreation), 3, any), 6508 ok. 6509 6510 6511%%----------------------------------------------------------------- 6512%% Ticket: OTP-1366 6513%% Slogan: snmp traps not sent to all managers 6514%% Note: NYI! We need a way to tell the test server that we need 6515%% mgrs on two different machines. 6516%%----------------------------------------------------------------- 6517otp_1366(suite) -> []; 6518otp_1366(Config) when is_list(Config) -> 6519 ?P(otp_1366), 6520 init_case(Config), 6521 ?line load_master("OLD-SNMPEA-MIB"), 6522 ?line init_old(), 6523 try_test(otp_1366_test), 6524 ?line unload_master("OLD-SNMPEA-MIB"), 6525 ok. 6526 6527otp_1366_2(X) -> ?P(otp_1366_2), otp_1366(X). 6528 6529otp_1366_3(X) -> ?P(otp_1366_3), otp_1366(X). 6530 6531otp_1366_test() -> 6532 ?NPRINT("NOT YET IMPLEMENTED"), 6533 'NYI'. 6534 6535 6536%%----------------------------------------------------------------- 6537%% Ticket: OTP-2776 6538%% Slogan: snmp:validate_date_and_time() fails when time is 00:00 6539%%----------------------------------------------------------------- 6540otp_2776(suite) -> []; 6541otp_2776(Config) when is_list(Config) -> 6542 ?P(otp_2776), 6543 init_case(Config), 6544 try_test(otp_2776_test). 6545 6546otp_2776_2(X) -> ?P(otp_2776_2), otp_2776(X). 6547 6548otp_2776_3(X) -> ?P(otp_2776_3), otp_2776(X). 6549 6550otp_2776_test() -> 6551 ?NPRINT("Testing bug reported in ticket OTP-2776..."), 6552 6553 Dt01_valid = [19,98,9,1,1,0,23,0,43,0,0], 6554 Dt02_valid = [19,98,9,1,0,0,0,0,43,0,0], % This is what is fixed: 00:00 6555 Dt03_valid = [19,98,2,28,1,0,23,0,43,0,0], 6556 Dt04_invalid = [19,98,2,29,1,0,23,0,43,0,0], 6557 Dt05_valid = [19,96,2,29,1,0,23,0,43,0,0], 6558 Dt06_valid = [20,0,2,29,1,0,23,0,43,0,0], 6559 Dt07_invalid = [19,96,2,30,1,0,23,0,43,0,0], % This is also fixed: 30/2 6560 Dt08_valid = [19,98,4,30,1,0,23,0,43,0,0], 6561 Dt09_invalid = [19,98,4,31,1,0,23,0,43,0,0], % This is also fixed: 31/4 6562 Dt10_invalid = [], 6563 Dt11_invalid = [kalle,hobbe], 6564 L = [{ 1, true, Dt01_valid}, 6565 { 2, true, Dt02_valid}, 6566 { 3, true, Dt03_valid}, 6567 { 4, false, Dt04_invalid}, 6568 { 5, true, Dt05_valid}, 6569 { 6, true, Dt06_valid}, 6570 { 7, false, Dt07_invalid}, 6571 { 8, true, Dt08_valid}, 6572 { 9, false, Dt09_invalid}, 6573 {10, false, Dt10_invalid}, 6574 {11, false, Dt11_invalid}], 6575 6576 ?line ok = validate_dat(L). 6577 6578 6579validate_dat(L) -> validate_dat(L,[]). 6580 6581validate_dat([],V) -> 6582 Fun = fun({_,X}) -> case X of 6583 ok -> false; 6584 _ -> true 6585 end 6586 end, 6587 validate_dat1( lists:reverse( lists:filter(Fun,V) ) ); 6588validate_dat([{Id,E,Dat}|T],V) -> 6589 validate_dat(T,[validate_dat2(Id,E,Dat) | V]). 6590 6591validate_dat1([]) -> ok; 6592validate_dat1(L) -> {error,L}. 6593 6594validate_dat2(Id, E, Dat) -> 6595 Res = case {E,snmp:validate_date_and_time(Dat)} of 6596 {E,E} -> ok; 6597 {E,A} -> {E,A} 6598 end, 6599 {Id, Res}. 6600 6601 6602%%----------------------------------------------------------------- 6603%% Ticket: OTP-2979 6604%% Slogan: get-next on more than 1 column in an empty table 6605%% returns bad response. 6606%%----------------------------------------------------------------- 6607otp_2979(suite) -> []; 6608otp_2979(Config) when is_list(Config) -> 6609 ?P(otp_2979), 6610 init_case(Config), 6611 ?line load_master("Test1"), 6612 ?line init_old(), 6613 try_test(otp_2979_test), 6614 ?line unload_master("Test1"). 6615 6616otp_2979_2(X) -> ?P(otp_2979_2), otp_2979(X). 6617 6618otp_2979_3(X) -> ?P(otp_2979_3), otp_2979(X). 6619 6620otp_2979_test() -> 6621 gn([[sparseDescr], [sparseStatus]]), 6622 ?line ?expect1([{[sparseStr,0], "slut"}, 6623 {[sparseStr,0], "slut"}]), 6624 ok. 6625 6626 6627%%----------------------------------------------------------------- 6628%% Ticket: OTP-3187 6629%% Slogan: get-next on vacmAccessTable for colums > 5 returns 6630%% endOfTable - should return value. 6631%%----------------------------------------------------------------- 6632otp_3187(suite) -> []; 6633otp_3187(Config) when is_list(Config) -> 6634 ?P(otp_3187), 6635 init_case(Config), 6636 ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), 6637 otp_3187_test(), 6638 ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). 6639 6640otp_3187_2(X) -> ?P(otp_3187_2), otp_3187(X). 6641 6642otp_3187_3(X) -> ?P(otp_3187_3), otp_3187(X). 6643 6644otp_3187_test() -> 6645 ?line Elements = 6646 snmp_view_based_acm_mib:vacmAccessTable(get_next,[],[4,5,6]), 6647 lists:foreach(fun(E) -> 6648 ?line if E == endOfTable -> 6649 ?FAIL(endOfTable); 6650 true -> ok 6651 end 6652 end, Elements). 6653 6654%%----------------------------------------------------------------- 6655%% Ticket: OTP-3542 6656%% Slogan: 6657%%----------------------------------------------------------------- 6658otp_3542(suite) -> []; 6659otp_3542(Config) when is_list(Config) -> 6660 ?P(otp_3542), 6661 init_case(Config), 6662 try_test(otp_3542_test). 6663 6664otp_3542_test() -> 6665 io:format("SNMP v3 discovery...~n"), 6666 ?line Res = snmp_test_mgr:d(), 6667 io:format("SNMP v3 discovery result: ~p~n",[Res]). 6668 6669 6670%%----------------------------------------------------------------- 6671%% Ticket: OTP-3725 6672%% Slogan: Slow response time on snmpa:int_to_enum 6673%%----------------------------------------------------------------- 6674otp_3725(suite) -> []; 6675otp_3725(Config) when is_list(Config) -> 6676 ?P(otp_3725), 6677 init_case(Config), 6678 6679 ?line load_master("OLD-SNMPEA-MIB"), 6680 ?line init_old(), 6681 try_test(otp_3725_test, [node()]), 6682 ?line unload_master("OLD-SNMPEA-MIB"). 6683 6684%% Req. OLD-SNMPEA-MIB 6685otp_3725_test(MaNode) -> 6686 io:format("Testing feature requested in ticket OTP-3725...~n"), 6687 ?line rpc:call(MaNode,snmpa,verbosity,[symbolic_store,trace]), 6688 ?line Db = rpc:call(MaNode,snmp,get_symbolic_store_db,[]), 6689 ?DBG("otp_3725_test -> Db = ~p",[Db]), 6690 6691 ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, 6692 [Db, intAgentIpAddress]), 6693 ?DBG("otp_3725_test -> name_to_oid for ~p: ~p",[intAgentIpAddress,OID]), 6694 ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, oid_to_name, 6695 [Db,OID]), 6696 ?DBG("otp_3725_test -> oid_to_name for ~p: ~p",[OID,intAgentIpAddress]), 6697 ?line false = rpc:call(MaNode, snmp, name_to_oid, [Db, intAgentIpAddres]), 6698 ?line false = rpc:call(MaNode, snmp, oid_to_name, 6699 [Db, [1,5,32,3,54,3,3,34,4]]), 6700 ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, 6701 [Db, intViewType, excluded]), 6702 ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, 6703 [Db, intViewType, 2]), 6704 ?line false = rpc:call(MaNode, snmp, enum_to_int, 6705 [Db, intViewType, exclude]), 6706 ?line false = rpc:call(MaNode, snmp, enum_to_int, 6707 [Db, intAgentIpAddress, exclude]), 6708 ?line false = rpc:call(MaNode, snmp, enum_to_int, 6709 [Db, intAgentIpAddre, exclude]), 6710 ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, intViewType, 3]), 6711 ?line false = rpc:call(MaNode, snmp, int_to_enum, 6712 [Db, intAgentIpAddress, 2]), 6713 ?line false = rpc:call(MaNode, snmp, int_to_enum, 6714 [Db, intAgentIpAddre, 2]), 6715 ?line {value, active} = rpc:call(MaNode, snmp, int_to_enum, 6716 [Db, 'RowStatus', ?active]), 6717 ?line {value, ?destroy} = rpc:call(MaNode, snmp, enum_to_int, 6718 [Db, 'RowStatus', destroy]), 6719 ?line false = rpc:call(MaNode, snmp, enum_to_int, 6720 [Db, 'RowStatus', xxxdestroy]), 6721 ?line false = rpc:call(MaNode, snmp, enum_to_int, 6722 [Db, 'xxRowStatus', destroy]), 6723 ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'RowStatus', 25]), 6724 ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'xxRowStatus', 1]), 6725 ok. 6726 6727 6728%%----------------------------------------------------------------- 6729%% Ticket: OTP-4394 6730%% Slogan: Target mib tag list check invalid 6731%%----------------------------------------------------------------- 6732 6733tickets1_cases() -> 6734 [ 6735 {group, otp4394}, 6736 {group, otp7157}, 6737 {group, otp16092} 6738 ]. 6739 6740 6741otp_4394_init(Config) when is_list(Config) -> 6742 ?DBG("otp_4394_init -> entry with" 6743 "~n Config: ~p", [Config]), 6744 ?line AgentConfDir = ?config(agent_conf_dir, Config), 6745 ?line MgrDir = ?config(mgr_dir, Config), 6746 ?line Ip = ?config(ip, Config), 6747 ?line otp_4394_config(AgentConfDir, MgrDir, Ip), 6748 MasterAgentVerbosity = {master_agent_verbosity, trace}, 6749 NetIfVerbosity = {net_if_verbosity, trace}, 6750 Opts = [MasterAgentVerbosity, NetIfVerbosity], 6751 [{vsn, v1} | start_v1_agent(Config, Opts)]. 6752 6753otp_4394_config(AgentConfDir, MgrDir, Ip0) -> 6754 ?DBG("otp_4394_config -> entry with" 6755 "~n AgentConfDir: ~p" 6756 "~n MgrDir: ~p" 6757 "~n Ip0: ~p", [AgentConfDir, MgrDir, Ip0]), 6758 Vsn = [v1], 6759 Ip = tuple_to_list(Ip0), 6760 ?line snmp_config:write_agent_snmp_files(AgentConfDir, Vsn, Ip, 6761 ?TRAP_UDP, Ip, 4000, 6762 "OTP-4394 test"), 6763 ?line case update_usm(Vsn, AgentConfDir) of 6764 true -> 6765 ?line copy_file(join(AgentConfDir, "usm.conf"), 6766 join(MgrDir, "usm.conf")), 6767 ?line update_usm_mgr(Vsn, MgrDir); 6768 false -> 6769 ?line ok 6770 end, 6771 C1 = {"a", "all-rights", "initial", "", "pc"}, 6772 C2 = {"c", "secret", "secret_name", "", "secret_tag"}, 6773 ?line write_community_conf(AgentConfDir, [C1, C2]), 6774 ?line update_vacm(Vsn, AgentConfDir), 6775 Ta1 = {"shelob v1", 6776 [134,138,177,177], 5000, 1500, 3, %% Use Ip and modify 6777 "pc1", 6778 "target_v1", "", 6779 %% [255,255,255,255,0,0], 6780 [], 6781 2048}, 6782 Ta2 = {"bifur v1", 6783 [134,138,177,75], 5000, 1500, 3, %% Use Ip 6784 "pc2", 6785 "target_v1", "", 6786 %% [255,255,255,255,0,0], 6787 [], 2048}, 6788 ?line write_target_addr_conf(AgentConfDir, [Ta1, Ta2]), 6789 ?line write_target_params_conf(AgentConfDir, Vsn), 6790 ?line write_notify_conf(AgentConfDir), 6791 ok. 6792 6793otp_4394_finish(Config) when is_list(Config) -> 6794 ?DBG("finish_otp_4394 -> entry", []), 6795 C1 = stop_agent(Config), 6796 delete_files(C1), 6797 erase(mgr_node), 6798 lists:keydelete(vsn, 1, C1). 6799 6800otp_4394(suite) -> []; 6801otp_4394(Config) -> 6802 ?P(otp_4394), 6803 ?DBG("otp_4394 -> entry", []), 6804 init_case(Config), 6805 try_test(otp_4394_test), 6806 ?DBG("otp_4394 -> done", []), 6807 ok. 6808 6809otp_4394_test() -> 6810 ?DBG("otp_4394_test -> entry", []), 6811 gn([[1,1]]), 6812 Res = 6813 case snmp_test_mgr:expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]) of 6814 {error, 1, _, {_, [timeout]}} -> 6815 ?DBG("otp_4394_test -> expected result: timeout", []), 6816 ok; 6817 Else -> 6818 Else 6819 end, 6820 ?DBG("otp_4394_test -> done with: ~p", [Res]), 6821 Res. 6822 6823 6824%%----------------------------------------------------------------- 6825%% Ticket: OTP-7157 6826%% Slogan: Target mib tag list check invalid 6827%%----------------------------------------------------------------- 6828 6829otp_7157_init(Config) when is_list(Config) -> 6830 %% <CONDITIONAL-SKIP> 6831 Skippable = [win32], 6832 Condition = fun() -> ?OS_BASED_SKIP(Skippable) end, 6833 ?NON_PC_TC_MAYBE_SKIP(Config, Condition), 6834 %% </CONDITIONAL-SKIP> 6835 6836 ?DBG("init_otp_7157 -> entry with" 6837 "~n Config: ~p", [Config]), 6838 ?line AgentConfDir = ?config(agent_conf_dir, Config), 6839 ?line MgrDir = ?config(mgr_dir, Config), 6840 ?line Ip = ?config(ip, Config), 6841 ?line config([v2], MgrDir, AgentConfDir, 6842 tuple_to_list(Ip), tuple_to_list(Ip)), 6843 MasterAgentVerbosity = {master_agent_verbosity, trace}, 6844 NetIfVerbosity = {net_if_verbosity, trace}, 6845 Opts = [MasterAgentVerbosity, NetIfVerbosity], 6846 [{vsn, v2} | start_v2_agent(Config, Opts)]. 6847 6848 6849otp_7157_finish(Config) when is_list(Config) -> 6850 ?DBG("finish_otp_7157 -> entry", []), 6851 C1 = stop_agent(Config), 6852 delete_files(C1), 6853 erase(mgr_node), 6854 lists:keydelete(vsn, 1, C1). 6855 6856otp_7157(suite) -> []; 6857otp_7157(Config) -> 6858 ?P(otp_7157), 6859 ?DBG("otp_7157 -> entry", []), 6860 init_case(Config), 6861 MA = whereis(snmp_master_agent), 6862 ?line load_master("Test1"), 6863 try_test(otp_7157_test, [MA]), 6864 ?line unload_master("Test1"), 6865 ?DBG("otp_7157 -> done", []), 6866 ok. 6867 6868%% ts:run(snmp, snmp_agent_test, [batch]). 6869otp_7157_test(MA) -> 6870 ?IPRINT("start otp_7157_test test (~p)", [MA]), 6871 snmpa:verbosity(MA, trace), 6872 ?IPRINT("start otp_7157_test test"), 6873 6874 ?NPRINT("Testing that varbinds in traps/notifications are not reordered"), 6875 6876 ?DBG("send cntTrap",[]), 6877 snmpa:send_trap(MA, cntTrap, "standard trap"), 6878 6879 ?DBG("await response",[]), 6880 %% We don't really care about the values, just the vb order. 6881 ?line ok = ?expect2(v2trap, [{[sysUpTime, 0], any}, 6882 {[snmpTrapOID, 0], any}, 6883 {[sysContact, 0], any}, 6884 {[cnt64, 0], any}, 6885 {[sysLocation, 0], any}]), 6886 6887 ?DBG("done", []), 6888 ok. 6889 6890 6891 6892%%----------------------------------------------------------------- 6893%% Ticket: OTP-16092 6894%% Slogan: Extra socket options 6895%% We perform simple start and stop tests with and without 6896%% this option. 6897%%----------------------------------------------------------------- 6898 6899otp16092_cases() -> 6900 [ 6901 otp_16092_simple_start_and_stop1, % default 6902 otp_16092_simple_start_and_stop2, % [] 6903 otp_16092_simple_start_and_stop3, % bad => ignored 6904 otp_16092_simple_start_and_stop4 % invalid content 6905 ]. 6906 6907otp_16092_simple_start_and_stop1(suite) -> []; 6908otp_16092_simple_start_and_stop1(Config) -> 6909 ?P(otp_16092_simple_start_and_stop1), 6910 ?DBG("otp_16092_simple_start_and_stop1 -> entry", []), 6911 6912 TC = fun() -> 6913 otp_16092_simple_start_and_stop(Config, default, success) 6914 end, 6915 6916 Result = otp_16092_try(TC), 6917 6918 ?DBG("otp_16092_simple_start_and_stop1 -> done: " 6919 "~n ~p", [Result]), 6920 6921 Result. 6922 6923 6924otp_16092_simple_start_and_stop2(suite) -> []; 6925otp_16092_simple_start_and_stop2(Config) -> 6926 ?P(otp_16092_simple_start_and_stop2), 6927 ?DBG("otp_16092_simple_start_and_stop2 -> entry", []), 6928 6929 TC = fun() -> 6930 otp_16092_simple_start_and_stop(Config, [], success) 6931 end, 6932 6933 Result = otp_16092_try(TC), 6934 6935 ?DBG("otp_16092_simple_start_and_stop2 -> done: " 6936 "~n ~p", [Result]), 6937 6938 Result. 6939 6940 6941otp_16092_simple_start_and_stop3(suite) -> []; 6942otp_16092_simple_start_and_stop3(Config) -> 6943 ?P(otp_16092_simple_start_and_stop3), 6944 ?DBG("otp_16092_simple_start_and_stop3 -> entry", []), 6945 6946 TC = fun() -> 6947 otp_16092_simple_start_and_stop(Config, 6948 'this-should-be-ignored', 6949 success) 6950 end, 6951 6952 Result = otp_16092_try(TC), 6953 6954 ?DBG("otp_16092_simple_start_and_stop3 -> done: " 6955 "~n ~p", [Result]), 6956 6957 Result. 6958 6959 6960otp_16092_simple_start_and_stop4(suite) -> []; 6961otp_16092_simple_start_and_stop4(Config) -> 6962 ?P(otp_16092_simple_start_and_stop4), 6963 ?DBG("otp_16092_simple_start_and_stop4 -> entry", []), 6964 6965 TC = fun() -> 6966 otp_16092_simple_start_and_stop(Config, 6967 ['this-should-fail'], 6968 failure) 6969 end, 6970 6971 Result = otp_16092_try(TC), 6972 6973 ?DBG("otp_16092_simple_start_and_stop4 -> done: " 6974 "~n ", [Result]), 6975 6976 Result. 6977 6978 6979otp_16092_try(TC) -> 6980 try TC() of 6981 Any -> 6982 Any 6983 catch 6984 _:{skip, _} = SKIP -> 6985 SKIP 6986 end. 6987 6988otp_16092_simple_start_and_stop(Config, ESO, Expected) -> 6989 ?line ConfDir = ?config(agent_conf_dir, Config), 6990 ?line DbDir = ?config(agent_db_dir, Config), 6991 6992 ?NPRINT("try start agent node"), 6993 {ok, Node} = ?ALIB:start_node(agent_16092), 6994 6995 Vsns = [v1], 6996 IP = tuple_to_list(?config(ip, Config)), 6997 ManagerIP = IP, 6998 TrapPort = ?TRAP_UDP, 6999 AgentIP = IP, 7000 AgentPort = 4000, 7001 SysName = "test", 7002 ok = snmp_config:write_agent_snmp_files( 7003 ConfDir, Vsns, ManagerIP, TrapPort, AgentIP, AgentPort, SysName), 7004 7005 ConfOpts = [{dir, ConfDir}, 7006 {force_load, false}, 7007 {verbosity, trace}], 7008 NiOpts = 7009 case ESO of 7010 default -> 7011 [{verbosity, trace}]; 7012 _ -> 7013 [{verbosity, trace}, {options, [{extra_sock_opts, ESO}]}] 7014 end, 7015 7016 Opts = [{agent_type, master}, 7017 {versions, Vsns}, 7018 {db_dir, DbDir}, 7019 {config, ConfOpts}, 7020 {net_if, NiOpts}], 7021 7022 otp16092_try_start_and_stop_agent(Node, Opts, Expected), 7023 7024 ?NPRINT("try stop agent node ~p", [Node]), 7025 ?ALIB:stop_node(Node), 7026 7027 ?SLEEP(1000), 7028 7029 ?NPRINT("done"), 7030 ok. 7031 7032 7033otp16092_try_start_and_stop_agent(Node, Opts, Expected) -> 7034 ?IPRINT("try start snmp (agent) supervisor (on ~p) - expect ~p", 7035 [Node, Expected]), 7036 case start_standalone_agent(Node, Opts) of 7037 Pid when is_pid(Pid) andalso (Expected =:= success) -> 7038 ?IPRINT("Expected success starting snmp (agent) supervisor"), 7039 ?SLEEP(1000), 7040 stop_standalone_agent(Pid), 7041 ok; 7042 Pid when is_pid(Pid) andalso (Expected =:= failure) -> 7043 ?EPRINT("Unexpected success starting snmp (agent) supervisor: (~p)", 7044 [Pid]), 7045 ?SLEEP(1000), 7046 stop_standalone_agent(Pid), 7047 ?FAIL('unexpected-start-success'); 7048 7049 {error, 7050 shutdown, 7051 {failed_to_start_child, snmpa_agent_sup, 7052 {shutdown, 7053 {failed_to_start_child, snmpa_agent, 7054 {net_if_error, Reason}}}}} when (Expected =:= failure) -> 7055 ?IPRINT("Expected (shutdown, net-if) error starting " 7056 "snmp (agent) supervisor (on ~p):" 7057 "~n ~p", [Node, Reason]), 7058 ok; 7059 {error, {shutdown, Reason}} when (Expected =:= failure) -> 7060 ?IPRINT("Expected (shutdown) error starting " 7061 "snmp (agent) supervisor (on ~p):" 7062 "~n ~p", [Node, Reason]), 7063 ok; 7064 {error, Reason} when (Expected =:= failure) -> 7065 ?IPRINT("Expected error starting snmp (agent) supervisor (on ~p):" 7066 "~n ~p", [Node, Reason]), 7067 ok; 7068 7069 {badrpc, 7070 {'EXIT', 7071 {shutdown, 7072 {failed_to_start_child, snmpa_agent_sup, 7073 {shutdown, 7074 {failed_to_start_child, snmpa_agent, 7075 {net_if_error, Reason}}}}}}} when (Expected =:= failure) -> 7076 ?IPRINT("Expected (badrpc, shutdown, net-if) error starting " 7077 "snmp (agent) supervisor (on ~p):" 7078 "~n ~p", [Node, Reason]), 7079 ok; 7080 {badrpc, {'EXIT', {shutdown, Reason}}} when (Expected =:= failure) -> 7081 ?IPRINT("Expected (badrpc, shutdown) error starting " 7082 "snmp (agent) supervisor (on ~p):" 7083 "~n ~p", [Node, Reason]), 7084 ok; 7085 {badrpc, {'EXIT', Reason}} when (Expected =:= failure) -> 7086 ?IPRINT("Expected (badrpc) error starting snmp (agent) supervisor " 7087 "(on ~p):" 7088 "~n ~p", [Node, Reason]), 7089 ok; 7090 7091 {badrpc, Reason} = BADRPC -> 7092 ?WPRINT("Bad RPC to node ~p failed:" 7093 "~n ~p", [Node, Reason]), 7094 ?SKIP({BADRPC, Node}) 7095 7096 end, 7097 ok. 7098 7099 7100 7101 7102%%----------------------------------------------------------------- 7103%% Extra test cases 7104%% These cases are started in the new way 7105%%----------------------------------------------------------------- 7106 7107tickets2_cases() -> 7108 [ 7109 otp8395, 7110 otp9884 7111 ]. 7112 7113 7114otp8395({init, Config}) when is_list(Config) -> 7115 ?DBG("otp8395(init) -> entry with" 7116 "~n Config: ~p", [Config]), 7117 7118 %% -- 7119 %% Start nodes 7120 %% 7121 7122 {ok, AgentNode} = start_node(agent), 7123 {ok, ManagerNode} = start_node(manager), 7124 7125 %% -- 7126 %% Mnesia init 7127 %% 7128 7129 AgentDbDir = ?config(agent_db_dir, Config), 7130 AgentMnesiaDir = join([AgentDbDir, "mnesia"]), 7131 mnesia_init(AgentNode, AgentMnesiaDir), 7132 7133 mnesia_create_schema(AgentNode, [AgentNode]), 7134 7135 mnesia_start(AgentNode), 7136 7137 %% -- 7138 %% Host & IP 7139 %% 7140 7141 AgentHost = ?HOSTNAME(AgentNode), 7142 %% SubAgentHost = ?HPSTNAME(SubAgentNode), 7143 ManagerHost = ?HOSTNAME(ManagerNode), 7144 7145 IpFamily = inet, 7146 Host = snmp_test_lib:hostname(), 7147 Ip = ?LOCALHOST(), 7148 {ok, AgentIP0} = snmp_misc:ip(AgentHost), 7149 AgentIP = tuple_to_list(AgentIP0), 7150 %% {ok, SubAgentIP0} = snmp_misc:ip(SubAgentHost), 7151 %% SubAgentIP = tuple_to_list(SubAgentIP0), 7152 {ok, ManagerIP0} = snmp_misc:ip(ManagerHost), 7153 ManagerIP = tuple_to_list(ManagerIP0), 7154 7155 7156 %% -- 7157 %% Write agent config 7158 %% 7159 7160 Vsns = [v1], 7161 AgentConfDir = ?config(agent_conf_dir, Config), 7162 ManagerConfDir = ?config(manager_top_dir, Config), 7163 config(Vsns, ManagerConfDir, AgentConfDir, ManagerIP, AgentIP, IpFamily), 7164 7165 7166 %% -- 7167 %% Start the agent 7168 %% 7169 7170 Config2 = start_agent([{host, Host}, 7171 {ip, Ip}, 7172 {ipfamily, IpFamily}, 7173 {agent_node, AgentNode}, 7174 {agent_host, AgentHost}, 7175 {agent_ip, AgentIP}, 7176 %% {sub_agent_node, SubAgentNode}, 7177 %% {sub_agent_host, SubAgentHost}, 7178 %% {sub_agent_ip, SubAgentIP}, 7179 {manager_node, ManagerNode}, 7180 {manager_host, ManagerHost}, 7181 {manager_ip, ManagerIP}|Config]), 7182 7183 %% -- 7184 %% Create watchdog 7185 %% 7186 7187 wd_start(1, Config2); 7188 7189otp8395({fin, Config}) when is_list(Config) -> 7190 ?DBG("otp8395(fin) -> entry with" 7191 "~n Config: ~p", [Config]), 7192 7193 AgentNode = ?config(agent_node, Config), 7194 ManagerNode = ?config(manager_node, Config), 7195 7196 %% - 7197 %% Stop agent (this is the nice way to do it, 7198 %% so logs and files can be closed in the proper way). 7199 %% 7200 7201 AgentSup = ?config(agent_sup, Config), 7202 ?DBG("otp8395(fin) -> stop (stand-alone) agent: ~p", [AgentSup]), 7203 stop_standalone_agent(AgentSup), 7204 7205 %% - 7206 %% Stop mnesia 7207 %% 7208 ?DBG("otp8395(fin) -> stop mnesia", []), 7209 mnesia_stop(AgentNode), 7210 7211 7212 %% - 7213 %% Stop the agent node 7214 %% 7215 7216 ?DBG("otp8395(fin) -> stop agent node", []), 7217 stop_node(AgentNode), 7218 7219 %% - 7220 %% Stop the manager node 7221 %% 7222 7223 ?DBG("otp8395(fin) -> stop manager node", []), 7224 stop_node(ManagerNode), 7225 7226 wd_stop(Config); 7227 7228otp8395(doc) -> 7229 "OTP-8395 - ATL with sequence numbering. "; 7230 7231otp8395(Config) when is_list(Config) -> 7232 ?DBG("otp8395 -> entry with" 7233 "~n Config: ~p", [Config]), 7234 7235 ?SLEEP(1000), 7236 7237 %% This is just to dirty trick for the ***old*** test-code 7238 put(mgr_node, ?config(manager_node, Config)), 7239 put(mgr_dir, ?config(manager_top_dir, Config)), 7240 put(mib_dir, ?config(mib_dir, Config)), 7241 put(vsn, v1), 7242 put(master_host, ?config(agent_host, Config)), 7243 put(ipfamily, ?config(ipfamily, Config)), 7244 try_test(simple_standard_test), 7245 7246 ?SLEEP(1000), 7247 AgentNode = ?config(agent_node, Config), 7248 AgentLogDir = ?config(agent_log_dir, Config), 7249 OutFile = join([AgentLogDir, "otp8395.txt"]), 7250 {ok, _LogInfo} = rpc:call(AgentNode, snmpa, log_info, []), 7251 ?DBG("otp8395 -> LogInfo: ~p", [_LogInfo]), 7252 7253 %% SyncRes = rpc:call(AgentNode, snmp, log_sync, [?audit_trail_log_name]), 7254 %% ?DBG("otp8395 -> SyncRes: ~p", [SyncRes]), 7255 7256 ok = agent_log_validation(AgentNode), 7257 _LTTRes = 7258 rpc:call(AgentNode, snmpa, log_to_txt, [AgentLogDir, [], OutFile]), 7259 ?DBG("otp8395 -> LTTRes: ~p", [_LTTRes]), 7260 7261 ?SLEEP(1000), 7262 ?DBG("otp8395 -> done", []), 7263 ok. 7264 7265 7266%%----------------------------------------------------------------- 7267 7268otp9884({init, Config}) when is_list(Config) -> 7269 ?DBG("otp9884(init) -> entry with" 7270 "~n Config: ~p", [Config]), 7271 init_v1_agent([{ipfamily, inet} | Config]); 7272 7273otp9884({fin, Config}) when is_list(Config) -> 7274 ?DBG("otp9884(fin) -> entry with" 7275 "~n Config: ~p", [Config]), 7276 fin_v1_agent(Config); 7277 7278otp9884(doc) -> 7279 "OTP-9884 - Simultaneous backup(s) call should not work. "; 7280 7281otp9884(Config) when is_list(Config) -> 7282 ?DBG("otp9884 -> entry with" 7283 "~n Config: ~p", [Config]), 7284 7285 AgentNode = ?config(agent_node, Config), 7286 [AgentBkpDir1, AgentBkpDir2] = ?config(agent_backup_dirs, Config), 7287 Self = self(), 7288 timer:apply_after(1000, 7289 ?MODULE, 7290 otp9884_backup, 7291 [AgentNode, Self, first, AgentBkpDir1]), 7292 timer:apply_after(1000, 7293 ?MODULE, 7294 otp9884_backup, 7295 [AgentNode, Self, second, AgentBkpDir2]), 7296 otp9884_await_backup_started(), 7297 otp9884_await_backup_completion(undefined, undefined), 7298 7299 ?DBG("otp9884 -> done", []), 7300 ok. 7301 7302 7303otp9884_backup(Node, Pid, Tag, Dir) -> 7304 ?IPRINT("[~w] backup - await continue", [Tag]), 7305 Pid ! {otp9884_backup_started, Tag, self()}, 7306 receive 7307 {otp9884_backup_continue, Tag, Pid} -> 7308 ok 7309 end, 7310 ?IPRINT("[~w] backup start", [Tag]), 7311 Res = rpc:call(Node, snmpa, backup, [Dir]), 7312 ?IPRINT("[~w] backup result: ~p", [Tag, Res]), 7313 Pid ! {otp9884_backup_complete, Tag, Res}. 7314 7315 7316otp9884_await_backup_started() -> 7317 otp9884_await_backup_started(undefined, undefined). 7318 7319otp9884_await_backup_started(First, Second) 7320 when is_pid(First) andalso is_pid(Second) -> 7321 ?IPRINT("otp9884_await_backup_started -> order first continue"), 7322 First ! {otp9884_backup_continue, first, self()}, 7323 ?IPRINT("otp9884_await_backup_started -> order second continue"), 7324 Second ! {otp9884_backup_continue, second, self()}, 7325 ok; 7326otp9884_await_backup_started(First, Second) -> 7327 receive 7328 {otp9884_backup_started, first, Pid} when (First =:= undefined) -> 7329 ?IPRINT("otp9884_await_backup_started -> received started from first"), 7330 otp9884_await_backup_started(Pid, Second); 7331 {otp9884_backup_started, second, Pid} when (Second =:= undefined) -> 7332 ?IPRINT("otp9884_await_backup_started -> received started from second"), 7333 otp9884_await_backup_started(First, Pid) 7334 end. 7335 7336otp9884_await_backup_completion(ok, Second) 7337 when ((Second =/= ok) andalso (Second =/= undefined)) -> 7338 ?IPRINT("otp9884_await_backup_completion -> " 7339 "first backup succeed and second failed (~p)", [Second]), 7340 ok; 7341otp9884_await_backup_completion(First, ok) 7342 when ((First =/= ok) andalso (First =/= undefined)) -> 7343 ?IPRINT("otp9884_await_backup_completion -> " 7344 "second backup succeed and first failed (~p)", [First]), 7345 ok; 7346otp9884_await_backup_completion(First, Second) 7347 when (((First =:= undefined) andalso (Second =:= undefined)) 7348 orelse 7349 ((First =:= undefined) andalso (Second =/= undefined)) 7350 orelse 7351 ((First =/= undefined) andalso (Second =:= undefined))) -> 7352 ?IPRINT("otp9884_await_backup_completion -> await complete messages"), 7353 receive 7354 {otp9884_backup_complete, first, Res} -> 7355 ?IPRINT("otp9884_await_backup_completion -> " 7356 "received complete message for first: ~p", [Res]), 7357 otp9884_await_backup_completion(Res, Second); 7358 {otp9884_backup_complete, second, Res} -> 7359 ?IPRINT("otp9884_await_backup_completion -> " 7360 "received complete message for second: ~p", [Res]), 7361 otp9884_await_backup_completion(First, Res) 7362 after 10000 -> 7363 %% we have waited long enough 7364 ?EPRINT("otp9884_await_backup_completion -> timeout"), 7365 throw({error, {timeout, First, Second}}) 7366 end; 7367otp9884_await_backup_completion(First, Second) -> 7368 ?EPRINT("Bad Completion: " 7369 "~n First: ~p" 7370 "~n Second: ~p", [First, Second]), 7371 throw({error, {bad_completion, First, Second}}). 7372 7373 7374%%----------------------------------------------------------------- 7375 7376agent_log_validation(Node) -> 7377 rpc:call(Node, ?MODULE, agent_log_validation, []). 7378 7379agent_log_validation() -> 7380 put(sname, otp8308), 7381 put(verbosity, trace), 7382 snmp_log:validate(?audit_trail_log_name, true). 7383 7384mnesia_init(Node, Dir) -> 7385 rpc:call(Node, ?MODULE, mnesia_init, [Dir]). 7386 7387mnesia_init(Dir) -> 7388 ok = application:load(mnesia), 7389 application_controller:set_env(mnesia, dir, Dir). 7390 7391mnesia_create_schema(Node, Nodes) -> 7392 rpc:call(Node, mnesia, create_schema, [Nodes]). 7393 7394mnesia_start(Node) -> 7395 rpc:call(Node, application, start, [mnesia]). 7396 7397mnesia_start() -> 7398 application:start(mnesia). 7399 7400mnesia_stop(Node) -> 7401 rpc:call(Node, application, stop, [mnesia]). 7402 7403mnesia_stop() -> 7404 application:start(mnesia). 7405 7406 7407start_agent(Config) -> 7408 start_agent(Config, []). 7409 7410start_agent(Config, Opts) -> 7411 7412 %% Directories 7413 ConfDir = ?config(agent_conf_dir, Config), 7414 DbDir = ?config(agent_db_dir, Config), 7415 LogDir = ?config(agent_log_dir, Config), 7416 7417 Vsns = [v1], 7418 7419 AgentConfig = process_agent_options(ConfDir, DbDir, LogDir, Vsns, Opts), 7420 7421 %% Nodes 7422 AgentNode = ?config(agent_node, Config), 7423 7424 process_flag(trap_exit, true), 7425 7426 AgentTopSup = start_standalone_agent(AgentNode, AgentConfig), 7427 7428 [{agent_sup, AgentTopSup} | Config]. 7429 7430 7431process_agent_options(ConfDir, DbDir, LogDir, Vsns, Opts) -> 7432 Defaults = 7433 [{agent_type, master}, 7434 {agent_verbosity, trace}, 7435 {priority, normal}, 7436 {versions, Vsns}, 7437 {db_dir, DbDir}, 7438 {mib_storage, ets}, 7439 {local_db, [{repair, true}, 7440 {auto_save, 5000}, 7441 {verbosity, log}]}, 7442 {error_report_module, snmpa_error_logger}, 7443 {config, [{dir, ConfDir}, 7444 {force_load, true}, 7445 {verbosity, trace}]}, 7446 {multi_threaded, true}, 7447 {mib_server, [{mibentry_override, false}, 7448 {trapentry_override, false}, 7449 {verbosity, info}]}, 7450 {target_cache, [{verbosity,info}]}, 7451 {symbolic_store, [{verbosity,log}]}, 7452 {note_store, [{timeout,30000}, {verbosity,log}]}, 7453 {net_if, [{module, snmpa_net_if}, 7454 {verbosity, trace}, 7455 {options, [{bind_to, false}, 7456 {no_reuse, false}, 7457 {req_limit, infinity}]}]}, 7458 {audit_trail_log, [{type, read_write}, 7459 {dir, LogDir}, 7460 {size, {10240,20}}, 7461 {repair, true}, 7462 {seqno, true}]}], 7463 7464 process_options(Defaults, Opts). 7465 7466process_options(Defaults, _Opts) -> 7467 %% process_options(Defaults, Opts, []). 7468 Defaults. 7469 7470 7471start_standalone_agent(Node, Config) -> 7472 rpc:call(Node, ?MODULE, start_standalone_agent, [Config]). 7473 7474start_standalone_agent(Config) -> 7475 case snmpa_supervisor:start_link(normal, Config) of 7476 {ok, AgentTopSup} -> 7477 unlink(AgentTopSup), 7478 AgentTopSup; 7479 {error, {already_started, AgentTopSup}} -> 7480 AgentTopSup; 7481 {error, _} = ERROR -> 7482 ERROR 7483 end. 7484 7485stop_standalone_agent(Pid) when (node(Pid) =/= node()) -> 7486 MRef = erlang:monitor(process, Pid), 7487 rpc:call(node(Pid), ?MODULE, stop_standalone_agent, [Pid]), 7488 receive 7489 {'DOWN', MRef, process, Pid, _Info} -> 7490 ?DBG("received expected DOWN message " 7491 "regarding snmp agent supervisor: " 7492 "~n Info: ~p", [_Info]), 7493 ok 7494 after 5000 -> 7495 ?DBG("no DOWN message " 7496 "regarding snmp agent supervisor within time", []), 7497 ok 7498 end; 7499stop_standalone_agent(Pid) -> 7500 ?DBG("attempting to terminate agent top-supervisor: ~p", [Pid]), 7501 nkill(Pid, kill). 7502 7503 7504nkill(Pid, Reason) -> 7505 nkill(Pid, Reason, 10). 7506 7507nkill(Pid, Reason, N) when N > 0 -> 7508 case (catch erlang:process_info(Pid)) of 7509 Info when is_list(Info) -> 7510 ?DBG("Info for process to kill: " 7511 "~n Info: ~p", [Info]), 7512 exit(Pid, Reason), 7513 ?SLEEP(1000), 7514 nkill(Pid, Reason, N-1); 7515 _ -> 7516 ?DBG("No process info => already dead?", []), 7517 ok 7518 end. 7519 7520 7521%%----------------------------------------------------------------- 7522%% Slogan: info test 7523%%----------------------------------------------------------------- 7524 7525info_test(suite) -> []; 7526info_test(Config) when is_list(Config) -> 7527 ?P(info_test), 7528 init_case(Config), 7529 7530 ?line load_master("OLD-SNMPEA-MIB"), 7531 ?line init_old(), 7532 try_test(do_info, [node()]), 7533 ?line unload_master("OLD-SNMPEA-MIB"). 7534 7535do_info(MaNode) -> 7536 ?line Info = rpc:call(MaNode, snmpa, info, []), 7537 ?DBG("info_test1 -> Info: ~n~p", [Info]), 7538 Keys = [vsns, 7539 stats_counters, 7540 {agent, [process_memory, db_memory]}, 7541 {net_if, [process_memory, port_info, reqs]}, 7542 {note_store, [process_memory, db_memory]}, 7543 {symbolic_store, [process_memory, db_memory]}, 7544 {local_db, [process_memory, db_memory]}, 7545 {mib_server, [process_memory, 7546 loaded_mibs, 7547 subagents, 7548 tree_size_bytes, 7549 db_memory]}], 7550 verify_info(Info, Keys), 7551 ok. 7552 7553verify_info([], []) -> 7554 ok; 7555verify_info([], Keys) -> 7556 ?FAIL({remaining_info_keys, Keys}); 7557verify_info(Info0, [Key|Keys]) -> 7558 Info = verify_info1(Info0, Key), 7559 verify_info(Info, Keys). 7560 7561verify_info1(Info0, Key) when is_atom(Key) -> 7562 case lists:keydelete(Key, 1, Info0) of 7563 Info0 -> 7564 ?FAIL({missing_info, Key}); 7565 Info -> 7566 Info 7567 end; 7568verify_info1(Info0, {Key, SubKeys}) when is_atom(Key) andalso is_list(SubKeys) -> 7569 case lists:keysearch(Key, 1, Info0) of 7570 false -> 7571 ?FAIL({missing_info, Key}); 7572 {value, {Key, SubInfo}} -> 7573 case verify_subinfo(SubInfo, SubKeys) of 7574 ok -> 7575 lists:keydelete(Key, 1, Info0); 7576 {error, MissingSubKeyOrKeys} -> 7577 ?FAIL({missing_info, {Key, MissingSubKeyOrKeys}}) 7578 end 7579 end. 7580 7581verify_subinfo(_, []) -> 7582 ok; 7583verify_subinfo([], Keys) -> 7584 {error, Keys}; 7585verify_subinfo(Info0, [Key|Keys]) -> 7586 case lists:keydelete(Key, 1, Info0) of 7587 Info0 -> 7588 {error, Key}; 7589 Info -> 7590 verify_subinfo(Info, Keys) 7591 end. 7592 7593%% Index String - string used in index 7594is(S) -> [length(S) | S]. 7595 7596try_test(Func) -> 7597 ?NPRINT("try test ~w...", [Func]), 7598 ?ALIB:try_test(?MODULE, Func). 7599 7600try_test(Func, A) -> 7601 ?NPRINT("try test ~w...", [Func]), 7602 ?ALIB:try_test(?MODULE, Func, A). 7603 7604try_test(Func, A, Opts) -> 7605 ?NPRINT("try test ~w...", [Func]), 7606 ?ALIB:try_test(?MODULE, Func, A, Opts). 7607 7608 7609%% Test manager wrapperfunctions: 7610g(Oids) -> snmp_test_mgr:g(Oids). 7611%%gn() -> snmp_test_mgr:gn(). 7612gn(OidsOrN) -> snmp_test_mgr:gn(OidsOrN). 7613gb(NR, MR, Oids) -> snmp_test_mgr:gb(NR, MR, Oids). 7614s(VAV) -> snmp_test_mgr:s(VAV). 7615 7616get_req(Id, Vars) -> 7617 ?ALIB:get_req(Id, Vars). 7618 7619get_next_req(Vars) -> 7620 ?ALIB:get_next_req(Vars). 7621 7622 7623start_node(Name) -> 7624 ?ALIB:start_node(Name). 7625 7626stop_node(undefined) -> 7627 ok; 7628stop_node(Node) -> 7629 ?ALIB:stop_node(Node). 7630 7631 7632%%%----------------------------------------------------------------- 7633%%% Configuration 7634%%%----------------------------------------------------------------- 7635delete_files(Config) -> 7636 ?ALIB:delete_files(Config). 7637 7638config(Vsns, MgrDir, AgentDir, MIp, AIp) -> 7639 ?ALIB:config(Vsns, MgrDir, AgentDir, MIp, AIp). 7640 7641config(Vsns, MgrDir, AgentDir, MIp, AIp, IpFamily) -> 7642 ?ALIB:config(Vsns, MgrDir, AgentDir, MIp, AIp, IpFamily). 7643 7644update_usm(Vsns, Dir) -> 7645 ?ALIB:update_usm(Vsns, Dir). 7646 7647update_usm_mgr(Vsns, Dir) -> 7648 ?ALIB:update_usm_mgr(Vsns, Dir). 7649 7650rewrite_usm_mgr(Dir, ShaKey, DesKey) -> 7651 ?ALIB:rewrite_usm_mgr(Dir, ShaKey, DesKey). 7652 7653reset_usm_mgr(Dir) -> 7654 ?ALIB:reset_usm_mgr(Dir). 7655 7656 7657update_vacm(Vsn, Dir) -> 7658 ?ALIB:update_vacm(Vsn, Dir). 7659 7660write_community_conf(Dir, Conf) -> 7661 ?ALIB:write_community_conf(Dir, Conf). 7662 7663write_target_addr_conf(Dir, Conf) -> 7664 ?ALIB:write_target_addr_conf(Dir, Conf). 7665 7666 7667rewrite_target_addr_conf(Dir, NewPort) -> 7668 ?ALIB:rewrite_target_addr_conf(Dir, NewPort). 7669 7670 7671reset_target_addr_conf(Dir) -> 7672 ?ALIB:reset_target_addr_conf(Dir). 7673 7674write_target_params_conf(Dir, Vsns) -> 7675 ?ALIB:write_target_params_conf(Dir, Vsns). 7676 7677rewrite_target_params_conf(Dir, SecName, SecLevel) -> 7678 ?ALIB:rewrite_target_params_conf(Dir, SecName, SecLevel). 7679 7680reset_target_params_conf(Dir) -> 7681 ?ALIB:reset_target_params_conf(Dir). 7682 7683write_notify_conf(Dir) -> 7684 ?ALIB:write_notify_conf(Dir). 7685 7686 7687%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 7688 7689copy_file(From, To) -> 7690 ?ALIB:copy_file(From, To). 7691 7692 7693%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 7694 7695display_log(Config) -> 7696 case lists:keysearch(agent_log_dir, 1, Config) of 7697 {value, {_, Dir}} -> 7698 case lists:keysearch(snmp_master, 1, Config) of 7699 {value, {_, Node}} -> 7700 LogDir = Dir, 7701 Mibs = [], 7702 OutFile = join(LogDir, "snmpa_log.txt"), 7703 ?IPRINT("~n" 7704 "=========================" 7705 " < Audit Trail Log > " 7706 "=========================" 7707 "~n"), 7708 rcall(Node, snmpa, log_to_txt, [LogDir, Mibs, OutFile]), 7709 rcall(Node, snmpa, log_to_io, [LogDir, Mibs]), 7710 ?IPRINT("~n" 7711 "=========================" 7712 " < / Audit Trail Log > " 7713 "=========================" 7714 "~n"); 7715 false -> 7716 ?IPRINT("display_log -> no agent node found"), 7717 ok 7718 end; 7719 false -> 7720 ?IPRINT("display_log -> no agent log dir found: " 7721 "~n ~p", [Config]), 7722 ok 7723 end. 7724 7725 7726%% ------ 7727 7728display_memory_usage() -> 7729 Info = snmpa:info(snmp_master_agent), 7730 AMU = display_agent_memory_usage(Info), 7731 NIMU = display_net_if_memory_usage(Info), 7732 NSMU = display_note_store_memory_usage(Info), 7733 SSMU = display_symbolic_store_memory_usage(Info), 7734 LDBMU = display_local_db_memory_usage(Info), 7735 MSMU = display_mib_server_memory_usage(Info), 7736 ?NPRINT("Memory usage: ~n" ++ AMU ++ NIMU ++ NSMU ++ SSMU ++ LDBMU ++ MSMU), 7737 ok. 7738 7739display_agent_memory_usage(Info) -> 7740 AgentInfo = lists_key1search(agent, Info), 7741 ProcMem = 7742 lists_key1search([process_memory,master_agent], AgentInfo), 7743 WProcMem = 7744 lists_key1search([process_memory,worker], AgentInfo), 7745 SWProcMem = 7746 lists_key1search([process_memory,set_worker], AgentInfo), 7747 TabSize = 7748 lists_key1search([db_memory,agent], AgentInfo), 7749 CCSize = 7750 lists_key1search([db_memory,community_cache], AgentInfo), 7751 VacmSize = 7752 lists_key1search([db_memory,vacm], AgentInfo), 7753 ?F(" Agent memory usage: " 7754 "~n Master process memory size: ~p" 7755 "~n Worker process memory size: ~p" 7756 "~n Set-worker process memory size: ~p" 7757 "~n Agent tab size: ~p" 7758 "~n Community cache size: ~p" 7759 "~n Vacm tab size: ~p" 7760 "~n", 7761 [ProcMem, WProcMem, SWProcMem, 7762 TabSize, CCSize, VacmSize]). 7763 7764display_net_if_memory_usage(Info) -> 7765 NiInfo = lists_key1search(net_if, Info), 7766 ProcMem = lists_key1search(process_memory, NiInfo), 7767 ?F(" Net if memory usage: " 7768 "~n Process memory size: ~p" 7769 "~n", [ProcMem]). 7770 7771display_note_store_memory_usage(Info) -> 7772 NsInfo = lists_key1search(note_store, Info), 7773 ProcMem = lists_key1search([process_memory,notes], NsInfo), 7774 ProcTmrMem = lists_key1search([process_memory,timer], NsInfo), 7775 TabSize = lists_key1search([db_memory,notes], NsInfo), 7776 ?F(" Note store memory usage: " 7777 "~n Notes process memory size: ~p" 7778 "~n Timer process memory size: ~p" 7779 "~n Notes tab size: ~p" 7780 "~n", 7781 [ProcMem, ProcTmrMem, TabSize]). 7782 7783 display_symbolic_store_memory_usage(Info) -> 7784 SsInfo = lists_key1search(symbolic_store, Info), 7785 ProcMem = lists_key1search(process_memory, SsInfo), 7786 DbMem = lists_key1search(db_memory, SsInfo), 7787 ?F(" Symbolic store memory usage: " 7788 "~n Process memory size: ~p" 7789 "~n DB size: ~p" 7790 "~n", 7791 [ProcMem, DbMem]). 7792 7793display_local_db_memory_usage(Info) -> 7794 LdInfo = lists_key1search(local_db, Info), 7795 ProcMem = lists_key1search(process_memory, LdInfo), 7796 EtsSize = lists_key1search([db_memory,ets], LdInfo), 7797 DetsSize = lists_key1search([db_memory,dets], LdInfo), 7798 ?F(" Local DB memory usage: " 7799 "~n Process memory size: ~p" 7800 "~n DB [ets] size: ~p" 7801 "~n DB [dets] size: ~p" 7802 "~n", 7803 [ProcMem, EtsSize, DetsSize]). 7804 7805display_mib_server_memory_usage(Info) -> 7806 MibInfo = lists_key1search(mib_server, Info), 7807 ProcMem = lists_key1search(process_memory, MibInfo), 7808 TreeSize = lists_key1search(tree_size_bytes, MibInfo), 7809 MibDbSize = lists_key1search([db_memory,mib], MibInfo), 7810 NodeDbSize = lists_key1search([db_memory,node], MibInfo), 7811 TreeDbSize = lists_key1search([db_memory,tree], MibInfo), 7812 ?F(" MIB server memory usage: " 7813 "~n Process memory size: ~p" 7814 "~n Tree size: ~p" 7815 "~n Mib db size: ~p" 7816 "~n Node db size: ~p" 7817 "~n Tree db size: ~p" 7818 "~n", 7819 [ProcMem, TreeSize, MibDbSize, NodeDbSize, TreeDbSize]). 7820 7821lists_key1search([], Res) -> 7822 Res; 7823lists_key1search([Key|Keys], List) when is_atom(Key) andalso is_list(List) -> 7824 case lists:keysearch(Key, 1, List) of 7825 {value, {Key, Val}} -> 7826 lists_key1search(Keys, Val); 7827 false -> 7828 undefined 7829 end; 7830lists_key1search(Key, List) when is_atom(Key) -> 7831 case lists:keysearch(Key, 1, List) of 7832 {value, {Key, Val}} -> 7833 Val; 7834 false -> 7835 undefined 7836 end. 7837 7838 7839%% ------ 7840 7841init_v1_agent(Config) -> 7842 %% -- 7843 %% Start nodes 7844 %% 7845 7846 {ok, AgentNode} = start_node(agent), 7847 7848 %% We don't use a manager in this test but the (common) config 7849 %% function takes an argument that is derived from this 7850 {ok, ManagerNode} = start_node(manager), 7851 7852 %% -- 7853 %% Mnesia init 7854 %% 7855 7856 AgentDbDir = ?config(agent_db_dir, Config), 7857 AgentMnesiaDir = join([AgentDbDir, "mnesia"]), 7858 mnesia_init(AgentNode, AgentMnesiaDir), 7859 7860 mnesia_create_schema(AgentNode, [AgentNode]), 7861 7862 mnesia_start(AgentNode), 7863 7864 %% -- 7865 %% Host & IP 7866 %% 7867 7868 AgentHost = ?HOSTNAME(AgentNode), 7869 ManagerHost = ?HOSTNAME(ManagerNode), 7870 7871 Host = snmp_test_lib:hostname(), 7872 IpFamily = config_ipfamily(Config), 7873 Ip = ?LOCALHOST(IpFamily), 7874 {ok, AgentIP0} = snmp_misc:ip(AgentHost, IpFamily), 7875 AgentIP = tuple_to_list(AgentIP0), 7876 {ok, ManagerIP0} = snmp_misc:ip(ManagerHost, IpFamily), 7877 ManagerIP = tuple_to_list(ManagerIP0), 7878 7879 7880 %% -- 7881 %% Write agent config 7882 %% 7883 7884 Vsns = [v1], 7885 ManagerConfDir = ?config(manager_top_dir, Config), 7886 AgentConfDir = ?config(agent_conf_dir, Config), 7887 AgentTopDir = ?config(agent_top_dir, Config), 7888 AgentBkpDir1 = join([AgentTopDir, backup1]), 7889 AgentBkpDir2 = join([AgentTopDir, backup2]), 7890 ok = file:make_dir(AgentBkpDir1), 7891 ok = file:make_dir(AgentBkpDir2), 7892 AgentBkpDirs = [AgentBkpDir1, AgentBkpDir2], 7893 config(Vsns, ManagerConfDir, AgentConfDir, ManagerIP, AgentIP, IpFamily), 7894 7895 7896 %% -- 7897 %% Start the agent 7898 %% 7899 7900 Config2 = start_agent([{host, Host}, 7901 {ip, Ip}, 7902 {agent_node, AgentNode}, 7903 {agent_host, AgentHost}, 7904 {agent_ip, AgentIP}, 7905 {agent_backup_dirs, AgentBkpDirs}|Config]), 7906 7907 %% -- 7908 %% Create watchdog 7909 %% 7910 7911 wd_start(1, Config2). 7912 7913fin_v1_agent(Config) -> 7914 AgentNode = ?config(agent_node, Config), 7915 ManagerNode = ?config(manager_node, Config), 7916 7917 %% - 7918 %% Stop agent (this is the nice way to do it, 7919 %% so logs and files can be closed in the proper way). 7920 %% 7921 7922 AgentSup = ?config(agent_sup, Config), 7923 stop_standalone_agent(AgentSup), 7924 7925 %% - 7926 %% Stop mnesia 7927 %% 7928 mnesia_stop(AgentNode), 7929 7930 7931 %% - 7932 %% Stop the agent node 7933 %% 7934 stop_node(AgentNode), 7935 7936 7937 %% SubAgentNode = ?config(sub_agent_node, Config), 7938 %% stop_node(SubAgentNode), 7939 7940 7941 %% - 7942 %% Stop the manager node 7943 %% 7944 stop_node(ManagerNode), 7945 7946 wd_stop(Config). 7947 7948 7949config_ipfamily(Config) -> 7950 case ?config(ipfamily, Config) of 7951 undefined -> 7952 inet; 7953 Value -> 7954 Value 7955 end. 7956 7957 7958%% ------ 7959 7960join(Parts) -> 7961 filename:join(Parts). 7962 7963join(Dir, File) -> 7964 filename:join(Dir, File). 7965 7966 7967%% ------ 7968 7969rcall(Node, Mod, Func, Args) -> 7970 case rpc:call(Node, Mod, Func, Args) of 7971 {badrpc, nodedown} -> 7972 ?FAIL({rpc_failure, Node}); 7973 Else -> 7974 Else 7975 end. 7976 7977 7978