1. /*
  2. * @(#)file SnmpMsgProcessingModel.java
  3. * @(#)author Sun Microsystems, Inc.
  4. * @(#)version 1.19
  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 com.sun.jmx.snmp.mpm.SnmpMsgTranslator;
  13. import com.sun.jmx.snmp.SnmpTooBigException;
  14. import com.sun.jmx.snmp.SnmpStatusException;
  15. import com.sun.jmx.snmp.SnmpPdu;
  16. import com.sun.jmx.snmp.SnmpPduFactory;
  17. import com.sun.jmx.snmp.SnmpSecurityParameters;
  18. import com.sun.jmx.snmp.SnmpParams;
  19. /**
  20. * The message processing model interface. Any message processing model must implement this interface in order to be integrated in the engine framework.
  21. * The model is called by the dispatcher when a call is received or when a call is sent.
  22. * <p><b>This API is a Sun Microsystems internal API and is subject
  23. * to change without notice.</b></p>
  24. * @since 1.5
  25. */
  26. public interface SnmpMsgProcessingModel extends SnmpModel {
  27. /**
  28. * This method is called when a call is to be sent to the network.
  29. * @param factory The pdu factory to use to encode and decode pdu.
  30. * @return The object that will handle every steps of the sending (mainly marshalling and security).
  31. */
  32. public SnmpOutgoingRequest getOutgoingRequest(SnmpPduFactory factory);
  33. /**
  34. * This method is called when a call is received from the network.
  35. * @param factory The pdu factory to use to encode and decode pdu.
  36. * @return The object that will handle every steps of the receiving (mainly unmarshalling and security).
  37. */
  38. public SnmpIncomingRequest getIncomingRequest(SnmpPduFactory factory);
  39. /**
  40. * This method is called when a response is received from the network.
  41. * @param factory The pdu factory to use to encode and decode pdu.
  42. * @return The object that will handle every steps of the receiving (mainly unmarshalling and security).
  43. */
  44. public SnmpIncomingResponse getIncomingResponse(SnmpPduFactory factory);
  45. /**
  46. * This method is called to instantiate a pdu according to the passed pdu type and parameters.
  47. * @param p The request parameters.
  48. * @param type The pdu type.
  49. * @return The pdu.
  50. */
  51. public SnmpPdu getRequestPdu(SnmpParams p, int type) throws SnmpStatusException;
  52. /**
  53. * This method is called to encode a full scoped pdu that has not been encrypted. <CODE>contextName</CODE>, <CODE>contextEngineID</CODE> and data are known.
  54. * <BR>The specified parameters are defined in RFC 2572 (see also the {@link com.sun.jmx.snmp.SnmpV3Message} class).
  55. * @param version The SNMP protocol version.
  56. * @param msgID The SNMP message ID.
  57. * @param msgMaxSize The max message size.
  58. * @param msgFlags The message flags.
  59. * @param msgSecurityModel The message security model.
  60. * @param params The security parameters.
  61. * @param contextEngineID The context engine ID.
  62. * @param contextName The context name.
  63. * @param data The encoded data.
  64. * @param dataLength The encoded data length.
  65. * @param outputBytes The buffer containing the encoded message.
  66. * @return The encoded bytes number.
  67. */
  68. public int encode(int version,
  69. int msgID,
  70. int msgMaxSize,
  71. byte msgFlags,
  72. int msgSecurityModel,
  73. SnmpSecurityParameters params,
  74. byte[] contextEngineID,
  75. byte[] contextName,
  76. byte[] data,
  77. int dataLength,
  78. byte[] outputBytes) throws SnmpTooBigException;
  79. /**
  80. * This method is called to encode a full scoped pdu that as been encrypted. <CODE>contextName</CODE>, <CODE>contextEngineID</CODE> and data are known.
  81. * <BR>The specified parameters are defined in RFC 2572 (see also the {@link com.sun.jmx.snmp.SnmpV3Message} class).
  82. * @param version The SNMP protocol version.
  83. * @param msgID The SNMP message ID.
  84. * @param msgMaxSize The max message size.
  85. * @param msgFlags The message flags.
  86. * @param msgSecurityModel The message security model.
  87. * @param params The security parameters.
  88. * @param encryptedPdu The encrypted pdu.
  89. * @param outputBytes The buffer containing the encoded message.
  90. * @return The encoded bytes number.
  91. */
  92. public int encodePriv(int version,
  93. int msgID,
  94. int msgMaxSize,
  95. byte msgFlags,
  96. int msgSecurityModel,
  97. SnmpSecurityParameters params,
  98. byte[] encryptedPdu,
  99. byte[] outputBytes) throws SnmpTooBigException;
  100. /**
  101. * This method returns a decoded scoped pdu. This method decodes only the <CODE>contextEngineID</CODE>, <CODE>contextName</CODE> and data. It is needed by the <CODE>SnmpSecurityModel</CODE> after decryption.
  102. * @param pdu The encoded pdu.
  103. * @return The partialy scoped pdu.
  104. */
  105. public SnmpDecryptedPdu decode(byte[] pdu) throws SnmpStatusException;
  106. /**
  107. * This method returns an encoded scoped pdu. This method encode only the <CODE>contextEngineID</CODE>, <CODE>contextName</CODE> and data. It is needed by the <CODE>SnmpSecurityModel</CODE> for decryption.
  108. * @param pdu The pdu to encode.
  109. * @param outputBytes The partialy scoped pdu.
  110. * @return The encoded bytes number.
  111. */
  112. public int encode(SnmpDecryptedPdu pdu,
  113. byte[] outputBytes) throws SnmpTooBigException;
  114. /**
  115. * In order to change the behavior of the translator, set it.
  116. * @param translator The translator that will be used.
  117. */
  118. public void setMsgTranslator(SnmpMsgTranslator translator);
  119. /**
  120. * Returns the current translator.
  121. * @return The current translator.
  122. */
  123. public SnmpMsgTranslator getMsgTranslator();
  124. }