title: Simulate Multiple Virtual Timers with one Physical Timer
body: <p>I am trying to implement a Selective Repeat Protocol using C for an networking assignment but am stumped at how to simulate the timer for each individual packets. I only have access to a single timer and can only call the functions as described below.</p>
  
  <pre><code>/* start timer at A or B (int), increment in time*/
  extern void starttimer(int, double);       
  
  /* stop timer at A or B (int) */
  extern void stoptimer(int);             
  </code></pre>
  
  <p>Kurose and Ross mentioned in their networking textbook that </p>
  
  <blockquote>
    <p>A single hardware timer can be used to mimic the
    operation of multiple logical timers [Varghese 1997].</p>
  </blockquote>
  
  <p>And I found the following hint for a similar <a href="http://www.cs.rochester.edu/~kshen/csc257-fall2011/assignments/assignment3.html" rel="noreferrer">assignment</a></p>
  
  <blockquote>
    <p>You can simulate multiple virtual timers using a single physical timer. The basic idea is that you keep a chain of virtual timers ordered in their expiration time and the physical timer will go off at the first virtual timer expiration. </p>
  </blockquote>
  
  <p>However, I do not have access to any time variables other than RTT as the emulator is on another layer of abstraction. How can I implement the timer for individual packets in this case?</p>