Search in sources :

Example 16 with Integer32

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);
}
Also used : Integer32(org.snmp4j.smi.Integer32) DecimalFormat(java.text.DecimalFormat)

Example 17 with Integer32

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();
}
Also used : Integer32(org.snmp4j.smi.Integer32) Test(org.junit.Test)

Example 18 with Integer32

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();
}
Also used : Integer32(org.snmp4j.smi.Integer32) OctetString(org.snmp4j.smi.OctetString) Test(org.junit.Test)

Example 19 with Integer32

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();
}
Also used : OctetString(org.snmp4j.smi.OctetString) Integer32(org.snmp4j.smi.Integer32) Test(org.junit.Test)

Example 20 with Integer32

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();
}
Also used : Integer32(org.snmp4j.smi.Integer32) OctetString(org.snmp4j.smi.OctetString) Test(org.junit.Test)

Aggregations

Integer32 (org.snmp4j.smi.Integer32)21 Test (org.junit.Test)12 OctetString (org.snmp4j.smi.OctetString)11 OID (org.snmp4j.smi.OID)7 PDU (org.snmp4j.PDU)4 TimeTicks (org.snmp4j.smi.TimeTicks)4 VariableBinding (org.snmp4j.smi.VariableBinding)4 IpAddress (org.snmp4j.smi.IpAddress)3 Null (org.snmp4j.smi.Null)3 Variable (org.snmp4j.smi.Variable)3 IOException (java.io.IOException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 DecimalFormat (java.text.DecimalFormat)1 Date (java.util.Date)1 Matcher (java.util.regex.Matcher)1 SnmpBindingProvider (org.openhab.binding.snmp.SnmpBindingProvider)1 Command (org.openhab.core.types.Command)1 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)1 DynamicVariable (org.opennms.mock.snmp.responder.DynamicVariable)1 SnmpErrorStatusException (org.opennms.mock.snmp.responder.SnmpErrorStatusException)1