-
Notifications
You must be signed in to change notification settings - Fork 5
/
double_flow.py
122 lines (95 loc) · 3.94 KB
/
double_flow.py
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
# @ModuleName : double_flow
# @Function :
# @Author : azson
# @Time : 2020/4/10 15:52
'''
from objects.emulator import SimpleEmulator
from utils import analyze_emulator, plot_cwnd, plot_rate
import os, sys, inspect, random
from config.constant import *
from objects.sender import Sender as WinSender
from objects.engine import Engine
from objects.link import Link
from player.examples.reno import Reno
# from player.examples.simple_bbr import BBR
from player.examples.match_trace_rate import MTR
from player.block_selection import Solution as BlockSelection
from objects.cc_base import CongestionControl
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0, parentdir)
class RenoSolution(Reno, BlockSelection):
pass
class NormalSolution(MTR, BlockSelection):
pass
# send block if exists
class DirectSendSolution(CongestionControl, BlockSelection):
pass
def create_2flow_emulator(solution, block_file=None, trace_file=None, **kwargs):
emulator = SimpleEmulator(
block_file=block_file,
trace_file=trace_file,
senders=[],
links=[],
**kwargs
)
emulator.trace_list = emulator.get_trace()
queue = int(random.uniform(*emulator.queue_range))
emulator.links = [Link(emulator.trace_list, queue), Link([], queue)]
solution_1 = solution
sender_1 = WinSender(emulator.links, 0, emulator.features, history_len=emulator.history_len, solution=solution_1)
sender_1.init_application(emulator.block_file, **kwargs)
solution_2 = NormalSolution()
solution_2.init_trace(emulator.trace_file)
sender_2 = WinSender(emulator.links, 0, emulator.features, history_len=emulator.history_len, solution=solution_2)
# sender_2.init_application(emulator.block_file, ENABLE_BLOCK_LOG=False)
emulator.senders = [sender_1, sender_2]
emulator.net = Engine(emulator.senders, emulator.links, **kwargs)
return emulator
def create_multi_service_emulator(solution_list, sender_block_file_list, trace_file, **kwargs):
# create normal emulator
emulator = SimpleEmulator(
block_file=sender_block_file_list[0],
trace_file=trace_file,
senders=[],
links=[],
**kwargs
)
# reset links of emulator
emulator.trace_list = emulator.get_trace()
queue = int(random.uniform(*emulator.queue_range))
emulator.links = [Link(emulator.trace_list, queue), Link([], queue, delay=emulator.trace_list[0][3])]
# reset senders of emulator
senders = []
for idx, solution in enumerate(solution_list):
solution = solution if solution else DirectSendSolution()
sender = WinSender(emulator.links, 0, emulator.features, history_len=emulator.history_len, solution=solution)
ENABLE_BLOCK_LOG = True if idx == 0 else False
sender.init_application(sender_block_file_list[idx], ENABLE_BLOCK_LOG=ENABLE_BLOCK_LOG, **kwargs)
senders.append(sender)
emulator.senders = senders
# reset net of emulator
emulator.net = Engine(emulator.senders, emulator.links, **kwargs)
return emulator
def create_mmgc_compete_emulator(solution, first_block_file, second_block_file, trace_file=None, **kwargs):
emulator = create_multi_service_emulator(
solution_list=[solution, None],
sender_block_file_list=[first_block_file, second_block_file],
trace_file=trace_file,
**kwargs
)
return emulator
def create_emulator(solution, block_file, trace_file, second_block_file=None, **kwargs):
if second_block_file:
return create_mmgc_compete_emulator(solution, first_block_file=block_file, \
second_block_file=second_block_file, trace_file=trace_file, **kwargs)
else:
return SimpleEmulator(
block_file=block_file,
trace_file=trace_file,
solution=solution,
**kwargs
)