PTLib
Version 2.14.3
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
psnmp.h
Go to the documentation of this file.
1
/*
2
* psnmp.h
3
*
4
* Simple Network Management Protocol classes.
5
*
6
* Portable Windows Library
7
*
8
* Copyright (c) 1993-2002 Equivalence Pty. Ltd.
9
*
10
* The contents of this file are subject to the Mozilla Public License
11
* Version 1.0 (the "License"); you may not use this file except in
12
* compliance with the License. You may obtain a copy of the License at
13
* http://www.mozilla.org/MPL/
14
*
15
* Software distributed under the License is distributed on an "AS IS"
16
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17
* the License for the specific language governing rights and limitations
18
* under the License.
19
*
20
* The Original Code is Portable Windows Library.
21
*
22
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23
*
24
* Contributor(s): ______________________________________.
25
*
26
* $Revision: 25507 $
27
* $Author: rjongbloed $
28
* $Date: 2011-04-06 15:02:42 +1000 (Wed, 06 Apr 2011) $
29
*/
30
31
#ifndef PTLIB_PSNMP_H
32
#define PTLIB_PSNMP_H
33
34
#ifdef P_USE_PRAGMA
35
#pragma interface
36
#endif
37
38
#ifdef P_SNMP
39
40
#include <
ptlib/sockets.h
>
41
#include <
ptclib/snmp.h
>
42
#include <
ptclib/pasn.h
>
43
44
#include <list>
45
#include <vector>
46
48
51
class
PSNMPVarBindingList
:
public
PObject
52
{
53
PCLASSINFO
(
PSNMPVarBindingList
,
PObject
)
54
public
:
55
56
void
Append
(
const
PString
& objectID);
57
void
Append
(
const
PString
& objectID,
PASNObject
* obj);
58
void
AppendString
(
const
PString
& objectID,
const
PString
& str);
59
60
void
RemoveAll
();
61
62
PINDEX
GetSize
()
const
;
63
64
PINDEX
GetIndex
(
const
PString
& objectID)
const
;
65
PString
GetObjectID
(PINDEX idx)
const
;
66
PASNObject
&
operator[]
(PINDEX idx)
const
;
67
68
void
PrintOn
(ostream & strm)
const
;
69
70
protected
:
71
PStringArray
objectIds
;
72
PASNObjectArray
values
;
73
};
74
76
79
class
PSNMP
:
public
PIndirectChannel
80
{
81
PCLASSINFO
(
PSNMP
,
PIndirectChannel
)
82
public
:
83
enum
ErrorType
{
84
// Standard RFC1157 errors
85
NoError
= 0,
86
TooBig
= 1,
87
NoSuchName
= 2,
88
BadValue
= 3,
89
ReadOnly
= 4,
90
GenErr
= 5,
91
92
// Additional errors
93
NoResponse
,
94
MalformedResponse
,
95
SendFailed
,
96
RxBufferTooSmall
,
97
TxDataTooBig
,
98
NumErrors
99
};
100
101
enum
RequestType
{
102
GetRequest
= 0,
103
GetNextRequest
= 1,
104
GetResponse
= 2,
105
SetRequest
= 3,
106
Trap
= 4,
107
};
108
109
enum
{
TrapPort
= 162 };
110
111
enum
TrapType
{
112
ColdStart
= 0,
113
WarmStart
= 1,
114
LinkDown
= 2,
115
LinkUp
= 3,
116
AuthenticationFailure
= 4,
117
EGPNeighbourLoss
= 5,
118
EnterpriseSpecific
= 6,
119
NumTrapTypes
120
};
121
122
static
PString
GetErrorText
(
ErrorType
err);
123
124
static
PString
GetTrapTypeText
(PINDEX code);
125
126
static
void
SendEnterpriseTrap
(
127
const
PIPSocket::Address
& addr,
128
const
PString
& community,
129
const
PString
& enterprise,
130
PINDEX specificTrap,
131
PASNUnsigned
timeTicks,
132
WORD sendPort =
TrapPort
);
133
134
static
void
SendEnterpriseTrap
(
135
const
PIPSocket::Address
& addr,
136
const
PString
& community,
137
const
PString
& enterprise,
138
PINDEX specificTrap,
139
PASNUnsigned
timeTicks,
140
const
PSNMPVarBindingList
& vars,
141
WORD sendPort =
TrapPort
);
142
143
static
void
SendTrap
(
144
const
PIPSocket::Address
& addr,
145
PSNMP::TrapType
trapType,
146
const
PString
& community,
147
const
PString
& enterprise,
148
PINDEX specificTrap,
149
PASNUnsigned
timeTicks,
150
const
PSNMPVarBindingList
& vars,
151
WORD sendPort =
TrapPort
);
152
153
static
void
SendTrap
(
154
const
PIPSocket::Address
& addr,
155
PSNMP::TrapType
trapType,
156
const
PString
& community,
157
const
PString
& enterprise,
158
PINDEX specificTrap,
159
PASNUnsigned
timeTicks,
160
const
PSNMPVarBindingList
& vars,
161
const
PIPSocket::Address
& agentAddress,
162
WORD sendPort =
TrapPort
);
163
164
static
void
WriteTrap
(
PChannel
& channel,
165
PSNMP::TrapType
trapType,
166
const
PString
& community,
167
const
PString
& enterprise,
168
PINDEX specificTrap,
169
PASNUnsigned
timeTicks,
170
const
PSNMPVarBindingList
& vars,
171
const
PIPSocket::Address
& agentAddress);
172
173
/*
174
static PBoolean DecodeTrap(const PBYTEArray & readBuffer,
175
PINDEX & version,
176
PString & community,
177
PString & enterprise,
178
PIPSocket::Address & address,
179
PINDEX & genericTrapType,
180
PINDEX & specificTrapType,
181
PASNUnsigned & timeTicks,
182
PSNMPVarBindingList & varsOut);
183
*/
184
185
typedef
list<pair<PString,PRFC1155_ObjectSyntax> >
BindingList
;
186
};
187
188
190
193
class
PSNMPClient
:
public
PSNMP
194
{
195
PCLASSINFO
(
PSNMPClient
,
PSNMP
)
196
public
:
197
PSNMPClient
(
const
PString
& host,
198
PINDEX
retryMax
= 5,
199
PINDEX timeoutMax = 5,
200
PINDEX rxBufferSize = 1500,
201
PINDEX txSize = 484);
202
203
PSNMPClient
(PINDEX
retryMax
= 5,
204
PINDEX timeoutMax = 5,
205
PINDEX rxBufferSize = 1500,
206
PINDEX txSize = 484);
207
208
void
SetVersion
(
PASNInt
version
);
209
PASNInt
GetVersion
()
const
;
210
211
void
SetCommunity
(
const
PString
& str);
212
PString
GetCommunity
()
const
;
213
214
void
SetRequestID
(
PASNInt
requestID);
215
PASNInt
GetRequestID
()
const
;
216
217
PBoolean
WriteGetRequest
(
PSNMPVarBindingList
& varsIn,
218
PSNMPVarBindingList
& varsOut);
219
220
PBoolean
WriteGetNextRequest
(
PSNMPVarBindingList
& varsIn,
221
PSNMPVarBindingList
& varsOut);
222
223
PBoolean
WriteSetRequest
(
PSNMPVarBindingList
& varsIn,
224
PSNMPVarBindingList
& varsOut);
225
226
ErrorType
GetLastErrorCode
()
const
;
227
PINDEX
GetLastErrorIndex
()
const
;
228
PString
GetLastErrorText
()
const
;
229
230
protected
:
231
PBoolean
WriteRequest
(
PASNInt
requestCode,
232
PSNMPVarBindingList
& varsIn,
233
PSNMPVarBindingList
& varsOut);
234
235
236
PBoolean
ReadRequest
(
PBYTEArray
&
readBuffer
);
237
238
PString
hostName
;
239
PString
community
;
240
PASNInt
requestId
;
241
PASNInt
version
;
242
PINDEX
retryMax
;
243
PINDEX
lastErrorIndex
;
244
ErrorType
lastErrorCode
;
245
PBYTEArray
readBuffer
;
246
PINDEX
maxRxSize
;
247
PINDEX
maxTxSize
;
248
};
249
250
252
255
class
PSNMPServer
:
public
PSNMP
256
{
257
PCLASSINFO
(
PSNMPServer
,
PSNMP
)
258
public
:
259
260
PSNMPServer
(
PIPSocket::Address
binding =
PIPSocket::GetDefaultIpAny
(),
261
WORD localPort = 161,
262
PINDEX timeout = 5000,
263
PINDEX rxSize = 10000,
264
PINDEX txSize = 10000);
265
266
~PSNMPServer
();
267
268
void
Main
();
269
270
void
SetVersion
(
PASNInt
newVersion);
271
PBoolean
HandleChannel
();
272
PBoolean
ProcessPDU
(
const
PBYTEArray
&
readBuffer
,
PBYTEArray
& writeBuffer);
273
274
virtual
PBoolean
Authorise
(
const
PIPSocket::Address
& received);
275
virtual
PBoolean
ConfirmVersion
(PASN_Integer vers);
276
virtual
PBoolean
ConfirmCommunity
(PASN_OctetString &
community
);
277
278
virtual
PBoolean
MIB_LocalMatch
(
PSNMP_PDU
& pdu);
279
280
virtual
PBoolean
OnGetRequest
(PINDEX reqID,
PSNMP::BindingList
& vars,
PSNMP::ErrorType
& errCode);
281
virtual
PBoolean
OnGetNextRequest
(PINDEX reqID,
PSNMP::BindingList
& vars,
PSNMP::ErrorType
& errCode);
282
virtual
PBoolean
OnSetRequest
(PINDEX reqID,
PSNMP::BindingList
& vars,
PSNMP::ErrorType
& errCode);
283
284
PSNMP::ErrorType
SendGetResponse
(
PSNMPVarBindingList
& vars);
285
286
protected
:
287
PThreadObj<PSNMPServer>
m_thread
;
288
PString
community
;
289
PASN_Integer
version
;
290
PINDEX
lastErrorIndex
;
291
ErrorType
lastErrorCode
;
292
PBYTEArray
readBuffer
;
293
PINDEX
maxRxSize
;
294
PINDEX
maxTxSize
;
295
PUDPSocket
*
baseSocket
;
296
PDictionary<PRFC1155_ObjectName, PRFC1155_ObjectSyntax>
objList
;
297
};
298
299
#endif // P_SNMP
300
301
#endif // PTLIB_PSNMP_H
302
303
304
// End Of File ///////////////////////////////////////////////////////////////
include
ptclib
psnmp.h
Generated on Fri Oct 10 2014 21:15:13 for PTLib by
1.8.3.1