📄 snmptargetmib.java
字号:
/*_############################################################################
_##
_## SNMP4J-Agent - SnmpTargetMIB.java
_##
_## Copyright 2005-2006 Frank Fock (SNMP4J.org)
_##
_## Licensed under the Apache License, Version 2.0 (the "License");
_## you may not use this file except in compliance with the License.
_## You may obtain a copy of the License at
_##
_## http://www.apache.org/licenses/LICENSE-2.0
_##
_## Unless required by applicable law or agreed to in writing, software
_## distributed under the License is distributed on an "AS IS" BASIS,
_## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
_## See the License for the specific language governing permissions and
_## limitations under the License.
_##
_##########################################################################*/
package org.snmp4j.agent.mo.snmp;
//--AgentGen BEGIN=_BEGIN
//--AgentGen END
import java.util.*;
import org.snmp4j.*;
import org.snmp4j.agent.*;
import org.snmp4j.agent.mo.*;
import org.snmp4j.agent.request.*;
import org.snmp4j.event.*;
import org.snmp4j.log.*;
import org.snmp4j.mp.*;
import org.snmp4j.security.*;
import org.snmp4j.smi.*;
import java.net.Inet4Address;
import java.net.Inet6Address;
//--AgentGen BEGIN=_IMPORT
//--AgentGen END
public class SnmpTargetMIB implements MOGroup, CounterListener,
MOTableRowListener {
private static final LogAdapter logger =
LogFactory.getLogger(SnmpTargetMIB.class);
// Constants
private static final OID oidSnmpTargetSpinLock =
new OID(new int[] {1, 3, 6, 1, 6, 3, 12, 1, 1, 0});
private MOScalar snmpTargetSpinLock;
private static final OID oidSnmpUnknownContexts =
new OID(new int[] {1, 3, 6, 1, 6, 3, 12, 1, 5, 0});
private MOScalar snmpUnknownContexts;
private static final OID oidSnmpUnavailableContexts =
new OID(new int[] {1, 3, 6, 1, 6, 3, 12, 1, 4, 0});
private MOScalar snmpUnavailableContexts;
private static final OID oidSnmpTargetParamsEntry =
new OID(new int[] {1, 3, 6, 1, 6, 3, 12, 1, 3, 1});
// Column sub-identifer defintions for snmpTargetParamsEntry:
private static final int colSnmpTargetParamsMPModel = 2;
private static final int colSnmpTargetParamsSecurityModel = 3;
private static final int colSnmpTargetParamsSecurityName = 4;
private static final int colSnmpTargetParamsSecurityLevel = 5;
private static final int colSnmpTargetParamsStorageType = 6;
private static final int colSnmpTargetParamsRowStatus = 7;
// Column index defintions for snmpTargetParamsEntry:
static final int idxSnmpTargetParamsMPModel = 0;
static final int idxSnmpTargetParamsSecurityModel = 1;
static final int idxSnmpTargetParamsSecurityName = 2;
static final int idxSnmpTargetParamsSecurityLevel = 3;
static final int idxSnmpTargetParamsStorageType = 4;
static final int idxSnmpTargetParamsRowStatus = 5;
private static MOTableSubIndex[] snmpTargetParamsEntryIndexes =
new MOTableSubIndex[] {
new MOTableSubIndex(SMIConstants.SYNTAX_OCTET_STRING, 1, 32)
};
private static MOTableIndex snmpTargetParamsEntryIndex =
new MOTableIndex(snmpTargetParamsEntryIndexes, true) {
public boolean isValidIndex(OID index) {
boolean isValidIndex = super.isValidIndex(index);
if (isValidIndex) {
//--AgentGen BEGIN=snmpTargetParamsEntry::isValidIndex
//--AgentGen END
}
return isValidIndex;
}
};
private DefaultMOTable snmpTargetParamsEntry;
private DefaultMOMutableTableModel snmpTargetParamsEntryModel;
private static final OID oidSnmpTargetAddrEntry =
new OID(new int[] {1, 3, 6, 1, 6, 3, 12, 1, 2, 1});
// Column sub-identifer defintions for snmpTargetAddrEntry:
private static final int colSnmpTargetAddrTDomain = 2;
private static final int colSnmpTargetAddrTAddress = 3;
private static final int colSnmpTargetAddrTimeout = 4;
private static final int colSnmpTargetAddrRetryCount = 5;
private static final int colSnmpTargetAddrTagList = 6;
private static final int colSnmpTargetAddrParams = 7;
private static final int colSnmpTargetAddrStorageType = 8;
private static final int colSnmpTargetAddrRowStatus = 9;
// Column index defintions for snmpTargetAddrEntry:
static final int idxSnmpTargetAddrTDomain = 0;
static final int idxSnmpTargetAddrTAddress = 1;
static final int idxSnmpTargetAddrTimeout = 2;
static final int idxSnmpTargetAddrRetryCount = 3;
static final int idxSnmpTargetAddrTagList = 4;
static final int idxSnmpTargetAddrParams = 5;
static final int idxSnmpTargetAddrStorageType = 6;
static final int idxSnmpTargetAddrRowStatus = 7;
private static MOTableSubIndex[] snmpTargetAddrEntryIndexes =
new MOTableSubIndex[] {
new MOTableSubIndex(SMIConstants.SYNTAX_OCTET_STRING, 1, 32)
};
private static MOTableIndex snmpTargetAddrEntryIndex =
new MOTableIndex(snmpTargetAddrEntryIndexes, true) {
public boolean isValidIndex(OID index) {
boolean isValidIndex = super.isValidIndex(index);
if (isValidIndex) {
//--AgentGen BEGIN=snmpTargetAddrEntry::isValidIndex
//--AgentGen END
}
return isValidIndex;
}
};
private static final OID[] DEFAULT_TDOMAINS = {
TransportDomains.snmpUDPDomain,
TransportDomains.transportDomainTcpIpv4,
TransportDomains.transportDomainTcpIpv6,
TransportDomains.transportDomainUdpIpv4,
TransportDomains.transportDomainUdpIpv6
};
private DefaultMOTable snmpTargetAddrEntry;
private DefaultMOMutableTableModel snmpTargetAddrEntryModel;
private Hashtable snmpTargetAddrTagIndex = new Hashtable();
// maps TDomain OIDs to TDomainAddressFactory instances
private Hashtable supportedAddressClasses = new Hashtable();
private Snmp session;
private CoexistenceInfoProvider coexistenceProvider;
public SnmpTargetMIB(Snmp session) {
this.session = session;
snmpTargetSpinLock = new TestAndIncr(oidSnmpTargetSpinLock);
snmpUnknownContexts =
new MOScalar(oidSnmpUnknownContexts,
MOAccessImpl.ACCESS_READ_ONLY, new Counter32());
snmpUnavailableContexts =
new MOScalar(oidSnmpUnavailableContexts,
MOAccessImpl.ACCESS_READ_ONLY, new Counter32());
createSnmpTargetParamsEntry();
createSnmpTargetAddrEntry();
}
public Collection getTargetAddrRowsForTag(OctetString tag) {
Collection l = (Collection)snmpTargetAddrTagIndex.get(tag);
if (l == null) {
return Collections.EMPTY_SET;
}
else {
synchronized (l) {
l = new ArrayList(l);
}
}
return l;
}
public Address getTargetAddress(OctetString name) {
OID index = name.toSubIndex(true);
SnmpTargetAddrEntryRow trow =
(SnmpTargetAddrEntryRow) this.snmpTargetAddrEntryModel.getRow(index);
if (trow != null) {
return trow.getAddress();
}
return null;
}
public Target getTarget(OctetString name,
OctetString contextEngineID,
OctetString contextName) {
OID index = name.toSubIndex(true);
SnmpTargetAddrEntryRow trow =
(SnmpTargetAddrEntryRow) this.snmpTargetAddrEntryModel.getRow(index);
if (trow != null) {
return trow.getTarget(contextEngineID, contextName);
}
return null;
}
public void addDefaultTDomains() {
TDomainAddressFactoryImpl factory = new TDomainAddressFactoryImpl();
for (int i=0; i<DEFAULT_TDOMAINS.length; i++) {
supportedAddressClasses.put(DEFAULT_TDOMAINS[i], factory);
}
}
public void addSupportedTDomain(OID transportDomain,
TDomainAddressFactory factory) {
supportedAddressClasses.put(transportDomain, factory);
}
public boolean addTargetAddress(OctetString name,
OID transportDomain, OctetString address,
int timeout, int retries,
OctetString tagList,
OctetString params,
int storageType) {
Variable[] vbs = new Variable[snmpTargetAddrEntry.getColumnCount()];
int n=0;
vbs[n++] = transportDomain;
vbs[n++] = address;
vbs[n++] = new Integer32(timeout);
vbs[n++] = new Integer32(retries);
vbs[n++] = tagList;
vbs[n++] = params;
vbs[n++] = new Integer32(storageType);
vbs[n++] = new Integer32(RowStatus.active);
OID index = name.toSubIndex(true);
MOTableRow row = snmpTargetAddrEntry.createRow(index, vbs);
snmpTargetAddrEntry.addRow(row);
return true;
}
public MOTableRow removeTargetAddress(OctetString name) {
OID index = name.toSubIndex(true);
MOTableRow removedRow = snmpTargetAddrEntryModel.removeRow(index);
if (removedRow != null) {
removeRowFromTargetAddrTagIndex(removedRow);
}
return removedRow;
}
protected void removeRowFromTargetAddrTagIndex(MOTableRow removedRow) {
OctetString tagList =
(OctetString) removedRow.getValue(idxSnmpTargetAddrTagList);
Set tags = SnmpTagList.getTags(tagList);
if ((tags != null) && (this.snmpTargetAddrTagIndex != null)) {
for (Iterator it = tags.iterator(); it.hasNext(); ) {
Object item = it.next();
Collection indexRows =
(Collection) this.snmpTargetAddrTagIndex.get(item);
if (indexRows != null) {
synchronized (indexRows) {
indexRows.remove(removedRow);
if (indexRows.isEmpty()) {
this.snmpTargetAddrTagIndex.remove(item);
}
}
}
}
}
}
public boolean addTargetParams(OctetString name, int mpModel, int secModel,
OctetString secName, int secLevel,
int storageType) {
Variable[] vbs = new Variable[snmpTargetParamsEntry.getColumnCount()];
int n=0;
vbs[n++] = new Integer32(mpModel);
vbs[n++] = new Integer32(secModel);
vbs[n++] = secName;
vbs[n++] = new Integer32(secLevel);
vbs[n++] = new Integer32(storageType);
vbs[n++] = new Integer32(RowStatus.active);
OID index = name.toSubIndex(true);
MOTableRow row = snmpTargetParamsEntry.createRow(index, vbs);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -