Package org.snmp4j.smi

Examples of org.snmp4j.smi.OctetString


  public OctetString getAddress(Address address) {
    if (address instanceof TransportIpAddress) {
      TransportIpAddress tipaddr = (TransportIpAddress) address;
      byte[] addrBytes = tipaddr.getInetAddress().getAddress();
      OctetString addr = new OctetString(addrBytes);
      addr.append((byte) (tipaddr.getPort() >> 8));
      addr.append((byte) (tipaddr.getPort() & 0xFF));
      return addr;
    }
    return null;
  }
View Full Code Here


  public static int isValidTagList(Variable newValue) {
    if (!(newValue instanceof OctetString)) {
      return SnmpConstants.SNMP_ERROR_WRONG_TYPE;
    }
    OctetString os = (OctetString)newValue;
    if (os.length() > 255) {
      return SnmpConstants.SNMP_ERROR_WRONG_LENGTH;
    }
    else if (os.length() > 0) {
      if (SnmpTagValue.isDelimiter(os.get(0)) ||
          SnmpTagValue.isDelimiter(os.get(os.length()-1))) {
        return SnmpConstants.SNMP_ERROR_BAD_VALUE;
      }
      boolean lastWasDelimiter = false;
      for (int i = 0; i < os.length()-1; i++) {
        boolean isDelimiter = SnmpTagValue.isDelimiter(os.get(i));
        if (lastWasDelimiter && isDelimiter) {
          return SnmpConstants.SNMP_ERROR_BAD_VALUE;
        }
        lastWasDelimiter = isDelimiter;
      }
View Full Code Here

   *    {@link SnmpConstants#SNMP_ERROR_SUCCESS} if <code>dateAndTime</code>
   *    is valid or an appropriate SNMP error code if not.
   */
  public static int validateDateAndTime(Variable dateAndTime) {
    if (dateAndTime instanceof OctetString) {
      OctetString os = (OctetString)dateAndTime;
      if ((os.length() != 8) && (os.length() != 11)) {
        return SnmpConstants.SNMP_ERROR_WRONG_LENGTH;
      }
      int month = (os.get(2) & 0xFF );
      int date = (os.get(3) & 0xFF );
      int hour = (os.get(4) & 0xFF );
      int minute = (os.get(5) & 0xFF );
      int second = (os.get(6) & 0xFF );
      int deci = (os.get(7) & 0xFF );
      if ((month < 1) || (month > 12) ||
          (date < 1) || (date > 31) || (hour > 23) || (second > 59) ||
          (minute > 59) || (deci > 9)) {
        return SnmpConstants.SNMP_ERROR_WRONG_VALUE;
      }
      if (os.length() == 11) {
        if ((os.get(8) != '+') && (os.get(8) != '-')) {
          return SnmpConstants.SNMP_ERROR_WRONG_VALUE;
        }
      }
      return SnmpConstants.SNMP_ERROR_SUCCESS;
    }
View Full Code Here

   *    a <code>GregorianCalendar</code> instance.
   * @return
   *    the corresponding DateAndTime <code>OctetString</code>.
   */
  public static OctetString makeDateAndTime(GregorianCalendar dateAndTime) {
    OctetString os = new OctetString();
    os.append((byte)(dateAndTime.get(Calendar.YEAR)/256));
    os.append((byte)(dateAndTime.get(Calendar.YEAR)%256));
    os.append((byte)(dateAndTime.get(Calendar.MONTH)+1));
    os.append((byte)(dateAndTime.get(Calendar.DAY_OF_MONTH)));
    os.append((byte)(dateAndTime.get(Calendar.HOUR_OF_DAY)));
    os.append((byte)(dateAndTime.get(Calendar.MINUTE)));
    os.append((byte)(dateAndTime.get(Calendar.SECOND)));
    os.append((byte)(dateAndTime.get(Calendar.MILLISECOND)/100));
    if (dateAndTime.getTimeZone() != null) {
      TimeZone tz = dateAndTime.getTimeZone();
      os.append((tz.getRawOffset()>=0) ? "+":"-");
      os.append((byte)(tz.getOffset(dateAndTime.getTimeInMillis())/3600000));
      os.append((byte)(tz.getOffset((dateAndTime.getTimeInMillis())%3600000)/60000));
    }
    return os;
  }
View Full Code Here

        } else {
            throw new IllegalArgumentException("Unknown protocol: " + endpoint.getProtocol());
        }

        this.snmp = new Snmp(this.transport);
        this.usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
        SecurityModels.getInstance().addSecurityModel(usm);

        // setting up target
        target = new CommunityTarget();
        target.setCommunity(new OctetString(this.endpoint.getSnmpCommunity()));
        target.setAddress(targetAddress);
        target.setRetries(this.endpoint.getRetries());
        target.setTimeout(this.endpoint.getTimeout());
        target.setVersion(this.endpoint.getSnmpVersion());
View Full Code Here

      logger.error("MPv1 used with unsupported SNMP version");
      return SnmpConstants.SNMP_MP_UNSUPPORTED_SECURITY_MODEL;
    }


    OctetString community = new OctetString(securityName);
    Integer32 version = new Integer32(messageProcessingModel);
    // compute total length
    int length = pdu.getBERLength();
    length += community.getBERLength();
    length += version.getBERLength();

    ByteBuffer buf = ByteBuffer.allocate(length +
                                         BER.getBERLengthOfLength(length) + 1);
    // set the buffer of the outgoing message
    outgoingMessage.setBuffer(buf);

    // encode the message
    BER.encodeHeader(outgoingMessage, BER.SEQUENCE, length);
    version.encodeBER(outgoingMessage);

    community.encodeBER(outgoingMessage);
    pdu.encodeBER(outgoingMessage);

    return SnmpConstants.SNMP_MP_OK;
  }
View Full Code Here

  /**
   * Creates a new user entry with empty engine ID and empty user.
   */
  public UsmUserEntry() {
    engineID = new OctetString();
    userName = new OctetString();
    usmUser = new UsmUser(new OctetString(), null, null, null, null);
  }
View Full Code Here

   *    the privacy key.
   */
  public UsmUserEntry(byte[] engineID, OctetString securityName,
                      OID authProtocol, byte[] authKey,
                      OID privProtocol, byte[] privKey) {
    this.engineID = (engineID == null) ? null : new OctetString(engineID);
    this.userName = securityName;
    this.authenticationKey = authKey;
    this.privacyKey = privKey;
    this.usmUser =
        new UsmUser(userName, authProtocol,
                    ((authenticationKey != null) ?
                     new OctetString(authenticationKey) : null),
                    privProtocol,
                    ((privacyKey != null) ?
                     new OctetString(privacyKey) : null), this.engineID);
  }
View Full Code Here

    byte[] extendedKey = new byte[getMinKeyLength()];
    System.arraycopy(shortKey, 0, extendedKey, 0, shortKey.length);

    while (length < getMinKeyLength()) {
      byte[] key =
          authProtocol.passwordToKey(new OctetString(extendedKey, 0, length),
                                     engineID);
      int copyBytes = Math.min(getMinKeyLength() - length,
                               authProtocol.getDigestLength());
      System.arraycopy(key, 0, extendedKey, length, copyBytes);
      length += copyBytes;
View Full Code Here

   *
   * @param buf  Array of bytes to convert to hex string
   * @return  Generated hex string
   */
  public static String asHex(byte buf[]) {
    return new OctetString(buf).toHexString();
  }
View Full Code Here

TOP

Related Classes of org.snmp4j.smi.OctetString

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.