doc/manual/source/attributes.rst
author Peter D. Barnes, Jr. <barnes26@llnl.gov>
Wed, 17 Jul 2013 17:09:36 -0700
changeset 9957 1a4d84a85bad
parent 9912 d59302c89378
child 10409 4533305686ad
permissions -rw-r--r--
Manual and Tutorial syntax coloring
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
.. include:: replace.txt
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
     2
.. highlight:: cpp
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
     3
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
7662
c13e33e96231 clear warnings in manual build process
Tom Henderson <tomh@tomh.org>
parents: 7548
diff changeset
     5
.. _Attributes:
c13e33e96231 clear warnings in manual build process
Tom Henderson <tomh@tomh.org>
parents: 7548
diff changeset
     6
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
Attributes
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
----------
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
In |ns3| simulations, there are two main aspects to configuration:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
* the simulation topology and how objects are connected 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
* the values used by the models instantiated in the topology
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
This chapter focuses on the second item above: how the many values in use in
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
|ns3| are organized, documented, and modifiable by |ns3| users. The |ns3|
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
attribute system is also the underpinning of how traces and statistics are
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
gathered in the simulator. 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
Before delving into details of the attribute value system, it will help to
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
review some basic properties of class :cpp:class:`ns3::Object`.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
Object Overview
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
***************
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
|ns3| is fundamentally a C++ object-based system. By this we mean that new C++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
classes (types) can be declared, defined, and subclassed as usual.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
Many |ns3| objects inherit from the :cpp:class:`ns3::Object` base class.  These
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
objects have some additional properties that we exploit for organizing the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
system and improving the memory management of our objects:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
* a "metadata" system that links the class name to a lot of meta-information
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
  about the object, including the base class of the subclass, the set of
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
  accessible constructors in the subclass, and the set of "attributes" of the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
  subclass
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    37
* a reference counting smart pointer implementation, for memory management.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    38
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    39
|ns3| objects that use the attribute system derive from either
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    40
:cpp:class:`ns3::Object` or :cpp:class:`ns3::ObjectBase`. Most |ns3| objects we
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    41
will discuss derive from :cpp:class:`ns3::Object`, but a few that are outside
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    42
the smart pointer memory management framework derive from
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    43
:cpp:class:`ns3::ObjectBase`.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    44
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    45
Let's review a couple of properties of these objects.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    46
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    47
Smart pointers
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    48
**************
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    49
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    50
As introduced in the |ns3| tutorial, |ns3| objects are memory managed by a
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    51
`reference counting smart pointer implementation
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    52
<http://en.wikipedia.org/wiki/Smart_pointer>`_, class :cpp:class:`ns3::Ptr`. 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    53
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    54
Smart pointers are used extensively in the |ns3| APIs, to avoid passing
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    55
references to heap-allocated objects that may cause memory leaks.  
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    56
For most basic usage (syntax), treat a smart pointer like a regular pointer:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    57
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    58
  Ptr<WifiNetDevice> nd = ...;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    59
  nd->CallSomeFunction ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    60
  // etc.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    61
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    62
CreateObject
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    63
++++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    64
7662
c13e33e96231 clear warnings in manual build process
Tom Henderson <tomh@tomh.org>
parents: 7548
diff changeset
    65
