doc/manual/helpers.texi
author Tom Henderson <tomh@tomh.org>
Sun, 18 Oct 2009 22:11:29 -0700
changeset 5431 01a657b8d1ef
parent 5426 7b36d173c490
permissions -rw-r--r--
some cleanup of part 1 of manual
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5426
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
@node Helpers
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
@chapter Helpers
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
The above chapters introduced you to various ns-3 programming concepts
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
such as smart pointers for reference-counted memory management, attributes,
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
namespaces, callbacks, etc.   Users who work at this low-level API
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
can interconnect ns-3 objects with fine granulariy.  However, a
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
simulation program written entirely using the low-level API would
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
be quite long and tedious to code.  For this reason, a separate so-called
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
``helper API'' has been overlaid on the core ns-3 API.  If you have read
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
the ns-3 tutorial, you will already be familiar with the helper API,
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
since it is the API that new users are typically introduced to first.
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
In this chapter, we introduce the design philosophy of the helper
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
API and contrast it to the low-level API.  If you become a heavy
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
user of ns-3, you will likely move back and forth between these
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
APIs even in the same program.
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
The helper API has a few goals:
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
@enumerate
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
@item the rest of @code{src/} has no dependencies on the helper API;
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
anything that can be done with the helper API can be coded also at
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    22
the low-level API
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
@item @strong{Containers:}  Often simulations will need to do
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    24
a number of identical actions to groups of objects.  The helper
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    25
API makes heavy use of containers of similar objects to which similar
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
or identical operations can be performed.
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
@item The helper API is not generic; it does not strive to maximize
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    28
code reuse.  So, programming constructs such as polymorphism and
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    29
templates that achieve code reuse are not as prevalent.  For instance,
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    30
there are separate CsmaNetDevice helpers and PointToPointNetDevice
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    31
helpers but they do not derive from a common NetDevice base class.
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    32
@item The helper API typically works with stack-allocated (vs.
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
heap-allocated) objects.  For some programs, ns-3 users may not
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    34
need to worry about any low level Object Create or Ptr handling;
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    35
they can make do with containers of objects and stack-allocated helpers
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    36
that operate on them.
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    37
@end enumerate
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    38
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    39
The helper API is really all about making ns-3 programs easier to
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    40
write and read, without taking away the power of the low-level 
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    41
interface.  The rest of this chapter provides some examples of
7b36d173c490 Manual organization
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    42
the programming conventions of the helper API.