public boolean skipVariable(long var, Object data, int pduVersion) { switch((int)var) { case 8: case 7: case 6: case 5: case 4: case 2: if (pduVersion==SnmpDefinitions.snmpVersionOne) return true; break; case 1: return true; default: break; } return super.skipVariable(var,data,pduVersion); }
public boolean skipVariable(long var, Object data, int pduVersion) { switch((int)var) { case 23: case 22: case 21: case 20: case 13: case 12: case 11: case 10: if (pduVersion==SnmpDefinitions.snmpVersionOne) return true; break; default: break; } return super.skipVariable(var,data,pduVersion); }
/** * Setter for the "JvmMemoryGCCall" variable. */ public void setJvmMemoryGCCall(EnumJvmMemoryGCCall x) throws SnmpStatusException { if (x.intValue() == JvmMemoryGCCallStart.intValue()) { final Map<Object, Object> m = JvmContextFactory.getUserData(); try { ManagementFactory.getMemoryMXBean().gc(); if (m != null) m.put("jvmMemory.getJvmMemoryGCCall", JvmMemoryGCCallStarted); } catch (Exception ex) { if (m != null) m.put("jvmMemory.getJvmMemoryGCCall", JvmMemoryGCCallFailed); } return; } throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue); }
/** * This is a factory method for creating new SnmpMibRequest objects. * @param reqPdu The received PDU. * @param vblist The vector of SnmpVarBind objects in which the * MIB concerned by this request is involved. * @param version The protocol version of the SNMP request. * @param userData User allocated contextual data. * * @return A new SnmpMibRequest object. * * @since 1.5 **/ public static SnmpMibRequest newMibRequest(SnmpPdu reqPdu, Vector<SnmpVarBind> vblist, int version, Object userData) { return new SnmpMibRequestImpl(null, reqPdu, vblist, version, userData, null, SnmpDefinitions.noAuthNoPriv, getSecurityModel(version), null,null); }
public static int mapSetException(int errorStatus, int version) throws SnmpStatusException { final int errorCode = errorStatus; if (version == SnmpDefinitions.snmpVersionOne) return errorCode; int mappedErrorCode = errorCode; // Now take care of V2 errorCodes that can be stored // in the varbind itself: if (errorCode == SnmpStatusException.noSuchObject) // noSuchObject => notWritable mappedErrorCode = SnmpStatusException.snmpRspNotWritable; else if (errorCode == SnmpStatusException.noSuchInstance) // noSuchInstance => notWritable mappedErrorCode = SnmpStatusException.snmpRspNotWritable; return mappedErrorCode; }
@Override public void registerSetException(SnmpVarBind var, SnmpStatusException exception) throws SnmpStatusException { // The index in the exception must correspond to // the SNMP index ... // if (version == SnmpDefinitions.snmpVersionOne) throw new SnmpStatusException(exception, getVarIndex(var)+1); // Although the first pass of check() did not fail, // the set() phase could not be carried out correctly. // Since we don't know how to make an "undo", and some // assignation may already have been performed, we're going // to throw an snmpRspUndoFailed. // throw new SnmpStatusException(SnmpDefinitions.snmpRspUndoFailed, getVarIndex(var)+1); }
/** * Processes a <CODE>get</CODE> operation. It will throw an exception for V1 requests or it will set exceptions within the list for V2 requests. * * @param inRequest The SnmpMibRequest object holding the list of variable to be retrieved. * * @exception SnmpStatusException An error occurred during the operation. */ @Override public void get(SnmpMibRequest inRequest) throws SnmpStatusException { SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpErrorHandlerAgent.class.getName(), "get", "Get in Exception"); if(inRequest.getVersion() == SnmpDefinitions.snmpVersionOne) throw new SnmpStatusException(SnmpStatusException.noSuchName); Enumeration<SnmpVarBind> l = inRequest.getElements(); while(l.hasMoreElements()) { SnmpVarBind varbind = l.nextElement(); varbind.setNoSuchObject(); } }
/** * Processes a <CODE>getNext</CODE> operation. It will throw an exception for V1 requests or it will set exceptions within the list for V2 requests.. * * @param inRequest The SnmpMibRequest object holding the list of variables to be retrieved. * * @exception SnmpStatusException An error occurred during the operation. */ @Override public void getNext(SnmpMibRequest inRequest) throws SnmpStatusException { SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpErrorHandlerAgent.class.getName(), "getNext", "GetNext in Exception"); if(inRequest.getVersion() == SnmpDefinitions.snmpVersionOne) throw new SnmpStatusException(SnmpStatusException.noSuchName); Enumeration<SnmpVarBind> l = inRequest.getElements(); while(l.hasMoreElements()) { SnmpVarBind varbind = l.nextElement(); varbind.setEndOfMibView(); } }
/** * Processes a <CODE>getBulk</CODE> operation. It will throw an exception if the request is a V1 one or it will set exceptions within the list for V2 ones. * * @param inRequest The SnmpMibRequest object holding the list of variable to be retrieved. * * @exception SnmpStatusException An error occurred during the operation. */ @Override public void getBulk(SnmpMibRequest inRequest, int nonRepeat, int maxRepeat) throws SnmpStatusException { SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpErrorHandlerAgent.class.getName(), "getBulk", "GetBulk in Exception"); if(inRequest.getVersion() == SnmpDefinitions.snmpVersionOne) throw new SnmpStatusException(SnmpDefinitions.snmpRspGenErr, 0); Enumeration<SnmpVarBind> l = inRequest.getElements(); while(l.hasMoreElements()) { SnmpVarBind varbind = l.nextElement(); varbind.setEndOfMibView(); } }
/** * Check the type of the pdu: only the get/set/bulk request * are accepted. */ private boolean checkPduType(SnmpPduPacket pdu) { boolean result; switch(pdu.type) { case SnmpDefinitions.pduGetRequestPdu: case SnmpDefinitions.pduGetNextRequestPdu: case SnmpDefinitions.pduSetRequestPdu: case SnmpDefinitions.pduGetBulkRequestPdu: result = true ; break; default: if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag, "checkPduType", "cannot respond to this kind of PDU"); } result = false ; break; } return result ; }
/** * Make a response pdu with the specified error status and index. * NOTE: the response pdu share its varBindList with the request pdu. */ private SnmpPduRequest newValidResponsePdu(SnmpPduPacket reqPdu, SnmpVarBind[] varBindList) { SnmpPduRequest result = new SnmpPduRequest() ; result.address = reqPdu.address ; result.port = reqPdu.port ; result.version = reqPdu.version ; result.community = reqPdu.community ; result.type = SnmpPduRequest.pduGetResponsePdu ; result.requestId = reqPdu.requestId ; result.errorStatus = SnmpDefinitions.snmpRspNoError ; result.errorIndex = 0 ; result.varBindList = varBindList ; ((SnmpAdaptorServer)adaptorServer). updateErrorCounters(result.errorStatus) ; return result ; }
static final int mapErrorStatus(int errorStatus, int protocolVersion, int reqPduType) { if (errorStatus == SnmpDefinitions.snmpRspNoError) return SnmpDefinitions.snmpRspNoError; // Too bad, an error occurs ... we need to translate it ... // if (protocolVersion == SnmpDefinitions.snmpVersionOne) return mapErrorStatusToV1(errorStatus,reqPduType); if (protocolVersion == SnmpDefinitions.snmpVersionTwo || protocolVersion == SnmpDefinitions.snmpVersionThree) return mapErrorStatusToV2(errorStatus,reqPduType); return SnmpDefinitions.snmpRspGenErr; }