pydistsim.network.node.Node
- class Node(network: NetworkType | None = None, commRange: None | int = None, sensors: None | tuple[type[Sensor] | str] = None, **kwargs)[source]
Bases:
ObserverManagerMixinRepresents a node in a network.
- Parameters:
network (NetworkType, optional) – Optional network object to which the node belongs.
commRange (int, optional) – Communication range of the node.
sensors (tuple[type[Sensor] | str], optional) – Tuple of sensor types or names.
kwargs – Additional keyword arguments.
Methods
__init__add_observersBlock messages from being received by the node.
Convert a message box to a dictionary representation.
clear_observersGet the node's information as a dictionary.
Get the log messages stored in the node's memory.
Insert a log message in the node's memory.
notify_observersPush a message to the inbox of the node.
Push a message to the outbox of the node.
Pop message from inbox but only if it has been there at least one step.
Reset the node's state.
Unblock messages from being received by the node.
unboxAttributes
Get the communication range of the node.
Get the composite sensor of the node.
Get the inbox of the node.
next_node_idGet the sensors of the node.
Get the status of the node.
The network to which the node belongs.
- _compositeSensor
Object that collects the data from all available sensors.
- _internal_id
Internal ID of the node. Only used for internal simulation purposes.
- block_inbox(filter_func: Callable[[Message], bool]) Callable[[Message], bool][source]
Block messages from being received by the node.
- Parameters:
filter_func (function) – The filter function to be used.
- Returns:
The filter function.
- box_as_dic(box: str)[source]
Convert a message box to a dictionary representation.
- Parameters:
box (str) – The message box to be converted.
- Returns:
The dictionary representation of the message box.
- Return type:
dict
- property commRange: int
Get the communication range of the node.
- Returns:
The communication range of the node.
- Return type:
int
- property compositeSensor
Get the composite sensor of the node.
- Returns:
The composite sensor of the node.
- Return type:
- get_dic()[source]
Get the node’s information as a dictionary.
- Returns:
The node’s information.
- Return type:
dict
- get_log()[source]
Get the log messages stored in the node’s memory.
- Returns:
The log messages.
- Return type:
list[tuple[LogLevels, str, dict]]
- property inbox
Get the inbox of the node.
- Returns:
The inbox of the node.
- Return type:
list[Message]
- log(message: str, level: LogLevels = LogLevels.WARNING)[source]
Insert a log message in the node’s memory.
- Parameters:
message (str) – The log message to be inserted.
level (LogLevels, optional) – The log level of the message.
- network
The network to which the node belongs.
- push_to_inbox(message: Message[Node])[source]
Push a message to the inbox of the node.
- Parameters:
message (Message) – The message to be pushed to the inbox.
- push_to_outbox(message: Message[Node], destination: Node)[source]
Push a message to the outbox of the node.
- receive()[source]
Pop message from inbox but only if it has been there at least one step.
Messages should be delayed for one step for visualization purposes. Messages are processed without delay only if they are pushed into empty inbox. So if inbox is empty when push_to_inbox is called _inboxDelay is set to True.
This method is used only internally and is not supposed to be used inside algorithms.
- Returns:
The received message, or None if no message is available.
- Return type:
Message or None
- property sensors
Get the sensors of the node.
- Returns:
The sensors of the node.
- Return type:
list[Sensor]
- property status
Get the status of the node.
- Returns:
The status of the node.
- Return type:
str