From 5c16cd5f30829fb3edf4e924cba5d59774865270 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 14 Feb 2012 11:36:48 +0100 Subject: [snmp] Updated with new snmpm_user behaviour --- lib/snmp/examples/ex2/snmp_ex2_manager.erl | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/snmp/examples/ex2/snmp_ex2_manager.erl b/lib/snmp/examples/ex2/snmp_ex2_manager.erl index ff873327bc..1b247d713d 100644 --- a/lib/snmp/examples/ex2/snmp_ex2_manager.erl +++ b/lib/snmp/examples/ex2/snmp_ex2_manager.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2006-2010. All Rights Reserved. +%% Copyright Ericsson AB 2006-2012. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -39,7 +39,7 @@ %% Manager callback API: -export([handle_error/3, - handle_agent/4, + handle_agent/5, handle_pdu/4, handle_trap/3, handle_inform/3, @@ -265,16 +265,17 @@ handle_snmp_callback(handle_error, {ReqId, Reason}) -> "~n Reason: ~p" "~n", [ReqId, Reason]), ok; -handle_snmp_callback(handle_agent, {Addr, Port, SnmpInfo}) -> +handle_snmp_callback(handle_agent, {Addr, Port, Type, SnmpInfo}) -> {ES, EI, VBs} = SnmpInfo, io:format("*** UNKNOWN AGENT ***" "~n Address: ~p" "~n Port: ~p" + "~n Type: ~p" "~n SNMP Info: " "~n Error Status: ~w" "~n Error Index: ~w" "~n Varbinds: ~p" - "~n", [Addr, Port, ES, EI, VBs]), + "~n", [Addr, Port, Type, ES, EI, VBs]), ok; handle_snmp_callback(handle_pdu, {TargetName, ReqId, SnmpResponse}) -> {ES, EI, VBs} = SnmpResponse, @@ -382,8 +383,8 @@ handle_error(ReqId, Reason, Server) when is_pid(Server) -> ignore. -handle_agent(Addr, Port, SnmpInfo, Server) when is_pid(Server) -> - report_callback(Server, handle_agent, {Addr, Port, SnmpInfo}), +handle_agent(Addr, Port, Type, SnmpInfo, Server) when is_pid(Server) -> + report_callback(Server, handle_agent, {Addr, Port, Type, SnmpInfo}), ignore. -- cgit v1.2.3 From e1904d50ebae01d704f998f7873067e8538e8a35 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 14 Feb 2012 12:14:04 +0100 Subject: [snmp] Removed warnings for unused variables --- lib/snmp/src/agent/snmpa_agent.erl | 2 +- lib/snmp/src/agent/snmpa_local_db.erl | 4 ++-- lib/snmp/src/agent/snmpa_mib.erl | 2 +- lib/snmp/src/app/snmp.appup.src | 14 ++++++++++++++ 4 files changed, 18 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/snmp/src/agent/snmpa_agent.erl b/lib/snmp/src/agent/snmpa_agent.erl index 9cc986cf47..9d30e332f1 100644 --- a/lib/snmp/src/agent/snmpa_agent.erl +++ b/lib/snmp/src/agent/snmpa_agent.erl @@ -1281,7 +1281,7 @@ handle_call({backup, BackupDir}, From, #state{backup = undefined} = S) -> ?vtrace("backup server: ~p", [BackupServer]), {noreply, S#state{backup = {BackupServer, From}}}; -handle_call({backup, _BackupDir}, From, #state{backup = Backup} = S) -> +handle_call({backup, _BackupDir}, _From, #state{backup = Backup} = S) -> ?vinfo("backup already in progress: ~p", [Backup]), {reply, {error, backup_in_progress}, S}; diff --git a/lib/snmp/src/agent/snmpa_local_db.erl b/lib/snmp/src/agent/snmpa_local_db.erl index ab277fc3e9..2c0cad807a 100644 --- a/lib/snmp/src/agent/snmpa_local_db.erl +++ b/lib/snmp/src/agent/snmpa_local_db.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. +%% Copyright Ericsson AB 1996-2012. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -515,7 +515,7 @@ handle_call({backup, BackupDir}, From, {reply, Error, State} end; -handle_call({backup, _BackupDir}, From, #state{backup = Backup} = S) -> +handle_call({backup, _BackupDir}, _From, #state{backup = Backup} = S) -> ?vinfo("backup already in progress: ~p", [Backup]), {reply, {error, backup_in_progress}, S}; diff --git a/lib/snmp/src/agent/snmpa_mib.erl b/lib/snmp/src/agent/snmpa_mib.erl index 574467d38f..575a018c0c 100644 --- a/lib/snmp/src/agent/snmpa_mib.erl +++ b/lib/snmp/src/agent/snmpa_mib.erl @@ -580,7 +580,7 @@ handle_call({backup, BackupDir}, From, {reply, Error, State} end; -handle_call({backup, _BackupDir}, From, #state{backup = Backup} = S) -> +handle_call({backup, _BackupDir}, _From, #state{backup = Backup} = S) -> ?vinfo("backup already in progress: ~p", [Backup]), {reply, {error, backup_in_progress}, S}; diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index c8e5eec6db..2f823a5c2d 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -22,6 +22,13 @@ %% ----- U p g r a d e ------------------------------------------------------- [ + {"4.21.7", + [ + {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, + {update, snmpa_mib, soft, soft_purge, soft_purge, []}, + {update, snmpa_agent, soft, soft_purge, soft_purge, []} + ] + }, {"4.21.6", [ {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, @@ -200,6 +207,13 @@ %% ------D o w n g r a d e --------------------------------------------------- [ + {"4.21.7", + [ + {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, + {update, snmpa_mib, soft, soft_purge, soft_purge, []}, + {update, snmpa_agent, soft, soft_purge, soft_purge, []} + ] + }, {"4.21.6", [ {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, -- cgit v1.2.3 From 953b3db9dc6e782623db5aae7f0c012ccb11018f Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 23 Jan 2012 18:55:23 +0100 Subject: [snmp/manager] Introduced new net-if module Moved the net-if multi-threading to a separate module, snmpm_net_if_mt. Restored the old module to its previous state. OTP-9876 --- lib/snmp/src/app/snmp.app.src | 3 +- lib/snmp/src/manager/depend.mk | 9 +- lib/snmp/src/manager/modules.mk | 3 +- lib/snmp/src/manager/snmpm_mpd.erl | 6 +- lib/snmp/src/manager/snmpm_net_if_mt.erl | 1206 ++++++++++++++++++++++++++++++ 5 files changed, 1221 insertions(+), 6 deletions(-) create mode 100644 lib/snmp/src/manager/snmpm_net_if_mt.erl (limited to 'lib') diff --git a/lib/snmp/src/app/snmp.app.src b/lib/snmp/src/app/snmp.app.src index a880a14696..7fb76baaa5 100644 --- a/lib/snmp/src/app/snmp.app.src +++ b/lib/snmp/src/app/snmp.app.src @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. +%% Copyright Ericsson AB 1996-2012. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -90,6 +90,7 @@ snmpm_misc_sup, snmpm_mpd, snmpm_net_if, + snmpm_net_if_mt, snmpm_net_if_filter, snmpm_network_interface, snmpm_network_interface_filter, diff --git a/lib/snmp/src/manager/depend.mk b/lib/snmp/src/manager/depend.mk index 0e7e9e3df7..2e7783c8ed 100644 --- a/lib/snmp/src/manager/depend.mk +++ b/lib/snmp/src/manager/depend.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2009. All Rights Reserved. +# Copyright Ericsson AB 2004-2012. All Rights Reserved. # # The contents of this file are subject to the Erlang Public License, # Version 1.1, (the "License"); you may not use this file except in @@ -49,6 +49,13 @@ $(EBIN)/snmpm_net_if.$(EMULATOR): \ snmpm_net_if.erl \ snmpm_network_interface.erl +$(EBIN)/snmpm_net_if_mt.$(EMULATOR): \ + ../../include/snmp_types.hrl \ + ../misc/snmp_debug.hrl \ + ../misc/snmp_verbosity.hrl \ + snmpm_net_if_mt.erl \ + snmpm_network_interface.erl + $(EBIN)/snmpm_server.$(EMULATOR): \ ../../include/snmp_types.hrl \ ../../include/STANDARD-MIB.hrl \ diff --git a/lib/snmp/src/manager/modules.mk b/lib/snmp/src/manager/modules.mk index 79f3dd65d9..d46545ea3f 100644 --- a/lib/snmp/src/manager/modules.mk +++ b/lib/snmp/src/manager/modules.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2009. All Rights Reserved. +# Copyright Ericsson AB 2004-2012. All Rights Reserved. # # The contents of this file are subject to the Erlang Public License, # Version 1.1, (the "License"); you may not use this file except in @@ -31,6 +31,7 @@ MODULES = \ snmpm_mpd \ snmpm_misc_sup \ snmpm_net_if \ + snmpm_net_if_mt \ snmpm_net_if_filter \ snmpm_server \ snmpm_server_sup \ diff --git a/lib/snmp/src/manager/snmpm_mpd.erl b/lib/snmp/src/manager/snmpm_mpd.erl index 103c87d32b..883224143e 100644 --- a/lib/snmp/src/manager/snmpm_mpd.erl +++ b/lib/snmp/src/manager/snmpm_mpd.erl @@ -110,9 +110,9 @@ process_msg(Msg, Domain, Addr, Port, State, NoteStore, Logger) -> #message{version = 'version-2', vsn_hdr = Community, data = Data} when State#state.v2c =:= true -> HS = ?empty_msg_size + length(Community), - (catch process_v1_v2c_msg('version-2', NoteStore, Msg, - Domain, Addr, Port, - Community, Data, HS, Logger)); + process_v1_v2c_msg('version-2', NoteStore, Msg, + Domain, Addr, Port, + Community, Data, HS, Logger); %% Version 3 #message{version = 'version-3', vsn_hdr = H, data = Data} diff --git a/lib/snmp/src/manager/snmpm_net_if_mt.erl b/lib/snmp/src/manager/snmpm_net_if_mt.erl new file mode 100644 index 0000000000..93b21af1d7 --- /dev/null +++ b/lib/snmp/src/manager/snmpm_net_if_mt.erl @@ -0,0 +1,1206 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2004-2012. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% + +-module(snmpm_net_if_mt). + +-behaviour(gen_server). +-behaviour(snmpm_network_interface). + + +%% Network Interface callback functions +-export([ + start_link/2, + stop/1, + send_pdu/6, % Backward compatibillity + send_pdu/7, % Backward compatibillity + send_pdu/8, + + inform_response/4, + + note_store/2, + + info/1, + verbosity/2, + %% system_info_updated/2, + get_log_type/1, set_log_type/2, + filter_reset/1 + ]). + +%% gen_server callbacks +-export([init/1, handle_call/3, handle_cast/2, handle_info/2, + code_change/3, terminate/2]). + +-define(SNMP_USE_V3, true). +-include("snmp_types.hrl"). +-include("snmpm_internal.hrl"). +-include("snmpm_atl.hrl"). +-include("snmp_debug.hrl"). + +%% -define(VMODULE,"NET_IF"). +-include("snmp_verbosity.hrl"). + +-record(state, + { + server, + note_store, + sock, + mpd_state, + logger, % undefined | pid() + irb = auto, % auto | {user, integer()} + irgc, + filter + }). + + +-define(DEFAULT_FILTER_MODULE, snmpm_net_if_filter). +-define(DEFAULT_FILTER_OPTS, [{module, ?DEFAULT_FILTER_MODULE}]). + +-ifdef(snmp_debug). +-define(GS_START_LINK(Args), + gen_server:start_link(?MODULE, Args, [{debug,[trace]}])). +-else. +-define(GS_START_LINK(Args), + gen_server:start_link(?MODULE, Args, [])). +-endif. + + +-define(IRGC_TIMEOUT, timer:minutes(5)). + +-define(ATL_SEQNO_INITIAL, 1). +-define(ATL_SEQNO_MAX, 2147483647). + + +%%%------------------------------------------------------------------- +%%% API +%%%------------------------------------------------------------------- +start_link(Server, NoteStore) -> + ?d("start_link -> entry with" + "~n Server: ~p" + "~n NoteStore: ~p", [Server, NoteStore]), + Args = [Server, NoteStore], + ?GS_START_LINK(Args). + +stop(Pid) -> + call(Pid, stop). + +send_pdu(Pid, Pdu, Vsn, MsgData, Addr, Port) -> + send_pdu(Pid, Pdu, Vsn, MsgData, Addr, Port, ?DEFAULT_EXTRA_INFO). + +send_pdu(Pid, Pdu, Vsn, MsgData, Addr, Port, ExtraInfo) -> + Domain = snmpm_config:default_transport_domain(), + send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Addr, Port, ExtraInfo). + +send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Addr, Port, ExtraInfo) + when is_record(Pdu, pdu) -> + ?d("send_pdu -> entry with" + "~n Pid: ~p" + "~n Pdu: ~p" + "~n Vsn: ~p" + "~n MsgData: ~p" + "~n Domain: ~p" + "~n Addr: ~p" + "~n Port: ~p", [Pid, Pdu, Vsn, MsgData, Domain, Addr, Port]), + cast(Pid, {send_pdu, Pdu, Vsn, MsgData, Domain, Addr, Port, ExtraInfo}). + +note_store(Pid, NoteStore) -> + call(Pid, {note_store, NoteStore}). + +inform_response(Pid, Ref, Addr, Port) -> + cast(Pid, {inform_response, Ref, Addr, Port}). + +info(Pid) -> + call(Pid, info). + +verbosity(Pid, V) -> + call(Pid, {verbosity, V}). + +%% system_info_updated(Pid, What) -> +%% call(Pid, {system_info_updated, What}). + +get_log_type(Pid) -> + call(Pid, get_log_type). + +set_log_type(Pid, NewType) -> + call(Pid, {set_log_type, NewType}). + +filter_reset(Pid) -> + cast(Pid, filter_reset). + + +%%%------------------------------------------------------------------- +%%% Callback functions from gen_server +%%%------------------------------------------------------------------- + +%%-------------------------------------------------------------------- +%% Func: init/1 +%% Returns: {ok, State} | +%% {ok, State, Timeout} | +%% ignore | +%% {stop, Reason} +%%-------------------------------------------------------------------- +init([Server, NoteStore]) -> + ?d("init -> entry with" + "~n Server: ~p" + "~n NoteStore: ~p", [Server, NoteStore]), + case (catch do_init(Server, NoteStore)) of + {error, Reason} -> + {stop, Reason}; + {ok, State} -> + {ok, State} + end. + +do_init(Server, NoteStore) -> + process_flag(trap_exit, true), + + %% -- Prio -- + {ok, Prio} = snmpm_config:system_info(prio), + process_flag(priority, Prio), + + %% -- Create inform request table -- + ets:new(snmpm_inform_request_table, + [set, protected, named_table, {keypos, 1}]), + + %% -- Verbosity -- + {ok, Verbosity} = snmpm_config:system_info(net_if_verbosity), + put(sname,mnif), + put(verbosity,Verbosity), + ?vlog("starting", []), + + %% -- MPD -- + {ok, Vsns} = snmpm_config:system_info(versions), + MpdState = snmpm_mpd:init(Vsns), + + %% -- Module dependent options -- + {ok, Opts} = snmpm_config:system_info(net_if_options), + + %% -- Inform response behaviour -- + {ok, IRB} = snmpm_config:system_info(net_if_irb), + IrGcRef = irgc_start(IRB), + + %% -- Socket -- + SndBuf = get_opt(Opts, sndbuf, default), + RecBuf = get_opt(Opts, recbuf, default), + BindTo = get_opt(Opts, bind_to, false), + NoReuse = get_opt(Opts, no_reuse, false), + {ok, Port} = snmpm_config:system_info(port), + {ok, Sock} = do_open_port(Port, SndBuf, RecBuf, BindTo, NoReuse), + + %% Flow control -- + FilterOpts = get_opt(Opts, filter, []), + FilterMod = create_filter(FilterOpts), + ?vdebug("FilterMod: ~w", [FilterMod]), + + %% -- Audit trail log --- + {ok, ATL} = snmpm_config:system_info(audit_trail_log), + Log = do_init_log(ATL), + + %% -- Initiate counters --- + init_counters(), + + %% -- We are done --- + State = #state{server = Server, + note_store = NoteStore, + mpd_state = MpdState, + sock = Sock, + log = Log, + irb = IRB, + irgc = IrGcRef, + filter = FilterMod}, + ?vdebug("started", []), + {ok, State}. + + +%% Open port +do_open_port(Port, SendSz, RecvSz, BindTo, NoReuse) -> + ?vtrace("do_open_port -> entry with" + "~n Port: ~p" + "~n SendSz: ~p" + "~n RecvSz: ~p" + "~n BindTo: ~p" + "~n NoReuse: ~p", [Port, SendSz, RecvSz, BindTo, NoReuse]), + IpOpts1 = bind_to(BindTo), + IpOpts2 = no_reuse(NoReuse), + IpOpts3 = recbuf(RecvSz), + IpOpts4 = sndbuf(SendSz), + IpOpts = [binary | IpOpts1 ++ IpOpts2 ++ IpOpts3 ++ IpOpts4], + OpenRes = + case init:get_argument(snmpm_fd) of + {ok, [[FdStr]]} -> + Fd = list_to_integer(FdStr), + gen_udp:open(0, [{fd, Fd}|IpOpts]); + error -> + gen_udp:open(Port, IpOpts) + end, + case OpenRes of + {error, _} = Error -> + throw(Error); + OK -> + OK + end. + +bind_to(true) -> + case snmpm_config:system_info(address) of + {ok, Addr} when is_list(Addr) -> + [{ip, list_to_tuple(Addr)}]; + {ok, Addr} -> + [{ip, Addr}]; + _ -> + [] + end; +bind_to(_) -> + []. + +no_reuse(false) -> + [{reuseaddr, true}]; +no_reuse(_) -> + []. + +recbuf(default) -> + []; +recbuf(Sz) -> + [{recbuf, Sz}]. + +sndbuf(default) -> + []; +sndbuf(Sz) -> + [{sndbuf, Sz}]. + + +create_filter(Opts) when is_list(Opts) -> + case get_opt(Opts, module, ?DEFAULT_FILTER_MODULE) of + ?DEFAULT_FILTER_MODULE = Mod -> + Mod; + Module -> + snmpm_network_interface_filter:verify(Module), + Module + end; +create_filter(BadOpts) -> + throw({error, {bad_filter_opts, BadOpts}}). + + +%% ---------------------------------------------------------------------- +%% Audit Trail Logger +%% ---------------------------------------------------------------------- + +%% Open log +do_init_log(false) -> + ?vtrace("do_init_log(false) -> entry", []), + undefined; +do_init_log(true) -> + ?vtrace("do_init_log(true) -> entry", []), + logger_start(). + +logger_start() -> + {Pid, _} = Logger = + erlang:spawn_opt(?MODULE, logger_init, [self()], [monitor]), + receive + {logger_started, Pid} -> + {ok, Type} = snmpm_config:system_info(audit_trail_log_type), + {Logger, Type}; + {'DOWN', _MonitorRef, process, Pid, Reason} -> + throw({error, {failed_starting_logger, Logger, Reason}}) + after 5000 -> + %% This should really not take any time at all, + %% so 5 secs is plenty of time. + throw({error, {failed_starting_logger, Logger, timeout}) + end. + +logger_init(Parent) -> + case (catch do_logger_init()) of + {ok, Log} -> + Parent ! {logger_started, self()}, + logger_loop(#logger{parent = Parent, + log = Log}); + {error, Reason} -> + exit({failed_init_log, Reason}) + end. + +%% Open log +do_logger_init() -> + ?vtrace("do_logger_init() -> entry", []), + {ok, Dir} = snmpm_config:system_info(audit_trail_log_dir), + {ok, Size} = snmpm_config:system_info(audit_trail_log_size), + {ok, Repair} = snmpm_config:system_info(audit_trail_log_repair), + Name = ?audit_trail_log_name, + File = filename:absname(?audit_trail_log_file, Dir), + case snmpm_config:system_info(audit_trail_log_seqno) of + {ok, true} -> + Initial = ?ATL_SEQNO_INITIAL, + Max = ?ATL_SEQNO_MAX, + Module = snmpm_config, + Function = increment_counter, + Args = [atl_seqno, Initial, Max], + SeqNoGen = {Module, Function, Args}, + case snmp_log:create(Name, File, SeqNoGen, Size, Repair, true) of + {ok, Log} -> + ?vdebug("log created: ~w", [Log]), + {ok, Log}; + {error, Reason} -> + {error, {failed_create_audit_log, Reason}} + end; + _ -> + case snmp_log:create(Name, File, Size, Repair, true) of + {ok, Log} -> + ?vdebug("log created: ~w", [Log]), + {ok, Log}; + {error, Reason} -> + {error, {failed_create_audit_log, Reason}} + end + end. + + +logger_loop(Logger) -> + receive + {log, Msg, Addr, Port} -> + snmp_log:log(Logger#logger.log, Msg, Addr, Port); + {stop, Pid} when Pid =:= Logger#logger.parent -> + exit(normal) + end, + logger_loop(Logger). + + +%% ---------------------------------------------------------------------- + + +%%-------------------------------------------------------------------- +%% Func: handle_call/3 +%% Returns: {reply, Reply, State} | +%% {reply, Reply, State, Timeout} | +%% {noreply, State} | +%% {noreply, State, Timeout} | +%% {stop, Reason, Reply, State} | (terminate/2 is called) +%% {stop, Reason, State} (terminate/2 is called) +%%-------------------------------------------------------------------- +handle_call({verbosity, Verbosity}, _From, State) -> + ?vlog("received verbosity request", []), + put(verbosity, Verbosity), + {reply, ok, State}; + +%% handle_call({system_info_updated, What}, _From, State) -> +%% ?vlog("received system_info_updated request with What = ~p", [What]), +%% {NewState, Reply} = handle_system_info_updated(State, What), +%% {reply, Reply, NewState}; + +handle_call(get_log_type, _From, State) -> + ?vlog("received get-log-type request", []), + Reply = (catch handle_get_log_type(State)), + {reply, Reply, State}; + +handle_call({set_log_type, NewType}, _From, State) -> + ?vlog("received set-log-type request with NewType = ~p", [NewType]), + {NewState, Reply} = (catch handle_set_log_type(State, NewType)), + {reply, Reply, NewState}; + +handle_call({note_store, Pid}, _From, State) -> + ?vlog("received new note_store: ~w", [Pid]), + {reply, ok, State#state{note_store = Pid}}; + +handle_call(stop, _From, State) -> + ?vlog("received stop request", []), + Reply = ok, + {stop, normal, Reply, State}; + +handle_call(info, _From, State) -> + ?vlog("received info request", []), + Reply = get_info(State), + {reply, Reply, State}; + +handle_call(Req, From, State) -> + warning_msg("received unknown request (from ~p): ~n~p", [Req, From]), + {reply, {error, {invalid_request, Req}}, State}. + + +%%-------------------------------------------------------------------- +%% Func: handle_cast/2 +%% Returns: {noreply, State} | +%% {noreply, State, Timeout} | +%% {stop, Reason, State} (terminate/2 is called) +%%-------------------------------------------------------------------- +handle_cast({send_pdu, Pdu, Vsn, MsgData, Domain, Addr, Port, ExtraInfo}, + State) -> + ?vlog("received send_pdu message with" + "~n Pdu: ~p" + "~n Vsn: ~p" + "~n MsgData: ~p" + "~n Domain: ~p" + "~n Addr: ~p" + "~n Port: ~p", [Pdu, Vsn, MsgData, Domain, Addr, Port]), + maybe_process_extra_info(ExtraInfo), + maybe_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, Port, State), + {noreply, State}; + +handle_cast({inform_response, Ref, Addr, Port}, State) -> + ?vlog("received inform_response message with" + "~n Ref: ~p" + "~n Addr: ~p" + "~n Port: ~p", [Ref, Addr, Port]), + handle_inform_response(Ref, Addr, Port, State), + {noreply, State}; + +handle_cast(filter_reset, State) -> + ?vlog("received filter_reset message", []), + reset_counters(), + {noreply, State}; + +handle_cast(Msg, State) -> + warning_msg("received unknown message: ~n~p", [Msg]), + {noreply, State}. + + +%%-------------------------------------------------------------------- +%% Func: handle_info/2 +%% Returns: {noreply, State} | +%% {noreply, State, Timeout} | +%% {stop, Reason, State} (terminate/2 is called) +%%-------------------------------------------------------------------- +handle_info({udp, Sock, Ip, Port, Bytes}, State) -> + ?vlog("received ~w bytes from ~p:~p", [size(Bytes), Ip, Port]), + handle_udp(Sock, Ip, Port, Bytes, State), + {noreply, State}; + +handle_info(inform_response_gc, State) -> + ?vlog("received inform_response_gc message", []), + State2 = handle_inform_response_gc(State), + {noreply, State2}; + +handle_info({disk_log, _Node, Log, Info}, State) -> + ?vlog("received disk_log message: " + "~n Info: ~p", [Info]), + State2 = handle_disk_log(Log, Info, State), + {noreply, State2}; + +handle_info(Info, State) -> + warning_msg("received unknown info: ~n~p", [Info]), + {noreply, State}. + + +%%-------------------------------------------------------------------- +%% Func: terminate/2 +%% Purpose: Shutdown the server +%% Returns: any (ignored by gen_server) +%%-------------------------------------------------------------------- +terminate(Reason, #state{log = Log, irgc = IrGcRef}) -> + ?vdebug("terminate: ~p", [Reason]), + irgc_stop(IrGcRef), + %% Close logs + do_close_log(Log), + ok. + + +do_close_log({Log, _Type}) -> + (catch snmp_log:sync(Log)), + (catch snmp_log:close(Log)), + ok; +do_close_log(_) -> + ok. + + +%%---------------------------------------------------------------------- +%% Func: code_change/3 +%% Purpose: Convert process state when code is changed +%% Returns: {ok, NewState} +%%---------------------------------------------------------------------- + +code_change(_Vsn, State, _Extra) -> + ?d("code_change -> entry with" + "~n Vsn: ~p" + "~n State: ~p" + "~n Extra: ~p", [_Vsn, State, _Extra]), + {ok, State}. + + +%%%------------------------------------------------------------------- +%%% Internal functions +%%%------------------------------------------------------------------- + +handle_udp(Sock, Addr, Port, Bytes, State) -> + spawn_opt(fun() -> + maybe_handle_recv_msg(Addr, Port, Bytes, State) + end, + [monitor]). + + +maybe_handle_recv_msg(Addr, Port, Bytes, #state{filter = FilterMod} = State) -> + case (catch FilterMod:accept_recv(Addr, Port)) of + false -> + %% Drop the received packet + inc(netIfMsgInDrops), + ok; + _ -> + handle_recv_msg(Addr, Port, Bytes, State) + end. + + +handle_recv_msg(Addr, Port, Bytes, #state{server = Pid}) + when is_binary(Bytes) andalso (size(Bytes) =:= 0) -> + Pid ! {snmp_error, {empty_message, Addr, Port}, Addr, Port}, + ok; + +handle_recv_msg(Addr, Port, Bytes, + #state{server = Pid, + note_store = NoteStore, + mpd_state = MpdState, + sock = Sock, + log = Log} = State) -> + Domain = snmp_conf:which_domain(Addr), % What the ****... + Logger = logger(Log, read, Addr, Port), + case (catch snmpm_mpd:process_msg(Bytes, Domain, Addr, Port, + MpdState, NoteStore, Logger)) of + + {ok, Vsn, Pdu, MS, ACM} -> + maybe_handle_recv_pdu(Addr, Port, Vsn, Pdu, MS, ACM, + Logger, State); + + {discarded, Reason, Report} -> + ?vdebug("discarded: ~p", [Reason]), + ErrorInfo = {failed_processing_message, Reason}, + Pid ! {snmp_error, ErrorInfo, Addr, Port}, + maybe_udp_send(State#state.filter, Sock, Addr, Port, Report), + ok; + + {discarded, Reason} -> + ?vdebug("discarded: ~p", [Reason]), + ErrorInfo = {failed_processing_message, Reason}, + Pid ! {snmp_error, ErrorInfo, Addr, Port}, + ok; + + Error -> + error_msg("processing of received message failed: " + "~n ~p", [Error]), + ok + end. + + +maybe_handle_recv_pdu(Addr, Port, + Vsn, #pdu{type = Type} = Pdu, PduMS, ACM, + Logger, + #state{filter = FilterMod} = State) -> + case (catch FilterMod:accept_recv_pdu(Addr, Port, Type)) of + false -> + inc(netIfPduInDrops), + ok; + _ -> + handle_recv_pdu(Addr, Port, Vsn, Pdu, PduMS, ACM, Logger, State) + end; +maybe_handle_recv_pdu(Addr, Port, Vsn, Trap, PduMS, ACM, Logger, + #state{filter = FilterMod} = State) + when is_record(Trap, trappdu) -> + case (catch FilterMod:accept_recv_pdu(Addr, Port, trappdu)) of + false -> + inc(netIfPduInDrops), + ok; + _ -> + handle_recv_pdu(Addr, Port, Vsn, Trap, PduMS, ACM, Logger, State) + end; +maybe_handle_recv_pdu(Addr, Port, Vsn, Pdu, PduMS, ACM, Logger, State) -> + handle_recv_pdu(Addr, Port, Vsn, Pdu, PduMS, ACM, Logger, State). + + +handle_recv_pdu(Addr, Port, + Vsn, #pdu{type = 'inform-request'} = Pdu, _PduMS, ACM, + Logger, #state{server = Pid, irb = IRB} = State) -> + handle_inform_request(IRB, Pid, Vsn, Pdu, ACM, + Addr, Port, Logger, State); +handle_recv_pdu(Addr, Port, + _Vsn, #pdu{type = report} = Pdu, _PduMS, ok, + _Logger, + #state{server = Pid} = _State) -> + ?vtrace("received report - ok", []), + Pid ! {snmp_report, {ok, Pdu}, Addr, Port}; +handle_recv_pdu(Addr, Port, + _Vsn, #pdu{type = report} = Pdu, _PduMS, + {error, ReqId, Reason}, + _Logger, + #state{server = Pid} = _State) -> + ?vtrace("received report - error", []), + Pid ! {snmp_report, {error, ReqId, Reason, Pdu}, Addr, Port}; +handle_recv_pdu(Addr, Port, + _Vsn, #pdu{type = 'snmpv2-trap'} = Pdu, _PduMS, _ACM, + _Logger, + #state{server = Pid} = _State) -> + ?vtrace("received snmpv2-trap", []), + Pid ! {snmp_trap, Pdu, Addr, Port}; +handle_recv_pdu(Addr, Port, + _Vsn, Trap, _PduMS, _ACM, + _Logger, + #state{server = Pid} = _State) when is_record(Trap, trappdu) -> + ?vtrace("received trappdu", []), + Pid ! {snmp_trap, Trap, Addr, Port}; +handle_recv_pdu(Addr, Port, + _Vsn, Pdu, _PduMS, _ACM, + _Logger, + #state{server = Pid} = _State) when is_record(Pdu, pdu) -> + ?vtrace("received pdu", []), + Pid ! {snmp_pdu, Pdu, Addr, Port}; +handle_recv_pdu(_Addr, _Port, _Vsn, Pdu, _PduMS, ACM, _Logger, _State) -> + ?vlog("received unexpected pdu: " + "~n Pdu: ~p" + "~n ACM: ~p", [Pdu, ACM]). + + +handle_inform_request(auto, Pid, Vsn, Pdu, ACM, Addr, Port, Logger, State) -> + ?vtrace("received inform-request (true)", []), + Pid ! {snmp_inform, ignore, Pdu, Addr, Port}, + RePdu = make_response_pdu(Pdu), + maybe_send_inform_response(RePdu, Vsn, ACM, Addr, Port, Logger, State); +handle_inform_request({user, To}, Pid, Vsn, #pdu{request_id = ReqId} = Pdu, + ACM, Addr, Port, _Logger, _State) -> + ?vtrace("received inform-request (false)", []), + + Pid ! {snmp_inform, ReqId, Pdu, Addr, Port}, + + %% Before we go any further, we need to check that we have not + %% already received this message (possible resend). + + Key = {ReqId, Addr, Port}, + case ets:lookup(snmpm_inform_request_table, Key) of + [_] -> + %% OK, we already know about this. We assume this + %% is a resend. Either the agent is really eager or + %% the user has not answered yet. Bad user! + ok; + [] -> + RePdu = make_response_pdu(Pdu), + Expire = t() + To, + Rec = {Key, Expire, {Vsn, ACM, RePdu}}, + ets:insert(snmpm_inform_request_table, Rec) + end. + +handle_inform_response(Ref, Addr, Port, State) -> + Key = {Ref, Addr, Port}, + case ets:lookup(snmpm_inform_request_table, Key) of + [{Key, _, {Vsn, ACM, RePdu}}] -> + Logger = logger(State#state.log, read, Addr, Port), + ets:delete(snmpm_inform_request_table, Key), + maybe_send_inform_response(RePdu, Vsn, ACM, Addr, Port, + Logger, State); + [] -> + %% Already acknowledged, or the user was to slow to reply... + ok + end, + ok. + +maybe_send_inform_response(RePdu, Vsn, ACM, Addr, Port, Logger, + #state{server = Pid, + sock = Sock, + filter = FilterMod}) -> + case (catch FilterMod:accept_send_pdu(Addr, Port, pdu_type_of(RePdu))) of + false -> + inc(netIfPduOutDrops), + ok; + _ -> + case snmpm_mpd:generate_response_msg(Vsn, RePdu, ACM, Logger) of + {ok, Msg} -> + maybe_udp_send(FilterMod, Sock, Addr, Port, Msg); + {discarded, Reason} -> + ?vlog("failed generating response message:" + "~n Reason: ~p", [Reason]), + ReqId = RePdu#pdu.request_id, + ErrorInfo = {failed_generating_response, {RePdu, Reason}}, + Pid ! {snmp_error, ReqId, ErrorInfo, Addr, Port}, + ok + end + end. + +handle_inform_response_gc(#state{irb = IRB} = State) -> + ets:safe_fixtable(snmpm_inform_request_table, true), + do_irgc(ets:first(snmpm_inform_request_table), t()), + ets:safe_fixtable(snmpm_inform_request_table, false), + State#state{irgc = irgc_start(IRB)}. + +%% We are deleting at the same time as we are traversing the table!!! +do_irgc('$end_of_table', _) -> + ok; +do_irgc(Key, Now) -> + Next = ets:next(snmpm_inform_request_table, Key), + case ets:lookup(snmpm_inform_request_table, Key) of + [{Key, BestBefore, _}] when BestBefore < Now -> + ets:delete(snmpm_inform_request_table, Key); + _ -> + ok + end, + do_irgc(Next, Now). + +irgc_start(auto) -> + undefined; +irgc_start(_) -> + erlang:send_after(?IRGC_TIMEOUT, self(), inform_response_gc). + +irgc_stop(undefined) -> + ok; +irgc_stop(Ref) -> + (catch erlang:cancel_timer(Ref)). + + +handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, Port, State) -> + spawn_opt(fun() -> + maybe_handle_send_pdu(Pdu, Vsn, MsgData, + Domain, Addr, Port, + State) + end, + [monitor]). + +maybe_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, Port, + #state{filter = FilterMod} = State) -> + case (catch FilterMod:accept_send_pdu(Addr, Port, pdu_type_of(Pdu))) of + false -> + inc(netIfPduOutDrops), + ok; + _ -> + do_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, Port, State) + end. + +do_handle_send_pdu(Pdu, Vsn, MsgData, _Domain, Addr, Port, + #state{server = Pid, + note_store = NoteStore, + sock = Sock, + log = Log, + filter = FilterMod}) -> + Logger = logger(Log, write, Addr, Port), + case (catch snmpm_mpd:generate_msg(Vsn, NoteStore, + Pdu, MsgData, Logger)) of + {ok, Msg} -> + ?vtrace("handle_send_pdu -> message generated", []), + maybe_udp_send(FilterMod, Sock, Addr, Port, Msg); + {discarded, Reason} -> + ?vlog("PDU not sent: " + "~n PDU: ~p" + "~n Reason: ~p", [Pdu, Reason]), + Pid ! {snmp_error, Pdu, Reason}, + ok + end. + + +maybe_udp_send(FilterMod, Sock, Addr, Port, Msg) -> + case (catch FilterMod:accept_send(Addr, Port)) of + false -> + inc(netIfMsgOutDrops), + ok; + _ -> + udp_send(Sock, Addr, Port, Msg) + end. + + +udp_send(Sock, Addr, Port, Msg) -> + case (catch gen_udp:send(Sock, Addr, Port, Msg)) of + ok -> + ?vdebug("sent ~w bytes to ~w:~w [~w]", + [sz(Msg), Addr, Port, Sock]), + ok; + {error, Reason} -> + error_msg("failed sending message to ~p:~p: " + "~n ~p",[Addr, Port, Reason]); + Error -> + error_msg("failed sending message to ~p:~p: " + "~n ~p",[Addr, Port, Error]) + end. + +sz(B) when is_binary(B) -> + size(B); +sz(L) when is_list(L) -> + length(L); +sz(_) -> + undefined. + + +handle_disk_log(_Log, {wrap, NoLostItems}, State) -> + ?vlog("Audit Trail Log - wrapped: ~w previously logged items where lost", + [NoLostItems]), + State; +handle_disk_log(_Log, {truncated, NoLostItems}, State) -> + ?vlog("Audit Trail Log - truncated: ~w items where lost when truncating", + [NoLostItems]), + State; +handle_disk_log(_Log, full, State) -> + error_msg("Failed to write to Audit Trail Log (full)", []), + State; +handle_disk_log(_Log, {error_status, ok}, State) -> + State; +handle_disk_log(_Log, {error_status, {error, Reason}}, State) -> + error_msg("Error status received from Audit Trail Log: " + "~n~p", [Reason]), + State; +handle_disk_log(_Log, _Info, State) -> + State. + + +%% mk_discovery_msg('version-3', Pdu, _VsnHdr, UserName) -> +%% ScopedPDU = #scopedPdu{contextEngineID = "", +%% contextName = "", +%% data = Pdu}, +%% Bytes = snmp_pdus:enc_scoped_pdu(ScopedPDU), +%% MsgID = get(msg_id), +%% put(msg_id,MsgID+1), +%% UsmSecParams = +%% #usmSecurityParameters{msgAuthoritativeEngineID = "", +%% msgAuthoritativeEngineBoots = 0, +%% msgAuthoritativeEngineTime = 0, +%% msgUserName = UserName, +%% msgPrivacyParameters = "", +%% msgAuthenticationParameters = ""}, +%% SecBytes = snmp_pdus:enc_usm_security_parameters(UsmSecParams), +%% PduType = Pdu#pdu.type, +%% Hdr = #v3_hdr{msgID = MsgID, +%% msgMaxSize = 1000, +%% msgFlags = snmp_misc:mk_msg_flags(PduType, 0), +%% msgSecurityModel = ?SEC_USM, +%% msgSecurityParameters = SecBytes}, +%% Msg = #message{version = 'version-3', vsn_hdr = Hdr, data = Bytes}, +%% case (catch snmp_pdus:enc_message_only(Msg)) of +%% {'EXIT', Reason} -> +%% error("Encoding error. Pdu: ~w. Reason: ~w",[Pdu, Reason]), +%% error; +%% L when list(L) -> +%% {Msg, L} +%% end; +%% mk_discovery_msg(Version, Pdu, {Com, _, _, _, _}, UserName) -> +%% Msg = #message{version = Version, vsn_hdr = Com, data = Pdu}, +%% case catch snmp_pdus:enc_message(Msg) of +%% {'EXIT', Reason} -> +%% error("Encoding error. Pdu: ~w. Reason: ~w",[Pdu, Reason]), +%% error; +%% L when list(L) -> +%% {Msg, L} +%% end. + + +%% mk_msg('version-3', Pdu, {Context, User, EngineID, CtxEngineId, SecLevel}, +%% MsgData) -> +%% %% Code copied from snmp_mpd.erl +%% {MsgId, SecName, SecData} = +%% if +%% tuple(MsgData), Pdu#pdu.type == 'get-response' -> +%% MsgData; +%% true -> +%% Md = get(msg_id), +%% put(msg_id, Md + 1), +%% {Md, User, []} +%% end, +%% ScopedPDU = #scopedPdu{contextEngineID = CtxEngineId, +%% contextName = Context, +%% data = Pdu}, +%% ScopedPDUBytes = snmp_pdus:enc_scoped_pdu(ScopedPDU), + +%% PduType = Pdu#pdu.type, +%% V3Hdr = #v3_hdr{msgID = MsgId, +%% msgMaxSize = 1000, +%% msgFlags = snmp_misc:mk_msg_flags(PduType, SecLevel), +%% msgSecurityModel = ?SEC_USM}, +%% Message = #message{version = 'version-3', vsn_hdr = V3Hdr, +%% data = ScopedPDUBytes}, +%% SecEngineID = case PduType of +%% 'get-response' -> snmp_framework_mib:get_engine_id(); +%% _ -> EngineID +%% end, +%% case catch snmp_usm:generate_outgoing_msg(Message, SecEngineID, +%% SecName, SecData, SecLevel) of +%% {'EXIT', Reason} -> +%% error("Encoding error. Pdu: ~w. Reason: ~w",[Pdu, Reason]), +%% error; +%% {error, Reason} -> +%% error("Encoding error. Pdu: ~w. Reason: ~w",[Pdu, Reason]), +%% error; +%% Packet -> +%% Packet +%% end; +%% mk_msg(Version, Pdu, {Com, _User, _EngineID, _Ctx, _SecLevel}, _SecData) -> +%% Msg = #message{version = Version, vsn_hdr = Com, data = Pdu}, +%% case catch snmp_pdus:enc_message(Msg) of +%% {'EXIT', Reason} -> +%% error("Encoding error. Pdu: ~w. Reason: ~w",[Pdu, Reason]), +%% error; +%% B when list(B) -> +%% B +%% end. + + +%% handle_system_info_updated(#state{log = {Log, _OldType}} = State, +%% audit_trail_log_type = _What) -> +%% %% Just to make sure, check that ATL is actually enabled +%% case snmpm_config:system_info(audit_trail_log) of +%% {ok, true} -> +%% {ok, Type} = snmpm_config:system_info(audit_trail_log_type), +%% NewState = State#state{log = {Log, Type}}, +%% {NewState, ok}; +%% _ -> +%% {State, {error, {adt_not_enabled}}} +%% end; +%% handle_system_info_updated(_State, _What) -> +%% ok. + +handle_get_log_type(#state{log = {_Log, Value}} = State) -> + %% Just to make sure, check that ATL is actually enabled + case snmpm_config:system_info(audit_trail_log) of + {ok, true} -> + Type = + case {lists:member(read, Value), lists:member(write, Value)} of + {true, true} -> + read_write; + {true, false} -> + read; + {false, true} -> + write; + {false, false} -> + throw({State, {error, {bad_atl_type, Value}}}) + end, + {ok, Type}; + _ -> + {error, not_enabled} + end; +handle_get_log_type(_State) -> + {error, not_enabled}. + +handle_set_log_type(#state{log = {Log, OldValue}} = State, NewType) -> + %% Just to make sure, check that ATL is actually enabled + case snmpm_config:system_info(audit_trail_log) of + {ok, true} -> + NewValue = + case NewType of + read -> + [read]; + write -> + [write]; + read_write -> + [read,write]; + _ -> + throw({State, {error, {bad_atl_type, NewType}}}) + end, + NewState = State#state{log = {Log, NewValue}}, + OldType = + case {lists:member(read, OldValue), + lists:member(write, OldValue)} of + {true, true} -> + read_write; + {true, false} -> + read; + {false, true} -> + write; + {false, false} -> + throw({State, {error, {bad_atl_type, OldValue}}}) + end, + {NewState, {ok, OldType}}; + _ -> + {State, {error, not_enabled}} + end; +handle_set_log_type(State, _NewType) -> + {State, {error, not_enabled}}. + + +%% ------------------------------------------------------------------- + +make_response_pdu(#pdu{request_id = ReqId, varbinds = Vbs}) -> + #pdu{type = 'get-response', + request_id = ReqId, + error_status = noError, + error_index = 0, + varbinds = Vbs}. + + +%% ---------------------------------------------------------------- + +pdu_type_of(#pdu{type = Type}) -> + Type; +pdu_type_of(TrapPdu) when is_record(TrapPdu, trappdu) -> + trap. + + +%% ------------------------------------------------------------------- + +%% At this point this function is used during testing +maybe_process_extra_info(?DEFAULT_EXTRA_INFO) -> + ok; +maybe_process_extra_info({?SNMPM_EXTRA_INFO_TAG, Fun}) + when is_function(Fun, 0) -> + (catch Fun()), + ok; +maybe_process_extra_info(_ExtraInfo) -> + ok. + + +%% ------------------------------------------------------------------- + +t() -> + {A,B,C} = erlang:now(), + A*1000000000+B*1000+(C div 1000). + + +%% ------------------------------------------------------------------- + +logger(undefined, _Type, _Addr, _Port) -> + fun(_) -> + ok + end; +logger({{Pid, _}, Types}, Type, Addr, Port) -> + case lists:member(Type, Types) of + true -> + fun(Msg) -> + Pid ! {log, Msg, Addr, Port} + end; + false -> + fun(_) -> + ok + end + end. + + +%% ------------------------------------------------------------------- + +%% info_msg(F, A) -> +%% ?snmpm_info("NET-IF server: " ++ F, A). + +warning_msg(F, A) -> + ?snmpm_warning("NET-IF server: " ++ F, A). + +error_msg(F, A) -> + ?snmpm_error("NET-IF server: " ++ F, A). + + + +%%%------------------------------------------------------------------- + +% get_opt(Key, Opts) -> +% ?vtrace("get option ~w", [Key]), +% snmp_misc:get_option(Key, Opts). + +get_opt(Opts, Key, Def) -> + ?vtrace("get option ~w with default ~p", [Key, Def]), + snmp_misc:get_option(Key, Opts, Def). + + +%% ------------------------------------------------------------------- + +get_info(#state{sock = Id}) -> + ProcSize = proc_mem(self()), + PortInfo = get_port_info(Id), + [{process_memory, ProcSize}, {port_info, PortInfo}]. + +proc_mem(P) when is_pid(P) -> + case (catch erlang:process_info(P, memory)) of + {memory, Sz} when is_integer(Sz) -> + Sz; + _ -> + undefined + end. +%% proc_mem(_) -> +%% undefined. + + +get_port_info(Id) -> + PortInfo = + case (catch erlang:port_info(Id)) of + PI when is_list(PI) -> + [{port_info, PI}]; + _ -> + [] + end, + PortStatus = + case (catch prim_inet:getstatus(Id)) of + {ok, PS} -> + [{port_status, PS}]; + _ -> + [] + end, + PortAct = + case (catch inet:getopts(Id, [active])) of + {ok, PA} -> + [{port_act, PA}]; + _ -> + [] + end, + PortStats = + case (catch inet:getstat(Id)) of + {ok, Stat} -> + [{port_stats, Stat}]; + _ -> + [] + end, + IfList = + case (catch inet:getif(Id)) of + {ok, IFs} -> + [{interfaces, IFs}]; + _ -> + [] + end, + BufSz = + case (catch inet:getopts(Id, [recbuf, sndbuf, buffer])) of + {ok, Sz} -> + [{buffer_size, Sz}]; + _ -> + [] + end, + [{socket, Id}] ++ + IfList ++ + PortStats ++ + PortInfo ++ + PortStatus ++ + PortAct ++ + BufSz. + + +%%----------------------------------------------------------------- +%% Counter functions +%%----------------------------------------------------------------- +init_counters() -> + F = fun(Counter) -> maybe_create_counter(Counter) end, + lists:map(F, counters()). + +reset_counters() -> + F = fun(Counter) -> snmpm_config:reset_stats_counter(Counter) end, + lists:map(F, counters()). + +maybe_create_counter(Counter) -> + snmpm_config:maybe_cre_stats_counter(Counter, 0). + +counters() -> + [ + netIfMsgOutDrops, + netIfMsgInDrops, + netIfPduOutDrops, + netIfPduInDrops + ]. + +inc(Name) -> inc(Name, 1). +inc(Name, N) -> snmpm_config:incr_stats_counter(Name, N). + +%% get_counters() -> +%% Counters = counters(), +%% get_counters(Counters, []). + +%% get_counters([], Acc) -> +%% lists:reverse(Acc); +%% get_counters([Counter|Counters], Acc) -> +%% case snmpm_config:get_stats_counter(Counter) of +%% {ok, CounterVal} -> +%% get_counters(Counters, [{Counter, CounterVal}|Acc]); +%% _ -> +%% get_counters(Counters, Acc) +%% end. + + +%% ---------------------------------------------------------------- + +call(Pid, Req) -> + call(Pid, Req, infinity). + +call(Pid, Req, Timeout) -> + gen_server:call(Pid, Req, Timeout). + +cast(Pid, Msg) -> + gen_server:cast(Pid, Msg). + -- cgit v1.2.3 From ac97167c084941d524fc46fef1f52de24c807655 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 31 Jan 2012 16:20:22 +0100 Subject: [snmp/manager] Misc cleanup OTP-9876 --- lib/snmp/src/manager/snmpm_config.erl | 2 +- lib/snmp/src/manager/snmpm_net_if_mt.erl | 114 ++++++++++++++++++++++++------- lib/snmp/src/misc/snmp_verbosity.erl | 4 +- lib/snmp/vsn.mk | 2 +- 4 files changed, 96 insertions(+), 26 deletions(-) (limited to 'lib') diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl index c2e57abddb..5bbf9e5542 100644 --- a/lib/snmp/src/manager/snmpm_config.erl +++ b/lib/snmp/src/manager/snmpm_config.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2011. All Rights Reserved. +%% Copyright Ericsson AB 2004-2012. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/snmp/src/manager/snmpm_net_if_mt.erl b/lib/snmp/src/manager/snmpm_net_if_mt.erl index 93b21af1d7..ab6965691c 100644 --- a/lib/snmp/src/manager/snmpm_net_if_mt.erl +++ b/lib/snmp/src/manager/snmpm_net_if_mt.erl @@ -46,6 +46,8 @@ -export([init/1, handle_call/3, handle_cast/2, handle_info/2, code_change/3, terminate/2]). +-export([logger_init/2]). + -define(SNMP_USE_V3, true). -include("snmp_types.hrl"). -include("snmpm_internal.hrl"). @@ -61,12 +63,19 @@ note_store, sock, mpd_state, - logger, % undefined | pid() + log, irb = auto, % auto | {user, integer()} irgc, filter }). +%% State record of the logger process +-record(logger, + { + parent, + log + }). + -define(DEFAULT_FILTER_MODULE, snmpm_net_if_filter). -define(DEFAULT_FILTER_OPTS, [{module, ?DEFAULT_FILTER_MODULE}]). @@ -308,7 +317,8 @@ do_init_log(true) -> logger_start() -> {Pid, _} = Logger = - erlang:spawn_opt(?MODULE, logger_init, [self()], [monitor]), + erlang:spawn_opt(?MODULE, logger_init, [self(), get(verbosity)], + [monitor]), receive {logger_started, Pid} -> {ok, Type} = snmpm_config:system_info(audit_trail_log_type), @@ -318,17 +328,19 @@ logger_start() -> after 5000 -> %% This should really not take any time at all, %% so 5 secs is plenty of time. - throw({error, {failed_starting_logger, Logger, timeout}) + throw({error, {failed_starting_logger, Logger, timeout}}) end. -logger_init(Parent) -> +logger_init(Parent, Verbosity) -> + put(sname, mnifl), + put(verbosity, Verbosity), case (catch do_logger_init()) of {ok, Log} -> Parent ! {logger_started, self()}, logger_loop(#logger{parent = Parent, log = Log}); {error, Reason} -> - exit({failed_init_log, Reason}) + exit({logger, failed_init, Reason}) end. %% Open log @@ -442,7 +454,7 @@ handle_cast({send_pdu, Pdu, Vsn, MsgData, Domain, Addr, Port, ExtraInfo}, "~n Addr: ~p" "~n Port: ~p", [Pdu, Vsn, MsgData, Domain, Addr, Port]), maybe_process_extra_info(ExtraInfo), - maybe_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, Port, State), + handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, Port, State), {noreply, State}; handle_cast({inform_response, Ref, Addr, Port}, State) -> @@ -469,9 +481,9 @@ handle_cast(Msg, State) -> %% {noreply, State, Timeout} | %% {stop, Reason, State} (terminate/2 is called) %%-------------------------------------------------------------------- -handle_info({udp, Sock, Ip, Port, Bytes}, State) -> +handle_info({udp, Sock, Ip, Port, Bytes}, #state{sock = Sock} = State) -> ?vlog("received ~w bytes from ~p:~p", [size(Bytes), Ip, Port]), - handle_udp(Sock, Ip, Port, Bytes, State), + handle_udp(Ip, Port, Bytes, State), {noreply, State}; handle_info(inform_response_gc, State) -> @@ -485,6 +497,13 @@ handle_info({disk_log, _Node, Log, Info}, State) -> State2 = handle_disk_log(Log, Info, State), {noreply, State2}; +handle_info({'DOWN', _MRef, process, Pid, {net_if_worker, ExitStatus}}, + State) -> + ?vdebug("received DOWN message from net_if-worker: " + "~n ExitStatus: ~p", [ExitStatus]), + handle_worker_exit(Pid, ExitStatus), + {noreply, State}; + handle_info(Info, State) -> warning_msg("received unknown info: ~n~p", [Info]), {noreply, State}. @@ -529,9 +548,11 @@ code_change(_Vsn, State, _Extra) -> %%% Internal functions %%%------------------------------------------------------------------- -handle_udp(Sock, Addr, Port, Bytes, State) -> +handle_udp(Addr, Port, Bytes, State) -> spawn_opt(fun() -> - maybe_handle_recv_msg(Addr, Port, Bytes, State) + Res = (catch maybe_handle_recv_msg(Addr, Port, + Bytes, State)), + worker_exit(udp, {Addr, Port}, Res) end, [monitor]). @@ -622,36 +643,42 @@ handle_recv_pdu(Addr, Port, _Logger, #state{server = Pid} = _State) -> ?vtrace("received report - ok", []), - Pid ! {snmp_report, {ok, Pdu}, Addr, Port}; + Pid ! {snmp_report, {ok, Pdu}, Addr, Port}, + ok; handle_recv_pdu(Addr, Port, _Vsn, #pdu{type = report} = Pdu, _PduMS, {error, ReqId, Reason}, _Logger, #state{server = Pid} = _State) -> ?vtrace("received report - error", []), - Pid ! {snmp_report, {error, ReqId, Reason, Pdu}, Addr, Port}; + Pid ! {snmp_report, {error, ReqId, Reason, Pdu}, Addr, Port}, + ok; handle_recv_pdu(Addr, Port, _Vsn, #pdu{type = 'snmpv2-trap'} = Pdu, _PduMS, _ACM, _Logger, #state{server = Pid} = _State) -> ?vtrace("received snmpv2-trap", []), - Pid ! {snmp_trap, Pdu, Addr, Port}; + Pid ! {snmp_trap, Pdu, Addr, Port}, + ok; handle_recv_pdu(Addr, Port, _Vsn, Trap, _PduMS, _ACM, _Logger, #state{server = Pid} = _State) when is_record(Trap, trappdu) -> ?vtrace("received trappdu", []), - Pid ! {snmp_trap, Trap, Addr, Port}; + Pid ! {snmp_trap, Trap, Addr, Port}, + ok; handle_recv_pdu(Addr, Port, _Vsn, Pdu, _PduMS, _ACM, _Logger, #state{server = Pid} = _State) when is_record(Pdu, pdu) -> ?vtrace("received pdu", []), - Pid ! {snmp_pdu, Pdu, Addr, Port}; + Pid ! {snmp_pdu, Pdu, Addr, Port}, + ok; handle_recv_pdu(_Addr, _Port, _Vsn, Pdu, _PduMS, ACM, _Logger, _State) -> ?vlog("received unexpected pdu: " "~n Pdu: ~p" - "~n ACM: ~p", [Pdu, ACM]). + "~n ACM: ~p", [Pdu, ACM]), + ok. handle_inform_request(auto, Pid, Vsn, Pdu, ACM, Addr, Port, Logger, State) -> @@ -680,9 +707,21 @@ handle_inform_request({user, To}, Pid, Vsn, #pdu{request_id = ReqId} = Pdu, Expire = t() + To, Rec = {Key, Expire, {Vsn, ACM, RePdu}}, ets:insert(snmpm_inform_request_table, Rec) - end. + end, + ok. handle_inform_response(Ref, Addr, Port, State) -> + spawn_opt(fun() -> + Res = (catch do_handle_inform_response(Ref, + Addr, Port, + State)), + worker_exit(inform_reponse, {Addr, Port}, Res) + end, + [monitor]). + + + +do_handle_inform_response(Ref, Addr, Port, State) -> Key = {Ref, Addr, Port}, case ets:lookup(snmpm_inform_request_table, Key) of [{Key, _, {Vsn, ACM, RePdu}}] -> @@ -750,9 +789,10 @@ irgc_stop(Ref) -> handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, Port, State) -> spawn_opt(fun() -> - maybe_handle_send_pdu(Pdu, Vsn, MsgData, - Domain, Addr, Port, - State) + Res = (catch maybe_handle_send_pdu(Pdu, Vsn, MsgData, + Domain, Addr, Port, + State)), + worker_exit(send_pdu, {Domain, Addr, Port}, Res) end, [monitor]). @@ -776,7 +816,7 @@ do_handle_send_pdu(Pdu, Vsn, MsgData, _Domain, Addr, Port, case (catch snmpm_mpd:generate_msg(Vsn, NoteStore, Pdu, MsgData, Logger)) of {ok, Msg} -> - ?vtrace("handle_send_pdu -> message generated", []), + ?vtrace("do_handle_send_pdu -> message generated", []), maybe_udp_send(FilterMod, Sock, Addr, Port, Msg); {discarded, Reason} -> ?vlog("PDU not sent: " @@ -805,10 +845,12 @@ udp_send(Sock, Addr, Port, Msg) -> ok; {error, Reason} -> error_msg("failed sending message to ~p:~p: " - "~n ~p",[Addr, Port, Reason]); + "~n ~p",[Addr, Port, Reason]), + ok; Error -> error_msg("failed sending message to ~p:~p: " - "~n ~p",[Addr, Port, Error]) + "~n ~p",[Addr, Port, Error]), + ok end. sz(B) when is_binary(B) -> @@ -1002,6 +1044,32 @@ handle_set_log_type(State, _NewType) -> {State, {error, not_enabled}}. +%% ------------------------------------------------------------------- + +worker_exit(Tag, Info, Result) -> + exit({net_if_worker, {Tag, Info, Result}}). + +handle_worker_exit(_, {_, _, ok}) -> + ok; +handle_worker_exit(Pid, {udp, {Addr, Port}, ExitStatus}) -> + warning_msg("Worker process (~p) terminated " + "while processing (incomming) message from ~w:~w: " + "~n~p", [Pid, Addr, Port, ExitStatus]), + ok; +handle_worker_exit(Pid, {send_pdu, {Domain, Addr, Port}, ExitStatus}) -> + warning_msg("Worker process (~p) terminated " + "while processing (outgoing) pdu for [~w] ~w:~w: " + "~n~p", [Pid, Domain, Addr, Port, ExitStatus]), + ok; +handle_worker_exit(Pid, {inform_response, {Addr, Port}, ExitStatus}) -> + warning_msg("Worker process (~p) terminated " + "while processing (outgoing) inform response for ~w:~w: " + "~n~p", [Pid, Addr, Port, ExitStatus]), + ok; +handle_worker_exit(_, _) -> + ok. + + %% ------------------------------------------------------------------- make_response_pdu(#pdu{request_id = ReqId, varbinds = Vbs}) -> diff --git a/lib/snmp/src/misc/snmp_verbosity.erl b/lib/snmp/src/misc/snmp_verbosity.erl index 85037ba2ae..f2f85ebf79 100644 --- a/lib/snmp/src/misc/snmp_verbosity.erl +++ b/lib/snmp/src/misc/snmp_verbosity.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2000-2009. All Rights Reserved. +%% Copyright Ericsson AB 2000-2012. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -144,6 +144,8 @@ image_of_sname(mse) -> "M-SERVER"; image_of_sname(msew) -> io_lib:format("M-SERVER-worker(~p)", [self()]); image_of_sname(mns) -> "M-NOTE-STORE"; image_of_sname(mnif) -> "M-NET-IF"; +image_of_sname(mnifl) -> "M-NET-IF-LOGGER"; +image_of_sname(mnifw) -> io_lib:format("M-NET-IF-worker(~p)", [self()]); image_of_sname(mconf) -> "M-CONF"; image_of_sname(mgr) -> "MGR"; diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index dafdcefe79..aea38a4cdb 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -18,6 +18,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 4.21.5 +SNMP_VSN = 4.22 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From db2c9e79e24d742745cc1be3e80d239e0ac6f894 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 1 Feb 2012 14:58:19 +0100 Subject: [snmp/manager] Added test cases for net_if-mt Made the inform_request table public (to allow the worker processes to insert data). Also added test cases (this was done by adding "mt" groups). OTP-9876 --- lib/snmp/src/manager/snmpm_net_if_mt.erl | 4 +- lib/snmp/test/snmp_manager_test.erl | 137 ++++++++++++++++++++++++++----- 2 files changed, 119 insertions(+), 22 deletions(-) (limited to 'lib') diff --git a/lib/snmp/src/manager/snmpm_net_if_mt.erl b/lib/snmp/src/manager/snmpm_net_if_mt.erl index ab6965691c..753626be72 100644 --- a/lib/snmp/src/manager/snmpm_net_if_mt.erl +++ b/lib/snmp/src/manager/snmpm_net_if_mt.erl @@ -182,8 +182,10 @@ do_init(Server, NoteStore) -> process_flag(priority, Prio), %% -- Create inform request table -- + %% This should really be protected, but it also needs to + %% be writable for the worker processes, so... ets:new(snmpm_inform_request_table, - [set, protected, named_table, {keypos, 1}]), + [set, public, named_table, {keypos, 1}]), %% -- Verbosity -- {ok, Verbosity} = snmpm_config:system_info(net_if_verbosity), diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index 75c9f7b277..5dc5799ddf 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -146,12 +146,55 @@ %% External functions %%====================================================================== +which_group(Config) -> + case ?config(tc_group_properties, Config) of + undefined -> + %% Properties, if they exist, is a list + ignore; + GroupProps -> + GroupName = ?config(name, GroupProps), + %% tc_group_path is a list of parent groups... + GroupPaths = ?config(tc_group_path, Config), + {GroupName, [?config(name, GPs) || GPs <- GroupPaths]} + end. + +mk_group_dir(GPRoot, [], Group) -> + ?DBG("mk_group_dir -> entry with: " + "~n GPRoot: ~p" + "~n Group: ~p", [GPRoot, Group]), + GroupDir = filename:join(GPRoot, Group), + case file:make_dir(GroupDir) of + ok -> + GroupDir; + {error, eexist} -> + GroupDir; + Error -> + ?FAIL({failed_creating_group_dir, Error}) + end; +mk_group_dir(GPRoot, [Dir|Dirs], Group) -> + ?DBG("mk_group_dir -> entry with: " + "~n GPRoot: ~p" + "~n Dir: ~p" + "~n Group: ~p", [GPRoot, Dir, Group]), + GPDir = filename:join(GPRoot, Dir), + case file:make_dir(GPDir) of + ok -> + ok; + {error, eexist} -> + ok; + Error -> + ?FAIL({failed_creating_group_path_dir, Error}) + end, + mk_group_dir(GPDir, Dirs, Group). + + + init_per_testcase(Case, Config) when is_list(Config) -> io:format(user, "~n~n*** INIT ~w:~w ***~n~n", [?MODULE,Case]), init_per_testcase2(Case, Config). init_per_testcase2(Case, Config) -> - ?DBG("init [~w] Nodes [1]: ~p", [Case, erlang:nodes()]), + ?DBG("init_per_testcase2 -> ~p", [erlang:nodes()]), %% Fix a correct data dir (points to the wrong location): DataDir0 = ?config(data_dir, Config), @@ -162,20 +205,35 @@ init_per_testcase2(Case, Config) -> PrivDir = ?config(priv_dir, Config), TopDir = filename:join(PrivDir, ?MODULE), + ?DBG("init_per_testcase2 -> try create top dir: ~n~p", [TopDir]), case file:make_dir(TopDir) of ok -> ok; {error, eexist} -> ok; - Error -> - ?FAIL({failed_creating_subsuite_top_dir, Error}) + ErrorS -> + ?FAIL({failed_creating_subsuite_top_dir, ErrorS}) end, + + CaseRootDir = + case which_group(Config) of + {Group, GroupPath} -> + ?DBG("init_per_testcase2 -> try create group dir with: " + "~n Group: ~p" + "~n GroupPath: ~p", [Group, GroupPath]), + mk_group_dir(TopDir, GroupPath, Group); + _ -> + TopDir + end, - CaseTopDir = filename:join(TopDir, Case), + CaseTopDir = filename:join(CaseRootDir, Case), + ?DBG("init_per_testcase2 -> try create case top dir: ~n~p", [CaseTopDir]), ?line ok = file:make_dir(CaseTopDir), %% -- Manager dirs -- - MgrTopDir = filename:join(CaseTopDir, "manager/"), + MgrTopDir = filename:join(CaseTopDir, "manager/"), + ?DBG("init_per_testcase2 -> try create manager top dir: ~n~p", + [MgrTopDir]), ?line ok = file:make_dir(MgrTopDir), MgrConfDir = filename:join(MgrTopDir, "conf/"), @@ -204,6 +262,7 @@ init_per_testcase2(Case, Config) -> {watchdog, ?WD_START(?MINS(5))}, {ip, ?LOCALHOST()}, {top_dir, TopDir}, + {case_root_dir, CaseRootDir}, {agent_dir, AgTopDir}, {agent_conf_dir, AgConfDir}, {agent_db_dir, AgDbDir}, @@ -388,7 +447,9 @@ all() -> {group, user_tests}, {group, agent_tests}, {group, request_tests}, + {group, request_tests_mt}, {group, event_tests}, + {group, event_tests_mt}, discovery, {group, tickets} ]. @@ -431,6 +492,15 @@ groups() -> {group, misc_request_tests} ] }, + {request_tests_mt, [], + [ + {group, get_tests}, + {group, get_next_tests}, + {group, set_tests}, + {group, bulk_tests}, + {group, misc_request_tests} + ] + }, {get_tests, [], [ simple_sync_get1, @@ -477,18 +547,30 @@ groups() -> misc_async2 ] }, - {event_tests, [], - [ - trap1%% , - %% trap2, - %% inform1, - %% inform2, - %% inform3, - %% inform4, - %% inform_swarm, - %% report - ] - }, + {event_tests, [], + [ + trap1, + trap2, + inform1, + inform2, + inform3, + inform4, + inform_swarm, + report + ] + }, + {event_tests_mt, [], + [ + trap1, + trap2, + inform1, + inform2, + inform3, + inform4, + inform_swarm, + report + ] + }, {tickets, [], [ {group, otp8015}, @@ -507,8 +589,12 @@ groups() -> } ]. +init_per_group(request_tests_mt = _GroupName, Config) -> + [{manager_net_if_module, snmpm_net_if_mt} | Config]; +init_per_group(event_tests_mt = _GroupName, Config) -> + [{manager_net_if_module, snmpm_net_if_mt} | Config]; init_per_group(_GroupName, Config) -> - Config. + Config. end_per_group(_GroupName, Config) -> Config. @@ -4423,7 +4509,7 @@ inform1(Config) when is_list(Config) -> inform2(suite) -> []; inform2(Config) when is_list(Config) -> process_flag(trap_exit, true), - put(tname,i2), + put(tname, i2), p("starting with Config: ~p~n", [Config]), MgrNode = ?config(manager_node, Config), @@ -4577,7 +4663,7 @@ inform2(Config) when is_list(Config) -> [ {1, "Manager and agent info at start of test", Cmd1}, {2, "Send notifcation [no receiver] from agent", Cmd2}, - {3, "await inform-sent acknowledge from agent", Cmd3}, + {3, "Await inform-sent acknowledge from agent", Cmd3}, {4, "Await first inform to manager - do not reply", Cmd4}, {5, "Await second inform to manager - reply", Cmd5}, {6, "await inform-acknowledge from agent", Cmd6}, @@ -5720,6 +5806,15 @@ start_manager(Node, Vsns, Conf0, Opts) -> AtlSeqNo = get_opt(manager_atl_seqno, Conf0, false), + NetIfConf = + case get_opt(manager_net_if_module, Conf0, no_module) of + no_module -> + [{verbosity, NetIfVerbosity}]; + NetIfModule -> + [{module, NetIfModule}, + {verbosity, NetIfVerbosity}] + end, + Env = [{versions, Vsns}, {inform_request_behaviour, IRB}, {audit_trail_log, [{type, read_write}, @@ -5732,7 +5827,7 @@ start_manager(Node, Vsns, Conf0, Opts) -> {verbosity, ConfigVerbosity}]}, {note_store, [{verbosity, NoteStoreVerbosity}]}, {server, [{verbosity, ServerVerbosity}]}, - {net_if, [{verbosity, NetIfVerbosity}]}], + {net_if, NetIfConf}], ?line ok = set_mgr_env(Node, Env), ?line ok = start_snmp(Node), -- cgit v1.2.3 From a77df6bb39b851ef86385577f758378e8282a72b Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 1 Feb 2012 15:00:28 +0100 Subject: [snmp/manager] Preliminary appup Add preliminary appup. Also reorder app file. OTP-9876 --- lib/snmp/src/app/snmp.app.src | 2 +- lib/snmp/src/app/snmp.appup.src | 200 +++++++++++++++++----------------------- 2 files changed, 85 insertions(+), 117 deletions(-) (limited to 'lib') diff --git a/lib/snmp/src/app/snmp.app.src b/lib/snmp/src/app/snmp.app.src index 7fb76baaa5..b11c1ef934 100644 --- a/lib/snmp/src/app/snmp.app.src +++ b/lib/snmp/src/app/snmp.app.src @@ -90,8 +90,8 @@ snmpm_misc_sup, snmpm_mpd, snmpm_net_if, - snmpm_net_if_mt, snmpm_net_if_filter, + snmpm_net_if_mt, snmpm_network_interface, snmpm_network_interface_filter, snmpm_server, diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index 589b728dc5..50a5916d20 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -22,12 +22,39 @@ %% ----- U p g r a d e ------------------------------------------------------- [ + %% This is a place holder + {"4.21.7", + [ + {load_module, snmp_verbosity, soft_purge, soft_purge, []}, + {load_module, snmpm_mpd, soft_purge, soft_purge, []}, + {add_module, snmpm_net_if_mt} + ] + }, + %% This is a place holder + {"4.21.6", + [ + {load_module, snmp_verbosity, soft_purge, soft_purge, []}, + {load_module, snmpm_mpd, soft_purge, soft_purge, []}, + {add_module, snmpm_net_if_mt} + ] + }, + %% This is a place holder + {"4.21.5", + [ + {load_module, snmp_verbosity, soft_purge, soft_purge, []}, + {load_module, snmpm_mpd, soft_purge, soft_purge, []}, + {add_module, snmpm_net_if_mt} + ] + }, {"4.21.4", [ {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, {load_module, snmpa_vacm, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, []} + {load_module, snmp_verbosity, soft_purge, soft_purge, []}, + {load_module, snmpm_mpd, soft_purge, soft_purge, []}, + {update, snmpa_agent, soft, soft_purge, soft_purge, []}, + {add_module, snmpm_net_if_mt} ] }, {"4.21.3", @@ -35,8 +62,11 @@ {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, {load_module, snmpa_vacm, soft_purge, soft_purge, []}, + {load_module, snmp_verbosity, soft_purge, soft_purge, []}, + {load_module, snmpm_mpd, soft_purge, soft_purge, []}, {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, []} + {update, snmpa_agent, soft, soft_purge, soft_purge, []}, + {add_module, snmpm_net_if_mt} ] }, {"4.21.2", @@ -47,8 +77,11 @@ {load_module, snmpa_set_lib, soft_purge, soft_purge, []}, {load_module, snmpa_trap, soft_purge, soft_purge, []}, {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, + {load_module, snmp_verbosity, soft_purge, soft_purge, []}, + {load_module, snmpm_mpd, soft_purge, soft_purge, []}, {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, []} + {update, snmpa_agent, soft, soft_purge, soft_purge, []}, + {add_module, snmpm_net_if_mt} ] }, {"4.21.1", @@ -59,9 +92,12 @@ {load_module, snmpa_set_lib, soft_purge, soft_purge, []}, {load_module, snmpa_trap, soft_purge, soft_purge, []}, {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, + {load_module, snmp_verbosity, soft_purge, soft_purge, []}, + {load_module, snmpm_mpd, soft_purge, soft_purge, []}, {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, {update, snmpa_agent, soft, soft_purge, soft_purge, []}, - {update, snmp_note_store, soft, soft_purge, soft_purge, []} + {update, snmp_note_store, soft, soft_purge, soft_purge, []}, + {add_module, snmpm_net_if_mt} ] }, {"4.21", @@ -73,63 +109,12 @@ {load_module, snmpa_trap, soft_purge, soft_purge, []}, {load_module, snmp_target_mib, soft_purge, soft_purge, []}, {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, + {load_module, snmp_verbosity, soft_purge, soft_purge, []}, + {load_module, snmpm_mpd, soft_purge, soft_purge, []}, {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, {update, snmpa_agent, soft, soft_purge, soft_purge, []}, - {update, snmp_note_store, soft, soft_purge, soft_purge, []} - ] - }, - {"4.20.1", - [ - {load_module, snmpa_vacm, soft_purge, soft_purge, []}, - {load_module, snmpa_set_lib, soft_purge, soft_purge, []}, - {load_module, snmpa_trap, soft_purge, soft_purge, []}, - {load_module, snmp_target_mib, soft_purge, soft_purge, []}, - {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, - {load_module, snmpm, soft_purge, soft_purge, - [snmpm_server, snmpm_config, snmp_config]}, - {load_module, snmp_conf, soft_purge, soft_purge, []}, - {load_module, snmp_config, soft_purge, soft_purge, []}, - {load_module, snmpm_mpd, soft_purge, soft_purge, - [snmp_conf, snmp_config, snmpm_config]}, - {load_module, snmpa_mpd, soft_purge, soft_purge, - [snmp_conf, snmp_config]}, - {load_module, snmpa_conf, soft_purge, soft_purge, [snmp_config]}, - {update, snmp_note_store, soft, soft_purge, soft_purge, []}, - {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_mpd]}, - {update, snmpm_config, soft, soft_purge, soft_purge, [snmp_conf]}, - {update, snmpm_server, soft, soft_purge, soft_purge, - [snmpm_net_if, snmpm_mpd, snmpm_config]}, - {update, snmpm_net_if, soft, soft_purge, soft_purge, - [snmp_conf, snmpm_mpd, snmpm_config]} - ] - }, - {"4.20", - [ - {load_module, snmpa_vacm, soft_purge, soft_purge, []}, - {load_module, snmpa_set_lib, soft_purge, soft_purge, []}, - {load_module, snmpa_trap, soft_purge, soft_purge, []}, - {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, - {load_module, snmp_target_mib, soft_purge, soft_purge, [snmp_conf]}, - {load_module, snmpm, soft_purge, soft_purge, - [snmpm_server, snmpm_config, snmp_config]}, - {load_module, snmp_conf, soft_purge, soft_purge, []}, - {load_module, snmp_config, soft_purge, soft_purge, []}, - {load_module, snmpm_mpd, soft_purge, soft_purge, - [snmp_conf, snmp_config, snmpm_config]}, - {load_module, snmpa_mpd, soft_purge, soft_purge, - [snmp_conf, snmp_config]}, - {load_module, snmpa_conf, soft_purge, soft_purge, [snmp_config]}, {update, snmp_note_store, soft, soft_purge, soft_purge, []}, - {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_mpd]}, - {update, snmpm_config, soft, soft_purge, soft_purge, [snmp_conf]}, - {update, snmpm_server, soft, soft_purge, soft_purge, - [snmpm_net_if, snmpm_mpd, snmpm_config]}, - {update, snmpm_net_if, soft, soft_purge, soft_purge, - [snmp_conf, snmpm_mpd, snmpm_config]} + {add_module, snmpm_net_if_mt} ] } ], @@ -137,12 +122,37 @@ %% ------D o w n g r a d e --------------------------------------------------- [ + %% This is a place holder + {"4.21.7", + [ + {load_module, snmp_verbosity, soft_purge, soft_purge, []}, + {load_module, snmpm_mpd, soft_purge, soft_purge, []}, + {add_module, snmpm_net_if_mt} + ] + }, + %% This is a place holder + {"4.21.6", + [ + {load_module, snmp_verbosity, soft_purge, soft_purge, []}, + {load_module, snmpm_mpd, soft_purge, soft_purge, []}, + {add_module, snmpm_net_if_mt} + ] + }, + %% This is a place holder + {"4.21.5", + [ + {load_module, snmp_verbosity, soft_purge, soft_purge, []}, + {load_module, snmpm_mpd, soft_purge, soft_purge, []}, + {add_module, snmpm_net_if_mt} + ] + }, {"4.21.4", [ {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, {load_module, snmpa_vacm, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, []} + {update, snmpa_agent, soft, soft_purge, soft_purge, []}, + {add_module, snmpm_net_if_mt} ] }, {"4.21.3", @@ -150,8 +160,11 @@ {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, {load_module, snmpa_vacm, soft_purge, soft_purge, []}, + {load_module, snmp_verbosity, soft_purge, soft_purge, []}, + {load_module, snmpm_mpd, soft_purge, soft_purge, []}, {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, []} + {update, snmpa_agent, soft, soft_purge, soft_purge, []}, + {add_module, snmpm_net_if_mt} ] }, {"4.21.2", @@ -162,8 +175,11 @@ {load_module, snmpa_set_lib, soft_purge, soft_purge, []}, {load_module, snmpa_trap, soft_purge, soft_purge, []}, {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, + {load_module, snmp_verbosity, soft_purge, soft_purge, []}, + {load_module, snmpm_mpd, soft_purge, soft_purge, []}, {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, []} + {update, snmpa_agent, soft, soft_purge, soft_purge, []}, + {add_module, snmpm_net_if_mt} ] }, {"4.21.1", @@ -174,9 +190,12 @@ {load_module, snmpa_set_lib, soft_purge, soft_purge, []}, {load_module, snmpa_trap, soft_purge, soft_purge, []}, {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, + {load_module, snmp_verbosity, soft_purge, soft_purge, []}, + {load_module, snmpm_mpd, soft_purge, soft_purge, []}, {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, {update, snmpa_agent, soft, soft_purge, soft_purge, []}, - {update, snmp_note_store, soft, soft_purge, soft_purge, []} + {update, snmp_note_store, soft, soft_purge, soft_purge, []}, + {add_module, snmpm_net_if_mt} ] }, {"4.21", @@ -188,63 +207,12 @@ {load_module, snmpa_trap, soft_purge, soft_purge, []}, {load_module, snmp_target_mib, soft_purge, soft_purge, []}, {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, + {load_module, snmp_verbosity, soft_purge, soft_purge, []}, + {load_module, snmpm_mpd, soft_purge, soft_purge, []}, {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, {update, snmpa_agent, soft, soft_purge, soft_purge, []}, - {update, snmp_note_store, soft, soft_purge, soft_purge, []} - ] - }, - {"4.20.1", - [ - {load_module, snmpa_vacm, soft_purge, soft_purge, []}, - {load_module, snmpa_set_lib, soft_purge, soft_purge, []}, - {load_module, snmpa_trap, soft_purge, soft_purge, []}, - {load_module, snmp_target_mib, soft_purge, soft_purge, []}, - {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, - {load_module, snmpm, soft_purge, soft_purge, - [snmpm_server, snmpm_config, snmp_config]}, - {load_module, snmp_conf, soft_purge, soft_purge, []}, - {load_module, snmp_config, soft_purge, soft_purge, []}, - {load_module, snmpm_mpd, soft_purge, soft_purge, - [snmp_conf, snmp_config, snmpm_config]}, - {load_module, snmpa_mpd, soft_purge, soft_purge, - [snmp_conf, snmp_config]}, - {load_module, snmpa_conf, soft_purge, soft_purge, [snmp_config]}, - {update, snmp_note_store, soft, soft_purge, soft_purge, []}, - {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_mpd]}, - {update, snmpm_config, soft, soft_purge, soft_purge, [snmp_conf]}, - {update, snmpm_server, soft, soft_purge, soft_purge, - [snmpm_net_if, snmpm_mpd, snmpm_config]}, - {update, snmpm_net_if, soft, soft_purge, soft_purge, - [snmp_conf, snmpm_mpd, snmpm_config]} - ] - }, - {"4.20", - [ - {load_module, snmpa_vacm, soft_purge, soft_purge, []}, - {load_module, snmpa_set_lib, soft_purge, soft_purge, []}, - {load_module, snmpa_trap, soft_purge, soft_purge, []}, - {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, - {load_module, snmp_target_mib, soft_purge, soft_purge, [snmp_conf]}, - {load_module, snmpm, soft_purge, soft_purge, - [snmpm_server, snmpm_config, snmp_config]}, - {load_module, snmp_conf, soft_purge, soft_purge, []}, - {load_module, snmp_config, soft_purge, soft_purge, []}, - {load_module, snmpm_mpd, soft_purge, soft_purge, - [snmp_conf, snmp_config, snmpm_config]}, - {load_module, snmpa_mpd, soft_purge, soft_purge, - [snmp_conf, snmp_config]}, - {load_module, snmpa_conf, soft_purge, soft_purge, [snmp_config]}, {update, snmp_note_store, soft, soft_purge, soft_purge, []}, - {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_mpd]}, - {update, snmpm_config, soft, soft_purge, soft_purge, [snmp_conf]}, - {update, snmpm_server, soft, soft_purge, soft_purge, - [snmpm_net_if, snmpm_mpd, snmpm_config]}, - {update, snmpm_net_if, soft, soft_purge, soft_purge, - [snmp_conf, snmpm_mpd, snmpm_config]} + {add_module, snmpm_net_if_mt} ] } ] -- cgit v1.2.3 From a625c82cc2adb53e9aa70291445ed5a2a95a4f84 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 1 Feb 2012 18:27:17 +0100 Subject: [snmp/manager] Reworked the ATL mechanism for the net-if-mt Removed the separate logger process. Instead open the log from each worker process and log from them directly. OTP-9876 --- lib/snmp/src/manager/snmpm_net_if_mt.erl | 125 +++++++++++++------------------ lib/snmp/src/misc/snmp_log.erl | 38 +++++++--- lib/snmp/test/snmp_log_test.erl | 27 ++++--- 3 files changed, 100 insertions(+), 90 deletions(-) (limited to 'lib') diff --git a/lib/snmp/src/manager/snmpm_net_if_mt.erl b/lib/snmp/src/manager/snmpm_net_if_mt.erl index 753626be72..3e87f6a7fb 100644 --- a/lib/snmp/src/manager/snmpm_net_if_mt.erl +++ b/lib/snmp/src/manager/snmpm_net_if_mt.erl @@ -46,8 +46,6 @@ -export([init/1, handle_call/3, handle_cast/2, handle_info/2, code_change/3, terminate/2]). --export([logger_init/2]). - -define(SNMP_USE_V3, true). -include("snmp_types.hrl"). -include("snmpm_internal.hrl"). @@ -69,13 +67,6 @@ filter }). -%% State record of the logger process --record(logger, - { - parent, - log - }). - -define(DEFAULT_FILTER_MODULE, snmpm_net_if_filter). -define(DEFAULT_FILTER_OPTS, [{module, ?DEFAULT_FILTER_MODULE}]). @@ -189,13 +180,14 @@ do_init(Server, NoteStore) -> %% -- Verbosity -- {ok, Verbosity} = snmpm_config:system_info(net_if_verbosity), - put(sname,mnif), - put(verbosity,Verbosity), + put(sname, mnif), + put(verbosity, Verbosity), ?vlog("starting", []), %% -- MPD -- {ok, Vsns} = snmpm_config:system_info(versions), MpdState = snmpm_mpd:init(Vsns), + ?vdebug("MpdState: ~w", [MpdState]), %% -- Module dependent options -- {ok, Opts} = snmpm_config:system_info(net_if_options), @@ -220,6 +212,7 @@ do_init(Server, NoteStore) -> %% -- Audit trail log --- {ok, ATL} = snmpm_config:system_info(audit_trail_log), Log = do_init_log(ATL), + ?vdebug("Log: ~w", [Log]), %% -- Initiate counters --- init_counters(), @@ -315,44 +308,12 @@ do_init_log(false) -> undefined; do_init_log(true) -> ?vtrace("do_init_log(true) -> entry", []), - logger_start(). - -logger_start() -> - {Pid, _} = Logger = - erlang:spawn_opt(?MODULE, logger_init, [self(), get(verbosity)], - [monitor]), - receive - {logger_started, Pid} -> - {ok, Type} = snmpm_config:system_info(audit_trail_log_type), - {Logger, Type}; - {'DOWN', _MonitorRef, process, Pid, Reason} -> - throw({error, {failed_starting_logger, Logger, Reason}}) - after 5000 -> - %% This should really not take any time at all, - %% so 5 secs is plenty of time. - throw({error, {failed_starting_logger, Logger, timeout}}) - end. - -logger_init(Parent, Verbosity) -> - put(sname, mnifl), - put(verbosity, Verbosity), - case (catch do_logger_init()) of - {ok, Log} -> - Parent ! {logger_started, self()}, - logger_loop(#logger{parent = Parent, - log = Log}); - {error, Reason} -> - exit({logger, failed_init, Reason}) - end. - -%% Open log -do_logger_init() -> - ?vtrace("do_logger_init() -> entry", []), + {ok, Type} = snmpm_config:system_info(audit_trail_log_type), {ok, Dir} = snmpm_config:system_info(audit_trail_log_dir), {ok, Size} = snmpm_config:system_info(audit_trail_log_size), {ok, Repair} = snmpm_config:system_info(audit_trail_log_repair), - Name = ?audit_trail_log_name, - File = filename:absname(?audit_trail_log_file, Dir), + Name = ?audit_trail_log_name, + File = filename:absname(?audit_trail_log_file, Dir), case snmpm_config:system_info(audit_trail_log_seqno) of {ok, true} -> Initial = ?ATL_SEQNO_INITIAL, @@ -364,33 +325,22 @@ do_logger_init() -> case snmp_log:create(Name, File, SeqNoGen, Size, Repair, true) of {ok, Log} -> ?vdebug("log created: ~w", [Log]), - {ok, Log}; + {Name, Log, Type}; {error, Reason} -> - {error, {failed_create_audit_log, Reason}} + throw({error, {failed_create_audit_log, Reason}}) end; _ -> case snmp_log:create(Name, File, Size, Repair, true) of {ok, Log} -> ?vdebug("log created: ~w", [Log]), - {ok, Log}; + {Name, Log, Type}; {error, Reason} -> - {error, {failed_create_audit_log, Reason}} + throw({error, {failed_create_audit_log, Reason}}) end end. -logger_loop(Logger) -> - receive - {log, Msg, Addr, Port} -> - snmp_log:log(Logger#logger.log, Msg, Addr, Port); - {stop, Pid} when Pid =:= Logger#logger.parent -> - exit(normal) - end, - logger_loop(Logger). - - %% ---------------------------------------------------------------------- - %%-------------------------------------------------------------------- %% Func: handle_call/3 @@ -551,9 +501,12 @@ code_change(_Vsn, State, _Extra) -> %%%------------------------------------------------------------------- handle_udp(Addr, Port, Bytes, State) -> + Verbosity = get(verbosity), spawn_opt(fun() -> - Res = (catch maybe_handle_recv_msg(Addr, Port, - Bytes, State)), + Log = worker_init(State, Verbosity), + Res = (catch maybe_handle_recv_msg( + Addr, Port, Bytes, + State#state{log = Log})), worker_exit(udp, {Addr, Port}, Res) end, [monitor]). @@ -713,10 +666,13 @@ handle_inform_request({user, To}, Pid, Vsn, #pdu{request_id = ReqId} = Pdu, ok. handle_inform_response(Ref, Addr, Port, State) -> + Verbosity = get(verbosity), spawn_opt(fun() -> - Res = (catch do_handle_inform_response(Ref, - Addr, Port, - State)), + Log = worker_init(State, Verbosity), + Res = (catch do_handle_inform_response( + Ref, + Addr, Port, + State#state{log = Log})), worker_exit(inform_reponse, {Addr, Port}, Res) end, [monitor]). @@ -790,10 +746,13 @@ irgc_stop(Ref) -> handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, Port, State) -> + Verbosity = get(verbosity), spawn_opt(fun() -> - Res = (catch maybe_handle_send_pdu(Pdu, Vsn, MsgData, - Domain, Addr, Port, - State)), + Log = worker_init(State, Verbosity), + Res = (catch maybe_handle_send_pdu( + Pdu, Vsn, MsgData, + Domain, Addr, Port, + State#state{log = Log})), worker_exit(send_pdu, {Domain, Addr, Port}, Res) end, [monitor]). @@ -1048,6 +1007,30 @@ handle_set_log_type(State, _NewType) -> %% ------------------------------------------------------------------- +worker_init(#state{log = undefined = Log}, Verbosity) -> + worker_init2(Log, Verbosity); +worker_init(#state{log = {Name, Log, Type}}, Verbosity) -> + case snmp_log:open(Name, Log) of + {ok, NewLog} -> + worker_init2({Name, NewLog, Type}, Verbosity); + {error, Reason} -> + warning_msg("NetIf worker ~p failed opening ATL: " + "~n ~p", [self(), Reason]), + NewLog = undefined, + worker_init2({Name, NewLog, Type}, Verbosity) + end; +worker_init(State, Verbosity) -> + ?vinfo("worker_init -> entry with invalid data: " + "~n State: ~p" + "~n Verbosity: ~p", [State, Verbosity]), + exit({worker_init, State, Verbosity}). + +worker_init2(Log, Verbosity) -> + put(sname, mnifw), + put(verbosity, Verbosity), + Log. + + worker_exit(Tag, Info, Result) -> exit({net_if_worker, {Tag, Info, Result}}). @@ -1116,11 +1099,11 @@ logger(undefined, _Type, _Addr, _Port) -> fun(_) -> ok end; -logger({{Pid, _}, Types}, Type, Addr, Port) -> +logger({_Name, Log, Types}, Type, Addr, Port) -> case lists:member(Type, Types) of true -> fun(Msg) -> - Pid ! {log, Msg, Addr, Port} + snmp_log:log(Log, Msg, Addr, Port) end; false -> fun(_) -> diff --git a/lib/snmp/src/misc/snmp_log.erl b/lib/snmp/src/misc/snmp_log.erl index 2c781810ef..7f7030c9bf 100644 --- a/lib/snmp/src/misc/snmp_log.erl +++ b/lib/snmp/src/misc/snmp_log.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2011. All Rights Reserved. +%% Copyright Ericsson AB 1997-2012. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -21,7 +21,7 @@ -export([ - create/4, create/5, create/6, + create/4, create/5, create/6, open/1, open/2, change_size/2, close/1, sync/1, info/1, log/4, log_to_txt/5, log_to_txt/6, log_to_txt/7, @@ -109,6 +109,24 @@ create(Name, File, SeqNoGen, Size, Repair, Notify) -> {error, {bad_args, Name, File, SeqNoGen, Size, Repair, Notify}}. +%% -- open --- + +%% Open an already existing ( = open ) log + +open(Name) -> + open(Name, #snmp_log{seqno = disabled}). +open(Name, #snmp_log{seqno = SeqNoGen} = _OldLog) -> + %% We include mode in the opts just to be on the safe side + case disk_log:open([{name, Name}, {mode, read_write}]) of + {ok, Log} -> + %% SeqNo must be proprly initiated also + {ok, #snmp_log{id = Log, seqno = SeqNoGen}}; + {repaired, Log, _RecBytes, _BadBytes} -> + {ok, #snmp_log{id = Log, seqno = SeqNoGen}}; + ERROR -> + ERROR + end. + %% -- close --- @@ -705,21 +723,21 @@ tsf_ge(_Local,Universal,{universal_time,DateTime}) -> tsf_ge(Local,_Universal,DateTime) -> tsf_ge(Local,DateTime). -tsf_ge(TimeStamp,DateTime) -> +tsf_ge(TimeStamp, DateTime) -> T1 = calendar:datetime_to_gregorian_seconds(TimeStamp), T2 = calendar:datetime_to_gregorian_seconds(DateTime), T1 >= T2. -tsf_le(_Local,_Universal,null) -> +tsf_le(_Local, _Universal, null) -> true; -tsf_le(Local,_Universal,{local_time,DateTime}) -> - tsf_le(Local,DateTime); -tsf_le(_Local,Universal,{universal_time,DateTime}) -> - tsf_le(Universal,DateTime); -tsf_le(Local,_Universal,DateTime) -> +tsf_le(Local, _Universal, {local_time, DateTime}) -> + tsf_le(Local, DateTime); +tsf_le(_Local, Universal, {universal_time, DateTime}) -> + tsf_le(Universal, DateTime); +tsf_le(Local, _Universal, DateTime) -> tsf_le(Local,DateTime). -tsf_le(TimeStamp,DateTime) -> +tsf_le(TimeStamp, DateTime) -> T1 = calendar:datetime_to_gregorian_seconds(TimeStamp), T2 = calendar:datetime_to_gregorian_seconds(DateTime), T1 =< T2. diff --git a/lib/snmp/test/snmp_log_test.erl b/lib/snmp/test/snmp_log_test.erl index b692017407..8478825f59 100644 --- a/lib/snmp/test/snmp_log_test.erl +++ b/lib/snmp/test/snmp_log_test.erl @@ -42,7 +42,11 @@ -export([ init_per_testcase/2, end_per_testcase/2, - all/0,groups/0,init_per_group/2,end_per_group/2, + all/0, + groups/0, + init_per_group/2, + end_per_group/2, + open_and_close/1, open_write_and_close1/1, @@ -109,16 +113,21 @@ end_per_testcase(_Case, Config) when is_list(Config) -> %%====================================================================== %% ?SKIP(not_yet_implemented). all() -> -[open_and_close, {group, open_write_and_close}, - {group, log_to_io}, {group, log_to_txt}]. + [ + open_and_close, + {group, open_write_and_close}, + {group, log_to_io}, + {group, log_to_txt}]. groups() -> - [{open_write_and_close, [], - [open_write_and_close1, open_write_and_close2, - open_write_and_close3, open_write_and_close4]}, - {log_to_io, [], [log_to_io1, log_to_io2]}, - {log_to_txt, [], - [log_to_txt1, log_to_txt2, log_to_txt3]}]. + [ + {open_write_and_close, [], + [open_write_and_close1, open_write_and_close2, + open_write_and_close3, open_write_and_close4]}, + {log_to_io, [], [log_to_io1, log_to_io2]}, + {log_to_txt, [], + [log_to_txt1, log_to_txt2, log_to_txt3]} + ]. init_per_group(_GroupName, Config) -> Config. -- cgit v1.2.3 From 96b87c341798930cc9e582ccfc1c67e6e0e0fdd9 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 20 Feb 2012 17:40:04 +0100 Subject: [snmp] Moved experimental test suites to an experimental sub-dir OTP-9876 --- lib/snmp/test/exp/.gitignore | 0 lib/snmp/test/exp/snmp_agent_bl_test.erl | 5654 ++++++++++++++++++++++++++++++ lib/snmp/test/exp/snmp_agent_ms_test.erl | 5649 +++++++++++++++++++++++++++++ lib/snmp/test/exp/snmp_agent_mt_test.erl | 5649 +++++++++++++++++++++++++++++ lib/snmp/test/exp/snmp_agent_v1_test.erl | 2673 ++++++++++++++ lib/snmp/test/exp/snmp_agent_v2_test.erl | 5649 +++++++++++++++++++++++++++++ lib/snmp/test/exp/snmp_agent_v3_test.erl | 5649 +++++++++++++++++++++++++++++ lib/snmp/test/snmp_agent_bl_test.erl | 5654 ------------------------------ lib/snmp/test/snmp_agent_ms_test.erl | 5649 ----------------------------- lib/snmp/test/snmp_agent_mt_test.erl | 5649 ----------------------------- lib/snmp/test/snmp_agent_v1_test.erl | 2673 -------------- lib/snmp/test/snmp_agent_v2_test.erl | 5649 ----------------------------- lib/snmp/test/snmp_agent_v3_test.erl | 5649 ----------------------------- 13 files changed, 30923 insertions(+), 30923 deletions(-) create mode 100644 lib/snmp/test/exp/.gitignore create mode 100644 lib/snmp/test/exp/snmp_agent_bl_test.erl create mode 100644 lib/snmp/test/exp/snmp_agent_ms_test.erl create mode 100644 lib/snmp/test/exp/snmp_agent_mt_test.erl create mode 100644 lib/snmp/test/exp/snmp_agent_v1_test.erl create mode 100644 lib/snmp/test/exp/snmp_agent_v2_test.erl create mode 100644 lib/snmp/test/exp/snmp_agent_v3_test.erl delete mode 100644 lib/snmp/test/snmp_agent_bl_test.erl delete mode 100644 lib/snmp/test/snmp_agent_ms_test.erl delete mode 100644 lib/snmp/test/snmp_agent_mt_test.erl delete mode 100644 lib/snmp/test/snmp_agent_v1_test.erl delete mode 100644 lib/snmp/test/snmp_agent_v2_test.erl delete mode 100644 lib/snmp/test/snmp_agent_v3_test.erl (limited to 'lib') diff --git a/lib/snmp/test/exp/.gitignore b/lib/snmp/test/exp/.gitignore new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lib/snmp/test/exp/snmp_agent_bl_test.erl b/lib/snmp/test/exp/snmp_agent_bl_test.erl new file mode 100644 index 0000000000..b17489a755 --- /dev/null +++ b/lib/snmp/test/exp/snmp_agent_bl_test.erl @@ -0,0 +1,5654 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2005-2010. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% + +-module(snmp_agent_bl_test). + +%% TODO +%% * Test fault-tolerance (kill master etc) +%% + +% -include_lib("kernel/include/file.hrl"). +% -include("test_server.hrl"). +% -include("snmp_test_lib.hrl"). +% -define(SNMP_USE_V3, true). +% -include_lib("snmp/include/snmp_types.hrl"). + +%% -include_lib("snmp/include/SNMP-COMMUNITY-MIB.hrl"). +%% -include_lib("snmp/include/SNMP-VIEW-BASED-ACM-MIB.hrl"). +%% -include_lib("snmp/include/SNMP-USER-BASED-SM-MIB.hrl"). + + +% -define(klas1, [1,3,6,1,2,1,7]). +% -define(klas2, [1,3,6,1,2,1,9]). +% -define(klas3, [1,3,6,1,2,1,8,1]). +% -define(klas4, [1,3,6,1,2,1,8,4]). +% -define(sa, [1,3,6,1,4,1,193,2]). +% -define(system, [1,3,6,1,2,1,1]). +% -define(snmp, [1,3,6,1,2,1,11]). +% -define(snmpTraps, [1,3,6,1,6,3,1,1,5]). +% -define(ericsson, [1,3,6,1,4,1,193]). +% -define(testTrap, [1,3,6,1,2,1,15,0]). +% -define(xDescr, [1,3,6,1,2,1,17,1]). +% -define(xDescr2, [1,3,6,1,2,1,17,2]). + +% -define(active, 1). +% -define(notInService, 2). +% -define(notReady, 3). +% -define(createAndGo, 4). +% -define(createAndWait, 5). +% -define(destroy, 6). + +% -define(TRAP_UDP, 5000). + +% -define(tooBigStr, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"). + +-define(str(X), snmp_pdus:bits_to_str(X)). + +-define(break(), begin io:format(user, "break at line ~w: pid: ~p\n", + [?LINE, self()]), + receive cont -> ok end + end). + + +-import(snmp_test_mgr, [gn/1, g/1, s/1, gb/3]). +-define(v1_2(V1,V2), + case get(vsn) of + v1 -> V1; + _ -> V2 + end). + +-define(v1_2_3(V1,V2,V3), + case get(vsn) of + v1 -> V1; + v2 -> V2; + _ -> V3 + end). + +all(suite) -> {req, + [mnesia, distribution, + {local_slave_nodes, 2}, {time, 360}], + [{conf, init_all, cases(), finish_all}]}. + +init_per_testcase(_Case, Config) when list(Config) -> + Dog = ?t:timetrap(?t:minutes(6)), + [{watchdog, Dog}|Config]. + +end_per_testcase(_Case, Config) when list(Config) -> + Dog = ?config(watchdog, Config), + ?t:timetrap_cancel(Dog), + Config. + +cases() -> + case ?OSTYPE() of + vxworks -> + %% No crypto app, so skip v3 testcases + [ + app_info, + test_v1, test_v2, test_v1_v2, + test_multi_threaded, + mib_storage, + tickets]; + _Else -> + [ + app_info, + test_v1, test_v2, test_v1_v2, test_v3, + test_multi_threaded, + mib_storage, + tickets + ] + end. + + +%%%----------------------------------------------------------------- +%%% The test case structure is as follows: +%%% +%%% init_all - starts mnesia, +%%% +%%% init_v1 - starts agent +%%% simple +%%% big - e.g. starts/stops subagent, load/unloads mibs +%%% init_mul +%%% mul_get +%%% mul_set +%%% +%%% finish_mul +%%% +%%% finish_v1 +%%% +%%% init_v2 - starts agent +%%% finish_v2 +%%% +%%% init_bilingual - starts agent +%%% finish_bilingual +%%% +%%% finish_all +%%% +%%% There is still one problem with these testsuites. If one test +%%% fails, it may not be possible to run some other cases, as it +%%% may have e.g. created some row or loaded some table, that it +%%% didn't undo (since it failed). +%%%----------------------------------------------------------------- + +init_all(Config0) when list(Config0) -> + ?LOG("init_all -> entry with" + "~n Config0: ~p",[Config0]), + + %% -- + %% Fix config: + %% + + DataDir0 = ?config(data_dir, Config0), + DataDir1 = filename:split(filename:absname(DataDir0)), + [_|DataDir2] = lists:reverse(DataDir1), + DataDir3 = filename:join(lists:reverse(DataDir2) ++ [?snmp_test_data]), + Config1 = lists:keydelete(data_dir, 1, Config0), + Config = [{data_dir, DataDir3 ++ "/"}|Config1], + + %% -- + %% Start nodes + %% + + ?line {ok, SaNode} = start_node(snmp_sa), + ?line {ok, MgrNode} = start_node(snmp_mgr), + + + %% -- + %% Create necessary files + %% + + Dir = ?config(priv_dir, Config), + ?DBG("init_all -> Dir ~p", [Dir]), + + DataDir = ?config(data_dir, Config), + ?DBG("init_all -> DataDir ~p", [DataDir]), + + file:make_dir(MgrDir = filename:join(Dir, "mgr_dir/")), + ?DBG("init_all -> MgrDir ~p", [MgrDir]), + + file:make_dir(AgentDir = filename:join(Dir, "agent_dir/")), + ?DBG("init_all -> AgentDir ~p", [AgentDir]), + + file:make_dir(SaDir = filename:join(Dir, "sa_dir/")), + ?DBG("init_all -> SaDir ~p", [SaDir]), + + + %% -- + %% Start and initiate mnesia + %% + + ?DBG("init_all -> load application mnesia", []), + ?line ok = application:load(mnesia), + + ?DBG("init_all -> load application mnesia on node ~p", [SaNode]), + ?line ok = rpc:call(SaNode, application, load, [mnesia]), + + ?DBG("init_all -> application mnesia: set_env dir",[]), + ?line application_controller:set_env(mnesia, dir, + filename:join(Dir, "Mnesia1")), + + ?DBG("init_all -> application mnesia: set_env dir on node ~p",[SaNode]), + ?line rpc:call(SaNode, application_controller, set_env, + [mnesia, dir, filename:join(Dir, "Mnesia2")]), + + ?DBG("init_all -> create mnesia schema",[]), + ?line ok = mnesia:create_schema([SaNode, node()]), + + ?DBG("init_all -> start application mnesia",[]), + ?line ok = application:start(mnesia), + + ?DBG("init_all -> start application mnesia on ~p",[SaNode]), + ?line ok = rpc:call(SaNode, application, start, [mnesia]), + Ip = ?LOCALHOST(), + [{snmp_sa, SaNode}, + {snmp_mgr, MgrNode}, + {agent_dir, AgentDir ++ "/"}, + {mgr_dir, MgrDir ++ "/"}, + {sa_dir, SaDir ++ "/"}, + {mib_dir, DataDir}, + {ip, Ip} | + Config]. + +finish_all(Config) when list(Config) -> + SaNode = ?config(snmp_sa, Config), + MgrNode = ?config(snmp_mgr, Config), + stop_node(SaNode), + stop_node(MgrNode), + application:stop(mnesia). + +start_v1_agent(Config) when list(Config) -> + start_agent(Config, [v1]). + +start_v1_agent(Config,Opts) when list(Config), list(Opts) -> + start_agent(Config, [v1], Opts). + +start_v2_agent(Config) when list(Config) -> + start_agent(Config, [v2]). + +start_v3_agent(Config) when list(Config) -> + start_agent(Config, [v3]). + +start_bilingual_agent(Config) when list(Config) -> + start_agent(Config, [v1,v2]). + +start_multi_threaded_agent(Config) when list(Config) -> + start_agent(Config, [v2], [{snmp_multi_threaded, true}]). + +stop_agent(Config) when list(Config) -> + ?LOG("stop_agent -> entry with" + "~n Config: ~p",[Config]), + + {Sup, Par} = ?config(snmp_sup, Config), + ?DBG("stop_agent -> attempt to stop (sup) ~p" + "~n Sup: ~p" + "~n Par: ~p", + [Sup, + (catch process_info(Sup)), + (catch process_info(Par))]), + stop_sup(Sup, Par), + + {Sup2, Par2} = ?config(snmp_sub, Config), + ?DBG("stop_agent -> attempt to stop (sub) ~p" + "~n Sup2: ~p" + "~n Par2: ~p", + [Sup2, + (catch process_info(Sup2)), + (catch process_info(Par2))]), + stop_sup(Sup2, Par2), + + ?DBG("stop_agent -> done - now cleanup config", []), + C1 = lists:keydelete(snmp_sup, 1, Config), + lists:keydelete(snmp_sub, 1, C1). + + +stop_sup(Pid, _) when node(Pid) == node() -> + case (catch process_info(Pid)) of + PI when list(PI) -> + ?LOG("stop_sup -> attempt to stop ~p", [Pid]), + Ref = erlang:monitor(process, Pid), + exit(Pid, kill), + await_stopped(Pid, Ref); + {'EXIT', _Reason} -> + ?LOG("stop_sup -> ~p not running", [Pid]), + ok + end; +stop_sup(Pid, _) -> + ?LOG("stop_sup -> attempt to stop ~p", [Pid]), + Ref = erlang:monitor(process, Pid), + ?LOG("stop_sup -> Ref: ~p", [Ref]), + %% Pid ! {'EXIT', Parent, shutdown}, % usch + exit(Pid, kill), + await_stopped(Pid, Ref). + +await_stopped(Pid, Ref) -> + receive + {'DOWN', Ref, process, Pid, _Reason} -> + ?DBG("received down message for ~p", [Pid]), + ok + after 10000 -> + ?INF("await_stopped -> timeout for ~p",[Pid]), + erlang:demonitor(Ref), + ?FAIL({failed_stop,Pid}) + end. + + +start_agent(Config, Vsn) -> + start_agent(Config, Vsn, []). +start_agent(Config, Vsn, Opts) -> + ?LOG("start_agent -> entry (~p) with" + "~n Config: ~p" + "~n Vsn: ~p" + "~n Opts: ~p",[node(), Config, Vsn, Opts]), + + ?line AgentDir = ?config(agent_dir, Config), + ?line SaNode = ?config(snmp_sa, Config), + + snmp_app_env_init(vsn_init(Vsn) ++ + [{audit_trail_log, read_write_log}, + {audit_trail_log_dir, AgentDir}, + {audit_trail_log_size, {10240, 10}}, + {force_config_reload, false}, + {snmp_agent_type, master}, + {snmp_config_dir, AgentDir}, + {snmp_db_dir, AgentDir}, + {snmp_local_db_auto_repair, true}, + {snmp_master_agent_verbosity, trace}, + {snmp_supervisor_verbosity, trace}, + {snmp_mibserver_verbosity, trace}, + {snmp_symbolic_store_verbosity, trace}, + {snmp_note_store_verbosity, trace}, + {snmp_net_if_verbosity, trace}], + Opts), + + + process_flag(trap_exit,true), + + {ok, AppSup} = snmp_app_sup:start_link(), + unlink(AppSup), + ?DBG("start_agent -> snmp app supervisor: ~p",[AppSup]), + + ?DBG("start_agent -> start master agent (old style)",[]), + Sup = case (catch snmpa_app:start(normal)) of + {ok, S} -> + ?DBG("start_agent -> started, Sup: ~p",[S]), + S; + + Else -> + ?DBG("start_agent -> unknown result: ~n~p",[Else]), + %% Get info about the apps we depend on + MnesiaInfo = mnesia_running(), + ?FAIL({start_failed,Else,MnesiaInfo}) + end, + + ?DBG("start_agent -> unlink from supervisor",[]), + ?line unlink(Sup), + ?line SaDir = ?config(sa_dir, Config), + ?DBG("start_agent -> (rpc) start sub on ~p",[SaNode]), + ?line {ok, Sub} = rpc:call(SaNode, ?MODULE, start_sub, [SaDir]), + ?DBG("start_agent -> done",[]), + ?line [{snmp_sup, {Sup, self()}}, {snmp_sub, Sub} | Config]. + + +vsn_init(Vsn) -> + vsn_init([v1,v2,v3], Vsn, []). + +vsn_init([], _Vsn, Acc) -> + Acc; +vsn_init([V|Vsns], Vsn, Acc) -> + case lists:member(V, Vsn) of + true -> + vsn_init(Vsns, Vsn, [{V, true}|Acc]); + false -> + vsn_init(Vsns, Vsn, [{V, false}|Acc]) + end. + +snmp_app_env_init(Env0, Opts) -> + ?DBG("snmp_app_env_init -> unload snmp",[]), + ?line application:unload(snmp), + ?DBG("snmp_app_env_init -> load snmp",[]), + ?line application:load(snmp), + ?DBG("snmp_app_env_init -> initiate (snmp) application env",[]), + F1 = fun({Key,Val} = New, Acc0) -> + ?DBG("snmp_app_env_init -> " + "updating setting ~p to ~p", [Key, Val]), + case lists:keyreplace(Key, 1, Acc0, New) of + Acc0 -> + [New|Acc0]; + Acc -> + Acc + end + end, + Env = lists:foldr(F1, Env0, Opts), + ?DBG("snmp_app_env_init -> Env: ~p",[Env]), + F2 = fun({Key,Val}) -> + ?DBG("snmp_app_env_init -> setting ~p to ~p",[Key, Val]), + application_controller:set_env(snmp, Key, Val) + end, + lists:foreach(F2, Env). + + + + +%% Test if application is running +mnesia_running() -> ?IS_MNESIA_RUNNING(). +crypto_running() -> ?IS_CRYPTO_RUNNING(). + + +start_sub(Dir) -> + ?DBG("start_sub -> entry",[]), + Opts = [{db_dir, Dir}, + {supervisor, [{verbosity, trace}]}], + %% BMK BMK +% {ok, P} = snmp_supervisor:start_sub(Dir), + {ok, P} = snmpa_supervisor:start_sub_sup(Opts), + unlink(P), + {ok, {P, self()}}. + +create_tables(SaNode) -> + ?line {atomic, ok} = mnesia:create_table([{name, friendsTable2}, + {ram_copies, [SaNode]}, + {snmp, [{key, integer}]}, + {attributes, [a1,a2,a3]}]), + ?line {atomic, ok} = mnesia:create_table([{name, kompissTable2}, + {ram_copies, [SaNode]}, + {snmp, [{key, integer}]}, + {attributes, [a1,a2,a3]}]), + ?line {atomic, ok} = mnesia:create_table([{name, snmp_variables}, + {attributes, [a1,a2]}]). + +delete_tables() -> + mnesia:delete_table(friendsTable2), + mnesia:delete_table(kompissTable2), + mnesia:delete_table(snmp_variables). + +%% Creation is done in runtime! +delete_mib_storage_mnesia_tables() -> + mnesia:delete_table(snmpa_mib_data), + mnesia:delete_table(snmpa_mib_tree), + mnesia:delete_table(snmpa_symbolic_store). + +%%----------------------------------------------------------------- +%% A test case is always one of: +%% - v1 specific case +%% - v2 specific case +%% - v1 and v2 case +%% All v1 specific cases are prefixed with v1_, and all v2 with +%% v2_. E.g. v1_trap/v2_trap. +%% +%% All other cases are shared. However, the testserver uses the name +%% of the case to generate a file for that case. The same case cannot +%% be used in different configurations in the same suite. Therefore +%% all these functions exists in two variants, the base function +%% , and a second version _2. There may be several +%% versions as well, _N. +%%----------------------------------------------------------------- +mib_storage(suite) -> [ + mib_storage_ets, + mib_storage_dets, + mib_storage_mnesia, + mib_storage_size_check_ets, + mib_storage_size_check_dets, + mib_storage_size_check_mnesia, + mib_storage_varm_dets, + mib_storage_varm_mnesia + ]. + +mib_storage_ets(suite) -> {req, [], {conf, init_mib_storage_ets, + mib_storage_ets_cases(), + finish_mib_storage_ets}}. + +mib_storage_dets(suite) -> {req, [], {conf, init_mib_storage_dets, + mib_storage_dets_cases(), + finish_mib_storage_dets}}. + +mib_storage_mnesia(suite) -> {req, [], {conf, init_mib_storage_mnesia, + mib_storage_mnesia_cases(), + finish_mib_storage_mnesia}}. + +mib_storage_size_check_ets(suite) -> + {req, [], {conf, + init_size_check_mse, + mse_size_check_cases(), + finish_size_check_mse}}. + +mib_storage_size_check_dets(suite) -> + {req, [], {conf, + init_size_check_msd, + msd_size_check_cases(), + finish_size_check_msd}}. + +mib_storage_size_check_mnesia(suite) -> + {req, [], {conf, + init_size_check_msm, + msm_size_check_cases(), + finish_size_check_msm}}. + +mib_storage_varm_dets(suite) -> + {req, [], {conf, + init_varm_mib_storage_dets, + varm_mib_storage_dets_cases(), + finish_varm_mib_storage_dets}}. + +mib_storage_varm_mnesia(suite) -> + {req, [], {conf, + init_varm_mib_storage_mnesia, + varm_mib_storage_mnesia_cases(), + finish_varm_mib_storage_mnesia}}. + +mib_storage_ets_cases() -> + [ + mse_simple, + mse_v1_processing, + mse_big, + mse_big2, + mse_loop_mib, + mse_api, + mse_sa_register, + mse_v1_trap, + mse_sa_error, + mse_next_across_sa, + mse_undo, + mse_standard_mib, + mse_community_mib, + mse_framework_mib, + mse_target_mib, + mse_notification_mib, + mse_view_based_acm_mib, + mse_sparse_table, + mse_me_of, + mse_mib_of]. + +mib_storage_dets_cases() -> + [ + msd_simple, + msd_v1_processing, + msd_big, + msd_big2, + msd_loop_mib, + msd_api, + msd_sa_register, + msd_v1_trap, + msd_sa_error, + msd_next_across_sa, + msd_undo, + msd_standard_mib, + msd_community_mib, + msd_framework_mib, + msd_target_mib, + msd_notification_mib, + msd_view_based_acm_mib, + msd_sparse_table, + msd_me_of, + msd_mib_of + ]. + +mib_storage_mnesia_cases() -> + [ + msm_simple, + msm_v1_processing, + msm_big, + msm_big2, + msm_loop_mib, + msm_api, + msm_sa_register, + msm_v1_trap, + msm_sa_error, + msm_next_across_sa, + msm_undo, + msm_standard_mib, + msm_community_mib, + msm_framework_mib, + msm_target_mib, + msm_notification_mib, + msm_view_based_acm_mib, + msm_sparse_table, + msm_me_of, + msm_mib_of + ]. + +mse_size_check_cases() -> + [mse_size_check]. + +msd_size_check_cases() -> + [msd_size_check]. + +msm_size_check_cases() -> + [msm_size_check]. + +varm_mib_storage_dets_cases() -> + [msd_varm_mib_start]. + +varm_mib_storage_mnesia_cases() -> + [msm_varm_mib_start]. + +init_mib_storage_ets(Config) when list(Config) -> + ?LOG("init_mib_storage_ets -> entry", []), + MibStorage = {snmp_mib_storage,ets}, + init_ms(Config, [MibStorage]). + +init_mib_storage_dets(Config) when list(Config) -> + ?LOG("init_mib_storage_ets -> entry", []), + ?line AgentDir = ?GCONF(agent_dir, Config), + MibStorage = {snmp_mib_storage,{dets,AgentDir}}, + init_ms(Config, [MibStorage]). + +init_mib_storage_mnesia(Config) when list(Config) -> + ?LOG("init_mib_storage_ets -> entry", []), + MibStorage = {snmp_mib_storage,{mnesia,[]}}, + init_ms(Config, [MibStorage]). + +init_ms(Config, Opts) when list(Config) -> + ?LOG("init_mib_storage_ets -> entry", []), + ?line SaNode = ?GCONF(snmp_sa, Config), + ?line create_tables(SaNode), + ?line AgentDir = ?GCONF(agent_dir, Config), + ?line MgrDir = ?GCONF(mgr_dir, Config), + ?line Ip = ?GCONF(ip, Config), + ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, + MibsVerbosity = {snmp_mibserver_verbosity, trace}, + SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, + Opts1 = [MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity|Opts], + [{vsn, v1} | start_v1_agent(Config,Opts1)]. + +init_size_check_mse(Config) when list(Config) -> + MibStorage = {snmp_mib_storage, ets}, + init_size_check_ms(Config, [MibStorage]). + +init_size_check_msd(Config) when list(Config) -> + AgentDir = ?GCONF(agent_dir, Config), + MibStorage = {snmp_mib_storage, {dets, AgentDir}}, + init_size_check_ms(Config, [MibStorage]). + +init_size_check_msm(Config) when list(Config) -> + MibStorage = {snmp_mib_storage, {mnesia,[]}}, + init_size_check_ms(Config, [MibStorage]). + +init_size_check_ms(Config, Opts) when list(Config) -> + SaNode = ?GCONF(snmp_sa, Config), + %% We are using v3 here, so crypto must be supported or else... + case ?CRYPTO_START() of + ok -> + case ?CRYPTO_SUPPORT() of + {no, Reason} -> + ?SKIP({unsupported_encryption, Reason}); + yes -> + ok + end; + {error, Reason} -> + ?SKIP({failed_starting_crypto, Reason}) + end, + create_tables(SaNode), + AgentDir = ?GCONF(agent_dir, Config), + MgrDir = ?GCONF(mgr_dir, Config), + Ip = ?GCONF(ip, Config), + ?line ok = + config([v3], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v3} | start_agent(Config, [v3], Opts)]. + +init_varm_mib_storage_dets(Config) when list(Config) -> + ?LOG("init_varm_mib_storage_dets -> entry", []), + ?line SaNode = ?GCONF(snmp_sa, Config), + ?line create_tables(SaNode), + ?line AgentDir = ?GCONF(agent_dir, Config), + ?line MgrDir = ?GCONF(mgr_dir, Config), + ?line Ip = ?GCONF(ip, Config), + ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + MibStorage = {snmp_mib_storage,{dets,AgentDir}}, + MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, + MibsVerbosity = {snmp_mibserver_verbosity, trace}, + SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, + Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity], + [{vsn, v1}, {agent_opts,Opts} | Config]. + +init_varm_mib_storage_mnesia(Config) when list(Config) -> + ?LOG("init_varm_mib_storage_mnesia -> entry", []), + ?line SaNode = ?GCONF(snmp_sa, Config), + ?line create_tables(SaNode), + ?line AgentDir = ?GCONF(agent_dir, Config), + ?line MgrDir = ?GCONF(mgr_dir, Config), + ?line Ip = ?GCONF(ip, Config), + ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + MibStorage = {snmp_mib_storage,{mnesia,[]}}, + MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, + MibsVerbosity = {snmp_mibserver_verbosity, trace}, + SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, + Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity], + [{vsn, v1}, {agent_opts,Opts} | Config]. + +finish_mib_storage_ets(Config) when list(Config) -> + ?LOG("finish_mib_storage_ets -> entry", []), + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + C2 = lists:keydelete(vsn, 1, C1), + lists:keydelete(agent_opts, 1, C2). + +finish_mib_storage_dets(Config) when list(Config) -> + ?LOG("finish_mib_storage_dets -> entry", []), + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + C2 = lists:keydelete(vsn, 1, C1), + lists:keydelete(agent_opts, 1, C2). + +finish_mib_storage_mnesia(Config) when list(Config) -> + ?LOG("finish_mib_storage_mnesia -> entry", []), + delete_tables(), + delete_mib_storage_mnesia_tables(), + C1 = stop_agent(Config), + delete_files(C1), + C2 = lists:keydelete(vsn, 1, C1), + lists:keydelete(agent_opts, 1, C2). + +finish_varm_mib_storage_dets(Config) when list(Config) -> + ?LOG("finish_varm_mib_storage_dets -> entry", []), + delete_tables(), + %% C1 = stop_agent(Config), % In case something went wrong... + delete_files(Config), + C2 = lists:keydelete(vsn, 1, Config), + lists:keydelete(agent_opts, 1, C2). + +finish_varm_mib_storage_mnesia(Config) when list(Config) -> + ?LOG("finish_varm_mib_storage_mnesia -> entry", []), + delete_tables(), + delete_mib_storage_mnesia_tables(), + %% C1 = stop_agent(Config), % In case something went wrong... + delete_files(Config), + C2 = lists:keydelete(vsn, 1, Config), + lists:keydelete(agent_opts, 1, C2). + +finish_size_check_mse(Config) when list(Config) -> + finish_size_check_ms(Config). + +finish_size_check_msd(Config) when list(Config) -> + finish_size_check_ms(Config). + +finish_size_check_msm(Config) when list(Config) -> + finish_size_check_ms(Config). + +finish_size_check_ms(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + + +%% These are just interface functions to fool the test server +mse_simple(X) -> simple(X). +mse_v1_processing(X) -> v1_processing(X). +mse_big(X) -> big(X). +mse_big2(X) -> big2(X). +mse_loop_mib(X) -> loop_mib(X). +mse_api(X) -> api(X). +mse_sa_register(X) -> sa_register(X). +mse_v1_trap(X) -> v1_trap(X). +mse_sa_error(X) -> sa_error(X). +mse_next_across_sa(X) -> next_across_sa(X). +mse_undo(X) -> undo(X). +mse_standard_mib(X) -> snmp_standard_mib(X). +mse_community_mib(X) -> snmp_community_mib(X). +mse_framework_mib(X) -> snmp_framework_mib(X). +mse_target_mib(X) -> snmp_target_mib(X). +mse_notification_mib(X) -> snmp_notification_mib(X). +mse_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). +mse_sparse_table(X) -> sparse_table(X). +mse_me_of(X) -> ms_me_of(X). +mse_mib_of(X) -> ms_mib_of(X). + +msd_simple(X) -> simple(X). +msd_v1_processing(X) -> v1_processing(X). +msd_big(X) -> big(X). +msd_big2(X) -> big2(X). +msd_loop_mib(X) -> loop_mib(X). +msd_api(X) -> api(X). +msd_sa_register(X) -> sa_register(X). +msd_v1_trap(X) -> v1_trap(X). +msd_sa_error(X) -> sa_error(X). +msd_next_across_sa(X) -> next_across_sa(X). +msd_undo(X) -> undo(X). +msd_standard_mib(X) -> snmp_standard_mib(X). +msd_community_mib(X) -> snmp_community_mib(X). +msd_framework_mib(X) -> snmp_framework_mib(X). +msd_target_mib(X) -> snmp_target_mib(X). +msd_notification_mib(X) -> snmp_notification_mib(X). +msd_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). +msd_sparse_table(X) -> sparse_table(X). +msd_me_of(X) -> ms_me_of(X). +msd_mib_of(X) -> ms_mib_of(X). + +msm_simple(X) -> simple(X). +msm_v1_processing(X) -> v1_processing(X). +msm_big(X) -> big(X). +msm_big2(X) -> big2(X). +msm_loop_mib(X) -> loop_mib(X). +msm_api(X) -> api(X). +msm_sa_register(X) -> sa_register(X). +msm_v1_trap(X) -> v1_trap(X). +msm_sa_error(X) -> sa_error(X). +msm_next_across_sa(X) -> next_across_sa(X). +msm_undo(X) -> undo(X). +msm_standard_mib(X) -> snmp_standard_mib(X). +msm_community_mib(X) -> snmp_community_mib(X). +msm_framework_mib(X) -> snmp_framework_mib(X). +msm_target_mib(X) -> snmp_target_mib(X). +msm_notification_mib(X) -> snmp_notification_mib(X). +msm_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). +msm_sparse_table(X) -> sparse_table(X). +msm_me_of(X) -> ms_me_of(X). +msm_mib_of(X) -> ms_mib_of(X). + + +mse_size_check(X) -> p("mse_size_check..."), ms_size_check(X). +msd_size_check(X) -> p("msd_size_check..."), ms_size_check(X). +msm_size_check(X) -> p("msm_size_check..."), ms_size_check(X). + +msd_varm_mib_start(X) -> p("msd_varm_mib_start..."), varm_mib_start(X). +msm_varm_mib_start(X) -> p("msm_varm_mib_start..."), varm_mib_start(X). + +ms_size_check(suite) -> []; +ms_size_check(Config) when list(Config) -> + p("ms_size_check..."), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?LOG("mib server size check...", []), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + ?line load_master_std("OTP-SNMPEA-MIB"), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-MPD-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-USER-BASED-SM-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + ?line load_master_std("SNMPv2-MIB"), + ?line load_master_std("SNMPv2-TM"), + + ?SLEEP(2000), + + ?line display_memory_usage(), + + ?line unload_master("OTP-SNMPEA-MIB"), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?line unload_master("SNMP-MPD-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-USER-BASED-SM-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + ?line unload_master("SNMPv2-MIB"), + ?line unload_master("SNMPv2-TM"), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + + ok. + + +varm_mib_start(suite) -> []; +varm_mib_start(Config) when list(Config) -> + p("varm_mib_start..."), + ?LOG("varm_mib_start -> entry", []), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + %% Start the agent + Opts = ?GCONF(agent_opts, Config), + Config1 = start_v1_agent(Config, Opts), + + %% Sleep some in order for the agent to start properly + ?DBG("varm_mib_start -> sleep some (before loading mobs)", []), + ?SLEEP(5000), + + %% Load all the mibs + HardwiredMibs = loaded_mibs(), + ?DBG("varm_mib_start -> load all mibs", []), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + + %% Unload the hardwired mibs + ?DBG("varm_mib_start -> sleep some (before unloading hardwired mibs)", []), + ?SLEEP(1000), + ?DBG("varm_mib_start -> unload (hardwired) mibs", []), + ?line unload_mibs(HardwiredMibs), %% unload hardwired + + ?DBG("varm_mib_start -> sleep some (before stopping agent)", []), + ?SLEEP(1000), + + %% Stop the agent (without deleting the stored files) + ?DBG("varm_mib_start -> stop the agent", []), + Config2 = stop_agent(Config1), + + %% Sleep some in order for the agent to stop properly + ?DBG("varm_mib_start -> sleep some (before re-starting the agent)", []), + ?SLEEP(5000), + + %% Start the agent (again) + ?DBG("varm_mib_start -> start the agent", []), + Config3 = start_v1_agent(Config2, Opts), + + ?DBG("varm_mib_start -> sleep some (before starting tests)", []), + ?SLEEP(5000), + + %% Perform the test(s) + ?DBG("varm_mib_start -> perform the tests", []), + try_test(snmp_community_mib), + try_test(snmp_framework_mib), + try_test(snmp_target_mib), + try_test(snmp_notification_mib), + + %% Stop the agent (without deleting the stored files) + ?DBG("varm_mib_start -> stop the agent", []), + stop_agent(Config3), + ok. + + +-define(snmpTrapCommunity_instance, [1,3,6,1,6,3,18,1,4,0]). +-define(vacmViewSpinLock_instance, [1,3,6,1,6,3,16,1,5,1,0]). +-define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). + +ms_me_of(suite) -> []; +ms_me_of(Config) when list(Config) -> + p("ms_me_of..."), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + ?line load_master_std("OTP-SNMPEA-MIB"), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-MPD-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + + ?SLEEP(2000), + + ?line display_memory_usage(), + + + ?DBG("ms_me_of -> find ~w from SNMP-COMMUNITY-MIB", + [?snmpTrapCommunity_instance]), + ?line ok = me_of(?snmpTrapCommunity_instance), + + ?DBG("ms_me_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", + [?vacmViewSpinLock_instance]), + ?line ok = me_of(?vacmViewSpinLock_instance), + + ?DBG("ms_me_of -> find ~w from SNMP-USER-BASED-SM-MIB", + [?usmStatsNotInTimeWindows_instance]), + ?line {error, _} = me_of(?usmStatsNotInTimeWindows_instance), + + + ?line unload_master("OTP-SNMPEA-MIB"), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?line unload_master("SNMP-MPD-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + + ok. + +me_of(Oid) -> + case snmpa:me_of(Oid) of + {ok, #me{oid = Oid}} -> + ok; + {ok, #me{oid = OtherOid}} -> + case lists:reverse(Oid) of + [0|Rest] -> + case lists:reverse(Rest) of + OtherOid -> + ok; + AnotherOid -> + {error, {invalid_oid, Oid, AnotherOid}} + end; + _ -> + {error, {invalid_oid, Oid, OtherOid}} + end; + {error, Reason} -> + {error, Reason}; + Else -> + {error, Else} + end. + + +ms_mib_of(suite) -> []; +ms_mib_of(Config) when list(Config) -> + p("ms_mib_of..."), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + ?line load_master_std("OTP-SNMPEA-MIB"), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-MPD-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + + ?SLEEP(2000), + + ?line display_memory_usage(), + + + ?DBG("ms_mib_of -> find ~w from SNMP-COMMUNITY-MIB", + [?snmpTrapCommunity_instance]), + ?line ok = mib_of(?snmpTrapCommunity_instance, 'SNMP-COMMUNITY-MIB'), + + ?DBG("ms_mib_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", + [?vacmViewSpinLock_instance]), + ?line ok = mib_of(?vacmViewSpinLock_instance, 'SNMP-VIEW-BASED-ACM-MIB'), + + ?DBG("ms_mib_of -> find ~w from SNMP-USER-BASED-SM-MIB", + [?usmStatsNotInTimeWindows_instance]), + ?line {error, _} = mib_of(?usmStatsNotInTimeWindows_instance, + 'SNMP-USER-BASED-SM-MIB'), + + + ?line unload_master("OTP-SNMPEA-MIB"), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?line unload_master("SNMP-MPD-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + + ok. + +mib_of(Oid, ExpectedMibName) -> + ?DBG("mib_of -> entry with" + "~n Oid: ~p" + "~n ExpectedMibName: ~p", [Oid, ExpectedMibName]), + %% case snmpa:mib_of(Oid) of + MibOf = snmpa:mib_of(Oid), + ?DBG("mib_of -> MibOf: ~n~p", [MibOf]), + case MibOf of + {ok, ExpectedMibName} -> + ok; + {ok, OtherMibName} -> + {error, {invalid_mib, ExpectedMibName, OtherMibName}}; + {error, Reason} -> + {error, Reason}; + Else -> + ?DBG("mib_of -> Else: ~n~p", [Else]), + {error, Else} + end. + + +app_info(suite) -> []; +app_info(Config) when list(Config) -> + SnmpDir = app_dir(snmp), + SslDir = app_dir(ssl), + CryptoDir = app_dir(crypto), + Attr = snmp:module_info(attributes), + AppVsn = + case lists:keysearch(app_vsn, 1, Attr) of + {value, {app_vsn, V}} -> + V; + false -> + "undefined" + end, + io:format("Root dir: ~s~n" + "SNMP: Application dir: ~s~n" + " Application ver: ~s~n" + "SSL: Application dir: ~s~n" + "CRYPTO: Application dir: ~s~n", + [code:root_dir(), SnmpDir, AppVsn, SslDir, CryptoDir]), + ok. + +app_dir(App) -> + case code:lib_dir(App) of + D when list(D) -> + filename:basename(D); + {error, _Reason} -> + "undefined" + end. + + +test_v1(suite) -> {req, [], {conf, init_v1, v1_cases(), finish_v1}}. + +%v1_cases() -> [loop_mib]; +v1_cases() -> + [simple, + db_notify_client, + v1_processing, big, big2, loop_mib, + api, subagent, mnesia, multiple_reqs, + sa_register, v1_trap, sa_error, next_across_sa, undo, reported_bugs, + standard_mibs, sparse_table, cnt_64, + opaque, + % opaque]. + + change_target_addr_config]. + +init_v1(Config) when list(Config) -> + ?line SaNode = ?config(snmp_sa, Config), + ?line create_tables(SaNode), + ?line AgentDir = ?config(agent_dir, Config), + ?line MgrDir = ?config(mgr_dir, Config), + ?line Ip = ?config(ip, Config), + ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v1} | start_v1_agent(Config)]. + +finish_v1(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + +test_v2(suite) -> {req, [], {conf, init_v2, v2_cases(), finish_v2}}. + +%v2_cases() -> [loop_mib_2]; +v2_cases() -> + [simple_2, v2_processing, big_2, big2_2, loop_mib_2, + api_2, subagent_2, mnesia_2, + multiple_reqs_2, sa_register_2, v2_trap, v2_inform, sa_error_2, + next_across_sa_2, undo_2, reported_bugs_2, standard_mibs_2, + v2_types, implied, sparse_table_2, cnt_64_2, opaque_2, v2_caps]. + +init_v2(Config) when list(Config) -> + SaNode = ?config(snmp_sa, Config), + create_tables(SaNode), + AgentDir = ?config(agent_dir, Config), + MgrDir = ?config(mgr_dir, Config), + Ip = ?config(ip, Config), + config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v2} | start_v2_agent(Config)]. + +finish_v2(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + +test_v1_v2(suite) -> {req, [], {conf, init_v1_v2, v1_v2_cases(), finish_v1_v2}}. + +v1_v2_cases() -> + [simple_bi]. + +init_v1_v2(Config) when list(Config) -> + SaNode = ?config(snmp_sa, Config), + create_tables(SaNode), + AgentDir = ?config(agent_dir, Config), + MgrDir = ?config(mgr_dir, Config), + Ip = ?config(ip, Config), + config([v1,v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, bilingual} | start_bilingual_agent(Config)]. + +finish_v1_v2(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + +test_v3(suite) -> {req, [], {conf, init_v3, v3_cases(), finish_v3}}. + +%v3_cases() -> [loop_mib_3]; +v3_cases() -> + [simple_3, v3_processing, + big_3, big2_3, api_3, subagent_3, mnesia_3, loop_mib_3, + multiple_reqs_3, sa_register_3, v3_trap, v3_inform, sa_error_3, + next_across_sa_3, undo_3, reported_bugs_3, standard_mibs_3, + v3_security, + v2_types_3, implied_3, sparse_table_3, cnt_64_3, opaque_3, v2_caps_3]. + +init_v3(Config) when list(Config) -> + %% Make sure crypto works, otherwise start_agent will fail + %% and we will be stuck with a bunch of mnesia tables for + %% the rest of this suite... + ?DBG("start_agent -> start crypto app",[]), + case os:type() of + vxworks -> + no_crypto; + _ -> + case ?CRYPTO_START() of + ok -> + case ?CRYPTO_SUPPORT() of + {no, Reason} -> + ?SKIP({unsupported_encryption, Reason}); + yes -> + ok + end; + {error, Reason} -> + ?SKIP({failed_starting_crypto, Reason}) + end + end, + SaNode = ?config(snmp_sa, Config), + create_tables(SaNode), + AgentDir = ?config(agent_dir, Config), + MgrDir = ?config(mgr_dir, Config), + Ip = ?config(ip, Config), + ?line ok = config([v3], MgrDir, AgentDir, + tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v3} | start_v3_agent(Config)]. + +finish_v3(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + +test_multi_threaded(suite) -> {req, [], {conf, init_mt, mt_cases(), finish_mt}}. + +mt_cases() -> + [multi_threaded, mt_trap]. + +init_mt(Config) when list(Config) -> + SaNode = ?config(snmp_sa, Config), + create_tables(SaNode), + AgentDir = ?config(agent_dir, Config), + MgrDir = ?config(mgr_dir, Config), + Ip = ?config(ip, Config), + ?line ok = config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v2} | start_multi_threaded_agent(Config)]. + +finish_mt(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + +%% This one *must* be run first in each case. +init_case(Config) when list(Config) -> + ?DBG("init_case -> entry with" + "~n Config: ~p", [Config]), + SaNode = ?config(snmp_sa, Config), + MgrNode = ?config(snmp_mgr, Config), + MasterNode = node(), + + SaHost = ?HOSTNAME(SaNode), + MgrHost = ?HOSTNAME(MgrNode), + MasterHost = ?HOSTNAME(MasterNode), + {ok, MasterIP} = snmp_misc:ip(MasterHost), + {ok, MIP} = snmp_misc:ip(MgrHost), + {ok, SIP} = snmp_misc:ip(SaHost), + + + put(mgr_node, MgrNode), + put(sa_node, SaNode), + put(master_node, MasterNode), + put(sa_host, SaHost), + put(mgr_host, MgrHost), + put(master_host, MasterHost), + put(mip, tuple_to_list(MIP)), + put(masterip , tuple_to_list(MasterIP)), + put(sip, tuple_to_list(SIP)), + + MibDir = ?config(mib_dir, Config), + put(mib_dir, MibDir), + StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", + put(std_mib_dir, StdM), + + MgrDir = ?config(mgr_dir, Config), + put(mgr_dir, MgrDir), + + put(vsn, ?config(vsn, Config)), + ?DBG("init_case -> exit with" + "~n MasterNode: ~p" + "~n SaNode: ~p" + "~n MgrNode: ~p" + "~n MibDir: ~p", [MasterNode, SaNode, MgrNode, MibDir]), + {SaNode, MgrNode, MibDir}. + +load_master(Mib) -> + ?DBG("load_master -> entry with" + "~n Mib: ~p", [Mib]), + snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety + ok = snmpa:load_mibs(snmp_master_agent, [get(mib_dir) ++ Mib]). + +load_master_std(Mib) -> + ?DBG("load_master_std -> entry with" + "~n Mib: ~p", [Mib]), + snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety + ok = snmpa:load_mibs(snmp_master_agent, [get(std_mib_dir) ++ Mib]). + +unload_master(Mib) -> + ?DBG("unload_master -> entry with" + "~n Mib: ~p", [Mib]), + ok = snmpa:unload_mibs(snmp_master_agent, [Mib]). + +loaded_mibs() -> + ?DBG("loaded_mibs -> entry",[]), + Info = snmpa:info(snmp_master_agent), + {value, {loaded_mibs, Mibs}} = lists:keysearch(loaded_mibs, 1, Info), + [atom_to_list(Mib) || {Mib,_,_} <- Mibs]. + +unload_mibs(Mibs) -> + ?DBG("unload_mibs -> entry with" + "~n Mibs: ~p", [Mibs]), + ok = snmpa:unload_mibs(snmp_master_agent, Mibs). + +start_subagent(SaNode, RegTree, Mib) -> + ?DBG("start_subagent -> entry with" + "~n SaNode: ~p" + "~n RegTree: ~p" + "~n Mib: ~p", [SaNode, RegTree, Mib]), + MA = whereis(snmp_master_agent), + ?DBG("start_subagent -> MA: ~p", [MA]), + MibDir = get(mib_dir), + Mib1 = join(MibDir,Mib), + %% BMK BMK +% case rpc:call(SaNode,snmp_supervisor,start_subagent,[MA,RegTree,[Mib1]]) of + case rpc:call(SaNode, snmpa_supervisor, + start_sub_agent, [MA, RegTree, [Mib1]]) of + {ok, SA} -> + ?DBG("start_subagent -> SA: ~p", [SA]), + {ok, SA}; + Error -> + ?FAIL({subagent_start_failed, SaNode, Error, [MA, RegTree, Mib1]}) + end. + +stop_subagent(SA) -> + ?DBG("stop_subagent -> entry with" + "~n SA: ~p", [SA]), + %% BNK BMK + %% rpc:call(node(SA), snmp_supervisor, stop_subagent, [SA]). + rpc:call(node(SA), snmpa_supervisor, stop_sub_agent, [SA]). + +%%----------------------------------------------------------------- +%% This function takes care of the old OTP-SNMPEA-MIB. +%% Unfortunately, the testcases were written to use the data in the +%% internal tables, and these table are now obsolete and not used +%% by the agent. Therefore, we emulate them by using +%% OLD-SNMPEA-MIB, which uses the default impl. of all tables. +%% +%% These two rows must exist in intCommunityTable +%% {[147,214,36,45], "public", 2, readWrite}. +%% {[147,214,36,45], "standard trap", 2, read}. +%% (But with the manager's IP address) +%% +%%----------------------------------------------------------------- +init_old() -> + snmpa_local_db:table_create_row(intCommunityTable, + get(mip) ++ [6 | "public"], + {get(mip), "public", 2, 2}), + snmpa_local_db:table_create_row(intCommunityTable, + get(mip) ++ [13 | "standard trap"], + {get(mip), "standard trap", 2, 1}), + snmpa_local_db:variable_set(intAgentIpAddress, [127,0,0,1]). + + + +simple(suite) -> []; +simple(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + try_test(simple_standard_test). + +simple_2(X) -> simple(X). + +simple_bi(suite) -> []; +simple_bi(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + put(vsn, v1), % First, try v1 manager + try_test(simple_standard_test), + + put(vsn, v2), % Then, try v2 manager + try_test(simple_standard_test). + +simple_3(X) -> + simple(X). + +big(suite) -> []; +big(Config) when list(Config) -> + ?DBG("big -> entry", []), + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Starting subagent..."), + ?line pong = net_adm:ping(SaNode), + + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), + ?DBG("big -> SA: ~p", [SA]), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(big_test), + ?line stop_subagent(SA), + ?line unload_master("OLD-SNMPEA-MIB"). + +big_2(X) -> big(X). + +big_3(X) -> big(X). + + +big2(suite) -> []; +big2(Config) when list(Config) -> + %% This is exactly the same tests as 'big', but with the + %% v2 equivalent of the mibs. + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Starting subagent..."), + ?line pong = net_adm:ping(SaNode), + + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1-v2"), + ?line load_master("OLD-SNMPEA-MIB-v2"), + ?line init_old(), + try_test(big_test), + ?line stop_subagent(SA), + ?line unload_master("OLD-SNMPEA-MIB-v2"). + +big2_2(X) -> big2(X). + +big2_3(X) -> big2(X). + + +multi_threaded(suite) -> []; +multi_threaded(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test1"), + try_test(multi_threaded_test), + ?line unload_master("Test1"). + +mt_trap(suite) -> []; +mt_trap(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line load_master("Test1"), + ?line load_master("TestTrapv2"), + try_test(mt_trap_test, [MA]), + ?line unload_master("TestTrapv2"), + ?line unload_master("Test1"). + +v2_types(suite) -> []; +v2_types(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test1"), + try_test(types_v2_test), + ?line unload_master("Test1"). + +v2_types_3(X) -> v2_types(X). + + +implied(suite) -> []; +implied(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line load_master("Test1"), + try_test(implied_test,[MA]), + ?line unload_master("Test1"). + +implied_3(X) -> implied(X). + + +sparse_table(suite) -> []; +sparse_table(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test1"), + try_test(sparse_table_test), + ?line unload_master("Test1"). + +sparse_table_2(X) -> sparse_table(X). + +sparse_table_3(X) -> sparse_table(X). + +cnt_64(suite) -> []; +cnt_64(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line load_master("Test1"), + try_test(cnt_64_test, [MA]), + ?line unload_master("Test1"). + +cnt_64_2(X) -> cnt_64(X). + +cnt_64_3(X) -> cnt_64(X). + +opaque(suite) -> []; +opaque(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test1"), + try_test(opaque_test), + ?line unload_master("Test1"). + +opaque_2(X) -> opaque(X). + +opaque_3(X) -> opaque(X). + + +change_target_addr_config(suite) -> []; +change_target_addr_config(Config) when list(Config) -> + p("Testing changing target address config..."), + ?LOG("change_target_addr_config -> entry",[]), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + put(sname,snmp_suite), + put(verbosity,trace), + + MA = whereis(snmp_master_agent), + + ?LOG("change_target_addr_config -> load TestTrap",[]), + ?line load_master("TestTrap"), + + ?LOG("change_target_addr_config -> set trace verbosity for local_db",[]), + ?line snmpa:verbosity(local_db,trace), + + %% First send some traps that will arive att the original manager + ?LOG("change_target_addr_config -> send trap",[]), + try_test(ma_trap1, [MA]), + + ?LOG("change_target_addr_config -> set silence verbosity for local_db",[]), + ?line snmpa:verbosity(local_db,silence), + + %% Start new dummy listener + ?LOG("change_target_addr_config -> start dummy manager",[]), + ?line {ok,Pid,NewPort} = dummy_manager_start(MA), + + %% Reconfigure + ?LOG("change_target_addr_config -> reconfigure",[]), + AgentDir = ?config(agent_dir, Config), + ?line rewrite_target_addr_conf(AgentDir, NewPort), + ?line snmp_target_mib:reconfigure(AgentDir), + + %% Send the trap again + ?LOG("change_target_addr_config -> send trap again",[]), + catch dummy_manager_send_trap2(Pid), + + ?LOG("change_target_addr_config -> await trap ack",[]), + catch dummy_manager_await_trap2_ack(), + + ?LOG("change_target_addr_config -> stop dummy manager",[]), + ?line ok = dummy_manager_stop(Pid), + + ?LOG("change_target_addr_config -> reset target address config",[]), + ?line reset_target_addr_conf(AgentDir), + + ?LOG("change_target_addr_config -> unload TestTrap",[]), + ?line unload_master("TestTrap"). + + +dummy_manager_start(MA) -> + ?DBG("dummy_manager_start -> entry",[]), + Pid = spawn(get(mgr_node), ?MODULE,dummy_manager_init,[self(),MA]), + ?DBG("dummy_manager_start -> Pid: ~p",[Pid]), + await_dummy_manager_started(Pid). + +await_dummy_manager_started(Pid) -> + receive + {dummy_manager_started,Pid,Port} -> + ?DBG("dummy_manager_start -> acknowledge received with" + "~n Port: ~p",[Port]), + {ok,Pid,Port}; + {'EXIT', Pid, Reason} -> + {error, Pid, Reason}; + O -> + ?LOG("dummy_manager_start -> received unknown message:" + "~n ~p",[O]), + await_dummy_manager_started(Pid) + end. + +dummy_manager_stop(Pid) -> + ?DBG("dummy_manager_stop -> entry with Pid: ~p",[Pid]), + Pid ! stop, + receive + {dummy_manager_stopping, Pid} -> + ?DBG("dummy_manager_stop -> acknowledge received",[]), + ok + after 10000 -> + ?ERR("dummy_manager_stop -> timeout",[]), + timeout + end. + +dummy_manager_send_trap2(Pid) -> + ?DBG("dummy_manager_send_trap2 -> entry",[]), + Pid ! {send_trap,testTrap2}. + +dummy_manager_await_trap2_ack() -> + ?DBG("dummy_manager_await_trap2 -> entry",[]), + receive + {received_trap,Trap} -> + ?LOG("dummy_manager_await_trap2 -> received trap: ~p",[Trap]), + %% Note: + %% Without this sleep the v2_inform_i testcase failes! There + %% is no relation between these two test cases as far as I + %% able to figure out... + sleep(60000), + ok; + O -> + ?ERR("dummy_manager_await_trap2 -> unexpected message: ~p",[O]), + ok + after 10000 -> + ?ERR("dummy_manager_await_trap2 -> timeout",[]), + timeout + end. + +dummy_manager_init(Parent,MA) -> + ?DBG("dummy_manager_init -> entry with" + "~n Parent: ~p" + "~n MA: ~p",[Parent,MA]), + {ok,S} = gen_udp:open(0,[{recbuf,65535}]), + ?DBG("dummy_manager_init -> S: ~p",[S]), + {ok,Port} = inet:port(S), + ?DBG("dummy_manager_init -> Port: ~p",[Port]), + Parent ! {dummy_manager_started,self(),Port}, + dummy_manager_loop(Parent,S,MA). + +dummy_manager_loop(P,S,MA) -> + ?LOG("dummy_manager_loop -> ready for receive",[]), + receive + {send_trap,Trap} -> + ?LOG("dummy_manager_loop -> received trap send request" + "~n Trap: ~p",[Trap]), + snmpa:send_trap(MA, Trap, "standard trap"), + dummy_manager_loop(P,S,MA); + {udp, _UdpId, Ip, UdpPort, Bytes} -> + ?LOG("dummy_manager_loop -> received upd message" + "~n from: ~p:~p" + "~n size: ~p", + [Ip, UdpPort, dummy_manager_message_sz(Bytes)]), + R = dummy_manager_handle_message(Bytes), + ?DBG("dummy_manager_loop -> R: ~p",[R]), + P ! R, + dummy_manager_loop(P,S,MA); + stop -> + ?DBG("dummy_manager_loop -> received stop request",[]), + P ! {dummy_manager_stopping, self()}, + gen_udp:close(S), + exit(normal); + O -> + ?LOG("dummy_manager_loop -> received unknown message:" + "~n ~p",[O]), + dummy_manager_loop(P,S,MA) + end. + +dummy_manager_message_sz(B) when binary(B) -> + size(B); +dummy_manager_message_sz(L) when list(L) -> + length(L); +dummy_manager_message_sz(_) -> + undefined. + +dummy_manager_handle_message(Bytes) -> + case (catch snmp_pdus:dec_message(Bytes)) of + {'EXIT',Reason} -> + ?ERR("dummy_manager_handle_message -> " + "failed decoding message only:~n ~p",[Reason]), + {error,Reason}; + M -> + ?DBG("dummy_manager_handle_message -> decoded message:" + "~n ~p",[M]), + {received_trap,M} + end. + + +api(suite) -> []; +api(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(api_test, [node()]), + ?line unload_master("OLD-SNMPEA-MIB"). + +api_2(X) -> api(X). + +api_3(X) -> api(X). + + +subagent(suite) -> []; +subagent(Config) when list(Config) -> + {SaNode, _MgrNode, MibDir} = init_case(Config), + + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), + try_test(load_test_sa), + + p("Testing unregister subagent..."), + MA = whereis(snmp_master_agent), + rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), + try_test(unreg_test), + + p("Loading previous subagent mib in master and testing..."), + ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas1"]), + try_test(load_test), + + p("Unloading previous subagent mib in master and testing..."), + ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas1"]), + try_test(unreg_test), + p("Testing register subagent..."), + rpc:call(SaNode, snmp, register_subagent, + [MA, ?klas1, SA]), + try_test(load_test_sa), + + ?line stop_subagent(SA), + try_test(unreg_test). + +subagent_2(X) -> subagent(X). + +subagent_3(X) -> subagent(X). + + +mnesia(suite) -> []; +mnesia(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Starting subagent with mnesia impl..."), + {ok, SA} = start_subagent(SaNode, ?klas2, "Klas2"), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + + try_test(big_test_2), + + p("Testing unregister subagent..."), + MA = whereis(snmp_master_agent), + rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), + try_test(unreg_test), + ?line unload_master("OLD-SNMPEA-MIB"), + ?line stop_subagent(SA). + +mnesia_2(X) -> mnesia(X). + +mnesia_3(X) -> mnesia(X). + + +multiple_reqs(suite) -> + {req, [], {conf, init_mul, mul_cases(), finish_mul}}. + +mul_cases() -> + [mul_get, mul_get_err, mul_next, mul_next_err, mul_set_err]. + +multiple_reqs_2(suite) -> + {req, [], {conf, init_mul, mul_cases_2(), finish_mul}}. + +multiple_reqs_3(_X) -> + {req, [], {conf, init_mul, mul_cases_3(), finish_mul}}. + + +mul_cases_2() -> + [mul_get_2, mul_get_err_2, mul_next_2, mul_next_err_2, mul_set_err_2]. + + +mul_cases_3() -> + [mul_get_3, mul_get_err_3, mul_next_3, mul_next_err_3, mul_set_err_3]. + + +init_mul(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + [{mul_sub, SA} | Config]. + +finish_mul(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + SA = ?config(mul_sub, Config), + + ?line unload_master("OLD-SNMPEA-MIB"), + ?line stop_subagent(SA), + lists:keydelete(mul_sub, 1, Config). + +mul_get(suite) -> []; +mul_get(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple get..."), + try_test(do_mul_get). + +mul_get_2(X) -> mul_get(X). + +mul_get_3(X) -> mul_get(X). + + +mul_get_err(suite) -> []; +mul_get_err(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple get with error..."), + try_test(do_mul_get_err). + +mul_get_err_2(X) -> mul_get_err(X). + +mul_get_err_3(X) -> mul_get_err(X). + + +mul_next(suite) -> []; +mul_next(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple next..."), + try_test(do_mul_next). + +mul_next_2(X) -> mul_next(X). + +mul_next_3(X) -> mul_next(X). + + +mul_next_err(suite) -> []; +mul_next_err(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple next..."), + try_test(do_mul_next_err). + +mul_next_err_2(X) -> mul_next_err(X). + +mul_next_err_3(X) -> mul_next_err(X). + + +mul_set(suite) -> []; +mul_set(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple set..."), + try_test(do_mul_set). + +mul_set_2(X) -> mul_set(X). + +mul_set_3(X) -> mul_set(X). + + +mul_set_err(suite) -> []; +mul_set_err(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple set with error..."), + try_test(do_mul_set_err). + +mul_set_err_2(X) -> mul_set_err(X). + +mul_set_err_3(X) -> mul_set_err(X). + + +sa_register(suite) -> []; +sa_register(Config) when list(Config) -> + ?DBG("sa_register -> entry", []), + {SaNode, _MgrNode, MibDir} = init_case(Config), + + ?DBG("sa_register -> start subagent", []), + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), + + ?DBG("sa_register -> unregister subagent", []), + p("Testing unregister subagent (2)..."), + MA = whereis(snmp_master_agent), + rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), + try_test(unreg_test), + + p("Loading SA-MIB..."), + ?DBG("sa_register -> unload mibs", []), + snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), + ?DBG("sa_register -> unload mibs", []), + snmpa:load_mibs(SA, [MibDir ++ "SA-MIB"]), + ?DBG("sa_register -> register subagent", []), + rpc:call(SaNode, snmp, register_subagent, [MA,?sa,SA]), + try_test(sa_mib), + + ?DBG("sa_register -> stop subagent", []), + ?line stop_subagent(SA). + +sa_register_2(X) -> sa_register(X). + +sa_register_3(X) -> sa_register(X). + + +v1_trap(suite) -> []; +v1_trap(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Testing trap sending from master agent..."), + MA = whereis(snmp_master_agent), + + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(ma_trap1, [MA]), + try_test(ma_trap2, [MA]), + try_test(ma_v2_2_v1_trap, [MA]), + try_test(ma_v2_2_v1_trap2, [MA]), + + p("Testing trap sending from subagent..."), + try_test(sa_trap1, [SA]), + try_test(sa_trap2, [SA]), + try_test(sa_trap3, [SA]), + + ?line unload_master("TestTrap"), + ?line unload_master("TestTrapv2"), + + ?line stop_subagent(SA). + +v2_trap(suite) -> []; +v2_trap(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Testing trap sending from master agent..."), + MA = whereis(snmp_master_agent), + + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + + try_test(ma_v2_trap1, [MA]), + try_test(ma_v2_trap2, [MA]), + try_test(ma_v1_2_v2_trap, [MA]), + try_test(ma_v1_2_v2_trap2, [MA]), + + try_test(sa_mib), + p("Testing trap sending from subagent..."), + try_test(sa_v1_2_v2_trap1, [SA]), + try_test(sa_v1_2_v2_trap2, [SA]), + try_test(sa_v1_2_v2_trap3, [SA]), + + ?line unload_master("TestTrap"), + ?line unload_master("TestTrapv2"), + + ?line stop_subagent(SA). + +v3_trap(X) -> + v2_trap(X). + +v2_inform(suite) -> + {req, [], {conf, init_v2_inform, [v2_inform_i], finish_v2_inform}}. + +v3_inform(_X) -> + %% v2_inform(X). + {req, [], {conf, init_v3_inform, [v3_inform_i], finish_v3_inform}}. + +init_v2_inform(Config) when list(Config) -> + _Dir = ?config(agent_dir, Config), +% snmp_internal_mib:configure(Dir), + Config. + +init_v3_inform(X) -> + init_v2_inform(X). + +finish_v2_inform(Config) when list(Config) -> + _Dir = ?config(agent_dir, Config), +% snmp_internal_mib:configure(Dir), + Config. + +finish_v3_inform(X) -> + finish_v2_inform(X). + + + +v2_inform_i(suite) -> []; +v2_inform_i(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing inform sending from master agent... NOTE! This test\ntakes a " + "few minutes (5) to complete."), + MA = whereis(snmp_master_agent), + + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(ma_v2_inform1, [MA]), + + ?line unload_master("TestTrap"), + ?line unload_master("TestTrapv2"). + +v3_inform_i(X) -> v2_inform_i(X). + + +sa_error(suite) -> []; +sa_error(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Testing sa bad value (is_set_ok)..."), + try_test(sa_errs_bad_value), + + p("Testing sa gen err (set)..."), + try_test(sa_errs_gen_err), + + p("Testing too big..."), + try_test(sa_too_big), + + ?line unload_master("OLD-SNMPEA-MIB"), + stop_subagent(SA). + +sa_error_2(X) -> sa_error(X). + +sa_error_3(X) -> sa_error(X). + + +next_across_sa(suite) -> []; +next_across_sa(Config) when list(Config) -> + {SaNode, _MgrNode, MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Loading another subagent mib..."), + ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas1"]), + + rpc:call(SaNode, snmp, register_subagent, [MA, ?klas1, SA]), + try_test(load_test_sa), + + p("Testing next across subagent (endOfMibView from SA)..."), + try_test(next_across_sa), + + p("Unloading mib"), + snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), + rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), + try_test(unreg_test), + + p("Starting another subagent"), + ?line {ok, SA2} = start_subagent(SaNode, ?klas1, "Klas1"), + p("Testing next across subagent (wrong prefix from SA)..."), + try_test(next_across_sa), + + stop_subagent(SA), + stop_subagent(SA2). + +next_across_sa_2(X) -> next_across_sa(X). + +next_across_sa_3(X) -> next_across_sa(X). + + +undo(suite) -> []; +undo(Config) when list(Config) -> + {SaNode, _MgrNode, MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Testing undo phase at master agent..."), + ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas3"]), + ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas4"]), + try_test(undo_test), + try_test(api_test2), + ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas3"]), + + p("Testing bad return values from instrum. funcs..."), + try_test(bad_return), + + ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas4"]), + + p("Testing undo phase at subagent..."), + ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas3"]), + ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas4"]), + ?line ok = snmpa:register_subagent(MA, ?klas3, SA), + ?line ok = snmpa:register_subagent(MA, ?klas4, SA), + try_test(undo_test), + try_test(api_test3), + + p("Testing undo phase across master/subagents..."), + try_test(undo_test), + try_test(api_test3), + stop_subagent(SA). + +undo_2(X) -> undo(X). + +undo_3(X) -> undo(X). + +%% Req. Test2 +v1_processing(suite) -> []; +v1_processing(Config) when list(Config) -> + ?DBG("v1_processing -> entry", []), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + try_test(v1_proc), + ?line unload_master("Test2"). + +%% Req. Test2 +v2_processing(suite) -> []; +v2_processing(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + try_test(v2_proc), + ?line unload_master("Test2"). + +%% Req. Test2 +v3_processing(suite) -> []; +v3_processing(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + try_test(v2_proc), % same as v2! + ?line unload_master("Test2"). + + +%% We'll try get/set/trap and inform for all the auth & priv protocols. +%% For informs, the mgr is auth-engine. The agent has to sync. This is +%% accomplished by the first inform sent. That one will generate a +%% report, which makes it in sync. The notification-generating +%% application times out, and send again. This time it'll work. +v3_security(suite) -> [v3_crypto_basic, v3_md5_auth, v3_sha_auth, v3_des_priv]. + +v3_crypto_basic(suite) -> []; +v3_crypto_basic(_Config) -> + EID = [0,0,0,0,0,0,0,0,0,0,0,2], + %% From rfc2274 appendix A.3.1 + ?line KMd5_1 = snmp:passwd2localized_key(md5, "maplesyrup", EID), + ?line [16#52,16#6f,16#5e,16#ed,16#9f,16#cc,16#e2,16#6f, + 16#89,16#64,16#c2,16#93,16#07,16#87,16#d8,16#2b] = + KMd5_1, + %% From rfc2274 appendix A.3.2 + ?line KSHA_1 = snmp:passwd2localized_key(sha, "maplesyrup", EID), + ?line [16#66,16#95,16#fe,16#bc,16#92,16#88,16#e3,16#62,16#82,16#23, + 16#5f,16#c7,16#15,16#1f,16#12,16#84,16#97,16#b3,16#8f,16#3f] = + KSHA_1, + %% From rfc2274, appendix A.5.1 + ?line KMd5_2 = snmp:passwd2localized_key(md5, "newsyrup", EID), + ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#88,16#05,16#61,16#51,16#41,16#67,16#6c,16#c9, + 16#19,16#61,16#74,16#e7,16#42,16#a3,16#25,16#51] = + snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2, 16, + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), + %% From rfc2274, appendix A.5.2 + ?line KSHA_2 = snmp:passwd2localized_key(sha, "newsyrup", EID), + ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#00,16#00,16#00,16#00,16#9c,16#10,16#17,16#f4, + 16#fd,16#48,16#3d,16#2d,16#e8,16#d5,16#fa,16#db, + 16#f8,16#43,16#92,16#cb,16#06,16#45,16#70,16#51] = + snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2, 20, + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), + KSHA_1t = lists:sublist(KSHA_1, 16), + KSHA_2t = lists:sublist(KSHA_2, 16), + ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#7e,16#f8,16#d8,16#a4,16#c9,16#cd,16#b2,16#6b, + 16#47,16#59,16#1c,16#d8,16#52,16#ff,16#88,16#b5] = + snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1t, KSHA_2t, 16, + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), + + %% Try with correct random + ?line Kc1 = snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2), + ?line KMd5_2 = snmp_user_based_sm_mib:extract_new_key(md5, KMd5_1, Kc1), + ?line Kc2 = snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2), + ?line KSHA_2 = snmp_user_based_sm_mib:extract_new_key(sha, KSHA_1, Kc2), + ok. + + + +v3_md5_auth(suite) -> []; +v3_md5_auth(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + p("Testing MD5 authentication...takes a few seconds..."), + + AgentDir = ?config(agent_dir, Config), + ?line rewrite_target_params_conf(AgentDir, "authMD5", authNoPriv), + ?line snmp_target_mib:reconfigure(AgentDir), + + MA = whereis(snmp_master_agent), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(v3_sync, [[{v2_proc, []}, + {ma_v2_trap1, [MA]}, + {v3_inform_sync, [MA]}]], + [{sec_level, authNoPriv}, {user, "authMD5"}]), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + ?line reset_target_params_conf(AgentDir). + +v3_sha_auth(suite) -> []; +v3_sha_auth(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + p("Testing SHA authentication...takes a few seconds..."), + + AgentDir = ?config(agent_dir, Config), + ?line rewrite_target_params_conf(AgentDir, "authSHA", authNoPriv), + ?line snmp_target_mib:reconfigure(AgentDir), + + MA = whereis(snmp_master_agent), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(v3_sync, [[{v2_proc, []}, + {ma_v2_trap1, [MA]}, + {v3_inform_sync, [MA]}]], + [{sec_level, authNoPriv}, {user, "authSHA"}]), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + ?line reset_target_params_conf(AgentDir). + +v3_des_priv(suite) -> []; +v3_des_priv(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + p("Testing DES encryption...takes a few seconds..."), + + AgentDir = ?config(agent_dir, Config), + ?line rewrite_target_params_conf(AgentDir, "privDES", authPriv), + ?line snmp_target_mib:reconfigure(AgentDir), + + MA = whereis(snmp_master_agent), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(v3_sync, [[{v2_proc, []}, + {ma_v2_trap1, [MA]}, + {v3_inform_sync, [MA]}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + ?line reset_target_params_conf(AgentDir). + +%% -define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). + +%% Make sure mgr is in sync with agent +v3_sync(Funcs) -> + ?DBG("v3_sync -> entry with Funcs: ~p",[Funcs]), + g([[sysDescr, 0]]), + expect(432, report, [{?usmStatsNotInTimeWindows_instance, any}]), + g([[sysDescr, 0]]), + expect(433, [{[sysDescr,0], any}]), + lists:foreach(fun({Func, Args}) -> apply(?MODULE, Func, Args) end, Funcs). + +v3_inform_sync(MA) -> + ?DBG("v3_sync -> entry with MA: ~p => Send notification",[MA]), + ?line snmpa:send_notification(MA, testTrapv22, no_receiver, + "standard inform", []), + %% Make sure agent is in sync with mgr... + ?DBG("v3_sync -> wait some time: ",[]), + sleep(20000), % more than 1500*10 in target_addr.conf + ?DBG("v3_sync -> await response",[]), + ?line expect(1, {inform, true}, + [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]). + + +v2_caps(suite) -> []; +v2_caps(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + try_test(v2_caps_i, [node()]). + +v2_caps_3(X) -> v2_caps(X). + + +v2_caps_i(Node) -> + ?line Idx = rpc:call(Node, snmp, add_agent_caps, [[1,2,3,4,5], "test cap"]), + g([[sysORID, Idx], [sysORDescr, Idx]]), + ?line expect(1, [{[sysORID, Idx], [1,2,3,4,5]}, + {[sysORDescr, Idx], "test cap"}]), + ?line rpc:call(Node, snmp, del_agent_caps, [Idx]), + g([[sysORID, Idx]]), + ?line expect(2, [{[sysORID, Idx], noSuchInstance}]). + + +%% Req. Test2 +v1_proc() -> + ?DBG("v1_proc -> entry", []), + %% According to RFC1157. + %% Template:
: + v1_get_p(), + v1_get_next_p(), + v1_set_p(). + + +v1_get_p() -> + %% 4.1.2:1 + g([[test2]]), + ?line expect(10, noSuchName, 1, [{[test2], 'NULL'}]), + g([[tDescr]]), + ?line expect(11, noSuchName, 1, [{[tDescr], 'NULL'}]), + g([[tDescr2,0]]), + ?line expect(12, noSuchName, 1, [{[tDescr2,0], 'NULL'}]), + g([[tDescr3,0]]), + ?line expect(131, noSuchName, 1, [{[tDescr3,0], 'NULL'}]), + g([[tDescr4,0]]), + ?line expect(132, noSuchName, 1, [{[tDescr4,0], 'NULL'}]), + g([[sysDescr, 0], [tDescr,0]]), % Outside mibview + ?line expect(14, noSuchName, 2, [{[sysDescr, 0], 'NULL'}, + {[tDescr,0], 'NULL'}]), + g([[sysDescr,3]]), + ?line expect(15, noSuchName, 1, [{[sysDescr, 3], 'NULL'}]), + + %% 4.1.2:2 + g([[tTable]]), + ?line expect(20, noSuchName, 1, [{[tTable], 'NULL'}]), + g([[tEntry]]), + ?line expect(21, noSuchName, 1, [{[tEntry], 'NULL'}]), + + %% 4.1.2:3 + g([[tTooBig, 0]]), + ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), + + %% 4.1.2:4 + g([[tGenErr1, 0]]), + ?line expect(40, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), + g([[tGenErr2, 0]]), + ?line expect(41, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), + g([[sysDescr, 0], [tGenErr3, 0]]), + ?line expect(42, genErr, 2, [{[sysDescr, 0], 'NULL'}, + {[tGenErr3, 0], 'NULL'}]). + + +v1_get_next_p() -> + %% 4.1.3:1 + gn([[1,3,7,1]]), + ?line expect(10, noSuchName, 1, [{[1,3,7,1], 'NULL'}]), + gn([[tDescr2]]), + ?line expect(11, tooBig, 0, any), + + %% 4.1.3:2 + gn([[tTooBig]]), + io:format("We currently don't handle tooBig correct!!!\n"), +% ?line expect(20, tooBig, 0, [{[tTooBig], 'NULL'}]), + ?line expect(20, tooBig, 0, any), + + %% 4.1.3:3 + gn([[tGenErr1]]), +% ?line expect(40, genErr, 1, [{[tGenErr1], 'NULL'}]), + ?line expect(40, genErr, 1, any), + gn([[tGenErr2]]), +% ?line expect(41, genErr, 1, [{[tGenErr2], 'NULL'}]), + ?line expect(41, genErr, 1, any), + gn([[sysDescr], [tGenErr3]]), +% ?line expect(42, genErr, 2, [{[sysDescr], 'NULL'}, +% {[tGenErr3], 'NULL'}]). + ?line expect(42, genErr, 2, any). + +v1_set_p() -> + %% 4.1.5:1 + s([{[1,3,7,0], i, 4}]), + ?line expect(10, noSuchName, 1, [{[1,3,7,0], 4}]), + s([{[tDescr,0], s, "outside mibview"}]), + ?line expect(11, noSuchName, 1, [{[tDescr,0], "outside mibview"}]), + s([{[tDescr3,0], s, "read-only"}]), + ?line expect(12, noSuchName, 1, [{[tDescr3,0], "read-only"}]), + s([{[tDescr3], s, "noSuchObject"}]), + ?line expect(13, noSuchName, 1, [{[tDescr3], "noSuchObject"}]), + s([{[tDescr3,1], s, "noSuchInstance"}]), + ?line expect(14, noSuchName, 1, [{[tDescr3,1], "noSuchInstance"}]), + s([{[tDescr2,0], s, "inconsistentName"}]), + ?line expect(15, noSuchName, 1, [{[tDescr2,0], "inconsistentName"}]), + + %% 4.1.5:2 + s([{[tDescr2, 0], i, 4}]), + ?line expect(20, badValue, 1, [{[tDescr2, 0], 4}]), + s([{[tDescr2, 0], s, "badValue"}]), + ?line expect(21, badValue, 1, [{[tDescr2, 0], "badValue"}]), + + %% 4.1.5:3 + %% The standard is quite incorrect here. The resp pdu was too big. In + %% the resp pdu, we have the original vbs. In the tooBig pdu we still + %% have to original vbs => the tooBig pdu is too big as well!!! It + %% may not get it to the manager, unless the agent uses 'NULL' instead + %% of the std-like original value. + s([{[tTooBig, 0], s, ?tooBigStr}]), + %% according to std: +% ?line expect(30, tooBig, 0, [{[tTooBig, 0], ?tooBigStr}]), + ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), + + %% 4.1.5:4 + s([{[tDescr2, 0], s, "is_set_ok_fail"}]), + ?line expect(40, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]), + s([{[tDescr2, 0], s, "commit_fail"}]), + ?line expect(41, genErr, 1, [{[tDescr2, 0], "commit_fail"}]). + +%% Req. Test2 +v2_proc() -> + %% According to RFC1905. + %% Template:
: + ?DBG("v2_proc -> entry",[]), + v2_get_p(), + v2_get_next_p(), + v2_get_bulk_p(), + v2_set_p(). + +v2_get_p() -> + %% 4.2.1:2 + ?DBG("v2_get_p -> entry",[]), + g([[test2]]), + ?line expect(10, [{[test2], noSuchObject}]), + g([[tDescr]]), + ?line expect(11, [{[tDescr], noSuchObject}]), + g([[tDescr4,0]]), + ?line expect(12, [{[tDescr4,0], noSuchObject}]), + g([[sysDescr, 0], [tDescr,0]]), % Outside mibview + ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}, + {[tDescr,0], noSuchObject}]), + g([[tTable]]), + ?line expect(14, [{[tTable], noSuchObject}]), + g([[tEntry]]), + ?line expect(15, [{[tEntry], noSuchObject}]), + + %% 4.2.1:3 + g([[tDescr2,0]]), %% instrum ret noSuchName!!! + ?line expect(20, [{[tDescr2,0], noSuchInstance}]), + g([[tDescr3,0]]), + ?line expect(21, [{[tDescr3,0], noSuchInstance}]), + g([[sysDescr,3]]), + ?line expect(22, [{[sysDescr, 3], noSuchInstance}]), + g([[tIndex,1]]), + ?line expect(23, [{[tIndex, 1], noSuchInstance}]), + + %% 4.2.1 - any other error: genErr + g([[tGenErr1, 0]]), + ?line expect(30, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), + g([[tGenErr2, 0]]), + ?line expect(31, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), + g([[sysDescr, 0], [tGenErr3, 0]]), + ?line expect(32, genErr, 2, [{[sysDescr, 0], 'NULL'}, + {[tGenErr3, 0], 'NULL'}]), + + %% 4.2.1 - tooBig + g([[tTooBig, 0]]), + ?line expect(40, tooBig, 0, []). + + +v2_get_next_p() -> + %% 4.2.2:2 + ?DBG("v2_get_next_p -> entry",[]), + gn([[1,3,7,1]]), + ?line expect(10, [{[1,3,7,1], endOfMibView}]), + gn([[sysDescr], [1,3,7,1]]), + ?line expect(11, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}]), + gn([[tCnt2, 1]]), + ?line expect(12, [{[tCnt2,2], 100}]), + gn([[tCnt2, 2]]), + ?line expect(12, [{[tCnt2,2], endOfMibView}]), + + %% 4.2.2 - any other error: genErr + gn([[tGenErr1]]), + ?line expect(20, genErr, 1, [{[tGenErr1], 'NULL'}]), + gn([[tGenErr2]]), + ?line expect(21, genErr, 1, [{[tGenErr2], 'NULL'}]), + gn([[sysDescr], [tGenErr3]]), + ?line expect(22, genErr, 2, [{[sysDescr], 'NULL'}, + {[tGenErr3], 'NULL'}]), + + %% 4.2.2 - tooBig + gn([[tTooBig]]), + ?line expect(20, tooBig, 0, []). + +v2_get_bulk_p() -> + %% 4.2.3 + ?DBG("v2_get_bulk_p -> entry",[]), + gb(1, 1, []), + ?line expect(10, []), + gb(-1, 1, []), + ?line expect(11, []), + gb(-1, -1, []), + ?line expect(12, []), + gb(-1, -1, []), + ?line expect(13, []), + gb(2, 0, [[sysDescr], [1,3,7,1]]), + ?line expect(14, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}]), + gb(1, 2, [[sysDescr], [1,3,7,1]]), + ?line expect(15, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}]), + gb(0, 2, [[sysDescr], [1,3,7,1]]), + ?line expect(16, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}, + {[sysObjectID, 0], [1,2,3]}, + {[1,3,7,1], endOfMibView}]), + + gb(2, 2, [[sysDescr], [1,3,7,1], [sysDescr], [1,3,7,1]]), + ?line expect(17, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}, + {[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}, + {[sysObjectID, 0], [1,2,3]}, + {[1,3,7,1], endOfMibView}]), + + gb(1, 2, [[sysDescr], [sysDescr], [tTooBig]]), + ?line expect(18, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[sysDescr, 0], "Erlang SNMP agent"}]), + + gb(1,12, [[tDescr2], [sysDescr]]), % next one after tDescr2 is tTooBig. + ?line expect(19, []), + + gb(2,2, [[sysDescr], [sysObjectID], [tGenErr1], [sysDescr]]), + ?line expect(20, genErr, 3, [{[sysDescr], 'NULL'}, + {[sysObjectID], 'NULL'}, + {[tGenErr1], 'NULL'}, + {[sysDescr], 'NULL'}]), + gb(0, 2, [[tCnt2, 1]]), + ?line expect(21, [{[tCnt2,2], 100}, + {[tCnt2,2], endOfMibView}]). + + +v2_set_p() -> + %% 4.2.5:1 + ?DBG("v2_set_p -> entry",[]), + s([{[1,3,7,0], i, 4}]), + ?line expect(10, noAccess, 1, [{[1,3,7,0], 4}]), + s([{[tDescr,0], s, "outside mibview"}]), + ?line expect(11, noAccess, 1, [{[tDescr,0], "outside mibview"}]), + + %% 4.2.5:2 + s([{[1,3,6,1,0], s, "noSuchObject"}]), + ?line expect(20, notWritable, 1, [{[1,3,6,1,0], "noSuchObject"}]), + + %% 4.2.5:3 + s([{[tDescr2, 0], i, 4}]), + ?line expect(30, wrongType, 1, [{[tDescr2, 0], 4}]), + s([{[tDescr2, 0], s, "badValue"}]), + ?line expect(31, badValue, 1, [{[tDescr2, 0], "badValue"}]), + + %% 4.2.5:4 + s([{[tStr, 0], s, ""}]), + ?line expect(40, wrongLength, 1, [{[tStr, 0], ""}]), + s([{[tStr, 0], s, "12345"}]), + ?line expect(40, wrongLength, 1, [{[tStr, 0], "12345"}]), + + %% 4.2.5:5 - N/A + + %% 4.2.5:6 + s([{[tInt1, 0], i, 0}]), + ?line expect(60, wrongValue, 1, [{[tInt1, 0], 0}]), + s([{[tInt1, 0], i, 5}]), + ?line expect(61, wrongValue, 1, [{[tInt1, 0], 5}]), + s([{[tInt2, 0], i, 0}]), + ?line expect(62, wrongValue, 1, [{[tInt2, 0], 0}]), + s([{[tInt2, 0], i, 5}]), + ?line expect(63, wrongValue, 1, [{[tInt2, 0], 5}]), + s([{[tInt3, 0], i, 5}]), + ?line expect(64, wrongValue, 1, [{[tInt3, 0], 5}]), + + %% 4.2.5:7 + s([{[tDescrX, 1, 1], s, "noCreation"}]), + ?line expect(70, noCreation, 1, [{[tDescrX, 1, 1], "noCreation"}]), + + %% 4.2.5:8 + s([{[tDescrX, 1, 2], s, "inconsistentName"}]), + ?line expect(80, inconsistentName, 1, + [{[tDescrX, 1, 2], "inconsistentName"}]), + + %% 4.2.5:9 + s([{[tCnt, 1, 2], i, 5}]), + ?line expect(90, notWritable, 1, [{[tCnt, 1, 2], 5}]), + s([{[tDescr3,0], s, "read-only"}]), + ?line expect(90, notWritable, 1, [{[tDescr3,0], "read-only"}]), + + %% 4.2.5:10 + s([{[tDescr2,0], s, "inconsistentValue"}]), + ?line expect(100, inconsistentValue, 1, + [{[tDescr2,0], "inconsistentValue"}]), + + %% 4.2.5:11 + s([{[tDescr2,0], s, "resourceUnavailable"}]), + ?line expect(110, resourceUnavailable, 1, + [{[tDescr2,0],"resourceUnavailable"}]), + + %% 4.2.5:12 + s([{[tDescr2, 0], s, "is_set_ok_fail"}]), + ?line expect(120, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]). + + %% commitFailed and undoFailed is tested by the 'undo' case. + + +%% Req. OLD-SNMPEA-MIB +table_test() -> + io:format("Testing simple get, next and set on communityTable...~n"), +%% {[147,214,36,45], "public", 2, readWrite}. +%% {[147,214,36,45], "standard trap", 2, read}. + Key1c3 = [intCommunityViewIndex,get(mip),is("public")], + Key2c3 = [intCommunityViewIndex,get(mip),is("standard trap")], + Key1c4 = [intCommunityAccess,get(mip),is("public")], + EndKey = [intCommunityEntry,[9],get(mip),is("public")], + gn([[intCommunityEntry]]), + ?line expect(7, [{Key1c3, 2}]), + gn([[intCommunityTable]]), + ?line expect(71, [{Key1c3, 2}]), + gn([[community]]), + ?line expect(72, [{Key1c3, 2}]), + gn([[otpSnmpeaMIB]]), + ?line expect(73, [{Key1c3, 2}]), + gn([[ericsson]]), + ?line expect(74, [{Key1c3, 2}]), + gn([Key1c3]), + ?line expect(8, [{Key2c3, 2}]), + gn([Key2c3]), + ?line expect(9, [{Key1c4, 2}]), + gn([EndKey]), + AgentIp = [intAgentIpAddress,0], + ?line expect(10, [{AgentIp, any}]), + g([Key1c3]), + ?line expect(11, [{Key1c3, 2}]), + g([EndKey]), + ?line ?v1_2(expect(12, noSuchName, 1, any), + expect(12, [{EndKey, noSuchObject}])), + + io:format("Testing row creation/deletion on communityTable...~n"), + NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], + NewKeyc4 = [intCommunityAccess,get(mip),is("test")], + NewKeyc5 = [intCommunityStatus,get(mip),is("test")], + s([{NewKeyc5, ?createAndGo}]), + ?line expect(14, ?v1_2(badValue, inconsistentValue), 1,any), + s([{NewKeyc5, ?createAndGo}, {NewKeyc3, 2}, {NewKeyc4, 2}]), + ?line expect(15, [{NewKeyc5, ?createAndGo},{NewKeyc3, 2}, {NewKeyc4, 2}]), + g([NewKeyc4]), + ?line expect(16, [{NewKeyc4, 2}]), + s([{NewKeyc5, ?destroy}]), + ?line expect(17, [{NewKeyc5, ?destroy}]), + s([{NewKeyc4, 2}]), + ?line expect(18, ?v1_2(noSuchName, inconsistentName), 1,[{NewKeyc4, 2}]), + s([{NewKeyc5, ?createAndWait}]), + ?line expect(19, [{NewKeyc5, ?createAndWait}]), + g([NewKeyc5]), + ?line expect(20, [{NewKeyc5, ?notReady}]), + s([{NewKeyc4, 2}]), + ?line expect(21, [{NewKeyc4, 2}]), + g([NewKeyc5]), + ?line expect(22, [{NewKeyc5, ?notReady}]), + s([{NewKeyc3, 2}]), + ?line expect(23, [{NewKeyc3, 2}]), + g([NewKeyc5]), + ?line expect(24, [{NewKeyc5, ?notInService}]), + s([{NewKeyc5, ?active}]), + ?line expect(25, [{NewKeyc5, ?active}]), + s([{NewKeyc5, ?destroy}]), + ?line expect(26, [{NewKeyc5, ?destroy}]), + s([{NewKeyc3, 3}]), + ?line expect(27, ?v1_2(noSuchName, inconsistentName), 1,[{NewKeyc3, 3}]), + otp_1128(). + +%% Req. system group +simple_standard_test() -> + ?DBG("simple_standard_test -> entry",[]), + gn([[1,1]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3]]), + ?line expect(11, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6]]), + ?line expect(12, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6,1]]), + ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6,1,2]]), + ?line expect(14, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6,1,2,1]]), + ?line expect(15, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6,1,2,1,1]]), + ?line expect(16, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[sysDescr]]), + ?line expect(17, [{[sysDescr,0], "Erlang SNMP agent"}]), + g([[sysDescr,0]]), + ?line expect(2, [{[sysDescr,0], "Erlang SNMP agent"}]), + g([[sysDescr]]), + ?line ?v1_2(expect(3, noSuchName, 1, any), + expect(3, [{[sysDescr], noSuchObject}])), + g([[1,6,7,0]]), + ?line ?v1_2(expect(41, noSuchName, 1, any), + expect(3, [{[1,6,7,0], noSuchObject}])), + gn([[1,13]]), + ?line ?v1_2(expect(4, noSuchName,1, any), + expect(4, [{[1,13], endOfMibView}])), + s([{[sysLocation, 0], "new_value"}]), + ?line expect(5, [{[sysLocation, 0], "new_value"}]), + g([[sysLocation, 0]]), + ?line expect(6, [{[sysLocation, 0], "new_value"}]), + io:format("Testing noSuchName and badValue...~n"), + s([{[sysServices,0], 3}]), + ?line expect(61, ?v1_2(noSuchName, notWritable), 1, any), + s([{[sysLocation, 0], i, 3}]), + ?line expect(62, ?v1_2(badValue, wrongType), 1, any), + ?DBG("simple_standard_test -> done",[]), + ok. + +%% This is run in the agent node +db_notify_client(suite) -> []; +db_notify_client(Config) when list(Config) -> + {SaNode, MgrNode, MibDir} = init_case(Config), + ?DBG("~n\tSaNode: ~p~n\tMgrNode: ~p~n\tMibDir: ~p", + [SaNode,MgrNode,MibDir]), + snmpa_local_db:register_notify_client(self(),?MODULE), + + %% This call (the manager) will issue to set operations, so + %% we expect to receive to notify(insert) calls. + try_test(db_notify_client_test), + + ?DBG("await first notify",[]), + receive + {db_notify_test_reply,insert} -> ?DBG("first notify received",[]),ok + end, + + ?DBG("await second notify",[]), + receive + {db_notify_test_reply,insert} -> ?DBG("second notify received",[]),ok + end, + + snmpa_local_db:unregister_notify_client(self()). + + +%% This is run in the manager node +db_notify_client_test() -> + ?DBG("set first new sysLocation",[]), + s([{[sysLocation, 0], "new_value"}]), + ?line expect(5, [{[sysLocation, 0], "new_value"}]), + + ?DBG("set second new sysLocation",[]), + s([{[sysLocation, 0], "new_value"}]), + ?line expect(5, [{[sysLocation, 0], "new_value"}]). + +notify(Pid,What) -> + ?DBG("notify(~p,~p) -> called",[Pid,What]), + Pid ! {db_notify_test_reply,What}. + + +%% Req: system group, OLD-SNMPEA-MIB, Klas1 +big_test() -> + ?DBG("big_test -> testing simple next/get/set @ master agent...",[]), + simple_standard_test(), + + ?DBG("big_test -> testing simple next/get/set @ subagent...",[]), + gn([[klas1]]), + ?line expect(1, [{[fname,0], ""}]), + g([[fname,0]]), + ?line expect(2, [{[fname,0], ""}]), + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + g([[fname,0]]), + ?line expect(4, [{[fname,0], "test set"}]), + + ?DBG("big_test -> " + "testing next from last instance in master to subagent...",[]), + gn([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(5, [{[fname,0], "test set"}]), + gn([[1,1], + [?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, + {[fname,0], "test set"}]), + s([{[fname,0], s, ""}]), + ?line expect(52, [{[fname,0], ""}]), + + table_test(), + + ?DBG("big_test -> adding one row in subagent table",[]), + _FTab = [friendsEntry], + s([{[friendsEntry, [2, 3]], s, "kompis3"}, + {[friendsEntry, [3, 3]], i, ?createAndGo}]), + ?line expect(6, [{[friendsEntry, [2, 3]], "kompis3"}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + g([[friendsEntry, [2, 3]], + [friendsEntry, [3, 3]]]), + ?line expect(7, [{[friendsEntry, [2, 3]], "kompis3"}, + {[friendsEntry, [3, 3]], ?active}]), + s([{[friendsEntry, [3, 3]], i, ?destroy}]), + ?line expect(8, [{[friendsEntry, [3, 3]], ?destroy}]), + + otp_1131(), + + ?DBG("big_test -> adding two rows in subagent table with special INDEX", + []), + s([{[kompissEntry, [1, 3]], s, "kompis3"}, + {[kompissEntry, [2, 3]], i, ?createAndGo}]), + ?line expect(9, [{[kompissEntry, [1, 3]], "kompis3"}, + {[kompissEntry, [2, 3]], ?createAndGo}]), + g([[kompissEntry, [1, 3]], + [kompissEntry, [2, 3]]]), + ?line expect(10, [{[kompissEntry, [1, 3]], "kompis3"}, + {[kompissEntry, [2, 3]], ?active}]), + gn([[kompissEntry, [1]], + [kompissEntry, [2]]]), + ?line expect(11, [{[kompissEntry, [1, 3]], "kompis3"}, + {[kompissEntry, [2, 3]], ?active}]), + s([{[kompissEntry, [1, 2]], s, "kompis3"}, + {[kompissEntry, [2, 2]], i, ?createAndGo}]), + ?line expect(12, [{[kompissEntry, [1, 2]], "kompis3"}, + {[kompissEntry, [2, 2]], ?createAndGo}]), + gn([[kompissEntry, [1, 1]], + [kompissEntry, [2, 1]]]), + ?line expect(13, [{[kompissEntry, [1, 2]], "kompis3"}, + {[kompissEntry, [2, 2]], ?active}]), + s([{[kompissEntry, [2, 3]], i, ?destroy}]), + ?line expect(14, [{[kompissEntry, [2, 3]], ?destroy}]), + s([{[kompissEntry, [2, 2]], i, ?destroy}]), + ?line expect(15, [{[kompissEntry, [2, 2]], ?destroy}]), + ?DBG("big_test -> done",[]), + ok. + +%% Req. system group, Klas2, OLD-SNMPEA-MIB +big_test_2() -> + p("Testing simple next/get/set @ master agent (2)..."), + simple_standard_test(), + + p("Testing simple next/get/set @ subagent (2)..."), + gn([[klas2]]), + ?line expect(1, [{[fname2,0], ""}]), + g([[fname2,0]]), + ?line expect(2, [{[fname2,0], ""}]), + s([{[fname2,0], s, "test set"}]), + ?line expect(3, [{[fname2,0], "test set"}]), + g([[fname2,0]]), + ?line expect(4, [{[fname2,0], "test set"}]), + + otp_1298(), + + p("Testing next from last object in master to subagent (2)..."), + gn([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(5, [{[fname2,0], "test set"}]), + gn([[1,1], + [?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, + {[fname2,0], "test set"}]), + + table_test(), + + p("Adding one row in subagent table (2)"), + _FTab = [friendsEntry2], + s([{[friendsEntry2, [2, 3]], s, "kompis3"}, + {[friendsEntry2, [3, 3]], i, ?createAndGo}]), + ?line expect(6, [{[friendsEntry2, [2, 3]], "kompis3"}, + {[friendsEntry2, [3, 3]], ?createAndGo}]), + g([[friendsEntry2, [2, 3]], + [friendsEntry2, [3, 3]]]), + ?line expect(7, [{[friendsEntry2, [2, 3]], "kompis3"}, + {[friendsEntry2, [3, 3]], ?active}]), + s([{[friendsEntry2, [3, 3]], i, ?destroy}]), + ?line expect(8, [{[friendsEntry2, [3, 3]], ?destroy}]), + + p("Adding two rows in subagent table with special INDEX (2)"), + s([{[kompissEntry2, [1, 3]], s, "kompis3"}, + {[kompissEntry2, [2, 3]], i, ?createAndGo}]), + ?line expect(9, [{[kompissEntry2, [1, 3]], "kompis3"}, + {[kompissEntry2, [2, 3]], ?createAndGo}]), + g([[kompissEntry2, [1, 3]], + [kompissEntry2, [2, 3]]]), + ?line expect(10, [{[kompissEntry2, [1, 3]], "kompis3"}, + {[kompissEntry2, [2, 3]], ?active}]), + gn([[kompissEntry2, [1]], + [kompissEntry2, [2]]]), + ?line expect(11, [{[kompissEntry2, [1, 3]], "kompis3"}, + {[kompissEntry2, [2, 3]], ?active}]), + s([{[kompissEntry2, [1, 2]], s, "kompis3"}, + {[kompissEntry2, [2, 2]], i, ?createAndGo}]), + ?line expect(12, [{[kompissEntry2, [1, 2]], "kompis3"}, + {[kompissEntry2, [2, 2]], ?createAndGo}]), + gn([[kompissEntry2, [1, 1]], + [kompissEntry2, [2, 1]]]), + ?line expect(13, [{[kompissEntry2, [1, 2]], "kompis3"}, + {[kompissEntry2, [2, 2]], ?active}]), + s([{[kompissEntry2, [2, 3]], i, ?destroy}]), + ?line expect(14, [{[kompissEntry2, [2, 3]], ?destroy}]), + s([{[kompissEntry2, [2, 2]], i, ?destroy}]), + ?line expect(15, [{[kompissEntry2, [2, 2]], ?destroy}]), + ok. + +%% Req. Test1 +multi_threaded_test() -> + p("Testing multi threaded agent..."), + g([[multiStr,0]]), + Pid = get_multi_pid(), + g([[sysUpTime,0]]), + ?line expect(1, [{[sysUpTime,0], any}]), + s([{[sysLocation, 0], s, "pelle"}]), + ?line expect(2, [{[sysLocation, 0], "pelle"}]), + Pid ! continue, + ?line expect(3, [{[multiStr,0], "ok"}]), + + s([{[multiStr, 0], s, "block"}]), + Pid2 = get_multi_pid(), + g([[sysUpTime,0]]), + ?line expect(4, [{[sysUpTime,0], any}]), + g([[multiStr,0]]), + Pid3 = get_multi_pid(), + g([[sysUpTime,0]]), + ?line expect(5, [{[sysUpTime,0], any}]), + s([{[sysLocation, 0], s, "kalle"}]), + Pid3 ! continue, + ?line expect(6, [{[multiStr,0], "ok"}]), + Pid2 ! continue, + ?line expect(7, [{[multiStr,0], "block"}]), + ?line expect(8, [{[sysLocation,0], "kalle"}]). + +%% Req. Test1, TestTrapv2 +mt_trap_test(MA) -> + snmpa:send_trap(MA, testTrapv22, "standard trap"), + ?line expect(1, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + + snmpa:send_trap(MA, mtTrap, "standard trap"), + Pid = get_multi_pid(), + g([[sysUpTime,0]]), + ?line expect(2, [{[sysUpTime,0], any}]), + snmpa:send_trap(MA, testTrapv22, "standard trap"), + ?line expect(3, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + Pid ! continue, + ?line expect(4, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?testTrap ++ [2]}, + {[multiStr,0], "ok"}]). + + +get_multi_pid() -> + get_multi_pid(10). +get_multi_pid(0) -> + ?line ?FAIL(no_global_name); +get_multi_pid(N) -> + sleep(1000), + case global:whereis_name(snmp_multi_tester) of + Pid when pid(Pid) -> Pid; + _ -> get_multi_pid(N-1) + end. + +%% Req. Test1 +types_v2_test() -> + p("Testing v2 types..."), + + s([{[bits1,0], 2#10}]), + ?line expect(1, [{[bits1,0], ?str(2#10)}]), + g([[bits1,0]]), + ?line expect(2, [{[bits1,0], ?str(2#101)}]), + + s([{[bits2,0], 2#11000000110}]), + ?line expect(3, [{[bits2,0], ?str(2#11000000110)}]), + g([[bits2,0]]), + ?line expect(4, [{[bits2,0], ?str(2#11000000110)}]), + + g([[bits3,0]]), + ?line expect(50, genErr, 1, any), + + g([[bits4,0]]), + ?line expect(51, genErr, 1, any), + + s([{[bits1,0], s, [2#10]}]), + ?line expect(6, ?v1_2(badValue, wrongValue), 1, any), + + s([{[bits2,0], 2#11001001101010011}]), + ?line expect(7, ?v1_2(badValue, wrongValue), 1, any). + + +%% Req. Test1 +implied_test(MA) -> + ?LOG("implied_test -> start",[]), + p("Testing IMPLIED..."), + + snmpa:verbosity(MA,trace), + snmpa:verbosity(MA,trace), + + %% Create two rows, check that they are get-nexted in correct order. + Idx1 = "apa", + Idx2 = "qq", + ?DBG("implied_test -> (send) create row 1 '~s' in table 1",[Idx1]), + s([{[testStatus, Idx1], i, ?createAndGo}, {[testDescr, Idx1],s,"row 1"}]), + ?line expect(1, [{[testStatus, Idx1], ?createAndGo}, + {[testDescr, Idx1], "row 1"}]), + ?DBG("implied_test -> (send) create row 2 '~s' in table 1",[Idx2]), + s([{[testStatus, Idx2], i, ?createAndGo}, {[testDescr, Idx2],s,"row 2"}]), + ?line expect(2, [{[testStatus, Idx2], ?createAndGo}, + {[testDescr, Idx2], "row 2"}]), + ?DBG("implied_test -> get-next(testDescr)",[]), + gn([[testDescr]]), + ?line expect(3, [{[testDescr,Idx1], "row 1"}]), + ?DBG("implied_test -> get-next(testDescr) of row 1",[]), + gn([[testDescr,Idx1]]), + ?line expect(4, [{[testDescr,Idx2], "row 2"}]), + + % Delete the rows + ?DBG("implied_test -> (send) delete row 1 '~s' from table 1",[Idx1]), + s([{[testStatus, Idx1], i, ?destroy}]), + ?line expect(5, [{[testStatus, Idx1], ?destroy}]), + ?DBG("implied_test -> (send) delete row 2 '~s' from table 1",[Idx2]), + s([{[testStatus, Idx2], i, ?destroy}]), + ?line expect(6, [{[testStatus, Idx2], ?destroy}]), + + %% Try the same in other table + Idx3 = [1, "apa"], + Idx4 = [1, "qq"], + ?DBG("implied_test -> (send) create row 1 '~s' in table 2",[Idx3]), + s([{[testStatus2, Idx3], i, ?createAndGo}, {[testDescr2,Idx3],s,"row 1"}]), + ?line expect(1, [{[testStatus2, Idx3], ?createAndGo}, + {[testDescr2, Idx3], "row 1"}]), + ?DBG("implied_test -> (send) create row 2 '~s' in table 2",[Idx4]), + s([{[testStatus2, Idx4], i, ?createAndGo}, {[testDescr2,Idx4],s,"row 2"}]), + ?line expect(2, [{[testStatus2, Idx4], ?createAndGo}, + {[testDescr2, Idx4], "row 2"}]), + ?DBG("implied_test -> get-next(testDescr2)",[]), + gn([[testDescr2]]), + ?line expect(3, [{[testDescr2,Idx3], "row 1"}]), + ?DBG("implied_test -> get-next(testDescr2) of row 1",[]), + gn([[testDescr2,Idx3]]), + ?line expect(4, [{[testDescr2,Idx4], "row 2"}]), + + % Delete the rows + ?DBG("implied_test -> (send) delete row 1 '~s' from table 2",[Idx3]), + s([{[testStatus2, Idx3], i, ?destroy}]), + ?line expect(5, [{[testStatus2, Idx3], ?destroy}]), + ?DBG("implied_test -> (send) delete row 2 '~s' from table 2",[Idx4]), + s([{[testStatus2, Idx4], i, ?destroy}]), + ?line expect(6, [{[testStatus2, Idx4], ?destroy}]), + + snmpa:verbosity(MA,log), + + ?LOG("implied_test -> done",[]). + + + +%% Req. Test1 +sparse_table_test() -> + p("Testing sparse table..."), + + %% Create two rows, check that they are get-nexted in correct order. + Idx1 = 1, + Idx2 = 2, + s([{[sparseStatus, Idx1], i, ?createAndGo}, + {[sparseDescr, Idx1], s, "row 1"}]), + ?line expect(1, [{[sparseStatus, Idx1], ?createAndGo}, + {[sparseDescr, Idx1], "row 1"}]), + s([{[sparseStatus, Idx2], i, ?createAndGo}, + {[sparseDescr, Idx2], s, "row 2"}]), + ?line expect(2, [{[sparseStatus, Idx2], ?createAndGo}, + {[sparseDescr, Idx2], "row 2"}]), + ?v1_2(gn([[sparseIndex], [sparseDescr,Idx1], [sparseDescr,Idx2], + [sparseStatus,Idx1], [sparseStatus,Idx2]]), + gb(0,5,[[sparseIndex]])), + ?line expect(3, [{[sparseDescr,Idx1], "row 1"}, + {[sparseDescr,Idx2], "row 2"}, + {[sparseStatus,Idx1], ?active}, + {[sparseStatus,Idx2], ?active}, + {[sparseStr,0], "slut"}]), + % Delete the rows + s([{[sparseStatus, Idx1], i, ?destroy}]), + ?line expect(4, [{[sparseStatus, Idx1], ?destroy}]), + s([{[sparseStatus, Idx2], i, ?destroy}]), + ?line expect(5, [{[sparseStatus, Idx2], ?destroy}]). + + +%% Req. Test1 +cnt_64_test(MA) -> + ?LOG("start cnt64 test (~p)",[MA]), + snmpa:verbosity(MA,trace), + ?LOG("start cnt64 test",[]), + p("Testing Counter64, and at the same time, RowStatus is not last column"), + + ?DBG("get cnt64",[]), + g([[cnt64,0]]), + ?DBG("await response",[]), + ?line ?v1_2(expect(1, noSuchName, 1, any), + expect(1, [{[cnt64,0],18446744073709551615}])), + ?DBG("get-next cnt64",[]), + gn([[cnt64]]), + ?DBG("await response",[]), + ?line ?v1_2(expect(2, [{[cnt64Str,0], "after cnt64"}]), + expect(2, [{[cnt64,0],18446744073709551615}])), + ?DBG("send cntTrap",[]), + snmpa:send_trap(MA,cntTrap,"standard trap",[{sysContact,"pelle"}, + {cnt64, 10}, + {sysLocation, "here"}]), + ?DBG("await response",[]), + ?line ?v1_2(expect(3, trap, [test], 6, 1, [{[sysContact,0], "pelle"}, + {[sysLocation,0], "here"}]), + expect(3, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?testTrap ++ [1]}, + {[sysContact,0], "pelle"}, + {[cnt64,0], 10}, + {[sysLocation,0], "here"}])), + + %% Create two rows, check that they are get-nexted in correct order. + Idx1 = 1, + Idx2 = 2, + ?DBG("create row (cntStatus): ~p",[Idx1]), + s([{[cntStatus, Idx1], i, ?createAndGo}]), + ?DBG("await response",[]), + ?line expect(1, [{[cntStatus, Idx1], ?createAndGo}]), + ?DBG("create row (cntStatus): ~p",[Idx2]), + s([{[cntStatus, Idx2], i, ?createAndGo}]), + ?DBG("await response",[]), + ?line expect(2, [{[cntStatus, Idx2], ?createAndGo}]), + + ?DBG("get-next (cntIndex)",[]), + gn([[cntIndex]]), + ?DBG("await response",[]), + ?line ?v1_2(expect(3, [{[cntStatus,Idx1], ?active}]), + expect(3, [{[cntCnt,Idx1], 0}])), + % Delete the rows + ?DBG("delete row (cntStatus): ~p",[Idx1]), + s([{[cntStatus, Idx1], i, ?destroy}]), + ?DBG("await response",[]), + ?line expect(4, [{[cntStatus, Idx1], ?destroy}]), + ?DBG("delete row (cntStatus): ~p",[Idx2]), + s([{[cntStatus, Idx2], i, ?destroy}]), + ?DBG("await response",[]), + ?line expect(5, [{[cntStatus, Idx2], ?destroy}]), + catch snmpa:verbosity(MA,log), + ?DBG("done",[]), + ok. + +%% Req. Test1 +opaque_test() -> + p("Testing Opaque datatype..."), + g([[opaqueObj,0]]), + ?line expect(1, [{[opaqueObj,0], "opaque-data"}]). + +%% Req. OLD-SNMPEA-MIB +api_test(MaNode) -> + ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, + [intAgentIpAddress]), + ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, + oid_to_name, [OID]), + ?line false = rpc:call(MaNode, snmp, name_to_oid, [intAgentIpAddres]), + ?line false = rpc:call(MaNode, snmp, oid_to_name, + [[1,5,32,3,54,3,3,34,4]]), + ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, + [intViewType, excluded]), + ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, + [intViewType, 2]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, [intViewType, exclude]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [intAgentIpAddress, exclude]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [intAgentIpAddre, exclude]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [intViewType, 3]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddress, 2]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddre, 2]), + ?line {value, active} = rpc:call(MaNode, snmp, + int_to_enum, ['RowStatus', ?active]), + ?line {value, ?destroy} = rpc:call(MaNode, snmp, + enum_to_int, ['RowStatus', destroy]), + ?line false = rpc:call(MaNode, snmp, + enum_to_int, ['RowStatus', xxxdestroy]), + ?line false = rpc:call(MaNode, snmp, + enum_to_int, ['xxRowStatus', destroy]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, ['RowStatus', 25]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, ['xxRowStatus', 1]), + ?line case snmp:date_and_time() of + List when list(List), length(List) == 8 -> ok; + List when list(List), length(List) == 11 -> ok + end. + +%% Req. Klas3 +api_test2() -> + g([[fname3,0]]), + ?line expect(1, [{[fname3,0], "ok"}]), + g([[fname4,0]]), + ?line expect(2, [{[fname4,0], 1}]). + +api_test3() -> + g([[fname3,0]]), + ?line expect(1, [{[fname3,0], "ok"}]). + + +unreg_test() -> + gn([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(1, [{[snmpInPkts, 0], any}]). + +load_test() -> + gn([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(1, [{[fname,0], ""}]). + +%% Req. Klas1 +load_test_sa() -> + gn([[?v1_2(sysServices,sysORLastChange), 0]]), + ?line expect(1, [{[fname,0], any}]). + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_get() -> + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + g([[sysDescr,0], Key1c4, [fname,0],Key1c3, + [sysName,0]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[fname,0], "test set"}, + {Key1c3, 2}, + {[sysName,0], "test"}]), + g([[1,3,7,1], Key1c4, [sysDescr,0], [1,3,7,2], Key1c3, [sysDescr,0]]), + ?line ?v1_2(expect(2, noSuchName, [1,4], any), + expect(2, [{[1,3,7,1], noSuchObject}, + {Key1c4, 2}, + {[sysDescr,0], "Erlang SNMP agent"}, + {[1,3,7,2], noSuchObject}, + {Key1c3, 2}, + {[sysDescr,0], "Erlang SNMP agent"}])). + +%% Req. v1, system group, Klas1, OLD-SNMPEA-MIB, *ej* Klas3. +do_mul_get_err() -> + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + g([[sysDescr,0],Key1c4,[fname,0], Key1c3, [sysName,2]]), + ?line ?v1_2(expect(1, noSuchName, 5, any), + expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[fname,0], "test set"}, + {Key1c3, 2}, + {[sysName,2], noSuchInstance}])), + g([[sysDescr,0],Key1c4,[fname3,0], Key1c3, [sysName,1]]), + ?line ?v1_2(expect(1, noSuchName, [3,5], any), + expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[fname3,0], noSuchObject}, + {Key1c3, 2}, + {[sysName,1], noSuchInstance}])). + + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_next() -> + Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], + Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + gn([[sysDescr], Key1c4s, [fname],Key1c3s,[sysName]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, {[fname,0], "test set"}, + {Key1c3, 2}, {[sysName,0], "test"}]). + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_next_err() -> + Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], + Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + gn([[sysDescr], Key1c4s, [1,3,6,999], [fname],[1,3,90], Key1c3s,[sysName]]), + ?line ?v1_2(expect(1, noSuchName, [3,5], any), + expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[1,3,6,999], endOfMibView}, + {[fname,0], "test set"}, + {[1,3,90], endOfMibView}, + {Key1c3, 2}, + {[sysName,0], "test"}])). + + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_set() -> + p("Adding one row in subagent table, and one in master table"), + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + s([{[friendsEntry, [2, 3]], "kompis3"}, + {NewKeyc3, 2}, + {[sysLocation,0], "new_value"}, + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + ?line expect(1, [{[friendsEntry, [2, 3]], "kompis3"}, + {NewKeyc3, 2}, + {[sysLocation,0], "new_value"}, + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + g([[friendsEntry, [2, 3]], + [sysLocation,0], + [friendsEntry, [3, 3]]]), + ?line expect(2, [{[friendsEntry, [2, 3]], "kompis3"}, + {[sysLocation,0], "new_value"}, + {[friendsEntry, [3, 3]], ?active}]), + g([NewKeyc4]), + ?line expect(3, [{NewKeyc4, 2}]), + s([{[friendsEntry, [3, 3]], ?destroy}, + {NewKeyc5, ?destroy}]), + ?line expect(4, [{[friendsEntry, [3, 3]], ?destroy}, + {NewKeyc5, ?destroy}]). + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_set_err() -> + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + p("Adding one row in subagent table, and one in master table"), + s([{[friendsEntry, [2, 3]], s, "kompis3"}, + {NewKeyc3, 2}, + {[sysUpTime,0], 45}, % sysUpTime (readOnly) + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + ?line expect(1, ?v1_2(noSuchName, notWritable), 3, any), + g([[friendsEntry, [2, 3]]]), + ?line ?v1_2(expect(2, noSuchName, 1, any), + expect(2, [{[friendsEntry, [2,3]], noSuchInstance}])), + g([NewKeyc4]), + ?line ?v1_2(expect(3, noSuchName, 1, any), + expect(3, [{NewKeyc4, noSuchInstance}])). + +%% Req. SA-MIB +sa_mib() -> + g([[sa, [2,0]]]), + ?line expect(1, [{[sa, [2,0]], 3}]), + s([{[sa, [1,0]], s, "sa_test"}]), + ?line expect(2, [{[sa, [1,0]], "sa_test"}]). + +ma_trap1(MA) -> + snmpa:send_trap(MA, testTrap2, "standard trap"), + ?line expect(1, trap, [system], 6, 1, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}]), + snmpa:send_trap(MA, testTrap1, "standard trap"), + ?line expect(2, trap, [1,2,3] , 1, 0, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}]). + +ma_trap2(MA) -> + snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). + +ma_v2_2_v1_trap(MA) -> + snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). + +ma_v2_2_v1_trap2(MA) -> + snmpa:send_trap(MA,linkUp,"standard trap",[{ifIndex, [1], 1}, + {ifAdminStatus, [1], 1}, + {ifOperStatus, [1], 2}]), + ?line expect(3, trap, [1,2,3], 3, 0, [{[ifIndex, 1], 1}, + {[ifAdminStatus, 1], 1}, + {[ifOperStatus, 1], 2}]). + +sa_trap1(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap"), + ?line expect(4, trap, [ericsson], 6, 1, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}]). + +sa_trap2(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), + ?line expect(5, trap, [ericsson], 6, 1, [{[system, [4,0]], + "pelle"}, + {[sa, [1,0]], "sa_test"}]). + +sa_trap3(SA) -> + snmpa:send_trap(SA, saTrap2, "standard trap", + [{intViewSubtree, [4], [1,2,3,4]}]), + ?line expect(6, trap, [ericsson], 6, 2, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}, + {[intViewSubtree,4],[1,2,3,4]}]). + +ma_v2_trap1(MA) -> + ?DBG("ma_v2_traps -> entry with MA = ~p => " + "send standard trap: testTrapv22",[MA]), + snmpa:send_trap(MA, testTrapv22, "standard trap"), + ?line expect(1, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + ?DBG("ma_v2_traps -> send standard trap: testTrapv21",[]), + snmpa:send_trap(MA, testTrapv21, "standard trap"), + ?line expect(2, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?snmp ++ [1]}]). + +ma_v2_trap2(MA) -> + snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}, + {[system, [4,0]], "pelle"}]). + +%% Note: This test case takes a while... actually a couple of minutes. +ma_v2_inform1(MA) -> + ?DBG("ma_v2_inform -> entry with MA = ~p => " + "send notification: testTrapv22",[MA]), + ?line snmpa:send_notification(MA, testTrapv22, no_receiver, "standard inform", []), + ?line expect(1, {inform, true}, + [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + + ?DBG("ma_v2_inform -> send notification: testTrapv22",[]), + snmpa:send_notification(MA, testTrapv22, {tag1, self()}, + "standard inform", []), + ?line expect(1, {inform, true}, + [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + ?DBG("ma_v2_inform -> await targets",[]), + receive + {snmp_targets, tag1, [_]} -> + ok; + {snmp_targets, tag1, Addrs1} -> + ?line ?FAIL({bad_addrs, Addrs1}) + after + 5000 -> + ?ERR("ma_v2_inform1 -> awaiting snmp_targets(tag1) timeout",[]), + ?line ?FAIL(nothing_at_all) + end, + ?DBG("ma_v2_inform -> await notification",[]), + receive + {snmp_notification, tag1, {got_response, _}} -> + ok; + {snmp_notification, tag1, {no_response, _}} -> + ?line ?FAIL(no_response) + after + 20000 -> + ?ERR("ma_v2_inform1 -> " + "awaiting snmp_notification(tag1) timeout",[]), + ?line ?FAIL(nothing_at_all) + end, + + %% + %% -- The rest is possibly erroneous... + %% + + ?DBG("ma_v2_inform -> send notification: testTrapv22",[]), + snmpa:send_notification(MA, testTrapv22, {tag2, self()}, + "standard inform", []), + ?line expect(2, {inform, false}, + [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + ?DBG("ma_v2_inform -> await targets",[]), + receive + {snmp_targets, tag2, [_]} -> + ok; + {snmp_targets, tag2, Addrs2} -> + ?ERR("ma_v2_inform1 -> awaiting snmp_targets(tag2) timeout",[]), + ?line ?FAIL({bad_addrs, Addrs2}) + after + 5000 -> + ?line ?FAIL(nothing_at_all) + end, + ?DBG("ma_v2_inform -> await notification",[]), + receive + {snmp_notification, tag2, {got_response, _}} -> + ?line ?FAIL(got_response); + {snmp_notification, tag2, {no_response, _}} -> + ok + after + 240000 -> + ?ERR("ma_v2_inform1 -> " + "awaiting snmp_notification(tag2) timeout",[]), + ?line ?FAIL(nothing_at_all) + end. + + +ma_v1_2_v2_trap(MA) -> + snmpa:send_trap(MA,linkDown,"standard trap",[{ifIndex, [1], 1}]), + ?line expect(2, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?snmpTraps ++ [3]}, + {[ifIndex, 1], 1}, + {[snmpTrapEnterprise, 0], [1,2,3]}]). + + +ma_v1_2_v2_trap2(MA) -> + snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}, + {[system, [4,0]], "pelle"}, + {[snmpTrapEnterprise, 0], ?system}]). + + +sa_v1_2_v2_trap1(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap"), + ?line expect(4, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, + {[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}, + {[snmpTrapEnterprise, 0], ?ericsson}]). + +sa_v1_2_v2_trap2(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), + ?line expect(4, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, + {[system, [4,0]], "pelle"}, + {[sa, [1,0]], "sa_test"}, + {[snmpTrapEnterprise, 0], ?ericsson}]). + + +sa_v1_2_v2_trap3(SA) -> + snmpa:send_trap(SA, saTrap2, "standard trap", + [{intViewSubtree, [4], [1,2,3,4]}]), + ?line expect(4, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?ericsson ++ [0, 2]}, + {[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}, + {[intViewSubtree,4],[1,2,3,4]}, + {[snmpTrapEnterprise, 0], ?ericsson}]). + + +%% Req. SA-MIB, OLD-SNMPEA-MIB +sa_errs_bad_value() -> + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + s([{NewKeyc3, 2}, + {[sa, [2,0]], 5}, % badValue (i is_set_ok) + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}]), + ?line expect(1, badValue, 2, any), + s([{NewKeyc3, 2}, + {[sa, [2,0]], 6}, % wrongValue (i is_set_ok) + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}]), + ?line expect(1, ?v1_2(badValue, wrongValue), 2, any), + g([NewKeyc4]), + ?line ?v1_2(expect(2, noSuchName, 1, any), + expect(2, [{NewKeyc4, noSuchInstance}])). + +%% Req. SA-MIB, OLD-SNMPEA-MIB +sa_errs_gen_err() -> + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + s([{NewKeyc3, 2},{NewKeyc4, 2}, + {NewKeyc5, ?createAndGo}, {[sa, [3,0]], 5}]), + ?line expect(1, genErr, 4, any), +% The row might have been added; we don't know. +% (as a matter of fact we do - it is added, because the agent +% first sets its own vars, and then th SAs. Lets destroy it. + s([{NewKeyc5, ?destroy}]), + ?line expect(2, [{NewKeyc5, ?destroy}]). + +%% Req. SA-MIB, OLD-SNMPEA-MIB +sa_too_big() -> + g([[sa, [4,0]]]), + ?line expect(1, tooBig). + +%% Req. Klas1, system group, snmp group (v1/v2) +next_across_sa() -> + gn([[sysDescr],[klas1,5]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {[snmpInPkts, 0], any}]). + +%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]). -> noError +%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]). -> {badValue, 2} +%% snmp_test_mgr:s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]). -> {genErr, 1} +%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]). -> {genErr, 1} +%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]). -> {genErr, 1} +%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]). -> {genErr, 2} +%% Req. Klas3, Klas4 +undo_test() -> + s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), + ?line expect(1, [{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), + s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]), + ?line expect(2, ?v1_2(badValue, inconsistentValue), 2, any), + s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]), + ?line expect(3, ?v1_2(genErr, undoFailed), 1, any), + s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]), + ?line expect(4, ?v1_2(genErr, commitFailed), 1, any), +% unfortunatly we don't know if we'll get undoFailed or commitFailed. +% it depends on which order the agent traverses the varbind list. +% s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]), +% ?line expect(5, ?v1_2(genErr, undoFailed), 1, any), + s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]), + ?line expect(6, genErr, 2, any). + +%% Req. Klas3, Klas4 +bad_return() -> + g([[fStatus4,4], + [fName4,4]]), + ?line expect(4, genErr, 2, any), + g([[fStatus4,5], + [fName4,5]]), + ?line expect(5, genErr, 1, any), + g([[fStatus4,6], + [fName4,6]]), + ?line expect(6, genErr, 2, any), + gn([[fStatus4,7], + [fName4,7]]), + ?line expect(7, genErr, 2, any), + gn([[fStatus4,8], + [fName4,8]]), + ?line expect(8, genErr, 1, any), + gn([[fStatus4,9], + [fName4,9]]), + ?line expect(9, genErr, 2, any). + + +%%%----------------------------------------------------------------- +%%% Test the implementation of standard mibs. +%%% We should *at least* try to GET all variables, just to make +%%% sure the instrumentation functions work. +%%% Note that many of the functions in the standard mib is +%%% already tested by the normal tests. +%%%----------------------------------------------------------------- +standard_mibs(suite) -> + [snmp_standard_mib, snmp_community_mib, + snmp_framework_mib, + snmp_target_mib, snmp_notification_mib, + snmp_view_based_acm_mib]. + +standard_mibs_2(suite) -> + [snmpv2_mib_2, snmp_community_mib_2, + snmp_framework_mib_2, + snmp_target_mib_2, snmp_notification_mib_2, + snmp_view_based_acm_mib_2]. + +standard_mibs_3(suite) -> + [snmpv2_mib_3,snmp_framework_mib_3, snmp_mpd_mib_3, + snmp_target_mib_3, snmp_notification_mib_3, + snmp_view_based_acm_mib_3, snmp_user_based_sm_mib_3]. + +%%----------------------------------------------------------------- +%% For this test, the agent is configured for v1. +%% o Test the counters and control objects in SNMP-STANDARD-MIB +%%----------------------------------------------------------------- +snmp_standard_mib(suite) -> []; +snmp_standard_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?DBG("snmp_standard_mib -> std_mib_init", []), + try_test(std_mib_init), + + ?DBG("snmp_standard_mib -> std_mib_a", []), + InBadVsns = try_test(std_mib_a), + put(vsn, v2), + ?DBG("snmp_standard_mib -> std_mib_read", []), + try_test(std_mib_read), + put(vsn, v1), + + ?DBG("snmp_standard_mib -> std_mib_b (~w)", [InBadVsns]), + Bad = try_test(std_mib_b, [InBadVsns]), + ?DBG("snmp_standard_mib -> std_mib_read (community: 'bad community')", []), + try_test(std_mib_read, [], [{community, "bad community"}]), + ?DBG("snmp_standard_mib -> std_mib_write (community: 'public')", []), + try_test(std_mib_write, [], [{community, "public"}]), + ?DBG("snmp_standard_mib -> std_mib_asn_err", []), + try_test(std_mib_asn_err), + ?DBG("snmp_standard_mib -> std_mib_c (~w)", [Bad]), + try_test(std_mib_c, [Bad]), + ?DBG("snmp_standard_mib -> std_mib_a", []), + try_test(standard_mib_a), + + ?DBG("snmp_standard_mib -> std_mib_finish", []), + try_test(std_mib_finish), + ?DBG("snmp_standard_mib -> std_mib_test_finish", []), + try_test(standard_mib_test_finish, [], [{community, "bad community"}]). + +%% Req. SNMP-STANDARD-MIB +standard_mib_a() -> + ?line [OutPkts] = get_req(2, [[snmpOutPkts,0]]), + ?line [OutPkts2] = get_req(3, [[snmpOutPkts,0]]), + ?line OutPkts2 = OutPkts + 1, + %% There are some more counters we could test here, but it's not that + %% important, since they are removed from SNMPv2-MIB. + ok. + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_init() -> + %% disable authentication failure traps. (otherwise w'd get many of + %% them - this is also a test to see that it works). + s([{[snmpEnableAuthenTraps,0], 2}]), + ?line expect(1, [{[snmpEnableAuthenTraps, 0], 2}]). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_finish() -> + %% enable again + s([{[snmpEnableAuthenTraps,0], 1}]), + ?line expect(1, [{[snmpEnableAuthenTraps, 0], 1}]). + +%% Req. SNMP-STANDARD-MIB +standard_mib_test_finish() -> + %% force a authenticationFailure + std_mib_write(), + %% check that we got a trap + ?line expect(2, trap, [1,2,3], 4, 0, []). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_read() -> + ?DBG("std_mib_read -> entry", []), + g([[sysUpTime,0]]), % try a bad ; msg dropped, no reply + ?DBG("std_mib_read -> await timeout (i.e. no reply)", []), + ?line expect(1, timeout). % make sure we don't get a trap! + + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_write() -> + ?DBG("std_mib_write -> entry", []), + s([{[sysLocation, 0], "new_value"}]). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_asn_err() -> + snmp_test_mgr:send_bytes([48,99,67,12,0,0,0,0,0,0,5]). + +%%----------------------------------------------------------------- +%% For this test, the agent is configured for v2 and v3. +%% o Test the counters and control objects in SNMPv2-MIB +%%----------------------------------------------------------------- +snmpv2_mib_2(suite) -> []; +snmpv2_mib_2(Config) when list(Config) -> + ?LOG("snmpv2_mib_2 -> start",[]), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?DBG("snmpv2_mib_2 -> standard mib init",[]), + try_test(std_mib_init), + + ?DBG("snmpv2_mib_2 -> get number of (so far) bad versions",[]), + InBadVsns = try_test(std_mib_a), + + ?DBG("snmpv2_mib_2 -> make a bad version read",[]), + put(vsn, v1), + try_test(std_mib_read), + + ?DBG("snmpv2_mib_2 -> bad version read",[]), + put(vsn, v2), + Bad = try_test(std_mib_b, [InBadVsns]), + + ?DBG("snmpv2_mib_2 -> read with bad community",[]), + try_test(std_mib_read, [], [{community, "bad community"}]), + + ?DBG("snmpv2_mib_2 -> write with public community",[]), + try_test(std_mib_write, [], [{community, "public"}]), + + ?DBG("snmpv2_mib_2 -> asn err",[]), + try_test(std_mib_asn_err), + + ?DBG("snmpv2_mib_2 -> check counters",[]), + try_test(std_mib_c, [Bad]), + + ?DBG("snmpv2_mib_2 -> get som counters",[]), + try_test(snmpv2_mib_a), + + ?DBG("snmpv2_mib_2 -> enable auth traps, and await some",[]), + try_test(std_mib_finish), + + ?DBG("snmpv2_mib_2 -> force auth failure, and await trap, " + "then disable auth traps",[]), + try_test(snmpv2_mib_test_finish, [], [{community, "bad community"}]), + + ?LOG("snmpv2_mib_2 -> done",[]). + +%% Req. SNMPv2-MIB +snmpv2_mib_3(suite) -> []; +snmpv2_mib_3(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + InBadVsns = try_test(std_mib_a), + put(vsn, v1), + try_test(std_mib_read), + put(vsn, v3), + _Bad = try_test(std_mib_b, [InBadVsns]), + try_test(snmpv2_mib_a), + + try_test(std_mib_finish). + +-define(authenticationFailure, [1,3,6,1,6,3,1,1,5,5]). + +%% Req. SNMPv2-MIB +snmpv2_mib_test_finish() -> + %% force a authenticationFailure + ?DBG("ma_v2_inform -> write to std mib",[]), + std_mib_write(), + + %% check that we got a trap + ?DBG("ma_v2_inform -> await trap",[]), + ?line expect(2, v2trap, [{[sysUpTime,0], any}, + {[snmpTrapOID,0], ?authenticationFailure}]), + + %% and the the inform + ?DBG("ma_v2_inform -> await inform",[]), + ?line expect(2, {inform,true}, [{[sysUpTime,0], any}, + {[snmpTrapOID,0],?authenticationFailure}]). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_a() -> + ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), + ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), + ?line InPkts2 = InPkts + 1, + + ?line [InBadVsns] = get_req(4, [[snmpInBadVersions,0]]), + InBadVsns. + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_b(InBadVsns) -> + ?line [InBadVsns2] = get_req(1, [[snmpInBadVersions,0]]), + ?line InBadVsns2 = InBadVsns + 1, + ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), + ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), + ?line InPkts2 = InPkts + 1, + ?line [InBadCommunityNames, InBadCommunityUses, InASNErrs] = + get_req(4, [[snmpInBadCommunityNames,0], + [snmpInBadCommunityUses,0], + [snmpInASNParseErrs, 0]]), + {InBadCommunityNames, InBadCommunityUses, InASNErrs}. + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_c({InBadCommunityNames, InBadCommunityUses, InASNErrs}) -> + ?line [InBadCommunityNames2, InBadCommunityUses2, InASNErrs2] = + get_req(1, [[snmpInBadCommunityNames,0], + [snmpInBadCommunityUses,0], + [snmpInASNParseErrs, 0]]), + ?line InBadCommunityNames2 = InBadCommunityNames + 1, + ?line InBadCommunityUses2 = InBadCommunityUses + 1, + ?line InASNErrs2 = InASNErrs + 1. + +%% Req. SNMPv2-MIB +snmpv2_mib_a() -> + ?line [SetSerial] = get_req(2, [[snmpSetSerialNo,0]]), + s([{[snmpSetSerialNo,0], SetSerial}, {[sysLocation, 0], "val2"}]), + ?line expect(3, [{[snmpSetSerialNo,0], SetSerial}, + {[sysLocation, 0], "val2"}]), + s([{[sysLocation, 0], "val3"}, {[snmpSetSerialNo,0], SetSerial}]), + ?line expect(4, inconsistentValue, 2, + [{[sysLocation, 0], "val3"}, + {[snmpSetSerialNo,0], SetSerial}]), + ?line ["val2"] = get_req(5, [[sysLocation,0]]). + + +%%----------------------------------------------------------------- +%% o Bad community uses/name is tested already +%% in SNMPv2-MIB and STANDARD-MIB. +%% o Test add/deletion of rows. +%%----------------------------------------------------------------- +snmp_community_mib(suite) -> []; +snmp_community_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + try_test(snmp_community_mib), + ?line unload_master("SNMP-COMMUNITY-MIB"). + +snmp_community_mib_2(X) -> snmp_community_mib(X). + +%% Req. SNMP-COMMUNITY-MIB +snmp_community_mib() -> + ?INF("NOT YET IMPLEMENTED", []), + nyi. + +%%----------------------------------------------------------------- +%% o Test engine boots / time +%%----------------------------------------------------------------- +snmp_framework_mib(suite) -> []; +snmp_framework_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + try_test(snmp_framework_mib), + ?line unload_master("SNMP-FRAMEWORK-MIB"). + +snmp_framework_mib_2(X) -> snmp_framework_mib(X). + +snmp_framework_mib_3(suite) -> []; +snmp_framework_mib_3(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + try_test(snmp_framework_mib). + + +%% Req. SNMP-FRAMEWORK-MIB +snmp_framework_mib() -> + ?line ["agentEngine"] = get_req(1, [[snmpEngineID,0]]), + ?line [EngineTime] = get_req(2, [[snmpEngineTime,0]]), + sleep(5000), + ?line [EngineTime2] = get_req(3, [[snmpEngineTime,0]]), + if + EngineTime+7 < EngineTime2 -> + ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); + EngineTime+4 > EngineTime2 -> + ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); + true -> ok + end, + ?line case get_req(4, [[snmpEngineBoots,0]]) of + [Boots] when integer(Boots) -> ok; + Else -> ?FAIL(Else) + end, + ok. + +%%----------------------------------------------------------------- +%% o Test the counters +%%----------------------------------------------------------------- +snmp_mpd_mib_3(suite) -> []; +snmp_mpd_mib_3(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + UnknownPDUHs = try_test(snmp_mpd_mib_a), + try_test(snmp_mpd_mib_b, [], [{context_engine_id, "bad engine"}]), + try_test(snmp_mpd_mib_c, [UnknownPDUHs]). + + +%% Req. SNMP-MPD-MIB +snmp_mpd_mib_a() -> + ?line [UnknownSecs, InvalidMsgs] = + get_req(1, [[snmpUnknownSecurityModels,0], + [snmpInvalidMsgs,0]]), + Pdu = #pdu{type = 'get-request', + request_id = 23, + error_status = noError, + error_index = 0, + varbinds = []}, + SPdu = #scopedPdu{contextEngineID = "agentEngine", + contextName = "", + data = Pdu}, + ?line SPDUBytes = snmp_pdus:enc_scoped_pdu(SPdu), + V3Hdr1 = #v3_hdr{msgID = 21, + msgMaxSize = 484, + msgFlags = [7], + msgSecurityModel = 23, % bad sec model + msgSecurityParameters = []}, + V3Hdr2 = #v3_hdr{msgID = 21, + msgMaxSize = 484, + msgFlags = [6], % bad flag combination + msgSecurityModel = 3, + msgSecurityParameters = []}, + Message1 = #message{version = 'version-3', vsn_hdr = V3Hdr1, + data = SPDUBytes}, + Message2 = #message{version = 'version-3', vsn_hdr = V3Hdr2, + data = SPDUBytes}, + ?line MsgBytes1 = snmp_pdus:enc_message_only(Message1), + ?line MsgBytes2 = snmp_pdus:enc_message_only(Message2), + snmp_test_mgr:send_bytes(MsgBytes1), + snmp_test_mgr:send_bytes(MsgBytes2), + + ?line [UnknownSecs2, InvalidMsgs2, UnknownPDUHs] = + get_req(1, [[snmpUnknownSecurityModels,0], + [snmpInvalidMsgs,0], + [snmpUnknownPDUHandlers, 0]]), + ?line UnknownSecs2 = UnknownSecs + 1, + ?line InvalidMsgs2 = InvalidMsgs + 1, + UnknownPDUHs. + +-define(snmpUnknownPDUHandlers_instance, [1,3,6,1,6,3,11,2,1,3,0]). +snmp_mpd_mib_b() -> + g([[sysUpTime,0]]), + ?line expect(1, report, [{?snmpUnknownPDUHandlers_instance, any}]). + + +snmp_mpd_mib_c(UnknownPDUHs) -> + ?line [UnknownPDUHs2] = get_req(1, [[snmpUnknownPDUHandlers, 0]]), + ?line UnknownPDUHs2 = UnknownPDUHs + 1. + + +snmp_target_mib(suite) -> []; +snmp_target_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-TARGET-MIB"), + try_test(snmp_target_mib), + ?line unload_master("SNMP-TARGET-MIB"). + +snmp_target_mib_2(X) -> snmp_target_mib(X). + +snmp_target_mib_3(X) -> snmp_target_mib(X). + +snmp_target_mib() -> + ?INF("NOT YET IMPLEMENTED", []), + nyi. + +snmp_notification_mib(suite) -> []; +snmp_notification_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + try_test(snmp_notification_mib), + ?line unload_master("SNMP-NOTIFICATION-MIB"). + +snmp_notification_mib_2(X) -> snmp_notification_mib(X). + +snmp_notification_mib_3(X) -> snmp_notification_mib(X). + +snmp_notification_mib() -> + ?INF("NOT YET IMPLEMENTED", []), + nyi. + +%%----------------------------------------------------------------- +%% o add/delete views and try them +%% o try boundaries +%%----------------------------------------------------------------- +snmp_view_based_acm_mib(suite) -> []; +snmp_view_based_acm_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + ?line load_master("Test2"), + snmp_view_based_acm_mib(), + ?line unload_master("Test2"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). + +snmp_view_based_acm_mib_2(X) -> snmp_view_based_acm_mib(X). + +snmp_view_based_acm_mib_3(X) -> snmp_view_based_acm_mib(X). + +snmp_view_based_acm_mib() -> + snmpa:verbosity(net_if,trace), + snmpa:verbosity(master_agent,trace), + ?LOG("start snmp_view_based_acm_mib test",[]), + %% The user "no-rights" is present in USM, and is mapped to security + %% name 'no-rights", which is not present in VACM. + %% So, we'll add rights for it, try them and delete them. + %% We'll give "no-rights" write access to tDescr.0 and read access + %% to tDescr2.0 + %% These are the options we'll use to the mgr + Opts = [{user, "no-rights"}, {community, "no-rights"}], + %% Find the valid secmodel, and one invalid secmodel. + {SecMod, InvSecMod} = + case get(vsn) of + v1 -> {?SEC_V1, ?SEC_V2C}; + v2 -> {?SEC_V2C, ?SEC_USM}; + v3 -> {?SEC_USM, ?SEC_V1} + end, + ?DBG("assign rights for 'no-rights'",[]), + ?line try_test(use_no_rights, [], Opts), + + %% Now, add a mapping from "no-rights" -> "no-rights-group" + GRow1Status = [vacmSecurityToGroupStatus,[SecMod, 9,"no-rights"]], + GRow1 = + [{[vacmGroupName, [SecMod, 9,"no-rights"]], "no-rights-group"}, + {GRow1Status, ?createAndGo}], + ?DBG("set '~p'",[GRow1]), + ?line try_test(do_set, [GRow1]), + + ?DBG("assign rights for 'no-rights'",[]), + ?line try_test(use_no_rights, [], Opts), + + %% Create a mapping for another sec model, and make sure it dosn't + %% give us access + GRow2Status = [vacmSecurityToGroupStatus,[InvSecMod, 9,"no-rights"]], + GRow2 = [{[vacmGroupName, [InvSecMod, 9, "no-rights"]], "initial"}, + {GRow2Status, ?createAndGo}], + + ?DBG("set '~p'",[GRow2]), + ?line try_test(do_set, [GRow2]), + + ?DBG("assign rights for 'no-rights'",[]), + ?line try_test(use_no_rights, [], Opts), + + %% Delete that row + ?line try_test(del_row, [GRow2Status]), + + RVName = "rv_name", + WVName = "wv_name", + + %% Access row + ARow1Idx = [15 | "no-rights-group"] ++ [0, ?SEC_ANY, 1], + ARow1Status = [vacmAccessStatus, ARow1Idx], + ARow1 = [{[vacmAccessContextMatch, ARow1Idx], 1}, + {[vacmAccessReadViewName, ARow1Idx], RVName}, + {[vacmAccessWriteViewName, ARow1Idx], WVName}, + {ARow1Status, ?createAndGo}], + + %% This access row would give acces, if InvSecMod was valid. + ARow2Idx = [15 | "no-rights-group"] ++ [0, InvSecMod, 1], + ARow2Status = [vacmAccessStatus, ARow2Idx], + ARow2 = [{[vacmAccessContextMatch, ARow2Idx], 1}, + {[vacmAccessReadViewName, ARow2Idx], "internet"}, + {[vacmAccessWriteViewName, ARow2Idx], "internet"}, + {ARow2Status, ?createAndGo}], + + ?line try_test(do_set, [ARow2]), + + ?line try_test(use_no_rights, [], Opts), + + %% Delete that row + ?line try_test(del_row, [ARow2Status]), + + + %% Add valid row + ?line try_test(do_set, [ARow1]), + + ?line try_test(use_no_rights, [], Opts), + + %% Create the view family + VRow1Idx = mk_ln(RVName) ++ mk_ln(?xDescr), % object access + VRow2Idx = mk_ln(RVName) ++ mk_ln(?xDescr2 ++ [0]), % instance access + VRow3Idx = mk_ln(WVName) ++ mk_ln(?xDescr), % object access + VRow4Idx = mk_ln(WVName) ++ mk_ln(?xDescr ++ [0]), % instance access + VRow1Status = [vacmViewTreeFamilyStatus, VRow1Idx], + VRow2Status = [vacmViewTreeFamilyStatus, VRow2Idx], + VRow3Status = [vacmViewTreeFamilyStatus, VRow3Idx], + VRow4Status = [vacmViewTreeFamilyStatus, VRow4Idx], + + ?line try_test(add_row, [VRow1Status]), + ?line try_test(add_row, [VRow2Status]), + ?line try_test(add_row, [VRow3Status]), + + %% We're supposed to have access now... + ?line try_test(use_rights, [], Opts), + + %% Change Row3 to Row4 + ?line try_test(del_row, [VRow3Status]), + ?line try_test(add_row, [VRow4Status]), + + %% We should still have access... + ?line try_test(use_rights, [], Opts), + + %% Delete rows + ?line try_test(del_row, [GRow1Status]), + + ?line try_test(use_no_rights, [], Opts), + + %% Delete rest of rows + ?line try_test(del_row, [ARow1Status]), + ?line try_test(del_row, [VRow1Status]), + ?line try_test(del_row, [VRow2Status]), + ?line try_test(del_row, [VRow4Status]), + + ?line try_test(use_no_rights, [], Opts), + snmpa:verbosity(master_agent,log). + +do_set(Row) -> + s(Row), + expect(1, Row). + +add_row(RowStatus) -> + s([{RowStatus, ?createAndGo}]), + expect(1, [{RowStatus, ?createAndGo}]). + +del_row(RowStatus) -> + s([{RowStatus, ?destroy}]), + expect(1, [{RowStatus, ?destroy}]). + + + +use_no_rights() -> + g([[xDescr,0]]), + ?v1_2_3(expect(11, noSuchName, 1, any), + expect(12, [{[xDescr,0], noSuchObject}]), + expect(13, authorizationError, 1, any)), + g([[xDescr2,0]]), + ?v1_2_3(expect(21, noSuchName, 1, any), + expect(22, [{[xDescr2,0], noSuchObject}]), + expect(23, authorizationError, 1, any)), + gn([[xDescr]]), + ?v1_2_3(expect(31, noSuchName, 1, any), + expect(32, [{[xDescr], endOfMibView}]), + expect(33, authorizationError, 1, any)), + s([{[xDescr,0], "tryit"}]), + ?v1_2_3(expect(41, noSuchName, 1, any), + expect(42, noAccess, 1, any), + expect(43, authorizationError, 1, any)). + + +use_rights() -> + g([[xDescr,0]]), + expect(1, [{[xDescr,0], any}]), + g([[xDescr2,0]]), + expect(2, [{[xDescr2,0], any}]), + s([{[xDescr,0], "tryit"}]), + expect(3, noError, 0, any), + g([[xDescr,0]]), + expect(4, [{[xDescr,0], "tryit"}]). + +mk_ln(X) -> + [length(X) | X]. + +%%----------------------------------------------------------------- +%% o add/delete users and try them +%% o test all secLevels +%% o test all combinations of protocols +%% o try bad ops; check counters +%%----------------------------------------------------------------- +snmp_user_based_sm_mib_3(suite) -> []; +snmp_user_based_sm_mib_3(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + _AgentDir = ?config(agent_dir, Config), + ?line load_master_std("SNMP-USER-BASED-SM-MIB"), + + %% The newUser used here already has VACM access. + + %% Add a new user in the simplest way; just createAndGo + try_test(v3_sync, [[{usm_add_user1, []}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + %% Try to use the new user + ?line load_master("Test2"), + try_test(v3_sync, [[{usm_use_user, []}]], + [{sec_level, authPriv}, {user, "newUser"}]), + ?line unload_master("Test2"), + + ShaKey1 = snmp:passwd2localized_key(sha, "new sha password", "agentEngine"), + DesKey1 = lists:sublist(ShaKey1, 16), + + %% Change the new user's keys - 1 + try_test(v3_sync, [[{usm_key_change1, [ShaKey1, DesKey1]}]], + [{sec_level, authPriv}, {user, "newUser"}]), + + %% Try to use the new keys + MgrDir = ?config(mgr_dir, Config), + ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), + ?line load_master("Test2"), + try_test(v3_sync, [[{usm_use_user, []}]], + [{sec_level, authPriv}, {user, "newUser"}]), + ?line unload_master("Test2"), + + ShaKey2 = snmp:passwd2localized_key(sha, "newer password", "agentEngine"), + DesKey2 = lists:sublist(ShaKey2, 16), + + %% Change the new user's keys - 2 + ?line try_test(v3_sync, + [[{usm_key_change2, [ShaKey1, DesKey1, ShaKey2, DesKey2]}]], + [{sec_level, authPriv}, {user, "newUser"}]), + + %% Try to use the new keys + reset_usm_mgr(MgrDir), + ?line rewrite_usm_mgr(MgrDir, ShaKey2, DesKey2), + ?line load_master("Test2"), + ?line try_test(v3_sync, [[{usm_use_user, []}]], + [{sec_level, authPriv}, {user, "newUser"}]), + ?line unload_master("Test2"), + reset_usm_mgr(MgrDir), + + %% Change the new user's keys - 3 + ?line try_test(v3_sync, + [[{usm_key_change3, [ShaKey2, DesKey2, ShaKey1, DesKey1]}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + %% Try to use the new keys + ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), + ?line load_master("Test2"), + try_test(v3_sync, [[{usm_use_user, []}]], + [{sec_level, authPriv}, {user, "newUser"}]), + ?line unload_master("Test2"), + reset_usm_mgr(MgrDir), + + %% Try some read requests + ?line try_test(v3_sync, [[{usm_read, []}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + %% Delete the new user + ?line try_test(v3_sync, [[{usm_del_user, []}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + %% Try some bad requests + ?line try_test(v3_sync, [[{usm_bad, []}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + ?line unload_master("SNMP-USER-BASED-SM-MIB"). + +-define(usmUserSecurityName, [1,3,6,1,6,3,15,1,2,2,1,3]). + +usm_add_user1() -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + RowPointer = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], + Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer}, + {[usmUserStatus, NewRowIndex], ?createAndGo}], + ?line s(Vbs1), + ?line expect(1, Vbs1), + ok. + +usm_use_user() -> + v2_proc(). + + +%% Change own public keys +usm_key_change1(ShaKey, DesKey) -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + "passwd_shaxxxxxxxxxx", + ShaKey), + DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + "passwd_desxxxxxx", + DesKey), + Vbs1 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, + {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], + s(Vbs1), + ?line expect(1, Vbs1). + +%% Change own private keys +usm_key_change2(OldShaKey, OldDesKey, ShaKey, DesKey) -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + OldShaKey, + ShaKey), + DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + OldDesKey, + DesKey), + Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}, + {[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], + s(Vbs1), + ?line expect(1, Vbs1). + +%% Change other's public keys +usm_key_change3(OldShaKey, OldDesKey, ShaKey, DesKey) -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + OldShaKey, + ShaKey), + DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + OldDesKey, + DesKey), + Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}], + s(Vbs1), + ?line expect(1, noAccess, 1, any), + Vbs2 = [{[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], + s(Vbs2), + ?line expect(2, noAccess, 1, any), + + + Vbs3 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, + {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], + s(Vbs3), + ?line expect(1, Vbs3). + +usm_read() -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + ?line g([[usmUserSecurityName, NewRowIndex], + [usmUserCloneFrom, NewRowIndex], + [usmUserAuthKeyChange, NewRowIndex], + [usmUserOwnAuthKeyChange, NewRowIndex], + [usmUserPrivKeyChange, NewRowIndex], + [usmUserOwnPrivKeyChange, NewRowIndex]]), + ?line expect(1, + [{[usmUserSecurityName, NewRowIndex], "newUser"}, + {[usmUserCloneFrom, NewRowIndex], [0,0]}, + {[usmUserAuthKeyChange, NewRowIndex], ""}, + {[usmUserOwnAuthKeyChange, NewRowIndex], ""}, + {[usmUserPrivKeyChange, NewRowIndex], ""}, + {[usmUserOwnPrivKeyChange, NewRowIndex], ""}]), + ok. + + + +usm_del_user() -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + Vbs1 = [{[usmUserStatus, NewRowIndex], ?destroy}], + ?line s(Vbs1), + ?line expect(1, Vbs1), + ok. + +-define(usmUserCloneFrom, [1,3,6,1,6,3,15,1,2,2,1,4]). + +-define(usmNoAuthProtocol, [1,3,6,1,6,3,10,1,1,1]). + +-define(usmHMACMD5AuthProtocol, [1,3,6,1,6,3,10,1,1,2]). + +-define(usmHMACSHAAuthProtocol, [1,3,6,1,6,3,10,1,1,3]). + +-define(usmNoPrivProtocol, [1,3,6,1,6,3,10,1,2,1]). + +-define(usmDESPrivProtocol, [1,3,6,1,6,3,10,1,2,2]). + +usm_bad() -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + RowPointer1 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDOS"], + Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer1}, + {[usmUserStatus, NewRowIndex], ?createAndGo}], + ?line s(Vbs1), + ?line expect(1, inconsistentName, 1, any), + + RowPointer2 = ?usmUserCloneFrom ++ [11|"agentEngine"] ++ [7|"privDES"], + Vbs2 = [{[usmUserCloneFrom, NewRowIndex], RowPointer2}, + {[usmUserStatus, NewRowIndex], ?createAndGo}], + ?line s(Vbs2), + ?line expect(2, wrongValue, 1, any), + + RowPointer3 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], + Vbs3 = [{[usmUserCloneFrom, NewRowIndex], RowPointer3}, + {[usmUserStatus, NewRowIndex], ?createAndGo}], + ?line s(Vbs3), + ?line expect(3, Vbs3), + ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmNoAuthProtocol}]), + ?line expect(4, inconsistentValue, 1, any), + ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmHMACMD5AuthProtocol}]), + ?line expect(5, inconsistentValue, 1, any), + ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmDESPrivProtocol}]), + ?line expect(6, wrongValue, 1, any), + ?line s([{[usmUserPrivProtocol, NewRowIndex], ?usmHMACSHAAuthProtocol}]), + ?line expect(7, wrongValue, 1, any), + + Vbs4 = [{[usmUserStatus, NewRowIndex], ?destroy}], + ?line s(Vbs4), + ?line expect(1, Vbs4), + + ok. + + +%%----------------------------------------------------------------- +%% Loop through entire MIB, to make sure that all instrum. funcs +%% works. +%% Load all std mibs that are not loaded by default. +%%----------------------------------------------------------------- +loop_mib(suite) -> []; +loop_mib(Config) when list(Config) -> + ?LOG("loop_mib -> initiate case",[]), + %% snmpa:verbosity(master_agent,debug), + %% snmpa:verbosity(mib_server,info), + {SaNode, MgrNode, MibDir} = init_case(Config), + ?DBG("loop_mib -> ~n" + "\tSaNode: ~p~n" + "\tMgrNode: ~p~n" + "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), + ?DBG("loop_mib -> load mib SNMP-COMMUNITY-MIB",[]), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?DBG("loop_mib -> load mib SNMP-MPD-MIB",[]), + ?line load_master_std("SNMP-MPD-MIB"), + ?DBG("loop_mib -> load mib SNMP-TARGET-MIB",[]), + ?line load_master_std("SNMP-TARGET-MIB"), + ?DBG("loop_mib -> load mib SNMP-NOTIFICATION-MIB",[]), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?DBG("loop_mib -> load mib SNMP-FRAMEWORK-MIB",[]), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?DBG("loop_mib -> load mib SNMP-VIEW-BASED-ACM-MIB",[]), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + ?DBG("loop_mib -> try",[]), + try_test(loop_mib_1), + ?DBG("loop_mib -> unload mib SNMP-COMMUNITY-MIB",[]), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?DBG("loop_mib -> unload mib SNMP-MPD-MIB",[]), + ?line unload_master("SNMP-MPD-MIB"), + ?DBG("loop_mib -> unload mib SNMP-TARGET-MIB",[]), + ?line unload_master("SNMP-TARGET-MIB"), + ?DBG("loop_mib -> unload mib SNMP-NOTIFICATION-MIB",[]), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?DBG("loop_mib -> unload mib SNMP-FRAMEWORK-MIB",[]), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?DBG("loop_mib -> unload mib SNMP-VIEW-BASED-ACM-MIB",[]), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + %% snmpa:verbosity(master_agent,log), + %% snmpa:verbosity(mib_server,silence), + ?LOG("loop_mib -> done",[]). + + +loop_mib_2(suite) -> []; +loop_mib_2(Config) when list(Config) -> + ?LOG("loop_mib_2 -> initiate case",[]), + {SaNode, MgrNode, MibDir} = init_case(Config), + ?DBG("loop_mib_2 -> ~n" + "\tSaNode: ~p~n" + "\tMgrNode: ~p~n" + "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), + ?DBG("loop_mib_2 -> load mibs",[]), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-MPD-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + try_test(loop_mib_2), + ?DBG("loop_mib_2 -> unload mibs",[]), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?line unload_master("SNMP-MPD-MIB"), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + ?LOG("loop_mib_2 -> done",[]). + + +loop_mib_3(suite) -> []; +loop_mib_3(Config) when list(Config) -> + ?LOG("loop_mib_3 -> initiate case",[]), + {SaNode, MgrNode, MibDir} = init_case(Config), + ?DBG("loop_mib_3 -> ~n" + "\tSaNode: ~p~n" + "\tMgrNode: ~p~n" + "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), + ?DBG("loop_mib_3 -> load mibs",[]), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + ?line load_master_std("SNMP-USER-BASED-SM-MIB"), + try_test(loop_mib_2), + ?DBG("loop_mib_3 -> unload mibs",[]), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + ?line unload_master("SNMP-USER-BASED-SM-MIB"), + ?LOG("loop_mib_3 -> done",[]). + + +%% Req. As many mibs all possible +loop_mib_1() -> + ?DBG("loop_mib_1 -> entry",[]), + N = loop_it_1([1,1], 0), + io:format(user, "found ~w varibles\n", [N]), + ?line N = if N < 100 -> 100; + true -> N + end. + + +loop_it_1(Oid, N) -> + ?DBG("loop_it_1 -> entry with~n" + "\tOid: ~p~n" + "\tN: ~p",[Oid,N]), + case get_next_req([Oid]) of + #pdu{type='get-response', error_status=noError, error_index=0, + varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> + ?DBG("loop_it_1 -> ~n" + "\tNOid: ~p~n" + "\tValue: ~p",[NOid,Value]), + ?line [Value2] = get_req(1, [NOid]), % must not be same + ?DBG("loop_it_1 -> ~n" + "\tValue2: ~p",[Value2]), + loop_it_1(NOid, N+1); + #pdu{type='get-response', error_status=noSuchName, error_index=1, + varbinds=[_]} -> + ?DBG("loop_it_1 -> done",[]), + N; + + #pdu{type = Type, error_status = Err, error_index = Idx, + varbinds = Vbs} -> + exit({unexpected_pdu, ?LINE, Type, Err, Idx, Vbs}) + end. + +%% Req. As many mibs all possible +loop_mib_2() -> + ?DBG("loop_mib_1 -> entry",[]), + N = loop_it_2([1,1], 0), + io:format(user, "found ~w varibles\n", [N]), + ?line N = if N < 100 -> 100; + true -> N + end. + + +loop_it_2(Oid, N) -> + ?DBG("loop_it_2 -> entry with~n" + "\tOid: ~p~n" + "\tN: ~p",[Oid,N]), + case get_next_req([Oid]) of + #pdu{type='get-response', error_status=noError, error_index=0, + varbinds=[#varbind{oid = NOid, value = endOfMibView}]} -> + ?DBG("loop_it_2 -> ~n" + "\tNOid: ~p",[NOid]), + N; + #pdu{type='get-response', error_status=noError, error_index=0, + varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> + ?DBG("loop_it_2 -> ~n" + "\tNOid: ~p~n" + "\tValue: ~p",[NOid,Value]), + ?line [Value2] = get_req(1, [NOid]), % must not be same + ?DBG("loop_it_2 -> ~n" + "\tValue2: ~p",[Value2]), + loop_it_2(NOid, N+1) + end. + + +%%%----------------------------------------------------------------- +%%% Testing of reported bugs and other tickets. +%%%----------------------------------------------------------------- + +reported_bugs(suite) -> + [otp_1128, otp_1129, otp_1131, otp_1162, + otp_1222, otp_1298, otp_1331, otp_1338, + otp_1342, otp_2776, otp_2979, otp_3187, otp_3725]. + +reported_bugs_2(suite) -> + [otp_1128_2, otp_1129_2, otp_1131_2, otp_1162_2, + otp_1222_2, otp_1298_2, otp_1331_2, otp_1338_2, + otp_1342_2, otp_2776_2, otp_2979_2, otp_3187_2]. + +reported_bugs_3(suite) -> + [otp_1128_3, otp_1129_3, otp_1131_3, otp_1162_3, + otp_1222_3, otp_1298_3, otp_1331_3, otp_1338_3, + otp_1342_3, otp_2776_3, otp_2979_3, otp_3187_3, + otp_3542]. + + +%% These are (ticket) test cases where the initiation has to be done +%% individually. +tickets(suite) -> + [otp_4394]. + +%%----------------------------------------------------------------- +%% Ticket: OTP-1128 +%% Slogan: Bug in handling of createAndWait set-requests. +%%----------------------------------------------------------------- +otp_1128(suite) -> []; +otp_1128(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(otp_1128), + ?line unload_master("OLD-SNMPEA-MIB"). + +otp_1128_2(X) -> otp_1128(X). + +otp_1128_3(X) -> otp_1128(X). + +otp_1128() -> + io:format("Testing bug reported in ticket OTP-1128...~n"), + + NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], + NewKeyc4 = [intCommunityAccess,get(mip),is("test")], + NewKeyc5 = [intCommunityStatus,get(mip),is("test")], + + s([{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), + ?line expect(28, [{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), + g([NewKeyc5]), + ?line expect(29, [{NewKeyc5, ?notReady}]), + s([{NewKeyc5, ?active}, {NewKeyc3, 2}]), + ?line expect(30, [{NewKeyc5, ?active}, {NewKeyc3, 2}]), + g([NewKeyc5]), + ?line expect(31, [{NewKeyc5, ?active}]), + s([{NewKeyc5, ?destroy}]), + ?line expect(32, [{NewKeyc5, ?destroy}]). + +%%----------------------------------------------------------------- +%% Ticket: OTP-1129, OTP-1169 +%% Slogan: snmpa:int_to_enum crashes on bad oids +%%----------------------------------------------------------------- +otp_1129(suite) -> []; +otp_1129(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas3"), + try_test(otp_1129_i, [node()]), + ?line unload_master("Klas3"). + +otp_1129_2(X) -> otp_1129(X). + +otp_1129_3(X) -> otp_1129(X). + +otp_1129_i(MaNode) -> + io:format("Testing bug reported in ticket OTP-1129...~n"), + false = rpc:call(MaNode, snmp, int_to_enum, [iso, 1]), + false = rpc:call(MaNode, snmp, int_to_enum, [isox, 1]). + +%%----------------------------------------------------------------- +%% Ticket: OTP-1131 +%% Slogan: Agent crashes / erlang node halts if RowIndex in a +%% setrequest is of bad type, e.g. an INDEX {INTEGER}, +%% and RowIdenx [3,2]. +%%----------------------------------------------------------------- +otp_1131(suite) -> []; +otp_1131(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas1"), + try_test(otp_1131), + ?line unload_master("Klas1"). + +otp_1131_2(X) -> otp_1131(X). + +otp_1131_3(X) -> otp_1131(X). + +otp_1131() -> + io:format("Testing bug reported in ticket OTP-1131...~n"), + s([{[friendsEntry, [2, 3, 1]], s, "kompis3"}, + {[friendsEntry, [3, 3, 1]], i, ?createAndGo}]), + ?line expect(1, ?v1_2(noSuchName, noCreation), 2, any). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1162 +%% Slogan: snmp_agent can't handle wrongValue from instrum.func +%%----------------------------------------------------------------- +otp_1162(suite) -> []; +otp_1162(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + try_test(otp_1162), + stop_subagent(SA). + +otp_1162_2(X) -> otp_1162(X). + +otp_1162_3(X) -> otp_1162(X). + +otp_1162() -> + s([{[sa, [2,0]], 6}]), % wrongValue (i is_set_ok) + ?line expect(1, ?v1_2(badValue, wrongValue), 1, any). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1222 +%% Slogan: snmp agent crash if faulty index is returned from instrum +%%----------------------------------------------------------------- +otp_1222(suite) -> []; +otp_1222(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas3"), + ?line load_master("Klas4"), + try_test(otp_1222), + ?line unload_master("Klas3"), + ?line unload_master("Klas4"). + +otp_1222_2(X) -> otp_1222(X). + +otp_1222_3(X) -> otp_1222(X). + +otp_1222() -> + io:format("Testing bug reported in ticket OTP-1222...~n"), + s([{[fStatus4,1], 4}, {[fName4,1], 1}]), + ?line expect(1, genErr, 0, any), + s([{[fStatus4,2], 4}, {[fName4,2], 1}]), + ?line expect(2, genErr, 0, any). + +%%----------------------------------------------------------------- +%% Ticket: OTP-1298 +%% Slogan: Negative INTEGER values are treated as positive. +%%----------------------------------------------------------------- +otp_1298(suite) -> []; +otp_1298(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas2"), + try_test(otp_1298), + ?line unload_master("Klas2"). + +otp_1298_2(X) -> otp_1298(X). + +otp_1298_3(X) -> otp_1298(X). + +otp_1298() -> + io:format("Testing bug reported in ticket OTP-1298...~n"), + s([{[fint,0], -1}]), + ?line expect(1298, [{[fint,0], -1}]). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1331 +%% Slogan: snmp_generic should return noError when deleting non-ex row +%%----------------------------------------------------------------- +otp_1331(suite) -> []; +otp_1331(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(otp_1331), + ?line unload_master("OLD-SNMPEA-MIB"). + +otp_1331_2(X) -> otp_1331(X). + +otp_1331_3(X) -> otp_1331(X). + +otp_1331() -> + NewKeyc5 = [intCommunityStatus,[127,32,0,0],is("test")], + s([{NewKeyc5, ?destroy}]), + ?line expect(1, [{NewKeyc5, ?destroy}]). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1338 +%% Slogan: snmp bug in initialisation of default values for mnesia tabs +%%----------------------------------------------------------------- +otp_1338(suite) -> []; +otp_1338(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas2"), + try_test(otp_1338), + ?line unload_master("Klas2"). + +otp_1338_2(X) -> otp_1338(X). + +otp_1338_3(X) -> otp_1338(X). + +otp_1338() -> + s([{[kStatus2, 7], i, ?createAndGo}]), + ?line expect(1, [{[kStatus2, 7], ?createAndGo}]), + g([[kName2, 7]]), + ?line expect(2, [{[kName2, 7], "JJJ"}]). + +%%----------------------------------------------------------------- +%% Ticket: OTP-1342 +%% Slogan: default impl of snmp table can't handle bad index access, +%% Set when INDEX is read-write gets into an infinite loop! +%%----------------------------------------------------------------- +otp_1342(suite) -> []; +otp_1342(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas4"), + try_test(otp_1342), + ?line unload_master("Klas4"). + +otp_1342_2(X) -> otp_1342(X). + +otp_1342_3(X) -> otp_1342(X). + +otp_1342() -> + s([{[fIndex5, 1], i, 1}, + {[fName5, 1], i, 3}, + {[fStatus5, 1], i, ?createAndGo}]), + ?line expect(1, ?v1_2(noSuchName, noCreation), 3, any). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1366 +%% Slogan: snmp traps not sent to all managers +%% Note: NYI! We need a way to tell the test server that we need +%% mgrs on two different machines. +%%----------------------------------------------------------------- +otp_1366(suite) -> []; +otp_1366(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(otp_1366), + ?line unload_master("OLD-SNMPEA-MIB"). + +otp_1366_2(X) -> otp_1366(X). + +otp_1366_3(X) -> otp_1366(X). + +otp_1366() -> + ?INF("NOT YET IMPLEMENTED", []), + 'NYI'. + +%%----------------------------------------------------------------- +%% Ticket: OTP-2776 +%% Slogan: snmp:validate_date_and_time() fails when time is 00:00 +%%----------------------------------------------------------------- +otp_2776(suite) -> []; +otp_2776(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + try_test(otp_2776). + +otp_2776_2(X) -> otp_2776(X). + +otp_2776_3(X) -> otp_2776(X). + +otp_2776() -> + io:format("Testing bug reported in ticket OTP-2776...~n"), + + Dt01_valid = [19,98,9,1,1,0,23,0,43,0,0], + Dt02_valid = [19,98,9,1,0,0,0,0,43,0,0], % This is what is fixed: 00:00 + Dt03_valid = [19,98,2,28,1,0,23,0,43,0,0], + Dt04_invalid = [19,98,2,29,1,0,23,0,43,0,0], + Dt05_valid = [19,96,2,29,1,0,23,0,43,0,0], + Dt06_valid = [20,0,2,29,1,0,23,0,43,0,0], + Dt07_invalid = [19,96,2,30,1,0,23,0,43,0,0], % This is also fixed: 30/2 + Dt08_valid = [19,98,4,30,1,0,23,0,43,0,0], + Dt09_invalid = [19,98,4,31,1,0,23,0,43,0,0], % This is also fixed: 31/4 + Dt10_invalid = [], + Dt11_invalid = [kalle,hobbe], + L = [{ 1, true, Dt01_valid}, + { 2, true, Dt02_valid}, + { 3, true, Dt03_valid}, + { 4, false, Dt04_invalid}, + { 5, true, Dt05_valid}, + { 6, true, Dt06_valid}, + { 7, false, Dt07_invalid}, + { 8, true, Dt08_valid}, + { 9, false, Dt09_invalid}, + {10, false, Dt10_invalid}, + {11, false, Dt11_invalid}], + + ?line ok = validate_dat(L). + + +validate_dat(L) -> validate_dat(L,[]). + +validate_dat([],V) -> + Fun = fun({_,X}) -> case X of + ok -> false; + _ -> true + end + end, + validate_dat1( lists:reverse( lists:filter(Fun,V) ) ); +validate_dat([{Id,E,Dat}|T],V) -> + validate_dat(T,[validate_dat2(Id,E,Dat) | V]). + +validate_dat1([]) -> ok; +validate_dat1(L) -> {error,L}. + +validate_dat2(Id, E, Dat) -> + Res = case {E,snmp:validate_date_and_time(Dat)} of + {E,E} -> ok; + {E,A} -> {E,A} + end, + {Id, Res}. + + +%%----------------------------------------------------------------- +%% Ticket: OTP-2979 +%% Slogan: get-next on more than 1 column in an empty table +%% returns bad response. +%%----------------------------------------------------------------- +otp_2979(suite) -> []; +otp_2979(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Test1"), + ?line init_old(), + try_test(otp_2979), + ?line unload_master("Test1"). + +otp_2979_2(X) -> otp_2979(X). + +otp_2979_3(X) -> otp_2979(X). + +otp_2979() -> + gn([[sparseDescr], [sparseStatus]]), + ?line expect(1, [{[sparseStr,0], "slut"}, + {[sparseStr,0], "slut"}]). + +%%----------------------------------------------------------------- +%% Ticket: OTP-3187 +%% Slogan: get-next on vacmAccessTable for colums > 5 returns +%% endOfTable - should return value. +%%----------------------------------------------------------------- +otp_3187(suite) -> []; +otp_3187(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + otp_3187(), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). + +otp_3187_2(X) -> otp_3187(X). + +otp_3187_3(X) -> otp_3187(X). + +otp_3187() -> + ?line Elements = + snmp_view_based_acm_mib:vacmAccessTable(get_next,[],[4,5,6]), + lists:foreach(fun(E) -> + ?line if E == endOfTable -> + ?FAIL(endOfTable); + true -> ok + end + end, Elements). + +%%----------------------------------------------------------------- +%% Ticket: OTP-3542 +%% Slogan: +%%----------------------------------------------------------------- +otp_3542(suite) -> []; +otp_3542(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + try_test(otp_3542). + +otp_3542() -> + io:format("SNMP v3 discovery...~n"), + ?line Res = snmp_test_mgr:d(), + io:format("SNMP v3 discovery result: ~p~n",[Res]). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-3725 +%% Slogan: Slow response time on snmpa:int_to_enum +%%----------------------------------------------------------------- +otp_3725(suite) -> []; +otp_3725(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(otp_3725_test, [node()]), + ?line unload_master("OLD-SNMPEA-MIB"). + +%% Req. OLD-SNMPEA-MIB +otp_3725_test(MaNode) -> + io:format("Testing feature requested in ticket OTP-3725...~n"), + ?line rpc:call(MaNode,snmpa,verbosity,[symbolic_store,trace]), + ?line Db = rpc:call(MaNode,snmp,get_symbolic_store_db,[]), + ?DBG("otp_3725_test -> Db = ~p",[Db]), + + ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, + [Db, intAgentIpAddress]), + ?DBG("otp_3725_test -> name_to_oid for ~p: ~p",[intAgentIpAddress,OID]), + ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, oid_to_name, + [Db,OID]), + ?DBG("otp_3725_test -> oid_to_name for ~p: ~p",[OID,intAgentIpAddress]), + ?line false = rpc:call(MaNode, snmp, name_to_oid, [Db, intAgentIpAddres]), + ?line false = rpc:call(MaNode, snmp, oid_to_name, + [Db, [1,5,32,3,54,3,3,34,4]]), + ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, + [Db, intViewType, excluded]), + ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, + [Db, intViewType, 2]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, intViewType, exclude]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, intAgentIpAddress, exclude]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, intAgentIpAddre, exclude]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, intViewType, 3]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, + [Db, intAgentIpAddress, 2]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, + [Db, intAgentIpAddre, 2]), + ?line {value, active} = rpc:call(MaNode, snmp, int_to_enum, + [Db, 'RowStatus', ?active]), + ?line {value, ?destroy} = rpc:call(MaNode, snmp, enum_to_int, + [Db, 'RowStatus', destroy]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, 'RowStatus', xxxdestroy]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, 'xxRowStatus', destroy]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'RowStatus', 25]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'xxRowStatus', 1]), + ok. + + +%%----------------------------------------------------------------- +%% Ticket: OTP-4394 +%% Slogan: Target mib tag list check invalid +%%----------------------------------------------------------------- + + +otp_4394(suite) -> {req, [], {conf, + init_otp_4394, + [otp_4394_test], + finish_otp_4394}}. + +init_otp_4394(Config) when list(Config) -> + ?DBG("init_otp_4394 -> entry with" + "~n Config: ~p", [Config]), + ?line AgentDir = ?config(agent_dir, Config), + ?line MgrDir = ?config(mgr_dir, Config), + ?line Ip = ?config(ip, Config), + ?line otp_4394_config(AgentDir, MgrDir, Ip), + MasterAgentVerbosity = {master_agent_verbosity, trace}, + NetIfVerbosity = {net_if_verbosity, trace}, + Opts = [MasterAgentVerbosity,NetIfVerbosity], + [{vsn, v1} | start_v1_agent(Config,Opts)]. + +otp_4394_config(AgentDir, MgrDir, Ip0) -> + ?DBG("otp_4394_config -> entry with" + "~n AgentDir: ~p" + "~n MgrDir: ~p" + "~n Ip0: ~p", [AgentDir, MgrDir, Ip0]), + Vsn = [v1], + Ip = tuple_to_list(Ip0), + ?line snmp_config:write_agent_snmp_files(AgentDir, Vsn, Ip, + ?TRAP_UDP, Ip, 4000, + "OTP-4394 test"), + ?line case update_usm(Vsn, AgentDir) of + true -> + ?line copy_file(filename:join(AgentDir, "usm.conf"), + filename:join(MgrDir, "usm.conf")), + ?line update_usm_mgr(Vsn, MgrDir); + false -> + ?line ok + end, + C1 = {"a", "all-rights", "initial", "", "pc"}, + C2 = {"c", "secret", "secret_name", "", "secret_tag"}, + ?line write_community_conf(AgentDir, [C1, C2]), + ?line update_vacm(Vsn, AgentDir), + Ta1 = {"shelob v1", + [134,138,177,177], 5000, 1500, 3, %% Använd Ip och modda + "pc1", + "target_v1", "", + %% [255,255,255,255,0,0], + [], + 2048}, + Ta2 = {"bifur v1", + [134,138,177,75], 5000, 1500, 3, %% Använd Ip + "pc2", + "target_v1", "", + %% [255,255,255,255,0,0], + [], 2048}, + ?line write_target_addr_conf(AgentDir, [Ta1, Ta2]), + ?line write_target_params_conf(AgentDir, Vsn), + ?line write_notify_conf(AgentDir), + ok. + + + +finish_otp_4394(Config) when list(Config) -> + ?DBG("finish_otp_4394 -> entry", []), + C1 = stop_agent(Config), + delete_files(C1), + erase(mgr_node), + lists:keydelete(vsn, 1, C1). + +otp_4394_test(suite) -> []; +otp_4394_test(Config) -> + ?DBG("otp_4394_test -> entry", []), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + try_test(otp_4394_test1), + ?DBG("otp_4394_test -> done", []), + ok. + +otp_4394_test1() -> + ?DBG("otp_4394_test1 -> entry", []), + gn([[1,1]]), + Res = + case snmp_test_mgr:expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]) of + %% {error, 1, {"?",[]}, {"~w",[timeout]}} + {error, 1, _, {_, [timeout]}} -> + ?DBG("otp_4394_test1 -> expected result: timeout", []), + ok; + Else -> + Else + end, + ?DBG("otp_4394_test1 -> done with: ~p", [Res]), + Res. + + +%%%-------------------------------------------------- +%%% Used to test the standard mib with our +%%% configuration. +%%%-------------------------------------------------- +run(F, A, Opts) -> + M = get(mib_dir), + Dir = get(mgr_dir), + User = snmp_misc:get_option(user, Opts, "all-rights"), + SecLevel = snmp_misc:get_option(sec_level, Opts, noAuthNoPriv), + EngineID = snmp_misc:get_option(engine_id, Opts, "agentEngine"), + CtxEngineID = snmp_misc:get_option(context_engine_id, Opts, EngineID), + Community = snmp_misc:get_option(community, Opts, "all-rights"), + ?DBG("run -> start crypto app",[]), + Crypto = case os:type() of + vxworks -> + no_crypto; + _ -> + ?CRYPTO_START() + end, + ?DBG("run -> Crypto: ~p",[Crypto]), + catch snmp_test_mgr:stop(), % If we had a running mgr from a failed case + StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", + ?DBG("run -> config:~n" + "\tM: ~p~n" + "\tDir: ~p~n" + "\tUser: ~p~n" + "\tSecLevel: ~p~n" + "\tEngineID: ~p~n" + "\tCtxEngineID: ~p~n" + "\tCommunity: ~p~n" + "\tStdM: ~p", + [M,Dir,User,SecLevel,EngineID,CtxEngineID,Community,StdM]), + case snmp_test_mgr:start([%% {agent, snmp_test_lib:hostname()}, + {packet_server_debug,true}, + {debug,true}, + {agent, get(master_host)}, + {agent_udp, 4000}, + {trap_udp, 5000}, + {recbuf,65535}, + quiet, + get(vsn), + {community, Community}, + {user, User}, + {sec_level, SecLevel}, + {engine_id, EngineID}, + {context_engine_id, CtxEngineID}, + {dir, Dir}, + {mibs, mibs(StdM, M)}]) of + {ok, _Pid} -> + Res = apply(?MODULE, F, A), + catch snmp_test_mgr:stop(), + Res; + Err -> + io:format("Error starting manager: ~p\n", [Err]), + catch snmp_test_mgr:stop(), + ?line exit({mgr_start, Err}) + end. + + +mibs(StdMibDir,MibDir) -> + [join(StdMibDir, ?v1_2("STANDARD-MIB.bin", "SNMPv2-MIB.bin")), + join(MibDir, "OLD-SNMPEA-MIB.bin"), + join(StdMibDir, "SNMP-FRAMEWORK-MIB"), + join(StdMibDir, "SNMP-MPD-MIB"), + join(StdMibDir, "SNMP-VIEW-BASED-ACM-MIB"), + join(StdMibDir, "SNMP-USER-BASED-SM-MIB"), + join(StdMibDir, "SNMP-TARGET-MIB"), + join(StdMibDir, "SNMP-NOTIFICATION-MIB"), + join(MibDir, "Klas1.bin"), + join(MibDir, "Klas2.bin"), + join(MibDir, "Klas3.bin"), + join(MibDir, "Klas4.bin"), + join(MibDir, "SA-MIB.bin"), + join(MibDir, "TestTrap.bin"), + join(MibDir, "Test1.bin"), + join(MibDir, "Test2.bin"), + join(MibDir, "TestTrapv2.bin")]. + +join(D,F) -> + filename:join(D,F). + +%% string used in index +is(S) -> [length(S) | S]. + +try_test(Func) -> + call(get(mgr_node), ?MODULE, run, [Func, [], []]). + +try_test(Func, A) -> + call(get(mgr_node), ?MODULE, run, [Func, A, []]). + +try_test(Func, A, Opts) -> + call(get(mgr_node), ?MODULE, run, [Func, A, Opts]). + +call(N,M,F,A) -> + ?DBG("call -> entry with~n" + " N: ~p~n" + " M: ~p~n" + " F: ~p~n" + " A: ~p~n" + " when~n" + " get(): ~p", + [N,M,F,A,get()]), + spawn(N, ?MODULE, wait, [self(),get(),M,F,A]), + receive + {done, {'EXIT', Rn}, Loc} -> + ?DBG("call -> returned ~p",[{done, {'EXIT', Rn}, Loc}]), + put(test_server_loc, Loc), + exit(Rn); + {done, Ret, Zed} -> + ?DBG("call -> returned ~p~n",[{done, Ret, Zed}]), + Ret + end. + +wait(From, Env, M, F, A) -> + ?DBG("wait -> entry with ~n" + "\tFrom: ~p~n" + "\tEnv: ~p",[From,Env]), + lists:foreach(fun({K,V}) -> put(K,V) end, Env), + Rn = (catch apply(M, F, A)), + ?DBG("wait -> Rn: ~n~p", [Rn]), + From ! {done, Rn, get(test_server_loc)}, + exit(Rn). + +expect(A,B) -> ok = snmp_test_mgr:expect(A,B). +expect(A,B,C) -> ok = snmp_test_mgr:expect(A,B,C). +expect(A,B,C,D) -> ok = snmp_test_mgr:expect(A,B,C,D). +expect(A,B,C,D,E,F) -> ok = snmp_test_mgr:expect(A,B,C,D,E,F). + +get_req(Id, Vars) -> + ?DBG("get_req -> entry with~n" + "\tId: ~p~n" + "\tVars: ~p",[Id,Vars]), + g(Vars), + ?DBG("get_req -> await response",[]), + {ok, Val} = snmp_test_mgr:get_response(Id, Vars), + ?DBG("get_req -> response: ~p",[Val]), + Val. + +get_next_req(Vars) -> + ?DBG("get_next_req -> entry with Vars '~p', send request",[Vars]), + gn(Vars), + ?DBG("get_next_req -> await response",[]), + Response = snmp_test_mgr:receive_response(), + ?DBG("get_next_req -> response: ~p",[Response]), + Response. + + + +start_node(Name) -> + ?LOG("start_node -> entry with Name: ~p",[Name]), + M = list_to_atom(?HOSTNAME(node())), + ?DBG("start_node -> M: ~p",[M]), + Pa = filename:dirname(code:which(?MODULE)), + ?DBG("start_node -> Pa: ~p",[Pa]), + + Args = case init:get_argument('CC_TEST') of + {ok, [[]]} -> + " -pa /clearcase/otp/libraries/snmp/ebin "; + {ok, [[Path]]} -> + " -pa " ++ Path; + error -> + "" + end, + %% Do not use start_link!!! (the proc that calls this one is tmp) + ?DBG("start_node -> Args: ~p~n",[Args]), + A = Args ++ " -pa " ++ Pa, + case (catch ?START_NODE(Name, A)) of + {ok, Node} -> + %% Tell the test_server to not clean up things it never started. + ?DBG("start_node -> Node: ~p",[Node]), + {ok, Node}; + Else -> + ?ERR("start_node -> failed with(other): Else: ~p",[Else]), + ?line ?FAIL(Else) + end. + + +stop_node(Node) -> + ?LOG("stop_node -> Node: ~p",[Node]), + rpc:cast(Node, erlang, halt, []). + +p(X) -> + io:format(user, X++"\n", []). + +sleep(X) -> + receive + after + X -> ok + end. + +%%%----------------------------------------------------------------- +%%% Configuration +%%%----------------------------------------------------------------- +config(Vsns, MgrDir, AgentDir, MIp, AIp) -> + ?line snmp_config:write_agent_snmp_files(AgentDir, Vsns, MIp, + ?TRAP_UDP, AIp, 4000, + "test"), + ?line case update_usm(Vsns, AgentDir) of + true -> + ?line copy_file(filename:join(AgentDir, "usm.conf"), + filename:join(MgrDir, "usm.conf")), + ?line update_usm_mgr(Vsns, MgrDir); + false -> + ?line ok + end, + ?line update_community(Vsns, AgentDir), + ?line update_vacm(Vsns, AgentDir), + ?line write_target_addr_conf(AgentDir, MIp, ?TRAP_UDP, Vsns), + ?line write_target_params_conf(AgentDir, Vsns), + ?line write_notify_conf(AgentDir), + ok. + +delete_files(Config) -> + Dir = ?config(agent_dir, Config), + {ok, List} = file:list_dir(Dir), + lists:foreach(fun(FName) -> file:delete(filename:join(Dir, FName)) end, + List). + +update_usm(Vsns, Dir) -> + case lists:member(v3, Vsns) of + true -> + {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),[read,write]), + file:position(Fid, eof), + ok = io:format(Fid, "{\"agentEngine\", \"all-rights\", " + "\"all-rights\", zeroDotZero, " + "usmNoAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"\", \"\"}.\n", []), + ok = io:format(Fid, "{\"agentEngine\", \"no-rights\", " + "\"no-rights\", zeroDotZero, " + "usmNoAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"\", \"\"}.\n", []), + ok = io:format(Fid, "{\"agentEngine\", \"authMD5\", " + "\"authMD5\", zeroDotZero, " + "usmHMACMD5AuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"passwd_md5xxxxxx\", \"\"}.\n", []), + ok = io:format(Fid, "{\"agentEngine\", \"authSHA\", " + "\"authSHA\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"\"}.\n", []), + ok = io:format(Fid, "{\"agentEngine\", \"privDES\", " + "\"privDES\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", + []), + ok = io:format(Fid, "{\"mgrEngine\", \"all-rights\", " + "\"all-rights\", zeroDotZero, " + "usmNoAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"\", \"\"}.\n", []), + ok = io:format(Fid, "{\"mgrEngine\", \"no-rights\", " + "\"no-rights\", zeroDotZero, " + "usmNoAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"\", \"\"}.\n", []), + ok = io:format(Fid, "{\"mgrEngine\", \"authMD5\", " + "\"authMD5\", zeroDotZero, " + "usmHMACMD5AuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"passwd_md5xxxxxx\", \"\"}.\n", []), + ok = io:format(Fid, "{\"mgrEngine\", \"authSHA\", " + "\"authSHA\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"\"}.\n", []), + ok = io:format(Fid, "{\"mgrEngine\", \"privDES\", " + "\"privDES\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", + []), + file:close(Fid), + true; + false -> + false + end. + +update_usm_mgr(Vsns, Dir) -> + case lists:member(v3, Vsns) of + true -> + {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),[read,write]), + file:position(Fid, eof), + ok = io:format(Fid, "{\"agentEngine\", \"newUser\", " + "\"newUser\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", + []), + ok = io:format(Fid, "{\"mgrEngine\", \"newUser\", " + "\"newUser\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", + []), + file:close(Fid), + true; + false -> + false + end. + +rewrite_usm_mgr(Dir, ShaKey, DesKey) -> + ?line ok = file:rename(filename:join(Dir,"usm.conf"), + filename:join(Dir,"usm.old")), + ?line {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),write), + ok = io:format(Fid, "{\"agentEngine\", \"newUser\", " + "\"newUser\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"~s\", \"~s\"}.\n", + [ShaKey, DesKey]), + ok = io:format(Fid, "{\"mgrEngine\", \"newUser\", " + "\"newUser\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"~s\", \"~s\"}.\n", + [ShaKey, DesKey]), + file:close(Fid). + +reset_usm_mgr(Dir) -> + ?line ok = file:rename(filename:join(Dir,"usm.old"), + filename:join(Dir,"usm.conf")). + + +update_community([v3], _Dir) -> ok; +update_community(_, Dir) -> + {ok, Fid} = file:open(filename:join(Dir,"community.conf"),[read,write]), + file:position(Fid, eof), + ok=io:format(Fid,"{\"no-rights\",\"no-rights\",\"no-rights\",\"\",\"\"}.\n", + []), + file:close(Fid). + + +-define(tDescr_instance, [1,3,6,1,2,1,16,1,0]). +update_vacm(_Vsn, Dir) -> + {ok, Fid} = file:open(filename:join(Dir,"vacm.conf"),[read,write]), + file:position(Fid, eof), + ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"authMD5\",\"initial\"}.\n",[]), + ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"authSHA\",\"initial\"}.\n",[]), + ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"privDES\",\"initial\"}.\n",[]), + ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"newUser\",\"initial\"}.\n",[]), + ok = io:format(Fid, "{vacmViewTreeFamily, \"internet\", " + "~w, excluded, null}.\n", [?tDescr_instance]), + file:close(Fid). + + +vacm_ver(v1) -> v1; +vacm_ver(v2) -> v2c; +vacm_ver(v3) -> usm. + + +write_community_conf(Dir, Confs) -> + {ok, Fid} = file:open(filename:join(Dir,"community.conf"),write), + ok = write_community_conf1(Fid, Confs), + file:close(Fid). + +write_community_conf1(_, []) -> + ok; +write_community_conf1(Fid, [{ComIdx, ComName, SecName, CtxName, TransTag}|Confs]) -> + ok = io:format(Fid, "{\"~s\", \"~s\", \"~s\", \"~s\", \"~s\"}.~n", + [ComIdx, ComName, SecName, CtxName, TransTag]), + write_community_conf1(Fid, Confs). + + +write_target_addr_conf(Dir, Confs) -> + {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), + ok = write_target_addr_conf1(Fid, Confs), + file:close(Fid). + + +write_target_addr_conf1(_, []) -> + ok; +write_target_addr_conf1(Fid, + [{Name, Ip, Port, Timeout, Retry, TagList, ParamName, + EngineId, TMask, MaxMsgSz}|Confs]) -> + ok = io:format(Fid, "{\"~s\", ~w, ~w, ~w, ~w, \"~s\", \"~s\", \"~s\", ~w, ~w}.~n", + [Name, Ip, Port, Timeout, Retry, TagList, ParamName, + EngineId, TMask, MaxMsgSz]), + write_target_addr_conf1(Fid, Confs). + +write_target_addr_conf(Dir, ManagerIp, UDP, Vsns) -> + {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), + lists:foreach(fun(Vsn) -> + ok = io:format(Fid, + "{\"~s\", ~w, ~w, 1500, 3, " + "\"std_trap\", \"~s\"}.~n", + [mk_ip(ManagerIp, Vsn), + ManagerIp, UDP, mk_param(Vsn)]), + case Vsn of + v1 -> ok; + v2 -> + ok = io:format(Fid, + "{\"~s.2\",~w,~w,1500,3, " + "\"std_inform\", \"~s\"}.~n", + [mk_ip(ManagerIp, Vsn), + ManagerIp, UDP, + mk_param(Vsn)]); + v3 -> + ok = io:format(Fid, + "{\"~s.3\",~w,~w,1500,3, " + "\"std_inform\", \"~s\", " + "\"mgrEngine\", [], 1024}.~n", + [mk_ip(ManagerIp, Vsn), + ManagerIp, UDP, + mk_param(Vsn)]) + end + end, + Vsns), + file:close(Fid). + +mk_param(v1) -> "target_v1"; +mk_param(v2) -> "target_v2"; +mk_param(v3) -> "target_v3". + +mk_ip([A,B,C,D], Vsn) -> + io_lib:format("~w.~w.~w.~w ~w", [A,B,C,D,Vsn]). + + +rewrite_target_addr_conf(Dir,NewPort) -> + TAFile = filename:join(Dir, "target_addr.conf"), + ?DBG("rewrite_target_addr_conf -> read target file info of address config file",[]), + case file:read_file_info(TAFile) of + {ok, _} -> ok; + {error, R} -> ?ERR("failure reading file info of " + "target address config file: ~p",[R]), + ok + end, + + ?line [TrapAddr|Addrs] = + snmp_conf:read(TAFile,fun(R) -> rewrite_target_addr_conf1(R) end), + + ?DBG("rewrite_target_addr_conf -> TrapAddr: ~p",[TrapAddr]), + + NewAddrs = [rewrite_target_addr_conf2(NewPort,TrapAddr)|Addrs], + + ?DBG("rewrite_target_addr_conf -> NewAddrs: ~p",[NewAddrs]), + + ?line ok = file:rename(filename:join(Dir,"target_addr.conf"), + filename:join(Dir,"target_addr.old")), + ?line {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), + + ?line ok = rewrite_target_addr_conf3(Fid,NewAddrs), + + file:close(Fid). + +rewrite_target_addr_conf1(O) -> + {ok,O}. + +rewrite_target_addr_conf2(NewPort,{Name,Ip,_Port,Timeout,Retry, + "std_trap",EngineId}) -> + ?LOG("rewrite_target_addr_conf2 -> entry with std_trap",[]), + {Name,Ip,NewPort,Timeout,Retry,"std_trap",EngineId}; +rewrite_target_addr_conf2(_NewPort,O) -> + ?LOG("rewrite_target_addr_conf2 -> entry with " + "~n O: ~p",[O]), + O. + + +rewrite_target_addr_conf3(_,[]) -> ok; +rewrite_target_addr_conf3(Fid,[{Name,Ip,Port,Timeout,Retry, + ParamName,EngineId}|T]) -> + ?LOG("rewrite_target_addr_conf3 -> write(1) ~s",[ParamName]), + io:format(Fid, + "{\"~s\", " % Name + "~p, " % Ip + "~p, " % Port + "~p, " % Timeout + "~p, " % Retry + "\"~s\", " % ParamsName + "\"~s\"}.", % EngineId + [Name,Ip,Port,Timeout,Retry,ParamName,EngineId]), + rewrite_target_addr_conf3(Fid,T); +rewrite_target_addr_conf3(Fid,[{Name,Ip,Port,Timeout,Retry,TagList, + ParamName,EngineId,TMask,MMS}|T]) -> + ?LOG("rewrite_target_addr_conf3 -> write(2) ~s",[ParamName]), + io:format(Fid, + "{\"~s\", " % Name + "~p, " % Ip + "~p, " % Port + "~p, " % Timeout + "~p, " % Retry + "\"~s\", " % TagList + "\"~s\", " % ParamsName + "\"~s\"," % EngineId + "~p, " % TMask + "~p}.", % MMS + [Name,Ip,Port,Timeout,Retry,TagList,ParamName, + EngineId,TMask,MMS]), + rewrite_target_addr_conf3(Fid,T). + +reset_target_addr_conf(Dir) -> + ?line ok = file:rename(filename:join(Dir,"target_addr.old"), + filename:join(Dir,"target_addr.conf")). + +write_target_params_conf(Dir, Vsns) -> + {ok, Fid} = file:open(filename:join(Dir,"target_params.conf"),write), + lists:foreach(fun(Vsn) -> + MP = if Vsn == v1 -> v1; + Vsn == v2 -> v2c; + Vsn == v3 -> v3 + end, + SM = if Vsn == v1 -> v1; + Vsn == v2 -> v2c; + Vsn == v3 -> usm + end, + ok = io:format(Fid, "{\"target_~w\", ~w, ~w, " + "\"all-rights\", noAuthNoPriv}.~n", + [Vsn, MP, SM]) + end, + Vsns), + file:close(Fid). + +rewrite_target_params_conf(Dir, SecName, SecLevel) -> + ?line ok = file:rename(filename:join(Dir,"target_params.conf"), + filename:join(Dir,"target_params.old")), + ?line {ok, Fid} = file:open(filename:join(Dir,"target_params.conf"),write), + ?line ok = io:format(Fid, "{\"target_v3\", v3, usm, \"~s\", ~w}.~n", + [SecName, SecLevel]), + file:close(Fid). + +reset_target_params_conf(Dir) -> + ?line ok = file:rename(filename:join(Dir,"target_params.old"), + filename:join(Dir,"target_params.conf")). + +write_notify_conf(Dir) -> + {ok, Fid} = file:open(filename:join(Dir,"notify.conf"),write), + ok = io:format(Fid, "{\"standard trap\", \"std_trap\", trap}.~n", []), + ok = io:format(Fid, "{\"standard inform\", \"std_inform\",inform}.~n", []), + file:close(Fid). + +ver_to_trap_str([v1]) -> "v1"; +ver_to_trap_str([v2]) -> "v2"; +% default is to use the latest snmp version +ver_to_trap_str([v1,v2]) -> "v2". + + + +write_view_conf(Dir) -> + {ok, Fid} = file:open(a(Dir,"view.conf"),write), + ok = io:format(Fid, "{2, [1,3,6], included, null}.~n", []), + ok = io:format(Fid, "{2, ~w, excluded, null}.~n", [?tDescr_instance]), + file:close(Fid). + +a(A,B) -> lists:append(A,B). + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +copy_file(From, To) -> + {ok, Bin} = file:read_file(From), + ok = file:write_file(To, Bin). + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +display_memory_usage() -> + Info = snmpa:info(snmp_master_agent), + TreeSize = lists_key1search(tree_size_bytes, Info), + ProcMem = lists_key1search(process_memory, Info), + MibDbSize = lists_key1search([db_memory,mib], Info), + NodeDbSize = lists_key1search([db_memory,node], Info), + TreeDbSize = lists_key1search([db_memory,tree], Info), + ?INF("Memory usage: " + "~n Tree size: ~p" + "~n Process memory size: ~p" + "~n Mib db size: ~p" + "~n Node db size: ~p" + "~n Tree db size: ~p", + [TreeSize, ProcMem, MibDbSize, NodeDbSize, TreeDbSize]). + +lists_key1search([], Res) -> + Res; +lists_key1search([Key|Keys], List) when atom(Key), list(List) -> + case lists:keysearch(Key, 1, List) of + {value, {Key, Val}} -> + lists_key1search(Keys, Val); + false -> + undefined + end; +lists_key1search(Key, List) when atom(Key) -> + case lists:keysearch(Key, 1, List) of + {value, {Key, Val}} -> + Val; + false -> + undefined + end. + + +regs() -> + lists:sort(registered()). diff --git a/lib/snmp/test/exp/snmp_agent_ms_test.erl b/lib/snmp/test/exp/snmp_agent_ms_test.erl new file mode 100644 index 0000000000..1f34f1c8d1 --- /dev/null +++ b/lib/snmp/test/exp/snmp_agent_ms_test.erl @@ -0,0 +1,5649 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2005-2010. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% + +-module(snmp_agent_ms_test). + +%% TODO +%% * Test fault-tolerance (kill master etc) +%% + +-compile(export_all). + +-define(application, snmp). + +-include_lib("kernel/include/file.hrl"). +-include_lib("test_server/include/test_server.hrl"). +-include("snmp_test_lib.hrl"). +-define(SNMP_USE_V3, true). +-include_lib("snmp/include/snmp_types.hrl"). +%% -include_lib("snmp/include/SNMP-COMMUNITY-MIB.hrl"). +%% -include_lib("snmp/include/SNMP-VIEW-BASED-ACM-MIB.hrl"). +%% -include_lib("snmp/include/SNMP-USER-BASED-SM-MIB.hrl"). + + +-define(klas1, [1,3,6,1,2,1,7]). +-define(klas2, [1,3,6,1,2,1,9]). +-define(klas3, [1,3,6,1,2,1,8,1]). +-define(klas4, [1,3,6,1,2,1,8,4]). +-define(sa, [1,3,6,1,4,1,193,2]). +-define(system, [1,3,6,1,2,1,1]). +-define(snmp, [1,3,6,1,2,1,11]). +-define(snmpTraps, [1,3,6,1,6,3,1,1,5]). +-define(ericsson, [1,3,6,1,4,1,193]). +-define(testTrap, [1,3,6,1,2,1,15,0]). +-define(xDescr, [1,3,6,1,2,1,17,1]). +-define(xDescr2, [1,3,6,1,2,1,17,2]). + +-define(active, 1). +-define(notInService, 2). +-define(notReady, 3). +-define(createAndGo, 4). +-define(createAndWait, 5). +-define(destroy, 6). + +-define(TRAP_UDP, 5000). + +-define(tooBigStr, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"). + +-define(str(X), snmp_pdus:bits_to_str(X)). + +-define(break(), begin io:format(user, "break at line ~w: pid: ~p\n", + [?LINE, self()]), + receive cont -> ok end + end). + + +-import(snmp_test_mgr, [gn/1, g/1, s/1, gb/3]). +-define(v1_2(V1,V2), + case get(vsn) of + v1 -> V1; + _ -> V2 + end). + +-define(v1_2_3(V1,V2,V3), + case get(vsn) of + v1 -> V1; + v2 -> V2; + _ -> V3 + end). + +all() -> +[cases()]. + +groups() -> + [{mib_storage, [], + [{group, mib_storage_ets}, {group, mib_storage_dets}, + {group, mib_storage_mnesia}, + {group, mib_storage_size_check_ets}, + {group, mib_storage_size_check_dets}, + {group, mib_storage_size_check_mnesia}, + {group, mib_storage_varm_dets}, + {group, mib_storage_varm_mnesia}]}, + {mib_storage_ets, [], mib_storage_ets_cases()}, + {mib_storage_dets, [], mib_storage_dets_cases()}, + {mib_storage_mnesia, [], mib_storage_mnesia_cases()}, + {mib_storage_size_check_ets, [], + mse_size_check_cases()}, + {mib_storage_size_check_dets, [], + msd_size_check_cases()}, + {mib_storage_size_check_mnesia, [], + msm_size_check_cases()}, + {mib_storage_varm_dets, [], + varm_mib_storage_dets_cases()}, + {mib_storage_varm_mnesia, [], + varm_mib_storage_mnesia_cases()}, + {test_v1, [], v1_cases()}, {test_v2, [], v2_cases()}, + {test_v1_v2, [], v1_v2_cases()}, + {test_v3, [], v3_cases()}, + {test_multi_threaded, [], mt_cases()}, + {multiple_reqs, [], mul_cases()}, + {multiple_reqs_2, [], mul_cases_2()}, + {v2_inform, [], [v2_inform_i]}, + {v3_security, [], + [v3_crypto_basic, v3_md5_auth, v3_sha_auth, + v3_des_priv]}, + {standard_mibs, [], + [snmp_standard_mib, snmp_community_mib, + snmp_framework_mib, snmp_target_mib, + snmp_notification_mib, snmp_view_based_acm_mib]}, + {standard_mibs_2, [], + [snmpv2_mib_2, snmp_community_mib_2, + snmp_framework_mib_2, snmp_target_mib_2, + snmp_notification_mib_2, snmp_view_based_acm_mib_2]}, + {standard_mibs_3, [], + [snmpv2_mib_3, snmp_framework_mib_3, snmp_mpd_mib_3, + snmp_target_mib_3, snmp_notification_mib_3, + snmp_view_based_acm_mib_3, snmp_user_based_sm_mib_3]}, + {reported_bugs, [], + [otp_1128, otp_1129, otp_1131, otp_1162, otp_1222, + otp_1298, otp_1331, otp_1338, otp_1342, otp_2776, + otp_2979, otp_3187, otp_3725]}, + {reported_bugs_2, [], + [otp_1128_2, otp_1129_2, otp_1131_2, otp_1162_2, + otp_1222_2, otp_1298_2, otp_1331_2, otp_1338_2, + otp_1342_2, otp_2776_2, otp_2979_2, otp_3187_2]}, + {reported_bugs_3, [], + [otp_1128_3, otp_1129_3, otp_1131_3, otp_1162_3, + otp_1222_3, otp_1298_3, otp_1331_3, otp_1338_3, + otp_1342_3, otp_2776_3, otp_2979_3, otp_3187_3, + otp_3542]}, + {tickets, [], [{group, otp_4394}]}, + {otp_4394, [], [otp_4394_test]}]. + +init_per_group(otp_4394, Config) -> + init_otp_4394(Config); +init_per_group(v2_inform, Config) -> + init_v2_inform(Config); +init_per_group(multiple_reqs_2, Config) -> + init_mul(Config); +init_per_group(multiple_reqs, Config) -> + init_mul(Config); +init_per_group(test_multi_threaded, Config) -> + init_mt(Config); +init_per_group(test_v3, Config) -> + init_v3(Config); +init_per_group(test_v1_v2, Config) -> + init_v1_v2(Config); +init_per_group(test_v2, Config) -> + init_v2(Config); +init_per_group(test_v1, Config) -> + init_v1(Config); +init_per_group(mib_storage_varm_mnesia, Config) -> + init_varm_mib_storage_mnesia(Config); +init_per_group(mib_storage_varm_dets, Config) -> + init_varm_mib_storage_dets(Config); +init_per_group(mib_storage_size_check_mnesia, Config) -> + init_size_check_msm(Config); +init_per_group(mib_storage_size_check_dets, Config) -> + init_size_check_msd(Config); +init_per_group(mib_storage_size_check_ets, Config) -> + init_size_check_mse(Config); +init_per_group(mib_storage_mnesia, Config) -> + init_mib_storage_mnesia(Config); +init_per_group(mib_storage_dets, Config) -> + init_mib_storage_dets(Config); +init_per_group(mib_storage_ets, Config) -> + init_mib_storage_ets(Config); +init_per_group(_GroupName, Config) -> + Config. + +end_per_group(otp_4394, Config) -> + finish_otp_4394(Config); +end_per_group(v2_inform, Config) -> + finish_v2_inform(Config); +end_per_group(multiple_reqs_2, Config) -> + finish_mul(Config); +end_per_group(multiple_reqs, Config) -> + finish_mul(Config); +end_per_group(test_multi_threaded, Config) -> + finish_mt(Config); +end_per_group(test_v3, Config) -> + finish_v3(Config); +end_per_group(test_v1_v2, Config) -> + finish_v1_v2(Config); +end_per_group(test_v2, Config) -> + finish_v2(Config); +end_per_group(test_v1, Config) -> + finish_v1(Config); +end_per_group(mib_storage_varm_mnesia, Config) -> + finish_varm_mib_storage_mnesia(Config); +end_per_group(mib_storage_varm_dets, Config) -> + finish_varm_mib_storage_dets(Config); +end_per_group(mib_storage_size_check_mnesia, Config) -> + finish_size_check_msm(Config); +end_per_group(mib_storage_size_check_dets, Config) -> + finish_size_check_msd(Config); +end_per_group(mib_storage_size_check_ets, Config) -> + finish_size_check_mse(Config); +end_per_group(mib_storage_mnesia, Config) -> + finish_mib_storage_mnesia(Config); +end_per_group(mib_storage_dets, Config) -> + finish_mib_storage_dets(Config); +end_per_group(mib_storage_ets, Config) -> + finish_mib_storage_ets(Config); +end_per_group(_GroupName, Config) -> + Config. + + +init_per_testcase(_Case, Config) when list(Config) -> + Dog = ?t:timetrap(?t:minutes(6)), + [{watchdog, Dog}|Config]. + +end_per_testcase(_Case, Config) when list(Config) -> + Dog = ?config(watchdog, Config), + ?t:timetrap_cancel(Dog), + Config. + +cases() -> +case ?OSTYPE() of + vxworks -> + [app_info, {group, test_v1}, {group, test_v2}, + {group, test_v1_v2}, {group, test_multi_threaded}, + {group, mib_storage}, {group, tickets}]; + _Else -> + [app_info, {group, test_v1}, {group, test_v2}, + {group, test_v1_v2}, {group, test_v3}, + {group, test_multi_threaded}, {group, mib_storage}, + {group, tickets}] +end. + + +%%%----------------------------------------------------------------- +%%% The test case structure is as follows: +%%% +%%% init_all - starts mnesia, +%%% +%%% init_v1 - starts agent +%%% simple +%%% big - e.g. starts/stops subagent, load/unloads mibs +%%% init_mul +%%% mul_get +%%% mul_set +%%% +%%% finish_mul +%%% +%%% finish_v1 +%%% +%%% init_v2 - starts agent +%%% finish_v2 +%%% +%%% init_bilingual - starts agent +%%% finish_bilingual +%%% +%%% finish_all +%%% +%%% There is still one problem with these testsuites. If one test +%%% fails, it may not be possible to run some other cases, as it +%%% may have e.g. created some row or loaded some table, that it +%%% didn't undo (since it failed). +%%%----------------------------------------------------------------- + +init_all(Config0) when list(Config0) -> + ?LOG("init_all -> entry with" + "~n Config0: ~p",[Config0]), + + %% -- + %% Fix config: + %% + + DataDir0 = ?config(data_dir, Config0), + DataDir1 = filename:split(filename:absname(DataDir0)), + [_|DataDir2] = lists:reverse(DataDir1), + DataDir3 = filename:join(lists:reverse(DataDir2) ++ [?snmp_test_data]), + Config1 = lists:keydelete(data_dir, 1, Config0), + Config = [{data_dir, DataDir3 ++ "/"}|Config1], + + %% -- + %% Start nodes + %% + + ?line {ok, SaNode} = start_node(snmp_sa), + ?line {ok, MgrNode} = start_node(snmp_mgr), + + + %% -- + %% Create necessary files + %% + + Dir = ?config(priv_dir, Config), + ?DBG("init_all -> Dir ~p", [Dir]), + + DataDir = ?config(data_dir, Config), + ?DBG("init_all -> DataDir ~p", [DataDir]), + + file:make_dir(MgrDir = filename:join(Dir, "mgr_dir/")), + ?DBG("init_all -> MgrDir ~p", [MgrDir]), + + file:make_dir(AgentDir = filename:join(Dir, "agent_dir/")), + ?DBG("init_all -> AgentDir ~p", [AgentDir]), + + file:make_dir(SaDir = filename:join(Dir, "sa_dir/")), + ?DBG("init_all -> SaDir ~p", [SaDir]), + + + %% -- + %% Start and initiate mnesia + %% + + ?DBG("init_all -> load application mnesia", []), + ?line ok = application:load(mnesia), + + ?DBG("init_all -> load application mnesia on node ~p", [SaNode]), + ?line ok = rpc:call(SaNode, application, load, [mnesia]), + + ?DBG("init_all -> application mnesia: set_env dir",[]), + ?line application_controller:set_env(mnesia, dir, + filename:join(Dir, "Mnesia1")), + + ?DBG("init_all -> application mnesia: set_env dir on node ~p",[SaNode]), + ?line rpc:call(SaNode, application_controller, set_env, + [mnesia, dir, filename:join(Dir, "Mnesia2")]), + + ?DBG("init_all -> create mnesia schema",[]), + ?line ok = mnesia:create_schema([SaNode, node()]), + + ?DBG("init_all -> start application mnesia",[]), + ?line ok = application:start(mnesia), + + ?DBG("init_all -> start application mnesia on ~p",[SaNode]), + ?line ok = rpc:call(SaNode, application, start, [mnesia]), + Ip = ?LOCALHOST(), + [{snmp_sa, SaNode}, + {snmp_mgr, MgrNode}, + {agent_dir, AgentDir ++ "/"}, + {mgr_dir, MgrDir ++ "/"}, + {sa_dir, SaDir ++ "/"}, + {mib_dir, DataDir}, + {ip, Ip} | + Config]. + +finish_all(Config) when list(Config) -> + SaNode = ?config(snmp_sa, Config), + MgrNode = ?config(snmp_mgr, Config), + stop_node(SaNode), + stop_node(MgrNode), + application:stop(mnesia). + +start_v1_agent(Config) when list(Config) -> + start_agent(Config, [v1]). + +start_v1_agent(Config,Opts) when list(Config), list(Opts) -> + start_agent(Config, [v1], Opts). + +start_v2_agent(Config) when list(Config) -> + start_agent(Config, [v2]). + +start_v3_agent(Config) when list(Config) -> + start_agent(Config, [v3]). + +start_bilingual_agent(Config) when list(Config) -> + start_agent(Config, [v1,v2]). + +start_multi_threaded_agent(Config) when list(Config) -> + start_agent(Config, [v2], [{snmp_multi_threaded, true}]). + +stop_agent(Config) when list(Config) -> + ?LOG("stop_agent -> entry with" + "~n Config: ~p",[Config]), + + {Sup, Par} = ?config(snmp_sup, Config), + ?DBG("stop_agent -> attempt to stop (sup) ~p" + "~n Sup: ~p" + "~n Par: ~p", + [Sup, + (catch process_info(Sup)), + (catch process_info(Par))]), + stop_sup(Sup, Par), + + {Sup2, Par2} = ?config(snmp_sub, Config), + ?DBG("stop_agent -> attempt to stop (sub) ~p" + "~n Sup2: ~p" + "~n Par2: ~p", + [Sup2, + (catch process_info(Sup2)), + (catch process_info(Par2))]), + stop_sup(Sup2, Par2), + + ?DBG("stop_agent -> done - now cleanup config", []), + C1 = lists:keydelete(snmp_sup, 1, Config), + lists:keydelete(snmp_sub, 1, C1). + + +stop_sup(Pid, _) when node(Pid) == node() -> + case (catch process_info(Pid)) of + PI when list(PI) -> + ?LOG("stop_sup -> attempt to stop ~p", [Pid]), + Ref = erlang:monitor(process, Pid), + exit(Pid, kill), + await_stopped(Pid, Ref); + {'EXIT', _Reason} -> + ?LOG("stop_sup -> ~p not running", [Pid]), + ok + end; +stop_sup(Pid, _) -> + ?LOG("stop_sup -> attempt to stop ~p", [Pid]), + Ref = erlang:monitor(process, Pid), + ?LOG("stop_sup -> Ref: ~p", [Ref]), + %% Pid ! {'EXIT', Parent, shutdown}, % usch + exit(Pid, kill), + await_stopped(Pid, Ref). + +await_stopped(Pid, Ref) -> + receive + {'DOWN', Ref, process, Pid, _Reason} -> + ?DBG("received down message for ~p", [Pid]), + ok + after 10000 -> + ?INF("await_stopped -> timeout for ~p",[Pid]), + erlang:demonitor(Ref), + ?FAIL({failed_stop,Pid}) + end. + + +start_agent(Config, Vsn) -> + start_agent(Config, Vsn, []). +start_agent(Config, Vsn, Opts) -> + ?LOG("start_agent -> entry (~p) with" + "~n Config: ~p" + "~n Vsn: ~p" + "~n Opts: ~p",[node(), Config, Vsn, Opts]), + + ?line AgentDir = ?config(agent_dir, Config), + ?line SaNode = ?config(snmp_sa, Config), + + snmp_app_env_init(vsn_init(Vsn) ++ + [{audit_trail_log, read_write_log}, + {audit_trail_log_dir, AgentDir}, + {audit_trail_log_size, {10240, 10}}, + {force_config_reload, false}, + {snmp_agent_type, master}, + {snmp_config_dir, AgentDir}, + {snmp_db_dir, AgentDir}, + {snmp_local_db_auto_repair, true}, + {snmp_master_agent_verbosity, trace}, + {snmp_supervisor_verbosity, trace}, + {snmp_mibserver_verbosity, trace}, + {snmp_symbolic_store_verbosity, trace}, + {snmp_note_store_verbosity, trace}, + {snmp_net_if_verbosity, trace}], + Opts), + + + process_flag(trap_exit,true), + + {ok, AppSup} = snmp_app_sup:start_link(), + unlink(AppSup), + ?DBG("start_agent -> snmp app supervisor: ~p",[AppSup]), + + ?DBG("start_agent -> start master agent (old style)",[]), + Sup = case (catch snmpa_app:start(normal)) of + {ok, S} -> + ?DBG("start_agent -> started, Sup: ~p",[S]), + S; + + Else -> + ?DBG("start_agent -> unknown result: ~n~p",[Else]), + %% Get info about the apps we depend on + MnesiaInfo = mnesia_running(), + ?FAIL({start_failed,Else,MnesiaInfo}) + end, + + ?DBG("start_agent -> unlink from supervisor",[]), + ?line unlink(Sup), + ?line SaDir = ?config(sa_dir, Config), + ?DBG("start_agent -> (rpc) start sub on ~p",[SaNode]), + ?line {ok, Sub} = rpc:call(SaNode, ?MODULE, start_sub, [SaDir]), + ?DBG("start_agent -> done",[]), + ?line [{snmp_sup, {Sup, self()}}, {snmp_sub, Sub} | Config]. + + +vsn_init(Vsn) -> + vsn_init([v1,v2,v3], Vsn, []). + +vsn_init([], _Vsn, Acc) -> + Acc; +vsn_init([V|Vsns], Vsn, Acc) -> + case lists:member(V, Vsn) of + true -> + vsn_init(Vsns, Vsn, [{V, true}|Acc]); + false -> + vsn_init(Vsns, Vsn, [{V, false}|Acc]) + end. + +snmp_app_env_init(Env0, Opts) -> + ?DBG("snmp_app_env_init -> unload snmp",[]), + ?line application:unload(snmp), + ?DBG("snmp_app_env_init -> load snmp",[]), + ?line application:load(snmp), + ?DBG("snmp_app_env_init -> initiate (snmp) application env",[]), + F1 = fun({Key,Val} = New, Acc0) -> + ?DBG("snmp_app_env_init -> " + "updating setting ~p to ~p", [Key, Val]), + case lists:keyreplace(Key, 1, Acc0, New) of + Acc0 -> + [New|Acc0]; + Acc -> + Acc + end + end, + Env = lists:foldr(F1, Env0, Opts), + ?DBG("snmp_app_env_init -> Env: ~p",[Env]), + F2 = fun({Key,Val}) -> + ?DBG("snmp_app_env_init -> setting ~p to ~p",[Key, Val]), + application_controller:set_env(snmp, Key, Val) + end, + lists:foreach(F2, Env). + + + + +%% Test if application is running +mnesia_running() -> ?IS_MNESIA_RUNNING(). +crypto_running() -> ?IS_CRYPTO_RUNNING(). + + +start_sub(Dir) -> + ?DBG("start_sub -> entry",[]), + Opts = [{db_dir, Dir}, + {supervisor, [{verbosity, trace}]}], + %% BMK BMK +% {ok, P} = snmp_supervisor:start_sub(Dir), + {ok, P} = snmpa_supervisor:start_sub_sup(Opts), + unlink(P), + {ok, {P, self()}}. + +create_tables(SaNode) -> + ?line {atomic, ok} = mnesia:create_table([{name, friendsTable2}, + {ram_copies, [SaNode]}, + {snmp, [{key, integer}]}, + {attributes, [a1,a2,a3]}]), + ?line {atomic, ok} = mnesia:create_table([{name, kompissTable2}, + {ram_copies, [SaNode]}, + {snmp, [{key, integer}]}, + {attributes, [a1,a2,a3]}]), + ?line {atomic, ok} = mnesia:create_table([{name, snmp_variables}, + {attributes, [a1,a2]}]). + +delete_tables() -> + mnesia:delete_table(friendsTable2), + mnesia:delete_table(kompissTable2), + mnesia:delete_table(snmp_variables). + +%% Creation is done in runtime! +delete_mib_storage_mnesia_tables() -> + mnesia:delete_table(snmpa_mib_data), + mnesia:delete_table(snmpa_mib_tree), + mnesia:delete_table(snmpa_symbolic_store). + +%%----------------------------------------------------------------- +%% A test case is always one of: +%% - v1 specific case +%% - v2 specific case +%% - v1 and v2 case +%% All v1 specific cases are prefixed with v1_, and all v2 with +%% v2_. E.g. v1_trap/v2_trap. +%% +%% All other cases are shared. However, the testserver uses the name +%% of the case to generate a file for that case. The same case cannot +%% be used in different configurations in the same suite. Therefore +%% all these functions exists in two variants, the base function +%% , and a second version _2. There may be several +%% versions as well, _N. +%%----------------------------------------------------------------- + + + + + + + + + +mib_storage_ets_cases() -> +[mse_simple, mse_v1_processing, mse_big, mse_big2, + mse_loop_mib, mse_api, mse_sa_register, mse_v1_trap, + mse_sa_error, mse_next_across_sa, mse_undo, + mse_standard_mib, mse_community_mib, mse_framework_mib, + mse_target_mib, mse_notification_mib, + mse_view_based_acm_mib, mse_sparse_table, mse_me_of, + mse_mib_of]. + +mib_storage_dets_cases() -> +[msd_simple, msd_v1_processing, msd_big, msd_big2, + msd_loop_mib, msd_api, msd_sa_register, msd_v1_trap, + msd_sa_error, msd_next_across_sa, msd_undo, + msd_standard_mib, msd_community_mib, msd_framework_mib, + msd_target_mib, msd_notification_mib, + msd_view_based_acm_mib, msd_sparse_table, msd_me_of, + msd_mib_of]. + +mib_storage_mnesia_cases() -> +[msm_simple, msm_v1_processing, msm_big, msm_big2, + msm_loop_mib, msm_api, msm_sa_register, msm_v1_trap, + msm_sa_error, msm_next_across_sa, msm_undo, + msm_standard_mib, msm_community_mib, msm_framework_mib, + msm_target_mib, msm_notification_mib, + msm_view_based_acm_mib, msm_sparse_table, msm_me_of, + msm_mib_of]. + +mse_size_check_cases() -> +[mse_size_check]. + +msd_size_check_cases() -> +[msd_size_check]. + +msm_size_check_cases() -> +[msm_size_check]. + +varm_mib_storage_dets_cases() -> +[msd_varm_mib_start]. + +varm_mib_storage_mnesia_cases() -> +[msm_varm_mib_start]. + +init_mib_storage_ets(Config) when list(Config) -> + ?LOG("init_mib_storage_ets -> entry", []), + MibStorage = {snmp_mib_storage,ets}, + init_ms(Config, [MibStorage]). + +init_mib_storage_dets(Config) when list(Config) -> + ?LOG("init_mib_storage_ets -> entry", []), + ?line AgentDir = ?GCONF(agent_dir, Config), + MibStorage = {snmp_mib_storage,{dets,AgentDir}}, + init_ms(Config, [MibStorage]). + +init_mib_storage_mnesia(Config) when list(Config) -> + ?LOG("init_mib_storage_ets -> entry", []), + MibStorage = {snmp_mib_storage,{mnesia,[]}}, + init_ms(Config, [MibStorage]). + +init_ms(Config, Opts) when list(Config) -> + ?LOG("init_mib_storage_ets -> entry", []), + ?line SaNode = ?GCONF(snmp_sa, Config), + ?line create_tables(SaNode), + ?line AgentDir = ?GCONF(agent_dir, Config), + ?line MgrDir = ?GCONF(mgr_dir, Config), + ?line Ip = ?GCONF(ip, Config), + ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, + MibsVerbosity = {snmp_mibserver_verbosity, trace}, + SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, + Opts1 = [MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity|Opts], + [{vsn, v1} | start_v1_agent(Config,Opts1)]. + +init_size_check_mse(Config) when list(Config) -> + MibStorage = {snmp_mib_storage, ets}, + init_size_check_ms(Config, [MibStorage]). + +init_size_check_msd(Config) when list(Config) -> + AgentDir = ?GCONF(agent_dir, Config), + MibStorage = {snmp_mib_storage, {dets, AgentDir}}, + init_size_check_ms(Config, [MibStorage]). + +init_size_check_msm(Config) when list(Config) -> + MibStorage = {snmp_mib_storage, {mnesia,[]}}, + init_size_check_ms(Config, [MibStorage]). + +init_size_check_ms(Config, Opts) when list(Config) -> + SaNode = ?GCONF(snmp_sa, Config), + %% We are using v3 here, so crypto must be supported or else... + case ?CRYPTO_START() of + ok -> + case ?CRYPTO_SUPPORT() of + {no, Reason} -> + ?SKIP({unsupported_encryption, Reason}); + yes -> + ok + end; + {error, Reason} -> + ?SKIP({failed_starting_crypto, Reason}) + end, + create_tables(SaNode), + AgentDir = ?GCONF(agent_dir, Config), + MgrDir = ?GCONF(mgr_dir, Config), + Ip = ?GCONF(ip, Config), + ?line ok = + config([v3], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v3} | start_agent(Config, [v3], Opts)]. + +init_varm_mib_storage_dets(Config) when list(Config) -> + ?LOG("init_varm_mib_storage_dets -> entry", []), + ?line SaNode = ?GCONF(snmp_sa, Config), + ?line create_tables(SaNode), + ?line AgentDir = ?GCONF(agent_dir, Config), + ?line MgrDir = ?GCONF(mgr_dir, Config), + ?line Ip = ?GCONF(ip, Config), + ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + MibStorage = {snmp_mib_storage,{dets,AgentDir}}, + MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, + MibsVerbosity = {snmp_mibserver_verbosity, trace}, + SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, + Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity], + [{vsn, v1}, {agent_opts,Opts} | Config]. + +init_varm_mib_storage_mnesia(Config) when list(Config) -> + ?LOG("init_varm_mib_storage_mnesia -> entry", []), + ?line SaNode = ?GCONF(snmp_sa, Config), + ?line create_tables(SaNode), + ?line AgentDir = ?GCONF(agent_dir, Config), + ?line MgrDir = ?GCONF(mgr_dir, Config), + ?line Ip = ?GCONF(ip, Config), + ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + MibStorage = {snmp_mib_storage,{mnesia,[]}}, + MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, + MibsVerbosity = {snmp_mibserver_verbosity, trace}, + SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, + Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity], + [{vsn, v1}, {agent_opts,Opts} | Config]. + +finish_mib_storage_ets(Config) when list(Config) -> + ?LOG("finish_mib_storage_ets -> entry", []), + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + C2 = lists:keydelete(vsn, 1, C1), + lists:keydelete(agent_opts, 1, C2). + +finish_mib_storage_dets(Config) when list(Config) -> + ?LOG("finish_mib_storage_dets -> entry", []), + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + C2 = lists:keydelete(vsn, 1, C1), + lists:keydelete(agent_opts, 1, C2). + +finish_mib_storage_mnesia(Config) when list(Config) -> + ?LOG("finish_mib_storage_mnesia -> entry", []), + delete_tables(), + delete_mib_storage_mnesia_tables(), + C1 = stop_agent(Config), + delete_files(C1), + C2 = lists:keydelete(vsn, 1, C1), + lists:keydelete(agent_opts, 1, C2). + +finish_varm_mib_storage_dets(Config) when list(Config) -> + ?LOG("finish_varm_mib_storage_dets -> entry", []), + delete_tables(), + %% C1 = stop_agent(Config), % In case something went wrong... + delete_files(Config), + C2 = lists:keydelete(vsn, 1, Config), + lists:keydelete(agent_opts, 1, C2). + +finish_varm_mib_storage_mnesia(Config) when list(Config) -> + ?LOG("finish_varm_mib_storage_mnesia -> entry", []), + delete_tables(), + delete_mib_storage_mnesia_tables(), + %% C1 = stop_agent(Config), % In case something went wrong... + delete_files(Config), + C2 = lists:keydelete(vsn, 1, Config), + lists:keydelete(agent_opts, 1, C2). + +finish_size_check_mse(Config) when list(Config) -> + finish_size_check_ms(Config). + +finish_size_check_msd(Config) when list(Config) -> + finish_size_check_ms(Config). + +finish_size_check_msm(Config) when list(Config) -> + finish_size_check_ms(Config). + +finish_size_check_ms(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + + +%% These are just interface functions to fool the test server +mse_simple(X) -> simple(X). +mse_v1_processing(X) -> v1_processing(X). +mse_big(X) -> big(X). +mse_big2(X) -> big2(X). +mse_loop_mib(X) -> loop_mib(X). +mse_api(X) -> api(X). +mse_sa_register(X) -> sa_register(X). +mse_v1_trap(X) -> v1_trap(X). +mse_sa_error(X) -> sa_error(X). +mse_next_across_sa(X) -> next_across_sa(X). +mse_undo(X) -> undo(X). +mse_standard_mib(X) -> snmp_standard_mib(X). +mse_community_mib(X) -> snmp_community_mib(X). +mse_framework_mib(X) -> snmp_framework_mib(X). +mse_target_mib(X) -> snmp_target_mib(X). +mse_notification_mib(X) -> snmp_notification_mib(X). +mse_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). +mse_sparse_table(X) -> sparse_table(X). +mse_me_of(X) -> ms_me_of(X). +mse_mib_of(X) -> ms_mib_of(X). + +msd_simple(X) -> simple(X). +msd_v1_processing(X) -> v1_processing(X). +msd_big(X) -> big(X). +msd_big2(X) -> big2(X). +msd_loop_mib(X) -> loop_mib(X). +msd_api(X) -> api(X). +msd_sa_register(X) -> sa_register(X). +msd_v1_trap(X) -> v1_trap(X). +msd_sa_error(X) -> sa_error(X). +msd_next_across_sa(X) -> next_across_sa(X). +msd_undo(X) -> undo(X). +msd_standard_mib(X) -> snmp_standard_mib(X). +msd_community_mib(X) -> snmp_community_mib(X). +msd_framework_mib(X) -> snmp_framework_mib(X). +msd_target_mib(X) -> snmp_target_mib(X). +msd_notification_mib(X) -> snmp_notification_mib(X). +msd_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). +msd_sparse_table(X) -> sparse_table(X). +msd_me_of(X) -> ms_me_of(X). +msd_mib_of(X) -> ms_mib_of(X). + +msm_simple(X) -> simple(X). +msm_v1_processing(X) -> v1_processing(X). +msm_big(X) -> big(X). +msm_big2(X) -> big2(X). +msm_loop_mib(X) -> loop_mib(X). +msm_api(X) -> api(X). +msm_sa_register(X) -> sa_register(X). +msm_v1_trap(X) -> v1_trap(X). +msm_sa_error(X) -> sa_error(X). +msm_next_across_sa(X) -> next_across_sa(X). +msm_undo(X) -> undo(X). +msm_standard_mib(X) -> snmp_standard_mib(X). +msm_community_mib(X) -> snmp_community_mib(X). +msm_framework_mib(X) -> snmp_framework_mib(X). +msm_target_mib(X) -> snmp_target_mib(X). +msm_notification_mib(X) -> snmp_notification_mib(X). +msm_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). +msm_sparse_table(X) -> sparse_table(X). +msm_me_of(X) -> ms_me_of(X). +msm_mib_of(X) -> ms_mib_of(X). + + +mse_size_check(X) -> p("mse_size_check..."), ms_size_check(X). +msd_size_check(X) -> p("msd_size_check..."), ms_size_check(X). +msm_size_check(X) -> p("msm_size_check..."), ms_size_check(X). + +msd_varm_mib_start(X) -> p("msd_varm_mib_start..."), varm_mib_start(X). +msm_varm_mib_start(X) -> p("msm_varm_mib_start..."), varm_mib_start(X). + +ms_size_check(suite) -> []; +ms_size_check(Config) when list(Config) -> + p("ms_size_check..."), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?LOG("mib server size check...", []), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + ?line load_master_std("OTP-SNMPEA-MIB"), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-MPD-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-USER-BASED-SM-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + ?line load_master_std("SNMPv2-MIB"), + ?line load_master_std("SNMPv2-TM"), + + ?SLEEP(2000), + + ?line display_memory_usage(), + + ?line unload_master("OTP-SNMPEA-MIB"), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?line unload_master("SNMP-MPD-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-USER-BASED-SM-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + ?line unload_master("SNMPv2-MIB"), + ?line unload_master("SNMPv2-TM"), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + + ok. + + +varm_mib_start(suite) -> []; +varm_mib_start(Config) when list(Config) -> + p("varm_mib_start..."), + ?LOG("varm_mib_start -> entry", []), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + %% Start the agent + Opts = ?GCONF(agent_opts, Config), + Config1 = start_v1_agent(Config, Opts), + + %% Sleep some in order for the agent to start properly + ?DBG("varm_mib_start -> sleep some (before loading mobs)", []), + ?SLEEP(5000), + + %% Load all the mibs + HardwiredMibs = loaded_mibs(), + ?DBG("varm_mib_start -> load all mibs", []), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + + %% Unload the hardwired mibs + ?DBG("varm_mib_start -> sleep some (before unloading hardwired mibs)", []), + ?SLEEP(1000), + ?DBG("varm_mib_start -> unload (hardwired) mibs", []), + ?line unload_mibs(HardwiredMibs), %% unload hardwired + + ?DBG("varm_mib_start -> sleep some (before stopping agent)", []), + ?SLEEP(1000), + + %% Stop the agent (without deleting the stored files) + ?DBG("varm_mib_start -> stop the agent", []), + Config2 = stop_agent(Config1), + + %% Sleep some in order for the agent to stop properly + ?DBG("varm_mib_start -> sleep some (before re-starting the agent)", []), + ?SLEEP(5000), + + %% Start the agent (again) + ?DBG("varm_mib_start -> start the agent", []), + Config3 = start_v1_agent(Config2, Opts), + + ?DBG("varm_mib_start -> sleep some (before starting tests)", []), + ?SLEEP(5000), + + %% Perform the test(s) + ?DBG("varm_mib_start -> perform the tests", []), + try_test(snmp_community_mib), + try_test(snmp_framework_mib), + try_test(snmp_target_mib), + try_test(snmp_notification_mib), + + %% Stop the agent (without deleting the stored files) + ?DBG("varm_mib_start -> stop the agent", []), + stop_agent(Config3), + ok. + + +-define(snmpTrapCommunity_instance, [1,3,6,1,6,3,18,1,4,0]). +-define(vacmViewSpinLock_instance, [1,3,6,1,6,3,16,1,5,1,0]). +-define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). + +ms_me_of(suite) -> []; +ms_me_of(Config) when list(Config) -> + p("ms_me_of..."), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + ?line load_master_std("OTP-SNMPEA-MIB"), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-MPD-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + + ?SLEEP(2000), + + ?line display_memory_usage(), + + + ?DBG("ms_me_of -> find ~w from SNMP-COMMUNITY-MIB", + [?snmpTrapCommunity_instance]), + ?line ok = me_of(?snmpTrapCommunity_instance), + + ?DBG("ms_me_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", + [?vacmViewSpinLock_instance]), + ?line ok = me_of(?vacmViewSpinLock_instance), + + ?DBG("ms_me_of -> find ~w from SNMP-USER-BASED-SM-MIB", + [?usmStatsNotInTimeWindows_instance]), + ?line {error, _} = me_of(?usmStatsNotInTimeWindows_instance), + + + ?line unload_master("OTP-SNMPEA-MIB"), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?line unload_master("SNMP-MPD-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + + ok. + +me_of(Oid) -> + case snmpa:me_of(Oid) of + {ok, #me{oid = Oid}} -> + ok; + {ok, #me{oid = OtherOid}} -> + case lists:reverse(Oid) of + [0|Rest] -> + case lists:reverse(Rest) of + OtherOid -> + ok; + AnotherOid -> + {error, {invalid_oid, Oid, AnotherOid}} + end; + _ -> + {error, {invalid_oid, Oid, OtherOid}} + end; + {error, Reason} -> + {error, Reason}; + Else -> + {error, Else} + end. + + +ms_mib_of(suite) -> []; +ms_mib_of(Config) when list(Config) -> + p("ms_mib_of..."), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + ?line load_master_std("OTP-SNMPEA-MIB"), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-MPD-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + + ?SLEEP(2000), + + ?line display_memory_usage(), + + + ?DBG("ms_mib_of -> find ~w from SNMP-COMMUNITY-MIB", + [?snmpTrapCommunity_instance]), + ?line ok = mib_of(?snmpTrapCommunity_instance, 'SNMP-COMMUNITY-MIB'), + + ?DBG("ms_mib_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", + [?vacmViewSpinLock_instance]), + ?line ok = mib_of(?vacmViewSpinLock_instance, 'SNMP-VIEW-BASED-ACM-MIB'), + + ?DBG("ms_mib_of -> find ~w from SNMP-USER-BASED-SM-MIB", + [?usmStatsNotInTimeWindows_instance]), + ?line {error, _} = mib_of(?usmStatsNotInTimeWindows_instance, + 'SNMP-USER-BASED-SM-MIB'), + + + ?line unload_master("OTP-SNMPEA-MIB"), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?line unload_master("SNMP-MPD-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + + ok. + +mib_of(Oid, ExpectedMibName) -> + ?DBG("mib_of -> entry with" + "~n Oid: ~p" + "~n ExpectedMibName: ~p", [Oid, ExpectedMibName]), + %% case snmpa:mib_of(Oid) of + MibOf = snmpa:mib_of(Oid), + ?DBG("mib_of -> MibOf: ~n~p", [MibOf]), + case MibOf of + {ok, ExpectedMibName} -> + ok; + {ok, OtherMibName} -> + {error, {invalid_mib, ExpectedMibName, OtherMibName}}; + {error, Reason} -> + {error, Reason}; + Else -> + ?DBG("mib_of -> Else: ~n~p", [Else]), + {error, Else} + end. + + +app_info(suite) -> []; +app_info(Config) when list(Config) -> + SnmpDir = app_dir(snmp), + SslDir = app_dir(ssl), + CryptoDir = app_dir(crypto), + Attr = snmp:module_info(attributes), + AppVsn = + case lists:keysearch(app_vsn, 1, Attr) of + {value, {app_vsn, V}} -> + V; + false -> + "undefined" + end, + io:format("Root dir: ~s~n" + "SNMP: Application dir: ~s~n" + " Application ver: ~s~n" + "SSL: Application dir: ~s~n" + "CRYPTO: Application dir: ~s~n", + [code:root_dir(), SnmpDir, AppVsn, SslDir, CryptoDir]), + ok. + +app_dir(App) -> + case code:lib_dir(App) of + D when list(D) -> + filename:basename(D); + {error, _Reason} -> + "undefined" + end. + + + +%v1_cases() -> [loop_mib]; +v1_cases() -> +[simple, db_notify_client, v1_processing, big, big2, + loop_mib, api, subagent, mnesia, {group, multiple_reqs}, + sa_register, v1_trap, sa_error, next_across_sa, undo, + {group, reported_bugs}, {group, standard_mibs}, + sparse_table, cnt_64, opaque, change_target_addr_config]. + +init_v1(Config) when list(Config) -> + ?line SaNode = ?config(snmp_sa, Config), + ?line create_tables(SaNode), + ?line AgentDir = ?config(agent_dir, Config), + ?line MgrDir = ?config(mgr_dir, Config), + ?line Ip = ?config(ip, Config), + ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v1} | start_v1_agent(Config)]. + +finish_v1(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + + +%v2_cases() -> [loop_mib_2]; +v2_cases() -> +[simple_2, v2_processing, big_2, big2_2, loop_mib_2, + api_2, subagent_2, mnesia_2, {group, multiple_reqs_2}, + sa_register_2, v2_trap, {group, v2_inform}, sa_error_2, + next_across_sa_2, undo_2, {group, reported_bugs_2}, + {group, standard_mibs_2}, v2_types, implied, + sparse_table_2, cnt_64_2, opaque_2, v2_caps]. + +init_v2(Config) when list(Config) -> + SaNode = ?config(snmp_sa, Config), + create_tables(SaNode), + AgentDir = ?config(agent_dir, Config), + MgrDir = ?config(mgr_dir, Config), + Ip = ?config(ip, Config), + config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v2} | start_v2_agent(Config)]. + +finish_v2(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + + +v1_v2_cases() -> +[simple_bi]. + +init_v1_v2(Config) when list(Config) -> + SaNode = ?config(snmp_sa, Config), + create_tables(SaNode), + AgentDir = ?config(agent_dir, Config), + MgrDir = ?config(mgr_dir, Config), + Ip = ?config(ip, Config), + config([v1,v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, bilingual} | start_bilingual_agent(Config)]. + +finish_v1_v2(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + + +%v3_cases() -> [loop_mib_3]; +v3_cases() -> +[simple_3, v3_processing, big_3, big2_3, api_3, + subagent_3, mnesia_3, loop_mib_3, multiple_reqs_3, + sa_register_3, v3_trap, v3_inform, sa_error_3, + next_across_sa_3, undo_3, {group, reported_bugs_3}, + {group, standard_mibs_3}, {group, v3_security}, + v2_types_3, implied_3, sparse_table_3, cnt_64_3, + opaque_3, v2_caps_3]. + +init_v3(Config) when list(Config) -> + %% Make sure crypto works, otherwise start_agent will fail + %% and we will be stuck with a bunch of mnesia tables for + %% the rest of this suite... + ?DBG("start_agent -> start crypto app",[]), + case os:type() of + vxworks -> + no_crypto; + _ -> + case ?CRYPTO_START() of + ok -> + case ?CRYPTO_SUPPORT() of + {no, Reason} -> + ?SKIP({unsupported_encryption, Reason}); + yes -> + ok + end; + {error, Reason} -> + ?SKIP({failed_starting_crypto, Reason}) + end + end, + SaNode = ?config(snmp_sa, Config), + create_tables(SaNode), + AgentDir = ?config(agent_dir, Config), + MgrDir = ?config(mgr_dir, Config), + Ip = ?config(ip, Config), + ?line ok = config([v3], MgrDir, AgentDir, + tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v3} | start_v3_agent(Config)]. + +finish_v3(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + + +mt_cases() -> +[multi_threaded, mt_trap]. + +init_mt(Config) when list(Config) -> + SaNode = ?config(snmp_sa, Config), + create_tables(SaNode), + AgentDir = ?config(agent_dir, Config), + MgrDir = ?config(mgr_dir, Config), + Ip = ?config(ip, Config), + ?line ok = config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v2} | start_multi_threaded_agent(Config)]. + +finish_mt(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + +%% This one *must* be run first in each case. +init_case(Config) when list(Config) -> + ?DBG("init_case -> entry with" + "~n Config: ~p", [Config]), + SaNode = ?config(snmp_sa, Config), + MgrNode = ?config(snmp_mgr, Config), + MasterNode = node(), + + SaHost = ?HOSTNAME(SaNode), + MgrHost = ?HOSTNAME(MgrNode), + MasterHost = ?HOSTNAME(MasterNode), + {ok, MasterIP} = snmp_misc:ip(MasterHost), + {ok, MIP} = snmp_misc:ip(MgrHost), + {ok, SIP} = snmp_misc:ip(SaHost), + + + put(mgr_node, MgrNode), + put(sa_node, SaNode), + put(master_node, MasterNode), + put(sa_host, SaHost), + put(mgr_host, MgrHost), + put(master_host, MasterHost), + put(mip, tuple_to_list(MIP)), + put(masterip , tuple_to_list(MasterIP)), + put(sip, tuple_to_list(SIP)), + + MibDir = ?config(mib_dir, Config), + put(mib_dir, MibDir), + StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", + put(std_mib_dir, StdM), + + MgrDir = ?config(mgr_dir, Config), + put(mgr_dir, MgrDir), + + put(vsn, ?config(vsn, Config)), + ?DBG("init_case -> exit with" + "~n MasterNode: ~p" + "~n SaNode: ~p" + "~n MgrNode: ~p" + "~n MibDir: ~p", [MasterNode, SaNode, MgrNode, MibDir]), + {SaNode, MgrNode, MibDir}. + +load_master(Mib) -> + ?DBG("load_master -> entry with" + "~n Mib: ~p", [Mib]), + snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety + ok = snmpa:load_mibs(snmp_master_agent, [get(mib_dir) ++ Mib]). + +load_master_std(Mib) -> + ?DBG("load_master_std -> entry with" + "~n Mib: ~p", [Mib]), + snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety + ok = snmpa:load_mibs(snmp_master_agent, [get(std_mib_dir) ++ Mib]). + +unload_master(Mib) -> + ?DBG("unload_master -> entry with" + "~n Mib: ~p", [Mib]), + ok = snmpa:unload_mibs(snmp_master_agent, [Mib]). + +loaded_mibs() -> + ?DBG("loaded_mibs -> entry",[]), + Info = snmpa:info(snmp_master_agent), + {value, {loaded_mibs, Mibs}} = lists:keysearch(loaded_mibs, 1, Info), + [atom_to_list(Mib) || {Mib,_,_} <- Mibs]. + +unload_mibs(Mibs) -> + ?DBG("unload_mibs -> entry with" + "~n Mibs: ~p", [Mibs]), + ok = snmpa:unload_mibs(snmp_master_agent, Mibs). + +start_subagent(SaNode, RegTree, Mib) -> + ?DBG("start_subagent -> entry with" + "~n SaNode: ~p" + "~n RegTree: ~p" + "~n Mib: ~p", [SaNode, RegTree, Mib]), + MA = whereis(snmp_master_agent), + ?DBG("start_subagent -> MA: ~p", [MA]), + MibDir = get(mib_dir), + Mib1 = join(MibDir,Mib), + %% BMK BMK +% case rpc:call(SaNode,snmp_supervisor,start_subagent,[MA,RegTree,[Mib1]]) of + case rpc:call(SaNode, snmpa_supervisor, + start_sub_agent, [MA, RegTree, [Mib1]]) of + {ok, SA} -> + ?DBG("start_subagent -> SA: ~p", [SA]), + {ok, SA}; + Error -> + ?FAIL({subagent_start_failed, SaNode, Error, [MA, RegTree, Mib1]}) + end. + +stop_subagent(SA) -> + ?DBG("stop_subagent -> entry with" + "~n SA: ~p", [SA]), + %% BNK BMK + %% rpc:call(node(SA), snmp_supervisor, stop_subagent, [SA]). + rpc:call(node(SA), snmpa_supervisor, stop_sub_agent, [SA]). + +%%----------------------------------------------------------------- +%% This function takes care of the old OTP-SNMPEA-MIB. +%% Unfortunately, the testcases were written to use the data in the +%% internal tables, and these table are now obsolete and not used +%% by the agent. Therefore, we emulate them by using +%% OLD-SNMPEA-MIB, which uses the default impl. of all tables. +%% +%% These two rows must exist in intCommunityTable +%% {[147,214,36,45], "public", 2, readWrite}. +%% {[147,214,36,45], "standard trap", 2, read}. +%% (But with the manager's IP address) +%% +%%----------------------------------------------------------------- +init_old() -> + snmpa_local_db:table_create_row(intCommunityTable, + get(mip) ++ [6 | "public"], + {get(mip), "public", 2, 2}), + snmpa_local_db:table_create_row(intCommunityTable, + get(mip) ++ [13 | "standard trap"], + {get(mip), "standard trap", 2, 1}), + snmpa_local_db:variable_set(intAgentIpAddress, [127,0,0,1]). + + + +simple(suite) -> []; +simple(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + try_test(simple_standard_test). + +simple_2(X) -> simple(X). + +simple_bi(suite) -> []; +simple_bi(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + put(vsn, v1), % First, try v1 manager + try_test(simple_standard_test), + + put(vsn, v2), % Then, try v2 manager + try_test(simple_standard_test). + +simple_3(X) -> + simple(X). + +big(suite) -> []; +big(Config) when list(Config) -> + ?DBG("big -> entry", []), + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Starting subagent..."), + ?line pong = net_adm:ping(SaNode), + + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), + ?DBG("big -> SA: ~p", [SA]), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(big_test), + ?line stop_subagent(SA), + ?line unload_master("OLD-SNMPEA-MIB"). + +big_2(X) -> big(X). + +big_3(X) -> big(X). + + +big2(suite) -> []; +big2(Config) when list(Config) -> + %% This is exactly the same tests as 'big', but with the + %% v2 equivalent of the mibs. + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Starting subagent..."), + ?line pong = net_adm:ping(SaNode), + + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1-v2"), + ?line load_master("OLD-SNMPEA-MIB-v2"), + ?line init_old(), + try_test(big_test), + ?line stop_subagent(SA), + ?line unload_master("OLD-SNMPEA-MIB-v2"). + +big2_2(X) -> big2(X). + +big2_3(X) -> big2(X). + + +multi_threaded(suite) -> []; +multi_threaded(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test1"), + try_test(multi_threaded_test), + ?line unload_master("Test1"). + +mt_trap(suite) -> []; +mt_trap(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line load_master("Test1"), + ?line load_master("TestTrapv2"), + try_test(mt_trap_test, [MA]), + ?line unload_master("TestTrapv2"), + ?line unload_master("Test1"). + +v2_types(suite) -> []; +v2_types(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test1"), + try_test(types_v2_test), + ?line unload_master("Test1"). + +v2_types_3(X) -> v2_types(X). + + +implied(suite) -> []; +implied(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line load_master("Test1"), + try_test(implied_test,[MA]), + ?line unload_master("Test1"). + +implied_3(X) -> implied(X). + + +sparse_table(suite) -> []; +sparse_table(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test1"), + try_test(sparse_table_test), + ?line unload_master("Test1"). + +sparse_table_2(X) -> sparse_table(X). + +sparse_table_3(X) -> sparse_table(X). + +cnt_64(suite) -> []; +cnt_64(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line load_master("Test1"), + try_test(cnt_64_test, [MA]), + ?line unload_master("Test1"). + +cnt_64_2(X) -> cnt_64(X). + +cnt_64_3(X) -> cnt_64(X). + +opaque(suite) -> []; +opaque(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test1"), + try_test(opaque_test), + ?line unload_master("Test1"). + +opaque_2(X) -> opaque(X). + +opaque_3(X) -> opaque(X). + + +change_target_addr_config(suite) -> []; +change_target_addr_config(Config) when list(Config) -> + p("Testing changing target address config..."), + ?LOG("change_target_addr_config -> entry",[]), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + put(sname,snmp_suite), + put(verbosity,trace), + + MA = whereis(snmp_master_agent), + + ?LOG("change_target_addr_config -> load TestTrap",[]), + ?line load_master("TestTrap"), + + ?LOG("change_target_addr_config -> set trace verbosity for local_db",[]), + ?line snmpa:verbosity(local_db,trace), + + %% First send some traps that will arive att the original manager + ?LOG("change_target_addr_config -> send trap",[]), + try_test(ma_trap1, [MA]), + + ?LOG("change_target_addr_config -> set silence verbosity for local_db",[]), + ?line snmpa:verbosity(local_db,silence), + + %% Start new dummy listener + ?LOG("change_target_addr_config -> start dummy manager",[]), + ?line {ok,Pid,NewPort} = dummy_manager_start(MA), + + %% Reconfigure + ?LOG("change_target_addr_config -> reconfigure",[]), + AgentDir = ?config(agent_dir, Config), + ?line rewrite_target_addr_conf(AgentDir, NewPort), + ?line snmp_target_mib:reconfigure(AgentDir), + + %% Send the trap again + ?LOG("change_target_addr_config -> send trap again",[]), + catch dummy_manager_send_trap2(Pid), + + ?LOG("change_target_addr_config -> await trap ack",[]), + catch dummy_manager_await_trap2_ack(), + + ?LOG("change_target_addr_config -> stop dummy manager",[]), + ?line ok = dummy_manager_stop(Pid), + + ?LOG("change_target_addr_config -> reset target address config",[]), + ?line reset_target_addr_conf(AgentDir), + + ?LOG("change_target_addr_config -> unload TestTrap",[]), + ?line unload_master("TestTrap"). + + +dummy_manager_start(MA) -> + ?DBG("dummy_manager_start -> entry",[]), + Pid = spawn(get(mgr_node), ?MODULE,dummy_manager_init,[self(),MA]), + ?DBG("dummy_manager_start -> Pid: ~p",[Pid]), + await_dummy_manager_started(Pid). + +await_dummy_manager_started(Pid) -> + receive + {dummy_manager_started,Pid,Port} -> + ?DBG("dummy_manager_start -> acknowledge received with" + "~n Port: ~p",[Port]), + {ok,Pid,Port}; + {'EXIT', Pid, Reason} -> + {error, Pid, Reason}; + O -> + ?LOG("dummy_manager_start -> received unknown message:" + "~n ~p",[O]), + await_dummy_manager_started(Pid) + end. + +dummy_manager_stop(Pid) -> + ?DBG("dummy_manager_stop -> entry with Pid: ~p",[Pid]), + Pid ! stop, + receive + {dummy_manager_stopping, Pid} -> + ?DBG("dummy_manager_stop -> acknowledge received",[]), + ok + after 10000 -> + ?ERR("dummy_manager_stop -> timeout",[]), + timeout + end. + +dummy_manager_send_trap2(Pid) -> + ?DBG("dummy_manager_send_trap2 -> entry",[]), + Pid ! {send_trap,testTrap2}. + +dummy_manager_await_trap2_ack() -> + ?DBG("dummy_manager_await_trap2 -> entry",[]), + receive + {received_trap,Trap} -> + ?LOG("dummy_manager_await_trap2 -> received trap: ~p",[Trap]), + %% Note: + %% Without this sleep the v2_inform_i testcase failes! There + %% is no relation between these two test cases as far as I + %% able to figure out... + sleep(60000), + ok; + O -> + ?ERR("dummy_manager_await_trap2 -> unexpected message: ~p",[O]), + ok + after 10000 -> + ?ERR("dummy_manager_await_trap2 -> timeout",[]), + timeout + end. + +dummy_manager_init(Parent,MA) -> + ?DBG("dummy_manager_init -> entry with" + "~n Parent: ~p" + "~n MA: ~p",[Parent,MA]), + {ok,S} = gen_udp:open(0,[{recbuf,65535}]), + ?DBG("dummy_manager_init -> S: ~p",[S]), + {ok,Port} = inet:port(S), + ?DBG("dummy_manager_init -> Port: ~p",[Port]), + Parent ! {dummy_manager_started,self(),Port}, + dummy_manager_loop(Parent,S,MA). + +dummy_manager_loop(P,S,MA) -> + ?LOG("dummy_manager_loop -> ready for receive",[]), + receive + {send_trap,Trap} -> + ?LOG("dummy_manager_loop -> received trap send request" + "~n Trap: ~p",[Trap]), + snmpa:send_trap(MA, Trap, "standard trap"), + dummy_manager_loop(P,S,MA); + {udp, _UdpId, Ip, UdpPort, Bytes} -> + ?LOG("dummy_manager_loop -> received upd message" + "~n from: ~p:~p" + "~n size: ~p", + [Ip, UdpPort, dummy_manager_message_sz(Bytes)]), + R = dummy_manager_handle_message(Bytes), + ?DBG("dummy_manager_loop -> R: ~p",[R]), + P ! R, + dummy_manager_loop(P,S,MA); + stop -> + ?DBG("dummy_manager_loop -> received stop request",[]), + P ! {dummy_manager_stopping, self()}, + gen_udp:close(S), + exit(normal); + O -> + ?LOG("dummy_manager_loop -> received unknown message:" + "~n ~p",[O]), + dummy_manager_loop(P,S,MA) + end. + +dummy_manager_message_sz(B) when binary(B) -> + size(B); +dummy_manager_message_sz(L) when list(L) -> + length(L); +dummy_manager_message_sz(_) -> + undefined. + +dummy_manager_handle_message(Bytes) -> + case (catch snmp_pdus:dec_message(Bytes)) of + {'EXIT',Reason} -> + ?ERR("dummy_manager_handle_message -> " + "failed decoding message only:~n ~p",[Reason]), + {error,Reason}; + M -> + ?DBG("dummy_manager_handle_message -> decoded message:" + "~n ~p",[M]), + {received_trap,M} + end. + + +api(suite) -> []; +api(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(api_test, [node()]), + ?line unload_master("OLD-SNMPEA-MIB"). + +api_2(X) -> api(X). + +api_3(X) -> api(X). + + +subagent(suite) -> []; +subagent(Config) when list(Config) -> + {SaNode, _MgrNode, MibDir} = init_case(Config), + + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), + try_test(load_test_sa), + + p("Testing unregister subagent..."), + MA = whereis(snmp_master_agent), + rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), + try_test(unreg_test), + + p("Loading previous subagent mib in master and testing..."), + ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas1"]), + try_test(load_test), + + p("Unloading previous subagent mib in master and testing..."), + ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas1"]), + try_test(unreg_test), + p("Testing register subagent..."), + rpc:call(SaNode, snmp, register_subagent, + [MA, ?klas1, SA]), + try_test(load_test_sa), + + ?line stop_subagent(SA), + try_test(unreg_test). + +subagent_2(X) -> subagent(X). + +subagent_3(X) -> subagent(X). + + +mnesia(suite) -> []; +mnesia(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Starting subagent with mnesia impl..."), + {ok, SA} = start_subagent(SaNode, ?klas2, "Klas2"), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + + try_test(big_test_2), + + p("Testing unregister subagent..."), + MA = whereis(snmp_master_agent), + rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), + try_test(unreg_test), + ?line unload_master("OLD-SNMPEA-MIB"), + ?line stop_subagent(SA). + +mnesia_2(X) -> mnesia(X). + +mnesia_3(X) -> mnesia(X). + + + +mul_cases() -> +[mul_get, mul_get_err, mul_next, mul_next_err, + mul_set_err]. + + +multiple_reqs_3(_X) -> + {req, [], {conf, init_mul, mul_cases_3(), finish_mul}}. + + +mul_cases_2() -> +[mul_get_2, mul_get_err_2, mul_next_2, mul_next_err_2, + mul_set_err_2]. + + +mul_cases_3() -> + [mul_get_3, mul_get_err_3, mul_next_3, mul_next_err_3, mul_set_err_3]. + + +init_mul(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + [{mul_sub, SA} | Config]. + +finish_mul(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + SA = ?config(mul_sub, Config), + + ?line unload_master("OLD-SNMPEA-MIB"), + ?line stop_subagent(SA), + lists:keydelete(mul_sub, 1, Config). + +mul_get(suite) -> []; +mul_get(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple get..."), + try_test(do_mul_get). + +mul_get_2(X) -> mul_get(X). + +mul_get_3(X) -> mul_get(X). + + +mul_get_err(suite) -> []; +mul_get_err(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple get with error..."), + try_test(do_mul_get_err). + +mul_get_err_2(X) -> mul_get_err(X). + +mul_get_err_3(X) -> mul_get_err(X). + + +mul_next(suite) -> []; +mul_next(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple next..."), + try_test(do_mul_next). + +mul_next_2(X) -> mul_next(X). + +mul_next_3(X) -> mul_next(X). + + +mul_next_err(suite) -> []; +mul_next_err(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple next..."), + try_test(do_mul_next_err). + +mul_next_err_2(X) -> mul_next_err(X). + +mul_next_err_3(X) -> mul_next_err(X). + + +mul_set(suite) -> []; +mul_set(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple set..."), + try_test(do_mul_set). + +mul_set_2(X) -> mul_set(X). + +mul_set_3(X) -> mul_set(X). + + +mul_set_err(suite) -> []; +mul_set_err(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple set with error..."), + try_test(do_mul_set_err). + +mul_set_err_2(X) -> mul_set_err(X). + +mul_set_err_3(X) -> mul_set_err(X). + + +sa_register(suite) -> []; +sa_register(Config) when list(Config) -> + ?DBG("sa_register -> entry", []), + {SaNode, _MgrNode, MibDir} = init_case(Config), + + ?DBG("sa_register -> start subagent", []), + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), + + ?DBG("sa_register -> unregister subagent", []), + p("Testing unregister subagent (2)..."), + MA = whereis(snmp_master_agent), + rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), + try_test(unreg_test), + + p("Loading SA-MIB..."), + ?DBG("sa_register -> unload mibs", []), + snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), + ?DBG("sa_register -> unload mibs", []), + snmpa:load_mibs(SA, [MibDir ++ "SA-MIB"]), + ?DBG("sa_register -> register subagent", []), + rpc:call(SaNode, snmp, register_subagent, [MA,?sa,SA]), + try_test(sa_mib), + + ?DBG("sa_register -> stop subagent", []), + ?line stop_subagent(SA). + +sa_register_2(X) -> sa_register(X). + +sa_register_3(X) -> sa_register(X). + + +v1_trap(suite) -> []; +v1_trap(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Testing trap sending from master agent..."), + MA = whereis(snmp_master_agent), + + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(ma_trap1, [MA]), + try_test(ma_trap2, [MA]), + try_test(ma_v2_2_v1_trap, [MA]), + try_test(ma_v2_2_v1_trap2, [MA]), + + p("Testing trap sending from subagent..."), + try_test(sa_trap1, [SA]), + try_test(sa_trap2, [SA]), + try_test(sa_trap3, [SA]), + + ?line unload_master("TestTrap"), + ?line unload_master("TestTrapv2"), + + ?line stop_subagent(SA). + +v2_trap(suite) -> []; +v2_trap(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Testing trap sending from master agent..."), + MA = whereis(snmp_master_agent), + + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + + try_test(ma_v2_trap1, [MA]), + try_test(ma_v2_trap2, [MA]), + try_test(ma_v1_2_v2_trap, [MA]), + try_test(ma_v1_2_v2_trap2, [MA]), + + try_test(sa_mib), + p("Testing trap sending from subagent..."), + try_test(sa_v1_2_v2_trap1, [SA]), + try_test(sa_v1_2_v2_trap2, [SA]), + try_test(sa_v1_2_v2_trap3, [SA]), + + ?line unload_master("TestTrap"), + ?line unload_master("TestTrapv2"), + + ?line stop_subagent(SA). + +v3_trap(X) -> + v2_trap(X). + + +v3_inform(_X) -> + %% v2_inform(X). + {req, [], {conf, init_v3_inform, [v3_inform_i], finish_v3_inform}}. + +init_v2_inform(Config) when list(Config) -> + _Dir = ?config(agent_dir, Config), +% snmp_internal_mib:configure(Dir), + Config. + +init_v3_inform(X) -> + init_v2_inform(X). + +finish_v2_inform(Config) when list(Config) -> + _Dir = ?config(agent_dir, Config), +% snmp_internal_mib:configure(Dir), + Config. + +finish_v3_inform(X) -> + finish_v2_inform(X). + + + +v2_inform_i(suite) -> []; +v2_inform_i(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing inform sending from master agent... NOTE! This test\ntakes a " + "few minutes (5) to complete."), + MA = whereis(snmp_master_agent), + + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(ma_v2_inform1, [MA]), + + ?line unload_master("TestTrap"), + ?line unload_master("TestTrapv2"). + +v3_inform_i(X) -> v2_inform_i(X). + + +sa_error(suite) -> []; +sa_error(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Testing sa bad value (is_set_ok)..."), + try_test(sa_errs_bad_value), + + p("Testing sa gen err (set)..."), + try_test(sa_errs_gen_err), + + p("Testing too big..."), + try_test(sa_too_big), + + ?line unload_master("OLD-SNMPEA-MIB"), + stop_subagent(SA). + +sa_error_2(X) -> sa_error(X). + +sa_error_3(X) -> sa_error(X). + + +next_across_sa(suite) -> []; +next_across_sa(Config) when list(Config) -> + {SaNode, _MgrNode, MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Loading another subagent mib..."), + ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas1"]), + + rpc:call(SaNode, snmp, register_subagent, [MA, ?klas1, SA]), + try_test(load_test_sa), + + p("Testing next across subagent (endOfMibView from SA)..."), + try_test(next_across_sa), + + p("Unloading mib"), + snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), + rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), + try_test(unreg_test), + + p("Starting another subagent"), + ?line {ok, SA2} = start_subagent(SaNode, ?klas1, "Klas1"), + p("Testing next across subagent (wrong prefix from SA)..."), + try_test(next_across_sa), + + stop_subagent(SA), + stop_subagent(SA2). + +next_across_sa_2(X) -> next_across_sa(X). + +next_across_sa_3(X) -> next_across_sa(X). + + +undo(suite) -> []; +undo(Config) when list(Config) -> + {SaNode, _MgrNode, MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Testing undo phase at master agent..."), + ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas3"]), + ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas4"]), + try_test(undo_test), + try_test(api_test2), + ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas3"]), + + p("Testing bad return values from instrum. funcs..."), + try_test(bad_return), + + ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas4"]), + + p("Testing undo phase at subagent..."), + ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas3"]), + ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas4"]), + ?line ok = snmpa:register_subagent(MA, ?klas3, SA), + ?line ok = snmpa:register_subagent(MA, ?klas4, SA), + try_test(undo_test), + try_test(api_test3), + + p("Testing undo phase across master/subagents..."), + try_test(undo_test), + try_test(api_test3), + stop_subagent(SA). + +undo_2(X) -> undo(X). + +undo_3(X) -> undo(X). + +%% Req. Test2 +v1_processing(suite) -> []; +v1_processing(Config) when list(Config) -> + ?DBG("v1_processing -> entry", []), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + try_test(v1_proc), + ?line unload_master("Test2"). + +%% Req. Test2 +v2_processing(suite) -> []; +v2_processing(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + try_test(v2_proc), + ?line unload_master("Test2"). + +%% Req. Test2 +v3_processing(suite) -> []; +v3_processing(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + try_test(v2_proc), % same as v2! + ?line unload_master("Test2"). + + +%% We'll try get/set/trap and inform for all the auth & priv protocols. +%% For informs, the mgr is auth-engine. The agent has to sync. This is +%% accomplished by the first inform sent. That one will generate a +%% report, which makes it in sync. The notification-generating +%% application times out, and send again. This time it'll work. + +v3_crypto_basic(suite) -> []; +v3_crypto_basic(_Config) -> + EID = [0,0,0,0,0,0,0,0,0,0,0,2], + %% From rfc2274 appendix A.3.1 + ?line KMd5_1 = snmp:passwd2localized_key(md5, "maplesyrup", EID), + ?line [16#52,16#6f,16#5e,16#ed,16#9f,16#cc,16#e2,16#6f, + 16#89,16#64,16#c2,16#93,16#07,16#87,16#d8,16#2b] = + KMd5_1, + %% From rfc2274 appendix A.3.2 + ?line KSHA_1 = snmp:passwd2localized_key(sha, "maplesyrup", EID), + ?line [16#66,16#95,16#fe,16#bc,16#92,16#88,16#e3,16#62,16#82,16#23, + 16#5f,16#c7,16#15,16#1f,16#12,16#84,16#97,16#b3,16#8f,16#3f] = + KSHA_1, + %% From rfc2274, appendix A.5.1 + ?line KMd5_2 = snmp:passwd2localized_key(md5, "newsyrup", EID), + ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#88,16#05,16#61,16#51,16#41,16#67,16#6c,16#c9, + 16#19,16#61,16#74,16#e7,16#42,16#a3,16#25,16#51] = + snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2, 16, + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), + %% From rfc2274, appendix A.5.2 + ?line KSHA_2 = snmp:passwd2localized_key(sha, "newsyrup", EID), + ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#00,16#00,16#00,16#00,16#9c,16#10,16#17,16#f4, + 16#fd,16#48,16#3d,16#2d,16#e8,16#d5,16#fa,16#db, + 16#f8,16#43,16#92,16#cb,16#06,16#45,16#70,16#51] = + snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2, 20, + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), + KSHA_1t = lists:sublist(KSHA_1, 16), + KSHA_2t = lists:sublist(KSHA_2, 16), + ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#7e,16#f8,16#d8,16#a4,16#c9,16#cd,16#b2,16#6b, + 16#47,16#59,16#1c,16#d8,16#52,16#ff,16#88,16#b5] = + snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1t, KSHA_2t, 16, + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), + + %% Try with correct random + ?line Kc1 = snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2), + ?line KMd5_2 = snmp_user_based_sm_mib:extract_new_key(md5, KMd5_1, Kc1), + ?line Kc2 = snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2), + ?line KSHA_2 = snmp_user_based_sm_mib:extract_new_key(sha, KSHA_1, Kc2), + ok. + + + +v3_md5_auth(suite) -> []; +v3_md5_auth(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + p("Testing MD5 authentication...takes a few seconds..."), + + AgentDir = ?config(agent_dir, Config), + ?line rewrite_target_params_conf(AgentDir, "authMD5", authNoPriv), + ?line snmp_target_mib:reconfigure(AgentDir), + + MA = whereis(snmp_master_agent), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(v3_sync, [[{v2_proc, []}, + {ma_v2_trap1, [MA]}, + {v3_inform_sync, [MA]}]], + [{sec_level, authNoPriv}, {user, "authMD5"}]), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + ?line reset_target_params_conf(AgentDir). + +v3_sha_auth(suite) -> []; +v3_sha_auth(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + p("Testing SHA authentication...takes a few seconds..."), + + AgentDir = ?config(agent_dir, Config), + ?line rewrite_target_params_conf(AgentDir, "authSHA", authNoPriv), + ?line snmp_target_mib:reconfigure(AgentDir), + + MA = whereis(snmp_master_agent), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(v3_sync, [[{v2_proc, []}, + {ma_v2_trap1, [MA]}, + {v3_inform_sync, [MA]}]], + [{sec_level, authNoPriv}, {user, "authSHA"}]), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + ?line reset_target_params_conf(AgentDir). + +v3_des_priv(suite) -> []; +v3_des_priv(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + p("Testing DES encryption...takes a few seconds..."), + + AgentDir = ?config(agent_dir, Config), + ?line rewrite_target_params_conf(AgentDir, "privDES", authPriv), + ?line snmp_target_mib:reconfigure(AgentDir), + + MA = whereis(snmp_master_agent), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(v3_sync, [[{v2_proc, []}, + {ma_v2_trap1, [MA]}, + {v3_inform_sync, [MA]}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + ?line reset_target_params_conf(AgentDir). + +%% -define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). + +%% Make sure mgr is in sync with agent +v3_sync(Funcs) -> + ?DBG("v3_sync -> entry with Funcs: ~p",[Funcs]), + g([[sysDescr, 0]]), + expect(432, report, [{?usmStatsNotInTimeWindows_instance, any}]), + g([[sysDescr, 0]]), + expect(433, [{[sysDescr,0], any}]), + lists:foreach(fun({Func, Args}) -> apply(?MODULE, Func, Args) end, Funcs). + +v3_inform_sync(MA) -> + ?DBG("v3_sync -> entry with MA: ~p => Send notification",[MA]), + ?line snmpa:send_notification(MA, testTrapv22, no_receiver, + "standard inform", []), + %% Make sure agent is in sync with mgr... + ?DBG("v3_sync -> wait some time: ",[]), + sleep(20000), % more than 1500*10 in target_addr.conf + ?DBG("v3_sync -> await response",[]), + ?line expect(1, {inform, true}, + [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]). + + +v2_caps(suite) -> []; +v2_caps(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + try_test(v2_caps_i, [node()]). + +v2_caps_3(X) -> v2_caps(X). + + +v2_caps_i(Node) -> + ?line Idx = rpc:call(Node, snmp, add_agent_caps, [[1,2,3,4,5], "test cap"]), + g([[sysORID, Idx], [sysORDescr, Idx]]), + ?line expect(1, [{[sysORID, Idx], [1,2,3,4,5]}, + {[sysORDescr, Idx], "test cap"}]), + ?line rpc:call(Node, snmp, del_agent_caps, [Idx]), + g([[sysORID, Idx]]), + ?line expect(2, [{[sysORID, Idx], noSuchInstance}]). + + +%% Req. Test2 +v1_proc() -> + ?DBG("v1_proc -> entry", []), + %% According to RFC1157. + %% Template:
: + v1_get_p(), + v1_get_next_p(), + v1_set_p(). + + +v1_get_p() -> + %% 4.1.2:1 + g([[test2]]), + ?line expect(10, noSuchName, 1, [{[test2], 'NULL'}]), + g([[tDescr]]), + ?line expect(11, noSuchName, 1, [{[tDescr], 'NULL'}]), + g([[tDescr2,0]]), + ?line expect(12, noSuchName, 1, [{[tDescr2,0], 'NULL'}]), + g([[tDescr3,0]]), + ?line expect(131, noSuchName, 1, [{[tDescr3,0], 'NULL'}]), + g([[tDescr4,0]]), + ?line expect(132, noSuchName, 1, [{[tDescr4,0], 'NULL'}]), + g([[sysDescr, 0], [tDescr,0]]), % Outside mibview + ?line expect(14, noSuchName, 2, [{[sysDescr, 0], 'NULL'}, + {[tDescr,0], 'NULL'}]), + g([[sysDescr,3]]), + ?line expect(15, noSuchName, 1, [{[sysDescr, 3], 'NULL'}]), + + %% 4.1.2:2 + g([[tTable]]), + ?line expect(20, noSuchName, 1, [{[tTable], 'NULL'}]), + g([[tEntry]]), + ?line expect(21, noSuchName, 1, [{[tEntry], 'NULL'}]), + + %% 4.1.2:3 + g([[tTooBig, 0]]), + ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), + + %% 4.1.2:4 + g([[tGenErr1, 0]]), + ?line expect(40, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), + g([[tGenErr2, 0]]), + ?line expect(41, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), + g([[sysDescr, 0], [tGenErr3, 0]]), + ?line expect(42, genErr, 2, [{[sysDescr, 0], 'NULL'}, + {[tGenErr3, 0], 'NULL'}]). + + +v1_get_next_p() -> + %% 4.1.3:1 + gn([[1,3,7,1]]), + ?line expect(10, noSuchName, 1, [{[1,3,7,1], 'NULL'}]), + gn([[tDescr2]]), + ?line expect(11, tooBig, 0, any), + + %% 4.1.3:2 + gn([[tTooBig]]), + io:format("We currently don't handle tooBig correct!!!\n"), +% ?line expect(20, tooBig, 0, [{[tTooBig], 'NULL'}]), + ?line expect(20, tooBig, 0, any), + + %% 4.1.3:3 + gn([[tGenErr1]]), +% ?line expect(40, genErr, 1, [{[tGenErr1], 'NULL'}]), + ?line expect(40, genErr, 1, any), + gn([[tGenErr2]]), +% ?line expect(41, genErr, 1, [{[tGenErr2], 'NULL'}]), + ?line expect(41, genErr, 1, any), + gn([[sysDescr], [tGenErr3]]), +% ?line expect(42, genErr, 2, [{[sysDescr], 'NULL'}, +% {[tGenErr3], 'NULL'}]). + ?line expect(42, genErr, 2, any). + +v1_set_p() -> + %% 4.1.5:1 + s([{[1,3,7,0], i, 4}]), + ?line expect(10, noSuchName, 1, [{[1,3,7,0], 4}]), + s([{[tDescr,0], s, "outside mibview"}]), + ?line expect(11, noSuchName, 1, [{[tDescr,0], "outside mibview"}]), + s([{[tDescr3,0], s, "read-only"}]), + ?line expect(12, noSuchName, 1, [{[tDescr3,0], "read-only"}]), + s([{[tDescr3], s, "noSuchObject"}]), + ?line expect(13, noSuchName, 1, [{[tDescr3], "noSuchObject"}]), + s([{[tDescr3,1], s, "noSuchInstance"}]), + ?line expect(14, noSuchName, 1, [{[tDescr3,1], "noSuchInstance"}]), + s([{[tDescr2,0], s, "inconsistentName"}]), + ?line expect(15, noSuchName, 1, [{[tDescr2,0], "inconsistentName"}]), + + %% 4.1.5:2 + s([{[tDescr2, 0], i, 4}]), + ?line expect(20, badValue, 1, [{[tDescr2, 0], 4}]), + s([{[tDescr2, 0], s, "badValue"}]), + ?line expect(21, badValue, 1, [{[tDescr2, 0], "badValue"}]), + + %% 4.1.5:3 + %% The standard is quite incorrect here. The resp pdu was too big. In + %% the resp pdu, we have the original vbs. In the tooBig pdu we still + %% have to original vbs => the tooBig pdu is too big as well!!! It + %% may not get it to the manager, unless the agent uses 'NULL' instead + %% of the std-like original value. + s([{[tTooBig, 0], s, ?tooBigStr}]), + %% according to std: +% ?line expect(30, tooBig, 0, [{[tTooBig, 0], ?tooBigStr}]), + ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), + + %% 4.1.5:4 + s([{[tDescr2, 0], s, "is_set_ok_fail"}]), + ?line expect(40, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]), + s([{[tDescr2, 0], s, "commit_fail"}]), + ?line expect(41, genErr, 1, [{[tDescr2, 0], "commit_fail"}]). + +%% Req. Test2 +v2_proc() -> + %% According to RFC1905. + %% Template:
: + ?DBG("v2_proc -> entry",[]), + v2_get_p(), + v2_get_next_p(), + v2_get_bulk_p(), + v2_set_p(). + +v2_get_p() -> + %% 4.2.1:2 + ?DBG("v2_get_p -> entry",[]), + g([[test2]]), + ?line expect(10, [{[test2], noSuchObject}]), + g([[tDescr]]), + ?line expect(11, [{[tDescr], noSuchObject}]), + g([[tDescr4,0]]), + ?line expect(12, [{[tDescr4,0], noSuchObject}]), + g([[sysDescr, 0], [tDescr,0]]), % Outside mibview + ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}, + {[tDescr,0], noSuchObject}]), + g([[tTable]]), + ?line expect(14, [{[tTable], noSuchObject}]), + g([[tEntry]]), + ?line expect(15, [{[tEntry], noSuchObject}]), + + %% 4.2.1:3 + g([[tDescr2,0]]), %% instrum ret noSuchName!!! + ?line expect(20, [{[tDescr2,0], noSuchInstance}]), + g([[tDescr3,0]]), + ?line expect(21, [{[tDescr3,0], noSuchInstance}]), + g([[sysDescr,3]]), + ?line expect(22, [{[sysDescr, 3], noSuchInstance}]), + g([[tIndex,1]]), + ?line expect(23, [{[tIndex, 1], noSuchInstance}]), + + %% 4.2.1 - any other error: genErr + g([[tGenErr1, 0]]), + ?line expect(30, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), + g([[tGenErr2, 0]]), + ?line expect(31, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), + g([[sysDescr, 0], [tGenErr3, 0]]), + ?line expect(32, genErr, 2, [{[sysDescr, 0], 'NULL'}, + {[tGenErr3, 0], 'NULL'}]), + + %% 4.2.1 - tooBig + g([[tTooBig, 0]]), + ?line expect(40, tooBig, 0, []). + + +v2_get_next_p() -> + %% 4.2.2:2 + ?DBG("v2_get_next_p -> entry",[]), + gn([[1,3,7,1]]), + ?line expect(10, [{[1,3,7,1], endOfMibView}]), + gn([[sysDescr], [1,3,7,1]]), + ?line expect(11, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}]), + gn([[tCnt2, 1]]), + ?line expect(12, [{[tCnt2,2], 100}]), + gn([[tCnt2, 2]]), + ?line expect(12, [{[tCnt2,2], endOfMibView}]), + + %% 4.2.2 - any other error: genErr + gn([[tGenErr1]]), + ?line expect(20, genErr, 1, [{[tGenErr1], 'NULL'}]), + gn([[tGenErr2]]), + ?line expect(21, genErr, 1, [{[tGenErr2], 'NULL'}]), + gn([[sysDescr], [tGenErr3]]), + ?line expect(22, genErr, 2, [{[sysDescr], 'NULL'}, + {[tGenErr3], 'NULL'}]), + + %% 4.2.2 - tooBig + gn([[tTooBig]]), + ?line expect(20, tooBig, 0, []). + +v2_get_bulk_p() -> + %% 4.2.3 + ?DBG("v2_get_bulk_p -> entry",[]), + gb(1, 1, []), + ?line expect(10, []), + gb(-1, 1, []), + ?line expect(11, []), + gb(-1, -1, []), + ?line expect(12, []), + gb(-1, -1, []), + ?line expect(13, []), + gb(2, 0, [[sysDescr], [1,3,7,1]]), + ?line expect(14, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}]), + gb(1, 2, [[sysDescr], [1,3,7,1]]), + ?line expect(15, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}]), + gb(0, 2, [[sysDescr], [1,3,7,1]]), + ?line expect(16, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}, + {[sysObjectID, 0], [1,2,3]}, + {[1,3,7,1], endOfMibView}]), + + gb(2, 2, [[sysDescr], [1,3,7,1], [sysDescr], [1,3,7,1]]), + ?line expect(17, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}, + {[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}, + {[sysObjectID, 0], [1,2,3]}, + {[1,3,7,1], endOfMibView}]), + + gb(1, 2, [[sysDescr], [sysDescr], [tTooBig]]), + ?line expect(18, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[sysDescr, 0], "Erlang SNMP agent"}]), + + gb(1,12, [[tDescr2], [sysDescr]]), % next one after tDescr2 is tTooBig. + ?line expect(19, []), + + gb(2,2, [[sysDescr], [sysObjectID], [tGenErr1], [sysDescr]]), + ?line expect(20, genErr, 3, [{[sysDescr], 'NULL'}, + {[sysObjectID], 'NULL'}, + {[tGenErr1], 'NULL'}, + {[sysDescr], 'NULL'}]), + gb(0, 2, [[tCnt2, 1]]), + ?line expect(21, [{[tCnt2,2], 100}, + {[tCnt2,2], endOfMibView}]). + + +v2_set_p() -> + %% 4.2.5:1 + ?DBG("v2_set_p -> entry",[]), + s([{[1,3,7,0], i, 4}]), + ?line expect(10, noAccess, 1, [{[1,3,7,0], 4}]), + s([{[tDescr,0], s, "outside mibview"}]), + ?line expect(11, noAccess, 1, [{[tDescr,0], "outside mibview"}]), + + %% 4.2.5:2 + s([{[1,3,6,1,0], s, "noSuchObject"}]), + ?line expect(20, notWritable, 1, [{[1,3,6,1,0], "noSuchObject"}]), + + %% 4.2.5:3 + s([{[tDescr2, 0], i, 4}]), + ?line expect(30, wrongType, 1, [{[tDescr2, 0], 4}]), + s([{[tDescr2, 0], s, "badValue"}]), + ?line expect(31, badValue, 1, [{[tDescr2, 0], "badValue"}]), + + %% 4.2.5:4 + s([{[tStr, 0], s, ""}]), + ?line expect(40, wrongLength, 1, [{[tStr, 0], ""}]), + s([{[tStr, 0], s, "12345"}]), + ?line expect(40, wrongLength, 1, [{[tStr, 0], "12345"}]), + + %% 4.2.5:5 - N/A + + %% 4.2.5:6 + s([{[tInt1, 0], i, 0}]), + ?line expect(60, wrongValue, 1, [{[tInt1, 0], 0}]), + s([{[tInt1, 0], i, 5}]), + ?line expect(61, wrongValue, 1, [{[tInt1, 0], 5}]), + s([{[tInt2, 0], i, 0}]), + ?line expect(62, wrongValue, 1, [{[tInt2, 0], 0}]), + s([{[tInt2, 0], i, 5}]), + ?line expect(63, wrongValue, 1, [{[tInt2, 0], 5}]), + s([{[tInt3, 0], i, 5}]), + ?line expect(64, wrongValue, 1, [{[tInt3, 0], 5}]), + + %% 4.2.5:7 + s([{[tDescrX, 1, 1], s, "noCreation"}]), + ?line expect(70, noCreation, 1, [{[tDescrX, 1, 1], "noCreation"}]), + + %% 4.2.5:8 + s([{[tDescrX, 1, 2], s, "inconsistentName"}]), + ?line expect(80, inconsistentName, 1, + [{[tDescrX, 1, 2], "inconsistentName"}]), + + %% 4.2.5:9 + s([{[tCnt, 1, 2], i, 5}]), + ?line expect(90, notWritable, 1, [{[tCnt, 1, 2], 5}]), + s([{[tDescr3,0], s, "read-only"}]), + ?line expect(90, notWritable, 1, [{[tDescr3,0], "read-only"}]), + + %% 4.2.5:10 + s([{[tDescr2,0], s, "inconsistentValue"}]), + ?line expect(100, inconsistentValue, 1, + [{[tDescr2,0], "inconsistentValue"}]), + + %% 4.2.5:11 + s([{[tDescr2,0], s, "resourceUnavailable"}]), + ?line expect(110, resourceUnavailable, 1, + [{[tDescr2,0],"resourceUnavailable"}]), + + %% 4.2.5:12 + s([{[tDescr2, 0], s, "is_set_ok_fail"}]), + ?line expect(120, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]). + + %% commitFailed and undoFailed is tested by the 'undo' case. + + +%% Req. OLD-SNMPEA-MIB +table_test() -> + io:format("Testing simple get, next and set on communityTable...~n"), +%% {[147,214,36,45], "public", 2, readWrite}. +%% {[147,214,36,45], "standard trap", 2, read}. + Key1c3 = [intCommunityViewIndex,get(mip),is("public")], + Key2c3 = [intCommunityViewIndex,get(mip),is("standard trap")], + Key1c4 = [intCommunityAccess,get(mip),is("public")], + EndKey = [intCommunityEntry,[9],get(mip),is("public")], + gn([[intCommunityEntry]]), + ?line expect(7, [{Key1c3, 2}]), + gn([[intCommunityTable]]), + ?line expect(71, [{Key1c3, 2}]), + gn([[community]]), + ?line expect(72, [{Key1c3, 2}]), + gn([[otpSnmpeaMIB]]), + ?line expect(73, [{Key1c3, 2}]), + gn([[ericsson]]), + ?line expect(74, [{Key1c3, 2}]), + gn([Key1c3]), + ?line expect(8, [{Key2c3, 2}]), + gn([Key2c3]), + ?line expect(9, [{Key1c4, 2}]), + gn([EndKey]), + AgentIp = [intAgentIpAddress,0], + ?line expect(10, [{AgentIp, any}]), + g([Key1c3]), + ?line expect(11, [{Key1c3, 2}]), + g([EndKey]), + ?line ?v1_2(expect(12, noSuchName, 1, any), + expect(12, [{EndKey, noSuchObject}])), + + io:format("Testing row creation/deletion on communityTable...~n"), + NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], + NewKeyc4 = [intCommunityAccess,get(mip),is("test")], + NewKeyc5 = [intCommunityStatus,get(mip),is("test")], + s([{NewKeyc5, ?createAndGo}]), + ?line expect(14, ?v1_2(badValue, inconsistentValue), 1,any), + s([{NewKeyc5, ?createAndGo}, {NewKeyc3, 2}, {NewKeyc4, 2}]), + ?line expect(15, [{NewKeyc5, ?createAndGo},{NewKeyc3, 2}, {NewKeyc4, 2}]), + g([NewKeyc4]), + ?line expect(16, [{NewKeyc4, 2}]), + s([{NewKeyc5, ?destroy}]), + ?line expect(17, [{NewKeyc5, ?destroy}]), + s([{NewKeyc4, 2}]), + ?line expect(18, ?v1_2(noSuchName, inconsistentName), 1,[{NewKeyc4, 2}]), + s([{NewKeyc5, ?createAndWait}]), + ?line expect(19, [{NewKeyc5, ?createAndWait}]), + g([NewKeyc5]), + ?line expect(20, [{NewKeyc5, ?notReady}]), + s([{NewKeyc4, 2}]), + ?line expect(21, [{NewKeyc4, 2}]), + g([NewKeyc5]), + ?line expect(22, [{NewKeyc5, ?notReady}]), + s([{NewKeyc3, 2}]), + ?line expect(23, [{NewKeyc3, 2}]), + g([NewKeyc5]), + ?line expect(24, [{NewKeyc5, ?notInService}]), + s([{NewKeyc5, ?active}]), + ?line expect(25, [{NewKeyc5, ?active}]), + s([{NewKeyc5, ?destroy}]), + ?line expect(26, [{NewKeyc5, ?destroy}]), + s([{NewKeyc3, 3}]), + ?line expect(27, ?v1_2(noSuchName, inconsistentName), 1,[{NewKeyc3, 3}]), + otp_1128(). + +%% Req. system group +simple_standard_test() -> + ?DBG("simple_standard_test -> entry",[]), + gn([[1,1]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3]]), + ?line expect(11, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6]]), + ?line expect(12, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6,1]]), + ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6,1,2]]), + ?line expect(14, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6,1,2,1]]), + ?line expect(15, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6,1,2,1,1]]), + ?line expect(16, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[sysDescr]]), + ?line expect(17, [{[sysDescr,0], "Erlang SNMP agent"}]), + g([[sysDescr,0]]), + ?line expect(2, [{[sysDescr,0], "Erlang SNMP agent"}]), + g([[sysDescr]]), + ?line ?v1_2(expect(3, noSuchName, 1, any), + expect(3, [{[sysDescr], noSuchObject}])), + g([[1,6,7,0]]), + ?line ?v1_2(expect(41, noSuchName, 1, any), + expect(3, [{[1,6,7,0], noSuchObject}])), + gn([[1,13]]), + ?line ?v1_2(expect(4, noSuchName,1, any), + expect(4, [{[1,13], endOfMibView}])), + s([{[sysLocation, 0], "new_value"}]), + ?line expect(5, [{[sysLocation, 0], "new_value"}]), + g([[sysLocation, 0]]), + ?line expect(6, [{[sysLocation, 0], "new_value"}]), + io:format("Testing noSuchName and badValue...~n"), + s([{[sysServices,0], 3}]), + ?line expect(61, ?v1_2(noSuchName, notWritable), 1, any), + s([{[sysLocation, 0], i, 3}]), + ?line expect(62, ?v1_2(badValue, wrongType), 1, any), + ?DBG("simple_standard_test -> done",[]), + ok. + +%% This is run in the agent node +db_notify_client(suite) -> []; +db_notify_client(Config) when list(Config) -> + {SaNode, MgrNode, MibDir} = init_case(Config), + ?DBG("~n\tSaNode: ~p~n\tMgrNode: ~p~n\tMibDir: ~p", + [SaNode,MgrNode,MibDir]), + snmpa_local_db:register_notify_client(self(),?MODULE), + + %% This call (the manager) will issue to set operations, so + %% we expect to receive to notify(insert) calls. + try_test(db_notify_client_test), + + ?DBG("await first notify",[]), + receive + {db_notify_test_reply,insert} -> ?DBG("first notify received",[]),ok + end, + + ?DBG("await second notify",[]), + receive + {db_notify_test_reply,insert} -> ?DBG("second notify received",[]),ok + end, + + snmpa_local_db:unregister_notify_client(self()). + + +%% This is run in the manager node +db_notify_client_test() -> + ?DBG("set first new sysLocation",[]), + s([{[sysLocation, 0], "new_value"}]), + ?line expect(5, [{[sysLocation, 0], "new_value"}]), + + ?DBG("set second new sysLocation",[]), + s([{[sysLocation, 0], "new_value"}]), + ?line expect(5, [{[sysLocation, 0], "new_value"}]). + +notify(Pid,What) -> + ?DBG("notify(~p,~p) -> called",[Pid,What]), + Pid ! {db_notify_test_reply,What}. + + +%% Req: system group, OLD-SNMPEA-MIB, Klas1 +big_test() -> + ?DBG("big_test -> testing simple next/get/set @ master agent...",[]), + simple_standard_test(), + + ?DBG("big_test -> testing simple next/get/set @ subagent...",[]), + gn([[klas1]]), + ?line expect(1, [{[fname,0], ""}]), + g([[fname,0]]), + ?line expect(2, [{[fname,0], ""}]), + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + g([[fname,0]]), + ?line expect(4, [{[fname,0], "test set"}]), + + ?DBG("big_test -> " + "testing next from last instance in master to subagent...",[]), + gn([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(5, [{[fname,0], "test set"}]), + gn([[1,1], + [?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, + {[fname,0], "test set"}]), + s([{[fname,0], s, ""}]), + ?line expect(52, [{[fname,0], ""}]), + + table_test(), + + ?DBG("big_test -> adding one row in subagent table",[]), + _FTab = [friendsEntry], + s([{[friendsEntry, [2, 3]], s, "kompis3"}, + {[friendsEntry, [3, 3]], i, ?createAndGo}]), + ?line expect(6, [{[friendsEntry, [2, 3]], "kompis3"}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + g([[friendsEntry, [2, 3]], + [friendsEntry, [3, 3]]]), + ?line expect(7, [{[friendsEntry, [2, 3]], "kompis3"}, + {[friendsEntry, [3, 3]], ?active}]), + s([{[friendsEntry, [3, 3]], i, ?destroy}]), + ?line expect(8, [{[friendsEntry, [3, 3]], ?destroy}]), + + otp_1131(), + + ?DBG("big_test -> adding two rows in subagent table with special INDEX", + []), + s([{[kompissEntry, [1, 3]], s, "kompis3"}, + {[kompissEntry, [2, 3]], i, ?createAndGo}]), + ?line expect(9, [{[kompissEntry, [1, 3]], "kompis3"}, + {[kompissEntry, [2, 3]], ?createAndGo}]), + g([[kompissEntry, [1, 3]], + [kompissEntry, [2, 3]]]), + ?line expect(10, [{[kompissEntry, [1, 3]], "kompis3"}, + {[kompissEntry, [2, 3]], ?active}]), + gn([[kompissEntry, [1]], + [kompissEntry, [2]]]), + ?line expect(11, [{[kompissEntry, [1, 3]], "kompis3"}, + {[kompissEntry, [2, 3]], ?active}]), + s([{[kompissEntry, [1, 2]], s, "kompis3"}, + {[kompissEntry, [2, 2]], i, ?createAndGo}]), + ?line expect(12, [{[kompissEntry, [1, 2]], "kompis3"}, + {[kompissEntry, [2, 2]], ?createAndGo}]), + gn([[kompissEntry, [1, 1]], + [kompissEntry, [2, 1]]]), + ?line expect(13, [{[kompissEntry, [1, 2]], "kompis3"}, + {[kompissEntry, [2, 2]], ?active}]), + s([{[kompissEntry, [2, 3]], i, ?destroy}]), + ?line expect(14, [{[kompissEntry, [2, 3]], ?destroy}]), + s([{[kompissEntry, [2, 2]], i, ?destroy}]), + ?line expect(15, [{[kompissEntry, [2, 2]], ?destroy}]), + ?DBG("big_test -> done",[]), + ok. + +%% Req. system group, Klas2, OLD-SNMPEA-MIB +big_test_2() -> + p("Testing simple next/get/set @ master agent (2)..."), + simple_standard_test(), + + p("Testing simple next/get/set @ subagent (2)..."), + gn([[klas2]]), + ?line expect(1, [{[fname2,0], ""}]), + g([[fname2,0]]), + ?line expect(2, [{[fname2,0], ""}]), + s([{[fname2,0], s, "test set"}]), + ?line expect(3, [{[fname2,0], "test set"}]), + g([[fname2,0]]), + ?line expect(4, [{[fname2,0], "test set"}]), + + otp_1298(), + + p("Testing next from last object in master to subagent (2)..."), + gn([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(5, [{[fname2,0], "test set"}]), + gn([[1,1], + [?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, + {[fname2,0], "test set"}]), + + table_test(), + + p("Adding one row in subagent table (2)"), + _FTab = [friendsEntry2], + s([{[friendsEntry2, [2, 3]], s, "kompis3"}, + {[friendsEntry2, [3, 3]], i, ?createAndGo}]), + ?line expect(6, [{[friendsEntry2, [2, 3]], "kompis3"}, + {[friendsEntry2, [3, 3]], ?createAndGo}]), + g([[friendsEntry2, [2, 3]], + [friendsEntry2, [3, 3]]]), + ?line expect(7, [{[friendsEntry2, [2, 3]], "kompis3"}, + {[friendsEntry2, [3, 3]], ?active}]), + s([{[friendsEntry2, [3, 3]], i, ?destroy}]), + ?line expect(8, [{[friendsEntry2, [3, 3]], ?destroy}]), + + p("Adding two rows in subagent table with special INDEX (2)"), + s([{[kompissEntry2, [1, 3]], s, "kompis3"}, + {[kompissEntry2, [2, 3]], i, ?createAndGo}]), + ?line expect(9, [{[kompissEntry2, [1, 3]], "kompis3"}, + {[kompissEntry2, [2, 3]], ?createAndGo}]), + g([[kompissEntry2, [1, 3]], + [kompissEntry2, [2, 3]]]), + ?line expect(10, [{[kompissEntry2, [1, 3]], "kompis3"}, + {[kompissEntry2, [2, 3]], ?active}]), + gn([[kompissEntry2, [1]], + [kompissEntry2, [2]]]), + ?line expect(11, [{[kompissEntry2, [1, 3]], "kompis3"}, + {[kompissEntry2, [2, 3]], ?active}]), + s([{[kompissEntry2, [1, 2]], s, "kompis3"}, + {[kompissEntry2, [2, 2]], i, ?createAndGo}]), + ?line expect(12, [{[kompissEntry2, [1, 2]], "kompis3"}, + {[kompissEntry2, [2, 2]], ?createAndGo}]), + gn([[kompissEntry2, [1, 1]], + [kompissEntry2, [2, 1]]]), + ?line expect(13, [{[kompissEntry2, [1, 2]], "kompis3"}, + {[kompissEntry2, [2, 2]], ?active}]), + s([{[kompissEntry2, [2, 3]], i, ?destroy}]), + ?line expect(14, [{[kompissEntry2, [2, 3]], ?destroy}]), + s([{[kompissEntry2, [2, 2]], i, ?destroy}]), + ?line expect(15, [{[kompissEntry2, [2, 2]], ?destroy}]), + ok. + +%% Req. Test1 +multi_threaded_test() -> + p("Testing multi threaded agent..."), + g([[multiStr,0]]), + Pid = get_multi_pid(), + g([[sysUpTime,0]]), + ?line expect(1, [{[sysUpTime,0], any}]), + s([{[sysLocation, 0], s, "pelle"}]), + ?line expect(2, [{[sysLocation, 0], "pelle"}]), + Pid ! continue, + ?line expect(3, [{[multiStr,0], "ok"}]), + + s([{[multiStr, 0], s, "block"}]), + Pid2 = get_multi_pid(), + g([[sysUpTime,0]]), + ?line expect(4, [{[sysUpTime,0], any}]), + g([[multiStr,0]]), + Pid3 = get_multi_pid(), + g([[sysUpTime,0]]), + ?line expect(5, [{[sysUpTime,0], any}]), + s([{[sysLocation, 0], s, "kalle"}]), + Pid3 ! continue, + ?line expect(6, [{[multiStr,0], "ok"}]), + Pid2 ! continue, + ?line expect(7, [{[multiStr,0], "block"}]), + ?line expect(8, [{[sysLocation,0], "kalle"}]). + +%% Req. Test1, TestTrapv2 +mt_trap_test(MA) -> + snmpa:send_trap(MA, testTrapv22, "standard trap"), + ?line expect(1, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + + snmpa:send_trap(MA, mtTrap, "standard trap"), + Pid = get_multi_pid(), + g([[sysUpTime,0]]), + ?line expect(2, [{[sysUpTime,0], any}]), + snmpa:send_trap(MA, testTrapv22, "standard trap"), + ?line expect(3, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + Pid ! continue, + ?line expect(4, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?testTrap ++ [2]}, + {[multiStr,0], "ok"}]). + + +get_multi_pid() -> + get_multi_pid(10). +get_multi_pid(0) -> + ?line ?FAIL(no_global_name); +get_multi_pid(N) -> + sleep(1000), + case global:whereis_name(snmp_multi_tester) of + Pid when pid(Pid) -> Pid; + _ -> get_multi_pid(N-1) + end. + +%% Req. Test1 +types_v2_test() -> + p("Testing v2 types..."), + + s([{[bits1,0], 2#10}]), + ?line expect(1, [{[bits1,0], ?str(2#10)}]), + g([[bits1,0]]), + ?line expect(2, [{[bits1,0], ?str(2#101)}]), + + s([{[bits2,0], 2#11000000110}]), + ?line expect(3, [{[bits2,0], ?str(2#11000000110)}]), + g([[bits2,0]]), + ?line expect(4, [{[bits2,0], ?str(2#11000000110)}]), + + g([[bits3,0]]), + ?line expect(50, genErr, 1, any), + + g([[bits4,0]]), + ?line expect(51, genErr, 1, any), + + s([{[bits1,0], s, [2#10]}]), + ?line expect(6, ?v1_2(badValue, wrongValue), 1, any), + + s([{[bits2,0], 2#11001001101010011}]), + ?line expect(7, ?v1_2(badValue, wrongValue), 1, any). + + +%% Req. Test1 +implied_test(MA) -> + ?LOG("implied_test -> start",[]), + p("Testing IMPLIED..."), + + snmpa:verbosity(MA,trace), + snmpa:verbosity(MA,trace), + + %% Create two rows, check that they are get-nexted in correct order. + Idx1 = "apa", + Idx2 = "qq", + ?DBG("implied_test -> (send) create row 1 '~s' in table 1",[Idx1]), + s([{[testStatus, Idx1], i, ?createAndGo}, {[testDescr, Idx1],s,"row 1"}]), + ?line expect(1, [{[testStatus, Idx1], ?createAndGo}, + {[testDescr, Idx1], "row 1"}]), + ?DBG("implied_test -> (send) create row 2 '~s' in table 1",[Idx2]), + s([{[testStatus, Idx2], i, ?createAndGo}, {[testDescr, Idx2],s,"row 2"}]), + ?line expect(2, [{[testStatus, Idx2], ?createAndGo}, + {[testDescr, Idx2], "row 2"}]), + ?DBG("implied_test -> get-next(testDescr)",[]), + gn([[testDescr]]), + ?line expect(3, [{[testDescr,Idx1], "row 1"}]), + ?DBG("implied_test -> get-next(testDescr) of row 1",[]), + gn([[testDescr,Idx1]]), + ?line expect(4, [{[testDescr,Idx2], "row 2"}]), + + % Delete the rows + ?DBG("implied_test -> (send) delete row 1 '~s' from table 1",[Idx1]), + s([{[testStatus, Idx1], i, ?destroy}]), + ?line expect(5, [{[testStatus, Idx1], ?destroy}]), + ?DBG("implied_test -> (send) delete row 2 '~s' from table 1",[Idx2]), + s([{[testStatus, Idx2], i, ?destroy}]), + ?line expect(6, [{[testStatus, Idx2], ?destroy}]), + + %% Try the same in other table + Idx3 = [1, "apa"], + Idx4 = [1, "qq"], + ?DBG("implied_test -> (send) create row 1 '~s' in table 2",[Idx3]), + s([{[testStatus2, Idx3], i, ?createAndGo}, {[testDescr2,Idx3],s,"row 1"}]), + ?line expect(1, [{[testStatus2, Idx3], ?createAndGo}, + {[testDescr2, Idx3], "row 1"}]), + ?DBG("implied_test -> (send) create row 2 '~s' in table 2",[Idx4]), + s([{[testStatus2, Idx4], i, ?createAndGo}, {[testDescr2,Idx4],s,"row 2"}]), + ?line expect(2, [{[testStatus2, Idx4], ?createAndGo}, + {[testDescr2, Idx4], "row 2"}]), + ?DBG("implied_test -> get-next(testDescr2)",[]), + gn([[testDescr2]]), + ?line expect(3, [{[testDescr2,Idx3], "row 1"}]), + ?DBG("implied_test -> get-next(testDescr2) of row 1",[]), + gn([[testDescr2,Idx3]]), + ?line expect(4, [{[testDescr2,Idx4], "row 2"}]), + + % Delete the rows + ?DBG("implied_test -> (send) delete row 1 '~s' from table 2",[Idx3]), + s([{[testStatus2, Idx3], i, ?destroy}]), + ?line expect(5, [{[testStatus2, Idx3], ?destroy}]), + ?DBG("implied_test -> (send) delete row 2 '~s' from table 2",[Idx4]), + s([{[testStatus2, Idx4], i, ?destroy}]), + ?line expect(6, [{[testStatus2, Idx4], ?destroy}]), + + snmpa:verbosity(MA,log), + + ?LOG("implied_test -> done",[]). + + + +%% Req. Test1 +sparse_table_test() -> + p("Testing sparse table..."), + + %% Create two rows, check that they are get-nexted in correct order. + Idx1 = 1, + Idx2 = 2, + s([{[sparseStatus, Idx1], i, ?createAndGo}, + {[sparseDescr, Idx1], s, "row 1"}]), + ?line expect(1, [{[sparseStatus, Idx1], ?createAndGo}, + {[sparseDescr, Idx1], "row 1"}]), + s([{[sparseStatus, Idx2], i, ?createAndGo}, + {[sparseDescr, Idx2], s, "row 2"}]), + ?line expect(2, [{[sparseStatus, Idx2], ?createAndGo}, + {[sparseDescr, Idx2], "row 2"}]), + ?v1_2(gn([[sparseIndex], [sparseDescr,Idx1], [sparseDescr,Idx2], + [sparseStatus,Idx1], [sparseStatus,Idx2]]), + gb(0,5,[[sparseIndex]])), + ?line expect(3, [{[sparseDescr,Idx1], "row 1"}, + {[sparseDescr,Idx2], "row 2"}, + {[sparseStatus,Idx1], ?active}, + {[sparseStatus,Idx2], ?active}, + {[sparseStr,0], "slut"}]), + % Delete the rows + s([{[sparseStatus, Idx1], i, ?destroy}]), + ?line expect(4, [{[sparseStatus, Idx1], ?destroy}]), + s([{[sparseStatus, Idx2], i, ?destroy}]), + ?line expect(5, [{[sparseStatus, Idx2], ?destroy}]). + + +%% Req. Test1 +cnt_64_test(MA) -> + ?LOG("start cnt64 test (~p)",[MA]), + snmpa:verbosity(MA,trace), + ?LOG("start cnt64 test",[]), + p("Testing Counter64, and at the same time, RowStatus is not last column"), + + ?DBG("get cnt64",[]), + g([[cnt64,0]]), + ?DBG("await response",[]), + ?line ?v1_2(expect(1, noSuchName, 1, any), + expect(1, [{[cnt64,0],18446744073709551615}])), + ?DBG("get-next cnt64",[]), + gn([[cnt64]]), + ?DBG("await response",[]), + ?line ?v1_2(expect(2, [{[cnt64Str,0], "after cnt64"}]), + expect(2, [{[cnt64,0],18446744073709551615}])), + ?DBG("send cntTrap",[]), + snmpa:send_trap(MA,cntTrap,"standard trap",[{sysContact,"pelle"}, + {cnt64, 10}, + {sysLocation, "here"}]), + ?DBG("await response",[]), + ?line ?v1_2(expect(3, trap, [test], 6, 1, [{[sysContact,0], "pelle"}, + {[sysLocation,0], "here"}]), + expect(3, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?testTrap ++ [1]}, + {[sysContact,0], "pelle"}, + {[cnt64,0], 10}, + {[sysLocation,0], "here"}])), + + %% Create two rows, check that they are get-nexted in correct order. + Idx1 = 1, + Idx2 = 2, + ?DBG("create row (cntStatus): ~p",[Idx1]), + s([{[cntStatus, Idx1], i, ?createAndGo}]), + ?DBG("await response",[]), + ?line expect(1, [{[cntStatus, Idx1], ?createAndGo}]), + ?DBG("create row (cntStatus): ~p",[Idx2]), + s([{[cntStatus, Idx2], i, ?createAndGo}]), + ?DBG("await response",[]), + ?line expect(2, [{[cntStatus, Idx2], ?createAndGo}]), + + ?DBG("get-next (cntIndex)",[]), + gn([[cntIndex]]), + ?DBG("await response",[]), + ?line ?v1_2(expect(3, [{[cntStatus,Idx1], ?active}]), + expect(3, [{[cntCnt,Idx1], 0}])), + % Delete the rows + ?DBG("delete row (cntStatus): ~p",[Idx1]), + s([{[cntStatus, Idx1], i, ?destroy}]), + ?DBG("await response",[]), + ?line expect(4, [{[cntStatus, Idx1], ?destroy}]), + ?DBG("delete row (cntStatus): ~p",[Idx2]), + s([{[cntStatus, Idx2], i, ?destroy}]), + ?DBG("await response",[]), + ?line expect(5, [{[cntStatus, Idx2], ?destroy}]), + catch snmpa:verbosity(MA,log), + ?DBG("done",[]), + ok. + +%% Req. Test1 +opaque_test() -> + p("Testing Opaque datatype..."), + g([[opaqueObj,0]]), + ?line expect(1, [{[opaqueObj,0], "opaque-data"}]). + +%% Req. OLD-SNMPEA-MIB +api_test(MaNode) -> + ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, + [intAgentIpAddress]), + ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, + oid_to_name, [OID]), + ?line false = rpc:call(MaNode, snmp, name_to_oid, [intAgentIpAddres]), + ?line false = rpc:call(MaNode, snmp, oid_to_name, + [[1,5,32,3,54,3,3,34,4]]), + ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, + [intViewType, excluded]), + ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, + [intViewType, 2]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, [intViewType, exclude]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [intAgentIpAddress, exclude]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [intAgentIpAddre, exclude]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [intViewType, 3]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddress, 2]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddre, 2]), + ?line {value, active} = rpc:call(MaNode, snmp, + int_to_enum, ['RowStatus', ?active]), + ?line {value, ?destroy} = rpc:call(MaNode, snmp, + enum_to_int, ['RowStatus', destroy]), + ?line false = rpc:call(MaNode, snmp, + enum_to_int, ['RowStatus', xxxdestroy]), + ?line false = rpc:call(MaNode, snmp, + enum_to_int, ['xxRowStatus', destroy]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, ['RowStatus', 25]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, ['xxRowStatus', 1]), + ?line case snmp:date_and_time() of + List when list(List), length(List) == 8 -> ok; + List when list(List), length(List) == 11 -> ok + end. + +%% Req. Klas3 +api_test2() -> + g([[fname3,0]]), + ?line expect(1, [{[fname3,0], "ok"}]), + g([[fname4,0]]), + ?line expect(2, [{[fname4,0], 1}]). + +api_test3() -> + g([[fname3,0]]), + ?line expect(1, [{[fname3,0], "ok"}]). + + +unreg_test() -> + gn([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(1, [{[snmpInPkts, 0], any}]). + +load_test() -> + gn([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(1, [{[fname,0], ""}]). + +%% Req. Klas1 +load_test_sa() -> + gn([[?v1_2(sysServices,sysORLastChange), 0]]), + ?line expect(1, [{[fname,0], any}]). + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_get() -> + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + g([[sysDescr,0], Key1c4, [fname,0],Key1c3, + [sysName,0]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[fname,0], "test set"}, + {Key1c3, 2}, + {[sysName,0], "test"}]), + g([[1,3,7,1], Key1c4, [sysDescr,0], [1,3,7,2], Key1c3, [sysDescr,0]]), + ?line ?v1_2(expect(2, noSuchName, [1,4], any), + expect(2, [{[1,3,7,1], noSuchObject}, + {Key1c4, 2}, + {[sysDescr,0], "Erlang SNMP agent"}, + {[1,3,7,2], noSuchObject}, + {Key1c3, 2}, + {[sysDescr,0], "Erlang SNMP agent"}])). + +%% Req. v1, system group, Klas1, OLD-SNMPEA-MIB, *ej* Klas3. +do_mul_get_err() -> + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + g([[sysDescr,0],Key1c4,[fname,0], Key1c3, [sysName,2]]), + ?line ?v1_2(expect(1, noSuchName, 5, any), + expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[fname,0], "test set"}, + {Key1c3, 2}, + {[sysName,2], noSuchInstance}])), + g([[sysDescr,0],Key1c4,[fname3,0], Key1c3, [sysName,1]]), + ?line ?v1_2(expect(1, noSuchName, [3,5], any), + expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[fname3,0], noSuchObject}, + {Key1c3, 2}, + {[sysName,1], noSuchInstance}])). + + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_next() -> + Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], + Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + gn([[sysDescr], Key1c4s, [fname],Key1c3s,[sysName]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, {[fname,0], "test set"}, + {Key1c3, 2}, {[sysName,0], "test"}]). + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_next_err() -> + Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], + Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + gn([[sysDescr], Key1c4s, [1,3,6,999], [fname],[1,3,90], Key1c3s,[sysName]]), + ?line ?v1_2(expect(1, noSuchName, [3,5], any), + expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[1,3,6,999], endOfMibView}, + {[fname,0], "test set"}, + {[1,3,90], endOfMibView}, + {Key1c3, 2}, + {[sysName,0], "test"}])). + + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_set() -> + p("Adding one row in subagent table, and one in master table"), + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + s([{[friendsEntry, [2, 3]], "kompis3"}, + {NewKeyc3, 2}, + {[sysLocation,0], "new_value"}, + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + ?line expect(1, [{[friendsEntry, [2, 3]], "kompis3"}, + {NewKeyc3, 2}, + {[sysLocation,0], "new_value"}, + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + g([[friendsEntry, [2, 3]], + [sysLocation,0], + [friendsEntry, [3, 3]]]), + ?line expect(2, [{[friendsEntry, [2, 3]], "kompis3"}, + {[sysLocation,0], "new_value"}, + {[friendsEntry, [3, 3]], ?active}]), + g([NewKeyc4]), + ?line expect(3, [{NewKeyc4, 2}]), + s([{[friendsEntry, [3, 3]], ?destroy}, + {NewKeyc5, ?destroy}]), + ?line expect(4, [{[friendsEntry, [3, 3]], ?destroy}, + {NewKeyc5, ?destroy}]). + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_set_err() -> + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + p("Adding one row in subagent table, and one in master table"), + s([{[friendsEntry, [2, 3]], s, "kompis3"}, + {NewKeyc3, 2}, + {[sysUpTime,0], 45}, % sysUpTime (readOnly) + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + ?line expect(1, ?v1_2(noSuchName, notWritable), 3, any), + g([[friendsEntry, [2, 3]]]), + ?line ?v1_2(expect(2, noSuchName, 1, any), + expect(2, [{[friendsEntry, [2,3]], noSuchInstance}])), + g([NewKeyc4]), + ?line ?v1_2(expect(3, noSuchName, 1, any), + expect(3, [{NewKeyc4, noSuchInstance}])). + +%% Req. SA-MIB +sa_mib() -> + g([[sa, [2,0]]]), + ?line expect(1, [{[sa, [2,0]], 3}]), + s([{[sa, [1,0]], s, "sa_test"}]), + ?line expect(2, [{[sa, [1,0]], "sa_test"}]). + +ma_trap1(MA) -> + snmpa:send_trap(MA, testTrap2, "standard trap"), + ?line expect(1, trap, [system], 6, 1, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}]), + snmpa:send_trap(MA, testTrap1, "standard trap"), + ?line expect(2, trap, [1,2,3] , 1, 0, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}]). + +ma_trap2(MA) -> + snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). + +ma_v2_2_v1_trap(MA) -> + snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). + +ma_v2_2_v1_trap2(MA) -> + snmpa:send_trap(MA,linkUp,"standard trap",[{ifIndex, [1], 1}, + {ifAdminStatus, [1], 1}, + {ifOperStatus, [1], 2}]), + ?line expect(3, trap, [1,2,3], 3, 0, [{[ifIndex, 1], 1}, + {[ifAdminStatus, 1], 1}, + {[ifOperStatus, 1], 2}]). + +sa_trap1(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap"), + ?line expect(4, trap, [ericsson], 6, 1, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}]). + +sa_trap2(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), + ?line expect(5, trap, [ericsson], 6, 1, [{[system, [4,0]], + "pelle"}, + {[sa, [1,0]], "sa_test"}]). + +sa_trap3(SA) -> + snmpa:send_trap(SA, saTrap2, "standard trap", + [{intViewSubtree, [4], [1,2,3,4]}]), + ?line expect(6, trap, [ericsson], 6, 2, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}, + {[intViewSubtree,4],[1,2,3,4]}]). + +ma_v2_trap1(MA) -> + ?DBG("ma_v2_traps -> entry with MA = ~p => " + "send standard trap: testTrapv22",[MA]), + snmpa:send_trap(MA, testTrapv22, "standard trap"), + ?line expect(1, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + ?DBG("ma_v2_traps -> send standard trap: testTrapv21",[]), + snmpa:send_trap(MA, testTrapv21, "standard trap"), + ?line expect(2, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?snmp ++ [1]}]). + +ma_v2_trap2(MA) -> + snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}, + {[system, [4,0]], "pelle"}]). + +%% Note: This test case takes a while... actually a couple of minutes. +ma_v2_inform1(MA) -> + ?DBG("ma_v2_inform -> entry with MA = ~p => " + "send notification: testTrapv22",[MA]), + ?line snmpa:send_notification(MA, testTrapv22, no_receiver, "standard inform", []), + ?line expect(1, {inform, true}, + [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + + ?DBG("ma_v2_inform -> send notification: testTrapv22",[]), + snmpa:send_notification(MA, testTrapv22, {tag1, self()}, + "standard inform", []), + ?line expect(1, {inform, true}, + [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + ?DBG("ma_v2_inform -> await targets",[]), + receive + {snmp_targets, tag1, [_]} -> + ok; + {snmp_targets, tag1, Addrs1} -> + ?line ?FAIL({bad_addrs, Addrs1}) + after + 5000 -> + ?ERR("ma_v2_inform1 -> awaiting snmp_targets(tag1) timeout",[]), + ?line ?FAIL(nothing_at_all) + end, + ?DBG("ma_v2_inform -> await notification",[]), + receive + {snmp_notification, tag1, {got_response, _}} -> + ok; + {snmp_notification, tag1, {no_response, _}} -> + ?line ?FAIL(no_response) + after + 20000 -> + ?ERR("ma_v2_inform1 -> " + "awaiting snmp_notification(tag1) timeout",[]), + ?line ?FAIL(nothing_at_all) + end, + + %% + %% -- The rest is possibly erroneous... + %% + + ?DBG("ma_v2_inform -> send notification: testTrapv22",[]), + snmpa:send_notification(MA, testTrapv22, {tag2, self()}, + "standard inform", []), + ?line expect(2, {inform, false}, + [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + ?DBG("ma_v2_inform -> await targets",[]), + receive + {snmp_targets, tag2, [_]} -> + ok; + {snmp_targets, tag2, Addrs2} -> + ?ERR("ma_v2_inform1 -> awaiting snmp_targets(tag2) timeout",[]), + ?line ?FAIL({bad_addrs, Addrs2}) + after + 5000 -> + ?line ?FAIL(nothing_at_all) + end, + ?DBG("ma_v2_inform -> await notification",[]), + receive + {snmp_notification, tag2, {got_response, _}} -> + ?line ?FAIL(got_response); + {snmp_notification, tag2, {no_response, _}} -> + ok + after + 240000 -> + ?ERR("ma_v2_inform1 -> " + "awaiting snmp_notification(tag2) timeout",[]), + ?line ?FAIL(nothing_at_all) + end. + + +ma_v1_2_v2_trap(MA) -> + snmpa:send_trap(MA,linkDown,"standard trap",[{ifIndex, [1], 1}]), + ?line expect(2, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?snmpTraps ++ [3]}, + {[ifIndex, 1], 1}, + {[snmpTrapEnterprise, 0], [1,2,3]}]). + + +ma_v1_2_v2_trap2(MA) -> + snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}, + {[system, [4,0]], "pelle"}, + {[snmpTrapEnterprise, 0], ?system}]). + + +sa_v1_2_v2_trap1(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap"), + ?line expect(4, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, + {[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}, + {[snmpTrapEnterprise, 0], ?ericsson}]). + +sa_v1_2_v2_trap2(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), + ?line expect(4, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, + {[system, [4,0]], "pelle"}, + {[sa, [1,0]], "sa_test"}, + {[snmpTrapEnterprise, 0], ?ericsson}]). + + +sa_v1_2_v2_trap3(SA) -> + snmpa:send_trap(SA, saTrap2, "standard trap", + [{intViewSubtree, [4], [1,2,3,4]}]), + ?line expect(4, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?ericsson ++ [0, 2]}, + {[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}, + {[intViewSubtree,4],[1,2,3,4]}, + {[snmpTrapEnterprise, 0], ?ericsson}]). + + +%% Req. SA-MIB, OLD-SNMPEA-MIB +sa_errs_bad_value() -> + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + s([{NewKeyc3, 2}, + {[sa, [2,0]], 5}, % badValue (i is_set_ok) + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}]), + ?line expect(1, badValue, 2, any), + s([{NewKeyc3, 2}, + {[sa, [2,0]], 6}, % wrongValue (i is_set_ok) + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}]), + ?line expect(1, ?v1_2(badValue, wrongValue), 2, any), + g([NewKeyc4]), + ?line ?v1_2(expect(2, noSuchName, 1, any), + expect(2, [{NewKeyc4, noSuchInstance}])). + +%% Req. SA-MIB, OLD-SNMPEA-MIB +sa_errs_gen_err() -> + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + s([{NewKeyc3, 2},{NewKeyc4, 2}, + {NewKeyc5, ?createAndGo}, {[sa, [3,0]], 5}]), + ?line expect(1, genErr, 4, any), +% The row might have been added; we don't know. +% (as a matter of fact we do - it is added, because the agent +% first sets its own vars, and then th SAs. Lets destroy it. + s([{NewKeyc5, ?destroy}]), + ?line expect(2, [{NewKeyc5, ?destroy}]). + +%% Req. SA-MIB, OLD-SNMPEA-MIB +sa_too_big() -> + g([[sa, [4,0]]]), + ?line expect(1, tooBig). + +%% Req. Klas1, system group, snmp group (v1/v2) +next_across_sa() -> + gn([[sysDescr],[klas1,5]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {[snmpInPkts, 0], any}]). + +%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]). -> noError +%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]). -> {badValue, 2} +%% snmp_test_mgr:s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]). -> {genErr, 1} +%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]). -> {genErr, 1} +%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]). -> {genErr, 1} +%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]). -> {genErr, 2} +%% Req. Klas3, Klas4 +undo_test() -> + s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), + ?line expect(1, [{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), + s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]), + ?line expect(2, ?v1_2(badValue, inconsistentValue), 2, any), + s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]), + ?line expect(3, ?v1_2(genErr, undoFailed), 1, any), + s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]), + ?line expect(4, ?v1_2(genErr, commitFailed), 1, any), +% unfortunatly we don't know if we'll get undoFailed or commitFailed. +% it depends on which order the agent traverses the varbind list. +% s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]), +% ?line expect(5, ?v1_2(genErr, undoFailed), 1, any), + s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]), + ?line expect(6, genErr, 2, any). + +%% Req. Klas3, Klas4 +bad_return() -> + g([[fStatus4,4], + [fName4,4]]), + ?line expect(4, genErr, 2, any), + g([[fStatus4,5], + [fName4,5]]), + ?line expect(5, genErr, 1, any), + g([[fStatus4,6], + [fName4,6]]), + ?line expect(6, genErr, 2, any), + gn([[fStatus4,7], + [fName4,7]]), + ?line expect(7, genErr, 2, any), + gn([[fStatus4,8], + [fName4,8]]), + ?line expect(8, genErr, 1, any), + gn([[fStatus4,9], + [fName4,9]]), + ?line expect(9, genErr, 2, any). + + +%%%----------------------------------------------------------------- +%%% Test the implementation of standard mibs. +%%% We should *at least* try to GET all variables, just to make +%%% sure the instrumentation functions work. +%%% Note that many of the functions in the standard mib is +%%% already tested by the normal tests. +%%%----------------------------------------------------------------- + + + +%%----------------------------------------------------------------- +%% For this test, the agent is configured for v1. +%% o Test the counters and control objects in SNMP-STANDARD-MIB +%%----------------------------------------------------------------- +snmp_standard_mib(suite) -> []; +snmp_standard_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?DBG("snmp_standard_mib -> std_mib_init", []), + try_test(std_mib_init), + + ?DBG("snmp_standard_mib -> std_mib_a", []), + InBadVsns = try_test(std_mib_a), + put(vsn, v2), + ?DBG("snmp_standard_mib -> std_mib_read", []), + try_test(std_mib_read), + put(vsn, v1), + + ?DBG("snmp_standard_mib -> std_mib_b (~w)", [InBadVsns]), + Bad = try_test(std_mib_b, [InBadVsns]), + ?DBG("snmp_standard_mib -> std_mib_read (community: 'bad community')", []), + try_test(std_mib_read, [], [{community, "bad community"}]), + ?DBG("snmp_standard_mib -> std_mib_write (community: 'public')", []), + try_test(std_mib_write, [], [{community, "public"}]), + ?DBG("snmp_standard_mib -> std_mib_asn_err", []), + try_test(std_mib_asn_err), + ?DBG("snmp_standard_mib -> std_mib_c (~w)", [Bad]), + try_test(std_mib_c, [Bad]), + ?DBG("snmp_standard_mib -> std_mib_a", []), + try_test(standard_mib_a), + + ?DBG("snmp_standard_mib -> std_mib_finish", []), + try_test(std_mib_finish), + ?DBG("snmp_standard_mib -> std_mib_test_finish", []), + try_test(standard_mib_test_finish, [], [{community, "bad community"}]). + +%% Req. SNMP-STANDARD-MIB +standard_mib_a() -> + ?line [OutPkts] = get_req(2, [[snmpOutPkts,0]]), + ?line [OutPkts2] = get_req(3, [[snmpOutPkts,0]]), + ?line OutPkts2 = OutPkts + 1, + %% There are some more counters we could test here, but it's not that + %% important, since they are removed from SNMPv2-MIB. + ok. + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_init() -> + %% disable authentication failure traps. (otherwise w'd get many of + %% them - this is also a test to see that it works). + s([{[snmpEnableAuthenTraps,0], 2}]), + ?line expect(1, [{[snmpEnableAuthenTraps, 0], 2}]). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_finish() -> + %% enable again + s([{[snmpEnableAuthenTraps,0], 1}]), + ?line expect(1, [{[snmpEnableAuthenTraps, 0], 1}]). + +%% Req. SNMP-STANDARD-MIB +standard_mib_test_finish() -> + %% force a authenticationFailure + std_mib_write(), + %% check that we got a trap + ?line expect(2, trap, [1,2,3], 4, 0, []). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_read() -> + ?DBG("std_mib_read -> entry", []), + g([[sysUpTime,0]]), % try a bad ; msg dropped, no reply + ?DBG("std_mib_read -> await timeout (i.e. no reply)", []), + ?line expect(1, timeout). % make sure we don't get a trap! + + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_write() -> + ?DBG("std_mib_write -> entry", []), + s([{[sysLocation, 0], "new_value"}]). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_asn_err() -> + snmp_test_mgr:send_bytes([48,99,67,12,0,0,0,0,0,0,5]). + +%%----------------------------------------------------------------- +%% For this test, the agent is configured for v2 and v3. +%% o Test the counters and control objects in SNMPv2-MIB +%%----------------------------------------------------------------- +snmpv2_mib_2(suite) -> []; +snmpv2_mib_2(Config) when list(Config) -> + ?LOG("snmpv2_mib_2 -> start",[]), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?DBG("snmpv2_mib_2 -> standard mib init",[]), + try_test(std_mib_init), + + ?DBG("snmpv2_mib_2 -> get number of (so far) bad versions",[]), + InBadVsns = try_test(std_mib_a), + + ?DBG("snmpv2_mib_2 -> make a bad version read",[]), + put(vsn, v1), + try_test(std_mib_read), + + ?DBG("snmpv2_mib_2 -> bad version read",[]), + put(vsn, v2), + Bad = try_test(std_mib_b, [InBadVsns]), + + ?DBG("snmpv2_mib_2 -> read with bad community",[]), + try_test(std_mib_read, [], [{community, "bad community"}]), + + ?DBG("snmpv2_mib_2 -> write with public community",[]), + try_test(std_mib_write, [], [{community, "public"}]), + + ?DBG("snmpv2_mib_2 -> asn err",[]), + try_test(std_mib_asn_err), + + ?DBG("snmpv2_mib_2 -> check counters",[]), + try_test(std_mib_c, [Bad]), + + ?DBG("snmpv2_mib_2 -> get som counters",[]), + try_test(snmpv2_mib_a), + + ?DBG("snmpv2_mib_2 -> enable auth traps, and await some",[]), + try_test(std_mib_finish), + + ?DBG("snmpv2_mib_2 -> force auth failure, and await trap, " + "then disable auth traps",[]), + try_test(snmpv2_mib_test_finish, [], [{community, "bad community"}]), + + ?LOG("snmpv2_mib_2 -> done",[]). + +%% Req. SNMPv2-MIB +snmpv2_mib_3(suite) -> []; +snmpv2_mib_3(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + InBadVsns = try_test(std_mib_a), + put(vsn, v1), + try_test(std_mib_read), + put(vsn, v3), + _Bad = try_test(std_mib_b, [InBadVsns]), + try_test(snmpv2_mib_a), + + try_test(std_mib_finish). + +-define(authenticationFailure, [1,3,6,1,6,3,1,1,5,5]). + +%% Req. SNMPv2-MIB +snmpv2_mib_test_finish() -> + %% force a authenticationFailure + ?DBG("ma_v2_inform -> write to std mib",[]), + std_mib_write(), + + %% check that we got a trap + ?DBG("ma_v2_inform -> await trap",[]), + ?line expect(2, v2trap, [{[sysUpTime,0], any}, + {[snmpTrapOID,0], ?authenticationFailure}]), + + %% and the the inform + ?DBG("ma_v2_inform -> await inform",[]), + ?line expect(2, {inform,true}, [{[sysUpTime,0], any}, + {[snmpTrapOID,0],?authenticationFailure}]). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_a() -> + ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), + ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), + ?line InPkts2 = InPkts + 1, + + ?line [InBadVsns] = get_req(4, [[snmpInBadVersions,0]]), + InBadVsns. + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_b(InBadVsns) -> + ?line [InBadVsns2] = get_req(1, [[snmpInBadVersions,0]]), + ?line InBadVsns2 = InBadVsns + 1, + ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), + ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), + ?line InPkts2 = InPkts + 1, + ?line [InBadCommunityNames, InBadCommunityUses, InASNErrs] = + get_req(4, [[snmpInBadCommunityNames,0], + [snmpInBadCommunityUses,0], + [snmpInASNParseErrs, 0]]), + {InBadCommunityNames, InBadCommunityUses, InASNErrs}. + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_c({InBadCommunityNames, InBadCommunityUses, InASNErrs}) -> + ?line [InBadCommunityNames2, InBadCommunityUses2, InASNErrs2] = + get_req(1, [[snmpInBadCommunityNames,0], + [snmpInBadCommunityUses,0], + [snmpInASNParseErrs, 0]]), + ?line InBadCommunityNames2 = InBadCommunityNames + 1, + ?line InBadCommunityUses2 = InBadCommunityUses + 1, + ?line InASNErrs2 = InASNErrs + 1. + +%% Req. SNMPv2-MIB +snmpv2_mib_a() -> + ?line [SetSerial] = get_req(2, [[snmpSetSerialNo,0]]), + s([{[snmpSetSerialNo,0], SetSerial}, {[sysLocation, 0], "val2"}]), + ?line expect(3, [{[snmpSetSerialNo,0], SetSerial}, + {[sysLocation, 0], "val2"}]), + s([{[sysLocation, 0], "val3"}, {[snmpSetSerialNo,0], SetSerial}]), + ?line expect(4, inconsistentValue, 2, + [{[sysLocation, 0], "val3"}, + {[snmpSetSerialNo,0], SetSerial}]), + ?line ["val2"] = get_req(5, [[sysLocation,0]]). + + +%%----------------------------------------------------------------- +%% o Bad community uses/name is tested already +%% in SNMPv2-MIB and STANDARD-MIB. +%% o Test add/deletion of rows. +%%----------------------------------------------------------------- +snmp_community_mib(suite) -> []; +snmp_community_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + try_test(snmp_community_mib), + ?line unload_master("SNMP-COMMUNITY-MIB"). + +snmp_community_mib_2(X) -> snmp_community_mib(X). + +%% Req. SNMP-COMMUNITY-MIB +snmp_community_mib() -> + ?INF("NOT YET IMPLEMENTED", []), + nyi. + +%%----------------------------------------------------------------- +%% o Test engine boots / time +%%----------------------------------------------------------------- +snmp_framework_mib(suite) -> []; +snmp_framework_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + try_test(snmp_framework_mib), + ?line unload_master("SNMP-FRAMEWORK-MIB"). + +snmp_framework_mib_2(X) -> snmp_framework_mib(X). + +snmp_framework_mib_3(suite) -> []; +snmp_framework_mib_3(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + try_test(snmp_framework_mib). + + +%% Req. SNMP-FRAMEWORK-MIB +snmp_framework_mib() -> + ?line ["agentEngine"] = get_req(1, [[snmpEngineID,0]]), + ?line [EngineTime] = get_req(2, [[snmpEngineTime,0]]), + sleep(5000), + ?line [EngineTime2] = get_req(3, [[snmpEngineTime,0]]), + if + EngineTime+7 < EngineTime2 -> + ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); + EngineTime+4 > EngineTime2 -> + ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); + true -> ok + end, + ?line case get_req(4, [[snmpEngineBoots,0]]) of + [Boots] when integer(Boots) -> ok; + Else -> ?FAIL(Else) + end, + ok. + +%%----------------------------------------------------------------- +%% o Test the counters +%%----------------------------------------------------------------- +snmp_mpd_mib_3(suite) -> []; +snmp_mpd_mib_3(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + UnknownPDUHs = try_test(snmp_mpd_mib_a), + try_test(snmp_mpd_mib_b, [], [{context_engine_id, "bad engine"}]), + try_test(snmp_mpd_mib_c, [UnknownPDUHs]). + + +%% Req. SNMP-MPD-MIB +snmp_mpd_mib_a() -> + ?line [UnknownSecs, InvalidMsgs] = + get_req(1, [[snmpUnknownSecurityModels,0], + [snmpInvalidMsgs,0]]), + Pdu = #pdu{type = 'get-request', + request_id = 23, + error_status = noError, + error_index = 0, + varbinds = []}, + SPdu = #scopedPdu{contextEngineID = "agentEngine", + contextName = "", + data = Pdu}, + ?line SPDUBytes = snmp_pdus:enc_scoped_pdu(SPdu), + V3Hdr1 = #v3_hdr{msgID = 21, + msgMaxSize = 484, + msgFlags = [7], + msgSecurityModel = 23, % bad sec model + msgSecurityParameters = []}, + V3Hdr2 = #v3_hdr{msgID = 21, + msgMaxSize = 484, + msgFlags = [6], % bad flag combination + msgSecurityModel = 3, + msgSecurityParameters = []}, + Message1 = #message{version = 'version-3', vsn_hdr = V3Hdr1, + data = SPDUBytes}, + Message2 = #message{version = 'version-3', vsn_hdr = V3Hdr2, + data = SPDUBytes}, + ?line MsgBytes1 = snmp_pdus:enc_message_only(Message1), + ?line MsgBytes2 = snmp_pdus:enc_message_only(Message2), + snmp_test_mgr:send_bytes(MsgBytes1), + snmp_test_mgr:send_bytes(MsgBytes2), + + ?line [UnknownSecs2, InvalidMsgs2, UnknownPDUHs] = + get_req(1, [[snmpUnknownSecurityModels,0], + [snmpInvalidMsgs,0], + [snmpUnknownPDUHandlers, 0]]), + ?line UnknownSecs2 = UnknownSecs + 1, + ?line InvalidMsgs2 = InvalidMsgs + 1, + UnknownPDUHs. + +-define(snmpUnknownPDUHandlers_instance, [1,3,6,1,6,3,11,2,1,3,0]). +snmp_mpd_mib_b() -> + g([[sysUpTime,0]]), + ?line expect(1, report, [{?snmpUnknownPDUHandlers_instance, any}]). + + +snmp_mpd_mib_c(UnknownPDUHs) -> + ?line [UnknownPDUHs2] = get_req(1, [[snmpUnknownPDUHandlers, 0]]), + ?line UnknownPDUHs2 = UnknownPDUHs + 1. + + +snmp_target_mib(suite) -> []; +snmp_target_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-TARGET-MIB"), + try_test(snmp_target_mib), + ?line unload_master("SNMP-TARGET-MIB"). + +snmp_target_mib_2(X) -> snmp_target_mib(X). + +snmp_target_mib_3(X) -> snmp_target_mib(X). + +snmp_target_mib() -> + ?INF("NOT YET IMPLEMENTED", []), + nyi. + +snmp_notification_mib(suite) -> []; +snmp_notification_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + try_test(snmp_notification_mib), + ?line unload_master("SNMP-NOTIFICATION-MIB"). + +snmp_notification_mib_2(X) -> snmp_notification_mib(X). + +snmp_notification_mib_3(X) -> snmp_notification_mib(X). + +snmp_notification_mib() -> + ?INF("NOT YET IMPLEMENTED", []), + nyi. + +%%----------------------------------------------------------------- +%% o add/delete views and try them +%% o try boundaries +%%----------------------------------------------------------------- +snmp_view_based_acm_mib(suite) -> []; +snmp_view_based_acm_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + ?line load_master("Test2"), + snmp_view_based_acm_mib(), + ?line unload_master("Test2"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). + +snmp_view_based_acm_mib_2(X) -> snmp_view_based_acm_mib(X). + +snmp_view_based_acm_mib_3(X) -> snmp_view_based_acm_mib(X). + +snmp_view_based_acm_mib() -> + snmpa:verbosity(net_if,trace), + snmpa:verbosity(master_agent,trace), + ?LOG("start snmp_view_based_acm_mib test",[]), + %% The user "no-rights" is present in USM, and is mapped to security + %% name 'no-rights", which is not present in VACM. + %% So, we'll add rights for it, try them and delete them. + %% We'll give "no-rights" write access to tDescr.0 and read access + %% to tDescr2.0 + %% These are the options we'll use to the mgr + Opts = [{user, "no-rights"}, {community, "no-rights"}], + %% Find the valid secmodel, and one invalid secmodel. + {SecMod, InvSecMod} = + case get(vsn) of + v1 -> {?SEC_V1, ?SEC_V2C}; + v2 -> {?SEC_V2C, ?SEC_USM}; + v3 -> {?SEC_USM, ?SEC_V1} + end, + ?DBG("assign rights for 'no-rights'",[]), + ?line try_test(use_no_rights, [], Opts), + + %% Now, add a mapping from "no-rights" -> "no-rights-group" + GRow1Status = [vacmSecurityToGroupStatus,[SecMod, 9,"no-rights"]], + GRow1 = + [{[vacmGroupName, [SecMod, 9,"no-rights"]], "no-rights-group"}, + {GRow1Status, ?createAndGo}], + ?DBG("set '~p'",[GRow1]), + ?line try_test(do_set, [GRow1]), + + ?DBG("assign rights for 'no-rights'",[]), + ?line try_test(use_no_rights, [], Opts), + + %% Create a mapping for another sec model, and make sure it dosn't + %% give us access + GRow2Status = [vacmSecurityToGroupStatus,[InvSecMod, 9,"no-rights"]], + GRow2 = [{[vacmGroupName, [InvSecMod, 9, "no-rights"]], "initial"}, + {GRow2Status, ?createAndGo}], + + ?DBG("set '~p'",[GRow2]), + ?line try_test(do_set, [GRow2]), + + ?DBG("assign rights for 'no-rights'",[]), + ?line try_test(use_no_rights, [], Opts), + + %% Delete that row + ?line try_test(del_row, [GRow2Status]), + + RVName = "rv_name", + WVName = "wv_name", + + %% Access row + ARow1Idx = [15 | "no-rights-group"] ++ [0, ?SEC_ANY, 1], + ARow1Status = [vacmAccessStatus, ARow1Idx], + ARow1 = [{[vacmAccessContextMatch, ARow1Idx], 1}, + {[vacmAccessReadViewName, ARow1Idx], RVName}, + {[vacmAccessWriteViewName, ARow1Idx], WVName}, + {ARow1Status, ?createAndGo}], + + %% This access row would give acces, if InvSecMod was valid. + ARow2Idx = [15 | "no-rights-group"] ++ [0, InvSecMod, 1], + ARow2Status = [vacmAccessStatus, ARow2Idx], + ARow2 = [{[vacmAccessContextMatch, ARow2Idx], 1}, + {[vacmAccessReadViewName, ARow2Idx], "internet"}, + {[vacmAccessWriteViewName, ARow2Idx], "internet"}, + {ARow2Status, ?createAndGo}], + + ?line try_test(do_set, [ARow2]), + + ?line try_test(use_no_rights, [], Opts), + + %% Delete that row + ?line try_test(del_row, [ARow2Status]), + + + %% Add valid row + ?line try_test(do_set, [ARow1]), + + ?line try_test(use_no_rights, [], Opts), + + %% Create the view family + VRow1Idx = mk_ln(RVName) ++ mk_ln(?xDescr), % object access + VRow2Idx = mk_ln(RVName) ++ mk_ln(?xDescr2 ++ [0]), % instance access + VRow3Idx = mk_ln(WVName) ++ mk_ln(?xDescr), % object access + VRow4Idx = mk_ln(WVName) ++ mk_ln(?xDescr ++ [0]), % instance access + VRow1Status = [vacmViewTreeFamilyStatus, VRow1Idx], + VRow2Status = [vacmViewTreeFamilyStatus, VRow2Idx], + VRow3Status = [vacmViewTreeFamilyStatus, VRow3Idx], + VRow4Status = [vacmViewTreeFamilyStatus, VRow4Idx], + + ?line try_test(add_row, [VRow1Status]), + ?line try_test(add_row, [VRow2Status]), + ?line try_test(add_row, [VRow3Status]), + + %% We're supposed to have access now... + ?line try_test(use_rights, [], Opts), + + %% Change Row3 to Row4 + ?line try_test(del_row, [VRow3Status]), + ?line try_test(add_row, [VRow4Status]), + + %% We should still have access... + ?line try_test(use_rights, [], Opts), + + %% Delete rows + ?line try_test(del_row, [GRow1Status]), + + ?line try_test(use_no_rights, [], Opts), + + %% Delete rest of rows + ?line try_test(del_row, [ARow1Status]), + ?line try_test(del_row, [VRow1Status]), + ?line try_test(del_row, [VRow2Status]), + ?line try_test(del_row, [VRow4Status]), + + ?line try_test(use_no_rights, [], Opts), + snmpa:verbosity(master_agent,log). + +do_set(Row) -> + s(Row), + expect(1, Row). + +add_row(RowStatus) -> + s([{RowStatus, ?createAndGo}]), + expect(1, [{RowStatus, ?createAndGo}]). + +del_row(RowStatus) -> + s([{RowStatus, ?destroy}]), + expect(1, [{RowStatus, ?destroy}]). + + + +use_no_rights() -> + g([[xDescr,0]]), + ?v1_2_3(expect(11, noSuchName, 1, any), + expect(12, [{[xDescr,0], noSuchObject}]), + expect(13, authorizationError, 1, any)), + g([[xDescr2,0]]), + ?v1_2_3(expect(21, noSuchName, 1, any), + expect(22, [{[xDescr2,0], noSuchObject}]), + expect(23, authorizationError, 1, any)), + gn([[xDescr]]), + ?v1_2_3(expect(31, noSuchName, 1, any), + expect(32, [{[xDescr], endOfMibView}]), + expect(33, authorizationError, 1, any)), + s([{[xDescr,0], "tryit"}]), + ?v1_2_3(expect(41, noSuchName, 1, any), + expect(42, noAccess, 1, any), + expect(43, authorizationError, 1, any)). + + +use_rights() -> + g([[xDescr,0]]), + expect(1, [{[xDescr,0], any}]), + g([[xDescr2,0]]), + expect(2, [{[xDescr2,0], any}]), + s([{[xDescr,0], "tryit"}]), + expect(3, noError, 0, any), + g([[xDescr,0]]), + expect(4, [{[xDescr,0], "tryit"}]). + +mk_ln(X) -> + [length(X) | X]. + +%%----------------------------------------------------------------- +%% o add/delete users and try them +%% o test all secLevels +%% o test all combinations of protocols +%% o try bad ops; check counters +%%----------------------------------------------------------------- +snmp_user_based_sm_mib_3(suite) -> []; +snmp_user_based_sm_mib_3(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + _AgentDir = ?config(agent_dir, Config), + ?line load_master_std("SNMP-USER-BASED-SM-MIB"), + + %% The newUser used here already has VACM access. + + %% Add a new user in the simplest way; just createAndGo + try_test(v3_sync, [[{usm_add_user1, []}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + %% Try to use the new user + ?line load_master("Test2"), + try_test(v3_sync, [[{usm_use_user, []}]], + [{sec_level, authPriv}, {user, "newUser"}]), + ?line unload_master("Test2"), + + ShaKey1 = snmp:passwd2localized_key(sha, "new sha password", "agentEngine"), + DesKey1 = lists:sublist(ShaKey1, 16), + + %% Change the new user's keys - 1 + try_test(v3_sync, [[{usm_key_change1, [ShaKey1, DesKey1]}]], + [{sec_level, authPriv}, {user, "newUser"}]), + + %% Try to use the new keys + MgrDir = ?config(mgr_dir, Config), + ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), + ?line load_master("Test2"), + try_test(v3_sync, [[{usm_use_user, []}]], + [{sec_level, authPriv}, {user, "newUser"}]), + ?line unload_master("Test2"), + + ShaKey2 = snmp:passwd2localized_key(sha, "newer password", "agentEngine"), + DesKey2 = lists:sublist(ShaKey2, 16), + + %% Change the new user's keys - 2 + ?line try_test(v3_sync, + [[{usm_key_change2, [ShaKey1, DesKey1, ShaKey2, DesKey2]}]], + [{sec_level, authPriv}, {user, "newUser"}]), + + %% Try to use the new keys + reset_usm_mgr(MgrDir), + ?line rewrite_usm_mgr(MgrDir, ShaKey2, DesKey2), + ?line load_master("Test2"), + ?line try_test(v3_sync, [[{usm_use_user, []}]], + [{sec_level, authPriv}, {user, "newUser"}]), + ?line unload_master("Test2"), + reset_usm_mgr(MgrDir), + + %% Change the new user's keys - 3 + ?line try_test(v3_sync, + [[{usm_key_change3, [ShaKey2, DesKey2, ShaKey1, DesKey1]}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + %% Try to use the new keys + ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), + ?line load_master("Test2"), + try_test(v3_sync, [[{usm_use_user, []}]], + [{sec_level, authPriv}, {user, "newUser"}]), + ?line unload_master("Test2"), + reset_usm_mgr(MgrDir), + + %% Try some read requests + ?line try_test(v3_sync, [[{usm_read, []}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + %% Delete the new user + ?line try_test(v3_sync, [[{usm_del_user, []}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + %% Try some bad requests + ?line try_test(v3_sync, [[{usm_bad, []}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + ?line unload_master("SNMP-USER-BASED-SM-MIB"). + +-define(usmUserSecurityName, [1,3,6,1,6,3,15,1,2,2,1,3]). + +usm_add_user1() -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + RowPointer = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], + Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer}, + {[usmUserStatus, NewRowIndex], ?createAndGo}], + ?line s(Vbs1), + ?line expect(1, Vbs1), + ok. + +usm_use_user() -> + v2_proc(). + + +%% Change own public keys +usm_key_change1(ShaKey, DesKey) -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + "passwd_shaxxxxxxxxxx", + ShaKey), + DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + "passwd_desxxxxxx", + DesKey), + Vbs1 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, + {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], + s(Vbs1), + ?line expect(1, Vbs1). + +%% Change own private keys +usm_key_change2(OldShaKey, OldDesKey, ShaKey, DesKey) -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + OldShaKey, + ShaKey), + DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + OldDesKey, + DesKey), + Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}, + {[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], + s(Vbs1), + ?line expect(1, Vbs1). + +%% Change other's public keys +usm_key_change3(OldShaKey, OldDesKey, ShaKey, DesKey) -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + OldShaKey, + ShaKey), + DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + OldDesKey, + DesKey), + Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}], + s(Vbs1), + ?line expect(1, noAccess, 1, any), + Vbs2 = [{[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], + s(Vbs2), + ?line expect(2, noAccess, 1, any), + + + Vbs3 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, + {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], + s(Vbs3), + ?line expect(1, Vbs3). + +usm_read() -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + ?line g([[usmUserSecurityName, NewRowIndex], + [usmUserCloneFrom, NewRowIndex], + [usmUserAuthKeyChange, NewRowIndex], + [usmUserOwnAuthKeyChange, NewRowIndex], + [usmUserPrivKeyChange, NewRowIndex], + [usmUserOwnPrivKeyChange, NewRowIndex]]), + ?line expect(1, + [{[usmUserSecurityName, NewRowIndex], "newUser"}, + {[usmUserCloneFrom, NewRowIndex], [0,0]}, + {[usmUserAuthKeyChange, NewRowIndex], ""}, + {[usmUserOwnAuthKeyChange, NewRowIndex], ""}, + {[usmUserPrivKeyChange, NewRowIndex], ""}, + {[usmUserOwnPrivKeyChange, NewRowIndex], ""}]), + ok. + + + +usm_del_user() -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + Vbs1 = [{[usmUserStatus, NewRowIndex], ?destroy}], + ?line s(Vbs1), + ?line expect(1, Vbs1), + ok. + +-define(usmUserCloneFrom, [1,3,6,1,6,3,15,1,2,2,1,4]). + +-define(usmNoAuthProtocol, [1,3,6,1,6,3,10,1,1,1]). + +-define(usmHMACMD5AuthProtocol, [1,3,6,1,6,3,10,1,1,2]). + +-define(usmHMACSHAAuthProtocol, [1,3,6,1,6,3,10,1,1,3]). + +-define(usmNoPrivProtocol, [1,3,6,1,6,3,10,1,2,1]). + +-define(usmDESPrivProtocol, [1,3,6,1,6,3,10,1,2,2]). + +usm_bad() -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + RowPointer1 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDOS"], + Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer1}, + {[usmUserStatus, NewRowIndex], ?createAndGo}], + ?line s(Vbs1), + ?line expect(1, inconsistentName, 1, any), + + RowPointer2 = ?usmUserCloneFrom ++ [11|"agentEngine"] ++ [7|"privDES"], + Vbs2 = [{[usmUserCloneFrom, NewRowIndex], RowPointer2}, + {[usmUserStatus, NewRowIndex], ?createAndGo}], + ?line s(Vbs2), + ?line expect(2, wrongValue, 1, any), + + RowPointer3 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], + Vbs3 = [{[usmUserCloneFrom, NewRowIndex], RowPointer3}, + {[usmUserStatus, NewRowIndex], ?createAndGo}], + ?line s(Vbs3), + ?line expect(3, Vbs3), + ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmNoAuthProtocol}]), + ?line expect(4, inconsistentValue, 1, any), + ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmHMACMD5AuthProtocol}]), + ?line expect(5, inconsistentValue, 1, any), + ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmDESPrivProtocol}]), + ?line expect(6, wrongValue, 1, any), + ?line s([{[usmUserPrivProtocol, NewRowIndex], ?usmHMACSHAAuthProtocol}]), + ?line expect(7, wrongValue, 1, any), + + Vbs4 = [{[usmUserStatus, NewRowIndex], ?destroy}], + ?line s(Vbs4), + ?line expect(1, Vbs4), + + ok. + + +%%----------------------------------------------------------------- +%% Loop through entire MIB, to make sure that all instrum. funcs +%% works. +%% Load all std mibs that are not loaded by default. +%%----------------------------------------------------------------- +loop_mib(suite) -> []; +loop_mib(Config) when list(Config) -> + ?LOG("loop_mib -> initiate case",[]), + %% snmpa:verbosity(master_agent,debug), + %% snmpa:verbosity(mib_server,info), + {SaNode, MgrNode, MibDir} = init_case(Config), + ?DBG("loop_mib -> ~n" + "\tSaNode: ~p~n" + "\tMgrNode: ~p~n" + "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), + ?DBG("loop_mib -> load mib SNMP-COMMUNITY-MIB",[]), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?DBG("loop_mib -> load mib SNMP-MPD-MIB",[]), + ?line load_master_std("SNMP-MPD-MIB"), + ?DBG("loop_mib -> load mib SNMP-TARGET-MIB",[]), + ?line load_master_std("SNMP-TARGET-MIB"), + ?DBG("loop_mib -> load mib SNMP-NOTIFICATION-MIB",[]), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?DBG("loop_mib -> load mib SNMP-FRAMEWORK-MIB",[]), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?DBG("loop_mib -> load mib SNMP-VIEW-BASED-ACM-MIB",[]), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + ?DBG("loop_mib -> try",[]), + try_test(loop_mib_1), + ?DBG("loop_mib -> unload mib SNMP-COMMUNITY-MIB",[]), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?DBG("loop_mib -> unload mib SNMP-MPD-MIB",[]), + ?line unload_master("SNMP-MPD-MIB"), + ?DBG("loop_mib -> unload mib SNMP-TARGET-MIB",[]), + ?line unload_master("SNMP-TARGET-MIB"), + ?DBG("loop_mib -> unload mib SNMP-NOTIFICATION-MIB",[]), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?DBG("loop_mib -> unload mib SNMP-FRAMEWORK-MIB",[]), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?DBG("loop_mib -> unload mib SNMP-VIEW-BASED-ACM-MIB",[]), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + %% snmpa:verbosity(master_agent,log), + %% snmpa:verbosity(mib_server,silence), + ?LOG("loop_mib -> done",[]). + + +loop_mib_2(suite) -> []; +loop_mib_2(Config) when list(Config) -> + ?LOG("loop_mib_2 -> initiate case",[]), + {SaNode, MgrNode, MibDir} = init_case(Config), + ?DBG("loop_mib_2 -> ~n" + "\tSaNode: ~p~n" + "\tMgrNode: ~p~n" + "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), + ?DBG("loop_mib_2 -> load mibs",[]), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-MPD-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + try_test(loop_mib_2), + ?DBG("loop_mib_2 -> unload mibs",[]), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?line unload_master("SNMP-MPD-MIB"), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + ?LOG("loop_mib_2 -> done",[]). + + +loop_mib_3(suite) -> []; +loop_mib_3(Config) when list(Config) -> + ?LOG("loop_mib_3 -> initiate case",[]), + {SaNode, MgrNode, MibDir} = init_case(Config), + ?DBG("loop_mib_3 -> ~n" + "\tSaNode: ~p~n" + "\tMgrNode: ~p~n" + "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), + ?DBG("loop_mib_3 -> load mibs",[]), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + ?line load_master_std("SNMP-USER-BASED-SM-MIB"), + try_test(loop_mib_2), + ?DBG("loop_mib_3 -> unload mibs",[]), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + ?line unload_master("SNMP-USER-BASED-SM-MIB"), + ?LOG("loop_mib_3 -> done",[]). + + +%% Req. As many mibs all possible +loop_mib_1() -> + ?DBG("loop_mib_1 -> entry",[]), + N = loop_it_1([1,1], 0), + io:format(user, "found ~w varibles\n", [N]), + ?line N = if N < 100 -> 100; + true -> N + end. + + +loop_it_1(Oid, N) -> + ?DBG("loop_it_1 -> entry with~n" + "\tOid: ~p~n" + "\tN: ~p",[Oid,N]), + case get_next_req([Oid]) of + #pdu{type='get-response', error_status=noError, error_index=0, + varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> + ?DBG("loop_it_1 -> ~n" + "\tNOid: ~p~n" + "\tValue: ~p",[NOid,Value]), + ?line [Value2] = get_req(1, [NOid]), % must not be same + ?DBG("loop_it_1 -> ~n" + "\tValue2: ~p",[Value2]), + loop_it_1(NOid, N+1); + #pdu{type='get-response', error_status=noSuchName, error_index=1, + varbinds=[_]} -> + ?DBG("loop_it_1 -> done",[]), + N; + + #pdu{type = Type, error_status = Err, error_index = Idx, + varbinds = Vbs} -> + exit({unexpected_pdu, ?LINE, Type, Err, Idx, Vbs}) + end. + +%% Req. As many mibs all possible +loop_mib_2() -> + ?DBG("loop_mib_1 -> entry",[]), + N = loop_it_2([1,1], 0), + io:format(user, "found ~w varibles\n", [N]), + ?line N = if N < 100 -> 100; + true -> N + end. + + +loop_it_2(Oid, N) -> + ?DBG("loop_it_2 -> entry with~n" + "\tOid: ~p~n" + "\tN: ~p",[Oid,N]), + case get_next_req([Oid]) of + #pdu{type='get-response', error_status=noError, error_index=0, + varbinds=[#varbind{oid = NOid, value = endOfMibView}]} -> + ?DBG("loop_it_2 -> ~n" + "\tNOid: ~p",[NOid]), + N; + #pdu{type='get-response', error_status=noError, error_index=0, + varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> + ?DBG("loop_it_2 -> ~n" + "\tNOid: ~p~n" + "\tValue: ~p",[NOid,Value]), + ?line [Value2] = get_req(1, [NOid]), % must not be same + ?DBG("loop_it_2 -> ~n" + "\tValue2: ~p",[Value2]), + loop_it_2(NOid, N+1) + end. + + +%%%----------------------------------------------------------------- +%%% Testing of reported bugs and other tickets. +%%%----------------------------------------------------------------- + + + + + +%% These are (ticket) test cases where the initiation has to be done +%% individually. + +%%----------------------------------------------------------------- +%% Ticket: OTP-1128 +%% Slogan: Bug in handling of createAndWait set-requests. +%%----------------------------------------------------------------- +otp_1128(suite) -> []; +otp_1128(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(otp_1128), + ?line unload_master("OLD-SNMPEA-MIB"). + +otp_1128_2(X) -> otp_1128(X). + +otp_1128_3(X) -> otp_1128(X). + +otp_1128() -> + io:format("Testing bug reported in ticket OTP-1128...~n"), + + NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], + NewKeyc4 = [intCommunityAccess,get(mip),is("test")], + NewKeyc5 = [intCommunityStatus,get(mip),is("test")], + + s([{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), + ?line expect(28, [{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), + g([NewKeyc5]), + ?line expect(29, [{NewKeyc5, ?notReady}]), + s([{NewKeyc5, ?active}, {NewKeyc3, 2}]), + ?line expect(30, [{NewKeyc5, ?active}, {NewKeyc3, 2}]), + g([NewKeyc5]), + ?line expect(31, [{NewKeyc5, ?active}]), + s([{NewKeyc5, ?destroy}]), + ?line expect(32, [{NewKeyc5, ?destroy}]). + +%%----------------------------------------------------------------- +%% Ticket: OTP-1129, OTP-1169 +%% Slogan: snmpa:int_to_enum crashes on bad oids +%%----------------------------------------------------------------- +otp_1129(suite) -> []; +otp_1129(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas3"), + try_test(otp_1129_i, [node()]), + ?line unload_master("Klas3"). + +otp_1129_2(X) -> otp_1129(X). + +otp_1129_3(X) -> otp_1129(X). + +otp_1129_i(MaNode) -> + io:format("Testing bug reported in ticket OTP-1129...~n"), + false = rpc:call(MaNode, snmp, int_to_enum, [iso, 1]), + false = rpc:call(MaNode, snmp, int_to_enum, [isox, 1]). + +%%----------------------------------------------------------------- +%% Ticket: OTP-1131 +%% Slogan: Agent crashes / erlang node halts if RowIndex in a +%% setrequest is of bad type, e.g. an INDEX {INTEGER}, +%% and RowIdenx [3,2]. +%%----------------------------------------------------------------- +otp_1131(suite) -> []; +otp_1131(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas1"), + try_test(otp_1131), + ?line unload_master("Klas1"). + +otp_1131_2(X) -> otp_1131(X). + +otp_1131_3(X) -> otp_1131(X). + +otp_1131() -> + io:format("Testing bug reported in ticket OTP-1131...~n"), + s([{[friendsEntry, [2, 3, 1]], s, "kompis3"}, + {[friendsEntry, [3, 3, 1]], i, ?createAndGo}]), + ?line expect(1, ?v1_2(noSuchName, noCreation), 2, any). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1162 +%% Slogan: snmp_agent can't handle wrongValue from instrum.func +%%----------------------------------------------------------------- +otp_1162(suite) -> []; +otp_1162(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + try_test(otp_1162), + stop_subagent(SA). + +otp_1162_2(X) -> otp_1162(X). + +otp_1162_3(X) -> otp_1162(X). + +otp_1162() -> + s([{[sa, [2,0]], 6}]), % wrongValue (i is_set_ok) + ?line expect(1, ?v1_2(badValue, wrongValue), 1, any). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1222 +%% Slogan: snmp agent crash if faulty index is returned from instrum +%%----------------------------------------------------------------- +otp_1222(suite) -> []; +otp_1222(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas3"), + ?line load_master("Klas4"), + try_test(otp_1222), + ?line unload_master("Klas3"), + ?line unload_master("Klas4"). + +otp_1222_2(X) -> otp_1222(X). + +otp_1222_3(X) -> otp_1222(X). + +otp_1222() -> + io:format("Testing bug reported in ticket OTP-1222...~n"), + s([{[fStatus4,1], 4}, {[fName4,1], 1}]), + ?line expect(1, genErr, 0, any), + s([{[fStatus4,2], 4}, {[fName4,2], 1}]), + ?line expect(2, genErr, 0, any). + +%%----------------------------------------------------------------- +%% Ticket: OTP-1298 +%% Slogan: Negative INTEGER values are treated as positive. +%%----------------------------------------------------------------- +otp_1298(suite) -> []; +otp_1298(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas2"), + try_test(otp_1298), + ?line unload_master("Klas2"). + +otp_1298_2(X) -> otp_1298(X). + +otp_1298_3(X) -> otp_1298(X). + +otp_1298() -> + io:format("Testing bug reported in ticket OTP-1298...~n"), + s([{[fint,0], -1}]), + ?line expect(1298, [{[fint,0], -1}]). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1331 +%% Slogan: snmp_generic should return noError when deleting non-ex row +%%----------------------------------------------------------------- +otp_1331(suite) -> []; +otp_1331(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(otp_1331), + ?line unload_master("OLD-SNMPEA-MIB"). + +otp_1331_2(X) -> otp_1331(X). + +otp_1331_3(X) -> otp_1331(X). + +otp_1331() -> + NewKeyc5 = [intCommunityStatus,[127,32,0,0],is("test")], + s([{NewKeyc5, ?destroy}]), + ?line expect(1, [{NewKeyc5, ?destroy}]). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1338 +%% Slogan: snmp bug in initialisation of default values for mnesia tabs +%%----------------------------------------------------------------- +otp_1338(suite) -> []; +otp_1338(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas2"), + try_test(otp_1338), + ?line unload_master("Klas2"). + +otp_1338_2(X) -> otp_1338(X). + +otp_1338_3(X) -> otp_1338(X). + +otp_1338() -> + s([{[kStatus2, 7], i, ?createAndGo}]), + ?line expect(1, [{[kStatus2, 7], ?createAndGo}]), + g([[kName2, 7]]), + ?line expect(2, [{[kName2, 7], "JJJ"}]). + +%%----------------------------------------------------------------- +%% Ticket: OTP-1342 +%% Slogan: default impl of snmp table can't handle bad index access, +%% Set when INDEX is read-write gets into an infinite loop! +%%----------------------------------------------------------------- +otp_1342(suite) -> []; +otp_1342(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas4"), + try_test(otp_1342), + ?line unload_master("Klas4"). + +otp_1342_2(X) -> otp_1342(X). + +otp_1342_3(X) -> otp_1342(X). + +otp_1342() -> + s([{[fIndex5, 1], i, 1}, + {[fName5, 1], i, 3}, + {[fStatus5, 1], i, ?createAndGo}]), + ?line expect(1, ?v1_2(noSuchName, noCreation), 3, any). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1366 +%% Slogan: snmp traps not sent to all managers +%% Note: NYI! We need a way to tell the test server that we need +%% mgrs on two different machines. +%%----------------------------------------------------------------- +otp_1366(suite) -> []; +otp_1366(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(otp_1366), + ?line unload_master("OLD-SNMPEA-MIB"). + +otp_1366_2(X) -> otp_1366(X). + +otp_1366_3(X) -> otp_1366(X). + +otp_1366() -> + ?INF("NOT YET IMPLEMENTED", []), + 'NYI'. + +%%----------------------------------------------------------------- +%% Ticket: OTP-2776 +%% Slogan: snmp:validate_date_and_time() fails when time is 00:00 +%%----------------------------------------------------------------- +otp_2776(suite) -> []; +otp_2776(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + try_test(otp_2776). + +otp_2776_2(X) -> otp_2776(X). + +otp_2776_3(X) -> otp_2776(X). + +otp_2776() -> + io:format("Testing bug reported in ticket OTP-2776...~n"), + + Dt01_valid = [19,98,9,1,1,0,23,0,43,0,0], + Dt02_valid = [19,98,9,1,0,0,0,0,43,0,0], % This is what is fixed: 00:00 + Dt03_valid = [19,98,2,28,1,0,23,0,43,0,0], + Dt04_invalid = [19,98,2,29,1,0,23,0,43,0,0], + Dt05_valid = [19,96,2,29,1,0,23,0,43,0,0], + Dt06_valid = [20,0,2,29,1,0,23,0,43,0,0], + Dt07_invalid = [19,96,2,30,1,0,23,0,43,0,0], % This is also fixed: 30/2 + Dt08_valid = [19,98,4,30,1,0,23,0,43,0,0], + Dt09_invalid = [19,98,4,31,1,0,23,0,43,0,0], % This is also fixed: 31/4 + Dt10_invalid = [], + Dt11_invalid = [kalle,hobbe], + L = [{ 1, true, Dt01_valid}, + { 2, true, Dt02_valid}, + { 3, true, Dt03_valid}, + { 4, false, Dt04_invalid}, + { 5, true, Dt05_valid}, + { 6, true, Dt06_valid}, + { 7, false, Dt07_invalid}, + { 8, true, Dt08_valid}, + { 9, false, Dt09_invalid}, + {10, false, Dt10_invalid}, + {11, false, Dt11_invalid}], + + ?line ok = validate_dat(L). + + +validate_dat(L) -> validate_dat(L,[]). + +validate_dat([],V) -> + Fun = fun({_,X}) -> case X of + ok -> false; + _ -> true + end + end, + validate_dat1( lists:reverse( lists:filter(Fun,V) ) ); +validate_dat([{Id,E,Dat}|T],V) -> + validate_dat(T,[validate_dat2(Id,E,Dat) | V]). + +validate_dat1([]) -> ok; +validate_dat1(L) -> {error,L}. + +validate_dat2(Id, E, Dat) -> + Res = case {E,snmp:validate_date_and_time(Dat)} of + {E,E} -> ok; + {E,A} -> {E,A} + end, + {Id, Res}. + + +%%----------------------------------------------------------------- +%% Ticket: OTP-2979 +%% Slogan: get-next on more than 1 column in an empty table +%% returns bad response. +%%----------------------------------------------------------------- +otp_2979(suite) -> []; +otp_2979(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Test1"), + ?line init_old(), + try_test(otp_2979), + ?line unload_master("Test1"). + +otp_2979_2(X) -> otp_2979(X). + +otp_2979_3(X) -> otp_2979(X). + +otp_2979() -> + gn([[sparseDescr], [sparseStatus]]), + ?line expect(1, [{[sparseStr,0], "slut"}, + {[sparseStr,0], "slut"}]). + +%%----------------------------------------------------------------- +%% Ticket: OTP-3187 +%% Slogan: get-next on vacmAccessTable for colums > 5 returns +%% endOfTable - should return value. +%%----------------------------------------------------------------- +otp_3187(suite) -> []; +otp_3187(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + otp_3187(), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). + +otp_3187_2(X) -> otp_3187(X). + +otp_3187_3(X) -> otp_3187(X). + +otp_3187() -> + ?line Elements = + snmp_view_based_acm_mib:vacmAccessTable(get_next,[],[4,5,6]), + lists:foreach(fun(E) -> + ?line if E == endOfTable -> + ?FAIL(endOfTable); + true -> ok + end + end, Elements). + +%%----------------------------------------------------------------- +%% Ticket: OTP-3542 +%% Slogan: +%%----------------------------------------------------------------- +otp_3542(suite) -> []; +otp_3542(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + try_test(otp_3542). + +otp_3542() -> + io:format("SNMP v3 discovery...~n"), + ?line Res = snmp_test_mgr:d(), + io:format("SNMP v3 discovery result: ~p~n",[Res]). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-3725 +%% Slogan: Slow response time on snmpa:int_to_enum +%%----------------------------------------------------------------- +otp_3725(suite) -> []; +otp_3725(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(otp_3725_test, [node()]), + ?line unload_master("OLD-SNMPEA-MIB"). + +%% Req. OLD-SNMPEA-MIB +otp_3725_test(MaNode) -> + io:format("Testing feature requested in ticket OTP-3725...~n"), + ?line rpc:call(MaNode,snmpa,verbosity,[symbolic_store,trace]), + ?line Db = rpc:call(MaNode,snmp,get_symbolic_store_db,[]), + ?DBG("otp_3725_test -> Db = ~p",[Db]), + + ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, + [Db, intAgentIpAddress]), + ?DBG("otp_3725_test -> name_to_oid for ~p: ~p",[intAgentIpAddress,OID]), + ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, oid_to_name, + [Db,OID]), + ?DBG("otp_3725_test -> oid_to_name for ~p: ~p",[OID,intAgentIpAddress]), + ?line false = rpc:call(MaNode, snmp, name_to_oid, [Db, intAgentIpAddres]), + ?line false = rpc:call(MaNode, snmp, oid_to_name, + [Db, [1,5,32,3,54,3,3,34,4]]), + ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, + [Db, intViewType, excluded]), + ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, + [Db, intViewType, 2]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, intViewType, exclude]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, intAgentIpAddress, exclude]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, intAgentIpAddre, exclude]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, intViewType, 3]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, + [Db, intAgentIpAddress, 2]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, + [Db, intAgentIpAddre, 2]), + ?line {value, active} = rpc:call(MaNode, snmp, int_to_enum, + [Db, 'RowStatus', ?active]), + ?line {value, ?destroy} = rpc:call(MaNode, snmp, enum_to_int, + [Db, 'RowStatus', destroy]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, 'RowStatus', xxxdestroy]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, 'xxRowStatus', destroy]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'RowStatus', 25]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'xxRowStatus', 1]), + ok. + + +%%----------------------------------------------------------------- +%% Ticket: OTP-4394 +%% Slogan: Target mib tag list check invalid +%%----------------------------------------------------------------- + + + +init_otp_4394(Config) when list(Config) -> + ?DBG("init_otp_4394 -> entry with" + "~n Config: ~p", [Config]), + ?line AgentDir = ?config(agent_dir, Config), + ?line MgrDir = ?config(mgr_dir, Config), + ?line Ip = ?config(ip, Config), + ?line otp_4394_config(AgentDir, MgrDir, Ip), + MasterAgentVerbosity = {master_agent_verbosity, trace}, + NetIfVerbosity = {net_if_verbosity, trace}, + Opts = [MasterAgentVerbosity,NetIfVerbosity], + [{vsn, v1} | start_v1_agent(Config,Opts)]. + +otp_4394_config(AgentDir, MgrDir, Ip0) -> + ?DBG("otp_4394_config -> entry with" + "~n AgentDir: ~p" + "~n MgrDir: ~p" + "~n Ip0: ~p", [AgentDir, MgrDir, Ip0]), + Vsn = [v1], + Ip = tuple_to_list(Ip0), + ?line snmp_config:write_agent_snmp_files(AgentDir, Vsn, Ip, + ?TRAP_UDP, Ip, 4000, + "OTP-4394 test"), + ?line case update_usm(Vsn, AgentDir) of + true -> + ?line copy_file(filename:join(AgentDir, "usm.conf"), + filename:join(MgrDir, "usm.conf")), + ?line update_usm_mgr(Vsn, MgrDir); + false -> + ?line ok + end, + C1 = {"a", "all-rights", "initial", "", "pc"}, + C2 = {"c", "secret", "secret_name", "", "secret_tag"}, + ?line write_community_conf(AgentDir, [C1, C2]), + ?line update_vacm(Vsn, AgentDir), + Ta1 = {"shelob v1", + [134,138,177,177], 5000, 1500, 3, %% Använd Ip och modda + "pc1", + "target_v1", "", + %% [255,255,255,255,0,0], + [], + 2048}, + Ta2 = {"bifur v1", + [134,138,177,75], 5000, 1500, 3, %% Använd Ip + "pc2", + "target_v1", "", + %% [255,255,255,255,0,0], + [], 2048}, + ?line write_target_addr_conf(AgentDir, [Ta1, Ta2]), + ?line write_target_params_conf(AgentDir, Vsn), + ?line write_notify_conf(AgentDir), + ok. + + + +finish_otp_4394(Config) when list(Config) -> + ?DBG("finish_otp_4394 -> entry", []), + C1 = stop_agent(Config), + delete_files(C1), + erase(mgr_node), + lists:keydelete(vsn, 1, C1). + +otp_4394_test(suite) -> []; +otp_4394_test(Config) -> + ?DBG("otp_4394_test -> entry", []), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + try_test(otp_4394_test1), + ?DBG("otp_4394_test -> done", []), + ok. + +otp_4394_test1() -> + ?DBG("otp_4394_test1 -> entry", []), + gn([[1,1]]), + Res = + case snmp_test_mgr:expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]) of + %% {error, 1, {"?",[]}, {"~w",[timeout]}} + {error, 1, _, {_, [timeout]}} -> + ?DBG("otp_4394_test1 -> expected result: timeout", []), + ok; + Else -> + Else + end, + ?DBG("otp_4394_test1 -> done with: ~p", [Res]), + Res. + + +%%%-------------------------------------------------- +%%% Used to test the standard mib with our +%%% configuration. +%%%-------------------------------------------------- +run(F, A, Opts) -> + M = get(mib_dir), + Dir = get(mgr_dir), + User = snmp_misc:get_option(user, Opts, "all-rights"), + SecLevel = snmp_misc:get_option(sec_level, Opts, noAuthNoPriv), + EngineID = snmp_misc:get_option(engine_id, Opts, "agentEngine"), + CtxEngineID = snmp_misc:get_option(context_engine_id, Opts, EngineID), + Community = snmp_misc:get_option(community, Opts, "all-rights"), + ?DBG("run -> start crypto app",[]), + Crypto = case os:type() of + vxworks -> + no_crypto; + _ -> + ?CRYPTO_START() + end, + ?DBG("run -> Crypto: ~p",[Crypto]), + catch snmp_test_mgr:stop(), % If we had a running mgr from a failed case + StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", + ?DBG("run -> config:~n" + "\tM: ~p~n" + "\tDir: ~p~n" + "\tUser: ~p~n" + "\tSecLevel: ~p~n" + "\tEngineID: ~p~n" + "\tCtxEngineID: ~p~n" + "\tCommunity: ~p~n" + "\tStdM: ~p", + [M,Dir,User,SecLevel,EngineID,CtxEngineID,Community,StdM]), + case snmp_test_mgr:start([%% {agent, snmp_test_lib:hostname()}, + {packet_server_debug,true}, + {debug,true}, + {agent, get(master_host)}, + {agent_udp, 4000}, + {trap_udp, 5000}, + {recbuf,65535}, + quiet, + get(vsn), + {community, Community}, + {user, User}, + {sec_level, SecLevel}, + {engine_id, EngineID}, + {context_engine_id, CtxEngineID}, + {dir, Dir}, + {mibs, mibs(StdM, M)}]) of + {ok, _Pid} -> + Res = apply(?MODULE, F, A), + catch snmp_test_mgr:stop(), + Res; + Err -> + io:format("Error starting manager: ~p\n", [Err]), + catch snmp_test_mgr:stop(), + ?line exit({mgr_start, Err}) + end. + + +mibs(StdMibDir,MibDir) -> + [join(StdMibDir, ?v1_2("STANDARD-MIB.bin", "SNMPv2-MIB.bin")), + join(MibDir, "OLD-SNMPEA-MIB.bin"), + join(StdMibDir, "SNMP-FRAMEWORK-MIB"), + join(StdMibDir, "SNMP-MPD-MIB"), + join(StdMibDir, "SNMP-VIEW-BASED-ACM-MIB"), + join(StdMibDir, "SNMP-USER-BASED-SM-MIB"), + join(StdMibDir, "SNMP-TARGET-MIB"), + join(StdMibDir, "SNMP-NOTIFICATION-MIB"), + join(MibDir, "Klas1.bin"), + join(MibDir, "Klas2.bin"), + join(MibDir, "Klas3.bin"), + join(MibDir, "Klas4.bin"), + join(MibDir, "SA-MIB.bin"), + join(MibDir, "TestTrap.bin"), + join(MibDir, "Test1.bin"), + join(MibDir, "Test2.bin"), + join(MibDir, "TestTrapv2.bin")]. + +join(D,F) -> + filename:join(D,F). + +%% string used in index +is(S) -> [length(S) | S]. + +try_test(Func) -> + call(get(mgr_node), ?MODULE, run, [Func, [], []]). + +try_test(Func, A) -> + call(get(mgr_node), ?MODULE, run, [Func, A, []]). + +try_test(Func, A, Opts) -> + call(get(mgr_node), ?MODULE, run, [Func, A, Opts]). + +call(N,M,F,A) -> + ?DBG("call -> entry with~n" + " N: ~p~n" + " M: ~p~n" + " F: ~p~n" + " A: ~p~n" + " when~n" + " get(): ~p", + [N,M,F,A,get()]), + spawn(N, ?MODULE, wait, [self(),get(),M,F,A]), + receive + {done, {'EXIT', Rn}, Loc} -> + ?DBG("call -> returned ~p",[{done, {'EXIT', Rn}, Loc}]), + put(test_server_loc, Loc), + exit(Rn); + {done, Ret, Zed} -> + ?DBG("call -> returned ~p~n",[{done, Ret, Zed}]), + Ret + end. + +wait(From, Env, M, F, A) -> + ?DBG("wait -> entry with ~n" + "\tFrom: ~p~n" + "\tEnv: ~p",[From,Env]), + lists:foreach(fun({K,V}) -> put(K,V) end, Env), + Rn = (catch apply(M, F, A)), + ?DBG("wait -> Rn: ~n~p", [Rn]), + From ! {done, Rn, get(test_server_loc)}, + exit(Rn). + +expect(A,B) -> ok = snmp_test_mgr:expect(A,B). +expect(A,B,C) -> ok = snmp_test_mgr:expect(A,B,C). +expect(A,B,C,D) -> ok = snmp_test_mgr:expect(A,B,C,D). +expect(A,B,C,D,E,F) -> ok = snmp_test_mgr:expect(A,B,C,D,E,F). + +get_req(Id, Vars) -> + ?DBG("get_req -> entry with~n" + "\tId: ~p~n" + "\tVars: ~p",[Id,Vars]), + g(Vars), + ?DBG("get_req -> await response",[]), + {ok, Val} = snmp_test_mgr:get_response(Id, Vars), + ?DBG("get_req -> response: ~p",[Val]), + Val. + +get_next_req(Vars) -> + ?DBG("get_next_req -> entry with Vars '~p', send request",[Vars]), + gn(Vars), + ?DBG("get_next_req -> await response",[]), + Response = snmp_test_mgr:receive_response(), + ?DBG("get_next_req -> response: ~p",[Response]), + Response. + + + +start_node(Name) -> + ?LOG("start_node -> entry with Name: ~p",[Name]), + M = list_to_atom(?HOSTNAME(node())), + ?DBG("start_node -> M: ~p",[M]), + Pa = filename:dirname(code:which(?MODULE)), + ?DBG("start_node -> Pa: ~p",[Pa]), + + Args = case init:get_argument('CC_TEST') of + {ok, [[]]} -> + " -pa /clearcase/otp/libraries/snmp/ebin "; + {ok, [[Path]]} -> + " -pa " ++ Path; + error -> + "" + end, + %% Do not use start_link!!! (the proc that calls this one is tmp) + ?DBG("start_node -> Args: ~p~n",[Args]), + A = Args ++ " -pa " ++ Pa, + case (catch ?START_NODE(Name, A)) of + {ok, Node} -> + %% Tell the test_server to not clean up things it never started. + ?DBG("start_node -> Node: ~p",[Node]), + {ok, Node}; + Else -> + ?ERR("start_node -> failed with(other): Else: ~p",[Else]), + ?line ?FAIL(Else) + end. + + +stop_node(Node) -> + ?LOG("stop_node -> Node: ~p",[Node]), + rpc:cast(Node, erlang, halt, []). + +p(X) -> + io:format(user, X++"\n", []). + +sleep(X) -> + receive + after + X -> ok + end. + +%%%----------------------------------------------------------------- +%%% Configuration +%%%----------------------------------------------------------------- +config(Vsns, MgrDir, AgentDir, MIp, AIp) -> + ?line snmp_config:write_agent_snmp_files(AgentDir, Vsns, MIp, + ?TRAP_UDP, AIp, 4000, + "test"), + ?line case update_usm(Vsns, AgentDir) of + true -> + ?line copy_file(filename:join(AgentDir, "usm.conf"), + filename:join(MgrDir, "usm.conf")), + ?line update_usm_mgr(Vsns, MgrDir); + false -> + ?line ok + end, + ?line update_community(Vsns, AgentDir), + ?line update_vacm(Vsns, AgentDir), + ?line write_target_addr_conf(AgentDir, MIp, ?TRAP_UDP, Vsns), + ?line write_target_params_conf(AgentDir, Vsns), + ?line write_notify_conf(AgentDir), + ok. + +delete_files(Config) -> + Dir = ?config(agent_dir, Config), + {ok, List} = file:list_dir(Dir), + lists:foreach(fun(FName) -> file:delete(filename:join(Dir, FName)) end, + List). + +update_usm(Vsns, Dir) -> + case lists:member(v3, Vsns) of + true -> + {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),[read,write]), + file:position(Fid, eof), + ok = io:format(Fid, "{\"agentEngine\", \"all-rights\", " + "\"all-rights\", zeroDotZero, " + "usmNoAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"\", \"\"}.\n", []), + ok = io:format(Fid, "{\"agentEngine\", \"no-rights\", " + "\"no-rights\", zeroDotZero, " + "usmNoAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"\", \"\"}.\n", []), + ok = io:format(Fid, "{\"agentEngine\", \"authMD5\", " + "\"authMD5\", zeroDotZero, " + "usmHMACMD5AuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"passwd_md5xxxxxx\", \"\"}.\n", []), + ok = io:format(Fid, "{\"agentEngine\", \"authSHA\", " + "\"authSHA\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"\"}.\n", []), + ok = io:format(Fid, "{\"agentEngine\", \"privDES\", " + "\"privDES\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", + []), + ok = io:format(Fid, "{\"mgrEngine\", \"all-rights\", " + "\"all-rights\", zeroDotZero, " + "usmNoAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"\", \"\"}.\n", []), + ok = io:format(Fid, "{\"mgrEngine\", \"no-rights\", " + "\"no-rights\", zeroDotZero, " + "usmNoAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"\", \"\"}.\n", []), + ok = io:format(Fid, "{\"mgrEngine\", \"authMD5\", " + "\"authMD5\", zeroDotZero, " + "usmHMACMD5AuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"passwd_md5xxxxxx\", \"\"}.\n", []), + ok = io:format(Fid, "{\"mgrEngine\", \"authSHA\", " + "\"authSHA\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"\"}.\n", []), + ok = io:format(Fid, "{\"mgrEngine\", \"privDES\", " + "\"privDES\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", + []), + file:close(Fid), + true; + false -> + false + end. + +update_usm_mgr(Vsns, Dir) -> + case lists:member(v3, Vsns) of + true -> + {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),[read,write]), + file:position(Fid, eof), + ok = io:format(Fid, "{\"agentEngine\", \"newUser\", " + "\"newUser\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", + []), + ok = io:format(Fid, "{\"mgrEngine\", \"newUser\", " + "\"newUser\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", + []), + file:close(Fid), + true; + false -> + false + end. + +rewrite_usm_mgr(Dir, ShaKey, DesKey) -> + ?line ok = file:rename(filename:join(Dir,"usm.conf"), + filename:join(Dir,"usm.old")), + ?line {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),write), + ok = io:format(Fid, "{\"agentEngine\", \"newUser\", " + "\"newUser\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"~s\", \"~s\"}.\n", + [ShaKey, DesKey]), + ok = io:format(Fid, "{\"mgrEngine\", \"newUser\", " + "\"newUser\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"~s\", \"~s\"}.\n", + [ShaKey, DesKey]), + file:close(Fid). + +reset_usm_mgr(Dir) -> + ?line ok = file:rename(filename:join(Dir,"usm.old"), + filename:join(Dir,"usm.conf")). + + +update_community([v3], _Dir) -> ok; +update_community(_, Dir) -> + {ok, Fid} = file:open(filename:join(Dir,"community.conf"),[read,write]), + file:position(Fid, eof), + ok=io:format(Fid,"{\"no-rights\",\"no-rights\",\"no-rights\",\"\",\"\"}.\n", + []), + file:close(Fid). + + +-define(tDescr_instance, [1,3,6,1,2,1,16,1,0]). +update_vacm(_Vsn, Dir) -> + {ok, Fid} = file:open(filename:join(Dir,"vacm.conf"),[read,write]), + file:position(Fid, eof), + ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"authMD5\",\"initial\"}.\n",[]), + ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"authSHA\",\"initial\"}.\n",[]), + ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"privDES\",\"initial\"}.\n",[]), + ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"newUser\",\"initial\"}.\n",[]), + ok = io:format(Fid, "{vacmViewTreeFamily, \"internet\", " + "~w, excluded, null}.\n", [?tDescr_instance]), + file:close(Fid). + + +vacm_ver(v1) -> v1; +vacm_ver(v2) -> v2c; +vacm_ver(v3) -> usm. + + +write_community_conf(Dir, Confs) -> + {ok, Fid} = file:open(filename:join(Dir,"community.conf"),write), + ok = write_community_conf1(Fid, Confs), + file:close(Fid). + +write_community_conf1(_, []) -> + ok; +write_community_conf1(Fid, [{ComIdx, ComName, SecName, CtxName, TransTag}|Confs]) -> + ok = io:format(Fid, "{\"~s\", \"~s\", \"~s\", \"~s\", \"~s\"}.~n", + [ComIdx, ComName, SecName, CtxName, TransTag]), + write_community_conf1(Fid, Confs). + + +write_target_addr_conf(Dir, Confs) -> + {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), + ok = write_target_addr_conf1(Fid, Confs), + file:close(Fid). + + +write_target_addr_conf1(_, []) -> + ok; +write_target_addr_conf1(Fid, + [{Name, Ip, Port, Timeout, Retry, TagList, ParamName, + EngineId, TMask, MaxMsgSz}|Confs]) -> + ok = io:format(Fid, "{\"~s\", ~w, ~w, ~w, ~w, \"~s\", \"~s\", \"~s\", ~w, ~w}.~n", + [Name, Ip, Port, Timeout, Retry, TagList, ParamName, + EngineId, TMask, MaxMsgSz]), + write_target_addr_conf1(Fid, Confs). + +write_target_addr_conf(Dir, ManagerIp, UDP, Vsns) -> + {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), + lists:foreach(fun(Vsn) -> + ok = io:format(Fid, + "{\"~s\", ~w, ~w, 1500, 3, " + "\"std_trap\", \"~s\"}.~n", + [mk_ip(ManagerIp, Vsn), + ManagerIp, UDP, mk_param(Vsn)]), + case Vsn of + v1 -> ok; + v2 -> + ok = io:format(Fid, + "{\"~s.2\",~w,~w,1500,3, " + "\"std_inform\", \"~s\"}.~n", + [mk_ip(ManagerIp, Vsn), + ManagerIp, UDP, + mk_param(Vsn)]); + v3 -> + ok = io:format(Fid, + "{\"~s.3\",~w,~w,1500,3, " + "\"std_inform\", \"~s\", " + "\"mgrEngine\", [], 1024}.~n", + [mk_ip(ManagerIp, Vsn), + ManagerIp, UDP, + mk_param(Vsn)]) + end + end, + Vsns), + file:close(Fid). + +mk_param(v1) -> "target_v1"; +mk_param(v2) -> "target_v2"; +mk_param(v3) -> "target_v3". + +mk_ip([A,B,C,D], Vsn) -> + io_lib:format("~w.~w.~w.~w ~w", [A,B,C,D,Vsn]). + + +rewrite_target_addr_conf(Dir,NewPort) -> + TAFile = filename:join(Dir, "target_addr.conf"), + ?DBG("rewrite_target_addr_conf -> read target file info of address config file",[]), + case file:read_file_info(TAFile) of + {ok, _} -> ok; + {error, R} -> ?ERR("failure reading file info of " + "target address config file: ~p",[R]), + ok + end, + + ?line [TrapAddr|Addrs] = + snmp_conf:read(TAFile,fun(R) -> rewrite_target_addr_conf1(R) end), + + ?DBG("rewrite_target_addr_conf -> TrapAddr: ~p",[TrapAddr]), + + NewAddrs = [rewrite_target_addr_conf2(NewPort,TrapAddr)|Addrs], + + ?DBG("rewrite_target_addr_conf -> NewAddrs: ~p",[NewAddrs]), + + ?line ok = file:rename(filename:join(Dir,"target_addr.conf"), + filename:join(Dir,"target_addr.old")), + ?line {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), + + ?line ok = rewrite_target_addr_conf3(Fid,NewAddrs), + + file:close(Fid). + +rewrite_target_addr_conf1(O) -> + {ok,O}. + +rewrite_target_addr_conf2(NewPort,{Name,Ip,_Port,Timeout,Retry, + "std_trap",EngineId}) -> + ?LOG("rewrite_target_addr_conf2 -> entry with std_trap",[]), + {Name,Ip,NewPort,Timeout,Retry,"std_trap",EngineId}; +rewrite_target_addr_conf2(_NewPort,O) -> + ?LOG("rewrite_target_addr_conf2 -> entry with " + "~n O: ~p",[O]), + O. + + +rewrite_target_addr_conf3(_,[]) -> ok; +rewrite_target_addr_conf3(Fid,[{Name,Ip,Port,Timeout,Retry, + ParamName,EngineId}|T]) -> + ?LOG("rewrite_target_addr_conf3 -> write(1) ~s",[ParamName]), + io:format(Fid, + "{\"~s\", " % Name + "~p, " % Ip + "~p, " % Port + "~p, " % Timeout + "~p, " % Retry + "\"~s\", " % ParamsName + "\"~s\"}.", % EngineId + [Name,Ip,Port,Timeout,Retry,ParamName,EngineId]), + rewrite_target_addr_conf3(Fid,T); +rewrite_target_addr_conf3(Fid,[{Name,Ip,Port,Timeout,Retry,TagList, + ParamName,EngineId,TMask,MMS}|T]) -> + ?LOG("rewrite_target_addr_conf3 -> write(2) ~s",[ParamName]), + io:format(Fid, + "{\"~s\", " % Name + "~p, " % Ip + "~p, " % Port + "~p, " % Timeout + "~p, " % Retry + "\"~s\", " % TagList + "\"~s\", " % ParamsName + "\"~s\"," % EngineId + "~p, " % TMask + "~p}.", % MMS + [Name,Ip,Port,Timeout,Retry,TagList,ParamName, + EngineId,TMask,MMS]), + rewrite_target_addr_conf3(Fid,T). + +reset_target_addr_conf(Dir) -> + ?line ok = file:rename(filename:join(Dir,"target_addr.old"), + filename:join(Dir,"target_addr.conf")). + +write_target_params_conf(Dir, Vsns) -> + {ok, Fid} = file:open(filename:join(Dir,"target_params.conf"),write), + lists:foreach(fun(Vsn) -> + MP = if Vsn == v1 -> v1; + Vsn == v2 -> v2c; + Vsn == v3 -> v3 + end, + SM = if Vsn == v1 -> v1; + Vsn == v2 -> v2c; + Vsn == v3 -> usm + end, + ok = io:format(Fid, "{\"target_~w\", ~w, ~w, " + "\"all-rights\", noAuthNoPriv}.~n", + [Vsn, MP, SM]) + end, + Vsns), + file:close(Fid). + +rewrite_target_params_conf(Dir, SecName, SecLevel) -> + ?line ok = file:rename(filename:join(Dir,"target_params.conf"), + filename:join(Dir,"target_params.old")), + ?line {ok, Fid} = file:open(filename:join(Dir,"target_params.conf"),write), + ?line ok = io:format(Fid, "{\"target_v3\", v3, usm, \"~s\", ~w}.~n", + [SecName, SecLevel]), + file:close(Fid). + +reset_target_params_conf(Dir) -> + ?line ok = file:rename(filename:join(Dir,"target_params.old"), + filename:join(Dir,"target_params.conf")). + +write_notify_conf(Dir) -> + {ok, Fid} = file:open(filename:join(Dir,"notify.conf"),write), + ok = io:format(Fid, "{\"standard trap\", \"std_trap\", trap}.~n", []), + ok = io:format(Fid, "{\"standard inform\", \"std_inform\",inform}.~n", []), + file:close(Fid). + +ver_to_trap_str([v1]) -> "v1"; +ver_to_trap_str([v2]) -> "v2"; +% default is to use the latest snmp version +ver_to_trap_str([v1,v2]) -> "v2". + + + +write_view_conf(Dir) -> + {ok, Fid} = file:open(a(Dir,"view.conf"),write), + ok = io:format(Fid, "{2, [1,3,6], included, null}.~n", []), + ok = io:format(Fid, "{2, ~w, excluded, null}.~n", [?tDescr_instance]), + file:close(Fid). + +a(A,B) -> lists:append(A,B). + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +copy_file(From, To) -> + {ok, Bin} = file:read_file(From), + ok = file:write_file(To, Bin). + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +display_memory_usage() -> + Info = snmpa:info(snmp_master_agent), + TreeSize = lists_key1search(tree_size_bytes, Info), + ProcMem = lists_key1search(process_memory, Info), + MibDbSize = lists_key1search([db_memory,mib], Info), + NodeDbSize = lists_key1search([db_memory,node], Info), + TreeDbSize = lists_key1search([db_memory,tree], Info), + ?INF("Memory usage: " + "~n Tree size: ~p" + "~n Process memory size: ~p" + "~n Mib db size: ~p" + "~n Node db size: ~p" + "~n Tree db size: ~p", + [TreeSize, ProcMem, MibDbSize, NodeDbSize, TreeDbSize]). + +lists_key1search([], Res) -> + Res; +lists_key1search([Key|Keys], List) when atom(Key), list(List) -> + case lists:keysearch(Key, 1, List) of + {value, {Key, Val}} -> + lists_key1search(Keys, Val); + false -> + undefined + end; +lists_key1search(Key, List) when atom(Key) -> + case lists:keysearch(Key, 1, List) of + {value, {Key, Val}} -> + Val; + false -> + undefined + end. + + +regs() -> + lists:sort(registered()). diff --git a/lib/snmp/test/exp/snmp_agent_mt_test.erl b/lib/snmp/test/exp/snmp_agent_mt_test.erl new file mode 100644 index 0000000000..4f125c0017 --- /dev/null +++ b/lib/snmp/test/exp/snmp_agent_mt_test.erl @@ -0,0 +1,5649 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2005-2010. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% + +-module(snmp_agent_mt_test). + +%% TODO +%% * Test fault-tolerance (kill master etc) +%% + +-compile(export_all). + +-define(application, snmp). + +-include_lib("kernel/include/file.hrl"). +-include_lib("test_server/include/test_server.hrl"). +-include("snmp_test_lib.hrl"). +-define(SNMP_USE_V3, true). +-include_lib("snmp/include/snmp_types.hrl"). +%% -include_lib("snmp/include/SNMP-COMMUNITY-MIB.hrl"). +%% -include_lib("snmp/include/SNMP-VIEW-BASED-ACM-MIB.hrl"). +%% -include_lib("snmp/include/SNMP-USER-BASED-SM-MIB.hrl"). + + +-define(klas1, [1,3,6,1,2,1,7]). +-define(klas2, [1,3,6,1,2,1,9]). +-define(klas3, [1,3,6,1,2,1,8,1]). +-define(klas4, [1,3,6,1,2,1,8,4]). +-define(sa, [1,3,6,1,4,1,193,2]). +-define(system, [1,3,6,1,2,1,1]). +-define(snmp, [1,3,6,1,2,1,11]). +-define(snmpTraps, [1,3,6,1,6,3,1,1,5]). +-define(ericsson, [1,3,6,1,4,1,193]). +-define(testTrap, [1,3,6,1,2,1,15,0]). +-define(xDescr, [1,3,6,1,2,1,17,1]). +-define(xDescr2, [1,3,6,1,2,1,17,2]). + +-define(active, 1). +-define(notInService, 2). +-define(notReady, 3). +-define(createAndGo, 4). +-define(createAndWait, 5). +-define(destroy, 6). + +-define(TRAP_UDP, 5000). + +-define(tooBigStr, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"). + +-define(str(X), snmp_pdus:bits_to_str(X)). + +-define(break(), begin io:format(user, "break at line ~w: pid: ~p\n", + [?LINE, self()]), + receive cont -> ok end + end). + + +-import(snmp_test_mgr, [gn/1, g/1, s/1, gb/3]). +-define(v1_2(V1,V2), + case get(vsn) of + v1 -> V1; + _ -> V2 + end). + +-define(v1_2_3(V1,V2,V3), + case get(vsn) of + v1 -> V1; + v2 -> V2; + _ -> V3 + end). + +all() -> +[cases()]. + +groups() -> + [{mib_storage, [], + [{group, mib_storage_ets}, {group, mib_storage_dets}, + {group, mib_storage_mnesia}, + {group, mib_storage_size_check_ets}, + {group, mib_storage_size_check_dets}, + {group, mib_storage_size_check_mnesia}, + {group, mib_storage_varm_dets}, + {group, mib_storage_varm_mnesia}]}, + {mib_storage_ets, [], mib_storage_ets_cases()}, + {mib_storage_dets, [], mib_storage_dets_cases()}, + {mib_storage_mnesia, [], mib_storage_mnesia_cases()}, + {mib_storage_size_check_ets, [], + mse_size_check_cases()}, + {mib_storage_size_check_dets, [], + msd_size_check_cases()}, + {mib_storage_size_check_mnesia, [], + msm_size_check_cases()}, + {mib_storage_varm_dets, [], + varm_mib_storage_dets_cases()}, + {mib_storage_varm_mnesia, [], + varm_mib_storage_mnesia_cases()}, + {test_v1, [], v1_cases()}, {test_v2, [], v2_cases()}, + {test_v1_v2, [], v1_v2_cases()}, + {test_v3, [], v3_cases()}, + {test_multi_threaded, [], mt_cases()}, + {multiple_reqs, [], mul_cases()}, + {multiple_reqs_2, [], mul_cases_2()}, + {v2_inform, [], [v2_inform_i]}, + {v3_security, [], + [v3_crypto_basic, v3_md5_auth, v3_sha_auth, + v3_des_priv]}, + {standard_mibs, [], + [snmp_standard_mib, snmp_community_mib, + snmp_framework_mib, snmp_target_mib, + snmp_notification_mib, snmp_view_based_acm_mib]}, + {standard_mibs_2, [], + [snmpv2_mib_2, snmp_community_mib_2, + snmp_framework_mib_2, snmp_target_mib_2, + snmp_notification_mib_2, snmp_view_based_acm_mib_2]}, + {standard_mibs_3, [], + [snmpv2_mib_3, snmp_framework_mib_3, snmp_mpd_mib_3, + snmp_target_mib_3, snmp_notification_mib_3, + snmp_view_based_acm_mib_3, snmp_user_based_sm_mib_3]}, + {reported_bugs, [], + [otp_1128, otp_1129, otp_1131, otp_1162, otp_1222, + otp_1298, otp_1331, otp_1338, otp_1342, otp_2776, + otp_2979, otp_3187, otp_3725]}, + {reported_bugs_2, [], + [otp_1128_2, otp_1129_2, otp_1131_2, otp_1162_2, + otp_1222_2, otp_1298_2, otp_1331_2, otp_1338_2, + otp_1342_2, otp_2776_2, otp_2979_2, otp_3187_2]}, + {reported_bugs_3, [], + [otp_1128_3, otp_1129_3, otp_1131_3, otp_1162_3, + otp_1222_3, otp_1298_3, otp_1331_3, otp_1338_3, + otp_1342_3, otp_2776_3, otp_2979_3, otp_3187_3, + otp_3542]}, + {tickets, [], [{group, otp_4394}]}, + {otp_4394, [], [otp_4394_test]}]. + +init_per_group(otp_4394, Config) -> + init_otp_4394(Config); +init_per_group(v2_inform, Config) -> + init_v2_inform(Config); +init_per_group(multiple_reqs_2, Config) -> + init_mul(Config); +init_per_group(multiple_reqs, Config) -> + init_mul(Config); +init_per_group(test_multi_threaded, Config) -> + init_mt(Config); +init_per_group(test_v3, Config) -> + init_v3(Config); +init_per_group(test_v1_v2, Config) -> + init_v1_v2(Config); +init_per_group(test_v2, Config) -> + init_v2(Config); +init_per_group(test_v1, Config) -> + init_v1(Config); +init_per_group(mib_storage_varm_mnesia, Config) -> + init_varm_mib_storage_mnesia(Config); +init_per_group(mib_storage_varm_dets, Config) -> + init_varm_mib_storage_dets(Config); +init_per_group(mib_storage_size_check_mnesia, Config) -> + init_size_check_msm(Config); +init_per_group(mib_storage_size_check_dets, Config) -> + init_size_check_msd(Config); +init_per_group(mib_storage_size_check_ets, Config) -> + init_size_check_mse(Config); +init_per_group(mib_storage_mnesia, Config) -> + init_mib_storage_mnesia(Config); +init_per_group(mib_storage_dets, Config) -> + init_mib_storage_dets(Config); +init_per_group(mib_storage_ets, Config) -> + init_mib_storage_ets(Config); +init_per_group(_GroupName, Config) -> + Config. + +end_per_group(otp_4394, Config) -> + finish_otp_4394(Config); +end_per_group(v2_inform, Config) -> + finish_v2_inform(Config); +end_per_group(multiple_reqs_2, Config) -> + finish_mul(Config); +end_per_group(multiple_reqs, Config) -> + finish_mul(Config); +end_per_group(test_multi_threaded, Config) -> + finish_mt(Config); +end_per_group(test_v3, Config) -> + finish_v3(Config); +end_per_group(test_v1_v2, Config) -> + finish_v1_v2(Config); +end_per_group(test_v2, Config) -> + finish_v2(Config); +end_per_group(test_v1, Config) -> + finish_v1(Config); +end_per_group(mib_storage_varm_mnesia, Config) -> + finish_varm_mib_storage_mnesia(Config); +end_per_group(mib_storage_varm_dets, Config) -> + finish_varm_mib_storage_dets(Config); +end_per_group(mib_storage_size_check_mnesia, Config) -> + finish_size_check_msm(Config); +end_per_group(mib_storage_size_check_dets, Config) -> + finish_size_check_msd(Config); +end_per_group(mib_storage_size_check_ets, Config) -> + finish_size_check_mse(Config); +end_per_group(mib_storage_mnesia, Config) -> + finish_mib_storage_mnesia(Config); +end_per_group(mib_storage_dets, Config) -> + finish_mib_storage_dets(Config); +end_per_group(mib_storage_ets, Config) -> + finish_mib_storage_ets(Config); +end_per_group(_GroupName, Config) -> + Config. + + +init_per_testcase(_Case, Config) when list(Config) -> + Dog = ?t:timetrap(?t:minutes(6)), + [{watchdog, Dog}|Config]. + +end_per_testcase(_Case, Config) when list(Config) -> + Dog = ?config(watchdog, Config), + ?t:timetrap_cancel(Dog), + Config. + +cases() -> +case ?OSTYPE() of + vxworks -> + [app_info, {group, test_v1}, {group, test_v2}, + {group, test_v1_v2}, {group, test_multi_threaded}, + {group, mib_storage}, {group, tickets}]; + _Else -> + [app_info, {group, test_v1}, {group, test_v2}, + {group, test_v1_v2}, {group, test_v3}, + {group, test_multi_threaded}, {group, mib_storage}, + {group, tickets}] +end. + + +%%%----------------------------------------------------------------- +%%% The test case structure is as follows: +%%% +%%% init_all - starts mnesia, +%%% +%%% init_v1 - starts agent +%%% simple +%%% big - e.g. starts/stops subagent, load/unloads mibs +%%% init_mul +%%% mul_get +%%% mul_set +%%% +%%% finish_mul +%%% +%%% finish_v1 +%%% +%%% init_v2 - starts agent +%%% finish_v2 +%%% +%%% init_bilingual - starts agent +%%% finish_bilingual +%%% +%%% finish_all +%%% +%%% There is still one problem with these testsuites. If one test +%%% fails, it may not be possible to run some other cases, as it +%%% may have e.g. created some row or loaded some table, that it +%%% didn't undo (since it failed). +%%%----------------------------------------------------------------- + +init_all(Config0) when list(Config0) -> + ?LOG("init_all -> entry with" + "~n Config0: ~p",[Config0]), + + %% -- + %% Fix config: + %% + + DataDir0 = ?config(data_dir, Config0), + DataDir1 = filename:split(filename:absname(DataDir0)), + [_|DataDir2] = lists:reverse(DataDir1), + DataDir3 = filename:join(lists:reverse(DataDir2) ++ [?snmp_test_data]), + Config1 = lists:keydelete(data_dir, 1, Config0), + Config = [{data_dir, DataDir3 ++ "/"}|Config1], + + %% -- + %% Start nodes + %% + + ?line {ok, SaNode} = start_node(snmp_sa), + ?line {ok, MgrNode} = start_node(snmp_mgr), + + + %% -- + %% Create necessary files + %% + + Dir = ?config(priv_dir, Config), + ?DBG("init_all -> Dir ~p", [Dir]), + + DataDir = ?config(data_dir, Config), + ?DBG("init_all -> DataDir ~p", [DataDir]), + + file:make_dir(MgrDir = filename:join(Dir, "mgr_dir/")), + ?DBG("init_all -> MgrDir ~p", [MgrDir]), + + file:make_dir(AgentDir = filename:join(Dir, "agent_dir/")), + ?DBG("init_all -> AgentDir ~p", [AgentDir]), + + file:make_dir(SaDir = filename:join(Dir, "sa_dir/")), + ?DBG("init_all -> SaDir ~p", [SaDir]), + + + %% -- + %% Start and initiate mnesia + %% + + ?DBG("init_all -> load application mnesia", []), + ?line ok = application:load(mnesia), + + ?DBG("init_all -> load application mnesia on node ~p", [SaNode]), + ?line ok = rpc:call(SaNode, application, load, [mnesia]), + + ?DBG("init_all -> application mnesia: set_env dir",[]), + ?line application_controller:set_env(mnesia, dir, + filename:join(Dir, "Mnesia1")), + + ?DBG("init_all -> application mnesia: set_env dir on node ~p",[SaNode]), + ?line rpc:call(SaNode, application_controller, set_env, + [mnesia, dir, filename:join(Dir, "Mnesia2")]), + + ?DBG("init_all -> create mnesia schema",[]), + ?line ok = mnesia:create_schema([SaNode, node()]), + + ?DBG("init_all -> start application mnesia",[]), + ?line ok = application:start(mnesia), + + ?DBG("init_all -> start application mnesia on ~p",[SaNode]), + ?line ok = rpc:call(SaNode, application, start, [mnesia]), + Ip = ?LOCALHOST(), + [{snmp_sa, SaNode}, + {snmp_mgr, MgrNode}, + {agent_dir, AgentDir ++ "/"}, + {mgr_dir, MgrDir ++ "/"}, + {sa_dir, SaDir ++ "/"}, + {mib_dir, DataDir}, + {ip, Ip} | + Config]. + +finish_all(Config) when list(Config) -> + SaNode = ?config(snmp_sa, Config), + MgrNode = ?config(snmp_mgr, Config), + stop_node(SaNode), + stop_node(MgrNode), + application:stop(mnesia). + +start_v1_agent(Config) when list(Config) -> + start_agent(Config, [v1]). + +start_v1_agent(Config,Opts) when list(Config), list(Opts) -> + start_agent(Config, [v1], Opts). + +start_v2_agent(Config) when list(Config) -> + start_agent(Config, [v2]). + +start_v3_agent(Config) when list(Config) -> + start_agent(Config, [v3]). + +start_bilingual_agent(Config) when list(Config) -> + start_agent(Config, [v1,v2]). + +start_multi_threaded_agent(Config) when list(Config) -> + start_agent(Config, [v2], [{snmp_multi_threaded, true}]). + +stop_agent(Config) when list(Config) -> + ?LOG("stop_agent -> entry with" + "~n Config: ~p",[Config]), + + {Sup, Par} = ?config(snmp_sup, Config), + ?DBG("stop_agent -> attempt to stop (sup) ~p" + "~n Sup: ~p" + "~n Par: ~p", + [Sup, + (catch process_info(Sup)), + (catch process_info(Par))]), + stop_sup(Sup, Par), + + {Sup2, Par2} = ?config(snmp_sub, Config), + ?DBG("stop_agent -> attempt to stop (sub) ~p" + "~n Sup2: ~p" + "~n Par2: ~p", + [Sup2, + (catch process_info(Sup2)), + (catch process_info(Par2))]), + stop_sup(Sup2, Par2), + + ?DBG("stop_agent -> done - now cleanup config", []), + C1 = lists:keydelete(snmp_sup, 1, Config), + lists:keydelete(snmp_sub, 1, C1). + + +stop_sup(Pid, _) when node(Pid) == node() -> + case (catch process_info(Pid)) of + PI when list(PI) -> + ?LOG("stop_sup -> attempt to stop ~p", [Pid]), + Ref = erlang:monitor(process, Pid), + exit(Pid, kill), + await_stopped(Pid, Ref); + {'EXIT', _Reason} -> + ?LOG("stop_sup -> ~p not running", [Pid]), + ok + end; +stop_sup(Pid, _) -> + ?LOG("stop_sup -> attempt to stop ~p", [Pid]), + Ref = erlang:monitor(process, Pid), + ?LOG("stop_sup -> Ref: ~p", [Ref]), + %% Pid ! {'EXIT', Parent, shutdown}, % usch + exit(Pid, kill), + await_stopped(Pid, Ref). + +await_stopped(Pid, Ref) -> + receive + {'DOWN', Ref, process, Pid, _Reason} -> + ?DBG("received down message for ~p", [Pid]), + ok + after 10000 -> + ?INF("await_stopped -> timeout for ~p",[Pid]), + erlang:demonitor(Ref), + ?FAIL({failed_stop,Pid}) + end. + + +start_agent(Config, Vsn) -> + start_agent(Config, Vsn, []). +start_agent(Config, Vsn, Opts) -> + ?LOG("start_agent -> entry (~p) with" + "~n Config: ~p" + "~n Vsn: ~p" + "~n Opts: ~p",[node(), Config, Vsn, Opts]), + + ?line AgentDir = ?config(agent_dir, Config), + ?line SaNode = ?config(snmp_sa, Config), + + snmp_app_env_init(vsn_init(Vsn) ++ + [{audit_trail_log, read_write_log}, + {audit_trail_log_dir, AgentDir}, + {audit_trail_log_size, {10240, 10}}, + {force_config_reload, false}, + {snmp_agent_type, master}, + {snmp_config_dir, AgentDir}, + {snmp_db_dir, AgentDir}, + {snmp_local_db_auto_repair, true}, + {snmp_master_agent_verbosity, trace}, + {snmp_supervisor_verbosity, trace}, + {snmp_mibserver_verbosity, trace}, + {snmp_symbolic_store_verbosity, trace}, + {snmp_note_store_verbosity, trace}, + {snmp_net_if_verbosity, trace}], + Opts), + + + process_flag(trap_exit,true), + + {ok, AppSup} = snmp_app_sup:start_link(), + unlink(AppSup), + ?DBG("start_agent -> snmp app supervisor: ~p",[AppSup]), + + ?DBG("start_agent -> start master agent (old style)",[]), + Sup = case (catch snmpa_app:start(normal)) of + {ok, S} -> + ?DBG("start_agent -> started, Sup: ~p",[S]), + S; + + Else -> + ?DBG("start_agent -> unknown result: ~n~p",[Else]), + %% Get info about the apps we depend on + MnesiaInfo = mnesia_running(), + ?FAIL({start_failed,Else,MnesiaInfo}) + end, + + ?DBG("start_agent -> unlink from supervisor",[]), + ?line unlink(Sup), + ?line SaDir = ?config(sa_dir, Config), + ?DBG("start_agent -> (rpc) start sub on ~p",[SaNode]), + ?line {ok, Sub} = rpc:call(SaNode, ?MODULE, start_sub, [SaDir]), + ?DBG("start_agent -> done",[]), + ?line [{snmp_sup, {Sup, self()}}, {snmp_sub, Sub} | Config]. + + +vsn_init(Vsn) -> + vsn_init([v1,v2,v3], Vsn, []). + +vsn_init([], _Vsn, Acc) -> + Acc; +vsn_init([V|Vsns], Vsn, Acc) -> + case lists:member(V, Vsn) of + true -> + vsn_init(Vsns, Vsn, [{V, true}|Acc]); + false -> + vsn_init(Vsns, Vsn, [{V, false}|Acc]) + end. + +snmp_app_env_init(Env0, Opts) -> + ?DBG("snmp_app_env_init -> unload snmp",[]), + ?line application:unload(snmp), + ?DBG("snmp_app_env_init -> load snmp",[]), + ?line application:load(snmp), + ?DBG("snmp_app_env_init -> initiate (snmp) application env",[]), + F1 = fun({Key,Val} = New, Acc0) -> + ?DBG("snmp_app_env_init -> " + "updating setting ~p to ~p", [Key, Val]), + case lists:keyreplace(Key, 1, Acc0, New) of + Acc0 -> + [New|Acc0]; + Acc -> + Acc + end + end, + Env = lists:foldr(F1, Env0, Opts), + ?DBG("snmp_app_env_init -> Env: ~p",[Env]), + F2 = fun({Key,Val}) -> + ?DBG("snmp_app_env_init -> setting ~p to ~p",[Key, Val]), + application_controller:set_env(snmp, Key, Val) + end, + lists:foreach(F2, Env). + + + + +%% Test if application is running +mnesia_running() -> ?IS_MNESIA_RUNNING(). +crypto_running() -> ?IS_CRYPTO_RUNNING(). + + +start_sub(Dir) -> + ?DBG("start_sub -> entry",[]), + Opts = [{db_dir, Dir}, + {supervisor, [{verbosity, trace}]}], + %% BMK BMK +% {ok, P} = snmp_supervisor:start_sub(Dir), + {ok, P} = snmpa_supervisor:start_sub_sup(Opts), + unlink(P), + {ok, {P, self()}}. + +create_tables(SaNode) -> + ?line {atomic, ok} = mnesia:create_table([{name, friendsTable2}, + {ram_copies, [SaNode]}, + {snmp, [{key, integer}]}, + {attributes, [a1,a2,a3]}]), + ?line {atomic, ok} = mnesia:create_table([{name, kompissTable2}, + {ram_copies, [SaNode]}, + {snmp, [{key, integer}]}, + {attributes, [a1,a2,a3]}]), + ?line {atomic, ok} = mnesia:create_table([{name, snmp_variables}, + {attributes, [a1,a2]}]). + +delete_tables() -> + mnesia:delete_table(friendsTable2), + mnesia:delete_table(kompissTable2), + mnesia:delete_table(snmp_variables). + +%% Creation is done in runtime! +delete_mib_storage_mnesia_tables() -> + mnesia:delete_table(snmpa_mib_data), + mnesia:delete_table(snmpa_mib_tree), + mnesia:delete_table(snmpa_symbolic_store). + +%%----------------------------------------------------------------- +%% A test case is always one of: +%% - v1 specific case +%% - v2 specific case +%% - v1 and v2 case +%% All v1 specific cases are prefixed with v1_, and all v2 with +%% v2_. E.g. v1_trap/v2_trap. +%% +%% All other cases are shared. However, the testserver uses the name +%% of the case to generate a file for that case. The same case cannot +%% be used in different configurations in the same suite. Therefore +%% all these functions exists in two variants, the base function +%% , and a second version _2. There may be several +%% versions as well, _N. +%%----------------------------------------------------------------- + + + + + + + + + +mib_storage_ets_cases() -> +[mse_simple, mse_v1_processing, mse_big, mse_big2, + mse_loop_mib, mse_api, mse_sa_register, mse_v1_trap, + mse_sa_error, mse_next_across_sa, mse_undo, + mse_standard_mib, mse_community_mib, mse_framework_mib, + mse_target_mib, mse_notification_mib, + mse_view_based_acm_mib, mse_sparse_table, mse_me_of, + mse_mib_of]. + +mib_storage_dets_cases() -> +[msd_simple, msd_v1_processing, msd_big, msd_big2, + msd_loop_mib, msd_api, msd_sa_register, msd_v1_trap, + msd_sa_error, msd_next_across_sa, msd_undo, + msd_standard_mib, msd_community_mib, msd_framework_mib, + msd_target_mib, msd_notification_mib, + msd_view_based_acm_mib, msd_sparse_table, msd_me_of, + msd_mib_of]. + +mib_storage_mnesia_cases() -> +[msm_simple, msm_v1_processing, msm_big, msm_big2, + msm_loop_mib, msm_api, msm_sa_register, msm_v1_trap, + msm_sa_error, msm_next_across_sa, msm_undo, + msm_standard_mib, msm_community_mib, msm_framework_mib, + msm_target_mib, msm_notification_mib, + msm_view_based_acm_mib, msm_sparse_table, msm_me_of, + msm_mib_of]. + +mse_size_check_cases() -> +[mse_size_check]. + +msd_size_check_cases() -> +[msd_size_check]. + +msm_size_check_cases() -> +[msm_size_check]. + +varm_mib_storage_dets_cases() -> +[msd_varm_mib_start]. + +varm_mib_storage_mnesia_cases() -> +[msm_varm_mib_start]. + +init_mib_storage_ets(Config) when list(Config) -> + ?LOG("init_mib_storage_ets -> entry", []), + MibStorage = {snmp_mib_storage,ets}, + init_ms(Config, [MibStorage]). + +init_mib_storage_dets(Config) when list(Config) -> + ?LOG("init_mib_storage_ets -> entry", []), + ?line AgentDir = ?GCONF(agent_dir, Config), + MibStorage = {snmp_mib_storage,{dets,AgentDir}}, + init_ms(Config, [MibStorage]). + +init_mib_storage_mnesia(Config) when list(Config) -> + ?LOG("init_mib_storage_ets -> entry", []), + MibStorage = {snmp_mib_storage,{mnesia,[]}}, + init_ms(Config, [MibStorage]). + +init_ms(Config, Opts) when list(Config) -> + ?LOG("init_mib_storage_ets -> entry", []), + ?line SaNode = ?GCONF(snmp_sa, Config), + ?line create_tables(SaNode), + ?line AgentDir = ?GCONF(agent_dir, Config), + ?line MgrDir = ?GCONF(mgr_dir, Config), + ?line Ip = ?GCONF(ip, Config), + ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, + MibsVerbosity = {snmp_mibserver_verbosity, trace}, + SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, + Opts1 = [MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity|Opts], + [{vsn, v1} | start_v1_agent(Config,Opts1)]. + +init_size_check_mse(Config) when list(Config) -> + MibStorage = {snmp_mib_storage, ets}, + init_size_check_ms(Config, [MibStorage]). + +init_size_check_msd(Config) when list(Config) -> + AgentDir = ?GCONF(agent_dir, Config), + MibStorage = {snmp_mib_storage, {dets, AgentDir}}, + init_size_check_ms(Config, [MibStorage]). + +init_size_check_msm(Config) when list(Config) -> + MibStorage = {snmp_mib_storage, {mnesia,[]}}, + init_size_check_ms(Config, [MibStorage]). + +init_size_check_ms(Config, Opts) when list(Config) -> + SaNode = ?GCONF(snmp_sa, Config), + %% We are using v3 here, so crypto must be supported or else... + case ?CRYPTO_START() of + ok -> + case ?CRYPTO_SUPPORT() of + {no, Reason} -> + ?SKIP({unsupported_encryption, Reason}); + yes -> + ok + end; + {error, Reason} -> + ?SKIP({failed_starting_crypto, Reason}) + end, + create_tables(SaNode), + AgentDir = ?GCONF(agent_dir, Config), + MgrDir = ?GCONF(mgr_dir, Config), + Ip = ?GCONF(ip, Config), + ?line ok = + config([v3], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v3} | start_agent(Config, [v3], Opts)]. + +init_varm_mib_storage_dets(Config) when list(Config) -> + ?LOG("init_varm_mib_storage_dets -> entry", []), + ?line SaNode = ?GCONF(snmp_sa, Config), + ?line create_tables(SaNode), + ?line AgentDir = ?GCONF(agent_dir, Config), + ?line MgrDir = ?GCONF(mgr_dir, Config), + ?line Ip = ?GCONF(ip, Config), + ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + MibStorage = {snmp_mib_storage,{dets,AgentDir}}, + MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, + MibsVerbosity = {snmp_mibserver_verbosity, trace}, + SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, + Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity], + [{vsn, v1}, {agent_opts,Opts} | Config]. + +init_varm_mib_storage_mnesia(Config) when list(Config) -> + ?LOG("init_varm_mib_storage_mnesia -> entry", []), + ?line SaNode = ?GCONF(snmp_sa, Config), + ?line create_tables(SaNode), + ?line AgentDir = ?GCONF(agent_dir, Config), + ?line MgrDir = ?GCONF(mgr_dir, Config), + ?line Ip = ?GCONF(ip, Config), + ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + MibStorage = {snmp_mib_storage,{mnesia,[]}}, + MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, + MibsVerbosity = {snmp_mibserver_verbosity, trace}, + SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, + Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity], + [{vsn, v1}, {agent_opts,Opts} | Config]. + +finish_mib_storage_ets(Config) when list(Config) -> + ?LOG("finish_mib_storage_ets -> entry", []), + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + C2 = lists:keydelete(vsn, 1, C1), + lists:keydelete(agent_opts, 1, C2). + +finish_mib_storage_dets(Config) when list(Config) -> + ?LOG("finish_mib_storage_dets -> entry", []), + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + C2 = lists:keydelete(vsn, 1, C1), + lists:keydelete(agent_opts, 1, C2). + +finish_mib_storage_mnesia(Config) when list(Config) -> + ?LOG("finish_mib_storage_mnesia -> entry", []), + delete_tables(), + delete_mib_storage_mnesia_tables(), + C1 = stop_agent(Config), + delete_files(C1), + C2 = lists:keydelete(vsn, 1, C1), + lists:keydelete(agent_opts, 1, C2). + +finish_varm_mib_storage_dets(Config) when list(Config) -> + ?LOG("finish_varm_mib_storage_dets -> entry", []), + delete_tables(), + %% C1 = stop_agent(Config), % In case something went wrong... + delete_files(Config), + C2 = lists:keydelete(vsn, 1, Config), + lists:keydelete(agent_opts, 1, C2). + +finish_varm_mib_storage_mnesia(Config) when list(Config) -> + ?LOG("finish_varm_mib_storage_mnesia -> entry", []), + delete_tables(), + delete_mib_storage_mnesia_tables(), + %% C1 = stop_agent(Config), % In case something went wrong... + delete_files(Config), + C2 = lists:keydelete(vsn, 1, Config), + lists:keydelete(agent_opts, 1, C2). + +finish_size_check_mse(Config) when list(Config) -> + finish_size_check_ms(Config). + +finish_size_check_msd(Config) when list(Config) -> + finish_size_check_ms(Config). + +finish_size_check_msm(Config) when list(Config) -> + finish_size_check_ms(Config). + +finish_size_check_ms(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + + +%% These are just interface functions to fool the test server +mse_simple(X) -> simple(X). +mse_v1_processing(X) -> v1_processing(X). +mse_big(X) -> big(X). +mse_big2(X) -> big2(X). +mse_loop_mib(X) -> loop_mib(X). +mse_api(X) -> api(X). +mse_sa_register(X) -> sa_register(X). +mse_v1_trap(X) -> v1_trap(X). +mse_sa_error(X) -> sa_error(X). +mse_next_across_sa(X) -> next_across_sa(X). +mse_undo(X) -> undo(X). +mse_standard_mib(X) -> snmp_standard_mib(X). +mse_community_mib(X) -> snmp_community_mib(X). +mse_framework_mib(X) -> snmp_framework_mib(X). +mse_target_mib(X) -> snmp_target_mib(X). +mse_notification_mib(X) -> snmp_notification_mib(X). +mse_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). +mse_sparse_table(X) -> sparse_table(X). +mse_me_of(X) -> ms_me_of(X). +mse_mib_of(X) -> ms_mib_of(X). + +msd_simple(X) -> simple(X). +msd_v1_processing(X) -> v1_processing(X). +msd_big(X) -> big(X). +msd_big2(X) -> big2(X). +msd_loop_mib(X) -> loop_mib(X). +msd_api(X) -> api(X). +msd_sa_register(X) -> sa_register(X). +msd_v1_trap(X) -> v1_trap(X). +msd_sa_error(X) -> sa_error(X). +msd_next_across_sa(X) -> next_across_sa(X). +msd_undo(X) -> undo(X). +msd_standard_mib(X) -> snmp_standard_mib(X). +msd_community_mib(X) -> snmp_community_mib(X). +msd_framework_mib(X) -> snmp_framework_mib(X). +msd_target_mib(X) -> snmp_target_mib(X). +msd_notification_mib(X) -> snmp_notification_mib(X). +msd_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). +msd_sparse_table(X) -> sparse_table(X). +msd_me_of(X) -> ms_me_of(X). +msd_mib_of(X) -> ms_mib_of(X). + +msm_simple(X) -> simple(X). +msm_v1_processing(X) -> v1_processing(X). +msm_big(X) -> big(X). +msm_big2(X) -> big2(X). +msm_loop_mib(X) -> loop_mib(X). +msm_api(X) -> api(X). +msm_sa_register(X) -> sa_register(X). +msm_v1_trap(X) -> v1_trap(X). +msm_sa_error(X) -> sa_error(X). +msm_next_across_sa(X) -> next_across_sa(X). +msm_undo(X) -> undo(X). +msm_standard_mib(X) -> snmp_standard_mib(X). +msm_community_mib(X) -> snmp_community_mib(X). +msm_framework_mib(X) -> snmp_framework_mib(X). +msm_target_mib(X) -> snmp_target_mib(X). +msm_notification_mib(X) -> snmp_notification_mib(X). +msm_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). +msm_sparse_table(X) -> sparse_table(X). +msm_me_of(X) -> ms_me_of(X). +msm_mib_of(X) -> ms_mib_of(X). + + +mse_size_check(X) -> p("mse_size_check..."), ms_size_check(X). +msd_size_check(X) -> p("msd_size_check..."), ms_size_check(X). +msm_size_check(X) -> p("msm_size_check..."), ms_size_check(X). + +msd_varm_mib_start(X) -> p("msd_varm_mib_start..."), varm_mib_start(X). +msm_varm_mib_start(X) -> p("msm_varm_mib_start..."), varm_mib_start(X). + +ms_size_check(suite) -> []; +ms_size_check(Config) when list(Config) -> + p("ms_size_check..."), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?LOG("mib server size check...", []), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + ?line load_master_std("OTP-SNMPEA-MIB"), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-MPD-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-USER-BASED-SM-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + ?line load_master_std("SNMPv2-MIB"), + ?line load_master_std("SNMPv2-TM"), + + ?SLEEP(2000), + + ?line display_memory_usage(), + + ?line unload_master("OTP-SNMPEA-MIB"), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?line unload_master("SNMP-MPD-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-USER-BASED-SM-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + ?line unload_master("SNMPv2-MIB"), + ?line unload_master("SNMPv2-TM"), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + + ok. + + +varm_mib_start(suite) -> []; +varm_mib_start(Config) when list(Config) -> + p("varm_mib_start..."), + ?LOG("varm_mib_start -> entry", []), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + %% Start the agent + Opts = ?GCONF(agent_opts, Config), + Config1 = start_v1_agent(Config, Opts), + + %% Sleep some in order for the agent to start properly + ?DBG("varm_mib_start -> sleep some (before loading mobs)", []), + ?SLEEP(5000), + + %% Load all the mibs + HardwiredMibs = loaded_mibs(), + ?DBG("varm_mib_start -> load all mibs", []), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + + %% Unload the hardwired mibs + ?DBG("varm_mib_start -> sleep some (before unloading hardwired mibs)", []), + ?SLEEP(1000), + ?DBG("varm_mib_start -> unload (hardwired) mibs", []), + ?line unload_mibs(HardwiredMibs), %% unload hardwired + + ?DBG("varm_mib_start -> sleep some (before stopping agent)", []), + ?SLEEP(1000), + + %% Stop the agent (without deleting the stored files) + ?DBG("varm_mib_start -> stop the agent", []), + Config2 = stop_agent(Config1), + + %% Sleep some in order for the agent to stop properly + ?DBG("varm_mib_start -> sleep some (before re-starting the agent)", []), + ?SLEEP(5000), + + %% Start the agent (again) + ?DBG("varm_mib_start -> start the agent", []), + Config3 = start_v1_agent(Config2, Opts), + + ?DBG("varm_mib_start -> sleep some (before starting tests)", []), + ?SLEEP(5000), + + %% Perform the test(s) + ?DBG("varm_mib_start -> perform the tests", []), + try_test(snmp_community_mib), + try_test(snmp_framework_mib), + try_test(snmp_target_mib), + try_test(snmp_notification_mib), + + %% Stop the agent (without deleting the stored files) + ?DBG("varm_mib_start -> stop the agent", []), + stop_agent(Config3), + ok. + + +-define(snmpTrapCommunity_instance, [1,3,6,1,6,3,18,1,4,0]). +-define(vacmViewSpinLock_instance, [1,3,6,1,6,3,16,1,5,1,0]). +-define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). + +ms_me_of(suite) -> []; +ms_me_of(Config) when list(Config) -> + p("ms_me_of..."), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + ?line load_master_std("OTP-SNMPEA-MIB"), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-MPD-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + + ?SLEEP(2000), + + ?line display_memory_usage(), + + + ?DBG("ms_me_of -> find ~w from SNMP-COMMUNITY-MIB", + [?snmpTrapCommunity_instance]), + ?line ok = me_of(?snmpTrapCommunity_instance), + + ?DBG("ms_me_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", + [?vacmViewSpinLock_instance]), + ?line ok = me_of(?vacmViewSpinLock_instance), + + ?DBG("ms_me_of -> find ~w from SNMP-USER-BASED-SM-MIB", + [?usmStatsNotInTimeWindows_instance]), + ?line {error, _} = me_of(?usmStatsNotInTimeWindows_instance), + + + ?line unload_master("OTP-SNMPEA-MIB"), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?line unload_master("SNMP-MPD-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + + ok. + +me_of(Oid) -> + case snmpa:me_of(Oid) of + {ok, #me{oid = Oid}} -> + ok; + {ok, #me{oid = OtherOid}} -> + case lists:reverse(Oid) of + [0|Rest] -> + case lists:reverse(Rest) of + OtherOid -> + ok; + AnotherOid -> + {error, {invalid_oid, Oid, AnotherOid}} + end; + _ -> + {error, {invalid_oid, Oid, OtherOid}} + end; + {error, Reason} -> + {error, Reason}; + Else -> + {error, Else} + end. + + +ms_mib_of(suite) -> []; +ms_mib_of(Config) when list(Config) -> + p("ms_mib_of..."), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + ?line load_master_std("OTP-SNMPEA-MIB"), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-MPD-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + + ?SLEEP(2000), + + ?line display_memory_usage(), + + + ?DBG("ms_mib_of -> find ~w from SNMP-COMMUNITY-MIB", + [?snmpTrapCommunity_instance]), + ?line ok = mib_of(?snmpTrapCommunity_instance, 'SNMP-COMMUNITY-MIB'), + + ?DBG("ms_mib_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", + [?vacmViewSpinLock_instance]), + ?line ok = mib_of(?vacmViewSpinLock_instance, 'SNMP-VIEW-BASED-ACM-MIB'), + + ?DBG("ms_mib_of -> find ~w from SNMP-USER-BASED-SM-MIB", + [?usmStatsNotInTimeWindows_instance]), + ?line {error, _} = mib_of(?usmStatsNotInTimeWindows_instance, + 'SNMP-USER-BASED-SM-MIB'), + + + ?line unload_master("OTP-SNMPEA-MIB"), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?line unload_master("SNMP-MPD-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + + ok. + +mib_of(Oid, ExpectedMibName) -> + ?DBG("mib_of -> entry with" + "~n Oid: ~p" + "~n ExpectedMibName: ~p", [Oid, ExpectedMibName]), + %% case snmpa:mib_of(Oid) of + MibOf = snmpa:mib_of(Oid), + ?DBG("mib_of -> MibOf: ~n~p", [MibOf]), + case MibOf of + {ok, ExpectedMibName} -> + ok; + {ok, OtherMibName} -> + {error, {invalid_mib, ExpectedMibName, OtherMibName}}; + {error, Reason} -> + {error, Reason}; + Else -> + ?DBG("mib_of -> Else: ~n~p", [Else]), + {error, Else} + end. + + +app_info(suite) -> []; +app_info(Config) when list(Config) -> + SnmpDir = app_dir(snmp), + SslDir = app_dir(ssl), + CryptoDir = app_dir(crypto), + Attr = snmp:module_info(attributes), + AppVsn = + case lists:keysearch(app_vsn, 1, Attr) of + {value, {app_vsn, V}} -> + V; + false -> + "undefined" + end, + io:format("Root dir: ~s~n" + "SNMP: Application dir: ~s~n" + " Application ver: ~s~n" + "SSL: Application dir: ~s~n" + "CRYPTO: Application dir: ~s~n", + [code:root_dir(), SnmpDir, AppVsn, SslDir, CryptoDir]), + ok. + +app_dir(App) -> + case code:lib_dir(App) of + D when list(D) -> + filename:basename(D); + {error, _Reason} -> + "undefined" + end. + + + +%v1_cases() -> [loop_mib]; +v1_cases() -> +[simple, db_notify_client, v1_processing, big, big2, + loop_mib, api, subagent, mnesia, {group, multiple_reqs}, + sa_register, v1_trap, sa_error, next_across_sa, undo, + {group, reported_bugs}, {group, standard_mibs}, + sparse_table, cnt_64, opaque, change_target_addr_config]. + +init_v1(Config) when list(Config) -> + ?line SaNode = ?config(snmp_sa, Config), + ?line create_tables(SaNode), + ?line AgentDir = ?config(agent_dir, Config), + ?line MgrDir = ?config(mgr_dir, Config), + ?line Ip = ?config(ip, Config), + ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v1} | start_v1_agent(Config)]. + +finish_v1(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + + +%v2_cases() -> [loop_mib_2]; +v2_cases() -> +[simple_2, v2_processing, big_2, big2_2, loop_mib_2, + api_2, subagent_2, mnesia_2, {group, multiple_reqs_2}, + sa_register_2, v2_trap, {group, v2_inform}, sa_error_2, + next_across_sa_2, undo_2, {group, reported_bugs_2}, + {group, standard_mibs_2}, v2_types, implied, + sparse_table_2, cnt_64_2, opaque_2, v2_caps]. + +init_v2(Config) when list(Config) -> + SaNode = ?config(snmp_sa, Config), + create_tables(SaNode), + AgentDir = ?config(agent_dir, Config), + MgrDir = ?config(mgr_dir, Config), + Ip = ?config(ip, Config), + config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v2} | start_v2_agent(Config)]. + +finish_v2(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + + +v1_v2_cases() -> +[simple_bi]. + +init_v1_v2(Config) when list(Config) -> + SaNode = ?config(snmp_sa, Config), + create_tables(SaNode), + AgentDir = ?config(agent_dir, Config), + MgrDir = ?config(mgr_dir, Config), + Ip = ?config(ip, Config), + config([v1,v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, bilingual} | start_bilingual_agent(Config)]. + +finish_v1_v2(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + + +%v3_cases() -> [loop_mib_3]; +v3_cases() -> +[simple_3, v3_processing, big_3, big2_3, api_3, + subagent_3, mnesia_3, loop_mib_3, multiple_reqs_3, + sa_register_3, v3_trap, v3_inform, sa_error_3, + next_across_sa_3, undo_3, {group, reported_bugs_3}, + {group, standard_mibs_3}, {group, v3_security}, + v2_types_3, implied_3, sparse_table_3, cnt_64_3, + opaque_3, v2_caps_3]. + +init_v3(Config) when list(Config) -> + %% Make sure crypto works, otherwise start_agent will fail + %% and we will be stuck with a bunch of mnesia tables for + %% the rest of this suite... + ?DBG("start_agent -> start crypto app",[]), + case os:type() of + vxworks -> + no_crypto; + _ -> + case ?CRYPTO_START() of + ok -> + case ?CRYPTO_SUPPORT() of + {no, Reason} -> + ?SKIP({unsupported_encryption, Reason}); + yes -> + ok + end; + {error, Reason} -> + ?SKIP({failed_starting_crypto, Reason}) + end + end, + SaNode = ?config(snmp_sa, Config), + create_tables(SaNode), + AgentDir = ?config(agent_dir, Config), + MgrDir = ?config(mgr_dir, Config), + Ip = ?config(ip, Config), + ?line ok = config([v3], MgrDir, AgentDir, + tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v3} | start_v3_agent(Config)]. + +finish_v3(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + + +mt_cases() -> +[multi_threaded, mt_trap]. + +init_mt(Config) when list(Config) -> + SaNode = ?config(snmp_sa, Config), + create_tables(SaNode), + AgentDir = ?config(agent_dir, Config), + MgrDir = ?config(mgr_dir, Config), + Ip = ?config(ip, Config), + ?line ok = config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v2} | start_multi_threaded_agent(Config)]. + +finish_mt(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + +%% This one *must* be run first in each case. +init_case(Config) when list(Config) -> + ?DBG("init_case -> entry with" + "~n Config: ~p", [Config]), + SaNode = ?config(snmp_sa, Config), + MgrNode = ?config(snmp_mgr, Config), + MasterNode = node(), + + SaHost = ?HOSTNAME(SaNode), + MgrHost = ?HOSTNAME(MgrNode), + MasterHost = ?HOSTNAME(MasterNode), + {ok, MasterIP} = snmp_misc:ip(MasterHost), + {ok, MIP} = snmp_misc:ip(MgrHost), + {ok, SIP} = snmp_misc:ip(SaHost), + + + put(mgr_node, MgrNode), + put(sa_node, SaNode), + put(master_node, MasterNode), + put(sa_host, SaHost), + put(mgr_host, MgrHost), + put(master_host, MasterHost), + put(mip, tuple_to_list(MIP)), + put(masterip , tuple_to_list(MasterIP)), + put(sip, tuple_to_list(SIP)), + + MibDir = ?config(mib_dir, Config), + put(mib_dir, MibDir), + StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", + put(std_mib_dir, StdM), + + MgrDir = ?config(mgr_dir, Config), + put(mgr_dir, MgrDir), + + put(vsn, ?config(vsn, Config)), + ?DBG("init_case -> exit with" + "~n MasterNode: ~p" + "~n SaNode: ~p" + "~n MgrNode: ~p" + "~n MibDir: ~p", [MasterNode, SaNode, MgrNode, MibDir]), + {SaNode, MgrNode, MibDir}. + +load_master(Mib) -> + ?DBG("load_master -> entry with" + "~n Mib: ~p", [Mib]), + snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety + ok = snmpa:load_mibs(snmp_master_agent, [get(mib_dir) ++ Mib]). + +load_master_std(Mib) -> + ?DBG("load_master_std -> entry with" + "~n Mib: ~p", [Mib]), + snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety + ok = snmpa:load_mibs(snmp_master_agent, [get(std_mib_dir) ++ Mib]). + +unload_master(Mib) -> + ?DBG("unload_master -> entry with" + "~n Mib: ~p", [Mib]), + ok = snmpa:unload_mibs(snmp_master_agent, [Mib]). + +loaded_mibs() -> + ?DBG("loaded_mibs -> entry",[]), + Info = snmpa:info(snmp_master_agent), + {value, {loaded_mibs, Mibs}} = lists:keysearch(loaded_mibs, 1, Info), + [atom_to_list(Mib) || {Mib,_,_} <- Mibs]. + +unload_mibs(Mibs) -> + ?DBG("unload_mibs -> entry with" + "~n Mibs: ~p", [Mibs]), + ok = snmpa:unload_mibs(snmp_master_agent, Mibs). + +start_subagent(SaNode, RegTree, Mib) -> + ?DBG("start_subagent -> entry with" + "~n SaNode: ~p" + "~n RegTree: ~p" + "~n Mib: ~p", [SaNode, RegTree, Mib]), + MA = whereis(snmp_master_agent), + ?DBG("start_subagent -> MA: ~p", [MA]), + MibDir = get(mib_dir), + Mib1 = join(MibDir,Mib), + %% BMK BMK +% case rpc:call(SaNode,snmp_supervisor,start_subagent,[MA,RegTree,[Mib1]]) of + case rpc:call(SaNode, snmpa_supervisor, + start_sub_agent, [MA, RegTree, [Mib1]]) of + {ok, SA} -> + ?DBG("start_subagent -> SA: ~p", [SA]), + {ok, SA}; + Error -> + ?FAIL({subagent_start_failed, SaNode, Error, [MA, RegTree, Mib1]}) + end. + +stop_subagent(SA) -> + ?DBG("stop_subagent -> entry with" + "~n SA: ~p", [SA]), + %% BNK BMK + %% rpc:call(node(SA), snmp_supervisor, stop_subagent, [SA]). + rpc:call(node(SA), snmpa_supervisor, stop_sub_agent, [SA]). + +%%----------------------------------------------------------------- +%% This function takes care of the old OTP-SNMPEA-MIB. +%% Unfortunately, the testcases were written to use the data in the +%% internal tables, and these table are now obsolete and not used +%% by the agent. Therefore, we emulate them by using +%% OLD-SNMPEA-MIB, which uses the default impl. of all tables. +%% +%% These two rows must exist in intCommunityTable +%% {[147,214,36,45], "public", 2, readWrite}. +%% {[147,214,36,45], "standard trap", 2, read}. +%% (But with the manager's IP address) +%% +%%----------------------------------------------------------------- +init_old() -> + snmpa_local_db:table_create_row(intCommunityTable, + get(mip) ++ [6 | "public"], + {get(mip), "public", 2, 2}), + snmpa_local_db:table_create_row(intCommunityTable, + get(mip) ++ [13 | "standard trap"], + {get(mip), "standard trap", 2, 1}), + snmpa_local_db:variable_set(intAgentIpAddress, [127,0,0,1]). + + + +simple(suite) -> []; +simple(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + try_test(simple_standard_test). + +simple_2(X) -> simple(X). + +simple_bi(suite) -> []; +simple_bi(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + put(vsn, v1), % First, try v1 manager + try_test(simple_standard_test), + + put(vsn, v2), % Then, try v2 manager + try_test(simple_standard_test). + +simple_3(X) -> + simple(X). + +big(suite) -> []; +big(Config) when list(Config) -> + ?DBG("big -> entry", []), + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Starting subagent..."), + ?line pong = net_adm:ping(SaNode), + + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), + ?DBG("big -> SA: ~p", [SA]), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(big_test), + ?line stop_subagent(SA), + ?line unload_master("OLD-SNMPEA-MIB"). + +big_2(X) -> big(X). + +big_3(X) -> big(X). + + +big2(suite) -> []; +big2(Config) when list(Config) -> + %% This is exactly the same tests as 'big', but with the + %% v2 equivalent of the mibs. + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Starting subagent..."), + ?line pong = net_adm:ping(SaNode), + + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1-v2"), + ?line load_master("OLD-SNMPEA-MIB-v2"), + ?line init_old(), + try_test(big_test), + ?line stop_subagent(SA), + ?line unload_master("OLD-SNMPEA-MIB-v2"). + +big2_2(X) -> big2(X). + +big2_3(X) -> big2(X). + + +multi_threaded(suite) -> []; +multi_threaded(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test1"), + try_test(multi_threaded_test), + ?line unload_master("Test1"). + +mt_trap(suite) -> []; +mt_trap(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line load_master("Test1"), + ?line load_master("TestTrapv2"), + try_test(mt_trap_test, [MA]), + ?line unload_master("TestTrapv2"), + ?line unload_master("Test1"). + +v2_types(suite) -> []; +v2_types(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test1"), + try_test(types_v2_test), + ?line unload_master("Test1"). + +v2_types_3(X) -> v2_types(X). + + +implied(suite) -> []; +implied(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line load_master("Test1"), + try_test(implied_test,[MA]), + ?line unload_master("Test1"). + +implied_3(X) -> implied(X). + + +sparse_table(suite) -> []; +sparse_table(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test1"), + try_test(sparse_table_test), + ?line unload_master("Test1"). + +sparse_table_2(X) -> sparse_table(X). + +sparse_table_3(X) -> sparse_table(X). + +cnt_64(suite) -> []; +cnt_64(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line load_master("Test1"), + try_test(cnt_64_test, [MA]), + ?line unload_master("Test1"). + +cnt_64_2(X) -> cnt_64(X). + +cnt_64_3(X) -> cnt_64(X). + +opaque(suite) -> []; +opaque(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test1"), + try_test(opaque_test), + ?line unload_master("Test1"). + +opaque_2(X) -> opaque(X). + +opaque_3(X) -> opaque(X). + + +change_target_addr_config(suite) -> []; +change_target_addr_config(Config) when list(Config) -> + p("Testing changing target address config..."), + ?LOG("change_target_addr_config -> entry",[]), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + put(sname,snmp_suite), + put(verbosity,trace), + + MA = whereis(snmp_master_agent), + + ?LOG("change_target_addr_config -> load TestTrap",[]), + ?line load_master("TestTrap"), + + ?LOG("change_target_addr_config -> set trace verbosity for local_db",[]), + ?line snmpa:verbosity(local_db,trace), + + %% First send some traps that will arive att the original manager + ?LOG("change_target_addr_config -> send trap",[]), + try_test(ma_trap1, [MA]), + + ?LOG("change_target_addr_config -> set silence verbosity for local_db",[]), + ?line snmpa:verbosity(local_db,silence), + + %% Start new dummy listener + ?LOG("change_target_addr_config -> start dummy manager",[]), + ?line {ok,Pid,NewPort} = dummy_manager_start(MA), + + %% Reconfigure + ?LOG("change_target_addr_config -> reconfigure",[]), + AgentDir = ?config(agent_dir, Config), + ?line rewrite_target_addr_conf(AgentDir, NewPort), + ?line snmp_target_mib:reconfigure(AgentDir), + + %% Send the trap again + ?LOG("change_target_addr_config -> send trap again",[]), + catch dummy_manager_send_trap2(Pid), + + ?LOG("change_target_addr_config -> await trap ack",[]), + catch dummy_manager_await_trap2_ack(), + + ?LOG("change_target_addr_config -> stop dummy manager",[]), + ?line ok = dummy_manager_stop(Pid), + + ?LOG("change_target_addr_config -> reset target address config",[]), + ?line reset_target_addr_conf(AgentDir), + + ?LOG("change_target_addr_config -> unload TestTrap",[]), + ?line unload_master("TestTrap"). + + +dummy_manager_start(MA) -> + ?DBG("dummy_manager_start -> entry",[]), + Pid = spawn(get(mgr_node), ?MODULE,dummy_manager_init,[self(),MA]), + ?DBG("dummy_manager_start -> Pid: ~p",[Pid]), + await_dummy_manager_started(Pid). + +await_dummy_manager_started(Pid) -> + receive + {dummy_manager_started,Pid,Port} -> + ?DBG("dummy_manager_start -> acknowledge received with" + "~n Port: ~p",[Port]), + {ok,Pid,Port}; + {'EXIT', Pid, Reason} -> + {error, Pid, Reason}; + O -> + ?LOG("dummy_manager_start -> received unknown message:" + "~n ~p",[O]), + await_dummy_manager_started(Pid) + end. + +dummy_manager_stop(Pid) -> + ?DBG("dummy_manager_stop -> entry with Pid: ~p",[Pid]), + Pid ! stop, + receive + {dummy_manager_stopping, Pid} -> + ?DBG("dummy_manager_stop -> acknowledge received",[]), + ok + after 10000 -> + ?ERR("dummy_manager_stop -> timeout",[]), + timeout + end. + +dummy_manager_send_trap2(Pid) -> + ?DBG("dummy_manager_send_trap2 -> entry",[]), + Pid ! {send_trap,testTrap2}. + +dummy_manager_await_trap2_ack() -> + ?DBG("dummy_manager_await_trap2 -> entry",[]), + receive + {received_trap,Trap} -> + ?LOG("dummy_manager_await_trap2 -> received trap: ~p",[Trap]), + %% Note: + %% Without this sleep the v2_inform_i testcase failes! There + %% is no relation between these two test cases as far as I + %% able to figure out... + sleep(60000), + ok; + O -> + ?ERR("dummy_manager_await_trap2 -> unexpected message: ~p",[O]), + ok + after 10000 -> + ?ERR("dummy_manager_await_trap2 -> timeout",[]), + timeout + end. + +dummy_manager_init(Parent,MA) -> + ?DBG("dummy_manager_init -> entry with" + "~n Parent: ~p" + "~n MA: ~p",[Parent,MA]), + {ok,S} = gen_udp:open(0,[{recbuf,65535}]), + ?DBG("dummy_manager_init -> S: ~p",[S]), + {ok,Port} = inet:port(S), + ?DBG("dummy_manager_init -> Port: ~p",[Port]), + Parent ! {dummy_manager_started,self(),Port}, + dummy_manager_loop(Parent,S,MA). + +dummy_manager_loop(P,S,MA) -> + ?LOG("dummy_manager_loop -> ready for receive",[]), + receive + {send_trap,Trap} -> + ?LOG("dummy_manager_loop -> received trap send request" + "~n Trap: ~p",[Trap]), + snmpa:send_trap(MA, Trap, "standard trap"), + dummy_manager_loop(P,S,MA); + {udp, _UdpId, Ip, UdpPort, Bytes} -> + ?LOG("dummy_manager_loop -> received upd message" + "~n from: ~p:~p" + "~n size: ~p", + [Ip, UdpPort, dummy_manager_message_sz(Bytes)]), + R = dummy_manager_handle_message(Bytes), + ?DBG("dummy_manager_loop -> R: ~p",[R]), + P ! R, + dummy_manager_loop(P,S,MA); + stop -> + ?DBG("dummy_manager_loop -> received stop request",[]), + P ! {dummy_manager_stopping, self()}, + gen_udp:close(S), + exit(normal); + O -> + ?LOG("dummy_manager_loop -> received unknown message:" + "~n ~p",[O]), + dummy_manager_loop(P,S,MA) + end. + +dummy_manager_message_sz(B) when binary(B) -> + size(B); +dummy_manager_message_sz(L) when list(L) -> + length(L); +dummy_manager_message_sz(_) -> + undefined. + +dummy_manager_handle_message(Bytes) -> + case (catch snmp_pdus:dec_message(Bytes)) of + {'EXIT',Reason} -> + ?ERR("dummy_manager_handle_message -> " + "failed decoding message only:~n ~p",[Reason]), + {error,Reason}; + M -> + ?DBG("dummy_manager_handle_message -> decoded message:" + "~n ~p",[M]), + {received_trap,M} + end. + + +api(suite) -> []; +api(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(api_test, [node()]), + ?line unload_master("OLD-SNMPEA-MIB"). + +api_2(X) -> api(X). + +api_3(X) -> api(X). + + +subagent(suite) -> []; +subagent(Config) when list(Config) -> + {SaNode, _MgrNode, MibDir} = init_case(Config), + + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), + try_test(load_test_sa), + + p("Testing unregister subagent..."), + MA = whereis(snmp_master_agent), + rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), + try_test(unreg_test), + + p("Loading previous subagent mib in master and testing..."), + ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas1"]), + try_test(load_test), + + p("Unloading previous subagent mib in master and testing..."), + ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas1"]), + try_test(unreg_test), + p("Testing register subagent..."), + rpc:call(SaNode, snmp, register_subagent, + [MA, ?klas1, SA]), + try_test(load_test_sa), + + ?line stop_subagent(SA), + try_test(unreg_test). + +subagent_2(X) -> subagent(X). + +subagent_3(X) -> subagent(X). + + +mnesia(suite) -> []; +mnesia(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Starting subagent with mnesia impl..."), + {ok, SA} = start_subagent(SaNode, ?klas2, "Klas2"), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + + try_test(big_test_2), + + p("Testing unregister subagent..."), + MA = whereis(snmp_master_agent), + rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), + try_test(unreg_test), + ?line unload_master("OLD-SNMPEA-MIB"), + ?line stop_subagent(SA). + +mnesia_2(X) -> mnesia(X). + +mnesia_3(X) -> mnesia(X). + + + +mul_cases() -> +[mul_get, mul_get_err, mul_next, mul_next_err, + mul_set_err]. + + +multiple_reqs_3(_X) -> + {req, [], {conf, init_mul, mul_cases_3(), finish_mul}}. + + +mul_cases_2() -> +[mul_get_2, mul_get_err_2, mul_next_2, mul_next_err_2, + mul_set_err_2]. + + +mul_cases_3() -> + [mul_get_3, mul_get_err_3, mul_next_3, mul_next_err_3, mul_set_err_3]. + + +init_mul(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + [{mul_sub, SA} | Config]. + +finish_mul(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + SA = ?config(mul_sub, Config), + + ?line unload_master("OLD-SNMPEA-MIB"), + ?line stop_subagent(SA), + lists:keydelete(mul_sub, 1, Config). + +mul_get(suite) -> []; +mul_get(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple get..."), + try_test(do_mul_get). + +mul_get_2(X) -> mul_get(X). + +mul_get_3(X) -> mul_get(X). + + +mul_get_err(suite) -> []; +mul_get_err(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple get with error..."), + try_test(do_mul_get_err). + +mul_get_err_2(X) -> mul_get_err(X). + +mul_get_err_3(X) -> mul_get_err(X). + + +mul_next(suite) -> []; +mul_next(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple next..."), + try_test(do_mul_next). + +mul_next_2(X) -> mul_next(X). + +mul_next_3(X) -> mul_next(X). + + +mul_next_err(suite) -> []; +mul_next_err(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple next..."), + try_test(do_mul_next_err). + +mul_next_err_2(X) -> mul_next_err(X). + +mul_next_err_3(X) -> mul_next_err(X). + + +mul_set(suite) -> []; +mul_set(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple set..."), + try_test(do_mul_set). + +mul_set_2(X) -> mul_set(X). + +mul_set_3(X) -> mul_set(X). + + +mul_set_err(suite) -> []; +mul_set_err(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple set with error..."), + try_test(do_mul_set_err). + +mul_set_err_2(X) -> mul_set_err(X). + +mul_set_err_3(X) -> mul_set_err(X). + + +sa_register(suite) -> []; +sa_register(Config) when list(Config) -> + ?DBG("sa_register -> entry", []), + {SaNode, _MgrNode, MibDir} = init_case(Config), + + ?DBG("sa_register -> start subagent", []), + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), + + ?DBG("sa_register -> unregister subagent", []), + p("Testing unregister subagent (2)..."), + MA = whereis(snmp_master_agent), + rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), + try_test(unreg_test), + + p("Loading SA-MIB..."), + ?DBG("sa_register -> unload mibs", []), + snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), + ?DBG("sa_register -> unload mibs", []), + snmpa:load_mibs(SA, [MibDir ++ "SA-MIB"]), + ?DBG("sa_register -> register subagent", []), + rpc:call(SaNode, snmp, register_subagent, [MA,?sa,SA]), + try_test(sa_mib), + + ?DBG("sa_register -> stop subagent", []), + ?line stop_subagent(SA). + +sa_register_2(X) -> sa_register(X). + +sa_register_3(X) -> sa_register(X). + + +v1_trap(suite) -> []; +v1_trap(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Testing trap sending from master agent..."), + MA = whereis(snmp_master_agent), + + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(ma_trap1, [MA]), + try_test(ma_trap2, [MA]), + try_test(ma_v2_2_v1_trap, [MA]), + try_test(ma_v2_2_v1_trap2, [MA]), + + p("Testing trap sending from subagent..."), + try_test(sa_trap1, [SA]), + try_test(sa_trap2, [SA]), + try_test(sa_trap3, [SA]), + + ?line unload_master("TestTrap"), + ?line unload_master("TestTrapv2"), + + ?line stop_subagent(SA). + +v2_trap(suite) -> []; +v2_trap(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Testing trap sending from master agent..."), + MA = whereis(snmp_master_agent), + + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + + try_test(ma_v2_trap1, [MA]), + try_test(ma_v2_trap2, [MA]), + try_test(ma_v1_2_v2_trap, [MA]), + try_test(ma_v1_2_v2_trap2, [MA]), + + try_test(sa_mib), + p("Testing trap sending from subagent..."), + try_test(sa_v1_2_v2_trap1, [SA]), + try_test(sa_v1_2_v2_trap2, [SA]), + try_test(sa_v1_2_v2_trap3, [SA]), + + ?line unload_master("TestTrap"), + ?line unload_master("TestTrapv2"), + + ?line stop_subagent(SA). + +v3_trap(X) -> + v2_trap(X). + + +v3_inform(_X) -> + %% v2_inform(X). + {req, [], {conf, init_v3_inform, [v3_inform_i], finish_v3_inform}}. + +init_v2_inform(Config) when list(Config) -> + _Dir = ?config(agent_dir, Config), +% snmp_internal_mib:configure(Dir), + Config. + +init_v3_inform(X) -> + init_v2_inform(X). + +finish_v2_inform(Config) when list(Config) -> + _Dir = ?config(agent_dir, Config), +% snmp_internal_mib:configure(Dir), + Config. + +finish_v3_inform(X) -> + finish_v2_inform(X). + + + +v2_inform_i(suite) -> []; +v2_inform_i(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing inform sending from master agent... NOTE! This test\ntakes a " + "few minutes (5) to complete."), + MA = whereis(snmp_master_agent), + + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(ma_v2_inform1, [MA]), + + ?line unload_master("TestTrap"), + ?line unload_master("TestTrapv2"). + +v3_inform_i(X) -> v2_inform_i(X). + + +sa_error(suite) -> []; +sa_error(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Testing sa bad value (is_set_ok)..."), + try_test(sa_errs_bad_value), + + p("Testing sa gen err (set)..."), + try_test(sa_errs_gen_err), + + p("Testing too big..."), + try_test(sa_too_big), + + ?line unload_master("OLD-SNMPEA-MIB"), + stop_subagent(SA). + +sa_error_2(X) -> sa_error(X). + +sa_error_3(X) -> sa_error(X). + + +next_across_sa(suite) -> []; +next_across_sa(Config) when list(Config) -> + {SaNode, _MgrNode, MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Loading another subagent mib..."), + ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas1"]), + + rpc:call(SaNode, snmp, register_subagent, [MA, ?klas1, SA]), + try_test(load_test_sa), + + p("Testing next across subagent (endOfMibView from SA)..."), + try_test(next_across_sa), + + p("Unloading mib"), + snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), + rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), + try_test(unreg_test), + + p("Starting another subagent"), + ?line {ok, SA2} = start_subagent(SaNode, ?klas1, "Klas1"), + p("Testing next across subagent (wrong prefix from SA)..."), + try_test(next_across_sa), + + stop_subagent(SA), + stop_subagent(SA2). + +next_across_sa_2(X) -> next_across_sa(X). + +next_across_sa_3(X) -> next_across_sa(X). + + +undo(suite) -> []; +undo(Config) when list(Config) -> + {SaNode, _MgrNode, MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Testing undo phase at master agent..."), + ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas3"]), + ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas4"]), + try_test(undo_test), + try_test(api_test2), + ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas3"]), + + p("Testing bad return values from instrum. funcs..."), + try_test(bad_return), + + ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas4"]), + + p("Testing undo phase at subagent..."), + ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas3"]), + ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas4"]), + ?line ok = snmpa:register_subagent(MA, ?klas3, SA), + ?line ok = snmpa:register_subagent(MA, ?klas4, SA), + try_test(undo_test), + try_test(api_test3), + + p("Testing undo phase across master/subagents..."), + try_test(undo_test), + try_test(api_test3), + stop_subagent(SA). + +undo_2(X) -> undo(X). + +undo_3(X) -> undo(X). + +%% Req. Test2 +v1_processing(suite) -> []; +v1_processing(Config) when list(Config) -> + ?DBG("v1_processing -> entry", []), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + try_test(v1_proc), + ?line unload_master("Test2"). + +%% Req. Test2 +v2_processing(suite) -> []; +v2_processing(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + try_test(v2_proc), + ?line unload_master("Test2"). + +%% Req. Test2 +v3_processing(suite) -> []; +v3_processing(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + try_test(v2_proc), % same as v2! + ?line unload_master("Test2"). + + +%% We'll try get/set/trap and inform for all the auth & priv protocols. +%% For informs, the mgr is auth-engine. The agent has to sync. This is +%% accomplished by the first inform sent. That one will generate a +%% report, which makes it in sync. The notification-generating +%% application times out, and send again. This time it'll work. + +v3_crypto_basic(suite) -> []; +v3_crypto_basic(_Config) -> + EID = [0,0,0,0,0,0,0,0,0,0,0,2], + %% From rfc2274 appendix A.3.1 + ?line KMd5_1 = snmp:passwd2localized_key(md5, "maplesyrup", EID), + ?line [16#52,16#6f,16#5e,16#ed,16#9f,16#cc,16#e2,16#6f, + 16#89,16#64,16#c2,16#93,16#07,16#87,16#d8,16#2b] = + KMd5_1, + %% From rfc2274 appendix A.3.2 + ?line KSHA_1 = snmp:passwd2localized_key(sha, "maplesyrup", EID), + ?line [16#66,16#95,16#fe,16#bc,16#92,16#88,16#e3,16#62,16#82,16#23, + 16#5f,16#c7,16#15,16#1f,16#12,16#84,16#97,16#b3,16#8f,16#3f] = + KSHA_1, + %% From rfc2274, appendix A.5.1 + ?line KMd5_2 = snmp:passwd2localized_key(md5, "newsyrup", EID), + ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#88,16#05,16#61,16#51,16#41,16#67,16#6c,16#c9, + 16#19,16#61,16#74,16#e7,16#42,16#a3,16#25,16#51] = + snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2, 16, + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), + %% From rfc2274, appendix A.5.2 + ?line KSHA_2 = snmp:passwd2localized_key(sha, "newsyrup", EID), + ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#00,16#00,16#00,16#00,16#9c,16#10,16#17,16#f4, + 16#fd,16#48,16#3d,16#2d,16#e8,16#d5,16#fa,16#db, + 16#f8,16#43,16#92,16#cb,16#06,16#45,16#70,16#51] = + snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2, 20, + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), + KSHA_1t = lists:sublist(KSHA_1, 16), + KSHA_2t = lists:sublist(KSHA_2, 16), + ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#7e,16#f8,16#d8,16#a4,16#c9,16#cd,16#b2,16#6b, + 16#47,16#59,16#1c,16#d8,16#52,16#ff,16#88,16#b5] = + snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1t, KSHA_2t, 16, + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), + + %% Try with correct random + ?line Kc1 = snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2), + ?line KMd5_2 = snmp_user_based_sm_mib:extract_new_key(md5, KMd5_1, Kc1), + ?line Kc2 = snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2), + ?line KSHA_2 = snmp_user_based_sm_mib:extract_new_key(sha, KSHA_1, Kc2), + ok. + + + +v3_md5_auth(suite) -> []; +v3_md5_auth(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + p("Testing MD5 authentication...takes a few seconds..."), + + AgentDir = ?config(agent_dir, Config), + ?line rewrite_target_params_conf(AgentDir, "authMD5", authNoPriv), + ?line snmp_target_mib:reconfigure(AgentDir), + + MA = whereis(snmp_master_agent), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(v3_sync, [[{v2_proc, []}, + {ma_v2_trap1, [MA]}, + {v3_inform_sync, [MA]}]], + [{sec_level, authNoPriv}, {user, "authMD5"}]), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + ?line reset_target_params_conf(AgentDir). + +v3_sha_auth(suite) -> []; +v3_sha_auth(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + p("Testing SHA authentication...takes a few seconds..."), + + AgentDir = ?config(agent_dir, Config), + ?line rewrite_target_params_conf(AgentDir, "authSHA", authNoPriv), + ?line snmp_target_mib:reconfigure(AgentDir), + + MA = whereis(snmp_master_agent), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(v3_sync, [[{v2_proc, []}, + {ma_v2_trap1, [MA]}, + {v3_inform_sync, [MA]}]], + [{sec_level, authNoPriv}, {user, "authSHA"}]), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + ?line reset_target_params_conf(AgentDir). + +v3_des_priv(suite) -> []; +v3_des_priv(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + p("Testing DES encryption...takes a few seconds..."), + + AgentDir = ?config(agent_dir, Config), + ?line rewrite_target_params_conf(AgentDir, "privDES", authPriv), + ?line snmp_target_mib:reconfigure(AgentDir), + + MA = whereis(snmp_master_agent), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(v3_sync, [[{v2_proc, []}, + {ma_v2_trap1, [MA]}, + {v3_inform_sync, [MA]}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + ?line reset_target_params_conf(AgentDir). + +%% -define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). + +%% Make sure mgr is in sync with agent +v3_sync(Funcs) -> + ?DBG("v3_sync -> entry with Funcs: ~p",[Funcs]), + g([[sysDescr, 0]]), + expect(432, report, [{?usmStatsNotInTimeWindows_instance, any}]), + g([[sysDescr, 0]]), + expect(433, [{[sysDescr,0], any}]), + lists:foreach(fun({Func, Args}) -> apply(?MODULE, Func, Args) end, Funcs). + +v3_inform_sync(MA) -> + ?DBG("v3_sync -> entry with MA: ~p => Send notification",[MA]), + ?line snmpa:send_notification(MA, testTrapv22, no_receiver, + "standard inform", []), + %% Make sure agent is in sync with mgr... + ?DBG("v3_sync -> wait some time: ",[]), + sleep(20000), % more than 1500*10 in target_addr.conf + ?DBG("v3_sync -> await response",[]), + ?line expect(1, {inform, true}, + [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]). + + +v2_caps(suite) -> []; +v2_caps(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + try_test(v2_caps_i, [node()]). + +v2_caps_3(X) -> v2_caps(X). + + +v2_caps_i(Node) -> + ?line Idx = rpc:call(Node, snmp, add_agent_caps, [[1,2,3,4,5], "test cap"]), + g([[sysORID, Idx], [sysORDescr, Idx]]), + ?line expect(1, [{[sysORID, Idx], [1,2,3,4,5]}, + {[sysORDescr, Idx], "test cap"}]), + ?line rpc:call(Node, snmp, del_agent_caps, [Idx]), + g([[sysORID, Idx]]), + ?line expect(2, [{[sysORID, Idx], noSuchInstance}]). + + +%% Req. Test2 +v1_proc() -> + ?DBG("v1_proc -> entry", []), + %% According to RFC1157. + %% Template:
: + v1_get_p(), + v1_get_next_p(), + v1_set_p(). + + +v1_get_p() -> + %% 4.1.2:1 + g([[test2]]), + ?line expect(10, noSuchName, 1, [{[test2], 'NULL'}]), + g([[tDescr]]), + ?line expect(11, noSuchName, 1, [{[tDescr], 'NULL'}]), + g([[tDescr2,0]]), + ?line expect(12, noSuchName, 1, [{[tDescr2,0], 'NULL'}]), + g([[tDescr3,0]]), + ?line expect(131, noSuchName, 1, [{[tDescr3,0], 'NULL'}]), + g([[tDescr4,0]]), + ?line expect(132, noSuchName, 1, [{[tDescr4,0], 'NULL'}]), + g([[sysDescr, 0], [tDescr,0]]), % Outside mibview + ?line expect(14, noSuchName, 2, [{[sysDescr, 0], 'NULL'}, + {[tDescr,0], 'NULL'}]), + g([[sysDescr,3]]), + ?line expect(15, noSuchName, 1, [{[sysDescr, 3], 'NULL'}]), + + %% 4.1.2:2 + g([[tTable]]), + ?line expect(20, noSuchName, 1, [{[tTable], 'NULL'}]), + g([[tEntry]]), + ?line expect(21, noSuchName, 1, [{[tEntry], 'NULL'}]), + + %% 4.1.2:3 + g([[tTooBig, 0]]), + ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), + + %% 4.1.2:4 + g([[tGenErr1, 0]]), + ?line expect(40, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), + g([[tGenErr2, 0]]), + ?line expect(41, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), + g([[sysDescr, 0], [tGenErr3, 0]]), + ?line expect(42, genErr, 2, [{[sysDescr, 0], 'NULL'}, + {[tGenErr3, 0], 'NULL'}]). + + +v1_get_next_p() -> + %% 4.1.3:1 + gn([[1,3,7,1]]), + ?line expect(10, noSuchName, 1, [{[1,3,7,1], 'NULL'}]), + gn([[tDescr2]]), + ?line expect(11, tooBig, 0, any), + + %% 4.1.3:2 + gn([[tTooBig]]), + io:format("We currently don't handle tooBig correct!!!\n"), +% ?line expect(20, tooBig, 0, [{[tTooBig], 'NULL'}]), + ?line expect(20, tooBig, 0, any), + + %% 4.1.3:3 + gn([[tGenErr1]]), +% ?line expect(40, genErr, 1, [{[tGenErr1], 'NULL'}]), + ?line expect(40, genErr, 1, any), + gn([[tGenErr2]]), +% ?line expect(41, genErr, 1, [{[tGenErr2], 'NULL'}]), + ?line expect(41, genErr, 1, any), + gn([[sysDescr], [tGenErr3]]), +% ?line expect(42, genErr, 2, [{[sysDescr], 'NULL'}, +% {[tGenErr3], 'NULL'}]). + ?line expect(42, genErr, 2, any). + +v1_set_p() -> + %% 4.1.5:1 + s([{[1,3,7,0], i, 4}]), + ?line expect(10, noSuchName, 1, [{[1,3,7,0], 4}]), + s([{[tDescr,0], s, "outside mibview"}]), + ?line expect(11, noSuchName, 1, [{[tDescr,0], "outside mibview"}]), + s([{[tDescr3,0], s, "read-only"}]), + ?line expect(12, noSuchName, 1, [{[tDescr3,0], "read-only"}]), + s([{[tDescr3], s, "noSuchObject"}]), + ?line expect(13, noSuchName, 1, [{[tDescr3], "noSuchObject"}]), + s([{[tDescr3,1], s, "noSuchInstance"}]), + ?line expect(14, noSuchName, 1, [{[tDescr3,1], "noSuchInstance"}]), + s([{[tDescr2,0], s, "inconsistentName"}]), + ?line expect(15, noSuchName, 1, [{[tDescr2,0], "inconsistentName"}]), + + %% 4.1.5:2 + s([{[tDescr2, 0], i, 4}]), + ?line expect(20, badValue, 1, [{[tDescr2, 0], 4}]), + s([{[tDescr2, 0], s, "badValue"}]), + ?line expect(21, badValue, 1, [{[tDescr2, 0], "badValue"}]), + + %% 4.1.5:3 + %% The standard is quite incorrect here. The resp pdu was too big. In + %% the resp pdu, we have the original vbs. In the tooBig pdu we still + %% have to original vbs => the tooBig pdu is too big as well!!! It + %% may not get it to the manager, unless the agent uses 'NULL' instead + %% of the std-like original value. + s([{[tTooBig, 0], s, ?tooBigStr}]), + %% according to std: +% ?line expect(30, tooBig, 0, [{[tTooBig, 0], ?tooBigStr}]), + ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), + + %% 4.1.5:4 + s([{[tDescr2, 0], s, "is_set_ok_fail"}]), + ?line expect(40, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]), + s([{[tDescr2, 0], s, "commit_fail"}]), + ?line expect(41, genErr, 1, [{[tDescr2, 0], "commit_fail"}]). + +%% Req. Test2 +v2_proc() -> + %% According to RFC1905. + %% Template:
: + ?DBG("v2_proc -> entry",[]), + v2_get_p(), + v2_get_next_p(), + v2_get_bulk_p(), + v2_set_p(). + +v2_get_p() -> + %% 4.2.1:2 + ?DBG("v2_get_p -> entry",[]), + g([[test2]]), + ?line expect(10, [{[test2], noSuchObject}]), + g([[tDescr]]), + ?line expect(11, [{[tDescr], noSuchObject}]), + g([[tDescr4,0]]), + ?line expect(12, [{[tDescr4,0], noSuchObject}]), + g([[sysDescr, 0], [tDescr,0]]), % Outside mibview + ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}, + {[tDescr,0], noSuchObject}]), + g([[tTable]]), + ?line expect(14, [{[tTable], noSuchObject}]), + g([[tEntry]]), + ?line expect(15, [{[tEntry], noSuchObject}]), + + %% 4.2.1:3 + g([[tDescr2,0]]), %% instrum ret noSuchName!!! + ?line expect(20, [{[tDescr2,0], noSuchInstance}]), + g([[tDescr3,0]]), + ?line expect(21, [{[tDescr3,0], noSuchInstance}]), + g([[sysDescr,3]]), + ?line expect(22, [{[sysDescr, 3], noSuchInstance}]), + g([[tIndex,1]]), + ?line expect(23, [{[tIndex, 1], noSuchInstance}]), + + %% 4.2.1 - any other error: genErr + g([[tGenErr1, 0]]), + ?line expect(30, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), + g([[tGenErr2, 0]]), + ?line expect(31, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), + g([[sysDescr, 0], [tGenErr3, 0]]), + ?line expect(32, genErr, 2, [{[sysDescr, 0], 'NULL'}, + {[tGenErr3, 0], 'NULL'}]), + + %% 4.2.1 - tooBig + g([[tTooBig, 0]]), + ?line expect(40, tooBig, 0, []). + + +v2_get_next_p() -> + %% 4.2.2:2 + ?DBG("v2_get_next_p -> entry",[]), + gn([[1,3,7,1]]), + ?line expect(10, [{[1,3,7,1], endOfMibView}]), + gn([[sysDescr], [1,3,7,1]]), + ?line expect(11, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}]), + gn([[tCnt2, 1]]), + ?line expect(12, [{[tCnt2,2], 100}]), + gn([[tCnt2, 2]]), + ?line expect(12, [{[tCnt2,2], endOfMibView}]), + + %% 4.2.2 - any other error: genErr + gn([[tGenErr1]]), + ?line expect(20, genErr, 1, [{[tGenErr1], 'NULL'}]), + gn([[tGenErr2]]), + ?line expect(21, genErr, 1, [{[tGenErr2], 'NULL'}]), + gn([[sysDescr], [tGenErr3]]), + ?line expect(22, genErr, 2, [{[sysDescr], 'NULL'}, + {[tGenErr3], 'NULL'}]), + + %% 4.2.2 - tooBig + gn([[tTooBig]]), + ?line expect(20, tooBig, 0, []). + +v2_get_bulk_p() -> + %% 4.2.3 + ?DBG("v2_get_bulk_p -> entry",[]), + gb(1, 1, []), + ?line expect(10, []), + gb(-1, 1, []), + ?line expect(11, []), + gb(-1, -1, []), + ?line expect(12, []), + gb(-1, -1, []), + ?line expect(13, []), + gb(2, 0, [[sysDescr], [1,3,7,1]]), + ?line expect(14, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}]), + gb(1, 2, [[sysDescr], [1,3,7,1]]), + ?line expect(15, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}]), + gb(0, 2, [[sysDescr], [1,3,7,1]]), + ?line expect(16, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}, + {[sysObjectID, 0], [1,2,3]}, + {[1,3,7,1], endOfMibView}]), + + gb(2, 2, [[sysDescr], [1,3,7,1], [sysDescr], [1,3,7,1]]), + ?line expect(17, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}, + {[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}, + {[sysObjectID, 0], [1,2,3]}, + {[1,3,7,1], endOfMibView}]), + + gb(1, 2, [[sysDescr], [sysDescr], [tTooBig]]), + ?line expect(18, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[sysDescr, 0], "Erlang SNMP agent"}]), + + gb(1,12, [[tDescr2], [sysDescr]]), % next one after tDescr2 is tTooBig. + ?line expect(19, []), + + gb(2,2, [[sysDescr], [sysObjectID], [tGenErr1], [sysDescr]]), + ?line expect(20, genErr, 3, [{[sysDescr], 'NULL'}, + {[sysObjectID], 'NULL'}, + {[tGenErr1], 'NULL'}, + {[sysDescr], 'NULL'}]), + gb(0, 2, [[tCnt2, 1]]), + ?line expect(21, [{[tCnt2,2], 100}, + {[tCnt2,2], endOfMibView}]). + + +v2_set_p() -> + %% 4.2.5:1 + ?DBG("v2_set_p -> entry",[]), + s([{[1,3,7,0], i, 4}]), + ?line expect(10, noAccess, 1, [{[1,3,7,0], 4}]), + s([{[tDescr,0], s, "outside mibview"}]), + ?line expect(11, noAccess, 1, [{[tDescr,0], "outside mibview"}]), + + %% 4.2.5:2 + s([{[1,3,6,1,0], s, "noSuchObject"}]), + ?line expect(20, notWritable, 1, [{[1,3,6,1,0], "noSuchObject"}]), + + %% 4.2.5:3 + s([{[tDescr2, 0], i, 4}]), + ?line expect(30, wrongType, 1, [{[tDescr2, 0], 4}]), + s([{[tDescr2, 0], s, "badValue"}]), + ?line expect(31, badValue, 1, [{[tDescr2, 0], "badValue"}]), + + %% 4.2.5:4 + s([{[tStr, 0], s, ""}]), + ?line expect(40, wrongLength, 1, [{[tStr, 0], ""}]), + s([{[tStr, 0], s, "12345"}]), + ?line expect(40, wrongLength, 1, [{[tStr, 0], "12345"}]), + + %% 4.2.5:5 - N/A + + %% 4.2.5:6 + s([{[tInt1, 0], i, 0}]), + ?line expect(60, wrongValue, 1, [{[tInt1, 0], 0}]), + s([{[tInt1, 0], i, 5}]), + ?line expect(61, wrongValue, 1, [{[tInt1, 0], 5}]), + s([{[tInt2, 0], i, 0}]), + ?line expect(62, wrongValue, 1, [{[tInt2, 0], 0}]), + s([{[tInt2, 0], i, 5}]), + ?line expect(63, wrongValue, 1, [{[tInt2, 0], 5}]), + s([{[tInt3, 0], i, 5}]), + ?line expect(64, wrongValue, 1, [{[tInt3, 0], 5}]), + + %% 4.2.5:7 + s([{[tDescrX, 1, 1], s, "noCreation"}]), + ?line expect(70, noCreation, 1, [{[tDescrX, 1, 1], "noCreation"}]), + + %% 4.2.5:8 + s([{[tDescrX, 1, 2], s, "inconsistentName"}]), + ?line expect(80, inconsistentName, 1, + [{[tDescrX, 1, 2], "inconsistentName"}]), + + %% 4.2.5:9 + s([{[tCnt, 1, 2], i, 5}]), + ?line expect(90, notWritable, 1, [{[tCnt, 1, 2], 5}]), + s([{[tDescr3,0], s, "read-only"}]), + ?line expect(90, notWritable, 1, [{[tDescr3,0], "read-only"}]), + + %% 4.2.5:10 + s([{[tDescr2,0], s, "inconsistentValue"}]), + ?line expect(100, inconsistentValue, 1, + [{[tDescr2,0], "inconsistentValue"}]), + + %% 4.2.5:11 + s([{[tDescr2,0], s, "resourceUnavailable"}]), + ?line expect(110, resourceUnavailable, 1, + [{[tDescr2,0],"resourceUnavailable"}]), + + %% 4.2.5:12 + s([{[tDescr2, 0], s, "is_set_ok_fail"}]), + ?line expect(120, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]). + + %% commitFailed and undoFailed is tested by the 'undo' case. + + +%% Req. OLD-SNMPEA-MIB +table_test() -> + io:format("Testing simple get, next and set on communityTable...~n"), +%% {[147,214,36,45], "public", 2, readWrite}. +%% {[147,214,36,45], "standard trap", 2, read}. + Key1c3 = [intCommunityViewIndex,get(mip),is("public")], + Key2c3 = [intCommunityViewIndex,get(mip),is("standard trap")], + Key1c4 = [intCommunityAccess,get(mip),is("public")], + EndKey = [intCommunityEntry,[9],get(mip),is("public")], + gn([[intCommunityEntry]]), + ?line expect(7, [{Key1c3, 2}]), + gn([[intCommunityTable]]), + ?line expect(71, [{Key1c3, 2}]), + gn([[community]]), + ?line expect(72, [{Key1c3, 2}]), + gn([[otpSnmpeaMIB]]), + ?line expect(73, [{Key1c3, 2}]), + gn([[ericsson]]), + ?line expect(74, [{Key1c3, 2}]), + gn([Key1c3]), + ?line expect(8, [{Key2c3, 2}]), + gn([Key2c3]), + ?line expect(9, [{Key1c4, 2}]), + gn([EndKey]), + AgentIp = [intAgentIpAddress,0], + ?line expect(10, [{AgentIp, any}]), + g([Key1c3]), + ?line expect(11, [{Key1c3, 2}]), + g([EndKey]), + ?line ?v1_2(expect(12, noSuchName, 1, any), + expect(12, [{EndKey, noSuchObject}])), + + io:format("Testing row creation/deletion on communityTable...~n"), + NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], + NewKeyc4 = [intCommunityAccess,get(mip),is("test")], + NewKeyc5 = [intCommunityStatus,get(mip),is("test")], + s([{NewKeyc5, ?createAndGo}]), + ?line expect(14, ?v1_2(badValue, inconsistentValue), 1,any), + s([{NewKeyc5, ?createAndGo}, {NewKeyc3, 2}, {NewKeyc4, 2}]), + ?line expect(15, [{NewKeyc5, ?createAndGo},{NewKeyc3, 2}, {NewKeyc4, 2}]), + g([NewKeyc4]), + ?line expect(16, [{NewKeyc4, 2}]), + s([{NewKeyc5, ?destroy}]), + ?line expect(17, [{NewKeyc5, ?destroy}]), + s([{NewKeyc4, 2}]), + ?line expect(18, ?v1_2(noSuchName, inconsistentName), 1,[{NewKeyc4, 2}]), + s([{NewKeyc5, ?createAndWait}]), + ?line expect(19, [{NewKeyc5, ?createAndWait}]), + g([NewKeyc5]), + ?line expect(20, [{NewKeyc5, ?notReady}]), + s([{NewKeyc4, 2}]), + ?line expect(21, [{NewKeyc4, 2}]), + g([NewKeyc5]), + ?line expect(22, [{NewKeyc5, ?notReady}]), + s([{NewKeyc3, 2}]), + ?line expect(23, [{NewKeyc3, 2}]), + g([NewKeyc5]), + ?line expect(24, [{NewKeyc5, ?notInService}]), + s([{NewKeyc5, ?active}]), + ?line expect(25, [{NewKeyc5, ?active}]), + s([{NewKeyc5, ?destroy}]), + ?line expect(26, [{NewKeyc5, ?destroy}]), + s([{NewKeyc3, 3}]), + ?line expect(27, ?v1_2(noSuchName, inconsistentName), 1,[{NewKeyc3, 3}]), + otp_1128(). + +%% Req. system group +simple_standard_test() -> + ?DBG("simple_standard_test -> entry",[]), + gn([[1,1]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3]]), + ?line expect(11, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6]]), + ?line expect(12, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6,1]]), + ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6,1,2]]), + ?line expect(14, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6,1,2,1]]), + ?line expect(15, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6,1,2,1,1]]), + ?line expect(16, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[sysDescr]]), + ?line expect(17, [{[sysDescr,0], "Erlang SNMP agent"}]), + g([[sysDescr,0]]), + ?line expect(2, [{[sysDescr,0], "Erlang SNMP agent"}]), + g([[sysDescr]]), + ?line ?v1_2(expect(3, noSuchName, 1, any), + expect(3, [{[sysDescr], noSuchObject}])), + g([[1,6,7,0]]), + ?line ?v1_2(expect(41, noSuchName, 1, any), + expect(3, [{[1,6,7,0], noSuchObject}])), + gn([[1,13]]), + ?line ?v1_2(expect(4, noSuchName,1, any), + expect(4, [{[1,13], endOfMibView}])), + s([{[sysLocation, 0], "new_value"}]), + ?line expect(5, [{[sysLocation, 0], "new_value"}]), + g([[sysLocation, 0]]), + ?line expect(6, [{[sysLocation, 0], "new_value"}]), + io:format("Testing noSuchName and badValue...~n"), + s([{[sysServices,0], 3}]), + ?line expect(61, ?v1_2(noSuchName, notWritable), 1, any), + s([{[sysLocation, 0], i, 3}]), + ?line expect(62, ?v1_2(badValue, wrongType), 1, any), + ?DBG("simple_standard_test -> done",[]), + ok. + +%% This is run in the agent node +db_notify_client(suite) -> []; +db_notify_client(Config) when list(Config) -> + {SaNode, MgrNode, MibDir} = init_case(Config), + ?DBG("~n\tSaNode: ~p~n\tMgrNode: ~p~n\tMibDir: ~p", + [SaNode,MgrNode,MibDir]), + snmpa_local_db:register_notify_client(self(),?MODULE), + + %% This call (the manager) will issue to set operations, so + %% we expect to receive to notify(insert) calls. + try_test(db_notify_client_test), + + ?DBG("await first notify",[]), + receive + {db_notify_test_reply,insert} -> ?DBG("first notify received",[]),ok + end, + + ?DBG("await second notify",[]), + receive + {db_notify_test_reply,insert} -> ?DBG("second notify received",[]),ok + end, + + snmpa_local_db:unregister_notify_client(self()). + + +%% This is run in the manager node +db_notify_client_test() -> + ?DBG("set first new sysLocation",[]), + s([{[sysLocation, 0], "new_value"}]), + ?line expect(5, [{[sysLocation, 0], "new_value"}]), + + ?DBG("set second new sysLocation",[]), + s([{[sysLocation, 0], "new_value"}]), + ?line expect(5, [{[sysLocation, 0], "new_value"}]). + +notify(Pid,What) -> + ?DBG("notify(~p,~p) -> called",[Pid,What]), + Pid ! {db_notify_test_reply,What}. + + +%% Req: system group, OLD-SNMPEA-MIB, Klas1 +big_test() -> + ?DBG("big_test -> testing simple next/get/set @ master agent...",[]), + simple_standard_test(), + + ?DBG("big_test -> testing simple next/get/set @ subagent...",[]), + gn([[klas1]]), + ?line expect(1, [{[fname,0], ""}]), + g([[fname,0]]), + ?line expect(2, [{[fname,0], ""}]), + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + g([[fname,0]]), + ?line expect(4, [{[fname,0], "test set"}]), + + ?DBG("big_test -> " + "testing next from last instance in master to subagent...",[]), + gn([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(5, [{[fname,0], "test set"}]), + gn([[1,1], + [?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, + {[fname,0], "test set"}]), + s([{[fname,0], s, ""}]), + ?line expect(52, [{[fname,0], ""}]), + + table_test(), + + ?DBG("big_test -> adding one row in subagent table",[]), + _FTab = [friendsEntry], + s([{[friendsEntry, [2, 3]], s, "kompis3"}, + {[friendsEntry, [3, 3]], i, ?createAndGo}]), + ?line expect(6, [{[friendsEntry, [2, 3]], "kompis3"}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + g([[friendsEntry, [2, 3]], + [friendsEntry, [3, 3]]]), + ?line expect(7, [{[friendsEntry, [2, 3]], "kompis3"}, + {[friendsEntry, [3, 3]], ?active}]), + s([{[friendsEntry, [3, 3]], i, ?destroy}]), + ?line expect(8, [{[friendsEntry, [3, 3]], ?destroy}]), + + otp_1131(), + + ?DBG("big_test -> adding two rows in subagent table with special INDEX", + []), + s([{[kompissEntry, [1, 3]], s, "kompis3"}, + {[kompissEntry, [2, 3]], i, ?createAndGo}]), + ?line expect(9, [{[kompissEntry, [1, 3]], "kompis3"}, + {[kompissEntry, [2, 3]], ?createAndGo}]), + g([[kompissEntry, [1, 3]], + [kompissEntry, [2, 3]]]), + ?line expect(10, [{[kompissEntry, [1, 3]], "kompis3"}, + {[kompissEntry, [2, 3]], ?active}]), + gn([[kompissEntry, [1]], + [kompissEntry, [2]]]), + ?line expect(11, [{[kompissEntry, [1, 3]], "kompis3"}, + {[kompissEntry, [2, 3]], ?active}]), + s([{[kompissEntry, [1, 2]], s, "kompis3"}, + {[kompissEntry, [2, 2]], i, ?createAndGo}]), + ?line expect(12, [{[kompissEntry, [1, 2]], "kompis3"}, + {[kompissEntry, [2, 2]], ?createAndGo}]), + gn([[kompissEntry, [1, 1]], + [kompissEntry, [2, 1]]]), + ?line expect(13, [{[kompissEntry, [1, 2]], "kompis3"}, + {[kompissEntry, [2, 2]], ?active}]), + s([{[kompissEntry, [2, 3]], i, ?destroy}]), + ?line expect(14, [{[kompissEntry, [2, 3]], ?destroy}]), + s([{[kompissEntry, [2, 2]], i, ?destroy}]), + ?line expect(15, [{[kompissEntry, [2, 2]], ?destroy}]), + ?DBG("big_test -> done",[]), + ok. + +%% Req. system group, Klas2, OLD-SNMPEA-MIB +big_test_2() -> + p("Testing simple next/get/set @ master agent (2)..."), + simple_standard_test(), + + p("Testing simple next/get/set @ subagent (2)..."), + gn([[klas2]]), + ?line expect(1, [{[fname2,0], ""}]), + g([[fname2,0]]), + ?line expect(2, [{[fname2,0], ""}]), + s([{[fname2,0], s, "test set"}]), + ?line expect(3, [{[fname2,0], "test set"}]), + g([[fname2,0]]), + ?line expect(4, [{[fname2,0], "test set"}]), + + otp_1298(), + + p("Testing next from last object in master to subagent (2)..."), + gn([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(5, [{[fname2,0], "test set"}]), + gn([[1,1], + [?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, + {[fname2,0], "test set"}]), + + table_test(), + + p("Adding one row in subagent table (2)"), + _FTab = [friendsEntry2], + s([{[friendsEntry2, [2, 3]], s, "kompis3"}, + {[friendsEntry2, [3, 3]], i, ?createAndGo}]), + ?line expect(6, [{[friendsEntry2, [2, 3]], "kompis3"}, + {[friendsEntry2, [3, 3]], ?createAndGo}]), + g([[friendsEntry2, [2, 3]], + [friendsEntry2, [3, 3]]]), + ?line expect(7, [{[friendsEntry2, [2, 3]], "kompis3"}, + {[friendsEntry2, [3, 3]], ?active}]), + s([{[friendsEntry2, [3, 3]], i, ?destroy}]), + ?line expect(8, [{[friendsEntry2, [3, 3]], ?destroy}]), + + p("Adding two rows in subagent table with special INDEX (2)"), + s([{[kompissEntry2, [1, 3]], s, "kompis3"}, + {[kompissEntry2, [2, 3]], i, ?createAndGo}]), + ?line expect(9, [{[kompissEntry2, [1, 3]], "kompis3"}, + {[kompissEntry2, [2, 3]], ?createAndGo}]), + g([[kompissEntry2, [1, 3]], + [kompissEntry2, [2, 3]]]), + ?line expect(10, [{[kompissEntry2, [1, 3]], "kompis3"}, + {[kompissEntry2, [2, 3]], ?active}]), + gn([[kompissEntry2, [1]], + [kompissEntry2, [2]]]), + ?line expect(11, [{[kompissEntry2, [1, 3]], "kompis3"}, + {[kompissEntry2, [2, 3]], ?active}]), + s([{[kompissEntry2, [1, 2]], s, "kompis3"}, + {[kompissEntry2, [2, 2]], i, ?createAndGo}]), + ?line expect(12, [{[kompissEntry2, [1, 2]], "kompis3"}, + {[kompissEntry2, [2, 2]], ?createAndGo}]), + gn([[kompissEntry2, [1, 1]], + [kompissEntry2, [2, 1]]]), + ?line expect(13, [{[kompissEntry2, [1, 2]], "kompis3"}, + {[kompissEntry2, [2, 2]], ?active}]), + s([{[kompissEntry2, [2, 3]], i, ?destroy}]), + ?line expect(14, [{[kompissEntry2, [2, 3]], ?destroy}]), + s([{[kompissEntry2, [2, 2]], i, ?destroy}]), + ?line expect(15, [{[kompissEntry2, [2, 2]], ?destroy}]), + ok. + +%% Req. Test1 +multi_threaded_test() -> + p("Testing multi threaded agent..."), + g([[multiStr,0]]), + Pid = get_multi_pid(), + g([[sysUpTime,0]]), + ?line expect(1, [{[sysUpTime,0], any}]), + s([{[sysLocation, 0], s, "pelle"}]), + ?line expect(2, [{[sysLocation, 0], "pelle"}]), + Pid ! continue, + ?line expect(3, [{[multiStr,0], "ok"}]), + + s([{[multiStr, 0], s, "block"}]), + Pid2 = get_multi_pid(), + g([[sysUpTime,0]]), + ?line expect(4, [{[sysUpTime,0], any}]), + g([[multiStr,0]]), + Pid3 = get_multi_pid(), + g([[sysUpTime,0]]), + ?line expect(5, [{[sysUpTime,0], any}]), + s([{[sysLocation, 0], s, "kalle"}]), + Pid3 ! continue, + ?line expect(6, [{[multiStr,0], "ok"}]), + Pid2 ! continue, + ?line expect(7, [{[multiStr,0], "block"}]), + ?line expect(8, [{[sysLocation,0], "kalle"}]). + +%% Req. Test1, TestTrapv2 +mt_trap_test(MA) -> + snmpa:send_trap(MA, testTrapv22, "standard trap"), + ?line expect(1, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + + snmpa:send_trap(MA, mtTrap, "standard trap"), + Pid = get_multi_pid(), + g([[sysUpTime,0]]), + ?line expect(2, [{[sysUpTime,0], any}]), + snmpa:send_trap(MA, testTrapv22, "standard trap"), + ?line expect(3, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + Pid ! continue, + ?line expect(4, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?testTrap ++ [2]}, + {[multiStr,0], "ok"}]). + + +get_multi_pid() -> + get_multi_pid(10). +get_multi_pid(0) -> + ?line ?FAIL(no_global_name); +get_multi_pid(N) -> + sleep(1000), + case global:whereis_name(snmp_multi_tester) of + Pid when pid(Pid) -> Pid; + _ -> get_multi_pid(N-1) + end. + +%% Req. Test1 +types_v2_test() -> + p("Testing v2 types..."), + + s([{[bits1,0], 2#10}]), + ?line expect(1, [{[bits1,0], ?str(2#10)}]), + g([[bits1,0]]), + ?line expect(2, [{[bits1,0], ?str(2#101)}]), + + s([{[bits2,0], 2#11000000110}]), + ?line expect(3, [{[bits2,0], ?str(2#11000000110)}]), + g([[bits2,0]]), + ?line expect(4, [{[bits2,0], ?str(2#11000000110)}]), + + g([[bits3,0]]), + ?line expect(50, genErr, 1, any), + + g([[bits4,0]]), + ?line expect(51, genErr, 1, any), + + s([{[bits1,0], s, [2#10]}]), + ?line expect(6, ?v1_2(badValue, wrongValue), 1, any), + + s([{[bits2,0], 2#11001001101010011}]), + ?line expect(7, ?v1_2(badValue, wrongValue), 1, any). + + +%% Req. Test1 +implied_test(MA) -> + ?LOG("implied_test -> start",[]), + p("Testing IMPLIED..."), + + snmpa:verbosity(MA,trace), + snmpa:verbosity(MA,trace), + + %% Create two rows, check that they are get-nexted in correct order. + Idx1 = "apa", + Idx2 = "qq", + ?DBG("implied_test -> (send) create row 1 '~s' in table 1",[Idx1]), + s([{[testStatus, Idx1], i, ?createAndGo}, {[testDescr, Idx1],s,"row 1"}]), + ?line expect(1, [{[testStatus, Idx1], ?createAndGo}, + {[testDescr, Idx1], "row 1"}]), + ?DBG("implied_test -> (send) create row 2 '~s' in table 1",[Idx2]), + s([{[testStatus, Idx2], i, ?createAndGo}, {[testDescr, Idx2],s,"row 2"}]), + ?line expect(2, [{[testStatus, Idx2], ?createAndGo}, + {[testDescr, Idx2], "row 2"}]), + ?DBG("implied_test -> get-next(testDescr)",[]), + gn([[testDescr]]), + ?line expect(3, [{[testDescr,Idx1], "row 1"}]), + ?DBG("implied_test -> get-next(testDescr) of row 1",[]), + gn([[testDescr,Idx1]]), + ?line expect(4, [{[testDescr,Idx2], "row 2"}]), + + % Delete the rows + ?DBG("implied_test -> (send) delete row 1 '~s' from table 1",[Idx1]), + s([{[testStatus, Idx1], i, ?destroy}]), + ?line expect(5, [{[testStatus, Idx1], ?destroy}]), + ?DBG("implied_test -> (send) delete row 2 '~s' from table 1",[Idx2]), + s([{[testStatus, Idx2], i, ?destroy}]), + ?line expect(6, [{[testStatus, Idx2], ?destroy}]), + + %% Try the same in other table + Idx3 = [1, "apa"], + Idx4 = [1, "qq"], + ?DBG("implied_test -> (send) create row 1 '~s' in table 2",[Idx3]), + s([{[testStatus2, Idx3], i, ?createAndGo}, {[testDescr2,Idx3],s,"row 1"}]), + ?line expect(1, [{[testStatus2, Idx3], ?createAndGo}, + {[testDescr2, Idx3], "row 1"}]), + ?DBG("implied_test -> (send) create row 2 '~s' in table 2",[Idx4]), + s([{[testStatus2, Idx4], i, ?createAndGo}, {[testDescr2,Idx4],s,"row 2"}]), + ?line expect(2, [{[testStatus2, Idx4], ?createAndGo}, + {[testDescr2, Idx4], "row 2"}]), + ?DBG("implied_test -> get-next(testDescr2)",[]), + gn([[testDescr2]]), + ?line expect(3, [{[testDescr2,Idx3], "row 1"}]), + ?DBG("implied_test -> get-next(testDescr2) of row 1",[]), + gn([[testDescr2,Idx3]]), + ?line expect(4, [{[testDescr2,Idx4], "row 2"}]), + + % Delete the rows + ?DBG("implied_test -> (send) delete row 1 '~s' from table 2",[Idx3]), + s([{[testStatus2, Idx3], i, ?destroy}]), + ?line expect(5, [{[testStatus2, Idx3], ?destroy}]), + ?DBG("implied_test -> (send) delete row 2 '~s' from table 2",[Idx4]), + s([{[testStatus2, Idx4], i, ?destroy}]), + ?line expect(6, [{[testStatus2, Idx4], ?destroy}]), + + snmpa:verbosity(MA,log), + + ?LOG("implied_test -> done",[]). + + + +%% Req. Test1 +sparse_table_test() -> + p("Testing sparse table..."), + + %% Create two rows, check that they are get-nexted in correct order. + Idx1 = 1, + Idx2 = 2, + s([{[sparseStatus, Idx1], i, ?createAndGo}, + {[sparseDescr, Idx1], s, "row 1"}]), + ?line expect(1, [{[sparseStatus, Idx1], ?createAndGo}, + {[sparseDescr, Idx1], "row 1"}]), + s([{[sparseStatus, Idx2], i, ?createAndGo}, + {[sparseDescr, Idx2], s, "row 2"}]), + ?line expect(2, [{[sparseStatus, Idx2], ?createAndGo}, + {[sparseDescr, Idx2], "row 2"}]), + ?v1_2(gn([[sparseIndex], [sparseDescr,Idx1], [sparseDescr,Idx2], + [sparseStatus,Idx1], [sparseStatus,Idx2]]), + gb(0,5,[[sparseIndex]])), + ?line expect(3, [{[sparseDescr,Idx1], "row 1"}, + {[sparseDescr,Idx2], "row 2"}, + {[sparseStatus,Idx1], ?active}, + {[sparseStatus,Idx2], ?active}, + {[sparseStr,0], "slut"}]), + % Delete the rows + s([{[sparseStatus, Idx1], i, ?destroy}]), + ?line expect(4, [{[sparseStatus, Idx1], ?destroy}]), + s([{[sparseStatus, Idx2], i, ?destroy}]), + ?line expect(5, [{[sparseStatus, Idx2], ?destroy}]). + + +%% Req. Test1 +cnt_64_test(MA) -> + ?LOG("start cnt64 test (~p)",[MA]), + snmpa:verbosity(MA,trace), + ?LOG("start cnt64 test",[]), + p("Testing Counter64, and at the same time, RowStatus is not last column"), + + ?DBG("get cnt64",[]), + g([[cnt64,0]]), + ?DBG("await response",[]), + ?line ?v1_2(expect(1, noSuchName, 1, any), + expect(1, [{[cnt64,0],18446744073709551615}])), + ?DBG("get-next cnt64",[]), + gn([[cnt64]]), + ?DBG("await response",[]), + ?line ?v1_2(expect(2, [{[cnt64Str,0], "after cnt64"}]), + expect(2, [{[cnt64,0],18446744073709551615}])), + ?DBG("send cntTrap",[]), + snmpa:send_trap(MA,cntTrap,"standard trap",[{sysContact,"pelle"}, + {cnt64, 10}, + {sysLocation, "here"}]), + ?DBG("await response",[]), + ?line ?v1_2(expect(3, trap, [test], 6, 1, [{[sysContact,0], "pelle"}, + {[sysLocation,0], "here"}]), + expect(3, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?testTrap ++ [1]}, + {[sysContact,0], "pelle"}, + {[cnt64,0], 10}, + {[sysLocation,0], "here"}])), + + %% Create two rows, check that they are get-nexted in correct order. + Idx1 = 1, + Idx2 = 2, + ?DBG("create row (cntStatus): ~p",[Idx1]), + s([{[cntStatus, Idx1], i, ?createAndGo}]), + ?DBG("await response",[]), + ?line expect(1, [{[cntStatus, Idx1], ?createAndGo}]), + ?DBG("create row (cntStatus): ~p",[Idx2]), + s([{[cntStatus, Idx2], i, ?createAndGo}]), + ?DBG("await response",[]), + ?line expect(2, [{[cntStatus, Idx2], ?createAndGo}]), + + ?DBG("get-next (cntIndex)",[]), + gn([[cntIndex]]), + ?DBG("await response",[]), + ?line ?v1_2(expect(3, [{[cntStatus,Idx1], ?active}]), + expect(3, [{[cntCnt,Idx1], 0}])), + % Delete the rows + ?DBG("delete row (cntStatus): ~p",[Idx1]), + s([{[cntStatus, Idx1], i, ?destroy}]), + ?DBG("await response",[]), + ?line expect(4, [{[cntStatus, Idx1], ?destroy}]), + ?DBG("delete row (cntStatus): ~p",[Idx2]), + s([{[cntStatus, Idx2], i, ?destroy}]), + ?DBG("await response",[]), + ?line expect(5, [{[cntStatus, Idx2], ?destroy}]), + catch snmpa:verbosity(MA,log), + ?DBG("done",[]), + ok. + +%% Req. Test1 +opaque_test() -> + p("Testing Opaque datatype..."), + g([[opaqueObj,0]]), + ?line expect(1, [{[opaqueObj,0], "opaque-data"}]). + +%% Req. OLD-SNMPEA-MIB +api_test(MaNode) -> + ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, + [intAgentIpAddress]), + ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, + oid_to_name, [OID]), + ?line false = rpc:call(MaNode, snmp, name_to_oid, [intAgentIpAddres]), + ?line false = rpc:call(MaNode, snmp, oid_to_name, + [[1,5,32,3,54,3,3,34,4]]), + ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, + [intViewType, excluded]), + ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, + [intViewType, 2]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, [intViewType, exclude]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [intAgentIpAddress, exclude]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [intAgentIpAddre, exclude]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [intViewType, 3]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddress, 2]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddre, 2]), + ?line {value, active} = rpc:call(MaNode, snmp, + int_to_enum, ['RowStatus', ?active]), + ?line {value, ?destroy} = rpc:call(MaNode, snmp, + enum_to_int, ['RowStatus', destroy]), + ?line false = rpc:call(MaNode, snmp, + enum_to_int, ['RowStatus', xxxdestroy]), + ?line false = rpc:call(MaNode, snmp, + enum_to_int, ['xxRowStatus', destroy]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, ['RowStatus', 25]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, ['xxRowStatus', 1]), + ?line case snmp:date_and_time() of + List when list(List), length(List) == 8 -> ok; + List when list(List), length(List) == 11 -> ok + end. + +%% Req. Klas3 +api_test2() -> + g([[fname3,0]]), + ?line expect(1, [{[fname3,0], "ok"}]), + g([[fname4,0]]), + ?line expect(2, [{[fname4,0], 1}]). + +api_test3() -> + g([[fname3,0]]), + ?line expect(1, [{[fname3,0], "ok"}]). + + +unreg_test() -> + gn([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(1, [{[snmpInPkts, 0], any}]). + +load_test() -> + gn([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(1, [{[fname,0], ""}]). + +%% Req. Klas1 +load_test_sa() -> + gn([[?v1_2(sysServices,sysORLastChange), 0]]), + ?line expect(1, [{[fname,0], any}]). + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_get() -> + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + g([[sysDescr,0], Key1c4, [fname,0],Key1c3, + [sysName,0]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[fname,0], "test set"}, + {Key1c3, 2}, + {[sysName,0], "test"}]), + g([[1,3,7,1], Key1c4, [sysDescr,0], [1,3,7,2], Key1c3, [sysDescr,0]]), + ?line ?v1_2(expect(2, noSuchName, [1,4], any), + expect(2, [{[1,3,7,1], noSuchObject}, + {Key1c4, 2}, + {[sysDescr,0], "Erlang SNMP agent"}, + {[1,3,7,2], noSuchObject}, + {Key1c3, 2}, + {[sysDescr,0], "Erlang SNMP agent"}])). + +%% Req. v1, system group, Klas1, OLD-SNMPEA-MIB, *ej* Klas3. +do_mul_get_err() -> + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + g([[sysDescr,0],Key1c4,[fname,0], Key1c3, [sysName,2]]), + ?line ?v1_2(expect(1, noSuchName, 5, any), + expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[fname,0], "test set"}, + {Key1c3, 2}, + {[sysName,2], noSuchInstance}])), + g([[sysDescr,0],Key1c4,[fname3,0], Key1c3, [sysName,1]]), + ?line ?v1_2(expect(1, noSuchName, [3,5], any), + expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[fname3,0], noSuchObject}, + {Key1c3, 2}, + {[sysName,1], noSuchInstance}])). + + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_next() -> + Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], + Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + gn([[sysDescr], Key1c4s, [fname],Key1c3s,[sysName]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, {[fname,0], "test set"}, + {Key1c3, 2}, {[sysName,0], "test"}]). + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_next_err() -> + Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], + Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + gn([[sysDescr], Key1c4s, [1,3,6,999], [fname],[1,3,90], Key1c3s,[sysName]]), + ?line ?v1_2(expect(1, noSuchName, [3,5], any), + expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[1,3,6,999], endOfMibView}, + {[fname,0], "test set"}, + {[1,3,90], endOfMibView}, + {Key1c3, 2}, + {[sysName,0], "test"}])). + + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_set() -> + p("Adding one row in subagent table, and one in master table"), + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + s([{[friendsEntry, [2, 3]], "kompis3"}, + {NewKeyc3, 2}, + {[sysLocation,0], "new_value"}, + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + ?line expect(1, [{[friendsEntry, [2, 3]], "kompis3"}, + {NewKeyc3, 2}, + {[sysLocation,0], "new_value"}, + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + g([[friendsEntry, [2, 3]], + [sysLocation,0], + [friendsEntry, [3, 3]]]), + ?line expect(2, [{[friendsEntry, [2, 3]], "kompis3"}, + {[sysLocation,0], "new_value"}, + {[friendsEntry, [3, 3]], ?active}]), + g([NewKeyc4]), + ?line expect(3, [{NewKeyc4, 2}]), + s([{[friendsEntry, [3, 3]], ?destroy}, + {NewKeyc5, ?destroy}]), + ?line expect(4, [{[friendsEntry, [3, 3]], ?destroy}, + {NewKeyc5, ?destroy}]). + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_set_err() -> + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + p("Adding one row in subagent table, and one in master table"), + s([{[friendsEntry, [2, 3]], s, "kompis3"}, + {NewKeyc3, 2}, + {[sysUpTime,0], 45}, % sysUpTime (readOnly) + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + ?line expect(1, ?v1_2(noSuchName, notWritable), 3, any), + g([[friendsEntry, [2, 3]]]), + ?line ?v1_2(expect(2, noSuchName, 1, any), + expect(2, [{[friendsEntry, [2,3]], noSuchInstance}])), + g([NewKeyc4]), + ?line ?v1_2(expect(3, noSuchName, 1, any), + expect(3, [{NewKeyc4, noSuchInstance}])). + +%% Req. SA-MIB +sa_mib() -> + g([[sa, [2,0]]]), + ?line expect(1, [{[sa, [2,0]], 3}]), + s([{[sa, [1,0]], s, "sa_test"}]), + ?line expect(2, [{[sa, [1,0]], "sa_test"}]). + +ma_trap1(MA) -> + snmpa:send_trap(MA, testTrap2, "standard trap"), + ?line expect(1, trap, [system], 6, 1, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}]), + snmpa:send_trap(MA, testTrap1, "standard trap"), + ?line expect(2, trap, [1,2,3] , 1, 0, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}]). + +ma_trap2(MA) -> + snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). + +ma_v2_2_v1_trap(MA) -> + snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). + +ma_v2_2_v1_trap2(MA) -> + snmpa:send_trap(MA,linkUp,"standard trap",[{ifIndex, [1], 1}, + {ifAdminStatus, [1], 1}, + {ifOperStatus, [1], 2}]), + ?line expect(3, trap, [1,2,3], 3, 0, [{[ifIndex, 1], 1}, + {[ifAdminStatus, 1], 1}, + {[ifOperStatus, 1], 2}]). + +sa_trap1(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap"), + ?line expect(4, trap, [ericsson], 6, 1, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}]). + +sa_trap2(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), + ?line expect(5, trap, [ericsson], 6, 1, [{[system, [4,0]], + "pelle"}, + {[sa, [1,0]], "sa_test"}]). + +sa_trap3(SA) -> + snmpa:send_trap(SA, saTrap2, "standard trap", + [{intViewSubtree, [4], [1,2,3,4]}]), + ?line expect(6, trap, [ericsson], 6, 2, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}, + {[intViewSubtree,4],[1,2,3,4]}]). + +ma_v2_trap1(MA) -> + ?DBG("ma_v2_traps -> entry with MA = ~p => " + "send standard trap: testTrapv22",[MA]), + snmpa:send_trap(MA, testTrapv22, "standard trap"), + ?line expect(1, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + ?DBG("ma_v2_traps -> send standard trap: testTrapv21",[]), + snmpa:send_trap(MA, testTrapv21, "standard trap"), + ?line expect(2, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?snmp ++ [1]}]). + +ma_v2_trap2(MA) -> + snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}, + {[system, [4,0]], "pelle"}]). + +%% Note: This test case takes a while... actually a couple of minutes. +ma_v2_inform1(MA) -> + ?DBG("ma_v2_inform -> entry with MA = ~p => " + "send notification: testTrapv22",[MA]), + ?line snmpa:send_notification(MA, testTrapv22, no_receiver, "standard inform", []), + ?line expect(1, {inform, true}, + [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + + ?DBG("ma_v2_inform -> send notification: testTrapv22",[]), + snmpa:send_notification(MA, testTrapv22, {tag1, self()}, + "standard inform", []), + ?line expect(1, {inform, true}, + [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + ?DBG("ma_v2_inform -> await targets",[]), + receive + {snmp_targets, tag1, [_]} -> + ok; + {snmp_targets, tag1, Addrs1} -> + ?line ?FAIL({bad_addrs, Addrs1}) + after + 5000 -> + ?ERR("ma_v2_inform1 -> awaiting snmp_targets(tag1) timeout",[]), + ?line ?FAIL(nothing_at_all) + end, + ?DBG("ma_v2_inform -> await notification",[]), + receive + {snmp_notification, tag1, {got_response, _}} -> + ok; + {snmp_notification, tag1, {no_response, _}} -> + ?line ?FAIL(no_response) + after + 20000 -> + ?ERR("ma_v2_inform1 -> " + "awaiting snmp_notification(tag1) timeout",[]), + ?line ?FAIL(nothing_at_all) + end, + + %% + %% -- The rest is possibly erroneous... + %% + + ?DBG("ma_v2_inform -> send notification: testTrapv22",[]), + snmpa:send_notification(MA, testTrapv22, {tag2, self()}, + "standard inform", []), + ?line expect(2, {inform, false}, + [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + ?DBG("ma_v2_inform -> await targets",[]), + receive + {snmp_targets, tag2, [_]} -> + ok; + {snmp_targets, tag2, Addrs2} -> + ?ERR("ma_v2_inform1 -> awaiting snmp_targets(tag2) timeout",[]), + ?line ?FAIL({bad_addrs, Addrs2}) + after + 5000 -> + ?line ?FAIL(nothing_at_all) + end, + ?DBG("ma_v2_inform -> await notification",[]), + receive + {snmp_notification, tag2, {got_response, _}} -> + ?line ?FAIL(got_response); + {snmp_notification, tag2, {no_response, _}} -> + ok + after + 240000 -> + ?ERR("ma_v2_inform1 -> " + "awaiting snmp_notification(tag2) timeout",[]), + ?line ?FAIL(nothing_at_all) + end. + + +ma_v1_2_v2_trap(MA) -> + snmpa:send_trap(MA,linkDown,"standard trap",[{ifIndex, [1], 1}]), + ?line expect(2, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?snmpTraps ++ [3]}, + {[ifIndex, 1], 1}, + {[snmpTrapEnterprise, 0], [1,2,3]}]). + + +ma_v1_2_v2_trap2(MA) -> + snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}, + {[system, [4,0]], "pelle"}, + {[snmpTrapEnterprise, 0], ?system}]). + + +sa_v1_2_v2_trap1(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap"), + ?line expect(4, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, + {[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}, + {[snmpTrapEnterprise, 0], ?ericsson}]). + +sa_v1_2_v2_trap2(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), + ?line expect(4, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, + {[system, [4,0]], "pelle"}, + {[sa, [1,0]], "sa_test"}, + {[snmpTrapEnterprise, 0], ?ericsson}]). + + +sa_v1_2_v2_trap3(SA) -> + snmpa:send_trap(SA, saTrap2, "standard trap", + [{intViewSubtree, [4], [1,2,3,4]}]), + ?line expect(4, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?ericsson ++ [0, 2]}, + {[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}, + {[intViewSubtree,4],[1,2,3,4]}, + {[snmpTrapEnterprise, 0], ?ericsson}]). + + +%% Req. SA-MIB, OLD-SNMPEA-MIB +sa_errs_bad_value() -> + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + s([{NewKeyc3, 2}, + {[sa, [2,0]], 5}, % badValue (i is_set_ok) + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}]), + ?line expect(1, badValue, 2, any), + s([{NewKeyc3, 2}, + {[sa, [2,0]], 6}, % wrongValue (i is_set_ok) + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}]), + ?line expect(1, ?v1_2(badValue, wrongValue), 2, any), + g([NewKeyc4]), + ?line ?v1_2(expect(2, noSuchName, 1, any), + expect(2, [{NewKeyc4, noSuchInstance}])). + +%% Req. SA-MIB, OLD-SNMPEA-MIB +sa_errs_gen_err() -> + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + s([{NewKeyc3, 2},{NewKeyc4, 2}, + {NewKeyc5, ?createAndGo}, {[sa, [3,0]], 5}]), + ?line expect(1, genErr, 4, any), +% The row might have been added; we don't know. +% (as a matter of fact we do - it is added, because the agent +% first sets its own vars, and then th SAs. Lets destroy it. + s([{NewKeyc5, ?destroy}]), + ?line expect(2, [{NewKeyc5, ?destroy}]). + +%% Req. SA-MIB, OLD-SNMPEA-MIB +sa_too_big() -> + g([[sa, [4,0]]]), + ?line expect(1, tooBig). + +%% Req. Klas1, system group, snmp group (v1/v2) +next_across_sa() -> + gn([[sysDescr],[klas1,5]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {[snmpInPkts, 0], any}]). + +%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]). -> noError +%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]). -> {badValue, 2} +%% snmp_test_mgr:s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]). -> {genErr, 1} +%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]). -> {genErr, 1} +%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]). -> {genErr, 1} +%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]). -> {genErr, 2} +%% Req. Klas3, Klas4 +undo_test() -> + s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), + ?line expect(1, [{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), + s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]), + ?line expect(2, ?v1_2(badValue, inconsistentValue), 2, any), + s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]), + ?line expect(3, ?v1_2(genErr, undoFailed), 1, any), + s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]), + ?line expect(4, ?v1_2(genErr, commitFailed), 1, any), +% unfortunatly we don't know if we'll get undoFailed or commitFailed. +% it depends on which order the agent traverses the varbind list. +% s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]), +% ?line expect(5, ?v1_2(genErr, undoFailed), 1, any), + s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]), + ?line expect(6, genErr, 2, any). + +%% Req. Klas3, Klas4 +bad_return() -> + g([[fStatus4,4], + [fName4,4]]), + ?line expect(4, genErr, 2, any), + g([[fStatus4,5], + [fName4,5]]), + ?line expect(5, genErr, 1, any), + g([[fStatus4,6], + [fName4,6]]), + ?line expect(6, genErr, 2, any), + gn([[fStatus4,7], + [fName4,7]]), + ?line expect(7, genErr, 2, any), + gn([[fStatus4,8], + [fName4,8]]), + ?line expect(8, genErr, 1, any), + gn([[fStatus4,9], + [fName4,9]]), + ?line expect(9, genErr, 2, any). + + +%%%----------------------------------------------------------------- +%%% Test the implementation of standard mibs. +%%% We should *at least* try to GET all variables, just to make +%%% sure the instrumentation functions work. +%%% Note that many of the functions in the standard mib is +%%% already tested by the normal tests. +%%%----------------------------------------------------------------- + + + +%%----------------------------------------------------------------- +%% For this test, the agent is configured for v1. +%% o Test the counters and control objects in SNMP-STANDARD-MIB +%%----------------------------------------------------------------- +snmp_standard_mib(suite) -> []; +snmp_standard_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?DBG("snmp_standard_mib -> std_mib_init", []), + try_test(std_mib_init), + + ?DBG("snmp_standard_mib -> std_mib_a", []), + InBadVsns = try_test(std_mib_a), + put(vsn, v2), + ?DBG("snmp_standard_mib -> std_mib_read", []), + try_test(std_mib_read), + put(vsn, v1), + + ?DBG("snmp_standard_mib -> std_mib_b (~w)", [InBadVsns]), + Bad = try_test(std_mib_b, [InBadVsns]), + ?DBG("snmp_standard_mib -> std_mib_read (community: 'bad community')", []), + try_test(std_mib_read, [], [{community, "bad community"}]), + ?DBG("snmp_standard_mib -> std_mib_write (community: 'public')", []), + try_test(std_mib_write, [], [{community, "public"}]), + ?DBG("snmp_standard_mib -> std_mib_asn_err", []), + try_test(std_mib_asn_err), + ?DBG("snmp_standard_mib -> std_mib_c (~w)", [Bad]), + try_test(std_mib_c, [Bad]), + ?DBG("snmp_standard_mib -> std_mib_a", []), + try_test(standard_mib_a), + + ?DBG("snmp_standard_mib -> std_mib_finish", []), + try_test(std_mib_finish), + ?DBG("snmp_standard_mib -> std_mib_test_finish", []), + try_test(standard_mib_test_finish, [], [{community, "bad community"}]). + +%% Req. SNMP-STANDARD-MIB +standard_mib_a() -> + ?line [OutPkts] = get_req(2, [[snmpOutPkts,0]]), + ?line [OutPkts2] = get_req(3, [[snmpOutPkts,0]]), + ?line OutPkts2 = OutPkts + 1, + %% There are some more counters we could test here, but it's not that + %% important, since they are removed from SNMPv2-MIB. + ok. + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_init() -> + %% disable authentication failure traps. (otherwise w'd get many of + %% them - this is also a test to see that it works). + s([{[snmpEnableAuthenTraps,0], 2}]), + ?line expect(1, [{[snmpEnableAuthenTraps, 0], 2}]). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_finish() -> + %% enable again + s([{[snmpEnableAuthenTraps,0], 1}]), + ?line expect(1, [{[snmpEnableAuthenTraps, 0], 1}]). + +%% Req. SNMP-STANDARD-MIB +standard_mib_test_finish() -> + %% force a authenticationFailure + std_mib_write(), + %% check that we got a trap + ?line expect(2, trap, [1,2,3], 4, 0, []). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_read() -> + ?DBG("std_mib_read -> entry", []), + g([[sysUpTime,0]]), % try a bad ; msg dropped, no reply + ?DBG("std_mib_read -> await timeout (i.e. no reply)", []), + ?line expect(1, timeout). % make sure we don't get a trap! + + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_write() -> + ?DBG("std_mib_write -> entry", []), + s([{[sysLocation, 0], "new_value"}]). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_asn_err() -> + snmp_test_mgr:send_bytes([48,99,67,12,0,0,0,0,0,0,5]). + +%%----------------------------------------------------------------- +%% For this test, the agent is configured for v2 and v3. +%% o Test the counters and control objects in SNMPv2-MIB +%%----------------------------------------------------------------- +snmpv2_mib_2(suite) -> []; +snmpv2_mib_2(Config) when list(Config) -> + ?LOG("snmpv2_mib_2 -> start",[]), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?DBG("snmpv2_mib_2 -> standard mib init",[]), + try_test(std_mib_init), + + ?DBG("snmpv2_mib_2 -> get number of (so far) bad versions",[]), + InBadVsns = try_test(std_mib_a), + + ?DBG("snmpv2_mib_2 -> make a bad version read",[]), + put(vsn, v1), + try_test(std_mib_read), + + ?DBG("snmpv2_mib_2 -> bad version read",[]), + put(vsn, v2), + Bad = try_test(std_mib_b, [InBadVsns]), + + ?DBG("snmpv2_mib_2 -> read with bad community",[]), + try_test(std_mib_read, [], [{community, "bad community"}]), + + ?DBG("snmpv2_mib_2 -> write with public community",[]), + try_test(std_mib_write, [], [{community, "public"}]), + + ?DBG("snmpv2_mib_2 -> asn err",[]), + try_test(std_mib_asn_err), + + ?DBG("snmpv2_mib_2 -> check counters",[]), + try_test(std_mib_c, [Bad]), + + ?DBG("snmpv2_mib_2 -> get som counters",[]), + try_test(snmpv2_mib_a), + + ?DBG("snmpv2_mib_2 -> enable auth traps, and await some",[]), + try_test(std_mib_finish), + + ?DBG("snmpv2_mib_2 -> force auth failure, and await trap, " + "then disable auth traps",[]), + try_test(snmpv2_mib_test_finish, [], [{community, "bad community"}]), + + ?LOG("snmpv2_mib_2 -> done",[]). + +%% Req. SNMPv2-MIB +snmpv2_mib_3(suite) -> []; +snmpv2_mib_3(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + InBadVsns = try_test(std_mib_a), + put(vsn, v1), + try_test(std_mib_read), + put(vsn, v3), + _Bad = try_test(std_mib_b, [InBadVsns]), + try_test(snmpv2_mib_a), + + try_test(std_mib_finish). + +-define(authenticationFailure, [1,3,6,1,6,3,1,1,5,5]). + +%% Req. SNMPv2-MIB +snmpv2_mib_test_finish() -> + %% force a authenticationFailure + ?DBG("ma_v2_inform -> write to std mib",[]), + std_mib_write(), + + %% check that we got a trap + ?DBG("ma_v2_inform -> await trap",[]), + ?line expect(2, v2trap, [{[sysUpTime,0], any}, + {[snmpTrapOID,0], ?authenticationFailure}]), + + %% and the the inform + ?DBG("ma_v2_inform -> await inform",[]), + ?line expect(2, {inform,true}, [{[sysUpTime,0], any}, + {[snmpTrapOID,0],?authenticationFailure}]). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_a() -> + ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), + ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), + ?line InPkts2 = InPkts + 1, + + ?line [InBadVsns] = get_req(4, [[snmpInBadVersions,0]]), + InBadVsns. + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_b(InBadVsns) -> + ?line [InBadVsns2] = get_req(1, [[snmpInBadVersions,0]]), + ?line InBadVsns2 = InBadVsns + 1, + ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), + ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), + ?line InPkts2 = InPkts + 1, + ?line [InBadCommunityNames, InBadCommunityUses, InASNErrs] = + get_req(4, [[snmpInBadCommunityNames,0], + [snmpInBadCommunityUses,0], + [snmpInASNParseErrs, 0]]), + {InBadCommunityNames, InBadCommunityUses, InASNErrs}. + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_c({InBadCommunityNames, InBadCommunityUses, InASNErrs}) -> + ?line [InBadCommunityNames2, InBadCommunityUses2, InASNErrs2] = + get_req(1, [[snmpInBadCommunityNames,0], + [snmpInBadCommunityUses,0], + [snmpInASNParseErrs, 0]]), + ?line InBadCommunityNames2 = InBadCommunityNames + 1, + ?line InBadCommunityUses2 = InBadCommunityUses + 1, + ?line InASNErrs2 = InASNErrs + 1. + +%% Req. SNMPv2-MIB +snmpv2_mib_a() -> + ?line [SetSerial] = get_req(2, [[snmpSetSerialNo,0]]), + s([{[snmpSetSerialNo,0], SetSerial}, {[sysLocation, 0], "val2"}]), + ?line expect(3, [{[snmpSetSerialNo,0], SetSerial}, + {[sysLocation, 0], "val2"}]), + s([{[sysLocation, 0], "val3"}, {[snmpSetSerialNo,0], SetSerial}]), + ?line expect(4, inconsistentValue, 2, + [{[sysLocation, 0], "val3"}, + {[snmpSetSerialNo,0], SetSerial}]), + ?line ["val2"] = get_req(5, [[sysLocation,0]]). + + +%%----------------------------------------------------------------- +%% o Bad community uses/name is tested already +%% in SNMPv2-MIB and STANDARD-MIB. +%% o Test add/deletion of rows. +%%----------------------------------------------------------------- +snmp_community_mib(suite) -> []; +snmp_community_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + try_test(snmp_community_mib), + ?line unload_master("SNMP-COMMUNITY-MIB"). + +snmp_community_mib_2(X) -> snmp_community_mib(X). + +%% Req. SNMP-COMMUNITY-MIB +snmp_community_mib() -> + ?INF("NOT YET IMPLEMENTED", []), + nyi. + +%%----------------------------------------------------------------- +%% o Test engine boots / time +%%----------------------------------------------------------------- +snmp_framework_mib(suite) -> []; +snmp_framework_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + try_test(snmp_framework_mib), + ?line unload_master("SNMP-FRAMEWORK-MIB"). + +snmp_framework_mib_2(X) -> snmp_framework_mib(X). + +snmp_framework_mib_3(suite) -> []; +snmp_framework_mib_3(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + try_test(snmp_framework_mib). + + +%% Req. SNMP-FRAMEWORK-MIB +snmp_framework_mib() -> + ?line ["agentEngine"] = get_req(1, [[snmpEngineID,0]]), + ?line [EngineTime] = get_req(2, [[snmpEngineTime,0]]), + sleep(5000), + ?line [EngineTime2] = get_req(3, [[snmpEngineTime,0]]), + if + EngineTime+7 < EngineTime2 -> + ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); + EngineTime+4 > EngineTime2 -> + ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); + true -> ok + end, + ?line case get_req(4, [[snmpEngineBoots,0]]) of + [Boots] when integer(Boots) -> ok; + Else -> ?FAIL(Else) + end, + ok. + +%%----------------------------------------------------------------- +%% o Test the counters +%%----------------------------------------------------------------- +snmp_mpd_mib_3(suite) -> []; +snmp_mpd_mib_3(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + UnknownPDUHs = try_test(snmp_mpd_mib_a), + try_test(snmp_mpd_mib_b, [], [{context_engine_id, "bad engine"}]), + try_test(snmp_mpd_mib_c, [UnknownPDUHs]). + + +%% Req. SNMP-MPD-MIB +snmp_mpd_mib_a() -> + ?line [UnknownSecs, InvalidMsgs] = + get_req(1, [[snmpUnknownSecurityModels,0], + [snmpInvalidMsgs,0]]), + Pdu = #pdu{type = 'get-request', + request_id = 23, + error_status = noError, + error_index = 0, + varbinds = []}, + SPdu = #scopedPdu{contextEngineID = "agentEngine", + contextName = "", + data = Pdu}, + ?line SPDUBytes = snmp_pdus:enc_scoped_pdu(SPdu), + V3Hdr1 = #v3_hdr{msgID = 21, + msgMaxSize = 484, + msgFlags = [7], + msgSecurityModel = 23, % bad sec model + msgSecurityParameters = []}, + V3Hdr2 = #v3_hdr{msgID = 21, + msgMaxSize = 484, + msgFlags = [6], % bad flag combination + msgSecurityModel = 3, + msgSecurityParameters = []}, + Message1 = #message{version = 'version-3', vsn_hdr = V3Hdr1, + data = SPDUBytes}, + Message2 = #message{version = 'version-3', vsn_hdr = V3Hdr2, + data = SPDUBytes}, + ?line MsgBytes1 = snmp_pdus:enc_message_only(Message1), + ?line MsgBytes2 = snmp_pdus:enc_message_only(Message2), + snmp_test_mgr:send_bytes(MsgBytes1), + snmp_test_mgr:send_bytes(MsgBytes2), + + ?line [UnknownSecs2, InvalidMsgs2, UnknownPDUHs] = + get_req(1, [[snmpUnknownSecurityModels,0], + [snmpInvalidMsgs,0], + [snmpUnknownPDUHandlers, 0]]), + ?line UnknownSecs2 = UnknownSecs + 1, + ?line InvalidMsgs2 = InvalidMsgs + 1, + UnknownPDUHs. + +-define(snmpUnknownPDUHandlers_instance, [1,3,6,1,6,3,11,2,1,3,0]). +snmp_mpd_mib_b() -> + g([[sysUpTime,0]]), + ?line expect(1, report, [{?snmpUnknownPDUHandlers_instance, any}]). + + +snmp_mpd_mib_c(UnknownPDUHs) -> + ?line [UnknownPDUHs2] = get_req(1, [[snmpUnknownPDUHandlers, 0]]), + ?line UnknownPDUHs2 = UnknownPDUHs + 1. + + +snmp_target_mib(suite) -> []; +snmp_target_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-TARGET-MIB"), + try_test(snmp_target_mib), + ?line unload_master("SNMP-TARGET-MIB"). + +snmp_target_mib_2(X) -> snmp_target_mib(X). + +snmp_target_mib_3(X) -> snmp_target_mib(X). + +snmp_target_mib() -> + ?INF("NOT YET IMPLEMENTED", []), + nyi. + +snmp_notification_mib(suite) -> []; +snmp_notification_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + try_test(snmp_notification_mib), + ?line unload_master("SNMP-NOTIFICATION-MIB"). + +snmp_notification_mib_2(X) -> snmp_notification_mib(X). + +snmp_notification_mib_3(X) -> snmp_notification_mib(X). + +snmp_notification_mib() -> + ?INF("NOT YET IMPLEMENTED", []), + nyi. + +%%----------------------------------------------------------------- +%% o add/delete views and try them +%% o try boundaries +%%----------------------------------------------------------------- +snmp_view_based_acm_mib(suite) -> []; +snmp_view_based_acm_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + ?line load_master("Test2"), + snmp_view_based_acm_mib(), + ?line unload_master("Test2"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). + +snmp_view_based_acm_mib_2(X) -> snmp_view_based_acm_mib(X). + +snmp_view_based_acm_mib_3(X) -> snmp_view_based_acm_mib(X). + +snmp_view_based_acm_mib() -> + snmpa:verbosity(net_if,trace), + snmpa:verbosity(master_agent,trace), + ?LOG("start snmp_view_based_acm_mib test",[]), + %% The user "no-rights" is present in USM, and is mapped to security + %% name 'no-rights", which is not present in VACM. + %% So, we'll add rights for it, try them and delete them. + %% We'll give "no-rights" write access to tDescr.0 and read access + %% to tDescr2.0 + %% These are the options we'll use to the mgr + Opts = [{user, "no-rights"}, {community, "no-rights"}], + %% Find the valid secmodel, and one invalid secmodel. + {SecMod, InvSecMod} = + case get(vsn) of + v1 -> {?SEC_V1, ?SEC_V2C}; + v2 -> {?SEC_V2C, ?SEC_USM}; + v3 -> {?SEC_USM, ?SEC_V1} + end, + ?DBG("assign rights for 'no-rights'",[]), + ?line try_test(use_no_rights, [], Opts), + + %% Now, add a mapping from "no-rights" -> "no-rights-group" + GRow1Status = [vacmSecurityToGroupStatus,[SecMod, 9,"no-rights"]], + GRow1 = + [{[vacmGroupName, [SecMod, 9,"no-rights"]], "no-rights-group"}, + {GRow1Status, ?createAndGo}], + ?DBG("set '~p'",[GRow1]), + ?line try_test(do_set, [GRow1]), + + ?DBG("assign rights for 'no-rights'",[]), + ?line try_test(use_no_rights, [], Opts), + + %% Create a mapping for another sec model, and make sure it dosn't + %% give us access + GRow2Status = [vacmSecurityToGroupStatus,[InvSecMod, 9,"no-rights"]], + GRow2 = [{[vacmGroupName, [InvSecMod, 9, "no-rights"]], "initial"}, + {GRow2Status, ?createAndGo}], + + ?DBG("set '~p'",[GRow2]), + ?line try_test(do_set, [GRow2]), + + ?DBG("assign rights for 'no-rights'",[]), + ?line try_test(use_no_rights, [], Opts), + + %% Delete that row + ?line try_test(del_row, [GRow2Status]), + + RVName = "rv_name", + WVName = "wv_name", + + %% Access row + ARow1Idx = [15 | "no-rights-group"] ++ [0, ?SEC_ANY, 1], + ARow1Status = [vacmAccessStatus, ARow1Idx], + ARow1 = [{[vacmAccessContextMatch, ARow1Idx], 1}, + {[vacmAccessReadViewName, ARow1Idx], RVName}, + {[vacmAccessWriteViewName, ARow1Idx], WVName}, + {ARow1Status, ?createAndGo}], + + %% This access row would give acces, if InvSecMod was valid. + ARow2Idx = [15 | "no-rights-group"] ++ [0, InvSecMod, 1], + ARow2Status = [vacmAccessStatus, ARow2Idx], + ARow2 = [{[vacmAccessContextMatch, ARow2Idx], 1}, + {[vacmAccessReadViewName, ARow2Idx], "internet"}, + {[vacmAccessWriteViewName, ARow2Idx], "internet"}, + {ARow2Status, ?createAndGo}], + + ?line try_test(do_set, [ARow2]), + + ?line try_test(use_no_rights, [], Opts), + + %% Delete that row + ?line try_test(del_row, [ARow2Status]), + + + %% Add valid row + ?line try_test(do_set, [ARow1]), + + ?line try_test(use_no_rights, [], Opts), + + %% Create the view family + VRow1Idx = mk_ln(RVName) ++ mk_ln(?xDescr), % object access + VRow2Idx = mk_ln(RVName) ++ mk_ln(?xDescr2 ++ [0]), % instance access + VRow3Idx = mk_ln(WVName) ++ mk_ln(?xDescr), % object access + VRow4Idx = mk_ln(WVName) ++ mk_ln(?xDescr ++ [0]), % instance access + VRow1Status = [vacmViewTreeFamilyStatus, VRow1Idx], + VRow2Status = [vacmViewTreeFamilyStatus, VRow2Idx], + VRow3Status = [vacmViewTreeFamilyStatus, VRow3Idx], + VRow4Status = [vacmViewTreeFamilyStatus, VRow4Idx], + + ?line try_test(add_row, [VRow1Status]), + ?line try_test(add_row, [VRow2Status]), + ?line try_test(add_row, [VRow3Status]), + + %% We're supposed to have access now... + ?line try_test(use_rights, [], Opts), + + %% Change Row3 to Row4 + ?line try_test(del_row, [VRow3Status]), + ?line try_test(add_row, [VRow4Status]), + + %% We should still have access... + ?line try_test(use_rights, [], Opts), + + %% Delete rows + ?line try_test(del_row, [GRow1Status]), + + ?line try_test(use_no_rights, [], Opts), + + %% Delete rest of rows + ?line try_test(del_row, [ARow1Status]), + ?line try_test(del_row, [VRow1Status]), + ?line try_test(del_row, [VRow2Status]), + ?line try_test(del_row, [VRow4Status]), + + ?line try_test(use_no_rights, [], Opts), + snmpa:verbosity(master_agent,log). + +do_set(Row) -> + s(Row), + expect(1, Row). + +add_row(RowStatus) -> + s([{RowStatus, ?createAndGo}]), + expect(1, [{RowStatus, ?createAndGo}]). + +del_row(RowStatus) -> + s([{RowStatus, ?destroy}]), + expect(1, [{RowStatus, ?destroy}]). + + + +use_no_rights() -> + g([[xDescr,0]]), + ?v1_2_3(expect(11, noSuchName, 1, any), + expect(12, [{[xDescr,0], noSuchObject}]), + expect(13, authorizationError, 1, any)), + g([[xDescr2,0]]), + ?v1_2_3(expect(21, noSuchName, 1, any), + expect(22, [{[xDescr2,0], noSuchObject}]), + expect(23, authorizationError, 1, any)), + gn([[xDescr]]), + ?v1_2_3(expect(31, noSuchName, 1, any), + expect(32, [{[xDescr], endOfMibView}]), + expect(33, authorizationError, 1, any)), + s([{[xDescr,0], "tryit"}]), + ?v1_2_3(expect(41, noSuchName, 1, any), + expect(42, noAccess, 1, any), + expect(43, authorizationError, 1, any)). + + +use_rights() -> + g([[xDescr,0]]), + expect(1, [{[xDescr,0], any}]), + g([[xDescr2,0]]), + expect(2, [{[xDescr2,0], any}]), + s([{[xDescr,0], "tryit"}]), + expect(3, noError, 0, any), + g([[xDescr,0]]), + expect(4, [{[xDescr,0], "tryit"}]). + +mk_ln(X) -> + [length(X) | X]. + +%%----------------------------------------------------------------- +%% o add/delete users and try them +%% o test all secLevels +%% o test all combinations of protocols +%% o try bad ops; check counters +%%----------------------------------------------------------------- +snmp_user_based_sm_mib_3(suite) -> []; +snmp_user_based_sm_mib_3(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + _AgentDir = ?config(agent_dir, Config), + ?line load_master_std("SNMP-USER-BASED-SM-MIB"), + + %% The newUser used here already has VACM access. + + %% Add a new user in the simplest way; just createAndGo + try_test(v3_sync, [[{usm_add_user1, []}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + %% Try to use the new user + ?line load_master("Test2"), + try_test(v3_sync, [[{usm_use_user, []}]], + [{sec_level, authPriv}, {user, "newUser"}]), + ?line unload_master("Test2"), + + ShaKey1 = snmp:passwd2localized_key(sha, "new sha password", "agentEngine"), + DesKey1 = lists:sublist(ShaKey1, 16), + + %% Change the new user's keys - 1 + try_test(v3_sync, [[{usm_key_change1, [ShaKey1, DesKey1]}]], + [{sec_level, authPriv}, {user, "newUser"}]), + + %% Try to use the new keys + MgrDir = ?config(mgr_dir, Config), + ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), + ?line load_master("Test2"), + try_test(v3_sync, [[{usm_use_user, []}]], + [{sec_level, authPriv}, {user, "newUser"}]), + ?line unload_master("Test2"), + + ShaKey2 = snmp:passwd2localized_key(sha, "newer password", "agentEngine"), + DesKey2 = lists:sublist(ShaKey2, 16), + + %% Change the new user's keys - 2 + ?line try_test(v3_sync, + [[{usm_key_change2, [ShaKey1, DesKey1, ShaKey2, DesKey2]}]], + [{sec_level, authPriv}, {user, "newUser"}]), + + %% Try to use the new keys + reset_usm_mgr(MgrDir), + ?line rewrite_usm_mgr(MgrDir, ShaKey2, DesKey2), + ?line load_master("Test2"), + ?line try_test(v3_sync, [[{usm_use_user, []}]], + [{sec_level, authPriv}, {user, "newUser"}]), + ?line unload_master("Test2"), + reset_usm_mgr(MgrDir), + + %% Change the new user's keys - 3 + ?line try_test(v3_sync, + [[{usm_key_change3, [ShaKey2, DesKey2, ShaKey1, DesKey1]}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + %% Try to use the new keys + ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), + ?line load_master("Test2"), + try_test(v3_sync, [[{usm_use_user, []}]], + [{sec_level, authPriv}, {user, "newUser"}]), + ?line unload_master("Test2"), + reset_usm_mgr(MgrDir), + + %% Try some read requests + ?line try_test(v3_sync, [[{usm_read, []}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + %% Delete the new user + ?line try_test(v3_sync, [[{usm_del_user, []}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + %% Try some bad requests + ?line try_test(v3_sync, [[{usm_bad, []}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + ?line unload_master("SNMP-USER-BASED-SM-MIB"). + +-define(usmUserSecurityName, [1,3,6,1,6,3,15,1,2,2,1,3]). + +usm_add_user1() -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + RowPointer = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], + Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer}, + {[usmUserStatus, NewRowIndex], ?createAndGo}], + ?line s(Vbs1), + ?line expect(1, Vbs1), + ok. + +usm_use_user() -> + v2_proc(). + + +%% Change own public keys +usm_key_change1(ShaKey, DesKey) -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + "passwd_shaxxxxxxxxxx", + ShaKey), + DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + "passwd_desxxxxxx", + DesKey), + Vbs1 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, + {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], + s(Vbs1), + ?line expect(1, Vbs1). + +%% Change own private keys +usm_key_change2(OldShaKey, OldDesKey, ShaKey, DesKey) -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + OldShaKey, + ShaKey), + DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + OldDesKey, + DesKey), + Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}, + {[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], + s(Vbs1), + ?line expect(1, Vbs1). + +%% Change other's public keys +usm_key_change3(OldShaKey, OldDesKey, ShaKey, DesKey) -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + OldShaKey, + ShaKey), + DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + OldDesKey, + DesKey), + Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}], + s(Vbs1), + ?line expect(1, noAccess, 1, any), + Vbs2 = [{[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], + s(Vbs2), + ?line expect(2, noAccess, 1, any), + + + Vbs3 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, + {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], + s(Vbs3), + ?line expect(1, Vbs3). + +usm_read() -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + ?line g([[usmUserSecurityName, NewRowIndex], + [usmUserCloneFrom, NewRowIndex], + [usmUserAuthKeyChange, NewRowIndex], + [usmUserOwnAuthKeyChange, NewRowIndex], + [usmUserPrivKeyChange, NewRowIndex], + [usmUserOwnPrivKeyChange, NewRowIndex]]), + ?line expect(1, + [{[usmUserSecurityName, NewRowIndex], "newUser"}, + {[usmUserCloneFrom, NewRowIndex], [0,0]}, + {[usmUserAuthKeyChange, NewRowIndex], ""}, + {[usmUserOwnAuthKeyChange, NewRowIndex], ""}, + {[usmUserPrivKeyChange, NewRowIndex], ""}, + {[usmUserOwnPrivKeyChange, NewRowIndex], ""}]), + ok. + + + +usm_del_user() -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + Vbs1 = [{[usmUserStatus, NewRowIndex], ?destroy}], + ?line s(Vbs1), + ?line expect(1, Vbs1), + ok. + +-define(usmUserCloneFrom, [1,3,6,1,6,3,15,1,2,2,1,4]). + +-define(usmNoAuthProtocol, [1,3,6,1,6,3,10,1,1,1]). + +-define(usmHMACMD5AuthProtocol, [1,3,6,1,6,3,10,1,1,2]). + +-define(usmHMACSHAAuthProtocol, [1,3,6,1,6,3,10,1,1,3]). + +-define(usmNoPrivProtocol, [1,3,6,1,6,3,10,1,2,1]). + +-define(usmDESPrivProtocol, [1,3,6,1,6,3,10,1,2,2]). + +usm_bad() -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + RowPointer1 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDOS"], + Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer1}, + {[usmUserStatus, NewRowIndex], ?createAndGo}], + ?line s(Vbs1), + ?line expect(1, inconsistentName, 1, any), + + RowPointer2 = ?usmUserCloneFrom ++ [11|"agentEngine"] ++ [7|"privDES"], + Vbs2 = [{[usmUserCloneFrom, NewRowIndex], RowPointer2}, + {[usmUserStatus, NewRowIndex], ?createAndGo}], + ?line s(Vbs2), + ?line expect(2, wrongValue, 1, any), + + RowPointer3 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], + Vbs3 = [{[usmUserCloneFrom, NewRowIndex], RowPointer3}, + {[usmUserStatus, NewRowIndex], ?createAndGo}], + ?line s(Vbs3), + ?line expect(3, Vbs3), + ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmNoAuthProtocol}]), + ?line expect(4, inconsistentValue, 1, any), + ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmHMACMD5AuthProtocol}]), + ?line expect(5, inconsistentValue, 1, any), + ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmDESPrivProtocol}]), + ?line expect(6, wrongValue, 1, any), + ?line s([{[usmUserPrivProtocol, NewRowIndex], ?usmHMACSHAAuthProtocol}]), + ?line expect(7, wrongValue, 1, any), + + Vbs4 = [{[usmUserStatus, NewRowIndex], ?destroy}], + ?line s(Vbs4), + ?line expect(1, Vbs4), + + ok. + + +%%----------------------------------------------------------------- +%% Loop through entire MIB, to make sure that all instrum. funcs +%% works. +%% Load all std mibs that are not loaded by default. +%%----------------------------------------------------------------- +loop_mib(suite) -> []; +loop_mib(Config) when list(Config) -> + ?LOG("loop_mib -> initiate case",[]), + %% snmpa:verbosity(master_agent,debug), + %% snmpa:verbosity(mib_server,info), + {SaNode, MgrNode, MibDir} = init_case(Config), + ?DBG("loop_mib -> ~n" + "\tSaNode: ~p~n" + "\tMgrNode: ~p~n" + "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), + ?DBG("loop_mib -> load mib SNMP-COMMUNITY-MIB",[]), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?DBG("loop_mib -> load mib SNMP-MPD-MIB",[]), + ?line load_master_std("SNMP-MPD-MIB"), + ?DBG("loop_mib -> load mib SNMP-TARGET-MIB",[]), + ?line load_master_std("SNMP-TARGET-MIB"), + ?DBG("loop_mib -> load mib SNMP-NOTIFICATION-MIB",[]), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?DBG("loop_mib -> load mib SNMP-FRAMEWORK-MIB",[]), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?DBG("loop_mib -> load mib SNMP-VIEW-BASED-ACM-MIB",[]), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + ?DBG("loop_mib -> try",[]), + try_test(loop_mib_1), + ?DBG("loop_mib -> unload mib SNMP-COMMUNITY-MIB",[]), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?DBG("loop_mib -> unload mib SNMP-MPD-MIB",[]), + ?line unload_master("SNMP-MPD-MIB"), + ?DBG("loop_mib -> unload mib SNMP-TARGET-MIB",[]), + ?line unload_master("SNMP-TARGET-MIB"), + ?DBG("loop_mib -> unload mib SNMP-NOTIFICATION-MIB",[]), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?DBG("loop_mib -> unload mib SNMP-FRAMEWORK-MIB",[]), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?DBG("loop_mib -> unload mib SNMP-VIEW-BASED-ACM-MIB",[]), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + %% snmpa:verbosity(master_agent,log), + %% snmpa:verbosity(mib_server,silence), + ?LOG("loop_mib -> done",[]). + + +loop_mib_2(suite) -> []; +loop_mib_2(Config) when list(Config) -> + ?LOG("loop_mib_2 -> initiate case",[]), + {SaNode, MgrNode, MibDir} = init_case(Config), + ?DBG("loop_mib_2 -> ~n" + "\tSaNode: ~p~n" + "\tMgrNode: ~p~n" + "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), + ?DBG("loop_mib_2 -> load mibs",[]), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-MPD-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + try_test(loop_mib_2), + ?DBG("loop_mib_2 -> unload mibs",[]), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?line unload_master("SNMP-MPD-MIB"), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + ?LOG("loop_mib_2 -> done",[]). + + +loop_mib_3(suite) -> []; +loop_mib_3(Config) when list(Config) -> + ?LOG("loop_mib_3 -> initiate case",[]), + {SaNode, MgrNode, MibDir} = init_case(Config), + ?DBG("loop_mib_3 -> ~n" + "\tSaNode: ~p~n" + "\tMgrNode: ~p~n" + "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), + ?DBG("loop_mib_3 -> load mibs",[]), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + ?line load_master_std("SNMP-USER-BASED-SM-MIB"), + try_test(loop_mib_2), + ?DBG("loop_mib_3 -> unload mibs",[]), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + ?line unload_master("SNMP-USER-BASED-SM-MIB"), + ?LOG("loop_mib_3 -> done",[]). + + +%% Req. As many mibs all possible +loop_mib_1() -> + ?DBG("loop_mib_1 -> entry",[]), + N = loop_it_1([1,1], 0), + io:format(user, "found ~w varibles\n", [N]), + ?line N = if N < 100 -> 100; + true -> N + end. + + +loop_it_1(Oid, N) -> + ?DBG("loop_it_1 -> entry with~n" + "\tOid: ~p~n" + "\tN: ~p",[Oid,N]), + case get_next_req([Oid]) of + #pdu{type='get-response', error_status=noError, error_index=0, + varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> + ?DBG("loop_it_1 -> ~n" + "\tNOid: ~p~n" + "\tValue: ~p",[NOid,Value]), + ?line [Value2] = get_req(1, [NOid]), % must not be same + ?DBG("loop_it_1 -> ~n" + "\tValue2: ~p",[Value2]), + loop_it_1(NOid, N+1); + #pdu{type='get-response', error_status=noSuchName, error_index=1, + varbinds=[_]} -> + ?DBG("loop_it_1 -> done",[]), + N; + + #pdu{type = Type, error_status = Err, error_index = Idx, + varbinds = Vbs} -> + exit({unexpected_pdu, ?LINE, Type, Err, Idx, Vbs}) + end. + +%% Req. As many mibs all possible +loop_mib_2() -> + ?DBG("loop_mib_1 -> entry",[]), + N = loop_it_2([1,1], 0), + io:format(user, "found ~w varibles\n", [N]), + ?line N = if N < 100 -> 100; + true -> N + end. + + +loop_it_2(Oid, N) -> + ?DBG("loop_it_2 -> entry with~n" + "\tOid: ~p~n" + "\tN: ~p",[Oid,N]), + case get_next_req([Oid]) of + #pdu{type='get-response', error_status=noError, error_index=0, + varbinds=[#varbind{oid = NOid, value = endOfMibView}]} -> + ?DBG("loop_it_2 -> ~n" + "\tNOid: ~p",[NOid]), + N; + #pdu{type='get-response', error_status=noError, error_index=0, + varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> + ?DBG("loop_it_2 -> ~n" + "\tNOid: ~p~n" + "\tValue: ~p",[NOid,Value]), + ?line [Value2] = get_req(1, [NOid]), % must not be same + ?DBG("loop_it_2 -> ~n" + "\tValue2: ~p",[Value2]), + loop_it_2(NOid, N+1) + end. + + +%%%----------------------------------------------------------------- +%%% Testing of reported bugs and other tickets. +%%%----------------------------------------------------------------- + + + + + +%% These are (ticket) test cases where the initiation has to be done +%% individually. + +%%----------------------------------------------------------------- +%% Ticket: OTP-1128 +%% Slogan: Bug in handling of createAndWait set-requests. +%%----------------------------------------------------------------- +otp_1128(suite) -> []; +otp_1128(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(otp_1128), + ?line unload_master("OLD-SNMPEA-MIB"). + +otp_1128_2(X) -> otp_1128(X). + +otp_1128_3(X) -> otp_1128(X). + +otp_1128() -> + io:format("Testing bug reported in ticket OTP-1128...~n"), + + NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], + NewKeyc4 = [intCommunityAccess,get(mip),is("test")], + NewKeyc5 = [intCommunityStatus,get(mip),is("test")], + + s([{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), + ?line expect(28, [{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), + g([NewKeyc5]), + ?line expect(29, [{NewKeyc5, ?notReady}]), + s([{NewKeyc5, ?active}, {NewKeyc3, 2}]), + ?line expect(30, [{NewKeyc5, ?active}, {NewKeyc3, 2}]), + g([NewKeyc5]), + ?line expect(31, [{NewKeyc5, ?active}]), + s([{NewKeyc5, ?destroy}]), + ?line expect(32, [{NewKeyc5, ?destroy}]). + +%%----------------------------------------------------------------- +%% Ticket: OTP-1129, OTP-1169 +%% Slogan: snmpa:int_to_enum crashes on bad oids +%%----------------------------------------------------------------- +otp_1129(suite) -> []; +otp_1129(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas3"), + try_test(otp_1129_i, [node()]), + ?line unload_master("Klas3"). + +otp_1129_2(X) -> otp_1129(X). + +otp_1129_3(X) -> otp_1129(X). + +otp_1129_i(MaNode) -> + io:format("Testing bug reported in ticket OTP-1129...~n"), + false = rpc:call(MaNode, snmp, int_to_enum, [iso, 1]), + false = rpc:call(MaNode, snmp, int_to_enum, [isox, 1]). + +%%----------------------------------------------------------------- +%% Ticket: OTP-1131 +%% Slogan: Agent crashes / erlang node halts if RowIndex in a +%% setrequest is of bad type, e.g. an INDEX {INTEGER}, +%% and RowIdenx [3,2]. +%%----------------------------------------------------------------- +otp_1131(suite) -> []; +otp_1131(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas1"), + try_test(otp_1131), + ?line unload_master("Klas1"). + +otp_1131_2(X) -> otp_1131(X). + +otp_1131_3(X) -> otp_1131(X). + +otp_1131() -> + io:format("Testing bug reported in ticket OTP-1131...~n"), + s([{[friendsEntry, [2, 3, 1]], s, "kompis3"}, + {[friendsEntry, [3, 3, 1]], i, ?createAndGo}]), + ?line expect(1, ?v1_2(noSuchName, noCreation), 2, any). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1162 +%% Slogan: snmp_agent can't handle wrongValue from instrum.func +%%----------------------------------------------------------------- +otp_1162(suite) -> []; +otp_1162(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + try_test(otp_1162), + stop_subagent(SA). + +otp_1162_2(X) -> otp_1162(X). + +otp_1162_3(X) -> otp_1162(X). + +otp_1162() -> + s([{[sa, [2,0]], 6}]), % wrongValue (i is_set_ok) + ?line expect(1, ?v1_2(badValue, wrongValue), 1, any). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1222 +%% Slogan: snmp agent crash if faulty index is returned from instrum +%%----------------------------------------------------------------- +otp_1222(suite) -> []; +otp_1222(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas3"), + ?line load_master("Klas4"), + try_test(otp_1222), + ?line unload_master("Klas3"), + ?line unload_master("Klas4"). + +otp_1222_2(X) -> otp_1222(X). + +otp_1222_3(X) -> otp_1222(X). + +otp_1222() -> + io:format("Testing bug reported in ticket OTP-1222...~n"), + s([{[fStatus4,1], 4}, {[fName4,1], 1}]), + ?line expect(1, genErr, 0, any), + s([{[fStatus4,2], 4}, {[fName4,2], 1}]), + ?line expect(2, genErr, 0, any). + +%%----------------------------------------------------------------- +%% Ticket: OTP-1298 +%% Slogan: Negative INTEGER values are treated as positive. +%%----------------------------------------------------------------- +otp_1298(suite) -> []; +otp_1298(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas2"), + try_test(otp_1298), + ?line unload_master("Klas2"). + +otp_1298_2(X) -> otp_1298(X). + +otp_1298_3(X) -> otp_1298(X). + +otp_1298() -> + io:format("Testing bug reported in ticket OTP-1298...~n"), + s([{[fint,0], -1}]), + ?line expect(1298, [{[fint,0], -1}]). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1331 +%% Slogan: snmp_generic should return noError when deleting non-ex row +%%----------------------------------------------------------------- +otp_1331(suite) -> []; +otp_1331(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(otp_1331), + ?line unload_master("OLD-SNMPEA-MIB"). + +otp_1331_2(X) -> otp_1331(X). + +otp_1331_3(X) -> otp_1331(X). + +otp_1331() -> + NewKeyc5 = [intCommunityStatus,[127,32,0,0],is("test")], + s([{NewKeyc5, ?destroy}]), + ?line expect(1, [{NewKeyc5, ?destroy}]). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1338 +%% Slogan: snmp bug in initialisation of default values for mnesia tabs +%%----------------------------------------------------------------- +otp_1338(suite) -> []; +otp_1338(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas2"), + try_test(otp_1338), + ?line unload_master("Klas2"). + +otp_1338_2(X) -> otp_1338(X). + +otp_1338_3(X) -> otp_1338(X). + +otp_1338() -> + s([{[kStatus2, 7], i, ?createAndGo}]), + ?line expect(1, [{[kStatus2, 7], ?createAndGo}]), + g([[kName2, 7]]), + ?line expect(2, [{[kName2, 7], "JJJ"}]). + +%%----------------------------------------------------------------- +%% Ticket: OTP-1342 +%% Slogan: default impl of snmp table can't handle bad index access, +%% Set when INDEX is read-write gets into an infinite loop! +%%----------------------------------------------------------------- +otp_1342(suite) -> []; +otp_1342(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas4"), + try_test(otp_1342), + ?line unload_master("Klas4"). + +otp_1342_2(X) -> otp_1342(X). + +otp_1342_3(X) -> otp_1342(X). + +otp_1342() -> + s([{[fIndex5, 1], i, 1}, + {[fName5, 1], i, 3}, + {[fStatus5, 1], i, ?createAndGo}]), + ?line expect(1, ?v1_2(noSuchName, noCreation), 3, any). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1366 +%% Slogan: snmp traps not sent to all managers +%% Note: NYI! We need a way to tell the test server that we need +%% mgrs on two different machines. +%%----------------------------------------------------------------- +otp_1366(suite) -> []; +otp_1366(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(otp_1366), + ?line unload_master("OLD-SNMPEA-MIB"). + +otp_1366_2(X) -> otp_1366(X). + +otp_1366_3(X) -> otp_1366(X). + +otp_1366() -> + ?INF("NOT YET IMPLEMENTED", []), + 'NYI'. + +%%----------------------------------------------------------------- +%% Ticket: OTP-2776 +%% Slogan: snmp:validate_date_and_time() fails when time is 00:00 +%%----------------------------------------------------------------- +otp_2776(suite) -> []; +otp_2776(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + try_test(otp_2776). + +otp_2776_2(X) -> otp_2776(X). + +otp_2776_3(X) -> otp_2776(X). + +otp_2776() -> + io:format("Testing bug reported in ticket OTP-2776...~n"), + + Dt01_valid = [19,98,9,1,1,0,23,0,43,0,0], + Dt02_valid = [19,98,9,1,0,0,0,0,43,0,0], % This is what is fixed: 00:00 + Dt03_valid = [19,98,2,28,1,0,23,0,43,0,0], + Dt04_invalid = [19,98,2,29,1,0,23,0,43,0,0], + Dt05_valid = [19,96,2,29,1,0,23,0,43,0,0], + Dt06_valid = [20,0,2,29,1,0,23,0,43,0,0], + Dt07_invalid = [19,96,2,30,1,0,23,0,43,0,0], % This is also fixed: 30/2 + Dt08_valid = [19,98,4,30,1,0,23,0,43,0,0], + Dt09_invalid = [19,98,4,31,1,0,23,0,43,0,0], % This is also fixed: 31/4 + Dt10_invalid = [], + Dt11_invalid = [kalle,hobbe], + L = [{ 1, true, Dt01_valid}, + { 2, true, Dt02_valid}, + { 3, true, Dt03_valid}, + { 4, false, Dt04_invalid}, + { 5, true, Dt05_valid}, + { 6, true, Dt06_valid}, + { 7, false, Dt07_invalid}, + { 8, true, Dt08_valid}, + { 9, false, Dt09_invalid}, + {10, false, Dt10_invalid}, + {11, false, Dt11_invalid}], + + ?line ok = validate_dat(L). + + +validate_dat(L) -> validate_dat(L,[]). + +validate_dat([],V) -> + Fun = fun({_,X}) -> case X of + ok -> false; + _ -> true + end + end, + validate_dat1( lists:reverse( lists:filter(Fun,V) ) ); +validate_dat([{Id,E,Dat}|T],V) -> + validate_dat(T,[validate_dat2(Id,E,Dat) | V]). + +validate_dat1([]) -> ok; +validate_dat1(L) -> {error,L}. + +validate_dat2(Id, E, Dat) -> + Res = case {E,snmp:validate_date_and_time(Dat)} of + {E,E} -> ok; + {E,A} -> {E,A} + end, + {Id, Res}. + + +%%----------------------------------------------------------------- +%% Ticket: OTP-2979 +%% Slogan: get-next on more than 1 column in an empty table +%% returns bad response. +%%----------------------------------------------------------------- +otp_2979(suite) -> []; +otp_2979(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Test1"), + ?line init_old(), + try_test(otp_2979), + ?line unload_master("Test1"). + +otp_2979_2(X) -> otp_2979(X). + +otp_2979_3(X) -> otp_2979(X). + +otp_2979() -> + gn([[sparseDescr], [sparseStatus]]), + ?line expect(1, [{[sparseStr,0], "slut"}, + {[sparseStr,0], "slut"}]). + +%%----------------------------------------------------------------- +%% Ticket: OTP-3187 +%% Slogan: get-next on vacmAccessTable for colums > 5 returns +%% endOfTable - should return value. +%%----------------------------------------------------------------- +otp_3187(suite) -> []; +otp_3187(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + otp_3187(), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). + +otp_3187_2(X) -> otp_3187(X). + +otp_3187_3(X) -> otp_3187(X). + +otp_3187() -> + ?line Elements = + snmp_view_based_acm_mib:vacmAccessTable(get_next,[],[4,5,6]), + lists:foreach(fun(E) -> + ?line if E == endOfTable -> + ?FAIL(endOfTable); + true -> ok + end + end, Elements). + +%%----------------------------------------------------------------- +%% Ticket: OTP-3542 +%% Slogan: +%%----------------------------------------------------------------- +otp_3542(suite) -> []; +otp_3542(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + try_test(otp_3542). + +otp_3542() -> + io:format("SNMP v3 discovery...~n"), + ?line Res = snmp_test_mgr:d(), + io:format("SNMP v3 discovery result: ~p~n",[Res]). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-3725 +%% Slogan: Slow response time on snmpa:int_to_enum +%%----------------------------------------------------------------- +otp_3725(suite) -> []; +otp_3725(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(otp_3725_test, [node()]), + ?line unload_master("OLD-SNMPEA-MIB"). + +%% Req. OLD-SNMPEA-MIB +otp_3725_test(MaNode) -> + io:format("Testing feature requested in ticket OTP-3725...~n"), + ?line rpc:call(MaNode,snmpa,verbosity,[symbolic_store,trace]), + ?line Db = rpc:call(MaNode,snmp,get_symbolic_store_db,[]), + ?DBG("otp_3725_test -> Db = ~p",[Db]), + + ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, + [Db, intAgentIpAddress]), + ?DBG("otp_3725_test -> name_to_oid for ~p: ~p",[intAgentIpAddress,OID]), + ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, oid_to_name, + [Db,OID]), + ?DBG("otp_3725_test -> oid_to_name for ~p: ~p",[OID,intAgentIpAddress]), + ?line false = rpc:call(MaNode, snmp, name_to_oid, [Db, intAgentIpAddres]), + ?line false = rpc:call(MaNode, snmp, oid_to_name, + [Db, [1,5,32,3,54,3,3,34,4]]), + ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, + [Db, intViewType, excluded]), + ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, + [Db, intViewType, 2]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, intViewType, exclude]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, intAgentIpAddress, exclude]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, intAgentIpAddre, exclude]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, intViewType, 3]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, + [Db, intAgentIpAddress, 2]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, + [Db, intAgentIpAddre, 2]), + ?line {value, active} = rpc:call(MaNode, snmp, int_to_enum, + [Db, 'RowStatus', ?active]), + ?line {value, ?destroy} = rpc:call(MaNode, snmp, enum_to_int, + [Db, 'RowStatus', destroy]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, 'RowStatus', xxxdestroy]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, 'xxRowStatus', destroy]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'RowStatus', 25]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'xxRowStatus', 1]), + ok. + + +%%----------------------------------------------------------------- +%% Ticket: OTP-4394 +%% Slogan: Target mib tag list check invalid +%%----------------------------------------------------------------- + + + +init_otp_4394(Config) when list(Config) -> + ?DBG("init_otp_4394 -> entry with" + "~n Config: ~p", [Config]), + ?line AgentDir = ?config(agent_dir, Config), + ?line MgrDir = ?config(mgr_dir, Config), + ?line Ip = ?config(ip, Config), + ?line otp_4394_config(AgentDir, MgrDir, Ip), + MasterAgentVerbosity = {master_agent_verbosity, trace}, + NetIfVerbosity = {net_if_verbosity, trace}, + Opts = [MasterAgentVerbosity,NetIfVerbosity], + [{vsn, v1} | start_v1_agent(Config,Opts)]. + +otp_4394_config(AgentDir, MgrDir, Ip0) -> + ?DBG("otp_4394_config -> entry with" + "~n AgentDir: ~p" + "~n MgrDir: ~p" + "~n Ip0: ~p", [AgentDir, MgrDir, Ip0]), + Vsn = [v1], + Ip = tuple_to_list(Ip0), + ?line snmp_config:write_agent_snmp_files(AgentDir, Vsn, Ip, + ?TRAP_UDP, Ip, 4000, + "OTP-4394 test"), + ?line case update_usm(Vsn, AgentDir) of + true -> + ?line copy_file(filename:join(AgentDir, "usm.conf"), + filename:join(MgrDir, "usm.conf")), + ?line update_usm_mgr(Vsn, MgrDir); + false -> + ?line ok + end, + C1 = {"a", "all-rights", "initial", "", "pc"}, + C2 = {"c", "secret", "secret_name", "", "secret_tag"}, + ?line write_community_conf(AgentDir, [C1, C2]), + ?line update_vacm(Vsn, AgentDir), + Ta1 = {"shelob v1", + [134,138,177,177], 5000, 1500, 3, %% Använd Ip och modda + "pc1", + "target_v1", "", + %% [255,255,255,255,0,0], + [], + 2048}, + Ta2 = {"bifur v1", + [134,138,177,75], 5000, 1500, 3, %% Använd Ip + "pc2", + "target_v1", "", + %% [255,255,255,255,0,0], + [], 2048}, + ?line write_target_addr_conf(AgentDir, [Ta1, Ta2]), + ?line write_target_params_conf(AgentDir, Vsn), + ?line write_notify_conf(AgentDir), + ok. + + + +finish_otp_4394(Config) when list(Config) -> + ?DBG("finish_otp_4394 -> entry", []), + C1 = stop_agent(Config), + delete_files(C1), + erase(mgr_node), + lists:keydelete(vsn, 1, C1). + +otp_4394_test(suite) -> []; +otp_4394_test(Config) -> + ?DBG("otp_4394_test -> entry", []), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + try_test(otp_4394_test1), + ?DBG("otp_4394_test -> done", []), + ok. + +otp_4394_test1() -> + ?DBG("otp_4394_test1 -> entry", []), + gn([[1,1]]), + Res = + case snmp_test_mgr:expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]) of + %% {error, 1, {"?",[]}, {"~w",[timeout]}} + {error, 1, _, {_, [timeout]}} -> + ?DBG("otp_4394_test1 -> expected result: timeout", []), + ok; + Else -> + Else + end, + ?DBG("otp_4394_test1 -> done with: ~p", [Res]), + Res. + + +%%%-------------------------------------------------- +%%% Used to test the standard mib with our +%%% configuration. +%%%-------------------------------------------------- +run(F, A, Opts) -> + M = get(mib_dir), + Dir = get(mgr_dir), + User = snmp_misc:get_option(user, Opts, "all-rights"), + SecLevel = snmp_misc:get_option(sec_level, Opts, noAuthNoPriv), + EngineID = snmp_misc:get_option(engine_id, Opts, "agentEngine"), + CtxEngineID = snmp_misc:get_option(context_engine_id, Opts, EngineID), + Community = snmp_misc:get_option(community, Opts, "all-rights"), + ?DBG("run -> start crypto app",[]), + Crypto = case os:type() of + vxworks -> + no_crypto; + _ -> + ?CRYPTO_START() + end, + ?DBG("run -> Crypto: ~p",[Crypto]), + catch snmp_test_mgr:stop(), % If we had a running mgr from a failed case + StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", + ?DBG("run -> config:~n" + "\tM: ~p~n" + "\tDir: ~p~n" + "\tUser: ~p~n" + "\tSecLevel: ~p~n" + "\tEngineID: ~p~n" + "\tCtxEngineID: ~p~n" + "\tCommunity: ~p~n" + "\tStdM: ~p", + [M,Dir,User,SecLevel,EngineID,CtxEngineID,Community,StdM]), + case snmp_test_mgr:start([%% {agent, snmp_test_lib:hostname()}, + {packet_server_debug,true}, + {debug,true}, + {agent, get(master_host)}, + {agent_udp, 4000}, + {trap_udp, 5000}, + {recbuf,65535}, + quiet, + get(vsn), + {community, Community}, + {user, User}, + {sec_level, SecLevel}, + {engine_id, EngineID}, + {context_engine_id, CtxEngineID}, + {dir, Dir}, + {mibs, mibs(StdM, M)}]) of + {ok, _Pid} -> + Res = apply(?MODULE, F, A), + catch snmp_test_mgr:stop(), + Res; + Err -> + io:format("Error starting manager: ~p\n", [Err]), + catch snmp_test_mgr:stop(), + ?line exit({mgr_start, Err}) + end. + + +mibs(StdMibDir,MibDir) -> + [join(StdMibDir, ?v1_2("STANDARD-MIB.bin", "SNMPv2-MIB.bin")), + join(MibDir, "OLD-SNMPEA-MIB.bin"), + join(StdMibDir, "SNMP-FRAMEWORK-MIB"), + join(StdMibDir, "SNMP-MPD-MIB"), + join(StdMibDir, "SNMP-VIEW-BASED-ACM-MIB"), + join(StdMibDir, "SNMP-USER-BASED-SM-MIB"), + join(StdMibDir, "SNMP-TARGET-MIB"), + join(StdMibDir, "SNMP-NOTIFICATION-MIB"), + join(MibDir, "Klas1.bin"), + join(MibDir, "Klas2.bin"), + join(MibDir, "Klas3.bin"), + join(MibDir, "Klas4.bin"), + join(MibDir, "SA-MIB.bin"), + join(MibDir, "TestTrap.bin"), + join(MibDir, "Test1.bin"), + join(MibDir, "Test2.bin"), + join(MibDir, "TestTrapv2.bin")]. + +join(D,F) -> + filename:join(D,F). + +%% string used in index +is(S) -> [length(S) | S]. + +try_test(Func) -> + call(get(mgr_node), ?MODULE, run, [Func, [], []]). + +try_test(Func, A) -> + call(get(mgr_node), ?MODULE, run, [Func, A, []]). + +try_test(Func, A, Opts) -> + call(get(mgr_node), ?MODULE, run, [Func, A, Opts]). + +call(N,M,F,A) -> + ?DBG("call -> entry with~n" + " N: ~p~n" + " M: ~p~n" + " F: ~p~n" + " A: ~p~n" + " when~n" + " get(): ~p", + [N,M,F,A,get()]), + spawn(N, ?MODULE, wait, [self(),get(),M,F,A]), + receive + {done, {'EXIT', Rn}, Loc} -> + ?DBG("call -> returned ~p",[{done, {'EXIT', Rn}, Loc}]), + put(test_server_loc, Loc), + exit(Rn); + {done, Ret, Zed} -> + ?DBG("call -> returned ~p~n",[{done, Ret, Zed}]), + Ret + end. + +wait(From, Env, M, F, A) -> + ?DBG("wait -> entry with ~n" + "\tFrom: ~p~n" + "\tEnv: ~p",[From,Env]), + lists:foreach(fun({K,V}) -> put(K,V) end, Env), + Rn = (catch apply(M, F, A)), + ?DBG("wait -> Rn: ~n~p", [Rn]), + From ! {done, Rn, get(test_server_loc)}, + exit(Rn). + +expect(A,B) -> ok = snmp_test_mgr:expect(A,B). +expect(A,B,C) -> ok = snmp_test_mgr:expect(A,B,C). +expect(A,B,C,D) -> ok = snmp_test_mgr:expect(A,B,C,D). +expect(A,B,C,D,E,F) -> ok = snmp_test_mgr:expect(A,B,C,D,E,F). + +get_req(Id, Vars) -> + ?DBG("get_req -> entry with~n" + "\tId: ~p~n" + "\tVars: ~p",[Id,Vars]), + g(Vars), + ?DBG("get_req -> await response",[]), + {ok, Val} = snmp_test_mgr:get_response(Id, Vars), + ?DBG("get_req -> response: ~p",[Val]), + Val. + +get_next_req(Vars) -> + ?DBG("get_next_req -> entry with Vars '~p', send request",[Vars]), + gn(Vars), + ?DBG("get_next_req -> await response",[]), + Response = snmp_test_mgr:receive_response(), + ?DBG("get_next_req -> response: ~p",[Response]), + Response. + + + +start_node(Name) -> + ?LOG("start_node -> entry with Name: ~p",[Name]), + M = list_to_atom(?HOSTNAME(node())), + ?DBG("start_node -> M: ~p",[M]), + Pa = filename:dirname(code:which(?MODULE)), + ?DBG("start_node -> Pa: ~p",[Pa]), + + Args = case init:get_argument('CC_TEST') of + {ok, [[]]} -> + " -pa /clearcase/otp/libraries/snmp/ebin "; + {ok, [[Path]]} -> + " -pa " ++ Path; + error -> + "" + end, + %% Do not use start_link!!! (the proc that calls this one is tmp) + ?DBG("start_node -> Args: ~p~n",[Args]), + A = Args ++ " -pa " ++ Pa, + case (catch ?START_NODE(Name, A)) of + {ok, Node} -> + %% Tell the test_server to not clean up things it never started. + ?DBG("start_node -> Node: ~p",[Node]), + {ok, Node}; + Else -> + ?ERR("start_node -> failed with(other): Else: ~p",[Else]), + ?line ?FAIL(Else) + end. + + +stop_node(Node) -> + ?LOG("stop_node -> Node: ~p",[Node]), + rpc:cast(Node, erlang, halt, []). + +p(X) -> + io:format(user, X++"\n", []). + +sleep(X) -> + receive + after + X -> ok + end. + +%%%----------------------------------------------------------------- +%%% Configuration +%%%----------------------------------------------------------------- +config(Vsns, MgrDir, AgentDir, MIp, AIp) -> + ?line snmp_config:write_agent_snmp_files(AgentDir, Vsns, MIp, + ?TRAP_UDP, AIp, 4000, + "test"), + ?line case update_usm(Vsns, AgentDir) of + true -> + ?line copy_file(filename:join(AgentDir, "usm.conf"), + filename:join(MgrDir, "usm.conf")), + ?line update_usm_mgr(Vsns, MgrDir); + false -> + ?line ok + end, + ?line update_community(Vsns, AgentDir), + ?line update_vacm(Vsns, AgentDir), + ?line write_target_addr_conf(AgentDir, MIp, ?TRAP_UDP, Vsns), + ?line write_target_params_conf(AgentDir, Vsns), + ?line write_notify_conf(AgentDir), + ok. + +delete_files(Config) -> + Dir = ?config(agent_dir, Config), + {ok, List} = file:list_dir(Dir), + lists:foreach(fun(FName) -> file:delete(filename:join(Dir, FName)) end, + List). + +update_usm(Vsns, Dir) -> + case lists:member(v3, Vsns) of + true -> + {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),[read,write]), + file:position(Fid, eof), + ok = io:format(Fid, "{\"agentEngine\", \"all-rights\", " + "\"all-rights\", zeroDotZero, " + "usmNoAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"\", \"\"}.\n", []), + ok = io:format(Fid, "{\"agentEngine\", \"no-rights\", " + "\"no-rights\", zeroDotZero, " + "usmNoAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"\", \"\"}.\n", []), + ok = io:format(Fid, "{\"agentEngine\", \"authMD5\", " + "\"authMD5\", zeroDotZero, " + "usmHMACMD5AuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"passwd_md5xxxxxx\", \"\"}.\n", []), + ok = io:format(Fid, "{\"agentEngine\", \"authSHA\", " + "\"authSHA\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"\"}.\n", []), + ok = io:format(Fid, "{\"agentEngine\", \"privDES\", " + "\"privDES\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", + []), + ok = io:format(Fid, "{\"mgrEngine\", \"all-rights\", " + "\"all-rights\", zeroDotZero, " + "usmNoAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"\", \"\"}.\n", []), + ok = io:format(Fid, "{\"mgrEngine\", \"no-rights\", " + "\"no-rights\", zeroDotZero, " + "usmNoAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"\", \"\"}.\n", []), + ok = io:format(Fid, "{\"mgrEngine\", \"authMD5\", " + "\"authMD5\", zeroDotZero, " + "usmHMACMD5AuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"passwd_md5xxxxxx\", \"\"}.\n", []), + ok = io:format(Fid, "{\"mgrEngine\", \"authSHA\", " + "\"authSHA\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"\"}.\n", []), + ok = io:format(Fid, "{\"mgrEngine\", \"privDES\", " + "\"privDES\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", + []), + file:close(Fid), + true; + false -> + false + end. + +update_usm_mgr(Vsns, Dir) -> + case lists:member(v3, Vsns) of + true -> + {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),[read,write]), + file:position(Fid, eof), + ok = io:format(Fid, "{\"agentEngine\", \"newUser\", " + "\"newUser\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", + []), + ok = io:format(Fid, "{\"mgrEngine\", \"newUser\", " + "\"newUser\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", + []), + file:close(Fid), + true; + false -> + false + end. + +rewrite_usm_mgr(Dir, ShaKey, DesKey) -> + ?line ok = file:rename(filename:join(Dir,"usm.conf"), + filename:join(Dir,"usm.old")), + ?line {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),write), + ok = io:format(Fid, "{\"agentEngine\", \"newUser\", " + "\"newUser\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"~s\", \"~s\"}.\n", + [ShaKey, DesKey]), + ok = io:format(Fid, "{\"mgrEngine\", \"newUser\", " + "\"newUser\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"~s\", \"~s\"}.\n", + [ShaKey, DesKey]), + file:close(Fid). + +reset_usm_mgr(Dir) -> + ?line ok = file:rename(filename:join(Dir,"usm.old"), + filename:join(Dir,"usm.conf")). + + +update_community([v3], _Dir) -> ok; +update_community(_, Dir) -> + {ok, Fid} = file:open(filename:join(Dir,"community.conf"),[read,write]), + file:position(Fid, eof), + ok=io:format(Fid,"{\"no-rights\",\"no-rights\",\"no-rights\",\"\",\"\"}.\n", + []), + file:close(Fid). + + +-define(tDescr_instance, [1,3,6,1,2,1,16,1,0]). +update_vacm(_Vsn, Dir) -> + {ok, Fid} = file:open(filename:join(Dir,"vacm.conf"),[read,write]), + file:position(Fid, eof), + ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"authMD5\",\"initial\"}.\n",[]), + ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"authSHA\",\"initial\"}.\n",[]), + ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"privDES\",\"initial\"}.\n",[]), + ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"newUser\",\"initial\"}.\n",[]), + ok = io:format(Fid, "{vacmViewTreeFamily, \"internet\", " + "~w, excluded, null}.\n", [?tDescr_instance]), + file:close(Fid). + + +vacm_ver(v1) -> v1; +vacm_ver(v2) -> v2c; +vacm_ver(v3) -> usm. + + +write_community_conf(Dir, Confs) -> + {ok, Fid} = file:open(filename:join(Dir,"community.conf"),write), + ok = write_community_conf1(Fid, Confs), + file:close(Fid). + +write_community_conf1(_, []) -> + ok; +write_community_conf1(Fid, [{ComIdx, ComName, SecName, CtxName, TransTag}|Confs]) -> + ok = io:format(Fid, "{\"~s\", \"~s\", \"~s\", \"~s\", \"~s\"}.~n", + [ComIdx, ComName, SecName, CtxName, TransTag]), + write_community_conf1(Fid, Confs). + + +write_target_addr_conf(Dir, Confs) -> + {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), + ok = write_target_addr_conf1(Fid, Confs), + file:close(Fid). + + +write_target_addr_conf1(_, []) -> + ok; +write_target_addr_conf1(Fid, + [{Name, Ip, Port, Timeout, Retry, TagList, ParamName, + EngineId, TMask, MaxMsgSz}|Confs]) -> + ok = io:format(Fid, "{\"~s\", ~w, ~w, ~w, ~w, \"~s\", \"~s\", \"~s\", ~w, ~w}.~n", + [Name, Ip, Port, Timeout, Retry, TagList, ParamName, + EngineId, TMask, MaxMsgSz]), + write_target_addr_conf1(Fid, Confs). + +write_target_addr_conf(Dir, ManagerIp, UDP, Vsns) -> + {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), + lists:foreach(fun(Vsn) -> + ok = io:format(Fid, + "{\"~s\", ~w, ~w, 1500, 3, " + "\"std_trap\", \"~s\"}.~n", + [mk_ip(ManagerIp, Vsn), + ManagerIp, UDP, mk_param(Vsn)]), + case Vsn of + v1 -> ok; + v2 -> + ok = io:format(Fid, + "{\"~s.2\",~w,~w,1500,3, " + "\"std_inform\", \"~s\"}.~n", + [mk_ip(ManagerIp, Vsn), + ManagerIp, UDP, + mk_param(Vsn)]); + v3 -> + ok = io:format(Fid, + "{\"~s.3\",~w,~w,1500,3, " + "\"std_inform\", \"~s\", " + "\"mgrEngine\", [], 1024}.~n", + [mk_ip(ManagerIp, Vsn), + ManagerIp, UDP, + mk_param(Vsn)]) + end + end, + Vsns), + file:close(Fid). + +mk_param(v1) -> "target_v1"; +mk_param(v2) -> "target_v2"; +mk_param(v3) -> "target_v3". + +mk_ip([A,B,C,D], Vsn) -> + io_lib:format("~w.~w.~w.~w ~w", [A,B,C,D,Vsn]). + + +rewrite_target_addr_conf(Dir,NewPort) -> + TAFile = filename:join(Dir, "target_addr.conf"), + ?DBG("rewrite_target_addr_conf -> read target file info of address config file",[]), + case file:read_file_info(TAFile) of + {ok, _} -> ok; + {error, R} -> ?ERR("failure reading file info of " + "target address config file: ~p",[R]), + ok + end, + + ?line [TrapAddr|Addrs] = + snmp_conf:read(TAFile,fun(R) -> rewrite_target_addr_conf1(R) end), + + ?DBG("rewrite_target_addr_conf -> TrapAddr: ~p",[TrapAddr]), + + NewAddrs = [rewrite_target_addr_conf2(NewPort,TrapAddr)|Addrs], + + ?DBG("rewrite_target_addr_conf -> NewAddrs: ~p",[NewAddrs]), + + ?line ok = file:rename(filename:join(Dir,"target_addr.conf"), + filename:join(Dir,"target_addr.old")), + ?line {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), + + ?line ok = rewrite_target_addr_conf3(Fid,NewAddrs), + + file:close(Fid). + +rewrite_target_addr_conf1(O) -> + {ok,O}. + +rewrite_target_addr_conf2(NewPort,{Name,Ip,_Port,Timeout,Retry, + "std_trap",EngineId}) -> + ?LOG("rewrite_target_addr_conf2 -> entry with std_trap",[]), + {Name,Ip,NewPort,Timeout,Retry,"std_trap",EngineId}; +rewrite_target_addr_conf2(_NewPort,O) -> + ?LOG("rewrite_target_addr_conf2 -> entry with " + "~n O: ~p",[O]), + O. + + +rewrite_target_addr_conf3(_,[]) -> ok; +rewrite_target_addr_conf3(Fid,[{Name,Ip,Port,Timeout,Retry, + ParamName,EngineId}|T]) -> + ?LOG("rewrite_target_addr_conf3 -> write(1) ~s",[ParamName]), + io:format(Fid, + "{\"~s\", " % Name + "~p, " % Ip + "~p, " % Port + "~p, " % Timeout + "~p, " % Retry + "\"~s\", " % ParamsName + "\"~s\"}.", % EngineId + [Name,Ip,Port,Timeout,Retry,ParamName,EngineId]), + rewrite_target_addr_conf3(Fid,T); +rewrite_target_addr_conf3(Fid,[{Name,Ip,Port,Timeout,Retry,TagList, + ParamName,EngineId,TMask,MMS}|T]) -> + ?LOG("rewrite_target_addr_conf3 -> write(2) ~s",[ParamName]), + io:format(Fid, + "{\"~s\", " % Name + "~p, " % Ip + "~p, " % Port + "~p, " % Timeout + "~p, " % Retry + "\"~s\", " % TagList + "\"~s\", " % ParamsName + "\"~s\"," % EngineId + "~p, " % TMask + "~p}.", % MMS + [Name,Ip,Port,Timeout,Retry,TagList,ParamName, + EngineId,TMask,MMS]), + rewrite_target_addr_conf3(Fid,T). + +reset_target_addr_conf(Dir) -> + ?line ok = file:rename(filename:join(Dir,"target_addr.old"), + filename:join(Dir,"target_addr.conf")). + +write_target_params_conf(Dir, Vsns) -> + {ok, Fid} = file:open(filename:join(Dir,"target_params.conf"),write), + lists:foreach(fun(Vsn) -> + MP = if Vsn == v1 -> v1; + Vsn == v2 -> v2c; + Vsn == v3 -> v3 + end, + SM = if Vsn == v1 -> v1; + Vsn == v2 -> v2c; + Vsn == v3 -> usm + end, + ok = io:format(Fid, "{\"target_~w\", ~w, ~w, " + "\"all-rights\", noAuthNoPriv}.~n", + [Vsn, MP, SM]) + end, + Vsns), + file:close(Fid). + +rewrite_target_params_conf(Dir, SecName, SecLevel) -> + ?line ok = file:rename(filename:join(Dir,"target_params.conf"), + filename:join(Dir,"target_params.old")), + ?line {ok, Fid} = file:open(filename:join(Dir,"target_params.conf"),write), + ?line ok = io:format(Fid, "{\"target_v3\", v3, usm, \"~s\", ~w}.~n", + [SecName, SecLevel]), + file:close(Fid). + +reset_target_params_conf(Dir) -> + ?line ok = file:rename(filename:join(Dir,"target_params.old"), + filename:join(Dir,"target_params.conf")). + +write_notify_conf(Dir) -> + {ok, Fid} = file:open(filename:join(Dir,"notify.conf"),write), + ok = io:format(Fid, "{\"standard trap\", \"std_trap\", trap}.~n", []), + ok = io:format(Fid, "{\"standard inform\", \"std_inform\",inform}.~n", []), + file:close(Fid). + +ver_to_trap_str([v1]) -> "v1"; +ver_to_trap_str([v2]) -> "v2"; +% default is to use the latest snmp version +ver_to_trap_str([v1,v2]) -> "v2". + + + +write_view_conf(Dir) -> + {ok, Fid} = file:open(a(Dir,"view.conf"),write), + ok = io:format(Fid, "{2, [1,3,6], included, null}.~n", []), + ok = io:format(Fid, "{2, ~w, excluded, null}.~n", [?tDescr_instance]), + file:close(Fid). + +a(A,B) -> lists:append(A,B). + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +copy_file(From, To) -> + {ok, Bin} = file:read_file(From), + ok = file:write_file(To, Bin). + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +display_memory_usage() -> + Info = snmpa:info(snmp_master_agent), + TreeSize = lists_key1search(tree_size_bytes, Info), + ProcMem = lists_key1search(process_memory, Info), + MibDbSize = lists_key1search([db_memory,mib], Info), + NodeDbSize = lists_key1search([db_memory,node], Info), + TreeDbSize = lists_key1search([db_memory,tree], Info), + ?INF("Memory usage: " + "~n Tree size: ~p" + "~n Process memory size: ~p" + "~n Mib db size: ~p" + "~n Node db size: ~p" + "~n Tree db size: ~p", + [TreeSize, ProcMem, MibDbSize, NodeDbSize, TreeDbSize]). + +lists_key1search([], Res) -> + Res; +lists_key1search([Key|Keys], List) when atom(Key), list(List) -> + case lists:keysearch(Key, 1, List) of + {value, {Key, Val}} -> + lists_key1search(Keys, Val); + false -> + undefined + end; +lists_key1search(Key, List) when atom(Key) -> + case lists:keysearch(Key, 1, List) of + {value, {Key, Val}} -> + Val; + false -> + undefined + end. + + +regs() -> + lists:sort(registered()). diff --git a/lib/snmp/test/exp/snmp_agent_v1_test.erl b/lib/snmp/test/exp/snmp_agent_v1_test.erl new file mode 100644 index 0000000000..737bb25cc3 --- /dev/null +++ b/lib/snmp/test/exp/snmp_agent_v1_test.erl @@ -0,0 +1,2673 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2005-2010. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% + +-module(snmp_agent_v1_test). + +%% TODO +%% * Test fault-tolerance (kill master etc) +%% + +-export([]). + +-define(application, snmp). + +-include_lib("kernel/include/file.hrl"). +-include("test_server.hrl"). +-include("snmp_test_lib.hrl"). +-define(SNMP_USE_V3, true). +-include_lib("snmp/include/snmp_types.hrl"). + + +-define(klas1, [1,3,6,1,2,1,7]). +-define(klas2, [1,3,6,1,2,1,9]). +-define(klas3, [1,3,6,1,2,1,8,1]). +-define(klas4, [1,3,6,1,2,1,8,4]). +-define(sa, [1,3,6,1,4,1,193,2]). +-define(system, [1,3,6,1,2,1,1]). +-define(snmp, [1,3,6,1,2,1,11]). +-define(snmpTraps, [1,3,6,1,6,3,1,1,5]). +-define(ericsson, [1,3,6,1,4,1,193]). +-define(testTrap, [1,3,6,1,2,1,15,0]). +-define(xDescr, [1,3,6,1,2,1,17,1]). +-define(xDescr2, [1,3,6,1,2,1,17,2]). + +-define(active, 1). +-define(notInService, 2). +-define(notReady, 3). +-define(createAndGo, 4). +-define(createAndWait, 5). +-define(destroy, 6). + +-define(TRAP_UDP, 5000). + +-define(tooBigStr, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"). + + +%% -- test manager defines -- +-define(MGR, snmp_test_mgr). +-define(GN(X), ?MGR:gn(X)). +-define(G(X), ?MGR:g(X)). +-define(S(X), ?MGR:s(X)). +-define(GB(X), ?MGR:gb(X)). +-define(SEND_BYTES(X), ?MGR:send_bytes(X)). + +%% -- agent test lib defines -- +-define(LIB, snmp_agent_test_lib). +-define(INIT_CASE(X), ?LIB:init_case(X)). +-define(TRY_TEST1(A), ?LIB:try_test(A)). +-define(TRY_TEST2(A, B), ?LIB:try_test(A, B)). +-define(TRY_TEST3(A, B, C), ?LIB:try_test(A, B, C)). +-define(START_SA(A, B, C), ?LIB:start_subagent(A, B, C)). +-define(STOP_SA(A), ?LIB:stop_subagent(A)). +-define(P1(C), ?LIB:p(C)). +-define(P2(F), ?LIB:p(F,[])). +-define(P3(F,A), ?LIB:p(F,A)). +-define(RPC(N, F, A), ?LIB:rpc(N, F, A)). + + +-define(v1_2(V1,V2), + case get(vsn) of + v1 -> V1; + _ -> V2 + end). + +-define(v1_2_3(V1,V2,V3), + case get(vsn) of + v1 -> V1; + v2 -> V2; + _ -> V3 + end). + +all(suite) -> {req, + [mnesia, distribution, + {local_slave_nodes, 2}, {time, 360}], + [{conf, init, cases(), finish}]}. + +init_per_testcase(_Case, Config) when list(Config) -> + Dog = ?t:timetrap(?t:minutes(6)), + [{watchdog, Dog}|Config]. + +end_per_testcase(_Case, Config) when list(Config) -> + Dog = ?config(watchdog, Config), + ?t:timetrap_cancel(Dog), + Config. + +cases() -> + [simple, + db_notify_client, + processing, + big, + big2, + %% implied, + loop_mib, + api, + subagent, + mnesia, + multiple_reqs, + sa_register, + v1_trap, + sa_error, + next_across_sa, + undo, + standard_mibs, + sparse_table, + cnt_64, + opaque, + %% opaque]. + + change_target_addr_config, + + reported_bugs, + tickets + ]. + + +init(Config) -> + init_all(Config), + init_v1(Config). + +finish(Config) -> + finish_v1(Config), + finish_all(Config). + +init_v1(Config) when list(Config) -> + ?line SaNode = ?config(snmp_sa, Config), + ?line create_tables(SaNode), + ?line AgentDir = ?config(agent_dir, Config), + ?line MgrDir = ?config(mgr_dir, Config), + ?line Ip = ?config(ip, Config), + ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v1} | start_v1_agent(Config)]. + +finish_v1(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + + +%%----------------------------------------------------------------- +%% This function takes care of the old OTP-SNMPEA-MIB. +%% Unfortunately, the testcases were written to use the data in the +%% internal tables, and these table are now obsolete and not used +%% by the agent. Therefore, we emulate them by using +%% OLD-SNMPEA-MIB, which uses the default impl. of all tables. +%% +%% These two rows must exist in intCommunityTable +%% {[147,214,36,45], "public", 2, readWrite}. +%% {[147,214,36,45], "standard trap", 2, read}. +%% (But with the manager's IP address) +%% +%%----------------------------------------------------------------- +init_old() -> + snmpa_local_db:table_create_row(intCommunityTable, + get(mip) ++ [6 | "public"], + {get(mip), "public", 2, 2}), + snmpa_local_db:table_create_row(intCommunityTable, + get(mip) ++ [13 | "standard trap"], + {get(mip), "standard trap", 2, 1}), + snmpa_local_db:variable_set(intAgentIpAddress, [127,0,0,1]). + + +%% ========================================================================= +%% +%% C A S E S +%% +%% ========================================================================= + +%% -- simple -- + +simple(suite) -> []; +simple(Config) when list(Config) -> + ?P1(simple), + ?INIT_CASE(Config), + + ?TRY_TEST1(simple_standard_test). + +simple_standard_test() -> + ?DBG("simple_standard_test -> entry",[]), + ?GN([[1,1]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]), + + ?GN([[1,3]]), + ?line expect(11, [{[sysDescr,0], "Erlang SNMP agent"}]), + + ?GN([[1,3,6]]), + ?line expect(12, [{[sysDescr,0], "Erlang SNMP agent"}]), + + ?GN([[1,3,6,1]]), + ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}]), + + ?GN([[1,3,6,1,2]]), + ?line expect(14, [{[sysDescr,0], "Erlang SNMP agent"}]), + + ?GN([[1,3,6,1,2,1]]), + ?line expect(15, [{[sysDescr,0], "Erlang SNMP agent"}]), + + ?GN([[1,3,6,1,2,1,1]]), + ?line expect(16, [{[sysDescr,0], "Erlang SNMP agent"}]), + + ?GN([[sysDescr]]), + ?line expect(17, [{[sysDescr,0], "Erlang SNMP agent"}]), + + ?G([[sysDescr,0]]), + ?line expect(2, [{[sysDescr,0], "Erlang SNMP agent"}]), + + ?G([[sysDescr]]), + ?line ?v1_2(expect(3, noSuchName, 1, any), + expect(3, [{[sysDescr], noSuchObject}])), + + ?G([[1,6,7,0]]), + ?line ?v1_2(expect(41, noSuchName, 1, any), + expect(3, [{[1,6,7,0], noSuchObject}])), + + ?GN([[1,13]]), + ?line ?v1_2(expect(4, noSuchName,1, any), + expect(4, [{[1,13], endOfMibView}])), + + ?S([{[sysLocation, 0], "new_value"}]), + ?line expect(5, [{[sysLocation, 0], "new_value"}]), + + ?G([[sysLocation, 0]]), + ?line expect(6, [{[sysLocation, 0], "new_value"}]), + + io:format("Testing noSuchName and badValue...~n"), + ?S([{[sysServices,0], 3}]), + ?line expect(61, ?v1_2(noSuchName, notWritable), 1, any), + + ?S([{[sysLocation, 0], i, 3}]), + ?line expect(62, ?v1_2(badValue, wrongType), 1, any), + ?DBG("simple_standard_test -> done",[]), + ok. + + +%% -- db_notify_client -- + +%% This is run in the agent node +db_notify_client(suite) -> []; +db_notify_client(Config) when list(Config) -> + ?P1(db_notify_client), + {SaNode, MgrNode, MibDir} = ?INIT_CASE(Config), + ?DBG("~n\tSaNode: ~p~n\tMgrNode: ~p~n\tMibDir: ~p", + [SaNode,MgrNode,MibDir]), + snmpa_local_db:register_notify_client(self(),?MODULE), + + %% This call (the manager) will issue to set operations, so + %% we expect to receive to notify(insert) calls. + ?TRY_TEST1(db_notify_client_test), + + ?DBG("await first notify",[]), + receive + {db_notify_test_reply,insert} -> ?DBG("first notify received",[]),ok + end, + + ?DBG("await second notify",[]), + receive + {db_notify_test_reply,insert} -> ?DBG("second notify received",[]),ok + end, + + snmpa_local_db:unregister_notify_client(self()). + + +%% This is run in the manager node +db_notify_client_test() -> + ?DBG("set first new sysLocation",[]), + ?S([{[sysLocation, 0], "new_value"}]), + ?line expect(5, [{[sysLocation, 0], "new_value"}]), + + ?DBG("set second new sysLocation",[]), + ?S([{[sysLocation, 0], "new_value"}]), + ?line expect(5, [{[sysLocation, 0], "new_value"}]). + +notify(Pid,What) -> + ?DBG("notify(~p,~p) -> called",[Pid,What]), + Pid ! {db_notify_test_reply,What}. + + +%% -- processing -- + +%% Req. Test2 +processing(suite) -> []; +processing(Config) when list(Config) -> + ?P1(processing), + ?INIT_CASE(Config), + + ?line load_master("Test2"), + ?TRY_TEST1(v1_proc), + ?line unload_master("Test2"). + +v1_proc() -> + ?DBG("v1_proc -> entry", []), + %% According to RFC1157. + %% Template:
: + v1_get_p(), + v1_get_next_p(), + v1_set_p(). + +v1_get_p() -> + %% 4.1.2:1 + ?G([[test2]]), + ?line expect(10, noSuchName, 1, [{[test2], 'NULL'}]), + ?G([[tDescr]]), + ?line expect(11, noSuchName, 1, [{[tDescr], 'NULL'}]), + ?G([[tDescr2,0]]), + ?line expect(12, noSuchName, 1, [{[tDescr2,0], 'NULL'}]), + ?G([[tDescr3,0]]), + ?line expect(131, noSuchName, 1, [{[tDescr3,0], 'NULL'}]), + ?G([[tDescr4,0]]), + ?line expect(132, noSuchName, 1, [{[tDescr4,0], 'NULL'}]), + ?G([[sysDescr, 0], [tDescr,0]]), % Outside mibview + ?line expect(14, noSuchName, 2, [{[sysDescr, 0], 'NULL'}, + {[tDescr,0], 'NULL'}]), + ?G([[sysDescr,3]]), + ?line expect(15, noSuchName, 1, [{[sysDescr, 3], 'NULL'}]), + + %% 4.1.2:2 + ?G([[tTable]]), + ?line expect(20, noSuchName, 1, [{[tTable], 'NULL'}]), + ?G([[tEntry]]), + ?line expect(21, noSuchName, 1, [{[tEntry], 'NULL'}]), + + %% 4.1.2:3 + ?G([[tTooBig, 0]]), + ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), + + %% 4.1.2:4 + ?G([[tGenErr1, 0]]), + ?line expect(40, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), + ?G([[tGenErr2, 0]]), + ?line expect(41, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), + ?G([[sysDescr, 0], [tGenErr3, 0]]), + ?line expect(42, genErr, 2, [{[sysDescr, 0], 'NULL'}, + {[tGenErr3, 0], 'NULL'}]). + +v1_get_next_p() -> + %% 4.1.3:1 + ?GN([[1,3,7,1]]), + ?line expect(10, noSuchName, 1, [{[1,3,7,1], 'NULL'}]), + + ?GN([[tDescr2]]), + ?line expect(11, tooBig, 0, any), + + %% 4.1.3:2 + ?GN([[tTooBig]]), + io:format("We currently don't handle tooBig correct!!!\n"), + %% ?line expect(20, tooBig, 0, [{[tTooBig], 'NULL'}]), + ?line expect(20, tooBig, 0, any), + + %% 4.1.3:3 + ?GN([[tGenErr1]]), + %% ?line expect(40, genErr, 1, [{[tGenErr1], 'NULL'}]), + ?line expect(40, genErr, 1, any), + + ?GN([[tGenErr2]]), + %% ?line expect(41, genErr, 1, [{[tGenErr2], 'NULL'}]), + ?line expect(41, genErr, 1, any), + + ?GN([[sysDescr], [tGenErr3]]), + %% ?line expect(42, genErr, 2, [{[sysDescr], 'NULL'}, + %% {[tGenErr3], 'NULL'}]). + ?line expect(42, genErr, 2, any). + +v1_set_p() -> + %% 4.1.5:1 + ?S([{[1,3,7,0], i, 4}]), + ?line expect(10, noSuchName, 1, [{[1,3,7,0], 4}]), + + ?S([{[tDescr,0], s, "outside mibview"}]), + ?line expect(11, noSuchName, 1, [{[tDescr,0], "outside mibview"}]), + + ?S([{[tDescr3,0], s, "read-only"}]), + ?line expect(12, noSuchName, 1, [{[tDescr3,0], "read-only"}]), + + ?S([{[tDescr3], s, "noSuchObject"}]), + ?line expect(13, noSuchName, 1, [{[tDescr3], "noSuchObject"}]), + + ?S([{[tDescr3,1], s, "noSuchInstance"}]), + ?line expect(14, noSuchName, 1, [{[tDescr3,1], "noSuchInstance"}]), + + ?S([{[tDescr2,0], s, "inconsistentName"}]), + ?line expect(15, noSuchName, 1, [{[tDescr2,0], "inconsistentName"}]), + + %% 4.1.5:2 + ?S([{[tDescr2, 0], i, 4}]), + ?line expect(20, badValue, 1, [{[tDescr2, 0], 4}]), + + ?S([{[tDescr2, 0], s, "badValue"}]), + ?line expect(21, badValue, 1, [{[tDescr2, 0], "badValue"}]), + + %% 4.1.5:3 + %% The standard is quite incorrect here. The resp pdu was too big. In + %% the resp pdu, we have the original vbs. In the tooBig pdu we still + %% have to original vbs => the tooBig pdu is too big as well!!! It + %% may not get it to the manager, unless the agent uses 'NULL' instead + %% of the std-like original value. + ?S([{[tTooBig, 0], s, ?tooBigStr}]), + %% according to std: + %% ?line expect(30, tooBig, 0, [{[tTooBig, 0], ?tooBigStr}]), + ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), + + %% 4.1.5:4 + ?S([{[tDescr2, 0], s, "is_set_ok_fail"}]), + ?line expect(40, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]), + + ?S([{[tDescr2, 0], s, "commit_fail"}]), + ?line expect(41, genErr, 1, [{[tDescr2, 0], "commit_fail"}]). + + +%% -- big -- + +big(suite) -> []; +big(Config) when list(Config) -> + ?P1(big), + {SaNode, _MgrNode, _MibDir} = ?INIT_CASE(Config), + + p("Starting subagent..."), + ?line pong = net_adm:ping(SaNode), + + ?line {ok, SA} = ?START_SA(SaNode, ?klas1, "Klas1"), + ?DBG("big -> SA: ~p", [SA]), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + + ?TRY_TEST1(big_test), + + ?line ?STOP_SA(SA), + ?line unload_master("OLD-SNMPEA-MIB"). + +%% Req: system group, OLD-SNMPEA-MIB, Klas1 +big_test() -> + ?DBG("big_test -> testing simple next/get/set @ master agent...",[]), + simple_standard_test(), + + ?DBG("big_test -> testing simple next/get/set @ subagent...",[]), + ?GN([[klas1]]), + ?line expect(1, [{[fname,0], ""}]), + + ?G([[fname,0]]), + ?line expect(2, [{[fname,0], ""}]), + + ?S([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + + ?G([[fname,0]]), + ?line expect(4, [{[fname,0], "test set"}]), + + ?DBG("big_test -> " + "testing next from last instance in master to subagent...",[]), + ?GN([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(5, [{[fname,0], "test set"}]), + + ?GN([[1,1], + [?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, + {[fname,0], "test set"}]), + ?S([{[fname,0], s, ""}]), + ?line expect(52, [{[fname,0], ""}]), + + table_test(), + + ?DBG("big_test -> adding one row in subagent table",[]), + _FTab = [friendsEntry], + ?S([{[friendsEntry, [2, 3]], s, "kompis3"}, + {[friendsEntry, [3, 3]], i, ?createAndGo}]), + ?line expect(6, [{[friendsEntry, [2, 3]], "kompis3"}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + + ?G([[friendsEntry, [2, 3]], + [friendsEntry, [3, 3]]]), + ?line expect(7, [{[friendsEntry, [2, 3]], "kompis3"}, + {[friendsEntry, [3, 3]], ?active}]), + + ?S([{[friendsEntry, [3, 3]], i, ?destroy}]), + ?line expect(8, [{[friendsEntry, [3, 3]], ?destroy}]), + + otp_1131(), + + ?DBG("big_test -> adding two rows in subagent table with special INDEX", + []), + ?S([{[kompissEntry, [1, 3]], s, "kompis3"}, + {[kompissEntry, [2, 3]], i, ?createAndGo}]), + ?line expect(9, [{[kompissEntry, [1, 3]], "kompis3"}, + {[kompissEntry, [2, 3]], ?createAndGo}]), + + ?G([[kompissEntry, [1, 3]], + [kompissEntry, [2, 3]]]), + ?line expect(10, [{[kompissEntry, [1, 3]], "kompis3"}, + {[kompissEntry, [2, 3]], ?active}]), + + ?GN([[kompissEntry, [1]], + [kompissEntry, [2]]]), + ?line expect(11, [{[kompissEntry, [1, 3]], "kompis3"}, + {[kompissEntry, [2, 3]], ?active}]), + + ?S([{[kompissEntry, [1, 2]], s, "kompis3"}, + {[kompissEntry, [2, 2]], i, ?createAndGo}]), + ?line expect(12, [{[kompissEntry, [1, 2]], "kompis3"}, + {[kompissEntry, [2, 2]], ?createAndGo}]), + + ?GN([[kompissEntry, [1, 1]], + [kompissEntry, [2, 1]]]), + ?line expect(13, [{[kompissEntry, [1, 2]], "kompis3"}, + {[kompissEntry, [2, 2]], ?active}]), + + ?S([{[kompissEntry, [2, 3]], i, ?destroy}]), + ?line expect(14, [{[kompissEntry, [2, 3]], ?destroy}]), + + ?S([{[kompissEntry, [2, 2]], i, ?destroy}]), + ?line expect(15, [{[kompissEntry, [2, 2]], ?destroy}]), + ?DBG("big_test -> done",[]), + ok. + + +%% Req. system group, Klas2, OLD-SNMPEA-MIB +big_test_2() -> + ?P1(big_test_2), + + ?P2("Testing simple next/get/set @ master agent (2)..."), + simple_standard_test(), + + p("Testing simple next/get/set @ subagent (2)..."), + ?GN([[klas2]]), + ?line expect(1, [{[fname2,0], ""}]), + + ?G([[fname2,0]]), + ?line expect(2, [{[fname2,0], ""}]), + + ?S([{[fname2,0], s, "test set"}]), + ?line expect(3, [{[fname2,0], "test set"}]), + + ?G([[fname2,0]]), + ?line expect(4, [{[fname2,0], "test set"}]), + + otp_1298(), + + ?P2("Testing next from last object in master to subagent (2)..."), + ?GN([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(5, [{[fname2,0], "test set"}]), + + ?GN([[1,1], + [?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, + {[fname2,0], "test set"}]), + + table_test(), + + ?P2("Adding one row in subagent table (2)"), + ?S([{[friendsEntry2, [2, 3]], s, "kompis3"}, + {[friendsEntry2, [3, 3]], i, ?createAndGo}]), + ?line expect(6, [{[friendsEntry2, [2, 3]], "kompis3"}, + {[friendsEntry2, [3, 3]], ?createAndGo}]), + + ?G([[friendsEntry2, [2, 3]], + [friendsEntry2, [3, 3]]]), + ?line expect(7, [{[friendsEntry2, [2, 3]], "kompis3"}, + {[friendsEntry2, [3, 3]], ?active}]), + + ?S([{[friendsEntry2, [3, 3]], i, ?destroy}]), + ?line expect(8, [{[friendsEntry2, [3, 3]], ?destroy}]), + + ?P2("Adding two rows in subagent table with special INDEX (2)"), + ?S([{[kompissEntry2, [1, 3]], s, "kompis3"}, + {[kompissEntry2, [2, 3]], i, ?createAndGo}]), + ?line expect(9, [{[kompissEntry2, [1, 3]], "kompis3"}, + {[kompissEntry2, [2, 3]], ?createAndGo}]), + ?G([[kompissEntry2, [1, 3]], + [kompissEntry2, [2, 3]]]), + ?line expect(10, [{[kompissEntry2, [1, 3]], "kompis3"}, + {[kompissEntry2, [2, 3]], ?active}]), + ?GN([[kompissEntry2, [1]], + [kompissEntry2, [2]]]), + ?line expect(11, [{[kompissEntry2, [1, 3]], "kompis3"}, + {[kompissEntry2, [2, 3]], ?active}]), + + ?S([{[kompissEntry2, [1, 2]], s, "kompis3"}, + {[kompissEntry2, [2, 2]], i, ?createAndGo}]), + ?line expect(12, [{[kompissEntry2, [1, 2]], "kompis3"}, + {[kompissEntry2, [2, 2]], ?createAndGo}]), + + ?GN([[kompissEntry2, [1, 1]], + [kompissEntry2, [2, 1]]]), + ?line expect(13, [{[kompissEntry2, [1, 2]], "kompis3"}, + {[kompissEntry2, [2, 2]], ?active}]), + + ?S([{[kompissEntry2, [2, 3]], i, ?destroy}]), + ?line expect(14, [{[kompissEntry2, [2, 3]], ?destroy}]), + + ?S([{[kompissEntry2, [2, 2]], i, ?destroy}]), + ?line expect(15, [{[kompissEntry2, [2, 2]], ?destroy}]), + ok. + + +%% -- bug2 -- + +big2(suite) -> []; +big2(Config) when list(Config) -> + ?P1(big2), + %% This is exactly the same tests as 'big', but with the + %% v2 equivalent of the mibs. + {SaNode, _MgrNode, _MibDir} = ?INIT_CASE(Config), + + ?P2("Starting subagent..."), + ?line pong = net_adm:ping(SaNode), + + ?line {ok, SA} = ?START_SA(SaNode, ?klas1, "Klas1-v2"), + ?line load_master("OLD-SNMPEA-MIB-v2"), + ?line init_old(), + + ?TRY_TEST1(big_test), + + ?line ?STOP_SUBAGENT(SA), + ?line unload_master("OLD-SNMPEA-MIB-v2"). + + +implied(suite) -> []; +implied(Config) when list(Config) -> + ?P1(implied), + ?INIT_CASE(Config), + + ?line load_master("Test1"), + + ?TRY_TEST2(implied_test,[whereis(snmp_master_agent)]), + + ?line unload_master("Test1"). + +%% Req. Test1 +implied_test(MA) -> + ?LOG("implied_test -> start",[]), + + snmpa:verbosity(MA,trace), + snmpa:verbosity(MA,trace), + + %% Create two rows, check that they are get-nexted in correct order. + Idx1 = "apa", + Idx2 = "qq", + + ?DBG("implied_test -> (send) create row 1 '~s' in table 1",[Idx1]), + ?S([{[testStatus, Idx1], i, ?createAndGo}, {[testDescr, Idx1],s,"row 1"}]), + ?line expect(1, [{[testStatus, Idx1], ?createAndGo}, + {[testDescr, Idx1], "row 1"}]), + ?DBG("implied_test -> (send) create row 2 '~s' in table 1",[Idx2]), + + ?S([{[testStatus, Idx2], i, ?createAndGo}, {[testDescr, Idx2],s,"row 2"}]), + ?line expect(2, [{[testStatus, Idx2], ?createAndGo}, + {[testDescr, Idx2], "row 2"}]), + ?DBG("implied_test -> get-next(testDescr)",[]), + + ?GN([[testDescr]]), + ?line expect(3, [{[testDescr,Idx1], "row 1"}]), + ?DBG("implied_test -> get-next(testDescr) of row 1",[]), + + ?GN([[testDescr,Idx1]]), + ?line expect(4, [{[testDescr,Idx2], "row 2"}]), + + % Delete the rows + ?DBG("implied_test -> (send) delete row 1 '~s' from table 1",[Idx1]), + ?S([{[testStatus, Idx1], i, ?destroy}]), + ?line expect(5, [{[testStatus, Idx1], ?destroy}]), + + ?DBG("implied_test -> (send) delete row 2 '~s' from table 1",[Idx2]), + ?S([{[testStatus, Idx2], i, ?destroy}]), + ?line expect(6, [{[testStatus, Idx2], ?destroy}]), + + %% Try the same in other table + Idx3 = [1, "apa"], + Idx4 = [1, "qq"], + ?DBG("implied_test -> (send) create row 1 '~s' in table 2",[Idx3]), + ?S([{[testStatus2, Idx3], i, ?createAndGo}, {[testDescr2,Idx3],s,"row 1"}]), + ?line expect(1, [{[testStatus2, Idx3], ?createAndGo}, + {[testDescr2, Idx3], "row 1"}]), + + ?DBG("implied_test -> (send) create row 2 '~s' in table 2",[Idx4]), + ?S([{[testStatus2, Idx4], i, ?createAndGo}, + {[testDescr2,Idx4],s,"row 2"}]), + ?line expect(2, [{[testStatus2, Idx4], ?createAndGo}, + {[testDescr2, Idx4], "row 2"}]), + + ?DBG("implied_test -> get-next(testDescr2)",[]), + ?GN([[testDescr2]]), + ?line expect(3, [{[testDescr2,Idx3], "row 1"}]), + ?DBG("implied_test -> get-next(testDescr2) of row 1",[]), + + ?GN([[testDescr2,Idx3]]), + ?line expect(4, [{[testDescr2,Idx4], "row 2"}]), + + % Delete the rows + ?DBG("implied_test -> (send) delete row 1 '~s' from table 2",[Idx3]), + ?S([{[testStatus2, Idx3], i, ?destroy}]), + ?line expect(5, [{[testStatus2, Idx3], ?destroy}]), + + ?DBG("implied_test -> (send) delete row 2 '~s' from table 2",[Idx4]), + ?S([{[testStatus2, Idx4], i, ?destroy}]), + ?line expect(6, [{[testStatus2, Idx4], ?destroy}]), + + snmpa:verbosity(MA,log), + + ?LOG("implied_test -> done",[]). + + +%% -- loop_mib -- + +%%----------------------------------------------------------------- +%% Loop through entire MIB, to make sure that all instrum. funcs +%% works. +%% Load all std mibs that are not loaded by default. +%%----------------------------------------------------------------- +loop_mib(suite) -> []; +loop_mib(Config) when list(Config) -> + ?P1(loop_mib), + %% snmpa:verbosity(master_agent,debug), + %% snmpa:verbosity(mib_server,info), + {SaNode, MgrNode, MibDir} = ?INIT_CASE(Config), + ?DBG("loop_mib -> " + "~n SaNode: ~p" + "~n MgrNode: ~p" + "~n MibDir: ~p", [SaNode, MgrNode, MibDir]), + + ?DBG("loop_mib -> load mib SNMP-COMMUNITY-MIB",[]), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?DBG("loop_mib -> load mib SNMP-MPD-MIB",[]), + ?line load_master_std("SNMP-MPD-MIB"), + ?DBG("loop_mib -> load mib SNMP-TARGET-MIB",[]), + ?line load_master_std("SNMP-TARGET-MIB"), + ?DBG("loop_mib -> load mib SNMP-NOTIFICATION-MIB",[]), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?DBG("loop_mib -> load mib SNMP-FRAMEWORK-MIB",[]), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?DBG("loop_mib -> load mib SNMP-VIEW-BASED-ACM-MIB",[]), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + ?DBG("loop_mib -> try",[]), + + ?TRY_TEST1(loop_mib), + + ?DBG("loop_mib -> unload mib SNMP-COMMUNITY-MIB",[]), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?DBG("loop_mib -> unload mib SNMP-MPD-MIB",[]), + ?line unload_master("SNMP-MPD-MIB"), + ?DBG("loop_mib -> unload mib SNMP-TARGET-MIB",[]), + ?line unload_master("SNMP-TARGET-MIB"), + ?DBG("loop_mib -> unload mib SNMP-NOTIFICATION-MIB",[]), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?DBG("loop_mib -> unload mib SNMP-FRAMEWORK-MIB",[]), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?DBG("loop_mib -> unload mib SNMP-VIEW-BASED-ACM-MIB",[]), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + %% snmpa:verbosity(master_agent,log), + %% snmpa:verbosity(mib_server,silence), + ?LOG("loop_mib -> done",[]). + +%% Req. As many mibs all possible +loop_mib() -> + ?DBG("loop_mib -> entry",[]), + N = loop_it([1,1], 0), + ?P3("found ~w varibles\n", [N]), + ?line N = if N < 100 -> 100; + true -> N + end. + +loop_it(Oid, N) -> + ?DBG("loop_it -> entry with" + "~n Oid: ~p" + "~n N: ~p", [Oid,N]), + case get_next_req([Oid]) of + #pdu{type='get-response', error_status=noError, error_index=0, + varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> + ?DBG("loop_it -> " + "~n NOid: ~p" + "~n Value: ~p",[NOid,Value]), + ?line [Value2] = get_req(1, [NOid]), % must not be same + ?DBG("loop_it_1 -> " + "~n Value2: ~p",[Value2]), + loop_it(NOid, N+1); + + #pdu{type='get-response', error_status=noSuchName, error_index=1, + varbinds=[_]} -> + ?DBG("loop_it -> done",[]), + N; + + #pdu{type = Type, error_status = Err, error_index = Idx, + varbinds = Vbs} -> + exit({unexpected_pdu, ?LINE, Type, Err, Idx, Vbs}) + + end. + + +%% -- api -- + +api(suite) -> []; +api(Config) when list(Config) -> + ?P1(api), + ?INIY_CASE(Config), + + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + + ?TRY_TEST2(api_test, [node()]), + + ?line unload_master("OLD-SNMPEA-MIB"). + +%% Req. OLD-SNMPEA-MIB +api_test(MaNode) -> + ?line {value, OID} = ?RPC(MaNode, name_to_oid, [intAgentIpAddress]), + ?line {value, intAgentIpAddress} = ?RPC(MaNode, oid_to_name, [OID]), + ?line false = ?RPC(MaNode, name_to_oid, [intAgentIpAddres]), + ?line false = ?RPC(MaNode, oid_to_name, [[1,5,32,3,54,3,3,34,4]]), + ?line {value, 2} = ?RPC(MaNode, enum_to_int, [intViewType, excluded]), + ?line {value, excluded} = ?RPC(MaNode, int_to_enum, [intViewType, 2]), + ?line false = ?RPC(MaNode, enum_to_int, [intViewType, exclude]), + ?line false = ?RPC(MaNode, enum_to_int, [intAgentIpAddress, exclude]), + ?line false = ?RPC(MaNode, enum_to_int, [intAgentIpAddre, exclude]), + ?line false = ?RPC(MaNode, int_to_enum, [intViewType, 3]), + ?line false = ?RPC(MaNode, int_to_enum, [intAgentIpAddress, 2]), + ?line false = ?RPC(MaNode, int_to_enum, [intAgentIpAddre, 2]), + ?line {value, active} = ?RPC(MaNode, int_to_enum, ['RowStatus', ?active]), + ?line {value, ?destroy} = + ?RPC(MaNode, enum_to_int, ['RowStatus', destroy]), + ?line false = ?RPC(MaNode, enum_to_int, ['RowStatus', xxxdestroy]), + ?line false = ?RPC(MaNode, enum_to_int, ['xxRowStatus', destroy]), + ?line false = ?RPC(MaNode, int_to_enum, ['RowStatus', 25]), + ?line false = ?RPC(MaNode, int_to_enum, ['xxRowStatus', 1]), + ?line case snmp:date_and_time() of + List when list(List), length(List) == 8 -> ok; + List when list(List), length(List) == 11 -> ok + end. + + +%% -- subagent -- + +subagent(suite) -> []; +subagent(Config) when list(Config) -> + ?P1(subagent), + {SaNode, _MgrNode, MibDir} = ?INIT_CASE(Config), + + ?line {ok, SA} = ?START_SA(SaNode, ?klas1, "Klas1"), + + ?TRY_TEST1(load_test_sa), + + ?P2("Testing unregister subagent [~w]...", [SA]), + MA = whereis(snmp_master_agent), + ?RPC(SaNode, unregister_subagent, [MA, SA]), + ?TRY_TEST1(unreg_test), + + ?P2("Loading previous subagent mib in master and testing..."), + ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas1"]), + ?TRY_TEST1(load_test), + + ?P2("Unloading previous subagent mib in master and testing..."), + ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas1"]), + + ?TRY_TEST1(unreg_test), + + ?P2("Testing register subagent..."), + ?RPC(SaNode, register_subagent, [MA, ?klas1, SA]), + ?TRY_TEST1(load_test_sa), + + ?line ?STOP_SA(SA), + ?TRY_TEST1(unreg_test). + +%% Req. Klas1 +load_test_sa() -> + ?GN([[?v1_2(sysServices,sysORLastChange), 0]]), + ?line expect(1, [{[fname,0], any}]). + +unreg_test() -> + ?GN([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(1, [{[snmpInPkts, 0], any}]). + +load_test() -> + ?GN([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(1, [{[fname,0], ""}]). + + +%% -- mnesia -- + +mnesia(suite) -> []; +mnesia(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Starting subagent with mnesia impl..."), + {ok, SA} = start_subagent(SaNode, ?klas2, "Klas2"), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + + ?TRY_TEST1(big_test_2), + + p("Testing unregister subagent..."), + MA = whereis(snmp_master_agent), + rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), + ?TRY_TEST1(unreg_test), + ?line unload_master("OLD-SNMPEA-MIB"), + ?line stop_subagent(SA). + + +%% -- multiple_reqs -- + +multiple_reqs(suite) -> + {req, [], {conf, init_mul, mul_cases(), finish_mul}}. + +mul_cases() -> + [mul_get, mul_get_err, mul_next, mul_next_err, mul_set_err]. + +init_mul(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + [{mul_sub, SA} | Config]. + +finish_mul(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + SA = ?config(mul_sub, Config), + + ?line unload_master("OLD-SNMPEA-MIB"), + ?line stop_subagent(SA), + lists:keydelete(mul_sub, 1, Config). + + +%% -- mul_get -- + +mul_get(suite) -> []; +mul_get(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple get..."), + ?TRY_TEST1(do_mul_get). + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_get() -> + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + g([[sysDescr,0], Key1c4, [fname,0],Key1c3, + [sysName,0]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[fname,0], "test set"}, + {Key1c3, 2}, + {[sysName,0], "test"}]), + g([[1,3,7,1], Key1c4, [sysDescr,0], [1,3,7,2], Key1c3, [sysDescr,0]]), + ?line ?v1_2(expect(2, noSuchName, [1,4], any), + expect(2, [{[1,3,7,1], noSuchObject}, + {Key1c4, 2}, + {[sysDescr,0], "Erlang SNMP agent"}, + {[1,3,7,2], noSuchObject}, + {Key1c3, 2}, + {[sysDescr,0], "Erlang SNMP agent"}])). + + +%% -- mul_get_err -- + +mul_get_err(suite) -> []; +mul_get_err(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple get with error..."), + ?TRY_TEST1(do_mul_get_err). + +%% Req. v1, system group, Klas1, OLD-SNMPEA-MIB, *ej* Klas3. +do_mul_get_err() -> + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + g([[sysDescr,0],Key1c4,[fname,0], Key1c3, [sysName,2]]), + ?line ?v1_2(expect(1, noSuchName, 5, any), + expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[fname,0], "test set"}, + {Key1c3, 2}, + {[sysName,2], noSuchInstance}])), + g([[sysDescr,0],Key1c4,[fname3,0], Key1c3, [sysName,1]]), + ?line ?v1_2(expect(1, noSuchName, [3,5], any), + expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[fname3,0], noSuchObject}, + {Key1c3, 2}, + {[sysName,1], noSuchInstance}])). + + +%% -- mul_next -- + +mul_next(suite) -> []; +mul_next(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple next..."), + ?TRY_TEST1(do_mul_next). + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_next() -> + Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], + Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + gn([[sysDescr], Key1c4s, [fname],Key1c3s,[sysName]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, {[fname,0], "test set"}, + {Key1c3, 2}, {[sysName,0], "test"}]). + + +%% -- mul_next_err -- + +mul_next_err(suite) -> []; +mul_next_err(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple next..."), + ?TRY_TEST1(do_mul_next_err). + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_next_err() -> + Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], + Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + gn([[sysDescr], Key1c4s, [1,3,6,999], [fname],[1,3,90], Key1c3s,[sysName]]), + ?line ?v1_2(expect(1, noSuchName, [3,5], any), + expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[1,3,6,999], endOfMibView}, + {[fname,0], "test set"}, + {[1,3,90], endOfMibView}, + {Key1c3, 2}, + {[sysName,0], "test"}])). + + +%% -- mul_set -- + +mul_set(suite) -> []; +mul_set(Config) when list(Config) -> + ?P(mul_set), + ?INIT_CASE(Config), + + ?TRY_TEST1(do_mul_set). + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_set() -> + p("Adding one row in subagent table, and one in master table"), + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + s([{[friendsEntry, [2, 3]], "kompis3"}, + {NewKeyc3, 2}, + {[sysLocation,0], "new_value"}, + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + ?line expect(1, [{[friendsEntry, [2, 3]], "kompis3"}, + {NewKeyc3, 2}, + {[sysLocation,0], "new_value"}, + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + g([[friendsEntry, [2, 3]], + [sysLocation,0], + [friendsEntry, [3, 3]]]), + ?line expect(2, [{[friendsEntry, [2, 3]], "kompis3"}, + {[sysLocation,0], "new_value"}, + {[friendsEntry, [3, 3]], ?active}]), + g([NewKeyc4]), + ?line expect(3, [{NewKeyc4, 2}]), + s([{[friendsEntry, [3, 3]], ?destroy}, + {NewKeyc5, ?destroy}]), + ?line expect(4, [{[friendsEntry, [3, 3]], ?destroy}, + {NewKeyc5, ?destroy}]). + + +%% -- mul_set_err -- + +mul_set_err(suite) -> []; +mul_set_err(Config) when list(Config) -> + ?P(mul_set_err), + ?INIT_CASE(Config), + + ?TRY_TEST1(do_mul_set_err). + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_set_err() -> + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + p("Adding one row in subagent table, and one in master table"), + s([{[friendsEntry, [2, 3]], s, "kompis3"}, + {NewKeyc3, 2}, + {[sysUpTime,0], 45}, % sysUpTime (readOnly) + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + ?line expect(1, ?v1_2(noSuchName, notWritable), 3, any), + g([[friendsEntry, [2, 3]]]), + ?line ?v1_2(expect(2, noSuchName, 1, any), + expect(2, [{[friendsEntry, [2,3]], noSuchInstance}])), + g([NewKeyc4]), + ?line ?v1_2(expect(3, noSuchName, 1, any), + expect(3, [{NewKeyc4, noSuchInstance}])). + + +%% -- sa_register -- + +sa_register(suite) -> []; +sa_register(Config) when list(Config) -> + ?P1(sa_register), + {SaNode, _MgrNode, MibDir} = ?INIT_CASE(Config), + + ?DBG("sa_register -> start subagent", []), + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), + + ?DBG("sa_register -> unregister subagent", []), + ?P2("Testing unregister subagent (2)..."), + MA = whereis(snmp_master_agent), + rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), + ?TRY_TEST1(unreg_test), + + ?P2("Loading SA-MIB..."), + ?DBG("sa_register -> unload mibs", []), + snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), + ?DBG("sa_register -> unload mibs", []), + snmpa:load_mibs(SA, [MibDir ++ "SA-MIB"]), + ?DBG("sa_register -> register subagent", []), + rpc:call(SaNode, snmp, register_subagent, [MA,?sa,SA]), + ?TRY_TEST1(sa_mib), + + ?DBG("sa_register -> stop subagent", []), + ?line stop_subagent(SA). + +%% Req. SA-MIB +sa_mib() -> + g([[sa, [2,0]]]), + ?line expect(1, [{[sa, [2,0]], 3}]), + s([{[sa, [1,0]], s, "sa_test"}]), + ?line expect(2, [{[sa, [1,0]], "sa_test"}]). + + +%% -- v1_trap -- + +v1_trap(suite) -> []; +v1_trap(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Testing trap sending from master agent..."), + MA = whereis(snmp_master_agent), + + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + ?TRY_TEST2(ma_trap1, [MA]), + ?TRY_TEST2(ma_trap2, [MA]), + ?TRY_TEST2(ma_v2_2_v1_trap, [MA]), + ?TRY_TEST2(ma_v2_2_v1_trap2, [MA]), + + p("Testing trap sending from subagent..."), + ?TRY_TEST2(sa_trap1, [SA]), + ?TRY_TEST2(sa_trap2, [SA]), + ?TRY_TEST2(sa_trap3, [SA]), + + ?line unload_master("TestTrap"), + ?line unload_master("TestTrapv2"), + + ?line stop_subagent(SA). + +ma_trap1(MA) -> + snmpa:send_trap(MA, testTrap2, "standard trap"), + ?line expect(1, trap, [system], 6, 1, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}]), + snmpa:send_trap(MA, testTrap1, "standard trap"), + ?line expect(2, trap, [1,2,3] , 1, 0, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}]). + +ma_trap2(MA) -> + snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). + +ma_v2_2_v1_trap(MA) -> + snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). + +ma_v2_2_v1_trap2(MA) -> + snmpa:send_trap(MA,linkUp,"standard trap",[{ifIndex, [1], 1}, + {ifAdminStatus, [1], 1}, + {ifOperStatus, [1], 2}]), + ?line expect(3, trap, [1,2,3], 3, 0, [{[ifIndex, 1], 1}, + {[ifAdminStatus, 1], 1}, + {[ifOperStatus, 1], 2}]). + +sa_trap1(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap"), + ?line expect(4, trap, [ericsson], 6, 1, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}]). + +sa_trap2(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), + ?line expect(5, trap, [ericsson], 6, 1, [{[system, [4,0]], + "pelle"}, + {[sa, [1,0]], "sa_test"}]). + +sa_trap3(SA) -> + snmpa:send_trap(SA, saTrap2, "standard trap", + [{intViewSubtree, [4], [1,2,3,4]}]), + ?line expect(6, trap, [ericsson], 6, 2, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}, + {[intViewSubtree,4],[1,2,3,4]}]). + +ma_v2_trap1(MA) -> + ?DBG("ma_v2_traps -> entry with MA = ~p => " + "send standard trap: testTrapv22",[MA]), + snmpa:send_trap(MA, testTrapv22, "standard trap"), + ?line expect(1, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + ?DBG("ma_v2_traps -> send standard trap: testTrapv21",[]), + snmpa:send_trap(MA, testTrapv21, "standard trap"), + ?line expect(2, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?snmp ++ [1]}]). + +ma_v2_trap2(MA) -> + snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}, + {[system, [4,0]], "pelle"}]). + +ma_v1_2_v2_trap(MA) -> + snmpa:send_trap(MA,linkDown,"standard trap",[{ifIndex, [1], 1}]), + ?line expect(2, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?snmpTraps ++ [3]}, + {[ifIndex, 1], 1}, + {[snmpTrapEnterprise, 0], [1,2,3]}]). + + +ma_v1_2_v2_trap2(MA) -> + snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}, + {[system, [4,0]], "pelle"}, + {[snmpTrapEnterprise, 0], ?system}]). + + +sa_v1_2_v2_trap1(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap"), + ?line expect(4, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, + {[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}, + {[snmpTrapEnterprise, 0], ?ericsson}]). + +sa_v1_2_v2_trap2(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), + ?line expect(4, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, + {[system, [4,0]], "pelle"}, + {[sa, [1,0]], "sa_test"}, + {[snmpTrapEnterprise, 0], ?ericsson}]). + + +sa_v1_2_v2_trap3(SA) -> + snmpa:send_trap(SA, saTrap2, "standard trap", + [{intViewSubtree, [4], [1,2,3,4]}]), + ?line expect(4, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?ericsson ++ [0, 2]}, + {[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}, + {[intViewSubtree,4],[1,2,3,4]}, + {[snmpTrapEnterprise, 0], ?ericsson}]). + + +%% -- sa_error -- + +sa_error(suite) -> []; +sa_error(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Testing sa bad value (is_set_ok)..."), + ?TRY_TEST1(sa_errs_bad_value), + + p("Testing sa gen err (set)..."), + ?TRY_TEST1(sa_errs_gen_err), + + p("Testing too big..."), + ?TRY_TEST1(sa_too_big), + + ?line unload_master("OLD-SNMPEA-MIB"), + stop_subagent(SA). + +%% Req. SA-MIB, OLD-SNMPEA-MIB +sa_errs_bad_value() -> + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + s([{NewKeyc3, 2}, + {[sa, [2,0]], 5}, % badValue (i is_set_ok) + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}]), + ?line expect(1, badValue, 2, any), + s([{NewKeyc3, 2}, + {[sa, [2,0]], 6}, % wrongValue (i is_set_ok) + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}]), + ?line expect(1, ?v1_2(badValue, wrongValue), 2, any), + g([NewKeyc4]), + ?line ?v1_2(expect(2, noSuchName, 1, any), + expect(2, [{NewKeyc4, noSuchInstance}])). + +%% Req. SA-MIB, OLD-SNMPEA-MIB +sa_errs_gen_err() -> + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + s([{NewKeyc3, 2},{NewKeyc4, 2}, + {NewKeyc5, ?createAndGo}, {[sa, [3,0]], 5}]), + ?line expect(1, genErr, 4, any), +% The row might have been added; we don't know. +% (as a matter of fact we do - it is added, because the agent +% first sets its own vars, and then th SAs. Lets destroy it. + s([{NewKeyc5, ?destroy}]), + ?line expect(2, [{NewKeyc5, ?destroy}]). + +%% Req. SA-MIB, OLD-SNMPEA-MIB +sa_too_big() -> + g([[sa, [4,0]]]), + ?line expect(1, tooBig). + + +%% -- next_across_sa -- + +next_across_sa(suite) -> []; +next_across_sa(Config) when list(Config) -> + {SaNode, _MgrNode, MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Loading another subagent mib..."), + ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas1"]), + + rpc:call(SaNode, snmp, register_subagent, [MA, ?klas1, SA]), + ?TRY_TEST1(load_test_sa), + + p("Testing next across subagent (endOfMibView from SA)..."), + ?TRY_TEST1(next_across_sa), + + p("Unloading mib"), + snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), + rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), + ?TRY_TEST1(unreg_test), + + p("Starting another subagent"), + ?line {ok, SA2} = start_subagent(SaNode, ?klas1, "Klas1"), + p("Testing next across subagent (wrong prefix from SA)..."), + ?TRY_TEST1(next_across_sa), + + stop_subagent(SA), + stop_subagent(SA2). + +%% Req. Klas1, system group, snmp group (v1/v2) +next_across_sa() -> + gn([[sysDescr],[klas1,5]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {[snmpInPkts, 0], any}]). + + +%% -- undo -- + +undo(suite) -> []; +undo(Config) when list(Config) -> + {SaNode, _MgrNode, MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Testing undo phase at master agent..."), + ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas3"]), + ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas4"]), + ?TRY_TEST1(undo_test), + ?TRY_TEST1(api_test2), + ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas3"]), + + p("Testing bad return values from instrum. funcs..."), + ?TRY_TEST1(bad_return), + + ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas4"]), + + p("Testing undo phase at subagent..."), + ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas3"]), + ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas4"]), + ?line ok = snmpa:register_subagent(MA, ?klas3, SA), + ?line ok = snmpa:register_subagent(MA, ?klas4, SA), + ?TRY_TEST1(undo_test), + ?TRY_TEST1(api_test3), + + p("Testing undo phase across master/subagents..."), + ?TRY_TEST1(undo_test), + ?TRY_TEST1(api_test3), + stop_subagent(SA). + +%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]). -> noError +%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]). -> {badValue, 2} +%% snmp_test_mgr:s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]). -> {genErr, 1} +%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]). -> {genErr, 1} +%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]). -> {genErr, 1} +%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]). -> {genErr, 2} +%% Req. Klas3, Klas4 +undo_test() -> + s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), + ?line expect(1, [{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), + s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]), + ?line expect(2, ?v1_2(badValue, inconsistentValue), 2, any), + s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]), + ?line expect(3, ?v1_2(genErr, undoFailed), 1, any), + s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]), + ?line expect(4, ?v1_2(genErr, commitFailed), 1, any), + %% unfortunatly we don't know if we'll get undoFailed or commitFailed. + %% it depends on which order the agent traverses the varbind list. + %% s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]), + %% ?line expect(5, ?v1_2(genErr, undoFailed), 1, any), + s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]), + ?line expect(6, genErr, 2, any). + +%% Req. Klas3, Klas4 +bad_return() -> + g([[fStatus4,4], + [fName4,4]]), + ?line expect(4, genErr, 2, any), + g([[fStatus4,5], + [fName4,5]]), + ?line expect(5, genErr, 1, any), + g([[fStatus4,6], + [fName4,6]]), + ?line expect(6, genErr, 2, any), + gn([[fStatus4,7], + [fName4,7]]), + ?line expect(7, genErr, 2, any), + gn([[fStatus4,8], + [fName4,8]]), + ?line expect(8, genErr, 1, any), + gn([[fStatus4,9], + [fName4,9]]), + ?line expect(9, genErr, 2, any). + + +%% -- standard_mibs -- + +%%%----------------------------------------------------------------- +%%% Test the implementation of standard mibs. +%%% We should *at least* try to GET all variables, just to make +%%% sure the instrumentation functions work. +%%% Note that many of the functions in the standard mib is +%%% already tested by the normal tests. +%%%----------------------------------------------------------------- +standard_mibs(suite) -> + [snmp_standard_mib, + snmp_community_mib, + snmp_framework_mib, + snmp_target_mib, + snmp_notification_mib, + snmp_view_based_acm_mib]. + + +%% -- snmp_standard_mib -- + +%%----------------------------------------------------------------- +%% For this test, the agent is configured for v1. +%% o Test the counters and control objects in SNMP-STANDARD-MIB +%%----------------------------------------------------------------- +snmp_standard_mib(suite) -> []; +snmp_standard_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?DBG("snmp_standard_mib -> std_mib_init", []), + ?TRY_TEST1(std_mib_init), + + ?DBG("snmp_standard_mib -> std_mib_a", []), + InBadVsns = ?TRY_TEST1(std_mib_a), + put(vsn, v2), + ?DBG("snmp_standard_mib -> std_mib_read", []), + ?TRY_TEST1(std_mib_read), + put(vsn, v1), + + ?DBG("snmp_standard_mib -> std_mib_b (~w)", [InBadVsns]), + Bad = ?TRY_TEST2(std_mib_b, [InBadVsns]), + ?DBG("snmp_standard_mib -> std_mib_read (community: 'bad community')", []), + ?TRY_TEST3(std_mib_read, [], [{community, "bad community"}]), + ?DBG("snmp_standard_mib -> std_mib_write (community: 'public')", []), + ?TRY_TEST3(std_mib_write, [], [{community, "public"}]), + ?DBG("snmp_standard_mib -> std_mib_asn_err", []), + ?TRY_TEST1(std_mib_asn_err), + ?DBG("snmp_standard_mib -> std_mib_c (~w)", [Bad]), + ?TRY_TEST2(std_mib_c, [Bad]), + ?DBG("snmp_standard_mib -> std_mib_a", []), + ?TRY_TEST1(standard_mib_a), + + ?DBG("snmp_standard_mib -> std_mib_finish", []), + ?TRY_TEST1(std_mib_finish), + ?DBG("snmp_standard_mib -> std_mib_test_finish", []), + ?TRY_TEST3(standard_mib_test_finish, [], [{community, "bad community"}]). + +%% Req. SNMP-STANDARD-MIB +standard_mib_a() -> + ?line [OutPkts] = get_req(2, [[snmpOutPkts,0]]), + ?line [OutPkts2] = get_req(3, [[snmpOutPkts,0]]), + ?line OutPkts2 = OutPkts + 1, + %% There are some more counters we could test here, but it's not that + %% important, since they are removed from SNMPv2-MIB. + ok. + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_init() -> + %% disable authentication failure traps. (otherwise w'd get many of + %% them - this is also a test to see that it works). + s([{[snmpEnableAuthenTraps,0], 2}]), + ?line expect(1, [{[snmpEnableAuthenTraps, 0], 2}]). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_finish() -> + %% enable again + s([{[snmpEnableAuthenTraps,0], 1}]), + ?line expect(1, [{[snmpEnableAuthenTraps, 0], 1}]). + +%% Req. SNMP-STANDARD-MIB +standard_mib_test_finish() -> + %% force a authenticationFailure + std_mib_write(), + %% check that we got a trap + ?line expect(2, trap, [1,2,3], 4, 0, []). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_read() -> + ?DBG("std_mib_read -> entry", []), + g([[sysUpTime,0]]), % try a bad ; msg dropped, no reply + ?DBG("std_mib_read -> await timeout (i.e. no reply)", []), + ?line expect(1, timeout). % make sure we don't get a trap! + + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_write() -> + ?DBG("std_mib_write -> entry", []), + s([{[sysLocation, 0], "new_value"}]). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_asn_err() -> + ?SEND_BYTES([48,99,67,12,0,0,0,0,0,0,5]). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_a() -> + ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), + ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), + ?line InPkts2 = InPkts + 1, + + ?line [InBadVsns] = get_req(4, [[snmpInBadVersions,0]]), + InBadVsns. + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_b(InBadVsns) -> + ?line [InBadVsns2] = get_req(1, [[snmpInBadVersions,0]]), + ?line InBadVsns2 = InBadVsns + 1, + ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), + ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), + ?line InPkts2 = InPkts + 1, + ?line [InBadCommunityNames, InBadCommunityUses, InASNErrs] = + get_req(4, [[snmpInBadCommunityNames,0], + [snmpInBadCommunityUses,0], + [snmpInASNParseErrs, 0]]), + {InBadCommunityNames, InBadCommunityUses, InASNErrs}. + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_c({InBadCommunityNames, InBadCommunityUses, InASNErrs}) -> + ?line [InBadCommunityNames2, InBadCommunityUses2, InASNErrs2] = + get_req(1, [[snmpInBadCommunityNames,0], + [snmpInBadCommunityUses,0], + [snmpInASNParseErrs, 0]]), + ?line InBadCommunityNames2 = InBadCommunityNames + 1, + ?line InBadCommunityUses2 = InBadCommunityUses + 1, + ?line InASNErrs2 = InASNErrs + 1. + + +%% -- snmp_community_mib -- + +%%----------------------------------------------------------------- +%% o Bad community uses/name is tested already +%% in SNMPv2-MIB and STANDARD-MIB. +%% o Test add/deletion of rows. +%%----------------------------------------------------------------- +snmp_community_mib(suite) -> []; +snmp_community_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?TRY_TEST1(snmp_community_mib), + ?line unload_master("SNMP-COMMUNITY-MIB"). + +snmp_community_mib_2(X) -> snmp_community_mib(X). + +%% Req. SNMP-COMMUNITY-MIB +snmp_community_mib() -> + ?INF("NOT YET IMPLEMENTED", []), + nyi. + + +%% -- snmp_framework_mib -- + +%%----------------------------------------------------------------- +%% o Test engine boots / time +%%----------------------------------------------------------------- +snmp_framework_mib(suite) -> []; +snmp_framework_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?TRY_TEST1(snmp_framework_mib), + ?line unload_master("SNMP-FRAMEWORK-MIB"). + +%% Req. SNMP-FRAMEWORK-MIB +snmp_framework_mib() -> + ?line ["agentEngine"] = get_req(1, [[snmpEngineID,0]]), + ?line [EngineTime] = get_req(2, [[snmpEngineTime,0]]), + sleep(5000), + ?line [EngineTime2] = get_req(3, [[snmpEngineTime,0]]), + if + EngineTime+7 < EngineTime2 -> + ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); + EngineTime+4 > EngineTime2 -> + ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); + true -> ok + end, + ?line case get_req(4, [[snmpEngineBoots,0]]) of + [Boots] when integer(Boots) -> ok; + Else -> ?FAIL(Else) + end, + ok. + + +%% -- snmp_target_mib -- + +snmp_target_mib(suite) -> []; +snmp_target_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-TARGET-MIB"), + ?TRY_TEST1(snmp_target_mib), + ?line unload_master("SNMP-TARGET-MIB"). + +snmp_target_mib() -> + ?INF("NOT YET IMPLEMENTED", []), + nyi. + + +%% -- snmp_notification_mib -- + +snmp_notification_mib(suite) -> []; +snmp_notification_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?TRY_TEST1(snmp_notification_mib), + ?line unload_master("SNMP-NOTIFICATION-MIB"). + +snmp_notification_mib() -> + ?INF("NOT YET IMPLEMENTED", []), + nyi. + + +%% -- snmp_view_based_acm_mib -- + +%%----------------------------------------------------------------- +%% o add/delete views and try them +%% o try boundaries +%%----------------------------------------------------------------- +snmp_view_based_acm_mib(suite) -> []; +snmp_view_based_acm_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + ?line load_master("Test2"), + snmp_view_based_acm_mib(), + ?line unload_master("Test2"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). + +snmp_view_based_acm_mib() -> + snmpa:verbosity(net_if,trace), + snmpa:verbosity(master_agent,trace), + ?LOG("start snmp_view_based_acm_mib test",[]), + %% The user "no-rights" is present in USM, and is mapped to security + %% name 'no-rights", which is not present in VACM. + %% So, we'll add rights for it, try them and delete them. + %% We'll give "no-rights" write access to tDescr.0 and read access + %% to tDescr2.0 + %% These are the options we'll use to the mgr + Opts = [{user, "no-rights"}, {community, "no-rights"}], + %% Find the valid secmodel, and one invalid secmodel. + {SecMod, InvSecMod} = + case get(vsn) of + v1 -> {?SEC_V1, ?SEC_V2C}; + v2 -> {?SEC_V2C, ?SEC_USM}; + v3 -> {?SEC_USM, ?SEC_V1} + end, + ?DBG("assign rights for 'no-rights'",[]), + ?line ?TRY_TEST3(use_no_rights, [], Opts), + + %% Now, add a mapping from "no-rights" -> "no-rights-group" + GRow1Status = [vacmSecurityToGroupStatus,[SecMod, 9,"no-rights"]], + GRow1 = + [{[vacmGroupName, [SecMod, 9,"no-rights"]], "no-rights-group"}, + {GRow1Status, ?createAndGo}], + ?DBG("set '~p'",[GRow1]), + ?line ?TRY_TEST2(do_set, [GRow1]), + + ?DBG("assign rights for 'no-rights'",[]), + ?line ?TRY_TEST3(use_no_rights, [], Opts), + + %% Create a mapping for another sec model, and make sure it dosn't + %% give us access + GRow2Status = [vacmSecurityToGroupStatus,[InvSecMod, 9,"no-rights"]], + GRow2 = [{[vacmGroupName, [InvSecMod, 9, "no-rights"]], "initial"}, + {GRow2Status, ?createAndGo}], + + ?DBG("set '~p'",[GRow2]), + ?line ?TRY_TEST2(do_set, [GRow2]), + + ?DBG("assign rights for 'no-rights'",[]), + ?line ?TRY_TEST3(use_no_rights, [], Opts), + + %% Delete that row + ?line ?TRY_TEST2(del_row, [GRow2Status]), + + RVName = "rv_name", + WVName = "wv_name", + + %% Access row + ARow1Idx = [15 | "no-rights-group"] ++ [0, ?SEC_ANY, 1], + ARow1Status = [vacmAccessStatus, ARow1Idx], + ARow1 = [{[vacmAccessContextMatch, ARow1Idx], 1}, + {[vacmAccessReadViewName, ARow1Idx], RVName}, + {[vacmAccessWriteViewName, ARow1Idx], WVName}, + {ARow1Status, ?createAndGo}], + + %% This access row would give acces, if InvSecMod was valid. + ARow2Idx = [15 | "no-rights-group"] ++ [0, InvSecMod, 1], + ARow2Status = [vacmAccessStatus, ARow2Idx], + ARow2 = [{[vacmAccessContextMatch, ARow2Idx], 1}, + {[vacmAccessReadViewName, ARow2Idx], "internet"}, + {[vacmAccessWriteViewName, ARow2Idx], "internet"}, + {ARow2Status, ?createAndGo}], + + ?line ?TRY_TEST2(do_set, [ARow2]), + + ?line ?TRY_TEST3(use_no_rights, [], Opts), + + %% Delete that row + ?line ?TRY_TEST2(del_row, [ARow2Status]), + + + %% Add valid row + ?line ?TRY_TEST2(do_set, [ARow1]), + + ?line ?TRY_TEST3(use_no_rights, [], Opts), + + %% Create the view family + VRow1Idx = mk_ln(RVName) ++ mk_ln(?xDescr), % object access + VRow2Idx = mk_ln(RVName) ++ mk_ln(?xDescr2 ++ [0]), % instance access + VRow3Idx = mk_ln(WVName) ++ mk_ln(?xDescr), % object access + VRow4Idx = mk_ln(WVName) ++ mk_ln(?xDescr ++ [0]), % instance access + VRow1Status = [vacmViewTreeFamilyStatus, VRow1Idx], + VRow2Status = [vacmViewTreeFamilyStatus, VRow2Idx], + VRow3Status = [vacmViewTreeFamilyStatus, VRow3Idx], + VRow4Status = [vacmViewTreeFamilyStatus, VRow4Idx], + + ?line ?TRY_TEST2(add_row, [VRow1Status]), + ?line ?TRY_TEST2(add_row, [VRow2Status]), + ?line ?TRY_TEST2(add_row, [VRow3Status]), + + %% We're supposed to have access now... + ?line ?TRY_TEST3(use_rights, [], Opts), + + %% Change Row3 to Row4 + ?line ?TRY_TEST2(del_row, [VRow3Status]), + ?line ?TRY_TEST2(add_row, [VRow4Status]), + + %% We should still have access... + ?line ?TRY_TEST3(use_rights, [], Opts), + + %% Delete rows + ?line ?TRY_TEST2(del_row, [GRow1Status]), + + ?line ?TRY_TEST3(use_no_rights, [], Opts), + + %% Delete rest of rows + ?line ?TRY_TEST2(del_row, [ARow1Status]), + ?line ?TRY_TEST2(del_row, [VRow1Status]), + ?line ?TRY_TEST2(del_row, [VRow2Status]), + ?line ?TRY_TEST2(del_row, [VRow4Status]), + + ?line ?TRY_TEST3(use_no_rights, [], Opts), + snmpa:verbosity(master_agent,log). + +do_set(Row) -> + s(Row), + expect(1, Row). + +add_row(RowStatus) -> + s([{RowStatus, ?createAndGo}]), + expect(1, [{RowStatus, ?createAndGo}]). + +del_row(RowStatus) -> + s([{RowStatus, ?destroy}]), + expect(1, [{RowStatus, ?destroy}]). + + + +use_no_rights() -> + g([[xDescr,0]]), + ?v1_2_3(expect(11, noSuchName, 1, any), + expect(12, [{[xDescr,0], noSuchObject}]), + expect(13, authorizationError, 1, any)), + g([[xDescr2,0]]), + ?v1_2_3(expect(21, noSuchName, 1, any), + expect(22, [{[xDescr2,0], noSuchObject}]), + expect(23, authorizationError, 1, any)), + gn([[xDescr]]), + ?v1_2_3(expect(31, noSuchName, 1, any), + expect(32, [{[xDescr], endOfMibView}]), + expect(33, authorizationError, 1, any)), + s([{[xDescr,0], "tryit"}]), + ?v1_2_3(expect(41, noSuchName, 1, any), + expect(42, noAccess, 1, any), + expect(43, authorizationError, 1, any)). + + +use_rights() -> + g([[xDescr,0]]), + expect(1, [{[xDescr,0], any}]), + g([[xDescr2,0]]), + expect(2, [{[xDescr2,0], any}]), + s([{[xDescr,0], "tryit"}]), + expect(3, noError, 0, any), + g([[xDescr,0]]), + expect(4, [{[xDescr,0], "tryit"}]). + + +%% -- sparse_table -- + +sparse_table(suite) -> []; +sparse_table(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = ?INIT_CASE(Config), + + ?line load_master("Test1"), + ?TRY_TEST1(sparse_table_test), + ?line unload_master("Test1"). + +%% Req. Test1 +sparse_table_test() -> + p("Testing sparse table..."), + + %% Create two rows, check that they are get-nexted in correct order. + Idx1 = 1, + Idx2 = 2, + s([{[sparseStatus, Idx1], i, ?createAndGo}, + {[sparseDescr, Idx1], s, "row 1"}]), + ?line expect(1, [{[sparseStatus, Idx1], ?createAndGo}, + {[sparseDescr, Idx1], "row 1"}]), + s([{[sparseStatus, Idx2], i, ?createAndGo}, + {[sparseDescr, Idx2], s, "row 2"}]), + ?line expect(2, [{[sparseStatus, Idx2], ?createAndGo}, + {[sparseDescr, Idx2], "row 2"}]), + ?v1_2(gn([[sparseIndex], [sparseDescr,Idx1], [sparseDescr,Idx2], + [sparseStatus,Idx1], [sparseStatus,Idx2]]), + gb(0,5,[[sparseIndex]])), + ?line expect(3, [{[sparseDescr,Idx1], "row 1"}, + {[sparseDescr,Idx2], "row 2"}, + {[sparseStatus,Idx1], ?active}, + {[sparseStatus,Idx2], ?active}, + {[sparseStr,0], "slut"}]), + % Delete the rows + s([{[sparseStatus, Idx1], i, ?destroy}]), + ?line expect(4, [{[sparseStatus, Idx1], ?destroy}]), + s([{[sparseStatus, Idx2], i, ?destroy}]), + ?line expect(5, [{[sparseStatus, Idx2], ?destroy}]). + + +%% -- cnt_64 -- + +cnt_64(suite) -> []; +cnt_64(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = ?INIT_CASE(Config), + MA = whereis(snmp_master_agent), + + ?line load_master("Test1"), + ?TRY_TEST2(cnt_64_test, [MA]), + ?line unload_master("Test1"). + +%% Req. Test1 +cnt_64_test(MA) -> + ?LOG("start cnt64 test (~p)",[MA]), + snmpa:verbosity(MA,trace), + ?LOG("start cnt64 test",[]), + p("Testing Counter64, and at the same time, RowStatus is not last column"), + + ?DBG("get cnt64",[]), + g([[cnt64,0]]), + ?DBG("await response",[]), + ?line ?v1_2(expect(1, noSuchName, 1, any), + expect(1, [{[cnt64,0],18446744073709551615}])), + ?DBG("get-next cnt64",[]), + gn([[cnt64]]), + ?DBG("await response",[]), + ?line ?v1_2(expect(2, [{[cnt64Str,0], "after cnt64"}]), + expect(2, [{[cnt64,0],18446744073709551615}])), + ?DBG("send cntTrap",[]), + snmpa:send_trap(MA,cntTrap,"standard trap",[{sysContact,"pelle"}, + {cnt64, 10}, + {sysLocation, "here"}]), + ?DBG("await response",[]), + ?line ?v1_2(expect(3, trap, [test], 6, 1, [{[sysContact,0], "pelle"}, + {[sysLocation,0], "here"}]), + expect(3, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?testTrap ++ [1]}, + {[sysContact,0], "pelle"}, + {[cnt64,0], 10}, + {[sysLocation,0], "here"}])), + + %% Create two rows, check that they are get-nexted in correct order. + Idx1 = 1, + Idx2 = 2, + ?DBG("create row (cntStatus): ~p",[Idx1]), + s([{[cntStatus, Idx1], i, ?createAndGo}]), + ?DBG("await response",[]), + ?line expect(1, [{[cntStatus, Idx1], ?createAndGo}]), + ?DBG("create row (cntStatus): ~p",[Idx2]), + s([{[cntStatus, Idx2], i, ?createAndGo}]), + ?DBG("await response",[]), + ?line expect(2, [{[cntStatus, Idx2], ?createAndGo}]), + + ?DBG("get-next (cntIndex)",[]), + gn([[cntIndex]]), + ?DBG("await response",[]), + ?line ?v1_2(expect(3, [{[cntStatus,Idx1], ?active}]), + expect(3, [{[cntCnt,Idx1], 0}])), + % Delete the rows + ?DBG("delete row (cntStatus): ~p",[Idx1]), + s([{[cntStatus, Idx1], i, ?destroy}]), + ?DBG("await response",[]), + ?line expect(4, [{[cntStatus, Idx1], ?destroy}]), + ?DBG("delete row (cntStatus): ~p",[Idx2]), + s([{[cntStatus, Idx2], i, ?destroy}]), + ?DBG("await response",[]), + ?line expect(5, [{[cntStatus, Idx2], ?destroy}]), + catch snmpa:verbosity(MA,log), + ?DBG("done",[]), + ok. + + +%% -- opaque -- + +opaque(suite) -> []; +opaque(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = ?INIT_CASE(Config), + + ?line load_master("Test1"), + ?TRY_TEST1(opaque_test), + ?line unload_master("Test1"). + +%% Req. Test1 +opaque_test() -> + p("Testing Opaque datatype..."), + g([[opaqueObj,0]]), + ?line expect(1, [{[opaqueObj,0], "opaque-data"}]). + + +%% -- change_target_addr_config -- + +change_target_addr_config(suite) -> []; +change_target_addr_config(Config) when list(Config) -> + p("Testing changing target address config..."), + ?LOG("change_target_addr_config -> entry",[]), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + put(sname,snmp_suite), + put(verbosity,trace), + + MA = whereis(snmp_master_agent), + + ?LOG("change_target_addr_config -> load TestTrap",[]), + ?line load_master("TestTrap"), + + ?LOG("change_target_addr_config -> set trace verbosity for local_db",[]), + ?line snmpa:verbosity(local_db,trace), + + %% First send some traps that will arive att the original manager + ?LOG("change_target_addr_config -> send trap",[]), + ?TRY_TEST2(ma_trap1, [MA]), + + ?LOG("change_target_addr_config -> set silence verbosity for local_db",[]), + ?line snmpa:verbosity(local_db,silence), + + %% Start new dummy listener + ?LOG("change_target_addr_config -> start dummy manager",[]), + ?line {ok,Pid,NewPort} = dummy_manager_start(MA), + + %% Reconfigure + ?LOG("change_target_addr_config -> reconfigure",[]), + AgentDir = ?config(agent_dir, Config), + ?line rewrite_target_addr_conf(AgentDir, NewPort), + ?line snmp_target_mib:reconfigure(AgentDir), + + %% Send the trap again + ?LOG("change_target_addr_config -> send trap again",[]), + catch dummy_manager_send_trap2(Pid), + + ?LOG("change_target_addr_config -> await trap ack",[]), + catch dummy_manager_await_trap2_ack(), + + ?LOG("change_target_addr_config -> stop dummy manager",[]), + ?line ok = dummy_manager_stop(Pid), + + ?LOG("change_target_addr_config -> reset target address config",[]), + ?line reset_target_addr_conf(AgentDir), + + ?LOG("change_target_addr_config -> unload TestTrap",[]), + ?line unload_master("TestTrap"). + + +dummy_manager_start(MA) -> + ?DBG("dummy_manager_start -> entry",[]), + Pid = spawn(get(mgr_node), ?MODULE,dummy_manager_init,[self(),MA]), + ?DBG("dummy_manager_start -> Pid: ~p",[Pid]), + await_dummy_manager_started(Pid). + +await_dummy_manager_started(Pid) -> + receive + {dummy_manager_started,Pid,Port} -> + ?DBG("dummy_manager_start -> acknowledge received with" + "~n Port: ~p",[Port]), + {ok,Pid,Port}; + {'EXIT', Pid, Reason} -> + {error, Pid, Reason}; + O -> + ?LOG("dummy_manager_start -> received unknown message:" + "~n ~p",[O]), + await_dummy_manager_started(Pid) + end. + +dummy_manager_stop(Pid) -> + ?DBG("dummy_manager_stop -> entry with Pid: ~p",[Pid]), + Pid ! stop, + receive + {dummy_manager_stopping, Pid} -> + ?DBG("dummy_manager_stop -> acknowledge received",[]), + ok + after 10000 -> + ?ERR("dummy_manager_stop -> timeout",[]), + timeout + end. + +dummy_manager_send_trap2(Pid) -> + ?DBG("dummy_manager_send_trap2 -> entry",[]), + Pid ! {send_trap,testTrap2}. + +dummy_manager_await_trap2_ack() -> + ?DBG("dummy_manager_await_trap2 -> entry",[]), + receive + {received_trap,Trap} -> + ?LOG("dummy_manager_await_trap2 -> received trap: ~p",[Trap]), + %% Note: + %% Without this sleep the v2_inform_i testcase failes! There + %% is no relation between these two test cases as far as I + %% able to figure out... + sleep(60000), + ok; + O -> + ?ERR("dummy_manager_await_trap2 -> unexpected message: ~p",[O]), + ok + after 10000 -> + ?ERR("dummy_manager_await_trap2 -> timeout",[]), + timeout + end. + +dummy_manager_init(Parent,MA) -> + ?DBG("dummy_manager_init -> entry with" + "~n Parent: ~p" + "~n MA: ~p",[Parent,MA]), + {ok,S} = gen_udp:open(0,[{recbuf,65535}]), + ?DBG("dummy_manager_init -> S: ~p",[S]), + {ok,Port} = inet:port(S), + ?DBG("dummy_manager_init -> Port: ~p",[Port]), + Parent ! {dummy_manager_started,self(),Port}, + dummy_manager_loop(Parent,S,MA). + +dummy_manager_loop(P,S,MA) -> + ?LOG("dummy_manager_loop -> ready for receive",[]), + receive + {send_trap,Trap} -> + ?LOG("dummy_manager_loop -> received trap send request" + "~n Trap: ~p",[Trap]), + snmpa:send_trap(MA, Trap, "standard trap"), + dummy_manager_loop(P,S,MA); + {udp, _UdpId, Ip, UdpPort, Bytes} -> + ?LOG("dummy_manager_loop -> received upd message" + "~n from: ~p:~p" + "~n size: ~p", + [Ip, UdpPort, dummy_manager_message_sz(Bytes)]), + R = dummy_manager_handle_message(Bytes), + ?DBG("dummy_manager_loop -> R: ~p",[R]), + P ! R, + dummy_manager_loop(P,S,MA); + stop -> + ?DBG("dummy_manager_loop -> received stop request",[]), + P ! {dummy_manager_stopping, self()}, + gen_udp:close(S), + exit(normal); + O -> + ?LOG("dummy_manager_loop -> received unknown message:" + "~n ~p",[O]), + dummy_manager_loop(P,S,MA) + end. + +dummy_manager_message_sz(B) when binary(B) -> + size(B); +dummy_manager_message_sz(L) when list(L) -> + length(L); +dummy_manager_message_sz(_) -> + undefined. + +dummy_manager_handle_message(Bytes) -> + case (catch snmp_pdus:dec_message(Bytes)) of + {'EXIT',Reason} -> + ?ERR("dummy_manager_handle_message -> " + "failed decoding message only:~n ~p",[Reason]), + {error,Reason}; + M -> + ?DBG("dummy_manager_handle_message -> decoded message:" + "~n ~p",[M]), + {received_trap,M} + end. + + +%% -- reported_bugs -- + +%%%----------------------------------------------------------------- +%%% Testing of reported bugs and other tickets. +%%%----------------------------------------------------------------- + +reported_bugs(suite) -> + [otp_1128, otp_1129, otp_1131, otp_1162, + otp_1222, otp_1298, otp_1331, otp_1338, + otp_1342, otp_2776, otp_2979, otp_3187, otp_3725]. + +%%----------------------------------------------------------------- +%% Ticket: OTP-1128 +%% Slogan: Bug in handling of createAndWait set-requests. +%%----------------------------------------------------------------- +otp_1128(suite) -> []; +otp_1128(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + ?TRY_TEST1(otp_1128), + ?line unload_master("OLD-SNMPEA-MIB"). + +otp_1128() -> + io:format("Testing bug reported in ticket OTP-1128...~n"), + + NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], + NewKeyc4 = [intCommunityAccess,get(mip),is("test")], + NewKeyc5 = [intCommunityStatus,get(mip),is("test")], + + s([{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), + ?line expect(28, [{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), + g([NewKeyc5]), + ?line expect(29, [{NewKeyc5, ?notReady}]), + s([{NewKeyc5, ?active}, {NewKeyc3, 2}]), + ?line expect(30, [{NewKeyc5, ?active}, {NewKeyc3, 2}]), + g([NewKeyc5]), + ?line expect(31, [{NewKeyc5, ?active}]), + s([{NewKeyc5, ?destroy}]), + ?line expect(32, [{NewKeyc5, ?destroy}]). + +%%----------------------------------------------------------------- +%% Ticket: OTP-1129, OTP-1169 +%% Slogan: snmpa:int_to_enum crashes on bad oids +%%----------------------------------------------------------------- +otp_1129(suite) -> []; +otp_1129(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas3"), + ?TRY_TEST2(otp_1129_i, [node()]), + ?line unload_master("Klas3"). + +otp_1129_i(MaNode) -> + io:format("Testing bug reported in ticket OTP-1129...~n"), + false = rpc:call(MaNode, snmp, int_to_enum, [iso, 1]), + false = rpc:call(MaNode, snmp, int_to_enum, [isox, 1]). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1131 +%% Slogan: Agent crashes / erlang node halts if RowIndex in a +%% setrequest is of bad type, e.g. an INDEX {INTEGER}, +%% and RowIdenx [3,2]. +%%----------------------------------------------------------------- +otp_1131(suite) -> []; +otp_1131(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas1"), + ?TRY_TEST1(otp_1131), + ?line unload_master("Klas1"). + +otp_1131() -> + io:format("Testing bug reported in ticket OTP-1131...~n"), + s([{[friendsEntry, [2, 3, 1]], s, "kompis3"}, + {[friendsEntry, [3, 3, 1]], i, ?createAndGo}]), + ?line expect(1, ?v1_2(noSuchName, noCreation), 2, any). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1162 +%% Slogan: snmp_agent can't handle wrongValue from instrum.func +%%----------------------------------------------------------------- +otp_1162(suite) -> []; +otp_1162(Config) when list(Config) -> + ?P1(otp_1162), + {SaNode, _MgrNode, _MibDir} = ?INIT_CASE(Config), + ?line {ok, SA} = ?START_SA(SaNode, ?sa, "SA-MIB"), + ?TRY_TEST1(otp_1162), + ?STOP_SA(SA). + +otp_1162() -> + s([{[sa, [2,0]], 6}]), % wrongValue (i is_set_ok) + ?line expect(1, ?v1_2(badValue, wrongValue), 1, any). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1222 +%% Slogan: snmp agent crash if faulty index is returned from instrum +%%----------------------------------------------------------------- +otp_1222(suite) -> []; +otp_1222(Config) when list(Config) -> + ?P1(otp_1222), + ?INIT_CASE(Config), + ?line load_master("Klas3"), + ?line load_master("Klas4"), + ?TRY_TEST1(otp_1222), + ?line unload_master("Klas3"), + ?line unload_master("Klas4"). + +otp_1222() -> + io:format("Testing bug reported in ticket OTP-1222...~n"), + s([{[fStatus4,1], 4}, {[fName4,1], 1}]), + ?line expect(1, genErr, 0, any), + s([{[fStatus4,2], 4}, {[fName4,2], 1}]), + ?line expect(2, genErr, 0, any). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1298 +%% Slogan: Negative INTEGER values are treated as positive. +%%----------------------------------------------------------------- +otp_1298(suite) -> []; +otp_1298(Config) when list(Config) -> + ?P1(otp_1298), + ?INIT_CASE(Config), + ?line load_master("Klas2"), + ?TRY_TEST1(otp_1298), + ?line unload_master("Klas2"). + +otp_1298() -> + io:format("Testing bug reported in ticket OTP-1298...~n"), + s([{[fint,0], -1}]), + ?line expect(1298, [{[fint,0], -1}]). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1331 +%% Slogan: snmp_generic should return noError when deleting non-ex row +%%----------------------------------------------------------------- +otp_1331(suite) -> []; +otp_1331(Config) when list(Config) -> + ?P1(otp_1331), + ?INIT_CASE(Config), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + ?TRY_TEST1(otp_1331), + ?line unload_master("OLD-SNMPEA-MIB"). + +otp_1331() -> + NewKeyc5 = [intCommunityStatus,[127,32,0,0],is("test")], + s([{NewKeyc5, ?destroy}]), + ?line expect(1, [{NewKeyc5, ?destroy}]). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1338 +%% Slogan: snmp bug in initialisation of default values for mnesia tabs +%%----------------------------------------------------------------- +otp_1338(suite) -> []; +otp_1338(Config) when list(Config) -> + ?P1(otp_1338), + ?INIT_CASE(Config), + ?line load_master("Klas2"), + ?TRY_TEST1(otp_1338), + ?line unload_master("Klas2"). + +otp_1338() -> + s([{[kStatus2, 7], i, ?createAndGo}]), + ?line expect(1, [{[kStatus2, 7], ?createAndGo}]), + g([[kName2, 7]]), + ?line expect(2, [{[kName2, 7], "JJJ"}]). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1342 +%% Slogan: default impl of snmp table can't handle bad index access, +%% Set when INDEX is read-write gets into an infinite loop! +%%----------------------------------------------------------------- +otp_1342(suite) -> []; +otp_1342(Config) when list(Config) -> + ?P1(otp_1342), + ?INIT_CASE(Config), + ?line load_master("Klas4"), + ?TRY_TEST1(otp_1342), + ?line unload_master("Klas4"). + +otp_1342() -> + s([{[fIndex5, 1], i, 1}, + {[fName5, 1], i, 3}, + {[fStatus5, 1], i, ?createAndGo}]), + ?line expect(1, ?v1_2(noSuchName, noCreation), 3, any). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1366 +%% Slogan: snmp traps not sent to all managers +%% Note: NYI! We need a way to tell the test server that we need +%% mgrs on two different machines. +%%----------------------------------------------------------------- +otp_1366(suite) -> []; +otp_1366(Config) when list(Config) -> + ?P1(otp_1366), + ?INIT_CASE(Config), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + ?TRY_TEST1(otp_1366), + ?line unload_master("OLD-SNMPEA-MIB"). + +otp_1366() -> + ?INF("NOT YET IMPLEMENTED", []), + 'NYI'. + + +%%----------------------------------------------------------------- +%% Ticket: OTP-2776 +%% Slogan: snmp:validate_date_and_time() fails when time is 00:00 +%%----------------------------------------------------------------- +otp_2776(suite) -> []; +otp_2776(Config) when list(Config) -> + ?P1(otp_2776), + ?INIT_CASE(Config), + ?TRY_TEST1(otp_2776). + +otp_2776() -> + io:format("Testing bug reported in ticket OTP-2776...~n"), + + Dt01_valid = [19,98,9,1,1,0,23,0,43,0,0], + Dt02_valid = [19,98,9,1,0,0,0,0,43,0,0], % This is what is fixed: 00:00 + Dt03_valid = [19,98,2,28,1,0,23,0,43,0,0], + Dt04_invalid = [19,98,2,29,1,0,23,0,43,0,0], + Dt05_valid = [19,96,2,29,1,0,23,0,43,0,0], + Dt06_valid = [20,0,2,29,1,0,23,0,43,0,0], + Dt07_invalid = [19,96,2,30,1,0,23,0,43,0,0], % This is also fixed: 30/2 + Dt08_valid = [19,98,4,30,1,0,23,0,43,0,0], + Dt09_invalid = [19,98,4,31,1,0,23,0,43,0,0], % This is also fixed: 31/4 + Dt10_invalid = [], + Dt11_invalid = [kalle,hobbe], + L = [{ 1, true, Dt01_valid}, + { 2, true, Dt02_valid}, + { 3, true, Dt03_valid}, + { 4, false, Dt04_invalid}, + { 5, true, Dt05_valid}, + { 6, true, Dt06_valid}, + { 7, false, Dt07_invalid}, + { 8, true, Dt08_valid}, + { 9, false, Dt09_invalid}, + {10, false, Dt10_invalid}, + {11, false, Dt11_invalid}], + + ?line ok = validate_dat(L). + + +validate_dat(L) -> validate_dat(L,[]). + +validate_dat([],V) -> + Fun = fun({_,X}) -> case X of + ok -> false; + _ -> true + end + end, + validate_dat1( lists:reverse( lists:filter(Fun,V) ) ); +validate_dat([{Id,E,Dat}|T],V) -> + validate_dat(T,[validate_dat2(Id,E,Dat) | V]). + +validate_dat1([]) -> ok; +validate_dat1(L) -> {error,L}. + +validate_dat2(Id, E, Dat) -> + Res = case {E,snmp:validate_date_and_time(Dat)} of + {E,E} -> ok; + {E,A} -> {E,A} + end, + {Id, Res}. + + +%%----------------------------------------------------------------- +%% Ticket: OTP-2979 +%% Slogan: get-next on more than 1 column in an empty table +%% returns bad response. +%%----------------------------------------------------------------- +otp_2979(suite) -> []; +otp_2979(Config) when list(Config) -> + ?P1(otp_2979), + ?INIT_CASE(Config), + ?line load_master("Test1"), + ?line init_old(), + ?TRY_TEST1(otp_2979), + ?line unload_master("Test1"). + +otp_2979() -> + gn([[sparseDescr], [sparseStatus]]), + ?line expect(1, [{[sparseStr,0], "slut"}, + {[sparseStr,0], "slut"}]). + +%%----------------------------------------------------------------- +%% Ticket: OTP-3187 +%% Slogan: get-next on vacmAccessTable for colums > 5 returns +%% endOfTable - should return value. +%%----------------------------------------------------------------- +otp_3187(suite) -> []; +otp_3187(Config) when list(Config) -> + ?P1(otp_3187), + ?INIT_CASE(Config), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + otp_3187(), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). + +otp_3187() -> + ?line Elements = + snmp_view_based_acm_mib:vacmAccessTable(get_next,[],[4,5,6]), + lists:foreach(fun(E) -> + ?line if E == endOfTable -> + ?FAIL(endOfTable); + true -> ok + end + end, Elements). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-3542 +%% Slogan: +%%----------------------------------------------------------------- +otp_3542(suite) -> []; +otp_3542(Config) when list(Config) -> + ?P1(otp_3542), + ?INIT_CASE(Config), + ?TRY_TEST1(otp_3542). + +otp_3542() -> + io:format("SNMP v3 discovery...~n"), + ?line Res = snmp_test_mgr:d(), + io:format("SNMP v3 discovery result: ~p~n",[Res]). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-3725 +%% Slogan: Slow response time on snmpa:int_to_enum +%%----------------------------------------------------------------- +otp_3725(suite) -> []; +otp_3725(Config) when list(Config) -> + ?P1(otp_3725), + ?INIT_CASE(Config), + + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + ?TRY_TEST2(otp_3725_test, [node()]), + ?line unload_master("OLD-SNMPEA-MIB"). + +%% Req. OLD-SNMPEA-MIB +otp_3725_test(MaNode) -> + io:format("Testing feature requested in ticket OTP-3725...~n"), + ?line rpc:call(MaNode,snmpa,verbosity,[symbolic_store,trace]), + ?line Db = rpc:call(MaNode,snmp,get_symbolic_store_db,[]), + ?DBG("otp_3725_test -> Db = ~p",[Db]), + + ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, + [Db, intAgentIpAddress]), + ?DBG("otp_3725_test -> name_to_oid for ~p: ~p",[intAgentIpAddress,OID]), + ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, oid_to_name, + [Db,OID]), + ?DBG("otp_3725_test -> oid_to_name for ~p: ~p",[OID,intAgentIpAddress]), + ?line false = rpc:call(MaNode, snmp, name_to_oid, [Db, intAgentIpAddres]), + ?line false = rpc:call(MaNode, snmp, oid_to_name, + [Db, [1,5,32,3,54,3,3,34,4]]), + ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, + [Db, intViewType, excluded]), + ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, + [Db, intViewType, 2]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, intViewType, exclude]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, intAgentIpAddress, exclude]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, intAgentIpAddre, exclude]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, intViewType, 3]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, + [Db, intAgentIpAddress, 2]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, + [Db, intAgentIpAddre, 2]), + ?line {value, active} = rpc:call(MaNode, snmp, int_to_enum, + [Db, 'RowStatus', ?active]), + ?line {value, ?destroy} = rpc:call(MaNode, snmp, enum_to_int, + [Db, 'RowStatus', destroy]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, 'RowStatus', xxxdestroy]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, 'xxRowStatus', destroy]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'RowStatus', 25]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'xxRowStatus', 1]), + ok. + + +%% -- tickets -- + +%% These are (ticket) test cases where the initiation has to be done +%% individually. +tickets(suite) -> + [otp_4394]. + + +%%----------------------------------------------------------------- +%% Ticket: OTP-4394 +%% Slogan: Target mib tag list check invalid +%%----------------------------------------------------------------- + +otp_4394(suite) -> {req, [], {conf, + init_otp_4394, + [otp_4394_test], + finish_otp_4394}}. + +init_otp_4394(Config) when list(Config) -> + ?DBG("init_otp_4394 -> entry with" + "~n Config: ~p", [Config]), + ?line AgentDir = ?config(agent_dir, Config), + ?line MgrDir = ?config(mgr_dir, Config), + ?line Ip = ?config(ip, Config), + ?line otp_4394_config(AgentDir, MgrDir, Ip), + MasterAgentVerbosity = {master_agent_verbosity, trace}, + NetIfVerbosity = {net_if_verbosity, trace}, + Opts = [MasterAgentVerbosity,NetIfVerbosity], + [{vsn, v1} | start_v1_agent(Config,Opts)]. + +otp_4394_config(AgentDir, MgrDir, Ip0) -> + ?DBG("otp_4394_config -> entry with" + "~n AgentDir: ~p" + "~n MgrDir: ~p" + "~n Ip0: ~p", [AgentDir, MgrDir, Ip0]), + Vsn = [v1], + Ip = tuple_to_list(Ip0), + ?line snmp_config:write_agent_snmp_files(AgentDir, Vsn, Ip, + ?TRAP_UDP, Ip, 4000, + "OTP-4394 test"), + ?line case update_usm(Vsn, AgentDir) of + true -> + ?line copy_file(filename:join(AgentDir, "usm.conf"), + filename:join(MgrDir, "usm.conf")), + ?line update_usm_mgr(Vsn, MgrDir); + false -> + ?line ok + end, + C1 = {"a", "all-rights", "initial", "", "pc"}, + C2 = {"c", "secret", "secret_name", "", "secret_tag"}, + ?line write_community_conf(AgentDir, [C1, C2]), + ?line update_vacm(Vsn, AgentDir), + Ta1 = {"shelob v1", + [134,138,177,177], 5000, 1500, 3, %% Använd Ip och modda + "pc1", + "target_v1", "", + %% [255,255,255,255,0,0], + [], + 2048}, + Ta2 = {"bifur v1", + [134,138,177,75], 5000, 1500, 3, %% Använd Ip + "pc2", + "target_v1", "", + %% [255,255,255,255,0,0], + [], 2048}, + ?line write_target_addr_conf(AgentDir, [Ta1, Ta2]), + ?line write_target_params_conf(AgentDir, Vsn), + ?line write_notify_conf(AgentDir), + ok. + +finish_otp_4394(Config) when list(Config) -> + ?DBG("finish_otp_4394 -> entry", []), + C1 = stop_agent(Config), + delete_files(C1), + erase(mgr_node), + lists:keydelete(vsn, 1, C1). + +otp_4394_test(suite) -> []; +otp_4394_test(Config) -> + ?P1(otp_4394_test), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?TRY_TEST1(otp_4394_test1), + ?DBG("otp_4394_test -> done", []), + ok. + +otp_4394_test1() -> + ?DBG("otp_4394_test1 -> entry", []), + gn([[1,1]]), + Res = + case snmp_test_mgr:expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]) of + %% {error, 1, {"?",[]}, {"~w",[timeout]}} + {error, 1, _, {_, [timeout]}} -> + ?DBG("otp_4394_test1 -> expected result: timeout", []), + ok; + Else -> + Else + end, + ?DBG("otp_4394_test1 -> done with: ~p", [Res]), + Res. + + +mk_ln(X) -> + [length(X) | X]. + + + +%% string used in index +is(S) -> [length(S) | S]. + +expect(A,B) -> ok = ?MGR:expect(A,B). +expect(A,B,C) -> ok = ?MGR:expect(A,B,C). +expect(A,B,C,D) -> ok = ?MGR:expect(A,B,C,D). +expect(A,B,C,D,E,F) -> ok = ?MGR:expect(A,B,C,D,E,F). + diff --git a/lib/snmp/test/exp/snmp_agent_v2_test.erl b/lib/snmp/test/exp/snmp_agent_v2_test.erl new file mode 100644 index 0000000000..dc94c18ad9 --- /dev/null +++ b/lib/snmp/test/exp/snmp_agent_v2_test.erl @@ -0,0 +1,5649 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2005-2010. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% + +-module(snmp_agent_v2_test). + +%% TODO +%% * Test fault-tolerance (kill master etc) +%% + +-compile(export_all). + +-define(application, snmp). + +-include_lib("kernel/include/file.hrl"). +-include_lib("test_server/include/test_server.hrl"). +-include("snmp_test_lib.hrl"). +-define(SNMP_USE_V3, true). +-include_lib("snmp/include/snmp_types.hrl"). +%% -include_lib("snmp/include/SNMP-COMMUNITY-MIB.hrl"). +%% -include_lib("snmp/include/SNMP-VIEW-BASED-ACM-MIB.hrl"). +%% -include_lib("snmp/include/SNMP-USER-BASED-SM-MIB.hrl"). + + +-define(klas1, [1,3,6,1,2,1,7]). +-define(klas2, [1,3,6,1,2,1,9]). +-define(klas3, [1,3,6,1,2,1,8,1]). +-define(klas4, [1,3,6,1,2,1,8,4]). +-define(sa, [1,3,6,1,4,1,193,2]). +-define(system, [1,3,6,1,2,1,1]). +-define(snmp, [1,3,6,1,2,1,11]). +-define(snmpTraps, [1,3,6,1,6,3,1,1,5]). +-define(ericsson, [1,3,6,1,4,1,193]). +-define(testTrap, [1,3,6,1,2,1,15,0]). +-define(xDescr, [1,3,6,1,2,1,17,1]). +-define(xDescr2, [1,3,6,1,2,1,17,2]). + +-define(active, 1). +-define(notInService, 2). +-define(notReady, 3). +-define(createAndGo, 4). +-define(createAndWait, 5). +-define(destroy, 6). + +-define(TRAP_UDP, 5000). + +-define(tooBigStr, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"). + +-define(str(X), snmp_pdus:bits_to_str(X)). + +-define(break(), begin io:format(user, "break at line ~w: pid: ~p\n", + [?LINE, self()]), + receive cont -> ok end + end). + + +-import(snmp_test_mgr, [gn/1, g/1, s/1, gb/3]). +-define(v1_2(V1,V2), + case get(vsn) of + v1 -> V1; + _ -> V2 + end). + +-define(v1_2_3(V1,V2,V3), + case get(vsn) of + v1 -> V1; + v2 -> V2; + _ -> V3 + end). + +all() -> +[cases()]. + +groups() -> + [{mib_storage, [], + [{group, mib_storage_ets}, {group, mib_storage_dets}, + {group, mib_storage_mnesia}, + {group, mib_storage_size_check_ets}, + {group, mib_storage_size_check_dets}, + {group, mib_storage_size_check_mnesia}, + {group, mib_storage_varm_dets}, + {group, mib_storage_varm_mnesia}]}, + {mib_storage_ets, [], mib_storage_ets_cases()}, + {mib_storage_dets, [], mib_storage_dets_cases()}, + {mib_storage_mnesia, [], mib_storage_mnesia_cases()}, + {mib_storage_size_check_ets, [], + mse_size_check_cases()}, + {mib_storage_size_check_dets, [], + msd_size_check_cases()}, + {mib_storage_size_check_mnesia, [], + msm_size_check_cases()}, + {mib_storage_varm_dets, [], + varm_mib_storage_dets_cases()}, + {mib_storage_varm_mnesia, [], + varm_mib_storage_mnesia_cases()}, + {test_v1, [], v1_cases()}, {test_v2, [], v2_cases()}, + {test_v1_v2, [], v1_v2_cases()}, + {test_v3, [], v3_cases()}, + {test_multi_threaded, [], mt_cases()}, + {multiple_reqs, [], mul_cases()}, + {multiple_reqs_2, [], mul_cases_2()}, + {v2_inform, [], [v2_inform_i]}, + {v3_security, [], + [v3_crypto_basic, v3_md5_auth, v3_sha_auth, + v3_des_priv]}, + {standard_mibs, [], + [snmp_standard_mib, snmp_community_mib, + snmp_framework_mib, snmp_target_mib, + snmp_notification_mib, snmp_view_based_acm_mib]}, + {standard_mibs_2, [], + [snmpv2_mib_2, snmp_community_mib_2, + snmp_framework_mib_2, snmp_target_mib_2, + snmp_notification_mib_2, snmp_view_based_acm_mib_2]}, + {standard_mibs_3, [], + [snmpv2_mib_3, snmp_framework_mib_3, snmp_mpd_mib_3, + snmp_target_mib_3, snmp_notification_mib_3, + snmp_view_based_acm_mib_3, snmp_user_based_sm_mib_3]}, + {reported_bugs, [], + [otp_1128, otp_1129, otp_1131, otp_1162, otp_1222, + otp_1298, otp_1331, otp_1338, otp_1342, otp_2776, + otp_2979, otp_3187, otp_3725]}, + {reported_bugs_2, [], + [otp_1128_2, otp_1129_2, otp_1131_2, otp_1162_2, + otp_1222_2, otp_1298_2, otp_1331_2, otp_1338_2, + otp_1342_2, otp_2776_2, otp_2979_2, otp_3187_2]}, + {reported_bugs_3, [], + [otp_1128_3, otp_1129_3, otp_1131_3, otp_1162_3, + otp_1222_3, otp_1298_3, otp_1331_3, otp_1338_3, + otp_1342_3, otp_2776_3, otp_2979_3, otp_3187_3, + otp_3542]}, + {tickets, [], [{group, otp_4394}]}, + {otp_4394, [], [otp_4394_test]}]. + +init_per_group(otp_4394, Config) -> + init_otp_4394(Config); +init_per_group(v2_inform, Config) -> + init_v2_inform(Config); +init_per_group(multiple_reqs_2, Config) -> + init_mul(Config); +init_per_group(multiple_reqs, Config) -> + init_mul(Config); +init_per_group(test_multi_threaded, Config) -> + init_mt(Config); +init_per_group(test_v3, Config) -> + init_v3(Config); +init_per_group(test_v1_v2, Config) -> + init_v1_v2(Config); +init_per_group(test_v2, Config) -> + init_v2(Config); +init_per_group(test_v1, Config) -> + init_v1(Config); +init_per_group(mib_storage_varm_mnesia, Config) -> + init_varm_mib_storage_mnesia(Config); +init_per_group(mib_storage_varm_dets, Config) -> + init_varm_mib_storage_dets(Config); +init_per_group(mib_storage_size_check_mnesia, Config) -> + init_size_check_msm(Config); +init_per_group(mib_storage_size_check_dets, Config) -> + init_size_check_msd(Config); +init_per_group(mib_storage_size_check_ets, Config) -> + init_size_check_mse(Config); +init_per_group(mib_storage_mnesia, Config) -> + init_mib_storage_mnesia(Config); +init_per_group(mib_storage_dets, Config) -> + init_mib_storage_dets(Config); +init_per_group(mib_storage_ets, Config) -> + init_mib_storage_ets(Config); +init_per_group(_GroupName, Config) -> + Config. + +end_per_group(otp_4394, Config) -> + finish_otp_4394(Config); +end_per_group(v2_inform, Config) -> + finish_v2_inform(Config); +end_per_group(multiple_reqs_2, Config) -> + finish_mul(Config); +end_per_group(multiple_reqs, Config) -> + finish_mul(Config); +end_per_group(test_multi_threaded, Config) -> + finish_mt(Config); +end_per_group(test_v3, Config) -> + finish_v3(Config); +end_per_group(test_v1_v2, Config) -> + finish_v1_v2(Config); +end_per_group(test_v2, Config) -> + finish_v2(Config); +end_per_group(test_v1, Config) -> + finish_v1(Config); +end_per_group(mib_storage_varm_mnesia, Config) -> + finish_varm_mib_storage_mnesia(Config); +end_per_group(mib_storage_varm_dets, Config) -> + finish_varm_mib_storage_dets(Config); +end_per_group(mib_storage_size_check_mnesia, Config) -> + finish_size_check_msm(Config); +end_per_group(mib_storage_size_check_dets, Config) -> + finish_size_check_msd(Config); +end_per_group(mib_storage_size_check_ets, Config) -> + finish_size_check_mse(Config); +end_per_group(mib_storage_mnesia, Config) -> + finish_mib_storage_mnesia(Config); +end_per_group(mib_storage_dets, Config) -> + finish_mib_storage_dets(Config); +end_per_group(mib_storage_ets, Config) -> + finish_mib_storage_ets(Config); +end_per_group(_GroupName, Config) -> + Config. + + +init_per_testcase(_Case, Config) when list(Config) -> + Dog = ?t:timetrap(?t:minutes(6)), + [{watchdog, Dog}|Config]. + +end_per_testcase(_Case, Config) when list(Config) -> + Dog = ?config(watchdog, Config), + ?t:timetrap_cancel(Dog), + Config. + +cases() -> +case ?OSTYPE() of + vxworks -> + [app_info, {group, test_v1}, {group, test_v2}, + {group, test_v1_v2}, {group, test_multi_threaded}, + {group, mib_storage}, {group, tickets}]; + _Else -> + [app_info, {group, test_v1}, {group, test_v2}, + {group, test_v1_v2}, {group, test_v3}, + {group, test_multi_threaded}, {group, mib_storage}, + {group, tickets}] +end. + + +%%%----------------------------------------------------------------- +%%% The test case structure is as follows: +%%% +%%% init_all - starts mnesia, +%%% +%%% init_v1 - starts agent +%%% simple +%%% big - e.g. starts/stops subagent, load/unloads mibs +%%% init_mul +%%% mul_get +%%% mul_set +%%% +%%% finish_mul +%%% +%%% finish_v1 +%%% +%%% init_v2 - starts agent +%%% finish_v2 +%%% +%%% init_bilingual - starts agent +%%% finish_bilingual +%%% +%%% finish_all +%%% +%%% There is still one problem with these testsuites. If one test +%%% fails, it may not be possible to run some other cases, as it +%%% may have e.g. created some row or loaded some table, that it +%%% didn't undo (since it failed). +%%%----------------------------------------------------------------- + +init_all(Config0) when list(Config0) -> + ?LOG("init_all -> entry with" + "~n Config0: ~p",[Config0]), + + %% -- + %% Fix config: + %% + + DataDir0 = ?config(data_dir, Config0), + DataDir1 = filename:split(filename:absname(DataDir0)), + [_|DataDir2] = lists:reverse(DataDir1), + DataDir3 = filename:join(lists:reverse(DataDir2) ++ [?snmp_test_data]), + Config1 = lists:keydelete(data_dir, 1, Config0), + Config = [{data_dir, DataDir3 ++ "/"}|Config1], + + %% -- + %% Start nodes + %% + + ?line {ok, SaNode} = start_node(snmp_sa), + ?line {ok, MgrNode} = start_node(snmp_mgr), + + + %% -- + %% Create necessary files + %% + + Dir = ?config(priv_dir, Config), + ?DBG("init_all -> Dir ~p", [Dir]), + + DataDir = ?config(data_dir, Config), + ?DBG("init_all -> DataDir ~p", [DataDir]), + + file:make_dir(MgrDir = filename:join(Dir, "mgr_dir/")), + ?DBG("init_all -> MgrDir ~p", [MgrDir]), + + file:make_dir(AgentDir = filename:join(Dir, "agent_dir/")), + ?DBG("init_all -> AgentDir ~p", [AgentDir]), + + file:make_dir(SaDir = filename:join(Dir, "sa_dir/")), + ?DBG("init_all -> SaDir ~p", [SaDir]), + + + %% -- + %% Start and initiate mnesia + %% + + ?DBG("init_all -> load application mnesia", []), + ?line ok = application:load(mnesia), + + ?DBG("init_all -> load application mnesia on node ~p", [SaNode]), + ?line ok = rpc:call(SaNode, application, load, [mnesia]), + + ?DBG("init_all -> application mnesia: set_env dir",[]), + ?line application_controller:set_env(mnesia, dir, + filename:join(Dir, "Mnesia1")), + + ?DBG("init_all -> application mnesia: set_env dir on node ~p",[SaNode]), + ?line rpc:call(SaNode, application_controller, set_env, + [mnesia, dir, filename:join(Dir, "Mnesia2")]), + + ?DBG("init_all -> create mnesia schema",[]), + ?line ok = mnesia:create_schema([SaNode, node()]), + + ?DBG("init_all -> start application mnesia",[]), + ?line ok = application:start(mnesia), + + ?DBG("init_all -> start application mnesia on ~p",[SaNode]), + ?line ok = rpc:call(SaNode, application, start, [mnesia]), + Ip = ?LOCALHOST(), + [{snmp_sa, SaNode}, + {snmp_mgr, MgrNode}, + {agent_dir, AgentDir ++ "/"}, + {mgr_dir, MgrDir ++ "/"}, + {sa_dir, SaDir ++ "/"}, + {mib_dir, DataDir}, + {ip, Ip} | + Config]. + +finish_all(Config) when list(Config) -> + SaNode = ?config(snmp_sa, Config), + MgrNode = ?config(snmp_mgr, Config), + stop_node(SaNode), + stop_node(MgrNode), + application:stop(mnesia). + +start_v1_agent(Config) when list(Config) -> + start_agent(Config, [v1]). + +start_v1_agent(Config,Opts) when list(Config), list(Opts) -> + start_agent(Config, [v1], Opts). + +start_v2_agent(Config) when list(Config) -> + start_agent(Config, [v2]). + +start_v3_agent(Config) when list(Config) -> + start_agent(Config, [v3]). + +start_bilingual_agent(Config) when list(Config) -> + start_agent(Config, [v1,v2]). + +start_multi_threaded_agent(Config) when list(Config) -> + start_agent(Config, [v2], [{snmp_multi_threaded, true}]). + +stop_agent(Config) when list(Config) -> + ?LOG("stop_agent -> entry with" + "~n Config: ~p",[Config]), + + {Sup, Par} = ?config(snmp_sup, Config), + ?DBG("stop_agent -> attempt to stop (sup) ~p" + "~n Sup: ~p" + "~n Par: ~p", + [Sup, + (catch process_info(Sup)), + (catch process_info(Par))]), + stop_sup(Sup, Par), + + {Sup2, Par2} = ?config(snmp_sub, Config), + ?DBG("stop_agent -> attempt to stop (sub) ~p" + "~n Sup2: ~p" + "~n Par2: ~p", + [Sup2, + (catch process_info(Sup2)), + (catch process_info(Par2))]), + stop_sup(Sup2, Par2), + + ?DBG("stop_agent -> done - now cleanup config", []), + C1 = lists:keydelete(snmp_sup, 1, Config), + lists:keydelete(snmp_sub, 1, C1). + + +stop_sup(Pid, _) when node(Pid) == node() -> + case (catch process_info(Pid)) of + PI when list(PI) -> + ?LOG("stop_sup -> attempt to stop ~p", [Pid]), + Ref = erlang:monitor(process, Pid), + exit(Pid, kill), + await_stopped(Pid, Ref); + {'EXIT', _Reason} -> + ?LOG("stop_sup -> ~p not running", [Pid]), + ok + end; +stop_sup(Pid, _) -> + ?LOG("stop_sup -> attempt to stop ~p", [Pid]), + Ref = erlang:monitor(process, Pid), + ?LOG("stop_sup -> Ref: ~p", [Ref]), + %% Pid ! {'EXIT', Parent, shutdown}, % usch + exit(Pid, kill), + await_stopped(Pid, Ref). + +await_stopped(Pid, Ref) -> + receive + {'DOWN', Ref, process, Pid, _Reason} -> + ?DBG("received down message for ~p", [Pid]), + ok + after 10000 -> + ?INF("await_stopped -> timeout for ~p",[Pid]), + erlang:demonitor(Ref), + ?FAIL({failed_stop,Pid}) + end. + + +start_agent(Config, Vsn) -> + start_agent(Config, Vsn, []). +start_agent(Config, Vsn, Opts) -> + ?LOG("start_agent -> entry (~p) with" + "~n Config: ~p" + "~n Vsn: ~p" + "~n Opts: ~p",[node(), Config, Vsn, Opts]), + + ?line AgentDir = ?config(agent_dir, Config), + ?line SaNode = ?config(snmp_sa, Config), + + snmp_app_env_init(vsn_init(Vsn) ++ + [{audit_trail_log, read_write_log}, + {audit_trail_log_dir, AgentDir}, + {audit_trail_log_size, {10240, 10}}, + {force_config_reload, false}, + {snmp_agent_type, master}, + {snmp_config_dir, AgentDir}, + {snmp_db_dir, AgentDir}, + {snmp_local_db_auto_repair, true}, + {snmp_master_agent_verbosity, trace}, + {snmp_supervisor_verbosity, trace}, + {snmp_mibserver_verbosity, trace}, + {snmp_symbolic_store_verbosity, trace}, + {snmp_note_store_verbosity, trace}, + {snmp_net_if_verbosity, trace}], + Opts), + + + process_flag(trap_exit,true), + + {ok, AppSup} = snmp_app_sup:start_link(), + unlink(AppSup), + ?DBG("start_agent -> snmp app supervisor: ~p",[AppSup]), + + ?DBG("start_agent -> start master agent (old style)",[]), + Sup = case (catch snmpa_app:start(normal)) of + {ok, S} -> + ?DBG("start_agent -> started, Sup: ~p",[S]), + S; + + Else -> + ?DBG("start_agent -> unknown result: ~n~p",[Else]), + %% Get info about the apps we depend on + MnesiaInfo = mnesia_running(), + ?FAIL({start_failed,Else,MnesiaInfo}) + end, + + ?DBG("start_agent -> unlink from supervisor",[]), + ?line unlink(Sup), + ?line SaDir = ?config(sa_dir, Config), + ?DBG("start_agent -> (rpc) start sub on ~p",[SaNode]), + ?line {ok, Sub} = rpc:call(SaNode, ?MODULE, start_sub, [SaDir]), + ?DBG("start_agent -> done",[]), + ?line [{snmp_sup, {Sup, self()}}, {snmp_sub, Sub} | Config]. + + +vsn_init(Vsn) -> + vsn_init([v1,v2,v3], Vsn, []). + +vsn_init([], _Vsn, Acc) -> + Acc; +vsn_init([V|Vsns], Vsn, Acc) -> + case lists:member(V, Vsn) of + true -> + vsn_init(Vsns, Vsn, [{V, true}|Acc]); + false -> + vsn_init(Vsns, Vsn, [{V, false}|Acc]) + end. + +snmp_app_env_init(Env0, Opts) -> + ?DBG("snmp_app_env_init -> unload snmp",[]), + ?line application:unload(snmp), + ?DBG("snmp_app_env_init -> load snmp",[]), + ?line application:load(snmp), + ?DBG("snmp_app_env_init -> initiate (snmp) application env",[]), + F1 = fun({Key,Val} = New, Acc0) -> + ?DBG("snmp_app_env_init -> " + "updating setting ~p to ~p", [Key, Val]), + case lists:keyreplace(Key, 1, Acc0, New) of + Acc0 -> + [New|Acc0]; + Acc -> + Acc + end + end, + Env = lists:foldr(F1, Env0, Opts), + ?DBG("snmp_app_env_init -> Env: ~p",[Env]), + F2 = fun({Key,Val}) -> + ?DBG("snmp_app_env_init -> setting ~p to ~p",[Key, Val]), + application_controller:set_env(snmp, Key, Val) + end, + lists:foreach(F2, Env). + + + + +%% Test if application is running +mnesia_running() -> ?IS_MNESIA_RUNNING(). +crypto_running() -> ?IS_CRYPTO_RUNNING(). + + +start_sub(Dir) -> + ?DBG("start_sub -> entry",[]), + Opts = [{db_dir, Dir}, + {supervisor, [{verbosity, trace}]}], + %% BMK BMK +% {ok, P} = snmp_supervisor:start_sub(Dir), + {ok, P} = snmpa_supervisor:start_sub_sup(Opts), + unlink(P), + {ok, {P, self()}}. + +create_tables(SaNode) -> + ?line {atomic, ok} = mnesia:create_table([{name, friendsTable2}, + {ram_copies, [SaNode]}, + {snmp, [{key, integer}]}, + {attributes, [a1,a2,a3]}]), + ?line {atomic, ok} = mnesia:create_table([{name, kompissTable2}, + {ram_copies, [SaNode]}, + {snmp, [{key, integer}]}, + {attributes, [a1,a2,a3]}]), + ?line {atomic, ok} = mnesia:create_table([{name, snmp_variables}, + {attributes, [a1,a2]}]). + +delete_tables() -> + mnesia:delete_table(friendsTable2), + mnesia:delete_table(kompissTable2), + mnesia:delete_table(snmp_variables). + +%% Creation is done in runtime! +delete_mib_storage_mnesia_tables() -> + mnesia:delete_table(snmpa_mib_data), + mnesia:delete_table(snmpa_mib_tree), + mnesia:delete_table(snmpa_symbolic_store). + +%%----------------------------------------------------------------- +%% A test case is always one of: +%% - v1 specific case +%% - v2 specific case +%% - v1 and v2 case +%% All v1 specific cases are prefixed with v1_, and all v2 with +%% v2_. E.g. v1_trap/v2_trap. +%% +%% All other cases are shared. However, the testserver uses the name +%% of the case to generate a file for that case. The same case cannot +%% be used in different configurations in the same suite. Therefore +%% all these functions exists in two variants, the base function +%% , and a second version _2. There may be several +%% versions as well, _N. +%%----------------------------------------------------------------- + + + + + + + + + +mib_storage_ets_cases() -> +[mse_simple, mse_v1_processing, mse_big, mse_big2, + mse_loop_mib, mse_api, mse_sa_register, mse_v1_trap, + mse_sa_error, mse_next_across_sa, mse_undo, + mse_standard_mib, mse_community_mib, mse_framework_mib, + mse_target_mib, mse_notification_mib, + mse_view_based_acm_mib, mse_sparse_table, mse_me_of, + mse_mib_of]. + +mib_storage_dets_cases() -> +[msd_simple, msd_v1_processing, msd_big, msd_big2, + msd_loop_mib, msd_api, msd_sa_register, msd_v1_trap, + msd_sa_error, msd_next_across_sa, msd_undo, + msd_standard_mib, msd_community_mib, msd_framework_mib, + msd_target_mib, msd_notification_mib, + msd_view_based_acm_mib, msd_sparse_table, msd_me_of, + msd_mib_of]. + +mib_storage_mnesia_cases() -> +[msm_simple, msm_v1_processing, msm_big, msm_big2, + msm_loop_mib, msm_api, msm_sa_register, msm_v1_trap, + msm_sa_error, msm_next_across_sa, msm_undo, + msm_standard_mib, msm_community_mib, msm_framework_mib, + msm_target_mib, msm_notification_mib, + msm_view_based_acm_mib, msm_sparse_table, msm_me_of, + msm_mib_of]. + +mse_size_check_cases() -> +[mse_size_check]. + +msd_size_check_cases() -> +[msd_size_check]. + +msm_size_check_cases() -> +[msm_size_check]. + +varm_mib_storage_dets_cases() -> +[msd_varm_mib_start]. + +varm_mib_storage_mnesia_cases() -> +[msm_varm_mib_start]. + +init_mib_storage_ets(Config) when list(Config) -> + ?LOG("init_mib_storage_ets -> entry", []), + MibStorage = {snmp_mib_storage,ets}, + init_ms(Config, [MibStorage]). + +init_mib_storage_dets(Config) when list(Config) -> + ?LOG("init_mib_storage_ets -> entry", []), + ?line AgentDir = ?GCONF(agent_dir, Config), + MibStorage = {snmp_mib_storage,{dets,AgentDir}}, + init_ms(Config, [MibStorage]). + +init_mib_storage_mnesia(Config) when list(Config) -> + ?LOG("init_mib_storage_ets -> entry", []), + MibStorage = {snmp_mib_storage,{mnesia,[]}}, + init_ms(Config, [MibStorage]). + +init_ms(Config, Opts) when list(Config) -> + ?LOG("init_mib_storage_ets -> entry", []), + ?line SaNode = ?GCONF(snmp_sa, Config), + ?line create_tables(SaNode), + ?line AgentDir = ?GCONF(agent_dir, Config), + ?line MgrDir = ?GCONF(mgr_dir, Config), + ?line Ip = ?GCONF(ip, Config), + ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, + MibsVerbosity = {snmp_mibserver_verbosity, trace}, + SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, + Opts1 = [MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity|Opts], + [{vsn, v1} | start_v1_agent(Config,Opts1)]. + +init_size_check_mse(Config) when list(Config) -> + MibStorage = {snmp_mib_storage, ets}, + init_size_check_ms(Config, [MibStorage]). + +init_size_check_msd(Config) when list(Config) -> + AgentDir = ?GCONF(agent_dir, Config), + MibStorage = {snmp_mib_storage, {dets, AgentDir}}, + init_size_check_ms(Config, [MibStorage]). + +init_size_check_msm(Config) when list(Config) -> + MibStorage = {snmp_mib_storage, {mnesia,[]}}, + init_size_check_ms(Config, [MibStorage]). + +init_size_check_ms(Config, Opts) when list(Config) -> + SaNode = ?GCONF(snmp_sa, Config), + %% We are using v3 here, so crypto must be supported or else... + case ?CRYPTO_START() of + ok -> + case ?CRYPTO_SUPPORT() of + {no, Reason} -> + ?SKIP({unsupported_encryption, Reason}); + yes -> + ok + end; + {error, Reason} -> + ?SKIP({failed_starting_crypto, Reason}) + end, + create_tables(SaNode), + AgentDir = ?GCONF(agent_dir, Config), + MgrDir = ?GCONF(mgr_dir, Config), + Ip = ?GCONF(ip, Config), + ?line ok = + config([v3], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v3} | start_agent(Config, [v3], Opts)]. + +init_varm_mib_storage_dets(Config) when list(Config) -> + ?LOG("init_varm_mib_storage_dets -> entry", []), + ?line SaNode = ?GCONF(snmp_sa, Config), + ?line create_tables(SaNode), + ?line AgentDir = ?GCONF(agent_dir, Config), + ?line MgrDir = ?GCONF(mgr_dir, Config), + ?line Ip = ?GCONF(ip, Config), + ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + MibStorage = {snmp_mib_storage,{dets,AgentDir}}, + MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, + MibsVerbosity = {snmp_mibserver_verbosity, trace}, + SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, + Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity], + [{vsn, v1}, {agent_opts,Opts} | Config]. + +init_varm_mib_storage_mnesia(Config) when list(Config) -> + ?LOG("init_varm_mib_storage_mnesia -> entry", []), + ?line SaNode = ?GCONF(snmp_sa, Config), + ?line create_tables(SaNode), + ?line AgentDir = ?GCONF(agent_dir, Config), + ?line MgrDir = ?GCONF(mgr_dir, Config), + ?line Ip = ?GCONF(ip, Config), + ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + MibStorage = {snmp_mib_storage,{mnesia,[]}}, + MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, + MibsVerbosity = {snmp_mibserver_verbosity, trace}, + SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, + Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity], + [{vsn, v1}, {agent_opts,Opts} | Config]. + +finish_mib_storage_ets(Config) when list(Config) -> + ?LOG("finish_mib_storage_ets -> entry", []), + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + C2 = lists:keydelete(vsn, 1, C1), + lists:keydelete(agent_opts, 1, C2). + +finish_mib_storage_dets(Config) when list(Config) -> + ?LOG("finish_mib_storage_dets -> entry", []), + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + C2 = lists:keydelete(vsn, 1, C1), + lists:keydelete(agent_opts, 1, C2). + +finish_mib_storage_mnesia(Config) when list(Config) -> + ?LOG("finish_mib_storage_mnesia -> entry", []), + delete_tables(), + delete_mib_storage_mnesia_tables(), + C1 = stop_agent(Config), + delete_files(C1), + C2 = lists:keydelete(vsn, 1, C1), + lists:keydelete(agent_opts, 1, C2). + +finish_varm_mib_storage_dets(Config) when list(Config) -> + ?LOG("finish_varm_mib_storage_dets -> entry", []), + delete_tables(), + %% C1 = stop_agent(Config), % In case something went wrong... + delete_files(Config), + C2 = lists:keydelete(vsn, 1, Config), + lists:keydelete(agent_opts, 1, C2). + +finish_varm_mib_storage_mnesia(Config) when list(Config) -> + ?LOG("finish_varm_mib_storage_mnesia -> entry", []), + delete_tables(), + delete_mib_storage_mnesia_tables(), + %% C1 = stop_agent(Config), % In case something went wrong... + delete_files(Config), + C2 = lists:keydelete(vsn, 1, Config), + lists:keydelete(agent_opts, 1, C2). + +finish_size_check_mse(Config) when list(Config) -> + finish_size_check_ms(Config). + +finish_size_check_msd(Config) when list(Config) -> + finish_size_check_ms(Config). + +finish_size_check_msm(Config) when list(Config) -> + finish_size_check_ms(Config). + +finish_size_check_ms(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + + +%% These are just interface functions to fool the test server +mse_simple(X) -> simple(X). +mse_v1_processing(X) -> v1_processing(X). +mse_big(X) -> big(X). +mse_big2(X) -> big2(X). +mse_loop_mib(X) -> loop_mib(X). +mse_api(X) -> api(X). +mse_sa_register(X) -> sa_register(X). +mse_v1_trap(X) -> v1_trap(X). +mse_sa_error(X) -> sa_error(X). +mse_next_across_sa(X) -> next_across_sa(X). +mse_undo(X) -> undo(X). +mse_standard_mib(X) -> snmp_standard_mib(X). +mse_community_mib(X) -> snmp_community_mib(X). +mse_framework_mib(X) -> snmp_framework_mib(X). +mse_target_mib(X) -> snmp_target_mib(X). +mse_notification_mib(X) -> snmp_notification_mib(X). +mse_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). +mse_sparse_table(X) -> sparse_table(X). +mse_me_of(X) -> ms_me_of(X). +mse_mib_of(X) -> ms_mib_of(X). + +msd_simple(X) -> simple(X). +msd_v1_processing(X) -> v1_processing(X). +msd_big(X) -> big(X). +msd_big2(X) -> big2(X). +msd_loop_mib(X) -> loop_mib(X). +msd_api(X) -> api(X). +msd_sa_register(X) -> sa_register(X). +msd_v1_trap(X) -> v1_trap(X). +msd_sa_error(X) -> sa_error(X). +msd_next_across_sa(X) -> next_across_sa(X). +msd_undo(X) -> undo(X). +msd_standard_mib(X) -> snmp_standard_mib(X). +msd_community_mib(X) -> snmp_community_mib(X). +msd_framework_mib(X) -> snmp_framework_mib(X). +msd_target_mib(X) -> snmp_target_mib(X). +msd_notification_mib(X) -> snmp_notification_mib(X). +msd_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). +msd_sparse_table(X) -> sparse_table(X). +msd_me_of(X) -> ms_me_of(X). +msd_mib_of(X) -> ms_mib_of(X). + +msm_simple(X) -> simple(X). +msm_v1_processing(X) -> v1_processing(X). +msm_big(X) -> big(X). +msm_big2(X) -> big2(X). +msm_loop_mib(X) -> loop_mib(X). +msm_api(X) -> api(X). +msm_sa_register(X) -> sa_register(X). +msm_v1_trap(X) -> v1_trap(X). +msm_sa_error(X) -> sa_error(X). +msm_next_across_sa(X) -> next_across_sa(X). +msm_undo(X) -> undo(X). +msm_standard_mib(X) -> snmp_standard_mib(X). +msm_community_mib(X) -> snmp_community_mib(X). +msm_framework_mib(X) -> snmp_framework_mib(X). +msm_target_mib(X) -> snmp_target_mib(X). +msm_notification_mib(X) -> snmp_notification_mib(X). +msm_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). +msm_sparse_table(X) -> sparse_table(X). +msm_me_of(X) -> ms_me_of(X). +msm_mib_of(X) -> ms_mib_of(X). + + +mse_size_check(X) -> p("mse_size_check..."), ms_size_check(X). +msd_size_check(X) -> p("msd_size_check..."), ms_size_check(X). +msm_size_check(X) -> p("msm_size_check..."), ms_size_check(X). + +msd_varm_mib_start(X) -> p("msd_varm_mib_start..."), varm_mib_start(X). +msm_varm_mib_start(X) -> p("msm_varm_mib_start..."), varm_mib_start(X). + +ms_size_check(suite) -> []; +ms_size_check(Config) when list(Config) -> + p("ms_size_check..."), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?LOG("mib server size check...", []), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + ?line load_master_std("OTP-SNMPEA-MIB"), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-MPD-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-USER-BASED-SM-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + ?line load_master_std("SNMPv2-MIB"), + ?line load_master_std("SNMPv2-TM"), + + ?SLEEP(2000), + + ?line display_memory_usage(), + + ?line unload_master("OTP-SNMPEA-MIB"), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?line unload_master("SNMP-MPD-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-USER-BASED-SM-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + ?line unload_master("SNMPv2-MIB"), + ?line unload_master("SNMPv2-TM"), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + + ok. + + +varm_mib_start(suite) -> []; +varm_mib_start(Config) when list(Config) -> + p("varm_mib_start..."), + ?LOG("varm_mib_start -> entry", []), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + %% Start the agent + Opts = ?GCONF(agent_opts, Config), + Config1 = start_v1_agent(Config, Opts), + + %% Sleep some in order for the agent to start properly + ?DBG("varm_mib_start -> sleep some (before loading mobs)", []), + ?SLEEP(5000), + + %% Load all the mibs + HardwiredMibs = loaded_mibs(), + ?DBG("varm_mib_start -> load all mibs", []), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + + %% Unload the hardwired mibs + ?DBG("varm_mib_start -> sleep some (before unloading hardwired mibs)", []), + ?SLEEP(1000), + ?DBG("varm_mib_start -> unload (hardwired) mibs", []), + ?line unload_mibs(HardwiredMibs), %% unload hardwired + + ?DBG("varm_mib_start -> sleep some (before stopping agent)", []), + ?SLEEP(1000), + + %% Stop the agent (without deleting the stored files) + ?DBG("varm_mib_start -> stop the agent", []), + Config2 = stop_agent(Config1), + + %% Sleep some in order for the agent to stop properly + ?DBG("varm_mib_start -> sleep some (before re-starting the agent)", []), + ?SLEEP(5000), + + %% Start the agent (again) + ?DBG("varm_mib_start -> start the agent", []), + Config3 = start_v1_agent(Config2, Opts), + + ?DBG("varm_mib_start -> sleep some (before starting tests)", []), + ?SLEEP(5000), + + %% Perform the test(s) + ?DBG("varm_mib_start -> perform the tests", []), + try_test(snmp_community_mib), + try_test(snmp_framework_mib), + try_test(snmp_target_mib), + try_test(snmp_notification_mib), + + %% Stop the agent (without deleting the stored files) + ?DBG("varm_mib_start -> stop the agent", []), + stop_agent(Config3), + ok. + + +-define(snmpTrapCommunity_instance, [1,3,6,1,6,3,18,1,4,0]). +-define(vacmViewSpinLock_instance, [1,3,6,1,6,3,16,1,5,1,0]). +-define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). + +ms_me_of(suite) -> []; +ms_me_of(Config) when list(Config) -> + p("ms_me_of..."), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + ?line load_master_std("OTP-SNMPEA-MIB"), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-MPD-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + + ?SLEEP(2000), + + ?line display_memory_usage(), + + + ?DBG("ms_me_of -> find ~w from SNMP-COMMUNITY-MIB", + [?snmpTrapCommunity_instance]), + ?line ok = me_of(?snmpTrapCommunity_instance), + + ?DBG("ms_me_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", + [?vacmViewSpinLock_instance]), + ?line ok = me_of(?vacmViewSpinLock_instance), + + ?DBG("ms_me_of -> find ~w from SNMP-USER-BASED-SM-MIB", + [?usmStatsNotInTimeWindows_instance]), + ?line {error, _} = me_of(?usmStatsNotInTimeWindows_instance), + + + ?line unload_master("OTP-SNMPEA-MIB"), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?line unload_master("SNMP-MPD-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + + ok. + +me_of(Oid) -> + case snmpa:me_of(Oid) of + {ok, #me{oid = Oid}} -> + ok; + {ok, #me{oid = OtherOid}} -> + case lists:reverse(Oid) of + [0|Rest] -> + case lists:reverse(Rest) of + OtherOid -> + ok; + AnotherOid -> + {error, {invalid_oid, Oid, AnotherOid}} + end; + _ -> + {error, {invalid_oid, Oid, OtherOid}} + end; + {error, Reason} -> + {error, Reason}; + Else -> + {error, Else} + end. + + +ms_mib_of(suite) -> []; +ms_mib_of(Config) when list(Config) -> + p("ms_mib_of..."), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + ?line load_master_std("OTP-SNMPEA-MIB"), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-MPD-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + + ?SLEEP(2000), + + ?line display_memory_usage(), + + + ?DBG("ms_mib_of -> find ~w from SNMP-COMMUNITY-MIB", + [?snmpTrapCommunity_instance]), + ?line ok = mib_of(?snmpTrapCommunity_instance, 'SNMP-COMMUNITY-MIB'), + + ?DBG("ms_mib_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", + [?vacmViewSpinLock_instance]), + ?line ok = mib_of(?vacmViewSpinLock_instance, 'SNMP-VIEW-BASED-ACM-MIB'), + + ?DBG("ms_mib_of -> find ~w from SNMP-USER-BASED-SM-MIB", + [?usmStatsNotInTimeWindows_instance]), + ?line {error, _} = mib_of(?usmStatsNotInTimeWindows_instance, + 'SNMP-USER-BASED-SM-MIB'), + + + ?line unload_master("OTP-SNMPEA-MIB"), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?line unload_master("SNMP-MPD-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + + ok. + +mib_of(Oid, ExpectedMibName) -> + ?DBG("mib_of -> entry with" + "~n Oid: ~p" + "~n ExpectedMibName: ~p", [Oid, ExpectedMibName]), + %% case snmpa:mib_of(Oid) of + MibOf = snmpa:mib_of(Oid), + ?DBG("mib_of -> MibOf: ~n~p", [MibOf]), + case MibOf of + {ok, ExpectedMibName} -> + ok; + {ok, OtherMibName} -> + {error, {invalid_mib, ExpectedMibName, OtherMibName}}; + {error, Reason} -> + {error, Reason}; + Else -> + ?DBG("mib_of -> Else: ~n~p", [Else]), + {error, Else} + end. + + +app_info(suite) -> []; +app_info(Config) when list(Config) -> + SnmpDir = app_dir(snmp), + SslDir = app_dir(ssl), + CryptoDir = app_dir(crypto), + Attr = snmp:module_info(attributes), + AppVsn = + case lists:keysearch(app_vsn, 1, Attr) of + {value, {app_vsn, V}} -> + V; + false -> + "undefined" + end, + io:format("Root dir: ~s~n" + "SNMP: Application dir: ~s~n" + " Application ver: ~s~n" + "SSL: Application dir: ~s~n" + "CRYPTO: Application dir: ~s~n", + [code:root_dir(), SnmpDir, AppVsn, SslDir, CryptoDir]), + ok. + +app_dir(App) -> + case code:lib_dir(App) of + D when list(D) -> + filename:basename(D); + {error, _Reason} -> + "undefined" + end. + + + +%v1_cases() -> [loop_mib]; +v1_cases() -> +[simple, db_notify_client, v1_processing, big, big2, + loop_mib, api, subagent, mnesia, {group, multiple_reqs}, + sa_register, v1_trap, sa_error, next_across_sa, undo, + {group, reported_bugs}, {group, standard_mibs}, + sparse_table, cnt_64, opaque, change_target_addr_config]. + +init_v1(Config) when list(Config) -> + ?line SaNode = ?config(snmp_sa, Config), + ?line create_tables(SaNode), + ?line AgentDir = ?config(agent_dir, Config), + ?line MgrDir = ?config(mgr_dir, Config), + ?line Ip = ?config(ip, Config), + ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v1} | start_v1_agent(Config)]. + +finish_v1(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + + +%v2_cases() -> [loop_mib_2]; +v2_cases() -> +[simple_2, v2_processing, big_2, big2_2, loop_mib_2, + api_2, subagent_2, mnesia_2, {group, multiple_reqs_2}, + sa_register_2, v2_trap, {group, v2_inform}, sa_error_2, + next_across_sa_2, undo_2, {group, reported_bugs_2}, + {group, standard_mibs_2}, v2_types, implied, + sparse_table_2, cnt_64_2, opaque_2, v2_caps]. + +init_v2(Config) when list(Config) -> + SaNode = ?config(snmp_sa, Config), + create_tables(SaNode), + AgentDir = ?config(agent_dir, Config), + MgrDir = ?config(mgr_dir, Config), + Ip = ?config(ip, Config), + config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v2} | start_v2_agent(Config)]. + +finish_v2(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + + +v1_v2_cases() -> +[simple_bi]. + +init_v1_v2(Config) when list(Config) -> + SaNode = ?config(snmp_sa, Config), + create_tables(SaNode), + AgentDir = ?config(agent_dir, Config), + MgrDir = ?config(mgr_dir, Config), + Ip = ?config(ip, Config), + config([v1,v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, bilingual} | start_bilingual_agent(Config)]. + +finish_v1_v2(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + + +%v3_cases() -> [loop_mib_3]; +v3_cases() -> +[simple_3, v3_processing, big_3, big2_3, api_3, + subagent_3, mnesia_3, loop_mib_3, multiple_reqs_3, + sa_register_3, v3_trap, v3_inform, sa_error_3, + next_across_sa_3, undo_3, {group, reported_bugs_3}, + {group, standard_mibs_3}, {group, v3_security}, + v2_types_3, implied_3, sparse_table_3, cnt_64_3, + opaque_3, v2_caps_3]. + +init_v3(Config) when list(Config) -> + %% Make sure crypto works, otherwise start_agent will fail + %% and we will be stuck with a bunch of mnesia tables for + %% the rest of this suite... + ?DBG("start_agent -> start crypto app",[]), + case os:type() of + vxworks -> + no_crypto; + _ -> + case ?CRYPTO_START() of + ok -> + case ?CRYPTO_SUPPORT() of + {no, Reason} -> + ?SKIP({unsupported_encryption, Reason}); + yes -> + ok + end; + {error, Reason} -> + ?SKIP({failed_starting_crypto, Reason}) + end + end, + SaNode = ?config(snmp_sa, Config), + create_tables(SaNode), + AgentDir = ?config(agent_dir, Config), + MgrDir = ?config(mgr_dir, Config), + Ip = ?config(ip, Config), + ?line ok = config([v3], MgrDir, AgentDir, + tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v3} | start_v3_agent(Config)]. + +finish_v3(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + + +mt_cases() -> +[multi_threaded, mt_trap]. + +init_mt(Config) when list(Config) -> + SaNode = ?config(snmp_sa, Config), + create_tables(SaNode), + AgentDir = ?config(agent_dir, Config), + MgrDir = ?config(mgr_dir, Config), + Ip = ?config(ip, Config), + ?line ok = config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v2} | start_multi_threaded_agent(Config)]. + +finish_mt(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + +%% This one *must* be run first in each case. +init_case(Config) when list(Config) -> + ?DBG("init_case -> entry with" + "~n Config: ~p", [Config]), + SaNode = ?config(snmp_sa, Config), + MgrNode = ?config(snmp_mgr, Config), + MasterNode = node(), + + SaHost = ?HOSTNAME(SaNode), + MgrHost = ?HOSTNAME(MgrNode), + MasterHost = ?HOSTNAME(MasterNode), + {ok, MasterIP} = snmp_misc:ip(MasterHost), + {ok, MIP} = snmp_misc:ip(MgrHost), + {ok, SIP} = snmp_misc:ip(SaHost), + + + put(mgr_node, MgrNode), + put(sa_node, SaNode), + put(master_node, MasterNode), + put(sa_host, SaHost), + put(mgr_host, MgrHost), + put(master_host, MasterHost), + put(mip, tuple_to_list(MIP)), + put(masterip , tuple_to_list(MasterIP)), + put(sip, tuple_to_list(SIP)), + + MibDir = ?config(mib_dir, Config), + put(mib_dir, MibDir), + StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", + put(std_mib_dir, StdM), + + MgrDir = ?config(mgr_dir, Config), + put(mgr_dir, MgrDir), + + put(vsn, ?config(vsn, Config)), + ?DBG("init_case -> exit with" + "~n MasterNode: ~p" + "~n SaNode: ~p" + "~n MgrNode: ~p" + "~n MibDir: ~p", [MasterNode, SaNode, MgrNode, MibDir]), + {SaNode, MgrNode, MibDir}. + +load_master(Mib) -> + ?DBG("load_master -> entry with" + "~n Mib: ~p", [Mib]), + snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety + ok = snmpa:load_mibs(snmp_master_agent, [get(mib_dir) ++ Mib]). + +load_master_std(Mib) -> + ?DBG("load_master_std -> entry with" + "~n Mib: ~p", [Mib]), + snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety + ok = snmpa:load_mibs(snmp_master_agent, [get(std_mib_dir) ++ Mib]). + +unload_master(Mib) -> + ?DBG("unload_master -> entry with" + "~n Mib: ~p", [Mib]), + ok = snmpa:unload_mibs(snmp_master_agent, [Mib]). + +loaded_mibs() -> + ?DBG("loaded_mibs -> entry",[]), + Info = snmpa:info(snmp_master_agent), + {value, {loaded_mibs, Mibs}} = lists:keysearch(loaded_mibs, 1, Info), + [atom_to_list(Mib) || {Mib,_,_} <- Mibs]. + +unload_mibs(Mibs) -> + ?DBG("unload_mibs -> entry with" + "~n Mibs: ~p", [Mibs]), + ok = snmpa:unload_mibs(snmp_master_agent, Mibs). + +start_subagent(SaNode, RegTree, Mib) -> + ?DBG("start_subagent -> entry with" + "~n SaNode: ~p" + "~n RegTree: ~p" + "~n Mib: ~p", [SaNode, RegTree, Mib]), + MA = whereis(snmp_master_agent), + ?DBG("start_subagent -> MA: ~p", [MA]), + MibDir = get(mib_dir), + Mib1 = join(MibDir,Mib), + %% BMK BMK +% case rpc:call(SaNode,snmp_supervisor,start_subagent,[MA,RegTree,[Mib1]]) of + case rpc:call(SaNode, snmpa_supervisor, + start_sub_agent, [MA, RegTree, [Mib1]]) of + {ok, SA} -> + ?DBG("start_subagent -> SA: ~p", [SA]), + {ok, SA}; + Error -> + ?FAIL({subagent_start_failed, SaNode, Error, [MA, RegTree, Mib1]}) + end. + +stop_subagent(SA) -> + ?DBG("stop_subagent -> entry with" + "~n SA: ~p", [SA]), + %% BNK BMK + %% rpc:call(node(SA), snmp_supervisor, stop_subagent, [SA]). + rpc:call(node(SA), snmpa_supervisor, stop_sub_agent, [SA]). + +%%----------------------------------------------------------------- +%% This function takes care of the old OTP-SNMPEA-MIB. +%% Unfortunately, the testcases were written to use the data in the +%% internal tables, and these table are now obsolete and not used +%% by the agent. Therefore, we emulate them by using +%% OLD-SNMPEA-MIB, which uses the default impl. of all tables. +%% +%% These two rows must exist in intCommunityTable +%% {[147,214,36,45], "public", 2, readWrite}. +%% {[147,214,36,45], "standard trap", 2, read}. +%% (But with the manager's IP address) +%% +%%----------------------------------------------------------------- +init_old() -> + snmpa_local_db:table_create_row(intCommunityTable, + get(mip) ++ [6 | "public"], + {get(mip), "public", 2, 2}), + snmpa_local_db:table_create_row(intCommunityTable, + get(mip) ++ [13 | "standard trap"], + {get(mip), "standard trap", 2, 1}), + snmpa_local_db:variable_set(intAgentIpAddress, [127,0,0,1]). + + + +simple(suite) -> []; +simple(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + try_test(simple_standard_test). + +simple_2(X) -> simple(X). + +simple_bi(suite) -> []; +simple_bi(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + put(vsn, v1), % First, try v1 manager + try_test(simple_standard_test), + + put(vsn, v2), % Then, try v2 manager + try_test(simple_standard_test). + +simple_3(X) -> + simple(X). + +big(suite) -> []; +big(Config) when list(Config) -> + ?DBG("big -> entry", []), + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Starting subagent..."), + ?line pong = net_adm:ping(SaNode), + + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), + ?DBG("big -> SA: ~p", [SA]), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(big_test), + ?line stop_subagent(SA), + ?line unload_master("OLD-SNMPEA-MIB"). + +big_2(X) -> big(X). + +big_3(X) -> big(X). + + +big2(suite) -> []; +big2(Config) when list(Config) -> + %% This is exactly the same tests as 'big', but with the + %% v2 equivalent of the mibs. + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Starting subagent..."), + ?line pong = net_adm:ping(SaNode), + + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1-v2"), + ?line load_master("OLD-SNMPEA-MIB-v2"), + ?line init_old(), + try_test(big_test), + ?line stop_subagent(SA), + ?line unload_master("OLD-SNMPEA-MIB-v2"). + +big2_2(X) -> big2(X). + +big2_3(X) -> big2(X). + + +multi_threaded(suite) -> []; +multi_threaded(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test1"), + try_test(multi_threaded_test), + ?line unload_master("Test1"). + +mt_trap(suite) -> []; +mt_trap(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line load_master("Test1"), + ?line load_master("TestTrapv2"), + try_test(mt_trap_test, [MA]), + ?line unload_master("TestTrapv2"), + ?line unload_master("Test1"). + +v2_types(suite) -> []; +v2_types(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test1"), + try_test(types_v2_test), + ?line unload_master("Test1"). + +v2_types_3(X) -> v2_types(X). + + +implied(suite) -> []; +implied(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line load_master("Test1"), + try_test(implied_test,[MA]), + ?line unload_master("Test1"). + +implied_3(X) -> implied(X). + + +sparse_table(suite) -> []; +sparse_table(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test1"), + try_test(sparse_table_test), + ?line unload_master("Test1"). + +sparse_table_2(X) -> sparse_table(X). + +sparse_table_3(X) -> sparse_table(X). + +cnt_64(suite) -> []; +cnt_64(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line load_master("Test1"), + try_test(cnt_64_test, [MA]), + ?line unload_master("Test1"). + +cnt_64_2(X) -> cnt_64(X). + +cnt_64_3(X) -> cnt_64(X). + +opaque(suite) -> []; +opaque(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test1"), + try_test(opaque_test), + ?line unload_master("Test1"). + +opaque_2(X) -> opaque(X). + +opaque_3(X) -> opaque(X). + + +change_target_addr_config(suite) -> []; +change_target_addr_config(Config) when list(Config) -> + p("Testing changing target address config..."), + ?LOG("change_target_addr_config -> entry",[]), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + put(sname,snmp_suite), + put(verbosity,trace), + + MA = whereis(snmp_master_agent), + + ?LOG("change_target_addr_config -> load TestTrap",[]), + ?line load_master("TestTrap"), + + ?LOG("change_target_addr_config -> set trace verbosity for local_db",[]), + ?line snmpa:verbosity(local_db,trace), + + %% First send some traps that will arive att the original manager + ?LOG("change_target_addr_config -> send trap",[]), + try_test(ma_trap1, [MA]), + + ?LOG("change_target_addr_config -> set silence verbosity for local_db",[]), + ?line snmpa:verbosity(local_db,silence), + + %% Start new dummy listener + ?LOG("change_target_addr_config -> start dummy manager",[]), + ?line {ok,Pid,NewPort} = dummy_manager_start(MA), + + %% Reconfigure + ?LOG("change_target_addr_config -> reconfigure",[]), + AgentDir = ?config(agent_dir, Config), + ?line rewrite_target_addr_conf(AgentDir, NewPort), + ?line snmp_target_mib:reconfigure(AgentDir), + + %% Send the trap again + ?LOG("change_target_addr_config -> send trap again",[]), + catch dummy_manager_send_trap2(Pid), + + ?LOG("change_target_addr_config -> await trap ack",[]), + catch dummy_manager_await_trap2_ack(), + + ?LOG("change_target_addr_config -> stop dummy manager",[]), + ?line ok = dummy_manager_stop(Pid), + + ?LOG("change_target_addr_config -> reset target address config",[]), + ?line reset_target_addr_conf(AgentDir), + + ?LOG("change_target_addr_config -> unload TestTrap",[]), + ?line unload_master("TestTrap"). + + +dummy_manager_start(MA) -> + ?DBG("dummy_manager_start -> entry",[]), + Pid = spawn(get(mgr_node), ?MODULE,dummy_manager_init,[self(),MA]), + ?DBG("dummy_manager_start -> Pid: ~p",[Pid]), + await_dummy_manager_started(Pid). + +await_dummy_manager_started(Pid) -> + receive + {dummy_manager_started,Pid,Port} -> + ?DBG("dummy_manager_start -> acknowledge received with" + "~n Port: ~p",[Port]), + {ok,Pid,Port}; + {'EXIT', Pid, Reason} -> + {error, Pid, Reason}; + O -> + ?LOG("dummy_manager_start -> received unknown message:" + "~n ~p",[O]), + await_dummy_manager_started(Pid) + end. + +dummy_manager_stop(Pid) -> + ?DBG("dummy_manager_stop -> entry with Pid: ~p",[Pid]), + Pid ! stop, + receive + {dummy_manager_stopping, Pid} -> + ?DBG("dummy_manager_stop -> acknowledge received",[]), + ok + after 10000 -> + ?ERR("dummy_manager_stop -> timeout",[]), + timeout + end. + +dummy_manager_send_trap2(Pid) -> + ?DBG("dummy_manager_send_trap2 -> entry",[]), + Pid ! {send_trap,testTrap2}. + +dummy_manager_await_trap2_ack() -> + ?DBG("dummy_manager_await_trap2 -> entry",[]), + receive + {received_trap,Trap} -> + ?LOG("dummy_manager_await_trap2 -> received trap: ~p",[Trap]), + %% Note: + %% Without this sleep the v2_inform_i testcase failes! There + %% is no relation between these two test cases as far as I + %% able to figure out... + sleep(60000), + ok; + O -> + ?ERR("dummy_manager_await_trap2 -> unexpected message: ~p",[O]), + ok + after 10000 -> + ?ERR("dummy_manager_await_trap2 -> timeout",[]), + timeout + end. + +dummy_manager_init(Parent,MA) -> + ?DBG("dummy_manager_init -> entry with" + "~n Parent: ~p" + "~n MA: ~p",[Parent,MA]), + {ok,S} = gen_udp:open(0,[{recbuf,65535}]), + ?DBG("dummy_manager_init -> S: ~p",[S]), + {ok,Port} = inet:port(S), + ?DBG("dummy_manager_init -> Port: ~p",[Port]), + Parent ! {dummy_manager_started,self(),Port}, + dummy_manager_loop(Parent,S,MA). + +dummy_manager_loop(P,S,MA) -> + ?LOG("dummy_manager_loop -> ready for receive",[]), + receive + {send_trap,Trap} -> + ?LOG("dummy_manager_loop -> received trap send request" + "~n Trap: ~p",[Trap]), + snmpa:send_trap(MA, Trap, "standard trap"), + dummy_manager_loop(P,S,MA); + {udp, _UdpId, Ip, UdpPort, Bytes} -> + ?LOG("dummy_manager_loop -> received upd message" + "~n from: ~p:~p" + "~n size: ~p", + [Ip, UdpPort, dummy_manager_message_sz(Bytes)]), + R = dummy_manager_handle_message(Bytes), + ?DBG("dummy_manager_loop -> R: ~p",[R]), + P ! R, + dummy_manager_loop(P,S,MA); + stop -> + ?DBG("dummy_manager_loop -> received stop request",[]), + P ! {dummy_manager_stopping, self()}, + gen_udp:close(S), + exit(normal); + O -> + ?LOG("dummy_manager_loop -> received unknown message:" + "~n ~p",[O]), + dummy_manager_loop(P,S,MA) + end. + +dummy_manager_message_sz(B) when binary(B) -> + size(B); +dummy_manager_message_sz(L) when list(L) -> + length(L); +dummy_manager_message_sz(_) -> + undefined. + +dummy_manager_handle_message(Bytes) -> + case (catch snmp_pdus:dec_message(Bytes)) of + {'EXIT',Reason} -> + ?ERR("dummy_manager_handle_message -> " + "failed decoding message only:~n ~p",[Reason]), + {error,Reason}; + M -> + ?DBG("dummy_manager_handle_message -> decoded message:" + "~n ~p",[M]), + {received_trap,M} + end. + + +api(suite) -> []; +api(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(api_test, [node()]), + ?line unload_master("OLD-SNMPEA-MIB"). + +api_2(X) -> api(X). + +api_3(X) -> api(X). + + +subagent(suite) -> []; +subagent(Config) when list(Config) -> + {SaNode, _MgrNode, MibDir} = init_case(Config), + + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), + try_test(load_test_sa), + + p("Testing unregister subagent..."), + MA = whereis(snmp_master_agent), + rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), + try_test(unreg_test), + + p("Loading previous subagent mib in master and testing..."), + ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas1"]), + try_test(load_test), + + p("Unloading previous subagent mib in master and testing..."), + ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas1"]), + try_test(unreg_test), + p("Testing register subagent..."), + rpc:call(SaNode, snmp, register_subagent, + [MA, ?klas1, SA]), + try_test(load_test_sa), + + ?line stop_subagent(SA), + try_test(unreg_test). + +subagent_2(X) -> subagent(X). + +subagent_3(X) -> subagent(X). + + +mnesia(suite) -> []; +mnesia(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Starting subagent with mnesia impl..."), + {ok, SA} = start_subagent(SaNode, ?klas2, "Klas2"), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + + try_test(big_test_2), + + p("Testing unregister subagent..."), + MA = whereis(snmp_master_agent), + rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), + try_test(unreg_test), + ?line unload_master("OLD-SNMPEA-MIB"), + ?line stop_subagent(SA). + +mnesia_2(X) -> mnesia(X). + +mnesia_3(X) -> mnesia(X). + + + +mul_cases() -> +[mul_get, mul_get_err, mul_next, mul_next_err, + mul_set_err]. + + +multiple_reqs_3(_X) -> + {req, [], {conf, init_mul, mul_cases_3(), finish_mul}}. + + +mul_cases_2() -> +[mul_get_2, mul_get_err_2, mul_next_2, mul_next_err_2, + mul_set_err_2]. + + +mul_cases_3() -> + [mul_get_3, mul_get_err_3, mul_next_3, mul_next_err_3, mul_set_err_3]. + + +init_mul(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + [{mul_sub, SA} | Config]. + +finish_mul(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + SA = ?config(mul_sub, Config), + + ?line unload_master("OLD-SNMPEA-MIB"), + ?line stop_subagent(SA), + lists:keydelete(mul_sub, 1, Config). + +mul_get(suite) -> []; +mul_get(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple get..."), + try_test(do_mul_get). + +mul_get_2(X) -> mul_get(X). + +mul_get_3(X) -> mul_get(X). + + +mul_get_err(suite) -> []; +mul_get_err(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple get with error..."), + try_test(do_mul_get_err). + +mul_get_err_2(X) -> mul_get_err(X). + +mul_get_err_3(X) -> mul_get_err(X). + + +mul_next(suite) -> []; +mul_next(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple next..."), + try_test(do_mul_next). + +mul_next_2(X) -> mul_next(X). + +mul_next_3(X) -> mul_next(X). + + +mul_next_err(suite) -> []; +mul_next_err(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple next..."), + try_test(do_mul_next_err). + +mul_next_err_2(X) -> mul_next_err(X). + +mul_next_err_3(X) -> mul_next_err(X). + + +mul_set(suite) -> []; +mul_set(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple set..."), + try_test(do_mul_set). + +mul_set_2(X) -> mul_set(X). + +mul_set_3(X) -> mul_set(X). + + +mul_set_err(suite) -> []; +mul_set_err(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple set with error..."), + try_test(do_mul_set_err). + +mul_set_err_2(X) -> mul_set_err(X). + +mul_set_err_3(X) -> mul_set_err(X). + + +sa_register(suite) -> []; +sa_register(Config) when list(Config) -> + ?DBG("sa_register -> entry", []), + {SaNode, _MgrNode, MibDir} = init_case(Config), + + ?DBG("sa_register -> start subagent", []), + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), + + ?DBG("sa_register -> unregister subagent", []), + p("Testing unregister subagent (2)..."), + MA = whereis(snmp_master_agent), + rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), + try_test(unreg_test), + + p("Loading SA-MIB..."), + ?DBG("sa_register -> unload mibs", []), + snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), + ?DBG("sa_register -> unload mibs", []), + snmpa:load_mibs(SA, [MibDir ++ "SA-MIB"]), + ?DBG("sa_register -> register subagent", []), + rpc:call(SaNode, snmp, register_subagent, [MA,?sa,SA]), + try_test(sa_mib), + + ?DBG("sa_register -> stop subagent", []), + ?line stop_subagent(SA). + +sa_register_2(X) -> sa_register(X). + +sa_register_3(X) -> sa_register(X). + + +v1_trap(suite) -> []; +v1_trap(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Testing trap sending from master agent..."), + MA = whereis(snmp_master_agent), + + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(ma_trap1, [MA]), + try_test(ma_trap2, [MA]), + try_test(ma_v2_2_v1_trap, [MA]), + try_test(ma_v2_2_v1_trap2, [MA]), + + p("Testing trap sending from subagent..."), + try_test(sa_trap1, [SA]), + try_test(sa_trap2, [SA]), + try_test(sa_trap3, [SA]), + + ?line unload_master("TestTrap"), + ?line unload_master("TestTrapv2"), + + ?line stop_subagent(SA). + +v2_trap(suite) -> []; +v2_trap(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Testing trap sending from master agent..."), + MA = whereis(snmp_master_agent), + + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + + try_test(ma_v2_trap1, [MA]), + try_test(ma_v2_trap2, [MA]), + try_test(ma_v1_2_v2_trap, [MA]), + try_test(ma_v1_2_v2_trap2, [MA]), + + try_test(sa_mib), + p("Testing trap sending from subagent..."), + try_test(sa_v1_2_v2_trap1, [SA]), + try_test(sa_v1_2_v2_trap2, [SA]), + try_test(sa_v1_2_v2_trap3, [SA]), + + ?line unload_master("TestTrap"), + ?line unload_master("TestTrapv2"), + + ?line stop_subagent(SA). + +v3_trap(X) -> + v2_trap(X). + + +v3_inform(_X) -> + %% v2_inform(X). + {req, [], {conf, init_v3_inform, [v3_inform_i], finish_v3_inform}}. + +init_v2_inform(Config) when list(Config) -> + _Dir = ?config(agent_dir, Config), +% snmp_internal_mib:configure(Dir), + Config. + +init_v3_inform(X) -> + init_v2_inform(X). + +finish_v2_inform(Config) when list(Config) -> + _Dir = ?config(agent_dir, Config), +% snmp_internal_mib:configure(Dir), + Config. + +finish_v3_inform(X) -> + finish_v2_inform(X). + + + +v2_inform_i(suite) -> []; +v2_inform_i(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing inform sending from master agent... NOTE! This test\ntakes a " + "few minutes (5) to complete."), + MA = whereis(snmp_master_agent), + + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(ma_v2_inform1, [MA]), + + ?line unload_master("TestTrap"), + ?line unload_master("TestTrapv2"). + +v3_inform_i(X) -> v2_inform_i(X). + + +sa_error(suite) -> []; +sa_error(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Testing sa bad value (is_set_ok)..."), + try_test(sa_errs_bad_value), + + p("Testing sa gen err (set)..."), + try_test(sa_errs_gen_err), + + p("Testing too big..."), + try_test(sa_too_big), + + ?line unload_master("OLD-SNMPEA-MIB"), + stop_subagent(SA). + +sa_error_2(X) -> sa_error(X). + +sa_error_3(X) -> sa_error(X). + + +next_across_sa(suite) -> []; +next_across_sa(Config) when list(Config) -> + {SaNode, _MgrNode, MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Loading another subagent mib..."), + ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas1"]), + + rpc:call(SaNode, snmp, register_subagent, [MA, ?klas1, SA]), + try_test(load_test_sa), + + p("Testing next across subagent (endOfMibView from SA)..."), + try_test(next_across_sa), + + p("Unloading mib"), + snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), + rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), + try_test(unreg_test), + + p("Starting another subagent"), + ?line {ok, SA2} = start_subagent(SaNode, ?klas1, "Klas1"), + p("Testing next across subagent (wrong prefix from SA)..."), + try_test(next_across_sa), + + stop_subagent(SA), + stop_subagent(SA2). + +next_across_sa_2(X) -> next_across_sa(X). + +next_across_sa_3(X) -> next_across_sa(X). + + +undo(suite) -> []; +undo(Config) when list(Config) -> + {SaNode, _MgrNode, MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Testing undo phase at master agent..."), + ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas3"]), + ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas4"]), + try_test(undo_test), + try_test(api_test2), + ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas3"]), + + p("Testing bad return values from instrum. funcs..."), + try_test(bad_return), + + ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas4"]), + + p("Testing undo phase at subagent..."), + ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas3"]), + ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas4"]), + ?line ok = snmpa:register_subagent(MA, ?klas3, SA), + ?line ok = snmpa:register_subagent(MA, ?klas4, SA), + try_test(undo_test), + try_test(api_test3), + + p("Testing undo phase across master/subagents..."), + try_test(undo_test), + try_test(api_test3), + stop_subagent(SA). + +undo_2(X) -> undo(X). + +undo_3(X) -> undo(X). + +%% Req. Test2 +v1_processing(suite) -> []; +v1_processing(Config) when list(Config) -> + ?DBG("v1_processing -> entry", []), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + try_test(v1_proc), + ?line unload_master("Test2"). + +%% Req. Test2 +v2_processing(suite) -> []; +v2_processing(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + try_test(v2_proc), + ?line unload_master("Test2"). + +%% Req. Test2 +v3_processing(suite) -> []; +v3_processing(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + try_test(v2_proc), % same as v2! + ?line unload_master("Test2"). + + +%% We'll try get/set/trap and inform for all the auth & priv protocols. +%% For informs, the mgr is auth-engine. The agent has to sync. This is +%% accomplished by the first inform sent. That one will generate a +%% report, which makes it in sync. The notification-generating +%% application times out, and send again. This time it'll work. + +v3_crypto_basic(suite) -> []; +v3_crypto_basic(_Config) -> + EID = [0,0,0,0,0,0,0,0,0,0,0,2], + %% From rfc2274 appendix A.3.1 + ?line KMd5_1 = snmp:passwd2localized_key(md5, "maplesyrup", EID), + ?line [16#52,16#6f,16#5e,16#ed,16#9f,16#cc,16#e2,16#6f, + 16#89,16#64,16#c2,16#93,16#07,16#87,16#d8,16#2b] = + KMd5_1, + %% From rfc2274 appendix A.3.2 + ?line KSHA_1 = snmp:passwd2localized_key(sha, "maplesyrup", EID), + ?line [16#66,16#95,16#fe,16#bc,16#92,16#88,16#e3,16#62,16#82,16#23, + 16#5f,16#c7,16#15,16#1f,16#12,16#84,16#97,16#b3,16#8f,16#3f] = + KSHA_1, + %% From rfc2274, appendix A.5.1 + ?line KMd5_2 = snmp:passwd2localized_key(md5, "newsyrup", EID), + ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#88,16#05,16#61,16#51,16#41,16#67,16#6c,16#c9, + 16#19,16#61,16#74,16#e7,16#42,16#a3,16#25,16#51] = + snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2, 16, + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), + %% From rfc2274, appendix A.5.2 + ?line KSHA_2 = snmp:passwd2localized_key(sha, "newsyrup", EID), + ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#00,16#00,16#00,16#00,16#9c,16#10,16#17,16#f4, + 16#fd,16#48,16#3d,16#2d,16#e8,16#d5,16#fa,16#db, + 16#f8,16#43,16#92,16#cb,16#06,16#45,16#70,16#51] = + snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2, 20, + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), + KSHA_1t = lists:sublist(KSHA_1, 16), + KSHA_2t = lists:sublist(KSHA_2, 16), + ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#7e,16#f8,16#d8,16#a4,16#c9,16#cd,16#b2,16#6b, + 16#47,16#59,16#1c,16#d8,16#52,16#ff,16#88,16#b5] = + snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1t, KSHA_2t, 16, + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), + + %% Try with correct random + ?line Kc1 = snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2), + ?line KMd5_2 = snmp_user_based_sm_mib:extract_new_key(md5, KMd5_1, Kc1), + ?line Kc2 = snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2), + ?line KSHA_2 = snmp_user_based_sm_mib:extract_new_key(sha, KSHA_1, Kc2), + ok. + + + +v3_md5_auth(suite) -> []; +v3_md5_auth(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + p("Testing MD5 authentication...takes a few seconds..."), + + AgentDir = ?config(agent_dir, Config), + ?line rewrite_target_params_conf(AgentDir, "authMD5", authNoPriv), + ?line snmp_target_mib:reconfigure(AgentDir), + + MA = whereis(snmp_master_agent), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(v3_sync, [[{v2_proc, []}, + {ma_v2_trap1, [MA]}, + {v3_inform_sync, [MA]}]], + [{sec_level, authNoPriv}, {user, "authMD5"}]), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + ?line reset_target_params_conf(AgentDir). + +v3_sha_auth(suite) -> []; +v3_sha_auth(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + p("Testing SHA authentication...takes a few seconds..."), + + AgentDir = ?config(agent_dir, Config), + ?line rewrite_target_params_conf(AgentDir, "authSHA", authNoPriv), + ?line snmp_target_mib:reconfigure(AgentDir), + + MA = whereis(snmp_master_agent), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(v3_sync, [[{v2_proc, []}, + {ma_v2_trap1, [MA]}, + {v3_inform_sync, [MA]}]], + [{sec_level, authNoPriv}, {user, "authSHA"}]), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + ?line reset_target_params_conf(AgentDir). + +v3_des_priv(suite) -> []; +v3_des_priv(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + p("Testing DES encryption...takes a few seconds..."), + + AgentDir = ?config(agent_dir, Config), + ?line rewrite_target_params_conf(AgentDir, "privDES", authPriv), + ?line snmp_target_mib:reconfigure(AgentDir), + + MA = whereis(snmp_master_agent), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(v3_sync, [[{v2_proc, []}, + {ma_v2_trap1, [MA]}, + {v3_inform_sync, [MA]}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + ?line reset_target_params_conf(AgentDir). + +%% -define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). + +%% Make sure mgr is in sync with agent +v3_sync(Funcs) -> + ?DBG("v3_sync -> entry with Funcs: ~p",[Funcs]), + g([[sysDescr, 0]]), + expect(432, report, [{?usmStatsNotInTimeWindows_instance, any}]), + g([[sysDescr, 0]]), + expect(433, [{[sysDescr,0], any}]), + lists:foreach(fun({Func, Args}) -> apply(?MODULE, Func, Args) end, Funcs). + +v3_inform_sync(MA) -> + ?DBG("v3_sync -> entry with MA: ~p => Send notification",[MA]), + ?line snmpa:send_notification(MA, testTrapv22, no_receiver, + "standard inform", []), + %% Make sure agent is in sync with mgr... + ?DBG("v3_sync -> wait some time: ",[]), + sleep(20000), % more than 1500*10 in target_addr.conf + ?DBG("v3_sync -> await response",[]), + ?line expect(1, {inform, true}, + [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]). + + +v2_caps(suite) -> []; +v2_caps(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + try_test(v2_caps_i, [node()]). + +v2_caps_3(X) -> v2_caps(X). + + +v2_caps_i(Node) -> + ?line Idx = rpc:call(Node, snmp, add_agent_caps, [[1,2,3,4,5], "test cap"]), + g([[sysORID, Idx], [sysORDescr, Idx]]), + ?line expect(1, [{[sysORID, Idx], [1,2,3,4,5]}, + {[sysORDescr, Idx], "test cap"}]), + ?line rpc:call(Node, snmp, del_agent_caps, [Idx]), + g([[sysORID, Idx]]), + ?line expect(2, [{[sysORID, Idx], noSuchInstance}]). + + +%% Req. Test2 +v1_proc() -> + ?DBG("v1_proc -> entry", []), + %% According to RFC1157. + %% Template:
: + v1_get_p(), + v1_get_next_p(), + v1_set_p(). + + +v1_get_p() -> + %% 4.1.2:1 + g([[test2]]), + ?line expect(10, noSuchName, 1, [{[test2], 'NULL'}]), + g([[tDescr]]), + ?line expect(11, noSuchName, 1, [{[tDescr], 'NULL'}]), + g([[tDescr2,0]]), + ?line expect(12, noSuchName, 1, [{[tDescr2,0], 'NULL'}]), + g([[tDescr3,0]]), + ?line expect(131, noSuchName, 1, [{[tDescr3,0], 'NULL'}]), + g([[tDescr4,0]]), + ?line expect(132, noSuchName, 1, [{[tDescr4,0], 'NULL'}]), + g([[sysDescr, 0], [tDescr,0]]), % Outside mibview + ?line expect(14, noSuchName, 2, [{[sysDescr, 0], 'NULL'}, + {[tDescr,0], 'NULL'}]), + g([[sysDescr,3]]), + ?line expect(15, noSuchName, 1, [{[sysDescr, 3], 'NULL'}]), + + %% 4.1.2:2 + g([[tTable]]), + ?line expect(20, noSuchName, 1, [{[tTable], 'NULL'}]), + g([[tEntry]]), + ?line expect(21, noSuchName, 1, [{[tEntry], 'NULL'}]), + + %% 4.1.2:3 + g([[tTooBig, 0]]), + ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), + + %% 4.1.2:4 + g([[tGenErr1, 0]]), + ?line expect(40, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), + g([[tGenErr2, 0]]), + ?line expect(41, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), + g([[sysDescr, 0], [tGenErr3, 0]]), + ?line expect(42, genErr, 2, [{[sysDescr, 0], 'NULL'}, + {[tGenErr3, 0], 'NULL'}]). + + +v1_get_next_p() -> + %% 4.1.3:1 + gn([[1,3,7,1]]), + ?line expect(10, noSuchName, 1, [{[1,3,7,1], 'NULL'}]), + gn([[tDescr2]]), + ?line expect(11, tooBig, 0, any), + + %% 4.1.3:2 + gn([[tTooBig]]), + io:format("We currently don't handle tooBig correct!!!\n"), +% ?line expect(20, tooBig, 0, [{[tTooBig], 'NULL'}]), + ?line expect(20, tooBig, 0, any), + + %% 4.1.3:3 + gn([[tGenErr1]]), +% ?line expect(40, genErr, 1, [{[tGenErr1], 'NULL'}]), + ?line expect(40, genErr, 1, any), + gn([[tGenErr2]]), +% ?line expect(41, genErr, 1, [{[tGenErr2], 'NULL'}]), + ?line expect(41, genErr, 1, any), + gn([[sysDescr], [tGenErr3]]), +% ?line expect(42, genErr, 2, [{[sysDescr], 'NULL'}, +% {[tGenErr3], 'NULL'}]). + ?line expect(42, genErr, 2, any). + +v1_set_p() -> + %% 4.1.5:1 + s([{[1,3,7,0], i, 4}]), + ?line expect(10, noSuchName, 1, [{[1,3,7,0], 4}]), + s([{[tDescr,0], s, "outside mibview"}]), + ?line expect(11, noSuchName, 1, [{[tDescr,0], "outside mibview"}]), + s([{[tDescr3,0], s, "read-only"}]), + ?line expect(12, noSuchName, 1, [{[tDescr3,0], "read-only"}]), + s([{[tDescr3], s, "noSuchObject"}]), + ?line expect(13, noSuchName, 1, [{[tDescr3], "noSuchObject"}]), + s([{[tDescr3,1], s, "noSuchInstance"}]), + ?line expect(14, noSuchName, 1, [{[tDescr3,1], "noSuchInstance"}]), + s([{[tDescr2,0], s, "inconsistentName"}]), + ?line expect(15, noSuchName, 1, [{[tDescr2,0], "inconsistentName"}]), + + %% 4.1.5:2 + s([{[tDescr2, 0], i, 4}]), + ?line expect(20, badValue, 1, [{[tDescr2, 0], 4}]), + s([{[tDescr2, 0], s, "badValue"}]), + ?line expect(21, badValue, 1, [{[tDescr2, 0], "badValue"}]), + + %% 4.1.5:3 + %% The standard is quite incorrect here. The resp pdu was too big. In + %% the resp pdu, we have the original vbs. In the tooBig pdu we still + %% have to original vbs => the tooBig pdu is too big as well!!! It + %% may not get it to the manager, unless the agent uses 'NULL' instead + %% of the std-like original value. + s([{[tTooBig, 0], s, ?tooBigStr}]), + %% according to std: +% ?line expect(30, tooBig, 0, [{[tTooBig, 0], ?tooBigStr}]), + ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), + + %% 4.1.5:4 + s([{[tDescr2, 0], s, "is_set_ok_fail"}]), + ?line expect(40, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]), + s([{[tDescr2, 0], s, "commit_fail"}]), + ?line expect(41, genErr, 1, [{[tDescr2, 0], "commit_fail"}]). + +%% Req. Test2 +v2_proc() -> + %% According to RFC1905. + %% Template:
: + ?DBG("v2_proc -> entry",[]), + v2_get_p(), + v2_get_next_p(), + v2_get_bulk_p(), + v2_set_p(). + +v2_get_p() -> + %% 4.2.1:2 + ?DBG("v2_get_p -> entry",[]), + g([[test2]]), + ?line expect(10, [{[test2], noSuchObject}]), + g([[tDescr]]), + ?line expect(11, [{[tDescr], noSuchObject}]), + g([[tDescr4,0]]), + ?line expect(12, [{[tDescr4,0], noSuchObject}]), + g([[sysDescr, 0], [tDescr,0]]), % Outside mibview + ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}, + {[tDescr,0], noSuchObject}]), + g([[tTable]]), + ?line expect(14, [{[tTable], noSuchObject}]), + g([[tEntry]]), + ?line expect(15, [{[tEntry], noSuchObject}]), + + %% 4.2.1:3 + g([[tDescr2,0]]), %% instrum ret noSuchName!!! + ?line expect(20, [{[tDescr2,0], noSuchInstance}]), + g([[tDescr3,0]]), + ?line expect(21, [{[tDescr3,0], noSuchInstance}]), + g([[sysDescr,3]]), + ?line expect(22, [{[sysDescr, 3], noSuchInstance}]), + g([[tIndex,1]]), + ?line expect(23, [{[tIndex, 1], noSuchInstance}]), + + %% 4.2.1 - any other error: genErr + g([[tGenErr1, 0]]), + ?line expect(30, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), + g([[tGenErr2, 0]]), + ?line expect(31, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), + g([[sysDescr, 0], [tGenErr3, 0]]), + ?line expect(32, genErr, 2, [{[sysDescr, 0], 'NULL'}, + {[tGenErr3, 0], 'NULL'}]), + + %% 4.2.1 - tooBig + g([[tTooBig, 0]]), + ?line expect(40, tooBig, 0, []). + + +v2_get_next_p() -> + %% 4.2.2:2 + ?DBG("v2_get_next_p -> entry",[]), + gn([[1,3,7,1]]), + ?line expect(10, [{[1,3,7,1], endOfMibView}]), + gn([[sysDescr], [1,3,7,1]]), + ?line expect(11, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}]), + gn([[tCnt2, 1]]), + ?line expect(12, [{[tCnt2,2], 100}]), + gn([[tCnt2, 2]]), + ?line expect(12, [{[tCnt2,2], endOfMibView}]), + + %% 4.2.2 - any other error: genErr + gn([[tGenErr1]]), + ?line expect(20, genErr, 1, [{[tGenErr1], 'NULL'}]), + gn([[tGenErr2]]), + ?line expect(21, genErr, 1, [{[tGenErr2], 'NULL'}]), + gn([[sysDescr], [tGenErr3]]), + ?line expect(22, genErr, 2, [{[sysDescr], 'NULL'}, + {[tGenErr3], 'NULL'}]), + + %% 4.2.2 - tooBig + gn([[tTooBig]]), + ?line expect(20, tooBig, 0, []). + +v2_get_bulk_p() -> + %% 4.2.3 + ?DBG("v2_get_bulk_p -> entry",[]), + gb(1, 1, []), + ?line expect(10, []), + gb(-1, 1, []), + ?line expect(11, []), + gb(-1, -1, []), + ?line expect(12, []), + gb(-1, -1, []), + ?line expect(13, []), + gb(2, 0, [[sysDescr], [1,3,7,1]]), + ?line expect(14, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}]), + gb(1, 2, [[sysDescr], [1,3,7,1]]), + ?line expect(15, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}]), + gb(0, 2, [[sysDescr], [1,3,7,1]]), + ?line expect(16, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}, + {[sysObjectID, 0], [1,2,3]}, + {[1,3,7,1], endOfMibView}]), + + gb(2, 2, [[sysDescr], [1,3,7,1], [sysDescr], [1,3,7,1]]), + ?line expect(17, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}, + {[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}, + {[sysObjectID, 0], [1,2,3]}, + {[1,3,7,1], endOfMibView}]), + + gb(1, 2, [[sysDescr], [sysDescr], [tTooBig]]), + ?line expect(18, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[sysDescr, 0], "Erlang SNMP agent"}]), + + gb(1,12, [[tDescr2], [sysDescr]]), % next one after tDescr2 is tTooBig. + ?line expect(19, []), + + gb(2,2, [[sysDescr], [sysObjectID], [tGenErr1], [sysDescr]]), + ?line expect(20, genErr, 3, [{[sysDescr], 'NULL'}, + {[sysObjectID], 'NULL'}, + {[tGenErr1], 'NULL'}, + {[sysDescr], 'NULL'}]), + gb(0, 2, [[tCnt2, 1]]), + ?line expect(21, [{[tCnt2,2], 100}, + {[tCnt2,2], endOfMibView}]). + + +v2_set_p() -> + %% 4.2.5:1 + ?DBG("v2_set_p -> entry",[]), + s([{[1,3,7,0], i, 4}]), + ?line expect(10, noAccess, 1, [{[1,3,7,0], 4}]), + s([{[tDescr,0], s, "outside mibview"}]), + ?line expect(11, noAccess, 1, [{[tDescr,0], "outside mibview"}]), + + %% 4.2.5:2 + s([{[1,3,6,1,0], s, "noSuchObject"}]), + ?line expect(20, notWritable, 1, [{[1,3,6,1,0], "noSuchObject"}]), + + %% 4.2.5:3 + s([{[tDescr2, 0], i, 4}]), + ?line expect(30, wrongType, 1, [{[tDescr2, 0], 4}]), + s([{[tDescr2, 0], s, "badValue"}]), + ?line expect(31, badValue, 1, [{[tDescr2, 0], "badValue"}]), + + %% 4.2.5:4 + s([{[tStr, 0], s, ""}]), + ?line expect(40, wrongLength, 1, [{[tStr, 0], ""}]), + s([{[tStr, 0], s, "12345"}]), + ?line expect(40, wrongLength, 1, [{[tStr, 0], "12345"}]), + + %% 4.2.5:5 - N/A + + %% 4.2.5:6 + s([{[tInt1, 0], i, 0}]), + ?line expect(60, wrongValue, 1, [{[tInt1, 0], 0}]), + s([{[tInt1, 0], i, 5}]), + ?line expect(61, wrongValue, 1, [{[tInt1, 0], 5}]), + s([{[tInt2, 0], i, 0}]), + ?line expect(62, wrongValue, 1, [{[tInt2, 0], 0}]), + s([{[tInt2, 0], i, 5}]), + ?line expect(63, wrongValue, 1, [{[tInt2, 0], 5}]), + s([{[tInt3, 0], i, 5}]), + ?line expect(64, wrongValue, 1, [{[tInt3, 0], 5}]), + + %% 4.2.5:7 + s([{[tDescrX, 1, 1], s, "noCreation"}]), + ?line expect(70, noCreation, 1, [{[tDescrX, 1, 1], "noCreation"}]), + + %% 4.2.5:8 + s([{[tDescrX, 1, 2], s, "inconsistentName"}]), + ?line expect(80, inconsistentName, 1, + [{[tDescrX, 1, 2], "inconsistentName"}]), + + %% 4.2.5:9 + s([{[tCnt, 1, 2], i, 5}]), + ?line expect(90, notWritable, 1, [{[tCnt, 1, 2], 5}]), + s([{[tDescr3,0], s, "read-only"}]), + ?line expect(90, notWritable, 1, [{[tDescr3,0], "read-only"}]), + + %% 4.2.5:10 + s([{[tDescr2,0], s, "inconsistentValue"}]), + ?line expect(100, inconsistentValue, 1, + [{[tDescr2,0], "inconsistentValue"}]), + + %% 4.2.5:11 + s([{[tDescr2,0], s, "resourceUnavailable"}]), + ?line expect(110, resourceUnavailable, 1, + [{[tDescr2,0],"resourceUnavailable"}]), + + %% 4.2.5:12 + s([{[tDescr2, 0], s, "is_set_ok_fail"}]), + ?line expect(120, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]). + + %% commitFailed and undoFailed is tested by the 'undo' case. + + +%% Req. OLD-SNMPEA-MIB +table_test() -> + io:format("Testing simple get, next and set on communityTable...~n"), +%% {[147,214,36,45], "public", 2, readWrite}. +%% {[147,214,36,45], "standard trap", 2, read}. + Key1c3 = [intCommunityViewIndex,get(mip),is("public")], + Key2c3 = [intCommunityViewIndex,get(mip),is("standard trap")], + Key1c4 = [intCommunityAccess,get(mip),is("public")], + EndKey = [intCommunityEntry,[9],get(mip),is("public")], + gn([[intCommunityEntry]]), + ?line expect(7, [{Key1c3, 2}]), + gn([[intCommunityTable]]), + ?line expect(71, [{Key1c3, 2}]), + gn([[community]]), + ?line expect(72, [{Key1c3, 2}]), + gn([[otpSnmpeaMIB]]), + ?line expect(73, [{Key1c3, 2}]), + gn([[ericsson]]), + ?line expect(74, [{Key1c3, 2}]), + gn([Key1c3]), + ?line expect(8, [{Key2c3, 2}]), + gn([Key2c3]), + ?line expect(9, [{Key1c4, 2}]), + gn([EndKey]), + AgentIp = [intAgentIpAddress,0], + ?line expect(10, [{AgentIp, any}]), + g([Key1c3]), + ?line expect(11, [{Key1c3, 2}]), + g([EndKey]), + ?line ?v1_2(expect(12, noSuchName, 1, any), + expect(12, [{EndKey, noSuchObject}])), + + io:format("Testing row creation/deletion on communityTable...~n"), + NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], + NewKeyc4 = [intCommunityAccess,get(mip),is("test")], + NewKeyc5 = [intCommunityStatus,get(mip),is("test")], + s([{NewKeyc5, ?createAndGo}]), + ?line expect(14, ?v1_2(badValue, inconsistentValue), 1,any), + s([{NewKeyc5, ?createAndGo}, {NewKeyc3, 2}, {NewKeyc4, 2}]), + ?line expect(15, [{NewKeyc5, ?createAndGo},{NewKeyc3, 2}, {NewKeyc4, 2}]), + g([NewKeyc4]), + ?line expect(16, [{NewKeyc4, 2}]), + s([{NewKeyc5, ?destroy}]), + ?line expect(17, [{NewKeyc5, ?destroy}]), + s([{NewKeyc4, 2}]), + ?line expect(18, ?v1_2(noSuchName, inconsistentName), 1,[{NewKeyc4, 2}]), + s([{NewKeyc5, ?createAndWait}]), + ?line expect(19, [{NewKeyc5, ?createAndWait}]), + g([NewKeyc5]), + ?line expect(20, [{NewKeyc5, ?notReady}]), + s([{NewKeyc4, 2}]), + ?line expect(21, [{NewKeyc4, 2}]), + g([NewKeyc5]), + ?line expect(22, [{NewKeyc5, ?notReady}]), + s([{NewKeyc3, 2}]), + ?line expect(23, [{NewKeyc3, 2}]), + g([NewKeyc5]), + ?line expect(24, [{NewKeyc5, ?notInService}]), + s([{NewKeyc5, ?active}]), + ?line expect(25, [{NewKeyc5, ?active}]), + s([{NewKeyc5, ?destroy}]), + ?line expect(26, [{NewKeyc5, ?destroy}]), + s([{NewKeyc3, 3}]), + ?line expect(27, ?v1_2(noSuchName, inconsistentName), 1,[{NewKeyc3, 3}]), + otp_1128(). + +%% Req. system group +simple_standard_test() -> + ?DBG("simple_standard_test -> entry",[]), + gn([[1,1]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3]]), + ?line expect(11, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6]]), + ?line expect(12, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6,1]]), + ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6,1,2]]), + ?line expect(14, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6,1,2,1]]), + ?line expect(15, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6,1,2,1,1]]), + ?line expect(16, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[sysDescr]]), + ?line expect(17, [{[sysDescr,0], "Erlang SNMP agent"}]), + g([[sysDescr,0]]), + ?line expect(2, [{[sysDescr,0], "Erlang SNMP agent"}]), + g([[sysDescr]]), + ?line ?v1_2(expect(3, noSuchName, 1, any), + expect(3, [{[sysDescr], noSuchObject}])), + g([[1,6,7,0]]), + ?line ?v1_2(expect(41, noSuchName, 1, any), + expect(3, [{[1,6,7,0], noSuchObject}])), + gn([[1,13]]), + ?line ?v1_2(expect(4, noSuchName,1, any), + expect(4, [{[1,13], endOfMibView}])), + s([{[sysLocation, 0], "new_value"}]), + ?line expect(5, [{[sysLocation, 0], "new_value"}]), + g([[sysLocation, 0]]), + ?line expect(6, [{[sysLocation, 0], "new_value"}]), + io:format("Testing noSuchName and badValue...~n"), + s([{[sysServices,0], 3}]), + ?line expect(61, ?v1_2(noSuchName, notWritable), 1, any), + s([{[sysLocation, 0], i, 3}]), + ?line expect(62, ?v1_2(badValue, wrongType), 1, any), + ?DBG("simple_standard_test -> done",[]), + ok. + +%% This is run in the agent node +db_notify_client(suite) -> []; +db_notify_client(Config) when list(Config) -> + {SaNode, MgrNode, MibDir} = init_case(Config), + ?DBG("~n\tSaNode: ~p~n\tMgrNode: ~p~n\tMibDir: ~p", + [SaNode,MgrNode,MibDir]), + snmpa_local_db:register_notify_client(self(),?MODULE), + + %% This call (the manager) will issue to set operations, so + %% we expect to receive to notify(insert) calls. + try_test(db_notify_client_test), + + ?DBG("await first notify",[]), + receive + {db_notify_test_reply,insert} -> ?DBG("first notify received",[]),ok + end, + + ?DBG("await second notify",[]), + receive + {db_notify_test_reply,insert} -> ?DBG("second notify received",[]),ok + end, + + snmpa_local_db:unregister_notify_client(self()). + + +%% This is run in the manager node +db_notify_client_test() -> + ?DBG("set first new sysLocation",[]), + s([{[sysLocation, 0], "new_value"}]), + ?line expect(5, [{[sysLocation, 0], "new_value"}]), + + ?DBG("set second new sysLocation",[]), + s([{[sysLocation, 0], "new_value"}]), + ?line expect(5, [{[sysLocation, 0], "new_value"}]). + +notify(Pid,What) -> + ?DBG("notify(~p,~p) -> called",[Pid,What]), + Pid ! {db_notify_test_reply,What}. + + +%% Req: system group, OLD-SNMPEA-MIB, Klas1 +big_test() -> + ?DBG("big_test -> testing simple next/get/set @ master agent...",[]), + simple_standard_test(), + + ?DBG("big_test -> testing simple next/get/set @ subagent...",[]), + gn([[klas1]]), + ?line expect(1, [{[fname,0], ""}]), + g([[fname,0]]), + ?line expect(2, [{[fname,0], ""}]), + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + g([[fname,0]]), + ?line expect(4, [{[fname,0], "test set"}]), + + ?DBG("big_test -> " + "testing next from last instance in master to subagent...",[]), + gn([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(5, [{[fname,0], "test set"}]), + gn([[1,1], + [?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, + {[fname,0], "test set"}]), + s([{[fname,0], s, ""}]), + ?line expect(52, [{[fname,0], ""}]), + + table_test(), + + ?DBG("big_test -> adding one row in subagent table",[]), + _FTab = [friendsEntry], + s([{[friendsEntry, [2, 3]], s, "kompis3"}, + {[friendsEntry, [3, 3]], i, ?createAndGo}]), + ?line expect(6, [{[friendsEntry, [2, 3]], "kompis3"}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + g([[friendsEntry, [2, 3]], + [friendsEntry, [3, 3]]]), + ?line expect(7, [{[friendsEntry, [2, 3]], "kompis3"}, + {[friendsEntry, [3, 3]], ?active}]), + s([{[friendsEntry, [3, 3]], i, ?destroy}]), + ?line expect(8, [{[friendsEntry, [3, 3]], ?destroy}]), + + otp_1131(), + + ?DBG("big_test -> adding two rows in subagent table with special INDEX", + []), + s([{[kompissEntry, [1, 3]], s, "kompis3"}, + {[kompissEntry, [2, 3]], i, ?createAndGo}]), + ?line expect(9, [{[kompissEntry, [1, 3]], "kompis3"}, + {[kompissEntry, [2, 3]], ?createAndGo}]), + g([[kompissEntry, [1, 3]], + [kompissEntry, [2, 3]]]), + ?line expect(10, [{[kompissEntry, [1, 3]], "kompis3"}, + {[kompissEntry, [2, 3]], ?active}]), + gn([[kompissEntry, [1]], + [kompissEntry, [2]]]), + ?line expect(11, [{[kompissEntry, [1, 3]], "kompis3"}, + {[kompissEntry, [2, 3]], ?active}]), + s([{[kompissEntry, [1, 2]], s, "kompis3"}, + {[kompissEntry, [2, 2]], i, ?createAndGo}]), + ?line expect(12, [{[kompissEntry, [1, 2]], "kompis3"}, + {[kompissEntry, [2, 2]], ?createAndGo}]), + gn([[kompissEntry, [1, 1]], + [kompissEntry, [2, 1]]]), + ?line expect(13, [{[kompissEntry, [1, 2]], "kompis3"}, + {[kompissEntry, [2, 2]], ?active}]), + s([{[kompissEntry, [2, 3]], i, ?destroy}]), + ?line expect(14, [{[kompissEntry, [2, 3]], ?destroy}]), + s([{[kompissEntry, [2, 2]], i, ?destroy}]), + ?line expect(15, [{[kompissEntry, [2, 2]], ?destroy}]), + ?DBG("big_test -> done",[]), + ok. + +%% Req. system group, Klas2, OLD-SNMPEA-MIB +big_test_2() -> + p("Testing simple next/get/set @ master agent (2)..."), + simple_standard_test(), + + p("Testing simple next/get/set @ subagent (2)..."), + gn([[klas2]]), + ?line expect(1, [{[fname2,0], ""}]), + g([[fname2,0]]), + ?line expect(2, [{[fname2,0], ""}]), + s([{[fname2,0], s, "test set"}]), + ?line expect(3, [{[fname2,0], "test set"}]), + g([[fname2,0]]), + ?line expect(4, [{[fname2,0], "test set"}]), + + otp_1298(), + + p("Testing next from last object in master to subagent (2)..."), + gn([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(5, [{[fname2,0], "test set"}]), + gn([[1,1], + [?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, + {[fname2,0], "test set"}]), + + table_test(), + + p("Adding one row in subagent table (2)"), + _FTab = [friendsEntry2], + s([{[friendsEntry2, [2, 3]], s, "kompis3"}, + {[friendsEntry2, [3, 3]], i, ?createAndGo}]), + ?line expect(6, [{[friendsEntry2, [2, 3]], "kompis3"}, + {[friendsEntry2, [3, 3]], ?createAndGo}]), + g([[friendsEntry2, [2, 3]], + [friendsEntry2, [3, 3]]]), + ?line expect(7, [{[friendsEntry2, [2, 3]], "kompis3"}, + {[friendsEntry2, [3, 3]], ?active}]), + s([{[friendsEntry2, [3, 3]], i, ?destroy}]), + ?line expect(8, [{[friendsEntry2, [3, 3]], ?destroy}]), + + p("Adding two rows in subagent table with special INDEX (2)"), + s([{[kompissEntry2, [1, 3]], s, "kompis3"}, + {[kompissEntry2, [2, 3]], i, ?createAndGo}]), + ?line expect(9, [{[kompissEntry2, [1, 3]], "kompis3"}, + {[kompissEntry2, [2, 3]], ?createAndGo}]), + g([[kompissEntry2, [1, 3]], + [kompissEntry2, [2, 3]]]), + ?line expect(10, [{[kompissEntry2, [1, 3]], "kompis3"}, + {[kompissEntry2, [2, 3]], ?active}]), + gn([[kompissEntry2, [1]], + [kompissEntry2, [2]]]), + ?line expect(11, [{[kompissEntry2, [1, 3]], "kompis3"}, + {[kompissEntry2, [2, 3]], ?active}]), + s([{[kompissEntry2, [1, 2]], s, "kompis3"}, + {[kompissEntry2, [2, 2]], i, ?createAndGo}]), + ?line expect(12, [{[kompissEntry2, [1, 2]], "kompis3"}, + {[kompissEntry2, [2, 2]], ?createAndGo}]), + gn([[kompissEntry2, [1, 1]], + [kompissEntry2, [2, 1]]]), + ?line expect(13, [{[kompissEntry2, [1, 2]], "kompis3"}, + {[kompissEntry2, [2, 2]], ?active}]), + s([{[kompissEntry2, [2, 3]], i, ?destroy}]), + ?line expect(14, [{[kompissEntry2, [2, 3]], ?destroy}]), + s([{[kompissEntry2, [2, 2]], i, ?destroy}]), + ?line expect(15, [{[kompissEntry2, [2, 2]], ?destroy}]), + ok. + +%% Req. Test1 +multi_threaded_test() -> + p("Testing multi threaded agent..."), + g([[multiStr,0]]), + Pid = get_multi_pid(), + g([[sysUpTime,0]]), + ?line expect(1, [{[sysUpTime,0], any}]), + s([{[sysLocation, 0], s, "pelle"}]), + ?line expect(2, [{[sysLocation, 0], "pelle"}]), + Pid ! continue, + ?line expect(3, [{[multiStr,0], "ok"}]), + + s([{[multiStr, 0], s, "block"}]), + Pid2 = get_multi_pid(), + g([[sysUpTime,0]]), + ?line expect(4, [{[sysUpTime,0], any}]), + g([[multiStr,0]]), + Pid3 = get_multi_pid(), + g([[sysUpTime,0]]), + ?line expect(5, [{[sysUpTime,0], any}]), + s([{[sysLocation, 0], s, "kalle"}]), + Pid3 ! continue, + ?line expect(6, [{[multiStr,0], "ok"}]), + Pid2 ! continue, + ?line expect(7, [{[multiStr,0], "block"}]), + ?line expect(8, [{[sysLocation,0], "kalle"}]). + +%% Req. Test1, TestTrapv2 +mt_trap_test(MA) -> + snmpa:send_trap(MA, testTrapv22, "standard trap"), + ?line expect(1, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + + snmpa:send_trap(MA, mtTrap, "standard trap"), + Pid = get_multi_pid(), + g([[sysUpTime,0]]), + ?line expect(2, [{[sysUpTime,0], any}]), + snmpa:send_trap(MA, testTrapv22, "standard trap"), + ?line expect(3, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + Pid ! continue, + ?line expect(4, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?testTrap ++ [2]}, + {[multiStr,0], "ok"}]). + + +get_multi_pid() -> + get_multi_pid(10). +get_multi_pid(0) -> + ?line ?FAIL(no_global_name); +get_multi_pid(N) -> + sleep(1000), + case global:whereis_name(snmp_multi_tester) of + Pid when pid(Pid) -> Pid; + _ -> get_multi_pid(N-1) + end. + +%% Req. Test1 +types_v2_test() -> + p("Testing v2 types..."), + + s([{[bits1,0], 2#10}]), + ?line expect(1, [{[bits1,0], ?str(2#10)}]), + g([[bits1,0]]), + ?line expect(2, [{[bits1,0], ?str(2#101)}]), + + s([{[bits2,0], 2#11000000110}]), + ?line expect(3, [{[bits2,0], ?str(2#11000000110)}]), + g([[bits2,0]]), + ?line expect(4, [{[bits2,0], ?str(2#11000000110)}]), + + g([[bits3,0]]), + ?line expect(50, genErr, 1, any), + + g([[bits4,0]]), + ?line expect(51, genErr, 1, any), + + s([{[bits1,0], s, [2#10]}]), + ?line expect(6, ?v1_2(badValue, wrongValue), 1, any), + + s([{[bits2,0], 2#11001001101010011}]), + ?line expect(7, ?v1_2(badValue, wrongValue), 1, any). + + +%% Req. Test1 +implied_test(MA) -> + ?LOG("implied_test -> start",[]), + p("Testing IMPLIED..."), + + snmpa:verbosity(MA,trace), + snmpa:verbosity(MA,trace), + + %% Create two rows, check that they are get-nexted in correct order. + Idx1 = "apa", + Idx2 = "qq", + ?DBG("implied_test -> (send) create row 1 '~s' in table 1",[Idx1]), + s([{[testStatus, Idx1], i, ?createAndGo}, {[testDescr, Idx1],s,"row 1"}]), + ?line expect(1, [{[testStatus, Idx1], ?createAndGo}, + {[testDescr, Idx1], "row 1"}]), + ?DBG("implied_test -> (send) create row 2 '~s' in table 1",[Idx2]), + s([{[testStatus, Idx2], i, ?createAndGo}, {[testDescr, Idx2],s,"row 2"}]), + ?line expect(2, [{[testStatus, Idx2], ?createAndGo}, + {[testDescr, Idx2], "row 2"}]), + ?DBG("implied_test -> get-next(testDescr)",[]), + gn([[testDescr]]), + ?line expect(3, [{[testDescr,Idx1], "row 1"}]), + ?DBG("implied_test -> get-next(testDescr) of row 1",[]), + gn([[testDescr,Idx1]]), + ?line expect(4, [{[testDescr,Idx2], "row 2"}]), + + % Delete the rows + ?DBG("implied_test -> (send) delete row 1 '~s' from table 1",[Idx1]), + s([{[testStatus, Idx1], i, ?destroy}]), + ?line expect(5, [{[testStatus, Idx1], ?destroy}]), + ?DBG("implied_test -> (send) delete row 2 '~s' from table 1",[Idx2]), + s([{[testStatus, Idx2], i, ?destroy}]), + ?line expect(6, [{[testStatus, Idx2], ?destroy}]), + + %% Try the same in other table + Idx3 = [1, "apa"], + Idx4 = [1, "qq"], + ?DBG("implied_test -> (send) create row 1 '~s' in table 2",[Idx3]), + s([{[testStatus2, Idx3], i, ?createAndGo}, {[testDescr2,Idx3],s,"row 1"}]), + ?line expect(1, [{[testStatus2, Idx3], ?createAndGo}, + {[testDescr2, Idx3], "row 1"}]), + ?DBG("implied_test -> (send) create row 2 '~s' in table 2",[Idx4]), + s([{[testStatus2, Idx4], i, ?createAndGo}, {[testDescr2,Idx4],s,"row 2"}]), + ?line expect(2, [{[testStatus2, Idx4], ?createAndGo}, + {[testDescr2, Idx4], "row 2"}]), + ?DBG("implied_test -> get-next(testDescr2)",[]), + gn([[testDescr2]]), + ?line expect(3, [{[testDescr2,Idx3], "row 1"}]), + ?DBG("implied_test -> get-next(testDescr2) of row 1",[]), + gn([[testDescr2,Idx3]]), + ?line expect(4, [{[testDescr2,Idx4], "row 2"}]), + + % Delete the rows + ?DBG("implied_test -> (send) delete row 1 '~s' from table 2",[Idx3]), + s([{[testStatus2, Idx3], i, ?destroy}]), + ?line expect(5, [{[testStatus2, Idx3], ?destroy}]), + ?DBG("implied_test -> (send) delete row 2 '~s' from table 2",[Idx4]), + s([{[testStatus2, Idx4], i, ?destroy}]), + ?line expect(6, [{[testStatus2, Idx4], ?destroy}]), + + snmpa:verbosity(MA,log), + + ?LOG("implied_test -> done",[]). + + + +%% Req. Test1 +sparse_table_test() -> + p("Testing sparse table..."), + + %% Create two rows, check that they are get-nexted in correct order. + Idx1 = 1, + Idx2 = 2, + s([{[sparseStatus, Idx1], i, ?createAndGo}, + {[sparseDescr, Idx1], s, "row 1"}]), + ?line expect(1, [{[sparseStatus, Idx1], ?createAndGo}, + {[sparseDescr, Idx1], "row 1"}]), + s([{[sparseStatus, Idx2], i, ?createAndGo}, + {[sparseDescr, Idx2], s, "row 2"}]), + ?line expect(2, [{[sparseStatus, Idx2], ?createAndGo}, + {[sparseDescr, Idx2], "row 2"}]), + ?v1_2(gn([[sparseIndex], [sparseDescr,Idx1], [sparseDescr,Idx2], + [sparseStatus,Idx1], [sparseStatus,Idx2]]), + gb(0,5,[[sparseIndex]])), + ?line expect(3, [{[sparseDescr,Idx1], "row 1"}, + {[sparseDescr,Idx2], "row 2"}, + {[sparseStatus,Idx1], ?active}, + {[sparseStatus,Idx2], ?active}, + {[sparseStr,0], "slut"}]), + % Delete the rows + s([{[sparseStatus, Idx1], i, ?destroy}]), + ?line expect(4, [{[sparseStatus, Idx1], ?destroy}]), + s([{[sparseStatus, Idx2], i, ?destroy}]), + ?line expect(5, [{[sparseStatus, Idx2], ?destroy}]). + + +%% Req. Test1 +cnt_64_test(MA) -> + ?LOG("start cnt64 test (~p)",[MA]), + snmpa:verbosity(MA,trace), + ?LOG("start cnt64 test",[]), + p("Testing Counter64, and at the same time, RowStatus is not last column"), + + ?DBG("get cnt64",[]), + g([[cnt64,0]]), + ?DBG("await response",[]), + ?line ?v1_2(expect(1, noSuchName, 1, any), + expect(1, [{[cnt64,0],18446744073709551615}])), + ?DBG("get-next cnt64",[]), + gn([[cnt64]]), + ?DBG("await response",[]), + ?line ?v1_2(expect(2, [{[cnt64Str,0], "after cnt64"}]), + expect(2, [{[cnt64,0],18446744073709551615}])), + ?DBG("send cntTrap",[]), + snmpa:send_trap(MA,cntTrap,"standard trap",[{sysContact,"pelle"}, + {cnt64, 10}, + {sysLocation, "here"}]), + ?DBG("await response",[]), + ?line ?v1_2(expect(3, trap, [test], 6, 1, [{[sysContact,0], "pelle"}, + {[sysLocation,0], "here"}]), + expect(3, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?testTrap ++ [1]}, + {[sysContact,0], "pelle"}, + {[cnt64,0], 10}, + {[sysLocation,0], "here"}])), + + %% Create two rows, check that they are get-nexted in correct order. + Idx1 = 1, + Idx2 = 2, + ?DBG("create row (cntStatus): ~p",[Idx1]), + s([{[cntStatus, Idx1], i, ?createAndGo}]), + ?DBG("await response",[]), + ?line expect(1, [{[cntStatus, Idx1], ?createAndGo}]), + ?DBG("create row (cntStatus): ~p",[Idx2]), + s([{[cntStatus, Idx2], i, ?createAndGo}]), + ?DBG("await response",[]), + ?line expect(2, [{[cntStatus, Idx2], ?createAndGo}]), + + ?DBG("get-next (cntIndex)",[]), + gn([[cntIndex]]), + ?DBG("await response",[]), + ?line ?v1_2(expect(3, [{[cntStatus,Idx1], ?active}]), + expect(3, [{[cntCnt,Idx1], 0}])), + % Delete the rows + ?DBG("delete row (cntStatus): ~p",[Idx1]), + s([{[cntStatus, Idx1], i, ?destroy}]), + ?DBG("await response",[]), + ?line expect(4, [{[cntStatus, Idx1], ?destroy}]), + ?DBG("delete row (cntStatus): ~p",[Idx2]), + s([{[cntStatus, Idx2], i, ?destroy}]), + ?DBG("await response",[]), + ?line expect(5, [{[cntStatus, Idx2], ?destroy}]), + catch snmpa:verbosity(MA,log), + ?DBG("done",[]), + ok. + +%% Req. Test1 +opaque_test() -> + p("Testing Opaque datatype..."), + g([[opaqueObj,0]]), + ?line expect(1, [{[opaqueObj,0], "opaque-data"}]). + +%% Req. OLD-SNMPEA-MIB +api_test(MaNode) -> + ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, + [intAgentIpAddress]), + ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, + oid_to_name, [OID]), + ?line false = rpc:call(MaNode, snmp, name_to_oid, [intAgentIpAddres]), + ?line false = rpc:call(MaNode, snmp, oid_to_name, + [[1,5,32,3,54,3,3,34,4]]), + ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, + [intViewType, excluded]), + ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, + [intViewType, 2]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, [intViewType, exclude]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [intAgentIpAddress, exclude]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [intAgentIpAddre, exclude]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [intViewType, 3]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddress, 2]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddre, 2]), + ?line {value, active} = rpc:call(MaNode, snmp, + int_to_enum, ['RowStatus', ?active]), + ?line {value, ?destroy} = rpc:call(MaNode, snmp, + enum_to_int, ['RowStatus', destroy]), + ?line false = rpc:call(MaNode, snmp, + enum_to_int, ['RowStatus', xxxdestroy]), + ?line false = rpc:call(MaNode, snmp, + enum_to_int, ['xxRowStatus', destroy]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, ['RowStatus', 25]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, ['xxRowStatus', 1]), + ?line case snmp:date_and_time() of + List when list(List), length(List) == 8 -> ok; + List when list(List), length(List) == 11 -> ok + end. + +%% Req. Klas3 +api_test2() -> + g([[fname3,0]]), + ?line expect(1, [{[fname3,0], "ok"}]), + g([[fname4,0]]), + ?line expect(2, [{[fname4,0], 1}]). + +api_test3() -> + g([[fname3,0]]), + ?line expect(1, [{[fname3,0], "ok"}]). + + +unreg_test() -> + gn([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(1, [{[snmpInPkts, 0], any}]). + +load_test() -> + gn([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(1, [{[fname,0], ""}]). + +%% Req. Klas1 +load_test_sa() -> + gn([[?v1_2(sysServices,sysORLastChange), 0]]), + ?line expect(1, [{[fname,0], any}]). + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_get() -> + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + g([[sysDescr,0], Key1c4, [fname,0],Key1c3, + [sysName,0]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[fname,0], "test set"}, + {Key1c3, 2}, + {[sysName,0], "test"}]), + g([[1,3,7,1], Key1c4, [sysDescr,0], [1,3,7,2], Key1c3, [sysDescr,0]]), + ?line ?v1_2(expect(2, noSuchName, [1,4], any), + expect(2, [{[1,3,7,1], noSuchObject}, + {Key1c4, 2}, + {[sysDescr,0], "Erlang SNMP agent"}, + {[1,3,7,2], noSuchObject}, + {Key1c3, 2}, + {[sysDescr,0], "Erlang SNMP agent"}])). + +%% Req. v1, system group, Klas1, OLD-SNMPEA-MIB, *ej* Klas3. +do_mul_get_err() -> + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + g([[sysDescr,0],Key1c4,[fname,0], Key1c3, [sysName,2]]), + ?line ?v1_2(expect(1, noSuchName, 5, any), + expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[fname,0], "test set"}, + {Key1c3, 2}, + {[sysName,2], noSuchInstance}])), + g([[sysDescr,0],Key1c4,[fname3,0], Key1c3, [sysName,1]]), + ?line ?v1_2(expect(1, noSuchName, [3,5], any), + expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[fname3,0], noSuchObject}, + {Key1c3, 2}, + {[sysName,1], noSuchInstance}])). + + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_next() -> + Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], + Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + gn([[sysDescr], Key1c4s, [fname],Key1c3s,[sysName]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, {[fname,0], "test set"}, + {Key1c3, 2}, {[sysName,0], "test"}]). + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_next_err() -> + Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], + Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + gn([[sysDescr], Key1c4s, [1,3,6,999], [fname],[1,3,90], Key1c3s,[sysName]]), + ?line ?v1_2(expect(1, noSuchName, [3,5], any), + expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[1,3,6,999], endOfMibView}, + {[fname,0], "test set"}, + {[1,3,90], endOfMibView}, + {Key1c3, 2}, + {[sysName,0], "test"}])). + + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_set() -> + p("Adding one row in subagent table, and one in master table"), + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + s([{[friendsEntry, [2, 3]], "kompis3"}, + {NewKeyc3, 2}, + {[sysLocation,0], "new_value"}, + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + ?line expect(1, [{[friendsEntry, [2, 3]], "kompis3"}, + {NewKeyc3, 2}, + {[sysLocation,0], "new_value"}, + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + g([[friendsEntry, [2, 3]], + [sysLocation,0], + [friendsEntry, [3, 3]]]), + ?line expect(2, [{[friendsEntry, [2, 3]], "kompis3"}, + {[sysLocation,0], "new_value"}, + {[friendsEntry, [3, 3]], ?active}]), + g([NewKeyc4]), + ?line expect(3, [{NewKeyc4, 2}]), + s([{[friendsEntry, [3, 3]], ?destroy}, + {NewKeyc5, ?destroy}]), + ?line expect(4, [{[friendsEntry, [3, 3]], ?destroy}, + {NewKeyc5, ?destroy}]). + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_set_err() -> + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + p("Adding one row in subagent table, and one in master table"), + s([{[friendsEntry, [2, 3]], s, "kompis3"}, + {NewKeyc3, 2}, + {[sysUpTime,0], 45}, % sysUpTime (readOnly) + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + ?line expect(1, ?v1_2(noSuchName, notWritable), 3, any), + g([[friendsEntry, [2, 3]]]), + ?line ?v1_2(expect(2, noSuchName, 1, any), + expect(2, [{[friendsEntry, [2,3]], noSuchInstance}])), + g([NewKeyc4]), + ?line ?v1_2(expect(3, noSuchName, 1, any), + expect(3, [{NewKeyc4, noSuchInstance}])). + +%% Req. SA-MIB +sa_mib() -> + g([[sa, [2,0]]]), + ?line expect(1, [{[sa, [2,0]], 3}]), + s([{[sa, [1,0]], s, "sa_test"}]), + ?line expect(2, [{[sa, [1,0]], "sa_test"}]). + +ma_trap1(MA) -> + snmpa:send_trap(MA, testTrap2, "standard trap"), + ?line expect(1, trap, [system], 6, 1, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}]), + snmpa:send_trap(MA, testTrap1, "standard trap"), + ?line expect(2, trap, [1,2,3] , 1, 0, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}]). + +ma_trap2(MA) -> + snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). + +ma_v2_2_v1_trap(MA) -> + snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). + +ma_v2_2_v1_trap2(MA) -> + snmpa:send_trap(MA,linkUp,"standard trap",[{ifIndex, [1], 1}, + {ifAdminStatus, [1], 1}, + {ifOperStatus, [1], 2}]), + ?line expect(3, trap, [1,2,3], 3, 0, [{[ifIndex, 1], 1}, + {[ifAdminStatus, 1], 1}, + {[ifOperStatus, 1], 2}]). + +sa_trap1(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap"), + ?line expect(4, trap, [ericsson], 6, 1, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}]). + +sa_trap2(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), + ?line expect(5, trap, [ericsson], 6, 1, [{[system, [4,0]], + "pelle"}, + {[sa, [1,0]], "sa_test"}]). + +sa_trap3(SA) -> + snmpa:send_trap(SA, saTrap2, "standard trap", + [{intViewSubtree, [4], [1,2,3,4]}]), + ?line expect(6, trap, [ericsson], 6, 2, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}, + {[intViewSubtree,4],[1,2,3,4]}]). + +ma_v2_trap1(MA) -> + ?DBG("ma_v2_traps -> entry with MA = ~p => " + "send standard trap: testTrapv22",[MA]), + snmpa:send_trap(MA, testTrapv22, "standard trap"), + ?line expect(1, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + ?DBG("ma_v2_traps -> send standard trap: testTrapv21",[]), + snmpa:send_trap(MA, testTrapv21, "standard trap"), + ?line expect(2, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?snmp ++ [1]}]). + +ma_v2_trap2(MA) -> + snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}, + {[system, [4,0]], "pelle"}]). + +%% Note: This test case takes a while... actually a couple of minutes. +ma_v2_inform1(MA) -> + ?DBG("ma_v2_inform -> entry with MA = ~p => " + "send notification: testTrapv22",[MA]), + ?line snmpa:send_notification(MA, testTrapv22, no_receiver, "standard inform", []), + ?line expect(1, {inform, true}, + [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + + ?DBG("ma_v2_inform -> send notification: testTrapv22",[]), + snmpa:send_notification(MA, testTrapv22, {tag1, self()}, + "standard inform", []), + ?line expect(1, {inform, true}, + [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + ?DBG("ma_v2_inform -> await targets",[]), + receive + {snmp_targets, tag1, [_]} -> + ok; + {snmp_targets, tag1, Addrs1} -> + ?line ?FAIL({bad_addrs, Addrs1}) + after + 5000 -> + ?ERR("ma_v2_inform1 -> awaiting snmp_targets(tag1) timeout",[]), + ?line ?FAIL(nothing_at_all) + end, + ?DBG("ma_v2_inform -> await notification",[]), + receive + {snmp_notification, tag1, {got_response, _}} -> + ok; + {snmp_notification, tag1, {no_response, _}} -> + ?line ?FAIL(no_response) + after + 20000 -> + ?ERR("ma_v2_inform1 -> " + "awaiting snmp_notification(tag1) timeout",[]), + ?line ?FAIL(nothing_at_all) + end, + + %% + %% -- The rest is possibly erroneous... + %% + + ?DBG("ma_v2_inform -> send notification: testTrapv22",[]), + snmpa:send_notification(MA, testTrapv22, {tag2, self()}, + "standard inform", []), + ?line expect(2, {inform, false}, + [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + ?DBG("ma_v2_inform -> await targets",[]), + receive + {snmp_targets, tag2, [_]} -> + ok; + {snmp_targets, tag2, Addrs2} -> + ?ERR("ma_v2_inform1 -> awaiting snmp_targets(tag2) timeout",[]), + ?line ?FAIL({bad_addrs, Addrs2}) + after + 5000 -> + ?line ?FAIL(nothing_at_all) + end, + ?DBG("ma_v2_inform -> await notification",[]), + receive + {snmp_notification, tag2, {got_response, _}} -> + ?line ?FAIL(got_response); + {snmp_notification, tag2, {no_response, _}} -> + ok + after + 240000 -> + ?ERR("ma_v2_inform1 -> " + "awaiting snmp_notification(tag2) timeout",[]), + ?line ?FAIL(nothing_at_all) + end. + + +ma_v1_2_v2_trap(MA) -> + snmpa:send_trap(MA,linkDown,"standard trap",[{ifIndex, [1], 1}]), + ?line expect(2, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?snmpTraps ++ [3]}, + {[ifIndex, 1], 1}, + {[snmpTrapEnterprise, 0], [1,2,3]}]). + + +ma_v1_2_v2_trap2(MA) -> + snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}, + {[system, [4,0]], "pelle"}, + {[snmpTrapEnterprise, 0], ?system}]). + + +sa_v1_2_v2_trap1(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap"), + ?line expect(4, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, + {[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}, + {[snmpTrapEnterprise, 0], ?ericsson}]). + +sa_v1_2_v2_trap2(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), + ?line expect(4, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, + {[system, [4,0]], "pelle"}, + {[sa, [1,0]], "sa_test"}, + {[snmpTrapEnterprise, 0], ?ericsson}]). + + +sa_v1_2_v2_trap3(SA) -> + snmpa:send_trap(SA, saTrap2, "standard trap", + [{intViewSubtree, [4], [1,2,3,4]}]), + ?line expect(4, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?ericsson ++ [0, 2]}, + {[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}, + {[intViewSubtree,4],[1,2,3,4]}, + {[snmpTrapEnterprise, 0], ?ericsson}]). + + +%% Req. SA-MIB, OLD-SNMPEA-MIB +sa_errs_bad_value() -> + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + s([{NewKeyc3, 2}, + {[sa, [2,0]], 5}, % badValue (i is_set_ok) + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}]), + ?line expect(1, badValue, 2, any), + s([{NewKeyc3, 2}, + {[sa, [2,0]], 6}, % wrongValue (i is_set_ok) + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}]), + ?line expect(1, ?v1_2(badValue, wrongValue), 2, any), + g([NewKeyc4]), + ?line ?v1_2(expect(2, noSuchName, 1, any), + expect(2, [{NewKeyc4, noSuchInstance}])). + +%% Req. SA-MIB, OLD-SNMPEA-MIB +sa_errs_gen_err() -> + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + s([{NewKeyc3, 2},{NewKeyc4, 2}, + {NewKeyc5, ?createAndGo}, {[sa, [3,0]], 5}]), + ?line expect(1, genErr, 4, any), +% The row might have been added; we don't know. +% (as a matter of fact we do - it is added, because the agent +% first sets its own vars, and then th SAs. Lets destroy it. + s([{NewKeyc5, ?destroy}]), + ?line expect(2, [{NewKeyc5, ?destroy}]). + +%% Req. SA-MIB, OLD-SNMPEA-MIB +sa_too_big() -> + g([[sa, [4,0]]]), + ?line expect(1, tooBig). + +%% Req. Klas1, system group, snmp group (v1/v2) +next_across_sa() -> + gn([[sysDescr],[klas1,5]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {[snmpInPkts, 0], any}]). + +%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]). -> noError +%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]). -> {badValue, 2} +%% snmp_test_mgr:s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]). -> {genErr, 1} +%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]). -> {genErr, 1} +%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]). -> {genErr, 1} +%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]). -> {genErr, 2} +%% Req. Klas3, Klas4 +undo_test() -> + s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), + ?line expect(1, [{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), + s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]), + ?line expect(2, ?v1_2(badValue, inconsistentValue), 2, any), + s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]), + ?line expect(3, ?v1_2(genErr, undoFailed), 1, any), + s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]), + ?line expect(4, ?v1_2(genErr, commitFailed), 1, any), +% unfortunatly we don't know if we'll get undoFailed or commitFailed. +% it depends on which order the agent traverses the varbind list. +% s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]), +% ?line expect(5, ?v1_2(genErr, undoFailed), 1, any), + s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]), + ?line expect(6, genErr, 2, any). + +%% Req. Klas3, Klas4 +bad_return() -> + g([[fStatus4,4], + [fName4,4]]), + ?line expect(4, genErr, 2, any), + g([[fStatus4,5], + [fName4,5]]), + ?line expect(5, genErr, 1, any), + g([[fStatus4,6], + [fName4,6]]), + ?line expect(6, genErr, 2, any), + gn([[fStatus4,7], + [fName4,7]]), + ?line expect(7, genErr, 2, any), + gn([[fStatus4,8], + [fName4,8]]), + ?line expect(8, genErr, 1, any), + gn([[fStatus4,9], + [fName4,9]]), + ?line expect(9, genErr, 2, any). + + +%%%----------------------------------------------------------------- +%%% Test the implementation of standard mibs. +%%% We should *at least* try to GET all variables, just to make +%%% sure the instrumentation functions work. +%%% Note that many of the functions in the standard mib is +%%% already tested by the normal tests. +%%%----------------------------------------------------------------- + + + +%%----------------------------------------------------------------- +%% For this test, the agent is configured for v1. +%% o Test the counters and control objects in SNMP-STANDARD-MIB +%%----------------------------------------------------------------- +snmp_standard_mib(suite) -> []; +snmp_standard_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?DBG("snmp_standard_mib -> std_mib_init", []), + try_test(std_mib_init), + + ?DBG("snmp_standard_mib -> std_mib_a", []), + InBadVsns = try_test(std_mib_a), + put(vsn, v2), + ?DBG("snmp_standard_mib -> std_mib_read", []), + try_test(std_mib_read), + put(vsn, v1), + + ?DBG("snmp_standard_mib -> std_mib_b (~w)", [InBadVsns]), + Bad = try_test(std_mib_b, [InBadVsns]), + ?DBG("snmp_standard_mib -> std_mib_read (community: 'bad community')", []), + try_test(std_mib_read, [], [{community, "bad community"}]), + ?DBG("snmp_standard_mib -> std_mib_write (community: 'public')", []), + try_test(std_mib_write, [], [{community, "public"}]), + ?DBG("snmp_standard_mib -> std_mib_asn_err", []), + try_test(std_mib_asn_err), + ?DBG("snmp_standard_mib -> std_mib_c (~w)", [Bad]), + try_test(std_mib_c, [Bad]), + ?DBG("snmp_standard_mib -> std_mib_a", []), + try_test(standard_mib_a), + + ?DBG("snmp_standard_mib -> std_mib_finish", []), + try_test(std_mib_finish), + ?DBG("snmp_standard_mib -> std_mib_test_finish", []), + try_test(standard_mib_test_finish, [], [{community, "bad community"}]). + +%% Req. SNMP-STANDARD-MIB +standard_mib_a() -> + ?line [OutPkts] = get_req(2, [[snmpOutPkts,0]]), + ?line [OutPkts2] = get_req(3, [[snmpOutPkts,0]]), + ?line OutPkts2 = OutPkts + 1, + %% There are some more counters we could test here, but it's not that + %% important, since they are removed from SNMPv2-MIB. + ok. + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_init() -> + %% disable authentication failure traps. (otherwise w'd get many of + %% them - this is also a test to see that it works). + s([{[snmpEnableAuthenTraps,0], 2}]), + ?line expect(1, [{[snmpEnableAuthenTraps, 0], 2}]). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_finish() -> + %% enable again + s([{[snmpEnableAuthenTraps,0], 1}]), + ?line expect(1, [{[snmpEnableAuthenTraps, 0], 1}]). + +%% Req. SNMP-STANDARD-MIB +standard_mib_test_finish() -> + %% force a authenticationFailure + std_mib_write(), + %% check that we got a trap + ?line expect(2, trap, [1,2,3], 4, 0, []). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_read() -> + ?DBG("std_mib_read -> entry", []), + g([[sysUpTime,0]]), % try a bad ; msg dropped, no reply + ?DBG("std_mib_read -> await timeout (i.e. no reply)", []), + ?line expect(1, timeout). % make sure we don't get a trap! + + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_write() -> + ?DBG("std_mib_write -> entry", []), + s([{[sysLocation, 0], "new_value"}]). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_asn_err() -> + snmp_test_mgr:send_bytes([48,99,67,12,0,0,0,0,0,0,5]). + +%%----------------------------------------------------------------- +%% For this test, the agent is configured for v2 and v3. +%% o Test the counters and control objects in SNMPv2-MIB +%%----------------------------------------------------------------- +snmpv2_mib_2(suite) -> []; +snmpv2_mib_2(Config) when list(Config) -> + ?LOG("snmpv2_mib_2 -> start",[]), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?DBG("snmpv2_mib_2 -> standard mib init",[]), + try_test(std_mib_init), + + ?DBG("snmpv2_mib_2 -> get number of (so far) bad versions",[]), + InBadVsns = try_test(std_mib_a), + + ?DBG("snmpv2_mib_2 -> make a bad version read",[]), + put(vsn, v1), + try_test(std_mib_read), + + ?DBG("snmpv2_mib_2 -> bad version read",[]), + put(vsn, v2), + Bad = try_test(std_mib_b, [InBadVsns]), + + ?DBG("snmpv2_mib_2 -> read with bad community",[]), + try_test(std_mib_read, [], [{community, "bad community"}]), + + ?DBG("snmpv2_mib_2 -> write with public community",[]), + try_test(std_mib_write, [], [{community, "public"}]), + + ?DBG("snmpv2_mib_2 -> asn err",[]), + try_test(std_mib_asn_err), + + ?DBG("snmpv2_mib_2 -> check counters",[]), + try_test(std_mib_c, [Bad]), + + ?DBG("snmpv2_mib_2 -> get som counters",[]), + try_test(snmpv2_mib_a), + + ?DBG("snmpv2_mib_2 -> enable auth traps, and await some",[]), + try_test(std_mib_finish), + + ?DBG("snmpv2_mib_2 -> force auth failure, and await trap, " + "then disable auth traps",[]), + try_test(snmpv2_mib_test_finish, [], [{community, "bad community"}]), + + ?LOG("snmpv2_mib_2 -> done",[]). + +%% Req. SNMPv2-MIB +snmpv2_mib_3(suite) -> []; +snmpv2_mib_3(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + InBadVsns = try_test(std_mib_a), + put(vsn, v1), + try_test(std_mib_read), + put(vsn, v3), + _Bad = try_test(std_mib_b, [InBadVsns]), + try_test(snmpv2_mib_a), + + try_test(std_mib_finish). + +-define(authenticationFailure, [1,3,6,1,6,3,1,1,5,5]). + +%% Req. SNMPv2-MIB +snmpv2_mib_test_finish() -> + %% force a authenticationFailure + ?DBG("ma_v2_inform -> write to std mib",[]), + std_mib_write(), + + %% check that we got a trap + ?DBG("ma_v2_inform -> await trap",[]), + ?line expect(2, v2trap, [{[sysUpTime,0], any}, + {[snmpTrapOID,0], ?authenticationFailure}]), + + %% and the the inform + ?DBG("ma_v2_inform -> await inform",[]), + ?line expect(2, {inform,true}, [{[sysUpTime,0], any}, + {[snmpTrapOID,0],?authenticationFailure}]). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_a() -> + ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), + ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), + ?line InPkts2 = InPkts + 1, + + ?line [InBadVsns] = get_req(4, [[snmpInBadVersions,0]]), + InBadVsns. + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_b(InBadVsns) -> + ?line [InBadVsns2] = get_req(1, [[snmpInBadVersions,0]]), + ?line InBadVsns2 = InBadVsns + 1, + ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), + ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), + ?line InPkts2 = InPkts + 1, + ?line [InBadCommunityNames, InBadCommunityUses, InASNErrs] = + get_req(4, [[snmpInBadCommunityNames,0], + [snmpInBadCommunityUses,0], + [snmpInASNParseErrs, 0]]), + {InBadCommunityNames, InBadCommunityUses, InASNErrs}. + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_c({InBadCommunityNames, InBadCommunityUses, InASNErrs}) -> + ?line [InBadCommunityNames2, InBadCommunityUses2, InASNErrs2] = + get_req(1, [[snmpInBadCommunityNames,0], + [snmpInBadCommunityUses,0], + [snmpInASNParseErrs, 0]]), + ?line InBadCommunityNames2 = InBadCommunityNames + 1, + ?line InBadCommunityUses2 = InBadCommunityUses + 1, + ?line InASNErrs2 = InASNErrs + 1. + +%% Req. SNMPv2-MIB +snmpv2_mib_a() -> + ?line [SetSerial] = get_req(2, [[snmpSetSerialNo,0]]), + s([{[snmpSetSerialNo,0], SetSerial}, {[sysLocation, 0], "val2"}]), + ?line expect(3, [{[snmpSetSerialNo,0], SetSerial}, + {[sysLocation, 0], "val2"}]), + s([{[sysLocation, 0], "val3"}, {[snmpSetSerialNo,0], SetSerial}]), + ?line expect(4, inconsistentValue, 2, + [{[sysLocation, 0], "val3"}, + {[snmpSetSerialNo,0], SetSerial}]), + ?line ["val2"] = get_req(5, [[sysLocation,0]]). + + +%%----------------------------------------------------------------- +%% o Bad community uses/name is tested already +%% in SNMPv2-MIB and STANDARD-MIB. +%% o Test add/deletion of rows. +%%----------------------------------------------------------------- +snmp_community_mib(suite) -> []; +snmp_community_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + try_test(snmp_community_mib), + ?line unload_master("SNMP-COMMUNITY-MIB"). + +snmp_community_mib_2(X) -> snmp_community_mib(X). + +%% Req. SNMP-COMMUNITY-MIB +snmp_community_mib() -> + ?INF("NOT YET IMPLEMENTED", []), + nyi. + +%%----------------------------------------------------------------- +%% o Test engine boots / time +%%----------------------------------------------------------------- +snmp_framework_mib(suite) -> []; +snmp_framework_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + try_test(snmp_framework_mib), + ?line unload_master("SNMP-FRAMEWORK-MIB"). + +snmp_framework_mib_2(X) -> snmp_framework_mib(X). + +snmp_framework_mib_3(suite) -> []; +snmp_framework_mib_3(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + try_test(snmp_framework_mib). + + +%% Req. SNMP-FRAMEWORK-MIB +snmp_framework_mib() -> + ?line ["agentEngine"] = get_req(1, [[snmpEngineID,0]]), + ?line [EngineTime] = get_req(2, [[snmpEngineTime,0]]), + sleep(5000), + ?line [EngineTime2] = get_req(3, [[snmpEngineTime,0]]), + if + EngineTime+7 < EngineTime2 -> + ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); + EngineTime+4 > EngineTime2 -> + ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); + true -> ok + end, + ?line case get_req(4, [[snmpEngineBoots,0]]) of + [Boots] when integer(Boots) -> ok; + Else -> ?FAIL(Else) + end, + ok. + +%%----------------------------------------------------------------- +%% o Test the counters +%%----------------------------------------------------------------- +snmp_mpd_mib_3(suite) -> []; +snmp_mpd_mib_3(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + UnknownPDUHs = try_test(snmp_mpd_mib_a), + try_test(snmp_mpd_mib_b, [], [{context_engine_id, "bad engine"}]), + try_test(snmp_mpd_mib_c, [UnknownPDUHs]). + + +%% Req. SNMP-MPD-MIB +snmp_mpd_mib_a() -> + ?line [UnknownSecs, InvalidMsgs] = + get_req(1, [[snmpUnknownSecurityModels,0], + [snmpInvalidMsgs,0]]), + Pdu = #pdu{type = 'get-request', + request_id = 23, + error_status = noError, + error_index = 0, + varbinds = []}, + SPdu = #scopedPdu{contextEngineID = "agentEngine", + contextName = "", + data = Pdu}, + ?line SPDUBytes = snmp_pdus:enc_scoped_pdu(SPdu), + V3Hdr1 = #v3_hdr{msgID = 21, + msgMaxSize = 484, + msgFlags = [7], + msgSecurityModel = 23, % bad sec model + msgSecurityParameters = []}, + V3Hdr2 = #v3_hdr{msgID = 21, + msgMaxSize = 484, + msgFlags = [6], % bad flag combination + msgSecurityModel = 3, + msgSecurityParameters = []}, + Message1 = #message{version = 'version-3', vsn_hdr = V3Hdr1, + data = SPDUBytes}, + Message2 = #message{version = 'version-3', vsn_hdr = V3Hdr2, + data = SPDUBytes}, + ?line MsgBytes1 = snmp_pdus:enc_message_only(Message1), + ?line MsgBytes2 = snmp_pdus:enc_message_only(Message2), + snmp_test_mgr:send_bytes(MsgBytes1), + snmp_test_mgr:send_bytes(MsgBytes2), + + ?line [UnknownSecs2, InvalidMsgs2, UnknownPDUHs] = + get_req(1, [[snmpUnknownSecurityModels,0], + [snmpInvalidMsgs,0], + [snmpUnknownPDUHandlers, 0]]), + ?line UnknownSecs2 = UnknownSecs + 1, + ?line InvalidMsgs2 = InvalidMsgs + 1, + UnknownPDUHs. + +-define(snmpUnknownPDUHandlers_instance, [1,3,6,1,6,3,11,2,1,3,0]). +snmp_mpd_mib_b() -> + g([[sysUpTime,0]]), + ?line expect(1, report, [{?snmpUnknownPDUHandlers_instance, any}]). + + +snmp_mpd_mib_c(UnknownPDUHs) -> + ?line [UnknownPDUHs2] = get_req(1, [[snmpUnknownPDUHandlers, 0]]), + ?line UnknownPDUHs2 = UnknownPDUHs + 1. + + +snmp_target_mib(suite) -> []; +snmp_target_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-TARGET-MIB"), + try_test(snmp_target_mib), + ?line unload_master("SNMP-TARGET-MIB"). + +snmp_target_mib_2(X) -> snmp_target_mib(X). + +snmp_target_mib_3(X) -> snmp_target_mib(X). + +snmp_target_mib() -> + ?INF("NOT YET IMPLEMENTED", []), + nyi. + +snmp_notification_mib(suite) -> []; +snmp_notification_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + try_test(snmp_notification_mib), + ?line unload_master("SNMP-NOTIFICATION-MIB"). + +snmp_notification_mib_2(X) -> snmp_notification_mib(X). + +snmp_notification_mib_3(X) -> snmp_notification_mib(X). + +snmp_notification_mib() -> + ?INF("NOT YET IMPLEMENTED", []), + nyi. + +%%----------------------------------------------------------------- +%% o add/delete views and try them +%% o try boundaries +%%----------------------------------------------------------------- +snmp_view_based_acm_mib(suite) -> []; +snmp_view_based_acm_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + ?line load_master("Test2"), + snmp_view_based_acm_mib(), + ?line unload_master("Test2"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). + +snmp_view_based_acm_mib_2(X) -> snmp_view_based_acm_mib(X). + +snmp_view_based_acm_mib_3(X) -> snmp_view_based_acm_mib(X). + +snmp_view_based_acm_mib() -> + snmpa:verbosity(net_if,trace), + snmpa:verbosity(master_agent,trace), + ?LOG("start snmp_view_based_acm_mib test",[]), + %% The user "no-rights" is present in USM, and is mapped to security + %% name 'no-rights", which is not present in VACM. + %% So, we'll add rights for it, try them and delete them. + %% We'll give "no-rights" write access to tDescr.0 and read access + %% to tDescr2.0 + %% These are the options we'll use to the mgr + Opts = [{user, "no-rights"}, {community, "no-rights"}], + %% Find the valid secmodel, and one invalid secmodel. + {SecMod, InvSecMod} = + case get(vsn) of + v1 -> {?SEC_V1, ?SEC_V2C}; + v2 -> {?SEC_V2C, ?SEC_USM}; + v3 -> {?SEC_USM, ?SEC_V1} + end, + ?DBG("assign rights for 'no-rights'",[]), + ?line try_test(use_no_rights, [], Opts), + + %% Now, add a mapping from "no-rights" -> "no-rights-group" + GRow1Status = [vacmSecurityToGroupStatus,[SecMod, 9,"no-rights"]], + GRow1 = + [{[vacmGroupName, [SecMod, 9,"no-rights"]], "no-rights-group"}, + {GRow1Status, ?createAndGo}], + ?DBG("set '~p'",[GRow1]), + ?line try_test(do_set, [GRow1]), + + ?DBG("assign rights for 'no-rights'",[]), + ?line try_test(use_no_rights, [], Opts), + + %% Create a mapping for another sec model, and make sure it dosn't + %% give us access + GRow2Status = [vacmSecurityToGroupStatus,[InvSecMod, 9,"no-rights"]], + GRow2 = [{[vacmGroupName, [InvSecMod, 9, "no-rights"]], "initial"}, + {GRow2Status, ?createAndGo}], + + ?DBG("set '~p'",[GRow2]), + ?line try_test(do_set, [GRow2]), + + ?DBG("assign rights for 'no-rights'",[]), + ?line try_test(use_no_rights, [], Opts), + + %% Delete that row + ?line try_test(del_row, [GRow2Status]), + + RVName = "rv_name", + WVName = "wv_name", + + %% Access row + ARow1Idx = [15 | "no-rights-group"] ++ [0, ?SEC_ANY, 1], + ARow1Status = [vacmAccessStatus, ARow1Idx], + ARow1 = [{[vacmAccessContextMatch, ARow1Idx], 1}, + {[vacmAccessReadViewName, ARow1Idx], RVName}, + {[vacmAccessWriteViewName, ARow1Idx], WVName}, + {ARow1Status, ?createAndGo}], + + %% This access row would give acces, if InvSecMod was valid. + ARow2Idx = [15 | "no-rights-group"] ++ [0, InvSecMod, 1], + ARow2Status = [vacmAccessStatus, ARow2Idx], + ARow2 = [{[vacmAccessContextMatch, ARow2Idx], 1}, + {[vacmAccessReadViewName, ARow2Idx], "internet"}, + {[vacmAccessWriteViewName, ARow2Idx], "internet"}, + {ARow2Status, ?createAndGo}], + + ?line try_test(do_set, [ARow2]), + + ?line try_test(use_no_rights, [], Opts), + + %% Delete that row + ?line try_test(del_row, [ARow2Status]), + + + %% Add valid row + ?line try_test(do_set, [ARow1]), + + ?line try_test(use_no_rights, [], Opts), + + %% Create the view family + VRow1Idx = mk_ln(RVName) ++ mk_ln(?xDescr), % object access + VRow2Idx = mk_ln(RVName) ++ mk_ln(?xDescr2 ++ [0]), % instance access + VRow3Idx = mk_ln(WVName) ++ mk_ln(?xDescr), % object access + VRow4Idx = mk_ln(WVName) ++ mk_ln(?xDescr ++ [0]), % instance access + VRow1Status = [vacmViewTreeFamilyStatus, VRow1Idx], + VRow2Status = [vacmViewTreeFamilyStatus, VRow2Idx], + VRow3Status = [vacmViewTreeFamilyStatus, VRow3Idx], + VRow4Status = [vacmViewTreeFamilyStatus, VRow4Idx], + + ?line try_test(add_row, [VRow1Status]), + ?line try_test(add_row, [VRow2Status]), + ?line try_test(add_row, [VRow3Status]), + + %% We're supposed to have access now... + ?line try_test(use_rights, [], Opts), + + %% Change Row3 to Row4 + ?line try_test(del_row, [VRow3Status]), + ?line try_test(add_row, [VRow4Status]), + + %% We should still have access... + ?line try_test(use_rights, [], Opts), + + %% Delete rows + ?line try_test(del_row, [GRow1Status]), + + ?line try_test(use_no_rights, [], Opts), + + %% Delete rest of rows + ?line try_test(del_row, [ARow1Status]), + ?line try_test(del_row, [VRow1Status]), + ?line try_test(del_row, [VRow2Status]), + ?line try_test(del_row, [VRow4Status]), + + ?line try_test(use_no_rights, [], Opts), + snmpa:verbosity(master_agent,log). + +do_set(Row) -> + s(Row), + expect(1, Row). + +add_row(RowStatus) -> + s([{RowStatus, ?createAndGo}]), + expect(1, [{RowStatus, ?createAndGo}]). + +del_row(RowStatus) -> + s([{RowStatus, ?destroy}]), + expect(1, [{RowStatus, ?destroy}]). + + + +use_no_rights() -> + g([[xDescr,0]]), + ?v1_2_3(expect(11, noSuchName, 1, any), + expect(12, [{[xDescr,0], noSuchObject}]), + expect(13, authorizationError, 1, any)), + g([[xDescr2,0]]), + ?v1_2_3(expect(21, noSuchName, 1, any), + expect(22, [{[xDescr2,0], noSuchObject}]), + expect(23, authorizationError, 1, any)), + gn([[xDescr]]), + ?v1_2_3(expect(31, noSuchName, 1, any), + expect(32, [{[xDescr], endOfMibView}]), + expect(33, authorizationError, 1, any)), + s([{[xDescr,0], "tryit"}]), + ?v1_2_3(expect(41, noSuchName, 1, any), + expect(42, noAccess, 1, any), + expect(43, authorizationError, 1, any)). + + +use_rights() -> + g([[xDescr,0]]), + expect(1, [{[xDescr,0], any}]), + g([[xDescr2,0]]), + expect(2, [{[xDescr2,0], any}]), + s([{[xDescr,0], "tryit"}]), + expect(3, noError, 0, any), + g([[xDescr,0]]), + expect(4, [{[xDescr,0], "tryit"}]). + +mk_ln(X) -> + [length(X) | X]. + +%%----------------------------------------------------------------- +%% o add/delete users and try them +%% o test all secLevels +%% o test all combinations of protocols +%% o try bad ops; check counters +%%----------------------------------------------------------------- +snmp_user_based_sm_mib_3(suite) -> []; +snmp_user_based_sm_mib_3(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + _AgentDir = ?config(agent_dir, Config), + ?line load_master_std("SNMP-USER-BASED-SM-MIB"), + + %% The newUser used here already has VACM access. + + %% Add a new user in the simplest way; just createAndGo + try_test(v3_sync, [[{usm_add_user1, []}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + %% Try to use the new user + ?line load_master("Test2"), + try_test(v3_sync, [[{usm_use_user, []}]], + [{sec_level, authPriv}, {user, "newUser"}]), + ?line unload_master("Test2"), + + ShaKey1 = snmp:passwd2localized_key(sha, "new sha password", "agentEngine"), + DesKey1 = lists:sublist(ShaKey1, 16), + + %% Change the new user's keys - 1 + try_test(v3_sync, [[{usm_key_change1, [ShaKey1, DesKey1]}]], + [{sec_level, authPriv}, {user, "newUser"}]), + + %% Try to use the new keys + MgrDir = ?config(mgr_dir, Config), + ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), + ?line load_master("Test2"), + try_test(v3_sync, [[{usm_use_user, []}]], + [{sec_level, authPriv}, {user, "newUser"}]), + ?line unload_master("Test2"), + + ShaKey2 = snmp:passwd2localized_key(sha, "newer password", "agentEngine"), + DesKey2 = lists:sublist(ShaKey2, 16), + + %% Change the new user's keys - 2 + ?line try_test(v3_sync, + [[{usm_key_change2, [ShaKey1, DesKey1, ShaKey2, DesKey2]}]], + [{sec_level, authPriv}, {user, "newUser"}]), + + %% Try to use the new keys + reset_usm_mgr(MgrDir), + ?line rewrite_usm_mgr(MgrDir, ShaKey2, DesKey2), + ?line load_master("Test2"), + ?line try_test(v3_sync, [[{usm_use_user, []}]], + [{sec_level, authPriv}, {user, "newUser"}]), + ?line unload_master("Test2"), + reset_usm_mgr(MgrDir), + + %% Change the new user's keys - 3 + ?line try_test(v3_sync, + [[{usm_key_change3, [ShaKey2, DesKey2, ShaKey1, DesKey1]}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + %% Try to use the new keys + ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), + ?line load_master("Test2"), + try_test(v3_sync, [[{usm_use_user, []}]], + [{sec_level, authPriv}, {user, "newUser"}]), + ?line unload_master("Test2"), + reset_usm_mgr(MgrDir), + + %% Try some read requests + ?line try_test(v3_sync, [[{usm_read, []}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + %% Delete the new user + ?line try_test(v3_sync, [[{usm_del_user, []}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + %% Try some bad requests + ?line try_test(v3_sync, [[{usm_bad, []}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + ?line unload_master("SNMP-USER-BASED-SM-MIB"). + +-define(usmUserSecurityName, [1,3,6,1,6,3,15,1,2,2,1,3]). + +usm_add_user1() -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + RowPointer = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], + Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer}, + {[usmUserStatus, NewRowIndex], ?createAndGo}], + ?line s(Vbs1), + ?line expect(1, Vbs1), + ok. + +usm_use_user() -> + v2_proc(). + + +%% Change own public keys +usm_key_change1(ShaKey, DesKey) -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + "passwd_shaxxxxxxxxxx", + ShaKey), + DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + "passwd_desxxxxxx", + DesKey), + Vbs1 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, + {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], + s(Vbs1), + ?line expect(1, Vbs1). + +%% Change own private keys +usm_key_change2(OldShaKey, OldDesKey, ShaKey, DesKey) -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + OldShaKey, + ShaKey), + DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + OldDesKey, + DesKey), + Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}, + {[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], + s(Vbs1), + ?line expect(1, Vbs1). + +%% Change other's public keys +usm_key_change3(OldShaKey, OldDesKey, ShaKey, DesKey) -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + OldShaKey, + ShaKey), + DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + OldDesKey, + DesKey), + Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}], + s(Vbs1), + ?line expect(1, noAccess, 1, any), + Vbs2 = [{[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], + s(Vbs2), + ?line expect(2, noAccess, 1, any), + + + Vbs3 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, + {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], + s(Vbs3), + ?line expect(1, Vbs3). + +usm_read() -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + ?line g([[usmUserSecurityName, NewRowIndex], + [usmUserCloneFrom, NewRowIndex], + [usmUserAuthKeyChange, NewRowIndex], + [usmUserOwnAuthKeyChange, NewRowIndex], + [usmUserPrivKeyChange, NewRowIndex], + [usmUserOwnPrivKeyChange, NewRowIndex]]), + ?line expect(1, + [{[usmUserSecurityName, NewRowIndex], "newUser"}, + {[usmUserCloneFrom, NewRowIndex], [0,0]}, + {[usmUserAuthKeyChange, NewRowIndex], ""}, + {[usmUserOwnAuthKeyChange, NewRowIndex], ""}, + {[usmUserPrivKeyChange, NewRowIndex], ""}, + {[usmUserOwnPrivKeyChange, NewRowIndex], ""}]), + ok. + + + +usm_del_user() -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + Vbs1 = [{[usmUserStatus, NewRowIndex], ?destroy}], + ?line s(Vbs1), + ?line expect(1, Vbs1), + ok. + +-define(usmUserCloneFrom, [1,3,6,1,6,3,15,1,2,2,1,4]). + +-define(usmNoAuthProtocol, [1,3,6,1,6,3,10,1,1,1]). + +-define(usmHMACMD5AuthProtocol, [1,3,6,1,6,3,10,1,1,2]). + +-define(usmHMACSHAAuthProtocol, [1,3,6,1,6,3,10,1,1,3]). + +-define(usmNoPrivProtocol, [1,3,6,1,6,3,10,1,2,1]). + +-define(usmDESPrivProtocol, [1,3,6,1,6,3,10,1,2,2]). + +usm_bad() -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + RowPointer1 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDOS"], + Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer1}, + {[usmUserStatus, NewRowIndex], ?createAndGo}], + ?line s(Vbs1), + ?line expect(1, inconsistentName, 1, any), + + RowPointer2 = ?usmUserCloneFrom ++ [11|"agentEngine"] ++ [7|"privDES"], + Vbs2 = [{[usmUserCloneFrom, NewRowIndex], RowPointer2}, + {[usmUserStatus, NewRowIndex], ?createAndGo}], + ?line s(Vbs2), + ?line expect(2, wrongValue, 1, any), + + RowPointer3 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], + Vbs3 = [{[usmUserCloneFrom, NewRowIndex], RowPointer3}, + {[usmUserStatus, NewRowIndex], ?createAndGo}], + ?line s(Vbs3), + ?line expect(3, Vbs3), + ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmNoAuthProtocol}]), + ?line expect(4, inconsistentValue, 1, any), + ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmHMACMD5AuthProtocol}]), + ?line expect(5, inconsistentValue, 1, any), + ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmDESPrivProtocol}]), + ?line expect(6, wrongValue, 1, any), + ?line s([{[usmUserPrivProtocol, NewRowIndex], ?usmHMACSHAAuthProtocol}]), + ?line expect(7, wrongValue, 1, any), + + Vbs4 = [{[usmUserStatus, NewRowIndex], ?destroy}], + ?line s(Vbs4), + ?line expect(1, Vbs4), + + ok. + + +%%----------------------------------------------------------------- +%% Loop through entire MIB, to make sure that all instrum. funcs +%% works. +%% Load all std mibs that are not loaded by default. +%%----------------------------------------------------------------- +loop_mib(suite) -> []; +loop_mib(Config) when list(Config) -> + ?LOG("loop_mib -> initiate case",[]), + %% snmpa:verbosity(master_agent,debug), + %% snmpa:verbosity(mib_server,info), + {SaNode, MgrNode, MibDir} = init_case(Config), + ?DBG("loop_mib -> ~n" + "\tSaNode: ~p~n" + "\tMgrNode: ~p~n" + "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), + ?DBG("loop_mib -> load mib SNMP-COMMUNITY-MIB",[]), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?DBG("loop_mib -> load mib SNMP-MPD-MIB",[]), + ?line load_master_std("SNMP-MPD-MIB"), + ?DBG("loop_mib -> load mib SNMP-TARGET-MIB",[]), + ?line load_master_std("SNMP-TARGET-MIB"), + ?DBG("loop_mib -> load mib SNMP-NOTIFICATION-MIB",[]), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?DBG("loop_mib -> load mib SNMP-FRAMEWORK-MIB",[]), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?DBG("loop_mib -> load mib SNMP-VIEW-BASED-ACM-MIB",[]), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + ?DBG("loop_mib -> try",[]), + try_test(loop_mib_1), + ?DBG("loop_mib -> unload mib SNMP-COMMUNITY-MIB",[]), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?DBG("loop_mib -> unload mib SNMP-MPD-MIB",[]), + ?line unload_master("SNMP-MPD-MIB"), + ?DBG("loop_mib -> unload mib SNMP-TARGET-MIB",[]), + ?line unload_master("SNMP-TARGET-MIB"), + ?DBG("loop_mib -> unload mib SNMP-NOTIFICATION-MIB",[]), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?DBG("loop_mib -> unload mib SNMP-FRAMEWORK-MIB",[]), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?DBG("loop_mib -> unload mib SNMP-VIEW-BASED-ACM-MIB",[]), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + %% snmpa:verbosity(master_agent,log), + %% snmpa:verbosity(mib_server,silence), + ?LOG("loop_mib -> done",[]). + + +loop_mib_2(suite) -> []; +loop_mib_2(Config) when list(Config) -> + ?LOG("loop_mib_2 -> initiate case",[]), + {SaNode, MgrNode, MibDir} = init_case(Config), + ?DBG("loop_mib_2 -> ~n" + "\tSaNode: ~p~n" + "\tMgrNode: ~p~n" + "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), + ?DBG("loop_mib_2 -> load mibs",[]), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-MPD-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + try_test(loop_mib_2), + ?DBG("loop_mib_2 -> unload mibs",[]), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?line unload_master("SNMP-MPD-MIB"), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + ?LOG("loop_mib_2 -> done",[]). + + +loop_mib_3(suite) -> []; +loop_mib_3(Config) when list(Config) -> + ?LOG("loop_mib_3 -> initiate case",[]), + {SaNode, MgrNode, MibDir} = init_case(Config), + ?DBG("loop_mib_3 -> ~n" + "\tSaNode: ~p~n" + "\tMgrNode: ~p~n" + "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), + ?DBG("loop_mib_3 -> load mibs",[]), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + ?line load_master_std("SNMP-USER-BASED-SM-MIB"), + try_test(loop_mib_2), + ?DBG("loop_mib_3 -> unload mibs",[]), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + ?line unload_master("SNMP-USER-BASED-SM-MIB"), + ?LOG("loop_mib_3 -> done",[]). + + +%% Req. As many mibs all possible +loop_mib_1() -> + ?DBG("loop_mib_1 -> entry",[]), + N = loop_it_1([1,1], 0), + io:format(user, "found ~w varibles\n", [N]), + ?line N = if N < 100 -> 100; + true -> N + end. + + +loop_it_1(Oid, N) -> + ?DBG("loop_it_1 -> entry with~n" + "\tOid: ~p~n" + "\tN: ~p",[Oid,N]), + case get_next_req([Oid]) of + #pdu{type='get-response', error_status=noError, error_index=0, + varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> + ?DBG("loop_it_1 -> ~n" + "\tNOid: ~p~n" + "\tValue: ~p",[NOid,Value]), + ?line [Value2] = get_req(1, [NOid]), % must not be same + ?DBG("loop_it_1 -> ~n" + "\tValue2: ~p",[Value2]), + loop_it_1(NOid, N+1); + #pdu{type='get-response', error_status=noSuchName, error_index=1, + varbinds=[_]} -> + ?DBG("loop_it_1 -> done",[]), + N; + + #pdu{type = Type, error_status = Err, error_index = Idx, + varbinds = Vbs} -> + exit({unexpected_pdu, ?LINE, Type, Err, Idx, Vbs}) + end. + +%% Req. As many mibs all possible +loop_mib_2() -> + ?DBG("loop_mib_1 -> entry",[]), + N = loop_it_2([1,1], 0), + io:format(user, "found ~w varibles\n", [N]), + ?line N = if N < 100 -> 100; + true -> N + end. + + +loop_it_2(Oid, N) -> + ?DBG("loop_it_2 -> entry with~n" + "\tOid: ~p~n" + "\tN: ~p",[Oid,N]), + case get_next_req([Oid]) of + #pdu{type='get-response', error_status=noError, error_index=0, + varbinds=[#varbind{oid = NOid, value = endOfMibView}]} -> + ?DBG("loop_it_2 -> ~n" + "\tNOid: ~p",[NOid]), + N; + #pdu{type='get-response', error_status=noError, error_index=0, + varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> + ?DBG("loop_it_2 -> ~n" + "\tNOid: ~p~n" + "\tValue: ~p",[NOid,Value]), + ?line [Value2] = get_req(1, [NOid]), % must not be same + ?DBG("loop_it_2 -> ~n" + "\tValue2: ~p",[Value2]), + loop_it_2(NOid, N+1) + end. + + +%%%----------------------------------------------------------------- +%%% Testing of reported bugs and other tickets. +%%%----------------------------------------------------------------- + + + + + +%% These are (ticket) test cases where the initiation has to be done +%% individually. + +%%----------------------------------------------------------------- +%% Ticket: OTP-1128 +%% Slogan: Bug in handling of createAndWait set-requests. +%%----------------------------------------------------------------- +otp_1128(suite) -> []; +otp_1128(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(otp_1128), + ?line unload_master("OLD-SNMPEA-MIB"). + +otp_1128_2(X) -> otp_1128(X). + +otp_1128_3(X) -> otp_1128(X). + +otp_1128() -> + io:format("Testing bug reported in ticket OTP-1128...~n"), + + NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], + NewKeyc4 = [intCommunityAccess,get(mip),is("test")], + NewKeyc5 = [intCommunityStatus,get(mip),is("test")], + + s([{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), + ?line expect(28, [{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), + g([NewKeyc5]), + ?line expect(29, [{NewKeyc5, ?notReady}]), + s([{NewKeyc5, ?active}, {NewKeyc3, 2}]), + ?line expect(30, [{NewKeyc5, ?active}, {NewKeyc3, 2}]), + g([NewKeyc5]), + ?line expect(31, [{NewKeyc5, ?active}]), + s([{NewKeyc5, ?destroy}]), + ?line expect(32, [{NewKeyc5, ?destroy}]). + +%%----------------------------------------------------------------- +%% Ticket: OTP-1129, OTP-1169 +%% Slogan: snmpa:int_to_enum crashes on bad oids +%%----------------------------------------------------------------- +otp_1129(suite) -> []; +otp_1129(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas3"), + try_test(otp_1129_i, [node()]), + ?line unload_master("Klas3"). + +otp_1129_2(X) -> otp_1129(X). + +otp_1129_3(X) -> otp_1129(X). + +otp_1129_i(MaNode) -> + io:format("Testing bug reported in ticket OTP-1129...~n"), + false = rpc:call(MaNode, snmp, int_to_enum, [iso, 1]), + false = rpc:call(MaNode, snmp, int_to_enum, [isox, 1]). + +%%----------------------------------------------------------------- +%% Ticket: OTP-1131 +%% Slogan: Agent crashes / erlang node halts if RowIndex in a +%% setrequest is of bad type, e.g. an INDEX {INTEGER}, +%% and RowIdenx [3,2]. +%%----------------------------------------------------------------- +otp_1131(suite) -> []; +otp_1131(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas1"), + try_test(otp_1131), + ?line unload_master("Klas1"). + +otp_1131_2(X) -> otp_1131(X). + +otp_1131_3(X) -> otp_1131(X). + +otp_1131() -> + io:format("Testing bug reported in ticket OTP-1131...~n"), + s([{[friendsEntry, [2, 3, 1]], s, "kompis3"}, + {[friendsEntry, [3, 3, 1]], i, ?createAndGo}]), + ?line expect(1, ?v1_2(noSuchName, noCreation), 2, any). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1162 +%% Slogan: snmp_agent can't handle wrongValue from instrum.func +%%----------------------------------------------------------------- +otp_1162(suite) -> []; +otp_1162(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + try_test(otp_1162), + stop_subagent(SA). + +otp_1162_2(X) -> otp_1162(X). + +otp_1162_3(X) -> otp_1162(X). + +otp_1162() -> + s([{[sa, [2,0]], 6}]), % wrongValue (i is_set_ok) + ?line expect(1, ?v1_2(badValue, wrongValue), 1, any). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1222 +%% Slogan: snmp agent crash if faulty index is returned from instrum +%%----------------------------------------------------------------- +otp_1222(suite) -> []; +otp_1222(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas3"), + ?line load_master("Klas4"), + try_test(otp_1222), + ?line unload_master("Klas3"), + ?line unload_master("Klas4"). + +otp_1222_2(X) -> otp_1222(X). + +otp_1222_3(X) -> otp_1222(X). + +otp_1222() -> + io:format("Testing bug reported in ticket OTP-1222...~n"), + s([{[fStatus4,1], 4}, {[fName4,1], 1}]), + ?line expect(1, genErr, 0, any), + s([{[fStatus4,2], 4}, {[fName4,2], 1}]), + ?line expect(2, genErr, 0, any). + +%%----------------------------------------------------------------- +%% Ticket: OTP-1298 +%% Slogan: Negative INTEGER values are treated as positive. +%%----------------------------------------------------------------- +otp_1298(suite) -> []; +otp_1298(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas2"), + try_test(otp_1298), + ?line unload_master("Klas2"). + +otp_1298_2(X) -> otp_1298(X). + +otp_1298_3(X) -> otp_1298(X). + +otp_1298() -> + io:format("Testing bug reported in ticket OTP-1298...~n"), + s([{[fint,0], -1}]), + ?line expect(1298, [{[fint,0], -1}]). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1331 +%% Slogan: snmp_generic should return noError when deleting non-ex row +%%----------------------------------------------------------------- +otp_1331(suite) -> []; +otp_1331(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(otp_1331), + ?line unload_master("OLD-SNMPEA-MIB"). + +otp_1331_2(X) -> otp_1331(X). + +otp_1331_3(X) -> otp_1331(X). + +otp_1331() -> + NewKeyc5 = [intCommunityStatus,[127,32,0,0],is("test")], + s([{NewKeyc5, ?destroy}]), + ?line expect(1, [{NewKeyc5, ?destroy}]). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1338 +%% Slogan: snmp bug in initialisation of default values for mnesia tabs +%%----------------------------------------------------------------- +otp_1338(suite) -> []; +otp_1338(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas2"), + try_test(otp_1338), + ?line unload_master("Klas2"). + +otp_1338_2(X) -> otp_1338(X). + +otp_1338_3(X) -> otp_1338(X). + +otp_1338() -> + s([{[kStatus2, 7], i, ?createAndGo}]), + ?line expect(1, [{[kStatus2, 7], ?createAndGo}]), + g([[kName2, 7]]), + ?line expect(2, [{[kName2, 7], "JJJ"}]). + +%%----------------------------------------------------------------- +%% Ticket: OTP-1342 +%% Slogan: default impl of snmp table can't handle bad index access, +%% Set when INDEX is read-write gets into an infinite loop! +%%----------------------------------------------------------------- +otp_1342(suite) -> []; +otp_1342(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas4"), + try_test(otp_1342), + ?line unload_master("Klas4"). + +otp_1342_2(X) -> otp_1342(X). + +otp_1342_3(X) -> otp_1342(X). + +otp_1342() -> + s([{[fIndex5, 1], i, 1}, + {[fName5, 1], i, 3}, + {[fStatus5, 1], i, ?createAndGo}]), + ?line expect(1, ?v1_2(noSuchName, noCreation), 3, any). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1366 +%% Slogan: snmp traps not sent to all managers +%% Note: NYI! We need a way to tell the test server that we need +%% mgrs on two different machines. +%%----------------------------------------------------------------- +otp_1366(suite) -> []; +otp_1366(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(otp_1366), + ?line unload_master("OLD-SNMPEA-MIB"). + +otp_1366_2(X) -> otp_1366(X). + +otp_1366_3(X) -> otp_1366(X). + +otp_1366() -> + ?INF("NOT YET IMPLEMENTED", []), + 'NYI'. + +%%----------------------------------------------------------------- +%% Ticket: OTP-2776 +%% Slogan: snmp:validate_date_and_time() fails when time is 00:00 +%%----------------------------------------------------------------- +otp_2776(suite) -> []; +otp_2776(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + try_test(otp_2776). + +otp_2776_2(X) -> otp_2776(X). + +otp_2776_3(X) -> otp_2776(X). + +otp_2776() -> + io:format("Testing bug reported in ticket OTP-2776...~n"), + + Dt01_valid = [19,98,9,1,1,0,23,0,43,0,0], + Dt02_valid = [19,98,9,1,0,0,0,0,43,0,0], % This is what is fixed: 00:00 + Dt03_valid = [19,98,2,28,1,0,23,0,43,0,0], + Dt04_invalid = [19,98,2,29,1,0,23,0,43,0,0], + Dt05_valid = [19,96,2,29,1,0,23,0,43,0,0], + Dt06_valid = [20,0,2,29,1,0,23,0,43,0,0], + Dt07_invalid = [19,96,2,30,1,0,23,0,43,0,0], % This is also fixed: 30/2 + Dt08_valid = [19,98,4,30,1,0,23,0,43,0,0], + Dt09_invalid = [19,98,4,31,1,0,23,0,43,0,0], % This is also fixed: 31/4 + Dt10_invalid = [], + Dt11_invalid = [kalle,hobbe], + L = [{ 1, true, Dt01_valid}, + { 2, true, Dt02_valid}, + { 3, true, Dt03_valid}, + { 4, false, Dt04_invalid}, + { 5, true, Dt05_valid}, + { 6, true, Dt06_valid}, + { 7, false, Dt07_invalid}, + { 8, true, Dt08_valid}, + { 9, false, Dt09_invalid}, + {10, false, Dt10_invalid}, + {11, false, Dt11_invalid}], + + ?line ok = validate_dat(L). + + +validate_dat(L) -> validate_dat(L,[]). + +validate_dat([],V) -> + Fun = fun({_,X}) -> case X of + ok -> false; + _ -> true + end + end, + validate_dat1( lists:reverse( lists:filter(Fun,V) ) ); +validate_dat([{Id,E,Dat}|T],V) -> + validate_dat(T,[validate_dat2(Id,E,Dat) | V]). + +validate_dat1([]) -> ok; +validate_dat1(L) -> {error,L}. + +validate_dat2(Id, E, Dat) -> + Res = case {E,snmp:validate_date_and_time(Dat)} of + {E,E} -> ok; + {E,A} -> {E,A} + end, + {Id, Res}. + + +%%----------------------------------------------------------------- +%% Ticket: OTP-2979 +%% Slogan: get-next on more than 1 column in an empty table +%% returns bad response. +%%----------------------------------------------------------------- +otp_2979(suite) -> []; +otp_2979(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Test1"), + ?line init_old(), + try_test(otp_2979), + ?line unload_master("Test1"). + +otp_2979_2(X) -> otp_2979(X). + +otp_2979_3(X) -> otp_2979(X). + +otp_2979() -> + gn([[sparseDescr], [sparseStatus]]), + ?line expect(1, [{[sparseStr,0], "slut"}, + {[sparseStr,0], "slut"}]). + +%%----------------------------------------------------------------- +%% Ticket: OTP-3187 +%% Slogan: get-next on vacmAccessTable for colums > 5 returns +%% endOfTable - should return value. +%%----------------------------------------------------------------- +otp_3187(suite) -> []; +otp_3187(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + otp_3187(), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). + +otp_3187_2(X) -> otp_3187(X). + +otp_3187_3(X) -> otp_3187(X). + +otp_3187() -> + ?line Elements = + snmp_view_based_acm_mib:vacmAccessTable(get_next,[],[4,5,6]), + lists:foreach(fun(E) -> + ?line if E == endOfTable -> + ?FAIL(endOfTable); + true -> ok + end + end, Elements). + +%%----------------------------------------------------------------- +%% Ticket: OTP-3542 +%% Slogan: +%%----------------------------------------------------------------- +otp_3542(suite) -> []; +otp_3542(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + try_test(otp_3542). + +otp_3542() -> + io:format("SNMP v3 discovery...~n"), + ?line Res = snmp_test_mgr:d(), + io:format("SNMP v3 discovery result: ~p~n",[Res]). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-3725 +%% Slogan: Slow response time on snmpa:int_to_enum +%%----------------------------------------------------------------- +otp_3725(suite) -> []; +otp_3725(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(otp_3725_test, [node()]), + ?line unload_master("OLD-SNMPEA-MIB"). + +%% Req. OLD-SNMPEA-MIB +otp_3725_test(MaNode) -> + io:format("Testing feature requested in ticket OTP-3725...~n"), + ?line rpc:call(MaNode,snmpa,verbosity,[symbolic_store,trace]), + ?line Db = rpc:call(MaNode,snmp,get_symbolic_store_db,[]), + ?DBG("otp_3725_test -> Db = ~p",[Db]), + + ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, + [Db, intAgentIpAddress]), + ?DBG("otp_3725_test -> name_to_oid for ~p: ~p",[intAgentIpAddress,OID]), + ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, oid_to_name, + [Db,OID]), + ?DBG("otp_3725_test -> oid_to_name for ~p: ~p",[OID,intAgentIpAddress]), + ?line false = rpc:call(MaNode, snmp, name_to_oid, [Db, intAgentIpAddres]), + ?line false = rpc:call(MaNode, snmp, oid_to_name, + [Db, [1,5,32,3,54,3,3,34,4]]), + ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, + [Db, intViewType, excluded]), + ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, + [Db, intViewType, 2]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, intViewType, exclude]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, intAgentIpAddress, exclude]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, intAgentIpAddre, exclude]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, intViewType, 3]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, + [Db, intAgentIpAddress, 2]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, + [Db, intAgentIpAddre, 2]), + ?line {value, active} = rpc:call(MaNode, snmp, int_to_enum, + [Db, 'RowStatus', ?active]), + ?line {value, ?destroy} = rpc:call(MaNode, snmp, enum_to_int, + [Db, 'RowStatus', destroy]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, 'RowStatus', xxxdestroy]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, 'xxRowStatus', destroy]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'RowStatus', 25]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'xxRowStatus', 1]), + ok. + + +%%----------------------------------------------------------------- +%% Ticket: OTP-4394 +%% Slogan: Target mib tag list check invalid +%%----------------------------------------------------------------- + + + +init_otp_4394(Config) when list(Config) -> + ?DBG("init_otp_4394 -> entry with" + "~n Config: ~p", [Config]), + ?line AgentDir = ?config(agent_dir, Config), + ?line MgrDir = ?config(mgr_dir, Config), + ?line Ip = ?config(ip, Config), + ?line otp_4394_config(AgentDir, MgrDir, Ip), + MasterAgentVerbosity = {master_agent_verbosity, trace}, + NetIfVerbosity = {net_if_verbosity, trace}, + Opts = [MasterAgentVerbosity,NetIfVerbosity], + [{vsn, v1} | start_v1_agent(Config,Opts)]. + +otp_4394_config(AgentDir, MgrDir, Ip0) -> + ?DBG("otp_4394_config -> entry with" + "~n AgentDir: ~p" + "~n MgrDir: ~p" + "~n Ip0: ~p", [AgentDir, MgrDir, Ip0]), + Vsn = [v1], + Ip = tuple_to_list(Ip0), + ?line snmp_config:write_agent_snmp_files(AgentDir, Vsn, Ip, + ?TRAP_UDP, Ip, 4000, + "OTP-4394 test"), + ?line case update_usm(Vsn, AgentDir) of + true -> + ?line copy_file(filename:join(AgentDir, "usm.conf"), + filename:join(MgrDir, "usm.conf")), + ?line update_usm_mgr(Vsn, MgrDir); + false -> + ?line ok + end, + C1 = {"a", "all-rights", "initial", "", "pc"}, + C2 = {"c", "secret", "secret_name", "", "secret_tag"}, + ?line write_community_conf(AgentDir, [C1, C2]), + ?line update_vacm(Vsn, AgentDir), + Ta1 = {"shelob v1", + [134,138,177,177], 5000, 1500, 3, %% Använd Ip och modda + "pc1", + "target_v1", "", + %% [255,255,255,255,0,0], + [], + 2048}, + Ta2 = {"bifur v1", + [134,138,177,75], 5000, 1500, 3, %% Använd Ip + "pc2", + "target_v1", "", + %% [255,255,255,255,0,0], + [], 2048}, + ?line write_target_addr_conf(AgentDir, [Ta1, Ta2]), + ?line write_target_params_conf(AgentDir, Vsn), + ?line write_notify_conf(AgentDir), + ok. + + + +finish_otp_4394(Config) when list(Config) -> + ?DBG("finish_otp_4394 -> entry", []), + C1 = stop_agent(Config), + delete_files(C1), + erase(mgr_node), + lists:keydelete(vsn, 1, C1). + +otp_4394_test(suite) -> []; +otp_4394_test(Config) -> + ?DBG("otp_4394_test -> entry", []), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + try_test(otp_4394_test1), + ?DBG("otp_4394_test -> done", []), + ok. + +otp_4394_test1() -> + ?DBG("otp_4394_test1 -> entry", []), + gn([[1,1]]), + Res = + case snmp_test_mgr:expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]) of + %% {error, 1, {"?",[]}, {"~w",[timeout]}} + {error, 1, _, {_, [timeout]}} -> + ?DBG("otp_4394_test1 -> expected result: timeout", []), + ok; + Else -> + Else + end, + ?DBG("otp_4394_test1 -> done with: ~p", [Res]), + Res. + + +%%%-------------------------------------------------- +%%% Used to test the standard mib with our +%%% configuration. +%%%-------------------------------------------------- +run(F, A, Opts) -> + M = get(mib_dir), + Dir = get(mgr_dir), + User = snmp_misc:get_option(user, Opts, "all-rights"), + SecLevel = snmp_misc:get_option(sec_level, Opts, noAuthNoPriv), + EngineID = snmp_misc:get_option(engine_id, Opts, "agentEngine"), + CtxEngineID = snmp_misc:get_option(context_engine_id, Opts, EngineID), + Community = snmp_misc:get_option(community, Opts, "all-rights"), + ?DBG("run -> start crypto app",[]), + Crypto = case os:type() of + vxworks -> + no_crypto; + _ -> + ?CRYPTO_START() + end, + ?DBG("run -> Crypto: ~p",[Crypto]), + catch snmp_test_mgr:stop(), % If we had a running mgr from a failed case + StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", + ?DBG("run -> config:~n" + "\tM: ~p~n" + "\tDir: ~p~n" + "\tUser: ~p~n" + "\tSecLevel: ~p~n" + "\tEngineID: ~p~n" + "\tCtxEngineID: ~p~n" + "\tCommunity: ~p~n" + "\tStdM: ~p", + [M,Dir,User,SecLevel,EngineID,CtxEngineID,Community,StdM]), + case snmp_test_mgr:start([%% {agent, snmp_test_lib:hostname()}, + {packet_server_debug,true}, + {debug,true}, + {agent, get(master_host)}, + {agent_udp, 4000}, + {trap_udp, 5000}, + {recbuf,65535}, + quiet, + get(vsn), + {community, Community}, + {user, User}, + {sec_level, SecLevel}, + {engine_id, EngineID}, + {context_engine_id, CtxEngineID}, + {dir, Dir}, + {mibs, mibs(StdM, M)}]) of + {ok, _Pid} -> + Res = apply(?MODULE, F, A), + catch snmp_test_mgr:stop(), + Res; + Err -> + io:format("Error starting manager: ~p\n", [Err]), + catch snmp_test_mgr:stop(), + ?line exit({mgr_start, Err}) + end. + + +mibs(StdMibDir,MibDir) -> + [join(StdMibDir, ?v1_2("STANDARD-MIB.bin", "SNMPv2-MIB.bin")), + join(MibDir, "OLD-SNMPEA-MIB.bin"), + join(StdMibDir, "SNMP-FRAMEWORK-MIB"), + join(StdMibDir, "SNMP-MPD-MIB"), + join(StdMibDir, "SNMP-VIEW-BASED-ACM-MIB"), + join(StdMibDir, "SNMP-USER-BASED-SM-MIB"), + join(StdMibDir, "SNMP-TARGET-MIB"), + join(StdMibDir, "SNMP-NOTIFICATION-MIB"), + join(MibDir, "Klas1.bin"), + join(MibDir, "Klas2.bin"), + join(MibDir, "Klas3.bin"), + join(MibDir, "Klas4.bin"), + join(MibDir, "SA-MIB.bin"), + join(MibDir, "TestTrap.bin"), + join(MibDir, "Test1.bin"), + join(MibDir, "Test2.bin"), + join(MibDir, "TestTrapv2.bin")]. + +join(D,F) -> + filename:join(D,F). + +%% string used in index +is(S) -> [length(S) | S]. + +try_test(Func) -> + call(get(mgr_node), ?MODULE, run, [Func, [], []]). + +try_test(Func, A) -> + call(get(mgr_node), ?MODULE, run, [Func, A, []]). + +try_test(Func, A, Opts) -> + call(get(mgr_node), ?MODULE, run, [Func, A, Opts]). + +call(N,M,F,A) -> + ?DBG("call -> entry with~n" + " N: ~p~n" + " M: ~p~n" + " F: ~p~n" + " A: ~p~n" + " when~n" + " get(): ~p", + [N,M,F,A,get()]), + spawn(N, ?MODULE, wait, [self(),get(),M,F,A]), + receive + {done, {'EXIT', Rn}, Loc} -> + ?DBG("call -> returned ~p",[{done, {'EXIT', Rn}, Loc}]), + put(test_server_loc, Loc), + exit(Rn); + {done, Ret, Zed} -> + ?DBG("call -> returned ~p~n",[{done, Ret, Zed}]), + Ret + end. + +wait(From, Env, M, F, A) -> + ?DBG("wait -> entry with ~n" + "\tFrom: ~p~n" + "\tEnv: ~p",[From,Env]), + lists:foreach(fun({K,V}) -> put(K,V) end, Env), + Rn = (catch apply(M, F, A)), + ?DBG("wait -> Rn: ~n~p", [Rn]), + From ! {done, Rn, get(test_server_loc)}, + exit(Rn). + +expect(A,B) -> ok = snmp_test_mgr:expect(A,B). +expect(A,B,C) -> ok = snmp_test_mgr:expect(A,B,C). +expect(A,B,C,D) -> ok = snmp_test_mgr:expect(A,B,C,D). +expect(A,B,C,D,E,F) -> ok = snmp_test_mgr:expect(A,B,C,D,E,F). + +get_req(Id, Vars) -> + ?DBG("get_req -> entry with~n" + "\tId: ~p~n" + "\tVars: ~p",[Id,Vars]), + g(Vars), + ?DBG("get_req -> await response",[]), + {ok, Val} = snmp_test_mgr:get_response(Id, Vars), + ?DBG("get_req -> response: ~p",[Val]), + Val. + +get_next_req(Vars) -> + ?DBG("get_next_req -> entry with Vars '~p', send request",[Vars]), + gn(Vars), + ?DBG("get_next_req -> await response",[]), + Response = snmp_test_mgr:receive_response(), + ?DBG("get_next_req -> response: ~p",[Response]), + Response. + + + +start_node(Name) -> + ?LOG("start_node -> entry with Name: ~p",[Name]), + M = list_to_atom(?HOSTNAME(node())), + ?DBG("start_node -> M: ~p",[M]), + Pa = filename:dirname(code:which(?MODULE)), + ?DBG("start_node -> Pa: ~p",[Pa]), + + Args = case init:get_argument('CC_TEST') of + {ok, [[]]} -> + " -pa /clearcase/otp/libraries/snmp/ebin "; + {ok, [[Path]]} -> + " -pa " ++ Path; + error -> + "" + end, + %% Do not use start_link!!! (the proc that calls this one is tmp) + ?DBG("start_node -> Args: ~p~n",[Args]), + A = Args ++ " -pa " ++ Pa, + case (catch ?START_NODE(Name, A)) of + {ok, Node} -> + %% Tell the test_server to not clean up things it never started. + ?DBG("start_node -> Node: ~p",[Node]), + {ok, Node}; + Else -> + ?ERR("start_node -> failed with(other): Else: ~p",[Else]), + ?line ?FAIL(Else) + end. + + +stop_node(Node) -> + ?LOG("stop_node -> Node: ~p",[Node]), + rpc:cast(Node, erlang, halt, []). + +p(X) -> + io:format(user, X++"\n", []). + +sleep(X) -> + receive + after + X -> ok + end. + +%%%----------------------------------------------------------------- +%%% Configuration +%%%----------------------------------------------------------------- +config(Vsns, MgrDir, AgentDir, MIp, AIp) -> + ?line snmp_config:write_agent_snmp_files(AgentDir, Vsns, MIp, + ?TRAP_UDP, AIp, 4000, + "test"), + ?line case update_usm(Vsns, AgentDir) of + true -> + ?line copy_file(filename:join(AgentDir, "usm.conf"), + filename:join(MgrDir, "usm.conf")), + ?line update_usm_mgr(Vsns, MgrDir); + false -> + ?line ok + end, + ?line update_community(Vsns, AgentDir), + ?line update_vacm(Vsns, AgentDir), + ?line write_target_addr_conf(AgentDir, MIp, ?TRAP_UDP, Vsns), + ?line write_target_params_conf(AgentDir, Vsns), + ?line write_notify_conf(AgentDir), + ok. + +delete_files(Config) -> + Dir = ?config(agent_dir, Config), + {ok, List} = file:list_dir(Dir), + lists:foreach(fun(FName) -> file:delete(filename:join(Dir, FName)) end, + List). + +update_usm(Vsns, Dir) -> + case lists:member(v3, Vsns) of + true -> + {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),[read,write]), + file:position(Fid, eof), + ok = io:format(Fid, "{\"agentEngine\", \"all-rights\", " + "\"all-rights\", zeroDotZero, " + "usmNoAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"\", \"\"}.\n", []), + ok = io:format(Fid, "{\"agentEngine\", \"no-rights\", " + "\"no-rights\", zeroDotZero, " + "usmNoAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"\", \"\"}.\n", []), + ok = io:format(Fid, "{\"agentEngine\", \"authMD5\", " + "\"authMD5\", zeroDotZero, " + "usmHMACMD5AuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"passwd_md5xxxxxx\", \"\"}.\n", []), + ok = io:format(Fid, "{\"agentEngine\", \"authSHA\", " + "\"authSHA\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"\"}.\n", []), + ok = io:format(Fid, "{\"agentEngine\", \"privDES\", " + "\"privDES\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", + []), + ok = io:format(Fid, "{\"mgrEngine\", \"all-rights\", " + "\"all-rights\", zeroDotZero, " + "usmNoAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"\", \"\"}.\n", []), + ok = io:format(Fid, "{\"mgrEngine\", \"no-rights\", " + "\"no-rights\", zeroDotZero, " + "usmNoAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"\", \"\"}.\n", []), + ok = io:format(Fid, "{\"mgrEngine\", \"authMD5\", " + "\"authMD5\", zeroDotZero, " + "usmHMACMD5AuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"passwd_md5xxxxxx\", \"\"}.\n", []), + ok = io:format(Fid, "{\"mgrEngine\", \"authSHA\", " + "\"authSHA\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"\"}.\n", []), + ok = io:format(Fid, "{\"mgrEngine\", \"privDES\", " + "\"privDES\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", + []), + file:close(Fid), + true; + false -> + false + end. + +update_usm_mgr(Vsns, Dir) -> + case lists:member(v3, Vsns) of + true -> + {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),[read,write]), + file:position(Fid, eof), + ok = io:format(Fid, "{\"agentEngine\", \"newUser\", " + "\"newUser\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", + []), + ok = io:format(Fid, "{\"mgrEngine\", \"newUser\", " + "\"newUser\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", + []), + file:close(Fid), + true; + false -> + false + end. + +rewrite_usm_mgr(Dir, ShaKey, DesKey) -> + ?line ok = file:rename(filename:join(Dir,"usm.conf"), + filename:join(Dir,"usm.old")), + ?line {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),write), + ok = io:format(Fid, "{\"agentEngine\", \"newUser\", " + "\"newUser\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"~s\", \"~s\"}.\n", + [ShaKey, DesKey]), + ok = io:format(Fid, "{\"mgrEngine\", \"newUser\", " + "\"newUser\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"~s\", \"~s\"}.\n", + [ShaKey, DesKey]), + file:close(Fid). + +reset_usm_mgr(Dir) -> + ?line ok = file:rename(filename:join(Dir,"usm.old"), + filename:join(Dir,"usm.conf")). + + +update_community([v3], _Dir) -> ok; +update_community(_, Dir) -> + {ok, Fid} = file:open(filename:join(Dir,"community.conf"),[read,write]), + file:position(Fid, eof), + ok=io:format(Fid,"{\"no-rights\",\"no-rights\",\"no-rights\",\"\",\"\"}.\n", + []), + file:close(Fid). + + +-define(tDescr_instance, [1,3,6,1,2,1,16,1,0]). +update_vacm(_Vsn, Dir) -> + {ok, Fid} = file:open(filename:join(Dir,"vacm.conf"),[read,write]), + file:position(Fid, eof), + ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"authMD5\",\"initial\"}.\n",[]), + ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"authSHA\",\"initial\"}.\n",[]), + ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"privDES\",\"initial\"}.\n",[]), + ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"newUser\",\"initial\"}.\n",[]), + ok = io:format(Fid, "{vacmViewTreeFamily, \"internet\", " + "~w, excluded, null}.\n", [?tDescr_instance]), + file:close(Fid). + + +vacm_ver(v1) -> v1; +vacm_ver(v2) -> v2c; +vacm_ver(v3) -> usm. + + +write_community_conf(Dir, Confs) -> + {ok, Fid} = file:open(filename:join(Dir,"community.conf"),write), + ok = write_community_conf1(Fid, Confs), + file:close(Fid). + +write_community_conf1(_, []) -> + ok; +write_community_conf1(Fid, [{ComIdx, ComName, SecName, CtxName, TransTag}|Confs]) -> + ok = io:format(Fid, "{\"~s\", \"~s\", \"~s\", \"~s\", \"~s\"}.~n", + [ComIdx, ComName, SecName, CtxName, TransTag]), + write_community_conf1(Fid, Confs). + + +write_target_addr_conf(Dir, Confs) -> + {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), + ok = write_target_addr_conf1(Fid, Confs), + file:close(Fid). + + +write_target_addr_conf1(_, []) -> + ok; +write_target_addr_conf1(Fid, + [{Name, Ip, Port, Timeout, Retry, TagList, ParamName, + EngineId, TMask, MaxMsgSz}|Confs]) -> + ok = io:format(Fid, "{\"~s\", ~w, ~w, ~w, ~w, \"~s\", \"~s\", \"~s\", ~w, ~w}.~n", + [Name, Ip, Port, Timeout, Retry, TagList, ParamName, + EngineId, TMask, MaxMsgSz]), + write_target_addr_conf1(Fid, Confs). + +write_target_addr_conf(Dir, ManagerIp, UDP, Vsns) -> + {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), + lists:foreach(fun(Vsn) -> + ok = io:format(Fid, + "{\"~s\", ~w, ~w, 1500, 3, " + "\"std_trap\", \"~s\"}.~n", + [mk_ip(ManagerIp, Vsn), + ManagerIp, UDP, mk_param(Vsn)]), + case Vsn of + v1 -> ok; + v2 -> + ok = io:format(Fid, + "{\"~s.2\",~w,~w,1500,3, " + "\"std_inform\", \"~s\"}.~n", + [mk_ip(ManagerIp, Vsn), + ManagerIp, UDP, + mk_param(Vsn)]); + v3 -> + ok = io:format(Fid, + "{\"~s.3\",~w,~w,1500,3, " + "\"std_inform\", \"~s\", " + "\"mgrEngine\", [], 1024}.~n", + [mk_ip(ManagerIp, Vsn), + ManagerIp, UDP, + mk_param(Vsn)]) + end + end, + Vsns), + file:close(Fid). + +mk_param(v1) -> "target_v1"; +mk_param(v2) -> "target_v2"; +mk_param(v3) -> "target_v3". + +mk_ip([A,B,C,D], Vsn) -> + io_lib:format("~w.~w.~w.~w ~w", [A,B,C,D,Vsn]). + + +rewrite_target_addr_conf(Dir,NewPort) -> + TAFile = filename:join(Dir, "target_addr.conf"), + ?DBG("rewrite_target_addr_conf -> read target file info of address config file",[]), + case file:read_file_info(TAFile) of + {ok, _} -> ok; + {error, R} -> ?ERR("failure reading file info of " + "target address config file: ~p",[R]), + ok + end, + + ?line [TrapAddr|Addrs] = + snmp_conf:read(TAFile,fun(R) -> rewrite_target_addr_conf1(R) end), + + ?DBG("rewrite_target_addr_conf -> TrapAddr: ~p",[TrapAddr]), + + NewAddrs = [rewrite_target_addr_conf2(NewPort,TrapAddr)|Addrs], + + ?DBG("rewrite_target_addr_conf -> NewAddrs: ~p",[NewAddrs]), + + ?line ok = file:rename(filename:join(Dir,"target_addr.conf"), + filename:join(Dir,"target_addr.old")), + ?line {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), + + ?line ok = rewrite_target_addr_conf3(Fid,NewAddrs), + + file:close(Fid). + +rewrite_target_addr_conf1(O) -> + {ok,O}. + +rewrite_target_addr_conf2(NewPort,{Name,Ip,_Port,Timeout,Retry, + "std_trap",EngineId}) -> + ?LOG("rewrite_target_addr_conf2 -> entry with std_trap",[]), + {Name,Ip,NewPort,Timeout,Retry,"std_trap",EngineId}; +rewrite_target_addr_conf2(_NewPort,O) -> + ?LOG("rewrite_target_addr_conf2 -> entry with " + "~n O: ~p",[O]), + O. + + +rewrite_target_addr_conf3(_,[]) -> ok; +rewrite_target_addr_conf3(Fid,[{Name,Ip,Port,Timeout,Retry, + ParamName,EngineId}|T]) -> + ?LOG("rewrite_target_addr_conf3 -> write(1) ~s",[ParamName]), + io:format(Fid, + "{\"~s\", " % Name + "~p, " % Ip + "~p, " % Port + "~p, " % Timeout + "~p, " % Retry + "\"~s\", " % ParamsName + "\"~s\"}.", % EngineId + [Name,Ip,Port,Timeout,Retry,ParamName,EngineId]), + rewrite_target_addr_conf3(Fid,T); +rewrite_target_addr_conf3(Fid,[{Name,Ip,Port,Timeout,Retry,TagList, + ParamName,EngineId,TMask,MMS}|T]) -> + ?LOG("rewrite_target_addr_conf3 -> write(2) ~s",[ParamName]), + io:format(Fid, + "{\"~s\", " % Name + "~p, " % Ip + "~p, " % Port + "~p, " % Timeout + "~p, " % Retry + "\"~s\", " % TagList + "\"~s\", " % ParamsName + "\"~s\"," % EngineId + "~p, " % TMask + "~p}.", % MMS + [Name,Ip,Port,Timeout,Retry,TagList,ParamName, + EngineId,TMask,MMS]), + rewrite_target_addr_conf3(Fid,T). + +reset_target_addr_conf(Dir) -> + ?line ok = file:rename(filename:join(Dir,"target_addr.old"), + filename:join(Dir,"target_addr.conf")). + +write_target_params_conf(Dir, Vsns) -> + {ok, Fid} = file:open(filename:join(Dir,"target_params.conf"),write), + lists:foreach(fun(Vsn) -> + MP = if Vsn == v1 -> v1; + Vsn == v2 -> v2c; + Vsn == v3 -> v3 + end, + SM = if Vsn == v1 -> v1; + Vsn == v2 -> v2c; + Vsn == v3 -> usm + end, + ok = io:format(Fid, "{\"target_~w\", ~w, ~w, " + "\"all-rights\", noAuthNoPriv}.~n", + [Vsn, MP, SM]) + end, + Vsns), + file:close(Fid). + +rewrite_target_params_conf(Dir, SecName, SecLevel) -> + ?line ok = file:rename(filename:join(Dir,"target_params.conf"), + filename:join(Dir,"target_params.old")), + ?line {ok, Fid} = file:open(filename:join(Dir,"target_params.conf"),write), + ?line ok = io:format(Fid, "{\"target_v3\", v3, usm, \"~s\", ~w}.~n", + [SecName, SecLevel]), + file:close(Fid). + +reset_target_params_conf(Dir) -> + ?line ok = file:rename(filename:join(Dir,"target_params.old"), + filename:join(Dir,"target_params.conf")). + +write_notify_conf(Dir) -> + {ok, Fid} = file:open(filename:join(Dir,"notify.conf"),write), + ok = io:format(Fid, "{\"standard trap\", \"std_trap\", trap}.~n", []), + ok = io:format(Fid, "{\"standard inform\", \"std_inform\",inform}.~n", []), + file:close(Fid). + +ver_to_trap_str([v1]) -> "v1"; +ver_to_trap_str([v2]) -> "v2"; +% default is to use the latest snmp version +ver_to_trap_str([v1,v2]) -> "v2". + + + +write_view_conf(Dir) -> + {ok, Fid} = file:open(a(Dir,"view.conf"),write), + ok = io:format(Fid, "{2, [1,3,6], included, null}.~n", []), + ok = io:format(Fid, "{2, ~w, excluded, null}.~n", [?tDescr_instance]), + file:close(Fid). + +a(A,B) -> lists:append(A,B). + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +copy_file(From, To) -> + {ok, Bin} = file:read_file(From), + ok = file:write_file(To, Bin). + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +display_memory_usage() -> + Info = snmpa:info(snmp_master_agent), + TreeSize = lists_key1search(tree_size_bytes, Info), + ProcMem = lists_key1search(process_memory, Info), + MibDbSize = lists_key1search([db_memory,mib], Info), + NodeDbSize = lists_key1search([db_memory,node], Info), + TreeDbSize = lists_key1search([db_memory,tree], Info), + ?INF("Memory usage: " + "~n Tree size: ~p" + "~n Process memory size: ~p" + "~n Mib db size: ~p" + "~n Node db size: ~p" + "~n Tree db size: ~p", + [TreeSize, ProcMem, MibDbSize, NodeDbSize, TreeDbSize]). + +lists_key1search([], Res) -> + Res; +lists_key1search([Key|Keys], List) when atom(Key), list(List) -> + case lists:keysearch(Key, 1, List) of + {value, {Key, Val}} -> + lists_key1search(Keys, Val); + false -> + undefined + end; +lists_key1search(Key, List) when atom(Key) -> + case lists:keysearch(Key, 1, List) of + {value, {Key, Val}} -> + Val; + false -> + undefined + end. + + +regs() -> + lists:sort(registered()). diff --git a/lib/snmp/test/exp/snmp_agent_v3_test.erl b/lib/snmp/test/exp/snmp_agent_v3_test.erl new file mode 100644 index 0000000000..266be72878 --- /dev/null +++ b/lib/snmp/test/exp/snmp_agent_v3_test.erl @@ -0,0 +1,5649 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2005-2010. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% + +-module(snmp_agent_v3_test). + +%% TODO +%% * Test fault-tolerance (kill master etc) +%% + +-compile(export_all). + +-define(application, snmp). + +-include_lib("kernel/include/file.hrl"). +-include_lib("test_server/include/test_server.hrl"). +-include("snmp_test_lib.hrl"). +-define(SNMP_USE_V3, true). +-include_lib("snmp/include/snmp_types.hrl"). +%% -include_lib("snmp/include/SNMP-COMMUNITY-MIB.hrl"). +%% -include_lib("snmp/include/SNMP-VIEW-BASED-ACM-MIB.hrl"). +%% -include_lib("snmp/include/SNMP-USER-BASED-SM-MIB.hrl"). + + +-define(klas1, [1,3,6,1,2,1,7]). +-define(klas2, [1,3,6,1,2,1,9]). +-define(klas3, [1,3,6,1,2,1,8,1]). +-define(klas4, [1,3,6,1,2,1,8,4]). +-define(sa, [1,3,6,1,4,1,193,2]). +-define(system, [1,3,6,1,2,1,1]). +-define(snmp, [1,3,6,1,2,1,11]). +-define(snmpTraps, [1,3,6,1,6,3,1,1,5]). +-define(ericsson, [1,3,6,1,4,1,193]). +-define(testTrap, [1,3,6,1,2,1,15,0]). +-define(xDescr, [1,3,6,1,2,1,17,1]). +-define(xDescr2, [1,3,6,1,2,1,17,2]). + +-define(active, 1). +-define(notInService, 2). +-define(notReady, 3). +-define(createAndGo, 4). +-define(createAndWait, 5). +-define(destroy, 6). + +-define(TRAP_UDP, 5000). + +-define(tooBigStr, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"). + +-define(str(X), snmp_pdus:bits_to_str(X)). + +-define(break(), begin io:format(user, "break at line ~w: pid: ~p\n", + [?LINE, self()]), + receive cont -> ok end + end). + + +-import(snmp_test_mgr, [gn/1, g/1, s/1, gb/3]). +-define(v1_2(V1,V2), + case get(vsn) of + v1 -> V1; + _ -> V2 + end). + +-define(v1_2_3(V1,V2,V3), + case get(vsn) of + v1 -> V1; + v2 -> V2; + _ -> V3 + end). + +all() -> +[cases()]. + +groups() -> + [{mib_storage, [], + [{group, mib_storage_ets}, {group, mib_storage_dets}, + {group, mib_storage_mnesia}, + {group, mib_storage_size_check_ets}, + {group, mib_storage_size_check_dets}, + {group, mib_storage_size_check_mnesia}, + {group, mib_storage_varm_dets}, + {group, mib_storage_varm_mnesia}]}, + {mib_storage_ets, [], mib_storage_ets_cases()}, + {mib_storage_dets, [], mib_storage_dets_cases()}, + {mib_storage_mnesia, [], mib_storage_mnesia_cases()}, + {mib_storage_size_check_ets, [], + mse_size_check_cases()}, + {mib_storage_size_check_dets, [], + msd_size_check_cases()}, + {mib_storage_size_check_mnesia, [], + msm_size_check_cases()}, + {mib_storage_varm_dets, [], + varm_mib_storage_dets_cases()}, + {mib_storage_varm_mnesia, [], + varm_mib_storage_mnesia_cases()}, + {test_v1, [], v1_cases()}, {test_v2, [], v2_cases()}, + {test_v1_v2, [], v1_v2_cases()}, + {test_v3, [], v3_cases()}, + {test_multi_threaded, [], mt_cases()}, + {multiple_reqs, [], mul_cases()}, + {multiple_reqs_2, [], mul_cases_2()}, + {v2_inform, [], [v2_inform_i]}, + {v3_security, [], + [v3_crypto_basic, v3_md5_auth, v3_sha_auth, + v3_des_priv]}, + {standard_mibs, [], + [snmp_standard_mib, snmp_community_mib, + snmp_framework_mib, snmp_target_mib, + snmp_notification_mib, snmp_view_based_acm_mib]}, + {standard_mibs_2, [], + [snmpv2_mib_2, snmp_community_mib_2, + snmp_framework_mib_2, snmp_target_mib_2, + snmp_notification_mib_2, snmp_view_based_acm_mib_2]}, + {standard_mibs_3, [], + [snmpv2_mib_3, snmp_framework_mib_3, snmp_mpd_mib_3, + snmp_target_mib_3, snmp_notification_mib_3, + snmp_view_based_acm_mib_3, snmp_user_based_sm_mib_3]}, + {reported_bugs, [], + [otp_1128, otp_1129, otp_1131, otp_1162, otp_1222, + otp_1298, otp_1331, otp_1338, otp_1342, otp_2776, + otp_2979, otp_3187, otp_3725]}, + {reported_bugs_2, [], + [otp_1128_2, otp_1129_2, otp_1131_2, otp_1162_2, + otp_1222_2, otp_1298_2, otp_1331_2, otp_1338_2, + otp_1342_2, otp_2776_2, otp_2979_2, otp_3187_2]}, + {reported_bugs_3, [], + [otp_1128_3, otp_1129_3, otp_1131_3, otp_1162_3, + otp_1222_3, otp_1298_3, otp_1331_3, otp_1338_3, + otp_1342_3, otp_2776_3, otp_2979_3, otp_3187_3, + otp_3542]}, + {tickets, [], [{group, otp_4394}]}, + {otp_4394, [], [otp_4394_test]}]. + +init_per_group(otp_4394, Config) -> + init_otp_4394(Config); +init_per_group(v2_inform, Config) -> + init_v2_inform(Config); +init_per_group(multiple_reqs_2, Config) -> + init_mul(Config); +init_per_group(multiple_reqs, Config) -> + init_mul(Config); +init_per_group(test_multi_threaded, Config) -> + init_mt(Config); +init_per_group(test_v3, Config) -> + init_v3(Config); +init_per_group(test_v1_v2, Config) -> + init_v1_v2(Config); +init_per_group(test_v2, Config) -> + init_v2(Config); +init_per_group(test_v1, Config) -> + init_v1(Config); +init_per_group(mib_storage_varm_mnesia, Config) -> + init_varm_mib_storage_mnesia(Config); +init_per_group(mib_storage_varm_dets, Config) -> + init_varm_mib_storage_dets(Config); +init_per_group(mib_storage_size_check_mnesia, Config) -> + init_size_check_msm(Config); +init_per_group(mib_storage_size_check_dets, Config) -> + init_size_check_msd(Config); +init_per_group(mib_storage_size_check_ets, Config) -> + init_size_check_mse(Config); +init_per_group(mib_storage_mnesia, Config) -> + init_mib_storage_mnesia(Config); +init_per_group(mib_storage_dets, Config) -> + init_mib_storage_dets(Config); +init_per_group(mib_storage_ets, Config) -> + init_mib_storage_ets(Config); +init_per_group(_GroupName, Config) -> + Config. + +end_per_group(otp_4394, Config) -> + finish_otp_4394(Config); +end_per_group(v2_inform, Config) -> + finish_v2_inform(Config); +end_per_group(multiple_reqs_2, Config) -> + finish_mul(Config); +end_per_group(multiple_reqs, Config) -> + finish_mul(Config); +end_per_group(test_multi_threaded, Config) -> + finish_mt(Config); +end_per_group(test_v3, Config) -> + finish_v3(Config); +end_per_group(test_v1_v2, Config) -> + finish_v1_v2(Config); +end_per_group(test_v2, Config) -> + finish_v2(Config); +end_per_group(test_v1, Config) -> + finish_v1(Config); +end_per_group(mib_storage_varm_mnesia, Config) -> + finish_varm_mib_storage_mnesia(Config); +end_per_group(mib_storage_varm_dets, Config) -> + finish_varm_mib_storage_dets(Config); +end_per_group(mib_storage_size_check_mnesia, Config) -> + finish_size_check_msm(Config); +end_per_group(mib_storage_size_check_dets, Config) -> + finish_size_check_msd(Config); +end_per_group(mib_storage_size_check_ets, Config) -> + finish_size_check_mse(Config); +end_per_group(mib_storage_mnesia, Config) -> + finish_mib_storage_mnesia(Config); +end_per_group(mib_storage_dets, Config) -> + finish_mib_storage_dets(Config); +end_per_group(mib_storage_ets, Config) -> + finish_mib_storage_ets(Config); +end_per_group(_GroupName, Config) -> + Config. + + +init_per_testcase(_Case, Config) when list(Config) -> + Dog = ?t:timetrap(?t:minutes(6)), + [{watchdog, Dog}|Config]. + +end_per_testcase(_Case, Config) when list(Config) -> + Dog = ?config(watchdog, Config), + ?t:timetrap_cancel(Dog), + Config. + +cases() -> +case ?OSTYPE() of + vxworks -> + [app_info, {group, test_v1}, {group, test_v2}, + {group, test_v1_v2}, {group, test_multi_threaded}, + {group, mib_storage}, {group, tickets}]; + _Else -> + [app_info, {group, test_v1}, {group, test_v2}, + {group, test_v1_v2}, {group, test_v3}, + {group, test_multi_threaded}, {group, mib_storage}, + {group, tickets}] +end. + + +%%%----------------------------------------------------------------- +%%% The test case structure is as follows: +%%% +%%% init_all - starts mnesia, +%%% +%%% init_v1 - starts agent +%%% simple +%%% big - e.g. starts/stops subagent, load/unloads mibs +%%% init_mul +%%% mul_get +%%% mul_set +%%% +%%% finish_mul +%%% +%%% finish_v1 +%%% +%%% init_v2 - starts agent +%%% finish_v2 +%%% +%%% init_bilingual - starts agent +%%% finish_bilingual +%%% +%%% finish_all +%%% +%%% There is still one problem with these testsuites. If one test +%%% fails, it may not be possible to run some other cases, as it +%%% may have e.g. created some row or loaded some table, that it +%%% didn't undo (since it failed). +%%%----------------------------------------------------------------- + +init_all(Config0) when list(Config0) -> + ?LOG("init_all -> entry with" + "~n Config0: ~p",[Config0]), + + %% -- + %% Fix config: + %% + + DataDir0 = ?config(data_dir, Config0), + DataDir1 = filename:split(filename:absname(DataDir0)), + [_|DataDir2] = lists:reverse(DataDir1), + DataDir3 = filename:join(lists:reverse(DataDir2) ++ [?snmp_test_data]), + Config1 = lists:keydelete(data_dir, 1, Config0), + Config = [{data_dir, DataDir3 ++ "/"}|Config1], + + %% -- + %% Start nodes + %% + + ?line {ok, SaNode} = start_node(snmp_sa), + ?line {ok, MgrNode} = start_node(snmp_mgr), + + + %% -- + %% Create necessary files + %% + + Dir = ?config(priv_dir, Config), + ?DBG("init_all -> Dir ~p", [Dir]), + + DataDir = ?config(data_dir, Config), + ?DBG("init_all -> DataDir ~p", [DataDir]), + + file:make_dir(MgrDir = filename:join(Dir, "mgr_dir/")), + ?DBG("init_all -> MgrDir ~p", [MgrDir]), + + file:make_dir(AgentDir = filename:join(Dir, "agent_dir/")), + ?DBG("init_all -> AgentDir ~p", [AgentDir]), + + file:make_dir(SaDir = filename:join(Dir, "sa_dir/")), + ?DBG("init_all -> SaDir ~p", [SaDir]), + + + %% -- + %% Start and initiate mnesia + %% + + ?DBG("init_all -> load application mnesia", []), + ?line ok = application:load(mnesia), + + ?DBG("init_all -> load application mnesia on node ~p", [SaNode]), + ?line ok = rpc:call(SaNode, application, load, [mnesia]), + + ?DBG("init_all -> application mnesia: set_env dir",[]), + ?line application_controller:set_env(mnesia, dir, + filename:join(Dir, "Mnesia1")), + + ?DBG("init_all -> application mnesia: set_env dir on node ~p",[SaNode]), + ?line rpc:call(SaNode, application_controller, set_env, + [mnesia, dir, filename:join(Dir, "Mnesia2")]), + + ?DBG("init_all -> create mnesia schema",[]), + ?line ok = mnesia:create_schema([SaNode, node()]), + + ?DBG("init_all -> start application mnesia",[]), + ?line ok = application:start(mnesia), + + ?DBG("init_all -> start application mnesia on ~p",[SaNode]), + ?line ok = rpc:call(SaNode, application, start, [mnesia]), + Ip = ?LOCALHOST(), + [{snmp_sa, SaNode}, + {snmp_mgr, MgrNode}, + {agent_dir, AgentDir ++ "/"}, + {mgr_dir, MgrDir ++ "/"}, + {sa_dir, SaDir ++ "/"}, + {mib_dir, DataDir}, + {ip, Ip} | + Config]. + +finish_all(Config) when list(Config) -> + SaNode = ?config(snmp_sa, Config), + MgrNode = ?config(snmp_mgr, Config), + stop_node(SaNode), + stop_node(MgrNode), + application:stop(mnesia). + +start_v1_agent(Config) when list(Config) -> + start_agent(Config, [v1]). + +start_v1_agent(Config,Opts) when list(Config), list(Opts) -> + start_agent(Config, [v1], Opts). + +start_v2_agent(Config) when list(Config) -> + start_agent(Config, [v2]). + +start_v3_agent(Config) when list(Config) -> + start_agent(Config, [v3]). + +start_bilingual_agent(Config) when list(Config) -> + start_agent(Config, [v1,v2]). + +start_multi_threaded_agent(Config) when list(Config) -> + start_agent(Config, [v2], [{snmp_multi_threaded, true}]). + +stop_agent(Config) when list(Config) -> + ?LOG("stop_agent -> entry with" + "~n Config: ~p",[Config]), + + {Sup, Par} = ?config(snmp_sup, Config), + ?DBG("stop_agent -> attempt to stop (sup) ~p" + "~n Sup: ~p" + "~n Par: ~p", + [Sup, + (catch process_info(Sup)), + (catch process_info(Par))]), + stop_sup(Sup, Par), + + {Sup2, Par2} = ?config(snmp_sub, Config), + ?DBG("stop_agent -> attempt to stop (sub) ~p" + "~n Sup2: ~p" + "~n Par2: ~p", + [Sup2, + (catch process_info(Sup2)), + (catch process_info(Par2))]), + stop_sup(Sup2, Par2), + + ?DBG("stop_agent -> done - now cleanup config", []), + C1 = lists:keydelete(snmp_sup, 1, Config), + lists:keydelete(snmp_sub, 1, C1). + + +stop_sup(Pid, _) when node(Pid) == node() -> + case (catch process_info(Pid)) of + PI when list(PI) -> + ?LOG("stop_sup -> attempt to stop ~p", [Pid]), + Ref = erlang:monitor(process, Pid), + exit(Pid, kill), + await_stopped(Pid, Ref); + {'EXIT', _Reason} -> + ?LOG("stop_sup -> ~p not running", [Pid]), + ok + end; +stop_sup(Pid, _) -> + ?LOG("stop_sup -> attempt to stop ~p", [Pid]), + Ref = erlang:monitor(process, Pid), + ?LOG("stop_sup -> Ref: ~p", [Ref]), + %% Pid ! {'EXIT', Parent, shutdown}, % usch + exit(Pid, kill), + await_stopped(Pid, Ref). + +await_stopped(Pid, Ref) -> + receive + {'DOWN', Ref, process, Pid, _Reason} -> + ?DBG("received down message for ~p", [Pid]), + ok + after 10000 -> + ?INF("await_stopped -> timeout for ~p",[Pid]), + erlang:demonitor(Ref), + ?FAIL({failed_stop,Pid}) + end. + + +start_agent(Config, Vsn) -> + start_agent(Config, Vsn, []). +start_agent(Config, Vsn, Opts) -> + ?LOG("start_agent -> entry (~p) with" + "~n Config: ~p" + "~n Vsn: ~p" + "~n Opts: ~p",[node(), Config, Vsn, Opts]), + + ?line AgentDir = ?config(agent_dir, Config), + ?line SaNode = ?config(snmp_sa, Config), + + snmp_app_env_init(vsn_init(Vsn) ++ + [{audit_trail_log, read_write_log}, + {audit_trail_log_dir, AgentDir}, + {audit_trail_log_size, {10240, 10}}, + {force_config_reload, false}, + {snmp_agent_type, master}, + {snmp_config_dir, AgentDir}, + {snmp_db_dir, AgentDir}, + {snmp_local_db_auto_repair, true}, + {snmp_master_agent_verbosity, trace}, + {snmp_supervisor_verbosity, trace}, + {snmp_mibserver_verbosity, trace}, + {snmp_symbolic_store_verbosity, trace}, + {snmp_note_store_verbosity, trace}, + {snmp_net_if_verbosity, trace}], + Opts), + + + process_flag(trap_exit,true), + + {ok, AppSup} = snmp_app_sup:start_link(), + unlink(AppSup), + ?DBG("start_agent -> snmp app supervisor: ~p",[AppSup]), + + ?DBG("start_agent -> start master agent (old style)",[]), + Sup = case (catch snmpa_app:start(normal)) of + {ok, S} -> + ?DBG("start_agent -> started, Sup: ~p",[S]), + S; + + Else -> + ?DBG("start_agent -> unknown result: ~n~p",[Else]), + %% Get info about the apps we depend on + MnesiaInfo = mnesia_running(), + ?FAIL({start_failed,Else,MnesiaInfo}) + end, + + ?DBG("start_agent -> unlink from supervisor",[]), + ?line unlink(Sup), + ?line SaDir = ?config(sa_dir, Config), + ?DBG("start_agent -> (rpc) start sub on ~p",[SaNode]), + ?line {ok, Sub} = rpc:call(SaNode, ?MODULE, start_sub, [SaDir]), + ?DBG("start_agent -> done",[]), + ?line [{snmp_sup, {Sup, self()}}, {snmp_sub, Sub} | Config]. + + +vsn_init(Vsn) -> + vsn_init([v1,v2,v3], Vsn, []). + +vsn_init([], _Vsn, Acc) -> + Acc; +vsn_init([V|Vsns], Vsn, Acc) -> + case lists:member(V, Vsn) of + true -> + vsn_init(Vsns, Vsn, [{V, true}|Acc]); + false -> + vsn_init(Vsns, Vsn, [{V, false}|Acc]) + end. + +snmp_app_env_init(Env0, Opts) -> + ?DBG("snmp_app_env_init -> unload snmp",[]), + ?line application:unload(snmp), + ?DBG("snmp_app_env_init -> load snmp",[]), + ?line application:load(snmp), + ?DBG("snmp_app_env_init -> initiate (snmp) application env",[]), + F1 = fun({Key,Val} = New, Acc0) -> + ?DBG("snmp_app_env_init -> " + "updating setting ~p to ~p", [Key, Val]), + case lists:keyreplace(Key, 1, Acc0, New) of + Acc0 -> + [New|Acc0]; + Acc -> + Acc + end + end, + Env = lists:foldr(F1, Env0, Opts), + ?DBG("snmp_app_env_init -> Env: ~p",[Env]), + F2 = fun({Key,Val}) -> + ?DBG("snmp_app_env_init -> setting ~p to ~p",[Key, Val]), + application_controller:set_env(snmp, Key, Val) + end, + lists:foreach(F2, Env). + + + + +%% Test if application is running +mnesia_running() -> ?IS_MNESIA_RUNNING(). +crypto_running() -> ?IS_CRYPTO_RUNNING(). + + +start_sub(Dir) -> + ?DBG("start_sub -> entry",[]), + Opts = [{db_dir, Dir}, + {supervisor, [{verbosity, trace}]}], + %% BMK BMK +% {ok, P} = snmp_supervisor:start_sub(Dir), + {ok, P} = snmpa_supervisor:start_sub_sup(Opts), + unlink(P), + {ok, {P, self()}}. + +create_tables(SaNode) -> + ?line {atomic, ok} = mnesia:create_table([{name, friendsTable2}, + {ram_copies, [SaNode]}, + {snmp, [{key, integer}]}, + {attributes, [a1,a2,a3]}]), + ?line {atomic, ok} = mnesia:create_table([{name, kompissTable2}, + {ram_copies, [SaNode]}, + {snmp, [{key, integer}]}, + {attributes, [a1,a2,a3]}]), + ?line {atomic, ok} = mnesia:create_table([{name, snmp_variables}, + {attributes, [a1,a2]}]). + +delete_tables() -> + mnesia:delete_table(friendsTable2), + mnesia:delete_table(kompissTable2), + mnesia:delete_table(snmp_variables). + +%% Creation is done in runtime! +delete_mib_storage_mnesia_tables() -> + mnesia:delete_table(snmpa_mib_data), + mnesia:delete_table(snmpa_mib_tree), + mnesia:delete_table(snmpa_symbolic_store). + +%%----------------------------------------------------------------- +%% A test case is always one of: +%% - v1 specific case +%% - v2 specific case +%% - v1 and v2 case +%% All v1 specific cases are prefixed with v1_, and all v2 with +%% v2_. E.g. v1_trap/v2_trap. +%% +%% All other cases are shared. However, the testserver uses the name +%% of the case to generate a file for that case. The same case cannot +%% be used in different configurations in the same suite. Therefore +%% all these functions exists in two variants, the base function +%% , and a second version _2. There may be several +%% versions as well, _N. +%%----------------------------------------------------------------- + + + + + + + + + +mib_storage_ets_cases() -> +[mse_simple, mse_v1_processing, mse_big, mse_big2, + mse_loop_mib, mse_api, mse_sa_register, mse_v1_trap, + mse_sa_error, mse_next_across_sa, mse_undo, + mse_standard_mib, mse_community_mib, mse_framework_mib, + mse_target_mib, mse_notification_mib, + mse_view_based_acm_mib, mse_sparse_table, mse_me_of, + mse_mib_of]. + +mib_storage_dets_cases() -> +[msd_simple, msd_v1_processing, msd_big, msd_big2, + msd_loop_mib, msd_api, msd_sa_register, msd_v1_trap, + msd_sa_error, msd_next_across_sa, msd_undo, + msd_standard_mib, msd_community_mib, msd_framework_mib, + msd_target_mib, msd_notification_mib, + msd_view_based_acm_mib, msd_sparse_table, msd_me_of, + msd_mib_of]. + +mib_storage_mnesia_cases() -> +[msm_simple, msm_v1_processing, msm_big, msm_big2, + msm_loop_mib, msm_api, msm_sa_register, msm_v1_trap, + msm_sa_error, msm_next_across_sa, msm_undo, + msm_standard_mib, msm_community_mib, msm_framework_mib, + msm_target_mib, msm_notification_mib, + msm_view_based_acm_mib, msm_sparse_table, msm_me_of, + msm_mib_of]. + +mse_size_check_cases() -> +[mse_size_check]. + +msd_size_check_cases() -> +[msd_size_check]. + +msm_size_check_cases() -> +[msm_size_check]. + +varm_mib_storage_dets_cases() -> +[msd_varm_mib_start]. + +varm_mib_storage_mnesia_cases() -> +[msm_varm_mib_start]. + +init_mib_storage_ets(Config) when list(Config) -> + ?LOG("init_mib_storage_ets -> entry", []), + MibStorage = {snmp_mib_storage,ets}, + init_ms(Config, [MibStorage]). + +init_mib_storage_dets(Config) when list(Config) -> + ?LOG("init_mib_storage_ets -> entry", []), + ?line AgentDir = ?GCONF(agent_dir, Config), + MibStorage = {snmp_mib_storage,{dets,AgentDir}}, + init_ms(Config, [MibStorage]). + +init_mib_storage_mnesia(Config) when list(Config) -> + ?LOG("init_mib_storage_ets -> entry", []), + MibStorage = {snmp_mib_storage,{mnesia,[]}}, + init_ms(Config, [MibStorage]). + +init_ms(Config, Opts) when list(Config) -> + ?LOG("init_mib_storage_ets -> entry", []), + ?line SaNode = ?GCONF(snmp_sa, Config), + ?line create_tables(SaNode), + ?line AgentDir = ?GCONF(agent_dir, Config), + ?line MgrDir = ?GCONF(mgr_dir, Config), + ?line Ip = ?GCONF(ip, Config), + ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, + MibsVerbosity = {snmp_mibserver_verbosity, trace}, + SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, + Opts1 = [MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity|Opts], + [{vsn, v1} | start_v1_agent(Config,Opts1)]. + +init_size_check_mse(Config) when list(Config) -> + MibStorage = {snmp_mib_storage, ets}, + init_size_check_ms(Config, [MibStorage]). + +init_size_check_msd(Config) when list(Config) -> + AgentDir = ?GCONF(agent_dir, Config), + MibStorage = {snmp_mib_storage, {dets, AgentDir}}, + init_size_check_ms(Config, [MibStorage]). + +init_size_check_msm(Config) when list(Config) -> + MibStorage = {snmp_mib_storage, {mnesia,[]}}, + init_size_check_ms(Config, [MibStorage]). + +init_size_check_ms(Config, Opts) when list(Config) -> + SaNode = ?GCONF(snmp_sa, Config), + %% We are using v3 here, so crypto must be supported or else... + case ?CRYPTO_START() of + ok -> + case ?CRYPTO_SUPPORT() of + {no, Reason} -> + ?SKIP({unsupported_encryption, Reason}); + yes -> + ok + end; + {error, Reason} -> + ?SKIP({failed_starting_crypto, Reason}) + end, + create_tables(SaNode), + AgentDir = ?GCONF(agent_dir, Config), + MgrDir = ?GCONF(mgr_dir, Config), + Ip = ?GCONF(ip, Config), + ?line ok = + config([v3], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v3} | start_agent(Config, [v3], Opts)]. + +init_varm_mib_storage_dets(Config) when list(Config) -> + ?LOG("init_varm_mib_storage_dets -> entry", []), + ?line SaNode = ?GCONF(snmp_sa, Config), + ?line create_tables(SaNode), + ?line AgentDir = ?GCONF(agent_dir, Config), + ?line MgrDir = ?GCONF(mgr_dir, Config), + ?line Ip = ?GCONF(ip, Config), + ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + MibStorage = {snmp_mib_storage,{dets,AgentDir}}, + MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, + MibsVerbosity = {snmp_mibserver_verbosity, trace}, + SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, + Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity], + [{vsn, v1}, {agent_opts,Opts} | Config]. + +init_varm_mib_storage_mnesia(Config) when list(Config) -> + ?LOG("init_varm_mib_storage_mnesia -> entry", []), + ?line SaNode = ?GCONF(snmp_sa, Config), + ?line create_tables(SaNode), + ?line AgentDir = ?GCONF(agent_dir, Config), + ?line MgrDir = ?GCONF(mgr_dir, Config), + ?line Ip = ?GCONF(ip, Config), + ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + MibStorage = {snmp_mib_storage,{mnesia,[]}}, + MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, + MibsVerbosity = {snmp_mibserver_verbosity, trace}, + SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, + Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity], + [{vsn, v1}, {agent_opts,Opts} | Config]. + +finish_mib_storage_ets(Config) when list(Config) -> + ?LOG("finish_mib_storage_ets -> entry", []), + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + C2 = lists:keydelete(vsn, 1, C1), + lists:keydelete(agent_opts, 1, C2). + +finish_mib_storage_dets(Config) when list(Config) -> + ?LOG("finish_mib_storage_dets -> entry", []), + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + C2 = lists:keydelete(vsn, 1, C1), + lists:keydelete(agent_opts, 1, C2). + +finish_mib_storage_mnesia(Config) when list(Config) -> + ?LOG("finish_mib_storage_mnesia -> entry", []), + delete_tables(), + delete_mib_storage_mnesia_tables(), + C1 = stop_agent(Config), + delete_files(C1), + C2 = lists:keydelete(vsn, 1, C1), + lists:keydelete(agent_opts, 1, C2). + +finish_varm_mib_storage_dets(Config) when list(Config) -> + ?LOG("finish_varm_mib_storage_dets -> entry", []), + delete_tables(), + %% C1 = stop_agent(Config), % In case something went wrong... + delete_files(Config), + C2 = lists:keydelete(vsn, 1, Config), + lists:keydelete(agent_opts, 1, C2). + +finish_varm_mib_storage_mnesia(Config) when list(Config) -> + ?LOG("finish_varm_mib_storage_mnesia -> entry", []), + delete_tables(), + delete_mib_storage_mnesia_tables(), + %% C1 = stop_agent(Config), % In case something went wrong... + delete_files(Config), + C2 = lists:keydelete(vsn, 1, Config), + lists:keydelete(agent_opts, 1, C2). + +finish_size_check_mse(Config) when list(Config) -> + finish_size_check_ms(Config). + +finish_size_check_msd(Config) when list(Config) -> + finish_size_check_ms(Config). + +finish_size_check_msm(Config) when list(Config) -> + finish_size_check_ms(Config). + +finish_size_check_ms(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + + +%% These are just interface functions to fool the test server +mse_simple(X) -> simple(X). +mse_v1_processing(X) -> v1_processing(X). +mse_big(X) -> big(X). +mse_big2(X) -> big2(X). +mse_loop_mib(X) -> loop_mib(X). +mse_api(X) -> api(X). +mse_sa_register(X) -> sa_register(X). +mse_v1_trap(X) -> v1_trap(X). +mse_sa_error(X) -> sa_error(X). +mse_next_across_sa(X) -> next_across_sa(X). +mse_undo(X) -> undo(X). +mse_standard_mib(X) -> snmp_standard_mib(X). +mse_community_mib(X) -> snmp_community_mib(X). +mse_framework_mib(X) -> snmp_framework_mib(X). +mse_target_mib(X) -> snmp_target_mib(X). +mse_notification_mib(X) -> snmp_notification_mib(X). +mse_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). +mse_sparse_table(X) -> sparse_table(X). +mse_me_of(X) -> ms_me_of(X). +mse_mib_of(X) -> ms_mib_of(X). + +msd_simple(X) -> simple(X). +msd_v1_processing(X) -> v1_processing(X). +msd_big(X) -> big(X). +msd_big2(X) -> big2(X). +msd_loop_mib(X) -> loop_mib(X). +msd_api(X) -> api(X). +msd_sa_register(X) -> sa_register(X). +msd_v1_trap(X) -> v1_trap(X). +msd_sa_error(X) -> sa_error(X). +msd_next_across_sa(X) -> next_across_sa(X). +msd_undo(X) -> undo(X). +msd_standard_mib(X) -> snmp_standard_mib(X). +msd_community_mib(X) -> snmp_community_mib(X). +msd_framework_mib(X) -> snmp_framework_mib(X). +msd_target_mib(X) -> snmp_target_mib(X). +msd_notification_mib(X) -> snmp_notification_mib(X). +msd_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). +msd_sparse_table(X) -> sparse_table(X). +msd_me_of(X) -> ms_me_of(X). +msd_mib_of(X) -> ms_mib_of(X). + +msm_simple(X) -> simple(X). +msm_v1_processing(X) -> v1_processing(X). +msm_big(X) -> big(X). +msm_big2(X) -> big2(X). +msm_loop_mib(X) -> loop_mib(X). +msm_api(X) -> api(X). +msm_sa_register(X) -> sa_register(X). +msm_v1_trap(X) -> v1_trap(X). +msm_sa_error(X) -> sa_error(X). +msm_next_across_sa(X) -> next_across_sa(X). +msm_undo(X) -> undo(X). +msm_standard_mib(X) -> snmp_standard_mib(X). +msm_community_mib(X) -> snmp_community_mib(X). +msm_framework_mib(X) -> snmp_framework_mib(X). +msm_target_mib(X) -> snmp_target_mib(X). +msm_notification_mib(X) -> snmp_notification_mib(X). +msm_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). +msm_sparse_table(X) -> sparse_table(X). +msm_me_of(X) -> ms_me_of(X). +msm_mib_of(X) -> ms_mib_of(X). + + +mse_size_check(X) -> p("mse_size_check..."), ms_size_check(X). +msd_size_check(X) -> p("msd_size_check..."), ms_size_check(X). +msm_size_check(X) -> p("msm_size_check..."), ms_size_check(X). + +msd_varm_mib_start(X) -> p("msd_varm_mib_start..."), varm_mib_start(X). +msm_varm_mib_start(X) -> p("msm_varm_mib_start..."), varm_mib_start(X). + +ms_size_check(suite) -> []; +ms_size_check(Config) when list(Config) -> + p("ms_size_check..."), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?LOG("mib server size check...", []), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + ?line load_master_std("OTP-SNMPEA-MIB"), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-MPD-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-USER-BASED-SM-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + ?line load_master_std("SNMPv2-MIB"), + ?line load_master_std("SNMPv2-TM"), + + ?SLEEP(2000), + + ?line display_memory_usage(), + + ?line unload_master("OTP-SNMPEA-MIB"), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?line unload_master("SNMP-MPD-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-USER-BASED-SM-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + ?line unload_master("SNMPv2-MIB"), + ?line unload_master("SNMPv2-TM"), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + + ok. + + +varm_mib_start(suite) -> []; +varm_mib_start(Config) when list(Config) -> + p("varm_mib_start..."), + ?LOG("varm_mib_start -> entry", []), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + %% Start the agent + Opts = ?GCONF(agent_opts, Config), + Config1 = start_v1_agent(Config, Opts), + + %% Sleep some in order for the agent to start properly + ?DBG("varm_mib_start -> sleep some (before loading mobs)", []), + ?SLEEP(5000), + + %% Load all the mibs + HardwiredMibs = loaded_mibs(), + ?DBG("varm_mib_start -> load all mibs", []), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + + %% Unload the hardwired mibs + ?DBG("varm_mib_start -> sleep some (before unloading hardwired mibs)", []), + ?SLEEP(1000), + ?DBG("varm_mib_start -> unload (hardwired) mibs", []), + ?line unload_mibs(HardwiredMibs), %% unload hardwired + + ?DBG("varm_mib_start -> sleep some (before stopping agent)", []), + ?SLEEP(1000), + + %% Stop the agent (without deleting the stored files) + ?DBG("varm_mib_start -> stop the agent", []), + Config2 = stop_agent(Config1), + + %% Sleep some in order for the agent to stop properly + ?DBG("varm_mib_start -> sleep some (before re-starting the agent)", []), + ?SLEEP(5000), + + %% Start the agent (again) + ?DBG("varm_mib_start -> start the agent", []), + Config3 = start_v1_agent(Config2, Opts), + + ?DBG("varm_mib_start -> sleep some (before starting tests)", []), + ?SLEEP(5000), + + %% Perform the test(s) + ?DBG("varm_mib_start -> perform the tests", []), + try_test(snmp_community_mib), + try_test(snmp_framework_mib), + try_test(snmp_target_mib), + try_test(snmp_notification_mib), + + %% Stop the agent (without deleting the stored files) + ?DBG("varm_mib_start -> stop the agent", []), + stop_agent(Config3), + ok. + + +-define(snmpTrapCommunity_instance, [1,3,6,1,6,3,18,1,4,0]). +-define(vacmViewSpinLock_instance, [1,3,6,1,6,3,16,1,5,1,0]). +-define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). + +ms_me_of(suite) -> []; +ms_me_of(Config) when list(Config) -> + p("ms_me_of..."), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + ?line load_master_std("OTP-SNMPEA-MIB"), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-MPD-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + + ?SLEEP(2000), + + ?line display_memory_usage(), + + + ?DBG("ms_me_of -> find ~w from SNMP-COMMUNITY-MIB", + [?snmpTrapCommunity_instance]), + ?line ok = me_of(?snmpTrapCommunity_instance), + + ?DBG("ms_me_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", + [?vacmViewSpinLock_instance]), + ?line ok = me_of(?vacmViewSpinLock_instance), + + ?DBG("ms_me_of -> find ~w from SNMP-USER-BASED-SM-MIB", + [?usmStatsNotInTimeWindows_instance]), + ?line {error, _} = me_of(?usmStatsNotInTimeWindows_instance), + + + ?line unload_master("OTP-SNMPEA-MIB"), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?line unload_master("SNMP-MPD-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + + ok. + +me_of(Oid) -> + case snmpa:me_of(Oid) of + {ok, #me{oid = Oid}} -> + ok; + {ok, #me{oid = OtherOid}} -> + case lists:reverse(Oid) of + [0|Rest] -> + case lists:reverse(Rest) of + OtherOid -> + ok; + AnotherOid -> + {error, {invalid_oid, Oid, AnotherOid}} + end; + _ -> + {error, {invalid_oid, Oid, OtherOid}} + end; + {error, Reason} -> + {error, Reason}; + Else -> + {error, Else} + end. + + +ms_mib_of(suite) -> []; +ms_mib_of(Config) when list(Config) -> + p("ms_mib_of..."), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + ?line load_master_std("OTP-SNMPEA-MIB"), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-MPD-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + + ?SLEEP(2000), + + ?line display_memory_usage(), + + + ?DBG("ms_mib_of -> find ~w from SNMP-COMMUNITY-MIB", + [?snmpTrapCommunity_instance]), + ?line ok = mib_of(?snmpTrapCommunity_instance, 'SNMP-COMMUNITY-MIB'), + + ?DBG("ms_mib_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", + [?vacmViewSpinLock_instance]), + ?line ok = mib_of(?vacmViewSpinLock_instance, 'SNMP-VIEW-BASED-ACM-MIB'), + + ?DBG("ms_mib_of -> find ~w from SNMP-USER-BASED-SM-MIB", + [?usmStatsNotInTimeWindows_instance]), + ?line {error, _} = mib_of(?usmStatsNotInTimeWindows_instance, + 'SNMP-USER-BASED-SM-MIB'), + + + ?line unload_master("OTP-SNMPEA-MIB"), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?line unload_master("SNMP-MPD-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + + ok. + +mib_of(Oid, ExpectedMibName) -> + ?DBG("mib_of -> entry with" + "~n Oid: ~p" + "~n ExpectedMibName: ~p", [Oid, ExpectedMibName]), + %% case snmpa:mib_of(Oid) of + MibOf = snmpa:mib_of(Oid), + ?DBG("mib_of -> MibOf: ~n~p", [MibOf]), + case MibOf of + {ok, ExpectedMibName} -> + ok; + {ok, OtherMibName} -> + {error, {invalid_mib, ExpectedMibName, OtherMibName}}; + {error, Reason} -> + {error, Reason}; + Else -> + ?DBG("mib_of -> Else: ~n~p", [Else]), + {error, Else} + end. + + +app_info(suite) -> []; +app_info(Config) when list(Config) -> + SnmpDir = app_dir(snmp), + SslDir = app_dir(ssl), + CryptoDir = app_dir(crypto), + Attr = snmp:module_info(attributes), + AppVsn = + case lists:keysearch(app_vsn, 1, Attr) of + {value, {app_vsn, V}} -> + V; + false -> + "undefined" + end, + io:format("Root dir: ~s~n" + "SNMP: Application dir: ~s~n" + " Application ver: ~s~n" + "SSL: Application dir: ~s~n" + "CRYPTO: Application dir: ~s~n", + [code:root_dir(), SnmpDir, AppVsn, SslDir, CryptoDir]), + ok. + +app_dir(App) -> + case code:lib_dir(App) of + D when list(D) -> + filename:basename(D); + {error, _Reason} -> + "undefined" + end. + + + +%v1_cases() -> [loop_mib]; +v1_cases() -> +[simple, db_notify_client, v1_processing, big, big2, + loop_mib, api, subagent, mnesia, {group, multiple_reqs}, + sa_register, v1_trap, sa_error, next_across_sa, undo, + {group, reported_bugs}, {group, standard_mibs}, + sparse_table, cnt_64, opaque, change_target_addr_config]. + +init_v1(Config) when list(Config) -> + ?line SaNode = ?config(snmp_sa, Config), + ?line create_tables(SaNode), + ?line AgentDir = ?config(agent_dir, Config), + ?line MgrDir = ?config(mgr_dir, Config), + ?line Ip = ?config(ip, Config), + ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v1} | start_v1_agent(Config)]. + +finish_v1(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + + +%v2_cases() -> [loop_mib_2]; +v2_cases() -> +[simple_2, v2_processing, big_2, big2_2, loop_mib_2, + api_2, subagent_2, mnesia_2, {group, multiple_reqs_2}, + sa_register_2, v2_trap, {group, v2_inform}, sa_error_2, + next_across_sa_2, undo_2, {group, reported_bugs_2}, + {group, standard_mibs_2}, v2_types, implied, + sparse_table_2, cnt_64_2, opaque_2, v2_caps]. + +init_v2(Config) when list(Config) -> + SaNode = ?config(snmp_sa, Config), + create_tables(SaNode), + AgentDir = ?config(agent_dir, Config), + MgrDir = ?config(mgr_dir, Config), + Ip = ?config(ip, Config), + config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v2} | start_v2_agent(Config)]. + +finish_v2(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + + +v1_v2_cases() -> +[simple_bi]. + +init_v1_v2(Config) when list(Config) -> + SaNode = ?config(snmp_sa, Config), + create_tables(SaNode), + AgentDir = ?config(agent_dir, Config), + MgrDir = ?config(mgr_dir, Config), + Ip = ?config(ip, Config), + config([v1,v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, bilingual} | start_bilingual_agent(Config)]. + +finish_v1_v2(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + + +%v3_cases() -> [loop_mib_3]; +v3_cases() -> +[simple_3, v3_processing, big_3, big2_3, api_3, + subagent_3, mnesia_3, loop_mib_3, multiple_reqs_3, + sa_register_3, v3_trap, v3_inform, sa_error_3, + next_across_sa_3, undo_3, {group, reported_bugs_3}, + {group, standard_mibs_3}, {group, v3_security}, + v2_types_3, implied_3, sparse_table_3, cnt_64_3, + opaque_3, v2_caps_3]. + +init_v3(Config) when list(Config) -> + %% Make sure crypto works, otherwise start_agent will fail + %% and we will be stuck with a bunch of mnesia tables for + %% the rest of this suite... + ?DBG("start_agent -> start crypto app",[]), + case os:type() of + vxworks -> + no_crypto; + _ -> + case ?CRYPTO_START() of + ok -> + case ?CRYPTO_SUPPORT() of + {no, Reason} -> + ?SKIP({unsupported_encryption, Reason}); + yes -> + ok + end; + {error, Reason} -> + ?SKIP({failed_starting_crypto, Reason}) + end + end, + SaNode = ?config(snmp_sa, Config), + create_tables(SaNode), + AgentDir = ?config(agent_dir, Config), + MgrDir = ?config(mgr_dir, Config), + Ip = ?config(ip, Config), + ?line ok = config([v3], MgrDir, AgentDir, + tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v3} | start_v3_agent(Config)]. + +finish_v3(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + + +mt_cases() -> +[multi_threaded, mt_trap]. + +init_mt(Config) when list(Config) -> + SaNode = ?config(snmp_sa, Config), + create_tables(SaNode), + AgentDir = ?config(agent_dir, Config), + MgrDir = ?config(mgr_dir, Config), + Ip = ?config(ip, Config), + ?line ok = config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + [{vsn, v2} | start_multi_threaded_agent(Config)]. + +finish_mt(Config) when list(Config) -> + delete_tables(), + C1 = stop_agent(Config), + delete_files(C1), + lists:keydelete(vsn, 1, C1). + +%% This one *must* be run first in each case. +init_case(Config) when list(Config) -> + ?DBG("init_case -> entry with" + "~n Config: ~p", [Config]), + SaNode = ?config(snmp_sa, Config), + MgrNode = ?config(snmp_mgr, Config), + MasterNode = node(), + + SaHost = ?HOSTNAME(SaNode), + MgrHost = ?HOSTNAME(MgrNode), + MasterHost = ?HOSTNAME(MasterNode), + {ok, MasterIP} = snmp_misc:ip(MasterHost), + {ok, MIP} = snmp_misc:ip(MgrHost), + {ok, SIP} = snmp_misc:ip(SaHost), + + + put(mgr_node, MgrNode), + put(sa_node, SaNode), + put(master_node, MasterNode), + put(sa_host, SaHost), + put(mgr_host, MgrHost), + put(master_host, MasterHost), + put(mip, tuple_to_list(MIP)), + put(masterip , tuple_to_list(MasterIP)), + put(sip, tuple_to_list(SIP)), + + MibDir = ?config(mib_dir, Config), + put(mib_dir, MibDir), + StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", + put(std_mib_dir, StdM), + + MgrDir = ?config(mgr_dir, Config), + put(mgr_dir, MgrDir), + + put(vsn, ?config(vsn, Config)), + ?DBG("init_case -> exit with" + "~n MasterNode: ~p" + "~n SaNode: ~p" + "~n MgrNode: ~p" + "~n MibDir: ~p", [MasterNode, SaNode, MgrNode, MibDir]), + {SaNode, MgrNode, MibDir}. + +load_master(Mib) -> + ?DBG("load_master -> entry with" + "~n Mib: ~p", [Mib]), + snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety + ok = snmpa:load_mibs(snmp_master_agent, [get(mib_dir) ++ Mib]). + +load_master_std(Mib) -> + ?DBG("load_master_std -> entry with" + "~n Mib: ~p", [Mib]), + snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety + ok = snmpa:load_mibs(snmp_master_agent, [get(std_mib_dir) ++ Mib]). + +unload_master(Mib) -> + ?DBG("unload_master -> entry with" + "~n Mib: ~p", [Mib]), + ok = snmpa:unload_mibs(snmp_master_agent, [Mib]). + +loaded_mibs() -> + ?DBG("loaded_mibs -> entry",[]), + Info = snmpa:info(snmp_master_agent), + {value, {loaded_mibs, Mibs}} = lists:keysearch(loaded_mibs, 1, Info), + [atom_to_list(Mib) || {Mib,_,_} <- Mibs]. + +unload_mibs(Mibs) -> + ?DBG("unload_mibs -> entry with" + "~n Mibs: ~p", [Mibs]), + ok = snmpa:unload_mibs(snmp_master_agent, Mibs). + +start_subagent(SaNode, RegTree, Mib) -> + ?DBG("start_subagent -> entry with" + "~n SaNode: ~p" + "~n RegTree: ~p" + "~n Mib: ~p", [SaNode, RegTree, Mib]), + MA = whereis(snmp_master_agent), + ?DBG("start_subagent -> MA: ~p", [MA]), + MibDir = get(mib_dir), + Mib1 = join(MibDir,Mib), + %% BMK BMK +% case rpc:call(SaNode,snmp_supervisor,start_subagent,[MA,RegTree,[Mib1]]) of + case rpc:call(SaNode, snmpa_supervisor, + start_sub_agent, [MA, RegTree, [Mib1]]) of + {ok, SA} -> + ?DBG("start_subagent -> SA: ~p", [SA]), + {ok, SA}; + Error -> + ?FAIL({subagent_start_failed, SaNode, Error, [MA, RegTree, Mib1]}) + end. + +stop_subagent(SA) -> + ?DBG("stop_subagent -> entry with" + "~n SA: ~p", [SA]), + %% BNK BMK + %% rpc:call(node(SA), snmp_supervisor, stop_subagent, [SA]). + rpc:call(node(SA), snmpa_supervisor, stop_sub_agent, [SA]). + +%%----------------------------------------------------------------- +%% This function takes care of the old OTP-SNMPEA-MIB. +%% Unfortunately, the testcases were written to use the data in the +%% internal tables, and these table are now obsolete and not used +%% by the agent. Therefore, we emulate them by using +%% OLD-SNMPEA-MIB, which uses the default impl. of all tables. +%% +%% These two rows must exist in intCommunityTable +%% {[147,214,36,45], "public", 2, readWrite}. +%% {[147,214,36,45], "standard trap", 2, read}. +%% (But with the manager's IP address) +%% +%%----------------------------------------------------------------- +init_old() -> + snmpa_local_db:table_create_row(intCommunityTable, + get(mip) ++ [6 | "public"], + {get(mip), "public", 2, 2}), + snmpa_local_db:table_create_row(intCommunityTable, + get(mip) ++ [13 | "standard trap"], + {get(mip), "standard trap", 2, 1}), + snmpa_local_db:variable_set(intAgentIpAddress, [127,0,0,1]). + + + +simple(suite) -> []; +simple(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + try_test(simple_standard_test). + +simple_2(X) -> simple(X). + +simple_bi(suite) -> []; +simple_bi(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + put(vsn, v1), % First, try v1 manager + try_test(simple_standard_test), + + put(vsn, v2), % Then, try v2 manager + try_test(simple_standard_test). + +simple_3(X) -> + simple(X). + +big(suite) -> []; +big(Config) when list(Config) -> + ?DBG("big -> entry", []), + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Starting subagent..."), + ?line pong = net_adm:ping(SaNode), + + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), + ?DBG("big -> SA: ~p", [SA]), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(big_test), + ?line stop_subagent(SA), + ?line unload_master("OLD-SNMPEA-MIB"). + +big_2(X) -> big(X). + +big_3(X) -> big(X). + + +big2(suite) -> []; +big2(Config) when list(Config) -> + %% This is exactly the same tests as 'big', but with the + %% v2 equivalent of the mibs. + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Starting subagent..."), + ?line pong = net_adm:ping(SaNode), + + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1-v2"), + ?line load_master("OLD-SNMPEA-MIB-v2"), + ?line init_old(), + try_test(big_test), + ?line stop_subagent(SA), + ?line unload_master("OLD-SNMPEA-MIB-v2"). + +big2_2(X) -> big2(X). + +big2_3(X) -> big2(X). + + +multi_threaded(suite) -> []; +multi_threaded(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test1"), + try_test(multi_threaded_test), + ?line unload_master("Test1"). + +mt_trap(suite) -> []; +mt_trap(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line load_master("Test1"), + ?line load_master("TestTrapv2"), + try_test(mt_trap_test, [MA]), + ?line unload_master("TestTrapv2"), + ?line unload_master("Test1"). + +v2_types(suite) -> []; +v2_types(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test1"), + try_test(types_v2_test), + ?line unload_master("Test1"). + +v2_types_3(X) -> v2_types(X). + + +implied(suite) -> []; +implied(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line load_master("Test1"), + try_test(implied_test,[MA]), + ?line unload_master("Test1"). + +implied_3(X) -> implied(X). + + +sparse_table(suite) -> []; +sparse_table(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test1"), + try_test(sparse_table_test), + ?line unload_master("Test1"). + +sparse_table_2(X) -> sparse_table(X). + +sparse_table_3(X) -> sparse_table(X). + +cnt_64(suite) -> []; +cnt_64(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line load_master("Test1"), + try_test(cnt_64_test, [MA]), + ?line unload_master("Test1"). + +cnt_64_2(X) -> cnt_64(X). + +cnt_64_3(X) -> cnt_64(X). + +opaque(suite) -> []; +opaque(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test1"), + try_test(opaque_test), + ?line unload_master("Test1"). + +opaque_2(X) -> opaque(X). + +opaque_3(X) -> opaque(X). + + +change_target_addr_config(suite) -> []; +change_target_addr_config(Config) when list(Config) -> + p("Testing changing target address config..."), + ?LOG("change_target_addr_config -> entry",[]), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + put(sname,snmp_suite), + put(verbosity,trace), + + MA = whereis(snmp_master_agent), + + ?LOG("change_target_addr_config -> load TestTrap",[]), + ?line load_master("TestTrap"), + + ?LOG("change_target_addr_config -> set trace verbosity for local_db",[]), + ?line snmpa:verbosity(local_db,trace), + + %% First send some traps that will arive att the original manager + ?LOG("change_target_addr_config -> send trap",[]), + try_test(ma_trap1, [MA]), + + ?LOG("change_target_addr_config -> set silence verbosity for local_db",[]), + ?line snmpa:verbosity(local_db,silence), + + %% Start new dummy listener + ?LOG("change_target_addr_config -> start dummy manager",[]), + ?line {ok,Pid,NewPort} = dummy_manager_start(MA), + + %% Reconfigure + ?LOG("change_target_addr_config -> reconfigure",[]), + AgentDir = ?config(agent_dir, Config), + ?line rewrite_target_addr_conf(AgentDir, NewPort), + ?line snmp_target_mib:reconfigure(AgentDir), + + %% Send the trap again + ?LOG("change_target_addr_config -> send trap again",[]), + catch dummy_manager_send_trap2(Pid), + + ?LOG("change_target_addr_config -> await trap ack",[]), + catch dummy_manager_await_trap2_ack(), + + ?LOG("change_target_addr_config -> stop dummy manager",[]), + ?line ok = dummy_manager_stop(Pid), + + ?LOG("change_target_addr_config -> reset target address config",[]), + ?line reset_target_addr_conf(AgentDir), + + ?LOG("change_target_addr_config -> unload TestTrap",[]), + ?line unload_master("TestTrap"). + + +dummy_manager_start(MA) -> + ?DBG("dummy_manager_start -> entry",[]), + Pid = spawn(get(mgr_node), ?MODULE,dummy_manager_init,[self(),MA]), + ?DBG("dummy_manager_start -> Pid: ~p",[Pid]), + await_dummy_manager_started(Pid). + +await_dummy_manager_started(Pid) -> + receive + {dummy_manager_started,Pid,Port} -> + ?DBG("dummy_manager_start -> acknowledge received with" + "~n Port: ~p",[Port]), + {ok,Pid,Port}; + {'EXIT', Pid, Reason} -> + {error, Pid, Reason}; + O -> + ?LOG("dummy_manager_start -> received unknown message:" + "~n ~p",[O]), + await_dummy_manager_started(Pid) + end. + +dummy_manager_stop(Pid) -> + ?DBG("dummy_manager_stop -> entry with Pid: ~p",[Pid]), + Pid ! stop, + receive + {dummy_manager_stopping, Pid} -> + ?DBG("dummy_manager_stop -> acknowledge received",[]), + ok + after 10000 -> + ?ERR("dummy_manager_stop -> timeout",[]), + timeout + end. + +dummy_manager_send_trap2(Pid) -> + ?DBG("dummy_manager_send_trap2 -> entry",[]), + Pid ! {send_trap,testTrap2}. + +dummy_manager_await_trap2_ack() -> + ?DBG("dummy_manager_await_trap2 -> entry",[]), + receive + {received_trap,Trap} -> + ?LOG("dummy_manager_await_trap2 -> received trap: ~p",[Trap]), + %% Note: + %% Without this sleep the v2_inform_i testcase failes! There + %% is no relation between these two test cases as far as I + %% able to figure out... + sleep(60000), + ok; + O -> + ?ERR("dummy_manager_await_trap2 -> unexpected message: ~p",[O]), + ok + after 10000 -> + ?ERR("dummy_manager_await_trap2 -> timeout",[]), + timeout + end. + +dummy_manager_init(Parent,MA) -> + ?DBG("dummy_manager_init -> entry with" + "~n Parent: ~p" + "~n MA: ~p",[Parent,MA]), + {ok,S} = gen_udp:open(0,[{recbuf,65535}]), + ?DBG("dummy_manager_init -> S: ~p",[S]), + {ok,Port} = inet:port(S), + ?DBG("dummy_manager_init -> Port: ~p",[Port]), + Parent ! {dummy_manager_started,self(),Port}, + dummy_manager_loop(Parent,S,MA). + +dummy_manager_loop(P,S,MA) -> + ?LOG("dummy_manager_loop -> ready for receive",[]), + receive + {send_trap,Trap} -> + ?LOG("dummy_manager_loop -> received trap send request" + "~n Trap: ~p",[Trap]), + snmpa:send_trap(MA, Trap, "standard trap"), + dummy_manager_loop(P,S,MA); + {udp, _UdpId, Ip, UdpPort, Bytes} -> + ?LOG("dummy_manager_loop -> received upd message" + "~n from: ~p:~p" + "~n size: ~p", + [Ip, UdpPort, dummy_manager_message_sz(Bytes)]), + R = dummy_manager_handle_message(Bytes), + ?DBG("dummy_manager_loop -> R: ~p",[R]), + P ! R, + dummy_manager_loop(P,S,MA); + stop -> + ?DBG("dummy_manager_loop -> received stop request",[]), + P ! {dummy_manager_stopping, self()}, + gen_udp:close(S), + exit(normal); + O -> + ?LOG("dummy_manager_loop -> received unknown message:" + "~n ~p",[O]), + dummy_manager_loop(P,S,MA) + end. + +dummy_manager_message_sz(B) when binary(B) -> + size(B); +dummy_manager_message_sz(L) when list(L) -> + length(L); +dummy_manager_message_sz(_) -> + undefined. + +dummy_manager_handle_message(Bytes) -> + case (catch snmp_pdus:dec_message(Bytes)) of + {'EXIT',Reason} -> + ?ERR("dummy_manager_handle_message -> " + "failed decoding message only:~n ~p",[Reason]), + {error,Reason}; + M -> + ?DBG("dummy_manager_handle_message -> decoded message:" + "~n ~p",[M]), + {received_trap,M} + end. + + +api(suite) -> []; +api(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(api_test, [node()]), + ?line unload_master("OLD-SNMPEA-MIB"). + +api_2(X) -> api(X). + +api_3(X) -> api(X). + + +subagent(suite) -> []; +subagent(Config) when list(Config) -> + {SaNode, _MgrNode, MibDir} = init_case(Config), + + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), + try_test(load_test_sa), + + p("Testing unregister subagent..."), + MA = whereis(snmp_master_agent), + rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), + try_test(unreg_test), + + p("Loading previous subagent mib in master and testing..."), + ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas1"]), + try_test(load_test), + + p("Unloading previous subagent mib in master and testing..."), + ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas1"]), + try_test(unreg_test), + p("Testing register subagent..."), + rpc:call(SaNode, snmp, register_subagent, + [MA, ?klas1, SA]), + try_test(load_test_sa), + + ?line stop_subagent(SA), + try_test(unreg_test). + +subagent_2(X) -> subagent(X). + +subagent_3(X) -> subagent(X). + + +mnesia(suite) -> []; +mnesia(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Starting subagent with mnesia impl..."), + {ok, SA} = start_subagent(SaNode, ?klas2, "Klas2"), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + + try_test(big_test_2), + + p("Testing unregister subagent..."), + MA = whereis(snmp_master_agent), + rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), + try_test(unreg_test), + ?line unload_master("OLD-SNMPEA-MIB"), + ?line stop_subagent(SA). + +mnesia_2(X) -> mnesia(X). + +mnesia_3(X) -> mnesia(X). + + + +mul_cases() -> +[mul_get, mul_get_err, mul_next, mul_next_err, + mul_set_err]. + + +multiple_reqs_3(_X) -> + {req, [], {conf, init_mul, mul_cases_3(), finish_mul}}. + + +mul_cases_2() -> +[mul_get_2, mul_get_err_2, mul_next_2, mul_next_err_2, + mul_set_err_2]. + + +mul_cases_3() -> + [mul_get_3, mul_get_err_3, mul_next_3, mul_next_err_3, mul_set_err_3]. + + +init_mul(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + [{mul_sub, SA} | Config]. + +finish_mul(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + SA = ?config(mul_sub, Config), + + ?line unload_master("OLD-SNMPEA-MIB"), + ?line stop_subagent(SA), + lists:keydelete(mul_sub, 1, Config). + +mul_get(suite) -> []; +mul_get(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple get..."), + try_test(do_mul_get). + +mul_get_2(X) -> mul_get(X). + +mul_get_3(X) -> mul_get(X). + + +mul_get_err(suite) -> []; +mul_get_err(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple get with error..."), + try_test(do_mul_get_err). + +mul_get_err_2(X) -> mul_get_err(X). + +mul_get_err_3(X) -> mul_get_err(X). + + +mul_next(suite) -> []; +mul_next(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple next..."), + try_test(do_mul_next). + +mul_next_2(X) -> mul_next(X). + +mul_next_3(X) -> mul_next(X). + + +mul_next_err(suite) -> []; +mul_next_err(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple next..."), + try_test(do_mul_next_err). + +mul_next_err_2(X) -> mul_next_err(X). + +mul_next_err_3(X) -> mul_next_err(X). + + +mul_set(suite) -> []; +mul_set(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple set..."), + try_test(do_mul_set). + +mul_set_2(X) -> mul_set(X). + +mul_set_3(X) -> mul_set(X). + + +mul_set_err(suite) -> []; +mul_set_err(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing multiple set with error..."), + try_test(do_mul_set_err). + +mul_set_err_2(X) -> mul_set_err(X). + +mul_set_err_3(X) -> mul_set_err(X). + + +sa_register(suite) -> []; +sa_register(Config) when list(Config) -> + ?DBG("sa_register -> entry", []), + {SaNode, _MgrNode, MibDir} = init_case(Config), + + ?DBG("sa_register -> start subagent", []), + ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), + + ?DBG("sa_register -> unregister subagent", []), + p("Testing unregister subagent (2)..."), + MA = whereis(snmp_master_agent), + rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), + try_test(unreg_test), + + p("Loading SA-MIB..."), + ?DBG("sa_register -> unload mibs", []), + snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), + ?DBG("sa_register -> unload mibs", []), + snmpa:load_mibs(SA, [MibDir ++ "SA-MIB"]), + ?DBG("sa_register -> register subagent", []), + rpc:call(SaNode, snmp, register_subagent, [MA,?sa,SA]), + try_test(sa_mib), + + ?DBG("sa_register -> stop subagent", []), + ?line stop_subagent(SA). + +sa_register_2(X) -> sa_register(X). + +sa_register_3(X) -> sa_register(X). + + +v1_trap(suite) -> []; +v1_trap(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Testing trap sending from master agent..."), + MA = whereis(snmp_master_agent), + + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(ma_trap1, [MA]), + try_test(ma_trap2, [MA]), + try_test(ma_v2_2_v1_trap, [MA]), + try_test(ma_v2_2_v1_trap2, [MA]), + + p("Testing trap sending from subagent..."), + try_test(sa_trap1, [SA]), + try_test(sa_trap2, [SA]), + try_test(sa_trap3, [SA]), + + ?line unload_master("TestTrap"), + ?line unload_master("TestTrapv2"), + + ?line stop_subagent(SA). + +v2_trap(suite) -> []; +v2_trap(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Testing trap sending from master agent..."), + MA = whereis(snmp_master_agent), + + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + + try_test(ma_v2_trap1, [MA]), + try_test(ma_v2_trap2, [MA]), + try_test(ma_v1_2_v2_trap, [MA]), + try_test(ma_v1_2_v2_trap2, [MA]), + + try_test(sa_mib), + p("Testing trap sending from subagent..."), + try_test(sa_v1_2_v2_trap1, [SA]), + try_test(sa_v1_2_v2_trap2, [SA]), + try_test(sa_v1_2_v2_trap3, [SA]), + + ?line unload_master("TestTrap"), + ?line unload_master("TestTrapv2"), + + ?line stop_subagent(SA). + +v3_trap(X) -> + v2_trap(X). + + +v3_inform(_X) -> + %% v2_inform(X). + {req, [], {conf, init_v3_inform, [v3_inform_i], finish_v3_inform}}. + +init_v2_inform(Config) when list(Config) -> + _Dir = ?config(agent_dir, Config), +% snmp_internal_mib:configure(Dir), + Config. + +init_v3_inform(X) -> + init_v2_inform(X). + +finish_v2_inform(Config) when list(Config) -> + _Dir = ?config(agent_dir, Config), +% snmp_internal_mib:configure(Dir), + Config. + +finish_v3_inform(X) -> + finish_v2_inform(X). + + + +v2_inform_i(suite) -> []; +v2_inform_i(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + p("Testing inform sending from master agent... NOTE! This test\ntakes a " + "few minutes (5) to complete."), + MA = whereis(snmp_master_agent), + + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(ma_v2_inform1, [MA]), + + ?line unload_master("TestTrap"), + ?line unload_master("TestTrapv2"). + +v3_inform_i(X) -> v2_inform_i(X). + + +sa_error(suite) -> []; +sa_error(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Testing sa bad value (is_set_ok)..."), + try_test(sa_errs_bad_value), + + p("Testing sa gen err (set)..."), + try_test(sa_errs_gen_err), + + p("Testing too big..."), + try_test(sa_too_big), + + ?line unload_master("OLD-SNMPEA-MIB"), + stop_subagent(SA). + +sa_error_2(X) -> sa_error(X). + +sa_error_3(X) -> sa_error(X). + + +next_across_sa(suite) -> []; +next_across_sa(Config) when list(Config) -> + {SaNode, _MgrNode, MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Loading another subagent mib..."), + ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas1"]), + + rpc:call(SaNode, snmp, register_subagent, [MA, ?klas1, SA]), + try_test(load_test_sa), + + p("Testing next across subagent (endOfMibView from SA)..."), + try_test(next_across_sa), + + p("Unloading mib"), + snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), + rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), + try_test(unreg_test), + + p("Starting another subagent"), + ?line {ok, SA2} = start_subagent(SaNode, ?klas1, "Klas1"), + p("Testing next across subagent (wrong prefix from SA)..."), + try_test(next_across_sa), + + stop_subagent(SA), + stop_subagent(SA2). + +next_across_sa_2(X) -> next_across_sa(X). + +next_across_sa_3(X) -> next_across_sa(X). + + +undo(suite) -> []; +undo(Config) when list(Config) -> + {SaNode, _MgrNode, MibDir} = init_case(Config), + MA = whereis(snmp_master_agent), + + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + + p("Testing undo phase at master agent..."), + ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas3"]), + ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas4"]), + try_test(undo_test), + try_test(api_test2), + ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas3"]), + + p("Testing bad return values from instrum. funcs..."), + try_test(bad_return), + + ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas4"]), + + p("Testing undo phase at subagent..."), + ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas3"]), + ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas4"]), + ?line ok = snmpa:register_subagent(MA, ?klas3, SA), + ?line ok = snmpa:register_subagent(MA, ?klas4, SA), + try_test(undo_test), + try_test(api_test3), + + p("Testing undo phase across master/subagents..."), + try_test(undo_test), + try_test(api_test3), + stop_subagent(SA). + +undo_2(X) -> undo(X). + +undo_3(X) -> undo(X). + +%% Req. Test2 +v1_processing(suite) -> []; +v1_processing(Config) when list(Config) -> + ?DBG("v1_processing -> entry", []), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + try_test(v1_proc), + ?line unload_master("Test2"). + +%% Req. Test2 +v2_processing(suite) -> []; +v2_processing(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + try_test(v2_proc), + ?line unload_master("Test2"). + +%% Req. Test2 +v3_processing(suite) -> []; +v3_processing(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("Test2"), + try_test(v2_proc), % same as v2! + ?line unload_master("Test2"). + + +%% We'll try get/set/trap and inform for all the auth & priv protocols. +%% For informs, the mgr is auth-engine. The agent has to sync. This is +%% accomplished by the first inform sent. That one will generate a +%% report, which makes it in sync. The notification-generating +%% application times out, and send again. This time it'll work. + +v3_crypto_basic(suite) -> []; +v3_crypto_basic(_Config) -> + EID = [0,0,0,0,0,0,0,0,0,0,0,2], + %% From rfc2274 appendix A.3.1 + ?line KMd5_1 = snmp:passwd2localized_key(md5, "maplesyrup", EID), + ?line [16#52,16#6f,16#5e,16#ed,16#9f,16#cc,16#e2,16#6f, + 16#89,16#64,16#c2,16#93,16#07,16#87,16#d8,16#2b] = + KMd5_1, + %% From rfc2274 appendix A.3.2 + ?line KSHA_1 = snmp:passwd2localized_key(sha, "maplesyrup", EID), + ?line [16#66,16#95,16#fe,16#bc,16#92,16#88,16#e3,16#62,16#82,16#23, + 16#5f,16#c7,16#15,16#1f,16#12,16#84,16#97,16#b3,16#8f,16#3f] = + KSHA_1, + %% From rfc2274, appendix A.5.1 + ?line KMd5_2 = snmp:passwd2localized_key(md5, "newsyrup", EID), + ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#88,16#05,16#61,16#51,16#41,16#67,16#6c,16#c9, + 16#19,16#61,16#74,16#e7,16#42,16#a3,16#25,16#51] = + snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2, 16, + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), + %% From rfc2274, appendix A.5.2 + ?line KSHA_2 = snmp:passwd2localized_key(sha, "newsyrup", EID), + ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#00,16#00,16#00,16#00,16#9c,16#10,16#17,16#f4, + 16#fd,16#48,16#3d,16#2d,16#e8,16#d5,16#fa,16#db, + 16#f8,16#43,16#92,16#cb,16#06,16#45,16#70,16#51] = + snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2, 20, + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), + KSHA_1t = lists:sublist(KSHA_1, 16), + KSHA_2t = lists:sublist(KSHA_2, 16), + ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, + 16#7e,16#f8,16#d8,16#a4,16#c9,16#cd,16#b2,16#6b, + 16#47,16#59,16#1c,16#d8,16#52,16#ff,16#88,16#b5] = + snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1t, KSHA_2t, 16, + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), + + %% Try with correct random + ?line Kc1 = snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2), + ?line KMd5_2 = snmp_user_based_sm_mib:extract_new_key(md5, KMd5_1, Kc1), + ?line Kc2 = snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2), + ?line KSHA_2 = snmp_user_based_sm_mib:extract_new_key(sha, KSHA_1, Kc2), + ok. + + + +v3_md5_auth(suite) -> []; +v3_md5_auth(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + p("Testing MD5 authentication...takes a few seconds..."), + + AgentDir = ?config(agent_dir, Config), + ?line rewrite_target_params_conf(AgentDir, "authMD5", authNoPriv), + ?line snmp_target_mib:reconfigure(AgentDir), + + MA = whereis(snmp_master_agent), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(v3_sync, [[{v2_proc, []}, + {ma_v2_trap1, [MA]}, + {v3_inform_sync, [MA]}]], + [{sec_level, authNoPriv}, {user, "authMD5"}]), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + ?line reset_target_params_conf(AgentDir). + +v3_sha_auth(suite) -> []; +v3_sha_auth(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + p("Testing SHA authentication...takes a few seconds..."), + + AgentDir = ?config(agent_dir, Config), + ?line rewrite_target_params_conf(AgentDir, "authSHA", authNoPriv), + ?line snmp_target_mib:reconfigure(AgentDir), + + MA = whereis(snmp_master_agent), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(v3_sync, [[{v2_proc, []}, + {ma_v2_trap1, [MA]}, + {v3_inform_sync, [MA]}]], + [{sec_level, authNoPriv}, {user, "authSHA"}]), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + ?line reset_target_params_conf(AgentDir). + +v3_des_priv(suite) -> []; +v3_des_priv(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + p("Testing DES encryption...takes a few seconds..."), + + AgentDir = ?config(agent_dir, Config), + ?line rewrite_target_params_conf(AgentDir, "privDES", authPriv), + ?line snmp_target_mib:reconfigure(AgentDir), + + MA = whereis(snmp_master_agent), + + ?line load_master("Test2"), + ?line load_master("TestTrap"), + ?line load_master("TestTrapv2"), + + try_test(v3_sync, [[{v2_proc, []}, + {ma_v2_trap1, [MA]}, + {v3_inform_sync, [MA]}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + ?line unload_master("TestTrapv2"), + ?line unload_master("TestTrap"), + ?line unload_master("Test2"), + ?line reset_target_params_conf(AgentDir). + +%% -define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). + +%% Make sure mgr is in sync with agent +v3_sync(Funcs) -> + ?DBG("v3_sync -> entry with Funcs: ~p",[Funcs]), + g([[sysDescr, 0]]), + expect(432, report, [{?usmStatsNotInTimeWindows_instance, any}]), + g([[sysDescr, 0]]), + expect(433, [{[sysDescr,0], any}]), + lists:foreach(fun({Func, Args}) -> apply(?MODULE, Func, Args) end, Funcs). + +v3_inform_sync(MA) -> + ?DBG("v3_sync -> entry with MA: ~p => Send notification",[MA]), + ?line snmpa:send_notification(MA, testTrapv22, no_receiver, + "standard inform", []), + %% Make sure agent is in sync with mgr... + ?DBG("v3_sync -> wait some time: ",[]), + sleep(20000), % more than 1500*10 in target_addr.conf + ?DBG("v3_sync -> await response",[]), + ?line expect(1, {inform, true}, + [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]). + + +v2_caps(suite) -> []; +v2_caps(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + try_test(v2_caps_i, [node()]). + +v2_caps_3(X) -> v2_caps(X). + + +v2_caps_i(Node) -> + ?line Idx = rpc:call(Node, snmp, add_agent_caps, [[1,2,3,4,5], "test cap"]), + g([[sysORID, Idx], [sysORDescr, Idx]]), + ?line expect(1, [{[sysORID, Idx], [1,2,3,4,5]}, + {[sysORDescr, Idx], "test cap"}]), + ?line rpc:call(Node, snmp, del_agent_caps, [Idx]), + g([[sysORID, Idx]]), + ?line expect(2, [{[sysORID, Idx], noSuchInstance}]). + + +%% Req. Test2 +v1_proc() -> + ?DBG("v1_proc -> entry", []), + %% According to RFC1157. + %% Template:
: + v1_get_p(), + v1_get_next_p(), + v1_set_p(). + + +v1_get_p() -> + %% 4.1.2:1 + g([[test2]]), + ?line expect(10, noSuchName, 1, [{[test2], 'NULL'}]), + g([[tDescr]]), + ?line expect(11, noSuchName, 1, [{[tDescr], 'NULL'}]), + g([[tDescr2,0]]), + ?line expect(12, noSuchName, 1, [{[tDescr2,0], 'NULL'}]), + g([[tDescr3,0]]), + ?line expect(131, noSuchName, 1, [{[tDescr3,0], 'NULL'}]), + g([[tDescr4,0]]), + ?line expect(132, noSuchName, 1, [{[tDescr4,0], 'NULL'}]), + g([[sysDescr, 0], [tDescr,0]]), % Outside mibview + ?line expect(14, noSuchName, 2, [{[sysDescr, 0], 'NULL'}, + {[tDescr,0], 'NULL'}]), + g([[sysDescr,3]]), + ?line expect(15, noSuchName, 1, [{[sysDescr, 3], 'NULL'}]), + + %% 4.1.2:2 + g([[tTable]]), + ?line expect(20, noSuchName, 1, [{[tTable], 'NULL'}]), + g([[tEntry]]), + ?line expect(21, noSuchName, 1, [{[tEntry], 'NULL'}]), + + %% 4.1.2:3 + g([[tTooBig, 0]]), + ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), + + %% 4.1.2:4 + g([[tGenErr1, 0]]), + ?line expect(40, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), + g([[tGenErr2, 0]]), + ?line expect(41, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), + g([[sysDescr, 0], [tGenErr3, 0]]), + ?line expect(42, genErr, 2, [{[sysDescr, 0], 'NULL'}, + {[tGenErr3, 0], 'NULL'}]). + + +v1_get_next_p() -> + %% 4.1.3:1 + gn([[1,3,7,1]]), + ?line expect(10, noSuchName, 1, [{[1,3,7,1], 'NULL'}]), + gn([[tDescr2]]), + ?line expect(11, tooBig, 0, any), + + %% 4.1.3:2 + gn([[tTooBig]]), + io:format("We currently don't handle tooBig correct!!!\n"), +% ?line expect(20, tooBig, 0, [{[tTooBig], 'NULL'}]), + ?line expect(20, tooBig, 0, any), + + %% 4.1.3:3 + gn([[tGenErr1]]), +% ?line expect(40, genErr, 1, [{[tGenErr1], 'NULL'}]), + ?line expect(40, genErr, 1, any), + gn([[tGenErr2]]), +% ?line expect(41, genErr, 1, [{[tGenErr2], 'NULL'}]), + ?line expect(41, genErr, 1, any), + gn([[sysDescr], [tGenErr3]]), +% ?line expect(42, genErr, 2, [{[sysDescr], 'NULL'}, +% {[tGenErr3], 'NULL'}]). + ?line expect(42, genErr, 2, any). + +v1_set_p() -> + %% 4.1.5:1 + s([{[1,3,7,0], i, 4}]), + ?line expect(10, noSuchName, 1, [{[1,3,7,0], 4}]), + s([{[tDescr,0], s, "outside mibview"}]), + ?line expect(11, noSuchName, 1, [{[tDescr,0], "outside mibview"}]), + s([{[tDescr3,0], s, "read-only"}]), + ?line expect(12, noSuchName, 1, [{[tDescr3,0], "read-only"}]), + s([{[tDescr3], s, "noSuchObject"}]), + ?line expect(13, noSuchName, 1, [{[tDescr3], "noSuchObject"}]), + s([{[tDescr3,1], s, "noSuchInstance"}]), + ?line expect(14, noSuchName, 1, [{[tDescr3,1], "noSuchInstance"}]), + s([{[tDescr2,0], s, "inconsistentName"}]), + ?line expect(15, noSuchName, 1, [{[tDescr2,0], "inconsistentName"}]), + + %% 4.1.5:2 + s([{[tDescr2, 0], i, 4}]), + ?line expect(20, badValue, 1, [{[tDescr2, 0], 4}]), + s([{[tDescr2, 0], s, "badValue"}]), + ?line expect(21, badValue, 1, [{[tDescr2, 0], "badValue"}]), + + %% 4.1.5:3 + %% The standard is quite incorrect here. The resp pdu was too big. In + %% the resp pdu, we have the original vbs. In the tooBig pdu we still + %% have to original vbs => the tooBig pdu is too big as well!!! It + %% may not get it to the manager, unless the agent uses 'NULL' instead + %% of the std-like original value. + s([{[tTooBig, 0], s, ?tooBigStr}]), + %% according to std: +% ?line expect(30, tooBig, 0, [{[tTooBig, 0], ?tooBigStr}]), + ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), + + %% 4.1.5:4 + s([{[tDescr2, 0], s, "is_set_ok_fail"}]), + ?line expect(40, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]), + s([{[tDescr2, 0], s, "commit_fail"}]), + ?line expect(41, genErr, 1, [{[tDescr2, 0], "commit_fail"}]). + +%% Req. Test2 +v2_proc() -> + %% According to RFC1905. + %% Template:
: + ?DBG("v2_proc -> entry",[]), + v2_get_p(), + v2_get_next_p(), + v2_get_bulk_p(), + v2_set_p(). + +v2_get_p() -> + %% 4.2.1:2 + ?DBG("v2_get_p -> entry",[]), + g([[test2]]), + ?line expect(10, [{[test2], noSuchObject}]), + g([[tDescr]]), + ?line expect(11, [{[tDescr], noSuchObject}]), + g([[tDescr4,0]]), + ?line expect(12, [{[tDescr4,0], noSuchObject}]), + g([[sysDescr, 0], [tDescr,0]]), % Outside mibview + ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}, + {[tDescr,0], noSuchObject}]), + g([[tTable]]), + ?line expect(14, [{[tTable], noSuchObject}]), + g([[tEntry]]), + ?line expect(15, [{[tEntry], noSuchObject}]), + + %% 4.2.1:3 + g([[tDescr2,0]]), %% instrum ret noSuchName!!! + ?line expect(20, [{[tDescr2,0], noSuchInstance}]), + g([[tDescr3,0]]), + ?line expect(21, [{[tDescr3,0], noSuchInstance}]), + g([[sysDescr,3]]), + ?line expect(22, [{[sysDescr, 3], noSuchInstance}]), + g([[tIndex,1]]), + ?line expect(23, [{[tIndex, 1], noSuchInstance}]), + + %% 4.2.1 - any other error: genErr + g([[tGenErr1, 0]]), + ?line expect(30, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), + g([[tGenErr2, 0]]), + ?line expect(31, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), + g([[sysDescr, 0], [tGenErr3, 0]]), + ?line expect(32, genErr, 2, [{[sysDescr, 0], 'NULL'}, + {[tGenErr3, 0], 'NULL'}]), + + %% 4.2.1 - tooBig + g([[tTooBig, 0]]), + ?line expect(40, tooBig, 0, []). + + +v2_get_next_p() -> + %% 4.2.2:2 + ?DBG("v2_get_next_p -> entry",[]), + gn([[1,3,7,1]]), + ?line expect(10, [{[1,3,7,1], endOfMibView}]), + gn([[sysDescr], [1,3,7,1]]), + ?line expect(11, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}]), + gn([[tCnt2, 1]]), + ?line expect(12, [{[tCnt2,2], 100}]), + gn([[tCnt2, 2]]), + ?line expect(12, [{[tCnt2,2], endOfMibView}]), + + %% 4.2.2 - any other error: genErr + gn([[tGenErr1]]), + ?line expect(20, genErr, 1, [{[tGenErr1], 'NULL'}]), + gn([[tGenErr2]]), + ?line expect(21, genErr, 1, [{[tGenErr2], 'NULL'}]), + gn([[sysDescr], [tGenErr3]]), + ?line expect(22, genErr, 2, [{[sysDescr], 'NULL'}, + {[tGenErr3], 'NULL'}]), + + %% 4.2.2 - tooBig + gn([[tTooBig]]), + ?line expect(20, tooBig, 0, []). + +v2_get_bulk_p() -> + %% 4.2.3 + ?DBG("v2_get_bulk_p -> entry",[]), + gb(1, 1, []), + ?line expect(10, []), + gb(-1, 1, []), + ?line expect(11, []), + gb(-1, -1, []), + ?line expect(12, []), + gb(-1, -1, []), + ?line expect(13, []), + gb(2, 0, [[sysDescr], [1,3,7,1]]), + ?line expect(14, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}]), + gb(1, 2, [[sysDescr], [1,3,7,1]]), + ?line expect(15, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}]), + gb(0, 2, [[sysDescr], [1,3,7,1]]), + ?line expect(16, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}, + {[sysObjectID, 0], [1,2,3]}, + {[1,3,7,1], endOfMibView}]), + + gb(2, 2, [[sysDescr], [1,3,7,1], [sysDescr], [1,3,7,1]]), + ?line expect(17, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}, + {[sysDescr, 0], "Erlang SNMP agent"}, + {[1,3,7,1], endOfMibView}, + {[sysObjectID, 0], [1,2,3]}, + {[1,3,7,1], endOfMibView}]), + + gb(1, 2, [[sysDescr], [sysDescr], [tTooBig]]), + ?line expect(18, [{[sysDescr, 0], "Erlang SNMP agent"}, + {[sysDescr, 0], "Erlang SNMP agent"}]), + + gb(1,12, [[tDescr2], [sysDescr]]), % next one after tDescr2 is tTooBig. + ?line expect(19, []), + + gb(2,2, [[sysDescr], [sysObjectID], [tGenErr1], [sysDescr]]), + ?line expect(20, genErr, 3, [{[sysDescr], 'NULL'}, + {[sysObjectID], 'NULL'}, + {[tGenErr1], 'NULL'}, + {[sysDescr], 'NULL'}]), + gb(0, 2, [[tCnt2, 1]]), + ?line expect(21, [{[tCnt2,2], 100}, + {[tCnt2,2], endOfMibView}]). + + +v2_set_p() -> + %% 4.2.5:1 + ?DBG("v2_set_p -> entry",[]), + s([{[1,3,7,0], i, 4}]), + ?line expect(10, noAccess, 1, [{[1,3,7,0], 4}]), + s([{[tDescr,0], s, "outside mibview"}]), + ?line expect(11, noAccess, 1, [{[tDescr,0], "outside mibview"}]), + + %% 4.2.5:2 + s([{[1,3,6,1,0], s, "noSuchObject"}]), + ?line expect(20, notWritable, 1, [{[1,3,6,1,0], "noSuchObject"}]), + + %% 4.2.5:3 + s([{[tDescr2, 0], i, 4}]), + ?line expect(30, wrongType, 1, [{[tDescr2, 0], 4}]), + s([{[tDescr2, 0], s, "badValue"}]), + ?line expect(31, badValue, 1, [{[tDescr2, 0], "badValue"}]), + + %% 4.2.5:4 + s([{[tStr, 0], s, ""}]), + ?line expect(40, wrongLength, 1, [{[tStr, 0], ""}]), + s([{[tStr, 0], s, "12345"}]), + ?line expect(40, wrongLength, 1, [{[tStr, 0], "12345"}]), + + %% 4.2.5:5 - N/A + + %% 4.2.5:6 + s([{[tInt1, 0], i, 0}]), + ?line expect(60, wrongValue, 1, [{[tInt1, 0], 0}]), + s([{[tInt1, 0], i, 5}]), + ?line expect(61, wrongValue, 1, [{[tInt1, 0], 5}]), + s([{[tInt2, 0], i, 0}]), + ?line expect(62, wrongValue, 1, [{[tInt2, 0], 0}]), + s([{[tInt2, 0], i, 5}]), + ?line expect(63, wrongValue, 1, [{[tInt2, 0], 5}]), + s([{[tInt3, 0], i, 5}]), + ?line expect(64, wrongValue, 1, [{[tInt3, 0], 5}]), + + %% 4.2.5:7 + s([{[tDescrX, 1, 1], s, "noCreation"}]), + ?line expect(70, noCreation, 1, [{[tDescrX, 1, 1], "noCreation"}]), + + %% 4.2.5:8 + s([{[tDescrX, 1, 2], s, "inconsistentName"}]), + ?line expect(80, inconsistentName, 1, + [{[tDescrX, 1, 2], "inconsistentName"}]), + + %% 4.2.5:9 + s([{[tCnt, 1, 2], i, 5}]), + ?line expect(90, notWritable, 1, [{[tCnt, 1, 2], 5}]), + s([{[tDescr3,0], s, "read-only"}]), + ?line expect(90, notWritable, 1, [{[tDescr3,0], "read-only"}]), + + %% 4.2.5:10 + s([{[tDescr2,0], s, "inconsistentValue"}]), + ?line expect(100, inconsistentValue, 1, + [{[tDescr2,0], "inconsistentValue"}]), + + %% 4.2.5:11 + s([{[tDescr2,0], s, "resourceUnavailable"}]), + ?line expect(110, resourceUnavailable, 1, + [{[tDescr2,0],"resourceUnavailable"}]), + + %% 4.2.5:12 + s([{[tDescr2, 0], s, "is_set_ok_fail"}]), + ?line expect(120, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]). + + %% commitFailed and undoFailed is tested by the 'undo' case. + + +%% Req. OLD-SNMPEA-MIB +table_test() -> + io:format("Testing simple get, next and set on communityTable...~n"), +%% {[147,214,36,45], "public", 2, readWrite}. +%% {[147,214,36,45], "standard trap", 2, read}. + Key1c3 = [intCommunityViewIndex,get(mip),is("public")], + Key2c3 = [intCommunityViewIndex,get(mip),is("standard trap")], + Key1c4 = [intCommunityAccess,get(mip),is("public")], + EndKey = [intCommunityEntry,[9],get(mip),is("public")], + gn([[intCommunityEntry]]), + ?line expect(7, [{Key1c3, 2}]), + gn([[intCommunityTable]]), + ?line expect(71, [{Key1c3, 2}]), + gn([[community]]), + ?line expect(72, [{Key1c3, 2}]), + gn([[otpSnmpeaMIB]]), + ?line expect(73, [{Key1c3, 2}]), + gn([[ericsson]]), + ?line expect(74, [{Key1c3, 2}]), + gn([Key1c3]), + ?line expect(8, [{Key2c3, 2}]), + gn([Key2c3]), + ?line expect(9, [{Key1c4, 2}]), + gn([EndKey]), + AgentIp = [intAgentIpAddress,0], + ?line expect(10, [{AgentIp, any}]), + g([Key1c3]), + ?line expect(11, [{Key1c3, 2}]), + g([EndKey]), + ?line ?v1_2(expect(12, noSuchName, 1, any), + expect(12, [{EndKey, noSuchObject}])), + + io:format("Testing row creation/deletion on communityTable...~n"), + NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], + NewKeyc4 = [intCommunityAccess,get(mip),is("test")], + NewKeyc5 = [intCommunityStatus,get(mip),is("test")], + s([{NewKeyc5, ?createAndGo}]), + ?line expect(14, ?v1_2(badValue, inconsistentValue), 1,any), + s([{NewKeyc5, ?createAndGo}, {NewKeyc3, 2}, {NewKeyc4, 2}]), + ?line expect(15, [{NewKeyc5, ?createAndGo},{NewKeyc3, 2}, {NewKeyc4, 2}]), + g([NewKeyc4]), + ?line expect(16, [{NewKeyc4, 2}]), + s([{NewKeyc5, ?destroy}]), + ?line expect(17, [{NewKeyc5, ?destroy}]), + s([{NewKeyc4, 2}]), + ?line expect(18, ?v1_2(noSuchName, inconsistentName), 1,[{NewKeyc4, 2}]), + s([{NewKeyc5, ?createAndWait}]), + ?line expect(19, [{NewKeyc5, ?createAndWait}]), + g([NewKeyc5]), + ?line expect(20, [{NewKeyc5, ?notReady}]), + s([{NewKeyc4, 2}]), + ?line expect(21, [{NewKeyc4, 2}]), + g([NewKeyc5]), + ?line expect(22, [{NewKeyc5, ?notReady}]), + s([{NewKeyc3, 2}]), + ?line expect(23, [{NewKeyc3, 2}]), + g([NewKeyc5]), + ?line expect(24, [{NewKeyc5, ?notInService}]), + s([{NewKeyc5, ?active}]), + ?line expect(25, [{NewKeyc5, ?active}]), + s([{NewKeyc5, ?destroy}]), + ?line expect(26, [{NewKeyc5, ?destroy}]), + s([{NewKeyc3, 3}]), + ?line expect(27, ?v1_2(noSuchName, inconsistentName), 1,[{NewKeyc3, 3}]), + otp_1128(). + +%% Req. system group +simple_standard_test() -> + ?DBG("simple_standard_test -> entry",[]), + gn([[1,1]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3]]), + ?line expect(11, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6]]), + ?line expect(12, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6,1]]), + ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6,1,2]]), + ?line expect(14, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6,1,2,1]]), + ?line expect(15, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[1,3,6,1,2,1,1]]), + ?line expect(16, [{[sysDescr,0], "Erlang SNMP agent"}]), + gn([[sysDescr]]), + ?line expect(17, [{[sysDescr,0], "Erlang SNMP agent"}]), + g([[sysDescr,0]]), + ?line expect(2, [{[sysDescr,0], "Erlang SNMP agent"}]), + g([[sysDescr]]), + ?line ?v1_2(expect(3, noSuchName, 1, any), + expect(3, [{[sysDescr], noSuchObject}])), + g([[1,6,7,0]]), + ?line ?v1_2(expect(41, noSuchName, 1, any), + expect(3, [{[1,6,7,0], noSuchObject}])), + gn([[1,13]]), + ?line ?v1_2(expect(4, noSuchName,1, any), + expect(4, [{[1,13], endOfMibView}])), + s([{[sysLocation, 0], "new_value"}]), + ?line expect(5, [{[sysLocation, 0], "new_value"}]), + g([[sysLocation, 0]]), + ?line expect(6, [{[sysLocation, 0], "new_value"}]), + io:format("Testing noSuchName and badValue...~n"), + s([{[sysServices,0], 3}]), + ?line expect(61, ?v1_2(noSuchName, notWritable), 1, any), + s([{[sysLocation, 0], i, 3}]), + ?line expect(62, ?v1_2(badValue, wrongType), 1, any), + ?DBG("simple_standard_test -> done",[]), + ok. + +%% This is run in the agent node +db_notify_client(suite) -> []; +db_notify_client(Config) when list(Config) -> + {SaNode, MgrNode, MibDir} = init_case(Config), + ?DBG("~n\tSaNode: ~p~n\tMgrNode: ~p~n\tMibDir: ~p", + [SaNode,MgrNode,MibDir]), + snmpa_local_db:register_notify_client(self(),?MODULE), + + %% This call (the manager) will issue to set operations, so + %% we expect to receive to notify(insert) calls. + try_test(db_notify_client_test), + + ?DBG("await first notify",[]), + receive + {db_notify_test_reply,insert} -> ?DBG("first notify received",[]),ok + end, + + ?DBG("await second notify",[]), + receive + {db_notify_test_reply,insert} -> ?DBG("second notify received",[]),ok + end, + + snmpa_local_db:unregister_notify_client(self()). + + +%% This is run in the manager node +db_notify_client_test() -> + ?DBG("set first new sysLocation",[]), + s([{[sysLocation, 0], "new_value"}]), + ?line expect(5, [{[sysLocation, 0], "new_value"}]), + + ?DBG("set second new sysLocation",[]), + s([{[sysLocation, 0], "new_value"}]), + ?line expect(5, [{[sysLocation, 0], "new_value"}]). + +notify(Pid,What) -> + ?DBG("notify(~p,~p) -> called",[Pid,What]), + Pid ! {db_notify_test_reply,What}. + + +%% Req: system group, OLD-SNMPEA-MIB, Klas1 +big_test() -> + ?DBG("big_test -> testing simple next/get/set @ master agent...",[]), + simple_standard_test(), + + ?DBG("big_test -> testing simple next/get/set @ subagent...",[]), + gn([[klas1]]), + ?line expect(1, [{[fname,0], ""}]), + g([[fname,0]]), + ?line expect(2, [{[fname,0], ""}]), + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + g([[fname,0]]), + ?line expect(4, [{[fname,0], "test set"}]), + + ?DBG("big_test -> " + "testing next from last instance in master to subagent...",[]), + gn([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(5, [{[fname,0], "test set"}]), + gn([[1,1], + [?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, + {[fname,0], "test set"}]), + s([{[fname,0], s, ""}]), + ?line expect(52, [{[fname,0], ""}]), + + table_test(), + + ?DBG("big_test -> adding one row in subagent table",[]), + _FTab = [friendsEntry], + s([{[friendsEntry, [2, 3]], s, "kompis3"}, + {[friendsEntry, [3, 3]], i, ?createAndGo}]), + ?line expect(6, [{[friendsEntry, [2, 3]], "kompis3"}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + g([[friendsEntry, [2, 3]], + [friendsEntry, [3, 3]]]), + ?line expect(7, [{[friendsEntry, [2, 3]], "kompis3"}, + {[friendsEntry, [3, 3]], ?active}]), + s([{[friendsEntry, [3, 3]], i, ?destroy}]), + ?line expect(8, [{[friendsEntry, [3, 3]], ?destroy}]), + + otp_1131(), + + ?DBG("big_test -> adding two rows in subagent table with special INDEX", + []), + s([{[kompissEntry, [1, 3]], s, "kompis3"}, + {[kompissEntry, [2, 3]], i, ?createAndGo}]), + ?line expect(9, [{[kompissEntry, [1, 3]], "kompis3"}, + {[kompissEntry, [2, 3]], ?createAndGo}]), + g([[kompissEntry, [1, 3]], + [kompissEntry, [2, 3]]]), + ?line expect(10, [{[kompissEntry, [1, 3]], "kompis3"}, + {[kompissEntry, [2, 3]], ?active}]), + gn([[kompissEntry, [1]], + [kompissEntry, [2]]]), + ?line expect(11, [{[kompissEntry, [1, 3]], "kompis3"}, + {[kompissEntry, [2, 3]], ?active}]), + s([{[kompissEntry, [1, 2]], s, "kompis3"}, + {[kompissEntry, [2, 2]], i, ?createAndGo}]), + ?line expect(12, [{[kompissEntry, [1, 2]], "kompis3"}, + {[kompissEntry, [2, 2]], ?createAndGo}]), + gn([[kompissEntry, [1, 1]], + [kompissEntry, [2, 1]]]), + ?line expect(13, [{[kompissEntry, [1, 2]], "kompis3"}, + {[kompissEntry, [2, 2]], ?active}]), + s([{[kompissEntry, [2, 3]], i, ?destroy}]), + ?line expect(14, [{[kompissEntry, [2, 3]], ?destroy}]), + s([{[kompissEntry, [2, 2]], i, ?destroy}]), + ?line expect(15, [{[kompissEntry, [2, 2]], ?destroy}]), + ?DBG("big_test -> done",[]), + ok. + +%% Req. system group, Klas2, OLD-SNMPEA-MIB +big_test_2() -> + p("Testing simple next/get/set @ master agent (2)..."), + simple_standard_test(), + + p("Testing simple next/get/set @ subagent (2)..."), + gn([[klas2]]), + ?line expect(1, [{[fname2,0], ""}]), + g([[fname2,0]]), + ?line expect(2, [{[fname2,0], ""}]), + s([{[fname2,0], s, "test set"}]), + ?line expect(3, [{[fname2,0], "test set"}]), + g([[fname2,0]]), + ?line expect(4, [{[fname2,0], "test set"}]), + + otp_1298(), + + p("Testing next from last object in master to subagent (2)..."), + gn([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(5, [{[fname2,0], "test set"}]), + gn([[1,1], + [?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, + {[fname2,0], "test set"}]), + + table_test(), + + p("Adding one row in subagent table (2)"), + _FTab = [friendsEntry2], + s([{[friendsEntry2, [2, 3]], s, "kompis3"}, + {[friendsEntry2, [3, 3]], i, ?createAndGo}]), + ?line expect(6, [{[friendsEntry2, [2, 3]], "kompis3"}, + {[friendsEntry2, [3, 3]], ?createAndGo}]), + g([[friendsEntry2, [2, 3]], + [friendsEntry2, [3, 3]]]), + ?line expect(7, [{[friendsEntry2, [2, 3]], "kompis3"}, + {[friendsEntry2, [3, 3]], ?active}]), + s([{[friendsEntry2, [3, 3]], i, ?destroy}]), + ?line expect(8, [{[friendsEntry2, [3, 3]], ?destroy}]), + + p("Adding two rows in subagent table with special INDEX (2)"), + s([{[kompissEntry2, [1, 3]], s, "kompis3"}, + {[kompissEntry2, [2, 3]], i, ?createAndGo}]), + ?line expect(9, [{[kompissEntry2, [1, 3]], "kompis3"}, + {[kompissEntry2, [2, 3]], ?createAndGo}]), + g([[kompissEntry2, [1, 3]], + [kompissEntry2, [2, 3]]]), + ?line expect(10, [{[kompissEntry2, [1, 3]], "kompis3"}, + {[kompissEntry2, [2, 3]], ?active}]), + gn([[kompissEntry2, [1]], + [kompissEntry2, [2]]]), + ?line expect(11, [{[kompissEntry2, [1, 3]], "kompis3"}, + {[kompissEntry2, [2, 3]], ?active}]), + s([{[kompissEntry2, [1, 2]], s, "kompis3"}, + {[kompissEntry2, [2, 2]], i, ?createAndGo}]), + ?line expect(12, [{[kompissEntry2, [1, 2]], "kompis3"}, + {[kompissEntry2, [2, 2]], ?createAndGo}]), + gn([[kompissEntry2, [1, 1]], + [kompissEntry2, [2, 1]]]), + ?line expect(13, [{[kompissEntry2, [1, 2]], "kompis3"}, + {[kompissEntry2, [2, 2]], ?active}]), + s([{[kompissEntry2, [2, 3]], i, ?destroy}]), + ?line expect(14, [{[kompissEntry2, [2, 3]], ?destroy}]), + s([{[kompissEntry2, [2, 2]], i, ?destroy}]), + ?line expect(15, [{[kompissEntry2, [2, 2]], ?destroy}]), + ok. + +%% Req. Test1 +multi_threaded_test() -> + p("Testing multi threaded agent..."), + g([[multiStr,0]]), + Pid = get_multi_pid(), + g([[sysUpTime,0]]), + ?line expect(1, [{[sysUpTime,0], any}]), + s([{[sysLocation, 0], s, "pelle"}]), + ?line expect(2, [{[sysLocation, 0], "pelle"}]), + Pid ! continue, + ?line expect(3, [{[multiStr,0], "ok"}]), + + s([{[multiStr, 0], s, "block"}]), + Pid2 = get_multi_pid(), + g([[sysUpTime,0]]), + ?line expect(4, [{[sysUpTime,0], any}]), + g([[multiStr,0]]), + Pid3 = get_multi_pid(), + g([[sysUpTime,0]]), + ?line expect(5, [{[sysUpTime,0], any}]), + s([{[sysLocation, 0], s, "kalle"}]), + Pid3 ! continue, + ?line expect(6, [{[multiStr,0], "ok"}]), + Pid2 ! continue, + ?line expect(7, [{[multiStr,0], "block"}]), + ?line expect(8, [{[sysLocation,0], "kalle"}]). + +%% Req. Test1, TestTrapv2 +mt_trap_test(MA) -> + snmpa:send_trap(MA, testTrapv22, "standard trap"), + ?line expect(1, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + + snmpa:send_trap(MA, mtTrap, "standard trap"), + Pid = get_multi_pid(), + g([[sysUpTime,0]]), + ?line expect(2, [{[sysUpTime,0], any}]), + snmpa:send_trap(MA, testTrapv22, "standard trap"), + ?line expect(3, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + Pid ! continue, + ?line expect(4, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?testTrap ++ [2]}, + {[multiStr,0], "ok"}]). + + +get_multi_pid() -> + get_multi_pid(10). +get_multi_pid(0) -> + ?line ?FAIL(no_global_name); +get_multi_pid(N) -> + sleep(1000), + case global:whereis_name(snmp_multi_tester) of + Pid when pid(Pid) -> Pid; + _ -> get_multi_pid(N-1) + end. + +%% Req. Test1 +types_v2_test() -> + p("Testing v2 types..."), + + s([{[bits1,0], 2#10}]), + ?line expect(1, [{[bits1,0], ?str(2#10)}]), + g([[bits1,0]]), + ?line expect(2, [{[bits1,0], ?str(2#101)}]), + + s([{[bits2,0], 2#11000000110}]), + ?line expect(3, [{[bits2,0], ?str(2#11000000110)}]), + g([[bits2,0]]), + ?line expect(4, [{[bits2,0], ?str(2#11000000110)}]), + + g([[bits3,0]]), + ?line expect(50, genErr, 1, any), + + g([[bits4,0]]), + ?line expect(51, genErr, 1, any), + + s([{[bits1,0], s, [2#10]}]), + ?line expect(6, ?v1_2(badValue, wrongValue), 1, any), + + s([{[bits2,0], 2#11001001101010011}]), + ?line expect(7, ?v1_2(badValue, wrongValue), 1, any). + + +%% Req. Test1 +implied_test(MA) -> + ?LOG("implied_test -> start",[]), + p("Testing IMPLIED..."), + + snmpa:verbosity(MA,trace), + snmpa:verbosity(MA,trace), + + %% Create two rows, check that they are get-nexted in correct order. + Idx1 = "apa", + Idx2 = "qq", + ?DBG("implied_test -> (send) create row 1 '~s' in table 1",[Idx1]), + s([{[testStatus, Idx1], i, ?createAndGo}, {[testDescr, Idx1],s,"row 1"}]), + ?line expect(1, [{[testStatus, Idx1], ?createAndGo}, + {[testDescr, Idx1], "row 1"}]), + ?DBG("implied_test -> (send) create row 2 '~s' in table 1",[Idx2]), + s([{[testStatus, Idx2], i, ?createAndGo}, {[testDescr, Idx2],s,"row 2"}]), + ?line expect(2, [{[testStatus, Idx2], ?createAndGo}, + {[testDescr, Idx2], "row 2"}]), + ?DBG("implied_test -> get-next(testDescr)",[]), + gn([[testDescr]]), + ?line expect(3, [{[testDescr,Idx1], "row 1"}]), + ?DBG("implied_test -> get-next(testDescr) of row 1",[]), + gn([[testDescr,Idx1]]), + ?line expect(4, [{[testDescr,Idx2], "row 2"}]), + + % Delete the rows + ?DBG("implied_test -> (send) delete row 1 '~s' from table 1",[Idx1]), + s([{[testStatus, Idx1], i, ?destroy}]), + ?line expect(5, [{[testStatus, Idx1], ?destroy}]), + ?DBG("implied_test -> (send) delete row 2 '~s' from table 1",[Idx2]), + s([{[testStatus, Idx2], i, ?destroy}]), + ?line expect(6, [{[testStatus, Idx2], ?destroy}]), + + %% Try the same in other table + Idx3 = [1, "apa"], + Idx4 = [1, "qq"], + ?DBG("implied_test -> (send) create row 1 '~s' in table 2",[Idx3]), + s([{[testStatus2, Idx3], i, ?createAndGo}, {[testDescr2,Idx3],s,"row 1"}]), + ?line expect(1, [{[testStatus2, Idx3], ?createAndGo}, + {[testDescr2, Idx3], "row 1"}]), + ?DBG("implied_test -> (send) create row 2 '~s' in table 2",[Idx4]), + s([{[testStatus2, Idx4], i, ?createAndGo}, {[testDescr2,Idx4],s,"row 2"}]), + ?line expect(2, [{[testStatus2, Idx4], ?createAndGo}, + {[testDescr2, Idx4], "row 2"}]), + ?DBG("implied_test -> get-next(testDescr2)",[]), + gn([[testDescr2]]), + ?line expect(3, [{[testDescr2,Idx3], "row 1"}]), + ?DBG("implied_test -> get-next(testDescr2) of row 1",[]), + gn([[testDescr2,Idx3]]), + ?line expect(4, [{[testDescr2,Idx4], "row 2"}]), + + % Delete the rows + ?DBG("implied_test -> (send) delete row 1 '~s' from table 2",[Idx3]), + s([{[testStatus2, Idx3], i, ?destroy}]), + ?line expect(5, [{[testStatus2, Idx3], ?destroy}]), + ?DBG("implied_test -> (send) delete row 2 '~s' from table 2",[Idx4]), + s([{[testStatus2, Idx4], i, ?destroy}]), + ?line expect(6, [{[testStatus2, Idx4], ?destroy}]), + + snmpa:verbosity(MA,log), + + ?LOG("implied_test -> done",[]). + + + +%% Req. Test1 +sparse_table_test() -> + p("Testing sparse table..."), + + %% Create two rows, check that they are get-nexted in correct order. + Idx1 = 1, + Idx2 = 2, + s([{[sparseStatus, Idx1], i, ?createAndGo}, + {[sparseDescr, Idx1], s, "row 1"}]), + ?line expect(1, [{[sparseStatus, Idx1], ?createAndGo}, + {[sparseDescr, Idx1], "row 1"}]), + s([{[sparseStatus, Idx2], i, ?createAndGo}, + {[sparseDescr, Idx2], s, "row 2"}]), + ?line expect(2, [{[sparseStatus, Idx2], ?createAndGo}, + {[sparseDescr, Idx2], "row 2"}]), + ?v1_2(gn([[sparseIndex], [sparseDescr,Idx1], [sparseDescr,Idx2], + [sparseStatus,Idx1], [sparseStatus,Idx2]]), + gb(0,5,[[sparseIndex]])), + ?line expect(3, [{[sparseDescr,Idx1], "row 1"}, + {[sparseDescr,Idx2], "row 2"}, + {[sparseStatus,Idx1], ?active}, + {[sparseStatus,Idx2], ?active}, + {[sparseStr,0], "slut"}]), + % Delete the rows + s([{[sparseStatus, Idx1], i, ?destroy}]), + ?line expect(4, [{[sparseStatus, Idx1], ?destroy}]), + s([{[sparseStatus, Idx2], i, ?destroy}]), + ?line expect(5, [{[sparseStatus, Idx2], ?destroy}]). + + +%% Req. Test1 +cnt_64_test(MA) -> + ?LOG("start cnt64 test (~p)",[MA]), + snmpa:verbosity(MA,trace), + ?LOG("start cnt64 test",[]), + p("Testing Counter64, and at the same time, RowStatus is not last column"), + + ?DBG("get cnt64",[]), + g([[cnt64,0]]), + ?DBG("await response",[]), + ?line ?v1_2(expect(1, noSuchName, 1, any), + expect(1, [{[cnt64,0],18446744073709551615}])), + ?DBG("get-next cnt64",[]), + gn([[cnt64]]), + ?DBG("await response",[]), + ?line ?v1_2(expect(2, [{[cnt64Str,0], "after cnt64"}]), + expect(2, [{[cnt64,0],18446744073709551615}])), + ?DBG("send cntTrap",[]), + snmpa:send_trap(MA,cntTrap,"standard trap",[{sysContact,"pelle"}, + {cnt64, 10}, + {sysLocation, "here"}]), + ?DBG("await response",[]), + ?line ?v1_2(expect(3, trap, [test], 6, 1, [{[sysContact,0], "pelle"}, + {[sysLocation,0], "here"}]), + expect(3, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?testTrap ++ [1]}, + {[sysContact,0], "pelle"}, + {[cnt64,0], 10}, + {[sysLocation,0], "here"}])), + + %% Create two rows, check that they are get-nexted in correct order. + Idx1 = 1, + Idx2 = 2, + ?DBG("create row (cntStatus): ~p",[Idx1]), + s([{[cntStatus, Idx1], i, ?createAndGo}]), + ?DBG("await response",[]), + ?line expect(1, [{[cntStatus, Idx1], ?createAndGo}]), + ?DBG("create row (cntStatus): ~p",[Idx2]), + s([{[cntStatus, Idx2], i, ?createAndGo}]), + ?DBG("await response",[]), + ?line expect(2, [{[cntStatus, Idx2], ?createAndGo}]), + + ?DBG("get-next (cntIndex)",[]), + gn([[cntIndex]]), + ?DBG("await response",[]), + ?line ?v1_2(expect(3, [{[cntStatus,Idx1], ?active}]), + expect(3, [{[cntCnt,Idx1], 0}])), + % Delete the rows + ?DBG("delete row (cntStatus): ~p",[Idx1]), + s([{[cntStatus, Idx1], i, ?destroy}]), + ?DBG("await response",[]), + ?line expect(4, [{[cntStatus, Idx1], ?destroy}]), + ?DBG("delete row (cntStatus): ~p",[Idx2]), + s([{[cntStatus, Idx2], i, ?destroy}]), + ?DBG("await response",[]), + ?line expect(5, [{[cntStatus, Idx2], ?destroy}]), + catch snmpa:verbosity(MA,log), + ?DBG("done",[]), + ok. + +%% Req. Test1 +opaque_test() -> + p("Testing Opaque datatype..."), + g([[opaqueObj,0]]), + ?line expect(1, [{[opaqueObj,0], "opaque-data"}]). + +%% Req. OLD-SNMPEA-MIB +api_test(MaNode) -> + ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, + [intAgentIpAddress]), + ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, + oid_to_name, [OID]), + ?line false = rpc:call(MaNode, snmp, name_to_oid, [intAgentIpAddres]), + ?line false = rpc:call(MaNode, snmp, oid_to_name, + [[1,5,32,3,54,3,3,34,4]]), + ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, + [intViewType, excluded]), + ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, + [intViewType, 2]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, [intViewType, exclude]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [intAgentIpAddress, exclude]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [intAgentIpAddre, exclude]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [intViewType, 3]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddress, 2]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddre, 2]), + ?line {value, active} = rpc:call(MaNode, snmp, + int_to_enum, ['RowStatus', ?active]), + ?line {value, ?destroy} = rpc:call(MaNode, snmp, + enum_to_int, ['RowStatus', destroy]), + ?line false = rpc:call(MaNode, snmp, + enum_to_int, ['RowStatus', xxxdestroy]), + ?line false = rpc:call(MaNode, snmp, + enum_to_int, ['xxRowStatus', destroy]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, ['RowStatus', 25]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, ['xxRowStatus', 1]), + ?line case snmp:date_and_time() of + List when list(List), length(List) == 8 -> ok; + List when list(List), length(List) == 11 -> ok + end. + +%% Req. Klas3 +api_test2() -> + g([[fname3,0]]), + ?line expect(1, [{[fname3,0], "ok"}]), + g([[fname4,0]]), + ?line expect(2, [{[fname4,0], 1}]). + +api_test3() -> + g([[fname3,0]]), + ?line expect(1, [{[fname3,0], "ok"}]). + + +unreg_test() -> + gn([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(1, [{[snmpInPkts, 0], any}]). + +load_test() -> + gn([[?v1_2(sysServices, sysORLastChange),0]]), + ?line expect(1, [{[fname,0], ""}]). + +%% Req. Klas1 +load_test_sa() -> + gn([[?v1_2(sysServices,sysORLastChange), 0]]), + ?line expect(1, [{[fname,0], any}]). + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_get() -> + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + g([[sysDescr,0], Key1c4, [fname,0],Key1c3, + [sysName,0]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[fname,0], "test set"}, + {Key1c3, 2}, + {[sysName,0], "test"}]), + g([[1,3,7,1], Key1c4, [sysDescr,0], [1,3,7,2], Key1c3, [sysDescr,0]]), + ?line ?v1_2(expect(2, noSuchName, [1,4], any), + expect(2, [{[1,3,7,1], noSuchObject}, + {Key1c4, 2}, + {[sysDescr,0], "Erlang SNMP agent"}, + {[1,3,7,2], noSuchObject}, + {Key1c3, 2}, + {[sysDescr,0], "Erlang SNMP agent"}])). + +%% Req. v1, system group, Klas1, OLD-SNMPEA-MIB, *ej* Klas3. +do_mul_get_err() -> + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + g([[sysDescr,0],Key1c4,[fname,0], Key1c3, [sysName,2]]), + ?line ?v1_2(expect(1, noSuchName, 5, any), + expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[fname,0], "test set"}, + {Key1c3, 2}, + {[sysName,2], noSuchInstance}])), + g([[sysDescr,0],Key1c4,[fname3,0], Key1c3, [sysName,1]]), + ?line ?v1_2(expect(1, noSuchName, [3,5], any), + expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[fname3,0], noSuchObject}, + {Key1c3, 2}, + {[sysName,1], noSuchInstance}])). + + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_next() -> + Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], + Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + gn([[sysDescr], Key1c4s, [fname],Key1c3s,[sysName]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, {[fname,0], "test set"}, + {Key1c3, 2}, {[sysName,0], "test"}]). + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_next_err() -> + Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], + Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], + Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], + Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], + s([{[fname,0], s, "test set"}]), + ?line expect(3, [{[fname,0], "test set"}]), + gn([[sysDescr], Key1c4s, [1,3,6,999], [fname],[1,3,90], Key1c3s,[sysName]]), + ?line ?v1_2(expect(1, noSuchName, [3,5], any), + expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {Key1c4, 2}, + {[1,3,6,999], endOfMibView}, + {[fname,0], "test set"}, + {[1,3,90], endOfMibView}, + {Key1c3, 2}, + {[sysName,0], "test"}])). + + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_set() -> + p("Adding one row in subagent table, and one in master table"), + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + s([{[friendsEntry, [2, 3]], "kompis3"}, + {NewKeyc3, 2}, + {[sysLocation,0], "new_value"}, + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + ?line expect(1, [{[friendsEntry, [2, 3]], "kompis3"}, + {NewKeyc3, 2}, + {[sysLocation,0], "new_value"}, + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + g([[friendsEntry, [2, 3]], + [sysLocation,0], + [friendsEntry, [3, 3]]]), + ?line expect(2, [{[friendsEntry, [2, 3]], "kompis3"}, + {[sysLocation,0], "new_value"}, + {[friendsEntry, [3, 3]], ?active}]), + g([NewKeyc4]), + ?line expect(3, [{NewKeyc4, 2}]), + s([{[friendsEntry, [3, 3]], ?destroy}, + {NewKeyc5, ?destroy}]), + ?line expect(4, [{[friendsEntry, [3, 3]], ?destroy}, + {NewKeyc5, ?destroy}]). + +%% Req. system group, Klas1, OLD-SNMPEA-MIB +do_mul_set_err() -> + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + p("Adding one row in subagent table, and one in master table"), + s([{[friendsEntry, [2, 3]], s, "kompis3"}, + {NewKeyc3, 2}, + {[sysUpTime,0], 45}, % sysUpTime (readOnly) + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}, + {[friendsEntry, [3, 3]], ?createAndGo}]), + ?line expect(1, ?v1_2(noSuchName, notWritable), 3, any), + g([[friendsEntry, [2, 3]]]), + ?line ?v1_2(expect(2, noSuchName, 1, any), + expect(2, [{[friendsEntry, [2,3]], noSuchInstance}])), + g([NewKeyc4]), + ?line ?v1_2(expect(3, noSuchName, 1, any), + expect(3, [{NewKeyc4, noSuchInstance}])). + +%% Req. SA-MIB +sa_mib() -> + g([[sa, [2,0]]]), + ?line expect(1, [{[sa, [2,0]], 3}]), + s([{[sa, [1,0]], s, "sa_test"}]), + ?line expect(2, [{[sa, [1,0]], "sa_test"}]). + +ma_trap1(MA) -> + snmpa:send_trap(MA, testTrap2, "standard trap"), + ?line expect(1, trap, [system], 6, 1, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}]), + snmpa:send_trap(MA, testTrap1, "standard trap"), + ?line expect(2, trap, [1,2,3] , 1, 0, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}]). + +ma_trap2(MA) -> + snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). + +ma_v2_2_v1_trap(MA) -> + snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). + +ma_v2_2_v1_trap2(MA) -> + snmpa:send_trap(MA,linkUp,"standard trap",[{ifIndex, [1], 1}, + {ifAdminStatus, [1], 1}, + {ifOperStatus, [1], 2}]), + ?line expect(3, trap, [1,2,3], 3, 0, [{[ifIndex, 1], 1}, + {[ifAdminStatus, 1], 1}, + {[ifOperStatus, 1], 2}]). + +sa_trap1(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap"), + ?line expect(4, trap, [ericsson], 6, 1, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}]). + +sa_trap2(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), + ?line expect(5, trap, [ericsson], 6, 1, [{[system, [4,0]], + "pelle"}, + {[sa, [1,0]], "sa_test"}]). + +sa_trap3(SA) -> + snmpa:send_trap(SA, saTrap2, "standard trap", + [{intViewSubtree, [4], [1,2,3,4]}]), + ?line expect(6, trap, [ericsson], 6, 2, [{[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}, + {[intViewSubtree,4],[1,2,3,4]}]). + +ma_v2_trap1(MA) -> + ?DBG("ma_v2_traps -> entry with MA = ~p => " + "send standard trap: testTrapv22",[MA]), + snmpa:send_trap(MA, testTrapv22, "standard trap"), + ?line expect(1, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + ?DBG("ma_v2_traps -> send standard trap: testTrapv21",[]), + snmpa:send_trap(MA, testTrapv21, "standard trap"), + ?line expect(2, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?snmp ++ [1]}]). + +ma_v2_trap2(MA) -> + snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}, + {[system, [4,0]], "pelle"}]). + +%% Note: This test case takes a while... actually a couple of minutes. +ma_v2_inform1(MA) -> + ?DBG("ma_v2_inform -> entry with MA = ~p => " + "send notification: testTrapv22",[MA]), + ?line snmpa:send_notification(MA, testTrapv22, no_receiver, "standard inform", []), + ?line expect(1, {inform, true}, + [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + + ?DBG("ma_v2_inform -> send notification: testTrapv22",[]), + snmpa:send_notification(MA, testTrapv22, {tag1, self()}, + "standard inform", []), + ?line expect(1, {inform, true}, + [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + ?DBG("ma_v2_inform -> await targets",[]), + receive + {snmp_targets, tag1, [_]} -> + ok; + {snmp_targets, tag1, Addrs1} -> + ?line ?FAIL({bad_addrs, Addrs1}) + after + 5000 -> + ?ERR("ma_v2_inform1 -> awaiting snmp_targets(tag1) timeout",[]), + ?line ?FAIL(nothing_at_all) + end, + ?DBG("ma_v2_inform -> await notification",[]), + receive + {snmp_notification, tag1, {got_response, _}} -> + ok; + {snmp_notification, tag1, {no_response, _}} -> + ?line ?FAIL(no_response) + after + 20000 -> + ?ERR("ma_v2_inform1 -> " + "awaiting snmp_notification(tag1) timeout",[]), + ?line ?FAIL(nothing_at_all) + end, + + %% + %% -- The rest is possibly erroneous... + %% + + ?DBG("ma_v2_inform -> send notification: testTrapv22",[]), + snmpa:send_notification(MA, testTrapv22, {tag2, self()}, + "standard inform", []), + ?line expect(2, {inform, false}, + [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}]), + ?DBG("ma_v2_inform -> await targets",[]), + receive + {snmp_targets, tag2, [_]} -> + ok; + {snmp_targets, tag2, Addrs2} -> + ?ERR("ma_v2_inform1 -> awaiting snmp_targets(tag2) timeout",[]), + ?line ?FAIL({bad_addrs, Addrs2}) + after + 5000 -> + ?line ?FAIL(nothing_at_all) + end, + ?DBG("ma_v2_inform -> await notification",[]), + receive + {snmp_notification, tag2, {got_response, _}} -> + ?line ?FAIL(got_response); + {snmp_notification, tag2, {no_response, _}} -> + ok + after + 240000 -> + ?ERR("ma_v2_inform1 -> " + "awaiting snmp_notification(tag2) timeout",[]), + ?line ?FAIL(nothing_at_all) + end. + + +ma_v1_2_v2_trap(MA) -> + snmpa:send_trap(MA,linkDown,"standard trap",[{ifIndex, [1], 1}]), + ?line expect(2, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?snmpTraps ++ [3]}, + {[ifIndex, 1], 1}, + {[snmpTrapEnterprise, 0], [1,2,3]}]). + + +ma_v1_2_v2_trap2(MA) -> + snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), + ?line expect(3, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?system ++ [0,1]}, + {[system, [4,0]], "pelle"}, + {[snmpTrapEnterprise, 0], ?system}]). + + +sa_v1_2_v2_trap1(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap"), + ?line expect(4, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, + {[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}, + {[snmpTrapEnterprise, 0], ?ericsson}]). + +sa_v1_2_v2_trap2(SA) -> + snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), + ?line expect(4, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, + {[system, [4,0]], "pelle"}, + {[sa, [1,0]], "sa_test"}, + {[snmpTrapEnterprise, 0], ?ericsson}]). + + +sa_v1_2_v2_trap3(SA) -> + snmpa:send_trap(SA, saTrap2, "standard trap", + [{intViewSubtree, [4], [1,2,3,4]}]), + ?line expect(4, v2trap, [{[sysUpTime, 0], any}, + {[snmpTrapOID, 0], ?ericsson ++ [0, 2]}, + {[system, [4,0]], + "{mbj,eklas}@erlang.ericsson.se"}, + {[sa, [1,0]], "sa_test"}, + {[intViewSubtree,4],[1,2,3,4]}, + {[snmpTrapEnterprise, 0], ?ericsson}]). + + +%% Req. SA-MIB, OLD-SNMPEA-MIB +sa_errs_bad_value() -> + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + s([{NewKeyc3, 2}, + {[sa, [2,0]], 5}, % badValue (i is_set_ok) + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}]), + ?line expect(1, badValue, 2, any), + s([{NewKeyc3, 2}, + {[sa, [2,0]], 6}, % wrongValue (i is_set_ok) + {NewKeyc5, ?createAndGo}, + {NewKeyc4, 2}]), + ?line expect(1, ?v1_2(badValue, wrongValue), 2, any), + g([NewKeyc4]), + ?line ?v1_2(expect(2, noSuchName, 1, any), + expect(2, [{NewKeyc4, noSuchInstance}])). + +%% Req. SA-MIB, OLD-SNMPEA-MIB +sa_errs_gen_err() -> + NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], + NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], + NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], + s([{NewKeyc3, 2},{NewKeyc4, 2}, + {NewKeyc5, ?createAndGo}, {[sa, [3,0]], 5}]), + ?line expect(1, genErr, 4, any), +% The row might have been added; we don't know. +% (as a matter of fact we do - it is added, because the agent +% first sets its own vars, and then th SAs. Lets destroy it. + s([{NewKeyc5, ?destroy}]), + ?line expect(2, [{NewKeyc5, ?destroy}]). + +%% Req. SA-MIB, OLD-SNMPEA-MIB +sa_too_big() -> + g([[sa, [4,0]]]), + ?line expect(1, tooBig). + +%% Req. Klas1, system group, snmp group (v1/v2) +next_across_sa() -> + gn([[sysDescr],[klas1,5]]), + ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, + {[snmpInPkts, 0], any}]). + +%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]). -> noError +%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]). -> {badValue, 2} +%% snmp_test_mgr:s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]). -> {genErr, 1} +%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]). -> {genErr, 1} +%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]). -> {genErr, 1} +%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]). -> {genErr, 2} +%% Req. Klas3, Klas4 +undo_test() -> + s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), + ?line expect(1, [{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), + s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]), + ?line expect(2, ?v1_2(badValue, inconsistentValue), 2, any), + s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]), + ?line expect(3, ?v1_2(genErr, undoFailed), 1, any), + s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]), + ?line expect(4, ?v1_2(genErr, commitFailed), 1, any), +% unfortunatly we don't know if we'll get undoFailed or commitFailed. +% it depends on which order the agent traverses the varbind list. +% s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]), +% ?line expect(5, ?v1_2(genErr, undoFailed), 1, any), + s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]), + ?line expect(6, genErr, 2, any). + +%% Req. Klas3, Klas4 +bad_return() -> + g([[fStatus4,4], + [fName4,4]]), + ?line expect(4, genErr, 2, any), + g([[fStatus4,5], + [fName4,5]]), + ?line expect(5, genErr, 1, any), + g([[fStatus4,6], + [fName4,6]]), + ?line expect(6, genErr, 2, any), + gn([[fStatus4,7], + [fName4,7]]), + ?line expect(7, genErr, 2, any), + gn([[fStatus4,8], + [fName4,8]]), + ?line expect(8, genErr, 1, any), + gn([[fStatus4,9], + [fName4,9]]), + ?line expect(9, genErr, 2, any). + + +%%%----------------------------------------------------------------- +%%% Test the implementation of standard mibs. +%%% We should *at least* try to GET all variables, just to make +%%% sure the instrumentation functions work. +%%% Note that many of the functions in the standard mib is +%%% already tested by the normal tests. +%%%----------------------------------------------------------------- + + + +%%----------------------------------------------------------------- +%% For this test, the agent is configured for v1. +%% o Test the counters and control objects in SNMP-STANDARD-MIB +%%----------------------------------------------------------------- +snmp_standard_mib(suite) -> []; +snmp_standard_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?DBG("snmp_standard_mib -> std_mib_init", []), + try_test(std_mib_init), + + ?DBG("snmp_standard_mib -> std_mib_a", []), + InBadVsns = try_test(std_mib_a), + put(vsn, v2), + ?DBG("snmp_standard_mib -> std_mib_read", []), + try_test(std_mib_read), + put(vsn, v1), + + ?DBG("snmp_standard_mib -> std_mib_b (~w)", [InBadVsns]), + Bad = try_test(std_mib_b, [InBadVsns]), + ?DBG("snmp_standard_mib -> std_mib_read (community: 'bad community')", []), + try_test(std_mib_read, [], [{community, "bad community"}]), + ?DBG("snmp_standard_mib -> std_mib_write (community: 'public')", []), + try_test(std_mib_write, [], [{community, "public"}]), + ?DBG("snmp_standard_mib -> std_mib_asn_err", []), + try_test(std_mib_asn_err), + ?DBG("snmp_standard_mib -> std_mib_c (~w)", [Bad]), + try_test(std_mib_c, [Bad]), + ?DBG("snmp_standard_mib -> std_mib_a", []), + try_test(standard_mib_a), + + ?DBG("snmp_standard_mib -> std_mib_finish", []), + try_test(std_mib_finish), + ?DBG("snmp_standard_mib -> std_mib_test_finish", []), + try_test(standard_mib_test_finish, [], [{community, "bad community"}]). + +%% Req. SNMP-STANDARD-MIB +standard_mib_a() -> + ?line [OutPkts] = get_req(2, [[snmpOutPkts,0]]), + ?line [OutPkts2] = get_req(3, [[snmpOutPkts,0]]), + ?line OutPkts2 = OutPkts + 1, + %% There are some more counters we could test here, but it's not that + %% important, since they are removed from SNMPv2-MIB. + ok. + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_init() -> + %% disable authentication failure traps. (otherwise w'd get many of + %% them - this is also a test to see that it works). + s([{[snmpEnableAuthenTraps,0], 2}]), + ?line expect(1, [{[snmpEnableAuthenTraps, 0], 2}]). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_finish() -> + %% enable again + s([{[snmpEnableAuthenTraps,0], 1}]), + ?line expect(1, [{[snmpEnableAuthenTraps, 0], 1}]). + +%% Req. SNMP-STANDARD-MIB +standard_mib_test_finish() -> + %% force a authenticationFailure + std_mib_write(), + %% check that we got a trap + ?line expect(2, trap, [1,2,3], 4, 0, []). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_read() -> + ?DBG("std_mib_read -> entry", []), + g([[sysUpTime,0]]), % try a bad ; msg dropped, no reply + ?DBG("std_mib_read -> await timeout (i.e. no reply)", []), + ?line expect(1, timeout). % make sure we don't get a trap! + + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_write() -> + ?DBG("std_mib_write -> entry", []), + s([{[sysLocation, 0], "new_value"}]). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_asn_err() -> + snmp_test_mgr:send_bytes([48,99,67,12,0,0,0,0,0,0,5]). + +%%----------------------------------------------------------------- +%% For this test, the agent is configured for v2 and v3. +%% o Test the counters and control objects in SNMPv2-MIB +%%----------------------------------------------------------------- +snmpv2_mib_2(suite) -> []; +snmpv2_mib_2(Config) when list(Config) -> + ?LOG("snmpv2_mib_2 -> start",[]), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?DBG("snmpv2_mib_2 -> standard mib init",[]), + try_test(std_mib_init), + + ?DBG("snmpv2_mib_2 -> get number of (so far) bad versions",[]), + InBadVsns = try_test(std_mib_a), + + ?DBG("snmpv2_mib_2 -> make a bad version read",[]), + put(vsn, v1), + try_test(std_mib_read), + + ?DBG("snmpv2_mib_2 -> bad version read",[]), + put(vsn, v2), + Bad = try_test(std_mib_b, [InBadVsns]), + + ?DBG("snmpv2_mib_2 -> read with bad community",[]), + try_test(std_mib_read, [], [{community, "bad community"}]), + + ?DBG("snmpv2_mib_2 -> write with public community",[]), + try_test(std_mib_write, [], [{community, "public"}]), + + ?DBG("snmpv2_mib_2 -> asn err",[]), + try_test(std_mib_asn_err), + + ?DBG("snmpv2_mib_2 -> check counters",[]), + try_test(std_mib_c, [Bad]), + + ?DBG("snmpv2_mib_2 -> get som counters",[]), + try_test(snmpv2_mib_a), + + ?DBG("snmpv2_mib_2 -> enable auth traps, and await some",[]), + try_test(std_mib_finish), + + ?DBG("snmpv2_mib_2 -> force auth failure, and await trap, " + "then disable auth traps",[]), + try_test(snmpv2_mib_test_finish, [], [{community, "bad community"}]), + + ?LOG("snmpv2_mib_2 -> done",[]). + +%% Req. SNMPv2-MIB +snmpv2_mib_3(suite) -> []; +snmpv2_mib_3(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + InBadVsns = try_test(std_mib_a), + put(vsn, v1), + try_test(std_mib_read), + put(vsn, v3), + _Bad = try_test(std_mib_b, [InBadVsns]), + try_test(snmpv2_mib_a), + + try_test(std_mib_finish). + +-define(authenticationFailure, [1,3,6,1,6,3,1,1,5,5]). + +%% Req. SNMPv2-MIB +snmpv2_mib_test_finish() -> + %% force a authenticationFailure + ?DBG("ma_v2_inform -> write to std mib",[]), + std_mib_write(), + + %% check that we got a trap + ?DBG("ma_v2_inform -> await trap",[]), + ?line expect(2, v2trap, [{[sysUpTime,0], any}, + {[snmpTrapOID,0], ?authenticationFailure}]), + + %% and the the inform + ?DBG("ma_v2_inform -> await inform",[]), + ?line expect(2, {inform,true}, [{[sysUpTime,0], any}, + {[snmpTrapOID,0],?authenticationFailure}]). + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_a() -> + ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), + ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), + ?line InPkts2 = InPkts + 1, + + ?line [InBadVsns] = get_req(4, [[snmpInBadVersions,0]]), + InBadVsns. + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_b(InBadVsns) -> + ?line [InBadVsns2] = get_req(1, [[snmpInBadVersions,0]]), + ?line InBadVsns2 = InBadVsns + 1, + ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), + ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), + ?line InPkts2 = InPkts + 1, + ?line [InBadCommunityNames, InBadCommunityUses, InASNErrs] = + get_req(4, [[snmpInBadCommunityNames,0], + [snmpInBadCommunityUses,0], + [snmpInASNParseErrs, 0]]), + {InBadCommunityNames, InBadCommunityUses, InASNErrs}. + +%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB +std_mib_c({InBadCommunityNames, InBadCommunityUses, InASNErrs}) -> + ?line [InBadCommunityNames2, InBadCommunityUses2, InASNErrs2] = + get_req(1, [[snmpInBadCommunityNames,0], + [snmpInBadCommunityUses,0], + [snmpInASNParseErrs, 0]]), + ?line InBadCommunityNames2 = InBadCommunityNames + 1, + ?line InBadCommunityUses2 = InBadCommunityUses + 1, + ?line InASNErrs2 = InASNErrs + 1. + +%% Req. SNMPv2-MIB +snmpv2_mib_a() -> + ?line [SetSerial] = get_req(2, [[snmpSetSerialNo,0]]), + s([{[snmpSetSerialNo,0], SetSerial}, {[sysLocation, 0], "val2"}]), + ?line expect(3, [{[snmpSetSerialNo,0], SetSerial}, + {[sysLocation, 0], "val2"}]), + s([{[sysLocation, 0], "val3"}, {[snmpSetSerialNo,0], SetSerial}]), + ?line expect(4, inconsistentValue, 2, + [{[sysLocation, 0], "val3"}, + {[snmpSetSerialNo,0], SetSerial}]), + ?line ["val2"] = get_req(5, [[sysLocation,0]]). + + +%%----------------------------------------------------------------- +%% o Bad community uses/name is tested already +%% in SNMPv2-MIB and STANDARD-MIB. +%% o Test add/deletion of rows. +%%----------------------------------------------------------------- +snmp_community_mib(suite) -> []; +snmp_community_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + try_test(snmp_community_mib), + ?line unload_master("SNMP-COMMUNITY-MIB"). + +snmp_community_mib_2(X) -> snmp_community_mib(X). + +%% Req. SNMP-COMMUNITY-MIB +snmp_community_mib() -> + ?INF("NOT YET IMPLEMENTED", []), + nyi. + +%%----------------------------------------------------------------- +%% o Test engine boots / time +%%----------------------------------------------------------------- +snmp_framework_mib(suite) -> []; +snmp_framework_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + try_test(snmp_framework_mib), + ?line unload_master("SNMP-FRAMEWORK-MIB"). + +snmp_framework_mib_2(X) -> snmp_framework_mib(X). + +snmp_framework_mib_3(suite) -> []; +snmp_framework_mib_3(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + try_test(snmp_framework_mib). + + +%% Req. SNMP-FRAMEWORK-MIB +snmp_framework_mib() -> + ?line ["agentEngine"] = get_req(1, [[snmpEngineID,0]]), + ?line [EngineTime] = get_req(2, [[snmpEngineTime,0]]), + sleep(5000), + ?line [EngineTime2] = get_req(3, [[snmpEngineTime,0]]), + if + EngineTime+7 < EngineTime2 -> + ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); + EngineTime+4 > EngineTime2 -> + ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); + true -> ok + end, + ?line case get_req(4, [[snmpEngineBoots,0]]) of + [Boots] when integer(Boots) -> ok; + Else -> ?FAIL(Else) + end, + ok. + +%%----------------------------------------------------------------- +%% o Test the counters +%%----------------------------------------------------------------- +snmp_mpd_mib_3(suite) -> []; +snmp_mpd_mib_3(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + UnknownPDUHs = try_test(snmp_mpd_mib_a), + try_test(snmp_mpd_mib_b, [], [{context_engine_id, "bad engine"}]), + try_test(snmp_mpd_mib_c, [UnknownPDUHs]). + + +%% Req. SNMP-MPD-MIB +snmp_mpd_mib_a() -> + ?line [UnknownSecs, InvalidMsgs] = + get_req(1, [[snmpUnknownSecurityModels,0], + [snmpInvalidMsgs,0]]), + Pdu = #pdu{type = 'get-request', + request_id = 23, + error_status = noError, + error_index = 0, + varbinds = []}, + SPdu = #scopedPdu{contextEngineID = "agentEngine", + contextName = "", + data = Pdu}, + ?line SPDUBytes = snmp_pdus:enc_scoped_pdu(SPdu), + V3Hdr1 = #v3_hdr{msgID = 21, + msgMaxSize = 484, + msgFlags = [7], + msgSecurityModel = 23, % bad sec model + msgSecurityParameters = []}, + V3Hdr2 = #v3_hdr{msgID = 21, + msgMaxSize = 484, + msgFlags = [6], % bad flag combination + msgSecurityModel = 3, + msgSecurityParameters = []}, + Message1 = #message{version = 'version-3', vsn_hdr = V3Hdr1, + data = SPDUBytes}, + Message2 = #message{version = 'version-3', vsn_hdr = V3Hdr2, + data = SPDUBytes}, + ?line MsgBytes1 = snmp_pdus:enc_message_only(Message1), + ?line MsgBytes2 = snmp_pdus:enc_message_only(Message2), + snmp_test_mgr:send_bytes(MsgBytes1), + snmp_test_mgr:send_bytes(MsgBytes2), + + ?line [UnknownSecs2, InvalidMsgs2, UnknownPDUHs] = + get_req(1, [[snmpUnknownSecurityModels,0], + [snmpInvalidMsgs,0], + [snmpUnknownPDUHandlers, 0]]), + ?line UnknownSecs2 = UnknownSecs + 1, + ?line InvalidMsgs2 = InvalidMsgs + 1, + UnknownPDUHs. + +-define(snmpUnknownPDUHandlers_instance, [1,3,6,1,6,3,11,2,1,3,0]). +snmp_mpd_mib_b() -> + g([[sysUpTime,0]]), + ?line expect(1, report, [{?snmpUnknownPDUHandlers_instance, any}]). + + +snmp_mpd_mib_c(UnknownPDUHs) -> + ?line [UnknownPDUHs2] = get_req(1, [[snmpUnknownPDUHandlers, 0]]), + ?line UnknownPDUHs2 = UnknownPDUHs + 1. + + +snmp_target_mib(suite) -> []; +snmp_target_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-TARGET-MIB"), + try_test(snmp_target_mib), + ?line unload_master("SNMP-TARGET-MIB"). + +snmp_target_mib_2(X) -> snmp_target_mib(X). + +snmp_target_mib_3(X) -> snmp_target_mib(X). + +snmp_target_mib() -> + ?INF("NOT YET IMPLEMENTED", []), + nyi. + +snmp_notification_mib(suite) -> []; +snmp_notification_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + try_test(snmp_notification_mib), + ?line unload_master("SNMP-NOTIFICATION-MIB"). + +snmp_notification_mib_2(X) -> snmp_notification_mib(X). + +snmp_notification_mib_3(X) -> snmp_notification_mib(X). + +snmp_notification_mib() -> + ?INF("NOT YET IMPLEMENTED", []), + nyi. + +%%----------------------------------------------------------------- +%% o add/delete views and try them +%% o try boundaries +%%----------------------------------------------------------------- +snmp_view_based_acm_mib(suite) -> []; +snmp_view_based_acm_mib(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + ?line load_master("Test2"), + snmp_view_based_acm_mib(), + ?line unload_master("Test2"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). + +snmp_view_based_acm_mib_2(X) -> snmp_view_based_acm_mib(X). + +snmp_view_based_acm_mib_3(X) -> snmp_view_based_acm_mib(X). + +snmp_view_based_acm_mib() -> + snmpa:verbosity(net_if,trace), + snmpa:verbosity(master_agent,trace), + ?LOG("start snmp_view_based_acm_mib test",[]), + %% The user "no-rights" is present in USM, and is mapped to security + %% name 'no-rights", which is not present in VACM. + %% So, we'll add rights for it, try them and delete them. + %% We'll give "no-rights" write access to tDescr.0 and read access + %% to tDescr2.0 + %% These are the options we'll use to the mgr + Opts = [{user, "no-rights"}, {community, "no-rights"}], + %% Find the valid secmodel, and one invalid secmodel. + {SecMod, InvSecMod} = + case get(vsn) of + v1 -> {?SEC_V1, ?SEC_V2C}; + v2 -> {?SEC_V2C, ?SEC_USM}; + v3 -> {?SEC_USM, ?SEC_V1} + end, + ?DBG("assign rights for 'no-rights'",[]), + ?line try_test(use_no_rights, [], Opts), + + %% Now, add a mapping from "no-rights" -> "no-rights-group" + GRow1Status = [vacmSecurityToGroupStatus,[SecMod, 9,"no-rights"]], + GRow1 = + [{[vacmGroupName, [SecMod, 9,"no-rights"]], "no-rights-group"}, + {GRow1Status, ?createAndGo}], + ?DBG("set '~p'",[GRow1]), + ?line try_test(do_set, [GRow1]), + + ?DBG("assign rights for 'no-rights'",[]), + ?line try_test(use_no_rights, [], Opts), + + %% Create a mapping for another sec model, and make sure it dosn't + %% give us access + GRow2Status = [vacmSecurityToGroupStatus,[InvSecMod, 9,"no-rights"]], + GRow2 = [{[vacmGroupName, [InvSecMod, 9, "no-rights"]], "initial"}, + {GRow2Status, ?createAndGo}], + + ?DBG("set '~p'",[GRow2]), + ?line try_test(do_set, [GRow2]), + + ?DBG("assign rights for 'no-rights'",[]), + ?line try_test(use_no_rights, [], Opts), + + %% Delete that row + ?line try_test(del_row, [GRow2Status]), + + RVName = "rv_name", + WVName = "wv_name", + + %% Access row + ARow1Idx = [15 | "no-rights-group"] ++ [0, ?SEC_ANY, 1], + ARow1Status = [vacmAccessStatus, ARow1Idx], + ARow1 = [{[vacmAccessContextMatch, ARow1Idx], 1}, + {[vacmAccessReadViewName, ARow1Idx], RVName}, + {[vacmAccessWriteViewName, ARow1Idx], WVName}, + {ARow1Status, ?createAndGo}], + + %% This access row would give acces, if InvSecMod was valid. + ARow2Idx = [15 | "no-rights-group"] ++ [0, InvSecMod, 1], + ARow2Status = [vacmAccessStatus, ARow2Idx], + ARow2 = [{[vacmAccessContextMatch, ARow2Idx], 1}, + {[vacmAccessReadViewName, ARow2Idx], "internet"}, + {[vacmAccessWriteViewName, ARow2Idx], "internet"}, + {ARow2Status, ?createAndGo}], + + ?line try_test(do_set, [ARow2]), + + ?line try_test(use_no_rights, [], Opts), + + %% Delete that row + ?line try_test(del_row, [ARow2Status]), + + + %% Add valid row + ?line try_test(do_set, [ARow1]), + + ?line try_test(use_no_rights, [], Opts), + + %% Create the view family + VRow1Idx = mk_ln(RVName) ++ mk_ln(?xDescr), % object access + VRow2Idx = mk_ln(RVName) ++ mk_ln(?xDescr2 ++ [0]), % instance access + VRow3Idx = mk_ln(WVName) ++ mk_ln(?xDescr), % object access + VRow4Idx = mk_ln(WVName) ++ mk_ln(?xDescr ++ [0]), % instance access + VRow1Status = [vacmViewTreeFamilyStatus, VRow1Idx], + VRow2Status = [vacmViewTreeFamilyStatus, VRow2Idx], + VRow3Status = [vacmViewTreeFamilyStatus, VRow3Idx], + VRow4Status = [vacmViewTreeFamilyStatus, VRow4Idx], + + ?line try_test(add_row, [VRow1Status]), + ?line try_test(add_row, [VRow2Status]), + ?line try_test(add_row, [VRow3Status]), + + %% We're supposed to have access now... + ?line try_test(use_rights, [], Opts), + + %% Change Row3 to Row4 + ?line try_test(del_row, [VRow3Status]), + ?line try_test(add_row, [VRow4Status]), + + %% We should still have access... + ?line try_test(use_rights, [], Opts), + + %% Delete rows + ?line try_test(del_row, [GRow1Status]), + + ?line try_test(use_no_rights, [], Opts), + + %% Delete rest of rows + ?line try_test(del_row, [ARow1Status]), + ?line try_test(del_row, [VRow1Status]), + ?line try_test(del_row, [VRow2Status]), + ?line try_test(del_row, [VRow4Status]), + + ?line try_test(use_no_rights, [], Opts), + snmpa:verbosity(master_agent,log). + +do_set(Row) -> + s(Row), + expect(1, Row). + +add_row(RowStatus) -> + s([{RowStatus, ?createAndGo}]), + expect(1, [{RowStatus, ?createAndGo}]). + +del_row(RowStatus) -> + s([{RowStatus, ?destroy}]), + expect(1, [{RowStatus, ?destroy}]). + + + +use_no_rights() -> + g([[xDescr,0]]), + ?v1_2_3(expect(11, noSuchName, 1, any), + expect(12, [{[xDescr,0], noSuchObject}]), + expect(13, authorizationError, 1, any)), + g([[xDescr2,0]]), + ?v1_2_3(expect(21, noSuchName, 1, any), + expect(22, [{[xDescr2,0], noSuchObject}]), + expect(23, authorizationError, 1, any)), + gn([[xDescr]]), + ?v1_2_3(expect(31, noSuchName, 1, any), + expect(32, [{[xDescr], endOfMibView}]), + expect(33, authorizationError, 1, any)), + s([{[xDescr,0], "tryit"}]), + ?v1_2_3(expect(41, noSuchName, 1, any), + expect(42, noAccess, 1, any), + expect(43, authorizationError, 1, any)). + + +use_rights() -> + g([[xDescr,0]]), + expect(1, [{[xDescr,0], any}]), + g([[xDescr2,0]]), + expect(2, [{[xDescr2,0], any}]), + s([{[xDescr,0], "tryit"}]), + expect(3, noError, 0, any), + g([[xDescr,0]]), + expect(4, [{[xDescr,0], "tryit"}]). + +mk_ln(X) -> + [length(X) | X]. + +%%----------------------------------------------------------------- +%% o add/delete users and try them +%% o test all secLevels +%% o test all combinations of protocols +%% o try bad ops; check counters +%%----------------------------------------------------------------- +snmp_user_based_sm_mib_3(suite) -> []; +snmp_user_based_sm_mib_3(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + _AgentDir = ?config(agent_dir, Config), + ?line load_master_std("SNMP-USER-BASED-SM-MIB"), + + %% The newUser used here already has VACM access. + + %% Add a new user in the simplest way; just createAndGo + try_test(v3_sync, [[{usm_add_user1, []}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + %% Try to use the new user + ?line load_master("Test2"), + try_test(v3_sync, [[{usm_use_user, []}]], + [{sec_level, authPriv}, {user, "newUser"}]), + ?line unload_master("Test2"), + + ShaKey1 = snmp:passwd2localized_key(sha, "new sha password", "agentEngine"), + DesKey1 = lists:sublist(ShaKey1, 16), + + %% Change the new user's keys - 1 + try_test(v3_sync, [[{usm_key_change1, [ShaKey1, DesKey1]}]], + [{sec_level, authPriv}, {user, "newUser"}]), + + %% Try to use the new keys + MgrDir = ?config(mgr_dir, Config), + ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), + ?line load_master("Test2"), + try_test(v3_sync, [[{usm_use_user, []}]], + [{sec_level, authPriv}, {user, "newUser"}]), + ?line unload_master("Test2"), + + ShaKey2 = snmp:passwd2localized_key(sha, "newer password", "agentEngine"), + DesKey2 = lists:sublist(ShaKey2, 16), + + %% Change the new user's keys - 2 + ?line try_test(v3_sync, + [[{usm_key_change2, [ShaKey1, DesKey1, ShaKey2, DesKey2]}]], + [{sec_level, authPriv}, {user, "newUser"}]), + + %% Try to use the new keys + reset_usm_mgr(MgrDir), + ?line rewrite_usm_mgr(MgrDir, ShaKey2, DesKey2), + ?line load_master("Test2"), + ?line try_test(v3_sync, [[{usm_use_user, []}]], + [{sec_level, authPriv}, {user, "newUser"}]), + ?line unload_master("Test2"), + reset_usm_mgr(MgrDir), + + %% Change the new user's keys - 3 + ?line try_test(v3_sync, + [[{usm_key_change3, [ShaKey2, DesKey2, ShaKey1, DesKey1]}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + %% Try to use the new keys + ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), + ?line load_master("Test2"), + try_test(v3_sync, [[{usm_use_user, []}]], + [{sec_level, authPriv}, {user, "newUser"}]), + ?line unload_master("Test2"), + reset_usm_mgr(MgrDir), + + %% Try some read requests + ?line try_test(v3_sync, [[{usm_read, []}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + %% Delete the new user + ?line try_test(v3_sync, [[{usm_del_user, []}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + %% Try some bad requests + ?line try_test(v3_sync, [[{usm_bad, []}]], + [{sec_level, authPriv}, {user, "privDES"}]), + + ?line unload_master("SNMP-USER-BASED-SM-MIB"). + +-define(usmUserSecurityName, [1,3,6,1,6,3,15,1,2,2,1,3]). + +usm_add_user1() -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + RowPointer = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], + Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer}, + {[usmUserStatus, NewRowIndex], ?createAndGo}], + ?line s(Vbs1), + ?line expect(1, Vbs1), + ok. + +usm_use_user() -> + v2_proc(). + + +%% Change own public keys +usm_key_change1(ShaKey, DesKey) -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + "passwd_shaxxxxxxxxxx", + ShaKey), + DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + "passwd_desxxxxxx", + DesKey), + Vbs1 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, + {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], + s(Vbs1), + ?line expect(1, Vbs1). + +%% Change own private keys +usm_key_change2(OldShaKey, OldDesKey, ShaKey, DesKey) -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + OldShaKey, + ShaKey), + DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + OldDesKey, + DesKey), + Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}, + {[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], + s(Vbs1), + ?line expect(1, Vbs1). + +%% Change other's public keys +usm_key_change3(OldShaKey, OldDesKey, ShaKey, DesKey) -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + OldShaKey, + ShaKey), + DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, + OldDesKey, + DesKey), + Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}], + s(Vbs1), + ?line expect(1, noAccess, 1, any), + Vbs2 = [{[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], + s(Vbs2), + ?line expect(2, noAccess, 1, any), + + + Vbs3 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, + {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], + s(Vbs3), + ?line expect(1, Vbs3). + +usm_read() -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + ?line g([[usmUserSecurityName, NewRowIndex], + [usmUserCloneFrom, NewRowIndex], + [usmUserAuthKeyChange, NewRowIndex], + [usmUserOwnAuthKeyChange, NewRowIndex], + [usmUserPrivKeyChange, NewRowIndex], + [usmUserOwnPrivKeyChange, NewRowIndex]]), + ?line expect(1, + [{[usmUserSecurityName, NewRowIndex], "newUser"}, + {[usmUserCloneFrom, NewRowIndex], [0,0]}, + {[usmUserAuthKeyChange, NewRowIndex], ""}, + {[usmUserOwnAuthKeyChange, NewRowIndex], ""}, + {[usmUserPrivKeyChange, NewRowIndex], ""}, + {[usmUserOwnPrivKeyChange, NewRowIndex], ""}]), + ok. + + + +usm_del_user() -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + Vbs1 = [{[usmUserStatus, NewRowIndex], ?destroy}], + ?line s(Vbs1), + ?line expect(1, Vbs1), + ok. + +-define(usmUserCloneFrom, [1,3,6,1,6,3,15,1,2,2,1,4]). + +-define(usmNoAuthProtocol, [1,3,6,1,6,3,10,1,1,1]). + +-define(usmHMACMD5AuthProtocol, [1,3,6,1,6,3,10,1,1,2]). + +-define(usmHMACSHAAuthProtocol, [1,3,6,1,6,3,10,1,1,3]). + +-define(usmNoPrivProtocol, [1,3,6,1,6,3,10,1,2,1]). + +-define(usmDESPrivProtocol, [1,3,6,1,6,3,10,1,2,2]). + +usm_bad() -> + NewRowIndex = [11,"agentEngine", 7, "newUser"], + RowPointer1 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDOS"], + Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer1}, + {[usmUserStatus, NewRowIndex], ?createAndGo}], + ?line s(Vbs1), + ?line expect(1, inconsistentName, 1, any), + + RowPointer2 = ?usmUserCloneFrom ++ [11|"agentEngine"] ++ [7|"privDES"], + Vbs2 = [{[usmUserCloneFrom, NewRowIndex], RowPointer2}, + {[usmUserStatus, NewRowIndex], ?createAndGo}], + ?line s(Vbs2), + ?line expect(2, wrongValue, 1, any), + + RowPointer3 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], + Vbs3 = [{[usmUserCloneFrom, NewRowIndex], RowPointer3}, + {[usmUserStatus, NewRowIndex], ?createAndGo}], + ?line s(Vbs3), + ?line expect(3, Vbs3), + ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmNoAuthProtocol}]), + ?line expect(4, inconsistentValue, 1, any), + ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmHMACMD5AuthProtocol}]), + ?line expect(5, inconsistentValue, 1, any), + ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmDESPrivProtocol}]), + ?line expect(6, wrongValue, 1, any), + ?line s([{[usmUserPrivProtocol, NewRowIndex], ?usmHMACSHAAuthProtocol}]), + ?line expect(7, wrongValue, 1, any), + + Vbs4 = [{[usmUserStatus, NewRowIndex], ?destroy}], + ?line s(Vbs4), + ?line expect(1, Vbs4), + + ok. + + +%%----------------------------------------------------------------- +%% Loop through entire MIB, to make sure that all instrum. funcs +%% works. +%% Load all std mibs that are not loaded by default. +%%----------------------------------------------------------------- +loop_mib(suite) -> []; +loop_mib(Config) when list(Config) -> + ?LOG("loop_mib -> initiate case",[]), + %% snmpa:verbosity(master_agent,debug), + %% snmpa:verbosity(mib_server,info), + {SaNode, MgrNode, MibDir} = init_case(Config), + ?DBG("loop_mib -> ~n" + "\tSaNode: ~p~n" + "\tMgrNode: ~p~n" + "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), + ?DBG("loop_mib -> load mib SNMP-COMMUNITY-MIB",[]), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?DBG("loop_mib -> load mib SNMP-MPD-MIB",[]), + ?line load_master_std("SNMP-MPD-MIB"), + ?DBG("loop_mib -> load mib SNMP-TARGET-MIB",[]), + ?line load_master_std("SNMP-TARGET-MIB"), + ?DBG("loop_mib -> load mib SNMP-NOTIFICATION-MIB",[]), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?DBG("loop_mib -> load mib SNMP-FRAMEWORK-MIB",[]), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?DBG("loop_mib -> load mib SNMP-VIEW-BASED-ACM-MIB",[]), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + ?DBG("loop_mib -> try",[]), + try_test(loop_mib_1), + ?DBG("loop_mib -> unload mib SNMP-COMMUNITY-MIB",[]), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?DBG("loop_mib -> unload mib SNMP-MPD-MIB",[]), + ?line unload_master("SNMP-MPD-MIB"), + ?DBG("loop_mib -> unload mib SNMP-TARGET-MIB",[]), + ?line unload_master("SNMP-TARGET-MIB"), + ?DBG("loop_mib -> unload mib SNMP-NOTIFICATION-MIB",[]), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?DBG("loop_mib -> unload mib SNMP-FRAMEWORK-MIB",[]), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?DBG("loop_mib -> unload mib SNMP-VIEW-BASED-ACM-MIB",[]), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + %% snmpa:verbosity(master_agent,log), + %% snmpa:verbosity(mib_server,silence), + ?LOG("loop_mib -> done",[]). + + +loop_mib_2(suite) -> []; +loop_mib_2(Config) when list(Config) -> + ?LOG("loop_mib_2 -> initiate case",[]), + {SaNode, MgrNode, MibDir} = init_case(Config), + ?DBG("loop_mib_2 -> ~n" + "\tSaNode: ~p~n" + "\tMgrNode: ~p~n" + "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), + ?DBG("loop_mib_2 -> load mibs",[]), + ?line load_master_std("SNMP-COMMUNITY-MIB"), + ?line load_master_std("SNMP-MPD-MIB"), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-FRAMEWORK-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + try_test(loop_mib_2), + ?DBG("loop_mib_2 -> unload mibs",[]), + ?line unload_master("SNMP-COMMUNITY-MIB"), + ?line unload_master("SNMP-MPD-MIB"), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-FRAMEWORK-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + ?LOG("loop_mib_2 -> done",[]). + + +loop_mib_3(suite) -> []; +loop_mib_3(Config) when list(Config) -> + ?LOG("loop_mib_3 -> initiate case",[]), + {SaNode, MgrNode, MibDir} = init_case(Config), + ?DBG("loop_mib_3 -> ~n" + "\tSaNode: ~p~n" + "\tMgrNode: ~p~n" + "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), + ?DBG("loop_mib_3 -> load mibs",[]), + ?line load_master_std("SNMP-TARGET-MIB"), + ?line load_master_std("SNMP-NOTIFICATION-MIB"), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + ?line load_master_std("SNMP-USER-BASED-SM-MIB"), + try_test(loop_mib_2), + ?DBG("loop_mib_3 -> unload mibs",[]), + ?line unload_master("SNMP-TARGET-MIB"), + ?line unload_master("SNMP-NOTIFICATION-MIB"), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), + ?line unload_master("SNMP-USER-BASED-SM-MIB"), + ?LOG("loop_mib_3 -> done",[]). + + +%% Req. As many mibs all possible +loop_mib_1() -> + ?DBG("loop_mib_1 -> entry",[]), + N = loop_it_1([1,1], 0), + io:format(user, "found ~w varibles\n", [N]), + ?line N = if N < 100 -> 100; + true -> N + end. + + +loop_it_1(Oid, N) -> + ?DBG("loop_it_1 -> entry with~n" + "\tOid: ~p~n" + "\tN: ~p",[Oid,N]), + case get_next_req([Oid]) of + #pdu{type='get-response', error_status=noError, error_index=0, + varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> + ?DBG("loop_it_1 -> ~n" + "\tNOid: ~p~n" + "\tValue: ~p",[NOid,Value]), + ?line [Value2] = get_req(1, [NOid]), % must not be same + ?DBG("loop_it_1 -> ~n" + "\tValue2: ~p",[Value2]), + loop_it_1(NOid, N+1); + #pdu{type='get-response', error_status=noSuchName, error_index=1, + varbinds=[_]} -> + ?DBG("loop_it_1 -> done",[]), + N; + + #pdu{type = Type, error_status = Err, error_index = Idx, + varbinds = Vbs} -> + exit({unexpected_pdu, ?LINE, Type, Err, Idx, Vbs}) + end. + +%% Req. As many mibs all possible +loop_mib_2() -> + ?DBG("loop_mib_1 -> entry",[]), + N = loop_it_2([1,1], 0), + io:format(user, "found ~w varibles\n", [N]), + ?line N = if N < 100 -> 100; + true -> N + end. + + +loop_it_2(Oid, N) -> + ?DBG("loop_it_2 -> entry with~n" + "\tOid: ~p~n" + "\tN: ~p",[Oid,N]), + case get_next_req([Oid]) of + #pdu{type='get-response', error_status=noError, error_index=0, + varbinds=[#varbind{oid = NOid, value = endOfMibView}]} -> + ?DBG("loop_it_2 -> ~n" + "\tNOid: ~p",[NOid]), + N; + #pdu{type='get-response', error_status=noError, error_index=0, + varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> + ?DBG("loop_it_2 -> ~n" + "\tNOid: ~p~n" + "\tValue: ~p",[NOid,Value]), + ?line [Value2] = get_req(1, [NOid]), % must not be same + ?DBG("loop_it_2 -> ~n" + "\tValue2: ~p",[Value2]), + loop_it_2(NOid, N+1) + end. + + +%%%----------------------------------------------------------------- +%%% Testing of reported bugs and other tickets. +%%%----------------------------------------------------------------- + + + + + +%% These are (ticket) test cases where the initiation has to be done +%% individually. + +%%----------------------------------------------------------------- +%% Ticket: OTP-1128 +%% Slogan: Bug in handling of createAndWait set-requests. +%%----------------------------------------------------------------- +otp_1128(suite) -> []; +otp_1128(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(otp_1128), + ?line unload_master("OLD-SNMPEA-MIB"). + +otp_1128_2(X) -> otp_1128(X). + +otp_1128_3(X) -> otp_1128(X). + +otp_1128() -> + io:format("Testing bug reported in ticket OTP-1128...~n"), + + NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], + NewKeyc4 = [intCommunityAccess,get(mip),is("test")], + NewKeyc5 = [intCommunityStatus,get(mip),is("test")], + + s([{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), + ?line expect(28, [{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), + g([NewKeyc5]), + ?line expect(29, [{NewKeyc5, ?notReady}]), + s([{NewKeyc5, ?active}, {NewKeyc3, 2}]), + ?line expect(30, [{NewKeyc5, ?active}, {NewKeyc3, 2}]), + g([NewKeyc5]), + ?line expect(31, [{NewKeyc5, ?active}]), + s([{NewKeyc5, ?destroy}]), + ?line expect(32, [{NewKeyc5, ?destroy}]). + +%%----------------------------------------------------------------- +%% Ticket: OTP-1129, OTP-1169 +%% Slogan: snmpa:int_to_enum crashes on bad oids +%%----------------------------------------------------------------- +otp_1129(suite) -> []; +otp_1129(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas3"), + try_test(otp_1129_i, [node()]), + ?line unload_master("Klas3"). + +otp_1129_2(X) -> otp_1129(X). + +otp_1129_3(X) -> otp_1129(X). + +otp_1129_i(MaNode) -> + io:format("Testing bug reported in ticket OTP-1129...~n"), + false = rpc:call(MaNode, snmp, int_to_enum, [iso, 1]), + false = rpc:call(MaNode, snmp, int_to_enum, [isox, 1]). + +%%----------------------------------------------------------------- +%% Ticket: OTP-1131 +%% Slogan: Agent crashes / erlang node halts if RowIndex in a +%% setrequest is of bad type, e.g. an INDEX {INTEGER}, +%% and RowIdenx [3,2]. +%%----------------------------------------------------------------- +otp_1131(suite) -> []; +otp_1131(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas1"), + try_test(otp_1131), + ?line unload_master("Klas1"). + +otp_1131_2(X) -> otp_1131(X). + +otp_1131_3(X) -> otp_1131(X). + +otp_1131() -> + io:format("Testing bug reported in ticket OTP-1131...~n"), + s([{[friendsEntry, [2, 3, 1]], s, "kompis3"}, + {[friendsEntry, [3, 3, 1]], i, ?createAndGo}]), + ?line expect(1, ?v1_2(noSuchName, noCreation), 2, any). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1162 +%% Slogan: snmp_agent can't handle wrongValue from instrum.func +%%----------------------------------------------------------------- +otp_1162(suite) -> []; +otp_1162(Config) when list(Config) -> + {SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), + try_test(otp_1162), + stop_subagent(SA). + +otp_1162_2(X) -> otp_1162(X). + +otp_1162_3(X) -> otp_1162(X). + +otp_1162() -> + s([{[sa, [2,0]], 6}]), % wrongValue (i is_set_ok) + ?line expect(1, ?v1_2(badValue, wrongValue), 1, any). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1222 +%% Slogan: snmp agent crash if faulty index is returned from instrum +%%----------------------------------------------------------------- +otp_1222(suite) -> []; +otp_1222(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas3"), + ?line load_master("Klas4"), + try_test(otp_1222), + ?line unload_master("Klas3"), + ?line unload_master("Klas4"). + +otp_1222_2(X) -> otp_1222(X). + +otp_1222_3(X) -> otp_1222(X). + +otp_1222() -> + io:format("Testing bug reported in ticket OTP-1222...~n"), + s([{[fStatus4,1], 4}, {[fName4,1], 1}]), + ?line expect(1, genErr, 0, any), + s([{[fStatus4,2], 4}, {[fName4,2], 1}]), + ?line expect(2, genErr, 0, any). + +%%----------------------------------------------------------------- +%% Ticket: OTP-1298 +%% Slogan: Negative INTEGER values are treated as positive. +%%----------------------------------------------------------------- +otp_1298(suite) -> []; +otp_1298(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas2"), + try_test(otp_1298), + ?line unload_master("Klas2"). + +otp_1298_2(X) -> otp_1298(X). + +otp_1298_3(X) -> otp_1298(X). + +otp_1298() -> + io:format("Testing bug reported in ticket OTP-1298...~n"), + s([{[fint,0], -1}]), + ?line expect(1298, [{[fint,0], -1}]). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1331 +%% Slogan: snmp_generic should return noError when deleting non-ex row +%%----------------------------------------------------------------- +otp_1331(suite) -> []; +otp_1331(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(otp_1331), + ?line unload_master("OLD-SNMPEA-MIB"). + +otp_1331_2(X) -> otp_1331(X). + +otp_1331_3(X) -> otp_1331(X). + +otp_1331() -> + NewKeyc5 = [intCommunityStatus,[127,32,0,0],is("test")], + s([{NewKeyc5, ?destroy}]), + ?line expect(1, [{NewKeyc5, ?destroy}]). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1338 +%% Slogan: snmp bug in initialisation of default values for mnesia tabs +%%----------------------------------------------------------------- +otp_1338(suite) -> []; +otp_1338(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas2"), + try_test(otp_1338), + ?line unload_master("Klas2"). + +otp_1338_2(X) -> otp_1338(X). + +otp_1338_3(X) -> otp_1338(X). + +otp_1338() -> + s([{[kStatus2, 7], i, ?createAndGo}]), + ?line expect(1, [{[kStatus2, 7], ?createAndGo}]), + g([[kName2, 7]]), + ?line expect(2, [{[kName2, 7], "JJJ"}]). + +%%----------------------------------------------------------------- +%% Ticket: OTP-1342 +%% Slogan: default impl of snmp table can't handle bad index access, +%% Set when INDEX is read-write gets into an infinite loop! +%%----------------------------------------------------------------- +otp_1342(suite) -> []; +otp_1342(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Klas4"), + try_test(otp_1342), + ?line unload_master("Klas4"). + +otp_1342_2(X) -> otp_1342(X). + +otp_1342_3(X) -> otp_1342(X). + +otp_1342() -> + s([{[fIndex5, 1], i, 1}, + {[fName5, 1], i, 3}, + {[fStatus5, 1], i, ?createAndGo}]), + ?line expect(1, ?v1_2(noSuchName, noCreation), 3, any). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-1366 +%% Slogan: snmp traps not sent to all managers +%% Note: NYI! We need a way to tell the test server that we need +%% mgrs on two different machines. +%%----------------------------------------------------------------- +otp_1366(suite) -> []; +otp_1366(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(otp_1366), + ?line unload_master("OLD-SNMPEA-MIB"). + +otp_1366_2(X) -> otp_1366(X). + +otp_1366_3(X) -> otp_1366(X). + +otp_1366() -> + ?INF("NOT YET IMPLEMENTED", []), + 'NYI'. + +%%----------------------------------------------------------------- +%% Ticket: OTP-2776 +%% Slogan: snmp:validate_date_and_time() fails when time is 00:00 +%%----------------------------------------------------------------- +otp_2776(suite) -> []; +otp_2776(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + try_test(otp_2776). + +otp_2776_2(X) -> otp_2776(X). + +otp_2776_3(X) -> otp_2776(X). + +otp_2776() -> + io:format("Testing bug reported in ticket OTP-2776...~n"), + + Dt01_valid = [19,98,9,1,1,0,23,0,43,0,0], + Dt02_valid = [19,98,9,1,0,0,0,0,43,0,0], % This is what is fixed: 00:00 + Dt03_valid = [19,98,2,28,1,0,23,0,43,0,0], + Dt04_invalid = [19,98,2,29,1,0,23,0,43,0,0], + Dt05_valid = [19,96,2,29,1,0,23,0,43,0,0], + Dt06_valid = [20,0,2,29,1,0,23,0,43,0,0], + Dt07_invalid = [19,96,2,30,1,0,23,0,43,0,0], % This is also fixed: 30/2 + Dt08_valid = [19,98,4,30,1,0,23,0,43,0,0], + Dt09_invalid = [19,98,4,31,1,0,23,0,43,0,0], % This is also fixed: 31/4 + Dt10_invalid = [], + Dt11_invalid = [kalle,hobbe], + L = [{ 1, true, Dt01_valid}, + { 2, true, Dt02_valid}, + { 3, true, Dt03_valid}, + { 4, false, Dt04_invalid}, + { 5, true, Dt05_valid}, + { 6, true, Dt06_valid}, + { 7, false, Dt07_invalid}, + { 8, true, Dt08_valid}, + { 9, false, Dt09_invalid}, + {10, false, Dt10_invalid}, + {11, false, Dt11_invalid}], + + ?line ok = validate_dat(L). + + +validate_dat(L) -> validate_dat(L,[]). + +validate_dat([],V) -> + Fun = fun({_,X}) -> case X of + ok -> false; + _ -> true + end + end, + validate_dat1( lists:reverse( lists:filter(Fun,V) ) ); +validate_dat([{Id,E,Dat}|T],V) -> + validate_dat(T,[validate_dat2(Id,E,Dat) | V]). + +validate_dat1([]) -> ok; +validate_dat1(L) -> {error,L}. + +validate_dat2(Id, E, Dat) -> + Res = case {E,snmp:validate_date_and_time(Dat)} of + {E,E} -> ok; + {E,A} -> {E,A} + end, + {Id, Res}. + + +%%----------------------------------------------------------------- +%% Ticket: OTP-2979 +%% Slogan: get-next on more than 1 column in an empty table +%% returns bad response. +%%----------------------------------------------------------------- +otp_2979(suite) -> []; +otp_2979(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master("Test1"), + ?line init_old(), + try_test(otp_2979), + ?line unload_master("Test1"). + +otp_2979_2(X) -> otp_2979(X). + +otp_2979_3(X) -> otp_2979(X). + +otp_2979() -> + gn([[sparseDescr], [sparseStatus]]), + ?line expect(1, [{[sparseStr,0], "slut"}, + {[sparseStr,0], "slut"}]). + +%%----------------------------------------------------------------- +%% Ticket: OTP-3187 +%% Slogan: get-next on vacmAccessTable for colums > 5 returns +%% endOfTable - should return value. +%%----------------------------------------------------------------- +otp_3187(suite) -> []; +otp_3187(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), + otp_3187(), + ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). + +otp_3187_2(X) -> otp_3187(X). + +otp_3187_3(X) -> otp_3187(X). + +otp_3187() -> + ?line Elements = + snmp_view_based_acm_mib:vacmAccessTable(get_next,[],[4,5,6]), + lists:foreach(fun(E) -> + ?line if E == endOfTable -> + ?FAIL(endOfTable); + true -> ok + end + end, Elements). + +%%----------------------------------------------------------------- +%% Ticket: OTP-3542 +%% Slogan: +%%----------------------------------------------------------------- +otp_3542(suite) -> []; +otp_3542(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + try_test(otp_3542). + +otp_3542() -> + io:format("SNMP v3 discovery...~n"), + ?line Res = snmp_test_mgr:d(), + io:format("SNMP v3 discovery result: ~p~n",[Res]). + + +%%----------------------------------------------------------------- +%% Ticket: OTP-3725 +%% Slogan: Slow response time on snmpa:int_to_enum +%%----------------------------------------------------------------- +otp_3725(suite) -> []; +otp_3725(Config) when list(Config) -> + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + + ?line load_master("OLD-SNMPEA-MIB"), + ?line init_old(), + try_test(otp_3725_test, [node()]), + ?line unload_master("OLD-SNMPEA-MIB"). + +%% Req. OLD-SNMPEA-MIB +otp_3725_test(MaNode) -> + io:format("Testing feature requested in ticket OTP-3725...~n"), + ?line rpc:call(MaNode,snmpa,verbosity,[symbolic_store,trace]), + ?line Db = rpc:call(MaNode,snmp,get_symbolic_store_db,[]), + ?DBG("otp_3725_test -> Db = ~p",[Db]), + + ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, + [Db, intAgentIpAddress]), + ?DBG("otp_3725_test -> name_to_oid for ~p: ~p",[intAgentIpAddress,OID]), + ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, oid_to_name, + [Db,OID]), + ?DBG("otp_3725_test -> oid_to_name for ~p: ~p",[OID,intAgentIpAddress]), + ?line false = rpc:call(MaNode, snmp, name_to_oid, [Db, intAgentIpAddres]), + ?line false = rpc:call(MaNode, snmp, oid_to_name, + [Db, [1,5,32,3,54,3,3,34,4]]), + ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, + [Db, intViewType, excluded]), + ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, + [Db, intViewType, 2]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, intViewType, exclude]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, intAgentIpAddress, exclude]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, intAgentIpAddre, exclude]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, intViewType, 3]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, + [Db, intAgentIpAddress, 2]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, + [Db, intAgentIpAddre, 2]), + ?line {value, active} = rpc:call(MaNode, snmp, int_to_enum, + [Db, 'RowStatus', ?active]), + ?line {value, ?destroy} = rpc:call(MaNode, snmp, enum_to_int, + [Db, 'RowStatus', destroy]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, 'RowStatus', xxxdestroy]), + ?line false = rpc:call(MaNode, snmp, enum_to_int, + [Db, 'xxRowStatus', destroy]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'RowStatus', 25]), + ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'xxRowStatus', 1]), + ok. + + +%%----------------------------------------------------------------- +%% Ticket: OTP-4394 +%% Slogan: Target mib tag list check invalid +%%----------------------------------------------------------------- + + + +init_otp_4394(Config) when list(Config) -> + ?DBG("init_otp_4394 -> entry with" + "~n Config: ~p", [Config]), + ?line AgentDir = ?config(agent_dir, Config), + ?line MgrDir = ?config(mgr_dir, Config), + ?line Ip = ?config(ip, Config), + ?line otp_4394_config(AgentDir, MgrDir, Ip), + MasterAgentVerbosity = {master_agent_verbosity, trace}, + NetIfVerbosity = {net_if_verbosity, trace}, + Opts = [MasterAgentVerbosity,NetIfVerbosity], + [{vsn, v1} | start_v1_agent(Config,Opts)]. + +otp_4394_config(AgentDir, MgrDir, Ip0) -> + ?DBG("otp_4394_config -> entry with" + "~n AgentDir: ~p" + "~n MgrDir: ~p" + "~n Ip0: ~p", [AgentDir, MgrDir, Ip0]), + Vsn = [v1], + Ip = tuple_to_list(Ip0), + ?line snmp_config:write_agent_snmp_files(AgentDir, Vsn, Ip, + ?TRAP_UDP, Ip, 4000, + "OTP-4394 test"), + ?line case update_usm(Vsn, AgentDir) of + true -> + ?line copy_file(filename:join(AgentDir, "usm.conf"), + filename:join(MgrDir, "usm.conf")), + ?line update_usm_mgr(Vsn, MgrDir); + false -> + ?line ok + end, + C1 = {"a", "all-rights", "initial", "", "pc"}, + C2 = {"c", "secret", "secret_name", "", "secret_tag"}, + ?line write_community_conf(AgentDir, [C1, C2]), + ?line update_vacm(Vsn, AgentDir), + Ta1 = {"shelob v1", + [134,138,177,177], 5000, 1500, 3, %% Använd Ip och modda + "pc1", + "target_v1", "", + %% [255,255,255,255,0,0], + [], + 2048}, + Ta2 = {"bifur v1", + [134,138,177,75], 5000, 1500, 3, %% Använd Ip + "pc2", + "target_v1", "", + %% [255,255,255,255,0,0], + [], 2048}, + ?line write_target_addr_conf(AgentDir, [Ta1, Ta2]), + ?line write_target_params_conf(AgentDir, Vsn), + ?line write_notify_conf(AgentDir), + ok. + + + +finish_otp_4394(Config) when list(Config) -> + ?DBG("finish_otp_4394 -> entry", []), + C1 = stop_agent(Config), + delete_files(C1), + erase(mgr_node), + lists:keydelete(vsn, 1, C1). + +otp_4394_test(suite) -> []; +otp_4394_test(Config) -> + ?DBG("otp_4394_test -> entry", []), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), + try_test(otp_4394_test1), + ?DBG("otp_4394_test -> done", []), + ok. + +otp_4394_test1() -> + ?DBG("otp_4394_test1 -> entry", []), + gn([[1,1]]), + Res = + case snmp_test_mgr:expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]) of + %% {error, 1, {"?",[]}, {"~w",[timeout]}} + {error, 1, _, {_, [timeout]}} -> + ?DBG("otp_4394_test1 -> expected result: timeout", []), + ok; + Else -> + Else + end, + ?DBG("otp_4394_test1 -> done with: ~p", [Res]), + Res. + + +%%%-------------------------------------------------- +%%% Used to test the standard mib with our +%%% configuration. +%%%-------------------------------------------------- +run(F, A, Opts) -> + M = get(mib_dir), + Dir = get(mgr_dir), + User = snmp_misc:get_option(user, Opts, "all-rights"), + SecLevel = snmp_misc:get_option(sec_level, Opts, noAuthNoPriv), + EngineID = snmp_misc:get_option(engine_id, Opts, "agentEngine"), + CtxEngineID = snmp_misc:get_option(context_engine_id, Opts, EngineID), + Community = snmp_misc:get_option(community, Opts, "all-rights"), + ?DBG("run -> start crypto app",[]), + Crypto = case os:type() of + vxworks -> + no_crypto; + _ -> + ?CRYPTO_START() + end, + ?DBG("run -> Crypto: ~p",[Crypto]), + catch snmp_test_mgr:stop(), % If we had a running mgr from a failed case + StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", + ?DBG("run -> config:~n" + "\tM: ~p~n" + "\tDir: ~p~n" + "\tUser: ~p~n" + "\tSecLevel: ~p~n" + "\tEngineID: ~p~n" + "\tCtxEngineID: ~p~n" + "\tCommunity: ~p~n" + "\tStdM: ~p", + [M,Dir,User,SecLevel,EngineID,CtxEngineID,Community,StdM]), + case snmp_test_mgr:start([%% {agent, snmp_test_lib:hostname()}, + {packet_server_debug,true}, + {debug,true}, + {agent, get(master_host)}, + {agent_udp, 4000}, + {trap_udp, 5000}, + {recbuf,65535}, + quiet, + get(vsn), + {community, Community}, + {user, User}, + {sec_level, SecLevel}, + {engine_id, EngineID}, + {context_engine_id, CtxEngineID}, + {dir, Dir}, + {mibs, mibs(StdM, M)}]) of + {ok, _Pid} -> + Res = apply(?MODULE, F, A), + catch snmp_test_mgr:stop(), + Res; + Err -> + io:format("Error starting manager: ~p\n", [Err]), + catch snmp_test_mgr:stop(), + ?line exit({mgr_start, Err}) + end. + + +mibs(StdMibDir,MibDir) -> + [join(StdMibDir, ?v1_2("STANDARD-MIB.bin", "SNMPv2-MIB.bin")), + join(MibDir, "OLD-SNMPEA-MIB.bin"), + join(StdMibDir, "SNMP-FRAMEWORK-MIB"), + join(StdMibDir, "SNMP-MPD-MIB"), + join(StdMibDir, "SNMP-VIEW-BASED-ACM-MIB"), + join(StdMibDir, "SNMP-USER-BASED-SM-MIB"), + join(StdMibDir, "SNMP-TARGET-MIB"), + join(StdMibDir, "SNMP-NOTIFICATION-MIB"), + join(MibDir, "Klas1.bin"), + join(MibDir, "Klas2.bin"), + join(MibDir, "Klas3.bin"), + join(MibDir, "Klas4.bin"), + join(MibDir, "SA-MIB.bin"), + join(MibDir, "TestTrap.bin"), + join(MibDir, "Test1.bin"), + join(MibDir, "Test2.bin"), + join(MibDir, "TestTrapv2.bin")]. + +join(D,F) -> + filename:join(D,F). + +%% string used in index +is(S) -> [length(S) | S]. + +try_test(Func) -> + call(get(mgr_node), ?MODULE, run, [Func, [], []]). + +try_test(Func, A) -> + call(get(mgr_node), ?MODULE, run, [Func, A, []]). + +try_test(Func, A, Opts) -> + call(get(mgr_node), ?MODULE, run, [Func, A, Opts]). + +call(N,M,F,A) -> + ?DBG("call -> entry with~n" + " N: ~p~n" + " M: ~p~n" + " F: ~p~n" + " A: ~p~n" + " when~n" + " get(): ~p", + [N,M,F,A,get()]), + spawn(N, ?MODULE, wait, [self(),get(),M,F,A]), + receive + {done, {'EXIT', Rn}, Loc} -> + ?DBG("call -> returned ~p",[{done, {'EXIT', Rn}, Loc}]), + put(test_server_loc, Loc), + exit(Rn); + {done, Ret, Zed} -> + ?DBG("call -> returned ~p~n",[{done, Ret, Zed}]), + Ret + end. + +wait(From, Env, M, F, A) -> + ?DBG("wait -> entry with ~n" + "\tFrom: ~p~n" + "\tEnv: ~p",[From,Env]), + lists:foreach(fun({K,V}) -> put(K,V) end, Env), + Rn = (catch apply(M, F, A)), + ?DBG("wait -> Rn: ~n~p", [Rn]), + From ! {done, Rn, get(test_server_loc)}, + exit(Rn). + +expect(A,B) -> ok = snmp_test_mgr:expect(A,B). +expect(A,B,C) -> ok = snmp_test_mgr:expect(A,B,C). +expect(A,B,C,D) -> ok = snmp_test_mgr:expect(A,B,C,D). +expect(A,B,C,D,E,F) -> ok = snmp_test_mgr:expect(A,B,C,D,E,F). + +get_req(Id, Vars) -> + ?DBG("get_req -> entry with~n" + "\tId: ~p~n" + "\tVars: ~p",[Id,Vars]), + g(Vars), + ?DBG("get_req -> await response",[]), + {ok, Val} = snmp_test_mgr:get_response(Id, Vars), + ?DBG("get_req -> response: ~p",[Val]), + Val. + +get_next_req(Vars) -> + ?DBG("get_next_req -> entry with Vars '~p', send request",[Vars]), + gn(Vars), + ?DBG("get_next_req -> await response",[]), + Response = snmp_test_mgr:receive_response(), + ?DBG("get_next_req -> response: ~p",[Response]), + Response. + + + +start_node(Name) -> + ?LOG("start_node -> entry with Name: ~p",[Name]), + M = list_to_atom(?HOSTNAME(node())), + ?DBG("start_node -> M: ~p",[M]), + Pa = filename:dirname(code:which(?MODULE)), + ?DBG("start_node -> Pa: ~p",[Pa]), + + Args = case init:get_argument('CC_TEST') of + {ok, [[]]} -> + " -pa /clearcase/otp/libraries/snmp/ebin "; + {ok, [[Path]]} -> + " -pa " ++ Path; + error -> + "" + end, + %% Do not use start_link!!! (the proc that calls this one is tmp) + ?DBG("start_node -> Args: ~p~n",[Args]), + A = Args ++ " -pa " ++ Pa, + case (catch ?START_NODE(Name, A)) of + {ok, Node} -> + %% Tell the test_server to not clean up things it never started. + ?DBG("start_node -> Node: ~p",[Node]), + {ok, Node}; + Else -> + ?ERR("start_node -> failed with(other): Else: ~p",[Else]), + ?line ?FAIL(Else) + end. + + +stop_node(Node) -> + ?LOG("stop_node -> Node: ~p",[Node]), + rpc:cast(Node, erlang, halt, []). + +p(X) -> + io:format(user, X++"\n", []). + +sleep(X) -> + receive + after + X -> ok + end. + +%%%----------------------------------------------------------------- +%%% Configuration +%%%----------------------------------------------------------------- +config(Vsns, MgrDir, AgentDir, MIp, AIp) -> + ?line snmp_config:write_agent_snmp_files(AgentDir, Vsns, MIp, + ?TRAP_UDP, AIp, 4000, + "test"), + ?line case update_usm(Vsns, AgentDir) of + true -> + ?line copy_file(filename:join(AgentDir, "usm.conf"), + filename:join(MgrDir, "usm.conf")), + ?line update_usm_mgr(Vsns, MgrDir); + false -> + ?line ok + end, + ?line update_community(Vsns, AgentDir), + ?line update_vacm(Vsns, AgentDir), + ?line write_target_addr_conf(AgentDir, MIp, ?TRAP_UDP, Vsns), + ?line write_target_params_conf(AgentDir, Vsns), + ?line write_notify_conf(AgentDir), + ok. + +delete_files(Config) -> + Dir = ?config(agent_dir, Config), + {ok, List} = file:list_dir(Dir), + lists:foreach(fun(FName) -> file:delete(filename:join(Dir, FName)) end, + List). + +update_usm(Vsns, Dir) -> + case lists:member(v3, Vsns) of + true -> + {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),[read,write]), + file:position(Fid, eof), + ok = io:format(Fid, "{\"agentEngine\", \"all-rights\", " + "\"all-rights\", zeroDotZero, " + "usmNoAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"\", \"\"}.\n", []), + ok = io:format(Fid, "{\"agentEngine\", \"no-rights\", " + "\"no-rights\", zeroDotZero, " + "usmNoAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"\", \"\"}.\n", []), + ok = io:format(Fid, "{\"agentEngine\", \"authMD5\", " + "\"authMD5\", zeroDotZero, " + "usmHMACMD5AuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"passwd_md5xxxxxx\", \"\"}.\n", []), + ok = io:format(Fid, "{\"agentEngine\", \"authSHA\", " + "\"authSHA\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"\"}.\n", []), + ok = io:format(Fid, "{\"agentEngine\", \"privDES\", " + "\"privDES\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", + []), + ok = io:format(Fid, "{\"mgrEngine\", \"all-rights\", " + "\"all-rights\", zeroDotZero, " + "usmNoAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"\", \"\"}.\n", []), + ok = io:format(Fid, "{\"mgrEngine\", \"no-rights\", " + "\"no-rights\", zeroDotZero, " + "usmNoAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"\", \"\"}.\n", []), + ok = io:format(Fid, "{\"mgrEngine\", \"authMD5\", " + "\"authMD5\", zeroDotZero, " + "usmHMACMD5AuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"passwd_md5xxxxxx\", \"\"}.\n", []), + ok = io:format(Fid, "{\"mgrEngine\", \"authSHA\", " + "\"authSHA\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmNoPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"\"}.\n", []), + ok = io:format(Fid, "{\"mgrEngine\", \"privDES\", " + "\"privDES\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", + []), + file:close(Fid), + true; + false -> + false + end. + +update_usm_mgr(Vsns, Dir) -> + case lists:member(v3, Vsns) of + true -> + {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),[read,write]), + file:position(Fid, eof), + ok = io:format(Fid, "{\"agentEngine\", \"newUser\", " + "\"newUser\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", + []), + ok = io:format(Fid, "{\"mgrEngine\", \"newUser\", " + "\"newUser\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", + []), + file:close(Fid), + true; + false -> + false + end. + +rewrite_usm_mgr(Dir, ShaKey, DesKey) -> + ?line ok = file:rename(filename:join(Dir,"usm.conf"), + filename:join(Dir,"usm.old")), + ?line {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),write), + ok = io:format(Fid, "{\"agentEngine\", \"newUser\", " + "\"newUser\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"~s\", \"~s\"}.\n", + [ShaKey, DesKey]), + ok = io:format(Fid, "{\"mgrEngine\", \"newUser\", " + "\"newUser\", zeroDotZero, " + "usmHMACSHAAuthProtocol, \"\", \"\", " + "usmDESPrivProtocol, \"\", \"\", \"\", " + "\"~s\", \"~s\"}.\n", + [ShaKey, DesKey]), + file:close(Fid). + +reset_usm_mgr(Dir) -> + ?line ok = file:rename(filename:join(Dir,"usm.old"), + filename:join(Dir,"usm.conf")). + + +update_community([v3], _Dir) -> ok; +update_community(_, Dir) -> + {ok, Fid} = file:open(filename:join(Dir,"community.conf"),[read,write]), + file:position(Fid, eof), + ok=io:format(Fid,"{\"no-rights\",\"no-rights\",\"no-rights\",\"\",\"\"}.\n", + []), + file:close(Fid). + + +-define(tDescr_instance, [1,3,6,1,2,1,16,1,0]). +update_vacm(_Vsn, Dir) -> + {ok, Fid} = file:open(filename:join(Dir,"vacm.conf"),[read,write]), + file:position(Fid, eof), + ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"authMD5\",\"initial\"}.\n",[]), + ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"authSHA\",\"initial\"}.\n",[]), + ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"privDES\",\"initial\"}.\n",[]), + ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"newUser\",\"initial\"}.\n",[]), + ok = io:format(Fid, "{vacmViewTreeFamily, \"internet\", " + "~w, excluded, null}.\n", [?tDescr_instance]), + file:close(Fid). + + +vacm_ver(v1) -> v1; +vacm_ver(v2) -> v2c; +vacm_ver(v3) -> usm. + + +write_community_conf(Dir, Confs) -> + {ok, Fid} = file:open(filename:join(Dir,"community.conf"),write), + ok = write_community_conf1(Fid, Confs), + file:close(Fid). + +write_community_conf1(_, []) -> + ok; +write_community_conf1(Fid, [{ComIdx, ComName, SecName, CtxName, TransTag}|Confs]) -> + ok = io:format(Fid, "{\"~s\", \"~s\", \"~s\", \"~s\", \"~s\"}.~n", + [ComIdx, ComName, SecName, CtxName, TransTag]), + write_community_conf1(Fid, Confs). + + +write_target_addr_conf(Dir, Confs) -> + {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), + ok = write_target_addr_conf1(Fid, Confs), + file:close(Fid). + + +write_target_addr_conf1(_, []) -> + ok; +write_target_addr_conf1(Fid, + [{Name, Ip, Port, Timeout, Retry, TagList, ParamName, + EngineId, TMask, MaxMsgSz}|Confs]) -> + ok = io:format(Fid, "{\"~s\", ~w, ~w, ~w, ~w, \"~s\", \"~s\", \"~s\", ~w, ~w}.~n", + [Name, Ip, Port, Timeout, Retry, TagList, ParamName, + EngineId, TMask, MaxMsgSz]), + write_target_addr_conf1(Fid, Confs). + +write_target_addr_conf(Dir, ManagerIp, UDP, Vsns) -> + {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), + lists:foreach(fun(Vsn) -> + ok = io:format(Fid, + "{\"~s\", ~w, ~w, 1500, 3, " + "\"std_trap\", \"~s\"}.~n", + [mk_ip(ManagerIp, Vsn), + ManagerIp, UDP, mk_param(Vsn)]), + case Vsn of + v1 -> ok; + v2 -> + ok = io:format(Fid, + "{\"~s.2\",~w,~w,1500,3, " + "\"std_inform\", \"~s\"}.~n", + [mk_ip(ManagerIp, Vsn), + ManagerIp, UDP, + mk_param(Vsn)]); + v3 -> + ok = io:format(Fid, + "{\"~s.3\",~w,~w,1500,3, " + "\"std_inform\", \"~s\", " + "\"mgrEngine\", [], 1024}.~n", + [mk_ip(ManagerIp, Vsn), + ManagerIp, UDP, + mk_param(Vsn)]) + end + end, + Vsns), + file:close(Fid). + +mk_param(v1) -> "target_v1"; +mk_param(v2) -> "target_v2"; +mk_param(v3) -> "target_v3". + +mk_ip([A,B,C,D], Vsn) -> + io_lib:format("~w.~w.~w.~w ~w", [A,B,C,D,Vsn]). + + +rewrite_target_addr_conf(Dir,NewPort) -> + TAFile = filename:join(Dir, "target_addr.conf"), + ?DBG("rewrite_target_addr_conf -> read target file info of address config file",[]), + case file:read_file_info(TAFile) of + {ok, _} -> ok; + {error, R} -> ?ERR("failure reading file info of " + "target address config file: ~p",[R]), + ok + end, + + ?line [TrapAddr|Addrs] = + snmp_conf:read(TAFile,fun(R) -> rewrite_target_addr_conf1(R) end), + + ?DBG("rewrite_target_addr_conf -> TrapAddr: ~p",[TrapAddr]), + + NewAddrs = [rewrite_target_addr_conf2(NewPort,TrapAddr)|Addrs], + + ?DBG("rewrite_target_addr_conf -> NewAddrs: ~p",[NewAddrs]), + + ?line ok = file:rename(filename:join(Dir,"target_addr.conf"), + filename:join(Dir,"target_addr.old")), + ?line {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), + + ?line ok = rewrite_target_addr_conf3(Fid,NewAddrs), + + file:close(Fid). + +rewrite_target_addr_conf1(O) -> + {ok,O}. + +rewrite_target_addr_conf2(NewPort,{Name,Ip,_Port,Timeout,Retry, + "std_trap",EngineId}) -> + ?LOG("rewrite_target_addr_conf2 -> entry with std_trap",[]), + {Name,Ip,NewPort,Timeout,Retry,"std_trap",EngineId}; +rewrite_target_addr_conf2(_NewPort,O) -> + ?LOG("rewrite_target_addr_conf2 -> entry with " + "~n O: ~p",[O]), + O. + + +rewrite_target_addr_conf3(_,[]) -> ok; +rewrite_target_addr_conf3(Fid,[{Name,Ip,Port,Timeout,Retry, + ParamName,EngineId}|T]) -> + ?LOG("rewrite_target_addr_conf3 -> write(1) ~s",[ParamName]), + io:format(Fid, + "{\"~s\", " % Name + "~p, " % Ip + "~p, " % Port + "~p, " % Timeout + "~p, " % Retry + "\"~s\", " % ParamsName + "\"~s\"}.", % EngineId + [Name,Ip,Port,Timeout,Retry,ParamName,EngineId]), + rewrite_target_addr_conf3(Fid,T); +rewrite_target_addr_conf3(Fid,[{Name,Ip,Port,Timeout,Retry,TagList, + ParamName,EngineId,TMask,MMS}|T]) -> + ?LOG("rewrite_target_addr_conf3 -> write(2) ~s",[ParamName]), + io:format(Fid, + "{\"~s\", " % Name + "~p, " % Ip + "~p, " % Port + "~p, " % Timeout + "~p, " % Retry + "\"~s\", " % TagList + "\"~s\", " % ParamsName + "\"~s\"," % EngineId + "~p, " % TMask + "~p}.", % MMS + [Name,Ip,Port,Timeout,Retry,TagList,ParamName, + EngineId,TMask,MMS]), + rewrite_target_addr_conf3(Fid,T). + +reset_target_addr_conf(Dir) -> + ?line ok = file:rename(filename:join(Dir,"target_addr.old"), + filename:join(Dir,"target_addr.conf")). + +write_target_params_conf(Dir, Vsns) -> + {ok, Fid} = file:open(filename:join(Dir,"target_params.conf"),write), + lists:foreach(fun(Vsn) -> + MP = if Vsn == v1 -> v1; + Vsn == v2 -> v2c; + Vsn == v3 -> v3 + end, + SM = if Vsn == v1 -> v1; + Vsn == v2 -> v2c; + Vsn == v3 -> usm + end, + ok = io:format(Fid, "{\"target_~w\", ~w, ~w, " + "\"all-rights\", noAuthNoPriv}.~n", + [Vsn, MP, SM]) + end, + Vsns), + file:close(Fid). + +rewrite_target_params_conf(Dir, SecName, SecLevel) -> + ?line ok = file:rename(filename:join(Dir,"target_params.conf"), + filename:join(Dir,"target_params.old")), + ?line {ok, Fid} = file:open(filename:join(Dir,"target_params.conf"),write), + ?line ok = io:format(Fid, "{\"target_v3\", v3, usm, \"~s\", ~w}.~n", + [SecName, SecLevel]), + file:close(Fid). + +reset_target_params_conf(Dir) -> + ?line ok = file:rename(filename:join(Dir,"target_params.old"), + filename:join(Dir,"target_params.conf")). + +write_notify_conf(Dir) -> + {ok, Fid} = file:open(filename:join(Dir,"notify.conf"),write), + ok = io:format(Fid, "{\"standard trap\", \"std_trap\", trap}.~n", []), + ok = io:format(Fid, "{\"standard inform\", \"std_inform\",inform}.~n", []), + file:close(Fid). + +ver_to_trap_str([v1]) -> "v1"; +ver_to_trap_str([v2]) -> "v2"; +% default is to use the latest snmp version +ver_to_trap_str([v1,v2]) -> "v2". + + + +write_view_conf(Dir) -> + {ok, Fid} = file:open(a(Dir,"view.conf"),write), + ok = io:format(Fid, "{2, [1,3,6], included, null}.~n", []), + ok = io:format(Fid, "{2, ~w, excluded, null}.~n", [?tDescr_instance]), + file:close(Fid). + +a(A,B) -> lists:append(A,B). + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +copy_file(From, To) -> + {ok, Bin} = file:read_file(From), + ok = file:write_file(To, Bin). + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +display_memory_usage() -> + Info = snmpa:info(snmp_master_agent), + TreeSize = lists_key1search(tree_size_bytes, Info), + ProcMem = lists_key1search(process_memory, Info), + MibDbSize = lists_key1search([db_memory,mib], Info), + NodeDbSize = lists_key1search([db_memory,node], Info), + TreeDbSize = lists_key1search([db_memory,tree], Info), + ?INF("Memory usage: " + "~n Tree size: ~p" + "~n Process memory size: ~p" + "~n Mib db size: ~p" + "~n Node db size: ~p" + "~n Tree db size: ~p", + [TreeSize, ProcMem, MibDbSize, NodeDbSize, TreeDbSize]). + +lists_key1search([], Res) -> + Res; +lists_key1search([Key|Keys], List) when atom(Key), list(List) -> + case lists:keysearch(Key, 1, List) of + {value, {Key, Val}} -> + lists_key1search(Keys, Val); + false -> + undefined + end; +lists_key1search(Key, List) when atom(Key) -> + case lists:keysearch(Key, 1, List) of + {value, {Key, Val}} -> + Val; + false -> + undefined + end. + + +regs() -> + lists:sort(registered()). diff --git a/lib/snmp/test/snmp_agent_bl_test.erl b/lib/snmp/test/snmp_agent_bl_test.erl deleted file mode 100644 index b17489a755..0000000000 --- a/lib/snmp/test/snmp_agent_bl_test.erl +++ /dev/null @@ -1,5654 +0,0 @@ -%% -%% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2005-2010. All Rights Reserved. -%% -%% The contents of this file are subject to the Erlang Public License, -%% Version 1.1, (the "License"); you may not use this file except in -%% compliance with the License. You should have received a copy of the -%% Erlang Public License along with this software. If not, it can be -%% retrieved online at http://www.erlang.org/. -%% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -%% the License for the specific language governing rights and limitations -%% under the License. -%% -%% %CopyrightEnd% -%% - --module(snmp_agent_bl_test). - -%% TODO -%% * Test fault-tolerance (kill master etc) -%% - -% -include_lib("kernel/include/file.hrl"). -% -include("test_server.hrl"). -% -include("snmp_test_lib.hrl"). -% -define(SNMP_USE_V3, true). -% -include_lib("snmp/include/snmp_types.hrl"). - -%% -include_lib("snmp/include/SNMP-COMMUNITY-MIB.hrl"). -%% -include_lib("snmp/include/SNMP-VIEW-BASED-ACM-MIB.hrl"). -%% -include_lib("snmp/include/SNMP-USER-BASED-SM-MIB.hrl"). - - -% -define(klas1, [1,3,6,1,2,1,7]). -% -define(klas2, [1,3,6,1,2,1,9]). -% -define(klas3, [1,3,6,1,2,1,8,1]). -% -define(klas4, [1,3,6,1,2,1,8,4]). -% -define(sa, [1,3,6,1,4,1,193,2]). -% -define(system, [1,3,6,1,2,1,1]). -% -define(snmp, [1,3,6,1,2,1,11]). -% -define(snmpTraps, [1,3,6,1,6,3,1,1,5]). -% -define(ericsson, [1,3,6,1,4,1,193]). -% -define(testTrap, [1,3,6,1,2,1,15,0]). -% -define(xDescr, [1,3,6,1,2,1,17,1]). -% -define(xDescr2, [1,3,6,1,2,1,17,2]). - -% -define(active, 1). -% -define(notInService, 2). -% -define(notReady, 3). -% -define(createAndGo, 4). -% -define(createAndWait, 5). -% -define(destroy, 6). - -% -define(TRAP_UDP, 5000). - -% -define(tooBigStr, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"). - --define(str(X), snmp_pdus:bits_to_str(X)). - --define(break(), begin io:format(user, "break at line ~w: pid: ~p\n", - [?LINE, self()]), - receive cont -> ok end - end). - - --import(snmp_test_mgr, [gn/1, g/1, s/1, gb/3]). --define(v1_2(V1,V2), - case get(vsn) of - v1 -> V1; - _ -> V2 - end). - --define(v1_2_3(V1,V2,V3), - case get(vsn) of - v1 -> V1; - v2 -> V2; - _ -> V3 - end). - -all(suite) -> {req, - [mnesia, distribution, - {local_slave_nodes, 2}, {time, 360}], - [{conf, init_all, cases(), finish_all}]}. - -init_per_testcase(_Case, Config) when list(Config) -> - Dog = ?t:timetrap(?t:minutes(6)), - [{watchdog, Dog}|Config]. - -end_per_testcase(_Case, Config) when list(Config) -> - Dog = ?config(watchdog, Config), - ?t:timetrap_cancel(Dog), - Config. - -cases() -> - case ?OSTYPE() of - vxworks -> - %% No crypto app, so skip v3 testcases - [ - app_info, - test_v1, test_v2, test_v1_v2, - test_multi_threaded, - mib_storage, - tickets]; - _Else -> - [ - app_info, - test_v1, test_v2, test_v1_v2, test_v3, - test_multi_threaded, - mib_storage, - tickets - ] - end. - - -%%%----------------------------------------------------------------- -%%% The test case structure is as follows: -%%% -%%% init_all - starts mnesia, -%%% -%%% init_v1 - starts agent -%%% simple -%%% big - e.g. starts/stops subagent, load/unloads mibs -%%% init_mul -%%% mul_get -%%% mul_set -%%% -%%% finish_mul -%%% -%%% finish_v1 -%%% -%%% init_v2 - starts agent -%%% finish_v2 -%%% -%%% init_bilingual - starts agent -%%% finish_bilingual -%%% -%%% finish_all -%%% -%%% There is still one problem with these testsuites. If one test -%%% fails, it may not be possible to run some other cases, as it -%%% may have e.g. created some row or loaded some table, that it -%%% didn't undo (since it failed). -%%%----------------------------------------------------------------- - -init_all(Config0) when list(Config0) -> - ?LOG("init_all -> entry with" - "~n Config0: ~p",[Config0]), - - %% -- - %% Fix config: - %% - - DataDir0 = ?config(data_dir, Config0), - DataDir1 = filename:split(filename:absname(DataDir0)), - [_|DataDir2] = lists:reverse(DataDir1), - DataDir3 = filename:join(lists:reverse(DataDir2) ++ [?snmp_test_data]), - Config1 = lists:keydelete(data_dir, 1, Config0), - Config = [{data_dir, DataDir3 ++ "/"}|Config1], - - %% -- - %% Start nodes - %% - - ?line {ok, SaNode} = start_node(snmp_sa), - ?line {ok, MgrNode} = start_node(snmp_mgr), - - - %% -- - %% Create necessary files - %% - - Dir = ?config(priv_dir, Config), - ?DBG("init_all -> Dir ~p", [Dir]), - - DataDir = ?config(data_dir, Config), - ?DBG("init_all -> DataDir ~p", [DataDir]), - - file:make_dir(MgrDir = filename:join(Dir, "mgr_dir/")), - ?DBG("init_all -> MgrDir ~p", [MgrDir]), - - file:make_dir(AgentDir = filename:join(Dir, "agent_dir/")), - ?DBG("init_all -> AgentDir ~p", [AgentDir]), - - file:make_dir(SaDir = filename:join(Dir, "sa_dir/")), - ?DBG("init_all -> SaDir ~p", [SaDir]), - - - %% -- - %% Start and initiate mnesia - %% - - ?DBG("init_all -> load application mnesia", []), - ?line ok = application:load(mnesia), - - ?DBG("init_all -> load application mnesia on node ~p", [SaNode]), - ?line ok = rpc:call(SaNode, application, load, [mnesia]), - - ?DBG("init_all -> application mnesia: set_env dir",[]), - ?line application_controller:set_env(mnesia, dir, - filename:join(Dir, "Mnesia1")), - - ?DBG("init_all -> application mnesia: set_env dir on node ~p",[SaNode]), - ?line rpc:call(SaNode, application_controller, set_env, - [mnesia, dir, filename:join(Dir, "Mnesia2")]), - - ?DBG("init_all -> create mnesia schema",[]), - ?line ok = mnesia:create_schema([SaNode, node()]), - - ?DBG("init_all -> start application mnesia",[]), - ?line ok = application:start(mnesia), - - ?DBG("init_all -> start application mnesia on ~p",[SaNode]), - ?line ok = rpc:call(SaNode, application, start, [mnesia]), - Ip = ?LOCALHOST(), - [{snmp_sa, SaNode}, - {snmp_mgr, MgrNode}, - {agent_dir, AgentDir ++ "/"}, - {mgr_dir, MgrDir ++ "/"}, - {sa_dir, SaDir ++ "/"}, - {mib_dir, DataDir}, - {ip, Ip} | - Config]. - -finish_all(Config) when list(Config) -> - SaNode = ?config(snmp_sa, Config), - MgrNode = ?config(snmp_mgr, Config), - stop_node(SaNode), - stop_node(MgrNode), - application:stop(mnesia). - -start_v1_agent(Config) when list(Config) -> - start_agent(Config, [v1]). - -start_v1_agent(Config,Opts) when list(Config), list(Opts) -> - start_agent(Config, [v1], Opts). - -start_v2_agent(Config) when list(Config) -> - start_agent(Config, [v2]). - -start_v3_agent(Config) when list(Config) -> - start_agent(Config, [v3]). - -start_bilingual_agent(Config) when list(Config) -> - start_agent(Config, [v1,v2]). - -start_multi_threaded_agent(Config) when list(Config) -> - start_agent(Config, [v2], [{snmp_multi_threaded, true}]). - -stop_agent(Config) when list(Config) -> - ?LOG("stop_agent -> entry with" - "~n Config: ~p",[Config]), - - {Sup, Par} = ?config(snmp_sup, Config), - ?DBG("stop_agent -> attempt to stop (sup) ~p" - "~n Sup: ~p" - "~n Par: ~p", - [Sup, - (catch process_info(Sup)), - (catch process_info(Par))]), - stop_sup(Sup, Par), - - {Sup2, Par2} = ?config(snmp_sub, Config), - ?DBG("stop_agent -> attempt to stop (sub) ~p" - "~n Sup2: ~p" - "~n Par2: ~p", - [Sup2, - (catch process_info(Sup2)), - (catch process_info(Par2))]), - stop_sup(Sup2, Par2), - - ?DBG("stop_agent -> done - now cleanup config", []), - C1 = lists:keydelete(snmp_sup, 1, Config), - lists:keydelete(snmp_sub, 1, C1). - - -stop_sup(Pid, _) when node(Pid) == node() -> - case (catch process_info(Pid)) of - PI when list(PI) -> - ?LOG("stop_sup -> attempt to stop ~p", [Pid]), - Ref = erlang:monitor(process, Pid), - exit(Pid, kill), - await_stopped(Pid, Ref); - {'EXIT', _Reason} -> - ?LOG("stop_sup -> ~p not running", [Pid]), - ok - end; -stop_sup(Pid, _) -> - ?LOG("stop_sup -> attempt to stop ~p", [Pid]), - Ref = erlang:monitor(process, Pid), - ?LOG("stop_sup -> Ref: ~p", [Ref]), - %% Pid ! {'EXIT', Parent, shutdown}, % usch - exit(Pid, kill), - await_stopped(Pid, Ref). - -await_stopped(Pid, Ref) -> - receive - {'DOWN', Ref, process, Pid, _Reason} -> - ?DBG("received down message for ~p", [Pid]), - ok - after 10000 -> - ?INF("await_stopped -> timeout for ~p",[Pid]), - erlang:demonitor(Ref), - ?FAIL({failed_stop,Pid}) - end. - - -start_agent(Config, Vsn) -> - start_agent(Config, Vsn, []). -start_agent(Config, Vsn, Opts) -> - ?LOG("start_agent -> entry (~p) with" - "~n Config: ~p" - "~n Vsn: ~p" - "~n Opts: ~p",[node(), Config, Vsn, Opts]), - - ?line AgentDir = ?config(agent_dir, Config), - ?line SaNode = ?config(snmp_sa, Config), - - snmp_app_env_init(vsn_init(Vsn) ++ - [{audit_trail_log, read_write_log}, - {audit_trail_log_dir, AgentDir}, - {audit_trail_log_size, {10240, 10}}, - {force_config_reload, false}, - {snmp_agent_type, master}, - {snmp_config_dir, AgentDir}, - {snmp_db_dir, AgentDir}, - {snmp_local_db_auto_repair, true}, - {snmp_master_agent_verbosity, trace}, - {snmp_supervisor_verbosity, trace}, - {snmp_mibserver_verbosity, trace}, - {snmp_symbolic_store_verbosity, trace}, - {snmp_note_store_verbosity, trace}, - {snmp_net_if_verbosity, trace}], - Opts), - - - process_flag(trap_exit,true), - - {ok, AppSup} = snmp_app_sup:start_link(), - unlink(AppSup), - ?DBG("start_agent -> snmp app supervisor: ~p",[AppSup]), - - ?DBG("start_agent -> start master agent (old style)",[]), - Sup = case (catch snmpa_app:start(normal)) of - {ok, S} -> - ?DBG("start_agent -> started, Sup: ~p",[S]), - S; - - Else -> - ?DBG("start_agent -> unknown result: ~n~p",[Else]), - %% Get info about the apps we depend on - MnesiaInfo = mnesia_running(), - ?FAIL({start_failed,Else,MnesiaInfo}) - end, - - ?DBG("start_agent -> unlink from supervisor",[]), - ?line unlink(Sup), - ?line SaDir = ?config(sa_dir, Config), - ?DBG("start_agent -> (rpc) start sub on ~p",[SaNode]), - ?line {ok, Sub} = rpc:call(SaNode, ?MODULE, start_sub, [SaDir]), - ?DBG("start_agent -> done",[]), - ?line [{snmp_sup, {Sup, self()}}, {snmp_sub, Sub} | Config]. - - -vsn_init(Vsn) -> - vsn_init([v1,v2,v3], Vsn, []). - -vsn_init([], _Vsn, Acc) -> - Acc; -vsn_init([V|Vsns], Vsn, Acc) -> - case lists:member(V, Vsn) of - true -> - vsn_init(Vsns, Vsn, [{V, true}|Acc]); - false -> - vsn_init(Vsns, Vsn, [{V, false}|Acc]) - end. - -snmp_app_env_init(Env0, Opts) -> - ?DBG("snmp_app_env_init -> unload snmp",[]), - ?line application:unload(snmp), - ?DBG("snmp_app_env_init -> load snmp",[]), - ?line application:load(snmp), - ?DBG("snmp_app_env_init -> initiate (snmp) application env",[]), - F1 = fun({Key,Val} = New, Acc0) -> - ?DBG("snmp_app_env_init -> " - "updating setting ~p to ~p", [Key, Val]), - case lists:keyreplace(Key, 1, Acc0, New) of - Acc0 -> - [New|Acc0]; - Acc -> - Acc - end - end, - Env = lists:foldr(F1, Env0, Opts), - ?DBG("snmp_app_env_init -> Env: ~p",[Env]), - F2 = fun({Key,Val}) -> - ?DBG("snmp_app_env_init -> setting ~p to ~p",[Key, Val]), - application_controller:set_env(snmp, Key, Val) - end, - lists:foreach(F2, Env). - - - - -%% Test if application is running -mnesia_running() -> ?IS_MNESIA_RUNNING(). -crypto_running() -> ?IS_CRYPTO_RUNNING(). - - -start_sub(Dir) -> - ?DBG("start_sub -> entry",[]), - Opts = [{db_dir, Dir}, - {supervisor, [{verbosity, trace}]}], - %% BMK BMK -% {ok, P} = snmp_supervisor:start_sub(Dir), - {ok, P} = snmpa_supervisor:start_sub_sup(Opts), - unlink(P), - {ok, {P, self()}}. - -create_tables(SaNode) -> - ?line {atomic, ok} = mnesia:create_table([{name, friendsTable2}, - {ram_copies, [SaNode]}, - {snmp, [{key, integer}]}, - {attributes, [a1,a2,a3]}]), - ?line {atomic, ok} = mnesia:create_table([{name, kompissTable2}, - {ram_copies, [SaNode]}, - {snmp, [{key, integer}]}, - {attributes, [a1,a2,a3]}]), - ?line {atomic, ok} = mnesia:create_table([{name, snmp_variables}, - {attributes, [a1,a2]}]). - -delete_tables() -> - mnesia:delete_table(friendsTable2), - mnesia:delete_table(kompissTable2), - mnesia:delete_table(snmp_variables). - -%% Creation is done in runtime! -delete_mib_storage_mnesia_tables() -> - mnesia:delete_table(snmpa_mib_data), - mnesia:delete_table(snmpa_mib_tree), - mnesia:delete_table(snmpa_symbolic_store). - -%%----------------------------------------------------------------- -%% A test case is always one of: -%% - v1 specific case -%% - v2 specific case -%% - v1 and v2 case -%% All v1 specific cases are prefixed with v1_, and all v2 with -%% v2_. E.g. v1_trap/v2_trap. -%% -%% All other cases are shared. However, the testserver uses the name -%% of the case to generate a file for that case. The same case cannot -%% be used in different configurations in the same suite. Therefore -%% all these functions exists in two variants, the base function -%% , and a second version _2. There may be several -%% versions as well, _N. -%%----------------------------------------------------------------- -mib_storage(suite) -> [ - mib_storage_ets, - mib_storage_dets, - mib_storage_mnesia, - mib_storage_size_check_ets, - mib_storage_size_check_dets, - mib_storage_size_check_mnesia, - mib_storage_varm_dets, - mib_storage_varm_mnesia - ]. - -mib_storage_ets(suite) -> {req, [], {conf, init_mib_storage_ets, - mib_storage_ets_cases(), - finish_mib_storage_ets}}. - -mib_storage_dets(suite) -> {req, [], {conf, init_mib_storage_dets, - mib_storage_dets_cases(), - finish_mib_storage_dets}}. - -mib_storage_mnesia(suite) -> {req, [], {conf, init_mib_storage_mnesia, - mib_storage_mnesia_cases(), - finish_mib_storage_mnesia}}. - -mib_storage_size_check_ets(suite) -> - {req, [], {conf, - init_size_check_mse, - mse_size_check_cases(), - finish_size_check_mse}}. - -mib_storage_size_check_dets(suite) -> - {req, [], {conf, - init_size_check_msd, - msd_size_check_cases(), - finish_size_check_msd}}. - -mib_storage_size_check_mnesia(suite) -> - {req, [], {conf, - init_size_check_msm, - msm_size_check_cases(), - finish_size_check_msm}}. - -mib_storage_varm_dets(suite) -> - {req, [], {conf, - init_varm_mib_storage_dets, - varm_mib_storage_dets_cases(), - finish_varm_mib_storage_dets}}. - -mib_storage_varm_mnesia(suite) -> - {req, [], {conf, - init_varm_mib_storage_mnesia, - varm_mib_storage_mnesia_cases(), - finish_varm_mib_storage_mnesia}}. - -mib_storage_ets_cases() -> - [ - mse_simple, - mse_v1_processing, - mse_big, - mse_big2, - mse_loop_mib, - mse_api, - mse_sa_register, - mse_v1_trap, - mse_sa_error, - mse_next_across_sa, - mse_undo, - mse_standard_mib, - mse_community_mib, - mse_framework_mib, - mse_target_mib, - mse_notification_mib, - mse_view_based_acm_mib, - mse_sparse_table, - mse_me_of, - mse_mib_of]. - -mib_storage_dets_cases() -> - [ - msd_simple, - msd_v1_processing, - msd_big, - msd_big2, - msd_loop_mib, - msd_api, - msd_sa_register, - msd_v1_trap, - msd_sa_error, - msd_next_across_sa, - msd_undo, - msd_standard_mib, - msd_community_mib, - msd_framework_mib, - msd_target_mib, - msd_notification_mib, - msd_view_based_acm_mib, - msd_sparse_table, - msd_me_of, - msd_mib_of - ]. - -mib_storage_mnesia_cases() -> - [ - msm_simple, - msm_v1_processing, - msm_big, - msm_big2, - msm_loop_mib, - msm_api, - msm_sa_register, - msm_v1_trap, - msm_sa_error, - msm_next_across_sa, - msm_undo, - msm_standard_mib, - msm_community_mib, - msm_framework_mib, - msm_target_mib, - msm_notification_mib, - msm_view_based_acm_mib, - msm_sparse_table, - msm_me_of, - msm_mib_of - ]. - -mse_size_check_cases() -> - [mse_size_check]. - -msd_size_check_cases() -> - [msd_size_check]. - -msm_size_check_cases() -> - [msm_size_check]. - -varm_mib_storage_dets_cases() -> - [msd_varm_mib_start]. - -varm_mib_storage_mnesia_cases() -> - [msm_varm_mib_start]. - -init_mib_storage_ets(Config) when list(Config) -> - ?LOG("init_mib_storage_ets -> entry", []), - MibStorage = {snmp_mib_storage,ets}, - init_ms(Config, [MibStorage]). - -init_mib_storage_dets(Config) when list(Config) -> - ?LOG("init_mib_storage_ets -> entry", []), - ?line AgentDir = ?GCONF(agent_dir, Config), - MibStorage = {snmp_mib_storage,{dets,AgentDir}}, - init_ms(Config, [MibStorage]). - -init_mib_storage_mnesia(Config) when list(Config) -> - ?LOG("init_mib_storage_ets -> entry", []), - MibStorage = {snmp_mib_storage,{mnesia,[]}}, - init_ms(Config, [MibStorage]). - -init_ms(Config, Opts) when list(Config) -> - ?LOG("init_mib_storage_ets -> entry", []), - ?line SaNode = ?GCONF(snmp_sa, Config), - ?line create_tables(SaNode), - ?line AgentDir = ?GCONF(agent_dir, Config), - ?line MgrDir = ?GCONF(mgr_dir, Config), - ?line Ip = ?GCONF(ip, Config), - ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, - MibsVerbosity = {snmp_mibserver_verbosity, trace}, - SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, - Opts1 = [MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity|Opts], - [{vsn, v1} | start_v1_agent(Config,Opts1)]. - -init_size_check_mse(Config) when list(Config) -> - MibStorage = {snmp_mib_storage, ets}, - init_size_check_ms(Config, [MibStorage]). - -init_size_check_msd(Config) when list(Config) -> - AgentDir = ?GCONF(agent_dir, Config), - MibStorage = {snmp_mib_storage, {dets, AgentDir}}, - init_size_check_ms(Config, [MibStorage]). - -init_size_check_msm(Config) when list(Config) -> - MibStorage = {snmp_mib_storage, {mnesia,[]}}, - init_size_check_ms(Config, [MibStorage]). - -init_size_check_ms(Config, Opts) when list(Config) -> - SaNode = ?GCONF(snmp_sa, Config), - %% We are using v3 here, so crypto must be supported or else... - case ?CRYPTO_START() of - ok -> - case ?CRYPTO_SUPPORT() of - {no, Reason} -> - ?SKIP({unsupported_encryption, Reason}); - yes -> - ok - end; - {error, Reason} -> - ?SKIP({failed_starting_crypto, Reason}) - end, - create_tables(SaNode), - AgentDir = ?GCONF(agent_dir, Config), - MgrDir = ?GCONF(mgr_dir, Config), - Ip = ?GCONF(ip, Config), - ?line ok = - config([v3], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v3} | start_agent(Config, [v3], Opts)]. - -init_varm_mib_storage_dets(Config) when list(Config) -> - ?LOG("init_varm_mib_storage_dets -> entry", []), - ?line SaNode = ?GCONF(snmp_sa, Config), - ?line create_tables(SaNode), - ?line AgentDir = ?GCONF(agent_dir, Config), - ?line MgrDir = ?GCONF(mgr_dir, Config), - ?line Ip = ?GCONF(ip, Config), - ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - MibStorage = {snmp_mib_storage,{dets,AgentDir}}, - MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, - MibsVerbosity = {snmp_mibserver_verbosity, trace}, - SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, - Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity], - [{vsn, v1}, {agent_opts,Opts} | Config]. - -init_varm_mib_storage_mnesia(Config) when list(Config) -> - ?LOG("init_varm_mib_storage_mnesia -> entry", []), - ?line SaNode = ?GCONF(snmp_sa, Config), - ?line create_tables(SaNode), - ?line AgentDir = ?GCONF(agent_dir, Config), - ?line MgrDir = ?GCONF(mgr_dir, Config), - ?line Ip = ?GCONF(ip, Config), - ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - MibStorage = {snmp_mib_storage,{mnesia,[]}}, - MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, - MibsVerbosity = {snmp_mibserver_verbosity, trace}, - SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, - Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity], - [{vsn, v1}, {agent_opts,Opts} | Config]. - -finish_mib_storage_ets(Config) when list(Config) -> - ?LOG("finish_mib_storage_ets -> entry", []), - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - C2 = lists:keydelete(vsn, 1, C1), - lists:keydelete(agent_opts, 1, C2). - -finish_mib_storage_dets(Config) when list(Config) -> - ?LOG("finish_mib_storage_dets -> entry", []), - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - C2 = lists:keydelete(vsn, 1, C1), - lists:keydelete(agent_opts, 1, C2). - -finish_mib_storage_mnesia(Config) when list(Config) -> - ?LOG("finish_mib_storage_mnesia -> entry", []), - delete_tables(), - delete_mib_storage_mnesia_tables(), - C1 = stop_agent(Config), - delete_files(C1), - C2 = lists:keydelete(vsn, 1, C1), - lists:keydelete(agent_opts, 1, C2). - -finish_varm_mib_storage_dets(Config) when list(Config) -> - ?LOG("finish_varm_mib_storage_dets -> entry", []), - delete_tables(), - %% C1 = stop_agent(Config), % In case something went wrong... - delete_files(Config), - C2 = lists:keydelete(vsn, 1, Config), - lists:keydelete(agent_opts, 1, C2). - -finish_varm_mib_storage_mnesia(Config) when list(Config) -> - ?LOG("finish_varm_mib_storage_mnesia -> entry", []), - delete_tables(), - delete_mib_storage_mnesia_tables(), - %% C1 = stop_agent(Config), % In case something went wrong... - delete_files(Config), - C2 = lists:keydelete(vsn, 1, Config), - lists:keydelete(agent_opts, 1, C2). - -finish_size_check_mse(Config) when list(Config) -> - finish_size_check_ms(Config). - -finish_size_check_msd(Config) when list(Config) -> - finish_size_check_ms(Config). - -finish_size_check_msm(Config) when list(Config) -> - finish_size_check_ms(Config). - -finish_size_check_ms(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - - -%% These are just interface functions to fool the test server -mse_simple(X) -> simple(X). -mse_v1_processing(X) -> v1_processing(X). -mse_big(X) -> big(X). -mse_big2(X) -> big2(X). -mse_loop_mib(X) -> loop_mib(X). -mse_api(X) -> api(X). -mse_sa_register(X) -> sa_register(X). -mse_v1_trap(X) -> v1_trap(X). -mse_sa_error(X) -> sa_error(X). -mse_next_across_sa(X) -> next_across_sa(X). -mse_undo(X) -> undo(X). -mse_standard_mib(X) -> snmp_standard_mib(X). -mse_community_mib(X) -> snmp_community_mib(X). -mse_framework_mib(X) -> snmp_framework_mib(X). -mse_target_mib(X) -> snmp_target_mib(X). -mse_notification_mib(X) -> snmp_notification_mib(X). -mse_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). -mse_sparse_table(X) -> sparse_table(X). -mse_me_of(X) -> ms_me_of(X). -mse_mib_of(X) -> ms_mib_of(X). - -msd_simple(X) -> simple(X). -msd_v1_processing(X) -> v1_processing(X). -msd_big(X) -> big(X). -msd_big2(X) -> big2(X). -msd_loop_mib(X) -> loop_mib(X). -msd_api(X) -> api(X). -msd_sa_register(X) -> sa_register(X). -msd_v1_trap(X) -> v1_trap(X). -msd_sa_error(X) -> sa_error(X). -msd_next_across_sa(X) -> next_across_sa(X). -msd_undo(X) -> undo(X). -msd_standard_mib(X) -> snmp_standard_mib(X). -msd_community_mib(X) -> snmp_community_mib(X). -msd_framework_mib(X) -> snmp_framework_mib(X). -msd_target_mib(X) -> snmp_target_mib(X). -msd_notification_mib(X) -> snmp_notification_mib(X). -msd_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). -msd_sparse_table(X) -> sparse_table(X). -msd_me_of(X) -> ms_me_of(X). -msd_mib_of(X) -> ms_mib_of(X). - -msm_simple(X) -> simple(X). -msm_v1_processing(X) -> v1_processing(X). -msm_big(X) -> big(X). -msm_big2(X) -> big2(X). -msm_loop_mib(X) -> loop_mib(X). -msm_api(X) -> api(X). -msm_sa_register(X) -> sa_register(X). -msm_v1_trap(X) -> v1_trap(X). -msm_sa_error(X) -> sa_error(X). -msm_next_across_sa(X) -> next_across_sa(X). -msm_undo(X) -> undo(X). -msm_standard_mib(X) -> snmp_standard_mib(X). -msm_community_mib(X) -> snmp_community_mib(X). -msm_framework_mib(X) -> snmp_framework_mib(X). -msm_target_mib(X) -> snmp_target_mib(X). -msm_notification_mib(X) -> snmp_notification_mib(X). -msm_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). -msm_sparse_table(X) -> sparse_table(X). -msm_me_of(X) -> ms_me_of(X). -msm_mib_of(X) -> ms_mib_of(X). - - -mse_size_check(X) -> p("mse_size_check..."), ms_size_check(X). -msd_size_check(X) -> p("msd_size_check..."), ms_size_check(X). -msm_size_check(X) -> p("msm_size_check..."), ms_size_check(X). - -msd_varm_mib_start(X) -> p("msd_varm_mib_start..."), varm_mib_start(X). -msm_varm_mib_start(X) -> p("msm_varm_mib_start..."), varm_mib_start(X). - -ms_size_check(suite) -> []; -ms_size_check(Config) when list(Config) -> - p("ms_size_check..."), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?LOG("mib server size check...", []), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - ?line load_master_std("OTP-SNMPEA-MIB"), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-MPD-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-USER-BASED-SM-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - ?line load_master_std("SNMPv2-MIB"), - ?line load_master_std("SNMPv2-TM"), - - ?SLEEP(2000), - - ?line display_memory_usage(), - - ?line unload_master("OTP-SNMPEA-MIB"), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?line unload_master("SNMP-MPD-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-USER-BASED-SM-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - ?line unload_master("SNMPv2-MIB"), - ?line unload_master("SNMPv2-TM"), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - - ok. - - -varm_mib_start(suite) -> []; -varm_mib_start(Config) when list(Config) -> - p("varm_mib_start..."), - ?LOG("varm_mib_start -> entry", []), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - %% Start the agent - Opts = ?GCONF(agent_opts, Config), - Config1 = start_v1_agent(Config, Opts), - - %% Sleep some in order for the agent to start properly - ?DBG("varm_mib_start -> sleep some (before loading mobs)", []), - ?SLEEP(5000), - - %% Load all the mibs - HardwiredMibs = loaded_mibs(), - ?DBG("varm_mib_start -> load all mibs", []), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - - %% Unload the hardwired mibs - ?DBG("varm_mib_start -> sleep some (before unloading hardwired mibs)", []), - ?SLEEP(1000), - ?DBG("varm_mib_start -> unload (hardwired) mibs", []), - ?line unload_mibs(HardwiredMibs), %% unload hardwired - - ?DBG("varm_mib_start -> sleep some (before stopping agent)", []), - ?SLEEP(1000), - - %% Stop the agent (without deleting the stored files) - ?DBG("varm_mib_start -> stop the agent", []), - Config2 = stop_agent(Config1), - - %% Sleep some in order for the agent to stop properly - ?DBG("varm_mib_start -> sleep some (before re-starting the agent)", []), - ?SLEEP(5000), - - %% Start the agent (again) - ?DBG("varm_mib_start -> start the agent", []), - Config3 = start_v1_agent(Config2, Opts), - - ?DBG("varm_mib_start -> sleep some (before starting tests)", []), - ?SLEEP(5000), - - %% Perform the test(s) - ?DBG("varm_mib_start -> perform the tests", []), - try_test(snmp_community_mib), - try_test(snmp_framework_mib), - try_test(snmp_target_mib), - try_test(snmp_notification_mib), - - %% Stop the agent (without deleting the stored files) - ?DBG("varm_mib_start -> stop the agent", []), - stop_agent(Config3), - ok. - - --define(snmpTrapCommunity_instance, [1,3,6,1,6,3,18,1,4,0]). --define(vacmViewSpinLock_instance, [1,3,6,1,6,3,16,1,5,1,0]). --define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). - -ms_me_of(suite) -> []; -ms_me_of(Config) when list(Config) -> - p("ms_me_of..."), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - ?line load_master_std("OTP-SNMPEA-MIB"), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-MPD-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - - ?SLEEP(2000), - - ?line display_memory_usage(), - - - ?DBG("ms_me_of -> find ~w from SNMP-COMMUNITY-MIB", - [?snmpTrapCommunity_instance]), - ?line ok = me_of(?snmpTrapCommunity_instance), - - ?DBG("ms_me_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", - [?vacmViewSpinLock_instance]), - ?line ok = me_of(?vacmViewSpinLock_instance), - - ?DBG("ms_me_of -> find ~w from SNMP-USER-BASED-SM-MIB", - [?usmStatsNotInTimeWindows_instance]), - ?line {error, _} = me_of(?usmStatsNotInTimeWindows_instance), - - - ?line unload_master("OTP-SNMPEA-MIB"), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?line unload_master("SNMP-MPD-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - - ok. - -me_of(Oid) -> - case snmpa:me_of(Oid) of - {ok, #me{oid = Oid}} -> - ok; - {ok, #me{oid = OtherOid}} -> - case lists:reverse(Oid) of - [0|Rest] -> - case lists:reverse(Rest) of - OtherOid -> - ok; - AnotherOid -> - {error, {invalid_oid, Oid, AnotherOid}} - end; - _ -> - {error, {invalid_oid, Oid, OtherOid}} - end; - {error, Reason} -> - {error, Reason}; - Else -> - {error, Else} - end. - - -ms_mib_of(suite) -> []; -ms_mib_of(Config) when list(Config) -> - p("ms_mib_of..."), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - ?line load_master_std("OTP-SNMPEA-MIB"), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-MPD-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - - ?SLEEP(2000), - - ?line display_memory_usage(), - - - ?DBG("ms_mib_of -> find ~w from SNMP-COMMUNITY-MIB", - [?snmpTrapCommunity_instance]), - ?line ok = mib_of(?snmpTrapCommunity_instance, 'SNMP-COMMUNITY-MIB'), - - ?DBG("ms_mib_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", - [?vacmViewSpinLock_instance]), - ?line ok = mib_of(?vacmViewSpinLock_instance, 'SNMP-VIEW-BASED-ACM-MIB'), - - ?DBG("ms_mib_of -> find ~w from SNMP-USER-BASED-SM-MIB", - [?usmStatsNotInTimeWindows_instance]), - ?line {error, _} = mib_of(?usmStatsNotInTimeWindows_instance, - 'SNMP-USER-BASED-SM-MIB'), - - - ?line unload_master("OTP-SNMPEA-MIB"), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?line unload_master("SNMP-MPD-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - - ok. - -mib_of(Oid, ExpectedMibName) -> - ?DBG("mib_of -> entry with" - "~n Oid: ~p" - "~n ExpectedMibName: ~p", [Oid, ExpectedMibName]), - %% case snmpa:mib_of(Oid) of - MibOf = snmpa:mib_of(Oid), - ?DBG("mib_of -> MibOf: ~n~p", [MibOf]), - case MibOf of - {ok, ExpectedMibName} -> - ok; - {ok, OtherMibName} -> - {error, {invalid_mib, ExpectedMibName, OtherMibName}}; - {error, Reason} -> - {error, Reason}; - Else -> - ?DBG("mib_of -> Else: ~n~p", [Else]), - {error, Else} - end. - - -app_info(suite) -> []; -app_info(Config) when list(Config) -> - SnmpDir = app_dir(snmp), - SslDir = app_dir(ssl), - CryptoDir = app_dir(crypto), - Attr = snmp:module_info(attributes), - AppVsn = - case lists:keysearch(app_vsn, 1, Attr) of - {value, {app_vsn, V}} -> - V; - false -> - "undefined" - end, - io:format("Root dir: ~s~n" - "SNMP: Application dir: ~s~n" - " Application ver: ~s~n" - "SSL: Application dir: ~s~n" - "CRYPTO: Application dir: ~s~n", - [code:root_dir(), SnmpDir, AppVsn, SslDir, CryptoDir]), - ok. - -app_dir(App) -> - case code:lib_dir(App) of - D when list(D) -> - filename:basename(D); - {error, _Reason} -> - "undefined" - end. - - -test_v1(suite) -> {req, [], {conf, init_v1, v1_cases(), finish_v1}}. - -%v1_cases() -> [loop_mib]; -v1_cases() -> - [simple, - db_notify_client, - v1_processing, big, big2, loop_mib, - api, subagent, mnesia, multiple_reqs, - sa_register, v1_trap, sa_error, next_across_sa, undo, reported_bugs, - standard_mibs, sparse_table, cnt_64, - opaque, - % opaque]. - - change_target_addr_config]. - -init_v1(Config) when list(Config) -> - ?line SaNode = ?config(snmp_sa, Config), - ?line create_tables(SaNode), - ?line AgentDir = ?config(agent_dir, Config), - ?line MgrDir = ?config(mgr_dir, Config), - ?line Ip = ?config(ip, Config), - ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v1} | start_v1_agent(Config)]. - -finish_v1(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - -test_v2(suite) -> {req, [], {conf, init_v2, v2_cases(), finish_v2}}. - -%v2_cases() -> [loop_mib_2]; -v2_cases() -> - [simple_2, v2_processing, big_2, big2_2, loop_mib_2, - api_2, subagent_2, mnesia_2, - multiple_reqs_2, sa_register_2, v2_trap, v2_inform, sa_error_2, - next_across_sa_2, undo_2, reported_bugs_2, standard_mibs_2, - v2_types, implied, sparse_table_2, cnt_64_2, opaque_2, v2_caps]. - -init_v2(Config) when list(Config) -> - SaNode = ?config(snmp_sa, Config), - create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), - MgrDir = ?config(mgr_dir, Config), - Ip = ?config(ip, Config), - config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v2} | start_v2_agent(Config)]. - -finish_v2(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - -test_v1_v2(suite) -> {req, [], {conf, init_v1_v2, v1_v2_cases(), finish_v1_v2}}. - -v1_v2_cases() -> - [simple_bi]. - -init_v1_v2(Config) when list(Config) -> - SaNode = ?config(snmp_sa, Config), - create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), - MgrDir = ?config(mgr_dir, Config), - Ip = ?config(ip, Config), - config([v1,v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, bilingual} | start_bilingual_agent(Config)]. - -finish_v1_v2(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - -test_v3(suite) -> {req, [], {conf, init_v3, v3_cases(), finish_v3}}. - -%v3_cases() -> [loop_mib_3]; -v3_cases() -> - [simple_3, v3_processing, - big_3, big2_3, api_3, subagent_3, mnesia_3, loop_mib_3, - multiple_reqs_3, sa_register_3, v3_trap, v3_inform, sa_error_3, - next_across_sa_3, undo_3, reported_bugs_3, standard_mibs_3, - v3_security, - v2_types_3, implied_3, sparse_table_3, cnt_64_3, opaque_3, v2_caps_3]. - -init_v3(Config) when list(Config) -> - %% Make sure crypto works, otherwise start_agent will fail - %% and we will be stuck with a bunch of mnesia tables for - %% the rest of this suite... - ?DBG("start_agent -> start crypto app",[]), - case os:type() of - vxworks -> - no_crypto; - _ -> - case ?CRYPTO_START() of - ok -> - case ?CRYPTO_SUPPORT() of - {no, Reason} -> - ?SKIP({unsupported_encryption, Reason}); - yes -> - ok - end; - {error, Reason} -> - ?SKIP({failed_starting_crypto, Reason}) - end - end, - SaNode = ?config(snmp_sa, Config), - create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), - MgrDir = ?config(mgr_dir, Config), - Ip = ?config(ip, Config), - ?line ok = config([v3], MgrDir, AgentDir, - tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v3} | start_v3_agent(Config)]. - -finish_v3(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - -test_multi_threaded(suite) -> {req, [], {conf, init_mt, mt_cases(), finish_mt}}. - -mt_cases() -> - [multi_threaded, mt_trap]. - -init_mt(Config) when list(Config) -> - SaNode = ?config(snmp_sa, Config), - create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), - MgrDir = ?config(mgr_dir, Config), - Ip = ?config(ip, Config), - ?line ok = config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v2} | start_multi_threaded_agent(Config)]. - -finish_mt(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - -%% This one *must* be run first in each case. -init_case(Config) when list(Config) -> - ?DBG("init_case -> entry with" - "~n Config: ~p", [Config]), - SaNode = ?config(snmp_sa, Config), - MgrNode = ?config(snmp_mgr, Config), - MasterNode = node(), - - SaHost = ?HOSTNAME(SaNode), - MgrHost = ?HOSTNAME(MgrNode), - MasterHost = ?HOSTNAME(MasterNode), - {ok, MasterIP} = snmp_misc:ip(MasterHost), - {ok, MIP} = snmp_misc:ip(MgrHost), - {ok, SIP} = snmp_misc:ip(SaHost), - - - put(mgr_node, MgrNode), - put(sa_node, SaNode), - put(master_node, MasterNode), - put(sa_host, SaHost), - put(mgr_host, MgrHost), - put(master_host, MasterHost), - put(mip, tuple_to_list(MIP)), - put(masterip , tuple_to_list(MasterIP)), - put(sip, tuple_to_list(SIP)), - - MibDir = ?config(mib_dir, Config), - put(mib_dir, MibDir), - StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", - put(std_mib_dir, StdM), - - MgrDir = ?config(mgr_dir, Config), - put(mgr_dir, MgrDir), - - put(vsn, ?config(vsn, Config)), - ?DBG("init_case -> exit with" - "~n MasterNode: ~p" - "~n SaNode: ~p" - "~n MgrNode: ~p" - "~n MibDir: ~p", [MasterNode, SaNode, MgrNode, MibDir]), - {SaNode, MgrNode, MibDir}. - -load_master(Mib) -> - ?DBG("load_master -> entry with" - "~n Mib: ~p", [Mib]), - snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety - ok = snmpa:load_mibs(snmp_master_agent, [get(mib_dir) ++ Mib]). - -load_master_std(Mib) -> - ?DBG("load_master_std -> entry with" - "~n Mib: ~p", [Mib]), - snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety - ok = snmpa:load_mibs(snmp_master_agent, [get(std_mib_dir) ++ Mib]). - -unload_master(Mib) -> - ?DBG("unload_master -> entry with" - "~n Mib: ~p", [Mib]), - ok = snmpa:unload_mibs(snmp_master_agent, [Mib]). - -loaded_mibs() -> - ?DBG("loaded_mibs -> entry",[]), - Info = snmpa:info(snmp_master_agent), - {value, {loaded_mibs, Mibs}} = lists:keysearch(loaded_mibs, 1, Info), - [atom_to_list(Mib) || {Mib,_,_} <- Mibs]. - -unload_mibs(Mibs) -> - ?DBG("unload_mibs -> entry with" - "~n Mibs: ~p", [Mibs]), - ok = snmpa:unload_mibs(snmp_master_agent, Mibs). - -start_subagent(SaNode, RegTree, Mib) -> - ?DBG("start_subagent -> entry with" - "~n SaNode: ~p" - "~n RegTree: ~p" - "~n Mib: ~p", [SaNode, RegTree, Mib]), - MA = whereis(snmp_master_agent), - ?DBG("start_subagent -> MA: ~p", [MA]), - MibDir = get(mib_dir), - Mib1 = join(MibDir,Mib), - %% BMK BMK -% case rpc:call(SaNode,snmp_supervisor,start_subagent,[MA,RegTree,[Mib1]]) of - case rpc:call(SaNode, snmpa_supervisor, - start_sub_agent, [MA, RegTree, [Mib1]]) of - {ok, SA} -> - ?DBG("start_subagent -> SA: ~p", [SA]), - {ok, SA}; - Error -> - ?FAIL({subagent_start_failed, SaNode, Error, [MA, RegTree, Mib1]}) - end. - -stop_subagent(SA) -> - ?DBG("stop_subagent -> entry with" - "~n SA: ~p", [SA]), - %% BNK BMK - %% rpc:call(node(SA), snmp_supervisor, stop_subagent, [SA]). - rpc:call(node(SA), snmpa_supervisor, stop_sub_agent, [SA]). - -%%----------------------------------------------------------------- -%% This function takes care of the old OTP-SNMPEA-MIB. -%% Unfortunately, the testcases were written to use the data in the -%% internal tables, and these table are now obsolete and not used -%% by the agent. Therefore, we emulate them by using -%% OLD-SNMPEA-MIB, which uses the default impl. of all tables. -%% -%% These two rows must exist in intCommunityTable -%% {[147,214,36,45], "public", 2, readWrite}. -%% {[147,214,36,45], "standard trap", 2, read}. -%% (But with the manager's IP address) -%% -%%----------------------------------------------------------------- -init_old() -> - snmpa_local_db:table_create_row(intCommunityTable, - get(mip) ++ [6 | "public"], - {get(mip), "public", 2, 2}), - snmpa_local_db:table_create_row(intCommunityTable, - get(mip) ++ [13 | "standard trap"], - {get(mip), "standard trap", 2, 1}), - snmpa_local_db:variable_set(intAgentIpAddress, [127,0,0,1]). - - - -simple(suite) -> []; -simple(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - try_test(simple_standard_test). - -simple_2(X) -> simple(X). - -simple_bi(suite) -> []; -simple_bi(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - put(vsn, v1), % First, try v1 manager - try_test(simple_standard_test), - - put(vsn, v2), % Then, try v2 manager - try_test(simple_standard_test). - -simple_3(X) -> - simple(X). - -big(suite) -> []; -big(Config) when list(Config) -> - ?DBG("big -> entry", []), - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Starting subagent..."), - ?line pong = net_adm:ping(SaNode), - - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), - ?DBG("big -> SA: ~p", [SA]), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(big_test), - ?line stop_subagent(SA), - ?line unload_master("OLD-SNMPEA-MIB"). - -big_2(X) -> big(X). - -big_3(X) -> big(X). - - -big2(suite) -> []; -big2(Config) when list(Config) -> - %% This is exactly the same tests as 'big', but with the - %% v2 equivalent of the mibs. - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Starting subagent..."), - ?line pong = net_adm:ping(SaNode), - - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1-v2"), - ?line load_master("OLD-SNMPEA-MIB-v2"), - ?line init_old(), - try_test(big_test), - ?line stop_subagent(SA), - ?line unload_master("OLD-SNMPEA-MIB-v2"). - -big2_2(X) -> big2(X). - -big2_3(X) -> big2(X). - - -multi_threaded(suite) -> []; -multi_threaded(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test1"), - try_test(multi_threaded_test), - ?line unload_master("Test1"). - -mt_trap(suite) -> []; -mt_trap(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line load_master("Test1"), - ?line load_master("TestTrapv2"), - try_test(mt_trap_test, [MA]), - ?line unload_master("TestTrapv2"), - ?line unload_master("Test1"). - -v2_types(suite) -> []; -v2_types(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test1"), - try_test(types_v2_test), - ?line unload_master("Test1"). - -v2_types_3(X) -> v2_types(X). - - -implied(suite) -> []; -implied(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line load_master("Test1"), - try_test(implied_test,[MA]), - ?line unload_master("Test1"). - -implied_3(X) -> implied(X). - - -sparse_table(suite) -> []; -sparse_table(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test1"), - try_test(sparse_table_test), - ?line unload_master("Test1"). - -sparse_table_2(X) -> sparse_table(X). - -sparse_table_3(X) -> sparse_table(X). - -cnt_64(suite) -> []; -cnt_64(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line load_master("Test1"), - try_test(cnt_64_test, [MA]), - ?line unload_master("Test1"). - -cnt_64_2(X) -> cnt_64(X). - -cnt_64_3(X) -> cnt_64(X). - -opaque(suite) -> []; -opaque(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test1"), - try_test(opaque_test), - ?line unload_master("Test1"). - -opaque_2(X) -> opaque(X). - -opaque_3(X) -> opaque(X). - - -change_target_addr_config(suite) -> []; -change_target_addr_config(Config) when list(Config) -> - p("Testing changing target address config..."), - ?LOG("change_target_addr_config -> entry",[]), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - put(sname,snmp_suite), - put(verbosity,trace), - - MA = whereis(snmp_master_agent), - - ?LOG("change_target_addr_config -> load TestTrap",[]), - ?line load_master("TestTrap"), - - ?LOG("change_target_addr_config -> set trace verbosity for local_db",[]), - ?line snmpa:verbosity(local_db,trace), - - %% First send some traps that will arive att the original manager - ?LOG("change_target_addr_config -> send trap",[]), - try_test(ma_trap1, [MA]), - - ?LOG("change_target_addr_config -> set silence verbosity for local_db",[]), - ?line snmpa:verbosity(local_db,silence), - - %% Start new dummy listener - ?LOG("change_target_addr_config -> start dummy manager",[]), - ?line {ok,Pid,NewPort} = dummy_manager_start(MA), - - %% Reconfigure - ?LOG("change_target_addr_config -> reconfigure",[]), - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_addr_conf(AgentDir, NewPort), - ?line snmp_target_mib:reconfigure(AgentDir), - - %% Send the trap again - ?LOG("change_target_addr_config -> send trap again",[]), - catch dummy_manager_send_trap2(Pid), - - ?LOG("change_target_addr_config -> await trap ack",[]), - catch dummy_manager_await_trap2_ack(), - - ?LOG("change_target_addr_config -> stop dummy manager",[]), - ?line ok = dummy_manager_stop(Pid), - - ?LOG("change_target_addr_config -> reset target address config",[]), - ?line reset_target_addr_conf(AgentDir), - - ?LOG("change_target_addr_config -> unload TestTrap",[]), - ?line unload_master("TestTrap"). - - -dummy_manager_start(MA) -> - ?DBG("dummy_manager_start -> entry",[]), - Pid = spawn(get(mgr_node), ?MODULE,dummy_manager_init,[self(),MA]), - ?DBG("dummy_manager_start -> Pid: ~p",[Pid]), - await_dummy_manager_started(Pid). - -await_dummy_manager_started(Pid) -> - receive - {dummy_manager_started,Pid,Port} -> - ?DBG("dummy_manager_start -> acknowledge received with" - "~n Port: ~p",[Port]), - {ok,Pid,Port}; - {'EXIT', Pid, Reason} -> - {error, Pid, Reason}; - O -> - ?LOG("dummy_manager_start -> received unknown message:" - "~n ~p",[O]), - await_dummy_manager_started(Pid) - end. - -dummy_manager_stop(Pid) -> - ?DBG("dummy_manager_stop -> entry with Pid: ~p",[Pid]), - Pid ! stop, - receive - {dummy_manager_stopping, Pid} -> - ?DBG("dummy_manager_stop -> acknowledge received",[]), - ok - after 10000 -> - ?ERR("dummy_manager_stop -> timeout",[]), - timeout - end. - -dummy_manager_send_trap2(Pid) -> - ?DBG("dummy_manager_send_trap2 -> entry",[]), - Pid ! {send_trap,testTrap2}. - -dummy_manager_await_trap2_ack() -> - ?DBG("dummy_manager_await_trap2 -> entry",[]), - receive - {received_trap,Trap} -> - ?LOG("dummy_manager_await_trap2 -> received trap: ~p",[Trap]), - %% Note: - %% Without this sleep the v2_inform_i testcase failes! There - %% is no relation between these two test cases as far as I - %% able to figure out... - sleep(60000), - ok; - O -> - ?ERR("dummy_manager_await_trap2 -> unexpected message: ~p",[O]), - ok - after 10000 -> - ?ERR("dummy_manager_await_trap2 -> timeout",[]), - timeout - end. - -dummy_manager_init(Parent,MA) -> - ?DBG("dummy_manager_init -> entry with" - "~n Parent: ~p" - "~n MA: ~p",[Parent,MA]), - {ok,S} = gen_udp:open(0,[{recbuf,65535}]), - ?DBG("dummy_manager_init -> S: ~p",[S]), - {ok,Port} = inet:port(S), - ?DBG("dummy_manager_init -> Port: ~p",[Port]), - Parent ! {dummy_manager_started,self(),Port}, - dummy_manager_loop(Parent,S,MA). - -dummy_manager_loop(P,S,MA) -> - ?LOG("dummy_manager_loop -> ready for receive",[]), - receive - {send_trap,Trap} -> - ?LOG("dummy_manager_loop -> received trap send request" - "~n Trap: ~p",[Trap]), - snmpa:send_trap(MA, Trap, "standard trap"), - dummy_manager_loop(P,S,MA); - {udp, _UdpId, Ip, UdpPort, Bytes} -> - ?LOG("dummy_manager_loop -> received upd message" - "~n from: ~p:~p" - "~n size: ~p", - [Ip, UdpPort, dummy_manager_message_sz(Bytes)]), - R = dummy_manager_handle_message(Bytes), - ?DBG("dummy_manager_loop -> R: ~p",[R]), - P ! R, - dummy_manager_loop(P,S,MA); - stop -> - ?DBG("dummy_manager_loop -> received stop request",[]), - P ! {dummy_manager_stopping, self()}, - gen_udp:close(S), - exit(normal); - O -> - ?LOG("dummy_manager_loop -> received unknown message:" - "~n ~p",[O]), - dummy_manager_loop(P,S,MA) - end. - -dummy_manager_message_sz(B) when binary(B) -> - size(B); -dummy_manager_message_sz(L) when list(L) -> - length(L); -dummy_manager_message_sz(_) -> - undefined. - -dummy_manager_handle_message(Bytes) -> - case (catch snmp_pdus:dec_message(Bytes)) of - {'EXIT',Reason} -> - ?ERR("dummy_manager_handle_message -> " - "failed decoding message only:~n ~p",[Reason]), - {error,Reason}; - M -> - ?DBG("dummy_manager_handle_message -> decoded message:" - "~n ~p",[M]), - {received_trap,M} - end. - - -api(suite) -> []; -api(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(api_test, [node()]), - ?line unload_master("OLD-SNMPEA-MIB"). - -api_2(X) -> api(X). - -api_3(X) -> api(X). - - -subagent(suite) -> []; -subagent(Config) when list(Config) -> - {SaNode, _MgrNode, MibDir} = init_case(Config), - - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), - try_test(load_test_sa), - - p("Testing unregister subagent..."), - MA = whereis(snmp_master_agent), - rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), - try_test(unreg_test), - - p("Loading previous subagent mib in master and testing..."), - ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas1"]), - try_test(load_test), - - p("Unloading previous subagent mib in master and testing..."), - ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas1"]), - try_test(unreg_test), - p("Testing register subagent..."), - rpc:call(SaNode, snmp, register_subagent, - [MA, ?klas1, SA]), - try_test(load_test_sa), - - ?line stop_subagent(SA), - try_test(unreg_test). - -subagent_2(X) -> subagent(X). - -subagent_3(X) -> subagent(X). - - -mnesia(suite) -> []; -mnesia(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Starting subagent with mnesia impl..."), - {ok, SA} = start_subagent(SaNode, ?klas2, "Klas2"), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - - try_test(big_test_2), - - p("Testing unregister subagent..."), - MA = whereis(snmp_master_agent), - rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), - try_test(unreg_test), - ?line unload_master("OLD-SNMPEA-MIB"), - ?line stop_subagent(SA). - -mnesia_2(X) -> mnesia(X). - -mnesia_3(X) -> mnesia(X). - - -multiple_reqs(suite) -> - {req, [], {conf, init_mul, mul_cases(), finish_mul}}. - -mul_cases() -> - [mul_get, mul_get_err, mul_next, mul_next_err, mul_set_err]. - -multiple_reqs_2(suite) -> - {req, [], {conf, init_mul, mul_cases_2(), finish_mul}}. - -multiple_reqs_3(_X) -> - {req, [], {conf, init_mul, mul_cases_3(), finish_mul}}. - - -mul_cases_2() -> - [mul_get_2, mul_get_err_2, mul_next_2, mul_next_err_2, mul_set_err_2]. - - -mul_cases_3() -> - [mul_get_3, mul_get_err_3, mul_next_3, mul_next_err_3, mul_set_err_3]. - - -init_mul(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - [{mul_sub, SA} | Config]. - -finish_mul(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - SA = ?config(mul_sub, Config), - - ?line unload_master("OLD-SNMPEA-MIB"), - ?line stop_subagent(SA), - lists:keydelete(mul_sub, 1, Config). - -mul_get(suite) -> []; -mul_get(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple get..."), - try_test(do_mul_get). - -mul_get_2(X) -> mul_get(X). - -mul_get_3(X) -> mul_get(X). - - -mul_get_err(suite) -> []; -mul_get_err(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple get with error..."), - try_test(do_mul_get_err). - -mul_get_err_2(X) -> mul_get_err(X). - -mul_get_err_3(X) -> mul_get_err(X). - - -mul_next(suite) -> []; -mul_next(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple next..."), - try_test(do_mul_next). - -mul_next_2(X) -> mul_next(X). - -mul_next_3(X) -> mul_next(X). - - -mul_next_err(suite) -> []; -mul_next_err(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple next..."), - try_test(do_mul_next_err). - -mul_next_err_2(X) -> mul_next_err(X). - -mul_next_err_3(X) -> mul_next_err(X). - - -mul_set(suite) -> []; -mul_set(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple set..."), - try_test(do_mul_set). - -mul_set_2(X) -> mul_set(X). - -mul_set_3(X) -> mul_set(X). - - -mul_set_err(suite) -> []; -mul_set_err(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple set with error..."), - try_test(do_mul_set_err). - -mul_set_err_2(X) -> mul_set_err(X). - -mul_set_err_3(X) -> mul_set_err(X). - - -sa_register(suite) -> []; -sa_register(Config) when list(Config) -> - ?DBG("sa_register -> entry", []), - {SaNode, _MgrNode, MibDir} = init_case(Config), - - ?DBG("sa_register -> start subagent", []), - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), - - ?DBG("sa_register -> unregister subagent", []), - p("Testing unregister subagent (2)..."), - MA = whereis(snmp_master_agent), - rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), - try_test(unreg_test), - - p("Loading SA-MIB..."), - ?DBG("sa_register -> unload mibs", []), - snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), - ?DBG("sa_register -> unload mibs", []), - snmpa:load_mibs(SA, [MibDir ++ "SA-MIB"]), - ?DBG("sa_register -> register subagent", []), - rpc:call(SaNode, snmp, register_subagent, [MA,?sa,SA]), - try_test(sa_mib), - - ?DBG("sa_register -> stop subagent", []), - ?line stop_subagent(SA). - -sa_register_2(X) -> sa_register(X). - -sa_register_3(X) -> sa_register(X). - - -v1_trap(suite) -> []; -v1_trap(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Testing trap sending from master agent..."), - MA = whereis(snmp_master_agent), - - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(ma_trap1, [MA]), - try_test(ma_trap2, [MA]), - try_test(ma_v2_2_v1_trap, [MA]), - try_test(ma_v2_2_v1_trap2, [MA]), - - p("Testing trap sending from subagent..."), - try_test(sa_trap1, [SA]), - try_test(sa_trap2, [SA]), - try_test(sa_trap3, [SA]), - - ?line unload_master("TestTrap"), - ?line unload_master("TestTrapv2"), - - ?line stop_subagent(SA). - -v2_trap(suite) -> []; -v2_trap(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Testing trap sending from master agent..."), - MA = whereis(snmp_master_agent), - - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - - try_test(ma_v2_trap1, [MA]), - try_test(ma_v2_trap2, [MA]), - try_test(ma_v1_2_v2_trap, [MA]), - try_test(ma_v1_2_v2_trap2, [MA]), - - try_test(sa_mib), - p("Testing trap sending from subagent..."), - try_test(sa_v1_2_v2_trap1, [SA]), - try_test(sa_v1_2_v2_trap2, [SA]), - try_test(sa_v1_2_v2_trap3, [SA]), - - ?line unload_master("TestTrap"), - ?line unload_master("TestTrapv2"), - - ?line stop_subagent(SA). - -v3_trap(X) -> - v2_trap(X). - -v2_inform(suite) -> - {req, [], {conf, init_v2_inform, [v2_inform_i], finish_v2_inform}}. - -v3_inform(_X) -> - %% v2_inform(X). - {req, [], {conf, init_v3_inform, [v3_inform_i], finish_v3_inform}}. - -init_v2_inform(Config) when list(Config) -> - _Dir = ?config(agent_dir, Config), -% snmp_internal_mib:configure(Dir), - Config. - -init_v3_inform(X) -> - init_v2_inform(X). - -finish_v2_inform(Config) when list(Config) -> - _Dir = ?config(agent_dir, Config), -% snmp_internal_mib:configure(Dir), - Config. - -finish_v3_inform(X) -> - finish_v2_inform(X). - - - -v2_inform_i(suite) -> []; -v2_inform_i(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing inform sending from master agent... NOTE! This test\ntakes a " - "few minutes (5) to complete."), - MA = whereis(snmp_master_agent), - - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(ma_v2_inform1, [MA]), - - ?line unload_master("TestTrap"), - ?line unload_master("TestTrapv2"). - -v3_inform_i(X) -> v2_inform_i(X). - - -sa_error(suite) -> []; -sa_error(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Testing sa bad value (is_set_ok)..."), - try_test(sa_errs_bad_value), - - p("Testing sa gen err (set)..."), - try_test(sa_errs_gen_err), - - p("Testing too big..."), - try_test(sa_too_big), - - ?line unload_master("OLD-SNMPEA-MIB"), - stop_subagent(SA). - -sa_error_2(X) -> sa_error(X). - -sa_error_3(X) -> sa_error(X). - - -next_across_sa(suite) -> []; -next_across_sa(Config) when list(Config) -> - {SaNode, _MgrNode, MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Loading another subagent mib..."), - ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas1"]), - - rpc:call(SaNode, snmp, register_subagent, [MA, ?klas1, SA]), - try_test(load_test_sa), - - p("Testing next across subagent (endOfMibView from SA)..."), - try_test(next_across_sa), - - p("Unloading mib"), - snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), - rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), - try_test(unreg_test), - - p("Starting another subagent"), - ?line {ok, SA2} = start_subagent(SaNode, ?klas1, "Klas1"), - p("Testing next across subagent (wrong prefix from SA)..."), - try_test(next_across_sa), - - stop_subagent(SA), - stop_subagent(SA2). - -next_across_sa_2(X) -> next_across_sa(X). - -next_across_sa_3(X) -> next_across_sa(X). - - -undo(suite) -> []; -undo(Config) when list(Config) -> - {SaNode, _MgrNode, MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Testing undo phase at master agent..."), - ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas3"]), - ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas4"]), - try_test(undo_test), - try_test(api_test2), - ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas3"]), - - p("Testing bad return values from instrum. funcs..."), - try_test(bad_return), - - ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas4"]), - - p("Testing undo phase at subagent..."), - ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas3"]), - ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas4"]), - ?line ok = snmpa:register_subagent(MA, ?klas3, SA), - ?line ok = snmpa:register_subagent(MA, ?klas4, SA), - try_test(undo_test), - try_test(api_test3), - - p("Testing undo phase across master/subagents..."), - try_test(undo_test), - try_test(api_test3), - stop_subagent(SA). - -undo_2(X) -> undo(X). - -undo_3(X) -> undo(X). - -%% Req. Test2 -v1_processing(suite) -> []; -v1_processing(Config) when list(Config) -> - ?DBG("v1_processing -> entry", []), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - try_test(v1_proc), - ?line unload_master("Test2"). - -%% Req. Test2 -v2_processing(suite) -> []; -v2_processing(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - try_test(v2_proc), - ?line unload_master("Test2"). - -%% Req. Test2 -v3_processing(suite) -> []; -v3_processing(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - try_test(v2_proc), % same as v2! - ?line unload_master("Test2"). - - -%% We'll try get/set/trap and inform for all the auth & priv protocols. -%% For informs, the mgr is auth-engine. The agent has to sync. This is -%% accomplished by the first inform sent. That one will generate a -%% report, which makes it in sync. The notification-generating -%% application times out, and send again. This time it'll work. -v3_security(suite) -> [v3_crypto_basic, v3_md5_auth, v3_sha_auth, v3_des_priv]. - -v3_crypto_basic(suite) -> []; -v3_crypto_basic(_Config) -> - EID = [0,0,0,0,0,0,0,0,0,0,0,2], - %% From rfc2274 appendix A.3.1 - ?line KMd5_1 = snmp:passwd2localized_key(md5, "maplesyrup", EID), - ?line [16#52,16#6f,16#5e,16#ed,16#9f,16#cc,16#e2,16#6f, - 16#89,16#64,16#c2,16#93,16#07,16#87,16#d8,16#2b] = - KMd5_1, - %% From rfc2274 appendix A.3.2 - ?line KSHA_1 = snmp:passwd2localized_key(sha, "maplesyrup", EID), - ?line [16#66,16#95,16#fe,16#bc,16#92,16#88,16#e3,16#62,16#82,16#23, - 16#5f,16#c7,16#15,16#1f,16#12,16#84,16#97,16#b3,16#8f,16#3f] = - KSHA_1, - %% From rfc2274, appendix A.5.1 - ?line KMd5_2 = snmp:passwd2localized_key(md5, "newsyrup", EID), - ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#88,16#05,16#61,16#51,16#41,16#67,16#6c,16#c9, - 16#19,16#61,16#74,16#e7,16#42,16#a3,16#25,16#51] = - snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2, 16, - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), - %% From rfc2274, appendix A.5.2 - ?line KSHA_2 = snmp:passwd2localized_key(sha, "newsyrup", EID), - ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#00,16#00,16#00,16#00,16#9c,16#10,16#17,16#f4, - 16#fd,16#48,16#3d,16#2d,16#e8,16#d5,16#fa,16#db, - 16#f8,16#43,16#92,16#cb,16#06,16#45,16#70,16#51] = - snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2, 20, - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), - KSHA_1t = lists:sublist(KSHA_1, 16), - KSHA_2t = lists:sublist(KSHA_2, 16), - ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#7e,16#f8,16#d8,16#a4,16#c9,16#cd,16#b2,16#6b, - 16#47,16#59,16#1c,16#d8,16#52,16#ff,16#88,16#b5] = - snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1t, KSHA_2t, 16, - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), - - %% Try with correct random - ?line Kc1 = snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2), - ?line KMd5_2 = snmp_user_based_sm_mib:extract_new_key(md5, KMd5_1, Kc1), - ?line Kc2 = snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2), - ?line KSHA_2 = snmp_user_based_sm_mib:extract_new_key(sha, KSHA_1, Kc2), - ok. - - - -v3_md5_auth(suite) -> []; -v3_md5_auth(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - p("Testing MD5 authentication...takes a few seconds..."), - - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_params_conf(AgentDir, "authMD5", authNoPriv), - ?line snmp_target_mib:reconfigure(AgentDir), - - MA = whereis(snmp_master_agent), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(v3_sync, [[{v2_proc, []}, - {ma_v2_trap1, [MA]}, - {v3_inform_sync, [MA]}]], - [{sec_level, authNoPriv}, {user, "authMD5"}]), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - ?line reset_target_params_conf(AgentDir). - -v3_sha_auth(suite) -> []; -v3_sha_auth(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - p("Testing SHA authentication...takes a few seconds..."), - - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_params_conf(AgentDir, "authSHA", authNoPriv), - ?line snmp_target_mib:reconfigure(AgentDir), - - MA = whereis(snmp_master_agent), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(v3_sync, [[{v2_proc, []}, - {ma_v2_trap1, [MA]}, - {v3_inform_sync, [MA]}]], - [{sec_level, authNoPriv}, {user, "authSHA"}]), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - ?line reset_target_params_conf(AgentDir). - -v3_des_priv(suite) -> []; -v3_des_priv(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - p("Testing DES encryption...takes a few seconds..."), - - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_params_conf(AgentDir, "privDES", authPriv), - ?line snmp_target_mib:reconfigure(AgentDir), - - MA = whereis(snmp_master_agent), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(v3_sync, [[{v2_proc, []}, - {ma_v2_trap1, [MA]}, - {v3_inform_sync, [MA]}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - ?line reset_target_params_conf(AgentDir). - -%% -define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). - -%% Make sure mgr is in sync with agent -v3_sync(Funcs) -> - ?DBG("v3_sync -> entry with Funcs: ~p",[Funcs]), - g([[sysDescr, 0]]), - expect(432, report, [{?usmStatsNotInTimeWindows_instance, any}]), - g([[sysDescr, 0]]), - expect(433, [{[sysDescr,0], any}]), - lists:foreach(fun({Func, Args}) -> apply(?MODULE, Func, Args) end, Funcs). - -v3_inform_sync(MA) -> - ?DBG("v3_sync -> entry with MA: ~p => Send notification",[MA]), - ?line snmpa:send_notification(MA, testTrapv22, no_receiver, - "standard inform", []), - %% Make sure agent is in sync with mgr... - ?DBG("v3_sync -> wait some time: ",[]), - sleep(20000), % more than 1500*10 in target_addr.conf - ?DBG("v3_sync -> await response",[]), - ?line expect(1, {inform, true}, - [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]). - - -v2_caps(suite) -> []; -v2_caps(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - try_test(v2_caps_i, [node()]). - -v2_caps_3(X) -> v2_caps(X). - - -v2_caps_i(Node) -> - ?line Idx = rpc:call(Node, snmp, add_agent_caps, [[1,2,3,4,5], "test cap"]), - g([[sysORID, Idx], [sysORDescr, Idx]]), - ?line expect(1, [{[sysORID, Idx], [1,2,3,4,5]}, - {[sysORDescr, Idx], "test cap"}]), - ?line rpc:call(Node, snmp, del_agent_caps, [Idx]), - g([[sysORID, Idx]]), - ?line expect(2, [{[sysORID, Idx], noSuchInstance}]). - - -%% Req. Test2 -v1_proc() -> - ?DBG("v1_proc -> entry", []), - %% According to RFC1157. - %% Template:
: - v1_get_p(), - v1_get_next_p(), - v1_set_p(). - - -v1_get_p() -> - %% 4.1.2:1 - g([[test2]]), - ?line expect(10, noSuchName, 1, [{[test2], 'NULL'}]), - g([[tDescr]]), - ?line expect(11, noSuchName, 1, [{[tDescr], 'NULL'}]), - g([[tDescr2,0]]), - ?line expect(12, noSuchName, 1, [{[tDescr2,0], 'NULL'}]), - g([[tDescr3,0]]), - ?line expect(131, noSuchName, 1, [{[tDescr3,0], 'NULL'}]), - g([[tDescr4,0]]), - ?line expect(132, noSuchName, 1, [{[tDescr4,0], 'NULL'}]), - g([[sysDescr, 0], [tDescr,0]]), % Outside mibview - ?line expect(14, noSuchName, 2, [{[sysDescr, 0], 'NULL'}, - {[tDescr,0], 'NULL'}]), - g([[sysDescr,3]]), - ?line expect(15, noSuchName, 1, [{[sysDescr, 3], 'NULL'}]), - - %% 4.1.2:2 - g([[tTable]]), - ?line expect(20, noSuchName, 1, [{[tTable], 'NULL'}]), - g([[tEntry]]), - ?line expect(21, noSuchName, 1, [{[tEntry], 'NULL'}]), - - %% 4.1.2:3 - g([[tTooBig, 0]]), - ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), - - %% 4.1.2:4 - g([[tGenErr1, 0]]), - ?line expect(40, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), - g([[tGenErr2, 0]]), - ?line expect(41, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), - g([[sysDescr, 0], [tGenErr3, 0]]), - ?line expect(42, genErr, 2, [{[sysDescr, 0], 'NULL'}, - {[tGenErr3, 0], 'NULL'}]). - - -v1_get_next_p() -> - %% 4.1.3:1 - gn([[1,3,7,1]]), - ?line expect(10, noSuchName, 1, [{[1,3,7,1], 'NULL'}]), - gn([[tDescr2]]), - ?line expect(11, tooBig, 0, any), - - %% 4.1.3:2 - gn([[tTooBig]]), - io:format("We currently don't handle tooBig correct!!!\n"), -% ?line expect(20, tooBig, 0, [{[tTooBig], 'NULL'}]), - ?line expect(20, tooBig, 0, any), - - %% 4.1.3:3 - gn([[tGenErr1]]), -% ?line expect(40, genErr, 1, [{[tGenErr1], 'NULL'}]), - ?line expect(40, genErr, 1, any), - gn([[tGenErr2]]), -% ?line expect(41, genErr, 1, [{[tGenErr2], 'NULL'}]), - ?line expect(41, genErr, 1, any), - gn([[sysDescr], [tGenErr3]]), -% ?line expect(42, genErr, 2, [{[sysDescr], 'NULL'}, -% {[tGenErr3], 'NULL'}]). - ?line expect(42, genErr, 2, any). - -v1_set_p() -> - %% 4.1.5:1 - s([{[1,3,7,0], i, 4}]), - ?line expect(10, noSuchName, 1, [{[1,3,7,0], 4}]), - s([{[tDescr,0], s, "outside mibview"}]), - ?line expect(11, noSuchName, 1, [{[tDescr,0], "outside mibview"}]), - s([{[tDescr3,0], s, "read-only"}]), - ?line expect(12, noSuchName, 1, [{[tDescr3,0], "read-only"}]), - s([{[tDescr3], s, "noSuchObject"}]), - ?line expect(13, noSuchName, 1, [{[tDescr3], "noSuchObject"}]), - s([{[tDescr3,1], s, "noSuchInstance"}]), - ?line expect(14, noSuchName, 1, [{[tDescr3,1], "noSuchInstance"}]), - s([{[tDescr2,0], s, "inconsistentName"}]), - ?line expect(15, noSuchName, 1, [{[tDescr2,0], "inconsistentName"}]), - - %% 4.1.5:2 - s([{[tDescr2, 0], i, 4}]), - ?line expect(20, badValue, 1, [{[tDescr2, 0], 4}]), - s([{[tDescr2, 0], s, "badValue"}]), - ?line expect(21, badValue, 1, [{[tDescr2, 0], "badValue"}]), - - %% 4.1.5:3 - %% The standard is quite incorrect here. The resp pdu was too big. In - %% the resp pdu, we have the original vbs. In the tooBig pdu we still - %% have to original vbs => the tooBig pdu is too big as well!!! It - %% may not get it to the manager, unless the agent uses 'NULL' instead - %% of the std-like original value. - s([{[tTooBig, 0], s, ?tooBigStr}]), - %% according to std: -% ?line expect(30, tooBig, 0, [{[tTooBig, 0], ?tooBigStr}]), - ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), - - %% 4.1.5:4 - s([{[tDescr2, 0], s, "is_set_ok_fail"}]), - ?line expect(40, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]), - s([{[tDescr2, 0], s, "commit_fail"}]), - ?line expect(41, genErr, 1, [{[tDescr2, 0], "commit_fail"}]). - -%% Req. Test2 -v2_proc() -> - %% According to RFC1905. - %% Template:
: - ?DBG("v2_proc -> entry",[]), - v2_get_p(), - v2_get_next_p(), - v2_get_bulk_p(), - v2_set_p(). - -v2_get_p() -> - %% 4.2.1:2 - ?DBG("v2_get_p -> entry",[]), - g([[test2]]), - ?line expect(10, [{[test2], noSuchObject}]), - g([[tDescr]]), - ?line expect(11, [{[tDescr], noSuchObject}]), - g([[tDescr4,0]]), - ?line expect(12, [{[tDescr4,0], noSuchObject}]), - g([[sysDescr, 0], [tDescr,0]]), % Outside mibview - ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}, - {[tDescr,0], noSuchObject}]), - g([[tTable]]), - ?line expect(14, [{[tTable], noSuchObject}]), - g([[tEntry]]), - ?line expect(15, [{[tEntry], noSuchObject}]), - - %% 4.2.1:3 - g([[tDescr2,0]]), %% instrum ret noSuchName!!! - ?line expect(20, [{[tDescr2,0], noSuchInstance}]), - g([[tDescr3,0]]), - ?line expect(21, [{[tDescr3,0], noSuchInstance}]), - g([[sysDescr,3]]), - ?line expect(22, [{[sysDescr, 3], noSuchInstance}]), - g([[tIndex,1]]), - ?line expect(23, [{[tIndex, 1], noSuchInstance}]), - - %% 4.2.1 - any other error: genErr - g([[tGenErr1, 0]]), - ?line expect(30, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), - g([[tGenErr2, 0]]), - ?line expect(31, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), - g([[sysDescr, 0], [tGenErr3, 0]]), - ?line expect(32, genErr, 2, [{[sysDescr, 0], 'NULL'}, - {[tGenErr3, 0], 'NULL'}]), - - %% 4.2.1 - tooBig - g([[tTooBig, 0]]), - ?line expect(40, tooBig, 0, []). - - -v2_get_next_p() -> - %% 4.2.2:2 - ?DBG("v2_get_next_p -> entry",[]), - gn([[1,3,7,1]]), - ?line expect(10, [{[1,3,7,1], endOfMibView}]), - gn([[sysDescr], [1,3,7,1]]), - ?line expect(11, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}]), - gn([[tCnt2, 1]]), - ?line expect(12, [{[tCnt2,2], 100}]), - gn([[tCnt2, 2]]), - ?line expect(12, [{[tCnt2,2], endOfMibView}]), - - %% 4.2.2 - any other error: genErr - gn([[tGenErr1]]), - ?line expect(20, genErr, 1, [{[tGenErr1], 'NULL'}]), - gn([[tGenErr2]]), - ?line expect(21, genErr, 1, [{[tGenErr2], 'NULL'}]), - gn([[sysDescr], [tGenErr3]]), - ?line expect(22, genErr, 2, [{[sysDescr], 'NULL'}, - {[tGenErr3], 'NULL'}]), - - %% 4.2.2 - tooBig - gn([[tTooBig]]), - ?line expect(20, tooBig, 0, []). - -v2_get_bulk_p() -> - %% 4.2.3 - ?DBG("v2_get_bulk_p -> entry",[]), - gb(1, 1, []), - ?line expect(10, []), - gb(-1, 1, []), - ?line expect(11, []), - gb(-1, -1, []), - ?line expect(12, []), - gb(-1, -1, []), - ?line expect(13, []), - gb(2, 0, [[sysDescr], [1,3,7,1]]), - ?line expect(14, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}]), - gb(1, 2, [[sysDescr], [1,3,7,1]]), - ?line expect(15, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}]), - gb(0, 2, [[sysDescr], [1,3,7,1]]), - ?line expect(16, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}, - {[sysObjectID, 0], [1,2,3]}, - {[1,3,7,1], endOfMibView}]), - - gb(2, 2, [[sysDescr], [1,3,7,1], [sysDescr], [1,3,7,1]]), - ?line expect(17, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}, - {[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}, - {[sysObjectID, 0], [1,2,3]}, - {[1,3,7,1], endOfMibView}]), - - gb(1, 2, [[sysDescr], [sysDescr], [tTooBig]]), - ?line expect(18, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[sysDescr, 0], "Erlang SNMP agent"}]), - - gb(1,12, [[tDescr2], [sysDescr]]), % next one after tDescr2 is tTooBig. - ?line expect(19, []), - - gb(2,2, [[sysDescr], [sysObjectID], [tGenErr1], [sysDescr]]), - ?line expect(20, genErr, 3, [{[sysDescr], 'NULL'}, - {[sysObjectID], 'NULL'}, - {[tGenErr1], 'NULL'}, - {[sysDescr], 'NULL'}]), - gb(0, 2, [[tCnt2, 1]]), - ?line expect(21, [{[tCnt2,2], 100}, - {[tCnt2,2], endOfMibView}]). - - -v2_set_p() -> - %% 4.2.5:1 - ?DBG("v2_set_p -> entry",[]), - s([{[1,3,7,0], i, 4}]), - ?line expect(10, noAccess, 1, [{[1,3,7,0], 4}]), - s([{[tDescr,0], s, "outside mibview"}]), - ?line expect(11, noAccess, 1, [{[tDescr,0], "outside mibview"}]), - - %% 4.2.5:2 - s([{[1,3,6,1,0], s, "noSuchObject"}]), - ?line expect(20, notWritable, 1, [{[1,3,6,1,0], "noSuchObject"}]), - - %% 4.2.5:3 - s([{[tDescr2, 0], i, 4}]), - ?line expect(30, wrongType, 1, [{[tDescr2, 0], 4}]), - s([{[tDescr2, 0], s, "badValue"}]), - ?line expect(31, badValue, 1, [{[tDescr2, 0], "badValue"}]), - - %% 4.2.5:4 - s([{[tStr, 0], s, ""}]), - ?line expect(40, wrongLength, 1, [{[tStr, 0], ""}]), - s([{[tStr, 0], s, "12345"}]), - ?line expect(40, wrongLength, 1, [{[tStr, 0], "12345"}]), - - %% 4.2.5:5 - N/A - - %% 4.2.5:6 - s([{[tInt1, 0], i, 0}]), - ?line expect(60, wrongValue, 1, [{[tInt1, 0], 0}]), - s([{[tInt1, 0], i, 5}]), - ?line expect(61, wrongValue, 1, [{[tInt1, 0], 5}]), - s([{[tInt2, 0], i, 0}]), - ?line expect(62, wrongValue, 1, [{[tInt2, 0], 0}]), - s([{[tInt2, 0], i, 5}]), - ?line expect(63, wrongValue, 1, [{[tInt2, 0], 5}]), - s([{[tInt3, 0], i, 5}]), - ?line expect(64, wrongValue, 1, [{[tInt3, 0], 5}]), - - %% 4.2.5:7 - s([{[tDescrX, 1, 1], s, "noCreation"}]), - ?line expect(70, noCreation, 1, [{[tDescrX, 1, 1], "noCreation"}]), - - %% 4.2.5:8 - s([{[tDescrX, 1, 2], s, "inconsistentName"}]), - ?line expect(80, inconsistentName, 1, - [{[tDescrX, 1, 2], "inconsistentName"}]), - - %% 4.2.5:9 - s([{[tCnt, 1, 2], i, 5}]), - ?line expect(90, notWritable, 1, [{[tCnt, 1, 2], 5}]), - s([{[tDescr3,0], s, "read-only"}]), - ?line expect(90, notWritable, 1, [{[tDescr3,0], "read-only"}]), - - %% 4.2.5:10 - s([{[tDescr2,0], s, "inconsistentValue"}]), - ?line expect(100, inconsistentValue, 1, - [{[tDescr2,0], "inconsistentValue"}]), - - %% 4.2.5:11 - s([{[tDescr2,0], s, "resourceUnavailable"}]), - ?line expect(110, resourceUnavailable, 1, - [{[tDescr2,0],"resourceUnavailable"}]), - - %% 4.2.5:12 - s([{[tDescr2, 0], s, "is_set_ok_fail"}]), - ?line expect(120, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]). - - %% commitFailed and undoFailed is tested by the 'undo' case. - - -%% Req. OLD-SNMPEA-MIB -table_test() -> - io:format("Testing simple get, next and set on communityTable...~n"), -%% {[147,214,36,45], "public", 2, readWrite}. -%% {[147,214,36,45], "standard trap", 2, read}. - Key1c3 = [intCommunityViewIndex,get(mip),is("public")], - Key2c3 = [intCommunityViewIndex,get(mip),is("standard trap")], - Key1c4 = [intCommunityAccess,get(mip),is("public")], - EndKey = [intCommunityEntry,[9],get(mip),is("public")], - gn([[intCommunityEntry]]), - ?line expect(7, [{Key1c3, 2}]), - gn([[intCommunityTable]]), - ?line expect(71, [{Key1c3, 2}]), - gn([[community]]), - ?line expect(72, [{Key1c3, 2}]), - gn([[otpSnmpeaMIB]]), - ?line expect(73, [{Key1c3, 2}]), - gn([[ericsson]]), - ?line expect(74, [{Key1c3, 2}]), - gn([Key1c3]), - ?line expect(8, [{Key2c3, 2}]), - gn([Key2c3]), - ?line expect(9, [{Key1c4, 2}]), - gn([EndKey]), - AgentIp = [intAgentIpAddress,0], - ?line expect(10, [{AgentIp, any}]), - g([Key1c3]), - ?line expect(11, [{Key1c3, 2}]), - g([EndKey]), - ?line ?v1_2(expect(12, noSuchName, 1, any), - expect(12, [{EndKey, noSuchObject}])), - - io:format("Testing row creation/deletion on communityTable...~n"), - NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], - NewKeyc4 = [intCommunityAccess,get(mip),is("test")], - NewKeyc5 = [intCommunityStatus,get(mip),is("test")], - s([{NewKeyc5, ?createAndGo}]), - ?line expect(14, ?v1_2(badValue, inconsistentValue), 1,any), - s([{NewKeyc5, ?createAndGo}, {NewKeyc3, 2}, {NewKeyc4, 2}]), - ?line expect(15, [{NewKeyc5, ?createAndGo},{NewKeyc3, 2}, {NewKeyc4, 2}]), - g([NewKeyc4]), - ?line expect(16, [{NewKeyc4, 2}]), - s([{NewKeyc5, ?destroy}]), - ?line expect(17, [{NewKeyc5, ?destroy}]), - s([{NewKeyc4, 2}]), - ?line expect(18, ?v1_2(noSuchName, inconsistentName), 1,[{NewKeyc4, 2}]), - s([{NewKeyc5, ?createAndWait}]), - ?line expect(19, [{NewKeyc5, ?createAndWait}]), - g([NewKeyc5]), - ?line expect(20, [{NewKeyc5, ?notReady}]), - s([{NewKeyc4, 2}]), - ?line expect(21, [{NewKeyc4, 2}]), - g([NewKeyc5]), - ?line expect(22, [{NewKeyc5, ?notReady}]), - s([{NewKeyc3, 2}]), - ?line expect(23, [{NewKeyc3, 2}]), - g([NewKeyc5]), - ?line expect(24, [{NewKeyc5, ?notInService}]), - s([{NewKeyc5, ?active}]), - ?line expect(25, [{NewKeyc5, ?active}]), - s([{NewKeyc5, ?destroy}]), - ?line expect(26, [{NewKeyc5, ?destroy}]), - s([{NewKeyc3, 3}]), - ?line expect(27, ?v1_2(noSuchName, inconsistentName), 1,[{NewKeyc3, 3}]), - otp_1128(). - -%% Req. system group -simple_standard_test() -> - ?DBG("simple_standard_test -> entry",[]), - gn([[1,1]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3]]), - ?line expect(11, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6]]), - ?line expect(12, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6,1]]), - ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6,1,2]]), - ?line expect(14, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6,1,2,1]]), - ?line expect(15, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6,1,2,1,1]]), - ?line expect(16, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[sysDescr]]), - ?line expect(17, [{[sysDescr,0], "Erlang SNMP agent"}]), - g([[sysDescr,0]]), - ?line expect(2, [{[sysDescr,0], "Erlang SNMP agent"}]), - g([[sysDescr]]), - ?line ?v1_2(expect(3, noSuchName, 1, any), - expect(3, [{[sysDescr], noSuchObject}])), - g([[1,6,7,0]]), - ?line ?v1_2(expect(41, noSuchName, 1, any), - expect(3, [{[1,6,7,0], noSuchObject}])), - gn([[1,13]]), - ?line ?v1_2(expect(4, noSuchName,1, any), - expect(4, [{[1,13], endOfMibView}])), - s([{[sysLocation, 0], "new_value"}]), - ?line expect(5, [{[sysLocation, 0], "new_value"}]), - g([[sysLocation, 0]]), - ?line expect(6, [{[sysLocation, 0], "new_value"}]), - io:format("Testing noSuchName and badValue...~n"), - s([{[sysServices,0], 3}]), - ?line expect(61, ?v1_2(noSuchName, notWritable), 1, any), - s([{[sysLocation, 0], i, 3}]), - ?line expect(62, ?v1_2(badValue, wrongType), 1, any), - ?DBG("simple_standard_test -> done",[]), - ok. - -%% This is run in the agent node -db_notify_client(suite) -> []; -db_notify_client(Config) when list(Config) -> - {SaNode, MgrNode, MibDir} = init_case(Config), - ?DBG("~n\tSaNode: ~p~n\tMgrNode: ~p~n\tMibDir: ~p", - [SaNode,MgrNode,MibDir]), - snmpa_local_db:register_notify_client(self(),?MODULE), - - %% This call (the manager) will issue to set operations, so - %% we expect to receive to notify(insert) calls. - try_test(db_notify_client_test), - - ?DBG("await first notify",[]), - receive - {db_notify_test_reply,insert} -> ?DBG("first notify received",[]),ok - end, - - ?DBG("await second notify",[]), - receive - {db_notify_test_reply,insert} -> ?DBG("second notify received",[]),ok - end, - - snmpa_local_db:unregister_notify_client(self()). - - -%% This is run in the manager node -db_notify_client_test() -> - ?DBG("set first new sysLocation",[]), - s([{[sysLocation, 0], "new_value"}]), - ?line expect(5, [{[sysLocation, 0], "new_value"}]), - - ?DBG("set second new sysLocation",[]), - s([{[sysLocation, 0], "new_value"}]), - ?line expect(5, [{[sysLocation, 0], "new_value"}]). - -notify(Pid,What) -> - ?DBG("notify(~p,~p) -> called",[Pid,What]), - Pid ! {db_notify_test_reply,What}. - - -%% Req: system group, OLD-SNMPEA-MIB, Klas1 -big_test() -> - ?DBG("big_test -> testing simple next/get/set @ master agent...",[]), - simple_standard_test(), - - ?DBG("big_test -> testing simple next/get/set @ subagent...",[]), - gn([[klas1]]), - ?line expect(1, [{[fname,0], ""}]), - g([[fname,0]]), - ?line expect(2, [{[fname,0], ""}]), - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - g([[fname,0]]), - ?line expect(4, [{[fname,0], "test set"}]), - - ?DBG("big_test -> " - "testing next from last instance in master to subagent...",[]), - gn([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(5, [{[fname,0], "test set"}]), - gn([[1,1], - [?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, - {[fname,0], "test set"}]), - s([{[fname,0], s, ""}]), - ?line expect(52, [{[fname,0], ""}]), - - table_test(), - - ?DBG("big_test -> adding one row in subagent table",[]), - _FTab = [friendsEntry], - s([{[friendsEntry, [2, 3]], s, "kompis3"}, - {[friendsEntry, [3, 3]], i, ?createAndGo}]), - ?line expect(6, [{[friendsEntry, [2, 3]], "kompis3"}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - g([[friendsEntry, [2, 3]], - [friendsEntry, [3, 3]]]), - ?line expect(7, [{[friendsEntry, [2, 3]], "kompis3"}, - {[friendsEntry, [3, 3]], ?active}]), - s([{[friendsEntry, [3, 3]], i, ?destroy}]), - ?line expect(8, [{[friendsEntry, [3, 3]], ?destroy}]), - - otp_1131(), - - ?DBG("big_test -> adding two rows in subagent table with special INDEX", - []), - s([{[kompissEntry, [1, 3]], s, "kompis3"}, - {[kompissEntry, [2, 3]], i, ?createAndGo}]), - ?line expect(9, [{[kompissEntry, [1, 3]], "kompis3"}, - {[kompissEntry, [2, 3]], ?createAndGo}]), - g([[kompissEntry, [1, 3]], - [kompissEntry, [2, 3]]]), - ?line expect(10, [{[kompissEntry, [1, 3]], "kompis3"}, - {[kompissEntry, [2, 3]], ?active}]), - gn([[kompissEntry, [1]], - [kompissEntry, [2]]]), - ?line expect(11, [{[kompissEntry, [1, 3]], "kompis3"}, - {[kompissEntry, [2, 3]], ?active}]), - s([{[kompissEntry, [1, 2]], s, "kompis3"}, - {[kompissEntry, [2, 2]], i, ?createAndGo}]), - ?line expect(12, [{[kompissEntry, [1, 2]], "kompis3"}, - {[kompissEntry, [2, 2]], ?createAndGo}]), - gn([[kompissEntry, [1, 1]], - [kompissEntry, [2, 1]]]), - ?line expect(13, [{[kompissEntry, [1, 2]], "kompis3"}, - {[kompissEntry, [2, 2]], ?active}]), - s([{[kompissEntry, [2, 3]], i, ?destroy}]), - ?line expect(14, [{[kompissEntry, [2, 3]], ?destroy}]), - s([{[kompissEntry, [2, 2]], i, ?destroy}]), - ?line expect(15, [{[kompissEntry, [2, 2]], ?destroy}]), - ?DBG("big_test -> done",[]), - ok. - -%% Req. system group, Klas2, OLD-SNMPEA-MIB -big_test_2() -> - p("Testing simple next/get/set @ master agent (2)..."), - simple_standard_test(), - - p("Testing simple next/get/set @ subagent (2)..."), - gn([[klas2]]), - ?line expect(1, [{[fname2,0], ""}]), - g([[fname2,0]]), - ?line expect(2, [{[fname2,0], ""}]), - s([{[fname2,0], s, "test set"}]), - ?line expect(3, [{[fname2,0], "test set"}]), - g([[fname2,0]]), - ?line expect(4, [{[fname2,0], "test set"}]), - - otp_1298(), - - p("Testing next from last object in master to subagent (2)..."), - gn([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(5, [{[fname2,0], "test set"}]), - gn([[1,1], - [?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, - {[fname2,0], "test set"}]), - - table_test(), - - p("Adding one row in subagent table (2)"), - _FTab = [friendsEntry2], - s([{[friendsEntry2, [2, 3]], s, "kompis3"}, - {[friendsEntry2, [3, 3]], i, ?createAndGo}]), - ?line expect(6, [{[friendsEntry2, [2, 3]], "kompis3"}, - {[friendsEntry2, [3, 3]], ?createAndGo}]), - g([[friendsEntry2, [2, 3]], - [friendsEntry2, [3, 3]]]), - ?line expect(7, [{[friendsEntry2, [2, 3]], "kompis3"}, - {[friendsEntry2, [3, 3]], ?active}]), - s([{[friendsEntry2, [3, 3]], i, ?destroy}]), - ?line expect(8, [{[friendsEntry2, [3, 3]], ?destroy}]), - - p("Adding two rows in subagent table with special INDEX (2)"), - s([{[kompissEntry2, [1, 3]], s, "kompis3"}, - {[kompissEntry2, [2, 3]], i, ?createAndGo}]), - ?line expect(9, [{[kompissEntry2, [1, 3]], "kompis3"}, - {[kompissEntry2, [2, 3]], ?createAndGo}]), - g([[kompissEntry2, [1, 3]], - [kompissEntry2, [2, 3]]]), - ?line expect(10, [{[kompissEntry2, [1, 3]], "kompis3"}, - {[kompissEntry2, [2, 3]], ?active}]), - gn([[kompissEntry2, [1]], - [kompissEntry2, [2]]]), - ?line expect(11, [{[kompissEntry2, [1, 3]], "kompis3"}, - {[kompissEntry2, [2, 3]], ?active}]), - s([{[kompissEntry2, [1, 2]], s, "kompis3"}, - {[kompissEntry2, [2, 2]], i, ?createAndGo}]), - ?line expect(12, [{[kompissEntry2, [1, 2]], "kompis3"}, - {[kompissEntry2, [2, 2]], ?createAndGo}]), - gn([[kompissEntry2, [1, 1]], - [kompissEntry2, [2, 1]]]), - ?line expect(13, [{[kompissEntry2, [1, 2]], "kompis3"}, - {[kompissEntry2, [2, 2]], ?active}]), - s([{[kompissEntry2, [2, 3]], i, ?destroy}]), - ?line expect(14, [{[kompissEntry2, [2, 3]], ?destroy}]), - s([{[kompissEntry2, [2, 2]], i, ?destroy}]), - ?line expect(15, [{[kompissEntry2, [2, 2]], ?destroy}]), - ok. - -%% Req. Test1 -multi_threaded_test() -> - p("Testing multi threaded agent..."), - g([[multiStr,0]]), - Pid = get_multi_pid(), - g([[sysUpTime,0]]), - ?line expect(1, [{[sysUpTime,0], any}]), - s([{[sysLocation, 0], s, "pelle"}]), - ?line expect(2, [{[sysLocation, 0], "pelle"}]), - Pid ! continue, - ?line expect(3, [{[multiStr,0], "ok"}]), - - s([{[multiStr, 0], s, "block"}]), - Pid2 = get_multi_pid(), - g([[sysUpTime,0]]), - ?line expect(4, [{[sysUpTime,0], any}]), - g([[multiStr,0]]), - Pid3 = get_multi_pid(), - g([[sysUpTime,0]]), - ?line expect(5, [{[sysUpTime,0], any}]), - s([{[sysLocation, 0], s, "kalle"}]), - Pid3 ! continue, - ?line expect(6, [{[multiStr,0], "ok"}]), - Pid2 ! continue, - ?line expect(7, [{[multiStr,0], "block"}]), - ?line expect(8, [{[sysLocation,0], "kalle"}]). - -%% Req. Test1, TestTrapv2 -mt_trap_test(MA) -> - snmpa:send_trap(MA, testTrapv22, "standard trap"), - ?line expect(1, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - - snmpa:send_trap(MA, mtTrap, "standard trap"), - Pid = get_multi_pid(), - g([[sysUpTime,0]]), - ?line expect(2, [{[sysUpTime,0], any}]), - snmpa:send_trap(MA, testTrapv22, "standard trap"), - ?line expect(3, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - Pid ! continue, - ?line expect(4, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?testTrap ++ [2]}, - {[multiStr,0], "ok"}]). - - -get_multi_pid() -> - get_multi_pid(10). -get_multi_pid(0) -> - ?line ?FAIL(no_global_name); -get_multi_pid(N) -> - sleep(1000), - case global:whereis_name(snmp_multi_tester) of - Pid when pid(Pid) -> Pid; - _ -> get_multi_pid(N-1) - end. - -%% Req. Test1 -types_v2_test() -> - p("Testing v2 types..."), - - s([{[bits1,0], 2#10}]), - ?line expect(1, [{[bits1,0], ?str(2#10)}]), - g([[bits1,0]]), - ?line expect(2, [{[bits1,0], ?str(2#101)}]), - - s([{[bits2,0], 2#11000000110}]), - ?line expect(3, [{[bits2,0], ?str(2#11000000110)}]), - g([[bits2,0]]), - ?line expect(4, [{[bits2,0], ?str(2#11000000110)}]), - - g([[bits3,0]]), - ?line expect(50, genErr, 1, any), - - g([[bits4,0]]), - ?line expect(51, genErr, 1, any), - - s([{[bits1,0], s, [2#10]}]), - ?line expect(6, ?v1_2(badValue, wrongValue), 1, any), - - s([{[bits2,0], 2#11001001101010011}]), - ?line expect(7, ?v1_2(badValue, wrongValue), 1, any). - - -%% Req. Test1 -implied_test(MA) -> - ?LOG("implied_test -> start",[]), - p("Testing IMPLIED..."), - - snmpa:verbosity(MA,trace), - snmpa:verbosity(MA,trace), - - %% Create two rows, check that they are get-nexted in correct order. - Idx1 = "apa", - Idx2 = "qq", - ?DBG("implied_test -> (send) create row 1 '~s' in table 1",[Idx1]), - s([{[testStatus, Idx1], i, ?createAndGo}, {[testDescr, Idx1],s,"row 1"}]), - ?line expect(1, [{[testStatus, Idx1], ?createAndGo}, - {[testDescr, Idx1], "row 1"}]), - ?DBG("implied_test -> (send) create row 2 '~s' in table 1",[Idx2]), - s([{[testStatus, Idx2], i, ?createAndGo}, {[testDescr, Idx2],s,"row 2"}]), - ?line expect(2, [{[testStatus, Idx2], ?createAndGo}, - {[testDescr, Idx2], "row 2"}]), - ?DBG("implied_test -> get-next(testDescr)",[]), - gn([[testDescr]]), - ?line expect(3, [{[testDescr,Idx1], "row 1"}]), - ?DBG("implied_test -> get-next(testDescr) of row 1",[]), - gn([[testDescr,Idx1]]), - ?line expect(4, [{[testDescr,Idx2], "row 2"}]), - - % Delete the rows - ?DBG("implied_test -> (send) delete row 1 '~s' from table 1",[Idx1]), - s([{[testStatus, Idx1], i, ?destroy}]), - ?line expect(5, [{[testStatus, Idx1], ?destroy}]), - ?DBG("implied_test -> (send) delete row 2 '~s' from table 1",[Idx2]), - s([{[testStatus, Idx2], i, ?destroy}]), - ?line expect(6, [{[testStatus, Idx2], ?destroy}]), - - %% Try the same in other table - Idx3 = [1, "apa"], - Idx4 = [1, "qq"], - ?DBG("implied_test -> (send) create row 1 '~s' in table 2",[Idx3]), - s([{[testStatus2, Idx3], i, ?createAndGo}, {[testDescr2,Idx3],s,"row 1"}]), - ?line expect(1, [{[testStatus2, Idx3], ?createAndGo}, - {[testDescr2, Idx3], "row 1"}]), - ?DBG("implied_test -> (send) create row 2 '~s' in table 2",[Idx4]), - s([{[testStatus2, Idx4], i, ?createAndGo}, {[testDescr2,Idx4],s,"row 2"}]), - ?line expect(2, [{[testStatus2, Idx4], ?createAndGo}, - {[testDescr2, Idx4], "row 2"}]), - ?DBG("implied_test -> get-next(testDescr2)",[]), - gn([[testDescr2]]), - ?line expect(3, [{[testDescr2,Idx3], "row 1"}]), - ?DBG("implied_test -> get-next(testDescr2) of row 1",[]), - gn([[testDescr2,Idx3]]), - ?line expect(4, [{[testDescr2,Idx4], "row 2"}]), - - % Delete the rows - ?DBG("implied_test -> (send) delete row 1 '~s' from table 2",[Idx3]), - s([{[testStatus2, Idx3], i, ?destroy}]), - ?line expect(5, [{[testStatus2, Idx3], ?destroy}]), - ?DBG("implied_test -> (send) delete row 2 '~s' from table 2",[Idx4]), - s([{[testStatus2, Idx4], i, ?destroy}]), - ?line expect(6, [{[testStatus2, Idx4], ?destroy}]), - - snmpa:verbosity(MA,log), - - ?LOG("implied_test -> done",[]). - - - -%% Req. Test1 -sparse_table_test() -> - p("Testing sparse table..."), - - %% Create two rows, check that they are get-nexted in correct order. - Idx1 = 1, - Idx2 = 2, - s([{[sparseStatus, Idx1], i, ?createAndGo}, - {[sparseDescr, Idx1], s, "row 1"}]), - ?line expect(1, [{[sparseStatus, Idx1], ?createAndGo}, - {[sparseDescr, Idx1], "row 1"}]), - s([{[sparseStatus, Idx2], i, ?createAndGo}, - {[sparseDescr, Idx2], s, "row 2"}]), - ?line expect(2, [{[sparseStatus, Idx2], ?createAndGo}, - {[sparseDescr, Idx2], "row 2"}]), - ?v1_2(gn([[sparseIndex], [sparseDescr,Idx1], [sparseDescr,Idx2], - [sparseStatus,Idx1], [sparseStatus,Idx2]]), - gb(0,5,[[sparseIndex]])), - ?line expect(3, [{[sparseDescr,Idx1], "row 1"}, - {[sparseDescr,Idx2], "row 2"}, - {[sparseStatus,Idx1], ?active}, - {[sparseStatus,Idx2], ?active}, - {[sparseStr,0], "slut"}]), - % Delete the rows - s([{[sparseStatus, Idx1], i, ?destroy}]), - ?line expect(4, [{[sparseStatus, Idx1], ?destroy}]), - s([{[sparseStatus, Idx2], i, ?destroy}]), - ?line expect(5, [{[sparseStatus, Idx2], ?destroy}]). - - -%% Req. Test1 -cnt_64_test(MA) -> - ?LOG("start cnt64 test (~p)",[MA]), - snmpa:verbosity(MA,trace), - ?LOG("start cnt64 test",[]), - p("Testing Counter64, and at the same time, RowStatus is not last column"), - - ?DBG("get cnt64",[]), - g([[cnt64,0]]), - ?DBG("await response",[]), - ?line ?v1_2(expect(1, noSuchName, 1, any), - expect(1, [{[cnt64,0],18446744073709551615}])), - ?DBG("get-next cnt64",[]), - gn([[cnt64]]), - ?DBG("await response",[]), - ?line ?v1_2(expect(2, [{[cnt64Str,0], "after cnt64"}]), - expect(2, [{[cnt64,0],18446744073709551615}])), - ?DBG("send cntTrap",[]), - snmpa:send_trap(MA,cntTrap,"standard trap",[{sysContact,"pelle"}, - {cnt64, 10}, - {sysLocation, "here"}]), - ?DBG("await response",[]), - ?line ?v1_2(expect(3, trap, [test], 6, 1, [{[sysContact,0], "pelle"}, - {[sysLocation,0], "here"}]), - expect(3, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?testTrap ++ [1]}, - {[sysContact,0], "pelle"}, - {[cnt64,0], 10}, - {[sysLocation,0], "here"}])), - - %% Create two rows, check that they are get-nexted in correct order. - Idx1 = 1, - Idx2 = 2, - ?DBG("create row (cntStatus): ~p",[Idx1]), - s([{[cntStatus, Idx1], i, ?createAndGo}]), - ?DBG("await response",[]), - ?line expect(1, [{[cntStatus, Idx1], ?createAndGo}]), - ?DBG("create row (cntStatus): ~p",[Idx2]), - s([{[cntStatus, Idx2], i, ?createAndGo}]), - ?DBG("await response",[]), - ?line expect(2, [{[cntStatus, Idx2], ?createAndGo}]), - - ?DBG("get-next (cntIndex)",[]), - gn([[cntIndex]]), - ?DBG("await response",[]), - ?line ?v1_2(expect(3, [{[cntStatus,Idx1], ?active}]), - expect(3, [{[cntCnt,Idx1], 0}])), - % Delete the rows - ?DBG("delete row (cntStatus): ~p",[Idx1]), - s([{[cntStatus, Idx1], i, ?destroy}]), - ?DBG("await response",[]), - ?line expect(4, [{[cntStatus, Idx1], ?destroy}]), - ?DBG("delete row (cntStatus): ~p",[Idx2]), - s([{[cntStatus, Idx2], i, ?destroy}]), - ?DBG("await response",[]), - ?line expect(5, [{[cntStatus, Idx2], ?destroy}]), - catch snmpa:verbosity(MA,log), - ?DBG("done",[]), - ok. - -%% Req. Test1 -opaque_test() -> - p("Testing Opaque datatype..."), - g([[opaqueObj,0]]), - ?line expect(1, [{[opaqueObj,0], "opaque-data"}]). - -%% Req. OLD-SNMPEA-MIB -api_test(MaNode) -> - ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, - [intAgentIpAddress]), - ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, - oid_to_name, [OID]), - ?line false = rpc:call(MaNode, snmp, name_to_oid, [intAgentIpAddres]), - ?line false = rpc:call(MaNode, snmp, oid_to_name, - [[1,5,32,3,54,3,3,34,4]]), - ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, - [intViewType, excluded]), - ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, - [intViewType, 2]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, [intViewType, exclude]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [intAgentIpAddress, exclude]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [intAgentIpAddre, exclude]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [intViewType, 3]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddress, 2]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddre, 2]), - ?line {value, active} = rpc:call(MaNode, snmp, - int_to_enum, ['RowStatus', ?active]), - ?line {value, ?destroy} = rpc:call(MaNode, snmp, - enum_to_int, ['RowStatus', destroy]), - ?line false = rpc:call(MaNode, snmp, - enum_to_int, ['RowStatus', xxxdestroy]), - ?line false = rpc:call(MaNode, snmp, - enum_to_int, ['xxRowStatus', destroy]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, ['RowStatus', 25]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, ['xxRowStatus', 1]), - ?line case snmp:date_and_time() of - List when list(List), length(List) == 8 -> ok; - List when list(List), length(List) == 11 -> ok - end. - -%% Req. Klas3 -api_test2() -> - g([[fname3,0]]), - ?line expect(1, [{[fname3,0], "ok"}]), - g([[fname4,0]]), - ?line expect(2, [{[fname4,0], 1}]). - -api_test3() -> - g([[fname3,0]]), - ?line expect(1, [{[fname3,0], "ok"}]). - - -unreg_test() -> - gn([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(1, [{[snmpInPkts, 0], any}]). - -load_test() -> - gn([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(1, [{[fname,0], ""}]). - -%% Req. Klas1 -load_test_sa() -> - gn([[?v1_2(sysServices,sysORLastChange), 0]]), - ?line expect(1, [{[fname,0], any}]). - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_get() -> - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - g([[sysDescr,0], Key1c4, [fname,0],Key1c3, - [sysName,0]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[fname,0], "test set"}, - {Key1c3, 2}, - {[sysName,0], "test"}]), - g([[1,3,7,1], Key1c4, [sysDescr,0], [1,3,7,2], Key1c3, [sysDescr,0]]), - ?line ?v1_2(expect(2, noSuchName, [1,4], any), - expect(2, [{[1,3,7,1], noSuchObject}, - {Key1c4, 2}, - {[sysDescr,0], "Erlang SNMP agent"}, - {[1,3,7,2], noSuchObject}, - {Key1c3, 2}, - {[sysDescr,0], "Erlang SNMP agent"}])). - -%% Req. v1, system group, Klas1, OLD-SNMPEA-MIB, *ej* Klas3. -do_mul_get_err() -> - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - g([[sysDescr,0],Key1c4,[fname,0], Key1c3, [sysName,2]]), - ?line ?v1_2(expect(1, noSuchName, 5, any), - expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[fname,0], "test set"}, - {Key1c3, 2}, - {[sysName,2], noSuchInstance}])), - g([[sysDescr,0],Key1c4,[fname3,0], Key1c3, [sysName,1]]), - ?line ?v1_2(expect(1, noSuchName, [3,5], any), - expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[fname3,0], noSuchObject}, - {Key1c3, 2}, - {[sysName,1], noSuchInstance}])). - - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_next() -> - Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], - Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - gn([[sysDescr], Key1c4s, [fname],Key1c3s,[sysName]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, {[fname,0], "test set"}, - {Key1c3, 2}, {[sysName,0], "test"}]). - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_next_err() -> - Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], - Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - gn([[sysDescr], Key1c4s, [1,3,6,999], [fname],[1,3,90], Key1c3s,[sysName]]), - ?line ?v1_2(expect(1, noSuchName, [3,5], any), - expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[1,3,6,999], endOfMibView}, - {[fname,0], "test set"}, - {[1,3,90], endOfMibView}, - {Key1c3, 2}, - {[sysName,0], "test"}])). - - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_set() -> - p("Adding one row in subagent table, and one in master table"), - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - s([{[friendsEntry, [2, 3]], "kompis3"}, - {NewKeyc3, 2}, - {[sysLocation,0], "new_value"}, - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - ?line expect(1, [{[friendsEntry, [2, 3]], "kompis3"}, - {NewKeyc3, 2}, - {[sysLocation,0], "new_value"}, - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - g([[friendsEntry, [2, 3]], - [sysLocation,0], - [friendsEntry, [3, 3]]]), - ?line expect(2, [{[friendsEntry, [2, 3]], "kompis3"}, - {[sysLocation,0], "new_value"}, - {[friendsEntry, [3, 3]], ?active}]), - g([NewKeyc4]), - ?line expect(3, [{NewKeyc4, 2}]), - s([{[friendsEntry, [3, 3]], ?destroy}, - {NewKeyc5, ?destroy}]), - ?line expect(4, [{[friendsEntry, [3, 3]], ?destroy}, - {NewKeyc5, ?destroy}]). - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_set_err() -> - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - p("Adding one row in subagent table, and one in master table"), - s([{[friendsEntry, [2, 3]], s, "kompis3"}, - {NewKeyc3, 2}, - {[sysUpTime,0], 45}, % sysUpTime (readOnly) - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - ?line expect(1, ?v1_2(noSuchName, notWritable), 3, any), - g([[friendsEntry, [2, 3]]]), - ?line ?v1_2(expect(2, noSuchName, 1, any), - expect(2, [{[friendsEntry, [2,3]], noSuchInstance}])), - g([NewKeyc4]), - ?line ?v1_2(expect(3, noSuchName, 1, any), - expect(3, [{NewKeyc4, noSuchInstance}])). - -%% Req. SA-MIB -sa_mib() -> - g([[sa, [2,0]]]), - ?line expect(1, [{[sa, [2,0]], 3}]), - s([{[sa, [1,0]], s, "sa_test"}]), - ?line expect(2, [{[sa, [1,0]], "sa_test"}]). - -ma_trap1(MA) -> - snmpa:send_trap(MA, testTrap2, "standard trap"), - ?line expect(1, trap, [system], 6, 1, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}]), - snmpa:send_trap(MA, testTrap1, "standard trap"), - ?line expect(2, trap, [1,2,3] , 1, 0, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}]). - -ma_trap2(MA) -> - snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). - -ma_v2_2_v1_trap(MA) -> - snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). - -ma_v2_2_v1_trap2(MA) -> - snmpa:send_trap(MA,linkUp,"standard trap",[{ifIndex, [1], 1}, - {ifAdminStatus, [1], 1}, - {ifOperStatus, [1], 2}]), - ?line expect(3, trap, [1,2,3], 3, 0, [{[ifIndex, 1], 1}, - {[ifAdminStatus, 1], 1}, - {[ifOperStatus, 1], 2}]). - -sa_trap1(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap"), - ?line expect(4, trap, [ericsson], 6, 1, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}]). - -sa_trap2(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), - ?line expect(5, trap, [ericsson], 6, 1, [{[system, [4,0]], - "pelle"}, - {[sa, [1,0]], "sa_test"}]). - -sa_trap3(SA) -> - snmpa:send_trap(SA, saTrap2, "standard trap", - [{intViewSubtree, [4], [1,2,3,4]}]), - ?line expect(6, trap, [ericsson], 6, 2, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}, - {[intViewSubtree,4],[1,2,3,4]}]). - -ma_v2_trap1(MA) -> - ?DBG("ma_v2_traps -> entry with MA = ~p => " - "send standard trap: testTrapv22",[MA]), - snmpa:send_trap(MA, testTrapv22, "standard trap"), - ?line expect(1, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - ?DBG("ma_v2_traps -> send standard trap: testTrapv21",[]), - snmpa:send_trap(MA, testTrapv21, "standard trap"), - ?line expect(2, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?snmp ++ [1]}]). - -ma_v2_trap2(MA) -> - snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}, - {[system, [4,0]], "pelle"}]). - -%% Note: This test case takes a while... actually a couple of minutes. -ma_v2_inform1(MA) -> - ?DBG("ma_v2_inform -> entry with MA = ~p => " - "send notification: testTrapv22",[MA]), - ?line snmpa:send_notification(MA, testTrapv22, no_receiver, "standard inform", []), - ?line expect(1, {inform, true}, - [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - - ?DBG("ma_v2_inform -> send notification: testTrapv22",[]), - snmpa:send_notification(MA, testTrapv22, {tag1, self()}, - "standard inform", []), - ?line expect(1, {inform, true}, - [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - ?DBG("ma_v2_inform -> await targets",[]), - receive - {snmp_targets, tag1, [_]} -> - ok; - {snmp_targets, tag1, Addrs1} -> - ?line ?FAIL({bad_addrs, Addrs1}) - after - 5000 -> - ?ERR("ma_v2_inform1 -> awaiting snmp_targets(tag1) timeout",[]), - ?line ?FAIL(nothing_at_all) - end, - ?DBG("ma_v2_inform -> await notification",[]), - receive - {snmp_notification, tag1, {got_response, _}} -> - ok; - {snmp_notification, tag1, {no_response, _}} -> - ?line ?FAIL(no_response) - after - 20000 -> - ?ERR("ma_v2_inform1 -> " - "awaiting snmp_notification(tag1) timeout",[]), - ?line ?FAIL(nothing_at_all) - end, - - %% - %% -- The rest is possibly erroneous... - %% - - ?DBG("ma_v2_inform -> send notification: testTrapv22",[]), - snmpa:send_notification(MA, testTrapv22, {tag2, self()}, - "standard inform", []), - ?line expect(2, {inform, false}, - [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - ?DBG("ma_v2_inform -> await targets",[]), - receive - {snmp_targets, tag2, [_]} -> - ok; - {snmp_targets, tag2, Addrs2} -> - ?ERR("ma_v2_inform1 -> awaiting snmp_targets(tag2) timeout",[]), - ?line ?FAIL({bad_addrs, Addrs2}) - after - 5000 -> - ?line ?FAIL(nothing_at_all) - end, - ?DBG("ma_v2_inform -> await notification",[]), - receive - {snmp_notification, tag2, {got_response, _}} -> - ?line ?FAIL(got_response); - {snmp_notification, tag2, {no_response, _}} -> - ok - after - 240000 -> - ?ERR("ma_v2_inform1 -> " - "awaiting snmp_notification(tag2) timeout",[]), - ?line ?FAIL(nothing_at_all) - end. - - -ma_v1_2_v2_trap(MA) -> - snmpa:send_trap(MA,linkDown,"standard trap",[{ifIndex, [1], 1}]), - ?line expect(2, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?snmpTraps ++ [3]}, - {[ifIndex, 1], 1}, - {[snmpTrapEnterprise, 0], [1,2,3]}]). - - -ma_v1_2_v2_trap2(MA) -> - snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}, - {[system, [4,0]], "pelle"}, - {[snmpTrapEnterprise, 0], ?system}]). - - -sa_v1_2_v2_trap1(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap"), - ?line expect(4, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, - {[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}, - {[snmpTrapEnterprise, 0], ?ericsson}]). - -sa_v1_2_v2_trap2(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), - ?line expect(4, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, - {[system, [4,0]], "pelle"}, - {[sa, [1,0]], "sa_test"}, - {[snmpTrapEnterprise, 0], ?ericsson}]). - - -sa_v1_2_v2_trap3(SA) -> - snmpa:send_trap(SA, saTrap2, "standard trap", - [{intViewSubtree, [4], [1,2,3,4]}]), - ?line expect(4, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?ericsson ++ [0, 2]}, - {[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}, - {[intViewSubtree,4],[1,2,3,4]}, - {[snmpTrapEnterprise, 0], ?ericsson}]). - - -%% Req. SA-MIB, OLD-SNMPEA-MIB -sa_errs_bad_value() -> - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - s([{NewKeyc3, 2}, - {[sa, [2,0]], 5}, % badValue (i is_set_ok) - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}]), - ?line expect(1, badValue, 2, any), - s([{NewKeyc3, 2}, - {[sa, [2,0]], 6}, % wrongValue (i is_set_ok) - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}]), - ?line expect(1, ?v1_2(badValue, wrongValue), 2, any), - g([NewKeyc4]), - ?line ?v1_2(expect(2, noSuchName, 1, any), - expect(2, [{NewKeyc4, noSuchInstance}])). - -%% Req. SA-MIB, OLD-SNMPEA-MIB -sa_errs_gen_err() -> - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - s([{NewKeyc3, 2},{NewKeyc4, 2}, - {NewKeyc5, ?createAndGo}, {[sa, [3,0]], 5}]), - ?line expect(1, genErr, 4, any), -% The row might have been added; we don't know. -% (as a matter of fact we do - it is added, because the agent -% first sets its own vars, and then th SAs. Lets destroy it. - s([{NewKeyc5, ?destroy}]), - ?line expect(2, [{NewKeyc5, ?destroy}]). - -%% Req. SA-MIB, OLD-SNMPEA-MIB -sa_too_big() -> - g([[sa, [4,0]]]), - ?line expect(1, tooBig). - -%% Req. Klas1, system group, snmp group (v1/v2) -next_across_sa() -> - gn([[sysDescr],[klas1,5]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {[snmpInPkts, 0], any}]). - -%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]). -> noError -%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]). -> {badValue, 2} -%% snmp_test_mgr:s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]). -> {genErr, 1} -%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]). -> {genErr, 1} -%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]). -> {genErr, 1} -%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]). -> {genErr, 2} -%% Req. Klas3, Klas4 -undo_test() -> - s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), - ?line expect(1, [{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), - s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]), - ?line expect(2, ?v1_2(badValue, inconsistentValue), 2, any), - s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]), - ?line expect(3, ?v1_2(genErr, undoFailed), 1, any), - s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]), - ?line expect(4, ?v1_2(genErr, commitFailed), 1, any), -% unfortunatly we don't know if we'll get undoFailed or commitFailed. -% it depends on which order the agent traverses the varbind list. -% s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]), -% ?line expect(5, ?v1_2(genErr, undoFailed), 1, any), - s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]), - ?line expect(6, genErr, 2, any). - -%% Req. Klas3, Klas4 -bad_return() -> - g([[fStatus4,4], - [fName4,4]]), - ?line expect(4, genErr, 2, any), - g([[fStatus4,5], - [fName4,5]]), - ?line expect(5, genErr, 1, any), - g([[fStatus4,6], - [fName4,6]]), - ?line expect(6, genErr, 2, any), - gn([[fStatus4,7], - [fName4,7]]), - ?line expect(7, genErr, 2, any), - gn([[fStatus4,8], - [fName4,8]]), - ?line expect(8, genErr, 1, any), - gn([[fStatus4,9], - [fName4,9]]), - ?line expect(9, genErr, 2, any). - - -%%%----------------------------------------------------------------- -%%% Test the implementation of standard mibs. -%%% We should *at least* try to GET all variables, just to make -%%% sure the instrumentation functions work. -%%% Note that many of the functions in the standard mib is -%%% already tested by the normal tests. -%%%----------------------------------------------------------------- -standard_mibs(suite) -> - [snmp_standard_mib, snmp_community_mib, - snmp_framework_mib, - snmp_target_mib, snmp_notification_mib, - snmp_view_based_acm_mib]. - -standard_mibs_2(suite) -> - [snmpv2_mib_2, snmp_community_mib_2, - snmp_framework_mib_2, - snmp_target_mib_2, snmp_notification_mib_2, - snmp_view_based_acm_mib_2]. - -standard_mibs_3(suite) -> - [snmpv2_mib_3,snmp_framework_mib_3, snmp_mpd_mib_3, - snmp_target_mib_3, snmp_notification_mib_3, - snmp_view_based_acm_mib_3, snmp_user_based_sm_mib_3]. - -%%----------------------------------------------------------------- -%% For this test, the agent is configured for v1. -%% o Test the counters and control objects in SNMP-STANDARD-MIB -%%----------------------------------------------------------------- -snmp_standard_mib(suite) -> []; -snmp_standard_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?DBG("snmp_standard_mib -> std_mib_init", []), - try_test(std_mib_init), - - ?DBG("snmp_standard_mib -> std_mib_a", []), - InBadVsns = try_test(std_mib_a), - put(vsn, v2), - ?DBG("snmp_standard_mib -> std_mib_read", []), - try_test(std_mib_read), - put(vsn, v1), - - ?DBG("snmp_standard_mib -> std_mib_b (~w)", [InBadVsns]), - Bad = try_test(std_mib_b, [InBadVsns]), - ?DBG("snmp_standard_mib -> std_mib_read (community: 'bad community')", []), - try_test(std_mib_read, [], [{community, "bad community"}]), - ?DBG("snmp_standard_mib -> std_mib_write (community: 'public')", []), - try_test(std_mib_write, [], [{community, "public"}]), - ?DBG("snmp_standard_mib -> std_mib_asn_err", []), - try_test(std_mib_asn_err), - ?DBG("snmp_standard_mib -> std_mib_c (~w)", [Bad]), - try_test(std_mib_c, [Bad]), - ?DBG("snmp_standard_mib -> std_mib_a", []), - try_test(standard_mib_a), - - ?DBG("snmp_standard_mib -> std_mib_finish", []), - try_test(std_mib_finish), - ?DBG("snmp_standard_mib -> std_mib_test_finish", []), - try_test(standard_mib_test_finish, [], [{community, "bad community"}]). - -%% Req. SNMP-STANDARD-MIB -standard_mib_a() -> - ?line [OutPkts] = get_req(2, [[snmpOutPkts,0]]), - ?line [OutPkts2] = get_req(3, [[snmpOutPkts,0]]), - ?line OutPkts2 = OutPkts + 1, - %% There are some more counters we could test here, but it's not that - %% important, since they are removed from SNMPv2-MIB. - ok. - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_init() -> - %% disable authentication failure traps. (otherwise w'd get many of - %% them - this is also a test to see that it works). - s([{[snmpEnableAuthenTraps,0], 2}]), - ?line expect(1, [{[snmpEnableAuthenTraps, 0], 2}]). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_finish() -> - %% enable again - s([{[snmpEnableAuthenTraps,0], 1}]), - ?line expect(1, [{[snmpEnableAuthenTraps, 0], 1}]). - -%% Req. SNMP-STANDARD-MIB -standard_mib_test_finish() -> - %% force a authenticationFailure - std_mib_write(), - %% check that we got a trap - ?line expect(2, trap, [1,2,3], 4, 0, []). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_read() -> - ?DBG("std_mib_read -> entry", []), - g([[sysUpTime,0]]), % try a bad ; msg dropped, no reply - ?DBG("std_mib_read -> await timeout (i.e. no reply)", []), - ?line expect(1, timeout). % make sure we don't get a trap! - - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_write() -> - ?DBG("std_mib_write -> entry", []), - s([{[sysLocation, 0], "new_value"}]). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_asn_err() -> - snmp_test_mgr:send_bytes([48,99,67,12,0,0,0,0,0,0,5]). - -%%----------------------------------------------------------------- -%% For this test, the agent is configured for v2 and v3. -%% o Test the counters and control objects in SNMPv2-MIB -%%----------------------------------------------------------------- -snmpv2_mib_2(suite) -> []; -snmpv2_mib_2(Config) when list(Config) -> - ?LOG("snmpv2_mib_2 -> start",[]), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?DBG("snmpv2_mib_2 -> standard mib init",[]), - try_test(std_mib_init), - - ?DBG("snmpv2_mib_2 -> get number of (so far) bad versions",[]), - InBadVsns = try_test(std_mib_a), - - ?DBG("snmpv2_mib_2 -> make a bad version read",[]), - put(vsn, v1), - try_test(std_mib_read), - - ?DBG("snmpv2_mib_2 -> bad version read",[]), - put(vsn, v2), - Bad = try_test(std_mib_b, [InBadVsns]), - - ?DBG("snmpv2_mib_2 -> read with bad community",[]), - try_test(std_mib_read, [], [{community, "bad community"}]), - - ?DBG("snmpv2_mib_2 -> write with public community",[]), - try_test(std_mib_write, [], [{community, "public"}]), - - ?DBG("snmpv2_mib_2 -> asn err",[]), - try_test(std_mib_asn_err), - - ?DBG("snmpv2_mib_2 -> check counters",[]), - try_test(std_mib_c, [Bad]), - - ?DBG("snmpv2_mib_2 -> get som counters",[]), - try_test(snmpv2_mib_a), - - ?DBG("snmpv2_mib_2 -> enable auth traps, and await some",[]), - try_test(std_mib_finish), - - ?DBG("snmpv2_mib_2 -> force auth failure, and await trap, " - "then disable auth traps",[]), - try_test(snmpv2_mib_test_finish, [], [{community, "bad community"}]), - - ?LOG("snmpv2_mib_2 -> done",[]). - -%% Req. SNMPv2-MIB -snmpv2_mib_3(suite) -> []; -snmpv2_mib_3(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - InBadVsns = try_test(std_mib_a), - put(vsn, v1), - try_test(std_mib_read), - put(vsn, v3), - _Bad = try_test(std_mib_b, [InBadVsns]), - try_test(snmpv2_mib_a), - - try_test(std_mib_finish). - --define(authenticationFailure, [1,3,6,1,6,3,1,1,5,5]). - -%% Req. SNMPv2-MIB -snmpv2_mib_test_finish() -> - %% force a authenticationFailure - ?DBG("ma_v2_inform -> write to std mib",[]), - std_mib_write(), - - %% check that we got a trap - ?DBG("ma_v2_inform -> await trap",[]), - ?line expect(2, v2trap, [{[sysUpTime,0], any}, - {[snmpTrapOID,0], ?authenticationFailure}]), - - %% and the the inform - ?DBG("ma_v2_inform -> await inform",[]), - ?line expect(2, {inform,true}, [{[sysUpTime,0], any}, - {[snmpTrapOID,0],?authenticationFailure}]). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_a() -> - ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), - ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), - ?line InPkts2 = InPkts + 1, - - ?line [InBadVsns] = get_req(4, [[snmpInBadVersions,0]]), - InBadVsns. - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_b(InBadVsns) -> - ?line [InBadVsns2] = get_req(1, [[snmpInBadVersions,0]]), - ?line InBadVsns2 = InBadVsns + 1, - ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), - ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), - ?line InPkts2 = InPkts + 1, - ?line [InBadCommunityNames, InBadCommunityUses, InASNErrs] = - get_req(4, [[snmpInBadCommunityNames,0], - [snmpInBadCommunityUses,0], - [snmpInASNParseErrs, 0]]), - {InBadCommunityNames, InBadCommunityUses, InASNErrs}. - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_c({InBadCommunityNames, InBadCommunityUses, InASNErrs}) -> - ?line [InBadCommunityNames2, InBadCommunityUses2, InASNErrs2] = - get_req(1, [[snmpInBadCommunityNames,0], - [snmpInBadCommunityUses,0], - [snmpInASNParseErrs, 0]]), - ?line InBadCommunityNames2 = InBadCommunityNames + 1, - ?line InBadCommunityUses2 = InBadCommunityUses + 1, - ?line InASNErrs2 = InASNErrs + 1. - -%% Req. SNMPv2-MIB -snmpv2_mib_a() -> - ?line [SetSerial] = get_req(2, [[snmpSetSerialNo,0]]), - s([{[snmpSetSerialNo,0], SetSerial}, {[sysLocation, 0], "val2"}]), - ?line expect(3, [{[snmpSetSerialNo,0], SetSerial}, - {[sysLocation, 0], "val2"}]), - s([{[sysLocation, 0], "val3"}, {[snmpSetSerialNo,0], SetSerial}]), - ?line expect(4, inconsistentValue, 2, - [{[sysLocation, 0], "val3"}, - {[snmpSetSerialNo,0], SetSerial}]), - ?line ["val2"] = get_req(5, [[sysLocation,0]]). - - -%%----------------------------------------------------------------- -%% o Bad community uses/name is tested already -%% in SNMPv2-MIB and STANDARD-MIB. -%% o Test add/deletion of rows. -%%----------------------------------------------------------------- -snmp_community_mib(suite) -> []; -snmp_community_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - try_test(snmp_community_mib), - ?line unload_master("SNMP-COMMUNITY-MIB"). - -snmp_community_mib_2(X) -> snmp_community_mib(X). - -%% Req. SNMP-COMMUNITY-MIB -snmp_community_mib() -> - ?INF("NOT YET IMPLEMENTED", []), - nyi. - -%%----------------------------------------------------------------- -%% o Test engine boots / time -%%----------------------------------------------------------------- -snmp_framework_mib(suite) -> []; -snmp_framework_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - try_test(snmp_framework_mib), - ?line unload_master("SNMP-FRAMEWORK-MIB"). - -snmp_framework_mib_2(X) -> snmp_framework_mib(X). - -snmp_framework_mib_3(suite) -> []; -snmp_framework_mib_3(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - try_test(snmp_framework_mib). - - -%% Req. SNMP-FRAMEWORK-MIB -snmp_framework_mib() -> - ?line ["agentEngine"] = get_req(1, [[snmpEngineID,0]]), - ?line [EngineTime] = get_req(2, [[snmpEngineTime,0]]), - sleep(5000), - ?line [EngineTime2] = get_req(3, [[snmpEngineTime,0]]), - if - EngineTime+7 < EngineTime2 -> - ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); - EngineTime+4 > EngineTime2 -> - ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); - true -> ok - end, - ?line case get_req(4, [[snmpEngineBoots,0]]) of - [Boots] when integer(Boots) -> ok; - Else -> ?FAIL(Else) - end, - ok. - -%%----------------------------------------------------------------- -%% o Test the counters -%%----------------------------------------------------------------- -snmp_mpd_mib_3(suite) -> []; -snmp_mpd_mib_3(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - UnknownPDUHs = try_test(snmp_mpd_mib_a), - try_test(snmp_mpd_mib_b, [], [{context_engine_id, "bad engine"}]), - try_test(snmp_mpd_mib_c, [UnknownPDUHs]). - - -%% Req. SNMP-MPD-MIB -snmp_mpd_mib_a() -> - ?line [UnknownSecs, InvalidMsgs] = - get_req(1, [[snmpUnknownSecurityModels,0], - [snmpInvalidMsgs,0]]), - Pdu = #pdu{type = 'get-request', - request_id = 23, - error_status = noError, - error_index = 0, - varbinds = []}, - SPdu = #scopedPdu{contextEngineID = "agentEngine", - contextName = "", - data = Pdu}, - ?line SPDUBytes = snmp_pdus:enc_scoped_pdu(SPdu), - V3Hdr1 = #v3_hdr{msgID = 21, - msgMaxSize = 484, - msgFlags = [7], - msgSecurityModel = 23, % bad sec model - msgSecurityParameters = []}, - V3Hdr2 = #v3_hdr{msgID = 21, - msgMaxSize = 484, - msgFlags = [6], % bad flag combination - msgSecurityModel = 3, - msgSecurityParameters = []}, - Message1 = #message{version = 'version-3', vsn_hdr = V3Hdr1, - data = SPDUBytes}, - Message2 = #message{version = 'version-3', vsn_hdr = V3Hdr2, - data = SPDUBytes}, - ?line MsgBytes1 = snmp_pdus:enc_message_only(Message1), - ?line MsgBytes2 = snmp_pdus:enc_message_only(Message2), - snmp_test_mgr:send_bytes(MsgBytes1), - snmp_test_mgr:send_bytes(MsgBytes2), - - ?line [UnknownSecs2, InvalidMsgs2, UnknownPDUHs] = - get_req(1, [[snmpUnknownSecurityModels,0], - [snmpInvalidMsgs,0], - [snmpUnknownPDUHandlers, 0]]), - ?line UnknownSecs2 = UnknownSecs + 1, - ?line InvalidMsgs2 = InvalidMsgs + 1, - UnknownPDUHs. - --define(snmpUnknownPDUHandlers_instance, [1,3,6,1,6,3,11,2,1,3,0]). -snmp_mpd_mib_b() -> - g([[sysUpTime,0]]), - ?line expect(1, report, [{?snmpUnknownPDUHandlers_instance, any}]). - - -snmp_mpd_mib_c(UnknownPDUHs) -> - ?line [UnknownPDUHs2] = get_req(1, [[snmpUnknownPDUHandlers, 0]]), - ?line UnknownPDUHs2 = UnknownPDUHs + 1. - - -snmp_target_mib(suite) -> []; -snmp_target_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-TARGET-MIB"), - try_test(snmp_target_mib), - ?line unload_master("SNMP-TARGET-MIB"). - -snmp_target_mib_2(X) -> snmp_target_mib(X). - -snmp_target_mib_3(X) -> snmp_target_mib(X). - -snmp_target_mib() -> - ?INF("NOT YET IMPLEMENTED", []), - nyi. - -snmp_notification_mib(suite) -> []; -snmp_notification_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - try_test(snmp_notification_mib), - ?line unload_master("SNMP-NOTIFICATION-MIB"). - -snmp_notification_mib_2(X) -> snmp_notification_mib(X). - -snmp_notification_mib_3(X) -> snmp_notification_mib(X). - -snmp_notification_mib() -> - ?INF("NOT YET IMPLEMENTED", []), - nyi. - -%%----------------------------------------------------------------- -%% o add/delete views and try them -%% o try boundaries -%%----------------------------------------------------------------- -snmp_view_based_acm_mib(suite) -> []; -snmp_view_based_acm_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - ?line load_master("Test2"), - snmp_view_based_acm_mib(), - ?line unload_master("Test2"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). - -snmp_view_based_acm_mib_2(X) -> snmp_view_based_acm_mib(X). - -snmp_view_based_acm_mib_3(X) -> snmp_view_based_acm_mib(X). - -snmp_view_based_acm_mib() -> - snmpa:verbosity(net_if,trace), - snmpa:verbosity(master_agent,trace), - ?LOG("start snmp_view_based_acm_mib test",[]), - %% The user "no-rights" is present in USM, and is mapped to security - %% name 'no-rights", which is not present in VACM. - %% So, we'll add rights for it, try them and delete them. - %% We'll give "no-rights" write access to tDescr.0 and read access - %% to tDescr2.0 - %% These are the options we'll use to the mgr - Opts = [{user, "no-rights"}, {community, "no-rights"}], - %% Find the valid secmodel, and one invalid secmodel. - {SecMod, InvSecMod} = - case get(vsn) of - v1 -> {?SEC_V1, ?SEC_V2C}; - v2 -> {?SEC_V2C, ?SEC_USM}; - v3 -> {?SEC_USM, ?SEC_V1} - end, - ?DBG("assign rights for 'no-rights'",[]), - ?line try_test(use_no_rights, [], Opts), - - %% Now, add a mapping from "no-rights" -> "no-rights-group" - GRow1Status = [vacmSecurityToGroupStatus,[SecMod, 9,"no-rights"]], - GRow1 = - [{[vacmGroupName, [SecMod, 9,"no-rights"]], "no-rights-group"}, - {GRow1Status, ?createAndGo}], - ?DBG("set '~p'",[GRow1]), - ?line try_test(do_set, [GRow1]), - - ?DBG("assign rights for 'no-rights'",[]), - ?line try_test(use_no_rights, [], Opts), - - %% Create a mapping for another sec model, and make sure it dosn't - %% give us access - GRow2Status = [vacmSecurityToGroupStatus,[InvSecMod, 9,"no-rights"]], - GRow2 = [{[vacmGroupName, [InvSecMod, 9, "no-rights"]], "initial"}, - {GRow2Status, ?createAndGo}], - - ?DBG("set '~p'",[GRow2]), - ?line try_test(do_set, [GRow2]), - - ?DBG("assign rights for 'no-rights'",[]), - ?line try_test(use_no_rights, [], Opts), - - %% Delete that row - ?line try_test(del_row, [GRow2Status]), - - RVName = "rv_name", - WVName = "wv_name", - - %% Access row - ARow1Idx = [15 | "no-rights-group"] ++ [0, ?SEC_ANY, 1], - ARow1Status = [vacmAccessStatus, ARow1Idx], - ARow1 = [{[vacmAccessContextMatch, ARow1Idx], 1}, - {[vacmAccessReadViewName, ARow1Idx], RVName}, - {[vacmAccessWriteViewName, ARow1Idx], WVName}, - {ARow1Status, ?createAndGo}], - - %% This access row would give acces, if InvSecMod was valid. - ARow2Idx = [15 | "no-rights-group"] ++ [0, InvSecMod, 1], - ARow2Status = [vacmAccessStatus, ARow2Idx], - ARow2 = [{[vacmAccessContextMatch, ARow2Idx], 1}, - {[vacmAccessReadViewName, ARow2Idx], "internet"}, - {[vacmAccessWriteViewName, ARow2Idx], "internet"}, - {ARow2Status, ?createAndGo}], - - ?line try_test(do_set, [ARow2]), - - ?line try_test(use_no_rights, [], Opts), - - %% Delete that row - ?line try_test(del_row, [ARow2Status]), - - - %% Add valid row - ?line try_test(do_set, [ARow1]), - - ?line try_test(use_no_rights, [], Opts), - - %% Create the view family - VRow1Idx = mk_ln(RVName) ++ mk_ln(?xDescr), % object access - VRow2Idx = mk_ln(RVName) ++ mk_ln(?xDescr2 ++ [0]), % instance access - VRow3Idx = mk_ln(WVName) ++ mk_ln(?xDescr), % object access - VRow4Idx = mk_ln(WVName) ++ mk_ln(?xDescr ++ [0]), % instance access - VRow1Status = [vacmViewTreeFamilyStatus, VRow1Idx], - VRow2Status = [vacmViewTreeFamilyStatus, VRow2Idx], - VRow3Status = [vacmViewTreeFamilyStatus, VRow3Idx], - VRow4Status = [vacmViewTreeFamilyStatus, VRow4Idx], - - ?line try_test(add_row, [VRow1Status]), - ?line try_test(add_row, [VRow2Status]), - ?line try_test(add_row, [VRow3Status]), - - %% We're supposed to have access now... - ?line try_test(use_rights, [], Opts), - - %% Change Row3 to Row4 - ?line try_test(del_row, [VRow3Status]), - ?line try_test(add_row, [VRow4Status]), - - %% We should still have access... - ?line try_test(use_rights, [], Opts), - - %% Delete rows - ?line try_test(del_row, [GRow1Status]), - - ?line try_test(use_no_rights, [], Opts), - - %% Delete rest of rows - ?line try_test(del_row, [ARow1Status]), - ?line try_test(del_row, [VRow1Status]), - ?line try_test(del_row, [VRow2Status]), - ?line try_test(del_row, [VRow4Status]), - - ?line try_test(use_no_rights, [], Opts), - snmpa:verbosity(master_agent,log). - -do_set(Row) -> - s(Row), - expect(1, Row). - -add_row(RowStatus) -> - s([{RowStatus, ?createAndGo}]), - expect(1, [{RowStatus, ?createAndGo}]). - -del_row(RowStatus) -> - s([{RowStatus, ?destroy}]), - expect(1, [{RowStatus, ?destroy}]). - - - -use_no_rights() -> - g([[xDescr,0]]), - ?v1_2_3(expect(11, noSuchName, 1, any), - expect(12, [{[xDescr,0], noSuchObject}]), - expect(13, authorizationError, 1, any)), - g([[xDescr2,0]]), - ?v1_2_3(expect(21, noSuchName, 1, any), - expect(22, [{[xDescr2,0], noSuchObject}]), - expect(23, authorizationError, 1, any)), - gn([[xDescr]]), - ?v1_2_3(expect(31, noSuchName, 1, any), - expect(32, [{[xDescr], endOfMibView}]), - expect(33, authorizationError, 1, any)), - s([{[xDescr,0], "tryit"}]), - ?v1_2_3(expect(41, noSuchName, 1, any), - expect(42, noAccess, 1, any), - expect(43, authorizationError, 1, any)). - - -use_rights() -> - g([[xDescr,0]]), - expect(1, [{[xDescr,0], any}]), - g([[xDescr2,0]]), - expect(2, [{[xDescr2,0], any}]), - s([{[xDescr,0], "tryit"}]), - expect(3, noError, 0, any), - g([[xDescr,0]]), - expect(4, [{[xDescr,0], "tryit"}]). - -mk_ln(X) -> - [length(X) | X]. - -%%----------------------------------------------------------------- -%% o add/delete users and try them -%% o test all secLevels -%% o test all combinations of protocols -%% o try bad ops; check counters -%%----------------------------------------------------------------- -snmp_user_based_sm_mib_3(suite) -> []; -snmp_user_based_sm_mib_3(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - _AgentDir = ?config(agent_dir, Config), - ?line load_master_std("SNMP-USER-BASED-SM-MIB"), - - %% The newUser used here already has VACM access. - - %% Add a new user in the simplest way; just createAndGo - try_test(v3_sync, [[{usm_add_user1, []}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - %% Try to use the new user - ?line load_master("Test2"), - try_test(v3_sync, [[{usm_use_user, []}]], - [{sec_level, authPriv}, {user, "newUser"}]), - ?line unload_master("Test2"), - - ShaKey1 = snmp:passwd2localized_key(sha, "new sha password", "agentEngine"), - DesKey1 = lists:sublist(ShaKey1, 16), - - %% Change the new user's keys - 1 - try_test(v3_sync, [[{usm_key_change1, [ShaKey1, DesKey1]}]], - [{sec_level, authPriv}, {user, "newUser"}]), - - %% Try to use the new keys - MgrDir = ?config(mgr_dir, Config), - ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), - ?line load_master("Test2"), - try_test(v3_sync, [[{usm_use_user, []}]], - [{sec_level, authPriv}, {user, "newUser"}]), - ?line unload_master("Test2"), - - ShaKey2 = snmp:passwd2localized_key(sha, "newer password", "agentEngine"), - DesKey2 = lists:sublist(ShaKey2, 16), - - %% Change the new user's keys - 2 - ?line try_test(v3_sync, - [[{usm_key_change2, [ShaKey1, DesKey1, ShaKey2, DesKey2]}]], - [{sec_level, authPriv}, {user, "newUser"}]), - - %% Try to use the new keys - reset_usm_mgr(MgrDir), - ?line rewrite_usm_mgr(MgrDir, ShaKey2, DesKey2), - ?line load_master("Test2"), - ?line try_test(v3_sync, [[{usm_use_user, []}]], - [{sec_level, authPriv}, {user, "newUser"}]), - ?line unload_master("Test2"), - reset_usm_mgr(MgrDir), - - %% Change the new user's keys - 3 - ?line try_test(v3_sync, - [[{usm_key_change3, [ShaKey2, DesKey2, ShaKey1, DesKey1]}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - %% Try to use the new keys - ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), - ?line load_master("Test2"), - try_test(v3_sync, [[{usm_use_user, []}]], - [{sec_level, authPriv}, {user, "newUser"}]), - ?line unload_master("Test2"), - reset_usm_mgr(MgrDir), - - %% Try some read requests - ?line try_test(v3_sync, [[{usm_read, []}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - %% Delete the new user - ?line try_test(v3_sync, [[{usm_del_user, []}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - %% Try some bad requests - ?line try_test(v3_sync, [[{usm_bad, []}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - ?line unload_master("SNMP-USER-BASED-SM-MIB"). - --define(usmUserSecurityName, [1,3,6,1,6,3,15,1,2,2,1,3]). - -usm_add_user1() -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - RowPointer = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], - Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer}, - {[usmUserStatus, NewRowIndex], ?createAndGo}], - ?line s(Vbs1), - ?line expect(1, Vbs1), - ok. - -usm_use_user() -> - v2_proc(). - - -%% Change own public keys -usm_key_change1(ShaKey, DesKey) -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - "passwd_shaxxxxxxxxxx", - ShaKey), - DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - "passwd_desxxxxxx", - DesKey), - Vbs1 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, - {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], - s(Vbs1), - ?line expect(1, Vbs1). - -%% Change own private keys -usm_key_change2(OldShaKey, OldDesKey, ShaKey, DesKey) -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - OldShaKey, - ShaKey), - DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - OldDesKey, - DesKey), - Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}, - {[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], - s(Vbs1), - ?line expect(1, Vbs1). - -%% Change other's public keys -usm_key_change3(OldShaKey, OldDesKey, ShaKey, DesKey) -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - OldShaKey, - ShaKey), - DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - OldDesKey, - DesKey), - Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}], - s(Vbs1), - ?line expect(1, noAccess, 1, any), - Vbs2 = [{[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], - s(Vbs2), - ?line expect(2, noAccess, 1, any), - - - Vbs3 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, - {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], - s(Vbs3), - ?line expect(1, Vbs3). - -usm_read() -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - ?line g([[usmUserSecurityName, NewRowIndex], - [usmUserCloneFrom, NewRowIndex], - [usmUserAuthKeyChange, NewRowIndex], - [usmUserOwnAuthKeyChange, NewRowIndex], - [usmUserPrivKeyChange, NewRowIndex], - [usmUserOwnPrivKeyChange, NewRowIndex]]), - ?line expect(1, - [{[usmUserSecurityName, NewRowIndex], "newUser"}, - {[usmUserCloneFrom, NewRowIndex], [0,0]}, - {[usmUserAuthKeyChange, NewRowIndex], ""}, - {[usmUserOwnAuthKeyChange, NewRowIndex], ""}, - {[usmUserPrivKeyChange, NewRowIndex], ""}, - {[usmUserOwnPrivKeyChange, NewRowIndex], ""}]), - ok. - - - -usm_del_user() -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - Vbs1 = [{[usmUserStatus, NewRowIndex], ?destroy}], - ?line s(Vbs1), - ?line expect(1, Vbs1), - ok. - --define(usmUserCloneFrom, [1,3,6,1,6,3,15,1,2,2,1,4]). - --define(usmNoAuthProtocol, [1,3,6,1,6,3,10,1,1,1]). - --define(usmHMACMD5AuthProtocol, [1,3,6,1,6,3,10,1,1,2]). - --define(usmHMACSHAAuthProtocol, [1,3,6,1,6,3,10,1,1,3]). - --define(usmNoPrivProtocol, [1,3,6,1,6,3,10,1,2,1]). - --define(usmDESPrivProtocol, [1,3,6,1,6,3,10,1,2,2]). - -usm_bad() -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - RowPointer1 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDOS"], - Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer1}, - {[usmUserStatus, NewRowIndex], ?createAndGo}], - ?line s(Vbs1), - ?line expect(1, inconsistentName, 1, any), - - RowPointer2 = ?usmUserCloneFrom ++ [11|"agentEngine"] ++ [7|"privDES"], - Vbs2 = [{[usmUserCloneFrom, NewRowIndex], RowPointer2}, - {[usmUserStatus, NewRowIndex], ?createAndGo}], - ?line s(Vbs2), - ?line expect(2, wrongValue, 1, any), - - RowPointer3 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], - Vbs3 = [{[usmUserCloneFrom, NewRowIndex], RowPointer3}, - {[usmUserStatus, NewRowIndex], ?createAndGo}], - ?line s(Vbs3), - ?line expect(3, Vbs3), - ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmNoAuthProtocol}]), - ?line expect(4, inconsistentValue, 1, any), - ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmHMACMD5AuthProtocol}]), - ?line expect(5, inconsistentValue, 1, any), - ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmDESPrivProtocol}]), - ?line expect(6, wrongValue, 1, any), - ?line s([{[usmUserPrivProtocol, NewRowIndex], ?usmHMACSHAAuthProtocol}]), - ?line expect(7, wrongValue, 1, any), - - Vbs4 = [{[usmUserStatus, NewRowIndex], ?destroy}], - ?line s(Vbs4), - ?line expect(1, Vbs4), - - ok. - - -%%----------------------------------------------------------------- -%% Loop through entire MIB, to make sure that all instrum. funcs -%% works. -%% Load all std mibs that are not loaded by default. -%%----------------------------------------------------------------- -loop_mib(suite) -> []; -loop_mib(Config) when list(Config) -> - ?LOG("loop_mib -> initiate case",[]), - %% snmpa:verbosity(master_agent,debug), - %% snmpa:verbosity(mib_server,info), - {SaNode, MgrNode, MibDir} = init_case(Config), - ?DBG("loop_mib -> ~n" - "\tSaNode: ~p~n" - "\tMgrNode: ~p~n" - "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), - ?DBG("loop_mib -> load mib SNMP-COMMUNITY-MIB",[]), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?DBG("loop_mib -> load mib SNMP-MPD-MIB",[]), - ?line load_master_std("SNMP-MPD-MIB"), - ?DBG("loop_mib -> load mib SNMP-TARGET-MIB",[]), - ?line load_master_std("SNMP-TARGET-MIB"), - ?DBG("loop_mib -> load mib SNMP-NOTIFICATION-MIB",[]), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?DBG("loop_mib -> load mib SNMP-FRAMEWORK-MIB",[]), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?DBG("loop_mib -> load mib SNMP-VIEW-BASED-ACM-MIB",[]), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - ?DBG("loop_mib -> try",[]), - try_test(loop_mib_1), - ?DBG("loop_mib -> unload mib SNMP-COMMUNITY-MIB",[]), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?DBG("loop_mib -> unload mib SNMP-MPD-MIB",[]), - ?line unload_master("SNMP-MPD-MIB"), - ?DBG("loop_mib -> unload mib SNMP-TARGET-MIB",[]), - ?line unload_master("SNMP-TARGET-MIB"), - ?DBG("loop_mib -> unload mib SNMP-NOTIFICATION-MIB",[]), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?DBG("loop_mib -> unload mib SNMP-FRAMEWORK-MIB",[]), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?DBG("loop_mib -> unload mib SNMP-VIEW-BASED-ACM-MIB",[]), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - %% snmpa:verbosity(master_agent,log), - %% snmpa:verbosity(mib_server,silence), - ?LOG("loop_mib -> done",[]). - - -loop_mib_2(suite) -> []; -loop_mib_2(Config) when list(Config) -> - ?LOG("loop_mib_2 -> initiate case",[]), - {SaNode, MgrNode, MibDir} = init_case(Config), - ?DBG("loop_mib_2 -> ~n" - "\tSaNode: ~p~n" - "\tMgrNode: ~p~n" - "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), - ?DBG("loop_mib_2 -> load mibs",[]), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-MPD-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - try_test(loop_mib_2), - ?DBG("loop_mib_2 -> unload mibs",[]), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?line unload_master("SNMP-MPD-MIB"), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - ?LOG("loop_mib_2 -> done",[]). - - -loop_mib_3(suite) -> []; -loop_mib_3(Config) when list(Config) -> - ?LOG("loop_mib_3 -> initiate case",[]), - {SaNode, MgrNode, MibDir} = init_case(Config), - ?DBG("loop_mib_3 -> ~n" - "\tSaNode: ~p~n" - "\tMgrNode: ~p~n" - "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), - ?DBG("loop_mib_3 -> load mibs",[]), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - ?line load_master_std("SNMP-USER-BASED-SM-MIB"), - try_test(loop_mib_2), - ?DBG("loop_mib_3 -> unload mibs",[]), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - ?line unload_master("SNMP-USER-BASED-SM-MIB"), - ?LOG("loop_mib_3 -> done",[]). - - -%% Req. As many mibs all possible -loop_mib_1() -> - ?DBG("loop_mib_1 -> entry",[]), - N = loop_it_1([1,1], 0), - io:format(user, "found ~w varibles\n", [N]), - ?line N = if N < 100 -> 100; - true -> N - end. - - -loop_it_1(Oid, N) -> - ?DBG("loop_it_1 -> entry with~n" - "\tOid: ~p~n" - "\tN: ~p",[Oid,N]), - case get_next_req([Oid]) of - #pdu{type='get-response', error_status=noError, error_index=0, - varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> - ?DBG("loop_it_1 -> ~n" - "\tNOid: ~p~n" - "\tValue: ~p",[NOid,Value]), - ?line [Value2] = get_req(1, [NOid]), % must not be same - ?DBG("loop_it_1 -> ~n" - "\tValue2: ~p",[Value2]), - loop_it_1(NOid, N+1); - #pdu{type='get-response', error_status=noSuchName, error_index=1, - varbinds=[_]} -> - ?DBG("loop_it_1 -> done",[]), - N; - - #pdu{type = Type, error_status = Err, error_index = Idx, - varbinds = Vbs} -> - exit({unexpected_pdu, ?LINE, Type, Err, Idx, Vbs}) - end. - -%% Req. As many mibs all possible -loop_mib_2() -> - ?DBG("loop_mib_1 -> entry",[]), - N = loop_it_2([1,1], 0), - io:format(user, "found ~w varibles\n", [N]), - ?line N = if N < 100 -> 100; - true -> N - end. - - -loop_it_2(Oid, N) -> - ?DBG("loop_it_2 -> entry with~n" - "\tOid: ~p~n" - "\tN: ~p",[Oid,N]), - case get_next_req([Oid]) of - #pdu{type='get-response', error_status=noError, error_index=0, - varbinds=[#varbind{oid = NOid, value = endOfMibView}]} -> - ?DBG("loop_it_2 -> ~n" - "\tNOid: ~p",[NOid]), - N; - #pdu{type='get-response', error_status=noError, error_index=0, - varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> - ?DBG("loop_it_2 -> ~n" - "\tNOid: ~p~n" - "\tValue: ~p",[NOid,Value]), - ?line [Value2] = get_req(1, [NOid]), % must not be same - ?DBG("loop_it_2 -> ~n" - "\tValue2: ~p",[Value2]), - loop_it_2(NOid, N+1) - end. - - -%%%----------------------------------------------------------------- -%%% Testing of reported bugs and other tickets. -%%%----------------------------------------------------------------- - -reported_bugs(suite) -> - [otp_1128, otp_1129, otp_1131, otp_1162, - otp_1222, otp_1298, otp_1331, otp_1338, - otp_1342, otp_2776, otp_2979, otp_3187, otp_3725]. - -reported_bugs_2(suite) -> - [otp_1128_2, otp_1129_2, otp_1131_2, otp_1162_2, - otp_1222_2, otp_1298_2, otp_1331_2, otp_1338_2, - otp_1342_2, otp_2776_2, otp_2979_2, otp_3187_2]. - -reported_bugs_3(suite) -> - [otp_1128_3, otp_1129_3, otp_1131_3, otp_1162_3, - otp_1222_3, otp_1298_3, otp_1331_3, otp_1338_3, - otp_1342_3, otp_2776_3, otp_2979_3, otp_3187_3, - otp_3542]. - - -%% These are (ticket) test cases where the initiation has to be done -%% individually. -tickets(suite) -> - [otp_4394]. - -%%----------------------------------------------------------------- -%% Ticket: OTP-1128 -%% Slogan: Bug in handling of createAndWait set-requests. -%%----------------------------------------------------------------- -otp_1128(suite) -> []; -otp_1128(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(otp_1128), - ?line unload_master("OLD-SNMPEA-MIB"). - -otp_1128_2(X) -> otp_1128(X). - -otp_1128_3(X) -> otp_1128(X). - -otp_1128() -> - io:format("Testing bug reported in ticket OTP-1128...~n"), - - NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], - NewKeyc4 = [intCommunityAccess,get(mip),is("test")], - NewKeyc5 = [intCommunityStatus,get(mip),is("test")], - - s([{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), - ?line expect(28, [{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), - g([NewKeyc5]), - ?line expect(29, [{NewKeyc5, ?notReady}]), - s([{NewKeyc5, ?active}, {NewKeyc3, 2}]), - ?line expect(30, [{NewKeyc5, ?active}, {NewKeyc3, 2}]), - g([NewKeyc5]), - ?line expect(31, [{NewKeyc5, ?active}]), - s([{NewKeyc5, ?destroy}]), - ?line expect(32, [{NewKeyc5, ?destroy}]). - -%%----------------------------------------------------------------- -%% Ticket: OTP-1129, OTP-1169 -%% Slogan: snmpa:int_to_enum crashes on bad oids -%%----------------------------------------------------------------- -otp_1129(suite) -> []; -otp_1129(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas3"), - try_test(otp_1129_i, [node()]), - ?line unload_master("Klas3"). - -otp_1129_2(X) -> otp_1129(X). - -otp_1129_3(X) -> otp_1129(X). - -otp_1129_i(MaNode) -> - io:format("Testing bug reported in ticket OTP-1129...~n"), - false = rpc:call(MaNode, snmp, int_to_enum, [iso, 1]), - false = rpc:call(MaNode, snmp, int_to_enum, [isox, 1]). - -%%----------------------------------------------------------------- -%% Ticket: OTP-1131 -%% Slogan: Agent crashes / erlang node halts if RowIndex in a -%% setrequest is of bad type, e.g. an INDEX {INTEGER}, -%% and RowIdenx [3,2]. -%%----------------------------------------------------------------- -otp_1131(suite) -> []; -otp_1131(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas1"), - try_test(otp_1131), - ?line unload_master("Klas1"). - -otp_1131_2(X) -> otp_1131(X). - -otp_1131_3(X) -> otp_1131(X). - -otp_1131() -> - io:format("Testing bug reported in ticket OTP-1131...~n"), - s([{[friendsEntry, [2, 3, 1]], s, "kompis3"}, - {[friendsEntry, [3, 3, 1]], i, ?createAndGo}]), - ?line expect(1, ?v1_2(noSuchName, noCreation), 2, any). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1162 -%% Slogan: snmp_agent can't handle wrongValue from instrum.func -%%----------------------------------------------------------------- -otp_1162(suite) -> []; -otp_1162(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - try_test(otp_1162), - stop_subagent(SA). - -otp_1162_2(X) -> otp_1162(X). - -otp_1162_3(X) -> otp_1162(X). - -otp_1162() -> - s([{[sa, [2,0]], 6}]), % wrongValue (i is_set_ok) - ?line expect(1, ?v1_2(badValue, wrongValue), 1, any). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1222 -%% Slogan: snmp agent crash if faulty index is returned from instrum -%%----------------------------------------------------------------- -otp_1222(suite) -> []; -otp_1222(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas3"), - ?line load_master("Klas4"), - try_test(otp_1222), - ?line unload_master("Klas3"), - ?line unload_master("Klas4"). - -otp_1222_2(X) -> otp_1222(X). - -otp_1222_3(X) -> otp_1222(X). - -otp_1222() -> - io:format("Testing bug reported in ticket OTP-1222...~n"), - s([{[fStatus4,1], 4}, {[fName4,1], 1}]), - ?line expect(1, genErr, 0, any), - s([{[fStatus4,2], 4}, {[fName4,2], 1}]), - ?line expect(2, genErr, 0, any). - -%%----------------------------------------------------------------- -%% Ticket: OTP-1298 -%% Slogan: Negative INTEGER values are treated as positive. -%%----------------------------------------------------------------- -otp_1298(suite) -> []; -otp_1298(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas2"), - try_test(otp_1298), - ?line unload_master("Klas2"). - -otp_1298_2(X) -> otp_1298(X). - -otp_1298_3(X) -> otp_1298(X). - -otp_1298() -> - io:format("Testing bug reported in ticket OTP-1298...~n"), - s([{[fint,0], -1}]), - ?line expect(1298, [{[fint,0], -1}]). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1331 -%% Slogan: snmp_generic should return noError when deleting non-ex row -%%----------------------------------------------------------------- -otp_1331(suite) -> []; -otp_1331(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(otp_1331), - ?line unload_master("OLD-SNMPEA-MIB"). - -otp_1331_2(X) -> otp_1331(X). - -otp_1331_3(X) -> otp_1331(X). - -otp_1331() -> - NewKeyc5 = [intCommunityStatus,[127,32,0,0],is("test")], - s([{NewKeyc5, ?destroy}]), - ?line expect(1, [{NewKeyc5, ?destroy}]). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1338 -%% Slogan: snmp bug in initialisation of default values for mnesia tabs -%%----------------------------------------------------------------- -otp_1338(suite) -> []; -otp_1338(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas2"), - try_test(otp_1338), - ?line unload_master("Klas2"). - -otp_1338_2(X) -> otp_1338(X). - -otp_1338_3(X) -> otp_1338(X). - -otp_1338() -> - s([{[kStatus2, 7], i, ?createAndGo}]), - ?line expect(1, [{[kStatus2, 7], ?createAndGo}]), - g([[kName2, 7]]), - ?line expect(2, [{[kName2, 7], "JJJ"}]). - -%%----------------------------------------------------------------- -%% Ticket: OTP-1342 -%% Slogan: default impl of snmp table can't handle bad index access, -%% Set when INDEX is read-write gets into an infinite loop! -%%----------------------------------------------------------------- -otp_1342(suite) -> []; -otp_1342(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas4"), - try_test(otp_1342), - ?line unload_master("Klas4"). - -otp_1342_2(X) -> otp_1342(X). - -otp_1342_3(X) -> otp_1342(X). - -otp_1342() -> - s([{[fIndex5, 1], i, 1}, - {[fName5, 1], i, 3}, - {[fStatus5, 1], i, ?createAndGo}]), - ?line expect(1, ?v1_2(noSuchName, noCreation), 3, any). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1366 -%% Slogan: snmp traps not sent to all managers -%% Note: NYI! We need a way to tell the test server that we need -%% mgrs on two different machines. -%%----------------------------------------------------------------- -otp_1366(suite) -> []; -otp_1366(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(otp_1366), - ?line unload_master("OLD-SNMPEA-MIB"). - -otp_1366_2(X) -> otp_1366(X). - -otp_1366_3(X) -> otp_1366(X). - -otp_1366() -> - ?INF("NOT YET IMPLEMENTED", []), - 'NYI'. - -%%----------------------------------------------------------------- -%% Ticket: OTP-2776 -%% Slogan: snmp:validate_date_and_time() fails when time is 00:00 -%%----------------------------------------------------------------- -otp_2776(suite) -> []; -otp_2776(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - try_test(otp_2776). - -otp_2776_2(X) -> otp_2776(X). - -otp_2776_3(X) -> otp_2776(X). - -otp_2776() -> - io:format("Testing bug reported in ticket OTP-2776...~n"), - - Dt01_valid = [19,98,9,1,1,0,23,0,43,0,0], - Dt02_valid = [19,98,9,1,0,0,0,0,43,0,0], % This is what is fixed: 00:00 - Dt03_valid = [19,98,2,28,1,0,23,0,43,0,0], - Dt04_invalid = [19,98,2,29,1,0,23,0,43,0,0], - Dt05_valid = [19,96,2,29,1,0,23,0,43,0,0], - Dt06_valid = [20,0,2,29,1,0,23,0,43,0,0], - Dt07_invalid = [19,96,2,30,1,0,23,0,43,0,0], % This is also fixed: 30/2 - Dt08_valid = [19,98,4,30,1,0,23,0,43,0,0], - Dt09_invalid = [19,98,4,31,1,0,23,0,43,0,0], % This is also fixed: 31/4 - Dt10_invalid = [], - Dt11_invalid = [kalle,hobbe], - L = [{ 1, true, Dt01_valid}, - { 2, true, Dt02_valid}, - { 3, true, Dt03_valid}, - { 4, false, Dt04_invalid}, - { 5, true, Dt05_valid}, - { 6, true, Dt06_valid}, - { 7, false, Dt07_invalid}, - { 8, true, Dt08_valid}, - { 9, false, Dt09_invalid}, - {10, false, Dt10_invalid}, - {11, false, Dt11_invalid}], - - ?line ok = validate_dat(L). - - -validate_dat(L) -> validate_dat(L,[]). - -validate_dat([],V) -> - Fun = fun({_,X}) -> case X of - ok -> false; - _ -> true - end - end, - validate_dat1( lists:reverse( lists:filter(Fun,V) ) ); -validate_dat([{Id,E,Dat}|T],V) -> - validate_dat(T,[validate_dat2(Id,E,Dat) | V]). - -validate_dat1([]) -> ok; -validate_dat1(L) -> {error,L}. - -validate_dat2(Id, E, Dat) -> - Res = case {E,snmp:validate_date_and_time(Dat)} of - {E,E} -> ok; - {E,A} -> {E,A} - end, - {Id, Res}. - - -%%----------------------------------------------------------------- -%% Ticket: OTP-2979 -%% Slogan: get-next on more than 1 column in an empty table -%% returns bad response. -%%----------------------------------------------------------------- -otp_2979(suite) -> []; -otp_2979(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Test1"), - ?line init_old(), - try_test(otp_2979), - ?line unload_master("Test1"). - -otp_2979_2(X) -> otp_2979(X). - -otp_2979_3(X) -> otp_2979(X). - -otp_2979() -> - gn([[sparseDescr], [sparseStatus]]), - ?line expect(1, [{[sparseStr,0], "slut"}, - {[sparseStr,0], "slut"}]). - -%%----------------------------------------------------------------- -%% Ticket: OTP-3187 -%% Slogan: get-next on vacmAccessTable for colums > 5 returns -%% endOfTable - should return value. -%%----------------------------------------------------------------- -otp_3187(suite) -> []; -otp_3187(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - otp_3187(), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). - -otp_3187_2(X) -> otp_3187(X). - -otp_3187_3(X) -> otp_3187(X). - -otp_3187() -> - ?line Elements = - snmp_view_based_acm_mib:vacmAccessTable(get_next,[],[4,5,6]), - lists:foreach(fun(E) -> - ?line if E == endOfTable -> - ?FAIL(endOfTable); - true -> ok - end - end, Elements). - -%%----------------------------------------------------------------- -%% Ticket: OTP-3542 -%% Slogan: -%%----------------------------------------------------------------- -otp_3542(suite) -> []; -otp_3542(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - try_test(otp_3542). - -otp_3542() -> - io:format("SNMP v3 discovery...~n"), - ?line Res = snmp_test_mgr:d(), - io:format("SNMP v3 discovery result: ~p~n",[Res]). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-3725 -%% Slogan: Slow response time on snmpa:int_to_enum -%%----------------------------------------------------------------- -otp_3725(suite) -> []; -otp_3725(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(otp_3725_test, [node()]), - ?line unload_master("OLD-SNMPEA-MIB"). - -%% Req. OLD-SNMPEA-MIB -otp_3725_test(MaNode) -> - io:format("Testing feature requested in ticket OTP-3725...~n"), - ?line rpc:call(MaNode,snmpa,verbosity,[symbolic_store,trace]), - ?line Db = rpc:call(MaNode,snmp,get_symbolic_store_db,[]), - ?DBG("otp_3725_test -> Db = ~p",[Db]), - - ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, - [Db, intAgentIpAddress]), - ?DBG("otp_3725_test -> name_to_oid for ~p: ~p",[intAgentIpAddress,OID]), - ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, oid_to_name, - [Db,OID]), - ?DBG("otp_3725_test -> oid_to_name for ~p: ~p",[OID,intAgentIpAddress]), - ?line false = rpc:call(MaNode, snmp, name_to_oid, [Db, intAgentIpAddres]), - ?line false = rpc:call(MaNode, snmp, oid_to_name, - [Db, [1,5,32,3,54,3,3,34,4]]), - ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, - [Db, intViewType, excluded]), - ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, - [Db, intViewType, 2]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, intViewType, exclude]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, intAgentIpAddress, exclude]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, intAgentIpAddre, exclude]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, intViewType, 3]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, - [Db, intAgentIpAddress, 2]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, - [Db, intAgentIpAddre, 2]), - ?line {value, active} = rpc:call(MaNode, snmp, int_to_enum, - [Db, 'RowStatus', ?active]), - ?line {value, ?destroy} = rpc:call(MaNode, snmp, enum_to_int, - [Db, 'RowStatus', destroy]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, 'RowStatus', xxxdestroy]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, 'xxRowStatus', destroy]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'RowStatus', 25]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'xxRowStatus', 1]), - ok. - - -%%----------------------------------------------------------------- -%% Ticket: OTP-4394 -%% Slogan: Target mib tag list check invalid -%%----------------------------------------------------------------- - - -otp_4394(suite) -> {req, [], {conf, - init_otp_4394, - [otp_4394_test], - finish_otp_4394}}. - -init_otp_4394(Config) when list(Config) -> - ?DBG("init_otp_4394 -> entry with" - "~n Config: ~p", [Config]), - ?line AgentDir = ?config(agent_dir, Config), - ?line MgrDir = ?config(mgr_dir, Config), - ?line Ip = ?config(ip, Config), - ?line otp_4394_config(AgentDir, MgrDir, Ip), - MasterAgentVerbosity = {master_agent_verbosity, trace}, - NetIfVerbosity = {net_if_verbosity, trace}, - Opts = [MasterAgentVerbosity,NetIfVerbosity], - [{vsn, v1} | start_v1_agent(Config,Opts)]. - -otp_4394_config(AgentDir, MgrDir, Ip0) -> - ?DBG("otp_4394_config -> entry with" - "~n AgentDir: ~p" - "~n MgrDir: ~p" - "~n Ip0: ~p", [AgentDir, MgrDir, Ip0]), - Vsn = [v1], - Ip = tuple_to_list(Ip0), - ?line snmp_config:write_agent_snmp_files(AgentDir, Vsn, Ip, - ?TRAP_UDP, Ip, 4000, - "OTP-4394 test"), - ?line case update_usm(Vsn, AgentDir) of - true -> - ?line copy_file(filename:join(AgentDir, "usm.conf"), - filename:join(MgrDir, "usm.conf")), - ?line update_usm_mgr(Vsn, MgrDir); - false -> - ?line ok - end, - C1 = {"a", "all-rights", "initial", "", "pc"}, - C2 = {"c", "secret", "secret_name", "", "secret_tag"}, - ?line write_community_conf(AgentDir, [C1, C2]), - ?line update_vacm(Vsn, AgentDir), - Ta1 = {"shelob v1", - [134,138,177,177], 5000, 1500, 3, %% Använd Ip och modda - "pc1", - "target_v1", "", - %% [255,255,255,255,0,0], - [], - 2048}, - Ta2 = {"bifur v1", - [134,138,177,75], 5000, 1500, 3, %% Använd Ip - "pc2", - "target_v1", "", - %% [255,255,255,255,0,0], - [], 2048}, - ?line write_target_addr_conf(AgentDir, [Ta1, Ta2]), - ?line write_target_params_conf(AgentDir, Vsn), - ?line write_notify_conf(AgentDir), - ok. - - - -finish_otp_4394(Config) when list(Config) -> - ?DBG("finish_otp_4394 -> entry", []), - C1 = stop_agent(Config), - delete_files(C1), - erase(mgr_node), - lists:keydelete(vsn, 1, C1). - -otp_4394_test(suite) -> []; -otp_4394_test(Config) -> - ?DBG("otp_4394_test -> entry", []), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - try_test(otp_4394_test1), - ?DBG("otp_4394_test -> done", []), - ok. - -otp_4394_test1() -> - ?DBG("otp_4394_test1 -> entry", []), - gn([[1,1]]), - Res = - case snmp_test_mgr:expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]) of - %% {error, 1, {"?",[]}, {"~w",[timeout]}} - {error, 1, _, {_, [timeout]}} -> - ?DBG("otp_4394_test1 -> expected result: timeout", []), - ok; - Else -> - Else - end, - ?DBG("otp_4394_test1 -> done with: ~p", [Res]), - Res. - - -%%%-------------------------------------------------- -%%% Used to test the standard mib with our -%%% configuration. -%%%-------------------------------------------------- -run(F, A, Opts) -> - M = get(mib_dir), - Dir = get(mgr_dir), - User = snmp_misc:get_option(user, Opts, "all-rights"), - SecLevel = snmp_misc:get_option(sec_level, Opts, noAuthNoPriv), - EngineID = snmp_misc:get_option(engine_id, Opts, "agentEngine"), - CtxEngineID = snmp_misc:get_option(context_engine_id, Opts, EngineID), - Community = snmp_misc:get_option(community, Opts, "all-rights"), - ?DBG("run -> start crypto app",[]), - Crypto = case os:type() of - vxworks -> - no_crypto; - _ -> - ?CRYPTO_START() - end, - ?DBG("run -> Crypto: ~p",[Crypto]), - catch snmp_test_mgr:stop(), % If we had a running mgr from a failed case - StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", - ?DBG("run -> config:~n" - "\tM: ~p~n" - "\tDir: ~p~n" - "\tUser: ~p~n" - "\tSecLevel: ~p~n" - "\tEngineID: ~p~n" - "\tCtxEngineID: ~p~n" - "\tCommunity: ~p~n" - "\tStdM: ~p", - [M,Dir,User,SecLevel,EngineID,CtxEngineID,Community,StdM]), - case snmp_test_mgr:start([%% {agent, snmp_test_lib:hostname()}, - {packet_server_debug,true}, - {debug,true}, - {agent, get(master_host)}, - {agent_udp, 4000}, - {trap_udp, 5000}, - {recbuf,65535}, - quiet, - get(vsn), - {community, Community}, - {user, User}, - {sec_level, SecLevel}, - {engine_id, EngineID}, - {context_engine_id, CtxEngineID}, - {dir, Dir}, - {mibs, mibs(StdM, M)}]) of - {ok, _Pid} -> - Res = apply(?MODULE, F, A), - catch snmp_test_mgr:stop(), - Res; - Err -> - io:format("Error starting manager: ~p\n", [Err]), - catch snmp_test_mgr:stop(), - ?line exit({mgr_start, Err}) - end. - - -mibs(StdMibDir,MibDir) -> - [join(StdMibDir, ?v1_2("STANDARD-MIB.bin", "SNMPv2-MIB.bin")), - join(MibDir, "OLD-SNMPEA-MIB.bin"), - join(StdMibDir, "SNMP-FRAMEWORK-MIB"), - join(StdMibDir, "SNMP-MPD-MIB"), - join(StdMibDir, "SNMP-VIEW-BASED-ACM-MIB"), - join(StdMibDir, "SNMP-USER-BASED-SM-MIB"), - join(StdMibDir, "SNMP-TARGET-MIB"), - join(StdMibDir, "SNMP-NOTIFICATION-MIB"), - join(MibDir, "Klas1.bin"), - join(MibDir, "Klas2.bin"), - join(MibDir, "Klas3.bin"), - join(MibDir, "Klas4.bin"), - join(MibDir, "SA-MIB.bin"), - join(MibDir, "TestTrap.bin"), - join(MibDir, "Test1.bin"), - join(MibDir, "Test2.bin"), - join(MibDir, "TestTrapv2.bin")]. - -join(D,F) -> - filename:join(D,F). - -%% string used in index -is(S) -> [length(S) | S]. - -try_test(Func) -> - call(get(mgr_node), ?MODULE, run, [Func, [], []]). - -try_test(Func, A) -> - call(get(mgr_node), ?MODULE, run, [Func, A, []]). - -try_test(Func, A, Opts) -> - call(get(mgr_node), ?MODULE, run, [Func, A, Opts]). - -call(N,M,F,A) -> - ?DBG("call -> entry with~n" - " N: ~p~n" - " M: ~p~n" - " F: ~p~n" - " A: ~p~n" - " when~n" - " get(): ~p", - [N,M,F,A,get()]), - spawn(N, ?MODULE, wait, [self(),get(),M,F,A]), - receive - {done, {'EXIT', Rn}, Loc} -> - ?DBG("call -> returned ~p",[{done, {'EXIT', Rn}, Loc}]), - put(test_server_loc, Loc), - exit(Rn); - {done, Ret, Zed} -> - ?DBG("call -> returned ~p~n",[{done, Ret, Zed}]), - Ret - end. - -wait(From, Env, M, F, A) -> - ?DBG("wait -> entry with ~n" - "\tFrom: ~p~n" - "\tEnv: ~p",[From,Env]), - lists:foreach(fun({K,V}) -> put(K,V) end, Env), - Rn = (catch apply(M, F, A)), - ?DBG("wait -> Rn: ~n~p", [Rn]), - From ! {done, Rn, get(test_server_loc)}, - exit(Rn). - -expect(A,B) -> ok = snmp_test_mgr:expect(A,B). -expect(A,B,C) -> ok = snmp_test_mgr:expect(A,B,C). -expect(A,B,C,D) -> ok = snmp_test_mgr:expect(A,B,C,D). -expect(A,B,C,D,E,F) -> ok = snmp_test_mgr:expect(A,B,C,D,E,F). - -get_req(Id, Vars) -> - ?DBG("get_req -> entry with~n" - "\tId: ~p~n" - "\tVars: ~p",[Id,Vars]), - g(Vars), - ?DBG("get_req -> await response",[]), - {ok, Val} = snmp_test_mgr:get_response(Id, Vars), - ?DBG("get_req -> response: ~p",[Val]), - Val. - -get_next_req(Vars) -> - ?DBG("get_next_req -> entry with Vars '~p', send request",[Vars]), - gn(Vars), - ?DBG("get_next_req -> await response",[]), - Response = snmp_test_mgr:receive_response(), - ?DBG("get_next_req -> response: ~p",[Response]), - Response. - - - -start_node(Name) -> - ?LOG("start_node -> entry with Name: ~p",[Name]), - M = list_to_atom(?HOSTNAME(node())), - ?DBG("start_node -> M: ~p",[M]), - Pa = filename:dirname(code:which(?MODULE)), - ?DBG("start_node -> Pa: ~p",[Pa]), - - Args = case init:get_argument('CC_TEST') of - {ok, [[]]} -> - " -pa /clearcase/otp/libraries/snmp/ebin "; - {ok, [[Path]]} -> - " -pa " ++ Path; - error -> - "" - end, - %% Do not use start_link!!! (the proc that calls this one is tmp) - ?DBG("start_node -> Args: ~p~n",[Args]), - A = Args ++ " -pa " ++ Pa, - case (catch ?START_NODE(Name, A)) of - {ok, Node} -> - %% Tell the test_server to not clean up things it never started. - ?DBG("start_node -> Node: ~p",[Node]), - {ok, Node}; - Else -> - ?ERR("start_node -> failed with(other): Else: ~p",[Else]), - ?line ?FAIL(Else) - end. - - -stop_node(Node) -> - ?LOG("stop_node -> Node: ~p",[Node]), - rpc:cast(Node, erlang, halt, []). - -p(X) -> - io:format(user, X++"\n", []). - -sleep(X) -> - receive - after - X -> ok - end. - -%%%----------------------------------------------------------------- -%%% Configuration -%%%----------------------------------------------------------------- -config(Vsns, MgrDir, AgentDir, MIp, AIp) -> - ?line snmp_config:write_agent_snmp_files(AgentDir, Vsns, MIp, - ?TRAP_UDP, AIp, 4000, - "test"), - ?line case update_usm(Vsns, AgentDir) of - true -> - ?line copy_file(filename:join(AgentDir, "usm.conf"), - filename:join(MgrDir, "usm.conf")), - ?line update_usm_mgr(Vsns, MgrDir); - false -> - ?line ok - end, - ?line update_community(Vsns, AgentDir), - ?line update_vacm(Vsns, AgentDir), - ?line write_target_addr_conf(AgentDir, MIp, ?TRAP_UDP, Vsns), - ?line write_target_params_conf(AgentDir, Vsns), - ?line write_notify_conf(AgentDir), - ok. - -delete_files(Config) -> - Dir = ?config(agent_dir, Config), - {ok, List} = file:list_dir(Dir), - lists:foreach(fun(FName) -> file:delete(filename:join(Dir, FName)) end, - List). - -update_usm(Vsns, Dir) -> - case lists:member(v3, Vsns) of - true -> - {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),[read,write]), - file:position(Fid, eof), - ok = io:format(Fid, "{\"agentEngine\", \"all-rights\", " - "\"all-rights\", zeroDotZero, " - "usmNoAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"\", \"\"}.\n", []), - ok = io:format(Fid, "{\"agentEngine\", \"no-rights\", " - "\"no-rights\", zeroDotZero, " - "usmNoAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"\", \"\"}.\n", []), - ok = io:format(Fid, "{\"agentEngine\", \"authMD5\", " - "\"authMD5\", zeroDotZero, " - "usmHMACMD5AuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"passwd_md5xxxxxx\", \"\"}.\n", []), - ok = io:format(Fid, "{\"agentEngine\", \"authSHA\", " - "\"authSHA\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"\"}.\n", []), - ok = io:format(Fid, "{\"agentEngine\", \"privDES\", " - "\"privDES\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", - []), - ok = io:format(Fid, "{\"mgrEngine\", \"all-rights\", " - "\"all-rights\", zeroDotZero, " - "usmNoAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"\", \"\"}.\n", []), - ok = io:format(Fid, "{\"mgrEngine\", \"no-rights\", " - "\"no-rights\", zeroDotZero, " - "usmNoAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"\", \"\"}.\n", []), - ok = io:format(Fid, "{\"mgrEngine\", \"authMD5\", " - "\"authMD5\", zeroDotZero, " - "usmHMACMD5AuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"passwd_md5xxxxxx\", \"\"}.\n", []), - ok = io:format(Fid, "{\"mgrEngine\", \"authSHA\", " - "\"authSHA\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"\"}.\n", []), - ok = io:format(Fid, "{\"mgrEngine\", \"privDES\", " - "\"privDES\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", - []), - file:close(Fid), - true; - false -> - false - end. - -update_usm_mgr(Vsns, Dir) -> - case lists:member(v3, Vsns) of - true -> - {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),[read,write]), - file:position(Fid, eof), - ok = io:format(Fid, "{\"agentEngine\", \"newUser\", " - "\"newUser\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", - []), - ok = io:format(Fid, "{\"mgrEngine\", \"newUser\", " - "\"newUser\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", - []), - file:close(Fid), - true; - false -> - false - end. - -rewrite_usm_mgr(Dir, ShaKey, DesKey) -> - ?line ok = file:rename(filename:join(Dir,"usm.conf"), - filename:join(Dir,"usm.old")), - ?line {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),write), - ok = io:format(Fid, "{\"agentEngine\", \"newUser\", " - "\"newUser\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"~s\", \"~s\"}.\n", - [ShaKey, DesKey]), - ok = io:format(Fid, "{\"mgrEngine\", \"newUser\", " - "\"newUser\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"~s\", \"~s\"}.\n", - [ShaKey, DesKey]), - file:close(Fid). - -reset_usm_mgr(Dir) -> - ?line ok = file:rename(filename:join(Dir,"usm.old"), - filename:join(Dir,"usm.conf")). - - -update_community([v3], _Dir) -> ok; -update_community(_, Dir) -> - {ok, Fid} = file:open(filename:join(Dir,"community.conf"),[read,write]), - file:position(Fid, eof), - ok=io:format(Fid,"{\"no-rights\",\"no-rights\",\"no-rights\",\"\",\"\"}.\n", - []), - file:close(Fid). - - --define(tDescr_instance, [1,3,6,1,2,1,16,1,0]). -update_vacm(_Vsn, Dir) -> - {ok, Fid} = file:open(filename:join(Dir,"vacm.conf"),[read,write]), - file:position(Fid, eof), - ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"authMD5\",\"initial\"}.\n",[]), - ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"authSHA\",\"initial\"}.\n",[]), - ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"privDES\",\"initial\"}.\n",[]), - ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"newUser\",\"initial\"}.\n",[]), - ok = io:format(Fid, "{vacmViewTreeFamily, \"internet\", " - "~w, excluded, null}.\n", [?tDescr_instance]), - file:close(Fid). - - -vacm_ver(v1) -> v1; -vacm_ver(v2) -> v2c; -vacm_ver(v3) -> usm. - - -write_community_conf(Dir, Confs) -> - {ok, Fid} = file:open(filename:join(Dir,"community.conf"),write), - ok = write_community_conf1(Fid, Confs), - file:close(Fid). - -write_community_conf1(_, []) -> - ok; -write_community_conf1(Fid, [{ComIdx, ComName, SecName, CtxName, TransTag}|Confs]) -> - ok = io:format(Fid, "{\"~s\", \"~s\", \"~s\", \"~s\", \"~s\"}.~n", - [ComIdx, ComName, SecName, CtxName, TransTag]), - write_community_conf1(Fid, Confs). - - -write_target_addr_conf(Dir, Confs) -> - {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), - ok = write_target_addr_conf1(Fid, Confs), - file:close(Fid). - - -write_target_addr_conf1(_, []) -> - ok; -write_target_addr_conf1(Fid, - [{Name, Ip, Port, Timeout, Retry, TagList, ParamName, - EngineId, TMask, MaxMsgSz}|Confs]) -> - ok = io:format(Fid, "{\"~s\", ~w, ~w, ~w, ~w, \"~s\", \"~s\", \"~s\", ~w, ~w}.~n", - [Name, Ip, Port, Timeout, Retry, TagList, ParamName, - EngineId, TMask, MaxMsgSz]), - write_target_addr_conf1(Fid, Confs). - -write_target_addr_conf(Dir, ManagerIp, UDP, Vsns) -> - {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), - lists:foreach(fun(Vsn) -> - ok = io:format(Fid, - "{\"~s\", ~w, ~w, 1500, 3, " - "\"std_trap\", \"~s\"}.~n", - [mk_ip(ManagerIp, Vsn), - ManagerIp, UDP, mk_param(Vsn)]), - case Vsn of - v1 -> ok; - v2 -> - ok = io:format(Fid, - "{\"~s.2\",~w,~w,1500,3, " - "\"std_inform\", \"~s\"}.~n", - [mk_ip(ManagerIp, Vsn), - ManagerIp, UDP, - mk_param(Vsn)]); - v3 -> - ok = io:format(Fid, - "{\"~s.3\",~w,~w,1500,3, " - "\"std_inform\", \"~s\", " - "\"mgrEngine\", [], 1024}.~n", - [mk_ip(ManagerIp, Vsn), - ManagerIp, UDP, - mk_param(Vsn)]) - end - end, - Vsns), - file:close(Fid). - -mk_param(v1) -> "target_v1"; -mk_param(v2) -> "target_v2"; -mk_param(v3) -> "target_v3". - -mk_ip([A,B,C,D], Vsn) -> - io_lib:format("~w.~w.~w.~w ~w", [A,B,C,D,Vsn]). - - -rewrite_target_addr_conf(Dir,NewPort) -> - TAFile = filename:join(Dir, "target_addr.conf"), - ?DBG("rewrite_target_addr_conf -> read target file info of address config file",[]), - case file:read_file_info(TAFile) of - {ok, _} -> ok; - {error, R} -> ?ERR("failure reading file info of " - "target address config file: ~p",[R]), - ok - end, - - ?line [TrapAddr|Addrs] = - snmp_conf:read(TAFile,fun(R) -> rewrite_target_addr_conf1(R) end), - - ?DBG("rewrite_target_addr_conf -> TrapAddr: ~p",[TrapAddr]), - - NewAddrs = [rewrite_target_addr_conf2(NewPort,TrapAddr)|Addrs], - - ?DBG("rewrite_target_addr_conf -> NewAddrs: ~p",[NewAddrs]), - - ?line ok = file:rename(filename:join(Dir,"target_addr.conf"), - filename:join(Dir,"target_addr.old")), - ?line {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), - - ?line ok = rewrite_target_addr_conf3(Fid,NewAddrs), - - file:close(Fid). - -rewrite_target_addr_conf1(O) -> - {ok,O}. - -rewrite_target_addr_conf2(NewPort,{Name,Ip,_Port,Timeout,Retry, - "std_trap",EngineId}) -> - ?LOG("rewrite_target_addr_conf2 -> entry with std_trap",[]), - {Name,Ip,NewPort,Timeout,Retry,"std_trap",EngineId}; -rewrite_target_addr_conf2(_NewPort,O) -> - ?LOG("rewrite_target_addr_conf2 -> entry with " - "~n O: ~p",[O]), - O. - - -rewrite_target_addr_conf3(_,[]) -> ok; -rewrite_target_addr_conf3(Fid,[{Name,Ip,Port,Timeout,Retry, - ParamName,EngineId}|T]) -> - ?LOG("rewrite_target_addr_conf3 -> write(1) ~s",[ParamName]), - io:format(Fid, - "{\"~s\", " % Name - "~p, " % Ip - "~p, " % Port - "~p, " % Timeout - "~p, " % Retry - "\"~s\", " % ParamsName - "\"~s\"}.", % EngineId - [Name,Ip,Port,Timeout,Retry,ParamName,EngineId]), - rewrite_target_addr_conf3(Fid,T); -rewrite_target_addr_conf3(Fid,[{Name,Ip,Port,Timeout,Retry,TagList, - ParamName,EngineId,TMask,MMS}|T]) -> - ?LOG("rewrite_target_addr_conf3 -> write(2) ~s",[ParamName]), - io:format(Fid, - "{\"~s\", " % Name - "~p, " % Ip - "~p, " % Port - "~p, " % Timeout - "~p, " % Retry - "\"~s\", " % TagList - "\"~s\", " % ParamsName - "\"~s\"," % EngineId - "~p, " % TMask - "~p}.", % MMS - [Name,Ip,Port,Timeout,Retry,TagList,ParamName, - EngineId,TMask,MMS]), - rewrite_target_addr_conf3(Fid,T). - -reset_target_addr_conf(Dir) -> - ?line ok = file:rename(filename:join(Dir,"target_addr.old"), - filename:join(Dir,"target_addr.conf")). - -write_target_params_conf(Dir, Vsns) -> - {ok, Fid} = file:open(filename:join(Dir,"target_params.conf"),write), - lists:foreach(fun(Vsn) -> - MP = if Vsn == v1 -> v1; - Vsn == v2 -> v2c; - Vsn == v3 -> v3 - end, - SM = if Vsn == v1 -> v1; - Vsn == v2 -> v2c; - Vsn == v3 -> usm - end, - ok = io:format(Fid, "{\"target_~w\", ~w, ~w, " - "\"all-rights\", noAuthNoPriv}.~n", - [Vsn, MP, SM]) - end, - Vsns), - file:close(Fid). - -rewrite_target_params_conf(Dir, SecName, SecLevel) -> - ?line ok = file:rename(filename:join(Dir,"target_params.conf"), - filename:join(Dir,"target_params.old")), - ?line {ok, Fid} = file:open(filename:join(Dir,"target_params.conf"),write), - ?line ok = io:format(Fid, "{\"target_v3\", v3, usm, \"~s\", ~w}.~n", - [SecName, SecLevel]), - file:close(Fid). - -reset_target_params_conf(Dir) -> - ?line ok = file:rename(filename:join(Dir,"target_params.old"), - filename:join(Dir,"target_params.conf")). - -write_notify_conf(Dir) -> - {ok, Fid} = file:open(filename:join(Dir,"notify.conf"),write), - ok = io:format(Fid, "{\"standard trap\", \"std_trap\", trap}.~n", []), - ok = io:format(Fid, "{\"standard inform\", \"std_inform\",inform}.~n", []), - file:close(Fid). - -ver_to_trap_str([v1]) -> "v1"; -ver_to_trap_str([v2]) -> "v2"; -% default is to use the latest snmp version -ver_to_trap_str([v1,v2]) -> "v2". - - - -write_view_conf(Dir) -> - {ok, Fid} = file:open(a(Dir,"view.conf"),write), - ok = io:format(Fid, "{2, [1,3,6], included, null}.~n", []), - ok = io:format(Fid, "{2, ~w, excluded, null}.~n", [?tDescr_instance]), - file:close(Fid). - -a(A,B) -> lists:append(A,B). - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -copy_file(From, To) -> - {ok, Bin} = file:read_file(From), - ok = file:write_file(To, Bin). - - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -display_memory_usage() -> - Info = snmpa:info(snmp_master_agent), - TreeSize = lists_key1search(tree_size_bytes, Info), - ProcMem = lists_key1search(process_memory, Info), - MibDbSize = lists_key1search([db_memory,mib], Info), - NodeDbSize = lists_key1search([db_memory,node], Info), - TreeDbSize = lists_key1search([db_memory,tree], Info), - ?INF("Memory usage: " - "~n Tree size: ~p" - "~n Process memory size: ~p" - "~n Mib db size: ~p" - "~n Node db size: ~p" - "~n Tree db size: ~p", - [TreeSize, ProcMem, MibDbSize, NodeDbSize, TreeDbSize]). - -lists_key1search([], Res) -> - Res; -lists_key1search([Key|Keys], List) when atom(Key), list(List) -> - case lists:keysearch(Key, 1, List) of - {value, {Key, Val}} -> - lists_key1search(Keys, Val); - false -> - undefined - end; -lists_key1search(Key, List) when atom(Key) -> - case lists:keysearch(Key, 1, List) of - {value, {Key, Val}} -> - Val; - false -> - undefined - end. - - -regs() -> - lists:sort(registered()). diff --git a/lib/snmp/test/snmp_agent_ms_test.erl b/lib/snmp/test/snmp_agent_ms_test.erl deleted file mode 100644 index 1f34f1c8d1..0000000000 --- a/lib/snmp/test/snmp_agent_ms_test.erl +++ /dev/null @@ -1,5649 +0,0 @@ -%% -%% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2005-2010. All Rights Reserved. -%% -%% The contents of this file are subject to the Erlang Public License, -%% Version 1.1, (the "License"); you may not use this file except in -%% compliance with the License. You should have received a copy of the -%% Erlang Public License along with this software. If not, it can be -%% retrieved online at http://www.erlang.org/. -%% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -%% the License for the specific language governing rights and limitations -%% under the License. -%% -%% %CopyrightEnd% -%% - --module(snmp_agent_ms_test). - -%% TODO -%% * Test fault-tolerance (kill master etc) -%% - --compile(export_all). - --define(application, snmp). - --include_lib("kernel/include/file.hrl"). --include_lib("test_server/include/test_server.hrl"). --include("snmp_test_lib.hrl"). --define(SNMP_USE_V3, true). --include_lib("snmp/include/snmp_types.hrl"). -%% -include_lib("snmp/include/SNMP-COMMUNITY-MIB.hrl"). -%% -include_lib("snmp/include/SNMP-VIEW-BASED-ACM-MIB.hrl"). -%% -include_lib("snmp/include/SNMP-USER-BASED-SM-MIB.hrl"). - - --define(klas1, [1,3,6,1,2,1,7]). --define(klas2, [1,3,6,1,2,1,9]). --define(klas3, [1,3,6,1,2,1,8,1]). --define(klas4, [1,3,6,1,2,1,8,4]). --define(sa, [1,3,6,1,4,1,193,2]). --define(system, [1,3,6,1,2,1,1]). --define(snmp, [1,3,6,1,2,1,11]). --define(snmpTraps, [1,3,6,1,6,3,1,1,5]). --define(ericsson, [1,3,6,1,4,1,193]). --define(testTrap, [1,3,6,1,2,1,15,0]). --define(xDescr, [1,3,6,1,2,1,17,1]). --define(xDescr2, [1,3,6,1,2,1,17,2]). - --define(active, 1). --define(notInService, 2). --define(notReady, 3). --define(createAndGo, 4). --define(createAndWait, 5). --define(destroy, 6). - --define(TRAP_UDP, 5000). - --define(tooBigStr, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"). - --define(str(X), snmp_pdus:bits_to_str(X)). - --define(break(), begin io:format(user, "break at line ~w: pid: ~p\n", - [?LINE, self()]), - receive cont -> ok end - end). - - --import(snmp_test_mgr, [gn/1, g/1, s/1, gb/3]). --define(v1_2(V1,V2), - case get(vsn) of - v1 -> V1; - _ -> V2 - end). - --define(v1_2_3(V1,V2,V3), - case get(vsn) of - v1 -> V1; - v2 -> V2; - _ -> V3 - end). - -all() -> -[cases()]. - -groups() -> - [{mib_storage, [], - [{group, mib_storage_ets}, {group, mib_storage_dets}, - {group, mib_storage_mnesia}, - {group, mib_storage_size_check_ets}, - {group, mib_storage_size_check_dets}, - {group, mib_storage_size_check_mnesia}, - {group, mib_storage_varm_dets}, - {group, mib_storage_varm_mnesia}]}, - {mib_storage_ets, [], mib_storage_ets_cases()}, - {mib_storage_dets, [], mib_storage_dets_cases()}, - {mib_storage_mnesia, [], mib_storage_mnesia_cases()}, - {mib_storage_size_check_ets, [], - mse_size_check_cases()}, - {mib_storage_size_check_dets, [], - msd_size_check_cases()}, - {mib_storage_size_check_mnesia, [], - msm_size_check_cases()}, - {mib_storage_varm_dets, [], - varm_mib_storage_dets_cases()}, - {mib_storage_varm_mnesia, [], - varm_mib_storage_mnesia_cases()}, - {test_v1, [], v1_cases()}, {test_v2, [], v2_cases()}, - {test_v1_v2, [], v1_v2_cases()}, - {test_v3, [], v3_cases()}, - {test_multi_threaded, [], mt_cases()}, - {multiple_reqs, [], mul_cases()}, - {multiple_reqs_2, [], mul_cases_2()}, - {v2_inform, [], [v2_inform_i]}, - {v3_security, [], - [v3_crypto_basic, v3_md5_auth, v3_sha_auth, - v3_des_priv]}, - {standard_mibs, [], - [snmp_standard_mib, snmp_community_mib, - snmp_framework_mib, snmp_target_mib, - snmp_notification_mib, snmp_view_based_acm_mib]}, - {standard_mibs_2, [], - [snmpv2_mib_2, snmp_community_mib_2, - snmp_framework_mib_2, snmp_target_mib_2, - snmp_notification_mib_2, snmp_view_based_acm_mib_2]}, - {standard_mibs_3, [], - [snmpv2_mib_3, snmp_framework_mib_3, snmp_mpd_mib_3, - snmp_target_mib_3, snmp_notification_mib_3, - snmp_view_based_acm_mib_3, snmp_user_based_sm_mib_3]}, - {reported_bugs, [], - [otp_1128, otp_1129, otp_1131, otp_1162, otp_1222, - otp_1298, otp_1331, otp_1338, otp_1342, otp_2776, - otp_2979, otp_3187, otp_3725]}, - {reported_bugs_2, [], - [otp_1128_2, otp_1129_2, otp_1131_2, otp_1162_2, - otp_1222_2, otp_1298_2, otp_1331_2, otp_1338_2, - otp_1342_2, otp_2776_2, otp_2979_2, otp_3187_2]}, - {reported_bugs_3, [], - [otp_1128_3, otp_1129_3, otp_1131_3, otp_1162_3, - otp_1222_3, otp_1298_3, otp_1331_3, otp_1338_3, - otp_1342_3, otp_2776_3, otp_2979_3, otp_3187_3, - otp_3542]}, - {tickets, [], [{group, otp_4394}]}, - {otp_4394, [], [otp_4394_test]}]. - -init_per_group(otp_4394, Config) -> - init_otp_4394(Config); -init_per_group(v2_inform, Config) -> - init_v2_inform(Config); -init_per_group(multiple_reqs_2, Config) -> - init_mul(Config); -init_per_group(multiple_reqs, Config) -> - init_mul(Config); -init_per_group(test_multi_threaded, Config) -> - init_mt(Config); -init_per_group(test_v3, Config) -> - init_v3(Config); -init_per_group(test_v1_v2, Config) -> - init_v1_v2(Config); -init_per_group(test_v2, Config) -> - init_v2(Config); -init_per_group(test_v1, Config) -> - init_v1(Config); -init_per_group(mib_storage_varm_mnesia, Config) -> - init_varm_mib_storage_mnesia(Config); -init_per_group(mib_storage_varm_dets, Config) -> - init_varm_mib_storage_dets(Config); -init_per_group(mib_storage_size_check_mnesia, Config) -> - init_size_check_msm(Config); -init_per_group(mib_storage_size_check_dets, Config) -> - init_size_check_msd(Config); -init_per_group(mib_storage_size_check_ets, Config) -> - init_size_check_mse(Config); -init_per_group(mib_storage_mnesia, Config) -> - init_mib_storage_mnesia(Config); -init_per_group(mib_storage_dets, Config) -> - init_mib_storage_dets(Config); -init_per_group(mib_storage_ets, Config) -> - init_mib_storage_ets(Config); -init_per_group(_GroupName, Config) -> - Config. - -end_per_group(otp_4394, Config) -> - finish_otp_4394(Config); -end_per_group(v2_inform, Config) -> - finish_v2_inform(Config); -end_per_group(multiple_reqs_2, Config) -> - finish_mul(Config); -end_per_group(multiple_reqs, Config) -> - finish_mul(Config); -end_per_group(test_multi_threaded, Config) -> - finish_mt(Config); -end_per_group(test_v3, Config) -> - finish_v3(Config); -end_per_group(test_v1_v2, Config) -> - finish_v1_v2(Config); -end_per_group(test_v2, Config) -> - finish_v2(Config); -end_per_group(test_v1, Config) -> - finish_v1(Config); -end_per_group(mib_storage_varm_mnesia, Config) -> - finish_varm_mib_storage_mnesia(Config); -end_per_group(mib_storage_varm_dets, Config) -> - finish_varm_mib_storage_dets(Config); -end_per_group(mib_storage_size_check_mnesia, Config) -> - finish_size_check_msm(Config); -end_per_group(mib_storage_size_check_dets, Config) -> - finish_size_check_msd(Config); -end_per_group(mib_storage_size_check_ets, Config) -> - finish_size_check_mse(Config); -end_per_group(mib_storage_mnesia, Config) -> - finish_mib_storage_mnesia(Config); -end_per_group(mib_storage_dets, Config) -> - finish_mib_storage_dets(Config); -end_per_group(mib_storage_ets, Config) -> - finish_mib_storage_ets(Config); -end_per_group(_GroupName, Config) -> - Config. - - -init_per_testcase(_Case, Config) when list(Config) -> - Dog = ?t:timetrap(?t:minutes(6)), - [{watchdog, Dog}|Config]. - -end_per_testcase(_Case, Config) when list(Config) -> - Dog = ?config(watchdog, Config), - ?t:timetrap_cancel(Dog), - Config. - -cases() -> -case ?OSTYPE() of - vxworks -> - [app_info, {group, test_v1}, {group, test_v2}, - {group, test_v1_v2}, {group, test_multi_threaded}, - {group, mib_storage}, {group, tickets}]; - _Else -> - [app_info, {group, test_v1}, {group, test_v2}, - {group, test_v1_v2}, {group, test_v3}, - {group, test_multi_threaded}, {group, mib_storage}, - {group, tickets}] -end. - - -%%%----------------------------------------------------------------- -%%% The test case structure is as follows: -%%% -%%% init_all - starts mnesia, -%%% -%%% init_v1 - starts agent -%%% simple -%%% big - e.g. starts/stops subagent, load/unloads mibs -%%% init_mul -%%% mul_get -%%% mul_set -%%% -%%% finish_mul -%%% -%%% finish_v1 -%%% -%%% init_v2 - starts agent -%%% finish_v2 -%%% -%%% init_bilingual - starts agent -%%% finish_bilingual -%%% -%%% finish_all -%%% -%%% There is still one problem with these testsuites. If one test -%%% fails, it may not be possible to run some other cases, as it -%%% may have e.g. created some row or loaded some table, that it -%%% didn't undo (since it failed). -%%%----------------------------------------------------------------- - -init_all(Config0) when list(Config0) -> - ?LOG("init_all -> entry with" - "~n Config0: ~p",[Config0]), - - %% -- - %% Fix config: - %% - - DataDir0 = ?config(data_dir, Config0), - DataDir1 = filename:split(filename:absname(DataDir0)), - [_|DataDir2] = lists:reverse(DataDir1), - DataDir3 = filename:join(lists:reverse(DataDir2) ++ [?snmp_test_data]), - Config1 = lists:keydelete(data_dir, 1, Config0), - Config = [{data_dir, DataDir3 ++ "/"}|Config1], - - %% -- - %% Start nodes - %% - - ?line {ok, SaNode} = start_node(snmp_sa), - ?line {ok, MgrNode} = start_node(snmp_mgr), - - - %% -- - %% Create necessary files - %% - - Dir = ?config(priv_dir, Config), - ?DBG("init_all -> Dir ~p", [Dir]), - - DataDir = ?config(data_dir, Config), - ?DBG("init_all -> DataDir ~p", [DataDir]), - - file:make_dir(MgrDir = filename:join(Dir, "mgr_dir/")), - ?DBG("init_all -> MgrDir ~p", [MgrDir]), - - file:make_dir(AgentDir = filename:join(Dir, "agent_dir/")), - ?DBG("init_all -> AgentDir ~p", [AgentDir]), - - file:make_dir(SaDir = filename:join(Dir, "sa_dir/")), - ?DBG("init_all -> SaDir ~p", [SaDir]), - - - %% -- - %% Start and initiate mnesia - %% - - ?DBG("init_all -> load application mnesia", []), - ?line ok = application:load(mnesia), - - ?DBG("init_all -> load application mnesia on node ~p", [SaNode]), - ?line ok = rpc:call(SaNode, application, load, [mnesia]), - - ?DBG("init_all -> application mnesia: set_env dir",[]), - ?line application_controller:set_env(mnesia, dir, - filename:join(Dir, "Mnesia1")), - - ?DBG("init_all -> application mnesia: set_env dir on node ~p",[SaNode]), - ?line rpc:call(SaNode, application_controller, set_env, - [mnesia, dir, filename:join(Dir, "Mnesia2")]), - - ?DBG("init_all -> create mnesia schema",[]), - ?line ok = mnesia:create_schema([SaNode, node()]), - - ?DBG("init_all -> start application mnesia",[]), - ?line ok = application:start(mnesia), - - ?DBG("init_all -> start application mnesia on ~p",[SaNode]), - ?line ok = rpc:call(SaNode, application, start, [mnesia]), - Ip = ?LOCALHOST(), - [{snmp_sa, SaNode}, - {snmp_mgr, MgrNode}, - {agent_dir, AgentDir ++ "/"}, - {mgr_dir, MgrDir ++ "/"}, - {sa_dir, SaDir ++ "/"}, - {mib_dir, DataDir}, - {ip, Ip} | - Config]. - -finish_all(Config) when list(Config) -> - SaNode = ?config(snmp_sa, Config), - MgrNode = ?config(snmp_mgr, Config), - stop_node(SaNode), - stop_node(MgrNode), - application:stop(mnesia). - -start_v1_agent(Config) when list(Config) -> - start_agent(Config, [v1]). - -start_v1_agent(Config,Opts) when list(Config), list(Opts) -> - start_agent(Config, [v1], Opts). - -start_v2_agent(Config) when list(Config) -> - start_agent(Config, [v2]). - -start_v3_agent(Config) when list(Config) -> - start_agent(Config, [v3]). - -start_bilingual_agent(Config) when list(Config) -> - start_agent(Config, [v1,v2]). - -start_multi_threaded_agent(Config) when list(Config) -> - start_agent(Config, [v2], [{snmp_multi_threaded, true}]). - -stop_agent(Config) when list(Config) -> - ?LOG("stop_agent -> entry with" - "~n Config: ~p",[Config]), - - {Sup, Par} = ?config(snmp_sup, Config), - ?DBG("stop_agent -> attempt to stop (sup) ~p" - "~n Sup: ~p" - "~n Par: ~p", - [Sup, - (catch process_info(Sup)), - (catch process_info(Par))]), - stop_sup(Sup, Par), - - {Sup2, Par2} = ?config(snmp_sub, Config), - ?DBG("stop_agent -> attempt to stop (sub) ~p" - "~n Sup2: ~p" - "~n Par2: ~p", - [Sup2, - (catch process_info(Sup2)), - (catch process_info(Par2))]), - stop_sup(Sup2, Par2), - - ?DBG("stop_agent -> done - now cleanup config", []), - C1 = lists:keydelete(snmp_sup, 1, Config), - lists:keydelete(snmp_sub, 1, C1). - - -stop_sup(Pid, _) when node(Pid) == node() -> - case (catch process_info(Pid)) of - PI when list(PI) -> - ?LOG("stop_sup -> attempt to stop ~p", [Pid]), - Ref = erlang:monitor(process, Pid), - exit(Pid, kill), - await_stopped(Pid, Ref); - {'EXIT', _Reason} -> - ?LOG("stop_sup -> ~p not running", [Pid]), - ok - end; -stop_sup(Pid, _) -> - ?LOG("stop_sup -> attempt to stop ~p", [Pid]), - Ref = erlang:monitor(process, Pid), - ?LOG("stop_sup -> Ref: ~p", [Ref]), - %% Pid ! {'EXIT', Parent, shutdown}, % usch - exit(Pid, kill), - await_stopped(Pid, Ref). - -await_stopped(Pid, Ref) -> - receive - {'DOWN', Ref, process, Pid, _Reason} -> - ?DBG("received down message for ~p", [Pid]), - ok - after 10000 -> - ?INF("await_stopped -> timeout for ~p",[Pid]), - erlang:demonitor(Ref), - ?FAIL({failed_stop,Pid}) - end. - - -start_agent(Config, Vsn) -> - start_agent(Config, Vsn, []). -start_agent(Config, Vsn, Opts) -> - ?LOG("start_agent -> entry (~p) with" - "~n Config: ~p" - "~n Vsn: ~p" - "~n Opts: ~p",[node(), Config, Vsn, Opts]), - - ?line AgentDir = ?config(agent_dir, Config), - ?line SaNode = ?config(snmp_sa, Config), - - snmp_app_env_init(vsn_init(Vsn) ++ - [{audit_trail_log, read_write_log}, - {audit_trail_log_dir, AgentDir}, - {audit_trail_log_size, {10240, 10}}, - {force_config_reload, false}, - {snmp_agent_type, master}, - {snmp_config_dir, AgentDir}, - {snmp_db_dir, AgentDir}, - {snmp_local_db_auto_repair, true}, - {snmp_master_agent_verbosity, trace}, - {snmp_supervisor_verbosity, trace}, - {snmp_mibserver_verbosity, trace}, - {snmp_symbolic_store_verbosity, trace}, - {snmp_note_store_verbosity, trace}, - {snmp_net_if_verbosity, trace}], - Opts), - - - process_flag(trap_exit,true), - - {ok, AppSup} = snmp_app_sup:start_link(), - unlink(AppSup), - ?DBG("start_agent -> snmp app supervisor: ~p",[AppSup]), - - ?DBG("start_agent -> start master agent (old style)",[]), - Sup = case (catch snmpa_app:start(normal)) of - {ok, S} -> - ?DBG("start_agent -> started, Sup: ~p",[S]), - S; - - Else -> - ?DBG("start_agent -> unknown result: ~n~p",[Else]), - %% Get info about the apps we depend on - MnesiaInfo = mnesia_running(), - ?FAIL({start_failed,Else,MnesiaInfo}) - end, - - ?DBG("start_agent -> unlink from supervisor",[]), - ?line unlink(Sup), - ?line SaDir = ?config(sa_dir, Config), - ?DBG("start_agent -> (rpc) start sub on ~p",[SaNode]), - ?line {ok, Sub} = rpc:call(SaNode, ?MODULE, start_sub, [SaDir]), - ?DBG("start_agent -> done",[]), - ?line [{snmp_sup, {Sup, self()}}, {snmp_sub, Sub} | Config]. - - -vsn_init(Vsn) -> - vsn_init([v1,v2,v3], Vsn, []). - -vsn_init([], _Vsn, Acc) -> - Acc; -vsn_init([V|Vsns], Vsn, Acc) -> - case lists:member(V, Vsn) of - true -> - vsn_init(Vsns, Vsn, [{V, true}|Acc]); - false -> - vsn_init(Vsns, Vsn, [{V, false}|Acc]) - end. - -snmp_app_env_init(Env0, Opts) -> - ?DBG("snmp_app_env_init -> unload snmp",[]), - ?line application:unload(snmp), - ?DBG("snmp_app_env_init -> load snmp",[]), - ?line application:load(snmp), - ?DBG("snmp_app_env_init -> initiate (snmp) application env",[]), - F1 = fun({Key,Val} = New, Acc0) -> - ?DBG("snmp_app_env_init -> " - "updating setting ~p to ~p", [Key, Val]), - case lists:keyreplace(Key, 1, Acc0, New) of - Acc0 -> - [New|Acc0]; - Acc -> - Acc - end - end, - Env = lists:foldr(F1, Env0, Opts), - ?DBG("snmp_app_env_init -> Env: ~p",[Env]), - F2 = fun({Key,Val}) -> - ?DBG("snmp_app_env_init -> setting ~p to ~p",[Key, Val]), - application_controller:set_env(snmp, Key, Val) - end, - lists:foreach(F2, Env). - - - - -%% Test if application is running -mnesia_running() -> ?IS_MNESIA_RUNNING(). -crypto_running() -> ?IS_CRYPTO_RUNNING(). - - -start_sub(Dir) -> - ?DBG("start_sub -> entry",[]), - Opts = [{db_dir, Dir}, - {supervisor, [{verbosity, trace}]}], - %% BMK BMK -% {ok, P} = snmp_supervisor:start_sub(Dir), - {ok, P} = snmpa_supervisor:start_sub_sup(Opts), - unlink(P), - {ok, {P, self()}}. - -create_tables(SaNode) -> - ?line {atomic, ok} = mnesia:create_table([{name, friendsTable2}, - {ram_copies, [SaNode]}, - {snmp, [{key, integer}]}, - {attributes, [a1,a2,a3]}]), - ?line {atomic, ok} = mnesia:create_table([{name, kompissTable2}, - {ram_copies, [SaNode]}, - {snmp, [{key, integer}]}, - {attributes, [a1,a2,a3]}]), - ?line {atomic, ok} = mnesia:create_table([{name, snmp_variables}, - {attributes, [a1,a2]}]). - -delete_tables() -> - mnesia:delete_table(friendsTable2), - mnesia:delete_table(kompissTable2), - mnesia:delete_table(snmp_variables). - -%% Creation is done in runtime! -delete_mib_storage_mnesia_tables() -> - mnesia:delete_table(snmpa_mib_data), - mnesia:delete_table(snmpa_mib_tree), - mnesia:delete_table(snmpa_symbolic_store). - -%%----------------------------------------------------------------- -%% A test case is always one of: -%% - v1 specific case -%% - v2 specific case -%% - v1 and v2 case -%% All v1 specific cases are prefixed with v1_, and all v2 with -%% v2_. E.g. v1_trap/v2_trap. -%% -%% All other cases are shared. However, the testserver uses the name -%% of the case to generate a file for that case. The same case cannot -%% be used in different configurations in the same suite. Therefore -%% all these functions exists in two variants, the base function -%% , and a second version _2. There may be several -%% versions as well, _N. -%%----------------------------------------------------------------- - - - - - - - - - -mib_storage_ets_cases() -> -[mse_simple, mse_v1_processing, mse_big, mse_big2, - mse_loop_mib, mse_api, mse_sa_register, mse_v1_trap, - mse_sa_error, mse_next_across_sa, mse_undo, - mse_standard_mib, mse_community_mib, mse_framework_mib, - mse_target_mib, mse_notification_mib, - mse_view_based_acm_mib, mse_sparse_table, mse_me_of, - mse_mib_of]. - -mib_storage_dets_cases() -> -[msd_simple, msd_v1_processing, msd_big, msd_big2, - msd_loop_mib, msd_api, msd_sa_register, msd_v1_trap, - msd_sa_error, msd_next_across_sa, msd_undo, - msd_standard_mib, msd_community_mib, msd_framework_mib, - msd_target_mib, msd_notification_mib, - msd_view_based_acm_mib, msd_sparse_table, msd_me_of, - msd_mib_of]. - -mib_storage_mnesia_cases() -> -[msm_simple, msm_v1_processing, msm_big, msm_big2, - msm_loop_mib, msm_api, msm_sa_register, msm_v1_trap, - msm_sa_error, msm_next_across_sa, msm_undo, - msm_standard_mib, msm_community_mib, msm_framework_mib, - msm_target_mib, msm_notification_mib, - msm_view_based_acm_mib, msm_sparse_table, msm_me_of, - msm_mib_of]. - -mse_size_check_cases() -> -[mse_size_check]. - -msd_size_check_cases() -> -[msd_size_check]. - -msm_size_check_cases() -> -[msm_size_check]. - -varm_mib_storage_dets_cases() -> -[msd_varm_mib_start]. - -varm_mib_storage_mnesia_cases() -> -[msm_varm_mib_start]. - -init_mib_storage_ets(Config) when list(Config) -> - ?LOG("init_mib_storage_ets -> entry", []), - MibStorage = {snmp_mib_storage,ets}, - init_ms(Config, [MibStorage]). - -init_mib_storage_dets(Config) when list(Config) -> - ?LOG("init_mib_storage_ets -> entry", []), - ?line AgentDir = ?GCONF(agent_dir, Config), - MibStorage = {snmp_mib_storage,{dets,AgentDir}}, - init_ms(Config, [MibStorage]). - -init_mib_storage_mnesia(Config) when list(Config) -> - ?LOG("init_mib_storage_ets -> entry", []), - MibStorage = {snmp_mib_storage,{mnesia,[]}}, - init_ms(Config, [MibStorage]). - -init_ms(Config, Opts) when list(Config) -> - ?LOG("init_mib_storage_ets -> entry", []), - ?line SaNode = ?GCONF(snmp_sa, Config), - ?line create_tables(SaNode), - ?line AgentDir = ?GCONF(agent_dir, Config), - ?line MgrDir = ?GCONF(mgr_dir, Config), - ?line Ip = ?GCONF(ip, Config), - ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, - MibsVerbosity = {snmp_mibserver_verbosity, trace}, - SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, - Opts1 = [MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity|Opts], - [{vsn, v1} | start_v1_agent(Config,Opts1)]. - -init_size_check_mse(Config) when list(Config) -> - MibStorage = {snmp_mib_storage, ets}, - init_size_check_ms(Config, [MibStorage]). - -init_size_check_msd(Config) when list(Config) -> - AgentDir = ?GCONF(agent_dir, Config), - MibStorage = {snmp_mib_storage, {dets, AgentDir}}, - init_size_check_ms(Config, [MibStorage]). - -init_size_check_msm(Config) when list(Config) -> - MibStorage = {snmp_mib_storage, {mnesia,[]}}, - init_size_check_ms(Config, [MibStorage]). - -init_size_check_ms(Config, Opts) when list(Config) -> - SaNode = ?GCONF(snmp_sa, Config), - %% We are using v3 here, so crypto must be supported or else... - case ?CRYPTO_START() of - ok -> - case ?CRYPTO_SUPPORT() of - {no, Reason} -> - ?SKIP({unsupported_encryption, Reason}); - yes -> - ok - end; - {error, Reason} -> - ?SKIP({failed_starting_crypto, Reason}) - end, - create_tables(SaNode), - AgentDir = ?GCONF(agent_dir, Config), - MgrDir = ?GCONF(mgr_dir, Config), - Ip = ?GCONF(ip, Config), - ?line ok = - config([v3], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v3} | start_agent(Config, [v3], Opts)]. - -init_varm_mib_storage_dets(Config) when list(Config) -> - ?LOG("init_varm_mib_storage_dets -> entry", []), - ?line SaNode = ?GCONF(snmp_sa, Config), - ?line create_tables(SaNode), - ?line AgentDir = ?GCONF(agent_dir, Config), - ?line MgrDir = ?GCONF(mgr_dir, Config), - ?line Ip = ?GCONF(ip, Config), - ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - MibStorage = {snmp_mib_storage,{dets,AgentDir}}, - MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, - MibsVerbosity = {snmp_mibserver_verbosity, trace}, - SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, - Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity], - [{vsn, v1}, {agent_opts,Opts} | Config]. - -init_varm_mib_storage_mnesia(Config) when list(Config) -> - ?LOG("init_varm_mib_storage_mnesia -> entry", []), - ?line SaNode = ?GCONF(snmp_sa, Config), - ?line create_tables(SaNode), - ?line AgentDir = ?GCONF(agent_dir, Config), - ?line MgrDir = ?GCONF(mgr_dir, Config), - ?line Ip = ?GCONF(ip, Config), - ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - MibStorage = {snmp_mib_storage,{mnesia,[]}}, - MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, - MibsVerbosity = {snmp_mibserver_verbosity, trace}, - SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, - Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity], - [{vsn, v1}, {agent_opts,Opts} | Config]. - -finish_mib_storage_ets(Config) when list(Config) -> - ?LOG("finish_mib_storage_ets -> entry", []), - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - C2 = lists:keydelete(vsn, 1, C1), - lists:keydelete(agent_opts, 1, C2). - -finish_mib_storage_dets(Config) when list(Config) -> - ?LOG("finish_mib_storage_dets -> entry", []), - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - C2 = lists:keydelete(vsn, 1, C1), - lists:keydelete(agent_opts, 1, C2). - -finish_mib_storage_mnesia(Config) when list(Config) -> - ?LOG("finish_mib_storage_mnesia -> entry", []), - delete_tables(), - delete_mib_storage_mnesia_tables(), - C1 = stop_agent(Config), - delete_files(C1), - C2 = lists:keydelete(vsn, 1, C1), - lists:keydelete(agent_opts, 1, C2). - -finish_varm_mib_storage_dets(Config) when list(Config) -> - ?LOG("finish_varm_mib_storage_dets -> entry", []), - delete_tables(), - %% C1 = stop_agent(Config), % In case something went wrong... - delete_files(Config), - C2 = lists:keydelete(vsn, 1, Config), - lists:keydelete(agent_opts, 1, C2). - -finish_varm_mib_storage_mnesia(Config) when list(Config) -> - ?LOG("finish_varm_mib_storage_mnesia -> entry", []), - delete_tables(), - delete_mib_storage_mnesia_tables(), - %% C1 = stop_agent(Config), % In case something went wrong... - delete_files(Config), - C2 = lists:keydelete(vsn, 1, Config), - lists:keydelete(agent_opts, 1, C2). - -finish_size_check_mse(Config) when list(Config) -> - finish_size_check_ms(Config). - -finish_size_check_msd(Config) when list(Config) -> - finish_size_check_ms(Config). - -finish_size_check_msm(Config) when list(Config) -> - finish_size_check_ms(Config). - -finish_size_check_ms(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - - -%% These are just interface functions to fool the test server -mse_simple(X) -> simple(X). -mse_v1_processing(X) -> v1_processing(X). -mse_big(X) -> big(X). -mse_big2(X) -> big2(X). -mse_loop_mib(X) -> loop_mib(X). -mse_api(X) -> api(X). -mse_sa_register(X) -> sa_register(X). -mse_v1_trap(X) -> v1_trap(X). -mse_sa_error(X) -> sa_error(X). -mse_next_across_sa(X) -> next_across_sa(X). -mse_undo(X) -> undo(X). -mse_standard_mib(X) -> snmp_standard_mib(X). -mse_community_mib(X) -> snmp_community_mib(X). -mse_framework_mib(X) -> snmp_framework_mib(X). -mse_target_mib(X) -> snmp_target_mib(X). -mse_notification_mib(X) -> snmp_notification_mib(X). -mse_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). -mse_sparse_table(X) -> sparse_table(X). -mse_me_of(X) -> ms_me_of(X). -mse_mib_of(X) -> ms_mib_of(X). - -msd_simple(X) -> simple(X). -msd_v1_processing(X) -> v1_processing(X). -msd_big(X) -> big(X). -msd_big2(X) -> big2(X). -msd_loop_mib(X) -> loop_mib(X). -msd_api(X) -> api(X). -msd_sa_register(X) -> sa_register(X). -msd_v1_trap(X) -> v1_trap(X). -msd_sa_error(X) -> sa_error(X). -msd_next_across_sa(X) -> next_across_sa(X). -msd_undo(X) -> undo(X). -msd_standard_mib(X) -> snmp_standard_mib(X). -msd_community_mib(X) -> snmp_community_mib(X). -msd_framework_mib(X) -> snmp_framework_mib(X). -msd_target_mib(X) -> snmp_target_mib(X). -msd_notification_mib(X) -> snmp_notification_mib(X). -msd_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). -msd_sparse_table(X) -> sparse_table(X). -msd_me_of(X) -> ms_me_of(X). -msd_mib_of(X) -> ms_mib_of(X). - -msm_simple(X) -> simple(X). -msm_v1_processing(X) -> v1_processing(X). -msm_big(X) -> big(X). -msm_big2(X) -> big2(X). -msm_loop_mib(X) -> loop_mib(X). -msm_api(X) -> api(X). -msm_sa_register(X) -> sa_register(X). -msm_v1_trap(X) -> v1_trap(X). -msm_sa_error(X) -> sa_error(X). -msm_next_across_sa(X) -> next_across_sa(X). -msm_undo(X) -> undo(X). -msm_standard_mib(X) -> snmp_standard_mib(X). -msm_community_mib(X) -> snmp_community_mib(X). -msm_framework_mib(X) -> snmp_framework_mib(X). -msm_target_mib(X) -> snmp_target_mib(X). -msm_notification_mib(X) -> snmp_notification_mib(X). -msm_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). -msm_sparse_table(X) -> sparse_table(X). -msm_me_of(X) -> ms_me_of(X). -msm_mib_of(X) -> ms_mib_of(X). - - -mse_size_check(X) -> p("mse_size_check..."), ms_size_check(X). -msd_size_check(X) -> p("msd_size_check..."), ms_size_check(X). -msm_size_check(X) -> p("msm_size_check..."), ms_size_check(X). - -msd_varm_mib_start(X) -> p("msd_varm_mib_start..."), varm_mib_start(X). -msm_varm_mib_start(X) -> p("msm_varm_mib_start..."), varm_mib_start(X). - -ms_size_check(suite) -> []; -ms_size_check(Config) when list(Config) -> - p("ms_size_check..."), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?LOG("mib server size check...", []), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - ?line load_master_std("OTP-SNMPEA-MIB"), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-MPD-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-USER-BASED-SM-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - ?line load_master_std("SNMPv2-MIB"), - ?line load_master_std("SNMPv2-TM"), - - ?SLEEP(2000), - - ?line display_memory_usage(), - - ?line unload_master("OTP-SNMPEA-MIB"), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?line unload_master("SNMP-MPD-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-USER-BASED-SM-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - ?line unload_master("SNMPv2-MIB"), - ?line unload_master("SNMPv2-TM"), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - - ok. - - -varm_mib_start(suite) -> []; -varm_mib_start(Config) when list(Config) -> - p("varm_mib_start..."), - ?LOG("varm_mib_start -> entry", []), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - %% Start the agent - Opts = ?GCONF(agent_opts, Config), - Config1 = start_v1_agent(Config, Opts), - - %% Sleep some in order for the agent to start properly - ?DBG("varm_mib_start -> sleep some (before loading mobs)", []), - ?SLEEP(5000), - - %% Load all the mibs - HardwiredMibs = loaded_mibs(), - ?DBG("varm_mib_start -> load all mibs", []), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - - %% Unload the hardwired mibs - ?DBG("varm_mib_start -> sleep some (before unloading hardwired mibs)", []), - ?SLEEP(1000), - ?DBG("varm_mib_start -> unload (hardwired) mibs", []), - ?line unload_mibs(HardwiredMibs), %% unload hardwired - - ?DBG("varm_mib_start -> sleep some (before stopping agent)", []), - ?SLEEP(1000), - - %% Stop the agent (without deleting the stored files) - ?DBG("varm_mib_start -> stop the agent", []), - Config2 = stop_agent(Config1), - - %% Sleep some in order for the agent to stop properly - ?DBG("varm_mib_start -> sleep some (before re-starting the agent)", []), - ?SLEEP(5000), - - %% Start the agent (again) - ?DBG("varm_mib_start -> start the agent", []), - Config3 = start_v1_agent(Config2, Opts), - - ?DBG("varm_mib_start -> sleep some (before starting tests)", []), - ?SLEEP(5000), - - %% Perform the test(s) - ?DBG("varm_mib_start -> perform the tests", []), - try_test(snmp_community_mib), - try_test(snmp_framework_mib), - try_test(snmp_target_mib), - try_test(snmp_notification_mib), - - %% Stop the agent (without deleting the stored files) - ?DBG("varm_mib_start -> stop the agent", []), - stop_agent(Config3), - ok. - - --define(snmpTrapCommunity_instance, [1,3,6,1,6,3,18,1,4,0]). --define(vacmViewSpinLock_instance, [1,3,6,1,6,3,16,1,5,1,0]). --define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). - -ms_me_of(suite) -> []; -ms_me_of(Config) when list(Config) -> - p("ms_me_of..."), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - ?line load_master_std("OTP-SNMPEA-MIB"), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-MPD-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - - ?SLEEP(2000), - - ?line display_memory_usage(), - - - ?DBG("ms_me_of -> find ~w from SNMP-COMMUNITY-MIB", - [?snmpTrapCommunity_instance]), - ?line ok = me_of(?snmpTrapCommunity_instance), - - ?DBG("ms_me_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", - [?vacmViewSpinLock_instance]), - ?line ok = me_of(?vacmViewSpinLock_instance), - - ?DBG("ms_me_of -> find ~w from SNMP-USER-BASED-SM-MIB", - [?usmStatsNotInTimeWindows_instance]), - ?line {error, _} = me_of(?usmStatsNotInTimeWindows_instance), - - - ?line unload_master("OTP-SNMPEA-MIB"), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?line unload_master("SNMP-MPD-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - - ok. - -me_of(Oid) -> - case snmpa:me_of(Oid) of - {ok, #me{oid = Oid}} -> - ok; - {ok, #me{oid = OtherOid}} -> - case lists:reverse(Oid) of - [0|Rest] -> - case lists:reverse(Rest) of - OtherOid -> - ok; - AnotherOid -> - {error, {invalid_oid, Oid, AnotherOid}} - end; - _ -> - {error, {invalid_oid, Oid, OtherOid}} - end; - {error, Reason} -> - {error, Reason}; - Else -> - {error, Else} - end. - - -ms_mib_of(suite) -> []; -ms_mib_of(Config) when list(Config) -> - p("ms_mib_of..."), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - ?line load_master_std("OTP-SNMPEA-MIB"), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-MPD-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - - ?SLEEP(2000), - - ?line display_memory_usage(), - - - ?DBG("ms_mib_of -> find ~w from SNMP-COMMUNITY-MIB", - [?snmpTrapCommunity_instance]), - ?line ok = mib_of(?snmpTrapCommunity_instance, 'SNMP-COMMUNITY-MIB'), - - ?DBG("ms_mib_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", - [?vacmViewSpinLock_instance]), - ?line ok = mib_of(?vacmViewSpinLock_instance, 'SNMP-VIEW-BASED-ACM-MIB'), - - ?DBG("ms_mib_of -> find ~w from SNMP-USER-BASED-SM-MIB", - [?usmStatsNotInTimeWindows_instance]), - ?line {error, _} = mib_of(?usmStatsNotInTimeWindows_instance, - 'SNMP-USER-BASED-SM-MIB'), - - - ?line unload_master("OTP-SNMPEA-MIB"), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?line unload_master("SNMP-MPD-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - - ok. - -mib_of(Oid, ExpectedMibName) -> - ?DBG("mib_of -> entry with" - "~n Oid: ~p" - "~n ExpectedMibName: ~p", [Oid, ExpectedMibName]), - %% case snmpa:mib_of(Oid) of - MibOf = snmpa:mib_of(Oid), - ?DBG("mib_of -> MibOf: ~n~p", [MibOf]), - case MibOf of - {ok, ExpectedMibName} -> - ok; - {ok, OtherMibName} -> - {error, {invalid_mib, ExpectedMibName, OtherMibName}}; - {error, Reason} -> - {error, Reason}; - Else -> - ?DBG("mib_of -> Else: ~n~p", [Else]), - {error, Else} - end. - - -app_info(suite) -> []; -app_info(Config) when list(Config) -> - SnmpDir = app_dir(snmp), - SslDir = app_dir(ssl), - CryptoDir = app_dir(crypto), - Attr = snmp:module_info(attributes), - AppVsn = - case lists:keysearch(app_vsn, 1, Attr) of - {value, {app_vsn, V}} -> - V; - false -> - "undefined" - end, - io:format("Root dir: ~s~n" - "SNMP: Application dir: ~s~n" - " Application ver: ~s~n" - "SSL: Application dir: ~s~n" - "CRYPTO: Application dir: ~s~n", - [code:root_dir(), SnmpDir, AppVsn, SslDir, CryptoDir]), - ok. - -app_dir(App) -> - case code:lib_dir(App) of - D when list(D) -> - filename:basename(D); - {error, _Reason} -> - "undefined" - end. - - - -%v1_cases() -> [loop_mib]; -v1_cases() -> -[simple, db_notify_client, v1_processing, big, big2, - loop_mib, api, subagent, mnesia, {group, multiple_reqs}, - sa_register, v1_trap, sa_error, next_across_sa, undo, - {group, reported_bugs}, {group, standard_mibs}, - sparse_table, cnt_64, opaque, change_target_addr_config]. - -init_v1(Config) when list(Config) -> - ?line SaNode = ?config(snmp_sa, Config), - ?line create_tables(SaNode), - ?line AgentDir = ?config(agent_dir, Config), - ?line MgrDir = ?config(mgr_dir, Config), - ?line Ip = ?config(ip, Config), - ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v1} | start_v1_agent(Config)]. - -finish_v1(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - - -%v2_cases() -> [loop_mib_2]; -v2_cases() -> -[simple_2, v2_processing, big_2, big2_2, loop_mib_2, - api_2, subagent_2, mnesia_2, {group, multiple_reqs_2}, - sa_register_2, v2_trap, {group, v2_inform}, sa_error_2, - next_across_sa_2, undo_2, {group, reported_bugs_2}, - {group, standard_mibs_2}, v2_types, implied, - sparse_table_2, cnt_64_2, opaque_2, v2_caps]. - -init_v2(Config) when list(Config) -> - SaNode = ?config(snmp_sa, Config), - create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), - MgrDir = ?config(mgr_dir, Config), - Ip = ?config(ip, Config), - config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v2} | start_v2_agent(Config)]. - -finish_v2(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - - -v1_v2_cases() -> -[simple_bi]. - -init_v1_v2(Config) when list(Config) -> - SaNode = ?config(snmp_sa, Config), - create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), - MgrDir = ?config(mgr_dir, Config), - Ip = ?config(ip, Config), - config([v1,v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, bilingual} | start_bilingual_agent(Config)]. - -finish_v1_v2(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - - -%v3_cases() -> [loop_mib_3]; -v3_cases() -> -[simple_3, v3_processing, big_3, big2_3, api_3, - subagent_3, mnesia_3, loop_mib_3, multiple_reqs_3, - sa_register_3, v3_trap, v3_inform, sa_error_3, - next_across_sa_3, undo_3, {group, reported_bugs_3}, - {group, standard_mibs_3}, {group, v3_security}, - v2_types_3, implied_3, sparse_table_3, cnt_64_3, - opaque_3, v2_caps_3]. - -init_v3(Config) when list(Config) -> - %% Make sure crypto works, otherwise start_agent will fail - %% and we will be stuck with a bunch of mnesia tables for - %% the rest of this suite... - ?DBG("start_agent -> start crypto app",[]), - case os:type() of - vxworks -> - no_crypto; - _ -> - case ?CRYPTO_START() of - ok -> - case ?CRYPTO_SUPPORT() of - {no, Reason} -> - ?SKIP({unsupported_encryption, Reason}); - yes -> - ok - end; - {error, Reason} -> - ?SKIP({failed_starting_crypto, Reason}) - end - end, - SaNode = ?config(snmp_sa, Config), - create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), - MgrDir = ?config(mgr_dir, Config), - Ip = ?config(ip, Config), - ?line ok = config([v3], MgrDir, AgentDir, - tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v3} | start_v3_agent(Config)]. - -finish_v3(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - - -mt_cases() -> -[multi_threaded, mt_trap]. - -init_mt(Config) when list(Config) -> - SaNode = ?config(snmp_sa, Config), - create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), - MgrDir = ?config(mgr_dir, Config), - Ip = ?config(ip, Config), - ?line ok = config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v2} | start_multi_threaded_agent(Config)]. - -finish_mt(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - -%% This one *must* be run first in each case. -init_case(Config) when list(Config) -> - ?DBG("init_case -> entry with" - "~n Config: ~p", [Config]), - SaNode = ?config(snmp_sa, Config), - MgrNode = ?config(snmp_mgr, Config), - MasterNode = node(), - - SaHost = ?HOSTNAME(SaNode), - MgrHost = ?HOSTNAME(MgrNode), - MasterHost = ?HOSTNAME(MasterNode), - {ok, MasterIP} = snmp_misc:ip(MasterHost), - {ok, MIP} = snmp_misc:ip(MgrHost), - {ok, SIP} = snmp_misc:ip(SaHost), - - - put(mgr_node, MgrNode), - put(sa_node, SaNode), - put(master_node, MasterNode), - put(sa_host, SaHost), - put(mgr_host, MgrHost), - put(master_host, MasterHost), - put(mip, tuple_to_list(MIP)), - put(masterip , tuple_to_list(MasterIP)), - put(sip, tuple_to_list(SIP)), - - MibDir = ?config(mib_dir, Config), - put(mib_dir, MibDir), - StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", - put(std_mib_dir, StdM), - - MgrDir = ?config(mgr_dir, Config), - put(mgr_dir, MgrDir), - - put(vsn, ?config(vsn, Config)), - ?DBG("init_case -> exit with" - "~n MasterNode: ~p" - "~n SaNode: ~p" - "~n MgrNode: ~p" - "~n MibDir: ~p", [MasterNode, SaNode, MgrNode, MibDir]), - {SaNode, MgrNode, MibDir}. - -load_master(Mib) -> - ?DBG("load_master -> entry with" - "~n Mib: ~p", [Mib]), - snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety - ok = snmpa:load_mibs(snmp_master_agent, [get(mib_dir) ++ Mib]). - -load_master_std(Mib) -> - ?DBG("load_master_std -> entry with" - "~n Mib: ~p", [Mib]), - snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety - ok = snmpa:load_mibs(snmp_master_agent, [get(std_mib_dir) ++ Mib]). - -unload_master(Mib) -> - ?DBG("unload_master -> entry with" - "~n Mib: ~p", [Mib]), - ok = snmpa:unload_mibs(snmp_master_agent, [Mib]). - -loaded_mibs() -> - ?DBG("loaded_mibs -> entry",[]), - Info = snmpa:info(snmp_master_agent), - {value, {loaded_mibs, Mibs}} = lists:keysearch(loaded_mibs, 1, Info), - [atom_to_list(Mib) || {Mib,_,_} <- Mibs]. - -unload_mibs(Mibs) -> - ?DBG("unload_mibs -> entry with" - "~n Mibs: ~p", [Mibs]), - ok = snmpa:unload_mibs(snmp_master_agent, Mibs). - -start_subagent(SaNode, RegTree, Mib) -> - ?DBG("start_subagent -> entry with" - "~n SaNode: ~p" - "~n RegTree: ~p" - "~n Mib: ~p", [SaNode, RegTree, Mib]), - MA = whereis(snmp_master_agent), - ?DBG("start_subagent -> MA: ~p", [MA]), - MibDir = get(mib_dir), - Mib1 = join(MibDir,Mib), - %% BMK BMK -% case rpc:call(SaNode,snmp_supervisor,start_subagent,[MA,RegTree,[Mib1]]) of - case rpc:call(SaNode, snmpa_supervisor, - start_sub_agent, [MA, RegTree, [Mib1]]) of - {ok, SA} -> - ?DBG("start_subagent -> SA: ~p", [SA]), - {ok, SA}; - Error -> - ?FAIL({subagent_start_failed, SaNode, Error, [MA, RegTree, Mib1]}) - end. - -stop_subagent(SA) -> - ?DBG("stop_subagent -> entry with" - "~n SA: ~p", [SA]), - %% BNK BMK - %% rpc:call(node(SA), snmp_supervisor, stop_subagent, [SA]). - rpc:call(node(SA), snmpa_supervisor, stop_sub_agent, [SA]). - -%%----------------------------------------------------------------- -%% This function takes care of the old OTP-SNMPEA-MIB. -%% Unfortunately, the testcases were written to use the data in the -%% internal tables, and these table are now obsolete and not used -%% by the agent. Therefore, we emulate them by using -%% OLD-SNMPEA-MIB, which uses the default impl. of all tables. -%% -%% These two rows must exist in intCommunityTable -%% {[147,214,36,45], "public", 2, readWrite}. -%% {[147,214,36,45], "standard trap", 2, read}. -%% (But with the manager's IP address) -%% -%%----------------------------------------------------------------- -init_old() -> - snmpa_local_db:table_create_row(intCommunityTable, - get(mip) ++ [6 | "public"], - {get(mip), "public", 2, 2}), - snmpa_local_db:table_create_row(intCommunityTable, - get(mip) ++ [13 | "standard trap"], - {get(mip), "standard trap", 2, 1}), - snmpa_local_db:variable_set(intAgentIpAddress, [127,0,0,1]). - - - -simple(suite) -> []; -simple(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - try_test(simple_standard_test). - -simple_2(X) -> simple(X). - -simple_bi(suite) -> []; -simple_bi(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - put(vsn, v1), % First, try v1 manager - try_test(simple_standard_test), - - put(vsn, v2), % Then, try v2 manager - try_test(simple_standard_test). - -simple_3(X) -> - simple(X). - -big(suite) -> []; -big(Config) when list(Config) -> - ?DBG("big -> entry", []), - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Starting subagent..."), - ?line pong = net_adm:ping(SaNode), - - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), - ?DBG("big -> SA: ~p", [SA]), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(big_test), - ?line stop_subagent(SA), - ?line unload_master("OLD-SNMPEA-MIB"). - -big_2(X) -> big(X). - -big_3(X) -> big(X). - - -big2(suite) -> []; -big2(Config) when list(Config) -> - %% This is exactly the same tests as 'big', but with the - %% v2 equivalent of the mibs. - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Starting subagent..."), - ?line pong = net_adm:ping(SaNode), - - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1-v2"), - ?line load_master("OLD-SNMPEA-MIB-v2"), - ?line init_old(), - try_test(big_test), - ?line stop_subagent(SA), - ?line unload_master("OLD-SNMPEA-MIB-v2"). - -big2_2(X) -> big2(X). - -big2_3(X) -> big2(X). - - -multi_threaded(suite) -> []; -multi_threaded(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test1"), - try_test(multi_threaded_test), - ?line unload_master("Test1"). - -mt_trap(suite) -> []; -mt_trap(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line load_master("Test1"), - ?line load_master("TestTrapv2"), - try_test(mt_trap_test, [MA]), - ?line unload_master("TestTrapv2"), - ?line unload_master("Test1"). - -v2_types(suite) -> []; -v2_types(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test1"), - try_test(types_v2_test), - ?line unload_master("Test1"). - -v2_types_3(X) -> v2_types(X). - - -implied(suite) -> []; -implied(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line load_master("Test1"), - try_test(implied_test,[MA]), - ?line unload_master("Test1"). - -implied_3(X) -> implied(X). - - -sparse_table(suite) -> []; -sparse_table(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test1"), - try_test(sparse_table_test), - ?line unload_master("Test1"). - -sparse_table_2(X) -> sparse_table(X). - -sparse_table_3(X) -> sparse_table(X). - -cnt_64(suite) -> []; -cnt_64(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line load_master("Test1"), - try_test(cnt_64_test, [MA]), - ?line unload_master("Test1"). - -cnt_64_2(X) -> cnt_64(X). - -cnt_64_3(X) -> cnt_64(X). - -opaque(suite) -> []; -opaque(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test1"), - try_test(opaque_test), - ?line unload_master("Test1"). - -opaque_2(X) -> opaque(X). - -opaque_3(X) -> opaque(X). - - -change_target_addr_config(suite) -> []; -change_target_addr_config(Config) when list(Config) -> - p("Testing changing target address config..."), - ?LOG("change_target_addr_config -> entry",[]), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - put(sname,snmp_suite), - put(verbosity,trace), - - MA = whereis(snmp_master_agent), - - ?LOG("change_target_addr_config -> load TestTrap",[]), - ?line load_master("TestTrap"), - - ?LOG("change_target_addr_config -> set trace verbosity for local_db",[]), - ?line snmpa:verbosity(local_db,trace), - - %% First send some traps that will arive att the original manager - ?LOG("change_target_addr_config -> send trap",[]), - try_test(ma_trap1, [MA]), - - ?LOG("change_target_addr_config -> set silence verbosity for local_db",[]), - ?line snmpa:verbosity(local_db,silence), - - %% Start new dummy listener - ?LOG("change_target_addr_config -> start dummy manager",[]), - ?line {ok,Pid,NewPort} = dummy_manager_start(MA), - - %% Reconfigure - ?LOG("change_target_addr_config -> reconfigure",[]), - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_addr_conf(AgentDir, NewPort), - ?line snmp_target_mib:reconfigure(AgentDir), - - %% Send the trap again - ?LOG("change_target_addr_config -> send trap again",[]), - catch dummy_manager_send_trap2(Pid), - - ?LOG("change_target_addr_config -> await trap ack",[]), - catch dummy_manager_await_trap2_ack(), - - ?LOG("change_target_addr_config -> stop dummy manager",[]), - ?line ok = dummy_manager_stop(Pid), - - ?LOG("change_target_addr_config -> reset target address config",[]), - ?line reset_target_addr_conf(AgentDir), - - ?LOG("change_target_addr_config -> unload TestTrap",[]), - ?line unload_master("TestTrap"). - - -dummy_manager_start(MA) -> - ?DBG("dummy_manager_start -> entry",[]), - Pid = spawn(get(mgr_node), ?MODULE,dummy_manager_init,[self(),MA]), - ?DBG("dummy_manager_start -> Pid: ~p",[Pid]), - await_dummy_manager_started(Pid). - -await_dummy_manager_started(Pid) -> - receive - {dummy_manager_started,Pid,Port} -> - ?DBG("dummy_manager_start -> acknowledge received with" - "~n Port: ~p",[Port]), - {ok,Pid,Port}; - {'EXIT', Pid, Reason} -> - {error, Pid, Reason}; - O -> - ?LOG("dummy_manager_start -> received unknown message:" - "~n ~p",[O]), - await_dummy_manager_started(Pid) - end. - -dummy_manager_stop(Pid) -> - ?DBG("dummy_manager_stop -> entry with Pid: ~p",[Pid]), - Pid ! stop, - receive - {dummy_manager_stopping, Pid} -> - ?DBG("dummy_manager_stop -> acknowledge received",[]), - ok - after 10000 -> - ?ERR("dummy_manager_stop -> timeout",[]), - timeout - end. - -dummy_manager_send_trap2(Pid) -> - ?DBG("dummy_manager_send_trap2 -> entry",[]), - Pid ! {send_trap,testTrap2}. - -dummy_manager_await_trap2_ack() -> - ?DBG("dummy_manager_await_trap2 -> entry",[]), - receive - {received_trap,Trap} -> - ?LOG("dummy_manager_await_trap2 -> received trap: ~p",[Trap]), - %% Note: - %% Without this sleep the v2_inform_i testcase failes! There - %% is no relation between these two test cases as far as I - %% able to figure out... - sleep(60000), - ok; - O -> - ?ERR("dummy_manager_await_trap2 -> unexpected message: ~p",[O]), - ok - after 10000 -> - ?ERR("dummy_manager_await_trap2 -> timeout",[]), - timeout - end. - -dummy_manager_init(Parent,MA) -> - ?DBG("dummy_manager_init -> entry with" - "~n Parent: ~p" - "~n MA: ~p",[Parent,MA]), - {ok,S} = gen_udp:open(0,[{recbuf,65535}]), - ?DBG("dummy_manager_init -> S: ~p",[S]), - {ok,Port} = inet:port(S), - ?DBG("dummy_manager_init -> Port: ~p",[Port]), - Parent ! {dummy_manager_started,self(),Port}, - dummy_manager_loop(Parent,S,MA). - -dummy_manager_loop(P,S,MA) -> - ?LOG("dummy_manager_loop -> ready for receive",[]), - receive - {send_trap,Trap} -> - ?LOG("dummy_manager_loop -> received trap send request" - "~n Trap: ~p",[Trap]), - snmpa:send_trap(MA, Trap, "standard trap"), - dummy_manager_loop(P,S,MA); - {udp, _UdpId, Ip, UdpPort, Bytes} -> - ?LOG("dummy_manager_loop -> received upd message" - "~n from: ~p:~p" - "~n size: ~p", - [Ip, UdpPort, dummy_manager_message_sz(Bytes)]), - R = dummy_manager_handle_message(Bytes), - ?DBG("dummy_manager_loop -> R: ~p",[R]), - P ! R, - dummy_manager_loop(P,S,MA); - stop -> - ?DBG("dummy_manager_loop -> received stop request",[]), - P ! {dummy_manager_stopping, self()}, - gen_udp:close(S), - exit(normal); - O -> - ?LOG("dummy_manager_loop -> received unknown message:" - "~n ~p",[O]), - dummy_manager_loop(P,S,MA) - end. - -dummy_manager_message_sz(B) when binary(B) -> - size(B); -dummy_manager_message_sz(L) when list(L) -> - length(L); -dummy_manager_message_sz(_) -> - undefined. - -dummy_manager_handle_message(Bytes) -> - case (catch snmp_pdus:dec_message(Bytes)) of - {'EXIT',Reason} -> - ?ERR("dummy_manager_handle_message -> " - "failed decoding message only:~n ~p",[Reason]), - {error,Reason}; - M -> - ?DBG("dummy_manager_handle_message -> decoded message:" - "~n ~p",[M]), - {received_trap,M} - end. - - -api(suite) -> []; -api(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(api_test, [node()]), - ?line unload_master("OLD-SNMPEA-MIB"). - -api_2(X) -> api(X). - -api_3(X) -> api(X). - - -subagent(suite) -> []; -subagent(Config) when list(Config) -> - {SaNode, _MgrNode, MibDir} = init_case(Config), - - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), - try_test(load_test_sa), - - p("Testing unregister subagent..."), - MA = whereis(snmp_master_agent), - rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), - try_test(unreg_test), - - p("Loading previous subagent mib in master and testing..."), - ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas1"]), - try_test(load_test), - - p("Unloading previous subagent mib in master and testing..."), - ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas1"]), - try_test(unreg_test), - p("Testing register subagent..."), - rpc:call(SaNode, snmp, register_subagent, - [MA, ?klas1, SA]), - try_test(load_test_sa), - - ?line stop_subagent(SA), - try_test(unreg_test). - -subagent_2(X) -> subagent(X). - -subagent_3(X) -> subagent(X). - - -mnesia(suite) -> []; -mnesia(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Starting subagent with mnesia impl..."), - {ok, SA} = start_subagent(SaNode, ?klas2, "Klas2"), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - - try_test(big_test_2), - - p("Testing unregister subagent..."), - MA = whereis(snmp_master_agent), - rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), - try_test(unreg_test), - ?line unload_master("OLD-SNMPEA-MIB"), - ?line stop_subagent(SA). - -mnesia_2(X) -> mnesia(X). - -mnesia_3(X) -> mnesia(X). - - - -mul_cases() -> -[mul_get, mul_get_err, mul_next, mul_next_err, - mul_set_err]. - - -multiple_reqs_3(_X) -> - {req, [], {conf, init_mul, mul_cases_3(), finish_mul}}. - - -mul_cases_2() -> -[mul_get_2, mul_get_err_2, mul_next_2, mul_next_err_2, - mul_set_err_2]. - - -mul_cases_3() -> - [mul_get_3, mul_get_err_3, mul_next_3, mul_next_err_3, mul_set_err_3]. - - -init_mul(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - [{mul_sub, SA} | Config]. - -finish_mul(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - SA = ?config(mul_sub, Config), - - ?line unload_master("OLD-SNMPEA-MIB"), - ?line stop_subagent(SA), - lists:keydelete(mul_sub, 1, Config). - -mul_get(suite) -> []; -mul_get(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple get..."), - try_test(do_mul_get). - -mul_get_2(X) -> mul_get(X). - -mul_get_3(X) -> mul_get(X). - - -mul_get_err(suite) -> []; -mul_get_err(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple get with error..."), - try_test(do_mul_get_err). - -mul_get_err_2(X) -> mul_get_err(X). - -mul_get_err_3(X) -> mul_get_err(X). - - -mul_next(suite) -> []; -mul_next(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple next..."), - try_test(do_mul_next). - -mul_next_2(X) -> mul_next(X). - -mul_next_3(X) -> mul_next(X). - - -mul_next_err(suite) -> []; -mul_next_err(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple next..."), - try_test(do_mul_next_err). - -mul_next_err_2(X) -> mul_next_err(X). - -mul_next_err_3(X) -> mul_next_err(X). - - -mul_set(suite) -> []; -mul_set(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple set..."), - try_test(do_mul_set). - -mul_set_2(X) -> mul_set(X). - -mul_set_3(X) -> mul_set(X). - - -mul_set_err(suite) -> []; -mul_set_err(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple set with error..."), - try_test(do_mul_set_err). - -mul_set_err_2(X) -> mul_set_err(X). - -mul_set_err_3(X) -> mul_set_err(X). - - -sa_register(suite) -> []; -sa_register(Config) when list(Config) -> - ?DBG("sa_register -> entry", []), - {SaNode, _MgrNode, MibDir} = init_case(Config), - - ?DBG("sa_register -> start subagent", []), - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), - - ?DBG("sa_register -> unregister subagent", []), - p("Testing unregister subagent (2)..."), - MA = whereis(snmp_master_agent), - rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), - try_test(unreg_test), - - p("Loading SA-MIB..."), - ?DBG("sa_register -> unload mibs", []), - snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), - ?DBG("sa_register -> unload mibs", []), - snmpa:load_mibs(SA, [MibDir ++ "SA-MIB"]), - ?DBG("sa_register -> register subagent", []), - rpc:call(SaNode, snmp, register_subagent, [MA,?sa,SA]), - try_test(sa_mib), - - ?DBG("sa_register -> stop subagent", []), - ?line stop_subagent(SA). - -sa_register_2(X) -> sa_register(X). - -sa_register_3(X) -> sa_register(X). - - -v1_trap(suite) -> []; -v1_trap(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Testing trap sending from master agent..."), - MA = whereis(snmp_master_agent), - - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(ma_trap1, [MA]), - try_test(ma_trap2, [MA]), - try_test(ma_v2_2_v1_trap, [MA]), - try_test(ma_v2_2_v1_trap2, [MA]), - - p("Testing trap sending from subagent..."), - try_test(sa_trap1, [SA]), - try_test(sa_trap2, [SA]), - try_test(sa_trap3, [SA]), - - ?line unload_master("TestTrap"), - ?line unload_master("TestTrapv2"), - - ?line stop_subagent(SA). - -v2_trap(suite) -> []; -v2_trap(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Testing trap sending from master agent..."), - MA = whereis(snmp_master_agent), - - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - - try_test(ma_v2_trap1, [MA]), - try_test(ma_v2_trap2, [MA]), - try_test(ma_v1_2_v2_trap, [MA]), - try_test(ma_v1_2_v2_trap2, [MA]), - - try_test(sa_mib), - p("Testing trap sending from subagent..."), - try_test(sa_v1_2_v2_trap1, [SA]), - try_test(sa_v1_2_v2_trap2, [SA]), - try_test(sa_v1_2_v2_trap3, [SA]), - - ?line unload_master("TestTrap"), - ?line unload_master("TestTrapv2"), - - ?line stop_subagent(SA). - -v3_trap(X) -> - v2_trap(X). - - -v3_inform(_X) -> - %% v2_inform(X). - {req, [], {conf, init_v3_inform, [v3_inform_i], finish_v3_inform}}. - -init_v2_inform(Config) when list(Config) -> - _Dir = ?config(agent_dir, Config), -% snmp_internal_mib:configure(Dir), - Config. - -init_v3_inform(X) -> - init_v2_inform(X). - -finish_v2_inform(Config) when list(Config) -> - _Dir = ?config(agent_dir, Config), -% snmp_internal_mib:configure(Dir), - Config. - -finish_v3_inform(X) -> - finish_v2_inform(X). - - - -v2_inform_i(suite) -> []; -v2_inform_i(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing inform sending from master agent... NOTE! This test\ntakes a " - "few minutes (5) to complete."), - MA = whereis(snmp_master_agent), - - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(ma_v2_inform1, [MA]), - - ?line unload_master("TestTrap"), - ?line unload_master("TestTrapv2"). - -v3_inform_i(X) -> v2_inform_i(X). - - -sa_error(suite) -> []; -sa_error(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Testing sa bad value (is_set_ok)..."), - try_test(sa_errs_bad_value), - - p("Testing sa gen err (set)..."), - try_test(sa_errs_gen_err), - - p("Testing too big..."), - try_test(sa_too_big), - - ?line unload_master("OLD-SNMPEA-MIB"), - stop_subagent(SA). - -sa_error_2(X) -> sa_error(X). - -sa_error_3(X) -> sa_error(X). - - -next_across_sa(suite) -> []; -next_across_sa(Config) when list(Config) -> - {SaNode, _MgrNode, MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Loading another subagent mib..."), - ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas1"]), - - rpc:call(SaNode, snmp, register_subagent, [MA, ?klas1, SA]), - try_test(load_test_sa), - - p("Testing next across subagent (endOfMibView from SA)..."), - try_test(next_across_sa), - - p("Unloading mib"), - snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), - rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), - try_test(unreg_test), - - p("Starting another subagent"), - ?line {ok, SA2} = start_subagent(SaNode, ?klas1, "Klas1"), - p("Testing next across subagent (wrong prefix from SA)..."), - try_test(next_across_sa), - - stop_subagent(SA), - stop_subagent(SA2). - -next_across_sa_2(X) -> next_across_sa(X). - -next_across_sa_3(X) -> next_across_sa(X). - - -undo(suite) -> []; -undo(Config) when list(Config) -> - {SaNode, _MgrNode, MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Testing undo phase at master agent..."), - ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas3"]), - ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas4"]), - try_test(undo_test), - try_test(api_test2), - ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas3"]), - - p("Testing bad return values from instrum. funcs..."), - try_test(bad_return), - - ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas4"]), - - p("Testing undo phase at subagent..."), - ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas3"]), - ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas4"]), - ?line ok = snmpa:register_subagent(MA, ?klas3, SA), - ?line ok = snmpa:register_subagent(MA, ?klas4, SA), - try_test(undo_test), - try_test(api_test3), - - p("Testing undo phase across master/subagents..."), - try_test(undo_test), - try_test(api_test3), - stop_subagent(SA). - -undo_2(X) -> undo(X). - -undo_3(X) -> undo(X). - -%% Req. Test2 -v1_processing(suite) -> []; -v1_processing(Config) when list(Config) -> - ?DBG("v1_processing -> entry", []), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - try_test(v1_proc), - ?line unload_master("Test2"). - -%% Req. Test2 -v2_processing(suite) -> []; -v2_processing(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - try_test(v2_proc), - ?line unload_master("Test2"). - -%% Req. Test2 -v3_processing(suite) -> []; -v3_processing(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - try_test(v2_proc), % same as v2! - ?line unload_master("Test2"). - - -%% We'll try get/set/trap and inform for all the auth & priv protocols. -%% For informs, the mgr is auth-engine. The agent has to sync. This is -%% accomplished by the first inform sent. That one will generate a -%% report, which makes it in sync. The notification-generating -%% application times out, and send again. This time it'll work. - -v3_crypto_basic(suite) -> []; -v3_crypto_basic(_Config) -> - EID = [0,0,0,0,0,0,0,0,0,0,0,2], - %% From rfc2274 appendix A.3.1 - ?line KMd5_1 = snmp:passwd2localized_key(md5, "maplesyrup", EID), - ?line [16#52,16#6f,16#5e,16#ed,16#9f,16#cc,16#e2,16#6f, - 16#89,16#64,16#c2,16#93,16#07,16#87,16#d8,16#2b] = - KMd5_1, - %% From rfc2274 appendix A.3.2 - ?line KSHA_1 = snmp:passwd2localized_key(sha, "maplesyrup", EID), - ?line [16#66,16#95,16#fe,16#bc,16#92,16#88,16#e3,16#62,16#82,16#23, - 16#5f,16#c7,16#15,16#1f,16#12,16#84,16#97,16#b3,16#8f,16#3f] = - KSHA_1, - %% From rfc2274, appendix A.5.1 - ?line KMd5_2 = snmp:passwd2localized_key(md5, "newsyrup", EID), - ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#88,16#05,16#61,16#51,16#41,16#67,16#6c,16#c9, - 16#19,16#61,16#74,16#e7,16#42,16#a3,16#25,16#51] = - snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2, 16, - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), - %% From rfc2274, appendix A.5.2 - ?line KSHA_2 = snmp:passwd2localized_key(sha, "newsyrup", EID), - ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#00,16#00,16#00,16#00,16#9c,16#10,16#17,16#f4, - 16#fd,16#48,16#3d,16#2d,16#e8,16#d5,16#fa,16#db, - 16#f8,16#43,16#92,16#cb,16#06,16#45,16#70,16#51] = - snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2, 20, - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), - KSHA_1t = lists:sublist(KSHA_1, 16), - KSHA_2t = lists:sublist(KSHA_2, 16), - ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#7e,16#f8,16#d8,16#a4,16#c9,16#cd,16#b2,16#6b, - 16#47,16#59,16#1c,16#d8,16#52,16#ff,16#88,16#b5] = - snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1t, KSHA_2t, 16, - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), - - %% Try with correct random - ?line Kc1 = snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2), - ?line KMd5_2 = snmp_user_based_sm_mib:extract_new_key(md5, KMd5_1, Kc1), - ?line Kc2 = snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2), - ?line KSHA_2 = snmp_user_based_sm_mib:extract_new_key(sha, KSHA_1, Kc2), - ok. - - - -v3_md5_auth(suite) -> []; -v3_md5_auth(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - p("Testing MD5 authentication...takes a few seconds..."), - - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_params_conf(AgentDir, "authMD5", authNoPriv), - ?line snmp_target_mib:reconfigure(AgentDir), - - MA = whereis(snmp_master_agent), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(v3_sync, [[{v2_proc, []}, - {ma_v2_trap1, [MA]}, - {v3_inform_sync, [MA]}]], - [{sec_level, authNoPriv}, {user, "authMD5"}]), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - ?line reset_target_params_conf(AgentDir). - -v3_sha_auth(suite) -> []; -v3_sha_auth(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - p("Testing SHA authentication...takes a few seconds..."), - - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_params_conf(AgentDir, "authSHA", authNoPriv), - ?line snmp_target_mib:reconfigure(AgentDir), - - MA = whereis(snmp_master_agent), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(v3_sync, [[{v2_proc, []}, - {ma_v2_trap1, [MA]}, - {v3_inform_sync, [MA]}]], - [{sec_level, authNoPriv}, {user, "authSHA"}]), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - ?line reset_target_params_conf(AgentDir). - -v3_des_priv(suite) -> []; -v3_des_priv(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - p("Testing DES encryption...takes a few seconds..."), - - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_params_conf(AgentDir, "privDES", authPriv), - ?line snmp_target_mib:reconfigure(AgentDir), - - MA = whereis(snmp_master_agent), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(v3_sync, [[{v2_proc, []}, - {ma_v2_trap1, [MA]}, - {v3_inform_sync, [MA]}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - ?line reset_target_params_conf(AgentDir). - -%% -define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). - -%% Make sure mgr is in sync with agent -v3_sync(Funcs) -> - ?DBG("v3_sync -> entry with Funcs: ~p",[Funcs]), - g([[sysDescr, 0]]), - expect(432, report, [{?usmStatsNotInTimeWindows_instance, any}]), - g([[sysDescr, 0]]), - expect(433, [{[sysDescr,0], any}]), - lists:foreach(fun({Func, Args}) -> apply(?MODULE, Func, Args) end, Funcs). - -v3_inform_sync(MA) -> - ?DBG("v3_sync -> entry with MA: ~p => Send notification",[MA]), - ?line snmpa:send_notification(MA, testTrapv22, no_receiver, - "standard inform", []), - %% Make sure agent is in sync with mgr... - ?DBG("v3_sync -> wait some time: ",[]), - sleep(20000), % more than 1500*10 in target_addr.conf - ?DBG("v3_sync -> await response",[]), - ?line expect(1, {inform, true}, - [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]). - - -v2_caps(suite) -> []; -v2_caps(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - try_test(v2_caps_i, [node()]). - -v2_caps_3(X) -> v2_caps(X). - - -v2_caps_i(Node) -> - ?line Idx = rpc:call(Node, snmp, add_agent_caps, [[1,2,3,4,5], "test cap"]), - g([[sysORID, Idx], [sysORDescr, Idx]]), - ?line expect(1, [{[sysORID, Idx], [1,2,3,4,5]}, - {[sysORDescr, Idx], "test cap"}]), - ?line rpc:call(Node, snmp, del_agent_caps, [Idx]), - g([[sysORID, Idx]]), - ?line expect(2, [{[sysORID, Idx], noSuchInstance}]). - - -%% Req. Test2 -v1_proc() -> - ?DBG("v1_proc -> entry", []), - %% According to RFC1157. - %% Template:
: - v1_get_p(), - v1_get_next_p(), - v1_set_p(). - - -v1_get_p() -> - %% 4.1.2:1 - g([[test2]]), - ?line expect(10, noSuchName, 1, [{[test2], 'NULL'}]), - g([[tDescr]]), - ?line expect(11, noSuchName, 1, [{[tDescr], 'NULL'}]), - g([[tDescr2,0]]), - ?line expect(12, noSuchName, 1, [{[tDescr2,0], 'NULL'}]), - g([[tDescr3,0]]), - ?line expect(131, noSuchName, 1, [{[tDescr3,0], 'NULL'}]), - g([[tDescr4,0]]), - ?line expect(132, noSuchName, 1, [{[tDescr4,0], 'NULL'}]), - g([[sysDescr, 0], [tDescr,0]]), % Outside mibview - ?line expect(14, noSuchName, 2, [{[sysDescr, 0], 'NULL'}, - {[tDescr,0], 'NULL'}]), - g([[sysDescr,3]]), - ?line expect(15, noSuchName, 1, [{[sysDescr, 3], 'NULL'}]), - - %% 4.1.2:2 - g([[tTable]]), - ?line expect(20, noSuchName, 1, [{[tTable], 'NULL'}]), - g([[tEntry]]), - ?line expect(21, noSuchName, 1, [{[tEntry], 'NULL'}]), - - %% 4.1.2:3 - g([[tTooBig, 0]]), - ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), - - %% 4.1.2:4 - g([[tGenErr1, 0]]), - ?line expect(40, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), - g([[tGenErr2, 0]]), - ?line expect(41, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), - g([[sysDescr, 0], [tGenErr3, 0]]), - ?line expect(42, genErr, 2, [{[sysDescr, 0], 'NULL'}, - {[tGenErr3, 0], 'NULL'}]). - - -v1_get_next_p() -> - %% 4.1.3:1 - gn([[1,3,7,1]]), - ?line expect(10, noSuchName, 1, [{[1,3,7,1], 'NULL'}]), - gn([[tDescr2]]), - ?line expect(11, tooBig, 0, any), - - %% 4.1.3:2 - gn([[tTooBig]]), - io:format("We currently don't handle tooBig correct!!!\n"), -% ?line expect(20, tooBig, 0, [{[tTooBig], 'NULL'}]), - ?line expect(20, tooBig, 0, any), - - %% 4.1.3:3 - gn([[tGenErr1]]), -% ?line expect(40, genErr, 1, [{[tGenErr1], 'NULL'}]), - ?line expect(40, genErr, 1, any), - gn([[tGenErr2]]), -% ?line expect(41, genErr, 1, [{[tGenErr2], 'NULL'}]), - ?line expect(41, genErr, 1, any), - gn([[sysDescr], [tGenErr3]]), -% ?line expect(42, genErr, 2, [{[sysDescr], 'NULL'}, -% {[tGenErr3], 'NULL'}]). - ?line expect(42, genErr, 2, any). - -v1_set_p() -> - %% 4.1.5:1 - s([{[1,3,7,0], i, 4}]), - ?line expect(10, noSuchName, 1, [{[1,3,7,0], 4}]), - s([{[tDescr,0], s, "outside mibview"}]), - ?line expect(11, noSuchName, 1, [{[tDescr,0], "outside mibview"}]), - s([{[tDescr3,0], s, "read-only"}]), - ?line expect(12, noSuchName, 1, [{[tDescr3,0], "read-only"}]), - s([{[tDescr3], s, "noSuchObject"}]), - ?line expect(13, noSuchName, 1, [{[tDescr3], "noSuchObject"}]), - s([{[tDescr3,1], s, "noSuchInstance"}]), - ?line expect(14, noSuchName, 1, [{[tDescr3,1], "noSuchInstance"}]), - s([{[tDescr2,0], s, "inconsistentName"}]), - ?line expect(15, noSuchName, 1, [{[tDescr2,0], "inconsistentName"}]), - - %% 4.1.5:2 - s([{[tDescr2, 0], i, 4}]), - ?line expect(20, badValue, 1, [{[tDescr2, 0], 4}]), - s([{[tDescr2, 0], s, "badValue"}]), - ?line expect(21, badValue, 1, [{[tDescr2, 0], "badValue"}]), - - %% 4.1.5:3 - %% The standard is quite incorrect here. The resp pdu was too big. In - %% the resp pdu, we have the original vbs. In the tooBig pdu we still - %% have to original vbs => the tooBig pdu is too big as well!!! It - %% may not get it to the manager, unless the agent uses 'NULL' instead - %% of the std-like original value. - s([{[tTooBig, 0], s, ?tooBigStr}]), - %% according to std: -% ?line expect(30, tooBig, 0, [{[tTooBig, 0], ?tooBigStr}]), - ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), - - %% 4.1.5:4 - s([{[tDescr2, 0], s, "is_set_ok_fail"}]), - ?line expect(40, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]), - s([{[tDescr2, 0], s, "commit_fail"}]), - ?line expect(41, genErr, 1, [{[tDescr2, 0], "commit_fail"}]). - -%% Req. Test2 -v2_proc() -> - %% According to RFC1905. - %% Template:
: - ?DBG("v2_proc -> entry",[]), - v2_get_p(), - v2_get_next_p(), - v2_get_bulk_p(), - v2_set_p(). - -v2_get_p() -> - %% 4.2.1:2 - ?DBG("v2_get_p -> entry",[]), - g([[test2]]), - ?line expect(10, [{[test2], noSuchObject}]), - g([[tDescr]]), - ?line expect(11, [{[tDescr], noSuchObject}]), - g([[tDescr4,0]]), - ?line expect(12, [{[tDescr4,0], noSuchObject}]), - g([[sysDescr, 0], [tDescr,0]]), % Outside mibview - ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}, - {[tDescr,0], noSuchObject}]), - g([[tTable]]), - ?line expect(14, [{[tTable], noSuchObject}]), - g([[tEntry]]), - ?line expect(15, [{[tEntry], noSuchObject}]), - - %% 4.2.1:3 - g([[tDescr2,0]]), %% instrum ret noSuchName!!! - ?line expect(20, [{[tDescr2,0], noSuchInstance}]), - g([[tDescr3,0]]), - ?line expect(21, [{[tDescr3,0], noSuchInstance}]), - g([[sysDescr,3]]), - ?line expect(22, [{[sysDescr, 3], noSuchInstance}]), - g([[tIndex,1]]), - ?line expect(23, [{[tIndex, 1], noSuchInstance}]), - - %% 4.2.1 - any other error: genErr - g([[tGenErr1, 0]]), - ?line expect(30, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), - g([[tGenErr2, 0]]), - ?line expect(31, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), - g([[sysDescr, 0], [tGenErr3, 0]]), - ?line expect(32, genErr, 2, [{[sysDescr, 0], 'NULL'}, - {[tGenErr3, 0], 'NULL'}]), - - %% 4.2.1 - tooBig - g([[tTooBig, 0]]), - ?line expect(40, tooBig, 0, []). - - -v2_get_next_p() -> - %% 4.2.2:2 - ?DBG("v2_get_next_p -> entry",[]), - gn([[1,3,7,1]]), - ?line expect(10, [{[1,3,7,1], endOfMibView}]), - gn([[sysDescr], [1,3,7,1]]), - ?line expect(11, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}]), - gn([[tCnt2, 1]]), - ?line expect(12, [{[tCnt2,2], 100}]), - gn([[tCnt2, 2]]), - ?line expect(12, [{[tCnt2,2], endOfMibView}]), - - %% 4.2.2 - any other error: genErr - gn([[tGenErr1]]), - ?line expect(20, genErr, 1, [{[tGenErr1], 'NULL'}]), - gn([[tGenErr2]]), - ?line expect(21, genErr, 1, [{[tGenErr2], 'NULL'}]), - gn([[sysDescr], [tGenErr3]]), - ?line expect(22, genErr, 2, [{[sysDescr], 'NULL'}, - {[tGenErr3], 'NULL'}]), - - %% 4.2.2 - tooBig - gn([[tTooBig]]), - ?line expect(20, tooBig, 0, []). - -v2_get_bulk_p() -> - %% 4.2.3 - ?DBG("v2_get_bulk_p -> entry",[]), - gb(1, 1, []), - ?line expect(10, []), - gb(-1, 1, []), - ?line expect(11, []), - gb(-1, -1, []), - ?line expect(12, []), - gb(-1, -1, []), - ?line expect(13, []), - gb(2, 0, [[sysDescr], [1,3,7,1]]), - ?line expect(14, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}]), - gb(1, 2, [[sysDescr], [1,3,7,1]]), - ?line expect(15, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}]), - gb(0, 2, [[sysDescr], [1,3,7,1]]), - ?line expect(16, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}, - {[sysObjectID, 0], [1,2,3]}, - {[1,3,7,1], endOfMibView}]), - - gb(2, 2, [[sysDescr], [1,3,7,1], [sysDescr], [1,3,7,1]]), - ?line expect(17, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}, - {[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}, - {[sysObjectID, 0], [1,2,3]}, - {[1,3,7,1], endOfMibView}]), - - gb(1, 2, [[sysDescr], [sysDescr], [tTooBig]]), - ?line expect(18, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[sysDescr, 0], "Erlang SNMP agent"}]), - - gb(1,12, [[tDescr2], [sysDescr]]), % next one after tDescr2 is tTooBig. - ?line expect(19, []), - - gb(2,2, [[sysDescr], [sysObjectID], [tGenErr1], [sysDescr]]), - ?line expect(20, genErr, 3, [{[sysDescr], 'NULL'}, - {[sysObjectID], 'NULL'}, - {[tGenErr1], 'NULL'}, - {[sysDescr], 'NULL'}]), - gb(0, 2, [[tCnt2, 1]]), - ?line expect(21, [{[tCnt2,2], 100}, - {[tCnt2,2], endOfMibView}]). - - -v2_set_p() -> - %% 4.2.5:1 - ?DBG("v2_set_p -> entry",[]), - s([{[1,3,7,0], i, 4}]), - ?line expect(10, noAccess, 1, [{[1,3,7,0], 4}]), - s([{[tDescr,0], s, "outside mibview"}]), - ?line expect(11, noAccess, 1, [{[tDescr,0], "outside mibview"}]), - - %% 4.2.5:2 - s([{[1,3,6,1,0], s, "noSuchObject"}]), - ?line expect(20, notWritable, 1, [{[1,3,6,1,0], "noSuchObject"}]), - - %% 4.2.5:3 - s([{[tDescr2, 0], i, 4}]), - ?line expect(30, wrongType, 1, [{[tDescr2, 0], 4}]), - s([{[tDescr2, 0], s, "badValue"}]), - ?line expect(31, badValue, 1, [{[tDescr2, 0], "badValue"}]), - - %% 4.2.5:4 - s([{[tStr, 0], s, ""}]), - ?line expect(40, wrongLength, 1, [{[tStr, 0], ""}]), - s([{[tStr, 0], s, "12345"}]), - ?line expect(40, wrongLength, 1, [{[tStr, 0], "12345"}]), - - %% 4.2.5:5 - N/A - - %% 4.2.5:6 - s([{[tInt1, 0], i, 0}]), - ?line expect(60, wrongValue, 1, [{[tInt1, 0], 0}]), - s([{[tInt1, 0], i, 5}]), - ?line expect(61, wrongValue, 1, [{[tInt1, 0], 5}]), - s([{[tInt2, 0], i, 0}]), - ?line expect(62, wrongValue, 1, [{[tInt2, 0], 0}]), - s([{[tInt2, 0], i, 5}]), - ?line expect(63, wrongValue, 1, [{[tInt2, 0], 5}]), - s([{[tInt3, 0], i, 5}]), - ?line expect(64, wrongValue, 1, [{[tInt3, 0], 5}]), - - %% 4.2.5:7 - s([{[tDescrX, 1, 1], s, "noCreation"}]), - ?line expect(70, noCreation, 1, [{[tDescrX, 1, 1], "noCreation"}]), - - %% 4.2.5:8 - s([{[tDescrX, 1, 2], s, "inconsistentName"}]), - ?line expect(80, inconsistentName, 1, - [{[tDescrX, 1, 2], "inconsistentName"}]), - - %% 4.2.5:9 - s([{[tCnt, 1, 2], i, 5}]), - ?line expect(90, notWritable, 1, [{[tCnt, 1, 2], 5}]), - s([{[tDescr3,0], s, "read-only"}]), - ?line expect(90, notWritable, 1, [{[tDescr3,0], "read-only"}]), - - %% 4.2.5:10 - s([{[tDescr2,0], s, "inconsistentValue"}]), - ?line expect(100, inconsistentValue, 1, - [{[tDescr2,0], "inconsistentValue"}]), - - %% 4.2.5:11 - s([{[tDescr2,0], s, "resourceUnavailable"}]), - ?line expect(110, resourceUnavailable, 1, - [{[tDescr2,0],"resourceUnavailable"}]), - - %% 4.2.5:12 - s([{[tDescr2, 0], s, "is_set_ok_fail"}]), - ?line expect(120, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]). - - %% commitFailed and undoFailed is tested by the 'undo' case. - - -%% Req. OLD-SNMPEA-MIB -table_test() -> - io:format("Testing simple get, next and set on communityTable...~n"), -%% {[147,214,36,45], "public", 2, readWrite}. -%% {[147,214,36,45], "standard trap", 2, read}. - Key1c3 = [intCommunityViewIndex,get(mip),is("public")], - Key2c3 = [intCommunityViewIndex,get(mip),is("standard trap")], - Key1c4 = [intCommunityAccess,get(mip),is("public")], - EndKey = [intCommunityEntry,[9],get(mip),is("public")], - gn([[intCommunityEntry]]), - ?line expect(7, [{Key1c3, 2}]), - gn([[intCommunityTable]]), - ?line expect(71, [{Key1c3, 2}]), - gn([[community]]), - ?line expect(72, [{Key1c3, 2}]), - gn([[otpSnmpeaMIB]]), - ?line expect(73, [{Key1c3, 2}]), - gn([[ericsson]]), - ?line expect(74, [{Key1c3, 2}]), - gn([Key1c3]), - ?line expect(8, [{Key2c3, 2}]), - gn([Key2c3]), - ?line expect(9, [{Key1c4, 2}]), - gn([EndKey]), - AgentIp = [intAgentIpAddress,0], - ?line expect(10, [{AgentIp, any}]), - g([Key1c3]), - ?line expect(11, [{Key1c3, 2}]), - g([EndKey]), - ?line ?v1_2(expect(12, noSuchName, 1, any), - expect(12, [{EndKey, noSuchObject}])), - - io:format("Testing row creation/deletion on communityTable...~n"), - NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], - NewKeyc4 = [intCommunityAccess,get(mip),is("test")], - NewKeyc5 = [intCommunityStatus,get(mip),is("test")], - s([{NewKeyc5, ?createAndGo}]), - ?line expect(14, ?v1_2(badValue, inconsistentValue), 1,any), - s([{NewKeyc5, ?createAndGo}, {NewKeyc3, 2}, {NewKeyc4, 2}]), - ?line expect(15, [{NewKeyc5, ?createAndGo},{NewKeyc3, 2}, {NewKeyc4, 2}]), - g([NewKeyc4]), - ?line expect(16, [{NewKeyc4, 2}]), - s([{NewKeyc5, ?destroy}]), - ?line expect(17, [{NewKeyc5, ?destroy}]), - s([{NewKeyc4, 2}]), - ?line expect(18, ?v1_2(noSuchName, inconsistentName), 1,[{NewKeyc4, 2}]), - s([{NewKeyc5, ?createAndWait}]), - ?line expect(19, [{NewKeyc5, ?createAndWait}]), - g([NewKeyc5]), - ?line expect(20, [{NewKeyc5, ?notReady}]), - s([{NewKeyc4, 2}]), - ?line expect(21, [{NewKeyc4, 2}]), - g([NewKeyc5]), - ?line expect(22, [{NewKeyc5, ?notReady}]), - s([{NewKeyc3, 2}]), - ?line expect(23, [{NewKeyc3, 2}]), - g([NewKeyc5]), - ?line expect(24, [{NewKeyc5, ?notInService}]), - s([{NewKeyc5, ?active}]), - ?line expect(25, [{NewKeyc5, ?active}]), - s([{NewKeyc5, ?destroy}]), - ?line expect(26, [{NewKeyc5, ?destroy}]), - s([{NewKeyc3, 3}]), - ?line expect(27, ?v1_2(noSuchName, inconsistentName), 1,[{NewKeyc3, 3}]), - otp_1128(). - -%% Req. system group -simple_standard_test() -> - ?DBG("simple_standard_test -> entry",[]), - gn([[1,1]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3]]), - ?line expect(11, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6]]), - ?line expect(12, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6,1]]), - ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6,1,2]]), - ?line expect(14, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6,1,2,1]]), - ?line expect(15, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6,1,2,1,1]]), - ?line expect(16, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[sysDescr]]), - ?line expect(17, [{[sysDescr,0], "Erlang SNMP agent"}]), - g([[sysDescr,0]]), - ?line expect(2, [{[sysDescr,0], "Erlang SNMP agent"}]), - g([[sysDescr]]), - ?line ?v1_2(expect(3, noSuchName, 1, any), - expect(3, [{[sysDescr], noSuchObject}])), - g([[1,6,7,0]]), - ?line ?v1_2(expect(41, noSuchName, 1, any), - expect(3, [{[1,6,7,0], noSuchObject}])), - gn([[1,13]]), - ?line ?v1_2(expect(4, noSuchName,1, any), - expect(4, [{[1,13], endOfMibView}])), - s([{[sysLocation, 0], "new_value"}]), - ?line expect(5, [{[sysLocation, 0], "new_value"}]), - g([[sysLocation, 0]]), - ?line expect(6, [{[sysLocation, 0], "new_value"}]), - io:format("Testing noSuchName and badValue...~n"), - s([{[sysServices,0], 3}]), - ?line expect(61, ?v1_2(noSuchName, notWritable), 1, any), - s([{[sysLocation, 0], i, 3}]), - ?line expect(62, ?v1_2(badValue, wrongType), 1, any), - ?DBG("simple_standard_test -> done",[]), - ok. - -%% This is run in the agent node -db_notify_client(suite) -> []; -db_notify_client(Config) when list(Config) -> - {SaNode, MgrNode, MibDir} = init_case(Config), - ?DBG("~n\tSaNode: ~p~n\tMgrNode: ~p~n\tMibDir: ~p", - [SaNode,MgrNode,MibDir]), - snmpa_local_db:register_notify_client(self(),?MODULE), - - %% This call (the manager) will issue to set operations, so - %% we expect to receive to notify(insert) calls. - try_test(db_notify_client_test), - - ?DBG("await first notify",[]), - receive - {db_notify_test_reply,insert} -> ?DBG("first notify received",[]),ok - end, - - ?DBG("await second notify",[]), - receive - {db_notify_test_reply,insert} -> ?DBG("second notify received",[]),ok - end, - - snmpa_local_db:unregister_notify_client(self()). - - -%% This is run in the manager node -db_notify_client_test() -> - ?DBG("set first new sysLocation",[]), - s([{[sysLocation, 0], "new_value"}]), - ?line expect(5, [{[sysLocation, 0], "new_value"}]), - - ?DBG("set second new sysLocation",[]), - s([{[sysLocation, 0], "new_value"}]), - ?line expect(5, [{[sysLocation, 0], "new_value"}]). - -notify(Pid,What) -> - ?DBG("notify(~p,~p) -> called",[Pid,What]), - Pid ! {db_notify_test_reply,What}. - - -%% Req: system group, OLD-SNMPEA-MIB, Klas1 -big_test() -> - ?DBG("big_test -> testing simple next/get/set @ master agent...",[]), - simple_standard_test(), - - ?DBG("big_test -> testing simple next/get/set @ subagent...",[]), - gn([[klas1]]), - ?line expect(1, [{[fname,0], ""}]), - g([[fname,0]]), - ?line expect(2, [{[fname,0], ""}]), - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - g([[fname,0]]), - ?line expect(4, [{[fname,0], "test set"}]), - - ?DBG("big_test -> " - "testing next from last instance in master to subagent...",[]), - gn([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(5, [{[fname,0], "test set"}]), - gn([[1,1], - [?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, - {[fname,0], "test set"}]), - s([{[fname,0], s, ""}]), - ?line expect(52, [{[fname,0], ""}]), - - table_test(), - - ?DBG("big_test -> adding one row in subagent table",[]), - _FTab = [friendsEntry], - s([{[friendsEntry, [2, 3]], s, "kompis3"}, - {[friendsEntry, [3, 3]], i, ?createAndGo}]), - ?line expect(6, [{[friendsEntry, [2, 3]], "kompis3"}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - g([[friendsEntry, [2, 3]], - [friendsEntry, [3, 3]]]), - ?line expect(7, [{[friendsEntry, [2, 3]], "kompis3"}, - {[friendsEntry, [3, 3]], ?active}]), - s([{[friendsEntry, [3, 3]], i, ?destroy}]), - ?line expect(8, [{[friendsEntry, [3, 3]], ?destroy}]), - - otp_1131(), - - ?DBG("big_test -> adding two rows in subagent table with special INDEX", - []), - s([{[kompissEntry, [1, 3]], s, "kompis3"}, - {[kompissEntry, [2, 3]], i, ?createAndGo}]), - ?line expect(9, [{[kompissEntry, [1, 3]], "kompis3"}, - {[kompissEntry, [2, 3]], ?createAndGo}]), - g([[kompissEntry, [1, 3]], - [kompissEntry, [2, 3]]]), - ?line expect(10, [{[kompissEntry, [1, 3]], "kompis3"}, - {[kompissEntry, [2, 3]], ?active}]), - gn([[kompissEntry, [1]], - [kompissEntry, [2]]]), - ?line expect(11, [{[kompissEntry, [1, 3]], "kompis3"}, - {[kompissEntry, [2, 3]], ?active}]), - s([{[kompissEntry, [1, 2]], s, "kompis3"}, - {[kompissEntry, [2, 2]], i, ?createAndGo}]), - ?line expect(12, [{[kompissEntry, [1, 2]], "kompis3"}, - {[kompissEntry, [2, 2]], ?createAndGo}]), - gn([[kompissEntry, [1, 1]], - [kompissEntry, [2, 1]]]), - ?line expect(13, [{[kompissEntry, [1, 2]], "kompis3"}, - {[kompissEntry, [2, 2]], ?active}]), - s([{[kompissEntry, [2, 3]], i, ?destroy}]), - ?line expect(14, [{[kompissEntry, [2, 3]], ?destroy}]), - s([{[kompissEntry, [2, 2]], i, ?destroy}]), - ?line expect(15, [{[kompissEntry, [2, 2]], ?destroy}]), - ?DBG("big_test -> done",[]), - ok. - -%% Req. system group, Klas2, OLD-SNMPEA-MIB -big_test_2() -> - p("Testing simple next/get/set @ master agent (2)..."), - simple_standard_test(), - - p("Testing simple next/get/set @ subagent (2)..."), - gn([[klas2]]), - ?line expect(1, [{[fname2,0], ""}]), - g([[fname2,0]]), - ?line expect(2, [{[fname2,0], ""}]), - s([{[fname2,0], s, "test set"}]), - ?line expect(3, [{[fname2,0], "test set"}]), - g([[fname2,0]]), - ?line expect(4, [{[fname2,0], "test set"}]), - - otp_1298(), - - p("Testing next from last object in master to subagent (2)..."), - gn([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(5, [{[fname2,0], "test set"}]), - gn([[1,1], - [?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, - {[fname2,0], "test set"}]), - - table_test(), - - p("Adding one row in subagent table (2)"), - _FTab = [friendsEntry2], - s([{[friendsEntry2, [2, 3]], s, "kompis3"}, - {[friendsEntry2, [3, 3]], i, ?createAndGo}]), - ?line expect(6, [{[friendsEntry2, [2, 3]], "kompis3"}, - {[friendsEntry2, [3, 3]], ?createAndGo}]), - g([[friendsEntry2, [2, 3]], - [friendsEntry2, [3, 3]]]), - ?line expect(7, [{[friendsEntry2, [2, 3]], "kompis3"}, - {[friendsEntry2, [3, 3]], ?active}]), - s([{[friendsEntry2, [3, 3]], i, ?destroy}]), - ?line expect(8, [{[friendsEntry2, [3, 3]], ?destroy}]), - - p("Adding two rows in subagent table with special INDEX (2)"), - s([{[kompissEntry2, [1, 3]], s, "kompis3"}, - {[kompissEntry2, [2, 3]], i, ?createAndGo}]), - ?line expect(9, [{[kompissEntry2, [1, 3]], "kompis3"}, - {[kompissEntry2, [2, 3]], ?createAndGo}]), - g([[kompissEntry2, [1, 3]], - [kompissEntry2, [2, 3]]]), - ?line expect(10, [{[kompissEntry2, [1, 3]], "kompis3"}, - {[kompissEntry2, [2, 3]], ?active}]), - gn([[kompissEntry2, [1]], - [kompissEntry2, [2]]]), - ?line expect(11, [{[kompissEntry2, [1, 3]], "kompis3"}, - {[kompissEntry2, [2, 3]], ?active}]), - s([{[kompissEntry2, [1, 2]], s, "kompis3"}, - {[kompissEntry2, [2, 2]], i, ?createAndGo}]), - ?line expect(12, [{[kompissEntry2, [1, 2]], "kompis3"}, - {[kompissEntry2, [2, 2]], ?createAndGo}]), - gn([[kompissEntry2, [1, 1]], - [kompissEntry2, [2, 1]]]), - ?line expect(13, [{[kompissEntry2, [1, 2]], "kompis3"}, - {[kompissEntry2, [2, 2]], ?active}]), - s([{[kompissEntry2, [2, 3]], i, ?destroy}]), - ?line expect(14, [{[kompissEntry2, [2, 3]], ?destroy}]), - s([{[kompissEntry2, [2, 2]], i, ?destroy}]), - ?line expect(15, [{[kompissEntry2, [2, 2]], ?destroy}]), - ok. - -%% Req. Test1 -multi_threaded_test() -> - p("Testing multi threaded agent..."), - g([[multiStr,0]]), - Pid = get_multi_pid(), - g([[sysUpTime,0]]), - ?line expect(1, [{[sysUpTime,0], any}]), - s([{[sysLocation, 0], s, "pelle"}]), - ?line expect(2, [{[sysLocation, 0], "pelle"}]), - Pid ! continue, - ?line expect(3, [{[multiStr,0], "ok"}]), - - s([{[multiStr, 0], s, "block"}]), - Pid2 = get_multi_pid(), - g([[sysUpTime,0]]), - ?line expect(4, [{[sysUpTime,0], any}]), - g([[multiStr,0]]), - Pid3 = get_multi_pid(), - g([[sysUpTime,0]]), - ?line expect(5, [{[sysUpTime,0], any}]), - s([{[sysLocation, 0], s, "kalle"}]), - Pid3 ! continue, - ?line expect(6, [{[multiStr,0], "ok"}]), - Pid2 ! continue, - ?line expect(7, [{[multiStr,0], "block"}]), - ?line expect(8, [{[sysLocation,0], "kalle"}]). - -%% Req. Test1, TestTrapv2 -mt_trap_test(MA) -> - snmpa:send_trap(MA, testTrapv22, "standard trap"), - ?line expect(1, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - - snmpa:send_trap(MA, mtTrap, "standard trap"), - Pid = get_multi_pid(), - g([[sysUpTime,0]]), - ?line expect(2, [{[sysUpTime,0], any}]), - snmpa:send_trap(MA, testTrapv22, "standard trap"), - ?line expect(3, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - Pid ! continue, - ?line expect(4, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?testTrap ++ [2]}, - {[multiStr,0], "ok"}]). - - -get_multi_pid() -> - get_multi_pid(10). -get_multi_pid(0) -> - ?line ?FAIL(no_global_name); -get_multi_pid(N) -> - sleep(1000), - case global:whereis_name(snmp_multi_tester) of - Pid when pid(Pid) -> Pid; - _ -> get_multi_pid(N-1) - end. - -%% Req. Test1 -types_v2_test() -> - p("Testing v2 types..."), - - s([{[bits1,0], 2#10}]), - ?line expect(1, [{[bits1,0], ?str(2#10)}]), - g([[bits1,0]]), - ?line expect(2, [{[bits1,0], ?str(2#101)}]), - - s([{[bits2,0], 2#11000000110}]), - ?line expect(3, [{[bits2,0], ?str(2#11000000110)}]), - g([[bits2,0]]), - ?line expect(4, [{[bits2,0], ?str(2#11000000110)}]), - - g([[bits3,0]]), - ?line expect(50, genErr, 1, any), - - g([[bits4,0]]), - ?line expect(51, genErr, 1, any), - - s([{[bits1,0], s, [2#10]}]), - ?line expect(6, ?v1_2(badValue, wrongValue), 1, any), - - s([{[bits2,0], 2#11001001101010011}]), - ?line expect(7, ?v1_2(badValue, wrongValue), 1, any). - - -%% Req. Test1 -implied_test(MA) -> - ?LOG("implied_test -> start",[]), - p("Testing IMPLIED..."), - - snmpa:verbosity(MA,trace), - snmpa:verbosity(MA,trace), - - %% Create two rows, check that they are get-nexted in correct order. - Idx1 = "apa", - Idx2 = "qq", - ?DBG("implied_test -> (send) create row 1 '~s' in table 1",[Idx1]), - s([{[testStatus, Idx1], i, ?createAndGo}, {[testDescr, Idx1],s,"row 1"}]), - ?line expect(1, [{[testStatus, Idx1], ?createAndGo}, - {[testDescr, Idx1], "row 1"}]), - ?DBG("implied_test -> (send) create row 2 '~s' in table 1",[Idx2]), - s([{[testStatus, Idx2], i, ?createAndGo}, {[testDescr, Idx2],s,"row 2"}]), - ?line expect(2, [{[testStatus, Idx2], ?createAndGo}, - {[testDescr, Idx2], "row 2"}]), - ?DBG("implied_test -> get-next(testDescr)",[]), - gn([[testDescr]]), - ?line expect(3, [{[testDescr,Idx1], "row 1"}]), - ?DBG("implied_test -> get-next(testDescr) of row 1",[]), - gn([[testDescr,Idx1]]), - ?line expect(4, [{[testDescr,Idx2], "row 2"}]), - - % Delete the rows - ?DBG("implied_test -> (send) delete row 1 '~s' from table 1",[Idx1]), - s([{[testStatus, Idx1], i, ?destroy}]), - ?line expect(5, [{[testStatus, Idx1], ?destroy}]), - ?DBG("implied_test -> (send) delete row 2 '~s' from table 1",[Idx2]), - s([{[testStatus, Idx2], i, ?destroy}]), - ?line expect(6, [{[testStatus, Idx2], ?destroy}]), - - %% Try the same in other table - Idx3 = [1, "apa"], - Idx4 = [1, "qq"], - ?DBG("implied_test -> (send) create row 1 '~s' in table 2",[Idx3]), - s([{[testStatus2, Idx3], i, ?createAndGo}, {[testDescr2,Idx3],s,"row 1"}]), - ?line expect(1, [{[testStatus2, Idx3], ?createAndGo}, - {[testDescr2, Idx3], "row 1"}]), - ?DBG("implied_test -> (send) create row 2 '~s' in table 2",[Idx4]), - s([{[testStatus2, Idx4], i, ?createAndGo}, {[testDescr2,Idx4],s,"row 2"}]), - ?line expect(2, [{[testStatus2, Idx4], ?createAndGo}, - {[testDescr2, Idx4], "row 2"}]), - ?DBG("implied_test -> get-next(testDescr2)",[]), - gn([[testDescr2]]), - ?line expect(3, [{[testDescr2,Idx3], "row 1"}]), - ?DBG("implied_test -> get-next(testDescr2) of row 1",[]), - gn([[testDescr2,Idx3]]), - ?line expect(4, [{[testDescr2,Idx4], "row 2"}]), - - % Delete the rows - ?DBG("implied_test -> (send) delete row 1 '~s' from table 2",[Idx3]), - s([{[testStatus2, Idx3], i, ?destroy}]), - ?line expect(5, [{[testStatus2, Idx3], ?destroy}]), - ?DBG("implied_test -> (send) delete row 2 '~s' from table 2",[Idx4]), - s([{[testStatus2, Idx4], i, ?destroy}]), - ?line expect(6, [{[testStatus2, Idx4], ?destroy}]), - - snmpa:verbosity(MA,log), - - ?LOG("implied_test -> done",[]). - - - -%% Req. Test1 -sparse_table_test() -> - p("Testing sparse table..."), - - %% Create two rows, check that they are get-nexted in correct order. - Idx1 = 1, - Idx2 = 2, - s([{[sparseStatus, Idx1], i, ?createAndGo}, - {[sparseDescr, Idx1], s, "row 1"}]), - ?line expect(1, [{[sparseStatus, Idx1], ?createAndGo}, - {[sparseDescr, Idx1], "row 1"}]), - s([{[sparseStatus, Idx2], i, ?createAndGo}, - {[sparseDescr, Idx2], s, "row 2"}]), - ?line expect(2, [{[sparseStatus, Idx2], ?createAndGo}, - {[sparseDescr, Idx2], "row 2"}]), - ?v1_2(gn([[sparseIndex], [sparseDescr,Idx1], [sparseDescr,Idx2], - [sparseStatus,Idx1], [sparseStatus,Idx2]]), - gb(0,5,[[sparseIndex]])), - ?line expect(3, [{[sparseDescr,Idx1], "row 1"}, - {[sparseDescr,Idx2], "row 2"}, - {[sparseStatus,Idx1], ?active}, - {[sparseStatus,Idx2], ?active}, - {[sparseStr,0], "slut"}]), - % Delete the rows - s([{[sparseStatus, Idx1], i, ?destroy}]), - ?line expect(4, [{[sparseStatus, Idx1], ?destroy}]), - s([{[sparseStatus, Idx2], i, ?destroy}]), - ?line expect(5, [{[sparseStatus, Idx2], ?destroy}]). - - -%% Req. Test1 -cnt_64_test(MA) -> - ?LOG("start cnt64 test (~p)",[MA]), - snmpa:verbosity(MA,trace), - ?LOG("start cnt64 test",[]), - p("Testing Counter64, and at the same time, RowStatus is not last column"), - - ?DBG("get cnt64",[]), - g([[cnt64,0]]), - ?DBG("await response",[]), - ?line ?v1_2(expect(1, noSuchName, 1, any), - expect(1, [{[cnt64,0],18446744073709551615}])), - ?DBG("get-next cnt64",[]), - gn([[cnt64]]), - ?DBG("await response",[]), - ?line ?v1_2(expect(2, [{[cnt64Str,0], "after cnt64"}]), - expect(2, [{[cnt64,0],18446744073709551615}])), - ?DBG("send cntTrap",[]), - snmpa:send_trap(MA,cntTrap,"standard trap",[{sysContact,"pelle"}, - {cnt64, 10}, - {sysLocation, "here"}]), - ?DBG("await response",[]), - ?line ?v1_2(expect(3, trap, [test], 6, 1, [{[sysContact,0], "pelle"}, - {[sysLocation,0], "here"}]), - expect(3, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?testTrap ++ [1]}, - {[sysContact,0], "pelle"}, - {[cnt64,0], 10}, - {[sysLocation,0], "here"}])), - - %% Create two rows, check that they are get-nexted in correct order. - Idx1 = 1, - Idx2 = 2, - ?DBG("create row (cntStatus): ~p",[Idx1]), - s([{[cntStatus, Idx1], i, ?createAndGo}]), - ?DBG("await response",[]), - ?line expect(1, [{[cntStatus, Idx1], ?createAndGo}]), - ?DBG("create row (cntStatus): ~p",[Idx2]), - s([{[cntStatus, Idx2], i, ?createAndGo}]), - ?DBG("await response",[]), - ?line expect(2, [{[cntStatus, Idx2], ?createAndGo}]), - - ?DBG("get-next (cntIndex)",[]), - gn([[cntIndex]]), - ?DBG("await response",[]), - ?line ?v1_2(expect(3, [{[cntStatus,Idx1], ?active}]), - expect(3, [{[cntCnt,Idx1], 0}])), - % Delete the rows - ?DBG("delete row (cntStatus): ~p",[Idx1]), - s([{[cntStatus, Idx1], i, ?destroy}]), - ?DBG("await response",[]), - ?line expect(4, [{[cntStatus, Idx1], ?destroy}]), - ?DBG("delete row (cntStatus): ~p",[Idx2]), - s([{[cntStatus, Idx2], i, ?destroy}]), - ?DBG("await response",[]), - ?line expect(5, [{[cntStatus, Idx2], ?destroy}]), - catch snmpa:verbosity(MA,log), - ?DBG("done",[]), - ok. - -%% Req. Test1 -opaque_test() -> - p("Testing Opaque datatype..."), - g([[opaqueObj,0]]), - ?line expect(1, [{[opaqueObj,0], "opaque-data"}]). - -%% Req. OLD-SNMPEA-MIB -api_test(MaNode) -> - ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, - [intAgentIpAddress]), - ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, - oid_to_name, [OID]), - ?line false = rpc:call(MaNode, snmp, name_to_oid, [intAgentIpAddres]), - ?line false = rpc:call(MaNode, snmp, oid_to_name, - [[1,5,32,3,54,3,3,34,4]]), - ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, - [intViewType, excluded]), - ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, - [intViewType, 2]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, [intViewType, exclude]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [intAgentIpAddress, exclude]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [intAgentIpAddre, exclude]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [intViewType, 3]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddress, 2]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddre, 2]), - ?line {value, active} = rpc:call(MaNode, snmp, - int_to_enum, ['RowStatus', ?active]), - ?line {value, ?destroy} = rpc:call(MaNode, snmp, - enum_to_int, ['RowStatus', destroy]), - ?line false = rpc:call(MaNode, snmp, - enum_to_int, ['RowStatus', xxxdestroy]), - ?line false = rpc:call(MaNode, snmp, - enum_to_int, ['xxRowStatus', destroy]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, ['RowStatus', 25]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, ['xxRowStatus', 1]), - ?line case snmp:date_and_time() of - List when list(List), length(List) == 8 -> ok; - List when list(List), length(List) == 11 -> ok - end. - -%% Req. Klas3 -api_test2() -> - g([[fname3,0]]), - ?line expect(1, [{[fname3,0], "ok"}]), - g([[fname4,0]]), - ?line expect(2, [{[fname4,0], 1}]). - -api_test3() -> - g([[fname3,0]]), - ?line expect(1, [{[fname3,0], "ok"}]). - - -unreg_test() -> - gn([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(1, [{[snmpInPkts, 0], any}]). - -load_test() -> - gn([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(1, [{[fname,0], ""}]). - -%% Req. Klas1 -load_test_sa() -> - gn([[?v1_2(sysServices,sysORLastChange), 0]]), - ?line expect(1, [{[fname,0], any}]). - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_get() -> - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - g([[sysDescr,0], Key1c4, [fname,0],Key1c3, - [sysName,0]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[fname,0], "test set"}, - {Key1c3, 2}, - {[sysName,0], "test"}]), - g([[1,3,7,1], Key1c4, [sysDescr,0], [1,3,7,2], Key1c3, [sysDescr,0]]), - ?line ?v1_2(expect(2, noSuchName, [1,4], any), - expect(2, [{[1,3,7,1], noSuchObject}, - {Key1c4, 2}, - {[sysDescr,0], "Erlang SNMP agent"}, - {[1,3,7,2], noSuchObject}, - {Key1c3, 2}, - {[sysDescr,0], "Erlang SNMP agent"}])). - -%% Req. v1, system group, Klas1, OLD-SNMPEA-MIB, *ej* Klas3. -do_mul_get_err() -> - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - g([[sysDescr,0],Key1c4,[fname,0], Key1c3, [sysName,2]]), - ?line ?v1_2(expect(1, noSuchName, 5, any), - expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[fname,0], "test set"}, - {Key1c3, 2}, - {[sysName,2], noSuchInstance}])), - g([[sysDescr,0],Key1c4,[fname3,0], Key1c3, [sysName,1]]), - ?line ?v1_2(expect(1, noSuchName, [3,5], any), - expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[fname3,0], noSuchObject}, - {Key1c3, 2}, - {[sysName,1], noSuchInstance}])). - - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_next() -> - Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], - Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - gn([[sysDescr], Key1c4s, [fname],Key1c3s,[sysName]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, {[fname,0], "test set"}, - {Key1c3, 2}, {[sysName,0], "test"}]). - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_next_err() -> - Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], - Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - gn([[sysDescr], Key1c4s, [1,3,6,999], [fname],[1,3,90], Key1c3s,[sysName]]), - ?line ?v1_2(expect(1, noSuchName, [3,5], any), - expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[1,3,6,999], endOfMibView}, - {[fname,0], "test set"}, - {[1,3,90], endOfMibView}, - {Key1c3, 2}, - {[sysName,0], "test"}])). - - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_set() -> - p("Adding one row in subagent table, and one in master table"), - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - s([{[friendsEntry, [2, 3]], "kompis3"}, - {NewKeyc3, 2}, - {[sysLocation,0], "new_value"}, - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - ?line expect(1, [{[friendsEntry, [2, 3]], "kompis3"}, - {NewKeyc3, 2}, - {[sysLocation,0], "new_value"}, - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - g([[friendsEntry, [2, 3]], - [sysLocation,0], - [friendsEntry, [3, 3]]]), - ?line expect(2, [{[friendsEntry, [2, 3]], "kompis3"}, - {[sysLocation,0], "new_value"}, - {[friendsEntry, [3, 3]], ?active}]), - g([NewKeyc4]), - ?line expect(3, [{NewKeyc4, 2}]), - s([{[friendsEntry, [3, 3]], ?destroy}, - {NewKeyc5, ?destroy}]), - ?line expect(4, [{[friendsEntry, [3, 3]], ?destroy}, - {NewKeyc5, ?destroy}]). - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_set_err() -> - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - p("Adding one row in subagent table, and one in master table"), - s([{[friendsEntry, [2, 3]], s, "kompis3"}, - {NewKeyc3, 2}, - {[sysUpTime,0], 45}, % sysUpTime (readOnly) - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - ?line expect(1, ?v1_2(noSuchName, notWritable), 3, any), - g([[friendsEntry, [2, 3]]]), - ?line ?v1_2(expect(2, noSuchName, 1, any), - expect(2, [{[friendsEntry, [2,3]], noSuchInstance}])), - g([NewKeyc4]), - ?line ?v1_2(expect(3, noSuchName, 1, any), - expect(3, [{NewKeyc4, noSuchInstance}])). - -%% Req. SA-MIB -sa_mib() -> - g([[sa, [2,0]]]), - ?line expect(1, [{[sa, [2,0]], 3}]), - s([{[sa, [1,0]], s, "sa_test"}]), - ?line expect(2, [{[sa, [1,0]], "sa_test"}]). - -ma_trap1(MA) -> - snmpa:send_trap(MA, testTrap2, "standard trap"), - ?line expect(1, trap, [system], 6, 1, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}]), - snmpa:send_trap(MA, testTrap1, "standard trap"), - ?line expect(2, trap, [1,2,3] , 1, 0, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}]). - -ma_trap2(MA) -> - snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). - -ma_v2_2_v1_trap(MA) -> - snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). - -ma_v2_2_v1_trap2(MA) -> - snmpa:send_trap(MA,linkUp,"standard trap",[{ifIndex, [1], 1}, - {ifAdminStatus, [1], 1}, - {ifOperStatus, [1], 2}]), - ?line expect(3, trap, [1,2,3], 3, 0, [{[ifIndex, 1], 1}, - {[ifAdminStatus, 1], 1}, - {[ifOperStatus, 1], 2}]). - -sa_trap1(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap"), - ?line expect(4, trap, [ericsson], 6, 1, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}]). - -sa_trap2(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), - ?line expect(5, trap, [ericsson], 6, 1, [{[system, [4,0]], - "pelle"}, - {[sa, [1,0]], "sa_test"}]). - -sa_trap3(SA) -> - snmpa:send_trap(SA, saTrap2, "standard trap", - [{intViewSubtree, [4], [1,2,3,4]}]), - ?line expect(6, trap, [ericsson], 6, 2, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}, - {[intViewSubtree,4],[1,2,3,4]}]). - -ma_v2_trap1(MA) -> - ?DBG("ma_v2_traps -> entry with MA = ~p => " - "send standard trap: testTrapv22",[MA]), - snmpa:send_trap(MA, testTrapv22, "standard trap"), - ?line expect(1, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - ?DBG("ma_v2_traps -> send standard trap: testTrapv21",[]), - snmpa:send_trap(MA, testTrapv21, "standard trap"), - ?line expect(2, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?snmp ++ [1]}]). - -ma_v2_trap2(MA) -> - snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}, - {[system, [4,0]], "pelle"}]). - -%% Note: This test case takes a while... actually a couple of minutes. -ma_v2_inform1(MA) -> - ?DBG("ma_v2_inform -> entry with MA = ~p => " - "send notification: testTrapv22",[MA]), - ?line snmpa:send_notification(MA, testTrapv22, no_receiver, "standard inform", []), - ?line expect(1, {inform, true}, - [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - - ?DBG("ma_v2_inform -> send notification: testTrapv22",[]), - snmpa:send_notification(MA, testTrapv22, {tag1, self()}, - "standard inform", []), - ?line expect(1, {inform, true}, - [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - ?DBG("ma_v2_inform -> await targets",[]), - receive - {snmp_targets, tag1, [_]} -> - ok; - {snmp_targets, tag1, Addrs1} -> - ?line ?FAIL({bad_addrs, Addrs1}) - after - 5000 -> - ?ERR("ma_v2_inform1 -> awaiting snmp_targets(tag1) timeout",[]), - ?line ?FAIL(nothing_at_all) - end, - ?DBG("ma_v2_inform -> await notification",[]), - receive - {snmp_notification, tag1, {got_response, _}} -> - ok; - {snmp_notification, tag1, {no_response, _}} -> - ?line ?FAIL(no_response) - after - 20000 -> - ?ERR("ma_v2_inform1 -> " - "awaiting snmp_notification(tag1) timeout",[]), - ?line ?FAIL(nothing_at_all) - end, - - %% - %% -- The rest is possibly erroneous... - %% - - ?DBG("ma_v2_inform -> send notification: testTrapv22",[]), - snmpa:send_notification(MA, testTrapv22, {tag2, self()}, - "standard inform", []), - ?line expect(2, {inform, false}, - [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - ?DBG("ma_v2_inform -> await targets",[]), - receive - {snmp_targets, tag2, [_]} -> - ok; - {snmp_targets, tag2, Addrs2} -> - ?ERR("ma_v2_inform1 -> awaiting snmp_targets(tag2) timeout",[]), - ?line ?FAIL({bad_addrs, Addrs2}) - after - 5000 -> - ?line ?FAIL(nothing_at_all) - end, - ?DBG("ma_v2_inform -> await notification",[]), - receive - {snmp_notification, tag2, {got_response, _}} -> - ?line ?FAIL(got_response); - {snmp_notification, tag2, {no_response, _}} -> - ok - after - 240000 -> - ?ERR("ma_v2_inform1 -> " - "awaiting snmp_notification(tag2) timeout",[]), - ?line ?FAIL(nothing_at_all) - end. - - -ma_v1_2_v2_trap(MA) -> - snmpa:send_trap(MA,linkDown,"standard trap",[{ifIndex, [1], 1}]), - ?line expect(2, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?snmpTraps ++ [3]}, - {[ifIndex, 1], 1}, - {[snmpTrapEnterprise, 0], [1,2,3]}]). - - -ma_v1_2_v2_trap2(MA) -> - snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}, - {[system, [4,0]], "pelle"}, - {[snmpTrapEnterprise, 0], ?system}]). - - -sa_v1_2_v2_trap1(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap"), - ?line expect(4, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, - {[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}, - {[snmpTrapEnterprise, 0], ?ericsson}]). - -sa_v1_2_v2_trap2(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), - ?line expect(4, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, - {[system, [4,0]], "pelle"}, - {[sa, [1,0]], "sa_test"}, - {[snmpTrapEnterprise, 0], ?ericsson}]). - - -sa_v1_2_v2_trap3(SA) -> - snmpa:send_trap(SA, saTrap2, "standard trap", - [{intViewSubtree, [4], [1,2,3,4]}]), - ?line expect(4, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?ericsson ++ [0, 2]}, - {[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}, - {[intViewSubtree,4],[1,2,3,4]}, - {[snmpTrapEnterprise, 0], ?ericsson}]). - - -%% Req. SA-MIB, OLD-SNMPEA-MIB -sa_errs_bad_value() -> - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - s([{NewKeyc3, 2}, - {[sa, [2,0]], 5}, % badValue (i is_set_ok) - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}]), - ?line expect(1, badValue, 2, any), - s([{NewKeyc3, 2}, - {[sa, [2,0]], 6}, % wrongValue (i is_set_ok) - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}]), - ?line expect(1, ?v1_2(badValue, wrongValue), 2, any), - g([NewKeyc4]), - ?line ?v1_2(expect(2, noSuchName, 1, any), - expect(2, [{NewKeyc4, noSuchInstance}])). - -%% Req. SA-MIB, OLD-SNMPEA-MIB -sa_errs_gen_err() -> - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - s([{NewKeyc3, 2},{NewKeyc4, 2}, - {NewKeyc5, ?createAndGo}, {[sa, [3,0]], 5}]), - ?line expect(1, genErr, 4, any), -% The row might have been added; we don't know. -% (as a matter of fact we do - it is added, because the agent -% first sets its own vars, and then th SAs. Lets destroy it. - s([{NewKeyc5, ?destroy}]), - ?line expect(2, [{NewKeyc5, ?destroy}]). - -%% Req. SA-MIB, OLD-SNMPEA-MIB -sa_too_big() -> - g([[sa, [4,0]]]), - ?line expect(1, tooBig). - -%% Req. Klas1, system group, snmp group (v1/v2) -next_across_sa() -> - gn([[sysDescr],[klas1,5]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {[snmpInPkts, 0], any}]). - -%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]). -> noError -%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]). -> {badValue, 2} -%% snmp_test_mgr:s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]). -> {genErr, 1} -%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]). -> {genErr, 1} -%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]). -> {genErr, 1} -%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]). -> {genErr, 2} -%% Req. Klas3, Klas4 -undo_test() -> - s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), - ?line expect(1, [{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), - s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]), - ?line expect(2, ?v1_2(badValue, inconsistentValue), 2, any), - s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]), - ?line expect(3, ?v1_2(genErr, undoFailed), 1, any), - s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]), - ?line expect(4, ?v1_2(genErr, commitFailed), 1, any), -% unfortunatly we don't know if we'll get undoFailed or commitFailed. -% it depends on which order the agent traverses the varbind list. -% s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]), -% ?line expect(5, ?v1_2(genErr, undoFailed), 1, any), - s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]), - ?line expect(6, genErr, 2, any). - -%% Req. Klas3, Klas4 -bad_return() -> - g([[fStatus4,4], - [fName4,4]]), - ?line expect(4, genErr, 2, any), - g([[fStatus4,5], - [fName4,5]]), - ?line expect(5, genErr, 1, any), - g([[fStatus4,6], - [fName4,6]]), - ?line expect(6, genErr, 2, any), - gn([[fStatus4,7], - [fName4,7]]), - ?line expect(7, genErr, 2, any), - gn([[fStatus4,8], - [fName4,8]]), - ?line expect(8, genErr, 1, any), - gn([[fStatus4,9], - [fName4,9]]), - ?line expect(9, genErr, 2, any). - - -%%%----------------------------------------------------------------- -%%% Test the implementation of standard mibs. -%%% We should *at least* try to GET all variables, just to make -%%% sure the instrumentation functions work. -%%% Note that many of the functions in the standard mib is -%%% already tested by the normal tests. -%%%----------------------------------------------------------------- - - - -%%----------------------------------------------------------------- -%% For this test, the agent is configured for v1. -%% o Test the counters and control objects in SNMP-STANDARD-MIB -%%----------------------------------------------------------------- -snmp_standard_mib(suite) -> []; -snmp_standard_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?DBG("snmp_standard_mib -> std_mib_init", []), - try_test(std_mib_init), - - ?DBG("snmp_standard_mib -> std_mib_a", []), - InBadVsns = try_test(std_mib_a), - put(vsn, v2), - ?DBG("snmp_standard_mib -> std_mib_read", []), - try_test(std_mib_read), - put(vsn, v1), - - ?DBG("snmp_standard_mib -> std_mib_b (~w)", [InBadVsns]), - Bad = try_test(std_mib_b, [InBadVsns]), - ?DBG("snmp_standard_mib -> std_mib_read (community: 'bad community')", []), - try_test(std_mib_read, [], [{community, "bad community"}]), - ?DBG("snmp_standard_mib -> std_mib_write (community: 'public')", []), - try_test(std_mib_write, [], [{community, "public"}]), - ?DBG("snmp_standard_mib -> std_mib_asn_err", []), - try_test(std_mib_asn_err), - ?DBG("snmp_standard_mib -> std_mib_c (~w)", [Bad]), - try_test(std_mib_c, [Bad]), - ?DBG("snmp_standard_mib -> std_mib_a", []), - try_test(standard_mib_a), - - ?DBG("snmp_standard_mib -> std_mib_finish", []), - try_test(std_mib_finish), - ?DBG("snmp_standard_mib -> std_mib_test_finish", []), - try_test(standard_mib_test_finish, [], [{community, "bad community"}]). - -%% Req. SNMP-STANDARD-MIB -standard_mib_a() -> - ?line [OutPkts] = get_req(2, [[snmpOutPkts,0]]), - ?line [OutPkts2] = get_req(3, [[snmpOutPkts,0]]), - ?line OutPkts2 = OutPkts + 1, - %% There are some more counters we could test here, but it's not that - %% important, since they are removed from SNMPv2-MIB. - ok. - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_init() -> - %% disable authentication failure traps. (otherwise w'd get many of - %% them - this is also a test to see that it works). - s([{[snmpEnableAuthenTraps,0], 2}]), - ?line expect(1, [{[snmpEnableAuthenTraps, 0], 2}]). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_finish() -> - %% enable again - s([{[snmpEnableAuthenTraps,0], 1}]), - ?line expect(1, [{[snmpEnableAuthenTraps, 0], 1}]). - -%% Req. SNMP-STANDARD-MIB -standard_mib_test_finish() -> - %% force a authenticationFailure - std_mib_write(), - %% check that we got a trap - ?line expect(2, trap, [1,2,3], 4, 0, []). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_read() -> - ?DBG("std_mib_read -> entry", []), - g([[sysUpTime,0]]), % try a bad ; msg dropped, no reply - ?DBG("std_mib_read -> await timeout (i.e. no reply)", []), - ?line expect(1, timeout). % make sure we don't get a trap! - - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_write() -> - ?DBG("std_mib_write -> entry", []), - s([{[sysLocation, 0], "new_value"}]). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_asn_err() -> - snmp_test_mgr:send_bytes([48,99,67,12,0,0,0,0,0,0,5]). - -%%----------------------------------------------------------------- -%% For this test, the agent is configured for v2 and v3. -%% o Test the counters and control objects in SNMPv2-MIB -%%----------------------------------------------------------------- -snmpv2_mib_2(suite) -> []; -snmpv2_mib_2(Config) when list(Config) -> - ?LOG("snmpv2_mib_2 -> start",[]), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?DBG("snmpv2_mib_2 -> standard mib init",[]), - try_test(std_mib_init), - - ?DBG("snmpv2_mib_2 -> get number of (so far) bad versions",[]), - InBadVsns = try_test(std_mib_a), - - ?DBG("snmpv2_mib_2 -> make a bad version read",[]), - put(vsn, v1), - try_test(std_mib_read), - - ?DBG("snmpv2_mib_2 -> bad version read",[]), - put(vsn, v2), - Bad = try_test(std_mib_b, [InBadVsns]), - - ?DBG("snmpv2_mib_2 -> read with bad community",[]), - try_test(std_mib_read, [], [{community, "bad community"}]), - - ?DBG("snmpv2_mib_2 -> write with public community",[]), - try_test(std_mib_write, [], [{community, "public"}]), - - ?DBG("snmpv2_mib_2 -> asn err",[]), - try_test(std_mib_asn_err), - - ?DBG("snmpv2_mib_2 -> check counters",[]), - try_test(std_mib_c, [Bad]), - - ?DBG("snmpv2_mib_2 -> get som counters",[]), - try_test(snmpv2_mib_a), - - ?DBG("snmpv2_mib_2 -> enable auth traps, and await some",[]), - try_test(std_mib_finish), - - ?DBG("snmpv2_mib_2 -> force auth failure, and await trap, " - "then disable auth traps",[]), - try_test(snmpv2_mib_test_finish, [], [{community, "bad community"}]), - - ?LOG("snmpv2_mib_2 -> done",[]). - -%% Req. SNMPv2-MIB -snmpv2_mib_3(suite) -> []; -snmpv2_mib_3(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - InBadVsns = try_test(std_mib_a), - put(vsn, v1), - try_test(std_mib_read), - put(vsn, v3), - _Bad = try_test(std_mib_b, [InBadVsns]), - try_test(snmpv2_mib_a), - - try_test(std_mib_finish). - --define(authenticationFailure, [1,3,6,1,6,3,1,1,5,5]). - -%% Req. SNMPv2-MIB -snmpv2_mib_test_finish() -> - %% force a authenticationFailure - ?DBG("ma_v2_inform -> write to std mib",[]), - std_mib_write(), - - %% check that we got a trap - ?DBG("ma_v2_inform -> await trap",[]), - ?line expect(2, v2trap, [{[sysUpTime,0], any}, - {[snmpTrapOID,0], ?authenticationFailure}]), - - %% and the the inform - ?DBG("ma_v2_inform -> await inform",[]), - ?line expect(2, {inform,true}, [{[sysUpTime,0], any}, - {[snmpTrapOID,0],?authenticationFailure}]). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_a() -> - ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), - ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), - ?line InPkts2 = InPkts + 1, - - ?line [InBadVsns] = get_req(4, [[snmpInBadVersions,0]]), - InBadVsns. - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_b(InBadVsns) -> - ?line [InBadVsns2] = get_req(1, [[snmpInBadVersions,0]]), - ?line InBadVsns2 = InBadVsns + 1, - ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), - ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), - ?line InPkts2 = InPkts + 1, - ?line [InBadCommunityNames, InBadCommunityUses, InASNErrs] = - get_req(4, [[snmpInBadCommunityNames,0], - [snmpInBadCommunityUses,0], - [snmpInASNParseErrs, 0]]), - {InBadCommunityNames, InBadCommunityUses, InASNErrs}. - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_c({InBadCommunityNames, InBadCommunityUses, InASNErrs}) -> - ?line [InBadCommunityNames2, InBadCommunityUses2, InASNErrs2] = - get_req(1, [[snmpInBadCommunityNames,0], - [snmpInBadCommunityUses,0], - [snmpInASNParseErrs, 0]]), - ?line InBadCommunityNames2 = InBadCommunityNames + 1, - ?line InBadCommunityUses2 = InBadCommunityUses + 1, - ?line InASNErrs2 = InASNErrs + 1. - -%% Req. SNMPv2-MIB -snmpv2_mib_a() -> - ?line [SetSerial] = get_req(2, [[snmpSetSerialNo,0]]), - s([{[snmpSetSerialNo,0], SetSerial}, {[sysLocation, 0], "val2"}]), - ?line expect(3, [{[snmpSetSerialNo,0], SetSerial}, - {[sysLocation, 0], "val2"}]), - s([{[sysLocation, 0], "val3"}, {[snmpSetSerialNo,0], SetSerial}]), - ?line expect(4, inconsistentValue, 2, - [{[sysLocation, 0], "val3"}, - {[snmpSetSerialNo,0], SetSerial}]), - ?line ["val2"] = get_req(5, [[sysLocation,0]]). - - -%%----------------------------------------------------------------- -%% o Bad community uses/name is tested already -%% in SNMPv2-MIB and STANDARD-MIB. -%% o Test add/deletion of rows. -%%----------------------------------------------------------------- -snmp_community_mib(suite) -> []; -snmp_community_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - try_test(snmp_community_mib), - ?line unload_master("SNMP-COMMUNITY-MIB"). - -snmp_community_mib_2(X) -> snmp_community_mib(X). - -%% Req. SNMP-COMMUNITY-MIB -snmp_community_mib() -> - ?INF("NOT YET IMPLEMENTED", []), - nyi. - -%%----------------------------------------------------------------- -%% o Test engine boots / time -%%----------------------------------------------------------------- -snmp_framework_mib(suite) -> []; -snmp_framework_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - try_test(snmp_framework_mib), - ?line unload_master("SNMP-FRAMEWORK-MIB"). - -snmp_framework_mib_2(X) -> snmp_framework_mib(X). - -snmp_framework_mib_3(suite) -> []; -snmp_framework_mib_3(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - try_test(snmp_framework_mib). - - -%% Req. SNMP-FRAMEWORK-MIB -snmp_framework_mib() -> - ?line ["agentEngine"] = get_req(1, [[snmpEngineID,0]]), - ?line [EngineTime] = get_req(2, [[snmpEngineTime,0]]), - sleep(5000), - ?line [EngineTime2] = get_req(3, [[snmpEngineTime,0]]), - if - EngineTime+7 < EngineTime2 -> - ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); - EngineTime+4 > EngineTime2 -> - ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); - true -> ok - end, - ?line case get_req(4, [[snmpEngineBoots,0]]) of - [Boots] when integer(Boots) -> ok; - Else -> ?FAIL(Else) - end, - ok. - -%%----------------------------------------------------------------- -%% o Test the counters -%%----------------------------------------------------------------- -snmp_mpd_mib_3(suite) -> []; -snmp_mpd_mib_3(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - UnknownPDUHs = try_test(snmp_mpd_mib_a), - try_test(snmp_mpd_mib_b, [], [{context_engine_id, "bad engine"}]), - try_test(snmp_mpd_mib_c, [UnknownPDUHs]). - - -%% Req. SNMP-MPD-MIB -snmp_mpd_mib_a() -> - ?line [UnknownSecs, InvalidMsgs] = - get_req(1, [[snmpUnknownSecurityModels,0], - [snmpInvalidMsgs,0]]), - Pdu = #pdu{type = 'get-request', - request_id = 23, - error_status = noError, - error_index = 0, - varbinds = []}, - SPdu = #scopedPdu{contextEngineID = "agentEngine", - contextName = "", - data = Pdu}, - ?line SPDUBytes = snmp_pdus:enc_scoped_pdu(SPdu), - V3Hdr1 = #v3_hdr{msgID = 21, - msgMaxSize = 484, - msgFlags = [7], - msgSecurityModel = 23, % bad sec model - msgSecurityParameters = []}, - V3Hdr2 = #v3_hdr{msgID = 21, - msgMaxSize = 484, - msgFlags = [6], % bad flag combination - msgSecurityModel = 3, - msgSecurityParameters = []}, - Message1 = #message{version = 'version-3', vsn_hdr = V3Hdr1, - data = SPDUBytes}, - Message2 = #message{version = 'version-3', vsn_hdr = V3Hdr2, - data = SPDUBytes}, - ?line MsgBytes1 = snmp_pdus:enc_message_only(Message1), - ?line MsgBytes2 = snmp_pdus:enc_message_only(Message2), - snmp_test_mgr:send_bytes(MsgBytes1), - snmp_test_mgr:send_bytes(MsgBytes2), - - ?line [UnknownSecs2, InvalidMsgs2, UnknownPDUHs] = - get_req(1, [[snmpUnknownSecurityModels,0], - [snmpInvalidMsgs,0], - [snmpUnknownPDUHandlers, 0]]), - ?line UnknownSecs2 = UnknownSecs + 1, - ?line InvalidMsgs2 = InvalidMsgs + 1, - UnknownPDUHs. - --define(snmpUnknownPDUHandlers_instance, [1,3,6,1,6,3,11,2,1,3,0]). -snmp_mpd_mib_b() -> - g([[sysUpTime,0]]), - ?line expect(1, report, [{?snmpUnknownPDUHandlers_instance, any}]). - - -snmp_mpd_mib_c(UnknownPDUHs) -> - ?line [UnknownPDUHs2] = get_req(1, [[snmpUnknownPDUHandlers, 0]]), - ?line UnknownPDUHs2 = UnknownPDUHs + 1. - - -snmp_target_mib(suite) -> []; -snmp_target_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-TARGET-MIB"), - try_test(snmp_target_mib), - ?line unload_master("SNMP-TARGET-MIB"). - -snmp_target_mib_2(X) -> snmp_target_mib(X). - -snmp_target_mib_3(X) -> snmp_target_mib(X). - -snmp_target_mib() -> - ?INF("NOT YET IMPLEMENTED", []), - nyi. - -snmp_notification_mib(suite) -> []; -snmp_notification_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - try_test(snmp_notification_mib), - ?line unload_master("SNMP-NOTIFICATION-MIB"). - -snmp_notification_mib_2(X) -> snmp_notification_mib(X). - -snmp_notification_mib_3(X) -> snmp_notification_mib(X). - -snmp_notification_mib() -> - ?INF("NOT YET IMPLEMENTED", []), - nyi. - -%%----------------------------------------------------------------- -%% o add/delete views and try them -%% o try boundaries -%%----------------------------------------------------------------- -snmp_view_based_acm_mib(suite) -> []; -snmp_view_based_acm_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - ?line load_master("Test2"), - snmp_view_based_acm_mib(), - ?line unload_master("Test2"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). - -snmp_view_based_acm_mib_2(X) -> snmp_view_based_acm_mib(X). - -snmp_view_based_acm_mib_3(X) -> snmp_view_based_acm_mib(X). - -snmp_view_based_acm_mib() -> - snmpa:verbosity(net_if,trace), - snmpa:verbosity(master_agent,trace), - ?LOG("start snmp_view_based_acm_mib test",[]), - %% The user "no-rights" is present in USM, and is mapped to security - %% name 'no-rights", which is not present in VACM. - %% So, we'll add rights for it, try them and delete them. - %% We'll give "no-rights" write access to tDescr.0 and read access - %% to tDescr2.0 - %% These are the options we'll use to the mgr - Opts = [{user, "no-rights"}, {community, "no-rights"}], - %% Find the valid secmodel, and one invalid secmodel. - {SecMod, InvSecMod} = - case get(vsn) of - v1 -> {?SEC_V1, ?SEC_V2C}; - v2 -> {?SEC_V2C, ?SEC_USM}; - v3 -> {?SEC_USM, ?SEC_V1} - end, - ?DBG("assign rights for 'no-rights'",[]), - ?line try_test(use_no_rights, [], Opts), - - %% Now, add a mapping from "no-rights" -> "no-rights-group" - GRow1Status = [vacmSecurityToGroupStatus,[SecMod, 9,"no-rights"]], - GRow1 = - [{[vacmGroupName, [SecMod, 9,"no-rights"]], "no-rights-group"}, - {GRow1Status, ?createAndGo}], - ?DBG("set '~p'",[GRow1]), - ?line try_test(do_set, [GRow1]), - - ?DBG("assign rights for 'no-rights'",[]), - ?line try_test(use_no_rights, [], Opts), - - %% Create a mapping for another sec model, and make sure it dosn't - %% give us access - GRow2Status = [vacmSecurityToGroupStatus,[InvSecMod, 9,"no-rights"]], - GRow2 = [{[vacmGroupName, [InvSecMod, 9, "no-rights"]], "initial"}, - {GRow2Status, ?createAndGo}], - - ?DBG("set '~p'",[GRow2]), - ?line try_test(do_set, [GRow2]), - - ?DBG("assign rights for 'no-rights'",[]), - ?line try_test(use_no_rights, [], Opts), - - %% Delete that row - ?line try_test(del_row, [GRow2Status]), - - RVName = "rv_name", - WVName = "wv_name", - - %% Access row - ARow1Idx = [15 | "no-rights-group"] ++ [0, ?SEC_ANY, 1], - ARow1Status = [vacmAccessStatus, ARow1Idx], - ARow1 = [{[vacmAccessContextMatch, ARow1Idx], 1}, - {[vacmAccessReadViewName, ARow1Idx], RVName}, - {[vacmAccessWriteViewName, ARow1Idx], WVName}, - {ARow1Status, ?createAndGo}], - - %% This access row would give acces, if InvSecMod was valid. - ARow2Idx = [15 | "no-rights-group"] ++ [0, InvSecMod, 1], - ARow2Status = [vacmAccessStatus, ARow2Idx], - ARow2 = [{[vacmAccessContextMatch, ARow2Idx], 1}, - {[vacmAccessReadViewName, ARow2Idx], "internet"}, - {[vacmAccessWriteViewName, ARow2Idx], "internet"}, - {ARow2Status, ?createAndGo}], - - ?line try_test(do_set, [ARow2]), - - ?line try_test(use_no_rights, [], Opts), - - %% Delete that row - ?line try_test(del_row, [ARow2Status]), - - - %% Add valid row - ?line try_test(do_set, [ARow1]), - - ?line try_test(use_no_rights, [], Opts), - - %% Create the view family - VRow1Idx = mk_ln(RVName) ++ mk_ln(?xDescr), % object access - VRow2Idx = mk_ln(RVName) ++ mk_ln(?xDescr2 ++ [0]), % instance access - VRow3Idx = mk_ln(WVName) ++ mk_ln(?xDescr), % object access - VRow4Idx = mk_ln(WVName) ++ mk_ln(?xDescr ++ [0]), % instance access - VRow1Status = [vacmViewTreeFamilyStatus, VRow1Idx], - VRow2Status = [vacmViewTreeFamilyStatus, VRow2Idx], - VRow3Status = [vacmViewTreeFamilyStatus, VRow3Idx], - VRow4Status = [vacmViewTreeFamilyStatus, VRow4Idx], - - ?line try_test(add_row, [VRow1Status]), - ?line try_test(add_row, [VRow2Status]), - ?line try_test(add_row, [VRow3Status]), - - %% We're supposed to have access now... - ?line try_test(use_rights, [], Opts), - - %% Change Row3 to Row4 - ?line try_test(del_row, [VRow3Status]), - ?line try_test(add_row, [VRow4Status]), - - %% We should still have access... - ?line try_test(use_rights, [], Opts), - - %% Delete rows - ?line try_test(del_row, [GRow1Status]), - - ?line try_test(use_no_rights, [], Opts), - - %% Delete rest of rows - ?line try_test(del_row, [ARow1Status]), - ?line try_test(del_row, [VRow1Status]), - ?line try_test(del_row, [VRow2Status]), - ?line try_test(del_row, [VRow4Status]), - - ?line try_test(use_no_rights, [], Opts), - snmpa:verbosity(master_agent,log). - -do_set(Row) -> - s(Row), - expect(1, Row). - -add_row(RowStatus) -> - s([{RowStatus, ?createAndGo}]), - expect(1, [{RowStatus, ?createAndGo}]). - -del_row(RowStatus) -> - s([{RowStatus, ?destroy}]), - expect(1, [{RowStatus, ?destroy}]). - - - -use_no_rights() -> - g([[xDescr,0]]), - ?v1_2_3(expect(11, noSuchName, 1, any), - expect(12, [{[xDescr,0], noSuchObject}]), - expect(13, authorizationError, 1, any)), - g([[xDescr2,0]]), - ?v1_2_3(expect(21, noSuchName, 1, any), - expect(22, [{[xDescr2,0], noSuchObject}]), - expect(23, authorizationError, 1, any)), - gn([[xDescr]]), - ?v1_2_3(expect(31, noSuchName, 1, any), - expect(32, [{[xDescr], endOfMibView}]), - expect(33, authorizationError, 1, any)), - s([{[xDescr,0], "tryit"}]), - ?v1_2_3(expect(41, noSuchName, 1, any), - expect(42, noAccess, 1, any), - expect(43, authorizationError, 1, any)). - - -use_rights() -> - g([[xDescr,0]]), - expect(1, [{[xDescr,0], any}]), - g([[xDescr2,0]]), - expect(2, [{[xDescr2,0], any}]), - s([{[xDescr,0], "tryit"}]), - expect(3, noError, 0, any), - g([[xDescr,0]]), - expect(4, [{[xDescr,0], "tryit"}]). - -mk_ln(X) -> - [length(X) | X]. - -%%----------------------------------------------------------------- -%% o add/delete users and try them -%% o test all secLevels -%% o test all combinations of protocols -%% o try bad ops; check counters -%%----------------------------------------------------------------- -snmp_user_based_sm_mib_3(suite) -> []; -snmp_user_based_sm_mib_3(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - _AgentDir = ?config(agent_dir, Config), - ?line load_master_std("SNMP-USER-BASED-SM-MIB"), - - %% The newUser used here already has VACM access. - - %% Add a new user in the simplest way; just createAndGo - try_test(v3_sync, [[{usm_add_user1, []}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - %% Try to use the new user - ?line load_master("Test2"), - try_test(v3_sync, [[{usm_use_user, []}]], - [{sec_level, authPriv}, {user, "newUser"}]), - ?line unload_master("Test2"), - - ShaKey1 = snmp:passwd2localized_key(sha, "new sha password", "agentEngine"), - DesKey1 = lists:sublist(ShaKey1, 16), - - %% Change the new user's keys - 1 - try_test(v3_sync, [[{usm_key_change1, [ShaKey1, DesKey1]}]], - [{sec_level, authPriv}, {user, "newUser"}]), - - %% Try to use the new keys - MgrDir = ?config(mgr_dir, Config), - ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), - ?line load_master("Test2"), - try_test(v3_sync, [[{usm_use_user, []}]], - [{sec_level, authPriv}, {user, "newUser"}]), - ?line unload_master("Test2"), - - ShaKey2 = snmp:passwd2localized_key(sha, "newer password", "agentEngine"), - DesKey2 = lists:sublist(ShaKey2, 16), - - %% Change the new user's keys - 2 - ?line try_test(v3_sync, - [[{usm_key_change2, [ShaKey1, DesKey1, ShaKey2, DesKey2]}]], - [{sec_level, authPriv}, {user, "newUser"}]), - - %% Try to use the new keys - reset_usm_mgr(MgrDir), - ?line rewrite_usm_mgr(MgrDir, ShaKey2, DesKey2), - ?line load_master("Test2"), - ?line try_test(v3_sync, [[{usm_use_user, []}]], - [{sec_level, authPriv}, {user, "newUser"}]), - ?line unload_master("Test2"), - reset_usm_mgr(MgrDir), - - %% Change the new user's keys - 3 - ?line try_test(v3_sync, - [[{usm_key_change3, [ShaKey2, DesKey2, ShaKey1, DesKey1]}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - %% Try to use the new keys - ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), - ?line load_master("Test2"), - try_test(v3_sync, [[{usm_use_user, []}]], - [{sec_level, authPriv}, {user, "newUser"}]), - ?line unload_master("Test2"), - reset_usm_mgr(MgrDir), - - %% Try some read requests - ?line try_test(v3_sync, [[{usm_read, []}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - %% Delete the new user - ?line try_test(v3_sync, [[{usm_del_user, []}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - %% Try some bad requests - ?line try_test(v3_sync, [[{usm_bad, []}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - ?line unload_master("SNMP-USER-BASED-SM-MIB"). - --define(usmUserSecurityName, [1,3,6,1,6,3,15,1,2,2,1,3]). - -usm_add_user1() -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - RowPointer = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], - Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer}, - {[usmUserStatus, NewRowIndex], ?createAndGo}], - ?line s(Vbs1), - ?line expect(1, Vbs1), - ok. - -usm_use_user() -> - v2_proc(). - - -%% Change own public keys -usm_key_change1(ShaKey, DesKey) -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - "passwd_shaxxxxxxxxxx", - ShaKey), - DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - "passwd_desxxxxxx", - DesKey), - Vbs1 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, - {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], - s(Vbs1), - ?line expect(1, Vbs1). - -%% Change own private keys -usm_key_change2(OldShaKey, OldDesKey, ShaKey, DesKey) -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - OldShaKey, - ShaKey), - DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - OldDesKey, - DesKey), - Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}, - {[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], - s(Vbs1), - ?line expect(1, Vbs1). - -%% Change other's public keys -usm_key_change3(OldShaKey, OldDesKey, ShaKey, DesKey) -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - OldShaKey, - ShaKey), - DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - OldDesKey, - DesKey), - Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}], - s(Vbs1), - ?line expect(1, noAccess, 1, any), - Vbs2 = [{[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], - s(Vbs2), - ?line expect(2, noAccess, 1, any), - - - Vbs3 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, - {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], - s(Vbs3), - ?line expect(1, Vbs3). - -usm_read() -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - ?line g([[usmUserSecurityName, NewRowIndex], - [usmUserCloneFrom, NewRowIndex], - [usmUserAuthKeyChange, NewRowIndex], - [usmUserOwnAuthKeyChange, NewRowIndex], - [usmUserPrivKeyChange, NewRowIndex], - [usmUserOwnPrivKeyChange, NewRowIndex]]), - ?line expect(1, - [{[usmUserSecurityName, NewRowIndex], "newUser"}, - {[usmUserCloneFrom, NewRowIndex], [0,0]}, - {[usmUserAuthKeyChange, NewRowIndex], ""}, - {[usmUserOwnAuthKeyChange, NewRowIndex], ""}, - {[usmUserPrivKeyChange, NewRowIndex], ""}, - {[usmUserOwnPrivKeyChange, NewRowIndex], ""}]), - ok. - - - -usm_del_user() -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - Vbs1 = [{[usmUserStatus, NewRowIndex], ?destroy}], - ?line s(Vbs1), - ?line expect(1, Vbs1), - ok. - --define(usmUserCloneFrom, [1,3,6,1,6,3,15,1,2,2,1,4]). - --define(usmNoAuthProtocol, [1,3,6,1,6,3,10,1,1,1]). - --define(usmHMACMD5AuthProtocol, [1,3,6,1,6,3,10,1,1,2]). - --define(usmHMACSHAAuthProtocol, [1,3,6,1,6,3,10,1,1,3]). - --define(usmNoPrivProtocol, [1,3,6,1,6,3,10,1,2,1]). - --define(usmDESPrivProtocol, [1,3,6,1,6,3,10,1,2,2]). - -usm_bad() -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - RowPointer1 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDOS"], - Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer1}, - {[usmUserStatus, NewRowIndex], ?createAndGo}], - ?line s(Vbs1), - ?line expect(1, inconsistentName, 1, any), - - RowPointer2 = ?usmUserCloneFrom ++ [11|"agentEngine"] ++ [7|"privDES"], - Vbs2 = [{[usmUserCloneFrom, NewRowIndex], RowPointer2}, - {[usmUserStatus, NewRowIndex], ?createAndGo}], - ?line s(Vbs2), - ?line expect(2, wrongValue, 1, any), - - RowPointer3 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], - Vbs3 = [{[usmUserCloneFrom, NewRowIndex], RowPointer3}, - {[usmUserStatus, NewRowIndex], ?createAndGo}], - ?line s(Vbs3), - ?line expect(3, Vbs3), - ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmNoAuthProtocol}]), - ?line expect(4, inconsistentValue, 1, any), - ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmHMACMD5AuthProtocol}]), - ?line expect(5, inconsistentValue, 1, any), - ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmDESPrivProtocol}]), - ?line expect(6, wrongValue, 1, any), - ?line s([{[usmUserPrivProtocol, NewRowIndex], ?usmHMACSHAAuthProtocol}]), - ?line expect(7, wrongValue, 1, any), - - Vbs4 = [{[usmUserStatus, NewRowIndex], ?destroy}], - ?line s(Vbs4), - ?line expect(1, Vbs4), - - ok. - - -%%----------------------------------------------------------------- -%% Loop through entire MIB, to make sure that all instrum. funcs -%% works. -%% Load all std mibs that are not loaded by default. -%%----------------------------------------------------------------- -loop_mib(suite) -> []; -loop_mib(Config) when list(Config) -> - ?LOG("loop_mib -> initiate case",[]), - %% snmpa:verbosity(master_agent,debug), - %% snmpa:verbosity(mib_server,info), - {SaNode, MgrNode, MibDir} = init_case(Config), - ?DBG("loop_mib -> ~n" - "\tSaNode: ~p~n" - "\tMgrNode: ~p~n" - "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), - ?DBG("loop_mib -> load mib SNMP-COMMUNITY-MIB",[]), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?DBG("loop_mib -> load mib SNMP-MPD-MIB",[]), - ?line load_master_std("SNMP-MPD-MIB"), - ?DBG("loop_mib -> load mib SNMP-TARGET-MIB",[]), - ?line load_master_std("SNMP-TARGET-MIB"), - ?DBG("loop_mib -> load mib SNMP-NOTIFICATION-MIB",[]), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?DBG("loop_mib -> load mib SNMP-FRAMEWORK-MIB",[]), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?DBG("loop_mib -> load mib SNMP-VIEW-BASED-ACM-MIB",[]), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - ?DBG("loop_mib -> try",[]), - try_test(loop_mib_1), - ?DBG("loop_mib -> unload mib SNMP-COMMUNITY-MIB",[]), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?DBG("loop_mib -> unload mib SNMP-MPD-MIB",[]), - ?line unload_master("SNMP-MPD-MIB"), - ?DBG("loop_mib -> unload mib SNMP-TARGET-MIB",[]), - ?line unload_master("SNMP-TARGET-MIB"), - ?DBG("loop_mib -> unload mib SNMP-NOTIFICATION-MIB",[]), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?DBG("loop_mib -> unload mib SNMP-FRAMEWORK-MIB",[]), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?DBG("loop_mib -> unload mib SNMP-VIEW-BASED-ACM-MIB",[]), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - %% snmpa:verbosity(master_agent,log), - %% snmpa:verbosity(mib_server,silence), - ?LOG("loop_mib -> done",[]). - - -loop_mib_2(suite) -> []; -loop_mib_2(Config) when list(Config) -> - ?LOG("loop_mib_2 -> initiate case",[]), - {SaNode, MgrNode, MibDir} = init_case(Config), - ?DBG("loop_mib_2 -> ~n" - "\tSaNode: ~p~n" - "\tMgrNode: ~p~n" - "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), - ?DBG("loop_mib_2 -> load mibs",[]), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-MPD-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - try_test(loop_mib_2), - ?DBG("loop_mib_2 -> unload mibs",[]), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?line unload_master("SNMP-MPD-MIB"), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - ?LOG("loop_mib_2 -> done",[]). - - -loop_mib_3(suite) -> []; -loop_mib_3(Config) when list(Config) -> - ?LOG("loop_mib_3 -> initiate case",[]), - {SaNode, MgrNode, MibDir} = init_case(Config), - ?DBG("loop_mib_3 -> ~n" - "\tSaNode: ~p~n" - "\tMgrNode: ~p~n" - "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), - ?DBG("loop_mib_3 -> load mibs",[]), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - ?line load_master_std("SNMP-USER-BASED-SM-MIB"), - try_test(loop_mib_2), - ?DBG("loop_mib_3 -> unload mibs",[]), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - ?line unload_master("SNMP-USER-BASED-SM-MIB"), - ?LOG("loop_mib_3 -> done",[]). - - -%% Req. As many mibs all possible -loop_mib_1() -> - ?DBG("loop_mib_1 -> entry",[]), - N = loop_it_1([1,1], 0), - io:format(user, "found ~w varibles\n", [N]), - ?line N = if N < 100 -> 100; - true -> N - end. - - -loop_it_1(Oid, N) -> - ?DBG("loop_it_1 -> entry with~n" - "\tOid: ~p~n" - "\tN: ~p",[Oid,N]), - case get_next_req([Oid]) of - #pdu{type='get-response', error_status=noError, error_index=0, - varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> - ?DBG("loop_it_1 -> ~n" - "\tNOid: ~p~n" - "\tValue: ~p",[NOid,Value]), - ?line [Value2] = get_req(1, [NOid]), % must not be same - ?DBG("loop_it_1 -> ~n" - "\tValue2: ~p",[Value2]), - loop_it_1(NOid, N+1); - #pdu{type='get-response', error_status=noSuchName, error_index=1, - varbinds=[_]} -> - ?DBG("loop_it_1 -> done",[]), - N; - - #pdu{type = Type, error_status = Err, error_index = Idx, - varbinds = Vbs} -> - exit({unexpected_pdu, ?LINE, Type, Err, Idx, Vbs}) - end. - -%% Req. As many mibs all possible -loop_mib_2() -> - ?DBG("loop_mib_1 -> entry",[]), - N = loop_it_2([1,1], 0), - io:format(user, "found ~w varibles\n", [N]), - ?line N = if N < 100 -> 100; - true -> N - end. - - -loop_it_2(Oid, N) -> - ?DBG("loop_it_2 -> entry with~n" - "\tOid: ~p~n" - "\tN: ~p",[Oid,N]), - case get_next_req([Oid]) of - #pdu{type='get-response', error_status=noError, error_index=0, - varbinds=[#varbind{oid = NOid, value = endOfMibView}]} -> - ?DBG("loop_it_2 -> ~n" - "\tNOid: ~p",[NOid]), - N; - #pdu{type='get-response', error_status=noError, error_index=0, - varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> - ?DBG("loop_it_2 -> ~n" - "\tNOid: ~p~n" - "\tValue: ~p",[NOid,Value]), - ?line [Value2] = get_req(1, [NOid]), % must not be same - ?DBG("loop_it_2 -> ~n" - "\tValue2: ~p",[Value2]), - loop_it_2(NOid, N+1) - end. - - -%%%----------------------------------------------------------------- -%%% Testing of reported bugs and other tickets. -%%%----------------------------------------------------------------- - - - - - -%% These are (ticket) test cases where the initiation has to be done -%% individually. - -%%----------------------------------------------------------------- -%% Ticket: OTP-1128 -%% Slogan: Bug in handling of createAndWait set-requests. -%%----------------------------------------------------------------- -otp_1128(suite) -> []; -otp_1128(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(otp_1128), - ?line unload_master("OLD-SNMPEA-MIB"). - -otp_1128_2(X) -> otp_1128(X). - -otp_1128_3(X) -> otp_1128(X). - -otp_1128() -> - io:format("Testing bug reported in ticket OTP-1128...~n"), - - NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], - NewKeyc4 = [intCommunityAccess,get(mip),is("test")], - NewKeyc5 = [intCommunityStatus,get(mip),is("test")], - - s([{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), - ?line expect(28, [{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), - g([NewKeyc5]), - ?line expect(29, [{NewKeyc5, ?notReady}]), - s([{NewKeyc5, ?active}, {NewKeyc3, 2}]), - ?line expect(30, [{NewKeyc5, ?active}, {NewKeyc3, 2}]), - g([NewKeyc5]), - ?line expect(31, [{NewKeyc5, ?active}]), - s([{NewKeyc5, ?destroy}]), - ?line expect(32, [{NewKeyc5, ?destroy}]). - -%%----------------------------------------------------------------- -%% Ticket: OTP-1129, OTP-1169 -%% Slogan: snmpa:int_to_enum crashes on bad oids -%%----------------------------------------------------------------- -otp_1129(suite) -> []; -otp_1129(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas3"), - try_test(otp_1129_i, [node()]), - ?line unload_master("Klas3"). - -otp_1129_2(X) -> otp_1129(X). - -otp_1129_3(X) -> otp_1129(X). - -otp_1129_i(MaNode) -> - io:format("Testing bug reported in ticket OTP-1129...~n"), - false = rpc:call(MaNode, snmp, int_to_enum, [iso, 1]), - false = rpc:call(MaNode, snmp, int_to_enum, [isox, 1]). - -%%----------------------------------------------------------------- -%% Ticket: OTP-1131 -%% Slogan: Agent crashes / erlang node halts if RowIndex in a -%% setrequest is of bad type, e.g. an INDEX {INTEGER}, -%% and RowIdenx [3,2]. -%%----------------------------------------------------------------- -otp_1131(suite) -> []; -otp_1131(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas1"), - try_test(otp_1131), - ?line unload_master("Klas1"). - -otp_1131_2(X) -> otp_1131(X). - -otp_1131_3(X) -> otp_1131(X). - -otp_1131() -> - io:format("Testing bug reported in ticket OTP-1131...~n"), - s([{[friendsEntry, [2, 3, 1]], s, "kompis3"}, - {[friendsEntry, [3, 3, 1]], i, ?createAndGo}]), - ?line expect(1, ?v1_2(noSuchName, noCreation), 2, any). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1162 -%% Slogan: snmp_agent can't handle wrongValue from instrum.func -%%----------------------------------------------------------------- -otp_1162(suite) -> []; -otp_1162(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - try_test(otp_1162), - stop_subagent(SA). - -otp_1162_2(X) -> otp_1162(X). - -otp_1162_3(X) -> otp_1162(X). - -otp_1162() -> - s([{[sa, [2,0]], 6}]), % wrongValue (i is_set_ok) - ?line expect(1, ?v1_2(badValue, wrongValue), 1, any). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1222 -%% Slogan: snmp agent crash if faulty index is returned from instrum -%%----------------------------------------------------------------- -otp_1222(suite) -> []; -otp_1222(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas3"), - ?line load_master("Klas4"), - try_test(otp_1222), - ?line unload_master("Klas3"), - ?line unload_master("Klas4"). - -otp_1222_2(X) -> otp_1222(X). - -otp_1222_3(X) -> otp_1222(X). - -otp_1222() -> - io:format("Testing bug reported in ticket OTP-1222...~n"), - s([{[fStatus4,1], 4}, {[fName4,1], 1}]), - ?line expect(1, genErr, 0, any), - s([{[fStatus4,2], 4}, {[fName4,2], 1}]), - ?line expect(2, genErr, 0, any). - -%%----------------------------------------------------------------- -%% Ticket: OTP-1298 -%% Slogan: Negative INTEGER values are treated as positive. -%%----------------------------------------------------------------- -otp_1298(suite) -> []; -otp_1298(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas2"), - try_test(otp_1298), - ?line unload_master("Klas2"). - -otp_1298_2(X) -> otp_1298(X). - -otp_1298_3(X) -> otp_1298(X). - -otp_1298() -> - io:format("Testing bug reported in ticket OTP-1298...~n"), - s([{[fint,0], -1}]), - ?line expect(1298, [{[fint,0], -1}]). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1331 -%% Slogan: snmp_generic should return noError when deleting non-ex row -%%----------------------------------------------------------------- -otp_1331(suite) -> []; -otp_1331(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(otp_1331), - ?line unload_master("OLD-SNMPEA-MIB"). - -otp_1331_2(X) -> otp_1331(X). - -otp_1331_3(X) -> otp_1331(X). - -otp_1331() -> - NewKeyc5 = [intCommunityStatus,[127,32,0,0],is("test")], - s([{NewKeyc5, ?destroy}]), - ?line expect(1, [{NewKeyc5, ?destroy}]). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1338 -%% Slogan: snmp bug in initialisation of default values for mnesia tabs -%%----------------------------------------------------------------- -otp_1338(suite) -> []; -otp_1338(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas2"), - try_test(otp_1338), - ?line unload_master("Klas2"). - -otp_1338_2(X) -> otp_1338(X). - -otp_1338_3(X) -> otp_1338(X). - -otp_1338() -> - s([{[kStatus2, 7], i, ?createAndGo}]), - ?line expect(1, [{[kStatus2, 7], ?createAndGo}]), - g([[kName2, 7]]), - ?line expect(2, [{[kName2, 7], "JJJ"}]). - -%%----------------------------------------------------------------- -%% Ticket: OTP-1342 -%% Slogan: default impl of snmp table can't handle bad index access, -%% Set when INDEX is read-write gets into an infinite loop! -%%----------------------------------------------------------------- -otp_1342(suite) -> []; -otp_1342(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas4"), - try_test(otp_1342), - ?line unload_master("Klas4"). - -otp_1342_2(X) -> otp_1342(X). - -otp_1342_3(X) -> otp_1342(X). - -otp_1342() -> - s([{[fIndex5, 1], i, 1}, - {[fName5, 1], i, 3}, - {[fStatus5, 1], i, ?createAndGo}]), - ?line expect(1, ?v1_2(noSuchName, noCreation), 3, any). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1366 -%% Slogan: snmp traps not sent to all managers -%% Note: NYI! We need a way to tell the test server that we need -%% mgrs on two different machines. -%%----------------------------------------------------------------- -otp_1366(suite) -> []; -otp_1366(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(otp_1366), - ?line unload_master("OLD-SNMPEA-MIB"). - -otp_1366_2(X) -> otp_1366(X). - -otp_1366_3(X) -> otp_1366(X). - -otp_1366() -> - ?INF("NOT YET IMPLEMENTED", []), - 'NYI'. - -%%----------------------------------------------------------------- -%% Ticket: OTP-2776 -%% Slogan: snmp:validate_date_and_time() fails when time is 00:00 -%%----------------------------------------------------------------- -otp_2776(suite) -> []; -otp_2776(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - try_test(otp_2776). - -otp_2776_2(X) -> otp_2776(X). - -otp_2776_3(X) -> otp_2776(X). - -otp_2776() -> - io:format("Testing bug reported in ticket OTP-2776...~n"), - - Dt01_valid = [19,98,9,1,1,0,23,0,43,0,0], - Dt02_valid = [19,98,9,1,0,0,0,0,43,0,0], % This is what is fixed: 00:00 - Dt03_valid = [19,98,2,28,1,0,23,0,43,0,0], - Dt04_invalid = [19,98,2,29,1,0,23,0,43,0,0], - Dt05_valid = [19,96,2,29,1,0,23,0,43,0,0], - Dt06_valid = [20,0,2,29,1,0,23,0,43,0,0], - Dt07_invalid = [19,96,2,30,1,0,23,0,43,0,0], % This is also fixed: 30/2 - Dt08_valid = [19,98,4,30,1,0,23,0,43,0,0], - Dt09_invalid = [19,98,4,31,1,0,23,0,43,0,0], % This is also fixed: 31/4 - Dt10_invalid = [], - Dt11_invalid = [kalle,hobbe], - L = [{ 1, true, Dt01_valid}, - { 2, true, Dt02_valid}, - { 3, true, Dt03_valid}, - { 4, false, Dt04_invalid}, - { 5, true, Dt05_valid}, - { 6, true, Dt06_valid}, - { 7, false, Dt07_invalid}, - { 8, true, Dt08_valid}, - { 9, false, Dt09_invalid}, - {10, false, Dt10_invalid}, - {11, false, Dt11_invalid}], - - ?line ok = validate_dat(L). - - -validate_dat(L) -> validate_dat(L,[]). - -validate_dat([],V) -> - Fun = fun({_,X}) -> case X of - ok -> false; - _ -> true - end - end, - validate_dat1( lists:reverse( lists:filter(Fun,V) ) ); -validate_dat([{Id,E,Dat}|T],V) -> - validate_dat(T,[validate_dat2(Id,E,Dat) | V]). - -validate_dat1([]) -> ok; -validate_dat1(L) -> {error,L}. - -validate_dat2(Id, E, Dat) -> - Res = case {E,snmp:validate_date_and_time(Dat)} of - {E,E} -> ok; - {E,A} -> {E,A} - end, - {Id, Res}. - - -%%----------------------------------------------------------------- -%% Ticket: OTP-2979 -%% Slogan: get-next on more than 1 column in an empty table -%% returns bad response. -%%----------------------------------------------------------------- -otp_2979(suite) -> []; -otp_2979(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Test1"), - ?line init_old(), - try_test(otp_2979), - ?line unload_master("Test1"). - -otp_2979_2(X) -> otp_2979(X). - -otp_2979_3(X) -> otp_2979(X). - -otp_2979() -> - gn([[sparseDescr], [sparseStatus]]), - ?line expect(1, [{[sparseStr,0], "slut"}, - {[sparseStr,0], "slut"}]). - -%%----------------------------------------------------------------- -%% Ticket: OTP-3187 -%% Slogan: get-next on vacmAccessTable for colums > 5 returns -%% endOfTable - should return value. -%%----------------------------------------------------------------- -otp_3187(suite) -> []; -otp_3187(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - otp_3187(), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). - -otp_3187_2(X) -> otp_3187(X). - -otp_3187_3(X) -> otp_3187(X). - -otp_3187() -> - ?line Elements = - snmp_view_based_acm_mib:vacmAccessTable(get_next,[],[4,5,6]), - lists:foreach(fun(E) -> - ?line if E == endOfTable -> - ?FAIL(endOfTable); - true -> ok - end - end, Elements). - -%%----------------------------------------------------------------- -%% Ticket: OTP-3542 -%% Slogan: -%%----------------------------------------------------------------- -otp_3542(suite) -> []; -otp_3542(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - try_test(otp_3542). - -otp_3542() -> - io:format("SNMP v3 discovery...~n"), - ?line Res = snmp_test_mgr:d(), - io:format("SNMP v3 discovery result: ~p~n",[Res]). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-3725 -%% Slogan: Slow response time on snmpa:int_to_enum -%%----------------------------------------------------------------- -otp_3725(suite) -> []; -otp_3725(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(otp_3725_test, [node()]), - ?line unload_master("OLD-SNMPEA-MIB"). - -%% Req. OLD-SNMPEA-MIB -otp_3725_test(MaNode) -> - io:format("Testing feature requested in ticket OTP-3725...~n"), - ?line rpc:call(MaNode,snmpa,verbosity,[symbolic_store,trace]), - ?line Db = rpc:call(MaNode,snmp,get_symbolic_store_db,[]), - ?DBG("otp_3725_test -> Db = ~p",[Db]), - - ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, - [Db, intAgentIpAddress]), - ?DBG("otp_3725_test -> name_to_oid for ~p: ~p",[intAgentIpAddress,OID]), - ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, oid_to_name, - [Db,OID]), - ?DBG("otp_3725_test -> oid_to_name for ~p: ~p",[OID,intAgentIpAddress]), - ?line false = rpc:call(MaNode, snmp, name_to_oid, [Db, intAgentIpAddres]), - ?line false = rpc:call(MaNode, snmp, oid_to_name, - [Db, [1,5,32,3,54,3,3,34,4]]), - ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, - [Db, intViewType, excluded]), - ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, - [Db, intViewType, 2]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, intViewType, exclude]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, intAgentIpAddress, exclude]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, intAgentIpAddre, exclude]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, intViewType, 3]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, - [Db, intAgentIpAddress, 2]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, - [Db, intAgentIpAddre, 2]), - ?line {value, active} = rpc:call(MaNode, snmp, int_to_enum, - [Db, 'RowStatus', ?active]), - ?line {value, ?destroy} = rpc:call(MaNode, snmp, enum_to_int, - [Db, 'RowStatus', destroy]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, 'RowStatus', xxxdestroy]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, 'xxRowStatus', destroy]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'RowStatus', 25]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'xxRowStatus', 1]), - ok. - - -%%----------------------------------------------------------------- -%% Ticket: OTP-4394 -%% Slogan: Target mib tag list check invalid -%%----------------------------------------------------------------- - - - -init_otp_4394(Config) when list(Config) -> - ?DBG("init_otp_4394 -> entry with" - "~n Config: ~p", [Config]), - ?line AgentDir = ?config(agent_dir, Config), - ?line MgrDir = ?config(mgr_dir, Config), - ?line Ip = ?config(ip, Config), - ?line otp_4394_config(AgentDir, MgrDir, Ip), - MasterAgentVerbosity = {master_agent_verbosity, trace}, - NetIfVerbosity = {net_if_verbosity, trace}, - Opts = [MasterAgentVerbosity,NetIfVerbosity], - [{vsn, v1} | start_v1_agent(Config,Opts)]. - -otp_4394_config(AgentDir, MgrDir, Ip0) -> - ?DBG("otp_4394_config -> entry with" - "~n AgentDir: ~p" - "~n MgrDir: ~p" - "~n Ip0: ~p", [AgentDir, MgrDir, Ip0]), - Vsn = [v1], - Ip = tuple_to_list(Ip0), - ?line snmp_config:write_agent_snmp_files(AgentDir, Vsn, Ip, - ?TRAP_UDP, Ip, 4000, - "OTP-4394 test"), - ?line case update_usm(Vsn, AgentDir) of - true -> - ?line copy_file(filename:join(AgentDir, "usm.conf"), - filename:join(MgrDir, "usm.conf")), - ?line update_usm_mgr(Vsn, MgrDir); - false -> - ?line ok - end, - C1 = {"a", "all-rights", "initial", "", "pc"}, - C2 = {"c", "secret", "secret_name", "", "secret_tag"}, - ?line write_community_conf(AgentDir, [C1, C2]), - ?line update_vacm(Vsn, AgentDir), - Ta1 = {"shelob v1", - [134,138,177,177], 5000, 1500, 3, %% Använd Ip och modda - "pc1", - "target_v1", "", - %% [255,255,255,255,0,0], - [], - 2048}, - Ta2 = {"bifur v1", - [134,138,177,75], 5000, 1500, 3, %% Använd Ip - "pc2", - "target_v1", "", - %% [255,255,255,255,0,0], - [], 2048}, - ?line write_target_addr_conf(AgentDir, [Ta1, Ta2]), - ?line write_target_params_conf(AgentDir, Vsn), - ?line write_notify_conf(AgentDir), - ok. - - - -finish_otp_4394(Config) when list(Config) -> - ?DBG("finish_otp_4394 -> entry", []), - C1 = stop_agent(Config), - delete_files(C1), - erase(mgr_node), - lists:keydelete(vsn, 1, C1). - -otp_4394_test(suite) -> []; -otp_4394_test(Config) -> - ?DBG("otp_4394_test -> entry", []), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - try_test(otp_4394_test1), - ?DBG("otp_4394_test -> done", []), - ok. - -otp_4394_test1() -> - ?DBG("otp_4394_test1 -> entry", []), - gn([[1,1]]), - Res = - case snmp_test_mgr:expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]) of - %% {error, 1, {"?",[]}, {"~w",[timeout]}} - {error, 1, _, {_, [timeout]}} -> - ?DBG("otp_4394_test1 -> expected result: timeout", []), - ok; - Else -> - Else - end, - ?DBG("otp_4394_test1 -> done with: ~p", [Res]), - Res. - - -%%%-------------------------------------------------- -%%% Used to test the standard mib with our -%%% configuration. -%%%-------------------------------------------------- -run(F, A, Opts) -> - M = get(mib_dir), - Dir = get(mgr_dir), - User = snmp_misc:get_option(user, Opts, "all-rights"), - SecLevel = snmp_misc:get_option(sec_level, Opts, noAuthNoPriv), - EngineID = snmp_misc:get_option(engine_id, Opts, "agentEngine"), - CtxEngineID = snmp_misc:get_option(context_engine_id, Opts, EngineID), - Community = snmp_misc:get_option(community, Opts, "all-rights"), - ?DBG("run -> start crypto app",[]), - Crypto = case os:type() of - vxworks -> - no_crypto; - _ -> - ?CRYPTO_START() - end, - ?DBG("run -> Crypto: ~p",[Crypto]), - catch snmp_test_mgr:stop(), % If we had a running mgr from a failed case - StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", - ?DBG("run -> config:~n" - "\tM: ~p~n" - "\tDir: ~p~n" - "\tUser: ~p~n" - "\tSecLevel: ~p~n" - "\tEngineID: ~p~n" - "\tCtxEngineID: ~p~n" - "\tCommunity: ~p~n" - "\tStdM: ~p", - [M,Dir,User,SecLevel,EngineID,CtxEngineID,Community,StdM]), - case snmp_test_mgr:start([%% {agent, snmp_test_lib:hostname()}, - {packet_server_debug,true}, - {debug,true}, - {agent, get(master_host)}, - {agent_udp, 4000}, - {trap_udp, 5000}, - {recbuf,65535}, - quiet, - get(vsn), - {community, Community}, - {user, User}, - {sec_level, SecLevel}, - {engine_id, EngineID}, - {context_engine_id, CtxEngineID}, - {dir, Dir}, - {mibs, mibs(StdM, M)}]) of - {ok, _Pid} -> - Res = apply(?MODULE, F, A), - catch snmp_test_mgr:stop(), - Res; - Err -> - io:format("Error starting manager: ~p\n", [Err]), - catch snmp_test_mgr:stop(), - ?line exit({mgr_start, Err}) - end. - - -mibs(StdMibDir,MibDir) -> - [join(StdMibDir, ?v1_2("STANDARD-MIB.bin", "SNMPv2-MIB.bin")), - join(MibDir, "OLD-SNMPEA-MIB.bin"), - join(StdMibDir, "SNMP-FRAMEWORK-MIB"), - join(StdMibDir, "SNMP-MPD-MIB"), - join(StdMibDir, "SNMP-VIEW-BASED-ACM-MIB"), - join(StdMibDir, "SNMP-USER-BASED-SM-MIB"), - join(StdMibDir, "SNMP-TARGET-MIB"), - join(StdMibDir, "SNMP-NOTIFICATION-MIB"), - join(MibDir, "Klas1.bin"), - join(MibDir, "Klas2.bin"), - join(MibDir, "Klas3.bin"), - join(MibDir, "Klas4.bin"), - join(MibDir, "SA-MIB.bin"), - join(MibDir, "TestTrap.bin"), - join(MibDir, "Test1.bin"), - join(MibDir, "Test2.bin"), - join(MibDir, "TestTrapv2.bin")]. - -join(D,F) -> - filename:join(D,F). - -%% string used in index -is(S) -> [length(S) | S]. - -try_test(Func) -> - call(get(mgr_node), ?MODULE, run, [Func, [], []]). - -try_test(Func, A) -> - call(get(mgr_node), ?MODULE, run, [Func, A, []]). - -try_test(Func, A, Opts) -> - call(get(mgr_node), ?MODULE, run, [Func, A, Opts]). - -call(N,M,F,A) -> - ?DBG("call -> entry with~n" - " N: ~p~n" - " M: ~p~n" - " F: ~p~n" - " A: ~p~n" - " when~n" - " get(): ~p", - [N,M,F,A,get()]), - spawn(N, ?MODULE, wait, [self(),get(),M,F,A]), - receive - {done, {'EXIT', Rn}, Loc} -> - ?DBG("call -> returned ~p",[{done, {'EXIT', Rn}, Loc}]), - put(test_server_loc, Loc), - exit(Rn); - {done, Ret, Zed} -> - ?DBG("call -> returned ~p~n",[{done, Ret, Zed}]), - Ret - end. - -wait(From, Env, M, F, A) -> - ?DBG("wait -> entry with ~n" - "\tFrom: ~p~n" - "\tEnv: ~p",[From,Env]), - lists:foreach(fun({K,V}) -> put(K,V) end, Env), - Rn = (catch apply(M, F, A)), - ?DBG("wait -> Rn: ~n~p", [Rn]), - From ! {done, Rn, get(test_server_loc)}, - exit(Rn). - -expect(A,B) -> ok = snmp_test_mgr:expect(A,B). -expect(A,B,C) -> ok = snmp_test_mgr:expect(A,B,C). -expect(A,B,C,D) -> ok = snmp_test_mgr:expect(A,B,C,D). -expect(A,B,C,D,E,F) -> ok = snmp_test_mgr:expect(A,B,C,D,E,F). - -get_req(Id, Vars) -> - ?DBG("get_req -> entry with~n" - "\tId: ~p~n" - "\tVars: ~p",[Id,Vars]), - g(Vars), - ?DBG("get_req -> await response",[]), - {ok, Val} = snmp_test_mgr:get_response(Id, Vars), - ?DBG("get_req -> response: ~p",[Val]), - Val. - -get_next_req(Vars) -> - ?DBG("get_next_req -> entry with Vars '~p', send request",[Vars]), - gn(Vars), - ?DBG("get_next_req -> await response",[]), - Response = snmp_test_mgr:receive_response(), - ?DBG("get_next_req -> response: ~p",[Response]), - Response. - - - -start_node(Name) -> - ?LOG("start_node -> entry with Name: ~p",[Name]), - M = list_to_atom(?HOSTNAME(node())), - ?DBG("start_node -> M: ~p",[M]), - Pa = filename:dirname(code:which(?MODULE)), - ?DBG("start_node -> Pa: ~p",[Pa]), - - Args = case init:get_argument('CC_TEST') of - {ok, [[]]} -> - " -pa /clearcase/otp/libraries/snmp/ebin "; - {ok, [[Path]]} -> - " -pa " ++ Path; - error -> - "" - end, - %% Do not use start_link!!! (the proc that calls this one is tmp) - ?DBG("start_node -> Args: ~p~n",[Args]), - A = Args ++ " -pa " ++ Pa, - case (catch ?START_NODE(Name, A)) of - {ok, Node} -> - %% Tell the test_server to not clean up things it never started. - ?DBG("start_node -> Node: ~p",[Node]), - {ok, Node}; - Else -> - ?ERR("start_node -> failed with(other): Else: ~p",[Else]), - ?line ?FAIL(Else) - end. - - -stop_node(Node) -> - ?LOG("stop_node -> Node: ~p",[Node]), - rpc:cast(Node, erlang, halt, []). - -p(X) -> - io:format(user, X++"\n", []). - -sleep(X) -> - receive - after - X -> ok - end. - -%%%----------------------------------------------------------------- -%%% Configuration -%%%----------------------------------------------------------------- -config(Vsns, MgrDir, AgentDir, MIp, AIp) -> - ?line snmp_config:write_agent_snmp_files(AgentDir, Vsns, MIp, - ?TRAP_UDP, AIp, 4000, - "test"), - ?line case update_usm(Vsns, AgentDir) of - true -> - ?line copy_file(filename:join(AgentDir, "usm.conf"), - filename:join(MgrDir, "usm.conf")), - ?line update_usm_mgr(Vsns, MgrDir); - false -> - ?line ok - end, - ?line update_community(Vsns, AgentDir), - ?line update_vacm(Vsns, AgentDir), - ?line write_target_addr_conf(AgentDir, MIp, ?TRAP_UDP, Vsns), - ?line write_target_params_conf(AgentDir, Vsns), - ?line write_notify_conf(AgentDir), - ok. - -delete_files(Config) -> - Dir = ?config(agent_dir, Config), - {ok, List} = file:list_dir(Dir), - lists:foreach(fun(FName) -> file:delete(filename:join(Dir, FName)) end, - List). - -update_usm(Vsns, Dir) -> - case lists:member(v3, Vsns) of - true -> - {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),[read,write]), - file:position(Fid, eof), - ok = io:format(Fid, "{\"agentEngine\", \"all-rights\", " - "\"all-rights\", zeroDotZero, " - "usmNoAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"\", \"\"}.\n", []), - ok = io:format(Fid, "{\"agentEngine\", \"no-rights\", " - "\"no-rights\", zeroDotZero, " - "usmNoAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"\", \"\"}.\n", []), - ok = io:format(Fid, "{\"agentEngine\", \"authMD5\", " - "\"authMD5\", zeroDotZero, " - "usmHMACMD5AuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"passwd_md5xxxxxx\", \"\"}.\n", []), - ok = io:format(Fid, "{\"agentEngine\", \"authSHA\", " - "\"authSHA\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"\"}.\n", []), - ok = io:format(Fid, "{\"agentEngine\", \"privDES\", " - "\"privDES\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", - []), - ok = io:format(Fid, "{\"mgrEngine\", \"all-rights\", " - "\"all-rights\", zeroDotZero, " - "usmNoAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"\", \"\"}.\n", []), - ok = io:format(Fid, "{\"mgrEngine\", \"no-rights\", " - "\"no-rights\", zeroDotZero, " - "usmNoAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"\", \"\"}.\n", []), - ok = io:format(Fid, "{\"mgrEngine\", \"authMD5\", " - "\"authMD5\", zeroDotZero, " - "usmHMACMD5AuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"passwd_md5xxxxxx\", \"\"}.\n", []), - ok = io:format(Fid, "{\"mgrEngine\", \"authSHA\", " - "\"authSHA\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"\"}.\n", []), - ok = io:format(Fid, "{\"mgrEngine\", \"privDES\", " - "\"privDES\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", - []), - file:close(Fid), - true; - false -> - false - end. - -update_usm_mgr(Vsns, Dir) -> - case lists:member(v3, Vsns) of - true -> - {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),[read,write]), - file:position(Fid, eof), - ok = io:format(Fid, "{\"agentEngine\", \"newUser\", " - "\"newUser\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", - []), - ok = io:format(Fid, "{\"mgrEngine\", \"newUser\", " - "\"newUser\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", - []), - file:close(Fid), - true; - false -> - false - end. - -rewrite_usm_mgr(Dir, ShaKey, DesKey) -> - ?line ok = file:rename(filename:join(Dir,"usm.conf"), - filename:join(Dir,"usm.old")), - ?line {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),write), - ok = io:format(Fid, "{\"agentEngine\", \"newUser\", " - "\"newUser\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"~s\", \"~s\"}.\n", - [ShaKey, DesKey]), - ok = io:format(Fid, "{\"mgrEngine\", \"newUser\", " - "\"newUser\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"~s\", \"~s\"}.\n", - [ShaKey, DesKey]), - file:close(Fid). - -reset_usm_mgr(Dir) -> - ?line ok = file:rename(filename:join(Dir,"usm.old"), - filename:join(Dir,"usm.conf")). - - -update_community([v3], _Dir) -> ok; -update_community(_, Dir) -> - {ok, Fid} = file:open(filename:join(Dir,"community.conf"),[read,write]), - file:position(Fid, eof), - ok=io:format(Fid,"{\"no-rights\",\"no-rights\",\"no-rights\",\"\",\"\"}.\n", - []), - file:close(Fid). - - --define(tDescr_instance, [1,3,6,1,2,1,16,1,0]). -update_vacm(_Vsn, Dir) -> - {ok, Fid} = file:open(filename:join(Dir,"vacm.conf"),[read,write]), - file:position(Fid, eof), - ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"authMD5\",\"initial\"}.\n",[]), - ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"authSHA\",\"initial\"}.\n",[]), - ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"privDES\",\"initial\"}.\n",[]), - ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"newUser\",\"initial\"}.\n",[]), - ok = io:format(Fid, "{vacmViewTreeFamily, \"internet\", " - "~w, excluded, null}.\n", [?tDescr_instance]), - file:close(Fid). - - -vacm_ver(v1) -> v1; -vacm_ver(v2) -> v2c; -vacm_ver(v3) -> usm. - - -write_community_conf(Dir, Confs) -> - {ok, Fid} = file:open(filename:join(Dir,"community.conf"),write), - ok = write_community_conf1(Fid, Confs), - file:close(Fid). - -write_community_conf1(_, []) -> - ok; -write_community_conf1(Fid, [{ComIdx, ComName, SecName, CtxName, TransTag}|Confs]) -> - ok = io:format(Fid, "{\"~s\", \"~s\", \"~s\", \"~s\", \"~s\"}.~n", - [ComIdx, ComName, SecName, CtxName, TransTag]), - write_community_conf1(Fid, Confs). - - -write_target_addr_conf(Dir, Confs) -> - {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), - ok = write_target_addr_conf1(Fid, Confs), - file:close(Fid). - - -write_target_addr_conf1(_, []) -> - ok; -write_target_addr_conf1(Fid, - [{Name, Ip, Port, Timeout, Retry, TagList, ParamName, - EngineId, TMask, MaxMsgSz}|Confs]) -> - ok = io:format(Fid, "{\"~s\", ~w, ~w, ~w, ~w, \"~s\", \"~s\", \"~s\", ~w, ~w}.~n", - [Name, Ip, Port, Timeout, Retry, TagList, ParamName, - EngineId, TMask, MaxMsgSz]), - write_target_addr_conf1(Fid, Confs). - -write_target_addr_conf(Dir, ManagerIp, UDP, Vsns) -> - {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), - lists:foreach(fun(Vsn) -> - ok = io:format(Fid, - "{\"~s\", ~w, ~w, 1500, 3, " - "\"std_trap\", \"~s\"}.~n", - [mk_ip(ManagerIp, Vsn), - ManagerIp, UDP, mk_param(Vsn)]), - case Vsn of - v1 -> ok; - v2 -> - ok = io:format(Fid, - "{\"~s.2\",~w,~w,1500,3, " - "\"std_inform\", \"~s\"}.~n", - [mk_ip(ManagerIp, Vsn), - ManagerIp, UDP, - mk_param(Vsn)]); - v3 -> - ok = io:format(Fid, - "{\"~s.3\",~w,~w,1500,3, " - "\"std_inform\", \"~s\", " - "\"mgrEngine\", [], 1024}.~n", - [mk_ip(ManagerIp, Vsn), - ManagerIp, UDP, - mk_param(Vsn)]) - end - end, - Vsns), - file:close(Fid). - -mk_param(v1) -> "target_v1"; -mk_param(v2) -> "target_v2"; -mk_param(v3) -> "target_v3". - -mk_ip([A,B,C,D], Vsn) -> - io_lib:format("~w.~w.~w.~w ~w", [A,B,C,D,Vsn]). - - -rewrite_target_addr_conf(Dir,NewPort) -> - TAFile = filename:join(Dir, "target_addr.conf"), - ?DBG("rewrite_target_addr_conf -> read target file info of address config file",[]), - case file:read_file_info(TAFile) of - {ok, _} -> ok; - {error, R} -> ?ERR("failure reading file info of " - "target address config file: ~p",[R]), - ok - end, - - ?line [TrapAddr|Addrs] = - snmp_conf:read(TAFile,fun(R) -> rewrite_target_addr_conf1(R) end), - - ?DBG("rewrite_target_addr_conf -> TrapAddr: ~p",[TrapAddr]), - - NewAddrs = [rewrite_target_addr_conf2(NewPort,TrapAddr)|Addrs], - - ?DBG("rewrite_target_addr_conf -> NewAddrs: ~p",[NewAddrs]), - - ?line ok = file:rename(filename:join(Dir,"target_addr.conf"), - filename:join(Dir,"target_addr.old")), - ?line {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), - - ?line ok = rewrite_target_addr_conf3(Fid,NewAddrs), - - file:close(Fid). - -rewrite_target_addr_conf1(O) -> - {ok,O}. - -rewrite_target_addr_conf2(NewPort,{Name,Ip,_Port,Timeout,Retry, - "std_trap",EngineId}) -> - ?LOG("rewrite_target_addr_conf2 -> entry with std_trap",[]), - {Name,Ip,NewPort,Timeout,Retry,"std_trap",EngineId}; -rewrite_target_addr_conf2(_NewPort,O) -> - ?LOG("rewrite_target_addr_conf2 -> entry with " - "~n O: ~p",[O]), - O. - - -rewrite_target_addr_conf3(_,[]) -> ok; -rewrite_target_addr_conf3(Fid,[{Name,Ip,Port,Timeout,Retry, - ParamName,EngineId}|T]) -> - ?LOG("rewrite_target_addr_conf3 -> write(1) ~s",[ParamName]), - io:format(Fid, - "{\"~s\", " % Name - "~p, " % Ip - "~p, " % Port - "~p, " % Timeout - "~p, " % Retry - "\"~s\", " % ParamsName - "\"~s\"}.", % EngineId - [Name,Ip,Port,Timeout,Retry,ParamName,EngineId]), - rewrite_target_addr_conf3(Fid,T); -rewrite_target_addr_conf3(Fid,[{Name,Ip,Port,Timeout,Retry,TagList, - ParamName,EngineId,TMask,MMS}|T]) -> - ?LOG("rewrite_target_addr_conf3 -> write(2) ~s",[ParamName]), - io:format(Fid, - "{\"~s\", " % Name - "~p, " % Ip - "~p, " % Port - "~p, " % Timeout - "~p, " % Retry - "\"~s\", " % TagList - "\"~s\", " % ParamsName - "\"~s\"," % EngineId - "~p, " % TMask - "~p}.", % MMS - [Name,Ip,Port,Timeout,Retry,TagList,ParamName, - EngineId,TMask,MMS]), - rewrite_target_addr_conf3(Fid,T). - -reset_target_addr_conf(Dir) -> - ?line ok = file:rename(filename:join(Dir,"target_addr.old"), - filename:join(Dir,"target_addr.conf")). - -write_target_params_conf(Dir, Vsns) -> - {ok, Fid} = file:open(filename:join(Dir,"target_params.conf"),write), - lists:foreach(fun(Vsn) -> - MP = if Vsn == v1 -> v1; - Vsn == v2 -> v2c; - Vsn == v3 -> v3 - end, - SM = if Vsn == v1 -> v1; - Vsn == v2 -> v2c; - Vsn == v3 -> usm - end, - ok = io:format(Fid, "{\"target_~w\", ~w, ~w, " - "\"all-rights\", noAuthNoPriv}.~n", - [Vsn, MP, SM]) - end, - Vsns), - file:close(Fid). - -rewrite_target_params_conf(Dir, SecName, SecLevel) -> - ?line ok = file:rename(filename:join(Dir,"target_params.conf"), - filename:join(Dir,"target_params.old")), - ?line {ok, Fid} = file:open(filename:join(Dir,"target_params.conf"),write), - ?line ok = io:format(Fid, "{\"target_v3\", v3, usm, \"~s\", ~w}.~n", - [SecName, SecLevel]), - file:close(Fid). - -reset_target_params_conf(Dir) -> - ?line ok = file:rename(filename:join(Dir,"target_params.old"), - filename:join(Dir,"target_params.conf")). - -write_notify_conf(Dir) -> - {ok, Fid} = file:open(filename:join(Dir,"notify.conf"),write), - ok = io:format(Fid, "{\"standard trap\", \"std_trap\", trap}.~n", []), - ok = io:format(Fid, "{\"standard inform\", \"std_inform\",inform}.~n", []), - file:close(Fid). - -ver_to_trap_str([v1]) -> "v1"; -ver_to_trap_str([v2]) -> "v2"; -% default is to use the latest snmp version -ver_to_trap_str([v1,v2]) -> "v2". - - - -write_view_conf(Dir) -> - {ok, Fid} = file:open(a(Dir,"view.conf"),write), - ok = io:format(Fid, "{2, [1,3,6], included, null}.~n", []), - ok = io:format(Fid, "{2, ~w, excluded, null}.~n", [?tDescr_instance]), - file:close(Fid). - -a(A,B) -> lists:append(A,B). - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -copy_file(From, To) -> - {ok, Bin} = file:read_file(From), - ok = file:write_file(To, Bin). - - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -display_memory_usage() -> - Info = snmpa:info(snmp_master_agent), - TreeSize = lists_key1search(tree_size_bytes, Info), - ProcMem = lists_key1search(process_memory, Info), - MibDbSize = lists_key1search([db_memory,mib], Info), - NodeDbSize = lists_key1search([db_memory,node], Info), - TreeDbSize = lists_key1search([db_memory,tree], Info), - ?INF("Memory usage: " - "~n Tree size: ~p" - "~n Process memory size: ~p" - "~n Mib db size: ~p" - "~n Node db size: ~p" - "~n Tree db size: ~p", - [TreeSize, ProcMem, MibDbSize, NodeDbSize, TreeDbSize]). - -lists_key1search([], Res) -> - Res; -lists_key1search([Key|Keys], List) when atom(Key), list(List) -> - case lists:keysearch(Key, 1, List) of - {value, {Key, Val}} -> - lists_key1search(Keys, Val); - false -> - undefined - end; -lists_key1search(Key, List) when atom(Key) -> - case lists:keysearch(Key, 1, List) of - {value, {Key, Val}} -> - Val; - false -> - undefined - end. - - -regs() -> - lists:sort(registered()). diff --git a/lib/snmp/test/snmp_agent_mt_test.erl b/lib/snmp/test/snmp_agent_mt_test.erl deleted file mode 100644 index 4f125c0017..0000000000 --- a/lib/snmp/test/snmp_agent_mt_test.erl +++ /dev/null @@ -1,5649 +0,0 @@ -%% -%% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2005-2010. All Rights Reserved. -%% -%% The contents of this file are subject to the Erlang Public License, -%% Version 1.1, (the "License"); you may not use this file except in -%% compliance with the License. You should have received a copy of the -%% Erlang Public License along with this software. If not, it can be -%% retrieved online at http://www.erlang.org/. -%% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -%% the License for the specific language governing rights and limitations -%% under the License. -%% -%% %CopyrightEnd% -%% - --module(snmp_agent_mt_test). - -%% TODO -%% * Test fault-tolerance (kill master etc) -%% - --compile(export_all). - --define(application, snmp). - --include_lib("kernel/include/file.hrl"). --include_lib("test_server/include/test_server.hrl"). --include("snmp_test_lib.hrl"). --define(SNMP_USE_V3, true). --include_lib("snmp/include/snmp_types.hrl"). -%% -include_lib("snmp/include/SNMP-COMMUNITY-MIB.hrl"). -%% -include_lib("snmp/include/SNMP-VIEW-BASED-ACM-MIB.hrl"). -%% -include_lib("snmp/include/SNMP-USER-BASED-SM-MIB.hrl"). - - --define(klas1, [1,3,6,1,2,1,7]). --define(klas2, [1,3,6,1,2,1,9]). --define(klas3, [1,3,6,1,2,1,8,1]). --define(klas4, [1,3,6,1,2,1,8,4]). --define(sa, [1,3,6,1,4,1,193,2]). --define(system, [1,3,6,1,2,1,1]). --define(snmp, [1,3,6,1,2,1,11]). --define(snmpTraps, [1,3,6,1,6,3,1,1,5]). --define(ericsson, [1,3,6,1,4,1,193]). --define(testTrap, [1,3,6,1,2,1,15,0]). --define(xDescr, [1,3,6,1,2,1,17,1]). --define(xDescr2, [1,3,6,1,2,1,17,2]). - --define(active, 1). --define(notInService, 2). --define(notReady, 3). --define(createAndGo, 4). --define(createAndWait, 5). --define(destroy, 6). - --define(TRAP_UDP, 5000). - --define(tooBigStr, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"). - --define(str(X), snmp_pdus:bits_to_str(X)). - --define(break(), begin io:format(user, "break at line ~w: pid: ~p\n", - [?LINE, self()]), - receive cont -> ok end - end). - - --import(snmp_test_mgr, [gn/1, g/1, s/1, gb/3]). --define(v1_2(V1,V2), - case get(vsn) of - v1 -> V1; - _ -> V2 - end). - --define(v1_2_3(V1,V2,V3), - case get(vsn) of - v1 -> V1; - v2 -> V2; - _ -> V3 - end). - -all() -> -[cases()]. - -groups() -> - [{mib_storage, [], - [{group, mib_storage_ets}, {group, mib_storage_dets}, - {group, mib_storage_mnesia}, - {group, mib_storage_size_check_ets}, - {group, mib_storage_size_check_dets}, - {group, mib_storage_size_check_mnesia}, - {group, mib_storage_varm_dets}, - {group, mib_storage_varm_mnesia}]}, - {mib_storage_ets, [], mib_storage_ets_cases()}, - {mib_storage_dets, [], mib_storage_dets_cases()}, - {mib_storage_mnesia, [], mib_storage_mnesia_cases()}, - {mib_storage_size_check_ets, [], - mse_size_check_cases()}, - {mib_storage_size_check_dets, [], - msd_size_check_cases()}, - {mib_storage_size_check_mnesia, [], - msm_size_check_cases()}, - {mib_storage_varm_dets, [], - varm_mib_storage_dets_cases()}, - {mib_storage_varm_mnesia, [], - varm_mib_storage_mnesia_cases()}, - {test_v1, [], v1_cases()}, {test_v2, [], v2_cases()}, - {test_v1_v2, [], v1_v2_cases()}, - {test_v3, [], v3_cases()}, - {test_multi_threaded, [], mt_cases()}, - {multiple_reqs, [], mul_cases()}, - {multiple_reqs_2, [], mul_cases_2()}, - {v2_inform, [], [v2_inform_i]}, - {v3_security, [], - [v3_crypto_basic, v3_md5_auth, v3_sha_auth, - v3_des_priv]}, - {standard_mibs, [], - [snmp_standard_mib, snmp_community_mib, - snmp_framework_mib, snmp_target_mib, - snmp_notification_mib, snmp_view_based_acm_mib]}, - {standard_mibs_2, [], - [snmpv2_mib_2, snmp_community_mib_2, - snmp_framework_mib_2, snmp_target_mib_2, - snmp_notification_mib_2, snmp_view_based_acm_mib_2]}, - {standard_mibs_3, [], - [snmpv2_mib_3, snmp_framework_mib_3, snmp_mpd_mib_3, - snmp_target_mib_3, snmp_notification_mib_3, - snmp_view_based_acm_mib_3, snmp_user_based_sm_mib_3]}, - {reported_bugs, [], - [otp_1128, otp_1129, otp_1131, otp_1162, otp_1222, - otp_1298, otp_1331, otp_1338, otp_1342, otp_2776, - otp_2979, otp_3187, otp_3725]}, - {reported_bugs_2, [], - [otp_1128_2, otp_1129_2, otp_1131_2, otp_1162_2, - otp_1222_2, otp_1298_2, otp_1331_2, otp_1338_2, - otp_1342_2, otp_2776_2, otp_2979_2, otp_3187_2]}, - {reported_bugs_3, [], - [otp_1128_3, otp_1129_3, otp_1131_3, otp_1162_3, - otp_1222_3, otp_1298_3, otp_1331_3, otp_1338_3, - otp_1342_3, otp_2776_3, otp_2979_3, otp_3187_3, - otp_3542]}, - {tickets, [], [{group, otp_4394}]}, - {otp_4394, [], [otp_4394_test]}]. - -init_per_group(otp_4394, Config) -> - init_otp_4394(Config); -init_per_group(v2_inform, Config) -> - init_v2_inform(Config); -init_per_group(multiple_reqs_2, Config) -> - init_mul(Config); -init_per_group(multiple_reqs, Config) -> - init_mul(Config); -init_per_group(test_multi_threaded, Config) -> - init_mt(Config); -init_per_group(test_v3, Config) -> - init_v3(Config); -init_per_group(test_v1_v2, Config) -> - init_v1_v2(Config); -init_per_group(test_v2, Config) -> - init_v2(Config); -init_per_group(test_v1, Config) -> - init_v1(Config); -init_per_group(mib_storage_varm_mnesia, Config) -> - init_varm_mib_storage_mnesia(Config); -init_per_group(mib_storage_varm_dets, Config) -> - init_varm_mib_storage_dets(Config); -init_per_group(mib_storage_size_check_mnesia, Config) -> - init_size_check_msm(Config); -init_per_group(mib_storage_size_check_dets, Config) -> - init_size_check_msd(Config); -init_per_group(mib_storage_size_check_ets, Config) -> - init_size_check_mse(Config); -init_per_group(mib_storage_mnesia, Config) -> - init_mib_storage_mnesia(Config); -init_per_group(mib_storage_dets, Config) -> - init_mib_storage_dets(Config); -init_per_group(mib_storage_ets, Config) -> - init_mib_storage_ets(Config); -init_per_group(_GroupName, Config) -> - Config. - -end_per_group(otp_4394, Config) -> - finish_otp_4394(Config); -end_per_group(v2_inform, Config) -> - finish_v2_inform(Config); -end_per_group(multiple_reqs_2, Config) -> - finish_mul(Config); -end_per_group(multiple_reqs, Config) -> - finish_mul(Config); -end_per_group(test_multi_threaded, Config) -> - finish_mt(Config); -end_per_group(test_v3, Config) -> - finish_v3(Config); -end_per_group(test_v1_v2, Config) -> - finish_v1_v2(Config); -end_per_group(test_v2, Config) -> - finish_v2(Config); -end_per_group(test_v1, Config) -> - finish_v1(Config); -end_per_group(mib_storage_varm_mnesia, Config) -> - finish_varm_mib_storage_mnesia(Config); -end_per_group(mib_storage_varm_dets, Config) -> - finish_varm_mib_storage_dets(Config); -end_per_group(mib_storage_size_check_mnesia, Config) -> - finish_size_check_msm(Config); -end_per_group(mib_storage_size_check_dets, Config) -> - finish_size_check_msd(Config); -end_per_group(mib_storage_size_check_ets, Config) -> - finish_size_check_mse(Config); -end_per_group(mib_storage_mnesia, Config) -> - finish_mib_storage_mnesia(Config); -end_per_group(mib_storage_dets, Config) -> - finish_mib_storage_dets(Config); -end_per_group(mib_storage_ets, Config) -> - finish_mib_storage_ets(Config); -end_per_group(_GroupName, Config) -> - Config. - - -init_per_testcase(_Case, Config) when list(Config) -> - Dog = ?t:timetrap(?t:minutes(6)), - [{watchdog, Dog}|Config]. - -end_per_testcase(_Case, Config) when list(Config) -> - Dog = ?config(watchdog, Config), - ?t:timetrap_cancel(Dog), - Config. - -cases() -> -case ?OSTYPE() of - vxworks -> - [app_info, {group, test_v1}, {group, test_v2}, - {group, test_v1_v2}, {group, test_multi_threaded}, - {group, mib_storage}, {group, tickets}]; - _Else -> - [app_info, {group, test_v1}, {group, test_v2}, - {group, test_v1_v2}, {group, test_v3}, - {group, test_multi_threaded}, {group, mib_storage}, - {group, tickets}] -end. - - -%%%----------------------------------------------------------------- -%%% The test case structure is as follows: -%%% -%%% init_all - starts mnesia, -%%% -%%% init_v1 - starts agent -%%% simple -%%% big - e.g. starts/stops subagent, load/unloads mibs -%%% init_mul -%%% mul_get -%%% mul_set -%%% -%%% finish_mul -%%% -%%% finish_v1 -%%% -%%% init_v2 - starts agent -%%% finish_v2 -%%% -%%% init_bilingual - starts agent -%%% finish_bilingual -%%% -%%% finish_all -%%% -%%% There is still one problem with these testsuites. If one test -%%% fails, it may not be possible to run some other cases, as it -%%% may have e.g. created some row or loaded some table, that it -%%% didn't undo (since it failed). -%%%----------------------------------------------------------------- - -init_all(Config0) when list(Config0) -> - ?LOG("init_all -> entry with" - "~n Config0: ~p",[Config0]), - - %% -- - %% Fix config: - %% - - DataDir0 = ?config(data_dir, Config0), - DataDir1 = filename:split(filename:absname(DataDir0)), - [_|DataDir2] = lists:reverse(DataDir1), - DataDir3 = filename:join(lists:reverse(DataDir2) ++ [?snmp_test_data]), - Config1 = lists:keydelete(data_dir, 1, Config0), - Config = [{data_dir, DataDir3 ++ "/"}|Config1], - - %% -- - %% Start nodes - %% - - ?line {ok, SaNode} = start_node(snmp_sa), - ?line {ok, MgrNode} = start_node(snmp_mgr), - - - %% -- - %% Create necessary files - %% - - Dir = ?config(priv_dir, Config), - ?DBG("init_all -> Dir ~p", [Dir]), - - DataDir = ?config(data_dir, Config), - ?DBG("init_all -> DataDir ~p", [DataDir]), - - file:make_dir(MgrDir = filename:join(Dir, "mgr_dir/")), - ?DBG("init_all -> MgrDir ~p", [MgrDir]), - - file:make_dir(AgentDir = filename:join(Dir, "agent_dir/")), - ?DBG("init_all -> AgentDir ~p", [AgentDir]), - - file:make_dir(SaDir = filename:join(Dir, "sa_dir/")), - ?DBG("init_all -> SaDir ~p", [SaDir]), - - - %% -- - %% Start and initiate mnesia - %% - - ?DBG("init_all -> load application mnesia", []), - ?line ok = application:load(mnesia), - - ?DBG("init_all -> load application mnesia on node ~p", [SaNode]), - ?line ok = rpc:call(SaNode, application, load, [mnesia]), - - ?DBG("init_all -> application mnesia: set_env dir",[]), - ?line application_controller:set_env(mnesia, dir, - filename:join(Dir, "Mnesia1")), - - ?DBG("init_all -> application mnesia: set_env dir on node ~p",[SaNode]), - ?line rpc:call(SaNode, application_controller, set_env, - [mnesia, dir, filename:join(Dir, "Mnesia2")]), - - ?DBG("init_all -> create mnesia schema",[]), - ?line ok = mnesia:create_schema([SaNode, node()]), - - ?DBG("init_all -> start application mnesia",[]), - ?line ok = application:start(mnesia), - - ?DBG("init_all -> start application mnesia on ~p",[SaNode]), - ?line ok = rpc:call(SaNode, application, start, [mnesia]), - Ip = ?LOCALHOST(), - [{snmp_sa, SaNode}, - {snmp_mgr, MgrNode}, - {agent_dir, AgentDir ++ "/"}, - {mgr_dir, MgrDir ++ "/"}, - {sa_dir, SaDir ++ "/"}, - {mib_dir, DataDir}, - {ip, Ip} | - Config]. - -finish_all(Config) when list(Config) -> - SaNode = ?config(snmp_sa, Config), - MgrNode = ?config(snmp_mgr, Config), - stop_node(SaNode), - stop_node(MgrNode), - application:stop(mnesia). - -start_v1_agent(Config) when list(Config) -> - start_agent(Config, [v1]). - -start_v1_agent(Config,Opts) when list(Config), list(Opts) -> - start_agent(Config, [v1], Opts). - -start_v2_agent(Config) when list(Config) -> - start_agent(Config, [v2]). - -start_v3_agent(Config) when list(Config) -> - start_agent(Config, [v3]). - -start_bilingual_agent(Config) when list(Config) -> - start_agent(Config, [v1,v2]). - -start_multi_threaded_agent(Config) when list(Config) -> - start_agent(Config, [v2], [{snmp_multi_threaded, true}]). - -stop_agent(Config) when list(Config) -> - ?LOG("stop_agent -> entry with" - "~n Config: ~p",[Config]), - - {Sup, Par} = ?config(snmp_sup, Config), - ?DBG("stop_agent -> attempt to stop (sup) ~p" - "~n Sup: ~p" - "~n Par: ~p", - [Sup, - (catch process_info(Sup)), - (catch process_info(Par))]), - stop_sup(Sup, Par), - - {Sup2, Par2} = ?config(snmp_sub, Config), - ?DBG("stop_agent -> attempt to stop (sub) ~p" - "~n Sup2: ~p" - "~n Par2: ~p", - [Sup2, - (catch process_info(Sup2)), - (catch process_info(Par2))]), - stop_sup(Sup2, Par2), - - ?DBG("stop_agent -> done - now cleanup config", []), - C1 = lists:keydelete(snmp_sup, 1, Config), - lists:keydelete(snmp_sub, 1, C1). - - -stop_sup(Pid, _) when node(Pid) == node() -> - case (catch process_info(Pid)) of - PI when list(PI) -> - ?LOG("stop_sup -> attempt to stop ~p", [Pid]), - Ref = erlang:monitor(process, Pid), - exit(Pid, kill), - await_stopped(Pid, Ref); - {'EXIT', _Reason} -> - ?LOG("stop_sup -> ~p not running", [Pid]), - ok - end; -stop_sup(Pid, _) -> - ?LOG("stop_sup -> attempt to stop ~p", [Pid]), - Ref = erlang:monitor(process, Pid), - ?LOG("stop_sup -> Ref: ~p", [Ref]), - %% Pid ! {'EXIT', Parent, shutdown}, % usch - exit(Pid, kill), - await_stopped(Pid, Ref). - -await_stopped(Pid, Ref) -> - receive - {'DOWN', Ref, process, Pid, _Reason} -> - ?DBG("received down message for ~p", [Pid]), - ok - after 10000 -> - ?INF("await_stopped -> timeout for ~p",[Pid]), - erlang:demonitor(Ref), - ?FAIL({failed_stop,Pid}) - end. - - -start_agent(Config, Vsn) -> - start_agent(Config, Vsn, []). -start_agent(Config, Vsn, Opts) -> - ?LOG("start_agent -> entry (~p) with" - "~n Config: ~p" - "~n Vsn: ~p" - "~n Opts: ~p",[node(), Config, Vsn, Opts]), - - ?line AgentDir = ?config(agent_dir, Config), - ?line SaNode = ?config(snmp_sa, Config), - - snmp_app_env_init(vsn_init(Vsn) ++ - [{audit_trail_log, read_write_log}, - {audit_trail_log_dir, AgentDir}, - {audit_trail_log_size, {10240, 10}}, - {force_config_reload, false}, - {snmp_agent_type, master}, - {snmp_config_dir, AgentDir}, - {snmp_db_dir, AgentDir}, - {snmp_local_db_auto_repair, true}, - {snmp_master_agent_verbosity, trace}, - {snmp_supervisor_verbosity, trace}, - {snmp_mibserver_verbosity, trace}, - {snmp_symbolic_store_verbosity, trace}, - {snmp_note_store_verbosity, trace}, - {snmp_net_if_verbosity, trace}], - Opts), - - - process_flag(trap_exit,true), - - {ok, AppSup} = snmp_app_sup:start_link(), - unlink(AppSup), - ?DBG("start_agent -> snmp app supervisor: ~p",[AppSup]), - - ?DBG("start_agent -> start master agent (old style)",[]), - Sup = case (catch snmpa_app:start(normal)) of - {ok, S} -> - ?DBG("start_agent -> started, Sup: ~p",[S]), - S; - - Else -> - ?DBG("start_agent -> unknown result: ~n~p",[Else]), - %% Get info about the apps we depend on - MnesiaInfo = mnesia_running(), - ?FAIL({start_failed,Else,MnesiaInfo}) - end, - - ?DBG("start_agent -> unlink from supervisor",[]), - ?line unlink(Sup), - ?line SaDir = ?config(sa_dir, Config), - ?DBG("start_agent -> (rpc) start sub on ~p",[SaNode]), - ?line {ok, Sub} = rpc:call(SaNode, ?MODULE, start_sub, [SaDir]), - ?DBG("start_agent -> done",[]), - ?line [{snmp_sup, {Sup, self()}}, {snmp_sub, Sub} | Config]. - - -vsn_init(Vsn) -> - vsn_init([v1,v2,v3], Vsn, []). - -vsn_init([], _Vsn, Acc) -> - Acc; -vsn_init([V|Vsns], Vsn, Acc) -> - case lists:member(V, Vsn) of - true -> - vsn_init(Vsns, Vsn, [{V, true}|Acc]); - false -> - vsn_init(Vsns, Vsn, [{V, false}|Acc]) - end. - -snmp_app_env_init(Env0, Opts) -> - ?DBG("snmp_app_env_init -> unload snmp",[]), - ?line application:unload(snmp), - ?DBG("snmp_app_env_init -> load snmp",[]), - ?line application:load(snmp), - ?DBG("snmp_app_env_init -> initiate (snmp) application env",[]), - F1 = fun({Key,Val} = New, Acc0) -> - ?DBG("snmp_app_env_init -> " - "updating setting ~p to ~p", [Key, Val]), - case lists:keyreplace(Key, 1, Acc0, New) of - Acc0 -> - [New|Acc0]; - Acc -> - Acc - end - end, - Env = lists:foldr(F1, Env0, Opts), - ?DBG("snmp_app_env_init -> Env: ~p",[Env]), - F2 = fun({Key,Val}) -> - ?DBG("snmp_app_env_init -> setting ~p to ~p",[Key, Val]), - application_controller:set_env(snmp, Key, Val) - end, - lists:foreach(F2, Env). - - - - -%% Test if application is running -mnesia_running() -> ?IS_MNESIA_RUNNING(). -crypto_running() -> ?IS_CRYPTO_RUNNING(). - - -start_sub(Dir) -> - ?DBG("start_sub -> entry",[]), - Opts = [{db_dir, Dir}, - {supervisor, [{verbosity, trace}]}], - %% BMK BMK -% {ok, P} = snmp_supervisor:start_sub(Dir), - {ok, P} = snmpa_supervisor:start_sub_sup(Opts), - unlink(P), - {ok, {P, self()}}. - -create_tables(SaNode) -> - ?line {atomic, ok} = mnesia:create_table([{name, friendsTable2}, - {ram_copies, [SaNode]}, - {snmp, [{key, integer}]}, - {attributes, [a1,a2,a3]}]), - ?line {atomic, ok} = mnesia:create_table([{name, kompissTable2}, - {ram_copies, [SaNode]}, - {snmp, [{key, integer}]}, - {attributes, [a1,a2,a3]}]), - ?line {atomic, ok} = mnesia:create_table([{name, snmp_variables}, - {attributes, [a1,a2]}]). - -delete_tables() -> - mnesia:delete_table(friendsTable2), - mnesia:delete_table(kompissTable2), - mnesia:delete_table(snmp_variables). - -%% Creation is done in runtime! -delete_mib_storage_mnesia_tables() -> - mnesia:delete_table(snmpa_mib_data), - mnesia:delete_table(snmpa_mib_tree), - mnesia:delete_table(snmpa_symbolic_store). - -%%----------------------------------------------------------------- -%% A test case is always one of: -%% - v1 specific case -%% - v2 specific case -%% - v1 and v2 case -%% All v1 specific cases are prefixed with v1_, and all v2 with -%% v2_. E.g. v1_trap/v2_trap. -%% -%% All other cases are shared. However, the testserver uses the name -%% of the case to generate a file for that case. The same case cannot -%% be used in different configurations in the same suite. Therefore -%% all these functions exists in two variants, the base function -%% , and a second version _2. There may be several -%% versions as well, _N. -%%----------------------------------------------------------------- - - - - - - - - - -mib_storage_ets_cases() -> -[mse_simple, mse_v1_processing, mse_big, mse_big2, - mse_loop_mib, mse_api, mse_sa_register, mse_v1_trap, - mse_sa_error, mse_next_across_sa, mse_undo, - mse_standard_mib, mse_community_mib, mse_framework_mib, - mse_target_mib, mse_notification_mib, - mse_view_based_acm_mib, mse_sparse_table, mse_me_of, - mse_mib_of]. - -mib_storage_dets_cases() -> -[msd_simple, msd_v1_processing, msd_big, msd_big2, - msd_loop_mib, msd_api, msd_sa_register, msd_v1_trap, - msd_sa_error, msd_next_across_sa, msd_undo, - msd_standard_mib, msd_community_mib, msd_framework_mib, - msd_target_mib, msd_notification_mib, - msd_view_based_acm_mib, msd_sparse_table, msd_me_of, - msd_mib_of]. - -mib_storage_mnesia_cases() -> -[msm_simple, msm_v1_processing, msm_big, msm_big2, - msm_loop_mib, msm_api, msm_sa_register, msm_v1_trap, - msm_sa_error, msm_next_across_sa, msm_undo, - msm_standard_mib, msm_community_mib, msm_framework_mib, - msm_target_mib, msm_notification_mib, - msm_view_based_acm_mib, msm_sparse_table, msm_me_of, - msm_mib_of]. - -mse_size_check_cases() -> -[mse_size_check]. - -msd_size_check_cases() -> -[msd_size_check]. - -msm_size_check_cases() -> -[msm_size_check]. - -varm_mib_storage_dets_cases() -> -[msd_varm_mib_start]. - -varm_mib_storage_mnesia_cases() -> -[msm_varm_mib_start]. - -init_mib_storage_ets(Config) when list(Config) -> - ?LOG("init_mib_storage_ets -> entry", []), - MibStorage = {snmp_mib_storage,ets}, - init_ms(Config, [MibStorage]). - -init_mib_storage_dets(Config) when list(Config) -> - ?LOG("init_mib_storage_ets -> entry", []), - ?line AgentDir = ?GCONF(agent_dir, Config), - MibStorage = {snmp_mib_storage,{dets,AgentDir}}, - init_ms(Config, [MibStorage]). - -init_mib_storage_mnesia(Config) when list(Config) -> - ?LOG("init_mib_storage_ets -> entry", []), - MibStorage = {snmp_mib_storage,{mnesia,[]}}, - init_ms(Config, [MibStorage]). - -init_ms(Config, Opts) when list(Config) -> - ?LOG("init_mib_storage_ets -> entry", []), - ?line SaNode = ?GCONF(snmp_sa, Config), - ?line create_tables(SaNode), - ?line AgentDir = ?GCONF(agent_dir, Config), - ?line MgrDir = ?GCONF(mgr_dir, Config), - ?line Ip = ?GCONF(ip, Config), - ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, - MibsVerbosity = {snmp_mibserver_verbosity, trace}, - SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, - Opts1 = [MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity|Opts], - [{vsn, v1} | start_v1_agent(Config,Opts1)]. - -init_size_check_mse(Config) when list(Config) -> - MibStorage = {snmp_mib_storage, ets}, - init_size_check_ms(Config, [MibStorage]). - -init_size_check_msd(Config) when list(Config) -> - AgentDir = ?GCONF(agent_dir, Config), - MibStorage = {snmp_mib_storage, {dets, AgentDir}}, - init_size_check_ms(Config, [MibStorage]). - -init_size_check_msm(Config) when list(Config) -> - MibStorage = {snmp_mib_storage, {mnesia,[]}}, - init_size_check_ms(Config, [MibStorage]). - -init_size_check_ms(Config, Opts) when list(Config) -> - SaNode = ?GCONF(snmp_sa, Config), - %% We are using v3 here, so crypto must be supported or else... - case ?CRYPTO_START() of - ok -> - case ?CRYPTO_SUPPORT() of - {no, Reason} -> - ?SKIP({unsupported_encryption, Reason}); - yes -> - ok - end; - {error, Reason} -> - ?SKIP({failed_starting_crypto, Reason}) - end, - create_tables(SaNode), - AgentDir = ?GCONF(agent_dir, Config), - MgrDir = ?GCONF(mgr_dir, Config), - Ip = ?GCONF(ip, Config), - ?line ok = - config([v3], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v3} | start_agent(Config, [v3], Opts)]. - -init_varm_mib_storage_dets(Config) when list(Config) -> - ?LOG("init_varm_mib_storage_dets -> entry", []), - ?line SaNode = ?GCONF(snmp_sa, Config), - ?line create_tables(SaNode), - ?line AgentDir = ?GCONF(agent_dir, Config), - ?line MgrDir = ?GCONF(mgr_dir, Config), - ?line Ip = ?GCONF(ip, Config), - ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - MibStorage = {snmp_mib_storage,{dets,AgentDir}}, - MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, - MibsVerbosity = {snmp_mibserver_verbosity, trace}, - SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, - Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity], - [{vsn, v1}, {agent_opts,Opts} | Config]. - -init_varm_mib_storage_mnesia(Config) when list(Config) -> - ?LOG("init_varm_mib_storage_mnesia -> entry", []), - ?line SaNode = ?GCONF(snmp_sa, Config), - ?line create_tables(SaNode), - ?line AgentDir = ?GCONF(agent_dir, Config), - ?line MgrDir = ?GCONF(mgr_dir, Config), - ?line Ip = ?GCONF(ip, Config), - ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - MibStorage = {snmp_mib_storage,{mnesia,[]}}, - MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, - MibsVerbosity = {snmp_mibserver_verbosity, trace}, - SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, - Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity], - [{vsn, v1}, {agent_opts,Opts} | Config]. - -finish_mib_storage_ets(Config) when list(Config) -> - ?LOG("finish_mib_storage_ets -> entry", []), - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - C2 = lists:keydelete(vsn, 1, C1), - lists:keydelete(agent_opts, 1, C2). - -finish_mib_storage_dets(Config) when list(Config) -> - ?LOG("finish_mib_storage_dets -> entry", []), - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - C2 = lists:keydelete(vsn, 1, C1), - lists:keydelete(agent_opts, 1, C2). - -finish_mib_storage_mnesia(Config) when list(Config) -> - ?LOG("finish_mib_storage_mnesia -> entry", []), - delete_tables(), - delete_mib_storage_mnesia_tables(), - C1 = stop_agent(Config), - delete_files(C1), - C2 = lists:keydelete(vsn, 1, C1), - lists:keydelete(agent_opts, 1, C2). - -finish_varm_mib_storage_dets(Config) when list(Config) -> - ?LOG("finish_varm_mib_storage_dets -> entry", []), - delete_tables(), - %% C1 = stop_agent(Config), % In case something went wrong... - delete_files(Config), - C2 = lists:keydelete(vsn, 1, Config), - lists:keydelete(agent_opts, 1, C2). - -finish_varm_mib_storage_mnesia(Config) when list(Config) -> - ?LOG("finish_varm_mib_storage_mnesia -> entry", []), - delete_tables(), - delete_mib_storage_mnesia_tables(), - %% C1 = stop_agent(Config), % In case something went wrong... - delete_files(Config), - C2 = lists:keydelete(vsn, 1, Config), - lists:keydelete(agent_opts, 1, C2). - -finish_size_check_mse(Config) when list(Config) -> - finish_size_check_ms(Config). - -finish_size_check_msd(Config) when list(Config) -> - finish_size_check_ms(Config). - -finish_size_check_msm(Config) when list(Config) -> - finish_size_check_ms(Config). - -finish_size_check_ms(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - - -%% These are just interface functions to fool the test server -mse_simple(X) -> simple(X). -mse_v1_processing(X) -> v1_processing(X). -mse_big(X) -> big(X). -mse_big2(X) -> big2(X). -mse_loop_mib(X) -> loop_mib(X). -mse_api(X) -> api(X). -mse_sa_register(X) -> sa_register(X). -mse_v1_trap(X) -> v1_trap(X). -mse_sa_error(X) -> sa_error(X). -mse_next_across_sa(X) -> next_across_sa(X). -mse_undo(X) -> undo(X). -mse_standard_mib(X) -> snmp_standard_mib(X). -mse_community_mib(X) -> snmp_community_mib(X). -mse_framework_mib(X) -> snmp_framework_mib(X). -mse_target_mib(X) -> snmp_target_mib(X). -mse_notification_mib(X) -> snmp_notification_mib(X). -mse_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). -mse_sparse_table(X) -> sparse_table(X). -mse_me_of(X) -> ms_me_of(X). -mse_mib_of(X) -> ms_mib_of(X). - -msd_simple(X) -> simple(X). -msd_v1_processing(X) -> v1_processing(X). -msd_big(X) -> big(X). -msd_big2(X) -> big2(X). -msd_loop_mib(X) -> loop_mib(X). -msd_api(X) -> api(X). -msd_sa_register(X) -> sa_register(X). -msd_v1_trap(X) -> v1_trap(X). -msd_sa_error(X) -> sa_error(X). -msd_next_across_sa(X) -> next_across_sa(X). -msd_undo(X) -> undo(X). -msd_standard_mib(X) -> snmp_standard_mib(X). -msd_community_mib(X) -> snmp_community_mib(X). -msd_framework_mib(X) -> snmp_framework_mib(X). -msd_target_mib(X) -> snmp_target_mib(X). -msd_notification_mib(X) -> snmp_notification_mib(X). -msd_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). -msd_sparse_table(X) -> sparse_table(X). -msd_me_of(X) -> ms_me_of(X). -msd_mib_of(X) -> ms_mib_of(X). - -msm_simple(X) -> simple(X). -msm_v1_processing(X) -> v1_processing(X). -msm_big(X) -> big(X). -msm_big2(X) -> big2(X). -msm_loop_mib(X) -> loop_mib(X). -msm_api(X) -> api(X). -msm_sa_register(X) -> sa_register(X). -msm_v1_trap(X) -> v1_trap(X). -msm_sa_error(X) -> sa_error(X). -msm_next_across_sa(X) -> next_across_sa(X). -msm_undo(X) -> undo(X). -msm_standard_mib(X) -> snmp_standard_mib(X). -msm_community_mib(X) -> snmp_community_mib(X). -msm_framework_mib(X) -> snmp_framework_mib(X). -msm_target_mib(X) -> snmp_target_mib(X). -msm_notification_mib(X) -> snmp_notification_mib(X). -msm_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). -msm_sparse_table(X) -> sparse_table(X). -msm_me_of(X) -> ms_me_of(X). -msm_mib_of(X) -> ms_mib_of(X). - - -mse_size_check(X) -> p("mse_size_check..."), ms_size_check(X). -msd_size_check(X) -> p("msd_size_check..."), ms_size_check(X). -msm_size_check(X) -> p("msm_size_check..."), ms_size_check(X). - -msd_varm_mib_start(X) -> p("msd_varm_mib_start..."), varm_mib_start(X). -msm_varm_mib_start(X) -> p("msm_varm_mib_start..."), varm_mib_start(X). - -ms_size_check(suite) -> []; -ms_size_check(Config) when list(Config) -> - p("ms_size_check..."), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?LOG("mib server size check...", []), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - ?line load_master_std("OTP-SNMPEA-MIB"), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-MPD-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-USER-BASED-SM-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - ?line load_master_std("SNMPv2-MIB"), - ?line load_master_std("SNMPv2-TM"), - - ?SLEEP(2000), - - ?line display_memory_usage(), - - ?line unload_master("OTP-SNMPEA-MIB"), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?line unload_master("SNMP-MPD-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-USER-BASED-SM-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - ?line unload_master("SNMPv2-MIB"), - ?line unload_master("SNMPv2-TM"), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - - ok. - - -varm_mib_start(suite) -> []; -varm_mib_start(Config) when list(Config) -> - p("varm_mib_start..."), - ?LOG("varm_mib_start -> entry", []), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - %% Start the agent - Opts = ?GCONF(agent_opts, Config), - Config1 = start_v1_agent(Config, Opts), - - %% Sleep some in order for the agent to start properly - ?DBG("varm_mib_start -> sleep some (before loading mobs)", []), - ?SLEEP(5000), - - %% Load all the mibs - HardwiredMibs = loaded_mibs(), - ?DBG("varm_mib_start -> load all mibs", []), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - - %% Unload the hardwired mibs - ?DBG("varm_mib_start -> sleep some (before unloading hardwired mibs)", []), - ?SLEEP(1000), - ?DBG("varm_mib_start -> unload (hardwired) mibs", []), - ?line unload_mibs(HardwiredMibs), %% unload hardwired - - ?DBG("varm_mib_start -> sleep some (before stopping agent)", []), - ?SLEEP(1000), - - %% Stop the agent (without deleting the stored files) - ?DBG("varm_mib_start -> stop the agent", []), - Config2 = stop_agent(Config1), - - %% Sleep some in order for the agent to stop properly - ?DBG("varm_mib_start -> sleep some (before re-starting the agent)", []), - ?SLEEP(5000), - - %% Start the agent (again) - ?DBG("varm_mib_start -> start the agent", []), - Config3 = start_v1_agent(Config2, Opts), - - ?DBG("varm_mib_start -> sleep some (before starting tests)", []), - ?SLEEP(5000), - - %% Perform the test(s) - ?DBG("varm_mib_start -> perform the tests", []), - try_test(snmp_community_mib), - try_test(snmp_framework_mib), - try_test(snmp_target_mib), - try_test(snmp_notification_mib), - - %% Stop the agent (without deleting the stored files) - ?DBG("varm_mib_start -> stop the agent", []), - stop_agent(Config3), - ok. - - --define(snmpTrapCommunity_instance, [1,3,6,1,6,3,18,1,4,0]). --define(vacmViewSpinLock_instance, [1,3,6,1,6,3,16,1,5,1,0]). --define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). - -ms_me_of(suite) -> []; -ms_me_of(Config) when list(Config) -> - p("ms_me_of..."), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - ?line load_master_std("OTP-SNMPEA-MIB"), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-MPD-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - - ?SLEEP(2000), - - ?line display_memory_usage(), - - - ?DBG("ms_me_of -> find ~w from SNMP-COMMUNITY-MIB", - [?snmpTrapCommunity_instance]), - ?line ok = me_of(?snmpTrapCommunity_instance), - - ?DBG("ms_me_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", - [?vacmViewSpinLock_instance]), - ?line ok = me_of(?vacmViewSpinLock_instance), - - ?DBG("ms_me_of -> find ~w from SNMP-USER-BASED-SM-MIB", - [?usmStatsNotInTimeWindows_instance]), - ?line {error, _} = me_of(?usmStatsNotInTimeWindows_instance), - - - ?line unload_master("OTP-SNMPEA-MIB"), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?line unload_master("SNMP-MPD-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - - ok. - -me_of(Oid) -> - case snmpa:me_of(Oid) of - {ok, #me{oid = Oid}} -> - ok; - {ok, #me{oid = OtherOid}} -> - case lists:reverse(Oid) of - [0|Rest] -> - case lists:reverse(Rest) of - OtherOid -> - ok; - AnotherOid -> - {error, {invalid_oid, Oid, AnotherOid}} - end; - _ -> - {error, {invalid_oid, Oid, OtherOid}} - end; - {error, Reason} -> - {error, Reason}; - Else -> - {error, Else} - end. - - -ms_mib_of(suite) -> []; -ms_mib_of(Config) when list(Config) -> - p("ms_mib_of..."), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - ?line load_master_std("OTP-SNMPEA-MIB"), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-MPD-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - - ?SLEEP(2000), - - ?line display_memory_usage(), - - - ?DBG("ms_mib_of -> find ~w from SNMP-COMMUNITY-MIB", - [?snmpTrapCommunity_instance]), - ?line ok = mib_of(?snmpTrapCommunity_instance, 'SNMP-COMMUNITY-MIB'), - - ?DBG("ms_mib_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", - [?vacmViewSpinLock_instance]), - ?line ok = mib_of(?vacmViewSpinLock_instance, 'SNMP-VIEW-BASED-ACM-MIB'), - - ?DBG("ms_mib_of -> find ~w from SNMP-USER-BASED-SM-MIB", - [?usmStatsNotInTimeWindows_instance]), - ?line {error, _} = mib_of(?usmStatsNotInTimeWindows_instance, - 'SNMP-USER-BASED-SM-MIB'), - - - ?line unload_master("OTP-SNMPEA-MIB"), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?line unload_master("SNMP-MPD-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - - ok. - -mib_of(Oid, ExpectedMibName) -> - ?DBG("mib_of -> entry with" - "~n Oid: ~p" - "~n ExpectedMibName: ~p", [Oid, ExpectedMibName]), - %% case snmpa:mib_of(Oid) of - MibOf = snmpa:mib_of(Oid), - ?DBG("mib_of -> MibOf: ~n~p", [MibOf]), - case MibOf of - {ok, ExpectedMibName} -> - ok; - {ok, OtherMibName} -> - {error, {invalid_mib, ExpectedMibName, OtherMibName}}; - {error, Reason} -> - {error, Reason}; - Else -> - ?DBG("mib_of -> Else: ~n~p", [Else]), - {error, Else} - end. - - -app_info(suite) -> []; -app_info(Config) when list(Config) -> - SnmpDir = app_dir(snmp), - SslDir = app_dir(ssl), - CryptoDir = app_dir(crypto), - Attr = snmp:module_info(attributes), - AppVsn = - case lists:keysearch(app_vsn, 1, Attr) of - {value, {app_vsn, V}} -> - V; - false -> - "undefined" - end, - io:format("Root dir: ~s~n" - "SNMP: Application dir: ~s~n" - " Application ver: ~s~n" - "SSL: Application dir: ~s~n" - "CRYPTO: Application dir: ~s~n", - [code:root_dir(), SnmpDir, AppVsn, SslDir, CryptoDir]), - ok. - -app_dir(App) -> - case code:lib_dir(App) of - D when list(D) -> - filename:basename(D); - {error, _Reason} -> - "undefined" - end. - - - -%v1_cases() -> [loop_mib]; -v1_cases() -> -[simple, db_notify_client, v1_processing, big, big2, - loop_mib, api, subagent, mnesia, {group, multiple_reqs}, - sa_register, v1_trap, sa_error, next_across_sa, undo, - {group, reported_bugs}, {group, standard_mibs}, - sparse_table, cnt_64, opaque, change_target_addr_config]. - -init_v1(Config) when list(Config) -> - ?line SaNode = ?config(snmp_sa, Config), - ?line create_tables(SaNode), - ?line AgentDir = ?config(agent_dir, Config), - ?line MgrDir = ?config(mgr_dir, Config), - ?line Ip = ?config(ip, Config), - ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v1} | start_v1_agent(Config)]. - -finish_v1(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - - -%v2_cases() -> [loop_mib_2]; -v2_cases() -> -[simple_2, v2_processing, big_2, big2_2, loop_mib_2, - api_2, subagent_2, mnesia_2, {group, multiple_reqs_2}, - sa_register_2, v2_trap, {group, v2_inform}, sa_error_2, - next_across_sa_2, undo_2, {group, reported_bugs_2}, - {group, standard_mibs_2}, v2_types, implied, - sparse_table_2, cnt_64_2, opaque_2, v2_caps]. - -init_v2(Config) when list(Config) -> - SaNode = ?config(snmp_sa, Config), - create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), - MgrDir = ?config(mgr_dir, Config), - Ip = ?config(ip, Config), - config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v2} | start_v2_agent(Config)]. - -finish_v2(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - - -v1_v2_cases() -> -[simple_bi]. - -init_v1_v2(Config) when list(Config) -> - SaNode = ?config(snmp_sa, Config), - create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), - MgrDir = ?config(mgr_dir, Config), - Ip = ?config(ip, Config), - config([v1,v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, bilingual} | start_bilingual_agent(Config)]. - -finish_v1_v2(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - - -%v3_cases() -> [loop_mib_3]; -v3_cases() -> -[simple_3, v3_processing, big_3, big2_3, api_3, - subagent_3, mnesia_3, loop_mib_3, multiple_reqs_3, - sa_register_3, v3_trap, v3_inform, sa_error_3, - next_across_sa_3, undo_3, {group, reported_bugs_3}, - {group, standard_mibs_3}, {group, v3_security}, - v2_types_3, implied_3, sparse_table_3, cnt_64_3, - opaque_3, v2_caps_3]. - -init_v3(Config) when list(Config) -> - %% Make sure crypto works, otherwise start_agent will fail - %% and we will be stuck with a bunch of mnesia tables for - %% the rest of this suite... - ?DBG("start_agent -> start crypto app",[]), - case os:type() of - vxworks -> - no_crypto; - _ -> - case ?CRYPTO_START() of - ok -> - case ?CRYPTO_SUPPORT() of - {no, Reason} -> - ?SKIP({unsupported_encryption, Reason}); - yes -> - ok - end; - {error, Reason} -> - ?SKIP({failed_starting_crypto, Reason}) - end - end, - SaNode = ?config(snmp_sa, Config), - create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), - MgrDir = ?config(mgr_dir, Config), - Ip = ?config(ip, Config), - ?line ok = config([v3], MgrDir, AgentDir, - tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v3} | start_v3_agent(Config)]. - -finish_v3(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - - -mt_cases() -> -[multi_threaded, mt_trap]. - -init_mt(Config) when list(Config) -> - SaNode = ?config(snmp_sa, Config), - create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), - MgrDir = ?config(mgr_dir, Config), - Ip = ?config(ip, Config), - ?line ok = config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v2} | start_multi_threaded_agent(Config)]. - -finish_mt(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - -%% This one *must* be run first in each case. -init_case(Config) when list(Config) -> - ?DBG("init_case -> entry with" - "~n Config: ~p", [Config]), - SaNode = ?config(snmp_sa, Config), - MgrNode = ?config(snmp_mgr, Config), - MasterNode = node(), - - SaHost = ?HOSTNAME(SaNode), - MgrHost = ?HOSTNAME(MgrNode), - MasterHost = ?HOSTNAME(MasterNode), - {ok, MasterIP} = snmp_misc:ip(MasterHost), - {ok, MIP} = snmp_misc:ip(MgrHost), - {ok, SIP} = snmp_misc:ip(SaHost), - - - put(mgr_node, MgrNode), - put(sa_node, SaNode), - put(master_node, MasterNode), - put(sa_host, SaHost), - put(mgr_host, MgrHost), - put(master_host, MasterHost), - put(mip, tuple_to_list(MIP)), - put(masterip , tuple_to_list(MasterIP)), - put(sip, tuple_to_list(SIP)), - - MibDir = ?config(mib_dir, Config), - put(mib_dir, MibDir), - StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", - put(std_mib_dir, StdM), - - MgrDir = ?config(mgr_dir, Config), - put(mgr_dir, MgrDir), - - put(vsn, ?config(vsn, Config)), - ?DBG("init_case -> exit with" - "~n MasterNode: ~p" - "~n SaNode: ~p" - "~n MgrNode: ~p" - "~n MibDir: ~p", [MasterNode, SaNode, MgrNode, MibDir]), - {SaNode, MgrNode, MibDir}. - -load_master(Mib) -> - ?DBG("load_master -> entry with" - "~n Mib: ~p", [Mib]), - snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety - ok = snmpa:load_mibs(snmp_master_agent, [get(mib_dir) ++ Mib]). - -load_master_std(Mib) -> - ?DBG("load_master_std -> entry with" - "~n Mib: ~p", [Mib]), - snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety - ok = snmpa:load_mibs(snmp_master_agent, [get(std_mib_dir) ++ Mib]). - -unload_master(Mib) -> - ?DBG("unload_master -> entry with" - "~n Mib: ~p", [Mib]), - ok = snmpa:unload_mibs(snmp_master_agent, [Mib]). - -loaded_mibs() -> - ?DBG("loaded_mibs -> entry",[]), - Info = snmpa:info(snmp_master_agent), - {value, {loaded_mibs, Mibs}} = lists:keysearch(loaded_mibs, 1, Info), - [atom_to_list(Mib) || {Mib,_,_} <- Mibs]. - -unload_mibs(Mibs) -> - ?DBG("unload_mibs -> entry with" - "~n Mibs: ~p", [Mibs]), - ok = snmpa:unload_mibs(snmp_master_agent, Mibs). - -start_subagent(SaNode, RegTree, Mib) -> - ?DBG("start_subagent -> entry with" - "~n SaNode: ~p" - "~n RegTree: ~p" - "~n Mib: ~p", [SaNode, RegTree, Mib]), - MA = whereis(snmp_master_agent), - ?DBG("start_subagent -> MA: ~p", [MA]), - MibDir = get(mib_dir), - Mib1 = join(MibDir,Mib), - %% BMK BMK -% case rpc:call(SaNode,snmp_supervisor,start_subagent,[MA,RegTree,[Mib1]]) of - case rpc:call(SaNode, snmpa_supervisor, - start_sub_agent, [MA, RegTree, [Mib1]]) of - {ok, SA} -> - ?DBG("start_subagent -> SA: ~p", [SA]), - {ok, SA}; - Error -> - ?FAIL({subagent_start_failed, SaNode, Error, [MA, RegTree, Mib1]}) - end. - -stop_subagent(SA) -> - ?DBG("stop_subagent -> entry with" - "~n SA: ~p", [SA]), - %% BNK BMK - %% rpc:call(node(SA), snmp_supervisor, stop_subagent, [SA]). - rpc:call(node(SA), snmpa_supervisor, stop_sub_agent, [SA]). - -%%----------------------------------------------------------------- -%% This function takes care of the old OTP-SNMPEA-MIB. -%% Unfortunately, the testcases were written to use the data in the -%% internal tables, and these table are now obsolete and not used -%% by the agent. Therefore, we emulate them by using -%% OLD-SNMPEA-MIB, which uses the default impl. of all tables. -%% -%% These two rows must exist in intCommunityTable -%% {[147,214,36,45], "public", 2, readWrite}. -%% {[147,214,36,45], "standard trap", 2, read}. -%% (But with the manager's IP address) -%% -%%----------------------------------------------------------------- -init_old() -> - snmpa_local_db:table_create_row(intCommunityTable, - get(mip) ++ [6 | "public"], - {get(mip), "public", 2, 2}), - snmpa_local_db:table_create_row(intCommunityTable, - get(mip) ++ [13 | "standard trap"], - {get(mip), "standard trap", 2, 1}), - snmpa_local_db:variable_set(intAgentIpAddress, [127,0,0,1]). - - - -simple(suite) -> []; -simple(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - try_test(simple_standard_test). - -simple_2(X) -> simple(X). - -simple_bi(suite) -> []; -simple_bi(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - put(vsn, v1), % First, try v1 manager - try_test(simple_standard_test), - - put(vsn, v2), % Then, try v2 manager - try_test(simple_standard_test). - -simple_3(X) -> - simple(X). - -big(suite) -> []; -big(Config) when list(Config) -> - ?DBG("big -> entry", []), - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Starting subagent..."), - ?line pong = net_adm:ping(SaNode), - - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), - ?DBG("big -> SA: ~p", [SA]), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(big_test), - ?line stop_subagent(SA), - ?line unload_master("OLD-SNMPEA-MIB"). - -big_2(X) -> big(X). - -big_3(X) -> big(X). - - -big2(suite) -> []; -big2(Config) when list(Config) -> - %% This is exactly the same tests as 'big', but with the - %% v2 equivalent of the mibs. - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Starting subagent..."), - ?line pong = net_adm:ping(SaNode), - - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1-v2"), - ?line load_master("OLD-SNMPEA-MIB-v2"), - ?line init_old(), - try_test(big_test), - ?line stop_subagent(SA), - ?line unload_master("OLD-SNMPEA-MIB-v2"). - -big2_2(X) -> big2(X). - -big2_3(X) -> big2(X). - - -multi_threaded(suite) -> []; -multi_threaded(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test1"), - try_test(multi_threaded_test), - ?line unload_master("Test1"). - -mt_trap(suite) -> []; -mt_trap(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line load_master("Test1"), - ?line load_master("TestTrapv2"), - try_test(mt_trap_test, [MA]), - ?line unload_master("TestTrapv2"), - ?line unload_master("Test1"). - -v2_types(suite) -> []; -v2_types(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test1"), - try_test(types_v2_test), - ?line unload_master("Test1"). - -v2_types_3(X) -> v2_types(X). - - -implied(suite) -> []; -implied(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line load_master("Test1"), - try_test(implied_test,[MA]), - ?line unload_master("Test1"). - -implied_3(X) -> implied(X). - - -sparse_table(suite) -> []; -sparse_table(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test1"), - try_test(sparse_table_test), - ?line unload_master("Test1"). - -sparse_table_2(X) -> sparse_table(X). - -sparse_table_3(X) -> sparse_table(X). - -cnt_64(suite) -> []; -cnt_64(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line load_master("Test1"), - try_test(cnt_64_test, [MA]), - ?line unload_master("Test1"). - -cnt_64_2(X) -> cnt_64(X). - -cnt_64_3(X) -> cnt_64(X). - -opaque(suite) -> []; -opaque(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test1"), - try_test(opaque_test), - ?line unload_master("Test1"). - -opaque_2(X) -> opaque(X). - -opaque_3(X) -> opaque(X). - - -change_target_addr_config(suite) -> []; -change_target_addr_config(Config) when list(Config) -> - p("Testing changing target address config..."), - ?LOG("change_target_addr_config -> entry",[]), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - put(sname,snmp_suite), - put(verbosity,trace), - - MA = whereis(snmp_master_agent), - - ?LOG("change_target_addr_config -> load TestTrap",[]), - ?line load_master("TestTrap"), - - ?LOG("change_target_addr_config -> set trace verbosity for local_db",[]), - ?line snmpa:verbosity(local_db,trace), - - %% First send some traps that will arive att the original manager - ?LOG("change_target_addr_config -> send trap",[]), - try_test(ma_trap1, [MA]), - - ?LOG("change_target_addr_config -> set silence verbosity for local_db",[]), - ?line snmpa:verbosity(local_db,silence), - - %% Start new dummy listener - ?LOG("change_target_addr_config -> start dummy manager",[]), - ?line {ok,Pid,NewPort} = dummy_manager_start(MA), - - %% Reconfigure - ?LOG("change_target_addr_config -> reconfigure",[]), - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_addr_conf(AgentDir, NewPort), - ?line snmp_target_mib:reconfigure(AgentDir), - - %% Send the trap again - ?LOG("change_target_addr_config -> send trap again",[]), - catch dummy_manager_send_trap2(Pid), - - ?LOG("change_target_addr_config -> await trap ack",[]), - catch dummy_manager_await_trap2_ack(), - - ?LOG("change_target_addr_config -> stop dummy manager",[]), - ?line ok = dummy_manager_stop(Pid), - - ?LOG("change_target_addr_config -> reset target address config",[]), - ?line reset_target_addr_conf(AgentDir), - - ?LOG("change_target_addr_config -> unload TestTrap",[]), - ?line unload_master("TestTrap"). - - -dummy_manager_start(MA) -> - ?DBG("dummy_manager_start -> entry",[]), - Pid = spawn(get(mgr_node), ?MODULE,dummy_manager_init,[self(),MA]), - ?DBG("dummy_manager_start -> Pid: ~p",[Pid]), - await_dummy_manager_started(Pid). - -await_dummy_manager_started(Pid) -> - receive - {dummy_manager_started,Pid,Port} -> - ?DBG("dummy_manager_start -> acknowledge received with" - "~n Port: ~p",[Port]), - {ok,Pid,Port}; - {'EXIT', Pid, Reason} -> - {error, Pid, Reason}; - O -> - ?LOG("dummy_manager_start -> received unknown message:" - "~n ~p",[O]), - await_dummy_manager_started(Pid) - end. - -dummy_manager_stop(Pid) -> - ?DBG("dummy_manager_stop -> entry with Pid: ~p",[Pid]), - Pid ! stop, - receive - {dummy_manager_stopping, Pid} -> - ?DBG("dummy_manager_stop -> acknowledge received",[]), - ok - after 10000 -> - ?ERR("dummy_manager_stop -> timeout",[]), - timeout - end. - -dummy_manager_send_trap2(Pid) -> - ?DBG("dummy_manager_send_trap2 -> entry",[]), - Pid ! {send_trap,testTrap2}. - -dummy_manager_await_trap2_ack() -> - ?DBG("dummy_manager_await_trap2 -> entry",[]), - receive - {received_trap,Trap} -> - ?LOG("dummy_manager_await_trap2 -> received trap: ~p",[Trap]), - %% Note: - %% Without this sleep the v2_inform_i testcase failes! There - %% is no relation between these two test cases as far as I - %% able to figure out... - sleep(60000), - ok; - O -> - ?ERR("dummy_manager_await_trap2 -> unexpected message: ~p",[O]), - ok - after 10000 -> - ?ERR("dummy_manager_await_trap2 -> timeout",[]), - timeout - end. - -dummy_manager_init(Parent,MA) -> - ?DBG("dummy_manager_init -> entry with" - "~n Parent: ~p" - "~n MA: ~p",[Parent,MA]), - {ok,S} = gen_udp:open(0,[{recbuf,65535}]), - ?DBG("dummy_manager_init -> S: ~p",[S]), - {ok,Port} = inet:port(S), - ?DBG("dummy_manager_init -> Port: ~p",[Port]), - Parent ! {dummy_manager_started,self(),Port}, - dummy_manager_loop(Parent,S,MA). - -dummy_manager_loop(P,S,MA) -> - ?LOG("dummy_manager_loop -> ready for receive",[]), - receive - {send_trap,Trap} -> - ?LOG("dummy_manager_loop -> received trap send request" - "~n Trap: ~p",[Trap]), - snmpa:send_trap(MA, Trap, "standard trap"), - dummy_manager_loop(P,S,MA); - {udp, _UdpId, Ip, UdpPort, Bytes} -> - ?LOG("dummy_manager_loop -> received upd message" - "~n from: ~p:~p" - "~n size: ~p", - [Ip, UdpPort, dummy_manager_message_sz(Bytes)]), - R = dummy_manager_handle_message(Bytes), - ?DBG("dummy_manager_loop -> R: ~p",[R]), - P ! R, - dummy_manager_loop(P,S,MA); - stop -> - ?DBG("dummy_manager_loop -> received stop request",[]), - P ! {dummy_manager_stopping, self()}, - gen_udp:close(S), - exit(normal); - O -> - ?LOG("dummy_manager_loop -> received unknown message:" - "~n ~p",[O]), - dummy_manager_loop(P,S,MA) - end. - -dummy_manager_message_sz(B) when binary(B) -> - size(B); -dummy_manager_message_sz(L) when list(L) -> - length(L); -dummy_manager_message_sz(_) -> - undefined. - -dummy_manager_handle_message(Bytes) -> - case (catch snmp_pdus:dec_message(Bytes)) of - {'EXIT',Reason} -> - ?ERR("dummy_manager_handle_message -> " - "failed decoding message only:~n ~p",[Reason]), - {error,Reason}; - M -> - ?DBG("dummy_manager_handle_message -> decoded message:" - "~n ~p",[M]), - {received_trap,M} - end. - - -api(suite) -> []; -api(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(api_test, [node()]), - ?line unload_master("OLD-SNMPEA-MIB"). - -api_2(X) -> api(X). - -api_3(X) -> api(X). - - -subagent(suite) -> []; -subagent(Config) when list(Config) -> - {SaNode, _MgrNode, MibDir} = init_case(Config), - - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), - try_test(load_test_sa), - - p("Testing unregister subagent..."), - MA = whereis(snmp_master_agent), - rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), - try_test(unreg_test), - - p("Loading previous subagent mib in master and testing..."), - ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas1"]), - try_test(load_test), - - p("Unloading previous subagent mib in master and testing..."), - ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas1"]), - try_test(unreg_test), - p("Testing register subagent..."), - rpc:call(SaNode, snmp, register_subagent, - [MA, ?klas1, SA]), - try_test(load_test_sa), - - ?line stop_subagent(SA), - try_test(unreg_test). - -subagent_2(X) -> subagent(X). - -subagent_3(X) -> subagent(X). - - -mnesia(suite) -> []; -mnesia(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Starting subagent with mnesia impl..."), - {ok, SA} = start_subagent(SaNode, ?klas2, "Klas2"), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - - try_test(big_test_2), - - p("Testing unregister subagent..."), - MA = whereis(snmp_master_agent), - rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), - try_test(unreg_test), - ?line unload_master("OLD-SNMPEA-MIB"), - ?line stop_subagent(SA). - -mnesia_2(X) -> mnesia(X). - -mnesia_3(X) -> mnesia(X). - - - -mul_cases() -> -[mul_get, mul_get_err, mul_next, mul_next_err, - mul_set_err]. - - -multiple_reqs_3(_X) -> - {req, [], {conf, init_mul, mul_cases_3(), finish_mul}}. - - -mul_cases_2() -> -[mul_get_2, mul_get_err_2, mul_next_2, mul_next_err_2, - mul_set_err_2]. - - -mul_cases_3() -> - [mul_get_3, mul_get_err_3, mul_next_3, mul_next_err_3, mul_set_err_3]. - - -init_mul(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - [{mul_sub, SA} | Config]. - -finish_mul(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - SA = ?config(mul_sub, Config), - - ?line unload_master("OLD-SNMPEA-MIB"), - ?line stop_subagent(SA), - lists:keydelete(mul_sub, 1, Config). - -mul_get(suite) -> []; -mul_get(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple get..."), - try_test(do_mul_get). - -mul_get_2(X) -> mul_get(X). - -mul_get_3(X) -> mul_get(X). - - -mul_get_err(suite) -> []; -mul_get_err(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple get with error..."), - try_test(do_mul_get_err). - -mul_get_err_2(X) -> mul_get_err(X). - -mul_get_err_3(X) -> mul_get_err(X). - - -mul_next(suite) -> []; -mul_next(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple next..."), - try_test(do_mul_next). - -mul_next_2(X) -> mul_next(X). - -mul_next_3(X) -> mul_next(X). - - -mul_next_err(suite) -> []; -mul_next_err(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple next..."), - try_test(do_mul_next_err). - -mul_next_err_2(X) -> mul_next_err(X). - -mul_next_err_3(X) -> mul_next_err(X). - - -mul_set(suite) -> []; -mul_set(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple set..."), - try_test(do_mul_set). - -mul_set_2(X) -> mul_set(X). - -mul_set_3(X) -> mul_set(X). - - -mul_set_err(suite) -> []; -mul_set_err(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple set with error..."), - try_test(do_mul_set_err). - -mul_set_err_2(X) -> mul_set_err(X). - -mul_set_err_3(X) -> mul_set_err(X). - - -sa_register(suite) -> []; -sa_register(Config) when list(Config) -> - ?DBG("sa_register -> entry", []), - {SaNode, _MgrNode, MibDir} = init_case(Config), - - ?DBG("sa_register -> start subagent", []), - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), - - ?DBG("sa_register -> unregister subagent", []), - p("Testing unregister subagent (2)..."), - MA = whereis(snmp_master_agent), - rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), - try_test(unreg_test), - - p("Loading SA-MIB..."), - ?DBG("sa_register -> unload mibs", []), - snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), - ?DBG("sa_register -> unload mibs", []), - snmpa:load_mibs(SA, [MibDir ++ "SA-MIB"]), - ?DBG("sa_register -> register subagent", []), - rpc:call(SaNode, snmp, register_subagent, [MA,?sa,SA]), - try_test(sa_mib), - - ?DBG("sa_register -> stop subagent", []), - ?line stop_subagent(SA). - -sa_register_2(X) -> sa_register(X). - -sa_register_3(X) -> sa_register(X). - - -v1_trap(suite) -> []; -v1_trap(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Testing trap sending from master agent..."), - MA = whereis(snmp_master_agent), - - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(ma_trap1, [MA]), - try_test(ma_trap2, [MA]), - try_test(ma_v2_2_v1_trap, [MA]), - try_test(ma_v2_2_v1_trap2, [MA]), - - p("Testing trap sending from subagent..."), - try_test(sa_trap1, [SA]), - try_test(sa_trap2, [SA]), - try_test(sa_trap3, [SA]), - - ?line unload_master("TestTrap"), - ?line unload_master("TestTrapv2"), - - ?line stop_subagent(SA). - -v2_trap(suite) -> []; -v2_trap(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Testing trap sending from master agent..."), - MA = whereis(snmp_master_agent), - - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - - try_test(ma_v2_trap1, [MA]), - try_test(ma_v2_trap2, [MA]), - try_test(ma_v1_2_v2_trap, [MA]), - try_test(ma_v1_2_v2_trap2, [MA]), - - try_test(sa_mib), - p("Testing trap sending from subagent..."), - try_test(sa_v1_2_v2_trap1, [SA]), - try_test(sa_v1_2_v2_trap2, [SA]), - try_test(sa_v1_2_v2_trap3, [SA]), - - ?line unload_master("TestTrap"), - ?line unload_master("TestTrapv2"), - - ?line stop_subagent(SA). - -v3_trap(X) -> - v2_trap(X). - - -v3_inform(_X) -> - %% v2_inform(X). - {req, [], {conf, init_v3_inform, [v3_inform_i], finish_v3_inform}}. - -init_v2_inform(Config) when list(Config) -> - _Dir = ?config(agent_dir, Config), -% snmp_internal_mib:configure(Dir), - Config. - -init_v3_inform(X) -> - init_v2_inform(X). - -finish_v2_inform(Config) when list(Config) -> - _Dir = ?config(agent_dir, Config), -% snmp_internal_mib:configure(Dir), - Config. - -finish_v3_inform(X) -> - finish_v2_inform(X). - - - -v2_inform_i(suite) -> []; -v2_inform_i(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing inform sending from master agent... NOTE! This test\ntakes a " - "few minutes (5) to complete."), - MA = whereis(snmp_master_agent), - - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(ma_v2_inform1, [MA]), - - ?line unload_master("TestTrap"), - ?line unload_master("TestTrapv2"). - -v3_inform_i(X) -> v2_inform_i(X). - - -sa_error(suite) -> []; -sa_error(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Testing sa bad value (is_set_ok)..."), - try_test(sa_errs_bad_value), - - p("Testing sa gen err (set)..."), - try_test(sa_errs_gen_err), - - p("Testing too big..."), - try_test(sa_too_big), - - ?line unload_master("OLD-SNMPEA-MIB"), - stop_subagent(SA). - -sa_error_2(X) -> sa_error(X). - -sa_error_3(X) -> sa_error(X). - - -next_across_sa(suite) -> []; -next_across_sa(Config) when list(Config) -> - {SaNode, _MgrNode, MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Loading another subagent mib..."), - ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas1"]), - - rpc:call(SaNode, snmp, register_subagent, [MA, ?klas1, SA]), - try_test(load_test_sa), - - p("Testing next across subagent (endOfMibView from SA)..."), - try_test(next_across_sa), - - p("Unloading mib"), - snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), - rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), - try_test(unreg_test), - - p("Starting another subagent"), - ?line {ok, SA2} = start_subagent(SaNode, ?klas1, "Klas1"), - p("Testing next across subagent (wrong prefix from SA)..."), - try_test(next_across_sa), - - stop_subagent(SA), - stop_subagent(SA2). - -next_across_sa_2(X) -> next_across_sa(X). - -next_across_sa_3(X) -> next_across_sa(X). - - -undo(suite) -> []; -undo(Config) when list(Config) -> - {SaNode, _MgrNode, MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Testing undo phase at master agent..."), - ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas3"]), - ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas4"]), - try_test(undo_test), - try_test(api_test2), - ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas3"]), - - p("Testing bad return values from instrum. funcs..."), - try_test(bad_return), - - ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas4"]), - - p("Testing undo phase at subagent..."), - ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas3"]), - ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas4"]), - ?line ok = snmpa:register_subagent(MA, ?klas3, SA), - ?line ok = snmpa:register_subagent(MA, ?klas4, SA), - try_test(undo_test), - try_test(api_test3), - - p("Testing undo phase across master/subagents..."), - try_test(undo_test), - try_test(api_test3), - stop_subagent(SA). - -undo_2(X) -> undo(X). - -undo_3(X) -> undo(X). - -%% Req. Test2 -v1_processing(suite) -> []; -v1_processing(Config) when list(Config) -> - ?DBG("v1_processing -> entry", []), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - try_test(v1_proc), - ?line unload_master("Test2"). - -%% Req. Test2 -v2_processing(suite) -> []; -v2_processing(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - try_test(v2_proc), - ?line unload_master("Test2"). - -%% Req. Test2 -v3_processing(suite) -> []; -v3_processing(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - try_test(v2_proc), % same as v2! - ?line unload_master("Test2"). - - -%% We'll try get/set/trap and inform for all the auth & priv protocols. -%% For informs, the mgr is auth-engine. The agent has to sync. This is -%% accomplished by the first inform sent. That one will generate a -%% report, which makes it in sync. The notification-generating -%% application times out, and send again. This time it'll work. - -v3_crypto_basic(suite) -> []; -v3_crypto_basic(_Config) -> - EID = [0,0,0,0,0,0,0,0,0,0,0,2], - %% From rfc2274 appendix A.3.1 - ?line KMd5_1 = snmp:passwd2localized_key(md5, "maplesyrup", EID), - ?line [16#52,16#6f,16#5e,16#ed,16#9f,16#cc,16#e2,16#6f, - 16#89,16#64,16#c2,16#93,16#07,16#87,16#d8,16#2b] = - KMd5_1, - %% From rfc2274 appendix A.3.2 - ?line KSHA_1 = snmp:passwd2localized_key(sha, "maplesyrup", EID), - ?line [16#66,16#95,16#fe,16#bc,16#92,16#88,16#e3,16#62,16#82,16#23, - 16#5f,16#c7,16#15,16#1f,16#12,16#84,16#97,16#b3,16#8f,16#3f] = - KSHA_1, - %% From rfc2274, appendix A.5.1 - ?line KMd5_2 = snmp:passwd2localized_key(md5, "newsyrup", EID), - ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#88,16#05,16#61,16#51,16#41,16#67,16#6c,16#c9, - 16#19,16#61,16#74,16#e7,16#42,16#a3,16#25,16#51] = - snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2, 16, - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), - %% From rfc2274, appendix A.5.2 - ?line KSHA_2 = snmp:passwd2localized_key(sha, "newsyrup", EID), - ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#00,16#00,16#00,16#00,16#9c,16#10,16#17,16#f4, - 16#fd,16#48,16#3d,16#2d,16#e8,16#d5,16#fa,16#db, - 16#f8,16#43,16#92,16#cb,16#06,16#45,16#70,16#51] = - snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2, 20, - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), - KSHA_1t = lists:sublist(KSHA_1, 16), - KSHA_2t = lists:sublist(KSHA_2, 16), - ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#7e,16#f8,16#d8,16#a4,16#c9,16#cd,16#b2,16#6b, - 16#47,16#59,16#1c,16#d8,16#52,16#ff,16#88,16#b5] = - snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1t, KSHA_2t, 16, - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), - - %% Try with correct random - ?line Kc1 = snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2), - ?line KMd5_2 = snmp_user_based_sm_mib:extract_new_key(md5, KMd5_1, Kc1), - ?line Kc2 = snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2), - ?line KSHA_2 = snmp_user_based_sm_mib:extract_new_key(sha, KSHA_1, Kc2), - ok. - - - -v3_md5_auth(suite) -> []; -v3_md5_auth(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - p("Testing MD5 authentication...takes a few seconds..."), - - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_params_conf(AgentDir, "authMD5", authNoPriv), - ?line snmp_target_mib:reconfigure(AgentDir), - - MA = whereis(snmp_master_agent), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(v3_sync, [[{v2_proc, []}, - {ma_v2_trap1, [MA]}, - {v3_inform_sync, [MA]}]], - [{sec_level, authNoPriv}, {user, "authMD5"}]), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - ?line reset_target_params_conf(AgentDir). - -v3_sha_auth(suite) -> []; -v3_sha_auth(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - p("Testing SHA authentication...takes a few seconds..."), - - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_params_conf(AgentDir, "authSHA", authNoPriv), - ?line snmp_target_mib:reconfigure(AgentDir), - - MA = whereis(snmp_master_agent), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(v3_sync, [[{v2_proc, []}, - {ma_v2_trap1, [MA]}, - {v3_inform_sync, [MA]}]], - [{sec_level, authNoPriv}, {user, "authSHA"}]), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - ?line reset_target_params_conf(AgentDir). - -v3_des_priv(suite) -> []; -v3_des_priv(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - p("Testing DES encryption...takes a few seconds..."), - - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_params_conf(AgentDir, "privDES", authPriv), - ?line snmp_target_mib:reconfigure(AgentDir), - - MA = whereis(snmp_master_agent), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(v3_sync, [[{v2_proc, []}, - {ma_v2_trap1, [MA]}, - {v3_inform_sync, [MA]}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - ?line reset_target_params_conf(AgentDir). - -%% -define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). - -%% Make sure mgr is in sync with agent -v3_sync(Funcs) -> - ?DBG("v3_sync -> entry with Funcs: ~p",[Funcs]), - g([[sysDescr, 0]]), - expect(432, report, [{?usmStatsNotInTimeWindows_instance, any}]), - g([[sysDescr, 0]]), - expect(433, [{[sysDescr,0], any}]), - lists:foreach(fun({Func, Args}) -> apply(?MODULE, Func, Args) end, Funcs). - -v3_inform_sync(MA) -> - ?DBG("v3_sync -> entry with MA: ~p => Send notification",[MA]), - ?line snmpa:send_notification(MA, testTrapv22, no_receiver, - "standard inform", []), - %% Make sure agent is in sync with mgr... - ?DBG("v3_sync -> wait some time: ",[]), - sleep(20000), % more than 1500*10 in target_addr.conf - ?DBG("v3_sync -> await response",[]), - ?line expect(1, {inform, true}, - [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]). - - -v2_caps(suite) -> []; -v2_caps(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - try_test(v2_caps_i, [node()]). - -v2_caps_3(X) -> v2_caps(X). - - -v2_caps_i(Node) -> - ?line Idx = rpc:call(Node, snmp, add_agent_caps, [[1,2,3,4,5], "test cap"]), - g([[sysORID, Idx], [sysORDescr, Idx]]), - ?line expect(1, [{[sysORID, Idx], [1,2,3,4,5]}, - {[sysORDescr, Idx], "test cap"}]), - ?line rpc:call(Node, snmp, del_agent_caps, [Idx]), - g([[sysORID, Idx]]), - ?line expect(2, [{[sysORID, Idx], noSuchInstance}]). - - -%% Req. Test2 -v1_proc() -> - ?DBG("v1_proc -> entry", []), - %% According to RFC1157. - %% Template:
: - v1_get_p(), - v1_get_next_p(), - v1_set_p(). - - -v1_get_p() -> - %% 4.1.2:1 - g([[test2]]), - ?line expect(10, noSuchName, 1, [{[test2], 'NULL'}]), - g([[tDescr]]), - ?line expect(11, noSuchName, 1, [{[tDescr], 'NULL'}]), - g([[tDescr2,0]]), - ?line expect(12, noSuchName, 1, [{[tDescr2,0], 'NULL'}]), - g([[tDescr3,0]]), - ?line expect(131, noSuchName, 1, [{[tDescr3,0], 'NULL'}]), - g([[tDescr4,0]]), - ?line expect(132, noSuchName, 1, [{[tDescr4,0], 'NULL'}]), - g([[sysDescr, 0], [tDescr,0]]), % Outside mibview - ?line expect(14, noSuchName, 2, [{[sysDescr, 0], 'NULL'}, - {[tDescr,0], 'NULL'}]), - g([[sysDescr,3]]), - ?line expect(15, noSuchName, 1, [{[sysDescr, 3], 'NULL'}]), - - %% 4.1.2:2 - g([[tTable]]), - ?line expect(20, noSuchName, 1, [{[tTable], 'NULL'}]), - g([[tEntry]]), - ?line expect(21, noSuchName, 1, [{[tEntry], 'NULL'}]), - - %% 4.1.2:3 - g([[tTooBig, 0]]), - ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), - - %% 4.1.2:4 - g([[tGenErr1, 0]]), - ?line expect(40, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), - g([[tGenErr2, 0]]), - ?line expect(41, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), - g([[sysDescr, 0], [tGenErr3, 0]]), - ?line expect(42, genErr, 2, [{[sysDescr, 0], 'NULL'}, - {[tGenErr3, 0], 'NULL'}]). - - -v1_get_next_p() -> - %% 4.1.3:1 - gn([[1,3,7,1]]), - ?line expect(10, noSuchName, 1, [{[1,3,7,1], 'NULL'}]), - gn([[tDescr2]]), - ?line expect(11, tooBig, 0, any), - - %% 4.1.3:2 - gn([[tTooBig]]), - io:format("We currently don't handle tooBig correct!!!\n"), -% ?line expect(20, tooBig, 0, [{[tTooBig], 'NULL'}]), - ?line expect(20, tooBig, 0, any), - - %% 4.1.3:3 - gn([[tGenErr1]]), -% ?line expect(40, genErr, 1, [{[tGenErr1], 'NULL'}]), - ?line expect(40, genErr, 1, any), - gn([[tGenErr2]]), -% ?line expect(41, genErr, 1, [{[tGenErr2], 'NULL'}]), - ?line expect(41, genErr, 1, any), - gn([[sysDescr], [tGenErr3]]), -% ?line expect(42, genErr, 2, [{[sysDescr], 'NULL'}, -% {[tGenErr3], 'NULL'}]). - ?line expect(42, genErr, 2, any). - -v1_set_p() -> - %% 4.1.5:1 - s([{[1,3,7,0], i, 4}]), - ?line expect(10, noSuchName, 1, [{[1,3,7,0], 4}]), - s([{[tDescr,0], s, "outside mibview"}]), - ?line expect(11, noSuchName, 1, [{[tDescr,0], "outside mibview"}]), - s([{[tDescr3,0], s, "read-only"}]), - ?line expect(12, noSuchName, 1, [{[tDescr3,0], "read-only"}]), - s([{[tDescr3], s, "noSuchObject"}]), - ?line expect(13, noSuchName, 1, [{[tDescr3], "noSuchObject"}]), - s([{[tDescr3,1], s, "noSuchInstance"}]), - ?line expect(14, noSuchName, 1, [{[tDescr3,1], "noSuchInstance"}]), - s([{[tDescr2,0], s, "inconsistentName"}]), - ?line expect(15, noSuchName, 1, [{[tDescr2,0], "inconsistentName"}]), - - %% 4.1.5:2 - s([{[tDescr2, 0], i, 4}]), - ?line expect(20, badValue, 1, [{[tDescr2, 0], 4}]), - s([{[tDescr2, 0], s, "badValue"}]), - ?line expect(21, badValue, 1, [{[tDescr2, 0], "badValue"}]), - - %% 4.1.5:3 - %% The standard is quite incorrect here. The resp pdu was too big. In - %% the resp pdu, we have the original vbs. In the tooBig pdu we still - %% have to original vbs => the tooBig pdu is too big as well!!! It - %% may not get it to the manager, unless the agent uses 'NULL' instead - %% of the std-like original value. - s([{[tTooBig, 0], s, ?tooBigStr}]), - %% according to std: -% ?line expect(30, tooBig, 0, [{[tTooBig, 0], ?tooBigStr}]), - ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), - - %% 4.1.5:4 - s([{[tDescr2, 0], s, "is_set_ok_fail"}]), - ?line expect(40, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]), - s([{[tDescr2, 0], s, "commit_fail"}]), - ?line expect(41, genErr, 1, [{[tDescr2, 0], "commit_fail"}]). - -%% Req. Test2 -v2_proc() -> - %% According to RFC1905. - %% Template:
: - ?DBG("v2_proc -> entry",[]), - v2_get_p(), - v2_get_next_p(), - v2_get_bulk_p(), - v2_set_p(). - -v2_get_p() -> - %% 4.2.1:2 - ?DBG("v2_get_p -> entry",[]), - g([[test2]]), - ?line expect(10, [{[test2], noSuchObject}]), - g([[tDescr]]), - ?line expect(11, [{[tDescr], noSuchObject}]), - g([[tDescr4,0]]), - ?line expect(12, [{[tDescr4,0], noSuchObject}]), - g([[sysDescr, 0], [tDescr,0]]), % Outside mibview - ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}, - {[tDescr,0], noSuchObject}]), - g([[tTable]]), - ?line expect(14, [{[tTable], noSuchObject}]), - g([[tEntry]]), - ?line expect(15, [{[tEntry], noSuchObject}]), - - %% 4.2.1:3 - g([[tDescr2,0]]), %% instrum ret noSuchName!!! - ?line expect(20, [{[tDescr2,0], noSuchInstance}]), - g([[tDescr3,0]]), - ?line expect(21, [{[tDescr3,0], noSuchInstance}]), - g([[sysDescr,3]]), - ?line expect(22, [{[sysDescr, 3], noSuchInstance}]), - g([[tIndex,1]]), - ?line expect(23, [{[tIndex, 1], noSuchInstance}]), - - %% 4.2.1 - any other error: genErr - g([[tGenErr1, 0]]), - ?line expect(30, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), - g([[tGenErr2, 0]]), - ?line expect(31, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), - g([[sysDescr, 0], [tGenErr3, 0]]), - ?line expect(32, genErr, 2, [{[sysDescr, 0], 'NULL'}, - {[tGenErr3, 0], 'NULL'}]), - - %% 4.2.1 - tooBig - g([[tTooBig, 0]]), - ?line expect(40, tooBig, 0, []). - - -v2_get_next_p() -> - %% 4.2.2:2 - ?DBG("v2_get_next_p -> entry",[]), - gn([[1,3,7,1]]), - ?line expect(10, [{[1,3,7,1], endOfMibView}]), - gn([[sysDescr], [1,3,7,1]]), - ?line expect(11, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}]), - gn([[tCnt2, 1]]), - ?line expect(12, [{[tCnt2,2], 100}]), - gn([[tCnt2, 2]]), - ?line expect(12, [{[tCnt2,2], endOfMibView}]), - - %% 4.2.2 - any other error: genErr - gn([[tGenErr1]]), - ?line expect(20, genErr, 1, [{[tGenErr1], 'NULL'}]), - gn([[tGenErr2]]), - ?line expect(21, genErr, 1, [{[tGenErr2], 'NULL'}]), - gn([[sysDescr], [tGenErr3]]), - ?line expect(22, genErr, 2, [{[sysDescr], 'NULL'}, - {[tGenErr3], 'NULL'}]), - - %% 4.2.2 - tooBig - gn([[tTooBig]]), - ?line expect(20, tooBig, 0, []). - -v2_get_bulk_p() -> - %% 4.2.3 - ?DBG("v2_get_bulk_p -> entry",[]), - gb(1, 1, []), - ?line expect(10, []), - gb(-1, 1, []), - ?line expect(11, []), - gb(-1, -1, []), - ?line expect(12, []), - gb(-1, -1, []), - ?line expect(13, []), - gb(2, 0, [[sysDescr], [1,3,7,1]]), - ?line expect(14, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}]), - gb(1, 2, [[sysDescr], [1,3,7,1]]), - ?line expect(15, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}]), - gb(0, 2, [[sysDescr], [1,3,7,1]]), - ?line expect(16, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}, - {[sysObjectID, 0], [1,2,3]}, - {[1,3,7,1], endOfMibView}]), - - gb(2, 2, [[sysDescr], [1,3,7,1], [sysDescr], [1,3,7,1]]), - ?line expect(17, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}, - {[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}, - {[sysObjectID, 0], [1,2,3]}, - {[1,3,7,1], endOfMibView}]), - - gb(1, 2, [[sysDescr], [sysDescr], [tTooBig]]), - ?line expect(18, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[sysDescr, 0], "Erlang SNMP agent"}]), - - gb(1,12, [[tDescr2], [sysDescr]]), % next one after tDescr2 is tTooBig. - ?line expect(19, []), - - gb(2,2, [[sysDescr], [sysObjectID], [tGenErr1], [sysDescr]]), - ?line expect(20, genErr, 3, [{[sysDescr], 'NULL'}, - {[sysObjectID], 'NULL'}, - {[tGenErr1], 'NULL'}, - {[sysDescr], 'NULL'}]), - gb(0, 2, [[tCnt2, 1]]), - ?line expect(21, [{[tCnt2,2], 100}, - {[tCnt2,2], endOfMibView}]). - - -v2_set_p() -> - %% 4.2.5:1 - ?DBG("v2_set_p -> entry",[]), - s([{[1,3,7,0], i, 4}]), - ?line expect(10, noAccess, 1, [{[1,3,7,0], 4}]), - s([{[tDescr,0], s, "outside mibview"}]), - ?line expect(11, noAccess, 1, [{[tDescr,0], "outside mibview"}]), - - %% 4.2.5:2 - s([{[1,3,6,1,0], s, "noSuchObject"}]), - ?line expect(20, notWritable, 1, [{[1,3,6,1,0], "noSuchObject"}]), - - %% 4.2.5:3 - s([{[tDescr2, 0], i, 4}]), - ?line expect(30, wrongType, 1, [{[tDescr2, 0], 4}]), - s([{[tDescr2, 0], s, "badValue"}]), - ?line expect(31, badValue, 1, [{[tDescr2, 0], "badValue"}]), - - %% 4.2.5:4 - s([{[tStr, 0], s, ""}]), - ?line expect(40, wrongLength, 1, [{[tStr, 0], ""}]), - s([{[tStr, 0], s, "12345"}]), - ?line expect(40, wrongLength, 1, [{[tStr, 0], "12345"}]), - - %% 4.2.5:5 - N/A - - %% 4.2.5:6 - s([{[tInt1, 0], i, 0}]), - ?line expect(60, wrongValue, 1, [{[tInt1, 0], 0}]), - s([{[tInt1, 0], i, 5}]), - ?line expect(61, wrongValue, 1, [{[tInt1, 0], 5}]), - s([{[tInt2, 0], i, 0}]), - ?line expect(62, wrongValue, 1, [{[tInt2, 0], 0}]), - s([{[tInt2, 0], i, 5}]), - ?line expect(63, wrongValue, 1, [{[tInt2, 0], 5}]), - s([{[tInt3, 0], i, 5}]), - ?line expect(64, wrongValue, 1, [{[tInt3, 0], 5}]), - - %% 4.2.5:7 - s([{[tDescrX, 1, 1], s, "noCreation"}]), - ?line expect(70, noCreation, 1, [{[tDescrX, 1, 1], "noCreation"}]), - - %% 4.2.5:8 - s([{[tDescrX, 1, 2], s, "inconsistentName"}]), - ?line expect(80, inconsistentName, 1, - [{[tDescrX, 1, 2], "inconsistentName"}]), - - %% 4.2.5:9 - s([{[tCnt, 1, 2], i, 5}]), - ?line expect(90, notWritable, 1, [{[tCnt, 1, 2], 5}]), - s([{[tDescr3,0], s, "read-only"}]), - ?line expect(90, notWritable, 1, [{[tDescr3,0], "read-only"}]), - - %% 4.2.5:10 - s([{[tDescr2,0], s, "inconsistentValue"}]), - ?line expect(100, inconsistentValue, 1, - [{[tDescr2,0], "inconsistentValue"}]), - - %% 4.2.5:11 - s([{[tDescr2,0], s, "resourceUnavailable"}]), - ?line expect(110, resourceUnavailable, 1, - [{[tDescr2,0],"resourceUnavailable"}]), - - %% 4.2.5:12 - s([{[tDescr2, 0], s, "is_set_ok_fail"}]), - ?line expect(120, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]). - - %% commitFailed and undoFailed is tested by the 'undo' case. - - -%% Req. OLD-SNMPEA-MIB -table_test() -> - io:format("Testing simple get, next and set on communityTable...~n"), -%% {[147,214,36,45], "public", 2, readWrite}. -%% {[147,214,36,45], "standard trap", 2, read}. - Key1c3 = [intCommunityViewIndex,get(mip),is("public")], - Key2c3 = [intCommunityViewIndex,get(mip),is("standard trap")], - Key1c4 = [intCommunityAccess,get(mip),is("public")], - EndKey = [intCommunityEntry,[9],get(mip),is("public")], - gn([[intCommunityEntry]]), - ?line expect(7, [{Key1c3, 2}]), - gn([[intCommunityTable]]), - ?line expect(71, [{Key1c3, 2}]), - gn([[community]]), - ?line expect(72, [{Key1c3, 2}]), - gn([[otpSnmpeaMIB]]), - ?line expect(73, [{Key1c3, 2}]), - gn([[ericsson]]), - ?line expect(74, [{Key1c3, 2}]), - gn([Key1c3]), - ?line expect(8, [{Key2c3, 2}]), - gn([Key2c3]), - ?line expect(9, [{Key1c4, 2}]), - gn([EndKey]), - AgentIp = [intAgentIpAddress,0], - ?line expect(10, [{AgentIp, any}]), - g([Key1c3]), - ?line expect(11, [{Key1c3, 2}]), - g([EndKey]), - ?line ?v1_2(expect(12, noSuchName, 1, any), - expect(12, [{EndKey, noSuchObject}])), - - io:format("Testing row creation/deletion on communityTable...~n"), - NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], - NewKeyc4 = [intCommunityAccess,get(mip),is("test")], - NewKeyc5 = [intCommunityStatus,get(mip),is("test")], - s([{NewKeyc5, ?createAndGo}]), - ?line expect(14, ?v1_2(badValue, inconsistentValue), 1,any), - s([{NewKeyc5, ?createAndGo}, {NewKeyc3, 2}, {NewKeyc4, 2}]), - ?line expect(15, [{NewKeyc5, ?createAndGo},{NewKeyc3, 2}, {NewKeyc4, 2}]), - g([NewKeyc4]), - ?line expect(16, [{NewKeyc4, 2}]), - s([{NewKeyc5, ?destroy}]), - ?line expect(17, [{NewKeyc5, ?destroy}]), - s([{NewKeyc4, 2}]), - ?line expect(18, ?v1_2(noSuchName, inconsistentName), 1,[{NewKeyc4, 2}]), - s([{NewKeyc5, ?createAndWait}]), - ?line expect(19, [{NewKeyc5, ?createAndWait}]), - g([NewKeyc5]), - ?line expect(20, [{NewKeyc5, ?notReady}]), - s([{NewKeyc4, 2}]), - ?line expect(21, [{NewKeyc4, 2}]), - g([NewKeyc5]), - ?line expect(22, [{NewKeyc5, ?notReady}]), - s([{NewKeyc3, 2}]), - ?line expect(23, [{NewKeyc3, 2}]), - g([NewKeyc5]), - ?line expect(24, [{NewKeyc5, ?notInService}]), - s([{NewKeyc5, ?active}]), - ?line expect(25, [{NewKeyc5, ?active}]), - s([{NewKeyc5, ?destroy}]), - ?line expect(26, [{NewKeyc5, ?destroy}]), - s([{NewKeyc3, 3}]), - ?line expect(27, ?v1_2(noSuchName, inconsistentName), 1,[{NewKeyc3, 3}]), - otp_1128(). - -%% Req. system group -simple_standard_test() -> - ?DBG("simple_standard_test -> entry",[]), - gn([[1,1]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3]]), - ?line expect(11, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6]]), - ?line expect(12, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6,1]]), - ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6,1,2]]), - ?line expect(14, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6,1,2,1]]), - ?line expect(15, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6,1,2,1,1]]), - ?line expect(16, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[sysDescr]]), - ?line expect(17, [{[sysDescr,0], "Erlang SNMP agent"}]), - g([[sysDescr,0]]), - ?line expect(2, [{[sysDescr,0], "Erlang SNMP agent"}]), - g([[sysDescr]]), - ?line ?v1_2(expect(3, noSuchName, 1, any), - expect(3, [{[sysDescr], noSuchObject}])), - g([[1,6,7,0]]), - ?line ?v1_2(expect(41, noSuchName, 1, any), - expect(3, [{[1,6,7,0], noSuchObject}])), - gn([[1,13]]), - ?line ?v1_2(expect(4, noSuchName,1, any), - expect(4, [{[1,13], endOfMibView}])), - s([{[sysLocation, 0], "new_value"}]), - ?line expect(5, [{[sysLocation, 0], "new_value"}]), - g([[sysLocation, 0]]), - ?line expect(6, [{[sysLocation, 0], "new_value"}]), - io:format("Testing noSuchName and badValue...~n"), - s([{[sysServices,0], 3}]), - ?line expect(61, ?v1_2(noSuchName, notWritable), 1, any), - s([{[sysLocation, 0], i, 3}]), - ?line expect(62, ?v1_2(badValue, wrongType), 1, any), - ?DBG("simple_standard_test -> done",[]), - ok. - -%% This is run in the agent node -db_notify_client(suite) -> []; -db_notify_client(Config) when list(Config) -> - {SaNode, MgrNode, MibDir} = init_case(Config), - ?DBG("~n\tSaNode: ~p~n\tMgrNode: ~p~n\tMibDir: ~p", - [SaNode,MgrNode,MibDir]), - snmpa_local_db:register_notify_client(self(),?MODULE), - - %% This call (the manager) will issue to set operations, so - %% we expect to receive to notify(insert) calls. - try_test(db_notify_client_test), - - ?DBG("await first notify",[]), - receive - {db_notify_test_reply,insert} -> ?DBG("first notify received",[]),ok - end, - - ?DBG("await second notify",[]), - receive - {db_notify_test_reply,insert} -> ?DBG("second notify received",[]),ok - end, - - snmpa_local_db:unregister_notify_client(self()). - - -%% This is run in the manager node -db_notify_client_test() -> - ?DBG("set first new sysLocation",[]), - s([{[sysLocation, 0], "new_value"}]), - ?line expect(5, [{[sysLocation, 0], "new_value"}]), - - ?DBG("set second new sysLocation",[]), - s([{[sysLocation, 0], "new_value"}]), - ?line expect(5, [{[sysLocation, 0], "new_value"}]). - -notify(Pid,What) -> - ?DBG("notify(~p,~p) -> called",[Pid,What]), - Pid ! {db_notify_test_reply,What}. - - -%% Req: system group, OLD-SNMPEA-MIB, Klas1 -big_test() -> - ?DBG("big_test -> testing simple next/get/set @ master agent...",[]), - simple_standard_test(), - - ?DBG("big_test -> testing simple next/get/set @ subagent...",[]), - gn([[klas1]]), - ?line expect(1, [{[fname,0], ""}]), - g([[fname,0]]), - ?line expect(2, [{[fname,0], ""}]), - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - g([[fname,0]]), - ?line expect(4, [{[fname,0], "test set"}]), - - ?DBG("big_test -> " - "testing next from last instance in master to subagent...",[]), - gn([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(5, [{[fname,0], "test set"}]), - gn([[1,1], - [?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, - {[fname,0], "test set"}]), - s([{[fname,0], s, ""}]), - ?line expect(52, [{[fname,0], ""}]), - - table_test(), - - ?DBG("big_test -> adding one row in subagent table",[]), - _FTab = [friendsEntry], - s([{[friendsEntry, [2, 3]], s, "kompis3"}, - {[friendsEntry, [3, 3]], i, ?createAndGo}]), - ?line expect(6, [{[friendsEntry, [2, 3]], "kompis3"}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - g([[friendsEntry, [2, 3]], - [friendsEntry, [3, 3]]]), - ?line expect(7, [{[friendsEntry, [2, 3]], "kompis3"}, - {[friendsEntry, [3, 3]], ?active}]), - s([{[friendsEntry, [3, 3]], i, ?destroy}]), - ?line expect(8, [{[friendsEntry, [3, 3]], ?destroy}]), - - otp_1131(), - - ?DBG("big_test -> adding two rows in subagent table with special INDEX", - []), - s([{[kompissEntry, [1, 3]], s, "kompis3"}, - {[kompissEntry, [2, 3]], i, ?createAndGo}]), - ?line expect(9, [{[kompissEntry, [1, 3]], "kompis3"}, - {[kompissEntry, [2, 3]], ?createAndGo}]), - g([[kompissEntry, [1, 3]], - [kompissEntry, [2, 3]]]), - ?line expect(10, [{[kompissEntry, [1, 3]], "kompis3"}, - {[kompissEntry, [2, 3]], ?active}]), - gn([[kompissEntry, [1]], - [kompissEntry, [2]]]), - ?line expect(11, [{[kompissEntry, [1, 3]], "kompis3"}, - {[kompissEntry, [2, 3]], ?active}]), - s([{[kompissEntry, [1, 2]], s, "kompis3"}, - {[kompissEntry, [2, 2]], i, ?createAndGo}]), - ?line expect(12, [{[kompissEntry, [1, 2]], "kompis3"}, - {[kompissEntry, [2, 2]], ?createAndGo}]), - gn([[kompissEntry, [1, 1]], - [kompissEntry, [2, 1]]]), - ?line expect(13, [{[kompissEntry, [1, 2]], "kompis3"}, - {[kompissEntry, [2, 2]], ?active}]), - s([{[kompissEntry, [2, 3]], i, ?destroy}]), - ?line expect(14, [{[kompissEntry, [2, 3]], ?destroy}]), - s([{[kompissEntry, [2, 2]], i, ?destroy}]), - ?line expect(15, [{[kompissEntry, [2, 2]], ?destroy}]), - ?DBG("big_test -> done",[]), - ok. - -%% Req. system group, Klas2, OLD-SNMPEA-MIB -big_test_2() -> - p("Testing simple next/get/set @ master agent (2)..."), - simple_standard_test(), - - p("Testing simple next/get/set @ subagent (2)..."), - gn([[klas2]]), - ?line expect(1, [{[fname2,0], ""}]), - g([[fname2,0]]), - ?line expect(2, [{[fname2,0], ""}]), - s([{[fname2,0], s, "test set"}]), - ?line expect(3, [{[fname2,0], "test set"}]), - g([[fname2,0]]), - ?line expect(4, [{[fname2,0], "test set"}]), - - otp_1298(), - - p("Testing next from last object in master to subagent (2)..."), - gn([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(5, [{[fname2,0], "test set"}]), - gn([[1,1], - [?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, - {[fname2,0], "test set"}]), - - table_test(), - - p("Adding one row in subagent table (2)"), - _FTab = [friendsEntry2], - s([{[friendsEntry2, [2, 3]], s, "kompis3"}, - {[friendsEntry2, [3, 3]], i, ?createAndGo}]), - ?line expect(6, [{[friendsEntry2, [2, 3]], "kompis3"}, - {[friendsEntry2, [3, 3]], ?createAndGo}]), - g([[friendsEntry2, [2, 3]], - [friendsEntry2, [3, 3]]]), - ?line expect(7, [{[friendsEntry2, [2, 3]], "kompis3"}, - {[friendsEntry2, [3, 3]], ?active}]), - s([{[friendsEntry2, [3, 3]], i, ?destroy}]), - ?line expect(8, [{[friendsEntry2, [3, 3]], ?destroy}]), - - p("Adding two rows in subagent table with special INDEX (2)"), - s([{[kompissEntry2, [1, 3]], s, "kompis3"}, - {[kompissEntry2, [2, 3]], i, ?createAndGo}]), - ?line expect(9, [{[kompissEntry2, [1, 3]], "kompis3"}, - {[kompissEntry2, [2, 3]], ?createAndGo}]), - g([[kompissEntry2, [1, 3]], - [kompissEntry2, [2, 3]]]), - ?line expect(10, [{[kompissEntry2, [1, 3]], "kompis3"}, - {[kompissEntry2, [2, 3]], ?active}]), - gn([[kompissEntry2, [1]], - [kompissEntry2, [2]]]), - ?line expect(11, [{[kompissEntry2, [1, 3]], "kompis3"}, - {[kompissEntry2, [2, 3]], ?active}]), - s([{[kompissEntry2, [1, 2]], s, "kompis3"}, - {[kompissEntry2, [2, 2]], i, ?createAndGo}]), - ?line expect(12, [{[kompissEntry2, [1, 2]], "kompis3"}, - {[kompissEntry2, [2, 2]], ?createAndGo}]), - gn([[kompissEntry2, [1, 1]], - [kompissEntry2, [2, 1]]]), - ?line expect(13, [{[kompissEntry2, [1, 2]], "kompis3"}, - {[kompissEntry2, [2, 2]], ?active}]), - s([{[kompissEntry2, [2, 3]], i, ?destroy}]), - ?line expect(14, [{[kompissEntry2, [2, 3]], ?destroy}]), - s([{[kompissEntry2, [2, 2]], i, ?destroy}]), - ?line expect(15, [{[kompissEntry2, [2, 2]], ?destroy}]), - ok. - -%% Req. Test1 -multi_threaded_test() -> - p("Testing multi threaded agent..."), - g([[multiStr,0]]), - Pid = get_multi_pid(), - g([[sysUpTime,0]]), - ?line expect(1, [{[sysUpTime,0], any}]), - s([{[sysLocation, 0], s, "pelle"}]), - ?line expect(2, [{[sysLocation, 0], "pelle"}]), - Pid ! continue, - ?line expect(3, [{[multiStr,0], "ok"}]), - - s([{[multiStr, 0], s, "block"}]), - Pid2 = get_multi_pid(), - g([[sysUpTime,0]]), - ?line expect(4, [{[sysUpTime,0], any}]), - g([[multiStr,0]]), - Pid3 = get_multi_pid(), - g([[sysUpTime,0]]), - ?line expect(5, [{[sysUpTime,0], any}]), - s([{[sysLocation, 0], s, "kalle"}]), - Pid3 ! continue, - ?line expect(6, [{[multiStr,0], "ok"}]), - Pid2 ! continue, - ?line expect(7, [{[multiStr,0], "block"}]), - ?line expect(8, [{[sysLocation,0], "kalle"}]). - -%% Req. Test1, TestTrapv2 -mt_trap_test(MA) -> - snmpa:send_trap(MA, testTrapv22, "standard trap"), - ?line expect(1, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - - snmpa:send_trap(MA, mtTrap, "standard trap"), - Pid = get_multi_pid(), - g([[sysUpTime,0]]), - ?line expect(2, [{[sysUpTime,0], any}]), - snmpa:send_trap(MA, testTrapv22, "standard trap"), - ?line expect(3, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - Pid ! continue, - ?line expect(4, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?testTrap ++ [2]}, - {[multiStr,0], "ok"}]). - - -get_multi_pid() -> - get_multi_pid(10). -get_multi_pid(0) -> - ?line ?FAIL(no_global_name); -get_multi_pid(N) -> - sleep(1000), - case global:whereis_name(snmp_multi_tester) of - Pid when pid(Pid) -> Pid; - _ -> get_multi_pid(N-1) - end. - -%% Req. Test1 -types_v2_test() -> - p("Testing v2 types..."), - - s([{[bits1,0], 2#10}]), - ?line expect(1, [{[bits1,0], ?str(2#10)}]), - g([[bits1,0]]), - ?line expect(2, [{[bits1,0], ?str(2#101)}]), - - s([{[bits2,0], 2#11000000110}]), - ?line expect(3, [{[bits2,0], ?str(2#11000000110)}]), - g([[bits2,0]]), - ?line expect(4, [{[bits2,0], ?str(2#11000000110)}]), - - g([[bits3,0]]), - ?line expect(50, genErr, 1, any), - - g([[bits4,0]]), - ?line expect(51, genErr, 1, any), - - s([{[bits1,0], s, [2#10]}]), - ?line expect(6, ?v1_2(badValue, wrongValue), 1, any), - - s([{[bits2,0], 2#11001001101010011}]), - ?line expect(7, ?v1_2(badValue, wrongValue), 1, any). - - -%% Req. Test1 -implied_test(MA) -> - ?LOG("implied_test -> start",[]), - p("Testing IMPLIED..."), - - snmpa:verbosity(MA,trace), - snmpa:verbosity(MA,trace), - - %% Create two rows, check that they are get-nexted in correct order. - Idx1 = "apa", - Idx2 = "qq", - ?DBG("implied_test -> (send) create row 1 '~s' in table 1",[Idx1]), - s([{[testStatus, Idx1], i, ?createAndGo}, {[testDescr, Idx1],s,"row 1"}]), - ?line expect(1, [{[testStatus, Idx1], ?createAndGo}, - {[testDescr, Idx1], "row 1"}]), - ?DBG("implied_test -> (send) create row 2 '~s' in table 1",[Idx2]), - s([{[testStatus, Idx2], i, ?createAndGo}, {[testDescr, Idx2],s,"row 2"}]), - ?line expect(2, [{[testStatus, Idx2], ?createAndGo}, - {[testDescr, Idx2], "row 2"}]), - ?DBG("implied_test -> get-next(testDescr)",[]), - gn([[testDescr]]), - ?line expect(3, [{[testDescr,Idx1], "row 1"}]), - ?DBG("implied_test -> get-next(testDescr) of row 1",[]), - gn([[testDescr,Idx1]]), - ?line expect(4, [{[testDescr,Idx2], "row 2"}]), - - % Delete the rows - ?DBG("implied_test -> (send) delete row 1 '~s' from table 1",[Idx1]), - s([{[testStatus, Idx1], i, ?destroy}]), - ?line expect(5, [{[testStatus, Idx1], ?destroy}]), - ?DBG("implied_test -> (send) delete row 2 '~s' from table 1",[Idx2]), - s([{[testStatus, Idx2], i, ?destroy}]), - ?line expect(6, [{[testStatus, Idx2], ?destroy}]), - - %% Try the same in other table - Idx3 = [1, "apa"], - Idx4 = [1, "qq"], - ?DBG("implied_test -> (send) create row 1 '~s' in table 2",[Idx3]), - s([{[testStatus2, Idx3], i, ?createAndGo}, {[testDescr2,Idx3],s,"row 1"}]), - ?line expect(1, [{[testStatus2, Idx3], ?createAndGo}, - {[testDescr2, Idx3], "row 1"}]), - ?DBG("implied_test -> (send) create row 2 '~s' in table 2",[Idx4]), - s([{[testStatus2, Idx4], i, ?createAndGo}, {[testDescr2,Idx4],s,"row 2"}]), - ?line expect(2, [{[testStatus2, Idx4], ?createAndGo}, - {[testDescr2, Idx4], "row 2"}]), - ?DBG("implied_test -> get-next(testDescr2)",[]), - gn([[testDescr2]]), - ?line expect(3, [{[testDescr2,Idx3], "row 1"}]), - ?DBG("implied_test -> get-next(testDescr2) of row 1",[]), - gn([[testDescr2,Idx3]]), - ?line expect(4, [{[testDescr2,Idx4], "row 2"}]), - - % Delete the rows - ?DBG("implied_test -> (send) delete row 1 '~s' from table 2",[Idx3]), - s([{[testStatus2, Idx3], i, ?destroy}]), - ?line expect(5, [{[testStatus2, Idx3], ?destroy}]), - ?DBG("implied_test -> (send) delete row 2 '~s' from table 2",[Idx4]), - s([{[testStatus2, Idx4], i, ?destroy}]), - ?line expect(6, [{[testStatus2, Idx4], ?destroy}]), - - snmpa:verbosity(MA,log), - - ?LOG("implied_test -> done",[]). - - - -%% Req. Test1 -sparse_table_test() -> - p("Testing sparse table..."), - - %% Create two rows, check that they are get-nexted in correct order. - Idx1 = 1, - Idx2 = 2, - s([{[sparseStatus, Idx1], i, ?createAndGo}, - {[sparseDescr, Idx1], s, "row 1"}]), - ?line expect(1, [{[sparseStatus, Idx1], ?createAndGo}, - {[sparseDescr, Idx1], "row 1"}]), - s([{[sparseStatus, Idx2], i, ?createAndGo}, - {[sparseDescr, Idx2], s, "row 2"}]), - ?line expect(2, [{[sparseStatus, Idx2], ?createAndGo}, - {[sparseDescr, Idx2], "row 2"}]), - ?v1_2(gn([[sparseIndex], [sparseDescr,Idx1], [sparseDescr,Idx2], - [sparseStatus,Idx1], [sparseStatus,Idx2]]), - gb(0,5,[[sparseIndex]])), - ?line expect(3, [{[sparseDescr,Idx1], "row 1"}, - {[sparseDescr,Idx2], "row 2"}, - {[sparseStatus,Idx1], ?active}, - {[sparseStatus,Idx2], ?active}, - {[sparseStr,0], "slut"}]), - % Delete the rows - s([{[sparseStatus, Idx1], i, ?destroy}]), - ?line expect(4, [{[sparseStatus, Idx1], ?destroy}]), - s([{[sparseStatus, Idx2], i, ?destroy}]), - ?line expect(5, [{[sparseStatus, Idx2], ?destroy}]). - - -%% Req. Test1 -cnt_64_test(MA) -> - ?LOG("start cnt64 test (~p)",[MA]), - snmpa:verbosity(MA,trace), - ?LOG("start cnt64 test",[]), - p("Testing Counter64, and at the same time, RowStatus is not last column"), - - ?DBG("get cnt64",[]), - g([[cnt64,0]]), - ?DBG("await response",[]), - ?line ?v1_2(expect(1, noSuchName, 1, any), - expect(1, [{[cnt64,0],18446744073709551615}])), - ?DBG("get-next cnt64",[]), - gn([[cnt64]]), - ?DBG("await response",[]), - ?line ?v1_2(expect(2, [{[cnt64Str,0], "after cnt64"}]), - expect(2, [{[cnt64,0],18446744073709551615}])), - ?DBG("send cntTrap",[]), - snmpa:send_trap(MA,cntTrap,"standard trap",[{sysContact,"pelle"}, - {cnt64, 10}, - {sysLocation, "here"}]), - ?DBG("await response",[]), - ?line ?v1_2(expect(3, trap, [test], 6, 1, [{[sysContact,0], "pelle"}, - {[sysLocation,0], "here"}]), - expect(3, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?testTrap ++ [1]}, - {[sysContact,0], "pelle"}, - {[cnt64,0], 10}, - {[sysLocation,0], "here"}])), - - %% Create two rows, check that they are get-nexted in correct order. - Idx1 = 1, - Idx2 = 2, - ?DBG("create row (cntStatus): ~p",[Idx1]), - s([{[cntStatus, Idx1], i, ?createAndGo}]), - ?DBG("await response",[]), - ?line expect(1, [{[cntStatus, Idx1], ?createAndGo}]), - ?DBG("create row (cntStatus): ~p",[Idx2]), - s([{[cntStatus, Idx2], i, ?createAndGo}]), - ?DBG("await response",[]), - ?line expect(2, [{[cntStatus, Idx2], ?createAndGo}]), - - ?DBG("get-next (cntIndex)",[]), - gn([[cntIndex]]), - ?DBG("await response",[]), - ?line ?v1_2(expect(3, [{[cntStatus,Idx1], ?active}]), - expect(3, [{[cntCnt,Idx1], 0}])), - % Delete the rows - ?DBG("delete row (cntStatus): ~p",[Idx1]), - s([{[cntStatus, Idx1], i, ?destroy}]), - ?DBG("await response",[]), - ?line expect(4, [{[cntStatus, Idx1], ?destroy}]), - ?DBG("delete row (cntStatus): ~p",[Idx2]), - s([{[cntStatus, Idx2], i, ?destroy}]), - ?DBG("await response",[]), - ?line expect(5, [{[cntStatus, Idx2], ?destroy}]), - catch snmpa:verbosity(MA,log), - ?DBG("done",[]), - ok. - -%% Req. Test1 -opaque_test() -> - p("Testing Opaque datatype..."), - g([[opaqueObj,0]]), - ?line expect(1, [{[opaqueObj,0], "opaque-data"}]). - -%% Req. OLD-SNMPEA-MIB -api_test(MaNode) -> - ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, - [intAgentIpAddress]), - ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, - oid_to_name, [OID]), - ?line false = rpc:call(MaNode, snmp, name_to_oid, [intAgentIpAddres]), - ?line false = rpc:call(MaNode, snmp, oid_to_name, - [[1,5,32,3,54,3,3,34,4]]), - ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, - [intViewType, excluded]), - ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, - [intViewType, 2]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, [intViewType, exclude]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [intAgentIpAddress, exclude]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [intAgentIpAddre, exclude]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [intViewType, 3]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddress, 2]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddre, 2]), - ?line {value, active} = rpc:call(MaNode, snmp, - int_to_enum, ['RowStatus', ?active]), - ?line {value, ?destroy} = rpc:call(MaNode, snmp, - enum_to_int, ['RowStatus', destroy]), - ?line false = rpc:call(MaNode, snmp, - enum_to_int, ['RowStatus', xxxdestroy]), - ?line false = rpc:call(MaNode, snmp, - enum_to_int, ['xxRowStatus', destroy]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, ['RowStatus', 25]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, ['xxRowStatus', 1]), - ?line case snmp:date_and_time() of - List when list(List), length(List) == 8 -> ok; - List when list(List), length(List) == 11 -> ok - end. - -%% Req. Klas3 -api_test2() -> - g([[fname3,0]]), - ?line expect(1, [{[fname3,0], "ok"}]), - g([[fname4,0]]), - ?line expect(2, [{[fname4,0], 1}]). - -api_test3() -> - g([[fname3,0]]), - ?line expect(1, [{[fname3,0], "ok"}]). - - -unreg_test() -> - gn([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(1, [{[snmpInPkts, 0], any}]). - -load_test() -> - gn([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(1, [{[fname,0], ""}]). - -%% Req. Klas1 -load_test_sa() -> - gn([[?v1_2(sysServices,sysORLastChange), 0]]), - ?line expect(1, [{[fname,0], any}]). - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_get() -> - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - g([[sysDescr,0], Key1c4, [fname,0],Key1c3, - [sysName,0]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[fname,0], "test set"}, - {Key1c3, 2}, - {[sysName,0], "test"}]), - g([[1,3,7,1], Key1c4, [sysDescr,0], [1,3,7,2], Key1c3, [sysDescr,0]]), - ?line ?v1_2(expect(2, noSuchName, [1,4], any), - expect(2, [{[1,3,7,1], noSuchObject}, - {Key1c4, 2}, - {[sysDescr,0], "Erlang SNMP agent"}, - {[1,3,7,2], noSuchObject}, - {Key1c3, 2}, - {[sysDescr,0], "Erlang SNMP agent"}])). - -%% Req. v1, system group, Klas1, OLD-SNMPEA-MIB, *ej* Klas3. -do_mul_get_err() -> - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - g([[sysDescr,0],Key1c4,[fname,0], Key1c3, [sysName,2]]), - ?line ?v1_2(expect(1, noSuchName, 5, any), - expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[fname,0], "test set"}, - {Key1c3, 2}, - {[sysName,2], noSuchInstance}])), - g([[sysDescr,0],Key1c4,[fname3,0], Key1c3, [sysName,1]]), - ?line ?v1_2(expect(1, noSuchName, [3,5], any), - expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[fname3,0], noSuchObject}, - {Key1c3, 2}, - {[sysName,1], noSuchInstance}])). - - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_next() -> - Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], - Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - gn([[sysDescr], Key1c4s, [fname],Key1c3s,[sysName]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, {[fname,0], "test set"}, - {Key1c3, 2}, {[sysName,0], "test"}]). - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_next_err() -> - Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], - Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - gn([[sysDescr], Key1c4s, [1,3,6,999], [fname],[1,3,90], Key1c3s,[sysName]]), - ?line ?v1_2(expect(1, noSuchName, [3,5], any), - expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[1,3,6,999], endOfMibView}, - {[fname,0], "test set"}, - {[1,3,90], endOfMibView}, - {Key1c3, 2}, - {[sysName,0], "test"}])). - - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_set() -> - p("Adding one row in subagent table, and one in master table"), - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - s([{[friendsEntry, [2, 3]], "kompis3"}, - {NewKeyc3, 2}, - {[sysLocation,0], "new_value"}, - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - ?line expect(1, [{[friendsEntry, [2, 3]], "kompis3"}, - {NewKeyc3, 2}, - {[sysLocation,0], "new_value"}, - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - g([[friendsEntry, [2, 3]], - [sysLocation,0], - [friendsEntry, [3, 3]]]), - ?line expect(2, [{[friendsEntry, [2, 3]], "kompis3"}, - {[sysLocation,0], "new_value"}, - {[friendsEntry, [3, 3]], ?active}]), - g([NewKeyc4]), - ?line expect(3, [{NewKeyc4, 2}]), - s([{[friendsEntry, [3, 3]], ?destroy}, - {NewKeyc5, ?destroy}]), - ?line expect(4, [{[friendsEntry, [3, 3]], ?destroy}, - {NewKeyc5, ?destroy}]). - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_set_err() -> - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - p("Adding one row in subagent table, and one in master table"), - s([{[friendsEntry, [2, 3]], s, "kompis3"}, - {NewKeyc3, 2}, - {[sysUpTime,0], 45}, % sysUpTime (readOnly) - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - ?line expect(1, ?v1_2(noSuchName, notWritable), 3, any), - g([[friendsEntry, [2, 3]]]), - ?line ?v1_2(expect(2, noSuchName, 1, any), - expect(2, [{[friendsEntry, [2,3]], noSuchInstance}])), - g([NewKeyc4]), - ?line ?v1_2(expect(3, noSuchName, 1, any), - expect(3, [{NewKeyc4, noSuchInstance}])). - -%% Req. SA-MIB -sa_mib() -> - g([[sa, [2,0]]]), - ?line expect(1, [{[sa, [2,0]], 3}]), - s([{[sa, [1,0]], s, "sa_test"}]), - ?line expect(2, [{[sa, [1,0]], "sa_test"}]). - -ma_trap1(MA) -> - snmpa:send_trap(MA, testTrap2, "standard trap"), - ?line expect(1, trap, [system], 6, 1, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}]), - snmpa:send_trap(MA, testTrap1, "standard trap"), - ?line expect(2, trap, [1,2,3] , 1, 0, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}]). - -ma_trap2(MA) -> - snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). - -ma_v2_2_v1_trap(MA) -> - snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). - -ma_v2_2_v1_trap2(MA) -> - snmpa:send_trap(MA,linkUp,"standard trap",[{ifIndex, [1], 1}, - {ifAdminStatus, [1], 1}, - {ifOperStatus, [1], 2}]), - ?line expect(3, trap, [1,2,3], 3, 0, [{[ifIndex, 1], 1}, - {[ifAdminStatus, 1], 1}, - {[ifOperStatus, 1], 2}]). - -sa_trap1(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap"), - ?line expect(4, trap, [ericsson], 6, 1, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}]). - -sa_trap2(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), - ?line expect(5, trap, [ericsson], 6, 1, [{[system, [4,0]], - "pelle"}, - {[sa, [1,0]], "sa_test"}]). - -sa_trap3(SA) -> - snmpa:send_trap(SA, saTrap2, "standard trap", - [{intViewSubtree, [4], [1,2,3,4]}]), - ?line expect(6, trap, [ericsson], 6, 2, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}, - {[intViewSubtree,4],[1,2,3,4]}]). - -ma_v2_trap1(MA) -> - ?DBG("ma_v2_traps -> entry with MA = ~p => " - "send standard trap: testTrapv22",[MA]), - snmpa:send_trap(MA, testTrapv22, "standard trap"), - ?line expect(1, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - ?DBG("ma_v2_traps -> send standard trap: testTrapv21",[]), - snmpa:send_trap(MA, testTrapv21, "standard trap"), - ?line expect(2, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?snmp ++ [1]}]). - -ma_v2_trap2(MA) -> - snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}, - {[system, [4,0]], "pelle"}]). - -%% Note: This test case takes a while... actually a couple of minutes. -ma_v2_inform1(MA) -> - ?DBG("ma_v2_inform -> entry with MA = ~p => " - "send notification: testTrapv22",[MA]), - ?line snmpa:send_notification(MA, testTrapv22, no_receiver, "standard inform", []), - ?line expect(1, {inform, true}, - [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - - ?DBG("ma_v2_inform -> send notification: testTrapv22",[]), - snmpa:send_notification(MA, testTrapv22, {tag1, self()}, - "standard inform", []), - ?line expect(1, {inform, true}, - [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - ?DBG("ma_v2_inform -> await targets",[]), - receive - {snmp_targets, tag1, [_]} -> - ok; - {snmp_targets, tag1, Addrs1} -> - ?line ?FAIL({bad_addrs, Addrs1}) - after - 5000 -> - ?ERR("ma_v2_inform1 -> awaiting snmp_targets(tag1) timeout",[]), - ?line ?FAIL(nothing_at_all) - end, - ?DBG("ma_v2_inform -> await notification",[]), - receive - {snmp_notification, tag1, {got_response, _}} -> - ok; - {snmp_notification, tag1, {no_response, _}} -> - ?line ?FAIL(no_response) - after - 20000 -> - ?ERR("ma_v2_inform1 -> " - "awaiting snmp_notification(tag1) timeout",[]), - ?line ?FAIL(nothing_at_all) - end, - - %% - %% -- The rest is possibly erroneous... - %% - - ?DBG("ma_v2_inform -> send notification: testTrapv22",[]), - snmpa:send_notification(MA, testTrapv22, {tag2, self()}, - "standard inform", []), - ?line expect(2, {inform, false}, - [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - ?DBG("ma_v2_inform -> await targets",[]), - receive - {snmp_targets, tag2, [_]} -> - ok; - {snmp_targets, tag2, Addrs2} -> - ?ERR("ma_v2_inform1 -> awaiting snmp_targets(tag2) timeout",[]), - ?line ?FAIL({bad_addrs, Addrs2}) - after - 5000 -> - ?line ?FAIL(nothing_at_all) - end, - ?DBG("ma_v2_inform -> await notification",[]), - receive - {snmp_notification, tag2, {got_response, _}} -> - ?line ?FAIL(got_response); - {snmp_notification, tag2, {no_response, _}} -> - ok - after - 240000 -> - ?ERR("ma_v2_inform1 -> " - "awaiting snmp_notification(tag2) timeout",[]), - ?line ?FAIL(nothing_at_all) - end. - - -ma_v1_2_v2_trap(MA) -> - snmpa:send_trap(MA,linkDown,"standard trap",[{ifIndex, [1], 1}]), - ?line expect(2, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?snmpTraps ++ [3]}, - {[ifIndex, 1], 1}, - {[snmpTrapEnterprise, 0], [1,2,3]}]). - - -ma_v1_2_v2_trap2(MA) -> - snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}, - {[system, [4,0]], "pelle"}, - {[snmpTrapEnterprise, 0], ?system}]). - - -sa_v1_2_v2_trap1(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap"), - ?line expect(4, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, - {[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}, - {[snmpTrapEnterprise, 0], ?ericsson}]). - -sa_v1_2_v2_trap2(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), - ?line expect(4, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, - {[system, [4,0]], "pelle"}, - {[sa, [1,0]], "sa_test"}, - {[snmpTrapEnterprise, 0], ?ericsson}]). - - -sa_v1_2_v2_trap3(SA) -> - snmpa:send_trap(SA, saTrap2, "standard trap", - [{intViewSubtree, [4], [1,2,3,4]}]), - ?line expect(4, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?ericsson ++ [0, 2]}, - {[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}, - {[intViewSubtree,4],[1,2,3,4]}, - {[snmpTrapEnterprise, 0], ?ericsson}]). - - -%% Req. SA-MIB, OLD-SNMPEA-MIB -sa_errs_bad_value() -> - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - s([{NewKeyc3, 2}, - {[sa, [2,0]], 5}, % badValue (i is_set_ok) - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}]), - ?line expect(1, badValue, 2, any), - s([{NewKeyc3, 2}, - {[sa, [2,0]], 6}, % wrongValue (i is_set_ok) - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}]), - ?line expect(1, ?v1_2(badValue, wrongValue), 2, any), - g([NewKeyc4]), - ?line ?v1_2(expect(2, noSuchName, 1, any), - expect(2, [{NewKeyc4, noSuchInstance}])). - -%% Req. SA-MIB, OLD-SNMPEA-MIB -sa_errs_gen_err() -> - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - s([{NewKeyc3, 2},{NewKeyc4, 2}, - {NewKeyc5, ?createAndGo}, {[sa, [3,0]], 5}]), - ?line expect(1, genErr, 4, any), -% The row might have been added; we don't know. -% (as a matter of fact we do - it is added, because the agent -% first sets its own vars, and then th SAs. Lets destroy it. - s([{NewKeyc5, ?destroy}]), - ?line expect(2, [{NewKeyc5, ?destroy}]). - -%% Req. SA-MIB, OLD-SNMPEA-MIB -sa_too_big() -> - g([[sa, [4,0]]]), - ?line expect(1, tooBig). - -%% Req. Klas1, system group, snmp group (v1/v2) -next_across_sa() -> - gn([[sysDescr],[klas1,5]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {[snmpInPkts, 0], any}]). - -%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]). -> noError -%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]). -> {badValue, 2} -%% snmp_test_mgr:s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]). -> {genErr, 1} -%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]). -> {genErr, 1} -%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]). -> {genErr, 1} -%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]). -> {genErr, 2} -%% Req. Klas3, Klas4 -undo_test() -> - s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), - ?line expect(1, [{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), - s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]), - ?line expect(2, ?v1_2(badValue, inconsistentValue), 2, any), - s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]), - ?line expect(3, ?v1_2(genErr, undoFailed), 1, any), - s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]), - ?line expect(4, ?v1_2(genErr, commitFailed), 1, any), -% unfortunatly we don't know if we'll get undoFailed or commitFailed. -% it depends on which order the agent traverses the varbind list. -% s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]), -% ?line expect(5, ?v1_2(genErr, undoFailed), 1, any), - s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]), - ?line expect(6, genErr, 2, any). - -%% Req. Klas3, Klas4 -bad_return() -> - g([[fStatus4,4], - [fName4,4]]), - ?line expect(4, genErr, 2, any), - g([[fStatus4,5], - [fName4,5]]), - ?line expect(5, genErr, 1, any), - g([[fStatus4,6], - [fName4,6]]), - ?line expect(6, genErr, 2, any), - gn([[fStatus4,7], - [fName4,7]]), - ?line expect(7, genErr, 2, any), - gn([[fStatus4,8], - [fName4,8]]), - ?line expect(8, genErr, 1, any), - gn([[fStatus4,9], - [fName4,9]]), - ?line expect(9, genErr, 2, any). - - -%%%----------------------------------------------------------------- -%%% Test the implementation of standard mibs. -%%% We should *at least* try to GET all variables, just to make -%%% sure the instrumentation functions work. -%%% Note that many of the functions in the standard mib is -%%% already tested by the normal tests. -%%%----------------------------------------------------------------- - - - -%%----------------------------------------------------------------- -%% For this test, the agent is configured for v1. -%% o Test the counters and control objects in SNMP-STANDARD-MIB -%%----------------------------------------------------------------- -snmp_standard_mib(suite) -> []; -snmp_standard_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?DBG("snmp_standard_mib -> std_mib_init", []), - try_test(std_mib_init), - - ?DBG("snmp_standard_mib -> std_mib_a", []), - InBadVsns = try_test(std_mib_a), - put(vsn, v2), - ?DBG("snmp_standard_mib -> std_mib_read", []), - try_test(std_mib_read), - put(vsn, v1), - - ?DBG("snmp_standard_mib -> std_mib_b (~w)", [InBadVsns]), - Bad = try_test(std_mib_b, [InBadVsns]), - ?DBG("snmp_standard_mib -> std_mib_read (community: 'bad community')", []), - try_test(std_mib_read, [], [{community, "bad community"}]), - ?DBG("snmp_standard_mib -> std_mib_write (community: 'public')", []), - try_test(std_mib_write, [], [{community, "public"}]), - ?DBG("snmp_standard_mib -> std_mib_asn_err", []), - try_test(std_mib_asn_err), - ?DBG("snmp_standard_mib -> std_mib_c (~w)", [Bad]), - try_test(std_mib_c, [Bad]), - ?DBG("snmp_standard_mib -> std_mib_a", []), - try_test(standard_mib_a), - - ?DBG("snmp_standard_mib -> std_mib_finish", []), - try_test(std_mib_finish), - ?DBG("snmp_standard_mib -> std_mib_test_finish", []), - try_test(standard_mib_test_finish, [], [{community, "bad community"}]). - -%% Req. SNMP-STANDARD-MIB -standard_mib_a() -> - ?line [OutPkts] = get_req(2, [[snmpOutPkts,0]]), - ?line [OutPkts2] = get_req(3, [[snmpOutPkts,0]]), - ?line OutPkts2 = OutPkts + 1, - %% There are some more counters we could test here, but it's not that - %% important, since they are removed from SNMPv2-MIB. - ok. - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_init() -> - %% disable authentication failure traps. (otherwise w'd get many of - %% them - this is also a test to see that it works). - s([{[snmpEnableAuthenTraps,0], 2}]), - ?line expect(1, [{[snmpEnableAuthenTraps, 0], 2}]). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_finish() -> - %% enable again - s([{[snmpEnableAuthenTraps,0], 1}]), - ?line expect(1, [{[snmpEnableAuthenTraps, 0], 1}]). - -%% Req. SNMP-STANDARD-MIB -standard_mib_test_finish() -> - %% force a authenticationFailure - std_mib_write(), - %% check that we got a trap - ?line expect(2, trap, [1,2,3], 4, 0, []). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_read() -> - ?DBG("std_mib_read -> entry", []), - g([[sysUpTime,0]]), % try a bad ; msg dropped, no reply - ?DBG("std_mib_read -> await timeout (i.e. no reply)", []), - ?line expect(1, timeout). % make sure we don't get a trap! - - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_write() -> - ?DBG("std_mib_write -> entry", []), - s([{[sysLocation, 0], "new_value"}]). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_asn_err() -> - snmp_test_mgr:send_bytes([48,99,67,12,0,0,0,0,0,0,5]). - -%%----------------------------------------------------------------- -%% For this test, the agent is configured for v2 and v3. -%% o Test the counters and control objects in SNMPv2-MIB -%%----------------------------------------------------------------- -snmpv2_mib_2(suite) -> []; -snmpv2_mib_2(Config) when list(Config) -> - ?LOG("snmpv2_mib_2 -> start",[]), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?DBG("snmpv2_mib_2 -> standard mib init",[]), - try_test(std_mib_init), - - ?DBG("snmpv2_mib_2 -> get number of (so far) bad versions",[]), - InBadVsns = try_test(std_mib_a), - - ?DBG("snmpv2_mib_2 -> make a bad version read",[]), - put(vsn, v1), - try_test(std_mib_read), - - ?DBG("snmpv2_mib_2 -> bad version read",[]), - put(vsn, v2), - Bad = try_test(std_mib_b, [InBadVsns]), - - ?DBG("snmpv2_mib_2 -> read with bad community",[]), - try_test(std_mib_read, [], [{community, "bad community"}]), - - ?DBG("snmpv2_mib_2 -> write with public community",[]), - try_test(std_mib_write, [], [{community, "public"}]), - - ?DBG("snmpv2_mib_2 -> asn err",[]), - try_test(std_mib_asn_err), - - ?DBG("snmpv2_mib_2 -> check counters",[]), - try_test(std_mib_c, [Bad]), - - ?DBG("snmpv2_mib_2 -> get som counters",[]), - try_test(snmpv2_mib_a), - - ?DBG("snmpv2_mib_2 -> enable auth traps, and await some",[]), - try_test(std_mib_finish), - - ?DBG("snmpv2_mib_2 -> force auth failure, and await trap, " - "then disable auth traps",[]), - try_test(snmpv2_mib_test_finish, [], [{community, "bad community"}]), - - ?LOG("snmpv2_mib_2 -> done",[]). - -%% Req. SNMPv2-MIB -snmpv2_mib_3(suite) -> []; -snmpv2_mib_3(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - InBadVsns = try_test(std_mib_a), - put(vsn, v1), - try_test(std_mib_read), - put(vsn, v3), - _Bad = try_test(std_mib_b, [InBadVsns]), - try_test(snmpv2_mib_a), - - try_test(std_mib_finish). - --define(authenticationFailure, [1,3,6,1,6,3,1,1,5,5]). - -%% Req. SNMPv2-MIB -snmpv2_mib_test_finish() -> - %% force a authenticationFailure - ?DBG("ma_v2_inform -> write to std mib",[]), - std_mib_write(), - - %% check that we got a trap - ?DBG("ma_v2_inform -> await trap",[]), - ?line expect(2, v2trap, [{[sysUpTime,0], any}, - {[snmpTrapOID,0], ?authenticationFailure}]), - - %% and the the inform - ?DBG("ma_v2_inform -> await inform",[]), - ?line expect(2, {inform,true}, [{[sysUpTime,0], any}, - {[snmpTrapOID,0],?authenticationFailure}]). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_a() -> - ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), - ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), - ?line InPkts2 = InPkts + 1, - - ?line [InBadVsns] = get_req(4, [[snmpInBadVersions,0]]), - InBadVsns. - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_b(InBadVsns) -> - ?line [InBadVsns2] = get_req(1, [[snmpInBadVersions,0]]), - ?line InBadVsns2 = InBadVsns + 1, - ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), - ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), - ?line InPkts2 = InPkts + 1, - ?line [InBadCommunityNames, InBadCommunityUses, InASNErrs] = - get_req(4, [[snmpInBadCommunityNames,0], - [snmpInBadCommunityUses,0], - [snmpInASNParseErrs, 0]]), - {InBadCommunityNames, InBadCommunityUses, InASNErrs}. - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_c({InBadCommunityNames, InBadCommunityUses, InASNErrs}) -> - ?line [InBadCommunityNames2, InBadCommunityUses2, InASNErrs2] = - get_req(1, [[snmpInBadCommunityNames,0], - [snmpInBadCommunityUses,0], - [snmpInASNParseErrs, 0]]), - ?line InBadCommunityNames2 = InBadCommunityNames + 1, - ?line InBadCommunityUses2 = InBadCommunityUses + 1, - ?line InASNErrs2 = InASNErrs + 1. - -%% Req. SNMPv2-MIB -snmpv2_mib_a() -> - ?line [SetSerial] = get_req(2, [[snmpSetSerialNo,0]]), - s([{[snmpSetSerialNo,0], SetSerial}, {[sysLocation, 0], "val2"}]), - ?line expect(3, [{[snmpSetSerialNo,0], SetSerial}, - {[sysLocation, 0], "val2"}]), - s([{[sysLocation, 0], "val3"}, {[snmpSetSerialNo,0], SetSerial}]), - ?line expect(4, inconsistentValue, 2, - [{[sysLocation, 0], "val3"}, - {[snmpSetSerialNo,0], SetSerial}]), - ?line ["val2"] = get_req(5, [[sysLocation,0]]). - - -%%----------------------------------------------------------------- -%% o Bad community uses/name is tested already -%% in SNMPv2-MIB and STANDARD-MIB. -%% o Test add/deletion of rows. -%%----------------------------------------------------------------- -snmp_community_mib(suite) -> []; -snmp_community_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - try_test(snmp_community_mib), - ?line unload_master("SNMP-COMMUNITY-MIB"). - -snmp_community_mib_2(X) -> snmp_community_mib(X). - -%% Req. SNMP-COMMUNITY-MIB -snmp_community_mib() -> - ?INF("NOT YET IMPLEMENTED", []), - nyi. - -%%----------------------------------------------------------------- -%% o Test engine boots / time -%%----------------------------------------------------------------- -snmp_framework_mib(suite) -> []; -snmp_framework_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - try_test(snmp_framework_mib), - ?line unload_master("SNMP-FRAMEWORK-MIB"). - -snmp_framework_mib_2(X) -> snmp_framework_mib(X). - -snmp_framework_mib_3(suite) -> []; -snmp_framework_mib_3(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - try_test(snmp_framework_mib). - - -%% Req. SNMP-FRAMEWORK-MIB -snmp_framework_mib() -> - ?line ["agentEngine"] = get_req(1, [[snmpEngineID,0]]), - ?line [EngineTime] = get_req(2, [[snmpEngineTime,0]]), - sleep(5000), - ?line [EngineTime2] = get_req(3, [[snmpEngineTime,0]]), - if - EngineTime+7 < EngineTime2 -> - ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); - EngineTime+4 > EngineTime2 -> - ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); - true -> ok - end, - ?line case get_req(4, [[snmpEngineBoots,0]]) of - [Boots] when integer(Boots) -> ok; - Else -> ?FAIL(Else) - end, - ok. - -%%----------------------------------------------------------------- -%% o Test the counters -%%----------------------------------------------------------------- -snmp_mpd_mib_3(suite) -> []; -snmp_mpd_mib_3(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - UnknownPDUHs = try_test(snmp_mpd_mib_a), - try_test(snmp_mpd_mib_b, [], [{context_engine_id, "bad engine"}]), - try_test(snmp_mpd_mib_c, [UnknownPDUHs]). - - -%% Req. SNMP-MPD-MIB -snmp_mpd_mib_a() -> - ?line [UnknownSecs, InvalidMsgs] = - get_req(1, [[snmpUnknownSecurityModels,0], - [snmpInvalidMsgs,0]]), - Pdu = #pdu{type = 'get-request', - request_id = 23, - error_status = noError, - error_index = 0, - varbinds = []}, - SPdu = #scopedPdu{contextEngineID = "agentEngine", - contextName = "", - data = Pdu}, - ?line SPDUBytes = snmp_pdus:enc_scoped_pdu(SPdu), - V3Hdr1 = #v3_hdr{msgID = 21, - msgMaxSize = 484, - msgFlags = [7], - msgSecurityModel = 23, % bad sec model - msgSecurityParameters = []}, - V3Hdr2 = #v3_hdr{msgID = 21, - msgMaxSize = 484, - msgFlags = [6], % bad flag combination - msgSecurityModel = 3, - msgSecurityParameters = []}, - Message1 = #message{version = 'version-3', vsn_hdr = V3Hdr1, - data = SPDUBytes}, - Message2 = #message{version = 'version-3', vsn_hdr = V3Hdr2, - data = SPDUBytes}, - ?line MsgBytes1 = snmp_pdus:enc_message_only(Message1), - ?line MsgBytes2 = snmp_pdus:enc_message_only(Message2), - snmp_test_mgr:send_bytes(MsgBytes1), - snmp_test_mgr:send_bytes(MsgBytes2), - - ?line [UnknownSecs2, InvalidMsgs2, UnknownPDUHs] = - get_req(1, [[snmpUnknownSecurityModels,0], - [snmpInvalidMsgs,0], - [snmpUnknownPDUHandlers, 0]]), - ?line UnknownSecs2 = UnknownSecs + 1, - ?line InvalidMsgs2 = InvalidMsgs + 1, - UnknownPDUHs. - --define(snmpUnknownPDUHandlers_instance, [1,3,6,1,6,3,11,2,1,3,0]). -snmp_mpd_mib_b() -> - g([[sysUpTime,0]]), - ?line expect(1, report, [{?snmpUnknownPDUHandlers_instance, any}]). - - -snmp_mpd_mib_c(UnknownPDUHs) -> - ?line [UnknownPDUHs2] = get_req(1, [[snmpUnknownPDUHandlers, 0]]), - ?line UnknownPDUHs2 = UnknownPDUHs + 1. - - -snmp_target_mib(suite) -> []; -snmp_target_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-TARGET-MIB"), - try_test(snmp_target_mib), - ?line unload_master("SNMP-TARGET-MIB"). - -snmp_target_mib_2(X) -> snmp_target_mib(X). - -snmp_target_mib_3(X) -> snmp_target_mib(X). - -snmp_target_mib() -> - ?INF("NOT YET IMPLEMENTED", []), - nyi. - -snmp_notification_mib(suite) -> []; -snmp_notification_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - try_test(snmp_notification_mib), - ?line unload_master("SNMP-NOTIFICATION-MIB"). - -snmp_notification_mib_2(X) -> snmp_notification_mib(X). - -snmp_notification_mib_3(X) -> snmp_notification_mib(X). - -snmp_notification_mib() -> - ?INF("NOT YET IMPLEMENTED", []), - nyi. - -%%----------------------------------------------------------------- -%% o add/delete views and try them -%% o try boundaries -%%----------------------------------------------------------------- -snmp_view_based_acm_mib(suite) -> []; -snmp_view_based_acm_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - ?line load_master("Test2"), - snmp_view_based_acm_mib(), - ?line unload_master("Test2"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). - -snmp_view_based_acm_mib_2(X) -> snmp_view_based_acm_mib(X). - -snmp_view_based_acm_mib_3(X) -> snmp_view_based_acm_mib(X). - -snmp_view_based_acm_mib() -> - snmpa:verbosity(net_if,trace), - snmpa:verbosity(master_agent,trace), - ?LOG("start snmp_view_based_acm_mib test",[]), - %% The user "no-rights" is present in USM, and is mapped to security - %% name 'no-rights", which is not present in VACM. - %% So, we'll add rights for it, try them and delete them. - %% We'll give "no-rights" write access to tDescr.0 and read access - %% to tDescr2.0 - %% These are the options we'll use to the mgr - Opts = [{user, "no-rights"}, {community, "no-rights"}], - %% Find the valid secmodel, and one invalid secmodel. - {SecMod, InvSecMod} = - case get(vsn) of - v1 -> {?SEC_V1, ?SEC_V2C}; - v2 -> {?SEC_V2C, ?SEC_USM}; - v3 -> {?SEC_USM, ?SEC_V1} - end, - ?DBG("assign rights for 'no-rights'",[]), - ?line try_test(use_no_rights, [], Opts), - - %% Now, add a mapping from "no-rights" -> "no-rights-group" - GRow1Status = [vacmSecurityToGroupStatus,[SecMod, 9,"no-rights"]], - GRow1 = - [{[vacmGroupName, [SecMod, 9,"no-rights"]], "no-rights-group"}, - {GRow1Status, ?createAndGo}], - ?DBG("set '~p'",[GRow1]), - ?line try_test(do_set, [GRow1]), - - ?DBG("assign rights for 'no-rights'",[]), - ?line try_test(use_no_rights, [], Opts), - - %% Create a mapping for another sec model, and make sure it dosn't - %% give us access - GRow2Status = [vacmSecurityToGroupStatus,[InvSecMod, 9,"no-rights"]], - GRow2 = [{[vacmGroupName, [InvSecMod, 9, "no-rights"]], "initial"}, - {GRow2Status, ?createAndGo}], - - ?DBG("set '~p'",[GRow2]), - ?line try_test(do_set, [GRow2]), - - ?DBG("assign rights for 'no-rights'",[]), - ?line try_test(use_no_rights, [], Opts), - - %% Delete that row - ?line try_test(del_row, [GRow2Status]), - - RVName = "rv_name", - WVName = "wv_name", - - %% Access row - ARow1Idx = [15 | "no-rights-group"] ++ [0, ?SEC_ANY, 1], - ARow1Status = [vacmAccessStatus, ARow1Idx], - ARow1 = [{[vacmAccessContextMatch, ARow1Idx], 1}, - {[vacmAccessReadViewName, ARow1Idx], RVName}, - {[vacmAccessWriteViewName, ARow1Idx], WVName}, - {ARow1Status, ?createAndGo}], - - %% This access row would give acces, if InvSecMod was valid. - ARow2Idx = [15 | "no-rights-group"] ++ [0, InvSecMod, 1], - ARow2Status = [vacmAccessStatus, ARow2Idx], - ARow2 = [{[vacmAccessContextMatch, ARow2Idx], 1}, - {[vacmAccessReadViewName, ARow2Idx], "internet"}, - {[vacmAccessWriteViewName, ARow2Idx], "internet"}, - {ARow2Status, ?createAndGo}], - - ?line try_test(do_set, [ARow2]), - - ?line try_test(use_no_rights, [], Opts), - - %% Delete that row - ?line try_test(del_row, [ARow2Status]), - - - %% Add valid row - ?line try_test(do_set, [ARow1]), - - ?line try_test(use_no_rights, [], Opts), - - %% Create the view family - VRow1Idx = mk_ln(RVName) ++ mk_ln(?xDescr), % object access - VRow2Idx = mk_ln(RVName) ++ mk_ln(?xDescr2 ++ [0]), % instance access - VRow3Idx = mk_ln(WVName) ++ mk_ln(?xDescr), % object access - VRow4Idx = mk_ln(WVName) ++ mk_ln(?xDescr ++ [0]), % instance access - VRow1Status = [vacmViewTreeFamilyStatus, VRow1Idx], - VRow2Status = [vacmViewTreeFamilyStatus, VRow2Idx], - VRow3Status = [vacmViewTreeFamilyStatus, VRow3Idx], - VRow4Status = [vacmViewTreeFamilyStatus, VRow4Idx], - - ?line try_test(add_row, [VRow1Status]), - ?line try_test(add_row, [VRow2Status]), - ?line try_test(add_row, [VRow3Status]), - - %% We're supposed to have access now... - ?line try_test(use_rights, [], Opts), - - %% Change Row3 to Row4 - ?line try_test(del_row, [VRow3Status]), - ?line try_test(add_row, [VRow4Status]), - - %% We should still have access... - ?line try_test(use_rights, [], Opts), - - %% Delete rows - ?line try_test(del_row, [GRow1Status]), - - ?line try_test(use_no_rights, [], Opts), - - %% Delete rest of rows - ?line try_test(del_row, [ARow1Status]), - ?line try_test(del_row, [VRow1Status]), - ?line try_test(del_row, [VRow2Status]), - ?line try_test(del_row, [VRow4Status]), - - ?line try_test(use_no_rights, [], Opts), - snmpa:verbosity(master_agent,log). - -do_set(Row) -> - s(Row), - expect(1, Row). - -add_row(RowStatus) -> - s([{RowStatus, ?createAndGo}]), - expect(1, [{RowStatus, ?createAndGo}]). - -del_row(RowStatus) -> - s([{RowStatus, ?destroy}]), - expect(1, [{RowStatus, ?destroy}]). - - - -use_no_rights() -> - g([[xDescr,0]]), - ?v1_2_3(expect(11, noSuchName, 1, any), - expect(12, [{[xDescr,0], noSuchObject}]), - expect(13, authorizationError, 1, any)), - g([[xDescr2,0]]), - ?v1_2_3(expect(21, noSuchName, 1, any), - expect(22, [{[xDescr2,0], noSuchObject}]), - expect(23, authorizationError, 1, any)), - gn([[xDescr]]), - ?v1_2_3(expect(31, noSuchName, 1, any), - expect(32, [{[xDescr], endOfMibView}]), - expect(33, authorizationError, 1, any)), - s([{[xDescr,0], "tryit"}]), - ?v1_2_3(expect(41, noSuchName, 1, any), - expect(42, noAccess, 1, any), - expect(43, authorizationError, 1, any)). - - -use_rights() -> - g([[xDescr,0]]), - expect(1, [{[xDescr,0], any}]), - g([[xDescr2,0]]), - expect(2, [{[xDescr2,0], any}]), - s([{[xDescr,0], "tryit"}]), - expect(3, noError, 0, any), - g([[xDescr,0]]), - expect(4, [{[xDescr,0], "tryit"}]). - -mk_ln(X) -> - [length(X) | X]. - -%%----------------------------------------------------------------- -%% o add/delete users and try them -%% o test all secLevels -%% o test all combinations of protocols -%% o try bad ops; check counters -%%----------------------------------------------------------------- -snmp_user_based_sm_mib_3(suite) -> []; -snmp_user_based_sm_mib_3(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - _AgentDir = ?config(agent_dir, Config), - ?line load_master_std("SNMP-USER-BASED-SM-MIB"), - - %% The newUser used here already has VACM access. - - %% Add a new user in the simplest way; just createAndGo - try_test(v3_sync, [[{usm_add_user1, []}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - %% Try to use the new user - ?line load_master("Test2"), - try_test(v3_sync, [[{usm_use_user, []}]], - [{sec_level, authPriv}, {user, "newUser"}]), - ?line unload_master("Test2"), - - ShaKey1 = snmp:passwd2localized_key(sha, "new sha password", "agentEngine"), - DesKey1 = lists:sublist(ShaKey1, 16), - - %% Change the new user's keys - 1 - try_test(v3_sync, [[{usm_key_change1, [ShaKey1, DesKey1]}]], - [{sec_level, authPriv}, {user, "newUser"}]), - - %% Try to use the new keys - MgrDir = ?config(mgr_dir, Config), - ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), - ?line load_master("Test2"), - try_test(v3_sync, [[{usm_use_user, []}]], - [{sec_level, authPriv}, {user, "newUser"}]), - ?line unload_master("Test2"), - - ShaKey2 = snmp:passwd2localized_key(sha, "newer password", "agentEngine"), - DesKey2 = lists:sublist(ShaKey2, 16), - - %% Change the new user's keys - 2 - ?line try_test(v3_sync, - [[{usm_key_change2, [ShaKey1, DesKey1, ShaKey2, DesKey2]}]], - [{sec_level, authPriv}, {user, "newUser"}]), - - %% Try to use the new keys - reset_usm_mgr(MgrDir), - ?line rewrite_usm_mgr(MgrDir, ShaKey2, DesKey2), - ?line load_master("Test2"), - ?line try_test(v3_sync, [[{usm_use_user, []}]], - [{sec_level, authPriv}, {user, "newUser"}]), - ?line unload_master("Test2"), - reset_usm_mgr(MgrDir), - - %% Change the new user's keys - 3 - ?line try_test(v3_sync, - [[{usm_key_change3, [ShaKey2, DesKey2, ShaKey1, DesKey1]}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - %% Try to use the new keys - ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), - ?line load_master("Test2"), - try_test(v3_sync, [[{usm_use_user, []}]], - [{sec_level, authPriv}, {user, "newUser"}]), - ?line unload_master("Test2"), - reset_usm_mgr(MgrDir), - - %% Try some read requests - ?line try_test(v3_sync, [[{usm_read, []}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - %% Delete the new user - ?line try_test(v3_sync, [[{usm_del_user, []}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - %% Try some bad requests - ?line try_test(v3_sync, [[{usm_bad, []}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - ?line unload_master("SNMP-USER-BASED-SM-MIB"). - --define(usmUserSecurityName, [1,3,6,1,6,3,15,1,2,2,1,3]). - -usm_add_user1() -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - RowPointer = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], - Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer}, - {[usmUserStatus, NewRowIndex], ?createAndGo}], - ?line s(Vbs1), - ?line expect(1, Vbs1), - ok. - -usm_use_user() -> - v2_proc(). - - -%% Change own public keys -usm_key_change1(ShaKey, DesKey) -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - "passwd_shaxxxxxxxxxx", - ShaKey), - DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - "passwd_desxxxxxx", - DesKey), - Vbs1 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, - {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], - s(Vbs1), - ?line expect(1, Vbs1). - -%% Change own private keys -usm_key_change2(OldShaKey, OldDesKey, ShaKey, DesKey) -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - OldShaKey, - ShaKey), - DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - OldDesKey, - DesKey), - Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}, - {[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], - s(Vbs1), - ?line expect(1, Vbs1). - -%% Change other's public keys -usm_key_change3(OldShaKey, OldDesKey, ShaKey, DesKey) -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - OldShaKey, - ShaKey), - DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - OldDesKey, - DesKey), - Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}], - s(Vbs1), - ?line expect(1, noAccess, 1, any), - Vbs2 = [{[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], - s(Vbs2), - ?line expect(2, noAccess, 1, any), - - - Vbs3 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, - {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], - s(Vbs3), - ?line expect(1, Vbs3). - -usm_read() -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - ?line g([[usmUserSecurityName, NewRowIndex], - [usmUserCloneFrom, NewRowIndex], - [usmUserAuthKeyChange, NewRowIndex], - [usmUserOwnAuthKeyChange, NewRowIndex], - [usmUserPrivKeyChange, NewRowIndex], - [usmUserOwnPrivKeyChange, NewRowIndex]]), - ?line expect(1, - [{[usmUserSecurityName, NewRowIndex], "newUser"}, - {[usmUserCloneFrom, NewRowIndex], [0,0]}, - {[usmUserAuthKeyChange, NewRowIndex], ""}, - {[usmUserOwnAuthKeyChange, NewRowIndex], ""}, - {[usmUserPrivKeyChange, NewRowIndex], ""}, - {[usmUserOwnPrivKeyChange, NewRowIndex], ""}]), - ok. - - - -usm_del_user() -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - Vbs1 = [{[usmUserStatus, NewRowIndex], ?destroy}], - ?line s(Vbs1), - ?line expect(1, Vbs1), - ok. - --define(usmUserCloneFrom, [1,3,6,1,6,3,15,1,2,2,1,4]). - --define(usmNoAuthProtocol, [1,3,6,1,6,3,10,1,1,1]). - --define(usmHMACMD5AuthProtocol, [1,3,6,1,6,3,10,1,1,2]). - --define(usmHMACSHAAuthProtocol, [1,3,6,1,6,3,10,1,1,3]). - --define(usmNoPrivProtocol, [1,3,6,1,6,3,10,1,2,1]). - --define(usmDESPrivProtocol, [1,3,6,1,6,3,10,1,2,2]). - -usm_bad() -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - RowPointer1 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDOS"], - Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer1}, - {[usmUserStatus, NewRowIndex], ?createAndGo}], - ?line s(Vbs1), - ?line expect(1, inconsistentName, 1, any), - - RowPointer2 = ?usmUserCloneFrom ++ [11|"agentEngine"] ++ [7|"privDES"], - Vbs2 = [{[usmUserCloneFrom, NewRowIndex], RowPointer2}, - {[usmUserStatus, NewRowIndex], ?createAndGo}], - ?line s(Vbs2), - ?line expect(2, wrongValue, 1, any), - - RowPointer3 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], - Vbs3 = [{[usmUserCloneFrom, NewRowIndex], RowPointer3}, - {[usmUserStatus, NewRowIndex], ?createAndGo}], - ?line s(Vbs3), - ?line expect(3, Vbs3), - ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmNoAuthProtocol}]), - ?line expect(4, inconsistentValue, 1, any), - ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmHMACMD5AuthProtocol}]), - ?line expect(5, inconsistentValue, 1, any), - ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmDESPrivProtocol}]), - ?line expect(6, wrongValue, 1, any), - ?line s([{[usmUserPrivProtocol, NewRowIndex], ?usmHMACSHAAuthProtocol}]), - ?line expect(7, wrongValue, 1, any), - - Vbs4 = [{[usmUserStatus, NewRowIndex], ?destroy}], - ?line s(Vbs4), - ?line expect(1, Vbs4), - - ok. - - -%%----------------------------------------------------------------- -%% Loop through entire MIB, to make sure that all instrum. funcs -%% works. -%% Load all std mibs that are not loaded by default. -%%----------------------------------------------------------------- -loop_mib(suite) -> []; -loop_mib(Config) when list(Config) -> - ?LOG("loop_mib -> initiate case",[]), - %% snmpa:verbosity(master_agent,debug), - %% snmpa:verbosity(mib_server,info), - {SaNode, MgrNode, MibDir} = init_case(Config), - ?DBG("loop_mib -> ~n" - "\tSaNode: ~p~n" - "\tMgrNode: ~p~n" - "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), - ?DBG("loop_mib -> load mib SNMP-COMMUNITY-MIB",[]), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?DBG("loop_mib -> load mib SNMP-MPD-MIB",[]), - ?line load_master_std("SNMP-MPD-MIB"), - ?DBG("loop_mib -> load mib SNMP-TARGET-MIB",[]), - ?line load_master_std("SNMP-TARGET-MIB"), - ?DBG("loop_mib -> load mib SNMP-NOTIFICATION-MIB",[]), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?DBG("loop_mib -> load mib SNMP-FRAMEWORK-MIB",[]), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?DBG("loop_mib -> load mib SNMP-VIEW-BASED-ACM-MIB",[]), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - ?DBG("loop_mib -> try",[]), - try_test(loop_mib_1), - ?DBG("loop_mib -> unload mib SNMP-COMMUNITY-MIB",[]), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?DBG("loop_mib -> unload mib SNMP-MPD-MIB",[]), - ?line unload_master("SNMP-MPD-MIB"), - ?DBG("loop_mib -> unload mib SNMP-TARGET-MIB",[]), - ?line unload_master("SNMP-TARGET-MIB"), - ?DBG("loop_mib -> unload mib SNMP-NOTIFICATION-MIB",[]), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?DBG("loop_mib -> unload mib SNMP-FRAMEWORK-MIB",[]), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?DBG("loop_mib -> unload mib SNMP-VIEW-BASED-ACM-MIB",[]), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - %% snmpa:verbosity(master_agent,log), - %% snmpa:verbosity(mib_server,silence), - ?LOG("loop_mib -> done",[]). - - -loop_mib_2(suite) -> []; -loop_mib_2(Config) when list(Config) -> - ?LOG("loop_mib_2 -> initiate case",[]), - {SaNode, MgrNode, MibDir} = init_case(Config), - ?DBG("loop_mib_2 -> ~n" - "\tSaNode: ~p~n" - "\tMgrNode: ~p~n" - "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), - ?DBG("loop_mib_2 -> load mibs",[]), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-MPD-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - try_test(loop_mib_2), - ?DBG("loop_mib_2 -> unload mibs",[]), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?line unload_master("SNMP-MPD-MIB"), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - ?LOG("loop_mib_2 -> done",[]). - - -loop_mib_3(suite) -> []; -loop_mib_3(Config) when list(Config) -> - ?LOG("loop_mib_3 -> initiate case",[]), - {SaNode, MgrNode, MibDir} = init_case(Config), - ?DBG("loop_mib_3 -> ~n" - "\tSaNode: ~p~n" - "\tMgrNode: ~p~n" - "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), - ?DBG("loop_mib_3 -> load mibs",[]), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - ?line load_master_std("SNMP-USER-BASED-SM-MIB"), - try_test(loop_mib_2), - ?DBG("loop_mib_3 -> unload mibs",[]), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - ?line unload_master("SNMP-USER-BASED-SM-MIB"), - ?LOG("loop_mib_3 -> done",[]). - - -%% Req. As many mibs all possible -loop_mib_1() -> - ?DBG("loop_mib_1 -> entry",[]), - N = loop_it_1([1,1], 0), - io:format(user, "found ~w varibles\n", [N]), - ?line N = if N < 100 -> 100; - true -> N - end. - - -loop_it_1(Oid, N) -> - ?DBG("loop_it_1 -> entry with~n" - "\tOid: ~p~n" - "\tN: ~p",[Oid,N]), - case get_next_req([Oid]) of - #pdu{type='get-response', error_status=noError, error_index=0, - varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> - ?DBG("loop_it_1 -> ~n" - "\tNOid: ~p~n" - "\tValue: ~p",[NOid,Value]), - ?line [Value2] = get_req(1, [NOid]), % must not be same - ?DBG("loop_it_1 -> ~n" - "\tValue2: ~p",[Value2]), - loop_it_1(NOid, N+1); - #pdu{type='get-response', error_status=noSuchName, error_index=1, - varbinds=[_]} -> - ?DBG("loop_it_1 -> done",[]), - N; - - #pdu{type = Type, error_status = Err, error_index = Idx, - varbinds = Vbs} -> - exit({unexpected_pdu, ?LINE, Type, Err, Idx, Vbs}) - end. - -%% Req. As many mibs all possible -loop_mib_2() -> - ?DBG("loop_mib_1 -> entry",[]), - N = loop_it_2([1,1], 0), - io:format(user, "found ~w varibles\n", [N]), - ?line N = if N < 100 -> 100; - true -> N - end. - - -loop_it_2(Oid, N) -> - ?DBG("loop_it_2 -> entry with~n" - "\tOid: ~p~n" - "\tN: ~p",[Oid,N]), - case get_next_req([Oid]) of - #pdu{type='get-response', error_status=noError, error_index=0, - varbinds=[#varbind{oid = NOid, value = endOfMibView}]} -> - ?DBG("loop_it_2 -> ~n" - "\tNOid: ~p",[NOid]), - N; - #pdu{type='get-response', error_status=noError, error_index=0, - varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> - ?DBG("loop_it_2 -> ~n" - "\tNOid: ~p~n" - "\tValue: ~p",[NOid,Value]), - ?line [Value2] = get_req(1, [NOid]), % must not be same - ?DBG("loop_it_2 -> ~n" - "\tValue2: ~p",[Value2]), - loop_it_2(NOid, N+1) - end. - - -%%%----------------------------------------------------------------- -%%% Testing of reported bugs and other tickets. -%%%----------------------------------------------------------------- - - - - - -%% These are (ticket) test cases where the initiation has to be done -%% individually. - -%%----------------------------------------------------------------- -%% Ticket: OTP-1128 -%% Slogan: Bug in handling of createAndWait set-requests. -%%----------------------------------------------------------------- -otp_1128(suite) -> []; -otp_1128(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(otp_1128), - ?line unload_master("OLD-SNMPEA-MIB"). - -otp_1128_2(X) -> otp_1128(X). - -otp_1128_3(X) -> otp_1128(X). - -otp_1128() -> - io:format("Testing bug reported in ticket OTP-1128...~n"), - - NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], - NewKeyc4 = [intCommunityAccess,get(mip),is("test")], - NewKeyc5 = [intCommunityStatus,get(mip),is("test")], - - s([{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), - ?line expect(28, [{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), - g([NewKeyc5]), - ?line expect(29, [{NewKeyc5, ?notReady}]), - s([{NewKeyc5, ?active}, {NewKeyc3, 2}]), - ?line expect(30, [{NewKeyc5, ?active}, {NewKeyc3, 2}]), - g([NewKeyc5]), - ?line expect(31, [{NewKeyc5, ?active}]), - s([{NewKeyc5, ?destroy}]), - ?line expect(32, [{NewKeyc5, ?destroy}]). - -%%----------------------------------------------------------------- -%% Ticket: OTP-1129, OTP-1169 -%% Slogan: snmpa:int_to_enum crashes on bad oids -%%----------------------------------------------------------------- -otp_1129(suite) -> []; -otp_1129(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas3"), - try_test(otp_1129_i, [node()]), - ?line unload_master("Klas3"). - -otp_1129_2(X) -> otp_1129(X). - -otp_1129_3(X) -> otp_1129(X). - -otp_1129_i(MaNode) -> - io:format("Testing bug reported in ticket OTP-1129...~n"), - false = rpc:call(MaNode, snmp, int_to_enum, [iso, 1]), - false = rpc:call(MaNode, snmp, int_to_enum, [isox, 1]). - -%%----------------------------------------------------------------- -%% Ticket: OTP-1131 -%% Slogan: Agent crashes / erlang node halts if RowIndex in a -%% setrequest is of bad type, e.g. an INDEX {INTEGER}, -%% and RowIdenx [3,2]. -%%----------------------------------------------------------------- -otp_1131(suite) -> []; -otp_1131(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas1"), - try_test(otp_1131), - ?line unload_master("Klas1"). - -otp_1131_2(X) -> otp_1131(X). - -otp_1131_3(X) -> otp_1131(X). - -otp_1131() -> - io:format("Testing bug reported in ticket OTP-1131...~n"), - s([{[friendsEntry, [2, 3, 1]], s, "kompis3"}, - {[friendsEntry, [3, 3, 1]], i, ?createAndGo}]), - ?line expect(1, ?v1_2(noSuchName, noCreation), 2, any). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1162 -%% Slogan: snmp_agent can't handle wrongValue from instrum.func -%%----------------------------------------------------------------- -otp_1162(suite) -> []; -otp_1162(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - try_test(otp_1162), - stop_subagent(SA). - -otp_1162_2(X) -> otp_1162(X). - -otp_1162_3(X) -> otp_1162(X). - -otp_1162() -> - s([{[sa, [2,0]], 6}]), % wrongValue (i is_set_ok) - ?line expect(1, ?v1_2(badValue, wrongValue), 1, any). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1222 -%% Slogan: snmp agent crash if faulty index is returned from instrum -%%----------------------------------------------------------------- -otp_1222(suite) -> []; -otp_1222(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas3"), - ?line load_master("Klas4"), - try_test(otp_1222), - ?line unload_master("Klas3"), - ?line unload_master("Klas4"). - -otp_1222_2(X) -> otp_1222(X). - -otp_1222_3(X) -> otp_1222(X). - -otp_1222() -> - io:format("Testing bug reported in ticket OTP-1222...~n"), - s([{[fStatus4,1], 4}, {[fName4,1], 1}]), - ?line expect(1, genErr, 0, any), - s([{[fStatus4,2], 4}, {[fName4,2], 1}]), - ?line expect(2, genErr, 0, any). - -%%----------------------------------------------------------------- -%% Ticket: OTP-1298 -%% Slogan: Negative INTEGER values are treated as positive. -%%----------------------------------------------------------------- -otp_1298(suite) -> []; -otp_1298(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas2"), - try_test(otp_1298), - ?line unload_master("Klas2"). - -otp_1298_2(X) -> otp_1298(X). - -otp_1298_3(X) -> otp_1298(X). - -otp_1298() -> - io:format("Testing bug reported in ticket OTP-1298...~n"), - s([{[fint,0], -1}]), - ?line expect(1298, [{[fint,0], -1}]). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1331 -%% Slogan: snmp_generic should return noError when deleting non-ex row -%%----------------------------------------------------------------- -otp_1331(suite) -> []; -otp_1331(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(otp_1331), - ?line unload_master("OLD-SNMPEA-MIB"). - -otp_1331_2(X) -> otp_1331(X). - -otp_1331_3(X) -> otp_1331(X). - -otp_1331() -> - NewKeyc5 = [intCommunityStatus,[127,32,0,0],is("test")], - s([{NewKeyc5, ?destroy}]), - ?line expect(1, [{NewKeyc5, ?destroy}]). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1338 -%% Slogan: snmp bug in initialisation of default values for mnesia tabs -%%----------------------------------------------------------------- -otp_1338(suite) -> []; -otp_1338(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas2"), - try_test(otp_1338), - ?line unload_master("Klas2"). - -otp_1338_2(X) -> otp_1338(X). - -otp_1338_3(X) -> otp_1338(X). - -otp_1338() -> - s([{[kStatus2, 7], i, ?createAndGo}]), - ?line expect(1, [{[kStatus2, 7], ?createAndGo}]), - g([[kName2, 7]]), - ?line expect(2, [{[kName2, 7], "JJJ"}]). - -%%----------------------------------------------------------------- -%% Ticket: OTP-1342 -%% Slogan: default impl of snmp table can't handle bad index access, -%% Set when INDEX is read-write gets into an infinite loop! -%%----------------------------------------------------------------- -otp_1342(suite) -> []; -otp_1342(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas4"), - try_test(otp_1342), - ?line unload_master("Klas4"). - -otp_1342_2(X) -> otp_1342(X). - -otp_1342_3(X) -> otp_1342(X). - -otp_1342() -> - s([{[fIndex5, 1], i, 1}, - {[fName5, 1], i, 3}, - {[fStatus5, 1], i, ?createAndGo}]), - ?line expect(1, ?v1_2(noSuchName, noCreation), 3, any). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1366 -%% Slogan: snmp traps not sent to all managers -%% Note: NYI! We need a way to tell the test server that we need -%% mgrs on two different machines. -%%----------------------------------------------------------------- -otp_1366(suite) -> []; -otp_1366(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(otp_1366), - ?line unload_master("OLD-SNMPEA-MIB"). - -otp_1366_2(X) -> otp_1366(X). - -otp_1366_3(X) -> otp_1366(X). - -otp_1366() -> - ?INF("NOT YET IMPLEMENTED", []), - 'NYI'. - -%%----------------------------------------------------------------- -%% Ticket: OTP-2776 -%% Slogan: snmp:validate_date_and_time() fails when time is 00:00 -%%----------------------------------------------------------------- -otp_2776(suite) -> []; -otp_2776(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - try_test(otp_2776). - -otp_2776_2(X) -> otp_2776(X). - -otp_2776_3(X) -> otp_2776(X). - -otp_2776() -> - io:format("Testing bug reported in ticket OTP-2776...~n"), - - Dt01_valid = [19,98,9,1,1,0,23,0,43,0,0], - Dt02_valid = [19,98,9,1,0,0,0,0,43,0,0], % This is what is fixed: 00:00 - Dt03_valid = [19,98,2,28,1,0,23,0,43,0,0], - Dt04_invalid = [19,98,2,29,1,0,23,0,43,0,0], - Dt05_valid = [19,96,2,29,1,0,23,0,43,0,0], - Dt06_valid = [20,0,2,29,1,0,23,0,43,0,0], - Dt07_invalid = [19,96,2,30,1,0,23,0,43,0,0], % This is also fixed: 30/2 - Dt08_valid = [19,98,4,30,1,0,23,0,43,0,0], - Dt09_invalid = [19,98,4,31,1,0,23,0,43,0,0], % This is also fixed: 31/4 - Dt10_invalid = [], - Dt11_invalid = [kalle,hobbe], - L = [{ 1, true, Dt01_valid}, - { 2, true, Dt02_valid}, - { 3, true, Dt03_valid}, - { 4, false, Dt04_invalid}, - { 5, true, Dt05_valid}, - { 6, true, Dt06_valid}, - { 7, false, Dt07_invalid}, - { 8, true, Dt08_valid}, - { 9, false, Dt09_invalid}, - {10, false, Dt10_invalid}, - {11, false, Dt11_invalid}], - - ?line ok = validate_dat(L). - - -validate_dat(L) -> validate_dat(L,[]). - -validate_dat([],V) -> - Fun = fun({_,X}) -> case X of - ok -> false; - _ -> true - end - end, - validate_dat1( lists:reverse( lists:filter(Fun,V) ) ); -validate_dat([{Id,E,Dat}|T],V) -> - validate_dat(T,[validate_dat2(Id,E,Dat) | V]). - -validate_dat1([]) -> ok; -validate_dat1(L) -> {error,L}. - -validate_dat2(Id, E, Dat) -> - Res = case {E,snmp:validate_date_and_time(Dat)} of - {E,E} -> ok; - {E,A} -> {E,A} - end, - {Id, Res}. - - -%%----------------------------------------------------------------- -%% Ticket: OTP-2979 -%% Slogan: get-next on more than 1 column in an empty table -%% returns bad response. -%%----------------------------------------------------------------- -otp_2979(suite) -> []; -otp_2979(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Test1"), - ?line init_old(), - try_test(otp_2979), - ?line unload_master("Test1"). - -otp_2979_2(X) -> otp_2979(X). - -otp_2979_3(X) -> otp_2979(X). - -otp_2979() -> - gn([[sparseDescr], [sparseStatus]]), - ?line expect(1, [{[sparseStr,0], "slut"}, - {[sparseStr,0], "slut"}]). - -%%----------------------------------------------------------------- -%% Ticket: OTP-3187 -%% Slogan: get-next on vacmAccessTable for colums > 5 returns -%% endOfTable - should return value. -%%----------------------------------------------------------------- -otp_3187(suite) -> []; -otp_3187(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - otp_3187(), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). - -otp_3187_2(X) -> otp_3187(X). - -otp_3187_3(X) -> otp_3187(X). - -otp_3187() -> - ?line Elements = - snmp_view_based_acm_mib:vacmAccessTable(get_next,[],[4,5,6]), - lists:foreach(fun(E) -> - ?line if E == endOfTable -> - ?FAIL(endOfTable); - true -> ok - end - end, Elements). - -%%----------------------------------------------------------------- -%% Ticket: OTP-3542 -%% Slogan: -%%----------------------------------------------------------------- -otp_3542(suite) -> []; -otp_3542(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - try_test(otp_3542). - -otp_3542() -> - io:format("SNMP v3 discovery...~n"), - ?line Res = snmp_test_mgr:d(), - io:format("SNMP v3 discovery result: ~p~n",[Res]). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-3725 -%% Slogan: Slow response time on snmpa:int_to_enum -%%----------------------------------------------------------------- -otp_3725(suite) -> []; -otp_3725(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(otp_3725_test, [node()]), - ?line unload_master("OLD-SNMPEA-MIB"). - -%% Req. OLD-SNMPEA-MIB -otp_3725_test(MaNode) -> - io:format("Testing feature requested in ticket OTP-3725...~n"), - ?line rpc:call(MaNode,snmpa,verbosity,[symbolic_store,trace]), - ?line Db = rpc:call(MaNode,snmp,get_symbolic_store_db,[]), - ?DBG("otp_3725_test -> Db = ~p",[Db]), - - ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, - [Db, intAgentIpAddress]), - ?DBG("otp_3725_test -> name_to_oid for ~p: ~p",[intAgentIpAddress,OID]), - ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, oid_to_name, - [Db,OID]), - ?DBG("otp_3725_test -> oid_to_name for ~p: ~p",[OID,intAgentIpAddress]), - ?line false = rpc:call(MaNode, snmp, name_to_oid, [Db, intAgentIpAddres]), - ?line false = rpc:call(MaNode, snmp, oid_to_name, - [Db, [1,5,32,3,54,3,3,34,4]]), - ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, - [Db, intViewType, excluded]), - ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, - [Db, intViewType, 2]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, intViewType, exclude]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, intAgentIpAddress, exclude]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, intAgentIpAddre, exclude]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, intViewType, 3]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, - [Db, intAgentIpAddress, 2]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, - [Db, intAgentIpAddre, 2]), - ?line {value, active} = rpc:call(MaNode, snmp, int_to_enum, - [Db, 'RowStatus', ?active]), - ?line {value, ?destroy} = rpc:call(MaNode, snmp, enum_to_int, - [Db, 'RowStatus', destroy]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, 'RowStatus', xxxdestroy]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, 'xxRowStatus', destroy]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'RowStatus', 25]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'xxRowStatus', 1]), - ok. - - -%%----------------------------------------------------------------- -%% Ticket: OTP-4394 -%% Slogan: Target mib tag list check invalid -%%----------------------------------------------------------------- - - - -init_otp_4394(Config) when list(Config) -> - ?DBG("init_otp_4394 -> entry with" - "~n Config: ~p", [Config]), - ?line AgentDir = ?config(agent_dir, Config), - ?line MgrDir = ?config(mgr_dir, Config), - ?line Ip = ?config(ip, Config), - ?line otp_4394_config(AgentDir, MgrDir, Ip), - MasterAgentVerbosity = {master_agent_verbosity, trace}, - NetIfVerbosity = {net_if_verbosity, trace}, - Opts = [MasterAgentVerbosity,NetIfVerbosity], - [{vsn, v1} | start_v1_agent(Config,Opts)]. - -otp_4394_config(AgentDir, MgrDir, Ip0) -> - ?DBG("otp_4394_config -> entry with" - "~n AgentDir: ~p" - "~n MgrDir: ~p" - "~n Ip0: ~p", [AgentDir, MgrDir, Ip0]), - Vsn = [v1], - Ip = tuple_to_list(Ip0), - ?line snmp_config:write_agent_snmp_files(AgentDir, Vsn, Ip, - ?TRAP_UDP, Ip, 4000, - "OTP-4394 test"), - ?line case update_usm(Vsn, AgentDir) of - true -> - ?line copy_file(filename:join(AgentDir, "usm.conf"), - filename:join(MgrDir, "usm.conf")), - ?line update_usm_mgr(Vsn, MgrDir); - false -> - ?line ok - end, - C1 = {"a", "all-rights", "initial", "", "pc"}, - C2 = {"c", "secret", "secret_name", "", "secret_tag"}, - ?line write_community_conf(AgentDir, [C1, C2]), - ?line update_vacm(Vsn, AgentDir), - Ta1 = {"shelob v1", - [134,138,177,177], 5000, 1500, 3, %% Använd Ip och modda - "pc1", - "target_v1", "", - %% [255,255,255,255,0,0], - [], - 2048}, - Ta2 = {"bifur v1", - [134,138,177,75], 5000, 1500, 3, %% Använd Ip - "pc2", - "target_v1", "", - %% [255,255,255,255,0,0], - [], 2048}, - ?line write_target_addr_conf(AgentDir, [Ta1, Ta2]), - ?line write_target_params_conf(AgentDir, Vsn), - ?line write_notify_conf(AgentDir), - ok. - - - -finish_otp_4394(Config) when list(Config) -> - ?DBG("finish_otp_4394 -> entry", []), - C1 = stop_agent(Config), - delete_files(C1), - erase(mgr_node), - lists:keydelete(vsn, 1, C1). - -otp_4394_test(suite) -> []; -otp_4394_test(Config) -> - ?DBG("otp_4394_test -> entry", []), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - try_test(otp_4394_test1), - ?DBG("otp_4394_test -> done", []), - ok. - -otp_4394_test1() -> - ?DBG("otp_4394_test1 -> entry", []), - gn([[1,1]]), - Res = - case snmp_test_mgr:expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]) of - %% {error, 1, {"?",[]}, {"~w",[timeout]}} - {error, 1, _, {_, [timeout]}} -> - ?DBG("otp_4394_test1 -> expected result: timeout", []), - ok; - Else -> - Else - end, - ?DBG("otp_4394_test1 -> done with: ~p", [Res]), - Res. - - -%%%-------------------------------------------------- -%%% Used to test the standard mib with our -%%% configuration. -%%%-------------------------------------------------- -run(F, A, Opts) -> - M = get(mib_dir), - Dir = get(mgr_dir), - User = snmp_misc:get_option(user, Opts, "all-rights"), - SecLevel = snmp_misc:get_option(sec_level, Opts, noAuthNoPriv), - EngineID = snmp_misc:get_option(engine_id, Opts, "agentEngine"), - CtxEngineID = snmp_misc:get_option(context_engine_id, Opts, EngineID), - Community = snmp_misc:get_option(community, Opts, "all-rights"), - ?DBG("run -> start crypto app",[]), - Crypto = case os:type() of - vxworks -> - no_crypto; - _ -> - ?CRYPTO_START() - end, - ?DBG("run -> Crypto: ~p",[Crypto]), - catch snmp_test_mgr:stop(), % If we had a running mgr from a failed case - StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", - ?DBG("run -> config:~n" - "\tM: ~p~n" - "\tDir: ~p~n" - "\tUser: ~p~n" - "\tSecLevel: ~p~n" - "\tEngineID: ~p~n" - "\tCtxEngineID: ~p~n" - "\tCommunity: ~p~n" - "\tStdM: ~p", - [M,Dir,User,SecLevel,EngineID,CtxEngineID,Community,StdM]), - case snmp_test_mgr:start([%% {agent, snmp_test_lib:hostname()}, - {packet_server_debug,true}, - {debug,true}, - {agent, get(master_host)}, - {agent_udp, 4000}, - {trap_udp, 5000}, - {recbuf,65535}, - quiet, - get(vsn), - {community, Community}, - {user, User}, - {sec_level, SecLevel}, - {engine_id, EngineID}, - {context_engine_id, CtxEngineID}, - {dir, Dir}, - {mibs, mibs(StdM, M)}]) of - {ok, _Pid} -> - Res = apply(?MODULE, F, A), - catch snmp_test_mgr:stop(), - Res; - Err -> - io:format("Error starting manager: ~p\n", [Err]), - catch snmp_test_mgr:stop(), - ?line exit({mgr_start, Err}) - end. - - -mibs(StdMibDir,MibDir) -> - [join(StdMibDir, ?v1_2("STANDARD-MIB.bin", "SNMPv2-MIB.bin")), - join(MibDir, "OLD-SNMPEA-MIB.bin"), - join(StdMibDir, "SNMP-FRAMEWORK-MIB"), - join(StdMibDir, "SNMP-MPD-MIB"), - join(StdMibDir, "SNMP-VIEW-BASED-ACM-MIB"), - join(StdMibDir, "SNMP-USER-BASED-SM-MIB"), - join(StdMibDir, "SNMP-TARGET-MIB"), - join(StdMibDir, "SNMP-NOTIFICATION-MIB"), - join(MibDir, "Klas1.bin"), - join(MibDir, "Klas2.bin"), - join(MibDir, "Klas3.bin"), - join(MibDir, "Klas4.bin"), - join(MibDir, "SA-MIB.bin"), - join(MibDir, "TestTrap.bin"), - join(MibDir, "Test1.bin"), - join(MibDir, "Test2.bin"), - join(MibDir, "TestTrapv2.bin")]. - -join(D,F) -> - filename:join(D,F). - -%% string used in index -is(S) -> [length(S) | S]. - -try_test(Func) -> - call(get(mgr_node), ?MODULE, run, [Func, [], []]). - -try_test(Func, A) -> - call(get(mgr_node), ?MODULE, run, [Func, A, []]). - -try_test(Func, A, Opts) -> - call(get(mgr_node), ?MODULE, run, [Func, A, Opts]). - -call(N,M,F,A) -> - ?DBG("call -> entry with~n" - " N: ~p~n" - " M: ~p~n" - " F: ~p~n" - " A: ~p~n" - " when~n" - " get(): ~p", - [N,M,F,A,get()]), - spawn(N, ?MODULE, wait, [self(),get(),M,F,A]), - receive - {done, {'EXIT', Rn}, Loc} -> - ?DBG("call -> returned ~p",[{done, {'EXIT', Rn}, Loc}]), - put(test_server_loc, Loc), - exit(Rn); - {done, Ret, Zed} -> - ?DBG("call -> returned ~p~n",[{done, Ret, Zed}]), - Ret - end. - -wait(From, Env, M, F, A) -> - ?DBG("wait -> entry with ~n" - "\tFrom: ~p~n" - "\tEnv: ~p",[From,Env]), - lists:foreach(fun({K,V}) -> put(K,V) end, Env), - Rn = (catch apply(M, F, A)), - ?DBG("wait -> Rn: ~n~p", [Rn]), - From ! {done, Rn, get(test_server_loc)}, - exit(Rn). - -expect(A,B) -> ok = snmp_test_mgr:expect(A,B). -expect(A,B,C) -> ok = snmp_test_mgr:expect(A,B,C). -expect(A,B,C,D) -> ok = snmp_test_mgr:expect(A,B,C,D). -expect(A,B,C,D,E,F) -> ok = snmp_test_mgr:expect(A,B,C,D,E,F). - -get_req(Id, Vars) -> - ?DBG("get_req -> entry with~n" - "\tId: ~p~n" - "\tVars: ~p",[Id,Vars]), - g(Vars), - ?DBG("get_req -> await response",[]), - {ok, Val} = snmp_test_mgr:get_response(Id, Vars), - ?DBG("get_req -> response: ~p",[Val]), - Val. - -get_next_req(Vars) -> - ?DBG("get_next_req -> entry with Vars '~p', send request",[Vars]), - gn(Vars), - ?DBG("get_next_req -> await response",[]), - Response = snmp_test_mgr:receive_response(), - ?DBG("get_next_req -> response: ~p",[Response]), - Response. - - - -start_node(Name) -> - ?LOG("start_node -> entry with Name: ~p",[Name]), - M = list_to_atom(?HOSTNAME(node())), - ?DBG("start_node -> M: ~p",[M]), - Pa = filename:dirname(code:which(?MODULE)), - ?DBG("start_node -> Pa: ~p",[Pa]), - - Args = case init:get_argument('CC_TEST') of - {ok, [[]]} -> - " -pa /clearcase/otp/libraries/snmp/ebin "; - {ok, [[Path]]} -> - " -pa " ++ Path; - error -> - "" - end, - %% Do not use start_link!!! (the proc that calls this one is tmp) - ?DBG("start_node -> Args: ~p~n",[Args]), - A = Args ++ " -pa " ++ Pa, - case (catch ?START_NODE(Name, A)) of - {ok, Node} -> - %% Tell the test_server to not clean up things it never started. - ?DBG("start_node -> Node: ~p",[Node]), - {ok, Node}; - Else -> - ?ERR("start_node -> failed with(other): Else: ~p",[Else]), - ?line ?FAIL(Else) - end. - - -stop_node(Node) -> - ?LOG("stop_node -> Node: ~p",[Node]), - rpc:cast(Node, erlang, halt, []). - -p(X) -> - io:format(user, X++"\n", []). - -sleep(X) -> - receive - after - X -> ok - end. - -%%%----------------------------------------------------------------- -%%% Configuration -%%%----------------------------------------------------------------- -config(Vsns, MgrDir, AgentDir, MIp, AIp) -> - ?line snmp_config:write_agent_snmp_files(AgentDir, Vsns, MIp, - ?TRAP_UDP, AIp, 4000, - "test"), - ?line case update_usm(Vsns, AgentDir) of - true -> - ?line copy_file(filename:join(AgentDir, "usm.conf"), - filename:join(MgrDir, "usm.conf")), - ?line update_usm_mgr(Vsns, MgrDir); - false -> - ?line ok - end, - ?line update_community(Vsns, AgentDir), - ?line update_vacm(Vsns, AgentDir), - ?line write_target_addr_conf(AgentDir, MIp, ?TRAP_UDP, Vsns), - ?line write_target_params_conf(AgentDir, Vsns), - ?line write_notify_conf(AgentDir), - ok. - -delete_files(Config) -> - Dir = ?config(agent_dir, Config), - {ok, List} = file:list_dir(Dir), - lists:foreach(fun(FName) -> file:delete(filename:join(Dir, FName)) end, - List). - -update_usm(Vsns, Dir) -> - case lists:member(v3, Vsns) of - true -> - {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),[read,write]), - file:position(Fid, eof), - ok = io:format(Fid, "{\"agentEngine\", \"all-rights\", " - "\"all-rights\", zeroDotZero, " - "usmNoAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"\", \"\"}.\n", []), - ok = io:format(Fid, "{\"agentEngine\", \"no-rights\", " - "\"no-rights\", zeroDotZero, " - "usmNoAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"\", \"\"}.\n", []), - ok = io:format(Fid, "{\"agentEngine\", \"authMD5\", " - "\"authMD5\", zeroDotZero, " - "usmHMACMD5AuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"passwd_md5xxxxxx\", \"\"}.\n", []), - ok = io:format(Fid, "{\"agentEngine\", \"authSHA\", " - "\"authSHA\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"\"}.\n", []), - ok = io:format(Fid, "{\"agentEngine\", \"privDES\", " - "\"privDES\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", - []), - ok = io:format(Fid, "{\"mgrEngine\", \"all-rights\", " - "\"all-rights\", zeroDotZero, " - "usmNoAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"\", \"\"}.\n", []), - ok = io:format(Fid, "{\"mgrEngine\", \"no-rights\", " - "\"no-rights\", zeroDotZero, " - "usmNoAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"\", \"\"}.\n", []), - ok = io:format(Fid, "{\"mgrEngine\", \"authMD5\", " - "\"authMD5\", zeroDotZero, " - "usmHMACMD5AuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"passwd_md5xxxxxx\", \"\"}.\n", []), - ok = io:format(Fid, "{\"mgrEngine\", \"authSHA\", " - "\"authSHA\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"\"}.\n", []), - ok = io:format(Fid, "{\"mgrEngine\", \"privDES\", " - "\"privDES\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", - []), - file:close(Fid), - true; - false -> - false - end. - -update_usm_mgr(Vsns, Dir) -> - case lists:member(v3, Vsns) of - true -> - {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),[read,write]), - file:position(Fid, eof), - ok = io:format(Fid, "{\"agentEngine\", \"newUser\", " - "\"newUser\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", - []), - ok = io:format(Fid, "{\"mgrEngine\", \"newUser\", " - "\"newUser\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", - []), - file:close(Fid), - true; - false -> - false - end. - -rewrite_usm_mgr(Dir, ShaKey, DesKey) -> - ?line ok = file:rename(filename:join(Dir,"usm.conf"), - filename:join(Dir,"usm.old")), - ?line {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),write), - ok = io:format(Fid, "{\"agentEngine\", \"newUser\", " - "\"newUser\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"~s\", \"~s\"}.\n", - [ShaKey, DesKey]), - ok = io:format(Fid, "{\"mgrEngine\", \"newUser\", " - "\"newUser\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"~s\", \"~s\"}.\n", - [ShaKey, DesKey]), - file:close(Fid). - -reset_usm_mgr(Dir) -> - ?line ok = file:rename(filename:join(Dir,"usm.old"), - filename:join(Dir,"usm.conf")). - - -update_community([v3], _Dir) -> ok; -update_community(_, Dir) -> - {ok, Fid} = file:open(filename:join(Dir,"community.conf"),[read,write]), - file:position(Fid, eof), - ok=io:format(Fid,"{\"no-rights\",\"no-rights\",\"no-rights\",\"\",\"\"}.\n", - []), - file:close(Fid). - - --define(tDescr_instance, [1,3,6,1,2,1,16,1,0]). -update_vacm(_Vsn, Dir) -> - {ok, Fid} = file:open(filename:join(Dir,"vacm.conf"),[read,write]), - file:position(Fid, eof), - ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"authMD5\",\"initial\"}.\n",[]), - ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"authSHA\",\"initial\"}.\n",[]), - ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"privDES\",\"initial\"}.\n",[]), - ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"newUser\",\"initial\"}.\n",[]), - ok = io:format(Fid, "{vacmViewTreeFamily, \"internet\", " - "~w, excluded, null}.\n", [?tDescr_instance]), - file:close(Fid). - - -vacm_ver(v1) -> v1; -vacm_ver(v2) -> v2c; -vacm_ver(v3) -> usm. - - -write_community_conf(Dir, Confs) -> - {ok, Fid} = file:open(filename:join(Dir,"community.conf"),write), - ok = write_community_conf1(Fid, Confs), - file:close(Fid). - -write_community_conf1(_, []) -> - ok; -write_community_conf1(Fid, [{ComIdx, ComName, SecName, CtxName, TransTag}|Confs]) -> - ok = io:format(Fid, "{\"~s\", \"~s\", \"~s\", \"~s\", \"~s\"}.~n", - [ComIdx, ComName, SecName, CtxName, TransTag]), - write_community_conf1(Fid, Confs). - - -write_target_addr_conf(Dir, Confs) -> - {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), - ok = write_target_addr_conf1(Fid, Confs), - file:close(Fid). - - -write_target_addr_conf1(_, []) -> - ok; -write_target_addr_conf1(Fid, - [{Name, Ip, Port, Timeout, Retry, TagList, ParamName, - EngineId, TMask, MaxMsgSz}|Confs]) -> - ok = io:format(Fid, "{\"~s\", ~w, ~w, ~w, ~w, \"~s\", \"~s\", \"~s\", ~w, ~w}.~n", - [Name, Ip, Port, Timeout, Retry, TagList, ParamName, - EngineId, TMask, MaxMsgSz]), - write_target_addr_conf1(Fid, Confs). - -write_target_addr_conf(Dir, ManagerIp, UDP, Vsns) -> - {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), - lists:foreach(fun(Vsn) -> - ok = io:format(Fid, - "{\"~s\", ~w, ~w, 1500, 3, " - "\"std_trap\", \"~s\"}.~n", - [mk_ip(ManagerIp, Vsn), - ManagerIp, UDP, mk_param(Vsn)]), - case Vsn of - v1 -> ok; - v2 -> - ok = io:format(Fid, - "{\"~s.2\",~w,~w,1500,3, " - "\"std_inform\", \"~s\"}.~n", - [mk_ip(ManagerIp, Vsn), - ManagerIp, UDP, - mk_param(Vsn)]); - v3 -> - ok = io:format(Fid, - "{\"~s.3\",~w,~w,1500,3, " - "\"std_inform\", \"~s\", " - "\"mgrEngine\", [], 1024}.~n", - [mk_ip(ManagerIp, Vsn), - ManagerIp, UDP, - mk_param(Vsn)]) - end - end, - Vsns), - file:close(Fid). - -mk_param(v1) -> "target_v1"; -mk_param(v2) -> "target_v2"; -mk_param(v3) -> "target_v3". - -mk_ip([A,B,C,D], Vsn) -> - io_lib:format("~w.~w.~w.~w ~w", [A,B,C,D,Vsn]). - - -rewrite_target_addr_conf(Dir,NewPort) -> - TAFile = filename:join(Dir, "target_addr.conf"), - ?DBG("rewrite_target_addr_conf -> read target file info of address config file",[]), - case file:read_file_info(TAFile) of - {ok, _} -> ok; - {error, R} -> ?ERR("failure reading file info of " - "target address config file: ~p",[R]), - ok - end, - - ?line [TrapAddr|Addrs] = - snmp_conf:read(TAFile,fun(R) -> rewrite_target_addr_conf1(R) end), - - ?DBG("rewrite_target_addr_conf -> TrapAddr: ~p",[TrapAddr]), - - NewAddrs = [rewrite_target_addr_conf2(NewPort,TrapAddr)|Addrs], - - ?DBG("rewrite_target_addr_conf -> NewAddrs: ~p",[NewAddrs]), - - ?line ok = file:rename(filename:join(Dir,"target_addr.conf"), - filename:join(Dir,"target_addr.old")), - ?line {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), - - ?line ok = rewrite_target_addr_conf3(Fid,NewAddrs), - - file:close(Fid). - -rewrite_target_addr_conf1(O) -> - {ok,O}. - -rewrite_target_addr_conf2(NewPort,{Name,Ip,_Port,Timeout,Retry, - "std_trap",EngineId}) -> - ?LOG("rewrite_target_addr_conf2 -> entry with std_trap",[]), - {Name,Ip,NewPort,Timeout,Retry,"std_trap",EngineId}; -rewrite_target_addr_conf2(_NewPort,O) -> - ?LOG("rewrite_target_addr_conf2 -> entry with " - "~n O: ~p",[O]), - O. - - -rewrite_target_addr_conf3(_,[]) -> ok; -rewrite_target_addr_conf3(Fid,[{Name,Ip,Port,Timeout,Retry, - ParamName,EngineId}|T]) -> - ?LOG("rewrite_target_addr_conf3 -> write(1) ~s",[ParamName]), - io:format(Fid, - "{\"~s\", " % Name - "~p, " % Ip - "~p, " % Port - "~p, " % Timeout - "~p, " % Retry - "\"~s\", " % ParamsName - "\"~s\"}.", % EngineId - [Name,Ip,Port,Timeout,Retry,ParamName,EngineId]), - rewrite_target_addr_conf3(Fid,T); -rewrite_target_addr_conf3(Fid,[{Name,Ip,Port,Timeout,Retry,TagList, - ParamName,EngineId,TMask,MMS}|T]) -> - ?LOG("rewrite_target_addr_conf3 -> write(2) ~s",[ParamName]), - io:format(Fid, - "{\"~s\", " % Name - "~p, " % Ip - "~p, " % Port - "~p, " % Timeout - "~p, " % Retry - "\"~s\", " % TagList - "\"~s\", " % ParamsName - "\"~s\"," % EngineId - "~p, " % TMask - "~p}.", % MMS - [Name,Ip,Port,Timeout,Retry,TagList,ParamName, - EngineId,TMask,MMS]), - rewrite_target_addr_conf3(Fid,T). - -reset_target_addr_conf(Dir) -> - ?line ok = file:rename(filename:join(Dir,"target_addr.old"), - filename:join(Dir,"target_addr.conf")). - -write_target_params_conf(Dir, Vsns) -> - {ok, Fid} = file:open(filename:join(Dir,"target_params.conf"),write), - lists:foreach(fun(Vsn) -> - MP = if Vsn == v1 -> v1; - Vsn == v2 -> v2c; - Vsn == v3 -> v3 - end, - SM = if Vsn == v1 -> v1; - Vsn == v2 -> v2c; - Vsn == v3 -> usm - end, - ok = io:format(Fid, "{\"target_~w\", ~w, ~w, " - "\"all-rights\", noAuthNoPriv}.~n", - [Vsn, MP, SM]) - end, - Vsns), - file:close(Fid). - -rewrite_target_params_conf(Dir, SecName, SecLevel) -> - ?line ok = file:rename(filename:join(Dir,"target_params.conf"), - filename:join(Dir,"target_params.old")), - ?line {ok, Fid} = file:open(filename:join(Dir,"target_params.conf"),write), - ?line ok = io:format(Fid, "{\"target_v3\", v3, usm, \"~s\", ~w}.~n", - [SecName, SecLevel]), - file:close(Fid). - -reset_target_params_conf(Dir) -> - ?line ok = file:rename(filename:join(Dir,"target_params.old"), - filename:join(Dir,"target_params.conf")). - -write_notify_conf(Dir) -> - {ok, Fid} = file:open(filename:join(Dir,"notify.conf"),write), - ok = io:format(Fid, "{\"standard trap\", \"std_trap\", trap}.~n", []), - ok = io:format(Fid, "{\"standard inform\", \"std_inform\",inform}.~n", []), - file:close(Fid). - -ver_to_trap_str([v1]) -> "v1"; -ver_to_trap_str([v2]) -> "v2"; -% default is to use the latest snmp version -ver_to_trap_str([v1,v2]) -> "v2". - - - -write_view_conf(Dir) -> - {ok, Fid} = file:open(a(Dir,"view.conf"),write), - ok = io:format(Fid, "{2, [1,3,6], included, null}.~n", []), - ok = io:format(Fid, "{2, ~w, excluded, null}.~n", [?tDescr_instance]), - file:close(Fid). - -a(A,B) -> lists:append(A,B). - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -copy_file(From, To) -> - {ok, Bin} = file:read_file(From), - ok = file:write_file(To, Bin). - - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -display_memory_usage() -> - Info = snmpa:info(snmp_master_agent), - TreeSize = lists_key1search(tree_size_bytes, Info), - ProcMem = lists_key1search(process_memory, Info), - MibDbSize = lists_key1search([db_memory,mib], Info), - NodeDbSize = lists_key1search([db_memory,node], Info), - TreeDbSize = lists_key1search([db_memory,tree], Info), - ?INF("Memory usage: " - "~n Tree size: ~p" - "~n Process memory size: ~p" - "~n Mib db size: ~p" - "~n Node db size: ~p" - "~n Tree db size: ~p", - [TreeSize, ProcMem, MibDbSize, NodeDbSize, TreeDbSize]). - -lists_key1search([], Res) -> - Res; -lists_key1search([Key|Keys], List) when atom(Key), list(List) -> - case lists:keysearch(Key, 1, List) of - {value, {Key, Val}} -> - lists_key1search(Keys, Val); - false -> - undefined - end; -lists_key1search(Key, List) when atom(Key) -> - case lists:keysearch(Key, 1, List) of - {value, {Key, Val}} -> - Val; - false -> - undefined - end. - - -regs() -> - lists:sort(registered()). diff --git a/lib/snmp/test/snmp_agent_v1_test.erl b/lib/snmp/test/snmp_agent_v1_test.erl deleted file mode 100644 index 737bb25cc3..0000000000 --- a/lib/snmp/test/snmp_agent_v1_test.erl +++ /dev/null @@ -1,2673 +0,0 @@ -%% -%% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2005-2010. All Rights Reserved. -%% -%% The contents of this file are subject to the Erlang Public License, -%% Version 1.1, (the "License"); you may not use this file except in -%% compliance with the License. You should have received a copy of the -%% Erlang Public License along with this software. If not, it can be -%% retrieved online at http://www.erlang.org/. -%% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -%% the License for the specific language governing rights and limitations -%% under the License. -%% -%% %CopyrightEnd% -%% - --module(snmp_agent_v1_test). - -%% TODO -%% * Test fault-tolerance (kill master etc) -%% - --export([]). - --define(application, snmp). - --include_lib("kernel/include/file.hrl"). --include("test_server.hrl"). --include("snmp_test_lib.hrl"). --define(SNMP_USE_V3, true). --include_lib("snmp/include/snmp_types.hrl"). - - --define(klas1, [1,3,6,1,2,1,7]). --define(klas2, [1,3,6,1,2,1,9]). --define(klas3, [1,3,6,1,2,1,8,1]). --define(klas4, [1,3,6,1,2,1,8,4]). --define(sa, [1,3,6,1,4,1,193,2]). --define(system, [1,3,6,1,2,1,1]). --define(snmp, [1,3,6,1,2,1,11]). --define(snmpTraps, [1,3,6,1,6,3,1,1,5]). --define(ericsson, [1,3,6,1,4,1,193]). --define(testTrap, [1,3,6,1,2,1,15,0]). --define(xDescr, [1,3,6,1,2,1,17,1]). --define(xDescr2, [1,3,6,1,2,1,17,2]). - --define(active, 1). --define(notInService, 2). --define(notReady, 3). --define(createAndGo, 4). --define(createAndWait, 5). --define(destroy, 6). - --define(TRAP_UDP, 5000). - --define(tooBigStr, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"). - - -%% -- test manager defines -- --define(MGR, snmp_test_mgr). --define(GN(X), ?MGR:gn(X)). --define(G(X), ?MGR:g(X)). --define(S(X), ?MGR:s(X)). --define(GB(X), ?MGR:gb(X)). --define(SEND_BYTES(X), ?MGR:send_bytes(X)). - -%% -- agent test lib defines -- --define(LIB, snmp_agent_test_lib). --define(INIT_CASE(X), ?LIB:init_case(X)). --define(TRY_TEST1(A), ?LIB:try_test(A)). --define(TRY_TEST2(A, B), ?LIB:try_test(A, B)). --define(TRY_TEST3(A, B, C), ?LIB:try_test(A, B, C)). --define(START_SA(A, B, C), ?LIB:start_subagent(A, B, C)). --define(STOP_SA(A), ?LIB:stop_subagent(A)). --define(P1(C), ?LIB:p(C)). --define(P2(F), ?LIB:p(F,[])). --define(P3(F,A), ?LIB:p(F,A)). --define(RPC(N, F, A), ?LIB:rpc(N, F, A)). - - --define(v1_2(V1,V2), - case get(vsn) of - v1 -> V1; - _ -> V2 - end). - --define(v1_2_3(V1,V2,V3), - case get(vsn) of - v1 -> V1; - v2 -> V2; - _ -> V3 - end). - -all(suite) -> {req, - [mnesia, distribution, - {local_slave_nodes, 2}, {time, 360}], - [{conf, init, cases(), finish}]}. - -init_per_testcase(_Case, Config) when list(Config) -> - Dog = ?t:timetrap(?t:minutes(6)), - [{watchdog, Dog}|Config]. - -end_per_testcase(_Case, Config) when list(Config) -> - Dog = ?config(watchdog, Config), - ?t:timetrap_cancel(Dog), - Config. - -cases() -> - [simple, - db_notify_client, - processing, - big, - big2, - %% implied, - loop_mib, - api, - subagent, - mnesia, - multiple_reqs, - sa_register, - v1_trap, - sa_error, - next_across_sa, - undo, - standard_mibs, - sparse_table, - cnt_64, - opaque, - %% opaque]. - - change_target_addr_config, - - reported_bugs, - tickets - ]. - - -init(Config) -> - init_all(Config), - init_v1(Config). - -finish(Config) -> - finish_v1(Config), - finish_all(Config). - -init_v1(Config) when list(Config) -> - ?line SaNode = ?config(snmp_sa, Config), - ?line create_tables(SaNode), - ?line AgentDir = ?config(agent_dir, Config), - ?line MgrDir = ?config(mgr_dir, Config), - ?line Ip = ?config(ip, Config), - ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v1} | start_v1_agent(Config)]. - -finish_v1(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - - -%%----------------------------------------------------------------- -%% This function takes care of the old OTP-SNMPEA-MIB. -%% Unfortunately, the testcases were written to use the data in the -%% internal tables, and these table are now obsolete and not used -%% by the agent. Therefore, we emulate them by using -%% OLD-SNMPEA-MIB, which uses the default impl. of all tables. -%% -%% These two rows must exist in intCommunityTable -%% {[147,214,36,45], "public", 2, readWrite}. -%% {[147,214,36,45], "standard trap", 2, read}. -%% (But with the manager's IP address) -%% -%%----------------------------------------------------------------- -init_old() -> - snmpa_local_db:table_create_row(intCommunityTable, - get(mip) ++ [6 | "public"], - {get(mip), "public", 2, 2}), - snmpa_local_db:table_create_row(intCommunityTable, - get(mip) ++ [13 | "standard trap"], - {get(mip), "standard trap", 2, 1}), - snmpa_local_db:variable_set(intAgentIpAddress, [127,0,0,1]). - - -%% ========================================================================= -%% -%% C A S E S -%% -%% ========================================================================= - -%% -- simple -- - -simple(suite) -> []; -simple(Config) when list(Config) -> - ?P1(simple), - ?INIT_CASE(Config), - - ?TRY_TEST1(simple_standard_test). - -simple_standard_test() -> - ?DBG("simple_standard_test -> entry",[]), - ?GN([[1,1]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]), - - ?GN([[1,3]]), - ?line expect(11, [{[sysDescr,0], "Erlang SNMP agent"}]), - - ?GN([[1,3,6]]), - ?line expect(12, [{[sysDescr,0], "Erlang SNMP agent"}]), - - ?GN([[1,3,6,1]]), - ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}]), - - ?GN([[1,3,6,1,2]]), - ?line expect(14, [{[sysDescr,0], "Erlang SNMP agent"}]), - - ?GN([[1,3,6,1,2,1]]), - ?line expect(15, [{[sysDescr,0], "Erlang SNMP agent"}]), - - ?GN([[1,3,6,1,2,1,1]]), - ?line expect(16, [{[sysDescr,0], "Erlang SNMP agent"}]), - - ?GN([[sysDescr]]), - ?line expect(17, [{[sysDescr,0], "Erlang SNMP agent"}]), - - ?G([[sysDescr,0]]), - ?line expect(2, [{[sysDescr,0], "Erlang SNMP agent"}]), - - ?G([[sysDescr]]), - ?line ?v1_2(expect(3, noSuchName, 1, any), - expect(3, [{[sysDescr], noSuchObject}])), - - ?G([[1,6,7,0]]), - ?line ?v1_2(expect(41, noSuchName, 1, any), - expect(3, [{[1,6,7,0], noSuchObject}])), - - ?GN([[1,13]]), - ?line ?v1_2(expect(4, noSuchName,1, any), - expect(4, [{[1,13], endOfMibView}])), - - ?S([{[sysLocation, 0], "new_value"}]), - ?line expect(5, [{[sysLocation, 0], "new_value"}]), - - ?G([[sysLocation, 0]]), - ?line expect(6, [{[sysLocation, 0], "new_value"}]), - - io:format("Testing noSuchName and badValue...~n"), - ?S([{[sysServices,0], 3}]), - ?line expect(61, ?v1_2(noSuchName, notWritable), 1, any), - - ?S([{[sysLocation, 0], i, 3}]), - ?line expect(62, ?v1_2(badValue, wrongType), 1, any), - ?DBG("simple_standard_test -> done",[]), - ok. - - -%% -- db_notify_client -- - -%% This is run in the agent node -db_notify_client(suite) -> []; -db_notify_client(Config) when list(Config) -> - ?P1(db_notify_client), - {SaNode, MgrNode, MibDir} = ?INIT_CASE(Config), - ?DBG("~n\tSaNode: ~p~n\tMgrNode: ~p~n\tMibDir: ~p", - [SaNode,MgrNode,MibDir]), - snmpa_local_db:register_notify_client(self(),?MODULE), - - %% This call (the manager) will issue to set operations, so - %% we expect to receive to notify(insert) calls. - ?TRY_TEST1(db_notify_client_test), - - ?DBG("await first notify",[]), - receive - {db_notify_test_reply,insert} -> ?DBG("first notify received",[]),ok - end, - - ?DBG("await second notify",[]), - receive - {db_notify_test_reply,insert} -> ?DBG("second notify received",[]),ok - end, - - snmpa_local_db:unregister_notify_client(self()). - - -%% This is run in the manager node -db_notify_client_test() -> - ?DBG("set first new sysLocation",[]), - ?S([{[sysLocation, 0], "new_value"}]), - ?line expect(5, [{[sysLocation, 0], "new_value"}]), - - ?DBG("set second new sysLocation",[]), - ?S([{[sysLocation, 0], "new_value"}]), - ?line expect(5, [{[sysLocation, 0], "new_value"}]). - -notify(Pid,What) -> - ?DBG("notify(~p,~p) -> called",[Pid,What]), - Pid ! {db_notify_test_reply,What}. - - -%% -- processing -- - -%% Req. Test2 -processing(suite) -> []; -processing(Config) when list(Config) -> - ?P1(processing), - ?INIT_CASE(Config), - - ?line load_master("Test2"), - ?TRY_TEST1(v1_proc), - ?line unload_master("Test2"). - -v1_proc() -> - ?DBG("v1_proc -> entry", []), - %% According to RFC1157. - %% Template:
: - v1_get_p(), - v1_get_next_p(), - v1_set_p(). - -v1_get_p() -> - %% 4.1.2:1 - ?G([[test2]]), - ?line expect(10, noSuchName, 1, [{[test2], 'NULL'}]), - ?G([[tDescr]]), - ?line expect(11, noSuchName, 1, [{[tDescr], 'NULL'}]), - ?G([[tDescr2,0]]), - ?line expect(12, noSuchName, 1, [{[tDescr2,0], 'NULL'}]), - ?G([[tDescr3,0]]), - ?line expect(131, noSuchName, 1, [{[tDescr3,0], 'NULL'}]), - ?G([[tDescr4,0]]), - ?line expect(132, noSuchName, 1, [{[tDescr4,0], 'NULL'}]), - ?G([[sysDescr, 0], [tDescr,0]]), % Outside mibview - ?line expect(14, noSuchName, 2, [{[sysDescr, 0], 'NULL'}, - {[tDescr,0], 'NULL'}]), - ?G([[sysDescr,3]]), - ?line expect(15, noSuchName, 1, [{[sysDescr, 3], 'NULL'}]), - - %% 4.1.2:2 - ?G([[tTable]]), - ?line expect(20, noSuchName, 1, [{[tTable], 'NULL'}]), - ?G([[tEntry]]), - ?line expect(21, noSuchName, 1, [{[tEntry], 'NULL'}]), - - %% 4.1.2:3 - ?G([[tTooBig, 0]]), - ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), - - %% 4.1.2:4 - ?G([[tGenErr1, 0]]), - ?line expect(40, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), - ?G([[tGenErr2, 0]]), - ?line expect(41, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), - ?G([[sysDescr, 0], [tGenErr3, 0]]), - ?line expect(42, genErr, 2, [{[sysDescr, 0], 'NULL'}, - {[tGenErr3, 0], 'NULL'}]). - -v1_get_next_p() -> - %% 4.1.3:1 - ?GN([[1,3,7,1]]), - ?line expect(10, noSuchName, 1, [{[1,3,7,1], 'NULL'}]), - - ?GN([[tDescr2]]), - ?line expect(11, tooBig, 0, any), - - %% 4.1.3:2 - ?GN([[tTooBig]]), - io:format("We currently don't handle tooBig correct!!!\n"), - %% ?line expect(20, tooBig, 0, [{[tTooBig], 'NULL'}]), - ?line expect(20, tooBig, 0, any), - - %% 4.1.3:3 - ?GN([[tGenErr1]]), - %% ?line expect(40, genErr, 1, [{[tGenErr1], 'NULL'}]), - ?line expect(40, genErr, 1, any), - - ?GN([[tGenErr2]]), - %% ?line expect(41, genErr, 1, [{[tGenErr2], 'NULL'}]), - ?line expect(41, genErr, 1, any), - - ?GN([[sysDescr], [tGenErr3]]), - %% ?line expect(42, genErr, 2, [{[sysDescr], 'NULL'}, - %% {[tGenErr3], 'NULL'}]). - ?line expect(42, genErr, 2, any). - -v1_set_p() -> - %% 4.1.5:1 - ?S([{[1,3,7,0], i, 4}]), - ?line expect(10, noSuchName, 1, [{[1,3,7,0], 4}]), - - ?S([{[tDescr,0], s, "outside mibview"}]), - ?line expect(11, noSuchName, 1, [{[tDescr,0], "outside mibview"}]), - - ?S([{[tDescr3,0], s, "read-only"}]), - ?line expect(12, noSuchName, 1, [{[tDescr3,0], "read-only"}]), - - ?S([{[tDescr3], s, "noSuchObject"}]), - ?line expect(13, noSuchName, 1, [{[tDescr3], "noSuchObject"}]), - - ?S([{[tDescr3,1], s, "noSuchInstance"}]), - ?line expect(14, noSuchName, 1, [{[tDescr3,1], "noSuchInstance"}]), - - ?S([{[tDescr2,0], s, "inconsistentName"}]), - ?line expect(15, noSuchName, 1, [{[tDescr2,0], "inconsistentName"}]), - - %% 4.1.5:2 - ?S([{[tDescr2, 0], i, 4}]), - ?line expect(20, badValue, 1, [{[tDescr2, 0], 4}]), - - ?S([{[tDescr2, 0], s, "badValue"}]), - ?line expect(21, badValue, 1, [{[tDescr2, 0], "badValue"}]), - - %% 4.1.5:3 - %% The standard is quite incorrect here. The resp pdu was too big. In - %% the resp pdu, we have the original vbs. In the tooBig pdu we still - %% have to original vbs => the tooBig pdu is too big as well!!! It - %% may not get it to the manager, unless the agent uses 'NULL' instead - %% of the std-like original value. - ?S([{[tTooBig, 0], s, ?tooBigStr}]), - %% according to std: - %% ?line expect(30, tooBig, 0, [{[tTooBig, 0], ?tooBigStr}]), - ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), - - %% 4.1.5:4 - ?S([{[tDescr2, 0], s, "is_set_ok_fail"}]), - ?line expect(40, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]), - - ?S([{[tDescr2, 0], s, "commit_fail"}]), - ?line expect(41, genErr, 1, [{[tDescr2, 0], "commit_fail"}]). - - -%% -- big -- - -big(suite) -> []; -big(Config) when list(Config) -> - ?P1(big), - {SaNode, _MgrNode, _MibDir} = ?INIT_CASE(Config), - - p("Starting subagent..."), - ?line pong = net_adm:ping(SaNode), - - ?line {ok, SA} = ?START_SA(SaNode, ?klas1, "Klas1"), - ?DBG("big -> SA: ~p", [SA]), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - - ?TRY_TEST1(big_test), - - ?line ?STOP_SA(SA), - ?line unload_master("OLD-SNMPEA-MIB"). - -%% Req: system group, OLD-SNMPEA-MIB, Klas1 -big_test() -> - ?DBG("big_test -> testing simple next/get/set @ master agent...",[]), - simple_standard_test(), - - ?DBG("big_test -> testing simple next/get/set @ subagent...",[]), - ?GN([[klas1]]), - ?line expect(1, [{[fname,0], ""}]), - - ?G([[fname,0]]), - ?line expect(2, [{[fname,0], ""}]), - - ?S([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - - ?G([[fname,0]]), - ?line expect(4, [{[fname,0], "test set"}]), - - ?DBG("big_test -> " - "testing next from last instance in master to subagent...",[]), - ?GN([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(5, [{[fname,0], "test set"}]), - - ?GN([[1,1], - [?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, - {[fname,0], "test set"}]), - ?S([{[fname,0], s, ""}]), - ?line expect(52, [{[fname,0], ""}]), - - table_test(), - - ?DBG("big_test -> adding one row in subagent table",[]), - _FTab = [friendsEntry], - ?S([{[friendsEntry, [2, 3]], s, "kompis3"}, - {[friendsEntry, [3, 3]], i, ?createAndGo}]), - ?line expect(6, [{[friendsEntry, [2, 3]], "kompis3"}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - - ?G([[friendsEntry, [2, 3]], - [friendsEntry, [3, 3]]]), - ?line expect(7, [{[friendsEntry, [2, 3]], "kompis3"}, - {[friendsEntry, [3, 3]], ?active}]), - - ?S([{[friendsEntry, [3, 3]], i, ?destroy}]), - ?line expect(8, [{[friendsEntry, [3, 3]], ?destroy}]), - - otp_1131(), - - ?DBG("big_test -> adding two rows in subagent table with special INDEX", - []), - ?S([{[kompissEntry, [1, 3]], s, "kompis3"}, - {[kompissEntry, [2, 3]], i, ?createAndGo}]), - ?line expect(9, [{[kompissEntry, [1, 3]], "kompis3"}, - {[kompissEntry, [2, 3]], ?createAndGo}]), - - ?G([[kompissEntry, [1, 3]], - [kompissEntry, [2, 3]]]), - ?line expect(10, [{[kompissEntry, [1, 3]], "kompis3"}, - {[kompissEntry, [2, 3]], ?active}]), - - ?GN([[kompissEntry, [1]], - [kompissEntry, [2]]]), - ?line expect(11, [{[kompissEntry, [1, 3]], "kompis3"}, - {[kompissEntry, [2, 3]], ?active}]), - - ?S([{[kompissEntry, [1, 2]], s, "kompis3"}, - {[kompissEntry, [2, 2]], i, ?createAndGo}]), - ?line expect(12, [{[kompissEntry, [1, 2]], "kompis3"}, - {[kompissEntry, [2, 2]], ?createAndGo}]), - - ?GN([[kompissEntry, [1, 1]], - [kompissEntry, [2, 1]]]), - ?line expect(13, [{[kompissEntry, [1, 2]], "kompis3"}, - {[kompissEntry, [2, 2]], ?active}]), - - ?S([{[kompissEntry, [2, 3]], i, ?destroy}]), - ?line expect(14, [{[kompissEntry, [2, 3]], ?destroy}]), - - ?S([{[kompissEntry, [2, 2]], i, ?destroy}]), - ?line expect(15, [{[kompissEntry, [2, 2]], ?destroy}]), - ?DBG("big_test -> done",[]), - ok. - - -%% Req. system group, Klas2, OLD-SNMPEA-MIB -big_test_2() -> - ?P1(big_test_2), - - ?P2("Testing simple next/get/set @ master agent (2)..."), - simple_standard_test(), - - p("Testing simple next/get/set @ subagent (2)..."), - ?GN([[klas2]]), - ?line expect(1, [{[fname2,0], ""}]), - - ?G([[fname2,0]]), - ?line expect(2, [{[fname2,0], ""}]), - - ?S([{[fname2,0], s, "test set"}]), - ?line expect(3, [{[fname2,0], "test set"}]), - - ?G([[fname2,0]]), - ?line expect(4, [{[fname2,0], "test set"}]), - - otp_1298(), - - ?P2("Testing next from last object in master to subagent (2)..."), - ?GN([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(5, [{[fname2,0], "test set"}]), - - ?GN([[1,1], - [?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, - {[fname2,0], "test set"}]), - - table_test(), - - ?P2("Adding one row in subagent table (2)"), - ?S([{[friendsEntry2, [2, 3]], s, "kompis3"}, - {[friendsEntry2, [3, 3]], i, ?createAndGo}]), - ?line expect(6, [{[friendsEntry2, [2, 3]], "kompis3"}, - {[friendsEntry2, [3, 3]], ?createAndGo}]), - - ?G([[friendsEntry2, [2, 3]], - [friendsEntry2, [3, 3]]]), - ?line expect(7, [{[friendsEntry2, [2, 3]], "kompis3"}, - {[friendsEntry2, [3, 3]], ?active}]), - - ?S([{[friendsEntry2, [3, 3]], i, ?destroy}]), - ?line expect(8, [{[friendsEntry2, [3, 3]], ?destroy}]), - - ?P2("Adding two rows in subagent table with special INDEX (2)"), - ?S([{[kompissEntry2, [1, 3]], s, "kompis3"}, - {[kompissEntry2, [2, 3]], i, ?createAndGo}]), - ?line expect(9, [{[kompissEntry2, [1, 3]], "kompis3"}, - {[kompissEntry2, [2, 3]], ?createAndGo}]), - ?G([[kompissEntry2, [1, 3]], - [kompissEntry2, [2, 3]]]), - ?line expect(10, [{[kompissEntry2, [1, 3]], "kompis3"}, - {[kompissEntry2, [2, 3]], ?active}]), - ?GN([[kompissEntry2, [1]], - [kompissEntry2, [2]]]), - ?line expect(11, [{[kompissEntry2, [1, 3]], "kompis3"}, - {[kompissEntry2, [2, 3]], ?active}]), - - ?S([{[kompissEntry2, [1, 2]], s, "kompis3"}, - {[kompissEntry2, [2, 2]], i, ?createAndGo}]), - ?line expect(12, [{[kompissEntry2, [1, 2]], "kompis3"}, - {[kompissEntry2, [2, 2]], ?createAndGo}]), - - ?GN([[kompissEntry2, [1, 1]], - [kompissEntry2, [2, 1]]]), - ?line expect(13, [{[kompissEntry2, [1, 2]], "kompis3"}, - {[kompissEntry2, [2, 2]], ?active}]), - - ?S([{[kompissEntry2, [2, 3]], i, ?destroy}]), - ?line expect(14, [{[kompissEntry2, [2, 3]], ?destroy}]), - - ?S([{[kompissEntry2, [2, 2]], i, ?destroy}]), - ?line expect(15, [{[kompissEntry2, [2, 2]], ?destroy}]), - ok. - - -%% -- bug2 -- - -big2(suite) -> []; -big2(Config) when list(Config) -> - ?P1(big2), - %% This is exactly the same tests as 'big', but with the - %% v2 equivalent of the mibs. - {SaNode, _MgrNode, _MibDir} = ?INIT_CASE(Config), - - ?P2("Starting subagent..."), - ?line pong = net_adm:ping(SaNode), - - ?line {ok, SA} = ?START_SA(SaNode, ?klas1, "Klas1-v2"), - ?line load_master("OLD-SNMPEA-MIB-v2"), - ?line init_old(), - - ?TRY_TEST1(big_test), - - ?line ?STOP_SUBAGENT(SA), - ?line unload_master("OLD-SNMPEA-MIB-v2"). - - -implied(suite) -> []; -implied(Config) when list(Config) -> - ?P1(implied), - ?INIT_CASE(Config), - - ?line load_master("Test1"), - - ?TRY_TEST2(implied_test,[whereis(snmp_master_agent)]), - - ?line unload_master("Test1"). - -%% Req. Test1 -implied_test(MA) -> - ?LOG("implied_test -> start",[]), - - snmpa:verbosity(MA,trace), - snmpa:verbosity(MA,trace), - - %% Create two rows, check that they are get-nexted in correct order. - Idx1 = "apa", - Idx2 = "qq", - - ?DBG("implied_test -> (send) create row 1 '~s' in table 1",[Idx1]), - ?S([{[testStatus, Idx1], i, ?createAndGo}, {[testDescr, Idx1],s,"row 1"}]), - ?line expect(1, [{[testStatus, Idx1], ?createAndGo}, - {[testDescr, Idx1], "row 1"}]), - ?DBG("implied_test -> (send) create row 2 '~s' in table 1",[Idx2]), - - ?S([{[testStatus, Idx2], i, ?createAndGo}, {[testDescr, Idx2],s,"row 2"}]), - ?line expect(2, [{[testStatus, Idx2], ?createAndGo}, - {[testDescr, Idx2], "row 2"}]), - ?DBG("implied_test -> get-next(testDescr)",[]), - - ?GN([[testDescr]]), - ?line expect(3, [{[testDescr,Idx1], "row 1"}]), - ?DBG("implied_test -> get-next(testDescr) of row 1",[]), - - ?GN([[testDescr,Idx1]]), - ?line expect(4, [{[testDescr,Idx2], "row 2"}]), - - % Delete the rows - ?DBG("implied_test -> (send) delete row 1 '~s' from table 1",[Idx1]), - ?S([{[testStatus, Idx1], i, ?destroy}]), - ?line expect(5, [{[testStatus, Idx1], ?destroy}]), - - ?DBG("implied_test -> (send) delete row 2 '~s' from table 1",[Idx2]), - ?S([{[testStatus, Idx2], i, ?destroy}]), - ?line expect(6, [{[testStatus, Idx2], ?destroy}]), - - %% Try the same in other table - Idx3 = [1, "apa"], - Idx4 = [1, "qq"], - ?DBG("implied_test -> (send) create row 1 '~s' in table 2",[Idx3]), - ?S([{[testStatus2, Idx3], i, ?createAndGo}, {[testDescr2,Idx3],s,"row 1"}]), - ?line expect(1, [{[testStatus2, Idx3], ?createAndGo}, - {[testDescr2, Idx3], "row 1"}]), - - ?DBG("implied_test -> (send) create row 2 '~s' in table 2",[Idx4]), - ?S([{[testStatus2, Idx4], i, ?createAndGo}, - {[testDescr2,Idx4],s,"row 2"}]), - ?line expect(2, [{[testStatus2, Idx4], ?createAndGo}, - {[testDescr2, Idx4], "row 2"}]), - - ?DBG("implied_test -> get-next(testDescr2)",[]), - ?GN([[testDescr2]]), - ?line expect(3, [{[testDescr2,Idx3], "row 1"}]), - ?DBG("implied_test -> get-next(testDescr2) of row 1",[]), - - ?GN([[testDescr2,Idx3]]), - ?line expect(4, [{[testDescr2,Idx4], "row 2"}]), - - % Delete the rows - ?DBG("implied_test -> (send) delete row 1 '~s' from table 2",[Idx3]), - ?S([{[testStatus2, Idx3], i, ?destroy}]), - ?line expect(5, [{[testStatus2, Idx3], ?destroy}]), - - ?DBG("implied_test -> (send) delete row 2 '~s' from table 2",[Idx4]), - ?S([{[testStatus2, Idx4], i, ?destroy}]), - ?line expect(6, [{[testStatus2, Idx4], ?destroy}]), - - snmpa:verbosity(MA,log), - - ?LOG("implied_test -> done",[]). - - -%% -- loop_mib -- - -%%----------------------------------------------------------------- -%% Loop through entire MIB, to make sure that all instrum. funcs -%% works. -%% Load all std mibs that are not loaded by default. -%%----------------------------------------------------------------- -loop_mib(suite) -> []; -loop_mib(Config) when list(Config) -> - ?P1(loop_mib), - %% snmpa:verbosity(master_agent,debug), - %% snmpa:verbosity(mib_server,info), - {SaNode, MgrNode, MibDir} = ?INIT_CASE(Config), - ?DBG("loop_mib -> " - "~n SaNode: ~p" - "~n MgrNode: ~p" - "~n MibDir: ~p", [SaNode, MgrNode, MibDir]), - - ?DBG("loop_mib -> load mib SNMP-COMMUNITY-MIB",[]), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?DBG("loop_mib -> load mib SNMP-MPD-MIB",[]), - ?line load_master_std("SNMP-MPD-MIB"), - ?DBG("loop_mib -> load mib SNMP-TARGET-MIB",[]), - ?line load_master_std("SNMP-TARGET-MIB"), - ?DBG("loop_mib -> load mib SNMP-NOTIFICATION-MIB",[]), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?DBG("loop_mib -> load mib SNMP-FRAMEWORK-MIB",[]), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?DBG("loop_mib -> load mib SNMP-VIEW-BASED-ACM-MIB",[]), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - ?DBG("loop_mib -> try",[]), - - ?TRY_TEST1(loop_mib), - - ?DBG("loop_mib -> unload mib SNMP-COMMUNITY-MIB",[]), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?DBG("loop_mib -> unload mib SNMP-MPD-MIB",[]), - ?line unload_master("SNMP-MPD-MIB"), - ?DBG("loop_mib -> unload mib SNMP-TARGET-MIB",[]), - ?line unload_master("SNMP-TARGET-MIB"), - ?DBG("loop_mib -> unload mib SNMP-NOTIFICATION-MIB",[]), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?DBG("loop_mib -> unload mib SNMP-FRAMEWORK-MIB",[]), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?DBG("loop_mib -> unload mib SNMP-VIEW-BASED-ACM-MIB",[]), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - %% snmpa:verbosity(master_agent,log), - %% snmpa:verbosity(mib_server,silence), - ?LOG("loop_mib -> done",[]). - -%% Req. As many mibs all possible -loop_mib() -> - ?DBG("loop_mib -> entry",[]), - N = loop_it([1,1], 0), - ?P3("found ~w varibles\n", [N]), - ?line N = if N < 100 -> 100; - true -> N - end. - -loop_it(Oid, N) -> - ?DBG("loop_it -> entry with" - "~n Oid: ~p" - "~n N: ~p", [Oid,N]), - case get_next_req([Oid]) of - #pdu{type='get-response', error_status=noError, error_index=0, - varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> - ?DBG("loop_it -> " - "~n NOid: ~p" - "~n Value: ~p",[NOid,Value]), - ?line [Value2] = get_req(1, [NOid]), % must not be same - ?DBG("loop_it_1 -> " - "~n Value2: ~p",[Value2]), - loop_it(NOid, N+1); - - #pdu{type='get-response', error_status=noSuchName, error_index=1, - varbinds=[_]} -> - ?DBG("loop_it -> done",[]), - N; - - #pdu{type = Type, error_status = Err, error_index = Idx, - varbinds = Vbs} -> - exit({unexpected_pdu, ?LINE, Type, Err, Idx, Vbs}) - - end. - - -%% -- api -- - -api(suite) -> []; -api(Config) when list(Config) -> - ?P1(api), - ?INIY_CASE(Config), - - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - - ?TRY_TEST2(api_test, [node()]), - - ?line unload_master("OLD-SNMPEA-MIB"). - -%% Req. OLD-SNMPEA-MIB -api_test(MaNode) -> - ?line {value, OID} = ?RPC(MaNode, name_to_oid, [intAgentIpAddress]), - ?line {value, intAgentIpAddress} = ?RPC(MaNode, oid_to_name, [OID]), - ?line false = ?RPC(MaNode, name_to_oid, [intAgentIpAddres]), - ?line false = ?RPC(MaNode, oid_to_name, [[1,5,32,3,54,3,3,34,4]]), - ?line {value, 2} = ?RPC(MaNode, enum_to_int, [intViewType, excluded]), - ?line {value, excluded} = ?RPC(MaNode, int_to_enum, [intViewType, 2]), - ?line false = ?RPC(MaNode, enum_to_int, [intViewType, exclude]), - ?line false = ?RPC(MaNode, enum_to_int, [intAgentIpAddress, exclude]), - ?line false = ?RPC(MaNode, enum_to_int, [intAgentIpAddre, exclude]), - ?line false = ?RPC(MaNode, int_to_enum, [intViewType, 3]), - ?line false = ?RPC(MaNode, int_to_enum, [intAgentIpAddress, 2]), - ?line false = ?RPC(MaNode, int_to_enum, [intAgentIpAddre, 2]), - ?line {value, active} = ?RPC(MaNode, int_to_enum, ['RowStatus', ?active]), - ?line {value, ?destroy} = - ?RPC(MaNode, enum_to_int, ['RowStatus', destroy]), - ?line false = ?RPC(MaNode, enum_to_int, ['RowStatus', xxxdestroy]), - ?line false = ?RPC(MaNode, enum_to_int, ['xxRowStatus', destroy]), - ?line false = ?RPC(MaNode, int_to_enum, ['RowStatus', 25]), - ?line false = ?RPC(MaNode, int_to_enum, ['xxRowStatus', 1]), - ?line case snmp:date_and_time() of - List when list(List), length(List) == 8 -> ok; - List when list(List), length(List) == 11 -> ok - end. - - -%% -- subagent -- - -subagent(suite) -> []; -subagent(Config) when list(Config) -> - ?P1(subagent), - {SaNode, _MgrNode, MibDir} = ?INIT_CASE(Config), - - ?line {ok, SA} = ?START_SA(SaNode, ?klas1, "Klas1"), - - ?TRY_TEST1(load_test_sa), - - ?P2("Testing unregister subagent [~w]...", [SA]), - MA = whereis(snmp_master_agent), - ?RPC(SaNode, unregister_subagent, [MA, SA]), - ?TRY_TEST1(unreg_test), - - ?P2("Loading previous subagent mib in master and testing..."), - ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas1"]), - ?TRY_TEST1(load_test), - - ?P2("Unloading previous subagent mib in master and testing..."), - ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas1"]), - - ?TRY_TEST1(unreg_test), - - ?P2("Testing register subagent..."), - ?RPC(SaNode, register_subagent, [MA, ?klas1, SA]), - ?TRY_TEST1(load_test_sa), - - ?line ?STOP_SA(SA), - ?TRY_TEST1(unreg_test). - -%% Req. Klas1 -load_test_sa() -> - ?GN([[?v1_2(sysServices,sysORLastChange), 0]]), - ?line expect(1, [{[fname,0], any}]). - -unreg_test() -> - ?GN([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(1, [{[snmpInPkts, 0], any}]). - -load_test() -> - ?GN([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(1, [{[fname,0], ""}]). - - -%% -- mnesia -- - -mnesia(suite) -> []; -mnesia(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Starting subagent with mnesia impl..."), - {ok, SA} = start_subagent(SaNode, ?klas2, "Klas2"), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - - ?TRY_TEST1(big_test_2), - - p("Testing unregister subagent..."), - MA = whereis(snmp_master_agent), - rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), - ?TRY_TEST1(unreg_test), - ?line unload_master("OLD-SNMPEA-MIB"), - ?line stop_subagent(SA). - - -%% -- multiple_reqs -- - -multiple_reqs(suite) -> - {req, [], {conf, init_mul, mul_cases(), finish_mul}}. - -mul_cases() -> - [mul_get, mul_get_err, mul_next, mul_next_err, mul_set_err]. - -init_mul(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - [{mul_sub, SA} | Config]. - -finish_mul(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - SA = ?config(mul_sub, Config), - - ?line unload_master("OLD-SNMPEA-MIB"), - ?line stop_subagent(SA), - lists:keydelete(mul_sub, 1, Config). - - -%% -- mul_get -- - -mul_get(suite) -> []; -mul_get(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple get..."), - ?TRY_TEST1(do_mul_get). - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_get() -> - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - g([[sysDescr,0], Key1c4, [fname,0],Key1c3, - [sysName,0]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[fname,0], "test set"}, - {Key1c3, 2}, - {[sysName,0], "test"}]), - g([[1,3,7,1], Key1c4, [sysDescr,0], [1,3,7,2], Key1c3, [sysDescr,0]]), - ?line ?v1_2(expect(2, noSuchName, [1,4], any), - expect(2, [{[1,3,7,1], noSuchObject}, - {Key1c4, 2}, - {[sysDescr,0], "Erlang SNMP agent"}, - {[1,3,7,2], noSuchObject}, - {Key1c3, 2}, - {[sysDescr,0], "Erlang SNMP agent"}])). - - -%% -- mul_get_err -- - -mul_get_err(suite) -> []; -mul_get_err(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple get with error..."), - ?TRY_TEST1(do_mul_get_err). - -%% Req. v1, system group, Klas1, OLD-SNMPEA-MIB, *ej* Klas3. -do_mul_get_err() -> - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - g([[sysDescr,0],Key1c4,[fname,0], Key1c3, [sysName,2]]), - ?line ?v1_2(expect(1, noSuchName, 5, any), - expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[fname,0], "test set"}, - {Key1c3, 2}, - {[sysName,2], noSuchInstance}])), - g([[sysDescr,0],Key1c4,[fname3,0], Key1c3, [sysName,1]]), - ?line ?v1_2(expect(1, noSuchName, [3,5], any), - expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[fname3,0], noSuchObject}, - {Key1c3, 2}, - {[sysName,1], noSuchInstance}])). - - -%% -- mul_next -- - -mul_next(suite) -> []; -mul_next(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple next..."), - ?TRY_TEST1(do_mul_next). - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_next() -> - Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], - Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - gn([[sysDescr], Key1c4s, [fname],Key1c3s,[sysName]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, {[fname,0], "test set"}, - {Key1c3, 2}, {[sysName,0], "test"}]). - - -%% -- mul_next_err -- - -mul_next_err(suite) -> []; -mul_next_err(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple next..."), - ?TRY_TEST1(do_mul_next_err). - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_next_err() -> - Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], - Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - gn([[sysDescr], Key1c4s, [1,3,6,999], [fname],[1,3,90], Key1c3s,[sysName]]), - ?line ?v1_2(expect(1, noSuchName, [3,5], any), - expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[1,3,6,999], endOfMibView}, - {[fname,0], "test set"}, - {[1,3,90], endOfMibView}, - {Key1c3, 2}, - {[sysName,0], "test"}])). - - -%% -- mul_set -- - -mul_set(suite) -> []; -mul_set(Config) when list(Config) -> - ?P(mul_set), - ?INIT_CASE(Config), - - ?TRY_TEST1(do_mul_set). - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_set() -> - p("Adding one row in subagent table, and one in master table"), - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - s([{[friendsEntry, [2, 3]], "kompis3"}, - {NewKeyc3, 2}, - {[sysLocation,0], "new_value"}, - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - ?line expect(1, [{[friendsEntry, [2, 3]], "kompis3"}, - {NewKeyc3, 2}, - {[sysLocation,0], "new_value"}, - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - g([[friendsEntry, [2, 3]], - [sysLocation,0], - [friendsEntry, [3, 3]]]), - ?line expect(2, [{[friendsEntry, [2, 3]], "kompis3"}, - {[sysLocation,0], "new_value"}, - {[friendsEntry, [3, 3]], ?active}]), - g([NewKeyc4]), - ?line expect(3, [{NewKeyc4, 2}]), - s([{[friendsEntry, [3, 3]], ?destroy}, - {NewKeyc5, ?destroy}]), - ?line expect(4, [{[friendsEntry, [3, 3]], ?destroy}, - {NewKeyc5, ?destroy}]). - - -%% -- mul_set_err -- - -mul_set_err(suite) -> []; -mul_set_err(Config) when list(Config) -> - ?P(mul_set_err), - ?INIT_CASE(Config), - - ?TRY_TEST1(do_mul_set_err). - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_set_err() -> - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - p("Adding one row in subagent table, and one in master table"), - s([{[friendsEntry, [2, 3]], s, "kompis3"}, - {NewKeyc3, 2}, - {[sysUpTime,0], 45}, % sysUpTime (readOnly) - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - ?line expect(1, ?v1_2(noSuchName, notWritable), 3, any), - g([[friendsEntry, [2, 3]]]), - ?line ?v1_2(expect(2, noSuchName, 1, any), - expect(2, [{[friendsEntry, [2,3]], noSuchInstance}])), - g([NewKeyc4]), - ?line ?v1_2(expect(3, noSuchName, 1, any), - expect(3, [{NewKeyc4, noSuchInstance}])). - - -%% -- sa_register -- - -sa_register(suite) -> []; -sa_register(Config) when list(Config) -> - ?P1(sa_register), - {SaNode, _MgrNode, MibDir} = ?INIT_CASE(Config), - - ?DBG("sa_register -> start subagent", []), - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), - - ?DBG("sa_register -> unregister subagent", []), - ?P2("Testing unregister subagent (2)..."), - MA = whereis(snmp_master_agent), - rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), - ?TRY_TEST1(unreg_test), - - ?P2("Loading SA-MIB..."), - ?DBG("sa_register -> unload mibs", []), - snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), - ?DBG("sa_register -> unload mibs", []), - snmpa:load_mibs(SA, [MibDir ++ "SA-MIB"]), - ?DBG("sa_register -> register subagent", []), - rpc:call(SaNode, snmp, register_subagent, [MA,?sa,SA]), - ?TRY_TEST1(sa_mib), - - ?DBG("sa_register -> stop subagent", []), - ?line stop_subagent(SA). - -%% Req. SA-MIB -sa_mib() -> - g([[sa, [2,0]]]), - ?line expect(1, [{[sa, [2,0]], 3}]), - s([{[sa, [1,0]], s, "sa_test"}]), - ?line expect(2, [{[sa, [1,0]], "sa_test"}]). - - -%% -- v1_trap -- - -v1_trap(suite) -> []; -v1_trap(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Testing trap sending from master agent..."), - MA = whereis(snmp_master_agent), - - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - ?TRY_TEST2(ma_trap1, [MA]), - ?TRY_TEST2(ma_trap2, [MA]), - ?TRY_TEST2(ma_v2_2_v1_trap, [MA]), - ?TRY_TEST2(ma_v2_2_v1_trap2, [MA]), - - p("Testing trap sending from subagent..."), - ?TRY_TEST2(sa_trap1, [SA]), - ?TRY_TEST2(sa_trap2, [SA]), - ?TRY_TEST2(sa_trap3, [SA]), - - ?line unload_master("TestTrap"), - ?line unload_master("TestTrapv2"), - - ?line stop_subagent(SA). - -ma_trap1(MA) -> - snmpa:send_trap(MA, testTrap2, "standard trap"), - ?line expect(1, trap, [system], 6, 1, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}]), - snmpa:send_trap(MA, testTrap1, "standard trap"), - ?line expect(2, trap, [1,2,3] , 1, 0, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}]). - -ma_trap2(MA) -> - snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). - -ma_v2_2_v1_trap(MA) -> - snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). - -ma_v2_2_v1_trap2(MA) -> - snmpa:send_trap(MA,linkUp,"standard trap",[{ifIndex, [1], 1}, - {ifAdminStatus, [1], 1}, - {ifOperStatus, [1], 2}]), - ?line expect(3, trap, [1,2,3], 3, 0, [{[ifIndex, 1], 1}, - {[ifAdminStatus, 1], 1}, - {[ifOperStatus, 1], 2}]). - -sa_trap1(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap"), - ?line expect(4, trap, [ericsson], 6, 1, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}]). - -sa_trap2(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), - ?line expect(5, trap, [ericsson], 6, 1, [{[system, [4,0]], - "pelle"}, - {[sa, [1,0]], "sa_test"}]). - -sa_trap3(SA) -> - snmpa:send_trap(SA, saTrap2, "standard trap", - [{intViewSubtree, [4], [1,2,3,4]}]), - ?line expect(6, trap, [ericsson], 6, 2, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}, - {[intViewSubtree,4],[1,2,3,4]}]). - -ma_v2_trap1(MA) -> - ?DBG("ma_v2_traps -> entry with MA = ~p => " - "send standard trap: testTrapv22",[MA]), - snmpa:send_trap(MA, testTrapv22, "standard trap"), - ?line expect(1, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - ?DBG("ma_v2_traps -> send standard trap: testTrapv21",[]), - snmpa:send_trap(MA, testTrapv21, "standard trap"), - ?line expect(2, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?snmp ++ [1]}]). - -ma_v2_trap2(MA) -> - snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}, - {[system, [4,0]], "pelle"}]). - -ma_v1_2_v2_trap(MA) -> - snmpa:send_trap(MA,linkDown,"standard trap",[{ifIndex, [1], 1}]), - ?line expect(2, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?snmpTraps ++ [3]}, - {[ifIndex, 1], 1}, - {[snmpTrapEnterprise, 0], [1,2,3]}]). - - -ma_v1_2_v2_trap2(MA) -> - snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}, - {[system, [4,0]], "pelle"}, - {[snmpTrapEnterprise, 0], ?system}]). - - -sa_v1_2_v2_trap1(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap"), - ?line expect(4, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, - {[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}, - {[snmpTrapEnterprise, 0], ?ericsson}]). - -sa_v1_2_v2_trap2(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), - ?line expect(4, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, - {[system, [4,0]], "pelle"}, - {[sa, [1,0]], "sa_test"}, - {[snmpTrapEnterprise, 0], ?ericsson}]). - - -sa_v1_2_v2_trap3(SA) -> - snmpa:send_trap(SA, saTrap2, "standard trap", - [{intViewSubtree, [4], [1,2,3,4]}]), - ?line expect(4, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?ericsson ++ [0, 2]}, - {[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}, - {[intViewSubtree,4],[1,2,3,4]}, - {[snmpTrapEnterprise, 0], ?ericsson}]). - - -%% -- sa_error -- - -sa_error(suite) -> []; -sa_error(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Testing sa bad value (is_set_ok)..."), - ?TRY_TEST1(sa_errs_bad_value), - - p("Testing sa gen err (set)..."), - ?TRY_TEST1(sa_errs_gen_err), - - p("Testing too big..."), - ?TRY_TEST1(sa_too_big), - - ?line unload_master("OLD-SNMPEA-MIB"), - stop_subagent(SA). - -%% Req. SA-MIB, OLD-SNMPEA-MIB -sa_errs_bad_value() -> - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - s([{NewKeyc3, 2}, - {[sa, [2,0]], 5}, % badValue (i is_set_ok) - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}]), - ?line expect(1, badValue, 2, any), - s([{NewKeyc3, 2}, - {[sa, [2,0]], 6}, % wrongValue (i is_set_ok) - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}]), - ?line expect(1, ?v1_2(badValue, wrongValue), 2, any), - g([NewKeyc4]), - ?line ?v1_2(expect(2, noSuchName, 1, any), - expect(2, [{NewKeyc4, noSuchInstance}])). - -%% Req. SA-MIB, OLD-SNMPEA-MIB -sa_errs_gen_err() -> - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - s([{NewKeyc3, 2},{NewKeyc4, 2}, - {NewKeyc5, ?createAndGo}, {[sa, [3,0]], 5}]), - ?line expect(1, genErr, 4, any), -% The row might have been added; we don't know. -% (as a matter of fact we do - it is added, because the agent -% first sets its own vars, and then th SAs. Lets destroy it. - s([{NewKeyc5, ?destroy}]), - ?line expect(2, [{NewKeyc5, ?destroy}]). - -%% Req. SA-MIB, OLD-SNMPEA-MIB -sa_too_big() -> - g([[sa, [4,0]]]), - ?line expect(1, tooBig). - - -%% -- next_across_sa -- - -next_across_sa(suite) -> []; -next_across_sa(Config) when list(Config) -> - {SaNode, _MgrNode, MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Loading another subagent mib..."), - ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas1"]), - - rpc:call(SaNode, snmp, register_subagent, [MA, ?klas1, SA]), - ?TRY_TEST1(load_test_sa), - - p("Testing next across subagent (endOfMibView from SA)..."), - ?TRY_TEST1(next_across_sa), - - p("Unloading mib"), - snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), - rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), - ?TRY_TEST1(unreg_test), - - p("Starting another subagent"), - ?line {ok, SA2} = start_subagent(SaNode, ?klas1, "Klas1"), - p("Testing next across subagent (wrong prefix from SA)..."), - ?TRY_TEST1(next_across_sa), - - stop_subagent(SA), - stop_subagent(SA2). - -%% Req. Klas1, system group, snmp group (v1/v2) -next_across_sa() -> - gn([[sysDescr],[klas1,5]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {[snmpInPkts, 0], any}]). - - -%% -- undo -- - -undo(suite) -> []; -undo(Config) when list(Config) -> - {SaNode, _MgrNode, MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Testing undo phase at master agent..."), - ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas3"]), - ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas4"]), - ?TRY_TEST1(undo_test), - ?TRY_TEST1(api_test2), - ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas3"]), - - p("Testing bad return values from instrum. funcs..."), - ?TRY_TEST1(bad_return), - - ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas4"]), - - p("Testing undo phase at subagent..."), - ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas3"]), - ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas4"]), - ?line ok = snmpa:register_subagent(MA, ?klas3, SA), - ?line ok = snmpa:register_subagent(MA, ?klas4, SA), - ?TRY_TEST1(undo_test), - ?TRY_TEST1(api_test3), - - p("Testing undo phase across master/subagents..."), - ?TRY_TEST1(undo_test), - ?TRY_TEST1(api_test3), - stop_subagent(SA). - -%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]). -> noError -%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]). -> {badValue, 2} -%% snmp_test_mgr:s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]). -> {genErr, 1} -%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]). -> {genErr, 1} -%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]). -> {genErr, 1} -%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]). -> {genErr, 2} -%% Req. Klas3, Klas4 -undo_test() -> - s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), - ?line expect(1, [{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), - s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]), - ?line expect(2, ?v1_2(badValue, inconsistentValue), 2, any), - s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]), - ?line expect(3, ?v1_2(genErr, undoFailed), 1, any), - s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]), - ?line expect(4, ?v1_2(genErr, commitFailed), 1, any), - %% unfortunatly we don't know if we'll get undoFailed or commitFailed. - %% it depends on which order the agent traverses the varbind list. - %% s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]), - %% ?line expect(5, ?v1_2(genErr, undoFailed), 1, any), - s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]), - ?line expect(6, genErr, 2, any). - -%% Req. Klas3, Klas4 -bad_return() -> - g([[fStatus4,4], - [fName4,4]]), - ?line expect(4, genErr, 2, any), - g([[fStatus4,5], - [fName4,5]]), - ?line expect(5, genErr, 1, any), - g([[fStatus4,6], - [fName4,6]]), - ?line expect(6, genErr, 2, any), - gn([[fStatus4,7], - [fName4,7]]), - ?line expect(7, genErr, 2, any), - gn([[fStatus4,8], - [fName4,8]]), - ?line expect(8, genErr, 1, any), - gn([[fStatus4,9], - [fName4,9]]), - ?line expect(9, genErr, 2, any). - - -%% -- standard_mibs -- - -%%%----------------------------------------------------------------- -%%% Test the implementation of standard mibs. -%%% We should *at least* try to GET all variables, just to make -%%% sure the instrumentation functions work. -%%% Note that many of the functions in the standard mib is -%%% already tested by the normal tests. -%%%----------------------------------------------------------------- -standard_mibs(suite) -> - [snmp_standard_mib, - snmp_community_mib, - snmp_framework_mib, - snmp_target_mib, - snmp_notification_mib, - snmp_view_based_acm_mib]. - - -%% -- snmp_standard_mib -- - -%%----------------------------------------------------------------- -%% For this test, the agent is configured for v1. -%% o Test the counters and control objects in SNMP-STANDARD-MIB -%%----------------------------------------------------------------- -snmp_standard_mib(suite) -> []; -snmp_standard_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?DBG("snmp_standard_mib -> std_mib_init", []), - ?TRY_TEST1(std_mib_init), - - ?DBG("snmp_standard_mib -> std_mib_a", []), - InBadVsns = ?TRY_TEST1(std_mib_a), - put(vsn, v2), - ?DBG("snmp_standard_mib -> std_mib_read", []), - ?TRY_TEST1(std_mib_read), - put(vsn, v1), - - ?DBG("snmp_standard_mib -> std_mib_b (~w)", [InBadVsns]), - Bad = ?TRY_TEST2(std_mib_b, [InBadVsns]), - ?DBG("snmp_standard_mib -> std_mib_read (community: 'bad community')", []), - ?TRY_TEST3(std_mib_read, [], [{community, "bad community"}]), - ?DBG("snmp_standard_mib -> std_mib_write (community: 'public')", []), - ?TRY_TEST3(std_mib_write, [], [{community, "public"}]), - ?DBG("snmp_standard_mib -> std_mib_asn_err", []), - ?TRY_TEST1(std_mib_asn_err), - ?DBG("snmp_standard_mib -> std_mib_c (~w)", [Bad]), - ?TRY_TEST2(std_mib_c, [Bad]), - ?DBG("snmp_standard_mib -> std_mib_a", []), - ?TRY_TEST1(standard_mib_a), - - ?DBG("snmp_standard_mib -> std_mib_finish", []), - ?TRY_TEST1(std_mib_finish), - ?DBG("snmp_standard_mib -> std_mib_test_finish", []), - ?TRY_TEST3(standard_mib_test_finish, [], [{community, "bad community"}]). - -%% Req. SNMP-STANDARD-MIB -standard_mib_a() -> - ?line [OutPkts] = get_req(2, [[snmpOutPkts,0]]), - ?line [OutPkts2] = get_req(3, [[snmpOutPkts,0]]), - ?line OutPkts2 = OutPkts + 1, - %% There are some more counters we could test here, but it's not that - %% important, since they are removed from SNMPv2-MIB. - ok. - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_init() -> - %% disable authentication failure traps. (otherwise w'd get many of - %% them - this is also a test to see that it works). - s([{[snmpEnableAuthenTraps,0], 2}]), - ?line expect(1, [{[snmpEnableAuthenTraps, 0], 2}]). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_finish() -> - %% enable again - s([{[snmpEnableAuthenTraps,0], 1}]), - ?line expect(1, [{[snmpEnableAuthenTraps, 0], 1}]). - -%% Req. SNMP-STANDARD-MIB -standard_mib_test_finish() -> - %% force a authenticationFailure - std_mib_write(), - %% check that we got a trap - ?line expect(2, trap, [1,2,3], 4, 0, []). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_read() -> - ?DBG("std_mib_read -> entry", []), - g([[sysUpTime,0]]), % try a bad ; msg dropped, no reply - ?DBG("std_mib_read -> await timeout (i.e. no reply)", []), - ?line expect(1, timeout). % make sure we don't get a trap! - - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_write() -> - ?DBG("std_mib_write -> entry", []), - s([{[sysLocation, 0], "new_value"}]). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_asn_err() -> - ?SEND_BYTES([48,99,67,12,0,0,0,0,0,0,5]). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_a() -> - ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), - ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), - ?line InPkts2 = InPkts + 1, - - ?line [InBadVsns] = get_req(4, [[snmpInBadVersions,0]]), - InBadVsns. - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_b(InBadVsns) -> - ?line [InBadVsns2] = get_req(1, [[snmpInBadVersions,0]]), - ?line InBadVsns2 = InBadVsns + 1, - ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), - ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), - ?line InPkts2 = InPkts + 1, - ?line [InBadCommunityNames, InBadCommunityUses, InASNErrs] = - get_req(4, [[snmpInBadCommunityNames,0], - [snmpInBadCommunityUses,0], - [snmpInASNParseErrs, 0]]), - {InBadCommunityNames, InBadCommunityUses, InASNErrs}. - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_c({InBadCommunityNames, InBadCommunityUses, InASNErrs}) -> - ?line [InBadCommunityNames2, InBadCommunityUses2, InASNErrs2] = - get_req(1, [[snmpInBadCommunityNames,0], - [snmpInBadCommunityUses,0], - [snmpInASNParseErrs, 0]]), - ?line InBadCommunityNames2 = InBadCommunityNames + 1, - ?line InBadCommunityUses2 = InBadCommunityUses + 1, - ?line InASNErrs2 = InASNErrs + 1. - - -%% -- snmp_community_mib -- - -%%----------------------------------------------------------------- -%% o Bad community uses/name is tested already -%% in SNMPv2-MIB and STANDARD-MIB. -%% o Test add/deletion of rows. -%%----------------------------------------------------------------- -snmp_community_mib(suite) -> []; -snmp_community_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?TRY_TEST1(snmp_community_mib), - ?line unload_master("SNMP-COMMUNITY-MIB"). - -snmp_community_mib_2(X) -> snmp_community_mib(X). - -%% Req. SNMP-COMMUNITY-MIB -snmp_community_mib() -> - ?INF("NOT YET IMPLEMENTED", []), - nyi. - - -%% -- snmp_framework_mib -- - -%%----------------------------------------------------------------- -%% o Test engine boots / time -%%----------------------------------------------------------------- -snmp_framework_mib(suite) -> []; -snmp_framework_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?TRY_TEST1(snmp_framework_mib), - ?line unload_master("SNMP-FRAMEWORK-MIB"). - -%% Req. SNMP-FRAMEWORK-MIB -snmp_framework_mib() -> - ?line ["agentEngine"] = get_req(1, [[snmpEngineID,0]]), - ?line [EngineTime] = get_req(2, [[snmpEngineTime,0]]), - sleep(5000), - ?line [EngineTime2] = get_req(3, [[snmpEngineTime,0]]), - if - EngineTime+7 < EngineTime2 -> - ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); - EngineTime+4 > EngineTime2 -> - ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); - true -> ok - end, - ?line case get_req(4, [[snmpEngineBoots,0]]) of - [Boots] when integer(Boots) -> ok; - Else -> ?FAIL(Else) - end, - ok. - - -%% -- snmp_target_mib -- - -snmp_target_mib(suite) -> []; -snmp_target_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-TARGET-MIB"), - ?TRY_TEST1(snmp_target_mib), - ?line unload_master("SNMP-TARGET-MIB"). - -snmp_target_mib() -> - ?INF("NOT YET IMPLEMENTED", []), - nyi. - - -%% -- snmp_notification_mib -- - -snmp_notification_mib(suite) -> []; -snmp_notification_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?TRY_TEST1(snmp_notification_mib), - ?line unload_master("SNMP-NOTIFICATION-MIB"). - -snmp_notification_mib() -> - ?INF("NOT YET IMPLEMENTED", []), - nyi. - - -%% -- snmp_view_based_acm_mib -- - -%%----------------------------------------------------------------- -%% o add/delete views and try them -%% o try boundaries -%%----------------------------------------------------------------- -snmp_view_based_acm_mib(suite) -> []; -snmp_view_based_acm_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - ?line load_master("Test2"), - snmp_view_based_acm_mib(), - ?line unload_master("Test2"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). - -snmp_view_based_acm_mib() -> - snmpa:verbosity(net_if,trace), - snmpa:verbosity(master_agent,trace), - ?LOG("start snmp_view_based_acm_mib test",[]), - %% The user "no-rights" is present in USM, and is mapped to security - %% name 'no-rights", which is not present in VACM. - %% So, we'll add rights for it, try them and delete them. - %% We'll give "no-rights" write access to tDescr.0 and read access - %% to tDescr2.0 - %% These are the options we'll use to the mgr - Opts = [{user, "no-rights"}, {community, "no-rights"}], - %% Find the valid secmodel, and one invalid secmodel. - {SecMod, InvSecMod} = - case get(vsn) of - v1 -> {?SEC_V1, ?SEC_V2C}; - v2 -> {?SEC_V2C, ?SEC_USM}; - v3 -> {?SEC_USM, ?SEC_V1} - end, - ?DBG("assign rights for 'no-rights'",[]), - ?line ?TRY_TEST3(use_no_rights, [], Opts), - - %% Now, add a mapping from "no-rights" -> "no-rights-group" - GRow1Status = [vacmSecurityToGroupStatus,[SecMod, 9,"no-rights"]], - GRow1 = - [{[vacmGroupName, [SecMod, 9,"no-rights"]], "no-rights-group"}, - {GRow1Status, ?createAndGo}], - ?DBG("set '~p'",[GRow1]), - ?line ?TRY_TEST2(do_set, [GRow1]), - - ?DBG("assign rights for 'no-rights'",[]), - ?line ?TRY_TEST3(use_no_rights, [], Opts), - - %% Create a mapping for another sec model, and make sure it dosn't - %% give us access - GRow2Status = [vacmSecurityToGroupStatus,[InvSecMod, 9,"no-rights"]], - GRow2 = [{[vacmGroupName, [InvSecMod, 9, "no-rights"]], "initial"}, - {GRow2Status, ?createAndGo}], - - ?DBG("set '~p'",[GRow2]), - ?line ?TRY_TEST2(do_set, [GRow2]), - - ?DBG("assign rights for 'no-rights'",[]), - ?line ?TRY_TEST3(use_no_rights, [], Opts), - - %% Delete that row - ?line ?TRY_TEST2(del_row, [GRow2Status]), - - RVName = "rv_name", - WVName = "wv_name", - - %% Access row - ARow1Idx = [15 | "no-rights-group"] ++ [0, ?SEC_ANY, 1], - ARow1Status = [vacmAccessStatus, ARow1Idx], - ARow1 = [{[vacmAccessContextMatch, ARow1Idx], 1}, - {[vacmAccessReadViewName, ARow1Idx], RVName}, - {[vacmAccessWriteViewName, ARow1Idx], WVName}, - {ARow1Status, ?createAndGo}], - - %% This access row would give acces, if InvSecMod was valid. - ARow2Idx = [15 | "no-rights-group"] ++ [0, InvSecMod, 1], - ARow2Status = [vacmAccessStatus, ARow2Idx], - ARow2 = [{[vacmAccessContextMatch, ARow2Idx], 1}, - {[vacmAccessReadViewName, ARow2Idx], "internet"}, - {[vacmAccessWriteViewName, ARow2Idx], "internet"}, - {ARow2Status, ?createAndGo}], - - ?line ?TRY_TEST2(do_set, [ARow2]), - - ?line ?TRY_TEST3(use_no_rights, [], Opts), - - %% Delete that row - ?line ?TRY_TEST2(del_row, [ARow2Status]), - - - %% Add valid row - ?line ?TRY_TEST2(do_set, [ARow1]), - - ?line ?TRY_TEST3(use_no_rights, [], Opts), - - %% Create the view family - VRow1Idx = mk_ln(RVName) ++ mk_ln(?xDescr), % object access - VRow2Idx = mk_ln(RVName) ++ mk_ln(?xDescr2 ++ [0]), % instance access - VRow3Idx = mk_ln(WVName) ++ mk_ln(?xDescr), % object access - VRow4Idx = mk_ln(WVName) ++ mk_ln(?xDescr ++ [0]), % instance access - VRow1Status = [vacmViewTreeFamilyStatus, VRow1Idx], - VRow2Status = [vacmViewTreeFamilyStatus, VRow2Idx], - VRow3Status = [vacmViewTreeFamilyStatus, VRow3Idx], - VRow4Status = [vacmViewTreeFamilyStatus, VRow4Idx], - - ?line ?TRY_TEST2(add_row, [VRow1Status]), - ?line ?TRY_TEST2(add_row, [VRow2Status]), - ?line ?TRY_TEST2(add_row, [VRow3Status]), - - %% We're supposed to have access now... - ?line ?TRY_TEST3(use_rights, [], Opts), - - %% Change Row3 to Row4 - ?line ?TRY_TEST2(del_row, [VRow3Status]), - ?line ?TRY_TEST2(add_row, [VRow4Status]), - - %% We should still have access... - ?line ?TRY_TEST3(use_rights, [], Opts), - - %% Delete rows - ?line ?TRY_TEST2(del_row, [GRow1Status]), - - ?line ?TRY_TEST3(use_no_rights, [], Opts), - - %% Delete rest of rows - ?line ?TRY_TEST2(del_row, [ARow1Status]), - ?line ?TRY_TEST2(del_row, [VRow1Status]), - ?line ?TRY_TEST2(del_row, [VRow2Status]), - ?line ?TRY_TEST2(del_row, [VRow4Status]), - - ?line ?TRY_TEST3(use_no_rights, [], Opts), - snmpa:verbosity(master_agent,log). - -do_set(Row) -> - s(Row), - expect(1, Row). - -add_row(RowStatus) -> - s([{RowStatus, ?createAndGo}]), - expect(1, [{RowStatus, ?createAndGo}]). - -del_row(RowStatus) -> - s([{RowStatus, ?destroy}]), - expect(1, [{RowStatus, ?destroy}]). - - - -use_no_rights() -> - g([[xDescr,0]]), - ?v1_2_3(expect(11, noSuchName, 1, any), - expect(12, [{[xDescr,0], noSuchObject}]), - expect(13, authorizationError, 1, any)), - g([[xDescr2,0]]), - ?v1_2_3(expect(21, noSuchName, 1, any), - expect(22, [{[xDescr2,0], noSuchObject}]), - expect(23, authorizationError, 1, any)), - gn([[xDescr]]), - ?v1_2_3(expect(31, noSuchName, 1, any), - expect(32, [{[xDescr], endOfMibView}]), - expect(33, authorizationError, 1, any)), - s([{[xDescr,0], "tryit"}]), - ?v1_2_3(expect(41, noSuchName, 1, any), - expect(42, noAccess, 1, any), - expect(43, authorizationError, 1, any)). - - -use_rights() -> - g([[xDescr,0]]), - expect(1, [{[xDescr,0], any}]), - g([[xDescr2,0]]), - expect(2, [{[xDescr2,0], any}]), - s([{[xDescr,0], "tryit"}]), - expect(3, noError, 0, any), - g([[xDescr,0]]), - expect(4, [{[xDescr,0], "tryit"}]). - - -%% -- sparse_table -- - -sparse_table(suite) -> []; -sparse_table(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = ?INIT_CASE(Config), - - ?line load_master("Test1"), - ?TRY_TEST1(sparse_table_test), - ?line unload_master("Test1"). - -%% Req. Test1 -sparse_table_test() -> - p("Testing sparse table..."), - - %% Create two rows, check that they are get-nexted in correct order. - Idx1 = 1, - Idx2 = 2, - s([{[sparseStatus, Idx1], i, ?createAndGo}, - {[sparseDescr, Idx1], s, "row 1"}]), - ?line expect(1, [{[sparseStatus, Idx1], ?createAndGo}, - {[sparseDescr, Idx1], "row 1"}]), - s([{[sparseStatus, Idx2], i, ?createAndGo}, - {[sparseDescr, Idx2], s, "row 2"}]), - ?line expect(2, [{[sparseStatus, Idx2], ?createAndGo}, - {[sparseDescr, Idx2], "row 2"}]), - ?v1_2(gn([[sparseIndex], [sparseDescr,Idx1], [sparseDescr,Idx2], - [sparseStatus,Idx1], [sparseStatus,Idx2]]), - gb(0,5,[[sparseIndex]])), - ?line expect(3, [{[sparseDescr,Idx1], "row 1"}, - {[sparseDescr,Idx2], "row 2"}, - {[sparseStatus,Idx1], ?active}, - {[sparseStatus,Idx2], ?active}, - {[sparseStr,0], "slut"}]), - % Delete the rows - s([{[sparseStatus, Idx1], i, ?destroy}]), - ?line expect(4, [{[sparseStatus, Idx1], ?destroy}]), - s([{[sparseStatus, Idx2], i, ?destroy}]), - ?line expect(5, [{[sparseStatus, Idx2], ?destroy}]). - - -%% -- cnt_64 -- - -cnt_64(suite) -> []; -cnt_64(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = ?INIT_CASE(Config), - MA = whereis(snmp_master_agent), - - ?line load_master("Test1"), - ?TRY_TEST2(cnt_64_test, [MA]), - ?line unload_master("Test1"). - -%% Req. Test1 -cnt_64_test(MA) -> - ?LOG("start cnt64 test (~p)",[MA]), - snmpa:verbosity(MA,trace), - ?LOG("start cnt64 test",[]), - p("Testing Counter64, and at the same time, RowStatus is not last column"), - - ?DBG("get cnt64",[]), - g([[cnt64,0]]), - ?DBG("await response",[]), - ?line ?v1_2(expect(1, noSuchName, 1, any), - expect(1, [{[cnt64,0],18446744073709551615}])), - ?DBG("get-next cnt64",[]), - gn([[cnt64]]), - ?DBG("await response",[]), - ?line ?v1_2(expect(2, [{[cnt64Str,0], "after cnt64"}]), - expect(2, [{[cnt64,0],18446744073709551615}])), - ?DBG("send cntTrap",[]), - snmpa:send_trap(MA,cntTrap,"standard trap",[{sysContact,"pelle"}, - {cnt64, 10}, - {sysLocation, "here"}]), - ?DBG("await response",[]), - ?line ?v1_2(expect(3, trap, [test], 6, 1, [{[sysContact,0], "pelle"}, - {[sysLocation,0], "here"}]), - expect(3, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?testTrap ++ [1]}, - {[sysContact,0], "pelle"}, - {[cnt64,0], 10}, - {[sysLocation,0], "here"}])), - - %% Create two rows, check that they are get-nexted in correct order. - Idx1 = 1, - Idx2 = 2, - ?DBG("create row (cntStatus): ~p",[Idx1]), - s([{[cntStatus, Idx1], i, ?createAndGo}]), - ?DBG("await response",[]), - ?line expect(1, [{[cntStatus, Idx1], ?createAndGo}]), - ?DBG("create row (cntStatus): ~p",[Idx2]), - s([{[cntStatus, Idx2], i, ?createAndGo}]), - ?DBG("await response",[]), - ?line expect(2, [{[cntStatus, Idx2], ?createAndGo}]), - - ?DBG("get-next (cntIndex)",[]), - gn([[cntIndex]]), - ?DBG("await response",[]), - ?line ?v1_2(expect(3, [{[cntStatus,Idx1], ?active}]), - expect(3, [{[cntCnt,Idx1], 0}])), - % Delete the rows - ?DBG("delete row (cntStatus): ~p",[Idx1]), - s([{[cntStatus, Idx1], i, ?destroy}]), - ?DBG("await response",[]), - ?line expect(4, [{[cntStatus, Idx1], ?destroy}]), - ?DBG("delete row (cntStatus): ~p",[Idx2]), - s([{[cntStatus, Idx2], i, ?destroy}]), - ?DBG("await response",[]), - ?line expect(5, [{[cntStatus, Idx2], ?destroy}]), - catch snmpa:verbosity(MA,log), - ?DBG("done",[]), - ok. - - -%% -- opaque -- - -opaque(suite) -> []; -opaque(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = ?INIT_CASE(Config), - - ?line load_master("Test1"), - ?TRY_TEST1(opaque_test), - ?line unload_master("Test1"). - -%% Req. Test1 -opaque_test() -> - p("Testing Opaque datatype..."), - g([[opaqueObj,0]]), - ?line expect(1, [{[opaqueObj,0], "opaque-data"}]). - - -%% -- change_target_addr_config -- - -change_target_addr_config(suite) -> []; -change_target_addr_config(Config) when list(Config) -> - p("Testing changing target address config..."), - ?LOG("change_target_addr_config -> entry",[]), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - put(sname,snmp_suite), - put(verbosity,trace), - - MA = whereis(snmp_master_agent), - - ?LOG("change_target_addr_config -> load TestTrap",[]), - ?line load_master("TestTrap"), - - ?LOG("change_target_addr_config -> set trace verbosity for local_db",[]), - ?line snmpa:verbosity(local_db,trace), - - %% First send some traps that will arive att the original manager - ?LOG("change_target_addr_config -> send trap",[]), - ?TRY_TEST2(ma_trap1, [MA]), - - ?LOG("change_target_addr_config -> set silence verbosity for local_db",[]), - ?line snmpa:verbosity(local_db,silence), - - %% Start new dummy listener - ?LOG("change_target_addr_config -> start dummy manager",[]), - ?line {ok,Pid,NewPort} = dummy_manager_start(MA), - - %% Reconfigure - ?LOG("change_target_addr_config -> reconfigure",[]), - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_addr_conf(AgentDir, NewPort), - ?line snmp_target_mib:reconfigure(AgentDir), - - %% Send the trap again - ?LOG("change_target_addr_config -> send trap again",[]), - catch dummy_manager_send_trap2(Pid), - - ?LOG("change_target_addr_config -> await trap ack",[]), - catch dummy_manager_await_trap2_ack(), - - ?LOG("change_target_addr_config -> stop dummy manager",[]), - ?line ok = dummy_manager_stop(Pid), - - ?LOG("change_target_addr_config -> reset target address config",[]), - ?line reset_target_addr_conf(AgentDir), - - ?LOG("change_target_addr_config -> unload TestTrap",[]), - ?line unload_master("TestTrap"). - - -dummy_manager_start(MA) -> - ?DBG("dummy_manager_start -> entry",[]), - Pid = spawn(get(mgr_node), ?MODULE,dummy_manager_init,[self(),MA]), - ?DBG("dummy_manager_start -> Pid: ~p",[Pid]), - await_dummy_manager_started(Pid). - -await_dummy_manager_started(Pid) -> - receive - {dummy_manager_started,Pid,Port} -> - ?DBG("dummy_manager_start -> acknowledge received with" - "~n Port: ~p",[Port]), - {ok,Pid,Port}; - {'EXIT', Pid, Reason} -> - {error, Pid, Reason}; - O -> - ?LOG("dummy_manager_start -> received unknown message:" - "~n ~p",[O]), - await_dummy_manager_started(Pid) - end. - -dummy_manager_stop(Pid) -> - ?DBG("dummy_manager_stop -> entry with Pid: ~p",[Pid]), - Pid ! stop, - receive - {dummy_manager_stopping, Pid} -> - ?DBG("dummy_manager_stop -> acknowledge received",[]), - ok - after 10000 -> - ?ERR("dummy_manager_stop -> timeout",[]), - timeout - end. - -dummy_manager_send_trap2(Pid) -> - ?DBG("dummy_manager_send_trap2 -> entry",[]), - Pid ! {send_trap,testTrap2}. - -dummy_manager_await_trap2_ack() -> - ?DBG("dummy_manager_await_trap2 -> entry",[]), - receive - {received_trap,Trap} -> - ?LOG("dummy_manager_await_trap2 -> received trap: ~p",[Trap]), - %% Note: - %% Without this sleep the v2_inform_i testcase failes! There - %% is no relation between these two test cases as far as I - %% able to figure out... - sleep(60000), - ok; - O -> - ?ERR("dummy_manager_await_trap2 -> unexpected message: ~p",[O]), - ok - after 10000 -> - ?ERR("dummy_manager_await_trap2 -> timeout",[]), - timeout - end. - -dummy_manager_init(Parent,MA) -> - ?DBG("dummy_manager_init -> entry with" - "~n Parent: ~p" - "~n MA: ~p",[Parent,MA]), - {ok,S} = gen_udp:open(0,[{recbuf,65535}]), - ?DBG("dummy_manager_init -> S: ~p",[S]), - {ok,Port} = inet:port(S), - ?DBG("dummy_manager_init -> Port: ~p",[Port]), - Parent ! {dummy_manager_started,self(),Port}, - dummy_manager_loop(Parent,S,MA). - -dummy_manager_loop(P,S,MA) -> - ?LOG("dummy_manager_loop -> ready for receive",[]), - receive - {send_trap,Trap} -> - ?LOG("dummy_manager_loop -> received trap send request" - "~n Trap: ~p",[Trap]), - snmpa:send_trap(MA, Trap, "standard trap"), - dummy_manager_loop(P,S,MA); - {udp, _UdpId, Ip, UdpPort, Bytes} -> - ?LOG("dummy_manager_loop -> received upd message" - "~n from: ~p:~p" - "~n size: ~p", - [Ip, UdpPort, dummy_manager_message_sz(Bytes)]), - R = dummy_manager_handle_message(Bytes), - ?DBG("dummy_manager_loop -> R: ~p",[R]), - P ! R, - dummy_manager_loop(P,S,MA); - stop -> - ?DBG("dummy_manager_loop -> received stop request",[]), - P ! {dummy_manager_stopping, self()}, - gen_udp:close(S), - exit(normal); - O -> - ?LOG("dummy_manager_loop -> received unknown message:" - "~n ~p",[O]), - dummy_manager_loop(P,S,MA) - end. - -dummy_manager_message_sz(B) when binary(B) -> - size(B); -dummy_manager_message_sz(L) when list(L) -> - length(L); -dummy_manager_message_sz(_) -> - undefined. - -dummy_manager_handle_message(Bytes) -> - case (catch snmp_pdus:dec_message(Bytes)) of - {'EXIT',Reason} -> - ?ERR("dummy_manager_handle_message -> " - "failed decoding message only:~n ~p",[Reason]), - {error,Reason}; - M -> - ?DBG("dummy_manager_handle_message -> decoded message:" - "~n ~p",[M]), - {received_trap,M} - end. - - -%% -- reported_bugs -- - -%%%----------------------------------------------------------------- -%%% Testing of reported bugs and other tickets. -%%%----------------------------------------------------------------- - -reported_bugs(suite) -> - [otp_1128, otp_1129, otp_1131, otp_1162, - otp_1222, otp_1298, otp_1331, otp_1338, - otp_1342, otp_2776, otp_2979, otp_3187, otp_3725]. - -%%----------------------------------------------------------------- -%% Ticket: OTP-1128 -%% Slogan: Bug in handling of createAndWait set-requests. -%%----------------------------------------------------------------- -otp_1128(suite) -> []; -otp_1128(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - ?TRY_TEST1(otp_1128), - ?line unload_master("OLD-SNMPEA-MIB"). - -otp_1128() -> - io:format("Testing bug reported in ticket OTP-1128...~n"), - - NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], - NewKeyc4 = [intCommunityAccess,get(mip),is("test")], - NewKeyc5 = [intCommunityStatus,get(mip),is("test")], - - s([{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), - ?line expect(28, [{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), - g([NewKeyc5]), - ?line expect(29, [{NewKeyc5, ?notReady}]), - s([{NewKeyc5, ?active}, {NewKeyc3, 2}]), - ?line expect(30, [{NewKeyc5, ?active}, {NewKeyc3, 2}]), - g([NewKeyc5]), - ?line expect(31, [{NewKeyc5, ?active}]), - s([{NewKeyc5, ?destroy}]), - ?line expect(32, [{NewKeyc5, ?destroy}]). - -%%----------------------------------------------------------------- -%% Ticket: OTP-1129, OTP-1169 -%% Slogan: snmpa:int_to_enum crashes on bad oids -%%----------------------------------------------------------------- -otp_1129(suite) -> []; -otp_1129(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas3"), - ?TRY_TEST2(otp_1129_i, [node()]), - ?line unload_master("Klas3"). - -otp_1129_i(MaNode) -> - io:format("Testing bug reported in ticket OTP-1129...~n"), - false = rpc:call(MaNode, snmp, int_to_enum, [iso, 1]), - false = rpc:call(MaNode, snmp, int_to_enum, [isox, 1]). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1131 -%% Slogan: Agent crashes / erlang node halts if RowIndex in a -%% setrequest is of bad type, e.g. an INDEX {INTEGER}, -%% and RowIdenx [3,2]. -%%----------------------------------------------------------------- -otp_1131(suite) -> []; -otp_1131(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas1"), - ?TRY_TEST1(otp_1131), - ?line unload_master("Klas1"). - -otp_1131() -> - io:format("Testing bug reported in ticket OTP-1131...~n"), - s([{[friendsEntry, [2, 3, 1]], s, "kompis3"}, - {[friendsEntry, [3, 3, 1]], i, ?createAndGo}]), - ?line expect(1, ?v1_2(noSuchName, noCreation), 2, any). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1162 -%% Slogan: snmp_agent can't handle wrongValue from instrum.func -%%----------------------------------------------------------------- -otp_1162(suite) -> []; -otp_1162(Config) when list(Config) -> - ?P1(otp_1162), - {SaNode, _MgrNode, _MibDir} = ?INIT_CASE(Config), - ?line {ok, SA} = ?START_SA(SaNode, ?sa, "SA-MIB"), - ?TRY_TEST1(otp_1162), - ?STOP_SA(SA). - -otp_1162() -> - s([{[sa, [2,0]], 6}]), % wrongValue (i is_set_ok) - ?line expect(1, ?v1_2(badValue, wrongValue), 1, any). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1222 -%% Slogan: snmp agent crash if faulty index is returned from instrum -%%----------------------------------------------------------------- -otp_1222(suite) -> []; -otp_1222(Config) when list(Config) -> - ?P1(otp_1222), - ?INIT_CASE(Config), - ?line load_master("Klas3"), - ?line load_master("Klas4"), - ?TRY_TEST1(otp_1222), - ?line unload_master("Klas3"), - ?line unload_master("Klas4"). - -otp_1222() -> - io:format("Testing bug reported in ticket OTP-1222...~n"), - s([{[fStatus4,1], 4}, {[fName4,1], 1}]), - ?line expect(1, genErr, 0, any), - s([{[fStatus4,2], 4}, {[fName4,2], 1}]), - ?line expect(2, genErr, 0, any). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1298 -%% Slogan: Negative INTEGER values are treated as positive. -%%----------------------------------------------------------------- -otp_1298(suite) -> []; -otp_1298(Config) when list(Config) -> - ?P1(otp_1298), - ?INIT_CASE(Config), - ?line load_master("Klas2"), - ?TRY_TEST1(otp_1298), - ?line unload_master("Klas2"). - -otp_1298() -> - io:format("Testing bug reported in ticket OTP-1298...~n"), - s([{[fint,0], -1}]), - ?line expect(1298, [{[fint,0], -1}]). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1331 -%% Slogan: snmp_generic should return noError when deleting non-ex row -%%----------------------------------------------------------------- -otp_1331(suite) -> []; -otp_1331(Config) when list(Config) -> - ?P1(otp_1331), - ?INIT_CASE(Config), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - ?TRY_TEST1(otp_1331), - ?line unload_master("OLD-SNMPEA-MIB"). - -otp_1331() -> - NewKeyc5 = [intCommunityStatus,[127,32,0,0],is("test")], - s([{NewKeyc5, ?destroy}]), - ?line expect(1, [{NewKeyc5, ?destroy}]). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1338 -%% Slogan: snmp bug in initialisation of default values for mnesia tabs -%%----------------------------------------------------------------- -otp_1338(suite) -> []; -otp_1338(Config) when list(Config) -> - ?P1(otp_1338), - ?INIT_CASE(Config), - ?line load_master("Klas2"), - ?TRY_TEST1(otp_1338), - ?line unload_master("Klas2"). - -otp_1338() -> - s([{[kStatus2, 7], i, ?createAndGo}]), - ?line expect(1, [{[kStatus2, 7], ?createAndGo}]), - g([[kName2, 7]]), - ?line expect(2, [{[kName2, 7], "JJJ"}]). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1342 -%% Slogan: default impl of snmp table can't handle bad index access, -%% Set when INDEX is read-write gets into an infinite loop! -%%----------------------------------------------------------------- -otp_1342(suite) -> []; -otp_1342(Config) when list(Config) -> - ?P1(otp_1342), - ?INIT_CASE(Config), - ?line load_master("Klas4"), - ?TRY_TEST1(otp_1342), - ?line unload_master("Klas4"). - -otp_1342() -> - s([{[fIndex5, 1], i, 1}, - {[fName5, 1], i, 3}, - {[fStatus5, 1], i, ?createAndGo}]), - ?line expect(1, ?v1_2(noSuchName, noCreation), 3, any). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1366 -%% Slogan: snmp traps not sent to all managers -%% Note: NYI! We need a way to tell the test server that we need -%% mgrs on two different machines. -%%----------------------------------------------------------------- -otp_1366(suite) -> []; -otp_1366(Config) when list(Config) -> - ?P1(otp_1366), - ?INIT_CASE(Config), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - ?TRY_TEST1(otp_1366), - ?line unload_master("OLD-SNMPEA-MIB"). - -otp_1366() -> - ?INF("NOT YET IMPLEMENTED", []), - 'NYI'. - - -%%----------------------------------------------------------------- -%% Ticket: OTP-2776 -%% Slogan: snmp:validate_date_and_time() fails when time is 00:00 -%%----------------------------------------------------------------- -otp_2776(suite) -> []; -otp_2776(Config) when list(Config) -> - ?P1(otp_2776), - ?INIT_CASE(Config), - ?TRY_TEST1(otp_2776). - -otp_2776() -> - io:format("Testing bug reported in ticket OTP-2776...~n"), - - Dt01_valid = [19,98,9,1,1,0,23,0,43,0,0], - Dt02_valid = [19,98,9,1,0,0,0,0,43,0,0], % This is what is fixed: 00:00 - Dt03_valid = [19,98,2,28,1,0,23,0,43,0,0], - Dt04_invalid = [19,98,2,29,1,0,23,0,43,0,0], - Dt05_valid = [19,96,2,29,1,0,23,0,43,0,0], - Dt06_valid = [20,0,2,29,1,0,23,0,43,0,0], - Dt07_invalid = [19,96,2,30,1,0,23,0,43,0,0], % This is also fixed: 30/2 - Dt08_valid = [19,98,4,30,1,0,23,0,43,0,0], - Dt09_invalid = [19,98,4,31,1,0,23,0,43,0,0], % This is also fixed: 31/4 - Dt10_invalid = [], - Dt11_invalid = [kalle,hobbe], - L = [{ 1, true, Dt01_valid}, - { 2, true, Dt02_valid}, - { 3, true, Dt03_valid}, - { 4, false, Dt04_invalid}, - { 5, true, Dt05_valid}, - { 6, true, Dt06_valid}, - { 7, false, Dt07_invalid}, - { 8, true, Dt08_valid}, - { 9, false, Dt09_invalid}, - {10, false, Dt10_invalid}, - {11, false, Dt11_invalid}], - - ?line ok = validate_dat(L). - - -validate_dat(L) -> validate_dat(L,[]). - -validate_dat([],V) -> - Fun = fun({_,X}) -> case X of - ok -> false; - _ -> true - end - end, - validate_dat1( lists:reverse( lists:filter(Fun,V) ) ); -validate_dat([{Id,E,Dat}|T],V) -> - validate_dat(T,[validate_dat2(Id,E,Dat) | V]). - -validate_dat1([]) -> ok; -validate_dat1(L) -> {error,L}. - -validate_dat2(Id, E, Dat) -> - Res = case {E,snmp:validate_date_and_time(Dat)} of - {E,E} -> ok; - {E,A} -> {E,A} - end, - {Id, Res}. - - -%%----------------------------------------------------------------- -%% Ticket: OTP-2979 -%% Slogan: get-next on more than 1 column in an empty table -%% returns bad response. -%%----------------------------------------------------------------- -otp_2979(suite) -> []; -otp_2979(Config) when list(Config) -> - ?P1(otp_2979), - ?INIT_CASE(Config), - ?line load_master("Test1"), - ?line init_old(), - ?TRY_TEST1(otp_2979), - ?line unload_master("Test1"). - -otp_2979() -> - gn([[sparseDescr], [sparseStatus]]), - ?line expect(1, [{[sparseStr,0], "slut"}, - {[sparseStr,0], "slut"}]). - -%%----------------------------------------------------------------- -%% Ticket: OTP-3187 -%% Slogan: get-next on vacmAccessTable for colums > 5 returns -%% endOfTable - should return value. -%%----------------------------------------------------------------- -otp_3187(suite) -> []; -otp_3187(Config) when list(Config) -> - ?P1(otp_3187), - ?INIT_CASE(Config), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - otp_3187(), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). - -otp_3187() -> - ?line Elements = - snmp_view_based_acm_mib:vacmAccessTable(get_next,[],[4,5,6]), - lists:foreach(fun(E) -> - ?line if E == endOfTable -> - ?FAIL(endOfTable); - true -> ok - end - end, Elements). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-3542 -%% Slogan: -%%----------------------------------------------------------------- -otp_3542(suite) -> []; -otp_3542(Config) when list(Config) -> - ?P1(otp_3542), - ?INIT_CASE(Config), - ?TRY_TEST1(otp_3542). - -otp_3542() -> - io:format("SNMP v3 discovery...~n"), - ?line Res = snmp_test_mgr:d(), - io:format("SNMP v3 discovery result: ~p~n",[Res]). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-3725 -%% Slogan: Slow response time on snmpa:int_to_enum -%%----------------------------------------------------------------- -otp_3725(suite) -> []; -otp_3725(Config) when list(Config) -> - ?P1(otp_3725), - ?INIT_CASE(Config), - - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - ?TRY_TEST2(otp_3725_test, [node()]), - ?line unload_master("OLD-SNMPEA-MIB"). - -%% Req. OLD-SNMPEA-MIB -otp_3725_test(MaNode) -> - io:format("Testing feature requested in ticket OTP-3725...~n"), - ?line rpc:call(MaNode,snmpa,verbosity,[symbolic_store,trace]), - ?line Db = rpc:call(MaNode,snmp,get_symbolic_store_db,[]), - ?DBG("otp_3725_test -> Db = ~p",[Db]), - - ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, - [Db, intAgentIpAddress]), - ?DBG("otp_3725_test -> name_to_oid for ~p: ~p",[intAgentIpAddress,OID]), - ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, oid_to_name, - [Db,OID]), - ?DBG("otp_3725_test -> oid_to_name for ~p: ~p",[OID,intAgentIpAddress]), - ?line false = rpc:call(MaNode, snmp, name_to_oid, [Db, intAgentIpAddres]), - ?line false = rpc:call(MaNode, snmp, oid_to_name, - [Db, [1,5,32,3,54,3,3,34,4]]), - ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, - [Db, intViewType, excluded]), - ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, - [Db, intViewType, 2]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, intViewType, exclude]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, intAgentIpAddress, exclude]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, intAgentIpAddre, exclude]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, intViewType, 3]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, - [Db, intAgentIpAddress, 2]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, - [Db, intAgentIpAddre, 2]), - ?line {value, active} = rpc:call(MaNode, snmp, int_to_enum, - [Db, 'RowStatus', ?active]), - ?line {value, ?destroy} = rpc:call(MaNode, snmp, enum_to_int, - [Db, 'RowStatus', destroy]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, 'RowStatus', xxxdestroy]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, 'xxRowStatus', destroy]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'RowStatus', 25]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'xxRowStatus', 1]), - ok. - - -%% -- tickets -- - -%% These are (ticket) test cases where the initiation has to be done -%% individually. -tickets(suite) -> - [otp_4394]. - - -%%----------------------------------------------------------------- -%% Ticket: OTP-4394 -%% Slogan: Target mib tag list check invalid -%%----------------------------------------------------------------- - -otp_4394(suite) -> {req, [], {conf, - init_otp_4394, - [otp_4394_test], - finish_otp_4394}}. - -init_otp_4394(Config) when list(Config) -> - ?DBG("init_otp_4394 -> entry with" - "~n Config: ~p", [Config]), - ?line AgentDir = ?config(agent_dir, Config), - ?line MgrDir = ?config(mgr_dir, Config), - ?line Ip = ?config(ip, Config), - ?line otp_4394_config(AgentDir, MgrDir, Ip), - MasterAgentVerbosity = {master_agent_verbosity, trace}, - NetIfVerbosity = {net_if_verbosity, trace}, - Opts = [MasterAgentVerbosity,NetIfVerbosity], - [{vsn, v1} | start_v1_agent(Config,Opts)]. - -otp_4394_config(AgentDir, MgrDir, Ip0) -> - ?DBG("otp_4394_config -> entry with" - "~n AgentDir: ~p" - "~n MgrDir: ~p" - "~n Ip0: ~p", [AgentDir, MgrDir, Ip0]), - Vsn = [v1], - Ip = tuple_to_list(Ip0), - ?line snmp_config:write_agent_snmp_files(AgentDir, Vsn, Ip, - ?TRAP_UDP, Ip, 4000, - "OTP-4394 test"), - ?line case update_usm(Vsn, AgentDir) of - true -> - ?line copy_file(filename:join(AgentDir, "usm.conf"), - filename:join(MgrDir, "usm.conf")), - ?line update_usm_mgr(Vsn, MgrDir); - false -> - ?line ok - end, - C1 = {"a", "all-rights", "initial", "", "pc"}, - C2 = {"c", "secret", "secret_name", "", "secret_tag"}, - ?line write_community_conf(AgentDir, [C1, C2]), - ?line update_vacm(Vsn, AgentDir), - Ta1 = {"shelob v1", - [134,138,177,177], 5000, 1500, 3, %% Använd Ip och modda - "pc1", - "target_v1", "", - %% [255,255,255,255,0,0], - [], - 2048}, - Ta2 = {"bifur v1", - [134,138,177,75], 5000, 1500, 3, %% Använd Ip - "pc2", - "target_v1", "", - %% [255,255,255,255,0,0], - [], 2048}, - ?line write_target_addr_conf(AgentDir, [Ta1, Ta2]), - ?line write_target_params_conf(AgentDir, Vsn), - ?line write_notify_conf(AgentDir), - ok. - -finish_otp_4394(Config) when list(Config) -> - ?DBG("finish_otp_4394 -> entry", []), - C1 = stop_agent(Config), - delete_files(C1), - erase(mgr_node), - lists:keydelete(vsn, 1, C1). - -otp_4394_test(suite) -> []; -otp_4394_test(Config) -> - ?P1(otp_4394_test), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?TRY_TEST1(otp_4394_test1), - ?DBG("otp_4394_test -> done", []), - ok. - -otp_4394_test1() -> - ?DBG("otp_4394_test1 -> entry", []), - gn([[1,1]]), - Res = - case snmp_test_mgr:expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]) of - %% {error, 1, {"?",[]}, {"~w",[timeout]}} - {error, 1, _, {_, [timeout]}} -> - ?DBG("otp_4394_test1 -> expected result: timeout", []), - ok; - Else -> - Else - end, - ?DBG("otp_4394_test1 -> done with: ~p", [Res]), - Res. - - -mk_ln(X) -> - [length(X) | X]. - - - -%% string used in index -is(S) -> [length(S) | S]. - -expect(A,B) -> ok = ?MGR:expect(A,B). -expect(A,B,C) -> ok = ?MGR:expect(A,B,C). -expect(A,B,C,D) -> ok = ?MGR:expect(A,B,C,D). -expect(A,B,C,D,E,F) -> ok = ?MGR:expect(A,B,C,D,E,F). - diff --git a/lib/snmp/test/snmp_agent_v2_test.erl b/lib/snmp/test/snmp_agent_v2_test.erl deleted file mode 100644 index dc94c18ad9..0000000000 --- a/lib/snmp/test/snmp_agent_v2_test.erl +++ /dev/null @@ -1,5649 +0,0 @@ -%% -%% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2005-2010. All Rights Reserved. -%% -%% The contents of this file are subject to the Erlang Public License, -%% Version 1.1, (the "License"); you may not use this file except in -%% compliance with the License. You should have received a copy of the -%% Erlang Public License along with this software. If not, it can be -%% retrieved online at http://www.erlang.org/. -%% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -%% the License for the specific language governing rights and limitations -%% under the License. -%% -%% %CopyrightEnd% -%% - --module(snmp_agent_v2_test). - -%% TODO -%% * Test fault-tolerance (kill master etc) -%% - --compile(export_all). - --define(application, snmp). - --include_lib("kernel/include/file.hrl"). --include_lib("test_server/include/test_server.hrl"). --include("snmp_test_lib.hrl"). --define(SNMP_USE_V3, true). --include_lib("snmp/include/snmp_types.hrl"). -%% -include_lib("snmp/include/SNMP-COMMUNITY-MIB.hrl"). -%% -include_lib("snmp/include/SNMP-VIEW-BASED-ACM-MIB.hrl"). -%% -include_lib("snmp/include/SNMP-USER-BASED-SM-MIB.hrl"). - - --define(klas1, [1,3,6,1,2,1,7]). --define(klas2, [1,3,6,1,2,1,9]). --define(klas3, [1,3,6,1,2,1,8,1]). --define(klas4, [1,3,6,1,2,1,8,4]). --define(sa, [1,3,6,1,4,1,193,2]). --define(system, [1,3,6,1,2,1,1]). --define(snmp, [1,3,6,1,2,1,11]). --define(snmpTraps, [1,3,6,1,6,3,1,1,5]). --define(ericsson, [1,3,6,1,4,1,193]). --define(testTrap, [1,3,6,1,2,1,15,0]). --define(xDescr, [1,3,6,1,2,1,17,1]). --define(xDescr2, [1,3,6,1,2,1,17,2]). - --define(active, 1). --define(notInService, 2). --define(notReady, 3). --define(createAndGo, 4). --define(createAndWait, 5). --define(destroy, 6). - --define(TRAP_UDP, 5000). - --define(tooBigStr, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"). - --define(str(X), snmp_pdus:bits_to_str(X)). - --define(break(), begin io:format(user, "break at line ~w: pid: ~p\n", - [?LINE, self()]), - receive cont -> ok end - end). - - --import(snmp_test_mgr, [gn/1, g/1, s/1, gb/3]). --define(v1_2(V1,V2), - case get(vsn) of - v1 -> V1; - _ -> V2 - end). - --define(v1_2_3(V1,V2,V3), - case get(vsn) of - v1 -> V1; - v2 -> V2; - _ -> V3 - end). - -all() -> -[cases()]. - -groups() -> - [{mib_storage, [], - [{group, mib_storage_ets}, {group, mib_storage_dets}, - {group, mib_storage_mnesia}, - {group, mib_storage_size_check_ets}, - {group, mib_storage_size_check_dets}, - {group, mib_storage_size_check_mnesia}, - {group, mib_storage_varm_dets}, - {group, mib_storage_varm_mnesia}]}, - {mib_storage_ets, [], mib_storage_ets_cases()}, - {mib_storage_dets, [], mib_storage_dets_cases()}, - {mib_storage_mnesia, [], mib_storage_mnesia_cases()}, - {mib_storage_size_check_ets, [], - mse_size_check_cases()}, - {mib_storage_size_check_dets, [], - msd_size_check_cases()}, - {mib_storage_size_check_mnesia, [], - msm_size_check_cases()}, - {mib_storage_varm_dets, [], - varm_mib_storage_dets_cases()}, - {mib_storage_varm_mnesia, [], - varm_mib_storage_mnesia_cases()}, - {test_v1, [], v1_cases()}, {test_v2, [], v2_cases()}, - {test_v1_v2, [], v1_v2_cases()}, - {test_v3, [], v3_cases()}, - {test_multi_threaded, [], mt_cases()}, - {multiple_reqs, [], mul_cases()}, - {multiple_reqs_2, [], mul_cases_2()}, - {v2_inform, [], [v2_inform_i]}, - {v3_security, [], - [v3_crypto_basic, v3_md5_auth, v3_sha_auth, - v3_des_priv]}, - {standard_mibs, [], - [snmp_standard_mib, snmp_community_mib, - snmp_framework_mib, snmp_target_mib, - snmp_notification_mib, snmp_view_based_acm_mib]}, - {standard_mibs_2, [], - [snmpv2_mib_2, snmp_community_mib_2, - snmp_framework_mib_2, snmp_target_mib_2, - snmp_notification_mib_2, snmp_view_based_acm_mib_2]}, - {standard_mibs_3, [], - [snmpv2_mib_3, snmp_framework_mib_3, snmp_mpd_mib_3, - snmp_target_mib_3, snmp_notification_mib_3, - snmp_view_based_acm_mib_3, snmp_user_based_sm_mib_3]}, - {reported_bugs, [], - [otp_1128, otp_1129, otp_1131, otp_1162, otp_1222, - otp_1298, otp_1331, otp_1338, otp_1342, otp_2776, - otp_2979, otp_3187, otp_3725]}, - {reported_bugs_2, [], - [otp_1128_2, otp_1129_2, otp_1131_2, otp_1162_2, - otp_1222_2, otp_1298_2, otp_1331_2, otp_1338_2, - otp_1342_2, otp_2776_2, otp_2979_2, otp_3187_2]}, - {reported_bugs_3, [], - [otp_1128_3, otp_1129_3, otp_1131_3, otp_1162_3, - otp_1222_3, otp_1298_3, otp_1331_3, otp_1338_3, - otp_1342_3, otp_2776_3, otp_2979_3, otp_3187_3, - otp_3542]}, - {tickets, [], [{group, otp_4394}]}, - {otp_4394, [], [otp_4394_test]}]. - -init_per_group(otp_4394, Config) -> - init_otp_4394(Config); -init_per_group(v2_inform, Config) -> - init_v2_inform(Config); -init_per_group(multiple_reqs_2, Config) -> - init_mul(Config); -init_per_group(multiple_reqs, Config) -> - init_mul(Config); -init_per_group(test_multi_threaded, Config) -> - init_mt(Config); -init_per_group(test_v3, Config) -> - init_v3(Config); -init_per_group(test_v1_v2, Config) -> - init_v1_v2(Config); -init_per_group(test_v2, Config) -> - init_v2(Config); -init_per_group(test_v1, Config) -> - init_v1(Config); -init_per_group(mib_storage_varm_mnesia, Config) -> - init_varm_mib_storage_mnesia(Config); -init_per_group(mib_storage_varm_dets, Config) -> - init_varm_mib_storage_dets(Config); -init_per_group(mib_storage_size_check_mnesia, Config) -> - init_size_check_msm(Config); -init_per_group(mib_storage_size_check_dets, Config) -> - init_size_check_msd(Config); -init_per_group(mib_storage_size_check_ets, Config) -> - init_size_check_mse(Config); -init_per_group(mib_storage_mnesia, Config) -> - init_mib_storage_mnesia(Config); -init_per_group(mib_storage_dets, Config) -> - init_mib_storage_dets(Config); -init_per_group(mib_storage_ets, Config) -> - init_mib_storage_ets(Config); -init_per_group(_GroupName, Config) -> - Config. - -end_per_group(otp_4394, Config) -> - finish_otp_4394(Config); -end_per_group(v2_inform, Config) -> - finish_v2_inform(Config); -end_per_group(multiple_reqs_2, Config) -> - finish_mul(Config); -end_per_group(multiple_reqs, Config) -> - finish_mul(Config); -end_per_group(test_multi_threaded, Config) -> - finish_mt(Config); -end_per_group(test_v3, Config) -> - finish_v3(Config); -end_per_group(test_v1_v2, Config) -> - finish_v1_v2(Config); -end_per_group(test_v2, Config) -> - finish_v2(Config); -end_per_group(test_v1, Config) -> - finish_v1(Config); -end_per_group(mib_storage_varm_mnesia, Config) -> - finish_varm_mib_storage_mnesia(Config); -end_per_group(mib_storage_varm_dets, Config) -> - finish_varm_mib_storage_dets(Config); -end_per_group(mib_storage_size_check_mnesia, Config) -> - finish_size_check_msm(Config); -end_per_group(mib_storage_size_check_dets, Config) -> - finish_size_check_msd(Config); -end_per_group(mib_storage_size_check_ets, Config) -> - finish_size_check_mse(Config); -end_per_group(mib_storage_mnesia, Config) -> - finish_mib_storage_mnesia(Config); -end_per_group(mib_storage_dets, Config) -> - finish_mib_storage_dets(Config); -end_per_group(mib_storage_ets, Config) -> - finish_mib_storage_ets(Config); -end_per_group(_GroupName, Config) -> - Config. - - -init_per_testcase(_Case, Config) when list(Config) -> - Dog = ?t:timetrap(?t:minutes(6)), - [{watchdog, Dog}|Config]. - -end_per_testcase(_Case, Config) when list(Config) -> - Dog = ?config(watchdog, Config), - ?t:timetrap_cancel(Dog), - Config. - -cases() -> -case ?OSTYPE() of - vxworks -> - [app_info, {group, test_v1}, {group, test_v2}, - {group, test_v1_v2}, {group, test_multi_threaded}, - {group, mib_storage}, {group, tickets}]; - _Else -> - [app_info, {group, test_v1}, {group, test_v2}, - {group, test_v1_v2}, {group, test_v3}, - {group, test_multi_threaded}, {group, mib_storage}, - {group, tickets}] -end. - - -%%%----------------------------------------------------------------- -%%% The test case structure is as follows: -%%% -%%% init_all - starts mnesia, -%%% -%%% init_v1 - starts agent -%%% simple -%%% big - e.g. starts/stops subagent, load/unloads mibs -%%% init_mul -%%% mul_get -%%% mul_set -%%% -%%% finish_mul -%%% -%%% finish_v1 -%%% -%%% init_v2 - starts agent -%%% finish_v2 -%%% -%%% init_bilingual - starts agent -%%% finish_bilingual -%%% -%%% finish_all -%%% -%%% There is still one problem with these testsuites. If one test -%%% fails, it may not be possible to run some other cases, as it -%%% may have e.g. created some row or loaded some table, that it -%%% didn't undo (since it failed). -%%%----------------------------------------------------------------- - -init_all(Config0) when list(Config0) -> - ?LOG("init_all -> entry with" - "~n Config0: ~p",[Config0]), - - %% -- - %% Fix config: - %% - - DataDir0 = ?config(data_dir, Config0), - DataDir1 = filename:split(filename:absname(DataDir0)), - [_|DataDir2] = lists:reverse(DataDir1), - DataDir3 = filename:join(lists:reverse(DataDir2) ++ [?snmp_test_data]), - Config1 = lists:keydelete(data_dir, 1, Config0), - Config = [{data_dir, DataDir3 ++ "/"}|Config1], - - %% -- - %% Start nodes - %% - - ?line {ok, SaNode} = start_node(snmp_sa), - ?line {ok, MgrNode} = start_node(snmp_mgr), - - - %% -- - %% Create necessary files - %% - - Dir = ?config(priv_dir, Config), - ?DBG("init_all -> Dir ~p", [Dir]), - - DataDir = ?config(data_dir, Config), - ?DBG("init_all -> DataDir ~p", [DataDir]), - - file:make_dir(MgrDir = filename:join(Dir, "mgr_dir/")), - ?DBG("init_all -> MgrDir ~p", [MgrDir]), - - file:make_dir(AgentDir = filename:join(Dir, "agent_dir/")), - ?DBG("init_all -> AgentDir ~p", [AgentDir]), - - file:make_dir(SaDir = filename:join(Dir, "sa_dir/")), - ?DBG("init_all -> SaDir ~p", [SaDir]), - - - %% -- - %% Start and initiate mnesia - %% - - ?DBG("init_all -> load application mnesia", []), - ?line ok = application:load(mnesia), - - ?DBG("init_all -> load application mnesia on node ~p", [SaNode]), - ?line ok = rpc:call(SaNode, application, load, [mnesia]), - - ?DBG("init_all -> application mnesia: set_env dir",[]), - ?line application_controller:set_env(mnesia, dir, - filename:join(Dir, "Mnesia1")), - - ?DBG("init_all -> application mnesia: set_env dir on node ~p",[SaNode]), - ?line rpc:call(SaNode, application_controller, set_env, - [mnesia, dir, filename:join(Dir, "Mnesia2")]), - - ?DBG("init_all -> create mnesia schema",[]), - ?line ok = mnesia:create_schema([SaNode, node()]), - - ?DBG("init_all -> start application mnesia",[]), - ?line ok = application:start(mnesia), - - ?DBG("init_all -> start application mnesia on ~p",[SaNode]), - ?line ok = rpc:call(SaNode, application, start, [mnesia]), - Ip = ?LOCALHOST(), - [{snmp_sa, SaNode}, - {snmp_mgr, MgrNode}, - {agent_dir, AgentDir ++ "/"}, - {mgr_dir, MgrDir ++ "/"}, - {sa_dir, SaDir ++ "/"}, - {mib_dir, DataDir}, - {ip, Ip} | - Config]. - -finish_all(Config) when list(Config) -> - SaNode = ?config(snmp_sa, Config), - MgrNode = ?config(snmp_mgr, Config), - stop_node(SaNode), - stop_node(MgrNode), - application:stop(mnesia). - -start_v1_agent(Config) when list(Config) -> - start_agent(Config, [v1]). - -start_v1_agent(Config,Opts) when list(Config), list(Opts) -> - start_agent(Config, [v1], Opts). - -start_v2_agent(Config) when list(Config) -> - start_agent(Config, [v2]). - -start_v3_agent(Config) when list(Config) -> - start_agent(Config, [v3]). - -start_bilingual_agent(Config) when list(Config) -> - start_agent(Config, [v1,v2]). - -start_multi_threaded_agent(Config) when list(Config) -> - start_agent(Config, [v2], [{snmp_multi_threaded, true}]). - -stop_agent(Config) when list(Config) -> - ?LOG("stop_agent -> entry with" - "~n Config: ~p",[Config]), - - {Sup, Par} = ?config(snmp_sup, Config), - ?DBG("stop_agent -> attempt to stop (sup) ~p" - "~n Sup: ~p" - "~n Par: ~p", - [Sup, - (catch process_info(Sup)), - (catch process_info(Par))]), - stop_sup(Sup, Par), - - {Sup2, Par2} = ?config(snmp_sub, Config), - ?DBG("stop_agent -> attempt to stop (sub) ~p" - "~n Sup2: ~p" - "~n Par2: ~p", - [Sup2, - (catch process_info(Sup2)), - (catch process_info(Par2))]), - stop_sup(Sup2, Par2), - - ?DBG("stop_agent -> done - now cleanup config", []), - C1 = lists:keydelete(snmp_sup, 1, Config), - lists:keydelete(snmp_sub, 1, C1). - - -stop_sup(Pid, _) when node(Pid) == node() -> - case (catch process_info(Pid)) of - PI when list(PI) -> - ?LOG("stop_sup -> attempt to stop ~p", [Pid]), - Ref = erlang:monitor(process, Pid), - exit(Pid, kill), - await_stopped(Pid, Ref); - {'EXIT', _Reason} -> - ?LOG("stop_sup -> ~p not running", [Pid]), - ok - end; -stop_sup(Pid, _) -> - ?LOG("stop_sup -> attempt to stop ~p", [Pid]), - Ref = erlang:monitor(process, Pid), - ?LOG("stop_sup -> Ref: ~p", [Ref]), - %% Pid ! {'EXIT', Parent, shutdown}, % usch - exit(Pid, kill), - await_stopped(Pid, Ref). - -await_stopped(Pid, Ref) -> - receive - {'DOWN', Ref, process, Pid, _Reason} -> - ?DBG("received down message for ~p", [Pid]), - ok - after 10000 -> - ?INF("await_stopped -> timeout for ~p",[Pid]), - erlang:demonitor(Ref), - ?FAIL({failed_stop,Pid}) - end. - - -start_agent(Config, Vsn) -> - start_agent(Config, Vsn, []). -start_agent(Config, Vsn, Opts) -> - ?LOG("start_agent -> entry (~p) with" - "~n Config: ~p" - "~n Vsn: ~p" - "~n Opts: ~p",[node(), Config, Vsn, Opts]), - - ?line AgentDir = ?config(agent_dir, Config), - ?line SaNode = ?config(snmp_sa, Config), - - snmp_app_env_init(vsn_init(Vsn) ++ - [{audit_trail_log, read_write_log}, - {audit_trail_log_dir, AgentDir}, - {audit_trail_log_size, {10240, 10}}, - {force_config_reload, false}, - {snmp_agent_type, master}, - {snmp_config_dir, AgentDir}, - {snmp_db_dir, AgentDir}, - {snmp_local_db_auto_repair, true}, - {snmp_master_agent_verbosity, trace}, - {snmp_supervisor_verbosity, trace}, - {snmp_mibserver_verbosity, trace}, - {snmp_symbolic_store_verbosity, trace}, - {snmp_note_store_verbosity, trace}, - {snmp_net_if_verbosity, trace}], - Opts), - - - process_flag(trap_exit,true), - - {ok, AppSup} = snmp_app_sup:start_link(), - unlink(AppSup), - ?DBG("start_agent -> snmp app supervisor: ~p",[AppSup]), - - ?DBG("start_agent -> start master agent (old style)",[]), - Sup = case (catch snmpa_app:start(normal)) of - {ok, S} -> - ?DBG("start_agent -> started, Sup: ~p",[S]), - S; - - Else -> - ?DBG("start_agent -> unknown result: ~n~p",[Else]), - %% Get info about the apps we depend on - MnesiaInfo = mnesia_running(), - ?FAIL({start_failed,Else,MnesiaInfo}) - end, - - ?DBG("start_agent -> unlink from supervisor",[]), - ?line unlink(Sup), - ?line SaDir = ?config(sa_dir, Config), - ?DBG("start_agent -> (rpc) start sub on ~p",[SaNode]), - ?line {ok, Sub} = rpc:call(SaNode, ?MODULE, start_sub, [SaDir]), - ?DBG("start_agent -> done",[]), - ?line [{snmp_sup, {Sup, self()}}, {snmp_sub, Sub} | Config]. - - -vsn_init(Vsn) -> - vsn_init([v1,v2,v3], Vsn, []). - -vsn_init([], _Vsn, Acc) -> - Acc; -vsn_init([V|Vsns], Vsn, Acc) -> - case lists:member(V, Vsn) of - true -> - vsn_init(Vsns, Vsn, [{V, true}|Acc]); - false -> - vsn_init(Vsns, Vsn, [{V, false}|Acc]) - end. - -snmp_app_env_init(Env0, Opts) -> - ?DBG("snmp_app_env_init -> unload snmp",[]), - ?line application:unload(snmp), - ?DBG("snmp_app_env_init -> load snmp",[]), - ?line application:load(snmp), - ?DBG("snmp_app_env_init -> initiate (snmp) application env",[]), - F1 = fun({Key,Val} = New, Acc0) -> - ?DBG("snmp_app_env_init -> " - "updating setting ~p to ~p", [Key, Val]), - case lists:keyreplace(Key, 1, Acc0, New) of - Acc0 -> - [New|Acc0]; - Acc -> - Acc - end - end, - Env = lists:foldr(F1, Env0, Opts), - ?DBG("snmp_app_env_init -> Env: ~p",[Env]), - F2 = fun({Key,Val}) -> - ?DBG("snmp_app_env_init -> setting ~p to ~p",[Key, Val]), - application_controller:set_env(snmp, Key, Val) - end, - lists:foreach(F2, Env). - - - - -%% Test if application is running -mnesia_running() -> ?IS_MNESIA_RUNNING(). -crypto_running() -> ?IS_CRYPTO_RUNNING(). - - -start_sub(Dir) -> - ?DBG("start_sub -> entry",[]), - Opts = [{db_dir, Dir}, - {supervisor, [{verbosity, trace}]}], - %% BMK BMK -% {ok, P} = snmp_supervisor:start_sub(Dir), - {ok, P} = snmpa_supervisor:start_sub_sup(Opts), - unlink(P), - {ok, {P, self()}}. - -create_tables(SaNode) -> - ?line {atomic, ok} = mnesia:create_table([{name, friendsTable2}, - {ram_copies, [SaNode]}, - {snmp, [{key, integer}]}, - {attributes, [a1,a2,a3]}]), - ?line {atomic, ok} = mnesia:create_table([{name, kompissTable2}, - {ram_copies, [SaNode]}, - {snmp, [{key, integer}]}, - {attributes, [a1,a2,a3]}]), - ?line {atomic, ok} = mnesia:create_table([{name, snmp_variables}, - {attributes, [a1,a2]}]). - -delete_tables() -> - mnesia:delete_table(friendsTable2), - mnesia:delete_table(kompissTable2), - mnesia:delete_table(snmp_variables). - -%% Creation is done in runtime! -delete_mib_storage_mnesia_tables() -> - mnesia:delete_table(snmpa_mib_data), - mnesia:delete_table(snmpa_mib_tree), - mnesia:delete_table(snmpa_symbolic_store). - -%%----------------------------------------------------------------- -%% A test case is always one of: -%% - v1 specific case -%% - v2 specific case -%% - v1 and v2 case -%% All v1 specific cases are prefixed with v1_, and all v2 with -%% v2_. E.g. v1_trap/v2_trap. -%% -%% All other cases are shared. However, the testserver uses the name -%% of the case to generate a file for that case. The same case cannot -%% be used in different configurations in the same suite. Therefore -%% all these functions exists in two variants, the base function -%% , and a second version _2. There may be several -%% versions as well, _N. -%%----------------------------------------------------------------- - - - - - - - - - -mib_storage_ets_cases() -> -[mse_simple, mse_v1_processing, mse_big, mse_big2, - mse_loop_mib, mse_api, mse_sa_register, mse_v1_trap, - mse_sa_error, mse_next_across_sa, mse_undo, - mse_standard_mib, mse_community_mib, mse_framework_mib, - mse_target_mib, mse_notification_mib, - mse_view_based_acm_mib, mse_sparse_table, mse_me_of, - mse_mib_of]. - -mib_storage_dets_cases() -> -[msd_simple, msd_v1_processing, msd_big, msd_big2, - msd_loop_mib, msd_api, msd_sa_register, msd_v1_trap, - msd_sa_error, msd_next_across_sa, msd_undo, - msd_standard_mib, msd_community_mib, msd_framework_mib, - msd_target_mib, msd_notification_mib, - msd_view_based_acm_mib, msd_sparse_table, msd_me_of, - msd_mib_of]. - -mib_storage_mnesia_cases() -> -[msm_simple, msm_v1_processing, msm_big, msm_big2, - msm_loop_mib, msm_api, msm_sa_register, msm_v1_trap, - msm_sa_error, msm_next_across_sa, msm_undo, - msm_standard_mib, msm_community_mib, msm_framework_mib, - msm_target_mib, msm_notification_mib, - msm_view_based_acm_mib, msm_sparse_table, msm_me_of, - msm_mib_of]. - -mse_size_check_cases() -> -[mse_size_check]. - -msd_size_check_cases() -> -[msd_size_check]. - -msm_size_check_cases() -> -[msm_size_check]. - -varm_mib_storage_dets_cases() -> -[msd_varm_mib_start]. - -varm_mib_storage_mnesia_cases() -> -[msm_varm_mib_start]. - -init_mib_storage_ets(Config) when list(Config) -> - ?LOG("init_mib_storage_ets -> entry", []), - MibStorage = {snmp_mib_storage,ets}, - init_ms(Config, [MibStorage]). - -init_mib_storage_dets(Config) when list(Config) -> - ?LOG("init_mib_storage_ets -> entry", []), - ?line AgentDir = ?GCONF(agent_dir, Config), - MibStorage = {snmp_mib_storage,{dets,AgentDir}}, - init_ms(Config, [MibStorage]). - -init_mib_storage_mnesia(Config) when list(Config) -> - ?LOG("init_mib_storage_ets -> entry", []), - MibStorage = {snmp_mib_storage,{mnesia,[]}}, - init_ms(Config, [MibStorage]). - -init_ms(Config, Opts) when list(Config) -> - ?LOG("init_mib_storage_ets -> entry", []), - ?line SaNode = ?GCONF(snmp_sa, Config), - ?line create_tables(SaNode), - ?line AgentDir = ?GCONF(agent_dir, Config), - ?line MgrDir = ?GCONF(mgr_dir, Config), - ?line Ip = ?GCONF(ip, Config), - ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, - MibsVerbosity = {snmp_mibserver_verbosity, trace}, - SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, - Opts1 = [MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity|Opts], - [{vsn, v1} | start_v1_agent(Config,Opts1)]. - -init_size_check_mse(Config) when list(Config) -> - MibStorage = {snmp_mib_storage, ets}, - init_size_check_ms(Config, [MibStorage]). - -init_size_check_msd(Config) when list(Config) -> - AgentDir = ?GCONF(agent_dir, Config), - MibStorage = {snmp_mib_storage, {dets, AgentDir}}, - init_size_check_ms(Config, [MibStorage]). - -init_size_check_msm(Config) when list(Config) -> - MibStorage = {snmp_mib_storage, {mnesia,[]}}, - init_size_check_ms(Config, [MibStorage]). - -init_size_check_ms(Config, Opts) when list(Config) -> - SaNode = ?GCONF(snmp_sa, Config), - %% We are using v3 here, so crypto must be supported or else... - case ?CRYPTO_START() of - ok -> - case ?CRYPTO_SUPPORT() of - {no, Reason} -> - ?SKIP({unsupported_encryption, Reason}); - yes -> - ok - end; - {error, Reason} -> - ?SKIP({failed_starting_crypto, Reason}) - end, - create_tables(SaNode), - AgentDir = ?GCONF(agent_dir, Config), - MgrDir = ?GCONF(mgr_dir, Config), - Ip = ?GCONF(ip, Config), - ?line ok = - config([v3], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v3} | start_agent(Config, [v3], Opts)]. - -init_varm_mib_storage_dets(Config) when list(Config) -> - ?LOG("init_varm_mib_storage_dets -> entry", []), - ?line SaNode = ?GCONF(snmp_sa, Config), - ?line create_tables(SaNode), - ?line AgentDir = ?GCONF(agent_dir, Config), - ?line MgrDir = ?GCONF(mgr_dir, Config), - ?line Ip = ?GCONF(ip, Config), - ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - MibStorage = {snmp_mib_storage,{dets,AgentDir}}, - MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, - MibsVerbosity = {snmp_mibserver_verbosity, trace}, - SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, - Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity], - [{vsn, v1}, {agent_opts,Opts} | Config]. - -init_varm_mib_storage_mnesia(Config) when list(Config) -> - ?LOG("init_varm_mib_storage_mnesia -> entry", []), - ?line SaNode = ?GCONF(snmp_sa, Config), - ?line create_tables(SaNode), - ?line AgentDir = ?GCONF(agent_dir, Config), - ?line MgrDir = ?GCONF(mgr_dir, Config), - ?line Ip = ?GCONF(ip, Config), - ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - MibStorage = {snmp_mib_storage,{mnesia,[]}}, - MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, - MibsVerbosity = {snmp_mibserver_verbosity, trace}, - SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, - Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity], - [{vsn, v1}, {agent_opts,Opts} | Config]. - -finish_mib_storage_ets(Config) when list(Config) -> - ?LOG("finish_mib_storage_ets -> entry", []), - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - C2 = lists:keydelete(vsn, 1, C1), - lists:keydelete(agent_opts, 1, C2). - -finish_mib_storage_dets(Config) when list(Config) -> - ?LOG("finish_mib_storage_dets -> entry", []), - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - C2 = lists:keydelete(vsn, 1, C1), - lists:keydelete(agent_opts, 1, C2). - -finish_mib_storage_mnesia(Config) when list(Config) -> - ?LOG("finish_mib_storage_mnesia -> entry", []), - delete_tables(), - delete_mib_storage_mnesia_tables(), - C1 = stop_agent(Config), - delete_files(C1), - C2 = lists:keydelete(vsn, 1, C1), - lists:keydelete(agent_opts, 1, C2). - -finish_varm_mib_storage_dets(Config) when list(Config) -> - ?LOG("finish_varm_mib_storage_dets -> entry", []), - delete_tables(), - %% C1 = stop_agent(Config), % In case something went wrong... - delete_files(Config), - C2 = lists:keydelete(vsn, 1, Config), - lists:keydelete(agent_opts, 1, C2). - -finish_varm_mib_storage_mnesia(Config) when list(Config) -> - ?LOG("finish_varm_mib_storage_mnesia -> entry", []), - delete_tables(), - delete_mib_storage_mnesia_tables(), - %% C1 = stop_agent(Config), % In case something went wrong... - delete_files(Config), - C2 = lists:keydelete(vsn, 1, Config), - lists:keydelete(agent_opts, 1, C2). - -finish_size_check_mse(Config) when list(Config) -> - finish_size_check_ms(Config). - -finish_size_check_msd(Config) when list(Config) -> - finish_size_check_ms(Config). - -finish_size_check_msm(Config) when list(Config) -> - finish_size_check_ms(Config). - -finish_size_check_ms(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - - -%% These are just interface functions to fool the test server -mse_simple(X) -> simple(X). -mse_v1_processing(X) -> v1_processing(X). -mse_big(X) -> big(X). -mse_big2(X) -> big2(X). -mse_loop_mib(X) -> loop_mib(X). -mse_api(X) -> api(X). -mse_sa_register(X) -> sa_register(X). -mse_v1_trap(X) -> v1_trap(X). -mse_sa_error(X) -> sa_error(X). -mse_next_across_sa(X) -> next_across_sa(X). -mse_undo(X) -> undo(X). -mse_standard_mib(X) -> snmp_standard_mib(X). -mse_community_mib(X) -> snmp_community_mib(X). -mse_framework_mib(X) -> snmp_framework_mib(X). -mse_target_mib(X) -> snmp_target_mib(X). -mse_notification_mib(X) -> snmp_notification_mib(X). -mse_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). -mse_sparse_table(X) -> sparse_table(X). -mse_me_of(X) -> ms_me_of(X). -mse_mib_of(X) -> ms_mib_of(X). - -msd_simple(X) -> simple(X). -msd_v1_processing(X) -> v1_processing(X). -msd_big(X) -> big(X). -msd_big2(X) -> big2(X). -msd_loop_mib(X) -> loop_mib(X). -msd_api(X) -> api(X). -msd_sa_register(X) -> sa_register(X). -msd_v1_trap(X) -> v1_trap(X). -msd_sa_error(X) -> sa_error(X). -msd_next_across_sa(X) -> next_across_sa(X). -msd_undo(X) -> undo(X). -msd_standard_mib(X) -> snmp_standard_mib(X). -msd_community_mib(X) -> snmp_community_mib(X). -msd_framework_mib(X) -> snmp_framework_mib(X). -msd_target_mib(X) -> snmp_target_mib(X). -msd_notification_mib(X) -> snmp_notification_mib(X). -msd_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). -msd_sparse_table(X) -> sparse_table(X). -msd_me_of(X) -> ms_me_of(X). -msd_mib_of(X) -> ms_mib_of(X). - -msm_simple(X) -> simple(X). -msm_v1_processing(X) -> v1_processing(X). -msm_big(X) -> big(X). -msm_big2(X) -> big2(X). -msm_loop_mib(X) -> loop_mib(X). -msm_api(X) -> api(X). -msm_sa_register(X) -> sa_register(X). -msm_v1_trap(X) -> v1_trap(X). -msm_sa_error(X) -> sa_error(X). -msm_next_across_sa(X) -> next_across_sa(X). -msm_undo(X) -> undo(X). -msm_standard_mib(X) -> snmp_standard_mib(X). -msm_community_mib(X) -> snmp_community_mib(X). -msm_framework_mib(X) -> snmp_framework_mib(X). -msm_target_mib(X) -> snmp_target_mib(X). -msm_notification_mib(X) -> snmp_notification_mib(X). -msm_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). -msm_sparse_table(X) -> sparse_table(X). -msm_me_of(X) -> ms_me_of(X). -msm_mib_of(X) -> ms_mib_of(X). - - -mse_size_check(X) -> p("mse_size_check..."), ms_size_check(X). -msd_size_check(X) -> p("msd_size_check..."), ms_size_check(X). -msm_size_check(X) -> p("msm_size_check..."), ms_size_check(X). - -msd_varm_mib_start(X) -> p("msd_varm_mib_start..."), varm_mib_start(X). -msm_varm_mib_start(X) -> p("msm_varm_mib_start..."), varm_mib_start(X). - -ms_size_check(suite) -> []; -ms_size_check(Config) when list(Config) -> - p("ms_size_check..."), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?LOG("mib server size check...", []), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - ?line load_master_std("OTP-SNMPEA-MIB"), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-MPD-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-USER-BASED-SM-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - ?line load_master_std("SNMPv2-MIB"), - ?line load_master_std("SNMPv2-TM"), - - ?SLEEP(2000), - - ?line display_memory_usage(), - - ?line unload_master("OTP-SNMPEA-MIB"), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?line unload_master("SNMP-MPD-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-USER-BASED-SM-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - ?line unload_master("SNMPv2-MIB"), - ?line unload_master("SNMPv2-TM"), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - - ok. - - -varm_mib_start(suite) -> []; -varm_mib_start(Config) when list(Config) -> - p("varm_mib_start..."), - ?LOG("varm_mib_start -> entry", []), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - %% Start the agent - Opts = ?GCONF(agent_opts, Config), - Config1 = start_v1_agent(Config, Opts), - - %% Sleep some in order for the agent to start properly - ?DBG("varm_mib_start -> sleep some (before loading mobs)", []), - ?SLEEP(5000), - - %% Load all the mibs - HardwiredMibs = loaded_mibs(), - ?DBG("varm_mib_start -> load all mibs", []), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - - %% Unload the hardwired mibs - ?DBG("varm_mib_start -> sleep some (before unloading hardwired mibs)", []), - ?SLEEP(1000), - ?DBG("varm_mib_start -> unload (hardwired) mibs", []), - ?line unload_mibs(HardwiredMibs), %% unload hardwired - - ?DBG("varm_mib_start -> sleep some (before stopping agent)", []), - ?SLEEP(1000), - - %% Stop the agent (without deleting the stored files) - ?DBG("varm_mib_start -> stop the agent", []), - Config2 = stop_agent(Config1), - - %% Sleep some in order for the agent to stop properly - ?DBG("varm_mib_start -> sleep some (before re-starting the agent)", []), - ?SLEEP(5000), - - %% Start the agent (again) - ?DBG("varm_mib_start -> start the agent", []), - Config3 = start_v1_agent(Config2, Opts), - - ?DBG("varm_mib_start -> sleep some (before starting tests)", []), - ?SLEEP(5000), - - %% Perform the test(s) - ?DBG("varm_mib_start -> perform the tests", []), - try_test(snmp_community_mib), - try_test(snmp_framework_mib), - try_test(snmp_target_mib), - try_test(snmp_notification_mib), - - %% Stop the agent (without deleting the stored files) - ?DBG("varm_mib_start -> stop the agent", []), - stop_agent(Config3), - ok. - - --define(snmpTrapCommunity_instance, [1,3,6,1,6,3,18,1,4,0]). --define(vacmViewSpinLock_instance, [1,3,6,1,6,3,16,1,5,1,0]). --define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). - -ms_me_of(suite) -> []; -ms_me_of(Config) when list(Config) -> - p("ms_me_of..."), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - ?line load_master_std("OTP-SNMPEA-MIB"), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-MPD-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - - ?SLEEP(2000), - - ?line display_memory_usage(), - - - ?DBG("ms_me_of -> find ~w from SNMP-COMMUNITY-MIB", - [?snmpTrapCommunity_instance]), - ?line ok = me_of(?snmpTrapCommunity_instance), - - ?DBG("ms_me_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", - [?vacmViewSpinLock_instance]), - ?line ok = me_of(?vacmViewSpinLock_instance), - - ?DBG("ms_me_of -> find ~w from SNMP-USER-BASED-SM-MIB", - [?usmStatsNotInTimeWindows_instance]), - ?line {error, _} = me_of(?usmStatsNotInTimeWindows_instance), - - - ?line unload_master("OTP-SNMPEA-MIB"), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?line unload_master("SNMP-MPD-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - - ok. - -me_of(Oid) -> - case snmpa:me_of(Oid) of - {ok, #me{oid = Oid}} -> - ok; - {ok, #me{oid = OtherOid}} -> - case lists:reverse(Oid) of - [0|Rest] -> - case lists:reverse(Rest) of - OtherOid -> - ok; - AnotherOid -> - {error, {invalid_oid, Oid, AnotherOid}} - end; - _ -> - {error, {invalid_oid, Oid, OtherOid}} - end; - {error, Reason} -> - {error, Reason}; - Else -> - {error, Else} - end. - - -ms_mib_of(suite) -> []; -ms_mib_of(Config) when list(Config) -> - p("ms_mib_of..."), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - ?line load_master_std("OTP-SNMPEA-MIB"), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-MPD-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - - ?SLEEP(2000), - - ?line display_memory_usage(), - - - ?DBG("ms_mib_of -> find ~w from SNMP-COMMUNITY-MIB", - [?snmpTrapCommunity_instance]), - ?line ok = mib_of(?snmpTrapCommunity_instance, 'SNMP-COMMUNITY-MIB'), - - ?DBG("ms_mib_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", - [?vacmViewSpinLock_instance]), - ?line ok = mib_of(?vacmViewSpinLock_instance, 'SNMP-VIEW-BASED-ACM-MIB'), - - ?DBG("ms_mib_of -> find ~w from SNMP-USER-BASED-SM-MIB", - [?usmStatsNotInTimeWindows_instance]), - ?line {error, _} = mib_of(?usmStatsNotInTimeWindows_instance, - 'SNMP-USER-BASED-SM-MIB'), - - - ?line unload_master("OTP-SNMPEA-MIB"), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?line unload_master("SNMP-MPD-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - - ok. - -mib_of(Oid, ExpectedMibName) -> - ?DBG("mib_of -> entry with" - "~n Oid: ~p" - "~n ExpectedMibName: ~p", [Oid, ExpectedMibName]), - %% case snmpa:mib_of(Oid) of - MibOf = snmpa:mib_of(Oid), - ?DBG("mib_of -> MibOf: ~n~p", [MibOf]), - case MibOf of - {ok, ExpectedMibName} -> - ok; - {ok, OtherMibName} -> - {error, {invalid_mib, ExpectedMibName, OtherMibName}}; - {error, Reason} -> - {error, Reason}; - Else -> - ?DBG("mib_of -> Else: ~n~p", [Else]), - {error, Else} - end. - - -app_info(suite) -> []; -app_info(Config) when list(Config) -> - SnmpDir = app_dir(snmp), - SslDir = app_dir(ssl), - CryptoDir = app_dir(crypto), - Attr = snmp:module_info(attributes), - AppVsn = - case lists:keysearch(app_vsn, 1, Attr) of - {value, {app_vsn, V}} -> - V; - false -> - "undefined" - end, - io:format("Root dir: ~s~n" - "SNMP: Application dir: ~s~n" - " Application ver: ~s~n" - "SSL: Application dir: ~s~n" - "CRYPTO: Application dir: ~s~n", - [code:root_dir(), SnmpDir, AppVsn, SslDir, CryptoDir]), - ok. - -app_dir(App) -> - case code:lib_dir(App) of - D when list(D) -> - filename:basename(D); - {error, _Reason} -> - "undefined" - end. - - - -%v1_cases() -> [loop_mib]; -v1_cases() -> -[simple, db_notify_client, v1_processing, big, big2, - loop_mib, api, subagent, mnesia, {group, multiple_reqs}, - sa_register, v1_trap, sa_error, next_across_sa, undo, - {group, reported_bugs}, {group, standard_mibs}, - sparse_table, cnt_64, opaque, change_target_addr_config]. - -init_v1(Config) when list(Config) -> - ?line SaNode = ?config(snmp_sa, Config), - ?line create_tables(SaNode), - ?line AgentDir = ?config(agent_dir, Config), - ?line MgrDir = ?config(mgr_dir, Config), - ?line Ip = ?config(ip, Config), - ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v1} | start_v1_agent(Config)]. - -finish_v1(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - - -%v2_cases() -> [loop_mib_2]; -v2_cases() -> -[simple_2, v2_processing, big_2, big2_2, loop_mib_2, - api_2, subagent_2, mnesia_2, {group, multiple_reqs_2}, - sa_register_2, v2_trap, {group, v2_inform}, sa_error_2, - next_across_sa_2, undo_2, {group, reported_bugs_2}, - {group, standard_mibs_2}, v2_types, implied, - sparse_table_2, cnt_64_2, opaque_2, v2_caps]. - -init_v2(Config) when list(Config) -> - SaNode = ?config(snmp_sa, Config), - create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), - MgrDir = ?config(mgr_dir, Config), - Ip = ?config(ip, Config), - config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v2} | start_v2_agent(Config)]. - -finish_v2(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - - -v1_v2_cases() -> -[simple_bi]. - -init_v1_v2(Config) when list(Config) -> - SaNode = ?config(snmp_sa, Config), - create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), - MgrDir = ?config(mgr_dir, Config), - Ip = ?config(ip, Config), - config([v1,v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, bilingual} | start_bilingual_agent(Config)]. - -finish_v1_v2(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - - -%v3_cases() -> [loop_mib_3]; -v3_cases() -> -[simple_3, v3_processing, big_3, big2_3, api_3, - subagent_3, mnesia_3, loop_mib_3, multiple_reqs_3, - sa_register_3, v3_trap, v3_inform, sa_error_3, - next_across_sa_3, undo_3, {group, reported_bugs_3}, - {group, standard_mibs_3}, {group, v3_security}, - v2_types_3, implied_3, sparse_table_3, cnt_64_3, - opaque_3, v2_caps_3]. - -init_v3(Config) when list(Config) -> - %% Make sure crypto works, otherwise start_agent will fail - %% and we will be stuck with a bunch of mnesia tables for - %% the rest of this suite... - ?DBG("start_agent -> start crypto app",[]), - case os:type() of - vxworks -> - no_crypto; - _ -> - case ?CRYPTO_START() of - ok -> - case ?CRYPTO_SUPPORT() of - {no, Reason} -> - ?SKIP({unsupported_encryption, Reason}); - yes -> - ok - end; - {error, Reason} -> - ?SKIP({failed_starting_crypto, Reason}) - end - end, - SaNode = ?config(snmp_sa, Config), - create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), - MgrDir = ?config(mgr_dir, Config), - Ip = ?config(ip, Config), - ?line ok = config([v3], MgrDir, AgentDir, - tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v3} | start_v3_agent(Config)]. - -finish_v3(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - - -mt_cases() -> -[multi_threaded, mt_trap]. - -init_mt(Config) when list(Config) -> - SaNode = ?config(snmp_sa, Config), - create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), - MgrDir = ?config(mgr_dir, Config), - Ip = ?config(ip, Config), - ?line ok = config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v2} | start_multi_threaded_agent(Config)]. - -finish_mt(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - -%% This one *must* be run first in each case. -init_case(Config) when list(Config) -> - ?DBG("init_case -> entry with" - "~n Config: ~p", [Config]), - SaNode = ?config(snmp_sa, Config), - MgrNode = ?config(snmp_mgr, Config), - MasterNode = node(), - - SaHost = ?HOSTNAME(SaNode), - MgrHost = ?HOSTNAME(MgrNode), - MasterHost = ?HOSTNAME(MasterNode), - {ok, MasterIP} = snmp_misc:ip(MasterHost), - {ok, MIP} = snmp_misc:ip(MgrHost), - {ok, SIP} = snmp_misc:ip(SaHost), - - - put(mgr_node, MgrNode), - put(sa_node, SaNode), - put(master_node, MasterNode), - put(sa_host, SaHost), - put(mgr_host, MgrHost), - put(master_host, MasterHost), - put(mip, tuple_to_list(MIP)), - put(masterip , tuple_to_list(MasterIP)), - put(sip, tuple_to_list(SIP)), - - MibDir = ?config(mib_dir, Config), - put(mib_dir, MibDir), - StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", - put(std_mib_dir, StdM), - - MgrDir = ?config(mgr_dir, Config), - put(mgr_dir, MgrDir), - - put(vsn, ?config(vsn, Config)), - ?DBG("init_case -> exit with" - "~n MasterNode: ~p" - "~n SaNode: ~p" - "~n MgrNode: ~p" - "~n MibDir: ~p", [MasterNode, SaNode, MgrNode, MibDir]), - {SaNode, MgrNode, MibDir}. - -load_master(Mib) -> - ?DBG("load_master -> entry with" - "~n Mib: ~p", [Mib]), - snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety - ok = snmpa:load_mibs(snmp_master_agent, [get(mib_dir) ++ Mib]). - -load_master_std(Mib) -> - ?DBG("load_master_std -> entry with" - "~n Mib: ~p", [Mib]), - snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety - ok = snmpa:load_mibs(snmp_master_agent, [get(std_mib_dir) ++ Mib]). - -unload_master(Mib) -> - ?DBG("unload_master -> entry with" - "~n Mib: ~p", [Mib]), - ok = snmpa:unload_mibs(snmp_master_agent, [Mib]). - -loaded_mibs() -> - ?DBG("loaded_mibs -> entry",[]), - Info = snmpa:info(snmp_master_agent), - {value, {loaded_mibs, Mibs}} = lists:keysearch(loaded_mibs, 1, Info), - [atom_to_list(Mib) || {Mib,_,_} <- Mibs]. - -unload_mibs(Mibs) -> - ?DBG("unload_mibs -> entry with" - "~n Mibs: ~p", [Mibs]), - ok = snmpa:unload_mibs(snmp_master_agent, Mibs). - -start_subagent(SaNode, RegTree, Mib) -> - ?DBG("start_subagent -> entry with" - "~n SaNode: ~p" - "~n RegTree: ~p" - "~n Mib: ~p", [SaNode, RegTree, Mib]), - MA = whereis(snmp_master_agent), - ?DBG("start_subagent -> MA: ~p", [MA]), - MibDir = get(mib_dir), - Mib1 = join(MibDir,Mib), - %% BMK BMK -% case rpc:call(SaNode,snmp_supervisor,start_subagent,[MA,RegTree,[Mib1]]) of - case rpc:call(SaNode, snmpa_supervisor, - start_sub_agent, [MA, RegTree, [Mib1]]) of - {ok, SA} -> - ?DBG("start_subagent -> SA: ~p", [SA]), - {ok, SA}; - Error -> - ?FAIL({subagent_start_failed, SaNode, Error, [MA, RegTree, Mib1]}) - end. - -stop_subagent(SA) -> - ?DBG("stop_subagent -> entry with" - "~n SA: ~p", [SA]), - %% BNK BMK - %% rpc:call(node(SA), snmp_supervisor, stop_subagent, [SA]). - rpc:call(node(SA), snmpa_supervisor, stop_sub_agent, [SA]). - -%%----------------------------------------------------------------- -%% This function takes care of the old OTP-SNMPEA-MIB. -%% Unfortunately, the testcases were written to use the data in the -%% internal tables, and these table are now obsolete and not used -%% by the agent. Therefore, we emulate them by using -%% OLD-SNMPEA-MIB, which uses the default impl. of all tables. -%% -%% These two rows must exist in intCommunityTable -%% {[147,214,36,45], "public", 2, readWrite}. -%% {[147,214,36,45], "standard trap", 2, read}. -%% (But with the manager's IP address) -%% -%%----------------------------------------------------------------- -init_old() -> - snmpa_local_db:table_create_row(intCommunityTable, - get(mip) ++ [6 | "public"], - {get(mip), "public", 2, 2}), - snmpa_local_db:table_create_row(intCommunityTable, - get(mip) ++ [13 | "standard trap"], - {get(mip), "standard trap", 2, 1}), - snmpa_local_db:variable_set(intAgentIpAddress, [127,0,0,1]). - - - -simple(suite) -> []; -simple(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - try_test(simple_standard_test). - -simple_2(X) -> simple(X). - -simple_bi(suite) -> []; -simple_bi(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - put(vsn, v1), % First, try v1 manager - try_test(simple_standard_test), - - put(vsn, v2), % Then, try v2 manager - try_test(simple_standard_test). - -simple_3(X) -> - simple(X). - -big(suite) -> []; -big(Config) when list(Config) -> - ?DBG("big -> entry", []), - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Starting subagent..."), - ?line pong = net_adm:ping(SaNode), - - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), - ?DBG("big -> SA: ~p", [SA]), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(big_test), - ?line stop_subagent(SA), - ?line unload_master("OLD-SNMPEA-MIB"). - -big_2(X) -> big(X). - -big_3(X) -> big(X). - - -big2(suite) -> []; -big2(Config) when list(Config) -> - %% This is exactly the same tests as 'big', but with the - %% v2 equivalent of the mibs. - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Starting subagent..."), - ?line pong = net_adm:ping(SaNode), - - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1-v2"), - ?line load_master("OLD-SNMPEA-MIB-v2"), - ?line init_old(), - try_test(big_test), - ?line stop_subagent(SA), - ?line unload_master("OLD-SNMPEA-MIB-v2"). - -big2_2(X) -> big2(X). - -big2_3(X) -> big2(X). - - -multi_threaded(suite) -> []; -multi_threaded(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test1"), - try_test(multi_threaded_test), - ?line unload_master("Test1"). - -mt_trap(suite) -> []; -mt_trap(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line load_master("Test1"), - ?line load_master("TestTrapv2"), - try_test(mt_trap_test, [MA]), - ?line unload_master("TestTrapv2"), - ?line unload_master("Test1"). - -v2_types(suite) -> []; -v2_types(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test1"), - try_test(types_v2_test), - ?line unload_master("Test1"). - -v2_types_3(X) -> v2_types(X). - - -implied(suite) -> []; -implied(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line load_master("Test1"), - try_test(implied_test,[MA]), - ?line unload_master("Test1"). - -implied_3(X) -> implied(X). - - -sparse_table(suite) -> []; -sparse_table(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test1"), - try_test(sparse_table_test), - ?line unload_master("Test1"). - -sparse_table_2(X) -> sparse_table(X). - -sparse_table_3(X) -> sparse_table(X). - -cnt_64(suite) -> []; -cnt_64(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line load_master("Test1"), - try_test(cnt_64_test, [MA]), - ?line unload_master("Test1"). - -cnt_64_2(X) -> cnt_64(X). - -cnt_64_3(X) -> cnt_64(X). - -opaque(suite) -> []; -opaque(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test1"), - try_test(opaque_test), - ?line unload_master("Test1"). - -opaque_2(X) -> opaque(X). - -opaque_3(X) -> opaque(X). - - -change_target_addr_config(suite) -> []; -change_target_addr_config(Config) when list(Config) -> - p("Testing changing target address config..."), - ?LOG("change_target_addr_config -> entry",[]), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - put(sname,snmp_suite), - put(verbosity,trace), - - MA = whereis(snmp_master_agent), - - ?LOG("change_target_addr_config -> load TestTrap",[]), - ?line load_master("TestTrap"), - - ?LOG("change_target_addr_config -> set trace verbosity for local_db",[]), - ?line snmpa:verbosity(local_db,trace), - - %% First send some traps that will arive att the original manager - ?LOG("change_target_addr_config -> send trap",[]), - try_test(ma_trap1, [MA]), - - ?LOG("change_target_addr_config -> set silence verbosity for local_db",[]), - ?line snmpa:verbosity(local_db,silence), - - %% Start new dummy listener - ?LOG("change_target_addr_config -> start dummy manager",[]), - ?line {ok,Pid,NewPort} = dummy_manager_start(MA), - - %% Reconfigure - ?LOG("change_target_addr_config -> reconfigure",[]), - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_addr_conf(AgentDir, NewPort), - ?line snmp_target_mib:reconfigure(AgentDir), - - %% Send the trap again - ?LOG("change_target_addr_config -> send trap again",[]), - catch dummy_manager_send_trap2(Pid), - - ?LOG("change_target_addr_config -> await trap ack",[]), - catch dummy_manager_await_trap2_ack(), - - ?LOG("change_target_addr_config -> stop dummy manager",[]), - ?line ok = dummy_manager_stop(Pid), - - ?LOG("change_target_addr_config -> reset target address config",[]), - ?line reset_target_addr_conf(AgentDir), - - ?LOG("change_target_addr_config -> unload TestTrap",[]), - ?line unload_master("TestTrap"). - - -dummy_manager_start(MA) -> - ?DBG("dummy_manager_start -> entry",[]), - Pid = spawn(get(mgr_node), ?MODULE,dummy_manager_init,[self(),MA]), - ?DBG("dummy_manager_start -> Pid: ~p",[Pid]), - await_dummy_manager_started(Pid). - -await_dummy_manager_started(Pid) -> - receive - {dummy_manager_started,Pid,Port} -> - ?DBG("dummy_manager_start -> acknowledge received with" - "~n Port: ~p",[Port]), - {ok,Pid,Port}; - {'EXIT', Pid, Reason} -> - {error, Pid, Reason}; - O -> - ?LOG("dummy_manager_start -> received unknown message:" - "~n ~p",[O]), - await_dummy_manager_started(Pid) - end. - -dummy_manager_stop(Pid) -> - ?DBG("dummy_manager_stop -> entry with Pid: ~p",[Pid]), - Pid ! stop, - receive - {dummy_manager_stopping, Pid} -> - ?DBG("dummy_manager_stop -> acknowledge received",[]), - ok - after 10000 -> - ?ERR("dummy_manager_stop -> timeout",[]), - timeout - end. - -dummy_manager_send_trap2(Pid) -> - ?DBG("dummy_manager_send_trap2 -> entry",[]), - Pid ! {send_trap,testTrap2}. - -dummy_manager_await_trap2_ack() -> - ?DBG("dummy_manager_await_trap2 -> entry",[]), - receive - {received_trap,Trap} -> - ?LOG("dummy_manager_await_trap2 -> received trap: ~p",[Trap]), - %% Note: - %% Without this sleep the v2_inform_i testcase failes! There - %% is no relation between these two test cases as far as I - %% able to figure out... - sleep(60000), - ok; - O -> - ?ERR("dummy_manager_await_trap2 -> unexpected message: ~p",[O]), - ok - after 10000 -> - ?ERR("dummy_manager_await_trap2 -> timeout",[]), - timeout - end. - -dummy_manager_init(Parent,MA) -> - ?DBG("dummy_manager_init -> entry with" - "~n Parent: ~p" - "~n MA: ~p",[Parent,MA]), - {ok,S} = gen_udp:open(0,[{recbuf,65535}]), - ?DBG("dummy_manager_init -> S: ~p",[S]), - {ok,Port} = inet:port(S), - ?DBG("dummy_manager_init -> Port: ~p",[Port]), - Parent ! {dummy_manager_started,self(),Port}, - dummy_manager_loop(Parent,S,MA). - -dummy_manager_loop(P,S,MA) -> - ?LOG("dummy_manager_loop -> ready for receive",[]), - receive - {send_trap,Trap} -> - ?LOG("dummy_manager_loop -> received trap send request" - "~n Trap: ~p",[Trap]), - snmpa:send_trap(MA, Trap, "standard trap"), - dummy_manager_loop(P,S,MA); - {udp, _UdpId, Ip, UdpPort, Bytes} -> - ?LOG("dummy_manager_loop -> received upd message" - "~n from: ~p:~p" - "~n size: ~p", - [Ip, UdpPort, dummy_manager_message_sz(Bytes)]), - R = dummy_manager_handle_message(Bytes), - ?DBG("dummy_manager_loop -> R: ~p",[R]), - P ! R, - dummy_manager_loop(P,S,MA); - stop -> - ?DBG("dummy_manager_loop -> received stop request",[]), - P ! {dummy_manager_stopping, self()}, - gen_udp:close(S), - exit(normal); - O -> - ?LOG("dummy_manager_loop -> received unknown message:" - "~n ~p",[O]), - dummy_manager_loop(P,S,MA) - end. - -dummy_manager_message_sz(B) when binary(B) -> - size(B); -dummy_manager_message_sz(L) when list(L) -> - length(L); -dummy_manager_message_sz(_) -> - undefined. - -dummy_manager_handle_message(Bytes) -> - case (catch snmp_pdus:dec_message(Bytes)) of - {'EXIT',Reason} -> - ?ERR("dummy_manager_handle_message -> " - "failed decoding message only:~n ~p",[Reason]), - {error,Reason}; - M -> - ?DBG("dummy_manager_handle_message -> decoded message:" - "~n ~p",[M]), - {received_trap,M} - end. - - -api(suite) -> []; -api(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(api_test, [node()]), - ?line unload_master("OLD-SNMPEA-MIB"). - -api_2(X) -> api(X). - -api_3(X) -> api(X). - - -subagent(suite) -> []; -subagent(Config) when list(Config) -> - {SaNode, _MgrNode, MibDir} = init_case(Config), - - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), - try_test(load_test_sa), - - p("Testing unregister subagent..."), - MA = whereis(snmp_master_agent), - rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), - try_test(unreg_test), - - p("Loading previous subagent mib in master and testing..."), - ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas1"]), - try_test(load_test), - - p("Unloading previous subagent mib in master and testing..."), - ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas1"]), - try_test(unreg_test), - p("Testing register subagent..."), - rpc:call(SaNode, snmp, register_subagent, - [MA, ?klas1, SA]), - try_test(load_test_sa), - - ?line stop_subagent(SA), - try_test(unreg_test). - -subagent_2(X) -> subagent(X). - -subagent_3(X) -> subagent(X). - - -mnesia(suite) -> []; -mnesia(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Starting subagent with mnesia impl..."), - {ok, SA} = start_subagent(SaNode, ?klas2, "Klas2"), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - - try_test(big_test_2), - - p("Testing unregister subagent..."), - MA = whereis(snmp_master_agent), - rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), - try_test(unreg_test), - ?line unload_master("OLD-SNMPEA-MIB"), - ?line stop_subagent(SA). - -mnesia_2(X) -> mnesia(X). - -mnesia_3(X) -> mnesia(X). - - - -mul_cases() -> -[mul_get, mul_get_err, mul_next, mul_next_err, - mul_set_err]. - - -multiple_reqs_3(_X) -> - {req, [], {conf, init_mul, mul_cases_3(), finish_mul}}. - - -mul_cases_2() -> -[mul_get_2, mul_get_err_2, mul_next_2, mul_next_err_2, - mul_set_err_2]. - - -mul_cases_3() -> - [mul_get_3, mul_get_err_3, mul_next_3, mul_next_err_3, mul_set_err_3]. - - -init_mul(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - [{mul_sub, SA} | Config]. - -finish_mul(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - SA = ?config(mul_sub, Config), - - ?line unload_master("OLD-SNMPEA-MIB"), - ?line stop_subagent(SA), - lists:keydelete(mul_sub, 1, Config). - -mul_get(suite) -> []; -mul_get(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple get..."), - try_test(do_mul_get). - -mul_get_2(X) -> mul_get(X). - -mul_get_3(X) -> mul_get(X). - - -mul_get_err(suite) -> []; -mul_get_err(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple get with error..."), - try_test(do_mul_get_err). - -mul_get_err_2(X) -> mul_get_err(X). - -mul_get_err_3(X) -> mul_get_err(X). - - -mul_next(suite) -> []; -mul_next(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple next..."), - try_test(do_mul_next). - -mul_next_2(X) -> mul_next(X). - -mul_next_3(X) -> mul_next(X). - - -mul_next_err(suite) -> []; -mul_next_err(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple next..."), - try_test(do_mul_next_err). - -mul_next_err_2(X) -> mul_next_err(X). - -mul_next_err_3(X) -> mul_next_err(X). - - -mul_set(suite) -> []; -mul_set(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple set..."), - try_test(do_mul_set). - -mul_set_2(X) -> mul_set(X). - -mul_set_3(X) -> mul_set(X). - - -mul_set_err(suite) -> []; -mul_set_err(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple set with error..."), - try_test(do_mul_set_err). - -mul_set_err_2(X) -> mul_set_err(X). - -mul_set_err_3(X) -> mul_set_err(X). - - -sa_register(suite) -> []; -sa_register(Config) when list(Config) -> - ?DBG("sa_register -> entry", []), - {SaNode, _MgrNode, MibDir} = init_case(Config), - - ?DBG("sa_register -> start subagent", []), - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), - - ?DBG("sa_register -> unregister subagent", []), - p("Testing unregister subagent (2)..."), - MA = whereis(snmp_master_agent), - rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), - try_test(unreg_test), - - p("Loading SA-MIB..."), - ?DBG("sa_register -> unload mibs", []), - snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), - ?DBG("sa_register -> unload mibs", []), - snmpa:load_mibs(SA, [MibDir ++ "SA-MIB"]), - ?DBG("sa_register -> register subagent", []), - rpc:call(SaNode, snmp, register_subagent, [MA,?sa,SA]), - try_test(sa_mib), - - ?DBG("sa_register -> stop subagent", []), - ?line stop_subagent(SA). - -sa_register_2(X) -> sa_register(X). - -sa_register_3(X) -> sa_register(X). - - -v1_trap(suite) -> []; -v1_trap(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Testing trap sending from master agent..."), - MA = whereis(snmp_master_agent), - - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(ma_trap1, [MA]), - try_test(ma_trap2, [MA]), - try_test(ma_v2_2_v1_trap, [MA]), - try_test(ma_v2_2_v1_trap2, [MA]), - - p("Testing trap sending from subagent..."), - try_test(sa_trap1, [SA]), - try_test(sa_trap2, [SA]), - try_test(sa_trap3, [SA]), - - ?line unload_master("TestTrap"), - ?line unload_master("TestTrapv2"), - - ?line stop_subagent(SA). - -v2_trap(suite) -> []; -v2_trap(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Testing trap sending from master agent..."), - MA = whereis(snmp_master_agent), - - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - - try_test(ma_v2_trap1, [MA]), - try_test(ma_v2_trap2, [MA]), - try_test(ma_v1_2_v2_trap, [MA]), - try_test(ma_v1_2_v2_trap2, [MA]), - - try_test(sa_mib), - p("Testing trap sending from subagent..."), - try_test(sa_v1_2_v2_trap1, [SA]), - try_test(sa_v1_2_v2_trap2, [SA]), - try_test(sa_v1_2_v2_trap3, [SA]), - - ?line unload_master("TestTrap"), - ?line unload_master("TestTrapv2"), - - ?line stop_subagent(SA). - -v3_trap(X) -> - v2_trap(X). - - -v3_inform(_X) -> - %% v2_inform(X). - {req, [], {conf, init_v3_inform, [v3_inform_i], finish_v3_inform}}. - -init_v2_inform(Config) when list(Config) -> - _Dir = ?config(agent_dir, Config), -% snmp_internal_mib:configure(Dir), - Config. - -init_v3_inform(X) -> - init_v2_inform(X). - -finish_v2_inform(Config) when list(Config) -> - _Dir = ?config(agent_dir, Config), -% snmp_internal_mib:configure(Dir), - Config. - -finish_v3_inform(X) -> - finish_v2_inform(X). - - - -v2_inform_i(suite) -> []; -v2_inform_i(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing inform sending from master agent... NOTE! This test\ntakes a " - "few minutes (5) to complete."), - MA = whereis(snmp_master_agent), - - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(ma_v2_inform1, [MA]), - - ?line unload_master("TestTrap"), - ?line unload_master("TestTrapv2"). - -v3_inform_i(X) -> v2_inform_i(X). - - -sa_error(suite) -> []; -sa_error(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Testing sa bad value (is_set_ok)..."), - try_test(sa_errs_bad_value), - - p("Testing sa gen err (set)..."), - try_test(sa_errs_gen_err), - - p("Testing too big..."), - try_test(sa_too_big), - - ?line unload_master("OLD-SNMPEA-MIB"), - stop_subagent(SA). - -sa_error_2(X) -> sa_error(X). - -sa_error_3(X) -> sa_error(X). - - -next_across_sa(suite) -> []; -next_across_sa(Config) when list(Config) -> - {SaNode, _MgrNode, MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Loading another subagent mib..."), - ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas1"]), - - rpc:call(SaNode, snmp, register_subagent, [MA, ?klas1, SA]), - try_test(load_test_sa), - - p("Testing next across subagent (endOfMibView from SA)..."), - try_test(next_across_sa), - - p("Unloading mib"), - snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), - rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), - try_test(unreg_test), - - p("Starting another subagent"), - ?line {ok, SA2} = start_subagent(SaNode, ?klas1, "Klas1"), - p("Testing next across subagent (wrong prefix from SA)..."), - try_test(next_across_sa), - - stop_subagent(SA), - stop_subagent(SA2). - -next_across_sa_2(X) -> next_across_sa(X). - -next_across_sa_3(X) -> next_across_sa(X). - - -undo(suite) -> []; -undo(Config) when list(Config) -> - {SaNode, _MgrNode, MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Testing undo phase at master agent..."), - ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas3"]), - ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas4"]), - try_test(undo_test), - try_test(api_test2), - ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas3"]), - - p("Testing bad return values from instrum. funcs..."), - try_test(bad_return), - - ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas4"]), - - p("Testing undo phase at subagent..."), - ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas3"]), - ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas4"]), - ?line ok = snmpa:register_subagent(MA, ?klas3, SA), - ?line ok = snmpa:register_subagent(MA, ?klas4, SA), - try_test(undo_test), - try_test(api_test3), - - p("Testing undo phase across master/subagents..."), - try_test(undo_test), - try_test(api_test3), - stop_subagent(SA). - -undo_2(X) -> undo(X). - -undo_3(X) -> undo(X). - -%% Req. Test2 -v1_processing(suite) -> []; -v1_processing(Config) when list(Config) -> - ?DBG("v1_processing -> entry", []), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - try_test(v1_proc), - ?line unload_master("Test2"). - -%% Req. Test2 -v2_processing(suite) -> []; -v2_processing(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - try_test(v2_proc), - ?line unload_master("Test2"). - -%% Req. Test2 -v3_processing(suite) -> []; -v3_processing(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - try_test(v2_proc), % same as v2! - ?line unload_master("Test2"). - - -%% We'll try get/set/trap and inform for all the auth & priv protocols. -%% For informs, the mgr is auth-engine. The agent has to sync. This is -%% accomplished by the first inform sent. That one will generate a -%% report, which makes it in sync. The notification-generating -%% application times out, and send again. This time it'll work. - -v3_crypto_basic(suite) -> []; -v3_crypto_basic(_Config) -> - EID = [0,0,0,0,0,0,0,0,0,0,0,2], - %% From rfc2274 appendix A.3.1 - ?line KMd5_1 = snmp:passwd2localized_key(md5, "maplesyrup", EID), - ?line [16#52,16#6f,16#5e,16#ed,16#9f,16#cc,16#e2,16#6f, - 16#89,16#64,16#c2,16#93,16#07,16#87,16#d8,16#2b] = - KMd5_1, - %% From rfc2274 appendix A.3.2 - ?line KSHA_1 = snmp:passwd2localized_key(sha, "maplesyrup", EID), - ?line [16#66,16#95,16#fe,16#bc,16#92,16#88,16#e3,16#62,16#82,16#23, - 16#5f,16#c7,16#15,16#1f,16#12,16#84,16#97,16#b3,16#8f,16#3f] = - KSHA_1, - %% From rfc2274, appendix A.5.1 - ?line KMd5_2 = snmp:passwd2localized_key(md5, "newsyrup", EID), - ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#88,16#05,16#61,16#51,16#41,16#67,16#6c,16#c9, - 16#19,16#61,16#74,16#e7,16#42,16#a3,16#25,16#51] = - snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2, 16, - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), - %% From rfc2274, appendix A.5.2 - ?line KSHA_2 = snmp:passwd2localized_key(sha, "newsyrup", EID), - ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#00,16#00,16#00,16#00,16#9c,16#10,16#17,16#f4, - 16#fd,16#48,16#3d,16#2d,16#e8,16#d5,16#fa,16#db, - 16#f8,16#43,16#92,16#cb,16#06,16#45,16#70,16#51] = - snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2, 20, - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), - KSHA_1t = lists:sublist(KSHA_1, 16), - KSHA_2t = lists:sublist(KSHA_2, 16), - ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#7e,16#f8,16#d8,16#a4,16#c9,16#cd,16#b2,16#6b, - 16#47,16#59,16#1c,16#d8,16#52,16#ff,16#88,16#b5] = - snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1t, KSHA_2t, 16, - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), - - %% Try with correct random - ?line Kc1 = snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2), - ?line KMd5_2 = snmp_user_based_sm_mib:extract_new_key(md5, KMd5_1, Kc1), - ?line Kc2 = snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2), - ?line KSHA_2 = snmp_user_based_sm_mib:extract_new_key(sha, KSHA_1, Kc2), - ok. - - - -v3_md5_auth(suite) -> []; -v3_md5_auth(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - p("Testing MD5 authentication...takes a few seconds..."), - - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_params_conf(AgentDir, "authMD5", authNoPriv), - ?line snmp_target_mib:reconfigure(AgentDir), - - MA = whereis(snmp_master_agent), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(v3_sync, [[{v2_proc, []}, - {ma_v2_trap1, [MA]}, - {v3_inform_sync, [MA]}]], - [{sec_level, authNoPriv}, {user, "authMD5"}]), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - ?line reset_target_params_conf(AgentDir). - -v3_sha_auth(suite) -> []; -v3_sha_auth(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - p("Testing SHA authentication...takes a few seconds..."), - - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_params_conf(AgentDir, "authSHA", authNoPriv), - ?line snmp_target_mib:reconfigure(AgentDir), - - MA = whereis(snmp_master_agent), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(v3_sync, [[{v2_proc, []}, - {ma_v2_trap1, [MA]}, - {v3_inform_sync, [MA]}]], - [{sec_level, authNoPriv}, {user, "authSHA"}]), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - ?line reset_target_params_conf(AgentDir). - -v3_des_priv(suite) -> []; -v3_des_priv(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - p("Testing DES encryption...takes a few seconds..."), - - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_params_conf(AgentDir, "privDES", authPriv), - ?line snmp_target_mib:reconfigure(AgentDir), - - MA = whereis(snmp_master_agent), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(v3_sync, [[{v2_proc, []}, - {ma_v2_trap1, [MA]}, - {v3_inform_sync, [MA]}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - ?line reset_target_params_conf(AgentDir). - -%% -define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). - -%% Make sure mgr is in sync with agent -v3_sync(Funcs) -> - ?DBG("v3_sync -> entry with Funcs: ~p",[Funcs]), - g([[sysDescr, 0]]), - expect(432, report, [{?usmStatsNotInTimeWindows_instance, any}]), - g([[sysDescr, 0]]), - expect(433, [{[sysDescr,0], any}]), - lists:foreach(fun({Func, Args}) -> apply(?MODULE, Func, Args) end, Funcs). - -v3_inform_sync(MA) -> - ?DBG("v3_sync -> entry with MA: ~p => Send notification",[MA]), - ?line snmpa:send_notification(MA, testTrapv22, no_receiver, - "standard inform", []), - %% Make sure agent is in sync with mgr... - ?DBG("v3_sync -> wait some time: ",[]), - sleep(20000), % more than 1500*10 in target_addr.conf - ?DBG("v3_sync -> await response",[]), - ?line expect(1, {inform, true}, - [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]). - - -v2_caps(suite) -> []; -v2_caps(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - try_test(v2_caps_i, [node()]). - -v2_caps_3(X) -> v2_caps(X). - - -v2_caps_i(Node) -> - ?line Idx = rpc:call(Node, snmp, add_agent_caps, [[1,2,3,4,5], "test cap"]), - g([[sysORID, Idx], [sysORDescr, Idx]]), - ?line expect(1, [{[sysORID, Idx], [1,2,3,4,5]}, - {[sysORDescr, Idx], "test cap"}]), - ?line rpc:call(Node, snmp, del_agent_caps, [Idx]), - g([[sysORID, Idx]]), - ?line expect(2, [{[sysORID, Idx], noSuchInstance}]). - - -%% Req. Test2 -v1_proc() -> - ?DBG("v1_proc -> entry", []), - %% According to RFC1157. - %% Template:
: - v1_get_p(), - v1_get_next_p(), - v1_set_p(). - - -v1_get_p() -> - %% 4.1.2:1 - g([[test2]]), - ?line expect(10, noSuchName, 1, [{[test2], 'NULL'}]), - g([[tDescr]]), - ?line expect(11, noSuchName, 1, [{[tDescr], 'NULL'}]), - g([[tDescr2,0]]), - ?line expect(12, noSuchName, 1, [{[tDescr2,0], 'NULL'}]), - g([[tDescr3,0]]), - ?line expect(131, noSuchName, 1, [{[tDescr3,0], 'NULL'}]), - g([[tDescr4,0]]), - ?line expect(132, noSuchName, 1, [{[tDescr4,0], 'NULL'}]), - g([[sysDescr, 0], [tDescr,0]]), % Outside mibview - ?line expect(14, noSuchName, 2, [{[sysDescr, 0], 'NULL'}, - {[tDescr,0], 'NULL'}]), - g([[sysDescr,3]]), - ?line expect(15, noSuchName, 1, [{[sysDescr, 3], 'NULL'}]), - - %% 4.1.2:2 - g([[tTable]]), - ?line expect(20, noSuchName, 1, [{[tTable], 'NULL'}]), - g([[tEntry]]), - ?line expect(21, noSuchName, 1, [{[tEntry], 'NULL'}]), - - %% 4.1.2:3 - g([[tTooBig, 0]]), - ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), - - %% 4.1.2:4 - g([[tGenErr1, 0]]), - ?line expect(40, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), - g([[tGenErr2, 0]]), - ?line expect(41, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), - g([[sysDescr, 0], [tGenErr3, 0]]), - ?line expect(42, genErr, 2, [{[sysDescr, 0], 'NULL'}, - {[tGenErr3, 0], 'NULL'}]). - - -v1_get_next_p() -> - %% 4.1.3:1 - gn([[1,3,7,1]]), - ?line expect(10, noSuchName, 1, [{[1,3,7,1], 'NULL'}]), - gn([[tDescr2]]), - ?line expect(11, tooBig, 0, any), - - %% 4.1.3:2 - gn([[tTooBig]]), - io:format("We currently don't handle tooBig correct!!!\n"), -% ?line expect(20, tooBig, 0, [{[tTooBig], 'NULL'}]), - ?line expect(20, tooBig, 0, any), - - %% 4.1.3:3 - gn([[tGenErr1]]), -% ?line expect(40, genErr, 1, [{[tGenErr1], 'NULL'}]), - ?line expect(40, genErr, 1, any), - gn([[tGenErr2]]), -% ?line expect(41, genErr, 1, [{[tGenErr2], 'NULL'}]), - ?line expect(41, genErr, 1, any), - gn([[sysDescr], [tGenErr3]]), -% ?line expect(42, genErr, 2, [{[sysDescr], 'NULL'}, -% {[tGenErr3], 'NULL'}]). - ?line expect(42, genErr, 2, any). - -v1_set_p() -> - %% 4.1.5:1 - s([{[1,3,7,0], i, 4}]), - ?line expect(10, noSuchName, 1, [{[1,3,7,0], 4}]), - s([{[tDescr,0], s, "outside mibview"}]), - ?line expect(11, noSuchName, 1, [{[tDescr,0], "outside mibview"}]), - s([{[tDescr3,0], s, "read-only"}]), - ?line expect(12, noSuchName, 1, [{[tDescr3,0], "read-only"}]), - s([{[tDescr3], s, "noSuchObject"}]), - ?line expect(13, noSuchName, 1, [{[tDescr3], "noSuchObject"}]), - s([{[tDescr3,1], s, "noSuchInstance"}]), - ?line expect(14, noSuchName, 1, [{[tDescr3,1], "noSuchInstance"}]), - s([{[tDescr2,0], s, "inconsistentName"}]), - ?line expect(15, noSuchName, 1, [{[tDescr2,0], "inconsistentName"}]), - - %% 4.1.5:2 - s([{[tDescr2, 0], i, 4}]), - ?line expect(20, badValue, 1, [{[tDescr2, 0], 4}]), - s([{[tDescr2, 0], s, "badValue"}]), - ?line expect(21, badValue, 1, [{[tDescr2, 0], "badValue"}]), - - %% 4.1.5:3 - %% The standard is quite incorrect here. The resp pdu was too big. In - %% the resp pdu, we have the original vbs. In the tooBig pdu we still - %% have to original vbs => the tooBig pdu is too big as well!!! It - %% may not get it to the manager, unless the agent uses 'NULL' instead - %% of the std-like original value. - s([{[tTooBig, 0], s, ?tooBigStr}]), - %% according to std: -% ?line expect(30, tooBig, 0, [{[tTooBig, 0], ?tooBigStr}]), - ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), - - %% 4.1.5:4 - s([{[tDescr2, 0], s, "is_set_ok_fail"}]), - ?line expect(40, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]), - s([{[tDescr2, 0], s, "commit_fail"}]), - ?line expect(41, genErr, 1, [{[tDescr2, 0], "commit_fail"}]). - -%% Req. Test2 -v2_proc() -> - %% According to RFC1905. - %% Template:
: - ?DBG("v2_proc -> entry",[]), - v2_get_p(), - v2_get_next_p(), - v2_get_bulk_p(), - v2_set_p(). - -v2_get_p() -> - %% 4.2.1:2 - ?DBG("v2_get_p -> entry",[]), - g([[test2]]), - ?line expect(10, [{[test2], noSuchObject}]), - g([[tDescr]]), - ?line expect(11, [{[tDescr], noSuchObject}]), - g([[tDescr4,0]]), - ?line expect(12, [{[tDescr4,0], noSuchObject}]), - g([[sysDescr, 0], [tDescr,0]]), % Outside mibview - ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}, - {[tDescr,0], noSuchObject}]), - g([[tTable]]), - ?line expect(14, [{[tTable], noSuchObject}]), - g([[tEntry]]), - ?line expect(15, [{[tEntry], noSuchObject}]), - - %% 4.2.1:3 - g([[tDescr2,0]]), %% instrum ret noSuchName!!! - ?line expect(20, [{[tDescr2,0], noSuchInstance}]), - g([[tDescr3,0]]), - ?line expect(21, [{[tDescr3,0], noSuchInstance}]), - g([[sysDescr,3]]), - ?line expect(22, [{[sysDescr, 3], noSuchInstance}]), - g([[tIndex,1]]), - ?line expect(23, [{[tIndex, 1], noSuchInstance}]), - - %% 4.2.1 - any other error: genErr - g([[tGenErr1, 0]]), - ?line expect(30, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), - g([[tGenErr2, 0]]), - ?line expect(31, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), - g([[sysDescr, 0], [tGenErr3, 0]]), - ?line expect(32, genErr, 2, [{[sysDescr, 0], 'NULL'}, - {[tGenErr3, 0], 'NULL'}]), - - %% 4.2.1 - tooBig - g([[tTooBig, 0]]), - ?line expect(40, tooBig, 0, []). - - -v2_get_next_p() -> - %% 4.2.2:2 - ?DBG("v2_get_next_p -> entry",[]), - gn([[1,3,7,1]]), - ?line expect(10, [{[1,3,7,1], endOfMibView}]), - gn([[sysDescr], [1,3,7,1]]), - ?line expect(11, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}]), - gn([[tCnt2, 1]]), - ?line expect(12, [{[tCnt2,2], 100}]), - gn([[tCnt2, 2]]), - ?line expect(12, [{[tCnt2,2], endOfMibView}]), - - %% 4.2.2 - any other error: genErr - gn([[tGenErr1]]), - ?line expect(20, genErr, 1, [{[tGenErr1], 'NULL'}]), - gn([[tGenErr2]]), - ?line expect(21, genErr, 1, [{[tGenErr2], 'NULL'}]), - gn([[sysDescr], [tGenErr3]]), - ?line expect(22, genErr, 2, [{[sysDescr], 'NULL'}, - {[tGenErr3], 'NULL'}]), - - %% 4.2.2 - tooBig - gn([[tTooBig]]), - ?line expect(20, tooBig, 0, []). - -v2_get_bulk_p() -> - %% 4.2.3 - ?DBG("v2_get_bulk_p -> entry",[]), - gb(1, 1, []), - ?line expect(10, []), - gb(-1, 1, []), - ?line expect(11, []), - gb(-1, -1, []), - ?line expect(12, []), - gb(-1, -1, []), - ?line expect(13, []), - gb(2, 0, [[sysDescr], [1,3,7,1]]), - ?line expect(14, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}]), - gb(1, 2, [[sysDescr], [1,3,7,1]]), - ?line expect(15, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}]), - gb(0, 2, [[sysDescr], [1,3,7,1]]), - ?line expect(16, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}, - {[sysObjectID, 0], [1,2,3]}, - {[1,3,7,1], endOfMibView}]), - - gb(2, 2, [[sysDescr], [1,3,7,1], [sysDescr], [1,3,7,1]]), - ?line expect(17, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}, - {[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}, - {[sysObjectID, 0], [1,2,3]}, - {[1,3,7,1], endOfMibView}]), - - gb(1, 2, [[sysDescr], [sysDescr], [tTooBig]]), - ?line expect(18, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[sysDescr, 0], "Erlang SNMP agent"}]), - - gb(1,12, [[tDescr2], [sysDescr]]), % next one after tDescr2 is tTooBig. - ?line expect(19, []), - - gb(2,2, [[sysDescr], [sysObjectID], [tGenErr1], [sysDescr]]), - ?line expect(20, genErr, 3, [{[sysDescr], 'NULL'}, - {[sysObjectID], 'NULL'}, - {[tGenErr1], 'NULL'}, - {[sysDescr], 'NULL'}]), - gb(0, 2, [[tCnt2, 1]]), - ?line expect(21, [{[tCnt2,2], 100}, - {[tCnt2,2], endOfMibView}]). - - -v2_set_p() -> - %% 4.2.5:1 - ?DBG("v2_set_p -> entry",[]), - s([{[1,3,7,0], i, 4}]), - ?line expect(10, noAccess, 1, [{[1,3,7,0], 4}]), - s([{[tDescr,0], s, "outside mibview"}]), - ?line expect(11, noAccess, 1, [{[tDescr,0], "outside mibview"}]), - - %% 4.2.5:2 - s([{[1,3,6,1,0], s, "noSuchObject"}]), - ?line expect(20, notWritable, 1, [{[1,3,6,1,0], "noSuchObject"}]), - - %% 4.2.5:3 - s([{[tDescr2, 0], i, 4}]), - ?line expect(30, wrongType, 1, [{[tDescr2, 0], 4}]), - s([{[tDescr2, 0], s, "badValue"}]), - ?line expect(31, badValue, 1, [{[tDescr2, 0], "badValue"}]), - - %% 4.2.5:4 - s([{[tStr, 0], s, ""}]), - ?line expect(40, wrongLength, 1, [{[tStr, 0], ""}]), - s([{[tStr, 0], s, "12345"}]), - ?line expect(40, wrongLength, 1, [{[tStr, 0], "12345"}]), - - %% 4.2.5:5 - N/A - - %% 4.2.5:6 - s([{[tInt1, 0], i, 0}]), - ?line expect(60, wrongValue, 1, [{[tInt1, 0], 0}]), - s([{[tInt1, 0], i, 5}]), - ?line expect(61, wrongValue, 1, [{[tInt1, 0], 5}]), - s([{[tInt2, 0], i, 0}]), - ?line expect(62, wrongValue, 1, [{[tInt2, 0], 0}]), - s([{[tInt2, 0], i, 5}]), - ?line expect(63, wrongValue, 1, [{[tInt2, 0], 5}]), - s([{[tInt3, 0], i, 5}]), - ?line expect(64, wrongValue, 1, [{[tInt3, 0], 5}]), - - %% 4.2.5:7 - s([{[tDescrX, 1, 1], s, "noCreation"}]), - ?line expect(70, noCreation, 1, [{[tDescrX, 1, 1], "noCreation"}]), - - %% 4.2.5:8 - s([{[tDescrX, 1, 2], s, "inconsistentName"}]), - ?line expect(80, inconsistentName, 1, - [{[tDescrX, 1, 2], "inconsistentName"}]), - - %% 4.2.5:9 - s([{[tCnt, 1, 2], i, 5}]), - ?line expect(90, notWritable, 1, [{[tCnt, 1, 2], 5}]), - s([{[tDescr3,0], s, "read-only"}]), - ?line expect(90, notWritable, 1, [{[tDescr3,0], "read-only"}]), - - %% 4.2.5:10 - s([{[tDescr2,0], s, "inconsistentValue"}]), - ?line expect(100, inconsistentValue, 1, - [{[tDescr2,0], "inconsistentValue"}]), - - %% 4.2.5:11 - s([{[tDescr2,0], s, "resourceUnavailable"}]), - ?line expect(110, resourceUnavailable, 1, - [{[tDescr2,0],"resourceUnavailable"}]), - - %% 4.2.5:12 - s([{[tDescr2, 0], s, "is_set_ok_fail"}]), - ?line expect(120, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]). - - %% commitFailed and undoFailed is tested by the 'undo' case. - - -%% Req. OLD-SNMPEA-MIB -table_test() -> - io:format("Testing simple get, next and set on communityTable...~n"), -%% {[147,214,36,45], "public", 2, readWrite}. -%% {[147,214,36,45], "standard trap", 2, read}. - Key1c3 = [intCommunityViewIndex,get(mip),is("public")], - Key2c3 = [intCommunityViewIndex,get(mip),is("standard trap")], - Key1c4 = [intCommunityAccess,get(mip),is("public")], - EndKey = [intCommunityEntry,[9],get(mip),is("public")], - gn([[intCommunityEntry]]), - ?line expect(7, [{Key1c3, 2}]), - gn([[intCommunityTable]]), - ?line expect(71, [{Key1c3, 2}]), - gn([[community]]), - ?line expect(72, [{Key1c3, 2}]), - gn([[otpSnmpeaMIB]]), - ?line expect(73, [{Key1c3, 2}]), - gn([[ericsson]]), - ?line expect(74, [{Key1c3, 2}]), - gn([Key1c3]), - ?line expect(8, [{Key2c3, 2}]), - gn([Key2c3]), - ?line expect(9, [{Key1c4, 2}]), - gn([EndKey]), - AgentIp = [intAgentIpAddress,0], - ?line expect(10, [{AgentIp, any}]), - g([Key1c3]), - ?line expect(11, [{Key1c3, 2}]), - g([EndKey]), - ?line ?v1_2(expect(12, noSuchName, 1, any), - expect(12, [{EndKey, noSuchObject}])), - - io:format("Testing row creation/deletion on communityTable...~n"), - NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], - NewKeyc4 = [intCommunityAccess,get(mip),is("test")], - NewKeyc5 = [intCommunityStatus,get(mip),is("test")], - s([{NewKeyc5, ?createAndGo}]), - ?line expect(14, ?v1_2(badValue, inconsistentValue), 1,any), - s([{NewKeyc5, ?createAndGo}, {NewKeyc3, 2}, {NewKeyc4, 2}]), - ?line expect(15, [{NewKeyc5, ?createAndGo},{NewKeyc3, 2}, {NewKeyc4, 2}]), - g([NewKeyc4]), - ?line expect(16, [{NewKeyc4, 2}]), - s([{NewKeyc5, ?destroy}]), - ?line expect(17, [{NewKeyc5, ?destroy}]), - s([{NewKeyc4, 2}]), - ?line expect(18, ?v1_2(noSuchName, inconsistentName), 1,[{NewKeyc4, 2}]), - s([{NewKeyc5, ?createAndWait}]), - ?line expect(19, [{NewKeyc5, ?createAndWait}]), - g([NewKeyc5]), - ?line expect(20, [{NewKeyc5, ?notReady}]), - s([{NewKeyc4, 2}]), - ?line expect(21, [{NewKeyc4, 2}]), - g([NewKeyc5]), - ?line expect(22, [{NewKeyc5, ?notReady}]), - s([{NewKeyc3, 2}]), - ?line expect(23, [{NewKeyc3, 2}]), - g([NewKeyc5]), - ?line expect(24, [{NewKeyc5, ?notInService}]), - s([{NewKeyc5, ?active}]), - ?line expect(25, [{NewKeyc5, ?active}]), - s([{NewKeyc5, ?destroy}]), - ?line expect(26, [{NewKeyc5, ?destroy}]), - s([{NewKeyc3, 3}]), - ?line expect(27, ?v1_2(noSuchName, inconsistentName), 1,[{NewKeyc3, 3}]), - otp_1128(). - -%% Req. system group -simple_standard_test() -> - ?DBG("simple_standard_test -> entry",[]), - gn([[1,1]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3]]), - ?line expect(11, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6]]), - ?line expect(12, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6,1]]), - ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6,1,2]]), - ?line expect(14, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6,1,2,1]]), - ?line expect(15, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6,1,2,1,1]]), - ?line expect(16, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[sysDescr]]), - ?line expect(17, [{[sysDescr,0], "Erlang SNMP agent"}]), - g([[sysDescr,0]]), - ?line expect(2, [{[sysDescr,0], "Erlang SNMP agent"}]), - g([[sysDescr]]), - ?line ?v1_2(expect(3, noSuchName, 1, any), - expect(3, [{[sysDescr], noSuchObject}])), - g([[1,6,7,0]]), - ?line ?v1_2(expect(41, noSuchName, 1, any), - expect(3, [{[1,6,7,0], noSuchObject}])), - gn([[1,13]]), - ?line ?v1_2(expect(4, noSuchName,1, any), - expect(4, [{[1,13], endOfMibView}])), - s([{[sysLocation, 0], "new_value"}]), - ?line expect(5, [{[sysLocation, 0], "new_value"}]), - g([[sysLocation, 0]]), - ?line expect(6, [{[sysLocation, 0], "new_value"}]), - io:format("Testing noSuchName and badValue...~n"), - s([{[sysServices,0], 3}]), - ?line expect(61, ?v1_2(noSuchName, notWritable), 1, any), - s([{[sysLocation, 0], i, 3}]), - ?line expect(62, ?v1_2(badValue, wrongType), 1, any), - ?DBG("simple_standard_test -> done",[]), - ok. - -%% This is run in the agent node -db_notify_client(suite) -> []; -db_notify_client(Config) when list(Config) -> - {SaNode, MgrNode, MibDir} = init_case(Config), - ?DBG("~n\tSaNode: ~p~n\tMgrNode: ~p~n\tMibDir: ~p", - [SaNode,MgrNode,MibDir]), - snmpa_local_db:register_notify_client(self(),?MODULE), - - %% This call (the manager) will issue to set operations, so - %% we expect to receive to notify(insert) calls. - try_test(db_notify_client_test), - - ?DBG("await first notify",[]), - receive - {db_notify_test_reply,insert} -> ?DBG("first notify received",[]),ok - end, - - ?DBG("await second notify",[]), - receive - {db_notify_test_reply,insert} -> ?DBG("second notify received",[]),ok - end, - - snmpa_local_db:unregister_notify_client(self()). - - -%% This is run in the manager node -db_notify_client_test() -> - ?DBG("set first new sysLocation",[]), - s([{[sysLocation, 0], "new_value"}]), - ?line expect(5, [{[sysLocation, 0], "new_value"}]), - - ?DBG("set second new sysLocation",[]), - s([{[sysLocation, 0], "new_value"}]), - ?line expect(5, [{[sysLocation, 0], "new_value"}]). - -notify(Pid,What) -> - ?DBG("notify(~p,~p) -> called",[Pid,What]), - Pid ! {db_notify_test_reply,What}. - - -%% Req: system group, OLD-SNMPEA-MIB, Klas1 -big_test() -> - ?DBG("big_test -> testing simple next/get/set @ master agent...",[]), - simple_standard_test(), - - ?DBG("big_test -> testing simple next/get/set @ subagent...",[]), - gn([[klas1]]), - ?line expect(1, [{[fname,0], ""}]), - g([[fname,0]]), - ?line expect(2, [{[fname,0], ""}]), - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - g([[fname,0]]), - ?line expect(4, [{[fname,0], "test set"}]), - - ?DBG("big_test -> " - "testing next from last instance in master to subagent...",[]), - gn([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(5, [{[fname,0], "test set"}]), - gn([[1,1], - [?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, - {[fname,0], "test set"}]), - s([{[fname,0], s, ""}]), - ?line expect(52, [{[fname,0], ""}]), - - table_test(), - - ?DBG("big_test -> adding one row in subagent table",[]), - _FTab = [friendsEntry], - s([{[friendsEntry, [2, 3]], s, "kompis3"}, - {[friendsEntry, [3, 3]], i, ?createAndGo}]), - ?line expect(6, [{[friendsEntry, [2, 3]], "kompis3"}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - g([[friendsEntry, [2, 3]], - [friendsEntry, [3, 3]]]), - ?line expect(7, [{[friendsEntry, [2, 3]], "kompis3"}, - {[friendsEntry, [3, 3]], ?active}]), - s([{[friendsEntry, [3, 3]], i, ?destroy}]), - ?line expect(8, [{[friendsEntry, [3, 3]], ?destroy}]), - - otp_1131(), - - ?DBG("big_test -> adding two rows in subagent table with special INDEX", - []), - s([{[kompissEntry, [1, 3]], s, "kompis3"}, - {[kompissEntry, [2, 3]], i, ?createAndGo}]), - ?line expect(9, [{[kompissEntry, [1, 3]], "kompis3"}, - {[kompissEntry, [2, 3]], ?createAndGo}]), - g([[kompissEntry, [1, 3]], - [kompissEntry, [2, 3]]]), - ?line expect(10, [{[kompissEntry, [1, 3]], "kompis3"}, - {[kompissEntry, [2, 3]], ?active}]), - gn([[kompissEntry, [1]], - [kompissEntry, [2]]]), - ?line expect(11, [{[kompissEntry, [1, 3]], "kompis3"}, - {[kompissEntry, [2, 3]], ?active}]), - s([{[kompissEntry, [1, 2]], s, "kompis3"}, - {[kompissEntry, [2, 2]], i, ?createAndGo}]), - ?line expect(12, [{[kompissEntry, [1, 2]], "kompis3"}, - {[kompissEntry, [2, 2]], ?createAndGo}]), - gn([[kompissEntry, [1, 1]], - [kompissEntry, [2, 1]]]), - ?line expect(13, [{[kompissEntry, [1, 2]], "kompis3"}, - {[kompissEntry, [2, 2]], ?active}]), - s([{[kompissEntry, [2, 3]], i, ?destroy}]), - ?line expect(14, [{[kompissEntry, [2, 3]], ?destroy}]), - s([{[kompissEntry, [2, 2]], i, ?destroy}]), - ?line expect(15, [{[kompissEntry, [2, 2]], ?destroy}]), - ?DBG("big_test -> done",[]), - ok. - -%% Req. system group, Klas2, OLD-SNMPEA-MIB -big_test_2() -> - p("Testing simple next/get/set @ master agent (2)..."), - simple_standard_test(), - - p("Testing simple next/get/set @ subagent (2)..."), - gn([[klas2]]), - ?line expect(1, [{[fname2,0], ""}]), - g([[fname2,0]]), - ?line expect(2, [{[fname2,0], ""}]), - s([{[fname2,0], s, "test set"}]), - ?line expect(3, [{[fname2,0], "test set"}]), - g([[fname2,0]]), - ?line expect(4, [{[fname2,0], "test set"}]), - - otp_1298(), - - p("Testing next from last object in master to subagent (2)..."), - gn([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(5, [{[fname2,0], "test set"}]), - gn([[1,1], - [?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, - {[fname2,0], "test set"}]), - - table_test(), - - p("Adding one row in subagent table (2)"), - _FTab = [friendsEntry2], - s([{[friendsEntry2, [2, 3]], s, "kompis3"}, - {[friendsEntry2, [3, 3]], i, ?createAndGo}]), - ?line expect(6, [{[friendsEntry2, [2, 3]], "kompis3"}, - {[friendsEntry2, [3, 3]], ?createAndGo}]), - g([[friendsEntry2, [2, 3]], - [friendsEntry2, [3, 3]]]), - ?line expect(7, [{[friendsEntry2, [2, 3]], "kompis3"}, - {[friendsEntry2, [3, 3]], ?active}]), - s([{[friendsEntry2, [3, 3]], i, ?destroy}]), - ?line expect(8, [{[friendsEntry2, [3, 3]], ?destroy}]), - - p("Adding two rows in subagent table with special INDEX (2)"), - s([{[kompissEntry2, [1, 3]], s, "kompis3"}, - {[kompissEntry2, [2, 3]], i, ?createAndGo}]), - ?line expect(9, [{[kompissEntry2, [1, 3]], "kompis3"}, - {[kompissEntry2, [2, 3]], ?createAndGo}]), - g([[kompissEntry2, [1, 3]], - [kompissEntry2, [2, 3]]]), - ?line expect(10, [{[kompissEntry2, [1, 3]], "kompis3"}, - {[kompissEntry2, [2, 3]], ?active}]), - gn([[kompissEntry2, [1]], - [kompissEntry2, [2]]]), - ?line expect(11, [{[kompissEntry2, [1, 3]], "kompis3"}, - {[kompissEntry2, [2, 3]], ?active}]), - s([{[kompissEntry2, [1, 2]], s, "kompis3"}, - {[kompissEntry2, [2, 2]], i, ?createAndGo}]), - ?line expect(12, [{[kompissEntry2, [1, 2]], "kompis3"}, - {[kompissEntry2, [2, 2]], ?createAndGo}]), - gn([[kompissEntry2, [1, 1]], - [kompissEntry2, [2, 1]]]), - ?line expect(13, [{[kompissEntry2, [1, 2]], "kompis3"}, - {[kompissEntry2, [2, 2]], ?active}]), - s([{[kompissEntry2, [2, 3]], i, ?destroy}]), - ?line expect(14, [{[kompissEntry2, [2, 3]], ?destroy}]), - s([{[kompissEntry2, [2, 2]], i, ?destroy}]), - ?line expect(15, [{[kompissEntry2, [2, 2]], ?destroy}]), - ok. - -%% Req. Test1 -multi_threaded_test() -> - p("Testing multi threaded agent..."), - g([[multiStr,0]]), - Pid = get_multi_pid(), - g([[sysUpTime,0]]), - ?line expect(1, [{[sysUpTime,0], any}]), - s([{[sysLocation, 0], s, "pelle"}]), - ?line expect(2, [{[sysLocation, 0], "pelle"}]), - Pid ! continue, - ?line expect(3, [{[multiStr,0], "ok"}]), - - s([{[multiStr, 0], s, "block"}]), - Pid2 = get_multi_pid(), - g([[sysUpTime,0]]), - ?line expect(4, [{[sysUpTime,0], any}]), - g([[multiStr,0]]), - Pid3 = get_multi_pid(), - g([[sysUpTime,0]]), - ?line expect(5, [{[sysUpTime,0], any}]), - s([{[sysLocation, 0], s, "kalle"}]), - Pid3 ! continue, - ?line expect(6, [{[multiStr,0], "ok"}]), - Pid2 ! continue, - ?line expect(7, [{[multiStr,0], "block"}]), - ?line expect(8, [{[sysLocation,0], "kalle"}]). - -%% Req. Test1, TestTrapv2 -mt_trap_test(MA) -> - snmpa:send_trap(MA, testTrapv22, "standard trap"), - ?line expect(1, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - - snmpa:send_trap(MA, mtTrap, "standard trap"), - Pid = get_multi_pid(), - g([[sysUpTime,0]]), - ?line expect(2, [{[sysUpTime,0], any}]), - snmpa:send_trap(MA, testTrapv22, "standard trap"), - ?line expect(3, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - Pid ! continue, - ?line expect(4, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?testTrap ++ [2]}, - {[multiStr,0], "ok"}]). - - -get_multi_pid() -> - get_multi_pid(10). -get_multi_pid(0) -> - ?line ?FAIL(no_global_name); -get_multi_pid(N) -> - sleep(1000), - case global:whereis_name(snmp_multi_tester) of - Pid when pid(Pid) -> Pid; - _ -> get_multi_pid(N-1) - end. - -%% Req. Test1 -types_v2_test() -> - p("Testing v2 types..."), - - s([{[bits1,0], 2#10}]), - ?line expect(1, [{[bits1,0], ?str(2#10)}]), - g([[bits1,0]]), - ?line expect(2, [{[bits1,0], ?str(2#101)}]), - - s([{[bits2,0], 2#11000000110}]), - ?line expect(3, [{[bits2,0], ?str(2#11000000110)}]), - g([[bits2,0]]), - ?line expect(4, [{[bits2,0], ?str(2#11000000110)}]), - - g([[bits3,0]]), - ?line expect(50, genErr, 1, any), - - g([[bits4,0]]), - ?line expect(51, genErr, 1, any), - - s([{[bits1,0], s, [2#10]}]), - ?line expect(6, ?v1_2(badValue, wrongValue), 1, any), - - s([{[bits2,0], 2#11001001101010011}]), - ?line expect(7, ?v1_2(badValue, wrongValue), 1, any). - - -%% Req. Test1 -implied_test(MA) -> - ?LOG("implied_test -> start",[]), - p("Testing IMPLIED..."), - - snmpa:verbosity(MA,trace), - snmpa:verbosity(MA,trace), - - %% Create two rows, check that they are get-nexted in correct order. - Idx1 = "apa", - Idx2 = "qq", - ?DBG("implied_test -> (send) create row 1 '~s' in table 1",[Idx1]), - s([{[testStatus, Idx1], i, ?createAndGo}, {[testDescr, Idx1],s,"row 1"}]), - ?line expect(1, [{[testStatus, Idx1], ?createAndGo}, - {[testDescr, Idx1], "row 1"}]), - ?DBG("implied_test -> (send) create row 2 '~s' in table 1",[Idx2]), - s([{[testStatus, Idx2], i, ?createAndGo}, {[testDescr, Idx2],s,"row 2"}]), - ?line expect(2, [{[testStatus, Idx2], ?createAndGo}, - {[testDescr, Idx2], "row 2"}]), - ?DBG("implied_test -> get-next(testDescr)",[]), - gn([[testDescr]]), - ?line expect(3, [{[testDescr,Idx1], "row 1"}]), - ?DBG("implied_test -> get-next(testDescr) of row 1",[]), - gn([[testDescr,Idx1]]), - ?line expect(4, [{[testDescr,Idx2], "row 2"}]), - - % Delete the rows - ?DBG("implied_test -> (send) delete row 1 '~s' from table 1",[Idx1]), - s([{[testStatus, Idx1], i, ?destroy}]), - ?line expect(5, [{[testStatus, Idx1], ?destroy}]), - ?DBG("implied_test -> (send) delete row 2 '~s' from table 1",[Idx2]), - s([{[testStatus, Idx2], i, ?destroy}]), - ?line expect(6, [{[testStatus, Idx2], ?destroy}]), - - %% Try the same in other table - Idx3 = [1, "apa"], - Idx4 = [1, "qq"], - ?DBG("implied_test -> (send) create row 1 '~s' in table 2",[Idx3]), - s([{[testStatus2, Idx3], i, ?createAndGo}, {[testDescr2,Idx3],s,"row 1"}]), - ?line expect(1, [{[testStatus2, Idx3], ?createAndGo}, - {[testDescr2, Idx3], "row 1"}]), - ?DBG("implied_test -> (send) create row 2 '~s' in table 2",[Idx4]), - s([{[testStatus2, Idx4], i, ?createAndGo}, {[testDescr2,Idx4],s,"row 2"}]), - ?line expect(2, [{[testStatus2, Idx4], ?createAndGo}, - {[testDescr2, Idx4], "row 2"}]), - ?DBG("implied_test -> get-next(testDescr2)",[]), - gn([[testDescr2]]), - ?line expect(3, [{[testDescr2,Idx3], "row 1"}]), - ?DBG("implied_test -> get-next(testDescr2) of row 1",[]), - gn([[testDescr2,Idx3]]), - ?line expect(4, [{[testDescr2,Idx4], "row 2"}]), - - % Delete the rows - ?DBG("implied_test -> (send) delete row 1 '~s' from table 2",[Idx3]), - s([{[testStatus2, Idx3], i, ?destroy}]), - ?line expect(5, [{[testStatus2, Idx3], ?destroy}]), - ?DBG("implied_test -> (send) delete row 2 '~s' from table 2",[Idx4]), - s([{[testStatus2, Idx4], i, ?destroy}]), - ?line expect(6, [{[testStatus2, Idx4], ?destroy}]), - - snmpa:verbosity(MA,log), - - ?LOG("implied_test -> done",[]). - - - -%% Req. Test1 -sparse_table_test() -> - p("Testing sparse table..."), - - %% Create two rows, check that they are get-nexted in correct order. - Idx1 = 1, - Idx2 = 2, - s([{[sparseStatus, Idx1], i, ?createAndGo}, - {[sparseDescr, Idx1], s, "row 1"}]), - ?line expect(1, [{[sparseStatus, Idx1], ?createAndGo}, - {[sparseDescr, Idx1], "row 1"}]), - s([{[sparseStatus, Idx2], i, ?createAndGo}, - {[sparseDescr, Idx2], s, "row 2"}]), - ?line expect(2, [{[sparseStatus, Idx2], ?createAndGo}, - {[sparseDescr, Idx2], "row 2"}]), - ?v1_2(gn([[sparseIndex], [sparseDescr,Idx1], [sparseDescr,Idx2], - [sparseStatus,Idx1], [sparseStatus,Idx2]]), - gb(0,5,[[sparseIndex]])), - ?line expect(3, [{[sparseDescr,Idx1], "row 1"}, - {[sparseDescr,Idx2], "row 2"}, - {[sparseStatus,Idx1], ?active}, - {[sparseStatus,Idx2], ?active}, - {[sparseStr,0], "slut"}]), - % Delete the rows - s([{[sparseStatus, Idx1], i, ?destroy}]), - ?line expect(4, [{[sparseStatus, Idx1], ?destroy}]), - s([{[sparseStatus, Idx2], i, ?destroy}]), - ?line expect(5, [{[sparseStatus, Idx2], ?destroy}]). - - -%% Req. Test1 -cnt_64_test(MA) -> - ?LOG("start cnt64 test (~p)",[MA]), - snmpa:verbosity(MA,trace), - ?LOG("start cnt64 test",[]), - p("Testing Counter64, and at the same time, RowStatus is not last column"), - - ?DBG("get cnt64",[]), - g([[cnt64,0]]), - ?DBG("await response",[]), - ?line ?v1_2(expect(1, noSuchName, 1, any), - expect(1, [{[cnt64,0],18446744073709551615}])), - ?DBG("get-next cnt64",[]), - gn([[cnt64]]), - ?DBG("await response",[]), - ?line ?v1_2(expect(2, [{[cnt64Str,0], "after cnt64"}]), - expect(2, [{[cnt64,0],18446744073709551615}])), - ?DBG("send cntTrap",[]), - snmpa:send_trap(MA,cntTrap,"standard trap",[{sysContact,"pelle"}, - {cnt64, 10}, - {sysLocation, "here"}]), - ?DBG("await response",[]), - ?line ?v1_2(expect(3, trap, [test], 6, 1, [{[sysContact,0], "pelle"}, - {[sysLocation,0], "here"}]), - expect(3, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?testTrap ++ [1]}, - {[sysContact,0], "pelle"}, - {[cnt64,0], 10}, - {[sysLocation,0], "here"}])), - - %% Create two rows, check that they are get-nexted in correct order. - Idx1 = 1, - Idx2 = 2, - ?DBG("create row (cntStatus): ~p",[Idx1]), - s([{[cntStatus, Idx1], i, ?createAndGo}]), - ?DBG("await response",[]), - ?line expect(1, [{[cntStatus, Idx1], ?createAndGo}]), - ?DBG("create row (cntStatus): ~p",[Idx2]), - s([{[cntStatus, Idx2], i, ?createAndGo}]), - ?DBG("await response",[]), - ?line expect(2, [{[cntStatus, Idx2], ?createAndGo}]), - - ?DBG("get-next (cntIndex)",[]), - gn([[cntIndex]]), - ?DBG("await response",[]), - ?line ?v1_2(expect(3, [{[cntStatus,Idx1], ?active}]), - expect(3, [{[cntCnt,Idx1], 0}])), - % Delete the rows - ?DBG("delete row (cntStatus): ~p",[Idx1]), - s([{[cntStatus, Idx1], i, ?destroy}]), - ?DBG("await response",[]), - ?line expect(4, [{[cntStatus, Idx1], ?destroy}]), - ?DBG("delete row (cntStatus): ~p",[Idx2]), - s([{[cntStatus, Idx2], i, ?destroy}]), - ?DBG("await response",[]), - ?line expect(5, [{[cntStatus, Idx2], ?destroy}]), - catch snmpa:verbosity(MA,log), - ?DBG("done",[]), - ok. - -%% Req. Test1 -opaque_test() -> - p("Testing Opaque datatype..."), - g([[opaqueObj,0]]), - ?line expect(1, [{[opaqueObj,0], "opaque-data"}]). - -%% Req. OLD-SNMPEA-MIB -api_test(MaNode) -> - ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, - [intAgentIpAddress]), - ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, - oid_to_name, [OID]), - ?line false = rpc:call(MaNode, snmp, name_to_oid, [intAgentIpAddres]), - ?line false = rpc:call(MaNode, snmp, oid_to_name, - [[1,5,32,3,54,3,3,34,4]]), - ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, - [intViewType, excluded]), - ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, - [intViewType, 2]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, [intViewType, exclude]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [intAgentIpAddress, exclude]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [intAgentIpAddre, exclude]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [intViewType, 3]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddress, 2]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddre, 2]), - ?line {value, active} = rpc:call(MaNode, snmp, - int_to_enum, ['RowStatus', ?active]), - ?line {value, ?destroy} = rpc:call(MaNode, snmp, - enum_to_int, ['RowStatus', destroy]), - ?line false = rpc:call(MaNode, snmp, - enum_to_int, ['RowStatus', xxxdestroy]), - ?line false = rpc:call(MaNode, snmp, - enum_to_int, ['xxRowStatus', destroy]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, ['RowStatus', 25]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, ['xxRowStatus', 1]), - ?line case snmp:date_and_time() of - List when list(List), length(List) == 8 -> ok; - List when list(List), length(List) == 11 -> ok - end. - -%% Req. Klas3 -api_test2() -> - g([[fname3,0]]), - ?line expect(1, [{[fname3,0], "ok"}]), - g([[fname4,0]]), - ?line expect(2, [{[fname4,0], 1}]). - -api_test3() -> - g([[fname3,0]]), - ?line expect(1, [{[fname3,0], "ok"}]). - - -unreg_test() -> - gn([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(1, [{[snmpInPkts, 0], any}]). - -load_test() -> - gn([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(1, [{[fname,0], ""}]). - -%% Req. Klas1 -load_test_sa() -> - gn([[?v1_2(sysServices,sysORLastChange), 0]]), - ?line expect(1, [{[fname,0], any}]). - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_get() -> - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - g([[sysDescr,0], Key1c4, [fname,0],Key1c3, - [sysName,0]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[fname,0], "test set"}, - {Key1c3, 2}, - {[sysName,0], "test"}]), - g([[1,3,7,1], Key1c4, [sysDescr,0], [1,3,7,2], Key1c3, [sysDescr,0]]), - ?line ?v1_2(expect(2, noSuchName, [1,4], any), - expect(2, [{[1,3,7,1], noSuchObject}, - {Key1c4, 2}, - {[sysDescr,0], "Erlang SNMP agent"}, - {[1,3,7,2], noSuchObject}, - {Key1c3, 2}, - {[sysDescr,0], "Erlang SNMP agent"}])). - -%% Req. v1, system group, Klas1, OLD-SNMPEA-MIB, *ej* Klas3. -do_mul_get_err() -> - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - g([[sysDescr,0],Key1c4,[fname,0], Key1c3, [sysName,2]]), - ?line ?v1_2(expect(1, noSuchName, 5, any), - expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[fname,0], "test set"}, - {Key1c3, 2}, - {[sysName,2], noSuchInstance}])), - g([[sysDescr,0],Key1c4,[fname3,0], Key1c3, [sysName,1]]), - ?line ?v1_2(expect(1, noSuchName, [3,5], any), - expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[fname3,0], noSuchObject}, - {Key1c3, 2}, - {[sysName,1], noSuchInstance}])). - - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_next() -> - Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], - Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - gn([[sysDescr], Key1c4s, [fname],Key1c3s,[sysName]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, {[fname,0], "test set"}, - {Key1c3, 2}, {[sysName,0], "test"}]). - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_next_err() -> - Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], - Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - gn([[sysDescr], Key1c4s, [1,3,6,999], [fname],[1,3,90], Key1c3s,[sysName]]), - ?line ?v1_2(expect(1, noSuchName, [3,5], any), - expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[1,3,6,999], endOfMibView}, - {[fname,0], "test set"}, - {[1,3,90], endOfMibView}, - {Key1c3, 2}, - {[sysName,0], "test"}])). - - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_set() -> - p("Adding one row in subagent table, and one in master table"), - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - s([{[friendsEntry, [2, 3]], "kompis3"}, - {NewKeyc3, 2}, - {[sysLocation,0], "new_value"}, - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - ?line expect(1, [{[friendsEntry, [2, 3]], "kompis3"}, - {NewKeyc3, 2}, - {[sysLocation,0], "new_value"}, - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - g([[friendsEntry, [2, 3]], - [sysLocation,0], - [friendsEntry, [3, 3]]]), - ?line expect(2, [{[friendsEntry, [2, 3]], "kompis3"}, - {[sysLocation,0], "new_value"}, - {[friendsEntry, [3, 3]], ?active}]), - g([NewKeyc4]), - ?line expect(3, [{NewKeyc4, 2}]), - s([{[friendsEntry, [3, 3]], ?destroy}, - {NewKeyc5, ?destroy}]), - ?line expect(4, [{[friendsEntry, [3, 3]], ?destroy}, - {NewKeyc5, ?destroy}]). - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_set_err() -> - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - p("Adding one row in subagent table, and one in master table"), - s([{[friendsEntry, [2, 3]], s, "kompis3"}, - {NewKeyc3, 2}, - {[sysUpTime,0], 45}, % sysUpTime (readOnly) - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - ?line expect(1, ?v1_2(noSuchName, notWritable), 3, any), - g([[friendsEntry, [2, 3]]]), - ?line ?v1_2(expect(2, noSuchName, 1, any), - expect(2, [{[friendsEntry, [2,3]], noSuchInstance}])), - g([NewKeyc4]), - ?line ?v1_2(expect(3, noSuchName, 1, any), - expect(3, [{NewKeyc4, noSuchInstance}])). - -%% Req. SA-MIB -sa_mib() -> - g([[sa, [2,0]]]), - ?line expect(1, [{[sa, [2,0]], 3}]), - s([{[sa, [1,0]], s, "sa_test"}]), - ?line expect(2, [{[sa, [1,0]], "sa_test"}]). - -ma_trap1(MA) -> - snmpa:send_trap(MA, testTrap2, "standard trap"), - ?line expect(1, trap, [system], 6, 1, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}]), - snmpa:send_trap(MA, testTrap1, "standard trap"), - ?line expect(2, trap, [1,2,3] , 1, 0, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}]). - -ma_trap2(MA) -> - snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). - -ma_v2_2_v1_trap(MA) -> - snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). - -ma_v2_2_v1_trap2(MA) -> - snmpa:send_trap(MA,linkUp,"standard trap",[{ifIndex, [1], 1}, - {ifAdminStatus, [1], 1}, - {ifOperStatus, [1], 2}]), - ?line expect(3, trap, [1,2,3], 3, 0, [{[ifIndex, 1], 1}, - {[ifAdminStatus, 1], 1}, - {[ifOperStatus, 1], 2}]). - -sa_trap1(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap"), - ?line expect(4, trap, [ericsson], 6, 1, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}]). - -sa_trap2(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), - ?line expect(5, trap, [ericsson], 6, 1, [{[system, [4,0]], - "pelle"}, - {[sa, [1,0]], "sa_test"}]). - -sa_trap3(SA) -> - snmpa:send_trap(SA, saTrap2, "standard trap", - [{intViewSubtree, [4], [1,2,3,4]}]), - ?line expect(6, trap, [ericsson], 6, 2, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}, - {[intViewSubtree,4],[1,2,3,4]}]). - -ma_v2_trap1(MA) -> - ?DBG("ma_v2_traps -> entry with MA = ~p => " - "send standard trap: testTrapv22",[MA]), - snmpa:send_trap(MA, testTrapv22, "standard trap"), - ?line expect(1, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - ?DBG("ma_v2_traps -> send standard trap: testTrapv21",[]), - snmpa:send_trap(MA, testTrapv21, "standard trap"), - ?line expect(2, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?snmp ++ [1]}]). - -ma_v2_trap2(MA) -> - snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}, - {[system, [4,0]], "pelle"}]). - -%% Note: This test case takes a while... actually a couple of minutes. -ma_v2_inform1(MA) -> - ?DBG("ma_v2_inform -> entry with MA = ~p => " - "send notification: testTrapv22",[MA]), - ?line snmpa:send_notification(MA, testTrapv22, no_receiver, "standard inform", []), - ?line expect(1, {inform, true}, - [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - - ?DBG("ma_v2_inform -> send notification: testTrapv22",[]), - snmpa:send_notification(MA, testTrapv22, {tag1, self()}, - "standard inform", []), - ?line expect(1, {inform, true}, - [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - ?DBG("ma_v2_inform -> await targets",[]), - receive - {snmp_targets, tag1, [_]} -> - ok; - {snmp_targets, tag1, Addrs1} -> - ?line ?FAIL({bad_addrs, Addrs1}) - after - 5000 -> - ?ERR("ma_v2_inform1 -> awaiting snmp_targets(tag1) timeout",[]), - ?line ?FAIL(nothing_at_all) - end, - ?DBG("ma_v2_inform -> await notification",[]), - receive - {snmp_notification, tag1, {got_response, _}} -> - ok; - {snmp_notification, tag1, {no_response, _}} -> - ?line ?FAIL(no_response) - after - 20000 -> - ?ERR("ma_v2_inform1 -> " - "awaiting snmp_notification(tag1) timeout",[]), - ?line ?FAIL(nothing_at_all) - end, - - %% - %% -- The rest is possibly erroneous... - %% - - ?DBG("ma_v2_inform -> send notification: testTrapv22",[]), - snmpa:send_notification(MA, testTrapv22, {tag2, self()}, - "standard inform", []), - ?line expect(2, {inform, false}, - [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - ?DBG("ma_v2_inform -> await targets",[]), - receive - {snmp_targets, tag2, [_]} -> - ok; - {snmp_targets, tag2, Addrs2} -> - ?ERR("ma_v2_inform1 -> awaiting snmp_targets(tag2) timeout",[]), - ?line ?FAIL({bad_addrs, Addrs2}) - after - 5000 -> - ?line ?FAIL(nothing_at_all) - end, - ?DBG("ma_v2_inform -> await notification",[]), - receive - {snmp_notification, tag2, {got_response, _}} -> - ?line ?FAIL(got_response); - {snmp_notification, tag2, {no_response, _}} -> - ok - after - 240000 -> - ?ERR("ma_v2_inform1 -> " - "awaiting snmp_notification(tag2) timeout",[]), - ?line ?FAIL(nothing_at_all) - end. - - -ma_v1_2_v2_trap(MA) -> - snmpa:send_trap(MA,linkDown,"standard trap",[{ifIndex, [1], 1}]), - ?line expect(2, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?snmpTraps ++ [3]}, - {[ifIndex, 1], 1}, - {[snmpTrapEnterprise, 0], [1,2,3]}]). - - -ma_v1_2_v2_trap2(MA) -> - snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}, - {[system, [4,0]], "pelle"}, - {[snmpTrapEnterprise, 0], ?system}]). - - -sa_v1_2_v2_trap1(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap"), - ?line expect(4, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, - {[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}, - {[snmpTrapEnterprise, 0], ?ericsson}]). - -sa_v1_2_v2_trap2(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), - ?line expect(4, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, - {[system, [4,0]], "pelle"}, - {[sa, [1,0]], "sa_test"}, - {[snmpTrapEnterprise, 0], ?ericsson}]). - - -sa_v1_2_v2_trap3(SA) -> - snmpa:send_trap(SA, saTrap2, "standard trap", - [{intViewSubtree, [4], [1,2,3,4]}]), - ?line expect(4, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?ericsson ++ [0, 2]}, - {[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}, - {[intViewSubtree,4],[1,2,3,4]}, - {[snmpTrapEnterprise, 0], ?ericsson}]). - - -%% Req. SA-MIB, OLD-SNMPEA-MIB -sa_errs_bad_value() -> - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - s([{NewKeyc3, 2}, - {[sa, [2,0]], 5}, % badValue (i is_set_ok) - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}]), - ?line expect(1, badValue, 2, any), - s([{NewKeyc3, 2}, - {[sa, [2,0]], 6}, % wrongValue (i is_set_ok) - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}]), - ?line expect(1, ?v1_2(badValue, wrongValue), 2, any), - g([NewKeyc4]), - ?line ?v1_2(expect(2, noSuchName, 1, any), - expect(2, [{NewKeyc4, noSuchInstance}])). - -%% Req. SA-MIB, OLD-SNMPEA-MIB -sa_errs_gen_err() -> - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - s([{NewKeyc3, 2},{NewKeyc4, 2}, - {NewKeyc5, ?createAndGo}, {[sa, [3,0]], 5}]), - ?line expect(1, genErr, 4, any), -% The row might have been added; we don't know. -% (as a matter of fact we do - it is added, because the agent -% first sets its own vars, and then th SAs. Lets destroy it. - s([{NewKeyc5, ?destroy}]), - ?line expect(2, [{NewKeyc5, ?destroy}]). - -%% Req. SA-MIB, OLD-SNMPEA-MIB -sa_too_big() -> - g([[sa, [4,0]]]), - ?line expect(1, tooBig). - -%% Req. Klas1, system group, snmp group (v1/v2) -next_across_sa() -> - gn([[sysDescr],[klas1,5]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {[snmpInPkts, 0], any}]). - -%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]). -> noError -%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]). -> {badValue, 2} -%% snmp_test_mgr:s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]). -> {genErr, 1} -%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]). -> {genErr, 1} -%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]). -> {genErr, 1} -%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]). -> {genErr, 2} -%% Req. Klas3, Klas4 -undo_test() -> - s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), - ?line expect(1, [{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), - s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]), - ?line expect(2, ?v1_2(badValue, inconsistentValue), 2, any), - s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]), - ?line expect(3, ?v1_2(genErr, undoFailed), 1, any), - s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]), - ?line expect(4, ?v1_2(genErr, commitFailed), 1, any), -% unfortunatly we don't know if we'll get undoFailed or commitFailed. -% it depends on which order the agent traverses the varbind list. -% s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]), -% ?line expect(5, ?v1_2(genErr, undoFailed), 1, any), - s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]), - ?line expect(6, genErr, 2, any). - -%% Req. Klas3, Klas4 -bad_return() -> - g([[fStatus4,4], - [fName4,4]]), - ?line expect(4, genErr, 2, any), - g([[fStatus4,5], - [fName4,5]]), - ?line expect(5, genErr, 1, any), - g([[fStatus4,6], - [fName4,6]]), - ?line expect(6, genErr, 2, any), - gn([[fStatus4,7], - [fName4,7]]), - ?line expect(7, genErr, 2, any), - gn([[fStatus4,8], - [fName4,8]]), - ?line expect(8, genErr, 1, any), - gn([[fStatus4,9], - [fName4,9]]), - ?line expect(9, genErr, 2, any). - - -%%%----------------------------------------------------------------- -%%% Test the implementation of standard mibs. -%%% We should *at least* try to GET all variables, just to make -%%% sure the instrumentation functions work. -%%% Note that many of the functions in the standard mib is -%%% already tested by the normal tests. -%%%----------------------------------------------------------------- - - - -%%----------------------------------------------------------------- -%% For this test, the agent is configured for v1. -%% o Test the counters and control objects in SNMP-STANDARD-MIB -%%----------------------------------------------------------------- -snmp_standard_mib(suite) -> []; -snmp_standard_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?DBG("snmp_standard_mib -> std_mib_init", []), - try_test(std_mib_init), - - ?DBG("snmp_standard_mib -> std_mib_a", []), - InBadVsns = try_test(std_mib_a), - put(vsn, v2), - ?DBG("snmp_standard_mib -> std_mib_read", []), - try_test(std_mib_read), - put(vsn, v1), - - ?DBG("snmp_standard_mib -> std_mib_b (~w)", [InBadVsns]), - Bad = try_test(std_mib_b, [InBadVsns]), - ?DBG("snmp_standard_mib -> std_mib_read (community: 'bad community')", []), - try_test(std_mib_read, [], [{community, "bad community"}]), - ?DBG("snmp_standard_mib -> std_mib_write (community: 'public')", []), - try_test(std_mib_write, [], [{community, "public"}]), - ?DBG("snmp_standard_mib -> std_mib_asn_err", []), - try_test(std_mib_asn_err), - ?DBG("snmp_standard_mib -> std_mib_c (~w)", [Bad]), - try_test(std_mib_c, [Bad]), - ?DBG("snmp_standard_mib -> std_mib_a", []), - try_test(standard_mib_a), - - ?DBG("snmp_standard_mib -> std_mib_finish", []), - try_test(std_mib_finish), - ?DBG("snmp_standard_mib -> std_mib_test_finish", []), - try_test(standard_mib_test_finish, [], [{community, "bad community"}]). - -%% Req. SNMP-STANDARD-MIB -standard_mib_a() -> - ?line [OutPkts] = get_req(2, [[snmpOutPkts,0]]), - ?line [OutPkts2] = get_req(3, [[snmpOutPkts,0]]), - ?line OutPkts2 = OutPkts + 1, - %% There are some more counters we could test here, but it's not that - %% important, since they are removed from SNMPv2-MIB. - ok. - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_init() -> - %% disable authentication failure traps. (otherwise w'd get many of - %% them - this is also a test to see that it works). - s([{[snmpEnableAuthenTraps,0], 2}]), - ?line expect(1, [{[snmpEnableAuthenTraps, 0], 2}]). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_finish() -> - %% enable again - s([{[snmpEnableAuthenTraps,0], 1}]), - ?line expect(1, [{[snmpEnableAuthenTraps, 0], 1}]). - -%% Req. SNMP-STANDARD-MIB -standard_mib_test_finish() -> - %% force a authenticationFailure - std_mib_write(), - %% check that we got a trap - ?line expect(2, trap, [1,2,3], 4, 0, []). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_read() -> - ?DBG("std_mib_read -> entry", []), - g([[sysUpTime,0]]), % try a bad ; msg dropped, no reply - ?DBG("std_mib_read -> await timeout (i.e. no reply)", []), - ?line expect(1, timeout). % make sure we don't get a trap! - - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_write() -> - ?DBG("std_mib_write -> entry", []), - s([{[sysLocation, 0], "new_value"}]). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_asn_err() -> - snmp_test_mgr:send_bytes([48,99,67,12,0,0,0,0,0,0,5]). - -%%----------------------------------------------------------------- -%% For this test, the agent is configured for v2 and v3. -%% o Test the counters and control objects in SNMPv2-MIB -%%----------------------------------------------------------------- -snmpv2_mib_2(suite) -> []; -snmpv2_mib_2(Config) when list(Config) -> - ?LOG("snmpv2_mib_2 -> start",[]), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?DBG("snmpv2_mib_2 -> standard mib init",[]), - try_test(std_mib_init), - - ?DBG("snmpv2_mib_2 -> get number of (so far) bad versions",[]), - InBadVsns = try_test(std_mib_a), - - ?DBG("snmpv2_mib_2 -> make a bad version read",[]), - put(vsn, v1), - try_test(std_mib_read), - - ?DBG("snmpv2_mib_2 -> bad version read",[]), - put(vsn, v2), - Bad = try_test(std_mib_b, [InBadVsns]), - - ?DBG("snmpv2_mib_2 -> read with bad community",[]), - try_test(std_mib_read, [], [{community, "bad community"}]), - - ?DBG("snmpv2_mib_2 -> write with public community",[]), - try_test(std_mib_write, [], [{community, "public"}]), - - ?DBG("snmpv2_mib_2 -> asn err",[]), - try_test(std_mib_asn_err), - - ?DBG("snmpv2_mib_2 -> check counters",[]), - try_test(std_mib_c, [Bad]), - - ?DBG("snmpv2_mib_2 -> get som counters",[]), - try_test(snmpv2_mib_a), - - ?DBG("snmpv2_mib_2 -> enable auth traps, and await some",[]), - try_test(std_mib_finish), - - ?DBG("snmpv2_mib_2 -> force auth failure, and await trap, " - "then disable auth traps",[]), - try_test(snmpv2_mib_test_finish, [], [{community, "bad community"}]), - - ?LOG("snmpv2_mib_2 -> done",[]). - -%% Req. SNMPv2-MIB -snmpv2_mib_3(suite) -> []; -snmpv2_mib_3(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - InBadVsns = try_test(std_mib_a), - put(vsn, v1), - try_test(std_mib_read), - put(vsn, v3), - _Bad = try_test(std_mib_b, [InBadVsns]), - try_test(snmpv2_mib_a), - - try_test(std_mib_finish). - --define(authenticationFailure, [1,3,6,1,6,3,1,1,5,5]). - -%% Req. SNMPv2-MIB -snmpv2_mib_test_finish() -> - %% force a authenticationFailure - ?DBG("ma_v2_inform -> write to std mib",[]), - std_mib_write(), - - %% check that we got a trap - ?DBG("ma_v2_inform -> await trap",[]), - ?line expect(2, v2trap, [{[sysUpTime,0], any}, - {[snmpTrapOID,0], ?authenticationFailure}]), - - %% and the the inform - ?DBG("ma_v2_inform -> await inform",[]), - ?line expect(2, {inform,true}, [{[sysUpTime,0], any}, - {[snmpTrapOID,0],?authenticationFailure}]). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_a() -> - ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), - ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), - ?line InPkts2 = InPkts + 1, - - ?line [InBadVsns] = get_req(4, [[snmpInBadVersions,0]]), - InBadVsns. - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_b(InBadVsns) -> - ?line [InBadVsns2] = get_req(1, [[snmpInBadVersions,0]]), - ?line InBadVsns2 = InBadVsns + 1, - ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), - ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), - ?line InPkts2 = InPkts + 1, - ?line [InBadCommunityNames, InBadCommunityUses, InASNErrs] = - get_req(4, [[snmpInBadCommunityNames,0], - [snmpInBadCommunityUses,0], - [snmpInASNParseErrs, 0]]), - {InBadCommunityNames, InBadCommunityUses, InASNErrs}. - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_c({InBadCommunityNames, InBadCommunityUses, InASNErrs}) -> - ?line [InBadCommunityNames2, InBadCommunityUses2, InASNErrs2] = - get_req(1, [[snmpInBadCommunityNames,0], - [snmpInBadCommunityUses,0], - [snmpInASNParseErrs, 0]]), - ?line InBadCommunityNames2 = InBadCommunityNames + 1, - ?line InBadCommunityUses2 = InBadCommunityUses + 1, - ?line InASNErrs2 = InASNErrs + 1. - -%% Req. SNMPv2-MIB -snmpv2_mib_a() -> - ?line [SetSerial] = get_req(2, [[snmpSetSerialNo,0]]), - s([{[snmpSetSerialNo,0], SetSerial}, {[sysLocation, 0], "val2"}]), - ?line expect(3, [{[snmpSetSerialNo,0], SetSerial}, - {[sysLocation, 0], "val2"}]), - s([{[sysLocation, 0], "val3"}, {[snmpSetSerialNo,0], SetSerial}]), - ?line expect(4, inconsistentValue, 2, - [{[sysLocation, 0], "val3"}, - {[snmpSetSerialNo,0], SetSerial}]), - ?line ["val2"] = get_req(5, [[sysLocation,0]]). - - -%%----------------------------------------------------------------- -%% o Bad community uses/name is tested already -%% in SNMPv2-MIB and STANDARD-MIB. -%% o Test add/deletion of rows. -%%----------------------------------------------------------------- -snmp_community_mib(suite) -> []; -snmp_community_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - try_test(snmp_community_mib), - ?line unload_master("SNMP-COMMUNITY-MIB"). - -snmp_community_mib_2(X) -> snmp_community_mib(X). - -%% Req. SNMP-COMMUNITY-MIB -snmp_community_mib() -> - ?INF("NOT YET IMPLEMENTED", []), - nyi. - -%%----------------------------------------------------------------- -%% o Test engine boots / time -%%----------------------------------------------------------------- -snmp_framework_mib(suite) -> []; -snmp_framework_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - try_test(snmp_framework_mib), - ?line unload_master("SNMP-FRAMEWORK-MIB"). - -snmp_framework_mib_2(X) -> snmp_framework_mib(X). - -snmp_framework_mib_3(suite) -> []; -snmp_framework_mib_3(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - try_test(snmp_framework_mib). - - -%% Req. SNMP-FRAMEWORK-MIB -snmp_framework_mib() -> - ?line ["agentEngine"] = get_req(1, [[snmpEngineID,0]]), - ?line [EngineTime] = get_req(2, [[snmpEngineTime,0]]), - sleep(5000), - ?line [EngineTime2] = get_req(3, [[snmpEngineTime,0]]), - if - EngineTime+7 < EngineTime2 -> - ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); - EngineTime+4 > EngineTime2 -> - ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); - true -> ok - end, - ?line case get_req(4, [[snmpEngineBoots,0]]) of - [Boots] when integer(Boots) -> ok; - Else -> ?FAIL(Else) - end, - ok. - -%%----------------------------------------------------------------- -%% o Test the counters -%%----------------------------------------------------------------- -snmp_mpd_mib_3(suite) -> []; -snmp_mpd_mib_3(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - UnknownPDUHs = try_test(snmp_mpd_mib_a), - try_test(snmp_mpd_mib_b, [], [{context_engine_id, "bad engine"}]), - try_test(snmp_mpd_mib_c, [UnknownPDUHs]). - - -%% Req. SNMP-MPD-MIB -snmp_mpd_mib_a() -> - ?line [UnknownSecs, InvalidMsgs] = - get_req(1, [[snmpUnknownSecurityModels,0], - [snmpInvalidMsgs,0]]), - Pdu = #pdu{type = 'get-request', - request_id = 23, - error_status = noError, - error_index = 0, - varbinds = []}, - SPdu = #scopedPdu{contextEngineID = "agentEngine", - contextName = "", - data = Pdu}, - ?line SPDUBytes = snmp_pdus:enc_scoped_pdu(SPdu), - V3Hdr1 = #v3_hdr{msgID = 21, - msgMaxSize = 484, - msgFlags = [7], - msgSecurityModel = 23, % bad sec model - msgSecurityParameters = []}, - V3Hdr2 = #v3_hdr{msgID = 21, - msgMaxSize = 484, - msgFlags = [6], % bad flag combination - msgSecurityModel = 3, - msgSecurityParameters = []}, - Message1 = #message{version = 'version-3', vsn_hdr = V3Hdr1, - data = SPDUBytes}, - Message2 = #message{version = 'version-3', vsn_hdr = V3Hdr2, - data = SPDUBytes}, - ?line MsgBytes1 = snmp_pdus:enc_message_only(Message1), - ?line MsgBytes2 = snmp_pdus:enc_message_only(Message2), - snmp_test_mgr:send_bytes(MsgBytes1), - snmp_test_mgr:send_bytes(MsgBytes2), - - ?line [UnknownSecs2, InvalidMsgs2, UnknownPDUHs] = - get_req(1, [[snmpUnknownSecurityModels,0], - [snmpInvalidMsgs,0], - [snmpUnknownPDUHandlers, 0]]), - ?line UnknownSecs2 = UnknownSecs + 1, - ?line InvalidMsgs2 = InvalidMsgs + 1, - UnknownPDUHs. - --define(snmpUnknownPDUHandlers_instance, [1,3,6,1,6,3,11,2,1,3,0]). -snmp_mpd_mib_b() -> - g([[sysUpTime,0]]), - ?line expect(1, report, [{?snmpUnknownPDUHandlers_instance, any}]). - - -snmp_mpd_mib_c(UnknownPDUHs) -> - ?line [UnknownPDUHs2] = get_req(1, [[snmpUnknownPDUHandlers, 0]]), - ?line UnknownPDUHs2 = UnknownPDUHs + 1. - - -snmp_target_mib(suite) -> []; -snmp_target_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-TARGET-MIB"), - try_test(snmp_target_mib), - ?line unload_master("SNMP-TARGET-MIB"). - -snmp_target_mib_2(X) -> snmp_target_mib(X). - -snmp_target_mib_3(X) -> snmp_target_mib(X). - -snmp_target_mib() -> - ?INF("NOT YET IMPLEMENTED", []), - nyi. - -snmp_notification_mib(suite) -> []; -snmp_notification_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - try_test(snmp_notification_mib), - ?line unload_master("SNMP-NOTIFICATION-MIB"). - -snmp_notification_mib_2(X) -> snmp_notification_mib(X). - -snmp_notification_mib_3(X) -> snmp_notification_mib(X). - -snmp_notification_mib() -> - ?INF("NOT YET IMPLEMENTED", []), - nyi. - -%%----------------------------------------------------------------- -%% o add/delete views and try them -%% o try boundaries -%%----------------------------------------------------------------- -snmp_view_based_acm_mib(suite) -> []; -snmp_view_based_acm_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - ?line load_master("Test2"), - snmp_view_based_acm_mib(), - ?line unload_master("Test2"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). - -snmp_view_based_acm_mib_2(X) -> snmp_view_based_acm_mib(X). - -snmp_view_based_acm_mib_3(X) -> snmp_view_based_acm_mib(X). - -snmp_view_based_acm_mib() -> - snmpa:verbosity(net_if,trace), - snmpa:verbosity(master_agent,trace), - ?LOG("start snmp_view_based_acm_mib test",[]), - %% The user "no-rights" is present in USM, and is mapped to security - %% name 'no-rights", which is not present in VACM. - %% So, we'll add rights for it, try them and delete them. - %% We'll give "no-rights" write access to tDescr.0 and read access - %% to tDescr2.0 - %% These are the options we'll use to the mgr - Opts = [{user, "no-rights"}, {community, "no-rights"}], - %% Find the valid secmodel, and one invalid secmodel. - {SecMod, InvSecMod} = - case get(vsn) of - v1 -> {?SEC_V1, ?SEC_V2C}; - v2 -> {?SEC_V2C, ?SEC_USM}; - v3 -> {?SEC_USM, ?SEC_V1} - end, - ?DBG("assign rights for 'no-rights'",[]), - ?line try_test(use_no_rights, [], Opts), - - %% Now, add a mapping from "no-rights" -> "no-rights-group" - GRow1Status = [vacmSecurityToGroupStatus,[SecMod, 9,"no-rights"]], - GRow1 = - [{[vacmGroupName, [SecMod, 9,"no-rights"]], "no-rights-group"}, - {GRow1Status, ?createAndGo}], - ?DBG("set '~p'",[GRow1]), - ?line try_test(do_set, [GRow1]), - - ?DBG("assign rights for 'no-rights'",[]), - ?line try_test(use_no_rights, [], Opts), - - %% Create a mapping for another sec model, and make sure it dosn't - %% give us access - GRow2Status = [vacmSecurityToGroupStatus,[InvSecMod, 9,"no-rights"]], - GRow2 = [{[vacmGroupName, [InvSecMod, 9, "no-rights"]], "initial"}, - {GRow2Status, ?createAndGo}], - - ?DBG("set '~p'",[GRow2]), - ?line try_test(do_set, [GRow2]), - - ?DBG("assign rights for 'no-rights'",[]), - ?line try_test(use_no_rights, [], Opts), - - %% Delete that row - ?line try_test(del_row, [GRow2Status]), - - RVName = "rv_name", - WVName = "wv_name", - - %% Access row - ARow1Idx = [15 | "no-rights-group"] ++ [0, ?SEC_ANY, 1], - ARow1Status = [vacmAccessStatus, ARow1Idx], - ARow1 = [{[vacmAccessContextMatch, ARow1Idx], 1}, - {[vacmAccessReadViewName, ARow1Idx], RVName}, - {[vacmAccessWriteViewName, ARow1Idx], WVName}, - {ARow1Status, ?createAndGo}], - - %% This access row would give acces, if InvSecMod was valid. - ARow2Idx = [15 | "no-rights-group"] ++ [0, InvSecMod, 1], - ARow2Status = [vacmAccessStatus, ARow2Idx], - ARow2 = [{[vacmAccessContextMatch, ARow2Idx], 1}, - {[vacmAccessReadViewName, ARow2Idx], "internet"}, - {[vacmAccessWriteViewName, ARow2Idx], "internet"}, - {ARow2Status, ?createAndGo}], - - ?line try_test(do_set, [ARow2]), - - ?line try_test(use_no_rights, [], Opts), - - %% Delete that row - ?line try_test(del_row, [ARow2Status]), - - - %% Add valid row - ?line try_test(do_set, [ARow1]), - - ?line try_test(use_no_rights, [], Opts), - - %% Create the view family - VRow1Idx = mk_ln(RVName) ++ mk_ln(?xDescr), % object access - VRow2Idx = mk_ln(RVName) ++ mk_ln(?xDescr2 ++ [0]), % instance access - VRow3Idx = mk_ln(WVName) ++ mk_ln(?xDescr), % object access - VRow4Idx = mk_ln(WVName) ++ mk_ln(?xDescr ++ [0]), % instance access - VRow1Status = [vacmViewTreeFamilyStatus, VRow1Idx], - VRow2Status = [vacmViewTreeFamilyStatus, VRow2Idx], - VRow3Status = [vacmViewTreeFamilyStatus, VRow3Idx], - VRow4Status = [vacmViewTreeFamilyStatus, VRow4Idx], - - ?line try_test(add_row, [VRow1Status]), - ?line try_test(add_row, [VRow2Status]), - ?line try_test(add_row, [VRow3Status]), - - %% We're supposed to have access now... - ?line try_test(use_rights, [], Opts), - - %% Change Row3 to Row4 - ?line try_test(del_row, [VRow3Status]), - ?line try_test(add_row, [VRow4Status]), - - %% We should still have access... - ?line try_test(use_rights, [], Opts), - - %% Delete rows - ?line try_test(del_row, [GRow1Status]), - - ?line try_test(use_no_rights, [], Opts), - - %% Delete rest of rows - ?line try_test(del_row, [ARow1Status]), - ?line try_test(del_row, [VRow1Status]), - ?line try_test(del_row, [VRow2Status]), - ?line try_test(del_row, [VRow4Status]), - - ?line try_test(use_no_rights, [], Opts), - snmpa:verbosity(master_agent,log). - -do_set(Row) -> - s(Row), - expect(1, Row). - -add_row(RowStatus) -> - s([{RowStatus, ?createAndGo}]), - expect(1, [{RowStatus, ?createAndGo}]). - -del_row(RowStatus) -> - s([{RowStatus, ?destroy}]), - expect(1, [{RowStatus, ?destroy}]). - - - -use_no_rights() -> - g([[xDescr,0]]), - ?v1_2_3(expect(11, noSuchName, 1, any), - expect(12, [{[xDescr,0], noSuchObject}]), - expect(13, authorizationError, 1, any)), - g([[xDescr2,0]]), - ?v1_2_3(expect(21, noSuchName, 1, any), - expect(22, [{[xDescr2,0], noSuchObject}]), - expect(23, authorizationError, 1, any)), - gn([[xDescr]]), - ?v1_2_3(expect(31, noSuchName, 1, any), - expect(32, [{[xDescr], endOfMibView}]), - expect(33, authorizationError, 1, any)), - s([{[xDescr,0], "tryit"}]), - ?v1_2_3(expect(41, noSuchName, 1, any), - expect(42, noAccess, 1, any), - expect(43, authorizationError, 1, any)). - - -use_rights() -> - g([[xDescr,0]]), - expect(1, [{[xDescr,0], any}]), - g([[xDescr2,0]]), - expect(2, [{[xDescr2,0], any}]), - s([{[xDescr,0], "tryit"}]), - expect(3, noError, 0, any), - g([[xDescr,0]]), - expect(4, [{[xDescr,0], "tryit"}]). - -mk_ln(X) -> - [length(X) | X]. - -%%----------------------------------------------------------------- -%% o add/delete users and try them -%% o test all secLevels -%% o test all combinations of protocols -%% o try bad ops; check counters -%%----------------------------------------------------------------- -snmp_user_based_sm_mib_3(suite) -> []; -snmp_user_based_sm_mib_3(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - _AgentDir = ?config(agent_dir, Config), - ?line load_master_std("SNMP-USER-BASED-SM-MIB"), - - %% The newUser used here already has VACM access. - - %% Add a new user in the simplest way; just createAndGo - try_test(v3_sync, [[{usm_add_user1, []}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - %% Try to use the new user - ?line load_master("Test2"), - try_test(v3_sync, [[{usm_use_user, []}]], - [{sec_level, authPriv}, {user, "newUser"}]), - ?line unload_master("Test2"), - - ShaKey1 = snmp:passwd2localized_key(sha, "new sha password", "agentEngine"), - DesKey1 = lists:sublist(ShaKey1, 16), - - %% Change the new user's keys - 1 - try_test(v3_sync, [[{usm_key_change1, [ShaKey1, DesKey1]}]], - [{sec_level, authPriv}, {user, "newUser"}]), - - %% Try to use the new keys - MgrDir = ?config(mgr_dir, Config), - ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), - ?line load_master("Test2"), - try_test(v3_sync, [[{usm_use_user, []}]], - [{sec_level, authPriv}, {user, "newUser"}]), - ?line unload_master("Test2"), - - ShaKey2 = snmp:passwd2localized_key(sha, "newer password", "agentEngine"), - DesKey2 = lists:sublist(ShaKey2, 16), - - %% Change the new user's keys - 2 - ?line try_test(v3_sync, - [[{usm_key_change2, [ShaKey1, DesKey1, ShaKey2, DesKey2]}]], - [{sec_level, authPriv}, {user, "newUser"}]), - - %% Try to use the new keys - reset_usm_mgr(MgrDir), - ?line rewrite_usm_mgr(MgrDir, ShaKey2, DesKey2), - ?line load_master("Test2"), - ?line try_test(v3_sync, [[{usm_use_user, []}]], - [{sec_level, authPriv}, {user, "newUser"}]), - ?line unload_master("Test2"), - reset_usm_mgr(MgrDir), - - %% Change the new user's keys - 3 - ?line try_test(v3_sync, - [[{usm_key_change3, [ShaKey2, DesKey2, ShaKey1, DesKey1]}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - %% Try to use the new keys - ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), - ?line load_master("Test2"), - try_test(v3_sync, [[{usm_use_user, []}]], - [{sec_level, authPriv}, {user, "newUser"}]), - ?line unload_master("Test2"), - reset_usm_mgr(MgrDir), - - %% Try some read requests - ?line try_test(v3_sync, [[{usm_read, []}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - %% Delete the new user - ?line try_test(v3_sync, [[{usm_del_user, []}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - %% Try some bad requests - ?line try_test(v3_sync, [[{usm_bad, []}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - ?line unload_master("SNMP-USER-BASED-SM-MIB"). - --define(usmUserSecurityName, [1,3,6,1,6,3,15,1,2,2,1,3]). - -usm_add_user1() -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - RowPointer = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], - Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer}, - {[usmUserStatus, NewRowIndex], ?createAndGo}], - ?line s(Vbs1), - ?line expect(1, Vbs1), - ok. - -usm_use_user() -> - v2_proc(). - - -%% Change own public keys -usm_key_change1(ShaKey, DesKey) -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - "passwd_shaxxxxxxxxxx", - ShaKey), - DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - "passwd_desxxxxxx", - DesKey), - Vbs1 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, - {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], - s(Vbs1), - ?line expect(1, Vbs1). - -%% Change own private keys -usm_key_change2(OldShaKey, OldDesKey, ShaKey, DesKey) -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - OldShaKey, - ShaKey), - DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - OldDesKey, - DesKey), - Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}, - {[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], - s(Vbs1), - ?line expect(1, Vbs1). - -%% Change other's public keys -usm_key_change3(OldShaKey, OldDesKey, ShaKey, DesKey) -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - OldShaKey, - ShaKey), - DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - OldDesKey, - DesKey), - Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}], - s(Vbs1), - ?line expect(1, noAccess, 1, any), - Vbs2 = [{[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], - s(Vbs2), - ?line expect(2, noAccess, 1, any), - - - Vbs3 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, - {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], - s(Vbs3), - ?line expect(1, Vbs3). - -usm_read() -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - ?line g([[usmUserSecurityName, NewRowIndex], - [usmUserCloneFrom, NewRowIndex], - [usmUserAuthKeyChange, NewRowIndex], - [usmUserOwnAuthKeyChange, NewRowIndex], - [usmUserPrivKeyChange, NewRowIndex], - [usmUserOwnPrivKeyChange, NewRowIndex]]), - ?line expect(1, - [{[usmUserSecurityName, NewRowIndex], "newUser"}, - {[usmUserCloneFrom, NewRowIndex], [0,0]}, - {[usmUserAuthKeyChange, NewRowIndex], ""}, - {[usmUserOwnAuthKeyChange, NewRowIndex], ""}, - {[usmUserPrivKeyChange, NewRowIndex], ""}, - {[usmUserOwnPrivKeyChange, NewRowIndex], ""}]), - ok. - - - -usm_del_user() -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - Vbs1 = [{[usmUserStatus, NewRowIndex], ?destroy}], - ?line s(Vbs1), - ?line expect(1, Vbs1), - ok. - --define(usmUserCloneFrom, [1,3,6,1,6,3,15,1,2,2,1,4]). - --define(usmNoAuthProtocol, [1,3,6,1,6,3,10,1,1,1]). - --define(usmHMACMD5AuthProtocol, [1,3,6,1,6,3,10,1,1,2]). - --define(usmHMACSHAAuthProtocol, [1,3,6,1,6,3,10,1,1,3]). - --define(usmNoPrivProtocol, [1,3,6,1,6,3,10,1,2,1]). - --define(usmDESPrivProtocol, [1,3,6,1,6,3,10,1,2,2]). - -usm_bad() -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - RowPointer1 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDOS"], - Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer1}, - {[usmUserStatus, NewRowIndex], ?createAndGo}], - ?line s(Vbs1), - ?line expect(1, inconsistentName, 1, any), - - RowPointer2 = ?usmUserCloneFrom ++ [11|"agentEngine"] ++ [7|"privDES"], - Vbs2 = [{[usmUserCloneFrom, NewRowIndex], RowPointer2}, - {[usmUserStatus, NewRowIndex], ?createAndGo}], - ?line s(Vbs2), - ?line expect(2, wrongValue, 1, any), - - RowPointer3 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], - Vbs3 = [{[usmUserCloneFrom, NewRowIndex], RowPointer3}, - {[usmUserStatus, NewRowIndex], ?createAndGo}], - ?line s(Vbs3), - ?line expect(3, Vbs3), - ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmNoAuthProtocol}]), - ?line expect(4, inconsistentValue, 1, any), - ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmHMACMD5AuthProtocol}]), - ?line expect(5, inconsistentValue, 1, any), - ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmDESPrivProtocol}]), - ?line expect(6, wrongValue, 1, any), - ?line s([{[usmUserPrivProtocol, NewRowIndex], ?usmHMACSHAAuthProtocol}]), - ?line expect(7, wrongValue, 1, any), - - Vbs4 = [{[usmUserStatus, NewRowIndex], ?destroy}], - ?line s(Vbs4), - ?line expect(1, Vbs4), - - ok. - - -%%----------------------------------------------------------------- -%% Loop through entire MIB, to make sure that all instrum. funcs -%% works. -%% Load all std mibs that are not loaded by default. -%%----------------------------------------------------------------- -loop_mib(suite) -> []; -loop_mib(Config) when list(Config) -> - ?LOG("loop_mib -> initiate case",[]), - %% snmpa:verbosity(master_agent,debug), - %% snmpa:verbosity(mib_server,info), - {SaNode, MgrNode, MibDir} = init_case(Config), - ?DBG("loop_mib -> ~n" - "\tSaNode: ~p~n" - "\tMgrNode: ~p~n" - "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), - ?DBG("loop_mib -> load mib SNMP-COMMUNITY-MIB",[]), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?DBG("loop_mib -> load mib SNMP-MPD-MIB",[]), - ?line load_master_std("SNMP-MPD-MIB"), - ?DBG("loop_mib -> load mib SNMP-TARGET-MIB",[]), - ?line load_master_std("SNMP-TARGET-MIB"), - ?DBG("loop_mib -> load mib SNMP-NOTIFICATION-MIB",[]), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?DBG("loop_mib -> load mib SNMP-FRAMEWORK-MIB",[]), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?DBG("loop_mib -> load mib SNMP-VIEW-BASED-ACM-MIB",[]), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - ?DBG("loop_mib -> try",[]), - try_test(loop_mib_1), - ?DBG("loop_mib -> unload mib SNMP-COMMUNITY-MIB",[]), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?DBG("loop_mib -> unload mib SNMP-MPD-MIB",[]), - ?line unload_master("SNMP-MPD-MIB"), - ?DBG("loop_mib -> unload mib SNMP-TARGET-MIB",[]), - ?line unload_master("SNMP-TARGET-MIB"), - ?DBG("loop_mib -> unload mib SNMP-NOTIFICATION-MIB",[]), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?DBG("loop_mib -> unload mib SNMP-FRAMEWORK-MIB",[]), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?DBG("loop_mib -> unload mib SNMP-VIEW-BASED-ACM-MIB",[]), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - %% snmpa:verbosity(master_agent,log), - %% snmpa:verbosity(mib_server,silence), - ?LOG("loop_mib -> done",[]). - - -loop_mib_2(suite) -> []; -loop_mib_2(Config) when list(Config) -> - ?LOG("loop_mib_2 -> initiate case",[]), - {SaNode, MgrNode, MibDir} = init_case(Config), - ?DBG("loop_mib_2 -> ~n" - "\tSaNode: ~p~n" - "\tMgrNode: ~p~n" - "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), - ?DBG("loop_mib_2 -> load mibs",[]), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-MPD-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - try_test(loop_mib_2), - ?DBG("loop_mib_2 -> unload mibs",[]), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?line unload_master("SNMP-MPD-MIB"), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - ?LOG("loop_mib_2 -> done",[]). - - -loop_mib_3(suite) -> []; -loop_mib_3(Config) when list(Config) -> - ?LOG("loop_mib_3 -> initiate case",[]), - {SaNode, MgrNode, MibDir} = init_case(Config), - ?DBG("loop_mib_3 -> ~n" - "\tSaNode: ~p~n" - "\tMgrNode: ~p~n" - "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), - ?DBG("loop_mib_3 -> load mibs",[]), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - ?line load_master_std("SNMP-USER-BASED-SM-MIB"), - try_test(loop_mib_2), - ?DBG("loop_mib_3 -> unload mibs",[]), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - ?line unload_master("SNMP-USER-BASED-SM-MIB"), - ?LOG("loop_mib_3 -> done",[]). - - -%% Req. As many mibs all possible -loop_mib_1() -> - ?DBG("loop_mib_1 -> entry",[]), - N = loop_it_1([1,1], 0), - io:format(user, "found ~w varibles\n", [N]), - ?line N = if N < 100 -> 100; - true -> N - end. - - -loop_it_1(Oid, N) -> - ?DBG("loop_it_1 -> entry with~n" - "\tOid: ~p~n" - "\tN: ~p",[Oid,N]), - case get_next_req([Oid]) of - #pdu{type='get-response', error_status=noError, error_index=0, - varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> - ?DBG("loop_it_1 -> ~n" - "\tNOid: ~p~n" - "\tValue: ~p",[NOid,Value]), - ?line [Value2] = get_req(1, [NOid]), % must not be same - ?DBG("loop_it_1 -> ~n" - "\tValue2: ~p",[Value2]), - loop_it_1(NOid, N+1); - #pdu{type='get-response', error_status=noSuchName, error_index=1, - varbinds=[_]} -> - ?DBG("loop_it_1 -> done",[]), - N; - - #pdu{type = Type, error_status = Err, error_index = Idx, - varbinds = Vbs} -> - exit({unexpected_pdu, ?LINE, Type, Err, Idx, Vbs}) - end. - -%% Req. As many mibs all possible -loop_mib_2() -> - ?DBG("loop_mib_1 -> entry",[]), - N = loop_it_2([1,1], 0), - io:format(user, "found ~w varibles\n", [N]), - ?line N = if N < 100 -> 100; - true -> N - end. - - -loop_it_2(Oid, N) -> - ?DBG("loop_it_2 -> entry with~n" - "\tOid: ~p~n" - "\tN: ~p",[Oid,N]), - case get_next_req([Oid]) of - #pdu{type='get-response', error_status=noError, error_index=0, - varbinds=[#varbind{oid = NOid, value = endOfMibView}]} -> - ?DBG("loop_it_2 -> ~n" - "\tNOid: ~p",[NOid]), - N; - #pdu{type='get-response', error_status=noError, error_index=0, - varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> - ?DBG("loop_it_2 -> ~n" - "\tNOid: ~p~n" - "\tValue: ~p",[NOid,Value]), - ?line [Value2] = get_req(1, [NOid]), % must not be same - ?DBG("loop_it_2 -> ~n" - "\tValue2: ~p",[Value2]), - loop_it_2(NOid, N+1) - end. - - -%%%----------------------------------------------------------------- -%%% Testing of reported bugs and other tickets. -%%%----------------------------------------------------------------- - - - - - -%% These are (ticket) test cases where the initiation has to be done -%% individually. - -%%----------------------------------------------------------------- -%% Ticket: OTP-1128 -%% Slogan: Bug in handling of createAndWait set-requests. -%%----------------------------------------------------------------- -otp_1128(suite) -> []; -otp_1128(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(otp_1128), - ?line unload_master("OLD-SNMPEA-MIB"). - -otp_1128_2(X) -> otp_1128(X). - -otp_1128_3(X) -> otp_1128(X). - -otp_1128() -> - io:format("Testing bug reported in ticket OTP-1128...~n"), - - NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], - NewKeyc4 = [intCommunityAccess,get(mip),is("test")], - NewKeyc5 = [intCommunityStatus,get(mip),is("test")], - - s([{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), - ?line expect(28, [{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), - g([NewKeyc5]), - ?line expect(29, [{NewKeyc5, ?notReady}]), - s([{NewKeyc5, ?active}, {NewKeyc3, 2}]), - ?line expect(30, [{NewKeyc5, ?active}, {NewKeyc3, 2}]), - g([NewKeyc5]), - ?line expect(31, [{NewKeyc5, ?active}]), - s([{NewKeyc5, ?destroy}]), - ?line expect(32, [{NewKeyc5, ?destroy}]). - -%%----------------------------------------------------------------- -%% Ticket: OTP-1129, OTP-1169 -%% Slogan: snmpa:int_to_enum crashes on bad oids -%%----------------------------------------------------------------- -otp_1129(suite) -> []; -otp_1129(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas3"), - try_test(otp_1129_i, [node()]), - ?line unload_master("Klas3"). - -otp_1129_2(X) -> otp_1129(X). - -otp_1129_3(X) -> otp_1129(X). - -otp_1129_i(MaNode) -> - io:format("Testing bug reported in ticket OTP-1129...~n"), - false = rpc:call(MaNode, snmp, int_to_enum, [iso, 1]), - false = rpc:call(MaNode, snmp, int_to_enum, [isox, 1]). - -%%----------------------------------------------------------------- -%% Ticket: OTP-1131 -%% Slogan: Agent crashes / erlang node halts if RowIndex in a -%% setrequest is of bad type, e.g. an INDEX {INTEGER}, -%% and RowIdenx [3,2]. -%%----------------------------------------------------------------- -otp_1131(suite) -> []; -otp_1131(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas1"), - try_test(otp_1131), - ?line unload_master("Klas1"). - -otp_1131_2(X) -> otp_1131(X). - -otp_1131_3(X) -> otp_1131(X). - -otp_1131() -> - io:format("Testing bug reported in ticket OTP-1131...~n"), - s([{[friendsEntry, [2, 3, 1]], s, "kompis3"}, - {[friendsEntry, [3, 3, 1]], i, ?createAndGo}]), - ?line expect(1, ?v1_2(noSuchName, noCreation), 2, any). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1162 -%% Slogan: snmp_agent can't handle wrongValue from instrum.func -%%----------------------------------------------------------------- -otp_1162(suite) -> []; -otp_1162(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - try_test(otp_1162), - stop_subagent(SA). - -otp_1162_2(X) -> otp_1162(X). - -otp_1162_3(X) -> otp_1162(X). - -otp_1162() -> - s([{[sa, [2,0]], 6}]), % wrongValue (i is_set_ok) - ?line expect(1, ?v1_2(badValue, wrongValue), 1, any). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1222 -%% Slogan: snmp agent crash if faulty index is returned from instrum -%%----------------------------------------------------------------- -otp_1222(suite) -> []; -otp_1222(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas3"), - ?line load_master("Klas4"), - try_test(otp_1222), - ?line unload_master("Klas3"), - ?line unload_master("Klas4"). - -otp_1222_2(X) -> otp_1222(X). - -otp_1222_3(X) -> otp_1222(X). - -otp_1222() -> - io:format("Testing bug reported in ticket OTP-1222...~n"), - s([{[fStatus4,1], 4}, {[fName4,1], 1}]), - ?line expect(1, genErr, 0, any), - s([{[fStatus4,2], 4}, {[fName4,2], 1}]), - ?line expect(2, genErr, 0, any). - -%%----------------------------------------------------------------- -%% Ticket: OTP-1298 -%% Slogan: Negative INTEGER values are treated as positive. -%%----------------------------------------------------------------- -otp_1298(suite) -> []; -otp_1298(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas2"), - try_test(otp_1298), - ?line unload_master("Klas2"). - -otp_1298_2(X) -> otp_1298(X). - -otp_1298_3(X) -> otp_1298(X). - -otp_1298() -> - io:format("Testing bug reported in ticket OTP-1298...~n"), - s([{[fint,0], -1}]), - ?line expect(1298, [{[fint,0], -1}]). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1331 -%% Slogan: snmp_generic should return noError when deleting non-ex row -%%----------------------------------------------------------------- -otp_1331(suite) -> []; -otp_1331(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(otp_1331), - ?line unload_master("OLD-SNMPEA-MIB"). - -otp_1331_2(X) -> otp_1331(X). - -otp_1331_3(X) -> otp_1331(X). - -otp_1331() -> - NewKeyc5 = [intCommunityStatus,[127,32,0,0],is("test")], - s([{NewKeyc5, ?destroy}]), - ?line expect(1, [{NewKeyc5, ?destroy}]). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1338 -%% Slogan: snmp bug in initialisation of default values for mnesia tabs -%%----------------------------------------------------------------- -otp_1338(suite) -> []; -otp_1338(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas2"), - try_test(otp_1338), - ?line unload_master("Klas2"). - -otp_1338_2(X) -> otp_1338(X). - -otp_1338_3(X) -> otp_1338(X). - -otp_1338() -> - s([{[kStatus2, 7], i, ?createAndGo}]), - ?line expect(1, [{[kStatus2, 7], ?createAndGo}]), - g([[kName2, 7]]), - ?line expect(2, [{[kName2, 7], "JJJ"}]). - -%%----------------------------------------------------------------- -%% Ticket: OTP-1342 -%% Slogan: default impl of snmp table can't handle bad index access, -%% Set when INDEX is read-write gets into an infinite loop! -%%----------------------------------------------------------------- -otp_1342(suite) -> []; -otp_1342(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas4"), - try_test(otp_1342), - ?line unload_master("Klas4"). - -otp_1342_2(X) -> otp_1342(X). - -otp_1342_3(X) -> otp_1342(X). - -otp_1342() -> - s([{[fIndex5, 1], i, 1}, - {[fName5, 1], i, 3}, - {[fStatus5, 1], i, ?createAndGo}]), - ?line expect(1, ?v1_2(noSuchName, noCreation), 3, any). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1366 -%% Slogan: snmp traps not sent to all managers -%% Note: NYI! We need a way to tell the test server that we need -%% mgrs on two different machines. -%%----------------------------------------------------------------- -otp_1366(suite) -> []; -otp_1366(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(otp_1366), - ?line unload_master("OLD-SNMPEA-MIB"). - -otp_1366_2(X) -> otp_1366(X). - -otp_1366_3(X) -> otp_1366(X). - -otp_1366() -> - ?INF("NOT YET IMPLEMENTED", []), - 'NYI'. - -%%----------------------------------------------------------------- -%% Ticket: OTP-2776 -%% Slogan: snmp:validate_date_and_time() fails when time is 00:00 -%%----------------------------------------------------------------- -otp_2776(suite) -> []; -otp_2776(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - try_test(otp_2776). - -otp_2776_2(X) -> otp_2776(X). - -otp_2776_3(X) -> otp_2776(X). - -otp_2776() -> - io:format("Testing bug reported in ticket OTP-2776...~n"), - - Dt01_valid = [19,98,9,1,1,0,23,0,43,0,0], - Dt02_valid = [19,98,9,1,0,0,0,0,43,0,0], % This is what is fixed: 00:00 - Dt03_valid = [19,98,2,28,1,0,23,0,43,0,0], - Dt04_invalid = [19,98,2,29,1,0,23,0,43,0,0], - Dt05_valid = [19,96,2,29,1,0,23,0,43,0,0], - Dt06_valid = [20,0,2,29,1,0,23,0,43,0,0], - Dt07_invalid = [19,96,2,30,1,0,23,0,43,0,0], % This is also fixed: 30/2 - Dt08_valid = [19,98,4,30,1,0,23,0,43,0,0], - Dt09_invalid = [19,98,4,31,1,0,23,0,43,0,0], % This is also fixed: 31/4 - Dt10_invalid = [], - Dt11_invalid = [kalle,hobbe], - L = [{ 1, true, Dt01_valid}, - { 2, true, Dt02_valid}, - { 3, true, Dt03_valid}, - { 4, false, Dt04_invalid}, - { 5, true, Dt05_valid}, - { 6, true, Dt06_valid}, - { 7, false, Dt07_invalid}, - { 8, true, Dt08_valid}, - { 9, false, Dt09_invalid}, - {10, false, Dt10_invalid}, - {11, false, Dt11_invalid}], - - ?line ok = validate_dat(L). - - -validate_dat(L) -> validate_dat(L,[]). - -validate_dat([],V) -> - Fun = fun({_,X}) -> case X of - ok -> false; - _ -> true - end - end, - validate_dat1( lists:reverse( lists:filter(Fun,V) ) ); -validate_dat([{Id,E,Dat}|T],V) -> - validate_dat(T,[validate_dat2(Id,E,Dat) | V]). - -validate_dat1([]) -> ok; -validate_dat1(L) -> {error,L}. - -validate_dat2(Id, E, Dat) -> - Res = case {E,snmp:validate_date_and_time(Dat)} of - {E,E} -> ok; - {E,A} -> {E,A} - end, - {Id, Res}. - - -%%----------------------------------------------------------------- -%% Ticket: OTP-2979 -%% Slogan: get-next on more than 1 column in an empty table -%% returns bad response. -%%----------------------------------------------------------------- -otp_2979(suite) -> []; -otp_2979(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Test1"), - ?line init_old(), - try_test(otp_2979), - ?line unload_master("Test1"). - -otp_2979_2(X) -> otp_2979(X). - -otp_2979_3(X) -> otp_2979(X). - -otp_2979() -> - gn([[sparseDescr], [sparseStatus]]), - ?line expect(1, [{[sparseStr,0], "slut"}, - {[sparseStr,0], "slut"}]). - -%%----------------------------------------------------------------- -%% Ticket: OTP-3187 -%% Slogan: get-next on vacmAccessTable for colums > 5 returns -%% endOfTable - should return value. -%%----------------------------------------------------------------- -otp_3187(suite) -> []; -otp_3187(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - otp_3187(), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). - -otp_3187_2(X) -> otp_3187(X). - -otp_3187_3(X) -> otp_3187(X). - -otp_3187() -> - ?line Elements = - snmp_view_based_acm_mib:vacmAccessTable(get_next,[],[4,5,6]), - lists:foreach(fun(E) -> - ?line if E == endOfTable -> - ?FAIL(endOfTable); - true -> ok - end - end, Elements). - -%%----------------------------------------------------------------- -%% Ticket: OTP-3542 -%% Slogan: -%%----------------------------------------------------------------- -otp_3542(suite) -> []; -otp_3542(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - try_test(otp_3542). - -otp_3542() -> - io:format("SNMP v3 discovery...~n"), - ?line Res = snmp_test_mgr:d(), - io:format("SNMP v3 discovery result: ~p~n",[Res]). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-3725 -%% Slogan: Slow response time on snmpa:int_to_enum -%%----------------------------------------------------------------- -otp_3725(suite) -> []; -otp_3725(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(otp_3725_test, [node()]), - ?line unload_master("OLD-SNMPEA-MIB"). - -%% Req. OLD-SNMPEA-MIB -otp_3725_test(MaNode) -> - io:format("Testing feature requested in ticket OTP-3725...~n"), - ?line rpc:call(MaNode,snmpa,verbosity,[symbolic_store,trace]), - ?line Db = rpc:call(MaNode,snmp,get_symbolic_store_db,[]), - ?DBG("otp_3725_test -> Db = ~p",[Db]), - - ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, - [Db, intAgentIpAddress]), - ?DBG("otp_3725_test -> name_to_oid for ~p: ~p",[intAgentIpAddress,OID]), - ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, oid_to_name, - [Db,OID]), - ?DBG("otp_3725_test -> oid_to_name for ~p: ~p",[OID,intAgentIpAddress]), - ?line false = rpc:call(MaNode, snmp, name_to_oid, [Db, intAgentIpAddres]), - ?line false = rpc:call(MaNode, snmp, oid_to_name, - [Db, [1,5,32,3,54,3,3,34,4]]), - ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, - [Db, intViewType, excluded]), - ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, - [Db, intViewType, 2]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, intViewType, exclude]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, intAgentIpAddress, exclude]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, intAgentIpAddre, exclude]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, intViewType, 3]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, - [Db, intAgentIpAddress, 2]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, - [Db, intAgentIpAddre, 2]), - ?line {value, active} = rpc:call(MaNode, snmp, int_to_enum, - [Db, 'RowStatus', ?active]), - ?line {value, ?destroy} = rpc:call(MaNode, snmp, enum_to_int, - [Db, 'RowStatus', destroy]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, 'RowStatus', xxxdestroy]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, 'xxRowStatus', destroy]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'RowStatus', 25]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'xxRowStatus', 1]), - ok. - - -%%----------------------------------------------------------------- -%% Ticket: OTP-4394 -%% Slogan: Target mib tag list check invalid -%%----------------------------------------------------------------- - - - -init_otp_4394(Config) when list(Config) -> - ?DBG("init_otp_4394 -> entry with" - "~n Config: ~p", [Config]), - ?line AgentDir = ?config(agent_dir, Config), - ?line MgrDir = ?config(mgr_dir, Config), - ?line Ip = ?config(ip, Config), - ?line otp_4394_config(AgentDir, MgrDir, Ip), - MasterAgentVerbosity = {master_agent_verbosity, trace}, - NetIfVerbosity = {net_if_verbosity, trace}, - Opts = [MasterAgentVerbosity,NetIfVerbosity], - [{vsn, v1} | start_v1_agent(Config,Opts)]. - -otp_4394_config(AgentDir, MgrDir, Ip0) -> - ?DBG("otp_4394_config -> entry with" - "~n AgentDir: ~p" - "~n MgrDir: ~p" - "~n Ip0: ~p", [AgentDir, MgrDir, Ip0]), - Vsn = [v1], - Ip = tuple_to_list(Ip0), - ?line snmp_config:write_agent_snmp_files(AgentDir, Vsn, Ip, - ?TRAP_UDP, Ip, 4000, - "OTP-4394 test"), - ?line case update_usm(Vsn, AgentDir) of - true -> - ?line copy_file(filename:join(AgentDir, "usm.conf"), - filename:join(MgrDir, "usm.conf")), - ?line update_usm_mgr(Vsn, MgrDir); - false -> - ?line ok - end, - C1 = {"a", "all-rights", "initial", "", "pc"}, - C2 = {"c", "secret", "secret_name", "", "secret_tag"}, - ?line write_community_conf(AgentDir, [C1, C2]), - ?line update_vacm(Vsn, AgentDir), - Ta1 = {"shelob v1", - [134,138,177,177], 5000, 1500, 3, %% Använd Ip och modda - "pc1", - "target_v1", "", - %% [255,255,255,255,0,0], - [], - 2048}, - Ta2 = {"bifur v1", - [134,138,177,75], 5000, 1500, 3, %% Använd Ip - "pc2", - "target_v1", "", - %% [255,255,255,255,0,0], - [], 2048}, - ?line write_target_addr_conf(AgentDir, [Ta1, Ta2]), - ?line write_target_params_conf(AgentDir, Vsn), - ?line write_notify_conf(AgentDir), - ok. - - - -finish_otp_4394(Config) when list(Config) -> - ?DBG("finish_otp_4394 -> entry", []), - C1 = stop_agent(Config), - delete_files(C1), - erase(mgr_node), - lists:keydelete(vsn, 1, C1). - -otp_4394_test(suite) -> []; -otp_4394_test(Config) -> - ?DBG("otp_4394_test -> entry", []), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - try_test(otp_4394_test1), - ?DBG("otp_4394_test -> done", []), - ok. - -otp_4394_test1() -> - ?DBG("otp_4394_test1 -> entry", []), - gn([[1,1]]), - Res = - case snmp_test_mgr:expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]) of - %% {error, 1, {"?",[]}, {"~w",[timeout]}} - {error, 1, _, {_, [timeout]}} -> - ?DBG("otp_4394_test1 -> expected result: timeout", []), - ok; - Else -> - Else - end, - ?DBG("otp_4394_test1 -> done with: ~p", [Res]), - Res. - - -%%%-------------------------------------------------- -%%% Used to test the standard mib with our -%%% configuration. -%%%-------------------------------------------------- -run(F, A, Opts) -> - M = get(mib_dir), - Dir = get(mgr_dir), - User = snmp_misc:get_option(user, Opts, "all-rights"), - SecLevel = snmp_misc:get_option(sec_level, Opts, noAuthNoPriv), - EngineID = snmp_misc:get_option(engine_id, Opts, "agentEngine"), - CtxEngineID = snmp_misc:get_option(context_engine_id, Opts, EngineID), - Community = snmp_misc:get_option(community, Opts, "all-rights"), - ?DBG("run -> start crypto app",[]), - Crypto = case os:type() of - vxworks -> - no_crypto; - _ -> - ?CRYPTO_START() - end, - ?DBG("run -> Crypto: ~p",[Crypto]), - catch snmp_test_mgr:stop(), % If we had a running mgr from a failed case - StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", - ?DBG("run -> config:~n" - "\tM: ~p~n" - "\tDir: ~p~n" - "\tUser: ~p~n" - "\tSecLevel: ~p~n" - "\tEngineID: ~p~n" - "\tCtxEngineID: ~p~n" - "\tCommunity: ~p~n" - "\tStdM: ~p", - [M,Dir,User,SecLevel,EngineID,CtxEngineID,Community,StdM]), - case snmp_test_mgr:start([%% {agent, snmp_test_lib:hostname()}, - {packet_server_debug,true}, - {debug,true}, - {agent, get(master_host)}, - {agent_udp, 4000}, - {trap_udp, 5000}, - {recbuf,65535}, - quiet, - get(vsn), - {community, Community}, - {user, User}, - {sec_level, SecLevel}, - {engine_id, EngineID}, - {context_engine_id, CtxEngineID}, - {dir, Dir}, - {mibs, mibs(StdM, M)}]) of - {ok, _Pid} -> - Res = apply(?MODULE, F, A), - catch snmp_test_mgr:stop(), - Res; - Err -> - io:format("Error starting manager: ~p\n", [Err]), - catch snmp_test_mgr:stop(), - ?line exit({mgr_start, Err}) - end. - - -mibs(StdMibDir,MibDir) -> - [join(StdMibDir, ?v1_2("STANDARD-MIB.bin", "SNMPv2-MIB.bin")), - join(MibDir, "OLD-SNMPEA-MIB.bin"), - join(StdMibDir, "SNMP-FRAMEWORK-MIB"), - join(StdMibDir, "SNMP-MPD-MIB"), - join(StdMibDir, "SNMP-VIEW-BASED-ACM-MIB"), - join(StdMibDir, "SNMP-USER-BASED-SM-MIB"), - join(StdMibDir, "SNMP-TARGET-MIB"), - join(StdMibDir, "SNMP-NOTIFICATION-MIB"), - join(MibDir, "Klas1.bin"), - join(MibDir, "Klas2.bin"), - join(MibDir, "Klas3.bin"), - join(MibDir, "Klas4.bin"), - join(MibDir, "SA-MIB.bin"), - join(MibDir, "TestTrap.bin"), - join(MibDir, "Test1.bin"), - join(MibDir, "Test2.bin"), - join(MibDir, "TestTrapv2.bin")]. - -join(D,F) -> - filename:join(D,F). - -%% string used in index -is(S) -> [length(S) | S]. - -try_test(Func) -> - call(get(mgr_node), ?MODULE, run, [Func, [], []]). - -try_test(Func, A) -> - call(get(mgr_node), ?MODULE, run, [Func, A, []]). - -try_test(Func, A, Opts) -> - call(get(mgr_node), ?MODULE, run, [Func, A, Opts]). - -call(N,M,F,A) -> - ?DBG("call -> entry with~n" - " N: ~p~n" - " M: ~p~n" - " F: ~p~n" - " A: ~p~n" - " when~n" - " get(): ~p", - [N,M,F,A,get()]), - spawn(N, ?MODULE, wait, [self(),get(),M,F,A]), - receive - {done, {'EXIT', Rn}, Loc} -> - ?DBG("call -> returned ~p",[{done, {'EXIT', Rn}, Loc}]), - put(test_server_loc, Loc), - exit(Rn); - {done, Ret, Zed} -> - ?DBG("call -> returned ~p~n",[{done, Ret, Zed}]), - Ret - end. - -wait(From, Env, M, F, A) -> - ?DBG("wait -> entry with ~n" - "\tFrom: ~p~n" - "\tEnv: ~p",[From,Env]), - lists:foreach(fun({K,V}) -> put(K,V) end, Env), - Rn = (catch apply(M, F, A)), - ?DBG("wait -> Rn: ~n~p", [Rn]), - From ! {done, Rn, get(test_server_loc)}, - exit(Rn). - -expect(A,B) -> ok = snmp_test_mgr:expect(A,B). -expect(A,B,C) -> ok = snmp_test_mgr:expect(A,B,C). -expect(A,B,C,D) -> ok = snmp_test_mgr:expect(A,B,C,D). -expect(A,B,C,D,E,F) -> ok = snmp_test_mgr:expect(A,B,C,D,E,F). - -get_req(Id, Vars) -> - ?DBG("get_req -> entry with~n" - "\tId: ~p~n" - "\tVars: ~p",[Id,Vars]), - g(Vars), - ?DBG("get_req -> await response",[]), - {ok, Val} = snmp_test_mgr:get_response(Id, Vars), - ?DBG("get_req -> response: ~p",[Val]), - Val. - -get_next_req(Vars) -> - ?DBG("get_next_req -> entry with Vars '~p', send request",[Vars]), - gn(Vars), - ?DBG("get_next_req -> await response",[]), - Response = snmp_test_mgr:receive_response(), - ?DBG("get_next_req -> response: ~p",[Response]), - Response. - - - -start_node(Name) -> - ?LOG("start_node -> entry with Name: ~p",[Name]), - M = list_to_atom(?HOSTNAME(node())), - ?DBG("start_node -> M: ~p",[M]), - Pa = filename:dirname(code:which(?MODULE)), - ?DBG("start_node -> Pa: ~p",[Pa]), - - Args = case init:get_argument('CC_TEST') of - {ok, [[]]} -> - " -pa /clearcase/otp/libraries/snmp/ebin "; - {ok, [[Path]]} -> - " -pa " ++ Path; - error -> - "" - end, - %% Do not use start_link!!! (the proc that calls this one is tmp) - ?DBG("start_node -> Args: ~p~n",[Args]), - A = Args ++ " -pa " ++ Pa, - case (catch ?START_NODE(Name, A)) of - {ok, Node} -> - %% Tell the test_server to not clean up things it never started. - ?DBG("start_node -> Node: ~p",[Node]), - {ok, Node}; - Else -> - ?ERR("start_node -> failed with(other): Else: ~p",[Else]), - ?line ?FAIL(Else) - end. - - -stop_node(Node) -> - ?LOG("stop_node -> Node: ~p",[Node]), - rpc:cast(Node, erlang, halt, []). - -p(X) -> - io:format(user, X++"\n", []). - -sleep(X) -> - receive - after - X -> ok - end. - -%%%----------------------------------------------------------------- -%%% Configuration -%%%----------------------------------------------------------------- -config(Vsns, MgrDir, AgentDir, MIp, AIp) -> - ?line snmp_config:write_agent_snmp_files(AgentDir, Vsns, MIp, - ?TRAP_UDP, AIp, 4000, - "test"), - ?line case update_usm(Vsns, AgentDir) of - true -> - ?line copy_file(filename:join(AgentDir, "usm.conf"), - filename:join(MgrDir, "usm.conf")), - ?line update_usm_mgr(Vsns, MgrDir); - false -> - ?line ok - end, - ?line update_community(Vsns, AgentDir), - ?line update_vacm(Vsns, AgentDir), - ?line write_target_addr_conf(AgentDir, MIp, ?TRAP_UDP, Vsns), - ?line write_target_params_conf(AgentDir, Vsns), - ?line write_notify_conf(AgentDir), - ok. - -delete_files(Config) -> - Dir = ?config(agent_dir, Config), - {ok, List} = file:list_dir(Dir), - lists:foreach(fun(FName) -> file:delete(filename:join(Dir, FName)) end, - List). - -update_usm(Vsns, Dir) -> - case lists:member(v3, Vsns) of - true -> - {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),[read,write]), - file:position(Fid, eof), - ok = io:format(Fid, "{\"agentEngine\", \"all-rights\", " - "\"all-rights\", zeroDotZero, " - "usmNoAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"\", \"\"}.\n", []), - ok = io:format(Fid, "{\"agentEngine\", \"no-rights\", " - "\"no-rights\", zeroDotZero, " - "usmNoAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"\", \"\"}.\n", []), - ok = io:format(Fid, "{\"agentEngine\", \"authMD5\", " - "\"authMD5\", zeroDotZero, " - "usmHMACMD5AuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"passwd_md5xxxxxx\", \"\"}.\n", []), - ok = io:format(Fid, "{\"agentEngine\", \"authSHA\", " - "\"authSHA\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"\"}.\n", []), - ok = io:format(Fid, "{\"agentEngine\", \"privDES\", " - "\"privDES\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", - []), - ok = io:format(Fid, "{\"mgrEngine\", \"all-rights\", " - "\"all-rights\", zeroDotZero, " - "usmNoAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"\", \"\"}.\n", []), - ok = io:format(Fid, "{\"mgrEngine\", \"no-rights\", " - "\"no-rights\", zeroDotZero, " - "usmNoAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"\", \"\"}.\n", []), - ok = io:format(Fid, "{\"mgrEngine\", \"authMD5\", " - "\"authMD5\", zeroDotZero, " - "usmHMACMD5AuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"passwd_md5xxxxxx\", \"\"}.\n", []), - ok = io:format(Fid, "{\"mgrEngine\", \"authSHA\", " - "\"authSHA\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"\"}.\n", []), - ok = io:format(Fid, "{\"mgrEngine\", \"privDES\", " - "\"privDES\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", - []), - file:close(Fid), - true; - false -> - false - end. - -update_usm_mgr(Vsns, Dir) -> - case lists:member(v3, Vsns) of - true -> - {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),[read,write]), - file:position(Fid, eof), - ok = io:format(Fid, "{\"agentEngine\", \"newUser\", " - "\"newUser\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", - []), - ok = io:format(Fid, "{\"mgrEngine\", \"newUser\", " - "\"newUser\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", - []), - file:close(Fid), - true; - false -> - false - end. - -rewrite_usm_mgr(Dir, ShaKey, DesKey) -> - ?line ok = file:rename(filename:join(Dir,"usm.conf"), - filename:join(Dir,"usm.old")), - ?line {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),write), - ok = io:format(Fid, "{\"agentEngine\", \"newUser\", " - "\"newUser\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"~s\", \"~s\"}.\n", - [ShaKey, DesKey]), - ok = io:format(Fid, "{\"mgrEngine\", \"newUser\", " - "\"newUser\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"~s\", \"~s\"}.\n", - [ShaKey, DesKey]), - file:close(Fid). - -reset_usm_mgr(Dir) -> - ?line ok = file:rename(filename:join(Dir,"usm.old"), - filename:join(Dir,"usm.conf")). - - -update_community([v3], _Dir) -> ok; -update_community(_, Dir) -> - {ok, Fid} = file:open(filename:join(Dir,"community.conf"),[read,write]), - file:position(Fid, eof), - ok=io:format(Fid,"{\"no-rights\",\"no-rights\",\"no-rights\",\"\",\"\"}.\n", - []), - file:close(Fid). - - --define(tDescr_instance, [1,3,6,1,2,1,16,1,0]). -update_vacm(_Vsn, Dir) -> - {ok, Fid} = file:open(filename:join(Dir,"vacm.conf"),[read,write]), - file:position(Fid, eof), - ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"authMD5\",\"initial\"}.\n",[]), - ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"authSHA\",\"initial\"}.\n",[]), - ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"privDES\",\"initial\"}.\n",[]), - ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"newUser\",\"initial\"}.\n",[]), - ok = io:format(Fid, "{vacmViewTreeFamily, \"internet\", " - "~w, excluded, null}.\n", [?tDescr_instance]), - file:close(Fid). - - -vacm_ver(v1) -> v1; -vacm_ver(v2) -> v2c; -vacm_ver(v3) -> usm. - - -write_community_conf(Dir, Confs) -> - {ok, Fid} = file:open(filename:join(Dir,"community.conf"),write), - ok = write_community_conf1(Fid, Confs), - file:close(Fid). - -write_community_conf1(_, []) -> - ok; -write_community_conf1(Fid, [{ComIdx, ComName, SecName, CtxName, TransTag}|Confs]) -> - ok = io:format(Fid, "{\"~s\", \"~s\", \"~s\", \"~s\", \"~s\"}.~n", - [ComIdx, ComName, SecName, CtxName, TransTag]), - write_community_conf1(Fid, Confs). - - -write_target_addr_conf(Dir, Confs) -> - {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), - ok = write_target_addr_conf1(Fid, Confs), - file:close(Fid). - - -write_target_addr_conf1(_, []) -> - ok; -write_target_addr_conf1(Fid, - [{Name, Ip, Port, Timeout, Retry, TagList, ParamName, - EngineId, TMask, MaxMsgSz}|Confs]) -> - ok = io:format(Fid, "{\"~s\", ~w, ~w, ~w, ~w, \"~s\", \"~s\", \"~s\", ~w, ~w}.~n", - [Name, Ip, Port, Timeout, Retry, TagList, ParamName, - EngineId, TMask, MaxMsgSz]), - write_target_addr_conf1(Fid, Confs). - -write_target_addr_conf(Dir, ManagerIp, UDP, Vsns) -> - {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), - lists:foreach(fun(Vsn) -> - ok = io:format(Fid, - "{\"~s\", ~w, ~w, 1500, 3, " - "\"std_trap\", \"~s\"}.~n", - [mk_ip(ManagerIp, Vsn), - ManagerIp, UDP, mk_param(Vsn)]), - case Vsn of - v1 -> ok; - v2 -> - ok = io:format(Fid, - "{\"~s.2\",~w,~w,1500,3, " - "\"std_inform\", \"~s\"}.~n", - [mk_ip(ManagerIp, Vsn), - ManagerIp, UDP, - mk_param(Vsn)]); - v3 -> - ok = io:format(Fid, - "{\"~s.3\",~w,~w,1500,3, " - "\"std_inform\", \"~s\", " - "\"mgrEngine\", [], 1024}.~n", - [mk_ip(ManagerIp, Vsn), - ManagerIp, UDP, - mk_param(Vsn)]) - end - end, - Vsns), - file:close(Fid). - -mk_param(v1) -> "target_v1"; -mk_param(v2) -> "target_v2"; -mk_param(v3) -> "target_v3". - -mk_ip([A,B,C,D], Vsn) -> - io_lib:format("~w.~w.~w.~w ~w", [A,B,C,D,Vsn]). - - -rewrite_target_addr_conf(Dir,NewPort) -> - TAFile = filename:join(Dir, "target_addr.conf"), - ?DBG("rewrite_target_addr_conf -> read target file info of address config file",[]), - case file:read_file_info(TAFile) of - {ok, _} -> ok; - {error, R} -> ?ERR("failure reading file info of " - "target address config file: ~p",[R]), - ok - end, - - ?line [TrapAddr|Addrs] = - snmp_conf:read(TAFile,fun(R) -> rewrite_target_addr_conf1(R) end), - - ?DBG("rewrite_target_addr_conf -> TrapAddr: ~p",[TrapAddr]), - - NewAddrs = [rewrite_target_addr_conf2(NewPort,TrapAddr)|Addrs], - - ?DBG("rewrite_target_addr_conf -> NewAddrs: ~p",[NewAddrs]), - - ?line ok = file:rename(filename:join(Dir,"target_addr.conf"), - filename:join(Dir,"target_addr.old")), - ?line {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), - - ?line ok = rewrite_target_addr_conf3(Fid,NewAddrs), - - file:close(Fid). - -rewrite_target_addr_conf1(O) -> - {ok,O}. - -rewrite_target_addr_conf2(NewPort,{Name,Ip,_Port,Timeout,Retry, - "std_trap",EngineId}) -> - ?LOG("rewrite_target_addr_conf2 -> entry with std_trap",[]), - {Name,Ip,NewPort,Timeout,Retry,"std_trap",EngineId}; -rewrite_target_addr_conf2(_NewPort,O) -> - ?LOG("rewrite_target_addr_conf2 -> entry with " - "~n O: ~p",[O]), - O. - - -rewrite_target_addr_conf3(_,[]) -> ok; -rewrite_target_addr_conf3(Fid,[{Name,Ip,Port,Timeout,Retry, - ParamName,EngineId}|T]) -> - ?LOG("rewrite_target_addr_conf3 -> write(1) ~s",[ParamName]), - io:format(Fid, - "{\"~s\", " % Name - "~p, " % Ip - "~p, " % Port - "~p, " % Timeout - "~p, " % Retry - "\"~s\", " % ParamsName - "\"~s\"}.", % EngineId - [Name,Ip,Port,Timeout,Retry,ParamName,EngineId]), - rewrite_target_addr_conf3(Fid,T); -rewrite_target_addr_conf3(Fid,[{Name,Ip,Port,Timeout,Retry,TagList, - ParamName,EngineId,TMask,MMS}|T]) -> - ?LOG("rewrite_target_addr_conf3 -> write(2) ~s",[ParamName]), - io:format(Fid, - "{\"~s\", " % Name - "~p, " % Ip - "~p, " % Port - "~p, " % Timeout - "~p, " % Retry - "\"~s\", " % TagList - "\"~s\", " % ParamsName - "\"~s\"," % EngineId - "~p, " % TMask - "~p}.", % MMS - [Name,Ip,Port,Timeout,Retry,TagList,ParamName, - EngineId,TMask,MMS]), - rewrite_target_addr_conf3(Fid,T). - -reset_target_addr_conf(Dir) -> - ?line ok = file:rename(filename:join(Dir,"target_addr.old"), - filename:join(Dir,"target_addr.conf")). - -write_target_params_conf(Dir, Vsns) -> - {ok, Fid} = file:open(filename:join(Dir,"target_params.conf"),write), - lists:foreach(fun(Vsn) -> - MP = if Vsn == v1 -> v1; - Vsn == v2 -> v2c; - Vsn == v3 -> v3 - end, - SM = if Vsn == v1 -> v1; - Vsn == v2 -> v2c; - Vsn == v3 -> usm - end, - ok = io:format(Fid, "{\"target_~w\", ~w, ~w, " - "\"all-rights\", noAuthNoPriv}.~n", - [Vsn, MP, SM]) - end, - Vsns), - file:close(Fid). - -rewrite_target_params_conf(Dir, SecName, SecLevel) -> - ?line ok = file:rename(filename:join(Dir,"target_params.conf"), - filename:join(Dir,"target_params.old")), - ?line {ok, Fid} = file:open(filename:join(Dir,"target_params.conf"),write), - ?line ok = io:format(Fid, "{\"target_v3\", v3, usm, \"~s\", ~w}.~n", - [SecName, SecLevel]), - file:close(Fid). - -reset_target_params_conf(Dir) -> - ?line ok = file:rename(filename:join(Dir,"target_params.old"), - filename:join(Dir,"target_params.conf")). - -write_notify_conf(Dir) -> - {ok, Fid} = file:open(filename:join(Dir,"notify.conf"),write), - ok = io:format(Fid, "{\"standard trap\", \"std_trap\", trap}.~n", []), - ok = io:format(Fid, "{\"standard inform\", \"std_inform\",inform}.~n", []), - file:close(Fid). - -ver_to_trap_str([v1]) -> "v1"; -ver_to_trap_str([v2]) -> "v2"; -% default is to use the latest snmp version -ver_to_trap_str([v1,v2]) -> "v2". - - - -write_view_conf(Dir) -> - {ok, Fid} = file:open(a(Dir,"view.conf"),write), - ok = io:format(Fid, "{2, [1,3,6], included, null}.~n", []), - ok = io:format(Fid, "{2, ~w, excluded, null}.~n", [?tDescr_instance]), - file:close(Fid). - -a(A,B) -> lists:append(A,B). - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -copy_file(From, To) -> - {ok, Bin} = file:read_file(From), - ok = file:write_file(To, Bin). - - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -display_memory_usage() -> - Info = snmpa:info(snmp_master_agent), - TreeSize = lists_key1search(tree_size_bytes, Info), - ProcMem = lists_key1search(process_memory, Info), - MibDbSize = lists_key1search([db_memory,mib], Info), - NodeDbSize = lists_key1search([db_memory,node], Info), - TreeDbSize = lists_key1search([db_memory,tree], Info), - ?INF("Memory usage: " - "~n Tree size: ~p" - "~n Process memory size: ~p" - "~n Mib db size: ~p" - "~n Node db size: ~p" - "~n Tree db size: ~p", - [TreeSize, ProcMem, MibDbSize, NodeDbSize, TreeDbSize]). - -lists_key1search([], Res) -> - Res; -lists_key1search([Key|Keys], List) when atom(Key), list(List) -> - case lists:keysearch(Key, 1, List) of - {value, {Key, Val}} -> - lists_key1search(Keys, Val); - false -> - undefined - end; -lists_key1search(Key, List) when atom(Key) -> - case lists:keysearch(Key, 1, List) of - {value, {Key, Val}} -> - Val; - false -> - undefined - end. - - -regs() -> - lists:sort(registered()). diff --git a/lib/snmp/test/snmp_agent_v3_test.erl b/lib/snmp/test/snmp_agent_v3_test.erl deleted file mode 100644 index 266be72878..0000000000 --- a/lib/snmp/test/snmp_agent_v3_test.erl +++ /dev/null @@ -1,5649 +0,0 @@ -%% -%% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2005-2010. All Rights Reserved. -%% -%% The contents of this file are subject to the Erlang Public License, -%% Version 1.1, (the "License"); you may not use this file except in -%% compliance with the License. You should have received a copy of the -%% Erlang Public License along with this software. If not, it can be -%% retrieved online at http://www.erlang.org/. -%% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -%% the License for the specific language governing rights and limitations -%% under the License. -%% -%% %CopyrightEnd% -%% - --module(snmp_agent_v3_test). - -%% TODO -%% * Test fault-tolerance (kill master etc) -%% - --compile(export_all). - --define(application, snmp). - --include_lib("kernel/include/file.hrl"). --include_lib("test_server/include/test_server.hrl"). --include("snmp_test_lib.hrl"). --define(SNMP_USE_V3, true). --include_lib("snmp/include/snmp_types.hrl"). -%% -include_lib("snmp/include/SNMP-COMMUNITY-MIB.hrl"). -%% -include_lib("snmp/include/SNMP-VIEW-BASED-ACM-MIB.hrl"). -%% -include_lib("snmp/include/SNMP-USER-BASED-SM-MIB.hrl"). - - --define(klas1, [1,3,6,1,2,1,7]). --define(klas2, [1,3,6,1,2,1,9]). --define(klas3, [1,3,6,1,2,1,8,1]). --define(klas4, [1,3,6,1,2,1,8,4]). --define(sa, [1,3,6,1,4,1,193,2]). --define(system, [1,3,6,1,2,1,1]). --define(snmp, [1,3,6,1,2,1,11]). --define(snmpTraps, [1,3,6,1,6,3,1,1,5]). --define(ericsson, [1,3,6,1,4,1,193]). --define(testTrap, [1,3,6,1,2,1,15,0]). --define(xDescr, [1,3,6,1,2,1,17,1]). --define(xDescr2, [1,3,6,1,2,1,17,2]). - --define(active, 1). --define(notInService, 2). --define(notReady, 3). --define(createAndGo, 4). --define(createAndWait, 5). --define(destroy, 6). - --define(TRAP_UDP, 5000). - --define(tooBigStr, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"). - --define(str(X), snmp_pdus:bits_to_str(X)). - --define(break(), begin io:format(user, "break at line ~w: pid: ~p\n", - [?LINE, self()]), - receive cont -> ok end - end). - - --import(snmp_test_mgr, [gn/1, g/1, s/1, gb/3]). --define(v1_2(V1,V2), - case get(vsn) of - v1 -> V1; - _ -> V2 - end). - --define(v1_2_3(V1,V2,V3), - case get(vsn) of - v1 -> V1; - v2 -> V2; - _ -> V3 - end). - -all() -> -[cases()]. - -groups() -> - [{mib_storage, [], - [{group, mib_storage_ets}, {group, mib_storage_dets}, - {group, mib_storage_mnesia}, - {group, mib_storage_size_check_ets}, - {group, mib_storage_size_check_dets}, - {group, mib_storage_size_check_mnesia}, - {group, mib_storage_varm_dets}, - {group, mib_storage_varm_mnesia}]}, - {mib_storage_ets, [], mib_storage_ets_cases()}, - {mib_storage_dets, [], mib_storage_dets_cases()}, - {mib_storage_mnesia, [], mib_storage_mnesia_cases()}, - {mib_storage_size_check_ets, [], - mse_size_check_cases()}, - {mib_storage_size_check_dets, [], - msd_size_check_cases()}, - {mib_storage_size_check_mnesia, [], - msm_size_check_cases()}, - {mib_storage_varm_dets, [], - varm_mib_storage_dets_cases()}, - {mib_storage_varm_mnesia, [], - varm_mib_storage_mnesia_cases()}, - {test_v1, [], v1_cases()}, {test_v2, [], v2_cases()}, - {test_v1_v2, [], v1_v2_cases()}, - {test_v3, [], v3_cases()}, - {test_multi_threaded, [], mt_cases()}, - {multiple_reqs, [], mul_cases()}, - {multiple_reqs_2, [], mul_cases_2()}, - {v2_inform, [], [v2_inform_i]}, - {v3_security, [], - [v3_crypto_basic, v3_md5_auth, v3_sha_auth, - v3_des_priv]}, - {standard_mibs, [], - [snmp_standard_mib, snmp_community_mib, - snmp_framework_mib, snmp_target_mib, - snmp_notification_mib, snmp_view_based_acm_mib]}, - {standard_mibs_2, [], - [snmpv2_mib_2, snmp_community_mib_2, - snmp_framework_mib_2, snmp_target_mib_2, - snmp_notification_mib_2, snmp_view_based_acm_mib_2]}, - {standard_mibs_3, [], - [snmpv2_mib_3, snmp_framework_mib_3, snmp_mpd_mib_3, - snmp_target_mib_3, snmp_notification_mib_3, - snmp_view_based_acm_mib_3, snmp_user_based_sm_mib_3]}, - {reported_bugs, [], - [otp_1128, otp_1129, otp_1131, otp_1162, otp_1222, - otp_1298, otp_1331, otp_1338, otp_1342, otp_2776, - otp_2979, otp_3187, otp_3725]}, - {reported_bugs_2, [], - [otp_1128_2, otp_1129_2, otp_1131_2, otp_1162_2, - otp_1222_2, otp_1298_2, otp_1331_2, otp_1338_2, - otp_1342_2, otp_2776_2, otp_2979_2, otp_3187_2]}, - {reported_bugs_3, [], - [otp_1128_3, otp_1129_3, otp_1131_3, otp_1162_3, - otp_1222_3, otp_1298_3, otp_1331_3, otp_1338_3, - otp_1342_3, otp_2776_3, otp_2979_3, otp_3187_3, - otp_3542]}, - {tickets, [], [{group, otp_4394}]}, - {otp_4394, [], [otp_4394_test]}]. - -init_per_group(otp_4394, Config) -> - init_otp_4394(Config); -init_per_group(v2_inform, Config) -> - init_v2_inform(Config); -init_per_group(multiple_reqs_2, Config) -> - init_mul(Config); -init_per_group(multiple_reqs, Config) -> - init_mul(Config); -init_per_group(test_multi_threaded, Config) -> - init_mt(Config); -init_per_group(test_v3, Config) -> - init_v3(Config); -init_per_group(test_v1_v2, Config) -> - init_v1_v2(Config); -init_per_group(test_v2, Config) -> - init_v2(Config); -init_per_group(test_v1, Config) -> - init_v1(Config); -init_per_group(mib_storage_varm_mnesia, Config) -> - init_varm_mib_storage_mnesia(Config); -init_per_group(mib_storage_varm_dets, Config) -> - init_varm_mib_storage_dets(Config); -init_per_group(mib_storage_size_check_mnesia, Config) -> - init_size_check_msm(Config); -init_per_group(mib_storage_size_check_dets, Config) -> - init_size_check_msd(Config); -init_per_group(mib_storage_size_check_ets, Config) -> - init_size_check_mse(Config); -init_per_group(mib_storage_mnesia, Config) -> - init_mib_storage_mnesia(Config); -init_per_group(mib_storage_dets, Config) -> - init_mib_storage_dets(Config); -init_per_group(mib_storage_ets, Config) -> - init_mib_storage_ets(Config); -init_per_group(_GroupName, Config) -> - Config. - -end_per_group(otp_4394, Config) -> - finish_otp_4394(Config); -end_per_group(v2_inform, Config) -> - finish_v2_inform(Config); -end_per_group(multiple_reqs_2, Config) -> - finish_mul(Config); -end_per_group(multiple_reqs, Config) -> - finish_mul(Config); -end_per_group(test_multi_threaded, Config) -> - finish_mt(Config); -end_per_group(test_v3, Config) -> - finish_v3(Config); -end_per_group(test_v1_v2, Config) -> - finish_v1_v2(Config); -end_per_group(test_v2, Config) -> - finish_v2(Config); -end_per_group(test_v1, Config) -> - finish_v1(Config); -end_per_group(mib_storage_varm_mnesia, Config) -> - finish_varm_mib_storage_mnesia(Config); -end_per_group(mib_storage_varm_dets, Config) -> - finish_varm_mib_storage_dets(Config); -end_per_group(mib_storage_size_check_mnesia, Config) -> - finish_size_check_msm(Config); -end_per_group(mib_storage_size_check_dets, Config) -> - finish_size_check_msd(Config); -end_per_group(mib_storage_size_check_ets, Config) -> - finish_size_check_mse(Config); -end_per_group(mib_storage_mnesia, Config) -> - finish_mib_storage_mnesia(Config); -end_per_group(mib_storage_dets, Config) -> - finish_mib_storage_dets(Config); -end_per_group(mib_storage_ets, Config) -> - finish_mib_storage_ets(Config); -end_per_group(_GroupName, Config) -> - Config. - - -init_per_testcase(_Case, Config) when list(Config) -> - Dog = ?t:timetrap(?t:minutes(6)), - [{watchdog, Dog}|Config]. - -end_per_testcase(_Case, Config) when list(Config) -> - Dog = ?config(watchdog, Config), - ?t:timetrap_cancel(Dog), - Config. - -cases() -> -case ?OSTYPE() of - vxworks -> - [app_info, {group, test_v1}, {group, test_v2}, - {group, test_v1_v2}, {group, test_multi_threaded}, - {group, mib_storage}, {group, tickets}]; - _Else -> - [app_info, {group, test_v1}, {group, test_v2}, - {group, test_v1_v2}, {group, test_v3}, - {group, test_multi_threaded}, {group, mib_storage}, - {group, tickets}] -end. - - -%%%----------------------------------------------------------------- -%%% The test case structure is as follows: -%%% -%%% init_all - starts mnesia, -%%% -%%% init_v1 - starts agent -%%% simple -%%% big - e.g. starts/stops subagent, load/unloads mibs -%%% init_mul -%%% mul_get -%%% mul_set -%%% -%%% finish_mul -%%% -%%% finish_v1 -%%% -%%% init_v2 - starts agent -%%% finish_v2 -%%% -%%% init_bilingual - starts agent -%%% finish_bilingual -%%% -%%% finish_all -%%% -%%% There is still one problem with these testsuites. If one test -%%% fails, it may not be possible to run some other cases, as it -%%% may have e.g. created some row or loaded some table, that it -%%% didn't undo (since it failed). -%%%----------------------------------------------------------------- - -init_all(Config0) when list(Config0) -> - ?LOG("init_all -> entry with" - "~n Config0: ~p",[Config0]), - - %% -- - %% Fix config: - %% - - DataDir0 = ?config(data_dir, Config0), - DataDir1 = filename:split(filename:absname(DataDir0)), - [_|DataDir2] = lists:reverse(DataDir1), - DataDir3 = filename:join(lists:reverse(DataDir2) ++ [?snmp_test_data]), - Config1 = lists:keydelete(data_dir, 1, Config0), - Config = [{data_dir, DataDir3 ++ "/"}|Config1], - - %% -- - %% Start nodes - %% - - ?line {ok, SaNode} = start_node(snmp_sa), - ?line {ok, MgrNode} = start_node(snmp_mgr), - - - %% -- - %% Create necessary files - %% - - Dir = ?config(priv_dir, Config), - ?DBG("init_all -> Dir ~p", [Dir]), - - DataDir = ?config(data_dir, Config), - ?DBG("init_all -> DataDir ~p", [DataDir]), - - file:make_dir(MgrDir = filename:join(Dir, "mgr_dir/")), - ?DBG("init_all -> MgrDir ~p", [MgrDir]), - - file:make_dir(AgentDir = filename:join(Dir, "agent_dir/")), - ?DBG("init_all -> AgentDir ~p", [AgentDir]), - - file:make_dir(SaDir = filename:join(Dir, "sa_dir/")), - ?DBG("init_all -> SaDir ~p", [SaDir]), - - - %% -- - %% Start and initiate mnesia - %% - - ?DBG("init_all -> load application mnesia", []), - ?line ok = application:load(mnesia), - - ?DBG("init_all -> load application mnesia on node ~p", [SaNode]), - ?line ok = rpc:call(SaNode, application, load, [mnesia]), - - ?DBG("init_all -> application mnesia: set_env dir",[]), - ?line application_controller:set_env(mnesia, dir, - filename:join(Dir, "Mnesia1")), - - ?DBG("init_all -> application mnesia: set_env dir on node ~p",[SaNode]), - ?line rpc:call(SaNode, application_controller, set_env, - [mnesia, dir, filename:join(Dir, "Mnesia2")]), - - ?DBG("init_all -> create mnesia schema",[]), - ?line ok = mnesia:create_schema([SaNode, node()]), - - ?DBG("init_all -> start application mnesia",[]), - ?line ok = application:start(mnesia), - - ?DBG("init_all -> start application mnesia on ~p",[SaNode]), - ?line ok = rpc:call(SaNode, application, start, [mnesia]), - Ip = ?LOCALHOST(), - [{snmp_sa, SaNode}, - {snmp_mgr, MgrNode}, - {agent_dir, AgentDir ++ "/"}, - {mgr_dir, MgrDir ++ "/"}, - {sa_dir, SaDir ++ "/"}, - {mib_dir, DataDir}, - {ip, Ip} | - Config]. - -finish_all(Config) when list(Config) -> - SaNode = ?config(snmp_sa, Config), - MgrNode = ?config(snmp_mgr, Config), - stop_node(SaNode), - stop_node(MgrNode), - application:stop(mnesia). - -start_v1_agent(Config) when list(Config) -> - start_agent(Config, [v1]). - -start_v1_agent(Config,Opts) when list(Config), list(Opts) -> - start_agent(Config, [v1], Opts). - -start_v2_agent(Config) when list(Config) -> - start_agent(Config, [v2]). - -start_v3_agent(Config) when list(Config) -> - start_agent(Config, [v3]). - -start_bilingual_agent(Config) when list(Config) -> - start_agent(Config, [v1,v2]). - -start_multi_threaded_agent(Config) when list(Config) -> - start_agent(Config, [v2], [{snmp_multi_threaded, true}]). - -stop_agent(Config) when list(Config) -> - ?LOG("stop_agent -> entry with" - "~n Config: ~p",[Config]), - - {Sup, Par} = ?config(snmp_sup, Config), - ?DBG("stop_agent -> attempt to stop (sup) ~p" - "~n Sup: ~p" - "~n Par: ~p", - [Sup, - (catch process_info(Sup)), - (catch process_info(Par))]), - stop_sup(Sup, Par), - - {Sup2, Par2} = ?config(snmp_sub, Config), - ?DBG("stop_agent -> attempt to stop (sub) ~p" - "~n Sup2: ~p" - "~n Par2: ~p", - [Sup2, - (catch process_info(Sup2)), - (catch process_info(Par2))]), - stop_sup(Sup2, Par2), - - ?DBG("stop_agent -> done - now cleanup config", []), - C1 = lists:keydelete(snmp_sup, 1, Config), - lists:keydelete(snmp_sub, 1, C1). - - -stop_sup(Pid, _) when node(Pid) == node() -> - case (catch process_info(Pid)) of - PI when list(PI) -> - ?LOG("stop_sup -> attempt to stop ~p", [Pid]), - Ref = erlang:monitor(process, Pid), - exit(Pid, kill), - await_stopped(Pid, Ref); - {'EXIT', _Reason} -> - ?LOG("stop_sup -> ~p not running", [Pid]), - ok - end; -stop_sup(Pid, _) -> - ?LOG("stop_sup -> attempt to stop ~p", [Pid]), - Ref = erlang:monitor(process, Pid), - ?LOG("stop_sup -> Ref: ~p", [Ref]), - %% Pid ! {'EXIT', Parent, shutdown}, % usch - exit(Pid, kill), - await_stopped(Pid, Ref). - -await_stopped(Pid, Ref) -> - receive - {'DOWN', Ref, process, Pid, _Reason} -> - ?DBG("received down message for ~p", [Pid]), - ok - after 10000 -> - ?INF("await_stopped -> timeout for ~p",[Pid]), - erlang:demonitor(Ref), - ?FAIL({failed_stop,Pid}) - end. - - -start_agent(Config, Vsn) -> - start_agent(Config, Vsn, []). -start_agent(Config, Vsn, Opts) -> - ?LOG("start_agent -> entry (~p) with" - "~n Config: ~p" - "~n Vsn: ~p" - "~n Opts: ~p",[node(), Config, Vsn, Opts]), - - ?line AgentDir = ?config(agent_dir, Config), - ?line SaNode = ?config(snmp_sa, Config), - - snmp_app_env_init(vsn_init(Vsn) ++ - [{audit_trail_log, read_write_log}, - {audit_trail_log_dir, AgentDir}, - {audit_trail_log_size, {10240, 10}}, - {force_config_reload, false}, - {snmp_agent_type, master}, - {snmp_config_dir, AgentDir}, - {snmp_db_dir, AgentDir}, - {snmp_local_db_auto_repair, true}, - {snmp_master_agent_verbosity, trace}, - {snmp_supervisor_verbosity, trace}, - {snmp_mibserver_verbosity, trace}, - {snmp_symbolic_store_verbosity, trace}, - {snmp_note_store_verbosity, trace}, - {snmp_net_if_verbosity, trace}], - Opts), - - - process_flag(trap_exit,true), - - {ok, AppSup} = snmp_app_sup:start_link(), - unlink(AppSup), - ?DBG("start_agent -> snmp app supervisor: ~p",[AppSup]), - - ?DBG("start_agent -> start master agent (old style)",[]), - Sup = case (catch snmpa_app:start(normal)) of - {ok, S} -> - ?DBG("start_agent -> started, Sup: ~p",[S]), - S; - - Else -> - ?DBG("start_agent -> unknown result: ~n~p",[Else]), - %% Get info about the apps we depend on - MnesiaInfo = mnesia_running(), - ?FAIL({start_failed,Else,MnesiaInfo}) - end, - - ?DBG("start_agent -> unlink from supervisor",[]), - ?line unlink(Sup), - ?line SaDir = ?config(sa_dir, Config), - ?DBG("start_agent -> (rpc) start sub on ~p",[SaNode]), - ?line {ok, Sub} = rpc:call(SaNode, ?MODULE, start_sub, [SaDir]), - ?DBG("start_agent -> done",[]), - ?line [{snmp_sup, {Sup, self()}}, {snmp_sub, Sub} | Config]. - - -vsn_init(Vsn) -> - vsn_init([v1,v2,v3], Vsn, []). - -vsn_init([], _Vsn, Acc) -> - Acc; -vsn_init([V|Vsns], Vsn, Acc) -> - case lists:member(V, Vsn) of - true -> - vsn_init(Vsns, Vsn, [{V, true}|Acc]); - false -> - vsn_init(Vsns, Vsn, [{V, false}|Acc]) - end. - -snmp_app_env_init(Env0, Opts) -> - ?DBG("snmp_app_env_init -> unload snmp",[]), - ?line application:unload(snmp), - ?DBG("snmp_app_env_init -> load snmp",[]), - ?line application:load(snmp), - ?DBG("snmp_app_env_init -> initiate (snmp) application env",[]), - F1 = fun({Key,Val} = New, Acc0) -> - ?DBG("snmp_app_env_init -> " - "updating setting ~p to ~p", [Key, Val]), - case lists:keyreplace(Key, 1, Acc0, New) of - Acc0 -> - [New|Acc0]; - Acc -> - Acc - end - end, - Env = lists:foldr(F1, Env0, Opts), - ?DBG("snmp_app_env_init -> Env: ~p",[Env]), - F2 = fun({Key,Val}) -> - ?DBG("snmp_app_env_init -> setting ~p to ~p",[Key, Val]), - application_controller:set_env(snmp, Key, Val) - end, - lists:foreach(F2, Env). - - - - -%% Test if application is running -mnesia_running() -> ?IS_MNESIA_RUNNING(). -crypto_running() -> ?IS_CRYPTO_RUNNING(). - - -start_sub(Dir) -> - ?DBG("start_sub -> entry",[]), - Opts = [{db_dir, Dir}, - {supervisor, [{verbosity, trace}]}], - %% BMK BMK -% {ok, P} = snmp_supervisor:start_sub(Dir), - {ok, P} = snmpa_supervisor:start_sub_sup(Opts), - unlink(P), - {ok, {P, self()}}. - -create_tables(SaNode) -> - ?line {atomic, ok} = mnesia:create_table([{name, friendsTable2}, - {ram_copies, [SaNode]}, - {snmp, [{key, integer}]}, - {attributes, [a1,a2,a3]}]), - ?line {atomic, ok} = mnesia:create_table([{name, kompissTable2}, - {ram_copies, [SaNode]}, - {snmp, [{key, integer}]}, - {attributes, [a1,a2,a3]}]), - ?line {atomic, ok} = mnesia:create_table([{name, snmp_variables}, - {attributes, [a1,a2]}]). - -delete_tables() -> - mnesia:delete_table(friendsTable2), - mnesia:delete_table(kompissTable2), - mnesia:delete_table(snmp_variables). - -%% Creation is done in runtime! -delete_mib_storage_mnesia_tables() -> - mnesia:delete_table(snmpa_mib_data), - mnesia:delete_table(snmpa_mib_tree), - mnesia:delete_table(snmpa_symbolic_store). - -%%----------------------------------------------------------------- -%% A test case is always one of: -%% - v1 specific case -%% - v2 specific case -%% - v1 and v2 case -%% All v1 specific cases are prefixed with v1_, and all v2 with -%% v2_. E.g. v1_trap/v2_trap. -%% -%% All other cases are shared. However, the testserver uses the name -%% of the case to generate a file for that case. The same case cannot -%% be used in different configurations in the same suite. Therefore -%% all these functions exists in two variants, the base function -%% , and a second version _2. There may be several -%% versions as well, _N. -%%----------------------------------------------------------------- - - - - - - - - - -mib_storage_ets_cases() -> -[mse_simple, mse_v1_processing, mse_big, mse_big2, - mse_loop_mib, mse_api, mse_sa_register, mse_v1_trap, - mse_sa_error, mse_next_across_sa, mse_undo, - mse_standard_mib, mse_community_mib, mse_framework_mib, - mse_target_mib, mse_notification_mib, - mse_view_based_acm_mib, mse_sparse_table, mse_me_of, - mse_mib_of]. - -mib_storage_dets_cases() -> -[msd_simple, msd_v1_processing, msd_big, msd_big2, - msd_loop_mib, msd_api, msd_sa_register, msd_v1_trap, - msd_sa_error, msd_next_across_sa, msd_undo, - msd_standard_mib, msd_community_mib, msd_framework_mib, - msd_target_mib, msd_notification_mib, - msd_view_based_acm_mib, msd_sparse_table, msd_me_of, - msd_mib_of]. - -mib_storage_mnesia_cases() -> -[msm_simple, msm_v1_processing, msm_big, msm_big2, - msm_loop_mib, msm_api, msm_sa_register, msm_v1_trap, - msm_sa_error, msm_next_across_sa, msm_undo, - msm_standard_mib, msm_community_mib, msm_framework_mib, - msm_target_mib, msm_notification_mib, - msm_view_based_acm_mib, msm_sparse_table, msm_me_of, - msm_mib_of]. - -mse_size_check_cases() -> -[mse_size_check]. - -msd_size_check_cases() -> -[msd_size_check]. - -msm_size_check_cases() -> -[msm_size_check]. - -varm_mib_storage_dets_cases() -> -[msd_varm_mib_start]. - -varm_mib_storage_mnesia_cases() -> -[msm_varm_mib_start]. - -init_mib_storage_ets(Config) when list(Config) -> - ?LOG("init_mib_storage_ets -> entry", []), - MibStorage = {snmp_mib_storage,ets}, - init_ms(Config, [MibStorage]). - -init_mib_storage_dets(Config) when list(Config) -> - ?LOG("init_mib_storage_ets -> entry", []), - ?line AgentDir = ?GCONF(agent_dir, Config), - MibStorage = {snmp_mib_storage,{dets,AgentDir}}, - init_ms(Config, [MibStorage]). - -init_mib_storage_mnesia(Config) when list(Config) -> - ?LOG("init_mib_storage_ets -> entry", []), - MibStorage = {snmp_mib_storage,{mnesia,[]}}, - init_ms(Config, [MibStorage]). - -init_ms(Config, Opts) when list(Config) -> - ?LOG("init_mib_storage_ets -> entry", []), - ?line SaNode = ?GCONF(snmp_sa, Config), - ?line create_tables(SaNode), - ?line AgentDir = ?GCONF(agent_dir, Config), - ?line MgrDir = ?GCONF(mgr_dir, Config), - ?line Ip = ?GCONF(ip, Config), - ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, - MibsVerbosity = {snmp_mibserver_verbosity, trace}, - SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, - Opts1 = [MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity|Opts], - [{vsn, v1} | start_v1_agent(Config,Opts1)]. - -init_size_check_mse(Config) when list(Config) -> - MibStorage = {snmp_mib_storage, ets}, - init_size_check_ms(Config, [MibStorage]). - -init_size_check_msd(Config) when list(Config) -> - AgentDir = ?GCONF(agent_dir, Config), - MibStorage = {snmp_mib_storage, {dets, AgentDir}}, - init_size_check_ms(Config, [MibStorage]). - -init_size_check_msm(Config) when list(Config) -> - MibStorage = {snmp_mib_storage, {mnesia,[]}}, - init_size_check_ms(Config, [MibStorage]). - -init_size_check_ms(Config, Opts) when list(Config) -> - SaNode = ?GCONF(snmp_sa, Config), - %% We are using v3 here, so crypto must be supported or else... - case ?CRYPTO_START() of - ok -> - case ?CRYPTO_SUPPORT() of - {no, Reason} -> - ?SKIP({unsupported_encryption, Reason}); - yes -> - ok - end; - {error, Reason} -> - ?SKIP({failed_starting_crypto, Reason}) - end, - create_tables(SaNode), - AgentDir = ?GCONF(agent_dir, Config), - MgrDir = ?GCONF(mgr_dir, Config), - Ip = ?GCONF(ip, Config), - ?line ok = - config([v3], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v3} | start_agent(Config, [v3], Opts)]. - -init_varm_mib_storage_dets(Config) when list(Config) -> - ?LOG("init_varm_mib_storage_dets -> entry", []), - ?line SaNode = ?GCONF(snmp_sa, Config), - ?line create_tables(SaNode), - ?line AgentDir = ?GCONF(agent_dir, Config), - ?line MgrDir = ?GCONF(mgr_dir, Config), - ?line Ip = ?GCONF(ip, Config), - ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - MibStorage = {snmp_mib_storage,{dets,AgentDir}}, - MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, - MibsVerbosity = {snmp_mibserver_verbosity, trace}, - SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, - Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity], - [{vsn, v1}, {agent_opts,Opts} | Config]. - -init_varm_mib_storage_mnesia(Config) when list(Config) -> - ?LOG("init_varm_mib_storage_mnesia -> entry", []), - ?line SaNode = ?GCONF(snmp_sa, Config), - ?line create_tables(SaNode), - ?line AgentDir = ?GCONF(agent_dir, Config), - ?line MgrDir = ?GCONF(mgr_dir, Config), - ?line Ip = ?GCONF(ip, Config), - ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - MibStorage = {snmp_mib_storage,{mnesia,[]}}, - MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, - MibsVerbosity = {snmp_mibserver_verbosity, trace}, - SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, - Opts = [MibStorage,MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity], - [{vsn, v1}, {agent_opts,Opts} | Config]. - -finish_mib_storage_ets(Config) when list(Config) -> - ?LOG("finish_mib_storage_ets -> entry", []), - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - C2 = lists:keydelete(vsn, 1, C1), - lists:keydelete(agent_opts, 1, C2). - -finish_mib_storage_dets(Config) when list(Config) -> - ?LOG("finish_mib_storage_dets -> entry", []), - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - C2 = lists:keydelete(vsn, 1, C1), - lists:keydelete(agent_opts, 1, C2). - -finish_mib_storage_mnesia(Config) when list(Config) -> - ?LOG("finish_mib_storage_mnesia -> entry", []), - delete_tables(), - delete_mib_storage_mnesia_tables(), - C1 = stop_agent(Config), - delete_files(C1), - C2 = lists:keydelete(vsn, 1, C1), - lists:keydelete(agent_opts, 1, C2). - -finish_varm_mib_storage_dets(Config) when list(Config) -> - ?LOG("finish_varm_mib_storage_dets -> entry", []), - delete_tables(), - %% C1 = stop_agent(Config), % In case something went wrong... - delete_files(Config), - C2 = lists:keydelete(vsn, 1, Config), - lists:keydelete(agent_opts, 1, C2). - -finish_varm_mib_storage_mnesia(Config) when list(Config) -> - ?LOG("finish_varm_mib_storage_mnesia -> entry", []), - delete_tables(), - delete_mib_storage_mnesia_tables(), - %% C1 = stop_agent(Config), % In case something went wrong... - delete_files(Config), - C2 = lists:keydelete(vsn, 1, Config), - lists:keydelete(agent_opts, 1, C2). - -finish_size_check_mse(Config) when list(Config) -> - finish_size_check_ms(Config). - -finish_size_check_msd(Config) when list(Config) -> - finish_size_check_ms(Config). - -finish_size_check_msm(Config) when list(Config) -> - finish_size_check_ms(Config). - -finish_size_check_ms(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - - -%% These are just interface functions to fool the test server -mse_simple(X) -> simple(X). -mse_v1_processing(X) -> v1_processing(X). -mse_big(X) -> big(X). -mse_big2(X) -> big2(X). -mse_loop_mib(X) -> loop_mib(X). -mse_api(X) -> api(X). -mse_sa_register(X) -> sa_register(X). -mse_v1_trap(X) -> v1_trap(X). -mse_sa_error(X) -> sa_error(X). -mse_next_across_sa(X) -> next_across_sa(X). -mse_undo(X) -> undo(X). -mse_standard_mib(X) -> snmp_standard_mib(X). -mse_community_mib(X) -> snmp_community_mib(X). -mse_framework_mib(X) -> snmp_framework_mib(X). -mse_target_mib(X) -> snmp_target_mib(X). -mse_notification_mib(X) -> snmp_notification_mib(X). -mse_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). -mse_sparse_table(X) -> sparse_table(X). -mse_me_of(X) -> ms_me_of(X). -mse_mib_of(X) -> ms_mib_of(X). - -msd_simple(X) -> simple(X). -msd_v1_processing(X) -> v1_processing(X). -msd_big(X) -> big(X). -msd_big2(X) -> big2(X). -msd_loop_mib(X) -> loop_mib(X). -msd_api(X) -> api(X). -msd_sa_register(X) -> sa_register(X). -msd_v1_trap(X) -> v1_trap(X). -msd_sa_error(X) -> sa_error(X). -msd_next_across_sa(X) -> next_across_sa(X). -msd_undo(X) -> undo(X). -msd_standard_mib(X) -> snmp_standard_mib(X). -msd_community_mib(X) -> snmp_community_mib(X). -msd_framework_mib(X) -> snmp_framework_mib(X). -msd_target_mib(X) -> snmp_target_mib(X). -msd_notification_mib(X) -> snmp_notification_mib(X). -msd_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). -msd_sparse_table(X) -> sparse_table(X). -msd_me_of(X) -> ms_me_of(X). -msd_mib_of(X) -> ms_mib_of(X). - -msm_simple(X) -> simple(X). -msm_v1_processing(X) -> v1_processing(X). -msm_big(X) -> big(X). -msm_big2(X) -> big2(X). -msm_loop_mib(X) -> loop_mib(X). -msm_api(X) -> api(X). -msm_sa_register(X) -> sa_register(X). -msm_v1_trap(X) -> v1_trap(X). -msm_sa_error(X) -> sa_error(X). -msm_next_across_sa(X) -> next_across_sa(X). -msm_undo(X) -> undo(X). -msm_standard_mib(X) -> snmp_standard_mib(X). -msm_community_mib(X) -> snmp_community_mib(X). -msm_framework_mib(X) -> snmp_framework_mib(X). -msm_target_mib(X) -> snmp_target_mib(X). -msm_notification_mib(X) -> snmp_notification_mib(X). -msm_view_based_acm_mib(X) -> snmp_view_based_acm_mib(X). -msm_sparse_table(X) -> sparse_table(X). -msm_me_of(X) -> ms_me_of(X). -msm_mib_of(X) -> ms_mib_of(X). - - -mse_size_check(X) -> p("mse_size_check..."), ms_size_check(X). -msd_size_check(X) -> p("msd_size_check..."), ms_size_check(X). -msm_size_check(X) -> p("msm_size_check..."), ms_size_check(X). - -msd_varm_mib_start(X) -> p("msd_varm_mib_start..."), varm_mib_start(X). -msm_varm_mib_start(X) -> p("msm_varm_mib_start..."), varm_mib_start(X). - -ms_size_check(suite) -> []; -ms_size_check(Config) when list(Config) -> - p("ms_size_check..."), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?LOG("mib server size check...", []), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - ?line load_master_std("OTP-SNMPEA-MIB"), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-MPD-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-USER-BASED-SM-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - ?line load_master_std("SNMPv2-MIB"), - ?line load_master_std("SNMPv2-TM"), - - ?SLEEP(2000), - - ?line display_memory_usage(), - - ?line unload_master("OTP-SNMPEA-MIB"), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?line unload_master("SNMP-MPD-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-USER-BASED-SM-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - ?line unload_master("SNMPv2-MIB"), - ?line unload_master("SNMPv2-TM"), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - - ok. - - -varm_mib_start(suite) -> []; -varm_mib_start(Config) when list(Config) -> - p("varm_mib_start..."), - ?LOG("varm_mib_start -> entry", []), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - %% Start the agent - Opts = ?GCONF(agent_opts, Config), - Config1 = start_v1_agent(Config, Opts), - - %% Sleep some in order for the agent to start properly - ?DBG("varm_mib_start -> sleep some (before loading mobs)", []), - ?SLEEP(5000), - - %% Load all the mibs - HardwiredMibs = loaded_mibs(), - ?DBG("varm_mib_start -> load all mibs", []), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - - %% Unload the hardwired mibs - ?DBG("varm_mib_start -> sleep some (before unloading hardwired mibs)", []), - ?SLEEP(1000), - ?DBG("varm_mib_start -> unload (hardwired) mibs", []), - ?line unload_mibs(HardwiredMibs), %% unload hardwired - - ?DBG("varm_mib_start -> sleep some (before stopping agent)", []), - ?SLEEP(1000), - - %% Stop the agent (without deleting the stored files) - ?DBG("varm_mib_start -> stop the agent", []), - Config2 = stop_agent(Config1), - - %% Sleep some in order for the agent to stop properly - ?DBG("varm_mib_start -> sleep some (before re-starting the agent)", []), - ?SLEEP(5000), - - %% Start the agent (again) - ?DBG("varm_mib_start -> start the agent", []), - Config3 = start_v1_agent(Config2, Opts), - - ?DBG("varm_mib_start -> sleep some (before starting tests)", []), - ?SLEEP(5000), - - %% Perform the test(s) - ?DBG("varm_mib_start -> perform the tests", []), - try_test(snmp_community_mib), - try_test(snmp_framework_mib), - try_test(snmp_target_mib), - try_test(snmp_notification_mib), - - %% Stop the agent (without deleting the stored files) - ?DBG("varm_mib_start -> stop the agent", []), - stop_agent(Config3), - ok. - - --define(snmpTrapCommunity_instance, [1,3,6,1,6,3,18,1,4,0]). --define(vacmViewSpinLock_instance, [1,3,6,1,6,3,16,1,5,1,0]). --define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). - -ms_me_of(suite) -> []; -ms_me_of(Config) when list(Config) -> - p("ms_me_of..."), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - ?line load_master_std("OTP-SNMPEA-MIB"), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-MPD-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - - ?SLEEP(2000), - - ?line display_memory_usage(), - - - ?DBG("ms_me_of -> find ~w from SNMP-COMMUNITY-MIB", - [?snmpTrapCommunity_instance]), - ?line ok = me_of(?snmpTrapCommunity_instance), - - ?DBG("ms_me_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", - [?vacmViewSpinLock_instance]), - ?line ok = me_of(?vacmViewSpinLock_instance), - - ?DBG("ms_me_of -> find ~w from SNMP-USER-BASED-SM-MIB", - [?usmStatsNotInTimeWindows_instance]), - ?line {error, _} = me_of(?usmStatsNotInTimeWindows_instance), - - - ?line unload_master("OTP-SNMPEA-MIB"), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?line unload_master("SNMP-MPD-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - - ok. - -me_of(Oid) -> - case snmpa:me_of(Oid) of - {ok, #me{oid = Oid}} -> - ok; - {ok, #me{oid = OtherOid}} -> - case lists:reverse(Oid) of - [0|Rest] -> - case lists:reverse(Rest) of - OtherOid -> - ok; - AnotherOid -> - {error, {invalid_oid, Oid, AnotherOid}} - end; - _ -> - {error, {invalid_oid, Oid, OtherOid}} - end; - {error, Reason} -> - {error, Reason}; - Else -> - {error, Else} - end. - - -ms_mib_of(suite) -> []; -ms_mib_of(Config) when list(Config) -> - p("ms_mib_of..."), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - ?line load_master_std("OTP-SNMPEA-MIB"), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-MPD-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - - ?SLEEP(2000), - - ?line display_memory_usage(), - - - ?DBG("ms_mib_of -> find ~w from SNMP-COMMUNITY-MIB", - [?snmpTrapCommunity_instance]), - ?line ok = mib_of(?snmpTrapCommunity_instance, 'SNMP-COMMUNITY-MIB'), - - ?DBG("ms_mib_of -> find ~w from SNMP-VIEW-BASED-ACM-MIB", - [?vacmViewSpinLock_instance]), - ?line ok = mib_of(?vacmViewSpinLock_instance, 'SNMP-VIEW-BASED-ACM-MIB'), - - ?DBG("ms_mib_of -> find ~w from SNMP-USER-BASED-SM-MIB", - [?usmStatsNotInTimeWindows_instance]), - ?line {error, _} = mib_of(?usmStatsNotInTimeWindows_instance, - 'SNMP-USER-BASED-SM-MIB'), - - - ?line unload_master("OTP-SNMPEA-MIB"), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?line unload_master("SNMP-MPD-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - - ok. - -mib_of(Oid, ExpectedMibName) -> - ?DBG("mib_of -> entry with" - "~n Oid: ~p" - "~n ExpectedMibName: ~p", [Oid, ExpectedMibName]), - %% case snmpa:mib_of(Oid) of - MibOf = snmpa:mib_of(Oid), - ?DBG("mib_of -> MibOf: ~n~p", [MibOf]), - case MibOf of - {ok, ExpectedMibName} -> - ok; - {ok, OtherMibName} -> - {error, {invalid_mib, ExpectedMibName, OtherMibName}}; - {error, Reason} -> - {error, Reason}; - Else -> - ?DBG("mib_of -> Else: ~n~p", [Else]), - {error, Else} - end. - - -app_info(suite) -> []; -app_info(Config) when list(Config) -> - SnmpDir = app_dir(snmp), - SslDir = app_dir(ssl), - CryptoDir = app_dir(crypto), - Attr = snmp:module_info(attributes), - AppVsn = - case lists:keysearch(app_vsn, 1, Attr) of - {value, {app_vsn, V}} -> - V; - false -> - "undefined" - end, - io:format("Root dir: ~s~n" - "SNMP: Application dir: ~s~n" - " Application ver: ~s~n" - "SSL: Application dir: ~s~n" - "CRYPTO: Application dir: ~s~n", - [code:root_dir(), SnmpDir, AppVsn, SslDir, CryptoDir]), - ok. - -app_dir(App) -> - case code:lib_dir(App) of - D when list(D) -> - filename:basename(D); - {error, _Reason} -> - "undefined" - end. - - - -%v1_cases() -> [loop_mib]; -v1_cases() -> -[simple, db_notify_client, v1_processing, big, big2, - loop_mib, api, subagent, mnesia, {group, multiple_reqs}, - sa_register, v1_trap, sa_error, next_across_sa, undo, - {group, reported_bugs}, {group, standard_mibs}, - sparse_table, cnt_64, opaque, change_target_addr_config]. - -init_v1(Config) when list(Config) -> - ?line SaNode = ?config(snmp_sa, Config), - ?line create_tables(SaNode), - ?line AgentDir = ?config(agent_dir, Config), - ?line MgrDir = ?config(mgr_dir, Config), - ?line Ip = ?config(ip, Config), - ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v1} | start_v1_agent(Config)]. - -finish_v1(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - - -%v2_cases() -> [loop_mib_2]; -v2_cases() -> -[simple_2, v2_processing, big_2, big2_2, loop_mib_2, - api_2, subagent_2, mnesia_2, {group, multiple_reqs_2}, - sa_register_2, v2_trap, {group, v2_inform}, sa_error_2, - next_across_sa_2, undo_2, {group, reported_bugs_2}, - {group, standard_mibs_2}, v2_types, implied, - sparse_table_2, cnt_64_2, opaque_2, v2_caps]. - -init_v2(Config) when list(Config) -> - SaNode = ?config(snmp_sa, Config), - create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), - MgrDir = ?config(mgr_dir, Config), - Ip = ?config(ip, Config), - config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v2} | start_v2_agent(Config)]. - -finish_v2(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - - -v1_v2_cases() -> -[simple_bi]. - -init_v1_v2(Config) when list(Config) -> - SaNode = ?config(snmp_sa, Config), - create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), - MgrDir = ?config(mgr_dir, Config), - Ip = ?config(ip, Config), - config([v1,v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, bilingual} | start_bilingual_agent(Config)]. - -finish_v1_v2(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - - -%v3_cases() -> [loop_mib_3]; -v3_cases() -> -[simple_3, v3_processing, big_3, big2_3, api_3, - subagent_3, mnesia_3, loop_mib_3, multiple_reqs_3, - sa_register_3, v3_trap, v3_inform, sa_error_3, - next_across_sa_3, undo_3, {group, reported_bugs_3}, - {group, standard_mibs_3}, {group, v3_security}, - v2_types_3, implied_3, sparse_table_3, cnt_64_3, - opaque_3, v2_caps_3]. - -init_v3(Config) when list(Config) -> - %% Make sure crypto works, otherwise start_agent will fail - %% and we will be stuck with a bunch of mnesia tables for - %% the rest of this suite... - ?DBG("start_agent -> start crypto app",[]), - case os:type() of - vxworks -> - no_crypto; - _ -> - case ?CRYPTO_START() of - ok -> - case ?CRYPTO_SUPPORT() of - {no, Reason} -> - ?SKIP({unsupported_encryption, Reason}); - yes -> - ok - end; - {error, Reason} -> - ?SKIP({failed_starting_crypto, Reason}) - end - end, - SaNode = ?config(snmp_sa, Config), - create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), - MgrDir = ?config(mgr_dir, Config), - Ip = ?config(ip, Config), - ?line ok = config([v3], MgrDir, AgentDir, - tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v3} | start_v3_agent(Config)]. - -finish_v3(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - - -mt_cases() -> -[multi_threaded, mt_trap]. - -init_mt(Config) when list(Config) -> - SaNode = ?config(snmp_sa, Config), - create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), - MgrDir = ?config(mgr_dir, Config), - Ip = ?config(ip, Config), - ?line ok = config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v2} | start_multi_threaded_agent(Config)]. - -finish_mt(Config) when list(Config) -> - delete_tables(), - C1 = stop_agent(Config), - delete_files(C1), - lists:keydelete(vsn, 1, C1). - -%% This one *must* be run first in each case. -init_case(Config) when list(Config) -> - ?DBG("init_case -> entry with" - "~n Config: ~p", [Config]), - SaNode = ?config(snmp_sa, Config), - MgrNode = ?config(snmp_mgr, Config), - MasterNode = node(), - - SaHost = ?HOSTNAME(SaNode), - MgrHost = ?HOSTNAME(MgrNode), - MasterHost = ?HOSTNAME(MasterNode), - {ok, MasterIP} = snmp_misc:ip(MasterHost), - {ok, MIP} = snmp_misc:ip(MgrHost), - {ok, SIP} = snmp_misc:ip(SaHost), - - - put(mgr_node, MgrNode), - put(sa_node, SaNode), - put(master_node, MasterNode), - put(sa_host, SaHost), - put(mgr_host, MgrHost), - put(master_host, MasterHost), - put(mip, tuple_to_list(MIP)), - put(masterip , tuple_to_list(MasterIP)), - put(sip, tuple_to_list(SIP)), - - MibDir = ?config(mib_dir, Config), - put(mib_dir, MibDir), - StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", - put(std_mib_dir, StdM), - - MgrDir = ?config(mgr_dir, Config), - put(mgr_dir, MgrDir), - - put(vsn, ?config(vsn, Config)), - ?DBG("init_case -> exit with" - "~n MasterNode: ~p" - "~n SaNode: ~p" - "~n MgrNode: ~p" - "~n MibDir: ~p", [MasterNode, SaNode, MgrNode, MibDir]), - {SaNode, MgrNode, MibDir}. - -load_master(Mib) -> - ?DBG("load_master -> entry with" - "~n Mib: ~p", [Mib]), - snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety - ok = snmpa:load_mibs(snmp_master_agent, [get(mib_dir) ++ Mib]). - -load_master_std(Mib) -> - ?DBG("load_master_std -> entry with" - "~n Mib: ~p", [Mib]), - snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety - ok = snmpa:load_mibs(snmp_master_agent, [get(std_mib_dir) ++ Mib]). - -unload_master(Mib) -> - ?DBG("unload_master -> entry with" - "~n Mib: ~p", [Mib]), - ok = snmpa:unload_mibs(snmp_master_agent, [Mib]). - -loaded_mibs() -> - ?DBG("loaded_mibs -> entry",[]), - Info = snmpa:info(snmp_master_agent), - {value, {loaded_mibs, Mibs}} = lists:keysearch(loaded_mibs, 1, Info), - [atom_to_list(Mib) || {Mib,_,_} <- Mibs]. - -unload_mibs(Mibs) -> - ?DBG("unload_mibs -> entry with" - "~n Mibs: ~p", [Mibs]), - ok = snmpa:unload_mibs(snmp_master_agent, Mibs). - -start_subagent(SaNode, RegTree, Mib) -> - ?DBG("start_subagent -> entry with" - "~n SaNode: ~p" - "~n RegTree: ~p" - "~n Mib: ~p", [SaNode, RegTree, Mib]), - MA = whereis(snmp_master_agent), - ?DBG("start_subagent -> MA: ~p", [MA]), - MibDir = get(mib_dir), - Mib1 = join(MibDir,Mib), - %% BMK BMK -% case rpc:call(SaNode,snmp_supervisor,start_subagent,[MA,RegTree,[Mib1]]) of - case rpc:call(SaNode, snmpa_supervisor, - start_sub_agent, [MA, RegTree, [Mib1]]) of - {ok, SA} -> - ?DBG("start_subagent -> SA: ~p", [SA]), - {ok, SA}; - Error -> - ?FAIL({subagent_start_failed, SaNode, Error, [MA, RegTree, Mib1]}) - end. - -stop_subagent(SA) -> - ?DBG("stop_subagent -> entry with" - "~n SA: ~p", [SA]), - %% BNK BMK - %% rpc:call(node(SA), snmp_supervisor, stop_subagent, [SA]). - rpc:call(node(SA), snmpa_supervisor, stop_sub_agent, [SA]). - -%%----------------------------------------------------------------- -%% This function takes care of the old OTP-SNMPEA-MIB. -%% Unfortunately, the testcases were written to use the data in the -%% internal tables, and these table are now obsolete and not used -%% by the agent. Therefore, we emulate them by using -%% OLD-SNMPEA-MIB, which uses the default impl. of all tables. -%% -%% These two rows must exist in intCommunityTable -%% {[147,214,36,45], "public", 2, readWrite}. -%% {[147,214,36,45], "standard trap", 2, read}. -%% (But with the manager's IP address) -%% -%%----------------------------------------------------------------- -init_old() -> - snmpa_local_db:table_create_row(intCommunityTable, - get(mip) ++ [6 | "public"], - {get(mip), "public", 2, 2}), - snmpa_local_db:table_create_row(intCommunityTable, - get(mip) ++ [13 | "standard trap"], - {get(mip), "standard trap", 2, 1}), - snmpa_local_db:variable_set(intAgentIpAddress, [127,0,0,1]). - - - -simple(suite) -> []; -simple(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - try_test(simple_standard_test). - -simple_2(X) -> simple(X). - -simple_bi(suite) -> []; -simple_bi(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - put(vsn, v1), % First, try v1 manager - try_test(simple_standard_test), - - put(vsn, v2), % Then, try v2 manager - try_test(simple_standard_test). - -simple_3(X) -> - simple(X). - -big(suite) -> []; -big(Config) when list(Config) -> - ?DBG("big -> entry", []), - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Starting subagent..."), - ?line pong = net_adm:ping(SaNode), - - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), - ?DBG("big -> SA: ~p", [SA]), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(big_test), - ?line stop_subagent(SA), - ?line unload_master("OLD-SNMPEA-MIB"). - -big_2(X) -> big(X). - -big_3(X) -> big(X). - - -big2(suite) -> []; -big2(Config) when list(Config) -> - %% This is exactly the same tests as 'big', but with the - %% v2 equivalent of the mibs. - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Starting subagent..."), - ?line pong = net_adm:ping(SaNode), - - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1-v2"), - ?line load_master("OLD-SNMPEA-MIB-v2"), - ?line init_old(), - try_test(big_test), - ?line stop_subagent(SA), - ?line unload_master("OLD-SNMPEA-MIB-v2"). - -big2_2(X) -> big2(X). - -big2_3(X) -> big2(X). - - -multi_threaded(suite) -> []; -multi_threaded(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test1"), - try_test(multi_threaded_test), - ?line unload_master("Test1"). - -mt_trap(suite) -> []; -mt_trap(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line load_master("Test1"), - ?line load_master("TestTrapv2"), - try_test(mt_trap_test, [MA]), - ?line unload_master("TestTrapv2"), - ?line unload_master("Test1"). - -v2_types(suite) -> []; -v2_types(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test1"), - try_test(types_v2_test), - ?line unload_master("Test1"). - -v2_types_3(X) -> v2_types(X). - - -implied(suite) -> []; -implied(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line load_master("Test1"), - try_test(implied_test,[MA]), - ?line unload_master("Test1"). - -implied_3(X) -> implied(X). - - -sparse_table(suite) -> []; -sparse_table(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test1"), - try_test(sparse_table_test), - ?line unload_master("Test1"). - -sparse_table_2(X) -> sparse_table(X). - -sparse_table_3(X) -> sparse_table(X). - -cnt_64(suite) -> []; -cnt_64(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line load_master("Test1"), - try_test(cnt_64_test, [MA]), - ?line unload_master("Test1"). - -cnt_64_2(X) -> cnt_64(X). - -cnt_64_3(X) -> cnt_64(X). - -opaque(suite) -> []; -opaque(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test1"), - try_test(opaque_test), - ?line unload_master("Test1"). - -opaque_2(X) -> opaque(X). - -opaque_3(X) -> opaque(X). - - -change_target_addr_config(suite) -> []; -change_target_addr_config(Config) when list(Config) -> - p("Testing changing target address config..."), - ?LOG("change_target_addr_config -> entry",[]), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - put(sname,snmp_suite), - put(verbosity,trace), - - MA = whereis(snmp_master_agent), - - ?LOG("change_target_addr_config -> load TestTrap",[]), - ?line load_master("TestTrap"), - - ?LOG("change_target_addr_config -> set trace verbosity for local_db",[]), - ?line snmpa:verbosity(local_db,trace), - - %% First send some traps that will arive att the original manager - ?LOG("change_target_addr_config -> send trap",[]), - try_test(ma_trap1, [MA]), - - ?LOG("change_target_addr_config -> set silence verbosity for local_db",[]), - ?line snmpa:verbosity(local_db,silence), - - %% Start new dummy listener - ?LOG("change_target_addr_config -> start dummy manager",[]), - ?line {ok,Pid,NewPort} = dummy_manager_start(MA), - - %% Reconfigure - ?LOG("change_target_addr_config -> reconfigure",[]), - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_addr_conf(AgentDir, NewPort), - ?line snmp_target_mib:reconfigure(AgentDir), - - %% Send the trap again - ?LOG("change_target_addr_config -> send trap again",[]), - catch dummy_manager_send_trap2(Pid), - - ?LOG("change_target_addr_config -> await trap ack",[]), - catch dummy_manager_await_trap2_ack(), - - ?LOG("change_target_addr_config -> stop dummy manager",[]), - ?line ok = dummy_manager_stop(Pid), - - ?LOG("change_target_addr_config -> reset target address config",[]), - ?line reset_target_addr_conf(AgentDir), - - ?LOG("change_target_addr_config -> unload TestTrap",[]), - ?line unload_master("TestTrap"). - - -dummy_manager_start(MA) -> - ?DBG("dummy_manager_start -> entry",[]), - Pid = spawn(get(mgr_node), ?MODULE,dummy_manager_init,[self(),MA]), - ?DBG("dummy_manager_start -> Pid: ~p",[Pid]), - await_dummy_manager_started(Pid). - -await_dummy_manager_started(Pid) -> - receive - {dummy_manager_started,Pid,Port} -> - ?DBG("dummy_manager_start -> acknowledge received with" - "~n Port: ~p",[Port]), - {ok,Pid,Port}; - {'EXIT', Pid, Reason} -> - {error, Pid, Reason}; - O -> - ?LOG("dummy_manager_start -> received unknown message:" - "~n ~p",[O]), - await_dummy_manager_started(Pid) - end. - -dummy_manager_stop(Pid) -> - ?DBG("dummy_manager_stop -> entry with Pid: ~p",[Pid]), - Pid ! stop, - receive - {dummy_manager_stopping, Pid} -> - ?DBG("dummy_manager_stop -> acknowledge received",[]), - ok - after 10000 -> - ?ERR("dummy_manager_stop -> timeout",[]), - timeout - end. - -dummy_manager_send_trap2(Pid) -> - ?DBG("dummy_manager_send_trap2 -> entry",[]), - Pid ! {send_trap,testTrap2}. - -dummy_manager_await_trap2_ack() -> - ?DBG("dummy_manager_await_trap2 -> entry",[]), - receive - {received_trap,Trap} -> - ?LOG("dummy_manager_await_trap2 -> received trap: ~p",[Trap]), - %% Note: - %% Without this sleep the v2_inform_i testcase failes! There - %% is no relation between these two test cases as far as I - %% able to figure out... - sleep(60000), - ok; - O -> - ?ERR("dummy_manager_await_trap2 -> unexpected message: ~p",[O]), - ok - after 10000 -> - ?ERR("dummy_manager_await_trap2 -> timeout",[]), - timeout - end. - -dummy_manager_init(Parent,MA) -> - ?DBG("dummy_manager_init -> entry with" - "~n Parent: ~p" - "~n MA: ~p",[Parent,MA]), - {ok,S} = gen_udp:open(0,[{recbuf,65535}]), - ?DBG("dummy_manager_init -> S: ~p",[S]), - {ok,Port} = inet:port(S), - ?DBG("dummy_manager_init -> Port: ~p",[Port]), - Parent ! {dummy_manager_started,self(),Port}, - dummy_manager_loop(Parent,S,MA). - -dummy_manager_loop(P,S,MA) -> - ?LOG("dummy_manager_loop -> ready for receive",[]), - receive - {send_trap,Trap} -> - ?LOG("dummy_manager_loop -> received trap send request" - "~n Trap: ~p",[Trap]), - snmpa:send_trap(MA, Trap, "standard trap"), - dummy_manager_loop(P,S,MA); - {udp, _UdpId, Ip, UdpPort, Bytes} -> - ?LOG("dummy_manager_loop -> received upd message" - "~n from: ~p:~p" - "~n size: ~p", - [Ip, UdpPort, dummy_manager_message_sz(Bytes)]), - R = dummy_manager_handle_message(Bytes), - ?DBG("dummy_manager_loop -> R: ~p",[R]), - P ! R, - dummy_manager_loop(P,S,MA); - stop -> - ?DBG("dummy_manager_loop -> received stop request",[]), - P ! {dummy_manager_stopping, self()}, - gen_udp:close(S), - exit(normal); - O -> - ?LOG("dummy_manager_loop -> received unknown message:" - "~n ~p",[O]), - dummy_manager_loop(P,S,MA) - end. - -dummy_manager_message_sz(B) when binary(B) -> - size(B); -dummy_manager_message_sz(L) when list(L) -> - length(L); -dummy_manager_message_sz(_) -> - undefined. - -dummy_manager_handle_message(Bytes) -> - case (catch snmp_pdus:dec_message(Bytes)) of - {'EXIT',Reason} -> - ?ERR("dummy_manager_handle_message -> " - "failed decoding message only:~n ~p",[Reason]), - {error,Reason}; - M -> - ?DBG("dummy_manager_handle_message -> decoded message:" - "~n ~p",[M]), - {received_trap,M} - end. - - -api(suite) -> []; -api(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(api_test, [node()]), - ?line unload_master("OLD-SNMPEA-MIB"). - -api_2(X) -> api(X). - -api_3(X) -> api(X). - - -subagent(suite) -> []; -subagent(Config) when list(Config) -> - {SaNode, _MgrNode, MibDir} = init_case(Config), - - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), - try_test(load_test_sa), - - p("Testing unregister subagent..."), - MA = whereis(snmp_master_agent), - rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), - try_test(unreg_test), - - p("Loading previous subagent mib in master and testing..."), - ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas1"]), - try_test(load_test), - - p("Unloading previous subagent mib in master and testing..."), - ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas1"]), - try_test(unreg_test), - p("Testing register subagent..."), - rpc:call(SaNode, snmp, register_subagent, - [MA, ?klas1, SA]), - try_test(load_test_sa), - - ?line stop_subagent(SA), - try_test(unreg_test). - -subagent_2(X) -> subagent(X). - -subagent_3(X) -> subagent(X). - - -mnesia(suite) -> []; -mnesia(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Starting subagent with mnesia impl..."), - {ok, SA} = start_subagent(SaNode, ?klas2, "Klas2"), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - - try_test(big_test_2), - - p("Testing unregister subagent..."), - MA = whereis(snmp_master_agent), - rpc:call(SaNode, snmp, unregister_subagent, [MA, SA]), - try_test(unreg_test), - ?line unload_master("OLD-SNMPEA-MIB"), - ?line stop_subagent(SA). - -mnesia_2(X) -> mnesia(X). - -mnesia_3(X) -> mnesia(X). - - - -mul_cases() -> -[mul_get, mul_get_err, mul_next, mul_next_err, - mul_set_err]. - - -multiple_reqs_3(_X) -> - {req, [], {conf, init_mul, mul_cases_3(), finish_mul}}. - - -mul_cases_2() -> -[mul_get_2, mul_get_err_2, mul_next_2, mul_next_err_2, - mul_set_err_2]. - - -mul_cases_3() -> - [mul_get_3, mul_get_err_3, mul_next_3, mul_next_err_3, mul_set_err_3]. - - -init_mul(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - [{mul_sub, SA} | Config]. - -finish_mul(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - SA = ?config(mul_sub, Config), - - ?line unload_master("OLD-SNMPEA-MIB"), - ?line stop_subagent(SA), - lists:keydelete(mul_sub, 1, Config). - -mul_get(suite) -> []; -mul_get(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple get..."), - try_test(do_mul_get). - -mul_get_2(X) -> mul_get(X). - -mul_get_3(X) -> mul_get(X). - - -mul_get_err(suite) -> []; -mul_get_err(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple get with error..."), - try_test(do_mul_get_err). - -mul_get_err_2(X) -> mul_get_err(X). - -mul_get_err_3(X) -> mul_get_err(X). - - -mul_next(suite) -> []; -mul_next(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple next..."), - try_test(do_mul_next). - -mul_next_2(X) -> mul_next(X). - -mul_next_3(X) -> mul_next(X). - - -mul_next_err(suite) -> []; -mul_next_err(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple next..."), - try_test(do_mul_next_err). - -mul_next_err_2(X) -> mul_next_err(X). - -mul_next_err_3(X) -> mul_next_err(X). - - -mul_set(suite) -> []; -mul_set(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple set..."), - try_test(do_mul_set). - -mul_set_2(X) -> mul_set(X). - -mul_set_3(X) -> mul_set(X). - - -mul_set_err(suite) -> []; -mul_set_err(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing multiple set with error..."), - try_test(do_mul_set_err). - -mul_set_err_2(X) -> mul_set_err(X). - -mul_set_err_3(X) -> mul_set_err(X). - - -sa_register(suite) -> []; -sa_register(Config) when list(Config) -> - ?DBG("sa_register -> entry", []), - {SaNode, _MgrNode, MibDir} = init_case(Config), - - ?DBG("sa_register -> start subagent", []), - ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"), - - ?DBG("sa_register -> unregister subagent", []), - p("Testing unregister subagent (2)..."), - MA = whereis(snmp_master_agent), - rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), - try_test(unreg_test), - - p("Loading SA-MIB..."), - ?DBG("sa_register -> unload mibs", []), - snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), - ?DBG("sa_register -> unload mibs", []), - snmpa:load_mibs(SA, [MibDir ++ "SA-MIB"]), - ?DBG("sa_register -> register subagent", []), - rpc:call(SaNode, snmp, register_subagent, [MA,?sa,SA]), - try_test(sa_mib), - - ?DBG("sa_register -> stop subagent", []), - ?line stop_subagent(SA). - -sa_register_2(X) -> sa_register(X). - -sa_register_3(X) -> sa_register(X). - - -v1_trap(suite) -> []; -v1_trap(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Testing trap sending from master agent..."), - MA = whereis(snmp_master_agent), - - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(ma_trap1, [MA]), - try_test(ma_trap2, [MA]), - try_test(ma_v2_2_v1_trap, [MA]), - try_test(ma_v2_2_v1_trap2, [MA]), - - p("Testing trap sending from subagent..."), - try_test(sa_trap1, [SA]), - try_test(sa_trap2, [SA]), - try_test(sa_trap3, [SA]), - - ?line unload_master("TestTrap"), - ?line unload_master("TestTrapv2"), - - ?line stop_subagent(SA). - -v2_trap(suite) -> []; -v2_trap(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Testing trap sending from master agent..."), - MA = whereis(snmp_master_agent), - - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - - try_test(ma_v2_trap1, [MA]), - try_test(ma_v2_trap2, [MA]), - try_test(ma_v1_2_v2_trap, [MA]), - try_test(ma_v1_2_v2_trap2, [MA]), - - try_test(sa_mib), - p("Testing trap sending from subagent..."), - try_test(sa_v1_2_v2_trap1, [SA]), - try_test(sa_v1_2_v2_trap2, [SA]), - try_test(sa_v1_2_v2_trap3, [SA]), - - ?line unload_master("TestTrap"), - ?line unload_master("TestTrapv2"), - - ?line stop_subagent(SA). - -v3_trap(X) -> - v2_trap(X). - - -v3_inform(_X) -> - %% v2_inform(X). - {req, [], {conf, init_v3_inform, [v3_inform_i], finish_v3_inform}}. - -init_v2_inform(Config) when list(Config) -> - _Dir = ?config(agent_dir, Config), -% snmp_internal_mib:configure(Dir), - Config. - -init_v3_inform(X) -> - init_v2_inform(X). - -finish_v2_inform(Config) when list(Config) -> - _Dir = ?config(agent_dir, Config), -% snmp_internal_mib:configure(Dir), - Config. - -finish_v3_inform(X) -> - finish_v2_inform(X). - - - -v2_inform_i(suite) -> []; -v2_inform_i(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - p("Testing inform sending from master agent... NOTE! This test\ntakes a " - "few minutes (5) to complete."), - MA = whereis(snmp_master_agent), - - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(ma_v2_inform1, [MA]), - - ?line unload_master("TestTrap"), - ?line unload_master("TestTrapv2"). - -v3_inform_i(X) -> v2_inform_i(X). - - -sa_error(suite) -> []; -sa_error(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Testing sa bad value (is_set_ok)..."), - try_test(sa_errs_bad_value), - - p("Testing sa gen err (set)..."), - try_test(sa_errs_gen_err), - - p("Testing too big..."), - try_test(sa_too_big), - - ?line unload_master("OLD-SNMPEA-MIB"), - stop_subagent(SA). - -sa_error_2(X) -> sa_error(X). - -sa_error_3(X) -> sa_error(X). - - -next_across_sa(suite) -> []; -next_across_sa(Config) when list(Config) -> - {SaNode, _MgrNode, MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Loading another subagent mib..."), - ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas1"]), - - rpc:call(SaNode, snmp, register_subagent, [MA, ?klas1, SA]), - try_test(load_test_sa), - - p("Testing next across subagent (endOfMibView from SA)..."), - try_test(next_across_sa), - - p("Unloading mib"), - snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), - rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), - try_test(unreg_test), - - p("Starting another subagent"), - ?line {ok, SA2} = start_subagent(SaNode, ?klas1, "Klas1"), - p("Testing next across subagent (wrong prefix from SA)..."), - try_test(next_across_sa), - - stop_subagent(SA), - stop_subagent(SA2). - -next_across_sa_2(X) -> next_across_sa(X). - -next_across_sa_3(X) -> next_across_sa(X). - - -undo(suite) -> []; -undo(Config) when list(Config) -> - {SaNode, _MgrNode, MibDir} = init_case(Config), - MA = whereis(snmp_master_agent), - - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - - p("Testing undo phase at master agent..."), - ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas3"]), - ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas4"]), - try_test(undo_test), - try_test(api_test2), - ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas3"]), - - p("Testing bad return values from instrum. funcs..."), - try_test(bad_return), - - ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas4"]), - - p("Testing undo phase at subagent..."), - ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas3"]), - ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas4"]), - ?line ok = snmpa:register_subagent(MA, ?klas3, SA), - ?line ok = snmpa:register_subagent(MA, ?klas4, SA), - try_test(undo_test), - try_test(api_test3), - - p("Testing undo phase across master/subagents..."), - try_test(undo_test), - try_test(api_test3), - stop_subagent(SA). - -undo_2(X) -> undo(X). - -undo_3(X) -> undo(X). - -%% Req. Test2 -v1_processing(suite) -> []; -v1_processing(Config) when list(Config) -> - ?DBG("v1_processing -> entry", []), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - try_test(v1_proc), - ?line unload_master("Test2"). - -%% Req. Test2 -v2_processing(suite) -> []; -v2_processing(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - try_test(v2_proc), - ?line unload_master("Test2"). - -%% Req. Test2 -v3_processing(suite) -> []; -v3_processing(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("Test2"), - try_test(v2_proc), % same as v2! - ?line unload_master("Test2"). - - -%% We'll try get/set/trap and inform for all the auth & priv protocols. -%% For informs, the mgr is auth-engine. The agent has to sync. This is -%% accomplished by the first inform sent. That one will generate a -%% report, which makes it in sync. The notification-generating -%% application times out, and send again. This time it'll work. - -v3_crypto_basic(suite) -> []; -v3_crypto_basic(_Config) -> - EID = [0,0,0,0,0,0,0,0,0,0,0,2], - %% From rfc2274 appendix A.3.1 - ?line KMd5_1 = snmp:passwd2localized_key(md5, "maplesyrup", EID), - ?line [16#52,16#6f,16#5e,16#ed,16#9f,16#cc,16#e2,16#6f, - 16#89,16#64,16#c2,16#93,16#07,16#87,16#d8,16#2b] = - KMd5_1, - %% From rfc2274 appendix A.3.2 - ?line KSHA_1 = snmp:passwd2localized_key(sha, "maplesyrup", EID), - ?line [16#66,16#95,16#fe,16#bc,16#92,16#88,16#e3,16#62,16#82,16#23, - 16#5f,16#c7,16#15,16#1f,16#12,16#84,16#97,16#b3,16#8f,16#3f] = - KSHA_1, - %% From rfc2274, appendix A.5.1 - ?line KMd5_2 = snmp:passwd2localized_key(md5, "newsyrup", EID), - ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#88,16#05,16#61,16#51,16#41,16#67,16#6c,16#c9, - 16#19,16#61,16#74,16#e7,16#42,16#a3,16#25,16#51] = - snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2, 16, - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), - %% From rfc2274, appendix A.5.2 - ?line KSHA_2 = snmp:passwd2localized_key(sha, "newsyrup", EID), - ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#00,16#00,16#00,16#00,16#9c,16#10,16#17,16#f4, - 16#fd,16#48,16#3d,16#2d,16#e8,16#d5,16#fa,16#db, - 16#f8,16#43,16#92,16#cb,16#06,16#45,16#70,16#51] = - snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2, 20, - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), - KSHA_1t = lists:sublist(KSHA_1, 16), - KSHA_2t = lists:sublist(KSHA_2, 16), - ?line [16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#00,16#00,16#00,16#00,16#00,16#00,16#00,16#00, - 16#7e,16#f8,16#d8,16#a4,16#c9,16#cd,16#b2,16#6b, - 16#47,16#59,16#1c,16#d8,16#52,16#ff,16#88,16#b5] = - snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1t, KSHA_2t, 16, - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), - - %% Try with correct random - ?line Kc1 = snmp_user_based_sm_mib:mk_key_change(md5, KMd5_1, KMd5_2), - ?line KMd5_2 = snmp_user_based_sm_mib:extract_new_key(md5, KMd5_1, Kc1), - ?line Kc2 = snmp_user_based_sm_mib:mk_key_change(sha, KSHA_1, KSHA_2), - ?line KSHA_2 = snmp_user_based_sm_mib:extract_new_key(sha, KSHA_1, Kc2), - ok. - - - -v3_md5_auth(suite) -> []; -v3_md5_auth(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - p("Testing MD5 authentication...takes a few seconds..."), - - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_params_conf(AgentDir, "authMD5", authNoPriv), - ?line snmp_target_mib:reconfigure(AgentDir), - - MA = whereis(snmp_master_agent), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(v3_sync, [[{v2_proc, []}, - {ma_v2_trap1, [MA]}, - {v3_inform_sync, [MA]}]], - [{sec_level, authNoPriv}, {user, "authMD5"}]), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - ?line reset_target_params_conf(AgentDir). - -v3_sha_auth(suite) -> []; -v3_sha_auth(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - p("Testing SHA authentication...takes a few seconds..."), - - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_params_conf(AgentDir, "authSHA", authNoPriv), - ?line snmp_target_mib:reconfigure(AgentDir), - - MA = whereis(snmp_master_agent), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(v3_sync, [[{v2_proc, []}, - {ma_v2_trap1, [MA]}, - {v3_inform_sync, [MA]}]], - [{sec_level, authNoPriv}, {user, "authSHA"}]), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - ?line reset_target_params_conf(AgentDir). - -v3_des_priv(suite) -> []; -v3_des_priv(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - p("Testing DES encryption...takes a few seconds..."), - - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_params_conf(AgentDir, "privDES", authPriv), - ?line snmp_target_mib:reconfigure(AgentDir), - - MA = whereis(snmp_master_agent), - - ?line load_master("Test2"), - ?line load_master("TestTrap"), - ?line load_master("TestTrapv2"), - - try_test(v3_sync, [[{v2_proc, []}, - {ma_v2_trap1, [MA]}, - {v3_inform_sync, [MA]}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - ?line unload_master("TestTrapv2"), - ?line unload_master("TestTrap"), - ?line unload_master("Test2"), - ?line reset_target_params_conf(AgentDir). - -%% -define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). - -%% Make sure mgr is in sync with agent -v3_sync(Funcs) -> - ?DBG("v3_sync -> entry with Funcs: ~p",[Funcs]), - g([[sysDescr, 0]]), - expect(432, report, [{?usmStatsNotInTimeWindows_instance, any}]), - g([[sysDescr, 0]]), - expect(433, [{[sysDescr,0], any}]), - lists:foreach(fun({Func, Args}) -> apply(?MODULE, Func, Args) end, Funcs). - -v3_inform_sync(MA) -> - ?DBG("v3_sync -> entry with MA: ~p => Send notification",[MA]), - ?line snmpa:send_notification(MA, testTrapv22, no_receiver, - "standard inform", []), - %% Make sure agent is in sync with mgr... - ?DBG("v3_sync -> wait some time: ",[]), - sleep(20000), % more than 1500*10 in target_addr.conf - ?DBG("v3_sync -> await response",[]), - ?line expect(1, {inform, true}, - [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]). - - -v2_caps(suite) -> []; -v2_caps(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - try_test(v2_caps_i, [node()]). - -v2_caps_3(X) -> v2_caps(X). - - -v2_caps_i(Node) -> - ?line Idx = rpc:call(Node, snmp, add_agent_caps, [[1,2,3,4,5], "test cap"]), - g([[sysORID, Idx], [sysORDescr, Idx]]), - ?line expect(1, [{[sysORID, Idx], [1,2,3,4,5]}, - {[sysORDescr, Idx], "test cap"}]), - ?line rpc:call(Node, snmp, del_agent_caps, [Idx]), - g([[sysORID, Idx]]), - ?line expect(2, [{[sysORID, Idx], noSuchInstance}]). - - -%% Req. Test2 -v1_proc() -> - ?DBG("v1_proc -> entry", []), - %% According to RFC1157. - %% Template:
: - v1_get_p(), - v1_get_next_p(), - v1_set_p(). - - -v1_get_p() -> - %% 4.1.2:1 - g([[test2]]), - ?line expect(10, noSuchName, 1, [{[test2], 'NULL'}]), - g([[tDescr]]), - ?line expect(11, noSuchName, 1, [{[tDescr], 'NULL'}]), - g([[tDescr2,0]]), - ?line expect(12, noSuchName, 1, [{[tDescr2,0], 'NULL'}]), - g([[tDescr3,0]]), - ?line expect(131, noSuchName, 1, [{[tDescr3,0], 'NULL'}]), - g([[tDescr4,0]]), - ?line expect(132, noSuchName, 1, [{[tDescr4,0], 'NULL'}]), - g([[sysDescr, 0], [tDescr,0]]), % Outside mibview - ?line expect(14, noSuchName, 2, [{[sysDescr, 0], 'NULL'}, - {[tDescr,0], 'NULL'}]), - g([[sysDescr,3]]), - ?line expect(15, noSuchName, 1, [{[sysDescr, 3], 'NULL'}]), - - %% 4.1.2:2 - g([[tTable]]), - ?line expect(20, noSuchName, 1, [{[tTable], 'NULL'}]), - g([[tEntry]]), - ?line expect(21, noSuchName, 1, [{[tEntry], 'NULL'}]), - - %% 4.1.2:3 - g([[tTooBig, 0]]), - ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), - - %% 4.1.2:4 - g([[tGenErr1, 0]]), - ?line expect(40, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), - g([[tGenErr2, 0]]), - ?line expect(41, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), - g([[sysDescr, 0], [tGenErr3, 0]]), - ?line expect(42, genErr, 2, [{[sysDescr, 0], 'NULL'}, - {[tGenErr3, 0], 'NULL'}]). - - -v1_get_next_p() -> - %% 4.1.3:1 - gn([[1,3,7,1]]), - ?line expect(10, noSuchName, 1, [{[1,3,7,1], 'NULL'}]), - gn([[tDescr2]]), - ?line expect(11, tooBig, 0, any), - - %% 4.1.3:2 - gn([[tTooBig]]), - io:format("We currently don't handle tooBig correct!!!\n"), -% ?line expect(20, tooBig, 0, [{[tTooBig], 'NULL'}]), - ?line expect(20, tooBig, 0, any), - - %% 4.1.3:3 - gn([[tGenErr1]]), -% ?line expect(40, genErr, 1, [{[tGenErr1], 'NULL'}]), - ?line expect(40, genErr, 1, any), - gn([[tGenErr2]]), -% ?line expect(41, genErr, 1, [{[tGenErr2], 'NULL'}]), - ?line expect(41, genErr, 1, any), - gn([[sysDescr], [tGenErr3]]), -% ?line expect(42, genErr, 2, [{[sysDescr], 'NULL'}, -% {[tGenErr3], 'NULL'}]). - ?line expect(42, genErr, 2, any). - -v1_set_p() -> - %% 4.1.5:1 - s([{[1,3,7,0], i, 4}]), - ?line expect(10, noSuchName, 1, [{[1,3,7,0], 4}]), - s([{[tDescr,0], s, "outside mibview"}]), - ?line expect(11, noSuchName, 1, [{[tDescr,0], "outside mibview"}]), - s([{[tDescr3,0], s, "read-only"}]), - ?line expect(12, noSuchName, 1, [{[tDescr3,0], "read-only"}]), - s([{[tDescr3], s, "noSuchObject"}]), - ?line expect(13, noSuchName, 1, [{[tDescr3], "noSuchObject"}]), - s([{[tDescr3,1], s, "noSuchInstance"}]), - ?line expect(14, noSuchName, 1, [{[tDescr3,1], "noSuchInstance"}]), - s([{[tDescr2,0], s, "inconsistentName"}]), - ?line expect(15, noSuchName, 1, [{[tDescr2,0], "inconsistentName"}]), - - %% 4.1.5:2 - s([{[tDescr2, 0], i, 4}]), - ?line expect(20, badValue, 1, [{[tDescr2, 0], 4}]), - s([{[tDescr2, 0], s, "badValue"}]), - ?line expect(21, badValue, 1, [{[tDescr2, 0], "badValue"}]), - - %% 4.1.5:3 - %% The standard is quite incorrect here. The resp pdu was too big. In - %% the resp pdu, we have the original vbs. In the tooBig pdu we still - %% have to original vbs => the tooBig pdu is too big as well!!! It - %% may not get it to the manager, unless the agent uses 'NULL' instead - %% of the std-like original value. - s([{[tTooBig, 0], s, ?tooBigStr}]), - %% according to std: -% ?line expect(30, tooBig, 0, [{[tTooBig, 0], ?tooBigStr}]), - ?line expect(30, tooBig, 0, [{[tTooBig, 0], 'NULL'}]), - - %% 4.1.5:4 - s([{[tDescr2, 0], s, "is_set_ok_fail"}]), - ?line expect(40, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]), - s([{[tDescr2, 0], s, "commit_fail"}]), - ?line expect(41, genErr, 1, [{[tDescr2, 0], "commit_fail"}]). - -%% Req. Test2 -v2_proc() -> - %% According to RFC1905. - %% Template:
: - ?DBG("v2_proc -> entry",[]), - v2_get_p(), - v2_get_next_p(), - v2_get_bulk_p(), - v2_set_p(). - -v2_get_p() -> - %% 4.2.1:2 - ?DBG("v2_get_p -> entry",[]), - g([[test2]]), - ?line expect(10, [{[test2], noSuchObject}]), - g([[tDescr]]), - ?line expect(11, [{[tDescr], noSuchObject}]), - g([[tDescr4,0]]), - ?line expect(12, [{[tDescr4,0], noSuchObject}]), - g([[sysDescr, 0], [tDescr,0]]), % Outside mibview - ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}, - {[tDescr,0], noSuchObject}]), - g([[tTable]]), - ?line expect(14, [{[tTable], noSuchObject}]), - g([[tEntry]]), - ?line expect(15, [{[tEntry], noSuchObject}]), - - %% 4.2.1:3 - g([[tDescr2,0]]), %% instrum ret noSuchName!!! - ?line expect(20, [{[tDescr2,0], noSuchInstance}]), - g([[tDescr3,0]]), - ?line expect(21, [{[tDescr3,0], noSuchInstance}]), - g([[sysDescr,3]]), - ?line expect(22, [{[sysDescr, 3], noSuchInstance}]), - g([[tIndex,1]]), - ?line expect(23, [{[tIndex, 1], noSuchInstance}]), - - %% 4.2.1 - any other error: genErr - g([[tGenErr1, 0]]), - ?line expect(30, genErr, 1, [{[tGenErr1, 0], 'NULL'}]), - g([[tGenErr2, 0]]), - ?line expect(31, genErr, 1, [{[tGenErr2, 0], 'NULL'}]), - g([[sysDescr, 0], [tGenErr3, 0]]), - ?line expect(32, genErr, 2, [{[sysDescr, 0], 'NULL'}, - {[tGenErr3, 0], 'NULL'}]), - - %% 4.2.1 - tooBig - g([[tTooBig, 0]]), - ?line expect(40, tooBig, 0, []). - - -v2_get_next_p() -> - %% 4.2.2:2 - ?DBG("v2_get_next_p -> entry",[]), - gn([[1,3,7,1]]), - ?line expect(10, [{[1,3,7,1], endOfMibView}]), - gn([[sysDescr], [1,3,7,1]]), - ?line expect(11, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}]), - gn([[tCnt2, 1]]), - ?line expect(12, [{[tCnt2,2], 100}]), - gn([[tCnt2, 2]]), - ?line expect(12, [{[tCnt2,2], endOfMibView}]), - - %% 4.2.2 - any other error: genErr - gn([[tGenErr1]]), - ?line expect(20, genErr, 1, [{[tGenErr1], 'NULL'}]), - gn([[tGenErr2]]), - ?line expect(21, genErr, 1, [{[tGenErr2], 'NULL'}]), - gn([[sysDescr], [tGenErr3]]), - ?line expect(22, genErr, 2, [{[sysDescr], 'NULL'}, - {[tGenErr3], 'NULL'}]), - - %% 4.2.2 - tooBig - gn([[tTooBig]]), - ?line expect(20, tooBig, 0, []). - -v2_get_bulk_p() -> - %% 4.2.3 - ?DBG("v2_get_bulk_p -> entry",[]), - gb(1, 1, []), - ?line expect(10, []), - gb(-1, 1, []), - ?line expect(11, []), - gb(-1, -1, []), - ?line expect(12, []), - gb(-1, -1, []), - ?line expect(13, []), - gb(2, 0, [[sysDescr], [1,3,7,1]]), - ?line expect(14, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}]), - gb(1, 2, [[sysDescr], [1,3,7,1]]), - ?line expect(15, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}]), - gb(0, 2, [[sysDescr], [1,3,7,1]]), - ?line expect(16, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}, - {[sysObjectID, 0], [1,2,3]}, - {[1,3,7,1], endOfMibView}]), - - gb(2, 2, [[sysDescr], [1,3,7,1], [sysDescr], [1,3,7,1]]), - ?line expect(17, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}, - {[sysDescr, 0], "Erlang SNMP agent"}, - {[1,3,7,1], endOfMibView}, - {[sysObjectID, 0], [1,2,3]}, - {[1,3,7,1], endOfMibView}]), - - gb(1, 2, [[sysDescr], [sysDescr], [tTooBig]]), - ?line expect(18, [{[sysDescr, 0], "Erlang SNMP agent"}, - {[sysDescr, 0], "Erlang SNMP agent"}]), - - gb(1,12, [[tDescr2], [sysDescr]]), % next one after tDescr2 is tTooBig. - ?line expect(19, []), - - gb(2,2, [[sysDescr], [sysObjectID], [tGenErr1], [sysDescr]]), - ?line expect(20, genErr, 3, [{[sysDescr], 'NULL'}, - {[sysObjectID], 'NULL'}, - {[tGenErr1], 'NULL'}, - {[sysDescr], 'NULL'}]), - gb(0, 2, [[tCnt2, 1]]), - ?line expect(21, [{[tCnt2,2], 100}, - {[tCnt2,2], endOfMibView}]). - - -v2_set_p() -> - %% 4.2.5:1 - ?DBG("v2_set_p -> entry",[]), - s([{[1,3,7,0], i, 4}]), - ?line expect(10, noAccess, 1, [{[1,3,7,0], 4}]), - s([{[tDescr,0], s, "outside mibview"}]), - ?line expect(11, noAccess, 1, [{[tDescr,0], "outside mibview"}]), - - %% 4.2.5:2 - s([{[1,3,6,1,0], s, "noSuchObject"}]), - ?line expect(20, notWritable, 1, [{[1,3,6,1,0], "noSuchObject"}]), - - %% 4.2.5:3 - s([{[tDescr2, 0], i, 4}]), - ?line expect(30, wrongType, 1, [{[tDescr2, 0], 4}]), - s([{[tDescr2, 0], s, "badValue"}]), - ?line expect(31, badValue, 1, [{[tDescr2, 0], "badValue"}]), - - %% 4.2.5:4 - s([{[tStr, 0], s, ""}]), - ?line expect(40, wrongLength, 1, [{[tStr, 0], ""}]), - s([{[tStr, 0], s, "12345"}]), - ?line expect(40, wrongLength, 1, [{[tStr, 0], "12345"}]), - - %% 4.2.5:5 - N/A - - %% 4.2.5:6 - s([{[tInt1, 0], i, 0}]), - ?line expect(60, wrongValue, 1, [{[tInt1, 0], 0}]), - s([{[tInt1, 0], i, 5}]), - ?line expect(61, wrongValue, 1, [{[tInt1, 0], 5}]), - s([{[tInt2, 0], i, 0}]), - ?line expect(62, wrongValue, 1, [{[tInt2, 0], 0}]), - s([{[tInt2, 0], i, 5}]), - ?line expect(63, wrongValue, 1, [{[tInt2, 0], 5}]), - s([{[tInt3, 0], i, 5}]), - ?line expect(64, wrongValue, 1, [{[tInt3, 0], 5}]), - - %% 4.2.5:7 - s([{[tDescrX, 1, 1], s, "noCreation"}]), - ?line expect(70, noCreation, 1, [{[tDescrX, 1, 1], "noCreation"}]), - - %% 4.2.5:8 - s([{[tDescrX, 1, 2], s, "inconsistentName"}]), - ?line expect(80, inconsistentName, 1, - [{[tDescrX, 1, 2], "inconsistentName"}]), - - %% 4.2.5:9 - s([{[tCnt, 1, 2], i, 5}]), - ?line expect(90, notWritable, 1, [{[tCnt, 1, 2], 5}]), - s([{[tDescr3,0], s, "read-only"}]), - ?line expect(90, notWritable, 1, [{[tDescr3,0], "read-only"}]), - - %% 4.2.5:10 - s([{[tDescr2,0], s, "inconsistentValue"}]), - ?line expect(100, inconsistentValue, 1, - [{[tDescr2,0], "inconsistentValue"}]), - - %% 4.2.5:11 - s([{[tDescr2,0], s, "resourceUnavailable"}]), - ?line expect(110, resourceUnavailable, 1, - [{[tDescr2,0],"resourceUnavailable"}]), - - %% 4.2.5:12 - s([{[tDescr2, 0], s, "is_set_ok_fail"}]), - ?line expect(120, genErr, 1, [{[tDescr2, 0], "is_set_ok_fail"}]). - - %% commitFailed and undoFailed is tested by the 'undo' case. - - -%% Req. OLD-SNMPEA-MIB -table_test() -> - io:format("Testing simple get, next and set on communityTable...~n"), -%% {[147,214,36,45], "public", 2, readWrite}. -%% {[147,214,36,45], "standard trap", 2, read}. - Key1c3 = [intCommunityViewIndex,get(mip),is("public")], - Key2c3 = [intCommunityViewIndex,get(mip),is("standard trap")], - Key1c4 = [intCommunityAccess,get(mip),is("public")], - EndKey = [intCommunityEntry,[9],get(mip),is("public")], - gn([[intCommunityEntry]]), - ?line expect(7, [{Key1c3, 2}]), - gn([[intCommunityTable]]), - ?line expect(71, [{Key1c3, 2}]), - gn([[community]]), - ?line expect(72, [{Key1c3, 2}]), - gn([[otpSnmpeaMIB]]), - ?line expect(73, [{Key1c3, 2}]), - gn([[ericsson]]), - ?line expect(74, [{Key1c3, 2}]), - gn([Key1c3]), - ?line expect(8, [{Key2c3, 2}]), - gn([Key2c3]), - ?line expect(9, [{Key1c4, 2}]), - gn([EndKey]), - AgentIp = [intAgentIpAddress,0], - ?line expect(10, [{AgentIp, any}]), - g([Key1c3]), - ?line expect(11, [{Key1c3, 2}]), - g([EndKey]), - ?line ?v1_2(expect(12, noSuchName, 1, any), - expect(12, [{EndKey, noSuchObject}])), - - io:format("Testing row creation/deletion on communityTable...~n"), - NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], - NewKeyc4 = [intCommunityAccess,get(mip),is("test")], - NewKeyc5 = [intCommunityStatus,get(mip),is("test")], - s([{NewKeyc5, ?createAndGo}]), - ?line expect(14, ?v1_2(badValue, inconsistentValue), 1,any), - s([{NewKeyc5, ?createAndGo}, {NewKeyc3, 2}, {NewKeyc4, 2}]), - ?line expect(15, [{NewKeyc5, ?createAndGo},{NewKeyc3, 2}, {NewKeyc4, 2}]), - g([NewKeyc4]), - ?line expect(16, [{NewKeyc4, 2}]), - s([{NewKeyc5, ?destroy}]), - ?line expect(17, [{NewKeyc5, ?destroy}]), - s([{NewKeyc4, 2}]), - ?line expect(18, ?v1_2(noSuchName, inconsistentName), 1,[{NewKeyc4, 2}]), - s([{NewKeyc5, ?createAndWait}]), - ?line expect(19, [{NewKeyc5, ?createAndWait}]), - g([NewKeyc5]), - ?line expect(20, [{NewKeyc5, ?notReady}]), - s([{NewKeyc4, 2}]), - ?line expect(21, [{NewKeyc4, 2}]), - g([NewKeyc5]), - ?line expect(22, [{NewKeyc5, ?notReady}]), - s([{NewKeyc3, 2}]), - ?line expect(23, [{NewKeyc3, 2}]), - g([NewKeyc5]), - ?line expect(24, [{NewKeyc5, ?notInService}]), - s([{NewKeyc5, ?active}]), - ?line expect(25, [{NewKeyc5, ?active}]), - s([{NewKeyc5, ?destroy}]), - ?line expect(26, [{NewKeyc5, ?destroy}]), - s([{NewKeyc3, 3}]), - ?line expect(27, ?v1_2(noSuchName, inconsistentName), 1,[{NewKeyc3, 3}]), - otp_1128(). - -%% Req. system group -simple_standard_test() -> - ?DBG("simple_standard_test -> entry",[]), - gn([[1,1]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3]]), - ?line expect(11, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6]]), - ?line expect(12, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6,1]]), - ?line expect(13, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6,1,2]]), - ?line expect(14, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6,1,2,1]]), - ?line expect(15, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[1,3,6,1,2,1,1]]), - ?line expect(16, [{[sysDescr,0], "Erlang SNMP agent"}]), - gn([[sysDescr]]), - ?line expect(17, [{[sysDescr,0], "Erlang SNMP agent"}]), - g([[sysDescr,0]]), - ?line expect(2, [{[sysDescr,0], "Erlang SNMP agent"}]), - g([[sysDescr]]), - ?line ?v1_2(expect(3, noSuchName, 1, any), - expect(3, [{[sysDescr], noSuchObject}])), - g([[1,6,7,0]]), - ?line ?v1_2(expect(41, noSuchName, 1, any), - expect(3, [{[1,6,7,0], noSuchObject}])), - gn([[1,13]]), - ?line ?v1_2(expect(4, noSuchName,1, any), - expect(4, [{[1,13], endOfMibView}])), - s([{[sysLocation, 0], "new_value"}]), - ?line expect(5, [{[sysLocation, 0], "new_value"}]), - g([[sysLocation, 0]]), - ?line expect(6, [{[sysLocation, 0], "new_value"}]), - io:format("Testing noSuchName and badValue...~n"), - s([{[sysServices,0], 3}]), - ?line expect(61, ?v1_2(noSuchName, notWritable), 1, any), - s([{[sysLocation, 0], i, 3}]), - ?line expect(62, ?v1_2(badValue, wrongType), 1, any), - ?DBG("simple_standard_test -> done",[]), - ok. - -%% This is run in the agent node -db_notify_client(suite) -> []; -db_notify_client(Config) when list(Config) -> - {SaNode, MgrNode, MibDir} = init_case(Config), - ?DBG("~n\tSaNode: ~p~n\tMgrNode: ~p~n\tMibDir: ~p", - [SaNode,MgrNode,MibDir]), - snmpa_local_db:register_notify_client(self(),?MODULE), - - %% This call (the manager) will issue to set operations, so - %% we expect to receive to notify(insert) calls. - try_test(db_notify_client_test), - - ?DBG("await first notify",[]), - receive - {db_notify_test_reply,insert} -> ?DBG("first notify received",[]),ok - end, - - ?DBG("await second notify",[]), - receive - {db_notify_test_reply,insert} -> ?DBG("second notify received",[]),ok - end, - - snmpa_local_db:unregister_notify_client(self()). - - -%% This is run in the manager node -db_notify_client_test() -> - ?DBG("set first new sysLocation",[]), - s([{[sysLocation, 0], "new_value"}]), - ?line expect(5, [{[sysLocation, 0], "new_value"}]), - - ?DBG("set second new sysLocation",[]), - s([{[sysLocation, 0], "new_value"}]), - ?line expect(5, [{[sysLocation, 0], "new_value"}]). - -notify(Pid,What) -> - ?DBG("notify(~p,~p) -> called",[Pid,What]), - Pid ! {db_notify_test_reply,What}. - - -%% Req: system group, OLD-SNMPEA-MIB, Klas1 -big_test() -> - ?DBG("big_test -> testing simple next/get/set @ master agent...",[]), - simple_standard_test(), - - ?DBG("big_test -> testing simple next/get/set @ subagent...",[]), - gn([[klas1]]), - ?line expect(1, [{[fname,0], ""}]), - g([[fname,0]]), - ?line expect(2, [{[fname,0], ""}]), - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - g([[fname,0]]), - ?line expect(4, [{[fname,0], "test set"}]), - - ?DBG("big_test -> " - "testing next from last instance in master to subagent...",[]), - gn([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(5, [{[fname,0], "test set"}]), - gn([[1,1], - [?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, - {[fname,0], "test set"}]), - s([{[fname,0], s, ""}]), - ?line expect(52, [{[fname,0], ""}]), - - table_test(), - - ?DBG("big_test -> adding one row in subagent table",[]), - _FTab = [friendsEntry], - s([{[friendsEntry, [2, 3]], s, "kompis3"}, - {[friendsEntry, [3, 3]], i, ?createAndGo}]), - ?line expect(6, [{[friendsEntry, [2, 3]], "kompis3"}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - g([[friendsEntry, [2, 3]], - [friendsEntry, [3, 3]]]), - ?line expect(7, [{[friendsEntry, [2, 3]], "kompis3"}, - {[friendsEntry, [3, 3]], ?active}]), - s([{[friendsEntry, [3, 3]], i, ?destroy}]), - ?line expect(8, [{[friendsEntry, [3, 3]], ?destroy}]), - - otp_1131(), - - ?DBG("big_test -> adding two rows in subagent table with special INDEX", - []), - s([{[kompissEntry, [1, 3]], s, "kompis3"}, - {[kompissEntry, [2, 3]], i, ?createAndGo}]), - ?line expect(9, [{[kompissEntry, [1, 3]], "kompis3"}, - {[kompissEntry, [2, 3]], ?createAndGo}]), - g([[kompissEntry, [1, 3]], - [kompissEntry, [2, 3]]]), - ?line expect(10, [{[kompissEntry, [1, 3]], "kompis3"}, - {[kompissEntry, [2, 3]], ?active}]), - gn([[kompissEntry, [1]], - [kompissEntry, [2]]]), - ?line expect(11, [{[kompissEntry, [1, 3]], "kompis3"}, - {[kompissEntry, [2, 3]], ?active}]), - s([{[kompissEntry, [1, 2]], s, "kompis3"}, - {[kompissEntry, [2, 2]], i, ?createAndGo}]), - ?line expect(12, [{[kompissEntry, [1, 2]], "kompis3"}, - {[kompissEntry, [2, 2]], ?createAndGo}]), - gn([[kompissEntry, [1, 1]], - [kompissEntry, [2, 1]]]), - ?line expect(13, [{[kompissEntry, [1, 2]], "kompis3"}, - {[kompissEntry, [2, 2]], ?active}]), - s([{[kompissEntry, [2, 3]], i, ?destroy}]), - ?line expect(14, [{[kompissEntry, [2, 3]], ?destroy}]), - s([{[kompissEntry, [2, 2]], i, ?destroy}]), - ?line expect(15, [{[kompissEntry, [2, 2]], ?destroy}]), - ?DBG("big_test -> done",[]), - ok. - -%% Req. system group, Klas2, OLD-SNMPEA-MIB -big_test_2() -> - p("Testing simple next/get/set @ master agent (2)..."), - simple_standard_test(), - - p("Testing simple next/get/set @ subagent (2)..."), - gn([[klas2]]), - ?line expect(1, [{[fname2,0], ""}]), - g([[fname2,0]]), - ?line expect(2, [{[fname2,0], ""}]), - s([{[fname2,0], s, "test set"}]), - ?line expect(3, [{[fname2,0], "test set"}]), - g([[fname2,0]]), - ?line expect(4, [{[fname2,0], "test set"}]), - - otp_1298(), - - p("Testing next from last object in master to subagent (2)..."), - gn([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(5, [{[fname2,0], "test set"}]), - gn([[1,1], - [?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(51, [{[sysDescr,0], "Erlang SNMP agent"}, - {[fname2,0], "test set"}]), - - table_test(), - - p("Adding one row in subagent table (2)"), - _FTab = [friendsEntry2], - s([{[friendsEntry2, [2, 3]], s, "kompis3"}, - {[friendsEntry2, [3, 3]], i, ?createAndGo}]), - ?line expect(6, [{[friendsEntry2, [2, 3]], "kompis3"}, - {[friendsEntry2, [3, 3]], ?createAndGo}]), - g([[friendsEntry2, [2, 3]], - [friendsEntry2, [3, 3]]]), - ?line expect(7, [{[friendsEntry2, [2, 3]], "kompis3"}, - {[friendsEntry2, [3, 3]], ?active}]), - s([{[friendsEntry2, [3, 3]], i, ?destroy}]), - ?line expect(8, [{[friendsEntry2, [3, 3]], ?destroy}]), - - p("Adding two rows in subagent table with special INDEX (2)"), - s([{[kompissEntry2, [1, 3]], s, "kompis3"}, - {[kompissEntry2, [2, 3]], i, ?createAndGo}]), - ?line expect(9, [{[kompissEntry2, [1, 3]], "kompis3"}, - {[kompissEntry2, [2, 3]], ?createAndGo}]), - g([[kompissEntry2, [1, 3]], - [kompissEntry2, [2, 3]]]), - ?line expect(10, [{[kompissEntry2, [1, 3]], "kompis3"}, - {[kompissEntry2, [2, 3]], ?active}]), - gn([[kompissEntry2, [1]], - [kompissEntry2, [2]]]), - ?line expect(11, [{[kompissEntry2, [1, 3]], "kompis3"}, - {[kompissEntry2, [2, 3]], ?active}]), - s([{[kompissEntry2, [1, 2]], s, "kompis3"}, - {[kompissEntry2, [2, 2]], i, ?createAndGo}]), - ?line expect(12, [{[kompissEntry2, [1, 2]], "kompis3"}, - {[kompissEntry2, [2, 2]], ?createAndGo}]), - gn([[kompissEntry2, [1, 1]], - [kompissEntry2, [2, 1]]]), - ?line expect(13, [{[kompissEntry2, [1, 2]], "kompis3"}, - {[kompissEntry2, [2, 2]], ?active}]), - s([{[kompissEntry2, [2, 3]], i, ?destroy}]), - ?line expect(14, [{[kompissEntry2, [2, 3]], ?destroy}]), - s([{[kompissEntry2, [2, 2]], i, ?destroy}]), - ?line expect(15, [{[kompissEntry2, [2, 2]], ?destroy}]), - ok. - -%% Req. Test1 -multi_threaded_test() -> - p("Testing multi threaded agent..."), - g([[multiStr,0]]), - Pid = get_multi_pid(), - g([[sysUpTime,0]]), - ?line expect(1, [{[sysUpTime,0], any}]), - s([{[sysLocation, 0], s, "pelle"}]), - ?line expect(2, [{[sysLocation, 0], "pelle"}]), - Pid ! continue, - ?line expect(3, [{[multiStr,0], "ok"}]), - - s([{[multiStr, 0], s, "block"}]), - Pid2 = get_multi_pid(), - g([[sysUpTime,0]]), - ?line expect(4, [{[sysUpTime,0], any}]), - g([[multiStr,0]]), - Pid3 = get_multi_pid(), - g([[sysUpTime,0]]), - ?line expect(5, [{[sysUpTime,0], any}]), - s([{[sysLocation, 0], s, "kalle"}]), - Pid3 ! continue, - ?line expect(6, [{[multiStr,0], "ok"}]), - Pid2 ! continue, - ?line expect(7, [{[multiStr,0], "block"}]), - ?line expect(8, [{[sysLocation,0], "kalle"}]). - -%% Req. Test1, TestTrapv2 -mt_trap_test(MA) -> - snmpa:send_trap(MA, testTrapv22, "standard trap"), - ?line expect(1, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - - snmpa:send_trap(MA, mtTrap, "standard trap"), - Pid = get_multi_pid(), - g([[sysUpTime,0]]), - ?line expect(2, [{[sysUpTime,0], any}]), - snmpa:send_trap(MA, testTrapv22, "standard trap"), - ?line expect(3, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - Pid ! continue, - ?line expect(4, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?testTrap ++ [2]}, - {[multiStr,0], "ok"}]). - - -get_multi_pid() -> - get_multi_pid(10). -get_multi_pid(0) -> - ?line ?FAIL(no_global_name); -get_multi_pid(N) -> - sleep(1000), - case global:whereis_name(snmp_multi_tester) of - Pid when pid(Pid) -> Pid; - _ -> get_multi_pid(N-1) - end. - -%% Req. Test1 -types_v2_test() -> - p("Testing v2 types..."), - - s([{[bits1,0], 2#10}]), - ?line expect(1, [{[bits1,0], ?str(2#10)}]), - g([[bits1,0]]), - ?line expect(2, [{[bits1,0], ?str(2#101)}]), - - s([{[bits2,0], 2#11000000110}]), - ?line expect(3, [{[bits2,0], ?str(2#11000000110)}]), - g([[bits2,0]]), - ?line expect(4, [{[bits2,0], ?str(2#11000000110)}]), - - g([[bits3,0]]), - ?line expect(50, genErr, 1, any), - - g([[bits4,0]]), - ?line expect(51, genErr, 1, any), - - s([{[bits1,0], s, [2#10]}]), - ?line expect(6, ?v1_2(badValue, wrongValue), 1, any), - - s([{[bits2,0], 2#11001001101010011}]), - ?line expect(7, ?v1_2(badValue, wrongValue), 1, any). - - -%% Req. Test1 -implied_test(MA) -> - ?LOG("implied_test -> start",[]), - p("Testing IMPLIED..."), - - snmpa:verbosity(MA,trace), - snmpa:verbosity(MA,trace), - - %% Create two rows, check that they are get-nexted in correct order. - Idx1 = "apa", - Idx2 = "qq", - ?DBG("implied_test -> (send) create row 1 '~s' in table 1",[Idx1]), - s([{[testStatus, Idx1], i, ?createAndGo}, {[testDescr, Idx1],s,"row 1"}]), - ?line expect(1, [{[testStatus, Idx1], ?createAndGo}, - {[testDescr, Idx1], "row 1"}]), - ?DBG("implied_test -> (send) create row 2 '~s' in table 1",[Idx2]), - s([{[testStatus, Idx2], i, ?createAndGo}, {[testDescr, Idx2],s,"row 2"}]), - ?line expect(2, [{[testStatus, Idx2], ?createAndGo}, - {[testDescr, Idx2], "row 2"}]), - ?DBG("implied_test -> get-next(testDescr)",[]), - gn([[testDescr]]), - ?line expect(3, [{[testDescr,Idx1], "row 1"}]), - ?DBG("implied_test -> get-next(testDescr) of row 1",[]), - gn([[testDescr,Idx1]]), - ?line expect(4, [{[testDescr,Idx2], "row 2"}]), - - % Delete the rows - ?DBG("implied_test -> (send) delete row 1 '~s' from table 1",[Idx1]), - s([{[testStatus, Idx1], i, ?destroy}]), - ?line expect(5, [{[testStatus, Idx1], ?destroy}]), - ?DBG("implied_test -> (send) delete row 2 '~s' from table 1",[Idx2]), - s([{[testStatus, Idx2], i, ?destroy}]), - ?line expect(6, [{[testStatus, Idx2], ?destroy}]), - - %% Try the same in other table - Idx3 = [1, "apa"], - Idx4 = [1, "qq"], - ?DBG("implied_test -> (send) create row 1 '~s' in table 2",[Idx3]), - s([{[testStatus2, Idx3], i, ?createAndGo}, {[testDescr2,Idx3],s,"row 1"}]), - ?line expect(1, [{[testStatus2, Idx3], ?createAndGo}, - {[testDescr2, Idx3], "row 1"}]), - ?DBG("implied_test -> (send) create row 2 '~s' in table 2",[Idx4]), - s([{[testStatus2, Idx4], i, ?createAndGo}, {[testDescr2,Idx4],s,"row 2"}]), - ?line expect(2, [{[testStatus2, Idx4], ?createAndGo}, - {[testDescr2, Idx4], "row 2"}]), - ?DBG("implied_test -> get-next(testDescr2)",[]), - gn([[testDescr2]]), - ?line expect(3, [{[testDescr2,Idx3], "row 1"}]), - ?DBG("implied_test -> get-next(testDescr2) of row 1",[]), - gn([[testDescr2,Idx3]]), - ?line expect(4, [{[testDescr2,Idx4], "row 2"}]), - - % Delete the rows - ?DBG("implied_test -> (send) delete row 1 '~s' from table 2",[Idx3]), - s([{[testStatus2, Idx3], i, ?destroy}]), - ?line expect(5, [{[testStatus2, Idx3], ?destroy}]), - ?DBG("implied_test -> (send) delete row 2 '~s' from table 2",[Idx4]), - s([{[testStatus2, Idx4], i, ?destroy}]), - ?line expect(6, [{[testStatus2, Idx4], ?destroy}]), - - snmpa:verbosity(MA,log), - - ?LOG("implied_test -> done",[]). - - - -%% Req. Test1 -sparse_table_test() -> - p("Testing sparse table..."), - - %% Create two rows, check that they are get-nexted in correct order. - Idx1 = 1, - Idx2 = 2, - s([{[sparseStatus, Idx1], i, ?createAndGo}, - {[sparseDescr, Idx1], s, "row 1"}]), - ?line expect(1, [{[sparseStatus, Idx1], ?createAndGo}, - {[sparseDescr, Idx1], "row 1"}]), - s([{[sparseStatus, Idx2], i, ?createAndGo}, - {[sparseDescr, Idx2], s, "row 2"}]), - ?line expect(2, [{[sparseStatus, Idx2], ?createAndGo}, - {[sparseDescr, Idx2], "row 2"}]), - ?v1_2(gn([[sparseIndex], [sparseDescr,Idx1], [sparseDescr,Idx2], - [sparseStatus,Idx1], [sparseStatus,Idx2]]), - gb(0,5,[[sparseIndex]])), - ?line expect(3, [{[sparseDescr,Idx1], "row 1"}, - {[sparseDescr,Idx2], "row 2"}, - {[sparseStatus,Idx1], ?active}, - {[sparseStatus,Idx2], ?active}, - {[sparseStr,0], "slut"}]), - % Delete the rows - s([{[sparseStatus, Idx1], i, ?destroy}]), - ?line expect(4, [{[sparseStatus, Idx1], ?destroy}]), - s([{[sparseStatus, Idx2], i, ?destroy}]), - ?line expect(5, [{[sparseStatus, Idx2], ?destroy}]). - - -%% Req. Test1 -cnt_64_test(MA) -> - ?LOG("start cnt64 test (~p)",[MA]), - snmpa:verbosity(MA,trace), - ?LOG("start cnt64 test",[]), - p("Testing Counter64, and at the same time, RowStatus is not last column"), - - ?DBG("get cnt64",[]), - g([[cnt64,0]]), - ?DBG("await response",[]), - ?line ?v1_2(expect(1, noSuchName, 1, any), - expect(1, [{[cnt64,0],18446744073709551615}])), - ?DBG("get-next cnt64",[]), - gn([[cnt64]]), - ?DBG("await response",[]), - ?line ?v1_2(expect(2, [{[cnt64Str,0], "after cnt64"}]), - expect(2, [{[cnt64,0],18446744073709551615}])), - ?DBG("send cntTrap",[]), - snmpa:send_trap(MA,cntTrap,"standard trap",[{sysContact,"pelle"}, - {cnt64, 10}, - {sysLocation, "here"}]), - ?DBG("await response",[]), - ?line ?v1_2(expect(3, trap, [test], 6, 1, [{[sysContact,0], "pelle"}, - {[sysLocation,0], "here"}]), - expect(3, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?testTrap ++ [1]}, - {[sysContact,0], "pelle"}, - {[cnt64,0], 10}, - {[sysLocation,0], "here"}])), - - %% Create two rows, check that they are get-nexted in correct order. - Idx1 = 1, - Idx2 = 2, - ?DBG("create row (cntStatus): ~p",[Idx1]), - s([{[cntStatus, Idx1], i, ?createAndGo}]), - ?DBG("await response",[]), - ?line expect(1, [{[cntStatus, Idx1], ?createAndGo}]), - ?DBG("create row (cntStatus): ~p",[Idx2]), - s([{[cntStatus, Idx2], i, ?createAndGo}]), - ?DBG("await response",[]), - ?line expect(2, [{[cntStatus, Idx2], ?createAndGo}]), - - ?DBG("get-next (cntIndex)",[]), - gn([[cntIndex]]), - ?DBG("await response",[]), - ?line ?v1_2(expect(3, [{[cntStatus,Idx1], ?active}]), - expect(3, [{[cntCnt,Idx1], 0}])), - % Delete the rows - ?DBG("delete row (cntStatus): ~p",[Idx1]), - s([{[cntStatus, Idx1], i, ?destroy}]), - ?DBG("await response",[]), - ?line expect(4, [{[cntStatus, Idx1], ?destroy}]), - ?DBG("delete row (cntStatus): ~p",[Idx2]), - s([{[cntStatus, Idx2], i, ?destroy}]), - ?DBG("await response",[]), - ?line expect(5, [{[cntStatus, Idx2], ?destroy}]), - catch snmpa:verbosity(MA,log), - ?DBG("done",[]), - ok. - -%% Req. Test1 -opaque_test() -> - p("Testing Opaque datatype..."), - g([[opaqueObj,0]]), - ?line expect(1, [{[opaqueObj,0], "opaque-data"}]). - -%% Req. OLD-SNMPEA-MIB -api_test(MaNode) -> - ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, - [intAgentIpAddress]), - ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, - oid_to_name, [OID]), - ?line false = rpc:call(MaNode, snmp, name_to_oid, [intAgentIpAddres]), - ?line false = rpc:call(MaNode, snmp, oid_to_name, - [[1,5,32,3,54,3,3,34,4]]), - ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, - [intViewType, excluded]), - ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, - [intViewType, 2]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, [intViewType, exclude]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [intAgentIpAddress, exclude]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [intAgentIpAddre, exclude]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [intViewType, 3]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddress, 2]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [intAgentIpAddre, 2]), - ?line {value, active} = rpc:call(MaNode, snmp, - int_to_enum, ['RowStatus', ?active]), - ?line {value, ?destroy} = rpc:call(MaNode, snmp, - enum_to_int, ['RowStatus', destroy]), - ?line false = rpc:call(MaNode, snmp, - enum_to_int, ['RowStatus', xxxdestroy]), - ?line false = rpc:call(MaNode, snmp, - enum_to_int, ['xxRowStatus', destroy]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, ['RowStatus', 25]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, ['xxRowStatus', 1]), - ?line case snmp:date_and_time() of - List when list(List), length(List) == 8 -> ok; - List when list(List), length(List) == 11 -> ok - end. - -%% Req. Klas3 -api_test2() -> - g([[fname3,0]]), - ?line expect(1, [{[fname3,0], "ok"}]), - g([[fname4,0]]), - ?line expect(2, [{[fname4,0], 1}]). - -api_test3() -> - g([[fname3,0]]), - ?line expect(1, [{[fname3,0], "ok"}]). - - -unreg_test() -> - gn([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(1, [{[snmpInPkts, 0], any}]). - -load_test() -> - gn([[?v1_2(sysServices, sysORLastChange),0]]), - ?line expect(1, [{[fname,0], ""}]). - -%% Req. Klas1 -load_test_sa() -> - gn([[?v1_2(sysServices,sysORLastChange), 0]]), - ?line expect(1, [{[fname,0], any}]). - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_get() -> - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - g([[sysDescr,0], Key1c4, [fname,0],Key1c3, - [sysName,0]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[fname,0], "test set"}, - {Key1c3, 2}, - {[sysName,0], "test"}]), - g([[1,3,7,1], Key1c4, [sysDescr,0], [1,3,7,2], Key1c3, [sysDescr,0]]), - ?line ?v1_2(expect(2, noSuchName, [1,4], any), - expect(2, [{[1,3,7,1], noSuchObject}, - {Key1c4, 2}, - {[sysDescr,0], "Erlang SNMP agent"}, - {[1,3,7,2], noSuchObject}, - {Key1c3, 2}, - {[sysDescr,0], "Erlang SNMP agent"}])). - -%% Req. v1, system group, Klas1, OLD-SNMPEA-MIB, *ej* Klas3. -do_mul_get_err() -> - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - g([[sysDescr,0],Key1c4,[fname,0], Key1c3, [sysName,2]]), - ?line ?v1_2(expect(1, noSuchName, 5, any), - expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[fname,0], "test set"}, - {Key1c3, 2}, - {[sysName,2], noSuchInstance}])), - g([[sysDescr,0],Key1c4,[fname3,0], Key1c3, [sysName,1]]), - ?line ?v1_2(expect(1, noSuchName, [3,5], any), - expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[fname3,0], noSuchObject}, - {Key1c3, 2}, - {[sysName,1], noSuchInstance}])). - - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_next() -> - Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], - Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - gn([[sysDescr], Key1c4s, [fname],Key1c3s,[sysName]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, {[fname,0], "test set"}, - {Key1c3, 2}, {[sysName,0], "test"}]). - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_next_err() -> - Key1c3s = [intCommunityEntry,[3],get(mip),is("publi")], - Key1c4s = [intCommunityEntry,[4],get(mip),is("publi")], - Key1c3 = [intCommunityEntry,[3],get(mip),is("public")], - Key1c4 = [intCommunityEntry,[4],get(mip),is("public")], - s([{[fname,0], s, "test set"}]), - ?line expect(3, [{[fname,0], "test set"}]), - gn([[sysDescr], Key1c4s, [1,3,6,999], [fname],[1,3,90], Key1c3s,[sysName]]), - ?line ?v1_2(expect(1, noSuchName, [3,5], any), - expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {Key1c4, 2}, - {[1,3,6,999], endOfMibView}, - {[fname,0], "test set"}, - {[1,3,90], endOfMibView}, - {Key1c3, 2}, - {[sysName,0], "test"}])). - - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_set() -> - p("Adding one row in subagent table, and one in master table"), - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - s([{[friendsEntry, [2, 3]], "kompis3"}, - {NewKeyc3, 2}, - {[sysLocation,0], "new_value"}, - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - ?line expect(1, [{[friendsEntry, [2, 3]], "kompis3"}, - {NewKeyc3, 2}, - {[sysLocation,0], "new_value"}, - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - g([[friendsEntry, [2, 3]], - [sysLocation,0], - [friendsEntry, [3, 3]]]), - ?line expect(2, [{[friendsEntry, [2, 3]], "kompis3"}, - {[sysLocation,0], "new_value"}, - {[friendsEntry, [3, 3]], ?active}]), - g([NewKeyc4]), - ?line expect(3, [{NewKeyc4, 2}]), - s([{[friendsEntry, [3, 3]], ?destroy}, - {NewKeyc5, ?destroy}]), - ?line expect(4, [{[friendsEntry, [3, 3]], ?destroy}, - {NewKeyc5, ?destroy}]). - -%% Req. system group, Klas1, OLD-SNMPEA-MIB -do_mul_set_err() -> - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - p("Adding one row in subagent table, and one in master table"), - s([{[friendsEntry, [2, 3]], s, "kompis3"}, - {NewKeyc3, 2}, - {[sysUpTime,0], 45}, % sysUpTime (readOnly) - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}, - {[friendsEntry, [3, 3]], ?createAndGo}]), - ?line expect(1, ?v1_2(noSuchName, notWritable), 3, any), - g([[friendsEntry, [2, 3]]]), - ?line ?v1_2(expect(2, noSuchName, 1, any), - expect(2, [{[friendsEntry, [2,3]], noSuchInstance}])), - g([NewKeyc4]), - ?line ?v1_2(expect(3, noSuchName, 1, any), - expect(3, [{NewKeyc4, noSuchInstance}])). - -%% Req. SA-MIB -sa_mib() -> - g([[sa, [2,0]]]), - ?line expect(1, [{[sa, [2,0]], 3}]), - s([{[sa, [1,0]], s, "sa_test"}]), - ?line expect(2, [{[sa, [1,0]], "sa_test"}]). - -ma_trap1(MA) -> - snmpa:send_trap(MA, testTrap2, "standard trap"), - ?line expect(1, trap, [system], 6, 1, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}]), - snmpa:send_trap(MA, testTrap1, "standard trap"), - ?line expect(2, trap, [1,2,3] , 1, 0, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}]). - -ma_trap2(MA) -> - snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). - -ma_v2_2_v1_trap(MA) -> - snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, trap, [system], 6, 1, [{[system, [4,0]], "pelle"}]). - -ma_v2_2_v1_trap2(MA) -> - snmpa:send_trap(MA,linkUp,"standard trap",[{ifIndex, [1], 1}, - {ifAdminStatus, [1], 1}, - {ifOperStatus, [1], 2}]), - ?line expect(3, trap, [1,2,3], 3, 0, [{[ifIndex, 1], 1}, - {[ifAdminStatus, 1], 1}, - {[ifOperStatus, 1], 2}]). - -sa_trap1(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap"), - ?line expect(4, trap, [ericsson], 6, 1, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}]). - -sa_trap2(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), - ?line expect(5, trap, [ericsson], 6, 1, [{[system, [4,0]], - "pelle"}, - {[sa, [1,0]], "sa_test"}]). - -sa_trap3(SA) -> - snmpa:send_trap(SA, saTrap2, "standard trap", - [{intViewSubtree, [4], [1,2,3,4]}]), - ?line expect(6, trap, [ericsson], 6, 2, [{[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}, - {[intViewSubtree,4],[1,2,3,4]}]). - -ma_v2_trap1(MA) -> - ?DBG("ma_v2_traps -> entry with MA = ~p => " - "send standard trap: testTrapv22",[MA]), - snmpa:send_trap(MA, testTrapv22, "standard trap"), - ?line expect(1, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - ?DBG("ma_v2_traps -> send standard trap: testTrapv21",[]), - snmpa:send_trap(MA, testTrapv21, "standard trap"), - ?line expect(2, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?snmp ++ [1]}]). - -ma_v2_trap2(MA) -> - snmpa:send_trap(MA,testTrapv22,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}, - {[system, [4,0]], "pelle"}]). - -%% Note: This test case takes a while... actually a couple of minutes. -ma_v2_inform1(MA) -> - ?DBG("ma_v2_inform -> entry with MA = ~p => " - "send notification: testTrapv22",[MA]), - ?line snmpa:send_notification(MA, testTrapv22, no_receiver, "standard inform", []), - ?line expect(1, {inform, true}, - [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - - ?DBG("ma_v2_inform -> send notification: testTrapv22",[]), - snmpa:send_notification(MA, testTrapv22, {tag1, self()}, - "standard inform", []), - ?line expect(1, {inform, true}, - [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - ?DBG("ma_v2_inform -> await targets",[]), - receive - {snmp_targets, tag1, [_]} -> - ok; - {snmp_targets, tag1, Addrs1} -> - ?line ?FAIL({bad_addrs, Addrs1}) - after - 5000 -> - ?ERR("ma_v2_inform1 -> awaiting snmp_targets(tag1) timeout",[]), - ?line ?FAIL(nothing_at_all) - end, - ?DBG("ma_v2_inform -> await notification",[]), - receive - {snmp_notification, tag1, {got_response, _}} -> - ok; - {snmp_notification, tag1, {no_response, _}} -> - ?line ?FAIL(no_response) - after - 20000 -> - ?ERR("ma_v2_inform1 -> " - "awaiting snmp_notification(tag1) timeout",[]), - ?line ?FAIL(nothing_at_all) - end, - - %% - %% -- The rest is possibly erroneous... - %% - - ?DBG("ma_v2_inform -> send notification: testTrapv22",[]), - snmpa:send_notification(MA, testTrapv22, {tag2, self()}, - "standard inform", []), - ?line expect(2, {inform, false}, - [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}]), - ?DBG("ma_v2_inform -> await targets",[]), - receive - {snmp_targets, tag2, [_]} -> - ok; - {snmp_targets, tag2, Addrs2} -> - ?ERR("ma_v2_inform1 -> awaiting snmp_targets(tag2) timeout",[]), - ?line ?FAIL({bad_addrs, Addrs2}) - after - 5000 -> - ?line ?FAIL(nothing_at_all) - end, - ?DBG("ma_v2_inform -> await notification",[]), - receive - {snmp_notification, tag2, {got_response, _}} -> - ?line ?FAIL(got_response); - {snmp_notification, tag2, {no_response, _}} -> - ok - after - 240000 -> - ?ERR("ma_v2_inform1 -> " - "awaiting snmp_notification(tag2) timeout",[]), - ?line ?FAIL(nothing_at_all) - end. - - -ma_v1_2_v2_trap(MA) -> - snmpa:send_trap(MA,linkDown,"standard trap",[{ifIndex, [1], 1}]), - ?line expect(2, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?snmpTraps ++ [3]}, - {[ifIndex, 1], 1}, - {[snmpTrapEnterprise, 0], [1,2,3]}]). - - -ma_v1_2_v2_trap2(MA) -> - snmpa:send_trap(MA,testTrap2,"standard trap",[{sysContact,"pelle"}]), - ?line expect(3, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?system ++ [0,1]}, - {[system, [4,0]], "pelle"}, - {[snmpTrapEnterprise, 0], ?system}]). - - -sa_v1_2_v2_trap1(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap"), - ?line expect(4, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, - {[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}, - {[snmpTrapEnterprise, 0], ?ericsson}]). - -sa_v1_2_v2_trap2(SA) -> - snmpa:send_trap(SA, saTrap, "standard trap",[{sysContact,"pelle"}]), - ?line expect(4, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?ericsson ++ [0, 1]}, - {[system, [4,0]], "pelle"}, - {[sa, [1,0]], "sa_test"}, - {[snmpTrapEnterprise, 0], ?ericsson}]). - - -sa_v1_2_v2_trap3(SA) -> - snmpa:send_trap(SA, saTrap2, "standard trap", - [{intViewSubtree, [4], [1,2,3,4]}]), - ?line expect(4, v2trap, [{[sysUpTime, 0], any}, - {[snmpTrapOID, 0], ?ericsson ++ [0, 2]}, - {[system, [4,0]], - "{mbj,eklas}@erlang.ericsson.se"}, - {[sa, [1,0]], "sa_test"}, - {[intViewSubtree,4],[1,2,3,4]}, - {[snmpTrapEnterprise, 0], ?ericsson}]). - - -%% Req. SA-MIB, OLD-SNMPEA-MIB -sa_errs_bad_value() -> - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - s([{NewKeyc3, 2}, - {[sa, [2,0]], 5}, % badValue (i is_set_ok) - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}]), - ?line expect(1, badValue, 2, any), - s([{NewKeyc3, 2}, - {[sa, [2,0]], 6}, % wrongValue (i is_set_ok) - {NewKeyc5, ?createAndGo}, - {NewKeyc4, 2}]), - ?line expect(1, ?v1_2(badValue, wrongValue), 2, any), - g([NewKeyc4]), - ?line ?v1_2(expect(2, noSuchName, 1, any), - expect(2, [{NewKeyc4, noSuchInstance}])). - -%% Req. SA-MIB, OLD-SNMPEA-MIB -sa_errs_gen_err() -> - NewKeyc3 = [intCommunityEntry,[3],get(mip),is("test")], - NewKeyc4 = [intCommunityEntry,[4],get(mip),is("test")], - NewKeyc5 = [intCommunityEntry,[5],get(mip),is("test")], - s([{NewKeyc3, 2},{NewKeyc4, 2}, - {NewKeyc5, ?createAndGo}, {[sa, [3,0]], 5}]), - ?line expect(1, genErr, 4, any), -% The row might have been added; we don't know. -% (as a matter of fact we do - it is added, because the agent -% first sets its own vars, and then th SAs. Lets destroy it. - s([{NewKeyc5, ?destroy}]), - ?line expect(2, [{NewKeyc5, ?destroy}]). - -%% Req. SA-MIB, OLD-SNMPEA-MIB -sa_too_big() -> - g([[sa, [4,0]]]), - ?line expect(1, tooBig). - -%% Req. Klas1, system group, snmp group (v1/v2) -next_across_sa() -> - gn([[sysDescr],[klas1,5]]), - ?line expect(1, [{[sysDescr,0], "Erlang SNMP agent"}, - {[snmpInPkts, 0], any}]). - -%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]). -> noError -%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]). -> {badValue, 2} -%% snmp_test_mgr:s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]). -> {genErr, 1} -%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]). -> {genErr, 1} -%% snmp_test_mgr:s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]). -> {genErr, 1} -%% snmp_test_mgr:s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]). -> {genErr, 2} -%% Req. Klas3, Klas4 -undo_test() -> - s([{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), - ?line expect(1, [{[fStatus3, 1], 4}, {[fname3,0], "ok"}]), - s([{[fStatus3, 1], 4}, {[fname3,0], "hoj"}]), - ?line expect(2, ?v1_2(badValue, inconsistentValue), 2, any), - s([{[fStatus3, 3], 4}, {[fname3,0], "hoj"}]), - ?line expect(3, ?v1_2(genErr, undoFailed), 1, any), - s([{[fStatus3, 4], 4}, {[fname3,0], "ok"}]), - ?line expect(4, ?v1_2(genErr, commitFailed), 1, any), -% unfortunatly we don't know if we'll get undoFailed or commitFailed. -% it depends on which order the agent traverses the varbind list. -% s([{[fStatus3, 4], 4}, {[fname3,0], "ufail"}]), -% ?line expect(5, ?v1_2(genErr, undoFailed), 1, any), - s([{[fStatus3, 1], 4}, {[fname3,0], "xfail"}]), - ?line expect(6, genErr, 2, any). - -%% Req. Klas3, Klas4 -bad_return() -> - g([[fStatus4,4], - [fName4,4]]), - ?line expect(4, genErr, 2, any), - g([[fStatus4,5], - [fName4,5]]), - ?line expect(5, genErr, 1, any), - g([[fStatus4,6], - [fName4,6]]), - ?line expect(6, genErr, 2, any), - gn([[fStatus4,7], - [fName4,7]]), - ?line expect(7, genErr, 2, any), - gn([[fStatus4,8], - [fName4,8]]), - ?line expect(8, genErr, 1, any), - gn([[fStatus4,9], - [fName4,9]]), - ?line expect(9, genErr, 2, any). - - -%%%----------------------------------------------------------------- -%%% Test the implementation of standard mibs. -%%% We should *at least* try to GET all variables, just to make -%%% sure the instrumentation functions work. -%%% Note that many of the functions in the standard mib is -%%% already tested by the normal tests. -%%%----------------------------------------------------------------- - - - -%%----------------------------------------------------------------- -%% For this test, the agent is configured for v1. -%% o Test the counters and control objects in SNMP-STANDARD-MIB -%%----------------------------------------------------------------- -snmp_standard_mib(suite) -> []; -snmp_standard_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?DBG("snmp_standard_mib -> std_mib_init", []), - try_test(std_mib_init), - - ?DBG("snmp_standard_mib -> std_mib_a", []), - InBadVsns = try_test(std_mib_a), - put(vsn, v2), - ?DBG("snmp_standard_mib -> std_mib_read", []), - try_test(std_mib_read), - put(vsn, v1), - - ?DBG("snmp_standard_mib -> std_mib_b (~w)", [InBadVsns]), - Bad = try_test(std_mib_b, [InBadVsns]), - ?DBG("snmp_standard_mib -> std_mib_read (community: 'bad community')", []), - try_test(std_mib_read, [], [{community, "bad community"}]), - ?DBG("snmp_standard_mib -> std_mib_write (community: 'public')", []), - try_test(std_mib_write, [], [{community, "public"}]), - ?DBG("snmp_standard_mib -> std_mib_asn_err", []), - try_test(std_mib_asn_err), - ?DBG("snmp_standard_mib -> std_mib_c (~w)", [Bad]), - try_test(std_mib_c, [Bad]), - ?DBG("snmp_standard_mib -> std_mib_a", []), - try_test(standard_mib_a), - - ?DBG("snmp_standard_mib -> std_mib_finish", []), - try_test(std_mib_finish), - ?DBG("snmp_standard_mib -> std_mib_test_finish", []), - try_test(standard_mib_test_finish, [], [{community, "bad community"}]). - -%% Req. SNMP-STANDARD-MIB -standard_mib_a() -> - ?line [OutPkts] = get_req(2, [[snmpOutPkts,0]]), - ?line [OutPkts2] = get_req(3, [[snmpOutPkts,0]]), - ?line OutPkts2 = OutPkts + 1, - %% There are some more counters we could test here, but it's not that - %% important, since they are removed from SNMPv2-MIB. - ok. - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_init() -> - %% disable authentication failure traps. (otherwise w'd get many of - %% them - this is also a test to see that it works). - s([{[snmpEnableAuthenTraps,0], 2}]), - ?line expect(1, [{[snmpEnableAuthenTraps, 0], 2}]). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_finish() -> - %% enable again - s([{[snmpEnableAuthenTraps,0], 1}]), - ?line expect(1, [{[snmpEnableAuthenTraps, 0], 1}]). - -%% Req. SNMP-STANDARD-MIB -standard_mib_test_finish() -> - %% force a authenticationFailure - std_mib_write(), - %% check that we got a trap - ?line expect(2, trap, [1,2,3], 4, 0, []). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_read() -> - ?DBG("std_mib_read -> entry", []), - g([[sysUpTime,0]]), % try a bad ; msg dropped, no reply - ?DBG("std_mib_read -> await timeout (i.e. no reply)", []), - ?line expect(1, timeout). % make sure we don't get a trap! - - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_write() -> - ?DBG("std_mib_write -> entry", []), - s([{[sysLocation, 0], "new_value"}]). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_asn_err() -> - snmp_test_mgr:send_bytes([48,99,67,12,0,0,0,0,0,0,5]). - -%%----------------------------------------------------------------- -%% For this test, the agent is configured for v2 and v3. -%% o Test the counters and control objects in SNMPv2-MIB -%%----------------------------------------------------------------- -snmpv2_mib_2(suite) -> []; -snmpv2_mib_2(Config) when list(Config) -> - ?LOG("snmpv2_mib_2 -> start",[]), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?DBG("snmpv2_mib_2 -> standard mib init",[]), - try_test(std_mib_init), - - ?DBG("snmpv2_mib_2 -> get number of (so far) bad versions",[]), - InBadVsns = try_test(std_mib_a), - - ?DBG("snmpv2_mib_2 -> make a bad version read",[]), - put(vsn, v1), - try_test(std_mib_read), - - ?DBG("snmpv2_mib_2 -> bad version read",[]), - put(vsn, v2), - Bad = try_test(std_mib_b, [InBadVsns]), - - ?DBG("snmpv2_mib_2 -> read with bad community",[]), - try_test(std_mib_read, [], [{community, "bad community"}]), - - ?DBG("snmpv2_mib_2 -> write with public community",[]), - try_test(std_mib_write, [], [{community, "public"}]), - - ?DBG("snmpv2_mib_2 -> asn err",[]), - try_test(std_mib_asn_err), - - ?DBG("snmpv2_mib_2 -> check counters",[]), - try_test(std_mib_c, [Bad]), - - ?DBG("snmpv2_mib_2 -> get som counters",[]), - try_test(snmpv2_mib_a), - - ?DBG("snmpv2_mib_2 -> enable auth traps, and await some",[]), - try_test(std_mib_finish), - - ?DBG("snmpv2_mib_2 -> force auth failure, and await trap, " - "then disable auth traps",[]), - try_test(snmpv2_mib_test_finish, [], [{community, "bad community"}]), - - ?LOG("snmpv2_mib_2 -> done",[]). - -%% Req. SNMPv2-MIB -snmpv2_mib_3(suite) -> []; -snmpv2_mib_3(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - InBadVsns = try_test(std_mib_a), - put(vsn, v1), - try_test(std_mib_read), - put(vsn, v3), - _Bad = try_test(std_mib_b, [InBadVsns]), - try_test(snmpv2_mib_a), - - try_test(std_mib_finish). - --define(authenticationFailure, [1,3,6,1,6,3,1,1,5,5]). - -%% Req. SNMPv2-MIB -snmpv2_mib_test_finish() -> - %% force a authenticationFailure - ?DBG("ma_v2_inform -> write to std mib",[]), - std_mib_write(), - - %% check that we got a trap - ?DBG("ma_v2_inform -> await trap",[]), - ?line expect(2, v2trap, [{[sysUpTime,0], any}, - {[snmpTrapOID,0], ?authenticationFailure}]), - - %% and the the inform - ?DBG("ma_v2_inform -> await inform",[]), - ?line expect(2, {inform,true}, [{[sysUpTime,0], any}, - {[snmpTrapOID,0],?authenticationFailure}]). - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_a() -> - ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), - ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), - ?line InPkts2 = InPkts + 1, - - ?line [InBadVsns] = get_req(4, [[snmpInBadVersions,0]]), - InBadVsns. - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_b(InBadVsns) -> - ?line [InBadVsns2] = get_req(1, [[snmpInBadVersions,0]]), - ?line InBadVsns2 = InBadVsns + 1, - ?line [InPkts] = get_req(2, [[snmpInPkts,0]]), - ?line [InPkts2] = get_req(3, [[snmpInPkts,0]]), - ?line InPkts2 = InPkts + 1, - ?line [InBadCommunityNames, InBadCommunityUses, InASNErrs] = - get_req(4, [[snmpInBadCommunityNames,0], - [snmpInBadCommunityUses,0], - [snmpInASNParseErrs, 0]]), - {InBadCommunityNames, InBadCommunityUses, InASNErrs}. - -%% Req. SNMP-STANDARD-MIB | SNMPv2-MIB -std_mib_c({InBadCommunityNames, InBadCommunityUses, InASNErrs}) -> - ?line [InBadCommunityNames2, InBadCommunityUses2, InASNErrs2] = - get_req(1, [[snmpInBadCommunityNames,0], - [snmpInBadCommunityUses,0], - [snmpInASNParseErrs, 0]]), - ?line InBadCommunityNames2 = InBadCommunityNames + 1, - ?line InBadCommunityUses2 = InBadCommunityUses + 1, - ?line InASNErrs2 = InASNErrs + 1. - -%% Req. SNMPv2-MIB -snmpv2_mib_a() -> - ?line [SetSerial] = get_req(2, [[snmpSetSerialNo,0]]), - s([{[snmpSetSerialNo,0], SetSerial}, {[sysLocation, 0], "val2"}]), - ?line expect(3, [{[snmpSetSerialNo,0], SetSerial}, - {[sysLocation, 0], "val2"}]), - s([{[sysLocation, 0], "val3"}, {[snmpSetSerialNo,0], SetSerial}]), - ?line expect(4, inconsistentValue, 2, - [{[sysLocation, 0], "val3"}, - {[snmpSetSerialNo,0], SetSerial}]), - ?line ["val2"] = get_req(5, [[sysLocation,0]]). - - -%%----------------------------------------------------------------- -%% o Bad community uses/name is tested already -%% in SNMPv2-MIB and STANDARD-MIB. -%% o Test add/deletion of rows. -%%----------------------------------------------------------------- -snmp_community_mib(suite) -> []; -snmp_community_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - try_test(snmp_community_mib), - ?line unload_master("SNMP-COMMUNITY-MIB"). - -snmp_community_mib_2(X) -> snmp_community_mib(X). - -%% Req. SNMP-COMMUNITY-MIB -snmp_community_mib() -> - ?INF("NOT YET IMPLEMENTED", []), - nyi. - -%%----------------------------------------------------------------- -%% o Test engine boots / time -%%----------------------------------------------------------------- -snmp_framework_mib(suite) -> []; -snmp_framework_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - try_test(snmp_framework_mib), - ?line unload_master("SNMP-FRAMEWORK-MIB"). - -snmp_framework_mib_2(X) -> snmp_framework_mib(X). - -snmp_framework_mib_3(suite) -> []; -snmp_framework_mib_3(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - try_test(snmp_framework_mib). - - -%% Req. SNMP-FRAMEWORK-MIB -snmp_framework_mib() -> - ?line ["agentEngine"] = get_req(1, [[snmpEngineID,0]]), - ?line [EngineTime] = get_req(2, [[snmpEngineTime,0]]), - sleep(5000), - ?line [EngineTime2] = get_req(3, [[snmpEngineTime,0]]), - if - EngineTime+7 < EngineTime2 -> - ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); - EngineTime+4 > EngineTime2 -> - ?line ?FAIL({too_large_diff, EngineTime, EngineTime2}); - true -> ok - end, - ?line case get_req(4, [[snmpEngineBoots,0]]) of - [Boots] when integer(Boots) -> ok; - Else -> ?FAIL(Else) - end, - ok. - -%%----------------------------------------------------------------- -%% o Test the counters -%%----------------------------------------------------------------- -snmp_mpd_mib_3(suite) -> []; -snmp_mpd_mib_3(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - UnknownPDUHs = try_test(snmp_mpd_mib_a), - try_test(snmp_mpd_mib_b, [], [{context_engine_id, "bad engine"}]), - try_test(snmp_mpd_mib_c, [UnknownPDUHs]). - - -%% Req. SNMP-MPD-MIB -snmp_mpd_mib_a() -> - ?line [UnknownSecs, InvalidMsgs] = - get_req(1, [[snmpUnknownSecurityModels,0], - [snmpInvalidMsgs,0]]), - Pdu = #pdu{type = 'get-request', - request_id = 23, - error_status = noError, - error_index = 0, - varbinds = []}, - SPdu = #scopedPdu{contextEngineID = "agentEngine", - contextName = "", - data = Pdu}, - ?line SPDUBytes = snmp_pdus:enc_scoped_pdu(SPdu), - V3Hdr1 = #v3_hdr{msgID = 21, - msgMaxSize = 484, - msgFlags = [7], - msgSecurityModel = 23, % bad sec model - msgSecurityParameters = []}, - V3Hdr2 = #v3_hdr{msgID = 21, - msgMaxSize = 484, - msgFlags = [6], % bad flag combination - msgSecurityModel = 3, - msgSecurityParameters = []}, - Message1 = #message{version = 'version-3', vsn_hdr = V3Hdr1, - data = SPDUBytes}, - Message2 = #message{version = 'version-3', vsn_hdr = V3Hdr2, - data = SPDUBytes}, - ?line MsgBytes1 = snmp_pdus:enc_message_only(Message1), - ?line MsgBytes2 = snmp_pdus:enc_message_only(Message2), - snmp_test_mgr:send_bytes(MsgBytes1), - snmp_test_mgr:send_bytes(MsgBytes2), - - ?line [UnknownSecs2, InvalidMsgs2, UnknownPDUHs] = - get_req(1, [[snmpUnknownSecurityModels,0], - [snmpInvalidMsgs,0], - [snmpUnknownPDUHandlers, 0]]), - ?line UnknownSecs2 = UnknownSecs + 1, - ?line InvalidMsgs2 = InvalidMsgs + 1, - UnknownPDUHs. - --define(snmpUnknownPDUHandlers_instance, [1,3,6,1,6,3,11,2,1,3,0]). -snmp_mpd_mib_b() -> - g([[sysUpTime,0]]), - ?line expect(1, report, [{?snmpUnknownPDUHandlers_instance, any}]). - - -snmp_mpd_mib_c(UnknownPDUHs) -> - ?line [UnknownPDUHs2] = get_req(1, [[snmpUnknownPDUHandlers, 0]]), - ?line UnknownPDUHs2 = UnknownPDUHs + 1. - - -snmp_target_mib(suite) -> []; -snmp_target_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-TARGET-MIB"), - try_test(snmp_target_mib), - ?line unload_master("SNMP-TARGET-MIB"). - -snmp_target_mib_2(X) -> snmp_target_mib(X). - -snmp_target_mib_3(X) -> snmp_target_mib(X). - -snmp_target_mib() -> - ?INF("NOT YET IMPLEMENTED", []), - nyi. - -snmp_notification_mib(suite) -> []; -snmp_notification_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - try_test(snmp_notification_mib), - ?line unload_master("SNMP-NOTIFICATION-MIB"). - -snmp_notification_mib_2(X) -> snmp_notification_mib(X). - -snmp_notification_mib_3(X) -> snmp_notification_mib(X). - -snmp_notification_mib() -> - ?INF("NOT YET IMPLEMENTED", []), - nyi. - -%%----------------------------------------------------------------- -%% o add/delete views and try them -%% o try boundaries -%%----------------------------------------------------------------- -snmp_view_based_acm_mib(suite) -> []; -snmp_view_based_acm_mib(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - ?line load_master("Test2"), - snmp_view_based_acm_mib(), - ?line unload_master("Test2"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). - -snmp_view_based_acm_mib_2(X) -> snmp_view_based_acm_mib(X). - -snmp_view_based_acm_mib_3(X) -> snmp_view_based_acm_mib(X). - -snmp_view_based_acm_mib() -> - snmpa:verbosity(net_if,trace), - snmpa:verbosity(master_agent,trace), - ?LOG("start snmp_view_based_acm_mib test",[]), - %% The user "no-rights" is present in USM, and is mapped to security - %% name 'no-rights", which is not present in VACM. - %% So, we'll add rights for it, try them and delete them. - %% We'll give "no-rights" write access to tDescr.0 and read access - %% to tDescr2.0 - %% These are the options we'll use to the mgr - Opts = [{user, "no-rights"}, {community, "no-rights"}], - %% Find the valid secmodel, and one invalid secmodel. - {SecMod, InvSecMod} = - case get(vsn) of - v1 -> {?SEC_V1, ?SEC_V2C}; - v2 -> {?SEC_V2C, ?SEC_USM}; - v3 -> {?SEC_USM, ?SEC_V1} - end, - ?DBG("assign rights for 'no-rights'",[]), - ?line try_test(use_no_rights, [], Opts), - - %% Now, add a mapping from "no-rights" -> "no-rights-group" - GRow1Status = [vacmSecurityToGroupStatus,[SecMod, 9,"no-rights"]], - GRow1 = - [{[vacmGroupName, [SecMod, 9,"no-rights"]], "no-rights-group"}, - {GRow1Status, ?createAndGo}], - ?DBG("set '~p'",[GRow1]), - ?line try_test(do_set, [GRow1]), - - ?DBG("assign rights for 'no-rights'",[]), - ?line try_test(use_no_rights, [], Opts), - - %% Create a mapping for another sec model, and make sure it dosn't - %% give us access - GRow2Status = [vacmSecurityToGroupStatus,[InvSecMod, 9,"no-rights"]], - GRow2 = [{[vacmGroupName, [InvSecMod, 9, "no-rights"]], "initial"}, - {GRow2Status, ?createAndGo}], - - ?DBG("set '~p'",[GRow2]), - ?line try_test(do_set, [GRow2]), - - ?DBG("assign rights for 'no-rights'",[]), - ?line try_test(use_no_rights, [], Opts), - - %% Delete that row - ?line try_test(del_row, [GRow2Status]), - - RVName = "rv_name", - WVName = "wv_name", - - %% Access row - ARow1Idx = [15 | "no-rights-group"] ++ [0, ?SEC_ANY, 1], - ARow1Status = [vacmAccessStatus, ARow1Idx], - ARow1 = [{[vacmAccessContextMatch, ARow1Idx], 1}, - {[vacmAccessReadViewName, ARow1Idx], RVName}, - {[vacmAccessWriteViewName, ARow1Idx], WVName}, - {ARow1Status, ?createAndGo}], - - %% This access row would give acces, if InvSecMod was valid. - ARow2Idx = [15 | "no-rights-group"] ++ [0, InvSecMod, 1], - ARow2Status = [vacmAccessStatus, ARow2Idx], - ARow2 = [{[vacmAccessContextMatch, ARow2Idx], 1}, - {[vacmAccessReadViewName, ARow2Idx], "internet"}, - {[vacmAccessWriteViewName, ARow2Idx], "internet"}, - {ARow2Status, ?createAndGo}], - - ?line try_test(do_set, [ARow2]), - - ?line try_test(use_no_rights, [], Opts), - - %% Delete that row - ?line try_test(del_row, [ARow2Status]), - - - %% Add valid row - ?line try_test(do_set, [ARow1]), - - ?line try_test(use_no_rights, [], Opts), - - %% Create the view family - VRow1Idx = mk_ln(RVName) ++ mk_ln(?xDescr), % object access - VRow2Idx = mk_ln(RVName) ++ mk_ln(?xDescr2 ++ [0]), % instance access - VRow3Idx = mk_ln(WVName) ++ mk_ln(?xDescr), % object access - VRow4Idx = mk_ln(WVName) ++ mk_ln(?xDescr ++ [0]), % instance access - VRow1Status = [vacmViewTreeFamilyStatus, VRow1Idx], - VRow2Status = [vacmViewTreeFamilyStatus, VRow2Idx], - VRow3Status = [vacmViewTreeFamilyStatus, VRow3Idx], - VRow4Status = [vacmViewTreeFamilyStatus, VRow4Idx], - - ?line try_test(add_row, [VRow1Status]), - ?line try_test(add_row, [VRow2Status]), - ?line try_test(add_row, [VRow3Status]), - - %% We're supposed to have access now... - ?line try_test(use_rights, [], Opts), - - %% Change Row3 to Row4 - ?line try_test(del_row, [VRow3Status]), - ?line try_test(add_row, [VRow4Status]), - - %% We should still have access... - ?line try_test(use_rights, [], Opts), - - %% Delete rows - ?line try_test(del_row, [GRow1Status]), - - ?line try_test(use_no_rights, [], Opts), - - %% Delete rest of rows - ?line try_test(del_row, [ARow1Status]), - ?line try_test(del_row, [VRow1Status]), - ?line try_test(del_row, [VRow2Status]), - ?line try_test(del_row, [VRow4Status]), - - ?line try_test(use_no_rights, [], Opts), - snmpa:verbosity(master_agent,log). - -do_set(Row) -> - s(Row), - expect(1, Row). - -add_row(RowStatus) -> - s([{RowStatus, ?createAndGo}]), - expect(1, [{RowStatus, ?createAndGo}]). - -del_row(RowStatus) -> - s([{RowStatus, ?destroy}]), - expect(1, [{RowStatus, ?destroy}]). - - - -use_no_rights() -> - g([[xDescr,0]]), - ?v1_2_3(expect(11, noSuchName, 1, any), - expect(12, [{[xDescr,0], noSuchObject}]), - expect(13, authorizationError, 1, any)), - g([[xDescr2,0]]), - ?v1_2_3(expect(21, noSuchName, 1, any), - expect(22, [{[xDescr2,0], noSuchObject}]), - expect(23, authorizationError, 1, any)), - gn([[xDescr]]), - ?v1_2_3(expect(31, noSuchName, 1, any), - expect(32, [{[xDescr], endOfMibView}]), - expect(33, authorizationError, 1, any)), - s([{[xDescr,0], "tryit"}]), - ?v1_2_3(expect(41, noSuchName, 1, any), - expect(42, noAccess, 1, any), - expect(43, authorizationError, 1, any)). - - -use_rights() -> - g([[xDescr,0]]), - expect(1, [{[xDescr,0], any}]), - g([[xDescr2,0]]), - expect(2, [{[xDescr2,0], any}]), - s([{[xDescr,0], "tryit"}]), - expect(3, noError, 0, any), - g([[xDescr,0]]), - expect(4, [{[xDescr,0], "tryit"}]). - -mk_ln(X) -> - [length(X) | X]. - -%%----------------------------------------------------------------- -%% o add/delete users and try them -%% o test all secLevels -%% o test all combinations of protocols -%% o try bad ops; check counters -%%----------------------------------------------------------------- -snmp_user_based_sm_mib_3(suite) -> []; -snmp_user_based_sm_mib_3(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - _AgentDir = ?config(agent_dir, Config), - ?line load_master_std("SNMP-USER-BASED-SM-MIB"), - - %% The newUser used here already has VACM access. - - %% Add a new user in the simplest way; just createAndGo - try_test(v3_sync, [[{usm_add_user1, []}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - %% Try to use the new user - ?line load_master("Test2"), - try_test(v3_sync, [[{usm_use_user, []}]], - [{sec_level, authPriv}, {user, "newUser"}]), - ?line unload_master("Test2"), - - ShaKey1 = snmp:passwd2localized_key(sha, "new sha password", "agentEngine"), - DesKey1 = lists:sublist(ShaKey1, 16), - - %% Change the new user's keys - 1 - try_test(v3_sync, [[{usm_key_change1, [ShaKey1, DesKey1]}]], - [{sec_level, authPriv}, {user, "newUser"}]), - - %% Try to use the new keys - MgrDir = ?config(mgr_dir, Config), - ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), - ?line load_master("Test2"), - try_test(v3_sync, [[{usm_use_user, []}]], - [{sec_level, authPriv}, {user, "newUser"}]), - ?line unload_master("Test2"), - - ShaKey2 = snmp:passwd2localized_key(sha, "newer password", "agentEngine"), - DesKey2 = lists:sublist(ShaKey2, 16), - - %% Change the new user's keys - 2 - ?line try_test(v3_sync, - [[{usm_key_change2, [ShaKey1, DesKey1, ShaKey2, DesKey2]}]], - [{sec_level, authPriv}, {user, "newUser"}]), - - %% Try to use the new keys - reset_usm_mgr(MgrDir), - ?line rewrite_usm_mgr(MgrDir, ShaKey2, DesKey2), - ?line load_master("Test2"), - ?line try_test(v3_sync, [[{usm_use_user, []}]], - [{sec_level, authPriv}, {user, "newUser"}]), - ?line unload_master("Test2"), - reset_usm_mgr(MgrDir), - - %% Change the new user's keys - 3 - ?line try_test(v3_sync, - [[{usm_key_change3, [ShaKey2, DesKey2, ShaKey1, DesKey1]}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - %% Try to use the new keys - ?line rewrite_usm_mgr(MgrDir, ShaKey1, DesKey1), - ?line load_master("Test2"), - try_test(v3_sync, [[{usm_use_user, []}]], - [{sec_level, authPriv}, {user, "newUser"}]), - ?line unload_master("Test2"), - reset_usm_mgr(MgrDir), - - %% Try some read requests - ?line try_test(v3_sync, [[{usm_read, []}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - %% Delete the new user - ?line try_test(v3_sync, [[{usm_del_user, []}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - %% Try some bad requests - ?line try_test(v3_sync, [[{usm_bad, []}]], - [{sec_level, authPriv}, {user, "privDES"}]), - - ?line unload_master("SNMP-USER-BASED-SM-MIB"). - --define(usmUserSecurityName, [1,3,6,1,6,3,15,1,2,2,1,3]). - -usm_add_user1() -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - RowPointer = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], - Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer}, - {[usmUserStatus, NewRowIndex], ?createAndGo}], - ?line s(Vbs1), - ?line expect(1, Vbs1), - ok. - -usm_use_user() -> - v2_proc(). - - -%% Change own public keys -usm_key_change1(ShaKey, DesKey) -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - "passwd_shaxxxxxxxxxx", - ShaKey), - DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - "passwd_desxxxxxx", - DesKey), - Vbs1 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, - {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], - s(Vbs1), - ?line expect(1, Vbs1). - -%% Change own private keys -usm_key_change2(OldShaKey, OldDesKey, ShaKey, DesKey) -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - OldShaKey, - ShaKey), - DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - OldDesKey, - DesKey), - Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}, - {[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], - s(Vbs1), - ?line expect(1, Vbs1). - -%% Change other's public keys -usm_key_change3(OldShaKey, OldDesKey, ShaKey, DesKey) -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - ShaKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - OldShaKey, - ShaKey), - DesKeyChange = snmp_user_based_sm_mib:mk_key_change(sha, - OldDesKey, - DesKey), - Vbs1 = [{[usmUserOwnAuthKeyChange, NewRowIndex], ShaKeyChange}], - s(Vbs1), - ?line expect(1, noAccess, 1, any), - Vbs2 = [{[usmUserOwnPrivKeyChange, NewRowIndex], DesKeyChange}], - s(Vbs2), - ?line expect(2, noAccess, 1, any), - - - Vbs3 = [{[usmUserAuthKeyChange, NewRowIndex], ShaKeyChange}, - {[usmUserPrivKeyChange, NewRowIndex], DesKeyChange}], - s(Vbs3), - ?line expect(1, Vbs3). - -usm_read() -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - ?line g([[usmUserSecurityName, NewRowIndex], - [usmUserCloneFrom, NewRowIndex], - [usmUserAuthKeyChange, NewRowIndex], - [usmUserOwnAuthKeyChange, NewRowIndex], - [usmUserPrivKeyChange, NewRowIndex], - [usmUserOwnPrivKeyChange, NewRowIndex]]), - ?line expect(1, - [{[usmUserSecurityName, NewRowIndex], "newUser"}, - {[usmUserCloneFrom, NewRowIndex], [0,0]}, - {[usmUserAuthKeyChange, NewRowIndex], ""}, - {[usmUserOwnAuthKeyChange, NewRowIndex], ""}, - {[usmUserPrivKeyChange, NewRowIndex], ""}, - {[usmUserOwnPrivKeyChange, NewRowIndex], ""}]), - ok. - - - -usm_del_user() -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - Vbs1 = [{[usmUserStatus, NewRowIndex], ?destroy}], - ?line s(Vbs1), - ?line expect(1, Vbs1), - ok. - --define(usmUserCloneFrom, [1,3,6,1,6,3,15,1,2,2,1,4]). - --define(usmNoAuthProtocol, [1,3,6,1,6,3,10,1,1,1]). - --define(usmHMACMD5AuthProtocol, [1,3,6,1,6,3,10,1,1,2]). - --define(usmHMACSHAAuthProtocol, [1,3,6,1,6,3,10,1,1,3]). - --define(usmNoPrivProtocol, [1,3,6,1,6,3,10,1,2,1]). - --define(usmDESPrivProtocol, [1,3,6,1,6,3,10,1,2,2]). - -usm_bad() -> - NewRowIndex = [11,"agentEngine", 7, "newUser"], - RowPointer1 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDOS"], - Vbs1 = [{[usmUserCloneFrom, NewRowIndex], RowPointer1}, - {[usmUserStatus, NewRowIndex], ?createAndGo}], - ?line s(Vbs1), - ?line expect(1, inconsistentName, 1, any), - - RowPointer2 = ?usmUserCloneFrom ++ [11|"agentEngine"] ++ [7|"privDES"], - Vbs2 = [{[usmUserCloneFrom, NewRowIndex], RowPointer2}, - {[usmUserStatus, NewRowIndex], ?createAndGo}], - ?line s(Vbs2), - ?line expect(2, wrongValue, 1, any), - - RowPointer3 = ?usmUserSecurityName ++ [11|"agentEngine"] ++ [7|"privDES"], - Vbs3 = [{[usmUserCloneFrom, NewRowIndex], RowPointer3}, - {[usmUserStatus, NewRowIndex], ?createAndGo}], - ?line s(Vbs3), - ?line expect(3, Vbs3), - ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmNoAuthProtocol}]), - ?line expect(4, inconsistentValue, 1, any), - ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmHMACMD5AuthProtocol}]), - ?line expect(5, inconsistentValue, 1, any), - ?line s([{[usmUserAuthProtocol, NewRowIndex], ?usmDESPrivProtocol}]), - ?line expect(6, wrongValue, 1, any), - ?line s([{[usmUserPrivProtocol, NewRowIndex], ?usmHMACSHAAuthProtocol}]), - ?line expect(7, wrongValue, 1, any), - - Vbs4 = [{[usmUserStatus, NewRowIndex], ?destroy}], - ?line s(Vbs4), - ?line expect(1, Vbs4), - - ok. - - -%%----------------------------------------------------------------- -%% Loop through entire MIB, to make sure that all instrum. funcs -%% works. -%% Load all std mibs that are not loaded by default. -%%----------------------------------------------------------------- -loop_mib(suite) -> []; -loop_mib(Config) when list(Config) -> - ?LOG("loop_mib -> initiate case",[]), - %% snmpa:verbosity(master_agent,debug), - %% snmpa:verbosity(mib_server,info), - {SaNode, MgrNode, MibDir} = init_case(Config), - ?DBG("loop_mib -> ~n" - "\tSaNode: ~p~n" - "\tMgrNode: ~p~n" - "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), - ?DBG("loop_mib -> load mib SNMP-COMMUNITY-MIB",[]), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?DBG("loop_mib -> load mib SNMP-MPD-MIB",[]), - ?line load_master_std("SNMP-MPD-MIB"), - ?DBG("loop_mib -> load mib SNMP-TARGET-MIB",[]), - ?line load_master_std("SNMP-TARGET-MIB"), - ?DBG("loop_mib -> load mib SNMP-NOTIFICATION-MIB",[]), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?DBG("loop_mib -> load mib SNMP-FRAMEWORK-MIB",[]), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?DBG("loop_mib -> load mib SNMP-VIEW-BASED-ACM-MIB",[]), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - ?DBG("loop_mib -> try",[]), - try_test(loop_mib_1), - ?DBG("loop_mib -> unload mib SNMP-COMMUNITY-MIB",[]), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?DBG("loop_mib -> unload mib SNMP-MPD-MIB",[]), - ?line unload_master("SNMP-MPD-MIB"), - ?DBG("loop_mib -> unload mib SNMP-TARGET-MIB",[]), - ?line unload_master("SNMP-TARGET-MIB"), - ?DBG("loop_mib -> unload mib SNMP-NOTIFICATION-MIB",[]), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?DBG("loop_mib -> unload mib SNMP-FRAMEWORK-MIB",[]), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?DBG("loop_mib -> unload mib SNMP-VIEW-BASED-ACM-MIB",[]), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - %% snmpa:verbosity(master_agent,log), - %% snmpa:verbosity(mib_server,silence), - ?LOG("loop_mib -> done",[]). - - -loop_mib_2(suite) -> []; -loop_mib_2(Config) when list(Config) -> - ?LOG("loop_mib_2 -> initiate case",[]), - {SaNode, MgrNode, MibDir} = init_case(Config), - ?DBG("loop_mib_2 -> ~n" - "\tSaNode: ~p~n" - "\tMgrNode: ~p~n" - "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), - ?DBG("loop_mib_2 -> load mibs",[]), - ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?line load_master_std("SNMP-MPD-MIB"), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - try_test(loop_mib_2), - ?DBG("loop_mib_2 -> unload mibs",[]), - ?line unload_master("SNMP-COMMUNITY-MIB"), - ?line unload_master("SNMP-MPD-MIB"), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - ?LOG("loop_mib_2 -> done",[]). - - -loop_mib_3(suite) -> []; -loop_mib_3(Config) when list(Config) -> - ?LOG("loop_mib_3 -> initiate case",[]), - {SaNode, MgrNode, MibDir} = init_case(Config), - ?DBG("loop_mib_3 -> ~n" - "\tSaNode: ~p~n" - "\tMgrNode: ~p~n" - "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), - ?DBG("loop_mib_3 -> load mibs",[]), - ?line load_master_std("SNMP-TARGET-MIB"), - ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - ?line load_master_std("SNMP-USER-BASED-SM-MIB"), - try_test(loop_mib_2), - ?DBG("loop_mib_3 -> unload mibs",[]), - ?line unload_master("SNMP-TARGET-MIB"), - ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), - ?line unload_master("SNMP-USER-BASED-SM-MIB"), - ?LOG("loop_mib_3 -> done",[]). - - -%% Req. As many mibs all possible -loop_mib_1() -> - ?DBG("loop_mib_1 -> entry",[]), - N = loop_it_1([1,1], 0), - io:format(user, "found ~w varibles\n", [N]), - ?line N = if N < 100 -> 100; - true -> N - end. - - -loop_it_1(Oid, N) -> - ?DBG("loop_it_1 -> entry with~n" - "\tOid: ~p~n" - "\tN: ~p",[Oid,N]), - case get_next_req([Oid]) of - #pdu{type='get-response', error_status=noError, error_index=0, - varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> - ?DBG("loop_it_1 -> ~n" - "\tNOid: ~p~n" - "\tValue: ~p",[NOid,Value]), - ?line [Value2] = get_req(1, [NOid]), % must not be same - ?DBG("loop_it_1 -> ~n" - "\tValue2: ~p",[Value2]), - loop_it_1(NOid, N+1); - #pdu{type='get-response', error_status=noSuchName, error_index=1, - varbinds=[_]} -> - ?DBG("loop_it_1 -> done",[]), - N; - - #pdu{type = Type, error_status = Err, error_index = Idx, - varbinds = Vbs} -> - exit({unexpected_pdu, ?LINE, Type, Err, Idx, Vbs}) - end. - -%% Req. As many mibs all possible -loop_mib_2() -> - ?DBG("loop_mib_1 -> entry",[]), - N = loop_it_2([1,1], 0), - io:format(user, "found ~w varibles\n", [N]), - ?line N = if N < 100 -> 100; - true -> N - end. - - -loop_it_2(Oid, N) -> - ?DBG("loop_it_2 -> entry with~n" - "\tOid: ~p~n" - "\tN: ~p",[Oid,N]), - case get_next_req([Oid]) of - #pdu{type='get-response', error_status=noError, error_index=0, - varbinds=[#varbind{oid = NOid, value = endOfMibView}]} -> - ?DBG("loop_it_2 -> ~n" - "\tNOid: ~p",[NOid]), - N; - #pdu{type='get-response', error_status=noError, error_index=0, - varbinds=[#varbind{oid = NOid,value = Value}]} when NOid > Oid -> - ?DBG("loop_it_2 -> ~n" - "\tNOid: ~p~n" - "\tValue: ~p",[NOid,Value]), - ?line [Value2] = get_req(1, [NOid]), % must not be same - ?DBG("loop_it_2 -> ~n" - "\tValue2: ~p",[Value2]), - loop_it_2(NOid, N+1) - end. - - -%%%----------------------------------------------------------------- -%%% Testing of reported bugs and other tickets. -%%%----------------------------------------------------------------- - - - - - -%% These are (ticket) test cases where the initiation has to be done -%% individually. - -%%----------------------------------------------------------------- -%% Ticket: OTP-1128 -%% Slogan: Bug in handling of createAndWait set-requests. -%%----------------------------------------------------------------- -otp_1128(suite) -> []; -otp_1128(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(otp_1128), - ?line unload_master("OLD-SNMPEA-MIB"). - -otp_1128_2(X) -> otp_1128(X). - -otp_1128_3(X) -> otp_1128(X). - -otp_1128() -> - io:format("Testing bug reported in ticket OTP-1128...~n"), - - NewKeyc3 = [intCommunityViewIndex,get(mip),is("test")], - NewKeyc4 = [intCommunityAccess,get(mip),is("test")], - NewKeyc5 = [intCommunityStatus,get(mip),is("test")], - - s([{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), - ?line expect(28, [{NewKeyc5, ?createAndWait}, {NewKeyc4, 2}]), - g([NewKeyc5]), - ?line expect(29, [{NewKeyc5, ?notReady}]), - s([{NewKeyc5, ?active}, {NewKeyc3, 2}]), - ?line expect(30, [{NewKeyc5, ?active}, {NewKeyc3, 2}]), - g([NewKeyc5]), - ?line expect(31, [{NewKeyc5, ?active}]), - s([{NewKeyc5, ?destroy}]), - ?line expect(32, [{NewKeyc5, ?destroy}]). - -%%----------------------------------------------------------------- -%% Ticket: OTP-1129, OTP-1169 -%% Slogan: snmpa:int_to_enum crashes on bad oids -%%----------------------------------------------------------------- -otp_1129(suite) -> []; -otp_1129(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas3"), - try_test(otp_1129_i, [node()]), - ?line unload_master("Klas3"). - -otp_1129_2(X) -> otp_1129(X). - -otp_1129_3(X) -> otp_1129(X). - -otp_1129_i(MaNode) -> - io:format("Testing bug reported in ticket OTP-1129...~n"), - false = rpc:call(MaNode, snmp, int_to_enum, [iso, 1]), - false = rpc:call(MaNode, snmp, int_to_enum, [isox, 1]). - -%%----------------------------------------------------------------- -%% Ticket: OTP-1131 -%% Slogan: Agent crashes / erlang node halts if RowIndex in a -%% setrequest is of bad type, e.g. an INDEX {INTEGER}, -%% and RowIdenx [3,2]. -%%----------------------------------------------------------------- -otp_1131(suite) -> []; -otp_1131(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas1"), - try_test(otp_1131), - ?line unload_master("Klas1"). - -otp_1131_2(X) -> otp_1131(X). - -otp_1131_3(X) -> otp_1131(X). - -otp_1131() -> - io:format("Testing bug reported in ticket OTP-1131...~n"), - s([{[friendsEntry, [2, 3, 1]], s, "kompis3"}, - {[friendsEntry, [3, 3, 1]], i, ?createAndGo}]), - ?line expect(1, ?v1_2(noSuchName, noCreation), 2, any). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1162 -%% Slogan: snmp_agent can't handle wrongValue from instrum.func -%%----------------------------------------------------------------- -otp_1162(suite) -> []; -otp_1162(Config) when list(Config) -> - {SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), - try_test(otp_1162), - stop_subagent(SA). - -otp_1162_2(X) -> otp_1162(X). - -otp_1162_3(X) -> otp_1162(X). - -otp_1162() -> - s([{[sa, [2,0]], 6}]), % wrongValue (i is_set_ok) - ?line expect(1, ?v1_2(badValue, wrongValue), 1, any). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1222 -%% Slogan: snmp agent crash if faulty index is returned from instrum -%%----------------------------------------------------------------- -otp_1222(suite) -> []; -otp_1222(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas3"), - ?line load_master("Klas4"), - try_test(otp_1222), - ?line unload_master("Klas3"), - ?line unload_master("Klas4"). - -otp_1222_2(X) -> otp_1222(X). - -otp_1222_3(X) -> otp_1222(X). - -otp_1222() -> - io:format("Testing bug reported in ticket OTP-1222...~n"), - s([{[fStatus4,1], 4}, {[fName4,1], 1}]), - ?line expect(1, genErr, 0, any), - s([{[fStatus4,2], 4}, {[fName4,2], 1}]), - ?line expect(2, genErr, 0, any). - -%%----------------------------------------------------------------- -%% Ticket: OTP-1298 -%% Slogan: Negative INTEGER values are treated as positive. -%%----------------------------------------------------------------- -otp_1298(suite) -> []; -otp_1298(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas2"), - try_test(otp_1298), - ?line unload_master("Klas2"). - -otp_1298_2(X) -> otp_1298(X). - -otp_1298_3(X) -> otp_1298(X). - -otp_1298() -> - io:format("Testing bug reported in ticket OTP-1298...~n"), - s([{[fint,0], -1}]), - ?line expect(1298, [{[fint,0], -1}]). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1331 -%% Slogan: snmp_generic should return noError when deleting non-ex row -%%----------------------------------------------------------------- -otp_1331(suite) -> []; -otp_1331(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(otp_1331), - ?line unload_master("OLD-SNMPEA-MIB"). - -otp_1331_2(X) -> otp_1331(X). - -otp_1331_3(X) -> otp_1331(X). - -otp_1331() -> - NewKeyc5 = [intCommunityStatus,[127,32,0,0],is("test")], - s([{NewKeyc5, ?destroy}]), - ?line expect(1, [{NewKeyc5, ?destroy}]). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1338 -%% Slogan: snmp bug in initialisation of default values for mnesia tabs -%%----------------------------------------------------------------- -otp_1338(suite) -> []; -otp_1338(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas2"), - try_test(otp_1338), - ?line unload_master("Klas2"). - -otp_1338_2(X) -> otp_1338(X). - -otp_1338_3(X) -> otp_1338(X). - -otp_1338() -> - s([{[kStatus2, 7], i, ?createAndGo}]), - ?line expect(1, [{[kStatus2, 7], ?createAndGo}]), - g([[kName2, 7]]), - ?line expect(2, [{[kName2, 7], "JJJ"}]). - -%%----------------------------------------------------------------- -%% Ticket: OTP-1342 -%% Slogan: default impl of snmp table can't handle bad index access, -%% Set when INDEX is read-write gets into an infinite loop! -%%----------------------------------------------------------------- -otp_1342(suite) -> []; -otp_1342(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Klas4"), - try_test(otp_1342), - ?line unload_master("Klas4"). - -otp_1342_2(X) -> otp_1342(X). - -otp_1342_3(X) -> otp_1342(X). - -otp_1342() -> - s([{[fIndex5, 1], i, 1}, - {[fName5, 1], i, 3}, - {[fStatus5, 1], i, ?createAndGo}]), - ?line expect(1, ?v1_2(noSuchName, noCreation), 3, any). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-1366 -%% Slogan: snmp traps not sent to all managers -%% Note: NYI! We need a way to tell the test server that we need -%% mgrs on two different machines. -%%----------------------------------------------------------------- -otp_1366(suite) -> []; -otp_1366(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(otp_1366), - ?line unload_master("OLD-SNMPEA-MIB"). - -otp_1366_2(X) -> otp_1366(X). - -otp_1366_3(X) -> otp_1366(X). - -otp_1366() -> - ?INF("NOT YET IMPLEMENTED", []), - 'NYI'. - -%%----------------------------------------------------------------- -%% Ticket: OTP-2776 -%% Slogan: snmp:validate_date_and_time() fails when time is 00:00 -%%----------------------------------------------------------------- -otp_2776(suite) -> []; -otp_2776(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - try_test(otp_2776). - -otp_2776_2(X) -> otp_2776(X). - -otp_2776_3(X) -> otp_2776(X). - -otp_2776() -> - io:format("Testing bug reported in ticket OTP-2776...~n"), - - Dt01_valid = [19,98,9,1,1,0,23,0,43,0,0], - Dt02_valid = [19,98,9,1,0,0,0,0,43,0,0], % This is what is fixed: 00:00 - Dt03_valid = [19,98,2,28,1,0,23,0,43,0,0], - Dt04_invalid = [19,98,2,29,1,0,23,0,43,0,0], - Dt05_valid = [19,96,2,29,1,0,23,0,43,0,0], - Dt06_valid = [20,0,2,29,1,0,23,0,43,0,0], - Dt07_invalid = [19,96,2,30,1,0,23,0,43,0,0], % This is also fixed: 30/2 - Dt08_valid = [19,98,4,30,1,0,23,0,43,0,0], - Dt09_invalid = [19,98,4,31,1,0,23,0,43,0,0], % This is also fixed: 31/4 - Dt10_invalid = [], - Dt11_invalid = [kalle,hobbe], - L = [{ 1, true, Dt01_valid}, - { 2, true, Dt02_valid}, - { 3, true, Dt03_valid}, - { 4, false, Dt04_invalid}, - { 5, true, Dt05_valid}, - { 6, true, Dt06_valid}, - { 7, false, Dt07_invalid}, - { 8, true, Dt08_valid}, - { 9, false, Dt09_invalid}, - {10, false, Dt10_invalid}, - {11, false, Dt11_invalid}], - - ?line ok = validate_dat(L). - - -validate_dat(L) -> validate_dat(L,[]). - -validate_dat([],V) -> - Fun = fun({_,X}) -> case X of - ok -> false; - _ -> true - end - end, - validate_dat1( lists:reverse( lists:filter(Fun,V) ) ); -validate_dat([{Id,E,Dat}|T],V) -> - validate_dat(T,[validate_dat2(Id,E,Dat) | V]). - -validate_dat1([]) -> ok; -validate_dat1(L) -> {error,L}. - -validate_dat2(Id, E, Dat) -> - Res = case {E,snmp:validate_date_and_time(Dat)} of - {E,E} -> ok; - {E,A} -> {E,A} - end, - {Id, Res}. - - -%%----------------------------------------------------------------- -%% Ticket: OTP-2979 -%% Slogan: get-next on more than 1 column in an empty table -%% returns bad response. -%%----------------------------------------------------------------- -otp_2979(suite) -> []; -otp_2979(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master("Test1"), - ?line init_old(), - try_test(otp_2979), - ?line unload_master("Test1"). - -otp_2979_2(X) -> otp_2979(X). - -otp_2979_3(X) -> otp_2979(X). - -otp_2979() -> - gn([[sparseDescr], [sparseStatus]]), - ?line expect(1, [{[sparseStr,0], "slut"}, - {[sparseStr,0], "slut"}]). - -%%----------------------------------------------------------------- -%% Ticket: OTP-3187 -%% Slogan: get-next on vacmAccessTable for colums > 5 returns -%% endOfTable - should return value. -%%----------------------------------------------------------------- -otp_3187(suite) -> []; -otp_3187(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - otp_3187(), - ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"). - -otp_3187_2(X) -> otp_3187(X). - -otp_3187_3(X) -> otp_3187(X). - -otp_3187() -> - ?line Elements = - snmp_view_based_acm_mib:vacmAccessTable(get_next,[],[4,5,6]), - lists:foreach(fun(E) -> - ?line if E == endOfTable -> - ?FAIL(endOfTable); - true -> ok - end - end, Elements). - -%%----------------------------------------------------------------- -%% Ticket: OTP-3542 -%% Slogan: -%%----------------------------------------------------------------- -otp_3542(suite) -> []; -otp_3542(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - try_test(otp_3542). - -otp_3542() -> - io:format("SNMP v3 discovery...~n"), - ?line Res = snmp_test_mgr:d(), - io:format("SNMP v3 discovery result: ~p~n",[Res]). - - -%%----------------------------------------------------------------- -%% Ticket: OTP-3725 -%% Slogan: Slow response time on snmpa:int_to_enum -%%----------------------------------------------------------------- -otp_3725(suite) -> []; -otp_3725(Config) when list(Config) -> - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - - ?line load_master("OLD-SNMPEA-MIB"), - ?line init_old(), - try_test(otp_3725_test, [node()]), - ?line unload_master("OLD-SNMPEA-MIB"). - -%% Req. OLD-SNMPEA-MIB -otp_3725_test(MaNode) -> - io:format("Testing feature requested in ticket OTP-3725...~n"), - ?line rpc:call(MaNode,snmpa,verbosity,[symbolic_store,trace]), - ?line Db = rpc:call(MaNode,snmp,get_symbolic_store_db,[]), - ?DBG("otp_3725_test -> Db = ~p",[Db]), - - ?line {value, OID} = rpc:call(MaNode, snmp, name_to_oid, - [Db, intAgentIpAddress]), - ?DBG("otp_3725_test -> name_to_oid for ~p: ~p",[intAgentIpAddress,OID]), - ?line {value, intAgentIpAddress} = rpc:call(MaNode, snmp, oid_to_name, - [Db,OID]), - ?DBG("otp_3725_test -> oid_to_name for ~p: ~p",[OID,intAgentIpAddress]), - ?line false = rpc:call(MaNode, snmp, name_to_oid, [Db, intAgentIpAddres]), - ?line false = rpc:call(MaNode, snmp, oid_to_name, - [Db, [1,5,32,3,54,3,3,34,4]]), - ?line {value, 2} = rpc:call(MaNode, snmp, enum_to_int, - [Db, intViewType, excluded]), - ?line {value, excluded} = rpc:call(MaNode, snmp, int_to_enum, - [Db, intViewType, 2]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, intViewType, exclude]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, intAgentIpAddress, exclude]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, intAgentIpAddre, exclude]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, intViewType, 3]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, - [Db, intAgentIpAddress, 2]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, - [Db, intAgentIpAddre, 2]), - ?line {value, active} = rpc:call(MaNode, snmp, int_to_enum, - [Db, 'RowStatus', ?active]), - ?line {value, ?destroy} = rpc:call(MaNode, snmp, enum_to_int, - [Db, 'RowStatus', destroy]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, 'RowStatus', xxxdestroy]), - ?line false = rpc:call(MaNode, snmp, enum_to_int, - [Db, 'xxRowStatus', destroy]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'RowStatus', 25]), - ?line false = rpc:call(MaNode, snmp, int_to_enum, [Db, 'xxRowStatus', 1]), - ok. - - -%%----------------------------------------------------------------- -%% Ticket: OTP-4394 -%% Slogan: Target mib tag list check invalid -%%----------------------------------------------------------------- - - - -init_otp_4394(Config) when list(Config) -> - ?DBG("init_otp_4394 -> entry with" - "~n Config: ~p", [Config]), - ?line AgentDir = ?config(agent_dir, Config), - ?line MgrDir = ?config(mgr_dir, Config), - ?line Ip = ?config(ip, Config), - ?line otp_4394_config(AgentDir, MgrDir, Ip), - MasterAgentVerbosity = {master_agent_verbosity, trace}, - NetIfVerbosity = {net_if_verbosity, trace}, - Opts = [MasterAgentVerbosity,NetIfVerbosity], - [{vsn, v1} | start_v1_agent(Config,Opts)]. - -otp_4394_config(AgentDir, MgrDir, Ip0) -> - ?DBG("otp_4394_config -> entry with" - "~n AgentDir: ~p" - "~n MgrDir: ~p" - "~n Ip0: ~p", [AgentDir, MgrDir, Ip0]), - Vsn = [v1], - Ip = tuple_to_list(Ip0), - ?line snmp_config:write_agent_snmp_files(AgentDir, Vsn, Ip, - ?TRAP_UDP, Ip, 4000, - "OTP-4394 test"), - ?line case update_usm(Vsn, AgentDir) of - true -> - ?line copy_file(filename:join(AgentDir, "usm.conf"), - filename:join(MgrDir, "usm.conf")), - ?line update_usm_mgr(Vsn, MgrDir); - false -> - ?line ok - end, - C1 = {"a", "all-rights", "initial", "", "pc"}, - C2 = {"c", "secret", "secret_name", "", "secret_tag"}, - ?line write_community_conf(AgentDir, [C1, C2]), - ?line update_vacm(Vsn, AgentDir), - Ta1 = {"shelob v1", - [134,138,177,177], 5000, 1500, 3, %% Använd Ip och modda - "pc1", - "target_v1", "", - %% [255,255,255,255,0,0], - [], - 2048}, - Ta2 = {"bifur v1", - [134,138,177,75], 5000, 1500, 3, %% Använd Ip - "pc2", - "target_v1", "", - %% [255,255,255,255,0,0], - [], 2048}, - ?line write_target_addr_conf(AgentDir, [Ta1, Ta2]), - ?line write_target_params_conf(AgentDir, Vsn), - ?line write_notify_conf(AgentDir), - ok. - - - -finish_otp_4394(Config) when list(Config) -> - ?DBG("finish_otp_4394 -> entry", []), - C1 = stop_agent(Config), - delete_files(C1), - erase(mgr_node), - lists:keydelete(vsn, 1, C1). - -otp_4394_test(suite) -> []; -otp_4394_test(Config) -> - ?DBG("otp_4394_test -> entry", []), - {_SaNode, _MgrNode, _MibDir} = init_case(Config), - try_test(otp_4394_test1), - ?DBG("otp_4394_test -> done", []), - ok. - -otp_4394_test1() -> - ?DBG("otp_4394_test1 -> entry", []), - gn([[1,1]]), - Res = - case snmp_test_mgr:expect(1, [{[sysDescr,0], "Erlang SNMP agent"}]) of - %% {error, 1, {"?",[]}, {"~w",[timeout]}} - {error, 1, _, {_, [timeout]}} -> - ?DBG("otp_4394_test1 -> expected result: timeout", []), - ok; - Else -> - Else - end, - ?DBG("otp_4394_test1 -> done with: ~p", [Res]), - Res. - - -%%%-------------------------------------------------- -%%% Used to test the standard mib with our -%%% configuration. -%%%-------------------------------------------------- -run(F, A, Opts) -> - M = get(mib_dir), - Dir = get(mgr_dir), - User = snmp_misc:get_option(user, Opts, "all-rights"), - SecLevel = snmp_misc:get_option(sec_level, Opts, noAuthNoPriv), - EngineID = snmp_misc:get_option(engine_id, Opts, "agentEngine"), - CtxEngineID = snmp_misc:get_option(context_engine_id, Opts, EngineID), - Community = snmp_misc:get_option(community, Opts, "all-rights"), - ?DBG("run -> start crypto app",[]), - Crypto = case os:type() of - vxworks -> - no_crypto; - _ -> - ?CRYPTO_START() - end, - ?DBG("run -> Crypto: ~p",[Crypto]), - catch snmp_test_mgr:stop(), % If we had a running mgr from a failed case - StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", - ?DBG("run -> config:~n" - "\tM: ~p~n" - "\tDir: ~p~n" - "\tUser: ~p~n" - "\tSecLevel: ~p~n" - "\tEngineID: ~p~n" - "\tCtxEngineID: ~p~n" - "\tCommunity: ~p~n" - "\tStdM: ~p", - [M,Dir,User,SecLevel,EngineID,CtxEngineID,Community,StdM]), - case snmp_test_mgr:start([%% {agent, snmp_test_lib:hostname()}, - {packet_server_debug,true}, - {debug,true}, - {agent, get(master_host)}, - {agent_udp, 4000}, - {trap_udp, 5000}, - {recbuf,65535}, - quiet, - get(vsn), - {community, Community}, - {user, User}, - {sec_level, SecLevel}, - {engine_id, EngineID}, - {context_engine_id, CtxEngineID}, - {dir, Dir}, - {mibs, mibs(StdM, M)}]) of - {ok, _Pid} -> - Res = apply(?MODULE, F, A), - catch snmp_test_mgr:stop(), - Res; - Err -> - io:format("Error starting manager: ~p\n", [Err]), - catch snmp_test_mgr:stop(), - ?line exit({mgr_start, Err}) - end. - - -mibs(StdMibDir,MibDir) -> - [join(StdMibDir, ?v1_2("STANDARD-MIB.bin", "SNMPv2-MIB.bin")), - join(MibDir, "OLD-SNMPEA-MIB.bin"), - join(StdMibDir, "SNMP-FRAMEWORK-MIB"), - join(StdMibDir, "SNMP-MPD-MIB"), - join(StdMibDir, "SNMP-VIEW-BASED-ACM-MIB"), - join(StdMibDir, "SNMP-USER-BASED-SM-MIB"), - join(StdMibDir, "SNMP-TARGET-MIB"), - join(StdMibDir, "SNMP-NOTIFICATION-MIB"), - join(MibDir, "Klas1.bin"), - join(MibDir, "Klas2.bin"), - join(MibDir, "Klas3.bin"), - join(MibDir, "Klas4.bin"), - join(MibDir, "SA-MIB.bin"), - join(MibDir, "TestTrap.bin"), - join(MibDir, "Test1.bin"), - join(MibDir, "Test2.bin"), - join(MibDir, "TestTrapv2.bin")]. - -join(D,F) -> - filename:join(D,F). - -%% string used in index -is(S) -> [length(S) | S]. - -try_test(Func) -> - call(get(mgr_node), ?MODULE, run, [Func, [], []]). - -try_test(Func, A) -> - call(get(mgr_node), ?MODULE, run, [Func, A, []]). - -try_test(Func, A, Opts) -> - call(get(mgr_node), ?MODULE, run, [Func, A, Opts]). - -call(N,M,F,A) -> - ?DBG("call -> entry with~n" - " N: ~p~n" - " M: ~p~n" - " F: ~p~n" - " A: ~p~n" - " when~n" - " get(): ~p", - [N,M,F,A,get()]), - spawn(N, ?MODULE, wait, [self(),get(),M,F,A]), - receive - {done, {'EXIT', Rn}, Loc} -> - ?DBG("call -> returned ~p",[{done, {'EXIT', Rn}, Loc}]), - put(test_server_loc, Loc), - exit(Rn); - {done, Ret, Zed} -> - ?DBG("call -> returned ~p~n",[{done, Ret, Zed}]), - Ret - end. - -wait(From, Env, M, F, A) -> - ?DBG("wait -> entry with ~n" - "\tFrom: ~p~n" - "\tEnv: ~p",[From,Env]), - lists:foreach(fun({K,V}) -> put(K,V) end, Env), - Rn = (catch apply(M, F, A)), - ?DBG("wait -> Rn: ~n~p", [Rn]), - From ! {done, Rn, get(test_server_loc)}, - exit(Rn). - -expect(A,B) -> ok = snmp_test_mgr:expect(A,B). -expect(A,B,C) -> ok = snmp_test_mgr:expect(A,B,C). -expect(A,B,C,D) -> ok = snmp_test_mgr:expect(A,B,C,D). -expect(A,B,C,D,E,F) -> ok = snmp_test_mgr:expect(A,B,C,D,E,F). - -get_req(Id, Vars) -> - ?DBG("get_req -> entry with~n" - "\tId: ~p~n" - "\tVars: ~p",[Id,Vars]), - g(Vars), - ?DBG("get_req -> await response",[]), - {ok, Val} = snmp_test_mgr:get_response(Id, Vars), - ?DBG("get_req -> response: ~p",[Val]), - Val. - -get_next_req(Vars) -> - ?DBG("get_next_req -> entry with Vars '~p', send request",[Vars]), - gn(Vars), - ?DBG("get_next_req -> await response",[]), - Response = snmp_test_mgr:receive_response(), - ?DBG("get_next_req -> response: ~p",[Response]), - Response. - - - -start_node(Name) -> - ?LOG("start_node -> entry with Name: ~p",[Name]), - M = list_to_atom(?HOSTNAME(node())), - ?DBG("start_node -> M: ~p",[M]), - Pa = filename:dirname(code:which(?MODULE)), - ?DBG("start_node -> Pa: ~p",[Pa]), - - Args = case init:get_argument('CC_TEST') of - {ok, [[]]} -> - " -pa /clearcase/otp/libraries/snmp/ebin "; - {ok, [[Path]]} -> - " -pa " ++ Path; - error -> - "" - end, - %% Do not use start_link!!! (the proc that calls this one is tmp) - ?DBG("start_node -> Args: ~p~n",[Args]), - A = Args ++ " -pa " ++ Pa, - case (catch ?START_NODE(Name, A)) of - {ok, Node} -> - %% Tell the test_server to not clean up things it never started. - ?DBG("start_node -> Node: ~p",[Node]), - {ok, Node}; - Else -> - ?ERR("start_node -> failed with(other): Else: ~p",[Else]), - ?line ?FAIL(Else) - end. - - -stop_node(Node) -> - ?LOG("stop_node -> Node: ~p",[Node]), - rpc:cast(Node, erlang, halt, []). - -p(X) -> - io:format(user, X++"\n", []). - -sleep(X) -> - receive - after - X -> ok - end. - -%%%----------------------------------------------------------------- -%%% Configuration -%%%----------------------------------------------------------------- -config(Vsns, MgrDir, AgentDir, MIp, AIp) -> - ?line snmp_config:write_agent_snmp_files(AgentDir, Vsns, MIp, - ?TRAP_UDP, AIp, 4000, - "test"), - ?line case update_usm(Vsns, AgentDir) of - true -> - ?line copy_file(filename:join(AgentDir, "usm.conf"), - filename:join(MgrDir, "usm.conf")), - ?line update_usm_mgr(Vsns, MgrDir); - false -> - ?line ok - end, - ?line update_community(Vsns, AgentDir), - ?line update_vacm(Vsns, AgentDir), - ?line write_target_addr_conf(AgentDir, MIp, ?TRAP_UDP, Vsns), - ?line write_target_params_conf(AgentDir, Vsns), - ?line write_notify_conf(AgentDir), - ok. - -delete_files(Config) -> - Dir = ?config(agent_dir, Config), - {ok, List} = file:list_dir(Dir), - lists:foreach(fun(FName) -> file:delete(filename:join(Dir, FName)) end, - List). - -update_usm(Vsns, Dir) -> - case lists:member(v3, Vsns) of - true -> - {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),[read,write]), - file:position(Fid, eof), - ok = io:format(Fid, "{\"agentEngine\", \"all-rights\", " - "\"all-rights\", zeroDotZero, " - "usmNoAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"\", \"\"}.\n", []), - ok = io:format(Fid, "{\"agentEngine\", \"no-rights\", " - "\"no-rights\", zeroDotZero, " - "usmNoAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"\", \"\"}.\n", []), - ok = io:format(Fid, "{\"agentEngine\", \"authMD5\", " - "\"authMD5\", zeroDotZero, " - "usmHMACMD5AuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"passwd_md5xxxxxx\", \"\"}.\n", []), - ok = io:format(Fid, "{\"agentEngine\", \"authSHA\", " - "\"authSHA\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"\"}.\n", []), - ok = io:format(Fid, "{\"agentEngine\", \"privDES\", " - "\"privDES\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", - []), - ok = io:format(Fid, "{\"mgrEngine\", \"all-rights\", " - "\"all-rights\", zeroDotZero, " - "usmNoAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"\", \"\"}.\n", []), - ok = io:format(Fid, "{\"mgrEngine\", \"no-rights\", " - "\"no-rights\", zeroDotZero, " - "usmNoAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"\", \"\"}.\n", []), - ok = io:format(Fid, "{\"mgrEngine\", \"authMD5\", " - "\"authMD5\", zeroDotZero, " - "usmHMACMD5AuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"passwd_md5xxxxxx\", \"\"}.\n", []), - ok = io:format(Fid, "{\"mgrEngine\", \"authSHA\", " - "\"authSHA\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmNoPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"\"}.\n", []), - ok = io:format(Fid, "{\"mgrEngine\", \"privDES\", " - "\"privDES\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", - []), - file:close(Fid), - true; - false -> - false - end. - -update_usm_mgr(Vsns, Dir) -> - case lists:member(v3, Vsns) of - true -> - {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),[read,write]), - file:position(Fid, eof), - ok = io:format(Fid, "{\"agentEngine\", \"newUser\", " - "\"newUser\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", - []), - ok = io:format(Fid, "{\"mgrEngine\", \"newUser\", " - "\"newUser\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"passwd_shaxxxxxxxxxx\", \"passwd_desxxxxxx\"}.\n", - []), - file:close(Fid), - true; - false -> - false - end. - -rewrite_usm_mgr(Dir, ShaKey, DesKey) -> - ?line ok = file:rename(filename:join(Dir,"usm.conf"), - filename:join(Dir,"usm.old")), - ?line {ok, Fid} = file:open(filename:join(Dir,"usm.conf"),write), - ok = io:format(Fid, "{\"agentEngine\", \"newUser\", " - "\"newUser\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"~s\", \"~s\"}.\n", - [ShaKey, DesKey]), - ok = io:format(Fid, "{\"mgrEngine\", \"newUser\", " - "\"newUser\", zeroDotZero, " - "usmHMACSHAAuthProtocol, \"\", \"\", " - "usmDESPrivProtocol, \"\", \"\", \"\", " - "\"~s\", \"~s\"}.\n", - [ShaKey, DesKey]), - file:close(Fid). - -reset_usm_mgr(Dir) -> - ?line ok = file:rename(filename:join(Dir,"usm.old"), - filename:join(Dir,"usm.conf")). - - -update_community([v3], _Dir) -> ok; -update_community(_, Dir) -> - {ok, Fid} = file:open(filename:join(Dir,"community.conf"),[read,write]), - file:position(Fid, eof), - ok=io:format(Fid,"{\"no-rights\",\"no-rights\",\"no-rights\",\"\",\"\"}.\n", - []), - file:close(Fid). - - --define(tDescr_instance, [1,3,6,1,2,1,16,1,0]). -update_vacm(_Vsn, Dir) -> - {ok, Fid} = file:open(filename:join(Dir,"vacm.conf"),[read,write]), - file:position(Fid, eof), - ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"authMD5\",\"initial\"}.\n",[]), - ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"authSHA\",\"initial\"}.\n",[]), - ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"privDES\",\"initial\"}.\n",[]), - ok=io:format(Fid,"{vacmSecurityToGroup,usm,\"newUser\",\"initial\"}.\n",[]), - ok = io:format(Fid, "{vacmViewTreeFamily, \"internet\", " - "~w, excluded, null}.\n", [?tDescr_instance]), - file:close(Fid). - - -vacm_ver(v1) -> v1; -vacm_ver(v2) -> v2c; -vacm_ver(v3) -> usm. - - -write_community_conf(Dir, Confs) -> - {ok, Fid} = file:open(filename:join(Dir,"community.conf"),write), - ok = write_community_conf1(Fid, Confs), - file:close(Fid). - -write_community_conf1(_, []) -> - ok; -write_community_conf1(Fid, [{ComIdx, ComName, SecName, CtxName, TransTag}|Confs]) -> - ok = io:format(Fid, "{\"~s\", \"~s\", \"~s\", \"~s\", \"~s\"}.~n", - [ComIdx, ComName, SecName, CtxName, TransTag]), - write_community_conf1(Fid, Confs). - - -write_target_addr_conf(Dir, Confs) -> - {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), - ok = write_target_addr_conf1(Fid, Confs), - file:close(Fid). - - -write_target_addr_conf1(_, []) -> - ok; -write_target_addr_conf1(Fid, - [{Name, Ip, Port, Timeout, Retry, TagList, ParamName, - EngineId, TMask, MaxMsgSz}|Confs]) -> - ok = io:format(Fid, "{\"~s\", ~w, ~w, ~w, ~w, \"~s\", \"~s\", \"~s\", ~w, ~w}.~n", - [Name, Ip, Port, Timeout, Retry, TagList, ParamName, - EngineId, TMask, MaxMsgSz]), - write_target_addr_conf1(Fid, Confs). - -write_target_addr_conf(Dir, ManagerIp, UDP, Vsns) -> - {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), - lists:foreach(fun(Vsn) -> - ok = io:format(Fid, - "{\"~s\", ~w, ~w, 1500, 3, " - "\"std_trap\", \"~s\"}.~n", - [mk_ip(ManagerIp, Vsn), - ManagerIp, UDP, mk_param(Vsn)]), - case Vsn of - v1 -> ok; - v2 -> - ok = io:format(Fid, - "{\"~s.2\",~w,~w,1500,3, " - "\"std_inform\", \"~s\"}.~n", - [mk_ip(ManagerIp, Vsn), - ManagerIp, UDP, - mk_param(Vsn)]); - v3 -> - ok = io:format(Fid, - "{\"~s.3\",~w,~w,1500,3, " - "\"std_inform\", \"~s\", " - "\"mgrEngine\", [], 1024}.~n", - [mk_ip(ManagerIp, Vsn), - ManagerIp, UDP, - mk_param(Vsn)]) - end - end, - Vsns), - file:close(Fid). - -mk_param(v1) -> "target_v1"; -mk_param(v2) -> "target_v2"; -mk_param(v3) -> "target_v3". - -mk_ip([A,B,C,D], Vsn) -> - io_lib:format("~w.~w.~w.~w ~w", [A,B,C,D,Vsn]). - - -rewrite_target_addr_conf(Dir,NewPort) -> - TAFile = filename:join(Dir, "target_addr.conf"), - ?DBG("rewrite_target_addr_conf -> read target file info of address config file",[]), - case file:read_file_info(TAFile) of - {ok, _} -> ok; - {error, R} -> ?ERR("failure reading file info of " - "target address config file: ~p",[R]), - ok - end, - - ?line [TrapAddr|Addrs] = - snmp_conf:read(TAFile,fun(R) -> rewrite_target_addr_conf1(R) end), - - ?DBG("rewrite_target_addr_conf -> TrapAddr: ~p",[TrapAddr]), - - NewAddrs = [rewrite_target_addr_conf2(NewPort,TrapAddr)|Addrs], - - ?DBG("rewrite_target_addr_conf -> NewAddrs: ~p",[NewAddrs]), - - ?line ok = file:rename(filename:join(Dir,"target_addr.conf"), - filename:join(Dir,"target_addr.old")), - ?line {ok, Fid} = file:open(filename:join(Dir,"target_addr.conf"),write), - - ?line ok = rewrite_target_addr_conf3(Fid,NewAddrs), - - file:close(Fid). - -rewrite_target_addr_conf1(O) -> - {ok,O}. - -rewrite_target_addr_conf2(NewPort,{Name,Ip,_Port,Timeout,Retry, - "std_trap",EngineId}) -> - ?LOG("rewrite_target_addr_conf2 -> entry with std_trap",[]), - {Name,Ip,NewPort,Timeout,Retry,"std_trap",EngineId}; -rewrite_target_addr_conf2(_NewPort,O) -> - ?LOG("rewrite_target_addr_conf2 -> entry with " - "~n O: ~p",[O]), - O. - - -rewrite_target_addr_conf3(_,[]) -> ok; -rewrite_target_addr_conf3(Fid,[{Name,Ip,Port,Timeout,Retry, - ParamName,EngineId}|T]) -> - ?LOG("rewrite_target_addr_conf3 -> write(1) ~s",[ParamName]), - io:format(Fid, - "{\"~s\", " % Name - "~p, " % Ip - "~p, " % Port - "~p, " % Timeout - "~p, " % Retry - "\"~s\", " % ParamsName - "\"~s\"}.", % EngineId - [Name,Ip,Port,Timeout,Retry,ParamName,EngineId]), - rewrite_target_addr_conf3(Fid,T); -rewrite_target_addr_conf3(Fid,[{Name,Ip,Port,Timeout,Retry,TagList, - ParamName,EngineId,TMask,MMS}|T]) -> - ?LOG("rewrite_target_addr_conf3 -> write(2) ~s",[ParamName]), - io:format(Fid, - "{\"~s\", " % Name - "~p, " % Ip - "~p, " % Port - "~p, " % Timeout - "~p, " % Retry - "\"~s\", " % TagList - "\"~s\", " % ParamsName - "\"~s\"," % EngineId - "~p, " % TMask - "~p}.", % MMS - [Name,Ip,Port,Timeout,Retry,TagList,ParamName, - EngineId,TMask,MMS]), - rewrite_target_addr_conf3(Fid,T). - -reset_target_addr_conf(Dir) -> - ?line ok = file:rename(filename:join(Dir,"target_addr.old"), - filename:join(Dir,"target_addr.conf")). - -write_target_params_conf(Dir, Vsns) -> - {ok, Fid} = file:open(filename:join(Dir,"target_params.conf"),write), - lists:foreach(fun(Vsn) -> - MP = if Vsn == v1 -> v1; - Vsn == v2 -> v2c; - Vsn == v3 -> v3 - end, - SM = if Vsn == v1 -> v1; - Vsn == v2 -> v2c; - Vsn == v3 -> usm - end, - ok = io:format(Fid, "{\"target_~w\", ~w, ~w, " - "\"all-rights\", noAuthNoPriv}.~n", - [Vsn, MP, SM]) - end, - Vsns), - file:close(Fid). - -rewrite_target_params_conf(Dir, SecName, SecLevel) -> - ?line ok = file:rename(filename:join(Dir,"target_params.conf"), - filename:join(Dir,"target_params.old")), - ?line {ok, Fid} = file:open(filename:join(Dir,"target_params.conf"),write), - ?line ok = io:format(Fid, "{\"target_v3\", v3, usm, \"~s\", ~w}.~n", - [SecName, SecLevel]), - file:close(Fid). - -reset_target_params_conf(Dir) -> - ?line ok = file:rename(filename:join(Dir,"target_params.old"), - filename:join(Dir,"target_params.conf")). - -write_notify_conf(Dir) -> - {ok, Fid} = file:open(filename:join(Dir,"notify.conf"),write), - ok = io:format(Fid, "{\"standard trap\", \"std_trap\", trap}.~n", []), - ok = io:format(Fid, "{\"standard inform\", \"std_inform\",inform}.~n", []), - file:close(Fid). - -ver_to_trap_str([v1]) -> "v1"; -ver_to_trap_str([v2]) -> "v2"; -% default is to use the latest snmp version -ver_to_trap_str([v1,v2]) -> "v2". - - - -write_view_conf(Dir) -> - {ok, Fid} = file:open(a(Dir,"view.conf"),write), - ok = io:format(Fid, "{2, [1,3,6], included, null}.~n", []), - ok = io:format(Fid, "{2, ~w, excluded, null}.~n", [?tDescr_instance]), - file:close(Fid). - -a(A,B) -> lists:append(A,B). - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -copy_file(From, To) -> - {ok, Bin} = file:read_file(From), - ok = file:write_file(To, Bin). - - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -display_memory_usage() -> - Info = snmpa:info(snmp_master_agent), - TreeSize = lists_key1search(tree_size_bytes, Info), - ProcMem = lists_key1search(process_memory, Info), - MibDbSize = lists_key1search([db_memory,mib], Info), - NodeDbSize = lists_key1search([db_memory,node], Info), - TreeDbSize = lists_key1search([db_memory,tree], Info), - ?INF("Memory usage: " - "~n Tree size: ~p" - "~n Process memory size: ~p" - "~n Mib db size: ~p" - "~n Node db size: ~p" - "~n Tree db size: ~p", - [TreeSize, ProcMem, MibDbSize, NodeDbSize, TreeDbSize]). - -lists_key1search([], Res) -> - Res; -lists_key1search([Key|Keys], List) when atom(Key), list(List) -> - case lists:keysearch(Key, 1, List) of - {value, {Key, Val}} -> - lists_key1search(Keys, Val); - false -> - undefined - end; -lists_key1search(Key, List) when atom(Key) -> - case lists:keysearch(Key, 1, List) of - {value, {Key, Val}} -> - Val; - false -> - undefined - end. - - -regs() -> - lists:sort(registered()). -- cgit v1.2.3 From c27def2281391d4c70791f7406c1eee4f08c18da Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 21 Feb 2012 11:04:09 +0100 Subject: [snmp] Release notes and documentation for the new transport module Added the release notes and documentation for the new transport module, snmpm_net_if_mt. OTP-9876 --- lib/snmp/doc/src/notes.xml | 67 ++++++++++++++++++++++ lib/snmp/doc/src/snmp_config.xml | 12 ++-- lib/snmp/doc/src/snmp_manager_netif.xml | 43 +++++++------- .../doc/src/snmpm_network_interface_filter.xml | 9 +-- 4 files changed, 101 insertions(+), 30 deletions(-) (limited to 'lib') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 071b16a8f6..82c7deb467 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -33,6 +33,73 @@ +
+ SNMP Development Toolkit 4.22 +

Version 4.22 supports code replacement in runtime from/to + version 4.21.7 4.21.6 4.21.5, 4.21.4, 4.21.3, 4.21.2, 4.21.1 and 4.21.

+ +
+ Improvements and new features + + + + +

[manager] Introduced a new transport module, + snmpm_net_if_mt, + which handles all incomming and outgoing + traffic in newly created processes. The message/request is + processed and then the process exits.

+

Own Id: OTP-9876

+
+ +
+ +
+ +
+ Fixed Bugs and Malfunctions +

-

+ + +
+ +
+ Incompatibilities +

-

+ + + +
+ +
+ +
SNMP Development Toolkit 4.21.5

Version 4.21.5 supports code replacement in runtime from/to diff --git a/lib/snmp/doc/src/snmp_config.xml b/lib/snmp/doc/src/snmp_config.xml index fc8562b638..7431805489 100644 --- a/lib/snmp/doc/src/snmp_config.xml +++ b/lib/snmp/doc/src/snmp_config.xml @@ -523,17 +523,17 @@ {no_reuse, no_reuse()} | {filter, manager_net_if_filter_options()}

These options are actually specific to the used module. - The ones shown here are applicable to the default - manager_net_if_module().

+ The ones shown here are applicable to the default + manager_net_if_module().

For defaults see the options in manager_net_if_option().

]]> -

Module which handles the network interface part for the - SNMP manager. Must implement the - snmpm_network_interface behaviour.

-

Default is snmpm_net_if.

+

The module which handles the network interface part for the + SNMP manager. It must implement the + snmpm_network_interface behaviour.

+

Default is snmpm_net_if.

]]> diff --git a/lib/snmp/doc/src/snmp_manager_netif.xml b/lib/snmp/doc/src/snmp_manager_netif.xml index 2738ca76c1..169e20d10b 100644 --- a/lib/snmp/doc/src/snmp_manager_netif.xml +++ b/lib/snmp/doc/src/snmp_manager_netif.xml @@ -1,10 +1,10 @@ - +
- 20042009 + 20042012 Ericsson AB. All Rights Reserved. @@ -35,31 +35,34 @@ The Purpose of Manager Net if +

The Network Interface (Net if) process delivers SNMP PDUs to the - manager server, and receives SNMP PDUs from the manager server. - The most common behaviour of a Net if process is that is receives - request PDU from the manager server, encodes the PDU into bytes - and transmits the bytes onto the network to an agent. When the - reply from the agent is received by the Net if process, which it - decodes into an SNMP PDU, which it sends to the manager server. -

+ manager server, and receives SNMP PDUs from the manager server. + The most common behaviour of a Net if process is that is receives + request PDU from the manager server, encodes the PDU into bytes + and transmits the bytes onto the network to an agent. When the + reply from the agent is received by the Net if process, which it + decodes into an SNMP PDU, which it sends to the manager server.

+

However, that simple behaviour can be modified in numerous - ways. For example, the Net if process can apply some kind of - encrypting/decrypting scheme on the bytes. -

-

It is also possible to write your own Net if process. The default - Net if process is implemented in the module snmpm_net_if and - it uses UDP as the transport protocol. -

-

This section describes how to write a Net if process. -

+ ways. For example, the Net if process can apply some kind of + encrypting/decrypting scheme on the bytes.

+ +

The snmp application provides two different modules, + snmpm_net_if (the default) and snmpm_net_if_mt, + both uses the UDP as the transport protocol. The difference + between the two modules is that the latter is "multi-threaded", + i.e. for each message/request a new process is created that + process the message/request and then exits.

+ +

It is also possible to write your own Net if process, + this section describes how to write a Net if processdo that.

Mandatory Functions

A Net if process must implement the SNMP manager - network interface behaviour. -

+ network interface behaviour.

diff --git a/lib/snmp/doc/src/snmpm_network_interface_filter.xml b/lib/snmp/doc/src/snmpm_network_interface_filter.xml index ea1e183848..5f80cec94e 100644 --- a/lib/snmp/doc/src/snmpm_network_interface_filter.xml +++ b/lib/snmp/doc/src/snmpm_network_interface_filter.xml @@ -1,10 +1,10 @@ - +
- 20072009 + 20072012 Ericsson AB. All Rights Reserved. @@ -72,9 +72,10 @@

Note that the network interface filter is something which is used by the network interface implementation provided by the application - (snmpm_net_if). The default filter accepts all messages.

+ (snmpm_net_if and snmpm_net_if_mt). + The default filter accepts all messages.

A network interface filter can e.g. be used during testing or for load - regulation.

+ regulation.

-- cgit v1.2.3 From 6ac569677be3f56e8539394bbf3b7d29e62aa042 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 21 Feb 2012 12:21:29 +0100 Subject: [snmp] Tests for new manager net-if-mt module Updated manager test suite with groups that tests the new net-if module, snmpm_net_if_mt. Also fixed the suite, group and test-case init functions for a number of sub-suites. OTP-9876 --- lib/snmp/test/snmp_SUITE.erl | 47 ++++-- lib/snmp/test/snmp_agent_test.erl | 182 ++++++++++------------ lib/snmp/test/snmp_app_test.erl | 40 +++-- lib/snmp/test/snmp_compiler_test.erl | 61 +++++--- lib/snmp/test/snmp_manager_test.erl | 283 +++++++++++++++++++++-------------- lib/snmp/test/snmp_test_lib.erl | 87 ++++++++++- 6 files changed, 440 insertions(+), 260 deletions(-) (limited to 'lib') diff --git a/lib/snmp/test/snmp_SUITE.erl b/lib/snmp/test/snmp_SUITE.erl index b6d72da2fa..22b9c64588 100644 --- a/lib/snmp/test/snmp_SUITE.erl +++ b/lib/snmp/test/snmp_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2011. All Rights Reserved. +%% Copyright Ericsson AB 1997-2012. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -19,6 +19,8 @@ -module(snmp_SUITE). +-include("snmp_test_lib.hrl"). + -export([all/0, suite/0, groups/0, @@ -39,6 +41,21 @@ end_per_testcase(_Case, Config) when is_list(Config) -> Config. +init_per_suite(Config) when is_list(Config) -> + + ?DBG("init_per_suite -> entry with" + "~n Config: ~p", [Config]), + + Config. + +end_per_suite(Config) when is_list(Config) -> + + ?DBG("end_per_suite -> entry with" + "~n Config: ~p", [Config]), + + Config. + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Top test case @@ -53,7 +70,8 @@ all() -> {group, manager}]. groups() -> - [{app, [], [{group, app_test}, + [ + {app, [], [{group, app_test}, {group, appup_test}]}, {compiler, [], [{group, compiler_test}]}, {misc, [], [{group, conf_test}, @@ -66,6 +84,7 @@ groups() -> {manager, [], [{group, manager_config_test}, {group, manager_user_test}, {group, manager_test}]}, + {app_test, [], [{snmp_app_test, all}]}, {appup_test, [], [{snmp_appup_test, all}]}, {compiler_test, [], [{snmp_compiler_test, all}]}, @@ -78,17 +97,25 @@ groups() -> {agent_test, [], [{snmp_agent_test, all}]}, {manager_config_test, [], [{snmp_manager_config_test, all}]}, {manager_user_test, [], [{snmp_manager_user_test, all}]}, - {manager_test, [], [{snmp_manager_test, all}]}]. + {manager_test, [], [{snmp_manager_test, all}]} + ]. -init_per_suite(Config) -> - Config. -end_per_suite(_Config) -> - ok. +init_per_group(GroupName, Config0) -> -init_per_group(_GroupName, Config) -> - Config. + ?DBG("init_per_group -> entry with" + "~n GroupName: ~p" + "~n Config0: ~p", [GroupName, Config0]), + + %% Group name is not really the suite name + %% (but it is a good enough approximation), + %% but it does not matter since we only need + %% it to be unique. + snmp_test_lib:init_suite_top_dir(GroupName, Config0). + end_per_group(_GroupName, Config) -> - Config. + lists:keydelete(snmp_suite_top_dir, 1, Config). + + diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index c95346b5a6..d507ac648b 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2011. All Rights Reserved. +%% Copyright Ericsson AB 2003-2012. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -228,48 +228,79 @@ groups() -> } ]. -init_per_group(all_tcs, Config) -> - init_all(Config); -init_per_group(otp_7157, Config) -> - init_otp_7157(Config); -init_per_group(otp_4394, Config) -> - init_otp_4394(Config); -init_per_group(v2_inform, Config) -> - init_v2_inform(Config); -init_per_group(multiple_reqs_2, Config) -> - init_mul(Config); -init_per_group(multiple_reqs, Config) -> - init_mul(Config); -init_per_group(test_multi_threaded, Config) -> - init_mt(Config); -init_per_group(test_v3, Config) -> - init_v3(Config); -init_per_group(test_v1_v2, Config) -> - init_v1_v2(Config); -init_per_group(test_v2, Config) -> - init_v2(Config); -init_per_group(test_v1, Config) -> - init_v1(Config); -init_per_group(misc, Config) -> - init_misc(Config); -init_per_group(mib_storage_varm_mnesia, Config) -> - init_varm_mib_storage_mnesia(Config); -init_per_group(mib_storage_varm_dets, Config) -> - init_varm_mib_storage_dets(Config); -init_per_group(mib_storage_size_check_mnesia, Config) -> - init_size_check_msm(Config); -init_per_group(mib_storage_size_check_dets, Config) -> - init_size_check_msd(Config); -init_per_group(mib_storage_size_check_ets, Config) -> - init_size_check_mse(Config); -init_per_group(mib_storage_mnesia, Config) -> - init_mib_storage_mnesia(Config); -init_per_group(mib_storage_dets, Config) -> - init_mib_storage_dets(Config); -init_per_group(mib_storage_ets, Config) -> - init_mib_storage_ets(Config); -init_per_group(_GroupName, Config) -> - Config. + +init_per_suite(Config0) when is_list(Config0) -> + + ?DBG("init_per_suite -> entry with" + "~n Config0: ~p", [Config0]), + + Config1 = snmp_test_lib:init_suite_top_dir(?MODULE, Config0), + Config2 = snmp_test_lib:fix_data_dir(Config1), + + %% Mib-dirs + MibDir = snmp_test_lib:lookup(data_dir, Config2), + StdMibDir = filename:join([code:priv_dir(snmp), "mibs"]), + + Config3 = [{mib_dir, MibDir}, {std_mib_dir, StdMibDir} | Config2], + + ?DBG("init_per_suite -> end with" + "~n Config3: ~p", [Config3]), + + Config3. + +end_per_suite(Config) when is_list(Config) -> + + ?DBG("end_per_suite -> entry with" + "~n Config: ~p", [Config]), + + Config. + + +init_per_group(all_tcs = GroupName, Config) -> + init_all(snmp_test_lib:init_group_top_dir(GroupName, Config)); +init_per_group(otp_7157 = GroupName, Config) -> + init_otp_7157(snmp_test_lib:init_group_top_dir(GroupName, Config)); +init_per_group(otp_4394 = GroupName, Config) -> + init_otp_4394(snmp_test_lib:init_group_top_dir(GroupName, Config)); +init_per_group(v2_inform = GroupName, Config) -> + init_v2_inform(snmp_test_lib:init_group_top_dir(GroupName, Config)); +init_per_group(multiple_reqs_2 = GroupName, Config) -> + init_mul(snmp_test_lib:init_group_top_dir(GroupName, Config)); +init_per_group(multiple_reqs = GroupName, Config) -> + init_mul(snmp_test_lib:init_group_top_dir(GroupName, Config)); +init_per_group(test_multi_threaded = GroupName, Config) -> + init_mt(snmp_test_lib:init_group_top_dir(GroupName, Config)); +init_per_group(test_v3 = GroupName, Config) -> + init_v3(snmp_test_lib:init_group_top_dir(GroupName, Config)); +init_per_group(test_v1_v2 = GroupName, Config) -> + init_v1_v2(snmp_test_lib:init_group_top_dir(GroupName, Config)); +init_per_group(test_v2 = GroupName, Config) -> + init_v2(snmp_test_lib:init_group_top_dir(GroupName, Config)); +init_per_group(test_v1 = GroupName, Config) -> + init_v1(snmp_test_lib:init_group_top_dir(GroupName, Config)); +init_per_group(misc = GroupName, Config) -> + init_misc(snmp_test_lib:init_group_top_dir(GroupName, Config)); +init_per_group(mib_storage_varm_mnesia = GroupName, Config) -> + init_varm_mib_storage_mnesia(snmp_test_lib:init_group_top_dir(GroupName, + Config)); +init_per_group(mib_storage_varm_dets = GroupName, Config) -> + init_varm_mib_storage_dets(snmp_test_lib:init_group_top_dir(GroupName, + Config)); +init_per_group(mib_storage_size_check_mnesia = GroupName, Config) -> + init_size_check_msm(snmp_test_lib:init_group_top_dir(GroupName, Config)); +init_per_group(mib_storage_size_check_dets = GroupName, Config) -> + init_size_check_msd(snmp_test_lib:init_group_top_dir(GroupName, Config)); +init_per_group(mib_storage_size_check_ets = GroupName, Config) -> + init_size_check_mse(snmp_test_lib:init_group_top_dir(GroupName, Config)); +init_per_group(mib_storage_mnesia = GroupName, Config) -> + init_mib_storage_mnesia(snmp_test_lib:init_group_top_dir(GroupName, + Config)); +init_per_group(mib_storage_dets = GroupName, Config) -> + init_mib_storage_dets(snmp_test_lib:init_group_top_dir(GroupName, Config)); +init_per_group(mib_storage_ets = GroupName, Config) -> + init_mib_storage_ets(snmp_test_lib:init_group_top_dir(GroupName, Config)); +init_per_group(GroupName, Config) -> + snmp_test_lib:init_group_top_dir(GroupName, Config). end_per_group(all_tcs, Config) -> finish_all(Config); @@ -320,7 +351,7 @@ init_per_testcase(otp8395 = Case, Config) when is_list(Config) -> ?DBG("init_per_testcase -> entry with" "~n Case: ~p" "~n Config: ~p", [Case, Config]), - Config2 = init_per_testcase2(Case, init_per_suite(Config)), + Config2 = init_per_testcase2(Case, Config), otp8395({init, Config2}); init_per_testcase(otp_7157_test = _Case, Config) when is_list(Config) -> ?DBG("init_per_testcase -> entry with" @@ -358,65 +389,14 @@ end_per_testcase(_Case, Config) when is_list(Config) -> Config. -init_per_suite(Config) -> - ?DBG("init_per_suite -> entry with" - "~n Config: ~p", [Config]), - - %% Suite root dir for test suite - PrivDir = ?config(priv_dir, Config), - - %% Create top-directory for this sub-suite - SuiteTopDir = filename:join([PrivDir, ?MODULE]), - case file:make_dir(SuiteTopDir) of - ok -> - ok; - {error, eexist} -> - %% This can happen since this is not really a - %% suite-init function. - ok; - {error, Reason} -> - ?FAIL({failed_creating_suite_top_dir, SuiteTopDir, Reason}) - end, - - - %% -- - %% Fix config (data-dir is not correct): - %% - - Config1 = fix_data_dir(Config), - %% Config1 = Config, - - %% Mib-dirs - MibDir = ?config(data_dir, Config1), - StdMibDir = filename:join([code:priv_dir(snmp), "mibs"]), - - Config2 = [{suite_top_dir, SuiteTopDir}, - {mib_dir, MibDir}, - {std_mib_dir, StdMibDir} | Config1], - - ?DBG("init_per_suite -> done when" - "~n Config2: ~p", [Config2]), - Config2. - -%% end_per_suite(Config) -> -end_per_suite(Config) -> - Config. - -fix_data_dir(Config) -> - DataDir0 = ?config(data_dir, Config), - DataDir1 = filename:split(filename:absname(DataDir0)), - [_|DataDir2] = lists:reverse(DataDir1), - DataDir = filename:join(lists:reverse(DataDir2) ++ [?snmp_test_data]), - Config1 = lists:keydelete(data_dir, 1, Config), - [{data_dir, DataDir} | Config1]. - - init_per_testcase2(Case, Config) -> - SuiteToDir = ?config(suite_top_dir, Config), + %% SuiteToDir = ?config(snmp_suite_top_dir, Config), - %% Create top-directory for this test-case - CaseTopDir = filename:join([SuiteToDir, Case]), - ok = file:make_dir(CaseTopDir), + %% %% Create top-directory for this test-case + %% filename:join([SuiteToDir, Case]), + %% ok = file:make_dir(CaseTopDir), + + CaseTopDir = snmp_test_lib:init_testcase_top_dir(Case, Config), %% Create agent top-dir(s) AgentTopDir = filename:join([CaseTopDir, agent]), diff --git a/lib/snmp/test/snmp_app_test.erl b/lib/snmp/test/snmp_app_test.erl index bc62c8d530..825a232c99 100644 --- a/lib/snmp/test/snmp_app_test.erl +++ b/lib/snmp/test/snmp_app_test.erl @@ -23,8 +23,8 @@ -module(snmp_app_test). -export([ - all/0,groups/0,init_per_group/2,end_per_group/2, init_per_suite/1, - end_per_suite/1, + all/0, groups/0, init_per_group/2, end_per_group/2, + init_per_suite/1, end_per_suite/1, init_per_testcase/2, end_per_testcase/2, fields/1, @@ -52,33 +52,47 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% all() -> -Cases = [fields, modules, exportall, app_depend, - undef_funcs, {group, start_and_stop}], - Cases. + Cases = + [ + fields, + modules, + exportall, + app_depend, + undef_funcs, + {group, start_and_stop} + ], + Cases. groups() -> [{start_and_stop, [], - [start_and_stop_empty, start_and_stop_with_agent, - start_and_stop_with_manager, - start_and_stop_with_agent_and_manager, - start_epmty_and_then_agent_and_manager_and_stop, - start_with_agent_and_then_manager_and_stop, - start_with_manager_and_then_agent_and_stop]}]. + [start_and_stop_empty, + start_and_stop_with_agent, + start_and_stop_with_manager, + start_and_stop_with_agent_and_manager, + start_epmty_and_then_agent_and_manager_and_stop, + start_with_agent_and_then_manager_and_stop, + start_with_manager_and_then_agent_and_stop]}]. init_per_group(_GroupName, Config) -> - Config. + Config. end_per_group(_GroupName, Config) -> - Config. + Config. init_per_suite(Config) when is_list(Config) -> ?DISPLAY_SUITE_INFO(), + + %% Note that part of this stuff (the suite top dir creation) + %% may already be done (if we run the entire snmp suite). + PrivDir = ?config(priv_dir, Config), TopDir = filename:join(PrivDir, app), case file:make_dir(TopDir) of ok -> ok; + {error, eexist} -> + ok; Error -> fail({failed_creating_subsuite_top_dir, Error}) end, diff --git a/lib/snmp/test/snmp_compiler_test.erl b/lib/snmp/test/snmp_compiler_test.erl index 0a147130b0..f3a1e77322 100644 --- a/lib/snmp/test/snmp_compiler_test.erl +++ b/lib/snmp/test/snmp_compiler_test.erl @@ -40,6 +40,7 @@ all/0, groups/0, init_per_group/2, end_per_group/2, init_per_testcase/2, end_per_testcase/2, + init_per_suite/1, end_per_suite/1, description/1, oid_conflicts/1, @@ -74,19 +75,41 @@ %% External functions %%====================================================================== -init_per_testcase(_Case, Config) when is_list(Config) -> - Dir = ?config(priv_dir, Config), - DataDir = ?config(data_dir, Config), - [_|RL] = lists:reverse(filename:split(DataDir)), - MibDir = join(lists:reverse(["snmp_test_data"|RL])), - CompDir = join(Dir, "comp_dir/"), - ?line ok = file:make_dir(CompDir), - [{comp_dir, CompDir}, {mib_dir, MibDir} | Config]. +init_per_suite(Config0) when is_list(Config0) -> + + ?DBG("init_per_suite -> entry with" + "~n Config0: ~p", [Config0]), + + Config1 = snmp_test_lib:init_suite_top_dir(?MODULE, Config0), + Config2 = snmp_test_lib:fix_data_dir(Config1), + + %% Mib-dirs + %% data_dir is trashed by the test-server / common-test + %% so there is no point in fixing it... + MibDir = snmp_test_lib:lookup(data_dir, Config2), + StdMibDir = filename:join([code:priv_dir(snmp), "mibs"]), + + [{mib_dir, MibDir}, {std_mib_dir, StdMibDir} | Config2]. + +end_per_suite(Config) when is_list(Config) -> + + ?DBG("end_per_suite -> entry with" + "~n Config: ~p", [Config]), + + Config. + + +init_per_testcase(Case, Config) when is_list(Config) -> + + ?DBG("init_per_testcase -> entry with" + "~n Config: ~p", [Config]), + + CaseTopDir = snmp_test_lib:init_testcase_top_dir(Case, Config), + + [{case_top_dir, CaseTopDir} | Config]. end_per_testcase(_Case, Config) when is_list(Config) -> - CompDir = ?config(comp_dir, Config), - ?line ok = ?DEL_DIR(CompDir), - lists:keydelete(comp_dir, 1, Config). + Config. %%====================================================================== @@ -126,7 +149,7 @@ description(Config) when is_list(Config) -> put(tname,desc), p("starting with Config: ~p~n", [Config]), - Dir = ?config(comp_dir, Config), + Dir = ?config(case_top_dir, Config), Filename = join(Dir,"test"), MibSrcName = Filename ++ ".mib", MibBinName = Filename ++ ".bin", @@ -161,7 +184,7 @@ oid_conflicts(Config) when is_list(Config) -> put(tname,oid_conflicts), p("starting with Config: ~p~n", [Config]), - Dir = ?config(comp_dir, Config), + Dir = ?config(case_top_dir, Config), Mib = join(Dir,"TESTv2.mib"), ?line ok = write_oid_conflict_mib(Mib), ?line {error,compilation_failed} = @@ -278,7 +301,7 @@ warnings_as_errors(suite) -> warnings_as_errors(Config) when is_list(Config) -> put(tname,warnings_as_errors), p("starting with Config: ~p~n", [Config]), - Dir = ?config(comp_dir, Config), + Dir = ?config(case_top_dir, Config), MibDir = ?config(mib_dir, Config), MibFile = join(MibDir, "OTP8574-MIB.mib"), OutFile = join(Dir, "OTP8574-MIB.bin"), @@ -303,7 +326,7 @@ otp_6150(Config) when is_list(Config) -> put(tname,otp_6150), p("starting with Config: ~p~n", [Config]), - Dir = ?config(comp_dir, Config), + Dir = ?config(case_top_dir, Config), MibDir = ?config(mib_dir, Config), MibFile = join(MibDir, "ERICSSON-TOP-MIB.mib"), ?line {ok, Mib} = snmpc:compile(MibFile, [{outdir, Dir}, {verbosity, trace}]), @@ -319,7 +342,7 @@ otp_8574(Config) when is_list(Config) -> put(tname,otp_8574), p("starting with Config: ~p~n", [Config]), - Dir = ?config(comp_dir, Config), + Dir = ?config(case_top_dir, Config), MibDir = ?config(mib_dir, Config), MibFile = join(MibDir, "OTP8574-MIB.mib"), @@ -352,7 +375,7 @@ otp_8595(Config) when is_list(Config) -> put(tname,otp_8595), p("starting with Config: ~p~n", [Config]), - Dir = ?config(comp_dir, Config), + Dir = ?config(case_top_dir, Config), MibDir = ?config(mib_dir, Config), MibFile = join(MibDir, "OTP8595-MIB.mib"), ?line {ok, Mib} = @@ -546,8 +569,8 @@ check_desc(Desc1, Desc2) -> exit({'description not equal', Desc1, Desc2}). -join(Comp) -> - filename:join(Comp). +%% join(Comp) -> +%% filename:join(Comp). join(A,B) -> filename:join(A,B). diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index 5dc5799ddf..c374a2f0a6 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -49,6 +49,8 @@ init_per_group/2, end_per_group/2, init_per_testcase/2, end_per_testcase/2, + init_per_suite/1, end_per_suite/1, + simple_start_and_stop1/1, simple_start_and_stop2/1, @@ -146,48 +148,29 @@ %% External functions %%====================================================================== -which_group(Config) -> - case ?config(tc_group_properties, Config) of - undefined -> - %% Properties, if they exist, is a list - ignore; - GroupProps -> - GroupName = ?config(name, GroupProps), - %% tc_group_path is a list of parent groups... - GroupPaths = ?config(tc_group_path, Config), - {GroupName, [?config(name, GPs) || GPs <- GroupPaths]} - end. +init_per_suite(Config0) when is_list(Config0) -> + + ?DBG("init_per_suite -> entry with" + "~n Config0: ~p", [Config0]), + + Config1 = snmp_test_lib:init_suite_top_dir(?MODULE, Config0), + Config2 = snmp_test_lib:fix_data_dir(Config1), + + %% Mib-dirs + %% data_dir is trashed by the test-server / common-test + %% so there is no point in fixing it... + MibDir = snmp_test_lib:lookup(data_dir, Config2), + StdMibDir = filename:join([code:priv_dir(snmp), "mibs"]), + + [{mib_dir, MibDir}, {std_mib_dir, StdMibDir} | Config2]. + +end_per_suite(Config) when is_list(Config) -> + + ?DBG("end_per_suite -> entry with" + "~n Config: ~p", [Config]), + + Config. -mk_group_dir(GPRoot, [], Group) -> - ?DBG("mk_group_dir -> entry with: " - "~n GPRoot: ~p" - "~n Group: ~p", [GPRoot, Group]), - GroupDir = filename:join(GPRoot, Group), - case file:make_dir(GroupDir) of - ok -> - GroupDir; - {error, eexist} -> - GroupDir; - Error -> - ?FAIL({failed_creating_group_dir, Error}) - end; -mk_group_dir(GPRoot, [Dir|Dirs], Group) -> - ?DBG("mk_group_dir -> entry with: " - "~n GPRoot: ~p" - "~n Dir: ~p" - "~n Group: ~p", [GPRoot, Dir, Group]), - GPDir = filename:join(GPRoot, Dir), - case file:make_dir(GPDir) of - ok -> - ok; - {error, eexist} -> - ok; - Error -> - ?FAIL({failed_creating_group_path_dir, Error}) - end, - mk_group_dir(GPDir, Dirs, Group). - - init_per_testcase(Case, Config) when is_list(Config) -> io:format(user, "~n~n*** INIT ~w:~w ***~n~n", [?MODULE,Case]), @@ -196,40 +179,8 @@ init_per_testcase(Case, Config) when is_list(Config) -> init_per_testcase2(Case, Config) -> ?DBG("init_per_testcase2 -> ~p", [erlang:nodes()]), - %% Fix a correct data dir (points to the wrong location): - DataDir0 = ?config(data_dir, Config), - DataDir1 = filename:split(filename:absname(DataDir0)), - [_|DataDir2] = lists:reverse(DataDir1), - DataDir = filename:join(lists:reverse(DataDir2) ++ [?snmp_test_data]), - - PrivDir = ?config(priv_dir, Config), - - TopDir = filename:join(PrivDir, ?MODULE), - ?DBG("init_per_testcase2 -> try create top dir: ~n~p", [TopDir]), - case file:make_dir(TopDir) of - ok -> - ok; - {error, eexist} -> - ok; - ErrorS -> - ?FAIL({failed_creating_subsuite_top_dir, ErrorS}) - end, + CaseTopDir = snmp_test_lib:init_testcase_top_dir(Case, Config), - CaseRootDir = - case which_group(Config) of - {Group, GroupPath} -> - ?DBG("init_per_testcase2 -> try create group dir with: " - "~n Group: ~p" - "~n GroupPath: ~p", [Group, GroupPath]), - mk_group_dir(TopDir, GroupPath, Group); - _ -> - TopDir - end, - - CaseTopDir = filename:join(CaseRootDir, Case), - ?DBG("init_per_testcase2 -> try create case top dir: ~n~p", [CaseTopDir]), - ?line ok = file:make_dir(CaseTopDir), - %% -- Manager dirs -- MgrTopDir = filename:join(CaseTopDir, "manager/"), ?DBG("init_per_testcase2 -> try create manager top dir: ~n~p", @@ -258,11 +209,9 @@ init_per_testcase2(Case, Config) -> AgLogDir = filename:join(AgTopDir, "log/"), ?line ok = file:make_dir(AgLogDir), - Conf = [{snmp_data_dir, DataDir}, - {watchdog, ?WD_START(?MINS(5))}, + Conf = [{watchdog, ?WD_START(?MINS(5))}, {ip, ?LOCALHOST()}, - {top_dir, TopDir}, - {case_root_dir, CaseRootDir}, + {case_top_dir, CaseTopDir}, {agent_dir, AgTopDir}, {agent_conf_dir, AgConfDir}, {agent_db_dir, AgDbDir}, @@ -451,7 +400,7 @@ all() -> {group, event_tests}, {group, event_tests_mt}, discovery, - {group, tickets} + {group, tickets} ]. groups() -> @@ -589,15 +538,21 @@ groups() -> } ]. -init_per_group(request_tests_mt = _GroupName, Config) -> - [{manager_net_if_module, snmpm_net_if_mt} | Config]; -init_per_group(event_tests_mt = _GroupName, Config) -> - [{manager_net_if_module, snmpm_net_if_mt} | Config]; -init_per_group(_GroupName, Config) -> - Config. +init_per_group(request_tests_mt = GroupName, Config) -> + snmp_test_lib:init_group_top_dir( + GroupName, + [{manager_net_if_module, snmpm_net_if_mt} | Config]); +init_per_group(event_tests_mt = GroupName, Config) -> + snmp_test_lib:init_group_top_dir( + GroupName, + [{manager_net_if_module, snmpm_net_if_mt} | Config]); +init_per_group(GroupName, Config) -> + snmp_test_lib:init_group_top_dir(GroupName, Config). + end_per_group(_GroupName, Config) -> - Config. + %% Do we really need to do this? + lists:keydelete(snmp_group_top_dir, 1, Config). %%====================================================================== @@ -1657,6 +1612,11 @@ simple_sync_get1(Config) when is_list(Config) -> ?line ok = mgr_user_load_mib(Node, std_mib()), Oids2 = [[sysObjectID, 0], [sysDescr, 0], [sysUpTime, 0]], ?line ok = do_simple_sync_get(Node, Addr, Port, Oids2), + + p("Display log"), + display_log(Config), + + p("done"), ok. do_simple_sync_get(Node, Addr, Port, Oids) -> @@ -1664,7 +1624,7 @@ do_simple_sync_get(Node, Addr, Port, Oids) -> ?DBG("~n Reply: ~p" "~n Rem: ~w", [Reply, Rem]), - + %% verify that the operation actually worked: %% The order should be the same, so no need to seach ?line ok = case Reply of @@ -1698,7 +1658,9 @@ simple_sync_get2(suite) -> []; simple_sync_get2(Config) when is_list(Config) -> process_flag(trap_exit, true), put(tname, ssg2), - do_simple_sync_get2(Config). + do_simple_sync_get2(Config), + display_log(Config), + ok. do_simple_sync_get2(Config) -> Get = fun(Node, TargetName, Oids) -> @@ -1763,7 +1725,9 @@ simple_sync_get3(suite) -> []; simple_sync_get3(Config) when is_list(Config) -> process_flag(trap_exit, true), put(tname, ssg3), - do_simple_sync_get3(Config). + do_simple_sync_get3(Config), + display_log(Config), + ok. do_simple_sync_get3(Config) -> Self = self(), @@ -1789,8 +1753,8 @@ do_simple_sync_get3(Config) -> %%====================================================================== -simple_async_get1(doc) -> ["Simple (async) get-request - " - "Old style (Addr & Port)"]; +simple_async_get1(doc) -> + ["Simple (async) get-request - Old style (Addr & Port)"]; simple_async_get1(suite) -> []; simple_async_get1(Config) when is_list(Config) -> process_flag(trap_exit, true), @@ -1852,6 +1816,7 @@ simple_async_get1(Config) when is_list(Config) -> p("manager info when ending test: ~n~p", [mgr_info(MgrNode)]), p("agent info when ending test: ~n~p", [agent_info(AgentNode)]), + display_log(Config), ok. async_g_exec1(Node, Addr, Port, Oids) -> @@ -1902,7 +1867,9 @@ simple_async_get2(Config) when is_list(Config) -> TargetName = ?config(manager_agent_target_name, Config), Get = fun(Oids) -> async_g_exec2(MgrNode, TargetName, Oids) end, PostVerify = fun(Res) -> Res end, - do_simple_async_sync_get2(Config, MgrNode, AgentNode, Get, PostVerify). + do_simple_async_sync_get2(Config, MgrNode, AgentNode, Get, PostVerify), + display_log(Config), + ok. do_simple_async_sync_get2(Config, MgrNode, AgentNode, Get, PostVerify) -> ?line ok = mgr_user_load_mib(MgrNode, std_mib()), @@ -1991,7 +1958,9 @@ simple_async_get3(Config) when is_list(Config) -> PostVerify = fun(ok) -> receive Msg -> ok end; (Error) -> Error end, - do_simple_async_sync_get2(Config, MgrNode, AgentNode, Get, PostVerify). + do_simple_async_sync_get2(Config, MgrNode, AgentNode, Get, PostVerify), + display_log(Config), + ok. async_g_exec3(Node, TargetName, Oids, SendOpts) -> mgr_user_async_get2(Node, TargetName, Oids, SendOpts). @@ -2085,6 +2054,8 @@ simple_sync_get_next1(Config) when is_list(Config) -> end, ?line ok = do_simple_get_next(8, MgrNode, Addr, Port, Oids08, VF08), + + display_log(Config), ok. @@ -2148,7 +2119,10 @@ simple_sync_get_next2(Config) when is_list(Config) -> mgr_user_sync_get_next(Node, TargetName, Oids) end, PostVerify = fun(Res) -> Res end, - do_simple_sync_get_next2(Config, GetNext, PostVerify). + do_simple_sync_get_next2(Config, GetNext, PostVerify), + display_log(Config), + ok. + do_simple_sync_get_next2(Config, GetNext, PostVerify) when is_function(GetNext, 3) andalso is_function(PostVerify, 1) -> @@ -2279,7 +2253,9 @@ simple_sync_get_next3(Config) when is_list(Config) -> PostVerify = fun(ok) -> receive Msg -> ok end; (Error) -> Error end, - do_simple_sync_get_next2(Config, GetNext, PostVerify). + do_simple_sync_get_next2(Config, GetNext, PostVerify), + display_log(Config), + ok. %%====================================================================== @@ -2372,6 +2348,7 @@ simple_async_get_next1(Config) when is_list(Config) -> p("manager info when ending test: ~n~p", [mgr_info(MgrNode)]), p("agent info when ending test: ~n~p", [agent_info(AgentNode)]), + display_log(Config), ok. @@ -2401,7 +2378,9 @@ simple_async_get_next2(Config) when is_list(Config) -> async_gn_exec2(MgrNode, TargetName, Oids) end, PostVerify = fun(Res) -> Res end, - do_simple_async_get_next2(MgrNode, AgentNode, GetNext, PostVerify). + do_simple_async_get_next2(MgrNode, AgentNode, GetNext, PostVerify), + display_log(Config), + ok. do_simple_async_get_next2(MgrNode, AgentNode, GetNext, PostVerify) when is_function(GetNext, 1) andalso is_function(PostVerify, 1) -> @@ -2523,7 +2502,9 @@ simple_async_get_next3(Config) when is_list(Config) -> (Error) -> Error end, - do_simple_async_get_next2(MgrNode, AgentNode, GetNext, PostVerify). + do_simple_async_get_next2(MgrNode, AgentNode, GetNext, PostVerify), + display_log(Config), + ok. async_gn_exec3(Node, TargetName, Oids, SendOpts) -> mgr_user_async_get_next2(Node, TargetName, Oids, SendOpts). @@ -2561,6 +2542,8 @@ simple_sync_set1(Config) when is_list(Config) -> {[sysLocation, 0], Val22} ], ?line ok = do_simple_set1(Node, Addr, Port, VAVs2), + + display_log(Config), ok. do_simple_set1(Node, Addr, Port, VAVs) -> @@ -2613,7 +2596,9 @@ simple_sync_set2(Config) when is_list(Config) -> end, PostVerify = fun() -> ok end, - do_simple_sync_set2(Config, Set, PostVerify). + do_simple_sync_set2(Config, Set, PostVerify), + display_log(Config), + ok. do_simple_sync_set2(Config, Set, PostVerify) when is_function(Set, 3) andalso is_function(PostVerify, 0) -> @@ -2690,7 +2675,9 @@ simple_sync_set3(Config) when is_list(Config) -> end, PostVerify = fun() -> receive Msg -> ok end end, - do_simple_sync_set2(Config, Set, PostVerify). + do_simple_sync_set2(Config, Set, PostVerify), + display_log(Config), + ok. %%====================================================================== @@ -2749,6 +2736,7 @@ simple_async_set1(Config) when is_list(Config) -> p("manager info when ending test: ~n~p", [mgr_info(MgrNode)]), p("agent info when ending test: ~n~p", [agent_info(AgentNode)]), + display_log(Config), ok. @@ -2810,7 +2798,9 @@ simple_async_set2(Config) when is_list(Config) -> end, PostVerify = fun(Res) -> Res end, - do_simple_async_set2(MgrNode, AgentNode, Set, PostVerify). + do_simple_async_set2(MgrNode, AgentNode, Set, PostVerify), + display_log(Config), + ok. do_simple_async_set2(MgrNode, AgentNode, Set, PostVerify) -> Requests = @@ -2892,7 +2882,9 @@ simple_async_set3(Config) when is_list(Config) -> (Res) -> Res end, - do_simple_async_set2(MgrNode, AgentNode, Set, PostVerify). + do_simple_async_set2(MgrNode, AgentNode, Set, PostVerify), + display_log(Config), + ok. async_s_exec3(Node, TargetName, VAVs, SendOpts) -> mgr_user_async_set2(Node, TargetName, VAVs, SendOpts). @@ -3018,6 +3010,7 @@ simple_sync_get_bulk1(Config) when is_list(Config) -> 0, 2, [[TCnt2, 1]], VF11), + display_log(Config), ok. fl(L) -> @@ -3090,7 +3083,9 @@ simple_sync_get_bulk2(Config) when is_list(Config) -> end, PostVerify = fun(Res) -> Res end, - do_simple_sync_get_bulk2(Config, MgrNode, AgentNode, GetBulk, PostVerify). + do_simple_sync_get_bulk2(Config, MgrNode, AgentNode, GetBulk, PostVerify), + display_log(Config), + ok. do_simple_sync_get_bulk2(Config, MgrNode, AgentNode, GetBulk, PostVerify) -> %% -- 1 -- @@ -3255,7 +3250,9 @@ simple_sync_get_bulk3(Config) when is_list(Config) -> (Res) -> Res end, - do_simple_sync_get_bulk2(Config, MgrNode, AgentNode, GetBulk, PostVerify). + do_simple_sync_get_bulk2(Config, MgrNode, AgentNode, GetBulk, PostVerify), + display_log(Config), + ok. %%====================================================================== @@ -3394,6 +3391,7 @@ simple_async_get_bulk1(Config) when is_list(Config) -> p("manager info when ending test: ~n~p", [mgr_info(MgrNode)]), p("agent info when ending test: ~n~p", [agent_info(AgentNode)]), + display_log(Config), ok. @@ -3426,7 +3424,9 @@ simple_async_get_bulk2(Config) when is_list(Config) -> end, PostVerify = fun(Res) -> Res end, - do_simple_async_get_bulk2(MgrNode, AgentNode, GetBulk, PostVerify). + do_simple_async_get_bulk2(MgrNode, AgentNode, GetBulk, PostVerify), + display_log(Config), + ok. do_simple_async_get_bulk2(MgrNode, AgentNode, GetBulk, PostVerify) -> %% We re-use the verification functions from the ssgb test-case @@ -3591,7 +3591,9 @@ simple_async_get_bulk3(Config) when is_list(Config) -> (Res) -> Res end, - do_simple_async_get_bulk2(MgrNode, AgentNode, GetBulk, PostVerify). + do_simple_async_get_bulk2(MgrNode, AgentNode, GetBulk, PostVerify), + display_log(Config), + ok. async_gb_exec3(Node, TargetName, {NR, MR, Oids}, SendOpts) -> mgr_user_async_get_bulk2(Node, TargetName, NR, MR, Oids, SendOpts). @@ -3783,6 +3785,7 @@ misc_async1(Config) when is_list(Config) -> p("manager info when ending test: ~n~p", [mgr_info(MgrNode)]), p("agent info when ending test: ~n~p", [agent_info(AgentNode)]), + display_log(Config), ok. @@ -3971,6 +3974,7 @@ misc_async2(Config) when is_list(Config) -> p("manager info when ending test: ~n~p", [mgr_info(MgrNode)]), p("agent info when ending test: ~n~p", [agent_info(AgentNode)]), + display_log(Config), ok. @@ -4185,7 +4189,9 @@ trap1(Config) when is_list(Config) -> {5, "Manager and agent info after test completion", Cmd1} ], - command_handler(Commands). + command_handler(Commands), + display_log(Config), + ok. %%====================================================================== @@ -4376,7 +4382,9 @@ trap2(Config) when is_list(Config) -> {7, "Manager and agent info after test completion", Cmd1} ], - command_handler(Commands). + command_handler(Commands), + display_log(Config), + ok. %%====================================================================== @@ -4501,7 +4509,9 @@ inform1(Config) when is_list(Config) -> {6, "Manager and agent info after test completion", Cmd1} ], - command_handler(Commands). + command_handler(Commands), + display_log(Config), + ok. %%====================================================================== @@ -4671,7 +4681,9 @@ inform2(Config) when is_list(Config) -> {8, "Manager and agent info after test completion", Cmd1} ], - command_handler(Commands). + command_handler(Commands), + display_log(Config), + ok. %%====================================================================== @@ -4805,7 +4817,9 @@ inform3(Config) when is_list(Config) -> {9, "Manager and agent info after test completion", Cmd1} ], - command_handler(Commands). + command_handler(Commands), + display_log(Config), + ok. %%====================================================================== @@ -4921,7 +4935,9 @@ inform4(Config) when is_list(Config) -> {6, "Manager and agent info after test completion", Cmd1} ], - command_handler(Commands). + command_handler(Commands), + display_log(Config), + ok. %%====================================================================== @@ -5009,7 +5025,10 @@ inform_swarm(Config) when is_list(Config) -> {5, "Manager and agent info after test completion", Cmd1} ], - command_handler(Commands). + command_handler(Commands), + display_log(Config), + ok. + inform_swarm_collector(N) -> inform_swarm_collector(N, 0, 0, 0, 10000). @@ -5313,8 +5332,8 @@ init_agent(Config) -> %% -- %% Retrieve some dir's %% - Dir = ?config(top_dir, Config), - DataDir = ?config(data_dir, Config), + Dir = ?config(agent_dir, Config), + MibDir = ?config(mib_dir, Config), %% -- %% Start node @@ -5345,7 +5364,7 @@ init_agent(Config) -> ?line ok = write_agent_config(Vsns, Config), Conf = [{agent_node, Node}, - {mib_dir, DataDir} | Config], + {mib_dir, MibDir} | Config], %% %% Start the agent @@ -6111,6 +6130,38 @@ write_conf_file(Dir, File, Str) -> file:close(Fd). +%% ------ + +display_log(Config) -> + case lists:keysearch(manager_log_dir, 1, Config) of + {value, {_, Dir}} -> + case lists:keysearch(manager_node, 1, Config) of + {value, {_, Node}} -> + LogDir = Dir, + Mibs = [], + OutFile = j(LogDir, "snmpm_log.txt"), + p("~n" + "=========================" + " < Audit Trail Log > " + "=========================" + "~n"), + rcall(Node, snmpm, log_to_txt, [LogDir, Mibs, OutFile]), + rcall(Node, snmpm, log_to_io, [LogDir, Mibs]), + p("~n" + "=========================" + " < / Audit Trail Log > " + "=========================" + "~n"); + false -> + p("display_log -> no manager node found"), + ok + end; + false -> + p("display_log -> no manager log dir found"), + ok + end. + + %% ------ test2_mib(Config) -> @@ -6129,7 +6180,7 @@ snmpv2_mib() -> j(mib_dir(), "SNMPv2-MIB.bin"). test_mib_dir(Config) -> - ?config(snmp_data_dir, Config). + ?config(mib_dir, Config). mib_dir() -> j(code:priv_dir(snmp), "mibs"). diff --git a/lib/snmp/test/snmp_test_lib.erl b/lib/snmp/test/snmp_test_lib.erl index e4d58a1253..f247cfa1ae 100644 --- a/lib/snmp/test/snmp_test_lib.erl +++ b/lib/snmp/test/snmp_test_lib.erl @@ -25,7 +25,10 @@ -export([hostname/0, hostname/1, localhost/0, os_type/0, sz/1, display_suite_info/1]). -export([non_pc_tc_maybe_skip/4, os_based_skip/1]). --export([replace_config/3, set_config/3, get_config/2, get_config/3]). +-export([fix_data_dir/1, + init_suite_top_dir/2, init_group_top_dir/2, init_testcase_top_dir/2, + lookup/2, + replace_config/3, set_config/3, get_config/2, get_config/3]). -export([fail/3, skip/3]). -export([millis/0, millis_diff/2, hours/1, minutes/1, seconds/1, sleep/1]). -export([flush_mqueue/0, trap_exit/0, trap_exit/1]). @@ -198,6 +201,85 @@ os_based_skip(_Crap) -> %% Test suite utility functions %% +fix_data_dir(Config) -> + DataDir0 = lookup(data_dir, Config), + DataDir1 = filename:split(filename:absname(DataDir0)), + [_|DataDir2] = lists:reverse(DataDir1), + DataDir = filename:join(lists:reverse(DataDir2) ++ [?snmp_test_data]), + Config1 = lists:keydelete(data_dir, 1, Config), + [{data_dir, DataDir} | Config1]. + + +init_suite_top_dir(Suite, Config0) -> + Dir = lookup(priv_dir, Config0), + SuiteTopDir = filename:join(Dir, Suite), + case file:make_dir(SuiteTopDir) of + ok -> + ok; + {error, eexist} -> + ok; + {error, Reason} -> + fail({failed_creating_suite_top_dir, SuiteTopDir, Reason}, + ?MODULE, ?LINE) + end, + + %% This is just in case... + Config1 = lists:keydelete(snmp_group_top_dir, 1, Config0), + Config2 = lists:keydelete(snmp_suite_top_dir, 1, Config1), + [{snmp_suite_top_dir, SuiteTopDir} | Config2]. + + +init_group_top_dir(GroupName, Config) -> + case lists:keysearch(snmp_group_top_dir, 1, Config) of + {value, {_Key, Dir}} -> + %% This is a sub-group, so create our dir within Dir + GroupTopDir = filename:join(Dir, GroupName), + case file:make_dir(GroupTopDir) of + ok -> + ok; + {error, Reason} -> + fail({failed_creating_group_top_dir, GroupTopDir, Reason}, + ?MODULE, ?LINE) + end, + [{snmp_group_top_dir, GroupTopDir} | Config]; + + _ -> + case lists:keysearch(snmp_suite_top_dir, 1, Config) of + {value, {_Key, Dir}} -> + GroupTopDir = filename:join(Dir, GroupName), + case file:make_dir(GroupTopDir) of + ok -> + ok; + {error, Reason} -> + fail({failed_creating_group_top_dir, + GroupTopDir, Reason}, + ?MODULE, ?LINE) + end, + [{snmp_group_top_dir, GroupTopDir} | Config]; + _ -> + fail(could_not_find_suite_top_dir, ?MODULE, ?LINE) + end + end. + + +init_testcase_top_dir(Case, Config) -> + case lists:keysearch(snmp_group_top_dir, 1, Config) of + {value, {_Key, Dir}} -> + CaseTopDir = filename:join(Dir, Case), + ok = file:make_dir(CaseTopDir), + CaseTopDir; + false -> + case lists:keysearch(snmp_suite_top_dir, 1, Config) of + {value, {_Key, Dir}} -> + CaseTopDir = filename:join(Dir, Case), + ok = file:make_dir(CaseTopDir), + CaseTopDir; + false -> + fail(failed_creating_case_top_dir, ?MODULE, ?LINE) + end + end. + + replace_config(Key, Config, NewValue) -> lists:keyreplace(Key, 1, Config, {Key, NewValue}). @@ -220,6 +302,9 @@ get_config(Key,C,Default) -> Default end. +lookup(Key, Config) -> + {value, {Key, Value}} = lists:keysearch(Key, 1, Config), + Value. fail(Reason, Mod, Line) -> exit({suite_failed, Reason, Mod, Line}). -- cgit v1.2.3 From b5465108cd1456984872e2d04a51af021b4fe110 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 21 Feb 2012 12:25:34 +0100 Subject: [snmp] More documentaion regarding the new manager net-if module OTP-9876 --- lib/snmp/doc/src/snmp_app.xml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/snmp/doc/src/snmp_app.xml b/lib/snmp/doc/src/snmp_app.xml index 694e619da1..5f8672423f 100644 --- a/lib/snmp/doc/src/snmp_app.xml +++ b/lib/snmp/doc/src/snmp_app.xml @@ -1,4 +1,4 @@ - + @@ -35,8 +35,8 @@ The SNMP Application

This chapter describes the snmp - application in OTP. The SNMP application provides the following - services:

+ application in OTP. The SNMP application provides the following + services:

a multilingual extensible SNMP agent

@@ -525,15 +525,15 @@ {no_reuse, no_reuse()} | {filter, manager_net_if_filter_options()}

These options are actually specific to the used module. - The ones shown here are applicable to the default - manager_net_if_module().

+ The ones shown here are applicable to the default + manager_net_if_module().

For defaults see the options in manager_net_if_option().

]]> -

Module which handles the network interface part for the - SNMP manager. Must implement the +

The module which handles the network interface part for the + SNMP manager. It must implement the snmpm_network_interface behaviour.

Default is snmpm_net_if.

-- cgit v1.2.3 From f9f7bde8524e9863b689275691f4b4711e30d0ff Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 22 Feb 2012 14:16:48 +0100 Subject: [snmp] Add log_to_io function for both manager and agent Add a log_to_io Audit Trail Log converter function for both the manager (snmpm) and agent (snmpa). Also fixed the converter functions in the logger module, snmp_log, which previously sometimes did not work properly (re-open an already open log with different properties). OTP-9940 --- lib/snmp/doc/src/notes.xml | 9 ++++++ lib/snmp/doc/src/snmp.xml | 28 ++++++++++++++-- lib/snmp/doc/src/snmpa.xml | 34 +++++++++++++++++++- lib/snmp/doc/src/snmpm.xml | 34 +++++++++++++++++++- lib/snmp/src/agent/snmpa.erl | 26 +++++++++++++-- lib/snmp/src/app/snmp.erl | 7 ++++ lib/snmp/src/manager/snmpm.erl | 25 ++++++++++++++- lib/snmp/src/misc/snmp_log.erl | 72 ++++++++++++++++++++---------------------- 8 files changed, 190 insertions(+), 45 deletions(-) (limited to 'lib') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 82c7deb467..e7fb4e2287 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -45,6 +45,15 @@ --> + +

Added the log_to_io audit-trail-log converter function to the + api modules of both the + manager + and + agent.

+

Own Id: OTP-9940

+
+

[manager] Introduced a new transport module, snmpm_net_if_mt, diff --git a/lib/snmp/doc/src/snmp.xml b/lib/snmp/doc/src/snmp.xml index af0833f005..3e6610891f 100644 --- a/lib/snmp/doc/src/snmp.xml +++ b/lib/snmp/doc/src/snmp.xml @@ -1,10 +1,10 @@ - +

- 19962009 + 19962012 Ericsson AB. All Rights Reserved. @@ -391,6 +391,30 @@ version of the protocol data unit. There is a new line between Vsn and PDU.

+ + + + + + log_to_io(LogDir, Mibs, LogName, LogFile) -> ok | {error, Reason} + log_to_io(LogDir, Mibs, LogName, LogFile, Start) -> ok | {error, Reason} + log_to_io(LogDir, Mibs, LogName, LogFile, Start, Stop) -> ok | {error, Reason} + Convert an Audit Trail Log to text format + + LogDir = string() + Mibs = [MibName] + MibName = string() + LogName = string() + LogFile = string() + Start = Stop = null | datetime() | {local_time,datetime()} | {universal_time,datetime()} + Reason = term() + + +

Converts an Audit Trail Log to a readable format and + prints it on stdio. See + log_to_txt + above for more info.

+
diff --git a/lib/snmp/doc/src/snmpa.xml b/lib/snmp/doc/src/snmpa.xml index 27d89ea4e3..9984a10fea 100644 --- a/lib/snmp/doc/src/snmpa.xml +++ b/lib/snmp/doc/src/snmpa.xml @@ -4,7 +4,7 @@
- 20042011 + 20042012 Ericsson AB. All Rights Reserved. @@ -495,6 +495,7 @@ notification_delivery_info() = #snmpa_notification_delivery_info{} + log_to_txt(LogDir) log_to_txt(LogDir, Mibs) log_to_txt(LogDir, Mibs, OutFile) -> ok | {error, Reason} log_to_txt(LogDir, Mibs, OutFile, LogName) -> ok | {error, Reason} @@ -522,6 +523,37 @@ notification_delivery_info() = #snmpa_notification_delivery_info{} See snmp:log_to_txt for more info.

+ + +
+ + + log_to_io(LogDir) -> ok | {error, Reason} + log_to_io(LogDir, Mibs) -> ok | {error, Reason} + log_to_io(LogDir, Mibs, LogName) -> ok | {error, Reason} + log_to_io(LogDir, Mibs, LogName, LogFile) -> ok | {error, Reason} + log_to_io(LogDir, Mibs, LogName, LogFile, Start) -> ok | {error, Reason} + log_to_io(LogDir, Mibs, LogName, LogFile, Start, Stop) -> ok | {error, Reason} + Convert an Audit Trail Log to text format + + LogDir = string() + Mibs = [MibName] + MibName = string() + LogName = string() + LogFile = string() + Start = Stop = null | datetime() | {local_time,datetime()} | {universal_time,datetime()} + Reason = disk_log_open_error() | file_open_error() | term() + disk_log_open_error() = {LogName, term()} + file_open_error() = {OutFile, term()} + + +

Converts an Audit Trail Log to a readable format and + prints it on stdio. + LogName defaults to "snmpa_log". + LogFile defaults to "snmpa.log". + See snmp:log_to_io + for more info.

+
diff --git a/lib/snmp/doc/src/snmpm.xml b/lib/snmp/doc/src/snmpm.xml index c36a1b2a24..9bbb6cdbdb 100644 --- a/lib/snmp/doc/src/snmpm.xml +++ b/lib/snmp/doc/src/snmpm.xml @@ -4,7 +4,7 @@
- 20042011 + 20042012 Ericsson AB. All Rights Reserved. @@ -1237,6 +1237,38 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1 See snmp:log_to_txt for more info.

+ + + + + + log_to_io(LogDir) -> ok | {error, Reason} + log_to_io(LogDir, Mibs) -> ok | {error, Reason} + log_to_io(LogDir, Mibs) -> ok | {error, Reason} + log_to_io(LogDir, Mibs, LogName) -> ok | {error, Reason} + log_to_io(LogDir, Mibs, LogName, LogFile) -> ok | {error, Reason} + log_to_io(LogDir, Mibs, LogName, LogFile, Start) -> ok | {error, Reason} + log_to_io(LogDir, Mibs, LogName, LogFile, Start, Stop) -> ok | {error, Reason} + Convert an Audit Trail Log to text format + + LogDir = string() + Mibs = [MibName] + MibName = string() + LogName = string() + LogFile = string() + Start = Stop = null | datetime() | {local_time,datetime()} | {universal_time,datetime()} + Reason = disk_log_open_error() | file_open_error() | term() + disk_log_open_error() = {LogName, term()} + file_open_error() = {OutFile, term()} + + +

Converts an Audit Trail Log to a readable format and + prints it on stdio. + LogName defaults to "snmpm_log". + LogFile defaults to "snmpm.log". + See snmp:log_to_io + for more info.

+
diff --git a/lib/snmp/src/agent/snmpa.erl b/lib/snmp/src/agent/snmpa.erl index 50b169e4e7..584c7a22fb 100644 --- a/lib/snmp/src/agent/snmpa.erl +++ b/lib/snmp/src/agent/snmpa.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2011. All Rights Reserved. +%% Copyright Ericsson AB 2004-2012. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -83,8 +83,11 @@ -export([add_agent_caps/2, del_agent_caps/1, get_agent_caps/0]). %% Audit Trail Log functions --export([log_to_txt/2, log_to_txt/3, log_to_txt/4, +-export([log_to_txt/1, + log_to_txt/2, log_to_txt/3, log_to_txt/4, log_to_txt/5, log_to_txt/6, log_to_txt/7, + log_to_io/1, log_to_io/2, log_to_io/3, + log_to_io/4, log_to_io/5, log_to_io/6, log_info/0, change_log_size/1, get_log_type/0, get_log_type/1, @@ -780,6 +783,8 @@ get_agent_caps() -> %%% Audit Trail Log functions %%%----------------------------------------------------------------- +log_to_txt(LogDir) -> + log_to_txt(LogDir, []). log_to_txt(LogDir, Mibs) -> OutFile = "snmpa_log.txt", LogName = ?audit_trail_log_name, @@ -800,6 +805,23 @@ log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start, Stop) -> snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start, Stop). +log_to_io(LogDir) -> + log_to_io(LogDir, []). +log_to_io(LogDir, Mibs) -> + LogName = ?audit_trail_log_name, + LogFile = ?audit_trail_log_file, + snmp:log_to_io(LogDir, Mibs, LogName, LogFile). +log_to_io(LogDir, Mibs, LogName) -> + LogFile = ?audit_trail_log_file, + snmp:log_to_io(LogDir, Mibs, LogName, LogFile). +log_to_io(LogDir, Mibs, LogName, LogFile) -> + snmp:log_to_io(LogDir, Mibs, LogName, LogFile). +log_to_io(LogDir, Mibs, LogName, LogFile, Start) -> + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Start). +log_to_io(LogDir, Mibs, LogName, LogFile, Start, Stop) -> + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Start, Stop). + + log_info() -> LogName = ?audit_trail_log_name, snmp_log:info(LogName). diff --git a/lib/snmp/src/app/snmp.erl b/lib/snmp/src/app/snmp.erl index 3e0f05e604..fc03757e3f 100644 --- a/lib/snmp/src/app/snmp.erl +++ b/lib/snmp/src/app/snmp.erl @@ -50,6 +50,7 @@ read_mib/1, log_to_txt/5, log_to_txt/6, log_to_txt/7, + log_to_io/4, log_to_io/5, log_to_io/6, change_log_size/2, octet_string_to_bits/1, bits_to_octet_string/1, @@ -843,6 +844,12 @@ log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start) -> log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start, Stop) -> snmp_log:log_to_txt(LogName, LogFile, LogDir, Mibs, OutFile, Start, Stop). +log_to_io(LogDir, Mibs, LogName, LogFile) -> + snmp_log:log_to_io(LogName, LogFile, LogDir, Mibs). +log_to_io(LogDir, Mibs, LogName, LogFile, Start) -> + snmp_log:log_to_io(LogName, LogFile, LogDir, Mibs, Start). +log_to_io(LogDir, Mibs, LogName, LogFile, Start, Stop) -> + snmp_log:log_to_io(LogName, LogFile, LogDir, Mibs, Start, Stop). change_log_size(LogName, NewSize) -> snmp_log:change_size(LogName, NewSize). diff --git a/lib/snmp/src/manager/snmpm.erl b/lib/snmp/src/manager/snmpm.erl index 6d2ac8d747..89eaee9f80 100644 --- a/lib/snmp/src/manager/snmpm.erl +++ b/lib/snmp/src/manager/snmpm.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2011. All Rights Reserved. +%% Copyright Ericsson AB 2004-2012. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -75,8 +75,11 @@ %% %% Logging + log_to_txt/1, log_to_txt/2, log_to_txt/3, log_to_txt/4, log_to_txt/5, log_to_txt/6, log_to_txt/7, + log_to_io/1, log_to_io/2, log_to_io/3, + log_to_io/4, log_to_io/5, log_to_io/6, change_log_size/1, get_log_type/0, set_log_type/1, @@ -1371,6 +1374,9 @@ cancel_async_request(UserId, ReqId) -> %%%----------------------------------------------------------------- %%% Audit Trail Log functions (for backward compatibility) %%%----------------------------------------------------------------- + +log_to_txt(LogDir) -> + log_to_txt(LogDir, []). log_to_txt(LogDir, Mibs) -> OutFile = "snmpm_log.txt", LogName = ?audit_trail_log_name, @@ -1391,6 +1397,23 @@ log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start, Stop) -> snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start, Stop). +log_to_io(LogDir) -> + log_to_io(LogDir, []). +log_to_io(LogDir, Mibs) -> + LogName = ?audit_trail_log_name, + LogFile = ?audit_trail_log_file, + snmp:log_to_io(LogDir, Mibs, LogName, LogFile). +log_to_io(LogDir, Mibs, LogName) -> + LogFile = ?audit_trail_log_file, + snmp:log_to_io(LogDir, Mibs, LogName, LogFile). +log_to_io(LogDir, Mibs, LogName, LogFile) -> + snmp:log_to_io(LogDir, Mibs, LogName, LogFile). +log_to_io(LogDir, Mibs, LogName, LogFile, Start) -> + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Start). +log_to_io(LogDir, Mibs, LogName, LogFile, Start, Stop) -> + snmp:log_to_io(LogDir, Mibs, LogFile, Start, Stop). + + change_log_size(NewSize) -> LogName = ?audit_trail_log_name, snmp:change_log_size(LogName, NewSize). diff --git a/lib/snmp/src/misc/snmp_log.erl b/lib/snmp/src/misc/snmp_log.erl index 7f7030c9bf..a8c5df0b64 100644 --- a/lib/snmp/src/misc/snmp_log.erl +++ b/lib/snmp/src/misc/snmp_log.erl @@ -412,6 +412,14 @@ log_to_io(Log, FileName, Dir, Mibs, Start) -> log_to_io(Log, FileName, Dir, Mibs, Start, Stop) when is_list(Mibs) -> + ?vtrace("log_to_io -> entry with" + "~n Log: ~p" + "~n FileName: ~p" + "~n Dir: ~p" + "~n Mibs: ~p" + "~n Start: ~p" + "~n Stop: ~p", + [Log, FileName, Dir, Mibs, Start, Stop]), File = filename:join(Dir, FileName), Converter = fun(L) -> do_log_to_io(L, Mibs, Start, Stop) @@ -419,28 +427,10 @@ log_to_io(Log, FileName, Dir, Mibs, Start, Stop) log_convert(Log, File, Converter). -%% -- log_to_plain --- - -%% log_to_plain(Log, FileName, Dir) -> -%% log_to_plain(Log, FileName, Dir, null, null). - -%% log_to_plain(Log, FileName, Dir, Start) -> -%% log_to_plain(Log, FileName, Dir, Start, null). - -%% log_to_plain(Log, FileName, Dir, Start, Stop) -%% when is_list(Mibs) -> -%% File = filename:join(Dir, FileName), -%% Converter = fun(L) -> -%% do_log_to_plain(L, Start, Stop) -%% end, -%% log_convert(Log, File, Converter). - - %% -------------------------------------------------------------------- %% Internal functions %% -------------------------------------------------------------------- - %% -- log_convert --- log_convert(#snmp_log{id = Log}, File, Converter) -> @@ -449,6 +439,26 @@ log_convert(Log, File, Converter) -> do_log_convert(Log, File, Converter). do_log_convert(Log, File, Converter) -> + %% ?vtrace("do_log_converter -> entry with" + %% "~n Log: ~p" + %% "~n File: ~p" + %% "~n disk_log:info(Log): ~p", [Log, File, disk_log:info(Log)]), + {Pid, Ref} = + erlang:spawn_monitor( + fun() -> + Result = do_log_convert2(Log, File, Converter), + exit(Result) + end), + receive + {'DOWN', Ref, process, Pid, Result} -> + %% ?vtrace("do_log_converter -> received result" + %% "~n Result: ~p" + %% "~n disk_log:info(Log): ~p", + %% [Result, disk_log:info(Log)]), + Result + end. + +do_log_convert2(Log, File, Converter) -> %% First check if the caller process has already opened the %% log, because if we close an already open log we will cause %% a runtime error. @@ -457,29 +467,18 @@ do_log_convert(Log, File, Converter) -> Converter(Log); false -> %% Not yet member of the ruling party, apply for membership... - %% If a log is opened as read_write it is not possible to - %% open it as read_only. So, to get around this we open - %% it under a different name... - Log2 = convert_name(Log), - case log_open(Log2, File) of + case log_open(Log, File) of {ok, _} -> - Res = Converter(Log2), - disk_log:close(Log2), + Res = Converter(Log), + disk_log:close(Log), Res; {error, {name_already_open, _}} -> - Converter(Log2); + Converter(Log); {error, Reason} -> {error, {Log, Reason}} end end. -convert_name(Name) when is_list(Name) -> - Name ++ "_tmp"; -convert_name(Name) when is_atom(Name) -> - list_to_atom(atom_to_list(Name) ++ "_tmp"); -convert_name(Name) -> - lists:flatten(io_lib:format("~w_tmp", [Name])). - %% -- do_log_to_text --- @@ -882,11 +881,8 @@ do_std_log_open(Name, File, Size, Repair, Notify) -> log_open(Name, File) -> - Opts = [{name, Name}, - {file, File}, - {type, ?LOG_TYPE}, - {format, ?LOG_FORMAT}, - {mode, read_only}], + Opts = [{name, Name}, + {file, File}], case disk_log:open(Opts) of {error, {badarg, size}} -> {error, no_such_log}; -- cgit v1.2.3 From 04aa53cfc0263919f56b8a74ed4b0c57a3a3f204 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 22 Feb 2012 14:32:31 +0100 Subject: [snmp] Some restructure of the agent test suite OTP-9940 --- lib/snmp/test/snmp_agent_test.erl | 242 +++++++++++++++++++++------------- lib/snmp/test/snmp_agent_test_lib.erl | 211 +++++++++++++++-------------- lib/snmp/test/snmp_test_lib.erl | 2 +- 3 files changed, 259 insertions(+), 196 deletions(-) (limited to 'lib') diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index d507ac648b..9c9dd0c39a 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -351,32 +351,31 @@ init_per_testcase(otp8395 = Case, Config) when is_list(Config) -> ?DBG("init_per_testcase -> entry with" "~n Case: ~p" "~n Config: ~p", [Case, Config]), - Config2 = init_per_testcase2(Case, Config), - otp8395({init, Config2}); + otp8395({init, init_per_testcase2(Case, Config)}); init_per_testcase(otp_7157_test = _Case, Config) when is_list(Config) -> ?DBG("init_per_testcase -> entry with" "~n Case: ~p" "~n Config: ~p", [_Case, Config]), Dog = ?WD_START(?MINS(1)), - [{watchdog, Dog}|Config]; + [{watchdog, Dog} | Config ]; init_per_testcase(v2_inform_i = _Case, Config) when is_list(Config) -> ?DBG("init_per_testcase -> entry with" "~n Case: ~p" "~n Config: ~p", [_Case, Config]), Dog = ?WD_START(?MINS(10)), - [{watchdog, Dog}|Config]; + [{watchdog, Dog} | Config ]; init_per_testcase(v3_inform_i = _Case, Config) when is_list(Config) -> ?DBG("init_per_testcase -> entry with" "~n Case: ~p" "~n Config: ~p", [_Case, Config]), Dog = ?WD_START(?MINS(10)), - [{watchdog, Dog}|Config]; + [{watchdog, Dog} | Config ]; init_per_testcase(_Case, Config) when is_list(Config) -> ?DBG("init_per_testcase -> entry with" "~n Case: ~p" "~n Config: ~p", [_Case, Config]), Dog = ?WD_START(?MINS(6)), - [{watchdog, Dog}|Config]. + [{watchdog, Dog}| Config ]. end_per_testcase(otp8395, Config) when is_list(Config) -> otp8395({fin, Config}); @@ -390,11 +389,10 @@ end_per_testcase(_Case, Config) when is_list(Config) -> init_per_testcase2(Case, Config) -> - %% SuiteToDir = ?config(snmp_suite_top_dir, Config), - - %% %% Create top-directory for this test-case - %% filename:join([SuiteToDir, Case]), - %% ok = file:make_dir(CaseTopDir), + + ?DBG("end_per_testcase2 -> entry with" + "~n Case: ~p" + "~n Config: ~p", [Case, Config]), CaseTopDir = snmp_test_lib:init_testcase_top_dir(Case, Config), @@ -595,19 +593,19 @@ mib_storage_mnesia_cases() -> msm_mib_of]. mse_size_check_cases() -> -[mse_size_check]. + [mse_size_check]. msd_size_check_cases() -> -[msd_size_check]. + [msd_size_check]. msm_size_check_cases() -> -[msm_size_check]. + [msm_size_check]. varm_mib_storage_dets_cases() -> -[msd_varm_mib_start]. + [msd_varm_mib_start]. varm_mib_storage_mnesia_cases() -> -[msm_varm_mib_start]. + [msm_varm_mib_start]. init_mib_storage_ets(Config) when is_list(Config) -> ?LOG("init_mib_storage_ets -> entry", []), @@ -627,17 +625,18 @@ init_mib_storage_mnesia(Config) when is_list(Config) -> init_ms(Config, Opts) when is_list(Config) -> ?LOG("init_mib_storage_ets -> entry", []), - ?line SaNode = ?GCONF(snmp_sa, Config), + ?line SaNode = ?GCONF(snmp_sa, Config), ?line create_tables(SaNode), - ?line AgentDir = ?GCONF(agent_dir, Config), - ?line MgrDir = ?GCONF(mgr_dir, Config), - ?line Ip = ?GCONF(ip, Config), - ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + ?line AgentConfDir = ?GCONF(agent_conf_dir, Config), + ?line MgrDir = ?GCONF(mgr_dir, Config), + ?line Ip = ?GCONF(ip, Config), + ?line config([v1], MgrDir, AgentConfDir, + tuple_to_list(Ip), tuple_to_list(Ip)), MasterAgentVerbosity = {snmp_master_agent_verbosity, trace}, MibsVerbosity = {snmp_mibserver_verbosity, trace}, SymStoreVerbosity = {snmp_symbolic_store_verbosity, trace}, - Opts1 = [MasterAgentVerbosity,MibsVerbosity,SymStoreVerbosity|Opts], - [{vsn, v1} | start_v1_agent(Config,Opts1)]. + Opts1 = [MasterAgentVerbosity, MibsVerbosity, SymStoreVerbosity | Opts], + [{vsn, v1} | start_v1_agent(Config, Opts1)]. init_size_check_mse(Config) when is_list(Config) -> MibStorage = {snmp_mib_storage, ets}, @@ -1161,10 +1160,11 @@ v1_cases() -> init_v1(Config) when is_list(Config) -> ?line SaNode = ?config(snmp_sa, Config), ?line create_tables(SaNode), - ?line AgentDir = ?config(agent_dir, Config), + ?line AgentConfDir = ?config(agent_conf_dir, Config), ?line MgrDir = ?config(mgr_dir, Config), ?line Ip = ?config(ip, Config), - ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + ?line config([v1], MgrDir, AgentConfDir, + tuple_to_list(Ip), tuple_to_list(Ip)), [{vsn, v1} | start_v1_agent(Config)]. finish_v1(Config) when is_list(Config) -> @@ -1204,10 +1204,11 @@ v2_cases() -> init_v2(Config) when is_list(Config) -> SaNode = ?config(snmp_sa, Config), create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), + AgentConfDir = ?config(agent_conf_dir, Config), MgrDir = ?config(mgr_dir, Config), Ip = ?config(ip, Config), - config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + config([v2], MgrDir, AgentConfDir, + tuple_to_list(Ip), tuple_to_list(Ip)), [{vsn, v2} | start_v2_agent(Config)]. finish_v2(Config) when is_list(Config) -> @@ -1223,10 +1224,11 @@ v1_v2_cases() -> init_v1_v2(Config) when is_list(Config) -> SaNode = ?config(snmp_sa, Config), create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), + AgentConfDir = ?config(agent_conf_dir, Config), MgrDir = ?config(mgr_dir, Config), Ip = ?config(ip, Config), - config([v1,v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + config([v1,v2], MgrDir, AgentConfDir, + tuple_to_list(Ip), tuple_to_list(Ip)), [{vsn, bilingual} | start_bilingual_agent(Config)]. finish_v1_v2(Config) when is_list(Config) -> @@ -1287,10 +1289,10 @@ init_v3(Config) when is_list(Config) -> end, SaNode = ?config(snmp_sa, Config), create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), + AgentConfDir = ?config(agent_conf_dir, Config), MgrDir = ?config(mgr_dir, Config), Ip = ?config(ip, Config), - ?line ok = config([v3], MgrDir, AgentDir, + ?line ok = config([v3], MgrDir, AgentConfDir, tuple_to_list(Ip), tuple_to_list(Ip)), [{vsn, v3} | start_v3_agent(Config)]. @@ -1307,11 +1309,11 @@ mt_cases() -> init_mt(Config) when is_list(Config) -> SaNode = ?config(snmp_sa, Config), create_tables(SaNode), - AgentDir = ?config(agent_dir, Config), + AgentConfDir = ?config(agent_conf_dir, Config), MgrDir = ?config(mgr_dir, Config), Ip = ?config(ip, Config), - ?line ok = - config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + ?line ok = config([v2], MgrDir, AgentConfDir, + tuple_to_list(Ip), tuple_to_list(Ip)), [{vsn, v2} | start_multi_threaded_agent(Config)]. finish_mt(Config) when is_list(Config) -> @@ -1390,7 +1392,13 @@ simple(Config) when is_list(Config) -> ?P(simple), init_case(Config), - try_test(simple_standard_test). + try_test(simple_standard_test), + + p("Display log"), + display_log(Config), + + p("done"), + ok. simple_2(X) -> ?P(simple_2), simple(X). @@ -1570,7 +1578,7 @@ change_target_addr_config(Config) when is_list(Config) -> try_test(ma_trap1, [MA]), ?LOG("change_target_addr_config -> set silence verbosity for local_db",[]), - ?line snmpa:verbosity(local_db,silence), + ?line snmpa:verbosity(local_db, silence), %% Start new dummy listener ?LOG("change_target_addr_config -> start dummy manager",[]), @@ -1578,9 +1586,9 @@ change_target_addr_config(Config) when is_list(Config) -> %% Reconfigure ?LOG("change_target_addr_config -> reconfigure",[]), - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_addr_conf(AgentDir, NewPort), - ?line snmp_target_mib:reconfigure(AgentDir), + AgentConfDir = ?config(agent_conf_dir, Config), + ?line rewrite_target_addr_conf(AgentConfDir, NewPort), + ?line snmp_target_mib:reconfigure(AgentConfDir), %% Send the trap again ?LOG("change_target_addr_config -> send trap again",[]), @@ -1593,7 +1601,7 @@ change_target_addr_config(Config) when is_list(Config) -> ?line ok = dummy_manager_stop(Pid), ?LOG("change_target_addr_config -> reset target address config",[]), - ?line reset_target_addr_conf(AgentDir), + ?line reset_target_addr_conf(AgentConfDir), ?LOG("change_target_addr_config -> unload TestTrap",[]), ?line unload_master("TestTrap"). @@ -2036,7 +2044,7 @@ v3_inform(_X) -> {req, [], {conf, init_v3_inform, [v3_inform_i], finish_v3_inform}}. init_v2_inform(Config) when is_list(Config) -> - _Dir = ?config(agent_dir, Config), + _Dir = ?config(agent_conf_dir, Config), %% snmp_internal_mib:configure(Dir), Config. @@ -2044,7 +2052,7 @@ init_v3_inform(X) -> init_v2_inform(X). finish_v2_inform(Config) when is_list(Config) -> - _Dir = ?config(agent_dir, Config), + _Dir = ?config(agent_conf_dir, Config), %% snmp_internal_mib:configure(Dir), Config. @@ -2346,9 +2354,9 @@ v3_md5_auth(Config) when is_list(Config) -> ?P1("Testing MD5 authentication...takes a few seconds..."), - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_params_conf(AgentDir, "authMD5", authNoPriv), - ?line snmp_target_mib:reconfigure(AgentDir), + AgentConfDir = ?config(agent_conf_dir, Config), + ?line rewrite_target_params_conf(AgentConfDir, "authMD5", authNoPriv), + ?line snmp_target_mib:reconfigure(AgentConfDir), MA = whereis(snmp_master_agent), @@ -2357,14 +2365,14 @@ v3_md5_auth(Config) when is_list(Config) -> ?line load_master("TestTrapv2"), try_test(v3_sync, [[{v2_proc, []}, - {ma_v2_trap1, [MA]}, - {v3_inform_sync, [MA]}]], - [{sec_level, authNoPriv}, {user, "authMD5"}]), + {ma_v2_trap1, [MA]}, + {v3_inform_sync, [MA]}]], + [{sec_level, authNoPriv}, {user, "authMD5"}]), ?line unload_master("TestTrapv2"), ?line unload_master("TestTrap"), ?line unload_master("Test2"), - ?line reset_target_params_conf(AgentDir). + ?line reset_target_params_conf(AgentConfDir). v3_sha_auth(suite) -> []; v3_sha_auth(Config) when is_list(Config) -> @@ -2373,9 +2381,9 @@ v3_sha_auth(Config) when is_list(Config) -> ?P1("Testing SHA authentication...takes a few seconds..."), - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_params_conf(AgentDir, "authSHA", authNoPriv), - ?line snmp_target_mib:reconfigure(AgentDir), + AgentConfDir = ?config(agent_conf_dir, Config), + ?line rewrite_target_params_conf(AgentConfDir, "authSHA", authNoPriv), + ?line snmp_target_mib:reconfigure(AgentConfDir), MA = whereis(snmp_master_agent), @@ -2384,14 +2392,14 @@ v3_sha_auth(Config) when is_list(Config) -> ?line load_master("TestTrapv2"), try_test(v3_sync, [[{v2_proc, []}, - {ma_v2_trap1, [MA]}, - {v3_inform_sync, [MA]}]], - [{sec_level, authNoPriv}, {user, "authSHA"}]), + {ma_v2_trap1, [MA]}, + {v3_inform_sync, [MA]}]], + [{sec_level, authNoPriv}, {user, "authSHA"}]), ?line unload_master("TestTrapv2"), ?line unload_master("TestTrap"), ?line unload_master("Test2"), - ?line reset_target_params_conf(AgentDir). + ?line reset_target_params_conf(AgentConfDir). v3_des_priv(suite) -> []; v3_des_priv(Config) when is_list(Config) -> @@ -2400,9 +2408,9 @@ v3_des_priv(Config) when is_list(Config) -> ?P1("Testing DES encryption...takes a few seconds..."), - AgentDir = ?config(agent_dir, Config), - ?line rewrite_target_params_conf(AgentDir, "privDES", authPriv), - ?line snmp_target_mib:reconfigure(AgentDir), + AgentConfDir = ?config(agent_conf_dir, Config), + ?line rewrite_target_params_conf(AgentConfDir, "privDES", authPriv), + ?line snmp_target_mib:reconfigure(AgentConfDir), MA = whereis(snmp_master_agent), @@ -2413,14 +2421,14 @@ v3_des_priv(Config) when is_list(Config) -> ?line load_master("TestTrapv2"), try_test(v3_sync, [[{v2_proc, []}, - {ma_v2_trap1, [MA]}, - {v3_inform_sync, [MA]}]], - [{sec_level, authPriv}, {user, "privDES"}]), + {ma_v2_trap1, [MA]}, + {v3_inform_sync, [MA]}]], + [{sec_level, authPriv}, {user, "privDES"}]), ?line unload_master("TestTrapv2"), ?line unload_master("TestTrap"), ?line unload_master("Test2"), - ?line reset_target_params_conf(AgentDir). + ?line reset_target_params_conf(AgentConfDir). %% -define(usmStatsNotInTimeWindows_instance, [1,3,6,1,6,3,15,1,1,2,0]). @@ -4764,7 +4772,7 @@ snmp_user_based_sm_mib_3(Config) when is_list(Config) -> ?P(snmp_user_based_sm_mib_3), init_case(Config), - _AgentDir = ?config(agent_dir, Config), + _AgentDir = ?config(agent_conf_dir, Config), ?line load_master_std("SNMP-USER-BASED-SM-MIB"), %% The newUser used here already has VACM access. @@ -5706,28 +5714,28 @@ otp_3725_test(MaNode) -> init_otp_4394(Config) when is_list(Config) -> ?DBG("init_otp_4394 -> entry with" "~n Config: ~p", [Config]), - ?line AgentDir = ?config(agent_dir, Config), - ?line MgrDir = ?config(mgr_dir, Config), - ?line Ip = ?config(ip, Config), - ?line otp_4394_config(AgentDir, MgrDir, Ip), + ?line AgentConfDir = ?config(agent_conf_dir, Config), + ?line MgrDir = ?config(mgr_dir, Config), + ?line Ip = ?config(ip, Config), + ?line otp_4394_config(AgentConfDir, MgrDir, Ip), MasterAgentVerbosity = {master_agent_verbosity, trace}, NetIfVerbosity = {net_if_verbosity, trace}, - Opts = [MasterAgentVerbosity,NetIfVerbosity], - [{vsn, v1} | start_v1_agent(Config,Opts)]. + Opts = [MasterAgentVerbosity, NetIfVerbosity], + [{vsn, v1} | start_v1_agent(Config, Opts)]. -otp_4394_config(AgentDir, MgrDir, Ip0) -> +otp_4394_config(AgentConfDir, MgrDir, Ip0) -> ?DBG("otp_4394_config -> entry with" - "~n AgentDir: ~p" - "~n MgrDir: ~p" - "~n Ip0: ~p", [AgentDir, MgrDir, Ip0]), + "~n AgentConfDir: ~p" + "~n MgrDir: ~p" + "~n Ip0: ~p", [AgentConfDir, MgrDir, Ip0]), Vsn = [v1], Ip = tuple_to_list(Ip0), - ?line snmp_config:write_agent_snmp_files(AgentDir, Vsn, Ip, + ?line snmp_config:write_agent_snmp_files(AgentConfDir, Vsn, Ip, ?TRAP_UDP, Ip, 4000, "OTP-4394 test"), - ?line case update_usm(Vsn, AgentDir) of + ?line case update_usm(Vsn, AgentConfDir) of true -> - ?line copy_file(filename:join(AgentDir, "usm.conf"), + ?line copy_file(filename:join(AgentConfDir, "usm.conf"), filename:join(MgrDir, "usm.conf")), ?line update_usm_mgr(Vsn, MgrDir); false -> @@ -5735,8 +5743,8 @@ otp_4394_config(AgentDir, MgrDir, Ip0) -> end, C1 = {"a", "all-rights", "initial", "", "pc"}, C2 = {"c", "secret", "secret_name", "", "secret_tag"}, - ?line write_community_conf(AgentDir, [C1, C2]), - ?line update_vacm(Vsn, AgentDir), + ?line write_community_conf(AgentConfDir, [C1, C2]), + ?line update_vacm(Vsn, AgentConfDir), Ta1 = {"shelob v1", [134,138,177,177], 5000, 1500, 3, %% Använd Ip och modda "pc1", @@ -5750,9 +5758,9 @@ otp_4394_config(AgentDir, MgrDir, Ip0) -> "target_v1", "", %% [255,255,255,255,0,0], [], 2048}, - ?line write_target_addr_conf(AgentDir, [Ta1, Ta2]), - ?line write_target_params_conf(AgentDir, Vsn), - ?line write_notify_conf(AgentDir), + ?line write_target_addr_conf(AgentConfDir, [Ta1, Ta2]), + ?line write_target_params_conf(AgentConfDir, Vsn), + ?line write_notify_conf(AgentConfDir), ok. @@ -5805,10 +5813,11 @@ init_otp_7157(Config) when is_list(Config) -> ?DBG("init_otp_7157 -> entry with" "~n Config: ~p", [Config]), - ?line AgentDir = ?config(agent_dir, Config), + ?line AgentConfDir = ?config(agent_conf_dir, Config), ?line MgrDir = ?config(mgr_dir, Config), ?line Ip = ?config(ip, Config), - ?line config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)), + ?line config([v2], MgrDir, AgentConfDir, + tuple_to_list(Ip), tuple_to_list(Ip)), MasterAgentVerbosity = {master_agent_verbosity, trace}, NetIfVerbosity = {net_if_verbosity, trace}, Opts = [MasterAgentVerbosity, NetIfVerbosity], @@ -6353,8 +6362,8 @@ write_community_conf(Dir, Conf) -> write_target_addr_conf(Dir, Conf) -> snmp_agent_test_lib:write_target_addr_conf(Dir, Conf). -write_target_addr_conf(Dir, ManagerIp, UDP, Vsns) -> - snmp_agent_test_lib:write_target_addr_conf(Dir, ManagerIp, UDP, Vsns). +%% write_target_addr_conf(Dir, ManagerIp, UDP, Vsns) -> +%% snmp_agent_test_lib:write_target_addr_conf(Dir, ManagerIp, UDP, Vsns). rewrite_target_addr_conf(Dir, NewPort) -> snmp_agent_test_lib:rewrite_target_addr_conf(Dir, NewPort). @@ -6387,9 +6396,42 @@ copy_file(From, To) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +display_log(Config) -> + case lists:keysearch(agent_log_dir, 1, Config) of + {value, {_, Dir}} -> + case lists:keysearch(snmp_master, 1, Config) of + {value, {_, Node}} -> + LogDir = Dir, + Mibs = [], + OutFile = filename:join(LogDir, "snmpa_log.txt"), + p("~n" + "=========================" + " < Audit Trail Log > " + "=========================" + "~n"), + rcall(Node, snmpa, log_to_txt, [LogDir, Mibs, OutFile]), + rcall(Node, snmpa, log_to_io, [LogDir, Mibs]), + p("~n" + "=========================" + " < / Audit Trail Log > " + "=========================" + "~n", []); + false -> + p("display_log -> no agent node found"), + ok + end; + false -> + p("display_log -> no agent log dir found: " + "~n ~p", [Config]), + ok + end. + + +%% ------ + display_memory_usage() -> Info = snmpa:info(snmp_master_agent), - AMU = display_agent_memory_uasge(Info), + AMU = display_agent_memory_usage(Info), NIMU = display_net_if_memory_usage(Info), NSMU = display_note_store_memory_usage(Info), SSMU = display_symbolic_store_memory_usage(Info), @@ -6399,7 +6441,7 @@ display_memory_usage() -> AMU ++ NIMU ++ NSMU ++ SSMU ++ LDBMU ++ MSMU, []), ok. -display_agent_memory_uasge(Info) -> +display_agent_memory_usage(Info) -> AgentInfo = lists_key1search(agent, Info), ProcMem = lists_key1search([process_memory,master_agent], AgentInfo), @@ -6508,3 +6550,27 @@ lists_key1search(Key, List) when is_atom(Key) -> regs() -> lists:sort(registered()). + +%% ------ + +rcall(Node, Mod, Func, Args) -> + case rpc:call(Node, Mod, Func, Args) of + {badrpc, nodedown} -> + ?FAIL({rpc_failure, Node}); + Else -> + Else + end. + + +%% ------ + +p(F) -> + p(F, []). + +p(F, A) -> + io:format("*** [~s] ***" + "~n" ++ F ++ "~n", [formated_timestamp()|A]). + +formated_timestamp() -> + snmp_test_lib:formated_timestamp(). + diff --git a/lib/snmp/test/snmp_agent_test_lib.erl b/lib/snmp/test/snmp_agent_test_lib.erl index 084b3ee8da..cd9a87eab8 100644 --- a/lib/snmp/test/snmp_agent_test_lib.erl +++ b/lib/snmp/test/snmp_agent_test_lib.erl @@ -119,20 +119,10 @@ %%% didn't undo (since it failed). %%%----------------------------------------------------------------- -init_all(Config0) when is_list(Config0) -> - ?LOG("init_all -> entry with" - "~n Config0: ~p",[Config0]), - - %% -- - %% Fix config: - %% +init_all(Config) when is_list(Config) -> - DataDir0 = ?config(data_dir, Config0), - DataDir1 = filename:split(filename:absname(DataDir0)), - [_|DataDir2] = lists:reverse(DataDir1), - DataDir3 = filename:join(lists:reverse(DataDir2) ++ [?snmp_test_data]), - Config1 = lists:keydelete(data_dir, 1, Config0), - Config = [{data_dir, DataDir3 ++ "/"}|Config1], + ?LOG("init_all -> entry with" + "~n Config: ~p",[Config]), %% -- %% Start nodes @@ -143,34 +133,43 @@ init_all(Config0) when is_list(Config0) -> %% -- - %% Create necessary files + %% Create necessary files ( and dirs ) %% - PrivDir = ?config(priv_dir, Config), - ?DBG("init_all -> PrivDir ~p", [PrivDir]), + SuiteTopDir = ?config(snmp_suite_top_dir, Config), + ?DBG("init_all -> SuiteTopDir ~p", [SuiteTopDir]), - TopDir = filename:join(PrivDir, snmp_agent_test), - case file:make_dir(TopDir) of - ok -> - ok; - {error, eexist} -> - ok; - Error -> - ?FAIL({failed_creating_subsuite_top_dir, Error}) - end, + AgentDir = filename:join(SuiteTopDir, "agent/"), + ?line ok = file:make_dir(AgentDir), + ?DBG("init_all -> AgentDir ~p", [AgentDir]), - DataDir = ?config(data_dir, Config), - ?DBG("init_all -> DataDir ~p", [DataDir]), + AgentDbDir = filename:join(AgentDir, "db/"), + ?line ok = file:make_dir(AgentDbDir), + ?DBG("init_all -> AgentDbDir ~p", [AgentDbDir]), - ?line ok = file:make_dir(MgrDir = filename:join(TopDir, "mgr_dir/")), - ?DBG("init_all -> MgrDir ~p", [MgrDir]), + AgentLogDir = filename:join(AgentDir, "log/"), + ?line ok = file:make_dir(AgentLogDir), + ?DBG("init_all -> AgentLogDir ~p", [AgentLogDir]), - ?line ok = file:make_dir(AgentDir = filename:join(TopDir, "agent_dir/")), - ?DBG("init_all -> AgentDir ~p", [AgentDir]), + AgentConfDir = filename:join(AgentDir, "conf/"), + ?line ok = file:make_dir(AgentConfDir), + ?DBG("init_all -> AgentConfDir ~p", [AgentConfDir]), - ?line ok = file:make_dir(SaDir = filename:join(TopDir, "sa_dir/")), + MgrDir = filename:join(SuiteTopDir, "mgr/"), + ?line ok = file:make_dir(MgrDir), + ?DBG("init_all -> MgrDir ~p", [MgrDir]), + + SaDir = filename:join(SuiteTopDir, "sa/"), + ?line ok = file:make_dir(SaDir), ?DBG("init_all -> SaDir ~p", [SaDir]), + SaDbDir = filename:join(SaDir, "db/"), + ?line ok = file:make_dir(SaDbDir), + ?DBG("init_all -> SaDbDir ~p", [SaDbDir]), + + %% MibDir = ?config(mib_dir, Config), + %% ?DBG("init_all -> MibDir ~p", [DataDir]), + %% -- %% Start and initiate mnesia @@ -184,11 +183,11 @@ init_all(Config0) when is_list(Config0) -> ?DBG("init_all -> application mnesia: set_env dir",[]), ?line application_controller:set_env(mnesia, dir, - filename:join(TopDir, "Mnesia1")), + filename:join(AgentDbDir, "Mnesia1")), ?DBG("init_all -> application mnesia: set_env dir on node ~p",[SaNode]), - ?line rpc:call(SaNode, application_controller, set_env, - [mnesia, dir, filename:join(TopDir, "Mnesia2")]), + ?line rpc:call(SaNode, application_controller, set_env, + [mnesia, dir, filename:join(SaDir, "Mnesia2")]), ?DBG("init_all -> create mnesia schema",[]), ?line ok = mnesia:create_schema([SaNode, node()]), @@ -199,13 +198,18 @@ init_all(Config0) when is_list(Config0) -> ?DBG("init_all -> start application mnesia on ~p",[SaNode]), ?line ok = rpc:call(SaNode, application, start, [mnesia]), Ip = ?LOCALHOST(), - [{snmp_sa, SaNode}, - {snmp_mgr, MgrNode}, - {agent_dir, AgentDir ++ "/"}, - {mgr_dir, MgrDir ++ "/"}, - {sa_dir, SaDir ++ "/"}, - {mib_dir, DataDir}, - {ip, Ip} | + [{snmp_sa, SaNode}, + {snmp_mgr, MgrNode}, + {snmp_master, node()}, + {agent_dir, AgentDir ++ "/"}, + {agent_db_dir, AgentDbDir ++ "/"}, + {agent_log_dir, AgentLogDir ++ "/"}, + {agent_conf_dir, AgentConfDir ++ "/"}, + {sa_dir, SaDir ++ "/"}, + {sa_db_dir, SaDbDir ++ "/"}, + {mgr_dir, MgrDir ++ "/"}, + %% {mib_dir, DataDir}, + {ip, Ip} | Config]. @@ -220,11 +224,14 @@ finish_all(Config) when is_list(Config) -> %% --- This one *must* be run first in each case --- init_case(Config) when is_list(Config) -> + ?DBG("init_case -> entry with" - "~n Config: ~p", [Config]), - SaNode = ?config(snmp_sa, Config), - MgrNode = ?config(snmp_mgr, Config), - MasterNode = node(), + "~n Config: ~p", [Config]), + + SaNode = ?config(snmp_sa, Config), + MgrNode = ?config(snmp_mgr, Config), + MasterNode = ?config(snmp_master, Config), + %% MasterNode = node(), SaHost = ?HOSTNAME(SaNode), MgrHost = ?HOSTNAME(MgrNode), @@ -411,7 +418,8 @@ start_v3_agent(Config, Opts) when is_list(Config) andalso is_list(Opts) -> start_bilingual_agent(Config) when is_list(Config) -> start_agent(Config, [v1,v2]). -start_bilingual_agent(Config, Opts) when is_list(Config) andalso is_list(Opts) -> +start_bilingual_agent(Config, Opts) + when is_list(Config) andalso is_list(Opts) -> start_agent(Config, [v1,v2], Opts). start_mt_agent(Config) when is_list(Config) -> @@ -423,57 +431,33 @@ start_mt_agent(Config, Opts) when is_list(Config) andalso is_list(Opts) -> start_agent(Config, Vsns) -> start_agent(Config, Vsns, []). start_agent(Config, Vsns, Opts) -> + ?LOG("start_agent -> entry (~p) with" "~n Config: ~p" "~n Vsns: ~p" "~n Opts: ~p", [node(), Config, Vsns, Opts]), - ?line AgentDir = ?config(agent_dir, Config), - ?line SaNode = ?config(snmp_sa, Config), - -%% AgentConfig = -%% [{agent_type, master}, -%% %% {multi_threaded, MultiT}, -%% %% {priority, Prio}, -%% %% {error_report_mod, ErrorReportMod}, -%% {versions, Vsns}, -%% {db_dir, AgentDir}, -%% %% {db_init_error, DbInitError}, -%% %% {set_mechanism, SetModule}, -%% %% {authentication_service, AuthModule}, -%% {audit_trail_log, [{type, read_write}, -%% {dir, AgentDir}, -%% {size, {10240, 10}}, -%% {repair, true}]}, -%% {config, [{verbosity, info}, -%% {dir, AgentDir}, -%% {force_load, false}]}, -%% {mibs, Mibs}, -%% %% {mib_storage, MibStorage}, -%% {local_db, []}, -%% {mib_server, []}, -%% {symbolic_store, []}, -%% {note_store, []}, -%% {net_if, []}, -%% %% {supervisor, SupOpts} -%% ], - + ?line AgentLogDir = ?config(agent_log_dir, Config), + ?line AgentConfDir = ?config(agent_conf_dir, Config), + ?line AgentDbDir = ?config(agent_db_dir, Config), + ?line SaNode = ?config(snmp_sa, Config), + app_env_init(vsn_init(Vsns) ++ - [{audit_trail_log, read_write_log}, - {audit_trail_log_dir, AgentDir}, - {audit_trail_log_size, {10240, 10}}, - {force_config_reload, false}, - {snmp_agent_type, master}, - {snmp_config_dir, AgentDir}, - {snmp_db_dir, AgentDir}, - {snmp_local_db_auto_repair, true}, - {snmp_local_db_verbosity, log}, - {snmp_master_agent_verbosity, trace}, - {snmp_supervisor_verbosity, trace}, - {snmp_mibserver_verbosity, log}, + [{audit_trail_log, read_write_log}, + {audit_trail_log_dir, AgentLogDir}, + {audit_trail_log_size, {10240, 10}}, + {force_config_reload, false}, + {snmp_agent_type, master}, + {snmp_config_dir, AgentConfDir}, + {snmp_db_dir, AgentDbDir}, + {snmp_local_db_auto_repair, true}, + {snmp_local_db_verbosity, log}, + {snmp_master_agent_verbosity, trace}, + {snmp_supervisor_verbosity, trace}, + {snmp_mibserver_verbosity, log}, {snmp_symbolic_store_verbosity, log}, - {snmp_note_store_verbosity, log}, - {snmp_net_if_verbosity, trace}], + {snmp_note_store_verbosity, log}, + {snmp_net_if_verbosity, trace}], Opts), @@ -1237,30 +1221,44 @@ stop_node(Node) -> %%% Configuration %%%----------------------------------------------------------------- -config(Vsns, MgrDir, AgentDir, MIp, AIp) -> - ?line snmp_config:write_agent_snmp_files(AgentDir, Vsns, MIp, - ?TRAP_UDP, AIp, 4000, +config(Vsns, MgrDir, AgentConfDir, MIp, AIp) -> + ?LOG("config -> entry with" + "~n Vsns: ~p" + "~n MgrDir: ~p" + "~n AgentConfDir: ~p" + "~n MIp: ~p" + "~n AIp: ~p", + [Vsns, MgrDir, AgentConfDir, MIp, AIp]), + ?line snmp_config:write_agent_snmp_files(AgentConfDir, Vsns, + MIp, ?TRAP_UDP, AIp, 4000, "test"), - ?line case update_usm(Vsns, AgentDir) of + ?line case update_usm(Vsns, AgentConfDir) of true -> - ?line copy_file(filename:join(AgentDir, "usm.conf"), + ?line copy_file(filename:join(AgentConfDir, "usm.conf"), filename:join(MgrDir, "usm.conf")), ?line update_usm_mgr(Vsns, MgrDir); false -> ?line ok end, - ?line update_community(Vsns, AgentDir), - ?line update_vacm(Vsns, AgentDir), - ?line write_target_addr_conf(AgentDir, MIp, ?TRAP_UDP, Vsns), - ?line write_target_params_conf(AgentDir, Vsns), - ?line write_notify_conf(AgentDir), + ?line update_community(Vsns, AgentConfDir), + ?line update_vacm(Vsns, AgentConfDir), + ?line write_target_addr_conf(AgentConfDir, MIp, ?TRAP_UDP, Vsns), + ?line write_target_params_conf(AgentConfDir, Vsns), + ?line write_notify_conf(AgentConfDir), ok. delete_files(Config) -> - Dir = ?config(agent_dir, Config), - {ok, List} = file:list_dir(Dir), + AgentDir = ?config(agent_dir, Config), + delete_files(AgentDir, [db, conf]). + +delete_files(_AgentFiles, []) -> + ok; +delete_files(AgentDir, [DirName|DirNames]) -> + Dir = filename:join(AgentDir, DirName), + {ok, Files} = file:list_dir(Dir), lists:foreach(fun(FName) -> file:delete(filename:join(Dir, FName)) end, - List). + Files), + delete_files(AgentDir, DirNames). update_usm(Vsns, Dir) -> case lists:member(v3, Vsns) of @@ -1418,8 +1416,8 @@ rewrite_target_addr_conf2(_NewPort,O) -> O. reset_target_addr_conf(Dir) -> - ?line ok = file:rename(filename:join(Dir,"target_addr.old"), - filename:join(Dir,"target_addr.conf")). + ?line ok = file:rename(filename:join(Dir, "target_addr.old"), + filename:join(Dir, "target_addr.conf")). write_target_params_conf(Dir, Vsns) -> F = fun(v1) -> {"target_v1", v1, v1, "all-rights", noAuthNoPriv}; @@ -1458,7 +1456,6 @@ copy_file(From, To) -> ok = file:write_file(To, Bin). - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% display_memory_usage() -> diff --git a/lib/snmp/test/snmp_test_lib.erl b/lib/snmp/test/snmp_test_lib.erl index f247cfa1ae..bc54361aaf 100644 --- a/lib/snmp/test/snmp_test_lib.erl +++ b/lib/snmp/test/snmp_test_lib.erl @@ -207,7 +207,7 @@ fix_data_dir(Config) -> [_|DataDir2] = lists:reverse(DataDir1), DataDir = filename:join(lists:reverse(DataDir2) ++ [?snmp_test_data]), Config1 = lists:keydelete(data_dir, 1, Config), - [{data_dir, DataDir} | Config1]. + [{data_dir, DataDir ++ "/"} | Config1]. init_suite_top_dir(Suite, Config0) -> -- cgit v1.2.3 From 14a757d5444719c33e9fbca8d97114d58229291f Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 22 Feb 2012 14:40:36 +0100 Subject: [snmp] Updated release notes and appup file OTP-9876 OTP-9940 --- lib/snmp/doc/src/notes.xml | 4 +- lib/snmp/src/app/snmp.appup.src | 142 +++++++++++++++++++++++++++++----------- 2 files changed, 106 insertions(+), 40 deletions(-) (limited to 'lib') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index e7fb4e2287..ffbdec5a5b 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -46,8 +46,8 @@ -

Added the log_to_io audit-trail-log converter function to the - api modules of both the +

Added the log_to_io audit-trail-log converter function + to the api modules of both the manager and agent.

diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index 50a5916d20..e0cc93a6c6 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -25,52 +25,76 @@ %% This is a place holder {"4.21.7", [ + {load_module, snmp, soft_purge, soft_purge, [snmp_log]}, + {load_module, snmpa, soft_purge, soft_purge, [snmp]}, + {load_module, snmpm, soft_purge, soft_purge, [snmp]}, + {load_module, snmp_log, soft_purge, soft_purge, []}, {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmpm_mpd, soft_purge, soft_purge, []}, - {add_module, snmpm_net_if_mt} + {add_module, snmpm_net_if_mt} ] }, %% This is a place holder {"4.21.6", [ + {load_module, snmp, soft_purge, soft_purge, [snmp_log]}, + {load_module, snmpa, soft_purge, soft_purge, [snmp]}, + {load_module, snmpm, soft_purge, soft_purge, [snmp]}, + {load_module, snmp_log, soft_purge, soft_purge, []}, {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmpm_mpd, soft_purge, soft_purge, []}, - {add_module, snmpm_net_if_mt} + {add_module, snmpm_net_if_mt} ] }, %% This is a place holder {"4.21.5", [ + {load_module, snmp, soft_purge, soft_purge, [snmp_log]}, + {load_module, snmpa, soft_purge, soft_purge, [snmp]}, + {load_module, snmpm, soft_purge, soft_purge, [snmp]}, + {load_module, snmp_log, soft_purge, soft_purge, []}, {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmpm_mpd, soft_purge, soft_purge, []}, - {add_module, snmpm_net_if_mt} + {add_module, snmpm_net_if_mt} ] }, {"4.21.4", [ + {load_module, snmp, soft_purge, soft_purge, [snmp_log]}, + {load_module, snmpa, soft_purge, soft_purge, [snmp]}, + {load_module, snmpm, soft_purge, soft_purge, [snmp]}, + {load_module, snmp_log, soft_purge, soft_purge, []}, {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, {load_module, snmpa_vacm, soft_purge, soft_purge, []}, {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmpm_mpd, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, []}, - {add_module, snmpm_net_if_mt} + {update, snmpa_agent, soft, soft_purge, soft_purge, []}, + {add_module, snmpm_net_if_mt} ] }, {"4.21.3", [ + {load_module, snmp, soft_purge, soft_purge, [snmp_log]}, + {load_module, snmpa, soft_purge, soft_purge, [snmp]}, + {load_module, snmpm, soft_purge, soft_purge, [snmp]}, + {load_module, snmp_log, soft_purge, soft_purge, []}, {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, {load_module, snmpa_vacm, soft_purge, soft_purge, []}, {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmpm_mpd, soft_purge, soft_purge, []}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, []}, - {add_module, snmpm_net_if_mt} + {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, + {update, snmpa_agent, soft, soft_purge, soft_purge, []}, + {add_module, snmpm_net_if_mt} ] }, {"4.21.2", [ + {load_module, snmp, soft_purge, soft_purge, [snmp_log]}, + {load_module, snmpa, soft_purge, soft_purge, [snmp]}, + {load_module, snmpm, soft_purge, soft_purge, [snmp]}, + {load_module, snmp_log, soft_purge, soft_purge, []}, {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, {load_module, snmpa_vacm, soft_purge, soft_purge, []}, {load_module, snmpa_mpd, soft_purge, soft_purge, []}, @@ -79,13 +103,17 @@ {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmpm_mpd, soft_purge, soft_purge, []}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, []}, - {add_module, snmpm_net_if_mt} + {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, + {update, snmpa_agent, soft, soft_purge, soft_purge, []}, + {add_module, snmpm_net_if_mt} ] }, {"4.21.1", [ + {load_module, snmp, soft_purge, soft_purge, [snmp_log]}, + {load_module, snmpa, soft_purge, soft_purge, [snmp]}, + {load_module, snmpm, soft_purge, soft_purge, [snmp]}, + {load_module, snmp_log, soft_purge, soft_purge, []}, {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, {load_module, snmpa_vacm, soft_purge, soft_purge, []}, {load_module, snmpa_mpd, soft_purge, soft_purge, []}, @@ -94,14 +122,18 @@ {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmpm_mpd, soft_purge, soft_purge, []}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, []}, - {update, snmp_note_store, soft, soft_purge, soft_purge, []}, - {add_module, snmpm_net_if_mt} + {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, + {update, snmpa_agent, soft, soft_purge, soft_purge, []}, + {update, snmp_note_store, soft, soft_purge, soft_purge, []}, + {add_module, snmpm_net_if_mt} ] }, {"4.21", [ + {load_module, snmp, soft_purge, soft_purge, [snmp_log]}, + {load_module, snmpa, soft_purge, soft_purge, [snmp]}, + {load_module, snmpm, soft_purge, soft_purge, [snmp]}, + {load_module, snmp_log, soft_purge, soft_purge, []}, {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, {load_module, snmpa_vacm, soft_purge, soft_purge, []}, {load_module, snmpa_mpd, soft_purge, soft_purge, []}, @@ -111,10 +143,10 @@ {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmpm_mpd, soft_purge, soft_purge, []}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, []}, - {update, snmp_note_store, soft, soft_purge, soft_purge, []}, - {add_module, snmpm_net_if_mt} + {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, + {update, snmpa_agent, soft, soft_purge, soft_purge, []}, + {update, snmp_note_store, soft, soft_purge, soft_purge, []}, + {add_module, snmpm_net_if_mt} ] } ], @@ -125,50 +157,76 @@ %% This is a place holder {"4.21.7", [ + {load_module, snmp, soft_purge, soft_purge, [snmp_log]}, + {load_module, snmpa, soft_purge, soft_purge, [snmp]}, + {load_module, snmpm, soft_purge, soft_purge, [snmp]}, + {load_module, snmp_log, soft_purge, soft_purge, []}, {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmpm_mpd, soft_purge, soft_purge, []}, - {add_module, snmpm_net_if_mt} + {remove, {snmpm_net_if_mt, soft_purge, soft_purge}} ] }, %% This is a place holder {"4.21.6", [ + {load_module, snmp, soft_purge, soft_purge, [snmp_log]}, + {load_module, snmpa, soft_purge, soft_purge, [snmp]}, + {load_module, snmpm, soft_purge, soft_purge, [snmp]}, + {load_module, snmp_log, soft_purge, soft_purge, []}, {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmpm_mpd, soft_purge, soft_purge, []}, - {add_module, snmpm_net_if_mt} + {remove, {snmpm_net_if_mt, soft_purge, soft_purge}} ] }, %% This is a place holder {"4.21.5", [ + {load_module, snmp, soft_purge, soft_purge, [snmp_log]}, + {load_module, snmpa, soft_purge, soft_purge, [snmp]}, + {load_module, snmpm, soft_purge, soft_purge, [snmp]}, + {load_module, snmp_log, soft_purge, soft_purge, []}, {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmpm_mpd, soft_purge, soft_purge, []}, - {add_module, snmpm_net_if_mt} + {remove, {snmpm_net_if_mt, soft_purge, soft_purge}} ] }, {"4.21.4", [ + {load_module, snmp, soft_purge, soft_purge, [snmp_log]}, + {load_module, snmpa, soft_purge, soft_purge, [snmp]}, + {load_module, snmpm, soft_purge, soft_purge, [snmp]}, + {load_module, snmp_log, soft_purge, soft_purge, []}, {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, {load_module, snmpa_vacm, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, []}, - {add_module, snmpm_net_if_mt} + {load_module, snmp_verbosity, soft_purge, soft_purge, []}, + {load_module, snmpm_mpd, soft_purge, soft_purge, []}, + {update, snmpa_agent, soft, soft_purge, soft_purge, []}, + {remove, {snmpm_net_if_mt, soft_purge, soft_purge}} ] }, {"4.21.3", [ + {load_module, snmp, soft_purge, soft_purge, [snmp_log]}, + {load_module, snmpa, soft_purge, soft_purge, [snmp]}, + {load_module, snmpm, soft_purge, soft_purge, [snmp]}, + {load_module, snmp_log, soft_purge, soft_purge, []}, {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, {load_module, snmpa_vacm, soft_purge, soft_purge, []}, {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmpm_mpd, soft_purge, soft_purge, []}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, []}, - {add_module, snmpm_net_if_mt} + {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, + {update, snmpa_agent, soft, soft_purge, soft_purge, []}, + {remove, {snmpm_net_if_mt, soft_purge, soft_purge}} ] }, {"4.21.2", [ + {load_module, snmp, soft_purge, soft_purge, [snmp_log]}, + {load_module, snmpa, soft_purge, soft_purge, [snmp]}, + {load_module, snmpm, soft_purge, soft_purge, [snmp]}, + {load_module, snmp_log, soft_purge, soft_purge, []}, {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, {load_module, snmpa_vacm, soft_purge, soft_purge, []}, {load_module, snmpa_mpd, soft_purge, soft_purge, []}, @@ -177,13 +235,17 @@ {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmpm_mpd, soft_purge, soft_purge, []}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, []}, - {add_module, snmpm_net_if_mt} + {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, + {update, snmpa_agent, soft, soft_purge, soft_purge, []}, + {remove, {snmpm_net_if_mt, soft_purge, soft_purge}} ] }, {"4.21.1", [ + {load_module, snmp, soft_purge, soft_purge, [snmp_log]}, + {load_module, snmpa, soft_purge, soft_purge, [snmp]}, + {load_module, snmpm, soft_purge, soft_purge, [snmp]}, + {load_module, snmp_log, soft_purge, soft_purge, []}, {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, {load_module, snmpa_vacm, soft_purge, soft_purge, []}, {load_module, snmpa_mpd, soft_purge, soft_purge, []}, @@ -192,14 +254,18 @@ {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmpm_mpd, soft_purge, soft_purge, []}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, []}, - {update, snmp_note_store, soft, soft_purge, soft_purge, []}, - {add_module, snmpm_net_if_mt} + {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, + {update, snmpa_agent, soft, soft_purge, soft_purge, []}, + {update, snmp_note_store, soft, soft_purge, soft_purge, []}, + {remove, {snmpm_net_if_mt, soft_purge, soft_purge}} ] }, {"4.21", [ + {load_module, snmp, soft_purge, soft_purge, [snmp_log]}, + {load_module, snmpa, soft_purge, soft_purge, [snmp]}, + {load_module, snmpm, soft_purge, soft_purge, [snmp]}, + {load_module, snmp_log, soft_purge, soft_purge, []}, {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, {load_module, snmpa_vacm, soft_purge, soft_purge, []}, {load_module, snmpa_mpd, soft_purge, soft_purge, []}, @@ -209,10 +275,10 @@ {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmpm_mpd, soft_purge, soft_purge, []}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, []}, - {update, snmp_note_store, soft, soft_purge, soft_purge, []}, - {add_module, snmpm_net_if_mt} + {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, + {update, snmpa_agent, soft, soft_purge, soft_purge, []}, + {update, snmp_note_store, soft, soft_purge, soft_purge, []}, + {remove, {snmpm_net_if_mt, soft_purge, soft_purge}} ] } ] -- cgit v1.2.3 From 12e0e58dafd2b891df90118ba55333914e4d0f5d Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 23 Feb 2012 12:05:07 +0100 Subject: [snmp/agent] Documenting previously existing but undocumented function Documenting previously existing but undocumented function, snmp_generic:get_table_info/2. OTP-9942 --- lib/snmp/doc/src/notes.xml | 52 +++++++++++++++++++++++++ lib/snmp/doc/src/snmp_generic.xml | 81 +++++++++++++++++++++++++++++++++------ lib/snmp/vsn.mk | 2 +- 3 files changed, 122 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 704ff0a20f..a40e325ea2 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -33,6 +33,58 @@
+
+ SNMP Development Toolkit 4.22 +

Version 4.22 supports code replacement in runtime from/to + version 4.21.7, 4.21.6, 4.21.5, 4.21.4, 4.21.3, 4.21.2, 4.21.1 and + 4.21.

+ +
+ Improvements and new features + + + + +

[agent] Documenting previously existing but undocumented function, + snmp_generic:get_table_info/2.

+

Own Id: OTP-9942

+
+ +
+ +
+ +
+ Reported Fixed Bugs and Malfunctions +

-

+ + + +
+ +
+ Incompatibilities +

-

+
+ +
+ +
SNMP Development Toolkit 4.21.7

Version 4.21.7 supports code replacement in runtime from/to diff --git a/lib/snmp/doc/src/snmp_generic.xml b/lib/snmp/doc/src/snmp_generic.xml index 77f3cefaa2..79a22323d9 100644 --- a/lib/snmp/doc/src/snmp_generic.xml +++ b/lib/snmp/doc/src/snmp_generic.xml @@ -1,10 +1,10 @@ - +

- 19962009 + 19962012 Ericsson AB. All Rights Reserved. @@ -34,15 +34,16 @@ snmp_generic Generic Functions for Implementing SNMP Objects in a Database -

The module snmp_generic contains generic functions for implementing tables - (and variables) using the SNMP built-in database or Mnesia. These - default functions are used if no instrumentation function is - provided for a managed object in a MIB. Sometimes, it might be - necessary to customize the behaviour of the default functions. For - example, in some situations a trap should be sent if a row is - deleted or modified, or some hardware is to be informed, when - information is changed. -

+ +

The module snmp_generic contains generic functions for + implementing tables (and variables) using the SNMP built-in database + or Mnesia. These default functions are used if no instrumentation + function is provided for a managed object in a MIB. Sometimes, + it might be necessary to customize the behaviour of the default + functions. For example, in some situations a trap should be sent + if a row is deleted or modified, or some hardware is to be informed, + when information is changed.

+

The overall structure is shown in the following figure:

          +---------------+
@@ -93,6 +94,7 @@
   
 
   
+ DATA TYPES

In the functions defined below, the following types are used:

@@ -118,7 +120,10 @@ value() = term() case of a set operation.

+ +
+ get_status_col(Name, Cols) @@ -136,8 +141,11 @@ value() = term()

This function can be used in instrumentation functions for is_set_ok, undo or set to check if the status column of a table is modified.

+ +
+ get_index_types(Name) Get the index types of Name @@ -147,9 +155,36 @@ value() = term()

Gets the index types of Name

This function can be used in instrumentation functions to - retrieve the index types part of the table info.

+ retrieve the index types part of the table info.

+ +
+ + + get_table_info(Name, Item) -> table_info_result() + Get table info item of MIB table Name + + Name = name() + Item = table_item() | all + table_item() = nbr_of_cols | defvals | status_col | not_accessible | + index_types | first_accessible | first_own_index + table_info_result() = Value | [{table_item(), Value}] + Value = term() + + +

Get a specific table info item or, if Item has the + value all, a two tuple list (property list) is instead + returned with all the items and their respctive values of the + given table.

+ +

This function can be used in instrumentation functions to + retrieve a given part of the table info.

+ + +
+
+ table_func(Op1, NameDb) table_func(Op2, RowIndex, Cols, NameDb) -> Ret @@ -190,8 +225,11 @@ value() = term()

The function returns according to the specification of an instrumentation function.

+ +
+ table_get_elements(NameDb, RowIndex, Cols) -> Values Get elements in a table row @@ -204,8 +242,11 @@ value() = term()

Returns a list with values for all columns in Cols. If a column is undefined, its value is noinit.

+ +
+ table_next(NameDb, RestOid) -> RowIndex | endOfTable Find the next row in the table @@ -217,8 +258,11 @@ value() = term()

Finds the indices of the next row in the table. RestOid does not have to specify an existing row.

+ +
+ table_row_exists(NameDb, RowIndex) -> bool() Check if a row in a table exists @@ -228,8 +272,11 @@ value() = term()

Checks if a row in a table exists.

+ +
+ table_set_elements(NameDb, RowIndex, Cols) -> bool() Set elements in a table row @@ -246,8 +293,11 @@ value() = term() mnesia:write to store the values. This means that this function must be called from within a transaction (mnesia:transaction/1 or mnesia:dirty/1).

+ +
+ variable_func(Op1, NameDb) variable_func(Op2, Val, NameDb) -> Ret @@ -268,8 +318,11 @@ value() = term() the database.

The function returns according to the specification of an instrumentation function.

+ +
+ variable_get(NameDb) -> {value, Value} | undefined Get the value of a variable @@ -279,8 +332,11 @@ value() = term()

Gets the value of a variable.

+ +
+ variable_set(NameDb, NewVal) -> true | false Set a value for a variable @@ -299,6 +355,7 @@ value() = term()
+ Example

The following example shows an implementation of a table which is stored in Mnesia, but with some checks performed at set-request diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index fb1dcb6c41..36b9764bc8 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -18,6 +18,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 4.21.7 +SNMP_VSN = 4.22 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From f6b7aade87b64c4c60eba65dfac6310a8c7bf139 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 24 Feb 2012 09:50:33 +0100 Subject: [snmp] Fixed verbosity timestamp --- lib/snmp/src/misc/snmp_verbosity.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/snmp/src/misc/snmp_verbosity.erl b/lib/snmp/src/misc/snmp_verbosity.erl index f2f85ebf79..df5986b7bc 100644 --- a/lib/snmp/src/misc/snmp_verbosity.erl +++ b/lib/snmp/src/misc/snmp_verbosity.erl @@ -76,7 +76,7 @@ format_timestamp({_N1, _N2, N3} = Now) -> {YYYY,MM,DD} = Date, {Hour,Min,Sec} = Time, FormatDate = - io_lib:format("~.4w:~.2.0w:~.2.0w ~.2.0w:~.2.0w:~.2.0w 4~w", + io_lib:format("~.4w:~.2.0w:~.2.0w ~.2.0w:~.2.0w:~.2.0w ~w", [YYYY,MM,DD,Hour,Min,Sec,round(N3/1000)]), lists:flatten(FormatDate). -- cgit v1.2.3 From 92e37200fdfba41a625615b5b8e8308e363393aa Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 24 Feb 2012 15:29:04 +0100 Subject: [snmp/agent] Improve error handling while reading agent config files Improve error handling while reading agent config files. OTP-9943 --- lib/snmp/src/agent/snmp_community_mib.erl | 19 ++++++++++++++---- lib/snmp/src/agent/snmp_framework_mib.erl | 27 +++++++++++++++++--------- lib/snmp/src/agent/snmp_notification_mib.erl | 19 ++++++++++++++---- lib/snmp/src/agent/snmp_standard_mib.erl | 17 +++++++++++----- lib/snmp/src/agent/snmp_target_mib.erl | 8 ++++---- lib/snmp/src/agent/snmp_user_based_sm_mib.erl | 6 +++--- lib/snmp/src/agent/snmp_view_based_acm_mib.erl | 2 +- lib/snmp/src/misc/snmp_conf.erl | 17 ++++++++++++++-- lib/snmp/vsn.mk | 2 +- 9 files changed, 84 insertions(+), 33 deletions(-) (limited to 'lib') diff --git a/lib/snmp/src/agent/snmp_community_mib.erl b/lib/snmp/src/agent/snmp_community_mib.erl index 77307aa7ad..d7d41aca31 100644 --- a/lib/snmp/src/agent/snmp_community_mib.erl +++ b/lib/snmp/src/agent/snmp_community_mib.erl @@ -28,6 +28,7 @@ -export([add_community/5, add_community/6, delete_community/1]). -export([check_community/1]). +-include("snmpa_internal.hrl"). -include("SNMP-COMMUNITY-MIB.hrl"). -include("SNMP-TARGET-MIB.hrl"). -include("SNMPv2-TC.hrl"). @@ -120,10 +121,17 @@ init_tabs(Comms) -> read_community_config_files(Dir) -> ?vdebug("read community config file",[]), - Gen = fun(_) -> ok end, - Filter = fun(Comms) -> Comms end, - Check = fun(Entry) -> check_community(Entry) end, - [Comms] = + FileName = "community.conf", + Gen = fun(D, Reason) -> + warning_msg("failed reading config file ~s" + "~n Config Dir: ~s" + "~n Reason: ~p", + [FileName, D, Reason]), + ok + end, + Filter = fun(Comms) -> Comms end, + Check = fun(Entry) -> check_community(Entry) end, + [Comms] = snmp_conf:read_files(Dir, [{Gen, Filter, Check, "community.conf"}]), Comms. @@ -601,5 +609,8 @@ set_sname(_) -> %% Keep it, if already set. error(Reason) -> throw({error, Reason}). +warning_msg(F, A) -> + ?snmpa_warning("[COMMUNITY-MIB]: " ++ F, A). + config_err(F, A) -> snmpa_error:config_err("[COMMUNITY-MIB]: " ++ F, A). diff --git a/lib/snmp/src/agent/snmp_framework_mib.erl b/lib/snmp/src/agent/snmp_framework_mib.erl index 0d7866d94d..cc191bd956 100644 --- a/lib/snmp/src/agent/snmp_framework_mib.erl +++ b/lib/snmp/src/agent/snmp_framework_mib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1999-2010. All Rights Reserved. +%% Copyright Ericsson AB 1999-2012. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -115,7 +115,9 @@ do_configure(Dir) -> read_internal_config_files(Dir) -> ?vdebug("read context config file",[]), - Gen = fun(D) -> convert_context(D) end, + Gen = fun(D, Reason) -> + convert_context(D, Reason) + end, Filter = fun(Contexts) -> Contexts end, Check = fun(Entry) -> check_context(Entry) end, [Ctxs] = snmp_conf:read_files(Dir, [{Gen, Filter, Check, "context.conf"}]), @@ -123,10 +125,17 @@ read_internal_config_files(Dir) -> read_agent(Dir) -> - ?vdebug("read agent config file",[]), - Check = fun(Entry) -> check_agent(Entry) end, - File = filename:join(Dir, "agent.conf"), - Agent = snmp_conf:read(File, Check), + ?vdebug("read agent config file", []), + FileName = "agent.conf", + Check = fun(Entry) -> check_agent(Entry) end, + File = filename:join(Dir, FileName), + Agent = + try + snmp_conf:read(File, Check) + catch + throw:{error, Reason} -> + error({failed_reading_config_file, Dir, FileName, Reason}) + end, sort_agent(Agent). @@ -146,9 +155,9 @@ sort_agent(L) -> %%----------------------------------------------------------------- %% Generate a context.conf file. %%----------------------------------------------------------------- -convert_context(Dir) -> +convert_context(Dir, _Reason) -> config_err("missing context.conf file => generating a default file", []), - File = filename:join(Dir,"context.conf"), + File = filename:join(Dir, "context.conf"), case file:open(File, [write]) of {ok, Fid} -> ok = io:format(Fid, "~s\n", [context_header()]), @@ -165,7 +174,7 @@ context_header() -> io_lib:format("%% This file was automatically generated by " "snmp_config v~s ~w-~2.2.0w-~2.2.0w " "~2.2.0w:~2.2.0w:~2.2.0w\n", - [?version,Y,Mo,D,H,Mi,S]). + [?version, Y, Mo, D, H, Mi, S]). %%----------------------------------------------------------------- diff --git a/lib/snmp/src/agent/snmp_notification_mib.erl b/lib/snmp/src/agent/snmp_notification_mib.erl index 720ac749b8..37e09f5d3e 100644 --- a/lib/snmp/src/agent/snmp_notification_mib.erl +++ b/lib/snmp/src/agent/snmp_notification_mib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1998-2011. All Rights Reserved. +%% Copyright Ericsson AB 1998-2012. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -27,6 +27,7 @@ -export([add_notify/3, delete_notify/1]). -export([check_notify/1]). +-include("snmpa_internal.hrl"). -include("SNMP-NOTIFICATION-MIB.hrl"). -include("SNMPv2-TC.hrl"). -include("snmp_tables.hrl"). @@ -104,7 +105,14 @@ do_reconfigure(Dir) -> read_notify_config_files(Dir) -> ?vdebug("read notify config file",[]), - Gen = fun(_) -> ok end, + FileName = "notify.conf", + Gen = fun(D, Reason) -> + info_msg("failed reading config file ~s" + "~n Config Dir: ~s" + "~n Reason: ~p", + [FileName, D, Reason]), + ok + end, Filter = fun(Notifs) -> Notifs end, Check = fun(Entry) -> check_notify(Entry) end, [Notifs] = @@ -112,7 +120,7 @@ read_notify_config_files(Dir) -> Notifs. check_notify({Name, Tag, Type}) -> - snmp_conf:check_string(Name,{gt,0}), + snmp_conf:check_string(Name, {gt, 0}), snmp_conf:check_string(Tag), {ok, Val} = snmp_conf:check_atom(Type, [{trap, 1}, {inform, 2}]), Notify = {Name, Tag, Val, @@ -451,12 +459,15 @@ set_sname() -> set_sname(get(sname)). set_sname(undefined) -> - put(sname,conf); + put(sname, conf); set_sname(_) -> %% Keep it, if already set. ok. error(Reason) -> throw({error, Reason}). +info_msg(F, A) -> + ?snmpa_info("[NOTIFICATION-MIB]: " ++ F, A). + config_err(F, A) -> snmpa_error:config_err("[NOTIFICATION-MIB]: " ++ F, A). diff --git a/lib/snmp/src/agent/snmp_standard_mib.erl b/lib/snmp/src/agent/snmp_standard_mib.erl index b6834d278c..7db94e7bd5 100644 --- a/lib/snmp/src/agent/snmp_standard_mib.erl +++ b/lib/snmp/src/agent/snmp_standard_mib.erl @@ -143,18 +143,24 @@ do_reconfigure(Dir) -> %% Func: read_standard/1 %% Args: Dir is the directory with trailing dir_separator where %% the configuration files can be found. -%% Purpose: Reads th standard configuration file. +%% Purpose: Reads the standard configuration file. %% Returns: A list of standard variables %% Fails: If an error occurs, the process will die with Reason %% configuration_error. +%% This file is mandatory, as it contains mandatory +%% config options for which there are no default values. %%----------------------------------------------------------------- read_standard(Dir) -> ?vdebug("check standard config file",[]), - Gen = fun(_) -> ok end, - Filter = fun(Standard) -> sort_standard(Standard) end, - Check = fun(Entry) -> check_standard(Entry) end, + FileName = "standard.conf", + Gen = fun(D, Reason) -> + throw({error, {failed_reading_config_file, + D, FileName, Reason}}) + end, + Filter = fun(Standard) -> sort_standard(Standard) end, + Check = fun(Entry) -> check_standard(Entry) end, [Standard] = - snmp_conf:read_files(Dir, [{Gen, Filter, Check, "standard.conf"}]), + snmp_conf:read_files(Dir, [{Gen, Filter, Check, FileName}]), Standard. @@ -548,6 +554,7 @@ snmp_set_serial_no(set, NewVal) -> snmp_generic:variable_func(set, (NewVal + 1) rem 2147483648, {snmpSetSerialNo, volatile}). + %%----------------------------------------------------------------- %% This is the instrumentation function for sysOrTable %%----------------------------------------------------------------- diff --git a/lib/snmp/src/agent/snmp_target_mib.erl b/lib/snmp/src/agent/snmp_target_mib.erl index a45db89c09..b01d536caa 100644 --- a/lib/snmp/src/agent/snmp_target_mib.erl +++ b/lib/snmp/src/agent/snmp_target_mib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1998-2011. All Rights Reserved. +%% Copyright Ericsson AB 1998-2012. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -132,12 +132,12 @@ do_reconfigure(Dir) -> read_target_config_files(Dir) -> - ?vdebug("check target address config file",[]), - TAGen = fun(_D) -> ok end, + ?vdebug("check target address and parameter config file(s)",[]), + TAGen = fun(_D, _Reason) -> ok end, TAFilter = fun(Addr) -> Addr end, TACheck = fun(Entry) -> check_target_addr(Entry) end, - TPGen = fun(_D) -> ok end, + TPGen = fun(_D, _Reason) -> ok end, TPFilter = fun(Params) -> Params end, TPCheck = fun(Entry) -> check_target_params(Entry) end, diff --git a/lib/snmp/src/agent/snmp_user_based_sm_mib.erl b/lib/snmp/src/agent/snmp_user_based_sm_mib.erl index 69cebc858b..2e801622e7 100644 --- a/lib/snmp/src/agent/snmp_user_based_sm_mib.erl +++ b/lib/snmp/src/agent/snmp_user_based_sm_mib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1999-2010. All Rights Reserved. +%% Copyright Ericsson AB 1999-2012. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -136,7 +136,7 @@ do_reconfigure(Dir) -> read_usm_config_files(Dir) -> ?vdebug("read usm config file",[]), - Gen = fun(D) -> generate_usm(D) end, + Gen = fun(D, Reason) -> generate_usm(D, Reason) end, Filter = fun(Usms) -> Usms end, Check = fun(Entry) -> check_usm(Entry) end, [Usms] = @@ -144,7 +144,7 @@ read_usm_config_files(Dir) -> Usms. -generate_usm(Dir) -> +generate_usm(Dir, _Reason) -> info_msg("Incomplete configuration. Generating empty usm.conf.", []), USMFile = filename:join(Dir, "usm.conf"), ok = file:write_file(USMFile, list_to_binary([])). diff --git a/lib/snmp/src/agent/snmp_view_based_acm_mib.erl b/lib/snmp/src/agent/snmp_view_based_acm_mib.erl index 2cee91b081..479a44795f 100644 --- a/lib/snmp/src/agent/snmp_view_based_acm_mib.erl +++ b/lib/snmp/src/agent/snmp_view_based_acm_mib.erl @@ -115,7 +115,7 @@ do_reconfigure(Dir) -> read_vacm_config_files(Dir) -> ?vdebug("read vacm config file",[]), - Gen = fun(_) -> ok end, + Gen = fun(_D, _Reason) -> ok end, Filter = fun(Vacms) -> Sec2Group = [X || {vacmSecurityToGroup, X} <- Vacms], Access = [X || {vacmAccess, X} <- Vacms], diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index 7249def24e..e1e7fab57b 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2011. All Rights Reserved. +%% Copyright Ericsson AB 1996-2012. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -71,6 +71,18 @@ %%----------------------------------------------------------------- +%% read_files(Dir, Files) -> Configs +%% Dir - string() - Full path to the config dir. +%% Files - [{Gen, Filter, Check, FileName}] +%% Gen - function/2 - In case of failure when reading the config file, +%% this function is called to either generate a +%% default file or issue the error. +%% Filter - function/1 - Filters all the config entries read from the file +%% Check - function/1 - Check each entry as they are read from the file. +%% FileName - string() - Name of the config file. +%% Configs - [config_entry()] +%% config_entry() - term() + read_files(Dir, Files) when is_list(Dir) andalso is_list(Files) -> read_files(Dir, Files, []). @@ -90,7 +102,7 @@ read_files(Dir, [{Gen, Filter, Check, FileName}|Files], Res) {error, R} -> ?vlog("failed reading file info for ~s: " "~n ~p", [FileName, R]), - Gen(Dir), + Gen(Dir, R), read_files(Dir, Files, [Filter([])|Res]) end. @@ -99,6 +111,7 @@ read_files(Dir, [{Gen, Filter, Check, FileName}|Files], Res) read(File, Check) when is_function(Check) -> ?vdebug("read -> entry with" "~n File: ~p", [File]), + Fd = open_file(File), case loop(Fd, [], Check, 1, File) of diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index fb1dcb6c41..36b9764bc8 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -18,6 +18,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 4.21.7 +SNMP_VSN = 4.22 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From d11e013575ed400b7167342be4b08ba3d1166ee9 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 27 Feb 2012 14:33:16 +0100 Subject: [snmp/agent] Updated release notes and preliminary appup OTP-9943 --- lib/snmp/doc/src/notes.xml | 52 +++++++++++++ lib/snmp/src/app/snmp.appup.src | 157 +++++++--------------------------------- 2 files changed, 78 insertions(+), 131 deletions(-) (limited to 'lib') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 704ff0a20f..e0c7af4393 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -33,6 +33,58 @@

+
+ SNMP Development Toolkit 4.22 +

Version 4.22 supports code replacement in runtime from/to + version 4.21.7, 4.21.6, 4.21.5, 4.21.4, 4.21.3, 4.21.2, 4.21.1 and 4.21.

+ +
+ Improvements and new features + + + + +

[agent] Improve error handling while reading agent config files. + Some files contain mandatory information and is therefor themself + mandatory.

+

Own Id: OTP-9943

+
+ +
+ +
+ +
+ Reported Fixed Bugs and Malfunctions + + + + +

[agent] Simultaneous + snmpa:backup/1,2 + calls can interfere. + The master agent did not check if a backup was already in + progress when a backup request was accepted.

+

Own Id: OTP-9884

+

Aux Id: Seq 11995

+
+ +
+ +
+ +
+ Incompatibilities +

-

+
+ +
+ +
SNMP Development Toolkit 4.21.7

Version 4.21.7 supports code replacement in runtime from/to diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index c8e5eec6db..a0c065dba3 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -22,6 +22,18 @@ %% ----- U p g r a d e ------------------------------------------------------- [ + {"4.21.7", + [ + {load_module, snmp_conf, soft_purge, soft_purge, []}, + {load_module, snmp_community_mib, soft_purge, soft_purge, [snmp_conf]}, + {load_module, snmp_framework_mib, soft_purge, soft_purge, [snmp_conf]}, + {load_module, snmp_notification_mib, soft_purge, soft_purge, [snmp_conf]}, + {load_module, snmp_standard_mib, soft_purge, soft_purge, [snmp_conf]}, + {load_module, snmp_target_mib, soft_purge, soft_purge, [snmp_conf]}, + {load_module, snmp_user_based_sm_mib, soft_purge, soft_purge, [snmp_conf]}, + {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, [snmp_conf]} + ] + }, {"4.21.6", [ {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, @@ -128,78 +140,25 @@ {update, snmpa_mib, soft, soft_purge, soft_purge, []}, {update, snmpa_agent, soft, soft_purge, soft_purge, []}, {update, snmp_note_store, soft, soft_purge, soft_purge, []} - ] - }, - {"4.20.1", - [ - {load_module, snmpa, soft_purge, soft_purge, []}, - {load_module, snmpa_mib_lib, soft_purge, soft_purge, []}, - {update, snmpa_supervisor, soft, soft_purge, soft_purge, []}, - - {load_module, snmpa_vacm, soft_purge, soft_purge, []}, - {load_module, snmpa_set_lib, soft_purge, soft_purge, []}, - {load_module, snmpa_trap, soft_purge, soft_purge, []}, - {load_module, snmp_target_mib, soft_purge, soft_purge, [snmpa_mib_lib]}, - {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, - {load_module, snmpm, soft_purge, soft_purge, - [snmpm_server, snmpm_config, snmp_config]}, - {load_module, snmp_conf, soft_purge, soft_purge, []}, - {load_module, snmp_config, soft_purge, soft_purge, []}, - {load_module, snmpm_mpd, soft_purge, soft_purge, - [snmp_conf, snmp_config, snmpm_config]}, - {load_module, snmpa_mpd, soft_purge, soft_purge, - [snmp_conf, snmp_config]}, - {load_module, snmpa_conf, soft_purge, soft_purge, [snmp_config]}, - {update, snmp_note_store, soft, soft_purge, soft_purge, []}, - {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_mib, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_mpd]}, - {update, snmpm_config, soft, soft_purge, soft_purge, [snmp_conf]}, - {update, snmpm_server, soft, soft_purge, soft_purge, - [snmpm_net_if, snmpm_mpd, snmpm_config]}, - {update, snmpm_net_if, soft, soft_purge, soft_purge, - [snmp_conf, snmpm_mpd, snmpm_config]} - ] - }, - {"4.20", - [ - {load_module, snmpa, soft_purge, soft_purge, []}, - {load_module, snmpa_mib_lib, soft_purge, soft_purge, []}, - {update, snmpa_supervisor, soft, soft_purge, soft_purge, []}, - - {load_module, snmpa_vacm, soft_purge, soft_purge, []}, - {load_module, snmpa_set_lib, soft_purge, soft_purge, []}, - {load_module, snmpa_trap, soft_purge, soft_purge, []}, - {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, - {load_module, snmp_target_mib, soft_purge, soft_purge, - [snmpa_mib_lib, snmp_conf]}, - {load_module, snmpm, soft_purge, soft_purge, - [snmpm_server, snmpm_config, snmp_config]}, - {load_module, snmp_conf, soft_purge, soft_purge, []}, - {load_module, snmp_config, soft_purge, soft_purge, []}, - {load_module, snmpm_mpd, soft_purge, soft_purge, - [snmp_conf, snmp_config, snmpm_config]}, - {load_module, snmpa_mpd, soft_purge, soft_purge, - [snmp_conf, snmp_config]}, - {load_module, snmpa_conf, soft_purge, soft_purge, [snmp_config]}, - {update, snmp_note_store, soft, soft_purge, soft_purge, []}, - {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_mib, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_mpd]}, - {update, snmpm_config, soft, soft_purge, soft_purge, [snmp_conf]}, - {update, snmpm_server, soft, soft_purge, soft_purge, - [snmpm_net_if, snmpm_mpd, snmpm_config]}, - {update, snmpm_net_if, soft, soft_purge, soft_purge, - [snmp_conf, snmpm_mpd, snmpm_config]} - ] - } + ] + } ], %% ------D o w n g r a d e --------------------------------------------------- [ + {"4.21.7", + [ + {load_module, snmp_conf, soft_purge, soft_purge, []}, + {load_module, snmp_community_mib, soft_purge, soft_purge, [snmp_conf]}, + {load_module, snmp_framework_mib, soft_purge, soft_purge, [snmp_conf]}, + {load_module, snmp_notification_mib, soft_purge, soft_purge, [snmp_conf]}, + {load_module, snmp_standard_mib, soft_purge, soft_purge, [snmp_conf]}, + {load_module, snmp_target_mib, soft_purge, soft_purge, [snmp_conf]}, + {load_module, snmp_user_based_sm_mib, soft_purge, soft_purge, [snmp_conf]}, + {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, [snmp_conf]} + ] + }, {"4.21.6", [ {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, @@ -307,70 +266,6 @@ {update, snmpa_agent, soft, soft_purge, soft_purge, []}, {update, snmp_note_store, soft, soft_purge, soft_purge, []} ] - }, - {"4.20.1", - [ - {load_module, snmpa, soft_purge, soft_purge, []}, - {load_module, snmpa_mib_lib, soft_purge, soft_purge, []}, - {update, snmpa_supervisor, soft, soft_purge, soft_purge, []}, - - {load_module, snmpa_vacm, soft_purge, soft_purge, []}, - {load_module, snmpa_set_lib, soft_purge, soft_purge, []}, - {load_module, snmpa_trap, soft_purge, soft_purge, []}, - {load_module, snmp_target_mib, soft_purge, soft_purge, []}, - {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, - {load_module, snmpm, soft_purge, soft_purge, - [snmpm_server, snmpm_config, snmp_config]}, - {load_module, snmp_conf, soft_purge, soft_purge, []}, - {load_module, snmp_config, soft_purge, soft_purge, []}, - {load_module, snmpm_mpd, soft_purge, soft_purge, - [snmp_conf, snmp_config, snmpm_config]}, - {load_module, snmpa_mpd, soft_purge, soft_purge, - [snmp_conf, snmp_config]}, - {load_module, snmpa_conf, soft_purge, soft_purge, [snmp_config]}, - {update, snmp_note_store, soft, soft_purge, soft_purge, []}, - {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_mib, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_mpd]}, - {update, snmpm_config, soft, soft_purge, soft_purge, [snmp_conf]}, - {update, snmpm_server, soft, soft_purge, soft_purge, - [snmpm_net_if, snmpm_mpd, snmpm_config]}, - {update, snmpm_net_if, soft, soft_purge, soft_purge, - [snmp_conf, snmpm_mpd, snmpm_config]} - ] - }, - {"4.20", - [ - {load_module, snmpa, soft_purge, soft_purge, []}, - {load_module, snmpa_mib_lib, soft_purge, soft_purge, []}, - {update, snmpa_supervisor, soft, soft_purge, soft_purge, []}, - - {load_module, snmpa_vacm, soft_purge, soft_purge, []}, - {load_module, snmpa_set_lib, soft_purge, soft_purge, []}, - {load_module, snmpa_trap, soft_purge, soft_purge, []}, - {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, - {load_module, snmp_target_mib, soft_purge, soft_purge, [snmp_conf]}, - {load_module, snmpm, soft_purge, soft_purge, - [snmpm_server, snmpm_config, snmp_config]}, - {load_module, snmp_conf, soft_purge, soft_purge, []}, - {load_module, snmp_config, soft_purge, soft_purge, []}, - {load_module, snmpm_mpd, soft_purge, soft_purge, - [snmp_conf, snmp_config, snmpm_config]}, - {load_module, snmpa_mpd, soft_purge, soft_purge, - [snmp_conf, snmp_config]}, - {load_module, snmpa_conf, soft_purge, soft_purge, [snmp_config]}, - {update, snmp_note_store, soft, soft_purge, soft_purge, []}, - {load_module, snmp_generic_mnesia, soft_purge, soft_purge, []}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_mib, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_mpd]}, - {update, snmpm_config, soft, soft_purge, soft_purge, [snmp_conf]}, - {update, snmpm_server, soft, soft_purge, soft_purge, - [snmpm_net_if, snmpm_mpd, snmpm_config]}, - {update, snmpm_net_if, soft, soft_purge, soft_purge, - [snmp_conf, snmpm_mpd, snmpm_config]} - ] } ] }. -- cgit v1.2.3 From 5834b490b8f426e2bbdec7d0b41459e09fdfb82a Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 1 Mar 2012 18:09:22 +0100 Subject: [snmp/agent] Add dir listing to error reason Add dir listing to error reason when failing to read mandatory config file standard.conf. OTP-9943 --- lib/snmp/src/agent/snmp_standard_mib.erl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/snmp/src/agent/snmp_standard_mib.erl b/lib/snmp/src/agent/snmp_standard_mib.erl index 7db94e7bd5..7c78e03b3b 100644 --- a/lib/snmp/src/agent/snmp_standard_mib.erl +++ b/lib/snmp/src/agent/snmp_standard_mib.erl @@ -155,7 +155,8 @@ read_standard(Dir) -> FileName = "standard.conf", Gen = fun(D, Reason) -> throw({error, {failed_reading_config_file, - D, FileName, Reason}}) + D, FileName, + file:list_dir(Dir), Reason}}) end, Filter = fun(Standard) -> sort_standard(Standard) end, Check = fun(Entry) -> check_standard(Entry) end, @@ -595,4 +596,4 @@ error(Reason) -> throw({error, Reason}). config_err(F, A) -> - snmpa_error:config_err("[STANDARD-MIB]: " ++ F, A). + snmpa_error:config_err("[STANDARD-MIB] " ++ F, A). -- cgit v1.2.3 From c5a16ad3551a87a9bb361a8bce220cb849247d43 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 5 Mar 2012 14:07:35 +0100 Subject: [snmp/agent] Some minor improvements to the error messages OTP-9943 --- lib/snmp/src/agent/snmp_standard_mib.erl | 10 ++- lib/snmp/src/app/snmp.appup.src | 2 + lib/snmp/src/misc/snmp_config.erl | 102 +++++++++++++++++++++++++++---- 3 files changed, 100 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/snmp/src/agent/snmp_standard_mib.erl b/lib/snmp/src/agent/snmp_standard_mib.erl index 7c78e03b3b..ca93546923 100644 --- a/lib/snmp/src/agent/snmp_standard_mib.erl +++ b/lib/snmp/src/agent/snmp_standard_mib.erl @@ -156,7 +156,7 @@ read_standard(Dir) -> Gen = fun(D, Reason) -> throw({error, {failed_reading_config_file, D, FileName, - file:list_dir(Dir), Reason}}) + list_dir(Dir), Reason}}) end, Filter = fun(Standard) -> sort_standard(Standard) end, Check = fun(Entry) -> check_standard(Entry) end, @@ -164,6 +164,14 @@ read_standard(Dir) -> snmp_conf:read_files(Dir, [{Gen, Filter, Check, FileName}]), Standard. +list_dir(Dir) -> + case file:list_dir(Dir) of + {ok, Files} -> + Files; + Error -> + Error + end. + %%----------------------------------------------------------------- %% Make sure that each mandatory standard attribute is present, and diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index a0c065dba3..60877c547e 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -24,6 +24,7 @@ [ {"4.21.7", [ + {load_module, snmp_config, soft_purge, soft_purge, []}, {load_module, snmp_conf, soft_purge, soft_purge, []}, {load_module, snmp_community_mib, soft_purge, soft_purge, [snmp_conf]}, {load_module, snmp_framework_mib, soft_purge, soft_purge, [snmp_conf]}, @@ -149,6 +150,7 @@ [ {"4.21.7", [ + {load_module, snmp_config, soft_purge, soft_purge, []}, {load_module, snmp_conf, soft_purge, soft_purge, []}, {load_module, snmp_community_mib, soft_purge, soft_purge, [snmp_conf]}, {load_module, snmp_framework_mib, soft_purge, soft_purge, [snmp_conf]}, diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index 6ab20e3e48..8bf0ea945b 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -90,6 +90,17 @@ ]). +-export_type([void/0, + verify_config_entry_function/0, + verify_config_function/0, + write_config_function/0]). + + +%%---------------------------------------------------------------------- + +-type void() :: term(). % Any value - ignored + + %%---------------------------------------------------------------------- %% Handy SNMP configuration %%---------------------------------------------------------------------- @@ -2356,53 +2367,118 @@ write_sys_config_file_manager_atl_opt(Fid, {seqno, SeqNo}) -> header() -> - {Y,Mo,D} = date(), - {H,Mi,S} = time(), + {Y, Mo, D} = date(), + {H, Mi, S} = time(), io_lib:format("%% This file was generated by " - "snmp_config (version-~s) ~w-~2.2.0w-~2.2.0w " + "~w (version-~s) ~w-~2.2.0w-~2.2.0w " "~2.2.0w:~2.2.0w:~2.2.0w\n", - [?version,Y,Mo,D,H,Mi,S]). + [?MODULE, ?version, Y, Mo, D, H, Mi, S]). + +%% *If* these functions are successfull, they successfully return anything +%% (which is ignored), but they fail with either a throw or an exit or +%% something similar. + +%% Verification of one config entry read from a file +-type(verify_config_entry_function() :: + fun((Entry :: term()) -> ok | {error, Reason :: term()})). + +%% Verification of config to be written +-type(verify_config_function() :: + fun(() -> void())). + +%% Write config to file (as defined by Fd) +-type(write_config_function() :: + fun((Fd :: file:io_device()) -> void())). + +-spec write_config_file(Dir :: string(), + FileName :: string(), + Verify :: verify_config_function(), + Write :: write_config_function()) -> + ok | {error, Reason :: term()}. write_config_file(Dir, FileName, Verify, Write) when (is_list(Dir) andalso is_list(FileName) andalso is_function(Verify) andalso is_function(Write)) -> - (catch do_write_config_file(Dir, FileName, Verify, Write)). + try + begin + do_write_config_file(Dir, FileName, Verify, Write) + end + catch + throw:Error -> + Error; + T:E -> + {error, {failed_write, Dir, FileName, T, E}} + end. + do_write_config_file(Dir, FileName, Verify, Write) -> + io:format("do_write_config_file -> entry with" + "~n Dir: ~p" + "~n FileName: ~p" + "~nwhen" + "~n FileInfo(Dir): ~p" + "~n FileList(Dir): ~p" + "~n", [Dir, FileName, + file:read_file_info(filename:join(Dir, FileName)), + file:list_dir(Dir)]), Verify(), case file:open(filename:join(Dir, FileName), [write]) of {ok, Fd} -> - (catch Write(Fd)), - file:close(Fd), - ok; + file_write_and_close(Write, Fd, Dir, FileName); Error -> Error end. - append_config_file(Dir, FileName, Verify, Write) when (is_list(Dir) andalso is_list(FileName) andalso is_function(Verify) andalso is_function(Write)) -> - (catch do_append_config_file(Dir, FileName, Verify, Write)). + try + begin + do_append_config_file(Dir, FileName, Verify, Write) + end + catch + throw:Error -> + Error; + T:E -> + {error, {failed_append, Dir, FileName, T, E}} + end. do_append_config_file(Dir, FileName, Verify, Write) -> Verify(), case file:open(filename:join(Dir, FileName), [read, write]) of {ok, Fd} -> file:position(Fd, eof), - (catch Write(Fd)), - file:close(Fd), - ok; + file_write_and_close(Write, Fd, Dir, FileName); Error -> Error end. +file_write_and_close(Write, Fd, Dir, FileName) -> + ok = Write(Fd), + case file:sync(Fd) of + ok -> + case file:close(Fd) of + ok -> + ok; + {error, Reason} -> + {error, {failed_closing, Dir, FileName, Reason}} + end; + {error, Reason} -> + {error, {failed_syncing, Dir, FileName, Reason}} + end. + + +-spec read_config_file(Dir :: string(), + FileName :: string(), + Verify :: verify_config_entry_function()) -> + {ok, Config :: list()} | {error, Reason :: term()}. + read_config_file(Dir, FileName, Verify) when is_list(Dir) andalso is_list(FileName) andalso is_function(Verify) -> (catch do_read_config_file(Dir, FileName, Verify)). -- cgit v1.2.3 From c4ef63a7d48b06123fb0b96f38f2a8b7df32fe49 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 5 Mar 2012 14:09:37 +0100 Subject: [snmp] Misc cosmetic changes to some test suites OTP-9943 --- lib/snmp/test/snmp_agent_test.erl | 3 +-- lib/snmp/test/snmp_app_test.erl | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index e968bc65b1..21cf267bea 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -224,8 +224,7 @@ groups() -> }, {tickets2, [], [otp8395, otp9884]}, {otp_4394, [], [otp_4394_test]}, - {otp_7157, [], [otp_7157_test] - } + {otp_7157, [], [otp_7157_test]} ]. init_per_group(all_tcs, Config) -> diff --git a/lib/snmp/test/snmp_app_test.erl b/lib/snmp/test/snmp_app_test.erl index bc62c8d530..18cfee6fa2 100644 --- a/lib/snmp/test/snmp_app_test.erl +++ b/lib/snmp/test/snmp_app_test.erl @@ -23,7 +23,7 @@ -module(snmp_app_test). -export([ - all/0,groups/0,init_per_group/2,end_per_group/2, init_per_suite/1, + all/0,groups/0,init_per_group/2,end_per_group/2, init_per_suite/1, end_per_suite/1, init_per_testcase/2, end_per_testcase/2, @@ -52,24 +52,24 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% all() -> -Cases = [fields, modules, exportall, app_depend, - undef_funcs, {group, start_and_stop}], - Cases. + Cases = [fields, modules, exportall, app_depend, + undef_funcs, {group, start_and_stop}], + Cases. groups() -> [{start_and_stop, [], - [start_and_stop_empty, start_and_stop_with_agent, - start_and_stop_with_manager, - start_and_stop_with_agent_and_manager, - start_epmty_and_then_agent_and_manager_and_stop, - start_with_agent_and_then_manager_and_stop, - start_with_manager_and_then_agent_and_stop]}]. + [start_and_stop_empty, start_and_stop_with_agent, + start_and_stop_with_manager, + start_and_stop_with_agent_and_manager, + start_epmty_and_then_agent_and_manager_and_stop, + start_with_agent_and_then_manager_and_stop, + start_with_manager_and_then_agent_and_stop]}]. init_per_group(_GroupName, Config) -> - Config. + Config. end_per_group(_GroupName, Config) -> - Config. + Config. init_per_suite(Config) when is_list(Config) -> -- cgit v1.2.3 From 1b98726bb9306714bc6c52d00a88aacff2b007a4 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 9 Mar 2012 17:33:44 +0100 Subject: [snmp/compiler] Add a more up-to-date version of a test mib OTP-9969 --- lib/snmp/test/test-mibs/RMON-MIB.mib | 7782 +++++++++++++++++----------------- 1 file changed, 3957 insertions(+), 3825 deletions(-) (limited to 'lib') diff --git a/lib/snmp/test/test-mibs/RMON-MIB.mib b/lib/snmp/test/test-mibs/RMON-MIB.mib index 0824dbde1d..fa5bc82f4a 100644 --- a/lib/snmp/test/test-mibs/RMON-MIB.mib +++ b/lib/snmp/test/test-mibs/RMON-MIB.mib @@ -1,3826 +1,3958 @@ - RMON-MIB DEFINITIONS ::= BEGIN - - IMPORTS - Counter FROM RFC1155-SMI - mib-2,DisplayString FROM RFC1213-MIB - OBJECT-TYPE FROM RFC-1212 - TRAP-TYPE FROM RFC-1215; - - -- Remote Network Monitoring MIB - - rmon OBJECT IDENTIFIER ::= { mib-2 16 } - - - -- textual conventions - - OwnerString ::= DisplayString - -- This data type is used to model an administratively - -- assigned name of the owner of a resource. This - -- information is taken from the NVT ASCII character - -- set. It is suggested that this name contain one or - - - -- more of the following: IP address, management station - -- name, network manager's name, location, or phone - -- number. - -- In some cases the agent itself will be the owner of - -- an entry. In these cases, this string shall be set - -- to a string starting with 'monitor'. - -- - -- SNMP access control is articulated entirely in terms - -- of the contents of MIB views; access to a particular - -- SNMP object instance depends only upon its presence - -- or absence in a particular MIB view and never upon - -- its value or the value of related object instances. - -- Thus, objects of this type afford resolution of - -- resource contention only among cooperating managers; - -- they realize no access control function with respect - -- to uncooperative parties. - -- - -- By convention, objects with this syntax are declared as - -- having - -- - -- SIZE (0..127) - - EntryStatus ::= INTEGER - { valid(1), - createRequest(2), - underCreation(3), - invalid(4) - } - -- The status of a table entry. - -- - -- Setting this object to the value invalid(4) has the - -- effect of invalidating the corresponding entry. - -- That is, it effectively disassociates the mapping - -- identified with said entry. - -- It is an implementation-specific matter as to whether - -- the agent removes an invalidated entry from the table. - -- Accordingly, management stations must be prepared to - -- receive tabular information from agents that - -- corresponds to entries currently not in use. Proper - -- interpretation of such entries requires examination - -- of the relevant EntryStatus object. - -- - -- An existing instance of this object cannot be set to - -- createRequest(2). This object may only be set to - -- createRequest(2) when this instance is created. When - -- this object is created, the agent may wish to create - -- supplemental object instances with default values - -- to complete a conceptual row in this table. Because - - - -- the creation of these default objects is entirely at - -- the option of the agent, the manager must not assume - -- that any will be created, but may make use of any that - -- are created. Immediately after completing the create - -- operation, the agent must set this object to - -- underCreation(3). - -- - -- When in the underCreation(3) state, an entry is - -- allowed to exist in a possibly incomplete, possibly - -- inconsistent state, usually to allow it to be - -- modified in mutiple PDUs. When in this state, an - -- entry is not fully active. Entries shall exist in - -- the underCreation(3) state until the management - -- station is finished configuring the entry and sets - -- this object to valid(1) or aborts, setting this - -- object to invalid(4). If the agent determines that - -- an entry has been in the underCreation(3) state for - -- an abnormally long time, it may decide that the - -- management station has crashed. If the agent makes - -- this decision, it may set this object to invalid(4) - -- to reclaim the entry. A prudent agent will - -- understand that the management station may need to - -- wait for human input and will allow for that - -- possibility in its determination of this abnormally - -- long period. - -- - -- An entry in the valid(1) state is fully configured and - -- consistent and fully represents the configuration or - -- operation such a row is intended to represent. For - -- example, it could be a statistical function that is - -- configured and active, or a filter that is available - -- in the list of filters processed by the packet capture - -- process. - -- - -- A manager is restricted to changing the state of an - -- entry in the following ways: - -- - -- create under - -- To: valid Request Creation invalid - -- From: - -- valid OK NO OK OK - -- createRequest N/A N/A N/A N/A - -- underCreation OK NO OK OK - -- invalid NO NO NO OK - -- nonExistent NO OK NO OK - -- - -- In the table above, it is not applicable to move the - -- state from the createRequest state to any other - - - -- state because the manager will never find the - -- variable in that state. The nonExistent state is - -- not a value of the enumeration, rather it means that - -- the entryStatus variable does not exist at all. - -- - -- An agent may allow an entryStatus variable to change - -- state in additional ways, so long as the semantics - -- of the states are followed. This allowance is made - -- to ease the implementation of the agent and is made - -- despite the fact that managers should never - -- excercise these additional state transitions. - - - statistics OBJECT IDENTIFIER ::= { rmon 1 } - history OBJECT IDENTIFIER ::= { rmon 2 } - alarm OBJECT IDENTIFIER ::= { rmon 3 } - hosts OBJECT IDENTIFIER ::= { rmon 4 } - hostTopN OBJECT IDENTIFIER ::= { rmon 5 } - matrix OBJECT IDENTIFIER ::= { rmon 6 } - filter OBJECT IDENTIFIER ::= { rmon 7 } - capture OBJECT IDENTIFIER ::= { rmon 8 } - event OBJECT IDENTIFIER ::= { rmon 9 } - - - -- The Ethernet Statistics Group - -- - -- Implementation of the Ethernet Statistics group is - -- optional. - -- - -- The ethernet statistics group contains statistics - -- measured by the probe for each monitored interface on - -- this device. These statistics take the form of free - -- running counters that start from zero when a valid entry - -- is created. - -- - -- This group currently has statistics defined only for - -- Ethernet interfaces. Each etherStatsEntry contains - -- statistics for one Ethernet interface. The probe must - -- create one etherStats entry for each monitored Ethernet - -- interface on the device. - - etherStatsTable OBJECT-TYPE - SYNTAX SEQUENCE OF EtherStatsEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A list of Ethernet statistics entries." - ::= { statistics 1 } - - - etherStatsEntry OBJECT-TYPE - SYNTAX EtherStatsEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A collection of statistics kept for a particular - Ethernet interface. As an example, an instance of the - etherStatsPkts object might be named etherStatsPkts.1" - INDEX { etherStatsIndex } - ::= { etherStatsTable 1 } - - EtherStatsEntry ::= SEQUENCE { - etherStatsIndex INTEGER (1..65535), - etherStatsDataSource OBJECT IDENTIFIER, - etherStatsDropEvents Counter, - etherStatsOctets Counter, - etherStatsPkts Counter, - etherStatsBroadcastPkts Counter, - etherStatsMulticastPkts Counter, - etherStatsCRCAlignErrors Counter, - etherStatsUndersizePkts Counter, - etherStatsOversizePkts Counter, - etherStatsFragments Counter, - etherStatsJabbers Counter, - etherStatsCollisions Counter, - etherStatsPkts64Octets Counter, - etherStatsPkts65to127Octets Counter, - etherStatsPkts128to255Octets Counter, - etherStatsPkts256to511Octets Counter, - etherStatsPkts512to1023Octets Counter, - etherStatsPkts1024to1518Octets Counter, - etherStatsOwner OwnerString, - etherStatsStatus EntryStatus - } - - etherStatsIndex OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The value of this object uniquely identifies this - etherStats entry." - ::= { etherStatsEntry 1 } - - etherStatsDataSource OBJECT-TYPE - SYNTAX OBJECT IDENTIFIER - ACCESS read-write - STATUS mandatory - - - DESCRIPTION - "This object identifies the source of the data that - this etherStats entry is configured to analyze. This - source can be any ethernet interface on this device. - In order to identify a particular interface, this - object shall identify the instance of the ifIndex - object, defined in RFC 1213 and RFC 1573 [4,6], for - the desired interface. For example, if an entry - were to receive data from interface #1, this object - would be set to ifIndex.1. - - The statistics in this group reflect all packets - on the local network segment attached to the - identified interface. - - An agent may or may not be able to tell if - fundamental changes to the media of the interface - have occurred and necessitate an invalidation of - this entry. For example, a hot-pluggable ethernet - card could be pulled out and replaced by a - token-ring card. In such a case, if the agent has - such knowledge of the change, it is recommended that - it invalidate this entry. - - This object may not be modified if the associated - etherStatsStatus object is equal to valid(1)." - ::= { etherStatsEntry 2 } - - etherStatsDropEvents OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The total number of events in which packets - were dropped by the probe due to lack of resources. - Note that this number is not necessarily the number of - packets dropped; it is just the number of times this - condition has been detected." - ::= { etherStatsEntry 3 } - - etherStatsOctets OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The total number of octets of data (including - those in bad packets) received on the - network (excluding framing bits but including - - - FCS octets). - - This object can be used as a reasonable estimate of - ethernet utilization. If greater precision is - desired, the etherStatsPkts and etherStatsOctets - objects should be sampled before and after a common - interval. The differences in the sampled values are - Pkts and Octets, respectively, and the number of - seconds in the interval is Interval. These values - are used to calculate the Utilization as follows: - - Pkts * (9.6 + 6.4) + (Octets * .8) - Utilization = ------------------------------------- - Interval * 10,000 - - The result of this equation is the value Utilization - which is the percent utilization of the ethernet - segment on a scale of 0 to 100 percent." - ::= { etherStatsEntry 4 } - - etherStatsPkts OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The total number of packets (including bad packets, - broadcast packets, and multicast packets) received." - ::= { etherStatsEntry 5 } - - etherStatsBroadcastPkts OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The total number of good packets received that were - directed to the broadcast address. Note that this - does not include multicast packets." - ::= { etherStatsEntry 6 } - - etherStatsMulticastPkts OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The total number of good packets received that were - directed to a multicast address. Note that this - number does not include packets directed to the - broadcast address." - - - ::= { etherStatsEntry 7 } - - etherStatsCRCAlignErrors OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The total number of packets received that - had a length (excluding framing bits, but - including FCS octets) of between 64 and 1518 - octets, inclusive, but but had either a bad - Frame Check Sequence (FCS) with an integral - number of octets (FCS Error) or a bad FCS with - a non-integral number of octets (Alignment Error)." - ::= { etherStatsEntry 8 } - - etherStatsUndersizePkts OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The total number of packets received that were - less than 64 octets long (excluding framing bits, - but including FCS octets) and were otherwise well - formed." - ::= { etherStatsEntry 9 } - - etherStatsOversizePkts OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The total number of packets received that were - longer than 1518 octets (excluding framing bits, - but including FCS octets) and were otherwise - well formed." - ::= { etherStatsEntry 10 } - - etherStatsFragments OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The total number of packets received that were less - than 64 octets in length (excluding framing bits but - including FCS octets) and had either a bad Frame - Check Sequence (FCS) with an integral number of - octets (FCS Error) or a bad FCS with a non-integral - - - number of octets (Alignment Error). - - Note that it is entirely normal for - etherStatsFragments to increment. This is because - it counts both runts (which are normal occurrences - due to collisions) and noise hits." - ::= { etherStatsEntry 11 } - - etherStatsJabbers OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The total number of packets received that were - longer than 1518 octets (excluding framing bits, - but including FCS octets), and had either a bad - Frame Check Sequence (FCS) with an integral number - of octets (FCS Error) or a bad FCS with a - non-integral number of octets (Alignment Error). - - Note that this definition of jabber is different - than the definition in IEEE-802.3 section 8.2.1.5 - (10BASE5) and section 10.3.1.4 (10BASE2). These - documents define jabber as the condition where any - packet exceeds 20 ms. The allowed range to detect - jabber is between 20 ms and 150 ms." - ::= { etherStatsEntry 12 } - - etherStatsCollisions OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The best estimate of the total number of collisions - on this Ethernet segment. - - The value returned will depend on the location of - the RMON probe. Section 8.2.1.3 (10BASE-5) and - section 10.3.1.3 (10BASE-2) of IEEE standard 802.3 - states that a station must detect a collision, in - the receive mode, if three or more stations are - transmitting simultaneously. A repeater port must - detect a collision when two or more stations are - transmitting simultaneously. Thus a probe placed on - a repeater port could record more collisions than a - probe connected to a station on the same segment - would. - - - - Probe location plays a much smaller role when - considering 10BASE-T. 14.2.1.4 (10BASE-T) of IEEE - standard 802.3 defines a collision as the - simultaneous presence of signals on the DO and RD - circuits (transmitting and receiving at the same - time). A 10BASE-T station can only detect - collisions when it is transmitting. Thus probes - placed on a station and a repeater, should report - the same number of collisions. - - Note also that an RMON probe inside a repeater - should ideally report collisions between the - repeater and one or more other hosts (transmit - collisions as defined by IEEE 802.3k) plus receiver - collisions observed on any coax segments to which - the repeater is connected." - ::= { etherStatsEntry 13 } - - etherStatsPkts64Octets OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The total number of packets (including bad - packets) received that were 64 octets in length - (excluding framing bits but including FCS octets)." - ::= { etherStatsEntry 14 } - - etherStatsPkts65to127Octets OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The total number of packets (including bad - packets) received that were between - 65 and 127 octets in length inclusive - (excluding framing bits but including FCS octets)." - ::= { etherStatsEntry 15 } - - etherStatsPkts128to255Octets OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The total number of packets (including bad - packets) received that were between - 128 and 255 octets in length inclusive - (excluding framing bits but including FCS octets)." - - - ::= { etherStatsEntry 16 } - - etherStatsPkts256to511Octets OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The total number of packets (including bad - packets) received that were between - 256 and 511 octets in length inclusive - (excluding framing bits but including FCS octets)." - ::= { etherStatsEntry 17 } - - etherStatsPkts512to1023Octets OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The total number of packets (including bad - packets) received that were between - 512 and 1023 octets in length inclusive - (excluding framing bits but including FCS octets)." - ::= { etherStatsEntry 18 } - - etherStatsPkts1024to1518Octets OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The total number of packets (including bad - packets) received that were between - 1024 and 1518 octets in length inclusive - (excluding framing bits but including FCS octets)." - ::= { etherStatsEntry 19 } - - etherStatsOwner OBJECT-TYPE - SYNTAX OwnerString - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The entity that configured this entry and is - therefore using the resources assigned to it." - ::= { etherStatsEntry 20 } - - etherStatsStatus OBJECT-TYPE - SYNTAX EntryStatus - ACCESS read-write - STATUS mandatory - - - DESCRIPTION - "The status of this etherStats entry." - ::= { etherStatsEntry 21 } - - - -- The History Control Group - - -- Implementation of the History Control group is optional. - -- - -- The history control group controls the periodic statistical - -- sampling of data from various types of networks. The - -- historyControlTable stores configuration entries that each - -- define an interface, polling period, and other parameters. - -- Once samples are taken, their data is stored in an entry - -- in a media-specific table. Each such entry defines one - -- sample, and is associated with the historyControlEntry that - -- caused the sample to be taken. Each counter in the - -- etherHistoryEntry counts the same event as its - -- similarly-named counterpart in the etherStatsEntry, - -- except that each value here is a cumulative sum during a - -- sampling period. - -- - -- If the probe keeps track of the time of day, it should - -- start the first sample of the history at a time such that - -- when the next hour of the day begins, a sample is - -- started at that instant. This tends to make more - -- user-friendly reports, and enables comparison of reports - -- from different probes that have relatively accurate time - -- of day. - -- - -- The probe is encouraged to add two history control entries - -- per monitored interface upon initialization that describe - -- a short term and a long term polling period. Suggested - -- parameters are 30 seconds for the short term polling period - -- and 30 minutes for the long term period. - - historyControlTable OBJECT-TYPE - SYNTAX SEQUENCE OF HistoryControlEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A list of history control entries." - ::= { history 1 } - - historyControlEntry OBJECT-TYPE - SYNTAX HistoryControlEntry - ACCESS not-accessible - STATUS mandatory - - - DESCRIPTION - "A list of parameters that set up a periodic sampling - of statistics. As an example, an instance of the - historyControlInterval object might be named - historyControlInterval.2" - INDEX { historyControlIndex } - ::= { historyControlTable 1 } - - HistoryControlEntry ::= SEQUENCE { - historyControlIndex INTEGER (1..65535), - historyControlDataSource OBJECT IDENTIFIER, - historyControlBucketsRequested INTEGER (1..65535), - historyControlBucketsGranted INTEGER (1..65535), - historyControlInterval INTEGER (1..3600), - historyControlOwner OwnerString, - historyControlStatus EntryStatus - } - - historyControlIndex OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "An index that uniquely identifies an entry in the - historyControl table. Each such entry defines a - set of samples at a particular interval for an - interface on the device." - ::= { historyControlEntry 1 } - - historyControlDataSource OBJECT-TYPE - SYNTAX OBJECT IDENTIFIER - ACCESS read-write - STATUS mandatory - DESCRIPTION - "This object identifies the source of the data for - which historical data was collected and - placed in a media-specific table on behalf of this - historyControlEntry. This source can be any - interface on this device. In order to identify - a particular interface, this object shall identify - the instance of the ifIndex object, defined - in RFC 1213 and RFC 1573 [4,6], for the desired - interface. For example, if an entry were to receive - data from interface #1, this object would be set - to ifIndex.1. - - The statistics in this group reflect all packets - on the local network segment attached to the - - - identified interface. - - An agent may or may not be able to tell if fundamental - changes to the media of the interface have occurred - and necessitate an invalidation of this entry. For - example, a hot-pluggable ethernet card could be - pulled out and replaced by a token-ring card. In - such a case, if the agent has such knowledge of the - change, it is recommended that it invalidate this - entry. - - This object may not be modified if the associated - historyControlStatus object is equal to valid(1)." - ::= { historyControlEntry 2 } - - historyControlBucketsRequested OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The requested number of discrete time intervals - over which data is to be saved in the part of the - media-specific table associated with this - historyControlEntry. - - When this object is created or modified, the probe - should set historyControlBucketsGranted as closely to - this object as is possible for the particular probe - implementation and available resources." - DEFVAL { 50 } - ::= { historyControlEntry 3 } - - historyControlBucketsGranted OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of discrete sampling intervals - over which data shall be saved in the part of - the media-specific table associated with this - historyControlEntry. - - When the associated historyControlBucketsRequested - object is created or modified, the probe - should set this object as closely to the requested - value as is possible for the particular - probe implementation and available resources. The - probe must not lower this value except as a result - - - of a modification to the associated - historyControlBucketsRequested object. - - There will be times when the actual number of - buckets associated with this entry is less than - the value of this object. In this case, at the - end of each sampling interval, a new bucket will - be added to the media-specific table. - - When the number of buckets reaches the value of - this object and a new bucket is to be added to the - media-specific table, the oldest bucket associated - with this historyControlEntry shall be deleted by - the agent so that the new bucket can be added. - - When the value of this object changes to a value less - than the current value, entries are deleted - from the media-specific table associated with this - historyControlEntry. Enough of the oldest of these - entries shall be deleted by the agent so that their - number remains less than or equal to the new value of - this object. - - When the value of this object changes to a value - greater than the current value, the number of - associated media- specific entries may be allowed to - grow." - ::= { historyControlEntry 4 } - - historyControlInterval OBJECT-TYPE - SYNTAX INTEGER (1..3600) - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The interval in seconds over which the data is - sampled for each bucket in the part of the - media-specific table associated with this - historyControlEntry. This interval can - be set to any number of seconds between 1 and - 3600 (1 hour). - - Because the counters in a bucket may overflow at their - maximum value with no indication, a prudent manager - will take into account the possibility of overflow - in any of the associated counters. It is important - to consider the minimum time in which any counter - could overflow on a particular media type and set - the historyControlInterval object to a value less - - - than this interval. This is typically most - important for the 'octets' counter in any - media-specific table. For example, on an Ethernet - network, the etherHistoryOctets counter could - overflow in about one hour at the Ethernet's maximum - utilization. - - This object may not be modified if the associated - historyControlStatus object is equal to valid(1)." - DEFVAL { 1800 } - ::= { historyControlEntry 5 } - - historyControlOwner OBJECT-TYPE - SYNTAX OwnerString - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The entity that configured this entry and is - therefore using the resources assigned to it." - ::= { historyControlEntry 6 } - - historyControlStatus OBJECT-TYPE - SYNTAX EntryStatus - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The status of this historyControl entry. - - Each instance of the media-specific table associated - with this historyControlEntry will be deleted by the - agent if this historyControlEntry is not equal to - valid(1)." - ::= { historyControlEntry 7 } - - - -- The Ethernet History Group - - -- Implementation of the Ethernet History group is optional. - -- - -- The Ethernet History group records periodic - -- statistical samples from a network and stores them - -- for later retrieval. Once samples are taken, their - -- data is stored in an entry in a media-specific - -- table. Each such entry defines one sample, and is - -- associated with the historyControlEntry that caused - -- the sample to be taken. This group defines the - -- etherHistoryTable, for Ethernet networks. - -- - - - etherHistoryTable OBJECT-TYPE - SYNTAX SEQUENCE OF EtherHistoryEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A list of Ethernet history entries." - ::= { history 2 } - - etherHistoryEntry OBJECT-TYPE - SYNTAX EtherHistoryEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "An historical sample of Ethernet statistics on a - particular Ethernet interface. This sample is - associated with the historyControlEntry which set up - the parameters for a regular collection of these - samples. As an example, an instance of the - etherHistoryPkts object might be named - etherHistoryPkts.2.89" - INDEX { etherHistoryIndex , etherHistorySampleIndex } - ::= { etherHistoryTable 1 } - - EtherHistoryEntry ::= SEQUENCE { - etherHistoryIndex INTEGER (1..65535), - etherHistorySampleIndex INTEGER (1..2147483647), - etherHistoryIntervalStart TimeTicks, - etherHistoryDropEvents Counter, - etherHistoryOctets Counter, - etherHistoryPkts Counter, - etherHistoryBroadcastPkts Counter, - etherHistoryMulticastPkts Counter, - etherHistoryCRCAlignErrors Counter, - etherHistoryUndersizePkts Counter, - etherHistoryOversizePkts Counter, - etherHistoryFragments Counter, - etherHistoryJabbers Counter, - etherHistoryCollisions Counter, - etherHistoryUtilization INTEGER (0..10000) - } - - etherHistoryIndex OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The history of which this entry is a part. The - history identified by a particular value of this - - - index is the same history as identified - by the same value of historyControlIndex." - ::= { etherHistoryEntry 1 } - - etherHistorySampleIndex OBJECT-TYPE - SYNTAX INTEGER (1..2147483647) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "An index that uniquely identifies the particular - sample this entry represents among all samples - associated with the same historyControlEntry. - This index starts at 1 and increases by one - as each new sample is taken." - ::= { etherHistoryEntry 2 } - - etherHistoryIntervalStart OBJECT-TYPE - SYNTAX TimeTicks - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The value of sysUpTime at the start of the interval - over which this sample was measured. If the probe - keeps track of the time of day, it should start - the first sample of the history at a time such that - when the next hour of the day begins, a sample is - started at that instant. Note that following this - rule may require the probe to delay collecting the - first sample of the history, as each sample must be - of the same interval. Also note that the sample which - is currently being collected is not accessible in this - table until the end of its interval." - ::= { etherHistoryEntry 3 } - - etherHistoryDropEvents OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The total number of events in which packets - were dropped by the probe due to lack of resources - during this sampling interval. Note that this number - is not necessarily the number of packets dropped, it - is just the number of times this condition has been - detected." - ::= { etherHistoryEntry 4 } - - etherHistoryOctets OBJECT-TYPE - - - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The total number of octets of data (including - those in bad packets) received on the - network (excluding framing bits but including - FCS octets)." - ::= { etherHistoryEntry 5 } - - etherHistoryPkts OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of packets (including bad packets) - received during this sampling interval." - ::= { etherHistoryEntry 6 } - - etherHistoryBroadcastPkts OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of good packets received during this - sampling interval that were directed to the - broadcast address." - ::= { etherHistoryEntry 7 } - - etherHistoryMulticastPkts OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of good packets received during this - sampling interval that were directed to a - multicast address. Note that this number does not - include packets addressed to the broadcast address." - ::= { etherHistoryEntry 8 } - - etherHistoryCRCAlignErrors OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of packets received during this sampling - interval that had a length (excluding framing bits - but including FCS octets) between 64 and 1518 - - - octets, inclusive, but had either a bad Frame Check - Sequence (FCS) with an integral number of octets - (FCS Error) or a bad FCS with a non-integral number - of octets (Alignment Error)." - ::= { etherHistoryEntry 9 } - - etherHistoryUndersizePkts OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of packets received during this - sampling interval that were less than 64 octets - long (excluding framing bits but including FCS - octets) and were otherwise well formed." - ::= { etherHistoryEntry 10 } - - etherHistoryOversizePkts OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of packets received during this - sampling interval that were longer than 1518 - octets (excluding framing bits but including - FCS octets) but were otherwise well formed." - ::= { etherHistoryEntry 11 } - - etherHistoryFragments OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The total number of packets received during this - sampling interval that were less than 64 octets in - length (excluding framing bits but including FCS - octets) had either a bad Frame Check Sequence (FCS) - with an integral number of octets (FCS Error) or a bad - FCS with a non-integral number of octets (Alignment - Error). - - Note that it is entirely normal for - etherHistoryFragments to increment. This is because - it counts both runts (which are normal occurrences - due to collisions) and noise hits." - ::= { etherHistoryEntry 12 } - - etherHistoryJabbers OBJECT-TYPE - - - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of packets received during this - sampling interval that were longer than 1518 octets - (excluding framing bits but including FCS octets), - and had either a bad Frame Check Sequence (FCS) - with an integral number of octets (FCS Error) or - a bad FCS with a non-integral number of octets - (Alignment Error). - - Note that this definition of jabber is different - than the definition in IEEE-802.3 section 8.2.1.5 - (10BASE5) and section 10.3.1.4 (10BASE2). These - documents define jabber as the condition where any - packet exceeds 20 ms. The allowed range to detect - jabber is between 20 ms and 150 ms." - ::= { etherHistoryEntry 13 } - - etherHistoryCollisions OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The best estimate of the total number of collisions - on this Ethernet segment during this sampling - interval. - - The value returned will depend on the location of - the RMON probe. Section 8.2.1.3 (10BASE-5) and - section 10.3.1.3 (10BASE-2) of IEEE standard 802.3 - states that a station must detect a collision, in - the receive mode, if three or more stations are - transmitting simultaneously. A repeater port must - detect a collision when two or more stations are - transmitting simultaneously. Thus a probe placed on - a repeater port could record more collisions than a - probe connected to a station on the same segment - would. - - Probe location plays a much smaller role when - considering 10BASE-T. 14.2.1.4 (10BASE-T) of IEEE - standard 802.3 defines a collision as the - simultaneous presence of signals on the DO and RD - circuits (transmitting and receiving at the same - time). A 10BASE-T station can only detect - collisions when it is transmitting. Thus probes - - - placed on a station and a repeater, should report - the same number of collisions. - - Note also that an RMON probe inside a repeater - should ideally report collisions between the - repeater and one or more other hosts (transmit - collisions as defined by IEEE 802.3k) plus receiver - collisions observed on any coax segments to which - the repeater is connected." - ::= { etherHistoryEntry 14 } - - etherHistoryUtilization OBJECT-TYPE - SYNTAX INTEGER (0..10000) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The best estimate of the mean physical layer - network utilization on this interface during this - sampling interval, in hundredths of a percent." - ::= { etherHistoryEntry 15 } - - - -- The Alarm Group - - -- Implementation of the Alarm group is optional. - -- - -- The Alarm Group requires the implementation of the Event - -- group. - -- - -- The Alarm group periodically takes - -- statistical samples from variables in the probe and - -- compares them to thresholds that have been - -- configured. The alarm table stores configuration - -- entries that each define a variable, polling period, - -- and threshold parameters. If a sample is found to - -- cross the threshold values, an event is generated. - -- Only variables that resolve to an ASN.1 primitive - -- type of INTEGER (INTEGER, Counter, Gauge, or - -- TimeTicks) may be monitored in this way. - -- - -- This function has a hysteresis mechanism to limit - -- the generation of events. This mechanism generates - -- one event as a threshold is crossed in the - -- appropriate direction. No more events are generated - -- for that threshold until the opposite threshold is - -- crossed. - -- - -- In the case of a sampling a deltaValue, a probe may - - - -- implement this mechanism with more precision if it - -- takes a delta sample twice per period, each time - -- comparing the sum of the latest two samples to the - -- threshold. This allows the detection of threshold - -- crossings that span the sampling boundary. Note - -- that this does not require any special configuration - -- of the threshold value. It is suggested that probes - -- implement this more precise algorithm. - - alarmTable OBJECT-TYPE - SYNTAX SEQUENCE OF AlarmEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A list of alarm entries." - ::= { alarm 1 } - - alarmEntry OBJECT-TYPE - SYNTAX AlarmEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A list of parameters that set up a periodic checking - for alarm conditions. For example, an instance of the - alarmValue object might be named alarmValue.8" - INDEX { alarmIndex } - ::= { alarmTable 1 } - - AlarmEntry ::= SEQUENCE { - alarmIndex INTEGER (1..65535), - alarmInterval INTEGER, - alarmVariable OBJECT IDENTIFIER, - alarmSampleType INTEGER, - alarmValue INTEGER, - alarmStartupAlarm INTEGER, - alarmRisingThreshold INTEGER, - alarmFallingThreshold INTEGER, - alarmRisingEventIndex INTEGER (0..65535), - alarmFallingEventIndex INTEGER (0..65535), - alarmOwner OwnerString, - alarmStatus EntryStatus - } - - alarmIndex OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-only - STATUS mandatory - DESCRIPTION - - - "An index that uniquely identifies an entry in the - alarm table. Each such entry defines a - diagnostic sample at a particular interval - for an object on the device." - ::= { alarmEntry 1 } - - alarmInterval OBJECT-TYPE - SYNTAX INTEGER - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The interval in seconds over which the data is - sampled and compared with the rising and falling - thresholds. When setting this variable, care - should be taken in the case of deltaValue - sampling - the interval should be set short enough - that the sampled variable is very unlikely to - increase or decrease by more than 2^31 - 1 during - a single sampling interval. - - This object may not be modified if the associated - alarmStatus object is equal to valid(1)." - ::= { alarmEntry 2 } - - alarmVariable OBJECT-TYPE - SYNTAX OBJECT IDENTIFIER - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The object identifier of the particular variable to - be sampled. Only variables that resolve to an ASN.1 - primitive type of INTEGER (INTEGER, Counter, Gauge, - or TimeTicks) may be sampled. - - Because SNMP access control is articulated entirely - in terms of the contents of MIB views, no access - control mechanism exists that can restrict the value - of this object to identify only those objects that - exist in a particular MIB view. Because there is - thus no acceptable means of restricting the read - access that could be obtained through the alarm - mechanism, the probe must only grant write access to - this object in those views that have read access to - all objects on the probe. - - During a set operation, if the supplied variable - name is not available in the selected MIB view, a - badValue error must be returned. If at any time the - - - variable name of an established alarmEntry is no - longer available in the selected MIB view, the probe - must change the status of this alarmEntry to - invalid(4). - - This object may not be modified if the associated - alarmStatus object is equal to valid(1)." - ::= { alarmEntry 3 } - - alarmSampleType OBJECT-TYPE - SYNTAX INTEGER { - absoluteValue(1), - deltaValue(2) - } - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The method of sampling the selected variable and - calculating the value to be compared against the - thresholds. If the value of this object is - absoluteValue(1), the value of the selected variable - will be compared directly with the thresholds at the - end of the sampling interval. If the value of this - object is deltaValue(2), the value of the selected - variable at the last sample will be subtracted from - the current value, and the difference compared with - the thresholds. - - This object may not be modified if the associated - alarmStatus object is equal to valid(1)." - ::= { alarmEntry 4 } - - alarmValue OBJECT-TYPE - SYNTAX INTEGER - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The value of the statistic during the last sampling - period. For example, if the sample type is - deltaValue, this value will be the difference - between the samples at the beginning and end of the - period. If the sample type is absoluteValue, this - value will be the sampled value at the end of the - period. - - This is the value that is compared with the rising and - falling thresholds. - - - - The value during the current sampling period is not - made available until the period is completed and will - remain available until the next period completes." - ::= { alarmEntry 5 } - - alarmStartupAlarm OBJECT-TYPE - SYNTAX INTEGER { - risingAlarm(1), - fallingAlarm(2), - risingOrFallingAlarm(3) - } - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The alarm that may be sent when this entry is first - set to valid. If the first sample after this entry - becomes valid is greater than or equal to the - risingThreshold and alarmStartupAlarm is equal to - risingAlarm(1) or risingOrFallingAlarm(3), then a - single rising alarm will be generated. If the first - sample after this entry becomes valid is less than - or equal to the fallingThreshold and - alarmStartupAlarm is equal to fallingAlarm(2) or - risingOrFallingAlarm(3), then a single falling alarm - will be generated. - - This object may not be modified if the associated - alarmStatus object is equal to valid(1)." - ::= { alarmEntry 6 } - - alarmRisingThreshold OBJECT-TYPE - SYNTAX INTEGER - ACCESS read-write - STATUS mandatory - DESCRIPTION - "A threshold for the sampled statistic. When the - current sampled value is greater than or equal to - this threshold, and the value at the last sampling - interval was less than this threshold, a single - event will be generated. A single event will also - be generated if the first sample after this entry - becomes valid is greater than or equal to this - threshold and the associated alarmStartupAlarm is - equal to risingAlarm(1) or risingOrFallingAlarm(3). - - After a rising event is generated, another such event - will not be generated until the sampled value - falls below this threshold and reaches the - - - alarmFallingThreshold. - - This object may not be modified if the associated - alarmStatus object is equal to valid(1)." - ::= { alarmEntry 7 } - - alarmFallingThreshold OBJECT-TYPE - SYNTAX INTEGER - ACCESS read-write - STATUS mandatory - DESCRIPTION - "A threshold for the sampled statistic. When the - current sampled value is less than or equal to this - threshold, and the value at the last sampling - interval was greater than this threshold, a single - event will be generated. A single event will also - be generated if the first sample after this entry - becomes valid is less than or equal to this - threshold and the associated alarmStartupAlarm is - equal to fallingAlarm(2) or risingOrFallingAlarm(3). - - After a falling event is generated, another such event - will not be generated until the sampled value - rises above this threshold and reaches the - alarmRisingThreshold. - - This object may not be modified if the associated - alarmStatus object is equal to valid(1)." - ::= { alarmEntry 8 } - - alarmRisingEventIndex OBJECT-TYPE - SYNTAX INTEGER (0..65535) - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The index of the eventEntry that is - used when a rising threshold is crossed. The - eventEntry identified by a particular value of - this index is the same as identified by the same value - of the eventIndex object. If there is no - corresponding entry in the eventTable, then - no association exists. In particular, if this value - is zero, no associated event will be generated, as - zero is not a valid event index. - - This object may not be modified if the associated - alarmStatus object is equal to valid(1)." - ::= { alarmEntry 9 } - - - alarmFallingEventIndex OBJECT-TYPE - SYNTAX INTEGER (0..65535) - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The index of the eventEntry that is - used when a falling threshold is crossed. The - eventEntry identified by a particular value of - this index is the same as identified by the same value - of the eventIndex object. If there is no - corresponding entry in the eventTable, then - no association exists. In particular, if this value - is zero, no associated event will be generated, as - zero is not a valid event index. - - This object may not be modified if the associated - alarmStatus object is equal to valid(1)." - ::= { alarmEntry 10 } - - alarmOwner OBJECT-TYPE - SYNTAX OwnerString - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The entity that configured this entry and is - therefore using the resources assigned to it." - ::= { alarmEntry 11 } - - alarmStatus OBJECT-TYPE - SYNTAX EntryStatus - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The status of this alarm entry." - ::= { alarmEntry 12 } - - - -- The Host Group - - -- Implementation of the Host group is optional. - -- - -- The host group discovers new hosts on the network by - -- keeping a list of source and destination MAC Addresses seen - -- in good packets. For each of these addresses, the host - -- group keeps a set of statistics. The hostControlTable - -- controls which interfaces this function is performed on, - -- and contains some information about the process. On - -- behalf of each hostControlEntry, data is collected on an - - - -- interface and placed in both the hostTable and the - -- hostTimeTable. If the monitoring device finds itself - -- short of resources, it may delete entries as needed. It - -- is suggested that the device delete the least recently - -- used entries first. - - -- The hostTable contains entries for each address - -- discovered on a particular interface. Each entry - -- contains statistical data about that host. This table is - -- indexed by the MAC address of the host, through which a - -- random access may be achieved. - - -- The hostTimeTable contains data in the same format as the - -- hostTable, and must contain the same set of hosts, but is - -- indexed using hostTimeCreationOrder rather than - -- hostAddress. - -- The hostTimeCreationOrder is an integer which reflects - -- the relative order in which a particular entry was - -- discovered and thus inserted into the table. As this - -- order, and thus the index, is among those entries - -- currently in the table, the index for a particular entry - -- may change if an (earlier) entry is deleted. Thus the - -- association between hostTimeCreationOrder and - -- hostTimeEntry may be broken at any time. - - -- The hostTimeTable has two important uses. The first is the - -- fast download of this potentially large table. Because the - -- index of this table runs from 1 to the size of the table, - -- inclusive, its values are predictable. This allows very - -- efficient packing of variables into SNMP PDU's and allows - -- a table transfer to have multiple packets outstanding. - -- These benefits increase transfer rates tremendously. - - -- The second use of the hostTimeTable is the efficient - -- discovery by the management station of new entries added - -- to the table. After the management station has downloaded - -- the entire table, it knows that new entries will be added - -- immediately after the end of the current table. It can - -- thus detect new entries there and retrieve them easily. - - -- Because the association between hostTimeCreationOrder and - -- hostTimeEntry may be broken at any time, the management - -- station must monitor the related hostControlLastDeleteTime - -- object. When the management station thus detects a - -- deletion, it must assume that any such associations have - --- been broken, and invalidate any it has stored locally. - -- This includes restarting any download of the - -- hostTimeTable that may have been in progress, as well as - - - -- rediscovering the end of the hostTimeTable so that it may - -- detect new entries. If the management station does not - -- detect the broken association, it may continue to refer - -- to a particular host by its creationOrder while - -- unwittingly retrieving the data associated with another - -- host entirely. If this happens while downloading the - -- host table, the management station may fail to download - -- all of the entries in the table. - - hostControlTable OBJECT-TYPE - SYNTAX SEQUENCE OF HostControlEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A list of host table control entries." - ::= { hosts 1 } - - hostControlEntry OBJECT-TYPE - SYNTAX HostControlEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A list of parameters that set up the discovery of - hosts on a particular interface and the collection - of statistics about these hosts. For example, an - instance of the hostControlTableSize object might be - named hostControlTableSize.1" - INDEX { hostControlIndex } - ::= { hostControlTable 1 } - - HostControlEntry ::= SEQUENCE { - hostControlIndex INTEGER (1..65535), - hostControlDataSource OBJECT IDENTIFIER, - hostControlTableSize INTEGER, - hostControlLastDeleteTime TimeTicks, - hostControlOwner OwnerString, - hostControlStatus EntryStatus - } - - hostControlIndex OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "An index that uniquely identifies an entry in the - hostControl table. Each such entry defines - a function that discovers hosts on a particular - interface and places statistics about them in the - - - hostTable and the hostTimeTable on behalf of this - hostControlEntry." - ::= { hostControlEntry 1 } - - hostControlDataSource OBJECT-TYPE - SYNTAX OBJECT IDENTIFIER - ACCESS read-write - STATUS mandatory - DESCRIPTION - "This object identifies the source of the data for - this instance of the host function. This source - can be any interface on this device. In order - to identify a particular interface, this object shall - identify the instance of the ifIndex object, defined - in RFC 1213 and RFC 1573 [4,6], for the desired - interface. For example, if an entry were to receive - data from interface #1, this object would be set to - ifIndex.1. - - The statistics in this group reflect all packets - on the local network segment attached to the - identified interface. - - An agent may or may not be able to tell if - fundamental changes to the media of the interface - have occurred and necessitate an invalidation of - this entry. For example, a hot-pluggable ethernet - card could be pulled out and replaced by a - token-ring card. In such a case, if the agent has - such knowledge of the change, it is recommended that - it invalidate this entry. - - This object may not be modified if the associated - hostControlStatus object is equal to valid(1)." - ::= { hostControlEntry 2 } - - hostControlTableSize OBJECT-TYPE - SYNTAX INTEGER - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of hostEntries in the hostTable and the - hostTimeTable associated with this hostControlEntry." - ::= { hostControlEntry 3 } - - hostControlLastDeleteTime OBJECT-TYPE - SYNTAX TimeTicks - ACCESS read-only - - - STATUS mandatory - DESCRIPTION - "The value of sysUpTime when the last entry - was deleted from the portion of the hostTable - associated with this hostControlEntry. If no - deletions have occurred, this value shall be zero." - ::= { hostControlEntry 4 } - - hostControlOwner OBJECT-TYPE - SYNTAX OwnerString - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The entity that configured this entry and is - therefore using the resources assigned to it." - ::= { hostControlEntry 5 } - - hostControlStatus OBJECT-TYPE - SYNTAX EntryStatus - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The status of this hostControl entry. - - If this object is not equal to valid(1), all - associated entries in the hostTable, hostTimeTable, - and the hostTopNTable shall be deleted by the - agent." - ::= { hostControlEntry 6 } - - hostTable OBJECT-TYPE - SYNTAX SEQUENCE OF HostEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A list of host entries." - ::= { hosts 2 } - - hostEntry OBJECT-TYPE - SYNTAX HostEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A collection of statistics for a particular host - that has been discovered on an interface of this - device. For example, an instance of the - hostOutBroadcastPkts object might be named - hostOutBroadcastPkts.1.6.8.0.32.27.3.176" - - - INDEX { hostIndex, hostAddress } - ::= { hostTable 1 } - - HostEntry ::= SEQUENCE { - hostAddress OCTET STRING, - hostCreationOrder INTEGER (1..65535), - hostIndex INTEGER (1..65535), - hostInPkts Counter, - hostOutPkts Counter, - hostInOctets Counter, - hostOutOctets Counter, - hostOutErrors Counter, - hostOutBroadcastPkts Counter, - hostOutMulticastPkts Counter - } - - hostAddress OBJECT-TYPE - SYNTAX OCTET STRING - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The physical address of this host." - ::= { hostEntry 1 } - - hostCreationOrder OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "An index that defines the relative ordering of - the creation time of hosts captured for a - particular hostControlEntry. This index shall - be between 1 and N, where N is the value of - the associated hostControlTableSize. The ordering - of the indexes is based on the order of each entry's - insertion into the table, in which entries added - earlier have a lower index value than entries added - later. - - It is important to note that the order for a - particular entry may change as an (earlier) entry - is deleted from the table. Because this order may - change, management stations should make use of the - hostControlLastDeleteTime variable in the - hostControlEntry associated with the relevant - portion of the hostTable. By observing - this variable, the management station may detect - the circumstances where a previous association - - - between a value of hostCreationOrder - and a hostEntry may no longer hold." - ::= { hostEntry 2 } - - hostIndex OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The set of collected host statistics of which - this entry is a part. The set of hosts - identified by a particular value of this - index is associated with the hostControlEntry - as identified by the same value of hostControlIndex." - ::= { hostEntry 3 } - - hostInPkts OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of good packets transmitted to this - address since it was added to the hostTable." - ::= { hostEntry 4 } - - hostOutPkts OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of packets, including bad packets, - transmitted by this address since it was added - to the hostTable." - ::= { hostEntry 5 } - - hostInOctets OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of octets transmitted to this address - since it was added to the hostTable (excluding - framing bits but including FCS octets), except for - those octets in bad packets." - ::= { hostEntry 6 } - - hostOutOctets OBJECT-TYPE - SYNTAX Counter - - - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of octets transmitted by this address - since it was added to the hostTable (excluding - framing bits but including FCS octets), including - those octets in bad packets." - ::= { hostEntry 7 } - - hostOutErrors OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of bad packets transmitted by this address - since this host was added to the hostTable." - ::= { hostEntry 8 } - - hostOutBroadcastPkts OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of good packets transmitted by this - address that were directed to the broadcast address - since this host was added to the hostTable." - ::= { hostEntry 9 } - - hostOutMulticastPkts OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of good packets transmitted by this - address that were directed to a multicast address - since this host was added to the hostTable. - Note that this number does not include packets - directed to the broadcast address." - ::= { hostEntry 10 } - - -- host Time Table - - hostTimeTable OBJECT-TYPE - SYNTAX SEQUENCE OF HostTimeEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A list of time-ordered host table entries." - - - ::= { hosts 3 } - - hostTimeEntry OBJECT-TYPE - SYNTAX HostTimeEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A collection of statistics for a particular host - that has been discovered on an interface of this - device. This collection includes the relative - ordering of the creation time of this object. For - example, an instance of the hostTimeOutBroadcastPkts - object might be named - hostTimeOutBroadcastPkts.1.687" - INDEX { hostTimeIndex, hostTimeCreationOrder } - ::= { hostTimeTable 1 } - - HostTimeEntry ::= SEQUENCE { - hostTimeAddress OCTET STRING, - hostTimeCreationOrder INTEGER (1..65535), - hostTimeIndex INTEGER (1..65535), - hostTimeInPkts Counter, - hostTimeOutPkts Counter, - hostTimeInOctets Counter, - hostTimeOutOctets Counter, - hostTimeOutErrors Counter, - hostTimeOutBroadcastPkts Counter, - hostTimeOutMulticastPkts Counter - } - - hostTimeAddress OBJECT-TYPE - SYNTAX OCTET STRING - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The physical address of this host." - ::= { hostTimeEntry 1 } - - hostTimeCreationOrder OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "An index that uniquely identifies an entry in - the hostTime table among those entries associated - with the same hostControlEntry. This index shall - be between 1 and N, where N is the value of - the associated hostControlTableSize. The ordering - - - of the indexes is based on the order of each entry's - insertion into the table, in which entries added - earlier have a lower index value than entries added - later. Thus the management station has the ability to - learn of new entries added to this table without - downloading the entire table. - - It is important to note that the index for a - particular entry may change as an (earlier) entry - is deleted from the table. Because this order may - change, management stations should make use of the - hostControlLastDeleteTime variable in the - hostControlEntry associated with the relevant - portion of the hostTimeTable. By observing - this variable, the management station may detect - the circumstances where a download of the table - may have missed entries, and where a previous - association between a value of hostTimeCreationOrder - and a hostTimeEntry may no longer hold." - ::= { hostTimeEntry 2 } - - hostTimeIndex OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The set of collected host statistics of which - this entry is a part. The set of hosts - identified by a particular value of this - index is associated with the hostControlEntry - as identified by the same value of hostControlIndex." - ::= { hostTimeEntry 3 } - - hostTimeInPkts OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of good packets transmitted to this - address since it was added to the hostTimeTable." - ::= { hostTimeEntry 4 } - - hostTimeOutPkts OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of god packets transmitted by this - - - address since it was added to the hostTimeTable." - ::= { hostTimeEntry 5 } - - hostTimeInOctets OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of octets transmitted to this address - since it was added to the hostTimeTable (excluding - framing bits but including FCS octets), except for - those octets in bad packets." - ::= { hostTimeEntry 6 } - - hostTimeOutOctets OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of octets transmitted by this address - since it was added to the hostTimeTable (excluding - framing bits but including FCS octets), including - those octets in bad packets." - ::= { hostTimeEntry 7 } - - hostTimeOutErrors OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of bad packets transmitted by this address - since this host was added to the hostTimeTable." - ::= { hostTimeEntry 8 } - - hostTimeOutBroadcastPkts OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of good packets transmitted by this - address that were directed to the broadcast address - since this host was added to the hostTimeTable." - ::= { hostTimeEntry 9 } - - hostTimeOutMulticastPkts OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - - - DESCRIPTION - "The number of good packets transmitted by this - address that were directed to a multicast address - since this host was added to the hostTimeTable. - Note that this number does not include packets - directed to the broadcast address." - ::= { hostTimeEntry 10 } - - - -- The Host Top "N" Group - - -- Implementation of the Host Top N group is optional. - -- - -- The Host Top N group requires the implementation of the - -- host group. - -- - -- The Host Top N group is used to prepare reports that - -- describe the hosts that top a list ordered by one of - -- their statistics. - -- The available statistics are samples of one of their - -- base statistics, over an interval specified by the - -- management station. Thus, these statistics are rate - -- based. The management station also selects how many such - -- hosts are reported. - - -- The hostTopNControlTable is used to initiate the - -- generation of such a report. The management station - -- may select the parameters of such a report, such as - -- which interface, which statistic, how many hosts, - -- and the start and stop times of the sampling. When - -- the report is prepared, entries are created in the - -- hostTopNTable associated with the relevant - -- hostTopNControlEntry. These entries are static for - -- each report after it has been prepared. - - hostTopNControlTable OBJECT-TYPE - SYNTAX SEQUENCE OF HostTopNControlEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A list of top N host control entries." - ::= { hostTopN 1 } - - hostTopNControlEntry OBJECT-TYPE - SYNTAX HostTopNControlEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - - - "A set of parameters that control the creation of a - report of the top N hosts according to several - metrics. For example, an instance of the - hostTopNDuration object might be named - hostTopNDuration.3" - INDEX { hostTopNControlIndex } - ::= { hostTopNControlTable 1 } - - HostTopNControlEntry ::= SEQUENCE { - hostTopNControlIndex INTEGER (1..65535), - hostTopNHostIndex INTEGER (1..65535), - hostTopNRateBase INTEGER, - hostTopNTimeRemaining INTEGER, - hostTopNDuration INTEGER, - hostTopNRequestedSize INTEGER, - hostTopNGrantedSize INTEGER, - hostTopNStartTime TimeTicks, - hostTopNOwner OwnerString, - hostTopNStatus EntryStatus - } - - hostTopNControlIndex OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "An index that uniquely identifies an entry - in the hostTopNControl table. Each such - entry defines one top N report prepared for - one interface." - ::= { hostTopNControlEntry 1 } - - hostTopNHostIndex OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The host table for which a top N report will be - prepared on behalf of this entry. The host table - identified by a particular value of this index is - associated with the same host table as identified by - the same value of hostIndex. - - This object may not be modified if the associated - hostTopNStatus object is equal to valid(1)." - ::= { hostTopNControlEntry 2 } - - hostTopNRateBase OBJECT-TYPE - - - SYNTAX INTEGER { - hostTopNInPkts(1), - hostTopNOutPkts(2), - hostTopNInOctets(3), - hostTopNOutOctets(4), - hostTopNOutErrors(5), - hostTopNOutBroadcastPkts(6), - hostTopNOutMulticastPkts(7) - } - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The variable for each host that the hostTopNRate - variable is based upon. - - This object may not be modified if the associated - hostTopNStatus object is equal to valid(1)." - ::= { hostTopNControlEntry 3 } - - hostTopNTimeRemaining OBJECT-TYPE - SYNTAX INTEGER - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The number of seconds left in the report currently - being collected. When this object is modified by - the management station, a new collection is started, - possibly aborting a currently running report. The - new value is used as the requested duration of this - report, which is loaded into the associated - hostTopNDuration object. - - When this object is set to a non-zero value, any - associated hostTopNEntries shall be made - inaccessible by the monitor. While the value of - this object is non-zero, it decrements by one per - second until it reaches zero. During this time, all - associated hostTopNEntries shall remain - inaccessible. At the time that this object - decrements to zero, the report is made accessible in - the hostTopNTable. Thus, the hostTopN table needs - to be created only at the end of the collection - interval." - DEFVAL { 0 } - ::= { hostTopNControlEntry 4 } - - hostTopNDuration OBJECT-TYPE - SYNTAX INTEGER - - - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of seconds that this report has collected - during the last sampling interval, or if this - report is currently being collected, the number - of seconds that this report is being collected - during this sampling interval. - - When the associated hostTopNTimeRemaining object is - set, this object shall be set by the probe to the - same value and shall not be modified until the next - time the hostTopNTimeRemaining is set. - - This value shall be zero if no reports have been - requested for this hostTopNControlEntry." - DEFVAL { 0 } - ::= { hostTopNControlEntry 5 } - - hostTopNRequestedSize OBJECT-TYPE - SYNTAX INTEGER - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The maximum number of hosts requested for the top N - table. - - When this object is created or modified, the probe - should set hostTopNGrantedSize as closely to this - object as is possible for the particular probe - implementation and available resources." - DEFVAL { 10 } - ::= { hostTopNControlEntry 6 } - - hostTopNGrantedSize OBJECT-TYPE - SYNTAX INTEGER - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The maximum number of hosts in the top N table. - - When the associated hostTopNRequestedSize object is - created or modified, the probe should set this - object as closely to the requested value as is - possible for the particular implementation and - available resources. The probe must not lower this - value except as a result of a set to the associated - hostTopNRequestedSize object. - - - Hosts with the highest value of hostTopNRate shall be - placed in this table in decreasing order of this rate - until there is no more room or until there are no more - hosts." - ::= { hostTopNControlEntry 7 } - - hostTopNStartTime OBJECT-TYPE - SYNTAX TimeTicks - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The value of sysUpTime when this top N report was - last started. In other words, this is the time that - the associated hostTopNTimeRemaining object was - modified to start the requested report." - ::= { hostTopNControlEntry 8 } - - hostTopNOwner OBJECT-TYPE - SYNTAX OwnerString - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The entity that configured this entry and is - therefore using the resources assigned to it." - ::= { hostTopNControlEntry 9 } - - hostTopNStatus OBJECT-TYPE - SYNTAX EntryStatus - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The status of this hostTopNControl entry. - - If this object is not equal to valid(1), all - associated hostTopNEntries shall be deleted by the - agent." - ::= { hostTopNControlEntry 10 } - - hostTopNTable OBJECT-TYPE - SYNTAX SEQUENCE OF HostTopNEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A list of top N host entries." - ::= { hostTopN 2 } - - hostTopNEntry OBJECT-TYPE - SYNTAX HostTopNEntry - - - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A set of statistics for a host that is part of a - top N report. For example, an instance of the - hostTopNRate object might be named - hostTopNRate.3.10" - INDEX { hostTopNReport, hostTopNIndex } - ::= { hostTopNTable 1 } - - HostTopNEntry ::= SEQUENCE { - hostTopNReport INTEGER (1..65535), - hostTopNIndex INTEGER (1..65535), - hostTopNAddress OCTET STRING, - hostTopNRate INTEGER - } - - hostTopNReport OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "This object identifies the top N report of which - this entry is a part. The set of hosts - identified by a particular value of this - object is part of the same report as identified - by the same value of the hostTopNControlIndex object." - ::= { hostTopNEntry 1 } - - hostTopNIndex OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "An index that uniquely identifies an entry in - the hostTopN table among those in the same report. - This index is between 1 and N, where N is the - number of entries in this table. Increasing values - of hostTopNIndex shall be assigned to entries with - decreasing values of hostTopNRate until index N - is assigned to the entry with the lowest value of - hostTopNRate or there are no more hostTopNEntries." - ::= { hostTopNEntry 2 } - - hostTopNAddress OBJECT-TYPE - SYNTAX OCTET STRING - ACCESS read-only - STATUS mandatory - - - DESCRIPTION - "The physical address of this host." - ::= { hostTopNEntry 3 } - - hostTopNRate OBJECT-TYPE - SYNTAX INTEGER - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The amount of change in the selected variable - during this sampling interval. The selected - variable is this host's instance of the object - selected by hostTopNRateBase." - ::= { hostTopNEntry 4 } - - - -- The Matrix Group - - -- Implementation of the Matrix group is optional. - -- - -- The Matrix group consists of the matrixControlTable, - -- matrixSDTable and the matrixDSTable. These tables - -- store statistics for a particular conversation - -- between two addresses. As the device detects a new - -- conversation, including those to a non-unicast - -- address, it creates a new entry in both of the - -- matrix tables. It must only create new entries - -- based on information received in good packets. If - -- the monitoring device finds itself short of - -- resources, it may delete entries as needed. It is - -- suggested that the device delete the least recently - -- used entries first. - - matrixControlTable OBJECT-TYPE - SYNTAX SEQUENCE OF MatrixControlEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A list of information entries for the - traffic matrix on each interface." - ::= { matrix 1 } - - matrixControlEntry OBJECT-TYPE - SYNTAX MatrixControlEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "Information about a traffic matrix on a particular - - - interface. For example, an instance of the - matrixControlLastDeleteTime object might be named - matrixControlLastDeleteTime.1" - INDEX { matrixControlIndex } - ::= { matrixControlTable 1 } - - MatrixControlEntry ::= SEQUENCE { - matrixControlIndex INTEGER (1..65535), - matrixControlDataSource OBJECT IDENTIFIER, - matrixControlTableSize INTEGER, - matrixControlLastDeleteTime TimeTicks, - matrixControlOwner OwnerString, - matrixControlStatus EntryStatus - } - - matrixControlIndex OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "An index that uniquely identifies an entry in the - matrixControl table. Each such entry defines - a function that discovers conversations on a - particular interface and places statistics about - them in the matrixSDTable and the matrixDSTable on - behalf of this matrixControlEntry." - ::= { matrixControlEntry 1 } - - matrixControlDataSource OBJECT-TYPE - SYNTAX OBJECT IDENTIFIER - ACCESS read-write - STATUS mandatory - DESCRIPTION - "This object identifies the source of - the data from which this entry creates a traffic - matrix. This source can be any interface on this - device. In order to identify a particular - interface, this object shall identify the instance - of the ifIndex object, defined in RFC 1213 and RFC - 1573 [4,6], for the desired interface. For example, - if an entry were to receive data from interface #1, - this object would be set to ifIndex.1. - - The statistics in this group reflect all packets - on the local network segment attached to the - identified interface. - - An agent may or may not be able to tell if - - - fundamental changes to the media of the interface - have occurred and necessitate an invalidation of - this entry. For example, a hot-pluggable ethernet - card could be pulled out and replaced by a - token-ring card. In such a case, if the agent has - such knowledge of the change, it is recommended that - it invalidate this entry. - - This object may not be modified if the associated - matrixControlStatus object is equal to valid(1)." - ::= { matrixControlEntry 2 } - - matrixControlTableSize OBJECT-TYPE - SYNTAX INTEGER - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of matrixSDEntries in the matrixSDTable - for this interface. This must also be the value of - the number of entries in the matrixDSTable for this - interface." - ::= { matrixControlEntry 3 } - - matrixControlLastDeleteTime OBJECT-TYPE - SYNTAX TimeTicks - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The value of sysUpTime when the last entry - was deleted from the portion of the matrixSDTable - or matrixDSTable associated with this - matrixControlEntry. If no deletions have occurred, - this value shall be zero." - ::= { matrixControlEntry 4 } - - matrixControlOwner OBJECT-TYPE - SYNTAX OwnerString - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The entity that configured this entry and is - therefore using the resources assigned to it." - ::= { matrixControlEntry 5 } - - matrixControlStatus OBJECT-TYPE - SYNTAX EntryStatus - ACCESS read-write - STATUS mandatory - - - DESCRIPTION - "The status of this matrixControl entry. - - If this object is not equal to valid(1), all - associated entries in the matrixSDTable and the - matrixDSTable shall be deleted by the agent." - ::= { matrixControlEntry 6 } - - matrixSDTable OBJECT-TYPE - SYNTAX SEQUENCE OF MatrixSDEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A list of traffic matrix entries indexed by - source and destination MAC address." - ::= { matrix 2 } - - matrixSDEntry OBJECT-TYPE - SYNTAX MatrixSDEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A collection of statistics for communications between - two addresses on a particular interface. For example, - an instance of the matrixSDPkts object might be named - matrixSDPkts.1.6.8.0.32.27.3.176.6.8.0.32.10.8.113" - INDEX { matrixSDIndex, - matrixSDSourceAddress, matrixSDDestAddress } - ::= { matrixSDTable 1 } - - MatrixSDEntry ::= SEQUENCE { - matrixSDSourceAddress OCTET STRING, - matrixSDDestAddress OCTET STRING, - matrixSDIndex INTEGER (1..65535), - matrixSDPkts Counter, - matrixSDOctets Counter, - matrixSDErrors Counter - } - - matrixSDSourceAddress OBJECT-TYPE - SYNTAX OCTET STRING - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The source physical address." - ::= { matrixSDEntry 1 } - - matrixSDDestAddress OBJECT-TYPE - - - SYNTAX OCTET STRING - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The destination physical address." - ::= { matrixSDEntry 2 } - - matrixSDIndex OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The set of collected matrix statistics of which - this entry is a part. The set of matrix statistics - identified by a particular value of this index - is associated with the same matrixControlEntry - as identified by the same value of - matrixControlIndex." - ::= { matrixSDEntry 3 } - - matrixSDPkts OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of packets transmitted from the source - address to the destination address (this number - includes bad packets)." - ::= { matrixSDEntry 4 } - - matrixSDOctets OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of octets (excluding framing bits but - including FCS octets) contained in all packets - transmitted from the source address to the - destination address." - ::= { matrixSDEntry 5 } - - matrixSDErrors OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of bad packets transmitted from - the source address to the destination address." - - - ::= { matrixSDEntry 6 } - - - -- Traffic matrix tables from destination to source - - matrixDSTable OBJECT-TYPE - SYNTAX SEQUENCE OF MatrixDSEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A list of traffic matrix entries indexed by - destination and source MAC address." - ::= { matrix 3 } - - matrixDSEntry OBJECT-TYPE - SYNTAX MatrixDSEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A collection of statistics for communications between - two addresses on a particular interface. For example, - an instance of the matrixSDPkts object might be named - matrixSDPkts.1.6.8.0.32.10.8.113.6.8.0.32.27.3.176" - INDEX { matrixDSIndex, - matrixDSDestAddress, matrixDSSourceAddress } - ::= { matrixDSTable 1 } - - MatrixDSEntry ::= SEQUENCE { - matrixDSSourceAddress OCTET STRING, - matrixDSDestAddress OCTET STRING, - matrixDSIndex INTEGER (1..65535), - matrixDSPkts Counter, - matrixDSOctets Counter, - matrixDSErrors Counter - } - - matrixDSSourceAddress OBJECT-TYPE - SYNTAX OCTET STRING - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The source physical address." - ::= { matrixDSEntry 1 } - - matrixDSDestAddress OBJECT-TYPE - SYNTAX OCTET STRING - ACCESS read-only - STATUS mandatory - - - DESCRIPTION - "The destination physical address." - ::= { matrixDSEntry 2 } - - matrixDSIndex OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The set of collected matrix statistics of which - this entry is a part. The set of matrix statistics - identified by a particular value of this index - is associated with the same matrixControlEntry - as identified by the same value of - matrixControlIndex." - ::= { matrixDSEntry 3 } - - matrixDSPkts OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of packets transmitted from the source - address to the destination address (this number - includes bad packets)." - ::= { matrixDSEntry 4 } - - matrixDSOctets OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of octets (excluding framing bits - but including FCS octets) contained in all packets - transmitted from the source address to the - destination address." - ::= { matrixDSEntry 5 } - - matrixDSErrors OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of bad packets transmitted from - the source address to the destination address." - ::= { matrixDSEntry 6 } - - - - - -- The Filter Group - - -- Implementation of the Filter group is optional. - -- - -- The Filter group allows packets to be captured with an - -- arbitrary filter expression. A logical data and - -- event stream or "channel" is formed by the packets - -- that match the filter expression. - -- - -- This filter mechanism allows the creation of an arbitrary - -- logical expression with which to filter packets. Each - -- filter associated with a channel is OR'ed with the others. - -- Within a filter, any bits checked in the data and status - -- are AND'ed with respect to other bits in the same filter. - -- The NotMask also allows for checking for inequality. - -- Finally, the channelAcceptType object allows for - -- inversion of the whole equation. - -- - -- If a management station wishes to receive a trap to alert - -- it that new packets have been captured and are available - -- for download, it is recommended that it set up an alarm - -- entry that monitors the value of the relevant - -- channelMatches instance. - -- - -- The channel can be turned on or off, and can also - -- generate events when packets pass through it. - - filterTable OBJECT-TYPE - SYNTAX SEQUENCE OF FilterEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A list of packet filter entries." - ::= { filter 1 } - - filterEntry OBJECT-TYPE - SYNTAX FilterEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A set of parameters for a packet filter applied on a - particular interface. As an example, an instance of - the filterPktData object might be named - filterPktData.12" - INDEX { filterIndex } - ::= { filterTable 1 } - - - - - FilterEntry ::= SEQUENCE { - filterIndex INTEGER (1..65535), - filterChannelIndex INTEGER (1..65535), - filterPktDataOffset INTEGER, - filterPktData OCTET STRING, - filterPktDataMask OCTET STRING, - filterPktDataNotMask OCTET STRING, - filterPktStatus INTEGER, - filterPktStatusMask INTEGER, - filterPktStatusNotMask INTEGER, - filterOwner OwnerString, - filterStatus EntryStatus - } - - filterIndex OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "An index that uniquely identifies an entry - in the filter table. Each such entry defines - one filter that is to be applied to every packet - received on an interface." - ::= { filterEntry 1 } - - filterChannelIndex OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-write - STATUS mandatory - DESCRIPTION - "This object identifies the channel of which this - filter is a part. The filters identified by a - particular value of this object are associated with - the same channel as identified by the same value of - the channelIndex object." - ::= { filterEntry 2 } - - filterPktDataOffset OBJECT-TYPE - SYNTAX INTEGER - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The offset from the beginning of each packet where - a match of packet data will be attempted. This offset - is measured from the point in the physical layer - packet after the framing bits, if any. For example, - in an Ethernet frame, this point is at the beginning - of the destination MAC address. - - - This object may not be modified if the associated - filterStatus object is equal to valid(1)." - DEFVAL { 0 } - ::= { filterEntry 3 } - - filterPktData OBJECT-TYPE - SYNTAX OCTET STRING - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The data that is to be matched with the input - packet. For each packet received, this filter and - the accompanying filterPktDataMask and - filterPktDataNotMask will be adjusted for the - offset. The only bits relevant to this match - algorithm are those that have the corresponding - filterPktDataMask bit equal to one. The following - three rules are then applied to every packet: - - (1) If the packet is too short and does not have data - corresponding to part of the filterPktData, the - packet will fail this data match. - - (2) For each relevant bit from the packet with the - corresponding filterPktDataNotMask bit set to - zero, if the bit from the packet is not equal to - the corresponding bit from the filterPktData, - then the packet will fail this data match. - - (3) If for every relevant bit from the packet with the - corresponding filterPktDataNotMask bit set to one, - the bit from the packet is equal to the - corresponding bit from the filterPktData, then - the packet will fail this data match. - - Any packets that have not failed any of the three - matches above have passed this data match. In - particular, a zero length filter will match any - packet. - - This object may not be modified if the associated - filterStatus object is equal to valid(1)." - ::= { filterEntry 4 } - - filterPktDataMask OBJECT-TYPE - SYNTAX OCTET STRING - ACCESS read-write - STATUS mandatory - - - DESCRIPTION - "The mask that is applied to the match process. - After adjusting this mask for the offset, only those - bits in the received packet that correspond to bits - set in this mask are relevant for further processing - by the match algorithm. The offset is applied to - filterPktDataMask in the same way it is applied to the - filter. For the purposes of the matching algorithm, - if the associated filterPktData object is longer - than this mask, this mask is conceptually extended - with '1' bits until it reaches the length of the - filterPktData object. - - This object may not be modified if the associated - filterStatus object is equal to valid(1)." - ::= { filterEntry 5 } - - filterPktDataNotMask OBJECT-TYPE - SYNTAX OCTET STRING - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The inversion mask that is applied to the match - process. After adjusting this mask for the offset, - those relevant bits in the received packet that - correspond to bits cleared in this mask must all be - equal to their corresponding bits in the - filterPktData object for the packet to be accepted. - In addition, at least one of those relevant bits in - the received packet that correspond to bits set in - this mask must be different to its corresponding bit - in the filterPktData object. - - For the purposes of the matching algorithm, if the - associated filterPktData object is longer than this - mask, this mask is conceptually extended with '0' - bits until it reaches the length of the - filterPktData object. - - This object may not be modified if the associated - filterStatus object is equal to valid(1)." - ::= { filterEntry 6 } - - filterPktStatus OBJECT-TYPE - SYNTAX INTEGER - ACCESS read-write - STATUS mandatory - DESCRIPTION - - - "The status that is to be matched with the input - packet. The only bits relevant to this match - algorithm are those that have the corresponding - filterPktStatusMask bit equal to one. The following - two rules are then applied to every packet: - - (1) For each relevant bit from the packet status - with the corresponding filterPktStatusNotMask bit - set to zero, if the bit from the packet status is - not equal to the corresponding bit from the - filterPktStatus, then the packet will fail this - status match. - - (2) If for every relevant bit from the packet status - with the corresponding filterPktStatusNotMask bit - set to one, the bit from the packet status is - equal to the corresponding bit from the - filterPktStatus, then the packet will fail this - status match. - - Any packets that have not failed either of the two - matches above have passed this status match. In - particular, a zero length status filter will match any - packet's status. - - The value of the packet status is a sum. This sum - initially takes the value zero. Then, for each - error, E, that has been discovered in this packet, - 2 raised to a value representing E is added to the - sum. The errors and the bits that represent them are - dependent on the media type of the interface that - this channel is receiving packets from. - - The errors defined for a packet captured off of an - Ethernet interface are as follows: - - bit # Error - 0 Packet is longer than 1518 octets - 1 Packet is shorter than 64 octets - 2 Packet experienced a CRC or Alignment - error - - For example, an Ethernet fragment would have a - value of 6 (2^1 + 2^2). - - As this MIB is expanded to new media types, this - object will have other media-specific errors - defined. - - - For the purposes of this status matching algorithm, - if the packet status is longer than this - filterPktStatus object, this object is conceptually - extended with '0' bits until it reaches the size of - the packet status. - - This object may not be modified if the associated - filterStatus object is equal to valid(1)." - ::= { filterEntry 7 } - - filterPktStatusMask OBJECT-TYPE - SYNTAX INTEGER - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The mask that is applied to the status match - process. Only those bits in the received packet - that correspond to bits set in this mask are - relevant for further processing by the status match - algorithm. For the purposes of the matching - algorithm, if the associated filterPktStatus object - is longer than this mask, this mask is conceptually - extended with '1' bits until it reaches the size of - the filterPktStatus. In addition, if a packet - status is longer than this mask, this mask is - conceptually extended with '0' bits until it reaches - the size of the packet status. - - This object may not be modified if the associated - filterStatus object is equal to valid(1)." - ::= { filterEntry 8 } - - filterPktStatusNotMask OBJECT-TYPE - SYNTAX INTEGER - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The inversion mask that is applied to the status - match process. Those relevant bits in the received - packet status that correspond to bits cleared in - this mask must all be equal to their corresponding - bits in the filterPktStatus object for the packet to - be accepted. In addition, at least one of those - relevant bits in the received packet status that - correspond to bits set in this mask must be - different to its corresponding bit in the - filterPktStatus object for the packet to be - accepted. - - - For the purposes of the matching algorithm, if the - associated filterPktStatus object or a packet status - is longer than this mask, this mask is conceptually - extended with '0' bits until it reaches the longer - of the lengths of the filterPktStatus object and the - packet status. - - This object may not be modified if the associated - filterStatus object is equal to valid(1)." - ::= { filterEntry 9 } - - filterOwner OBJECT-TYPE - SYNTAX OwnerString - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The entity that configured this entry and is - therefore using the resources assigned to it." - ::= { filterEntry 10 } - - filterStatus OBJECT-TYPE - SYNTAX EntryStatus - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The status of this filter entry." - ::= { filterEntry 11 } - - channelTable OBJECT-TYPE - SYNTAX SEQUENCE OF ChannelEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A list of packet channel entries." - ::= { filter 2 } - - channelEntry OBJECT-TYPE - SYNTAX ChannelEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A set of parameters for a packet channel applied on a - particular interface. As an example, an instance of - the channelMatches object might be named - channelMatches.3" - INDEX { channelIndex } - ::= { channelTable 1 } - - - - ChannelEntry ::= SEQUENCE { - channelIndex INTEGER (1..65535), - channelIfIndex INTEGER (1..65535), - channelAcceptType INTEGER, - channelDataControl INTEGER, - channelTurnOnEventIndex INTEGER (0..65535), - channelTurnOffEventIndex INTEGER (0..65535), - channelEventIndex INTEGER (0..65535), - channelEventStatus INTEGER, - channelMatches Counter, - channelDescription DisplayString (SIZE (0..127)), - channelOwner OwnerString, - channelStatus EntryStatus - } - - channelIndex OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "An index that uniquely identifies an entry in the - channel table. Each such entry defines one channel, - a logical data and event stream. - - It is suggested that before creating a channel, an - application should scan all instances of the - filterChannelIndex object to make sure that there - are no pre-existing filters that would be - inadvertently be linked to the channel." - ::= { channelEntry 1 } - - channelIfIndex OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The value of this object uniquely identifies the - interface on this remote network monitoring device - to which the associated filters are applied to allow - data into this channel. The interface identified by - a particular value of this object is the same - interface as identified by the same value of the - ifIndex object, defined in RFC 1213 and RFC 1573 - [4,6]. - - The filters in this group are applied to all packets - on the local network segment attached to the - identified interface. - - - An agent may or may not be able to tell if - fundamental changes to the media of the interface - have occurred and necessitate an invalidation of - this entry. For example, a hot-pluggable ethernet - card could be pulled out and replaced by a - token-ring card. In such a case, if the agent has - such knowledge of the change, it is recommended that - it invalidate this entry. - - This object may not be modified if the associated - channelStatus object is equal to valid(1)." - ::= { channelEntry 2 } - - channelAcceptType OBJECT-TYPE - SYNTAX INTEGER { - acceptMatched(1), - acceptFailed(2) - } - ACCESS read-write - STATUS mandatory - DESCRIPTION - "This object controls the action of the filters - associated with this channel. If this object is equal - to acceptMatched(1), packets will be accepted to this - channel if they are accepted by both the packet data - and packet status matches of an associated filter. If - this object is equal to acceptFailed(2), packets will - be accepted to this channel only if they fail either - the packet data match or the packet status match of - each of the associated filters. - - In particular, a channel with no associated filters - will match no packets if set to acceptMatched(1) - case and will match all packets in the - acceptFailed(2) case. - - This object may not be modified if the associated - channelStatus object is equal to valid(1)." - ::= { channelEntry 3 } - - channelDataControl OBJECT-TYPE - SYNTAX INTEGER { - on(1), - off(2) - } - ACCESS read-write - STATUS mandatory - DESCRIPTION - - - "This object controls the flow of data through this - channel. If this object is on(1), data, status and - events flow through this channel. If this object is - off(2), data, status and events will not flow - through this channel." - DEFVAL { off } - ::= { channelEntry 4 } - - channelTurnOnEventIndex OBJECT-TYPE - SYNTAX INTEGER (0..65535) - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The value of this object identifies the event - that is configured to turn the associated - channelDataControl from off to on when the event is - generated. The event identified by a particular value - of this object is the same event as identified by the - same value of the eventIndex object. If there is no - corresponding entry in the eventTable, then no - association exists. In fact, if no event is intended - for this channel, channelTurnOnEventIndex must be - set to zero, a non-existent event index. - - This object may not be modified if the associated - channelStatus object is equal to valid(1)." - ::= { channelEntry 5 } - - channelTurnOffEventIndex OBJECT-TYPE - SYNTAX INTEGER (0..65535) - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The value of this object identifies the event - that is configured to turn the associated - channelDataControl from on to off when the event is - generated. The event identified by a particular value - of this object is the same event as identified by the - same value of the eventIndex object. If there is no - corresponding entry in the eventTable, then no - association exists. In fact, if no event is intended - for this channel, channelTurnOffEventIndex must be - set to zero, a non-existent event index. - - This object may not be modified if the associated - channelStatus object is equal to valid(1)." - ::= { channelEntry 6 } - - - - channelEventIndex OBJECT-TYPE - SYNTAX INTEGER (0..65535) - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The value of this object identifies the event - that is configured to be generated when the - associated channelDataControl is on and a packet - is matched. The event identified by a particular - value of this object is the same event as identified - by the same value of the eventIndex object. If - there is no corresponding entry in the eventTable, - then no association exists. In fact, if no event is - intended for this channel, channelEventIndex must be - set to zero, a non-existent event index. - - This object may not be modified if the associated - channelStatus object is equal to valid(1)." - ::= { channelEntry 7 } - - channelEventStatus OBJECT-TYPE - SYNTAX INTEGER { - eventReady(1), - eventFired(2), - eventAlwaysReady(3) - } - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The event status of this channel. - - If this channel is configured to generate events - when packets are matched, a means of controlling - the flow of those events is often needed. When - this object is equal to eventReady(1), a single - event may be generated, after which this object - will be set by the probe to eventFired(2). While - in the eventFired(2) state, no events will be - generated until the object is modified to - eventReady(1) (or eventAlwaysReady(3)). The - management station can thus easily respond to a - notification of an event by re-enabling this object. - - If the management station wishes to disable this - flow control and allow events to be generated - at will, this object may be set to - eventAlwaysReady(3). Disabling the flow control - is discouraged as it can result in high network - - - traffic or other performance problems." - DEFVAL { eventReady } - ::= { channelEntry 8 } - - channelMatches OBJECT-TYPE - SYNTAX Counter - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of times this channel has matched a - packet. Note that this object is updated even when - channelDataControl is set to off." - ::= { channelEntry 9 } - - channelDescription OBJECT-TYPE - SYNTAX DisplayString (SIZE (0..127)) - ACCESS read-write - STATUS mandatory - DESCRIPTION - "A comment describing this channel." - ::= { channelEntry 10 } - - channelOwner OBJECT-TYPE - SYNTAX OwnerString - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The entity that configured this entry and is - therefore using the resources assigned to it." - ::= { channelEntry 11 } - - channelStatus OBJECT-TYPE - SYNTAX EntryStatus - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The status of this channel entry." - ::= { channelEntry 12 } - - - -- The Packet Capture Group - - -- Implementation of the Packet Capture group is optional. - -- - -- The Packet Capture Group requires implementation of the - -- Filter Group. - -- - -- The Packet Capture group allows packets to be captured - - - -- upon a filter match. The bufferControlTable controls - -- the captured packets output from a channel that is - -- associated with it. The captured packets are placed - -- in entries in the captureBufferTable. These entries are - -- associated with the bufferControlEntry on whose behalf they - -- were stored. - - bufferControlTable OBJECT-TYPE - SYNTAX SEQUENCE OF BufferControlEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A list of buffers control entries." - ::= { capture 1 } - - bufferControlEntry OBJECT-TYPE - SYNTAX BufferControlEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A set of parameters that control the collection of - a stream of packets that have matched filters. As - an example, an instance of the - bufferControlCaptureSliceSize object might be named - bufferControlCaptureSliceSize.3" - INDEX { bufferControlIndex } - ::= { bufferControlTable 1 } - - BufferControlEntry ::= SEQUENCE { - bufferControlIndex INTEGER (1..65535), - bufferControlChannelIndex INTEGER (1..65535), - bufferControlFullStatus INTEGER, - bufferControlFullAction INTEGER, - bufferControlCaptureSliceSize INTEGER, - bufferControlDownloadSliceSize INTEGER, - bufferControlDownloadOffset INTEGER, - bufferControlMaxOctetsRequested INTEGER, - bufferControlMaxOctetsGranted INTEGER, - bufferControlCapturedPackets INTEGER, - bufferControlTurnOnTime TimeTicks, - bufferControlOwner OwnerString, - bufferControlStatus EntryStatus - } - - bufferControlIndex OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-only - STATUS mandatory - - - DESCRIPTION - "An index that uniquely identifies an entry - in the bufferControl table. The value of this - index shall never be zero. Each such - entry defines one set of packets that is - captured and controlled by one or more filters." - ::= { bufferControlEntry 1 } - - bufferControlChannelIndex OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-write - STATUS mandatory - DESCRIPTION - "An index that identifies the channel that is the - source of packets for this bufferControl table. - The channel identified by a particular value of this - index is the same as identified by the same value of - the channelIndex object. - - This object may not be modified if the associated - bufferControlStatus object is equal to valid(1)." - ::= { bufferControlEntry 2 } - - bufferControlFullStatus OBJECT-TYPE - SYNTAX INTEGER { - spaceAvailable(1), - full(2) - } - ACCESS read-only - STATUS mandatory - DESCRIPTION - "This object shows whether the buffer has room to - accept new packets or if it is full. - - If the status is spaceAvailable(1), the buffer is - accepting new packets normally. If the status is - full(2) and the associated bufferControlFullAction - object is wrapWhenFull, the buffer is accepting new - packets by deleting enough of the oldest packets - to make room for new ones as they arrive. Otherwise, - if the status is full(2) and the - bufferControlFullAction object is lockWhenFull, - then the buffer has stopped collecting packets. - - When this object is set to full(2) the probe must - not later set it to spaceAvailable(1) except in the - case of a significant gain in resources such as - an increase of bufferControlOctetsGranted. In - - - particular, the wrap-mode action of deleting old - packets to make room for newly arrived packets - must not affect the value of this object." - ::= { bufferControlEntry 3 } - - bufferControlFullAction OBJECT-TYPE - SYNTAX INTEGER { - lockWhenFull(1), - wrapWhenFull(2) -- FIFO - } - ACCESS read-write - STATUS mandatory - DESCRIPTION - "Controls the action of the buffer when it - reaches the full status. When in the lockWhenFull(1) - state and a packet is added to the buffer that - fills the buffer, the bufferControlFullStatus will - be set to full(2) and this buffer will stop capturing - packets." - ::= { bufferControlEntry 4 } - - bufferControlCaptureSliceSize OBJECT-TYPE - SYNTAX INTEGER - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The maximum number of octets of each packet - that will be saved in this capture buffer. - For example, if a 1500 octet packet is received by - the probe and this object is set to 500, then only - 500 octets of the packet will be stored in the - associated capture buffer. If this variable is set - to 0, the capture buffer will save as many octets - as is possible. - - This object may not be modified if the associated - bufferControlStatus object is equal to valid(1)." - DEFVAL { 100 } - ::= { bufferControlEntry 5 } - - bufferControlDownloadSliceSize OBJECT-TYPE - SYNTAX INTEGER - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The maximum number of octets of each packet - in this capture buffer that will be returned in - an SNMP retrieval of that packet. For example, - - - if 500 octets of a packet have been stored in the - associated capture buffer, the associated - bufferControlDownloadOffset is 0, and this - object is set to 100, then the captureBufferPacket - object that contains the packet will contain only - the first 100 octets of the packet. - - A prudent manager will take into account possible - interoperability or fragmentation problems that may - occur if the download slice size is set too large. - In particular, conformant SNMP implementations are not - required to accept messages whose length exceeds 484 - octets, although they are encouraged to support larger - datagrams whenever feasible." - DEFVAL { 100 } - ::= { bufferControlEntry 6 } - - bufferControlDownloadOffset OBJECT-TYPE - SYNTAX INTEGER - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The offset of the first octet of each packet - in this capture buffer that will be returned in - an SNMP retrieval of that packet. For example, - if 500 octets of a packet have been stored in the - associated capture buffer and this object is set to - 100, then the captureBufferPacket object that - contains the packet will contain bytes starting - 100 octets into the packet." - DEFVAL { 0 } - ::= { bufferControlEntry 7 } - - bufferControlMaxOctetsRequested OBJECT-TYPE - SYNTAX INTEGER - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The requested maximum number of octets to be - saved in this captureBuffer, including any - implementation-specific overhead. If this variable - is set to -1, the capture buffer will save as many - octets as is possible. - - When this object is created or modified, the probe - should set bufferControlMaxOctetsGranted as closely - to this object as is possible for the particular probe - implementation and available resources. However, if - - - the object has the special value of -1, the probe - must set bufferControlMaxOctetsGranted to -1." - DEFVAL { -1 } - ::= { bufferControlEntry 8 } - - bufferControlMaxOctetsGranted OBJECT-TYPE - SYNTAX INTEGER - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The maximum number of octets that can be - saved in this captureBuffer, including overhead. - If this variable is -1, the capture buffer will save - as many octets as possible. - - When the bufferControlMaxOctetsRequested object is - created or modified, the probe should set this object - as closely to the requested value as is possible for - the particular probe implementation and available - resources. - However, if the request object has the special value - of -1, the probe must set this object to -1. - The probe must not lower this value except as a result - of a modification to the associated - bufferControlMaxOctetsRequested object. - - When this maximum number of octets is reached - and a new packet is to be added to this - capture buffer and the corresponding - bufferControlFullAction is set to wrapWhenFull(2), - enough of the oldest packets associated with this - capture buffer shall be deleted by the agent so - that the new packet can be added. If the - corresponding bufferControlFullAction is set to - lockWhenFull(1), the new packet shall be discarded. - In either case, the probe must set - bufferControlFullStatus to full(2). - - When the value of this object changes to a value less - than the current value, entries are deleted from - the captureBufferTable associated with this - bufferControlEntry. Enough of the - oldest of these captureBufferEntries shall be - deleted by the agent so that the number of octets - used remains less than or equal to the new value of - this object. - - When the value of this object changes to a value - - - greater than the current value, the number of - associated captureBufferEntries may be allowed to - grow." - ::= { bufferControlEntry 9 } - - bufferControlCapturedPackets OBJECT-TYPE - SYNTAX INTEGER - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of packets currently in this - captureBuffer." - ::= { bufferControlEntry 10 } - - bufferControlTurnOnTime OBJECT-TYPE - SYNTAX TimeTicks - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The value of sysUpTime when this capture buffer was - first turned on." - ::= { bufferControlEntry 11 } - - bufferControlOwner OBJECT-TYPE - SYNTAX OwnerString - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The entity that configured this entry and is - therefore using the resources assigned to it." - ::= { bufferControlEntry 12 } - - bufferControlStatus OBJECT-TYPE - SYNTAX EntryStatus - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The status of this buffer Control Entry." - ::= { bufferControlEntry 13 } - - captureBufferTable OBJECT-TYPE - SYNTAX SEQUENCE OF CaptureBufferEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A list of packets captured off of a channel." - ::= { capture 2 } - - - - captureBufferEntry OBJECT-TYPE - SYNTAX CaptureBufferEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A packet captured off of an attached network. As an - example, an instance of the captureBufferPacketData - object might be named captureBufferPacketData.3.1783" - INDEX { captureBufferControlIndex, captureBufferIndex } - ::= { captureBufferTable 1 } - - CaptureBufferEntry ::= SEQUENCE { - captureBufferControlIndex INTEGER (1..65535), - captureBufferIndex INTEGER (1..2147483647), - captureBufferPacketID INTEGER, - captureBufferPacketData OCTET STRING, - captureBufferPacketLength INTEGER, - captureBufferPacketTime INTEGER, - captureBufferPacketStatus INTEGER - } - - captureBufferControlIndex OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The index of the bufferControlEntry with which - this packet is associated." - ::= { captureBufferEntry 1 } - - captureBufferIndex OBJECT-TYPE - SYNTAX INTEGER (1..2147483647) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "An index that uniquely identifies an entry - in the captureBuffer table associated with a - particular bufferControlEntry. This index will - start at 1 and increase by one for each new packet - added with the same captureBufferControlIndex. - - Should this value reach 2147483647, the next packet - added with the same captureBufferControlIndex shall - cause this value to wrap around to 1." - ::= { captureBufferEntry 2 } - - captureBufferPacketID OBJECT-TYPE - SYNTAX INTEGER - - - ACCESS read-only - STATUS mandatory - DESCRIPTION - "An index that describes the order of packets - that are received on a particular interface. - The packetID of a packet captured on an - interface is defined to be greater than the - packetID's of all packets captured previously on - the same interface. As the captureBufferPacketID - object has a maximum positive value of 2^31 - 1, - any captureBufferPacketID object shall have the - value of the associated packet's packetID mod 2^31." - ::= { captureBufferEntry 3 } - - captureBufferPacketData OBJECT-TYPE - SYNTAX OCTET STRING - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The data inside the packet, starting at the - beginning of the packet plus any offset specified in - the associated bufferControlDownloadOffset, - including any link level headers. The length of the - data in this object is the minimum of the length of - the captured packet minus the offset, the length of - the associated bufferControlCaptureSliceSize minus - the offset, and the associated - bufferControlDownloadSliceSize. If this minimum is - less than zero, this object shall have a length of - zero." - ::= { captureBufferEntry 4 } - - captureBufferPacketLength OBJECT-TYPE - SYNTAX INTEGER - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The actual length (off the wire) of the packet stored - in this entry, including FCS octets." - ::= { captureBufferEntry 5 } - - captureBufferPacketTime OBJECT-TYPE - SYNTAX INTEGER - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The number of milliseconds that had passed since - this capture buffer was first turned on when this - - - packet was captured." - ::= { captureBufferEntry 6 } - - captureBufferPacketStatus OBJECT-TYPE - SYNTAX INTEGER - ACCESS read-only - STATUS mandatory - DESCRIPTION - "A value which indicates the error status of this - packet. - - The value of this object is defined in the same way as - filterPktStatus. The value is a sum. This sum - initially takes the value zero. Then, for each - error, E, that has been discovered in this packet, - 2 raised to a value representing E is added to the - sum. - - The errors defined for a packet captured off of an - Ethernet interface are as follows: - - bit # Error - 0 Packet is longer than 1518 octets - 1 Packet is shorter than 64 octets - 2 Packet experienced a CRC or Alignment - error - 3 First packet in this capture buffer after - it was detected that some packets were - not processed correctly. - 4 Packet's order in buffer is only - approximate (May only be set for packets - sent from the probe) - - For example, an Ethernet fragment would have a - value of 6 (2^1 + 2^2). - - As this MIB is expanded to new media types, this - object will have other media-specific errors defined." - ::= { captureBufferEntry 7 } - - - -- The Event Group - - -- Implementation of the Event group is optional. - -- - -- The Event group controls the generation and notification - -- of events from this device. Each entry in the eventTable - -- describes the parameters of the event that can be - - - -- triggered. Each event entry is fired by an associated - -- condition located elsewhere in the MIB. An event entry - -- may also be associated- with a function elsewhere in the - -- MIB that will be executed when the event is generated. For - -- example, a channel may be turned on or off by the firing - -- of an event. - -- - -- Each eventEntry may optionally specify that a log entry - -- be created on its behalf whenever the event occurs. - -- Each entry may also specify that notification should - -- occur by way of SNMP trap messages. In this case, the - -- community for the trap message is given in the associated - -- eventCommunity object. The enterprise and specific trap - -- fields of the trap are determined by the condition that - -- triggered the event. Two traps are defined: risingAlarm - -- and fallingAlarm. If the eventTable is triggered by a - -- condition specified elsewhere, the enterprise and - -- specific trap fields must be specified for traps - -- generated for that condition. - - eventTable OBJECT-TYPE - SYNTAX SEQUENCE OF EventEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A list of events to be generated." - ::= { event 1 } - - eventEntry OBJECT-TYPE - SYNTAX EventEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A set of parameters that describe an event to be - generated when certain conditions are met. As an - example, an instance of the eventLastTimeSent object - might be named eventLastTimeSent.6" - INDEX { eventIndex } - ::= { eventTable 1 } - - EventEntry ::= SEQUENCE { - eventIndex INTEGER (1..65535), - eventDescription DisplayString (SIZE (0..127)), - eventType INTEGER, - eventCommunity OCTET STRING (SIZE (0..127)), - eventLastTimeSent TimeTicks, - eventOwner OwnerString, - eventStatus EntryStatus - - - } - - eventIndex OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "An index that uniquely identifies an entry in the - event table. Each such entry defines one event that - is to be generated when the appropriate conditions - occur." - ::= { eventEntry 1 } - - eventDescription OBJECT-TYPE - SYNTAX DisplayString (SIZE (0..127)) - ACCESS read-write - STATUS mandatory - DESCRIPTION - "A comment describing this event entry." - ::= { eventEntry 2 } - - eventType OBJECT-TYPE - SYNTAX INTEGER { - none(1), - log(2), - snmp-trap(3), -- send an SNMP trap - log-and-trap(4) - } - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The type of notification that the probe will make - about this event. In the case of log, an entry is - made in the log table for each event. In the case of - snmp-trap, an SNMP trap is sent to one or more - management stations." - ::= { eventEntry 3 } - - eventCommunity OBJECT-TYPE - SYNTAX OCTET STRING (SIZE (0..127)) - ACCESS read-write - STATUS mandatory - DESCRIPTION - "If an SNMP trap is to be sent, it will be sent to - the SNMP community specified by this octet string. - In the future this table will be extended to include - the party security mechanism. This object shall be - set to a string of length zero if it is intended that - - - that mechanism be used to specify the destination of - the trap." - ::= { eventEntry 4 } - - eventLastTimeSent OBJECT-TYPE - SYNTAX TimeTicks - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The value of sysUpTime at the time this event - entry last generated an event. If this entry has - not generated any events, this value will be - zero." - ::= { eventEntry 5 } - - eventOwner OBJECT-TYPE - SYNTAX OwnerString - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The entity that configured this entry and is - therefore using the resources assigned to it. - - If this object contains a string starting with - 'monitor' and has associated entries in the log - table, all connected management stations should - retrieve those log entries, as they may have - significance to all management stations connected to - this device" - ::= { eventEntry 6 } - - eventStatus OBJECT-TYPE - SYNTAX EntryStatus - ACCESS read-write - STATUS mandatory - DESCRIPTION - "The status of this event entry. - - If this object is not equal to valid(1), all - associated log entries shall be deleted by the - agent." - ::= { eventEntry 7 } - - -- - logTable OBJECT-TYPE - SYNTAX SEQUENCE OF LogEntry - ACCESS not-accessible - STATUS mandatory - - - DESCRIPTION - "A list of events that have been logged." - ::= { event 2 } - - logEntry OBJECT-TYPE - SYNTAX LogEntry - ACCESS not-accessible - STATUS mandatory - DESCRIPTION - "A set of data describing an event that has been - logged. For example, an instance of the - logDescription object might be named - logDescription.6.47" - INDEX { logEventIndex, logIndex } - ::= { logTable 1 } - - LogEntry ::= SEQUENCE { - logEventIndex INTEGER (1..65535), - logIndex INTEGER (1..2147483647), - logTime TimeTicks, - logDescription DisplayString (SIZE (0..255)) - } - - logEventIndex OBJECT-TYPE - SYNTAX INTEGER (1..65535) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The event entry that generated this log - entry. The log identified by a particular - value of this index is associated with the same - eventEntry as identified by the same value - of eventIndex." - ::= { logEntry 1 } - - logIndex OBJECT-TYPE - SYNTAX INTEGER (1..2147483647) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "An index that uniquely identifies an entry - in the log table amongst those generated by the - same eventEntries. These indexes are - assigned beginning with 1 and increase by one - with each new log entry. The association - between values of logIndex and logEntries - is fixed for the lifetime of each logEntry. - The agent may choose to delete the oldest - - - instances of logEntry as required because of - lack of memory. It is an implementation-specific - matter as to when this deletion may occur." - ::= { logEntry 2 } - - logTime OBJECT-TYPE - SYNTAX TimeTicks - ACCESS read-only - STATUS mandatory - DESCRIPTION - "The value of sysUpTime when this log entry was - created." - ::= { logEntry 3 } - - logDescription OBJECT-TYPE - SYNTAX DisplayString (SIZE (0..255)) - ACCESS read-only - STATUS mandatory - DESCRIPTION - "An implementation dependent description of the - event that activated this log entry." - ::= { logEntry 4 } - - -- These definitions use the TRAP-TYPE macro as - -- defined in RFC 1215 [10] - - -- Remote Network Monitoring Traps - - risingAlarm TRAP-TYPE - ENTERPRISE rmon - VARIABLES { alarmIndex, alarmVariable, alarmSampleType, - alarmValue, alarmRisingThreshold } - DESCRIPTION - "The SNMP trap that is generated when an alarm - entry crosses its rising threshold and generates - an event that is configured for sending SNMP - traps." - ::= 1 - - fallingAlarm TRAP-TYPE - ENTERPRISE rmon - VARIABLES { alarmIndex, alarmVariable, alarmSampleType, - alarmValue, alarmFallingThreshold } - DESCRIPTION - "The SNMP trap that is generated when an alarm - entry crosses its falling threshold and generates - an event that is configured for sending SNMP - traps." - - - ::= 2 - - END +RMON-MIB DEFINITIONS ::= BEGIN + IMPORTS + MODULE-IDENTITY, OBJECT-TYPE, OBJECT-IDENTITY, + NOTIFICATION-TYPE, mib-2, Counter32, + Integer32, TimeTicks FROM SNMPv2-SMI + + TEXTUAL-CONVENTION, DisplayString FROM SNMPv2-TC + + MODULE-COMPLIANCE, OBJECT-GROUP, + NOTIFICATION-GROUP FROM SNMPv2-CONF; + + +-- Remote Network Monitoring MIB + +rmonMibModule MODULE-IDENTITY + LAST-UPDATED "200005110000Z" -- 11 May, 2000 + ORGANIZATION "IETF RMON MIB Working Group" + CONTACT-INFO + "Steve Waldbusser + Phone: +1-650-948-6500 + Fax: +1-650-745-0671 + Email: waldbusser@nextbeacon.com" + DESCRIPTION + "Remote network monitoring devices, often called + monitors or probes, are instruments that exist for + the purpose of managing a network. This MIB defines + objects for managing remote network monitoring devices." + + REVISION "200005110000Z" -- 11 May, 2000 + DESCRIPTION + "Reformatted into SMIv2 format. + + This version published as RFC 2819." + + REVISION "199502010000Z" -- 1 Feb, 1995 + DESCRIPTION + "Bug fixes, clarifications and minor changes based on + implementation experience, published as RFC1757 [18]. + + Two changes were made to object definitions: + + 1) A new status bit has been defined for the + captureBufferPacketStatus object, indicating that the + packet order within the capture buffer may not be identical to + the packet order as received off the wire. This bit may only + be used for packets transmitted by the probe. Older NMS + applications can safely ignore this status bit, which might be + used by newer agents. + + 2) The packetMatch trap has been removed. This trap was never + actually 'approved' and was not added to this document along + with the risingAlarm and fallingAlarm traps. The packetMatch + trap could not be throttled, which could cause disruption of + normal network traffic under some circumstances. An NMS should + configure a risingAlarm threshold on the appropriate + channelMatches instance if a trap is desired for a packetMatch + event. Note that logging of packetMatch events is still + supported--only trap generation for such events has been + removed. + + In addition, several clarifications to individual object + definitions have been added to assist agent and NMS + implementors: + + - global definition of 'good packets' and 'bad packets' + + - more detailed text governing conceptual row creation and + modification + + - instructions for probes relating to interface changes and + disruptions + + - clarification of some ethernet counter definitions + + - recommended formula for calculating network utilization + + - clarification of channel and captureBuffer behavior for some + unusual conditions + + - examples of proper instance naming for each table" + + REVISION "199111010000Z" -- 1 Nov, 1991 + DESCRIPTION + "The original version of this MIB, published as RFC1271." + ::= { rmonConformance 8 } + + rmon OBJECT IDENTIFIER ::= { mib-2 16 } + + + -- textual conventions + +OwnerString ::= TEXTUAL-CONVENTION + STATUS current + + DESCRIPTION + "This data type is used to model an administratively + assigned name of the owner of a resource. Implementations + must accept values composed of well-formed NVT ASCII + sequences. In addition, implementations should accept + values composed of well-formed UTF-8 sequences. + + It is suggested that this name contain one or more of + the following: IP address, management station name, + network manager's name, location, or phone number. + In some cases the agent itself will be the owner of + an entry. In these cases, this string shall be set + to a string starting with 'monitor'. + + SNMP access control is articulated entirely in terms + of the contents of MIB views; access to a particular + SNMP object instance depends only upon its presence + or absence in a particular MIB view and never upon + its value or the value of related object instances. + Thus, objects of this type afford resolution of + resource contention only among cooperating + managers; they realize no access control function + with respect to uncooperative parties." + SYNTAX OCTET STRING (SIZE (0..127)) + +EntryStatus ::= TEXTUAL-CONVENTION + STATUS current + DESCRIPTION + "The status of a table entry. + + Setting this object to the value invalid(4) has the + effect of invalidating the corresponding entry. + That is, it effectively disassociates the mapping + identified with said entry. + It is an implementation-specific matter as to whether + the agent removes an invalidated entry from the table. + Accordingly, management stations must be prepared to + receive tabular information from agents that corresponds + to entries currently not in use. Proper + interpretation of such entries requires examination + of the relevant EntryStatus object. + + An existing instance of this object cannot be set to + createRequest(2). This object may only be set to + createRequest(2) when this instance is created. When + this object is created, the agent may wish to create + supplemental object instances with default values + to complete a conceptual row in this table. Because the + creation of these default objects is entirely at the option + of the agent, the manager must not assume that any will be + created, but may make use of any that are created. + Immediately after completing the create operation, the agent + must set this object to underCreation(3). + + When in the underCreation(3) state, an entry is allowed to + exist in a possibly incomplete, possibly inconsistent state, + usually to allow it to be modified in multiple PDUs. When in + this state, an entry is not fully active. + Entries shall exist in the underCreation(3) state until + the management station is finished configuring the entry + and sets this object to valid(1) or aborts, setting this + object to invalid(4). If the agent determines that an + entry has been in the underCreation(3) state for an + abnormally long time, it may decide that the management + station has crashed. If the agent makes this decision, + it may set this object to invalid(4) to reclaim the + entry. A prudent agent will understand that the + management station may need to wait for human input + and will allow for that possibility in its + determination of this abnormally long period. + + An entry in the valid(1) state is fully configured and + consistent and fully represents the configuration or + operation such a row is intended to represent. For + example, it could be a statistical function that is + configured and active, or a filter that is available + in the list of filters processed by the packet capture + process. + + A manager is restricted to changing the state of an entry in + the following ways: + + To: valid createRequest underCreation invalid + From: + valid OK NO OK OK + createRequest N/A N/A N/A N/A + underCreation OK NO OK OK + invalid NO NO NO OK + nonExistent NO OK NO OK + + In the table above, it is not applicable to move the state + from the createRequest state to any other state because the + manager will never find the variable in that state. The + nonExistent state is not a value of the enumeration, rather + it means that the entryStatus variable does not exist at all. + + An agent may allow an entryStatus variable to change state in + additional ways, so long as the semantics of the states are + followed. This allowance is made to ease the implementation of + the agent and is made despite the fact that managers should + never exercise these additional state transitions." + SYNTAX INTEGER { + valid(1), + createRequest(2), + underCreation(3), + invalid(4) + } + + statistics OBJECT IDENTIFIER ::= { rmon 1 } + history OBJECT IDENTIFIER ::= { rmon 2 } + alarm OBJECT IDENTIFIER ::= { rmon 3 } + hosts OBJECT IDENTIFIER ::= { rmon 4 } + hostTopN OBJECT IDENTIFIER ::= { rmon 5 } + matrix OBJECT IDENTIFIER ::= { rmon 6 } + filter OBJECT IDENTIFIER ::= { rmon 7 } + capture OBJECT IDENTIFIER ::= { rmon 8 } + event OBJECT IDENTIFIER ::= { rmon 9 } + rmonConformance OBJECT IDENTIFIER ::= { rmon 20 } + +-- The Ethernet Statistics Group +-- +-- Implementation of the Ethernet Statistics group is optional. +-- Consult the MODULE-COMPLIANCE macro for the authoritative +-- conformance information for this MIB. +-- +-- The ethernet statistics group contains statistics measured by the +-- probe for each monitored interface on this device. These +-- statistics take the form of free running counters that start from +-- zero when a valid entry is created. +-- +-- This group currently has statistics defined only for +-- Ethernet interfaces. Each etherStatsEntry contains statistics +-- for one Ethernet interface. The probe must create one +-- etherStats entry for each monitored Ethernet interface +-- on the device. + +etherStatsTable OBJECT-TYPE + SYNTAX SEQUENCE OF EtherStatsEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A list of Ethernet statistics entries." + ::= { statistics 1 } + +etherStatsEntry OBJECT-TYPE + SYNTAX EtherStatsEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A collection of statistics kept for a particular + Ethernet interface. As an example, an instance of the + etherStatsPkts object might be named etherStatsPkts.1" + INDEX { etherStatsIndex } + ::= { etherStatsTable 1 } + +EtherStatsEntry ::= SEQUENCE { + etherStatsIndex Integer32, + etherStatsDataSource OBJECT IDENTIFIER, + etherStatsDropEvents Counter32, + etherStatsOctets Counter32, + etherStatsPkts Counter32, + etherStatsBroadcastPkts Counter32, + etherStatsMulticastPkts Counter32, + etherStatsCRCAlignErrors Counter32, + etherStatsUndersizePkts Counter32, + etherStatsOversizePkts Counter32, + etherStatsFragments Counter32, + etherStatsJabbers Counter32, + etherStatsCollisions Counter32, + etherStatsPkts64Octets Counter32, + etherStatsPkts65to127Octets Counter32, + etherStatsPkts128to255Octets Counter32, + etherStatsPkts256to511Octets Counter32, + etherStatsPkts512to1023Octets Counter32, + etherStatsPkts1024to1518Octets Counter32, + etherStatsOwner OwnerString, + etherStatsStatus EntryStatus +} + +etherStatsIndex OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The value of this object uniquely identifies this + etherStats entry." + ::= { etherStatsEntry 1 } + +etherStatsDataSource OBJECT-TYPE + SYNTAX OBJECT IDENTIFIER + MAX-ACCESS read-create + STATUS current + + DESCRIPTION + "This object identifies the source of the data that + this etherStats entry is configured to analyze. This + source can be any ethernet interface on this device. + In order to identify a particular interface, this object + shall identify the instance of the ifIndex object, + defined in RFC 2233 [17], for the desired interface. + For example, if an entry were to receive data from + interface #1, this object would be set to ifIndex.1. + + The statistics in this group reflect all packets + on the local network segment attached to the identified + interface. + + An agent may or may not be able to tell if fundamental + changes to the media of the interface have occurred and + necessitate an invalidation of this entry. For example, a + hot-pluggable ethernet card could be pulled out and replaced + by a token-ring card. In such a case, if the agent has such + knowledge of the change, it is recommended that it + invalidate this entry. + + This object may not be modified if the associated + etherStatsStatus object is equal to valid(1)." + ::= { etherStatsEntry 2 } + +etherStatsDropEvents OBJECT-TYPE + SYNTAX Counter32 + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The total number of events in which packets + were dropped by the probe due to lack of resources. + Note that this number is not necessarily the number of + packets dropped; it is just the number of times this + condition has been detected." + ::= { etherStatsEntry 3 } + +etherStatsOctets OBJECT-TYPE + SYNTAX Counter32 + UNITS "Octets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The total number of octets of data (including + those in bad packets) received on the + network (excluding framing bits but including + FCS octets). + + This object can be used as a reasonable estimate of + 10-Megabit ethernet utilization. If greater precision is + desired, the etherStatsPkts and etherStatsOctets objects + should be sampled before and after a common interval. The + differences in the sampled values are Pkts and Octets, + respectively, and the number of seconds in the interval is + Interval. These values are used to calculate the Utilization + as follows: + + Pkts * (9.6 + 6.4) + (Octets * .8) + Utilization = ------------------------------------- + Interval * 10,000 + + The result of this equation is the value Utilization which + is the percent utilization of the ethernet segment on a + scale of 0 to 100 percent." + ::= { etherStatsEntry 4 } + +etherStatsPkts OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The total number of packets (including bad packets, + broadcast packets, and multicast packets) received." + ::= { etherStatsEntry 5 } + +etherStatsBroadcastPkts OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The total number of good packets received that were + directed to the broadcast address. Note that this + does not include multicast packets." + ::= { etherStatsEntry 6 } + +etherStatsMulticastPkts OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The total number of good packets received that were + directed to a multicast address. Note that this number + does not include packets directed to the broadcast + address." + ::= { etherStatsEntry 7 } + +etherStatsCRCAlignErrors OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The total number of packets received that + had a length (excluding framing bits, but + including FCS octets) of between 64 and 1518 + octets, inclusive, but had either a bad + Frame Check Sequence (FCS) with an integral + number of octets (FCS Error) or a bad FCS with + a non-integral number of octets (Alignment Error)." + ::= { etherStatsEntry 8 } + +etherStatsUndersizePkts OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The total number of packets received that were + less than 64 octets long (excluding framing bits, + but including FCS octets) and were otherwise well + formed." + ::= { etherStatsEntry 9 } + +etherStatsOversizePkts OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The total number of packets received that were + longer than 1518 octets (excluding framing bits, + but including FCS octets) and were otherwise + well formed." + ::= { etherStatsEntry 10 } + +etherStatsFragments OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The total number of packets received that were less than + 64 octets in length (excluding framing bits but including + FCS octets) and had either a bad Frame Check Sequence + (FCS) with an integral number of octets (FCS Error) or a + bad FCS with a non-integral number of octets (Alignment + Error). + + Note that it is entirely normal for etherStatsFragments to + increment. This is because it counts both runts (which are + normal occurrences due to collisions) and noise hits." + ::= { etherStatsEntry 11 } + +etherStatsJabbers OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The total number of packets received that were + longer than 1518 octets (excluding framing bits, + but including FCS octets), and had either a bad + Frame Check Sequence (FCS) with an integral number + of octets (FCS Error) or a bad FCS with a non-integral + number of octets (Alignment Error). + + Note that this definition of jabber is different + than the definition in IEEE-802.3 section 8.2.1.5 + (10BASE5) and section 10.3.1.4 (10BASE2). These + documents define jabber as the condition where any + packet exceeds 20 ms. The allowed range to detect + jabber is between 20 ms and 150 ms." + ::= { etherStatsEntry 12 } + +etherStatsCollisions OBJECT-TYPE + SYNTAX Counter32 + UNITS "Collisions" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The best estimate of the total number of collisions + on this Ethernet segment. + + The value returned will depend on the location of the + RMON probe. Section 8.2.1.3 (10BASE-5) and section + 10.3.1.3 (10BASE-2) of IEEE standard 802.3 states that a + station must detect a collision, in the receive mode, if + three or more stations are transmitting simultaneously. A + repeater port must detect a collision when two or more + stations are transmitting simultaneously. Thus a probe + placed on a repeater port could record more collisions + than a probe connected to a station on the same segment + would. + + Probe location plays a much smaller role when considering + 10BASE-T. 14.2.1.4 (10BASE-T) of IEEE standard 802.3 + defines a collision as the simultaneous presence of signals + on the DO and RD circuits (transmitting and receiving + at the same time). A 10BASE-T station can only detect + collisions when it is transmitting. Thus probes placed on + a station and a repeater, should report the same number of + collisions. + + Note also that an RMON probe inside a repeater should + ideally report collisions between the repeater and one or + more other hosts (transmit collisions as defined by IEEE + 802.3k) plus receiver collisions observed on any coax + segments to which the repeater is connected." + ::= { etherStatsEntry 13 } + +etherStatsPkts64Octets OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The total number of packets (including bad + packets) received that were 64 octets in length + (excluding framing bits but including FCS octets)." + ::= { etherStatsEntry 14 } + +etherStatsPkts65to127Octets OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The total number of packets (including bad + packets) received that were between + 65 and 127 octets in length inclusive + (excluding framing bits but including FCS octets)." + ::= { etherStatsEntry 15 } + +etherStatsPkts128to255Octets OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + + STATUS current + DESCRIPTION + "The total number of packets (including bad + packets) received that were between + 128 and 255 octets in length inclusive + (excluding framing bits but including FCS octets)." + ::= { etherStatsEntry 16 } + +etherStatsPkts256to511Octets OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The total number of packets (including bad + packets) received that were between + 256 and 511 octets in length inclusive + (excluding framing bits but including FCS octets)." + ::= { etherStatsEntry 17 } + +etherStatsPkts512to1023Octets OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The total number of packets (including bad + packets) received that were between + 512 and 1023 octets in length inclusive + (excluding framing bits but including FCS octets)." + ::= { etherStatsEntry 18 } + +etherStatsPkts1024to1518Octets OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The total number of packets (including bad + packets) received that were between + 1024 and 1518 octets in length inclusive + (excluding framing bits but including FCS octets)." + ::= { etherStatsEntry 19 } + +etherStatsOwner OBJECT-TYPE + SYNTAX OwnerString + MAX-ACCESS read-create + STATUS current + + DESCRIPTION + "The entity that configured this entry and is therefore + using the resources assigned to it." + ::= { etherStatsEntry 20 } + +etherStatsStatus OBJECT-TYPE + SYNTAX EntryStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The status of this etherStats entry." + ::= { etherStatsEntry 21 } + +-- The History Control Group + +-- Implementation of the History Control group is optional. +-- Consult the MODULE-COMPLIANCE macro for the authoritative +-- conformance information for this MIB. +-- +-- The history control group controls the periodic statistical +-- sampling of data from various types of networks. The +-- historyControlTable stores configuration entries that each +-- define an interface, polling period, and other parameters. +-- Once samples are taken, their data is stored in an entry +-- in a media-specific table. Each such entry defines one +-- sample, and is associated with the historyControlEntry that +-- caused the sample to be taken. Each counter in the +-- etherHistoryEntry counts the same event as its similarly-named +-- counterpart in the etherStatsEntry, except that each value here +-- is a cumulative sum during a sampling period. +-- +-- If the probe keeps track of the time of day, it should start +-- the first sample of the history at a time such that +-- when the next hour of the day begins, a sample is +-- started at that instant. This tends to make more +-- user-friendly reports, and enables comparison of reports +-- from different probes that have relatively accurate time +-- of day. +-- +-- The probe is encouraged to add two history control entries +-- per monitored interface upon initialization that describe a short +-- term and a long term polling period. Suggested parameters are 30 +-- seconds for the short term polling period and 30 minutes for +-- the long term period. + +historyControlTable OBJECT-TYPE + SYNTAX SEQUENCE OF HistoryControlEntry + MAX-ACCESS not-accessible + + STATUS current + DESCRIPTION + "A list of history control entries." + ::= { history 1 } + +historyControlEntry OBJECT-TYPE + SYNTAX HistoryControlEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A list of parameters that set up a periodic sampling of + statistics. As an example, an instance of the + historyControlInterval object might be named + historyControlInterval.2" + INDEX { historyControlIndex } + ::= { historyControlTable 1 } + +HistoryControlEntry ::= SEQUENCE { + historyControlIndex Integer32, + historyControlDataSource OBJECT IDENTIFIER, + historyControlBucketsRequested Integer32, + historyControlBucketsGranted Integer32, + historyControlInterval Integer32, + historyControlOwner OwnerString, + historyControlStatus EntryStatus +} + +historyControlIndex OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "An index that uniquely identifies an entry in the + historyControl table. Each such entry defines a + set of samples at a particular interval for an + interface on the device." + ::= { historyControlEntry 1 } + +historyControlDataSource OBJECT-TYPE + SYNTAX OBJECT IDENTIFIER + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object identifies the source of the data for + which historical data was collected and + placed in a media-specific table on behalf of this + historyControlEntry. This source can be any + interface on this device. In order to identify + a particular interface, this object shall identify + the instance of the ifIndex object, defined + in RFC 2233 [17], for the desired interface. + For example, if an entry were to receive data from + interface #1, this object would be set to ifIndex.1. + + The statistics in this group reflect all packets + on the local network segment attached to the identified + interface. + + An agent may or may not be able to tell if fundamental + changes to the media of the interface have occurred and + necessitate an invalidation of this entry. For example, a + hot-pluggable ethernet card could be pulled out and replaced + by a token-ring card. In such a case, if the agent has such + knowledge of the change, it is recommended that it + invalidate this entry. + + This object may not be modified if the associated + historyControlStatus object is equal to valid(1)." + ::= { historyControlEntry 2 } + +historyControlBucketsRequested OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The requested number of discrete time intervals + over which data is to be saved in the part of the + media-specific table associated with this + historyControlEntry. + + When this object is created or modified, the probe + should set historyControlBucketsGranted as closely to + this object as is possible for the particular probe + implementation and available resources." + DEFVAL { 50 } + ::= { historyControlEntry 3 } + +historyControlBucketsGranted OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of discrete sampling intervals + over which data shall be saved in the part of + the media-specific table associated with this + historyControlEntry. + + When the associated historyControlBucketsRequested + object is created or modified, the probe + should set this object as closely to the requested + value as is possible for the particular + probe implementation and available resources. The + probe must not lower this value except as a result + of a modification to the associated + historyControlBucketsRequested object. + + There will be times when the actual number of + buckets associated with this entry is less than + the value of this object. In this case, at the + end of each sampling interval, a new bucket will + be added to the media-specific table. + + When the number of buckets reaches the value of + this object and a new bucket is to be added to the + media-specific table, the oldest bucket associated + with this historyControlEntry shall be deleted by + the agent so that the new bucket can be added. + + When the value of this object changes to a value less + than the current value, entries are deleted + from the media-specific table associated with this + historyControlEntry. Enough of the oldest of these + entries shall be deleted by the agent so that their + number remains less than or equal to the new value of + this object. + + When the value of this object changes to a value greater + than the current value, the number of associated media- + specific entries may be allowed to grow." + ::= { historyControlEntry 4 } + +historyControlInterval OBJECT-TYPE + SYNTAX Integer32 (1..3600) + UNITS "Seconds" + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The interval in seconds over which the data is + sampled for each bucket in the part of the + media-specific table associated with this + historyControlEntry. This interval can + be set to any number of seconds between 1 and + 3600 (1 hour). + + Because the counters in a bucket may overflow at their + maximum value with no indication, a prudent manager will + take into account the possibility of overflow in any of + the associated counters. It is important to consider the + minimum time in which any counter could overflow on a + particular media type and set the historyControlInterval + object to a value less than this interval. This is + typically most important for the 'octets' counter in any + media-specific table. For example, on an Ethernet + network, the etherHistoryOctets counter could overflow + in about one hour at the Ethernet's maximum + utilization. + + This object may not be modified if the associated + historyControlStatus object is equal to valid(1)." + DEFVAL { 1800 } + ::= { historyControlEntry 5 } + +historyControlOwner OBJECT-TYPE + SYNTAX OwnerString + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The entity that configured this entry and is therefore + using the resources assigned to it." + ::= { historyControlEntry 6 } + +historyControlStatus OBJECT-TYPE + SYNTAX EntryStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The status of this historyControl entry. + + Each instance of the media-specific table associated + with this historyControlEntry will be deleted by the agent + if this historyControlEntry is not equal to valid(1)." + ::= { historyControlEntry 7 } + +-- The Ethernet History Group + +-- Implementation of the Ethernet History group is optional. +-- Consult the MODULE-COMPLIANCE macro for the authoritative +-- conformance information for this MIB. +-- +-- The Ethernet History group records periodic statistical samples +-- from a network and stores them for later retrieval. +-- Once samples are taken, their data is stored in an entry +-- in a media-specific table. Each such entry defines one +-- sample, and is associated with the historyControlEntry that +-- caused the sample to be taken. This group defines the +-- etherHistoryTable, for Ethernet networks. +-- + +etherHistoryTable OBJECT-TYPE + SYNTAX SEQUENCE OF EtherHistoryEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A list of Ethernet history entries." + ::= { history 2 } + +etherHistoryEntry OBJECT-TYPE + SYNTAX EtherHistoryEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "An historical sample of Ethernet statistics on a particular + Ethernet interface. This sample is associated with the + historyControlEntry which set up the parameters for + a regular collection of these samples. As an example, an + instance of the etherHistoryPkts object might be named + etherHistoryPkts.2.89" + INDEX { etherHistoryIndex , etherHistorySampleIndex } + ::= { etherHistoryTable 1 } + +EtherHistoryEntry ::= SEQUENCE { + etherHistoryIndex Integer32, + etherHistorySampleIndex Integer32, + etherHistoryIntervalStart TimeTicks, + etherHistoryDropEvents Counter32, + etherHistoryOctets Counter32, + etherHistoryPkts Counter32, + etherHistoryBroadcastPkts Counter32, + etherHistoryMulticastPkts Counter32, + etherHistoryCRCAlignErrors Counter32, + etherHistoryUndersizePkts Counter32, + etherHistoryOversizePkts Counter32, + etherHistoryFragments Counter32, + etherHistoryJabbers Counter32, + etherHistoryCollisions Counter32, + etherHistoryUtilization Integer32 +} + +etherHistoryIndex OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The history of which this entry is a part. The + history identified by a particular value of this + index is the same history as identified + by the same value of historyControlIndex." + ::= { etherHistoryEntry 1 } + +etherHistorySampleIndex OBJECT-TYPE + SYNTAX Integer32 (1..2147483647) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "An index that uniquely identifies the particular + sample this entry represents among all samples + associated with the same historyControlEntry. + This index starts at 1 and increases by one + as each new sample is taken." + ::= { etherHistoryEntry 2 } + +etherHistoryIntervalStart OBJECT-TYPE + SYNTAX TimeTicks + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The value of sysUpTime at the start of the interval + over which this sample was measured. If the probe + keeps track of the time of day, it should start + the first sample of the history at a time such that + when the next hour of the day begins, a sample is + started at that instant. Note that following this + rule may require the probe to delay collecting the + first sample of the history, as each sample must be + of the same interval. Also note that the sample which + is currently being collected is not accessible in this + table until the end of its interval." + ::= { etherHistoryEntry 3 } + +etherHistoryDropEvents OBJECT-TYPE + SYNTAX Counter32 + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The total number of events in which packets + were dropped by the probe due to lack of resources + during this sampling interval. Note that this number + is not necessarily the number of packets dropped, it + is just the number of times this condition has been + detected." + ::= { etherHistoryEntry 4 } + +etherHistoryOctets OBJECT-TYPE + SYNTAX Counter32 + UNITS "Octets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The total number of octets of data (including + those in bad packets) received on the + network (excluding framing bits but including + FCS octets)." + ::= { etherHistoryEntry 5 } + +etherHistoryPkts OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of packets (including bad packets) + received during this sampling interval." + ::= { etherHistoryEntry 6 } + +etherHistoryBroadcastPkts OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of good packets received during this + sampling interval that were directed to the + broadcast address." + ::= { etherHistoryEntry 7 } + +etherHistoryMulticastPkts OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of good packets received during this + sampling interval that were directed to a + multicast address. Note that this number does not + include packets addressed to the broadcast address." + ::= { etherHistoryEntry 8 } + +etherHistoryCRCAlignErrors OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of packets received during this + sampling interval that had a length (excluding + framing bits but including FCS octets) between + 64 and 1518 octets, inclusive, but had either a bad Frame + Check Sequence (FCS) with an integral number of octets + (FCS Error) or a bad FCS with a non-integral number + of octets (Alignment Error)." + ::= { etherHistoryEntry 9 } + +etherHistoryUndersizePkts OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of packets received during this + sampling interval that were less than 64 octets + long (excluding framing bits but including FCS + octets) and were otherwise well formed." + ::= { etherHistoryEntry 10 } + +etherHistoryOversizePkts OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of packets received during this + sampling interval that were longer than 1518 + octets (excluding framing bits but including + FCS octets) but were otherwise well formed." + ::= { etherHistoryEntry 11 } + +etherHistoryFragments OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The total number of packets received during this + sampling interval that were less than 64 octets in + length (excluding framing bits but including FCS + octets) had either a bad Frame Check Sequence (FCS) + with an integral number of octets (FCS Error) or a bad + FCS with a non-integral number of octets (Alignment + Error). + + Note that it is entirely normal for etherHistoryFragments to + increment. This is because it counts both runts (which are + normal occurrences due to collisions) and noise hits." + ::= { etherHistoryEntry 12 } + +etherHistoryJabbers OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of packets received during this + sampling interval that were longer than 1518 octets + (excluding framing bits but including FCS octets), + and had either a bad Frame Check Sequence (FCS) + with an integral number of octets (FCS Error) or + a bad FCS with a non-integral number of octets + (Alignment Error). + + Note that this definition of jabber is different + than the definition in IEEE-802.3 section 8.2.1.5 + (10BASE5) and section 10.3.1.4 (10BASE2). These + documents define jabber as the condition where any + packet exceeds 20 ms. The allowed range to detect + jabber is between 20 ms and 150 ms." + ::= { etherHistoryEntry 13 } + +etherHistoryCollisions OBJECT-TYPE + SYNTAX Counter32 + UNITS "Collisions" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The best estimate of the total number of collisions + on this Ethernet segment during this sampling + interval. + + The value returned will depend on the location of the + RMON probe. Section 8.2.1.3 (10BASE-5) and section + 10.3.1.3 (10BASE-2) of IEEE standard 802.3 states that a + station must detect a collision, in the receive mode, if + three or more stations are transmitting simultaneously. A + repeater port must detect a collision when two or more + stations are transmitting simultaneously. Thus a probe + placed on a repeater port could record more collisions + than a probe connected to a station on the same segment + would. + + Probe location plays a much smaller role when considering + 10BASE-T. 14.2.1.4 (10BASE-T) of IEEE standard 802.3 + defines a collision as the simultaneous presence of signals + on the DO and RD circuits (transmitting and receiving + at the same time). A 10BASE-T station can only detect + collisions when it is transmitting. Thus probes placed on + a station and a repeater, should report the same number of + collisions. + + Note also that an RMON probe inside a repeater should + ideally report collisions between the repeater and one or + more other hosts (transmit collisions as defined by IEEE + 802.3k) plus receiver collisions observed on any coax + segments to which the repeater is connected." + ::= { etherHistoryEntry 14 } + +etherHistoryUtilization OBJECT-TYPE + SYNTAX Integer32 (0..10000) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The best estimate of the mean physical layer + network utilization on this interface during this + sampling interval, in hundredths of a percent." + ::= { etherHistoryEntry 15 } + +-- The Alarm Group + +-- Implementation of the Alarm group is optional. The Alarm Group +-- requires the implementation of the Event group. +-- Consult the MODULE-COMPLIANCE macro for the authoritative +-- conformance information for this MIB. +-- +-- The Alarm group periodically takes statistical samples from +-- variables in the probe and compares them to thresholds that have +-- been configured. The alarm table stores configuration +-- entries that each define a variable, polling period, and +-- threshold parameters. If a sample is found to cross the +-- threshold values, an event is generated. Only variables that +-- resolve to an ASN.1 primitive type of INTEGER (INTEGER, Integer32, +-- Counter32, Counter64, Gauge32, or TimeTicks) may be monitored in +-- this way. +-- +-- This function has a hysteresis mechanism to limit the generation +-- of events. This mechanism generates one event as a threshold +-- is crossed in the appropriate direction. No more events are +-- generated for that threshold until the opposite threshold is +-- crossed. +-- +-- In the case of a sampling a deltaValue, a probe may implement +-- this mechanism with more precision if it takes a delta sample +-- twice per period, each time comparing the sum of the latest two +-- samples to the threshold. This allows the detection of threshold +-- crossings that span the sampling boundary. Note that this does +-- not require any special configuration of the threshold value. +-- It is suggested that probes implement this more precise algorithm. + +alarmTable OBJECT-TYPE + SYNTAX SEQUENCE OF AlarmEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A list of alarm entries." + ::= { alarm 1 } + +alarmEntry OBJECT-TYPE + SYNTAX AlarmEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A list of parameters that set up a periodic checking + for alarm conditions. For example, an instance of the + alarmValue object might be named alarmValue.8" + INDEX { alarmIndex } + ::= { alarmTable 1 } + +AlarmEntry ::= SEQUENCE { + alarmIndex Integer32, + alarmInterval Integer32, + alarmVariable OBJECT IDENTIFIER, + alarmSampleType INTEGER, + alarmValue Integer32, + alarmStartupAlarm INTEGER, + alarmRisingThreshold Integer32, + alarmFallingThreshold Integer32, + alarmRisingEventIndex Integer32, + alarmFallingEventIndex Integer32, + alarmOwner OwnerString, + alarmStatus EntryStatus +} + +alarmIndex OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "An index that uniquely identifies an entry in the + alarm table. Each such entry defines a + diagnostic sample at a particular interval + for an object on the device." + ::= { alarmEntry 1 } + +alarmInterval OBJECT-TYPE + SYNTAX Integer32 + UNITS "Seconds" + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The interval in seconds over which the data is + sampled and compared with the rising and falling + thresholds. When setting this variable, care + should be taken in the case of deltaValue + sampling - the interval should be set short enough + that the sampled variable is very unlikely to + increase or decrease by more than 2^31 - 1 during + a single sampling interval. + + This object may not be modified if the associated + alarmStatus object is equal to valid(1)." + ::= { alarmEntry 2 } + +alarmVariable OBJECT-TYPE + SYNTAX OBJECT IDENTIFIER + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The object identifier of the particular variable to be + sampled. Only variables that resolve to an ASN.1 primitive + type of INTEGER (INTEGER, Integer32, Counter32, Counter64, + Gauge, or TimeTicks) may be sampled. + + Because SNMP access control is articulated entirely + in terms of the contents of MIB views, no access + control mechanism exists that can restrict the value of + this object to identify only those objects that exist + in a particular MIB view. Because there is thus no + acceptable means of restricting the read access that + could be obtained through the alarm mechanism, the + probe must only grant write access to this object in + those views that have read access to all objects on + the probe. + + During a set operation, if the supplied variable name is + not available in the selected MIB view, a badValue error + must be returned. If at any time the variable name of + an established alarmEntry is no longer available in the + selected MIB view, the probe must change the status of + this alarmEntry to invalid(4). + + This object may not be modified if the associated + alarmStatus object is equal to valid(1)." + ::= { alarmEntry 3 } + +alarmSampleType OBJECT-TYPE + SYNTAX INTEGER { + absoluteValue(1), + deltaValue(2) + } + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The method of sampling the selected variable and + calculating the value to be compared against the + thresholds. If the value of this object is + absoluteValue(1), the value of the selected variable + will be compared directly with the thresholds at the + end of the sampling interval. If the value of this + object is deltaValue(2), the value of the selected + variable at the last sample will be subtracted from + the current value, and the difference compared with + the thresholds. + + This object may not be modified if the associated + alarmStatus object is equal to valid(1)." + ::= { alarmEntry 4 } + +alarmValue OBJECT-TYPE + SYNTAX Integer32 + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The value of the statistic during the last sampling + period. For example, if the sample type is deltaValue, + this value will be the difference between the samples + at the beginning and end of the period. If the sample + type is absoluteValue, this value will be the sampled + value at the end of the period. + This is the value that is compared with the rising and + falling thresholds. + + The value during the current sampling period is not + made available until the period is completed and will + remain available until the next period completes." + ::= { alarmEntry 5 } + +alarmStartupAlarm OBJECT-TYPE + SYNTAX INTEGER { + risingAlarm(1), + fallingAlarm(2), + risingOrFallingAlarm(3) + } + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The alarm that may be sent when this entry is first + set to valid. If the first sample after this entry + becomes valid is greater than or equal to the + risingThreshold and alarmStartupAlarm is equal to + risingAlarm(1) or risingOrFallingAlarm(3), then a single + rising alarm will be generated. If the first sample + after this entry becomes valid is less than or equal + to the fallingThreshold and alarmStartupAlarm is equal + to fallingAlarm(2) or risingOrFallingAlarm(3), then a + single falling alarm will be generated. + + This object may not be modified if the associated + alarmStatus object is equal to valid(1)." + ::= { alarmEntry 6 } + +alarmRisingThreshold OBJECT-TYPE + SYNTAX Integer32 + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "A threshold for the sampled statistic. When the current + sampled value is greater than or equal to this threshold, + and the value at the last sampling interval was less than + this threshold, a single event will be generated. + A single event will also be generated if the first + sample after this entry becomes valid is greater than or + equal to this threshold and the associated + alarmStartupAlarm is equal to risingAlarm(1) or + risingOrFallingAlarm(3). + + After a rising event is generated, another such event + will not be generated until the sampled value + falls below this threshold and reaches the + alarmFallingThreshold. + + This object may not be modified if the associated + alarmStatus object is equal to valid(1)." + ::= { alarmEntry 7 } + +alarmFallingThreshold OBJECT-TYPE + SYNTAX Integer32 + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "A threshold for the sampled statistic. When the current + sampled value is less than or equal to this threshold, + and the value at the last sampling interval was greater than + this threshold, a single event will be generated. + A single event will also be generated if the first + sample after this entry becomes valid is less than or + equal to this threshold and the associated + alarmStartupAlarm is equal to fallingAlarm(2) or + risingOrFallingAlarm(3). + + After a falling event is generated, another such event + will not be generated until the sampled value + rises above this threshold and reaches the + alarmRisingThreshold. + + This object may not be modified if the associated + alarmStatus object is equal to valid(1)." + ::= { alarmEntry 8 } + +alarmRisingEventIndex OBJECT-TYPE + SYNTAX Integer32 (0..65535) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The index of the eventEntry that is + used when a rising threshold is crossed. The + eventEntry identified by a particular value of + this index is the same as identified by the same value + of the eventIndex object. If there is no + corresponding entry in the eventTable, then + no association exists. In particular, if this value + is zero, no associated event will be generated, as + zero is not a valid event index. + + This object may not be modified if the associated + alarmStatus object is equal to valid(1)." + ::= { alarmEntry 9 } + +alarmFallingEventIndex OBJECT-TYPE + SYNTAX Integer32 (0..65535) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The index of the eventEntry that is + used when a falling threshold is crossed. The + eventEntry identified by a particular value of + this index is the same as identified by the same value + of the eventIndex object. If there is no + corresponding entry in the eventTable, then + no association exists. In particular, if this value + is zero, no associated event will be generated, as + zero is not a valid event index. + + This object may not be modified if the associated + alarmStatus object is equal to valid(1)." + ::= { alarmEntry 10 } + +alarmOwner OBJECT-TYPE + SYNTAX OwnerString + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The entity that configured this entry and is therefore + using the resources assigned to it." + ::= { alarmEntry 11 } + +alarmStatus OBJECT-TYPE + SYNTAX EntryStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The status of this alarm entry." + ::= { alarmEntry 12 } + +-- The Host Group + +-- Implementation of the Host group is optional. +-- Consult the MODULE-COMPLIANCE macro for the authoritative +-- conformance information for this MIB. +-- +-- The host group discovers new hosts on the network by +-- keeping a list of source and destination MAC Addresses seen +-- in good packets. For each of these addresses, the host group +-- keeps a set of statistics. The hostControlTable controls +-- which interfaces this function is performed on, and contains +-- some information about the process. On behalf of each +-- hostControlEntry, data is collected on an interface and placed +-- in both the hostTable and the hostTimeTable. If the +-- monitoring device finds itself short of resources, it may +-- delete entries as needed. It is suggested that the device +-- delete the least recently used entries first. + +-- The hostTable contains entries for each address discovered on +-- a particular interface. Each entry contains statistical +-- data about that host. This table is indexed by the +-- MAC address of the host, through which a random access +-- may be achieved. + +-- The hostTimeTable contains data in the same format as the +-- hostTable, and must contain the same set of hosts, but is +-- indexed using hostTimeCreationOrder rather than hostAddress. +-- The hostTimeCreationOrder is an integer which reflects +-- the relative order in which a particular entry was discovered +-- and thus inserted into the table. As this order, and thus +-- the index, is among those entries currently in the table, +-- the index for a particular entry may change if an +-- (earlier) entry is deleted. Thus the association between +-- hostTimeCreationOrder and hostTimeEntry may be broken at +-- any time. + +-- The hostTimeTable has two important uses. The first is the +-- fast download of this potentially large table. Because the +-- index of this table runs from 1 to the size of the table, +-- inclusive, its values are predictable. This allows very +-- efficient packing of variables into SNMP PDU's and allows +-- a table transfer to have multiple packets outstanding. +-- These benefits increase transfer rates tremendously. + +-- The second use of the hostTimeTable is the efficient discovery +-- by the management station of new entries added to the table. +-- After the management station has downloaded the entire table, +-- it knows that new entries will be added immediately after the +-- end of the current table. It can thus detect new entries there +-- and retrieve them easily. + +-- Because the association between hostTimeCreationOrder and +-- hostTimeEntry may be broken at any time, the management +-- station must monitor the related hostControlLastDeleteTime +-- object. When the management station thus detects a deletion, +-- it must assume that any such associations have been broken, +-- and invalidate any it has stored locally. This includes +-- restarting any download of the hostTimeTable that may have been +-- in progress, as well as rediscovering the end of the +-- hostTimeTable so that it may detect new entries. If the +-- management station does not detect the broken association, +-- it may continue to refer to a particular host by its +-- creationOrder while unwittingly retrieving the data associated +-- with another host entirely. If this happens while downloading +-- the host table, the management station may fail to download +-- all of the entries in the table. + + +hostControlTable OBJECT-TYPE + SYNTAX SEQUENCE OF HostControlEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A list of host table control entries." + ::= { hosts 1 } + +hostControlEntry OBJECT-TYPE + SYNTAX HostControlEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A list of parameters that set up the discovery of hosts + on a particular interface and the collection of statistics + about these hosts. For example, an instance of the + hostControlTableSize object might be named + hostControlTableSize.1" + INDEX { hostControlIndex } + ::= { hostControlTable 1 } + +HostControlEntry ::= SEQUENCE { + + hostControlIndex Integer32, + hostControlDataSource OBJECT IDENTIFIER, + hostControlTableSize Integer32, + hostControlLastDeleteTime TimeTicks, + hostControlOwner OwnerString, + hostControlStatus EntryStatus +} + +hostControlIndex OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "An index that uniquely identifies an entry in the + hostControl table. Each such entry defines + a function that discovers hosts on a particular interface + and places statistics about them in the hostTable and + the hostTimeTable on behalf of this hostControlEntry." + ::= { hostControlEntry 1 } + +hostControlDataSource OBJECT-TYPE + SYNTAX OBJECT IDENTIFIER + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object identifies the source of the data for + this instance of the host function. This source + can be any interface on this device. In order + to identify a particular interface, this object shall + identify the instance of the ifIndex object, defined + in RFC 2233 [17], for the desired interface. + For example, if an entry were to receive data from + interface #1, this object would be set to ifIndex.1. + + The statistics in this group reflect all packets + on the local network segment attached to the identified + interface. + + An agent may or may not be able to tell if fundamental + changes to the media of the interface have occurred and + necessitate an invalidation of this entry. For example, a + hot-pluggable ethernet card could be pulled out and replaced + by a token-ring card. In such a case, if the agent has such + knowledge of the change, it is recommended that it + invalidate this entry. + + This object may not be modified if the associated + hostControlStatus object is equal to valid(1)." + ::= { hostControlEntry 2 } + +hostControlTableSize OBJECT-TYPE + SYNTAX Integer32 + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of hostEntries in the hostTable and the + hostTimeTable associated with this hostControlEntry." + ::= { hostControlEntry 3 } + +hostControlLastDeleteTime OBJECT-TYPE + SYNTAX TimeTicks + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The value of sysUpTime when the last entry + was deleted from the portion of the hostTable + associated with this hostControlEntry. If no + deletions have occurred, this value shall be zero." + ::= { hostControlEntry 4 } + +hostControlOwner OBJECT-TYPE + SYNTAX OwnerString + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The entity that configured this entry and is therefore + using the resources assigned to it." + ::= { hostControlEntry 5 } + +hostControlStatus OBJECT-TYPE + SYNTAX EntryStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The status of this hostControl entry. + + If this object is not equal to valid(1), all associated + entries in the hostTable, hostTimeTable, and the + hostTopNTable shall be deleted by the agent." + ::= { hostControlEntry 6 } + +hostTable OBJECT-TYPE + SYNTAX SEQUENCE OF HostEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A list of host entries." + ::= { hosts 2 } + +hostEntry OBJECT-TYPE + SYNTAX HostEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A collection of statistics for a particular host that has + been discovered on an interface of this device. For example, + an instance of the hostOutBroadcastPkts object might be + named hostOutBroadcastPkts.1.6.8.0.32.27.3.176" + INDEX { hostIndex, hostAddress } + ::= { hostTable 1 } + +HostEntry ::= SEQUENCE { + hostAddress OCTET STRING, + hostCreationOrder Integer32, + hostIndex Integer32, + hostInPkts Counter32, + hostOutPkts Counter32, + hostInOctets Counter32, + hostOutOctets Counter32, + hostOutErrors Counter32, + hostOutBroadcastPkts Counter32, + hostOutMulticastPkts Counter32 +} + +hostAddress OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The physical address of this host." + ::= { hostEntry 1 } + +hostCreationOrder OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "An index that defines the relative ordering of + the creation time of hosts captured for a + particular hostControlEntry. This index shall + be between 1 and N, where N is the value of + the associated hostControlTableSize. The ordering + of the indexes is based on the order of each entry's + insertion into the table, in which entries added earlier + have a lower index value than entries added later. + + It is important to note that the order for a + particular entry may change as an (earlier) entry + is deleted from the table. Because this order may + change, management stations should make use of the + hostControlLastDeleteTime variable in the + hostControlEntry associated with the relevant + portion of the hostTable. By observing + this variable, the management station may detect + the circumstances where a previous association + between a value of hostCreationOrder + and a hostEntry may no longer hold." + ::= { hostEntry 2 } + +hostIndex OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The set of collected host statistics of which + this entry is a part. The set of hosts + identified by a particular value of this + index is associated with the hostControlEntry + as identified by the same value of hostControlIndex." + ::= { hostEntry 3 } + +hostInPkts OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of good packets transmitted to this + address since it was added to the hostTable." + ::= { hostEntry 4 } + +hostOutPkts OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of packets, including bad packets, transmitted + by this address since it was added to the hostTable." + ::= { hostEntry 5 } + +hostInOctets OBJECT-TYPE + SYNTAX Counter32 + UNITS "Octets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of octets transmitted to this address since + it was added to the hostTable (excluding framing + bits but including FCS octets), except for those + octets in bad packets." + ::= { hostEntry 6 } + +hostOutOctets OBJECT-TYPE + SYNTAX Counter32 + UNITS "Octets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of octets transmitted by this address since + it was added to the hostTable (excluding framing + bits but including FCS octets), including those + octets in bad packets." + ::= { hostEntry 7 } + +hostOutErrors OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of bad packets transmitted by this address + since this host was added to the hostTable." + ::= { hostEntry 8 } + +hostOutBroadcastPkts OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of good packets transmitted by this + address that were directed to the broadcast address + since this host was added to the hostTable." + ::= { hostEntry 9 } + +hostOutMulticastPkts OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of good packets transmitted by this + address that were directed to a multicast address + since this host was added to the hostTable. + Note that this number does not include packets + directed to the broadcast address." + ::= { hostEntry 10 } + +-- host Time Table + +hostTimeTable OBJECT-TYPE + SYNTAX SEQUENCE OF HostTimeEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A list of time-ordered host table entries." + ::= { hosts 3 } + +hostTimeEntry OBJECT-TYPE + SYNTAX HostTimeEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A collection of statistics for a particular host that has + been discovered on an interface of this device. This + collection includes the relative ordering of the creation + time of this object. For example, an instance of the + hostTimeOutBroadcastPkts object might be named + hostTimeOutBroadcastPkts.1.687" + INDEX { hostTimeIndex, hostTimeCreationOrder } + ::= { hostTimeTable 1 } + +HostTimeEntry ::= SEQUENCE { + hostTimeAddress OCTET STRING, + hostTimeCreationOrder Integer32, + hostTimeIndex Integer32, + hostTimeInPkts Counter32, + hostTimeOutPkts Counter32, + hostTimeInOctets Counter32, + hostTimeOutOctets Counter32, + hostTimeOutErrors Counter32, + hostTimeOutBroadcastPkts Counter32, + hostTimeOutMulticastPkts Counter32 +} + +hostTimeAddress OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The physical address of this host." + ::= { hostTimeEntry 1 } + +hostTimeCreationOrder OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "An index that uniquely identifies an entry in + the hostTime table among those entries associated + with the same hostControlEntry. This index shall + be between 1 and N, where N is the value of + the associated hostControlTableSize. The ordering + of the indexes is based on the order of each entry's + insertion into the table, in which entries added earlier + have a lower index value than entries added later. + Thus the management station has the ability to + learn of new entries added to this table without + downloading the entire table. + + It is important to note that the index for a + particular entry may change as an (earlier) entry + is deleted from the table. Because this order may + change, management stations should make use of the + hostControlLastDeleteTime variable in the + hostControlEntry associated with the relevant + portion of the hostTimeTable. By observing + this variable, the management station may detect + the circumstances where a download of the table + may have missed entries, and where a previous + association between a value of hostTimeCreationOrder + and a hostTimeEntry may no longer hold." + ::= { hostTimeEntry 2 } + +hostTimeIndex OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The set of collected host statistics of which + this entry is a part. The set of hosts + identified by a particular value of this + index is associated with the hostControlEntry + as identified by the same value of hostControlIndex." + ::= { hostTimeEntry 3 } + +hostTimeInPkts OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of good packets transmitted to this + address since it was added to the hostTimeTable." + ::= { hostTimeEntry 4 } + +hostTimeOutPkts OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of packets, including bad packets, transmitted + by this address since it was added to the hostTimeTable." + ::= { hostTimeEntry 5 } + +hostTimeInOctets OBJECT-TYPE + SYNTAX Counter32 + UNITS "Octets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of octets transmitted to this address since + it was added to the hostTimeTable (excluding framing + bits but including FCS octets), except for those + octets in bad packets." + ::= { hostTimeEntry 6 } + +hostTimeOutOctets OBJECT-TYPE + SYNTAX Counter32 + UNITS "Octets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of octets transmitted by this address since + it was added to the hostTimeTable (excluding framing + bits but including FCS octets), including those + octets in bad packets." + ::= { hostTimeEntry 7 } + +hostTimeOutErrors OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of bad packets transmitted by this address + since this host was added to the hostTimeTable." + ::= { hostTimeEntry 8 } + +hostTimeOutBroadcastPkts OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of good packets transmitted by this + address that were directed to the broadcast address + since this host was added to the hostTimeTable." + ::= { hostTimeEntry 9 } + +hostTimeOutMulticastPkts OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of good packets transmitted by this + address that were directed to a multicast address + since this host was added to the hostTimeTable. + Note that this number does not include packets directed + to the broadcast address." + ::= { hostTimeEntry 10 } + +-- The Host Top "N" Group + +-- Implementation of the Host Top N group is optional. The Host Top N +-- group requires the implementation of the host group. +-- Consult the MODULE-COMPLIANCE macro for the authoritative +-- conformance information for this MIB. +-- +-- The Host Top N group is used to prepare reports that describe +-- the hosts that top a list ordered by one of their statistics. +-- The available statistics are samples of one of their +-- base statistics, over an interval specified by the management +-- station. Thus, these statistics are rate based. The management +-- station also selects how many such hosts are reported. + +-- The hostTopNControlTable is used to initiate the generation of +-- such a report. The management station may select the parameters +-- of such a report, such as which interface, which statistic, +-- how many hosts, and the start and stop times of the sampling. +-- When the report is prepared, entries are created in the +-- hostTopNTable associated with the relevant hostTopNControlEntry. +-- These entries are static for each report after it has been +-- prepared. + +hostTopNControlTable OBJECT-TYPE + SYNTAX SEQUENCE OF HostTopNControlEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A list of top N host control entries." + ::= { hostTopN 1 } + +hostTopNControlEntry OBJECT-TYPE + SYNTAX HostTopNControlEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A set of parameters that control the creation of a report + of the top N hosts according to several metrics. For + example, an instance of the hostTopNDuration object might + be named hostTopNDuration.3" + INDEX { hostTopNControlIndex } + ::= { hostTopNControlTable 1 } + +HostTopNControlEntry ::= SEQUENCE { + hostTopNControlIndex Integer32, + hostTopNHostIndex Integer32, + hostTopNRateBase INTEGER, + hostTopNTimeRemaining Integer32, + hostTopNDuration Integer32, + hostTopNRequestedSize Integer32, + hostTopNGrantedSize Integer32, + hostTopNStartTime TimeTicks, + hostTopNOwner OwnerString, + hostTopNStatus EntryStatus +} + +hostTopNControlIndex OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "An index that uniquely identifies an entry + in the hostTopNControl table. Each such + entry defines one top N report prepared for + one interface." + ::= { hostTopNControlEntry 1 } + +hostTopNHostIndex OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The host table for which a top N report will be prepared + on behalf of this entry. The host table identified by a + particular value of this index is associated with the same + host table as identified by the same value of + hostIndex. + + This object may not be modified if the associated + hostTopNStatus object is equal to valid(1)." + ::= { hostTopNControlEntry 2 } + +hostTopNRateBase OBJECT-TYPE + SYNTAX INTEGER { + hostTopNInPkts(1), + hostTopNOutPkts(2), + hostTopNInOctets(3), + hostTopNOutOctets(4), + hostTopNOutErrors(5), + hostTopNOutBroadcastPkts(6), + hostTopNOutMulticastPkts(7) + } + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The variable for each host that the hostTopNRate + variable is based upon. + + This object may not be modified if the associated + hostTopNStatus object is equal to valid(1)." + ::= { hostTopNControlEntry 3 } + +hostTopNTimeRemaining OBJECT-TYPE + SYNTAX Integer32 + UNITS "Seconds" + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The number of seconds left in the report currently being + collected. When this object is modified by the management + station, a new collection is started, possibly aborting + a currently running report. The new value is used + as the requested duration of this report, which is + loaded into the associated hostTopNDuration object. + + When this object is set to a non-zero value, any + associated hostTopNEntries shall be made + inaccessible by the monitor. While the value of this + object is non-zero, it decrements by one per second until + it reaches zero. During this time, all associated + hostTopNEntries shall remain inaccessible. At the time + that this object decrements to zero, the report is made + accessible in the hostTopNTable. Thus, the hostTopN + table needs to be created only at the end of the collection + interval." + DEFVAL { 0 } + ::= { hostTopNControlEntry 4 } + +hostTopNDuration OBJECT-TYPE + SYNTAX Integer32 + UNITS "Seconds" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of seconds that this report has collected + during the last sampling interval, or if this + report is currently being collected, the number + of seconds that this report is being collected + during this sampling interval. + + When the associated hostTopNTimeRemaining object is set, + this object shall be set by the probe to the same value + and shall not be modified until the next time + the hostTopNTimeRemaining is set. + + This value shall be zero if no reports have been + requested for this hostTopNControlEntry." + DEFVAL { 0 } + ::= { hostTopNControlEntry 5 } + +hostTopNRequestedSize OBJECT-TYPE + SYNTAX Integer32 + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The maximum number of hosts requested for the top N + table. + + When this object is created or modified, the probe + should set hostTopNGrantedSize as closely to this + object as is possible for the particular probe + implementation and available resources." + DEFVAL { 10 } + ::= { hostTopNControlEntry 6 } + +hostTopNGrantedSize OBJECT-TYPE + SYNTAX Integer32 + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The maximum number of hosts in the top N table. + + When the associated hostTopNRequestedSize object is + created or modified, the probe should set this + object as closely to the requested value as is possible + for the particular implementation and available + resources. The probe must not lower this value except + as a result of a set to the associated + hostTopNRequestedSize object. + + Hosts with the highest value of hostTopNRate shall be + placed in this table in decreasing order of this rate + until there is no more room or until there are no more + hosts." + ::= { hostTopNControlEntry 7 } + +hostTopNStartTime OBJECT-TYPE + SYNTAX TimeTicks + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The value of sysUpTime when this top N report was + last started. In other words, this is the time that + the associated hostTopNTimeRemaining object was + modified to start the requested report." + ::= { hostTopNControlEntry 8 } + +hostTopNOwner OBJECT-TYPE + SYNTAX OwnerString + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The entity that configured this entry and is therefore + using the resources assigned to it." + ::= { hostTopNControlEntry 9 } + +hostTopNStatus OBJECT-TYPE + SYNTAX EntryStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The status of this hostTopNControl entry. + + If this object is not equal to valid(1), all associated + hostTopNEntries shall be deleted by the agent." + ::= { hostTopNControlEntry 10 } + +hostTopNTable OBJECT-TYPE + SYNTAX SEQUENCE OF HostTopNEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A list of top N host entries." + ::= { hostTopN 2 } + +hostTopNEntry OBJECT-TYPE + SYNTAX HostTopNEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A set of statistics for a host that is part of a top N + report. For example, an instance of the hostTopNRate + object might be named hostTopNRate.3.10" + INDEX { hostTopNReport, hostTopNIndex } + ::= { hostTopNTable 1 } + +HostTopNEntry ::= SEQUENCE { + hostTopNReport Integer32, + hostTopNIndex Integer32, + hostTopNAddress OCTET STRING, + hostTopNRate Integer32 +} + +hostTopNReport OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "This object identifies the top N report of which + this entry is a part. The set of hosts + identified by a particular value of this + object is part of the same report as identified + by the same value of the hostTopNControlIndex object." + ::= { hostTopNEntry 1 } + +hostTopNIndex OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "An index that uniquely identifies an entry in + the hostTopN table among those in the same report. + This index is between 1 and N, where N is the + number of entries in this table. Increasing values + of hostTopNIndex shall be assigned to entries with + decreasing values of hostTopNRate until index N + is assigned to the entry with the lowest value of + hostTopNRate or there are no more hostTopNEntries." + ::= { hostTopNEntry 2 } + +hostTopNAddress OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The physical address of this host." + ::= { hostTopNEntry 3 } + +hostTopNRate OBJECT-TYPE + SYNTAX Integer32 + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The amount of change in the selected variable + during this sampling interval. The selected + variable is this host's instance of the object + selected by hostTopNRateBase." + ::= { hostTopNEntry 4 } + +-- The Matrix Group + +-- Implementation of the Matrix group is optional. +-- Consult the MODULE-COMPLIANCE macro for the authoritative +-- conformance information for this MIB. +-- +-- The Matrix group consists of the matrixControlTable, matrixSDTable +-- and the matrixDSTable. These tables store statistics for a +-- particular conversation between two addresses. As the device +-- detects a new conversation, including those to a non-unicast +-- address, it creates a new entry in both of the matrix tables. +-- It must only create new entries based on information +-- received in good packets. If the monitoring device finds +-- itself short of resources, it may delete entries as needed. +-- It is suggested that the device delete the least recently used +-- entries first. + +matrixControlTable OBJECT-TYPE + SYNTAX SEQUENCE OF MatrixControlEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A list of information entries for the + traffic matrix on each interface." + ::= { matrix 1 } + +matrixControlEntry OBJECT-TYPE + SYNTAX MatrixControlEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Information about a traffic matrix on a particular + interface. For example, an instance of the + matrixControlLastDeleteTime object might be named + matrixControlLastDeleteTime.1" + INDEX { matrixControlIndex } + ::= { matrixControlTable 1 } + +MatrixControlEntry ::= SEQUENCE { + matrixControlIndex Integer32, + matrixControlDataSource OBJECT IDENTIFIER, + matrixControlTableSize Integer32, + matrixControlLastDeleteTime TimeTicks, + matrixControlOwner OwnerString, + matrixControlStatus EntryStatus +} + +matrixControlIndex OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "An index that uniquely identifies an entry in the + matrixControl table. Each such entry defines + a function that discovers conversations on a particular + interface and places statistics about them in the + matrixSDTable and the matrixDSTable on behalf of this + matrixControlEntry." + ::= { matrixControlEntry 1 } + +matrixControlDataSource OBJECT-TYPE + SYNTAX OBJECT IDENTIFIER + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object identifies the source of + the data from which this entry creates a traffic matrix. + This source can be any interface on this device. In + order to identify a particular interface, this object + shall identify the instance of the ifIndex object, + defined in RFC 2233 [17], for the desired + interface. For example, if an entry were to receive data + from interface #1, this object would be set to ifIndex.1. + + The statistics in this group reflect all packets + on the local network segment attached to the identified + interface. + + An agent may or may not be able to tell if fundamental + changes to the media of the interface have occurred and + necessitate an invalidation of this entry. For example, a + hot-pluggable ethernet card could be pulled out and replaced + by a token-ring card. In such a case, if the agent has such + knowledge of the change, it is recommended that it + invalidate this entry. + + This object may not be modified if the associated + matrixControlStatus object is equal to valid(1)." + ::= { matrixControlEntry 2 } + +matrixControlTableSize OBJECT-TYPE + SYNTAX Integer32 + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of matrixSDEntries in the matrixSDTable + for this interface. This must also be the value of + the number of entries in the matrixDSTable for this + interface." + ::= { matrixControlEntry 3 } + +matrixControlLastDeleteTime OBJECT-TYPE + SYNTAX TimeTicks + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The value of sysUpTime when the last entry + was deleted from the portion of the matrixSDTable + or matrixDSTable associated with this matrixControlEntry. + If no deletions have occurred, this value shall be + zero." + ::= { matrixControlEntry 4 } + +matrixControlOwner OBJECT-TYPE + SYNTAX OwnerString + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The entity that configured this entry and is therefore + using the resources assigned to it." + ::= { matrixControlEntry 5 } + +matrixControlStatus OBJECT-TYPE + SYNTAX EntryStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The status of this matrixControl entry. + If this object is not equal to valid(1), all associated + entries in the matrixSDTable and the matrixDSTable + shall be deleted by the agent." + ::= { matrixControlEntry 6 } + +matrixSDTable OBJECT-TYPE + SYNTAX SEQUENCE OF MatrixSDEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A list of traffic matrix entries indexed by + source and destination MAC address." + ::= { matrix 2 } + +matrixSDEntry OBJECT-TYPE + SYNTAX MatrixSDEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A collection of statistics for communications between + two addresses on a particular interface. For example, + an instance of the matrixSDPkts object might be named + matrixSDPkts.1.6.8.0.32.27.3.176.6.8.0.32.10.8.113" + INDEX { matrixSDIndex, + matrixSDSourceAddress, matrixSDDestAddress } + ::= { matrixSDTable 1 } + +MatrixSDEntry ::= SEQUENCE { + matrixSDSourceAddress OCTET STRING, + matrixSDDestAddress OCTET STRING, + matrixSDIndex Integer32, + matrixSDPkts Counter32, + matrixSDOctets Counter32, + matrixSDErrors Counter32 +} + +matrixSDSourceAddress OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The source physical address." + ::= { matrixSDEntry 1 } + +matrixSDDestAddress OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The destination physical address." + ::= { matrixSDEntry 2 } + +matrixSDIndex OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The set of collected matrix statistics of which + this entry is a part. The set of matrix statistics + identified by a particular value of this index + is associated with the same matrixControlEntry + as identified by the same value of matrixControlIndex." + ::= { matrixSDEntry 3 } + +matrixSDPkts OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of packets transmitted from the source + address to the destination address (this number includes + bad packets)." + ::= { matrixSDEntry 4 } + +matrixSDOctets OBJECT-TYPE + SYNTAX Counter32 + UNITS "Octets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of octets (excluding framing bits but + including FCS octets) contained in all packets + transmitted from the source address to the + destination address." + ::= { matrixSDEntry 5 } + +matrixSDErrors OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of bad packets transmitted from + the source address to the destination address." + ::= { matrixSDEntry 6 } + +-- Traffic matrix tables from destination to source + +matrixDSTable OBJECT-TYPE + SYNTAX SEQUENCE OF MatrixDSEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A list of traffic matrix entries indexed by + destination and source MAC address." + ::= { matrix 3 } + +matrixDSEntry OBJECT-TYPE + SYNTAX MatrixDSEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A collection of statistics for communications between + two addresses on a particular interface. For example, + an instance of the matrixSDPkts object might be named + matrixSDPkts.1.6.8.0.32.10.8.113.6.8.0.32.27.3.176" + INDEX { matrixDSIndex, + matrixDSDestAddress, matrixDSSourceAddress } + ::= { matrixDSTable 1 } + +MatrixDSEntry ::= SEQUENCE { + matrixDSSourceAddress OCTET STRING, + matrixDSDestAddress OCTET STRING, + matrixDSIndex Integer32, + matrixDSPkts Counter32, + matrixDSOctets Counter32, + matrixDSErrors Counter32 +} + +matrixDSSourceAddress OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The source physical address." + ::= { matrixDSEntry 1 } + +matrixDSDestAddress OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The destination physical address." + ::= { matrixDSEntry 2 } + +matrixDSIndex OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The set of collected matrix statistics of which + this entry is a part. The set of matrix statistics + identified by a particular value of this index + is associated with the same matrixControlEntry + as identified by the same value of matrixControlIndex." + ::= { matrixDSEntry 3 } + +matrixDSPkts OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of packets transmitted from the source + address to the destination address (this number includes + bad packets)." + ::= { matrixDSEntry 4 } + +matrixDSOctets OBJECT-TYPE + SYNTAX Counter32 + UNITS "Octets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of octets (excluding framing bits + but including FCS octets) contained in all packets + transmitted from the source address to the + destination address." + ::= { matrixDSEntry 5 } + +matrixDSErrors OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of bad packets transmitted from + the source address to the destination address." + ::= { matrixDSEntry 6 } + +-- The Filter Group + +-- Implementation of the Filter group is optional. +-- Consult the MODULE-COMPLIANCE macro for the authoritative +-- conformance information for this MIB. +-- +-- The Filter group allows packets to be captured with an +-- arbitrary filter expression. A logical data and +-- event stream or "channel" is formed by the packets +-- that match the filter expression. +-- +-- This filter mechanism allows the creation of an arbitrary +-- logical expression with which to filter packets. Each +-- filter associated with a channel is OR'ed with the others. +-- Within a filter, any bits checked in the data and status are +-- AND'ed with respect to other bits in the same filter. The +-- NotMask also allows for checking for inequality. Finally, +-- the channelAcceptType object allows for inversion of the +-- whole equation. +-- +-- If a management station wishes to receive a trap to alert it +-- that new packets have been captured and are available for +-- download, it is recommended that it set up an alarm entry that +-- monitors the value of the relevant channelMatches instance. +-- +-- The channel can be turned on or off, and can also +-- generate events when packets pass through it. + +filterTable OBJECT-TYPE + SYNTAX SEQUENCE OF FilterEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A list of packet filter entries." + ::= { filter 1 } + +filterEntry OBJECT-TYPE + SYNTAX FilterEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A set of parameters for a packet filter applied on a + particular interface. As an example, an instance of the + filterPktData object might be named filterPktData.12" + INDEX { filterIndex } + ::= { filterTable 1 } + +FilterEntry ::= SEQUENCE { + filterIndex Integer32, + filterChannelIndex Integer32, + filterPktDataOffset Integer32, + filterPktData OCTET STRING, + filterPktDataMask OCTET STRING, + filterPktDataNotMask OCTET STRING, + filterPktStatus Integer32, + filterPktStatusMask Integer32, + filterPktStatusNotMask Integer32, + filterOwner OwnerString, + filterStatus EntryStatus +} + +filterIndex OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "An index that uniquely identifies an entry + in the filter table. Each such entry defines + one filter that is to be applied to every packet + received on an interface." + ::= { filterEntry 1 } + +filterChannelIndex OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object identifies the channel of which this filter + is a part. The filters identified by a particular value + of this object are associated with the same channel as + identified by the same value of the channelIndex object." + ::= { filterEntry 2 } + +filterPktDataOffset OBJECT-TYPE + SYNTAX Integer32 + UNITS "Octets" + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The offset from the beginning of each packet where + a match of packet data will be attempted. This offset + is measured from the point in the physical layer + packet after the framing bits, if any. For example, + in an Ethernet frame, this point is at the beginning of + the destination MAC address. + + This object may not be modified if the associated + filterStatus object is equal to valid(1)." + DEFVAL { 0 } + + ::= { filterEntry 3 } + +filterPktData OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The data that is to be matched with the input packet. + For each packet received, this filter and the accompanying + filterPktDataMask and filterPktDataNotMask will be + adjusted for the offset. The only bits relevant to this + match algorithm are those that have the corresponding + filterPktDataMask bit equal to one. The following three + rules are then applied to every packet: + + (1) If the packet is too short and does not have data + corresponding to part of the filterPktData, the packet + will fail this data match. + + (2) For each relevant bit from the packet with the + corresponding filterPktDataNotMask bit set to zero, if + the bit from the packet is not equal to the corresponding + bit from the filterPktData, then the packet will fail + this data match. + + (3) If for every relevant bit from the packet with the + corresponding filterPktDataNotMask bit set to one, the + bit from the packet is equal to the corresponding bit + from the filterPktData, then the packet will fail this + data match. + + Any packets that have not failed any of the three matches + above have passed this data match. In particular, a zero + length filter will match any packet. + + This object may not be modified if the associated + filterStatus object is equal to valid(1)." + ::= { filterEntry 4 } + +filterPktDataMask OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The mask that is applied to the match process. + After adjusting this mask for the offset, only those + bits in the received packet that correspond to bits set + in this mask are relevant for further processing by the + match algorithm. The offset is applied to filterPktDataMask + in the same way it is applied to the filter. For the + purposes of the matching algorithm, if the associated + filterPktData object is longer than this mask, this mask is + conceptually extended with '1' bits until it reaches the + length of the filterPktData object. + + This object may not be modified if the associated + filterStatus object is equal to valid(1)." + ::= { filterEntry 5 } + +filterPktDataNotMask OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The inversion mask that is applied to the match + process. After adjusting this mask for the offset, + those relevant bits in the received packet that correspond + to bits cleared in this mask must all be equal to their + corresponding bits in the filterPktData object for the packet + to be accepted. In addition, at least one of those relevant + bits in the received packet that correspond to bits set in + this mask must be different to its corresponding bit in the + filterPktData object. + + For the purposes of the matching algorithm, if the associated + filterPktData object is longer than this mask, this mask is + conceptually extended with '0' bits until it reaches the + length of the filterPktData object. + + This object may not be modified if the associated + filterStatus object is equal to valid(1)." + ::= { filterEntry 6 } + +filterPktStatus OBJECT-TYPE + SYNTAX Integer32 + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The status that is to be matched with the input packet. + The only bits relevant to this match algorithm are those that + have the corresponding filterPktStatusMask bit equal to one. + The following two rules are then applied to every packet: + + (1) For each relevant bit from the packet status with the + corresponding filterPktStatusNotMask bit set to zero, if + the bit from the packet status is not equal to the + corresponding bit from the filterPktStatus, then the + packet will fail this status match. + + (2) If for every relevant bit from the packet status with the + corresponding filterPktStatusNotMask bit set to one, the + bit from the packet status is equal to the corresponding + bit from the filterPktStatus, then the packet will fail + this status match. + + Any packets that have not failed either of the two matches + above have passed this status match. In particular, a zero + length status filter will match any packet's status. + + The value of the packet status is a sum. This sum + initially takes the value zero. Then, for each + error, E, that has been discovered in this packet, + 2 raised to a value representing E is added to the sum. + The errors and the bits that represent them are dependent + on the media type of the interface that this channel + is receiving packets from. + + The errors defined for a packet captured off of an + Ethernet interface are as follows: + + bit # Error + 0 Packet is longer than 1518 octets + 1 Packet is shorter than 64 octets + 2 Packet experienced a CRC or Alignment error + + For example, an Ethernet fragment would have a + value of 6 (2^1 + 2^2). + + As this MIB is expanded to new media types, this object + will have other media-specific errors defined. + + For the purposes of this status matching algorithm, if the + packet status is longer than this filterPktStatus object, + this object is conceptually extended with '0' bits until it + reaches the size of the packet status. + + This object may not be modified if the associated + filterStatus object is equal to valid(1)." + ::= { filterEntry 7 } + +filterPktStatusMask OBJECT-TYPE + SYNTAX Integer32 + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The mask that is applied to the status match process. + Only those bits in the received packet that correspond to + bits set in this mask are relevant for further processing + by the status match algorithm. For the purposes + of the matching algorithm, if the associated filterPktStatus + object is longer than this mask, this mask is conceptually + extended with '1' bits until it reaches the size of the + filterPktStatus. In addition, if a packet status is longer + than this mask, this mask is conceptually extended with '0' + bits until it reaches the size of the packet status. + + This object may not be modified if the associated + filterStatus object is equal to valid(1)." + ::= { filterEntry 8 } + +filterPktStatusNotMask OBJECT-TYPE + SYNTAX Integer32 + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The inversion mask that is applied to the status match + process. Those relevant bits in the received packet status + that correspond to bits cleared in this mask must all be + equal to their corresponding bits in the filterPktStatus + object for the packet to be accepted. In addition, at least + one of those relevant bits in the received packet status + that correspond to bits set in this mask must be different + to its corresponding bit in the filterPktStatus object for + the packet to be accepted. + + For the purposes of the matching algorithm, if the associated + filterPktStatus object or a packet status is longer than this + mask, this mask is conceptually extended with '0' bits until + it reaches the longer of the lengths of the filterPktStatus + object and the packet status. + + This object may not be modified if the associated + filterStatus object is equal to valid(1)." + ::= { filterEntry 9 } + +filterOwner OBJECT-TYPE + SYNTAX OwnerString + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The entity that configured this entry and is therefore + using the resources assigned to it." + ::= { filterEntry 10 } + +filterStatus OBJECT-TYPE + SYNTAX EntryStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The status of this filter entry." + ::= { filterEntry 11 } + +channelTable OBJECT-TYPE + SYNTAX SEQUENCE OF ChannelEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A list of packet channel entries." + ::= { filter 2 } + +channelEntry OBJECT-TYPE + SYNTAX ChannelEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A set of parameters for a packet channel applied on a + particular interface. As an example, an instance of the + channelMatches object might be named channelMatches.3" + INDEX { channelIndex } + ::= { channelTable 1 } + +ChannelEntry ::= SEQUENCE { + channelIndex Integer32, + channelIfIndex Integer32, + channelAcceptType INTEGER, + channelDataControl INTEGER, + channelTurnOnEventIndex Integer32, + channelTurnOffEventIndex Integer32, + channelEventIndex Integer32, + channelEventStatus INTEGER, + channelMatches Counter32, + channelDescription DisplayString, + channelOwner OwnerString, + channelStatus EntryStatus +} + +channelIndex OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "An index that uniquely identifies an entry in the channel + table. Each such entry defines one channel, a logical + data and event stream. + + It is suggested that before creating a channel, an + application should scan all instances of the + filterChannelIndex object to make sure that there are no + pre-existing filters that would be inadvertently be linked + to the channel." + ::= { channelEntry 1 } + +channelIfIndex OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of this object uniquely identifies the + interface on this remote network monitoring device to which + the associated filters are applied to allow data into this + channel. The interface identified by a particular value + of this object is the same interface as identified by the + same value of the ifIndex object, defined in RFC 2233 [17]. + + The filters in this group are applied to all packets on + the local network segment attached to the identified + interface. + + An agent may or may not be able to tell if fundamental + changes to the media of the interface have occurred and + necessitate an invalidation of this entry. For example, a + hot-pluggable ethernet card could be pulled out and replaced + by a token-ring card. In such a case, if the agent has such + knowledge of the change, it is recommended that it + invalidate this entry. + + This object may not be modified if the associated + channelStatus object is equal to valid(1)." + ::= { channelEntry 2 } + +channelAcceptType OBJECT-TYPE + SYNTAX INTEGER { + acceptMatched(1), + acceptFailed(2) + } + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object controls the action of the filters + associated with this channel. If this object is equal + to acceptMatched(1), packets will be accepted to this + channel if they are accepted by both the packet data and + packet status matches of an associated filter. If + this object is equal to acceptFailed(2), packets will + be accepted to this channel only if they fail either + the packet data match or the packet status match of + each of the associated filters. + + In particular, a channel with no associated filters will + match no packets if set to acceptMatched(1) case and will + match all packets in the acceptFailed(2) case. + + This object may not be modified if the associated + channelStatus object is equal to valid(1)." + ::= { channelEntry 3 } + +channelDataControl OBJECT-TYPE + SYNTAX INTEGER { + on(1), + off(2) + } + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object controls the flow of data through this channel. + If this object is on(1), data, status and events flow + through this channel. If this object is off(2), data, + status and events will not flow through this channel." + DEFVAL { off } + ::= { channelEntry 4 } + +channelTurnOnEventIndex OBJECT-TYPE + SYNTAX Integer32 (0..65535) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of this object identifies the event + that is configured to turn the associated + channelDataControl from off to on when the event is + generated. The event identified by a particular value + of this object is the same event as identified by the + same value of the eventIndex object. If there is no + corresponding entry in the eventTable, then no + association exists. In fact, if no event is intended + for this channel, channelTurnOnEventIndex must be + set to zero, a non-existent event index. + + This object may not be modified if the associated + channelStatus object is equal to valid(1)." + ::= { channelEntry 5 } + +channelTurnOffEventIndex OBJECT-TYPE + SYNTAX Integer32 (0..65535) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of this object identifies the event + that is configured to turn the associated + channelDataControl from on to off when the event is + generated. The event identified by a particular value + of this object is the same event as identified by the + same value of the eventIndex object. If there is no + corresponding entry in the eventTable, then no + association exists. In fact, if no event is intended + for this channel, channelTurnOffEventIndex must be + set to zero, a non-existent event index. + + This object may not be modified if the associated + channelStatus object is equal to valid(1)." + ::= { channelEntry 6 } + +channelEventIndex OBJECT-TYPE + SYNTAX Integer32 (0..65535) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of this object identifies the event + that is configured to be generated when the + associated channelDataControl is on and a packet + is matched. The event identified by a particular value + of this object is the same event as identified by the + same value of the eventIndex object. If there is no + corresponding entry in the eventTable, then no + association exists. In fact, if no event is intended + for this channel, channelEventIndex must be + set to zero, a non-existent event index. + + This object may not be modified if the associated + channelStatus object is equal to valid(1)." + ::= { channelEntry 7 } + +channelEventStatus OBJECT-TYPE + SYNTAX INTEGER { + eventReady(1), + eventFired(2), + eventAlwaysReady(3) + } + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The event status of this channel. + + If this channel is configured to generate events + when packets are matched, a means of controlling + the flow of those events is often needed. When + this object is equal to eventReady(1), a single + event may be generated, after which this object + will be set by the probe to eventFired(2). While + in the eventFired(2) state, no events will be + generated until the object is modified to + eventReady(1) (or eventAlwaysReady(3)). The + management station can thus easily respond to a + notification of an event by re-enabling this object. + + If the management station wishes to disable this + flow control and allow events to be generated + at will, this object may be set to + eventAlwaysReady(3). Disabling the flow control + is discouraged as it can result in high network + traffic or other performance problems." + DEFVAL { eventReady } + ::= { channelEntry 8 } + +channelMatches OBJECT-TYPE + SYNTAX Counter32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of times this channel has matched a packet. + Note that this object is updated even when + channelDataControl is set to off." + ::= { channelEntry 9 } + +channelDescription OBJECT-TYPE + SYNTAX DisplayString (SIZE (0..127)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "A comment describing this channel." + ::= { channelEntry 10 } + +channelOwner OBJECT-TYPE + SYNTAX OwnerString + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The entity that configured this entry and is therefore + using the resources assigned to it." + ::= { channelEntry 11 } + +channelStatus OBJECT-TYPE + SYNTAX EntryStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The status of this channel entry." + ::= { channelEntry 12 } + +-- The Packet Capture Group + +-- Implementation of the Packet Capture group is optional. The Packet +-- Capture Group requires implementation of the Filter Group. +-- Consult the MODULE-COMPLIANCE macro for the authoritative +-- conformance information for this MIB. +-- +-- The Packet Capture group allows packets to be captured +-- upon a filter match. The bufferControlTable controls +-- the captured packets output from a channel that is +-- associated with it. The captured packets are placed +-- in entries in the captureBufferTable. These entries are +-- associated with the bufferControlEntry on whose behalf they +-- were stored. + +bufferControlTable OBJECT-TYPE + SYNTAX SEQUENCE OF BufferControlEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A list of buffers control entries." + ::= { capture 1 } + +bufferControlEntry OBJECT-TYPE + SYNTAX BufferControlEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A set of parameters that control the collection of a stream + of packets that have matched filters. As an example, an + instance of the bufferControlCaptureSliceSize object might + be named bufferControlCaptureSliceSize.3" + + INDEX { bufferControlIndex } + ::= { bufferControlTable 1 } + +BufferControlEntry ::= SEQUENCE { + bufferControlIndex Integer32, + bufferControlChannelIndex Integer32, + bufferControlFullStatus INTEGER, + bufferControlFullAction INTEGER, + bufferControlCaptureSliceSize Integer32, + bufferControlDownloadSliceSize Integer32, + bufferControlDownloadOffset Integer32, + bufferControlMaxOctetsRequested Integer32, + bufferControlMaxOctetsGranted Integer32, + bufferControlCapturedPackets Integer32, + bufferControlTurnOnTime TimeTicks, + bufferControlOwner OwnerString, + bufferControlStatus EntryStatus +} + +bufferControlIndex OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "An index that uniquely identifies an entry + in the bufferControl table. The value of this + index shall never be zero. Each such + entry defines one set of packets that is + captured and controlled by one or more filters." + ::= { bufferControlEntry 1 } + +bufferControlChannelIndex OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "An index that identifies the channel that is the + source of packets for this bufferControl table. + The channel identified by a particular value of this + index is the same as identified by the same value of + the channelIndex object. + + This object may not be modified if the associated + bufferControlStatus object is equal to valid(1)." + ::= { bufferControlEntry 2 } + +bufferControlFullStatus OBJECT-TYPE + SYNTAX INTEGER { + spaceAvailable(1), + full(2) + } + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "This object shows whether the buffer has room to + accept new packets or if it is full. + + If the status is spaceAvailable(1), the buffer is + accepting new packets normally. If the status is + full(2) and the associated bufferControlFullAction + object is wrapWhenFull, the buffer is accepting new + packets by deleting enough of the oldest packets + to make room for new ones as they arrive. Otherwise, + if the status is full(2) and the + bufferControlFullAction object is lockWhenFull, + then the buffer has stopped collecting packets. + + When this object is set to full(2) the probe must + not later set it to spaceAvailable(1) except in the + case of a significant gain in resources such as + an increase of bufferControlOctetsGranted. In + particular, the wrap-mode action of deleting old + packets to make room for newly arrived packets + must not affect the value of this object." + ::= { bufferControlEntry 3 } + +bufferControlFullAction OBJECT-TYPE + SYNTAX INTEGER { + lockWhenFull(1), + wrapWhenFull(2) -- FIFO + } + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "Controls the action of the buffer when it + reaches the full status. When in the lockWhenFull(1) + state and a packet is added to the buffer that + fills the buffer, the bufferControlFullStatus will + be set to full(2) and this buffer will stop capturing + packets." + ::= { bufferControlEntry 4 } + +bufferControlCaptureSliceSize OBJECT-TYPE + SYNTAX Integer32 + UNITS "Octets" + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The maximum number of octets of each packet + that will be saved in this capture buffer. + For example, if a 1500 octet packet is received by + the probe and this object is set to 500, then only + 500 octets of the packet will be stored in the + associated capture buffer. If this variable is set + to 0, the capture buffer will save as many octets + as is possible. + + This object may not be modified if the associated + bufferControlStatus object is equal to valid(1)." + DEFVAL { 100 } + ::= { bufferControlEntry 5 } + +bufferControlDownloadSliceSize OBJECT-TYPE + SYNTAX Integer32 + UNITS "Octets" + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The maximum number of octets of each packet + in this capture buffer that will be returned in + an SNMP retrieval of that packet. For example, + if 500 octets of a packet have been stored in the + associated capture buffer, the associated + bufferControlDownloadOffset is 0, and this + object is set to 100, then the captureBufferPacket + object that contains the packet will contain only + the first 100 octets of the packet. + + A prudent manager will take into account possible + interoperability or fragmentation problems that may + occur if the download slice size is set too large. + In particular, conformant SNMP implementations are not + required to accept messages whose length exceeds 484 + octets, although they are encouraged to support larger + datagrams whenever feasible." + DEFVAL { 100 } + ::= { bufferControlEntry 6 } + +bufferControlDownloadOffset OBJECT-TYPE + SYNTAX Integer32 + UNITS "Octets" + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The offset of the first octet of each packet + in this capture buffer that will be returned in + an SNMP retrieval of that packet. For example, + if 500 octets of a packet have been stored in the + associated capture buffer and this object is set to + 100, then the captureBufferPacket object that + contains the packet will contain bytes starting + 100 octets into the packet." + DEFVAL { 0 } + ::= { bufferControlEntry 7 } + +bufferControlMaxOctetsRequested OBJECT-TYPE + SYNTAX Integer32 + UNITS "Octets" + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The requested maximum number of octets to be + saved in this captureBuffer, including any + implementation-specific overhead. If this variable + is set to -1, the capture buffer will save as many + octets as is possible. + + When this object is created or modified, the probe + should set bufferControlMaxOctetsGranted as closely + to this object as is possible for the particular probe + implementation and available resources. However, if + the object has the special value of -1, the probe + must set bufferControlMaxOctetsGranted to -1." + DEFVAL { -1 } + ::= { bufferControlEntry 8 } + +bufferControlMaxOctetsGranted OBJECT-TYPE + SYNTAX Integer32 + UNITS "Octets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The maximum number of octets that can be + saved in this captureBuffer, including overhead. + If this variable is -1, the capture buffer will save + as many octets as possible. + + When the bufferControlMaxOctetsRequested object is + created or modified, the probe should set this object + as closely to the requested value as is possible for the + particular probe implementation and available resources. + However, if the request object has the special value + of -1, the probe must set this object to -1. + + The probe must not lower this value except as a result of + a modification to the associated + bufferControlMaxOctetsRequested object. + + When this maximum number of octets is reached + and a new packet is to be added to this + capture buffer and the corresponding + bufferControlFullAction is set to wrapWhenFull(2), + enough of the oldest packets associated with this + capture buffer shall be deleted by the agent so + that the new packet can be added. If the corresponding + bufferControlFullAction is set to lockWhenFull(1), + the new packet shall be discarded. In either case, + the probe must set bufferControlFullStatus to + full(2). + + When the value of this object changes to a value less + than the current value, entries are deleted from + the captureBufferTable associated with this + bufferControlEntry. Enough of the + oldest of these captureBufferEntries shall be + deleted by the agent so that the number of octets + used remains less than or equal to the new value of + this object. + + When the value of this object changes to a value greater + than the current value, the number of associated + captureBufferEntries may be allowed to grow." + ::= { bufferControlEntry 9 } + +bufferControlCapturedPackets OBJECT-TYPE + SYNTAX Integer32 + UNITS "Packets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of packets currently in this captureBuffer." + ::= { bufferControlEntry 10 } + +bufferControlTurnOnTime OBJECT-TYPE + SYNTAX TimeTicks + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The value of sysUpTime when this capture buffer was + first turned on." + ::= { bufferControlEntry 11 } + +bufferControlOwner OBJECT-TYPE + SYNTAX OwnerString + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The entity that configured this entry and is therefore + using the resources assigned to it." + ::= { bufferControlEntry 12 } + +bufferControlStatus OBJECT-TYPE + SYNTAX EntryStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The status of this buffer Control Entry." + ::= { bufferControlEntry 13 } + +captureBufferTable OBJECT-TYPE + SYNTAX SEQUENCE OF CaptureBufferEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A list of packets captured off of a channel." + ::= { capture 2 } + +captureBufferEntry OBJECT-TYPE + SYNTAX CaptureBufferEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A packet captured off of an attached network. As an + example, an instance of the captureBufferPacketData + object might be named captureBufferPacketData.3.1783" + INDEX { captureBufferControlIndex, captureBufferIndex } + ::= { captureBufferTable 1 } + +CaptureBufferEntry ::= SEQUENCE { + captureBufferControlIndex Integer32, + captureBufferIndex Integer32, + captureBufferPacketID Integer32, + captureBufferPacketData OCTET STRING, + captureBufferPacketLength Integer32, + captureBufferPacketTime Integer32, + captureBufferPacketStatus Integer32 +} + +captureBufferControlIndex OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The index of the bufferControlEntry with which + this packet is associated." + ::= { captureBufferEntry 1 } + +captureBufferIndex OBJECT-TYPE + SYNTAX Integer32 (1..2147483647) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "An index that uniquely identifies an entry + in the captureBuffer table associated with a + particular bufferControlEntry. This index will + start at 1 and increase by one for each new packet + added with the same captureBufferControlIndex. + + Should this value reach 2147483647, the next packet + added with the same captureBufferControlIndex shall + cause this value to wrap around to 1." + ::= { captureBufferEntry 2 } + +captureBufferPacketID OBJECT-TYPE + SYNTAX Integer32 + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "An index that describes the order of packets + that are received on a particular interface. + The packetID of a packet captured on an + interface is defined to be greater than the + packetID's of all packets captured previously on + the same interface. As the captureBufferPacketID + object has a maximum positive value of 2^31 - 1, + any captureBufferPacketID object shall have the + value of the associated packet's packetID mod 2^31." + ::= { captureBufferEntry 3 } + +captureBufferPacketData OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The data inside the packet, starting at the beginning + of the packet plus any offset specified in the + associated bufferControlDownloadOffset, including any + link level headers. The length of the data in this object + is the minimum of the length of the captured packet minus + the offset, the length of the associated + bufferControlCaptureSliceSize minus the offset, and the + associated bufferControlDownloadSliceSize. If this minimum + is less than zero, this object shall have a length of zero." + ::= { captureBufferEntry 4 } + +captureBufferPacketLength OBJECT-TYPE + SYNTAX Integer32 + UNITS "Octets" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The actual length (off the wire) of the packet stored + in this entry, including FCS octets." + ::= { captureBufferEntry 5 } + +captureBufferPacketTime OBJECT-TYPE + SYNTAX Integer32 + UNITS "Milliseconds" + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The number of milliseconds that had passed since + this capture buffer was first turned on when this + packet was captured." + ::= { captureBufferEntry 6 } + +captureBufferPacketStatus OBJECT-TYPE + SYNTAX Integer32 + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "A value which indicates the error status of this packet. + + The value of this object is defined in the same way as + filterPktStatus. The value is a sum. This sum + initially takes the value zero. Then, for each + error, E, that has been discovered in this packet, + 2 raised to a value representing E is added to the sum. + + The errors defined for a packet captured off of an + Ethernet interface are as follows: + + bit # Error + 0 Packet is longer than 1518 octets + 1 Packet is shorter than 64 octets + 2 Packet experienced a CRC or Alignment error + 3 First packet in this capture buffer after + it was detected that some packets were + not processed correctly. + 4 Packet's order in buffer is only approximate + (May only be set for packets sent from + the probe) + + For example, an Ethernet fragment would have a + value of 6 (2^1 + 2^2). + + As this MIB is expanded to new media types, this object + will have other media-specific errors defined." + ::= { captureBufferEntry 7 } + +-- The Event Group + +-- Implementation of the Event group is optional. +-- Consult the MODULE-COMPLIANCE macro for the authoritative +-- conformance information for this MIB. +-- +-- The Event group controls the generation and notification +-- of events from this device. Each entry in the eventTable +-- describes the parameters of the event that can be triggered. +-- Each event entry is fired by an associated condition located +-- elsewhere in the MIB. An event entry may also be associated +-- with a function elsewhere in the MIB that will be executed +-- when the event is generated. For example, a channel may +-- be turned on or off by the firing of an event. +-- +-- Each eventEntry may optionally specify that a log entry +-- be created on its behalf whenever the event occurs. +-- Each entry may also specify that notification should +-- occur by way of SNMP trap messages. In this case, the +-- community for the trap message is given in the associated +-- eventCommunity object. The enterprise and specific trap +-- fields of the trap are determined by the condition that +-- triggered the event. Two traps are defined: risingAlarm and +-- fallingAlarm. If the eventTable is triggered by a condition +-- specified elsewhere, the enterprise and specific trap fields +-- must be specified for traps generated for that condition. + +eventTable OBJECT-TYPE + SYNTAX SEQUENCE OF EventEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A list of events to be generated." + ::= { event 1 } + +eventEntry OBJECT-TYPE + SYNTAX EventEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A set of parameters that describe an event to be generated + when certain conditions are met. As an example, an instance + of the eventLastTimeSent object might be named + eventLastTimeSent.6" + INDEX { eventIndex } + ::= { eventTable 1 } + +EventEntry ::= SEQUENCE { + eventIndex Integer32, + eventDescription DisplayString, + eventType INTEGER, + eventCommunity OCTET STRING, + eventLastTimeSent TimeTicks, + eventOwner OwnerString, + eventStatus EntryStatus +} + +eventIndex OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "An index that uniquely identifies an entry in the + event table. Each such entry defines one event that + is to be generated when the appropriate conditions + occur." + ::= { eventEntry 1 } + +eventDescription OBJECT-TYPE + SYNTAX DisplayString (SIZE (0..127)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "A comment describing this event entry." + ::= { eventEntry 2 } + +eventType OBJECT-TYPE + SYNTAX INTEGER { + none(1), + log(2), + snmptrap(3), -- send an SNMP trap + logandtrap(4) + } + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The type of notification that the probe will make + about this event. In the case of log, an entry is + made in the log table for each event. In the case of + snmp-trap, an SNMP trap is sent to one or more + management stations." + ::= { eventEntry 3 } + +eventCommunity OBJECT-TYPE + SYNTAX OCTET STRING (SIZE (0..127)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "If an SNMP trap is to be sent, it will be sent to + the SNMP community specified by this octet string." + ::= { eventEntry 4 } + +eventLastTimeSent OBJECT-TYPE + SYNTAX TimeTicks + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The value of sysUpTime at the time this event + entry last generated an event. If this entry has + not generated any events, this value will be + zero." + ::= { eventEntry 5 } + +eventOwner OBJECT-TYPE + SYNTAX OwnerString + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The entity that configured this entry and is therefore + using the resources assigned to it. + + If this object contains a string starting with 'monitor' + and has associated entries in the log table, all connected + management stations should retrieve those log entries, + as they may have significance to all management stations + connected to this device" + ::= { eventEntry 6 } + +eventStatus OBJECT-TYPE + SYNTAX EntryStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The status of this event entry. + + If this object is not equal to valid(1), all associated + log entries shall be deleted by the agent." + ::= { eventEntry 7 } + +-- +logTable OBJECT-TYPE + SYNTAX SEQUENCE OF LogEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A list of events that have been logged." + ::= { event 2 } + +logEntry OBJECT-TYPE + SYNTAX LogEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A set of data describing an event that has been + logged. For example, an instance of the logDescription + object might be named logDescription.6.47" + INDEX { logEventIndex, logIndex } + ::= { logTable 1 } + +LogEntry ::= SEQUENCE { + logEventIndex Integer32, + logIndex Integer32, + logTime TimeTicks, + logDescription DisplayString +} + +logEventIndex OBJECT-TYPE + SYNTAX Integer32 (1..65535) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The event entry that generated this log + entry. The log identified by a particular + value of this index is associated with the same + eventEntry as identified by the same value + of eventIndex." + ::= { logEntry 1 } + +logIndex OBJECT-TYPE + SYNTAX Integer32 (1..2147483647) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "An index that uniquely identifies an entry + in the log table amongst those generated by the + same eventEntries. These indexes are + assigned beginning with 1 and increase by one + with each new log entry. The association + between values of logIndex and logEntries + is fixed for the lifetime of each logEntry. + The agent may choose to delete the oldest + instances of logEntry as required because of + lack of memory. It is an implementation-specific + matter as to when this deletion may occur." + ::= { logEntry 2 } + +logTime OBJECT-TYPE + SYNTAX TimeTicks + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The value of sysUpTime when this log entry was created." + ::= { logEntry 3 } + +logDescription OBJECT-TYPE + SYNTAX DisplayString (SIZE (0..255)) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "An implementation dependent description of the + event that activated this log entry." + ::= { logEntry 4 } + +-- Remote Network Monitoring Traps + +rmonEventsV2 OBJECT-IDENTITY + STATUS current + DESCRIPTION "Definition point for RMON notifications." + ::= { rmon 0 } + +risingAlarm NOTIFICATION-TYPE + OBJECTS { alarmIndex, alarmVariable, alarmSampleType, + alarmValue, alarmRisingThreshold } + STATUS current + DESCRIPTION + "The SNMP trap that is generated when an alarm + entry crosses its rising threshold and generates + an event that is configured for sending SNMP + traps." + ::= { rmonEventsV2 1 } + +fallingAlarm NOTIFICATION-TYPE + OBJECTS { alarmIndex, alarmVariable, alarmSampleType, + alarmValue, alarmFallingThreshold } + STATUS current + DESCRIPTION + "The SNMP trap that is generated when an alarm + entry crosses its falling threshold and generates + an event that is configured for sending SNMP + traps." + ::= { rmonEventsV2 2 } + +-- Conformance information + +rmonCompliances OBJECT IDENTIFIER ::= { rmonConformance 9 } +rmonGroups OBJECT IDENTIFIER ::= { rmonConformance 10 } + +-- Compliance Statements +rmonCompliance MODULE-COMPLIANCE + STATUS current + DESCRIPTION + "The requirements for conformance to the RMON MIB. At least + one of the groups in this module must be implemented to + conform to the RMON MIB. Implementations of this MIB + must also implement the system group of MIB-II [16] and the + IF-MIB [17]." + MODULE -- this module + + GROUP rmonEtherStatsGroup + DESCRIPTION + "The RMON Ethernet Statistics Group is optional." + + GROUP rmonHistoryControlGroup + DESCRIPTION + "The RMON History Control Group is optional." + + GROUP rmonEthernetHistoryGroup + DESCRIPTION + "The RMON Ethernet History Group is optional." + + GROUP rmonAlarmGroup + DESCRIPTION + "The RMON Alarm Group is optional." + + GROUP rmonHostGroup + DESCRIPTION + "The RMON Host Group is mandatory when the + rmonHostTopNGroup is implemented." + + GROUP rmonHostTopNGroup + DESCRIPTION + "The RMON Host Top N Group is optional." + + GROUP rmonMatrixGroup + DESCRIPTION + "The RMON Matrix Group is optional." + + GROUP rmonFilterGroup + DESCRIPTION + "The RMON Filter Group is mandatory when the + rmonPacketCaptureGroup is implemented." + + GROUP rmonPacketCaptureGroup + DESCRIPTION + "The RMON Packet Capture Group is optional." + + GROUP rmonEventGroup + DESCRIPTION + "The RMON Event Group is mandatory when the + rmonAlarmGroup is implemented." + ::= { rmonCompliances 1 } + + rmonEtherStatsGroup OBJECT-GROUP + OBJECTS { + etherStatsIndex, etherStatsDataSource, + etherStatsDropEvents, etherStatsOctets, etherStatsPkts, + etherStatsBroadcastPkts, etherStatsMulticastPkts, + etherStatsCRCAlignErrors, etherStatsUndersizePkts, + etherStatsOversizePkts, etherStatsFragments, + etherStatsJabbers, etherStatsCollisions, + etherStatsPkts64Octets, etherStatsPkts65to127Octets, + etherStatsPkts128to255Octets, + etherStatsPkts256to511Octets, + etherStatsPkts512to1023Octets, + etherStatsPkts1024to1518Octets, + etherStatsOwner, etherStatsStatus + } + STATUS current + DESCRIPTION + "The RMON Ethernet Statistics Group." + ::= { rmonGroups 1 } + + rmonHistoryControlGroup OBJECT-GROUP + OBJECTS { + historyControlIndex, historyControlDataSource, + historyControlBucketsRequested, + historyControlBucketsGranted, historyControlInterval, + historyControlOwner, historyControlStatus + } + STATUS current + DESCRIPTION + "The RMON History Control Group." + ::= { rmonGroups 2 } + + rmonEthernetHistoryGroup OBJECT-GROUP + OBJECTS { + etherHistoryIndex, etherHistorySampleIndex, + etherHistoryIntervalStart, etherHistoryDropEvents, + etherHistoryOctets, etherHistoryPkts, + etherHistoryBroadcastPkts, etherHistoryMulticastPkts, + etherHistoryCRCAlignErrors, etherHistoryUndersizePkts, + etherHistoryOversizePkts, etherHistoryFragments, + etherHistoryJabbers, etherHistoryCollisions, + etherHistoryUtilization + } + STATUS current + DESCRIPTION + "The RMON Ethernet History Group." + ::= { rmonGroups 3 } + + rmonAlarmGroup OBJECT-GROUP + OBJECTS { + alarmIndex, alarmInterval, alarmVariable, + alarmSampleType, alarmValue, alarmStartupAlarm, + alarmRisingThreshold, alarmFallingThreshold, + alarmRisingEventIndex, alarmFallingEventIndex, + alarmOwner, alarmStatus + } + STATUS current + DESCRIPTION + "The RMON Alarm Group." + ::= { rmonGroups 4 } + + rmonHostGroup OBJECT-GROUP + OBJECTS { + hostControlIndex, hostControlDataSource, + hostControlTableSize, hostControlLastDeleteTime, + hostControlOwner, hostControlStatus, + hostAddress, hostCreationOrder, hostIndex, + hostInPkts, hostOutPkts, hostInOctets, + hostOutOctets, hostOutErrors, hostOutBroadcastPkts, + hostOutMulticastPkts, hostTimeAddress, + hostTimeCreationOrder, hostTimeIndex, + hostTimeInPkts, hostTimeOutPkts, hostTimeInOctets, + hostTimeOutOctets, hostTimeOutErrors, + hostTimeOutBroadcastPkts, hostTimeOutMulticastPkts + } + STATUS current + DESCRIPTION + "The RMON Host Group." + ::= { rmonGroups 5 } + + rmonHostTopNGroup OBJECT-GROUP + OBJECTS { + hostTopNControlIndex, hostTopNHostIndex, + hostTopNRateBase, hostTopNTimeRemaining, + hostTopNDuration, hostTopNRequestedSize, + hostTopNGrantedSize, hostTopNStartTime, + hostTopNOwner, hostTopNStatus, + hostTopNReport, hostTopNIndex, + hostTopNAddress, hostTopNRate + } + STATUS current + DESCRIPTION + "The RMON Host Top 'N' Group." + ::= { rmonGroups 6 } + + rmonMatrixGroup OBJECT-GROUP + OBJECTS { + matrixControlIndex, matrixControlDataSource, + matrixControlTableSize, matrixControlLastDeleteTime, + matrixControlOwner, matrixControlStatus, + matrixSDSourceAddress, matrixSDDestAddress, + matrixSDIndex, matrixSDPkts, + matrixSDOctets, matrixSDErrors, + matrixDSSourceAddress, matrixDSDestAddress, + matrixDSIndex, matrixDSPkts, + matrixDSOctets, matrixDSErrors + } + STATUS current + DESCRIPTION + "The RMON Matrix Group." + ::= { rmonGroups 7 } + + rmonFilterGroup OBJECT-GROUP + OBJECTS { + filterIndex, filterChannelIndex, filterPktDataOffset, + filterPktData, filterPktDataMask, + filterPktDataNotMask, filterPktStatus, + filterPktStatusMask, filterPktStatusNotMask, + filterOwner, filterStatus, + channelIndex, channelIfIndex, channelAcceptType, + channelDataControl, channelTurnOnEventIndex, + channelTurnOffEventIndex, channelEventIndex, + channelEventStatus, channelMatches, + channelDescription, channelOwner, channelStatus + } + STATUS current + DESCRIPTION + "The RMON Filter Group." + ::= { rmonGroups 8 } + + rmonPacketCaptureGroup OBJECT-GROUP + OBJECTS { + bufferControlIndex, bufferControlChannelIndex, + bufferControlFullStatus, bufferControlFullAction, + bufferControlCaptureSliceSize, + bufferControlDownloadSliceSize, + bufferControlDownloadOffset, + bufferControlMaxOctetsRequested, + bufferControlMaxOctetsGranted, + bufferControlCapturedPackets, + bufferControlTurnOnTime, + bufferControlOwner, bufferControlStatus, + captureBufferControlIndex, captureBufferIndex, + captureBufferPacketID, captureBufferPacketData, + captureBufferPacketLength, captureBufferPacketTime, + captureBufferPacketStatus + } + STATUS current + DESCRIPTION + "The RMON Packet Capture Group." + ::= { rmonGroups 9 } + + rmonEventGroup OBJECT-GROUP + OBJECTS { + eventIndex, eventDescription, eventType, + eventCommunity, eventLastTimeSent, + eventOwner, eventStatus, + logEventIndex, logIndex, logTime, + logDescription + } + STATUS current + DESCRIPTION + "The RMON Event Group." + ::= { rmonGroups 10 } + + rmonNotificationGroup NOTIFICATION-GROUP + NOTIFICATIONS { risingAlarm, fallingAlarm } + STATUS current + DESCRIPTION + "The RMON Notification Group." + ::= { rmonGroups 11 } +END -- cgit v1.2.3 From 393637b3e917338060658e7d1ea66c5829112c6f Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 9 Mar 2012 17:39:41 +0100 Subject: [snmp/compiler] More information with augmented tables The information the MIB compiler provides with augmented tables has been extended with nbr_of_cols, first_accessible and not_accessible. OTP-9969 --- lib/snmp/include/snmp_types.hrl | 25 +++++-- lib/snmp/src/compile/snmpc_lib.erl | 36 ++++++---- lib/snmp/test/modules.mk | 3 +- lib/snmp/test/snmp_compiler_test.erl | 48 ++++++++++++- lib/snmp/test/snmp_test_data/Test3.mib | 123 +++++++++++++++++++++++++++++++++ 5 files changed, 214 insertions(+), 21 deletions(-) create mode 100644 lib/snmp/test/snmp_test_data/Test3.mib (limited to 'lib') diff --git a/lib/snmp/include/snmp_types.hrl b/lib/snmp/include/snmp_types.hrl index 4adb24361c..fce087347f 100644 --- a/lib/snmp/include/snmp_types.hrl +++ b/lib/snmp/include/snmp_types.hrl @@ -78,23 +78,36 @@ %%----------------------------------------------------------------- %% TableInfo - stored in snmp_symbolic_store for use by the -%% generic table functions. +%% generic table functions. For an ordinary table, the +%% types will be the following: %% nbr_of_cols is an integer +%% pos_integer() %% defvals is a list of {Col, Defval}, ordered by column %% number +%% [{Col :: integer(), Defval :: term()}] %% status_col is an integer +%% pos_integer() %% not_accessible a sorted list of columns (> first_accessible) %% that are 'not-accessible' -%% indextypes is a list of #asn1_type for the index-columns, -%% ordered by column number -%% first_accessible is an integer, the first non-accessible -%% column +%% [pos_integer()] +%% index_types is a list of #asn1_type for the index-columns, +%% ordered by column number or an "augment"-tuple +%% [asn1_type()] +%% first_accessible is an integer, the first accessible column +%% pos_integer() %% first_own_index is an integer. 0 if there is no such index for %% this table. %% This is not the same as the last integer in the oid! %% Example: If a table has one own index (oid.1), one %% column (oid.2) and one imported index then %% first_own_index will be 2. +%% non_neg_integer() +%% For a augmented table, it will instead look like this: +%% index_types {augments, {atom(), asn1_type()}} +%% nbr_of_cols pos_integer() +%% not_accessible [pos_integer()] +%% first_accessible pos_integer() +%% %%----------------------------------------------------------------- -record(table_info, @@ -192,7 +205,7 @@ %%---------------------------------------------------------------------- -record(mib, {misc = [], - mib_format_version = "3.2", + mib_format_version = "3.3", name = "", module_identity, %% Not in SMIv1, and only with +module_identity mes = [], diff --git a/lib/snmp/src/compile/snmpc_lib.erl b/lib/snmp/src/compile/snmpc_lib.erl index 38bb8f3ac6..6e833b6c44 100644 --- a/lib/snmp/src/compile/snmpc_lib.erl +++ b/lib/snmp/src/compile/snmpc_lib.erl @@ -704,23 +704,29 @@ check_trap_name(EnterpriseName, Line, MEs) -> %% This information is needed to be able to create default instrumentation %% functions for tables. %%---------------------------------------------------------------------- -make_table_info(Line, _TableName, {augments,SrcTableEntry}, ColumnMEs) -> +make_table_info(Line, TableName, {augments, SrcTableEntry}, ColumnMEs) -> ColMEs = lists:keysort(#me.oid, ColumnMEs), - %% Nbr_of_Cols = length(ColMEs), + Nbr_of_Cols = length(ColMEs), MEs = ColMEs ++ (get(cdata))#cdata.mes, - Aug = case lookup(SrcTableEntry,MEs) of + Aug = case lookup(SrcTableEntry, MEs) of false -> print_error("Cannot AUGMENT the non-existing table entry ~p", - [SrcTableEntry],Line), + [SrcTableEntry], Line), {augments, error}; - {value,ME} -> - {augments, {SrcTableEntry,translate_type(ME#me.asn1_type)}} + {value, ME} -> + {augments, {SrcTableEntry, translate_type(ME#me.asn1_type)}} end, - #table_info{index_types = Aug}; -make_table_info(Line, TableName, {indexes,[]}, _ColumnMEs) -> + FirstNonIdxCol = augments_first_non_index_column(ColMEs), + NoAccs = list_not_accessible(FirstNonIdxCol, ColMEs), + FirstAcc = first_accessible(TableName, ColMEs), + #table_info{nbr_of_cols = Nbr_of_Cols, + first_accessible = FirstAcc, + not_accessible = NoAccs, + index_types = Aug}; +make_table_info(Line, TableName, {indexes, []}, _ColumnMEs) -> print_error("Table ~w lacks indexes.", [TableName],Line), #table_info{}; -make_table_info(Line, TableName, {indexes,Indexes}, ColumnMEs) -> +make_table_info(Line, TableName, {indexes, Indexes}, ColumnMEs) -> ColMEs = lists:keysort(#me.oid, ColumnMEs), NonImpliedIndexes = lists:map(fun non_implied_name/1, Indexes), test_read_create_access(ColMEs, Line, dummy), @@ -860,11 +866,17 @@ get_asn1_type(ColumnName, MEs, Line) -> end. test_index_positions(Line, Indexes, ColMEs) -> - TLI = lists:filter(fun (IndexName) -> - is_table_local_index(IndexName,ColMEs) end, - Indexes), + IsTLI = fun(IndexName) -> is_table_local_index(IndexName, ColMEs) end, + TLI = lists:filter(IsTLI, Indexes), test_index_positions_impl(Line, TLI, ColMEs). +%% An table that augments another cannot conatin any index, +%% so the first non-index column is always the first column. +augments_first_non_index_column([]) -> + none; +augments_first_non_index_column([#me{oid=Col}|_ColMEs]) -> + Col. + %% Returns the first non-index column | none test_index_positions_impl(_Line, [], []) -> none; test_index_positions_impl(_Line, [], [#me{oid=Col}|_ColMEs]) -> diff --git a/lib/snmp/test/modules.mk b/lib/snmp/test/modules.mk index eacc749b53..7b0bdc5b8f 100644 --- a/lib/snmp/test/modules.mk +++ b/lib/snmp/test/modules.mk @@ -76,7 +76,8 @@ MIB_FILES = \ TestTrap.mib \ TestTrapv2.mib \ Test1.mib \ - Test2.mib + Test2.mib \ + Test3.mib SPECS = snmp.spec snmp.spec.vxworks diff --git a/lib/snmp/test/snmp_compiler_test.erl b/lib/snmp/test/snmp_compiler_test.erl index f3a1e77322..257fc47952 100644 --- a/lib/snmp/test/snmp_compiler_test.erl +++ b/lib/snmp/test/snmp_compiler_test.erl @@ -49,6 +49,7 @@ agent_capabilities/1, module_compliance/1, warnings_as_errors/1, + augments_extra_info/1, otp_6150/1, otp_8574/1, @@ -59,6 +60,7 @@ %%---------------------------------------------------------------------- %% Internal exports %%---------------------------------------------------------------------- + -export([ ]). @@ -125,6 +127,7 @@ all() -> agent_capabilities, module_compliance, warnings_as_errors, + augments_extra_info, {group, tickets} ]. @@ -386,6 +389,47 @@ otp_8595(Config) when is_list(Config) -> ok. +%%====================================================================== + +augments_extra_info(suite) -> + []; +augments_extra_info(Config) when is_list(Config) -> + put(tname, augments_extra_info), + p("starting with Config: ~p~n", [Config]), + + Dir = ?config(case_top_dir, Config), + MibDir = ?config(mib_dir, Config), + Test2File = join(MibDir, "Test2.mib"), + Test3File = join(MibDir, "Test3.mib"), + ?line {ok, Test2BinFile} = + snmpc:compile(Test2File, [{outdir, Dir}, + {verbosity, silence}, + {group_check, false}]), + io:format("Test2BinFile: ~n~p~n", [Test2BinFile]), + ?line {ok, Test3BinFile} = + snmpc:compile(Test3File, [{i, [MibDir]}, + {outdir, Dir}, + {verbosity, silence}, + {group_check, true}]), + io:format("Test3BinFile: ~n~p~n", [Test3BinFile]), + {ok, Test3Mib} = snmp_misc:read_mib(Test3BinFile), + io:format("Test3Mib: ~n~p~n", [Test3Mib]), + %% There is only one table in this mib + #mib{table_infos = [{TableName, TI}]} = Test3Mib, + io:format("TableName: ~p" + "~n Table Info: ~p" + "~n", [TableName, TI]), + #table_info{nbr_of_cols = 4, + defvals = DefVals, + not_accessible = [2,4], + index_types = {augments, {tEntry, undefined}}, + first_accessible = 1} = TI, + io:format("Table info: ~p" + "~n DefVals: ~p" + "~n", [TableName, DefVals]), + ok. + + %%====================================================================== %% Internal functions %%====================================================================== @@ -540,11 +584,11 @@ DESCRIPTION \"" ++ Desc ++ "\" ::= { test 1 } END", - Message = file:write_file(Filename ,Binary), + Message = file:write_file(Filename, Binary), case Message of ok -> ok; {error, Reason} -> - exit({failed_writing_mib,Reason}) + exit({failed_writing_mib, Reason}) end. diff --git a/lib/snmp/test/snmp_test_data/Test3.mib b/lib/snmp/test/snmp_test_data/Test3.mib new file mode 100644 index 0000000000..7f76e4dba4 --- /dev/null +++ b/lib/snmp/test/snmp_test_data/Test3.mib @@ -0,0 +1,123 @@ +Test3 DEFINITIONS ::= BEGIN + +IMPORTS + MODULE-IDENTITY, OBJECT-TYPE, Integer32, snmpModules, mib-2 + FROM SNMPv2-SMI + MODULE-COMPLIANCE, OBJECT-GROUP + FROM SNMPv2-CONF + tEntry + FROM Test2; + +t3MIB MODULE-IDENTITY + LAST-UPDATED "1203090000Z" + ORGANIZATION "" + CONTACT-INFO + "" + DESCRIPTION + "Test mib, used to test processing of requests." + ::= { snmpModules 42 } + + +-- Administrative assignments **************************************** + +t3MIBObjects OBJECT IDENTIFIER ::= { t3MIB 1 } +t3MIBConformance OBJECT IDENTIFIER ::= { t3MIB 2 } + + +-- test4 OBJECT IDENTIFIER ::= { mib-2 18 } + +tAugTable OBJECT-TYPE + SYNTAX SEQUENCE OF TAugEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table AUGMENTS tTable of the Test2 MIB." + ::= { t3MIBObjects 1 } + +tAugEntry OBJECT-TYPE + SYNTAX TAugEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "An entry (conceptual row) in the sysORTable." + AUGMENTS { tEntry } + ::= { tAugTable 1 } + +TAugEntry ::= SEQUENCE { + tFoo1 OCTET STRING, + tFoo2 OCTET STRING, + tBar1 Integer32, + tBar2 Integer32 +} + +tFoo1 OBJECT-TYPE + SYNTAX OCTET STRING (SIZE (0..255)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "A string." + DEFVAL { "foo 1" } + ::= { tAugEntry 1 } + +tFoo2 OBJECT-TYPE + SYNTAX OCTET STRING (SIZE (0..255)) + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A string." + DEFVAL { "foo 2" } + ::= { tAugEntry 2 } + +tBar1 OBJECT-TYPE + SYNTAX Integer32 + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "An integer." + DEFVAL { 42 } + ::= { tAugEntry 3 } + +tBar2 OBJECT-TYPE + SYNTAX Integer32 + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "An integer." + DEFVAL { 42 } + ::= { tAugEntry 4 } + + +-- Conformance Information ******************************************* + +t3MIBCompliances OBJECT IDENTIFIER + ::= { t3MIBConformance 1 } +t3MIBGroups OBJECT IDENTIFIER + ::= { t3MIBConformance 2 } + +-- Compliance statements + +t3MIBCompliance MODULE-COMPLIANCE + STATUS current + DESCRIPTION + "The compliance statement for SNMP engines which + implement the SNMP-COMMUNITY-MIB." + + MODULE -- this module + MANDATORY-GROUPS { t3Group } + + ::= { t3MIBCompliances 1 } + +t3Group OBJECT-GROUP + OBJECTS { + tFoo1, + tFoo2, + tBar1, + tBar2 + } + STATUS current + DESCRIPTION + "A group." + ::= { t3MIBGroups 1 } + + +END -- cgit v1.2.3 From f77abaa8e8b7d1324f7cb59615caa4fb2a4fa161 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 9 Mar 2012 17:50:51 +0100 Subject: [snmp] Add proper release notes OTP-9969 --- lib/snmp/doc/src/notes.xml | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 844409dd21..2d045faa0f 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -45,6 +45,13 @@ --> + +

[compiler] The table information the MIB compiler provides with + augmented tables has been extended with nbr_of_cols, + first_accessible and not_accessible.

+

Own Id: OTP-9969

+ +

Added the log_to_io audit-trail-log converter function to the api modules of both the -- cgit v1.2.3 From da92034283c1813d6d06feb39f064d7d8f76f951 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 13 Mar 2012 17:35:18 +0100 Subject: [snmp] Fixing test MIB dependency Some test MIBs depend on each other (imports), which must be defined or parallell make may fail. OTP-9969 --- lib/snmp/test/Makefile | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib') diff --git a/lib/snmp/test/Makefile b/lib/snmp/test/Makefile index 78ffb1c255..8c1f53e51a 100644 --- a/lib/snmp/test/Makefile +++ b/lib/snmp/test/Makefile @@ -224,6 +224,9 @@ $(SNMP_BIN_TARGET_DIR)/Klas4.bin: $(SNMP_BIN_TARGET_DIR)/Klas3.bin $(SNMP_BIN_TARGET_DIR)/SA-MIB.bin: $(SNMP_BIN_TARGET_DIR)/OLD-SNMPEA-MIB.bin +$(SNMP_BIN_TARGET_DIR)/Test3.bin: $(SNMP_BIN_TARGET_DIR)/Test2.bin + + # ---------------------------------------------------- # Release Target # ---------------------------------------------------- -- cgit v1.2.3