org.snmp4j.PDU.setErrorIndex()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中org.snmp4j.PDU.setErrorIndex()方法的一些代码示例,展示了PDU.setErrorIndex()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PDU.setErrorIndex()方法的具体详情如下:
包路径:org.snmp4j.PDU
类名称:PDU
方法名:setErrorIndex

PDU.setErrorIndex介绍

[英]Sets the error index.
[中]设置错误索引。

代码示例

代码示例来源:origin: org.jboss.jbossas/jboss-snmp

/** 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);
}

代码示例来源:origin: org.mobicents.tools.snmp.adaptor/core

/** 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);
}

代码示例来源:origin: org.apache.camel/camel-snmp

PDU trap = exchange.getIn().getBody(PDU.class);
trap.setErrorIndex(0);
trap.setErrorStatus(0);
trap.setMaxRepetitions(0);

代码示例来源:origin: org.snmp4j/snmp4j-agent

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;
}

代码示例来源:origin: org.kaazing/snmp4j-agent

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;
}

代码示例来源:origin: OpenNMS/opennms

int type = command.getType();
command.setErrorIndex(0);
command.setErrorStatus(0);
command.setType(PDU.RESPONSE);
} finally {
  command.setErrorIndex(errorIndex);
  command.setErrorStatus(errorStatus);
  command.setType(type);

代码示例来源:origin: OpenNMS/opennms

/**
 * @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;
}

代码示例来源:origin: OpenNMS/opennms

/**
 * @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;
}

代码示例来源:origin: org.opennms.core.snmp/org.opennms.core.snmp.implementations.snmp4j

int type = command.getType();
command.setErrorIndex(0);
command.setErrorStatus(0);
command.setType(PDU.RESPONSE);
} finally {
  command.setErrorIndex(errorIndex);
  command.setErrorStatus(errorStatus);
  command.setType(type);

代码示例来源:origin: org.kaazing/snmp4j-agent

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());

代码示例来源:origin: org.snmp4j/snmp4j-agent

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());

代码示例来源:origin: org.apache.camel/camel-snmp

pdu.setErrorIndex(0);
pdu.setErrorStatus(0);
pdu.setType(PDU.RESPONSE);

代码示例来源:origin: org.snmp4j/snmp4j

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);
      }
    }
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.snmp4j

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);
   }
  }
 }
}

代码示例来源:origin: org.kaazing/snmp4j

(command.getType() != PDU.REPORT) &&
 (command.getType() != PDU.RESPONSE)) {
command.setErrorIndex(0);
command.setErrorStatus(0);
command.setType(PDU.RESPONSE);

代码示例来源:origin: org.kaazing/snmp4j

/**
  * 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());
 }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.snmp4j

/**
  * 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());
 }
}

代码示例来源:origin: org.snmp4j/snmp4j

/**
   * 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());
  }
}

代码示例来源:origin: org.opennms.lib.snmp/org.opennms.lib.snmp.snmp4j

if (command.getType() == PDU.INFORM) {
  PDU response = new PDU(command);
  response.setErrorIndex(0);
  response.setErrorStatus(0);
  response.setType(PDU.RESPONSE);

代码示例来源:origin: org.apache.camel/camel-snmp

@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);
  
}

相关文章