public class MockSnmpAgent extends org.snmp4j.agent.BaseAgent implements Runnable
MockSnmpAgent class extends the SNMP4J BaseAgent
class to provide a mock SNMP agent for SNMP-based OpenNMS tests.
Large chunks of code were lifted from the org.snmp4j.agent.test.TestAgent
class.| Modifier and Type | Class and Description |
|---|---|
static class |
MockSnmpAgent.MockUdpTransportMapping |
| Modifier and Type | Field and Description |
|---|---|
static boolean |
allowSetOnMissingOid |
agent, agentState, bootCounterFile, configFileURI, defaultContext, defaultPersistenceProvider, defaultProxyForwarder, dispatcher, mpv3, notificationOriginator, server, session, snmp4jConfigMIB, snmp4jLogMIB, snmpCommunityMIB, snmpFrameworkMIB, snmpNotificationMIB, snmpProxyMIB, snmpTargetMIB, snmpv2MIB, STATE_CREATED, STATE_INIT_FINISHED, STATE_INIT_STARTED, STATE_RUNNING, STATE_STOPPED, sysDescr, sysOID, sysServices, transportMappings, usm, usmMIB, vacmMIB| Constructor and Description |
|---|
MockSnmpAgent(File confFile,
URL moFile) |
MockSnmpAgent(File confFile,
URL moFile,
String bindAddress)
Creates the mock agent with files to read and store the boot counter,
to read and store the agent configuration, and to read the mocked
managed objects (MOs), plus a string describing the address and port
to bind to.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addCommunities(org.snmp4j.agent.mo.snmp.SnmpCommunityMIB communityMIB) |
protected void |
addNotificationTargets(org.snmp4j.agent.mo.snmp.SnmpTargetMIB targetMIB,
org.snmp4j.agent.mo.snmp.SnmpNotificationMIB notificationMIB) |
protected void |
addUsmUser(org.snmp4j.security.USM usm) |
protected void |
addViews(org.snmp4j.agent.mo.snmp.VacmMIB vacm) |
static MockSnmpAgent |
createAgentAndRun(URL moFile,
String bindAddress) |
protected List<org.snmp4j.agent.ManagedObject> |
createMockMOs() |
InetAddress |
getInetAddress() |
int |
getPort() |
void |
initConfigMIB() |
protected void |
initMessageDispatcher()
Note that this method can hang if your system entropy is not high enough.
|
void |
initSnmpSession() |
protected void |
initTransportMappings() |
boolean |
isRunning() |
boolean |
isStopped() |
static void |
main(String[] args) |
static AgentConfigData |
parseCli(String[] args) |
protected void |
registerManagedObjects() |
protected void |
registerSnmpMIBs() |
void |
run()
Starts the
MockSnmpAgent running. |
void |
setupDefaultProxyForwarder() |
void |
shutDown() |
void |
shutDownAndWait() |
String |
toString() |
protected void |
unregisterManagedObjects() |
protected void |
unregisterSnmpMIBs() |
void |
updateCounter32Value(String oid,
int val) |
void |
updateCounter64Value(String oid,
long val) |
void |
updateIntValue(String oid,
int val) |
void |
updateSession(org.snmp4j.Session session) |
void |
updateStringValue(String oid,
String val) |
void |
updateValue(org.snmp4j.smi.OID oid,
org.snmp4j.smi.Variable value) |
void |
updateValue(String oid,
org.snmp4j.smi.Variable value) |
void |
updateValuesFromResource(URL moFile) |
addShutdownHook, finishInit, getAgent, getAgentState, getBootCounterFile, getConfigFile, getContext, getDefaultContext, getDefaultProxyForwarder, getEngineBoots, getMPv3, getNotificationOriginator, getServer, getSession, getSnmp4jConfigMIB, getSnmp4jLogMIB, getSnmpCommunityMIB, getSnmpFrameworkMIB, getSnmpNotificationMIB, getSnmpProxyMIB, getSnmpTargetMIB, getSnmpv2MIB, getSysDescr, getSysOID, getSysServices, getUsm, getUsmMIB, getVacmMIB, init, loadConfig, saveConfig, sendColdStartNotification, setAgent, setBootCounterFile, setConfigFile, setDefaultContext, setDefaultProxyForwarder, setSysDescr, setSysOID, setSysServices, stop, updateEngineBootspublic MockSnmpAgent(File confFile, URL moFile, String bindAddress)
moFile - a MIB dump file describing the managed objects to be mocked. The current implementation
expects a Java properties file, which can conveniently be generated using the Net-SNMP
utility snmpwalk with the -One option set.public static MockSnmpAgent createAgentAndRun(URL moFile, String bindAddress) throws InterruptedException
InterruptedExceptionpublic static void main(String[] args) throws UnknownHostException, MalformedURLException
public static AgentConfigData parseCli(String[] args) throws UnknownHostException, MalformedURLException
protected void initMessageDispatcher()
Note that this method can hang if your system entropy is not high enough. Here is a stack trace from a test running on JDK 1.8u40:
Thread [MockSnmpAgent-1657048932] (Suspended) owns: SecureRandom (id=26) owns: SecureRandom (id=27) owns: SecurityProtocols (id=28) FileInputStream.readBytes(byte[], int, int) line: not available [native method] FileInputStream.read(byte[], int, int) line: 255 NativeSeedGenerator(SeedGenerator$URLSeedGenerator).getSeedBytes(byte[]) line: 539 SeedGenerator.generateSeed(byte[]) line: 144 SecureRandom$SeederHolder.() line: 203 [local variables unavailable] SecureRandom.engineNextBytes(byte[]) line: 221 SecureRandom.nextBytes(byte[]) line: 468 Salt. () line: 54 Salt.getInstance() line: 79 PrivDES. () line: 57 SecurityProtocols.addDefaultProtocols() line: 155 MockSnmpAgent.initMessageDispatcher() line: 306 MockSnmpAgent(BaseAgent).init() line: 145 MockSnmpAgent.run() line: 380 Thread.run() line: 745
initMessageDispatcher in class org.snmp4j.agent.BaseAgentpublic void initSnmpSession()
initSnmpSession in class org.snmp4j.agent.BaseAgentpublic void initConfigMIB()
initConfigMIB in class org.snmp4j.agent.BaseAgentpublic void setupDefaultProxyForwarder()
setupDefaultProxyForwarder in class org.snmp4j.agent.BaseAgentpublic void updateSession(org.snmp4j.Session session)
updateSession in class org.snmp4j.agent.BaseAgentpublic void shutDownAndWait()
throws InterruptedException
InterruptedExceptionpublic void run()
MockSnmpAgent running. Meant to be called from the
start method of class Thread, but could also be
used to bring up a standalone mock agent.public void shutDown()
public boolean isRunning()
public boolean isStopped()
protected void addCommunities(org.snmp4j.agent.mo.snmp.SnmpCommunityMIB communityMIB)
addCommunities in class org.snmp4j.agent.BaseAgentprotected void addViews(org.snmp4j.agent.mo.snmp.VacmMIB vacm)
addViews in class org.snmp4j.agent.BaseAgentprotected void addNotificationTargets(org.snmp4j.agent.mo.snmp.SnmpTargetMIB targetMIB,
org.snmp4j.agent.mo.snmp.SnmpNotificationMIB notificationMIB)
addNotificationTargets in class org.snmp4j.agent.BaseAgentprotected void addUsmUser(org.snmp4j.security.USM usm)
addUsmUser in class org.snmp4j.agent.BaseAgentprotected void initTransportMappings()
throws IOException
initTransportMappings in class org.snmp4j.agent.BaseAgentIOExceptionpublic InetAddress getInetAddress()
public int getPort()
protected void registerSnmpMIBs()
registerSnmpMIBs in class org.snmp4j.agent.BaseAgentprotected void unregisterSnmpMIBs()
unregisterSnmpMIBs in class org.snmp4j.agent.BaseAgentprotected void registerManagedObjects()
registerManagedObjects in class org.snmp4j.agent.BaseAgentprotected void unregisterManagedObjects()
unregisterManagedObjects in class org.snmp4j.agent.BaseAgentprotected List<org.snmp4j.agent.ManagedObject> createMockMOs()
public void updateValue(org.snmp4j.smi.OID oid,
org.snmp4j.smi.Variable value)
public void updateValue(String oid, org.snmp4j.smi.Variable value)
public void updateIntValue(String oid, int val)
public void updateCounter32Value(String oid, int val)
public void updateCounter64Value(String oid, long val)
public void updateValuesFromResource(URL moFile)
Copyright © 2020. All rights reserved.