Interop
gradysim.encapsulator.interop
Wraps the running protocol and prepares it for integration with the OMNeT++, in integrated-mode. It is injected with a InteropProvider instance that provides it with the necessary tools to interact with the OMNeT++ environment.
The integration works by collecting all the consequences of the protocol's actions and returning them to the OMNeT++. Consequences are actions that the protocol wants to perform on the environment, such as sending a message or moving the node. The OMNeT++ environment then performs these actions is able to call protocol when it needs to, such as when a message is received or a timer fires.
This encapsulator is instantiated by OMNeT++, the execution flow is only transferred to this code when an envet happens in the OMNeT++ simulation that warrants a call to the protocol. No code changes are necessary to run a protocol in this mode.
Consequence = Tuple[ConsequenceType, Union[CommunicationCommand, MobilityCommand, TimerParams, TrackVariableParams]]
module-attribute
A consequence is a tuple of a consequence type and a consequence payload. The payload is a different type for each consequence type
TimerParams = Tuple[str, float]
module-attribute
Parameters to a timer consequence. The str is the timer and the float is the timestamp when the timer should fire
TrackVariableParams = Tuple[str, Any]
module-attribute
Parameters to a track variable consequence. The str is the variable name and the Any is the variable value
ConsequenceType
Bases: int
, Enum
Enum representing the different types of consequences that can be returned by the protocol. Each consequence type serializes a different interaction the protocol wants to perform with the environment.
Source code in gradysim/encapsulator/interop.py
InteropEncapsulator
Bases: IEncapsulator
Encapsulator implementation for the OMNeT++ environment. The encapsulator wraps the protocol and prepares it for integration with the OMNeT++ environment. It is injected with a InteropProvider instance that provides it with the necessary tools to interact with the OMNeT++ environment.
Source code in gradysim/encapsulator/interop.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
__init__()
encapsulate(protocol)
Instantiates the protocol and injects the provider into it
Parameters:
Name | Type | Description | Default |
---|---|---|---|
protocol |
Type[IProtocol]
|
The type of protocol being encapsulated |
required |
Source code in gradysim/encapsulator/interop.py
finish()
Finalizes the protocol. Called by the OMNeT++ environment when the simulation is over.
Returns:
Type | Description |
---|---|
List[Consequence]
|
A list of consequences that the protocol wants to perform on the environment from this call |
Source code in gradysim/encapsulator/interop.py
handle_packet(message)
Handles a message. Called by the OMNeT++ environment when a message is received.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message |
str
|
Message being received |
required |
Returns:
Type | Description |
---|---|
List[Consequence]
|
A list of consequences that the protocol wants to perform on the environment from this call |
Source code in gradysim/encapsulator/interop.py
handle_telemetry(telemetry)
Handles a telemetry event. Called by the OMNeT++ environment when a telemetry event happens.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
telemetry |
Telemetry
|
Telemetry event being received |
required |
Returns:
Type | Description |
---|---|
List[Consequence]
|
A list of consequences that the protocol wants to perform on the environment from this call |
Source code in gradysim/encapsulator/interop.py
handle_timer(timer)
Handles a timer event. Called by the OMNeT++ environment when a timer fires.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timer |
str
|
The timer that fired |
required |
Returns:
Type | Description |
---|---|
List[Consequence]
|
A list of consequences that the protocol wants to perform on the environment from this call |
Source code in gradysim/encapsulator/interop.py
initialize()
Initializes the protocol. Called by the OMNeT++ environment before the simulation starts.
Returns:
Type | Description |
---|---|
List[Consequence]
|
A list of consequences that the protocol wants to perform on the environment from this call |
Source code in gradysim/encapsulator/interop.py
set_id(id)
Sets the node's unique identifier in the simulation. This method is called once by the OMNeT++ environment before calling any of the protocol's methods, to make sure the protocol has the correct id.
Source code in gradysim/encapsulator/interop.py
set_timestamp(timestamp)
Sets the current simulation time in seconds. This method is called by the OMNeT++ environment before calling the protocol's methods, to make sure the protocol has the correct time.
Source code in gradysim/encapsulator/interop.py
InteropProvider
Bases: IProvider
Provider implementation for the OMNeT++ environment. The provider is injected into the protocol encapsulator and provides it with the necessary tools to interact with the environment.
Source code in gradysim/encapsulator/interop.py
__init__()
Creates a new provider instance
Source code in gradysim/encapsulator/interop.py
current_time()
Returns the current simulation time in seconds
Returns: The current simulation time in seconds
get_id()
Returns the node's unique identifier in the simulation
Returns:
Type | Description |
---|---|
int
|
The node's unique identifier in the simulation |
schedule_timer(timer, timestamp)
Adds a timer consequence to the list of consequences
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timer |
str
|
The timer that will be fired |
required |
timestamp |
float
|
The timestamp in simulation seconds when the timer will fire |
required |
Source code in gradysim/encapsulator/interop.py
send_communication_command(command)
Adds a communication command to the list of consequences
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command |
CommunicationCommand
|
Command being issued |
required |
Source code in gradysim/encapsulator/interop.py
send_mobility_command(command)
Adds a mobility command to the list of consequences
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command |
MobilityCommand
|
Command being issued |
required |