As we discussed above in :ref:`Memory-management-and-class-Ptr`, at the
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    66
lowest-level API, objects of type :cpp:class:`ns3::Object` are not instantiated
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    67
using ``operator new`` as usual but instead by a templated function called
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    68
:cpp:func:`CreateObject()`.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    69
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    70
A typical way to create such an object is as follows:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    71
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    72
  Ptr<WifiNetDevice> nd = CreateObject<WifiNetDevice> ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    73
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    74
You can think of this as being functionally equivalent to:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    75
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    76
  WifiNetDevice* nd = new WifiNetDevice ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    77
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    78
Objects that derive from :cpp:class:`ns3::Object` must be allocated on the heap
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    79
using CreateObject(). Those deriving from :cpp:class:`ns3::ObjectBase`, such as
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    80
|ns3| helper functions and packet headers and trailers, can be allocated on the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    81
stack.  
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    82
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    83
In some scripts, you may not see a lot of CreateObject() calls in the code; this
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    84
is because there are some helper objects in effect that are doing the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    85
CreateObject()s for you.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    86
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    87
TypeId
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    88
++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    89
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    90
|ns3| classes that derive from class ns3::Object can include a metadata class
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    91
called ``TypeId`` that records meta-information about the class, for use in the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    92
object aggregation and component manager systems:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    93
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    94
* a unique string identifying the class
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    95
* the base class of the subclass, within the metadata system
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    96
* the set of accessible constructors in the subclass
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    97
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    98
Object Summary
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    99
++++++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   100
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   101
Putting all of these concepts together, let's look at a specific
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   102
example: class :cpp:class:`ns3::Node`.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   103
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   104
The public header file node.h has a declaration that includes a static GetTypeId
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   105
function call:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   106
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   107
    class Node : public Object
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   108
    {
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   109
    public:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   110
      static TypeId GetTypeId (void);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   111
      ...
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   112
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   113
This is defined in the ``node.cc`` file as follows:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   114
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   115
    TypeId 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   116
    Node::GetTypeId (void)
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   117
    {
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   118
      static TypeId tid = TypeId ("ns3::Node")
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   119
        .SetParent<Object> ()
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   120
        .AddConstructor<Node> ()
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   121
        .AddAttribute ("DeviceList", "The list of devices associated to this Node.",
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   122
                       ObjectVectorValue (),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   123
                       MakeObjectVectorAccessor (&Node::m_devices),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   124
                       MakeObjectVectorChecker<NetDevice> ())
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   125
        .AddAttribute ("ApplicationList", "The list of applications associated to this Node.",
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   126
                       ObjectVectorValue (),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   127
                       MakeObjectVectorAccessor (&Node::m_applications),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   128
                       MakeObjectVectorChecker<Application> ())
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   129
        .AddAttribute ("Id", "The id (unique integer) of this Node.",
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   130
                       TypeId::ATTR_GET, // allow only getting it.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   131
                       UintegerValue (0),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   132
                       MakeUintegerAccessor (&Node::m_id),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   133
                       MakeUintegerChecker<uint32_t> ())
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   134
        ;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   135
      return tid;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   136
    }
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   137
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   138
Consider the TypeId of an |ns3| ``Object`` class as an extended form of run time
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   139
type information (RTTI). The C++ language includes a simple kind of RTTI in
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   140
order to support ``dynamic_cast`` and ``typeid`` operators.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   141
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   142
The "``.SetParent<Object> ()``" call in the declaration above is used in
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   143
conjunction with our object aggregation mechanisms to allow safe up- and
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   144
down-casting in inheritance trees during ``GetObject``.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   145
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   146
The "``.AddConstructor<Node> ()``" call is used in conjunction with our abstract
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   147
object factory mechanisms to allow us to construct C++ objects without forcing a
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   148
user to know the concrete class of the object she is building.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   149
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   150
The three calls to "``.AddAttribute``" associate a given string with a strongly
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   151
typed value in the class. Notice that you must provide a help string which may
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   152
be displayed, for example, via command line processors. Each ``Attribute`` is
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   153
associated with mechanisms for accessing the underlying member variable in the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   154
object (for example, ``MakeUintegerAccessor`` tells the generic ``Attribute``
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   155
code how to get to the node ID above). There are also "Checker" methods which
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   156
are used to validate values.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   157
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   158
When users want to create Nodes, they will usually call some form of 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   159
``CreateObject``,::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   160
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   161
    Ptr<Node> n = CreateObject<Node> ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   162
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   163
or more abstractly, using an object factory, you can create a ``Node`` object
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   164
without even knowing the concrete C++ type::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   165
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   166
    ObjectFactory factory;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   167
    const std::string typeId = "ns3::Node'';
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   168
    factory.SetTypeId (typeId);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   169
    Ptr<Object> node = factory.Create <Object> ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   170
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   171
Both of these methods result in fully initialized attributes being available 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   172
in the resulting ``Object`` instances.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   173
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   174
We next discuss how attributes (values associated with member variables or
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   175
functions of the class) are plumbed into the above TypeId.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   176
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   177
Attribute Overview
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   178
******************
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   179
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   180
The goal of the attribute system is to organize the access of
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   181
internal member objects of a simulation. This goal arises because,
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   182
typically in simulation, users will cut and paste/modify existing
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   183
simulation scripts, or will use higher-level simulation constructs,
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   184
but often will be interested in studying or tracing particular 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   185
internal variables.  For instance, use cases such as:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   186
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   187
* "I want to trace the packets on the wireless interface only on the first
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   188
  access point"
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   189
* "I want to trace the value of the TCP congestion window (every time it
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   190
  changes) on a particular TCP socket"
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   191
* "I want a dump of all values that were used in my simulation."
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   192
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   193
Similarly, users may want fine-grained access to internal variables in the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   194
simulation, or may want to broadly change the initial value used for a
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   195
particular parameter in all subsequently created objects. Finally, users may
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   196
wish to know what variables are settable and retrievable in a simulation
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   197
configuration. This is not just for direct simulation interaction on the command
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   198
line; consider also a (future) graphical user interface that would like to be
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   199
able to provide a feature whereby a user might right-click on an node on the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   200
canvas and see a hierarchical, organized list of parameters that are settable on
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   201
the node and its constituent member objects, and help text and default values
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   202
for each parameter.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   203
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   204
Functional overview
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   205
+++++++++++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   206
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   207
We provide a way for users to access values deep in the system, without having
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   208
to plumb accessors (pointers) through the system and walk pointer chains to get
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   209
to them. Consider a class DropTailQueue that has a member variable that is an
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   210
unsigned integer ``m_maxPackets``; this member variable controls the depth of
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   211
the queue.  
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   212
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   213
If we look at the declaration of DropTailQueue, we see the following:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   214
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   215
    class DropTailQueue : public Queue {
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   216
    public:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   217
      static TypeId GetTypeId (void);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   218
      ...
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   219
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   220
    private:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   221
      std::queue<Ptr<Packet> > m_packets;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   222
      uint32_t m_maxPackets;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   223
    };
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   224
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   225
Let's consider things that a user may want to do with the value of
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   226
m_maxPackets:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   227
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   228
* Set a default value for the system, such that whenever a new DropTailQueue is
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   229
  created, this member is initialized to that default. 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   230
