com.adventnet.snmp.snmp2
Class Snmp3Message

java.lang.Object
  extended by com.adventnet.snmp.snmp2.SnmpMessage
      extended by com.adventnet.snmp.snmp2.Snmp3Message
All Implemented Interfaces:
java.io.Serializable

public class Snmp3Message
extends SnmpMessage
implements java.io.Serializable

This class encapsulates a v3 message. The message contains the version specifc pdu processing routines. Additional routines provide access to the security data, the security model specific constants etc..

See Also:
Serialized Form

Field Summary
(package private)  SnmpAPI API
           
static byte AUTH_NO_PRIV
          Used to specify that authenticated message be sent to the peer.
static byte AUTH_PRIV
          Used to specify that authentication and privacy are used in the communication with the peer.
(package private)  boolean authenticationFailed
           
(package private)  byte[] contextID
          The context ID associated with the message.
(package private)  byte[] contextName
          Context name associated with the message.
(package private)  byte msgFlags
          To store the decoded msgFlags on a received message
(package private)  int msgID
          Get snmp security model from the message.
(package private)  int msgMaxSize
           
static byte NO_AUTH_NO_PRIV
          Used to specify that both authentication and privacy should not be used.
(package private)  SecurityProvider provider
           
static byte REPORT_FLAG
          Used to specify that the report flag is set when request is sent out.
(package private)  SecurityModelEntry security
          The SecurityModelEntry reference for the message
(package private)  int securityModel
          SecurityModel associated with the message.
(package private)  byte[] securityName
           
 
Fields inherited from class com.adventnet.snmp.snmp2.SnmpMessage
alwaysEncode, asnParser, community, communityEnc, isDebug, messageVersion, msgVersion, pdu, writeCommunity
 
Constructor Summary
Snmp3Message()
           
Snmp3Message(byte[] message)
          Creates an Snmp3Message object initialised with the given byte array.
Snmp3Message(byte[] message, ProtocolOptions res_opt)
          Creates an Snmp3Message object initialised with the given byte array.
Snmp3Message(byte[] message, SecurityProvider securityprovider)
          Creates an Snmp3Message object initialised with the given byte array and security provider.
Snmp3Message(SnmpPDU p)
           
 
Method Summary
(package private)  int authenticate(SnmpSession session)
           
(package private)  void copy(Snmp3Message copy3Msg)
           
(package private)  boolean encode(SnmpSession session)
           
(package private)  void encodeMsgVersion()
           
 SnmpAPI getAPI()
           
 ASN1Parser getASNParser()
           
(package private)  byte[] getContextID()
          Get context ID associated with the message.
(package private)  byte[] getContextName()
          Get the context name associated with the message.
 byte getMsgFlags()
          Get the msgFlags field of the SNMP PDU.
 int getMsgID()
          Returns the message Id for the v3 packet.
 int getMsgMaxSize()
          Returns the max message size field of the SNMPV3 packet.
 SecurityModelEntry getSecurity()
          Get securityModel object is associated with the message.
 int getSecurityModel()
          Returns the securityModel assoicated with this message.
(package private)  byte[] getSecurityName()
          Return the securityModel independent securityName
 SecurityProvider getSecurityProvider()
           
(package private)  void init()
           
 boolean isAuthenticationFailed()
          Returns a boolean value based on whether V3 authentication has failed.
(package private)  void processMessage(SnmpSession session)
           
(package private)  void setContextID(byte[] id)
          Set context ID associated with the message.
(package private)  void setContextName(byte[] name)
          Set the context name associated with the message.
 void setMsgFlags(byte flags)
          This methods sets the message flags of the SNMPv3 message.
 void setMsgID(int id)
          Sets the message Id for the v3 packet
 void setMsgMaxSize(int size)
          Sets the message max size field for the SNMPV3 packet.
 void setSecurity(SecurityModelEntry entry, int modelNo)
          Set securityModel object is associated with the message.
(package private)  void setSecurityModel(int model)
          Set the securityModel to be associated with this message.
(package private)  void setSecurityName(byte[] name)
          Set the securityModel independent securityName.
 void setSecurityProvider(SecurityProvider provider)
           
 
Methods inherited from class com.adventnet.snmp.snmp2.SnmpMessage
authenticate, copy, encodeCommunity, getCommunity, getCommunityEncoding, getMsgVersion, getPDU, getWriteCommunity, setCommunity, setCommunityEncoding, setDebug, setMsgVersion, setReEncode, setWriteCommunity
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_AUTH_NO_PRIV

public static final byte NO_AUTH_NO_PRIV
Used to specify that both authentication and privacy should not be used.

See Also:
Constant Field Values

AUTH_NO_PRIV

public static final byte AUTH_NO_PRIV
Used to specify that authenticated message be sent to the peer.

See Also:
Constant Field Values

AUTH_PRIV

public static final byte AUTH_PRIV
Used to specify that authentication and privacy are used in the communication with the peer.

See Also:
Constant Field Values

REPORT_FLAG

public static final byte REPORT_FLAG
Used to specify that the report flag is set when request is sent out.

See Also:
Constant Field Values

msgFlags

byte msgFlags
To store the decoded msgFlags on a received message


msgID

int msgID
Get snmp security model from the message.


msgMaxSize

int msgMaxSize

security

SecurityModelEntry security
The SecurityModelEntry reference for the message


securityName

byte[] securityName

contextID

byte[] contextID
The context ID associated with the message.


contextName

byte[] contextName
Context name associated with the message.


securityModel

int securityModel
SecurityModel associated with the message.


provider

transient SecurityProvider provider

API

transient SnmpAPI API

authenticationFailed

boolean authenticationFailed
Constructor Detail

