// 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.mib2;
import java.io.*;
import java.util.*;
import com.ireasoning.util.*;
import com.ireasoning.protocol.snmp.*;
import javax.management.*;

/**
 * Class represents atTable MIB object in RFC1213_MIB
 */
public class AtTable extends SnmpTable implements AtTableMBean
{
    public static final SnmpOID[] OIDS = 
    { 
        //atIfIndex column
        new SnmpOID(".1.3.6.1.2.1.3.1.1.1.1.127.0.0.1"),
        new SnmpOID(".1.3.6.1.2.1.3.1.1.1.2.127.0.0.2"),
        new SnmpOID(".1.3.6.1.2.1.3.1.1.1.3.127.0.0.3"),
        new SnmpOID(".1.3.6.1.2.1.3.1.1.1.4.127.0.0.4"),
        new SnmpOID(".1.3.6.1.2.1.3.1.1.1.5.127.0.0.5"),

        //atPhysAddress column
        new SnmpOID(".1.3.6.1.2.1.3.1.1.2.1.127.0.0.1"),
        new SnmpOID(".1.3.6.1.2.1.3.1.1.2.2.127.0.0.2"),
        new SnmpOID(".1.3.6.1.2.1.3.1.1.2.3.127.0.0.3"),
        new SnmpOID(".1.3.6.1.2.1.3.1.1.2.4.127.0.0.4"),
        new SnmpOID(".1.3.6.1.2.1.3.1.1.2.5.127.0.0.5"),

        //atNetAddress column
        new SnmpOID(".1.3.6.1.2.1.3.1.1.3.1.127.0.0.1"),
        new SnmpOID(".1.3.6.1.2.1.3.1.1.3.2.127.0.0.2"),
        new SnmpOID(".1.3.6.1.2.1.3.1.1.3.3.127.0.0.3"),
        new SnmpOID(".1.3.6.1.2.1.3.1.1.3.4.127.0.0.4"),
        new SnmpOID(".1.3.6.1.2.1.3.1.1.3.5.127.0.0.5")

    };

    /**
     * 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 AtTable (OIDTreeNode root, String oid, Object[] args)
    {
        super(root, oid);
        // TODO: Add your implementation
        // new code
        setProcessSnmpRequestDirectly(true);
    }

    // new code
    /**
     * Returns the atIfIndex value contained in the passed oid
     */
    private int getIndexValue(SnmpOID oid)
    {
        int[] val = oid.getValue();
        return val[val.length - 5];
    }

    //new code
    /**
     * Returns the next OID 
     */
    public SnmpTableEntry getNextOID(SnmpOID oid)
    {
        for (int i = 0; i < OIDS.length ; i++) 
        {
            if(OIDS[i].compareTo(oid) > 0) 
            {
                SnmpTableEntry entry = new AtEntry(null);

                //Use oid of the instance node.
                entry.setOID(OIDS[i]);
                return entry;
            }
        }
        return null;
    }

    //new code
    public static final SnmpTableEntry EMPTY_ENTRY = new AtEntry(null);
    
    //new code
    /**
     * @return a non-null object if this oid exists in this subtree
     */
    public SnmpTableEntry getOID(SnmpOID oid)
    {
        for (int i = 0; i < OIDS.length ; i++) 
        {
            if(OIDS[i].equals(oid) ) 
            {
                return EMPTY_ENTRY;
            }
        }
        return null;
    }
    
    /**
     * Creates a new instance of table entry object
     */
    public SnmpTableEntry newEntryInstance()
    {
        return new AtEntry (this);
    }
    
    /**
     * Gets atIfIndex value
     * @param atEntry table entry object
     */
    public int getAtIfIndex(SnmpTableEntry atEntry)
    {
        SnmpTableEntry entry = (SnmpTableEntry) atEntry;
        SnmpOID oid = entry.getOID();
        int index = getIndexValue(oid);
        return index;
    }
    
    /**
     * Sets new atIfIndex value
     * @param atEntry table entry object
     * @param newValue new value to be set
     */
    public void setAtIfIndex(SnmpTableEntry atEntry, int newValue)
    {
    }
    
    /**
     * Gets atPhysAddress value
     * @param atEntry table entry object
     */
    public String getAtPhysAddress(SnmpTableEntry atEntry)
    {
        SnmpTableEntry entry = (SnmpTableEntry) atEntry;
        SnmpOID oid = entry.getOID();
        int index = getIndexValue(oid);
        return "10.20.30.40.50." + index;//return a arbitrary value, only for demo purpose
    }
    
    /**
     * Sets new atPhysAddress value
     * @param atEntry table entry object
     * @param newValue new value to be set
     */
    public void setAtPhysAddress(SnmpTableEntry atEntry, String newValue)
    {
        System.out.println( "setAtPhysAddressValue. newValue is " + newValue);
    }
    
    /**
     * Gets atNetAddress value
     * @param atEntry table entry object
     */
    public SnmpIpAddress getAtNetAddress(SnmpTableEntry atEntry)
    {
        SnmpTableEntry entry = (SnmpTableEntry) atEntry;
        SnmpOID oid = entry.getOID();
        oid = oid.suboid(oid.getLength() - 4, oid.getLength());
        String oidstr = oid.toString();
        oidstr = oidstr.substring(1, oidstr.length());
        return new SnmpIpAddress(oidstr);
    }
    
    /**
     * Sets new atNetAddress value
     * @param atEntry table entry object
     * @param newValue new value to be set
     */
    public void setAtNetAddress(SnmpTableEntry atEntry, SnmpIpAddress newValue)
    {
    }
    
}