FileDocCategorySizeDatePackage
SnmpEngineImpl.javaAPI DocJava SE 5 API14842Fri Aug 26 14:55:06 BST 2005com.sun.jmx.snmp.internal

SnmpEngineImpl

public class SnmpEngineImpl extends Object implements Serializable, com.sun.jmx.snmp.SnmpEngine
This engine is conformant with the RFC 2571. It is the main object within an SNMP entity (agent, manager...). To an engine is associated an {@link com.sun.jmx.snmp.SnmpEngineId}. The way the engineId is retrieved is linked to the way the engine is instantiated. See each SnmpEngine constructor for more details. An engine is composed of a set of sub systems {@link com.sun.jmx.snmp.internal.SnmpSubSystem}. An SNMP engine can contain a:
  • Message Processing Sub System : {@link com.sun.jmx.snmp.internal.SnmpMsgProcessingSubSystem}
  • Security Sub System : {@link com.sun.jmx.snmp.internal.SnmpSecuritySubSystem}
  • Access Control Sub System : {@link com.sun.jmx.snmp.internal.SnmpAccessControlSubSystem}

Each sub system contains a set of models. A model is an implementation of a particular treatement (eg: the User based Security Model defined in RFC 2574 is a functional element dealing with authentication and privacy).

Engine instantiation is based on a factory. This factory, implementing mandatorily {@link com.sun.jmx.snmp.SnmpEngineFactory SnmpEngineFactory} is set in the method setFactory.

This API is a Sun Microsystems internal API and is subject to change without notice.

since
1.5

Fields Summary
public static final int
noAuthNoPriv
Security level. No authentication, no privacy. Value is 0, as defined in RFC 2572
public static final int
authNoPriv
Security level. Authentication, no privacy. Value is 1, as defined in RFC 2572
public static final int
authPriv
Security level. Authentication, privacy. Value is 3, as defined in RFC 2572
public static final int
reportableFlag
Flag that indicates that a report is to be sent. Value is 4, as defined in RFC 2572
public static final int
authMask
Mask used to isolate authentication information within a message flag.
public static final int
privMask
Mask used to isolate privacy information within a message flag.
public static final int
authPrivMask
Mask used to isolate authentication and privacy information within a message flag.
private com.sun.jmx.snmp.SnmpEngineId
engineid
private com.sun.jmx.snmp.SnmpEngineFactory
factory
private long
startTime
private int
boot
private boolean
checkOid
private transient com.sun.jmx.snmp.SnmpUsmKeyHandler
usmKeyHandler
private transient SnmpLcd
lcd
private transient SnmpSecuritySubSystem
securitySub
private transient SnmpMsgProcessingSubSystem
messageSub
private transient SnmpAccessControlSubSystem
accessSub
String
dbgTag
Constructors Summary
public SnmpEngineImpl(com.sun.jmx.snmp.SnmpEngineFactory fact, SnmpLcd lcd, com.sun.jmx.snmp.SnmpEngineId engineid)
Constructor. A Local Configuration Datastore is passed to the engine. It will be used to store and retrieve data (engine Id, engine boots).

WARNING : The SnmpEngineId is computed as follow:

  • If an lcd file is provided containing the property "localEngineID", this property value is used.
  • .
  • If not, if the passed engineID is not null, this engine ID is used.
  • If not, a time based engineID is computed.
This constructor should be called by an SnmpEngineFactory. Don't call it directly.

param
fact The factory used to instantiate this engine.
param
lcd The local configuration datastore.
param
engineid The engine ID to use. If null is provided, an SnmpEngineId is computed using the current time.
throws
UnknownHostException Exception thrown, if the host name located in the property "localEngineID" is invalid.

	
	init(lcd, fact);
	initEngineID();
	if(this.engineid == null) {
	    if(engineid != null)
		this.engineid = engineid;
	    else
		this.engineid = SnmpEngineId.createEngineId();
	}
	lcd.storeEngineId(this.engineid);
	if(isTraceOn()) {
	    trace("SnmpEngine", "LOCAL ENGINE ID: " + this.engineid);
	}
    
public SnmpEngineImpl(com.sun.jmx.snmp.SnmpEngineFactory fact, SnmpLcd lcd, InetAddress address, int port)
Constructor. A Local Configuration Datastore is passed to the engine. It will be used to store and retrieve data (engine ID, engine boots).

