Search in sources :

Example 1 with Integer32

use of org.snmp4j.smi.Integer32 in project openhab1-addons by openhab.

the class SnmpBinding method internalReceiveCommand.

/**
     * @{inheritDoc
     */
@Override
public void internalReceiveCommand(String itemName, Command command) {
    logger.debug("SNMP receive command {} from {}", itemName, command);
    SnmpBindingProvider providerCmd = null;
    for (SnmpBindingProvider provider : this.providers) {
        OID oid = provider.getOID(itemName, command);
        if (oid != null) {
            providerCmd = provider;
            break;
        }
    }
    if (providerCmd == null) {
        logger.warn("No match for binding provider [itemName={}, command={}]", itemName, command);
        return;
    }
    logger.debug("SNMP command for {} to {}", itemName, providerCmd.toString());
    // Set up the target
    CommunityTarget target = new CommunityTarget();
    target.setCommunity(providerCmd.getCommunity(itemName, command));
    target.setAddress(providerCmd.getAddress(itemName, command));
    target.setRetries(retries);
    target.setTimeout(timeout);
    target.setVersion(providerCmd.getSnmpVersion(itemName, command));
    Variable var = providerCmd.getValue(itemName, command);
    OID oid = providerCmd.getOID(itemName, command);
    VariableBinding varBind = new VariableBinding(oid, var);
    // Create the PDU
    PDU pdu = new PDU();
    pdu.add(varBind);
    pdu.setType(PDU.SET);
    pdu.setRequestID(new Integer32(1));
    logger.debug("SNMP: Send CMD PDU {} {}", providerCmd.getAddress(itemName, command), pdu);
    if (snmp == null) {
        logger.error("SNMP: snmp not initialised - aborting request");
    } else {
        sendPDU(target, pdu);
    }
}
Also used : PDU(org.snmp4j.PDU) Integer32(org.snmp4j.smi.Integer32) Variable(org.snmp4j.smi.Variable) SnmpBindingProvider(org.openhab.binding.snmp.SnmpBindingProvider) OID(org.snmp4j.smi.OID) CommunityTarget(org.snmp4j.CommunityTarget) VariableBinding(org.snmp4j.smi.VariableBinding)

Example 2 with Integer32

use of org.snmp4j.smi.Integer32 in project opennms by OpenNMS.

the class LLDPMibIT method testGetNext.

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

Example 3 with Integer32

use of org.snmp4j.smi.Integer32 in project opennms by OpenNMS.

the class MockSnmpAgentIT method testDynamicVariableCacheAfterUpdateFromFile.

@Test
public void testDynamicVariableCacheAfterUpdateFromFile() throws Exception {
    final String oid = "1.3.5.1.1.10.0";
    request(oid).andExpect(oid, SMIConstants.SYNTAX_INTEGER, new Integer32(0));
    doGet();
    m_agent.updateValuesFromResource(classPathResource("differentSnmpData.properties"));
    Sleeper.getInstance().resetWithVariable(new Integer32(42));
    request(oid).andExpect(oid, SMIConstants.SYNTAX_INTEGER, new Integer32(42));
    doGet();
}
Also used : Integer32(org.snmp4j.smi.Integer32) OctetString(org.snmp4j.smi.OctetString) Test(org.junit.Test)

Example 4 with Integer32

use of org.snmp4j.smi.Integer32 in project opennms by OpenNMS.

the class MockSnmpAgentIT method testGetNextMultipleVarbinds.

@Test
public void testGetNextMultipleVarbinds() throws Exception {
    request("1.3.5.1.1.3").andExpect("1.3.5.1.1.3.0", SMIConstants.SYNTAX_INTEGER, new Integer32(42));
    doGetNext();
    m_agent.getUsm().setEngineBoots(15);
    request("1.3.5.1.1.3").andExpect("1.3.5.1.1.3.0", SMIConstants.SYNTAX_INTEGER, new Integer32(42));
    doGetNext();
    request("1.3.5.1.1.3").andExpect("1.3.5.1.1.3.0", SMIConstants.SYNTAX_INTEGER, new Integer32(42));
    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.3.5.1.1.3").andExpect("1.3.5.1.1.3.0", SMIConstants.SYNTAX_INTEGER, new Integer32(42));
    doGetNext();
}
Also used : Integer32(org.snmp4j.smi.Integer32) Test(org.junit.Test)

Example 5 with Integer32

use of org.snmp4j.smi.Integer32 in project opennms by OpenNMS.

the class MockSnmpAgentIT method testUpdateFromFileWithUSMTimeReset.

@Test
public void testUpdateFromFileWithUSMTimeReset() 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.getUsm().setEngineBoots(15);
    request("1.3.5.1.1.3.0").andExpect("1.3.5.1.1.3.0", SMIConstants.SYNTAX_INTEGER, new Integer32(42));
    doGet();
    request("1.3.5.1.1.3.0").andExpect("1.3.5.1.1.3.0", SMIConstants.SYNTAX_INTEGER, new Integer32(42));
    doGet();
    // 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.3.5.1.1.3.0").andExpect("1.3.5.1.1.3.0", SMIConstants.SYNTAX_INTEGER, new Integer32(42));
    doGet();
    request("1.3.5.1.1.3.0").andExpect("1.3.5.1.1.3.0", SMIConstants.SYNTAX_INTEGER, new Integer32(42));
    doGet();
    m_usm.removeEngineTime(m_agent.getUsm().getLocalEngineID());
    request("1.3.5.1.1.3.0").andExpect("1.3.5.1.1.3.0", SMIConstants.SYNTAX_INTEGER, new Integer32(42));
    doGet();
    request("1.3.5.1.1.3.0").andExpect("1.3.5.1.1.3.0", SMIConstants.SYNTAX_INTEGER, new Integer32(42));
    doGet();
}
Also used : Integer32(org.snmp4j.smi.Integer32) Test(org.junit.Test)

Aggregations

Integer32 (org.snmp4j.smi.Integer32)23 OctetString (org.snmp4j.smi.OctetString)13 Test (org.junit.Test)12 OID (org.snmp4j.smi.OID)9 PDU (org.snmp4j.PDU)5 IpAddress (org.snmp4j.smi.IpAddress)5 VariableBinding (org.snmp4j.smi.VariableBinding)5 TimeTicks (org.snmp4j.smi.TimeTicks)4 Null (org.snmp4j.smi.Null)3 Variable (org.snmp4j.smi.Variable)3 IOException (java.io.IOException)2 PDUv1 (org.snmp4j.PDUv1)2 Counter64 (org.snmp4j.smi.Counter64)2 TransportIpAddress (org.snmp4j.smi.TransportIpAddress)2 UnsignedInteger32 (org.snmp4j.smi.UnsignedInteger32)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 InetSocketAddress (java.net.InetSocketAddress)1 DecimalFormat (java.text.DecimalFormat)1 Date (java.util.Date)1 Enumeration (java.util.Enumeration)1