* Set or get the value on an already instantiated queue.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   231
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   232
The above things typically require providing Set() and Get() functions, and some
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   233
type of global default value.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   234
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   235
In the |ns3| attribute system, these value definitions and accessor functions
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   236
are moved into the TypeId class; e.g.:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   237
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   238
    NS_OBJECT_ENSURE_REGISTERED (DropTailQueue);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   239
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   240
    TypeId DropTailQueue::GetTypeId (void) 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   241
    {
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   242
      static TypeId tid = TypeId ("ns3::DropTailQueue")
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   243
        .SetParent<Queue> ()
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   244
        .AddConstructor<DropTailQueue> ()
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   245
        .AddAttribute ("MaxPackets", 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   246
                       "The maximum number of packets accepted by this DropTailQueue.",
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   247
                       UintegerValue (100),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   248
                       MakeUintegerAccessor (&DropTailQueue::m_maxPackets),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   249
                       MakeUintegerChecker<uint32_t> ())
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   250
        ;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   251
      
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   252
      return tid;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   253
    }
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   254
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   255
The AddAttribute() method is performing a number of things with this
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   256
value:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   257
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   258
* Binding the variable m_maxPackets to a string "MaxPackets"
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   259
* Providing a default value (100 packets)
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   260
* Providing some help text defining the value
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   261
* Providing a "checker" (not used in this example) that can be used to set
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   262
  bounds on the allowable range of values
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   263
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   264
The key point is that now the value of this variable and its default value are
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   265
accessible in the attribute namespace, which is based on strings such as
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   266
"MaxPackets" and TypeId strings. In the next section, we will provide an example
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   267
script that shows how users may manipulate these values.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   268
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   269
Note that initialization of the attribute relies on the macro
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   270
``NS_OBJECT_ENSURE_REGISTERED`` (DropTailQueue) being called; if you leave this
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   271
out of your new class implementation, your attributes will not be initialized
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   272
correctly.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   273
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   274
While we have described how to create attributes, we still haven't described how
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   275
to access and manage these values. For instance, there is no ``globals.h``
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   276
header file where these are stored; attributes are stored with their classes.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   277
Questions that naturally arise are how do users easily learn about all of the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   278
attributes of their models, and how does a user access these attributes, or
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   279
document their values as part of the record of their simulation?
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   280
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   281
Default values and command-line arguments
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   282
+++++++++++++++++++++++++++++++++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   283
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   284
Let's look at how a user script might access these values.  
7548
e8cd72402e69 Bug 962 - list of paths to reach objects contains bogus entries
Mitch Watrous <watrous@u.washington.edu>
parents: 7438
diff changeset
   285
This is based on the script found at ``src/point-to-point/examples/main-attribute-value.cc``,
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   286
with some details stripped out.::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   287
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   288
    //
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   289
    // This is a basic example of how to use the attribute system to
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   290
    // set and get a value in the underlying system; namely, an unsigned
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   291
    // integer of the maximum number of packets in a queue
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   292
    //
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   293
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   294
    int 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   295
    main (int argc, char *argv[])
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   296
    {
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   297
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   298
      // By default, the MaxPackets attribute has a value of 100 packets
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   299
      // (this default can be observed in the function DropTailQueue::GetTypeId)
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   300
      // 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   301
      // Here, we set it to 80 packets.  We could use one of two value types:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   302
      // a string-based value or a Uinteger value
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   303
      Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("80"));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   304
      // The below function call is redundant
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   305
      Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (80));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   306
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   307
      // Allow the user to override any of the defaults and the above
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   308
      // SetDefaults() at run-time, via command-line arguments
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   309
      CommandLine cmd;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   310
      cmd.Parse (argc, argv);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   311
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   312
The main thing to notice in the above are the two calls to 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   313
``Config::SetDefault``.  This is how we set the default value
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   314
for all subsequently instantiated DropTailQueues.  We illustrate
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   315
that two types of Value classes, a StringValue and a UintegerValue class,
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   316
can be used to assign the value to the attribute named by
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   317
"ns3::DropTailQueue::MaxPackets".
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   318
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   319
Now, we will create a few objects using the low-level API; here,
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   320
our newly created queues will not have a m_maxPackets initialized to
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   321
100 packets but to 80 packets, because of what we did above with
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   322
default values.::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   323
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   324
    Ptr<Node> n0 = CreateObject<Node> ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   325
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   326
    Ptr<PointToPointNetDevice> net0 = CreateObject<PointToPointNetDevice> ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   327
    n0->AddDevice (net0);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   328
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   329
    Ptr<Queue> q = CreateObject<DropTailQueue> ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   330
    net0->AddQueue(q);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   331
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   332
At this point, we have created a single node (Node 0) and a single
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   333
PointToPointNetDevice (NetDevice 0) and added a DropTailQueue to it.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   334
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   335
Now, we can manipulate the MaxPackets value of the already instantiated
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   336
DropTailQueue. Here are various ways to do that.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   337
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   338
Pointer-based access
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   339
++++++++++++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   340
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   341
We assume that a smart pointer (Ptr) to a relevant network device is in hand; in
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   342
the current example, it is the ``net0`` pointer. 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   343
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   344
One way to change the value is to access a pointer to the underlying queue and
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   345
modify its attribute.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   346
 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   347
