%description:
Tests TCPMsgBasedSendQueue, TCPMsgBasedRcvQueue classes
- segments with/without last byte of message
- overlapped segments
- segments out of order

%includes:
#include "TCPQueueTesterFunctions.h"

%global:

using namespace ::inet::tcp;

%activity:
TCPMsgBasedSendQueue sendQueue;
TCPMsgBasedSendQueue *sq = &sendQueue;

sq->init(1000);
EV << sq->info() <<"\n";

TCPMsgBasedRcvQueue rcvQueue;
TCPMsgBasedRcvQueue *rq = &rcvQueue;

rq->init(1000);
EV << rq->info() <<"\n";

enqueue(sq, "msg1", 100); // 1000..1100
enqueue(sq, "msg2", 400); // 1100..1500
enqueue(sq, "msg3", 600); // 1500..2100
enqueue(sq, "msg4",  50); // 2100..2150
enqueue(sq, "msg5", 150); // 2150..2300

insertSegment(rq, createSegmentWithBytes(sq, 1000, 1099));
insertSegment(rq, createSegmentWithBytes(sq, 1000, 1100));
insertSegment(rq, createSegmentWithBytes(sq, 1000, 2099));
insertSegment(rq, createSegmentWithBytes(sq, 1000, 2100));
insertSegment(rq, createSegmentWithBytes(sq, 2000, 2099));
insertSegment(rq, createSegmentWithBytes(sq, 2000, 2100));

extractBytesUpTo(rq, 2099);
extractBytesUpTo(rq, 2099);
extractBytesUpTo(rq, 2099);
extractBytesUpTo(rq, 2099);
extractBytesUpTo(rq, 2099);
discardUpTo(sq, 2099);

extractBytesUpTo(rq, 2100);
extractBytesUpTo(rq, 2100);
discardUpTo(sq, 2100);

insertSegment(rq, createSegmentWithBytes(sq, 2200, 2300));
insertSegment(rq, createSegmentWithBytes(sq, 2100, 2200));
extractBytesUpTo(rq, 2200);
extractBytesUpTo(rq, 2300);
discardUpTo(sq, 2300);

EV << ".\n";

%subst: /[\{\}]/ /

%contains: stdout
[1000..1000), 0 packets
rcv_nxt=1000 0 msgs
SQ:enqueue("msg1", 100): --> [1000..1100), 1 packets
SQ:enqueue("msg2", 400): --> [1000..1500), 2 packets
SQ:enqueue("msg3", 600): --> [1000..2100), 3 packets
SQ:enqueue("msg4", 50): --> [1000..2150), 4 packets
SQ:enqueue("msg5", 150): --> [1000..2300), 5 packets
SQ:createSegmentWithBytes(1000, 1099):
RQ:insertSeg [1000..1099) --> rcv_nxt=1099 [1000..1099) 0 msgs
SQ:createSegmentWithBytes(1000, 1100): msg1[1000..1100)
RQ:insertSeg [1000..1100) --> rcv_nxt=1100 [1000..1100) 1 msgs
SQ:createSegmentWithBytes(1000, 2099): msg1[1000..1100), msg2[1100..1500)
RQ:insertSeg [1000..2099) --> rcv_nxt=2099 [1000..2099) 2 msgs
SQ:createSegmentWithBytes(1000, 2100): msg1[1000..1100), msg2[1100..1500), msg3[1500..2100)
RQ:insertSeg [1000..2100) --> rcv_nxt=2100 [1000..2100) 3 msgs
SQ:createSegmentWithBytes(2000, 2099):
RQ:insertSeg [2000..2099) --> rcv_nxt=2100 [1000..2100) 3 msgs
SQ:createSegmentWithBytes(2000, 2100): msg3[1500..2100)
RQ:insertSeg [2000..2100) --> rcv_nxt=2100 [1000..2100) 3 msgs
RQ:extractUpTo(2099): < < msg1: 100 bytes > < msg2: 400 bytes > > --> rcv_nxt=2100 [2099..2100) 1 msgs
RQ:extractUpTo(2099): < > --> rcv_nxt=2100 [2099..2100) 1 msgs
RQ:extractUpTo(2099): < > --> rcv_nxt=2100 [2099..2100) 1 msgs
RQ:extractUpTo(2099): < > --> rcv_nxt=2100 [2099..2100) 1 msgs
RQ:extractUpTo(2099): < > --> rcv_nxt=2100 [2099..2100) 1 msgs
SQ:discardUpTo(2099): [2099..2300), 3 packets
RQ:extractUpTo(2100): < < msg3: 600 bytes > > --> rcv_nxt=2100 0 msgs
RQ:extractUpTo(2100): < > --> rcv_nxt=2100 0 msgs
SQ:discardUpTo(2100): [2100..2300), 2 packets
SQ:createSegmentWithBytes(2200, 2300): msg5[2150..2300)
RQ:insertSeg [2200..2300) --> rcv_nxt=2100 [2200..2300) 1 msgs
SQ:createSegmentWithBytes(2100, 2200): msg4[2100..2150)
RQ:insertSeg [2100..2200) --> rcv_nxt=2300 [2100..2300) 2 msgs
RQ:extractUpTo(2200): < < msg4: 50 bytes > > --> rcv_nxt=2300 [2200..2300) 1 msgs
RQ:extractUpTo(2300): < < msg5: 150 bytes > > --> rcv_nxt=2300 0 msgs
SQ:discardUpTo(2300): [2300..2300), 0 packets
.
