// Home | Go Back //
package agent.master;
import java.io.*;
import java.util.*;
import com.ireasoning.util.*;
import com.ireasoning.protocol.snmp.*;
import javax.management.*;
public class IfRcvAddressTable extends SnmpTable implements IfRcvAddressTableMBean
{
Hashtable _entryMap = new Hashtable();
ArrayList _oids = new ArrayList();
public IfRcvAddressTable (OIDTreeNode root, String oid, Object[] args)
{
super(root, oid);
setProcessSnmpRequestDirectly(true);
}
public SnmpTableEntry getOID(SnmpOID oid)
{
Logger.debug( "IfRcvAddressTable.getOID. oid=" + oid + ", _entryMap.size=" + _entryMap.size());
SnmpTableEntry entry = (SnmpTableEntry) _entryMap.get(oid);
return entry;
}
public SnmpTableEntry getNextOID(SnmpOID oid)
{
Logger.debug( "IfRcvAddressTable.getNextOID. oid=" + oid + ", _entryMap.size=" + _entryMap.size());
int size = _oids.size();
for (int i = 0; i < size ; i++)
{
SnmpOID o = (SnmpOID) _oids.get(i);
if(o.compareTo(oid) > 0)
{
IfRcvAddressEntry entry = (IfRcvAddressEntry) _entryMap.get(o);
entry.setOID(o);
return entry;
}
}
return null;
}
private boolean checkDestroy(Collection varbinds, SnmpOID rowStatusColumnOID)
{
Iterator it = varbinds.iterator();
while(it.hasNext())
{
SnmpVarBind vb = (SnmpVarBind)it.next();
SnmpOID oid = (SnmpOID) vb.getName();
if(oid.startsWith(rowStatusColumnOID))
{
int val = ((SnmpInt)vb.getValue()).getValue();
if(val == 6) {
SnmpTableEntry entry = (SnmpTableEntry) _entryMap.get(oid);
String suffix = entry.getIndexSuffix();
int size = _oids.size();
ArrayList removes = new ArrayList();
for (int i = 0; i < size ; i++)
{
SnmpOID o = (SnmpOID) _oids.get(i);
if(o.endsWith(suffix)) removes.add(o);
}
size = removes.size();
for (int i = 0; i < size ; i++)
{
SnmpOID o = (SnmpOID) removes.get(i);
Logger.debug( "delete:" + o);
_oids.remove(o);
_entryMap.remove(o);
}
return true;
}
}
}
return false;
}
public boolean preSetValue(SnmpTableEntry entry, SnmpVarBind newValue, Collection varbinds)
{
try
{
Logger.debug( "Enter preSetValue.........");
SnmpOID oid = (SnmpOID) newValue.getName();
SnmpOID entryNodeOID = (SnmpOID) _tableNode.getFirstChild().getName();
SnmpOID rowStatusColumnOID = new SnmpOID(entryNodeOID).append(".2");
SnmpOID addressTypeOID = new SnmpOID(entryNodeOID).append(".3");
if(_entryMap.get(oid) != null && checkDestroy(varbinds, rowStatusColumnOID)) return true;
boolean found = false;
SnmpVarBind vb = null;
SnmpVarBind addressTypeVB = null;
SnmpVarBind rowStatusVB = null;
Logger.debug( "varbinds.size=" + varbinds.size());
Iterator it = varbinds.iterator();
while(it.hasNext())
{
vb = (SnmpVarBind)it.next();
SnmpOID o = (SnmpOID) vb.getName();
Logger.debug( "o=" + o + ", rowStatusColumnOID=" + rowStatusColumnOID);
if(o.startsWith(rowStatusColumnOID))
{
rowStatusVB = vb;
found = true;
}
else if(o.startsWith(addressTypeOID))
{
addressTypeVB = vb;
}
}
if(!found) return false;
oid = (SnmpOID) rowStatusVB.getName();
SnmpOID suffix = oid.suboid(rowStatusColumnOID.getLength(), oid.getLength());
int ifIndex = suffix.get(0);
String address = suffix.suboid(1, suffix.getLength()).toString();
address = address.substring(1, address.length());
int ifRcvAddressStatus = ((SnmpInt) rowStatusVB.getValue()).getValue();
if(ifRcvAddressStatus == 4)
{
ifRcvAddressStatus = 1; }
else if(ifRcvAddressStatus == 5)
{
ifRcvAddressStatus = 3; }
else return false;
int ifRcvAddressType = 1; if(addressTypeVB != null)
{
ifRcvAddressType = ((SnmpInt)addressTypeVB.getValue()).getValue();
}
IfRcvAddressEntry e = new IfRcvAddressEntry(this, address, ifRcvAddressStatus, ifRcvAddressType);
e.setIndexSuffix(suffix.toString());
for (int i = 2; i <= 3 ; i++) {
SnmpOID o1 = new SnmpOID(entryNodeOID).append("." + i).append(suffix);
Logger.debug( "add:" + o1 + ", suffix =" + suffix);
_oids.add(o1);
_entryMap.put(o1, e);
}
Collections.sort(_oids);
}
catch(Exception e)
{
Logger.error(e);
}
return true;
}
public SnmpTableEntry newEntryInstance()
{
return new IfRcvAddressEntry (this);
}
public String getIfRcvAddressAddress(SnmpTableEntry ifRcvAddressEntry, SnmpPdu pdu)
{
synchronized (ifRcvAddressEntry)
{
IfRcvAddressEntry entry = (IfRcvAddressEntry) ifRcvAddressEntry;
return entry._ifRcvAddressAddress;
}
}
public void setIfRcvAddressAddressValue(SnmpTableEntry ifRcvAddressEntry, Object newValue, SnmpPdu pdu)
{
synchronized (ifRcvAddressEntry)
{
IfRcvAddressEntry entry = (IfRcvAddressEntry) ifRcvAddressEntry;
entry._ifRcvAddressAddress = (String) newValue;
}
}
public int getIfRcvAddressStatus(SnmpTableEntry ifRcvAddressEntry, SnmpPdu pdu)
{
synchronized (ifRcvAddressEntry)
{
IfRcvAddressEntry entry = (IfRcvAddressEntry) ifRcvAddressEntry;
return entry._ifRcvAddressStatus;
}
}
public void setIfRcvAddressStatusValue(SnmpTableEntry ifRcvAddressEntry, Object newValue, SnmpPdu pdu)
{
synchronized (ifRcvAddressEntry)
{
IfRcvAddressEntry entry = (IfRcvAddressEntry) ifRcvAddressEntry;
entry._ifRcvAddressStatus = ( (Integer) newValue).intValue() ;
}
}
public int getIfRcvAddressType(SnmpTableEntry ifRcvAddressEntry, SnmpPdu pdu)
{
synchronized (ifRcvAddressEntry)
{
IfRcvAddressEntry entry = (IfRcvAddressEntry) ifRcvAddressEntry;
return entry._ifRcvAddressType;
}
}
public void setIfRcvAddressTypeValue(SnmpTableEntry ifRcvAddressEntry, Object newValue, SnmpPdu pdu)
{
synchronized (ifRcvAddressEntry)
{
IfRcvAddressEntry entry = (IfRcvAddressEntry) ifRcvAddressEntry;
entry._ifRcvAddressType = ( (Integer) newValue).intValue() ;
}
}
}