First, we observe that we can get a pointer to the (base class) queue via the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   348
PointToPointNetDevice attributes, where it is called TxQueue::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   349
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   350
    PointerValue tmp;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   351
    net0->GetAttribute ("TxQueue", tmp);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   352
    Ptr<Object> txQueue = tmp.GetObject ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   353
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   354
Using the GetObject function, we can perform a safe downcast to a DropTailQueue,
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   355
where MaxPackets is a member::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   356
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   357
    Ptr<DropTailQueue> dtq = txQueue->GetObject <DropTailQueue> ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   358
    NS_ASSERT (dtq != 0);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   359
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   360
Next, we can get the value of an attribute on this queue.  We have introduced
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   361
wrapper "Value" classes for the underlying data types, similar to Java wrappers
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   362
around these types, since the attribute system stores values and not disparate
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   363
types.  Here, the attribute value is assigned to a UintegerValue, and the Get()
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   364
method on this value produces the (unwrapped) uint32_t.::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   365
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   366
    UintegerValue limit;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   367
    dtq->GetAttribute ("MaxPackets", limit);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   368
    NS_LOG_INFO ("1.  dtq limit: " << limit.Get () << " packets");
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   369
  
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   370
Note that the above downcast is not really needed; we could have done the same
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   371
using the Ptr<Queue> even though the attribute is a member of the subclass::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   372
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   373
    txQueue->GetAttribute ("MaxPackets", limit);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   374
    NS_LOG_INFO ("2.  txQueue limit: " << limit.Get () << " packets");
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   375
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   376
Now, let's set it to another value (60 packets)::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   377
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   378
    txQueue->SetAttribute("MaxPackets", UintegerValue (60));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   379
    txQueue->GetAttribute ("MaxPackets", limit);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   380
    NS_LOG_INFO ("3.  txQueue limit changed: " << limit.Get () << " packets");
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   381
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   382
Namespace-based access
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   383
++++++++++++++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   384
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   385
An alternative way to get at the attribute is to use the configuration
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   386
namespace.  Here, this attribute resides on a known path in this namespace; this
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   387
approach is useful if one doesn't have access to the underlying pointers and
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   388
would like to configure a specific attribute with a single statement.::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   389
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   390
    Config::Set ("/NodeList/0/DeviceList/0/TxQueue/MaxPackets", UintegerValue (25));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   391
    txQueue->GetAttribute ("MaxPackets", limit); 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   392
    NS_LOG_INFO ("4.  txQueue limit changed through namespace: " << 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   393
        limit.Get () << " packets");
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   394
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   395
We could have also used wildcards to set this value for all nodes and all net
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   396
devices (which in this simple example has the same effect as the previous
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   397
Set())::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   398
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   399
    Config::Set ("/NodeList/*/DeviceList/*/TxQueue/MaxPackets", UintegerValue (15));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   400
    txQueue->GetAttribute ("MaxPackets", limit); 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   401
    NS_LOG_INFO ("5.  txQueue limit changed through wildcarded namespace: " << 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   402
        limit.Get () << " packets");
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   403
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   404
Object Name Service-based access
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   405
++++++++++++++++++++++++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   406
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   407
Another way to get at the attribute is to use the object name service facility.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   408
Here, this attribute is found using a name string. This approach is useful if
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   409
one doesn't have access to the underlying pointers and it is difficult to
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   410
determine the required concrete configuration namespaced path.
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   411
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   412
::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   413
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   414
    Names::Add ("server", serverNode);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   415
    Names::Add ("server/eth0", serverDevice);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   416
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   417
    ...
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   418
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   419
    Config::Set ("/Names/server/eth0/TxQueue/MaxPackets", UintegerValue (25));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   420
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   421
See :ref:`Object-names` for a fuller treatment of the |ns3| configuration namespace.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   422
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   423
Setting through constructors helper classes
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   424
+++++++++++++++++++++++++++++++++++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   425
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   426
Arbitrary combinations of attributes can be set and fetched from
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   427
the helper and low-level APIs; either from the constructors themselves:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   428
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   429
    Ptr<Object> p = CreateObject<MyNewObject> ("n1", v1, "n2", v2, ...);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   430
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   431
or from the higher-level helper APIs, such as:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   432
9912
d59302c89378 fix typo in attributes section of manual
Junling Bu <linlinjavaer@gmail.com>
parents: 9698
diff changeset
   433
    mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   434
                                   "MinX", DoubleValue (-100.0),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   435
                                   "MinY", DoubleValue (-100.0),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   436
                                   "DeltaX", DoubleValue (5.0),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   437
                                   "DeltaY", DoubleValue (20.0),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   438
                                   "GridWidth", UintegerValue (20),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   439
                                   "LayoutType", StringValue ("RowFirst"));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   440
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   441
Implementation details
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   442
++++++++++++++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   443
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   444
Value classes
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   445
~~~~~~~~~~~~~
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   446
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   447
Readers will note the new FooValue classes which are subclasses of the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   448
AttributeValue base class. These can be thought of as an intermediate class that
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   449
can be used to convert from raw types to the Values that are used by the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   450
attribute system. Recall that this database is holding objects of many types
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   451
with a single generic type. Conversions to this type can either be done using an
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   452
intermediate class (IntegerValue, DoubleValue for "floating point") or via
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   453
strings. Direct implicit conversion of types to Value is not really practical.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   454
So in the above, users have a choice of using strings or values:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   455
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   456
    p->Set ("cwnd", StringValue ("100")); // string-based setter
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   457
    p->Set ("cwnd", IntegerValue (100)); // integer-based setter
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   458
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   459
The system provides some macros that help users declare and define
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   460
new AttributeValue subclasses for new types that they want to introduce into
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   461
the attribute system: 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   462
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   463
* ATTRIBUTE_HELPER_HEADER
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   464
* ATTRIBUTE_HELPER_CPP
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   465
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   466
Initialization order
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   467
~~~~~~~~~~~~~~~~~~~~
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   468
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   469
Attributes in the system must not depend on the state of any other Attribute in
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   470
this system. This is because an ordering of Attribute initialization is not
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   471
specified, nor enforced, by the system. A specific example of this can be seen
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   472
in automated configuration programs such as :cpp:class:`ns3::ConfigStore`.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   473
Although a given model may arrange it so that Attributes are initialized in a
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   474
particular order, another automatic configurator may decide independently to
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   475
change Attributes in, for example, alphabetic order.  
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   476
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   477
Because of this non-specific ordering, no Attribute in the system may have any
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   478
dependence on any other Attribute. As a corollary, Attribute setters must never
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   479
fail due to the state of another Attribute. No Attribute setter may change (set)
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   480
any other Attribute value as a result of changing its value.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   481
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   482
This is a very strong restriction and there are cases where Attributes must set
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   483
consistently to allow correct operation. To this end we do allow for consistency
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   484
checking *when the attribute is used* (cf. NS_ASSERT_MSG or NS_ABORT_MSG).
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   485
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   486
In general, the attribute code to assign values to the underlying class member
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   487
variables is executed after an object is constructed. But what if you need the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   488
values assigned before the constructor body executes, because you need them in
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   489
the logic of the constructor? There is a way to do this, used for example in the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   490
class :cpp:class:`ns3::ConfigStore`: call ``ObjectBase::ConstructSelf ()`` as
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   491
follows:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   492
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   493
    ConfigStore::ConfigStore ()
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   494
    {
7818
2a5c861ec2ee typo in manual
Tom Henderson <tomh@tomh.org>
parents: 7662
diff changeset
   495
      ObjectBase::ConstructSelf (AttributeConstructionList ());
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   496
      // continue on with constructor.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   497
    }
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   498
9698
9d91a3c643b2 Bug 1601 RttEstimator doesn't set m_currentEstimatedRtt fix
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9162
diff changeset
   499
