How to make a node work as source and sink in manet-routing-compare.cc

140 views
Skip to first unread message

Diljeet Madhani

unread,
Feb 24, 2017, 5:32:10 PM2/24/17
to ns-3-users
Hi all,

I am a beginner in network simulation and ns-3, so please pardon my ignorance if any.

I have thoroughly searched and read the archives, but didn't find anything relevant, at least not with my search terms. Also attempted a couple of things to find the solution myself, but couldn't.

In the example manet-routing-compare.cc, you can set a node as either a source or a sink. But since in the real world a node can be both of them, is there a way to do that in this example?

I guess this is the code that sets sinks and sources:

346  for (int i = 0; i < nSinks; i++)
347  {
348  Ptr<Socket> sink = SetupPacketReceive (adhocInterfaces.GetAddress (i), adhocNodes.Get (i));
349 
350  AddressValue remoteAddress (InetSocketAddress (adhocInterfaces.GetAddress (i), port));
351  onoff1.SetAttribute ("Remote", remoteAddress);
352 
353  Ptr<UniformRandomVariable> var = CreateObject<UniformRandomVariable> ();
354  ApplicationContainer temp = onoff1.Install (adhocNodes.Get (i + nSinks));
355  temp.Start (Seconds (var->GetValue (100.0,101.0)));
356  temp.Stop (Seconds (TotalTime));
357  }
358 

Since the sinks are i and sources are i+nSinks, I changed i+nSinks to i in line 354 to set the same nodes as both sinks and sources. The program runs fine, but no packets is received by any node.

Can someone please point out what am I missing? And what would be the correct way to do it, if it's possible at all?

Apologies if it has been discussed before, it would be great if I can get the link to the thread as I couldn't find anything.

Thanks a bunch.

Diljeet

Tommaso Pecorella

unread,
Feb 28, 2017, 5:33:41 AM2/28/17
to ns-3-users
Hi Diljeet,

you should start from the tutorial. There you'll find explained the concepts of applications, how to install them in the nodes and how to set etc application parameters.
Most probably when you did "move" the sinks, you didn't modify accordingly where the sender are sending the packets.

Cheers,

T.

Diljeet Madhani

unread,
Mar 1, 2017, 8:15:12 AM3/1/17
to ns-3-users
Hi Tommaso,

Thanks for the response.

I had read the tutorial cover to cover, although I have to admit that I didn't understand all of it.

Anyway, I have managed to figure out the solution to above problem. I'd describe it here so that if anyone wants to do something similar, can get an idea.

I was right in thinking that I had to change i+nSinks in line 354, but by changing it to i, I essentially made the UDP source/sink pairs to reside on the same node, which meant nothing was sent out on the network. To change it, I just introduced a new integer variable j, making it equal to nSinks and decrementing it in the loop. Replacing i+nSinks with --j installs sources on the same nodes that have sinks installed on them, just in reverse order. So, for example, if nSinks is equal to 10, node 0 will be source for sink 9, 1 for 8, 2 for 7 and so on. So, actually each node can transmit and receive the data simultaneously. Here's the modified code:

int j=nSinks;
346
  for (int i = 0; i < nSinks; i++)
347  {
348  Ptr<Socket> sink = SetupPacketReceive (adhocInterfaces.GetAddress (i), adhocNodes.Get (i));
349 
350  AddressValue remoteAddress (InetSocketAddress (adhocInterfaces.GetAddress (i), port));
351  onoff1.SetAttribute ("Remote", remoteAddress);
352 
353  Ptr<UniformRandomVariable> var = CreateObject<UniformRandomVariable> ();
354  ApplicationContainer temp = onoff1.Install (adhocNodes.Get (--j));
355  temp.Start (Seconds (var->GetValue (100.0,101.0)));
356  temp.Stop (Seconds (TotalTime));
357  }
358 

Kind regards,

Diljeet

孙岩啸

unread,
Jun 13, 2019, 4:01:42 AM6/13/19
to ns-3-users
Hi Diljeet
you're the king man,  helped me who is an absolute newbie in ns3. thx for sharing your question and solution
sun yanxiao

在 2017年3月1日星期三 UTC+8下午9:15:12,Diljeet Madhani写道:
Reply all
Reply to author
Forward
0 new messages