Source Code Cross Referenced for SNMPv2InformRequestPDU.java in  » JMX » jmanage » snmp » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » JMX » jmanage » snmp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * SNMP Package
003:         *
004:         * Copyright (C) 2004, Jonathan Sevy <jsevy@mcs.drexel.edu>
005:         *
006:         * This is free software. Redistribution and use in source and binary forms, with
007:         * or without modification, are permitted provided that the following conditions
008:         * are met:
009:         *
010:         *  1. Redistributions of source code must retain the above copyright notice, this
011:         *     list of conditions and the following disclaimer.
012:         *  2. Redistributions in binary form must reproduce the above copyright notice,
013:         *     this list of conditions and the following disclaimer in the documentation 
014:         *     and/or other materials provided with the distribution.
015:         *  3. The name of the author may not be used to endorse or promote products 
016:         *     derived from this software without specific prior written permission.
017:         *
018:         * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
019:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
020:         * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 
021:         * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
023:         * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
024:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
025:         * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
026:         * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027:         *
028:         */
029:
030:        package snmp;
031:
032:        /**
033:         *    The SNMPv2InformRequestPDU class represents an SNMPv2 Trap PDU from RFC 1448, as indicated below. This
034:         *    forms the payload of an SNMPv2 Inform Request message.
035:
036:         -- protocol data units
037:
038:         3.  Definitions
039:
040:         SNMPv2-PDU DEFINITIONS ::= BEGIN
041:
042:         IMPORTS
043:         ObjectName, ObjectSyntax, Integer32
044:         FROM SNMPv2-SMI;
045:
046:         -- protocol data units
047:
048:         PDUs ::=
049:         CHOICE {
050:         get-request
051:         GetRequest-PDU,
052:
053:         get-next-request
054:         GetNextRequest-PDU,
055:
056:         get-bulk-request
057:         GetBulkRequest-PDU,
058:
059:         response
060:         Response-PDU,
061:
062:         set-request
063:         SetRequest-PDU,
064:
065:         inform-request
066:         InformRequest-PDU,
067:
068:         snmpV2-trap
069:         SNMPv2-Trap-PDU
070:         }
071:
072:        
073:         -- PDUs
074:
075:         GetRequest-PDU ::=
076:         [0]
077:         IMPLICIT PDU
078:
079:         GetNextRequest-PDU ::=
080:         [1]
081:         IMPLICIT PDU
082:
083:         Response-PDU ::=
084:         [2]
085:         IMPLICIT PDU
086:
087:         SetRequest-PDU ::=
088:         [3]
089:         IMPLICIT PDU
090:
091:         -- [4] is obsolete
092:
093:         GetBulkRequest-PDU ::=
094:         [5]
095:         IMPLICIT BulkPDU
096:
097:         InformRequest-PDU ::=
098:         [6]
099:         IMPLICIT PDU
100:
101:         SNMPv2-Trap-PDU ::=
102:         [7]
103:         IMPLICIT PDU
104:
105:        
106:         max-bindings
107:         INTEGER ::= 2147483647
108:
109:         PDU ::=
110:         SEQUENCE {
111:         request-id
112:         Integer32,
113:
114:         error-status            -- sometimes ignored
115:         INTEGER {
116:         noError(0),
117:         tooBig(1),
118:         noSuchName(2),   -- for proxy compatibility
119:         badValue(3),     -- for proxy compatibility
120:         readOnly(4),     -- for proxy compatibility
121:         genErr(5),
122:         noAccess(6),
123:         wrongType(7),
124:         wrongLength(8),
125:         wrongEncoding(9),
126:         wrongValue(10),
127:         noCreation(11),
128:         inconsistentValue(12),
129:         resourceUnavailable(13),
130:         commitFailed(14),
131:         undoFailed(15),
132:         authorizationError(16),
133:         notWritable(17),
134:         inconsistentName(18)
135:         },
136:
137:         error-index            -- sometimes ignored
138:         INTEGER (0..max-bindings),
139:
140:         variable-bindings   -- values are sometimes ignored
141:         VarBindList
142:         }
143:
144:         */
145:
146:        public class SNMPv2InformRequestPDU extends SNMPPDU {
147:
148:            /**
149:             *    Create a new Inform Request PDU with given trapOID and sysUptime,
150:             *    and containing the supplied SNMP sequence as data.
151:             */
152:
153:            public SNMPv2InformRequestPDU(SNMPTimeTicks sysUptime,
154:                    SNMPObjectIdentifier snmpTrapOID, SNMPSequence varList)
155:                    throws SNMPBadValueException {
156:                super (SNMPBERCodec.SNMPv2INFORMREQUEST, 0, 0, 0, varList);
157:
158:                // create a variable pair for sysUptime, and insert into varBindList
159:                SNMPObjectIdentifier sysUptimeOID = new SNMPObjectIdentifier(
160:                        "1.3.6.1.2.1.1.3.0");
161:                SNMPVariablePair sysUptimePair = new SNMPVariablePair(
162:                        sysUptimeOID, sysUptime);
163:                varList.insertSNMPObjectAt(sysUptimePair, 0);
164:
165:                // create a variable pair for snmpTrapOID, and insert into varBindList
166:                SNMPObjectIdentifier snmpTrapOIDOID = new SNMPObjectIdentifier(
167:                        "1.3.6.1.6.3.1.1.4.1.0");
168:                SNMPVariablePair snmpOIDPair = new SNMPVariablePair(
169:                        snmpTrapOIDOID, snmpTrapOID);
170:                varList.insertSNMPObjectAt(snmpOIDPair, 1);
171:
172:            }
173:
174:            /**
175:             *    Create a new Inform Request PDU with given trapOID and sysUptime,
176:             *    and containing an empty SNMP sequence (VarBindList) as additional data.
177:             */
178:
179:            public SNMPv2InformRequestPDU(SNMPObjectIdentifier snmpTrapOID,
180:                    SNMPTimeTicks sysUptime) throws SNMPBadValueException {
181:                this (sysUptime, snmpTrapOID, new SNMPSequence());
182:            }
183:
184:            /**
185:             *    Create a new PDU of the specified type from the supplied BER encoding.
186:             *    @throws SNMPBadValueException Indicates invalid SNMP PDU encoding supplied in enc.
187:             */
188:
189:            protected SNMPv2InformRequestPDU(byte[] enc)
190:                    throws SNMPBadValueException {
191:                super (enc, SNMPBERCodec.SNMPv2INFORMREQUEST);
192:
193:                // validate the message: make sure the first two components of the varBindList
194:                // are the appropriate variable pairs
195:                SNMPSequence varBindList = this .getVarBindList();
196:
197:                if (varBindList.size() < 2) {
198:                    throw new SNMPBadValueException(
199:                            "Bad v2 Inform Request PDU: missing snmpTrapOID or sysUptime");
200:                }
201:
202:                // validate that the first variable binding is the sysUptime
203:                SNMPSequence variablePair = (SNMPSequence) varBindList
204:                        .getSNMPObjectAt(0);
205:                SNMPObjectIdentifier oid = (SNMPObjectIdentifier) variablePair
206:                        .getSNMPObjectAt(0);
207:                SNMPObject value = variablePair.getSNMPObjectAt(1);
208:                SNMPObjectIdentifier sysUptimeOID = new SNMPObjectIdentifier(
209:                        "1.3.6.1.2.1.1.3.0");
210:                if (!(value instanceof  SNMPTimeTicks)
211:                        || !oid.equals(sysUptimeOID)) {
212:                    throw new SNMPBadValueException(
213:                            "Bad v2 Inform Request PDU: bad sysUptime in variable binding list");
214:                }
215:
216:                // validate that the second variable binding is the snmpTrapOID
217:                variablePair = (SNMPSequence) varBindList.getSNMPObjectAt(1);
218:                oid = (SNMPObjectIdentifier) variablePair.getSNMPObjectAt(0);
219:                value = variablePair.getSNMPObjectAt(1);
220:                SNMPObjectIdentifier snmpTrapOIDOID = new SNMPObjectIdentifier(
221:                        "1.3.6.1.6.3.1.1.4.1.0");
222:                if (!(value instanceof  SNMPObjectIdentifier)
223:                        || !oid.equals(snmpTrapOIDOID)) {
224:                    throw new SNMPBadValueException(
225:                            "Bad v2 Inform Request PDU: bad snmpTrapOID in variable binding list");
226:                }
227:
228:            }
229:
230:            /** 
231:             *    A utility method that extracts the snmpTrapOID from the variable bind list (it's the second of the 
232:             *    variable pairs).
233:             */
234:
235:            public SNMPObjectIdentifier getSNMPTrapOID() {
236:                SNMPSequence contents = this .getVarBindList();
237:                SNMPSequence variablePair = (SNMPSequence) contents
238:                        .getSNMPObjectAt(1);
239:                return (SNMPObjectIdentifier) variablePair.getSNMPObjectAt(1);
240:            }
241:
242:            /** 
243:             *    A utility method that extracts the sysUptime from the variable bind list (it's the first of the 
244:             *    variable pairs).
245:             */
246:
247:            public SNMPTimeTicks getSysUptime() {
248:                SNMPSequence contents = this .getVarBindList();
249:                SNMPSequence variablePair = (SNMPSequence) contents
250:                        .getSNMPObjectAt(0);
251:                return (SNMPTimeTicks) variablePair.getSNMPObjectAt(1);
252:            }
253:
254:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.