⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snmpcommunitymib.java

📁 你个snmp的源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
   */
  static class SnmpTargetAddrTMaskValidator implements MOValueValidationListener {

    public void validate(MOValueValidationEvent validationEvent) {
      Variable newValue = validationEvent.getNewValue();
      OctetString os = (OctetString)newValue;
      if (!(((os.length() >= 0) && (os.length() <= 255)))) {
        validationEvent.setValidationStatus(SnmpConstants.SNMP_ERROR_WRONG_LENGTH);
        return;
      }
     //--AgentGen BEGIN=snmpTargetAddrTMask::validate
     //--AgentGen END
    }
  }
  /**
   * The <code>SnmpTargetAddrMMSValidator</code> implements the value
   * validation for <code>SnmpTargetAddrMMS</code>.
   */
  static class SnmpTargetAddrMMSValidator implements MOValueValidationListener {

    public void validate(MOValueValidationEvent validationEvent) {
      Variable newValue = validationEvent.getNewValue();
      long v = ((Integer32)newValue).getValue();
      if (!(((v >= 0L) && (v <= 0L)) ||
          ((v >= 484L)))) {
        validationEvent.setValidationStatus(SnmpConstants.SNMP_ERROR_WRONG_VALUE);
        return;
      }
     //--AgentGen BEGIN=snmpTargetAddrMMS::validate
     //--AgentGen END
    }
  }



  // Rows and Factories
  class SnmpCommunityEntryRowFactory
        extends DefaultMOMutableRow2PCFactory
  {
    public synchronized MOTableRow createRow(OID index, Variable[] values)
        throws UnsupportedOperationException
    {
      SnmpCommunityEntryRow row = new SnmpCommunityEntryRow(index, values);
      //--AgentGen BEGIN=snmpCommunityEntry::createRow
      if (coexistenceInfo == null) {
        coexistenceInfo = Collections.synchronizedMap(new HashMap());
      }
      coexistenceInfo.put(values[idxSnmpCommunityName], row);
      if (communityInfo == null) {
        communityInfo = Collections.synchronizedMap(new HashMap());
      }
      List l = (List) communityInfo.get(values[idxSnmpCommunitySecurityName]);
      if (l == null) {
        l = new LinkedList();
        communityInfo.put(values[idxSnmpCommunitySecurityName], l);
      }
      l.add(row);
      //--AgentGen END
      return row;
    }

    public synchronized void freeRow(MOTableRow row) {
     //--AgentGen BEGIN=snmpCommunityEntry::freeRow
     coexistenceInfo.remove(row.getValue(idxSnmpCommunityName));
     List l =
         (List) communityInfo.get(row.getValue(idxSnmpCommunitySecurityName));
     if (l != null) {
       l.remove(row);
       if (l.size() == 0) {
         communityInfo.remove(row.getValue(idxSnmpCommunitySecurityName));
       }
     }
     //--AgentGen END
    }
  }

  class SnmpCommunityEntryRow extends DefaultMOMutableRow2PC {
    public SnmpCommunityEntryRow(OID index, Variable[] values) {
      super(index, values);
    }

    public OctetString getSnmpCommunityName() {
      return (OctetString) getValue(idxSnmpCommunityName);
    }

    public void setSnmpCommunityName(OctetString newValue) {
      setValue(idxSnmpCommunityName, newValue);
    }

    public OctetString getSnmpCommunitySecurityName() {
      return (OctetString) getValue(idxSnmpCommunitySecurityName);
    }

    public void setSnmpCommunitySecurityName(OctetString newValue) {
      setValue(idxSnmpCommunitySecurityName, newValue);
    }

    public OctetString getSnmpCommunityContextEngineID() {
      return (OctetString) getValue(idxSnmpCommunityContextEngineID);
    }

    public void setSnmpCommunityContextEngineID(OctetString newValue) {
      setValue(idxSnmpCommunityContextEngineID, newValue);
    }

    public OctetString getSnmpCommunityContextName() {
      return (OctetString) getValue(idxSnmpCommunityContextName);
    }

    public void setSnmpCommunityContextName(OctetString newValue) {
      setValue(idxSnmpCommunityContextName, newValue);
    }

    public OctetString getSnmpCommunityTransportTag() {
      return (OctetString) getValue(idxSnmpCommunityTransportTag);
    }

    public void setSnmpCommunityTransportTag(OctetString newValue) {
      setValue(idxSnmpCommunityTransportTag, newValue);
    }

    public Integer32 getSnmpCommunityStorageType() {
      return (Integer32) getValue(idxSnmpCommunityStorageType);
    }

    public void setSnmpCommunityStorageType(Integer32 newValue) {
      setValue(idxSnmpCommunityStorageType, newValue);
    }

    public Integer32 getSnmpCommunityStatus() {
      return (Integer32) getValue(idxSnmpCommunityStatus);
    }

    public void setSnmpCommunityStatus(Integer32 newValue) {
      setValue(idxSnmpCommunityStatus, newValue);
    }


     //--AgentGen BEGIN=snmpCommunityEntry::RowFactory
     //--AgentGen END
  }

  class SnmpTargetAddrExtEntryRowFactory
        extends DefaultMOMutableRow2PCFactory
  {
    public MOTableRow createRow(OID index, Variable[] values)
        throws UnsupportedOperationException
    {
      SnmpTargetAddrExtEntryRow row = new SnmpTargetAddrExtEntryRow(index, values);
     //--AgentGen BEGIN=snmpTargetAddrExtEntry::createRow
     //--AgentGen END
      return row;
    }

    public void freeRow(MOTableRow row) {
     //--AgentGen BEGIN=snmpTargetAddrExtEntry::freeRow
     //--AgentGen END
    }
  }

  class SnmpTargetAddrExtEntryRow extends DefaultMOMutableRow2PC {
    public SnmpTargetAddrExtEntryRow(OID index, Variable[] values) {
      super(index, values);
    }

    public OctetString getSnmpTargetAddrTMask() {
      return (OctetString) getValue(idxSnmpTargetAddrTMask);
    }

    public void setSnmpTargetAddrTMask(OctetString newValue) {
      setValue(idxSnmpTargetAddrTMask, newValue);
    }

    public Integer32 getSnmpTargetAddrMMS() {
      return (Integer32) getValue(idxSnmpTargetAddrMMS);
    }

    public void setSnmpTargetAddrMMS(Integer32 newValue) {
      setValue(idxSnmpTargetAddrMMS, newValue);
    }


     //--AgentGen BEGIN=snmpTargetAddrExtEntry::RowFactory
     //--AgentGen END
  }



