def _create_hdf5_log_data_container(group, np_data, raw_log_index, compression=None):
    """Create a wlan_exp_log_data_container in the given group."""
    import h5py
    import numpy as np
    import wlan_exp.version as version

    # Add default attributes to the group
    group.attrs['wlan_exp_log'] = True
    group.attrs['wlan_exp_ver'] = np.array(version.wlan_exp_ver(), dtype=np.uint32)

    if('log_data' in group.keys() and type(group['log_data']) is h5py.Dataset):
        raise AttributeError("Dataset 'log_data' already exists in group {0}\n".format(group))
    
    # Create a data set for the numpy-formatted log_data (created above)
    group.create_dataset("log_data", data=np_data, compression=compression)

    # Add the index to the HDF5 file if necessary
    if not raw_log_index is None:
        index_grp = group.create_group("raw_log_index")

        for k, v in raw_log_index.items():
            # Check if highest-valued entry index can be represented as uint32 or requires uint64
            if (v[-1] < 2**32):
                dtype = np.uint32
            else:
                dtype = np.uint64

            # Group names must be strings - keys here are known to be integers (entry_type_id values)
            index_grp.create_dataset(str(k), data=np.array(v, dtype=dtype), compression=compression)
Ejemplo n.º 2
0
    def __init__(self, host_config=None):
        super(WlanExpNode, self).__init__(host_config)

        (self.wlan_exp_ver_major, self.wlan_exp_ver_minor,
         self.wlan_exp_ver_revision) = version.wlan_exp_ver()

        self.node_type = defaults.WLAN_EXP_BASE
        self.device_type = self.node_type
        self.wlan_scheduler_resolution = 1

        self.log_total_bytes_read = 0
        self.log_num_wraps = 0
        self.log_next_read_index = 0
Ejemplo n.º 3
0
    def __init__(self, host_config=None):
        super(WlanExpNode, self).__init__(host_config)
        
        (self.wlan_exp_ver_major, self.wlan_exp_ver_minor, 
                self.wlan_exp_ver_revision) = version.wlan_exp_ver()
        
        self.node_type                      = defaults.WLAN_EXP_BASE
        self.device_type                    = self.node_type
        self.wlan_scheduler_resolution      = 1

        self.log_total_bytes_read           = 0
        self.log_num_wraps                  = 0
        self.log_next_read_index            = 0
    def _create_container(self, group):
        """Internal method to create a valid log data container."""
        import numpy as np
        import wlan_exp.version as version

        # Add default attributes to the group
        group.attrs['wlan_exp_log'] = np.array([1], dtype=np.uint8)
        group.attrs['wlan_exp_ver'] = np.array(version.wlan_exp_ver(), dtype=np.uint32)

        # Create an empty numpy array of type 'V1' (ie one byte void)
        np_dt   = np.dtype('V1')
        np_data = np.empty((0,), np_dt)
        
        # Create an empty re-sizeable data set for the numpy-formatted data
        group.create_dataset("log_data", data=np_data, maxshape=(None,), compression=self.compression)
Ejemplo n.º 5
0
    def _create_container(self, group):
        """Internal method to create a valid log data container."""
        import numpy as np
        import wlan_exp.version as version

        # Add default attributes to the group
        group.attrs['wlan_exp_log'] = np.array([1], dtype=np.uint8)
        group.attrs['wlan_exp_ver'] = np.array(version.wlan_exp_ver(),
                                               dtype=np.uint32)

        # Create an empty numpy array of type 'V1' (ie one byte void)
        np_dt = np.dtype('V1')
        np_data = np.empty((0, ), np_dt)

        # Create an empty re-sizeable data set for the numpy-formatted data
        group.create_dataset("log_data",
                             data=np_data,
                             maxshape=(None, ),
                             compression=self.compression)
