Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revised the implementation of RTO. #29

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading