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