ns3 - modifying parameters during simulation

624 views
Skip to first unread message

Marcin Jękot

unread,
Jan 6, 2014, 4:40:01 PM1/6/14
to ns-3-...@googlegroups.com
Hello All,

We have a research project to do for our studies and we encountered serious issue, probably for the fact that we are not very familiar with ns3 environment.

We need to setup a simple point-to-point client-server network, where server will limit the send data depending on current upload to download ratio. So basically mechanism is similiar as in BitTorrent private trackers (if you are uploading to the network more than downloading, you download ratio is faster).

Is there any simple method to do that? We got idea to extract uploaded/downloaded packets sequence number, multiplicate it by packet size, calculate the UL/DL ratio and then map it to the delay in order to change overall throughput. This would be done periodically - let's say every 5 seconds. Is there any simplier method to do that? Some function that calculates sum of all data sent/received until certain moment of simulation?

Second question - if the answer to above is negative, then how to implement such activity? We are using simple UdpServerHelper and UdpClientHelper on both nodes to send/receive data, but we have problem with a) extracting the mentioned values during the simulation b) modify any parameters during the simulation (without interrupting it).

Shoud we use flowMonitor for a? And what solution is feasible for b)?
I would be extremely grateful for any assisstance!

Thanks,
Marcin
AGH University of Science and Technology

Tommaso Pecorella

unread,
Jan 6, 2014, 4:59:14 PM1/6/14
to ns-3-...@googlegroups.com
Hi,

I'd say that the "easiest" method is to do it by yourself. FlowMon could be interesting to check, but it might a bit too complex to start with. Moreover it's designed to collect data 'til the end of simulation, not to give you on-line statistics.

I'd start "slowly", and then maybe make your model more complex once you're fluent with ns-3.

As a start, study the UdpServer and UdpClient (not the helpers, the applications code). You'll learn how to receive a packet and count how many packets you got and how big they are.
Once you got how to measure, all you need is a periodic function (again, UdpClient or Ping4 can help) to get the partial data and do a decision.

Of course, the problem might be a bit more complex if the nodes are more than two (you'll need a container for the statistics, and a purge method for dead flows). Moreover, if the stats are to be collected by a man-in-the-middle, then things might become definitely more complex.
However, I'd suggest to start with the simplest thing, just to grasp the concepts.

Cheers,

T.

PS. don't use the sequence numbers. For each packet you get, extract its size. It's packet->GetSize ();

Marcin Jękot

unread,
Jan 6, 2014, 5:34:20 PM1/6/14
to ns-3-...@googlegroups.com
Hi Tommaso,

It looks like I owe you one ;) Many thanks!

However, I still have some concerns regarding the solution you proposed: we already tried doing it using only UdpServer/UdpClient in order to have possibility to use GetReceived () function, however we had a problem with 'attaching' those Server/Client to a node. Do you maybe have or are aware with any example (possibly simple) implementation of those? All examples I found so far were using only Helpers.

Also - what do you mean by periodic function? Is there any documentation for this? I cannot find anything on official page.

As I said, any 'actual' implementation that would be worth reviewing would be most appreciated.

Thanks once again - you already give us some, hm, direction.

Best,
Marcin

Tommaso Pecorella

unread,
Jan 7, 2014, 1:02:25 AM1/7/14
to ns-3-...@googlegroups.com
Hi,

Helpers are a nice way to install "stuff" on a node. What's really installed is the "stuff". As an example:

ApplicationContainer

UdpTraceClientHelper::Install (NodeContainer c)

{

  ApplicationContainer apps;

  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)

    {

      Ptr<Node> node = *i;

      Ptr<UdpTraceClient> client = m_factory.Create<UdpTraceClient> ();

      node->AddApplication (client);

      apps.Add (client);

    }

  return apps;

}

This is an internal function, it's called "behind the hood" for you. However looking at it is good: what's installed in the node is a Ptr<UdpTraceClient>.

So, you're *using* an Helper, but what's installed (and runs) is the Application.

About periodic functions. You're right, there's no such a thing in ns-3, but there are a lot of functions called by themselves over and over (after a specific time).
Check this function:

void

UdpClient::Send (void)


Who's calling it ?
Nobody, except...

  m_sendEvent = Simulator::Schedule (Seconds (0.0), &UdpClient::Send, this);

  m_sendEvent = Simulator::Schedule (m_interval, &UdpClient::Send, this);


The first line is in void UdpClient::StartApplication (void), the second is in void UdpClient::Send (void).
Now, UdpClient::StartApplication is called at application start (again, under the hoods), the second is... calling itself after a specific time (m_interval).

That's a periodic function :)

Last but not least, note the Simulator::Cancel (m_sendEvent); in void UdpClient::StopApplication (void). It's stopping the periodic function when the application stops (otherwise, it will run forever).

Hope this helps,

T.

Peng Wang

unread,
Mar 21, 2014, 10:54:45 PM3/21/14
to ns-3-...@googlegroups.com
Your answer is really helpful. It also gives me a direction. Thanks!

Nusrat Fatema

unread,
Apr 1, 2014, 9:08:40 AM4/1/14
to ns-3-...@googlegroups.com
Hello,

I am doing my MSc thesis on "Jamming Attacks on Bluetooth developed in NS3." I am new with NS-3 simulator. Instead of Wifi module I want to use Bluetooth module. But there is no Bluetooth module available. How do I port from NS-2? I also need help to build up an energy model for the effective Bluetooth jammer. Is it possible to share your thoughts? Thanks in advance.

--

Nusrat.




On Monday, January 6, 2014 10:40:01 PM UTC+1, Marcin Jękot wrote:

Nusrat Fatema

unread,
Apr 1, 2014, 9:09:19 AM4/1/14
to ns-3-...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages