omnetpypy.parser
This module provides the tools to parse the YAML configuration and topology files
- omnetpypy.parser.instantiate_compound_module(name, module_classes, channel_classes, compound_descriptors, next_module_id, next_channel_id)[source]
Instantiate a compound module from its yaml descriptor. The function is recursive, as a compound module can contain other compound modules. In such case, inner compound modules are fully initialized first.
- Parameters:
- namestr
The name of the compound module
- module_classeslist
A list of the simple module classes, already imported
- channel_classeslist
A list of the channel classes, already imported
- compound_descriptorslist
The list of compound module descriptors, used to instantiate the compound modules when needed
- next_module_idint
The current next simple module identifier
- next_channel_idint
The current next channel identifier
- Returns:
- tuple
The compound module instance (
CompoundModule
), the new next simple module identifier, the new next channel identifier, and the new next compound module identifier
- Raises:
- ValueError
If the compound module name is not found in the descriptors or one of its submodules was not defined
- omnetpypy.parser.parse_channels(channel_descriptors)[source]
Parse the channels from raw parsed data
- Parameters:
- channel_descriptorslist
A list of dictionaries containing the channel data
- Returns:
- list of
Channel
A list of the channel classes
- list of
- omnetpypy.parser.parse_connection(connection_data, compound_module, channel_classes, next_channel_id)[source]
Parse a connection from raw parsed data and entity classes within a compound module
- Parameters:
- connection_datadict
A dictionary containing the connection data
- compound_module
CompoundModule
The compound module instance
- channel_classeslist
A list of the channel classes, already imported
- next_channel_idint
The current next channel identifier, used to generate unique identifiers for channels
- Returns:
- int
The new next channel identifier
- Raises:
- Exception
If the connection data is invalid
- omnetpypy.parser.parse_simple_modules(simple_descriptors)[source]
Parse the simple modules from raw parsed data
- Parameters:
- simple_descriptorslist
A list containing the simple modules’ data as dictionaries with two keys “name” and “package”
- Returns:
- list of
SimpleModule
A list of the simple module classes
- list of
- omnetpypy.parser.parse_yaml_directory(directory_path, sim_context)[source]
Parse all the YAML files from the specified directory. Files are parsed in the order listed below. The directory should contain:
“config.yaml”: the configuration file
“simple.yaml”: the file listing all the simple modules used in the simulation
“channels.yaml” (optional): the file listing all the custom channels used in the simulation
“compound.yaml” (optional): the file listing all the compound modules used in the simulation
“network.yaml”: the network topology file
- Parameters:
- directory_pathstr
The path to the directory containing the YAML files
- sim_context
Simulation
The simulation with its context
- Returns:
- tuple
A tuple containing the configuration, the simple modules, the channels, and the compound modules
- Raises:
- FileNotFoundError
If one of the mandatory files is missing
- ValueError
If one of the files has an invalid format or there is a dependency loop in the compound modules
- omnetpypy.parser.parse_yaml_file(file_path)[source]
Parse the YAML configuration file.
- Parameters:
- file_pathstr
The path to the YAML configuration file
- Returns:
- dict
The parsed configuration, as a dictionary directly loaded from the YAML file
- omnetpypy.parser.sanitize_compound_descriptors(compound_descriptors)[source]
Sanitize the compound descriptors to ensure there is no submodule dependency loop that would cause endless recursion.
- Parameters:
- compound_descriptorslist
The list of compound module descriptors
- Raises:
- ValueError
If a dependency loop is detected or if one of the submodules has an invalid name