Snmp3Message

public Snmp3Message()

Snmp3Message

Snmp3Message(SnmpPDU p)

Snmp3Message

public Snmp3Message(byte[] message,
                    SecurityProvider securityprovider)
             throws SnmpException
Creates an Snmp3Message object initialised with the given byte array and security provider. This byte array is the PDU data to be decoded. * This method is used only to decode the received PDU data.

Throws:
SnmpException - is thrown upon error.

Snmp3Message

public Snmp3Message(byte[] message)
             throws SnmpException
Creates an Snmp3Message object initialised with the given byte array. This byte array is the PDU data to be decoded. This method is used only to decode the received PDU data and the API user is not advised to use this method.

Throws:
SnmpException - is thrown whenever error occurs.

Snmp3Message

public Snmp3Message(byte[] message,
                    ProtocolOptions res_opt)
             throws SnmpException
Creates an Snmp3Message object initialised with the given byte array. This byte array is the PDU data to be decoded. This method is used only to decode the received PDU data and the API user is not advised to use this method.

Throws:
SnmpException - is thrown whenever error occurs.
Method Detail

setMsgFlags

public void setMsgFlags(byte flags)
This methods sets the message flags of the SNMPv3 message. The "msgFlags" is an OCTET STRING of size one, as defined in the SNMPv3 message format. Of this one byte, only the least significant 3 bits are used.

The eight bits of this flag can be explained as follows:
 
 

NU NU NU NU NU R P A

NU - NOT USED
R     - Report bit. That is, if this bit is set to one, then the SNMPv3 entity that receives this message should respond back to the sender.
P     - Priv bit. That is, if this bit is set to one, then this SNMPv3 message uses privacy.
A     - Auth bit. That is, if this bit is set to one, then this SNMPv3 message uses authentication.

The Possible values for this msgFlags are
 
 

Value in Decimal R P A
0  0  0  0
1  0  0  1
3  0  1  1
4  1  0  0
5  1  0  1
7  1  1  1

There cannot be privacy without authentication, hence the values 2 and 6 cannot exist.
 
 
 

Parameters:
flags - the msgFlags value to set for this SNMPv3 message. If an invalid value is passed as argument to this method, then the method will return and the previous value will be retained.

getMsgFlags

public byte getMsgFlags()
Get the msgFlags field of the SNMP PDU.

Returns:
the messages flags field in the SNMPV3 message.

setMsgID

public void setMsgID(int id)
Sets the message Id for the v3 packet

Parameters:
id - The messageID to be set for the SNMPV3 request.

getMsgID

public int getMsgID()
Returns the message Id for the v3 packet.

Returns:
The messageID of the V3 packet to be sent or received.

setMsgMaxSize

public void setMsgMaxSize(int size)
Sets the message max size field for the SNMPV3 packet.

Parameters:
size - The maximum message size for the SNMPV3 packet.

getMsgMaxSize

public int getMsgMaxSize()
Returns the max message size field of the SNMPV3 packet.

Returns:
The maximum message size of the SNMPV3 packet.

getSecurity

public SecurityModelEntry getSecurity()
Get securityModel object is associated with the message.

Returns:
The securityModel reference maintained by this object.

setSecurity

public void setSecurity(SecurityModelEntry entry,
                        int modelNo)
Set securityModel object is associated with the message. The Snmp3Message creates a new securitymodel for decoding and encoding. This method sets the securitymodel reference

Parameters:
entry - The security model reference is to set the corresponding entry in the message.
modelNo - The securityModel no. is associated with the securit entry

setSecurityName

void setSecurityName(byte[] name)
Set the securityModel independent securityName.


getSecurityName

byte[] getSecurityName()
Return the securityModel independent securityName


setContextID

void setContextID(byte[] id)
Set context ID associated with the message.


getContextID

byte[] getContextID()
Get context ID associated with the message.


setContextName

void setContextName(byte[] name)
Set the context name associated with the message.


getContextName

byte[] getContextName()
Get the context name associated with the message.


setSecurityModel

void setSecurityModel(int model)
Set the securityModel to be associated with this message.


getSecurityModel

public int getSecurityModel()
Returns the securityModel assoicated with this message.


setSecurityProvider

public void setSecurityProvider(SecurityProvider provider)

getSecurityProvider

public SecurityProvider getSecurityProvider()

init

void init()

getASNParser

public ASN1Parser getASNParser()

getAPI

public SnmpAPI getAPI()

copy

void copy(Snmp3Message copy3Msg)

encode

boolean encode(SnmpSession session)
Overrides:
encode in class SnmpMessage

encodeMsgVersion

void encodeMsgVersion()
Overrides:
encodeMsgVersion in class SnmpMessage

isAuthenticationFailed

public boolean isAuthenticationFailed()
Returns a boolean value based on whether V3 authentication has failed. If the received SnmpV3 message fails in the authentication module which can be due to wrong digest or timeliness failure, then a flag is set to true. This method returns the status of the flag and is useful in the authenticate/callback method when the SnmpClient interface is implemented.

Returns:
True If the received SnmpV3 message fails in the authentication module, which can be due to wrong message digest or timeliness failure. Returns False otherwise.

authenticate

int authenticate(SnmpSession session)
Overrides:
authenticate in class SnmpMessage
Returns:
approptiate negative value in case authentication fails. positive value if successful. Returns 0 If authentication successful and command type != reportPDU. Returns 1 If authentication successful and command type = reportPDU. Returns -1 If authentication fails due to digest failure. Returns -2 If authentication fails due to timeliness failure. Returns -3 If some other reason.

processMessage

void processMessage(SnmpSession session)
              throws SnmpException
Throws:
SnmpException