OnOff appliccation interval

178 views
Skip to first unread message

Jack Higgins

unread,
Jan 18, 2017, 4:59:42 AM1/18/17
to ns-3-users

Dear all,

I have a simple question, ... but even after reading some stuff about the OnOffApplication I am still I little bit confused

Is it possible to on off an OnOffApplication every x number  seconds?

For example , I want to generate packets between seconds (on state)1-2 secs , then 11-12 secs , then 21-22 secs and so on (On state during 1 second every 10 seconds (off State))

   //On off application on multiple nodes

   Ipv4Address sinkAddress = mobileNode->GetObject<Ipv4>()->GetAddress(1,0).GetLocal();
   uint16_t onoffPort = 9;
   OnOffHelper onoff1 ("ns3::UdpSocketFactory", InetSocketAddress (sinkAddress, onoffPort));
   onoff1.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"));
   onoff1.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=10.0]"));
   onoff1.SetAttribute ("PacketSize", UintegerValue (1024)); //size in bytes
   onoff1.SetAttribute ("DataRate", StringValue (std::to_string(10000))); //bit/sec
  
   for(int i=0; i<=clientNodes.GetN()-1;  i++)
      {
    ApplicationContainer apps1;
    apps1.Add(onoff1.Install (NodeList::GetNode (i)));
    apps1.Start (Seconds (1));
    apps1.Stop (Seconds (40));


    
      }


Assuming there are 100  nodes the previous  code should generate 100 packets every 10 seconds ( 1 packet in each node every 10 seconds).
I think that the only valid values for ns3::ConstantRandomVariable[Constant=xx]are only 1.0 or 0.

Is it possible to use OnOffApplication to do what I described? 

Regards,

Jack


Konstantinos

unread,
Jan 18, 2017, 5:39:11 AM1/18/17
to ns-3-users, Peter Barnes
Hi Jack,

It is possible to set values other than 0 and 1 to meet your requirements.

Also, I think that there is a slight error in the documentation (hence Peter is CC'ed). It is stated that " When an application is started, the first packet transmission occurs after a delay equal to (packet size/bit rate). " 
The errors is that apart from this delay, the actual transmission will start after one OFF duration. 

OnOffApplication::ScheduleStartEvent 

254  Time offInterval = Seconds (m_offTime->GetValue ());
255  NS_LOG_LOGIC ("start at " << offInterval);


The second comment in your code is about how you specify the DataRate

   onoff1.SetAttribute ("PacketSize", UintegerValue (1024)); //size in bytes
   onoff1
.SetAttribute ("DataRate", StringValue (std::to_string(10000))); //bit/sec

You have a data rate of 10000 bits/sec with a packet size 1024 bytes = 8192bits. 
So you will have 1.22 packets per second. The remaining 0.22 packet is 'accumulated' and you may have 2 packets every 5 intervals. 
You can specify the data rate with Kbps or similar (see the API https://www.nsnam.org/docs/doxygen/classns3_1_1_data_rate.html)
For example you can simply put StringValue ("1KiB/s") will give you 8192 b/s, hence exactly 1 packet/sec

Finally, where you install the applications seems problematic and potentially buggy.
You have 

 apps1.Add(onoff1.Install (NodeList::GetNode (i)));

But the loop is for(int i=0; i<=clientNodes.GetN()-1;  i++)
So the index may not refer to the same node, particularly if you have multiple node containers.
Use the clientNodes to get the node to install.

Regards,
K

Jack Higgins

unread,
Jan 20, 2017, 1:28:13 AM1/20/17
to ns-3-users, pd...@mac.com

Thank you Konstantinos for your reply. 
Your comments did the trick . 
Indeed the problem was the fact that it starts with  an "offTime" + delay time.
I was aware of the  0.22 secs that would generate an extra packet every 5 intervals but it makes sense to make a more clear example to set the data rate to 1kbps,
also thanks for your advice on that and the possibly buggy way I was installing the nodes.

Now...... why is there an offTime at the start time, is this not just a documentation flaw but also a design flaw? is there any reason for this? (the delay might be a reason but beginning with an offTime??
This was indeed frustrating .
My example end up looking like this

   Ipv4Address sinkAddress = mobileNode->GetObject<Ipv4>()->GetAddress(1,0).GetLocal();
   uint16_t onoffPort = 9;
   OnOffHelper onoff1 ("ns3::UdpSocketFactory", InetSocketAddress (sinkAddress, onoffPort));
   onoff1.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"));
   onoff1.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=159.0]"));
   onoff1.SetAttribute ("PacketSize", UintegerValue (m_pktSize)); //m_pktSize
   onoff1.SetAttribute ("DataRate", StringValue ("1KiB/s" ));

  // double deviation = 0;
   for(int i=0; i<=clientNodes.GetN()-1;  i++)
      {
    ApplicationContainer apps1;
    apps1.Add(onoff1.Install (clientNodes.Get(i)));
    apps1.Start (Seconds (0));// apps1.Start (Seconds (0)+Seconds(deviation));
    apps1.Stop (Seconds (400)); //  apps1.Stop (Seconds (400)+Seconds(deviation));


   // deviation = deviation + 0.1;
      }

In the example above I start generating packets at  second 160 for 1 second every  and again every 160 seconds.... 
If anyone sees this I thinks is  soooo confusing on plain sight because I set the start time to 0 .....start time means.... start  after all it should not mean  "start 160 seconds later".
Additionally, you have to be aware of the delay time to set the on off times according to this. .......You get the point... is not very nice to configure.

But enough of my rant..... I'm just very grateful for your reply Konstantinos!.


Konstantinos

unread,
Jan 20, 2017, 3:28:32 AM1/20/17
to ns-3-users
Hi Jack,

For such 'simple' application that you only need to send a single packet every XX seconds, why don't you use UdpClient?
It is less complex in the configuration; no data-rate to calculate, simply select the interval and a single packet will be generated.
Further there is not 'off' time to wait at the start. 

Jack Higgins

unread,
Jan 22, 2017, 11:56:46 PM1/22/17
to ns-3-users


Hi Konstantinos,

Of course, however the real example will not be that simple. This example was only to simplify the behavior of OnOff application. 
My real intended example have multiple nodes that will generate multiple packets  with interval of some seconds, with different configurations of dataRates.
The real question is, are  there any reasons behind having offTime + delay at the start of an onOffApplication?
Such approach, for example, makes impossible to send packets at second 1 every 10 seconds ( I would have to configure the start time at -9 seconds).
Therefore, OnOff application should never start with an "OffTime", I might be complaining here, but there might be a reason behind this design, that is why 
I was wondering why? That...or this is a mistake in the design.
Yes, I could always make another application......but seems to be an overkill to make another app that does exactly the same thing as onOff without the  "OffTime"
at the beginning of the sequence. For now, I can work around the problem now that you pointed it out. But maybe this should be changed in future releases...

Thank you for the support.
Reply all
Reply to author
Forward
0 new messages