- java.lang.Object
-
- org.snmp4j.agent.BaseAgent
-
- org.snmp4j.agent.test.TestAgent
-
- All Implemented Interfaces:
java.lang.Runnable
public class TestAgent extends BaseAgent
TheTestAgentis a sample SNMP agent implementation of all features (MIB implementations) provided by the SNMP4J-Agent framework. TheTestAgentextends theBaseAgentwhich provides a framework for custom agent implementations through hook methods. Those abstract hook methods need to be implemented by extending theBaseAgent.This IF-MIB implementation part of this test agent, is instrumentation as a simulation MIB. Thus, by changing the agentppSimMode (1.3.6.1.4.1.4976.2.1.1.0) from 'oper(1)' to 'config(2)' any object of the IF-MIB is writable and even creatable (columnar objects) via SNMP. Check it out!
- Version:
- 1.0
- Author:
- Frank Fock
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Stringaddress-
Fields inherited from class org.snmp4j.agent.BaseAgent
agent, agentState, bootCounterFile, configFileURI, defaultContext, defaultPersistenceProvider, defaultProxyForwarder, dispatcher, mpv3, notificationOriginator, server, session, snmp4jConfigMIB, snmp4jLogMIB, snmpCommunityMIB, snmpFrameworkMIB, snmpMpdMib, snmpNotificationMIB, snmpProxyMIB, snmpTargetMIB, snmpv2MIB, STATE_CREATED, STATE_INIT_FINISHED, STATE_INIT_STARTED, STATE_RUNNING, STATE_STOPPED, sysDescr, sysOID, sysServices, transportMappings, usm, usmMIB, vacmMIB
-
-
Constructor Summary
Constructors Constructor Description TestAgent(java.io.File bootCounterFile, java.io.File configFile)Creates the test agent with a file to read and store the boot counter and a file to read and store its configuration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddCommunities(SnmpCommunityMIB communityMIB)Adds community to security name mappings needed for SNMPv1 and SNMPv2c.protected voidaddNotificationTargets(SnmpTargetMIB targetMIB, SnmpNotificationMIB notificationMIB)Adds initial notification targets and filters.protected voidaddUsmUser(org.snmp4j.security.USM usm)Adds all the necessary initial users to the USM.protected voidaddViews(VacmMIB vacm)Adds initial VACM configuration.protected voidinitTransportMappings()Initializes the transport mappings (ports) to be used by the agent.static voidmain(java.lang.String[] args)protected voidregisterManagedObjects()Register additional managed objects at the agent's server.protected voidregisterSnmpMIBs()Register the basic MIB modules at the agent'sMOServer.protected voidunregisterManagedObjects()Unregister additional managed objects from the agent's server.-
Methods inherited from class org.snmp4j.agent.BaseAgent
addShutdownHook, finishInit, getAgent, getAgentState, getBootCounterFile, getConfigFile, getContext, getDefaultContext, getDefaultProxyForwarder, getEngineBoots, getMPv3, getNotificationOriginator, getServer, getSession, getSnmp4jConfigMIB, getSnmp4jLogMIB, getSnmpCommunityMIB, getSnmpFrameworkMIB, getSnmpMpdMib, getSnmpNotificationMIB, getSnmpProxyMIB, getSnmpTargetMIB, getSnmpv2MIB, getSysDescr, getSysOID, getSysServices, getUsm, getUsmMIB, getVacmMIB, init, initConfigMIB, initMessageDispatcher, initSnmpSession, loadConfig, run, saveConfig, sendColdStartNotification, setAgent, setBootCounterFile, setConfigFile, setDefaultContext, setDefaultProxyForwarder, setSysDescr, setSysOID, setSysServices, setupDefaultProxyForwarder, stop, unregisterSnmpMIBs, updateEngineBoots, updateSession
-
-
-
-
Constructor Detail
-
TestAgent
public TestAgent(java.io.File bootCounterFile, java.io.File configFile) throws java.io.IOExceptionCreates the test agent with a file to read and store the boot counter and a file to read and store its configuration.- Parameters:
bootCounterFile- a file containing the boot counter in serialized form (as expected by BaseAgent).configFile- a configuration file with serialized management information.- Throws:
java.io.IOException- if the boot counter or config file cannot be read properly.
-
-
Method Detail
-
registerManagedObjects
protected void registerManagedObjects()
Description copied from class:BaseAgentRegister additional managed objects at the agent's server.- Specified by:
registerManagedObjectsin classBaseAgent
-
addNotificationTargets
protected void addNotificationTargets(SnmpTargetMIB targetMIB, SnmpNotificationMIB notificationMIB)
Description copied from class:BaseAgentAdds initial notification targets and filters.- Specified by:
addNotificationTargetsin classBaseAgent- Parameters:
targetMIB- the SnmpTargetMIB holding the target configuration.notificationMIB- the SnmpNotificationMIB holding the notification (filter) configuration.
-
addViews
protected void addViews(VacmMIB vacm)
Description copied from class:BaseAgentAdds initial VACM configuration.
-
addUsmUser
protected void addUsmUser(org.snmp4j.security.USM usm)
Description copied from class:BaseAgentAdds all the necessary initial users to the USM.- Specified by:
addUsmUserin classBaseAgent- Parameters:
usm- the USM instance used by this agent.
-
initTransportMappings
protected void initTransportMappings() throws java.io.IOExceptionDescription copied from class:BaseAgentInitializes the transport mappings (ports) to be used by the agent.- Overrides:
initTransportMappingsin classBaseAgent- Throws:
java.io.IOException- if an IO exception occurs while initializing the default transport mapping on all local IP addresses on port 161.
-
main
public static void main(java.lang.String[] args)
-
unregisterManagedObjects
protected void unregisterManagedObjects()
Description copied from class:BaseAgentUnregister additional managed objects from the agent's server.- Specified by:
unregisterManagedObjectsin classBaseAgent
-
addCommunities
protected void addCommunities(SnmpCommunityMIB communityMIB)
Description copied from class:BaseAgentAdds community to security name mappings needed for SNMPv1 and SNMPv2c.- Specified by:
addCommunitiesin classBaseAgent- Parameters:
communityMIB- the SnmpCommunityMIB holding coexistence configuration for community based security models.
-
registerSnmpMIBs
protected void registerSnmpMIBs()
Description copied from class:BaseAgentRegister the basic MIB modules at the agent'sMOServer.- Overrides:
registerSnmpMIBsin classBaseAgent
-
-