WARNING : The SnmpEngineId is computed as follow:

  • If an lcd file is provided containing the property "localEngineID", this property value is used.
  • .
  • If not, the passed address and port are used to compute one.
This constructor should be called by an SnmpEngineFactory. Don't call it directly.

param
fact The factory used to instantiate this engine.
param
lcd The local configuration datastore.
param
port UDP port to use in order to calculate the engine ID.
param
address An IP address used to calculate the engine ID.
throws
UnknownHostException Exception thrown, if the host name located in the property "localEngineID" is invalid.

	init(lcd, fact);
	initEngineID();
	if(engineid == null)
	    engineid = SnmpEngineId.createEngineId(address, port);

	lcd.storeEngineId(engineid);
	
	if(isTraceOn()) {
	    trace("SnmpEngine", "LOCAL ENGINE ID: " + engineid + " / " +
		  "LOCAL ENGINE NB BOOTS: " + boot + " / " +
		  "LOCAL ENGINE START TIME: " + getEngineTime());
	}
    
public SnmpEngineImpl(com.sun.jmx.snmp.SnmpEngineFactory fact, SnmpLcd lcd, int port)
Constructor. A Local Configuration Datastore is passed to the engine. It will be used to store and retrieve data (engine ID, engine boots).

WARNING : The SnmpEngineId is computed as follow:

  • If an lcd file is provided containing the property "localEngineID", this property value is used.
  • .
  • If not, The passed port is used to compute one.
This constructor should be called by an SnmpEngineFactory. Don't call it directly.

param
fact The factory used to instantiate this engine.
param
lcd The local configuration datastore
param
port UDP port to use in order to calculate the engine ID.
throws
UnknownHostException Exception thrown, if the host name located in the property "localEngineID" is invalid.

	init(lcd, fact);
	initEngineID();
	if(engineid == null)
	   engineid = SnmpEngineId.createEngineId(port);

	lcd.storeEngineId(engineid);

	if(isTraceOn()) {
	    trace("SnmpEngine", "LOCAL ENGINE ID: " + engineid + " / " +
		  "LOCAL ENGINE NB BOOTS: " + boot + " / " +
		  "LOCAL ENGINE START TIME: " + getEngineTime());
	}
    
public SnmpEngineImpl(com.sun.jmx.snmp.SnmpEngineFactory fact, SnmpLcd lcd)
Constructor. A Local Configuration Datastore is passed to the engine. It will be used to store and retrieve data (engine ID, engine boots).

WARNING : The SnmpEngineId is computed as follow:

  • If an lcd file is provided containing the property "localEngineID", this property value is used.
  • .
  • If not, a time based engineID is computed.
When no configuration nor java property is set for the engine ID value, a unique time based engine ID will be generated. This constructor should be called by an SnmpEngineFactory. Don't call it directly.

param
fact The factory used to instantiate this engine.
param
lcd The local configuration datastore.

	init(lcd, fact);
	initEngineID();
	if(engineid == null)
	    engineid = SnmpEngineId.createEngineId();
	
	lcd.storeEngineId(engineid);


	if(isTraceOn()) {
	    trace("SnmpEngine", "LOCAL ENGINE ID: " + engineid + " / " +
		  "LOCAL ENGINE NB BOOTS: " + boot + " / " +
		  "LOCAL ENGINE START TIME: " + getEngineTime());
	}
    
Methods Summary
public synchronized voidactivateCheckOid()
Access Control will check the oids. By default is false.

	checkOid = true;
    
public static voidcheckSecurityLevel(byte msgFlags)
Checks the passed msg flags according to the rules specified in RFC 2572.

param
msgFlags The msg flags.

	int secLevel = msgFlags & SnmpDefinitions.authPriv;
	if((secLevel & SnmpDefinitions.privMask) != 0)
	    if((secLevel & SnmpDefinitions.authMask) == 0) {
		throw new SnmpBadSecurityLevelException("Security level:"+ 
							" noAuthPriv!!!");
	    }
    
public synchronized voiddeactivateCheckOid()
Access Control will not check the oids. By default is false.

	checkOid = false;
    
voiddebug(java.lang.String clz, java.lang.String func, java.lang.String info)

        Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_SNMP, clz, func, info);
    
voiddebug(java.lang.String clz, java.lang.String func, java.lang.Throwable exception)

        Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_SNMP, clz, func, exception);
    
