blob: c0d5e19359d2fb0180133c0f53504d3db5fe3a19 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2000-2006 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package com.sun.jmx.snmp.agent;
27
28import java.util.Enumeration;
29import java.util.Vector;
30
31
32import com.sun.jmx.snmp.SnmpPdu;
33import com.sun.jmx.snmp.SnmpVarBind;
34import com.sun.jmx.snmp.SnmpEngine;
35
36/**
37 * This class implements the SnmpMibRequest interface.
38 * It represents the part of a SNMP request that involves a specific
39 * MIB. One instance of this class will be created for every MIB
40 * involved in a SNMP request, and will be passed to the SnmpMibAgent
41 * in charge of handling that MIB.
42 *
43 * Instances of this class are allocated by the SNMP engine. You will
44 * never need to use this class directly. You will only access
45 * instances of this class through their SnmpMibRequest interface.
46 *
47 */
48final class SnmpMibRequestImpl implements SnmpMibRequest {
49
50 /**
51 * @param engine The local engine.
52 * @param reqPdu The received pdu.
53 * @param vblist The vector of SnmpVarBind objects in which the
54 * MIB concerned by this request is involved.
55 * @param protocolVersion The protocol version of the SNMP request.
56 * @param userData User allocated contextual data. This object must
57 * be allocated on a per SNMP request basis through the
58 * SnmpUserDataFactory registered with the SnmpAdaptorServer,
59 * and is handed back to the user through SnmpMibRequest objects.
60 */
61 public SnmpMibRequestImpl(SnmpEngine engine,
62 SnmpPdu reqPdu,
63 Vector<SnmpVarBind> vblist,
64 int protocolVersion,
65 Object userData,
66 String principal,
67 int securityLevel,
68 int securityModel,
69 byte[] contextName,
70 byte[] accessContextName) {
71 varbinds = vblist;
72 version = protocolVersion;
73 data = userData;
74 this.reqPdu = reqPdu;
75 this.engine = engine;
76 this.principal = principal;
77 this.securityLevel = securityLevel;
78 this.securityModel = securityModel;
79 this.contextName = contextName;
80 this.accessContextName = accessContextName;
81 }
82 // -------------------------------------------------------------------
83 // PUBLIC METHODS from SnmpMibRequest
84 // -------------------------------------------------------------------
85
86 /**
87 * Returns the local engine. This parameter is returned only if <CODE> SnmpV3AdaptorServer </CODE> is the adaptor receiving this request. Otherwise null is returned.
88 * @return the local engine.
89 */
90 public SnmpEngine getEngine() {
91 return engine;
92 }
93
94 /**
95 * Gets the incoming request principal. This parameter is returned only if <CODE> SnmpV3AdaptorServer </CODE> is the adaptor receiving this request. Otherwise null is returned.
96 * @return The request principal.
97 **/
98 public String getPrincipal() {
99 return principal;
100 }
101
102 /**
103 * Gets the incoming request security level. This level is defined in {@link com.sun.jmx.snmp.SnmpEngine SnmpEngine}. This parameter is returned only if <CODE> SnmpV3AdaptorServer </CODE> is the adaptor receiving this request. Otherwise -1 is returned.
104 * @return The security level.
105 */
106 public int getSecurityLevel() {
107 return securityLevel;
108 }
109 /**
110 * Gets the incoming request security model. This parameter is returned only if <CODE> SnmpV3AdaptorServer </CODE> is the adaptor receiving this request. Otherwise -1 is returned.
111 * @return The security model.
112 */
113 public int getSecurityModel() {
114 return securityModel;
115 }
116 /**
117 * Gets the incoming request context name. This parameter is returned only if <CODE> SnmpV3AdaptorServer </CODE> is the adaptor receiving this request. Otherwise null is returned.
118 * @return The context name.
119 */
120 public byte[] getContextName() {
121 return contextName;
122 }
123
124 /**
125 * Gets the incoming request context name used by Access Control Model in order to allow or deny the access to OIDs. This parameter is returned only if <CODE> SnmpV3AdaptorServer </CODE> is the adaptor receiving this request. Otherwise null is returned.
126 * @return The checked context.
127 */
128 public byte[] getAccessContextName() {
129 return accessContextName;
130 }
131
132 // -------------------------------------------------------------------
133 // Implements the method defined in SnmpMibRequest interface.
134 // See SnmpMibRequest for the java doc.
135 // -------------------------------------------------------------------
136 public final SnmpPdu getPdu() {
137 return reqPdu;
138 }
139
140 // -------------------------------------------------------------------
141 // Implements the method defined in SnmpMibRequest interface.
142 // See SnmpMibRequest for the java doc.
143 // -------------------------------------------------------------------
144 public final Enumeration getElements() {return varbinds.elements();}
145
146 // -------------------------------------------------------------------
147 // Implements the method defined in SnmpMibRequest interface.
148 // See SnmpMibRequest for the java doc.
149 // -------------------------------------------------------------------
150 public final Vector<SnmpVarBind> getSubList() {return varbinds;}
151
152 // -------------------------------------------------------------------
153 // Implements the method defined in SnmpMibRequest interface.
154 // See SnmpMibRequest for the java doc.
155 // -------------------------------------------------------------------
156 public final int getSize() {
157 if (varbinds == null) return 0;
158 return varbinds.size();
159 }
160
161 // -------------------------------------------------------------------
162 // Implements the method defined in SnmpMibRequest interface.
163 // See SnmpMibRequest for the java doc.
164 // -------------------------------------------------------------------
165 public final int getVersion() {return version;}
166
167 // -------------------------------------------------------------------
168 // Implements the method defined in SnmpMibRequest interface.
169 // See SnmpMibRequest for the java doc.
170 // -------------------------------------------------------------------
171 public final int getRequestPduVersion() {return reqPdu.version;}
172
173 // -------------------------------------------------------------------
174 // Implements the method defined in SnmpMibRequest interface.
175 // See SnmpMibRequest for the java doc.
176 // -------------------------------------------------------------------
177 public final Object getUserData() {return data;}
178
179 // -------------------------------------------------------------------
180 // Implements the method defined in SnmpMibRequest interface.
181 // See SnmpMibRequest for the java doc.
182 // -------------------------------------------------------------------
183 public final int getVarIndex(SnmpVarBind varbind) {
184 return varbinds.indexOf(varbind);
185 }
186
187 // -------------------------------------------------------------------
188 // Implements the method defined in SnmpMibRequest interface.
189 // See SnmpMibRequest for the java doc.
190 // -------------------------------------------------------------------
191 public void addVarBind(SnmpVarBind varbind) {
192 varbinds.addElement(varbind);
193 }
194
195 // -------------------------------------------------------------------
196 // PACKAGE METHODS
197 // -------------------------------------------------------------------
198
199 // -------------------------------------------------------------------
200 // Allow to pass the request tree built during the check() phase
201 // to the set() method. Note: the if the tree is `null', then the
202 // set() method will rebuild a new tree identical to the tree built
203 // in the check() method.
204 //
205 // Passing this tree in the SnmpMibRequestImpl object allows to
206 // optimize the SET requests.
207 //
208 // -------------------------------------------------------------------
209 final void setRequestTree(SnmpRequestTree tree) {this.tree = tree;}
210
211 // -------------------------------------------------------------------
212 // Returns the SnmpRequestTree object built in the first operation
213 // phase for two-phase SNMP requests (like SET).
214 // -------------------------------------------------------------------
215 final SnmpRequestTree getRequestTree() {return tree;}
216
217 // -------------------------------------------------------------------
218 // Returns the underlying vector of SNMP varbinds (used for algorithm
219 // optimization).
220 // -------------------------------------------------------------------
221 final Vector getVarbinds() {return varbinds;}
222
223 // -------------------------------------------------------------------
224 // Private variables
225 // -------------------------------------------------------------------
226
227 // Ideally these variables should be declared final but it makes
228 // the jdk1.1.x compiler complain (seems to be a compiler bug, jdk1.2
229 // is OK).
230 private Vector<SnmpVarBind> varbinds;
231 private int version;
232 private Object data;
233 private SnmpPdu reqPdu = null;
234 // Non final variable.
235 private SnmpRequestTree tree = null;
236 private SnmpEngine engine = null;
237 private String principal = null;
238 private int securityLevel = -1;
239 private int securityModel = -1;
240 private byte[] contextName = null;
241 private byte[] accessContextName = null;
242}