#include "protoRouteMgr.h"
//#include "protoRouteTable.h"
//#include "protoSim.h"

class NsRouteMgr : public ProtoRouteMgr
{
public:
  NsRouteMgr();
  ~NsRouteMgr();
  virtual bool Open();
  virtual bool IsOpen() const {return (descriptor >= 0);}
  virtual void Close();
  
  virtual bool GetAllRoutes(ProtoAddress::Type addrType,
			    ProtoRouteTable& routeTable);

  virtual bool GetRoute(const ProtoAddress& dst,
			unsigned int        prefixLen,
			ProtoAddress&       gw,
			unsigned int&       ifIndex,
			int&                metric);

  virtual bool SetRoute(const ProtoAddress& dst,
			unsigned int          prefixLen,
			const ProtoAddress& gw,
			unsigned int          ifIndex = 0,
			int                   metric = -1);

  virtual bool DeleteRoute(const ProtoAddress& dst,
			   unsigned int          prefixLen,
			   const ProtoAddress& gw,
			   unsigned int          ifIndex = 0);  
  virtual bool SetForwarding(bool state);

  bool GetInterfaceAddress(unsigned int       ifIndex, 
			   ProtoAddress::Type addrType,
			   ProtoAddress&    theAddress);       
  int descriptor;
  pid_t pid;
  UINT32 sequence;
  private:
  int forwardingOn;
  ProtoRouteTable localTable;
}; //end class NsRouteMgr

ProtoRouteMgr* ProtoRouteMgr::Create()
{
  return (ProtoRouteMgr*)(new NsRouteMgr);
} // end ProtoRouteMgr::Create()

NsRouteMgr::NsRouteMgr()
{
  localTable.Init();
}

NsRouteMgr::~NsRouteMgr()
{
  Close();
}

bool NsRouteMgr::Open()
{
  return localTable.IsReady();
  //empty? maybe need ProtoRouteTable here?
}

void NsRouteMgr::Close()
{
  //empty? maybe need ProtoRouteTable delete here?
}

bool NsRouteMgr::GetRoute(const ProtoAddress& dst,
			  unsigned int        prefixLen,
			  ProtoAddress&       gw,
			  unsigned int&       ifIndex,
			  int&                metric)
{
  return localTable.FindRoute(dst,prefixLen,gw,ifIndex,metric);
}

bool NsRouteMgr::SetRoute(const ProtoAddress& dst,
			  unsigned int          prefixLen,
			  const ProtoAddress& gw,
			  unsigned int          ifIndex,
			  int                   metric)
{
  return localTable.SetRoute(dst,prefixLen,gw,ifIndex,metric);
  //call ProtoRouteTable setroute if there?
} // end NsRouteMgr::SetRoute()

bool NsRouteMgr::DeleteRoute(const ProtoAddress& dst,
                                unsigned int          prefixLen,
                                const ProtoAddress& gw,
                                unsigned int          ifIndex)
{
  return localTable.DeleteRoute(dst,prefixLen,&gw);
} // end NsRouteMgr::DeleteRoute()

bool NsRouteMgr::GetAllRoutes(ProtoAddress::Type addrType,
				 ProtoRouteTable&   routeTable)
{
  return false; //this function does not currently work in ns
}// end NsRouteMgr::GetAllRoutes

bool NsRouteMgr::GetInterfaceAddress(unsigned int        ifIndex, 
                                        ProtoAddress::Type  addrType,
                                        ProtoAddress&     theAddress)
{
  //this is going to be a little trickier
}
bool NsRouteMgr::SetForwarding(bool state)
{
  forwardingOn=state;
  return true;
}
