// Home | Go Back //

/*
 * Copyright (c) 2002-2003 iReasoning Inc. All Rights Reserved.
 * 
 * This SOURCE CODE FILE, which has been provided by iReasoning Inc. as part
 * of an iReasoning Software product for use ONLY by licensed users of the product,
 * includes CONFIDENTIAL and PROPRIETARY information of iReasoning Inc.  
 *
 * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 
 * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
 * THE PRODUCT.
 *
 * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD IREASONING SOFTWARE, ITS
 * RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY
 * CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR
 * DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES
 * ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR
 * DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR
 * DERIVED FROM THIS SOURCE CODE FILE.
 */

package agent.master;
import java.io.*;
import java.util.*;
import com.ireasoning.util.*;
import com.ireasoning.protocol.snmp.*;
import javax.management.*;

/**
 * Class represents ifTable MIB object in RFC1213_MIB
 */
public class IfTable extends SnmpTable implements IfTableMBean
{
    
    private Hashtable _ipAddrMap = new Hashtable();
    
    /** array list for storing NetInterface objects */
    private ArrayList _netifs;
    
    /**
     * Constructor
     * @param root SnmpOID tree root
     * @param oid the SnmpOID of this table. For example, ".1.3.6.1.2.1.2.2" for IfTable in RFC1213  
     * @param args the objects passed from caller for Initialization purpose
     */
    public IfTable (OIDTreeNode root, String oid, Object[] args)
    {
        super(root, oid);
        // TODO: Add your implementation

        //New code
        addInterfaces();
    }
    
    //New code
    private void addInterfaces()
    {
        _netifs = Util.ipconfig();
        int size = _netifs.size();
        for (int i = 0; i < size ; i++) 
        {
            NetInterface netif = (NetInterface) _netifs.get(i);
            int index = i + 1;
            IfEntry entry = new IfEntry(this, index , netif.descr, netif.physAddress);
            entry.addRow();
            //store in a hashtable, so it can be used by other table
            _ipAddrMap.put(netif.ipAddress, "" + index);
        }
    }
    
    //New code
    public ArrayList getNetInterfaces()
    {
        return _netifs;
    }

    //New code
    /**
     * Returns the ifIndex corresponding to the passed ipAddress
     */
    public String getIfIndex(String ipAddress)
    {
        return (String) _ipAddrMap.get(ipAddress);
    }
    
    public SnmpTableEntry newEntryInstance()
    {
        return new IfEntry (this);
    }
    
    /**
     * Gets ifIndex value
     * @param ifEntry table entry object
     * @param pdu the received SnmpPdu object
     */
    public int getIfIndex(SnmpTableEntry ifEntry, SnmpPdu pdu)
    {
        synchronized (ifEntry)
        {
            // TODO: Add your implementation
            IfEntry entry = (IfEntry) ifEntry;
            return entry._ifIndex;
        }
    }
    
    /**
     * Sets new ifIndex value
     * @param ifEntry table entry object
     * @param newValue new value to be set
     * @param pdu the received SnmpPdu object
     */
    public void setIfIndexValue(SnmpTableEntry ifEntry, Object newValue, SnmpPdu pdu)
    {
        // This MIB node is not writeable, so IfTableMBean does not have this method
        synchronized (ifEntry)
        {
            IfEntry entry = (IfEntry) ifEntry;
            entry._ifIndex = ( (Integer) newValue).intValue() ;
            // TODO: Add your implementation
        }
    }
    
    /**
     * Gets ifDescr value
     * @param ifEntry table entry object
     * @param pdu the received SnmpPdu object
     */
    public String getIfDescr(SnmpTableEntry ifEntry, SnmpPdu pdu)
    {
        synchronized (ifEntry)
        {
            // TODO: Add your implementation
            IfEntry entry = (IfEntry) ifEntry;
            return entry._ifDescr;
        }
    }
    
    /**
     * Sets new ifDescr value
     * @param ifEntry table entry object
     * @param newValue new value to be set
     * @param pdu the received SnmpPdu object
     */
    public void setIfDescrValue(SnmpTableEntry ifEntry, Object newValue, SnmpPdu pdu)
    {
        // This MIB node is not writeable, so IfTableMBean does not have this method
        synchronized (ifEntry)
        {
            IfEntry entry = (IfEntry) ifEntry;
            entry._ifDescr = (String) newValue;
            // TODO: Add your implementation
        }
    }
    