//--AgentGen BEGIN=_METHODS

  public CoexistenceInfo getCoexistenceInfo(OctetString community) {
    if (logger.isDebugEnabled()) {
      logger.debug("Looking up coexistence info for '"+community+"'");
    }
    if (coexistenceInfo == null) {
      return null;
    }
    SnmpCommunityEntryRow row =
        (SnmpCommunityEntryRow) coexistenceInfo.get(community);
    if (row != null) {
      CoexistenceInfo info =
          new CoexistenceInfo(row.getSnmpCommunitySecurityName(),
                              row.getSnmpCommunityContextEngineID(),
                              row.getSnmpCommunityContextName(),
                              row.getSnmpCommunityTransportTag());
      if (logger.isDebugEnabled()) {
        logger.debug("Found coexistence info for '"+community+"'="+info);
      }
      return info;
    }
    return null;
  }

  /**
   * Checks whether the supplied address passes the source address filter
   * configured for the supplied transport tag. The tag identifies a set of
   * addresses configured in the snmpTargetAddrTable which is extended by
   * the snmpTargetAddrExtTable. The transport address mask allows entries
   * in the snmpTargetAddrTable to define a set of addresses instead of
   * just a single address.
   *
   * @param address
   *    the address of the incoming packet to check.
   * @param coexistenceInfo
   *    a set of coexistence information that provides the transport tag that
   *    is used to identify allowed source addresses. On return, the maximum
   *    message size attribute of the coexistence info set will be set
   *    according to the values defined for the matched source address in
   *    the snmpTargetAddrExtTable.
   * @return boolean
   */
  public boolean passesFilter(Address address,
                              CoexistenceInfo coexistenceInfo) {
    if (!isSourceAddressFiltering()) {
      if (logger.isDebugEnabled()) {
        logger.debug("Address "+address+
                     " passes filter, "+
                     "because source address filtering is disabled");
      }
      return true;
    }
    if ((coexistenceInfo.getTransportTag() == null) ||
        (coexistenceInfo.getTransportTag().length() == 0)) {
      if (logger.isDebugEnabled()) {
        logger.debug("Address "+address+
                     " passes filter, because transportTag is null");
      }
      return true;
    }
    Collection matches =
        targetMIB.getTargetAddrRowsForTag(coexistenceInfo.getTransportTag());
    for (Iterator it = matches.iterator(); it.hasNext(); ) {
      SnmpTargetAddrEntryRow row = (SnmpTargetAddrEntryRow) it.next();
      SnmpTargetAddrExtEntryRow extRow = (SnmpTargetAddrExtEntryRow)
          snmpTargetAddrExtEntryModel.getRow(row.getIndex());
      OctetString filterTAddress =
          (OctetString) row.getValue(SnmpTargetMIB.idxSnmpTargetAddrTAddress);
      if (extRow != null) {
        OctetString mask = extRow.getSnmpTargetAddrTMask();
        OctetString matchAddress = row.getTAddress(address);
        if ((mask.length() == 0) &&
            (matchAddress != null) && (matchAddress.equals(filterTAddress))) {
          coexistenceInfo.setMaxMessageSize(
              extRow.getSnmpTargetAddrMMS().getValue());
          return true;
        }
        else if ((matchAddress != null) &&
                 (mask.length() == matchAddress.length()) &&
                 (matchAddress.length() == filterTAddress.length())) {
          OctetString maskedFilterTAddress = filterTAddress.mask(mask);
          OctetString maskedMatchTAddress = matchAddress.mask(mask);
          if (maskedFilterTAddress.equals(maskedMatchTAddress)) {
            coexistenceInfo.setMaxMessageSize(
                extRow.getSnmpTargetAddrMMS().getValue());
            return true;
          }
        }
      }
    }
    return false;
  }

  /**
   * Enables or disables source address filtering for incoming SNMPv1 or SNMPv2c
   * packets. By default source address filtering is disabled! If enabled, only
   * messages received for community based security models are processed, that
   * match an address in the snmpTargetAddressTable with the transport tag
   * associated with the community used.
   *
   * @param sourceAddressFiltering
   *    if <code>true</code> source address filtering is enabled, otherwise
   *    it is disabled.
   */
  public void setSourceAddressFiltering(boolean sourceAddressFiltering) {
    this.sourceAddressFiltering = sourceAddressFiltering;
  }

  /**
   * Returns <code>true</code> if source address filtering is enabled. In that
   * case a call to {@link #passesFilter} will always return <code>true</code>.
   * @return
   *    <code>true</code> if source address filtering is enabled,
   *    <code>false</code> otherwise.
   */
  public boolean isSourceAddressFiltering() {
    return sourceAddressFiltering;
  }

  public OctetString getCommunity(OctetString securityName,
                                  OctetString contextEngineID,
                                  OctetString contextName) {
    List l = (List) communityInfo.get(securityName);
    if (l != null) {
      for (Iterator it = l.iterator(); it.hasNext(); ) {
        SnmpCommunityEntryRow row = (SnmpCommunityEntryRow) it.next();
        if (row.getSnmpCommunityStatus().getValue() == RowStatus.active) {
          if (((contextEngineID == null) ||
               (contextEngineID.equals(row.getSnmpCommunityContextEngineID()))) &&
              ((row.getSnmpCommunityContextName().equals(contextName)))) {
            return row.getSnmpCommunityName();
          }
        }
      }
    }
    return null;
  }

  //--AgentGen END

//--AgentGen BEGIN=_CLASSES
//--AgentGen END

//--AgentGen BEGIN=_END
//--AgentGen END
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -