Beispiel #1
0
  VariableBinding getVarBindForSetRequest(String oid, int type, String value) {
    VariableBinding vb = new VariableBinding(new OID(oid));

    if (value != null) {
      Variable variable;
      switch (type) {
        case DSnmpMibRecord.VALUE_TYPE_INTEGER32:
          variable = new Integer32(Integer.parseInt(value));
          break;
        case DSnmpMibRecord.VALUE_TYPE_UNSIGNED_INTEGER32:
          variable = new UnsignedInteger32(Long.parseLong(value));
          break;
        case DSnmpMibRecord.VALUE_TYPE_OCTET_STRING:
          variable = new OctetString(value);
          break;
        case DSnmpMibRecord.VALUE_TYPE_NULL:
          variable = new Null();
          break;
        case DSnmpMibRecord.VALUE_TYPE_OID:
          variable = new OID(value);
          break;
        case DSnmpMibRecord.VALUE_TYPE_TIMETICKS:
          variable = new TimeTicks(Long.parseLong(value));
          break;
        case DSnmpMibRecord.VALUE_TYPE_IP_ADDRESS:
          variable = new IpAddress(value);
          break;
        default:
          throw new IllegalArgumentException("Variable type " + type + " not supported");
      }
      vb.setVariable(variable);
    }
    return vb;
  }
Beispiel #2
0
 private boolean processWalk(PDU response, PDU request, OID rootOID) throws SnmpException {
   if ((response == null)
       || (response.getErrorStatus() != 0)
       || (response.getType() == PDU.REPORT)) {
     return true;
   }
   boolean finished = false;
   OID lastOID = request.get(0).getOid();
   for (int i = 0; (!finished) && (i < response.size()); i++) {
     VariableBinding vb = response.get(i);
     if ((vb.getOid() == null)
         || (vb.getOid().size() < rootOID.size())
         || (rootOID.leftMostCompare(rootOID.size(), vb.getOid()) != 0)) {
       finished = true;
     } else if (Null.isExceptionSyntax(vb.getVariable().getSyntax())) {
       outputResponse(vb);
       finished = true;
     } else if (vb.getOid().compareTo(lastOID) <= 0) {
       throw new SnmpException(
           "Variable received is not lexicographic successor of requested one:"
               + vb.toString()
               + " <= "
               + lastOID);
     } else {
       outputResponse(vb);
       lastOID = vb.getOid();
     }
   }
   if (response.size() == 0) {
     finished = true;
   }
   if (!finished) {
     VariableBinding next = response.get(response.size() - 1);
     next.setVariable(new Null());
     request.set(0, next);
     request.setRequestID(new Integer32(0));
   }
   return finished;
 }