Beware that the object and all its derived classes must also implement a 
9d91a3c643b2 Bug 1601 RttEstimator doesn't set m_currentEstimatedRtt fix
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9162
diff changeset
   500
``virtual TypeId GetInstanceTypeId (void) const;`` method. Otherwise the
9d91a3c643b2 Bug 1601 RttEstimator doesn't set m_currentEstimatedRtt fix
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9162
diff changeset
   501
``ObjectBase::ConstructSelf ()`` will not be able to read the attributes.
9d91a3c643b2 Bug 1601 RttEstimator doesn't set m_currentEstimatedRtt fix
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9162
diff changeset
   502
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   503
Extending attributes
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   504
********************
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   505
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   506
The |ns3| system will place a number of internal values under the attribute
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   507
system, but undoubtedly users will want to extend this to pick up ones we have
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   508
missed, or to add their own classes to this.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   509
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   510
Adding an existing internal variable to the metadata system 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   511
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   512
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   513
Consider this variable in class TcpSocket:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   514
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   515
    uint32_t m_cWnd;   // Congestion window
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   516
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   517
Suppose that someone working with TCP wanted to get or set the value of that
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   518
variable using the metadata system. If it were not already provided by |ns3|,
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   519
the user could declare the following addition in the runtime metadata system (to
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   520
the TypeId declaration for TcpSocket):::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   521
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   522
    .AddAttribute ("Congestion window", 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   523
                   "Tcp congestion window (bytes)",
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   524
                   UintegerValue (1),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   525
                   MakeUintegerAccessor (&TcpSocket::m_cWnd),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   526
                   MakeUintegerChecker<uint16_t> ())
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   527
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   528
Now, the user with a pointer to the TcpSocket can perform operations such as
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   529
setting and getting the value, without having to add these functions explicitly.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   530
Furthermore, access controls can be applied, such as allowing the parameter to
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   531
be read and not written, or bounds checking on the permissible values can be
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   532
applied.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   533
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   534
Adding a new TypeId
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   535
+++++++++++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   536
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   537
Here, we discuss the impact on a user who wants to add a new class to |ns3|;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   538
what additional things must be done to hook it into this system.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   539
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   540
We've already introduced what a TypeId definition looks like:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   541
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   542
    TypeId
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   543
    RandomWalk2dMobilityModel::GetTypeId (void)
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   544
    {
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   545
      static TypeId tid = TypeId ("ns3::RandomWalk2dMobilityModel")
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   546
        .SetParent<MobilityModel> ()
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   547
        .SetGroupName ("Mobility")
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   548
        .AddConstructor<RandomWalk2dMobilityModel> ()
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   549
        .AddAttribute ("Bounds",
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   550
                       "Bounds of the area to cruise.",
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   551
                       RectangleValue (Rectangle (0.0, 0.0, 100.0, 100.0)),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   552
                       MakeRectangleAccessor (&RandomWalk2dMobilityModel::m_bounds),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   553
                       MakeRectangleChecker ())
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   554
        .AddAttribute ("Time",
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   555
                       "Change current direction and speed after moving for this delay.",
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   556
                       TimeValue (Seconds (1.0)),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   557
                       MakeTimeAccessor (&RandomWalk2dMobilityModel::m_modeTime),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   558
                       MakeTimeChecker ())
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   559
        // etc (more parameters).
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   560
        ;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   561
      return tid;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   562
    }
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   563
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   564
The declaration for this in the class declaration is one-line public member
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   565
method:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   566
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   567
    public:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   568
      static TypeId GetTypeId (void);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   569
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   570
Typical mistakes here involve:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   571
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   572
* Not calling the SetParent method or calling it with the wrong type
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   573
* Not calling the AddConstructor method of calling it with the wrong type
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   574
* Introducing a typographical error in the name of the TypeId in its constructor
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   575
* Not using the fully-qualified c++ typename of the enclosing c++ class as the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   576
  name of the TypeId
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   577
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   578
None of these mistakes can be detected by the |ns3| codebase so, users
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   579
are advised to check carefully multiple times that they got these right.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   580
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   581
Adding new class type to the attribute system
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   582
*********************************************
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   583
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   584
From the perspective of the user who writes a new class in the system and wants
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   585
to hook it in to the attribute system, there is mainly the matter of writing the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   586
conversions to/from strings and attribute values.  Most of this can be
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   587
copy/pasted with macro-ized code.  For instance, consider class declaration for
7148
6fc89f1818e8 Fix even more paths in the documentation
Mitch Watrous <watrous@u.washington.edu>
parents: 7145
diff changeset
   588
