5 //=============================================================================
11 * @author Peter E Mellquist Michael R. MacFaden (ported to ACE)
13 //=============================================================================
15 /*===================================================================
17 Hewlett-Packard Company
19 ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
20 Permission to use, copy, modify, distribute and/or sell this software
21 and/or its documentation is hereby granted without fee. User agrees
22 to display the above copyright notice and this license notice in all
23 copies of the software and any documentation of the software. User
24 agrees to assume all liability for the use of the software; Hewlett-Packard
25 makes no representations about the suitability of this software for any
26 purpose. It is provided "AS-IS" without warranty of any kind,either express
27 or implied. User hereby grants a royalty-free license to any and all
28 derivatives based upon this software code base.
29 =====================================================================*/
31 //----[ includes ]------------------------------------------------
32 #include "ace/INET_Addr.h"
34 #if !defined (ACE_LACKS_PRAGMA_ONCE)
36 #endif /* ACE_LACKS_PRAGMA_ONCE */
38 #include "asnmp/address.h"
39 #include "asnmp/oid.h"
40 #include "asnmp/octet.h"
42 //----[ enumerated types for SNMP versions ]-------------------------
45 version2c
, // 1 (Cisco IOS does not have IOS v2c agent available yet)
46 version3
// 2 (IETF working on this version)
49 // targets contain the following default properties
51 DEF_TIMEOUT
= 1, // unit: seconds
52 DEF_RETRIES
= 1, // no retry default
53 DEF_MAX_SNMP_PACKET
= 1430, // maximum pdu len on the wire (eth mtu-ip hdr)
54 // split bigger pdus (not implemented yet)
55 DEF_AGENT_PORT
= 161, // port # for SNMP agent
56 DEF_TRAP_PORT
= 162, // port # for SNMP trap receiver
57 DEF_VERSION
= version1
, // default SNMP version
58 MAX_COMM_STR_LEN
= 255, // max value this impl will accept from client
59 MAX_TARGET_STRING_REP
= 2048 // max value this impl will accept from client
62 #define READ_COMM_STR "public"
63 #define WRITE_COMM_STR "private"
65 // Abstract class used to provide a virtual interface into Targets
70 * @brief Abstract Base class SnmpTarget is used to Collect all transmission
71 * details to communicate with an SNMP
73 class ASNMP_Export SnmpTarget
76 /// allow destruction of derived classes
77 virtual ~SnmpTarget();
79 /// return validity of target
82 /// set the retry value
83 void set_retry( const int r
);
85 /// set the object's timeout (in seconds)
86 void set_timeout( const unsigned long t
);
88 /// set the instance version
89 void set_version( const snmp_version v
);
91 /// all classes constructed will have this write community string
92 void set_max_pdu_size(const unsigned long max_pdu_sz
);
94 /// change the "class" default default timeout (in seconds)
95 void set_default_timeout( const unsigned long t
);
97 /// change the default send retries
98 void set_default_retry( const int r
);
100 /// all classes constructed will have this write community string
101 void set_default_max_pdu_size(const unsigned long max_pdu_sz
);
103 /// change class default
104 void set_default_version( const snmp_version v
);
106 // *** get methods ***
108 /// get the retry value
109 int get_default_retry() const;
111 /// get the timeout (seconds)
112 unsigned long get_timeout() const;
114 /// get instance max buffer size
115 unsigned long get_max_pdu_size() const;
117 /// all classes constructed will have this write community string
118 void get_default_max_pdu_size(const unsigned long max_pdu_sz
);
121 snmp_version
get_version() const;
123 snmp_version
get_default_version() const;
125 /// return send retry number for this instancd
126 int get_retry() const;
129 * virtual clone operation for creating a new SnmpTarget from an existing
130 * SnmpTarget. The caller MUST use the delete operation on the return
133 virtual SnmpTarget
*clone() const = 0;
135 /// manipulate the base part
136 friend bool operator==(const SnmpTarget
& lhs
, const SnmpTarget
& rhs
);
138 SnmpTarget
& operator=(const SnmpTarget
& lhs
);
141 /// SnmpTarget(const SnmpTarget &);
144 /// used by derived class instances
147 /// instance value xmit timeout in milli secs
148 unsigned long timeout_
;
150 /// instance value number of retries
154 unsigned max_pdu_size_
;
156 /// instance value the snmp version
157 snmp_version version_
;
159 // class wide default values
160 /// xmit timeout in secs
161 static unsigned long default_timeout_
;
163 /// number of retries
164 static int default_retries_
;
166 /// snmp protocol version
167 static unsigned long default_max_pdu_size_
;
168 static snmp_version default_version_
;
171 //----[ UdpTarget class ]----------------------------------------------
172 // UDP/IP transport using "community string" based agents (targets)
177 * @brief Concrete class UdpTarget contains all Details for communicating
178 * with a SNMPv1 agent over UDP/IPv4 transport
180 class ASNMP_Export UdpTarget
: public SnmpTarget
186 * constructor with only address
187 * assumes default as public, public
188 * can be constructed with IP address object
190 UdpTarget( const UdpAddress
& udp
);
192 /// can be constructed with Udp address object TODO: merge addresses
193 UdpTarget( ACE_INET_Addr
& ace_inet_addr
);
200 /// set the read community using an OctetStr
201 void set_read_community( const OctetStr
& new_read_community
);
203 /// set the write community using an OctetStr
204 void set_write_community( const OctetStr
& write_community
);
207 int set_address( UdpAddress
&udp_address
);
211 /// get the read community as an Octet Str object
212 void get_read_community( OctetStr
& read_community_oct
) const;
214 /// get the write community as an OctetStr
215 void get_write_community( OctetStr
&write_community_oct
) const;
218 void get_address( UdpAddress
& address
) const;
220 /// all classes constructed will have this read community string
221 void set_default_read_community(const OctetStr
& rd_community
);
223 /// all classes constructed will have this write community string
224 void set_default_write_community(const OctetStr
& wr_community
);
226 /// all classes constructed will have this read community string
227 void get_default_read_community(OctetStr
& rd_community
) const;
229 /// all classes constructed will have this write community string
230 void get_default_write_community(OctetStr
& wr_community
) const;
232 /// overloaded assignment
233 UdpTarget
& operator=( const UdpTarget
& target
);
235 /// compare two C targets
236 friend bool operator==( const UdpTarget
&lhs
, const UdpTarget
&rhs
);
238 /// string representation of object
239 const char *to_string();
241 /// clone from existing UdpTarget
242 SnmpTarget
*clone() const;
245 static OctetStr default_rd_community_
;
246 static OctetStr default_wr_community_
;
247 OctetStr read_community_
;
248 OctetStr write_community_
;
249 UdpAddress udp_address_
;
250 snmp_version version_
;
252 /// to_string() rep of data
253 char output_buffer_
[MAX_TARGET_STRING_REP
];