def new_timestamp_group(self, timestamp: int, arrival_time: int) -> bool: if self.belongs_to_burst(timestamp, arrival_time): return False else: timestamp_delta = uint32_add(timestamp, -self.current_group.first_timestamp) return timestamp_delta > self.group_length
def compute_deltas(self, timestamp: int, arrival_time: int, packet_size: int) -> Optional[InterArrivalDelta]: deltas = None if self.current_group is None: self.current_group = TimestampGroup(timestamp) elif self.packet_out_of_order(timestamp): return deltas elif self.new_timestamp_group(timestamp, arrival_time): if self.previous_group is not None: deltas = InterArrivalDelta( timestamp=uint32_add( self.current_group.last_timestamp, -self.previous_group.last_timestamp, ), arrival_time=(self.current_group.arrival_time - self.previous_group.arrival_time), size=self.current_group.size - self.previous_group.size, ) # shift groups self.previous_group = self.current_group self.current_group = TimestampGroup(timestamp=timestamp) elif uint32_gt(timestamp, self.current_group.last_timestamp): self.current_group.last_timestamp = timestamp self.current_group.size += packet_size self.current_group.arrival_time = arrival_time return deltas
def belongs_to_burst(self, timestamp: int, arrival_time: int) -> bool: timestamp_delta = uint32_add(timestamp, -self.current_group.last_timestamp) timestamp_delta_ms = round(self.timestamp_to_ms * timestamp_delta) arrival_time_delta = arrival_time - self.current_group.arrival_time return timestamp_delta_ms == 0 or ( (arrival_time_delta - timestamp_delta_ms) < 0 and arrival_time_delta <= BURST_DELTA_THRESHOLD_MS)
def test_uint32_add(self): self.assertEqual(uint32_add(0, 1), 1) self.assertEqual(uint32_add(1, 1), 2) self.assertEqual(uint32_add(1, 2), 3) self.assertEqual(uint32_add(4294967294, 1), 4294967295) self.assertEqual(uint32_add(4294967295, 1), 0) self.assertEqual(uint32_add(4294967295, 3), 2)
def packet_out_of_order(self, timestamp: int) -> bool: timestamp_delta = uint32_add(timestamp, -self.current_group.first_timestamp) return timestamp_delta >= 0x80000000