Professional Documents
Culture Documents
Documentation Page Format: 1-Introduction
Documentation Page Format: 1-Introduction
Documentation Page Format: 1-Introduction
1 Introduction
This document serves as a reference for the services provided by the
Simulation Kernel and to the means of accessing these services. For the most
part, the simulation services are accessed through Kernel Procedures (KPs),
which are procedures that can be called from within process models,
Transceiver Pipeline stages, C/C++ functions that have been scheduled as
interrupts, or simply C/C++ functions that are directly or indirectly invoked from
one of these contexts.
KPs are categorized by primary function, based on the types of objects they
attempt to manipulate. The collection of KPs within a category is called a
package, and KPs within the same package share a common package keyword
in their procedure names. For instance, a large number of KPs are concerned
with manipulating packets; these are grouped together in the Packet package
and use the “pk” keyword. Each package has its own section. Sections are
arranged alphabetically, based on the package name.
Banner Displays the name of the KP in large type at the top of the page. The KP banner
includes an empty pair of parentheses (representing the argument list for the
KP).
Abstract Gives a brief synopsis of the KP usage. Most users will begin by browsing this
section when first learning about the KP.
Syntax Displays the calling syntax of the KP using a variation on the standard C/C++
function interface notation. The name of the KP is repeated, this time with a fully
specified argument list. Underneath this first line, the KP arguments are
detailed. Each argument’s name, data type, and description appears in a table.
Additional detailed information describes the techniques used to obtain certain
data types, or the appropriate symbolic constants to use as flag values.
Return Type Gives the data type of the return value of the KP and a short description of the
interpretation and use of the value.
Example Lists C/C++ or Transceiver Pipeline Model statements that show typical usage
of the KP. In some instances, the listing has been specially prepared for this
manual, while in other instances the listing is an excerpt from an example model
supplied with OPNET. Statement that invoke the current KP is in bold typeface.
Details Contains narrative text that explains portions of background modeling theory,
discusses limitations or special considerations of using the KP, and presents
detailed information about the KP internal operations, as needed.
Purpose Contains a less formal discussion of the need for the KP and explains the
primary application of the KP in simulations.
Errors Lists errors that can occur while the current KP is executing. Listed errors might
be controlled (i.e., the detection of special conditions by if statements,
resulting in a specific error message) or uncontrolled (i.e., an operating system
trap which detects a bad memory access).
Reference Lists KPs that are related to the current KP. Related KPs can be inverse in
nature to the current KP, variations on the current KP, or commonly used in
conjunction with the current KP. The goal of this section is to point users in
useful directions when they are looking for a KP to do a specific task.
• Names begin with the prefix op_, which serves to identify KPs as being
provided by the OPNET Simulation Kernel.
• The second word in a KP name is the package name (in lower case letters),
which is usually an abbreviated name of the object that the package
manipulates (e.g., pk, ici, or stat).
• The third word in a name may be a sub-package name (e.g., nfd in the KP
op_pk_nfd_set()), which provides a further categorization of the KP.
Many arguments and return values of KPs are standard C/C++ data types, such
as int, double, and char*.
Besides the basic C/C++ data types, arguments and return values are often
declared to be special OPNET data types. These data types are derived from
simulation data structures via the typedef statement of the C/C++ language.
Although users are involved in manipulating OPNET data types via KPs, and
they become familiar with the basic contents of each data type, the exact
internal structure of the data type need not be of concern. In fact, the contents
of simulation data structures may change in new releases of the software, so it
is good practice to not depend on undocumented internal fields of the data
structures. Each of the special data types are introduced in the following
sections.
• Animation Entities
• Booleans
• Compcodes
• Distributions
• Event Handles
• Statistic Handles
• ICIs
• Lists
• Object IDs
• Packets
• Log Handles
• Procedures
• Process Handles
Animation Entities
The Anim (Animation) package relies on numeric “serial numbers” (IDs) to refer
to specific animation entities involved in operations. Integer IDs are used
instead of C/C++ pointers because the IDs are communicated beyond the
scope of the simulation, to the animation viewer program, op_vuanim. Even
though the IDs are simply integer values, and may be stored in regular C/C++
integer variables, specific data types have been declared to precisely tag ID
arguments and variables. The three animation entities referenced by IDs are
viewers, macros, and drawings; their respective data types are listed below.
Booleans
Booleans are values returned by many Kernel Procedures to indicate a true or
false result. The value of a Boolean can be compared to the symbolic constants
OPC_TRUE and OPC_FALSE.
Compcodes
Compcodes are values returned by many Kernel Procedures that indicate
whether an operation completed successfully. The value of a Compcode may
be compared to the symbolic constants OPC_COMPCODE_SUCCESS and
OPC_COMPCODE_FAILURE.
Distributions
Distributions are data structures that describe the mapping of a random number
into a specific numeric outcome, consistent with a probability density function
(PDF). The distribution can include a numeric table which encodes the mapping,
or it can point to an algorithm which will perform the mapping. For table-based
distributions, the contents data is read in from a PDF model file which has been
prepared using the PDF Editor. These structures are manipulated by the Dist
package KPs.
Event Handles
Event handles are data structures which uniquely identify a pending simulation
event (interrupt). These structures are used by Intrpt Package KPs, so that
scheduled interrupts can be manipulated through their handle. Note that event
handles are actually data structures, and not integers or pointers. Therefore,
they should not be cast into or stored in integer or pointer variables.
Statistic Handles
Statistic handles are data structures used to identify global and local statistics
that are created dynamically. The data type provided for these handles is
Stathandle and the only way to obtain such a handle is by “registering” a statistic
via a KP dedicated to this purpose in the Stat package. A statistic has a unique
name that is specified at registration, and also an output vector used to store its
values over time. Local statistics are used within a specific processor or queue.
Global statistics are typically shared by several different entities in a simulation
model, and each of these entities contributes to the output vector in a distributed
manner.
ICIs
ICIs (Interface Control Information) are collections of structured data associated
with simulation interrupts. They serve as an inter-process communication
mechanism, specialized for conveying information which controls layered
protocol interfaces. These structures are manipulated by Ici package KPs.
Lists
Lists are ordered collections of data elements, stored in a doubly-linked chain.
Elements in lists can range from simple C/C++ data types to complex data
structures. Lists can be heterogeneous, containing collections of varied
elements, but they typically are not. Lists can grow arbitrarily large; elements
can be inserted into or removed from any specified position. Lists are often used
to temporarily store groups of related data structures. These structures are
manipulated by the List sub-package of the Prg package.
Object IDs
An object ID is a numeric “serial number” that uniquely identifies a single
simulation object. The Objid data type is used to declare these identifiers. Objids
are used by the Id, Ima, Topo and Pk packages.
Packets
Packets are the fundamental simulation entity for modeling encapsulation and
transmission of data. These structures are manipulated by Pk package KPs.
Log Handles
When creating simulation logs to aid in simulation debugging or results analysis,
a log handle is necessary for each category of log entry.
Procedures
Several KPs take C/C++ function pointers as arguments. Instead of declaring
these arguments as pointers to functions which return integers, a special data
type has been defined for use in the declarations, called Procedure.
Process Handles
Process handles are data structures which uniquely identify an active process
within a simulation. These structures are used by Pro package KPs, so that
operations can be performed on processes. Process handles are actually data
structures, and not integers or pointers. Therefore, they should not be cast into
or stored in integer or pointer variables.
The function listing builds down, from the top-level function towards the function
in which the error occurred. Thus, in the example, function #10
(sim_err_pk_access()) is associated with the segmentation violation that
caused the program to abort.
Syntax guides for these macros appear below, followed by example functions
that use them. Note that these macros do not need trailing semi-colons (they
include their own) and that the argument to FIN does not require double-quotes
(it also includes its own).
int
sum_three (int a, int b, int c)
{
int sum;
void
pr_banner (char* string)
{
FIN (pr_banner (string))
printf ("-----------\n");
printf ("%s\n", string);
printf ("-----------\n");
FOUT
}
All example models provided with OPNET incorporate these macros, and it is
recommended that user-defined functions incorporate them as well. If FIN,
FOUT, and FRET statements are properly inserted into user-defined functions,
op_vuerr can be used to determine the location of a program error even in a
nested group of model function calls.
WARNING—Do not use the FIN, FOUT, and FRET macros in the main()
function of an EMA or ET program. An abnormal function stack imbalance error
will occur if these macros occur before either prg_init(), Vos_Init(), or Ema_Init()
has been invoked.
The above problem does not manifest itself in process model state variables,
due to the way they are preprocessed into data structure references. However,
process model temporary (local) and header block (global) variables can
override function names, so care must be taken not to choose variable names
which have the same names as functions.
The most common way in which the name overriding problem occurs is not due
to user-defined variable names conflicting with user-defined function names.
Instead, user-defined variable names conflict with short system call function
names that the user is not even aware are being linked into the simulation. The
most likely “conflict list” of function names appears in Table 1-1; users should
avoid duplicating these names for use as variables.
exit() select()
Multi-Threading Safety
Modeler has a parallel simulation kernel that allows simulations to use multiple
processors. To ensure that activities such as the parallel transmission of
packets are performed correctly and as quickly as possible, any code involved
must use multi-threading-safe APIs (Kernel Procedures and PRG functions).
Most KPs and PRG APIs are MT-safe. Those that are not, or that have some
restrictions to their safeness, are identified as such in the API description and
are listed in Table 1-2.
Manual Terminology
This manual incorporates special terminology for discussing the relationships of
KPs and the environment in which they operate. The terminology is not
completely unique to this manual, but it is a slight variation on the general set of
terminology used in the complete documentation set. Several terms are defined
below.
Contexts
There are four contexts in which users can define procedural logic which is
integrated into a simulation. These contexts are fundamentally different in terms
of the resources available to the C/C++ statements which form the procedural
logic. The interface between user-specified C/C++ statements and simulation
resources is provided by Simulation Kernel procedures (KPs), and the four
different contexts each present a different set of limitations on which KPs can
be invoked. Many KPs are usable in all four contexts; exceptions are noted in
the KP documentation within this manual. The four contexts are listed below:
Invoking Process
As mentioned above, a KP can be invoked from one of four different execution
contexts. However, the vast majority of invocations of KPs are from the first two
contexts (i.e., from processes running on processors or queues). In the
documentation pages for KPs, the process that invoked the KP under
discussion is called the invoking process. The invoking process is also
sometimes called the current process.