#include "EthernetSwitch.h"

namespace cosi {

namespace library {

namespace wiredbas {

using namespace std ;

EthernetSwitch::EthernetSwitch(int Nin, int Nout, double Speed) {
	ComponentType = "Router";
	for (int i = 0; i < Nin; i++) {
		stringstream s;
		s << i;
		string Pname = "P" + s.str() ;
		mPorts.AddPort(Pname, "Eth", cosi::PortInterface::INOUT) ;
	}

	for (int i = 0; i < Nout; i++) {
		stringstream s;
		s << Nin + i;
		string Pname = "P" + s.str() ;
		mPorts.AddPort(Pname, "Eth", cosi::PortInterface::INOUT) ;
	}

	stringstream s;
	s << "Ethernet-Switch_" << Nin + Nout << std::endl;
	ComponentName = s.str();
	mDelayModel = new cosi::models::wiredbas::EthernetSwitchDelay(Speed) ;
}

EthernetSwitch::~EthernetSwitch() {
}

cosi::commstruct::wiredbas::PlatformInstance* EthernetSwitch::GetPlatformInstance(
		int V, Position pP) {
	cosi::commstruct::wiredbas::PlatformInstance * RetVal =
			new cosi::commstruct::wiredbas::PlatformInstance("");
	RetVal->AddVertex(V) ;
	(*RetVal)[V].PRJ(Name)SetValue(ComponentName);
	(*RetVal)[V].PRJ(Type)SetValue(ComponentType);
	(*RetVal)[V].PRJ(Position)Set(pP);
	(*RetVal)[V].PRJ(Ports)Set(mPorts);
	return RetVal;
}

cosi::commstruct::wiredbas::Implementation * EthernetSwitch::GetImplementationInstance(
		int V, Position pP, ThreadSet pThreads, TransferTable pT) {
	cosi::commstruct::wiredbas::Implementation
					* RetVal = new cosi::commstruct::wiredbas::Implementation("");
	RetVal->AddVertex(V) ;
	(*RetVal)[V].PRJ(Name)SetValue(ComponentName);
	(*RetVal)[V].PRJ(Type)SetValue(ComponentType);
	(*RetVal)[V].PRJ(Position)Set(pP);
	(*RetVal)[V].PRJ(Ports)Set(mPorts);
	(*RetVal)[V].PRJ(ThreadSet)Set(pThreads);
	(*RetVal)[V].PRJ(TransferTable)Set(pT);
	return RetVal;
}

double EthernetSwitch::GetCost() {
	return mCostModel->GetValue(ComponentName, ComponentType, mPorts) ;
}

RealDelay EthernetSwitch::GetDelay(Vertex NodeId,
		cosi::commstruct::wiredbas::Implementation* pI,Vertex Src, std::string Dest){
	return mDelayModel->Get(NodeId,pI,Src,Dest) ;
}
double EthernetSwitch::GetDelayValue(Vertex NodeId,
		cosi::commstruct::wiredbas::Implementation* pI,Vertex Src, std::string Dest){
	return mDelayModel->GetValue(NodeId,pI,Src,Dest) ;
}

}

}

}