voiddebug(java.lang.String func, java.lang.String info)

        debug(dbgTag, func, info);
    
voiddebug(java.lang.String func, java.lang.Throwable exception)

        debug(dbgTag, func, exception);
    
public SnmpAccessControlSubSystemgetAccessControlSubSystem()
Returns the Access Control Sub System.

return
The Access Control Sub System.

	return accessSub;
    
public intgetEngineBoots()
Gets the engine boot number. This is the number of time this engine has rebooted. Each time an SnmpEngine is instantiated, it will read this value in its Lcd, and store back the value incremented by one.

return
The engine's number of reboot.

 
	return boot; 
    
public com.sun.jmx.snmp.SnmpEngineIdgetEngineId()
Gets the engine Id. This is unique for each engine.

return
The engine Id object.

	return engineid;
    
public synchronized intgetEngineTime()
Gets the engine time in seconds. This is the time from the last reboot.

return
The time from the last reboot.


                              
         
	//We do the counter wrap in a lazt way. Each time Engine is asked for his time it checks. So if nobody use the Engine, the time can wrap and wrap again without incrementing nb boot. We can imagine that it is irrelevant due to the amount of time needed to wrap.
	long delta = (System.currentTimeMillis() / 1000) - startTime;
	if(delta >  0x7FFFFFFF) {
	    //67 years of running. That is a great thing!
	    //Reinitialize startTime.
	    startTime = System.currentTimeMillis() / 1000;

	    //Can't do anything with this counter.
	    if(boot != 0x7FFFFFFF)
		boot += 1;
	    //Store for future use.
	    storeNBBoots(boot);
	}
	
	return (int) ((System.currentTimeMillis() / 1000) - startTime); 
    
public SnmpLcdgetLcd()
Gets the engine Lcd.

return
The engine Lcd.

	return lcd;
    
public SnmpMsgProcessingSubSystemgetMsgProcessingSubSystem()
Returns the Message Processing Sub System.

return
The Message Processing Sub System.

	return messageSub;
    
public SnmpSecuritySubSystemgetSecuritySubSystem()
Returns the Security Sub System.

return
The Security Sub System.

	return securitySub;
    
public com.sun.jmx.snmp.SnmpUsmKeyHandlergetUsmKeyHandler()
Gets the Usm key handler.

return
The key handler.

	return usmKeyHandler;
    
private voidinit(SnmpLcd lcd, com.sun.jmx.snmp.SnmpEngineFactory fact)

	this.factory = fact;
	this.lcd = lcd;
	boot = lcd.getEngineBoots();

	if(boot == -1 || boot == 0)
	    boot = 1;

	storeNBBoots(boot);

	startTime = System.currentTimeMillis() / 1000;

    
private voidinitEngineID()

	String id = lcd.getEngineId();
	if(id != null) {
	    engineid = SnmpEngineId.createEngineId(id);
	}
    
public synchronized booleanisCheckOidActivated()
Access Control check or not the oids. By default is false.

	return checkOid;
    
booleanisDebugOn()

        return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_SNMP);
    
booleanisTraceOn()

        return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_SNMP);
    
public voidsetAccessControlSubSystem(SnmpAccessControlSubSystem sys)
Sets the Access Control Sub System.

param
sys The Access Control Sub System.

	accessSub = sys;
    
public voidsetMsgProcessingSubSystem(SnmpMsgProcessingSubSystem sys)
Sets the Message Processing Sub System.

param
sys The Message Processing Sub System.

	messageSub = sys;
    
public voidsetSecuritySubSystem(SnmpSecuritySubSystem sys)
Sets the Security Sub System.

param
sys The Security Sub System.

	securitySub = sys;
    
voidsetUsmKeyHandler(com.sun.jmx.snmp.SnmpUsmKeyHandler usmKeyHandler)

	this.usmKeyHandler = usmKeyHandler;
    
private voidstoreNBBoots(int boot)

	if(boot < 0 || boot == 0x7FFFFFFF) {
	    boot = 0x7FFFFFFF;
	    lcd.storeEngineBoots(boot);
	}
	else
	    lcd.storeEngineBoots(boot + 1);
    
voidtrace(java.lang.String clz, java.lang.String func, java.lang.String info)

        Trace.send(Trace.LEVEL_TRACE, Trace.INFO_SNMP, clz, func, info);
    
voidtrace(java.lang.String func, java.lang.String info)

        trace(dbgTag, func, info);