-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathannotated_packet.py
More file actions
69 lines (56 loc) · 2.49 KB
/
annotated_packet.py
File metadata and controls
69 lines (56 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import dpkt
from dpkt.tcp import *
from tcp_util import *
"""
The AnnotatedPacket data struct contains necessary information for our compression and analysis.
When a tcp_endpoint adds packets to its packet list, it will compute some features of
the Annotated Packets.
"""
class AnnotatedPacket(object):
def __init__(self, packet, timestamp_us, index):
# self.packet = 'eth': self.packet.ip.tcp.sport = source port number
# index = the (index)-th input packet (Ethernet packet)
self.packet = packet
self.timestamp_us = timestamp_us
self.index = index
self.ack_delay_ms = -1
self.ack_index = -1
# rtx = the retransmission packet of self.packet
# previous_tx = self.packet is the retransmission of the previous_tx
self.rtx = None
self.rtx_is_spurious = False
self.previous_tx = None
self.previous_packet = None
# data_len: used to compute the goodput
self.data_len = tcp_data_len(self)
# self.seq = the absolute seq number of the packet (32 bits long)
self.seq = packet.ip.tcp.seq
self.seq_end = add_offset(self.seq, self.data_len)
# Replace raw option buffer by a parsed version
self.packet.ip.tcp.opts = parse_opts(self.packet.ip.tcp.opts)
self.ack = packet.ip.tcp.ack
# Relative sequence numbers are set by the TCP endpoint
# (requires knowledge about the initial sequence numbers)
self.seq_relative = -1
self.ack_relative = -1
# Bytes that were received successfully by the other endpoint
# (packets transmitted before this one)
self.bytes_passed = -1
def is_lost(self):
return self.rtx is not None and not self.rtx_is_spurious
def update_length_and_offset(self, new_length, offset):
"""Update the sequence numbers and payload length (used when splitting
a jumbo packet into smaller on-the-wire frames"""
self.data_len = new_length
tcp_set_data_len(self, new_length)
assert self.data_len == tcp_data_len(self)
tcp = self.packet.ip.tcp
self.seq = tcp.seq = add_offset(self.seq, offset)
self.seq_end = add_offset(self.seq, self.data_len)
# trim buffer storing actual payload
if len(tcp.data) <= offset:
tcp.data = []
else:
buf_start = offset
buf_end = min(len(tcp.data), offset + new_length)
tcp.data = tcp.data[buf_start:buf_end]