Package Overview
The Process package is a set of Kernel Procedures that provide the ability to create and manage multiple processes within the context of a single processor or queue module. Process is the term used to refer to a single instance of a process model; a process model is the specification developed in the Process Editor for the behavior and function of a particular type of process.
Each processor or queue module in a model has at least one process associated with it. This process is called the module’s root process and is created automatically by the Simulation Kernel when a simulation begins. The Kernel refers to the module’s process model attribute to determine which type of process to create and install as the root process. The default behavior of a queue or processor module is to handle every event that occurs at this module by invoking the root process. This default behavior can be achieved without any use of the Process Package Kernel Procedures. The KPs of this package are useful only when the modeler wants to develop models in which multiple processes will coexist within one module.
The ability to maintain multiple processes within a single physical module corresponds directly to the multi-tasking or multi-context paradigms found in many common computing and telecommunications systems. For instance, multi-tasking operating systems allocate processes of various types dynamically as users request programs to be executed. Perhaps even more common for Riverbed-based applications, protocols such as X.25 or TCP are required to manage multiple contexts, in this case one per session or logical channel. It is convenient to think of each of these logical channels as being managed by an independent process with its own state, rather than modeling the collection of logical channels as a single process that maintains separate sets of state memory for each channel. The processes, which are instances of the same process model, can be created as needed when new logical channels are requested.
The root process of a module will necessarily be the first process to be invoked within that module because it is the only process that exists at that time. It can choose at that time or at a later date to create new processes by calling the KP op_pro_create(). When a process calls this KP to create another one, it is known as the parent of the new process. Conversely, the new process is referred to as a child process of the process that created it. Note that a process can have many children with different process models, but that each process can have only one parent. The Simulation Kernel places no limit upon the number of processes that can be created within a module using op_pro_create().
When using the KPs of the Process package, processes are referred to by variables called process handles, each of which is declared as a Prohandle.The KP op_pro_create() returns a Prohandle which the parent process can then use to invoke, destroy, or query attributes of the child process. A process can obtain a process handle for itself by calling the KP op_pro_self(). Similarly, a process handle for a process’ parent can be obtained via the KP op_pro_parent(). The Prohandle for the root process in a given module can be obtained by calling the KP op_pro_root(). Two process handles can be compared (to determine if they are equivalent) with the KP op_pro_equal().
A process handle is a multi-member data-structure and is therefore not well suited to certain purposes such as comparisons or diagnostic statements; therefore the Simulation Kernel assigns a unique positive integer to each process, known as the process ID. Process IDs are only guaranteed to be unique, and may not be contiguous or begin at any particular value. When referring to processes, the OPNET debugger prints process IDs. The ID of a process can be obtained by passing its handle to the KP op_pro_id().
Each process is owned by a single queue or processor module. It is upon this module’s physical resources that the process can act directly. For instance, when a process calls the KP op_pk_get() to obtain a packet from an input stream, or op_stat_local_read() to obtain the value of an input statistic, it implicitly refers to the streams and statistic wires of the module that owns it. The ownership of the root process is assigned when the process is automatically started by the Kernel and this same ownership is given to each of the child processes of the root and to their child processes in turn. The object ID of the module that owns a process can be determined by calling the KP op_pro_mod_objid().
Processes that are no longer useful (such as a process used to manage a logical channel that has been closed) can be removed from the owning module’s set of processes by passing their process handle to the KP op_pro_destroy(). This will automatically release the memory used to store the process’ state variables. However, there is no way for the Simulation Kernel to be aware of memory that this process may have allocated after its creation, and the responsibility for such deallocation belongs to the child process itself. The KP op_pro_destroy_options() performs the same function, but also permits optional operations, such as removing from the event queue all outstanding events scheduled for the destroyed process.
When a process wishes to cause another process within the same module to be executed, it passes the Prohandle for that process to the KP op_pro_invoke(). The process that is invoked cannot be owned by a different module than the process that invokes it, or an error will occur and the invocation will fail. However, the process that is invoked can be any other process owned by the same module, including the root process. A process invoked via op_pro_invoke() returns to the context of the invoking process once it has reached a blocking condition. A process model attains a blocking condition when it completes the enter-executives of an unforced state (see Chapter 5 “Process Domain” on page 169 for more information on this topic). The return of control to the invoking process occurs at the point in its logic immediately following the call to op_pro_invoke().
To support communication of information between processes that coexist within a queue or processor module, three types of shared memory mechanisms are defined. These are referred to as module memory, parent-to-child memory, and argument memory, and each is useful for different situations. There is no requirement to use any of the shared memory mechanisms provided by the Process Package when developing a model. In addition, processes can communicate directly via state variables.
Module memory is the most permanent and widely scoped memory provided by the Process Package. A single block of memory can be installed for a module by any process that is owned by that module. Installation is performed by calling the KP op_pro_modmem_install() and passing the address of the memory block. Any process owned by the module can then obtain the installed address by calling the KP op_pro_modmem_access(). The structure and contents of the memory block are entirely the responsibility of the model developer, as is memory deallocation of previously installed blocks when a new installation occurs. Initially the address OPC_NIL is installed to indicate the absence of any module memory.
The parent-to-child memory mechanism supports the communication of data between a process and its parent. Memory can only be installed once, when the child process is created. The address of this memory block is one of the arguments of the KP op_pro_create(). The address of the block can then be obtained by calling the KP op_pro_parmem_access(). As in the case of module memory, the structure of the memory block is entirely user-defined and deallocation of parent-to-child memory is not the responsibility of the Simulation Kernel should either or both of the processes be destroyed.
If a parent process is destroyed using op_pro_destroy_options() or op_pro_destroy(), the child processes remain unaffected; they do not become children of the module’s root process. Future calls to op_pro_parent() for these “orphaned” processes return an invalid handle and a recoverable error. The parent-to-child memory pointer may also point to invalid memory.
Unlike the module and parent-to-child shared-memory mechanisms discussed above, the argument memory mechanism has no persistence in the sense that it is provided on an invocation-by-invocation basis. Each call to the KP op_pro_invoke() provides an opportunity to pass the address of a memory block whose structure and usage is user-defined. This memory provides a way of passing parameters to processes as they are invoked as well as a mechanism for a process to return results to the process that called it. Argument memory is accessed only in the context of the invoked process via the KP op_pro_argmem_access().
By having access to another process’ state variables, a process can communicate via semaphores, monitor execution status, or modify the operation of the remote process. The KP op_pro_svar_get() returns a pointer to a specified state variable in another process, enabling the calling process to access that variable.