1. /*
  2. * @(#)file SnmpIncomingRequest.java
  3. * @(#)author Sun Microsystems, Inc.
  4. * @(#)version 1.20
  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. */
  11. package com.sun.jmx.snmp.internal;
  12. import java.net.InetAddress;
  13. import com.sun.jmx.snmp.SnmpSecurityParameters;
  14. import com.sun.jmx.snmp.SnmpTooBigException;
  15. import com.sun.jmx.snmp.SnmpStatusException;
  16. import com.sun.jmx.snmp.SnmpPdu;
  17. import com.sun.jmx.snmp.SnmpMsg;
  18. import com.sun.jmx.snmp.SnmpUnknownSecModelException;
  19. import com.sun.jmx.snmp.SnmpBadSecurityLevelException;
  20. /**
  21. <P> An <CODE>SnmpIncomingRequest</CODE> handles both sides of an incoming SNMP request:
  22. <ul>
  23. <li> The request. Unmarshalling of the received message. </li>
  24. <li> The response. Marshalling of the message to send. </li>
  25. </ul>
  26. * <p><b>This API is a Sun Microsystems internal API and is subject
  27. * to change without notice.</b></p>
  28. * @since 1.5
  29. */
  30. public interface SnmpIncomingRequest {
  31. /**
  32. * Once the incoming request decoded, returns the decoded security parameters.
  33. * @return The decoded security parameters.
  34. */
  35. public SnmpSecurityParameters getSecurityParameters();
  36. /**
  37. * Tests if a report is expected.
  38. * @return boolean indicating if a report is to be sent.
  39. */
  40. public boolean isReport();
  41. /**
  42. * Tests if a response is expected.
  43. * @return boolean indicating if a response is to be sent.
  44. */
  45. public boolean isResponse();
  46. /**
  47. * Tells this request that no response will be sent.
  48. */
  49. public void noResponse();
  50. /**
  51. * Gets the incoming request principal.
  52. * @return The request principal.
  53. **/
  54. public String getPrincipal();
  55. /**
  56. * Gets the incoming request security level. This level is defined in {@link com.sun.jmx.snmp.SnmpEngine SnmpEngine}.
  57. * @return The security level.
  58. */
  59. public int getSecurityLevel();
  60. /**
  61. * Gets the incoming request security model.
  62. * @return The security model.
  63. */
  64. public int getSecurityModel();
  65. /**
  66. * Gets the incoming request context name.
  67. * @return The context name.
  68. */
  69. public byte[] getContextName();
  70. /**
  71. * Gets the incoming request context engine Id.
  72. * @return The context engine Id.
  73. */
  74. public byte[] getContextEngineId();
  75. /**
  76. * Gets the incoming request context name used by Access Control Model in order to allow or deny the access to OIDs.
  77. */
  78. public byte[] getAccessContext();
  79. /**
  80. * Encodes the response message to send and puts the result in the specified byte array.
  81. *
  82. * @param outputBytes An array to receive the resulting encoding.
  83. *
  84. * @exception ArrayIndexOutOfBoundsException If the result does not fit
  85. * into the specified array.
  86. */
  87. public int encodeMessage(byte[] outputBytes)
  88. throws SnmpTooBigException;
  89. /**
  90. * Decodes the specified bytes and initializes the request with the incoming message.
  91. *
  92. * @param inputBytes The bytes to be decoded.
  93. *
  94. * @exception SnmpStatusException If the specified bytes are not a valid encoding or if the security applied to this request failed and no report is to be sent (typically trap PDU).
  95. */
  96. public void decodeMessage(byte[] inputBytes,
  97. int byteCount,
  98. InetAddress address,
  99. int port)
  100. throws SnmpStatusException, SnmpUnknownSecModelException,
  101. SnmpBadSecurityLevelException;
  102. /**
  103. * Initializes the response to send with the passed Pdu.
  104. * <P>
  105. * If the encoding length exceeds <CODE>maxDataLength</CODE>,
  106. * the method throws an exception.
  107. *
  108. * @param p The PDU to be encoded.
  109. * @param maxDataLength The maximum length permitted for the data field.
  110. *
  111. * @exception SnmpStatusException If the specified <CODE>pdu</CODE>
  112. * is not valid.
  113. * @exception SnmpTooBigException If the resulting encoding does not fit
  114. * into <CODE>maxDataLength</CODE> bytes.
  115. * @exception ArrayIndexOutOfBoundsException If the encoding exceeds
  116. * <CODE>maxDataLength</CODE>.
  117. */
  118. public SnmpMsg encodeSnmpPdu(SnmpPdu p,
  119. int maxDataLength)
  120. throws SnmpStatusException, SnmpTooBigException;
  121. /**
  122. * Gets the request PDU encoded in the received message.
  123. * <P>
  124. * This method decodes the data field and returns the resulting PDU.
  125. *
  126. * @return The resulting PDU.
  127. * @exception SnmpStatusException If the encoding is not valid.
  128. */
  129. public SnmpPdu decodeSnmpPdu()
  130. throws SnmpStatusException;
  131. /**
  132. * Returns a stringified form of the received message.
  133. * @return The message state string.
  134. */
  135. public String printRequestMessage();
  136. /**
  137. * Returns a stringified form of the message to send.
  138. * @return The message state string.
  139. */
  140. public String printResponseMessage();
  141. }