diff options
author | mrm <mrm@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-09-04 23:48:12 +0000 |
---|---|---|
committer | mrm <mrm@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-09-04 23:48:12 +0000 |
commit | ef570e751faf30666708533b0b5678d8117fa783 (patch) | |
tree | ce3827afdecfc2ab71da9ab19a9c7c266bfbd9a9 /ASNMP | |
parent | 3078456790c19208fa32223a395731df551c6176 (diff) | |
download | ATCD-ef570e751faf30666708533b0b5678d8117fa783.tar.gz |
agent api
Diffstat (limited to 'ASNMP')
-rw-r--r-- | ASNMP/asnmp/sagent.cpp | 93 | ||||
-rw-r--r-- | ASNMP/asnmp/sagent.h | 77 |
2 files changed, 170 insertions, 0 deletions
diff --git a/ASNMP/asnmp/sagent.cpp b/ASNMP/asnmp/sagent.cpp new file mode 100644 index 00000000000..d7330815aa0 --- /dev/null +++ b/ASNMP/asnmp/sagent.cpp @@ -0,0 +1,93 @@ +/* -*-C++-*- */ +// ============================================================================ +// +// = LIBRARY +// asnmp +// +// = FILENAME +// sagent.cpp +// +// = DESCRIPTION +// SNMP agent class defintion. The sagent class provides an object oriented +// approach for creating SNMP Agents. The sagent class is an encapsulation of SNMP +// sessions, gets, sets, etc. +// +// = AUTHOR +// Michael R. MacFaden +// +// ============================================================================ +#include "ace/Reactor.h" +#include "ace/SOCK_Dgram.h" + +#include "asnmp/oid.h" // snmp++ oid class +#include "asnmp/vb.h" // snbmp++ vb class +#include "asnmp/target.h" // snmp++ target class +#include "asnmp/pdu.h" // snmp++ pdu class +#include "asnmp/snmperrs.h" // error macros and strings +#include "asnmp/address.h" // snmp++ address class defs +#include "asnmp/snmp.h" // manager snmp interface +#include "asnmp/sagent.h" // agent interface +#include "asnmp/transaction.h" // convert from wire to API + +sagent::sagent(unsigned short port): Snmp(port) +{ + ACE_TRACE("sagent::sagent(short)"); +} + +sagent::~sagent() +{ + ACE_TRACE("sagent::~sagent"); +} + +int sagent::handle_input(ACE_HANDLE fd) +{ + ACE_TRACE("sagent::handle_input"); + + transaction tr(iv_snmp_session_); // this section needs a better design + tr.handle_input(fd); + char rcv_com_str[MAX_COMM_STR_LEN]; + tr.result(pdu_, rcv_com_str); + OctetStr community(rcv_com_str); + const ACE_INET_Addr &ta = tr.get_from_addr(); + char buf_tmp[MAXHOSTNAMELEN + 1]; + ta.addr_to_string (buf_tmp, MAXHOSTNAMELEN); + UdpAddress ra(buf_tmp); + tgt_.set_address(ra); + + + // process msg here by calling subclass's implementation + switch (pdu_.get_type()){ + case sNMP_PDU_GET: + tgt_.set_read_community(community); + this->handle_get(pdu_, tgt_); + break; + + case sNMP_PDU_GETNEXT: + tgt_.set_read_community(community); + this->handle_get_next(pdu_, tgt_); + break; + + case sNMP_PDU_SET: + tgt_.set_write_community(community); + this->handle_set(pdu_, tgt_); + break; + + default: + ACE_ASSERT(0); + } + return 0; +} + +ACE_HANDLE sagent::get_handle() const +{ + ACE_TRACE("sagent::get_handle"); + return iv_snmp_session_.get_handle(); +} + +int sagent::respond(Pdu& pdu,UdpTarget& tgt) +{ + transaction tr(pdu, tgt, iv_snmp_session_); + tr.send(); + return 0; +} + diff --git a/ASNMP/asnmp/sagent.h b/ASNMP/asnmp/sagent.h new file mode 100644 index 00000000000..4dbfcc2586a --- /dev/null +++ b/ASNMP/asnmp/sagent.h @@ -0,0 +1,77 @@ +/* -*-C++-*- */ +#ifndef SAGENT_CLS_ +#define SAGENT_CLS_ +// ============================================================================ +// +// = LIBRARY +// asnmp +// +// = FILENAME +// sagent.h +// +// = DESCRIPTION +// SNMP agent class defintion. The sagent class provides an object oriented +// approach for creating SNMP Agents. The sagent class is an encapsulation of SNMP +// sessions, gets, sets, etc. +// +// = AUTHOR +// Michael R. MacFaden +// +// ============================================================================ +#include "ace/Reactor.h" +#include "ace/SOCK_Dgram.h" + +#include "asnmp/oid.h" // snmp++ oid class +#include "asnmp/vb.h" // snbmp++ vb class +#include "asnmp/target.h" // snmp++ target class +#include "asnmp/pdu.h" // snmp++ pdu class +#include "asnmp/snmperrs.h" // error macros and strings +#include "asnmp/address.h" // snmp++ address class defs +#include "asnmp/snmp.h" // snmp interface + +// sagent - supports Version 1 operations in blocking mode + +#define DEF_AGENT_PORT (161) + +class ACE_Export sagent : public ACE_Event_Handler, Snmp + // = TITLE + // Concrete class sagent defines the session and interface to + // communicate with another SNMP Version 1 manager +{ + public: + + + // override the next three methods (callbacks) to implment your agent + // + + virtual int handle_get( Pdu &pdu, UdpTarget &target) = 0; + // retrieve data from a peer agent for a given list of oid values + + virtual int handle_get_next( Pdu &pdu, UdpTarget &target) = 0; + // retrieve data lexically adjacent to the oids specified in the pdu + // from the peer agent + + virtual int handle_set( Pdu &pdu, UdpTarget &target) = 0; + // set data in the agent from the list of oids in the pdu + + virtual int handle_input(ACE_HANDLE); + // new pdu received from mgr (reactor calls this) + + virtual ACE_HANDLE get_handle() const; + // retrieve io descriptor (reactor uses this) + + int respond(Pdu& pdu, UdpTarget& tgt); + // send a response pdu to the mgr + + protected: + sagent(unsigned short port = DEF_AGENT_PORT); + virtual ~sagent(); + +private: + sagent(const sagent&); + Pdu pdu_; // current input pdu + UdpTarget tgt_; // addr & com strs +}; + +#endif //SAGENT_CLS_ + |