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_v1_test).
22
23%% TODO
24%% * Test fault-tolerance (kill master etc)
25%%
26
27-export([]).
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
37
38-define(klas1, [1,3,6,1,2,1,7]).
39-define(klas2, [1,3,6,1,2,1,9]).
40-define(klas3, [1,3,6,1,2,1,8,1]).
41-define(klas4, [1,3,6,1,2,1,8,4]).
42-define(sa, [1,3,6,1,4,1,193,2]).
43-define(system, [1,3,6,1,2,1,1]).
44-define(snmp, [1,3,6,1,2,1,11]).
45-define(snmpTraps, [1,3,6,1,6,3,1,1,5]).
46-define(ericsson, [1,3,6,1,4,1,193]).
47-define(testTrap, [1,3,6,1,2,1,15,0]).
48-define(xDescr, [1,3,6,1,2,1,17,1]).
49-define(xDescr2, [1,3,6,1,2,1,17,2]).
50
51-define(active, 1).
52-define(notInService, 2).
53-define(notReady, 3).
54-define(createAndGo, 4).
55-define(createAndWait, 5).
56-define(destroy, 6).
57
58-define(TRAP_UDP, 5000).
59
60-define(tooBigStr, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").
61
62
63%% -- test manager defines --
64-define(MGR,           snmp_test_mgr).
65-define(GN(X),         ?MGR:gn(X)).
66-define(G(X),          ?MGR:g(X)).
67-define(S(X),          ?MGR:s(X)).
68-define(GB(X),         ?MGR:gb(X)).
69-define(SEND_BYTES(X), ?MGR:send_bytes(X)).
70
71%% -- agent test lib defines --
72-define(LIB,                snmp_agent_test_lib).
73-define(INIT_CASE(X),       ?LIB:init_case(X)).
74-define(TRY_TEST1(A),       ?LIB:try_test(A)).
75-define(TRY_TEST2(A, B),    ?LIB:try_test(A, B)).
76-define(TRY_TEST3(A, B, C), ?LIB:try_test(A, B, C)).
77-define(START_SA(A, B, C),  ?LIB:start_subagent(A, B, C)).
78-define(STOP_SA(A),         ?LIB:stop_subagent(A)).
79-define(P1(C),              ?LIB:p(C)).
80-define(P2(F),              ?LIB:p(F,[])).
81-define(P3(F,A),            ?LIB:p(F,A)).
82-define(RPC(N, F, A),       ?LIB:rpc(N, F, A)).
83
84
85-define(v1_2(V1,V2),
86	       case get(vsn) of
87		   v1 -> V1;
88		   _ -> V2
89	       end).
90
91-define(v1_2_3(V1,V2,V3),
92	       case get(vsn) of
93		   v1 -> V1;
94		   v2 -> V2;
95		   _ -> V3
96	       end).
97
98all(suite) -> {req,
99	       [mnesia, distribution,
100		{local_slave_nodes, 2}, {time, 360}],
101	       [{conf, init, cases(), finish}]}.
102
103init_per_testcase(_Case, Config) when list(Config) ->
104    Dog = ?t:timetrap(?t:minutes(6)),
105    [{watchdog, Dog}|Config].
106
107end_per_testcase(_Case, Config) when list(Config) ->
108    Dog = ?config(watchdog, Config),
109    ?t:timetrap_cancel(Dog),
110    Config.
111
112cases() ->
113    [simple,
114     db_notify_client,
115     processing,
116     big,
117     big2,
118     %% implied,
119     loop_mib,
120     api,
121     subagent,
122     mnesia,
123     multiple_reqs,
124     sa_register,
125     v1_trap,
126     sa_error,
127     next_across_sa,
128     undo,
129     standard_mibs,
130     sparse_table,
131     cnt_64,
132     opaque,
133     %% opaque].
134
135     change_target_addr_config,
136
137     reported_bugs,
138     tickets
139    ].
140
141
142init(Config) ->
143    init_all(Config),
144    init_v1(Config).
145
146finish(Config) ->
147    finish_v1(Config),
148    finish_all(Config).
149
150init_v1(Config) when list(Config) ->
151    ?line SaNode = ?config(snmp_sa, Config),
152    ?line create_tables(SaNode),
153    ?line AgentDir = ?config(agent_dir, Config),
154    ?line MgrDir   = ?config(mgr_dir, Config),
155    ?line Ip       = ?config(ip, Config),
156    ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)),
157    [{vsn, v1} | start_v1_agent(Config)].
158
159finish_v1(Config) when list(Config) ->
160    delete_tables(),
161    C1 = stop_agent(Config),
162    delete_files(C1),
163    lists:keydelete(vsn, 1, C1).
164
165
166%%-----------------------------------------------------------------
167%% This function takes care of the old OTP-SNMPEA-MIB.
168%% Unfortunately, the testcases were written to use the data in the
169%% internal tables, and these table are now obsolete and not used
170%% by the agent.  Therefore, we emulate them by using
171%% OLD-SNMPEA-MIB, which uses the default impl. of all tables.
172%%
173%% These two rows must exist in intCommunityTable
174%%    {[147,214,36,45], "public", 2, readWrite}.
175%%    {[147,214,36,45], "standard trap", 2, read}.
176%% (But with the manager's IP address)
177%%
178%%-----------------------------------------------------------------
179init_old() ->
180    snmpa_local_db:table_create_row(intCommunityTable,
181                                   get(mip) ++ [6 | "public"],
182                                   {get(mip), "public", 2, 2}),
183    snmpa_local_db:table_create_row(intCommunityTable,
184                                   get(mip) ++ [13 | "standard trap"],
185                                   {get(mip), "standard trap", 2, 1}),
186    snmpa_local_db:variable_set(intAgentIpAddress, [127,0,0,1]).
187
188
189%% =========================================================================
190%%
191%%                                C A S E S
192%%
193%% =========================================================================
194
195%% -- simple --
196
197simple(suite) -> [];
198simple(Config) when list(Config) ->
199    ?P1(simple),
200    ?INIT_CASE(Config),
201
202    ?TRY_TEST1(simple_standard_test).
203
204simple_standard_test() ->
205    ?DBG("simple_standard_test -> entry",[]),
206    ?GN([[1,1]]),
207    ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]),
208
209    ?GN([[1,3]]),
210    ?line expect(11, [{[sysDescr,0], "Erlang SNMP agent"}]),
211
212    ?GN([[1,3,6]]),
213    ?line expect(12, [{[sysDescr,0], "Erlang SNMP agent"}]),
214
215    ?GN([[1,3,6,1]]),
216    ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}]),
217
218    ?GN([[1,3,6,1,2]]),
219    ?line expect(14, [{[sysDescr,0], "Erlang SNMP agent"}]),
220
221    ?GN([[1,3,6,1,2,1]]),
222    ?line expect(15, [{[sysDescr,0], "Erlang SNMP agent"}]),
223
224    ?GN([[1,3,6,1,2,1,1]]),
225    ?line expect(16, [{[sysDescr,0], "Erlang SNMP agent"}]),
226
227    ?GN([[sysDescr]]),
228    ?line expect(17, [{[sysDescr,0], "Erlang SNMP agent"}]),
229
230    ?G([[sysDescr,0]]),
231    ?line expect(2, [{[sysDescr,0], "Erlang SNMP agent"}]),
232
233    ?G([[sysDescr]]),
234    ?line ?v1_2(expect(3, noSuchName, 1, any),
235		expect(3, [{[sysDescr], noSuchObject}])),
236
237    ?G([[1,6,7,0]]),
238    ?line ?v1_2(expect(41, noSuchName, 1, any),
239		expect(3, [{[1,6,7,0], noSuchObject}])),
240
241    ?GN([[1,13]]),
242    ?line ?v1_2(expect(4, noSuchName,1, any),
243		expect(4, [{[1,13], endOfMibView}])),
244
245    ?S([{[sysLocation, 0], "new_value"}]),
246    ?line expect(5, [{[sysLocation, 0], "new_value"}]),
247
248    ?G([[sysLocation, 0]]),
249    ?line expect(6, [{[sysLocation, 0], "new_value"}]),
250
251    io:format("Testing noSuchName and badValue...~n"),
252    ?S([{[sysServices,0], 3}]),
253    ?line expect(61, ?v1_2(noSuchName, notWritable), 1, any),
254
255    ?S([{[sysLocation, 0], i, 3}]),
256    ?line expect(62, ?v1_2(badValue, wrongType), 1, any),
257    ?DBG("simple_standard_test -> done",[]),
258    ok.
259
260
261%% -- db_notify_client --
262
263%% This is run in the agent node
264db_notify_client(suite) -> [];
265db_notify_client(Config) when list(Config) ->
266    ?P1(db_notify_client),
267    {SaNode, MgrNode, MibDir} = ?INIT_CASE(Config),
268    ?DBG("~n\tSaNode: ~p~n\tMgrNode: ~p~n\tMibDir: ~p",
269	   [SaNode,MgrNode,MibDir]),
270    snmpa_local_db:register_notify_client(self(),?MODULE),
271
272    %% This call (the manager) will issue to set operations, so
273    %% we expect to receive to notify(insert) calls.
274    ?TRY_TEST1(db_notify_client_test),
275
276    ?DBG("await first notify",[]),
277    receive
278	{db_notify_test_reply,insert} -> ?DBG("first notify received",[]),ok
279    end,
280
281    ?DBG("await second notify",[]),
282    receive
283	{db_notify_test_reply,insert} -> ?DBG("second notify received",[]),ok
284    end,
285
286    snmpa_local_db:unregister_notify_client(self()).
287
288
289%% This is run in the manager node
290db_notify_client_test() ->
291    ?DBG("set first new sysLocation",[]),
292    ?S([{[sysLocation, 0], "new_value"}]),
293    ?line expect(5, [{[sysLocation, 0], "new_value"}]),
294
295    ?DBG("set second new sysLocation",[]),
296    ?S([{[sysLocation, 0], "new_value"}]),
297    ?line expect(5, [{[sysLocation, 0], "new_value"}]).
298
299notify(Pid,What) ->
300    ?DBG("notify(~p,~p) -> called",[Pid,What]),
301    Pid ! {db_notify_test_reply,What}.
302
303
304%% -- processing --
305
306%% Req. Test2
307processing(suite) -> [];
308processing(Config) when list(Config) ->
309    ?P1(processing),
310    ?INIT_CASE(Config),
311
312    ?line load_master("Test2"),
313    ?TRY_TEST1(v1_proc),
314    ?line unload_master("Test2").
315
316v1_proc() ->
317    ?DBG("v1_proc -> entry", []),
318    %% According to RFC1157.
319    %% Template: <Section>:<list no>
320    v1_get_p(),
321    v1_get_next_p(),
322    v1_set_p().
323
324v1_get_p() ->
325    %% 4.1.2:1
326    ?G([[test2]]),
327    ?line expect(10, noSuchName, 1, [{[test2], 'NULL'}]),
328    ?G([[tDescr]]),
329    ?line expect(11, noSuchName, 1, [{[tDescr], 'NULL'}]),
330    ?G([[tDescr2,0]]),
331    ?line expect(12, noSuchName, 1, [{[tDescr2,0], 'NULL'}]),
332    ?G([[tDescr3,0]]),
333    ?line expect(131, noSuchName, 1, [{[tDescr3,0], 'NULL'}]),
334    ?G([[tDescr4,0]]),
335    ?line expect(132, noSuchName, 1, [{[tDescr4,0], 'NULL'}]),
336    ?G([[sysDescr, 0], [tDescr,0]]), % Outside mibview
337    ?line expect(14, noSuchName, 2, [{[sysDescr, 0], 'NULL'},
338				     {[tDescr,0], 'NULL'}]),
339    ?G([[sysDescr,3]]),
340    ?line expect(15, noSuchName, 1, [{[sysDescr, 3], 'NULL'}]),
341
342    %% 4.1.2:2
343    ?G([[tTable]]),
344    ?line expect(20, noSuchName, 1, [{[tTable], 'NULL'}]),
345    ?G([[tEntry]]),
346    ?line expect(21, noSuchName, 1, [{[tEntry], 'NULL'}]),
347
348    %% 4.1.2:3
349    ?G([[tTooBig, 0]]),
350    ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]),
351
352    %% 4.1.2:4
353    ?G([[tGenErr1, 0]]),
354    ?line expect(40, genErr, 1, [{[tGenErr1, 0], 'NULL'}]),
355    ?G([[tGenErr2, 0]]),
356    ?line expect(41, genErr, 1, [{[tGenErr2, 0], 'NULL'}]),
357    ?G([[sysDescr, 0], [tGenErr3, 0]]),
358    ?line expect(42, genErr, 2, [{[sysDescr, 0], 'NULL'},
359				 {[tGenErr3, 0], 'NULL'}]).
360
361v1_get_next_p() ->
362    %% 4.1.3:1
363    ?GN([[1,3,7,1]]),
364    ?line expect(10, noSuchName, 1, [{[1,3,7,1], 'NULL'}]),
365
366    ?GN([[tDescr2]]),
367    ?line expect(11, tooBig, 0, any),
368
369    %% 4.1.3:2
370    ?GN([[tTooBig]]),
371    io:format("We currently don't handle tooBig correct!!!\n"),
372    %% ?line expect(20, tooBig, 0, [{[tTooBig], 'NULL'}]),
373    ?line expect(20, tooBig, 0, any),
374
375    %% 4.1.3:3
376    ?GN([[tGenErr1]]),
377    %% ?line expect(40, genErr, 1, [{[tGenErr1], 'NULL'}]),
378    ?line expect(40, genErr, 1, any),
379
380    ?GN([[tGenErr2]]),
381    %% ?line expect(41, genErr, 1, [{[tGenErr2], 'NULL'}]),
382    ?line expect(41, genErr, 1, any),
383
384    ?GN([[sysDescr], [tGenErr3]]),
385    %% ?line expect(42, genErr, 2, [{[sysDescr], 'NULL'},
386    %%	                            {[tGenErr3], 'NULL'}]).
387    ?line expect(42, genErr, 2, any).
388
389v1_set_p() ->
390    %% 4.1.5:1
391    ?S([{[1,3,7,0], i, 4}]),
392    ?line expect(10, noSuchName, 1, [{[1,3,7,0], 4}]),
393
394    ?S([{[tDescr,0], s, "outside mibview"}]),
395    ?line expect(11, noSuchName, 1, [{[tDescr,0], "outside mibview"}]),
396
397    ?S([{[tDescr3,0], s, "read-only"}]),
398    ?line expect(12, noSuchName, 1, [{[tDescr3,0], "read-only"}]),
399
400    ?S([{[tDescr3], s, "noSuchObject"}]),
401    ?line expect(13, noSuchName, 1, [{[tDescr3], "noSuchObject"}]),
402
403    ?S([{[tDescr3,1], s, "noSuchInstance"}]),
404    ?line expect(14, noSuchName, 1, [{[tDescr3,1], "noSuchInstance"}]),
405
406    ?S([{[tDescr2,0], s, "inconsistentName"}]),
407    ?line expect(15, noSuchName, 1, [{[tDescr2,0], "inconsistentName"}]),
408
409    %% 4.1.5:2
410    ?S([{[tDescr2, 0], i, 4}]),
411    ?line expect(20, badValue, 1, [{[tDescr2, 0], 4}]),
412
413    ?S([{[tDescr2, 0], s, "badValue"}]),
414    ?line expect(21, badValue, 1, [{[tDescr2, 0], "badValue"}]),
415
416    %% 4.1.5:3
417    %% The standard is quite incorrect here.  The resp pdu was too big.  In
418    %% the resp pdu, we have the original vbs.  In the tooBig pdu we still
419    %% have to original vbs => the tooBig pdu is too big as well!!!  It
420    %% may not get it to the manager, unless the agent uses 'NULL' instead
421    %% of the std-like original value.
422    ?S([{[tTooBig, 0], s, ?tooBigStr}]),
423    %% according to std:
424    %% ?line expect(30, tooBig, 0, [{[tTooBig, 0], ?tooBigStr}]),
425    ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]),
426
427    %% 4.1.5:4
428    ?S([{[tDescr2, 0], s, "is_set_ok_fail"}]),
429    ?line expect(40, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]),
430
431    ?S([{[tDescr2, 0], s, "commit_fail"}]),
432    ?line expect(41, genErr, 1, [{[tDescr2, 0], "commit_fail"}]).
433
434
435%% -- big --
436
437big(suite) -> [];
438big(Config) when list(Config) ->
439    ?P1(big),
440    {SaNode, _MgrNode, _MibDir} = ?INIT_CASE(Config),
441
442    p("Starting subagent..."),
443    ?line pong = net_adm:ping(SaNode),
444
445    ?line {ok, SA} = ?START_SA(SaNode, ?klas1, "Klas1"),
446    ?DBG("big -> SA: ~p", [SA]),
447    ?line load_master("OLD-SNMPEA-MIB"),
448    ?line init_old(),
449
450    ?TRY_TEST1(big_test),
451
452    ?line ?STOP_SA(SA),
453    ?line unload_master("OLD-SNMPEA-MIB").
454
455%% Req: system group, OLD-SNMPEA-MIB, Klas1
456big_test() ->
457    ?DBG("big_test -> testing simple next/get/set @ master agent...",[]),
458    simple_standard_test(),
459
460    ?DBG("big_test -> testing simple next/get/set @ subagent...",[]),
461    ?GN([[klas1]]),
462    ?line expect(1, [{[fname,0], ""}]),
463
464    ?G([[fname,0]]),
465    ?line expect(2, [{[fname,0], ""}]),
466
467    ?S([{[fname,0], s, "test set"}]),
468    ?line expect(3, [{[fname,0], "test set"}]),
469
470    ?G([[fname,0]]),
471    ?line expect(4, [{[fname,0], "test set"}]),
472
473    ?DBG("big_test -> "
474	"testing next from last instance in master to subagent...",[]),
475    ?GN([[?v1_2(sysServices, sysORLastChange),0]]),
476    ?line expect(5, [{[fname,0], "test set"}]),
477
478    ?GN([[1,1],
479	[?v1_2(sysServices, sysORLastChange),0]]),
480    ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"},
481		{[fname,0], "test set"}]),
482    ?S([{[fname,0], s, ""}]),
483    ?line expect(52, [{[fname,0], ""}]),
484
485    table_test(),
486
487    ?DBG("big_test -> adding one row in subagent table",[]),
488    _FTab = [friendsEntry],
489    ?S([{[friendsEntry, [2, 3]], s, "kompis3"},
490       {[friendsEntry, [3, 3]], i, ?createAndGo}]),
491    ?line expect(6, [{[friendsEntry, [2, 3]], "kompis3"},
492	       {[friendsEntry, [3, 3]], ?createAndGo}]),
493
494    ?G([[friendsEntry, [2, 3]],
495       [friendsEntry, [3, 3]]]),
496    ?line expect(7, [{[friendsEntry, [2, 3]], "kompis3"},
497		     {[friendsEntry, [3, 3]], ?active}]),
498
499    ?S([{[friendsEntry, [3, 3]], i, ?destroy}]),
500    ?line expect(8, [{[friendsEntry, [3, 3]], ?destroy}]),
501
502    otp_1131(),
503
504    ?DBG("big_test -> adding two rows in subagent table with special INDEX",
505       []),
506    ?S([{[kompissEntry, [1, 3]], s, "kompis3"},
507       {[kompissEntry, [2, 3]], i, ?createAndGo}]),
508    ?line expect(9, [{[kompissEntry, [1, 3]], "kompis3"},
509		     {[kompissEntry, [2, 3]], ?createAndGo}]),
510
511    ?G([[kompissEntry, [1, 3]],
512       [kompissEntry, [2, 3]]]),
513    ?line expect(10, [{[kompissEntry, [1, 3]], "kompis3"},
514		      {[kompissEntry, [2, 3]], ?active}]),
515
516    ?GN([[kompissEntry, [1]],
517	[kompissEntry, [2]]]),
518    ?line expect(11, [{[kompissEntry, [1, 3]], "kompis3"},
519		      {[kompissEntry, [2, 3]], ?active}]),
520
521    ?S([{[kompissEntry, [1, 2]], s, "kompis3"},
522       {[kompissEntry, [2, 2]], i, ?createAndGo}]),
523    ?line expect(12, [{[kompissEntry, [1, 2]], "kompis3"},
524		      {[kompissEntry, [2, 2]], ?createAndGo}]),
525
526    ?GN([[kompissEntry, [1, 1]],
527	[kompissEntry, [2, 1]]]),
528    ?line expect(13, [{[kompissEntry, [1, 2]], "kompis3"},
529		      {[kompissEntry, [2, 2]], ?active}]),
530
531    ?S([{[kompissEntry, [2, 3]], i, ?destroy}]),
532    ?line expect(14, [{[kompissEntry, [2, 3]], ?destroy}]),
533
534    ?S([{[kompissEntry, [2, 2]], i, ?destroy}]),
535    ?line expect(15, [{[kompissEntry, [2, 2]], ?destroy}]),
536    ?DBG("big_test -> done",[]),
537    ok.
538
539
540%% Req. system group, Klas2, OLD-SNMPEA-MIB
541big_test_2() ->
542    ?P1(big_test_2),
543
544    ?P2("Testing simple next/get/set @ master agent (2)..."),
545    simple_standard_test(),
546
547    p("Testing simple next/get/set @ subagent (2)..."),
548    ?GN([[klas2]]),
549    ?line expect(1, [{[fname2,0], ""}]),
550
551    ?G([[fname2,0]]),
552    ?line expect(2, [{[fname2,0], ""}]),
553
554    ?S([{[fname2,0], s, "test set"}]),
555    ?line expect(3, [{[fname2,0], "test set"}]),
556
557    ?G([[fname2,0]]),
558    ?line expect(4, [{[fname2,0], "test set"}]),
559
560    otp_1298(),
561
562    ?P2("Testing next from last object in master to subagent (2)..."),
563    ?GN([[?v1_2(sysServices, sysORLastChange),0]]),
564    ?line expect(5, [{[fname2,0], "test set"}]),
565
566    ?GN([[1,1],
567        [?v1_2(sysServices, sysORLastChange),0]]),
568    ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"},
569                {[fname2,0], "test set"}]),
570
571    table_test(),
572
573    ?P2("Adding one row in subagent table (2)"),
574    ?S([{[friendsEntry2, [2, 3]], s, "kompis3"},
575       {[friendsEntry2, [3, 3]], i, ?createAndGo}]),
576    ?line expect(6, [{[friendsEntry2, [2, 3]], "kompis3"},
577               {[friendsEntry2, [3, 3]], ?createAndGo}]),
578
579    ?G([[friendsEntry2, [2, 3]],
580       [friendsEntry2, [3, 3]]]),
581    ?line expect(7, [{[friendsEntry2, [2, 3]], "kompis3"},
582               {[friendsEntry2, [3, 3]], ?active}]),
583
584    ?S([{[friendsEntry2, [3, 3]], i, ?destroy}]),
585    ?line expect(8, [{[friendsEntry2, [3, 3]], ?destroy}]),
586
587    ?P2("Adding two rows in subagent table with special INDEX (2)"),
588    ?S([{[kompissEntry2, [1, 3]], s, "kompis3"},
589       {[kompissEntry2, [2, 3]], i, ?createAndGo}]),
590    ?line expect(9, [{[kompissEntry2, [1, 3]], "kompis3"},
591               {[kompissEntry2, [2, 3]], ?createAndGo}]),
592    ?G([[kompissEntry2, [1, 3]],
593       [kompissEntry2, [2, 3]]]),
594    ?line expect(10, [{[kompissEntry2, [1, 3]], "kompis3"},
595                {[kompissEntry2, [2, 3]], ?active}]),
596    ?GN([[kompissEntry2, [1]],
597        [kompissEntry2, [2]]]),
598    ?line expect(11, [{[kompissEntry2, [1, 3]], "kompis3"},
599                {[kompissEntry2, [2, 3]], ?active}]),
600
601    ?S([{[kompissEntry2, [1, 2]], s, "kompis3"},
602       {[kompissEntry2, [2, 2]], i, ?createAndGo}]),
603    ?line expect(12, [{[kompissEntry2, [1, 2]], "kompis3"},
604                {[kompissEntry2, [2, 2]], ?createAndGo}]),
605
606    ?GN([[kompissEntry2, [1, 1]],
607        [kompissEntry2, [2, 1]]]),
608    ?line expect(13, [{[kompissEntry2, [1, 2]], "kompis3"},
609                {[kompissEntry2, [2, 2]], ?active}]),
610
611    ?S([{[kompissEntry2, [2, 3]], i, ?destroy}]),
612    ?line expect(14, [{[kompissEntry2, [2, 3]], ?destroy}]),
613
614    ?S([{[kompissEntry2, [2, 2]], i, ?destroy}]),
615    ?line expect(15, [{[kompissEntry2, [2, 2]], ?destroy}]),
616    ok.
617
618
619%% -- bug2 --
620
621big2(suite) -> [];
622big2(Config) when list(Config) ->
623    ?P1(big2),
624    %% This is exactly the same tests as 'big', but with the
625    %% v2 equivalent of the mibs.
626    {SaNode, _MgrNode, _MibDir} = ?INIT_CASE(Config),
627
628    ?P2("Starting subagent..."),
629    ?line pong = net_adm:ping(SaNode),
630
631    ?line {ok, SA} = ?START_SA(SaNode, ?klas1, "Klas1-v2"),
632    ?line load_master("OLD-SNMPEA-MIB-v2"),
633    ?line init_old(),
634
635    ?TRY_TEST1(big_test),
636
637    ?line ?STOP_SUBAGENT(SA),
638    ?line unload_master("OLD-SNMPEA-MIB-v2").
639
640
641implied(suite) -> [];
642implied(Config) when list(Config) ->
643    ?P1(implied),
644    ?INIT_CASE(Config),
645
646    ?line load_master("Test1"),
647
648    ?TRY_TEST2(implied_test,[whereis(snmp_master_agent)]),
649
650    ?line unload_master("Test1").
651
652%% Req. Test1
653implied_test(MA) ->
654    ?LOG("implied_test -> start",[]),
655
656    snmpa:verbosity(MA,trace),
657    snmpa:verbosity(MA,trace),
658
659    %% Create two rows, check that they are get-nexted in correct order.
660    Idx1 = "apa",
661    Idx2 = "qq",
662
663    ?DBG("implied_test -> (send) create row 1 '~s' in table 1",[Idx1]),
664    ?S([{[testStatus, Idx1], i, ?createAndGo}, {[testDescr, Idx1],s,"row 1"}]),
665    ?line expect(1, [{[testStatus, Idx1], ?createAndGo},
666		     {[testDescr, Idx1], "row 1"}]),
667    ?DBG("implied_test -> (send) create row 2 '~s' in table 1",[Idx2]),
668
669    ?S([{[testStatus, Idx2], i, ?createAndGo}, {[testDescr, Idx2],s,"row 2"}]),
670    ?line expect(2, [{[testStatus, Idx2], ?createAndGo},
671		     {[testDescr, Idx2], "row 2"}]),
672    ?DBG("implied_test -> get-next(testDescr)",[]),
673
674    ?GN([[testDescr]]),
675    ?line expect(3, [{[testDescr,Idx1], "row 1"}]),
676    ?DBG("implied_test -> get-next(testDescr) of row 1",[]),
677
678    ?GN([[testDescr,Idx1]]),
679    ?line expect(4, [{[testDescr,Idx2], "row 2"}]),
680
681    % Delete the rows
682    ?DBG("implied_test -> (send) delete row 1 '~s' from table 1",[Idx1]),
683    ?S([{[testStatus, Idx1], i, ?destroy}]),
684    ?line expect(5, [{[testStatus, Idx1], ?destroy}]),
685
686    ?DBG("implied_test -> (send) delete row 2 '~s' from table 1",[Idx2]),
687    ?S([{[testStatus, Idx2], i, ?destroy}]),
688    ?line expect(6, [{[testStatus, Idx2], ?destroy}]),
689
690    %% Try the same in other table
691    Idx3 = [1, "apa"],
692    Idx4 = [1, "qq"],
693    ?DBG("implied_test -> (send) create row 1 '~s' in table 2",[Idx3]),
694    ?S([{[testStatus2, Idx3], i, ?createAndGo}, {[testDescr2,Idx3],s,"row 1"}]),
695    ?line expect(1, [{[testStatus2, Idx3], ?createAndGo},
696		     {[testDescr2, Idx3], "row 1"}]),
697
698    ?DBG("implied_test -> (send) create row 2 '~s' in table 2",[Idx4]),
699    ?S([{[testStatus2, Idx4], i, ?createAndGo},
700	{[testDescr2,Idx4],s,"row 2"}]),
701    ?line expect(2, [{[testStatus2, Idx4], ?createAndGo},
702		     {[testDescr2, Idx4], "row 2"}]),
703
704    ?DBG("implied_test -> get-next(testDescr2)",[]),
705    ?GN([[testDescr2]]),
706    ?line expect(3, [{[testDescr2,Idx3], "row 1"}]),
707    ?DBG("implied_test -> get-next(testDescr2) of row 1",[]),
708
709    ?GN([[testDescr2,Idx3]]),
710    ?line expect(4, [{[testDescr2,Idx4], "row 2"}]),
711
712    % Delete the rows
713    ?DBG("implied_test -> (send) delete row 1 '~s' from table 2",[Idx3]),
714    ?S([{[testStatus2, Idx3], i, ?destroy}]),
715    ?line expect(5, [{[testStatus2, Idx3], ?destroy}]),
716
717    ?DBG("implied_test -> (send) delete row 2 '~s' from table 2",[Idx4]),
718    ?S([{[testStatus2, Idx4], i, ?destroy}]),
719    ?line expect(6, [{[testStatus2, Idx4], ?destroy}]),
720
721    snmpa:verbosity(MA,log),
722
723    ?LOG("implied_test -> done",[]).
724
725
726%% -- loop_mib --
727
728%%-----------------------------------------------------------------
729%% Loop through entire MIB, to make sure that all instrum. funcs
730%% works.
731%% Load all std mibs that are not loaded by default.
732%%-----------------------------------------------------------------
733loop_mib(suite) -> [];
734loop_mib(Config) when list(Config) ->
735    ?P1(loop_mib),
736    %% snmpa:verbosity(master_agent,debug),
737    %% snmpa:verbosity(mib_server,info),
738    {SaNode, MgrNode, MibDir} = ?INIT_CASE(Config),
739    ?DBG("loop_mib -> "
740	 "~n   SaNode:  ~p"
741	 "~n   MgrNode: ~p"
742	 "~n   MibDir:  ~p", [SaNode, MgrNode, MibDir]),
743
744    ?DBG("loop_mib -> load mib SNMP-COMMUNITY-MIB",[]),
745    ?line load_master_std("SNMP-COMMUNITY-MIB"),
746    ?DBG("loop_mib -> load mib SNMP-MPD-MIB",[]),
747    ?line load_master_std("SNMP-MPD-MIB"),
748    ?DBG("loop_mib -> load mib SNMP-TARGET-MIB",[]),
749    ?line load_master_std("SNMP-TARGET-MIB"),
750    ?DBG("loop_mib -> load mib SNMP-NOTIFICATION-MIB",[]),
751    ?line load_master_std("SNMP-NOTIFICATION-MIB"),
752    ?DBG("loop_mib -> load mib SNMP-FRAMEWORK-MIB",[]),
753    ?line load_master_std("SNMP-FRAMEWORK-MIB"),
754    ?DBG("loop_mib -> load mib SNMP-VIEW-BASED-ACM-MIB",[]),
755    ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"),
756    ?DBG("loop_mib -> try",[]),
757
758    ?TRY_TEST1(loop_mib),
759
760    ?DBG("loop_mib -> unload mib SNMP-COMMUNITY-MIB",[]),
761    ?line unload_master("SNMP-COMMUNITY-MIB"),
762    ?DBG("loop_mib -> unload mib SNMP-MPD-MIB",[]),
763    ?line unload_master("SNMP-MPD-MIB"),
764    ?DBG("loop_mib -> unload mib SNMP-TARGET-MIB",[]),
765    ?line unload_master("SNMP-TARGET-MIB"),
766    ?DBG("loop_mib -> unload mib SNMP-NOTIFICATION-MIB",[]),
767    ?line unload_master("SNMP-NOTIFICATION-MIB"),
768    ?DBG("loop_mib -> unload mib SNMP-FRAMEWORK-MIB",[]),
769    ?line unload_master("SNMP-FRAMEWORK-MIB"),
770    ?DBG("loop_mib -> unload mib SNMP-VIEW-BASED-ACM-MIB",[]),
771    ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"),
772    %% snmpa:verbosity(master_agent,log),
773    %% snmpa:verbosity(mib_server,silence),
774    ?LOG("loop_mib -> done",[]).
775
776%% Req. As many mibs all possible
777loop_mib() ->
778    ?DBG("loop_mib -> entry",[]),
779    N = loop_it([1,1], 0),
780    ?P3("found ~w varibles\n", [N]),
781    ?line N = if N < 100 -> 100;
782		 true -> N
783	      end.
784
785loop_it(Oid, N) ->
786    ?DBG("loop_it -> entry with"
787	 "~n   Oid: ~p"
788	 "~n   N:   ~p", [Oid,N]),
789    case get_next_req([Oid]) of
790	#pdu{type='get-response', error_status=noError, error_index=0,
791	     varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid ->
792	    ?DBG("loop_it -> "
793		   "~n   NOid:  ~p"
794		   "~n   Value: ~p",[NOid,Value]),
795	    ?line [Value2] = get_req(1, [NOid]), % must not be same
796	    ?DBG("loop_it_1 -> "
797		 "~n   Value2: ~p",[Value2]),
798	    loop_it(NOid, N+1);
799
800	#pdu{type='get-response', error_status=noSuchName, error_index=1,
801	     varbinds=[_]} ->
802	    ?DBG("loop_it -> done",[]),
803	    N;
804
805	#pdu{type = Type, error_status = Err, error_index = Idx,
806	     varbinds = Vbs} ->
807	    exit({unexpected_pdu, ?LINE, Type, Err, Idx, Vbs})
808
809    end.
810
811
812%% -- api --
813
814api(suite) -> [];
815api(Config) when list(Config) ->
816    ?P1(api),
817    ?INIY_CASE(Config),
818
819    ?line load_master("OLD-SNMPEA-MIB"),
820    ?line init_old(),
821
822    ?TRY_TEST2(api_test, [node()]),
823
824    ?line unload_master("OLD-SNMPEA-MIB").
825
826%% Req. OLD-SNMPEA-MIB
827api_test(MaNode) ->
828    ?line {value, OID} = ?RPC(MaNode, name_to_oid, [intAgentIpAddress]),
829    ?line {value, intAgentIpAddress} = ?RPC(MaNode, oid_to_name, [OID]),
830    ?line false = ?RPC(MaNode, name_to_oid, [intAgentIpAddres]),
831    ?line false = ?RPC(MaNode, oid_to_name, [[1,5,32,3,54,3,3,34,4]]),
832    ?line {value, 2} = ?RPC(MaNode, enum_to_int, [intViewType, excluded]),
833    ?line {value, excluded} = ?RPC(MaNode, int_to_enum, [intViewType, 2]),
834    ?line false = ?RPC(MaNode, enum_to_int, [intViewType, exclude]),
835    ?line false = ?RPC(MaNode, enum_to_int, [intAgentIpAddress, exclude]),
836    ?line false = ?RPC(MaNode, enum_to_int, [intAgentIpAddre, exclude]),
837    ?line false = ?RPC(MaNode, int_to_enum, [intViewType, 3]),
838    ?line false = ?RPC(MaNode, int_to_enum, [intAgentIpAddress, 2]),
839    ?line false = ?RPC(MaNode, int_to_enum, [intAgentIpAddre, 2]),
840    ?line {value, active} = ?RPC(MaNode, int_to_enum, ['RowStatus', ?active]),
841    ?line {value, ?destroy} =
842	?RPC(MaNode, enum_to_int, ['RowStatus', destroy]),
843    ?line false = ?RPC(MaNode, enum_to_int, ['RowStatus', xxxdestroy]),
844    ?line false = ?RPC(MaNode, enum_to_int, ['xxRowStatus', destroy]),
845    ?line false = ?RPC(MaNode, int_to_enum, ['RowStatus', 25]),
846    ?line false = ?RPC(MaNode, int_to_enum, ['xxRowStatus', 1]),
847    ?line case snmp:date_and_time() of
848	      List when list(List), length(List) == 8 -> ok;
849	      List when list(List), length(List) == 11 -> ok
850    end.
851
852
853%% -- subagent --
854
855subagent(suite) -> [];
856subagent(Config) when list(Config) ->
857    ?P1(subagent),
858    {SaNode, _MgrNode, MibDir} = ?INIT_CASE(Config),
859
860    ?line {ok, SA} = ?START_SA(SaNode, ?klas1, "Klas1"),
861
862    ?TRY_TEST1(load_test_sa),
863
864    ?P2("Testing unregister subagent [~w]...", [SA]),
865    MA = whereis(snmp_master_agent),
866    ?RPC(SaNode, unregister_subagent, [MA, SA]),
867    ?TRY_TEST1(unreg_test),
868
869    ?P2("Loading previous subagent mib in master and testing..."),
870    ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas1"]),
871    ?TRY_TEST1(load_test),
872
873    ?P2("Unloading previous subagent mib in master and testing..."),
874    ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas1"]),
875
876    ?TRY_TEST1(unreg_test),
877
878    ?P2("Testing register subagent..."),
879    ?RPC(SaNode, register_subagent, [MA, ?klas1, SA]),
880    ?TRY_TEST1(load_test_sa),
881
882    ?line ?STOP_SA(SA),
883    ?TRY_TEST1(unreg_test).
884
885%% Req. Klas1
886load_test_sa() ->
887    ?GN([[?v1_2(sysServices,sysORLastChange), 0]]),
888    ?line expect(1, [{[fname,0], any}]).
889
890unreg_test() ->
891    ?GN([[?v1_2(sysServices, sysORLastChange),0]]),
892    ?line expect(1, [{[snmpInPkts, 0], any}]).
893
894load_test() ->
895    ?GN([[?v1_2(sysServices, sysORLastChange),0]]),
896    ?line expect(1, [{[fname,0], ""}]).
897
898
899%% -- mnesia --
900
901mnesia(suite) -> [];
902mnesia(Config) when list(Config) ->
903    {SaNode, _MgrNode, _MibDir} = init_case(Config),
904
905    p("Starting subagent with mnesia impl..."),
906    {ok, SA} = start_subagent(SaNode, ?klas2, "Klas2"),
907    ?line load_master("OLD-SNMPEA-MIB"),
908    ?line init_old(),
909
910    ?TRY_TEST1(big_test_2),
911
912    p("Testing unregister subagent..."),
913    MA = whereis(snmp_master_agent),
914    rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]),
915    ?TRY_TEST1(unreg_test),
916    ?line unload_master("OLD-SNMPEA-MIB"),
917    ?line stop_subagent(SA).
918
919
920%% -- multiple_reqs --
921
922multiple_reqs(suite) ->
923    {req, [], {conf, init_mul, mul_cases(), finish_mul}}.
924
925mul_cases() ->
926    [mul_get, mul_get_err, mul_next, mul_next_err, mul_set_err].
927
928init_mul(Config) when list(Config) ->
929    {SaNode, _MgrNode, _MibDir} = init_case(Config),
930
931    ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"),
932    ?line load_master("OLD-SNMPEA-MIB"),
933    ?line init_old(),
934    [{mul_sub, SA} | Config].
935
936finish_mul(Config) when list(Config) ->
937    {_SaNode, _MgrNode, _MibDir} = init_case(Config),
938
939    SA = ?config(mul_sub, Config),
940
941    ?line unload_master("OLD-SNMPEA-MIB"),
942    ?line stop_subagent(SA),
943    lists:keydelete(mul_sub, 1, Config).
944
945
946%% -- mul_get --
947
948mul_get(suite) -> [];
949mul_get(Config) when list(Config) ->
950    {_SaNode, _MgrNode, _MibDir} = init_case(Config),
951
952    p("Testing multiple get..."),
953    ?TRY_TEST1(do_mul_get).
954
955%% Req. system group, Klas1, OLD-SNMPEA-MIB
956do_mul_get() ->
957    Key1c3 = [intCommunityEntry,[3],get(mip),is("public")],
958    Key1c4 = [intCommunityEntry,[4],get(mip),is("public")],
959    s([{[fname,0], s, "test set"}]),
960    ?line expect(3, [{[fname,0], "test set"}]),
961    g([[sysDescr,0], Key1c4, [fname,0],Key1c3,
962	       [sysName,0]]),
963    ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"},
964		     {Key1c4, 2},
965		     {[fname,0], "test set"},
966		     {Key1c3, 2},
967		     {[sysName,0], "test"}]),
968    g([[1,3,7,1], Key1c4, [sysDescr,0], [1,3,7,2], Key1c3, [sysDescr,0]]),
969    ?line ?v1_2(expect(2, noSuchName, [1,4], any),
970		expect(2, [{[1,3,7,1], noSuchObject},
971			   {Key1c4, 2},
972			   {[sysDescr,0], "Erlang SNMP agent"},
973			   {[1,3,7,2], noSuchObject},
974			   {Key1c3, 2},
975			   {[sysDescr,0], "Erlang SNMP agent"}])).
976
977
978%% -- mul_get_err --
979
980mul_get_err(suite) -> [];
981mul_get_err(Config) when list(Config) ->
982    {_SaNode, _MgrNode, _MibDir} = init_case(Config),
983
984    p("Testing multiple get with error..."),
985    ?TRY_TEST1(do_mul_get_err).
986
987%% Req. v1, system group, Klas1, OLD-SNMPEA-MIB, *ej* Klas3.
988do_mul_get_err() ->
989    Key1c3 = [intCommunityEntry,[3],get(mip),is("public")],
990    Key1c4 = [intCommunityEntry,[4],get(mip),is("public")],
991    s([{[fname,0], s, "test set"}]),
992    ?line expect(3, [{[fname,0], "test set"}]),
993    g([[sysDescr,0],Key1c4,[fname,0], Key1c3, [sysName,2]]),
994    ?line ?v1_2(expect(1, noSuchName, 5, any),
995		expect(1, [{[sysDescr,0], "Erlang SNMP agent"},
996			   {Key1c4, 2},
997			   {[fname,0], "test set"},
998			   {Key1c3, 2},
999			   {[sysName,2], noSuchInstance}])),
1000    g([[sysDescr,0],Key1c4,[fname3,0], Key1c3, [sysName,1]]),
1001    ?line ?v1_2(expect(1, noSuchName, [3,5], any),
1002		expect(1, [{[sysDescr,0], "Erlang SNMP agent"},
1003			   {Key1c4, 2},
1004			   {[fname3,0], noSuchObject},
1005			   {Key1c3, 2},
1006			   {[sysName,1], noSuchInstance}])).
1007
1008
1009%% -- mul_next --
1010
1011mul_next(suite) -> [];
1012mul_next(Config) when list(Config) ->
1013    {_SaNode, _MgrNode, _MibDir} = init_case(Config),
1014
1015    p("Testing multiple next..."),
1016    ?TRY_TEST1(do_mul_next).
1017
1018%% Req. system group, Klas1, OLD-SNMPEA-MIB
1019do_mul_next() ->
1020    Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")],
1021    Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")],
1022    Key1c3 = [intCommunityEntry,[3],get(mip),is("public")],
1023    Key1c4 = [intCommunityEntry,[4],get(mip),is("public")],
1024    s([{[fname,0], s, "test set"}]),
1025    ?line expect(3, [{[fname,0], "test set"}]),
1026    gn([[sysDescr], Key1c4s, [fname],Key1c3s,[sysName]]),
1027    ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"},
1028	       {Key1c4, 2}, {[fname,0], "test set"},
1029	       {Key1c3, 2}, {[sysName,0], "test"}]).
1030
1031
1032%% -- mul_next_err --
1033
1034mul_next_err(suite) -> [];
1035mul_next_err(Config) when list(Config) ->
1036    {_SaNode, _MgrNode, _MibDir} = init_case(Config),
1037
1038    p("Testing multiple next..."),
1039    ?TRY_TEST1(do_mul_next_err).
1040
1041%% Req. system group, Klas1, OLD-SNMPEA-MIB
1042do_mul_next_err() ->
1043    Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")],
1044    Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")],
1045    Key1c3 = [intCommunityEntry,[3],get(mip),is("public")],
1046    Key1c4 = [intCommunityEntry,[4],get(mip),is("public")],
1047    s([{[fname,0], s, "test set"}]),
1048    ?line expect(3, [{[fname,0], "test set"}]),
1049    gn([[sysDescr], Key1c4s, [1,3,6,999], [fname],[1,3,90], Key1c3s,[sysName]]),
1050    ?line ?v1_2(expect(1, noSuchName, [3,5], any),
1051		expect(1, [{[sysDescr,0], "Erlang SNMP agent"},
1052			   {Key1c4, 2},
1053			   {[1,3,6,999], endOfMibView},
1054			   {[fname,0], "test set"},
1055			   {[1,3,90], endOfMibView},
1056			   {Key1c3, 2},
1057			   {[sysName,0], "test"}])).
1058
1059
1060%% -- mul_set --
1061
1062mul_set(suite) -> [];
1063mul_set(Config) when list(Config) ->
1064    ?P(mul_set),
1065    ?INIT_CASE(Config),
1066
1067    ?TRY_TEST1(do_mul_set).
1068
1069%% Req. system group, Klas1, OLD-SNMPEA-MIB
1070do_mul_set() ->
1071    p("Adding one row in subagent table, and one in master table"),
1072    NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")],
1073    NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")],
1074    NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")],
1075    s([{[friendsEntry, [2, 3]], "kompis3"},
1076       {NewKeyc3, 2},
1077       {[sysLocation,0], "new_value"},
1078       {NewKeyc5, ?createAndGo},
1079       {NewKeyc4, 2},
1080       {[friendsEntry, [3, 3]], ?createAndGo}]),
1081    ?line expect(1, [{[friendsEntry, [2, 3]], "kompis3"},
1082	       {NewKeyc3, 2},
1083	       {[sysLocation,0], "new_value"},
1084	       {NewKeyc5, ?createAndGo},
1085	       {NewKeyc4, 2},
1086	       {[friendsEntry, [3, 3]], ?createAndGo}]),
1087    g([[friendsEntry, [2, 3]],
1088	       [sysLocation,0],
1089	       [friendsEntry, [3, 3]]]),
1090    ?line expect(2, [{[friendsEntry, [2, 3]], "kompis3"},
1091	       {[sysLocation,0], "new_value"},
1092	       {[friendsEntry, [3, 3]], ?active}]),
1093    g([NewKeyc4]),
1094    ?line expect(3, [{NewKeyc4, 2}]),
1095    s([{[friendsEntry, [3, 3]], ?destroy},
1096       {NewKeyc5, ?destroy}]),
1097    ?line expect(4, [{[friendsEntry, [3, 3]], ?destroy},
1098	       {NewKeyc5, ?destroy}]).
1099
1100
1101%% -- mul_set_err --
1102
1103mul_set_err(suite) -> [];
1104mul_set_err(Config) when list(Config) ->
1105    ?P(mul_set_err),
1106    ?INIT_CASE(Config),
1107
1108    ?TRY_TEST1(do_mul_set_err).
1109
1110%% Req. system group, Klas1, OLD-SNMPEA-MIB
1111do_mul_set_err() ->
1112    NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")],
1113    NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")],
1114    NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")],
1115    p("Adding one row in subagent table, and one in master table"),
1116    s([{[friendsEntry, [2, 3]], s, "kompis3"},
1117       {NewKeyc3, 2},
1118       {[sysUpTime,0], 45},   % sysUpTime (readOnly)
1119       {NewKeyc5, ?createAndGo},
1120       {NewKeyc4, 2},
1121       {[friendsEntry, [3, 3]], ?createAndGo}]),
1122    ?line expect(1, ?v1_2(noSuchName, notWritable), 3, any),
1123    g([[friendsEntry, [2, 3]]]),
1124    ?line ?v1_2(expect(2, noSuchName, 1, any),
1125		expect(2, [{[friendsEntry, [2,3]], noSuchInstance}])),
1126    g([NewKeyc4]),
1127    ?line ?v1_2(expect(3, noSuchName, 1, any),
1128		expect(3, [{NewKeyc4, noSuchInstance}])).
1129
1130
1131%% -- sa_register --
1132
1133sa_register(suite) -> [];
1134sa_register(Config) when list(Config) ->
1135    ?P1(sa_register),
1136    {SaNode, _MgrNode, MibDir} = ?INIT_CASE(Config),
1137
1138    ?DBG("sa_register -> start subagent", []),
1139    ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"),
1140
1141    ?DBG("sa_register -> unregister subagent", []),
1142    ?P2("Testing unregister subagent (2)..."),
1143    MA = whereis(snmp_master_agent),
1144    rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]),
1145    ?TRY_TEST1(unreg_test),
1146
1147    ?P2("Loading SA-MIB..."),
1148    ?DBG("sa_register -> unload mibs", []),
1149    snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]),
1150    ?DBG("sa_register -> unload mibs", []),
1151    snmpa:load_mibs(SA, [MibDir ++ "SA-MIB"]),
1152    ?DBG("sa_register -> register subagent", []),
1153    rpc:call(SaNode, snmp, register_subagent, [MA,?sa,SA]),
1154    ?TRY_TEST1(sa_mib),
1155
1156    ?DBG("sa_register -> stop subagent", []),
1157    ?line stop_subagent(SA).
1158
1159%% Req. SA-MIB
1160sa_mib() ->
1161    g([[sa, [2,0]]]),
1162    ?line expect(1, [{[sa, [2,0]], 3}]),
1163    s([{[sa, [1,0]], s, "sa_test"}]),
1164    ?line expect(2, [{[sa, [1,0]], "sa_test"}]).
1165
1166
1167%% -- v1_trap --
1168
1169v1_trap(suite) -> [];
1170v1_trap(Config) when list(Config) ->
1171    {SaNode, _MgrNode, _MibDir} = init_case(Config),
1172
1173    ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"),
1174
1175    p("Testing trap sending from master agent..."),
1176    MA = whereis(snmp_master_agent),
1177
1178    ?line load_master("TestTrap"),
1179    ?line load_master("TestTrapv2"),
1180
1181    ?TRY_TEST2(ma_trap1, [MA]),
1182    ?TRY_TEST2(ma_trap2, [MA]),
1183    ?TRY_TEST2(ma_v2_2_v1_trap, [MA]),
1184    ?TRY_TEST2(ma_v2_2_v1_trap2, [MA]),
1185
1186    p("Testing trap sending from subagent..."),
1187    ?TRY_TEST2(sa_trap1, [SA]),
1188    ?TRY_TEST2(sa_trap2, [SA]),
1189    ?TRY_TEST2(sa_trap3, [SA]),
1190
1191    ?line unload_master("TestTrap"),
1192    ?line unload_master("TestTrapv2"),
1193
1194    ?line stop_subagent(SA).
1195
1196ma_trap1(MA) ->
1197    snmpa:send_trap(MA, testTrap2, "standard trap"),
1198    ?line expect(1, trap, [system], 6, 1, [{[system, [4,0]],
1199				    "{mbj,eklas}@erlang.ericsson.se"}]),
1200    snmpa:send_trap(MA, testTrap1, "standard trap"),
1201    ?line expect(2, trap, [1,2,3] , 1, 0, [{[system, [4,0]],
1202				      "{mbj,eklas}@erlang.ericsson.se"}]).
1203
1204ma_trap2(MA) ->
1205    snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]),
1206    ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]).
1207
1208ma_v2_2_v1_trap(MA) ->
1209    snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]),
1210    ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]).
1211
1212ma_v2_2_v1_trap2(MA) ->
1213    snmpa:send_trap(MA,linkUp,"standard trap",[{ifIndex, [1], 1},
1214					      {ifAdminStatus, [1], 1},
1215					      {ifOperStatus, [1], 2}]),
1216    ?line expect(3, trap, [1,2,3], 3, 0, [{[ifIndex, 1], 1},
1217					 {[ifAdminStatus, 1], 1},
1218					 {[ifOperStatus, 1], 2}]).
1219
1220sa_trap1(SA) ->
1221    snmpa:send_trap(SA, saTrap, "standard trap"),
1222    ?line expect(4, trap, [ericsson], 6, 1, [{[system, [4,0]],
1223				      "{mbj,eklas}@erlang.ericsson.se"},
1224				     {[sa, [1,0]], "sa_test"}]).
1225
1226sa_trap2(SA) ->
1227    snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]),
1228    ?line expect(5, trap, [ericsson], 6, 1, [{[system, [4,0]],
1229				      "pelle"},
1230				     {[sa, [1,0]], "sa_test"}]).
1231
1232sa_trap3(SA) ->
1233    snmpa:send_trap(SA, saTrap2, "standard trap",
1234			 [{intViewSubtree, [4], [1,2,3,4]}]),
1235    ?line expect(6, trap, [ericsson], 6, 2, [{[system, [4,0]],
1236				      "{mbj,eklas}@erlang.ericsson.se"},
1237				     {[sa, [1,0]], "sa_test"},
1238				     {[intViewSubtree,4],[1,2,3,4]}]).
1239
1240ma_v2_trap1(MA) ->
1241    ?DBG("ma_v2_traps -> entry with MA = ~p => "
1242	   "send standard trap: testTrapv22",[MA]),
1243    snmpa:send_trap(MA, testTrapv22, "standard trap"),
1244    ?line expect(1, v2trap, [{[sysUpTime, 0], any},
1245			     {[snmpTrapOID, 0], ?system ++ [0,1]}]),
1246    ?DBG("ma_v2_traps -> send standard trap: testTrapv21",[]),
1247    snmpa:send_trap(MA, testTrapv21, "standard trap"),
1248    ?line expect(2, v2trap, [{[sysUpTime, 0], any},
1249			     {[snmpTrapOID, 0], ?snmp ++ [1]}]).
1250
1251ma_v2_trap2(MA) ->
1252    snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]),
1253    ?line expect(3, v2trap, [{[sysUpTime, 0], any},
1254			     {[snmpTrapOID, 0], ?system ++ [0,1]},
1255			     {[system, [4,0]], "pelle"}]).
1256
1257ma_v1_2_v2_trap(MA) ->
1258    snmpa:send_trap(MA,linkDown,"standard trap",[{ifIndex, [1], 1}]),
1259    ?line expect(2, v2trap, [{[sysUpTime, 0], any},
1260			     {[snmpTrapOID, 0], ?snmpTraps ++ [3]},
1261			     {[ifIndex, 1], 1},
1262			     {[snmpTrapEnterprise, 0], [1,2,3]}]).
1263
1264
1265ma_v1_2_v2_trap2(MA) ->
1266    snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]),
1267    ?line expect(3, v2trap, [{[sysUpTime, 0], any},
1268			     {[snmpTrapOID, 0], ?system ++ [0,1]},
1269			     {[system, [4,0]], "pelle"},
1270			     {[snmpTrapEnterprise, 0], ?system}]).
1271
1272
1273sa_v1_2_v2_trap1(SA) ->
1274    snmpa:send_trap(SA, saTrap, "standard trap"),
1275    ?line expect(4, v2trap, [{[sysUpTime, 0], any},
1276			     {[snmpTrapOID, 0], ?ericsson ++ [0, 1]},
1277			     {[system, [4,0]],
1278			      "{mbj,eklas}@erlang.ericsson.se"},
1279			     {[sa, [1,0]], "sa_test"},
1280			     {[snmpTrapEnterprise, 0], ?ericsson}]).
1281
1282sa_v1_2_v2_trap2(SA) ->
1283    snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]),
1284    ?line expect(4, v2trap, [{[sysUpTime, 0], any},
1285			     {[snmpTrapOID, 0], ?ericsson ++ [0, 1]},
1286			     {[system, [4,0]], "pelle"},
1287			     {[sa, [1,0]], "sa_test"},
1288			     {[snmpTrapEnterprise, 0], ?ericsson}]).
1289
1290
1291sa_v1_2_v2_trap3(SA) ->
1292    snmpa:send_trap(SA, saTrap2, "standard trap",
1293			 [{intViewSubtree, [4], [1,2,3,4]}]),
1294    ?line expect(4, v2trap, [{[sysUpTime, 0], any},
1295			     {[snmpTrapOID, 0], ?ericsson ++ [0, 2]},
1296			     {[system, [4,0]],
1297			      "{mbj,eklas}@erlang.ericsson.se"},
1298			     {[sa, [1,0]], "sa_test"},
1299			     {[intViewSubtree,4],[1,2,3,4]},
1300			     {[snmpTrapEnterprise, 0], ?ericsson}]).
1301
1302
1303%% -- sa_error --
1304
1305sa_error(suite) -> [];
1306sa_error(Config) when list(Config) ->
1307    {SaNode, _MgrNode, _MibDir} = init_case(Config),
1308
1309    ?line load_master("OLD-SNMPEA-MIB"),
1310    ?line init_old(),
1311    ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"),
1312
1313    p("Testing sa bad value (is_set_ok)..."),
1314    ?TRY_TEST1(sa_errs_bad_value),
1315
1316    p("Testing sa gen err (set)..."),
1317    ?TRY_TEST1(sa_errs_gen_err),
1318
1319    p("Testing too big..."),
1320    ?TRY_TEST1(sa_too_big),
1321
1322    ?line unload_master("OLD-SNMPEA-MIB"),
1323    stop_subagent(SA).
1324
1325%% Req. SA-MIB, OLD-SNMPEA-MIB
1326sa_errs_bad_value() ->
1327    NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")],
1328    NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")],
1329    NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")],
1330    s([{NewKeyc3, 2},
1331       {[sa, [2,0]], 5}, % badValue (i is_set_ok)
1332       {NewKeyc5, ?createAndGo},
1333       {NewKeyc4, 2}]),
1334    ?line expect(1, badValue, 2, any),
1335    s([{NewKeyc3, 2},
1336       {[sa, [2,0]], 6}, % wrongValue (i is_set_ok)
1337       {NewKeyc5, ?createAndGo},
1338       {NewKeyc4, 2}]),
1339    ?line expect(1, ?v1_2(badValue, wrongValue), 2, any),
1340    g([NewKeyc4]),
1341    ?line ?v1_2(expect(2, noSuchName, 1, any),
1342		expect(2, [{NewKeyc4, noSuchInstance}])).
1343
1344%% Req. SA-MIB, OLD-SNMPEA-MIB
1345sa_errs_gen_err() ->
1346    NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")],
1347    NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")],
1348    NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")],
1349    s([{NewKeyc3, 2},{NewKeyc4, 2},
1350       {NewKeyc5, ?createAndGo}, {[sa, [3,0]], 5}]),
1351    ?line expect(1, genErr, 4, any),
1352% The row might have been added; we don't know.
1353% (as a matter of fact we do - it is added, because the agent
1354% first sets its own vars, and then th SAs. Lets destroy it.
1355    s([{NewKeyc5, ?destroy}]),
1356    ?line expect(2, [{NewKeyc5, ?destroy}]).
1357
1358%% Req. SA-MIB, OLD-SNMPEA-MIB
1359sa_too_big() ->
1360    g([[sa, [4,0]]]),
1361    ?line expect(1, tooBig).
1362
1363
1364%% -- next_across_sa --
1365
1366next_across_sa(suite) -> [];
1367next_across_sa(Config) when list(Config) ->
1368    {SaNode, _MgrNode, MibDir} = init_case(Config),
1369    MA = whereis(snmp_master_agent),
1370
1371    ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"),
1372
1373    p("Loading another subagent mib..."),
1374    ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas1"]),
1375
1376    rpc:call(SaNode, snmp, register_subagent, [MA, ?klas1, SA]),
1377    ?TRY_TEST1(load_test_sa),
1378
1379    p("Testing next across subagent (endOfMibView from SA)..."),
1380    ?TRY_TEST1(next_across_sa),
1381
1382    p("Unloading mib"),
1383    snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]),
1384    rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]),
1385    ?TRY_TEST1(unreg_test),
1386
1387    p("Starting another subagent"),
1388    ?line {ok, SA2} = start_subagent(SaNode, ?klas1, "Klas1"),
1389    p("Testing next across subagent (wrong prefix from SA)..."),
1390    ?TRY_TEST1(next_across_sa),
1391
1392    stop_subagent(SA),
1393    stop_subagent(SA2).
1394
1395%% Req. Klas1, system group, snmp group (v1/v2)
1396next_across_sa() ->
1397    gn([[sysDescr],[klas1,5]]),
1398    ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"},
1399		     {[snmpInPkts, 0], any}]).
1400
1401
1402%% -- undo --
1403
1404undo(suite) -> [];
1405undo(Config) when list(Config) ->
1406    {SaNode, _MgrNode, MibDir} = init_case(Config),
1407    MA = whereis(snmp_master_agent),
1408
1409    ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"),
1410
1411    p("Testing undo phase at master agent..."),
1412    ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas3"]),
1413    ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas4"]),
1414    ?TRY_TEST1(undo_test),
1415    ?TRY_TEST1(api_test2),
1416    ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas3"]),
1417
1418    p("Testing bad return values from instrum. funcs..."),
1419    ?TRY_TEST1(bad_return),
1420
1421    ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas4"]),
1422
1423    p("Testing undo phase at subagent..."),
1424    ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas3"]),
1425    ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas4"]),
1426    ?line ok = snmpa:register_subagent(MA, ?klas3, SA),
1427    ?line ok = snmpa:register_subagent(MA, ?klas4, SA),
1428    ?TRY_TEST1(undo_test),
1429    ?TRY_TEST1(api_test3),
1430
1431    p("Testing undo phase across master/subagents..."),
1432    ?TRY_TEST1(undo_test),
1433    ?TRY_TEST1(api_test3),
1434    stop_subagent(SA).
1435
1436%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]). -> noError
1437%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]). -> {badValue, 2}
1438%% snmp_test_mgr:s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]). -> {genErr, 1}
1439%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]). -> {genErr, 1}
1440%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]). -> {genErr, 1}
1441%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]). -> {genErr, 2}
1442%% Req. Klas3, Klas4
1443undo_test() ->
1444    s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]),
1445    ?line expect(1, [{[fStatus3, 1], 4}, {[fname3,0], "ok"}]),
1446    s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]),
1447    ?line expect(2, ?v1_2(badValue, inconsistentValue), 2, any),
1448    s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]),
1449    ?line expect(3, ?v1_2(genErr, undoFailed), 1, any),
1450    s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]),
1451    ?line expect(4, ?v1_2(genErr, commitFailed), 1, any),
1452    %% unfortunatly we don't know if we'll get undoFailed or commitFailed.
1453    %% it depends on which order the agent traverses the varbind list.
1454    %%    s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]),
1455    %%    ?line expect(5, ?v1_2(genErr, undoFailed), 1, any),
1456    s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]),
1457    ?line expect(6, genErr, 2, any).
1458
1459%% Req. Klas3, Klas4
1460bad_return() ->
1461    g([[fStatus4,4],
1462       [fName4,4]]),
1463    ?line expect(4, genErr, 2, any),
1464    g([[fStatus4,5],
1465       [fName4,5]]),
1466    ?line expect(5, genErr, 1, any),
1467    g([[fStatus4,6],
1468       [fName4,6]]),
1469    ?line expect(6, genErr, 2, any),
1470    gn([[fStatus4,7],
1471       [fName4,7]]),
1472    ?line expect(7, genErr, 2, any),
1473    gn([[fStatus4,8],
1474       [fName4,8]]),
1475    ?line expect(8, genErr, 1, any),
1476    gn([[fStatus4,9],
1477       [fName4,9]]),
1478    ?line expect(9, genErr, 2, any).
1479
1480
1481%% -- standard_mibs --
1482
1483%%%-----------------------------------------------------------------
1484%%% Test the implementation of standard mibs.
1485%%% We should *at least* try to GET all variables, just to make
1486%%% sure the instrumentation functions work.
1487%%% Note that many of the functions in the standard mib is
1488%%% already tested by the normal tests.
1489%%%-----------------------------------------------------------------
1490standard_mibs(suite) ->
1491    [snmp_standard_mib,
1492     snmp_community_mib,
1493     snmp_framework_mib,
1494     snmp_target_mib,
1495     snmp_notification_mib,
1496     snmp_view_based_acm_mib].
1497
1498
1499%% -- snmp_standard_mib --
1500
1501%%-----------------------------------------------------------------
1502%% For this test, the agent is configured for v1.
1503%% o  Test the counters and control objects in SNMP-STANDARD-MIB
1504%%-----------------------------------------------------------------
1505snmp_standard_mib(suite) -> [];
1506snmp_standard_mib(Config) when list(Config) ->
1507    {_SaNode, _MgrNode, _MibDir} = init_case(Config),
1508    ?DBG("snmp_standard_mib -> std_mib_init", []),
1509    ?TRY_TEST1(std_mib_init),
1510
1511    ?DBG("snmp_standard_mib -> std_mib_a", []),
1512    InBadVsns = ?TRY_TEST1(std_mib_a),
1513    put(vsn, v2),
1514    ?DBG("snmp_standard_mib -> std_mib_read", []),
1515    ?TRY_TEST1(std_mib_read),
1516    put(vsn, v1),
1517
1518    ?DBG("snmp_standard_mib -> std_mib_b (~w)", [InBadVsns]),
1519    Bad = ?TRY_TEST2(std_mib_b, [InBadVsns]),
1520    ?DBG("snmp_standard_mib -> std_mib_read (community: 'bad community')", []),
1521    ?TRY_TEST3(std_mib_read, [], [{community, "bad community"}]),
1522    ?DBG("snmp_standard_mib -> std_mib_write (community: 'public')", []),
1523    ?TRY_TEST3(std_mib_write, [], [{community, "public"}]),
1524    ?DBG("snmp_standard_mib -> std_mib_asn_err", []),
1525    ?TRY_TEST1(std_mib_asn_err),
1526    ?DBG("snmp_standard_mib -> std_mib_c (~w)", [Bad]),
1527    ?TRY_TEST2(std_mib_c, [Bad]),
1528    ?DBG("snmp_standard_mib -> std_mib_a", []),
1529    ?TRY_TEST1(standard_mib_a),
1530
1531    ?DBG("snmp_standard_mib -> std_mib_finish", []),
1532    ?TRY_TEST1(std_mib_finish),
1533    ?DBG("snmp_standard_mib -> std_mib_test_finish", []),
1534    ?TRY_TEST3(standard_mib_test_finish, [], [{community, "bad community"}]).
1535
1536%% Req. SNMP-STANDARD-MIB
1537standard_mib_a() ->
1538    ?line [OutPkts] = get_req(2, [[snmpOutPkts,0]]),
1539    ?line [OutPkts2] = get_req(3, [[snmpOutPkts,0]]),
1540    ?line OutPkts2 = OutPkts + 1,
1541    %% There are some more counters we could test here, but it's not that
1542    %% important, since they are removed from SNMPv2-MIB.
1543    ok.
1544
1545%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB
1546std_mib_init() ->
1547    %% disable authentication failure traps.  (otherwise w'd get many of
1548    %% them - this is also a test to see that it works).
1549    s([{[snmpEnableAuthenTraps,0], 2}]),
1550    ?line expect(1, [{[snmpEnableAuthenTraps, 0], 2}]).
1551
1552%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB
1553std_mib_finish() ->
1554    %% enable again
1555    s([{[snmpEnableAuthenTraps,0], 1}]),
1556    ?line expect(1, [{[snmpEnableAuthenTraps, 0], 1}]).
1557
1558%% Req. SNMP-STANDARD-MIB
1559standard_mib_test_finish() ->
1560    %% force a authenticationFailure
1561    std_mib_write(),
1562    %% check that we got a trap
1563    ?line expect(2, trap, [1,2,3], 4, 0, []).
1564
1565%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB
1566std_mib_read() ->
1567    ?DBG("std_mib_read -> entry", []),
1568    g([[sysUpTime,0]]), % try a bad <something>; msg dropped, no reply
1569    ?DBG("std_mib_read -> await timeout (i.e. no reply)", []),
1570    ?line expect(1, timeout). % make sure we don't get a trap!
1571
1572
1573%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB
1574std_mib_write() ->
1575    ?DBG("std_mib_write -> entry", []),
1576    s([{[sysLocation, 0], "new_value"}]).
1577
1578%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB
1579std_mib_asn_err() ->
1580    ?SEND_BYTES([48,99,67,12,0,0,0,0,0,0,5]).
1581
1582%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB
1583std_mib_a() ->
1584    ?line [InPkts] = get_req(2, [[snmpInPkts,0]]),
1585    ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]),
1586    ?line InPkts2 = InPkts + 1,
1587
1588    ?line [InBadVsns] = get_req(4, [[snmpInBadVersions,0]]),
1589    InBadVsns.
1590
1591%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB
1592std_mib_b(InBadVsns) ->
1593    ?line [InBadVsns2] = get_req(1, [[snmpInBadVersions,0]]),
1594    ?line InBadVsns2 = InBadVsns + 1,
1595    ?line [InPkts] = get_req(2, [[snmpInPkts,0]]),
1596    ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]),
1597    ?line InPkts2 = InPkts + 1,
1598    ?line [InBadCommunityNames, InBadCommunityUses, InASNErrs] =
1599	get_req(4, [[snmpInBadCommunityNames,0],
1600		    [snmpInBadCommunityUses,0],
1601		    [snmpInASNParseErrs, 0]]),
1602    {InBadCommunityNames, InBadCommunityUses, InASNErrs}.
1603
1604%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB
1605std_mib_c({InBadCommunityNames, InBadCommunityUses, InASNErrs}) ->
1606    ?line [InBadCommunityNames2, InBadCommunityUses2, InASNErrs2] =
1607	get_req(1, [[snmpInBadCommunityNames,0],
1608		    [snmpInBadCommunityUses,0],
1609		    [snmpInASNParseErrs, 0]]),
1610    ?line InBadCommunityNames2 = InBadCommunityNames + 1,
1611    ?line InBadCommunityUses2 = InBadCommunityUses + 1,
1612    ?line InASNErrs2 = InASNErrs + 1.
1613
1614
1615%% -- snmp_community_mib --
1616
1617%%-----------------------------------------------------------------
1618%% o  Bad community uses/name is tested already
1619%%    in SNMPv2-MIB and STANDARD-MIB.
1620%% o  Test add/deletion of rows.
1621%%-----------------------------------------------------------------
1622snmp_community_mib(suite) -> [];
1623snmp_community_mib(Config) when list(Config) ->
1624    {_SaNode, _MgrNode, _MibDir} = init_case(Config),
1625    ?line load_master_std("SNMP-COMMUNITY-MIB"),
1626    ?TRY_TEST1(snmp_community_mib),
1627    ?line unload_master("SNMP-COMMUNITY-MIB").
1628
1629snmp_community_mib_2(X) -> snmp_community_mib(X).
1630
1631%% Req. SNMP-COMMUNITY-MIB
1632snmp_community_mib() ->
1633    ?INF("NOT YET IMPLEMENTED", []),
1634    nyi.
1635
1636
1637%% -- snmp_framework_mib --
1638
1639%%-----------------------------------------------------------------
1640%% o  Test engine boots / time
1641%%-----------------------------------------------------------------
1642snmp_framework_mib(suite) -> [];
1643snmp_framework_mib(Config) when list(Config) ->
1644    {_SaNode, _MgrNode, _MibDir} = init_case(Config),
1645    ?line load_master_std("SNMP-FRAMEWORK-MIB"),
1646    ?TRY_TEST1(snmp_framework_mib),
1647    ?line unload_master("SNMP-FRAMEWORK-MIB").
1648
1649%% Req. SNMP-FRAMEWORK-MIB
1650snmp_framework_mib() ->
1651    ?line ["agentEngine"] = get_req(1, [[snmpEngineID,0]]),
1652    ?line [EngineTime] = get_req(2, [[snmpEngineTime,0]]),
1653    sleep(5000),
1654    ?line [EngineTime2] = get_req(3, [[snmpEngineTime,0]]),
1655    if
1656	EngineTime+7 < EngineTime2 ->
1657	    ?line ?FAIL({too_large_diff, EngineTime, EngineTime2});
1658	EngineTime+4 > EngineTime2 ->
1659	    ?line ?FAIL({too_large_diff, EngineTime, EngineTime2});
1660	true -> ok
1661    end,
1662    ?line case get_req(4, [[snmpEngineBoots,0]]) of
1663	      [Boots] when integer(Boots) -> ok;
1664	      Else -> ?FAIL(Else)
1665	  end,
1666    ok.
1667
1668
1669%% -- snmp_target_mib --
1670
1671snmp_target_mib(suite) -> [];
1672snmp_target_mib(Config) when list(Config) ->
1673    {_SaNode, _MgrNode, _MibDir} = init_case(Config),
1674    ?line load_master_std("SNMP-TARGET-MIB"),
1675    ?TRY_TEST1(snmp_target_mib),
1676    ?line unload_master("SNMP-TARGET-MIB").
1677
1678snmp_target_mib() ->
1679    ?INF("NOT YET IMPLEMENTED", []),
1680    nyi.
1681
1682
1683%% -- snmp_notification_mib --
1684
1685snmp_notification_mib(suite) -> [];
1686snmp_notification_mib(Config) when list(Config) ->
1687    {_SaNode, _MgrNode, _MibDir} = init_case(Config),
1688    ?line load_master_std("SNMP-NOTIFICATION-MIB"),
1689    ?TRY_TEST1(snmp_notification_mib),
1690    ?line unload_master("SNMP-NOTIFICATION-MIB").
1691
1692snmp_notification_mib() ->
1693    ?INF("NOT YET IMPLEMENTED", []),
1694    nyi.
1695
1696
1697%% -- snmp_view_based_acm_mib --
1698
1699%%-----------------------------------------------------------------
1700%% o  add/delete views and try them
1701%% o  try boundaries
1702%%-----------------------------------------------------------------
1703snmp_view_based_acm_mib(suite) -> [];
1704snmp_view_based_acm_mib(Config) when list(Config) ->
1705    {_SaNode, _MgrNode, _MibDir} = init_case(Config),
1706    ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"),
1707    ?line load_master("Test2"),
1708    snmp_view_based_acm_mib(),
1709    ?line unload_master("Test2"),
1710    ?line unload_master("SNMP-VIEW-BASED-ACM-MIB").
1711
1712snmp_view_based_acm_mib() ->
1713    snmpa:verbosity(net_if,trace),
1714    snmpa:verbosity(master_agent,trace),
1715    ?LOG("start snmp_view_based_acm_mib test",[]),
1716    %% The user "no-rights" is present in USM, and is mapped to security
1717    %% name 'no-rights", which is not present in VACM.
1718    %% So, we'll add rights for it, try them and delete them.
1719    %% We'll give "no-rights" write access to tDescr.0 and read access
1720    %% to tDescr2.0
1721    %% These are the options we'll use to the mgr
1722    Opts = [{user, "no-rights"}, {community, "no-rights"}],
1723    %% Find the valid secmodel, and one invalid secmodel.
1724    {SecMod, InvSecMod} =
1725	case get(vsn) of
1726	    v1 -> {?SEC_V1, ?SEC_V2C};
1727	    v2 -> {?SEC_V2C, ?SEC_USM};
1728	    v3 -> {?SEC_USM, ?SEC_V1}
1729	end,
1730    ?DBG("assign rights for 'no-rights'",[]),
1731    ?line ?TRY_TEST3(use_no_rights, [], Opts),
1732
1733    %% Now, add a mapping from "no-rights" -> "no-rights-group"
1734    GRow1Status = [vacmSecurityToGroupStatus,[SecMod, 9,"no-rights"]],
1735    GRow1 =
1736	[{[vacmGroupName, [SecMod, 9,"no-rights"]], "no-rights-group"},
1737	 {GRow1Status, ?createAndGo}],
1738    ?DBG("set '~p'",[GRow1]),
1739    ?line ?TRY_TEST2(do_set, [GRow1]),
1740
1741    ?DBG("assign rights for 'no-rights'",[]),
1742    ?line ?TRY_TEST3(use_no_rights, [], Opts),
1743
1744    %% Create a mapping for another sec model, and make sure it dosn't
1745    %% give us access
1746    GRow2Status = [vacmSecurityToGroupStatus,[InvSecMod, 9,"no-rights"]],
1747    GRow2 = [{[vacmGroupName, [InvSecMod, 9, "no-rights"]], "initial"},
1748	     {GRow2Status, ?createAndGo}],
1749
1750    ?DBG("set '~p'",[GRow2]),
1751    ?line ?TRY_TEST2(do_set, [GRow2]),
1752
1753    ?DBG("assign rights for 'no-rights'",[]),
1754    ?line ?TRY_TEST3(use_no_rights, [], Opts),
1755
1756    %% Delete that row
1757    ?line ?TRY_TEST2(del_row, [GRow2Status]),
1758
1759    RVName = "rv_name",
1760    WVName = "wv_name",
1761
1762    %% Access row
1763    ARow1Idx = [15 | "no-rights-group"] ++ [0, ?SEC_ANY, 1],
1764    ARow1Status = [vacmAccessStatus, ARow1Idx],
1765    ARow1 = [{[vacmAccessContextMatch, ARow1Idx], 1},
1766	     {[vacmAccessReadViewName, ARow1Idx], RVName},
1767	     {[vacmAccessWriteViewName, ARow1Idx], WVName},
1768	     {ARow1Status, ?createAndGo}],
1769
1770    %% This access row would give acces, if InvSecMod was valid.
1771    ARow2Idx = [15 | "no-rights-group"] ++ [0, InvSecMod, 1],
1772    ARow2Status = [vacmAccessStatus, ARow2Idx],
1773    ARow2 = [{[vacmAccessContextMatch, ARow2Idx], 1},
1774	     {[vacmAccessReadViewName, ARow2Idx], "internet"},
1775	     {[vacmAccessWriteViewName, ARow2Idx], "internet"},
1776	     {ARow2Status, ?createAndGo}],
1777
1778    ?line ?TRY_TEST2(do_set, [ARow2]),
1779
1780    ?line ?TRY_TEST3(use_no_rights, [], Opts),
1781
1782    %% Delete that row
1783    ?line ?TRY_TEST2(del_row, [ARow2Status]),
1784
1785
1786    %% Add valid row
1787    ?line ?TRY_TEST2(do_set, [ARow1]),
1788
1789    ?line ?TRY_TEST3(use_no_rights, [], Opts),
1790
1791    %% Create the view family
1792    VRow1Idx = mk_ln(RVName) ++ mk_ln(?xDescr),         % object access
1793    VRow2Idx = mk_ln(RVName) ++ mk_ln(?xDescr2 ++ [0]), % instance access
1794    VRow3Idx = mk_ln(WVName) ++ mk_ln(?xDescr),         % object access
1795    VRow4Idx = mk_ln(WVName) ++ mk_ln(?xDescr ++ [0]),  % instance access
1796    VRow1Status = [vacmViewTreeFamilyStatus, VRow1Idx],
1797    VRow2Status = [vacmViewTreeFamilyStatus, VRow2Idx],
1798    VRow3Status = [vacmViewTreeFamilyStatus, VRow3Idx],
1799    VRow4Status = [vacmViewTreeFamilyStatus, VRow4Idx],
1800
1801    ?line ?TRY_TEST2(add_row, [VRow1Status]),
1802    ?line ?TRY_TEST2(add_row, [VRow2Status]),
1803    ?line ?TRY_TEST2(add_row, [VRow3Status]),
1804
1805    %% We're supposed to have access now...
1806    ?line ?TRY_TEST3(use_rights, [], Opts),
1807
1808    %% Change Row3 to Row4
1809    ?line ?TRY_TEST2(del_row, [VRow3Status]),
1810    ?line ?TRY_TEST2(add_row, [VRow4Status]),
1811
1812    %% We should still have access...
1813    ?line ?TRY_TEST3(use_rights, [], Opts),
1814
1815    %% Delete rows
1816    ?line ?TRY_TEST2(del_row, [GRow1Status]),
1817
1818    ?line ?TRY_TEST3(use_no_rights, [], Opts),
1819
1820    %% Delete rest of rows
1821    ?line ?TRY_TEST2(del_row, [ARow1Status]),
1822    ?line ?TRY_TEST2(del_row, [VRow1Status]),
1823    ?line ?TRY_TEST2(del_row, [VRow2Status]),
1824    ?line ?TRY_TEST2(del_row, [VRow4Status]),
1825
1826    ?line ?TRY_TEST3(use_no_rights, [], Opts),
1827    snmpa:verbosity(master_agent,log).
1828
1829do_set(Row) ->
1830    s(Row),
1831    expect(1, Row).
1832
1833add_row(RowStatus) ->
1834    s([{RowStatus, ?createAndGo}]),
1835    expect(1, [{RowStatus, ?createAndGo}]).
1836
1837del_row(RowStatus) ->
1838    s([{RowStatus, ?destroy}]),
1839    expect(1, [{RowStatus, ?destroy}]).
1840
1841
1842
1843use_no_rights() ->
1844    g([[xDescr,0]]),
1845    ?v1_2_3(expect(11, noSuchName, 1, any),
1846	    expect(12, [{[xDescr,0], noSuchObject}]),
1847	    expect(13, authorizationError, 1, any)),
1848    g([[xDescr2,0]]),
1849    ?v1_2_3(expect(21, noSuchName, 1, any),
1850	    expect(22, [{[xDescr2,0], noSuchObject}]),
1851	    expect(23, authorizationError, 1, any)),
1852    gn([[xDescr]]),
1853    ?v1_2_3(expect(31, noSuchName, 1, any),
1854	    expect(32, [{[xDescr], endOfMibView}]),
1855	    expect(33, authorizationError, 1, any)),
1856    s([{[xDescr,0], "tryit"}]),
1857    ?v1_2_3(expect(41, noSuchName, 1, any),
1858	    expect(42, noAccess, 1, any),
1859	    expect(43, authorizationError, 1, any)).
1860
1861
1862use_rights() ->
1863    g([[xDescr,0]]),
1864    expect(1, [{[xDescr,0], any}]),
1865    g([[xDescr2,0]]),
1866    expect(2, [{[xDescr2,0], any}]),
1867    s([{[xDescr,0], "tryit"}]),
1868    expect(3, noError, 0, any),
1869    g([[xDescr,0]]),
1870    expect(4, [{[xDescr,0], "tryit"}]).
1871
1872
1873%% -- sparse_table --
1874
1875sparse_table(suite) -> [];
1876sparse_table(Config) when list(Config) ->
1877    {_SaNode, _MgrNode, _MibDir} = ?INIT_CASE(Config),
1878
1879    ?line load_master("Test1"),
1880    ?TRY_TEST1(sparse_table_test),
1881    ?line unload_master("Test1").
1882
1883%% Req. Test1
1884sparse_table_test() ->
1885    p("Testing sparse table..."),
1886
1887    %% Create two rows, check that they are get-nexted in correct order.
1888    Idx1 = 1,
1889    Idx2 = 2,
1890    s([{[sparseStatus, Idx1], i, ?createAndGo},
1891       {[sparseDescr, Idx1], s, "row 1"}]),
1892    ?line expect(1, [{[sparseStatus, Idx1], ?createAndGo},
1893		     {[sparseDescr, Idx1], "row 1"}]),
1894    s([{[sparseStatus, Idx2], i, ?createAndGo},
1895       {[sparseDescr, Idx2], s, "row 2"}]),
1896    ?line expect(2, [{[sparseStatus, Idx2], ?createAndGo},
1897		     {[sparseDescr, Idx2], "row 2"}]),
1898    ?v1_2(gn([[sparseIndex], [sparseDescr,Idx1], [sparseDescr,Idx2],
1899	      [sparseStatus,Idx1], [sparseStatus,Idx2]]),
1900	  gb(0,5,[[sparseIndex]])),
1901    ?line expect(3, [{[sparseDescr,Idx1], "row 1"},
1902		     {[sparseDescr,Idx2], "row 2"},
1903		     {[sparseStatus,Idx1], ?active},
1904		     {[sparseStatus,Idx2], ?active},
1905		     {[sparseStr,0], "slut"}]),
1906    % Delete the rows
1907    s([{[sparseStatus, Idx1], i, ?destroy}]),
1908    ?line expect(4, [{[sparseStatus, Idx1], ?destroy}]),
1909    s([{[sparseStatus, Idx2], i, ?destroy}]),
1910    ?line expect(5, [{[sparseStatus, Idx2], ?destroy}]).
1911
1912
1913%% -- cnt_64 --
1914
1915cnt_64(suite) -> [];
1916cnt_64(Config) when list(Config) ->
1917    {_SaNode, _MgrNode, _MibDir} = ?INIT_CASE(Config),
1918    MA = whereis(snmp_master_agent),
1919
1920    ?line load_master("Test1"),
1921    ?TRY_TEST2(cnt_64_test, [MA]),
1922    ?line unload_master("Test1").
1923
1924%% Req. Test1
1925cnt_64_test(MA) ->
1926    ?LOG("start cnt64 test (~p)",[MA]),
1927    snmpa:verbosity(MA,trace),
1928    ?LOG("start cnt64 test",[]),
1929    p("Testing Counter64, and at the same time, RowStatus is not last column"),
1930
1931    ?DBG("get cnt64",[]),
1932    g([[cnt64,0]]),
1933    ?DBG("await response",[]),
1934    ?line ?v1_2(expect(1, noSuchName, 1, any),
1935		expect(1, [{[cnt64,0],18446744073709551615}])),
1936    ?DBG("get-next cnt64",[]),
1937    gn([[cnt64]]),
1938    ?DBG("await response",[]),
1939    ?line ?v1_2(expect(2, [{[cnt64Str,0], "after cnt64"}]),
1940		expect(2, [{[cnt64,0],18446744073709551615}])),
1941    ?DBG("send cntTrap",[]),
1942    snmpa:send_trap(MA,cntTrap,"standard trap",[{sysContact,"pelle"},
1943					       {cnt64, 10},
1944					       {sysLocation, "here"}]),
1945    ?DBG("await response",[]),
1946    ?line ?v1_2(expect(3, trap, [test], 6, 1, [{[sysContact,0], "pelle"},
1947					       {[sysLocation,0], "here"}]),
1948		expect(3, v2trap, [{[sysUpTime, 0], any},
1949				   {[snmpTrapOID, 0], ?testTrap ++ [1]},
1950				   {[sysContact,0], "pelle"},
1951				   {[cnt64,0], 10},
1952				   {[sysLocation,0], "here"}])),
1953
1954    %% Create two rows, check that they are get-nexted in correct order.
1955    Idx1 = 1,
1956    Idx2 = 2,
1957    ?DBG("create row (cntStatus): ~p",[Idx1]),
1958    s([{[cntStatus, Idx1], i, ?createAndGo}]),
1959    ?DBG("await response",[]),
1960    ?line expect(1, [{[cntStatus, Idx1], ?createAndGo}]),
1961    ?DBG("create row (cntStatus): ~p",[Idx2]),
1962    s([{[cntStatus, Idx2], i, ?createAndGo}]),
1963    ?DBG("await response",[]),
1964    ?line expect(2, [{[cntStatus, Idx2], ?createAndGo}]),
1965
1966    ?DBG("get-next (cntIndex)",[]),
1967    gn([[cntIndex]]),
1968    ?DBG("await response",[]),
1969    ?line ?v1_2(expect(3, [{[cntStatus,Idx1], ?active}]),
1970		expect(3, [{[cntCnt,Idx1], 0}])),
1971    % Delete the rows
1972    ?DBG("delete row (cntStatus): ~p",[Idx1]),
1973    s([{[cntStatus, Idx1], i, ?destroy}]),
1974    ?DBG("await response",[]),
1975    ?line expect(4, [{[cntStatus, Idx1], ?destroy}]),
1976    ?DBG("delete row (cntStatus): ~p",[Idx2]),
1977    s([{[cntStatus, Idx2], i, ?destroy}]),
1978    ?DBG("await response",[]),
1979    ?line expect(5, [{[cntStatus, Idx2], ?destroy}]),
1980    catch snmpa:verbosity(MA,log),
1981    ?DBG("done",[]),
1982    ok.
1983
1984
1985%% -- opaque --
1986
1987opaque(suite) -> [];
1988opaque(Config) when list(Config) ->
1989    {_SaNode, _MgrNode, _MibDir} = ?INIT_CASE(Config),
1990
1991    ?line load_master("Test1"),
1992    ?TRY_TEST1(opaque_test),
1993    ?line unload_master("Test1").
1994
1995%% Req. Test1
1996opaque_test() ->
1997    p("Testing Opaque datatype..."),
1998    g([[opaqueObj,0]]),
1999    ?line expect(1, [{[opaqueObj,0], "opaque-data"}]).
2000
2001
2002%% -- change_target_addr_config --
2003
2004change_target_addr_config(suite) -> [];
2005change_target_addr_config(Config) when list(Config) ->
2006    p("Testing changing target address config..."),
2007    ?LOG("change_target_addr_config -> entry",[]),
2008    {_SaNode, _MgrNode, _MibDir} = init_case(Config),
2009
2010    put(sname,snmp_suite),
2011    put(verbosity,trace),
2012
2013    MA = whereis(snmp_master_agent),
2014
2015    ?LOG("change_target_addr_config -> load TestTrap",[]),
2016    ?line load_master("TestTrap"),
2017
2018    ?LOG("change_target_addr_config -> set trace verbosity for local_db",[]),
2019    ?line snmpa:verbosity(local_db,trace),
2020
2021    %% First send some traps that will arive att the original manager
2022    ?LOG("change_target_addr_config -> send trap",[]),
2023    ?TRY_TEST2(ma_trap1, [MA]),
2024
2025    ?LOG("change_target_addr_config -> set silence verbosity for local_db",[]),
2026    ?line snmpa:verbosity(local_db,silence),
2027
2028    %% Start new dummy listener
2029    ?LOG("change_target_addr_config -> start dummy manager",[]),
2030    ?line {ok,Pid,NewPort} = dummy_manager_start(MA),
2031
2032    %% Reconfigure
2033    ?LOG("change_target_addr_config -> reconfigure",[]),
2034    AgentDir = ?config(agent_dir, Config),
2035    ?line rewrite_target_addr_conf(AgentDir, NewPort),
2036    ?line snmp_target_mib:reconfigure(AgentDir),
2037
2038    %% Send the trap again
2039    ?LOG("change_target_addr_config -> send trap again",[]),
2040    catch dummy_manager_send_trap2(Pid),
2041
2042    ?LOG("change_target_addr_config -> await trap ack",[]),
2043    catch dummy_manager_await_trap2_ack(),
2044
2045    ?LOG("change_target_addr_config -> stop dummy manager",[]),
2046    ?line ok = dummy_manager_stop(Pid),
2047
2048    ?LOG("change_target_addr_config -> reset target address config",[]),
2049    ?line reset_target_addr_conf(AgentDir),
2050
2051    ?LOG("change_target_addr_config -> unload TestTrap",[]),
2052    ?line unload_master("TestTrap").
2053
2054
2055dummy_manager_start(MA) ->
2056    ?DBG("dummy_manager_start -> entry",[]),
2057    Pid = spawn(get(mgr_node), ?MODULE,dummy_manager_init,[self(),MA]),
2058    ?DBG("dummy_manager_start -> Pid: ~p",[Pid]),
2059    await_dummy_manager_started(Pid).
2060
2061await_dummy_manager_started(Pid) ->
2062    receive
2063	{dummy_manager_started,Pid,Port} ->
2064	    ?DBG("dummy_manager_start -> acknowledge received with"
2065		"~n   Port: ~p",[Port]),
2066	    {ok,Pid,Port};
2067	{'EXIT', Pid, Reason} ->
2068	    {error, Pid, Reason};
2069	O ->
2070	    ?LOG("dummy_manager_start -> received unknown message:"
2071		 "~n   ~p",[O]),
2072	    await_dummy_manager_started(Pid)
2073    end.
2074
2075dummy_manager_stop(Pid) ->
2076    ?DBG("dummy_manager_stop -> entry with Pid: ~p",[Pid]),
2077    Pid ! stop,
2078    receive
2079	{dummy_manager_stopping, Pid} ->
2080	    ?DBG("dummy_manager_stop -> acknowledge received",[]),
2081	    ok
2082    after 10000 ->
2083	    ?ERR("dummy_manager_stop -> timeout",[]),
2084	    timeout
2085    end.
2086
2087dummy_manager_send_trap2(Pid) ->
2088    ?DBG("dummy_manager_send_trap2 -> entry",[]),
2089    Pid ! {send_trap,testTrap2}.
2090
2091dummy_manager_await_trap2_ack() ->
2092    ?DBG("dummy_manager_await_trap2 -> entry",[]),
2093    receive
2094	{received_trap,Trap} ->
2095	    ?LOG("dummy_manager_await_trap2 -> received trap: ~p",[Trap]),
2096	    %% Note:
2097	    %% Without this sleep the v2_inform_i testcase failes! There
2098	    %% is no relation between these two test cases as far as I
2099	    %% able to figure out...
2100	    sleep(60000),
2101	    ok;
2102	O ->
2103	    ?ERR("dummy_manager_await_trap2 -> unexpected message: ~p",[O]),
2104	    ok
2105    after 10000 ->
2106	    ?ERR("dummy_manager_await_trap2 -> timeout",[]),
2107	    timeout
2108    end.
2109
2110dummy_manager_init(Parent,MA) ->
2111    ?DBG("dummy_manager_init -> entry with"
2112	   "~n   Parent: ~p"
2113	   "~n   MA:     ~p",[Parent,MA]),
2114    {ok,S} = gen_udp:open(0,[{recbuf,65535}]),
2115    ?DBG("dummy_manager_init -> S: ~p",[S]),
2116    {ok,Port} = inet:port(S),
2117    ?DBG("dummy_manager_init -> Port: ~p",[Port]),
2118    Parent ! {dummy_manager_started,self(),Port},
2119    dummy_manager_loop(Parent,S,MA).
2120
2121dummy_manager_loop(P,S,MA) ->
2122    ?LOG("dummy_manager_loop -> ready for receive",[]),
2123    receive
2124	{send_trap,Trap} ->
2125	    ?LOG("dummy_manager_loop -> received trap send request"
2126		 "~n   Trap: ~p",[Trap]),
2127	    snmpa:send_trap(MA, Trap, "standard trap"),
2128	    dummy_manager_loop(P,S,MA);
2129	{udp, _UdpId, Ip, UdpPort, Bytes} ->
2130	    ?LOG("dummy_manager_loop -> received upd message"
2131		 "~n   from: ~p:~p"
2132		 "~n   size: ~p",
2133		 [Ip, UdpPort, dummy_manager_message_sz(Bytes)]),
2134	    R = dummy_manager_handle_message(Bytes),
2135	    ?DBG("dummy_manager_loop -> R: ~p",[R]),
2136	    P ! R,
2137	    dummy_manager_loop(P,S,MA);
2138	stop ->
2139	    ?DBG("dummy_manager_loop -> received stop request",[]),
2140	    P ! {dummy_manager_stopping, self()},
2141	    gen_udp:close(S),
2142	    exit(normal);
2143	O ->
2144	    ?LOG("dummy_manager_loop -> received unknown message:"
2145		 "~n   ~p",[O]),
2146	    dummy_manager_loop(P,S,MA)
2147    end.
2148
2149dummy_manager_message_sz(B) when binary(B) ->
2150    size(B);
2151dummy_manager_message_sz(L) when list(L) ->
2152    length(L);
2153dummy_manager_message_sz(_) ->
2154    undefined.
2155
2156dummy_manager_handle_message(Bytes) ->
2157    case (catch snmp_pdus:dec_message(Bytes)) of
2158	{'EXIT',Reason} ->
2159	    ?ERR("dummy_manager_handle_message -> "
2160		   "failed decoding message only:~n   ~p",[Reason]),
2161	    {error,Reason};
2162	M ->
2163	    ?DBG("dummy_manager_handle_message -> decoded message:"
2164		   "~n   ~p",[M]),
2165	    {received_trap,M}
2166    end.
2167
2168
2169%% -- reported_bugs --
2170
2171%%%-----------------------------------------------------------------
2172%%% Testing of reported bugs and other tickets.
2173%%%-----------------------------------------------------------------
2174
2175reported_bugs(suite) ->
2176    [otp_1128, otp_1129, otp_1131, otp_1162,
2177     otp_1222, otp_1298, otp_1331, otp_1338,
2178     otp_1342, otp_2776, otp_2979, otp_3187, otp_3725].
2179
2180%%-----------------------------------------------------------------
2181%% Ticket: OTP-1128
2182%% Slogan: Bug in handling of createAndWait set-requests.
2183%%-----------------------------------------------------------------
2184otp_1128(suite) -> [];
2185otp_1128(Config) when list(Config) ->
2186    {_SaNode, _MgrNode, _MibDir} = init_case(Config),
2187    ?line load_master("OLD-SNMPEA-MIB"),
2188    ?line init_old(),
2189    ?TRY_TEST1(otp_1128),
2190    ?line unload_master("OLD-SNMPEA-MIB").
2191
2192otp_1128() ->
2193    io:format("Testing bug reported in ticket OTP-1128...~n"),
2194
2195    NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")],
2196    NewKeyc4 = [intCommunityAccess,get(mip),is("test")],
2197    NewKeyc5 = [intCommunityStatus,get(mip),is("test")],
2198
2199    s([{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]),
2200    ?line expect(28, [{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]),
2201    g([NewKeyc5]),
2202    ?line expect(29, [{NewKeyc5, ?notReady}]),
2203    s([{NewKeyc5, ?active}, {NewKeyc3, 2}]),
2204    ?line expect(30, [{NewKeyc5, ?active}, {NewKeyc3, 2}]),
2205    g([NewKeyc5]),
2206    ?line expect(31, [{NewKeyc5, ?active}]),
2207    s([{NewKeyc5, ?destroy}]),
2208    ?line expect(32, [{NewKeyc5, ?destroy}]).
2209
2210%%-----------------------------------------------------------------
2211%% Ticket: OTP-1129, OTP-1169
2212%% Slogan: snmpa:int_to_enum crashes on bad oids
2213%%-----------------------------------------------------------------
2214otp_1129(suite) -> [];
2215otp_1129(Config) when list(Config) ->
2216    {_SaNode, _MgrNode, _MibDir} = init_case(Config),
2217    ?line load_master("Klas3"),
2218    ?TRY_TEST2(otp_1129_i, [node()]),
2219    ?line unload_master("Klas3").
2220
2221otp_1129_i(MaNode) ->
2222    io:format("Testing bug reported in ticket OTP-1129...~n"),
2223    false = rpc:call(MaNode, snmp, int_to_enum, [iso, 1]),
2224    false = rpc:call(MaNode, snmp, int_to_enum, [isox, 1]).
2225
2226
2227%%-----------------------------------------------------------------
2228%% Ticket: OTP-1131
2229%% Slogan: Agent crashes / erlang node halts if RowIndex in a
2230%%         setrequest is of bad type, e.g. an INDEX {INTEGER},
2231%%         and RowIdenx [3,2].
2232%%-----------------------------------------------------------------
2233otp_1131(suite) -> [];
2234otp_1131(Config) when list(Config) ->
2235    {_SaNode, _MgrNode, _MibDir} = init_case(Config),
2236    ?line load_master("Klas1"),
2237    ?TRY_TEST1(otp_1131),
2238    ?line unload_master("Klas1").
2239
2240otp_1131() ->
2241    io:format("Testing bug reported in ticket OTP-1131...~n"),
2242    s([{[friendsEntry, [2, 3, 1]], s, "kompis3"},
2243       {[friendsEntry, [3, 3, 1]], i, ?createAndGo}]),
2244    ?line expect(1, ?v1_2(noSuchName, noCreation), 2, any).
2245
2246
2247%%-----------------------------------------------------------------
2248%% Ticket: OTP-1162
2249%% Slogan: snmp_agent can't handle wrongValue from instrum.func
2250%%-----------------------------------------------------------------
2251otp_1162(suite) -> [];
2252otp_1162(Config) when list(Config) ->
2253    ?P1(otp_1162),
2254    {SaNode, _MgrNode, _MibDir} = ?INIT_CASE(Config),
2255    ?line {ok, SA} = ?START_SA(SaNode, ?sa, "SA-MIB"),
2256    ?TRY_TEST1(otp_1162),
2257    ?STOP_SA(SA).
2258
2259otp_1162() ->
2260    s([{[sa, [2,0]], 6}]), % wrongValue (i is_set_ok)
2261    ?line expect(1, ?v1_2(badValue, wrongValue), 1, any).
2262
2263
2264%%-----------------------------------------------------------------
2265%% Ticket: OTP-1222
2266%% Slogan: snmp agent crash if faulty index is returned from instrum
2267%%-----------------------------------------------------------------
2268otp_1222(suite) -> [];
2269otp_1222(Config) when list(Config) ->
2270    ?P1(otp_1222),
2271    ?INIT_CASE(Config),
2272    ?line load_master("Klas3"),
2273    ?line load_master("Klas4"),
2274    ?TRY_TEST1(otp_1222),
2275    ?line unload_master("Klas3"),
2276    ?line unload_master("Klas4").
2277
2278otp_1222() ->
2279    io:format("Testing bug reported in ticket OTP-1222...~n"),
2280    s([{[fStatus4,1], 4}, {[fName4,1], 1}]),
2281    ?line expect(1, genErr, 0, any),
2282    s([{[fStatus4,2], 4}, {[fName4,2], 1}]),
2283    ?line expect(2, genErr, 0, any).
2284
2285
2286%%-----------------------------------------------------------------
2287%% Ticket: OTP-1298
2288%% Slogan: Negative INTEGER values are treated as positive.
2289%%-----------------------------------------------------------------
2290otp_1298(suite) -> [];
2291otp_1298(Config) when list(Config) ->
2292    ?P1(otp_1298),
2293    ?INIT_CASE(Config),
2294    ?line load_master("Klas2"),
2295    ?TRY_TEST1(otp_1298),
2296    ?line unload_master("Klas2").
2297
2298otp_1298() ->
2299    io:format("Testing bug reported in ticket OTP-1298...~n"),
2300    s([{[fint,0], -1}]),
2301    ?line expect(1298, [{[fint,0], -1}]).
2302
2303
2304%%-----------------------------------------------------------------
2305%% Ticket: OTP-1331
2306%% Slogan: snmp_generic should return noError when deleting non-ex row
2307%%-----------------------------------------------------------------
2308otp_1331(suite) -> [];
2309otp_1331(Config) when list(Config) ->
2310    ?P1(otp_1331),
2311    ?INIT_CASE(Config),
2312    ?line load_master("OLD-SNMPEA-MIB"),
2313    ?line init_old(),
2314    ?TRY_TEST1(otp_1331),
2315    ?line unload_master("OLD-SNMPEA-MIB").
2316
2317otp_1331() ->
2318    NewKeyc5 = [intCommunityStatus,[127,32,0,0],is("test")],
2319    s([{NewKeyc5, ?destroy}]),
2320    ?line expect(1, [{NewKeyc5, ?destroy}]).
2321
2322
2323%%-----------------------------------------------------------------
2324%% Ticket: OTP-1338
2325%% Slogan: snmp bug in initialisation of default values for mnesia tabs
2326%%-----------------------------------------------------------------
2327otp_1338(suite) -> [];
2328otp_1338(Config) when list(Config) ->
2329    ?P1(otp_1338),
2330    ?INIT_CASE(Config),
2331    ?line load_master("Klas2"),
2332    ?TRY_TEST1(otp_1338),
2333    ?line unload_master("Klas2").
2334
2335otp_1338() ->
2336    s([{[kStatus2, 7], i, ?createAndGo}]),
2337    ?line expect(1, [{[kStatus2, 7], ?createAndGo}]),
2338    g([[kName2, 7]]),
2339    ?line expect(2, [{[kName2, 7], "JJJ"}]).
2340
2341
2342%%-----------------------------------------------------------------
2343%% Ticket: OTP-1342
2344%% Slogan: default impl of snmp table can't handle bad index access,
2345%%         Set when INDEX is read-write gets into an infinite loop!
2346%%-----------------------------------------------------------------
2347otp_1342(suite) -> [];
2348otp_1342(Config) when list(Config) ->
2349    ?P1(otp_1342),
2350    ?INIT_CASE(Config),
2351    ?line load_master("Klas4"),
2352    ?TRY_TEST1(otp_1342),
2353    ?line unload_master("Klas4").
2354
2355otp_1342() ->
2356    s([{[fIndex5, 1], i, 1},
2357       {[fName5, 1], i, 3},
2358       {[fStatus5, 1], i, ?createAndGo}]),
2359    ?line expect(1, ?v1_2(noSuchName, noCreation), 3, any).
2360
2361
2362%%-----------------------------------------------------------------
2363%% Ticket: OTP-1366
2364%% Slogan: snmp traps not sent to all managers
2365%% Note: NYI! We need a way to tell the test server that we need
2366%%       mgrs on two different machines.
2367%%-----------------------------------------------------------------
2368otp_1366(suite) -> [];
2369otp_1366(Config) when list(Config) ->
2370    ?P1(otp_1366),
2371    ?INIT_CASE(Config),
2372    ?line load_master("OLD-SNMPEA-MIB"),
2373    ?line init_old(),
2374    ?TRY_TEST1(otp_1366),
2375    ?line unload_master("OLD-SNMPEA-MIB").
2376
2377otp_1366() ->
2378    ?INF("NOT YET IMPLEMENTED", []),
2379    'NYI'.
2380
2381
2382%%-----------------------------------------------------------------
2383%% Ticket: OTP-2776
2384%% Slogan: snmp:validate_date_and_time() fails when time is 00:00
2385%%-----------------------------------------------------------------
2386otp_2776(suite) -> [];
2387otp_2776(Config) when list(Config) ->
2388    ?P1(otp_2776),
2389    ?INIT_CASE(Config),
2390    ?TRY_TEST1(otp_2776).
2391
2392otp_2776() ->
2393  io:format("Testing bug reported in ticket OTP-2776...~n"),
2394
2395  Dt01_valid   = [19,98,9,1,1,0,23,0,43,0,0],
2396  Dt02_valid   = [19,98,9,1,0,0,0,0,43,0,0],  % This is what is fixed: 00:00
2397  Dt03_valid   = [19,98,2,28,1,0,23,0,43,0,0],
2398  Dt04_invalid = [19,98,2,29,1,0,23,0,43,0,0],
2399  Dt05_valid   = [19,96,2,29,1,0,23,0,43,0,0],
2400  Dt06_valid   = [20,0,2,29,1,0,23,0,43,0,0],
2401  Dt07_invalid = [19,96,2,30,1,0,23,0,43,0,0], % This is also fixed: 30/2
2402  Dt08_valid   = [19,98,4,30,1,0,23,0,43,0,0],
2403  Dt09_invalid = [19,98,4,31,1,0,23,0,43,0,0], % This is also fixed: 31/4
2404  Dt10_invalid = [],
2405  Dt11_invalid = [kalle,hobbe],
2406  L = [{ 1, true,  Dt01_valid},
2407       { 2, true,  Dt02_valid},
2408       { 3, true,  Dt03_valid},
2409       { 4, false, Dt04_invalid},
2410       { 5, true,  Dt05_valid},
2411       { 6, true,  Dt06_valid},
2412       { 7, false, Dt07_invalid},
2413       { 8, true,  Dt08_valid},
2414       { 9, false, Dt09_invalid},
2415       {10, false, Dt10_invalid},
2416       {11, false, Dt11_invalid}],
2417
2418  ?line ok = validate_dat(L).
2419
2420
2421validate_dat(L) -> validate_dat(L,[]).
2422
2423validate_dat([],V) ->
2424  Fun = fun({_,X}) -> case X of
2425                        ok -> false;
2426                        _  -> true
2427                      end
2428        end,
2429  validate_dat1( lists:reverse( lists:filter(Fun,V) ) );
2430validate_dat([{Id,E,Dat}|T],V) ->
2431  validate_dat(T,[validate_dat2(Id,E,Dat) | V]).
2432
2433validate_dat1([]) -> ok;
2434validate_dat1(L)  -> {error,L}.
2435
2436validate_dat2(Id, E, Dat) ->
2437  Res = case {E,snmp:validate_date_and_time(Dat)} of
2438          {E,E} -> ok;
2439          {E,A} -> {E,A}
2440        end,
2441  {Id, Res}.
2442
2443
2444%%-----------------------------------------------------------------
2445%% Ticket: OTP-2979
2446%% Slogan: get-next on more than 1 column in an empty table
2447%%         returns bad response.
2448%%-----------------------------------------------------------------
2449otp_2979(suite) -> [];
2450otp_2979(Config) when list(Config) ->
2451    ?P1(otp_2979),
2452    ?INIT_CASE(Config),
2453    ?line load_master("Test1"),
2454    ?line init_old(),
2455    ?TRY_TEST1(otp_2979),
2456    ?line unload_master("Test1").
2457
2458otp_2979() ->
2459    gn([[sparseDescr], [sparseStatus]]),
2460    ?line expect(1, [{[sparseStr,0], "slut"},
2461		     {[sparseStr,0], "slut"}]).
2462
2463%%-----------------------------------------------------------------
2464%% Ticket: OTP-3187
2465%% Slogan: get-next on vacmAccessTable for colums > 5 returns
2466%%         endOfTable - should return value.
2467%%-----------------------------------------------------------------
2468otp_3187(suite) -> [];
2469otp_3187(Config) when list(Config) ->
2470    ?P1(otp_3187),
2471    ?INIT_CASE(Config),
2472    ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"),
2473    otp_3187(),
2474    ?line unload_master("SNMP-VIEW-BASED-ACM-MIB").
2475
2476otp_3187() ->
2477    ?line Elements =
2478       snmp_view_based_acm_mib:vacmAccessTable(get_next,[],[4,5,6]),
2479    lists:foreach(fun(E) ->
2480			   ?line if E == endOfTable ->
2481					?FAIL(endOfTable);
2482				       true -> ok
2483				end
2484		   end, Elements).
2485
2486
2487%%-----------------------------------------------------------------
2488%% Ticket: OTP-3542
2489%% Slogan:
2490%%-----------------------------------------------------------------
2491otp_3542(suite) -> [];
2492otp_3542(Config) when list(Config) ->
2493    ?P1(otp_3542),
2494    ?INIT_CASE(Config),
2495    ?TRY_TEST1(otp_3542).
2496
2497otp_3542() ->
2498    io:format("SNMP v3 discovery...~n"),
2499    ?line Res = snmp_test_mgr:d(),
2500    io:format("SNMP v3 discovery result: ~p~n",[Res]).
2501
2502
2503%%-----------------------------------------------------------------
2504%% Ticket: OTP-3725
2505%% Slogan: Slow response time on snmpa:int_to_enum
2506%%-----------------------------------------------------------------
2507otp_3725(suite) -> [];
2508otp_3725(Config) when list(Config) ->
2509    ?P1(otp_3725),
2510    ?INIT_CASE(Config),
2511
2512    ?line load_master("OLD-SNMPEA-MIB"),
2513    ?line init_old(),
2514    ?TRY_TEST2(otp_3725_test, [node()]),
2515    ?line unload_master("OLD-SNMPEA-MIB").
2516
2517%% Req. OLD-SNMPEA-MIB
2518otp_3725_test(MaNode) ->
2519    io:format("Testing feature requested in ticket OTP-3725...~n"),
2520    ?line rpc:call(MaNode,snmpa,verbosity,[symbolic_store,trace]),
2521    ?line Db = rpc:call(MaNode,snmp,get_symbolic_store_db,[]),
2522    ?DBG("otp_3725_test -> Db = ~p",[Db]),
2523
2524    ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid,
2525				  [Db, intAgentIpAddress]),
2526    ?DBG("otp_3725_test -> name_to_oid for ~p: ~p",[intAgentIpAddress,OID]),
2527    ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, oid_to_name,
2528						[Db,OID]),
2529    ?DBG("otp_3725_test -> oid_to_name for ~p: ~p",[OID,intAgentIpAddress]),
2530    ?line false = rpc:call(MaNode, snmp, name_to_oid, [Db, intAgentIpAddres]),
2531    ?line false = rpc:call(MaNode, snmp, oid_to_name,
2532			   [Db, [1,5,32,3,54,3,3,34,4]]),
2533    ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int,
2534				[Db, intViewType, excluded]),
2535    ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum,
2536				       [Db, intViewType, 2]),
2537    ?line false = rpc:call(MaNode, snmp, enum_to_int,
2538			   [Db, intViewType, exclude]),
2539    ?line false = rpc:call(MaNode, snmp, enum_to_int,
2540			   [Db, intAgentIpAddress, exclude]),
2541    ?line false = rpc:call(MaNode, snmp, enum_to_int,
2542			   [Db, intAgentIpAddre, exclude]),
2543    ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, intViewType, 3]),
2544    ?line false = rpc:call(MaNode, snmp, int_to_enum,
2545			   [Db, intAgentIpAddress, 2]),
2546    ?line false = rpc:call(MaNode, snmp, int_to_enum,
2547			   [Db, intAgentIpAddre, 2]),
2548    ?line {value, active} = rpc:call(MaNode, snmp, int_to_enum,
2549				     [Db, 'RowStatus', ?active]),
2550    ?line {value, ?destroy} = rpc:call(MaNode, snmp, enum_to_int,
2551				       [Db, 'RowStatus', destroy]),
2552    ?line false = rpc:call(MaNode, snmp, enum_to_int,
2553			   [Db, 'RowStatus', xxxdestroy]),
2554    ?line false = rpc:call(MaNode, snmp, enum_to_int,
2555			   [Db, 'xxRowStatus', destroy]),
2556    ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'RowStatus', 25]),
2557    ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'xxRowStatus', 1]),
2558    ok.
2559
2560
2561%% -- tickets --
2562
2563%% These are (ticket) test cases where the initiation has to be done
2564%% individually.
2565tickets(suite) ->
2566    [otp_4394].
2567
2568
2569%%-----------------------------------------------------------------
2570%% Ticket: OTP-4394
2571%% Slogan: Target mib tag list check invalid
2572%%-----------------------------------------------------------------
2573
2574otp_4394(suite) -> {req, [], {conf,
2575			      init_otp_4394,
2576			      [otp_4394_test],
2577			      finish_otp_4394}}.
2578
2579init_otp_4394(Config) when list(Config) ->
2580    ?DBG("init_otp_4394 -> entry with"
2581	   "~n   Config: ~p", [Config]),
2582    ?line AgentDir = ?config(agent_dir, Config),
2583    ?line MgrDir   = ?config(mgr_dir, Config),
2584    ?line Ip       = ?config(ip, Config),
2585    ?line otp_4394_config(AgentDir, MgrDir, Ip),
2586    MasterAgentVerbosity = {master_agent_verbosity, trace},
2587    NetIfVerbosity       = {net_if_verbosity,       trace},
2588    Opts = [MasterAgentVerbosity,NetIfVerbosity],
2589    [{vsn, v1} | start_v1_agent(Config,Opts)].
2590
2591otp_4394_config(AgentDir, MgrDir, Ip0) ->
2592    ?DBG("otp_4394_config -> entry with"
2593	   "~n   AgentDir: ~p"
2594	   "~n   MgrDir:   ~p"
2595	   "~n   Ip0:      ~p", [AgentDir, MgrDir, Ip0]),
2596    Vsn = [v1],
2597    Ip = tuple_to_list(Ip0),
2598    ?line snmp_config:write_agent_snmp_files(AgentDir, Vsn, Ip,
2599					     ?TRAP_UDP, Ip, 4000,
2600					     "OTP-4394 test"),
2601    ?line case update_usm(Vsn, AgentDir) of
2602	true ->
2603	    ?line copy_file(filename:join(AgentDir, "usm.conf"),
2604			    filename:join(MgrDir, "usm.conf")),
2605	    ?line update_usm_mgr(Vsn, MgrDir);
2606	false ->
2607	    ?line ok
2608    end,
2609    C1 = {"a", "all-rights", "initial", "", "pc"},
2610    C2 = {"c", "secret", "secret_name", "", "secret_tag"},
2611    ?line write_community_conf(AgentDir, [C1, C2]),
2612    ?line update_vacm(Vsn, AgentDir),
2613    Ta1 = {"shelob v1",
2614	   [134,138,177,177], 5000, 1500, 3, %% Anv�nd Ip och modda
2615	   "pc1",
2616	   "target_v1", "",
2617	   %% [255,255,255,255,0,0],
2618	   [],
2619	   2048},
2620    Ta2 = {"bifur v1",
2621	   [134,138,177,75], 5000, 1500, 3, %% Anv�nd Ip
2622	   "pc2",
2623	   "target_v1", "",
2624	   %% [255,255,255,255,0,0],
2625	   [], 2048},
2626    ?line write_target_addr_conf(AgentDir, [Ta1, Ta2]),
2627    ?line write_target_params_conf(AgentDir, Vsn),
2628    ?line write_notify_conf(AgentDir),
2629    ok.
2630
2631finish_otp_4394(Config) when list(Config) ->
2632    ?DBG("finish_otp_4394 -> entry", []),
2633    C1 = stop_agent(Config),
2634    delete_files(C1),
2635    erase(mgr_node),
2636    lists:keydelete(vsn, 1, C1).
2637
2638otp_4394_test(suite) -> [];
2639otp_4394_test(Config) ->
2640    ?P1(otp_4394_test),
2641    {_SaNode, _MgrNode, _MibDir} = init_case(Config),
2642    ?TRY_TEST1(otp_4394_test1),
2643    ?DBG("otp_4394_test -> done", []),
2644    ok.
2645
2646otp_4394_test1() ->
2647    ?DBG("otp_4394_test1 -> entry", []),
2648    gn([[1,1]]),
2649    Res =
2650	case snmp_test_mgr:expect(1, [{[sysDescr,0],  "Erlang SNMP agent"}]) of
2651	    %% {error, 1, {"?",[]}, {"~w",[timeout]}}
2652	    {error, 1, _, {_, [timeout]}} ->
2653		?DBG("otp_4394_test1 -> expected result: timeout", []),
2654		ok;
2655	    Else ->
2656		Else
2657	end,
2658    ?DBG("otp_4394_test1 -> done with: ~p", [Res]),
2659    Res.
2660
2661
2662mk_ln(X) ->
2663    [length(X) | X].
2664
2665
2666
2667%% string used in index
2668is(S) -> [length(S) | S].
2669
2670expect(A,B) ->         ok = ?MGR:expect(A,B).
2671expect(A,B,C) ->       ok = ?MGR:expect(A,B,C).
2672expect(A,B,C,D) ->     ok = ?MGR:expect(A,B,C,D).
2673expect(A,B,C,D,E,F) -> ok = ?MGR:expect(A,B,C,D,E,F).
2674
2675