Create an event and have it fire when the processingperiod is over,
like so:
EventId ProcessingCompleteEvent;
ProcessingCompleteEvent = Simulator::Schedule(Seconds(processtime),
&Myapplication::SendResponse, this);
(Assuming that your application is running as an instantiated object).
You naturally need a Myapplication::SendResponse() method somewhere.
--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.
Can't you simply set a
bool serverbusy = true;
when starting processing,
setting it back to false after process is done, and if additional
requests come in just do a if (serverbusy) return; // Exit without
doing anything
If you just want to consume real cycles on a real machine, you can do so in a for-loop.
Ptr<RealtimeSimulatorImpl> impl = DynamicCast<RealtimeSimulatorImpl> (Simulator::GetImplementation ());
for (;;)
{
if (impl->RealtimeNow () > tEnd)
{
Break;
}
}
This is easy. The effect of doing something like that is a little harder to understand, and it’s hard to know exactly unless you get more specific about how your code is put together. It probably won’t do what you want at all.
If you are using the realtime simulator only (no emulated or tap devices), then the for-loop has the effect of making the system appear slow for a short time. If the simulator is running in the default mode, it will notice that the simulation is beginning to lag realtime and will attempt to speed things up by delaying less between events. The simulation will proceed to catch up if it is not fully consuming the CPU and your for-loop will have little effect in the big picture..
If you have the realtime simulator running in hard real time mode and you delay for long enough, you may simply hit the hard limit and the realtime simulator will stop with a fatal error.
If you are using the realtime simulator with emulation or tap devices running, then there are multiple threads running in the system. While your server is looping the main simulator thread can still be swapped out by the OS and other threads can run. In this case, even though you think you are consuming “system” cycles, an emulated net device can receive packets. This is like a machine getting network interrupts and queuing packets even though the CPU is completely loaded. These packets will be scheduled by the devices to run at the current real time. Eventually, the server thread will stop spinning and the simulation will resume. The packets received during the server “busy wait” will execute as soon as possible following the server, but their execution time will be their reception and schedule time, which is a real time during the server wait. The simulator will notice it is behind and start speeding up and eventually compensate for your server busy wait.
If you think about it, the scenario you are presenting is no different than, as often happens, the ns-3 process being swapped out while your system does something else. The realtime simulator was designed to compensate for this. So when you see difficulties trying to notice a busy-wait loop in your server, it is evidence of the realtime simulator working as designed.
Another complication is that if you have scheduled events for some time in the future, their execution times will not be magically changed if you do a “busy-wait” in your server code. They will still run on time (assuming the scheduler can catch up).
As you may infer, ns-3 does not model the execution time of events – events are assumed to run instantaneously. When you start wanting to have the server event consume real time, you start fighting against the basic design of ns-3. You can use the realtime clock to find out how long your code is taking to execute and if you are careful, you can watch real time progress in your events and do realtime scheduling. This means it is possible to defeat all of the hoops the simulator jumps through to produce a best-effort version of realtime, but it is going to mean some work for you. You will also find that some models in the system make assumptions about time not progressing in events so if you start playing these games, be prepared for grief.
If you are using emulated and tap devices, you can to write code to set some flag when the server event is actually running in real time and queue inbound packets in emulated devices while this is happening. When your server is done it can schedule an event which schedules the packet handler. Of course, you are talking about realtime multithreaded programming here, it won’t be easy and you’ll end up hacking on the device code. Another way is to go into the devices and add some offset to the real time (i.e., schedule packet reception for some time in the future, not the current real time).
There are some simple things you can do, especially using the real time clock to profile your server code. If you want to do anything much more complicated than that, you may be in for a difficult time.
-- Craig
Michael
> <mailto:ns-3-users%2Bunsu...@googlegroups.com> .
--
You received this message because you are subscribed to a topic in the Google Groups "ns-3-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ns-3-users/ixUXoeAkLp0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+...@googlegroups.com.
Visit this group at http://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.