Commit 3256179b authored by Simon Morlat's avatar Simon Morlat

improve network simulator

parent 3facc587
......@@ -68,13 +68,11 @@ static mblk_t *simulate_bandwidth_limit(RtpSession *session, mblk_t *input){
if (sim->last_check.tv_sec==0){
sim->last_check=current;
sim->bit_budget=sim->params.max_bandwidth;
sim->bit_budget=0;
}
/*update the budget */
elapsed=elapsed_us(&sim->last_check,&current);
sim->bit_budget+=(elapsed*(int64_t)sim->params.max_bandwidth)/1000000LL;
if (sim->bit_budget>=sim->params.max_bandwidth)
sim->bit_budget=sim->params.max_bandwidth;
sim->last_check=current;
/* queue the packet for sending*/
if (input){
......@@ -104,6 +102,10 @@ static mblk_t *simulate_bandwidth_limit(RtpSession *session, mblk_t *input){
sim->qsize-=bits;
}
}
if (output==NULL && input==NULL && sim->bit_budget>=0){
/* unused budget is lost...*/
sim->last_check.tv_sec=0;
}
return output;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment