Search in sources :

Example 6 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 7 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)

Example 8 with Integer32

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

the class MockSnmpAgentIT method testGet.

@Test
public void testGet() 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.updateValue("1.3.5.1.1.3.0", new Integer32(77));
    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 9 with Integer32

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

the class MockSnmpAgentIT method testSleeperResponder.

@Test
public void testSleeperResponder() throws Exception {
    final String myOid = "1.3.5.1.1.11.0";
    // Verify that the sleeper responds correctly
    Sleeper.getInstance().setVariable(new Integer32(1));
    request(myOid).andExpect(myOid, SMIConstants.SYNTAX_INTEGER, new Integer32(1));
    doGet();
    // Set the timeout
    Sleeper.getInstance().setSleepTime(DEFAULT_TIMEOUT + 1000);
    // Make another request
    PDU pdu = createPDU(m_version);
    OID oid = new OID(myOid);
    pdu.add(new VariableBinding(oid));
    pdu.setType(PDU.GET);
    PDU response = sendRequest(pdu, m_version);
    // Verify that the request does in fact timeout
    assertNull("request timed out", response);
    // Clear the timeout
    Sleeper.getInstance().setSleepTime(0);
    // Update the variable
    Sleeper.getInstance().setVariable(new OctetString("Bingo!"));
    request(myOid).andExpect(myOid, SMIConstants.SYNTAX_OCTET_STRING, new OctetString("Bingo!"));
    doGet();
}
Also used : ScopedPDU(org.snmp4j.ScopedPDU) PDU(org.snmp4j.PDU) OctetString(org.snmp4j.smi.OctetString) Integer32(org.snmp4j.smi.Integer32) OctetString(org.snmp4j.smi.OctetString) OID(org.snmp4j.smi.OID) VariableBinding(org.snmp4j.smi.VariableBinding) Test(org.junit.Test)

Example 10 with Integer32

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

the class TrapDTOMapperTest method object2dtoTest.

@Test
public void object2dtoTest() throws UnknownHostException {
    long testStartTime = new Date().getTime();
    PDU snmp4JV2cTrapPdu = new PDU();
    snmp4JV2cTrapPdu.setType(PDU.TRAP);
    OID oid = new OID(".1.3.6.1.2.1.1.3.0");
    snmp4JV2cTrapPdu.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(5000)));
    snmp4JV2cTrapPdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, oid));
    snmp4JV2cTrapPdu.add(new VariableBinding(SnmpConstants.snmpTrapAddress, new IpAddress("127.0.0.1")));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID(oid), new OctetString("Trap Msg v2-1")));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID(oid), new OctetString("Trap Msg v2-2")));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.0"), new OctetString("Trap v1 msg-1")));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID(".1.3.6.1.2.1.1.3"), new OctetString("Trap v1 msg-2")));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID(".1.3.6.1.6.3.1.1.4.1.1"), new OctetString("Trap v1 msg-3")));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID(".1.3.6.1.4.1.733.6.3.18.1.5.0"), new Integer32(1)));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.0"), new Null()));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.1"), new Null(128)));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.2"), new Null(129)));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.3"), new Null(130)));
    TrapInformation snmp4JV2cTrap = new Snmp4JTrapNotifier.Snmp4JV2TrapInformation(InetAddressUtils.ONE_TWENTY_SEVEN, "public", snmp4JV2cTrapPdu);
    TrapDTO trapDto = new TrapDTO(snmp4JV2cTrap);
    System.out.println("trapDto is : " + trapDto);
    System.out.println("trapDto.getBody() is : " + trapDto.getRawMessage());
    System.out.println("trapDto.getCommunity() is : " + trapDto.getCommunity());
    assertEquals(".1.3.6.1.2.1.1.3", trapDto.getTrapIdentity().getEnterpriseId());
    assertEquals(6, trapDto.getTrapIdentity().getGeneric());
    assertEquals(0, trapDto.getTrapIdentity().getSpecific());
    assertEquals(InetAddressUtils.ONE_TWENTY_SEVEN, trapDto.getAgentAddress());
    assertEquals("public", trapDto.getCommunity());
    assertEquals(5000, trapDto.getTimestamp());
    // Trap and agent address are identical with SNMPv2
    assertEquals(InetAddressUtils.ONE_TWENTY_SEVEN, trapDto.getAgentAddress());
    assertEquals("v2", trapDto.getVersion());
    // Make sure that the message was created after the start of the test
    assertTrue(trapDto.getCreationTime() >= testStartTime);
}
Also used : PDU(org.snmp4j.PDU) OctetString(org.snmp4j.smi.OctetString) Null(org.snmp4j.smi.Null) TimeTicks(org.snmp4j.smi.TimeTicks) OID(org.snmp4j.smi.OID) Date(java.util.Date) Integer32(org.snmp4j.smi.Integer32) IpAddress(org.snmp4j.smi.IpAddress) VariableBinding(org.snmp4j.smi.VariableBinding) TrapInformation(org.opennms.netmgt.snmp.TrapInformation) 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