Rectangle in the ``src/mobility/model`` directory:
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   589
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   590
Header file
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   591
+++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   592
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   593
::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   594
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   595
    /**
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   596
     * \brief a 2d rectangle
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   597
     */
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   598
    class Rectangle
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   599
    {
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   600
      ...
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   601
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   602
      double xMin;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   603
      double xMax;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   604
      double yMin;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   605
      double yMax;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   606
    };
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   607
 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   608
One macro call and two operators, must be added below the class declaration in
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   609
order to turn a Rectangle into a value usable by the ``Attribute`` system:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   610
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   611
    std::ostream &operator << (std::ostream &os, const Rectangle &rectangle);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   612
    std::istream &operator >> (std::istream &is, Rectangle &rectangle);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   613
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   614
    ATTRIBUTE_HELPER_HEADER (Rectangle);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   615
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   616
Implementation file
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   617
+++++++++++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   618
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   619
In the class definition (``.cc`` file), the code looks like this:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   620
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   621
    ATTRIBUTE_HELPER_CPP (Rectangle);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   622
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   623
    std::ostream &
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   624
    operator << (std::ostream &os, const Rectangle &rectangle)
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   625
    {
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   626
      os << rectangle.xMin << "|" << rectangle.xMax << "|" << rectangle.yMin << "|"
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   627
         << rectangle.yMax;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   628
      return os;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   629
    }
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   630
    std::istream &
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   631
    operator >> (std::istream &is, Rectangle &rectangle)
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   632
     {
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   633
      char c1, c2, c3;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   634
      is >> rectangle.xMin >> c1 >> rectangle.xMax >> c2 >> rectangle.yMin >> c3 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   635
         >> rectangle.yMax;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   636
      if (c1 != '|' ||
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   637
          c2 != '|' ||
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   638
          c3 != '|')
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   639
        {
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   640
          is.setstate (std::ios_base::failbit);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   641
        }
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   642
      return is;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   643
    }
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   644
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   645
These stream operators simply convert from a string representation of the
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   646
Rectangle ("xMin|xMax|yMin|yMax") to the underlying Rectangle, and the modeler
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   647
must specify these operators and the string syntactical representation of an
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   648
instance of the new class.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   649
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   650
ConfigStore
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   651
***********
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   652
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   653
The ConfigStore is a specialized database for attribute values and 
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   654
default values.  Although it is a separately maintained module in
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   655
``src/config-store/`` directory, we document it here because of its 
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   656
sole dependency on |ns3| core module and attributes.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   657
7145
a925e518220b Rescan wifi's bindings and fix some paths in the documentation
Mitch Watrous <watrous@u.washington.edu>
parents: 7025
diff changeset
   658
Values for |ns3| attributes can be stored in an ASCII or XML text file
a925e518220b Rescan wifi's bindings and fix some paths in the documentation
Mitch Watrous <watrous@u.washington.edu>
parents: 7025
diff changeset
   659
