Skip to content

Commit

Permalink
Revised the implementation of RTO.
Browse files Browse the repository at this point in the history
  • Loading branch information
cying17 committed Feb 6, 2024
1 parent 04cb38e commit a7c58a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
8 changes: 4 additions & 4 deletions ns/packet/tcp_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 8 additions & 5 deletions ns/utils/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -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

0 comments on commit a7c58a6

Please sign in to comment.