/** This utility method is used to construct an error PDU. This code * was repeated so many times it was prudent to give it it's own method. * @param response This PDU is the one being modified into an error PDU. * @param oid The OID to contain the error Null instance. * @param errorIndex the VariableBinding in the PDU that caused the error. * @param err The error number defined in the PDU class that indicates a given failure */ private void makeErrorPdu(PDU response, PDU pdu, int errorIndex, int err){ response.clear(); response.addAll(pdu.toArray()); response.setErrorIndex(errorIndex); response.setErrorStatus(err); }
/** This utility method is used to construct an error PDU. This code * was repeated so many times it was prudent to give it it's own method. * @param response This PDU is the one being modified into an error PDU. * @param oid The OID to contain the error Null instance. * @param errorIndex the VariableBinding in the PDU that caused the error. * @param err The error number defined in the PDU class that indicates a given failure */ private void makeErrorPdu(PDU response, PDU pdu, int errorIndex, int err){ response.clear(); response.addAll(pdu.toArray()); response.setErrorIndex(errorIndex); response.setErrorStatus(err); }
PDU trap = exchange.getIn().getBody(PDU.class); trap.setErrorIndex(0); trap.setErrorStatus(0); trap.setMaxRepetitions(0);
private PDU createResponse() { PDU resp = (PDU) source.getPDU().clone(); resp.clear(); resp.setType(PDU.RESPONSE); resp.setRequestID(source.getPDU().getRequestID()); resp.setErrorIndex(0); resp.setErrorStatus(PDU.noError); return resp; }
private PDU createResponse() { PDU resp = (PDU) requestEvent.getPDU().clone(); resp.clear(); resp.setType(PDU.RESPONSE); resp.setRequestID(requestEvent.getPDU().getRequestID()); resp.setErrorIndex(0); resp.setErrorStatus(PDU.noError); return resp; }
int type = command.getType(); command.setErrorIndex(0); command.setErrorStatus(0); command.setType(PDU.RESPONSE); } finally { command.setErrorIndex(errorIndex); command.setErrorStatus(errorStatus); command.setType(type);
/** * @param request * @return */ private PDU processGetNext(PDU request) { PDU response = request; response.setErrorIndex(0); response.setErrorStatus(0); response.setType(PDU.RESPONSE); Vector<? extends VariableBinding> varBinds = response.getVariableBindings(); for(int i = 0; i < varBinds.size(); i++) { VariableBinding varBind = varBinds.get(i); VariableBinding nextVarBind = m_agent.getNext(varBind.getOid()); if (nextVarBind == null) { if (response instanceof PDUv1) { if (response.getErrorIndex() == 0) { response.setErrorIndex(i+1); response.setErrorStatus(PDU.noSuchName); } } else { varBind.setVariable(Null.endOfMibView); } } else { response.set(i, nextVarBind); } } return response; }
/** * @param request * @return */ private PDU processGet(PDU request) { PDU response = request; response.setErrorIndex(0); response.setErrorStatus(0); response.setType(PDU.RESPONSE); Vector<? extends VariableBinding> varBinds = response.getVariableBindings(); for(int i = 0; i < varBinds.size(); i++) { VariableBinding varBind = varBinds.get(i); VariableBinding nextVarBind = m_agent.get(varBind.getOid()); if (nextVarBind == null) { if (response instanceof PDUv1) { if (response.getErrorIndex() == 0) { response.setErrorIndex(i+1); response.setErrorStatus(PDU.noSuchName); } } else { varBind.setVariable(Null.endOfMibView); } } else { response.set(i, nextVarBind); } } return response; }
int type = command.getType(); command.setErrorIndex(0); command.setErrorStatus(0); command.setType(PDU.RESPONSE); } finally { command.setErrorIndex(errorIndex); command.setErrorStatus(errorStatus); command.setType(type);
if (vb.isException()) { response.setErrorStatus(PDU.noSuchName); response.setErrorIndex(i+1); response.set(i, new VariableBinding(vb.getOid())); return; response.setErrorStatus(errStatus); response.setErrorIndex(getErrorIndex());
if (vb.isException()) { response.setErrorStatus(PDU.noSuchName); response.setErrorIndex(i+1); response.set(i, new VariableBinding(vb.getOid())); return; response.setErrorStatus(errStatus); response.setErrorIndex(getErrorIndex());
pdu.setErrorIndex(0); pdu.setErrorStatus(0); pdu.setType(PDU.RESPONSE);
public synchronized void processPdu(CommandResponderEvent e) { PDU command = e.getPDU(); if (command != null) { if ((command.getType() != PDU.TRAP) && (command.getType() != PDU.V1TRAP) && (command.getType() != PDU.REPORT) && (command.getType() != PDU.RESPONSE)) { out.println(command.toString()); command.setErrorIndex(0); command.setErrorStatus(0); command.setType(PDU.RESPONSE); StatusInformation statusInformation = new StatusInformation(); StateReference ref = e.getStateReference(); try { e.getMessageDispatcher().returnResponsePdu(e. getMessageProcessingModel(), e.getSecurityModel(), e.getSecurityName(), e.getSecurityLevel(), command, e.getMaxSizeResponsePDU(), ref, statusInformation); } catch (MessageException ex) { err.println("Error while sending response: " + ex.getMessage()); LogFactory.getLogger(SnmpCommand.class).error(ex); } } } }
public synchronized void processPdu(CommandResponderEvent e) { PDU command = e.getPDU(); if (command != null) { System.out.println(command.toString()); if ((command.getType() != PDU.TRAP) && (command.getType() != PDU.V1TRAP) && (command.getType() != PDU.REPORT) && (command.getType() != PDU.RESPONSE)) { command.setErrorIndex(0); command.setErrorStatus(0); command.setType(PDU.RESPONSE); StatusInformation statusInformation = new StatusInformation(); StateReference ref = e.getStateReference(); try { e.getMessageDispatcher().returnResponsePdu(e.getMessageProcessingModel(), e.getSecurityModel(), e.getSecurityName(), e.getSecurityLevel(), command, e.getMaxSizeResponsePDU(), ref, statusInformation); } catch (MessageException ex) { System.err.println("Error while sending response: "+ex.getMessage()); LogFactory.getLogger(SnmpRequest.class).error(ex); } } } }
(command.getType() != PDU.REPORT) && (command.getType() != PDU.RESPONSE)) { command.setErrorIndex(0); command.setErrorStatus(0); command.setType(PDU.RESPONSE);
/** * Sends a RESPONSE PDU to the source address of a INFORM request. * @param event * the <code>CommandResponderEvent</code> with the INFORM request. * @throws * MessageException if the response could not be created and sent. */ protected void sendInformResponse(CommandResponderEvent event) throws MessageException { PDU responsePDU = (PDU) event.getPDU().clone(); responsePDU.setType(PDU.RESPONSE); responsePDU.setErrorStatus(PDU.noError); responsePDU.setErrorIndex(0); messageDispatcher.returnResponsePdu(event.getMessageProcessingModel(), event.getSecurityModel(), event.getSecurityName(), event.getSecurityLevel(), responsePDU, event.getMaxSizeResponsePDU(), event.getStateReference(), new StatusInformation()); } }
/** * Sends a RESPONSE PDU to the source address of a INFORM request. * @param event * the <code>CommandResponderEvent</code> with the INFORM request. * @throws * MessageException if the response could not be created and sent. */ protected void sendInformResponse(CommandResponderEvent event) throws MessageException { PDU responsePDU = (PDU) event.getPDU().clone(); responsePDU.setType(PDU.RESPONSE); responsePDU.setErrorStatus(PDU.noError); responsePDU.setErrorIndex(0); messageDispatcher.returnResponsePdu(event.getMessageProcessingModel(), event.getSecurityModel(), event.getSecurityName(), event.getSecurityLevel(), responsePDU, event.getMaxSizeResponsePDU(), event.getStateReference(), new StatusInformation()); } }
/** * Sends a RESPONSE PDU to the source address of a INFORM request. * * @param event * the <code>CommandResponderEvent</code> with the INFORM request. * * @throws MessageException * if the response could not be created and sent. */ protected void sendInformResponse(CommandResponderEvent event) throws MessageException { PDU responsePDU = (PDU) event.getPDU().clone(); responsePDU.setType(PDU.RESPONSE); responsePDU.setErrorStatus(PDU.noError); responsePDU.setErrorIndex(0); messageDispatcher.returnResponsePdu(event.getMessageProcessingModel(), event.getSecurityModel(), event.getSecurityName(), event.getSecurityLevel(), responsePDU, event.getMaxSizeResponsePDU(), event.getStateReference(), new StatusInformation()); } }
if (command.getType() == PDU.INFORM) { PDU response = new PDU(command); response.setErrorIndex(0); response.setErrorStatus(0); response.setType(PDU.RESPONSE);
@Override protected void doStart() throws Exception { super.doStart(); this.targetAddress = GenericAddress.parse(this.endpoint.getAddress()); LOG.debug("targetAddress: {}", targetAddress); this.usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0); SecurityModels.getInstance().addSecurityModel(this.usm); // setting up target this.target = new CommunityTarget(); this.target.setCommunity(new OctetString(endpoint.getSnmpCommunity())); this.target.setAddress(this.targetAddress); this.target.setRetries(this.endpoint.getRetries()); this.target.setTimeout(this.endpoint.getTimeout()); this.target.setVersion(this.endpoint.getSnmpVersion()); this.pdu = new PDU(); for (OID oid : this.endpoint.getOids()) { this.pdu.add(new VariableBinding(oid)); } this.pdu.setErrorIndex(0); this.pdu.setErrorStatus(0); this.pdu.setMaxRepetitions(0); this.pdu.setType(PDU.GET); }