use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class TestAgentTest method testEmptyAgent.
public void testEmptyAgent() {
TestAgent agent = new TestAgent();
SnmpObjId z1 = SnmpObjId.get(zeroInst1Base, "0");
try {
agent.getValueFor(z1);
fail("Expected exception");
} catch (AgentNoSuchObjectException e) {
}
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class TestAgentTest method verifyNextVarBind.
private SnmpObjId verifyNextVarBind(SnmpObjId reqObjId, TestVarBind respVarBind) {
try {
SnmpObjId nextOid = m_agent.getFollowingObjId(reqObjId);
assertEquals(nextOid, respVarBind.getObjId());
verifyObjIdValue(respVarBind);
return nextOid;
} catch (AgentEndOfMibException e) {
assertEquals(reqObjId, respVarBind.getObjId());
assertEquals(MockSnmpValue.END_OF_MIB, respVarBind.getValue());
return reqObjId;
}
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class TestAgentTest method validateBulkResponse.
private void validateBulkResponse(BulkPdu pdu, ResponsePdu resp) {
assertNotNull(resp);
assertEquals(ErrorStatus.NO_ERROR.ordinal(), resp.getErrorStatus());
int nonRepeaters = pdu.getNonRepeaters();
int repeaters = (pdu.size() - nonRepeaters);
// validate the length
int expectedSize = Math.min(nonRepeaters + (repeaters * pdu.getMaxRepititions()), m_agent.getMaxResponseSize());
assertEquals(expectedSize, resp.size());
// validate the nonRepeaters
for (int i = 0; i < nonRepeaters; i++) {
verifyBulkVarBind(pdu.getVarBindAt(i).getObjId(), resp, i);
}
// validate the repeaters
for (int i = 0; i < repeaters; i++) {
SnmpObjId oid = pdu.getVarBindAt(i + nonRepeaters).getObjId();
for (int count = 0; count < pdu.getMaxRepititions(); count++) {
oid = verifyBulkVarBind(oid, resp, nonRepeaters + (count * repeaters) + i);
}
}
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class TestAgentTest method testFollowingOid.
public void testFollowingOid() {
SnmpObjId z1 = SnmpObjId.get(zeroInst1Base);
SnmpObjId z2 = SnmpObjId.get(zeroInst2Base);
SnmpObjId z1dot0 = SnmpObjId.get(z1, "0");
SnmpObjId z2dot0 = SnmpObjId.get(z2, "0");
SnmpObjId col1 = SnmpObjId.get(col1Base);
SnmpObjId col1dot1 = SnmpObjId.get(col1, "1");
SnmpObjId col2 = SnmpObjId.get(col2Base);
SnmpObjId col2dot1 = SnmpObjId.get(col2, "1");
SnmpObjId col2dot10 = SnmpObjId.get(col2, "10");
SnmpObjId col3 = SnmpObjId.get(col3Base);
SnmpObjId col3dot1 = SnmpObjId.get(col3, "1");
SnmpObjId col3dot10 = SnmpObjId.get(col3, "10");
assertEquals(z1dot0, m_agent.getFollowingObjId(z1));
assertEquals(z2dot0, m_agent.getFollowingObjId(z1dot0));
assertEquals(z2dot0, m_agent.getFollowingObjId(z2));
assertEquals(col1dot1, m_agent.getFollowingObjId(z2dot0));
assertEquals(col1dot1, m_agent.getFollowingObjId(col1));
assertEquals(col3dot1, m_agent.getFollowingObjId(col2dot10));
try {
m_agent.getFollowingObjId(col3dot10);
fail("Expected exception");
} catch (NoSuchElementException e) {
}
m_agent.introduceSequenceError(col2dot10, col2dot1);
assertEquals(col2dot1, m_agent.getFollowingObjId(col2dot10));
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class SnmpProxyRpcModule method get.
private CompletableFuture<SnmpResponseDTO> get(SnmpRequestDTO request, SnmpGetRequestDTO get) {
final SnmpObjId[] oids = get.getOids().toArray(new SnmpObjId[get.getOids().size()]);
final CompletableFuture<SnmpValue[]> future = SnmpUtils.getAsync(request.getAgent(), oids);
return future.thenApply(values -> {
final List<SnmpResult> results = new ArrayList<>(oids.length);
for (int i = 0; i < oids.length; i++) {
final SnmpResult result = new SnmpResult(oids[i], null, values[i]);
results.add(result);
}
final SnmpResponseDTO responseDTO = new SnmpResponseDTO();
responseDTO.setCorrelationId(get.getCorrelationId());
responseDTO.setResults(results);
return responseDTO;
});
}
Aggregations