TCPQueueTesterFunctions.cc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #include "TCPQueueTesterFunctions.h"
  2. using namespace inet;
  3. using namespace inet::tcp;
  4. void enqueue(TCPMsgBasedSendQueue *sq, const char *msgname, ulong numBytes)
  5. {
  6. EV << "SQ:" << "enqueue(\"" << msgname << "\", " << numBytes << "):";
  7. cPacket *msg = new cPacket(msgname);
  8. msg->setByteLength(numBytes);
  9. sq->enqueueAppData(msg);
  10. EV << " --> " << sq->info() <<"\n";
  11. }
  12. void tryenqueue(TCPMsgBasedSendQueue *sq, const char *msgname, ulong numBytes)
  13. {
  14. EV << "SQ:" << "enqueue(\"" << msgname << "\", " << numBytes << "):";
  15. cPacket *msg = new cPacket(msgname);
  16. msg->setByteLength(numBytes);
  17. try {
  18. sq->enqueueAppData(msg);
  19. } catch (cRuntimeError& e) {
  20. delete msg;
  21. EV << " --> Error: " << e.what();
  22. }
  23. EV << " --> " << sq->info() <<"\n";
  24. }
  25. TCPSegment *createSegmentWithBytes(TCPMsgBasedSendQueue *sq, uint32 fromSeq, uint32 toSeq)
  26. {
  27. EV << "SQ:" << "createSegmentWithBytes(" << fromSeq << ", " << toSeq << "):";
  28. ulong numBytes = toSeq-fromSeq;
  29. TCPSegment *tcpseg = sq->createSegmentWithBytes(fromSeq, numBytes);
  30. for (int i=0; i<tcpseg->getPayloadArraySize(); i++)
  31. {
  32. TCPPayloadMessage& payload = tcpseg->getPayload(i);
  33. uint32_t startSeq = payload.endSequenceNo - payload.msg->getByteLength();
  34. EV << (i?", ":" ") << payload.msg->getName() << '[' << startSeq << ".." << payload.endSequenceNo <<')';
  35. }
  36. EV << "\n";
  37. return tcpseg;
  38. }
  39. void discardUpTo(TCPMsgBasedSendQueue *sq, uint32 seqNum)
  40. {
  41. EV << "SQ:" << "discardUpTo(" << seqNum << "): ";
  42. sq->discardUpTo(seqNum);
  43. EV << sq->info() <<"\n";
  44. }
  45. //////////////////////////////////////////////////////////////
  46. void insertSegment(TCPMsgBasedRcvQueue *rq, TCPSegment *tcpseg)
  47. {
  48. uint32_t beg = tcpseg->getSequenceNo();
  49. uint32_t end = beg + tcpseg->getPayloadLength();
  50. EV << "RQ:" << "insertSeg [" << beg << ".." << end << ")";
  51. uint32 rcv_nxt = rq->insertBytesFromSegment(tcpseg);
  52. delete tcpseg;
  53. EV << " --> " << rq->info() <<"\n";
  54. }
  55. void tryinsertSegment(TCPMsgBasedRcvQueue *rq, TCPSegment *tcpseg)
  56. {
  57. uint32_t beg = tcpseg->getSequenceNo();
  58. uint32_t end = beg + tcpseg->getPayloadLength();
  59. EV << "RQ:" << "insertSeg [" << beg << ".." << end << ")";
  60. try {
  61. uint32 rcv_nxt = rq->insertBytesFromSegment(tcpseg);
  62. } catch (cRuntimeError& e) {
  63. EV << " --> Error: " << e.what();
  64. }
  65. delete tcpseg;
  66. EV << " --> " << rq->info() <<"\n";
  67. }
  68. void extractBytesUpTo(TCPMsgBasedRcvQueue *rq, uint32 seq)
  69. {
  70. EV << "RQ:" << "extractUpTo(" << seq << "): <";
  71. cPacket *msg;
  72. while ((msg=rq->extractBytesUpTo(seq)) != NULL)
  73. {
  74. EV << " < " << msg->getName() << ": " << msg->getByteLength() << " bytes >";
  75. delete msg;
  76. }
  77. EV << " > --> " << rq->info() <<"\n";
  78. }
  79. /////////////////////////////////////////////////////////////////////////
  80. void insertSegment(TCPVirtualDataRcvQueue *q, uint32 beg, uint32 end)
  81. {
  82. EV << "RQ:" << "insertSeg [" << beg << ".." << end << ")";
  83. TCPSegment *tcpseg = new TCPSegment();
  84. tcpseg->setSequenceNo(beg);
  85. tcpseg->setPayloadLength(end-beg);
  86. uint32 rcv_nxt = q->insertBytesFromSegment(tcpseg);
  87. delete tcpseg;
  88. EV << " --> " << q->info() <<"\n";
  89. }
  90. void tryinsertSegment(TCPVirtualDataRcvQueue *q, uint32 beg, uint32 end)
  91. {
  92. EV << "RQ:" << "insertSeg [" << beg << ".." << end << ")";
  93. TCPSegment *tcpseg = new TCPSegment();
  94. tcpseg->setSequenceNo(beg);
  95. tcpseg->setPayloadLength(end-beg);
  96. try {
  97. uint32 rcv_nxt = q->insertBytesFromSegment(tcpseg);
  98. } catch (cRuntimeError& e) {
  99. EV << " --> Error: " << e.what();
  100. }
  101. delete tcpseg;
  102. EV << " --> " << q->info() <<"\n";
  103. }
  104. void extractBytesUpTo(TCPVirtualDataRcvQueue *q, uint32 seq)
  105. {
  106. EV << "RQ:" << "extractUpTo(" << seq << "):";
  107. cPacket *msg;
  108. while ((msg=q->extractBytesUpTo(seq))!=NULL)
  109. {
  110. EV << " msglen=" << msg->getByteLength();
  111. delete msg;
  112. }
  113. EV << " --> " << q->info() <<"\n";
  114. }