I would like to schedule an event in a specific time, more precisely, I want to generate a poisson traffic. So I need to send a packet at specific time intervals that are generated from an exponential distribution. I have done some researches on the Internet and found that the setitimer
method can schedule an alarm signal after a certain time, but I don't know how to use it in my case.
Thanks for the advice. I followed what you have said. I still have a little query: in my code I need to schedule two independant events at the same time, typically, filling two queues simultaneously. This is what I did right now:
void Queue_class::SetPoissonTraficFirstQueue(void)
{ // add one packet to the queue
struct sigaction act ;
struct itimerval timer ;
act.sa_handler = this ;
sigempty_set(&act.sa_mask) ; // no signal is added to the sa_mask
act.sa_flags = 0 ;
sigaction(SIGALARM, &act,0) ;
timer.it_value.tv_usec = 0 ;
timer.it_value.tv_sec = exponential_variable() ; // generates a random exponential variable
timer.it_interval.tv_sec = 0 ;
timer.it_interval.tv_usec = 0 ;
setitimer(ITIMER_REAL, *timer, NULL) ;
}
And the same function for the other queue but with a different exponential random variable
In the main, I do what follows:
int main()
{
Queue_class queue ;
queue.SetPoissonTraficFirstQueue() ;
queue.SetPoissonTraficSecondQueue() ;
// do business
}
I have two question please:
1- Is it a good solution to call the function internally with the pointer "this" in sa_handler method?
2- In the main function, do the two processes occur simultaneously as I want: I mean are both queues filled at the same time?