Using the TCP for packet transmission

78 views
Skip to first unread message

James Basuino

unread,
May 21, 2015, 9:59:17 AM5/21/15
to ns-3-...@googlegroups.com
Hello, I am new to Ns3 and I was wondering what would be the best way to go about layering on a TCP to an already existing connection type/channel at the application level. I have already worked through the adding new application tutorial and now I want to tweak this application to be a sort of client-server echo but with TCP instead of UDP. Sorry if this is an amateur question, but I would be appreciative for some insight. Thank you.

Tommaso Pecorella

unread,
May 21, 2015, 12:27:15 PM5/21/15
to ns-3-...@googlegroups.com
Hi,

the question isn't completely amateur-ish. Moreover, even if it would be, it's somewhat well explained, and we all have to start from somewhere, ins't it ?
Being newbies isn't a problem (it's a problem when one shouldn't be anymore a newbie and still is).

Anyway, as you may have noticed TCP is a stream protocol. This means that it's not guaranteed that the data the application is sending will be sent with one packet only, and that the receiver will receive one packet with the whole content that the sender has sent. The receiver could need several read to get what the sender did send with one send. There's too many "send" in the previous sentence, but I hope it does make sense.

If the previous sentence makes sense, then you'll understand the following: you need a data format. Typically applications using TCP use a L7 data format, so the receiver knows how many bytes it should read to process a message.
As an example, a HTTP message contains the message length (somewhere). In this way the receiver knows that it must keep reading 'til it decodes the length field, and then it knows how many [more] bytes it must read.

As for your goal, I'd suggest to use a simpler strategy. A common format is the TLV (Type, Length, Value), e.g., one byte to code the message type (echo request, echo reply), one byte for the length and n bytes for the message. If you want to have a message larger than 255 bytes, have a larger length field.
Another good idea is to add a sequence number and a timestamp, much like UDP echo.

Hope this helps,

T.

James Basuino

unread,
May 21, 2015, 1:38:13 PM5/21/15
to ns-3-...@googlegroups.com
Where does the ns3 TCP implementation use the L7 data format? Would I be able to copy it an then tweak it in a similar file to accommodate the simpler data format? Thank you for the correspondence.

Tommaso Pecorella

unread,
May 21, 2015, 2:50:57 PM5/21/15
to ns-3-...@googlegroups.com
Hi,

TCP doesn't use the L7 data format, it's transparent to it.
Unfortunately, we don't have any example of L7 format either. At least not one fully meant to be used with TCP.
You can borrow some ideas from UdpEcho, but pay attention to what I wrote: you can't assume that a Receive will give you enough data to process.

Hope this helps,

T.

James Basuino

unread,
May 21, 2015, 3:23:57 PM5/21/15
to ns-3-...@googlegroups.com
Thank you for the input. Ill try to work it out, I am very new to networking and am trying to learn and figure out as much as possible so I may be posting many more questions in the coming months. I hope they aren't too much of a nuisance haha.
Reply all
Reply to author
Forward
0 new messages