From 7f26c62a2f705cca26227411547c31288df289c5 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 2 Mar 2011 16:55:02 +0100 Subject: Updated version, preliminary appup and release notes. --- lib/snmp/doc/src/notes.xml | 49 +++++++++++++++++++++++++++++++++++++++++ lib/snmp/src/app/snmp.appup.src | 8 +++++++ lib/snmp/vsn.mk | 2 +- 3 files changed, 58 insertions(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 2efeb8ae3f..8677d5ab61 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -32,6 +32,55 @@ notes.xml +
+ SNMP Development Toolkit 4.20 +

Version 4.20 supports code replacement in runtime from/to + version 4,19 and 4.18.

+ +
+ Improvements and new features + + + +

[agent] Added support for sending traps to IPv6 targets.

+

Own Id: OTP-9088

+

Aux Id: Seq 11790

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

-

+ +
+ + +
+ Incompatibilities +

-

+
+ +
+
SNMP Development Toolkit 4.19

Version 4.19 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 de0e5d6e14..5687863522 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -22,6 +22,10 @@ %% ----- U p g r a d e ------------------------------------------------------- [ + {"4.19", + [ + ] + }, {"4.18", [ {load_module, snmp_misc, soft_purge, soft_purge, []}, @@ -53,6 +57,10 @@ %% ------D o w n g r a d e --------------------------------------------------- [ + {"4.19", + [ + ] + }, {"4.18", [ {load_module, snmp_misc, soft_purge, soft_purge, []}, diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index e70c97dcb8..29228fc59b 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -17,6 +17,6 @@ # # %CopyrightEnd% -SNMP_VSN = 4.19 +SNMP_VSN = 4.20 PRE_VSN = APP_VSN = "snmp-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From 91355baf90ac2e708799233a98244af532ea82cc Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 2 Mar 2011 17:07:36 +0100 Subject: Added new mib file (TRANSPORT-ADDRESS-MIB) and fixed makefile accordingly. --- lib/snmp/mibs/Makefile.in | 3 +- lib/snmp/mibs/TRANSPORT-ADDRESS-MIB.mib | 417 ++++++++++++++++++++++++++++++++ 2 files changed, 419 insertions(+), 1 deletion(-) create mode 100644 lib/snmp/mibs/TRANSPORT-ADDRESS-MIB.mib (limited to 'lib/snmp') diff --git a/lib/snmp/mibs/Makefile.in b/lib/snmp/mibs/Makefile.in index 7aefb0ea34..3af74eca75 100644 --- a/lib/snmp/mibs/Makefile.in +++ b/lib/snmp/mibs/Makefile.in @@ -61,7 +61,8 @@ MIBS_A = \ SNMP-USER-BASED-SM-MIB \ SNMP-VIEW-BASED-ACM-MIB \ SNMP-USM-AES-MIB \ - INET-ADDRESS-MIB + INET-ADDRESS-MIB \ + TRANSPORT-ADDRESS-MIB MIBS_B = OTP-SNMPEA-MIB diff --git a/lib/snmp/mibs/TRANSPORT-ADDRESS-MIB.mib b/lib/snmp/mibs/TRANSPORT-ADDRESS-MIB.mib new file mode 100644 index 0000000000..7d450fbc2a --- /dev/null +++ b/lib/snmp/mibs/TRANSPORT-ADDRESS-MIB.mib @@ -0,0 +1,417 @@ +TRANSPORT-ADDRESS-MIB DEFINITIONS ::= BEGIN + +IMPORTS + MODULE-IDENTITY, OBJECT-IDENTITY, mib-2 FROM SNMPv2-SMI + TEXTUAL-CONVENTION FROM SNMPv2-TC; + +transportAddressMIB MODULE-IDENTITY + LAST-UPDATED "200211010000Z" + ORGANIZATION + "IETF Operations and Management Area" + CONTACT-INFO + "Juergen Schoenwaelder (Editor) + TU Braunschweig + Bueltenweg 74/75 + 38106 Braunschweig, Germany + Phone: +49 531 391-3289 + EMail: schoenw@ibr.cs.tu-bs.de + + Send comments to ." + DESCRIPTION + "This MIB module provides commonly used transport + address definitions. + + Copyright (C) The Internet Society (2002). This version of + this MIB module is part of RFC 3419; see the RFC itself for + full legal notices." + + -- Revision log + + REVISION "200211010000Z" + DESCRIPTION + "Initial version, published as RFC 3419." + ::= { mib-2 100 } + + +transportDomains OBJECT IDENTIFIER ::= { transportAddressMIB 1 } + +transportDomainUdpIpv4 OBJECT-IDENTITY + STATUS current + DESCRIPTION + "The UDP over IPv4 transport domain. The corresponding + transport address is of type TransportAddressIPv4 for + global IPv4 addresses." + ::= { transportDomains 1 } + +transportDomainUdpIpv6 OBJECT-IDENTITY + STATUS current + DESCRIPTION + "The UDP over IPv6 transport domain. The corresponding + transport address is of type TransportAddressIPv6 for + global IPv6 addresses." + ::= { transportDomains 2 } + +transportDomainUdpIpv4z OBJECT-IDENTITY + STATUS current + DESCRIPTION + "The UDP over IPv4 transport domain. The corresponding + transport address is of type TransportAddressIPv4z for + scoped IPv4 addresses with a zone index." + ::= { transportDomains 3 } + +transportDomainUdpIpv6z OBJECT-IDENTITY + STATUS current + DESCRIPTION + "The UDP over IPv6 transport domain. The corresponding + transport address is of type TransportAddressIPv6z for + scoped IPv6 addresses with a zone index." + ::= { transportDomains 4 } + +transportDomainTcpIpv4 OBJECT-IDENTITY + STATUS current + DESCRIPTION + "The TCP over IPv4 transport domain. The corresponding + transport address is of type TransportAddressIPv4 for + global IPv4 addresses." + ::= { transportDomains 5 } + +transportDomainTcpIpv6 OBJECT-IDENTITY + STATUS current + DESCRIPTION + "The TCP over IPv6 transport domain. The corresponding + transport address is of type TransportAddressIPv6 for + global IPv6 addresses." + ::= { transportDomains 6 } + +transportDomainTcpIpv4z OBJECT-IDENTITY + STATUS current + DESCRIPTION + "The TCP over IPv4 transport domain. The corresponding + transport address is of type TransportAddressIPv4z for + scoped IPv4 addresses with a zone index." + ::= { transportDomains 7 } + +transportDomainTcpIpv6z OBJECT-IDENTITY + STATUS current + DESCRIPTION + "The TCP over IPv6 transport domain. The corresponding + transport address is of type TransportAddressIPv6z for + scoped IPv6 addresses with a zone index." + ::= { transportDomains 8 } + +transportDomainSctpIpv4 OBJECT-IDENTITY + STATUS current + DESCRIPTION + "The SCTP over IPv4 transport domain. The corresponding + transport address is of type TransportAddressIPv4 for + global IPv4 addresses. This transport domain usually + represents the primary address on multihomed SCTP + endpoints." + ::= { transportDomains 9 } + +transportDomainSctpIpv6 OBJECT-IDENTITY + STATUS current + DESCRIPTION + "The SCTP over IPv6 transport domain. The corresponding + transport address is of type TransportAddressIPv6 for + global IPv6 addresses. This transport domain usually + represents the primary address on multihomed SCTP + endpoints." + ::= { transportDomains 10 } + +transportDomainSctpIpv4z OBJECT-IDENTITY + STATUS current + DESCRIPTION + "The SCTP over IPv4 transport domain. The corresponding + transport address is of type TransportAddressIPv4z for + scoped IPv4 addresses with a zone index. This transport + domain usually represents the primary address on + multihomed SCTP endpoints." + ::= { transportDomains 11 } + +transportDomainSctpIpv6z OBJECT-IDENTITY + STATUS current + DESCRIPTION + "The SCTP over IPv6 transport domain. The corresponding + transport address is of type TransportAddressIPv6z for + scoped IPv6 addresses with a zone index. This transport + domain usually represents the primary address on + multihomed SCTP endpoints." + ::= { transportDomains 12 } + +transportDomainLocal OBJECT-IDENTITY + STATUS current + DESCRIPTION + "The Posix Local IPC transport domain. The corresponding + transport address is of type TransportAddressLocal. + + The Posix Local IPC transport domain incorporates the + well-known UNIX domain sockets." + ::= { transportDomains 13 } + +transportDomainUdpDns OBJECT-IDENTITY + STATUS current + DESCRIPTION + "The UDP transport domain using fully qualified domain + names. The corresponding transport address is of type + TransportAddressDns." + ::= { transportDomains 14 } + +transportDomainTcpDns OBJECT-IDENTITY + STATUS current + DESCRIPTION + "The TCP transport domain using fully qualified domain + names. The corresponding transport address is of type + TransportAddressDns." + ::= { transportDomains 15 } + +transportDomainSctpDns OBJECT-IDENTITY + STATUS current + DESCRIPTION + "The SCTP transport domain using fully qualified domain + names. The corresponding transport address is of type + TransportAddressDns." + ::= { transportDomains 16 } + +TransportDomain ::= TEXTUAL-CONVENTION + STATUS current + DESCRIPTION + "A value that represents a transport domain. + + Some possible values, such as transportDomainUdpIpv4, are + defined in this module. Other possible values can be + defined in other MIB modules." + SYNTAX OBJECT IDENTIFIER + +-- +-- The enumerated values of the textual convention below should +-- be identical to the last sub-identifier of the OID registered +-- for the same domain. +-- + +TransportAddressType ::= TEXTUAL-CONVENTION + STATUS current + DESCRIPTION + "A value that represents a transport domain. This is the + enumerated version of the transport domain registrations + in this MIB module. The enumerated values have the + following meaning: + + unknown(0) unknown transport address type + udpIpv4(1) transportDomainUdpIpv4 + udpIpv6(2) transportDomainUdpIpv6 + udpIpv4z(3) transportDomainUdpIpv4z + udpIpv6z(4) transportDomainUdpIpv6z + tcpIpv4(5) transportDomainTcpIpv4 + tcpIpv6(6) transportDomainTcpIpv6 + tcpIpv4z(7) transportDomainTcpIpv4z + tcpIpv6z(8) transportDomainTcpIpv6z + sctpIpv4(9) transportDomainSctpIpv4 + sctpIpv6(10) transportDomainSctpIpv6 + sctpIpv4z(11) transportDomainSctpIpv4z + sctpIpv6z(12) transportDomainSctpIpv6z + local(13) transportDomainLocal + udpDns(14) transportDomainUdpDns + tcpDns(15) transportDomainTcpDns + sctpDns(16) transportDomainSctpDns + + This textual convention can be used to represent transport + domains in situations where a syntax of TransportDomain is + unwieldy (for example, when used as an index). + + The usage of this textual convention implies that additional + transport domains can only be supported by updating this MIB + module. This extensibility restriction does not apply for the + TransportDomain textual convention which allows MIB authors + to define additional transport domains independently in + other MIB modules." + SYNTAX INTEGER { + unknown(0), + udpIpv4(1), + udpIpv6(2), + udpIpv4z(3), + udpIpv6z(4), + tcpIpv4(5), + tcpIpv6(6), + tcpIpv4z(7), + tcpIpv6z(8), + sctpIpv4(9), + sctpIpv6(10), + sctpIpv4z(11), + sctpIpv6z(12), + local(13), + udpDns(14), + tcpDns(15), + sctpDns(16) + } + +TransportAddress ::= TEXTUAL-CONVENTION + STATUS current + DESCRIPTION + "Denotes a generic transport address. + + A TransportAddress value is always interpreted within the + context of a TransportAddressType or TransportDomain value. + Every usage of the TransportAddress textual convention MUST + specify the TransportAddressType or TransportDomain object + which provides the context. Furthermore, MIB authors SHOULD + define a separate TransportAddressType or TransportDomain + object for each TransportAddress object. It is suggested that + the TransportAddressType or TransportDomain is logically + registered before the object(s) which use the + TransportAddress textual convention if they appear in the + same logical row. + + The value of a TransportAddress object must always be + consistent with the value of the associated + TransportAddressType or TransportDomain object. Attempts + to set a TransportAddress object to a value which is + inconsistent with the associated TransportAddressType or + TransportDomain must fail with an inconsistentValue error. + + When this textual convention is used as a syntax of an + index object, there may be issues with the limit of 128 + sub-identifiers specified in SMIv2, STD 58. In this case, + the OBJECT-TYPE declaration MUST include a 'SIZE' clause + to limit the number of potential instance sub-identifiers." + SYNTAX OCTET STRING (SIZE (0..255)) + +TransportAddressIPv4 ::= TEXTUAL-CONVENTION + DISPLAY-HINT "1d.1d.1d.1d:2d" + STATUS current + DESCRIPTION + "Represents a transport address consisting of an IPv4 + address and a port number (as used for example by UDP, + TCP and SCTP): + + octets contents encoding + 1-4 IPv4 address network-byte order + 5-6 port number network-byte order + + This textual convention SHOULD NOT be used directly in object + definitions since it restricts addresses to a specific format. + However, if it is used, it MAY be used either on its own or + in conjunction with TransportAddressType or TransportDomain + as a pair." + SYNTAX OCTET STRING (SIZE (6)) + +TransportAddressIPv6 ::= TEXTUAL-CONVENTION + DISPLAY-HINT "0a[2x:2x:2x:2x:2x:2x:2x:2x]0a:2d" + STATUS current + DESCRIPTION + "Represents a transport address consisting of an IPv6 + address and a port number (as used for example by UDP, + TCP and SCTP): + + octets contents encoding + 1-16 IPv6 address network-byte order + 17-18 port number network-byte order + + This textual convention SHOULD NOT be used directly in object + definitions since it restricts addresses to a specific format. + However, if it is used, it MAY be used either on its own or + in conjunction with TransportAddressType or TransportDomain + as a pair." + SYNTAX OCTET STRING (SIZE (18)) + +TransportAddressIPv4z ::= TEXTUAL-CONVENTION + DISPLAY-HINT "1d.1d.1d.1d%4d:2d" + STATUS current + DESCRIPTION + "Represents a transport address consisting of an IPv4 + address, a zone index and a port number (as used for + example by UDP, TCP and SCTP): + + octets contents encoding + 1-4 IPv4 address network-byte order + 5-8 zone index network-byte order + 9-10 port number network-byte order + + This textual convention SHOULD NOT be used directly in object + definitions since it restricts addresses to a specific format. + However, if it is used, it MAY be used either on its own or + in conjunction with TransportAddressType or TransportDomain + as a pair." + SYNTAX OCTET STRING (SIZE (10)) + +TransportAddressIPv6z ::= TEXTUAL-CONVENTION + DISPLAY-HINT "0a[2x:2x:2x:2x:2x:2x:2x:2x%4d]0a:2d" + STATUS current + DESCRIPTION + "Represents a transport address consisting of an IPv6 + address, a zone index and a port number (as used for + example by UDP, TCP and SCTP): + + octets contents encoding + 1-16 IPv6 address network-byte order + 17-20 zone index network-byte order + 21-22 port number network-byte order + + This textual convention SHOULD NOT be used directly in object + definitions since it restricts addresses to a specific format. + However, if it is used, it MAY be used either on its own or + in conjunction with TransportAddressType or TransportDomain + as a pair." + SYNTAX OCTET STRING (SIZE (22)) + +TransportAddressLocal ::= TEXTUAL-CONVENTION + DISPLAY-HINT "1a" + STATUS current + DESCRIPTION + "Represents a POSIX Local IPC transport address: + + octets contents encoding + all POSIX Local IPC address string + + The Posix Local IPC transport domain subsumes UNIX domain + sockets. + + This textual convention SHOULD NOT be used directly in object + definitions since it restricts addresses to a specific format. + However, if it is used, it MAY be used either on its own or + in conjunction with TransportAddressType or TransportDomain + as a pair. + + When this textual convention is used as a syntax of an + index object, there may be issues with the limit of 128 + sub-identifiers specified in SMIv2, STD 58. In this case, + the OBJECT-TYPE declaration MUST include a 'SIZE' clause + to limit the number of potential instance sub-identifiers." + REFERENCE + "Protocol Independent Interfaces (IEEE POSIX 1003.1g)" + SYNTAX OCTET STRING (SIZE (1..255)) + +TransportAddressDns ::= TEXTUAL-CONVENTION + DISPLAY-HINT "1a" + STATUS current + DESCRIPTION + "Represents a DNS domain name followed by a colon ':' + (ASCII character 0x3A) and a port number in ASCII. + The name SHOULD be fully qualified whenever possible. + + Values of this textual convention are not directly useable as + transport-layer addressing information, and require runtime + resolution. As such, applications that write them must be + prepared for handling errors if such values are not + supported, or cannot be resolved (if resolution occurs at the + time of the management operation). + + The DESCRIPTION clause of TransportAddress objects that may + have TransportAddressDns values must fully describe how (and + when) such names are to be resolved to IP addresses and vice + versa. + + This textual convention SHOULD NOT be used directly in object + definitions since it restricts addresses to a specific format. + However, if it is used, it MAY be used either on its own or + in conjunction with TransportAddressType or TransportDomain + as a pair. + + When this textual convention is used as a syntax of an + index object, there may be issues with the limit of 128 + sub-identifiers specified in SMIv2, STD 58. In this case, + the OBJECT-TYPE declaration MUST include a 'SIZE' clause + to limit the number of potential instance sub-identifiers." + SYNTAX OCTET STRING (SIZE (1..255)) + +END -- cgit v1.2.3 From 92893c6df0f01c6c1d16f9d52a135f44393e9b01 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 2 Mar 2011 17:34:54 +0100 Subject: Added check functions for domain and tdomain. Also updated check functions for ip and taddress. --- lib/snmp/src/misc/snmp_conf.erl | 150 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 141 insertions(+), 9 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index 4d2f5d8f92..5490d60ac2 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -37,7 +37,10 @@ check_timer/1, - check_ip/1, check_taddress/1, + check_domain/1, + check_tdomain/1, + check_ip/1, + check_taddress/1, check_taddress/2, check_packet_size/1, @@ -52,8 +55,10 @@ -define(SNMP_USE_V3, true). --include("snmp_types.hrl"). --include("SNMP-FRAMEWORK-MIB.hrl"). +-include_lib("snmp/include/snmp_types.hrl"). +-include_lib("snmp/include/SNMP-FRAMEWORK-MIB.hrl"). +-include_lib("snmp/include/TRANSPORT-ADDRESS-MIB.hrl"). +-include_lib("snmp/include/SNMPv2-TM.hrl"). -define(VMODULE,"CONF"). -include("snmp_verbosity.hrl"). @@ -338,15 +343,82 @@ check_sec_level(BadSecLevel) -> %% --------- -check_taddress(X) when is_list(X) andalso (length(X) =:= 6) -> +check_tdomain(TDomain) -> + SupportedTDomains = + [ + ?snmpUDPDomain, + ?transportDomainUdpIpv4, + ?transportDomainUdpIpv6 + ], + AllTDomains = + [ + ?transportDomainUdpIpv4, + ?transportDomainUdpIpv6, + ?transportDomainUdpIpv4z, + ?transportDomainUdpIpv6z, + ?transportDomainTcpIpv4, + ?transportDomainTcpIpv6, + ?transportDomainTcpIpv4z, + ?transportDomainTcpIpv6z, + ?transportDomainSctpIpv4, + ?transportDomainSctpIpv6, + ?transportDomainSctpIpv4z, + ?transportDomainSctpIpv6z, + ?transportDomainLocal, + ?transportDomainUdpDns, + ?transportDomainTcpDns, + ?transportDomainSctpDns + ], + case lists:member(TDomain, SupportedTDomains) of + true -> + ok; + false -> + case lists:member(TDomain, AllTDomains) of + true -> + error({unsupported_tdomain, TDomain}); + false -> + error({unknown_tdomain, TDomain}) + end + end. + + +%% --------- + +check_taddress(X) -> + check_taddress(snmpUDPDomain, X). + +check_taddress(snmpUDPDomain, X) -> + check_taddress(transportDomainUdpIpv4, X); + +check_taddress(transportDomainUdpIpv4, X) + when is_list(X) andalso (length(X) =:= 6) -> case (catch all_integer(X)) of true -> ok; false -> error({invalid_taddress, X}) end; -check_taddress(X) -> - error({invalid_taddress, X}). +check_taddress(transportDomainUdpIpv4, X) -> + error({invalid_taddress, X}); +check_taddress(?transportDomainUdpIpv4, X) -> + check_taddress(transportDomainUdpIpv4, X); + +check_taddress(transportDomainUdpIpv6, X) + when is_list(X) andalso (length(X) =:= 10) -> + case (catch all_integer(X)) of + true -> + ok; + false -> + error({invalid_taddress, X}) + end; +check_taddress(transportDomainUdpIpv6, X) -> + error({invalid_taddress, X}); +check_taddress(?transportDomainUdpIpv6, X) -> + check_taddress(transportDomainUdpIpv6, X); + +check_taddress(BadDomain, _X) -> + error({invalid_tdomain, BadDomain}). + %% --------- @@ -385,15 +457,75 @@ do_check_timer(WaitFor, Factor, Incr, Retry) -> %% --------- -check_ip(X) when is_list(X) andalso (length(X) =:= 4) -> +check_domain(Domain) -> + SupportedDomains = + [ + snmpUDPDomain, + transportDomainUdpIpv4, + transportDomainUdpIpv6 + ], + AllDomains = + [ + transportDomainUdpIpv4, + transportDomainUdpIpv6, + transportDomainUdpIpv4z, + transportDomainUdpIpv6z, + transportDomainTcpIpv4, + transportDomainTcpIpv6, + transportDomainTcpIpv4z, + transportDomainTcpIpv6z, + transportDomainSctpIpv4, + transportDomainSctpIpv6, + transportDomainSctpIpv4z, + transportDomainSctpIpv6z, + transportDomainLocal, + transportDomainUdpDns, + transportDomainTcpDns, + transportDomainSctpDns + ], + case lists:member(Domain, SupportedDomains) of + true -> + ok; + false -> + case lists:member(Domain, AllDomains) of + true -> + error({unsupported_domain, Domain}); + false -> + error({unknown_domain, Domain}) + end + end. + + +%% --------- + +check_ip(X) -> + check_ip(snmpUDPDomain, X). + +check_ip(snmpUDPDomain, X) -> + check_ip(transportDomainUdpIpv4, X); +check_ip(transportDomainUdpIpv4, X) when is_list(X) andalso (length(X) =:= 4) -> case (catch all_integer(X)) of true -> ok; false -> error({invalid_ip_address, X}) end; -check_ip(X) -> - error({invalid_ip_address, X}). +check_ip(transportDomainUdpIpv4, X) -> + error({invalid_ip_address, X}); + +check_ip(transportDomainUdpIpv6, X) when is_list(X) andalso (length(X) =:= 8) -> + case (catch all_integer(X)) of + true -> + ok; + false -> + error({invalid_ip_address, X}) + end; +check_ip(transportDomainUdpIpv6, X) -> + error({invalid_ip_address, X}); + +check_ip(BadDomain, _X) -> + error({invalid_domain, BadDomain}). + %% --------- -- cgit v1.2.3 From 8e312df7663c203ab936c9555cc0f61bbf83cb2f Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 2 Mar 2011 17:47:37 +0100 Subject: Added taddress and tdomain create functions. --- lib/snmp/src/misc/snmp_conf.erl | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'lib/snmp') diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index 5490d60ac2..6fc261b07e 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -39,8 +39,10 @@ check_domain/1, check_tdomain/1, + mk_tdomain/1, check_ip/1, check_taddress/1, check_taddress/2, + mk_taddress/3, check_packet_size/1, @@ -382,6 +384,18 @@ check_tdomain(TDomain) -> end. +%% --------- + +mk_tdomain(snmpUDPDomain) -> + ?snmpUDPDomain; +mk_tdomain(transportDomainUdpIpv4) -> + ?transportDomainUdpIpv4; +mk_tdomain(transportDomainUdpIpv6) -> + ?transportDomainUdpIpv6; +mk_tdomain(BadDomain) -> + error({bad_domain, BadDomain}). + + %% --------- check_taddress(X) -> @@ -496,6 +510,20 @@ check_domain(Domain) -> end. +%% --------- + +%% The values of Ip and Port has both been checked at this +%% point, so we dont need to do that again. +mk_taddress(snmpUDPDomain, Ip, Port) -> + mk_taddress(transportDomainUdpIpv4, Ip, Port); +mk_taddress(transportDomainUdpIpv4, Ip, Port) -> + Ip ++ [Port div 256, Port rem 256]; +mk_taddress(transportDomainUdpIpv6, Ip, Port) -> + Ip ++ [Port div 256, Port rem 256]; +mk_taddress(BadDomain, _Ip, _Port) -> + error({bad_domain, BadDomain}). + + %% --------- check_ip(X) -> -- cgit v1.2.3 From d711ad48d29ea87398880e2655db72455334bf07 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 2 Mar 2011 18:21:15 +0100 Subject: Preliminary support for multiple domains (e.g. IPv6). --- lib/snmp/src/agent/snmp_target_mib.erl | 157 ++++++++++++++++++++++----------- 1 file changed, 106 insertions(+), 51 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmp_target_mib.erl b/lib/snmp/src/agent/snmp_target_mib.erl index 270a5fd5b6..c76e4bb173 100644 --- a/lib/snmp/src/agent/snmp_target_mib.erl +++ b/lib/snmp/src/agent/snmp_target_mib.erl @@ -30,12 +30,13 @@ add_params/5, delete_params/1]). -export([check_target_addr/1, check_target_params/1]). --include("snmp_types.hrl"). --include("snmp_tables.hrl"). --include("SNMP-TARGET-MIB.hrl"). --include("SNMPv2-TC.hrl"). --include("SNMPv2-TM.hrl"). --include("SNMP-FRAMEWORK-MIB.hrl"). +-include_lib("snmp/include/snmp_types.hrl"). +-include_lib("snmp/include/snmp_tables.hrl"). +-include_lib("snmp/include/SNMP-TARGET-MIB.hrl"). +-include_lib("snmp/include/SNMPv2-TC.hrl"). +-include_lib("snmp/include/SNMPv2-TM.hrl"). +-include_lib("snmp/include/SNMP-FRAMEWORK-MIB.hrl"). +-include_lib("snmp/include/TRANSPORT-ADDRESS-MIB.hrl"). -define(VMODULE,"TARGET-MIB"). -include("snmp_verbosity.hrl"). @@ -139,39 +140,53 @@ read_target_config_files(Dir) -> %% {Name, Ip, Udp, Timeout, RetryCount, TagList, Params, EngineId, %% TMask, MMS} %%----------------------------------------------------------------- -check_target_addr({Name, Ip, Udp, Timeout, RetryCount, TagList, - Params, EngineId, TMask, MMS}) -> +default_domain() -> + snmpUDPDomain. + +check_target_addr({Name, Domain, Ip, Udp, Timeout, RetryCount, TagList, + Params, EngineId, TMask, MMS}) -> ?vtrace("check target address with:" - "~n Name: ~s" - "~n Ip: ~p" - "~n Udp: ~p" - "~n Timeout: ~p" - "~n RetryCount: ~p" - "~n TagList: ~p" - "~n Params: ~p" - "~n EngineId: ~p" - "~n TMask: ~p" - "~n MMS: ~p", - [Name,Ip,Udp,Timeout,RetryCount, - TagList,Params,EngineId,TMask,MMS]), + "~n Name: ~s" + "~n Domain: ~p" + "~n Ip: ~p" + "~n Udp: ~p" + "~n Timeout: ~p" + "~n RetryCount: ~p" + "~n TagList: ~p" + "~n Params: ~p" + "~n EngineId: ~p" + "~n TMask: ~p" + "~n MMS: ~p", + [Name, + Domain, Ip, Udp, + Timeout, RetryCount, + TagList, Params, EngineId, TMask, MMS]), snmp_conf:check_string(Name,{gt,0}), - snmp_conf:check_ip(Ip), + snmp_conf:check_domain(Domain), + snmp_conf:check_ip(Domain, Ip), snmp_conf:check_integer(Udp, {gt, 0}), snmp_conf:check_integer(Timeout, {gte, 0}), snmp_conf:check_integer(RetryCount, {gte,0}), snmp_conf:check_string(TagList), snmp_conf:check_string(Params), check_engine_id(EngineId), - TAddr = Ip ++ [Udp div 256, Udp rem 256], - check_mask(TMask, TAddr), + TAddress = snmp_conf:mk_taddress(Domain, Ip, Udp), + TDomain = snmp_conf:mk_tdomain(Domain), + check_mask(TDomain, TMask, TAddress), snmp_conf:check_packet_size(MMS), ?vtrace("check target address done",[]), - - Addr = {Name, ?snmpUDPDomain, TAddr, Timeout, + Addr = {Name, TDomain, TAddress, Timeout, RetryCount, TagList, Params, ?'StorageType_nonVolatile', ?'RowStatus_active', EngineId, TMask, MMS}, % Values for Augmenting table in SNMP-COMMUNITY-MIB {ok, Addr}; +check_target_addr({Name, Ip, Udp, Timeout, RetryCount, TagList, + Params, EngineId, TMask, MMS}) -> + Domain = default_domain(), + check_target_addr({Name, + Domain, Ip, Udp, + Timeout, RetryCount, TagList, + Params, EngineId, TMask, MMS}); check_target_addr({Name, Ip, Udp, Timeout, RetryCount, TagList, Params, EngineId}) -> check_target_addr({Name, Ip, Udp, Timeout, RetryCount, TagList, @@ -194,11 +209,12 @@ check_engine_id(discovery) -> check_engine_id(EngineId) -> snmp_conf:check_string(EngineId). -check_mask([], _TAddr) -> + +check_mask(_TDomain, [], _TAddress) -> ok; -check_mask(TMask, TAddr) when length(TMask) == length(TAddr) -> - snmp_conf:check_taddress(TMask); -check_mask(TMask, _TAddr) -> +check_mask(TDomain, TMask, TAddress) when length(TMask) =:= length(TAddress) -> + snmp_conf:check_taddress(TDomain, TMask); +check_mask(_TDomain, TMask, _TAddr) -> throw({error, {invalid_mask, TMask}}). @@ -261,7 +277,13 @@ table_del_row(Tab, Key) -> add_addr(Name, Ip, Port, Timeout, Retry, TagList, Params, EngineId, TMask, MMS) -> - Addr = {Name, Ip, Port, Timeout, Retry, TagList, + Domain = default_domain(), + add_addr(Name, Domain, Ip, Port, Timeout, Retry, TagList, + Params, EngineId, TMask, MMS). + +add_addr(Name, Domain, Ip, Port, Timeout, Retry, TagList, + Params, EngineId, TMask, MMS) -> + Addr = {Name, Domain, Ip, Port, Timeout, Retry, TagList, Params, EngineId, TMask, MMS}, case (catch check_target_addr(Addr)) of {ok, Row} -> @@ -341,8 +363,11 @@ maybe_create_var(Var) -> init_var(Var) -> ets:insert(snmp_agent_table, {Var, 0}). vars() -> - [snmpUnavailableContexts, - snmpUnknownContexts]. + [ + snmpUnavailableContexts, + snmpUnknownContexts + ]. + %%----------------------------------------------------------------- %% API functions @@ -562,6 +587,8 @@ snmpTargetAddrTable(print) -> Prefix, element(?snmpTargetAddrTDomain, Row), case element(?snmpTargetAddrTDomain, Row) of ?snmpUDPDomain -> udp; + ?transportDomainUdpIpv4 -> udpIpv4; + ?transportDomainUdpIpv6 -> udpIpv6; _ -> undefined end, Prefix, element(?snmpTargetAddrTAddress, Row), @@ -611,13 +638,13 @@ snmpTargetAddrTable(get_next, RowIndex, Cols) -> next(snmpTargetAddrTable, RowIndex, Cols); snmpTargetAddrTable(set, RowIndex, Cols0) -> %% BMK BMK BMK - case (catch verify_targetAddrTable_cols(Cols0, [])) of + case (catch verify_targetAddrTable_cols(Cols0)) of {ok, Cols} -> snmp_notification_mib:invalidate_cache(), %% Add columns for augmenting table snmpTargetAddrExtTable and for - %% target engine ID. Target engine ID is set to "". The function + %% target engine ID. Target engine ID is set to "". The function %% get_target_engine_id will return "" unless a value is set using - %% set_target_engine_id. If it is "" Informs can't be sent to the + %% set_target_engine_id. If it is "" Informs can't be sent to the %% target. NCols = Cols ++ [{?snmpTargetAddrEngineId, ""}, {?snmpTargetAddrTMask, []}, @@ -628,12 +655,12 @@ snmpTargetAddrTable(set, RowIndex, Cols0) -> Error end; snmpTargetAddrTable(is_set_ok, RowIndex, Cols0) -> - case (catch verify_targetAddrTable_cols(Cols0, [])) of + case (catch verify_targetAddrTable_cols(Cols0)) of {ok, Cols} -> %% Add columns for augmenting table snmpTargetAddrExtTable and for - %% target engine ID. Target engine ID is set to "". The function + %% target engine ID. Target engine ID is set to "". The function %% get_target_engine_id will return "" unless a value is set using - %% set_target_engine_id. If it is "" Informs can't be sent to the + %% set_target_engine_id. If it is "" Informs can't be sent to the %% target. NCols = Cols ++ [{?snmpTargetAddrEngineId, ""}, {?snmpTargetAddrTMask, []}, @@ -647,55 +674,83 @@ snmpTargetAddrTable(Op, Arg1, Arg2) -> Db = db(snmpTargetAddrTable), snmp_generic:table_func(Op, Arg1, Arg2, Db). +verify_targetAddrTable_cols(Cols) -> + ValidCols0 = verify_targetAddrTable_cols(Cols, []), + %% Make a last pass to verify TDomain and TAddress. + ValidCols0. + verify_targetAddrTable_cols([], Cols) -> {ok, lists:reverse(Cols)}; -verify_targetAddrTable_cols([{Col, Val0}|Cols], Acc) -> - Val = verify_targetAddrTable_col(Col, Val0), - verify_targetAddrTable_cols(Cols, [{Col, Val}|Acc]). +verify_targetAddrTable_cols([{Col, Val0}|Cols], ValidCols) -> + Val = verify_targetAddrTable_col(Col, Val0, ValidCols), + verify_targetAddrTable_cols(Cols, [{Col, Val}|ValidCols]). -verify_targetAddrTable_col(?snmpTargetAddrName, Name) -> +verify_targetAddrTable_col(?snmpTargetAddrName, Name, _) -> case (catch snmp_conf:check_string(Name)) of ok -> Name; _ -> wrongValue(?snmpTargetAddrName) end; -verify_targetAddrTable_col(?snmpTargetAddrTAddress, TAddr) -> - case (catch snmp_conf:check_taddress(TAddr)) of +verify_targetAddrTable_col(?snmpTargetAddrTDomain, TDomain, _) -> + case (catch snmp_conf:check_tdomain(TDomain)) of ok -> - TAddr; + TDomain; _ -> - wrongValue(?snmpTargetAddrTAddress) + wrongValue(?snmpTargetAddrTDomain) + end; +%% In order to (properly) validate the TAddress, +%% the TDomain must already have been validated +%% (the format of TAddress depends on TDomain). +verify_targetAddrTable_col(?snmpTargetAddrTAddress, TAddress, ValidCols) -> + case lists:keysearch(?snmpTargetAddrTDomain, 1, ValidCols) of + {value, {?snmpTargetAddrTDomain, TDomain}} -> + case (catch snmp_conf:check_taddress(TDomain, TAddress)) of + ok -> + TAddress; + _ -> + wrongValue(?snmpTargetAddrTAddress) + end; + false -> + %% The user did not provide us with a TDomain, which + %% must mean that he/she intends to use the old domain. + TDomain = snmp_misc:mk_tdomain(default_domain()), + case (catch snmp_conf:check_taddress(TDomain, TAddress)) of + ok -> + TAddress; + _ -> + wrongValue(?snmpTargetAddrTAddress) + end end; -verify_targetAddrTable_col(?snmpTargetAddrTimeout, Timeout) -> +verify_targetAddrTable_col(?snmpTargetAddrTimeout, Timeout, _) -> case (catch snmp_conf:check_integer(Timeout)) of ok when Timeout >= 0 -> Timeout; _ -> wrongValue(?snmpTargetAddrTimeout) end; -verify_targetAddrTable_col(?snmpTargetAddrRetryCount, Retry) -> +verify_targetAddrTable_col(?snmpTargetAddrRetryCount, Retry, _) -> case (catch snmp_conf:check_integer(Retry)) of ok when Retry >= 0 -> Retry; _ -> wrongValue(?snmpTargetAddrRetryCount) end; -verify_targetAddrTable_col(?snmpTargetAddrTagList, TagList) -> +verify_targetAddrTable_col(?snmpTargetAddrTagList, TagList, _) -> case (catch snmp_conf:check_string(TagList)) of ok -> TagList; _ -> wrongValue(?snmpTargetAddrTagList) end; -verify_targetAddrTable_col(?snmpTargetAddrParams, Params) -> +verify_targetAddrTable_col(?snmpTargetAddrParams, Params, _) -> case (catch snmp_conf:check_string(Params)) of ok -> Params; _ -> wrongValue(?snmpTargetAddrParams) end; -verify_targetAddrTable_col(_, Val) -> +verify_targetAddrTable_col(_, Val, _) -> Val. -- cgit v1.2.3 From 4526ec71fc913993ec6c5f0a9c0e11192240a60a Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 3 Mar 2011 14:27:32 +0100 Subject: Handling target address configuration files (with new Domain). Also added some proper documentation. --- lib/snmp/doc/src/notes.xml | 4 ++ lib/snmp/doc/src/snmp_agent_config_files.xml | 60 ++++++++++++---------------- lib/snmp/doc/src/snmp_target_mib.xml | 24 ++++++++--- lib/snmp/doc/src/snmpa_conf.xml | 25 +++++++++--- lib/snmp/src/agent/snmp_target_mib.erl | 21 ++++++---- lib/snmp/src/agent/snmpa_conf.erl | 47 ++++++++++++++++------ 6 files changed, 115 insertions(+), 66 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 8677d5ab61..8dd5bcb2c0 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -45,6 +45,10 @@

[agent] Added support for sending traps to IPv6 targets.

+

See the + target address config file, + the target_addr_entry/11 function or + add_addr/11 for more info.

Own Id: OTP-9088

Aux Id: Seq 11790

diff --git a/lib/snmp/doc/src/snmp_agent_config_files.xml b/lib/snmp/doc/src/snmp_agent_config_files.xml index b62269d506..bd5c537522 100644 --- a/lib/snmp/doc/src/snmp_agent_config_files.xml +++ b/lib/snmp/doc/src/snmp_agent_config_files.xml @@ -1,4 +1,4 @@ - + @@ -367,56 +367,50 @@ Target Address Definitions

The information about Target Address Definitions should be - stored in a file called - target_addr.conf. -

+ stored in a file called target_addr.conf.

The corresponding tables are snmpTargetAddrTable in the - SNMP-TARGET-MIB and snmpTargetAddrExtTable in the SNMP-COMMUNITY-MIB. -

-

Each entry is a term: -

-

{TargetName, Ip, Udp, Timeout, RetryCount, TagList, ParamsName, EngineId}. or

-{TargetName, Ip, Udp, Timeout, RetryCount, TagList, ParamsName, EngineId, TMask, MaxMessageSize}.

+ SNMP-TARGET-MIB and snmpTargetAddrExtTable in the + SNMP-COMMUNITY-MIB.

+

Each entry is a term:

+

{TargetName, Ip, Udp, Timeout, RetryCount, TagList, ParamsName, EngineId}.

or

+{TargetName, Ip, Udp, Timeout, RetryCount, TagList, ParamsName, EngineId, TMask, MaxMessageSize}.

or

+{TargetName, Domain, Ip, Udp, Timeout, RetryCount, TagList, ParamsName, EngineId, TMask, MaxMessageSize}.

TargetName is a unique non-empty string.

-

Ip is a list of four integers. -

+

Domain is one of the atoms: + transportDomainUdpIpv4 | transportDomainUdpIpv6.

-

Udp is an integer. -

+

Ip is a list of four or eight integers.

-

Timeout is an integer. -

+

Udp is an integer.

-

RetryCount is an integer. -

+

Timeout is an integer.

-

TagList is a string. -

+

RetryCount is an integer.

-

ParamsName is a string. -

+

TagList is a string.

-

EngineId is a string or the atom discovery. -

+

ParamsName is a string.

-

TMask is a string of size 0, or size 6 (default: []). -

+

EngineId is a string or the atom discovery.

-

MaxMessageSize is an integer (default: 2048). -

+

TMask is a list of integer() of size 0, + size 6 or size 10 (default: []).

+
+ +

MaxMessageSize is an integer (default: 2048).

Note that if EngineId has the value discovery, @@ -429,14 +423,10 @@ Target Parameters Definitions

The information about Target Parameters Definitions should be - stored in a file called - target_params.conf. -

+ stored in a file called target_params.conf.

The corresponding table is snmpTargetParamsTable in the - SNMP-TARGET-MIB. -

-

Each entry is a term: -

+ SNMP-TARGET-MIB.

+

Each entry is a term:

{ParamsName, MPModel, SecurityModel, SecurityName, SecurityLevel}.

diff --git a/lib/snmp/doc/src/snmp_target_mib.xml b/lib/snmp/doc/src/snmp_target_mib.xml index 4a36be19a3..d5151d41de 100644 --- a/lib/snmp/doc/src/snmp_target_mib.xml +++ b/lib/snmp/doc/src/snmp_target_mib.xml @@ -1,10 +1,10 @@ - +
- 19982009 + 19982011 Ericsson AB. All Rights Reserved. @@ -39,9 +39,21 @@ and functions for configuring the database.

The configuration files are described in the SNMP User's Manual.

- + +
+ DATA TYPES + + + +
+ configure(ConfDir) -> void() @@ -118,17 +130,19 @@ add_addr(Name, Ip, Port, Timeout, Retry, TagList, Params, EngineId, TMask, MMS) -> Ret + add_addr(Name, Domain, Ip, Port, Timeout, Retry, TagList, Params, EngineId, TMask, MMS) -> Ret Add one target address definition Name = string() - Ip = [integer()], length 4 + Domain = transportDomain() + Ip = transportAddressIPv4() | transportAddressIPv6() (depends on the value of Domain) Port = integer() Timeout = integer() Retry = integer() TagList = string() ParamsName = string() EngineId = string() - TMask = string(), length 0 or 6 + TMask = transportAddressMask() (depends on Domain) MMS = integer() Ret = {ok, Key} | {error, Reason} Key = term() diff --git a/lib/snmp/doc/src/snmpa_conf.xml b/lib/snmp/doc/src/snmpa_conf.xml index d873574c6e..a533c179ee 100644 --- a/lib/snmp/doc/src/snmpa_conf.xml +++ b/lib/snmp/doc/src/snmpa_conf.xml @@ -1,10 +1,10 @@ - +
- 20062010 + 20062011 Ericsson AB. All Rights Reserved. @@ -38,8 +38,21 @@ used for manipulating (write/append/read) the config files of the SNMP agent.

- + + +
+ DATA TYPES + + + +
+ agent_entry(Tag, Val) -> agent_entry() @@ -381,17 +394,19 @@ target_addr_entry(Name, Ip, TagList, ParamsName, EngineId, TMask) -> target_addr_entry() target_addr_entry(Name, Ip, Udp, TagList, ParamsName, EngineId, TMask, MaxMessageSize) -> target_addr_entry() target_addr_entry(Name, Ip, Udp, Timeout, RetryCount, TagList, ParamsName, EngineId, TMask, MaxMessageSize) -> target_addr_entry() + target_addr_entry(Name, Domain, Ip, Udp, Timeout, RetryCount, TagList, ParamsName, EngineId, TMask, MaxMessageSize) -> target_addr_entry() Create an target_addr entry Name = string() - Ip = string() + Domain = transportDomain() + Ip = transportAddressIPv4() | transportAddressIPv6() (depends on Domain) Udp = integer() Timeout = integer() RetryCount = integer() TagList = string() ParamsName = string() EngineId = string() - TMask = string() + TMask = transportAddressMask() (depends on Domain) MaxMessageSize = integer() target_addr_entry() = term() diff --git a/lib/snmp/src/agent/snmp_target_mib.erl b/lib/snmp/src/agent/snmp_target_mib.erl index c76e4bb173..c7fc449bd2 100644 --- a/lib/snmp/src/agent/snmp_target_mib.erl +++ b/lib/snmp/src/agent/snmp_target_mib.erl @@ -29,6 +29,7 @@ -export([add_addr/10, delete_addr/1, add_params/5, delete_params/1]). -export([check_target_addr/1, check_target_params/1]). +-export([default_domain/0]). -include_lib("snmp/include/snmp_types.hrl"). -include_lib("snmp/include/snmp_tables.hrl"). @@ -49,6 +50,12 @@ -define(snmpTargetAddrMMS, 12). +%%----------------------------------------------------------------- + +default_domain() -> + snmpUDPDomain. + + %%----------------------------------------------------------------- %% Func: configure/1 %% Args: Dir is the directory where the configuration files are found. @@ -140,8 +147,6 @@ read_target_config_files(Dir) -> %% {Name, Ip, Udp, Timeout, RetryCount, TagList, Params, EngineId, %% TMask, MMS} %%----------------------------------------------------------------- -default_domain() -> - snmpUDPDomain. check_target_addr({Name, Domain, Ip, Udp, Timeout, RetryCount, TagList, Params, EngineId, TMask, MMS}) -> @@ -172,7 +177,7 @@ check_target_addr({Name, Domain, Ip, Udp, Timeout, RetryCount, TagList, check_engine_id(EngineId), TAddress = snmp_conf:mk_taddress(Domain, Ip, Udp), TDomain = snmp_conf:mk_tdomain(Domain), - check_mask(TDomain, TMask, TAddress), + check_tmask(TDomain, TMask, TAddress), snmp_conf:check_packet_size(MMS), ?vtrace("check target address done",[]), Addr = {Name, TDomain, TAddress, Timeout, @@ -210,12 +215,12 @@ check_engine_id(EngineId) -> snmp_conf:check_string(EngineId). -check_mask(_TDomain, [], _TAddress) -> +check_tmask(_TDomain, [], _TAddress) -> ok; -check_mask(TDomain, TMask, TAddress) when length(TMask) =:= length(TAddress) -> +check_tmask(TDomain, TMask, TAddress) when length(TMask) =:= length(TAddress) -> snmp_conf:check_taddress(TDomain, TMask); -check_mask(_TDomain, TMask, _TAddr) -> - throw({error, {invalid_mask, TMask}}). +check_tmask(_TDomain, TMask, _TAddr) -> + throw({error, {invalid_tmask, TMask}}). %%----------------------------------------------------------------- @@ -637,7 +642,7 @@ snmpTargetAddrTable(get, RowIndex, Cols) -> snmpTargetAddrTable(get_next, RowIndex, Cols) -> next(snmpTargetAddrTable, RowIndex, Cols); snmpTargetAddrTable(set, RowIndex, Cols0) -> - %% BMK BMK BMK + %% BMK BMK case (catch verify_targetAddrTable_cols(Cols0)) of {ok, Cols} -> snmp_notification_mib:invalidate_cache(), diff --git a/lib/snmp/src/agent/snmpa_conf.erl b/lib/snmp/src/agent/snmpa_conf.erl index b4fc716b3e..c17256b258 100644 --- a/lib/snmp/src/agent/snmpa_conf.erl +++ b/lib/snmp/src/agent/snmpa_conf.erl @@ -48,7 +48,7 @@ %% target_addr.conf target_addr_entry/5, target_addr_entry/6, - target_addr_entry/8, target_addr_entry/10, + target_addr_entry/8, target_addr_entry/10, target_addr_entry/11, write_target_addr_config/2, write_target_addr_config/3, append_target_addr_config/2, read_target_addr_config/1, @@ -447,7 +447,23 @@ target_addr_entry(Name, EngineId, TMask, MaxMessageSize) -> + target_addr_entry(Name, snmp_target_mib:default_domain(), Ip, Udp, + Timeout, RetryCount, TagList, ParamsName, EngineId, + TMask, MaxMessageSize). + +target_addr_entry(Name, + Domain, + Ip, + Udp, + Timeout, + RetryCount, + TagList, + ParamsName, + EngineId, + TMask, + MaxMessageSize) -> {Name, + Domain, Ip, Udp, Timeout, @@ -465,9 +481,13 @@ write_target_addr_config(Dir, Conf) -> "%% The data is inserted into the snmpTargetAddrTable defined\n" "%% in SNMP-TARGET-MIB, and in the snmpTargetAddrExtTable defined\n" "%% in SNMP-COMMUNITY-MIB.\n" -"%% Each row is a 10-tuple:\n" -"%% {Name, Ip, Udp, Timeout, RetryCount, TagList, ParamsName, EngineId,\n" -"%% TMask, MaxMessageSize}.\n" +"%% Each row is a 10 or 11-tuple (Domain is optional):\n" +"%% {Name, \n" +"%% Domain, Ip, Udp, \n" +"%% Timeout, RetryCount, TagList, ParamsName, EngineId,\n" +"%% TMask, MaxMessageSize}.\n" +"%% The value of Domain deside the format of the Ip and TMask values. \n" +"%% If not present, classic Ipv4 is assumed. \n" "%% The EngineId value is only used if Inform-Requests are sent to this\n" "%% target. If Informs are not sent, this value is ignored, and can be\n" "%% e.g. an empty string. However, if Informs are sent, it is essential\n" @@ -524,13 +544,14 @@ write_target_addr_conf(Fd, Conf) -> lists:foreach(Fun, Conf). do_write_target_addr_conf(Fd, - {Name, Ip, Udp, + {Name, + Domain, Ip, Udp, Timeout, RetryCount, TagList, ParamsName, EngineId, TMask, MaxMessageSize}) -> io:format(Fd, - "{\"~s\", ~w, ~w, ~w, ~w, \"~s\", \"~s\", \"~s\", ~w, ~w}.~n", - [Name, Ip, Udp, Timeout, RetryCount, TagList, + "{\"~s\", ~w, ~w, ~w, ~w, ~w, \"~s\", \"~s\", \"~s\", ~w, ~w}.~n", + [Name, Domain, Ip, Udp, Timeout, RetryCount, TagList, ParamsName, EngineId, TMask, MaxMessageSize]); do_write_target_addr_conf(_Fd, Crap) -> error({bad_target_addr_config, Crap}). @@ -546,13 +567,13 @@ target_params_entry(Name, Vsn) -> target_params_entry(Name, Vsn, SecName, SecLevel). target_params_entry(Name, Vsn, SecName, SecLevel) -> - MPModel = if Vsn == v1 -> v1; - Vsn == v2 -> v2c; - Vsn == v3 -> v3 + MPModel = if Vsn =:= v1 -> v1; + Vsn =:= v2 -> v2c; + Vsn =:= v3 -> v3 end, - SecModel = if Vsn == v1 -> v1; - Vsn == v2 -> v2c; - Vsn == v3 -> usm + SecModel = if Vsn =:= v1 -> v1; + Vsn =:= v2 -> v2c; + Vsn =:= v3 -> usm end, target_params_entry(Name, MPModel, SecModel, SecName, SecLevel). -- cgit v1.2.3 From 1191b33a100185862929a4175436e946022a8789 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 3 Mar 2011 14:58:49 +0100 Subject: Trap sending module now handles the new domains. --- lib/snmp/src/agent/snmpa_trap.erl | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa_trap.erl b/lib/snmp/src/agent/snmpa_trap.erl index 450cb2e9f4..786512e0c9 100644 --- a/lib/snmp/src/agent/snmpa_trap.erl +++ b/lib/snmp/src/agent/snmpa_trap.erl @@ -33,13 +33,14 @@ send_inform/6]). -export([init_discovery_inform/12, send_discovery_inform/5]). --include("snmp_types.hrl"). --include("snmpa_internal.hrl"). --include("SNMPv2-MIB.hrl"). --include("SNMPv2-TM.hrl"). --include("SNMPv2-TC.hrl"). --include("SNMP-FRAMEWORK-MIB.hrl"). --include("SNMP-TARGET-MIB.hrl"). +-include_lib("snmp/include/snmp_types.hrl"). +-include_lib("snmp/src/agent/snmpa_internal.hrl"). +-include_lib("snmp/include/SNMPv2-MIB.hrl"). +-include_lib("snmp/include/SNMPv2-TM.hrl"). +-include_lib("snmp/include/SNMPv2-TC.hrl"). +-include_lib("snmp/include/SNMP-FRAMEWORK-MIB.hrl"). +-include_lib("snmp/include/SNMP-TARGET-MIB.hrl"). +-include_lib("snmp/include/TRANSPORT-ADDRESS-MIB.hrl"). -define(enterpriseSpecific, 6). @@ -1001,9 +1002,27 @@ transform_taddr({?snmpUDPDomain, [A1, A2, A3, A4, P1, P2]}) -> % v2 Addr = {A1, A2, A3, A4}, Port = P1 bsl 8 + P2, {Addr, Port}; +transform_taddr({?transportDomainUdpIpv4, [A1, A2, A3, A4, P1, P2]}) -> % v2 + Addr = {A1, A2, A3, A4}, + Port = P1 bsl 8 + P2, + {Addr, Port}; +transform_taddr({?transportDomainUdpIpv6, + [A1, A2, A3, A4, A5, A6, A7, A8, P1, P2]}) -> % v2 + Addr = {A1, A2, A3, A4, A5, A6, A7, A8}, + Port = P1 bsl 8 + P2, + {Addr, Port}; transform_taddr({{?snmpUDPDomain, [A1, A2, A3, A4, P1, P2]}, _MsgData}) -> % v3 Addr = {A1, A2, A3, A4}, Port = P1 bsl 8 + P2, + {Addr, Port}; +transform_taddr({{?transportDomainUdpIpv4, [A1, A2, A3, A4, P1, P2]}, _MsgData}) -> % v3 + Addr = {A1, A2, A3, A4}, + Port = P1 bsl 8 + P2, + {Addr, Port}; +transform_taddr({{?transportDomainUdpIpv6, + [A1, A2, A3, A4, A5, A6, A7, A8, P1, P2]}, _MsgData}) -> % v3 + Addr = {A1, A2, A3, A4, A5, A6, A7, A8}, + Port = P1 bsl 8 + P2, {Addr, Port}. @@ -1060,6 +1079,7 @@ mic([{Addr, Comm} | T], CurComm, AddrList, Res) -> mic([], CurComm, AddrList, Res) -> [{CurComm, AddrList} | Res]. + %%----------------------------------------------------------------- %% Convert the SecurityLevel into a flag value used by snmpa_mpd %%----------------------------------------------------------------- -- cgit v1.2.3 From 2ff2b4ee1b50eb621e436f7c448808d67d6690df Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 3 Mar 2011 18:17:43 +0100 Subject: Backup... --- lib/snmp/src/agent/snmpa_net_if.erl | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index 97a7a63dee..d07829bd7e 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -636,7 +636,6 @@ process_taddrs([{{_Domain, AddrAndPort}, _SecData}|T], Acc) -> process_taddrs([{_Domain, AddrAndPort}|T], Acc) -> process_taddrs(T, [AddrAndPort|Acc]). - merge_taddrs(To1, To2) -> merge_taddrs(To1, To2, []). -- cgit v1.2.3 From 0c14ab3979bb1eba4b4398c92d176e56eba8286b Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 7 Mar 2011 19:22:30 +0100 Subject: Basically backup commit (time to go home). Implemented handling of domains in the mpd module. Still some errors left though (3 test cases fail). --- lib/snmp/src/agent/snmpa_acm.erl | 26 +++++++----- lib/snmp/src/agent/snmpa_agent.erl | 5 ++- .../src/agent/snmpa_authentication_service.erl | 9 +++-- lib/snmp/src/agent/snmpa_conf.erl | 4 +- lib/snmp/src/agent/snmpa_mpd.erl | 44 +++++++++++--------- lib/snmp/src/agent/snmpa_net_if.erl | 47 +++++++++++++++++++--- lib/snmp/src/agent/snmpa_trap.erl | 2 +- lib/snmp/src/misc/snmp_conf.erl | 31 +++++++++++++- 8 files changed, 122 insertions(+), 46 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa_acm.erl b/lib/snmp/src/agent/snmpa_acm.erl index 6ad4f0b442..b37c82429c 100644 --- a/lib/snmp/src/agent/snmpa_acm.erl +++ b/lib/snmp/src/agent/snmpa_acm.erl @@ -62,11 +62,13 @@ %% {error, Reason} | %% {discarded, Variable, Reason} %% Types: Pdu = #pdu -%% ACMData = acm_data() = {community, Community, Address} | -%% {v3, MsgID, SecModel, SecName, SecLevel, -%% ContextEngineID, ContextName, SecData} +%% ACMData = acm_data() = +%% {community, SecModel, Community, TDomain, TAddress} | +%% {v3, MsgID, SecModel, SecName, SecLevel, +%% ContextEngineID, ContextName, SecData} %% Community = string() -%% Address = ip() ++ udp() (list) +%% TDomain = ?transportDomainUdpIpv4 | ?transportDomainUdpIpv6 +%% TAddress = ip() ++ udp() (list) %% MsgID = integer() %% SecModel = ?SEC_* (see snmp_types.hrl) %% SecName = string() @@ -114,7 +116,10 @@ error2status(_) -> genErr. %% discarded: no error response is sent %% authentication_failure: no error response is sent, a trap is generated %%----------------------------------------------------------------- -init_ca(Pdu, {community, SecModel, Community, TAddr}) -> +init_ca(Pdu, {community, SecModel, Community, TAddress}) -> + TDomain = snmp_conf:mk_tdomain(snmp_transport_mib:default_domain()), + init_ca(Pdu, {community, SecModel, Community, TDomain, TAddress}); +init_ca(Pdu, {community, SecModel, Community, TDomain, TAddress}) -> %% This is a v1 or v2c request. Use SNMP-COMMUNITY-MIB to %% map the community to vacm parameters. ?vtrace("check access for ~n" @@ -126,18 +131,18 @@ init_ca(Pdu, {community, SecModel, Community, TAddr}) -> _ -> read end, ?vtrace("View type: ~p", [ViewType]), - CaCacheKey = {Community, SecModel, TAddr, ViewType}, + CaCacheKey = {Community, SecModel, TDomain, TAddress, ViewType}, case check_ca_cache(CaCacheKey) of false -> - case snmp_community_mib:community2vacm(Community, - {?snmpUDPDomain,TAddr}) of + case snmp_community_mib:community2vacm(Community, + {TDomain, TAddress}) of {SecName, _ContextEngineId, ContextName} -> %% Maybe we should check that the contextEngineID %% matches the local engineID? %% It better, since we don't impl. proxy. ?vtrace("get mib view" "~n Security name: ~p" - "~n Context name: ~p",[SecName,ContextName]), + "~n Context name: ~p",[SecName, ContextName]), case snmpa_vacm:get_mib_view(ViewType, SecModel, SecName, ?'SnmpSecurityLevel_noAuthNoPriv', ContextName) of @@ -153,7 +158,7 @@ init_ca(Pdu, {community, SecModel, Community, TAddr}) -> end; undefined -> {authentication_failure, snmpInBadCommunityNames, - {bad_community_name, TAddr, Community}} + {bad_community_name, TDomain, TAddress, Community}} end; Res -> Res @@ -219,6 +224,7 @@ upd_ca_cache(KeyVal) -> invalidate_ca_cache() -> erase(ca_cache). + %%----------------------------------------------------------------- %% Func: check(Res) -> {ok, MibView} | {discarded, Variable, Reason} %% Args: Res = {ok, AccessFunc} | diff --git a/lib/snmp/src/agent/snmpa_agent.erl b/lib/snmp/src/agent/snmpa_agent.erl index f70885b2ec..c6a45c9f25 100644 --- a/lib/snmp/src/agent/snmpa_agent.erl +++ b/lib/snmp/src/agent/snmpa_agent.erl @@ -1470,7 +1470,10 @@ handle_backup_res([{Who, Crap}|Results], Acc) -> %% because we (for some reason) support the function %% snmpa:current_community(). %%----------------------------------------------------------------- -cheat({community, _SecModel, Community, _IpUdp}, Address, ContextName) -> +cheat({community, SecModel, Community, _TAddress}, Address, ContextName) -> + {Community, Address, ContextName}; +cheat({community, _SecModel, Community, _TDomain, _TAddress}, + Address, ContextName) -> {Community, Address, ContextName}; cheat(_, Address, ContextName) -> {"", Address, ContextName}. diff --git a/lib/snmp/src/agent/snmpa_authentication_service.erl b/lib/snmp/src/agent/snmpa_authentication_service.erl index 572fab7fbf..d406c58ee4 100644 --- a/lib/snmp/src/agent/snmpa_authentication_service.erl +++ b/lib/snmp/src/agent/snmpa_authentication_service.erl @@ -29,11 +29,12 @@ behaviour_info(_) -> %%----------------------------------------------------------------- %% init_check_access(Pdu, ACMData) %% Pdu = #pdu -%% ACMData = acm_data() = {community, Community, Address} | -%% {v3, MsgID, SecModel, SecName, SecLevel, -%% ContextEngineID, ContextName, SecData} +%% ACMData = acm_data() = {community, SecModel, Community, TDomain, TAddress} | +%% {v3, MsgID, SecModel, SecName, SecLevel, +%% ContextEngineID, ContextName, SecData} %% Community = string() -%% Address = ip() ++ udp() (list) +%% TDomain = ?transportDomainUdpIpv4 | ?transportDomainUdpIpv6 +%% TAddress = ip() ++ udp() (list) %% MsgID = integer() %% SecModel = ?SEC_* (see snmp_types.hrl) %% SecName = string() diff --git a/lib/snmp/src/agent/snmpa_conf.erl b/lib/snmp/src/agent/snmpa_conf.erl index c17256b258..75d31225e7 100644 --- a/lib/snmp/src/agent/snmpa_conf.erl +++ b/lib/snmp/src/agent/snmpa_conf.erl @@ -483,10 +483,10 @@ write_target_addr_config(Dir, Conf) -> "%% in SNMP-COMMUNITY-MIB.\n" "%% Each row is a 10 or 11-tuple (Domain is optional):\n" "%% {Name, \n" -"%% Domain, Ip, Udp, \n" +"%% Domain, Ip, Port, \n" "%% Timeout, RetryCount, TagList, ParamsName, EngineId,\n" "%% TMask, MaxMessageSize}.\n" -"%% The value of Domain deside the format of the Ip and TMask values. \n" +"%% The value of Domain decide the format of the Ip and TMask values. \n" "%% If not present, classic Ipv4 is assumed. \n" "%% The EngineId value is only used if Inform-Requests are sent to this\n" "%% target. If Informs are not sent, this value is ignored, and can be\n" diff --git a/lib/snmp/src/agent/snmpa_mpd.erl b/lib/snmp/src/agent/snmpa_mpd.erl index fd75b98f84..39a4246d26 100644 --- a/lib/snmp/src/agent/snmpa_mpd.erl +++ b/lib/snmp/src/agent/snmpa_mpd.erl @@ -115,8 +115,8 @@ reset() -> %% Func: process_packet(Packet, TDomain, TAddress, State, Log) -> %% {ok, SnmpVsn, Pdu, PduMS, ACMData} | {discarded, Reason} %% Types: Packet = binary() -%% TDomain = snmpUDPDomain | atom() -%% TAddress = {Ip, Udp} +%% TDomain = snmpUDPDomain | transportDomain() +%% TAddress = {Ip, Udp} (*but* depends on TDomain) %% State = #state %% Purpose: This is the main Message Dispatching function. (see %% section 4.2.1 in rfc2272) @@ -182,24 +182,30 @@ discarded_pdu(Variable) -> inc(Variable). %%----------------------------------------------------------------- %% Handles a Community based message (v1 or v2c). %%----------------------------------------------------------------- -v1_v2c_proc(Vsn, NoteStore, Community, snmpUDPDomain, +v1_v2c_proc(Vsn, NoteStore, Community, Domain, {Ip, Udp}, LocalEngineID, Data, HS, Log, Packet) -> - TAddress = tuple_to_list(Ip) ++ [Udp div 256, Udp rem 256], - AgentMS = get_engine_max_message_size(LocalEngineID), - MgrMS = snmp_community_mib:get_target_addr_ext_mms(?snmpUDPDomain, - TAddress), - PduMS = case MgrMS of - {ok, MMS} when MMS < AgentMS -> MMS - HS; - _ -> AgentMS - HS - end, + TDomain = snmp_conf:mk_tdomain(Domain), + TAddress = snmp_conf:mk_taddress(Domain, Ip, Udp), + AgentMS = get_engine_max_message_size(LocalEngineID), + MgrMS = snmp_community_mib:get_target_addr_ext_mms(TDomain, TAddress), + PduMS = case MgrMS of + {ok, MMS} when MMS < AgentMS -> MMS - HS; + _ -> AgentMS - HS + end, case (catch snmp_pdus:dec_pdu(Data)) of Pdu when is_record(Pdu, pdu) -> Log(Pdu#pdu.type, Packet), inc_snmp_in_vars(Pdu), #pdu{request_id = ReqId} = Pdu, - OkRes = {ok, Vsn, Pdu, PduMS, - {community, sec_model(Vsn), Community, TAddress}}, + + %% + %% We have added TDomain, what are the consequences? + ACMData = + {community, sec_model(Vsn), Community, TDomain, TAddress}, + OkRes = {ok, Vsn, Pdu, PduMS, ACMData}, + %% + %% Make sure that we don't process duplicate SET request %% twice. We don't know what could happen in that case. %% The mgr does, so he has to generate a new SET request. @@ -216,8 +222,6 @@ v1_v2c_proc(Vsn, NoteStore, Community, snmpUDPDomain, snmp_note_store:set_note(NoteStore, 100, Key, true), %% Uses ACMData that snmpa_acm knows of. - %% snmpUDPDomain is implicit, since that's the only - %% one we handle. OkRes; true -> {discarded, duplicate_pdu} @@ -275,12 +279,12 @@ v3_proc(NoteStore, Packet, LocalEngineID, V3Hdr, Data, Log) -> "~n msgSecurityParameters = ~w", [MsgID, MMS, MsgFlags, MsgSecurityModel, SecParams]), %% 7.2.4 - SecModule = get_security_module(MsgSecurityModel), + SecModule = get_security_module(MsgSecurityModel), %% 7.2.5 - SecLevel = check_sec_level(MsgFlags), + SecLevel = check_sec_level(MsgFlags), IsReportable = snmp_misc:is_reportable(MsgFlags), %% 7.2.6 - ?vtrace("v3_proc -> [7.2.6]" + ?vtrace("v3_proc -> [7.2.4-7.2.6]" "~n SecModule = ~p" "~n SecLevel = ~p" "~n IsReportable = ~p", @@ -531,7 +535,7 @@ check_sec_module_result(Res, V3Hdr, Data, LocalEngineID, IsReportable, Log) -> ?vdebug("security module result [7.2.6-b]:" "~n Reason: ~p", [Reason]), throw({discarded, {securityError, Reason}}); - {error, Reason, ErrorInfo} when IsReportable == true -> % case 7.2.6 a + {error, Reason, ErrorInfo} when IsReportable =:= true -> % case 7.2.6 a ?vdebug("security module result when reportable [7.2.6-a]:" "~n Reason: ~p" "~n ErrorInfo: ~p", [Reason, ErrorInfo]), @@ -574,7 +578,7 @@ generate_response_msg(Vsn, RePdu, Type, ACMData, LocalEngineID, Log) -> generate_response_msg(Vsn, RePdu, Type, ACMData, LocalEngineID, Log, 1). generate_response_msg(Vsn, RePdu, Type, - {community, _SecModel, Community, _IpUdp}, + {community, _SecModel, Community, _TDomain, _TAddress}, LocalEngineID, Log, _) -> case catch snmp_pdus:enc_pdu(RePdu) of diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index d07829bd7e..d4bb5bdf9f 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -504,7 +504,6 @@ handle_discovery_response(_Ip, _Port, #pdu{request_id = ReqId} = Pdu, S end. - handle_recv(#state{usock = Sock, mpd_state = MpdState, note_store = NS, @@ -513,7 +512,9 @@ handle_recv(#state{usock = Sock, LogF = fun(Type, Data) -> log(Log, Type, Data, Ip, Port) end, - case (catch snmpa_mpd:process_packet(Packet, snmpUDPDomain, {Ip, Port}, + Domain = snmp_conf:which_domain(Ip), % What the ****... + case (catch snmpa_mpd:process_packet(Packet, + Domain, {Ip, Port}, MpdState, NS, LogF)) of {ok, _Vsn, Pdu, _PduMS, {discovery, ManagerEngineId}} -> handle_discovery_response(Ip, Port, Pdu, ManagerEngineId, S); @@ -775,15 +776,49 @@ handle_send_pdu1(#state{log = Log, usock = Sock, filter = FilterMod}, Type, Addresses) -> SendFun = - fun({snmpUDPDomain, {Ip, Port}, Packet}) when is_binary(Packet) -> - ?vdebug("sending packet:" + fun({snmpUDPDomain, {Ip, Port}, Packet}) + when is_binary(Packet) -> + ?vdebug("[snmpUDPDomain] sending packet:" + "~n size: ~p" + "~n to: ~p:~p", + [sz(Packet), Ip, Port]), + maybe_udp_send(FilterMod, Log, Type, Sock, Ip, Port, Packet); + + ({snmpUDPDomain, {Ip, Port}, {Packet, _LogData}}) + when is_binary(Packet) -> + ?vdebug("[snmpUDPDomain] sending encrypted packet:" + "~n size: ~p" + "~n to: ~p:~p", + [sz(Packet), Ip, Port]), + maybe_udp_send(FilterMod, Log, Type, Sock, Ip, Port, Packet); + + ({transportDomainUdpIpv4, {Ip, Port}, Packet}) + when is_binary(Packet) -> + ?vdebug("[transportDomainUdpIpv4] sending packet:" + "~n size: ~p" + "~n to: ~p:~p", + [sz(Packet), Ip, Port]), + maybe_udp_send(FilterMod, Log, Type, Sock, Ip, Port, Packet); + + ({transportDomainUdpIpv4, {Ip, Port}, {Packet, _LogData}}) + when is_binary(Packet) -> + ?vdebug("[transportDomainUdpIpv4] sending encrypted packet:" + "~n size: ~p" + "~n to: ~p:~p", + [sz(Packet), Ip, Port]), + maybe_udp_send(FilterMod, Log, Type, Sock, Ip, Port, Packet); + + ({transportDomainUdpIpv6, {Ip, Port}, Packet}) + when is_binary(Packet) -> + ?vdebug("[transportDomainUdpIpv6] sending packet:" "~n size: ~p" "~n to: ~p:~p", [sz(Packet), Ip, Port]), maybe_udp_send(FilterMod, Log, Type, Sock, Ip, Port, Packet); - ({snmpUDPDomain, {Ip, Port}, {Packet, _LogData}}) when is_binary(Packet) -> - ?vdebug("sending encrypted packet:" + ({transportDomainUdpIpv6, {Ip, Port}, {Packet, _LogData}}) + when is_binary(Packet) -> + ?vdebug("[transportDomainUdpIpv6] sending encrypted packet:" "~n size: ~p" "~n to: ~p:~p", [sz(Packet), Ip, Port]), diff --git a/lib/snmp/src/agent/snmpa_trap.erl b/lib/snmp/src/agent/snmpa_trap.erl index 786512e0c9..648dd46508 100644 --- a/lib/snmp/src/agent/snmpa_trap.erl +++ b/lib/snmp/src/agent/snmpa_trap.erl @@ -1072,7 +1072,7 @@ mk_addr_communities(Recvs) -> [{Addr, Comm} | T] = lists:keysort(2, Recvs), mic(T, Comm, [Addr], []). -mic([{Addr, Comm} | T], CurComm, AddrList, Res) when Comm == CurComm -> +mic([{Addr, Comm} | T], CurComm, AddrList, Res) when Comm =:= CurComm -> mic(T, CurComm, [Addr | AddrList], Res); mic([{Addr, Comm} | T], CurComm, AddrList, Res) -> mic(T, Comm, [Addr], [{CurComm, AddrList} | Res]); diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index 6fc261b07e..cda86d3f6f 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -40,6 +40,7 @@ check_domain/1, check_tdomain/1, mk_tdomain/1, + which_domain/1, check_ip/1, check_taddress/1, check_taddress/2, mk_taddress/3, @@ -516,14 +517,40 @@ check_domain(Domain) -> %% point, so we dont need to do that again. mk_taddress(snmpUDPDomain, Ip, Port) -> mk_taddress(transportDomainUdpIpv4, Ip, Port); -mk_taddress(transportDomainUdpIpv4, Ip, Port) -> +mk_taddress(transportDomainUdpIpv4, Ip, Port) when is_list(Ip) -> Ip ++ [Port div 256, Port rem 256]; -mk_taddress(transportDomainUdpIpv6, Ip, Port) -> +mk_taddress(transportDomainUdpIpv4 = Domain, Ip, Port) when is_tuple(Ip) -> + mk_taddress(Domain, tuple_to_list(Ip), Port); +mk_taddress(transportDomainUdpIpv6, Ip, Port) when is_list(Ip) -> Ip ++ [Port div 256, Port rem 256]; +mk_taddress(transportDomainUdpIpv6 = Domain, Ip, Port) when is_tuple(Ip) -> + mk_taddress(Domain, tuple_to_list(Ip), Port); + +%% These are just for convenience +mk_taddress(?snmpUDPDomain, Ip, Port) -> + mk_taddress(snmpUDPDomain, Ip, Port); +mk_taddress(?transportDomainUdpIpv4, Ip, Port) -> + mk_taddress(transportDomainUdpIpv4, Ip, Port); +mk_taddress(?transportDomainUdpIpv6, Ip, Port) -> + mk_taddress(transportDomainUdpIpv6, Ip, Port); + +%% Bad domain mk_taddress(BadDomain, _Ip, _Port) -> error({bad_domain, BadDomain}). +%% --------- + +which_domain(Ip) when is_list(Ip) andalso (length(Ip) =:= 4) -> + transportDomainUdpIpv4; +which_domain(Ip) when is_tuple(Ip) andalso (size(Ip) =:= 4) -> + transportDomainUdpIpv4; +which_domain(Ip) when is_list(Ip) andalso (length(Ip) =:= 8) -> + transportDomainUdpIpv6; +which_domain(Ip) when is_tuple(Ip) andalso (size(Ip) =:= 8) -> + transportDomainUdpIpv6. + + %% --------- check_ip(X) -> -- cgit v1.2.3 From 20fe9e81991f1c18eb7d22371e2ad6befcc87fe6 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 7 Mar 2011 19:23:54 +0100 Subject: Bring example config file up-to-date. --- lib/snmp/priv/conf/agent/target_addr.conf | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/priv/conf/agent/target_addr.conf b/lib/snmp/priv/conf/agent/target_addr.conf index 33a5d0d4c4..f48a6645a3 100644 --- a/lib/snmp/priv/conf/agent/target_addr.conf +++ b/lib/snmp/priv/conf/agent/target_addr.conf @@ -3,9 +3,13 @@ %% The data is inserted into the snmpTargetAddrTable defined %% in SNMP-TARGET-MIB, and in the snmpTargeAddrExtTabke defined %% in SNMP-COMMUNITY-MIB. -%% Each row is a 9-tuple: -%% {Name, Ip, Udp, Timeout, RetryCount, TagList, ParamsName, EngineId, -%% TMask, MaxMessageSize}. +%% Each row is a 10 or 11-tuple (Domain is optional): +%% {Name, +%% Domain, Ip, Port, +%% Timeout, RetryCount, TagList, ParamsName, EngineId, +%% TMask, MaxMessageSize}. +%% The value of Domain decide the format of the Ip and TMask values. +%% If not present, classic Ipv4 is assumed. %% The EngineId value is only used if Inform-Requests are sent to this %% target. If Informs are not sent, this value is ignored, and can be %% e.g. an empty string. However, if Informs are sent, it is essential -- cgit v1.2.3 From f609a092a1741d60ff54fd9c29bd5785985eb48a Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 8 Mar 2011 16:24:17 +0100 Subject: Added some target debugging. --- lib/snmp/src/agent/snmp_notification_mib.erl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmp_notification_mib.erl b/lib/snmp/src/agent/snmp_notification_mib.erl index 1cd69b430f..3da5766b44 100644 --- a/lib/snmp/src/agent/snmp_notification_mib.erl +++ b/lib/snmp/src/agent/snmp_notification_mib.erl @@ -273,9 +273,12 @@ find_targets(Key, TargAddrs, Db, Res) -> get_targets([{TagList, Addr, TargetName, Params, Timeout, Retry}|T], Tag, Type, Name) -> case snmp_misc:is_tag_member(Tag, TagList) of - true -> [{Name, {Addr, TargetName, Params, type(Type, Timeout, Retry)}}| - get_targets(T, Tag, Type, Name)]; + true -> + ?vtrace("tag ~w *is* member", [Tag]), + [{Name, {Addr, TargetName, Params, type(Type, Timeout, Retry)}}| + get_targets(T, Tag, Type, Name)]; false -> + ?vtrace("tag ~w is *not* member", [Tag]), get_targets(T, Tag, Type, Name) end; get_targets([], _Tag, _Type, _Name) -> -- cgit v1.2.3 From 1079b25efb6d6d4a4834c6e74d1e8d8ccab5f788 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 8 Mar 2011 16:26:41 +0100 Subject: Cosmetics... --- lib/snmp/src/agent/snmpa_agent.erl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa_agent.erl b/lib/snmp/src/agent/snmpa_agent.erl index c6a45c9f25..d9a0438b56 100644 --- a/lib/snmp/src/agent/snmpa_agent.erl +++ b/lib/snmp/src/agent/snmpa_agent.erl @@ -754,8 +754,8 @@ handle_info({send_trap, Trap, NotifyName, ContextName, Recv, Varbinds}, S) -> "~n Varbinds: ~p", [Trap, NotifyName, ContextName, Recv, Varbinds]), LocalEngineID = ?DEFAULT_LOCAL_ENGINE_ID, - case catch handle_send_trap(S, Trap, NotifyName, ContextName, - Recv, Varbinds, LocalEngineID) of + case (catch handle_send_trap(S, Trap, NotifyName, ContextName, + Recv, Varbinds, LocalEngineID)) of {ok, NewS} -> {noreply, NewS}; {'EXIT', R} -> @@ -775,8 +775,8 @@ handle_info({send_trap, Trap, NotifyName, ContextName, Recv, Varbinds, "~n Varbinds: ~p" "~n LocalEngineID: ~p", [Trap, NotifyName, ContextName, Recv, Varbinds, LocalEngineID]), - case catch handle_send_trap(S, Trap, NotifyName, ContextName, - Recv, Varbinds, LocalEngineID) of + case (catch handle_send_trap(S, Trap, NotifyName, ContextName, + Recv, Varbinds, LocalEngineID)) of {ok, NewS} -> {noreply, NewS}; {'EXIT', R} -> @@ -923,9 +923,9 @@ handle_call({send_trap, Trap, NotifyName, ContextName, Recv, Varbinds}, ?DEFAULT_LOCAL_ENGINE_ID; _ -> %% subagent - - %% we don't need this, eventually the trap sent request - %% will reach the master-agent and then it will look up - %% the proper engine id. + %% we don't need this now, eventually the trap send + %% request will reach the master-agent and then it + %% will look up the proper engine id. ignore end, case (catch handle_send_trap(S, Trap, NotifyName, ContextName, @@ -1720,7 +1720,7 @@ handle_acm_error(Vsn, Reason, Pdu, ACMData, Address, Extra) -> handle_send_trap(S, TrapName, NotifyName, ContextName, Recv, Varbinds, LocalEngineID) -> ?vtrace("handle_send_trap -> entry with" - "~n S#state.type: ~p" + "~n Agent type: ~p" "~n TrapName: ~p" "~n NotifyName: ~p" "~n ContextName: ~p" -- cgit v1.2.3 From 699b00036849c33db8c13033c13291baa0ed1523 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 8 Mar 2011 18:19:24 +0100 Subject: Add handling pf domain and also default domain for cases where old style is used. --- lib/snmp/src/agent/snmpa_conf.erl | 16 +++++++++++++++- lib/snmp/src/misc/snmp_config.erl | 3 +++ 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa_conf.erl b/lib/snmp/src/agent/snmpa_conf.erl index 75d31225e7..4e5aab5319 100644 --- a/lib/snmp/src/agent/snmpa_conf.erl +++ b/lib/snmp/src/agent/snmpa_conf.erl @@ -541,8 +541,22 @@ write_target_addr_conf(Fd, Hdr, Conf) -> write_target_addr_conf(Fd, Conf) -> Fun = fun(Entry) -> do_write_target_addr_conf(Fd, Entry) end, - lists:foreach(Fun, Conf). + lists:foreach(Fun, Conf), + ok. +do_write_target_addr_conf(Fd, + {Name, + Ip, Udp, + Timeout, RetryCount, TagList, + ParamsName, EngineId, + TMask, MaxMessageSize}) -> + Domain = snmp_target_mib:default_domain(), + do_write_target_addr_conf(Fd, + {Name, + Domain, Ip, Udp, + Timeout, RetryCount, TagList, + ParamsName, EngineId, + TMask, MaxMessageSize}); do_write_target_addr_conf(Fd, {Name, Domain, Ip, Udp, diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index 25350e08cb..91a6550b0a 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -1721,10 +1721,12 @@ write_agent_snmp_target_addr_conf(Dir, ManagerIp, UDP, Hdr = header() ++ Comment, F = fun(v1 = Vsn, Acc) -> [{mk_ip(ManagerIp, Vsn), + snmp_target_mib:default_domain(), ManagerIp, UDP, Timeout, RetryCount, "std_trap", mk_param(Vsn), "", [], 2048}| Acc]; (v2 = Vsn, Acc) -> [{mk_ip(ManagerIp, Vsn), + snmp_target_mib:default_domain(), ManagerIp, UDP, Timeout, RetryCount, "std_trap", mk_param(Vsn), "", [], 2048}, {lists:flatten(io_lib:format("~s.2",[mk_ip(ManagerIp, Vsn)])), @@ -1732,6 +1734,7 @@ write_agent_snmp_target_addr_conf(Dir, ManagerIp, UDP, "std_inform", mk_param(Vsn), "", [], 2048}| Acc]; (v3 = Vsn, Acc) -> [{mk_ip(ManagerIp, Vsn), + snmp_target_mib:default_domain(), ManagerIp, UDP, Timeout, RetryCount, "std_trap", mk_param(Vsn), "", [], 2048}, {lists:flatten(io_lib:format("~s.3",[mk_ip(ManagerIp, Vsn)])), -- cgit v1.2.3 From 2b0d9ba437b263317227ce7d3ba0c581fa4dfb34 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 8 Mar 2011 18:23:31 +0100 Subject: Debugging when retrieving destinations. --- lib/snmp/src/agent/snmpa_trap.erl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa_trap.erl b/lib/snmp/src/agent/snmpa_trap.erl index 648dd46508..09ecb5228b 100644 --- a/lib/snmp/src/agent/snmpa_trap.erl +++ b/lib/snmp/src/agent/snmpa_trap.erl @@ -441,11 +441,13 @@ split_variables([]) -> {[], []}. %% NOTE: This function is executed in the master agent's context %%----------------------------------------------------------------- find_dests("") -> + ?vtrace("find destinations", []), snmp_notification_mib:get_targets(); find_dests(NotifyName) -> + ?vtrace("find destinations for ~p", [NotifyName]), case snmp_notification_mib:get_targets(NotifyName) of [] -> - ?vlog("No dests found for snmpNotifyName: ~p",[NotifyName]), + ?vlog("No dests found for NotifyName: ~p", [NotifyName]), []; Dests -> Dests -- cgit v1.2.3 From 252ae114a1482a67aaa24ecbf83a40d2e2dc173c Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 8 Mar 2011 18:24:29 +0100 Subject: Added export of new ip check function (using domain when checking). --- lib/snmp/src/misc/snmp_conf.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index cda86d3f6f..4fffb0fe38 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -41,7 +41,7 @@ check_tdomain/1, mk_tdomain/1, which_domain/1, - check_ip/1, + check_ip/1, check_ip/2, check_taddress/1, check_taddress/2, mk_taddress/3, -- cgit v1.2.3 From 49071db42818592e99950e5e971e877bb2ca2f59 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 8 Mar 2011 18:29:13 +0100 Subject: Mostly esthetic stuff... --- lib/snmp/test/snmp_agent_test.erl | 143 ++++++++++++++++++++++++---------- lib/snmp/test/snmp_agent_test_lib.erl | 15 ++-- 2 files changed, 112 insertions(+), 46 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index 692d29fda0..cf4d5523bf 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -105,16 +105,11 @@ groups() -> {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()}, + {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()}, {misc, [], misc_cases()}, {test_v1, [], v1_cases()}, {test_v2, [], v2_cases()}, {test_v1_v2, [], v1_v2_cases()}, @@ -378,17 +373,29 @@ end_per_testcase2(_Case, Config) -> cases() -> -case ?OSTYPE() of - vxworks -> - [{group, misc}, {group, test_v1}, {group, test_v2}, - {group, test_v1_v2}, {group, test_multi_threaded}, - {group, mib_storage}, {group, tickets1}]; - _Else -> - [{group, misc}, {group, test_v1}, {group, test_v2}, - {group, test_v1_v2}, {group, test_v3}, - {group, test_multi_threaded}, {group, mib_storage}, - {group, tickets1}] -end. + case ?OSTYPE() of + vxworks -> + [ + {group, misc}, + {group, test_v1}, + {group, test_v2}, + {group, test_v1_v2}, + {group, test_multi_threaded}, + {group, mib_storage}, + {group, tickets1} + ]; + _Else -> + [ + {group, misc}, + {group, test_v1}, + {group, test_v2}, + {group, test_v1_v2}, + {group, test_v3}, + {group, test_multi_threaded}, + {group, mib_storage}, + {group, tickets1} + ] + end. %%%----------------------------------------------------------------- @@ -1071,11 +1078,29 @@ app_dir(App) -> %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]. + [ + 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 is_list(Config) -> ?line SaNode = ?config(snmp_sa, Config), @@ -1094,12 +1119,31 @@ finish_v1(Config) when is_list(Config) -> 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]. + [ + 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 is_list(Config) -> SaNode = ?config(snmp_sa, Config), @@ -1118,7 +1162,7 @@ finish_v2(Config) when is_list(Config) -> v1_v2_cases() -> -[simple_bi]. + [simple_bi]. init_v1_v2(Config) when is_list(Config) -> SaNode = ?config(snmp_sa, Config), @@ -1137,13 +1181,32 @@ finish_v1_v2(Config) when is_list(Config) -> 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]. + [ + 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 is_list(Config) -> %% Make sure crypto works, otherwise start_agent will fail diff --git a/lib/snmp/test/snmp_agent_test_lib.erl b/lib/snmp/test/snmp_agent_test_lib.erl index 9e89aa889c..3ae2409997 100644 --- a/lib/snmp/test/snmp_agent_test_lib.erl +++ b/lib/snmp/test/snmp_agent_test_lib.erl @@ -1311,10 +1311,12 @@ rewrite_target_addr_conf(Dir, NewPort) -> "~n NewPort: ~p", [NewPort]), TAFile = filename:join(Dir, "target_addr.conf"), case file:read_file_info(TAFile) of - {ok, _} -> ok; - {error, R} -> ?ERR("failure reading file info of " - "target address config file: ~p",[R]), - ok + {ok, _} -> + ok; + {error, R} -> + ?ERR("failure reading file info of " + "target address config file: ~p",[R]), + ok end, ?line [TrapAddr|Addrs] = @@ -1335,8 +1337,9 @@ rewrite_target_addr_conf(Dir, NewPort) -> rewrite_target_addr_conf_check(O) -> {ok,O}. -rewrite_target_addr_conf2(NewPort,{Name,Ip,_Port,Timeout,Retry, - "std_trap",EngineId}) -> +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) -> -- cgit v1.2.3 From 2c6dfeef2e9e4622f9e6a587b4f92d5e76f2ee73 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 8 Mar 2011 23:07:58 +0100 Subject: Used invalid module names in two places. Corrected. --- lib/snmp/src/agent/snmp_target_mib.erl | 2 +- lib/snmp/src/agent/snmpa_acm.erl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmp_target_mib.erl b/lib/snmp/src/agent/snmp_target_mib.erl index c7fc449bd2..a2820269d0 100644 --- a/lib/snmp/src/agent/snmp_target_mib.erl +++ b/lib/snmp/src/agent/snmp_target_mib.erl @@ -719,7 +719,7 @@ verify_targetAddrTable_col(?snmpTargetAddrTAddress, TAddress, ValidCols) -> false -> %% The user did not provide us with a TDomain, which %% must mean that he/she intends to use the old domain. - TDomain = snmp_misc:mk_tdomain(default_domain()), + TDomain = snmp_conf:mk_tdomain(default_domain()), case (catch snmp_conf:check_taddress(TDomain, TAddress)) of ok -> TAddress; diff --git a/lib/snmp/src/agent/snmpa_acm.erl b/lib/snmp/src/agent/snmpa_acm.erl index b37c82429c..30bd34a205 100644 --- a/lib/snmp/src/agent/snmpa_acm.erl +++ b/lib/snmp/src/agent/snmpa_acm.erl @@ -117,7 +117,7 @@ error2status(_) -> genErr. %% authentication_failure: no error response is sent, a trap is generated %%----------------------------------------------------------------- init_ca(Pdu, {community, SecModel, Community, TAddress}) -> - TDomain = snmp_conf:mk_tdomain(snmp_transport_mib:default_domain()), + TDomain = snmp_conf:mk_tdomain(snmp_target_mib:default_domain()), init_ca(Pdu, {community, SecModel, Community, TDomain, TAddress}); init_ca(Pdu, {community, SecModel, Community, TDomain, TAddress}) -> %% This is a v1 or v2c request. Use SNMP-COMMUNITY-MIB to -- cgit v1.2.3 From 5dabc95081ca0be902f3e73df65276bda29924c0 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 9 Mar 2011 14:13:39 +0100 Subject: Backup commit. --- lib/snmp/src/app/snmp.appup.src | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/snmp') diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index 5687863522..e9db432934 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -24,6 +24,16 @@ [ {"4.19", [ + {load_module, snmp_conf, soft_purge, soft_purge, []}, + {load_module, snmp_config, soft_purge, soft_purge, []}, + {load_module, snmpa_mpd, soft_purge, soft_purge, []}, + {load_module, snmpa_trap, soft_purge, soft_purge, []}, + {load_module, snmpa_acm, soft_purge, soft_purge, []}, + {load_module, snmpa_conf, soft_purge, soft_purge, []}, + {load_module, snmp_notification_mib, soft_purge, soft_purge, []}, + {load_module, snmp_target_mib, soft_purge, soft_purge, []}, + {update, snmpa_net_if, soft, soft_purge, soft_purge, [snmpa_mpd]}, + {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_acm, snmpa_trap]} ] }, {"4.18", -- cgit v1.2.3 From 6c8f96a4a762e8bd9dd2ef758a5312791c064dd0 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 9 Mar 2011 15:32:04 +0100 Subject: Proper appup-file that actually passes the test suite. --- lib/snmp/src/app/snmp.appup.src | 78 +++++++++++++++++++++++++++++++++++------ 1 file changed, 68 insertions(+), 10 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index e9db432934..b8aea85cbe 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -26,18 +26,37 @@ [ {load_module, snmp_conf, soft_purge, soft_purge, []}, {load_module, snmp_config, soft_purge, soft_purge, []}, - {load_module, snmpa_mpd, soft_purge, soft_purge, []}, - {load_module, snmpa_trap, soft_purge, soft_purge, []}, - {load_module, snmpa_acm, soft_purge, soft_purge, []}, - {load_module, snmpa_conf, soft_purge, soft_purge, []}, - {load_module, snmp_notification_mib, soft_purge, soft_purge, []}, - {load_module, snmp_target_mib, soft_purge, soft_purge, []}, - {update, snmpa_net_if, soft, soft_purge, soft_purge, [snmpa_mpd]}, - {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_acm, snmpa_trap]} + {load_module, snmpa_mpd, soft_purge, soft_purge, [snmp_conf]}, + {load_module, snmpa_trap, soft_purge, soft_purge, + [snmpa_mpd, snmp_notification_mib, snmp_target_mib]}, + {load_module, snmpa_acm, soft_purge, soft_purge, + [snmp_conf, snmpa_acm, snmpa_mpd, snmp_target_mib]}, + {load_module, snmpa_conf, soft_purge, soft_purge, + [snmp_notification_mib]}, + {load_module, snmp_notification_mib, soft_purge, soft_purge, + [snmp_conf, snmp_target_mib]}, + {load_module, snmp_target_mib, soft_purge, soft_purge, + [snmp_conf]}, + {update, snmpa_net_if, soft, soft_purge, soft_purge, + [snmp_conf, snmpa_mpd]}, + {update, snmpa_agent, soft, soft_purge, soft_purge, + [snmpa_acm, snmpa_mpd, snmpa_trap]} ] }, {"4.18", [ + {load_module, snmp_conf, soft_purge, soft_purge, []}, + {load_module, snmp_config, soft_purge, soft_purge, []}, + {load_module, snmpa_mpd, soft_purge, soft_purge, [snmp_conf]}, + {load_module, snmpa_trap, soft_purge, soft_purge, + [snmpa_mpd, snmp_notification_mib, snmp_target_mib]}, + {load_module, snmpa_acm, soft_purge, soft_purge, + [snmp_conf, snmpa_acm, snmpa_mpd, snmp_target_mib]}, + {load_module, snmpa_conf, soft_purge, soft_purge, + [snmp_notification_mib]}, + {load_module, snmp_notification_mib, soft_purge, soft_purge, + [snmp_conf, snmp_target_mib]}, + {load_module, snmp_misc, soft_purge, soft_purge, []}, {load_module, snmpa_vacm, soft_purge, soft_purge, []}, {load_module, snmpa, soft_purge, soft_purge, @@ -59,7 +78,12 @@ [snmpa_mib_lib]}, {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, [snmpa_mib_lib, snmpa_vacm]}, - {load_module, snmpa_mib_lib, soft_purge, soft_purge, []} + {load_module, snmpa_mib_lib, soft_purge, soft_purge, []}, + + {update, snmpa_net_if, soft, soft_purge, soft_purge, + [snmp_conf, snmpa_mpd]}, + {update, snmpa_agent, soft, soft_purge, soft_purge, + [snmpa_acm, snmpa_mpd, snmpa_trap]} ] } ], @@ -69,10 +93,39 @@ [ {"4.19", [ + {load_module, snmp_conf, soft_purge, soft_purge, []}, + {load_module, snmp_config, soft_purge, soft_purge, []}, + {load_module, snmpa_mpd, soft_purge, soft_purge, [snmp_conf]}, + {load_module, snmpa_trap, soft_purge, soft_purge, + [snmpa_mpd, snmp_notification_mib, snmp_target_mib]}, + {load_module, snmpa_acm, soft_purge, soft_purge, + [snmp_conf, snmpa_acm, snmpa_mpd, snmp_target_mib]}, + {load_module, snmpa_conf, soft_purge, soft_purge, + [snmp_notification_mib]}, + {load_module, snmp_notification_mib, soft_purge, soft_purge, + [snmp_conf, snmp_target_mib]}, + {load_module, snmp_target_mib, soft_purge, soft_purge, + [snmp_conf]}, + {update, snmpa_net_if, soft, soft_purge, soft_purge, + [snmp_conf, snmpa_mpd]}, + {update, snmpa_agent, soft, soft_purge, soft_purge, + [snmpa_acm, snmpa_mpd, snmpa_trap]} ] }, {"4.18", [ + {load_module, snmp_conf, soft_purge, soft_purge, []}, + {load_module, snmp_config, soft_purge, soft_purge, []}, + {load_module, snmpa_mpd, soft_purge, soft_purge, [snmp_conf]}, + {load_module, snmpa_trap, soft_purge, soft_purge, + [snmpa_mpd, snmp_notification_mib, snmp_target_mib]}, + {load_module, snmpa_acm, soft_purge, soft_purge, + [snmp_conf, snmpa_acm, snmpa_mpd, snmp_target_mib]}, + {load_module, snmpa_conf, soft_purge, soft_purge, + [snmp_notification_mib]}, + {load_module, snmp_notification_mib, soft_purge, soft_purge, + [snmp_conf, snmp_target_mib]}, + {load_module, snmp_misc, soft_purge, soft_purge, []}, {load_module, snmpa_vacm, soft_purge, soft_purge, []}, {load_module, snmpa, soft_purge, soft_purge, @@ -94,7 +147,12 @@ [snmpa_mib_lib]}, {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, [snmpa_mib_lib, snmpa_vacm]}, - {load_module, snmpa_mib_lib, soft_purge, soft_purge, []} + {load_module, snmpa_mib_lib, soft_purge, soft_purge, []}, + + {update, snmpa_net_if, soft, soft_purge, soft_purge, + [snmp_conf, snmpa_mpd]}, + {update, snmpa_agent, soft, soft_purge, soft_purge, + [snmpa_acm, snmpa_mpd, snmpa_trap]} ] } ] -- cgit v1.2.3 From b56002c163ff5f811da902129dd4b2f37edc226d Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 9 Mar 2011 16:52:33 +0100 Subject: Added the new mib TRANSPORT-ADDRESS-MIB to the mib for which we are building man-pages. --- lib/snmp/doc/src/files.mk | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/files.mk b/lib/snmp/doc/src/files.mk index c906ba0cf2..44cfab0a14 100644 --- a/lib/snmp/doc/src/files.mk +++ b/lib/snmp/doc/src/files.mk @@ -157,4 +157,5 @@ MIB_FILES = \ $(MIBSDIR)/SNMP-VIEW-BASED-ACM-MIB.mib \ $(MIBSDIR)/SNMP-USM-AES-MIB.mib \ $(MIBSDIR)/INET-ADDRESS-MIB.mib \ + $(MIBSDIR)/TRANSPORT-ADDRESS-MIB.mib \ $(MIBSDIR)/OTP-SNMPEA-MIB.mib -- cgit v1.2.3 From 9b56ae6666dfa5e3389ec8ca117ddcbb4dc350a3 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 9 Mar 2011 17:23:28 +0100 Subject: The first basic (version) update: Version, release notes and (an empty) appup entry. --- lib/snmp/doc/src/notes.xml | 54 +++++++++++++++++++++++++++++++++++++++++ lib/snmp/src/app/snmp.appup.src | 8 ++++++ lib/snmp/vsn.mk | 2 +- 3 files changed, 63 insertions(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 2efeb8ae3f..b7e50c47e4 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -32,6 +32,59 @@ notes.xml
+
+ SNMP Development Toolkit 4.20 +

Version 4.20 supports code replacement in runtime from/to + version 4.19 and 4.18.

+ +
+ Improvements and new features + + + +

[agent] To be able to handle multiple engine-id(s) when + sending trap(s), the function + add_community/6 + has been added.

+

Own Id: OTP-9119 Aux Id: Seq 11792

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

-

+ +
+ + +
+ Incompatibilities +

-

+
+ +
+ +
SNMP Development Toolkit 4.19

Version 4.19 supports code replacement in runtime from/to @@ -126,6 +179,7 @@ snmp_view_basec_acm_mib:vacmAccessTable(set, RowIndex, Cols).

+
SNMP Development Toolkit 4.18

Version 4.18 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 de0e5d6e14..07e696ce88 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -22,6 +22,10 @@ %% ----- U p g r a d e ------------------------------------------------------- [ + {"4.19", + [ + ] + }, {"4.18", [ {load_module, snmp_misc, soft_purge, soft_purge, []}, @@ -53,6 +57,10 @@ %% ------D o w n g r a d e --------------------------------------------------- [ + {"4.19", + [ + ] + }, {"4.18", [ {load_module, snmp_misc, soft_purge, soft_purge, []}, diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index e70c97dcb8..29228fc59b 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -17,6 +17,6 @@ # # %CopyrightEnd% -SNMP_VSN = 4.19 +SNMP_VSN = 4.20 PRE_VSN = APP_VSN = "snmp-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From ed30d7b09dbdc23be7facd602a07f5a373da565e Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 9 Mar 2011 17:45:53 +0100 Subject: Added handling of muiltiple engine-id(s). --- lib/snmp/src/agent/snmp_community_mib.erl | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmp_community_mib.erl b/lib/snmp/src/agent/snmp_community_mib.erl index 5644a43345..3debe0a30e 100644 --- a/lib/snmp/src/agent/snmp_community_mib.erl +++ b/lib/snmp/src/agent/snmp_community_mib.erl @@ -25,7 +25,7 @@ snmpTargetAddrExtTable/3, community2vacm/2, vacm2community/2, get_target_addr_ext_mms/2]). --export([add_community/5, delete_community/1]). +-export([add_community/5, add_community/6, delete_community/1]). -export([check_community/1]). -include("SNMP-COMMUNITY-MIB.hrl"). @@ -128,12 +128,16 @@ read_community_config_files(Dir) -> Comms. check_community({Index, CommunityName, SecName, CtxName, TransportTag}) -> + EngineID = get_engine_id(), + check_community({Index, CommunityName, SecName, + EngineID, CtxName, TransportTag}); +check_community({Index, CommunityName, SecName, + EngineID, CtxName, TransportTag}) -> snmp_conf:check_string(Index,{gt,0}), snmp_conf:check_string(CommunityName), snmp_conf:check_string(SecName), snmp_conf:check_string(CtxName), snmp_conf:check_string(TransportTag), - EngineID = get_engine_id(), Comm = {Index, CommunityName, SecName, EngineID, CtxName, TransportTag, ?'StorageType_nonVolatile', ?'RowStatus_active'}, {ok, Comm}; @@ -173,6 +177,13 @@ table_del_row(Tab, Key) -> %% FIXME: does not work with mnesia add_community(Idx, CommName, SecName, CtxName, TransportTag) -> Community = {Idx, CommName, SecName, CtxName, TransportTag}, + do_add_community(Community). + +add_community(Idx, CommName, SecName, EngineId, CtxName, TransportTag) -> + Community = {Idx, CommName, SecName, EngineId, CtxName, TransportTag}, + do_add_community(Community). + +do_add_community(Community) -> case (catch check_community(Community)) of {ok, Row} -> Key = element(1, Row), -- cgit v1.2.3 From 143cc965e88ea2486c1e6b804f2ae033e870de2d Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 10 Mar 2011 18:16:33 +0100 Subject: Added export of snmp_target_mib:add_addr/11. --- lib/snmp/src/agent/snmp_target_mib.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmp_target_mib.erl b/lib/snmp/src/agent/snmp_target_mib.erl index a2820269d0..b2f2417b02 100644 --- a/lib/snmp/src/agent/snmp_target_mib.erl +++ b/lib/snmp/src/agent/snmp_target_mib.erl @@ -26,7 +26,7 @@ snmpTargetParamsTable/1, snmpTargetParamsTable/3, get_target_addrs/0, get_target_engine_id/1, set_target_engine_id/2, is_valid_tag/3, get/3, table_next/2]). --export([add_addr/10, delete_addr/1, +-export([add_addr/10, add_addr/11, delete_addr/1, add_params/5, delete_params/1]). -export([check_target_addr/1, check_target_params/1]). -export([default_domain/0]). -- cgit v1.2.3 From b1fa2355c461fd0feb11a41d4424594f5590373a Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 25 Mar 2011 21:39:03 +0100 Subject: Checking an taddress with domain snmpUDPDomain giv as a OID not handled. --- lib/snmp/src/misc/snmp_conf.erl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index 4fffb0fe38..cb5b3bbfbd 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -402,9 +402,13 @@ mk_tdomain(BadDomain) -> check_taddress(X) -> check_taddress(snmpUDPDomain, X). +check_taddress(?snmpUDPDomain, X) -> + check_taddress(transportDomainUdpIpv4, X); check_taddress(snmpUDPDomain, X) -> check_taddress(transportDomainUdpIpv4, X); +check_taddress(?transportDomainUdpIpv4, X) -> + check_taddress(transportDomainUdpIpv4, X); check_taddress(transportDomainUdpIpv4, X) when is_list(X) andalso (length(X) =:= 6) -> case (catch all_integer(X)) of @@ -415,9 +419,9 @@ check_taddress(transportDomainUdpIpv4, X) end; check_taddress(transportDomainUdpIpv4, X) -> error({invalid_taddress, X}); -check_taddress(?transportDomainUdpIpv4, X) -> - check_taddress(transportDomainUdpIpv4, X); +check_taddress(?transportDomainUdpIpv6, X) -> + check_taddress(transportDomainUdpIpv6, X); check_taddress(transportDomainUdpIpv6, X) when is_list(X) andalso (length(X) =:= 10) -> case (catch all_integer(X)) of @@ -428,8 +432,6 @@ check_taddress(transportDomainUdpIpv6, X) end; check_taddress(transportDomainUdpIpv6, X) -> error({invalid_taddress, X}); -check_taddress(?transportDomainUdpIpv6, X) -> - check_taddress(transportDomainUdpIpv6, X); check_taddress(BadDomain, _X) -> error({invalid_tdomain, BadDomain}). -- cgit v1.2.3 From 5f4c56191dd2ff41768b3ac2873a61da934298fc Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 28 Mar 2011 18:29:04 +0200 Subject: Cosmetic prep for handling of domains in the config tool. --- lib/snmp/src/misc/snmp_config.erl | 17 +++++++++++++++-- lib/snmp/src/misc/snmp_misc.erl | 9 +++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index 91a6550b0a..813942225e 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -491,6 +491,9 @@ config_agent_snmp(Dir, Vsns) -> Host = host(), AgentIP = ask("5. IP address for the agent (only used as id ~n" " when sending traps)", Host, fun verify_address/1), + %% We intentionally skip TDomain... + %% If the user wish to use IPv6, the user must create an dummy entry here + %% and then manually edit these entries later. ManagerIP = ask("6. IP address for the manager (only this manager ~n" " will have access to the agent, traps are sent ~n" " to this one)", Host, fun verify_address/1), @@ -1062,9 +1065,19 @@ verify_sec_type(ST) -> {error, "invalid security type: " ++ ST}. verify_address(A) -> - case (catch snmp_misc:ip(A)) of + verify_address(A, snmpUDPDomain). + +verify_address(A, snmpUDPDomain = _Domain) -> + do_verify_address(A, inet); +verify_address(A, transportDomainUdpIpv4 = _Domain) -> + do_verify_address(A, inet); +verify_address(A, transportDomainUdpIpv6 = _Domain) -> + do_verify_address(A, inet6). + +do_verify_address(A, Family) -> + case (catch snmp_misc:ip(A, Family)) of {ok, IP} -> - {ok, tuple_to_list(IP)}; + {ok, tuple_to_list(IP)}; {error, _} -> {error, "invalid address: " ++ A}; _E -> diff --git a/lib/snmp/src/misc/snmp_misc.erl b/lib/snmp/src/misc/snmp_misc.erl index 1b535743a4..2dce76992b 100644 --- a/lib/snmp/src/misc/snmp_misc.erl +++ b/lib/snmp/src/misc/snmp_misc.erl @@ -347,10 +347,15 @@ bits_to_int([Kibble|Ks],Kibbles,Res) -> %%---------------------------------------------------------------------- -%% Returns: {ok, {int(),int(),int(),int()}} | {error, Reason} +%% Returns: {ok, {int(),int(),int(),int()}} | +%% {ok, {int(),int(),int(),int()},int(),int(),int(),int()} | +%% {error, Reason} %%---------------------------------------------------------------------- ip(Host) -> - inet:getaddr(Host, inet). + ip(Host, inet). + +ip(Host, Family) -> + inet:getaddr(Host, Family). ensure_trailing_dir_delimiter([]) -> "/"; ensure_trailing_dir_delimiter(DirSuggestion) -> -- cgit v1.2.3 From 7e9ed39a425c3869f74dd69e6d3f48cf38a95f41 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 28 Mar 2011 18:37:05 +0200 Subject: Updated the appup also... --- lib/snmp/src/app/snmp.appup.src | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/snmp') diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index b8aea85cbe..db2b3ededb 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -25,6 +25,7 @@ {"4.19", [ {load_module, snmp_conf, soft_purge, soft_purge, []}, + {load_module, snmp_misc, soft_purge, soft_purge, []}, {load_module, snmp_config, soft_purge, soft_purge, []}, {load_module, snmpa_mpd, soft_purge, soft_purge, [snmp_conf]}, {load_module, snmpa_trap, soft_purge, soft_purge, @@ -94,6 +95,7 @@ {"4.19", [ {load_module, snmp_conf, soft_purge, soft_purge, []}, + {load_module, snmp_misc, soft_purge, soft_purge, []}, {load_module, snmp_config, soft_purge, soft_purge, []}, {load_module, snmpa_mpd, soft_purge, soft_purge, [snmp_conf]}, {load_module, snmpa_trap, soft_purge, soft_purge, -- cgit v1.2.3 From 49737813349f164b35737eb3cd59491930128f58 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 31 Mar 2011 17:46:17 +0200 Subject: Deprecated old manager API (set and get) request functions. --- lib/snmp/doc/src/notes.xml | 46 ++++++++++++++ lib/snmp/src/app/snmp.appup.src | 12 ++++ lib/snmp/src/manager/snmpm.erl | 135 +++++++++++----------------------------- lib/snmp/vsn.mk | 2 +- 4 files changed, 96 insertions(+), 99 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 2efeb8ae3f..87dcd46725 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -32,6 +32,52 @@ notes.xml

+
+ SNMP Development Toolkit 4.20 +

Version 4.20 supports code replacement in runtime from/to + version 4.19 and 4.18.

+ +
+ Improvements and new features + + + +

[manager] The old API functions (for get and set + requests) are now officially deprecated. + They will be removed as of R16B.

+

Own Id: OTP-9174

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

-

+ +
+ + +
+ Incompatibilities +

-

+
+ +
+
SNMP Development Toolkit 4.19

Version 4.19 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 de0e5d6e14..4e86e12465 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -22,8 +22,14 @@ %% ----- U p g r a d e ------------------------------------------------------- [ + {"4.19", + [ + {load_module, snmpm, soft_purge, soft_purge, []} + ] + }, {"4.18", [ + {load_module, snmpm, soft_purge, soft_purge, []}, {load_module, snmp_misc, soft_purge, soft_purge, []}, {load_module, snmpa_vacm, soft_purge, soft_purge, []}, {load_module, snmpa, soft_purge, soft_purge, @@ -53,8 +59,14 @@ %% ------D o w n g r a d e --------------------------------------------------- [ + {"4.19", + [ + {load_module, snmpm, soft_purge, soft_purge, []} + ] + }, {"4.18", [ + {load_module, snmpm, soft_purge, soft_purge, []}, {load_module, snmp_misc, soft_purge, soft_purge, []}, {load_module, snmpa_vacm, soft_purge, soft_purge, []}, {load_module, snmpa, soft_purge, soft_purge, diff --git a/lib/snmp/src/manager/snmpm.erl b/lib/snmp/src/manager/snmpm.erl index 5b6321b4c3..36b4901e9a 100644 --- a/lib/snmp/src/manager/snmpm.erl +++ b/lib/snmp/src/manager/snmpm.erl @@ -92,6 +92,43 @@ -export([format_reason/1, format_reason/2]). %% Backward compatibillity exports +-deprecated({agent_info, 3}). +-deprecated({update_agent_info, 5}). +-deprecated({g, 3}). +-deprecated({g, 4}). +-deprecated({g, 5}). +-deprecated({g, 6}). +-deprecated({g, 7}). +-deprecated({ag, 3}). +-deprecated({ag, 4}). +-deprecated({ag, 5}). +-deprecated({ag, 6}). +-deprecated({ag, 7}). +-deprecated({gn, 3}). +-deprecated({gn, 4}). +-deprecated({gn, 5}). +-deprecated({gn, 6}). +-deprecated({gn, 7}). +-deprecated({agn, 3}). +-deprecated({agn, 4}). +-deprecated({agn, 5}). +-deprecated({agn, 6}). +-deprecated({agn, 7}). +-deprecated({gb, 5}). +-deprecated({gb, 6}). +-deprecated({gb, 7}). +-deprecated({gb, 8}). +-deprecated({gb, 9}). +-deprecated({s, 3}). +-deprecated({s, 4}). +-deprecated({s, 5}). +-deprecated({s, 6}). +-deprecated({s, 7}). +-deprecated({as, 3}). +-deprecated({as, 4}). +-deprecated({as, 5}). +-deprecated({as, 6}). +-deprecated({as, 7}). -export([ agent_info/3, update_agent_info/5, g/3, g/4, g/5, g/6, g/7, @@ -393,24 +430,12 @@ agent_info(Addr, Port, Item) -> end. update_agent_info(UserId, TargetName, Item, Val) -> -%% p("update_agent_info -> entry with" -%% "~n UserId: ~p" -%% "~n TargetName: ~p" -%% "~n Item: ~p" -%% "~n Val: ~p", [UserId, TargetName, Item, Val]), snmpm_config:update_agent_info(UserId, TargetName, Item, Val). %% Backward compatibillity functions update_agent_info(UserId, Addr, Port, Item, Val) -> -%% p("update_agent_info -> entry with" -%% "~n UserId: ~p" -%% "~n Addr: ~p" -%% "~n Port: ~p" -%% "~n Item: ~p" -%% "~n Val: ~p", [UserId, Addr, Port, Item, Val]), case target_name(Addr, Port) of {ok, TargetName} -> -%% p("update_agent_info -> TargetName: ~p", [TargetName]), update_agent_info(UserId, TargetName, Item, Val); Error -> Error @@ -473,93 +498,39 @@ which_usm_users(EngineID) when is_list(EngineID) -> %% sync_get(UserId, TargetName, Oids) -> -%% p("sync_get -> entry with" -%% "~n UserId: ~p" -%% "~n TargetName: ~p" -%% "~n Oids: ~p", [UserId, TargetName, Oids]), sync_get(UserId, TargetName, ?DEFAULT_CONTEXT, Oids). sync_get(UserId, TargetName, Context, Oids) when is_list(Oids) -> -%% p("sync_get -> entry with" -%% "~n UserId: ~p" -%% "~n TargetName: ~p" -%% "~n Context: ~p" -%% "~n Oids: ~p", [UserId, TargetName, Context, Oids]), snmpm_server:sync_get(UserId, TargetName, Context, Oids); sync_get(UserId, TargetName, Oids, Timeout) when is_integer(Timeout) -> -%% p("sync_get -> entry with" -%% "~n UserId: ~p" -%% "~n TargetName: ~p" -%% "~n Oids: ~p" -%% "~n Timeout: ~p", [UserId, TargetName, Oids, Timeout]), sync_get(UserId, TargetName, ?DEFAULT_CONTEXT, Oids, Timeout). sync_get(UserId, TargetName, Context, Oids, Timeout) -> -%% p("sync_get -> entry with" -%% "~n UserId: ~p" -%% "~n TargetName: ~p" -%% "~n Context: ~p" -%% "~n Oids: ~p" -%% "~n Timeout: ~p", [UserId, TargetName, Context, Oids, Timeout]), snmpm_server:sync_get(UserId, TargetName, Context, Oids, Timeout). sync_get(UserId, TargetName, Context, Oids, Timeout, ExtraInfo) -> -%% p("sync_get -> entry with" -%% "~n UserId: ~p" -%% "~n TargetName: ~p" -%% "~n Context: ~p" -%% "~n Oids: ~p" -%% "~n Timeout: ~p" -%% "~n ExtraInfo: ~p", -%% [UserId, TargetName, Context, Oids, Timeout, ExtraInfo]), snmpm_server:sync_get(UserId, TargetName, Context, Oids, Timeout, ExtraInfo). g(UserId, Addr, Oids) -> -%% p("g -> entry with" -%% "~n UserId: ~p" -%% "~n Addr: ~p" -%% "~n Oids: ~p", [UserId, Addr, Oids]), g(UserId, Addr, ?DEFAULT_AGENT_PORT, Oids). g(UserId, Addr, CtxName, Oids) when is_list(CtxName) andalso is_list(Oids) -> -%% p("g -> entry with" -%% "~n UserId: ~p" -%% "~n Addr: ~p" -%% "~n CtxName: ~p" -%% "~n Oids: ~p", [UserId, Addr, CtxName, Oids]), g(UserId, Addr, ?DEFAULT_AGENT_PORT, CtxName, Oids); g(UserId, Addr, Port, Oids) when is_integer(Port) andalso is_list(Oids) -> -%% p("g -> entry with" -%% "~n UserId: ~p" -%% "~n Addr: ~p" -%% "~n Port: ~p" -%% "~n Oids: ~p", [UserId, Addr, Port, Oids]), g(UserId, Addr, Port, ?DEFAULT_CONTEXT, Oids); g(UserId, Addr, Oids, Timeout) when is_list(Oids) andalso is_integer(Timeout) -> -%% p("g -> entry with" -%% "~n UserId: ~p" -%% "~n Addr: ~p" -%% "~n Oids: ~p" -%% "~n Timeout: ~p", [UserId, Addr, Oids, Timeout]), g(UserId, Addr, ?DEFAULT_AGENT_PORT, Oids, Timeout). g(UserId, Addr, Port, CtxName, Oids) when is_integer(Port) andalso is_list(CtxName) andalso is_list(Oids) -> -%% p("g -> entry with" -%% "~n UserId: ~p" -%% "~n Addr: ~p" -%% "~n Port: ~p" -%% "~n Context: ~p" -%% "~n Oids: ~p", [UserId, Addr, Port, CtxName, Oids]), case target_name(Addr, Port) of {ok, TargetName} -> -%% p("g -> TargetName: ~p", [TargetName]), sync_get(UserId, TargetName, CtxName, Oids); Error -> Error @@ -567,55 +538,23 @@ g(UserId, Addr, Port, CtxName, Oids) g(UserId, Addr, Port, Oids, Timeout) when is_integer(Port) andalso is_list(Oids) andalso is_integer(Timeout) -> -%% p("g -> entry with" -%% "~n UserId: ~p" -%% "~n Addr: ~p" -%% "~n Oids: ~p" -%% "~n Timeout: ~p", -%% [UserId, Addr, Oids, Timeout]), g(UserId, Addr, Port, ?DEFAULT_CONTEXT, Oids, Timeout); g(UserId, Addr, CtxName, Oids, Timeout) when is_list(CtxName) andalso is_list(Oids) andalso is_integer(Timeout) -> -%% p("g -> entry with" -%% "~n UserId: ~p" -%% "~n Addr: ~p" -%% "~n CtxName: ~p" -%% "~n Oids: ~p" -%% "~n Timeout: ~p", -%% [UserId, Addr, CtxName, Oids, Timeout]), g(UserId, Addr, ?DEFAULT_AGENT_PORT, CtxName, Oids, Timeout). g(UserId, Addr, Port, CtxName, Oids, Timeout) -> -%% p("g -> entry with" -%% "~n UserId: ~p" -%% "~n Addr: ~p" -%% "~n Port: ~p" -%% "~n CtxName: ~p" -%% "~n Oids: ~p" -%% "~n Timeout: ~p", -%% [UserId, Addr, Port, CtxName, Oids, Timeout]), case target_name(Addr, Port) of {ok, TargetName} -> -%% p("g -> TargetName: ~p", [TargetName]), sync_get(UserId, TargetName, CtxName, Oids, Timeout); Error -> Error end. g(UserId, Addr, Port, CtxName, Oids, Timeout, ExtraInfo) -> -%% p("g -> entry with" -%% "~n UserId: ~p" -%% "~n Addr: ~p" -%% "~n Port: ~p" -%% "~n CtxName: ~p" -%% "~n Oids: ~p" -%% "~n Timeout: ~p" -%% "~n ExtraInfo: ~p", -%% [UserId, Addr, Port, CtxName, Oids, Timeout, ExtraInfo]), case target_name(Addr, Port) of {ok, TargetName} -> -%% p("g -> TargetName: ~p", [TargetName]), sync_get(UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo); Error -> Error diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index e70c97dcb8..29228fc59b 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -17,6 +17,6 @@ # # %CopyrightEnd% -SNMP_VSN = 4.19 +SNMP_VSN = 4.20 PRE_VSN = APP_VSN = "snmp-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From 51e89f67ba97074ec87275d50021749a18d004e9 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 1 Apr 2011 12:09:26 +0200 Subject: Added export of new (ip-) verification function. --- lib/snmp/src/misc/snmp_misc.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/misc/snmp_misc.erl b/lib/snmp/src/misc/snmp_misc.erl index 2dce76992b..6adef06ab9 100644 --- a/lib/snmp/src/misc/snmp_misc.erl +++ b/lib/snmp/src/misc/snmp_misc.erl @@ -40,7 +40,7 @@ get_option/2, get_option/3, get_sec_level/1, - ip/1, + ip/1, ip/2, is_auth/1, is_BitString/1, is_oid/1, -- cgit v1.2.3 From 7354ffb0e5cde599fcad776febd33cdb234f30a7 Mon Sep 17 00:00:00 2001 From: Kostis Sagonas Date: Sun, 3 Apr 2011 19:10:06 +0300 Subject: Add specs for functions that do not return --- lib/snmp/src/agent/snmpa_usm.erl | 17 +++++++---------- lib/snmp/src/manager/snmpm_usm.erl | 5 +++++ 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa_usm.erl b/lib/snmp/src/agent/snmpa_usm.erl index f35d1f1916..6f54307f9f 100644 --- a/lib/snmp/src/agent/snmpa_usm.erl +++ b/lib/snmp/src/agent/snmpa_usm.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1999-2010. All Rights Reserved. +%% Copyright Ericsson AB 1999-2011. 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 @@ -330,7 +330,6 @@ non_authoritative(SecName, end end. - is_auth(?usmNoAuthProtocol, _, _, _, SecName, _, _, _, _) -> % 3.2.5 error(usmStatsUnsupportedSecLevels, ?usmStatsUnsupportedSecLevels_instance, SecName); % OTP-5464 @@ -613,8 +612,7 @@ authenticate_outgoing(Message, UsmSecParams, end, ?vtrace("authenticate_outgoing -> encode message only",[]), snmp_pdus:enc_message_only(Message2). - - + %%----------------------------------------------------------------- %% Auth and priv algorithms @@ -753,14 +751,19 @@ set_engine_latest_time(SnmpEngineID, EngineTime) -> %%----------------------------------------------------------------- %% Utility functions %%----------------------------------------------------------------- +-spec error(term()) -> no_return(). error(Reason) -> throw({error, Reason}). +-spec error(term(), term()) -> no_return(). error(Reason, ErrorInfo) -> throw({error, Reason, ErrorInfo}). +-spec error(term(), term(), term()) -> no_return(). error(Variable, Oid, SecName) -> error(Variable, Oid, SecName, []). + +-spec error(term(), term(), term(), [term()]) -> no_return(). error(Variable, Oid, SecName, Opts) -> Val = inc(Variable), ErrorInfo = {#varbind{oid = Oid, @@ -772,7 +775,6 @@ error(Variable, Oid, SecName, Opts) -> inc(Name) -> ets:update_counter(snmp_agent_table, Name, 1). - get_counter(Name) -> case (catch ets:lookup(snmp_agent_table, Name)) of [{_, Val}] -> @@ -780,8 +782,3 @@ get_counter(Name) -> _ -> 0 end. - - - - - diff --git a/lib/snmp/src/manager/snmpm_usm.erl b/lib/snmp/src/manager/snmpm_usm.erl index 449127844a..ef2070a90e 100644 --- a/lib/snmp/src/manager/snmpm_usm.erl +++ b/lib/snmp/src/manager/snmpm_usm.erl @@ -476,14 +476,19 @@ set_engine_latest_time(SnmpEngineID, EngineTime) -> %%----------------------------------------------------------------- %% Utility functions %%----------------------------------------------------------------- +-spec error(term()) -> no_return(). error(Reason) -> throw({error, Reason}). +-spec error(term(), term()) -> no_return(). error(Reason, ErrorInfo) -> throw({error, Reason, ErrorInfo}). +-spec error(term(), term(), term()) -> no_return(). error(Variable, Oid, SecName) -> error(Variable, Oid, SecName, []). + +-spec error(term(), term(), term(), [term()]) -> no_return(). error(Variable, Oid, SecName, Opts) -> Val = inc(Variable), ErrorInfo = {#varbind{oid = Oid, -- cgit v1.2.3 From 245061870d1be138819c5a3df235da8faef90899 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 4 Apr 2011 16:09:50 +0200 Subject: Added extra-info as an argument to be provided when sending trap/notification and passed through to the net-if process. First version. --- lib/snmp/src/agent/snmpa.erl | 72 +++++++-- lib/snmp/src/agent/snmpa_agent.erl | 295 ++++++++++++++++++++++++++++------ lib/snmp/src/agent/snmpa_internal.hrl | 1 + lib/snmp/src/agent/snmpa_net_if.erl | 18 +++ lib/snmp/src/agent/snmpa_trap.erl | 140 +++++++++------- 5 files changed, 415 insertions(+), 111 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa.erl b/lib/snmp/src/agent/snmpa.erl index 22fbd33add..4cdc9d0064 100644 --- a/lib/snmp/src/agent/snmpa.erl +++ b/lib/snmp/src/agent/snmpa.erl @@ -108,8 +108,9 @@ -export([print_mib_info/0, print_mib_tables/0, print_mib_variables/0]). -include("snmpa_atl.hrl"). +-include("snmpa_internal.hrl"). --define(EXTRA_INFO, undefined). +-define(DISCO_EXTRA_INFO, undefined). %%----------------------------------------------------------------- @@ -596,22 +597,67 @@ set_request_limit(Agent, NewLimit) -> %% - +send_notification2(Agent, Notification, SendOpts) -> + snmpa_agent:send_notification(Agent, Notification, SendOpts). + +send_notification(Agent, Notification) -> + SendOpts = + [ + {receiver, no_receiver}, + {varbinds, []}, + {name, ""}, + {context, ""}, + {extra, ?DEFAULT_NOTIF_EXTRA_INFO} + ], + send_notification2(Agent, Notification, SendOpts). + send_notification(Agent, Notification, Recv) -> - send_notification(Agent, Notification, Recv, "", "", []). + SendOpts = + [ + {receiver, Recv}, + {varbinds, []}, + {name, ""}, + {context, ""}, + {extra, ?DEFAULT_NOTIF_EXTRA_INFO} + ], + send_notification2(Agent, Notification, SendOpts). send_notification(Agent, Notification, Recv, Varbinds) -> - send_notification(Agent, Notification, Recv, "", "", Varbinds). + SendOpts = + [ + {receiver, Recv}, + {varbinds, Varbinds}, + {name, ""}, + {context, ""}, + {extra, ?DEFAULT_NOTIF_EXTRA_INFO} + ], + send_notification2(Agent, Notification, SendOpts). send_notification(Agent, Notification, Recv, NotifyName, Varbinds) -> - send_notification(Agent, Notification, Recv, NotifyName, "", Varbinds). + SendOpts = + [ + {receiver, Recv}, + {varbinds, Varbinds}, + {name, NotifyName}, + {context, ""}, + {extra, ?DEFAULT_NOTIF_EXTRA_INFO} + ], + send_notification2(Agent, Notification, SendOpts). send_notification(Agent, Notification, Recv, NotifyName, ContextName, Varbinds) when (is_list(NotifyName) andalso is_list(ContextName) andalso is_list(Varbinds)) -> - snmpa_agent:send_trap(Agent, Notification, NotifyName, - ContextName, Recv, Varbinds). + SendOpts = + [ + {receiver, Recv}, + {varbinds, Varbinds}, + {name, NotifyName}, + {context, ContextName}, + {extra, ?DEFAULT_NOTIF_EXTRA_INFO} + ], + send_notification2(Agent, Notification, SendOpts). send_notification(Agent, Notification, Recv, NotifyName, ContextName, Varbinds, LocalEngineID) @@ -619,8 +665,16 @@ send_notification(Agent, Notification, Recv, is_list(ContextName) andalso is_list(Varbinds) andalso is_list(LocalEngineID)) -> - snmpa_agent:send_trap(Agent, Notification, NotifyName, - ContextName, Recv, Varbinds, LocalEngineID). + SendOpts = + [ + {receiver, Recv}, + {varbinds, Varbinds}, + {name, NotifyName}, + {context, ContextName}, + {extra, ?DEFAULT_NOTIF_EXTRA_INFO}, + {local_enging_id, LocalEngineID} + ], + send_notification2(Agent, Notification, SendOpts). %% Kept for backwards compatibility send_trap(Agent, Trap, Community) -> @@ -655,7 +709,7 @@ discovery(TargetName, Notification, Varbinds, DiscoHandler) discovery(TargetName, Notification, ContextName, Varbinds, DiscoHandler). discovery(TargetName, Notification, ContextName, Varbinds, DiscoHandler) -> - ExtraInfo = ?EXTRA_INFO, + ExtraInfo = ?DISCO_EXTRA_INFO, discovery(TargetName, Notification, ContextName, Varbinds, DiscoHandler, ExtraInfo). diff --git a/lib/snmp/src/agent/snmpa_agent.erl b/lib/snmp/src/agent/snmpa_agent.erl index d9a0438b56..0a28e753ce 100644 --- a/lib/snmp/src/agent/snmpa_agent.erl +++ b/lib/snmp/src/agent/snmpa_agent.erl @@ -30,7 +30,7 @@ -export([subagent_set/2, load_mibs/2, unload_mibs/2, which_mibs/1, whereis_mib/2, info/1, register_subagent/3, unregister_subagent/2, - send_trap/6, send_trap/7, + send_notification/3, register_notification_filter/5, unregister_notification_filter/2, which_notification_filter/1, @@ -62,10 +62,16 @@ -export([increment_counter/3]). -export([restart_worker/1, restart_set_worker/1]). +%% For backward compatibillity +-export([send_trap/6, send_trap/7]). + %% Internal exports -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3, tr_var/2, tr_varbind/1, - handle_pdu/7, worker/2, worker_loop/1, do_send_trap/7]). + handle_pdu/7, worker/2, worker_loop/1, + do_send_trap/7, do_send_trap/8]). + +-include("snmpa_internal.hrl"). -ifndef(default_verbosity). -define(default_verbosity,silence). @@ -527,6 +533,11 @@ which_notification_filter(Agent) -> call(Agent, which_notification_filter). +send_notification(Agent, Notification, SendOpts) -> + Msg = {send_notif, Notification, SendOpts}, + maybe_call(Agent, Msg). + +%% send_trap(Agent, Trap, NotifyName, CtxName, Recv, Varbinds) -> ?d("send_trap -> entry with" "~n self(): ~p" @@ -538,13 +549,33 @@ send_trap(Agent, Trap, NotifyName, CtxName, Recv, Varbinds) -> "~n Varbinds: ~p", [self(), Agent, wis(Agent), Trap, NotifyName, CtxName, Recv, Varbinds]), - Msg = {send_trap, Trap, NotifyName, CtxName, Recv, Varbinds}, - case (wis(Agent) =:= self()) of - false -> - call(Agent, Msg); - true -> - Agent ! Msg - end. + SendOpts = [ + {receiver, Recv}, + {varbinds, Varbinds}, + {name, NotifyName}, + {context, CtxName}, + {extra, ?DEFAULT_NOTIF_EXTRA_INFO} + ], + send_notification(Agent, Trap, SendOpts). + +%% send_trap(Agent, Trap, NotifyName, CtxName, Recv, Varbinds) -> +%% ?d("send_trap -> entry with" +%% "~n self(): ~p" +%% "~n Agent: ~p [~p]" +%% "~n Trap: ~p" +%% "~n NotifyName: ~p" +%% "~n CtxName: ~p" +%% "~n Recv: ~p" +%% "~n Varbinds: ~p", +%% [self(), Agent, wis(Agent), +%% Trap, NotifyName, CtxName, Recv, Varbinds]), +%% Msg = {send_trap, Trap, NotifyName, CtxName, Recv, Varbinds}, +%% case (wis(Agent) =:= self()) of +%% false -> +%% call(Agent, Msg); +%% true -> +%% Agent ! Msg +%% end. send_trap(Agent, Trap, NotifyName, CtxName, Recv, Varbinds, LocalEngineID) -> ?d("send_trap -> entry with" @@ -558,14 +589,38 @@ send_trap(Agent, Trap, NotifyName, CtxName, Recv, Varbinds, LocalEngineID) -> "~n LocalEngineID: ~p", [self(), Agent, wis(Agent), Trap, NotifyName, CtxName, Recv, Varbinds, LocalEngineID]), - Msg = - {send_trap, Trap, NotifyName, CtxName, Recv, Varbinds, LocalEngineID}, - case (wis(Agent) =:= self()) of - false -> - call(Agent, Msg); - true -> - Agent ! Msg - end. + SendOpts = [ + {receiver, Recv}, + {varbinds, Varbinds}, + {name, NotifyName}, + {context, CtxName}, + {extra, ?DEFAULT_NOTIF_EXTRA_INFO}, + {local_engine_id, LocalEngineID} + ], + send_notification(Agent, Trap, SendOpts). + +%% send_trap(Agent, Trap, NotifyName, CtxName, Recv, Varbinds, LocalEngineID) -> +%% ?d("send_trap -> entry with" +%% "~n self(): ~p" +%% "~n Agent: ~p [~p]" +%% "~n Trap: ~p" +%% "~n NotifyName: ~p" +%% "~n CtxName: ~p" +%% "~n Recv: ~p" +%% "~n Varbinds: ~p" +%% "~n LocalEngineID: ~p", +%% [self(), Agent, wis(Agent), +%% Trap, NotifyName, CtxName, Recv, Varbinds, LocalEngineID]), +%% Msg = +%% {send_trap, Trap, NotifyName, CtxName, Recv, Varbinds, LocalEngineID}, +%% case (wis(Agent) =:= self()) of +%% false -> +%% call(Agent, Msg); +%% true -> +%% Agent ! Msg +%% end. + +%% %% -- Discovery functions -- @@ -655,7 +710,14 @@ wis(Atom) when is_atom(Atom) -> forward_trap(Agent, TrapRecord, NotifyName, CtxName, Recv, Varbinds) -> - Agent ! {forward_trap, TrapRecord, NotifyName, CtxName, Recv, Varbinds}. + ExtraInfo = ?DEFAULT_NOTIF_EXTRA_INFO, + forward_trap(Agent, TrapRecord, NotifyName, CtxName, Recv, Varbinds, + ExtraInfo). + +forward_trap(Agent, TrapRecord, NotifyName, CtxName, Recv, Varbinds, + ExtraInfo) -> + Agent ! {forward_trap, TrapRecord, NotifyName, CtxName, Recv, Varbinds, + ExtraInfo}. %%----------------------------------------------------------------- @@ -745,6 +807,22 @@ handle_info(worker_available, S) -> ?vdebug("worker available",[]), {noreply, S#state{worker_state = ready}}; +handle_info({send_notif, Notification, SendOpts}, S) -> + ?vlog("[handle_info] send trap request:" + "~n Notification: ~p" + "~n SendOpts: ~p", + [Notification, SendOpts]), + case (catch handle_send_trap(cast, S, Notification, SendOpts)) of + {ok, NewS} -> + {noreply, NewS}; + {'EXIT', R} -> + ?vinfo("Trap not sent:~n ~p", [R]), + {noreply, S}; + _ -> + {noreply, S} + end; + +%% handle_info({send_trap, Trap, NotifyName, ContextName, Recv, Varbinds}, S) -> ?vlog("[handle_info] send trap request:" "~n Trap: ~p" @@ -753,9 +831,10 @@ handle_info({send_trap, Trap, NotifyName, ContextName, Recv, Varbinds}, S) -> "~n Recv: ~p" "~n Varbinds: ~p", [Trap, NotifyName, ContextName, Recv, Varbinds]), + ExtraInfo = ?DEFAULT_NOTIF_EXTRA_INFO, LocalEngineID = ?DEFAULT_LOCAL_ENGINE_ID, case (catch handle_send_trap(S, Trap, NotifyName, ContextName, - Recv, Varbinds, LocalEngineID)) of + Recv, Varbinds, LocalEngineID, ExtraInfo)) of {ok, NewS} -> {noreply, NewS}; {'EXIT', R} -> @@ -775,8 +854,9 @@ handle_info({send_trap, Trap, NotifyName, ContextName, Recv, Varbinds, "~n Varbinds: ~p" "~n LocalEngineID: ~p", [Trap, NotifyName, ContextName, Recv, Varbinds, LocalEngineID]), + ExtraInfo = ?DEFAULT_NOTIF_EXTRA_INFO, case (catch handle_send_trap(S, Trap, NotifyName, ContextName, - Recv, Varbinds, LocalEngineID)) of + Recv, Varbinds, LocalEngineID, ExtraInfo)) of {ok, NewS} -> {noreply, NewS}; {'EXIT', R} -> @@ -785,7 +865,30 @@ handle_info({send_trap, Trap, NotifyName, ContextName, Recv, Varbinds, _ -> {noreply, S} end; +%% +handle_info({forward_trap, TrapRecord, NotifyName, ContextName, + Recv, Varbinds, ExtraInfo}, S) -> + ?vlog("[handle_info] forward trap request:" + "~n TrapRecord: ~p" + "~n NotifyName: ~p" + "~n ContextName: ~p" + "~n Recv: ~p" + "~n Varbinds: ~p", + [TrapRecord, NotifyName, ContextName, Recv, Varbinds]), + LocalEngineID = ?DEFAULT_LOCAL_ENGINE_ID, + case (catch maybe_send_trap(S, TrapRecord, NotifyName, ContextName, + Recv, Varbinds, LocalEngineID, ExtraInfo)) of + {ok, NewS} -> + {noreply, NewS}; + {'EXIT', R} -> + ?vinfo("Trap not sent:~n ~p", [R]), + {noreply, S}; + _ -> + {noreply, S} + end; + +%% handle_info({forward_trap, TrapRecord, NotifyName, ContextName, Recv, Varbinds}, S) -> ?vlog("[handle_info] forward trap request:" @@ -795,9 +898,10 @@ handle_info({forward_trap, TrapRecord, NotifyName, ContextName, "~n Recv: ~p" "~n Varbinds: ~p", [TrapRecord, NotifyName, ContextName, Recv, Varbinds]), + ExtraInfo = ?DEFAULT_NOTIF_EXTRA_INFO, LocalEngineID = ?DEFAULT_LOCAL_ENGINE_ID, case (catch maybe_send_trap(S, TrapRecord, NotifyName, ContextName, - Recv, Varbinds, LocalEngineID)) of + Recv, Varbinds, LocalEngineID, ExtraInfo)) of {ok, NewS} -> {noreply, NewS}; {'EXIT', R} -> @@ -806,6 +910,7 @@ handle_info({forward_trap, TrapRecord, NotifyName, ContextName, _ -> {noreply, S} end; +%% handle_info({backup_done, Reply}, #state{backup = {_, From}} = S) -> ?vlog("[handle_info] backup done:" @@ -908,6 +1013,23 @@ handle_call(restart_set_worker, _From, #state{set_worker = Pid} = S) -> end, {reply, ok, S}; +handle_call({send_notif, Notification, SendOpts}, _From, S) -> + ?vlog("[handle_info] send trap request:" + "~n Notification: ~p" + "~n SendOpts: ~p", + [Notification, SendOpts]), + case (catch handle_send_trap(call, S, Notification, SendOpts)) of + {ok, NewS} -> + {reply, ok, NewS}; + {'EXIT', Reason} -> + ?vinfo("Trap not sent:~n ~p", [Reason]), + {reply, {error, {send_failed, Reason}}, S}; + _ -> + ?vinfo("Trap not sent", []), + {reply, {error, send_failed}, S} + end; + +%% handle_call({send_trap, Trap, NotifyName, ContextName, Recv, Varbinds}, _From, S) -> ?vlog("[handle_call] send trap request:" @@ -917,6 +1039,7 @@ handle_call({send_trap, Trap, NotifyName, ContextName, Recv, Varbinds}, "~n Recv: ~p" "~n Varbinds: ~p", [Trap, NotifyName, ContextName, Recv, Varbinds]), + ExtraInfo = ?DEFAULT_NOTIF_EXTRA_INFO, LocalEngineID = case S#state.type of master_agent -> @@ -929,7 +1052,7 @@ handle_call({send_trap, Trap, NotifyName, ContextName, Recv, Varbinds}, ignore end, case (catch handle_send_trap(S, Trap, NotifyName, ContextName, - Recv, Varbinds, LocalEngineID)) of + Recv, Varbinds, LocalEngineID, ExtraInfo)) of {ok, NewS} -> {reply, ok, NewS}; {'EXIT', Reason} -> @@ -951,8 +1074,9 @@ handle_call({send_trap, Trap, NotifyName, "~n Varbinds: ~p" "~n LocalEngineID: ~p", [Trap, NotifyName, ContextName, Recv, Varbinds, LocalEngineID]), + ExtraInfo = ?DEFAULT_NOTIF_EXTRA_INFO, case (catch handle_send_trap(S, Trap, NotifyName, ContextName, - Recv, Varbinds, LocalEngineID)) of + Recv, Varbinds, LocalEngineID, ExtraInfo)) of {ok, NewS} -> {reply, ok, NewS}; {'EXIT', Reason} -> @@ -962,6 +1086,7 @@ handle_call({send_trap, Trap, NotifyName, ?vinfo("Trap not sent", []), {reply, {error, send_failed}, S} end; +%% handle_call({discovery, TargetName, Notification, ContextName, Vbs, DiscoHandler, @@ -1526,19 +1651,24 @@ spawn_thread(Vsn, Pdu, PduMS, ACMData, Address, Extra) -> proc_lib:spawn_link(?MODULE, handle_pdu, Args). spawn_trap_thread(TrapRec, NotifyName, ContextName, Recv, Vbs, - LocalEngineID) -> + LocalEngineID, ExtraInfo) -> Dict = get(), proc_lib:spawn_link(?MODULE, do_send_trap, [TrapRec, NotifyName, ContextName, - Recv, Vbs, LocalEngineID, Dict]). + Recv, Vbs, LocalEngineID, ExtraInfo, Dict]). do_send_trap(TrapRec, NotifyName, ContextName, Recv, Vbs, LocalEngineID, Dict) -> + ExtraInfo = ?DEFAULT_NOTIF_EXTRA_INFO, + do_send_trap(TrapRec, NotifyName, ContextName, Recv, Vbs, + LocalEngineID, ExtraInfo, Dict). +do_send_trap(TrapRec, NotifyName, ContextName, Recv, Vbs, + LocalEngineID, ExtraInfo, Dict) -> lists:foreach(fun({Key, Val}) -> put(Key, Val) end, Dict), put(sname,trap_sender_short_name(get(sname))), ?vlog("starting",[]), snmpa_trap:send_trap(TrapRec, NotifyName, ContextName, Recv, Vbs, - LocalEngineID, get(net_if)). + LocalEngineID, ExtraInfo, get(net_if)). worker(Master, Dict) -> lists:foreach(fun({Key, Val}) -> put(Key, Val) end, Dict), @@ -1553,21 +1683,34 @@ worker_loop(Master) -> handle_pdu(Vsn, Pdu, PduMS, ACMData, Address, Extra), Master ! worker_available; - %% We don't trap exits! + %% We don't trap EXITs! {TrapRec, NotifyName, ContextName, Recv, Vbs} -> ?vtrace("worker_loop -> send trap:" "~n ~p", [TrapRec]), snmpa_trap:send_trap(TrapRec, NotifyName, - ContextName, Recv, Vbs, get(net_if)), + ContextName, Recv, Vbs, + ?DEFAULT_NOTIF_EXTRA_INFO, + get(net_if)), Master ! worker_available; - %% We don't trap exits! + %% We don't trap EXITs! {send_trap, TrapRec, NotifyName, ContextName, Recv, Vbs, LocalEngineID} -> ?vtrace("worker_loop -> send trap:" "~n ~p", [TrapRec]), snmpa_trap:send_trap(TrapRec, NotifyName, - ContextName, Recv, Vbs, LocalEngineID, + ContextName, Recv, Vbs, + LocalEngineID, ?DEFAULT_NOTIF_EXTRA_INFO, + get(net_if)), + Master ! worker_available; + + {send_trap, + TrapRec, NotifyName, ContextName, Recv, Vbs, LocalEngineID, ExtraInfo} -> + ?vtrace("worker_loop -> send trap:" + "~n ~p", [TrapRec]), + snmpa_trap:send_trap(TrapRec, NotifyName, + ContextName, Recv, Vbs, + LocalEngineID, ExtraInfo, get(net_if)), Master ! worker_available; @@ -1716,34 +1859,79 @@ handle_acm_error(Vsn, Reason, Pdu, ACMData, Address, Extra) -> ok end. +get_opt(Key, Default, SendOpts) -> + case lists:keysearch(Key, 1, SendOpts) of + {value, {Key, Value}} -> + Value; + false -> + Default + end. -handle_send_trap(S, TrapName, NotifyName, ContextName, Recv, Varbinds, - LocalEngineID) -> +handle_send_trap(call, #state{type = master_agent} = S, + Notification, SendOpts) -> + SendOpts2 = + case lists:keymember(local_engine_id, 1, SendOpts) of + true -> + SendOpts; + false -> + [{local_engine_id, ?DEFAULT_LOCAL_ENGINE_ID}|SendOpts] + end, + handle_send_trap(S, Notification, SendOpts2); +handle_send_trap(call, S, Notification, SendOpts) -> + SendOpts2 = + case lists:keymember(local_engine_id, 1, SendOpts) of + true -> + SendOpts; + false -> + %% subagent - + %% we don't need this now, eventually the trap send + %% request will reach the master-agent and then it + %% will look up the proper engine id. + [{local_engine_id, ignore}|SendOpts] + end, + handle_send_trap(S, Notification, SendOpts2); +handle_send_trap(_, S, Notification, SendOpts) -> + handle_send_trap(S, Notification, SendOpts). + +handle_send_trap(S, Notification, SendOpts) -> + NotifyName = get_opt(name, "", SendOpts), + ContextName = get_opt(context, "", SendOpts), + Recv = get_opt(receiver, no_receiver, SendOpts), + Varbinds = get_opt(varbinds, [], SendOpts), + ExtraInfo = get_opt(extra, ?DEFAULT_NOTIF_EXTRA_INFO, SendOpts), + LocalEngineID = + get_opt(local_engine_id, ?DEFAULT_LOCAL_ENGINE_ID, SendOpts), + handle_send_trap(S, Notification, NotifyName, ContextName, Recv, Varbinds, + LocalEngineID, ExtraInfo). + +handle_send_trap(#state{type = Type} = S, + Notification, NotifyName, ContextName, Recv, Varbinds, + LocalEngineID, ExtraInfo) -> ?vtrace("handle_send_trap -> entry with" "~n Agent type: ~p" "~n TrapName: ~p" "~n NotifyName: ~p" "~n ContextName: ~p" "~n LocalEngineID: ~p", - [S#state.type, TrapName, NotifyName, ContextName, LocalEngineID]), - case snmpa_trap:construct_trap(TrapName, Varbinds) of + [Type, Notification, NotifyName, ContextName, LocalEngineID]), + case snmpa_trap:construct_trap(Notification, Varbinds) of {ok, TrapRecord, VarList} -> ?vtrace("handle_send_trap -> construction complete: " "~n TrapRecord: ~p" "~n VarList: ~p", [TrapRecord, VarList]), - case S#state.type of + case Type of subagent -> ?vtrace("handle_send_trap -> [sub] forward trap",[]), maybe_forward_trap(S, TrapRecord, NotifyName, - ContextName, Recv, VarList), + ContextName, Recv, VarList, ExtraInfo), {ok, S}; master_agent -> ?vtrace("handle_send_trap -> " "[master] handle send trap",[]), maybe_send_trap(S, TrapRecord, NotifyName, ContextName, Recv, VarList, - LocalEngineID) + LocalEngineID, ExtraInfo) end; error -> error @@ -1751,7 +1939,7 @@ handle_send_trap(S, TrapName, NotifyName, ContextName, Recv, Varbinds, maybe_forward_trap(#state{parent = Parent, nfilters = NFs} = S, - TrapRec, NotifyName, ContextName, Recv, V) -> + TrapRec, NotifyName, ContextName, Recv, V, ExtraInfo) -> ?vtrace("maybe_forward_trap -> entry with" "~n NFs: ~p", [NFs]), case filter_notification(NFs, [], TrapRec) of @@ -1767,13 +1955,15 @@ maybe_forward_trap(#state{parent = Parent, nfilters = NFs} = S, {send, [], TrapRec2} -> ?vtrace("maybe_forward_trap -> forward trap:" "~n ~p", [TrapRec2]), - forward_trap(Parent, TrapRec2, NotifyName, ContextName, Recv, V), + forward_trap(Parent, TrapRec2, NotifyName, ContextName, Recv, V, + ExtraInfo), {ok, S}; {send, Removed, TrapRec2} -> ?vtrace("maybe_forward_trap -> forward trap:" "~n ~p", [TrapRec2]), - forward_trap(Parent, TrapRec2, NotifyName, ContextName, Recv, V), + forward_trap(Parent, TrapRec2, NotifyName, ContextName, Recv, V, + ExtraInfo), NFs2 = del_notification_filter(Removed, NFs), {ok, S#state{nfilters = NFs2}} end. @@ -1781,7 +1971,7 @@ maybe_forward_trap(#state{parent = Parent, nfilters = NFs} = S, maybe_send_trap(#state{nfilters = NFs} = S, TrapRec, NotifyName, ContextName, Recv, Varbinds, - LocalEngineID) -> + LocalEngineID, ExtraInfo) -> ?vtrace("maybe_send_trap -> entry with" "~n NFs: ~p", [NFs]), case filter_notification(NFs, [], TrapRec) of @@ -1799,7 +1989,7 @@ maybe_send_trap(#state{nfilters = NFs} = S, "~n ~p", [TrapRec2]), do_handle_send_trap(S, TrapRec2, NotifyName, ContextName, Recv, Varbinds, - LocalEngineID); + LocalEngineID, ExtraInfo); {send, Removed, TrapRec2} -> ?vtrace("maybe_send_trap -> send trap:" @@ -1807,36 +1997,37 @@ maybe_send_trap(#state{nfilters = NFs} = S, NFs2 = del_notification_filter(Removed, NFs), do_handle_send_trap(S#state{nfilters = NFs2}, TrapRec2, NotifyName, ContextName, Recv, Varbinds, - LocalEngineID) + LocalEngineID, ExtraInfo) end. do_handle_send_trap(S, TrapRec, NotifyName, ContextName, Recv, Varbinds, - LocalEngineID) -> + LocalEngineID, ExtraInfo) -> Vbs = snmpa_trap:try_initialise_vars(get(mibserver), Varbinds), case S#state.type of subagent -> forward_trap(S#state.parent, TrapRec, NotifyName, ContextName, - Recv, Vbs), + Recv, Vbs, ExtraInfo), {ok, S}; master_agent when S#state.multi_threaded =:= false -> ?vtrace("do_handle_send_trap -> send trap:" "~n ~p", [TrapRec]), snmpa_trap:send_trap(TrapRec, NotifyName, ContextName, - Recv, Vbs, LocalEngineID, get(net_if)), + Recv, Vbs, LocalEngineID, ExtraInfo, + get(net_if)), {ok, S}; master_agent when S#state.worker_state =:= busy -> %% Main worker busy => create new worker ?vtrace("do_handle_send_trap -> main worker busy: " "spawn a trap sender", []), spawn_trap_thread(TrapRec, NotifyName, ContextName, Recv, Vbs, - LocalEngineID), + LocalEngineID, ExtraInfo), {ok, S}; master_agent -> %% Send to main worker ?vtrace("do_handle_send_trap -> send to main worker",[]), S#state.worker ! {send_trap, TrapRec, NotifyName, ContextName, Recv, Vbs, - LocalEngineID}, + LocalEngineID, ExtraInfo}, {ok, S#state{worker_state = busy}} end. @@ -3974,6 +4165,14 @@ user_err(F, A) -> %% --------------------------------------------------------------------- +maybe_call(Server, Req) -> + case (wis(Server) =:= self()) of + false -> + call(Server, Req); + true -> + Server ! Req + end. + call(Server, Req) -> gen_server:call(Server, Req, infinity). diff --git a/lib/snmp/src/agent/snmpa_internal.hrl b/lib/snmp/src/agent/snmpa_internal.hrl index 9fa874f119..fba800175b 100644 --- a/lib/snmp/src/agent/snmpa_internal.hrl +++ b/lib/snmp/src/agent/snmpa_internal.hrl @@ -23,6 +23,7 @@ -include_lib("snmp/src/app/snmp_internal.hrl"). -define(DEFAULT_LOCAL_ENGINE_ID, snmp_framework_mib:get_engine_id()). +-define(DEFAULT_NOTIF_EXTRA_INFO, undefined). -define(snmpa_info(F, A), ?snmp_info("agent", F, A)). -define(snmpa_warning(F, A), ?snmp_warning("agent", F, A)). diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index d4bb5bdf9f..bbc43c3da7 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -314,6 +314,14 @@ loop(S) -> NewS = maybe_handle_send_pdu(S, Vsn, Pdu, MsgData, To, undefined), loop(NewS); + %% We dont use the extra-info at this time, ... + {send_pdu, Vsn, Pdu, MsgData, To, _ExtraInfo} -> + ?vdebug("send pdu: " + "~n Pdu: ~p" + "~n To: ~p", [Pdu, To]), + NewS = maybe_handle_send_pdu(S, Vsn, Pdu, MsgData, To, undefined), + loop(NewS); + %% Informs {send_pdu_req, Vsn, Pdu, MsgData, To, From} -> ?vdebug("send pdu request: " @@ -324,6 +332,16 @@ loop(S) -> NewS = maybe_handle_send_pdu(S, Vsn, Pdu, MsgData, To, From), loop(NewS); + %% We dont use the extra-info at this time, ... + {send_pdu_req, Vsn, Pdu, MsgData, To, From, _ExtraInfo} -> + ?vdebug("send pdu request: " + "~n Pdu: ~p" + "~n To: ~p" + "~n From: ~p", + [Pdu, To, toname(From)]), + NewS = maybe_handle_send_pdu(S, Vsn, Pdu, MsgData, To, From), + loop(NewS); + %% Discovery Inform {send_discovery, Pdu, MsgData, To, From} -> ?vdebug("received send discovery request: " diff --git a/lib/snmp/src/agent/snmpa_trap.erl b/lib/snmp/src/agent/snmpa_trap.erl index 09ecb5228b..0f6a5f8984 100644 --- a/lib/snmp/src/agent/snmpa_trap.erl +++ b/lib/snmp/src/agent/snmpa_trap.erl @@ -24,12 +24,12 @@ %% External exports -export([construct_trap/2, try_initialise_vars/2, - send_trap/6, send_trap/7]). + send_trap/6, send_trap/7, send_trap/8]). -export([send_discovery/5]). %% Internal exports --export([init_v2_inform/9, - init_v3_inform/9, init_v3_inform/10, +-export([init_v2_inform/9, init_v2_inform/10, + init_v3_inform/9, init_v3_inform/10, init_v3_inform/11, send_inform/6]). -export([init_discovery_inform/12, send_discovery_inform/5]). @@ -46,6 +46,7 @@ -define(VMODULE,"TRAP"). -include("snmp_verbosity.hrl"). +-include("snmpa_internal.hrl"). %%----------------------------------------------------------------- @@ -336,20 +337,27 @@ make_varbind_list(Varbinds) -> %% SnmpTargetAddrTable (using the Tag). %%----------------------------------------------------------------- send_trap(TrapRec, NotifyName, ContextName, Recv, Vbs, NetIf) -> + ExtraInfo = ?DEFAULT_NOTIF_EXTRA_INFO, LocalEngineID = ?DEFAULT_LOCAL_ENGINE_ID, send_trap(TrapRec, NotifyName, ContextName, Recv, Vbs, - LocalEngineID, NetIf). + LocalEngineID, ExtraInfo, NetIf). -send_trap(TrapRec, NotifyName, ContextName, Recv, Vbs, LocalEngineID, NetIf) -> +send_trap(TrapRec, NotifyName, ContextName, Recv, Vbs, ExtraInfo, NetIf) -> + LocalEngineID = ?DEFAULT_LOCAL_ENGINE_ID, + send_trap(TrapRec, NotifyName, ContextName, Recv, Vbs, + LocalEngineID, ExtraInfo, NetIf). + +send_trap(TrapRec, NotifyName, ContextName, Recv, Vbs, LocalEngineID, + ExtraInfo, NetIf) -> (catch do_send_trap(TrapRec, NotifyName, ContextName, Recv, Vbs, - LocalEngineID, NetIf)). + LocalEngineID, ExtraInfo, NetIf)). do_send_trap(TrapRec, NotifyName, ContextName, Recv, Vbs, - LocalEngineID, NetIf) -> + LocalEngineID, ExtraInfo, NetIf) -> VarbindList = make_varbind_list(Vbs), Dests = find_dests(NotifyName), send_trap_pdus(Dests, ContextName, {TrapRec, VarbindList}, [], [], [], - Recv, LocalEngineID, NetIf). + Recv, LocalEngineID, ExtraInfo, NetIf). send_discovery(TargetName, Record, ContextName, Vbs, NetIf) -> case find_dest(TargetName) of @@ -635,7 +643,7 @@ send_trap_pdus([{DestAddr, TargetName, {MpModel, SecModel, SecName, SecLevel}, Type} | T], ContextName, {TrapRec, Vbs}, V1Res, V2Res, V3Res, Recv, - LocalEngineID, NetIf) -> + LocalEngineID, ExtraInfo, NetIf) -> ?vdebug("send trap pdus: " "~n Destination address: ~p" "~n Target name: ~p" @@ -661,13 +669,13 @@ send_trap_pdus([{DestAddr, TargetName, {MpModel, SecModel, SecName, SecLevel}, send_trap_pdus(T, ContextName, {TrapRec, Vbs}, [{DestAddr, Community} | V1Res], V2Res, V3Res, Recv, - LocalEngineID, NetIf); + LocalEngineID, ExtraInfo, NetIf); undefined -> ?vdebug("No community found for v1 dest: ~p", [element(2, DestAddr)]), send_trap_pdus(T, ContextName, {TrapRec, Vbs}, V1Res, V2Res, V3Res, Recv, - LocalEngineID, NetIf) + LocalEngineID, ExtraInfo, NetIf) end; true when MpModel =:= ?MP_V2C -> ?vtrace("send_trap_pdus -> v2c mp model",[]), @@ -682,13 +690,14 @@ send_trap_pdus([{DestAddr, TargetName, {MpModel, SecModel, SecName, SecLevel}, send_trap_pdus(T, ContextName, {TrapRec, Vbs}, V1Res, [{DestAddr, Community, Type}|V2Res], - V3Res, Recv, LocalEngineID, NetIf); + V3Res, Recv, + LocalEngineID, ExtraInfo, NetIf); undefined -> ?vdebug("No community found for v2c dest: ~p", [element(2, DestAddr)]), send_trap_pdus(T, ContextName, {TrapRec, Vbs}, V1Res, V2Res, V3Res, Recv, - LocalEngineID, NetIf) + LocalEngineID, ExtraInfo, NetIf) end; true when MpModel =:= ?MP_V3 -> ?vtrace("send_trap_pdus -> v3 mp model",[]), @@ -697,20 +706,20 @@ send_trap_pdus([{DestAddr, TargetName, {MpModel, SecModel, SecName, SecLevel}, send_trap_pdus(T, ContextName, {TrapRec, Vbs}, V1Res, V2Res, [{DestAddr, MsgData, Type} | V3Res], - Recv, LocalEngineID, NetIf); + Recv, LocalEngineID, ExtraInfo, NetIf); true -> ?vlog("bad MpModel ~p for dest ~p", [MpModel, element(2, DestAddr)]), send_trap_pdus(T, ContextName, {TrapRec, Vbs}, V1Res, V2Res, V3Res, Recv, - LocalEngineID, NetIf); + LocalEngineID, ExtraInfo, NetIf); _ -> ?vlog("no access for dest: " "~n ~p in target ~p", [element(2, DestAddr), TargetName]), send_trap_pdus(T, ContextName, {TrapRec, Vbs}, V1Res, V2Res, V3Res, Recv, - LocalEngineID, NetIf) + LocalEngineID, ExtraInfo, NetIf) end; {discarded, Reason} -> ?vlog("mib view error ~p for" @@ -718,24 +727,27 @@ send_trap_pdus([{DestAddr, TargetName, {MpModel, SecModel, SecName, SecLevel}, "~n SecName: ~w", [Reason, element(2, DestAddr), SecName]), send_trap_pdus(T, ContextName, {TrapRec, Vbs}, - V1Res, V2Res, V3Res, Recv, LocalEngineID, NetIf) + V1Res, V2Res, V3Res, Recv, + LocalEngineID, ExtraInfo, NetIf) end; -send_trap_pdus([], ContextName, {TrapRec, Vbs}, V1Res, V2Res, V3Res, - Recv, LocalEngineID, NetIf) -> +send_trap_pdus([], ContextName, {TrapRec, Vbs}, + V1Res, V2Res, V3Res, Recv, + LocalEngineID, ExtraInfo, + NetIf) -> SysUpTime = snmp_standard_mib:sys_up_time(), ?vdebug("send trap pdus with sysUpTime ~p", [SysUpTime]), InformRecvs = get_inform_recvs(V2Res ++ V3Res), InformTargets = [Addr || {Addr, _, _, _} <- InformRecvs], deliver_recv(Recv, snmp_targets, InformTargets), - send_v1_trap(TrapRec, V1Res, Vbs, NetIf, SysUpTime), - send_v2_trap(TrapRec, V2Res, Vbs, Recv, NetIf, SysUpTime), - send_v3_trap(TrapRec, V3Res, Vbs, Recv, LocalEngineID, NetIf, + send_v1_trap(TrapRec, V1Res, Vbs, ExtraInfo, NetIf, SysUpTime), + send_v2_trap(TrapRec, V2Res, Vbs, Recv, ExtraInfo, NetIf, SysUpTime), + send_v3_trap(TrapRec, V3Res, Vbs, Recv, LocalEngineID, ExtraInfo, NetIf, SysUpTime, ContextName). -send_v1_trap(_TrapRec, [], _Vbs, _NetIf, _SysUpTime) -> +send_v1_trap(_TrapRec, [], _Vbs, _ExtraInfo, _NetIf, _SysUpTime) -> ok; send_v1_trap(#trap{enterpriseoid = Enter, specificcode = Spec}, - V1Res, Vbs, NetIf, SysUpTime) -> + V1Res, Vbs, ExtraInfo, NetIf, SysUpTime) -> ?vdebug("prepare to send v1 trap " "~n '~p'" "~n with" @@ -747,9 +759,10 @@ send_v1_trap(#trap{enterpriseoid = Enter, specificcode = Spec}, lists:foreach(fun({Community, Addrs}) -> ?vtrace("send v1 trap pdu to ~p",[Addrs]), NetIf ! {send_pdu, 'version-1', TrapPdu, - {community, Community}, Addrs} + {community, Community}, Addrs, ExtraInfo} end, AddrCommunities); -send_v1_trap(#notification{oid = Oid}, V1Res, Vbs, NetIf, SysUpTime) -> +send_v1_trap(#notification{oid = Oid}, V1Res, Vbs, ExtraInfo, NetIf, + SysUpTime) -> %% Use alg. in rfc2089 to map a v2 trap to a v1 trap % delete Counter64 objects from vbs ?vdebug("prepare to send v1 trap '~p'",[Oid]), @@ -771,31 +784,31 @@ send_v1_trap(#notification{oid = Oid}, V1Res, Vbs, NetIf, SysUpTime) -> lists:foreach(fun({Community, Addrs}) -> ?vtrace("send v1 trap to ~p",[Addrs]), NetIf ! {send_pdu, 'version-1', TrapPdu, - {community, Community}, Addrs} + {community, Community}, Addrs, ExtraInfo} end, AddrCommunities). -send_v2_trap(_TrapRec, [], _Vbs, _Recv, _NetIf, _SysUpTime) -> +send_v2_trap(_TrapRec, [], _Vbs, _Recv, _ExtraInfo, _NetIf, _SysUpTime) -> ok; -send_v2_trap(TrapRec, V2Res, Vbs, Recv, NetIf, SysUpTime) -> +send_v2_trap(TrapRec, V2Res, Vbs, Recv, ExtraInfo, NetIf, SysUpTime) -> ?vdebug("prepare to send v2 trap",[]), {_Oid, IVbs} = mk_v2_trap(TrapRec, Vbs, SysUpTime), - TrapRecvs = get_trap_recvs(V2Res), - InformRecvs = get_inform_recvs(V2Res), - do_send_v2_trap(TrapRecvs, IVbs, NetIf), - do_send_v2_inform(InformRecvs, IVbs, Recv, NetIf). + TrapRecvs = get_trap_recvs(V2Res), + InformRecvs = get_inform_recvs(V2Res), + do_send_v2_trap(TrapRecvs, IVbs, ExtraInfo, NetIf), + do_send_v2_inform(InformRecvs, IVbs, Recv, ExtraInfo, NetIf). -send_v3_trap(_TrapRec, [], _Vbs, _Recv, _LocalEngineID, +send_v3_trap(_TrapRec, [], _Vbs, _Recv, _LocalEngineID, _ExtraInfo, _NetIf, _SysUpTime, _ContextName) -> ok; -send_v3_trap(TrapRec, V3Res, Vbs, Recv, LocalEngineID, +send_v3_trap(TrapRec, V3Res, Vbs, Recv, LocalEngineID, ExtraInfo, NetIf, SysUpTime, ContextName) -> ?vdebug("prepare to send v3 trap",[]), {_Oid, IVbs} = mk_v2_trap(TrapRec, Vbs, SysUpTime), % v2 refers to SMIv2; TrapRecvs = get_trap_recvs(V3Res), % same SMI for v3 InformRecvs = get_inform_recvs(V3Res), - do_send_v3_trap(TrapRecvs, ContextName, IVbs, NetIf), + do_send_v3_trap(TrapRecvs, ContextName, IVbs, ExtraInfo, NetIf), do_send_v3_inform(InformRecvs, ContextName, IVbs, Recv, - LocalEngineID, NetIf). + LocalEngineID, ExtraInfo, NetIf). mk_v2_trap(#notification{oid = Oid}, Vbs, SysUpTime) -> @@ -833,60 +846,70 @@ get_inform_recvs(InformRecvs) -> [{Addr, MsgData, Timeout, Retry} || {Addr, MsgData, {inform, Timeout, Retry}} <- InformRecvs]. -do_send_v2_trap([], _Vbs, _NetIf) -> +do_send_v2_trap([], _Vbs, _ExtraInfo, _NetIf) -> ok; -do_send_v2_trap(Recvs, Vbs, NetIf) -> +do_send_v2_trap(Recvs, Vbs, ExtraInfo, NetIf) -> TrapPdu = make_v2_notif_pdu(Vbs, 'snmpv2-trap'), AddrCommunities = mk_addr_communities(Recvs), lists:foreach(fun({Community, Addrs}) -> ?vtrace("~n send v2 trap to ~p",[Addrs]), NetIf ! {send_pdu, 'version-2', TrapPdu, - {community, Community}, Addrs} + {community, Community}, Addrs, ExtraInfo} end, AddrCommunities), ok. -do_send_v2_inform([], _Vbs, _Recv, _NetIf) -> +do_send_v2_inform([], _Vbs, _Recv, _ExtraInfo, _NetIf) -> ok; -do_send_v2_inform(Recvs, Vbs, Recv, NetIf) -> +do_send_v2_inform(Recvs, Vbs, Recv, ExtraInfo, NetIf) -> lists:foreach( fun({Addr, Community, Timeout, Retry}) -> ?vtrace("~n start inform sender to send v2 inform to ~p", [Addr]), proc_lib:spawn_link(?MODULE, init_v2_inform, [Addr, Timeout, Retry, Vbs, - Recv, NetIf, Community, + Recv, ExtraInfo, NetIf, Community, get(verbosity), get(sname)]) end, Recvs). -do_send_v3_trap([], _ContextName, _Vbs, _NetIf) -> +do_send_v3_trap([], _ContextName, _Vbs, _ExtraInfo, _NetIf) -> ok; -do_send_v3_trap(Recvs, ContextName, Vbs, NetIf) -> +do_send_v3_trap(Recvs, ContextName, Vbs, ExtraInfo, NetIf) -> TrapPdu = make_v2_notif_pdu(Vbs, 'snmpv2-trap'), % Yes, v2 ContextEngineId = snmp_framework_mib:get_engine_id(), lists:foreach(fun(Recv) -> ?vtrace("~n send v3 notif to ~p",[Recv]), NetIf ! {send_pdu, 'version-3', TrapPdu, - {v3, ContextEngineId, ContextName}, [Recv]} + {v3, ContextEngineId, ContextName}, + [Recv], ExtraInfo} end, Recvs), ok. -do_send_v3_inform([], _ContextName, _Vbs, _Recv, _LocalEngineID, _NetIf) -> +do_send_v3_inform([], _ContextName, _Vbs, _Recv, + _LocalEngineID, _ExtraInfo, _NetIf) -> ok; -do_send_v3_inform(Recvs, ContextName, Vbs, Recv, LocalEngineID, NetIf) -> +do_send_v3_inform(Recvs, ContextName, Vbs, Recv, + LocalEngineID, ExtraInfo, NetIf) -> lists:foreach( fun({Addr, MsgData, Timeout, Retry}) -> ?vtrace("~n start inform sender to send v3 inform to ~p", [Addr]), proc_lib:spawn_link(?MODULE, init_v3_inform, [{Addr, MsgData}, Timeout, Retry, Vbs, - Recv, LocalEngineID, NetIf, ContextName, + Recv, LocalEngineID, ExtraInfo, + NetIf, ContextName, get(verbosity), get(sname)]) end, Recvs). %% New process -init_v2_inform(Addr, Timeout, Retry, Vbs, Recv, NetIf, Community,V,S) -> +init_v2_inform(Addr, Timeout, Retry, Vbs, Recv, NetIf, Community, V, S) -> + ExtraInfo = ?DEFAULT_NOTIF_EXTRA_INFO, + init_v2_inform(Addr, Timeout, Retry, Vbs, Recv, ExtraInfo, NetIf, + Community, V, S). + +init_v2_inform(Addr, Timeout, Retry, Vbs, Recv, ExtraInfo, NetIf, + Community, V, S) -> %% Make a new Inform for each recipient; they need unique %% request-ids! put(verbosity,V), @@ -895,17 +918,26 @@ init_v2_inform(Addr, Timeout, Retry, Vbs, Recv, NetIf, Community,V,S) -> [Timeout,Retry]), InformPdu = make_v2_notif_pdu(Vbs, 'inform-request'), Msg = {send_pdu_req, 'version-2', InformPdu, {community, Community}, - [Addr], self()}, + [Addr], self(), ExtraInfo}, ?MODULE:send_inform(Addr, Timeout*10, Retry, Msg, Recv, NetIf). %% New process init_v3_inform(Addr, Timeout, Retry, Vbs, Recv, NetIf, ContextName, V, S) -> + ExtraInfo = ?DEFAULT_NOTIF_EXTRA_INFO, LocalEngineID = ?DEFAULT_LOCAL_ENGINE_ID, - init_v3_inform(Addr, Timeout, Retry, Vbs, Recv, LocalEngineID, + init_v3_inform(Addr, Timeout, Retry, Vbs, Recv, + LocalEngineID, ExtraInfo, + NetIf, ContextName, V, S). + +init_v3_inform(Addr, Timeout, Retry, Vbs, Recv, LocalEngineID, NetIf, + ContextName, V, S) -> + ExtraInfo = ?DEFAULT_NOTIF_EXTRA_INFO, + init_v3_inform(Addr, Timeout, Retry, Vbs, Recv, + LocalEngineID, ExtraInfo, NetIf, ContextName, V, S). -init_v3_inform(Addr, Timeout, Retry, Vbs, Recv, LocalEngineID, +init_v3_inform(Addr, Timeout, Retry, Vbs, Recv, LocalEngineID, ExtraInfo, NetIf, ContextName, V, S) -> %% Make a new Inform for each recipient; they need unique %% request-ids! @@ -916,7 +948,7 @@ init_v3_inform(Addr, Timeout, Retry, Vbs, Recv, LocalEngineID, InformPdu = make_v2_notif_pdu(Vbs, 'inform-request'), % Yes, v2 ContextEngineId = LocalEngineID, Msg = {send_pdu_req, 'version-3', InformPdu, - {v3, ContextEngineId, ContextName}, [Addr], self()}, + {v3, ContextEngineId, ContextName}, [Addr], self(), ExtraInfo}, ?MODULE:send_inform(Addr, Timeout*10, Retry, Msg, Recv, NetIf). send_inform(Addr, _Timeout, -1, _Msg, Recv, _NetIf) -> -- cgit v1.2.3 From e9a4e34c2903abfd2d41a509b6d9cdea47ec7b89 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 4 Apr 2011 20:48:49 +0200 Subject: Added initial interface change. --- lib/snmp/src/manager/snmpm_server.erl | 61 +++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 13 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/manager/snmpm_server.erl b/lib/snmp/src/manager/snmpm_server.erl index d64b5b1d53..a5d4cdee32 100644 --- a/lib/snmp/src/manager/snmpm_server.erl +++ b/lib/snmp/src/manager/snmpm_server.erl @@ -32,14 +32,14 @@ register_user/4, register_user_monitor/4, unregister_user/1, - sync_get/4, sync_get/5, sync_get/6, - async_get/4, async_get/5, async_get/6, - sync_get_next/4, sync_get_next/5, sync_get_next/6, - async_get_next/4, async_get_next/5, async_get_next/6, - sync_get_bulk/6, sync_get_bulk/7, sync_get_bulk/8, - async_get_bulk/6, async_get_bulk/7, async_get_bulk/8, - sync_set/4, sync_set/5, sync_set/6, - async_set/4, async_set/5, async_set/6, + sync_get2/4, + async_get2/4, + sync_get_next2/4, + async_get_next2/4, + sync_get_bulk2/6, + async_get_bulk2/6, + sync_set2/4, + async_set2/4, cancel_async_request/2, %% discovery/2, discovery/3, discovery/4, discovery/5, discovery/6, @@ -55,6 +55,20 @@ ]). +%% +-export([sync_get/4, sync_get/5, sync_get/6, + async_get/4, async_get/5, async_get/6, + sync_get_next/4, sync_get_next/5, sync_get_next/6, + async_get_next/4, async_get_next/5, async_get_next/6, + sync_get_bulk/6, sync_get_bulk/7, sync_get_bulk/8, + async_get_bulk/6, async_get_bulk/7, async_get_bulk/8, + sync_set/4, sync_set/5, sync_set/6, + async_set/4, async_set/5, async_set/6 + ]). +%% + + + %% Internal exports -export([init/1, handle_call/3, handle_cast/2, handle_info/2, code_change/3, terminate/2]). @@ -192,6 +206,13 @@ unregister_user(UserId) -> %% -- [sync] get -- +%% The reason why we have a sync_get2 is to simplify backward +%% compatibillity. + +sync_get2(UserId, TargetName, Oids, Opts) -> + call({sync_get, self(), UserId, TargetName, Oids, Opts}). + +%% sync_get(UserId, TargetName, CtxName, Oids) -> sync_get(UserId, TargetName, CtxName, Oids, ?SYNC_GET_TIMEOUT). @@ -204,10 +225,17 @@ sync_get(UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo) is_list(CtxName) andalso is_list(Oids) andalso is_integer(Timeout) -> - call({sync_get, self(), UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo}). + Opts = [{context, CtxName}, {timeout, Timeout}, {extra, ExtraInfo}], + sync_get2(UserId, TargetName, Oids, Opts). +%% + %% -- [async] get -- +async_get2(UserId, TargetName, Oids, Opts) -> + call({async_get, self(), UserId, TargetName, Oids, Opts}). + +%% async_get(UserId, TargetName, CtxName, Oids) -> async_get(UserId, TargetName, CtxName, Oids, ?DEFAULT_ASYNC_EXPIRE, ?EXTRA_INFO). @@ -220,11 +248,17 @@ async_get(UserId, TargetName, CtxName, Oids, Expire, ExtraInfo) is_list(CtxName) andalso is_list(Oids) andalso is_integer(Expire) andalso (Expire >= 0)) -> - call({async_get, self(), UserId, TargetName, CtxName, Oids, Expire, - ExtraInfo}). + Opts = [{context, CtxName}, {expire, Expire}, {extra, ExtraInfo}], + async_get2(UserId, TargetName, Oids, Opts). +%% + %% -- [sync] get-next -- +sync_get_next2(UserId, TargetName, Oids, Opts) -> + call({sync_get_next, UserId, TargetName, Oids, Opts}). + +%% sync_get_next(UserId, TargetName, CtxName, Oids) -> sync_get_next(UserId, TargetName, CtxName, Oids, ?SYNC_GET_TIMEOUT, ?EXTRA_INFO). @@ -237,8 +271,9 @@ sync_get_next(UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo) is_list(CtxName) andalso is_list(Oids) andalso is_integer(Timeout) -> - call({sync_get_next, self(), UserId, TargetName, CtxName, Oids, Timeout, - ExtraInfo}). + Opts = [{context, CtxName}, {timeout, Timeout}, {extra, ExtraInfo}), + sync_get_next2(UserId, TargetName, Oids, Opts). +%% %% -- [async] get-next -- -- cgit v1.2.3 From 011728ea60468be455bb4b2ad7f79220f59fefda Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 5 Apr 2011 00:37:25 +0200 Subject: sync_get handled (also fixed the common agent-data creation function). --- lib/snmp/src/manager/snmpm_server.erl | 87 ++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 33 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/manager/snmpm_server.erl b/lib/snmp/src/manager/snmpm_server.erl index a5d4cdee32..55abca4b71 100644 --- a/lib/snmp/src/manager/snmpm_server.erl +++ b/lib/snmp/src/manager/snmpm_server.erl @@ -606,6 +606,19 @@ handle_call({unregister_user, UserId}, _From, State) -> %% We will reply to this request later, when the reply comes in from the %% agent, or when the timeout hits (unless we get an error now). +handle_call({sync_get, Pid, UserId, TargetName, Oids, SendOpts}, + From, State) -> + ?vlog("received sync_get [~p] request", [TargetName]), + case (catch handle_sync_get(Pid, + UserId, TargetName, Oids, SendOpts, + From, State)) of + ok -> + {noreply, State}; + Error -> + {reply, Error, State} + end; + +%% handle_call({sync_get, Pid, UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo}, From, State) -> ?vlog("received sync_get [~p] request", [CtxName]), @@ -617,6 +630,7 @@ handle_call({sync_get, Pid, UserId, TargetName, CtxName, Oids, Timeout, ExtraInf Error -> {reply, Error, State} end; +%% handle_call({sync_get_next, Pid, UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo}, From, State) -> @@ -936,36 +950,46 @@ terminate(Reason, #state{gct = GCT}) -> handle_sync_get(Pid, UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo, From, State) -> + SendOpts = + [ + {context, CtxName}, + {timeout, Timeout}, + {extra, Extra} + ], + handle_sync_get(Pid, UserId, TargetName, Oids, SendOpts, From, State). + +handle_sync_get(Pid, UserId, TargetName, Oids, SendOpts, From, State) -> ?vtrace("handle_sync_get -> entry with" "~n Pid: ~p" "~n UserId: ~p" "~n TargetName: ~p" - "~n CtxName: ~p" "~n Oids: ~p" - "~n Timeout: ~p" + "~n SendOpts: ~p" "~n From: ~p", - [Pid, UserId, TargetName, CtxName, Oids, Timeout, From]), - case agent_data(TargetName, CtxName) of + [Pid, UserId, TargetName, Oids, SendOpts, From]), + case agent_data(TargetName, SendOpts) of {ok, RegType, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_sync_get -> send a ~p message", [Vsn]), + Extra = get_opt(extra, ?EXTRA_INO, SendOpts), ReqId = send_get_request(Oids, Vsn, MsgData, Addr, Port, ExtraInfo, State), ?vdebug("handle_sync_get -> ReqId: ~p", [ReqId]), - Msg = {sync_timeout, ReqId, From}, - Ref = erlang:send_after(Timeout, self(), Msg), - MonRef = erlang:monitor(process, Pid), + Msg = {sync_timeout, ReqId, From}, + Timeout = get_opt(timeout, ?DEFAULT_SYNC_GET_TIMEOUT, SendOpts), + Ref = erlang:send_after(Timeout, self(), Msg), + MonRef = erlang:monitor(process, Pid), ?vtrace("handle_sync_get -> MonRef: ~p", [MonRef]), - Req = #request{id = ReqId, - user_id = UserId, - reg_type = RegType, - target = TargetName, - addr = Addr, - port = Port, - type = get, - data = MsgData, - ref = Ref, - mon = MonRef, - from = From}, + Req = #request{id = ReqId, + user_id = UserId, + reg_type = RegType, + target = TargetName, + addr = Addr, + port = Port, + type = get, + data = MsgData, + ref = Ref, + mon = MonRef, + from = From}, ets:insert(snmpm_request_table, Req), ok; Error -> @@ -987,7 +1011,7 @@ handle_sync_get_next(Pid, UserId, TargetName, CtxName, Oids, Timeout, "~n Timeout: ~p" "~n From: ~p", [Pid, UserId, TargetName, CtxName, Oids, Timeout, From]), - case agent_data(TargetName, CtxName) of + case agent_data(TargetName, SendOpts) of {ok, RegType, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_sync_get_next -> send a ~p message", [Vsn]), ReqId = send_get_next_request(Oids, Vsn, MsgData, @@ -1034,7 +1058,7 @@ handle_sync_get_bulk(Pid, UserId, TargetName, CtxName, "~n From: ~p", [Pid, UserId, TargetName, CtxName, NonRep, MaxRep, Oids, Timeout, From]), - case agent_data(TargetName, CtxName) of + case agent_data(TargetName, SendOpts) of {ok, RegType, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_sync_get_bulk -> send a ~p message", [Vsn]), ReqId = send_get_bulk_request(Oids, Vsn, MsgData, Addr, Port, @@ -1077,7 +1101,7 @@ handle_sync_set(Pid, UserId, TargetName, CtxName, VarsAndVals, Timeout, "~n Timeout: ~p" "~n From: ~p", [Pid, UserId, TargetName, CtxName, VarsAndVals, Timeout, From]), - case agent_data(TargetName, CtxName) of + case agent_data(TargetName, SendOpts) of {ok, RegType, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_sync_set -> send a ~p message", [Vsn]), ReqId = send_set_request(VarsAndVals, Vsn, MsgData, @@ -1119,7 +1143,7 @@ handle_async_get(Pid, UserId, TargetName, CtxName, Oids, Expire, ExtraInfo, "~n Oids: ~p" "~n Expire: ~p", [Pid, UserId, TargetName, CtxName, Oids, Expire]), - case agent_data(TargetName, CtxName) of + case agent_data(TargetName, SendOpts) of {ok, RegType, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_async_get -> send a ~p message", [Vsn]), ReqId = send_get_request(Oids, Vsn, MsgData, Addr, Port, @@ -1157,7 +1181,7 @@ handle_async_get_next(Pid, UserId, TargetName, CtxName, Oids, Expire, "~n Oids: ~p" "~n Expire: ~p", [Pid, UserId, TargetName, CtxName, Oids, Expire]), - case agent_data(TargetName, CtxName) of + case agent_data(TargetName, SendOpts) of {ok, RegType, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_async_get_next -> send a ~p message", [Vsn]), ReqId = send_get_next_request(Oids, Vsn, MsgData, @@ -1235,7 +1259,7 @@ handle_async_set(Pid, UserId, TargetName, CtxName, VarsAndVals, Expire, "~n VarsAndVals: ~p" "~n Expire: ~p", [Pid, UserId, TargetName, CtxName, VarsAndVals, Expire]), - case agent_data(TargetName, CtxName) of + case agent_data(TargetName, SendOpts) of {ok, RegType, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_async_set -> send a ~p message", [Vsn]), ReqId = send_set_request(VarsAndVals, Vsn, MsgData, @@ -2833,10 +2857,7 @@ request_id() -> %%---------------------------------------------------------------------- -agent_data(TargetName, CtxName) -> - agent_data(TargetName, CtxName, []). - -agent_data(TargetName, CtxName, Config) -> +agent_data(TargetName, SendOpts) -> case snmpm_config:agent_info(TargetName, all) of {ok, Info} -> Version = agent_data_item(version, Info), @@ -2850,13 +2871,13 @@ agent_data(TargetName, CtxName, Config) -> EngineId = agent_data_item(engine_id, Info), SecModel = agent_data_item(sec_model, - Config, + SendOpts, DefSecModel), SecName = agent_data_item(sec_name, - Config, + SendOpts, DefSecName), SecLevel = agent_data_item(sec_level, - Config, + SendOpts, DefSecLevel), {SecModel, SecName, mk_sec_level_flag(SecLevel), @@ -2866,10 +2887,10 @@ agent_data(TargetName, CtxName, Config) -> DefSecModel = agent_data_item(sec_model, Info), Comm = agent_data_item(community, - Config, + SendOPts, DefComm), SecModel = agent_data_item(sec_model, - Config, + SendOPts, DefSecModel), {Comm, SecModel} -- cgit v1.2.3 From dbacaf9db7977c3ad4ff35f7f6fe0085a6ab9956 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 5 Apr 2011 14:37:40 +0200 Subject: Documentation updated. --- lib/snmp/doc/src/notes.xml | 15 ++ lib/snmp/doc/src/snmp_agent_netif.xml | 198 ++++++++++++++++----------- lib/snmp/doc/src/snmpa.xml | 251 +++++++++++++++++++++------------- 3 files changed, 291 insertions(+), 173 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index f5fa7065fb..e9787c17da 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -43,6 +43,21 @@

-

--> + +

[agent] Pass extra info through the agent to the net-if + process when sending notifications.

+

See + + snmpa:send_notification2/3 for more info. + See also the incomming net-if messages when sending a + trap + and + + notification.

+

Own Id: OTP-9183

+

Aux Id: Seq 11817

+
+

[agent] Added support for sending traps to IPv6 targets.

See the diff --git a/lib/snmp/doc/src/snmp_agent_netif.xml b/lib/snmp/doc/src/snmp_agent_netif.xml index 1f2dbe80db..d751740a82 100644 --- a/lib/snmp/doc/src/snmp_agent_netif.xml +++ b/lib/snmp/doc/src/snmp_agent_netif.xml @@ -1,4 +1,4 @@ - + @@ -65,16 +65,19 @@

+ Messages

The section Messages describes mandatory messages, which Net if must send and be able to receive.

+ Outgoing Messages

Net if must send the following message when it receives an - SNMP PDU from the network that is aimed for the MasterAgent: -

+ SNMP PDU from the network that is aimed for the MasterAgent: +

+
 MasterAgent ! {snmp_pdu, Vsn, Pdu, PduMS, ACMData, From, Extra}
       
@@ -106,9 +109,10 @@ MasterAgent ! {snmp_pdu, Vsn, Pdu, PduMS, ACMData, From, Extra} the request.

The following message is used to report that a response to a - request has been received. The only request an agent can send - is an Inform-Request. -

+ request has been received. The only request an agent can send + is an Inform-Request. +

+
 Pid ! {snmp_response_received, Vsn, Pdu, From}
       
@@ -131,119 +135,153 @@ Pid ! {snmp_response_received, Vsn, Pdu, From}
+ Incoming Messages

This section describes the incoming messages which a Net if - process must be able to receive. -

+ process must be able to receive. +

+

{snmp_response, Vsn, Pdu, Type, ACMData, To, Extra}

This message is sent to the Net if process from a master agent as a response to a previously received request.

- Vsn is either 'version-1', - 'version-2', or 'version-3'. + +

Vsn is either 'version-1', + 'version-2', or 'version-3'.

- Pdu is an SNMP PDU record (as defined in - snmp_types.hrl) with the SNMP response. + +

Pdu is an SNMP PDU record (as defined in + snmp_types.hrl) with the SNMP response.

- Type is the #pdu.type of the original - request. + +

Type is the #pdu.type + of the original request.

- ACMData is data used by the Access Control - Module in use. Normally this is just sent to - snmpa_mpd:generate_response_message (see Reference Manual). + +

ACMData is data used by the Access Control + Module in use. Normally this is just sent to + snmpa_mpd:generate_response_message + (see Reference Manual).

- To is the destination address. If UDP over IP - is used, this should be a 2-tuple {IP, UDPport}, - where IP is a 4-tuple with the IP address, and - UDPport is an integer. + +

To is the destination address. If UDP over IP + is used, this should be a 2-tuple {IP, UDPport}, + where IP is a 4-tuple with the IP address, and + UDPport is an integer.

- Extra is the term that the Net if process - sent to the agent when the request was sent to the agent. + +

Extra is the term that the Net if process + sent to the agent when the request was sent to the agent.

+

{discarded_pdu, Vsn, ReqId, ACMData, Variable, Extra}

This message is sent from a master agent if it for some - reason decided to discard the pdu. -

+ reason decided to discard the pdu.

- Vsn is either 'version-1', - 'version-2', or 'version-3'. + +

Vsn is either 'version-1', + 'version-2', or 'version-3'.

- ReqId is the request id of the original - request. + +

ReqId is the request id of the original request.

- ACMData is data used by the Access Control - Module in use. Normally this is just sent to - snmpa_mpd:generate_response_message (see Reference Manual). + +

ACMData is data used by the Access Control + Module in use. Normally this is just sent to + snmpa_mpd:generate_response_message + (see Reference Manual).

- Variable is the name of an snmp counter that - represents the error, e.g. snmpInBadCommunityUses. + +

Variable is the name of an snmp counter that + represents the error, e.g. snmpInBadCommunityUses.

- Extra is the term that the Net if process - sent to the agent when the request was sent to the agent. + +

Extra is the term that the Net if process + sent to the agent when the request was sent to the agent.

-

{send_pdu, Vsn, Pdu, MsgData, To}

+ +

{send_pdu, Vsn, Pdu, MsgData, To, Extra}

This message is sent from a master agent when a trap is - to be sent. -

+ to be sent.

- Vsn is either 'version-1', - 'version-2', or 'version-3'. + +

Vsn is either 'version-1', + 'version-2', or 'version-3'.

- Pdu is an SNMP PDU record (as defined in - snmp_types.hrl) with the SNMP response. + +

Pdu is an SNMP PDU record (as defined in + snmp_types.hrl) with the SNMP response.

+
+ +

MsgData is the message specific data used in + the SNMP message. This value is normally sent to + snmpa_mpd:generate_message/4. In SNMPv1 and + SNMPv2c, this message data is the community string. In + SNMPv3, it is the context information.

- MsgData is the message specific data used in - the SNMP message. This value is normally sent to - snmpa_mpd:generate_message/4. In SNMPv1 and - SNMPv2c, this message data is the community string. In - SNMPv3, it is the context information. + +

To is a list of the destination addresses and + their corresponding security parameters. This value is + normally sent to snmpa_mpd:generate_message/4.

- To is a list of the destination addresses and - their corresponding security parameters. This value is - normally sent to snmpa_mpd:generate_message/4. + +

Extra is any term that the notification sender + wishes to pass to the Net if process when sending a notification + (see + send notification + for more info).

-

{send_pdu_req, Vsn, Pdu, MsgData, To, Pid}

-

This - message is sent from a master - agent when a request is - to be sent. The only request an agent can send is - Inform-Request. The net if process needs to remember the - request id and the Pid, and when a response is received for - the request id, send it to Pid, using a - snmp_response_received message. -

- - Vsn is either 'version-1', - 'version-2', or 'version-3'. - - Pdu is an SNMP PDU record (as defined in - snmp_types.hrl) with the SNMP response. - - MsgData is the message specific data used in - the SNMP message. This value is normally sent to - snmpa_mpd:generate_message/4. In SNMPv1 and - SNMPv2c, this message data is the community string. In - SNMPv3, it is the context information. + +

{send_pdu_req, Vsn, Pdu, MsgData, To, Pid, Extra}

+

This message is sent from a master agent when a request is to + be sent. The only request an agent can send is Inform-Request. + The net if process needs to remember the request id and the Pid, + and when a response is received for the request id, send it to Pid, + using a snmp_response_received message.

+ + +

Vsn is either 'version-1', + 'version-2', or 'version-3'.

+
+ +

Pdu is an SNMP PDU record (as defined in + snmp_types.hrl) with the SNMP response.

+
+ +

MsgData is the message specific data used in + the SNMP message. This value is normally sent to + snmpa_mpd:generate_message/4. In SNMPv1 and + SNMPv2c, this message data is the community string. In + SNMPv3, it is the context information.

+
+ +

To is a list of the destination addresses and + their corresponding security parameters. This value is + normally sent to snmpa_mpd:generate_message/4.

+
+ +

Pid is a process identifier.

+
+ +

Extra is any term that the notification sender + wishes to pass to the Net if process when sending a notification + (see + send notification + for more info).

- To is a list of the destination addresses and - their corresponding security parameters. This value is - normally sent to snmpa_mpd:generate_message/4. - - Pid is a process identifier. - -
+
diff --git a/lib/snmp/doc/src/snmpa.xml b/lib/snmp/doc/src/snmpa.xml index 1d680e80f5..1800bbc91a 100644 --- a/lib/snmp/doc/src/snmpa.xml +++ b/lib/snmp/doc/src/snmpa.xml @@ -872,10 +872,139 @@ snmp_agent:register_subagent(SA1,[1,2,3], SA2). then that sub-agent will be unregistered from all trees in Agent.

- + + + + send_notification2(Agent, Notification, SendOpts) -> void() + Send notification + + Agent = pid() | atom() + Notification = atom() + SendOpts = [send_option()] + send_option() = {receiver, receiver()} | {name, notify_name()} | {context, context_name()} | {varbinds, varbinds()} | {local_engine_id, string()} | {extra, extra_info()} + override_option() = atom() + receiver() = no_receiver | {tag(), tag_receiver()} | notification_delivery_info() + tag() = term(() + tag_receiver() = pid() | registered_name() | {Mod, Func, Args} + registered_name() = atom() + Mod = atom() + Func = atom() + Args = list() + notify_name() = string() + context_name() = string() + varbinds() = [varbind()] + varbind() = {variable(), value()} | {column(), row_index(), value()} | {oid(), value()} + variable() = atom() + value() = term() + column() = atom() + row_index() = [int()] + extra_info() = term() + + +

Send the notification Notification to the management + targets defined for notify-name (name) in the + snmpNotifyTable in SNMP-NOTIFICATION-MIB from the + specified context.

+ +

If no name is specified (or if it is ""), the + notification is sent to all management targets.

+ +

If no context is specified, the default context, "", + is used.

+ +

The send option receiver specifies where information + about delivery of Inform-Requests should be sent. The agent + sends Inform-Requests and waits for acknowledgments from the + management targets. + The receiver can have three values:

+ + + +

no_receiver - No information is delivered.

+
+ + +

notification_delivery_info() - The information is + delivered via a function call according to this data. See the + DATA TYPES section + above for details.

+
+ + +

{tag(), tag_receiver()} - The information is delivered + either via messages or via a function call according to the value + of tag_receiver().

+

Delivery is done differently depending on the value + of tag_receiver():

+ + + +

pid() | registered_name() - The info will be delivered in + the following messages:

+ + +

{snmp_targets, tag(), Addresses}

+

This informs the user which target addresses the + notification was sent to.

+
+ +

{snmp_notification, tag(), {got_response, Address}}

+

This informs the user that this target address + acknowledged the notification.

+
+ +

{snmp_notification, tag(), {no_response, Address}}

+

This informs the user that this target address + did not acknowledge the notification.

+
+
+

The notification is sent as an Inform-Request to each + target address in Addresses and if there are no + targets for which an Inform-Request is sent, Addresses + is the empty list [].

+

The tag_receiver() will first be sent the + snmp_targets message, and then for each address in + Addresses list, one of the two snmp_notification + messages.

+
+ + +

{Mod, Func, Args} - The info will be delivered via + the function call:

+

Mod:Func([Msg | Args])

+

where Msg has the same content and purpose as the + messages descrived above.

+
+ +
+
+
+ + +

The extra info is not normally interpreted by the agent, + instead it is passed through to the + net-if process. It is + up to the implementor of that process to make use of this data.

+

The version of net-if provided by this application makes no use + of this data, with one exception: + Any tuple containing the atom + snmpa_default_notification_extra_info + may be used by the agent and is therefor reserved.

+

See the net-if incomming messages for sending a + + trap and + + notification for more info.

+
+ + +
+
+ + send_notification(Agent, Notification, Receiver) send_notification(Agent, Notification, Receiver, Varbinds) @@ -907,29 +1036,25 @@ snmp_agent:register_subagent(SA1,[1,2,3], SA2).

Sends the notification Notification to the - management targets defined for NotifyName in the - snmpNotifyTable in SNMP-NOTIFICATION-MIB from the - specified context. If no NotifyName is specified (or - if it is ""), the notification is sent to all - management targets (Addresses below). If no ContextName - is specified, the default "" context is used. -

+ management targets defined for NotifyName in the + snmpNotifyTable in SNMP-NOTIFICATION-MIB from the + specified context.

+

If no NotifyName is specified (or if it is ""), + the notification is sent to all management targets + (Addresses below).

+

If no ContextName is specified, the default "" + context is used.

The parameter Receiver specifies where information - about delivery of Inform-Requests should be sent. The agent - sends Inform-Requests and waits for acknowledgments from the - managers. Receiver can have three values:

+ about delivery of Inform-Requests should be sent. The agent + sends Inform-Requests and waits for acknowledgments from the + managers. Receiver can have three values:

no_receiver - No information is delivered.

- -

{Tag, Recv} - The information is delivered either via messages - or via a function call according to the value of Recv.

-
-

notification_delivery_info() - The information is delivered via a function call according to this data. See the @@ -937,6 +1062,12 @@ snmp_agent:register_subagent(SA1,[1,2,3], SA2). above for details.

+ +

{Tag, Recv} - The information is delivered either via + messages or via a function call according to the value of + Recv.

+
+
@@ -1064,86 +1195,20 @@ snmp_agent:register_subagent(SA1,[1,2,3], SA2). (see SNMP-FRAMEWORK-MIB).

- - +

ExtraInfo is not normally used in any way by the agent. + It is intended to be passed along to the net-if process, which is + a component that a user can implement themself. The users own net-if + may then make use of ExtraInfo. The net-if provided with this + application does not process ExtraInfo.

+

There is one exception. Any tuple containing the atom + snmpa_default_notification_extra_info will, in this context, + be considered belonging to this application, and may be processed + by the agent.

+ +
- discovery(TargetName, Notification) -> {ok, ManagerEngineID} | {error, Reason} -- cgit v1.2.3 From 21259a5cdcf5d7308fedbb85925f83cee7d43ef1 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 5 Apr 2011 14:38:17 +0200 Subject: Chenged default extra-info value (for future use). --- lib/snmp/src/agent/snmpa_internal.hrl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa_internal.hrl b/lib/snmp/src/agent/snmpa_internal.hrl index fba800175b..a91f30a4a6 100644 --- a/lib/snmp/src/agent/snmpa_internal.hrl +++ b/lib/snmp/src/agent/snmpa_internal.hrl @@ -23,7 +23,7 @@ -include_lib("snmp/src/app/snmp_internal.hrl"). -define(DEFAULT_LOCAL_ENGINE_ID, snmp_framework_mib:get_engine_id()). --define(DEFAULT_NOTIF_EXTRA_INFO, undefined). +-define(DEFAULT_NOTIF_EXTRA_INFO, {snmpa_default_notification_extra_info}). -define(snmpa_info(F, A), ?snmp_info("agent", F, A)). -define(snmpa_warning(F, A), ?snmp_warning("agent", F, A)). -- cgit v1.2.3 From 1b5c5d07d539516aae36d13d119183954087ac79 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 5 Apr 2011 14:39:01 +0200 Subject: Cosmetic... --- lib/snmp/src/agent/snmpa_trap.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa_trap.erl b/lib/snmp/src/agent/snmpa_trap.erl index 0f6a5f8984..2a233fd38e 100644 --- a/lib/snmp/src/agent/snmpa_trap.erl +++ b/lib/snmp/src/agent/snmpa_trap.erl @@ -639,8 +639,8 @@ send_discovery_inform(Parent, Timeout, Retry, Msg, NetIf) -> %% should be used for the target, and determine the message %% specific parameters to be used. %%----------------------------------------------------------------- -send_trap_pdus([{DestAddr, TargetName, {MpModel, SecModel, SecName, SecLevel}, - Type} | T], +send_trap_pdus([{DestAddr, TargetName, + {MpModel, SecModel, SecName, SecLevel}, Type} | T], ContextName, {TrapRec, Vbs}, V1Res, V2Res, V3Res, Recv, LocalEngineID, ExtraInfo, NetIf) -> -- cgit v1.2.3 From 1900a5513cc743f5cba1d8df2bb2052bdc42a9ec Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 6 Apr 2011 12:55:35 +0200 Subject: Updated handle_sync... --- lib/snmp/src/manager/snmpm_server.erl | 202 ++++++++++++++++++++++------------ 1 file changed, 131 insertions(+), 71 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/manager/snmpm_server.erl b/lib/snmp/src/manager/snmpm_server.erl index 55abca4b71..0e6eb2d7be 100644 --- a/lib/snmp/src/manager/snmpm_server.erl +++ b/lib/snmp/src/manager/snmpm_server.erl @@ -89,13 +89,41 @@ -define(SERVER, ?MODULE). --define(SYNC_GET_TIMEOUT, 5000). --define(SYNC_SET_TIMEOUT, 5000). --define(DEFAULT_ASYNC_EXPIRE, 5000). --define(EXTRA_INFO, undefined). - --define(SNMP_AGENT_PORT, 161). - +-define(DEFAULT_SYNC_TIMEOUT, 5000). +-define(DEFAULT_SYNC_GET_TIMEOUT, ?DEFAULT_SYNC_TIMEOUT). +-define(DEFAULT_SYNC_GET_NEXT_TIMEOUT, ?DEFAULT_SYNC_TIMEOUT). +-define(DEFAULT_SYNC_GET_BULK_TIMEOUT, ?DEFAULT_SYNC_TIMEOUT). +-define(DEFAULT_SYNC_SET_TIMEOUT, ?DEFAULT_SYNC_TIMEOUT). + +-define(DEFAULT_ASYNC_EXPIRE, 5000). +-define(DEFAULT_ASYNC_GET_TIMEOUT, ?DEFAULT_ASYNC_EXPIRE). +-define(DEFAULT_ASYNC_GET_NEXT_TIMEOUT, ?DEFAULT_ASYNC_EXPIRE). +-define(DEFAULT_ASYNC_GET_BULK_TIMEOUT, ?DEFAULT_ASYNC_EXPIRE). +-define(DEFAULT_ASYNC_SET_TIMEOUT, ?DEFAULT_ASYNC_EXPIRE). + +-define(EXTRA_INFO, undefined). + +-define(SNMP_AGENT_PORT, 161). + +-define(GET_SYNC_GET_TIMEOUT(SendOpts), + get_opt(timeout, ?DEFAULT_SYNC_GET_TIMEOUT, SendOpts)). +-define(GET_SYNC_GET_NEXT_TIMEOUT(SendOpts), + get_opt(timeout, ?DEFAULT_SYNC_GET_NEXT_TIMEOUT, SendOpts)). +-define(GET_SYNC_GET_BULK_TIMEOUT(SendOpts), + get_opt(timeout, ?DEFAULT_SYNC_GET_BULK_TIMEOUT, SendOpts)). +-define(SYNC_SET_TIMEOUT(SendOpts), + get_opt(timeout, ?DEFAULT_SYNC_SET_TIMEOUT, SendOpts)). + +-define(GET_ASYNC_GET_EXPIRE(SendOpts), + get_opt(expire, ?DEFAULT_ASYNC_GET_EXPIRE, SendOpts)). +-define(GET_ASYNC_GET_NEXT_EXPIRE(SendOpts), + get_opt(expire, ?DEFAULT_ASYNC_GET_NEXT_EXPIRE, SendOpts)). +-define(GET_ASYNC_GET_BULK_EXPIRE(SendOpts), + get_opt(expire, ?DEFAULT_ASYNC_GET_BULK_EXPIRE, SendOpts)). +-define(GET_ASYNC_SET_EXPIRE(SendOpts), + get_opt(expire, ?DEFAULT_ASYNC_SET_EXPIRE, SendOpts)). + +-define(GET_EXTRA(SendOpts), get_opt(extra, ?DEFAULT_EXTRA, SendOpts)). -ifdef(snmp_debug). -define(GS_START_LINK(Args), @@ -954,7 +982,7 @@ handle_sync_get(Pid, UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo, [ {context, CtxName}, {timeout, Timeout}, - {extra, Extra} + {extra, ExtraInfo} ], handle_sync_get(Pid, UserId, TargetName, Oids, SendOpts, From, State). @@ -970,12 +998,12 @@ handle_sync_get(Pid, UserId, TargetName, Oids, SendOpts, From, State) -> case agent_data(TargetName, SendOpts) of {ok, RegType, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_sync_get -> send a ~p message", [Vsn]), - Extra = get_opt(extra, ?EXTRA_INO, SendOpts), - ReqId = send_get_request(Oids, Vsn, MsgData, Addr, Port, - ExtraInfo, State), + Extra = ?GET_EXTRA(SendOpts), + ReqId = send_get_request(Oids, Vsn, MsgData, + Addr, Port, Extra, State), ?vdebug("handle_sync_get -> ReqId: ~p", [ReqId]), Msg = {sync_timeout, ReqId, From}, - Timeout = get_opt(timeout, ?DEFAULT_SYNC_GET_TIMEOUT, SendOpts), + Timeout = ?SYNC_GET_TIMEOUT(SendOpts), Ref = erlang:send_after(Timeout, self(), Msg), MonRef = erlang:monitor(process, Pid), ?vtrace("handle_sync_get -> MonRef: ~p", [MonRef]), @@ -999,39 +1027,49 @@ handle_sync_get(Pid, UserId, TargetName, Oids, SendOpts, From, State) -> Error end. - handle_sync_get_next(Pid, UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo, From, State) -> + SendOpts = + [ + {context, CtxName}, + {timeout, Timeout}, + {extra, ExtraInfo} + ], + handle_sync_get_next(Pid, UserId, TargetName, Oids, SendOpts, From, State). + +handle_sync_get_next(Pid, UserId, TargetName, Oids, SendOpts, + From, State) -> ?vtrace("handle_sync_get_next -> entry with" "~n Pid: ~p" "~n UserId: ~p" "~n TargetName: ~p" - "~n CtxName: ~p" "~n Oids: ~p" - "~n Timeout: ~p" + "~n SendOpts: ~p" "~n From: ~p", - [Pid, UserId, TargetName, CtxName, Oids, Timeout, From]), + [Pid, UserId, TargetName, Oids, SendOpts, From]), case agent_data(TargetName, SendOpts) of {ok, RegType, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_sync_get_next -> send a ~p message", [Vsn]), - ReqId = send_get_next_request(Oids, Vsn, MsgData, - Addr, Port, ExtraInfo, State), + Extra = ?GET_EXTRA(SendOpts), + ReqId = send_get_next_request(Oids, Vsn, MsgData, + Addr, Port, Extra, State), ?vdebug("handle_sync_get_next -> ReqId: ~p", [ReqId]), - Msg = {sync_timeout, ReqId, From}, - Ref = erlang:send_after(Timeout, self(), Msg), - MonRef = erlang:monitor(process, Pid), + Msg = {sync_timeout, ReqId, From}, + Timeout = ?SYNC_GET_NEXT_TIMEOUT(SendOpts), + Ref = erlang:send_after(Timeout, self(), Msg), + MonRef = erlang:monitor(process, Pid), ?vtrace("handle_sync_get_next -> MonRef: ~p", [MonRef]), - Req = #request{id = ReqId, - user_id = UserId, - reg_type = RegType, - target = TargetName, - addr = Addr, - port = Port, - type = get_next, - data = MsgData, - ref = Ref, - mon = MonRef, - from = From}, + Req = #request{id = ReqId, + user_id = UserId, + reg_type = RegType, + target = TargetName, + addr = Addr, + port = Port, + type = get_next, + data = MsgData, + ref = Ref, + mon = MonRef, + from = From}, ets:insert(snmpm_request_table, Req), ok; @@ -1046,39 +1084,50 @@ handle_sync_get_next(Pid, UserId, TargetName, CtxName, Oids, Timeout, handle_sync_get_bulk(Pid, UserId, TargetName, CtxName, NonRep, MaxRep, Oids, Timeout, ExtraInfo, From, State) -> + SendOpts = + [ + {context, CtxName}, + {timeout, Timeout}, + {extra, ExtraInfo} + ], + handle_sync_get_bulk(Pid, UserId, TargetName, NonRep, MaxRep, Oids, + SendOpts, From, State). + +handle_sync_get_bulk(Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts, + From, State) -> ?vtrace("handle_sync_get_bulk -> entry with" "~n Pid: ~p" "~n UserId: ~p" "~n TargetName: ~p" - "~n CtxName: ~p" "~n NonRep: ~p" "~n MaxRep: ~p" "~n Oids: ~p" - "~n Timeout: ~p" + "~n SendOpts: ~p" "~n From: ~p", - [Pid, UserId, TargetName, CtxName, NonRep, MaxRep, Oids, - Timeout, From]), + [Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts, From]), case agent_data(TargetName, SendOpts) of {ok, RegType, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_sync_get_bulk -> send a ~p message", [Vsn]), - ReqId = send_get_bulk_request(Oids, Vsn, MsgData, Addr, Port, - NonRep, MaxRep, ExtraInfo, State), + Extra = ?GET_EXTRA(SendOpts), + ReqId = send_get_bulk_request(Oids, Vsn, MsgData, Addr, Port, + NonRep, MaxRep, Extra, State), ?vdebug("handle_sync_get_bulk -> ReqId: ~p", [ReqId]), - Msg = {sync_timeout, ReqId, From}, - Ref = erlang:send_after(Timeout, self(), Msg), - MonRef = erlang:monitor(process, Pid), + Msg = {sync_timeout, ReqId, From}, + Timeout = ?SYNC_GET_BULK_TIMEOUT(SendOpts), + Ref = erlang:send_after(Timeout, self(), Msg), + MonRef = erlang:monitor(process, Pid), ?vtrace("handle_sync_get_bulk -> MonRef: ~p", [MonRef]), - Req = #request{id = ReqId, - user_id = UserId, - reg_type = RegType, - target = TargetName, - addr = Addr, - port = Port, - type = get_bulk, - data = MsgData, - ref = Ref, - mon = MonRef, - from = From}, + Req = #request{id = ReqId, + user_id = UserId, + reg_type = RegType, + target = TargetName, + addr = Addr, + port = Port, + type = get_bulk, + data = MsgData, + ref = Ref, + mon = MonRef, + from = From}, ets:insert(snmpm_request_table, Req), ok; @@ -1092,36 +1141,47 @@ handle_sync_get_bulk(Pid, UserId, TargetName, CtxName, handle_sync_set(Pid, UserId, TargetName, CtxName, VarsAndVals, Timeout, ExtraInfo, From, State) -> + SendOpts = + [ + {context, CtxName}, + {timeout, Timeout}, + {extra, ExtraInfo} + ], + handle_sync_set(Pid, UserId, TargetName, VarsAndVals, SendOpts, + From, State). + +handle_sync_set(Pid, UserId, TargetName, VarsAndVals, SendOpts, From, State) -> ?vtrace("handle_sync_set -> entry with" "~n Pid: ~p" "~n UserId: ~p" "~n TargetName: ~p" - "~n CtxName: ~p" "~n VarsAndVals: ~p" - "~n Timeout: ~p" + "~n SendOpts: ~p" "~n From: ~p", - [Pid, UserId, TargetName, CtxName, VarsAndVals, Timeout, From]), + [Pid, UserId, TargetName, VarsAndVals, From]), case agent_data(TargetName, SendOpts) of {ok, RegType, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_sync_set -> send a ~p message", [Vsn]), - ReqId = send_set_request(VarsAndVals, Vsn, MsgData, - Addr, Port, ExtraInfo, State), + Extra = ?GET_EXTRA(SendOpts), + ReqId = send_set_request(VarsAndVals, Vsn, MsgData, + Addr, Port, Extra, State), ?vdebug("handle_sync_set -> ReqId: ~p", [ReqId]), - Msg = {sync_timeout, ReqId, From}, - Ref = erlang:send_after(Timeout, self(), Msg), - MonRef = erlang:monitor(process, Pid), + Msg = {sync_timeout, ReqId, From}, + Timeout = ?SYNC_SET_TIMEOUT(SendOpts), + Ref = erlang:send_after(Timeout, self(), Msg), + MonRef = erlang:monitor(process, Pid), ?vtrace("handle_sync_set -> MonRef: ~p", [MonRef]), - Req = #request{id = ReqId, - user_id = UserId, - reg_type = RegType, - target = TargetName, - addr = Addr, - port = Port, - type = set, - data = MsgData, - ref = Ref, - mon = MonRef, - from = From}, + Req = #request{id = ReqId, + user_id = UserId, + reg_type = RegType, + target = TargetName, + addr = Addr, + port = Port, + type = set, + data = MsgData, + ref = Ref, + mon = MonRef, + from = From}, ets:insert(snmpm_request_table, Req), ok; -- cgit v1.2.3 From 332b91c46d67dc31ca6080b2ba5c03636f3d584f Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 6 Apr 2011 17:46:04 +0200 Subject: Backup checkin (still working on the interface functions). --- lib/snmp/src/manager/snmpm_server.erl | 86 +++++++++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 13 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/manager/snmpm_server.erl b/lib/snmp/src/manager/snmpm_server.erl index 0e6eb2d7be..08f9703e9d 100644 --- a/lib/snmp/src/manager/snmpm_server.erl +++ b/lib/snmp/src/manager/snmpm_server.erl @@ -237,9 +237,12 @@ unregister_user(UserId) -> %% The reason why we have a sync_get2 is to simplify backward %% compatibillity. +sync_get2(UserId, TargetName, Oids) -> + sync_get2(UserId, TargetName, Oids, []). sync_get2(UserId, TargetName, Oids, Opts) -> call({sync_get, self(), UserId, TargetName, Oids, Opts}). + %% sync_get(UserId, TargetName, CtxName, Oids) -> sync_get(UserId, TargetName, CtxName, Oids, @@ -258,10 +261,14 @@ sync_get(UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo) %% + %% -- [async] get -- -async_get2(UserId, TargetName, Oids, Opts) -> - call({async_get, self(), UserId, TargetName, Oids, Opts}). +async_get2(UserId, TargetName, Oids) -> + async_get2(UserId, TargetName, Oids, []) -> +async_get2(UserId, TargetName, Oids, SendOpts) -> + call({async_get, self(), UserId, TargetName, Oids, SendOpts}). + %% async_get(UserId, TargetName, CtxName, Oids) -> @@ -281,10 +288,14 @@ async_get(UserId, TargetName, CtxName, Oids, Expire, ExtraInfo) %% + %% -- [sync] get-next -- +sync_get_next2(UserId, TargetName, Oids) -> + sync_get_next2(UserId, TargetName, Oids, []). sync_get_next2(UserId, TargetName, Oids, Opts) -> - call({sync_get_next, UserId, TargetName, Oids, Opts}). + call({sync_get_next, self(), UserId, TargetName, Oids, Opts}). + %% sync_get_next(UserId, TargetName, CtxName, Oids) -> @@ -303,8 +314,16 @@ sync_get_next(UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo) sync_get_next2(UserId, TargetName, Oids, Opts). %% + + %% -- [async] get-next -- +async_get_next2(UserId, TargetName, Oids) -> + async_get_next2(UserId, TargetName, Oids, []). +async_get_next2(UserId, TargetName, Oids, SendOpts) -> + call({async_get_next, self(), UserId, TargetName, Oids, Opts}). + + async_get_next(UserId, TargetName, CtxName, Oids) -> async_get_next(UserId, TargetName, CtxName, Oids, ?DEFAULT_ASYNC_EXPIRE, ?EXTRA_INFO). @@ -317,11 +336,19 @@ async_get_next(UserId, TargetName, CtxName, Oids, Expire, ExtraInfo) is_list(CtxName) andalso is_list(Oids) andalso is_integer(Expire) andalso (Expire >= 0)) -> - call({async_get_next, self(), UserId, TargetName, CtxName, Oids, - Expire, ExtraInfo}). + Opts = [{context, CtxName}, {expire, Expire}, {extra, ExtraInfo}), + async_get_next2(UserId, TargetName, Oids, Opts). + + %% -- [sync] get-bulk -- +sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids) -> + sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, []). +sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts) -> + call({sync_get_bulk, self(), UserId, TargetName, + NonRep, MaxRep, Oids, SendOpts}). + sync_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids) -> sync_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids, @@ -340,11 +367,19 @@ sync_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids, Timeout, is_list(CtxName) andalso is_list(Oids) andalso is_integer(Timeout) -> - call({sync_get_bulk, self(), UserId, TargetName, - NonRep, MaxRep, CtxName, Oids, Timeout, ExtraInfo}). + Opts = [{context, CtxName}, {timeout, Timeout}, {extra, ExtraInfo}), + sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, Opts}). + %% -- [async] get-bulk -- +async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids) -> + async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, []). +async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts) -> + call({async_get_bulk, self(), UserId, TargetName, NonRep, MaxRep, + Oids, SendOpts}). + + async_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids) -> async_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids, @@ -363,12 +398,20 @@ async_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids, Expire, is_list(CtxName) andalso is_list(Oids) andalso is_integer(Expire) -> - call({async_get_bulk, self(), UserId, TargetName, - NonRep, MaxRep, CtxName, Oids, Expire, ExtraInfo}). + Opts = [{context, CtxName}, {expire, Expire}, {extra, ExtraInfo}), + async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, Opts}). + + %% -- [sync] set -- %% VarsAndValues is: {PlainOid, o|s|i, Value} (unknown mibs) | {Oid, Value} +sync_set2(UserId, TargetName, VarsAndVals) -> + sync_set2(UserId, TargetName, VarsAndVals, []). +sync_set2(UserId, TargetName, VarsAndVals, SendOpts) -> + call({sync_set, self(), UserId, TargetName, VarsAndVals, SendOpts}). + + sync_set(UserId, TargetName, CtxName, VarsAndVals) -> sync_set(UserId, TargetName, CtxName, VarsAndVals, ?SYNC_SET_TIMEOUT, ?EXTRA_INFO). @@ -382,11 +425,19 @@ sync_set(UserId, TargetName, CtxName, VarsAndVals, Timeout, ExtraInfo) is_list(CtxName) andalso is_list(VarsAndVals) andalso is_integer(Timeout) -> - call({sync_set, self(), UserId, TargetName, - CtxName, VarsAndVals, Timeout, ExtraInfo}). + Opts = [{context, CtxName}, {timeout, Timeout}, {extra, ExtraInfo}), + sync_set2(UserId, TargetName, VarsAndVals, Opts}). + + %% -- [async] set -- +async_set2(UserId, TargetName, VarsAndVals) -> + async_set2(UserId, TargetName, VarsAndVals, []). +async_set2(UserId, TargetName, VarsAndVals, SendOpts) -> + call({async_set, self(), UserId, TargetName, VarsAndVals, SendOpts}). + + async_set(UserId, TargetName, CtxName, VarsAndVals) -> async_set(UserId, TargetName, CtxName, VarsAndVals, ?DEFAULT_ASYNC_EXPIRE, ?EXTRA_INFO). @@ -400,8 +451,8 @@ async_set(UserId, TargetName, CtxName, VarsAndVals, Expire, ExtraInfo) is_list(CtxName) andalso is_list(VarsAndVals) andalso is_integer(Expire) andalso (Expire >= 0)) -> - call({async_set, self(), UserId, TargetName, - CtxName, VarsAndVals, Expire, ExtraInfo}). + Opts = [{context, CtxName}, {expire, Expire}, {extra, ExtraInfo}), + async_set2(UserId, TargetName, VarsAndVals, Opts}). cancel_async_request(UserId, ReqId) -> @@ -1195,6 +1246,15 @@ handle_sync_set(Pid, UserId, TargetName, VarsAndVals, SendOpts, From, State) -> handle_async_get(Pid, UserId, TargetName, CtxName, Oids, Expire, ExtraInfo, State) -> + SendOpts = + [ + {context, CtxName}, + {timeout, Expire}, + {extra, ExtraInfo} + ], + handle_async_get(Pid, UserId, TargetName, Oids, SendOpts, State). + +handle_async_get(Pid, UserId, TargetName, Oids, SendOpts, State) -> ?vtrace("handle_async_get -> entry with" "~n Pid: ~p" "~n UserId: ~p" -- cgit v1.2.3 From 96273e7f909b14163aa117174994362736590140 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 7 Apr 2011 12:20:56 +0200 Subject: Release notes and API cleanup. --- lib/snmp/doc/src/notes.xml | 30 +++++++++++++++--------------- lib/snmp/doc/src/snmpa.xml | 1 - 2 files changed, 15 insertions(+), 16 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index e9787c17da..6853eefad2 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -43,21 +43,6 @@

-

--> - -

[agent] Pass extra info through the agent to the net-if - process when sending notifications.

-

See - - snmpa:send_notification2/3 for more info. - See also the incomming net-if messages when sending a - trap - and - - notification.

-

Own Id: OTP-9183

-

Aux Id: Seq 11817

-
-

[agent] Added support for sending traps to IPv6 targets.

See the @@ -75,6 +60,21 @@

Own Id: OTP-9174

+ +

[agent] Pass extra info through the agent to the net-if + process when sending notifications.

+

See + + snmpa:send_notification2/3 for more info. + See also the incomming net-if messages when sending a + trap + and + + notification.

+

Own Id: OTP-9183

+

Aux Id: Seq 11817

+
+
diff --git a/lib/snmp/doc/src/snmpa.xml b/lib/snmp/doc/src/snmpa.xml index 1800bbc91a..27d89ea4e3 100644 --- a/lib/snmp/doc/src/snmpa.xml +++ b/lib/snmp/doc/src/snmpa.xml @@ -885,7 +885,6 @@ snmp_agent:register_subagent(SA1,[1,2,3], SA2). Notification = atom() SendOpts = [send_option()] send_option() = {receiver, receiver()} | {name, notify_name()} | {context, context_name()} | {varbinds, varbinds()} | {local_engine_id, string()} | {extra, extra_info()} - override_option() = atom() receiver() = no_receiver | {tag(), tag_receiver()} | notification_delivery_info() tag() = term(() tag_receiver() = pid() | registered_name() | {Mod, Func, Args} -- cgit v1.2.3 From d620fd8d49314d0f412fbfa83c9f42f7d338558a Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 7 Apr 2011 12:22:10 +0200 Subject: Added export of new send notification function.c --- lib/snmp/src/agent/snmpa.erl | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa.erl b/lib/snmp/src/agent/snmpa.erl index 4cdc9d0064..630a14907d 100644 --- a/lib/snmp/src/agent/snmpa.erl +++ b/lib/snmp/src/agent/snmpa.erl @@ -60,6 +60,7 @@ register_subagent/3, unregister_subagent/2, + send_notification2/3, send_notification/3, send_notification/4, send_notification/5, send_notification/6, send_notification/7, send_trap/3, send_trap/4, -- cgit v1.2.3 From 554991eb76601ad74d5c8c045fcf53049c9fa39f Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 8 Apr 2011 17:52:22 +0200 Subject: Some handle_call-cases handled. --- lib/snmp/src/manager/snmpm_server.erl | 46 ++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/manager/snmpm_server.erl b/lib/snmp/src/manager/snmpm_server.erl index 08f9703e9d..13136ef1c0 100644 --- a/lib/snmp/src/manager/snmpm_server.erl +++ b/lib/snmp/src/manager/snmpm_server.erl @@ -687,7 +687,8 @@ handle_call({unregister_user, UserId}, _From, State) -> %% agent, or when the timeout hits (unless we get an error now). handle_call({sync_get, Pid, UserId, TargetName, Oids, SendOpts}, From, State) -> - ?vlog("received sync_get [~p] request", [TargetName]), + ?vlog("[~p,~p] received sync_get request for" + "~n ~p", [UserId, TargetName, Opts]), case (catch handle_sync_get(Pid, UserId, TargetName, Oids, SendOpts, From, State)) of @@ -698,9 +699,11 @@ handle_call({sync_get, Pid, UserId, TargetName, Oids, SendOpts}, end; %% +%% The only case where this would be called is during code upgrade handle_call({sync_get, Pid, UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo}, From, State) -> - ?vlog("received sync_get [~p] request", [CtxName]), + ?vlog("[~p,~p] received sync_get request for" + "~n ~p", [UserId, TargetName, Opts]), case (catch handle_sync_get(Pid, UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo, From, State)) of @@ -712,8 +715,26 @@ handle_call({sync_get, Pid, UserId, TargetName, CtxName, Oids, Timeout, ExtraInf %% -handle_call({sync_get_next, Pid, UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo}, From, State) -> - ?vlog("received sync_get_next [~p] request", [CtxName]), +handle_call({sync_get_next, Pid, UserId, TargetName, Oids, SendOpts}, + From, State) -> + ?vlog("[~p,~p] received sync_get_next request for: " + "~n ~p", [UserId, TargetName, Opts]), + case (catch handle_sync_get_next(Pid, + UserId, TargetName, Oids, SendOpts, + From, State)) of + ok -> + {noreply, State}; + Error -> + {reply, Error, State} + end; + + +%% +%% The only case where this would be called is during code upgrade +handle_call({sync_get_next, Pid, UserId, TargetName, CtxName, Oids, + Timeout, ExtraInfo}, From, State) -> + ?vlog("[~p,~p] received sync_get_next request for" + "~n ~p", [UserId, TargetName, Opts]), case (catch handle_sync_get_next(Pid, UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo, From, State)) of @@ -722,9 +743,25 @@ handle_call({sync_get_next, Pid, UserId, TargetName, CtxName, Oids, Timeout, Ext Error -> {reply, Error, State} end; +%% %% Check agent version? This op not in v1 +handle_call({sync_get_bulk, Pid, UserId, TargetName, + NonRep, MaxRep, Oids, SendOpts}, + From, State) -> + ?vlog("received sync_get_bulk [~p] request", [CtxName]), + case (catch handle_sync_get_bulk(Pid, + UserId, TargetName, NonRep, MaxRep, Oids, + SendOpts, From, State)) of + ok -> + {noreply, State}; + Error -> + {reply, Error, State} + end; + +%% +%% The only case where this would be called is during code upgrade handle_call({sync_get_bulk, Pid, UserId, TargetName, NonRep, MaxRep, CtxName, Oids, Timeout, ExtraInfo}, From, State) -> @@ -738,6 +775,7 @@ handle_call({sync_get_bulk, Pid, UserId, TargetName, Error -> {reply, Error, State} end; +%% handle_call({sync_set, Pid, UserId, TargetName, -- cgit v1.2.3 From 43b0aa5aac83beed77eff40df769c099fefaab43 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 12 Apr 2011 14:40:21 +0200 Subject: "Time to go to the gym"-backup... --- lib/snmp/src/manager/snmpm_server.erl | 295 ++++++++++++++++++++++++---------- 1 file changed, 207 insertions(+), 88 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/manager/snmpm_server.erl b/lib/snmp/src/manager/snmpm_server.erl index 13136ef1c0..cf29770244 100644 --- a/lib/snmp/src/manager/snmpm_server.erl +++ b/lib/snmp/src/manager/snmpm_server.erl @@ -89,41 +89,41 @@ -define(SERVER, ?MODULE). --define(DEFAULT_SYNC_TIMEOUT, 5000). +-define(DEFAULT_SYNC_TIMEOUT, timer:seconds(5)). -define(DEFAULT_SYNC_GET_TIMEOUT, ?DEFAULT_SYNC_TIMEOUT). -define(DEFAULT_SYNC_GET_NEXT_TIMEOUT, ?DEFAULT_SYNC_TIMEOUT). -define(DEFAULT_SYNC_GET_BULK_TIMEOUT, ?DEFAULT_SYNC_TIMEOUT). -define(DEFAULT_SYNC_SET_TIMEOUT, ?DEFAULT_SYNC_TIMEOUT). --define(DEFAULT_ASYNC_EXPIRE, 5000). --define(DEFAULT_ASYNC_GET_TIMEOUT, ?DEFAULT_ASYNC_EXPIRE). --define(DEFAULT_ASYNC_GET_NEXT_TIMEOUT, ?DEFAULT_ASYNC_EXPIRE). --define(DEFAULT_ASYNC_GET_BULK_TIMEOUT, ?DEFAULT_ASYNC_EXPIRE). --define(DEFAULT_ASYNC_SET_TIMEOUT, ?DEFAULT_ASYNC_EXPIRE). +-define(DEFAULT_ASYNC_TIMEOUT, timer:seconds(5)). +-define(DEFAULT_ASYNC_GET_TIMEOUT, ?DEFAULT_ASYNC_TIMEOUT). +-define(DEFAULT_ASYNC_GET_NEXT_TIMEOUT, ?DEFAULT_ASYNC_TIMEOUT). +-define(DEFAULT_ASYNC_GET_BULK_TIMEOUT, ?DEFAULT_ASYNC_TIMEOUT). +-define(DEFAULT_ASYNC_SET_TIMEOUT, ?DEFAULT_ASYNC_TIMEOUT). --define(EXTRA_INFO, undefined). +-define(DEFAULT_EXTRA_INFO, undefined). -define(SNMP_AGENT_PORT, 161). --define(GET_SYNC_GET_TIMEOUT(SendOpts), +-define(SYNC_GET_TIMEOUT(SendOpts), get_opt(timeout, ?DEFAULT_SYNC_GET_TIMEOUT, SendOpts)). --define(GET_SYNC_GET_NEXT_TIMEOUT(SendOpts), +-define(SYNC_GET_NEXT_TIMEOUT(SendOpts), get_opt(timeout, ?DEFAULT_SYNC_GET_NEXT_TIMEOUT, SendOpts)). --define(GET_SYNC_GET_BULK_TIMEOUT(SendOpts), +-define(SYNC_GET_BULK_TIMEOUT(SendOpts), get_opt(timeout, ?DEFAULT_SYNC_GET_BULK_TIMEOUT, SendOpts)). -define(SYNC_SET_TIMEOUT(SendOpts), get_opt(timeout, ?DEFAULT_SYNC_SET_TIMEOUT, SendOpts)). --define(GET_ASYNC_GET_EXPIRE(SendOpts), - get_opt(expire, ?DEFAULT_ASYNC_GET_EXPIRE, SendOpts)). --define(GET_ASYNC_GET_NEXT_EXPIRE(SendOpts), - get_opt(expire, ?DEFAULT_ASYNC_GET_NEXT_EXPIRE, SendOpts)). --define(GET_ASYNC_GET_BULK_EXPIRE(SendOpts), - get_opt(expire, ?DEFAULT_ASYNC_GET_BULK_EXPIRE, SendOpts)). --define(GET_ASYNC_SET_EXPIRE(SendOpts), - get_opt(expire, ?DEFAULT_ASYNC_SET_EXPIRE, SendOpts)). +-define(ASYNC_GET_TIMEOUT(SendOpts), + get_opt(timeout, ?DEFAULT_ASYNC_GET_TIMEOUT, SendOpts)). +-define(ASYNC_GET_NEXT_TIMEOUT(SendOpts), + get_opt(timeout, ?DEFAULT_ASYNC_GET_NEXT_TIMEOUT, SendOpts)). +-define(ASYNC_GET_BULK_TIMEOUT(SendOpts), + get_opt(timeout, ?DEFAULT_ASYNC_GET_BULK_TIMEOUT, SendOpts)). +-define(ASYNC_SET_TIMEOUT(SendOpts), + get_opt(timeout, ?DEFAULT_ASYNC_SET_TIMEOUT, SendOpts)). --define(GET_EXTRA(SendOpts), get_opt(extra, ?DEFAULT_EXTRA, SendOpts)). +-define(GET_EXTRA(SendOpts), get_opt(extra, ?DEFAULT_EXTRA_INFO, SendOpts)). -ifdef(snmp_debug). -define(GS_START_LINK(Args), @@ -246,10 +246,10 @@ sync_get2(UserId, TargetName, Oids, Opts) -> %% sync_get(UserId, TargetName, CtxName, Oids) -> sync_get(UserId, TargetName, CtxName, Oids, - ?SYNC_GET_TIMEOUT). + ?DEFAULT_SYNC_GET_TIMEOUT). sync_get(UserId, TargetName, CtxName, Oids, Timeout) -> - sync_get(UserId, TargetName, CtxName, Oids, Timeout, ?EXTRA_INFO). + sync_get(UserId, TargetName, CtxName, Oids, Timeout, ?DEFAULT_EXTRA_INFO). sync_get(UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo) when is_list(TargetName) andalso @@ -265,7 +265,7 @@ sync_get(UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo) %% -- [async] get -- async_get2(UserId, TargetName, Oids) -> - async_get2(UserId, TargetName, Oids, []) -> + async_get2(UserId, TargetName, Oids, []). async_get2(UserId, TargetName, Oids, SendOpts) -> call({async_get, self(), UserId, TargetName, Oids, SendOpts}). @@ -273,18 +273,18 @@ async_get2(UserId, TargetName, Oids, SendOpts) -> %% async_get(UserId, TargetName, CtxName, Oids) -> async_get(UserId, TargetName, CtxName, Oids, - ?DEFAULT_ASYNC_EXPIRE, ?EXTRA_INFO). + ?DEFAULT_ASYNC_GET_TIMEOUT, ?DEFAULT_EXTRA_INFO). async_get(UserId, TargetName, CtxName, Oids, Expire) -> - async_get(UserId, TargetName, CtxName, Oids, Expire, ?EXTRA_INFO). + async_get(UserId, TargetName, CtxName, Oids, Expire, ?DEFAULT_EXTRA_INFO). async_get(UserId, TargetName, CtxName, Oids, Expire, ExtraInfo) when (is_list(TargetName) andalso is_list(CtxName) andalso is_list(Oids) andalso is_integer(Expire) andalso (Expire >= 0)) -> - Opts = [{context, CtxName}, {expire, Expire}, {extra, ExtraInfo}], - async_get2(UserId, TargetName, Oids, Opts). + SendOpts = [{context, CtxName}, {expire, Expire}, {extra, ExtraInfo}], + async_get2(UserId, TargetName, Oids, SendOpts). %% @@ -293,25 +293,26 @@ async_get(UserId, TargetName, CtxName, Oids, Expire, ExtraInfo) sync_get_next2(UserId, TargetName, Oids) -> sync_get_next2(UserId, TargetName, Oids, []). -sync_get_next2(UserId, TargetName, Oids, Opts) -> - call({sync_get_next, self(), UserId, TargetName, Oids, Opts}). +sync_get_next2(UserId, TargetName, Oids, SendOpts) -> + call({sync_get_next, self(), UserId, TargetName, Oids, SendOpts}). %% sync_get_next(UserId, TargetName, CtxName, Oids) -> - sync_get_next(UserId, TargetName, CtxName, Oids, ?SYNC_GET_TIMEOUT, - ?EXTRA_INFO). + sync_get_next(UserId, TargetName, CtxName, Oids, + ?DEFAULT_SYNC_GET_TIMEOUT, ?DEFAULT_EXTRA_INFO). sync_get_next(UserId, TargetName, CtxName, Oids, Timeout) -> - sync_get_next(UserId, TargetName, CtxName, Oids, Timeout, ?EXTRA_INFO). + sync_get_next(UserId, TargetName, CtxName, Oids, Timeout, + ?DEFAULT_EXTRA_INFO). sync_get_next(UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo) when is_list(TargetName) andalso is_list(CtxName) andalso is_list(Oids) andalso is_integer(Timeout) -> - Opts = [{context, CtxName}, {timeout, Timeout}, {extra, ExtraInfo}), - sync_get_next2(UserId, TargetName, Oids, Opts). + SendOpts = [{context, CtxName}, {timeout, Timeout}, {extra, ExtraInfo}], + sync_get_next2(UserId, TargetName, Oids, SendOpts). %% @@ -321,23 +322,24 @@ sync_get_next(UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo) async_get_next2(UserId, TargetName, Oids) -> async_get_next2(UserId, TargetName, Oids, []). async_get_next2(UserId, TargetName, Oids, SendOpts) -> - call({async_get_next, self(), UserId, TargetName, Oids, Opts}). + call({async_get_next, self(), UserId, TargetName, Oids, SendOpts}). async_get_next(UserId, TargetName, CtxName, Oids) -> async_get_next(UserId, TargetName, CtxName, Oids, - ?DEFAULT_ASYNC_EXPIRE, ?EXTRA_INFO). + ?DEFAULT_ASYNC_GET_NEXT_TIMEOUT, ?DEFAULT_EXTRA_INFO). async_get_next(UserId, TargetName, CtxName, Oids, Expire) -> - async_get_next(UserId, TargetName, CtxName, Oids, Expire, ?EXTRA_INFO). + async_get_next(UserId, TargetName, CtxName, Oids, Expire, + ?DEFAULT_EXTRA_INFO). async_get_next(UserId, TargetName, CtxName, Oids, Expire, ExtraInfo) when (is_list(TargetName) andalso is_list(CtxName) andalso is_list(Oids) andalso is_integer(Expire) andalso (Expire >= 0)) -> - Opts = [{context, CtxName}, {expire, Expire}, {extra, ExtraInfo}), - async_get_next2(UserId, TargetName, Oids, Opts). + SendOpts = [{context, CtxName}, {expire, Expire}, {extra, ExtraInfo}], + async_get_next2(UserId, TargetName, Oids, SendOpts). @@ -352,12 +354,12 @@ sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts) -> sync_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids) -> sync_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids, - ?SYNC_GET_TIMEOUT, ?EXTRA_INFO). + ?DEFAULT_SYNC_GET_TIMEOUT, ?DEFAULT_EXTRA_INFO). sync_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids, Timeout) -> sync_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids, - Timeout, ?EXTRA_INFO). + Timeout, ?DEFAULT_EXTRA_INFO). sync_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids, Timeout, ExtraInfo) @@ -367,8 +369,8 @@ sync_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids, Timeout, is_list(CtxName) andalso is_list(Oids) andalso is_integer(Timeout) -> - Opts = [{context, CtxName}, {timeout, Timeout}, {extra, ExtraInfo}), - sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, Opts}). + SendOpts = [{context, CtxName}, {timeout, Timeout}, {extra, ExtraInfo}], + sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts). %% -- [async] get-bulk -- @@ -383,12 +385,12 @@ async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts) -> async_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids) -> async_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids, - ?DEFAULT_ASYNC_EXPIRE, ?EXTRA_INFO). + ?DEFAULT_ASYNC_GET_BULK_TIMEOUT, ?DEFAULT_EXTRA_INFO). async_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids, Expire) -> async_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids, - Expire, ?EXTRA_INFO). + Expire, ?DEFAULT_EXTRA_INFO). async_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids, Expire, ExtraInfo) @@ -398,8 +400,8 @@ async_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids, Expire, is_list(CtxName) andalso is_list(Oids) andalso is_integer(Expire) -> - Opts = [{context, CtxName}, {expire, Expire}, {extra, ExtraInfo}), - async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, Opts}). + SendOpts = [{context, CtxName}, {expire, Expire}, {extra, ExtraInfo}], + async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts). @@ -414,19 +416,19 @@ sync_set2(UserId, TargetName, VarsAndVals, SendOpts) -> sync_set(UserId, TargetName, CtxName, VarsAndVals) -> sync_set(UserId, TargetName, CtxName, VarsAndVals, - ?SYNC_SET_TIMEOUT, ?EXTRA_INFO). + ?DEFAULT_SYNC_SET_TIMEOUT, ?DEFAULT_EXTRA_INFO). sync_set(UserId, TargetName, CtxName, VarsAndVals, Timeout) -> sync_set(UserId, TargetName, CtxName, VarsAndVals, - Timeout, ?EXTRA_INFO). + Timeout, ?DEFAULT_EXTRA_INFO). sync_set(UserId, TargetName, CtxName, VarsAndVals, Timeout, ExtraInfo) when is_list(TargetName) andalso is_list(CtxName) andalso is_list(VarsAndVals) andalso is_integer(Timeout) -> - Opts = [{context, CtxName}, {timeout, Timeout}, {extra, ExtraInfo}), - sync_set2(UserId, TargetName, VarsAndVals, Opts}). + SendOpts = [{context, CtxName}, {timeout, Timeout}, {extra, ExtraInfo}], + sync_set2(UserId, TargetName, VarsAndVals, SendOpts). @@ -440,19 +442,19 @@ async_set2(UserId, TargetName, VarsAndVals, SendOpts) -> async_set(UserId, TargetName, CtxName, VarsAndVals) -> async_set(UserId, TargetName, CtxName, VarsAndVals, - ?DEFAULT_ASYNC_EXPIRE, ?EXTRA_INFO). + ?DEFAULT_ASYNC_SET_TIMEOUT, ?DEFAULT_EXTRA_INFO). async_set(UserId, TargetName, CtxName, VarsAndVals, Expire) -> async_set(UserId, TargetName, CtxName, VarsAndVals, - Expire, ?EXTRA_INFO). + Expire, ?DEFAULT_EXTRA_INFO). async_set(UserId, TargetName, CtxName, VarsAndVals, Expire, ExtraInfo) when (is_list(TargetName) andalso is_list(CtxName) andalso is_list(VarsAndVals) andalso is_integer(Expire) andalso (Expire >= 0)) -> - Opts = [{context, CtxName}, {expire, Expire}, {extra, ExtraInfo}), - async_set2(UserId, TargetName, VarsAndVals, Opts}). + SendOpts = [{context, CtxName}, {expire, Expire}, {extra, ExtraInfo}], + async_set2(UserId, TargetName, VarsAndVals, SendOpts). cancel_async_request(UserId, ReqId) -> @@ -687,8 +689,8 @@ handle_call({unregister_user, UserId}, _From, State) -> %% agent, or when the timeout hits (unless we get an error now). handle_call({sync_get, Pid, UserId, TargetName, Oids, SendOpts}, From, State) -> - ?vlog("[~p,~p] received sync_get request for" - "~n ~p", [UserId, TargetName, Opts]), + ?vlog("[~p,~p] received sync_get request for: " + "~n ~p", [UserId, TargetName, Oids]), case (catch handle_sync_get(Pid, UserId, TargetName, Oids, SendOpts, From, State)) of @@ -700,10 +702,11 @@ handle_call({sync_get, Pid, UserId, TargetName, Oids, SendOpts}, %% %% The only case where this would be called is during code upgrade -handle_call({sync_get, Pid, UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo}, +handle_call({sync_get, + Pid, UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo}, From, State) -> - ?vlog("[~p,~p] received sync_get request for" - "~n ~p", [UserId, TargetName, Opts]), + ?vlog("[~p,~p,~p] received sync_get request for: " + "~n ~p", [UserId, TargetName, CtxName, Oids]), case (catch handle_sync_get(Pid, UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo, From, State)) of @@ -718,7 +721,7 @@ handle_call({sync_get, Pid, UserId, TargetName, CtxName, Oids, Timeout, ExtraInf handle_call({sync_get_next, Pid, UserId, TargetName, Oids, SendOpts}, From, State) -> ?vlog("[~p,~p] received sync_get_next request for: " - "~n ~p", [UserId, TargetName, Opts]), + "~n ~p", [UserId, TargetName, SendOpts]), case (catch handle_sync_get_next(Pid, UserId, TargetName, Oids, SendOpts, From, State)) of @@ -731,10 +734,11 @@ handle_call({sync_get_next, Pid, UserId, TargetName, Oids, SendOpts}, %% %% The only case where this would be called is during code upgrade -handle_call({sync_get_next, Pid, UserId, TargetName, CtxName, Oids, - Timeout, ExtraInfo}, From, State) -> - ?vlog("[~p,~p] received sync_get_next request for" - "~n ~p", [UserId, TargetName, Opts]), +handle_call({sync_get_next, + Pid, UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo}, + From, State) -> + ?vlog("[~p,~p,~p] received sync_get_next request for" + "~n ~p", [UserId, TargetName, CtxName, Oids]), case (catch handle_sync_get_next(Pid, UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo, From, State)) of @@ -747,10 +751,11 @@ handle_call({sync_get_next, Pid, UserId, TargetName, CtxName, Oids, %% Check agent version? This op not in v1 -handle_call({sync_get_bulk, Pid, UserId, TargetName, - NonRep, MaxRep, Oids, SendOpts}, +handle_call({sync_get_bulk, + Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts}, From, State) -> - ?vlog("received sync_get_bulk [~p] request", [CtxName]), + ?vlog("[~p,~p] received sync_get_bulk request for: " + "~n ~p", [UserId, TargetName, Oids]), case (catch handle_sync_get_bulk(Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts, From, State)) of @@ -765,7 +770,8 @@ handle_call({sync_get_bulk, Pid, UserId, TargetName, handle_call({sync_get_bulk, Pid, UserId, TargetName, NonRep, MaxRep, CtxName, Oids, Timeout, ExtraInfo}, From, State) -> - ?vlog("received sync_get_bulk [~p] request", [CtxName]), + ?vlog("[~p,~p] received sync_get_bulk request for: ~p" + "~n ~p", [UserId, TargetName, CtxName, Oids]), case (catch handle_sync_get_bulk(Pid, UserId, TargetName, CtxName, NonRep, MaxRep, Oids, @@ -778,10 +784,28 @@ handle_call({sync_get_bulk, Pid, UserId, TargetName, %% +handle_call({sync_set, + Pid, UserId, TargetName, VarsAndVals, SendOpts}, + From, State) -> + ?vlog("[~p,~p] received sync_set request for: " + "~n ~p", [UserId, TargetName, VarsAndVals]), + case (catch handle_sync_set(Pid, + UserId, TargetName, VarsAndVals, SendOpts, + From, State)) of + ok -> + {noreply, State}; + Error -> + {reply, Error, State} + end; + + +%% +%% The only case where this would be called is during code upgrade handle_call({sync_set, Pid, UserId, TargetName, CtxName, VarsAndVals, Timeout, ExtraInfo}, From, State) -> - ?vlog("received sync_set [~p] request", [CtxName]), + ?vlog("[~p,~p,~p] received sync_set request for: " + "~n ~p", [UserId, TargetName, CtxName, VarsAndVals]), case (catch handle_sync_set(Pid, UserId, TargetName, CtxName, VarsAndVals, Timeout, ExtraInfo, From, State)) of @@ -790,45 +814,105 @@ handle_call({sync_set, Pid, UserId, TargetName, Error -> {reply, Error, State} end; +%% +handle_call({async_get, Pid, UserId, TargetName, Oids, SendOpts}, + _From, State) -> + ?vlog("[~p,~p] received async_get request for: " + "~n ~p", [UserId, TargetName, Oids]), + Reply = (catch handle_async_get(Pid, + UserId, TargetName, Oids, SendOpts, + State)), + {reply, Reply, State}; + + +%% +%% The only case where this would be called is during code upgrade handle_call({async_get, Pid, UserId, TargetName, CtxName, Oids, Expire, ExtraInfo}, _From, State) -> - ?vlog("received async_get [~p] request", [CtxName]), + ?vlog("[~p,~p,~p] received async_get request for: " + "~n ~p", [UserId, TargetName, CtxName, Oids]), Reply = (catch handle_async_get(Pid, UserId, TargetName, CtxName, Oids, Expire, ExtraInfo, State)), {reply, Reply, State}; +%% + + +handle_call({async_get_next, Pid, UserId, TargetName, Oids, SendOpts}, + _From, State) -> + ?vlog("[~p,~p] received async_get_next request for: " + "~n ~p", [UserId, TargetName, Oids]), + Reply = (catch handle_async_get_next(Pid, + UserId, TargetName, Oids, SendOpts, + State)), + {reply, Reply, State}; +%% +%% The only case where this would be called is during code upgrade handle_call({async_get_next, Pid, UserId, TargetName, CtxName, Oids, Expire, ExtraInfo}, _From, State) -> - ?vlog("received async_get_next [~p] request", [CtxName]), + ?vlog("[~p,~p,~p] received async_get_next request for: ", + [UserId, TargetName, CtxName, Oids]), Reply = (catch handle_async_get_next(Pid, UserId, TargetName, CtxName, Oids, Expire, ExtraInfo, State)), {reply, Reply, State}; +%% %% Check agent version? This op not in v1 +handle_call({async_get_bulk, + Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts}, + _From, State) -> + ?vlog("[~p,~p] received async_get_bulk request for: " + "~n ~p", [UserId, TargetName, Oids]), + Reply = (catch handle_async_get_bulk(Pid, + UserId, TargetName, + NonRep, MaxRep, Oids, SendOpts, + State)), + {reply, Reply, State}; + + +%% +%% The only case where this would be called is during code upgrade handle_call({async_get_bulk, Pid, UserId, TargetName, NonRep, MaxRep, CtxName, Oids, Expire, ExtraInfo}, _From, State) -> - ?vlog("received async_get_bulk [~p] request", [CtxName]), + ?vlog("[~p,~p,~p] received async_get_bulk request for: " + "~n ~p", [UserId, TargetName, CtxName, Oids]), Reply = (catch handle_async_get_bulk(Pid, UserId, TargetName, CtxName, NonRep, MaxRep, Oids, Expire, ExtraInfo, State)), {reply, Reply, State}; +%% +handle_call({async_set, + Pid, UserId, TargetName, VarsAndVals, SendOpts}, + _From, State) -> + ?vlog("[~p,~p] received async_set request for: " + "~n ~p", [UserId, TargetName, VarsAndVals]), + Reply = (catch handle_async_set(Pid, + UserId, TargetName, VarsAndVals, SendOpts, + State)), + {reply, Reply, State}; + + +%% +%% The only case where this would be called is during code upgrade handle_call({async_set, Pid, UserId, TargetName, CtxName, VarsAndVals, Expire, ExtraInfo}, _From, State) -> - ?vlog("received async_set [~p] request", [CtxName]), + ?vlog("[~p,~p,~p] received async_set request for: " + "~n ~p", [UserId, TargetName, CtxName, VarsAndVals]), Reply = (catch handle_async_set(Pid, UserId, TargetName, CtxName, VarsAndVals, Expire, ExtraInfo, State)), {reply, Reply, State}; +%% handle_call({cancel_async_request, UserId, ReqId}, _From, State) -> @@ -1297,16 +1381,17 @@ handle_async_get(Pid, UserId, TargetName, Oids, SendOpts, State) -> "~n Pid: ~p" "~n UserId: ~p" "~n TargetName: ~p" - "~n CtxName: ~p" "~n Oids: ~p" - "~n Expire: ~p", - [Pid, UserId, TargetName, CtxName, Oids, Expire]), + "~n SendOpts: ~p", + [Pid, UserId, TargetName, Oids, SendOpts]), case agent_data(TargetName, SendOpts) of {ok, RegType, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_async_get -> send a ~p message", [Vsn]), + Extra = ?GET_EXTRA(SendOpts), ReqId = send_get_request(Oids, Vsn, MsgData, Addr, Port, - ExtraInfo, State), + Extra, State), ?vdebug("handle_async_get -> ReqId: ~p", [ReqId]), + Expire = ?ASYNC_GET_TIMEOUT(SendOpts), Req = #request{id = ReqId, user_id = UserId, reg_type = RegType, @@ -1331,20 +1416,30 @@ handle_async_get(Pid, UserId, TargetName, Oids, SendOpts, State) -> handle_async_get_next(Pid, UserId, TargetName, CtxName, Oids, Expire, ExtraInfo, State) -> + SendOpts = + [ + {context, CtxName}, + {timeout, Expire}, + {extra, ExtraInfo} + ], + handle_async_get_next(Pid, UserId, TargetName, Oids, SendOpts, State). + +handle_async_get_next(Pid, UserId, TargetName, Oids, SendOpts, State) -> ?vtrace("handle_async_get_next -> entry with" "~n Pid: ~p" "~n UserId: ~p" "~n TargetName: ~p" - "~n CtxName: ~p" "~n Oids: ~p" "~n Expire: ~p", - [Pid, UserId, TargetName, CtxName, Oids, Expire]), + [Pid, UserId, TargetName, Oids, Expire]), case agent_data(TargetName, SendOpts) of {ok, RegType, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_async_get_next -> send a ~p message", [Vsn]), + Extra = ?GET_EXTRA(SendOpts), ReqId = send_get_next_request(Oids, Vsn, MsgData, - Addr, Port, ExtraInfo, State), + Addr, Port, Extra, State), ?vdebug("handle_async_get_next -> ReqId: ~p", [ReqId]), + Expire = ?ASYNC_GET_NEXT_TIMEOUT(SendOpts), Req = #request{id = ReqId, user_id = UserId, reg_type = RegType, @@ -1370,22 +1465,36 @@ handle_async_get_next(Pid, UserId, TargetName, CtxName, Oids, Expire, handle_async_get_bulk(Pid, UserId, TargetName, CtxName, NonRep, MaxRep, Oids, Expire, ExtraInfo, State) -> + SendOpts = + [ + {context, CtxName}, + {timeout, Expire}, + {extra, ExtraInfo} + ], + handle_async_get_bulk(Pid, + UserId, TargetName, NonRep, MaxRep, Oids, SendOpts, + State). + +handle_async_get_bulk(Pid, + UserId, TargetName, NonRep, MaxRep, Oids, SendOpts, + State) -> ?vtrace("handle_async_get_bulk -> entry with" "~n Pid: ~p" "~n UserId: ~p" "~n TargetName: ~p" - "~n CtxName: ~p" "~n NonRep: ~p" "~n MaxRep: ~p" "~n Oids: ~p" - "~n Expire: ~p", - [Pid, UserId, TargetName, CtxName, NonRep, MaxRep, Oids, Expire]), + "~n SendOpts: ~p", + [Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts]), case agent_data(TargetName, CtxName) of {ok, RegType, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_async_get_bulk -> send a ~p message", [Vsn]), + Extra = ?GET_EXTRA(SendOpts), ReqId = send_get_bulk_request(Oids, Vsn, MsgData, Addr, Port, - NonRep, MaxRep, ExtraInfo, State), + NonRep, MaxRep, Extra, State), ?vdebug("handle_async_get_bulk -> ReqId: ~p", [ReqId]), + Expire = ?ASYNC_GET_BULK_TIMEOUT(SendOpts), Req = #request{id = ReqId, user_id = UserId, reg_type = RegType, @@ -1409,20 +1518,30 @@ handle_async_get_bulk(Pid, UserId, TargetName, CtxName, handle_async_set(Pid, UserId, TargetName, CtxName, VarsAndVals, Expire, ExtraInfo, State) -> + SendOpts = + [ + {context, CtxName}, + {timeout, Expire}, + {extra, ExtraInfo} + ], + handle_async_set(Pid, UserId, TargetName, VarsAndVals, SendOpts, State). + +handle_async_set(Pid, UserId, TargetName, VarsAndVals, SendOpts, State) -> ?vtrace("handle_async_set -> entry with" "~n Pid: ~p" "~n UserId: ~p" "~n TargetName: ~p" - "~n CtxName: ~p" "~n VarsAndVals: ~p" - "~n Expire: ~p", - [Pid, UserId, TargetName, CtxName, VarsAndVals, Expire]), + "~n SendOpts: ~p", + [Pid, UserId, TargetName, VarsAndVals, SendOpts]), case agent_data(TargetName, SendOpts) of {ok, RegType, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_async_set -> send a ~p message", [Vsn]), + Extra = ?GET_EXTRA(SendOpts), ReqId = send_set_request(VarsAndVals, Vsn, MsgData, - Addr, Port, ExtraInfo, State), + Addr, Port, Extra, State), ?vdebug("handle_async_set -> ReqId: ~p", [ReqId]), + Expire = ?ASYNC_SET_TIMEOUT(SendOpts), Req = #request{id = ReqId, user_id = UserId, reg_type = RegType, -- cgit v1.2.3 From 21244028b693c6a1d4726b6a7d10bc947d9fb0f4 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 12 Apr 2011 15:29:54 +0200 Subject: First time through the compiler. --- lib/snmp/src/manager/snmpm.erl | 7 +++-- lib/snmp/src/manager/snmpm_internal.hrl | 2 ++ lib/snmp/src/manager/snmpm_server.erl | 51 +++++++++++++++++++-------------- 3 files changed, 36 insertions(+), 24 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/manager/snmpm.erl b/lib/snmp/src/manager/snmpm.erl index 36b4901e9a..7657f6df6e 100644 --- a/lib/snmp/src/manager/snmpm.erl +++ b/lib/snmp/src/manager/snmpm.erl @@ -145,12 +145,13 @@ -export([start_link/3, snmpm_start_verify/2, snmpm_start_verify/3]). --include("snmp_debug.hrl"). +-include_lib("snmp/src/misc/snmp_debug.hrl"). +-include_lib("snmp/include/snmp_types.hrl"). -include("snmpm_atl.hrl"). --include("snmp_types.hrl"). +-include("snmpm_internal.hrl"). -define(DEFAULT_AGENT_PORT, 161). --define(DEFAULT_CONTEXT, ""). +%% -define(DEFAULT_CONTEXT, ""). %% This function is called when the snmp application diff --git a/lib/snmp/src/manager/snmpm_internal.hrl b/lib/snmp/src/manager/snmpm_internal.hrl index 5d9b32e3f6..389aeaf197 100644 --- a/lib/snmp/src/manager/snmpm_internal.hrl +++ b/lib/snmp/src/manager/snmpm_internal.hrl @@ -20,6 +20,8 @@ -ifndef(snmpm_internal). -define(snmpm_internal, true). +-define(DEFAULT_CONTEXT, ""). + -include_lib("snmp/src/app/snmp_internal.hrl"). -define(snmpm_info(F, A), ?snmp_info("manager", F, A)). diff --git a/lib/snmp/src/manager/snmpm_server.erl b/lib/snmp/src/manager/snmpm_server.erl index cf29770244..3b49267994 100644 --- a/lib/snmp/src/manager/snmpm_server.erl +++ b/lib/snmp/src/manager/snmpm_server.erl @@ -237,8 +237,8 @@ unregister_user(UserId) -> %% The reason why we have a sync_get2 is to simplify backward %% compatibillity. -sync_get2(UserId, TargetName, Oids) -> - sync_get2(UserId, TargetName, Oids, []). +%% sync_get2(UserId, TargetName, Oids) -> +%% sync_get2(UserId, TargetName, Oids, []). sync_get2(UserId, TargetName, Oids, Opts) -> call({sync_get, self(), UserId, TargetName, Oids, Opts}). @@ -264,8 +264,8 @@ sync_get(UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo) %% -- [async] get -- -async_get2(UserId, TargetName, Oids) -> - async_get2(UserId, TargetName, Oids, []). +%% async_get2(UserId, TargetName, Oids) -> +%% async_get2(UserId, TargetName, Oids, []). async_get2(UserId, TargetName, Oids, SendOpts) -> call({async_get, self(), UserId, TargetName, Oids, SendOpts}). @@ -291,8 +291,8 @@ async_get(UserId, TargetName, CtxName, Oids, Expire, ExtraInfo) %% -- [sync] get-next -- -sync_get_next2(UserId, TargetName, Oids) -> - sync_get_next2(UserId, TargetName, Oids, []). +%% sync_get_next2(UserId, TargetName, Oids) -> +%% sync_get_next2(UserId, TargetName, Oids, []). sync_get_next2(UserId, TargetName, Oids, SendOpts) -> call({sync_get_next, self(), UserId, TargetName, Oids, SendOpts}). @@ -319,8 +319,8 @@ sync_get_next(UserId, TargetName, CtxName, Oids, Timeout, ExtraInfo) %% -- [async] get-next -- -async_get_next2(UserId, TargetName, Oids) -> - async_get_next2(UserId, TargetName, Oids, []). +%% async_get_next2(UserId, TargetName, Oids) -> +%% async_get_next2(UserId, TargetName, Oids, []). async_get_next2(UserId, TargetName, Oids, SendOpts) -> call({async_get_next, self(), UserId, TargetName, Oids, SendOpts}). @@ -345,8 +345,8 @@ async_get_next(UserId, TargetName, CtxName, Oids, Expire, ExtraInfo) %% -- [sync] get-bulk -- -sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids) -> - sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, []). +%% sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids) -> +%% sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, []). sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts) -> call({sync_get_bulk, self(), UserId, TargetName, NonRep, MaxRep, Oids, SendOpts}). @@ -375,8 +375,8 @@ sync_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids, Timeout, %% -- [async] get-bulk -- -async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids) -> - async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, []). +%% async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids) -> +%% async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, []). async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts) -> call({async_get_bulk, self(), UserId, TargetName, NonRep, MaxRep, Oids, SendOpts}). @@ -408,8 +408,8 @@ async_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids, Expire, %% -- [sync] set -- %% VarsAndValues is: {PlainOid, o|s|i, Value} (unknown mibs) | {Oid, Value} -sync_set2(UserId, TargetName, VarsAndVals) -> - sync_set2(UserId, TargetName, VarsAndVals, []). +%% sync_set2(UserId, TargetName, VarsAndVals) -> +%% sync_set2(UserId, TargetName, VarsAndVals, []). sync_set2(UserId, TargetName, VarsAndVals, SendOpts) -> call({sync_set, self(), UserId, TargetName, VarsAndVals, SendOpts}). @@ -434,8 +434,8 @@ sync_set(UserId, TargetName, CtxName, VarsAndVals, Timeout, ExtraInfo) %% -- [async] set -- -async_set2(UserId, TargetName, VarsAndVals) -> - async_set2(UserId, TargetName, VarsAndVals, []). +%% async_set2(UserId, TargetName, VarsAndVals) -> +%% async_set2(UserId, TargetName, VarsAndVals, []). async_set2(UserId, TargetName, VarsAndVals, SendOpts) -> call({async_set, self(), UserId, TargetName, VarsAndVals, SendOpts}). @@ -1430,8 +1430,8 @@ handle_async_get_next(Pid, UserId, TargetName, Oids, SendOpts, State) -> "~n UserId: ~p" "~n TargetName: ~p" "~n Oids: ~p" - "~n Expire: ~p", - [Pid, UserId, TargetName, Oids, Expire]), + "~n SendOpts: ~p", + [Pid, UserId, TargetName, Oids, SendOpts]), case agent_data(TargetName, SendOpts) of {ok, RegType, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_async_get_next -> send a ~p message", [Vsn]), @@ -1487,7 +1487,7 @@ handle_async_get_bulk(Pid, "~n Oids: ~p" "~n SendOpts: ~p", [Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts]), - case agent_data(TargetName, CtxName) of + case agent_data(TargetName, SendOpts) of {ok, RegType, Addr, Port, Vsn, MsgData} -> ?vtrace("handle_async_get_bulk -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), @@ -3146,6 +3146,9 @@ agent_data(TargetName, SendOpts) -> DefSecLevel = agent_data_item(sec_level, Info), EngineId = agent_data_item(engine_id, Info), + CtxName = agent_data_item(context, + SendOpts, + ?DEFAULT_CONTEXT), SecModel = agent_data_item(sec_model, SendOpts, @@ -3164,10 +3167,10 @@ agent_data(TargetName, SendOpts) -> DefSecModel = agent_data_item(sec_model, Info), Comm = agent_data_item(community, - SendOPts, + SendOpts, DefComm), SecModel = agent_data_item(sec_model, - SendOPts, + SendOpts, DefSecModel), {Comm, SecModel} @@ -3334,6 +3337,12 @@ default_agent_config() -> end. +%%---------------------------------------------------------------------- + +get_opt(Key, Default, Opts) -> + proplists:get_value(Key, Opts, Default). + + %%---------------------------------------------------------------------- is_started(#state{net_if = _Pid, net_if_mod = _Mod}) -> -- cgit v1.2.3 From 6f7913a20db1f59a67cc22ae3b6ce6d4d013deee Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 13 Apr 2011 12:05:20 +0200 Subject: Proper interface documentation for new API. Also release notes with links into API. --- lib/snmp/doc/src/notes.xml | 23 ++- lib/snmp/doc/src/snmpm.xml | 354 ++++++++++++++++++++++++++++----------------- 2 files changed, 247 insertions(+), 130 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index f5fa7065fb..11d2a513df 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -53,9 +53,30 @@

Aux Id: Seq 11790

+ +

[manager] The API for snmp requests has been changed to + allow the caller to override some configuration.

+

See + sync_get/3,4, + async_get/3,4, + sync_get_next/3,4, + async_get_next/3,4, + sync_get_bulk/5,6, + async_get_bulk/5,6, + sync_set/3,4 and + async_set/3,4 + for more info.

+

Own Id: OTP-9162

+
+

[manager] The old API functions (for get and set - requests) are now officially deprecated. + requests: + snmpm:g/3,4,5,6,7, snmpm:ag/3,4,5,6,7, + snmpm:gn/3,4,5,6,7, snmpm:agn/3,4,5,6,7, + snmpm:s/3,4,5,6,7, snmpm:s/3,4,5,6,7, + snmpm:gb/5,6,7,8,9 and snmpm:agb/5,6,7,8,9) + are now officially deprecated. They will be removed as of R16B.

Own Id: OTP-9174

diff --git a/lib/snmp/doc/src/snmpm.xml b/lib/snmp/doc/src/snmpm.xml index 1ee391d9ba..db7abd6867 100644 --- a/lib/snmp/doc/src/snmpm.xml +++ b/lib/snmp/doc/src/snmpm.xml @@ -1,4 +1,4 @@ - + @@ -63,6 +63,10 @@ value_type() = o ('OBJECT IDENTIFIER') | c64 ('Counter64') | tt ('TimeTicks') value() = term() +community() = string() +sec_model() = any | v1 | v2c | usm +sec_name() = string() +sec_level() = noAuthNoPriv | authNoPriv | authPriv ]]> @@ -488,22 +492,20 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1 sync_get(UserId, TargetName, Oids) -> {ok, SnmpReply, Remaining} | {error, Reason} - sync_get(UserId, TargetName, ContextName, Oids) -> {ok, SnmpReply, Remaining} | {error, Reason} - sync_get(UserId, TargetName, Oids, Timeout) -> {ok, SnmpReply, Remaining} | {error, Reason} - sync_get(UserId, TargetName, ContextName, Oids, Timeout) -> {ok, SnmpReply, Remaining} | {error, Reason} - sync_get(UserId, TargetName, ContextName, Oids, Timeout, ExtraInfo) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_get(UserId, TargetName, Oids, SendOpts) -> {ok, SnmpReply, Remaining} | {error, Reason} Synchronous get-request UserId = term() TargetName = target_name() - ContextName = string() Oids = [oid()] - Timeout = integer() - ExtraInfo = term() + SendOpts = send_opts() + send_opts() = [send_opt()] + send_opt() = {context, string()} | {timeout, pos_integer()} | {extra, term()} | {community, community()} | {sec_model, sec_model()} | {sec_name, string()} | {sec_level, sec_level()} | {max_message_size, pos_integer()} SnmpReply = snmp_reply() Remaining = integer() - Reason = {send_failed, ReqId, R} | {invalid_sec_info, SecInfo, SnmpInfo} | term() - R = term() + Reason = {send_failed, ReqId, ActualReason} | {invalid_sec_info, SecInfo, SnmpInfo} | term() + ReqId = term() + ActualReason = term() SecInfo = [sec_info()] sec_info() = {sec_tag(), ExpectedValue, ReceivedValue} sec_tag() = atom() @@ -512,19 +514,29 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

Synchronous get-request.

-

Remaining is the remaining time of the given or - default timeout time.

+ +

Remaining is the remaining time of the given (or default) + timeout time.

+

When Reason is {send_failed, ...} it means that - the net_if process failed to send the message. This could happen - because of any number of reasons, i.e. encoding error. R - is the actual reason in this case.

-

ExtraInfo is an opaque data structure passed on to - the net-if process. The net-if process included in this - application makes no use of this info, so the only use for it - in such a configuration (when using the built in net-if) would - be tracing.

-

For SnmpInfo, see the user callback function - handle_report.

+ the net_if process failed to send the message. This could happen + because of any number of reasons, i.e. encoding error. + ActualReason is the actual reason in this case.

+ +

The send option extra specifies an opaque data structure + passed on to the net-if process. The net-if process included in this + application makes no use of this info, so the only use for it + in such a option (when using the built in net-if) would + be tracing.

+ +

Some of the send options (community, sec_model, + sec_name, sec_level and max_message_size) + are override options. That is, + for this request, they override any configuration done + when the agent was registered.

+ +

For SnmpInfo, see the user callback function + handle_report.

@@ -532,33 +544,39 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1 async_get(UserId, TargetName, Oids) -> {ok, ReqId} | {error, Reason} - async_get(UserId, TargetName, ContextName, Oids) -> {ok, ReqId} | {error, Reason} - async_get(UserId, TargetName, Oids, Expire) -> {ok, ReqId} | {error, Reason} - async_get(UserId, TargetName, ContextName, Oids, Expire) -> {ok, ReqId} | {error, Reason} - async_get(UserId, TargetName, ContextName, Oids, Expire, ExtraInfo) -> {ok, ReqId} | {error, Reason} + async_get(UserId, TargetName, Oids, SendOpts) -> {ok, ReqId} | {error, Reason} Asynchronous get-request UserId = term() TargetName = target_name() - ContextName = string() Oids = [oid()] - Expire = integer() - ExtraInfo = term() + SendOpts = send_opts() + send_opts() = [send_opt()] + send_opt() = {context, string()} | {timeout, pos_integer()} | {extra, term()} | {community, community()} | {sec_model, sec_model()} | {sec_name, string()} | {sec_level, sec_level()} | {max_message_size, pos_integer()} ReqId = term() Reason = term()

Asynchronous get-request.

+

The reply, if it arrives, will be delivered to the user - through a call to the snmpm_user callback function - handle_pdu.

-

The Expire time indicates for how long the request is - valid (after which the manager is free to delete it).

-

ExtraInfo is an opaque data structure passed on to - the net-if process. The net-if process included in this - application makes no use of this info, so the only use for it - in such a configuration (when using the built in net-if) would - be tracing.

+ through a call to the snmpm_user callback function + handle_pdu.

+ +

The send option timeout specifies for how long the request is + valid (after which the manager is free to delete it).

+ +

The send option extra specifies an opaque data structure + passed on to the net-if process. The net-if process included in this + application makes no use of this info, so the only use for it + in such a configuration (when using the built in net-if) would + be tracing.

+ +

Some of the send options (community, sec_model, + sec_name, sec_level and max_message_size) + are override options. That is, + for this request, they override any configuration done + when the agent was registered.

@@ -566,35 +584,51 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1 sync_get_next(UserId, TargetName, Oids) -> {ok, SnmpReply, Remaining} | {error, Reason} - sync_get_next(UserId, TargetName, ContextName, Oids) -> {ok, SnmpReply, Remaining} | {error, Reason} - sync_get_next(UserId, TargetName, Oids, Timeout) -> {ok, SnmpReply, Remaining} | {error, Reason} - sync_get_next(UserId, TargetName, ContextName, Oids, Timeout) -> {ok, SnmpReply, Remaining} | {error, Reason} - sync_get_next(UserId, TargetName, ContextName, Oids, Timeout, ExtraInfo) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_get_next(UserId, TargetName, Oids, SendOpts) -> {ok, SnmpReply, Remaining} | {error, Reason} Synchronous get-next-request UserId = term() TargetName = target_name() - ContextName = string() Oids = [oid()] - Timeout = integer() - ExtraInfo = term() + SendOpts = send_opts() + send_opts() = [send_opt()] + send_opt() = {context, string()} | {timeout, pos_integer()} | {extra, term()} | {community, community()} | {sec_model, sec_model()} | {sec_name, string()} | {sec_level, sec_level()} | {max_message_size, pos_integer()} SnmpReply = snmp_reply() Remaining = integer() - Reason = {send_failed, ReqId, R} | {invalid_sec_info, SecInfo, SnmpInfo} | term() - R = term() + Reason = {send_failed, ReqId, ActualReason} | {invalid_sec_info, SecInfo, SnmpInfo} | term() + ReqId = term() + ActualReason = term() + SecInfo = [sec_info()] + sec_info() = {sec_tag(), ExpectedValue, ReceivedValue} + sec_tag() = atom() + ExpectedValue = ReceivedValue = term() + SnmpInfo = term()

Synchronous get-next-request.

-

Remaining time of the given or default timeout time.

+ +

Remaining is the remaining time of the given (or default) + timeout time.

+

When Reason is {send_failed, ...} it means that - the net_if process failed to send the message. This could happen - because of any number of reasons, i.e. encoding error. R - is the actual reason in this case.

-

ExtraInfo is an opaque data structure passed on to - the net-if process. The net-if process included in this - application makes no use of this info, so the only use for it - in such a configuration (when using the built in net-if) would - be tracing.

+ the net_if process failed to send the message. This could happen + because of any number of reasons, i.e. encoding error. + ActualReason is the actual reason in this case.

+ +

The send option extra specifies an opaque data structure + passed on to the net-if process. The net-if process included in this + application makes no use of this info, so the only use for it + in such a configuration (when using the built in net-if) would + be tracing.

+ +

Some of the send options (community, sec_model, + sec_name, sec_level and max_message_size) + are override options. That is, + for this request, they override any configuration done + when the agent was registered.

+ +

For SnmpInfo, see the user callback function + handle_report.

@@ -602,27 +636,36 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1 async_get_next(UserId, TargetName, Oids) -> {ok, ReqId} | {error, Reason} - async_get_next(UserId, TargetName, ContextName, Oids) -> {ok, ReqId} | {error, Reason} - async_get_next(UserId, TargetName, Oids, Expire) -> {ok, ReqId} | {error, Reason} - async_get_next(UserId, TargetName, ContextName, Oids, Expire) -> {ok, ReqId} | {error, Reason} - async_get_next(UserId, TargetName, ContextName, Oids, Expire, ExtraInfo) -> {ok, ReqId} | {error, Reason} + async_get_next(UserId, TargetName, Oids, SendOpts) -> {ok, ReqId} | {error, Reason} Asynchronous get-next-request UserId = term() TargetName = target_name() - ContextName = string() Oids = [oid()] - Expire = integer() - ExtraInfo = term() + send_opt() = {context, string()} | {timeout, pos_integer()} | {extra, term()} | {community, community()} | {sec_model, sec_model()} | {sec_name, string()} | {sec_level, sec_level()} | {max_message_size, pos_integer()} ReqId = integer() Reason = term()

Asynchronous get-next-request.

+

The reply will be delivered to the user through a call - to the snmpm_user callback function handle_pdu.

-

The Expire time indicates for how long the request is - valid (after which the manager is free to delete it).

+ to the snmpm_user callback function handle_pdu.

+ +

The send option timeout specifies for how long the request is + valid (after which the manager is free to delete it).

+ +

The send option extra specifies an opaque data structure + passed on to the net-if process. The net-if process included in this + application makes no use of this info, so the only use for it + in such a configuration (when using the built in net-if) would + be tracing.

+ +

Some of the send options (community, sec_model, + sec_name, sec_level and max_message_size) + are override options. That is, + for this request, they override any configuration done + when the agent was registered.

@@ -630,37 +673,54 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1 sync_set(UserId, TargetName, VarsAndVals) -> {ok, SnmpReply, Remaining} | {error, Reason} - sync_set(UserId, TargetName, ContextName, VarsAndVals) -> {ok, SnmpReply, Remaining} | {error, Reason} - sync_set(UserId, TargetName, VarsAndVals, Timeout) -> {ok, SnmpReply, Remaining} | {error, Reason} - sync_set(UserId, TargetName, ContextName, VarsAndVals, Timeout) -> {ok, SnmpReply, Remaining} | {error, Reason} - sync_set(UserId, TargetName, ContextName, VarsAndVals, Timeout, ExtraInfo) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_set(UserId, TargetName, VarsAndVals, SendOpts) -> {ok, SnmpReply, Remaining} | {error, Reason} Synchronous set-request UserId = term() TargetName = target_name() - ContextName = string() VarsAndVals = vars_and_vals() - Timeout = integer() - ExtraInfo = term() + SendOpts = send_opts() + send_opts() = [send_opt()] + send_opt() = {context, string()} | {timeout, pos_integer()} | {extra, term()} | {community, community()} | {sec_model, sec_model()} | {sec_name, string()} | {sec_level, sec_level()} | {max_message_size, pos_integer()} SnmpReply = snmp_reply() Remaining = integer() Reason = {send_failed, ReqId, ActualReason} | {invalid_sec_info, SecInfo, SnmpInfo} | term() + ReqId = term() ActualReason = term() + SecInfo = [sec_info()] + sec_info() = {sec_tag(), ExpectedValue, ReceivedValue} + sec_tag() = atom() + ExpectedValue = ReceivedValue = term() + SnmpInfo = term()

Synchronous set-request.

-

Remaining time of the given or default timeout time.

-

When Reason is {send_failed, ...} it means that - the net_if process failed to send the message. This could happen - because of any number of reasons, i.e. encoding error. R - is the actual reason in this case.

-

When var_and_val() is {oid(), value()}, the - manager makes an educated guess based on the loaded mibs.

-

ExtraInfo is an opaque data structure passed on to - the net-if process. The net-if process included in this - application makes no use of this info, so the only use for it - in such a configuration (when using the built in net-if) would - be tracing.

+ +

Remaining is the remaining time of the given (or default) + timeout time.

+ +

When Reason is {send_failed, ...} it means that + the net_if process failed to send the message. This could happen + because of any number of reasons, i.e. encoding error. + ActualReason is the actual reason in this case.

+ +

When var_and_val() is {oid(), value()}, the + manager makes an educated guess based on the loaded mibs.

+ +

The send option extra specifies an opaque data structure + passed on to the net-if process. The net-if process included in this + application makes no use of this info, so the only use for it + in such a configuration (when using the built in net-if) would + be tracing.

+ +

Some of the send options (community, sec_model, + sec_name, sec_level and max_message_size) + are override options. That is, + for this request, they override any configuration done + when the agent was registered.

+ +

For SnmpInfo, see the user callback function + handle_report.

@@ -668,33 +728,41 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1 async_set(UserId, TargetName, VarsAndVals) -> {ok, ReqId} | {error, Reason} - async_set(UserId, TargetName, ContextName, VarsAndVals) -> {ok, ReqId} | {error, Reason} - async_set(UserId, TargetName, VarsAndVals, Expire) -> {ok, ReqId} | {error, Reason} - async_set(UserId, TargetName, ContextName, VarsAndVals, Expire) -> {ok, ReqId} | {error, Reason} - async_set(UserId, TargetName, ContextName, VarsAndVals, Expire, ExtraInfo) -> {ok, ReqId} | {error, Reason} + async_set(UserId, TargetName, VarsAndVals, SendOpts) -> {ok, ReqId} | {error, Reason} Asynchronous set-request UserId = term() TargetName = target_name() VarsAndVals = vars_and_vals() - Expire = integer() - ExtraInfo = term() + SendOpts = send_opts() + send_opts() = [send_opt()] + send_opt() = {context, string()} | {timeout, pos_integer()} | {extra, term()} | {community, community()} | {sec_model, sec_model()} | {sec_name, string()} | {sec_level, sec_level()} | {max_message_size, pos_integer()} ReqId = term() Reason = term()

Asynchronous set-request.

-

The reply will be delivered to the user through a call - to the snmpm_user callback function handle_pdu.

-

The Expire time indicates for how long the request is - valid (after which the manager is free to delete it).

-

When var_and_val() is {oid(), value()}, the - manager makes an educated guess based on the loaded mibs.

-

ExtraInfo is an opaque data structure passed on to - the net-if process. The net-if process included in this - application makes no use of this info, so the only use for it - in such a configuration (when using the built in net-if) would - be tracing.

+ +

The reply will be delivered to the user through a call + to the snmpm_user callback function handle_pdu.

+ +

The send option timeout specifies for how long the request is + valid (after which the manager is free to delete it).

+ +

When var_and_val() is {oid(), value()}, the + manager makes an educated guess based on the loaded mibs.

+ +

The send option extra specifies an opaque data structure + passed on to the net-if process. The net-if process included in this + application makes no use of this info, so the only use for it + in such a configuration (when using the built in net-if) would + be tracing.

+ +

Some of the send options (community, sec_model, + sec_name, sec_level and max_message_size) + are override options. That is, + for this request, they override any configuration done + when the agent was registered.

@@ -702,36 +770,53 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1 sync_get_bulk(UserId, TragetName, NonRep, MaxRep, Oids) -> {ok, SnmpReply, Remaining} | {error, Reason} - sync_get_bulk(UserId, TragetName, NonRep, MaxRep, ContextName, Oids) -> {ok, SnmpReply, Remaining} | {error, Reason} - sync_get_bulk(UserId, TragetName, NonRep, MaxRep, Oids, Timeout) -> {ok, SnmpReply, Remaining} | {error, Reason} - sync_get_bulk(UserId, TragetName, NonRep, MaxRep, ContextName, Oids, Timeout) -> {ok, SnmpReply, Remaining} | {error, Reason} - sync_get_bulk(UserId, TragetName, NonRep, MaxRep, ContextName, Oids, Timeout, ExtraInfo) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_get_bulk(UserId, TragetName, NonRep, MaxRep, Oids, SendOpts) -> {ok, SnmpReply, Remaining} | {error, Reason} Synchronous get-bulk-request UserId = term() TargetName = target_name() NonRep = integer() MaxRep = integer() - ContextName = string() Oids = [oid()] - Timeout = integer() - ExtraInfo = term() + SendOpts = send_opts() + send_opts() = [send_opt()] + send_opt() = {context, string()} | {timeout, pos_integer()} | {extra, term()} | {community, community()} | {sec_model, sec_model()} | {sec_name, string()} | {sec_level, sec_level()} | {max_message_size, pos_integer()} SnmpReply = snmp_reply() Remaining = integer() - Reason = {send_failed, ReqId, R} | {invalid_sec_info, SecInfo, SnmpInfo} | term() + Reason = {send_failed, ReqId, ActualReason} | {invalid_sec_info, SecInfo, SnmpInfo} | term() + ReqId = term() + ActualReason = term() + SecInfo = [sec_info()] + sec_info() = {sec_tag(), ExpectedValue, ReceivedValue} + sec_tag() = atom() + ExpectedValue = ReceivedValue = term() + SnmpInfo = term()

Synchronous get-bulk-request (See RFC1905).

-

Remaining time of the given or default timeout time.

+ +

Remaining is the remaining time of the given (or default) + timeout time.

+

When Reason is {send_failed, ...} it means that - the net_if process failed to send the message. This could happen - because of any number of reasons, i.e. encoding error. R - is the actual reason in this case.

-

ExtraInfo is an opaque data structure passed on to - the net-if process. The net-if process included in this - application makes no use of this info, so the only use for it - in such a configuration (when using the built in net-if) would - be tracing.

+ the net_if process failed to send the message. This could happen + because of any number of reasons, i.e. encoding error. + ActualReason is the actual reason in this case.

+ +

The send option extra specifies an opaque data structure + passed on to the net-if process. The net-if process included in this + application makes no use of this info, so the only use for it + in such a configuration (when using the built in net-if) would + be tracing.

+ +

Some of the send options (community, sec_model, + sec_name, sec_level and max_message_size) + are override options. That is, + for this request, they override any configuration done + when the agent was registered.

+ +

For SnmpInfo, see the user callback function + handle_report.

@@ -739,29 +824,40 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1 async_get_bulk(UserId, TargetName, NonRep, MaxRep, Oids) -> {ok, ReqId} | {error, Reason} - async_get_bulk(UserId, TargetName, NonRep, MaxRep, ContextName, Oids) -> {ok, ReqId} | {error, Reason} - async_get_bulk(UserId, TargetName, NonRep, MaxRep, Oids, Expire) -> {ok, ReqId} | {error, Reason} - async_get_bulk(UserId, TargetName, NonRep, MaxRep, ContextName, Oids, Expire) -> {ok, ReqId} | {error, Reason} - async_get_bulk(UserId, TargetName, NonRep, MaxRep, ContextName, Oids, Expire, ExtraInfo) -> {ok, ReqId} | {error, Reason} + async_get_bulk(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts) -> {ok, ReqId} | {error, Reason} Asynchronous get-bulk-request UserId = term() TargetName = target_name() NonRep = integer() MaxRep = integer() - ContextName = string() Oids = [oid()] - Expire = integer() - ExtraInfo = term() + SendOpts = send_opts() + send_opts() = [send_opt()] + send_opt() = {context, string()} | {timeout, pos_integer()} | {extra, term()} | {community, community()} | {sec_model, sec_model()} | {sec_name, string()} | {sec_level, sec_level()} | {max_message_size, pos_integer()} ReqId = integer() Reason = term()

Asynchronous get-bulk-request (See RFC1905).

+

The reply will be delivered to the user through a call - to the snmpm_user callback function handle_pdu.

-

The Expire time indicates for how long the request is - valid (after which the manager is free to delete it).

+ to the snmpm_user callback function handle_pdu.

+ +

The send option timeout specifies for how long the request is + valid (after which the manager is free to delete it).

+ +

The send option extra specifies an opaque data structure + passed on to the net-if process. The net-if process included in this + application makes no use of this info, so the only use for it + in such a configuration (when using the built in net-if) would + be tracing.

+ +

Some of the send options (community, sec_model, + sec_name, sec_level and max_message_size) + are override options. That is, + for this request, they override any configuration done + when the agent was registered.

-- cgit v1.2.3 From 32aa680d7b2a06299f2cf37d54496060fff1b44a Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 14 Apr 2011 09:07:04 +0200 Subject: Final version of the (new) API. --- lib/snmp/doc/src/notes.xml | 24 +- lib/snmp/doc/src/snmpm.xml | 48 ++-- lib/snmp/src/manager/snmpm.erl | 402 ++++++++++++++++++++++++++-------- lib/snmp/src/manager/snmpm_server.erl | 8 + lib/snmp/test/snmp_manager_test.erl | 208 +++++++++++------- lib/snmp/test/snmp_manager_user.erl | 6 +- 6 files changed, 483 insertions(+), 213 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 11d2a513df..ae00c42a7c 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -54,17 +54,17 @@ -

[manager] The API for snmp requests has been changed to +

[manager] The API for snmp requests has been augmented to allow the caller to override some configuration.

-

See - sync_get/3,4, - async_get/3,4, - sync_get_next/3,4, - async_get_next/3,4, - sync_get_bulk/5,6, - async_get_bulk/5,6, - sync_set/3,4 and - async_set/3,4 +

This has been done by introducing a new set of API functions, see + sync_get2/3,4, + async_get2/3,4, + sync_get_next2/3,4, + async_get_next2/3,4, + sync_get_bulk2/5,6, + async_get_bulk2/5,6, + sync_set2/3,4 and + async_set2/3,4 for more info.

Own Id: OTP-9162

@@ -304,7 +304,7 @@ snmp_view_basec_acm_mib:vacmAccessTable(set, RowIndex, Cols).

The config utility (snmp:config/0) generated a default notify.conf - with a bad name for the starndard trap entry (was "stadard trap", + with a bad name for the standard trap entry (was "stadard trap", but should have been "standard trap"). This has been corrected.

Kenji Rikitake

Own Id: OTP-8433

@@ -508,7 +508,7 @@ snmp_view_basec_acm_mib:vacmAccessTable(set, RowIndex, Cols).

The config utility (snmp:config/0) generated a default notify.conf - with a bad name for the starndard trap entry (was "stadard trap", + with a bad name for the standard trap entry (was "stadard trap", but should have been "standard trap"). This has been corrected.

Kenji Rikitake

Own Id: OTP-8433

diff --git a/lib/snmp/doc/src/snmpm.xml b/lib/snmp/doc/src/snmpm.xml index db7abd6867..ff072205bc 100644 --- a/lib/snmp/doc/src/snmpm.xml +++ b/lib/snmp/doc/src/snmpm.xml @@ -486,13 +486,13 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

Get a list of all registered usm users with engine-id EngineID.

- +
- sync_get(UserId, TargetName, Oids) -> {ok, SnmpReply, Remaining} | {error, Reason} - sync_get(UserId, TargetName, Oids, SendOpts) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_get2(UserId, TargetName, Oids) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_get2(UserId, TargetName, Oids, SendOpts) -> {ok, SnmpReply, Remaining} | {error, Reason} Synchronous get-request UserId = term() @@ -538,13 +538,13 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

For SnmpInfo, see the user callback function handle_report.

- +
- async_get(UserId, TargetName, Oids) -> {ok, ReqId} | {error, Reason} - async_get(UserId, TargetName, Oids, SendOpts) -> {ok, ReqId} | {error, Reason} + async_get2(UserId, TargetName, Oids) -> {ok, ReqId} | {error, Reason} + async_get2(UserId, TargetName, Oids, SendOpts) -> {ok, ReqId} | {error, Reason} Asynchronous get-request UserId = term() @@ -578,13 +578,13 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1 for this request, they override any configuration done when the agent was registered.

- +
- sync_get_next(UserId, TargetName, Oids) -> {ok, SnmpReply, Remaining} | {error, Reason} - sync_get_next(UserId, TargetName, Oids, SendOpts) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_get_next2(UserId, TargetName, Oids) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_get_next2(UserId, TargetName, Oids, SendOpts) -> {ok, SnmpReply, Remaining} | {error, Reason} Synchronous get-next-request UserId = term() @@ -630,13 +630,13 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

For SnmpInfo, see the user callback function handle_report.

- +
- async_get_next(UserId, TargetName, Oids) -> {ok, ReqId} | {error, Reason} - async_get_next(UserId, TargetName, Oids, SendOpts) -> {ok, ReqId} | {error, Reason} + async_get_next2(UserId, TargetName, Oids) -> {ok, ReqId} | {error, Reason} + async_get_next2(UserId, TargetName, Oids, SendOpts) -> {ok, ReqId} | {error, Reason} Asynchronous get-next-request UserId = term() @@ -667,13 +667,13 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1 for this request, they override any configuration done when the agent was registered.

- +
- sync_set(UserId, TargetName, VarsAndVals) -> {ok, SnmpReply, Remaining} | {error, Reason} - sync_set(UserId, TargetName, VarsAndVals, SendOpts) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_set2(UserId, TargetName, VarsAndVals) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_set2(UserId, TargetName, VarsAndVals, SendOpts) -> {ok, SnmpReply, Remaining} | {error, Reason} Synchronous set-request UserId = term() @@ -722,13 +722,13 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

For SnmpInfo, see the user callback function handle_report.

- +
- async_set(UserId, TargetName, VarsAndVals) -> {ok, ReqId} | {error, Reason} - async_set(UserId, TargetName, VarsAndVals, SendOpts) -> {ok, ReqId} | {error, Reason} + async_set2(UserId, TargetName, VarsAndVals) -> {ok, ReqId} | {error, Reason} + async_set2(UserId, TargetName, VarsAndVals, SendOpts) -> {ok, ReqId} | {error, Reason} Asynchronous set-request UserId = term() @@ -764,13 +764,13 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1 for this request, they override any configuration done when the agent was registered.

- +
- sync_get_bulk(UserId, TragetName, NonRep, MaxRep, Oids) -> {ok, SnmpReply, Remaining} | {error, Reason} - sync_get_bulk(UserId, TragetName, NonRep, MaxRep, Oids, SendOpts) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_get_bulk2(UserId, TragetName, NonRep, MaxRep, Oids) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_get_bulk2(UserId, TragetName, NonRep, MaxRep, Oids, SendOpts) -> {ok, SnmpReply, Remaining} | {error, Reason} Synchronous get-bulk-request UserId = term() @@ -818,13 +818,13 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

For SnmpInfo, see the user callback function handle_report.

- +
- async_get_bulk(UserId, TargetName, NonRep, MaxRep, Oids) -> {ok, ReqId} | {error, Reason} - async_get_bulk(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts) -> {ok, ReqId} | {error, Reason} + async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids) -> {ok, ReqId} | {error, Reason} + async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts) -> {ok, ReqId} | {error, Reason} Asynchronous get-bulk-request UserId = term() diff --git a/lib/snmp/src/manager/snmpm.erl b/lib/snmp/src/manager/snmpm.erl index 7657f6df6e..dd85ec9f41 100644 --- a/lib/snmp/src/manager/snmpm.erl +++ b/lib/snmp/src/manager/snmpm.erl @@ -57,15 +57,16 @@ usm_user_info/3, update_usm_user_info/4, %% - %% Basic SNMP API - sync_get/3, sync_get/4, sync_get/5, sync_get/6, - async_get/3, async_get/4, async_get/5, async_get/6, - sync_get_next/3, sync_get_next/4, sync_get_next/5, sync_get_next/6, - async_get_next/3, async_get_next/4, async_get_next/5, async_get_next/6, - sync_set/3, sync_set/4, sync_set/5, sync_set/6, - async_set/3, async_set/4, async_set/5, async_set/6, - sync_get_bulk/5, sync_get_bulk/6, sync_get_bulk/7, sync_get_bulk/8, - async_get_bulk/5, async_get_bulk/6, async_get_bulk/7, async_get_bulk/8, + %% Basic SNMP API (version "3"). + sync_get2/3, sync_get2/4, + async_get2/3, async_get2/4, + sync_get_next2/3, sync_get_next2/4, + async_get_next2/3, async_get_next2/4, + sync_set2/3, sync_set2/4, + async_set2/3, async_set2/4, + sync_get_bulk2/5, sync_get_bulk2/6, + async_get_bulk2/5, async_get_bulk2/6, + cancel_async_request/2, %% @@ -91,7 +92,19 @@ -export([format_reason/1, format_reason/2]). -%% Backward compatibillity exports +%% Backward compatibillity exports (API version "2") +-export([ + sync_get/3, sync_get/4, sync_get/5, sync_get/6, + async_get/3, async_get/4, async_get/5, async_get/6, + sync_get_next/3, sync_get_next/4, sync_get_next/5, sync_get_next/6, + async_get_next/3, async_get_next/4, async_get_next/5, async_get_next/6, + sync_set/3, sync_set/4, sync_set/5, sync_set/6, + async_set/3, async_set/4, async_set/5, async_set/6, + sync_get_bulk/5, sync_get_bulk/6, sync_get_bulk/7, sync_get_bulk/8, + async_get_bulk/5, async_get_bulk/6, async_get_bulk/7, async_get_bulk/8 + ]). + +%% Backward compatibillity exports (API version "1") -deprecated({agent_info, 3}). -deprecated({update_agent_info, 5}). -deprecated({g, 3}). @@ -498,23 +511,37 @@ which_usm_users(EngineID) when is_list(EngineID) -> %% --- synchroneous get-request --- %% -sync_get(UserId, TargetName, Oids) -> - sync_get(UserId, TargetName, ?DEFAULT_CONTEXT, Oids). +sync_get2(UserId, TargetName, Oids) -> + sync_get2(UserId, TargetName, Oids, []). -sync_get(UserId, TargetName, Context, Oids) when is_list(Oids) -> - snmpm_server:sync_get(UserId, TargetName, Context, Oids); +sync_get2(UserId, TargetName, Oids, SendOpts) + when is_list(Oids) andalso is_list(SendOpts) -> + snmpm_server:sync_get2(UserId, TargetName, Oids, SendOpts). -sync_get(UserId, TargetName, Oids, Timeout) when is_integer(Timeout) -> - sync_get(UserId, TargetName, ?DEFAULT_CONTEXT, Oids, Timeout). +%% +sync_get(UserId, TargetName, Oids) -> + sync_get2(UserId, TargetName, Oids). + +sync_get(UserId, TargetName, Oids, Timeout) + when is_list(Oids) andalso is_integer(Timeout) -> + SendOpts = [{timeout, Timeout}], + sync_get2(UserId, TargetName, Oids, SendOpts); +sync_get(UserId, TargetName, Context, [OH|_] = Oids) + when is_list(Context) andalso is_list(OH) -> + SendOpts = [{context, Context}], + sync_get2(UserId, TargetName, Oids, SendOpts). sync_get(UserId, TargetName, Context, Oids, Timeout) -> - snmpm_server:sync_get(UserId, TargetName, Context, Oids, Timeout). + SendOpts = [{context, Context}, {timeout, Timeout}], + sync_get2(UserId, TargetName, Oids, SendOpts). sync_get(UserId, TargetName, Context, Oids, Timeout, ExtraInfo) -> - snmpm_server:sync_get(UserId, TargetName, Context, Oids, Timeout, - ExtraInfo). + SendOpts = [{context, Context}, {timeout, Timeout}, {extra, ExtraInfo}], + sync_get2(UserId, TargetName, Oids, SendOpts). +%% +%% g(UserId, Addr, Oids) -> g(UserId, Addr, ?DEFAULT_AGENT_PORT, Oids). @@ -560,6 +587,7 @@ g(UserId, Addr, Port, CtxName, Oids, Timeout, ExtraInfo) -> Error -> Error end. +%% @@ -569,23 +597,36 @@ g(UserId, Addr, Port, CtxName, Oids, Timeout, ExtraInfo) -> %% through a call to handle_pdu/5 %% -async_get(UserId, TargetName, Oids) -> - async_get(UserId, TargetName, ?DEFAULT_CONTEXT, Oids). +async_get2(UserId, TargetName, Oids) -> + async_get2(UserId, TargetName, Oids, []). + +async_get2(UserId, TargetName, Oids, SendOpts) + when is_list(Oids) andalso is_list(SendOpts) -> + snmpm_server:async_get2(UserId, TargetName, Oids, SendOpts). -async_get(UserId, TargetName, Context, Oids) when is_list(Oids) -> - snmpm_server:async_get(UserId, TargetName, Context, Oids); +%% +async_get(UserId, TargetName, Oids) -> + async_get2(UserId, TargetName, Oids). async_get(UserId, TargetName, Oids, Expire) when is_integer(Expire) -> - async_get(UserId, TargetName, ?DEFAULT_CONTEXT, Oids, Expire). + SendOpts = [{timeout, Expire}], + async_get2(UserId, TargetName, Oids, SendOpts); +async_get(UserId, TargetName, Context, Oids) + when is_list(Context) andalso is_list(Oids) -> + SendOpts = [{context, Context}], + async_get2(UserId, TargetName, Oids, SendOpts). async_get(UserId, TargetName, Context, Oids, Expire) -> - snmpm_server:async_get(UserId, TargetName, Context, Oids, Expire). + SendOpts = [{timeout, Expire}, {context, Context}], + async_get2(UserId, TargetName, Oids, SendOpts). async_get(UserId, TargetName, Context, Oids, Expire, ExtraInfo) -> - snmpm_server:async_get(UserId, TargetName, Context, Oids, Expire, - ExtraInfo). + SendOpts = [{timeout, Expire}, {context, Context}, {extra, ExtraInfo}], + async_get2(UserId, TargetName, Oids, SendOpts). +%% +%% ag(UserId, Addr, Oids) -> ag(UserId, Addr, ?DEFAULT_AGENT_PORT, Oids). @@ -630,31 +671,44 @@ ag(UserId, Addr, Port, CtxName, Oids, Expire, ExtraInfo) -> Error -> Error end. +%% %% --- synchroneous get_next-request --- %% -sync_get_next(UserId, TargetName, Oids) -> - sync_get_next(UserId, TargetName, ?DEFAULT_CONTEXT, Oids). +sync_get_next2(UserId, TargetName, Oids) -> + sync_get_next2(UserId, TargetName, Oids, []). -sync_get_next(UserId, TargetName, Context, Oids) - when is_list(Context) andalso is_list(Oids) -> - snmpm_server:sync_get_next(UserId, TargetName, Context, Oids); +sync_get_next2(UserId, TargetName, Oids, SendOpts) + when is_list(Oids) andalso is_list(SendOpts) -> + snmpm_server:sync_get_next2(UserId, TargetName, Oids, SendOpts). + +%% +sync_get_next(UserId, TargetName, Oids) -> + sync_get_next2(UserId, TargetName, Oids). sync_get_next(UserId, TargetName, Oids, Timeout) when is_list(Oids) andalso is_integer(Timeout) -> - sync_get_next(UserId, TargetName, ?DEFAULT_CONTEXT, Oids, Timeout). + SendOpts = [{timeout, Timeout}], + sync_get_next2(UserId, TargetName, Oids, SendOpts); +sync_get_next(UserId, TargetName, Context, Oids) + when is_list(Context) andalso is_list(Oids) -> + SendOpts = [{context, Context}], + sync_get_next2(UserId, TargetName, Oids, SendOpts). sync_get_next(UserId, TargetName, Context, Oids, Timeout) -> - snmpm_server:sync_get_next(UserId, TargetName, Context, Oids, Timeout). + SendOpts = [{timeout, Timeout}, {context, Context}], + sync_get_next2(UserId, TargetName, Oids, SendOpts). sync_get_next(UserId, TargetName, Context, Oids, Timeout, ExtraInfo) -> - snmpm_server:sync_get_next(UserId, TargetName, Context, Oids, Timeout, - ExtraInfo). + SendOpts = [{timeout, Timeout}, {context, Context}, {extra, ExtraInfo}], + sync_get_next2(UserId, TargetName, Oids, SendOpts). +%% +%% gn(UserId, Addr, Oids) -> gn(UserId, Addr, ?DEFAULT_AGENT_PORT, Oids). @@ -699,30 +753,44 @@ gn(UserId, Addr, Port, CtxName, Oids, Timeout, ExtraInfo) -> Error -> Error end. +%% %% --- asynchroneous get_next-request --- %% +async_get_next2(UserId, TargetName, Oids) -> + async_get_next2(UserId, TargetName, Oids, []). + +async_get_next2(UserId, TargetName, Oids, SendOpts) + when is_list(Oids) andalso is_list(SendOpts) -> + snmpm_server:async_get_next2(UserId, TargetName, Oids, SendOpts). + +%% async_get_next(UserId, TargetName, Oids) -> - async_get_next(UserId, TargetName, ?DEFAULT_CONTEXT, Oids). + async_get_next2(UserId, TargetName, Oids). +async_get_next(UserId, TargetName, Oids, Expire) + when is_list(Oids) andalso is_integer(Expire) -> + SendOpts = [{timeout, Expire}], + async_get_next2(UserId, TargetName, Oids, SendOpts); async_get_next(UserId, TargetName, Context, Oids) when is_list(Context) andalso is_list(Oids) -> - snmpm_server:async_get_next(UserId, TargetName, Context, Oids); + SendOpts = [{context, Context}], + async_get_next2(UserId, TargetName, Oids, SendOpts). -async_get_next(UserId, TargetName, Oids, Timeout) - when is_list(Oids) andalso is_integer(Timeout) -> - async_get_next(UserId, TargetName, ?DEFAULT_CONTEXT, Oids, Timeout). +async_get_next(UserId, TargetName, Context, Oids, Expire) -> + SendOpts = [{timeout, Expire}, {context, Context}], + async_get_next2(UserId, TargetName, Oids, SendOpts). -async_get_next(UserId, TargetName, Context, Oids, Timeout) -> - snmpm_server:async_get_next(UserId, TargetName, Context, Oids, Timeout). +async_get_next(UserId, TargetName, Context, Oids, Expire, ExtraInfo) -> + SendOpts = [{timeout, Expire}, {context, Context}, {extra, ExtraInfo}], + async_get_next2(UserId, TargetName, Oids, SendOpts). +%% -async_get_next(UserId, TargetName, Context, Oids, Timeout, ExtraInfo) -> - snmpm_server:async_get_next(UserId, TargetName, Context, Oids, Timeout, - ExtraInfo). +%% agn(UserId, Addr, Oids) -> agn(UserId, Addr, ?DEFAULT_AGENT_PORT, Oids). @@ -768,31 +836,44 @@ agn(UserId, Addr, Port, CtxName, Oids, Expire, ExtraInfo) -> Error -> Error end. +%% %% --- synchroneous set-request --- %% -sync_set(UserId, TargetName, VarsAndVals) -> - sync_set(UserId, TargetName, ?DEFAULT_CONTEXT, VarsAndVals). +sync_set2(UserId, TargetName, VarsAndVals) -> + sync_set2(UserId, TargetName, VarsAndVals, []). -sync_set(UserId, TargetName, Context, VarsAndVals) - when is_list(Context) andalso is_list(VarsAndVals) -> - snmpm_server:sync_set(UserId, TargetName, Context, VarsAndVals); +sync_set2(UserId, TargetName, VarsAndVals, SendOpts) + when is_list(VarsAndVals) andalso is_list(SendOpts) -> + snmpm_server:sync_set2(UserId, TargetName, VarsAndVals, SendOpts). + +%% +sync_set(UserId, TargetName, VarsAndVals) -> + sync_set2(UserId, TargetName, VarsAndVals). sync_set(UserId, TargetName, VarsAndVals, Timeout) when is_list(VarsAndVals) andalso is_integer(Timeout) -> - sync_set(UserId, TargetName, ?DEFAULT_CONTEXT, VarsAndVals, Timeout). + SendOpts = [{timeout, Timeout}], + sync_set2(UserId, TargetName, VarsAndVals, SendOpts); +sync_set(UserId, TargetName, Context, VarsAndVals) + when is_list(Context) andalso is_list(VarsAndVals) -> + SendOpts = [{context, Context}], + sync_set2(UserId, TargetName, VarsAndVals, SendOpts). sync_set(UserId, TargetName, Context, VarsAndVals, Timeout) -> - snmpm_server:sync_set(UserId, TargetName, Context, VarsAndVals, Timeout). + SendOpts = [{timeout, Timeout}, {context, Context}], + sync_set2(UserId, TargetName, VarsAndVals, SendOpts). sync_set(UserId, TargetName, Context, VarsAndVals, Timeout, ExtraInfo) -> - snmpm_server:sync_set(UserId, TargetName, Context, VarsAndVals, Timeout, - ExtraInfo). + SendOpts = [{timeout, Timeout}, {context, Context}, {extra, ExtraInfo}], + sync_set2(UserId, TargetName, VarsAndVals, SendOpts). +%% +%% s(UserId, Addr, VarsAndVals) -> s(UserId, Addr, ?DEFAULT_AGENT_PORT, VarsAndVals). @@ -846,31 +927,44 @@ s(UserId, Addr, Port, CtxName, VarsAndVals, Timeout, ExtraInfo) -> Error -> Error end. +%% %% --- asynchroneous set-request --- %% -async_set(UserId, TargetName, VarsAndVals) -> - async_set(UserId, TargetName, ?DEFAULT_CONTEXT, VarsAndVals). +async_set2(UserId, TargetName, VarsAndVals) -> + async_set2(UserId, TargetName, VarsAndVals, []). -async_set(UserId, TargetName, Context, VarsAndVals) - when is_list(Context) andalso is_list(VarsAndVals) -> - snmpm_server:async_set(UserId, TargetName, Context, VarsAndVals); +async_set2(UserId, TargetName, VarsAndVals, SendOpts) + when is_list(VarsAndVals) andalso is_list(SendOpts) -> + snmpm_server:async_set2(UserId, TargetName, VarsAndVals, SendOpts). + +%% +async_set(UserId, TargetName, VarsAndVals) -> + async_set2(UserId, TargetName, VarsAndVals). async_set(UserId, TargetName, VarsAndVals, Expire) when is_list(VarsAndVals) andalso is_integer(Expire) -> - async_set(UserId, TargetName, ?DEFAULT_CONTEXT, VarsAndVals, Expire). + SendOpts = [{timeout, Expire}], + async_set2(UserId, TargetName, VarsAndVals, SendOpts); +async_set(UserId, TargetName, Context, VarsAndVals) + when is_list(Context) andalso is_list(VarsAndVals) -> + SendOpts = [{context, Context}], + async_set2(UserId, TargetName, VarsAndVals, SendOpts). async_set(UserId, TargetName, Context, VarsAndVals, Expire) -> - snmpm_server:async_set(UserId, TargetName, Context, VarsAndVals, Expire). + SendOpts = [{timeout, Expire}, {context, Context}], + async_set2(UserId, TargetName, VarsAndVals, SendOpts). async_set(UserId, TargetName, Context, VarsAndVals, Expire, ExtraInfo) -> - snmpm_server:async_set(UserId, TargetName, Context, VarsAndVals, Expire, - ExtraInfo). + SendOpts = [{timeout, Expire}, {context, Context}, {extra, ExtraInfo}], + async_set2(UserId, TargetName, VarsAndVals, SendOpts). +%% +%% as(UserId, Addr, VarsAndVals) -> as(UserId, Addr, ?DEFAULT_AGENT_PORT, VarsAndVals). @@ -924,44 +1018,77 @@ as(UserId, Addr, Port, CtxName, VarsAndVals, Expire, ExtraInfo) -> Error -> Error end. - - +%% %% --- synchroneous get-bulk --- %% -sync_get_bulk(UserId, TargetName, NonRep, MaxRep, Oids) -> - sync_get_bulk(UserId, TargetName, NonRep, MaxRep, ?DEFAULT_CONTEXT, Oids). +sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids) -> + sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, []). -sync_get_bulk(UserId, TargetName, NonRep, MaxRep, Context, Oids) +sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts) when is_integer(NonRep) andalso is_integer(MaxRep) andalso - is_list(Context) andalso - is_list(Oids) -> - snmpm_server:sync_get_bulk(UserId, TargetName, - NonRep, MaxRep, - Context, Oids); + is_list(Oids) andalso + is_list(SendOpts) -> + %% p("sync_get_bulk -> entry with" + %% "~n UserId: ~p" + %% "~n TargetName: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n Oids: ~p" + %% "~n SendOpts: ~p", + %% [UserId, TargetName, NonRep, MaxRep, Oids, SendOpts]), + snmpm_server:sync_get_bulk2(UserId, TargetName, + NonRep, MaxRep, Oids, SendOpts). + +%% +sync_get_bulk(UserId, TargetName, NonRep, MaxRep, Oids) -> + sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids). sync_get_bulk(UserId, TargetName, NonRep, MaxRep, Oids, Timeout) when is_integer(NonRep) andalso is_integer(MaxRep) andalso is_list(Oids) andalso is_integer(Timeout) -> - sync_get_bulk(UserId, TargetName, NonRep, MaxRep, - ?DEFAULT_CONTEXT, Oids, Timeout). + SendOpts = [{timeout, Timeout}], + sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts); +sync_get_bulk(UserId, TargetName, NonRep, MaxRep, Context, Oids) + when is_integer(NonRep) andalso + is_integer(MaxRep) andalso + is_list(Context) andalso + is_list(Oids) -> + %% p("sync_get_bulk -> entry with" + %% "~n UserId: ~p" + %% "~n TargetName: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n Context: ~p" + %% "~n Oids: ~p", [UserId, TargetName, NonRep, MaxRep, Context, Oids]), + SendOpts = [{context, Context}], + sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts). sync_get_bulk(UserId, TargetName, NonRep, MaxRep, Context, Oids, Timeout) -> - snmpm_server:sync_get_bulk(UserId, TargetName, NonRep, MaxRep, - Context, Oids, Timeout). + SendOpts = [{timeout, Timeout}, {context, Context}], + sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts). sync_get_bulk(UserId, TargetName, NonRep, MaxRep, Context, Oids, Timeout, ExtraInfo) -> - snmpm_server:sync_get_bulk(UserId, TargetName, NonRep, MaxRep, - Context, Oids, Timeout, ExtraInfo). + SendOpts = [{timeout, Timeout}, {context, Context}, {extra, ExtraInfo}], + sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts). +%% +%% gb(UserId, Addr, NonRep, MaxRep, Oids) -> + %% p("gb -> entry with" + %% "~n UserId: ~p" + %% "~n Addr: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n Oids: ~p", + %% [UserId, Addr, NonRep, MaxRep, Oids]), gb(UserId, Addr, ?DEFAULT_AGENT_PORT, NonRep, MaxRep, Oids). gb(UserId, Addr, Port, NonRep, MaxRep, Oids) @@ -969,6 +1096,14 @@ gb(UserId, Addr, Port, NonRep, MaxRep, Oids) is_integer(NonRep) andalso is_integer(MaxRep) andalso is_list(Oids) -> + %% p("gb -> entry with" + %% "~n UserId: ~p" + %% "~n Addr: ~p" + %% "~n Port: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n Oids: ~p", + %% [UserId, Addr, Port, NonRep, MaxRep, Oids]), gb(UserId, Addr, Port, NonRep, MaxRep, ?DEFAULT_CONTEXT, Oids); gb(UserId, Addr, NonRep, MaxRep, CtxName, Oids) @@ -976,6 +1111,14 @@ gb(UserId, Addr, NonRep, MaxRep, CtxName, Oids) is_integer(MaxRep) andalso is_list(CtxName) andalso is_list(Oids) -> + %% p("gb -> entry with" + %% "~n UserId: ~p" + %% "~n Addr: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n CtxName: ~p" + %% "~n Oids: ~p", + %% [UserId, Addr, NonRep, MaxRep, CtxName, Oids]), gb(UserId, Addr, ?DEFAULT_AGENT_PORT, NonRep, MaxRep, CtxName, Oids); gb(UserId, Addr, NonRep, MaxRep, Oids, Timeout) @@ -983,6 +1126,14 @@ gb(UserId, Addr, NonRep, MaxRep, Oids, Timeout) is_integer(MaxRep) andalso is_list(Oids) andalso is_integer(Timeout) -> + %% p("gb -> entry with" + %% "~n UserId: ~p" + %% "~n Addr: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n Oids: ~p" + %% "~n Timeout: ~p", + %% [UserId, Addr, NonRep, MaxRep, Oids, Timeout]), gb(UserId, Addr, ?DEFAULT_AGENT_PORT, NonRep, MaxRep, Oids, Timeout). gb(UserId, Addr, Port, NonRep, MaxRep, CtxName, Oids) @@ -991,8 +1142,18 @@ gb(UserId, Addr, Port, NonRep, MaxRep, CtxName, Oids) is_integer(MaxRep) andalso is_list(CtxName) andalso is_list(Oids) -> + %% p("gb -> entry with" + %% "~n UserId: ~p" + %% "~n Addr: ~p" + %% "~n Port: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n CtxName: ~p" + %% "~n Oids: ~p", + %% [UserId, Addr, Port, NonRep, MaxRep, CtxName, Oids]), case target_name(Addr, Port) of {ok, TargetName} -> + %% p("gb -> TargetName: ~p", [TargetName]), sync_get_bulk(UserId, TargetName, NonRep, MaxRep, CtxName, Oids); Error -> Error @@ -1004,6 +1165,15 @@ gb(UserId, Addr, Port, NonRep, MaxRep, Oids, Timeout) is_integer(MaxRep) andalso is_list(Oids) andalso is_integer(Timeout) -> + %% p("gb -> entry with" + %% "~n UserId: ~p" + %% "~n Addr: ~p" + %% "~n Port: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n Oids: ~p" + %% "~n Timeout: ~p", + %% [UserId, Addr, Port, NonRep, MaxRep, Oids, Timeout]), gb(UserId, Addr, Port, NonRep, MaxRep, ?DEFAULT_CONTEXT, Oids, Timeout); gb(UserId, Addr, NonRep, MaxRep, CtxName, Oids, Timeout) @@ -1012,10 +1182,29 @@ gb(UserId, Addr, NonRep, MaxRep, CtxName, Oids, Timeout) is_list(CtxName) andalso is_list(Oids) andalso is_integer(Timeout) -> + %% p("gb -> entry with" + %% "~n UserId: ~p" + %% "~n Addr: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n CtxName: ~p" + %% "~n Oids: ~p" + %% "~n Timeout: ~p", + %% [UserId, Addr, NonRep, MaxRep, CtxName, Oids, Timeout]), gb(UserId, Addr, ?DEFAULT_AGENT_PORT, NonRep, MaxRep, CtxName, Oids, Timeout). gb(UserId, Addr, Port, NonRep, MaxRep, CtxName, Oids, Timeout) -> + %% p("gb -> entry with" + %% "~n UserId: ~p" + %% "~n Addr: ~p" + %% "~n Port: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n CtxName: ~p" + %% "~n Oids: ~p" + %% "~n Timeout: ~p", + %% [UserId, Addr, Port, NonRep, MaxRep, CtxName, Oids, Timeout]), case target_name(Addr, Port) of {ok, TargetName} -> sync_get_bulk(UserId, TargetName, @@ -1025,6 +1214,17 @@ gb(UserId, Addr, Port, NonRep, MaxRep, CtxName, Oids, Timeout) -> end. gb(UserId, Addr, Port, NonRep, MaxRep, CtxName, Oids, Timeout, ExtraInfo) -> + %% p("gb -> entry with" + %% "~n UserId: ~p" + %% "~n Addr: ~p" + %% "~n Port: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n CtxName: ~p" + %% "~n Oids: ~p" + %% "~n Timeout: ~p" + %% "~n ExtraInfo: ~p", + %% [UserId, Addr, Port, NonRep, MaxRep, CtxName, Oids, Timeout, ExtraInfo]), case target_name(Addr, Port) of {ok, TargetName} -> sync_get_bulk(UserId, TargetName, @@ -1032,42 +1232,55 @@ gb(UserId, Addr, Port, NonRep, MaxRep, CtxName, Oids, Timeout, ExtraInfo) -> Error -> Error end. +%% %% --- asynchroneous get-bulk --- %% -async_get_bulk(UserId, TargetName, NonRep, MaxRep, Oids) -> - async_get_bulk(UserId, TargetName, NonRep, MaxRep, ?DEFAULT_CONTEXT, Oids). +async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids) -> + async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, []). -async_get_bulk(UserId, TargetName, NonRep, MaxRep, Context, Oids) +async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts) when is_integer(NonRep) andalso is_integer(MaxRep) andalso - is_list(Context) andalso - is_list(Oids) -> - snmpm_server:async_get_bulk(UserId, TargetName, - NonRep, MaxRep, Context, Oids); + is_list(Oids) andalso + is_list(SendOpts) -> + snmpm_server:async_get_bulk2(UserId, TargetName, + NonRep, MaxRep, Oids, SendOpts). + +%% +async_get_bulk(UserId, TargetName, NonRep, MaxRep, Oids) -> + async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids). async_get_bulk(UserId, TargetName, NonRep, MaxRep, Oids, Expire) when is_integer(NonRep) andalso is_integer(MaxRep) andalso is_list(Oids) andalso is_integer(Expire) -> - async_get_bulk(UserId, TargetName, - NonRep, MaxRep, ?DEFAULT_CONTEXT, Oids, Expire). + SendOpts = [{timeout, Expire}], + async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts); +async_get_bulk(UserId, TargetName, NonRep, MaxRep, Context, Oids) + when is_integer(NonRep) andalso + is_integer(MaxRep) andalso + is_list(Context) andalso + is_list(Oids) -> + SendOpts = [{context, Context}], + async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts). async_get_bulk(UserId, TargetName, NonRep, MaxRep, Context, Oids, Expire) -> - snmpm_server:async_get_bulk(UserId, TargetName, - NonRep, MaxRep, Context, Oids, Expire). + SendOpts = [{timeout, Expire}, {context, Context}], + async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts). async_get_bulk(UserId, TargetName, NonRep, MaxRep, Context, Oids, Expire, ExtraInfo) -> - snmpm_server:async_get_bulk(UserId, TargetName, - NonRep, MaxRep, - Context, Oids, Expire, ExtraInfo). + SendOpts = [{timeout, Expire}, {context, Context}, {extra, ExtraInfo}], + async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts). +%% +%% agb(UserId, Addr, NonRep, MaxRep, Oids) -> agb(UserId, Addr, ?DEFAULT_AGENT_PORT, NonRep, MaxRep, Oids). @@ -1140,6 +1353,7 @@ agb(UserId, Addr, Port, NonRep, MaxRep, CtxName, Oids, Expire, ExtraInfo) -> Error -> Error end. +%% cancel_async_request(UserId, ReqId) -> diff --git a/lib/snmp/src/manager/snmpm_server.erl b/lib/snmp/src/manager/snmpm_server.erl index 3b49267994..29f0c61b0e 100644 --- a/lib/snmp/src/manager/snmpm_server.erl +++ b/lib/snmp/src/manager/snmpm_server.erl @@ -348,6 +348,14 @@ async_get_next(UserId, TargetName, CtxName, Oids, Expire, ExtraInfo) %% sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids) -> %% sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, []). sync_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids, SendOpts) -> + %% p("sync_get_bulk2 -> entry with" + %% "~n UserId: ~p" + %% "~n TargetName: ~p" + %% "~n NonRep: ~p" + %% "~n MaxRep: ~p" + %% "~n Oids: ~p" + %% "~n SendOpts: ~p", + %% [UserId, TargetName, NonRep, MaxRep, Oids, SendOpts]), call({sync_get_bulk, self(), UserId, TargetName, NonRep, MaxRep, Oids, SendOpts}). diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index 50836db731..a98ab889d0 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -43,7 +43,7 @@ %% External exports %%---------------------------------------------------------------------- -export([ - all/0,groups/0,init_per_group/2,end_per_group/2, + all/0, groups/0, init_per_group/2, end_per_group/2, init_per_testcase/2, end_per_testcase/2, @@ -360,42 +360,100 @@ end_per_testcase2(Case, Config) -> %%====================================================================== all() -> -[{group, start_and_stop_tests}, {group, misc_tests}, - {group, user_tests}, {group, agent_tests}, - {group, request_tests}, {group, event_tests}, discovery, - {group, tickets}]. + [ + {group, start_and_stop_tests}, + {group, misc_tests}, + {group, user_tests}, + {group, agent_tests}, + {group, request_tests}, + {group, event_tests}, + discovery, + {group, tickets} + ]. groups() -> - [{start_and_stop_tests, [], - [simple_start_and_stop1, simple_start_and_stop2, - simple_start_and_monitor_crash1, - simple_start_and_monitor_crash2, notify_started01, - notify_started02]}, - {misc_tests, [], [info]}, - {user_tests, [], [register_user1]}, - {agent_tests, [], [register_agent1, register_agent2]}, - {request_tests, [], - [{group, get_tests}, {group, get_next_tests}, - {group, set_tests}, {group, bulk_tests}, - {group, misc_request_tests}]}, - {get_tests, [], - [simple_sync_get1, simple_sync_get2, simple_async_get1, - simple_async_get2]}, - {get_next_tests, [], - [simple_sync_get_next1, simple_sync_get_next2, - simple_async_get_next1, simple_async_get_next2]}, - {set_tests, [], - [simple_sync_set1, simple_sync_set2, simple_async_set1, - simple_async_set2]}, - {bulk_tests, [], - [simple_sync_get_bulk1, simple_sync_get_bulk2, - simple_async_get_bulk1, simple_async_get_bulk2]}, - {misc_request_tests, [], [misc_async1, misc_async2]}, - {event_tests, [], - [trap1, trap2, inform1, inform2, inform3, inform4, - inform_swarm, report]}, - {tickets, [], [{group, otp8015}, {group, otp8395}]}, - {otp8015, [], [otp8015_1]}, {otp8395, [], [otp8395_1]}]. + [ + {start_and_stop_tests, [], + [ + simple_start_and_stop1, + simple_start_and_stop2, + simple_start_and_monitor_crash1, + simple_start_and_monitor_crash2, + notify_started01, + notify_started02 + ] + }, + {misc_tests, [], [info]}, + {user_tests, [], [register_user1]}, + {agent_tests, [], [register_agent1, register_agent2]}, + {request_tests, [], + [ + {group, get_tests}, + {group, get_next_tests}, + {group, set_tests}, + {group, bulk_tests}, + {group, misc_request_tests} + ] + }, + {get_tests, [], + [ + simple_sync_get1, + simple_sync_get2, + simple_async_get1, + simple_async_get2 + ] + }, + {get_next_tests, [], + [ + simple_sync_get_next1, + simple_sync_get_next2, + simple_async_get_next1, + simple_async_get_next2 + ] + }, + {set_tests, [], + [ + simple_sync_set1, + simple_sync_set2, + simple_async_set1, + simple_async_set2 + ] + }, + {bulk_tests, [], + [ + simple_sync_get_bulk1, + simple_sync_get_bulk2, + simple_async_get_bulk1, + simple_async_get_bulk2 + ] + }, + {misc_request_tests, [], + [ + misc_async1, + misc_async2 + ] + }, + {event_tests, [], + [ + trap1, + trap2, + inform1, + inform2, + inform3, + inform4, + inform_swarm, + report + ] + }, + {tickets, [], + [ + {group, otp8015}, + {group, otp8395} + ] + }, + {otp8015, [], [otp8015_1]}, + {otp8395, [], [otp8395_1]} + ]. init_per_group(_GroupName, Config) -> Config. @@ -404,21 +462,6 @@ end_per_group(_GroupName, Config) -> Config. - - - - - - - - - - - - - - - %%====================================================================== %% Test functions %%====================================================================== @@ -1435,40 +1478,41 @@ simple_async_get1(Config) when is_list(Config) -> ?line ok = agent_load_mib(AgentNode, Test2Mib), Exec = fun(Data) -> - async_g_exec1(MgrNode, Addr, Port, Data) + async_g_exec1(MgrNode, Addr, Port, Data) end, - Requests = [ - { 1, - [?sysObjectID_instance], - Exec, - fun(X) -> sag_verify(X, [?sysObjectID_instance]) end}, - { 2, - [?sysDescr_instance, ?sysUpTime_instance], - Exec, - fun(X) -> - sag_verify(X, [?sysObjectID_instance, - ?sysUpTime_instance]) - end}, - { 3, - [[sysObjectID, 0], [sysDescr, 0], [sysUpTime, 0]], - Exec, - fun(X) -> - sag_verify(X, [?sysObjectID_instance, - ?sysDescr_instance, - ?sysUpTime_instance]) - end}, - { 4, - [?sysObjectID_instance, - ?sysDescr_instance, - ?sysUpTime_instance], - Exec, - fun(X) -> - sag_verify(X, [?sysObjectID_instance, - ?sysDescr_instance, - ?sysUpTime_instance]) - end} - ], + Requests = + [ + { 1, + [?sysObjectID_instance], + Exec, + fun(X) -> sag_verify(X, [?sysObjectID_instance]) end }, + { 2, + [?sysDescr_instance, ?sysUpTime_instance], + Exec, + fun(X) -> + sag_verify(X, [?sysObjectID_instance, + ?sysUpTime_instance]) + end }, + { 3, + [[sysObjectID, 0], [sysDescr, 0], [sysUpTime, 0]], + Exec, + fun(X) -> + sag_verify(X, [?sysObjectID_instance, + ?sysDescr_instance, + ?sysUpTime_instance]) + end }, + { 4, + [?sysObjectID_instance, + ?sysDescr_instance, + ?sysUpTime_instance], + Exec, + fun(X) -> + sag_verify(X, [?sysObjectID_instance, + ?sysDescr_instance, + ?sysUpTime_instance]) + end } + ], p("manager info when starting test: ~n~p", [mgr_info(MgrNode)]), p("agent info when starting test: ~n~p", [agent_info(AgentNode)]), diff --git a/lib/snmp/test/snmp_manager_user.erl b/lib/snmp/test/snmp_manager_user.erl index b0e192344d..71fdebb67b 100644 --- a/lib/snmp/test/snmp_manager_user.erl +++ b/lib/snmp/test/snmp_manager_user.erl @@ -847,7 +847,11 @@ call(Req, To) when is_integer(To) -> {error, timeout} end. -reply(Pid, Reply, Ref) -> +reply(Pid, Reply, Ref) -> + d("reply -> entry with" + "~n Pid: ~p" + "~n Reply: ~p" + "~n Ref: ~p", [Pid, Reply, Ref]), Pid ! {Reply, Ref}. cast(Msg) -> -- cgit v1.2.3 From e6a14f6efc61aec9eef4197c08fd8fbe9116281b Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 14 Apr 2011 09:31:32 +0200 Subject: Added the documentation for the previous request API (removed by misstake). --- lib/snmp/doc/src/snmpm.xml | 281 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 281 insertions(+) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/snmpm.xml b/lib/snmp/doc/src/snmpm.xml index ff072205bc..b1c8e56721 100644 --- a/lib/snmp/doc/src/snmpm.xml +++ b/lib/snmp/doc/src/snmpm.xml @@ -538,6 +538,50 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

For SnmpInfo, see the user callback function handle_report.

+ + +
+ + + sync_get(UserId, TargetName, Oids) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_get(UserId, TargetName, ContextName, Oids) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_get(UserId, TargetName, Oids, Timeout) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_get(UserId, TargetName, ContextName, Oids, Timeout) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_get(UserId, TargetName, ContextName, Oids, Timeout, ExtraInfo) -> {ok, SnmpReply, Remaining} | {error, Reason} + Synchronous get-request + + UserId = term() + TargetName = target_name() + ContextName = string() + Oids = [oid()] + Timeout = integer() + ExtraInfo = term() + SnmpReply = snmp_reply() + Remaining = integer() + Reason = {send_failed, ReqId, R} | {invalid_sec_info, SecInfo, SnmpInfo} | term() + R = term() + SecInfo = [sec_info()] + sec_info() = {sec_tag(), ExpectedValue, ReceivedValue} + sec_tag() = atom() + ExpectedValue = ReceivedValue = term() + SnmpInfo = term() + + +

Synchronous get-request.

+

Remaining is the remaining time of the given or + default timeout time.

+

When Reason is {send_failed, ...} it means that + the net_if process failed to send the message. This could happen + because of any number of reasons, i.e. encoding error. R + is the actual reason in this case.

+

ExtraInfo is an opaque data structure passed on to + the net-if process. The net-if process included in this + application makes no use of this info, so the only use for it + in such a configuration (when using the built in net-if) would + be tracing.

+

For SnmpInfo, see the user callback function + handle_report.

+
@@ -578,6 +622,40 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1 for this request, they override any configuration done when the agent was registered.

+ + +
+ + + async_get(UserId, TargetName, Oids) -> {ok, ReqId} | {error, Reason} + async_get(UserId, TargetName, ContextName, Oids) -> {ok, ReqId} | {error, Reason} + async_get(UserId, TargetName, Oids, Expire) -> {ok, ReqId} | {error, Reason} + async_get(UserId, TargetName, ContextName, Oids, Expire) -> {ok, ReqId} | {error, Reason} + async_get(UserId, TargetName, ContextName, Oids, Expire, ExtraInfo) -> {ok, ReqId} | {error, Reason} + Asynchronous get-request + + UserId = term() + TargetName = target_name() + ContextName = string() + Oids = [oid()] + Expire = integer() + ExtraInfo = term() + ReqId = term() + Reason = term() + + +

Asynchronous get-request.

+

The reply, if it arrives, will be delivered to the user + through a call to the snmpm_user callback function + handle_pdu.

+

The Expire time indicates for how long the request is + valid (after which the manager is free to delete it).

+

ExtraInfo is an opaque data structure passed on to + the net-if process. The net-if process included in this + application makes no use of this info, so the only use for it + in such a configuration (when using the built in net-if) would + be tracing.

+
@@ -630,6 +708,42 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

For SnmpInfo, see the user callback function handle_report.

+ + +
+ + + sync_get_next(UserId, TargetName, Oids) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_get_next(UserId, TargetName, ContextName, Oids) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_get_next(UserId, TargetName, Oids, Timeout) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_get_next(UserId, TargetName, ContextName, Oids, Timeout) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_get_next(UserId, TargetName, ContextName, Oids, Timeout, ExtraInfo) -> {ok, SnmpReply, Remaining} | {error, Reason} + Synchronous get-next-request + + UserId = term() + TargetName = target_name() + ContextName = string() + Oids = [oid()] + Timeout = integer() + ExtraInfo = term() + SnmpReply = snmp_reply() + Remaining = integer() + Reason = {send_failed, ReqId, R} | {invalid_sec_info, SecInfo, SnmpInfo} | term() + R = term() + + +

Synchronous get-next-request.

+

Remaining time of the given or default timeout time.

+

When Reason is {send_failed, ...} it means that + the net_if process failed to send the message. This could happen + because of any number of reasons, i.e. encoding error. R + is the actual reason in this case.

+

ExtraInfo is an opaque data structure passed on to + the net-if process. The net-if process included in this + application makes no use of this info, so the only use for it + in such a configuration (when using the built in net-if) would + be tracing.

+
@@ -667,6 +781,34 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1 for this request, they override any configuration done when the agent was registered.

+ + +
+ + + async_get_next(UserId, TargetName, Oids) -> {ok, ReqId} | {error, Reason} + async_get_next(UserId, TargetName, ContextName, Oids) -> {ok, ReqId} | {error, Reason} + async_get_next(UserId, TargetName, Oids, Expire) -> {ok, ReqId} | {error, Reason} + async_get_next(UserId, TargetName, ContextName, Oids, Expire) -> {ok, ReqId} | {error, Reason} + async_get_next(UserId, TargetName, ContextName, Oids, Expire, ExtraInfo) -> {ok, ReqId} | {error, Reason} + Asynchronous get-next-request + + UserId = term() + TargetName = target_name() + ContextName = string() + Oids = [oid()] + Expire = integer() + ExtraInfo = term() + ReqId = integer() + Reason = term() + + +

Asynchronous get-next-request.

+

The reply will be delivered to the user through a call + to the snmpm_user callback function handle_pdu.

+

The Expire time indicates for how long the request is + valid (after which the manager is free to delete it).

+
@@ -722,6 +864,44 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

For SnmpInfo, see the user callback function handle_report.

+ + +
+ + + sync_set(UserId, TargetName, VarsAndVals) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_set(UserId, TargetName, ContextName, VarsAndVals) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_set(UserId, TargetName, VarsAndVals, Timeout) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_set(UserId, TargetName, ContextName, VarsAndVals, Timeout) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_set(UserId, TargetName, ContextName, VarsAndVals, Timeout, ExtraInfo) -> {ok, SnmpReply, Remaining} | {error, Reason} + Synchronous set-request + + UserId = term() + TargetName = target_name() + ContextName = string() + VarsAndVals = vars_and_vals() + Timeout = integer() + ExtraInfo = term() + SnmpReply = snmp_reply() + Remaining = integer() + Reason = {send_failed, ReqId, ActualReason} | {invalid_sec_info, SecInfo, SnmpInfo} | term() + ActualReason = term() + + +

Synchronous set-request.

+

Remaining time of the given or default timeout time.

+

When Reason is {send_failed, ...} it means that + the net_if process failed to send the message. This could happen + because of any number of reasons, i.e. encoding error. R + is the actual reason in this case.

+

When var_and_val() is {oid(), value()}, the + manager makes an educated guess based on the loaded mibs.

+

ExtraInfo is an opaque data structure passed on to + the net-if process. The net-if process included in this + application makes no use of this info, so the only use for it + in such a configuration (when using the built in net-if) would + be tracing.

+
@@ -764,6 +944,40 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1 for this request, they override any configuration done when the agent was registered.

+ + +
+ + + async_set(UserId, TargetName, VarsAndVals) -> {ok, ReqId} | {error, Reason} + async_set(UserId, TargetName, ContextName, VarsAndVals) -> {ok, ReqId} | {error, Reason} + async_set(UserId, TargetName, VarsAndVals, Expire) -> {ok, ReqId} | {error, Reason} + async_set(UserId, TargetName, ContextName, VarsAndVals, Expire) -> {ok, ReqId} | {error, Reason} + async_set(UserId, TargetName, ContextName, VarsAndVals, Expire, ExtraInfo) -> {ok, ReqId} | {error, Reason} + Asynchronous set-request + + UserId = term() + TargetName = target_name() + VarsAndVals = vars_and_vals() + Expire = integer() + ExtraInfo = term() + ReqId = term() + Reason = term() + + +

Asynchronous set-request.

+

The reply will be delivered to the user through a call + to the snmpm_user callback function handle_pdu.

+

The Expire time indicates for how long the request is + valid (after which the manager is free to delete it).

+

When var_and_val() is {oid(), value()}, the + manager makes an educated guess based on the loaded mibs.

+

ExtraInfo is an opaque data structure passed on to + the net-if process. The net-if process included in this + application makes no use of this info, so the only use for it + in such a configuration (when using the built in net-if) would + be tracing.

+
@@ -818,6 +1032,43 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

For SnmpInfo, see the user callback function handle_report.

+ + +
+ + + sync_get_bulk(UserId, TragetName, NonRep, MaxRep, Oids) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_get_bulk(UserId, TragetName, NonRep, MaxRep, ContextName, Oids) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_get_bulk(UserId, TragetName, NonRep, MaxRep, Oids, Timeout) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_get_bulk(UserId, TragetName, NonRep, MaxRep, ContextName, Oids, Timeout) -> {ok, SnmpReply, Remaining} | {error, Reason} + sync_get_bulk(UserId, TragetName, NonRep, MaxRep, ContextName, Oids, Timeout, ExtraInfo) -> {ok, SnmpReply, Remaining} | {error, Reason} + Synchronous get-bulk-request + + UserId = term() + TargetName = target_name() + NonRep = integer() + MaxRep = integer() + ContextName = string() + Oids = [oid()] + Timeout = integer() + ExtraInfo = term() + SnmpReply = snmp_reply() + Remaining = integer() + Reason = {send_failed, ReqId, R} | {invalid_sec_info, SecInfo, SnmpInfo} | term() + + +

Synchronous get-bulk-request (See RFC1905).

+

Remaining time of the given or default timeout time.

+

When Reason is {send_failed, ...} it means that + the net_if process failed to send the message. This could happen + because of any number of reasons, i.e. encoding error. R + is the actual reason in this case.

+

ExtraInfo is an opaque data structure passed on to + the net-if process. The net-if process included in this + application makes no use of this info, so the only use for it + in such a configuration (when using the built in net-if) would + be tracing.

+
@@ -859,6 +1110,36 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1 for this request, they override any configuration done when the agent was registered.

+ + +
+ + + async_get_bulk(UserId, TargetName, NonRep, MaxRep, Oids) -> {ok, ReqId} | {error, Reason} + async_get_bulk(UserId, TargetName, NonRep, MaxRep, ContextName, Oids) -> {ok, ReqId} | {error, Reason} + async_get_bulk(UserId, TargetName, NonRep, MaxRep, Oids, Expire) -> {ok, ReqId} | {error, Reason} + async_get_bulk(UserId, TargetName, NonRep, MaxRep, ContextName, Oids, Expire) -> {ok, ReqId} | {error, Reason} + async_get_bulk(UserId, TargetName, NonRep, MaxRep, ContextName, Oids, Expire, ExtraInfo) -> {ok, ReqId} | {error, Reason} + Asynchronous get-bulk-request + + UserId = term() + TargetName = target_name() + NonRep = integer() + MaxRep = integer() + ContextName = string() + Oids = [oid()] + Expire = integer() + ExtraInfo = term() + ReqId = integer() + Reason = term() + + +

Asynchronous get-bulk-request (See RFC1905).

+

The reply will be delivered to the user through a call + to the snmpm_user callback function handle_pdu.

+

The Expire time indicates for how long the request is + valid (after which the manager is free to delete it).

+
-- cgit v1.2.3 From 29ac3cf1c1e6620344192944ebeae7ee8f220bb7 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 14 Apr 2011 12:24:51 +0200 Subject: Detailed usage of "Extra" usage in the request API functions, including the reserved value. --- lib/snmp/doc/src/snmpm.xml | 210 +++++++++++++++++++------------- lib/snmp/src/manager/snmpm.erl | 1 - lib/snmp/src/manager/snmpm_internal.hrl | 5 +- lib/snmp/src/manager/snmpm_net_if.erl | 18 ++- lib/snmp/src/manager/snmpm_server.erl | 2 - 5 files changed, 145 insertions(+), 91 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/snmpm.xml b/lib/snmp/doc/src/snmpm.xml index b1c8e56721..72849b9c9e 100644 --- a/lib/snmp/doc/src/snmpm.xml +++ b/lib/snmp/doc/src/snmpm.xml @@ -525,9 +525,11 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

The send option extra specifies an opaque data structure passed on to the net-if process. The net-if process included in this - application makes no use of this info, so the only use for it - in such a option (when using the built in net-if) would - be tracing.

+ application makes, with one exception, no use of this info, + so the only use for it in such a option (when using the built in + net-if) would be tracing. The one usage exception is: + Any tuple with snmpm_extra_info_tag as its first + element is reserved for internal use.

Some of the send options (community, sec_model, sec_name, sec_level and max_message_size) @@ -569,16 +571,18 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

Synchronous get-request.

Remaining is the remaining time of the given or - default timeout time.

+ default timeout time.

When Reason is {send_failed, ...} it means that - the net_if process failed to send the message. This could happen - because of any number of reasons, i.e. encoding error. R - is the actual reason in this case.

-

ExtraInfo is an opaque data structure passed on to - the net-if process. The net-if process included in this - application makes no use of this info, so the only use for it - in such a configuration (when using the built in net-if) would - be tracing.

+ the net_if process failed to send the message. This could happen + because of any number of reasons, i.e. encoding error. R + is the actual reason in this case.

+

ExtraInfo is an opaque data structure passed on to + the net-if process. The net-if process included in this + application makes, with one exception, no use of this info, + so the only use for it in such a configuration (when using the + built in net-if) would be tracing. The one usage exception is: + Any tuple with snmpm_extra_info_tag as its first + element is reserved for internal use.

For SnmpInfo, see the user callback function handle_report.

@@ -610,12 +614,14 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

The send option timeout specifies for how long the request is valid (after which the manager is free to delete it).

-

The send option extra specifies an opaque data structure +

The send option extra specifies an opaque data structure passed on to the net-if process. The net-if process included in this - application makes no use of this info, so the only use for it - in such a configuration (when using the built in net-if) would - be tracing.

- + application makes, with one exception, no use of this info, + so the only use for it in such a option (when using the built in + net-if) would be tracing. The one usage exception is: + Any tuple with snmpm_extra_info_tag as its first + element is reserved for internal use.

+

Some of the send options (community, sec_model, sec_name, sec_level and max_message_size) are override options. That is, @@ -646,15 +652,17 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

Asynchronous get-request.

The reply, if it arrives, will be delivered to the user - through a call to the snmpm_user callback function - handle_pdu.

-

The Expire time indicates for how long the request is - valid (after which the manager is free to delete it).

-

ExtraInfo is an opaque data structure passed on to - the net-if process. The net-if process included in this - application makes no use of this info, so the only use for it - in such a configuration (when using the built in net-if) would - be tracing.

+ through a call to the snmpm_user callback function + handle_pdu.

+

The Expire time indicates for how long the request is + valid (after which the manager is free to delete it).

+

ExtraInfo is an opaque data structure passed on to + the net-if process. The net-if process included in this + application makes, with one exception, no use of this info, + so the only use for it in such a configuration (when using the + built in net-if) would be tracing. The one usage exception is: + Any tuple with snmpm_extra_info_tag as its first + element is reserved for internal use.

@@ -695,9 +703,11 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

The send option extra specifies an opaque data structure passed on to the net-if process. The net-if process included in this - application makes no use of this info, so the only use for it - in such a configuration (when using the built in net-if) would - be tracing.

+ application makes, with one exception, no use of this info, + so the only use for it in such a option (when using the built in + net-if) would be tracing. The one usage exception is: + Any tuple with snmpm_extra_info_tag as its first + element is reserved for internal use.

Some of the send options (community, sec_model, sec_name, sec_level and max_message_size) @@ -735,15 +745,17 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

Synchronous get-next-request.

Remaining time of the given or default timeout time.

When Reason is {send_failed, ...} it means that - the net_if process failed to send the message. This could happen - because of any number of reasons, i.e. encoding error. R - is the actual reason in this case.

-

ExtraInfo is an opaque data structure passed on to - the net-if process. The net-if process included in this - application makes no use of this info, so the only use for it - in such a configuration (when using the built in net-if) would - be tracing.

- + the net_if process failed to send the message. This could happen + because of any number of reasons, i.e. encoding error. R + is the actual reason in this case.

+

ExtraInfo is an opaque data structure passed on to + the net-if process. The net-if process included in this + application makes, with one exception, no use of this info, + so the only use for it in such a configuration (when using the + built in net-if) would be tracing. The one usage exception is: + Any tuple with snmpm_extra_info_tag as its first + element is reserved for internal use.

+ @@ -769,12 +781,14 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

The send option timeout specifies for how long the request is valid (after which the manager is free to delete it).

-

The send option extra specifies an opaque data structure +

The send option extra specifies an opaque data structure passed on to the net-if process. The net-if process included in this - application makes no use of this info, so the only use for it - in such a configuration (when using the built in net-if) would - be tracing.

- + application makes, with one exception, no use of this info, + so the only use for it in such a option (when using the built in + net-if) would be tracing. The one usage exception is: + Any tuple with snmpm_extra_info_tag as its first + element is reserved for internal use.

+

Some of the send options (community, sec_model, sec_name, sec_level and max_message_size) are override options. That is, @@ -808,6 +822,13 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1 to the snmpm_user callback function handle_pdu.

The Expire time indicates for how long the request is valid (after which the manager is free to delete it).

+

ExtraInfo is an opaque data structure passed on to + the net-if process. The net-if process included in this + application makes, with one exception, no use of this info, + so the only use for it in such a configuration (when using the + built in net-if) would be tracing. The one usage exception is: + Any tuple with snmpm_extra_info_tag as its first + element is reserved for internal use.

@@ -851,9 +872,11 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

The send option extra specifies an opaque data structure passed on to the net-if process. The net-if process included in this - application makes no use of this info, so the only use for it - in such a configuration (when using the built in net-if) would - be tracing.

+ application makes, with one exception, no use of this info, + so the only use for it in such a option (when using the built in + net-if) would be tracing. The one usage exception is: + Any tuple with snmpm_extra_info_tag as its first + element is reserved for internal use.

Some of the send options (community, sec_model, sec_name, sec_level and max_message_size) @@ -891,16 +914,18 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

Synchronous set-request.

Remaining time of the given or default timeout time.

When Reason is {send_failed, ...} it means that - the net_if process failed to send the message. This could happen - because of any number of reasons, i.e. encoding error. R - is the actual reason in this case.

-

When var_and_val() is {oid(), value()}, the - manager makes an educated guess based on the loaded mibs.

-

ExtraInfo is an opaque data structure passed on to - the net-if process. The net-if process included in this - application makes no use of this info, so the only use for it - in such a configuration (when using the built in net-if) would - be tracing.

+ the net_if process failed to send the message. This could happen + because of any number of reasons, i.e. encoding error. R + is the actual reason in this case.

+

When var_and_val() is {oid(), value()}, the + manager makes an educated guess based on the loaded mibs.

+

ExtraInfo is an opaque data structure passed on to + the net-if process. The net-if process included in this + application makes, with one exception, no use of this info, + so the only use for it in such a configuration (when using the + built in net-if) would be tracing. The one usage exception is: + Any tuple with snmpm_extra_info_tag as its first + element is reserved for internal use.

@@ -934,10 +959,12 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

The send option extra specifies an opaque data structure passed on to the net-if process. The net-if process included in this - application makes no use of this info, so the only use for it - in such a configuration (when using the built in net-if) would - be tracing.

- + application makes, with one exception, no use of this info, + so the only use for it in such a option (when using the built in + net-if) would be tracing. The one usage exception is: + Any tuple with snmpm_extra_info_tag as its first + element is reserved for internal use.

+

Some of the send options (community, sec_model, sec_name, sec_level and max_message_size) are override options. That is, @@ -967,17 +994,19 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

Asynchronous set-request.

The reply will be delivered to the user through a call - to the snmpm_user callback function handle_pdu.

+ to the snmpm_user callback function handle_pdu.

The Expire time indicates for how long the request is - valid (after which the manager is free to delete it).

-

When var_and_val() is {oid(), value()}, the - manager makes an educated guess based on the loaded mibs.

-

ExtraInfo is an opaque data structure passed on to - the net-if process. The net-if process included in this - application makes no use of this info, so the only use for it - in such a configuration (when using the built in net-if) would - be tracing.

- + valid (after which the manager is free to delete it).

+

When var_and_val() is {oid(), value()}, the + manager makes an educated guess based on the loaded mibs.

+

ExtraInfo is an opaque data structure passed on to + the net-if process. The net-if process included in this + application makes, with one exception, no use of this info, + so the only use for it in such a configuration (when using the + built in net-if) would be tracing. The one usage exception is: + Any tuple with snmpm_extra_info_tag as its first + element is reserved for internal use.

+ @@ -1019,10 +1048,12 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

The send option extra specifies an opaque data structure passed on to the net-if process. The net-if process included in this - application makes no use of this info, so the only use for it - in such a configuration (when using the built in net-if) would - be tracing.

- + application makes, with one exception, no use of this info, + so the only use for it in such a option (when using the built in + net-if) would be tracing. The one usage exception is: + Any tuple with snmpm_extra_info_tag as its first + element is reserved for internal use.

+

Some of the send options (community, sec_model, sec_name, sec_level and max_message_size) are override options. That is, @@ -1059,15 +1090,17 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

Synchronous get-bulk-request (See RFC1905).

Remaining time of the given or default timeout time.

-

When Reason is {send_failed, ...} it means that - the net_if process failed to send the message. This could happen - because of any number of reasons, i.e. encoding error. R - is the actual reason in this case.

-

ExtraInfo is an opaque data structure passed on to - the net-if process. The net-if process included in this - application makes no use of this info, so the only use for it - in such a configuration (when using the built in net-if) would - be tracing.

+

When Reason is {send_failed, ...} it means that + the net_if process failed to send the message. This could happen + because of any number of reasons, i.e. encoding error. R + is the actual reason in this case.

+

ExtraInfo is an opaque data structure passed on to + the net-if process. The net-if process included in this + application makes, with one exception, no use of this info, + so the only use for it in such a configuration (when using the + built in net-if) would be tracing. The one usage exception is: + Any tuple with snmpm_extra_info_tag as its first + element is reserved for internal use.

@@ -1136,9 +1169,16 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

Asynchronous get-bulk-request (See RFC1905).

The reply will be delivered to the user through a call - to the snmpm_user callback function handle_pdu.

+ to the snmpm_user callback function handle_pdu.

The Expire time indicates for how long the request is - valid (after which the manager is free to delete it).

+ valid (after which the manager is free to delete it).

+

ExtraInfo is an opaque data structure passed on to + the net-if process. The net-if process included in this + application makes, with one exception, no use of this info, + so the only use for it in such a configuration (when using the + built in net-if) would be tracing. The one usage exception is: + Any tuple with snmpm_extra_info_tag as its first + element is reserved for internal use.

diff --git a/lib/snmp/src/manager/snmpm.erl b/lib/snmp/src/manager/snmpm.erl index dd85ec9f41..8a629eaf3b 100644 --- a/lib/snmp/src/manager/snmpm.erl +++ b/lib/snmp/src/manager/snmpm.erl @@ -164,7 +164,6 @@ -include("snmpm_internal.hrl"). -define(DEFAULT_AGENT_PORT, 161). -%% -define(DEFAULT_CONTEXT, ""). %% This function is called when the snmp application diff --git a/lib/snmp/src/manager/snmpm_internal.hrl b/lib/snmp/src/manager/snmpm_internal.hrl index 389aeaf197..53ad41c6b0 100644 --- a/lib/snmp/src/manager/snmpm_internal.hrl +++ b/lib/snmp/src/manager/snmpm_internal.hrl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2006-2009. All Rights Reserved. +%% Copyright Ericsson AB 2006-2011. 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,6 +21,9 @@ -define(snmpm_internal, true). -define(DEFAULT_CONTEXT, ""). +-define(SNMPM_EXTRA_INFO_TAG, snmpm_extra_info_tag). +-define(DEFAULT_EXTRA_INFO, {?SNMPM_EXTRA_INFO_TAG}). + -include_lib("snmp/src/app/snmp_internal.hrl"). diff --git a/lib/snmp/src/manager/snmpm_net_if.erl b/lib/snmp/src/manager/snmpm_net_if.erl index 07156dacd9..3d248fff57 100644 --- a/lib/snmp/src/manager/snmpm_net_if.erl +++ b/lib/snmp/src/manager/snmpm_net_if.erl @@ -99,7 +99,7 @@ stop(Pid) -> call(Pid, stop). send_pdu(Pid, Pdu, Vsn, MsgData, Addr, Port) -> - send_pdu(Pid, Pdu, Vsn, MsgData, Addr, Port, undefined). + send_pdu(Pid, Pdu, Vsn, MsgData, Addr, Port, ?DEFAULT_EXTRA_INFO). send_pdu(Pid, Pdu, Vsn, MsgData, Addr, Port, ExtraInfo) when is_record(Pdu, pdu) -> @@ -380,13 +380,14 @@ handle_call(Req, From, State) -> %% {noreply, State, Timeout} | %% {stop, Reason, State} (terminate/2 is called) %%-------------------------------------------------------------------- -handle_cast({send_pdu, Pdu, Vsn, MsgData, Addr, Port, _ExtraInfo}, State) -> +handle_cast({send_pdu, Pdu, Vsn, MsgData, Addr, Port, ExtraInfo}, State) -> ?vlog("received send_pdu message with" "~n Pdu: ~p" "~n Vsn: ~p" "~n MsgData: ~p" "~n Addr: ~p" "~n Port: ~p", [Pdu, Vsn, MsgData, Addr, Port]), + maybe_process_extra_info(ExtraInfo), maybe_handle_send_pdu(Pdu, Vsn, MsgData, Addr, Port, State), {noreply, State}; @@ -997,6 +998,19 @@ 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() -> diff --git a/lib/snmp/src/manager/snmpm_server.erl b/lib/snmp/src/manager/snmpm_server.erl index 29f0c61b0e..b8d7cf6375 100644 --- a/lib/snmp/src/manager/snmpm_server.erl +++ b/lib/snmp/src/manager/snmpm_server.erl @@ -101,8 +101,6 @@ -define(DEFAULT_ASYNC_GET_BULK_TIMEOUT, ?DEFAULT_ASYNC_TIMEOUT). -define(DEFAULT_ASYNC_SET_TIMEOUT, ?DEFAULT_ASYNC_TIMEOUT). --define(DEFAULT_EXTRA_INFO, undefined). - -define(SNMP_AGENT_PORT, 161). -define(SYNC_GET_TIMEOUT(SendOpts), -- cgit v1.2.3 From c733034aa59ee536b166e2c676bb0239ee62b1a6 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 14 Apr 2011 12:27:04 +0200 Subject: First test case for request API version 3. --- lib/snmp/test/Makefile | 7 +- lib/snmp/test/snmp_manager_test.erl | 179 +++++++++++++++++++++++++----------- lib/snmp/test/snmp_manager_user.erl | 16 +++- 3 files changed, 143 insertions(+), 59 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/Makefile b/lib/snmp/test/Makefile index b7975024b4..0e9c73081d 100644 --- a/lib/snmp/test/Makefile +++ b/lib/snmp/test/Makefile @@ -145,9 +145,12 @@ endif # ---------------------------------------------------- EBIN = . -ERL_COMPILE_FLAGS += -I../src \ +ERL_COMPILE_FLAGS += -I../../snmp/src/app \ + -I../../snmp/src/misc \ + -I../../snmp/src/agent \ + -I../../snmp/src/manager \ -I$(ERL_TOP)/lib/test_server/include \ - -I../include \ + -I../../snmp/include \ -Dsnmp_test_data=snmp_test_data \ -Dversion=\"$(VSN)$(PRE_VSN)\" \ +'{parse_transform,sys_pre_attributes}' \ diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index a98ab889d0..962c449617 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -37,13 +37,16 @@ -include_lib("snmp/include/snmp_types.hrl"). -include_lib("snmp/include/STANDARD-MIB.hrl"). +-include_lib("snmp/src/manager/snmpm_internal.hrl"). %%---------------------------------------------------------------------- %% External exports %%---------------------------------------------------------------------- -export([ - all/0, groups/0, init_per_group/2, end_per_group/2, + all/0, + groups/0, + init_per_group/2, end_per_group/2, init_per_testcase/2, end_per_testcase/2, @@ -54,49 +57,38 @@ notify_started01/1, notify_started02/1, - register_user1/1, - register_agent1/1, register_agent2/1, - info/1, - - - simple_sync_get1/1, simple_sync_get2/1, + simple_sync_get3/1, simple_async_get1/1, simple_async_get2/1, - simple_sync_get_next1/1, simple_sync_get_next2/1, simple_async_get_next1/1, simple_async_get_next2/1, - simple_sync_set1/1, simple_sync_set2/1, simple_async_set1/1, simple_async_set2/1, - simple_sync_get_bulk1/1, simple_sync_get_bulk2/1, simple_async_get_bulk1/1, simple_async_get_bulk2/1, - misc_async1/1, misc_async2/1, discovery/1, - - trap1/1, trap2/1, @@ -109,8 +101,6 @@ report/1, - - otp8015_1/1, otp8395_1/1 @@ -220,7 +210,7 @@ init_per_testcase2(Case, Config) -> Conf2. init_per_testcase3(Case, Config) -> - OldApiCases = + ApiCases01 = [ simple_sync_get1, simple_async_get1, @@ -232,7 +222,7 @@ init_per_testcase3(Case, Config) -> simple_async_get_bulk1, misc_async1 ], - NewApiCases = + ApiCases02 = [ simple_sync_get2, simple_async_get2, @@ -245,6 +235,10 @@ init_per_testcase3(Case, Config) -> misc_async2, otp8395_1 ], + ApiCases03 = + [ + simple_sync_get3 + ], Cases = [ trap1, @@ -256,8 +250,9 @@ init_per_testcase3(Case, Config) -> inform_swarm, report ] ++ - OldApiCases ++ - NewApiCases, + ApiCases01 ++ + ApiCases02 ++ + ApiCases03, case lists:member(Case, Cases) of true -> NoAutoInformCases = [inform1, inform2, inform3, inform_swarm], @@ -279,7 +274,7 @@ init_per_testcase3(Case, Config) -> Conf2 = init_agent(Conf1), Conf3 = init_manager(AutoInform, Conf2), Conf4 = init_mgr_user(Conf3), - case lists:member(Case, NewApiCases) of + case lists:member(Case, ApiCases02 ++ ApiCases03) of true -> init_mgr_user_data2(Conf4); false -> @@ -301,7 +296,7 @@ end_per_testcase(Case, Config) when is_list(Config) -> Conf2. end_per_testcase2(Case, Config) -> - OldApiCases = + ApiCases01 = [ simple_sync_get1, simple_async_get1, @@ -313,7 +308,7 @@ end_per_testcase2(Case, Config) -> simple_async_get_bulk1, misc_async1 ], - NewApiCases = + ApiCases02 = [ simple_sync_get2, simple_async_get2, @@ -326,6 +321,10 @@ end_per_testcase2(Case, Config) -> misc_async2, otp8395_1 ], + ApiCases03 = + [ + simple_sync_get3 + ], Cases = [ trap1, @@ -337,11 +336,12 @@ end_per_testcase2(Case, Config) -> inform_swarm, report ] ++ - OldApiCases ++ - NewApiCases, + ApiCases01 ++ + ApiCases02 ++ + ApiCases03, case lists:member(Case, Cases) of true -> - Conf1 = case lists:member(Case, NewApiCases) of + Conf1 = case lists:member(Case, ApiCases02 ++ ApiCases03) of true -> fin_mgr_user_data2(Config); false -> @@ -383,9 +383,22 @@ groups() -> notify_started02 ] }, - {misc_tests, [], [info]}, - {user_tests, [], [register_user1]}, - {agent_tests, [], [register_agent1, register_agent2]}, + {misc_tests, [], + [ + info + ] + }, + {user_tests, [], + [ + register_user1 + ] + }, + {agent_tests, [], + [ + register_agent1, + register_agent2 + ] + }, {request_tests, [], [ {group, get_tests}, @@ -399,6 +412,7 @@ groups() -> [ simple_sync_get1, simple_sync_get2, + simple_sync_get3, simple_async_get1, simple_async_get2 ] @@ -451,8 +465,16 @@ groups() -> {group, otp8395} ] }, - {otp8015, [], [otp8015_1]}, - {otp8395, [], [otp8395_1]} + {otp8015, [], + [ + otp8015_1 + ] + }, + {otp8395, [], + [ + otp8395_1 + ] + } ]. init_per_group(_GroupName, Config) -> @@ -1403,14 +1425,22 @@ do_simple_get(Node, Addr, Port, Oids) -> %%====================================================================== -simple_sync_get2(doc) -> ["Simple sync get-request - New style (TargetName)"]; +simple_sync_get2(doc) -> + ["Simple sync get-request - Version 2 API (TargetName)"]; simple_sync_get2(suite) -> []; simple_sync_get2(Config) when is_list(Config) -> process_flag(trap_exit, true), put(tname, ssg2), - do_simple_get(Config). + do_simple_get2(Config). + +do_simple_get2(Config) -> + Get = fun(Node, TargetName, Oids) -> + mgr_user_sync_get(Node, TargetName, Oids) + end, + PostVerify = fun() -> ok end, + do_simple_get2(Config, Get, PostVerify). -do_simple_get(Config) -> +do_simple_get2(Config, Get, PostVerify) -> p("starting with Config: ~p~n", [Config]), Node = ?config(manager_node, Config), @@ -1418,20 +1448,21 @@ do_simple_get(Config) -> p("issue get-request without loading the mib"), Oids1 = [?sysObjectID_instance, ?sysDescr_instance, ?sysUpTime_instance], - ?line ok = do_simple_get(Node, TargetName, Oids1), + ?line ok = do_simple_get2(Node, TargetName, Oids1, Get, PostVerify), p("issue get-request after first loading the mibs"), ?line ok = mgr_user_load_mib(Node, std_mib()), Oids2 = [[sysObjectID, 0], [sysDescr, 0], [sysUpTime, 0]], - ?line ok = do_simple_get(Node, TargetName, Oids2), + ?line ok = do_simple_get2(Node, TargetName, Oids2, Get, PostVerify), ok. - -do_simple_get(Node, TargetName, Oids) -> - ?line {ok, Reply, Rem} = mgr_user_sync_get(Node, TargetName, Oids), + +do_simple_get2(Node, TargetName, Oids, Get, PostVerify) + when is_function(Get, 3) andalso is_function(PostVerify, 0) -> + ?line {ok, Reply, Rem} = Get(Node, TargetName, 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 @@ -1446,7 +1477,7 @@ do_simple_get(Node, TargetName, Oids) -> "~n SysDescr: ~s" "~n SysUpTime: ~w", [SysObjectID, SysDescr, SysUpTime]), - ok; + PostVerify(); {noError, 0, Vbs} -> p("unexpected varbinds: ~n~p", [Vbs]), {error, {unexpected_vbs, Vbs}}; @@ -1457,6 +1488,38 @@ do_simple_get(Node, TargetName, Oids) -> ok. +%%====================================================================== + +simple_sync_get3(doc) -> + ["Simple sync get-request - Version 3 API (TargetName and send-opts)"]; +simple_sync_get3(suite) -> []; +simple_sync_get3(Config) when is_list(Config) -> + process_flag(trap_exit, true), + put(tname, ssg3), + do_simple_get3(Config). + +do_simple_get3(Config) -> + Self = self(), + Msg = simple_sync_get3, + Fun = fun() -> Self ! Msg end, + Extra = {?SNMPM_EXTRA_INFO_TAG, Fun}, + SendOpts = + [ + {extra, Extra} + ], + Get = fun(Node, TargetName, Oids) -> + mgr_user_sync_get2(Node, TargetName, Oids, SendOpts) + end, + PostVerify = + fun() -> + receive + Msg -> + ok + end + end, + do_simple_get2(Config, Get, PostVerify). + + %%====================================================================== simple_async_get1(doc) -> ["Simple (async) get-request - " @@ -1560,8 +1623,8 @@ sag_verify_vbs([Vb|_], [E|_]) -> %%====================================================================== -simple_async_get2(doc) -> ["Simple (async) get-request - " - "New style (TargetName)"]; +simple_async_get2(doc) -> + ["Simple (async) get-request - Version 2 API (TargetName)"]; simple_async_get2(suite) -> []; simple_async_get2(Config) when is_list(Config) -> process_flag(trap_exit, true), @@ -1766,8 +1829,8 @@ check_ssgn_vbs([Vb|_], [E|_]) -> %%====================================================================== -simple_sync_get_next2(doc) -> ["Simple (sync) get_next-request - " - "New style (TargetName)"]; +simple_sync_get_next2(doc) -> + ["Simple (sync) get_next-request - Version 2 API (TargetName)"]; simple_sync_get_next2(suite) -> []; simple_sync_get_next2(Config) when is_list(Config) -> process_flag(trap_exit, true), @@ -1967,8 +2030,8 @@ async_gn_exec1(Node, Addr, Port, Oids) -> %%====================================================================== -simple_async_get_next2(doc) -> ["Simple (async) get_next-request - " - "New style (TargetName)"]; +simple_async_get_next2(doc) -> + ["Simple (async) get_next-request - Version 2 API (TargetName)"]; simple_async_get_next2(suite) -> []; simple_async_get_next2(Config) when is_list(Config) -> process_flag(trap_exit, true), @@ -2132,7 +2195,8 @@ value_of_vavs([{_Oid, Val}|VAVs], Acc) -> %%====================================================================== -simple_sync_set2(doc) -> ["Simple (sync) set-request - New style (TargetName)"]; +simple_sync_set2(doc) -> + ["Simple (sync) set-request - Version 2 API (TargetName)"]; simple_sync_set2(suite) -> []; simple_sync_set2(Config) when is_list(Config) -> process_flag(trap_exit, true), @@ -2281,8 +2345,8 @@ sas_verify_vbs([Vb|_], [E|_]) -> %%====================================================================== -simple_async_set2(doc) -> ["Simple (async) set-request - " - "New style (TargetName)"]; +simple_async_set2(doc) -> + ["Simple (async) set-request - Version 2 API (TargetName)"]; simple_async_set2(suite) -> []; simple_async_set2(Config) when is_list(Config) -> process_flag(trap_exit, true), @@ -2514,8 +2578,8 @@ check_ssgb_vbs([R|_], [E|_]) -> %%====================================================================== -simple_sync_get_bulk2(doc) -> ["Simple (sync) get_bulk-request - " - "New style (TargetName)"]; +simple_sync_get_bulk2(doc) -> + ["Simple (sync) get_bulk-request - Version 2 API (TargetName)"]; simple_sync_get_bulk2(suite) -> []; simple_sync_get_bulk2(Config) when is_list(Config) -> process_flag(trap_exit, true), @@ -2792,8 +2856,8 @@ async_gb_exec1(Node, Addr, Port, {NR, MR, Oids}) -> %%====================================================================== -simple_async_get_bulk2(doc) -> ["Simple (async) get_bulk-request - " - "New style (TargetName)"]; +simple_async_get_bulk2(doc) -> + ["Simple (async) get_bulk-request - Version 2 API (TargetName)"]; simple_async_get_bulk2(suite) -> []; simple_async_get_bulk2(Config) when is_list(Config) -> process_flag(trap_exit, true), @@ -3123,8 +3187,8 @@ misc_async1(Config) when is_list(Config) -> %%====================================================================== -misc_async2(doc) -> ["Misc (async) request(s) - " - "New style (TargetName)"]; +misc_async2(doc) -> + ["Misc (async) request(s) - Version 2 API (TargetName)"]; misc_async2(suite) -> []; misc_async2(Config) when is_list(Config) -> process_flag(trap_exit, true), @@ -4484,7 +4548,7 @@ otp8395_1(suite) -> []; otp8395_1(Config) when is_list(Config) -> process_flag(trap_exit, true), put(tname, otp8395_1), - do_simple_get(Config). + do_simple_get2(Config). %%====================================================================== @@ -5030,6 +5094,9 @@ mgr_user_sync_get(Node, Addr_or_TargetName, Oids) -> mgr_user_sync_get(Node, Addr, Port, Oids) -> rcall(Node, snmp_manager_user, sync_get, [Addr, Port, Oids]). +mgr_user_sync_get2(Node, TargetName, Oids, SendOpts) -> + rcall(Node, snmp_manager_user, sync_get2, [TargetName, Oids, SendOpts]). + %% mgr_user_async_get(Node, Oids) -> %% mgr_user_async_get(Node, ?LOCALHOST(), ?AGENT_PORT, Oids). mgr_user_async_get(Node, Addr_or_TargetName, Oids) -> diff --git a/lib/snmp/test/snmp_manager_user.erl b/lib/snmp/test/snmp_manager_user.erl index 71fdebb67b..af0d7839a8 100644 --- a/lib/snmp/test/snmp_manager_user.erl +++ b/lib/snmp/test/snmp_manager_user.erl @@ -50,7 +50,7 @@ update_agent_info/3, update_agent_info/4, which_all_agents/0, which_own_agents/0, load_mib/1, unload_mib/1, - sync_get/1, sync_get/2, sync_get/3, + sync_get/1, sync_get/2, sync_get/3, sync_get2/3, async_get/1, async_get/2, async_get/3, sync_get_next/1, sync_get_next/2, sync_get_next/3, async_get_next/1, async_get_next/2, async_get_next/3, @@ -171,6 +171,10 @@ sync_get(Addr_or_TargetName, Oids) -> sync_get(Addr, Port, Oids) -> call({sync_get, Addr, Port, Oids}). +sync_get2(TargetName, Oids, SendOpts) -> + call({sync_get2, TargetName, Oids, SendOpts}). + + %% -- async_get(Oids) -> @@ -400,6 +404,16 @@ loop(#state{parent = Parent, id = Id} = S) -> %% -- (sync) get-request -- %% + {{sync_get2, TargetName, Oids, SendOpts}, From, Ref} + when is_list(TargetName) -> + d("loop -> received sync_get2 request with" + "~n TargetName: ~p" + "~n Oids: ~p" + "~n SendOpts: ~p", [TargetName, Oids, SendOpts]), + Res = snmpm:sync_get2(Id, TargetName, Oids, SendOpts), + reply(From, Res, Ref), + loop(S); + %% No agent specified, so send it to all of them {{sync_get, Oids}, From, Ref} -> d("loop -> received sync_get request " -- cgit v1.2.3 From efacc58e49d5b25dc4b1c74e5f8330c9f26a4511 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 14 Apr 2011 15:07:59 +0200 Subject: Async get test case for version 3 request API. --- lib/snmp/test/snmp_manager_test.erl | 161 +++++++++++++++++++++++------------- lib/snmp/test/snmp_manager_user.erl | 15 +++- 2 files changed, 117 insertions(+), 59 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index 962c449617..e34e08906d 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -69,6 +69,7 @@ simple_sync_get3/1, simple_async_get1/1, simple_async_get2/1, + simple_async_get3/1, simple_sync_get_next1/1, simple_sync_get_next2/1, @@ -237,7 +238,8 @@ init_per_testcase3(Case, Config) -> ], ApiCases03 = [ - simple_sync_get3 + simple_sync_get3, + simple_async_get3 ], Cases = [ @@ -323,7 +325,8 @@ end_per_testcase2(Case, Config) -> ], ApiCases03 = [ - simple_sync_get3 + simple_sync_get3, + simple_async_get3 ], Cases = [ @@ -414,7 +417,8 @@ groups() -> simple_sync_get2, simple_sync_get3, simple_async_get1, - simple_async_get2 + simple_async_get2, + simple_async_get3 ] }, {get_next_tests, [], @@ -1384,15 +1388,15 @@ simple_sync_get1(Config) when is_list(Config) -> p("issue get-request without loading the mib"), Oids1 = [?sysObjectID_instance, ?sysDescr_instance, ?sysUpTime_instance], - ?line ok = do_simple_get(Node, Addr, Port, Oids1), + ?line ok = do_simple_sync_get(Node, Addr, Port, Oids1), p("issue get-request after first loading the mibs"), ?line ok = mgr_user_load_mib(Node, std_mib()), Oids2 = [[sysObjectID, 0], [sysDescr, 0], [sysUpTime, 0]], - ?line ok = do_simple_get(Node, Addr, Port, Oids2), + ?line ok = do_simple_sync_get(Node, Addr, Port, Oids2), ok. -do_simple_get(Node, Addr, Port, Oids) -> +do_simple_sync_get(Node, Addr, Port, Oids) -> ?line {ok, Reply, Rem} = mgr_user_sync_get(Node, Addr, Port, Oids), ?DBG("~n Reply: ~p" @@ -1431,16 +1435,16 @@ simple_sync_get2(suite) -> []; simple_sync_get2(Config) when is_list(Config) -> process_flag(trap_exit, true), put(tname, ssg2), - do_simple_get2(Config). + do_simple_sync_get2(Config). -do_simple_get2(Config) -> +do_simple_sync_get2(Config) -> Get = fun(Node, TargetName, Oids) -> mgr_user_sync_get(Node, TargetName, Oids) end, PostVerify = fun() -> ok end, - do_simple_get2(Config, Get, PostVerify). + do_simple_sync_get2(Config, Get, PostVerify). -do_simple_get2(Config, Get, PostVerify) -> +do_simple_sync_get2(Config, Get, PostVerify) -> p("starting with Config: ~p~n", [Config]), Node = ?config(manager_node, Config), @@ -1448,15 +1452,15 @@ do_simple_get2(Config, Get, PostVerify) -> p("issue get-request without loading the mib"), Oids1 = [?sysObjectID_instance, ?sysDescr_instance, ?sysUpTime_instance], - ?line ok = do_simple_get2(Node, TargetName, Oids1, Get, PostVerify), + ?line ok = do_simple_sync_get2(Node, TargetName, Oids1, Get, PostVerify), p("issue get-request after first loading the mibs"), ?line ok = mgr_user_load_mib(Node, std_mib()), Oids2 = [[sysObjectID, 0], [sysDescr, 0], [sysUpTime, 0]], - ?line ok = do_simple_get2(Node, TargetName, Oids2, Get, PostVerify), + ?line ok = do_simple_sync_get2(Node, TargetName, Oids2, Get, PostVerify), ok. -do_simple_get2(Node, TargetName, Oids, Get, PostVerify) +do_simple_sync_get2(Node, TargetName, Oids, Get, PostVerify) when is_function(Get, 3) andalso is_function(PostVerify, 0) -> ?line {ok, Reply, Rem} = Get(Node, TargetName, Oids), @@ -1496,9 +1500,9 @@ simple_sync_get3(suite) -> []; simple_sync_get3(Config) when is_list(Config) -> process_flag(trap_exit, true), put(tname, ssg3), - do_simple_get3(Config). + do_simple_sync_get3(Config). -do_simple_get3(Config) -> +do_simple_sync_get3(Config) -> Self = self(), Msg = simple_sync_get3, Fun = fun() -> Self ! Msg end, @@ -1517,7 +1521,7 @@ do_simple_get3(Config) -> ok end end, - do_simple_get2(Config, Get, PostVerify). + do_simple_sync_get2(Config, Get, PostVerify). %%====================================================================== @@ -1630,59 +1634,69 @@ simple_async_get2(Config) when is_list(Config) -> process_flag(trap_exit, true), put(tname, sag2), p("starting with Config: ~p~n", [Config]), - MgrNode = ?config(manager_node, Config), AgentNode = ?config(agent_node, Config), TargetName = ?config(manager_agent_target_name, Config), + Get = fun(Oids) -> async_g_exec2(MgrNode, TargetName, Oids) end, + PostVerify = fun() -> ok end, + do_simple_async_sync_get2(Config, MgrNode, AgentNode, Get, PostVerify). +do_simple_async_sync_get2(Config, MgrNode, AgentNode, Get, PostVerify) -> ?line ok = mgr_user_load_mib(MgrNode, std_mib()), Test2Mib = test2_mib(Config), ?line ok = mgr_user_load_mib(MgrNode, Test2Mib), ?line ok = agent_load_mib(AgentNode, Test2Mib), - - Exec = fun(Data) -> - async_g_exec2(MgrNode, TargetName, Data) - end, - - Requests = [ - { 1, - [?sysObjectID_instance], - Exec, - fun(X) -> sag_verify(X, [?sysObjectID_instance]) end}, - { 2, - [?sysDescr_instance, ?sysUpTime_instance], - Exec, - fun(X) -> - sag_verify(X, [?sysObjectID_instance, - ?sysUpTime_instance]) - end}, - { 3, - [[sysObjectID, 0], [sysDescr, 0], [sysUpTime, 0]], - Exec, - fun(X) -> - sag_verify(X, [?sysObjectID_instance, - ?sysDescr_instance, - ?sysUpTime_instance]) - end}, - { 4, - [?sysObjectID_instance, - ?sysDescr_instance, - ?sysUpTime_instance], - Exec, - fun(X) -> - sag_verify(X, [?sysObjectID_instance, - ?sysDescr_instance, - ?sysUpTime_instance]) - end} - ], + do_simple_async_sync_get2(fun() -> mgr_info(MgrNode) end, + fun() -> agent_info(AgentNode) end, + Get, PostVerify). + +do_simple_async_sync_get2(MgrInfo, AgentInfo, Get, PostVerify) + when is_function(MgrInfo, 0) andalso + is_function(AgentInfo, 0) andalso + is_function(Get, 1) andalso + is_function(PostVerify, 0) -> + Requests = + [ + { 1, + [?sysObjectID_instance], + Get, + fun(X) -> sag_verify(X, [?sysObjectID_instance]), PostVerify() end}, + { 2, + [?sysDescr_instance, ?sysUpTime_instance], + Get, + fun(X) -> + sag_verify(X, [?sysObjectID_instance, + ?sysUpTime_instance]) + end}, + { 3, + [[sysObjectID, 0], [sysDescr, 0], [sysUpTime, 0]], + Get, + fun(X) -> + sag_verify(X, [?sysObjectID_instance, + ?sysDescr_instance, + ?sysUpTime_instance]), + PostVerify() + end}, + { 4, + [?sysObjectID_instance, + ?sysDescr_instance, + ?sysUpTime_instance], + Get, + fun(X) -> + sag_verify(X, [?sysObjectID_instance, + ?sysDescr_instance, + ?sysUpTime_instance]), + PostVerify() + end} + ], - p("manager info when starting test: ~n~p", [mgr_info(MgrNode)]), - p("agent info when starting test: ~n~p", [agent_info(AgentNode)]), + p("manager info when starting test: ~n~p", [MgrInfo()]), + p("agent info when starting test: ~n~p", [AgentInfo()]), ?line ok = async_exec(Requests, []), - p("manager info when ending test: ~n~p", [mgr_info(MgrNode)]), - p("agent info when ending test: ~n~p", [agent_info(AgentNode)]), + p("manager info when ending test: ~n~p", [MgrInfo()]), + p("agent info when ending test: ~n~p", [AgentInfo()]), ok. @@ -1690,6 +1704,34 @@ async_g_exec2(Node, TargetName, Oids) -> mgr_user_async_get(Node, TargetName, Oids). +%%====================================================================== + +simple_async_get3(doc) -> + ["Simple (async) get-request - Version 3 API (TargetName and send-opts)"]; +simple_async_get3(suite) -> []; +simple_async_get3(Config) when is_list(Config) -> + process_flag(trap_exit, true), + put(tname, sag3), + p("starting with Config: ~p~n", [Config]), + MgrNode = ?config(manager_node, Config), + AgentNode = ?config(agent_node, Config), + TargetName = ?config(manager_agent_target_name, Config), + Self = self(), + Msg = simple_async_get3, + Fun = fun() -> Self ! Msg end, + Extra = {?SNMPM_EXTRA_INFO_TAG, Fun}, + SendOpts = + [ + {extra, Extra} + ], + Get = fun(Oids) -> async_g_exec3(MgrNode, TargetName, Oids, SendOpts) end, + PostVerify = fun() -> receive Msg -> ok end end, + do_simple_async_sync_get2(Config, MgrNode, AgentNode, Get, PostVerify). + +async_g_exec3(Node, TargetName, Oids, SendOpts) -> + mgr_user_async_get2(Node, TargetName, Oids, SendOpts). + + %%====================================================================== simple_sync_get_next1(doc) -> ["Simple (sync) get_next-request - " @@ -4548,7 +4590,7 @@ otp8395_1(suite) -> []; otp8395_1(Config) when is_list(Config) -> process_flag(trap_exit, true), put(tname, otp8395_1), - do_simple_get2(Config). + do_simple_sync_get2(Config). %%====================================================================== @@ -5104,6 +5146,9 @@ mgr_user_async_get(Node, Addr_or_TargetName, Oids) -> mgr_user_async_get(Node, Addr, Port, Oids) -> rcall(Node, snmp_manager_user, async_get, [Addr, Port, Oids]). +mgr_user_async_get2(Node, TargetName, Oids, SendOpts) -> + rcall(Node, snmp_manager_user, async_get2, [TargetName, Oids, SendOpts]). + %% mgr_user_sync_get_next(Node, Oids) -> %% mgr_user_sync_get_next(Node, ?LOCALHOST(), ?AGENT_PORT, Oids). mgr_user_sync_get_next(Node, Addr_or_TargetName, Oids) -> diff --git a/lib/snmp/test/snmp_manager_user.erl b/lib/snmp/test/snmp_manager_user.erl index af0d7839a8..d4c2574b17 100644 --- a/lib/snmp/test/snmp_manager_user.erl +++ b/lib/snmp/test/snmp_manager_user.erl @@ -51,7 +51,7 @@ which_all_agents/0, which_own_agents/0, load_mib/1, unload_mib/1, sync_get/1, sync_get/2, sync_get/3, sync_get2/3, - async_get/1, async_get/2, async_get/3, + async_get/1, async_get/2, async_get/3, async_get2/3, sync_get_next/1, sync_get_next/2, sync_get_next/3, async_get_next/1, async_get_next/2, async_get_next/3, sync_set/1, sync_set/2, sync_set/3, @@ -186,6 +186,9 @@ async_get(Addr_or_TargetName, Oids) -> async_get(Addr, Port, Oids) -> call({async_get, Addr, Port, Oids}). +async_get2(TargetName, Oids, SendOpts) -> + call({async_get2, TargetName, Oids, SendOpts}). + %% -- sync_get_next(Oids) -> @@ -453,6 +456,16 @@ loop(#state{parent = Parent, id = Id} = S) -> %% -- (async) get-request -- %% + {{async_get2, TargetName, Oids, SendOpts}, From, Ref} + when is_list(TargetName) -> + d("loop -> received async_get request with" + "~n TargetName: ~p" + "~n Oids: ~p" + "~n SendOpts: ~p", [TargetName, Oids, SendOpts]), + Res = snmpm:async_get2(Id, TargetName, Oids, SendOpts), + reply(From, Res, Ref), + loop(S); + %% No agent specified, so send it to all of them {{async_get, Oids}, From, Ref} -> d("loop -> received async_get request"), -- cgit v1.2.3 From be8ad07f8247d3b223846059eca6ab7192f6402b Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 14 Apr 2011 15:47:45 +0200 Subject: Sync get-next test case for version 3 request API. --- lib/snmp/test/snmp_manager_test.erl | 83 ++++++++++++++++++++++++++++++------- lib/snmp/test/snmp_manager_user.erl | 15 ++++++- 2 files changed, 81 insertions(+), 17 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index e34e08906d..1ffcc651d7 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -73,6 +73,7 @@ simple_sync_get_next1/1, simple_sync_get_next2/1, + simple_sync_get_next3/1, simple_async_get_next1/1, simple_async_get_next2/1, @@ -239,7 +240,8 @@ init_per_testcase3(Case, Config) -> ApiCases03 = [ simple_sync_get3, - simple_async_get3 + simple_async_get3, + simple_sync_get_next3 ], Cases = [ @@ -326,7 +328,8 @@ end_per_testcase2(Case, Config) -> ApiCases03 = [ simple_sync_get3, - simple_async_get3 + simple_async_get3, + simple_sync_get_next3 ], Cases = [ @@ -425,6 +428,7 @@ groups() -> [ simple_sync_get_next1, simple_sync_get_next2, + simple_sync_get_next3, simple_async_get_next1, simple_async_get_next2 ] @@ -1876,18 +1880,28 @@ simple_sync_get_next2(doc) -> simple_sync_get_next2(suite) -> []; simple_sync_get_next2(Config) when is_list(Config) -> process_flag(trap_exit, true), - put(tname, ssgn), + put(tname, ssgn2), p("starting with Config: ~p~n", [Config]), - MgrNode = ?config(manager_node, Config), - AgentNode = ?config(agent_node, Config), + GetNext = fun(Node, TargetName, Oids) -> + 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) + when is_function(GetNext, 3) andalso is_function(PostVerify, 1) -> + + MgrNode = ?config(manager_node, Config), + AgentNode = ?config(agent_node, Config), TargetName = ?config(manager_agent_target_name, Config), %% -- 1 -- Oids01 = [[1,3,7,1]], VF01 = fun(X) -> verify_ssgn_reply1(X, [{[1,3,7,1],endOfMibView}]) end, ?line ok = do_simple_get_next(1, - MgrNode, TargetName, Oids01, VF01), + MgrNode, TargetName, Oids01, VF01, + GetNext, PostVerify), ?line ok = mgr_user_load_mib(MgrNode, std_mib()), @@ -1897,7 +1911,8 @@ simple_sync_get_next2(Config) when is_list(Config) -> verify_ssgn_reply1(X, [?sysDescr_instance, endOfMibView]) end, ?line ok = do_simple_get_next(2, - MgrNode, TargetName, Oids02, VF02), + MgrNode, TargetName, Oids02, VF02, + GetNext, PostVerify), Test2Mib = test2_mib(Config), ?line ok = mgr_user_load_mib(MgrNode, Test2Mib), @@ -1910,7 +1925,8 @@ simple_sync_get_next2(Config) when is_list(Config) -> verify_ssgn_reply1(X, [{fl([TCnt2,2]), 100}]) end, ?line ok = do_simple_get_next(3, - MgrNode, TargetName, Oids03, VF03), + MgrNode, TargetName, Oids03, VF03, + GetNext, PostVerify), %% -- 4 -- Oids04 = [[TCnt2, 2]], @@ -1918,7 +1934,8 @@ simple_sync_get_next2(Config) when is_list(Config) -> verify_ssgn_reply1(X, [{fl([TCnt2,2]), endOfMibView}]) end, ?line ok = do_simple_get_next(4, - MgrNode, TargetName, Oids04, VF04), + MgrNode, TargetName, Oids04, VF04, + GetNext, PostVerify), %% -- 5 -- ?line {ok, [TGenErr1|_]} = mgr_user_name_to_oid(MgrNode, tGenErr1), @@ -1927,7 +1944,8 @@ simple_sync_get_next2(Config) when is_list(Config) -> verify_ssgn_reply2(X, {genErr, 1, [TGenErr1]}) end, ?line ok = do_simple_get_next(5, - MgrNode, TargetName, Oids05, VF05), + MgrNode, TargetName, Oids05, VF05, + GetNext, PostVerify), %% -- 6 -- ?line {ok, [TGenErr2|_]} = mgr_user_name_to_oid(MgrNode, tGenErr2), @@ -1936,7 +1954,8 @@ simple_sync_get_next2(Config) when is_list(Config) -> verify_ssgn_reply2(X, {genErr, 1, [TGenErr2]}) end, ?line ok = do_simple_get_next(6, - MgrNode, TargetName, Oids06, VF06), + MgrNode, TargetName, Oids06, VF06, + GetNext, PostVerify), %% -- 7 -- ?line {ok, [TGenErr3|_]} = mgr_user_name_to_oid(MgrNode, tGenErr3), @@ -1946,7 +1965,8 @@ simple_sync_get_next2(Config) when is_list(Config) -> [?sysDescr, TGenErr3]}) end, ?line ok = do_simple_get_next(7, - MgrNode, TargetName, Oids07, VF07), + MgrNode, TargetName, Oids07, VF07, + GetNext, PostVerify), %% -- 8 -- ?line {ok, [TTooBig|_]} = mgr_user_name_to_oid(MgrNode, tTooBig), @@ -1955,24 +1975,52 @@ simple_sync_get_next2(Config) when is_list(Config) -> verify_ssgn_reply2(X, {tooBig, 0, []}) end, ?line ok = do_simple_get_next(8, - MgrNode, TargetName, Oids08, VF08), + MgrNode, TargetName, Oids08, VF08, + GetNext, PostVerify), ok. -do_simple_get_next(N, Node, TargetName, Oids, Verify) -> +do_simple_get_next(N, Node, TargetName, Oids, Verify, GetNext, PostVerify) -> p("issue get-next command ~w", [N]), - case mgr_user_sync_get_next(Node, TargetName, Oids) of + case GetNext(Node, TargetName, Oids) of {ok, Reply, Rem} -> ?DBG("get-next ok:" "~n Reply: ~p" "~n Rem: ~w", [Reply, Rem]), - Verify(Reply); + PostVerify(Verify(Reply)); Error -> {error, {unexpected_reply, Error}} end. +%%====================================================================== + +simple_sync_get_next3(doc) -> + ["Simple (sync) get_next-request - " + "Version 3 API (TargetName with send-opts)"]; +simple_sync_get_next3(suite) -> []; +simple_sync_get_next3(Config) when is_list(Config) -> + process_flag(trap_exit, true), + put(tname, ssgn3), + p("starting with Config: ~p~n", [Config]), + Self = self(), + Msg = simple_sync_get_next3, + Fun = fun() -> Self ! Msg end, + Extra = {?SNMPM_EXTRA_INFO_TAG, Fun}, + SendOpts = + [ + {extra, Extra} + ], + GetNext = fun(Node, TargetName, Oids) -> + mgr_user_sync_get_next2(Node, TargetName, Oids, SendOpts) + end, + PostVerify = fun(ok) -> receive Msg -> ok end; + (Error) -> Error + end, + do_simple_sync_get_next2(Config, GetNext, PostVerify). + + %%====================================================================== simple_async_get_next1(doc) -> ["Simple (async) get_next-request - " @@ -5156,6 +5204,9 @@ mgr_user_sync_get_next(Node, Addr_or_TargetName, Oids) -> mgr_user_sync_get_next(Node, Addr, Port, Oids) -> rcall(Node, snmp_manager_user, sync_get_next, [Addr, Port, Oids]). +mgr_user_sync_get_next2(Node, TargetName, Oids, SendOpts) -> + rcall(Node, snmp_manager_user, sync_get_next2, [TargetName, Oids, SendOpts]). + %% mgr_user_async_get_next(Node, Oids) -> %% mgr_user_async_get_next(Node, ?LOCALHOST(), ?AGENT_PORT, Oids). mgr_user_async_get_next(Node, Addr_or_TargetName, Oids) -> diff --git a/lib/snmp/test/snmp_manager_user.erl b/lib/snmp/test/snmp_manager_user.erl index d4c2574b17..21543e4194 100644 --- a/lib/snmp/test/snmp_manager_user.erl +++ b/lib/snmp/test/snmp_manager_user.erl @@ -52,7 +52,7 @@ load_mib/1, unload_mib/1, sync_get/1, sync_get/2, sync_get/3, sync_get2/3, async_get/1, async_get/2, async_get/3, async_get2/3, - sync_get_next/1, sync_get_next/2, sync_get_next/3, + sync_get_next/1, sync_get_next/2, sync_get_next/3, sync_get_next2/3, async_get_next/1, async_get_next/2, async_get_next/3, sync_set/1, sync_set/2, sync_set/3, async_set/1, async_set/2, async_set/3, @@ -200,6 +200,9 @@ sync_get_next(Addr_or_TargetName, Oids) -> sync_get_next(Addr, Port, Oids) -> call({sync_get_next, Addr, Port, Oids}). +sync_get_next2(TargetName, Oids, SendOpts) -> + call({sync_get_next2, TargetName, Oids, SendOpts}). + %% -- async_get_next(Oids) -> @@ -499,6 +502,16 @@ loop(#state{parent = Parent, id = Id} = S) -> %% -- (sync) get_next-request -- %% + {{sync_get_next2, TargetName, Oids, SendOpts}, From, Ref} + when is_list(TargetName) -> + d("loop -> received sync_get_next request with" + "~n TargetName: ~p" + "~n Oids: ~p" + "~n SendOpts: ~p", [TargetName, Oids, SendOpts]), + Res = snmpm:sync_get_next2(Id, TargetName, Oids, SendOpts), + reply(From, Res, Ref), + loop(S); + %% No agent specified, so send it to all of them {{sync_get_next, Oids}, From, Ref} -> d("loop -> received sync_get_next request"), -- cgit v1.2.3 From ceb31ba2c09943bf2580f1cc9403905422a7dd44 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 14 Apr 2011 16:35:14 +0200 Subject: Async get-next test cases for version 3 request API. --- lib/snmp/test/snmp_manager_test.erl | 137 ++++++++++++++++++++++++++---------- lib/snmp/test/snmp_manager_user.erl | 15 +++- 2 files changed, 114 insertions(+), 38 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index 1ffcc651d7..986c324179 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -76,6 +76,7 @@ simple_sync_get_next3/1, simple_async_get_next1/1, simple_async_get_next2/1, + simple_async_get_next3/1, simple_sync_set1/1, simple_sync_set2/1, @@ -241,7 +242,8 @@ init_per_testcase3(Case, Config) -> [ simple_sync_get3, simple_async_get3, - simple_sync_get_next3 + simple_sync_get_next3, + simple_async_get_next3 ], Cases = [ @@ -329,7 +331,8 @@ end_per_testcase2(Case, Config) -> [ simple_sync_get3, simple_async_get3, - simple_sync_get_next3 + simple_sync_get_next3, + simple_async_get_next3 ], Cases = [ @@ -430,7 +433,8 @@ groups() -> simple_sync_get_next2, simple_sync_get_next3, simple_async_get_next1, - simple_async_get_next2 + simple_async_get_next2, + simple_async_get_next3 ] }, {set_tests, [], @@ -1642,7 +1646,7 @@ simple_async_get2(Config) when is_list(Config) -> AgentNode = ?config(agent_node, Config), TargetName = ?config(manager_agent_target_name, Config), Get = fun(Oids) -> async_g_exec2(MgrNode, TargetName, Oids) end, - PostVerify = fun() -> ok 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) -> @@ -1658,28 +1662,29 @@ do_simple_async_sync_get2(MgrInfo, AgentInfo, Get, PostVerify) when is_function(MgrInfo, 0) andalso is_function(AgentInfo, 0) andalso is_function(Get, 1) andalso - is_function(PostVerify, 0) -> + is_function(PostVerify, 1) -> Requests = [ { 1, [?sysObjectID_instance], Get, - fun(X) -> sag_verify(X, [?sysObjectID_instance]), PostVerify() end}, + fun(X) -> + PostVerify(sag_verify(X, [?sysObjectID_instance])) end}, { 2, [?sysDescr_instance, ?sysUpTime_instance], Get, fun(X) -> - sag_verify(X, [?sysObjectID_instance, - ?sysUpTime_instance]) + PostVerify(sag_verify(X, [?sysObjectID_instance, + ?sysUpTime_instance])) end}, { 3, [[sysObjectID, 0], [sysDescr, 0], [sysUpTime, 0]], Get, fun(X) -> - sag_verify(X, [?sysObjectID_instance, - ?sysDescr_instance, - ?sysUpTime_instance]), - PostVerify() + PostVerify(sag_verify(X, [?sysObjectID_instance, + ?sysDescr_instance, + ?sysUpTime_instance])) + end}, { 4, [?sysObjectID_instance, @@ -1687,10 +1692,9 @@ do_simple_async_sync_get2(MgrInfo, AgentInfo, Get, PostVerify) ?sysUpTime_instance], Get, fun(X) -> - sag_verify(X, [?sysObjectID_instance, - ?sysDescr_instance, - ?sysUpTime_instance]), - PostVerify() + PostVerify(sag_verify(X, [?sysObjectID_instance, + ?sysDescr_instance, + ?sysUpTime_instance])) end} ], @@ -1729,7 +1733,9 @@ simple_async_get3(Config) when is_list(Config) -> {extra, Extra} ], Get = fun(Oids) -> async_g_exec3(MgrNode, TargetName, Oids, SendOpts) end, - PostVerify = fun() -> receive Msg -> ok end end, + PostVerify = fun(ok) -> receive Msg -> ok end; + (Error) -> Error + end, do_simple_async_sync_get2(Config, MgrNode, AgentNode, Get, PostVerify). async_g_exec3(Node, TargetName, Oids, SendOpts) -> @@ -2136,11 +2142,14 @@ simple_async_get_next2(Config) when is_list(Config) -> Test2Mib = test2_mib(Config), ?line ok = mgr_user_load_mib(MgrNode, Test2Mib), ?line ok = agent_load_mib(AgentNode, Test2Mib), + GetNext = fun(Oids) -> + async_gn_exec2(MgrNode, TargetName, Oids) + end, + PostVerify = fun(Res) -> Res end, + do_simple_async_get_next2(MgrNode, AgentNode, GetNext, PostVerify). - Exec = fun(X) -> - async_gn_exec2(MgrNode, TargetName, X) - end, - +do_simple_async_get_next2(MgrNode, AgentNode, GetNext, PostVerify) + when is_function(GetNext, 1) andalso is_function(PostVerify, 1) -> ?line {ok, [TCnt2|_]} = mgr_user_name_to_oid(MgrNode, tCnt2), ?line {ok, [TGenErr1|_]} = mgr_user_name_to_oid(MgrNode, tGenErr1), ?line {ok, [TGenErr2|_]} = mgr_user_name_to_oid(MgrNode, tGenErr2), @@ -2151,51 +2160,60 @@ simple_async_get_next2(Config) when is_list(Config) -> [ {1, [[1,3,7,1]], - Exec, + GetNext, fun(X) -> - verify_ssgn_reply1(X, [{[1,3,7,1], endOfMibView}]) + PostVerify( + verify_ssgn_reply1(X, [{[1,3,7,1], endOfMibView}])) + end}, {2, [[sysDescr], [1,3,7,1]], - Exec, + GetNext, fun(X) -> - verify_ssgn_reply1(X, [?sysDescr_instance, endOfMibView]) + PostVerify( + verify_ssgn_reply1(X, [?sysDescr_instance, endOfMibView])) end}, {3, [[TCnt2, 1]], - Exec, + GetNext, fun(X) -> - verify_ssgn_reply1(X, [{fl([TCnt2,2]), 100}]) + PostVerify( + verify_ssgn_reply1(X, [{fl([TCnt2,2]), 100}])) end}, {4, [[TCnt2, 2]], - Exec, + GetNext, fun(X) -> - verify_ssgn_reply1(X, [{fl([TCnt2,2]), endOfMibView}]) + PostVerify( + verify_ssgn_reply1(X, [{fl([TCnt2,2]), endOfMibView}])) end}, {5, [TGenErr1], - Exec, + GetNext, fun(X) -> - verify_ssgn_reply2(X, {genErr, 1, [TGenErr1]}) + PostVerify( + verify_ssgn_reply2(X, {genErr, 1, [TGenErr1]})) end}, {6, [TGenErr2], - Exec, + GetNext, fun(X) -> - verify_ssgn_reply2(X, {genErr, 1, [TGenErr2]}) + PostVerify( + verify_ssgn_reply2(X, {genErr, 1, [TGenErr2]})) end}, {7, [[sysDescr], TGenErr3], - Exec, + GetNext, fun(X) -> - verify_ssgn_reply2(X, {genErr, 2, [TGenErr3]}) + PostVerify( + verify_ssgn_reply2(X, {genErr, 2, [TGenErr3]})) end}, {8, [TTooBig], - Exec, + GetNext, fun(X) -> - verify_ssgn_reply2(X, {tooBig, 0, []}) + PostVerify( + verify_ssgn_reply2(X, {tooBig, 0, []})) end} ], @@ -2214,6 +2232,48 @@ async_gn_exec2(Node, TargetName, Oids) -> mgr_user_async_get_next(Node, TargetName, Oids). +%%====================================================================== + +simple_async_get_next3(doc) -> + ["Simple (async) get_next-request - " + "Version 3 API (TargetName with send-opts)"]; +simple_async_get_next3(suite) -> []; +simple_async_get_next3(Config) when is_list(Config) -> + process_flag(trap_exit, true), + put(tname, ssgn2), + p("starting with Config: ~p~n", [Config]), + + MgrNode = ?config(manager_node, Config), + AgentNode = ?config(agent_node, Config), + TargetName = ?config(manager_agent_target_name, Config), + + ?line ok = mgr_user_load_mib(MgrNode, std_mib()), + Test2Mib = test2_mib(Config), + ?line ok = mgr_user_load_mib(MgrNode, Test2Mib), + ?line ok = agent_load_mib(AgentNode, Test2Mib), + + Self = self(), + Msg = simple_async_get_next3, + Fun = fun() -> Self ! Msg end, + Extra = {?SNMPM_EXTRA_INFO_TAG, Fun}, + SendOpts = + [ + {extra, Extra} + ], + + GetNext = fun(Oids) -> + async_gn_exec3(MgrNode, TargetName, Oids, SendOpts) + end, + PostVerify = fun(ok) -> receive Msg -> ok end; + (Error) -> Error + end, + + do_simple_async_get_next2(MgrNode, AgentNode, GetNext, PostVerify). + +async_gn_exec3(Node, TargetName, Oids, SendOpts) -> + mgr_user_async_get_next2(Node, TargetName, Oids, SendOpts). + + %%====================================================================== simple_sync_set1(doc) -> ["Simple (sync) set-request - " @@ -5214,6 +5274,9 @@ mgr_user_async_get_next(Node, Addr_or_TargetName, Oids) -> mgr_user_async_get_next(Node, Addr, Port, Oids) -> rcall(Node, snmp_manager_user, async_get_next, [Addr, Port, Oids]). +mgr_user_async_get_next2(Node, TargetName, Oids, SendOpts) -> + rcall(Node, snmp_manager_user, async_get_next2, [TargetName, Oids, SendOpts]). + %% mgr_user_sync_set(Node, VAV) -> %% mgr_user_sync_set(Node, ?LOCALHOST(), ?AGENT_PORT, VAV). mgr_user_sync_set(Node, Addr_or_TargetName, VAV) -> diff --git a/lib/snmp/test/snmp_manager_user.erl b/lib/snmp/test/snmp_manager_user.erl index 21543e4194..cb3f57ad1c 100644 --- a/lib/snmp/test/snmp_manager_user.erl +++ b/lib/snmp/test/snmp_manager_user.erl @@ -53,7 +53,7 @@ sync_get/1, sync_get/2, sync_get/3, sync_get2/3, async_get/1, async_get/2, async_get/3, async_get2/3, sync_get_next/1, sync_get_next/2, sync_get_next/3, sync_get_next2/3, - async_get_next/1, async_get_next/2, async_get_next/3, + async_get_next/1, async_get_next/2, async_get_next/3, async_get_next2/3, sync_set/1, sync_set/2, sync_set/3, async_set/1, async_set/2, async_set/3, sync_get_bulk/3, sync_get_bulk/4, sync_get_bulk/5, @@ -214,6 +214,9 @@ async_get_next(Addr_or_TargetName, Oids) -> async_get_next(Addr, Port, Oids) -> call({async_get_next, Addr, Port, Oids}). +async_get_next2(TargetName, Oids, SendOpts) -> + call({async_get_next2, TargetName, Oids, SendOpts}). + %% -- sync_set(VAV) -> @@ -545,6 +548,16 @@ loop(#state{parent = Parent, id = Id} = S) -> %% -- (async) get_next-request -- %% + {{async_get_next2, TargetName, Oids, SendOpts}, From, Ref} + when is_list(TargetName) -> + d("loop -> received async_get_next request with" + "~n TargetName: ~p" + "~n Oids: ~p" + "~n SendOpts: ~p", [TargetName, Oids, SendOpts]), + Res = snmpm:async_get_next2(Id, TargetName, Oids, SendOpts), + reply(From, Res, Ref), + loop(S); + %% No agent specified, so send it to all of them {{async_get_next, Oids}, From, Ref} -> d("loop -> received async_get_next request"), -- cgit v1.2.3 From fe2f0b21b8da7e7a83c74d5bb174d52bfcd380bd Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 14 Apr 2011 17:11:03 +0200 Subject: Sync set test case for version 2 request API. --- lib/snmp/test/snmp_manager_test.erl | 60 ++++++++++++++++++++++++++++++++----- lib/snmp/test/snmp_manager_user.erl | 21 ++++++++++--- 2 files changed, 69 insertions(+), 12 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index 986c324179..d638047701 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -80,6 +80,7 @@ simple_sync_set1/1, simple_sync_set2/1, + simple_sync_set3/1, simple_async_set1/1, simple_async_set2/1, @@ -243,7 +244,8 @@ init_per_testcase3(Case, Config) -> simple_sync_get3, simple_async_get3, simple_sync_get_next3, - simple_async_get_next3 + simple_async_get_next3, + simple_sync_set3 ], Cases = [ @@ -332,7 +334,8 @@ end_per_testcase2(Case, Config) -> simple_sync_get3, simple_async_get3, simple_sync_get_next3, - simple_async_get_next3 + simple_async_get_next3, + simple_sync_set3 ], Cases = [ @@ -441,6 +444,7 @@ groups() -> [ simple_sync_set1, simple_sync_set2, + simple_sync_set3, simple_async_set1, simple_async_set2 ] @@ -2353,7 +2357,17 @@ simple_sync_set2(Config) when is_list(Config) -> put(tname, sss2), p("starting with Config: ~p~n", [Config]), - Node = ?config(manager_node, Config), + Set = fun(Node, TargetName, VAVs) -> + mgr_user_sync_set(Node, TargetName, VAVs) + end, + PostVerify = fun() -> ok end, + + do_simple_sync_set2(Config, Set, PostVerify). + +do_simple_sync_set2(Config, Set, PostVerify) + when is_function(Set, 3) andalso is_function(PostVerify, 0) -> + + Node = ?config(manager_node, Config), TargetName = ?config(manager_agent_target_name, Config), p("issue set-request without loading the mib"), @@ -2363,7 +2377,7 @@ simple_sync_set2(Config) when is_list(Config) -> {?sysName_instance, s, Val11}, {?sysLocation_instance, s, Val12} ], - ?line ok = do_simple_set2(Node, TargetName, VAVs1), + ?line ok = do_simple_set2(Node, TargetName, VAVs1, Set, PostVerify), p("issue set-request after first loading the mibs"), ?line ok = mgr_user_load_mib(Node, std_mib()), @@ -2373,12 +2387,12 @@ simple_sync_set2(Config) when is_list(Config) -> {[sysName, 0], Val21}, {[sysLocation, 0], Val22} ], - ?line ok = do_simple_set2(Node, TargetName, VAVs2), + ?line ok = do_simple_set2(Node, TargetName, VAVs2, Set, PostVerify), ok. -do_simple_set2(Node, TargetName, VAVs) -> +do_simple_set2(Node, TargetName, VAVs, Set, PostVerify) -> [SysName, SysLoc] = value_of_vavs(VAVs), - ?line {ok, Reply, Rem} = mgr_user_sync_set(Node, TargetName, VAVs), + ?line {ok, Reply, Rem} = Set(Node, TargetName, VAVs), ?DBG("~n Reply: ~p" "~n Rem: ~w", [Reply, Rem]), @@ -2391,7 +2405,7 @@ do_simple_set2(Node, TargetName, VAVs) -> value = SysName}, #varbind{oid = ?sysLocation_instance, value = SysLoc}]} -> - ok; + PostVerify(); {noError, 0, Vbs} -> {error, {unexpected_vbs, Vbs}}; Else -> @@ -2401,6 +2415,33 @@ do_simple_set2(Node, TargetName, VAVs) -> ok. +%%====================================================================== + +simple_sync_set3(doc) -> + ["Simple (sync) set-request - Version 3 API (TargetName with send-opts)"]; +simple_sync_set3(suite) -> []; +simple_sync_set3(Config) when is_list(Config) -> + process_flag(trap_exit, true), + put(tname, sss3), + p("starting with Config: ~p~n", [Config]), + + Self = self(), + Msg = simple_sync_set3, + Fun = fun() -> Self ! Msg end, + Extra = {?SNMPM_EXTRA_INFO_TAG, Fun}, + SendOpts = + [ + {extra, Extra} + ], + + Set = fun(Node, TargetName, VAVs) -> + mgr_user_sync_set2(Node, TargetName, VAVs, SendOpts) + end, + PostVerify = fun() -> receive Msg -> ok end end, + + do_simple_sync_set2(Config, Set, PostVerify). + + %%====================================================================== simple_async_set1(doc) -> ["Simple (async) set-request - " @@ -5284,6 +5325,9 @@ mgr_user_sync_set(Node, Addr_or_TargetName, VAV) -> mgr_user_sync_set(Node, Addr, Port, VAV) -> rcall(Node, snmp_manager_user, sync_set, [Addr, Port, VAV]). +mgr_user_sync_set2(Node, TargetName, VAV, SendOpts) -> + rcall(Node, snmp_manager_user, sync_set2, [TargetName, VAV, SendOpts]). + %% mgr_user_async_set(Node, VAV) -> %% mgr_user_async_set(Node, ?LOCALHOST(), ?AGENT_PORT, VAV). mgr_user_async_set(Node, Addr_or_TargetName, VAV) -> diff --git a/lib/snmp/test/snmp_manager_user.erl b/lib/snmp/test/snmp_manager_user.erl index cb3f57ad1c..7c4bdbfb0a 100644 --- a/lib/snmp/test/snmp_manager_user.erl +++ b/lib/snmp/test/snmp_manager_user.erl @@ -54,7 +54,7 @@ async_get/1, async_get/2, async_get/3, async_get2/3, sync_get_next/1, sync_get_next/2, sync_get_next/3, sync_get_next2/3, async_get_next/1, async_get_next/2, async_get_next/3, async_get_next2/3, - sync_set/1, sync_set/2, sync_set/3, + sync_set/1, sync_set/2, sync_set/3, sync_set2/3, async_set/1, async_set/2, async_set/3, sync_get_bulk/3, sync_get_bulk/4, sync_get_bulk/5, async_get_bulk/3, async_get_bulk/4, async_get_bulk/5, @@ -228,6 +228,9 @@ sync_set(Addr_or_TargetName, VAV) -> sync_set(Addr, Port, VAV) -> call({sync_set, Addr, Port, VAV}). +sync_set2(TargetName, VAV, SendOpts) -> + call({sync_set2, TargetName, VAV, SendOpts}). + %% -- async_set(VAV) -> @@ -464,7 +467,7 @@ loop(#state{parent = Parent, id = Id} = S) -> {{async_get2, TargetName, Oids, SendOpts}, From, Ref} when is_list(TargetName) -> - d("loop -> received async_get request with" + d("loop -> received async_get2 request with" "~n TargetName: ~p" "~n Oids: ~p" "~n SendOpts: ~p", [TargetName, Oids, SendOpts]), @@ -507,7 +510,7 @@ loop(#state{parent = Parent, id = Id} = S) -> {{sync_get_next2, TargetName, Oids, SendOpts}, From, Ref} when is_list(TargetName) -> - d("loop -> received sync_get_next request with" + d("loop -> received sync_get_next2 request with" "~n TargetName: ~p" "~n Oids: ~p" "~n SendOpts: ~p", [TargetName, Oids, SendOpts]), @@ -550,7 +553,7 @@ loop(#state{parent = Parent, id = Id} = S) -> {{async_get_next2, TargetName, Oids, SendOpts}, From, Ref} when is_list(TargetName) -> - d("loop -> received async_get_next request with" + d("loop -> received async_get_next2 request with" "~n TargetName: ~p" "~n Oids: ~p" "~n SendOpts: ~p", [TargetName, Oids, SendOpts]), @@ -591,6 +594,16 @@ loop(#state{parent = Parent, id = Id} = S) -> %% -- (sync) set-request -- %% + {{sync_set2, TargetName, VAV, SendOpts}, From, Ref} + when is_list(TargetName) -> + d("loop -> received sync_set2 request with" + "~n TargetName: ~p" + "~n VAV: ~p" + "~n SendOpts: ~p", [TargetName, VAV, SendOpts]), + Res = snmpm:sync_set2(Id, TargetName, VAV, SendOpts), + reply(From, Res, Ref), + loop(S); + {{sync_set, VAV}, From, Ref} -> d("loop -> received sync_set request"), Res = [snmpm:sync_set(Id, TargetName, VAV) || -- cgit v1.2.3 From 625b265bfe3ba77f7554f8e7a7be29abff9eaaba Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 15 Apr 2011 10:37:44 +0200 Subject: Async set test case for version 3 request API. --- lib/snmp/test/snmp_manager_test.erl | 82 +++++++++++++++++++++++++++++++------ lib/snmp/test/snmp_manager_user.erl | 15 ++++++- 2 files changed, 84 insertions(+), 13 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index d638047701..808d10f116 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -83,6 +83,7 @@ simple_sync_set3/1, simple_async_set1/1, simple_async_set2/1, + simple_async_set3/1, simple_sync_get_bulk1/1, simple_sync_get_bulk2/1, @@ -245,7 +246,8 @@ init_per_testcase3(Case, Config) -> simple_async_get3, simple_sync_get_next3, simple_async_get_next3, - simple_sync_set3 + simple_sync_set3, + simple_async_set3 ], Cases = [ @@ -335,7 +337,8 @@ end_per_testcase2(Case, Config) -> simple_async_get3, simple_sync_get_next3, simple_async_get_next3, - simple_sync_set3 + simple_sync_set3, + simple_async_set3 ], Cases = [ @@ -446,7 +449,8 @@ groups() -> simple_sync_set2, simple_sync_set3, simple_async_set1, - simple_async_set2 + simple_async_set2, + simple_async_set3 ] }, {bulk_tests, [], @@ -2553,31 +2557,40 @@ simple_async_set2(Config) when is_list(Config) -> ?line ok = mgr_user_load_mib(MgrNode, Test2Mib), ?line ok = agent_load_mib(AgentNode, Test2Mib), - Exec = fun(X) -> - async_s_exec2(MgrNode, TargetName, X) - end, + Set = + fun(Oids) -> + async_s_exec2(MgrNode, TargetName, Oids) + end, + PostVerify = fun(Res) -> Res end, + + do_simple_async_set2(MgrNode, AgentNode, Set, PostVerify). +do_simple_async_set2(MgrNode, AgentNode, Set, PostVerify) -> Requests = [ {1, [{?sysName_instance, s, "Arne Anka"}], - Exec, + Set, fun(X) -> - sas_verify(X, [?sysName_instance]) + PostVerify(sas_verify(X, [?sysName_instance])) end}, {2, [{?sysLocation_instance, s, "Stockholm"}, {?sysName_instance, s, "Arne Anka"}], - Exec, + Set, fun(X) -> - sas_verify(X, [?sysLocation_instance, ?sysName_instance]) + PostVerify(sas_verify(X, + [?sysLocation_instance, + ?sysName_instance])) end}, {3, [{[sysName, 0], "Gothenburg"}, {[sysLocation, 0], "Sune Anka"}], - Exec, + Set, fun(X) -> - sas_verify(X, [?sysName_instance, ?sysLocation_instance]) + PostVerify(sas_verify(X, + [?sysName_instance, + ?sysLocation_instance])) end} ], @@ -2596,6 +2609,48 @@ async_s_exec2(Node, TargetName, VAVs) -> mgr_user_async_set(Node, TargetName, VAVs). +%%====================================================================== + +simple_async_set3(doc) -> + ["Simple (async) set-request - Version 3 API (TargetName with send-opts)"]; +simple_async_set3(suite) -> []; +simple_async_set3(Config) when is_list(Config) -> + process_flag(trap_exit, true), + put(tname, sas3), + p("starting with Config: ~p~n", [Config]), + + MgrNode = ?config(manager_node, Config), + AgentNode = ?config(agent_node, Config), + TargetName = ?config(manager_agent_target_name, Config), + + ?line ok = mgr_user_load_mib(MgrNode, std_mib()), + Test2Mib = test2_mib(Config), + ?line ok = mgr_user_load_mib(MgrNode, Test2Mib), + ?line ok = agent_load_mib(AgentNode, Test2Mib), + + Self = self(), + Msg = simple_async_set3, + Fun = fun() -> Self ! Msg end, + Extra = {?SNMPM_EXTRA_INFO_TAG, Fun}, + SendOpts = + [ + {extra, Extra} + ], + + Set = + fun(Oids) -> + async_s_exec3(MgrNode, TargetName, Oids, SendOpts) + end, + PostVerify = fun(ok) -> receive Msg -> ok end; + (Res) -> Res + end, + + do_simple_async_set2(MgrNode, AgentNode, Set, PostVerify). + +async_s_exec3(Node, TargetName, VAVs, SendOpts) -> + mgr_user_async_set2(Node, TargetName, VAVs, SendOpts). + + %%====================================================================== simple_sync_get_bulk1(doc) -> ["Simple (sync) get_bulk-request - " @@ -5335,6 +5390,9 @@ mgr_user_async_set(Node, Addr_or_TargetName, VAV) -> mgr_user_async_set(Node, Addr, Port, VAV) -> rcall(Node, snmp_manager_user, async_set, [Addr, Port, VAV]). +mgr_user_async_set2(Node, TargetName, VAV, SendOpts) -> + rcall(Node, snmp_manager_user, async_set2, [TargetName, VAV, SendOpts]). + %% mgr_user_sync_get_bulk(Node, NonRep, MaxRep, Oids) -> %% mgr_user_sync_get_bulk(Node, ?LOCALHOST(), ?AGENT_PORT, %% NonRep, MaxRep, Oids). diff --git a/lib/snmp/test/snmp_manager_user.erl b/lib/snmp/test/snmp_manager_user.erl index 7c4bdbfb0a..34f0779e9c 100644 --- a/lib/snmp/test/snmp_manager_user.erl +++ b/lib/snmp/test/snmp_manager_user.erl @@ -55,7 +55,7 @@ sync_get_next/1, sync_get_next/2, sync_get_next/3, sync_get_next2/3, async_get_next/1, async_get_next/2, async_get_next/3, async_get_next2/3, sync_set/1, sync_set/2, sync_set/3, sync_set2/3, - async_set/1, async_set/2, async_set/3, + async_set/1, async_set/2, async_set/3, async_set2/3, sync_get_bulk/3, sync_get_bulk/4, sync_get_bulk/5, async_get_bulk/3, async_get_bulk/4, async_get_bulk/5, name_to_oid/1, oid_to_name/1, @@ -242,6 +242,9 @@ async_set(Addr_or_TargetName, VAV) -> async_set(Addr, Port, VAV) -> call({async_set, Addr, Port, VAV}). +async_set2(TargetName, VAV, SendOpts) -> + call({async_set2, TargetName, VAV, SendOpts}). + %% -- sync_get_bulk(NonRep, MaxRep, Oids) -> @@ -634,6 +637,16 @@ loop(#state{parent = Parent, id = Id} = S) -> %% -- (async) set-request -- %% + {{async_set2, TargetName, VAV, SendOpts}, From, Ref} + when is_list(TargetName) -> + d("loop -> received async_set2 request with" + "~n TargetName: ~p" + "~n VAV: ~p" + "~n SendOpts: ~p", [TargetName, VAV, SendOpts]), + Res = snmpm:async_set2(Id, TargetName, VAV, SendOpts), + reply(From, Res, Ref), + loop(S); + {{async_set, VAV}, From, Ref} -> d("loop -> received async_set request"), Res = [snmpm:async_set(Id, TargetName, VAV) || -- cgit v1.2.3 From 4bdcd8b56cc6446012542db1df5fba893f0f38f0 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 15 Apr 2011 11:06:59 +0200 Subject: Sync get-bulk test case for version 3 of the request API. --- lib/snmp/test/snmp_manager_test.erl | 118 +++++++++++++++++++++++++++--------- lib/snmp/test/snmp_manager_user.erl | 19 +++++- 2 files changed, 108 insertions(+), 29 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index 808d10f116..3efb648c0b 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -87,6 +87,7 @@ simple_sync_get_bulk1/1, simple_sync_get_bulk2/1, + simple_sync_get_bulk3/1, simple_async_get_bulk1/1, simple_async_get_bulk2/1, @@ -247,7 +248,8 @@ init_per_testcase3(Case, Config) -> simple_sync_get_next3, simple_async_get_next3, simple_sync_set3, - simple_async_set3 + simple_async_set3, + simple_sync_get_bulk3 ], Cases = [ @@ -338,7 +340,8 @@ end_per_testcase2(Case, Config) -> simple_sync_get_next3, simple_async_get_next3, simple_sync_set3, - simple_async_set3 + simple_async_set3, + simple_sync_get_bulk3 ], Cases = [ @@ -457,6 +460,7 @@ groups() -> [ simple_sync_get_bulk1, simple_sync_get_bulk2, + simple_sync_get_bulk3, simple_async_get_bulk1, simple_async_get_bulk2 ] @@ -2836,20 +2840,33 @@ simple_sync_get_bulk2(Config) when is_list(Config) -> AgentNode = ?config(agent_node, Config), TargetName = ?config(manager_agent_target_name, Config), + GetBulk = + fun(NonRep, MaxRep, Oids) -> + mgr_user_sync_get_bulk(MgrNode, TargetName, + NonRep, MaxRep, Oids) + 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) -> %% -- 1 -- ?line ok = do_simple_get_bulk2(1, - MgrNode, TargetName, 1, 1, [], - fun verify_ssgb_reply1/1), + 1, 1, [], + fun verify_ssgb_reply1/1, + GetBulk, PostVerify), %% -- 2 -- ?line ok = do_simple_get_bulk2(2, - MgrNode, TargetName, -1, 1, [], - fun verify_ssgb_reply1/1), + -1, 1, [], + fun verify_ssgb_reply1/1, + GetBulk, PostVerify), %% -- 3 -- ?line ok = do_simple_get_bulk2(3, - MgrNode, TargetName, -1, -1, [], - fun verify_ssgb_reply1/1), + -1, -1, [], + fun verify_ssgb_reply1/1, + GetBulk, PostVerify), ?line ok = mgr_user_load_mib(MgrNode, std_mib()), %% -- 4 -- @@ -2857,13 +2874,13 @@ simple_sync_get_bulk2(Config) when is_list(Config) -> verify_ssgb_reply2(X, [?sysDescr_instance, endOfMibView]) end, ?line ok = do_simple_get_bulk2(4, - MgrNode, TargetName, - 2, 0, [[sysDescr],[1,3,7,1]], VF04), + 2, 0, [[sysDescr],[1,3,7,1]], VF04, + GetBulk, PostVerify), %% -- 5 -- ?line ok = do_simple_get_bulk2(5, - MgrNode, TargetName, - 1, 2, [[sysDescr],[1,3,7,1]], VF04), + 1, 2, [[sysDescr],[1,3,7,1]], VF04, + GetBulk, PostVerify), %% -- 6 -- VF06 = fun(X) -> @@ -2872,8 +2889,8 @@ simple_sync_get_bulk2(Config) when is_list(Config) -> ?sysObjectID_instance, endOfMibView]) end, ?line ok = do_simple_get_bulk2(6, - MgrNode, TargetName, - 0, 2, [[sysDescr],[1,3,7,1]], VF06), + 0, 2, [[sysDescr],[1,3,7,1]], VF06, + GetBulk, PostVerify), %% -- 7 -- VF07 = fun(X) -> @@ -2883,10 +2900,10 @@ simple_sync_get_bulk2(Config) when is_list(Config) -> ?sysObjectID_instance, endOfMibView]) end, ?line ok = do_simple_get_bulk2(7, - MgrNode, TargetName, 2, 2, [[sysDescr],[1,3,7,1],[sysDescr],[1,3,7,1]], - VF07), + VF07, + GetBulk, PostVerify), Test2Mib = test2_mib(Config), ?line ok = mgr_user_load_mib(MgrNode, Test2Mib), @@ -2899,17 +2916,17 @@ simple_sync_get_bulk2(Config) when is_list(Config) -> ?sysDescr_instance]) end, ?line ok = do_simple_get_bulk2(8, - MgrNode, TargetName, 1, 2, [[sysDescr],[sysDescr],[tTooBig]], - VF08), + VF08, + GetBulk, PostVerify), %% -- 9 -- ?line ok = do_simple_get_bulk2(9, - MgrNode, TargetName, 1, 12, [[tDescr2], [sysDescr]], - fun verify_ssgb_reply1/1), + fun verify_ssgb_reply1/1, + GetBulk, PostVerify), %% -- 10 -- VF10 = fun(X) -> @@ -2920,13 +2937,13 @@ simple_sync_get_bulk2(Config) when is_list(Config) -> {?sysDescr, 'NULL'}]) end, ?line ok = do_simple_get_bulk2(10, - MgrNode, TargetName, 2, 2, [[sysDescr], [sysObjectID], [tGenErr1], [sysDescr]], - VF10), + VF10, + GetBulk, PostVerify), %% -- 11 -- ?line {ok, [TCnt2|_]} = mgr_user_name_to_oid(MgrNode, tCnt2), @@ -2937,26 +2954,67 @@ simple_sync_get_bulk2(Config) when is_list(Config) -> {fl([TCnt2,2]), endOfMibView}]) end, ?line ok = do_simple_get_bulk2(11, - MgrNode, TargetName, 0, 2, - [[TCnt2, 1]], VF11), + [[TCnt2, 1]], VF11, + GetBulk, PostVerify), ok. -do_simple_get_bulk2(N, Node, TargetName, NonRep, MaxRep, Oids, Verify) -> +do_simple_get_bulk2(N, + NonRep, MaxRep, Oids, + Verify, GetBulk, PostVerify) + when is_function(Verify, 1) andalso + is_function(GetBulk, 3) andalso + is_function(PostVerify) -> p("issue get-bulk command ~w", [N]), - case mgr_user_sync_get_bulk(Node, TargetName, NonRep, MaxRep, Oids) of + case GetBulk(NonRep, MaxRep, Oids) of {ok, Reply, Rem} -> ?DBG("get-bulk ok:" "~n Reply: ~p" "~n Rem: ~w", [Reply, Rem]), - Verify(Reply); + PostVerify(Verify(Reply)); Error -> {error, {unexpected_reply, Error}} end. +%%====================================================================== + +simple_sync_get_bulk3(doc) -> + ["Simple (sync) get_bulk-request - " + "Version 3 API (TargetName with send-opts)"]; +simple_sync_get_bulk3(suite) -> []; +simple_sync_get_bulk3(Config) when is_list(Config) -> + process_flag(trap_exit, true), + put(tname, ssgb3), + p("starting with Config: ~p~n", [Config]), + + MgrNode = ?config(manager_node, Config), + AgentNode = ?config(agent_node, Config), + TargetName = ?config(manager_agent_target_name, Config), + + Self = self(), + Msg = simple_async_set3, + Fun = fun() -> Self ! Msg end, + Extra = {?SNMPM_EXTRA_INFO_TAG, Fun}, + SendOpts = + [ + {extra, Extra} + ], + + GetBulk = + fun(NonRep, MaxRep, Oids) -> + mgr_user_sync_get_bulk2(MgrNode, TargetName, + NonRep, MaxRep, Oids, SendOpts) + end, + PostVerify = fun(ok) -> receive Msg -> ok end; + (Res) -> Res + end, + + do_simple_sync_get_bulk2(Config, MgrNode, AgentNode, GetBulk, PostVerify). + + %%====================================================================== simple_async_get_bulk1(doc) -> ["Simple (async) get_bulk-request - " @@ -5398,11 +5456,15 @@ mgr_user_async_set2(Node, TargetName, VAV, SendOpts) -> %% NonRep, MaxRep, Oids). mgr_user_sync_get_bulk(Node, Addr_or_TargetName, NonRep, MaxRep, Oids) -> rcall(Node, snmp_manager_user, sync_get_bulk, - [Addr_or_TargetName, NonRep, MaxRep, Oids]). + [Addr_or_TargetName, NonRep, MaxRep, Oids]). mgr_user_sync_get_bulk(Node, Addr, Port, NonRep, MaxRep, Oids) -> rcall(Node, snmp_manager_user, sync_get_bulk, [Addr, Port, NonRep, MaxRep, Oids]). +mgr_user_sync_get_bulk2(Node, TargetName, NonRep, MaxRep, Oids, SendOpts) -> + rcall(Node, snmp_manager_user, sync_get_bulk2, + [TargetName, NonRep, MaxRep, Oids, SendOpts]). + %% mgr_user_async_get_bulk(Node, NonRep, MaxRep, Oids) -> %% mgr_user_async_get_bulk(Node, ?LOCALHOST(), ?AGENT_PORT, %% NonRep, MaxRep, Oids). diff --git a/lib/snmp/test/snmp_manager_user.erl b/lib/snmp/test/snmp_manager_user.erl index 34f0779e9c..c2b5886c4a 100644 --- a/lib/snmp/test/snmp_manager_user.erl +++ b/lib/snmp/test/snmp_manager_user.erl @@ -56,7 +56,7 @@ async_get_next/1, async_get_next/2, async_get_next/3, async_get_next2/3, sync_set/1, sync_set/2, sync_set/3, sync_set2/3, async_set/1, async_set/2, async_set/3, async_set2/3, - sync_get_bulk/3, sync_get_bulk/4, sync_get_bulk/5, + sync_get_bulk/3, sync_get_bulk/4, sync_get_bulk/5, sync_get_bulk2/5, async_get_bulk/3, async_get_bulk/4, async_get_bulk/5, name_to_oid/1, oid_to_name/1, purify_oid/1 @@ -256,6 +256,9 @@ sync_get_bulk(Addr_or_TargetName, NonRep, MaxRep, Oids) -> sync_get_bulk(Addr, Port, NonRep, MaxRep, Oids) -> call({sync_get_bulk, Addr, Port, NonRep, MaxRep, Oids}). +sync_get_bulk2(TargetName, NonRep, MaxRep, Oids, SendOpts) -> + call({sync_get_bulk2, TargetName, NonRep, MaxRep, Oids, SendOpts}). + %% -- async_get_bulk(NonRep, MaxRep, Oids) -> @@ -677,6 +680,20 @@ loop(#state{parent = Parent, id = Id} = S) -> %% -- (sync) get-bulk-request -- %% + {{sync_get_bulk2, TargetName, NonRep, MaxRep, Oids, SendOpts}, From, Ref} + when is_list(TargetName) -> + d("loop -> received sync_get_bulk request with" + "~n TargetName: ~p" + "~n NonRep: ~w" + "~n MaxRep: ~w" + "~n Oids: ~p" + "~n SendOpts: ~p", + [TargetName, NonRep, MaxRep, Oids, SendOpts]), + Res = snmpm:sync_get_bulk2(Id, TargetName, + NonRep, MaxRep, Oids, SendOpts), + reply(From, Res, Ref), + loop(S); + %% No agent specified, so send it to all of them {{sync_get_bulk, NonRep, MaxRep, Oids}, From, Ref} -> d("loop -> received sync_get_bulk request with" -- cgit v1.2.3 From f794bf0043b8955f74061b004dcb056ab0952815 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 15 Apr 2011 12:01:11 +0200 Subject: Async get-bulk test case for version 3 request API. --- lib/snmp/test/snmp_manager_test.erl | 158 +++++++++++++++++++++++++----------- lib/snmp/test/snmp_manager_user.erl | 19 ++++- 2 files changed, 128 insertions(+), 49 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index 3efb648c0b..6bd62df655 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -90,6 +90,7 @@ simple_sync_get_bulk3/1, simple_async_get_bulk1/1, simple_async_get_bulk2/1, + simple_async_get_bulk3/1, misc_async1/1, misc_async2/1, @@ -249,7 +250,8 @@ init_per_testcase3(Case, Config) -> simple_async_get_next3, simple_sync_set3, simple_async_set3, - simple_sync_get_bulk3 + simple_sync_get_bulk3, + simple_async_get_bulk3 ], Cases = [ @@ -341,7 +343,8 @@ end_per_testcase2(Case, Config) -> simple_async_get_next3, simple_sync_set3, simple_async_set3, - simple_sync_get_bulk3 + simple_sync_get_bulk3, + simple_async_get_bulk3 ], Cases = [ @@ -462,7 +465,8 @@ groups() -> simple_sync_get_bulk2, simple_sync_get_bulk3, simple_async_get_bulk1, - simple_async_get_bulk2 + simple_async_get_bulk2, + simple_async_get_bulk3 ] }, {misc_request_tests, [], @@ -3177,111 +3181,122 @@ simple_async_get_bulk2(Config) when is_list(Config) -> ?line ok = mgr_user_load_mib(MgrNode, Test2Mib), ?line ok = agent_load_mib(AgentNode, Test2Mib), - Exec = fun(Data) -> - async_gb_exec2(MgrNode, TargetName, Data) - end, + GetBulk = + fun(Data) -> + async_gb_exec2(MgrNode, TargetName, Data) + end, + PostVerify = fun(Res) -> Res end, + + do_simple_async_get_bulk2(MgrNode, AgentNode, GetBulk, PostVerify). +do_simple_async_get_bulk2(MgrNode, AgentNode, GetBulk, PostVerify) -> %% We re-use the verification functions from the ssgb test-case VF04 = fun(X) -> - verify_ssgb_reply2(X, [?sysDescr_instance, endOfMibView]) + PostVerify( + verify_ssgb_reply2(X, [?sysDescr_instance, endOfMibView])) end, VF06 = fun(X) -> - verify_ssgb_reply2(X, - [?sysDescr_instance, endOfMibView, - ?sysObjectID_instance, endOfMibView]) + PostVerify( + verify_ssgb_reply2(X, + [?sysDescr_instance, endOfMibView, + ?sysObjectID_instance, endOfMibView])) end, VF07 = fun(X) -> - verify_ssgb_reply2(X, - [?sysDescr_instance, endOfMibView, - ?sysDescr_instance, endOfMibView, - ?sysObjectID_instance, endOfMibView]) + PostVerify( + verify_ssgb_reply2(X, + [?sysDescr_instance, endOfMibView, + ?sysDescr_instance, endOfMibView, + ?sysObjectID_instance, endOfMibView])) end, VF08 = fun(X) -> - verify_ssgb_reply2(X, - [?sysDescr_instance, - ?sysDescr_instance]) + PostVerify( + verify_ssgb_reply2(X, + [?sysDescr_instance, + ?sysDescr_instance])) end, VF10 = fun(X) -> - verify_ssgb_reply3(X, - [{?sysDescr, 'NULL'}, - {?sysObjectID, 'NULL'}, - {?tGenErr1, 'NULL'}, - {?sysDescr, 'NULL'}]) + PostVerify( + verify_ssgb_reply3(X, + [{?sysDescr, 'NULL'}, + {?sysObjectID, 'NULL'}, + {?tGenErr1, 'NULL'}, + {?sysDescr, 'NULL'}])) end, ?line {ok, [TCnt2|_]} = mgr_user_name_to_oid(MgrNode, tCnt2), VF11 = fun(X) -> - verify_ssgb_reply2(X, - [{fl([TCnt2,2]), 100}, - {fl([TCnt2,2]), endOfMibView}]) + PostVerify( + verify_ssgb_reply2(X, + [{fl([TCnt2,2]), 100}, + {fl([TCnt2,2]), endOfMibView}])) end, Requests = [ { 1, {1, 1, []}, - Exec, - fun verify_ssgb_reply1/1}, + GetBulk, + fun(X) -> PostVerify(verify_ssgb_reply1(X)) end}, { 2, {-1, 1, []}, - Exec, - fun verify_ssgb_reply1/1}, + GetBulk, + fun(X) -> PostVerify(verify_ssgb_reply1(X)) end}, { 3, {-1, -1, []}, - Exec, - fun verify_ssgb_reply1/1}, + GetBulk, + fun(X) -> PostVerify(verify_ssgb_reply1(X)) end}, { 4, {2, 0, [[sysDescr],[1,3,7,1]]}, - Exec, + GetBulk, VF04}, { 5, {1, 2, [[sysDescr],[1,3,7,1]]}, - Exec, + GetBulk, VF04}, { 6, {0, 2, [[sysDescr],[1,3,7,1]]}, - Exec, + GetBulk, VF06}, { 7, {2, 2, [[sysDescr],[1,3,7,1],[sysDescr],[1,3,7,1]]}, - Exec, + GetBulk, VF07}, { 8, {1, 2, [[sysDescr],[sysDescr],[tTooBig]]}, - Exec, + GetBulk, VF08}, { 9, {1, 12, [[tDescr2], [sysDescr]]}, - Exec, - fun verify_ssgb_reply1/1}, + GetBulk, + fun(X) -> PostVerify(verify_ssgb_reply1(X)) end}, {10, {2, 2, [[sysDescr],[sysObjectID], [tGenErr1],[sysDescr]]}, - Exec, + GetBulk, VF10}, {11, {0, 2, [[TCnt2, 1]]}, - Exec, + GetBulk, VF11}, {12, {2, 0, [[sysDescr],[1,3,7,1]]}, - Exec, + GetBulk, VF04}, {13, {1, 12, [[tDescr2], [sysDescr]]}, - Exec, - fun verify_ssgb_reply1/1}, + GetBulk, + fun(X) -> PostVerify(verify_ssgb_reply1(X)) end}, {14, {2, 2, [[sysDescr],[sysObjectID],[tGenErr1],[sysDescr]]}, - Exec, + GetBulk, VF10}, {15, {0, 2, [[TCnt2, 1]]}, - Exec, + GetBulk, VF11}, {16, {2, 2, [[sysDescr],[1,3,7,1],[sysDescr],[1,3,7,1]]}, - Exec, + GetBulk, VF07}, {17, {2, 2, [[sysDescr],[sysObjectID], [tGenErr1],[sysDescr]]}, - Exec, + GetBulk, VF10} ], @@ -3300,6 +3315,49 @@ async_gb_exec2(Node, TargetName, {NR, MR, Oids}) -> mgr_user_async_get_bulk(Node, TargetName, NR, MR, Oids). +%%====================================================================== + +simple_async_get_bulk3(doc) -> + ["Simple (async) get_bulk-request - " + "Version 3 API (TargetName with send-opts)"]; +simple_async_get_bulk3(suite) -> []; +simple_async_get_bulk3(Config) when is_list(Config) -> + process_flag(trap_exit, true), + put(tname, sagb3), + p("starting with Config: ~p~n", [Config]), + + MgrNode = ?config(manager_node, Config), + AgentNode = ?config(agent_node, Config), + TargetName = ?config(manager_agent_target_name, Config), + + ?line ok = mgr_user_load_mib(MgrNode, std_mib()), + Test2Mib = test2_mib(Config), + ?line ok = mgr_user_load_mib(MgrNode, Test2Mib), + ?line ok = agent_load_mib(AgentNode, Test2Mib), + + Self = self(), + Msg = simple_async_get_bulk3, + Fun = fun() -> Self ! Msg end, + Extra = {?SNMPM_EXTRA_INFO_TAG, Fun}, + SendOpts = + [ + {extra, Extra} + ], + + GetBulk = + fun(Data) -> + async_gb_exec3(MgrNode, TargetName, Data, SendOpts) + end, + PostVerify = fun(ok) -> receive Msg -> ok end; + (Res) -> Res + end, + + do_simple_async_get_bulk2(MgrNode, AgentNode, GetBulk, PostVerify). + +async_gb_exec3(Node, TargetName, {NR, MR, Oids}, SendOpts) -> + mgr_user_async_get_bulk2(Node, TargetName, NR, MR, Oids, SendOpts). + + %%====================================================================== misc_async1(doc) -> ["Misc (async) request(s) - " @@ -5470,11 +5528,15 @@ mgr_user_sync_get_bulk2(Node, TargetName, NonRep, MaxRep, Oids, SendOpts) -> %% NonRep, MaxRep, Oids). mgr_user_async_get_bulk(Node, Addr_or_TargetName, NonRep, MaxRep, Oids) -> rcall(Node, snmp_manager_user, async_get_bulk, - [Addr_or_TargetName, NonRep, MaxRep, Oids]). + [Addr_or_TargetName, NonRep, MaxRep, Oids]). mgr_user_async_get_bulk(Node, Addr, Port, NonRep, MaxRep, Oids) -> rcall(Node, snmp_manager_user, async_get_bulk, [Addr, Port, NonRep, MaxRep, Oids]). +mgr_user_async_get_bulk2(Node, TargetName, NonRep, MaxRep, Oids, SendOpts) -> + rcall(Node, snmp_manager_user, async_get_bulk2, + [TargetName, NonRep, MaxRep, Oids, SendOpts]). + mgr_user_purify_oid(Node, Oid) -> rcall(Node, snmp_manager_user, purify_oid, [Oid]). diff --git a/lib/snmp/test/snmp_manager_user.erl b/lib/snmp/test/snmp_manager_user.erl index c2b5886c4a..30b5dd1fc7 100644 --- a/lib/snmp/test/snmp_manager_user.erl +++ b/lib/snmp/test/snmp_manager_user.erl @@ -57,7 +57,7 @@ sync_set/1, sync_set/2, sync_set/3, sync_set2/3, async_set/1, async_set/2, async_set/3, async_set2/3, sync_get_bulk/3, sync_get_bulk/4, sync_get_bulk/5, sync_get_bulk2/5, - async_get_bulk/3, async_get_bulk/4, async_get_bulk/5, + async_get_bulk/3, async_get_bulk/4, async_get_bulk/5, async_get_bulk2/5, name_to_oid/1, oid_to_name/1, purify_oid/1 ]). @@ -270,6 +270,9 @@ async_get_bulk(Addr_or_TargetName, NonRep, MaxRep, Oids) -> async_get_bulk(Addr, Port, NonRep, MaxRep, Oids) -> call({async_get_bulk, Addr, Port, NonRep, MaxRep, Oids}). +async_get_bulk2(TargetName, NonRep, MaxRep, Oids, SendOpts) -> + call({async_get_bulk2, TargetName, NonRep, MaxRep, Oids, SendOpts}). + %% -- name_to_oid(Name) -> @@ -741,6 +744,20 @@ loop(#state{parent = Parent, id = Id} = S) -> %% -- (async) get-bulk-request -- %% + {{async_get_bulk2, TargetName, NonRep, MaxRep, Oids, SendOpts}, + From, Ref} when is_list(TargetName) -> + d("loop -> received async_get_bulk2 request with" + "~n TargetName: ~p" + "~n NonRep: ~w" + "~n MaxRep: ~w" + "~n Oids: ~p" + "~n SendOpts: ~p", + [TargetName, NonRep, MaxRep, Oids, SendOpts]), + Res = snmpm:async_get_bulk2(Id, TargetName, + NonRep, MaxRep, Oids, SendOpts), + reply(From, Res, Ref), + loop(S); + %% No agent specified, so send it to all of them {{async_get_bulk, NonRep, MaxRep, Oids}, From, Ref} -> d("loop -> received async_get_bulk request with" -- cgit v1.2.3 From 8bf62843795deb64ccc0abcb11c35adc32b4a6a6 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 15 Apr 2011 13:35:57 +0200 Subject: Fixed appup. --- lib/snmp/src/app/snmp.appup.src | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index fd9f40caa0..1efb888730 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -24,7 +24,7 @@ [ {"4.19", [ - {load_module, snmpm, soft_purge, soft_purge, []}, + {load_module, snmpm, soft_purge, soft_purge, [snmpm_server]}, {load_module, snmp_conf, soft_purge, soft_purge, []}, {load_module, snmpa_conf, soft_purge, soft_purge, [snmp_conf]}, {load_module, snmp_misc, soft_purge, soft_purge, []}, @@ -40,6 +40,8 @@ [snmp_conf, snmp_target_mib]}, {load_module, snmp_target_mib, soft_purge, soft_purge, [snmp_conf]}, + {update, snmpm_net_if, soft, soft_purge, soft_purge, []}, + {update, snmpm_server, soft, soft_purge, soft_purge, [snmpm_net_if]}, {update, snmpa_net_if, soft, soft_purge, soft_purge, [snmp_conf, snmpa_mpd]}, {update, snmpa_agent, soft, soft_purge, soft_purge, @@ -48,7 +50,7 @@ }, {"4.18", [ - {load_module, snmpm, soft_purge, soft_purge, []}, + {load_module, snmpm, soft_purge, soft_purge, [snmpm_server]}, {load_module, snmp_misc, soft_purge, soft_purge, []}, {load_module, snmp_conf, soft_purge, soft_purge, []}, {load_module, snmp_config, soft_purge, soft_purge, [snmp_conf]}, @@ -82,6 +84,9 @@ [snmpa_mib_lib, snmpa_vacm]}, {load_module, snmpa_mib_lib, soft_purge, soft_purge, []}, + {update, snmpm_net_if, soft, soft_purge, soft_purge, []}, + {update, snmpm_server, soft, soft_purge, soft_purge, [snmpm_net_if]}, + {update, snmpa_net_if, soft, soft_purge, soft_purge, [snmp_conf, snmpa_mpd]}, {update, snmpa_agent, soft, soft_purge, soft_purge, @@ -95,7 +100,7 @@ [ {"4.19", [ - {load_module, snmpm, soft_purge, soft_purge, []}, + {load_module, snmpm, soft_purge, soft_purge, [snmpm_server]}, {load_module, snmp_conf, soft_purge, soft_purge, []}, {load_module, snmpa_conf, soft_purge, soft_purge, [snmp_conf]}, {load_module, snmp_misc, soft_purge, soft_purge, []}, @@ -111,6 +116,10 @@ [snmp_conf, snmp_target_mib]}, {load_module, snmp_target_mib, soft_purge, soft_purge, [snmp_conf]}, + + {update, snmpm_net_if, soft, soft_purge, soft_purge, []}, + {update, snmpm_server, soft, soft_purge, soft_purge, [snmpm_net_if]}, + {update, snmpa_net_if, soft, soft_purge, soft_purge, [snmp_conf, snmpa_mpd]}, {update, snmpa_agent, soft, soft_purge, soft_purge, @@ -119,7 +128,7 @@ }, {"4.18", [ - {load_module, snmpm, soft_purge, soft_purge, []}, + {load_module, snmpm, soft_purge, soft_purge, [snmpm_server]}, {load_module, snmp_misc, soft_purge, soft_purge, []}, {load_module, snmp_conf, soft_purge, soft_purge, []}, {load_module, snmpa_conf, soft_purge, soft_purge, [snmp_conf]}, @@ -153,6 +162,9 @@ [snmpa_mib_lib, snmpa_vacm]}, {load_module, snmpa_mib_lib, soft_purge, soft_purge, []}, + {update, snmpm_net_if, soft, soft_purge, soft_purge, []}, + {update, snmpm_server, soft, soft_purge, soft_purge, [snmpm_net_if]}, + {update, snmpa_net_if, soft, soft_purge, soft_purge, [snmp_conf, snmpa_mpd]}, {update, snmpa_agent, soft, soft_purge, soft_purge, -- cgit v1.2.3 From 30a9f962d349f322f389ebc056e972f871e689a8 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 18 Apr 2011 15:09:39 +0200 Subject: Patch received from Attila Rajmund Nohl. --- lib/snmp/src/agent/snmpa.erl | 2 +- lib/snmp/src/agent/snmpa_agent.erl | 9 +++++--- lib/snmp/src/agent/snmpa_net_if.erl | 13 ++++++++++++ lib/snmp/src/agent/snmpa_trap.erl | 41 +++++++++++++++++++++++++++++-------- lib/snmp/src/app/snmp.appup.src | 12 +++++++---- 5 files changed, 60 insertions(+), 17 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa.erl b/lib/snmp/src/agent/snmpa.erl index 630a14907d..e9023693d3 100644 --- a/lib/snmp/src/agent/snmpa.erl +++ b/lib/snmp/src/agent/snmpa.erl @@ -673,7 +673,7 @@ send_notification(Agent, Notification, Recv, {name, NotifyName}, {context, ContextName}, {extra, ?DEFAULT_NOTIF_EXTRA_INFO}, - {local_enging_id, LocalEngineID} + {local_engine_id, LocalEngineID} ], send_notification2(Agent, Notification, SendOpts). diff --git a/lib/snmp/src/agent/snmpa_agent.erl b/lib/snmp/src/agent/snmpa_agent.erl index 0a28e753ce..e4cfeddb6a 100644 --- a/lib/snmp/src/agent/snmpa_agent.erl +++ b/lib/snmp/src/agent/snmpa_agent.erl @@ -2126,7 +2126,7 @@ send_discovery(S, From, TargetName, Record, ContextName, InitVars, DiscoHandler, ExtraInfo) -> case snmpa_trap:send_discovery(TargetName, Record, ContextName, - InitVars, get(net_if)) of + InitVars, get(net_if), ExtraInfo) of {ok, Sender, SecLevel} -> Disco = #disco{from = From, rec = Record, @@ -2203,9 +2203,12 @@ handle_discovery_response(#state{disco = #disco{target = TargetName, #disco{rec = Record, ctx = ContextName, ivbs = InitVars} = Disco, - case snmpa_trap:send_discovery(TargetName, Record, + case snmpa_trap:send_discovery(TargetName, + Record, ContextName, - InitVars, get(net_if)) of + InitVars, + get(net_if), + ExtraInfo) of {ok, Sender, _SecLevel} -> ?vdebug("handle_discovery_response(1) -> " "stage 2 trap sent", []), diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index bbc43c3da7..bbc5568cde 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -343,6 +343,7 @@ loop(S) -> loop(NewS); %% Discovery Inform + %% {send_discovery, Pdu, MsgData, To, From} -> ?vdebug("received send discovery request: " "~n Pdu: ~p" @@ -351,6 +352,18 @@ loop(S) -> [Pdu, To, toname(From)]), NewS = handle_send_discovery(S, Pdu, MsgData, To, From), loop(NewS); + %% + + %% Discovery Inform + {send_discovery, Pdu, MsgData, To, From, ExtraInfo} -> + ?vdebug("received send discovery request: " + "~n Pdu: ~p" + "~n To: ~p" + "~n From: ~p" + "~n ExtraInfo: ~p", + [Pdu, To, toname(From), ExtraInfo]), + NewS = handle_send_discovery(S, Pdu, MsgData, To, From), + loop(NewS); {discarded_pdu, _Vsn, ReqId, _ACMData, Variable, _Extra} -> ?vdebug("discard PDU: ~p", [Variable]), diff --git a/lib/snmp/src/agent/snmpa_trap.erl b/lib/snmp/src/agent/snmpa_trap.erl index 2a233fd38e..04b78a3847 100644 --- a/lib/snmp/src/agent/snmpa_trap.erl +++ b/lib/snmp/src/agent/snmpa_trap.erl @@ -25,13 +25,18 @@ -export([construct_trap/2, try_initialise_vars/2, send_trap/6, send_trap/7, send_trap/8]). --export([send_discovery/5]). +-export([send_discovery/6]). %% Internal exports -export([init_v2_inform/9, init_v2_inform/10, init_v3_inform/9, init_v3_inform/10, init_v3_inform/11, send_inform/6]). --export([init_discovery_inform/12, send_discovery_inform/5]). +-export([init_discovery_inform/13, send_discovery_inform/5]). + +%% +-export([send_discovery/5, + init_discovery_inform/12]). +%% -include_lib("snmp/include/snmp_types.hrl"). -include_lib("snmp/src/agent/snmpa_internal.hrl"). @@ -360,9 +365,13 @@ do_send_trap(TrapRec, NotifyName, ContextName, Recv, Vbs, Recv, LocalEngineID, ExtraInfo, NetIf). send_discovery(TargetName, Record, ContextName, Vbs, NetIf) -> + ExtraInfo = ?DEFAULT_NOTIF_EXTRA_INFO, + send_discovery(TargetName, Record, ContextName, Vbs, NetIf, ExtraInfo). +send_discovery(TargetName, Record, ContextName, Vbs, NetIf, ExtraInfo) -> case find_dest(TargetName) of {ok, Dest} -> - send_discovery_pdu(Dest, Record, ContextName, Vbs, NetIf); + send_discovery_pdu(Dest, Record, ContextName, Vbs, NetIf, + ExtraInfo); Error -> Error end. @@ -540,7 +549,8 @@ find_dest(TargetName) -> send_discovery_pdu({Dest, TargetName, {SecModel, SecName, SecLevel}, Timeout, Retry}, - Record, ContextName, Vbs, NetIf) -> + Record, ContextName, Vbs, NetIf, + ExtraInfo) -> ?vdebug("send_discovery_pdu -> entry with " "~n Destination address: ~p" "~n Target name: ~p" @@ -550,9 +560,10 @@ send_discovery_pdu({Dest, TargetName, {SecModel, SecName, SecLevel}, "~n Timeout: ~p" "~n Retry: ~p" "~n Record: ~p" - "~n ContextName: ~p", + "~n ContextName: ~p" + "~n ExtraInfo: ~p", [Dest, TargetName, SecModel, SecName, SecLevel, - Timeout, Retry, Record, ContextName]), + Timeout, Retry, Record, ContextName, ExtraInfo]), case get_mib_view(SecModel, SecName, SecLevel, ContextName) of {ok, MibView} -> case check_all_varbinds(Record, Vbs, MibView) of @@ -562,7 +573,7 @@ send_discovery_pdu({Dest, TargetName, {SecModel, SecName, SecLevel}, SecModel, SecName, SecLevel, TargetName, ContextName, Timeout, Retry, - SysUpTime, NetIf); + SysUpTime, NetIf, ExtraInfo); false -> {error, {mibview_validation_failed, Vbs, MibView}} end; @@ -572,7 +583,7 @@ send_discovery_pdu({Dest, TargetName, {SecModel, SecName, SecLevel}, send_discovery_pdu(Record, Dest, Vbs, SecModel, SecName, SecLevel, TargetName, - ContextName, Timeout, Retry, SysUpTime, NetIf) -> + ContextName, Timeout, Retry, SysUpTime, NetIf, ExtraInfo) -> {_Oid, IVbs} = mk_v2_trap(Record, Vbs, SysUpTime), % v2 refers to SMIv2; Sender = proc_lib:spawn_link(?MODULE, init_discovery_inform, [self(), @@ -581,6 +592,7 @@ send_discovery_pdu(Record, Dest, Vbs, ContextName, Timeout, Retry, IVbs, NetIf, + ExtraInfo, get(verbosity)]), {ok, Sender, SecLevel}. @@ -588,6 +600,17 @@ init_discovery_inform(Parent, Dest, SecModel, SecName, SecLevel, TargetName, ContextName, Timeout, Retry, Vbs, NetIf, Verbosity) -> + ExtraInfo = ?DEFAULT_NOTIF_EXTRA_INFO, + init_discovery_inform(Parent, + Dest, + SecModel, SecName, SecLevel, TargetName, + ContextName, Timeout, Retry, Vbs, NetIf, + Verbosity, ExtraInfo). +init_discovery_inform(Parent, + Dest, + SecModel, SecName, SecLevel, TargetName, + ContextName, Timeout, Retry, Vbs, NetIf, + Verbosity, ExtraInfo) -> put(verbosity, Verbosity), put(sname, madis), Pdu = make_discovery_pdu(Vbs), @@ -595,7 +618,7 @@ init_discovery_inform(Parent, SecLevelFlag = mk_flag(SecLevel), SecData = {SecModel, SecName, SecLevelFlag, TargetName}, MsgData = {SecData, ContextEngineId, ContextName}, - Msg = {send_discovery, Pdu, MsgData, Dest, self()}, + Msg = {send_discovery, Pdu, MsgData, Dest, self(), ExtraInfo}, ?MODULE:send_discovery_inform(Parent, Timeout*10, Retry, Msg, NetIf). %% note_timeout(Timeout, Retry) diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index fd9f40caa0..46b2efffca 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -25,13 +25,14 @@ {"4.19", [ {load_module, snmpm, soft_purge, soft_purge, []}, + {load_module, snmpa, soft_purge, soft_purge, []}, {load_module, snmp_conf, soft_purge, soft_purge, []}, {load_module, snmpa_conf, soft_purge, soft_purge, [snmp_conf]}, {load_module, snmp_misc, soft_purge, soft_purge, []}, {load_module, snmp_config, soft_purge, soft_purge, []}, {load_module, snmpa_mpd, soft_purge, soft_purge, [snmp_conf]}, {load_module, snmpa_trap, soft_purge, soft_purge, - [snmpa_mpd, snmp_notification_mib, snmp_target_mib]}, + [snmpa_mpd, snmp_notification_mib, snmp_target_mib, snmpa_net_if]}, {load_module, snmpa_acm, soft_purge, soft_purge, [snmp_conf, snmpa_mpd, snmp_target_mib]}, {load_module, snmpa_conf, soft_purge, soft_purge, @@ -49,6 +50,7 @@ {"4.18", [ {load_module, snmpm, soft_purge, soft_purge, []}, + {load_module, snmpa, soft_purge, soft_purge, []}, {load_module, snmp_misc, soft_purge, soft_purge, []}, {load_module, snmp_conf, soft_purge, soft_purge, []}, {load_module, snmp_config, soft_purge, soft_purge, [snmp_conf]}, @@ -56,7 +58,7 @@ {load_module, snmpa_mpd, soft_purge, soft_purge, [snmp_conf]}, {load_module, snmpa_vacm, soft_purge, soft_purge, []}, {load_module, snmpa_trap, soft_purge, soft_purge, - [snmpa_mpd, snmp_notification_mib, snmp_target_mib]}, + [snmpa_mpd, snmp_notification_mib, snmp_target_mib, snmpa_net_if]}, {load_module, snmpa_acm, soft_purge, soft_purge, [snmp_conf, snmpa_mpd, snmp_target_mib]}, {load_module, snmpa, soft_purge, soft_purge, @@ -96,13 +98,14 @@ {"4.19", [ {load_module, snmpm, soft_purge, soft_purge, []}, + {load_module, snmpa, soft_purge, soft_purge, []}, {load_module, snmp_conf, soft_purge, soft_purge, []}, {load_module, snmpa_conf, soft_purge, soft_purge, [snmp_conf]}, {load_module, snmp_misc, soft_purge, soft_purge, []}, {load_module, snmp_config, soft_purge, soft_purge, []}, {load_module, snmpa_mpd, soft_purge, soft_purge, [snmp_conf]}, {load_module, snmpa_trap, soft_purge, soft_purge, - [snmpa_mpd, snmp_notification_mib, snmp_target_mib]}, + [snmpa_mpd, snmp_notification_mib, snmp_target_mib, snmpa_net_if]}, {load_module, snmpa_acm, soft_purge, soft_purge, [snmp_conf, snmpa_mpd, snmp_target_mib]}, {load_module, snmpa_conf, soft_purge, soft_purge, @@ -120,6 +123,7 @@ {"4.18", [ {load_module, snmpm, soft_purge, soft_purge, []}, + {load_module, snmpa, soft_purge, soft_purge, []}, {load_module, snmp_misc, soft_purge, soft_purge, []}, {load_module, snmp_conf, soft_purge, soft_purge, []}, {load_module, snmpa_conf, soft_purge, soft_purge, [snmp_conf]}, @@ -127,7 +131,7 @@ {load_module, snmpa_mpd, soft_purge, soft_purge, [snmp_conf]}, {load_module, snmpa_vacm, soft_purge, soft_purge, []}, {load_module, snmpa_trap, soft_purge, soft_purge, - [snmpa_mpd, snmp_notification_mib, snmp_target_mib]}, + [snmpa_mpd, snmp_notification_mib, snmp_target_mib, snmpa_net_if]}, {load_module, snmpa_acm, soft_purge, soft_purge, [snmp_conf, snmpa_mpd, snmp_target_mib]}, {load_module, snmpa, soft_purge, soft_purge, -- cgit v1.2.3 From 9022ef27b8628ca680654d542b4d520426480c2d Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 18 Apr 2011 15:57:01 +0200 Subject: Fixed appup. --- lib/snmp/src/app/snmp.appup.src | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/snmp') diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index 07e696ce88..998b52f3df 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -24,6 +24,7 @@ [ {"4.19", [ + {load_module, snmp_community_mib, soft_purge, soft_purge, []} ] }, {"4.18", @@ -59,6 +60,7 @@ [ {"4.19", [ + {load_module, snmp_community_mib, soft_purge, soft_purge, []} ] }, {"4.18", -- cgit v1.2.3 From 3e372b28827c3b5bc683ac08002af9cb8da5c692 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 18 Apr 2011 16:48:34 +0200 Subject: Also updated the dokumentation for the added function. --- lib/snmp/doc/src/notes.xml | 4 ++-- lib/snmp/doc/src/snmp_community_mib.xml | 26 +++++++++++++++++++------- 2 files changed, 21 insertions(+), 9 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index b7e50c47e4..a098c909d4 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -46,8 +46,8 @@

[agent] To be able to handle multiple engine-id(s) when sending trap(s), the function - add_community/6 - has been added.

+ + add_community/6 has been added.

Own Id: OTP-9119 Aux Id: Seq 11792

diff --git a/lib/snmp/doc/src/snmp_community_mib.xml b/lib/snmp/doc/src/snmp_community_mib.xml index 7c7386af19..5e7bca3e27 100644 --- a/lib/snmp/doc/src/snmp_community_mib.xml +++ b/lib/snmp/doc/src/snmp_community_mib.xml @@ -1,10 +1,10 @@ - +
- 19992009 + 19992011 Ericsson AB. All Rights Reserved. @@ -35,11 +35,13 @@ Instrumentation Functions for SNMP-COMMUNITY-MIB

The module snmp_community_mib implements the instrumentation - functions for the - SNMP-COMMUNITY-MIB, and functions for configuring the database. -

+ functions for the SNMP-COMMUNITY-MIB, and functions for configuring the + database.

The configuration files are described in the SNMP User's Manual.

+ +
+ configure(ConfDir) -> void() @@ -68,8 +70,11 @@

The configuration file read is: community.conf.

+ +
+ reconfigure(ConfDir) -> void() Configure the SNMP-COMMUNITY-MIB @@ -96,28 +101,35 @@ where the configuration files are found.

The configuration file read is: community.conf.

+
+ add_community(Idx, CommName, SecName, CtxName, TransportTag) -> Ret + add_community(Idx, CommName, SecName, EngineId, CtxName, TransportTag) -> Ret Added one community Idx = string() CommName = string() SecName = string() + EngineId = string() CtxName = string() TransportTag = string() Ret = {ok, Key} | {error, Reason} Key = term() - Reason = term() + Reason = term()

Adds a community to the agent config. - Equivalent to one line in the community.conf file.

+ Equivalent to one line in the community.conf file.

+

With the EngineId argument it is possible to + override the configured engine-id (SNMP-FRAMEWORK-MIB).

+ delete_community(Key) -> Ret Delete one community -- cgit v1.2.3 From 178cec8c7290e82db5d7d80a9d74ab0cb3f85bed Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 18 Apr 2011 17:00:05 +0200 Subject: Removed unused function. --- lib/snmp/src/agent/snmpa.erl | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa.erl b/lib/snmp/src/agent/snmpa.erl index e9023693d3..b2e4f253ab 100644 --- a/lib/snmp/src/agent/snmpa.erl +++ b/lib/snmp/src/agent/snmpa.erl @@ -601,17 +601,6 @@ set_request_limit(Agent, NewLimit) -> send_notification2(Agent, Notification, SendOpts) -> snmpa_agent:send_notification(Agent, Notification, SendOpts). -send_notification(Agent, Notification) -> - SendOpts = - [ - {receiver, no_receiver}, - {varbinds, []}, - {name, ""}, - {context, ""}, - {extra, ?DEFAULT_NOTIF_EXTRA_INFO} - ], - send_notification2(Agent, Notification, SendOpts). - send_notification(Agent, Notification, Recv) -> SendOpts = [ -- cgit v1.2.3 From 5b15b32e2d1aec2716c58879f0ada02557c757f5 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 20 Apr 2011 10:44:46 +0200 Subject: Just a save commit (I need to work on another branch...) --- lib/snmp/src/misc/snmp_pdus.erl | 50 +++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 9 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/misc/snmp_pdus.erl b/lib/snmp/src/misc/snmp_pdus.erl index dc8900c8cd..9c273bc0e0 100644 --- a/lib/snmp/src/misc/snmp_pdus.erl +++ b/lib/snmp/src/misc/snmp_pdus.erl @@ -268,25 +268,42 @@ dec_value([4 | Bytes]) -> dec_value([64 | Bytes]) -> {Value, Rest} = dec_oct_str_notag(Bytes), {{'IpAddress', Value}, Rest}; +%% dec_value([65 | Bytes]) -> +%% {Value, Rest} = dec_integer_notag(Bytes), +%% if +%% (Value >= 0) andalso (Value =< 4294967295) -> +%% {{'Counter32', Value}, Rest}; +%% true -> +%% exit({error, {bad_counter32, Value}}) +%% end; dec_value([65 | Bytes]) -> + %% Counter32 is an unsigned 32 but is actually encoded as + %% a signed integer 32 (INTEGER). {Value, Rest} = dec_integer_notag(Bytes), - if Value >= 0, Value =< 4294967295 -> - {{'Counter32', Value}, Rest}; - true -> - exit({error, {bad_counter32, Value}}) - end; + Value2 = + if + (Value >= 0) andalso (Value =< 16#ffffffff) -> + %% We accept value above 16#7fffffff + Value; + (Value < 0) -> + 16#ffffffff + Value + 1; + true -> + exit({error, {bad_counter32, Value}}) end, + {{'Counter64', Value2}, Rest}; dec_value([66 | Bytes]) -> {Value, Rest} = dec_integer_notag(Bytes), - if Value >= 0, Value =< 4294967295 -> + if + (Value >= 0) andalso (Value =< 4294967295) -> {{'Unsigned32', Value}, Rest}; - true -> + true -> exit({error, {bad_unsigned32, Value}}) end; dec_value([67 | Bytes]) -> {Value, Rest} = dec_integer_notag(Bytes), - if Value >= 0, Value =< 4294967295 -> + if + (Value >= 0) andalso (Value =< 4294967295) -> {{'TimeTicks', Value}, Rest}; - true -> + true -> exit({error, {bad_timeticks, Value}}) end; dec_value([68 | Bytes]) -> @@ -642,6 +659,21 @@ enc_value(_Type, endOfMibView) -> [130,0]; enc_value('NULL', _Val) -> [5,0]; +enc_value('Counter32', Val) -> + Val2 = + if + Val > 16#ffffffff -> + exit({error, {bad_counter32, Val}}); + Val >= 16#80000000 -> + (Val band 16#7fffffff) - 16#80000000; + Val >= 0 -> + Val; + true -> + exit({error, {bad_counter32, Val}}) + end, + Bytes2 = enc_integer_notag(Val2), + Len2 = elength(length(Bytes2)), + lists:append([65 | Len2],Bytes2); enc_value('Counter64', Val) -> Val2 = if -- cgit v1.2.3 From b880d9d8f983b08d5d9e14226b8dbfc1643dbf58 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 20 Apr 2011 10:48:29 +0200 Subject: Patch from Attila Rajmund Nohl: Arguments switched. --- lib/snmp/src/agent/snmpa_trap.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa_trap.erl b/lib/snmp/src/agent/snmpa_trap.erl index 04b78a3847..3c7ae804a5 100644 --- a/lib/snmp/src/agent/snmpa_trap.erl +++ b/lib/snmp/src/agent/snmpa_trap.erl @@ -592,8 +592,8 @@ send_discovery_pdu(Record, Dest, Vbs, ContextName, Timeout, Retry, IVbs, NetIf, - ExtraInfo, - get(verbosity)]), + get(verbosity), + ExtraInfo]), {ok, Sender, SecLevel}. init_discovery_inform(Parent, -- cgit v1.2.3 From fbcefc345a5fc677cce94e5b2ae6a52919d5ee2c Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 2 May 2011 16:15:58 +0200 Subject: Forgot to deprecate snmpm:agb/5,6,7,8,9 --- lib/snmp/src/manager/snmpm.erl | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/snmp') diff --git a/lib/snmp/src/manager/snmpm.erl b/lib/snmp/src/manager/snmpm.erl index 36b4901e9a..9cab8f29c2 100644 --- a/lib/snmp/src/manager/snmpm.erl +++ b/lib/snmp/src/manager/snmpm.erl @@ -119,6 +119,11 @@ -deprecated({gb, 7}). -deprecated({gb, 8}). -deprecated({gb, 9}). +-deprecated({agb, 5}). +-deprecated({agb, 6}). +-deprecated({agb, 7}). +-deprecated({agb, 8}). +-deprecated({agb, 9}). -deprecated({s, 3}). -deprecated({s, 4}). -deprecated({s, 5}). -- cgit v1.2.3 From b841f4fd4d6693ad91621c92839c2b36d7de472a Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 11 May 2011 10:55:10 +0200 Subject: Dialyzer cleanup (removed unused function clauses). --- lib/snmp/src/app/snmp.appup.src | 4 ++++ lib/snmp/src/misc/snmp_log.erl | 5 ----- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index 5bc48a43d0..f931b14338 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -28,6 +28,7 @@ {load_module, snmpm, soft_purge, soft_purge, [snmpm_server]}, {load_module, snmpa_usm, soft_purge, soft_purge, []}, {load_module, snmpm_usm, soft_purge, soft_purge, []}, + {load_module, snmp_log, soft_purge, soft_purge, []}, {load_module, snmp_conf, soft_purge, soft_purge, []}, {load_module, snmpa_conf, soft_purge, soft_purge, [snmp_conf]}, {load_module, snmp_misc, soft_purge, soft_purge, []}, @@ -59,6 +60,7 @@ {load_module, snmpa_usm, soft_purge, soft_purge, []}, {load_module, snmpm_usm, soft_purge, soft_purge, []}, {load_module, snmp_misc, soft_purge, soft_purge, []}, + {load_module, snmp_log, soft_purge, soft_purge, []}, {load_module, snmp_conf, soft_purge, soft_purge, []}, {load_module, snmp_config, soft_purge, soft_purge, [snmp_conf]}, {load_module, snmpa_conf, soft_purge, soft_purge, []}, @@ -111,6 +113,7 @@ {load_module, snmpm, soft_purge, soft_purge, [snmpm_server]}, {load_module, snmpa_usm, soft_purge, soft_purge, []}, {load_module, snmpm_usm, soft_purge, soft_purge, []}, + {load_module, snmp_log, soft_purge, soft_purge, []}, {load_module, snmp_conf, soft_purge, soft_purge, []}, {load_module, snmpa_conf, soft_purge, soft_purge, [snmp_conf]}, {load_module, snmp_misc, soft_purge, soft_purge, []}, @@ -144,6 +147,7 @@ {load_module, snmpa_usm, soft_purge, soft_purge, []}, {load_module, snmpm_usm, soft_purge, soft_purge, []}, {load_module, snmp_misc, soft_purge, soft_purge, []}, + {load_module, snmp_log, soft_purge, soft_purge, []}, {load_module, snmp_conf, soft_purge, soft_purge, []}, {load_module, snmpa_conf, soft_purge, soft_purge, [snmp_conf]}, {load_module, snmp_config, soft_purge, soft_purge, []}, diff --git a/lib/snmp/src/misc/snmp_log.erl b/lib/snmp/src/misc/snmp_log.erl index f9aa911817..7930e37c66 100644 --- a/lib/snmp/src/misc/snmp_log.erl +++ b/lib/snmp/src/misc/snmp_log.erl @@ -266,9 +266,6 @@ validate_loop(eof, _Log, _Validatior, _PrevTS, _PrevSN) -> ok; validate_loop({error, _} = Error, _Log, _Validator, _PrevTS, _PrevSN) -> Error; -validate_loop({corrupt_log_file, _} = Reason, - _Log, _Validator, _PrevTS, _PrevSN) -> - {error, Reason}; validate_loop({Cont, Terms}, Log, Validator, PrevTS, PrevSN) -> ?vtrace("validate_loop -> entry with" "~n Terms: ~p" @@ -508,8 +505,6 @@ loop(eof, _Log, _Write) -> ok; loop({error, _} = Error, _Log, _Write) -> Error; -loop({corrupt_log_file, _} = Reason, _Log, _Write) -> - {error, Reason}; loop({Cont, Terms}, Log, Write) -> case (catch lists:foreach(Write, Terms)) of {'EXIT', Reason} -> -- cgit v1.2.3 From 4dde37d7d40d213ba052a4f6c18b7c257bf93960 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 11 May 2011 12:11:57 +0200 Subject: Release notes, test case and some minor decode fixes (allow only 32 bit values when decoding). --- lib/snmp/doc/src/notes.xml | 9 +++++++ lib/snmp/src/misc/snmp_pdus.erl | 11 ++------ lib/snmp/test/snmp_pdus_test.erl | 55 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 64 insertions(+), 11 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index c507965cd8..105a977d92 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -43,6 +43,15 @@

-

--> + +

Fixed endode/decode of values of type Counter32.

+

This type (Counter32) is an unsigned integer 32, + but is actually encoded as an signed integer 32. + The encode/decode functions however, treated it as if it was + encodeded as an unsigned integer 32.

+

Own Id: OTP-9022

+
+

[agent] Added support for sending traps to IPv6 targets.

See the diff --git a/lib/snmp/src/misc/snmp_pdus.erl b/lib/snmp/src/misc/snmp_pdus.erl index 9c273bc0e0..213d0226b1 100644 --- a/lib/snmp/src/misc/snmp_pdus.erl +++ b/lib/snmp/src/misc/snmp_pdus.erl @@ -268,14 +268,6 @@ dec_value([4 | Bytes]) -> dec_value([64 | Bytes]) -> {Value, Rest} = dec_oct_str_notag(Bytes), {{'IpAddress', Value}, Rest}; -%% dec_value([65 | Bytes]) -> -%% {Value, Rest} = dec_integer_notag(Bytes), -%% if -%% (Value >= 0) andalso (Value =< 4294967295) -> -%% {{'Counter32', Value}, Rest}; -%% true -> -%% exit({error, {bad_counter32, Value}}) -%% end; dec_value([65 | Bytes]) -> %% Counter32 is an unsigned 32 but is actually encoded as %% a signed integer 32 (INTEGER). @@ -284,12 +276,13 @@ dec_value([65 | Bytes]) -> if (Value >= 0) andalso (Value =< 16#ffffffff) -> %% We accept value above 16#7fffffff + %% in order to be backward bug-compatible Value; (Value < 0) -> 16#ffffffff + Value + 1; true -> exit({error, {bad_counter32, Value}}) end, - {{'Counter64', Value2}, Rest}; + {{'Counter32', Value2}, Rest}; dec_value([66 | Bytes]) -> {Value, Rest} = dec_integer_notag(Bytes), if diff --git a/lib/snmp/test/snmp_pdus_test.erl b/lib/snmp/test/snmp_pdus_test.erl index ef510ad62e..197797c816 100644 --- a/lib/snmp/test/snmp_pdus_test.erl +++ b/lib/snmp/test/snmp_pdus_test.erl @@ -38,6 +38,8 @@ otp7575/1, otp8563/1, + otp9022/1, + init_per_testcase/2, end_per_testcase/2 ]). @@ -75,7 +77,7 @@ all() -> [{group, tickets}]. groups() -> - [{tickets, [], [otp7575, otp8563]}]. + [{tickets, [], [otp7575, otp8563, otp9022]}]. init_per_group(_GroupName, Config) -> Config. @@ -169,7 +171,56 @@ otp8563(Config) when is_list(Config) -> Unexpected7 -> exit({unexpected_encode_result, Unexpected7, Val7}) end, - + + ok. + + +otp9022(suite) -> []; +otp9022(doc) -> ["OTP-9022"]; +otp9022(Config) when is_list(Config) -> + Val1 = 16#7fffffff, + io:format("try encode and decode ~w~n", [Val1]), + Enc1 = snmp_pdus:enc_value('Counter32', Val1), + {{'Counter32', Val1}, []} = snmp_pdus:dec_value(Enc1), + + Val2 = Val1 + 1, + io:format("try encode and decode ~w~n", [Val2]), + Enc2 = snmp_pdus:enc_value('Counter32', Val2), + {{'Counter32', Val2}, []} = snmp_pdus:dec_value(Enc2), + + Val3 = Val2 + 1, + io:format("try encode and decode ~w~n", [Val3]), + Enc3 = snmp_pdus:enc_value('Counter32', Val3), + {{'Counter32', Val3}, []} = snmp_pdus:dec_value(Enc3), + + Val4 = 16#fffffffe, + io:format("try encode and decode ~w~n", [Val4]), + Enc4 = snmp_pdus:enc_value('Counter32', Val4), + {{'Counter32', Val4}, []} = snmp_pdus:dec_value(Enc4), + + Val5 = Val4 + 1, + io:format("try encode and decode ~w~n", [Val5]), + Enc5 = snmp_pdus:enc_value('Counter32', Val5), + {{'Counter32', Val5}, []} = snmp_pdus:dec_value(Enc5), + + Val6 = 16#ffffffff + 1, + io:format("try and fail to encode ~w~n", [Val6]), + case (catch snmp_pdus:enc_value('Counter32', Val6)) of + {'EXIT', {error, {bad_counter32, Val6}}} -> + ok; + Unexpected6 -> + exit({unexpected_encode_result, Unexpected6, Val6}) + end, + + Val7 = -1, + io:format("try and fail to encode ~w~n", [Val7]), + case (catch snmp_pdus:enc_value('Counter32', Val7)) of + {'EXIT', {error, {bad_counter32, Val7}}} -> + ok; + Unexpected7 -> + exit({unexpected_encode_result, Unexpected7, Val7}) + end, + ok. -- cgit v1.2.3 From 3122d9125723578e140082a499c08a27480de67b Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 11 May 2011 12:14:07 +0200 Subject: Cosmetics. --- lib/snmp/src/misc/snmp_pdus.erl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/misc/snmp_pdus.erl b/lib/snmp/src/misc/snmp_pdus.erl index 213d0226b1..82618a0b86 100644 --- a/lib/snmp/src/misc/snmp_pdus.erl +++ b/lib/snmp/src/misc/snmp_pdus.erl @@ -281,7 +281,8 @@ dec_value([65 | Bytes]) -> (Value < 0) -> 16#ffffffff + Value + 1; true -> - exit({error, {bad_counter32, Value}}) end, + exit({error, {bad_counter32, Value}}) + end, {{'Counter32', Value2}, Rest}; dec_value([66 | Bytes]) -> {Value, Rest} = dec_integer_notag(Bytes), -- cgit v1.2.3 From 011b45b19a12cb29216883e117a314a251a74fb3 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 11 May 2011 14:43:41 +0200 Subject: Updated appup file also (to handle snmp_pdus). --- lib/snmp/src/app/snmp.appup.src | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/snmp') diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index 4c2de0fcf4..4d68d57553 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -27,6 +27,7 @@ {load_module, snmpm, soft_purge, soft_purge, [snmpm_server]}, {load_module, snmpa_usm, soft_purge, soft_purge, []}, {load_module, snmpm_usm, soft_purge, soft_purge, []}, + {load_module, snmp_pdus, soft_purge, soft_purge, []}, {load_module, snmp_conf, soft_purge, soft_purge, []}, {load_module, snmpa_conf, soft_purge, soft_purge, [snmp_conf]}, {load_module, snmp_misc, soft_purge, soft_purge, []}, @@ -56,6 +57,7 @@ {load_module, snmpa_usm, soft_purge, soft_purge, []}, {load_module, snmpm_usm, soft_purge, soft_purge, []}, {load_module, snmp_misc, soft_purge, soft_purge, []}, + {load_module, snmp_pdus, soft_purge, soft_purge, []}, {load_module, snmp_conf, soft_purge, soft_purge, []}, {load_module, snmp_config, soft_purge, soft_purge, [snmp_conf]}, {load_module, snmpa_conf, soft_purge, soft_purge, []}, @@ -107,6 +109,7 @@ {load_module, snmpm, soft_purge, soft_purge, [snmpm_server]}, {load_module, snmpa_usm, soft_purge, soft_purge, []}, {load_module, snmpm_usm, soft_purge, soft_purge, []}, + {load_module, snmp_pdus, soft_purge, soft_purge, []}, {load_module, snmp_conf, soft_purge, soft_purge, []}, {load_module, snmpa_conf, soft_purge, soft_purge, [snmp_conf]}, {load_module, snmp_misc, soft_purge, soft_purge, []}, @@ -138,6 +141,7 @@ {load_module, snmpa_usm, soft_purge, soft_purge, []}, {load_module, snmpm_usm, soft_purge, soft_purge, []}, {load_module, snmp_misc, soft_purge, soft_purge, []}, + {load_module, snmp_pdus, soft_purge, soft_purge, []}, {load_module, snmp_conf, soft_purge, soft_purge, []}, {load_module, snmpa_conf, soft_purge, soft_purge, [snmp_conf]}, {load_module, snmp_config, soft_purge, soft_purge, []}, -- cgit v1.2.3 From 2f53cae005b91e09969a715978e4001fc04cb668 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 16 May 2011 10:53:51 +0200 Subject: Moved entry from "Improvements..." to "Fixed...". --- lib/snmp/doc/src/notes.xml | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index c1debd42b1..6a20d8ee3a 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -43,15 +43,6 @@

-

--> - -

Fixed endode/decode of values of type Counter32.

-

This type (Counter32) is an unsigned integer 32, - but is actually encoded as an signed integer 32. - The encode/decode functions however, treated it as if it was - encodeded as an unsigned integer 32.

-

Own Id: OTP-9022

-
-

[agent] Added support for sending traps to IPv6 targets.

See the @@ -125,19 +116,21 @@

Fixed Bugs and Malfunctions -

-

+ -

[agent] For the table vacmAccessTable, - when performing the is_set_ok and set operation(s), - all values of the vacmAccessSecurityModel column was - incorrectly translated to any.

-

Own Id: OTP-8980

-
+

Fixed endode/decode of values of type Counter32.

+

This type (Counter32) is an unsigned integer 32, + but is actually encoded as an signed integer 32. + The encode/decode functions however, treated it as if it was + encodeded as an unsigned integer 32.

+

Own Id: OTP-9022

+
--->
-- cgit v1.2.3 From 1f065e1df462e75464fa0a04badd02a6905bec30 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 16 May 2011 18:22:09 +0200 Subject: Spelling in (backward *compatibility*) comment. --- lib/snmp/src/manager/snmpm.erl | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/manager/snmpm.erl b/lib/snmp/src/manager/snmpm.erl index 49f7d66b9a..e457d3b47a 100644 --- a/lib/snmp/src/manager/snmpm.erl +++ b/lib/snmp/src/manager/snmpm.erl @@ -92,7 +92,7 @@ -export([format_reason/1, format_reason/2]). -%% Backward compatibillity exports (API version "2") +%% Backward compatibility exports (API version "2") -export([ sync_get/3, sync_get/4, sync_get/5, sync_get/6, async_get/3, async_get/4, async_get/5, async_get/6, @@ -104,7 +104,7 @@ async_get_bulk/5, async_get_bulk/6, async_get_bulk/7, async_get_bulk/8 ]). -%% Backward compatibillity exports (API version "1") +%% Backward compatibility exports (API version "1") -deprecated({agent_info, 3}). -deprecated({update_agent_info, 5}). -deprecated({g, 3}). @@ -387,23 +387,23 @@ register_agent(UserId, TargetName, Config) is_list(Config)) -> do_register_agent(UserId, TargetName, [{reg_type, target_name} | Config]); -%% Backward compatibillity +%% Backward compatibility %% Note that the agent engine id is a mandatory config option, %% so this function *will* fail! register_agent(UserId, Addr, Port) when is_integer(Port) -> register_agent(UserId, Addr, Port, []); -%% Backward compatibillity +%% Backward compatibility register_agent(UserId, Addr, Config) when is_list(Config) -> register_agent(UserId, Addr, ?DEFAULT_AGENT_PORT, Config). -%% Backward compatibillity +%% Backward compatibility %% Note that the agent engine id is a mandatory config option, %% so this function *will* fail! register_agent(UserId, Addr) -> register_agent(UserId, Addr, ?DEFAULT_AGENT_PORT, []). -%% Backward compatibillity +%% Backward compatibility register_agent(UserId, Addr, Port, Config0) -> case lists:keymember(target_name, 1, Config0) of false -> @@ -423,7 +423,7 @@ register_agent(UserId, Addr, Port, Config0) -> unregister_agent(UserId, TargetName) when is_list(TargetName) -> snmpm_config:unregister_agent(UserId, TargetName); -%% Backward compatibillity functions +%% Backward compatibility functions unregister_agent(UserId, Addr) -> unregister_agent(UserId, Addr, ?DEFAULT_AGENT_PORT). @@ -438,7 +438,7 @@ unregister_agent(UserId, Addr, Port) -> agent_info(TargetName, Item) -> snmpm_config:agent_info(TargetName, Item). -%% Backward compatibillity +%% Backward compatibility agent_info(Addr, Port, Item) -> case target_name(Addr, Port) of {ok, TargetName} -> @@ -450,7 +450,7 @@ agent_info(Addr, Port, Item) -> update_agent_info(UserId, TargetName, Item, Val) -> snmpm_config:update_agent_info(UserId, TargetName, Item, Val). -%% Backward compatibillity functions +%% Backward compatibility functions update_agent_info(UserId, Addr, Port, Item, Val) -> case target_name(Addr, Port) of {ok, TargetName} -> @@ -1365,7 +1365,7 @@ cancel_async_request(UserId, ReqId) -> %%%----------------------------------------------------------------- -%%% Audit Trail Log functions (for backward compatibillity) +%%% Audit Trail Log functions (for backward compatibility) %%%----------------------------------------------------------------- log_to_txt(LogDir, Mibs) -> OutFile = "snmpm_log.txt", -- cgit v1.2.3