Skip to content

Network Link

Bases: dict, ComponentManager, Agent

Class that represents a network link.

Source code in edge_sim_py/components/network_link.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
119
120
121
122
123
124
125
126
127
128
class NetworkLink(dict, ComponentManager, Agent):
    """Class that represents a network link."""

    # 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 NetworkLink object.

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

        Returns:
            object: Created NetworkLink 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

        # Reference to the network topology
        self["topology"] = None

        # List of network nodes that are connected by the link
        self["nodes"] = []

        # Link delay
        self["delay"] = 0

        # Link bandwidth capacity and bandwidth demand
        self["bandwidth"] = 0
        self["bandwidth_demand"] = 0

        # List of applications using the link for routing data to their users
        self["applications"] = []

        # List of network flows passing through the link
        self["active_flows"] = []

        # Network link active status
        self["active"] = True

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

    def __getattr__(self, attribute_name: str):
        """Retrieves an object attribute by its name.

        Args:
            attribute_name (str): Name of the attribute to be retrieved.

        Returns:
            (any): Attribute value.
        """
        if attribute_name in self:
            return self[attribute_name]
        else:
            raise AttributeError(f"Object {self} has no such attribute '{attribute_name}'.")

    def __setattr__(self, attribute_name: str, attribute_value: object):
        """Overrides the value of an object attribute.

        Args:
            attribute_name (str): Name of the attribute to be changed.
            attribute_value (object): Value for the attribute.
        """
        self[attribute_name] = attribute_value

    def __delattr__(self, attribute_name: str):
        """Deletes an object attribute by its name.

        Args:
            attribute_name (str): Name of the attribute to be deleted.
        """
        if attribute_name in self:
            del self[attribute_name]
        else:
            raise AttributeError(f"Object {self} has no such attribute '{attribute_name}'.")

    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,
                "delay": self.delay,
                "bandwidth": self.bandwidth,
                "bandwidth_demand": self.bandwidth_demand,
                "active": self.active,
            },
            "relationships": {
                "topology": {"class": "Topology", "id": self.topology.id},
                "active_flows": [{"class": type(flow).__name__, "id": flow.id} for flow in self.active_flows],
                "applications": [{"class": type(app).__name__, "id": app.id} for app in self.applications],
                "nodes": [{"class": type(node).__name__, "id": node.id} for node in self.nodes],
            },
        }
        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."""
        ...

__delattr__(attribute_name)

Deletes an object attribute by its name.

Parameters:

Name Type Description Default
attribute_name str

Name of the attribute to be deleted.

required
Source code in edge_sim_py/components/network_link.py
83
84
85
86
87
88
89
90
91
92
def __delattr__(self, attribute_name: str):
    """Deletes an object attribute by its name.

    Args:
        attribute_name (str): Name of the attribute to be deleted.
    """
    if attribute_name in self:
        del self[attribute_name]
    else:
        raise AttributeError(f"Object {self} has no such attribute '{attribute_name}'.")

__getattr__(attribute_name)

Retrieves an object attribute by its name.

Parameters:

Name Type Description Default
attribute_name str

Name of the attribute to be retrieved.

required

Returns:

Type Description
any

Attribute value.

Source code in edge_sim_py/components/network_link.py
60
61
62
63
64
65
66
67
68
69
70
71
72
def __getattr__(self, attribute_name: str):
    """Retrieves an object attribute by its name.

    Args:
        attribute_name (str): Name of the attribute to be retrieved.

    Returns:
        (any): Attribute value.
    """
    if attribute_name in self:
        return self[attribute_name]
    else:
        raise AttributeError(f"Object {self} has no such attribute '{attribute_name}'.")

__init__(obj_id=None)

Creates a NetworkLink object.

Parameters:

Name Type Description Default
obj_id int

Object identifier.

None

Returns:

Name Type Description
object object

Created NetworkLink object.

Source code in edge_sim_py/components/network_link.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
48
49
50
51
52
53
54
55
56
57
58
def __init__(self, obj_id: int = None) -> object:
    """Creates a NetworkLink object.

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

    Returns:
        object: Created NetworkLink 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

    # Reference to the network topology
    self["topology"] = None

    # List of network nodes that are connected by the link
    self["nodes"] = []

    # Link delay
    self["delay"] = 0

    # Link bandwidth capacity and bandwidth demand
    self["bandwidth"] = 0
    self["bandwidth_demand"] = 0

    # List of applications using the link for routing data to their users
    self["applications"] = []

    # List of network flows passing through the link
    self["active_flows"] = []

    # Network link active status
    self["active"] = True

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

__setattr__(attribute_name, attribute_value)

Overrides the value of an object attribute.

Parameters:

Name Type Description Default
attribute_name str

Name of the attribute to be changed.

required
attribute_value object

Value for the attribute.

required
Source code in edge_sim_py/components/network_link.py
74
75
76
77
78
79
80
81
def __setattr__(self, attribute_name: str, attribute_value: object):
    """Overrides the value of an object attribute.

    Args:
        attribute_name (str): Name of the attribute to be changed.
        attribute_value (object): Value for the attribute.
    """
    self[attribute_name] = attribute_value

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/network_link.py
117
118
119
120
121
122
123
124
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/network_link.py
126
127
128
def step(self):
    """Method that executes the events involving the object at each time step."""
    ...