Beispiel #1
0
    def config_data(cls, flags, node_id, type_flags, values):
        """
        Convert this class to a Config API message. Some TLVs are defined
        by the class, but node number, conf type flags, and values must
        be passed in.

        :param flags: message flags
        :param int node_id: node id
        :param type_flags: type flags
        :param values: values
        :return: configuration data object
        :rtype: ConfigData
        """
        keys = cls.getnames()
        keyvalues = map(lambda a, b: "%s=%s" % (a, b), keys, values)
        values_str = string.join(keyvalues, '|')
        datatypes = tuple(map(lambda x: x[1], cls.config_matrix))
        captions = reduce(lambda a, b: a + '|' + b,
                          map(lambda x: x[4], cls.config_matrix))
        possible_valuess = reduce(lambda a, b: a + '|' + b,
                                  map(lambda x: x[3], cls.config_matrix))

        return ConfigData(message_type=flags,
                          node=node_id,
                          object=cls.name,
                          type=type_flags,
                          data_types=datatypes,
                          data_values=values_str,
                          captions=captions,
                          possible_values=possible_valuess,
                          bitmap=cls.bitmap,
                          groups=cls.config_groups)
Beispiel #2
0
def setup_commeffect(session, emane_node):
    # configure emane to enable default connectivity
    config_data = ConfigData(node=emane_node.objid,
                             object="emane_commeffect",
                             type=2,
                             data_types=(11, ),
                             data_values="defaultconnectivitymode=1")
    EmaneCommEffectModel.configure_emane(session, config_data)
Beispiel #3
0
    def test_mobility(self, core):
        """
        Test basic wlan network.

        :param conftest.Core core: core fixture to test with
        """

        # create wlan
        wlan_node = core.session.add_object(cls=nodes.WlanNode)
        values = BasicRangeModel.getdefaultvalues()
        wlan_node.setmodel(BasicRangeModel, values)

        # create nodes
        core.create_node("n1",
                         objid=1,
                         position=(0, 0),
                         services=EMANE_SERVICES,
                         model="mdr")
        core.create_node("n2",
                         objid=2,
                         position=(0, 0),
                         services=EMANE_SERVICES,
                         model="mdr")

        # add interfaces
        interface_one = core.add_interface(wlan_node, "n1")
        interface_two = core.add_interface(wlan_node, "n2")

        # link nodes in wlan
        core.link(wlan_node, interface_one, interface_two)

        # configure mobility script for session
        config = ConfigData(
            node=wlan_node.objid,
            object="ns2script",
            type=0,
            data_types=(10, 3, 11, 10, 10, 10, 10, 10, 0),
            data_values="file=%s|refresh_ms=50|loop=1|autostart=0.0|"
            "map=|script_start=|script_pause=|script_stop=" % _MOBILITY_FILE)
        core.session.config_object(config)

        # add handler for receiving node updates
        event = threading.Event()

        def node_update(_):
            event.set()

        core.session.node_handlers.append(node_update)

        # instantiate session
        core.session.instantiate()

        # assert node directories created
        core.assert_nodes()

        # validate we receive a node message for updating its location
        assert event.wait(5)
Beispiel #4
0
Datei: conf.py Projekt: yrs1/core
    def config_data(cls, flags, node_id, type_flags, configurable_options,
                    config):
        """
        Convert this class to a Config API message. Some TLVs are defined
        by the class, but node number, conf type flags, and values must
        be passed in.

        :param int flags: message flags
        :param int node_id: node id
        :param int type_flags: type flags
        :param ConfigurableOptions configurable_options: options to create config data for
        :param dict config: configuration values for options
        :return: configuration data object
        :rtype: ConfigData
        """
        key_values = None
        captions = None
        data_types = []
        possible_values = []
        logging.debug("configurable: %s", configurable_options)
        logging.debug("configuration options: %s",
                      configurable_options.configurations)
        logging.debug("configuration data: %s", config)
        for configuration in configurable_options.configurations():
            if not captions:
                captions = configuration.label
            else:
                captions += "|%s" % configuration.label

            data_types.append(configuration.type.value)

            options = ",".join(configuration.options)
            possible_values.append(options)

            _id = configuration.id
            config_value = config.get(_id, configuration.default)
            key_value = "%s=%s" % (_id, config_value)
            if not key_values:
                key_values = key_value
            else:
                key_values += "|%s" % key_value

        groups_str = cls.groups_to_str(configurable_options.config_groups())
        return ConfigData(message_type=flags,
                          node=node_id,
                          object=configurable_options.name,
                          type=type_flags,
                          data_types=tuple(data_types),
                          data_values=key_values,
                          captions=captions,
                          possible_values="|".join(possible_values),
                          bitmap=configurable_options.bitmap,
                          groups=groups_str)