    /**
     * Gets ifType value
     * @param ifEntry table entry object
     * @param pdu the received SnmpPdu object
     */
    public int getIfType(SnmpTableEntry ifEntry, SnmpPdu pdu)
    {
        synchronized (ifEntry)
        {
            // TODO: Add your implementation
            IfEntry entry = (IfEntry) ifEntry;
            return entry._ifType;
        }
    }
    
    /**
     * Sets new ifType value
     * @param ifEntry table entry object
     * @param newValue new value to be set
     * @param pdu the received SnmpPdu object
     */
    public void setIfTypeValue(SnmpTableEntry ifEntry, Object newValue, SnmpPdu pdu)
    {
        // This MIB node is not writeable, so IfTableMBean does not have this method
        synchronized (ifEntry)
        {
            IfEntry entry = (IfEntry) ifEntry;
            entry._ifType = ( (Integer) newValue).intValue() ;
            // TODO: Add your implementation
        }
    }
    
    /**
     * Gets ifMtu value
     * @param ifEntry table entry object
     * @param pdu the received SnmpPdu object
     */
    public int getIfMtu(SnmpTableEntry ifEntry, SnmpPdu pdu)
    {
        synchronized (ifEntry)
        {
            // TODO: Add your implementation
            IfEntry entry = (IfEntry) ifEntry;
            return entry._ifMtu;
        }
    }
    
    /**
     * Sets new ifMtu value
     * @param ifEntry table entry object
     * @param newValue new value to be set
     * @param pdu the received SnmpPdu object
     */
    public void setIfMtuValue(SnmpTableEntry ifEntry, Object newValue, SnmpPdu pdu)
    {
        // This MIB node is not writeable, so IfTableMBean does not have this method
        synchronized (ifEntry)
        {
            IfEntry entry = (IfEntry) ifEntry;
            entry._ifMtu = ( (Integer) newValue).intValue() ;
            // TODO: Add your implementation
        }
    }
    
    /**
     * Gets ifSpeed value
     * @param ifEntry table entry object
     * @param pdu the received SnmpPdu object
     */
    public SnmpGauge32 getIfSpeed(SnmpTableEntry ifEntry, SnmpPdu pdu)
    {
        synchronized (ifEntry)
        {
            // TODO: Add your implementation
            IfEntry entry = (IfEntry) ifEntry;
            return entry._ifSpeed;
        }
    }
    
    /**
     * Sets new ifSpeed value
     * @param ifEntry table entry object
     * @param newValue new value to be set
     * @param pdu the received SnmpPdu object
     */
    public void setIfSpeedValue(SnmpTableEntry ifEntry, Object newValue, SnmpPdu pdu)
    {
        // This MIB node is not writeable, so IfTableMBean does not have this method
        synchronized (ifEntry)
        {
            IfEntry entry = (IfEntry) ifEntry;
            entry._ifSpeed = (SnmpGauge32) newValue;
            // TODO: Add your implementation
        }
    }
    
    /**
     * Gets ifPhysAddress value
     * @param ifEntry table entry object
     * @param pdu the received SnmpPdu object
     */
    public String getIfPhysAddress(SnmpTableEntry ifEntry, SnmpPdu pdu)
    {
        synchronized (ifEntry)
        {
            // TODO: Add your implementation
            IfEntry entry = (IfEntry) ifEntry;
            return entry._ifPhysAddress;
        }
    }
    
    /**
     * Sets new ifPhysAddress value
     * @param ifEntry table entry object
     * @param newValue new value to be set
     * @param pdu the received SnmpPdu object
     */
    public void setIfPhysAddressValue(SnmpTableEntry ifEntry, Object newValue, SnmpPdu pdu)
    {
        // This MIB node is not writeable, so IfTableMBean does not have this method
        synchronized (ifEntry)
        {
            IfEntry entry = (IfEntry) ifEntry;
            entry._ifPhysAddress = (String) newValue;
            // TODO: Add your implementation
        }
    }
    
