|
1 /* |
|
2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 */ |
|
25 package com.sun.jmx.snmp; |
|
26 |
|
27 |
|
28 import java.io.Serializable; |
|
29 import java.net.InetAddress; |
|
30 /** |
|
31 * Is the fully decoded representation of an SNMP packet. |
|
32 * <P> |
|
33 * Classes are derived from <CODE>SnmpPdu</CODE> to |
|
34 * represent the different forms of SNMP packets |
|
35 * ({@link com.sun.jmx.snmp.SnmpPduPacket SnmpPduPacket}, |
|
36 * {@link com.sun.jmx.snmp.SnmpScopedPduPacket SnmpScopedPduPacket}) |
|
37 * <BR>The <CODE>SnmpPdu</CODE> class defines the attributes |
|
38 * common to every form of SNMP packets. |
|
39 * |
|
40 * |
|
41 * <p><b>This API is a Sun Microsystems internal API and is subject |
|
42 * to change without notice.</b></p> |
|
43 * @see SnmpMessage |
|
44 * @see SnmpPduFactory |
|
45 * |
|
46 * @since 1.5 |
|
47 */ |
|
48 @SuppressWarnings("serial") // JDK implementation class |
|
49 public abstract class SnmpPdu implements SnmpDefinitions, Serializable { |
|
50 |
|
51 /** |
|
52 * PDU type. Types are defined in |
|
53 * {@link com.sun.jmx.snmp.SnmpDefinitions SnmpDefinitions}. |
|
54 * @serial |
|
55 */ |
|
56 public int type=0 ; |
|
57 |
|
58 /** |
|
59 * Protocol version. Versions are defined in |
|
60 * {@link com.sun.jmx.snmp.SnmpDefinitions SnmpDefinitions}. |
|
61 * @serial |
|
62 */ |
|
63 public int version=0 ; |
|
64 |
|
65 /** |
|
66 * List of variables. |
|
67 * @serial |
|
68 */ |
|
69 public SnmpVarBind[] varBindList ; |
|
70 |
|
71 |
|
72 /** |
|
73 * Request identifier. |
|
74 * Note that this field is not used by <CODE>SnmpPduTrap</CODE>. |
|
75 * @serial |
|
76 */ |
|
77 public int requestId=0 ; |
|
78 |
|
79 /** |
|
80 * Source or destination address. |
|
81 * <P>For an incoming PDU it's the source. |
|
82 * <BR>For an outgoing PDU it's the destination. |
|
83 * @serial |
|
84 */ |
|
85 public InetAddress address ; |
|
86 |
|
87 /** |
|
88 * Source or destination port. |
|
89 * <P>For an incoming PDU it's the source. |
|
90 * <BR>For an outgoing PDU it's the destination. |
|
91 * @serial |
|
92 */ |
|
93 public int port=0 ; |
|
94 |
|
95 /** |
|
96 * Returns the <CODE>String</CODE> representation of a PDU type. |
|
97 * For instance, if the PDU type is <CODE>SnmpDefinitions.pduGetRequestPdu</CODE>, |
|
98 * the method will return "SnmpGet". |
|
99 * @param cmd The integer representation of the PDU type. |
|
100 * @return The <CODE>String</CODE> representation of the PDU type. |
|
101 */ |
|
102 public static String pduTypeToString(int cmd) { |
|
103 switch (cmd) { |
|
104 case pduGetRequestPdu : |
|
105 return "SnmpGet" ; |
|
106 case pduGetNextRequestPdu : |
|
107 return "SnmpGetNext" ; |
|
108 case pduWalkRequest : |
|
109 return "SnmpWalk(*)" ; |
|
110 case pduSetRequestPdu : |
|
111 return "SnmpSet" ; |
|
112 case pduGetResponsePdu : |
|
113 return "SnmpResponse" ; |
|
114 case pduV1TrapPdu : |
|
115 return "SnmpV1Trap" ; |
|
116 case pduV2TrapPdu : |
|
117 return "SnmpV2Trap" ; |
|
118 case pduGetBulkRequestPdu : |
|
119 return "SnmpGetBulk" ; |
|
120 case pduInformRequestPdu : |
|
121 return "SnmpInform" ; |
|
122 } |
|
123 return "Unknown Command = " + cmd ; |
|
124 } |
|
125 } |