org.snmp4j.smi.Integer32 Java Examples

The following examples show how to use org.snmp4j.smi.Integer32. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModifiedVariableTest.java    From snmpman with Apache License 2.0 6 votes vote down vote up
@BeforeMethod
public void setUp() {
    variable = new Integer32(0);
    otherVariable = new Integer32(1);
    
    List<VariableModifier> modifiers = new ArrayList<>(1);

    final ModifierProperties modifierProperties = new ModifierProperties();
    modifierProperties.put("minimum", Integer.MIN_VALUE);
    modifierProperties.put("maximum", Integer.MAX_VALUE);
    modifierProperties.put("minimumStep", 1);
    modifierProperties.put("maximumStep", 10);

    final Integer32Modifier modifier = new Integer32Modifier();
    modifier.init(modifierProperties);
    
    modifiers.add(modifier);
    
    modifiedVariable = new ModifiedVariable(variable, modifiers);
}
 
Example #2
Source File: Integer32ModifierTest.java    From snmpman with Apache License 2.0 6 votes vote down vote up
@Test
public void testModify() {
    final ModifierProperties modifierProperties = new ModifierProperties();
    modifierProperties.put("minimum", Integer.MIN_VALUE);
    modifierProperties.put("maximum", Integer.MAX_VALUE);
    modifierProperties.put("minimumStep", 1);
    modifierProperties.put("maximumStep", 10);

    final Integer32Modifier modifier = new Integer32Modifier();
    modifier.init(modifierProperties);

    final Integer32 integer32 = new Integer32(0);
    assertEquals(integer32.getValue(), 0);

    final Integer32 modifiedVariable = modifier.modify(integer32);
    assertNotEquals(modifiedVariable.getValue(), 0);
}
 
Example #3
Source File: ModifiedVariableTest.java    From snmpman with Apache License 2.0 5 votes vote down vote up
@Test
public void testClone() {
    final Object clonedVariable = modifiedVariable.clone();
    assertNotSame(clonedVariable, modifiedVariable);
    assertTrue(clonedVariable instanceof Integer32);
    
    assertNotEquals(((Integer32) clonedVariable).getValue(), ((Integer32) variable).getValue());
}
 
Example #4
Source File: SnmpmanSetTest.java    From snmpman with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetterForInvalidValue() throws Exception {
    Integer newValue = 9999;
    ResponseEvent responseEvent = setVariableToOID(new OID(OID_OCTETSTRING).append(OID_ROW_INDEX), new Integer32(newValue));
    assertEquals(SnmpConstants.SNMP_ERROR_INCONSISTENT_VALUE, responseEvent.getResponse().getErrorStatus());
    assertThatOidHasValue(OID_OCTETSTRING, PRIMAL_OCTECT_VALUE);
}
 
Example #5
Source File: SNMPHelper.java    From SuitAgent with Apache License 2.0 4 votes vote down vote up
/**
 * walk方式获取指定的oid value
 *
 * @param snmp
 * @param target
 * @param oid
 * @return
 * @throws IOException
 */
public static List<PDU> snmpWalk(Snmp snmp, Target target, String oid) throws IOException {
    List<PDU> pduList = new ArrayList<>();

    ScopedPDU pdu = new ScopedPDU();
    OID targetOID = new OID(oid);
    pdu.add(new VariableBinding(targetOID));

    boolean finished = false;
    while (!finished) {
        VariableBinding vb = null;
        ResponseEvent respEvent = snmp.getNext(pdu, target);

        PDU response = respEvent.getResponse();

        if (null == response) {
            break;
        } else {
            vb = response.get(0);
        }
        // check finish
        finished = checkWalkFinished(targetOID, pdu, vb);
        if (!finished) {
            pduList.add(response);

            // Set up the variable binding for the next entry.
            pdu.setRequestID(new Integer32(0));
            pdu.set(0, vb);
        }
    }

    return pduList;
}
 
Example #6
Source File: SNMPHelper.java    From OpenFalcon-SuitAgent with Apache License 2.0 4 votes vote down vote up
/**
 * walk方式获取指定的oid value
 *
 * @param snmp
 * @param target
 * @param oid
 * @return
 * @throws IOException
 */
