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

import agent.multihome.interface1.*;
import agent.multihome.interface2.*;

/**
 * Agent main class
 */
public class Agent extends SnmpAgentX
{
    
    /**
     * Constructor. Create MBeanServer instance internally. Agent will be listening on port specified in config file, which can be retrieved by using SnmpAgentConfig.getPort().
     * @param configFileName Agent's config file name. If absolute path is not specified, the file will be assumed located under ./config directory or current directory
     */
    public Agent(String configFileName) throws Exception
    {
        super(configFileName, false);
    }
    
    /**
     * Constructor. Use MBeanServer object passed from caller
     * @param server MBeanServer object
     * @param configFileName Agent's config file name. If absolute path is not specified, the file will be assumed located under ./config directory or current directory
     */
    public Agent(MBeanServer server, String configFileName) throws Exception
    {
        super(server, configFileName, false);
    }
    
    public static void main(String[] args)
    {
        try
        {
            String configFile = "config\\MultiHomeSnmpAgent.xml";
            Agent agent = new Agent(configFile);
            agent.startMasterAgent();//start master agent listening on a port specified in config file

            MBeanServer server = agent.getMBeanServer();

            If1Agent  if1agent = new If1Agent (server, "config\\If1SnmpAgent.xml");
            SubAgentSession session1 = if1agent.connect(agent.getConfig().getIpAddress(), 705);
            
            //register first row of ifTable
            int ret = session1.register(OIDTree.IFENTRY + ".1.1" , 10, 22, 30);
            if(ret != 0)
            {
                Logger.error("ifagent1 registration of subtree failed");
            }

            If2Agent  if2agent = new If2Agent (server, "config\\If2SnmpAgent.xml");
            SubAgentSession session2 = if2agent.connect(agent.getConfig().getIpAddress(), 705);
            //register second row of ifTable
            ret = session2.register(OIDTree.IFENTRY + ".1.2" , 10, 22, 30);
            if(ret != 0)
            {
                Logger.error("ifagent2 registration of subtree failed");
            }
        }
        catch(Exception e)
        {
            Logger.error(e);
        }
    }
    
    /**
     * Sets the MIB tree data structure. This method gets called by base class
     */
    protected void setOIDTree()
    {
        _root = OIDTree.getTree();
    }
    
    /**
     * Register necessary MBeans
     */
    protected void registerMBeans() throws SnmpException
    {
        AgentMib.registerMBeans(_mbeanServer, _root);
    }
    
    /**
     * Unregister necessary MBeans
     */
    protected void unregisterMBeans()
    {
        AgentMib.unregisterMBeans();
    }
}