12.07.2015 Views

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

* outst<strong>and</strong>ing, cancel it.*/void TcpAgent::newtimer(Packet* pkt){hdr_tcp *tcph = (hdr_tcp*)pkt->access(off_tcp_);if (t_seqno_ > tcph->seqno())set_rtx_timer();else if (rtx_timer_.st<strong>at</strong>us() == TIMER_PENDING)rtx_timer_.cancel();}In the above code, the set_rtx_timer() method reschedules the retra<strong>ns</strong>mission timer by calling rtx_timer_.resched().Note th<strong>at</strong> if it is unclear whether or not the timer is already running, calling resched() elimin<strong>at</strong>es the need to explicitly cancelthe timer. In the second function, examples are given of the use of the st<strong>at</strong>us() <strong>and</strong> cancel(void) methods.Finally, the expire(void) method for class RtxTimer must be defined. In this case, expire(void) calls the timeout(void)method for TcpAgent. This is possible because timeout() is a public member function; if it were not, then RtxTimerwould have had to have been declared a friend class of TcpAgent.void TcpAgent::timeout(int tno){/* retra<strong>ns</strong>mit timer */if (tno == TCP_TIMER_RTX) {if (highest_ack_ == maxseq_ && !slow_start_restart_) {/** TCP option:* If no outst<strong>and</strong>ing d<strong>at</strong>a, then don’t do anything.*/return;};recover_ = maxseq_;recover_cause_ = 2;closecwnd(0);reset_rtx_timer(0,1);send_much(0, TCP_REASON_TIMEOUT, maxburst_);} else {/** delayed-send timer, with r<strong>and</strong>om overhead* to avoid phase effects*/send_much(1, TCP_REASON_TIMEOUT, maxburst_);}}void RtxTimer::expire(Event *e) {a_->timeout(TCP_TIMER_RTX);}<strong>The</strong> various TCP agents contain additional examples of timers.114

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!