Ejemplo n.º 1
0
  void discoverIfNeeded() throws java.io.IOException, PduException {
    uk.co.westhawk.snmp.beans.UsmDiscoveryBean discBean = null;
    boolean isNeeded = false;

    TimeWindow tWindow = TimeWindow.getCurrent();
    String engineId = tWindow.getSnmpEngineId(hostAddr, hostPort);
    if (engineId == null) {
      isNeeded = true;
      discBean = new uk.co.westhawk.snmp.beans.UsmDiscoveryBean(hostAddr, hostPort, typeSocket);
    }

    if (isUseAuthentication()) {
      if (isNeeded) {
        discBean.setAuthenticationDetails(
            userName, userAuthenticationPassword, authenticationProtocol);
      } else if (tWindow.isTimeLineKnown(engineId) == false) {
        isNeeded = true;
        discBean = new uk.co.westhawk.snmp.beans.UsmDiscoveryBean(hostAddr, hostPort, typeSocket);
        discBean.setAuthenticationDetails(
            userName, userAuthenticationPassword, authenticationProtocol);
      }

      if (isNeeded && isUsePrivacy()) {
        discBean.setPrivacyDetails(userPrivacyPassword);
      }
    }

    if (isNeeded) {
      discBean.startDiscovery();
    }
  }
Ejemplo 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);
  }