def gym_single_test(trace_path, load_ratio): g = gym.Gym("test_gym") g.reset(trace_path=trace_path, report_interval_ms=60, duration_time_ms=0) packet_record = PacketRecord() packet_record.reset() while True: packet_list, done = g.step(GROUND_TRUTH * load_ratio) if not done: for pkt in packet_list: packet_info = PacketInfo() packet_info.payload_type = pkt["payload_type"] packet_info.ssrc = pkt["ssrc"] packet_info.sequence_number = pkt["sequence_number"] packet_info.send_timestamp = pkt["send_time_ms"] packet_info.receive_timestamp = pkt["arrival_time_ms"] packet_info.padding_length = pkt["padding_length"] packet_info.header_length = pkt["header_length"] packet_info.payload_size = pkt["payload_size"] packet_info.bandwidth_prediction = GROUND_TRUTH * load_ratio packet_record.on_receive(packet_info) else: break # Check whole receiving rate at the end receiving_rate = packet_record.calculate_receiving_rate() check_result(receiving_rate, GROUND_TRUTH * min(1, load_ratio) * (1 - ERROR), GROUND_TRUTH * min(1, load_ratio * (1 + ERROR)), 'receiving_rate')
def test(): bwe_list = [] counter_list = [] counter = 0 # f = open('test.log','a+') estimator = Estimator() bwe = 300000 total_stats = [] trace_files = os.path.join(os.path.dirname(__file__), "traces", "*.json") for trace_file in glob.glob(trace_files): g = gym.Gym("test_gym") g.reset(trace_path=trace_file, report_interval_ms=60, duration_time_ms=0) while True: stats, done = g.step(bwe) # use the estimated bandwidth #todo: get bwe estimated by model for stat in stats: estimator.report_states(stat) bwe_list.append(bwe) counter_list.append(counter) counter += 1 bwe = estimator.get_estimated_bandwidth() # f.write('Current BWE: ' + str(bwe)) # f.write('\n') if not done: total_stats += stats else: break
def get_gym_stats(trace_path, duration_time_ms=3000, bandwidth_bps=1000): total_stats = [] g = gym.Gym() g.reset(trace_path=trace_path, duration_time_ms=duration_time_ms) while True: stats, done = g.step(bandwidth_bps) if not done: total_stats += stats else: return total_stats
def test_multiple_instances(): total_stats = [] g1 = gym.Gym() g2 = gym.Gym() g1.reset() g2.reset() while True: stats, done = g1.step(1000) if not done: total_stats += stats else: break while True: stats, done = g2.step(1000) if not done: total_stats += stats else: break assert (total_stats) for stats in total_stats: assert (isinstance(stats, dict))
def test_basic(): total_stats = [] g = gym.Gym("test_gym") g.reset() while True: stats, done = g.step(1000) if not done: total_stats += stats else: break assert (total_stats) for stats in total_stats: assert (isinstance(stats, dict))
def test_trace(): total_stats = [] trace_path = os.path.join(os.path.dirname(__file__), "data", "trace_example.json") g = gym.Gym("test_gym") g.reset(trace_path=trace_path, report_interval_ms=60, duration_time_ms=0) while True: stats, done = g.step(1000) if not done: total_stats += stats else: break assert (total_stats) for stats in total_stats: assert (isinstance(stats, dict))
def test_gym_stability(): g = gym.Gym("test_gym") trace_path = os.path.join(os.path.dirname(__file__), "data", "trace_300k.json") gym_single_test(trace_path, 0.75) gym_single_test(trace_path, 1.25)