Skip to content

Commit

Permalink
Simplify calc_rtt and error out in 'animation' when the flow contains…
Browse files Browse the repository at this point in the history
… no SYN packets

Using 'animation' with a flow that has no SYN packets gives the
following backtrace:
Traceback (most recent call last):
  File "./captcp.py", line 5210, in <module>
    sys.exit(captcp.run())
  File "./captcp.py", line 5191, in run
    pcap_parser.run()
  File "./captcp.py", line 562, in run
    self.callback(dt, packet.data)
  File "./captcp.py", line 4360, in process_packet
    self.process_local_side(ts, packet, tpi)
  File "./captcp.py", line 4302, in process_local_side
    (td, len(packet) / 2, self.rtt_data["twh-delay"] /
self.acceleration))
KeyError: 'twh-delay'

Error out properly in such conditions.
Slightly simplify calc_rtt while we're at it

Fixes Issue #15 - #15
  • Loading branch information
mbaldessari authored and hgn committed Nov 13, 2013
1 parent 9e589e2 commit f08c7aa
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions captcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4284,14 +4284,15 @@ def parse_local_options(self):


def calc_rtt(self, ts, packet, tpi):
if tpi.is_syn_flag() and not tpi.is_ack_flag():
if not tpi.is_syn_flag():
return

if not tpi.is_ack_flag():
self.logger.debug("TWH - SYN received")
self.rtt_data["syn-received"] = dict()
self.rtt_data["syn-received"]["ts"] = ts
self.rtt_data["syn-received"]["seq"] = tpi.seq

if tpi.is_syn_flag() and tpi.is_ack_flag() and \
tpi.ack == self.rtt_data["syn-received"]["seq"] + 1:
elif tpi.is_ack_flag() and tpi.ack == self.rtt_data["syn-received"]["seq"] + 1:
self.rtt_data["twh-rtt"] = Utils.ts_tofloat(ts - \
self.rtt_data["syn-received"]["ts"]) * 1000.0
self.logger.debug("TWH - SYN/ACK received (%.3f ms later)" %
Expand All @@ -4305,6 +4306,10 @@ def calc_rtt(self, ts, packet, tpi):

def process_local_side(self, ts, packet, tpi):
""" we animate the packet send from us to the peer """
if not self.rtt_data.has_key("twh-delay"):
self.logger.error("The chosen flow does not contain SYN packets")
sys.exit(ExitCodes.EXIT_CMD_LINE)

td = Utils.ts_tofloat(ts - self.reference_time) * 1000.0 / self.acceleration

self.js_fd.write("\t//ts: %s\n" % (td))
Expand All @@ -4314,6 +4319,9 @@ def process_local_side(self, ts, packet, tpi):

def process_remote_side(self, ts, packet, tpi):
""" we animate the packet send from remote to us """
if not self.rtt_data.has_key("twh-delay"):
self.logger.error("The chosen flow does not contain SYN packets")
sys.exit(ExitCodes.EXIT_CMD_LINE)
td = Utils.ts_tofloat(ts - self.reference_time) * 1000.0 / self.acceleration

self.js_fd.write("\t//ts: %s\n" % (td))
Expand Down

0 comments on commit f08c7aa

Please sign in to comment.