def __init__(self, history_len=10, features="sent latency inflation,latency ratio,send ratio", congestion_control_type="rl", log_dir=""): """Network environment used in simulation. congestion_control_type: rl is pcc-rl. cubic is TCPCubic. """ assert congestion_control_type in {"rl", "cubic"}, \ "Unrecognized congestion_control_type {}.".format( congestion_control_type) random.seed(42) self.log_dir = log_dir self.congestion_control_type = congestion_control_type if self.congestion_control_type == 'rl': self.use_cwnd = False elif self.congestion_control_type == 'cubic': self.use_cwnd = True self.viewer = None self.rand = None self.min_bw, self.max_bw = (100, 500) # packet per second self.min_lat, self.max_lat = (0.05, 0.5) # latency second self.min_queue, self.max_queue = (0, 8) self.min_loss, self.max_loss = (0.0, 0.05) self.history_len = history_len # print("History length: %d" % history_len) self.features = features.split(",") # print("Features: %s" % str(self.features)) self.links = None self.senders = None self.create_new_links_and_senders() self.net = Network(self.senders, self.links) self.run_dur = None self.run_period = 0.1 self.steps_taken = 0 self.max_steps = MAX_STEPS self.debug_thpt_changes = False self.last_thpt = None self.last_rate = None if self.use_cwnd: self.action_space = spaces.Box(np.array([-1e12, -1e12]), np.array([1e12, 1e12]), dtype=np.float32) else: self.action_space = spaces.Box(np.array([-1e12]), np.array([1e12]), dtype=np.float32) self.observation_space = None use_only_scale_free = True single_obs_min_vec = sender_obs.get_min_obs_vector(self.features) single_obs_max_vec = sender_obs.get_max_obs_vector(self.features) self.observation_space = spaces.Box(np.tile(single_obs_min_vec, self.history_len), np.tile(single_obs_max_vec, self.history_len), dtype=np.float32) self.reward_sum = 0.0 self.reward_ewma = 0.0 self.event_record = {"Events":[]} self.episodes_run = -1 print('event_id,event_type,next_hop,cur_latency,event_time,next_hop,dropped,event_q_length,send_rate,duration')
def __init__(self, history_len=arg_or_default("--history-len", default=10), features=arg_or_default("--input-features", default="sent latency inflation," + "latency ratio," + "send ratio")): self.viewer = None self.rand = None self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.setblocking(1) self.sock.bind(("localhost", 9787)) self.conn = None self.conn_addr = None self.features = features.split(",") self.history_len = history_len self.history = sender_obs.SenderHistory(history_len, self.features, 0) self.rate = STARTING_RATE single_obs_min_vec = sender_obs.get_min_obs_vector(self.features) single_obs_max_vec = sender_obs.get_max_obs_vector(self.features) self.observation_space = spaces.Box(np.tile(single_obs_min_vec, self.history_len), np.tile(single_obs_max_vec, self.history_len), dtype=np.float32) self.action_space = spaces.Box(np.array([-1e12]), np.array([1e12]), dtype=np.float32) self.steps_taken = 0 self.reward_sum = 0.0 self.reward_ewma = 0.0
def __init__(self, history_len=arg_or_default("--history-len", default=10), features=arg_or_default("--input-features", default="sent latency inflation," + "latency ratio," + "send ratio")): self.viewer = None self.rand = None self.min_bw, self.max_bw = (100, 500) # bandwidth self.min_lat, self.max_lat = (0.05, 0.5) # latency self.min_queue, self.max_queue = (0, 8) self.min_loss, self.max_loss = (0.0, 0.05) self.history_len = history_len print("History length: %d" % history_len) self.features = features.split(",") print("Features: %s" % str(self.features)) self.links = None self.senders = None self.create_new_links_and_senders() self.net = Network(self.senders, self.links) self.run_dur = None self.run_period = 0.1 self.steps_taken = 0 self.max_steps = MAX_STEPS self.debug_thpt_changes = False self.last_thpt = None self.last_rate = None # define action space if USE_CWND: self.action_space = spaces.Box(np.array([-1e12, -1e12]), np.array([1e12, 1e12]), dtype=np.float32) else: self.action_space = spaces.Box(np.array([-1e12]), np.array([1e12]), dtype=np.float32) # define observation space use_only_scale_free = True single_obs_min_vec = sender_obs.get_min_obs_vector(self.features) single_obs_max_vec = sender_obs.get_max_obs_vector(self.features) self.observation_space = spaces.Box(np.tile(single_obs_min_vec, self.history_len), np.tile(single_obs_max_vec, self.history_len), dtype=np.float32) self.reward_sum = 0.0 self.reward_ewma = 0.0 self.event_record = {"Events": []} self.episodes_run = -1
def __init__(self, env_config=None): print("Simulator for data center networks") self.viewer = None self.rand = None # 10G to 50G self.min_bw, self.max_bw = (MIN_RATE, MAX_RATE) # 100ns to 500ns self.min_lat, self.max_lat = (1e-7, 5e-7) # shallow buffer self.min_queue, self.max_queue = (0, 3) # ultra-low loss self.min_loss, self.max_loss = (0.0, 0.0005) self.history_len = env_config['history_len'] print("History length: %d" % self.history_len) self.features = env_config['features'].split(",") print("Features: %s" % str(self.features)) self.links = None self.senders = None self.create_new_links_and_senders() self.net = Network(self.senders, self.links) self.run_dur = None self.run_period = 0.1 self.steps_taken = 0 self.max_steps = MAX_STEPS self.debug_thpt_changes = False self.last_thpt = None self.last_rate = None if USE_CWND: self.action_space = spaces.Box(np.array([-1e12, -1e12]), np.array([1e12, 1e12]), dtype=np.float32) else: self.action_space = spaces.Box(np.array([-1e12]), np.array([1e12]), dtype=np.float32) self.observation_space = None use_only_scale_free = True single_obs_min_vec = sender_obs.get_min_obs_vector(self.features) single_obs_max_vec = sender_obs.get_max_obs_vector(self.features) self.observation_space = spaces.Box(np.tile(single_obs_min_vec, self.history_len), np.tile(single_obs_max_vec, self.history_len), dtype=np.float32) self.reward_sum = 0.0 self.reward_ewma = 0.0 self.event_record = {"Events": []} self.episodes_run = -1
def __init__( self, trace_scheduler: Scheduler, history_len: int = 10, # features="sent latency inflation,latency ratio,send ratio", features: List[str] = [ "sent latency inflation", "latency ratio", "recv ratio" ], record_pkt_log: bool = False): """Network environment used in simulation.""" self.record_pkt_log = record_pkt_log self.trace_scheduler = trace_scheduler self.current_trace = self.trace_scheduler.get_trace() self.history_len = history_len self.features = features # construct sender and network self.links = [Link(self.current_trace), Link(self.current_trace)] self.senders = [ AuroraSender( 10 * BYTES_PER_PACKET / (self.current_trace.get_delay(0) * 2 / 1000), self.features, self.history_len, 0, 0, self.current_trace) ] self.net = Network(self.senders, self.links, self.record_pkt_log) self.run_dur = 0.01 self.steps_taken = 0 self.action_space = spaces.Box(np.array([-1e12]), np.array([1e12]), dtype=np.float32) single_obs_min_vec = sender_obs.get_min_obs_vector(self.features) single_obs_max_vec = sender_obs.get_max_obs_vector(self.features) self.observation_space = spaces.Box(np.tile(single_obs_min_vec, self.history_len), np.tile(single_obs_max_vec, self.history_len), dtype=np.float32) self.reward_sum = 0.0 self.reward_ewma = 0.0 self.episodes_run = -1
def __init__( self, traces, history_len=10, # features="sent latency inflation,latency ratio,send ratio", features="sent latency inflation,latency ratio,recv ratio", train_flag=False, delta_scale=1.0, config_file=None, record_pkt_log: bool = False): """Network environment used in simulation. congestion_control_type: aurora is pcc-rl. cubic is TCPCubic. """ self.record_pkt_log = record_pkt_log self.config_file = config_file self.delta_scale = delta_scale self.traces = traces self.difficulty_trace_cache = {0: [], 1: [], 2: [], 3: [], 4: []} # self.baseline = BBR_old(False) self.baseline = Cubic(False) self.curr_diff = 0 if self.config_file is None: self.current_trace = np.random.choice(self.traces) else: self.insert_to_difficulty_cache(traces) self.current_trace = self.sample_trace(self.curr_diff) self.train_flag = train_flag self.use_cwnd = False self.history_len = history_len # print("History length: %d" % history_len) self.features = features.split(",") # print("Features: %s" % str(self.features)) self.links = None self.senders = None self.create_new_links_and_senders() self.net = Network(self.senders, self.links, self) self.run_dur = None self.run_period = 0.1 self.steps_taken = 0 self.debug_thpt_changes = False self.last_thpt = None self.last_rate = None if self.use_cwnd: self.action_space = spaces.Box(np.array([-1e12, -1e12]), np.array([1e12, 1e12]), dtype=np.float32) else: self.action_space = spaces.Box(np.array([-1e12]), np.array([1e12]), dtype=np.float32) self.observation_space = None # use_only_scale_free = True single_obs_min_vec = sender_obs.get_min_obs_vector(self.features) single_obs_max_vec = sender_obs.get_max_obs_vector(self.features) self.observation_space = spaces.Box(np.tile(single_obs_min_vec, self.history_len), np.tile(single_obs_max_vec, self.history_len), dtype=np.float32) # single_obs_min_vec = np.array([0, 0, -1e12, 0, 0, 0, 0]) # single_obs_max_vec = np.array([1e12, 1e12, 1e12, 1, 1e12, 1e12, 1e12]) # self.observation_space = spaces.Box(single_obs_min_vec, # single_obs_max_vec, # dtype=np.float32) self.reward_sum = 0.0 self.reward_ewma = 0.0 self.episodes_run = -1
def __init__(self, traces, history_len=10, # features="sent latency inflation,latency ratio,send ratio", features="sent latency inflation,latency ratio,recv ratio", train_flag=False, delta_scale=1.0, config_file=None, record_pkt_log: bool = False, real_trace_prob: float = 0): """Network environment used in simulation. congestion_control_type: aurora is pcc-rl. cubic is TCPCubic. """ self.real_trace_prob = real_trace_prob self.record_pkt_log = record_pkt_log self.config_file = config_file self.delta_scale = delta_scale self.traces = traces self.train_flag = train_flag if self.config_file: self.current_trace = generate_traces(self.config_file, 1, 30)[0] elif self.traces: self.current_trace = np.random.choice(self.traces) else: raise ValueError if self.train_flag and self.traces: self.real_trace_configs = [] for trace in self.traces: self.real_trace_configs.append(trace.real_trace_configs(True)) self.real_trace_configs = np.array(self.real_trace_configs).reshape(-1, 4) else: self.real_trace_configs = None self.use_cwnd = False self.history_len = history_len # print("History length: %d" % history_len) self.features = features.split(",") # print("Features: %s" % str(self.features)) self.links = None self.senders = None self.create_new_links_and_senders() self.net = Network(self.senders, self.links, self) self.run_dur = None self.run_period = 0.1 self.steps_taken = 0 self.debug_thpt_changes = False self.last_thpt = None self.last_rate = None if self.use_cwnd: self.action_space = spaces.Box( np.array([-1e12, -1e12]), np.array([1e12, 1e12]), dtype=np.float32) else: self.action_space = spaces.Box( np.array([-1e12]), np.array([1e12]), dtype=np.float32) self.observation_space = None # use_only_scale_free = True single_obs_min_vec = sender_obs.get_min_obs_vector(self.features) single_obs_max_vec = sender_obs.get_max_obs_vector(self.features) self.observation_space = spaces.Box(np.tile(single_obs_min_vec, self.history_len), np.tile(single_obs_max_vec, self.history_len), dtype=np.float32) self.reward_sum = 0.0 self.reward_ewma = 0.0 self.episodes_run = -1