[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ns] how to specify the byte rate of tcp sender
On Wednesday 25 July 2001 03:35, Neundorf Alexander wrote:
> Hi,
>
> I wanted to do something like a cbr tcp source, I took the Telnet
> class as example. I did the following:
Little clarification, please. Are you trying to make a TCP Agent
that sends at a fixed rate? Are you trying to make an Application
that generates data at a fixed rate to be sent using TCP?
> mainly I changed this function:
>
> void MyTestApp::timeout()
> {
> if (running_)
> {
> int sendNow=bitrate_/80;
> agent_->sendmsg(sendNow);
> timer_.resched(0.1);
> };
OK. You are creating a new Application, not a TCP Agent.
>
> Now my tcp source generates packets 10 times per second, but their
> size is *always* 1000 bytes. If I set bitrate_=64000, it should
> send 800 bytes at once. So my received bitrate is 80.000 bit per
> second (10 x 1000 bytes per second, x 8 bit per byte) instead of
> the expected 64000. I already found that TCPAgent::output() uses
> hdr_cmn->size, which is 1000. What am I doing wrong ?
TCP has a field, size_, that gets assigned the value 1000. size_,
through a number of function calls, gets put into the datalen_ field
of the common header. hdr_cmn::access(p)->size() accesses datalen_
to tell how many bytes of data are carried in the packet payload.
I assume that you aren't changing the value, so you are getting the
default size for a TCP packet - 1000 bytes of data per packet.
There are several things you are doing wrong:
1) you are getting the terminology mixed up. You are developing an
Application. Just because you want the Application to send its data
through TCP doesn't make it a TCP source.
2) you are using an awful lot of magic numbers in your code. Why not
make the interval a constant - say MY_INTERVAL. With the constant,
you can then toss the magic number 80 away, making the line read
something like int sendNow = bitrate_ / (8 / MY_INTERVAL);. Change
your mind about how often to send packets, make a single change my
way; make (at least) two changes your way.
3) you are doing something creative that has exposed a flaw in ns :)
sendmsg takes a number of bytes to be sent, but doesn't really use
that number anywhere useful. If sendmsg is going to transmit a
packet, seems like it could use the size it is given to properly
initialize the packet.