Esempio n. 1
0
def init_nodes(nodes_config, host_config=None, node_factory=None, output=False):
    """Initalize WLAN Exp nodes.

    Attributes:
        nodes_config -- A WnNodesConfiguration describing the nodes
        host_config  -- A WnConfiguration object describing the host configuration
        node_factory -- A WlanExpNodeFactory or subclass to create nodes of a 
                        given WARPNet type
        output -- Print output about the WARPNet nodes
    """
    global warpnet_type_dict
    
    # Create a Host Configuration if there is none provided
    if host_config is None:
        import wlan_exp.warpnet.config as wn_config
        host_config = wn_config.HostConfiguration()

    # If node_factory is not defined, create a default WlanExpNodeFactory
    if node_factory is None:
        import wlan_exp.node as node
        node_factory = node.WlanExpNodeFactory(host_config)

    # Record the WARPNet type dictionary from the NodeFactory for later use
    warpnet_type_dict = node_factory.get_wn_type_dict()

    # Use the WARPNet utility, wn_init_nodes, to initialize the nodes
    import wlan_exp.warpnet.util as wn_util
    return wn_util.wn_init_nodes(nodes_config, host_config, node_factory, output)
Esempio n. 2
0
def init_nodes(nodes_config,
               network_config=None,
               node_factory=None,
               network_reset=True,
               output=False):
    """Initalize WLAN Exp nodes.
    
    The init_nodes function serves two purposes:  1) To initialize the node for
    participation in the experiment and 2) To retrieve all necessary information 
    from the node to provide a valid python WlanExpNode object to be used in 
    the experiment script.
    
    When a WARP node is first configured from a bitstream, its network interface is
    set to a default value such that it is part of the defalt subnet 10.0.0 but does not 
    have a valid IP address for communication with the host.  As part of the init_nodes 
    process, if network_reset is True, the host will reset the network configuration
    on the node and configure the node with a valid IP address.  If the network settings 
    of a node have already been configured and are known to the python experiment script
    a priori, then it is not necessary to issue a network reset to reset the network
    settings on the node.  This can be extremely useful when trying to interact with a 
    node via multiple python experiment scripts at the same time.    

    Args:
        nodes_config (NodesConfiguration):  A NodesConfiguration describing the nodes
            in the network.
        network_config (NetworkConfiguration, optional): A NetworkConfiguration object 
            describing the network configuration
        node_factory (WlanExpNodeFactory, optional):  A WlanExpNodeFactory or subclass 
            to create nodes of a given WARPNet type
        network_reset (bool, optional):  Issue a network reset command to the nodes to 
            initialize / re-initialize their network interface.
        output (bool, optional):         Print output about the WARPNet nodes
    
    Returns:
        nodes (list of WlanExpNode):  
            Initialized list of WlanExpNode / sub-classes of WlanExpNode depending on the 
            hardware configuration of the WARP nodes.
    """
    global warpnet_type_dict

    # Create a Host Configuration if there is none provided
    if network_config is None:
        import wlan_exp.warpnet.config as wn_config
        network_config = wn_config.NetworkConfiguration()

    # If node_factory is not defined, create a default WlanExpNodeFactory
    if node_factory is None:
        import wlan_exp.node as node
        node_factory = node.WlanExpNodeFactory(network_config)

    # Record the WARPNet type dictionary from the NodeFactory for later use
    warpnet_type_dict = node_factory.get_wn_type_dict()

    # Use the WARPNet utility, wn_init_nodes, to initialize the nodes
    import wlan_exp.warpnet.util as wn_util
    return wn_util.wn_init_nodes(nodes_config, network_config, node_factory,
                                 network_reset, output)
Esempio n. 3
0
def node_type_to_str(node_type, node_factory=None):
    """Convert the Node WARPNet Type to a string description.

    Args:
        node_type (int):  WARPNet node type code (u32)
        node_factory (WlanExpNodeFactory): A WlanExpNodeFactory or subclass to 
            create nodes of a given WARPNet type
    
    Returns:
        node_type (str):  String representation of the WARPNet node type

    By default, a dictionary of WARPNet types is built dynamically during init_nodes().  
    If init_nodes() has not been run, then the method will try to create a WARPNet 
    type dictionary.  If a node_factory is not provided then a default WlanExpNodeFactory 
    will be used to determine the WARPNet type.  If a default WlanExpNodeFactory is used, 
    then only framework WARPNet types will be known and custom WARPNet types will return:  
    "Unknown WARPNet type: <value>"
    """
    global warpnet_type_dict

    # Build a warpnet_type_dict if it is not present
    if warpnet_type_dict is None:

        # Build a default node_factory if it is not present
        if node_factory is None:
            import wlan_exp.node as node
            import wlan_exp.warpnet.config as wn_config

            network_config = wn_config.NetworkConfiguration()
            node_factory = node.WlanExpNodeFactory(network_config)

        # Record the WARPNet type dictionary from the NodeFactory for later use
        warpnet_type_dict = node_factory.get_wn_type_dict()

    if (node_type in warpnet_type_dict.keys()):
        return warpnet_type_dict[node_type]['description']
    else:
        return "Unknown WARPNet type: 0x{0:8x}".format(node_type)