All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
psnmp.h
Go to the documentation of this file.
/*
* psnmp.h
*
* Simple Network Management Protocol classes.
*
* Portable Windows Library
*
* Copyright (c) 1993-2002 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Contributor(s): ______________________________________.
*
* $Revision: 26773 $
* $Author: rjongbloed $
* $Date: 2011-12-07 00:43:33 -0600 (Wed, 07 Dec 2011) $
*/
#ifndef PTLIB_PSNMP_H
#define PTLIB_PSNMP_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#ifdef P_SNMP
#include <ptlib/sockets.h>
#include <ptclib/snmp.h>
#include <ptclib/pasn.h>
#include <list>
#include <vector>
class PSNMPVarBindingList : public PObject
{
PCLASSINFO(PSNMPVarBindingList, PObject)
public:
void Append(const PString & objectID);
void Append(const PString & objectID, PASNObject * obj);
void AppendString(const PString & objectID, const PString & str);
void RemoveAll();
PINDEX GetSize() const;
PINDEX GetIndex(const PString & objectID) const;
PString GetObjectID(PINDEX idx) const;
PASNObject & operator[](PINDEX idx) const;
void PrintOn(ostream & strm) const;
protected:
PStringArray objectIds;
PASNObjectArray values;
};
class PSNMP : public PIndirectChannel
{
PCLASSINFO(PSNMP, PIndirectChannel)
public:
enum ErrorType {
// Standard RFC1157 errors
NoError = 0,
TooBig = 1,
NoSuchName = 2,
BadValue = 3,
ReadOnly = 4,
GenErr = 5,
// Additional errors
NoResponse,
MalformedResponse,
SendFailed,
RxBufferTooSmall,
TxDataTooBig,
NumErrors
};
enum RequestType {
GetRequest = 0,
GetNextRequest = 1,
GetResponse = 2,
SetRequest = 3,
Trap = 4,
};
enum { TrapPort = 162 };
enum TrapType {
ColdStart = 0,
WarmStart = 1,
LinkDown = 2,
LinkUp = 3,
AuthenticationFailure = 4,
EGPNeighbourLoss = 5,
EnterpriseSpecific = 6,
NumTrapTypes
};
static PString GetErrorText(ErrorType err);
static PString GetTrapTypeText(PINDEX code);
static void SendEnterpriseTrap (
const PIPSocket::Address & addr,
const PString & community,
const PString & enterprise,
PINDEX specificTrap,
PASNUnsigned timeTicks,
WORD sendPort = TrapPort);
static void SendEnterpriseTrap (
const PIPSocket::Address & addr,
const PString & community,
const PString & enterprise,
PINDEX specificTrap,
PASNUnsigned timeTicks,
const PSNMPVarBindingList & vars,
WORD sendPort = TrapPort);
static void SendTrap (
const PIPSocket::Address & addr,
PSNMP::TrapType trapType,
const PString & community,
const PString & enterprise,
PINDEX specificTrap,
PASNUnsigned timeTicks,
const PSNMPVarBindingList & vars,
WORD sendPort = TrapPort);
static void SendTrap (
const PIPSocket::Address & addr,
PSNMP::TrapType trapType,
const PString & community,
const PString & enterprise,
PINDEX specificTrap,
PASNUnsigned timeTicks,
const PSNMPVarBindingList & vars,
const PIPSocket::Address & agentAddress,
WORD sendPort = TrapPort);
static void WriteTrap ( PChannel & channel,
PSNMP::TrapType trapType,
const PString & community,
const PString & enterprise,
PINDEX specificTrap,
PASNUnsigned timeTicks,
const PSNMPVarBindingList & vars,
const PIPSocket::Address & agentAddress);
/*
static PBoolean DecodeTrap(const PBYTEArray & readBuffer,
PINDEX & version,
PString & community,
PString & enterprise,
PIPSocket::Address & address,
PINDEX & genericTrapType,
PINDEX & specificTrapType,
PASNUnsigned & timeTicks,
PSNMPVarBindingList & varsOut);
*/
typedef list<pair<PString,PRFC1155_ObjectSyntax> > BindingList;
};
class PSNMPClient : public PSNMP
{
PCLASSINFO(PSNMPClient, PSNMP)
public:
PSNMPClient(const PString & host,
PINDEX retryMax = 5,
PINDEX timeoutMax = 5,
PINDEX rxBufferSize = 1500,
PINDEX txSize = 484);
PSNMPClient(PINDEX retryMax = 5,
PINDEX timeoutMax = 5,
PINDEX rxBufferSize = 1500,
PINDEX txSize = 484);
void SetVersion(PASNInt version);
PASNInt GetVersion() const;
void SetCommunity(const PString & str);
PString GetCommunity() const;
void SetRequestID(PASNInt requestID);
PASNInt GetRequestID() const;
PBoolean WriteGetRequest (PSNMPVarBindingList & varsIn,
PSNMPVarBindingList & varsOut);
PBoolean WriteGetNextRequest (PSNMPVarBindingList & varsIn,
PSNMPVarBindingList & varsOut);
PBoolean WriteSetRequest (PSNMPVarBindingList & varsIn,
PSNMPVarBindingList & varsOut);
ErrorType GetLastErrorCode() const;
PINDEX GetLastErrorIndex() const;
PString GetLastErrorText() const;
protected:
PBoolean WriteRequest (PASNInt requestCode,
PSNMPVarBindingList & varsIn,
PSNMPVarBindingList & varsOut);
PBoolean ReadRequest(PBYTEArray & readBuffer);
PString hostName;
PString community;
PASNInt requestId;
PASNInt version;
PINDEX retryMax;
PINDEX lastErrorIndex;
ErrorType lastErrorCode;
PBYTEArray readBuffer;
PINDEX maxRxSize;
PINDEX maxTxSize;
};
class PSNMPServer : public PSNMP
{
PCLASSINFO(PSNMPServer, PSNMP)
public:
PSNMPServer(PIPSocket::Address binding = PIPSocket::GetDefaultIpAny(),
WORD localPort = 161,
PINDEX timeout = 5000,
PINDEX rxSize = 10000,
PINDEX txSize = 10000);
~PSNMPServer();
void Main();
void SetVersion(PASNInt newVersion);
PBoolean HandleChannel();
PBoolean ProcessPDU(const PBYTEArray & readBuffer, PBYTEArray & writeBuffer);
virtual PBoolean Authorise(const PIPSocket::Address & received);
virtual PBoolean ConfirmVersion(PASN_Integer vers);
virtual PBoolean ConfirmCommunity(PASN_OctetString & community);
virtual PBoolean MIB_LocalMatch(PSNMP_PDU & pdu);
virtual PBoolean OnGetRequest (PINDEX reqID, PSNMP::BindingList & vars, PSNMP::ErrorType & errCode);
virtual PBoolean OnGetNextRequest (PINDEX reqID, PSNMP::BindingList & vars, PSNMP::ErrorType & errCode);
virtual PBoolean OnSetRequest (PINDEX reqID, PSNMP::BindingList & vars, PSNMP::ErrorType & errCode);
PSNMP::ErrorType SendGetResponse (PSNMPVarBindingList & vars);
protected:
PThreadObj<PSNMPServer> m_thread;
PString community;
PASN_Integer version;
PINDEX lastErrorIndex;
ErrorType lastErrorCode;
PBYTEArray readBuffer;
PINDEX maxRxSize;
PINDEX maxTxSize;
PUDPSocket *baseSocket;
PDictionary<PRFC1155_ObjectName, PRFC1155_ObjectSyntax> objList;
};
#endif // P_SNMP
#endif // PTLIB_PSNMP_H
// End Of File ///////////////////////////////////////////////////////////////
PSNMPClient::readBuffer
PBYTEArray readBuffer
Definition: psnmp.h:245
PSNMP::BindingList
list< pair< PString, PRFC1155_ObjectSyntax > > BindingList
Definition: psnmp.h:185
snmp.h
PSNMPVarBindingList::operator[]
PASNObject & operator[](PINDEX idx) const
PSNMPVarBindingList::GetObjectID
PString GetObjectID(PINDEX idx) const
PSNMP::BadValue
Definition: psnmp.h:88
PSNMPServer::version
PASN_Integer version
Definition: psnmp.h:289
PCLASSINFO
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:1049
PSNMPServer::readBuffer
PBYTEArray readBuffer
Definition: psnmp.h:292
PSNMPClient::retryMax
PINDEX retryMax
Definition: psnmp.h:242
PSNMPServer::community
PString community
Definition: psnmp.h:288
PSNMP::LinkDown
Definition: psnmp.h:114
PSNMPVarBindingList::RemoveAll
void RemoveAll()
PSNMPServer::ConfirmCommunity
virtual PBoolean ConfirmCommunity(PASN_OctetString &community)
PSNMPClient::WriteGetRequest
PBoolean WriteGetRequest(PSNMPVarBindingList &varsIn, PSNMPVarBindingList &varsOut)
PSNMP::NumTrapTypes
Definition: psnmp.h:119
PSNMP::SendFailed
Definition: psnmp.h:95
PSNMP::NumErrors
Definition: psnmp.h:98
PUDPSocket
A socket channel that uses the UDP transport on the Internet Protocol.
Definition: udpsock.h:47
PDictionary< PRFC1155_ObjectName, PRFC1155_ObjectSyntax >
PSNMP::SendTrap
static void SendTrap(const PIPSocket::Address &addr, PSNMP::TrapType trapType, const PString &community, const PString &enterprise, PINDEX specificTrap, PASNUnsigned timeTicks, const PSNMPVarBindingList &vars, WORD sendPort=TrapPort)
PSNMP
A descendant of PUDPSocket which can perform SNMP calls.
Definition: psnmp.h:79
PSNMP::ColdStart
Definition: psnmp.h:112
PSNMPClient::SetVersion
void SetVersion(PASNInt version)
PSNMPClient::community
PString community
Definition: psnmp.h:239
PIndirectChannel
This is a channel that operates indirectly through another channel(s).
Definition: indchan.h:49
PSNMP::TrapType
TrapType
Definition: psnmp.h:111
PSNMP::GetTrapTypeText
static PString GetTrapTypeText(PINDEX code)
PSNMPVarBindingList::objectIds
PStringArray objectIds
Definition: psnmp.h:71
PStringArray
This is an array collection class of PString objects.
Definition: pstring.h:2024
PSNMPClient::SetCommunity
void SetCommunity(const PString &str)
PSNMP::GetRequest
Definition: psnmp.h:102
PSNMPServer::lastErrorIndex
PINDEX lastErrorIndex
Definition: psnmp.h:290
PASNInt
PInt32 PASNInt
Definition: pasn.h:43
PSNMPClient::lastErrorIndex
PINDEX lastErrorIndex
Definition: psnmp.h:243
PASNObject
This class defines the common behviour of all ASN objects.
Definition: pasn.h:64
PSNMPClient
Class which gets SNMP data.
Definition: psnmp.h:193
PSNMPServer::maxTxSize
PINDEX maxTxSize
Definition: psnmp.h:294
PSNMPClient::WriteRequest
PBoolean WriteRequest(PASNInt requestCode, PSNMPVarBindingList &varsIn, PSNMPVarBindingList &varsOut)
PSNMPServer::MIB_LocalMatch
virtual PBoolean MIB_LocalMatch(PSNMP_PDU &pdu)
PSNMP::AuthenticationFailure
Definition: psnmp.h:116
PSNMP::GetResponse
Definition: psnmp.h:104
PSNMPServer::SetVersion
void SetVersion(PASNInt newVersion)
PBoolean
BOOL PBoolean
Definition: object.h:102
PSNMPClient::GetLastErrorIndex
PINDEX GetLastErrorIndex() const
PSNMPServer::Main
void Main()
PSNMPClient::SetRequestID
void SetRequestID(PASNInt requestID)
PSNMP::ReadOnly
Definition: psnmp.h:89
PSNMPServer::OnSetRequest
virtual PBoolean OnSetRequest(PINDEX reqID, PSNMP::BindingList &vars, PSNMP::ErrorType &errCode)
PSNMPVarBindingList::AppendString
void AppendString(const PString &objectID, const PString &str)
PBYTEArray
Array of unsigned characters.
Definition: array.h:670
PSNMPClient::hostName
PString hostName
Definition: psnmp.h:238
PSNMP::WarmStart
Definition: psnmp.h:113
PSNMP::NoSuchName
Definition: psnmp.h:87
PSNMPServer::ProcessPDU
PBoolean ProcessPDU(const PBYTEArray &readBuffer, PBYTEArray &writeBuffer)
PSNMP::RxBufferTooSmall
Definition: psnmp.h:96
PSNMPClient::PSNMPClient
PSNMPClient(const PString &host, PINDEX retryMax=5, PINDEX timeoutMax=5, PINDEX rxBufferSize=1500, PINDEX txSize=484)
PSNMP::GetErrorText
static PString GetErrorText(ErrorType err)
PSNMP::EnterpriseSpecific
Definition: psnmp.h:118
PSNMP::ErrorType
ErrorType
Definition: psnmp.h:83
PSNMPVarBindingList::PrintOn
void PrintOn(ostream &strm) const
Output the contents of the object to the stream.
PSNMP::GenErr
Definition: psnmp.h:90
PSNMP::TrapPort
Definition: psnmp.h:109
PSNMP::Trap
Definition: psnmp.h:106
PSNMPServer::m_thread
PThreadObj< PSNMPServer > m_thread
Definition: psnmp.h:287
PSNMPClient::requestId
PASNInt requestId
Definition: psnmp.h:240
PSNMP::TxDataTooBig
Definition: psnmp.h:97
PSNMPClient::maxRxSize
PINDEX maxRxSize
Definition: psnmp.h:246
PSNMPServer::Authorise
virtual PBoolean Authorise(const PIPSocket::Address &received)
PChannel
Abstract class defining I/O channel semantics.
Definition: channel.h:107
PSNMPServer::OnGetNextRequest
virtual PBoolean OnGetNextRequest(PINDEX reqID, PSNMP::BindingList &vars, PSNMP::ErrorType &errCode)
PSNMPVarBindingList::values
PASNObjectArray values
Definition: psnmp.h:72
PSNMP::SendEnterpriseTrap
static void SendEnterpriseTrap(const PIPSocket::Address &addr, const PString &community, const PString &enterprise, PINDEX specificTrap, PASNUnsigned timeTicks, WORD sendPort=TrapPort)
PSNMPClient::GetRequestID
PASNInt GetRequestID() const
PSNMPVarBindingList::GetSize
PINDEX GetSize() const
PSNMPClient::maxTxSize
PINDEX maxTxSize
Definition: psnmp.h:247
PSNMPServer::~PSNMPServer
~PSNMPServer()
PString
The character string class.
Definition: pstring.h:108
PSNMP::NoResponse
Definition: psnmp.h:93
PSNMPServer::ConfirmVersion
virtual PBoolean ConfirmVersion(PASN_Integer vers)
PSNMPServer::HandleChannel
PBoolean HandleChannel()
PSNMPClient::version
PASNInt version
Definition: psnmp.h:241
PSNMPServer::PSNMPServer
PSNMPServer(PIPSocket::Address binding=PIPSocket::GetDefaultIpAny(), WORD localPort=161, PINDEX timeout=5000, PINDEX rxSize=10000, PINDEX txSize=10000)
PSNMPVarBindingList
A list of object IDs and their values.
Definition: psnmp.h:51
PSNMP::NoError
Definition: psnmp.h:85
PThreadObj< PSNMPServer >
PSNMP::WriteTrap
static void WriteTrap(PChannel &channel, PSNMP::TrapType trapType, const PString &community, const PString &enterprise, PINDEX specificTrap, PASNUnsigned timeTicks, const PSNMPVarBindingList &vars, const PIPSocket::Address &agentAddress)
PIPSocket::GetDefaultIpAny
static PIPSocket::Address GetDefaultIpAny()
PSNMPVarBindingList::Append
void Append(const PString &objectID)
PSNMP::TooBig
Definition: psnmp.h:86
PSNMPClient::lastErrorCode
ErrorType lastErrorCode
Definition: psnmp.h:244
PIPSocket::Address
A class describing an IP address.
Definition: ipsock.h:75
PSNMPVarBindingList::GetIndex
PINDEX GetIndex(const PString &objectID) const
PSNMPClient::ReadRequest
PBoolean ReadRequest(PBYTEArray &readBuffer)
PSNMPClient::WriteSetRequest
PBoolean WriteSetRequest(PSNMPVarBindingList &varsIn, PSNMPVarBindingList &varsOut)
PSNMPServer::SendGetResponse
PSNMP::ErrorType SendGetResponse(PSNMPVarBindingList &vars)
PSNMP::LinkUp
Definition: psnmp.h:115
PSNMPServer::OnGetRequest
virtual PBoolean OnGetRequest(PINDEX reqID, PSNMP::BindingList &vars, PSNMP::ErrorType &errCode)
PSNMPClient::WriteGetNextRequest
PBoolean WriteGetNextRequest(PSNMPVarBindingList &varsIn, PSNMPVarBindingList &varsOut)
PSNMPServer::baseSocket
PUDPSocket * baseSocket
Definition: psnmp.h:295
sockets.h
PSNMP::SetRequest
Definition: psnmp.h:105
PSNMPClient::GetCommunity
PString GetCommunity() const
PASN_OctetString
Class for ASN Octet String type.
Definition: asner.h:458
PSNMP::RequestType
RequestType
Definition: psnmp.h:101
PSNMP::EGPNeighbourLoss
Definition: psnmp.h:117
PASN_Integer
Class for ASN Integer type.
Definition: asner.h:234
PSNMPClient::GetLastErrorText
PString GetLastErrorText() const
PSNMP_PDU
Definition: snmp.h:135
pasn.h
PSNMPServer
Class which supplies SNMP data.
Definition: psnmp.h:255
PSNMP::GetNextRequest
Definition: psnmp.h:103
PSNMPServer::objList
PDictionary< PRFC1155_ObjectName, PRFC1155_ObjectSyntax > objList
Definition: psnmp.h:296
PObject
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PSNMPServer::maxRxSize
PINDEX maxRxSize
Definition: psnmp.h:293
PSNMPClient::GetVersion
PASNInt GetVersion() const
PASNUnsigned
DWORD PASNUnsigned
Definition: pasn.h:44
PSNMP::MalformedResponse
Definition: psnmp.h:94
PSNMPClient::GetLastErrorCode
ErrorType GetLastErrorCode() const
PSNMPServer::lastErrorCode
ErrorType lastErrorCode
Definition: psnmp.h:291