Package org.snmp4j.mp
Class MPv2c
java.lang.Object
org.snmp4j.mp.MPv2c
- All Implemented Interfaces:
 MessageProcessingModel
The 
MPv2c is the message processing model for SNMPv2c
 (community based SNMPv2).- Version:
 - 1.9.1
 - Author:
 - Frank Fock
 
- 
Field Summary
FieldsFields inherited from interface org.snmp4j.mp.MessageProcessingModel
MPv1, MPv2c, MPv2u, MPv3 - 
Constructor Summary
ConstructorsConstructorDescriptionMPv2c()Creates a SNMPv2c message processing model with a PDU factory for incoming messages that usesPDU.MPv2c(PDUFactory incomingPDUFactory) Creates a SNMPv2c message processing model with a custom PDU factory that must ignore the target parameter when creating a PDU for parsing incoming messages. - 
Method Summary
Modifier and TypeMethodDescriptionintgetID()Gets the numerical ID of the message processing model as defined by the constants in this interface or by an appropriate constant in the class implementing this interface.booleanisProtocolVersionSupported(int snmpProtocolVersion) Checks whether the supplied SNMP protocol version is supported by this message processing model.intprepareDataElements(MessageDispatcher messageDispatcher, Address transportAddress, BERInputStream wholeMsg, TransportStateReference tmStateReference, Integer32 messageProcessingModel, Integer32 securityModel, OctetString securityName, Integer32 securityLevel, MutablePDU pdu, PduHandle sendPduHandle, Integer32 maxSizeResponseScopedPDU, StatusInformation statusInformation, MutableStateReference mutableStateReference) Prepare data elements from an incoming SNMP message as described in RFC3412 §7.2.intprepareOutgoingMessage(Address transportAddress, int maxMessageSize, int messageProcessingModel, int securityModel, byte[] securityName, int securityLevel, PDU pdu, boolean expectResponse, PduHandle sendPduHandle, Address destTransportAddress, BEROutputStream outgoingMessage, TransportStateReference tmStateReference) Prepares an outgoing message as defined in RFC3412 §7.1.intprepareResponseMessage(int messageProcessingModel, int maxMessageSize, int securityModel, byte[] securityName, int securityLevel, PDU pdu, int maxSizeResponseScopedPDU, StateReference stateReference, StatusInformation statusInformation, BEROutputStream outgoingMessage) Prepares a response message as defined in RFC3412 §7.1.voidreleaseStateReference(PduHandle pduHandle) Release the state reference associated with the suppliedPduHandle. 
- 
Field Details
- 
ID
public static final int ID- See Also:
 
 - 
incomingPDUFactory
 
 - 
 - 
Constructor Details
- 
MPv2c
public MPv2c()Creates a SNMPv2c message processing model with a PDU factory for incoming messages that usesPDU. - 
MPv2c
Creates a SNMPv2c message processing model with a custom PDU factory that must ignore the target parameter when creating a PDU for parsing incoming messages.- Parameters:
 incomingPDUFactory- aPDUFactory. Ifnullthe default factory will be used which createsScopedPDUinstances.
 
 - 
 - 
Method Details
- 
getID
public int getID()Description copied from interface:MessageProcessingModelGets the numerical ID of the message processing model as defined by the constants in this interface or by an appropriate constant in the class implementing this interface.- Specified by:
 getIDin interfaceMessageProcessingModel- Returns:
 - a positive integer value.
 
 - 