and loaded into a future simulation.  This feature is known as the
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   660
|ns3| ConfigStore.  We can explore this system by using an example from
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   661
``src/config-store/examples/config-store-save.cc``.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   662
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   663
First, all users must include the following statement:::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   664
6941
9d2c79c992d7 Split contrib module into config-store and tools
Mitch Watrous <watrous@u.washington.edu>
parents: 6766
diff changeset
   665
    #include "ns3/config-store-module.h"
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   666
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   667
Next, this program adds a sample object A to show how the system
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   668
is extended:::
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   669
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   670
    class A : public Object
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   671
    {
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   672
    public:
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   673
      static TypeId GetTypeId (void) {
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   674
        static TypeId tid = TypeId ("ns3::A")
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   675
          .SetParent<Object> ()
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   676
          .AddAttribute ("TestInt16", "help text",
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   677
                         IntegerValue (-2),
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   678
                         MakeIntegerAccessor (&A::m_int16),
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   679
                         MakeIntegerChecker<int16_t> ())
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   680
          ;
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   681
          return tid;
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   682
        }
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   683
      int16_t m_int16;
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   684
    };
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   685
    
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   686
    NS_OBJECT_ENSURE_REGISTERED (A);
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   687
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   688
Next, we use the Config subsystem to override the defaults in a couple of
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   689
ways:::
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   690
     
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   691
      Config::SetDefault ("ns3::A::TestInt16", IntegerValue (-5));
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   692
    
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   693
      Ptr<A> a_obj = CreateObject<A> ();
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   694
      NS_ABORT_MSG_UNLESS (a_obj->m_int16 == -5, "Cannot set A's integer attribute via Config::SetDefault");
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   695
    
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   696
      Ptr<A> a2_obj = CreateObject<A> ();
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   697
      a2_obj->SetAttribute ("TestInt16", IntegerValue (-3));
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   698
      IntegerValue iv;
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   699
      a2_obj->GetAttribute ("TestInt16", iv);
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   700
      NS_ABORT_MSG_UNLESS (iv.Get () == -3, "Cannot set A's integer attribute via SetAttribute");
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   701
    
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   702
The next statement is necessary to make sure that (one of) the objects
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   703
created is rooted in the configuration namespace as an object instance.
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   704
This normally happens when you aggregate objects to ns3::Node or ns3::Channel
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   705
but here, since we are working at the core level, we need to create a
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   706
new root namespace object:::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   707
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   708
      Config::RegisterRootNamespaceObject (a2_obj);
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   709
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   710
Next, we want to output the configuration store.  The examples show how
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   711
to do it in two formats, XML and raw text.  In practice, one should perform
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   712
this step just before calling ``Simulator::Run ()``;  it will allow the
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   713
configuration to be saved just before running the simulation.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   714
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   715
There are three attributes that govern the behavior of the ConfigStore: "Mode",
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   716
"Filename", and "FileFormat".  The Mode (default "None") configures whether
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   717
|ns3| should load configuration from a previously saved file (specify
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   718
"Mode=Load") or save it to a file (specify "Mode=Save").  The Filename (default
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   719
"") is where the ConfigStore should store its output data.  The FileFormat
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   720
(default "RawText") governs whether the ConfigStore format is Xml or RawText
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   721
format.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   722
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   723
The example shows:::
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   724
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   725
      Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("output-attributes.xml"));
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   726
      Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   727
      Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   728
      ConfigStore outputConfig;
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   729
      outputConfig.ConfigureDefaults ();
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   730
      outputConfig.ConfigureAttributes ();
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   731
    
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   732
      // Output config store to txt format
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   733
      Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("output-attributes.txt"));
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   734
      Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("RawText"));
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   735
      Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   736
      ConfigStore outputConfig2;
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   737
      outputConfig2.ConfigureDefaults ();
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   738
      outputConfig2.ConfigureAttributes ();
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   739
    
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   740
      Simulator::Run ();
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   741
    
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   742
      Simulator::Destroy ();
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   743
    
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   744
After running, you can open the output-attributes.txt file and see:
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   745
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   746
.. sourcecode:: text
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   747
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   748
    default ns3::RealtimeSimulatorImpl::SynchronizationMode "BestEffort"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   749
    default ns3::RealtimeSimulatorImpl::HardLimit "+100000000.0ns"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   750
    default ns3::PcapFileWrapper::CaptureSize "65535"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   751
    default ns3::PacketSocket::RcvBufSize "131072"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   752
    default ns3::ErrorModel::IsEnabled "true"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   753
    default ns3::RateErrorModel::ErrorUnit "EU_BYTE"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   754
    default ns3::RateErrorModel::ErrorRate "0"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   755
    default ns3::RateErrorModel::RanVar "Uniform:0:1"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   756
    default ns3::DropTailQueue::Mode "Packets"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   757
    default ns3::DropTailQueue::MaxPackets "100"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   758
    default ns3::DropTailQueue::MaxBytes "6553500"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   759
    default ns3::Application::StartTime "+0.0ns"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   760
    default ns3::Application::StopTime "+0.0ns"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   761
    default ns3::ConfigStore::Mode "Save"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   762
    default ns3::ConfigStore::Filename "output-attributes.txt"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   763
    default ns3::ConfigStore::FileFormat "RawText"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   764
    default ns3::A::TestInt16 "-5"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   765
    global RngSeed "1"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   766
    global RngRun "1"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   767
    global SimulatorImplementationType "ns3::DefaultSimulatorImpl"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   768
    global SchedulerType "ns3::MapScheduler"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   769
    global ChecksumEnabled "false"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   770
    value /$ns3::A/TestInt16 "-3"
