use of org.snmp4j.smi.Integer32 in project opennms by OpenNMS.
the class SineWave method getVariableForOID.
@Override
public Variable getVariableForOID(String oidStr) {
String[] oids = oidStr.split("\\.");
Integer instance = Integer.parseInt(oids[oids.length - 1]);
// Convert the instance from degrees to radians and calculate the sin
double x = Math.sin(instance.doubleValue() * Math.PI / 180);
// Round the value to two decimal places and multiply it by 100
// Leaving us with an integer
DecimalFormat epsilum = new DecimalFormat("#.##");
x = Double.valueOf(epsilum.format(x)) * 100;
// Convert the result back to an integer
return new Integer32((int) x);
}
use of org.snmp4j.smi.Integer32 in project opennms by OpenNMS.
the class MockSnmpAgentIT method testUpdateFromFile.
@Test
public void testUpdateFromFile() throws Exception {
request("1.3.5.1.1.3.0").andExpect("1.3.5.1.1.3.0", SMIConstants.SYNTAX_INTEGER, new Integer32(42));
doGet();
m_agent.updateValuesFromResource(classPathResource("differentSnmpData.properties"));
request("1.3.5.1.1.3.0").andExpect("1.3.5.1.1.3.0", SMIConstants.SYNTAX_INTEGER, new Integer32(77));
doGet();
}
use of org.snmp4j.smi.Integer32 in project opennms by OpenNMS.
the class MockSnmpAgentIT method testSineWaveResponder.
@Test
public void testSineWaveResponder() throws Exception {
String oid = "1.3.5.1.1.10.0";
request(oid).andExpect(oid, SMIConstants.SYNTAX_INTEGER, new Integer32(0));
doGet();
oid = "1.3.5.1.1.10.30";
request(oid).andExpect(oid, SMIConstants.SYNTAX_INTEGER, new Integer32(50));
doGet();
oid = "1.3.5.1.1.10.45";
request(oid).andExpect(oid, SMIConstants.SYNTAX_INTEGER, new Integer32(71));
doGet();
oid = "1.3.5.1.1.10.90";
request(oid).andExpect(oid, SMIConstants.SYNTAX_INTEGER, new Integer32(100));
doGet();
}
use of org.snmp4j.smi.Integer32 in project opennms by OpenNMS.
the class LLDPMibIT method testGetNextMultipleVarbinds.
@Test
public void testGetNextMultipleVarbinds() throws Exception {
request(".1.0.8802.1.1.2.1.3.1").andExpect(".1.0.8802.1.1.2.1.3.1.0", SMIConstants.SYNTAX_INTEGER32, new Integer32(4));
doGetNext();
m_agent.getUsm().setEngineBoots(15);
byte[] hexString = new byte[] { (byte) 0x80, (byte) 0x71, (byte) 0x1F, (byte) 0x8F, (byte) 0xAF, (byte) 0xC0 };
request(".1.0.8802.1.1.2.1.3.1").andExpect(".1.0.8802.1.1.2.1.3.1.0", SMIConstants.SYNTAX_INTEGER32, new Integer32(4));
request(".1.0.8802.1.1.2.1.3.2").andExpect(".1.0.8802.1.1.2.1.3.2.0", SMIConstants.SYNTAX_OCTET_STRING, new OctetString(hexString));
request(".1.0.8802.1.1.2.1.3.3").andExpect(".1.0.8802.1.1.2.1.3.3.0", SMIConstants.SYNTAX_OCTET_STRING, new OctetString("penrose-mx480".getBytes()));
doGetNext();
// This statement breaks the internal state of the SNMP4J agent
// m_agent.getUsm().setLocalEngine(m_agent.getUsm().getLocalEngineID(), 15, 200);
m_agent.getUsm().removeEngineTime(m_usm.getLocalEngineID());
m_usm.removeEngineTime(m_agent.getUsm().getLocalEngineID());
request(".1.0.8802.1.1.2.1.3.1").andExpect(".1.0.8802.1.1.2.1.3.1.0", SMIConstants.SYNTAX_INTEGER32, new Integer32(4));
doGetNext();
}
use of org.snmp4j.smi.Integer32 in project opennms by OpenNMS.
the class MockSnmpAgentIT method testSet.
@Test
public void testSet() throws Exception {
final String oid = "1.3.5.1.1.3.0";
// current value is 42
request(oid).andExpect(oid, SMIConstants.SYNTAX_INTEGER, new Integer32(42));
doGet();
// set a value of 17
request(oid, new Integer32(17)).andExpect(oid, SMIConstants.SYNTAX_INTEGER32, new Integer32(17));
doSet();
// request new value and expect 17
request(oid).andExpect(oid, SMIConstants.SYNTAX_INTEGER, new Integer32(17));
doGet();
}
Aggregations