prepareOutgoingMessage
public int prepareOutgoingMessage(Address transportAddress, int maxMessageSize, int messageProcessingModel, int securityModel, byte[] securityName, int securityLevel, PDU pdu, boolean expectResponse, PduHandle sendPduHandle, Address destTransportAddress, BEROutputStream outgoingMessage, TransportStateReference tmStateReference) throws IOException Description copied from interface:MessageProcessingModelPrepares an outgoing message as defined in RFC3412 §7.1.- Specified by:
 prepareOutgoingMessagein interfaceMessageProcessingModel- Parameters:
 transportAddress- the destination transportAddress.maxMessageSize- the maximum message size the transport mapping for the destination address is capable of.messageProcessingModel- theMessageProcessingModelID (typically, the SNMP version).securityModel- the security model ID (seeSecurityModel) to use.securityName- the principal on behalf the message is to be sent.securityLevel- the level of security requested (seeSecurityLevel).pdu- thePDUto send. For a SNMPv1 trappduhas to be aPDUv1instance, for SNMPv3 messages it has to be aScopedPDUinstance.expectResponse- indicates if a message expects a response. This has to betruefor confirmed class PDUs andfalseotherwise.sendPduHandle- thePduHandlethat uniquely identifies the sent message.destTransportAddress- returns the destination transport address (currently set always set totransportAddress.outgoingMessage- returns the message to send.tmStateReference- the transport model state reference as defined by RFC 5590.- Returns:
 - the status of the message preparation. 
SnmpConstants.SNMP_MP_OKis returned if on success, otherwise any of theSnmpConstants.SNMP_MP_*values may be returned. - Throws:
 IOException- if the supplied PDU could not be encoded to theoutgoingMessage
 - 
prepareResponseMessage
public int prepareResponseMessage(int messageProcessingModel, int maxMessageSize, int securityModel, byte[] securityName, int securityLevel, PDU pdu, int maxSizeResponseScopedPDU, StateReference stateReference, StatusInformation statusInformation, BEROutputStream outgoingMessage) throws IOException Description copied from interface:MessageProcessingModelPrepares a response message as defined in RFC3412 §7.1.- Specified by:
 prepareResponseMessagein interfaceMessageProcessingModel- Parameters:
 messageProcessingModel- int theMessageProcessingModelID (typically, the SNMP version).maxMessageSize- the maximum message size the transport mapping for the destination address is capable of.securityModel- the security model ID (seeSecurityModel) to use.securityName- the principal on behalf the message is to be sent.securityLevel- the level of security requested (seeSecurityLevel).pdu- thePDUto send. For a SNMPv1 trappduhas to be aPDUv1instance, for SNMPv3 messages it has to be aScopedPDUinstance.maxSizeResponseScopedPDU- the maximum size of the scoped PDU the sender (of the request) can accept.stateReference- reference to state information presented with the request.statusInformation- returns success or error indication. When an error occured, the error counter OID and value are included.outgoingMessage- returns the message to send.- Returns:
 - the status of the message preparation. 
SnmpConstants.SNMP_MP_OKis returned if on success, otherwise any of theSnmpConstants.SNMP_MP_*values may be returned. - Throws:
 IOException- if an internal error or a resource exception occured.
 - 
prepareDataElements
public int prepareDataElements(MessageDispatcher messageDispatcher, Address transportAddress, BERInputStream wholeMsg, TransportStateReference tmStateReference, Integer32 messageProcessingModel, Integer32 securityModel, OctetString securityName, Integer32 securityLevel, MutablePDU pdu, PduHandle sendPduHandle, Integer32 maxSizeResponseScopedPDU, StatusInformation statusInformation, MutableStateReference mutableStateReference) throws IOException Description copied from interface:MessageProcessingModelPrepare data elements from an incoming SNMP message as described in RFC3412 §7.2.- Specified by:
 prepareDataElementsin interfaceMessageProcessingModel- Parameters:
 messageDispatcher- theMessageDispatcherinstance to be used to send reports. Thus,messageDispatcheris typically the calling module.transportAddress- the origin transport address.wholeMsg- the whole message as received from the network.tmStateReference- the transport model state reference as defined by RFC 5590.messageProcessingModel- returns the message processing model (typically the SNMP version).securityModel- returns the security model ID (seeSecurityModel.securityName- returns the principal.securityLevel- returns the requested security level (seeSecurityLevel).pdu- returns SNMP protocol data unit (the payload of the received message).sendPduHandle- returns the handle to match request.maxSizeResponseScopedPDU- returns the maximum size of the scoped PDU the sender can accept.statusInformation- returns success or error indication. When an error occurred, the error counter OID and value are included.mutableStateReference- returns the state reference to be used for a possible response. On input the stateReference may contain information about the transport mapping of the incoming request. This allows theMessageProcessingModelto send reports over the same transport as it received them.- Returns:
 - int
   the status of the message preparation. 
SnmpConstants.SNMP_MP_OKis returned on success, otherwise any of theSnmpConstants.SNMP_MP_*values may be returned. - Throws:
 IOException- if the decoding of the message failed.
 - 
isProtocolVersionSupported
public boolean isProtocolVersionSupported(int snmpProtocolVersion) Description copied from interface:MessageProcessingModelChecks whether the supplied SNMP protocol version is supported by this message processing model.- Specified by:
 isProtocolVersionSupportedin interfaceMessageProcessingModel- Parameters:
 snmpProtocolVersion- the SNMP protocol version.- Returns:
 trueif the supplied SNMP protocol is supported,falseotherwise.
 - 
releaseStateReference
Description copied from interface:MessageProcessingModelRelease the state reference associated with the suppliedPduHandle.- Specified by:
 releaseStateReferencein interfaceMessageProcessingModel- Parameters:
 pduHandle- aPduHandle.
 
 -