SnmpEngineImplpublic class SnmpEngineImpl extends Object implements Serializable, com.sun.jmx.snmp.SnmpEngineThis 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. |
Fields Summary |
---|
public static final int | noAuthNoPrivSecurity level. No authentication, no privacy. Value is 0,
as defined in RFC 2572 | public static final int | authNoPrivSecurity level. Authentication, no privacy. Value is 1, as
defined in RFC 2572 | public static final int | authPrivSecurity level. Authentication, privacy. Value is 3,
as defined in RFC 2572 | public static final int | reportableFlagFlag that indicates that a report is to be sent. Value is 4, as defined in RFC 2572 | public static final int | authMaskMask used to isolate authentication information within a message flag. | public static final int | privMaskMask used to isolate privacy information within a message flag. | public static final int | authPrivMaskMask 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.
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.
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.
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.
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 void | activateCheckOid()Access Control will check the oids. By default is false.
checkOid = true;
| public static void | checkSecurityLevel(byte msgFlags)Checks the passed msg flags according to the rules specified in RFC 2572.
int secLevel = msgFlags & SnmpDefinitions.authPriv;
if((secLevel & SnmpDefinitions.privMask) != 0)
if((secLevel & SnmpDefinitions.authMask) == 0) {
throw new SnmpBadSecurityLevelException("Security level:"+
" noAuthPriv!!!");
}
| public synchronized void | deactivateCheckOid()Access Control will not check the oids. By default is false.
checkOid = false;
| void | debug(java.lang.String clz, java.lang.String func, java.lang.String info)
Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_SNMP, clz, func, info);
| void | debug(java.lang.String clz, java.lang.String func, java.lang.Throwable exception)
Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_SNMP, clz, func, exception);
| void | debug(java.lang.String func, java.lang.String info)
debug(dbgTag, func, info);
| void | debug(java.lang.String func, java.lang.Throwable exception)
debug(dbgTag, func, exception);
| public SnmpAccessControlSubSystem | getAccessControlSubSystem()Returns the Access Control Sub System.
return accessSub;
| public int | getEngineBoots()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 boot;
| public com.sun.jmx.snmp.SnmpEngineId | getEngineId()Gets the engine Id. This is unique for each engine.
return engineid;
| public synchronized int | getEngineTime()Gets the engine time in seconds. This is 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 SnmpLcd | getLcd()Gets the engine Lcd.
return lcd;
| public SnmpMsgProcessingSubSystem | getMsgProcessingSubSystem()Returns the Message Processing Sub System.
return messageSub;
| public SnmpSecuritySubSystem | getSecuritySubSystem()Returns the Security Sub System.
return securitySub;
| public com.sun.jmx.snmp.SnmpUsmKeyHandler | getUsmKeyHandler()Gets the Usm key handler.
return usmKeyHandler;
| private void | init(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 void | initEngineID()
String id = lcd.getEngineId();
if(id != null) {
engineid = SnmpEngineId.createEngineId(id);
}
| public synchronized boolean | isCheckOidActivated()Access Control check or not the oids. By default is false.
return checkOid;
| boolean | isDebugOn()
return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_SNMP);
| boolean | isTraceOn()
return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_SNMP);
| public void | setAccessControlSubSystem(SnmpAccessControlSubSystem sys)Sets the Access Control Sub System.
accessSub = sys;
| public void | setMsgProcessingSubSystem(SnmpMsgProcessingSubSystem sys)Sets the Message Processing Sub System.
messageSub = sys;
| public void | setSecuritySubSystem(SnmpSecuritySubSystem sys)Sets the Security Sub System.
securitySub = sys;
| void | setUsmKeyHandler(com.sun.jmx.snmp.SnmpUsmKeyHandler usmKeyHandler)
this.usmKeyHandler = usmKeyHandler;
| private void | storeNBBoots(int boot)
if(boot < 0 || boot == 0x7FFFFFFF) {
boot = 0x7FFFFFFF;
lcd.storeEngineBoots(boot);
}
else
lcd.storeEngineBoots(boot + 1);
| void | trace(java.lang.String clz, java.lang.String func, java.lang.String info)
Trace.send(Trace.LEVEL_TRACE, Trace.INFO_SNMP, clz, func, info);
| void | trace(java.lang.String func, java.lang.String info)
trace(dbgTag, func, info);
|
|