Ejemplo n.º 6
0
    def is_valid(self):
        """Check that the HDF5 Log Container is valid.

        Returns:
            is_valid (bool):
                * True --> This is a valid HDF5 log file
                * False --> This is NOT a valid HDF5 log file
        """
        import numpy as np
        import wlan_exp.version as version

        # Check the group handle but do not create one
        group_handle = self._get_group_handle()

        if group_handle is None:
            msg = "WARNING: Log container is not valid.\n"
            msg += "    Could not find {0} in file.".format(
                self.hdf5_group_name)
            print(msg)
            return False

        try:
            if group_handle.attrs['wlan_exp_log']:
                # Require two attributes named 'wlan_exp_log' and 'wlan_exp_ver'
                ver = group_handle.attrs['wlan_exp_ver']

                ver_str = version.wlan_exp_ver_str(ver[0], ver[1], ver[2])
                ver_older_than_093 = (ver[0], ver[1], ver[2]) < (0, 9, 3)
                caller_desc = "HDF5 file '{0}' was written using version {1}".format(
                    self.file_handle.filename, ver_str)

                status = version.wlan_exp_ver_check(major=ver[0],
                                                    minor=ver[1],
                                                    revision=ver[2],
                                                    caller_desc=caller_desc)

                if (status == version.WLAN_EXP_VERSION_NEWER
                        and (version.wlan_exp_ver() >=
                             (0, 9, 3)) and ver_older_than_093):
                    msg = "The HDF5 file uses a version older than 0.93, please convert using \n"
                    msg += "the log_util_hdf5convert.py utility found the example directory in \n"
                    msg += "releases prior to 1.0."
                    print(msg)

                if (status == version.WLAN_EXP_VERSION_OLDER):
                    print(
                        "Please update the WLAN Exp installation to match the version on the HDF5 file."
                    )

            else:
                msg = "WARNING: Log container is not valid.\n"
                msg += "    'wlan_exp_log' attribute indicates log container is not valid."
                print(msg)
                return False

            if group_handle['log_data']:
                # Require a dataset named 'log_data'
                if (group_handle['log_data'].dtype.kind != np.dtype(
                        np.void).kind):
                    # Require the 'log_data' dataset to be HDF5 opaque type (numpy void type)
                    msg = "WARNING: Log container is not valid.\n"
                    msg += "    Log Data is not valid type.  Must be an HDF5 opaque type."
                    print(msg)
                    return False
        except Exception as err:
            msg = "WARNING: Log container is not valid.  The following error occurred:\n"
            msg += "    {0}".format(err)
            print(msg)
            return False

        return True
Ejemplo n.º 7
0
    def is_valid(self):
        """Check that the HDF5 Log Container is valid.

        Returns:
            is_valid (bool):
                * True --> This is a valid HDF5 log file
                * False --> This is NOT a valid HDF5 log file
        """
        import numpy as np
        import wlan_exp.version as version

        # Check the group handle but do not create one
        group_handle = self._get_group_handle()

        if group_handle is None:
            msg  = "WARNING: Log container is not valid.\n"
            msg += "    Could not find {0} in file.".format(self.hdf5_group_name)
            print(msg)
            return False

        try:
            if group_handle.attrs['wlan_exp_log']:
                # Require two attributes named 'wlan_exp_log' and 'wlan_exp_ver'
                ver = group_handle.attrs['wlan_exp_ver']

                ver_str            = version.wlan_exp_ver_str(ver[0], ver[1], ver[2])
                ver_older_than_093 = (ver[0], ver[1], ver[2]) < (0, 9, 3)
                caller_desc = "HDF5 file '{0}' was written using version {1}".format(self.file_handle.filename, ver_str)

                status = version.wlan_exp_ver_check(major=ver[0], minor=ver[1], revision=ver[2],
                                                    caller_desc=caller_desc)
                

                if (status == version.WLAN_EXP_VERSION_NEWER and 
                        (version.wlan_exp_ver() >= (0, 9, 3)) and ver_older_than_093):
                    msg  = "The HDF5 file uses a version older than 0.93, please convert using \n"
                    msg += "the log_util_hdf5convert.py utility found the example directory in \n"
                    msg += "releases prior to 1.0."
                    print(msg)
                
                if (status == version.WLAN_EXP_VERSION_OLDER):
                    print("Please update the wlan_exp installation to match the version on the HDF5 file.")
                            
            else:
                msg  = "WARNING: Log container is not valid.\n"
                msg += "    'wlan_exp_log' attribute indicates log container is not valid."
                print(msg)
                return False

            if group_handle['log_data']:
                # Require a dataset named 'log_data'
                if(group_handle['log_data'].dtype.kind != np.dtype(np.void).kind):
                    # Require the 'log_data' dataset to be HDF5 opaque type (numpy void type)
                    msg  = "WARNING: Log container is not valid.\n"
                    msg += "    Log Data is not valid type.  Must be an HDF5 opaque type."
                    print(msg)
                    return False
        except Exception as err:
            msg  = "WARNING: Log container is not valid.  The following error occurred:\n"
            msg += "    {0}".format(err)
            print(msg)
            return False

        return True