public static List<PDU> snmpWalk(Snmp snmp, Target target, String oid) throws IOException {
    List<PDU> pduList = new ArrayList<>();

    ScopedPDU pdu = new ScopedPDU();
    OID targetOID = new OID(oid);
    pdu.add(new VariableBinding(targetOID));

    boolean finished = false;
    while (!finished) {
        VariableBinding vb = null;
        ResponseEvent respEvent = snmp.getNext(pdu, target);

        PDU response = respEvent.getResponse();

        if (null == response) {
            break;
        } else {
            vb = response.get(0);
        }
        // check finish
        finished = checkWalkFinished(targetOID, pdu, vb);
        if (!finished) {
            pduList.add(response);

            // Set up the variable binding for the next entry.
            pdu.setRequestID(new Integer32(0));
            pdu.set(0, vb);
        }
    }

    return pduList;
}
 
Example #7
Source File: LumentumSdnRoadmFlowRuleProgrammable.java    From onos with Apache License 2.0 4 votes vote down vote up
private boolean removeCrossConnect(CrossConnectFlowRule xc) {

        int channel = toChannel(xc.ochSignal());

        // Create the PDU object
        PDU pdu = new PDU();
        pdu.setType(PDU.SET);

        // Disable the channel
        OID ctrlChannelState = new OID(CTRL_CHANNEL_STATE + (xc.isAddRule() ? "1." : "2.") + channel);
        pdu.add(new VariableBinding(ctrlChannelState, new Integer32(OUT_OF_SERVICE)));

        // Put cross connect back into default port 1
        OID ctrlChannelAddDropPortIndex = new OID(CTRL_CHANNEL_ADD_DROP_PORT_INDEX +
                (xc.isAddRule() ? "1." : "2.") + channel);
        pdu.add(new VariableBinding(ctrlChannelAddDropPortIndex,
                new UnsignedInteger32(DISABLE_CHANNEL_ADD_DROP_PORT_INDEX)));

        // Put port/channel back to open loop
        OID ctrlChannelMode = new OID(CTRL_CHANNEL_MODE + (xc.isAddRule() ? "1." : "2.") + channel);
        pdu.add(new VariableBinding(ctrlChannelMode, new Integer32(OPEN_LOOP)));

        // Add rules are set to target power, drop rules are attenuated
        if (xc.isAddRule()) {
            OID ctrlChannelTargetPower = new OID(CTRL_CHANNEL_TARGET_POWER + "1." + channel);
            pdu.add(new VariableBinding(ctrlChannelTargetPower, new Integer32(DISABLE_CHANNEL_TARGET_POWER)));
        } else {
            OID ctrlChannelAbsoluteAttenuation = new OID(CTRL_CHANNEL_ABSOLUTE_ATTENUATION + "2." + channel);
            pdu.add(new VariableBinding(
                    ctrlChannelAbsoluteAttenuation, new UnsignedInteger32(DISABLE_CHANNEL_ABSOLUTE_ATTENUATION)));
        }

        try {
            ResponseEvent response = snmp.set(pdu);

            // TODO: parse response
        } catch (IOException e) {
            log.error("Failed to remove cross connect, unable to connect to device: ", e);
            return false;
        }

        return true;
    }
 
Example #8
Source File: Integer32Modifier.java    From snmpman with Apache License 2.0 4 votes vote down vote up
@Override
public Integer32 modify(final Integer32 variable) {
    final int newValue = this.modify(variable.getValue(), minimum, maximum, minimumStep, maximumStep);
    log.trace("Counter32 variable {} will be tuned to {}", variable.getValue(), newValue);
    return new Integer32(newValue);
}
 
Example #9
Source File: SnmpGenericBindingProvider.java    From openhab1-addons with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @{inheritDoc
 */
@Override
public Integer32 getValue(String itemName, Command command) {
    SnmpBindingConfig config = (SnmpBindingConfig) bindingConfigs.get(itemName);
    return config != null ? config.get(command).value : null;
}
 
Example #10
Source File: SnmpBindingProvider.java    From openhab1-addons with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Returns the SNMP value for the command
 * 
 * @return value for the command
 */
Integer32 getValue(String itemName, Command command);