    /**
     * Gets ifAdminStatus value
     * @param ifEntry table entry object
     * @param pdu the received SnmpPdu object
     */
    public int getIfAdminStatus(SnmpTableEntry ifEntry, SnmpPdu pdu)
    {
        synchronized (ifEntry)
        {
            // TODO: Add your implementation
            IfEntry entry = (IfEntry) ifEntry;
            return entry._ifAdminStatus;
        }
    }
    
    /**
     * Sets new ifAdminStatus value
     * @param ifEntry table entry object
     * @param newValue new value to be set
     * @param pdu the received SnmpPdu object
     */
    public void setIfAdminStatusValue(SnmpTableEntry ifEntry, Object newValue, SnmpPdu pdu)
    {
        synchronized (ifEntry)
        {
            IfEntry entry = (IfEntry) ifEntry;
            entry._ifAdminStatus = ( (Integer) newValue).intValue() ;
            // TODO: Add your implementation
        }
    }
    
    /**
     * Gets ifOperStatus value
     * @param ifEntry table entry object
     * @param pdu the received SnmpPdu object
     */
    public int getIfOperStatus(SnmpTableEntry ifEntry, SnmpPdu pdu)
    {
        synchronized (ifEntry)
        {
            // TODO: Add your implementation
            IfEntry entry = (IfEntry) ifEntry;
            return entry._ifOperStatus;
        }
    }
    
    /**
     * Sets new ifOperStatus value
     * @param ifEntry table entry object
     * @param newValue new value to be set
     * @param pdu the received SnmpPdu object
     */
    public void setIfOperStatusValue(SnmpTableEntry ifEntry, Object newValue, SnmpPdu pdu)
    {
        // This MIB node is not writeable, so IfTableMBean does not have this method
        synchronized (ifEntry)
        {
            IfEntry entry = (IfEntry) ifEntry;
            entry._ifOperStatus = ( (Integer) newValue).intValue() ;
            // TODO: Add your implementation
        }
    }
    
    /**
     * Gets ifLastChange value
     * @param ifEntry table entry object
     * @param pdu the received SnmpPdu object
     */
    public SnmpTimeTicks getIfLastChange(SnmpTableEntry ifEntry, SnmpPdu pdu)
    {
        synchronized (ifEntry)
        {
            // TODO: Add your implementation
            IfEntry entry = (IfEntry) ifEntry;
            return entry._ifLastChange;
        }
    }
    
    /**
     * Sets new ifLastChange value
     * @param ifEntry table entry object
     * @param newValue new value to be set
     * @param pdu the received SnmpPdu object
     */
    public void setIfLastChangeValue(SnmpTableEntry ifEntry, Object newValue, SnmpPdu pdu)
    {
        // This MIB node is not writeable, so IfTableMBean does not have this method
        synchronized (ifEntry)
        {
            IfEntry entry = (IfEntry) ifEntry;
            entry._ifLastChange = (SnmpTimeTicks) newValue;
            // TODO: Add your implementation
        }
    }
    
    /**
     * Gets ifInOctets value
     * @param ifEntry table entry object
     * @param pdu the received SnmpPdu object
     */
    public SnmpCounter32 getIfInOctets(SnmpTableEntry ifEntry, SnmpPdu pdu)
    {
        synchronized (ifEntry)
        {
            // TODO: Add your implementation
            IfEntry entry = (IfEntry) ifEntry;
            return entry._ifInOctets;
        }
    }
    
    /**
     * Sets new ifInOctets value
     * @param ifEntry table entry object
     * @param newValue new value to be set
     * @param pdu the received SnmpPdu object
     */
    public void setIfInOctetsValue(SnmpTableEntry ifEntry, Object newValue, SnmpPdu pdu)
    {
        // This MIB node is not writeable, so IfTableMBean does not have this method
        synchronized (ifEntry)
        {
            IfEntry entry = (IfEntry) ifEntry;
            entry._ifInOctets = (SnmpCounter32) newValue;
            // TODO: Add your implementation
        }
    }
    
