trafpy.manager.src.schedulers package
Submodules
trafpy.manager.src.schedulers.agent module
- class trafpy.manager.src.schedulers.agent.Agent(Graph, RWA, slot_size, max_F, epsilon, alpha, gamma, agent_type='sarsa_learning')[source]
Bases:
SchedulerToolbox
- check_if_end_of_time_slot_decisions(action, chosen_flows)[source]
If one of the following is true, agent should stop making decisions this time slot and this method will return True:
1) The action chosen is the ‘null’ action, which is the agent’s way of explicitly stating that it doesn’t want to schedule anymore flows for this time slot
2) The action chosen is a flow that has already been chosen this time slot
3) The action chosen is invalid since, due to previously selected actions, there are no paths or channels (lightpaths) available
Args: - action: The action to be checked chosen by the agent - chosen_flows: A list of flows already chosen by the agent
trafpy.manager.src.schedulers.basrpt module
- class trafpy.manager.src.schedulers.basrpt.BASRPT(Graph, RWA, slot_size, V, packet_size=300, time_multiplexing=True, debug_mode=False, scheduler_name='basrpt')[source]
Bases:
SchedulerToolbox
- find_contending_flow(chosen_flow, chosen_flows)[source]
Goes through chosen flow possible path & channel combinations & compares to path-channel combinations in chosen flows. Saves all contentions that arise. When all possible contentions have been checked, finds the ‘most contentious’ (i.e. shortest flow completion time) in chosen_flows and returns this as the contending flow (since other flows in contending_flows will have a higher cost than this most contentious flow and therefore if the chosen flow has a lower cost than the most contentious flow, it will also have a lower cost than all competing flows and therefore should replace all contending flows)
trafpy.manager.src.schedulers.first_fit module
trafpy.manager.src.schedulers.parametric_agent module
trafpy.manager.src.schedulers.random_agent module
trafpy.manager.src.schedulers.schedulers module
trafpy.manager.src.schedulers.schedulertoolbox module
- class trafpy.manager.src.schedulers.schedulertoolbox.SchedulerToolbox_v2(Graph, RWA, slot_size, packet_size=300, time_multiplexing=True, debug_mode=False)[source]
Bases:
object
- allocate_available_bandwidth(flow_info, resolution_strategy)[source]
Goes through each edge and allocates bandwidth available on that edge to requesting flows until either no bandwidth left to allocate or all requesting flows would be completed this time slot.
If flow_id_to_cost is not None, will allocate bandwidth to flows in order of cost (prioritising low cost flows first). If flow_id_to_cost is None, must specify a valid resolution_strategy (e.g. ‘random’, ‘fair_share’, etc.).
- Parameters
flow_id_to_cost (dict) – Dict mapping flow_id to corresponding flow cost.
resolution_strategy (str) – Which resolution strategy to use if flow_id_to_cost is None to allocate available bandwidht and resolve conflicts
Returns:
- check_connection_valid(flow, num_decimals=6)[source]
Returns False if setting up connection would result in -ve bandwidth on at least one link in network.
- collect_flow_info_dicts(path_channel_assignment_strategy='random', cost_function=None)[source]
Goes through network and collects useful dictionaries for making scheduling decisions.
- Parameters
path_channel_assignment_strategy (str) – If ‘random’, allocates flows a randomly chosen path and channel. If None, does not allocate any path or channel; just uses whichever path and channel has already been assigned (if nothing assigned, will get an error later). If ‘fair_share_num_flows’, distributes number of flows across channels and paths equally. If ‘fair_share_num_packets’, distributes number of flow packets across channels and paths equally.
cost_function (function) – If not None, uses cost_function to assign a cost to each flow and stores this in a dictionary. cost_function must take a single flow dictionary argument.
- Returns
Maps flow_id to corresponding flow dictionary. requested_edges (dict): Maps links (edges) in network being requested
to corresponding flow ids requesting them.
- edge_to_flow_ids (dict): Maps edge to the list of flow ids requesting
it.
flow_id_to_cost (dict): Maps flow_id to corresponding cost of flow.
- Return type
queued_flows (dict)
Takes a network and filters out any flow that is not ready to be scheduled yet i.e. has incomplete parent flow dependencies. Use this method to get network representation for ‘job-agnostic’ flow scheduling systems.
- find_flow_idx(flow, flows)[source]
Finds flow idx in a list of flows. Assumes the following flow features are unique and unchanged properties of each flow: - flow size - source - destination - time arrived - flow_id - job_id
Args: - flow (dict): flow dictionary - flows (list of dicts) list of flows in which to find flow idx
- get_channel_bandwidth(edge, channel)[source]
Gets current channel bandwidth left on a given edge in the network.
- get_edge_to_bandwidth_dict(requested_edges, max_bw=True)[source]
Goes through network and maps each edge to its maximum bandwidth.
If max_bw, gets maximum possible bandwidth on each edge. If not max_bw, gets available bandwidth on each edge ASSUMES ONE CHANNEL.
- get_lowest_edge_bandwidth(path, max_bw=True, channel=None)[source]
Goes through path edges and finds bandwidth of lowest bandwidth edge port.
If max_bw, will return maximum possible bandwith of lowest max bandwidth edge. If not, will return available bandwidth of lowest available bandwidth edge.
N.B. if not max_bw, MUST given channel (since checking bandwidth available on edge)
- get_path_edges(path)[source]
Takes a path and returns list of edges in the path
Args: - path (list): path in which you want to find all edges
Returns: - edges (list of lists): all edges contained within the path
- remove_flow_from_queue(flow_dict, network)[source]
Given flow dict and network that flow is in, will locate flow in network and remove from queue
- reset_channel_capacities_of_edges()[source]
Takes edges and resets their available capacities back to their maximum capacities.
- resolve_contentions_and_set_up_flow(flow, chosen_flows, flow_info, scheduling_info, cost_info, resolution_strategy)[source]
If contention found, will resolve contention using resolution strategy.
Cost resolution strategy -> choose flow with lowest cost. Random resolution strategy -> choose random flow.
- set_up_connection(flow, num_decimals=6)[source]
Sets up connection between src-dst node pair by removing capacity from all edges in path connecting them. Also updates graph’s global curr network capacity used property
Args: - flow (dict): flow dict containing flow info to set up
- take_down_connection(flow, num_decimals=6)[source]
Removes established connection by adding capacity back onto all edges in the path connecting the src-dst node pair. Also updates graph’s global curr network capacity used property
Args: - flow (dict): flow dict containing info of flow to take down
- update_network_state(observation, hide_child_dependency_flows=True, reset_channel_capacities=True)[source]
If hide_child_dependency_flows is True, will only update scheduler network to see flows that are ready to be scheduled i.e. all parent flow dependencies have been completed. This is used for ‘job-agnostic’ scheduling systems which, rather than considering the job that each flow is part of, only consider the flow.
If False, will just update network with all flows (even those that cannot yet be scheduled). This is used for ‘job- & network- aware’ scheduling systems.
trafpy.manager.src.schedulers.srpt module
- class trafpy.manager.src.schedulers.srpt.SRPT(Graph, RWA, slot_size, packet_size=300, time_multiplexing=True, debug_mode=False, scheduler_name='srpt')[source]
Bases:
SchedulerToolbox
- find_contending_flow(chosen_flow, chosen_flows)[source]
Goes through chosen flow possible path & channel combinations & compares to path-channel combinations in chosen flows. Saves all contentions that arise. When all possible contentions have been checked, finds the ‘most contentious’ (i.e. shortest flow completion time) in chosen_flows and returns this as the contending flow (since other flows in contending_flows will have a higher FCT than this most contentious flow and therefore if the chosen flow has a lower FCT than the most contentious flow, it will also have a lower FCT than all competing flows and therefore should replace all contending flows)