#include "EthernetLinkDelay.h"

namespace cosi {

namespace models {

namespace wiredbas {

EthernetLinkDelay::EthernetLinkDelay(double pSpeed) {
	mSpeed = pSpeed;
	enum Field {PREAMBLE,SOF,DEST,SRC,TYPE,PAYLOAD,CRC,IFD};
	mFieldLength[PREAMBLE] = 56;
	mFieldLength[SOF] = 8;
	mFieldLength[DEST] = 48;
	mFieldLength[SRC] = 48;
	mFieldLength[TYPE] = 16;
	mFieldLength[CRC] = 32;
	mFieldLength[IFD] = 96;
	mOverhead = mFieldLength[PREAMBLE] + mFieldLength[SOF] + mFieldLength[DEST]
			+ mFieldLength[SRC] +mFieldLength[TYPE]+mFieldLength[CRC]
			+ mFieldLength[IFD] ;
}

EthernetLinkDelay::~EthernetLinkDelay() {
}

RealDelay EthernetLinkDelay::Get(int MsgLength, WiringPath pPath) {

}

double EthernetLinkDelay::GetValue(int MsgLength, WiringPath pPath) {
	int Nframe = (int)ceil((double)MsgLength/ 12000.0) ;
	int LastFrame = Nframe%12000;
	if (LastFrame < 368)
		LastFrame = 368;
	int Nbits = (Nframe-1)*(mOverhead + 12000)  + mOverhead + (int) ceil((double)LastFrame/8.0);
	return ( (double)Nbits / mSpeed ) ;
}

}

}

}
