/*
* Device.java
*
* Created on 19 January 2005, 23:41
*
* AsItHappens - real-time network monitor
* Copyright (C) 2006 Mark Abrahams
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
package nz.co.abrahams.asithappens.storage;
//import nz.co.abrahams.asithappens.oid.CustomOID;
//import nz.co.abrahams.asithappens.netflow.NetFlowMatchCriteria;
//import nz.co.abrahams.asithappens.netflow.NetFlowRecord;
//import nz.co.abrahams.asithappens.snmputil.SNMPScopeException;
import nz.co.abrahams.asithappens.core.DAOFactory;
import nz.co.abrahams.asithappens.snmputil.SNMPException;
//import nz.co.abrahams.asithappens.core.DBAccess;
//import nz.co.abrahams.asithappens.snmputil.SNMPType;
import nz.co.abrahams.asithappens.snmputil.SNMPAccess;
//import nz.co.abrahams.asithappens.snmputil.SNMPTypeException;
import nz.co.abrahams.asithappens.core.DBException;
//import nz.co.abrahams.asithappens.core.Configuration;
import java.net.*;
//import java.util.*;
import org.doomdark.uuid.EthernetAddress;
import org.apache.log4j.Logger;
/**
* A device that is targetted for collecting data from.
*
* @author mark
*/
public class Device {
/* Logging provider */
protected Logger logger;
/** Device name */
protected String name;
/** IP address */
protected InetAddress address;
/** MAC address */
protected EthernetAddress ethernetAddress;
/** SNMP read-only community string */
protected String communityRead;
/** SNMP read-write community string */
protected String communityWrite;
/** Indicates whether ro or rw community is to be used */
protected boolean useWriteCommunity;
/** SNMP ifIndex list */
//protected int[] portsIndex;
/** SNMP ifDescr list */
//protected String[] portsDescr;
/** SNMP ifAlias list */
//protected String[] portsAlias;
/** SNMP host resources processors list */
//protected int[] processorsIndex;
/** SNMP host resources processors descriptions */
//protected String[] processorsDescr;
/** SNMP host resources storage object list */
//protected int[] storageIndex;
/** SNMP host resources storage object descriptions */
//protected String[] storageDescr;
/** SNMP access handle */
//protected SNMPAccess snmpAccess;
/** SNMP capability flag */
//protected boolean snmpCapable;
/**
* Creates a new Device
*
* @param name device name
*/
public Device(String name) {
logger = Logger.getLogger(this.getClass().getName());
this.name = name;
//address = InetAddress.getByName(name);
}
/**
* Creates a new Device with SNMP capabiliity
*
* @param name device name
* @param community SNMP community string
*/
public Device(String name, String communityRead, String communityWrite, boolean useWrite) throws UnknownHostException, SNMPException {
this(name);
//logger = Logger.getLogger(this.getClass().getName());
this.communityRead = communityRead;
this.communityWrite = communityWrite;
this.useWriteCommunity = useWrite;
/*
if ( useWrite )
createSNMPInterface(communityWrite);
else
createSNMPInterface(communityRead);
*/
}
/**
* Creates a new Device with given IP and MAC addresses
*
* @param address IP address of device
* @param ethernetAddress MAC address of device
*/
public Device(InetAddress address, EthernetAddress ethernetAddress) {
this(address.getHostAddress());
this.address = address;
this.ethernetAddress = ethernetAddress;
}
/**
* Creates a new Device with given MAC address
*
* @param ethernetAddress MAC address of device
*/
public Device(EthernetAddress ethernetAddress) {
this(ethernetAddress.toString());
this.ethernetAddress = ethernetAddress;
}
/**
* Creates a new Device with given IP and MAC addresses
*
* @param address IP address of device
* @param ethernetAddress MAC address of device
*/
public Device(String name, String communityRead, String communityWrite, boolean useWrite, String address, String ethernetAddress) throws UnknownHostException, SNMPException {
this(name, communityRead, communityWrite, useWrite);
if ( address != null && ! address.equals("null") ) {
logger.info("Device address: " + address);
this.address = InetAddress.getByName(address);
}
if ( ethernetAddress != null )
this.ethernetAddress = new EthernetAddress(ethernetAddress);
}
/** @return device name */
public String getName() {
return name;
}
/**
* Attempts to resolve the device name to an IP address using the local
* name service.
*
* @return the IP address of the device
*/
public InetAddress resolveAddress() throws UnknownHostException {
try {
address = InetAddress.getByName(name);
return address;
} catch (UnknownHostException e) {
logger.warn("Cannot resolve host name \"" + name + "\"");
throw e;
}
}
/**
* Creates an interface to the SNMP access class.
*
* @param community SNMP community string
*/
/*
public SNMPAccess createSNMPInterface(String community) throws UnknownHostException, SNMPException {
snmpCapable = false;
snmpAccess = new SNMPAccess(getResolvedAddress(), community);
//this.communityRead = community;
snmpCapable = true;
return snmpAccess;
}
*/
/**
* Creates a read-only interface to the SNMP access class.
*
* @return read-only SNMP interface
*/
public SNMPAccess createSNMPReadInterface() throws UnknownHostException, SNMPException {
return new SNMPAccess(getResolvedAddress(), communityRead);
}
/**
* Creates a read-write interface to the SNMP access class.
*
* @return read-write SNMP interface
*/
public SNMPAccess createSNMPWriteInterface() throws UnknownHostException, SNMPException {
return new SNMPAccess(getResolvedAddress(), communityWrite);
}
/** Prefer expedient SNMP collection with no retries on failure */
/*
public void setExpedientCollection() {
if ( snmpAccess != null)
snmpAccess.setExpedientCollection();
}
*/
/** Prefer reliable SNMP collection with retries on failure */
/*
public void setReliableCollection() {
if ( snmpAccess != null)
snmpAccess.setReliableCollection();
}
*/
/** @return the IP address of the device */
public InetAddress getResolvedAddress() throws UnknownHostException {
if ( address == null )
address = resolveAddress();
return address;
}
public InetAddress getAddress() {
return address;
}
/** @return the MAC address of the device */
public EthernetAddress getEthernetAddress() {
return ethernetAddress;
}
/** @return the SNMP read community string for the device */
public String getCommunityRead() {
return communityRead;
}
/** @return the SNMP write community string for the device */
public String getCommunityWrite() {
return communityWrite;
}
/** @return the ifIndex list for the device */
/*
public int[] getPortsIndex() {
return portsIndex;
}
*/
/** @return the ifDescr list for the device */
/*
public String[] getPortsDescr() {
return portsDescr;
}
*/
/**
* Retrieve the SNMP ifDescr of an interface given its ifIndex.
*
* @param port ifIndex of interface
* @return retrieved ifDescr of interface
*/
/*
public String getIfDescr(int port) throws SNMPException {
return snmpAccess.getMIBValueString(SNMPAccess.OID_IFDESCR + "." + String.valueOf(port));
}
*/
/*
public int getIfIndex(String portString) throws SNMPException, DBException {
int portIndex = 0;
enumeratePorts();
for ( int i = 0 ; i < getPortsIndex().length ; i++ ) {
if ( getPortsDescr()[i].equals(portString) ) {
portIndex = getPortsIndex()[i];
}
}
return portIndex;
}
*/
/**
* Enumerates interfaces on a device in via the interfaces MIB table. The
* interfaces and description are stored in the portsIndex and portsDescr
* instance variables.
*/
/*
public void enumeratePorts() throws SNMPException, DBException {
int numInterfaces;
int count;
String[] tempPortsDescr;
String[] tempPortsAlias;
int[] tempPortsIndex;
String ifIndexOID;
String ifDescrOID;
String ifDescrValue;
String ifAliasOID;
String ifAliasValue;
int ifIndexValue;
LinkedList getNextPair;
DeviceDAO deviceDAO;
DBAccess dba;
boolean fetchIfAlias;
numInterfaces = snmpAccess.getMIBValueInteger(SNMPAccess.OID_IFNUMBER);
logger.debug("Number of interfaces: " + numInterfaces);
tempPortsDescr = new String[numInterfaces];
tempPortsAlias = new String[numInterfaces];
tempPortsIndex = new int[numInterfaces];
ifIndexOID = SNMPAccess.OID_IFNUMBER;
count = 0;
ifAliasValue = new String("");
if ( Configuration.getPropertyInt("device.ports.ifalias") == 1 )
fetchIfAlias = true;
else
fetchIfAlias = false;
try {
for ( count = 0 ; count < numInterfaces ; count++ ) {
getNextPair = snmpAccess.getNextMIBValue(ifIndexOID, SNMPType.Integer32, SNMPAccess.OID_IFINDEX);
ifIndexOID = (String)getNextPair.getFirst();
ifIndexValue = ((Integer)getNextPair.getLast()).intValue();
ifDescrOID = SNMPAccess.OID_IFDESCR + "." + String.valueOf(ifIndexValue);
ifDescrValue = snmpAccess.getMIBValueString(ifDescrOID);
if ( fetchIfAlias ) {
ifAliasOID = SNMPAccess.OID_IFALIAS + "." + String.valueOf(ifIndexValue);
try {
ifAliasValue = snmpAccess.getMIBValueString(ifAliasOID);
} catch (SNMPException e) {
fetchIfAlias = false;
}
}
logger.debug("Found interface: ifIndex=" + ifIndexValue + ", ifDescr=" + ifDescrValue);
tempPortsDescr[count] = ifDescrValue;
tempPortsIndex[count] = ifIndexValue;
if ( fetchIfAlias )
tempPortsAlias[count] = ifAliasValue;
}
portsIndex = tempPortsIndex;
portsDescr = tempPortsDescr;
if ( fetchIfAlias )
portsAlias = tempPortsAlias;
} catch (SNMPScopeException e) {
// Create partial port list if exception occurs after successfully enumerating some ports
if ( count > 0 ) {
portsIndex = new int[count];
portsDescr = new String[count];
System.arraycopy(tempPortsIndex, 0, portsIndex, 0, count);
System.arraycopy(tempPortsDescr, 0, portsDescr, 0, count);
if ( fetchIfAlias ) {
portsAlias = new String[count];
System.arraycopy(tempPortsAlias, 0, portsAlias, 0, count);
}
//e.printStackTrace();
logger.warn("Port enumeration partially failed");
} else {
e.printStackTrace();
logger.error("Port enumeration failed");
throw new SNMPException("Port enumeration failed", e);
}
}
}
*/
/*
public Vector getPortsVector() {
Vector data;
Vector row;
if ( portsIndex != null ) {
data = new Vector();
for ( int i = 0 ; i < portsIndex.length ; i++ ) {
row = new Vector();
row.addElement(portsDescr[i]);
if ( portsAlias != null )
row.addElement(portsAlias[i]);
else
row.addElement("");
data.addElement(row);
}
return data;
} else {
return null;
}
}
*/
/**
* Retrieves the ifInOctets counter via SNMP for the given interface.
*
* @param port the ifIndex of the desired interface
* @return the ifInOctets counter value
*/
/*
public long getIfInOctets(int port) throws SNMPException {
return snmpAccess.getMIBValueCounter32(SNMPAccess.OID_IFINOCTETS + "." + Integer.toString(port));
}
*/
/**
* Retrieves the ifOutOctets counter via SNMP for the given interface.
*
* @param port the ifIndex of the desired interface
* @return the ifOutOctets counter value
*/
/*
public long getIfOutOctets(int port) throws SNMPException {
return snmpAccess.getMIBValueCounter32(SNMPAccess.OID_IFOUTOCTETS + "." + Integer.toString(port));
}
*/
/**
* Retrieves the ifHCInOctets counter via SNMP for the given interface.
*
* @param port the ifIndex of the desired interface
* @return the ifHCInOctets counter value
*/
/*
public long getIfHCInOctets(int port) throws SNMPException {
return snmpAccess.getMIBValueCounter64(SNMPAccess.OID_IFHCINOCTETS + "." + Integer.toString(port));
}
*/
/**
* Retrieves the ifHCOutOctets counter via SNMP for the given interface.
*
* @param port the ifIndex of the desired interface
* @return the ifHCOutOctets counter value
*/
/*
public long getIfHCOutOctets(int port) throws SNMPException {
return snmpAccess.getMIBValueCounter64(SNMPAccess.OID_IFHCOUTOCTETS + "." + Integer.toString(port));
}
*/
/**
* Creates an NBAR Top-N table, which can subsequently be polled for statistics.
*
* @param port ifIndex of desired port for monitoring
* @param direction direction of information flow for monitoring
* @param tableSize Top-N table size
* @param sampleTime time between statistic samples
* @return MIB index of the new NBAR Top-N table
*/
/*
public int setNBARTopNConfigTable(int port, int direction, int tableSize, int sampleTime) throws SNMPException {
int result;
int tableIndex;
logger.debug("Creating Top-N table");
tableIndex = 1;
try {
while ( tableIndex <= Configuration.getPropertyInt("collector.nbar.table.index.maximum") ) {
result = snmpAccess.getMIBValueInteger(SNMPAccess.OID_cnpdTopNConfigIfIndex + "." + tableIndex);
tableIndex++;
}
}
// Exception thrown when value doesn't exist indicating a free table index
catch (Exception e) {
}
result = snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnpdTopNConfigIfIndex + "." + tableIndex, port);
result = snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnpdTopNConfigStatsSelect + "." + tableIndex, direction);
result = snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnpdTopNConfigRequestedSize + "." + tableIndex, tableSize);
//snmpAccess.setMIBValueGauge32(SNMPAccess.OID_cnpdTopNConfigSampleTime + "." + tableIndex, (long)sampleTime);
snmpAccess.setMIBValueGauge32(SNMPAccess.OID_cnpdTopNConfigSampleTime + "." + tableIndex, 10);
result = snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnpdTopNConfigStatus + "." + tableIndex, SNMPAccess.ROWSTATUS_createAndGo);
logger.info("Created Top-N table: TableIndex=" + tableIndex + ", ifIndex=" + port + ", direction=" + DataSets.DIRECTIONS[direction]
+ ", TableSize=" + tableSize + ", SampleTime=" + sampleTime);
return tableIndex;
}
*/
/**
* Sets a MIB value to trigger an NBAR Top-N table statistics update.
*
* @param tableIndex index of NBAR Top-N table
* @return the result of the SNMP set command
*/
/*
public int setNBARTopNNewInterval(int tableIndex) throws SNMPException {
return snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnpdTopNConfigStatus + "." + tableIndex, SNMPAccess.ROWSTATUS_active);
}
*/
/**
* Retrieve the names of the current protocols in the given NBAR Top-N table.
*
* @param tableIndex index of NBAR Top-N table
* @param tableSize number of desired table entries to retrieve
* @return the list of NBAR protocol names
*/
/*
public String[] getNBARTopNProtocols(int tableIndex, int tableSize) throws SNMPException {
String[] protocols;
int i;
protocols = new String[tableSize];
i = 0;
try {
for ( i = 0; i < tableSize; i++ ) {
protocols[i] = snmpAccess.getMIBValueString(SNMPAccess.OID_cnpdTopNStatsProtocolName + "." + tableIndex + "." + (i + 1));
}
if (logger.isDebugEnabled()) {
StringBuffer buffer = new StringBuffer("Protocols:");
for ( int j = 0; j < tableSize; j++ ) {
buffer.append(" " + protocols[j]);
}
logger.debug(buffer.toString());
}
return protocols;
} catch (Exception e) {
String[] partialProtocols;
partialProtocols = new String[i];
System.arraycopy(protocols, 0, partialProtocols, 0, i);
return partialProtocols;
}
}
*/
/**
* Retrieve the rates for the current protocols in the given NBAR Top-N table.
*
* @param tableIndex index of NBAR Top-N table
* @param tableSize number of desired table entries to retrieve
* @return the list of NBAR protocol rates
*/
/*
public long[] getNBARTopNRates(int tableIndex, int tableSize) throws SNMPException {
long[] rates;
int i;
rates = new long[tableSize];
i = 0;
try {
for ( i = 0; i < tableSize; i++ ) {
rates[i] = snmpAccess.getMIBValueCounter32(SNMPAccess.OID_cnpdTopNStatsRate + "." + tableIndex + "." + (i + 1));
}
if (logger.isDebugEnabled()) {
StringBuffer buffer = new StringBuffer("Rates:");
for ( int j = 0; j < tableSize; j++ ) {
buffer.append(" " + rates[j]);
}
logger.debug(buffer.toString());
}
return rates;
} catch (Exception e) {
long[] partialRates;
partialRates = new long[i];
System.arraycopy(rates, 0, partialRates, 0, i);
return partialRates;
}
}
*/
/**
* Destroys the given NBAR Top-N table.
*
* @param tableIndex index of NBAR Top-N table
* @return the result of the SNMP set command to destroy the table
*/
/*
public int setNBARTopNDestroy(int tableIndex) throws SNMPException {
logger.debug("Destroying NBAR Top-N table " + tableIndex);
return snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnpdTopNConfigStatus + "." + tableIndex, SNMPAccess.ROWSTATUS_destroy);
}
*/
/**
* @return the Netflow MIB variable denoting the existance of the Top-N table
*/
/*
public long getNetFlowTopFlowsTopNTable() throws SNMPException {
return snmpAccess.getMIBValueGauge32(SNMPAccess.OID_cnfTopFlowsTopN + ".0");
}
*/
/**
* @return the NetFlow MIB variable denoting the NetFlow status of an interface
*/
/*
public int getNetFlowEnable(int ifIndex) throws SNMPException {
return snmpAccess.getMIBValueInteger(SNMPAccess.OID_cnfCINetflowEnable + "." + ifIndex);
}
*/
/**
* @param ifIndex the interface for which to set the NetFlow status
* @param direction the direction to set the NetFlow status
*/
/*
public void setNetFlowEnable(int ifIndex, int direction) throws SNMPException {
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfCINetflowEnable + "." + ifIndex, direction);
}
*/
/**
* @param tableSize the size to set the NetFlow Top-N table
*/
/*
public void setNetFlowTopFlowsTopNTable(int tableSize) throws SNMPException {
snmpAccess.setMIBValueGauge32(SNMPAccess.OID_cnfTopFlowsTopN + ".0", tableSize);
}
*/
/**
* @param sortBy the criteria to sort the NetFlow Top-N table by
*/
/*
public void setNetFlowTopFlowsSortBy(int sortBy) throws SNMPException {
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfTopFlowsSortBy + ".0", sortBy);
}
*/
/**
* @param pollInterval the timeout interval to set for NetFlow cache entries
*/
/*
public void setNetFlowTopFlowsCacheTimeout(long pollInterval) throws SNMPException {
snmpAccess.setMIBValueGauge32(SNMPAccess.OID_cnfTopFlowsCacheTimeout + ".0", pollInterval);
}
*/
/**
* @param criteria the match criteria to set in the NetFlow MIB
*/
/*
public void setNetFlowMatchCriteria(NetFlowMatchCriteria criteria) throws SNMPException {
NetFlowMatchCriteria unset;
unset = new NetFlowMatchCriteria();
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfTopFlowsMatchSrcAddressType + ".0", criteria.srcAddressType);
if ( criteria.srcAddressType != unset.srcAddressType ) {
snmpAccess.setMIBValueHexString(SNMPAccess.OID_cnfTopFlowsMatchSrcAddress + ".0", criteria.getSrcAddressBytes());
snmpAccess.setMIBValueGauge32(SNMPAccess.OID_cnfTopFlowsMatchSrcAddressMask + ".0", criteria.srcAddressMask);
}
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfTopFlowsMatchDstAddressType + ".0", criteria.dstAddressType);
if ( criteria.dstAddressType != unset.dstAddressType ) {
snmpAccess.setMIBValueHexString(SNMPAccess.OID_cnfTopFlowsMatchDstAddress + ".0", criteria.getDstAddressBytes());
snmpAccess.setMIBValueGauge32(SNMPAccess.OID_cnfTopFlowsMatchDstAddressMask + ".0", criteria.dstAddressMask);
}
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfTopFlowsMatchNhAddressType + ".0", criteria.nhAddressType);
if ( criteria.nhAddressType != unset.nhAddressType ) {
snmpAccess.setMIBValueHexString(SNMPAccess.OID_cnfTopFlowsMatchNhAddress + ".0", criteria.getNhAddressBytes());
snmpAccess.setMIBValueGauge32(SNMPAccess.OID_cnfTopFlowsMatchNhAddressMask + ".0", criteria.nhAddressMask);
}
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfTopFlowsMatchSrcPortLo + ".0", criteria.srcPortLo);
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfTopFlowsMatchSrcPortHi + ".0", criteria.srcPortHi);
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfTopFlowsMatchDstPortLo + ".0", criteria.dstPortLo);
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfTopFlowsMatchDstPortHi + ".0", criteria.dstPortHi);
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfTopFlowsMatchSrcAS + ".0", criteria.srcAS);
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfTopFlowsMatchDstAS + ".0", criteria.dstAS);
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfTopFlowsMatchTOSByte + ".0", criteria.tosByte);
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfTopFlowsMatchProtocol + ".0", criteria.protocol);
snmpAccess.setMIBValueOctetString(SNMPAccess.OID_cnfTopFlowsMatchSampler + ".0", criteria.sampler);
snmpAccess.setMIBValueOctetString(SNMPAccess.OID_cnfTopFlowsMatchClass + ".0", criteria.classMap);
snmpAccess.setMIBValueGauge32(SNMPAccess.OID_cnfTopFlowsMatchMinPackets + ".0", criteria.minPackets);
snmpAccess.setMIBValueGauge32(SNMPAccess.OID_cnfTopFlowsMatchMaxPackets + ".0", criteria.maxPackets);
snmpAccess.setMIBValueGauge32(SNMPAccess.OID_cnfTopFlowsMatchMinBytes + ".0", criteria.minBytes);
snmpAccess.setMIBValueGauge32(SNMPAccess.OID_cnfTopFlowsMatchMaxBytes + ".0", criteria.maxBytes);
}
*/
/**
* @param current the current match criteria in the NetFlow MIB
*/
/*
public void restoreDefaultNetFlowMatchCriteria(NetFlowMatchCriteria current) throws SNMPException {
NetFlowMatchCriteria defaults;
defaults = new NetFlowMatchCriteria();
if ( current.srcAddressType != defaults.srcAddressType )
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfTopFlowsMatchSrcAddressType + ".0", defaults.srcAddressType);
if ( current.srcAddress != defaults.srcAddress )
snmpAccess.setMIBValueHexString(SNMPAccess.OID_cnfTopFlowsMatchSrcAddress + ".0", new byte[0]);
if ( current.srcAddressMask != defaults.srcAddressMask )
snmpAccess.setMIBValueGauge32(SNMPAccess.OID_cnfTopFlowsMatchSrcAddressMask + ".0", defaults.srcAddressMask);
if ( current.dstAddressType != defaults.dstAddressType )
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfTopFlowsMatchDstAddressType + ".0", defaults.dstAddressType);
if ( current.dstAddress != defaults.dstAddress )
snmpAccess.setMIBValueHexString(SNMPAccess.OID_cnfTopFlowsMatchDstAddress + ".0", new byte[0]);
if ( current.dstAddressMask != defaults.dstAddressMask )
snmpAccess.setMIBValueGauge32(SNMPAccess.OID_cnfTopFlowsMatchDstAddressMask + ".0", defaults.dstAddressMask);
if ( current.nhAddressType != defaults.nhAddressType )
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfTopFlowsMatchNhAddressType + ".0", defaults.nhAddressType);
if ( current.nhAddress != defaults.nhAddress )
snmpAccess.setMIBValueHexString(SNMPAccess.OID_cnfTopFlowsMatchNhAddress + ".0", new byte[0]);
if ( current.nhAddressMask != defaults.nhAddressMask )
snmpAccess.setMIBValueGauge32(SNMPAccess.OID_cnfTopFlowsMatchNhAddressMask + ".0", defaults.nhAddressMask);
if ( current.srcPortLo != defaults.srcPortLo )
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfTopFlowsMatchSrcPortLo + ".0", defaults.srcPortLo);
if ( current.srcPortHi != defaults.srcPortHi )
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfTopFlowsMatchSrcPortHi + ".0", defaults.srcPortHi);
if ( current.dstPortLo != defaults.dstPortLo )
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfTopFlowsMatchDstPortLo + ".0", defaults.dstPortLo);
if ( current.dstPortHi != defaults.dstPortHi )
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfTopFlowsMatchDstPortHi + ".0", defaults.dstPortHi);
if ( current.srcAS != defaults.srcAS )
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfTopFlowsMatchSrcAS + ".0", defaults.srcAS);
if ( current.dstAS != defaults.dstAS )
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfTopFlowsMatchDstAS + ".0", defaults.dstAS);
if ( current.tosByte != defaults.tosByte )
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfTopFlowsMatchTOSByte + ".0", defaults.tosByte);
if ( current.protocol != defaults.protocol )
snmpAccess.setMIBValueInteger(SNMPAccess.OID_cnfTopFlowsMatchProtocol + ".0", defaults.protocol);
if ( current.sampler != defaults.sampler )
snmpAccess.setMIBValueOctetString(SNMPAccess.OID_cnfTopFlowsMatchSampler + ".0", defaults.sampler);
if ( current.classMap != defaults.classMap )
snmpAccess.setMIBValueOctetString(SNMPAccess.OID_cnfTopFlowsMatchClass + ".0", defaults.classMap);
if ( current.minPackets != defaults.minPackets )
snmpAccess.setMIBValueGauge32(SNMPAccess.OID_cnfTopFlowsMatchMinPackets + ".0", defaults.minPackets);
if ( current.maxPackets != defaults.maxPackets )
snmpAccess.setMIBValueGauge32(SNMPAccess.OID_cnfTopFlowsMatchMaxPackets + ".0", defaults.maxPackets);
if ( current.minBytes != defaults.minBytes )
snmpAccess.setMIBValueGauge32(SNMPAccess.OID_cnfTopFlowsMatchMinBytes + ".0", defaults.minBytes);
if ( current.maxBytes != defaults.maxBytes )
snmpAccess.setMIBValueGauge32(SNMPAccess.OID_cnfTopFlowsMatchMaxBytes + ".0", defaults.maxBytes);
}
*/
/**
* Retrieves the NetFlow top flows table from the MIB.
*
* @param tableSize the number of flow entries to retrieve
* @return the ordered set of NetFlow records
*/
/*
public NetFlowRecord[] getNetFlowTopFlowsTable(int tableSize) {
NetFlowRecord[] records;
int i;
records = new NetFlowRecord[tableSize];
i = 0;
try {
setNetFlowTopFlowsTopNTable(tableSize);
for (i = 0; i < tableSize; i++) {
records[i] = new NetFlowRecord(
snmpAccess.getMIBValueIpAddress(SNMPAccess.OID_cnfTopFlowsSrcAddress + "." + (i + 1)),
snmpAccess.getMIBValueIpAddress(SNMPAccess.OID_cnfTopFlowsDstAddress + "." + (i + 1)),
(int)snmpAccess.getMIBValueGauge32(SNMPAccess.OID_cnfTopFlowsSrcPort + "." + (i + 1)),
(int)snmpAccess.getMIBValueGauge32(SNMPAccess.OID_cnfTopFlowsDstPort + "." + (i + 1)),
(int)snmpAccess.getMIBValueGauge32(SNMPAccess.OID_cnfTopFlowsTOS + "." + (i + 1)),
(int)snmpAccess.getMIBValueGauge32(SNMPAccess.OID_cnfTopFlowsProtocol + "." + (i + 1)) );
records[i].bytes = snmpAccess.getMIBValueGauge32(SNMPAccess.OID_cnfTopFlowsBytes + "." + (i + 1));
}
return records;
}
// SNMPException, UnknownHostException
catch (Exception e) {
NetFlowRecord[] partialRecords;
partialRecords = new NetFlowRecord[i];
System.arraycopy(records, 0, partialRecords, 0, i);
return partialRecords;
}
}
*/
/*
public void enumerateHostProcessors() throws SNMPException {
int count;
Vector<String> descrVector;
Vector<Integer> indexVector;
String processorIndexOID;
String processorDescrOID;
String processorTypeOID;
String processorDescrValue;
int processorIndexValue;
LinkedList getNextPair;
descrVector = new Vector();
indexVector = new Vector();
getNextPair = snmpAccess.getNextMIBValue(SNMPAccess.OID_hrDeviceIndex, SNMPType.Integer32);
processorIndexOID = (String)getNextPair.getFirst();
try {
//while ( processorIndexOID.matches(SNMPAccess.OID_hrDeviceIndex + ".*") ) {
while ( true ) {
processorIndexValue = ((Integer)getNextPair.getLast()).intValue();
processorDescrOID = SNMPAccess.OID_hrDeviceDescr + "." + String.valueOf(processorIndexValue);
processorTypeOID = SNMPAccess.OID_hrDeviceType + "." + String.valueOf(processorIndexValue);
processorDescrValue = snmpAccess.getMIBValueString(processorDescrOID);
logger.debug("Found device at " + processorIndexOID + ": " + processorDescrValue);
if ( snmpAccess.getMIBValueOID(processorTypeOID).matches(".*" + SNMPAccess.HR_DEVICETYPE_processor) ) {
descrVector.add(processorDescrValue);
indexVector.add(new Integer(processorIndexValue));
logger.debug("Adding processor \"" + processorDescrValue + "\" to list");
}
getNextPair = snmpAccess.getNextMIBValue(processorIndexOID, SNMPType.Integer32, SNMPAccess.OID_hrDeviceIndex);
processorIndexOID = (String)getNextPair.getFirst();
}
} catch (SNMPScopeException e) {
}
processorsIndex = new int[indexVector.size()];
processorsDescr = new String[descrVector.size()];
for ( int i = 0; i < indexVector.size(); i++ ) {
processorsIndex[i] = indexVector.elementAt(i);
processorsDescr[i] = descrVector.elementAt(i);
}
}
public int getProcessorLoad(int processorIndex) throws SNMPException {
return snmpAccess.getMIBValueInteger(SNMPAccess.OID_hrProcessorLoad + "." + processorIndex);
}
public int[] getProcessorsIndex() {
return processorsIndex;
}
public String[] getProcessorsDescr() {
return processorsDescr;
}
*/
/*
public int getCiscoProcessorLoad() throws SNMPException {
return snmpAccess.getMIBValueInteger(SNMPAccess.OID_oldCiscoCPUBusyPer + ".0");
}
*/
/*
public long getSSCPUUser() throws SNMPException {
return snmpAccess.getMIBValueCounter32(SNMPAccess.OID_ssCpuRawUser + ".0");
}
public long getSSCPUNice() throws SNMPException {
return snmpAccess.getMIBValueCounter32(SNMPAccess.OID_ssCpuRawNice + ".0");
}
public long getSSCPUSystem() throws SNMPException {
return snmpAccess.getMIBValueCounter32(SNMPAccess.OID_ssCpuRawSystem + ".0");
}
public long getSSCPUIdle() throws SNMPException {
return snmpAccess.getMIBValueCounter32(SNMPAccess.OID_ssCpuRawIdle + ".0");
}
public long getSSCPUWait() throws SNMPException {
return snmpAccess.getMIBValueCounter32(SNMPAccess.OID_ssCpuRawWait + ".0");
}
public long getSSCPUKernel() throws SNMPException {
return snmpAccess.getMIBValueCounter32(SNMPAccess.OID_ssCpuRawKernel + ".0");
}
public long getSSCPUInterrupt() throws SNMPException {
return snmpAccess.getMIBValueCounter32(SNMPAccess.OID_ssCpuRawInterrupt + ".0");
}
*/
/*
public int getUCDMemTotalReal() throws SNMPException {
return snmpAccess.getMIBValueInteger(SNMPAccess.OID_memTotalReal + ".0");
}
public int getUCDMemAvailReal() throws SNMPException {
return snmpAccess.getMIBValueInteger(SNMPAccess.OID_memAvailReal + ".0");
}
public int getUCDMemTotalSwap() throws SNMPException {
return snmpAccess.getMIBValueInteger(SNMPAccess.OID_memTotalSwap + ".0");
}
public int getUCDMemAvailSwap() throws SNMPException {
return snmpAccess.getMIBValueInteger(SNMPAccess.OID_memAvailSwap + ".0");
}
*/
/*
public void enumerateHostStorage() throws SNMPException {
int count;
Vector<String> descrVector;
Vector<Integer> indexVector;
String storageIndexOID;
String storageDescrOID;
String storageTypeOID;
String storageDescrValue;
int storageIndexValue;
LinkedList getNextPair;
descrVector = new Vector();
indexVector = new Vector();
getNextPair = snmpAccess.getNextMIBValue(SNMPAccess.OID_hrStorageDescr, SNMPType.OctetString);
storageDescrOID = (String)getNextPair.getFirst();
try {
//while ( storageDescrOID.matches(SNMPAccess.OID_hrStorageDescr + ".*") ) {
while ( true ) {
storageDescrValue = (String)getNextPair.getLast();
storageIndexValue = Integer.parseInt(storageDescrOID.substring(storageDescrOID.lastIndexOf('.') + 1));
descrVector.add(storageDescrValue);
indexVector.add(new Integer(storageIndexValue));
logger.debug("Adding storage object at " + storageIndexValue + ": \"" + storageDescrValue + "\" to list");
getNextPair = snmpAccess.getNextMIBValue(storageDescrOID, SNMPType.OctetString, SNMPAccess.OID_hrStorageDescr);
storageDescrOID = (String)getNextPair.getFirst();
}
}
// Normal exit condition - end of storage table reached
catch (SNMPScopeException e) {
}
storageIndex = new int[indexVector.size()];
storageDescr = new String[descrVector.size()];
for ( int i = 0; i < indexVector.size(); i++ ) {
storageIndex[i] = indexVector.elementAt(i);
storageDescr[i] = descrVector.elementAt(i);
}
}
*/
/*
public int getStorageAllocationUnits(int storageIndex) throws SNMPException {
return snmpAccess.getMIBValueInteger(SNMPAccess.OID_hrStorageAllocationUnits + "." + storageIndex);
}
public int getStorageUsed(int storageIndex) throws SNMPException {
return snmpAccess.getMIBValueInteger(SNMPAccess.OID_hrStorageUsed + "." + storageIndex);
}
public int[] getStorageIndex() {
return storageIndex;
}
public String[] getStorageDescr() {
return storageDescr;
}
*/
/*
public void enumerateCiscoMemoryPools() throws SNMPException {
Vector<String> descrVector;
Vector<Integer> indexVector;
String storageIndexOID;
String poolNameOID;
String storageTypeOID;
String poolNameValue;
int poolIndexValue;
LinkedList getNextPair;
descrVector = new Vector();
indexVector = new Vector();
getNextPair = snmpAccess.getNextMIBValue(SNMPAccess.OID_ciscoMemoryPoolName, SNMPType.OctetString);
poolNameOID = (String)getNextPair.getFirst();
try {
//while ( poolNameOID.matches(SNMPAccess.OID_ciscoMemoryPoolName + ".*") ) {
while ( true ) {
poolNameValue = (String)getNextPair.getLast();
poolIndexValue = Integer.parseInt(poolNameOID.substring(poolNameOID.lastIndexOf('.') + 1));
descrVector.add(poolNameValue);
indexVector.add(new Integer(poolIndexValue));
logger.debug("Adding memory pool object at " + poolIndexValue + ": \"" + poolNameValue + "\" to list");
getNextPair = snmpAccess.getNextMIBValue(poolNameOID, SNMPType.OctetString, SNMPAccess.OID_ciscoMemoryPoolName);
poolNameOID = (String)getNextPair.getFirst();
}
} catch (SNMPScopeException e) {
}
storageIndex = new int[indexVector.size()];
storageDescr = new String[descrVector.size()];
for ( int i = 0; i < indexVector.size(); i++ ) {
storageIndex[i] = indexVector.elementAt(i);
storageDescr[i] = descrVector.elementAt(i);
}
}
public long getCiscoMemoryUsed(int memoryIndex) throws SNMPException {
return snmpAccess.getMIBValueGauge32(SNMPAccess.OID_ciscoMemoryPoolUsed + "." + memoryIndex);
}
*/
/*
public long getCustomOIDInteger32(CustomOID oid) throws SNMPException, SNMPTypeException {
return snmpAccess.getMIBValueInteger(oid.oid);
}
public long getCustomOIDGauge32(CustomOID oid) throws SNMPException, SNMPTypeException {
return snmpAccess.getMIBValueGauge32(oid.oid);
}
public long getCustomOIDCounter32(CustomOID oid) throws SNMPException, SNMPTypeException {
return snmpAccess.getMIBValueCounter32(oid.oid);
}
public long getCustomOIDCounter64(CustomOID oid) throws SNMPException, SNMPTypeException {
return snmpAccess.getMIBValueCounter64(oid.oid);
}
*/
public String retrieveReadCommunity() throws DBException {
DeviceDAO deviceDAO;
String community;
deviceDAO = DAOFactory.getDeviceDAO();
community = deviceDAO.retrieveDeviceReadCommunity(name);
deviceDAO.closeConnection();
return community;
}
public String retrieveWriteCommunity() throws DBException {
DeviceDAO deviceDAO;
String community;
deviceDAO = DAOFactory.getDeviceDAO();
community = deviceDAO.retrieveDeviceWriteCommunity(name);
deviceDAO.closeConnection();
return community;
}
public String toString() {
return name;
}
/*
public void store() throws DBException {
DeviceDAO deviceDAO;
String ipAddressString;
String hardwareAddressString;
ipAddressString = null;
hardwareAddressString = null;
if ( address != null )
ipAddressString = address.getHostAddress();
if ( ethernetAddress != null )
hardwareAddressString = ethernetAddress.toString();
deviceDAO = DAOFactory.getDeviceDAO();
deviceDAO.updateDevice(name, communityRead, communityWrite, ipAddressString, hardwareAddressString);
deviceDAO.closeConnection();
}
public static Device load(String name, boolean useWrite) throws DBException, UnknownHostException, SNMPException {
DeviceDAO deviceDAO;
Device newDevice;
deviceDAO = DAOFactory.getDeviceDAO();
newDevice = deviceDAO.retrieveDevice(name, useWrite);
deviceDAO.closeConnection();
return newDevice;
}
*/
}