def initialize(self, peer, *args, engines=None, **kwargs):
        """ Initialize multiple LTP engines to be used by in parallel when sending a
            bundle.
        """
        # Call parent initialization
        super(DtnAbstractDuctParallelLTP, self).initialize(peer, **kwargs)

        # If no engines defined, raise error
        if not engines:
            raise ValueError('No engines defined for ParallelLTP duct')

        # Initialize variables
        self.num_engines = len(engines)

        # Iterate over the engines and initialize them
        for engine_id, engine_name in engines.items():
            # Get the engine properties
            props = self.env.config[engine_name]

            # Initialize variables
            iduct, oduct = None, None

            # Create the induct and outduct
            for class_name in getattr(props, 'class'):
                # Load class type
                try:
                    clazz = load_class_dynamically('simulator.ducts.inducts',
                                                   class_name)
                except ModuleNotFoundError:
                    clazz = load_class_dynamically('simulator.ducts.outducts',
                                                   class_name)

                # Construct depending on whether is an induct or outduct
                if clazz.duct_type == None:
                    raise RuntimeError(
                        f'{clazz} has no duct_type defined. Is it an induct or outduct?'
                    )
                elif clazz.duct_type == 'outduct':
                    oduct = clazz(self.env, engine_id, self, self.neighbor)
                elif clazz.duct_type == 'induct':
                    iduct = clazz(self.env, engine_id, peer, self.nid)
                else:
                    raise RuntimeError(
                        'f{clazz} has duct_type = {clazz.duct_type}. Valid options are "induct" and '
                        '"outduct"')

            # If either the ouduct or induct are not set, throw error
            if iduct == None or oduct == None:
                raise RuntimeError('Could not create duct f{duct_id}')

            # Initialize duct parameters. Initialization must happen after creating the ducts
            # since they must point to each other.
            oduct.initialize(iduct, **dict(props))
            iduct.initialize(oduct, **dict(props))

            # Store the engines
            self.engines[engine_id] = {'induct': iduct, 'outduct': oduct}
Exemplo n.º 2
0
    def initialize_router(self):
        # Initialize variables
        config = self.env.config

        # Get type of router for this node
        router_type = config[self.type].router

        # Instantiate generators dynamically based on class name
        clazz = load_class_dynamically('simulator.routers',
                                       getattr(config[router_type], 'class'))
        self.router = clazz(self.env, self)

        # Initialize this router
        self.router.initialize()

        # If this router is not opportunistic, you are done
        if not self.router.opportunistic: return

        # If this is an opportunistic router, then a specialized queue
        # manager is needed.
        clazz = load_class_dynamically('simulator.nodes',
                                       config[router_type].manager)
        self.queues['opportunistic'] = clazz(self.env, self,
                                             config[router_type])
Exemplo n.º 3
0
    def initialize_radios(self):
        # Iterate over the radios
        for radio in self.props.radios:
            # Create the radio for this duct
            class_name = getattr(self.config[radio], 'class')
            clazz = load_class_dynamically('simulator.radios', class_name)

            # Get properties
            radio_props = dict(self.config[radio])

            # Store the new radio
            self.radios[radio] = clazz(self.env, self)

            # Initialize the radio
            self.radios[radio].initialize(**radio_props)
Exemplo n.º 4
0
    def initialize_endpoints(self):
        # Add any additional endpoints
        for eid, ept_class in self.props.endpoints.items():
            # Handle special case for default endpoint
            if eid == 0:
                self.endpoints[eid] = DtnDefaultEndpoint(self.env, self)
                self.endpoints[eid].initialize()
                continue

            # Find the endpoint type
            clazz = load_class_dynamically('simulator.endpoints', ept_class)

            # Store the new endpoint
            self.endpoints[eid] = clazz(self.env, self)

            # Initialize endpoint
            if eid in self.config:
                self.endpoints[eid].initialize(**dict(self.config[eid]))
            else:
                self.endpoints[eid].initialize()
Exemplo n.º 5
0
    def initialize_neighbors_and_ducts(self):
        # Iterate over all neighbors
        for orig, neighbor in self.env.connections.keys():
            # If this is not the right origin, continue
            if orig != self.nid: continue

            # Store this neighbor
            self.neighbors.append(neighbor)

            # Create and store the priority queue for this neighbor
            self.queues[neighbor] = DtnCgrNeighborManager(
                self.env, self, neighbor)

            # Get the neighbor node and the connection between them
            other = self.env.nodes[neighbor]
            conn = self.env.connections[self.nid, neighbor]

            # Iterate over defined ducts and create them
            for duct_id, duct_name in self.env.config[conn.type].ducts.items():
                # Get the properties of this duct
                props = self.env.config[duct_name]

                # Initialize variables
                iduct, oduct = None, None

                # Create the induct and outduct
                for class_name in getattr(props, 'class'):
                    # Load class type. Since you can't know if it is an induct or outduct,
                    # try both.
                    try:
                        clazz = load_class_dynamically(
                            'simulator.ducts.inducts', class_name)
                    except ModuleNotFoundError:
                        clazz = load_class_dynamically(
                            'simulator.ducts.outducts', class_name)

                    # Construct depending on whether it is an induct or outduct
                    if clazz.duct_type == None:
                        raise RuntimeError(
                            f'{clazz} has no duct_type defined. Is it an induct or outduct?'
                        )
                    elif clazz.duct_type == 'outduct':
                        oduct = clazz(self.env, duct_id, self, neighbor)
                    elif clazz.duct_type == 'induct':
                        iduct = clazz(self.env, duct_id, other, orig)
                    else:
                        raise RuntimeError(
                            'f{clazz} has duct_type = {clazz.duct_type}. Valid options are "induct" and '
                            '"outduct"')

                # If either the ouduct or induct are not set, throw error
                if iduct == None or oduct == None:
                    raise RuntimeError('Could not create duct f{duct_id}')

                # Store the newly created ducts
                self.ducts[neighbor][duct_id]['outduct'] = oduct
                other.ducts[orig][duct_id]['induct'] = iduct

            # Iterate over defined ducts and initialize them. This is done separately
            # since you need to have created all ducts to initialize them for ParallelLTP
            for duct_id, duct_name in self.env.config[conn.type].ducts.items():
                # Get the properties of this duct
                props = self.env.config[duct_name]

                oduct = self.ducts[neighbor][duct_id]['outduct']
                iduct = other.ducts[orig][duct_id]['induct']

                # Initialize duct parameters. Initialization must happen after creating the ducts
                # since they must point to each other.
                oduct.initialize(iduct, **dict(props))
                iduct.initialize(oduct, **dict(props))

        # For now, assume that there is no need for an opportunistic queue.
        # If so, it will be initialized with the router.
        self.queues['opportunistic'] = None