60 #define THIS_NAME "SIM"
62 #define TRACE_OFF 0x0000
63 #define TRACE_TOE 1 << 1
64 #define TRACE_TOE_LSN 1 << 2
65 #define TRACE_TOE_OPN 1 << 3
66 #define TRACE_TOE_RXP 1 << 4
67 #define TRACE_TOE_TXP 1 << 5
68 #define TRACE_TAF 1 << 6
69 #define TRACE_MMIO 1 << 7
70 #define TRACE_DDSK 1 << 8
71 #define TRACE_DDSP 1 << 9
72 #define TRACE_ALL 0xFFFF
73 #define DEBUG_LEVEL (TRACE_OFF)
110 ap_uint<32> currCount;
111 ap_uint<32> prevCount=0xFFFFFFFF;
115 while (!(ss.empty())) {
117 if (currCount == prevCount) {
118 printWarn(myName,
"Houston, we have a problem !\n\tcurrCount=%d|prevCount=%d\n", currCount.to_uint(), prevCount.to_uint());
121 prevCount = currCount;
137 ap_uint<16> currCount;
138 ap_uint<16> prevCount=0xFFFFFFFF;
142 while (!(ss.empty())) {
144 if (currCount != prevCount) {
146 printInfo(myName,
"Detected a change on stream '%s' (currCounter=%d). \n",
147 ssName.c_str(), currCount.to_uint());
150 prevCount = currCount;
154 printError(myName,
"The free input buffer space (%d) did not settle back to its initial value (%d)!\n",
175 void pTAF(ofstream &ofTAF_Data,
176 stream<TcpAppData> &siTSIF_Data,
177 stream<TcpSessId> &siTSIF_SessId,
178 stream<TcpDatLen> &siTSIF_DatLen,
179 stream<TcpAppData> &soTSIF_Data,
180 stream<TcpSessId> &soTSIF_Meta,
181 stream<TcpSessId> &soTSIF_DLen)
189 if (!siTSIF_SessId.empty()) {
190 siTSIF_SessId.read(sessId);
192 if (!siTSIF_DatLen.empty()) {
193 siTSIF_DatLen.read(datLen);
195 if (!siTSIF_Data.empty()) {
196 siTSIF_Data.read(appData);
216 static bool mmio_printOnce =
true;
220 if (mmio_printOnce) {
222 "[SHELL/NTS/TOE] is ready -> Enabling operation of the TCP Shell Interface [TSIF].\n");
223 mmio_printOnce =
false;
250 ofstream &ofTAF_Gold,
251 ofstream &ofTOE_Gold,
252 ofstream &ofTOE_Data,
259 stream<TcpAppNotif> &soTSIF_Notif,
260 stream<TcpAppRdReq> &siTSIF_DReq,
261 stream<TcpAppData> &soTSIF_Data,
262 stream<TcpAppMeta> &soTSIF_Meta,
264 stream<TcpAppLsnReq> &siTSIF_LsnReq,
265 stream<TcpAppLsnRep> &soTSIF_LsnRep,
267 stream<TcpAppData> &siTSIF_Data,
268 stream<TcpAppSndReq> &siTSIF_SndReq,
269 stream<TcpAppSndRep> &soTSIF_SndRep,
271 stream<TcpAppOpnReq> &siTSIF_OpnReq,
272 stream<TcpAppOpnRep> &soTSIF_OpnRep)
278 static map<SessionId, InterruptEntry> toe_openedSess;
281 static enum FsmStates {
290 } toe_fsmState = CREATE_SCENARIO;
293 static bool toe_rxpIsReady =
false;
294 static bool toe_txpIsReady =
false;
304 if (toe_startupDelay) {
311 toe_rxpIsReady = (toe_startupDelay <= 500) ?
true :
false;
312 toe_txpIsReady = (toe_startupDelay <= 500) ?
true :
false;
319 if (!siTSIF_LsnReq.empty()) {
321 siTSIF_LsnReq.read(appLsnPortReq);
324 appLsnPortReq.to_int());
327 if (!soTSIF_LsnRep.full()) {
331 printFatal(
myLsnName,
"Cannot send listen reply back to [TSIF] because stream is full.\n");
342 if (!siTSIF_OpnReq.empty()) {
343 siTSIF_OpnReq.read(opnReq);
345 printInfo(
myOpnName,
"Received a request to open the following remote socket address:\n");
348 if (!soTSIF_OpnRep.full()) {
349 soTSIF_OpnRep.write(opnReply);
357 printFatal(
myOpnName,
"Cannot send open connection reply back to [TSIF] because stream is full.\n");
367 static int toe_sessCnt = 0;
368 static int toe_segCnt = 0;
372 if (toe_rxpIsReady) {
373 switch (toe_fsmState) {
374 case CREATE_SCENARIO:
375 switch (toe_segCnt) {
378 toe_notifByteCnt = echoDatLen;
384 toe_notifByteCnt = 8;
391 toe_notifByteCnt = 8;
397 toe_notifByteCnt = echoDatLen;
403 toe_notifByteCnt = echoDatLen;
409 if (toe_openedSess.find(toe_sessId) == toe_openedSess.end()) {
416 toe_openedSess[toe_sessId].byteCnt += toe_notifByteCnt;
417 toe_openedSess[toe_sessId].dstPort = toe_hostTcpDstPort;
419 printf(
"[+++] toe_openedSess[%d].byteCnt = %d\n", toe_sessId.to_int(),
420 toe_openedSess[toe_sessId].byteCnt.to_int());
422 toe_fsmState = SEND_NOTIFICATION;
424 case SEND_NOTIFICATION:
425 if (soTSIF_Notif.full()) {
428 soTSIF_Notif.write(
TcpAppNotif(toe_sessId, toe_notifByteCnt, toe_hostIp4Addr,
429 toe_hostTcpSrcPort, toe_hostTcpDstPort));
431 printInfo(
myRxpName,
"Sending Notif to [TSIF] (sessId=%2d, datLen=%4d, dstPort=%4d).\n",
432 toe_sessId.to_int(), toe_notifByteCnt.to_int(), toe_hostTcpDstPort.to_uint());
434 toe_fsmState = SEND_METADATA;
437 if (soTSIF_Meta.full()) {
440 soTSIF_Meta.write(toe_sessId);
442 toe_fsmState = SEND_8801_COMMAND;
444 toe_fsmState = SEND_DATA_SEGMENT;
447 case SEND_DATA_SEGMENT:
450 if (soTSIF_Data.full()) {
453 appData.
setTData((random() << 32) | random());
463 toe_fsmState = NEXT_SEGMENT;
465 soTSIF_Data.write(appData);
473 toe_fsmState = NEXT_SEGMENT;
475 case SEND_8801_COMMAND:
477 if (toe_sessId == 1) {
486 if (soTSIF_Data.full()) {
489 soTSIF_Data.write(appData);
500 if (soTSIF_Data.full()) {
503 soTSIF_Data.write(appData);
508 bool firstChunk =
true;
512 for (
int i = 0; i < 8; i++) {
514 unsigned char byte = (
GEN_CHK0 >> ((7 - i) * 8)) & 0xFF;
515 goldChunk.
setLE_TData(
byte, (i * 8) + 7, (i * 8) + 0);
520 firstChunk = !firstChunk;
523 for (
int i = 0; i < 8; i++) {
525 unsigned char byte = (
GEN_CHK1 >> ((7 - i) * 8)) & 0xFF;
526 goldChunk.
setLE_TData(
byte, (i * 8) + 7, (i * 8) + 0);
531 firstChunk = !firstChunk;
539 toe_fsmState = NEXT_SEGMENT;
543 toe_fsmState = NEXT_ROUND;
546 toe_fsmState = CREATE_SCENARIO;
557 toe_fsmState = CREATE_SCENARIO;
570 if (toe_rxpIsReady) {
572 if (!siTSIF_DReq.empty()) {
573 siTSIF_DReq.read(toe_appRdReq);
575 printInfo(
myRxpName,
"Received a data read request from [TSIF] (sessId=%d, datLen=%d).\n",
579 int sessByteCnt = toe_openedSess[toe_appRdReq.
sessionID].byteCnt.to_int();
580 if (toe_appRdReq.
length.to_int() > sessByteCnt) {
581 printInfo(
myRxpName,
"TOE is requesting more data (%d) than notified (%d) for session #%d !\n",
582 toe_appRdReq.
length.to_int(), sessByteCnt, toe_appRdReq.
sessionID.to_uint());
587 printf(
"[---] toe_openedSess[%d].byteCnt = %d\n", toe_appRdReq.
sessionID.to_int(),
588 toe_openedSess[toe_appRdReq.
sessionID].byteCnt.to_int());
597 if (toe_txpIsReady) {
598 if (!siTSIF_SndReq.empty()) {
600 siTSIF_SndReq.read(toe_appSndReq);
601 if (soTSIF_SndRep.full()) {
605 if (toe_openedSess.find(toe_appSndReq.
sessId) == toe_openedSess.end()) {
612 else if (toe_appSndReq.
length > 0x10000) {
616 printError(
myTxpName,
"There is not enough TxBuf memory space available for session %d.\n",
617 toe_appSndReq.
sessId.to_uint());
626 if (!siTSIF_Data.empty()) {
628 siTSIF_Data.read(appData);
void setTLast(tLast last)
void setLE_TLast(LE_tLast last)
void setLE_TData(LE_tData data, int leHi=64 -1, int leLo=0)
void setTKeep(tKeep keep)
void setTData(tData data)
void setLE_TKeep(LE_tKeep keep, int leHi=64/8-1, int leLo=0)
#define DEFAULT_SESSION_ID
#define DEFAULT_HOST_IP4_ADDR
bool writeAxisRawToFile(AxisRaw &axisRaw, ofstream &outFileStream)
Dump an Axis raw data chunk to a file.
int writeAxisAppToFile(AxisApp &axisApp, ofstream &outFile)
Dump a TCP or UDP application data chunk into a file. The data are stored as a stream of bytes which ...
#define printError(callerName, format,...)
A macro to print an error message.
void printAxisRaw(const char *callerName, AxisRaw chunk)
Prints an Axis raw data chunk (used for debugging).
void printSockAddr(const char *callerName, SockAddr sockAddr)
Print a socket address.
tKeep lenTotKeep(ap_uint< 4 > noValidBytes)
A function to set a number of '1' in an 8-bit field. It is used here to set the number of valid bytes...
#define printInfo(callerName, format,...)
A macro to print an information message.
#define printWarn(callerName, format,...)
A macro to print a warning message.
#define concat3(firstCharConst, secondCharConst, thirdCharConst)
#define printFatal(callerName, format,...)
A macro to print a fatal error message and exit.
bool drainDebugSpaceCounter(stream< ap_uint< 16 > > &ss, string ssName)
Empty the DebugSpaceCounter stream and check its last value.
const int cSimToeStartupDelay
void stepSim()
Increment the simulation counter.
void pTOE(int &nrErr, ofstream &ofTAF_Gold, ofstream &ofTOE_Gold, ofstream &ofTOE_Data, TcpDatLen echoDatLen, SockAddr testSock, TcpDatLen testDatLen, StsBit *poMMIO_Ready, stream< TcpAppNotif > &soTSIF_Notif, stream< TcpAppRdReq > &siTSIF_DReq, stream< TcpAppData > &soTSIF_Data, stream< TcpAppMeta > &soTSIF_Meta, stream< TcpAppLsnReq > &siTSIF_LsnReq, stream< TcpAppLsnRep > &soTSIF_LsnRep, stream< TcpAppData > &siTSIF_Data, stream< TcpAppSndReq > &siTSIF_SndReq, stream< TcpAppSndRep > &soTSIF_SndRep, stream< TcpAppOpnReq > &siTSIF_OpnReq, stream< TcpAppOpnRep > &soTSIF_OpnRep)
Emulate behavior of the SHELL/NTS/TCP Offload Engine (TOE).
#define RECV_MODE_LSN_PORT
#define XMIT_MODE_LSN_PORT
void pMMIO(StsBit *piSHL_Ready, CmdBit *poTSIF_Enable)
Emulate the behavior of the SHELL & MMIO.
unsigned int gMaxSimCycles
void increaseSimTime(unsigned int cycles)
Increase the simulation time of the testbench.
bool drainDebugSinkCounter(stream< ap_uint< 32 > > &ss, string ssName)
Empty the DebugSinkCounter stream and throw it away.
#define DEFAULT_HOST_TCP_SRC_PORT
#define ECHO_MODE_LSN_PORT
void pTAF(ofstream &ofTAF_Data, stream< TcpAppData > &siTSIF_Data, stream< TcpSessId > &siTSIF_SessId, stream< TcpDatLen > &siTSIF_DatLen, stream< TcpAppData > &soTSIF_Data, stream< TcpSessId > &soTSIF_Meta, stream< TcpSessId > &soTSIF_DLen)
Emulate the behavior of the ROLE/TcpAppFlash (TAF).
: Simulation environment for the TCP Shell Interface (TSIF).
ap_uint< 32 > byteSwap32(ap_uint< 32 > inputVector)
ap_uint< 16 > byteSwap16(ap_uint< 16 > inputVector)