Skip to content

Base Station

Bases: ComponentManager, Agent

Class that represents a base station.

Source code in edge_sim_py/components/base_station.py
  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
class BaseStation(ComponentManager, Agent):
    """Class that represents a base station."""

    # Class attributes that allow this class to use helper methods from ComponentManager
    _instances = []
    _object_count = 0

    def __init__(self, obj_id: int = None) -> object:
        """Creates a BaseStation object.

        Args:
            obj_id (int, optional): Object identifier.

        Returns:
            object: Created BaseStation object.
        """
        # Adding the new object to the list of instances of its class
        self.__class__._instances.append(self)

        # Object's class instance ID
        self.__class__._object_count += 1
        if obj_id is None:
            obj_id = self.__class__._object_count
        self.id = obj_id

        # Base station coordinates
        self.coordinates = None

        # Base station wireless delay
        self.wireless_delay = None

        # Lists of users, network switch, and edge servers connected to the base station
        self.users = []
        self.network_switch = None
        self.edge_servers = []

        # Model-specific attributes (defined inside the model's "initialize()" method)
        self.model = None
        self.unique_id = None

    def _to_dict(self) -> dict:
        """Method that overrides the way the object is formatted to JSON."

        Returns:
            dict: JSON-friendly representation of the object as a dictionary.
        """
        dictionary = {
            "attributes": {
                "id": self.id,
                "coordinates": self.coordinates,
                "wireless_delay": self.wireless_delay,
            },
            "relationships": {
                "users": [{"class": type(user).__name__, "id": user.id} for user in self.users],
                "edge_servers": [
                    {"class": type(edge_server).__name__, "id": edge_server.id} for edge_server in self.edge_servers
                ],
                "network_switch": {"class": type(self.network_switch).__name__, "id": self.network_switch.id}
                if self.network_switch
                else None,
            },
        }
        return dictionary

    def collect(self) -> dict:
        """Method that collects a set of metrics for the object.

        Returns:
            metrics (dict): Object metrics.
        """
        metrics = {}
        return metrics

    def step(self):
        """Method that executes the events involving the object at each time step."""
        ...

    def _connect_to_network_switch(self, network_switch: object) -> object:
        """Creates a relationship between the base station and a given networkSwitch object.

        Args:
            network_switch (NetworkSwitch): networkSwitch object.

        Returns:
            object: Updated BaseStation object.
        """
        self.network_switch = network_switch
        network_switch.base_station = self

        network_switch.coordinates = self.coordinates

        return self

    def _connect_to_edge_server(self, edge_server: object) -> object:
        """Creates a relationship between the base station and a given EdgeServer object.

        Args:
            edge_server (EdgeServer): EdgeServer object.

        Returns:
            object: Updated BaseStation object.
        """
        self.edge_servers.append(edge_server)
        edge_server.base_station = self

        edge_server.coordinates = self.coordinates
        edge_server.network_switch = self.network_switch
        self.network_switch.edge_servers.append(edge_server)

        return self

__init__(obj_id=None)

Creates a BaseStation object.

Parameters:

Name Type Description Default
obj_id int

Object identifier.

None

Returns:

Name Type Description
object object

Created BaseStation object.

Source code in edge_sim_py/components/base_station.py
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
def __init__(self, obj_id: int = None) -> object:
    """Creates a BaseStation object.

    Args:
        obj_id (int, optional): Object identifier.

    Returns:
        object: Created BaseStation object.
    """
    # Adding the new object to the list of instances of its class
    self.__class__._instances.append(self)

    # Object's class instance ID
    self.__class__._object_count += 1
    if obj_id is None:
        obj_id = self.__class__._object_count
    self.id = obj_id

    # Base station coordinates
    self.coordinates = None

    # Base station wireless delay
    self.wireless_delay = None

    # Lists of users, network switch, and edge servers connected to the base station
    self.users = []
    self.network_switch = None
    self.edge_servers = []

    # Model-specific attributes (defined inside the model's "initialize()" method)
    self.model = None
    self.unique_id = None

collect()

Method that collects a set of metrics for the object.

Returns:

Name Type Description
metrics dict

Object metrics.

Source code in edge_sim_py/components/base_station.py
73
74
75
76
77
78
79
80
def collect(self) -> dict:
    """Method that collects a set of metrics for the object.

    Returns:
        metrics (dict): Object metrics.
    """
    metrics = {}
    return metrics

step()

Method that executes the events involving the object at each time step.

Source code in edge_sim_py/components/base_station.py
82
83
84
def step(self):
    """Method that executes the events involving the object at each time step."""
    ...