    /**
     * Gets ifInUcastPkts value
     * @param ifEntry table entry object
     * @param pdu the received SnmpPdu object
     */
    public SnmpCounter32 getIfInUcastPkts(SnmpTableEntry ifEntry, SnmpPdu pdu)
    {
        synchronized (ifEntry)
        {
            // TODO: Add your implementation
            IfEntry entry = (IfEntry) ifEntry;
            return entry._ifInUcastPkts;
        }
    }
    
    /**
     * Sets new ifInUcastPkts value
     * @param ifEntry table entry object
     * @param newValue new value to be set
     * @param pdu the received SnmpPdu object
     */
    public void setIfInUcastPktsValue(SnmpTableEntry ifEntry, Object newValue, SnmpPdu pdu)
    {
        // This MIB node is not writeable, so IfTableMBean does not have this method
        synchronized (ifEntry)
        {
            IfEntry entry = (IfEntry) ifEntry;
            entry._ifInUcastPkts = (SnmpCounter32) newValue;
            // TODO: Add your implementation
        }
    }
    
    /**
     * Gets ifInNUcastPkts value
     * @param ifEntry table entry object
     * @param pdu the received SnmpPdu object
     */
    public SnmpCounter32 getIfInNUcastPkts(SnmpTableEntry ifEntry, SnmpPdu pdu)
    {
        synchronized (ifEntry)
        {
            // TODO: Add your implementation
            IfEntry entry = (IfEntry) ifEntry;
            return entry._ifInNUcastPkts;
        }
    }
    
    /**
     * Sets new ifInNUcastPkts value
     * @param ifEntry table entry object
     * @param newValue new value to be set
     * @param pdu the received SnmpPdu object
     */
    public void setIfInNUcastPktsValue(SnmpTableEntry ifEntry, Object newValue, SnmpPdu pdu)
    {
        // This MIB node is not writeable, so IfTableMBean does not have this method
        synchronized (ifEntry)
        {
            IfEntry entry = (IfEntry) ifEntry;
            entry._ifInNUcastPkts = (SnmpCounter32) newValue;
            // TODO: Add your implementation
        }
    }
    
    /**
     * Gets ifInDiscards value
     * @param ifEntry table entry object
     * @param pdu the received SnmpPdu object
     */
    public SnmpCounter32 getIfInDiscards(SnmpTableEntry ifEntry, SnmpPdu pdu)
    {
        synchronized (ifEntry)
        {
            // TODO: Add your implementation
            IfEntry entry = (IfEntry) ifEntry;
            return entry._ifInDiscards;
        }
    }
    
    /**
     * Sets new ifInDiscards value
     * @param ifEntry table entry object
     * @param newValue new value to be set
     * @param pdu the received SnmpPdu object
     */
    public void setIfInDiscardsValue(SnmpTableEntry ifEntry, Object newValue, SnmpPdu pdu)
    {
        // This MIB node is not writeable, so IfTableMBean does not have this method
        synchronized (ifEntry)
        {
            IfEntry entry = (IfEntry) ifEntry;
            entry._ifInDiscards = (SnmpCounter32) newValue;
            // TODO: Add your implementation
        }
    }
    
    /**
     * Gets ifInErrors value
     * @param ifEntry table entry object
     * @param pdu the received SnmpPdu object
     */
    public SnmpCounter32 getIfInErrors(SnmpTableEntry ifEntry, SnmpPdu pdu)
    {
        synchronized (ifEntry)
        {
            // TODO: Add your implementation
            IfEntry entry = (IfEntry) ifEntry;
            return entry._ifInErrors;
        }
    }
    
    /**
     * Sets new ifInErrors value
     * @param ifEntry table entry object
     * @param newValue new value to be set
     * @param pdu the received SnmpPdu object
     */
    public void setIfInErrorsValue(SnmpTableEntry ifEntry, Object newValue, SnmpPdu pdu)
    {
        // This MIB node is not writeable, so IfTableMBean does not have this method
        synchronized (ifEntry)
        {
            IfEntry entry = (IfEntry) ifEntry;
            entry._ifInErrors = (SnmpCounter32) newValue;
            // TODO: Add your implementation
        }
    }
    
