diff --git a/ns/packet/tcp_generator.py b/ns/packet/tcp_generator.py index 976df48..e4e6b1c 100644 --- a/ns/packet/tcp_generator.py +++ b/ns/packet/tcp_generator.py @@ -117,7 +117,7 @@ def run(self): self.env, timer_id=packet.packet_id, timeout_callback=self.timeout_callback, - timeout=self.rto, + rto=self.rto, ) if self.debug: @@ -151,8 +151,8 @@ def timeout_callback(self, packet_id=0): ) # starting a new timer for this segment and doubling the retransmission timeout - self.rto *= 2 - self.timers[packet_id].restart(self.rto) + revised_rto = self.timers[packet_id].rto * 2 + self.timers[packet_id].restart(revised_rto) def put(self, ack): """On receiving an acknowledgment packet.""" @@ -209,7 +209,7 @@ def put(self, ack): self.env, timer_id=packet.packet_id, timeout_callback=self.timeout_callback, - timeout=self.rto, + rto=self.rto, ) if self.debug: diff --git a/ns/utils/timer.py b/ns/utils/timer.py index 4beed7a..33416b6 100644 --- a/ns/utils/timer.py +++ b/ns/utils/timer.py @@ -21,12 +21,13 @@ class Timer: The timeout value. """ - def __init__(self, env, timer_id, timeout_callback, timeout): + def __init__(self, env, timer_id, timeout_callback, rto): self.env = env self.timer_id = timer_id self.timeout_callback = timeout_callback + self.rto = rto self.timer_started = self.env.now - self.timer_expiry = self.timer_started + timeout + self.timer_expiry = self.timer_started + rto self.stopped = False self.action = env.process(self.run()) @@ -46,11 +47,13 @@ def stop(self): self.stopped = True self.timer_expiry = self.env.now - def restart(self, timeout, start_time=0): - """Restarting the timer with a new timeout value.""" + def restart(self, revised_rto, start_time=0): + """Restarting the timer with a new rto value.""" + self.rto = revised_rto + if start_time == 0: self.timer_started = self.env.now else: self.timer_started = start_time - self.timer_expiry = self.timer_started + timeout + self.timer_expiry = self.timer_started + revised_rto