1. /*
  2. * @(#)file SnmpMibRequestImpl.java
  3. * @(#)author Sun Microsystems, Inc.
  4. * @(#)version 1.14
  5. * @(#)date 04/09/15
  6. *
  7. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  8. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  9. */
  10. package com.sun.jmx.snmp.agent;
  11. import java.util.Enumeration;
  12. import java.util.Vector;
  13. import com.sun.jmx.snmp.SnmpPdu;
  14. import com.sun.jmx.snmp.SnmpVarBind;
  15. import com.sun.jmx.snmp.SnmpEngine;
  16. /**
  17. * This class implements the SnmpMibRequest interface.
  18. * It represents the part of a SNMP request that involves a specific
  19. * MIB. One instance of this class will be created for every MIB
  20. * involved in a SNMP request, and will be passed to the SnmpMibAgent
  21. * in charge of handling that MIB.
  22. *
  23. * Instances of this class are allocated by the SNMP engine. You will
  24. * never need to use this class directly. You will only access
  25. * instances of this class through their SnmpMibRequest interface.
  26. *
  27. */
  28. final class SnmpMibRequestImpl implements SnmpMibRequest {
  29. /**
  30. * @param engine The local engine.
  31. * @param reqPdu The received pdu.
  32. * @param vblist The vector of SnmpVarBind objects in which the
  33. * MIB concerned by this request is involved.
  34. * @param protocolVersion The protocol version of the SNMP request.
  35. * @param userData User allocated contextual data. This object must
  36. * be allocated on a per SNMP request basis through the
  37. * SnmpUserDataFactory registered with the SnmpAdaptorServer,
  38. * and is handed back to the user through SnmpMibRequest objects.
  39. */
  40. public SnmpMibRequestImpl(SnmpEngine engine,
  41. SnmpPdu reqPdu,
  42. Vector vblist,
  43. int protocolVersion,
  44. Object userData,
  45. String principal,
  46. int securityLevel,
  47. int securityModel,
  48. byte[] contextName,
  49. byte[] accessContextName) {
  50. varbinds = vblist;
  51. version = protocolVersion;
  52. data = userData;
  53. this.reqPdu = reqPdu;
  54. this.engine = engine;
  55. this.principal = principal;
  56. this.securityLevel = securityLevel;
  57. this.securityModel = securityModel;
  58. this.contextName = contextName;
  59. this.accessContextName = accessContextName;
  60. }
  61. // -------------------------------------------------------------------
  62. // PUBLIC METHODS from SnmpMibRequest
  63. // -------------------------------------------------------------------
  64. /**
  65. * Returns the local engine. This parameter is returned only if <CODE> SnmpV3AdaptorServer </CODE> is the adaptor receiving this request. Otherwise null is returned.
  66. * @return the local engine.
  67. */
  68. public SnmpEngine getEngine() {
  69. return engine;
  70. }
  71. /**
  72. * Gets the incoming request principal. This parameter is returned only if <CODE> SnmpV3AdaptorServer </CODE> is the adaptor receiving this request. Otherwise null is returned.
  73. * @return The request principal.
  74. **/
  75. public String getPrincipal() {
  76. return principal;
  77. }
  78. /**
  79. * 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.
  80. * @return The security level.
  81. */
  82. public int getSecurityLevel() {
  83. return securityLevel;
  84. }
  85. /**
  86. * 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.
  87. * @return The security model.
  88. */
  89. public int getSecurityModel() {
  90. return securityModel;
  91. }
  92. /**
  93. * 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.
  94. * @return The context name.
  95. */
  96. public byte[] getContextName() {
  97. return contextName;
  98. }
  99. /**
  100. * 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.
  101. * @return The checked context.
  102. */
  103. public byte[] getAccessContextName() {
  104. return accessContextName;
  105. }
  106. // -------------------------------------------------------------------
  107. // Implements the method defined in SnmpMibRequest interface.
  108. // See SnmpMibRequest for the java doc.
  109. // -------------------------------------------------------------------
  110. public final SnmpPdu getPdu() {
  111. return reqPdu;
  112. }
  113. // -------------------------------------------------------------------
  114. // Implements the method defined in SnmpMibRequest interface.
  115. // See SnmpMibRequest for the java doc.
  116. // -------------------------------------------------------------------
  117. public final Enumeration getElements() {return varbinds.elements();}
  118. // -------------------------------------------------------------------
  119. // Implements the method defined in SnmpMibRequest interface.
  120. // See SnmpMibRequest for the java doc.
  121. // -------------------------------------------------------------------
  122. public final Vector getSubList() {return varbinds;}
  123. // -------------------------------------------------------------------
  124. // Implements the method defined in SnmpMibRequest interface.
  125. // See SnmpMibRequest for the java doc.
  126. // -------------------------------------------------------------------
  127. public final int getSize() {
  128. if (varbinds == null) return 0;
  129. return varbinds.size();
  130. }
  131. // -------------------------------------------------------------------
  132. // Implements the method defined in SnmpMibRequest interface.
  133. // See SnmpMibRequest for the java doc.
  134. // -------------------------------------------------------------------
  135. public final int getVersion() {return version;}
  136. // -------------------------------------------------------------------
  137. // Implements the method defined in SnmpMibRequest interface.
  138. // See SnmpMibRequest for the java doc.
  139. // -------------------------------------------------------------------
  140. public final int getRequestPduVersion() {return reqPdu.version;}
  141. // -------------------------------------------------------------------
  142. // Implements the method defined in SnmpMibRequest interface.
  143. // See SnmpMibRequest for the java doc.
  144. // -------------------------------------------------------------------
  145. public final Object getUserData() {return data;}
  146. // -------------------------------------------------------------------
  147. // Implements the method defined in SnmpMibRequest interface.
  148. // See SnmpMibRequest for the java doc.
  149. // -------------------------------------------------------------------
  150. public final int getVarIndex(SnmpVarBind varbind) {
  151. return varbinds.indexOf(varbind);
  152. }
  153. // -------------------------------------------------------------------
  154. // Implements the method defined in SnmpMibRequest interface.
  155. // See SnmpMibRequest for the java doc.
  156. // -------------------------------------------------------------------
  157. public void addVarBind(SnmpVarBind varbind) {
  158. varbinds.addElement(varbind);
  159. }
  160. // -------------------------------------------------------------------
  161. // PACKAGE METHODS
  162. // -------------------------------------------------------------------
  163. // -------------------------------------------------------------------
  164. // Allow to pass the request tree built during the check() phase
  165. // to the set() method. Note: the if the tree is `null', then the
  166. // set() method will rebuild a new tree identical to the tree built
  167. // in the check() method.
  168. //
  169. // Passing this tree in the SnmpMibRequestImpl object allows to
  170. // optimize the SET requests.
  171. //
  172. // -------------------------------------------------------------------
  173. final void setRequestTree(SnmpRequestTree tree) {this.tree = tree;}
  174. // -------------------------------------------------------------------
  175. // Returns the SnmpRequestTree object built in the first operation
  176. // phase for two-phase SNMP requests (like SET).
  177. // -------------------------------------------------------------------
  178. final SnmpRequestTree getRequestTree() {return tree;}
  179. // -------------------------------------------------------------------
  180. // Returns the underlying vector of SNMP varbinds (used for algorithm
  181. // optimization).
  182. // -------------------------------------------------------------------
  183. final Vector getVarbinds() {return varbinds;}
  184. // -------------------------------------------------------------------
  185. // Private variables
  186. // -------------------------------------------------------------------
  187. // Ideally these variables should be declared final but it makes
  188. // the jdk1.1.x compiler complain (seems to be a compiler bug, jdk1.2
  189. // is OK).
  190. private Vector varbinds;
  191. private int version;
  192. private Object data;
  193. private SnmpPdu reqPdu = null;
  194. // Non final variable.
  195. private SnmpRequestTree tree = null;
  196. private SnmpEngine engine = null;
  197. private String principal = null;
  198. private int securityLevel = -1;
  199. private int securityModel = -1;
  200. private byte[] contextName = null;
  201. private byte[] accessContextName = null;
  202. }