Skip to content

Equal Share

calculate_bandwidth_allocation(capacity, demands)

Calculates network shares using the simple notion of equal sharing, where the allocated bandwidth for each flow is equal to the available bandwidth divided by the number of active flows.

Parameters:

Name Type Description Default
capacity int

Network bandwidth to be shared.

required
demands list

List of demands (e.g.: list of demands of services that will be migrated).

required

Returns:

Name Type Description
list list

Network allocation scheme.

Source code in edge_sim_py/components/flow_scheduling/equal_share.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def calculate_bandwidth_allocation(capacity: int, demands: list) -> list:
    """Calculates network shares using the simple notion of equal sharing, where the allocated bandwidth
    for each flow is equal to the available bandwidth divided by the number of active flows.

    Args:
        capacity (int): Network bandwidth to be shared.
        demands (list): List of demands (e.g.: list of demands of services that will be migrated).

    Returns:
        list: Network allocation scheme.
    """
    # Giving a equal slice of bandwidth to each item in the demands list
    allocated_bandwidth = [capacity / len(demands)] * len(demands)

    return allocated_bandwidth

equal_share(topology, flows)

Manages the execution of a equal bandwidth share algorithm for network flows.

Parameters:

Name Type Description Default
topology object

Network topology object.

required
flows list

List of flows in the topology.

required
Source code in edge_sim_py/components/flow_scheduling/equal_share.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
def equal_share(topology: object, flows: list):
    """Manages the execution of a equal bandwidth share algorithm for network flows.

    Args:
        topology (object): Network topology object.
        flows (list): List of flows in the topology.
    """
    # Gathering the links of used by flows that either started or finished or that have more bandwidth than needed
    links_to_recalculate_bandwidth = []
    for flow in flows:
        flow_just_started = len([bw for bw in flow.bandwidth.values() if bw == None]) > 0
        flow_just_ended = flow.data_to_transfer == 0

        if flow_just_started or flow_just_ended:
            for i in range(0, len(flow.path) - 1):
                # Gathering link nodes
                link = (flow.path[i], flow.path[i + 1])

                # Checking if the link is not already included in "links_to_recalculate_bandwidth"
                if link not in links_to_recalculate_bandwidth:
                    links_to_recalculate_bandwidth.append(link)

    # Calculating the bandwidth shares for the active flows
    for link_nodes in links_to_recalculate_bandwidth:
        link = topology[link_nodes[0]][link_nodes[1]]

        # Recalculating bandwidth shares for the flows as some of them have changed
        flow_demands = [f.data_to_transfer for f in link["active_flows"]]
        if sum(flow_demands) > 0:
            bw_shares = calculate_bandwidth_allocation(capacity=link["bandwidth"], demands=flow_demands)

            for index, affected_flow in enumerate(link["active_flows"]):
                affected_flow.bandwidth[link["id"]] = bw_shares[index]