[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ns] Minor Bug in TCP code



There seems to be a minor bug in the TCP code in  NS.

The Problem: It apparently drops the very first packet sent out on the
connection. This happens because the TCP has to do a handshake to set up
the connection and therefore sends a SYN packet. The way it is implemented
is that when it is detected that the very first packet is being sent out,
that packet is converted to a SYN packet by changing the size to 40 bytes.
Thus if, say 500bytes, were to be sent out in the first packet, instead
only a SYN packet of 40 bytes is sent out.

If you want to look at where this happens, it's in tcp.cc, in function
TcpAgent::output around line 536:
if (seqno == 0) {
		if (syn_) {
			hdr_cmn::access(p)->size() = tcpip_base_hdr_size_;
		}
...
}


To correct this problem:
In file tcp.cc in function TcpAgent::sendmsg
Around lines, 585 replace
	if (nbytes == -1 && curseq_ <= TCP_MAXSEQ)
		curseq_ = TCP_MAXSEQ;
	else
		curseq_ += (nbytes/size_ + (nbytes%size_ ? 1 : 0));

with the following code:
	if (nbytes == -1 && curseq_ <= TCP_MAXSEQ)
		curseq_ = TCP_MAXSEQ;
	else
	{
		if (syn_ && 0 == curseq_)
			curseq_++;	//For syn packet
		curseq_ += (nbytes/size_ + (nbytes%size_ ? 1 : 0));
	}

This will ensure that when the first packet is being sent out a separate
packet for SYN is sent out before the first packet.

Sugat