    /**
     * Gets ifInUnknownProtos value
     * @param ifEntry table entry object
     * @param pdu the received SnmpPdu object
     */
    public SnmpCounter32 getIfInUnknownProtos(SnmpTableEntry ifEntry, SnmpPdu pdu)
    {
        synchronized (ifEntry)
        {
            // TODO: Add your implementation
            IfEntry entry = (IfEntry) ifEntry;
            return entry._ifInUnknownProtos;
        }
    }
    
    /**
     * Sets new ifInUnknownProtos value
     * @param ifEntry table entry object
     * @param newValue new value to be set
     * @param pdu the received SnmpPdu object
     */
    public void setIfInUnknownProtosValue(SnmpTableEntry ifEntry, Object newValue, SnmpPdu pdu)
    {
        // This MIB node is not writeable, so IfTableMBean does not have this method
        synchronized (ifEntry)
        {
            IfEntry entry = (IfEntry) ifEntry;
            entry._ifInUnknownProtos = (SnmpCounter32) newValue;
            // TODO: Add your implementation
        }
    }
    
    /**
     * Gets ifOutOctets value
     * @param ifEntry table entry object
     * @param pdu the received SnmpPdu object
     */
    public SnmpCounter32 getIfOutOctets(SnmpTableEntry ifEntry, SnmpPdu pdu)
    {
        synchronized (ifEntry)
        {
            // TODO: Add your implementation
            IfEntry entry = (IfEntry) ifEntry;
            return entry._ifOutOctets;
        }
    }
    
    /**
     * Sets new ifOutOctets value
     * @param ifEntry table entry object
     * @param newValue new value to be set
     * @param pdu the received SnmpPdu object
     */
    public void setIfOutOctetsValue(SnmpTableEntry ifEntry, Object newValue, SnmpPdu pdu)
    {
        // This MIB node is not writeable, so IfTableMBean does not have this method
        synchronized (ifEntry)
        {
            IfEntry entry = (IfEntry) ifEntry;
            entry._ifOutOctets = (SnmpCounter32) newValue;
            // TODO: Add your implementation
        }
    }
    
    /**
     * Gets ifOutUcastPkts value
     * @param ifEntry table entry object
     * @param pdu the received SnmpPdu object
     */
    public SnmpCounter32 getIfOutUcastPkts(SnmpTableEntry ifEntry, SnmpPdu pdu)
    {
        synchronized (ifEntry)
        {
            // TODO: Add your implementation
            IfEntry entry = (IfEntry) ifEntry;
            return entry._ifOutUcastPkts;
        }
    }
    
    /**
     * Sets new ifOutUcastPkts value
     * @param ifEntry table entry object
     * @param newValue new value to be set
     * @param pdu the received SnmpPdu object
     */
    public void setIfOutUcastPktsValue(SnmpTableEntry ifEntry, Object newValue, SnmpPdu pdu)
    {
        // This MIB node is not writeable, so IfTableMBean does not have this method
        synchronized (ifEntry)
        {
            IfEntry entry = (IfEntry) ifEntry;
            entry._ifOutUcastPkts = (SnmpCounter32) newValue;
            // TODO: Add your implementation
        }
    }
    
    /**
     * Gets ifOutNUcastPkts value
     * @param ifEntry table entry object
     * @param pdu the received SnmpPdu object
     */
    public SnmpCounter32 getIfOutNUcastPkts(SnmpTableEntry ifEntry, SnmpPdu pdu)
    {
        synchronized (ifEntry)
        {
            // TODO: Add your implementation
            IfEntry entry = (IfEntry) ifEntry;
            return entry._ifOutNUcastPkts;
        }
    }
    
    /**
     * Sets new ifOutNUcastPkts value
     * @param ifEntry table entry object
     * @param newValue new value to be set
     * @param pdu the received SnmpPdu object
     */
    public void setIfOutNUcastPktsValue(SnmpTableEntry ifEntry, Object newValue, SnmpPdu pdu)
    {
        // This MIB node is not writeable, so IfTableMBean does not have this method
        synchronized (ifEntry)
        {
            IfEntry entry = (IfEntry) ifEntry;
            entry._ifOutNUcastPkts = (SnmpCounter32) newValue;
            // TODO: Add your implementation
        }
    }
    
