Help with TcpSocketFactory and GenerateTraffic application

205 views
Skip to first unread message

Thiago

unread,
Jan 4, 2016, 12:08:18 AM1/4/16
to ns-3-users
Dear NS-3 users,

Hope you all had a great holidays!

I am simulating a scenario with Wi-Fi nodes using OLSR, where the source node sends a certain traffic to the sink node. My scenario is very similar to the one on wifi-simple-adhoc-grid.cc, but I want to use TCP instead.
I modified the code to use TcpSocketFactory instead of UdpSocketFactory. I am also using the FlowMonitor to get the statistics of the transmission. Please see code snippet below.

NodeContainer c;
c.Create (numNodes);

...

Ipv4AddressHelper ipv4;

NS_LOG_INFO ("Assign IP Addresses.");
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer i = ipv4.Assign (devices);


TypeId tid = TypeId::LookupByName ("ns3::TcpSocketFactory");
 
Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (sinkNode), tid);
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
recvSink->Bind (local);
recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));

Ptr<Socket> source = Socket::CreateSocket (c.Get (sourceNode), tid);
InetSocketAddress remote = InetSocketAddress (i.GetAddress (sinkNode, 0), 80);
source->Connect (remote);

...

// Give OLSR time to converge-- 30 seconds perhaps
Simulator::Schedule (Seconds (30.0), &GenerateTraffic,
                     source, packetSize, numPackets, interPacketInterval);


Problem 1:
FlowMonitor shows only one packer transmitted and one received;

Problem 2:
ReceivePacket method is never called.

I was reading the TCP reference page (https://www.nsnam.org/docs/release/3.24/models/html/tcp.html) and looked at the examples in ns-3/examples/tcp, but I could not figure out what is missing.
What is the best way to implement TCP in NS-3? I want an application to send 1000 packets of 1040 bytes each, every 100 ms.

Thanks in advance for your help.

Thiago

Tommaso Pecorella

unread,
Jan 4, 2016, 6:06:37 AM1/4/16
to ns-3-users
Hi,

The best way to use TCP (and UDP as well) is to use an Application. Check the examples.

About your problem (no packets received), check the routing and if the nodes are connected, I.e., if they can ping each other.
If I'm right that example had an issue with nodes becoming disconnect.

Cheers,
T.

Thiago

unread,
Jan 4, 2016, 11:00:16 PM1/4/16
to ns-3-users
Hi Tommaso,

Thanks for your reply.

I tried the BulkSendApplication from the tcp-bulk-send.cc example and it works fine. However, I need to control the rate as the sender forwards the data, i.e., 1 packet per second, 10 packets per second, and so on.
Could you point me to some example/tutorial/thread please?


Ciao

Konstantinos

unread,
Jan 5, 2016, 6:37:14 AM1/5/16
to ns-3-users
You can use OnOffApplication with OffTime=0, so it is always on, and play with packet size/datarate to have the required packet interval.

Tommaso Pecorella

unread,
Jan 5, 2016, 6:54:04 AM1/5/16
to ns-3-users
Hi

check the function
OnOffHelper::SetConstantRate (DataRate dataRate, uint32_t packetSize)

It basically does what you're looking for.

Cheers,

T.
Reply all
Reply to author
Forward
0 new messages