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

[ns] [bug] Minor Bug in TCP code



[Bug Report]

-----------------------------
Category:  Other
Package:   ns ns-allinone-2.1b8a
OS:        Linux
Environment Variables:
LD_LIBRARY_PATH=
TCL_LIBRARY=
TK_LIBRARY=


-----------------------------
Description:

I had sent this mail earlier on the ns mailing list. I hadn't sent it as a bug report.

Description of 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.


How Easily Reproducible:
(e.g. every time, intermittent, once only, etc.)


Steps to Reproduce:
(describe the minimal set of steps necessary to trigger the bug)
1. 
2. 
3. 


Actual Results:
(describe what the application did after performing the above steps)


Expected Results:
(describe what the application should have done, were the bug not present)


Additional Information:
(the following infomation is helpful to debug:
 1. simulation script, detailed output files, packet trace
 2. patch file if you modify some source code
 3. a backtrace from gdb if you get a segment fault
 If they are big files, PLEASE put them in your web space and
 include the URL here.)