def test_receiving_rate_kbps_single_packet(self):
     payload_sizes_bytes = [0.0, 500.0, 1200.0] # Empty or non-empty packet.
     for payload_size_bytes in payload_sizes_bytes:
         # id and send_time don't matter here.
         packet = Packet(None, None, payload_size_bytes)
         for i in range(10):
             packet.arrival_time_ms = i
             time_window_ms = random.uniform(100.0, 1000.0)
             self.assertEqual(receiving_rate_kbps([packet], time_window_ms),
                             8.0 * packet.payload_size_bytes / time_window_ms)
 def test_receiving_rate_kbps_single_packet(self):
     payload_sizes_bytes = [0.0, 500.0,
                            1200.0]  # Empty or non-empty packet.
     for payload_size_bytes in payload_sizes_bytes:
         # id and send_time don't matter here.
         packet = Packet(None, None, payload_size_bytes)
         for i in range(10):
             packet.arrival_time_ms = i
             time_window_ms = random.uniform(100.0, 1000.0)
             self.assertEqual(
                 receiving_rate_kbps([packet], time_window_ms),
                 8.0 * packet.payload_size_bytes / time_window_ms)
 def test_receiving_rate_regular_packets(self):
     for i in range(10):
         bitrate_kbps = random.uniform(150.0, 2500.0)
         packet_size_bytes = random.uniform(1.0, 8000.0)
         delay_ms = random.uniform(10.0, 300.0)
         packet_source = PacketSource(packet_size_bytes)
         packets = []
         for j in range(1000):
             packet = packet_source.create_packet(bitrate_kbps)
             packet.arrival_time_ms = packet.send_time_ms + delay_ms
             packets.append(packet)
         time_window_ms = random.uniform(0.0, 1.0) * packets[-1].arrival_time_ms
         self.assertNear(receiving_rate_kbps(packets, time_window_ms), bitrate_kbps, 0.001)
 def test_receiving_rate_regular_packets(self):
     for i in range(10):
         bitrate_kbps = random.uniform(150.0, 2500.0)
         packet_size_bytes = random.uniform(1.0, 8000.0)
         delay_ms = random.uniform(10.0, 300.0)
         packet_source = PacketSource(packet_size_bytes)
         packets = []
         for j in range(1000):
             packet = packet_source.create_packet(bitrate_kbps)
             packet.arrival_time_ms = packet.send_time_ms + delay_ms
             packets.append(packet)
         time_window_ms = random.uniform(0.0,
                                         1.0) * packets[-1].arrival_time_ms
         self.assertNear(receiving_rate_kbps(packets, time_window_ms),
                         bitrate_kbps, 0.001)
Esempio n. 5
0
 def receive_packet(self, packet):
     self.time_ms.append(packet.arrival_time_ms)
     self.packets.append(packet)
     # Use delay as a signal.
     # 1) Subtract Baseline.
     # 2) Apply Median filter.
     # 3) Apply Exponential Smoothing Filter.
     # 4) Non-linear Estimate queuing delay warping.
     delay_ms = packet.arrival_time_ms - packet.send_time_ms
     self.baseline_delay_ms = min(self.baseline_delay_ms, delay_ms)
     self.delay_signals_ms.append(delay_ms - self.baseline_delay_ms)
     self.median_filtered_delays_ms.append(self.__median_filter())
     self.exp_smoothed_delays_ms.append(self.__exp_smoothing_filter())
     self.est_queuing_delays_ms.append(self.__non_linear_warping())
     self.loss_ratios.append(loss_ratio(self.packets, NadaReceiver.LOSS_RATIO_TIME_WINDOW_MS))
     self.receiving_rates_kbps.append(receiving_rate_kbps(self.packets, NadaReceiver.RECEIVING_RATE_TIME_WINDOW_MS))
     self.congestion_signals_ms.append(self.est_queuing_delays_ms[-1] + NadaReceiver.LOSS_PENALTY_MS * self.loss_ratios[-1])
 def test_receiving_rate_kbps_no_packets(self):
     self.assertEqual(receiving_rate_kbps(None, 0.0), 0.0)
     self.assertEqual(receiving_rate_kbps(None, 100.0), 0.0)
     self.assertEqual(receiving_rate_kbps([], 0.0), 0.0)
     self.assertEqual(receiving_rate_kbps([], 100.0), 0.0)
 def test_receiving_rate_kbps_no_packets(self):
     self.assertEqual(receiving_rate_kbps(None, 0.0), 0.0)
     self.assertEqual(receiving_rate_kbps(None, 100.0), 0.0)
     self.assertEqual(receiving_rate_kbps([], 0.0), 0.0)
     self.assertEqual(receiving_rate_kbps([], 100.0), 0.0)