Beispiel #5
0
    def test_mobility(self, session, ip_prefixes):
        """
        Test basic wlan network.

        :param core.emulator.coreemu.EmuSession session: session for test
        :param ip_prefixes: generates ip addresses for nodes
        """

        # create wlan
        wlan_node = session.add_node(_type=NodeTypes.WIRELESS_LAN)
        session.set_wireless_model(wlan_node, BasicRangeModel)

        # create nodes
        node_options = NodeOptions()
        node_options.set_position(0, 0)
        node_one = session.create_wireless_node(node_options=node_options)
        node_two = session.create_wireless_node(node_options=node_options)

        # link nodes
        for node in [node_one, node_two]:
            interface = ip_prefixes.create_interface(node)
            session.add_link(node.objid,
                             wlan_node.objid,
                             interface_one=interface)

        # link nodes in wlan
        session.wireless_link_all(wlan_node, [node_one, node_two])

        # configure mobility script for session
        config = ConfigData(
            node=wlan_node.objid,
            object="ns2script",
            type=0,
            data_types=(10, 3, 11, 10, 10, 10, 10, 10, 0),
            data_values="file=%s|refresh_ms=50|loop=1|autostart=0.0|"
            "map=|script_start=|script_pause=|script_stop=" % _MOBILITY_FILE)
        session.config_object(config)

        # add handler for receiving node updates
        event = threading.Event()

        def node_update(_):
            event.set()

        session.node_handlers.append(node_update)

        # instantiate session
        session.instantiate()

        # validate we receive a node message for updating its location
        assert event.wait(5)
Beispiel #6
0
    def configure_request(self, config_data):
        """
        Receive configuration message for configuring services.
        With a request flag set, a list of services has been requested.
        When the opaque field is present, a specific service is being
        configured or requested.

        :param core.conf.ConfigData config_data: configuration data for carrying out a configuration
        :return: response messages
        :rtype: ConfigData
        """
        node_id = config_data.node
        session_id = config_data.session
        opaque = config_data.opaque

        logger.debug("configuration request: node(%s) session(%s) opaque(%s)",
                     node_id, session_id, opaque)

        # send back a list of available services
        if opaque is None:
            type_flag = ConfigFlags.NONE.value
            data_types = tuple(
                repeat(ConfigDataTypes.BOOL.value,
                       len(ServiceManager.services)))
            values = "|".join(repeat('0', len(ServiceManager.services)))
            names = map(lambda x: x._name, ServiceManager.services)
            captions = "|".join(names)
            possible_values = ""
            for s in ServiceManager.services:
                if s._custom_needed:
                    possible_values += '1'
                possible_values += '|'
            groups = self.buildgroups(ServiceManager.services)
        # send back the properties for this service
        else:
            if node_id is None:
                return None
            node = self.session.get_object(node_id)
            if node is None:
                logger.warn("Request to configure service for unknown node %s",
                            node_id)
                return None
            servicesstring = opaque.split(':')
            services, unknown = self.servicesfromopaque(opaque, node.objid)
            for u in unknown:
                logger.warn("Request for unknown service '%s'" % u)

            if len(services) < 1:
                return None

            if len(servicesstring) == 3:
                # a file request: e.g. "service:zebra:quagga.conf"
                file_data = self.getservicefile(services, node,
                                                servicesstring[2])
                self.session.broadcast_file(file_data)

                # short circuit this request early to avoid returning response below
                return None

            # the first service in the list is the one being configured
            svc = services[0]
            # send back:
            # dirs, configs, startindex, startup, shutdown, metadata, config
            type_flag = ConfigFlags.UPDATE.value
            data_types = tuple(
                repeat(ConfigDataTypes.STRING.value, len(svc.keys)))
            values = svc.tovaluelist(node, services)
            captions = None
            possible_values = None
            groups = None

        return ConfigData(message_type=0,
                          node=node_id,
                          object=self.name,
                          type=type_flag,
                          data_types=data_types,
                          data_values=values,
                          captions=captions,
                          possible_values=possible_values,
                          groups=groups,
                          session=session_id,
                          opaque=opaque)