Skip to content

Introduction

gradysim.encapsulator

The encapsulator module is a middle-man between protocols and environments. One of GrADyS-SIM NextGen's features is the construction of protocols that can be used in different environments without changes to their code. These environments are called execution modes. Protocols are wrapped in encapsulators that handle the effects of the environment on the protocol and are injected with provider instances that provide them with the necessary tools to interact with the environment.

This module provides encapsulators that enable users to run their protocols inside a python simulation (prototype-mode), integrated with a realistic network simulator OMNeT++ (integrated-mode) and, in the future, connected to real-life nodes.

All encapsulators implement the IEncapsulator interface.

gradysim.encapsulator.interface.IEncapsulator

Bases: ABC, Generic[T]

Defines a generic interface that all encapsulators should implement. Encapsulator's main task is to wrap nodes absorbing effects from the environment and propagating them to the node and injecting a provider instance so that the nodes can interact with the environment.

Source code in gradysim/encapsulator/interface.py
class IEncapsulator(ABC, Generic[T]):
    """
    Defines a generic interface that all encapsulators should implement. Encapsulator's main task is to wrap nodes
    absorbing effects from the environment and propagating them to the node and injecting a provider instance so
    that the nodes can interact with the environment.
    """
    protocol: T

    @abstractmethod
    def encapsulate(self, protocol: Type[T]) -> None:
        """
        Wraps a protocol. Should instantiate it and inject a provider instance into it. Every IEncapsulator instance
        wraps a single protocol only.

        Args:
            protocol: The type of protocol being instantiated
        """
        pass

    @abstractmethod
    def initialize(self):
        """
        Wraps the protocols initialize function
        """
        pass

    @abstractmethod
    def handle_timer(self, timer: str):
        """
        Wraps the protocols handler_timer function
        """
        pass

    @abstractmethod
    def handle_packet(self, message: str):
        """
        Wraps the protocols handle_packet function
        """
        pass

    @abstractmethod
    def handle_telemetry(self, telemetry: Telemetry):
        """
        Wraps the protocols handle_telemetry function
        """
        pass

    @abstractmethod
    def finish(self):
        """
        Wraps the protocols finish function
        """
        pass

encapsulate(protocol) abstractmethod

Wraps a protocol. Should instantiate it and inject a provider instance into it. Every IEncapsulator instance wraps a single protocol only.

Parameters:

Name Type Description Default
protocol Type[T]

The type of protocol being instantiated

required
Source code in gradysim/encapsulator/interface.py
@abstractmethod
def encapsulate(self, protocol: Type[T]) -> None:
    """
    Wraps a protocol. Should instantiate it and inject a provider instance into it. Every IEncapsulator instance
    wraps a single protocol only.

    Args:
        protocol: The type of protocol being instantiated
    """
    pass

finish() abstractmethod

Wraps the protocols finish function

Source code in gradysim/encapsulator/interface.py
@abstractmethod
def finish(self):
    """
    Wraps the protocols finish function
    """
    pass

handle_packet(message) abstractmethod

Wraps the protocols handle_packet function

Source code in gradysim/encapsulator/interface.py
@abstractmethod
def handle_packet(self, message: str):
    """
    Wraps the protocols handle_packet function
    """
    pass

handle_telemetry(telemetry) abstractmethod

Wraps the protocols handle_telemetry function

Source code in gradysim/encapsulator/interface.py
@abstractmethod
def handle_telemetry(self, telemetry: Telemetry):
    """
    Wraps the protocols handle_telemetry function
    """
    pass

handle_timer(timer) abstractmethod

Wraps the protocols handler_timer function

Source code in gradysim/encapsulator/interface.py
@abstractmethod
def handle_timer(self, timer: str):
    """
    Wraps the protocols handler_timer function
    """
    pass

initialize() abstractmethod

Wraps the protocols initialize function

Source code in gradysim/encapsulator/interface.py
@abstractmethod
def initialize(self):
    """
    Wraps the protocols initialize function
    """
    pass