    /**
     * Gets ifOutDiscards value
     * @param ifEntry table entry object
     * @param pdu the received SnmpPdu object
     */
    public SnmpCounter32 getIfOutDiscards(SnmpTableEntry ifEntry, SnmpPdu pdu)
    {
        synchronized (ifEntry)
        {
            // TODO: Add your implementation
            IfEntry entry = (IfEntry) ifEntry;
            return entry._ifOutDiscards;
        }
    }
    
    /**
     * Sets new ifOutDiscards value
     * @param ifEntry table entry object
     * @param newValue new value to be set
     * @param pdu the received SnmpPdu object
     */
    public void setIfOutDiscardsValue(SnmpTableEntry ifEntry, Object newValue, SnmpPdu pdu)
    {
        // This MIB node is not writeable, so IfTableMBean does not have this method
        synchronized (ifEntry)
        {
            IfEntry entry = (IfEntry) ifEntry;
            entry._ifOutDiscards = (SnmpCounter32) newValue;
            // TODO: Add your implementation
        }
    }
    
    /**
     * Gets ifOutErrors value
     * @param ifEntry table entry object
     * @param pdu the received SnmpPdu object
     */
    public SnmpCounter32 getIfOutErrors(SnmpTableEntry ifEntry, SnmpPdu pdu)
    {
        synchronized (ifEntry)
        {
            // TODO: Add your implementation
            IfEntry entry = (IfEntry) ifEntry;
            return entry._ifOutErrors;
        }
    }
    
    /**
     * Sets new ifOutErrors value
     * @param ifEntry table entry object
     * @param newValue new value to be set
     * @param pdu the received SnmpPdu object
     */
    public void setIfOutErrorsValue(SnmpTableEntry ifEntry, Object newValue, SnmpPdu pdu)
    {
        // This MIB node is not writeable, so IfTableMBean does not have this method
        synchronized (ifEntry)
        {
            IfEntry entry = (IfEntry) ifEntry;
            entry._ifOutErrors = (SnmpCounter32) newValue;
            // TODO: Add your implementation
        }
    }
    
    /**
     * Gets ifOutQLen value
     * @param ifEntry table entry object
     * @param pdu the received SnmpPdu object
     */
    public SnmpGauge32 getIfOutQLen(SnmpTableEntry ifEntry, SnmpPdu pdu)
    {
        synchronized (ifEntry)
        {
            // TODO: Add your implementation
            IfEntry entry = (IfEntry) ifEntry;
            return entry._ifOutQLen;
        }
    }
    
    /**
     * Sets new ifOutQLen value
     * @param ifEntry table entry object
     * @param newValue new value to be set
     * @param pdu the received SnmpPdu object
     */
    public void setIfOutQLenValue(SnmpTableEntry ifEntry, Object newValue, SnmpPdu pdu)
    {
        // This MIB node is not writeable, so IfTableMBean does not have this method
        synchronized (ifEntry)
        {
            IfEntry entry = (IfEntry) ifEntry;
            entry._ifOutQLen = (SnmpGauge32) newValue;
            // TODO: Add your implementation
        }
    }
    
    /**
     * Gets ifSpecific value
     * @param ifEntry table entry object
     * @param pdu the received SnmpPdu object
     */
    public SnmpOID getIfSpecific(SnmpTableEntry ifEntry, SnmpPdu pdu)
    {
        synchronized (ifEntry)
        {
            // TODO: Add your implementation
            IfEntry entry = (IfEntry) ifEntry;
            return entry._ifSpecific;
        }
    }
    
    /**
     * Sets new ifSpecific value
     * @param ifEntry table entry object
     * @param newValue new value to be set
     * @param pdu the received SnmpPdu object
     */
    public void setIfSpecificValue(SnmpTableEntry ifEntry, Object newValue, SnmpPdu pdu)
    {
        // This MIB node is not writeable, so IfTableMBean does not have this method
        synchronized (ifEntry)
        {
            IfEntry entry = (IfEntry) ifEntry;
            entry._ifSpecific = (SnmpOID) newValue;
            // TODO: Add your implementation
        }
    }
    
}