6766
4caf532b12c3 formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 6751
diff changeset
   771
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   772
In the above, all of the default values for attributes for the core 
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   773
module are shown.  Then, all the values for the |ns3| global values
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   774
are recorded.  Finally, the value of the instance of A that was rooted
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   775
in the configuration namespace is shown.  In a real ns-3 program, many
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   776
more models, attributes, and defaults would be shown.
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   777
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   778
An XML version also exists in ``output-attributes.xml``:
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   779
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   780
.. sourcecode:: xml
6766
4caf532b12c3 formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 6751
diff changeset
   781
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   782
    <?xml version="1.0" encoding="UTF-8"?>
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   783
    <ns3>
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   784
     <default name="ns3::RealtimeSimulatorImpl::SynchronizationMode" value="BestEffort"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   785
     <default name="ns3::RealtimeSimulatorImpl::HardLimit" value="+100000000.0ns"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   786
     <default name="ns3::PcapFileWrapper::CaptureSize" value="65535"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   787
     <default name="ns3::PacketSocket::RcvBufSize" value="131072"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   788
     <default name="ns3::ErrorModel::IsEnabled" value="true"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   789
     <default name="ns3::RateErrorModel::ErrorUnit" value="EU_BYTE"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   790
     <default name="ns3::RateErrorModel::ErrorRate" value="0"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   791
     <default name="ns3::RateErrorModel::RanVar" value="Uniform:0:1"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   792
     <default name="ns3::DropTailQueue::Mode" value="Packets"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   793
     <default name="ns3::DropTailQueue::MaxPackets" value="100"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   794
     <default name="ns3::DropTailQueue::MaxBytes" value="6553500"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   795
     <default name="ns3::Application::StartTime" value="+0.0ns"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   796
     <default name="ns3::Application::StopTime" value="+0.0ns"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   797
     <default name="ns3::ConfigStore::Mode" value="Save"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   798
     <default name="ns3::ConfigStore::Filename" value="output-attributes.xml"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   799
     <default name="ns3::ConfigStore::FileFormat" value="Xml"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   800
     <default name="ns3::A::TestInt16" value="-5"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   801
     <global name="RngSeed" value="1"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   802
     <global name="RngRun" value="1"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   803
     <global name="SimulatorImplementationType" value="ns3::DefaultSimulatorImpl"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   804
     <global name="SchedulerType" value="ns3::MapScheduler"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   805
     <global name="ChecksumEnabled" value="false"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   806
     <value path="/$ns3::A/TestInt16" value="-3"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   807
    </ns3>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   808
    
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   809
This file can be archived with your simulation script and output data.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   810
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   811
While it is possible to generate a sample config file and lightly edit it to
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   812
change a couple of values, there are cases where this process will not work
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   813
because the same value on the same object can appear multiple times in the same
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   814
automatically-generated configuration file under different configuration paths.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   815
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   816
As such, the best way to use this class is to use it to generate an initial
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   817
configuration file, extract from that configuration file only the strictly
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   818
necessary elements, and move these minimal elements to a new configuration file
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   819
which can then safely be edited and loaded in a subsequent simulation run. 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   820
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   821
When the ConfigStore object is instantiated, its attributes Filename, Mode, and
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   822
FileFormat must be set, either via command-line or via program statements.  
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   823
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   824
As a more complicated example, let's assume that we want to read in a
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   825
configuration of defaults from an input file named "input-defaults.xml", and
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   826
write out the resulting attributes to a separate file called
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   827
"output-attributes.xml".  (Note-- to get this input xml file to begin with, it
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   828
is sometimes helpful to run the program to generate an output xml file first,
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   829
then hand-edit that file and re-input it for the next simulation run).::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   830
6941
9d2c79c992d7 Split contrib module into config-store and tools
Mitch Watrous <watrous@u.washington.edu>
parents: 6766
diff changeset
   831
    #include "ns3/config-store-module.h"
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   832
    ...
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   833
    int main (...)
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   834
    {
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   835
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   836
      Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("input-defaults.xml"));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   837
      Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Load"));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   838
      Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   839
      ConfigStore inputConfig;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   840
      inputConfig.ConfigureDefaults ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   841
      
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   842
      //
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   843
      // Allow the user to override any of the defaults and the above Bind() at
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   844
      // run-time, via command-line arguments
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   845
      //
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   846
      CommandLine cmd;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   847
      cmd.Parse (argc, argv);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   848
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   849
      // setup topology
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   850
      ...
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   851
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   852
      // Invoke just before entering Simulator::Run ()
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   853
      Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("output-attributes.xml"));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   854
      Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   855
      ConfigStore outputConfig;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   856
      outputConfig.ConfigureAttributes ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   857
      Simulator::Run ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   858
    }
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   859
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   860
GTK-based ConfigStore
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   861
+++++++++++++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   862
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   863
There is a GTK-based front end for the ConfigStore.  This allows users to use a
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   864
GUI to access and change variables.  Screenshots of this feature are available
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   865
in the `|ns3| Overview <http://www.nsnam.org/docs/ns-3-overview.pdf>`_
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   866
presentation.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   867
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   868
To use this feature, one must install libgtk and libgtk-dev; an example
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   869
Ubuntu installation command is:
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   870
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   871
.. sourcecode:: bash
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   872
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   873
  $ sudo apt-get install libgtk2.0-0 libgtk2.0-dev
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   874
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   875
To check whether it is configured or not, check the output of the step:
9162
b587372eb2de Minor fixes and corrections to manual formatting.
Vedran Miletić <rivanvx@gmail.com>
parents: 7818
diff changeset
   876
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   877
.. sourcecode:: bash
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   878
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   879
  $ ./waf configure --enable-examples --enable-tests
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   880
9162
b587372eb2de Minor fixes and corrections to manual formatting.
Vedran Miletić <rivanvx@gmail.com>
parents: 7818
diff changeset
   881
  ---- Summary of optional NS-3 features:
b587372eb2de Minor fixes and corrections to manual formatting.
Vedran Miletić <rivanvx@gmail.com>
parents: 7818
diff changeset
   882
  Python Bindings               : enabled
b587372eb2de Minor fixes and corrections to manual formatting.
Vedran Miletić <rivanvx@gmail.com>
parents: 7818
diff changeset
   883
  Python API Scanning Support   : enabled
b587372eb2de Minor fixes and corrections to manual formatting.
Vedran Miletić <rivanvx@gmail.com>
parents: 7818
diff changeset
   884
  NS-3 Click Integration        : enabled
b587372eb2de Minor fixes and corrections to manual formatting.
Vedran Miletić <rivanvx@gmail.com>
parents: 7818
diff changeset
   885
  GtkConfigStore                : not enabled (library 'gtk+-2.0 >= 2.12' not found)
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   886
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   887
In the above example, it was not enabled, so it cannot be used until a suitable
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   888
version is installed and:
9162
b587372eb2de Minor fixes and corrections to manual formatting.
Vedran Miletić <rivanvx@gmail.com>
parents: 7818
diff changeset
   889
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   890
.. sourcecode:: bash
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   891
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   892
  $ ./waf configure --enable-examples --enable-tests
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   893
  $ ./waf
9162
b587372eb2de Minor fixes and corrections to manual formatting.
Vedran Miletić <rivanvx@gmail.com>
parents: 7818
diff changeset
   894
b587372eb2de Minor fixes and corrections to manual formatting.
Vedran Miletić <rivanvx@gmail.com>
parents: 7818
diff changeset
   895
is rerun.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   896
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   897
Usage is almost the same as the non-GTK-based version, but there
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   898
are no ConfigStore attributes involved:::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   899
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   900
  // Invoke just before entering Simulator::Run ()
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   901
  GtkConfigStore config;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   902
  config.ConfigureDefaults ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   903
  config.ConfigureAttributes ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   904
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   905
Now, when you run the script, a GUI should pop up, allowing you to open menus of
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   906
attributes on different nodes/objects, and then launch the simulation execution
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   907
when you are done.  
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   908
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   909
Future work
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   910
+++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   911
There are a couple of possible improvements:
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   912
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   913
* save a unique version number with date and time at start of file
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   914
* save rng initial seed somewhere.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   915
* make each RandomVariable serialize its own initial seed and re-read it later