Exemplo n.º 1
0
    def _set_gym_matrices(self):

        # set the action space
        num_actions = self.topo.get_num_hosts()
        min_bw = 10000.0 / float(self.topo.conf["max_capacity"])
        action_min = np.empty(num_actions)
        action_min.fill(min_bw)
        action_max = np.empty(num_actions)
        action_max.fill(1.0)
        self.action_space = spaces.Box(low=action_min,
                                       high=action_max,
                                       dtype=np.float32)
        # Initialize the action arrays shared with the control manager
        # Qdisc do not go beyond uint32 rate limit which is about 4Gbps
        tx_rate = RawArray(ctypes.c_uint32, num_actions)
        self.tx_rate = dc_utils.shmem_to_nparray(tx_rate, np.float32)
        active_rate = RawArray(ctypes.c_uint32, num_actions)
        self.active_rate = dc_utils.shmem_to_nparray(active_rate, np.float32)
        log.info("%s Setting action space", (self.short_id))
        log.info("from %s", action_min)
        log.info("to %s", action_max)

        # set the observation space
        num_ports = self.topo.get_num_sw_ports()
        num_features = len(self.conf["state_model"])
        if self.conf["collect_flows"]:
            num_features += num_actions * 2
        obs_min = np.empty(num_ports * num_features + num_actions)
        obs_min.fill(-np.inf)
        obs_max = np.empty(num_ports * num_features + num_actions)
        obs_max.fill(np.inf)
        self.observation_space = spaces.Box(low=obs_min,
                                            high=obs_max,
                                            dtype=np.float64)
Exemplo n.º 2
0
 def _init_stats_matrices(self, num_ports, num_hosts):
     # Set up the shared stats matrix
     stats_arr_len = num_ports * len(self.stats_dict)
     mp_stats = RawArray(c_ulong, stats_arr_len)
     np_stats = dc_utils.shmem_to_nparray(mp_stats, np.float64)
     self.stats = np_stats.reshape((len(self.stats_dict), num_ports))
     # Set up the shared flow matrix
     if (self.collect_flows):
         flow_arr_len = num_ports * num_hosts * 2
         mp_flows = RawArray(c_ubyte, flow_arr_len)
         np_flows = dc_utils.shmem_to_nparray(mp_flows, np.uint8)
         self.flow_stats = np_flows.reshape((num_ports, 2, num_hosts))
     # Save the initialized stats matrix to compute deltas
     self.prev_stats = self.stats.copy()
     self.deltas = np.zeros(shape=(len(self.stats_dict), num_ports))
Exemplo n.º 3
0
def init_rate_control(ctrl_iface, rate):
    # Initialize the action array shared with the control manager
    tx_rate = RawArray(ctypes.c_uint32, 1)
    tx_rate = dc_utils.shmem_to_nparray(tx_rate, np.float32)
    tx_rate.fill(rate)
    bw_proc = BandwidthController({"test": ctrl_iface}, tx_rate, tx_rate, rate)
    bw_proc.start()
    return tx_rate, bw_proc
Exemplo n.º 4
0
 def _set_gym_spaces(self, conf):
     # set configuration for the gym environment
     num_ports = self.topo.get_num_sw_ports()
     num_actions = self.topo.get_num_hosts()
     num_features = len(self.conf["state_model"])
     10e6 / self.topo.conf["max_capacity"]
     action_min = 10000.0 / float(self.topo.conf["max_capacity"])
     action_max = 1.0
     if self.conf["collect_flows"]:
         num_features += num_actions * 2
     self.action_space = spaces.Box(low=action_min,
                                    high=action_max,
                                    dtype=np.float64,
                                    shape=(num_actions, ))
     self.observation_space = spaces.Box(low=-np.inf,
                                         high=np.inf,
                                         dtype=np.float64,
                                         shape=(num_ports * num_features, ))
     log.info("Setting action space from %f to %f" %
              (action_min, action_max))
     tx_rate = Array(c_ulong, num_actions)
     self.tx_rate = shmem_to_nparray(tx_rate, np.int64)