Esempio n. 1
0
  /**
   * Encodes a discovery pdu packet. This methods encodes without checking is the discovery
   * paramters are all known.
   */
  public byte[] encodeDiscoveryPacket(
      byte msg_type, int rId, int errstat, int errind, Enumeration ve)
      throws java.io.IOException, EncodingException {
    String engineId = "";
    TimeWindow tWindow = TimeWindow.getCurrent();
    if (tWindow.isSnmpEngineIdKnown(hostAddr, hostPort) == true) {
      engineId = tWindow.getSnmpEngineId(hostAddr, hostPort);
    }
    TimeWindowNode node = new TimeWindowNode(engineId, 0, 0);

    return actualEncodePacket(msg_type, rId, errstat, errind, ve, node);
  }
Esempio n. 2
0
  /**
   * Encodes a pdu packet. If the stack is authoritative, the timeline details are retrieved from
   * the usmAgent. If not, this methods first checks if all the discovery paramters are all known,
   * if not it will throw an EncodingException. If so, it encodes and returns the bytes.
   */
  public byte[] encodePacket(byte msg_type, int rId, int errstat, int errind, Enumeration ve)
      throws java.io.IOException, EncodingException {
    TimeWindowNode node;
    if (isDestroyed == true) {
      throw new EncodingException("Context can no longer be used, since it is already destroyed");
    } else {
      if (isAuthoritative(msg_type) == true) {
        usmAgent.setSnmpContext(this);
        node =
            new TimeWindowNode(
                usmAgent.getSnmpEngineId(),
                usmAgent.getSnmpEngineBoots(),
                usmAgent.getSnmpEngineTime());
      } else {
        TimeWindow tWindow = TimeWindow.getCurrent();
        if (tWindow.isSnmpEngineIdKnown(hostAddr, hostPort) == false) {
          throw new EncodingException(
              "Engine ID of host "
                  + hostAddr
                  + ", port "
                  + hostPort
                  + " is unknown. Perform discovery.");
        }
        String engineId = tWindow.getSnmpEngineId(hostAddr, hostPort);
        node = new TimeWindowNode(engineId, 0, 0);

        if (isUseAuthentication()) {
          if (tWindow.isTimeLineKnown(engineId) == true) {
            node = tWindow.getTimeLine(engineId);
          } else {
            throw new EncodingException(
                "Time Line of Engine ID of host "
                    + hostAddr
                    + ", port "
                    + hostPort
                    + " is unknown. "
                    + "Perform discovery.");
          }
        }
      }
    }
    return actualEncodePacket(msg_type, rId, errstat, errind, ve, node);
  }