1 /*
   2  * Copyright (c) 2001, 2003, 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.internal;
  26 
  27 import java.util.Vector;
  28 import com.sun.jmx.snmp.SnmpMsg;
  29 import com.sun.jmx.snmp.SnmpParams;
  30 import com.sun.jmx.snmp.SnmpPdu;
  31 import com.sun.jmx.snmp.SnmpVarBind;
  32 import com.sun.jmx.snmp.SnmpStatusException;
  33 import com.sun.jmx.snmp.SnmpTooBigException;
  34 import com.sun.jmx.snmp.SnmpPduFactory;
  35 import com.sun.jmx.snmp.SnmpSecurityParameters;
  36 
  37 import com.sun.jmx.snmp.SnmpUnknownMsgProcModelException;
  38 
  39 /**
  40  * Message processing sub system interface. To allow engine integration, a message processing sub system must implement this interface. This sub system is called by the dispatcher when receiving or sending calls.
  41  * <p><b>This API is a Sun Microsystems internal API  and is subject
  42  * to change without notice.</b></p>
  43  * @since 1.5
  44  */
  45 public interface SnmpMsgProcessingSubSystem extends SnmpSubSystem {
  46 
  47     /**
  48      * Attaches the security sub system to this sub system. Message processing model are making usage of various security sub systems. This direct attachement avoid the need of accessing the engine to retrieve the Security sub system.
  49      * @param security The security sub system.
  50      */
  51     public void setSecuritySubSystem(SnmpSecuritySubSystem security);
  52     /** Gets the attached security sub system.
  53      * @return The security sub system.
  54      */
  55     public SnmpSecuritySubSystem getSecuritySubSystem();
  56 
  57     /**
  58      * This method is called when a call is received from the network.
  59      * @param model The model ID.
  60      * @param factory The pdu factory to use to encode and decode pdu.
  61      * @return The object that will handle every steps of the receiving (mainly unmarshalling and security).
  62      */
  63     public SnmpIncomingRequest getIncomingRequest(int model,
  64                                                   SnmpPduFactory factory)
  65         throws SnmpUnknownMsgProcModelException;
  66     /**
  67      * This method is called when a call is to be sent to the network. The sub system routes the call to the dedicated model according to the model ID.
  68      * @param model The model ID.
  69      * @param factory The pdu factory to use to encode and decode pdu.
  70      * @return The object that will handle every steps of the sending (mainly marshalling and security).
  71      */
  72     public SnmpOutgoingRequest getOutgoingRequest(int model,
  73                                                   SnmpPduFactory factory) throws SnmpUnknownMsgProcModelException ;
  74     /**
  75      * This method is called to instantiate a pdu according to the passed pdu type and parameters. The sub system routes the call to the dedicated model according to the model ID.
  76      * @param model The model ID.
  77      * @param p The request parameters.
  78      * @param type The pdu type.
  79      * @return The pdu.
  80      */
  81     public SnmpPdu getRequestPdu(int model, SnmpParams p, int type) throws SnmpUnknownMsgProcModelException, SnmpStatusException ;
  82      /**
  83      * This method is called when a call is received from the network. The sub system routes the call to the dedicated model according to the model ID.
  84      * @param model The model ID.
  85      * @param factory The pdu factory to use to decode pdu.
  86      * @return The object that will handle every steps of the receiving (mainly marshalling and security).
  87      */
  88     public SnmpIncomingResponse getIncomingResponse(int model,
  89                                                     SnmpPduFactory factory) throws SnmpUnknownMsgProcModelException;
  90     /**
  91      * This method is called to encode a full scoped pdu that as not been encrypted. <CODE>contextName</CODE>, <CODE>contextEngineID</CODE> and data are known. It will be routed to the dedicated model according to the version value.
  92      * <BR>The specified parameters are defined in RFC 2572 (see also the {@link com.sun.jmx.snmp.SnmpV3Message} class).
  93      * @param version The SNMP protocol version.
  94      * @param msgID The SNMP message ID.
  95      * @param msgMaxSize The max message size.
  96      * @param msgFlags The message flags.
  97      * @param msgSecurityModel The message security model.
  98      * @param params The security parameters.
  99      * @param contextEngineID The context engine ID.
 100      * @param contextName The context name.
 101      * @param data The encoded data.
 102      * @param dataLength The encoded data length.
 103      * @param outputBytes The buffer containing the encoded message.
 104      * @return The encoded bytes number.
 105      */
 106     public int encode(int version,
 107                       int msgID,
 108                       int msgMaxSize,
 109                       byte msgFlags,
 110                       int msgSecurityModel,
 111                       SnmpSecurityParameters params,
 112                       byte[] contextEngineID,
 113                       byte[] contextName,
 114                       byte[] data,
 115                       int dataLength,
 116                       byte[] outputBytes)
 117         throws SnmpTooBigException,
 118                SnmpUnknownMsgProcModelException ;
 119     /**
 120      * This method is called to encode a full scoped pdu that as been encrypted. <CODE>contextName</CODE>, <CODE>contextEngineID</CODE> and data are not known. It will be routed to the dedicated model according to the version value.
 121      * <BR>The specified parameters are defined in RFC 2572 (see also the {@link com.sun.jmx.snmp.SnmpV3Message} class).
 122      * @param version The SNMP protocol version.
 123      * @param msgID The SNMP message ID.
 124      * @param msgMaxSize The max message size.
 125      * @param msgFlags The message flags.
 126      * @param msgSecurityModel The message security model.
 127      * @param params The security parameters.
 128      * @param encryptedPdu The encrypted pdu.
 129      * @param outputBytes The buffer containing the encoded message.
 130      * @return The encoded bytes number.
 131      */
 132     public int encodePriv(int version,
 133                           int msgID,
 134                           int msgMaxSize,
 135                           byte msgFlags,
 136                           int msgSecurityModel,
 137                           SnmpSecurityParameters params,
 138                           byte[] encryptedPdu,
 139                           byte[] outputBytes) throws SnmpTooBigException, SnmpUnknownMsgProcModelException;
 140 
 141      /**
 142      * 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. It will be routed to the dedicated model according to the version value.
 143      * @param version The SNMP protocol version.
 144      * @param pdu The encoded pdu.
 145      * @return the partialy scoped pdu.
 146      */
 147     public SnmpDecryptedPdu decode(int version,
 148                                    byte[] pdu)
 149         throws SnmpStatusException, SnmpUnknownMsgProcModelException;
 150 
 151       /**
 152      * This method returns an encoded scoped pdu. This method encodes only the <CODE>contextEngineID</CODE>, <CODE>contextName</CODE> and data. It is needed by the <CODE>SnmpSecurityModel</CODE> for decryption. It will be routed to the dedicated model according to the version value.
 153      * @param version The SNMP protocol version.
 154      * @param pdu The pdu to encode.
 155      * @param outputBytes The partialy scoped pdu.
 156      * @return The encoded bytes number.
 157      */
 158     public int encode(int version,
 159                       SnmpDecryptedPdu pdu,
 160                       byte[] outputBytes)
 161         throws SnmpTooBigException, SnmpUnknownMsgProcModelException;
 162 }