doc/manual/source/attributes.rst
author Tom Henderson <tomh@tomh.org>
Wed, 27 Jan 2016 22:29:00 -0800
changeset 11680 8ec1579db3a0
parent 11249 525aab463dac
permissions -rw-r--r--
fix typos in attribute section of manual
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
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
     4
.. Section Separators:
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
     5
   ----
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
     6
   ****
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
     7
   ++++
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
     8
   ====
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
     9
   ~~~~
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
7662
c13e33e96231 clear warnings in manual build process
Tom Henderson <tomh@tomh.org>
parents: 7548
diff changeset
    11
.. _Attributes:
c13e33e96231 clear warnings in manual build process
Tom Henderson <tomh@tomh.org>
parents: 7548
diff changeset
    12
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    13
Configuration and Attributes
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    14
----------------------------
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
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
    17
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    18
* The simulation topology and how objects are connected.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    19
* The values used by the models instantiated in the topology.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
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
    22
|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
    23
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
    24
gathered in the simulator. 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    26
In the course of this chapter we will discuss the various ways to set or
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    27
modify the values used by |ns3| model objects.  In increasing order of
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    28
specificity, these are:
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    29
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    30
+---------------------------------------+-------------------------------------+
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    31
| Method                                | Scope                               |
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    32
+=======================================+=====================================+
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    33
| Default Attribute values set when     | Affect all instances of the class.  |
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    34
| Attributes are defined in             |                                     |
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    35
| :cpp:func:`GetTypeId ()`.             |                                     |
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    36
+---------------------------------------+-------------------------------------+
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    37
| | :cpp:class:`CommandLine`            | Affect all future instances.        |
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    38
| | :cpp:func:`Config::SetDefault()`    |                                     |
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    39
| | :cpp:class:`ConfigStore`            |                                     |
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    40
+---------------------------------------+-------------------------------------+
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    41
| :cpp:class:`ObjectFactory`            | Affects all instances created with  |
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    42
|                                       | the factory.                        |
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    43
+---------------------------------------+-------------------------------------+
11680
8ec1579db3a0 fix typos in attribute section of manual
Tom Henderson <tomh@tomh.org>
parents: 11249
diff changeset
    44
| Helper methods with (string/          | Affects all instances created by    |
8ec1579db3a0 fix typos in attribute section of manual
Tom Henderson <tomh@tomh.org>
parents: 11249
diff changeset
    45
| AttributeValue) parameter pairs       | the helper.                         |
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    46
+---------------------------------------+-------------------------------------+
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    47
| | :cpp:func:`MyClass::SetX ()`        | Alters this particular instance.    |
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    48
| | :cpp:func:`Object::SetAttribute ()` | Generally this is the only form     |
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    49
| | :cpp:func:`Config::Set()`           | which can be scheduled to alter     |
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    50
|                                       | an instance once the simulation     |
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    51
|                                       | is running.                         |
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    52
+---------------------------------------+-------------------------------------+
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    53
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    54
By "specificity" we mean that methods in later rows in the table
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    55
override the values set by, and typically affect fewer instances than,
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    56
earlier methods.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    57
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    58
Before delving into details of the attribute value system, it will help to
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    59
review some basic properties of class :cpp:class:`Object`.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    60
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    61
Object Overview
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    62
***************
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
|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
    65
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
    66
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    67
Many |ns3| objects inherit from the :cpp:class:`Object` base class.  These
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    68
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
    69
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
    70
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    71
* "Metadata" system that links the class name to a lot of meta-information
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    72
  about the object, including:
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    73
  
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    74
  * The base class of the subclass,
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    75
  * The set of accessible constructors in the subclass,
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    76
  * The set of "attributes" of the subclass,
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    77
  * Whether each attribute can be set, or is read-only,
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    78
  * The allowed range of values for each attribute.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    79
  
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    80
* Reference counting smart pointer implementation, for memory management.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    81
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    82
|ns3| objects that use the attribute system derive from either
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    83
:cpp:class:`Object` or :cpp:class:`ObjectBase`. Most |ns3| objects we
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    84
will discuss derive from :cpp:class:`Object`, but a few that are outside
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    85
the smart pointer memory management framework derive from
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    86
:cpp:class:`ObjectBase`.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    87
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    88
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
    89
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    90
Smart Pointers
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    91
++++++++++++++
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    92
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    93
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
    94
`reference counting smart pointer implementation
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
    95
<http://en.wikipedia.org/wiki/Smart_pointer>`_, class :cpp:class:`Ptr`. 
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    96
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    97
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
    98
references to heap-allocated objects that may cause memory leaks.  
10409
4533305686ad Remove extra ':'s
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
    99
For most basic usage (syntax), treat a smart pointer like a regular pointer::
6742
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
  Ptr<WifiNetDevice> nd = ...;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   102
  nd->CallSomeFunction ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   103
  // etc.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   104
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   105
So how do you get a smart pointer to an object, as in the first line
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   106
of this example?
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   107
  
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   108
CreateObject
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   109
============
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   110
7662
c13e33e96231 clear warnings in manual build process
Tom Henderson <tomh@tomh.org>
parents: 7548
diff changeset
   111
As we discussed above in :ref:`Memory-management-and-class-Ptr`, at the
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   112
lowest-level API, objects of type :cpp:class:`Object` are not instantiated
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   113
using ``operator new`` as usual but instead by a templated function called
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   114
:cpp:func:`CreateObject ()`.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   115
10409
4533305686ad Remove extra ':'s
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   116
A typical way to create such an object is as follows::
6742
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
  Ptr<WifiNetDevice> nd = CreateObject<WifiNetDevice> ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   119
10409
4533305686ad Remove extra ':'s
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   120
You can think of this as being functionally equivalent to::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   121
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   122
  WifiNetDevice* nd = new WifiNetDevice ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   123
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   124
Objects that derive from :cpp:class:`Object` must be allocated on the heap
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   125
using :cpp:func:`CreateObject ()`. Those deriving from :cpp:class:`ObjectBase`,
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   126
such as |ns3| helper functions and packet headers and trailers,
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   127
can be allocated on the stack.  
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   128
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   129
In some scripts, you may not see a lot of :cpp:func:`CreateObject ()` calls
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   130
in the code; this is because there are some helper objects in effect
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   131
that are doing the :cpp:func:`CreateObject ()` calls for you.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   132
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   133
TypeId
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
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   136
|ns3| classes that derive from class :cpp:class:`Object` can include
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   137
a metadata class called :cpp:class:`TypeId` that records meta-information
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   138
about the class, for use in the object aggregation and component manager
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   139
systems:
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   140
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   141
* A unique string identifying the class.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   142
* The base class of the subclass, within the metadata system.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   143
* The set of accessible constructors in the subclass.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   144
* A list of publicly accessible properties ("attributes") of the class.
6742
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
Object Summary
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   147
++++++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   148
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   149
Putting all of these concepts together, let's look at a specific
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   150
example: class :cpp:class:`Node`.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   151
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   152
The public header file ``node.h`` has a declaration that includes
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   153
a static :cpp:func:`GetTypeId ()` function call::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   154
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   155
    class Node : public Object
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   156
    {
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   157
    public:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   158
      static TypeId GetTypeId (void);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   159
      ...
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   160
10409
4533305686ad Remove extra ':'s
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   161
This is defined in the ``node.cc`` file as follows::
6742
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
    TypeId 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   164
    Node::GetTypeId (void)
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
      static TypeId tid = TypeId ("ns3::Node")
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   167
        .SetParent<Object> ()
11249
525aab463dac update manual for SetGroupName
Tom Henderson <tomh@tomh.org>
parents: 10868
diff changeset
   168
        .SetGroupName ("Network")
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   169
        .AddConstructor<Node> ()
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   170
        .AddAttribute ("DeviceList",
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   171
	               "The list of devices associated to this Node.",
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   172
                       ObjectVectorValue (),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   173
                       MakeObjectVectorAccessor (&Node::m_devices),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   174
                       MakeObjectVectorChecker<NetDevice> ())
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   175
        .AddAttribute ("ApplicationList",
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   176
	               "The list of applications associated to this Node.",
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   177
                       ObjectVectorValue (),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   178
                       MakeObjectVectorAccessor (&Node::m_applications),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   179
                       MakeObjectVectorChecker<Application> ())
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   180
        .AddAttribute ("Id",
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   181
	               "The id (unique integer) of this Node.",
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   182
                       TypeId::ATTR_GET, // allow only getting it.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   183
                       UintegerValue (0),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   184
                       MakeUintegerAccessor (&Node::m_id),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   185
                       MakeUintegerChecker<uint32_t> ())
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
      return tid;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   188
    }
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   189
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   190
Consider the :cpp:class:`TypeId` of the |ns3| :cpp:class:`Object` class
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   191
as an extended form of run time type information (RTTI). The C++ language
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   192
includes a simple kind of RTTI in order to support ``dynamic_cast`` and
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   193
``typeid`` operators.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   194
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   195
The :cpp:func:`SetParent<Object> ()` call in the definition above is used in
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   196
conjunction with our object aggregation mechanisms to allow safe up- and
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   197
down-casting in inheritance trees during :cpp:func:`GetObject ()`.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   198
It also enables subclasses to inherit the Attributes of their parent class.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   199
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   200
The :cpp:func:`AddConstructor<Node> ()` call is used in conjunction
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   201
with our abstract object factory mechanisms to allow us to construct
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   202
C++ objects without forcing a user to know the concrete class of
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   203
the object she is building.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   204
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   205
The three calls to :cpp:func:`AddAttribute ()` associate a given string
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   206
with a strongly typed value in the class. Notice that you must provide
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   207
a help string which may be displayed, for example, *via* command line
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   208
processors. Each :cpp:class:`Attribute` is associated with mechanisms
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   209
for accessing the underlying member variable in the object (for example,
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   210
:cpp:func:`MakeUintegerAccessor ()` tells the generic :cpp:class:`Attribute`
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   211
code how to get to the node ID above). There are also "Checker" methods which
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   212
are used to validate values against range limitations, such as maximum
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   213
and minimum allowed values.
6742
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
When users want to create Nodes, they will usually call some form of 
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   216
:cpp:func:`CreateObject ()`,::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   217
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   218
    Ptr<Node> n = CreateObject<Node> ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   219
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   220
or more abstractly, using an object factory, you can create a
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   221
:cpp:class:`Node` object without even knowing the concrete C++ type::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   222
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   223
    ObjectFactory factory;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   224
    const std::string typeId = "ns3::Node'';
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   225
    factory.SetTypeId (typeId);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   226
    Ptr<Object> node = factory.Create <Object> ();
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
Both of these methods result in fully initialized attributes being available 
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   229
in the resulting :cpp:class:`Object` instances.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   230
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   231
We next discuss how attributes (values associated with member variables or
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   232
functions of the class) are plumbed into the above :cpp:class:`TypeId`.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   233
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   234
Attributes
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   235
**********
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   236
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   237
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
   238
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
   239
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
   240
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
   241
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
   242
internal variables.  For instance, use cases such as:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   243
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   244
* *"I want to trace the packets on the wireless interface only on the first
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   245
  access point."*
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   246
* *"I want to trace the value of the TCP congestion window (every time it
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   247
  changes) on a particular TCP socket."*
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   248
* *"I want a dump of all values that were used in my simulation."*
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   249
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   250
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
   251
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
   252
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
   253
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
   254
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
   255
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
   256
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
   257
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
   258
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
   259
for each parameter.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   260
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   261
Defining Attributes
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   262
+++++++++++++++++++
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
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
   265
to plumb accessors (pointers) through the system and walk pointer chains to get
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   266
to them. Consider a class :cpp:class:`DropTailQueue` that has a member variable
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   267
that is an unsigned integer :cpp:member:`m_maxPackets`; this member variable controls
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   268
the depth of the queue.  
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   269
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   270
If we look at the declaration of :cpp:class:`DropTailQueue`, we see
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   271
the following::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   272
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   273
    class DropTailQueue : public Queue {
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   274
    public:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   275
      static TypeId GetTypeId (void);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   276
      ...
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   277
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   278
    private:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   279
      std::queue<Ptr<Packet> > m_packets;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   280
      uint32_t m_maxPackets;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   281
    };
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
Let's consider things that a user may want to do with the value of
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   284
:cpp:member:`m_maxPackets`:
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   285
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   286
* Set a default value for the system, such that whenever a new
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   287
  :cpp:class:`DropTailQueue` is created, this member is initialized
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   288
  to that default.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   289
* 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
   290
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   291
The above things typically require providing ``Set ()`` and ``Get ()``
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   292
functions, and some type of global default value.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   293
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   294
In the |ns3| attribute system, these value definitions and accessor function
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   295
registrations are moved into the :cpp:class:`TypeId` class; *e.g*.::
6742
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
    NS_OBJECT_ENSURE_REGISTERED (DropTailQueue);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   298
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   299
    TypeId
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   300
    DropTailQueue::GetTypeId (void) 
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   301
    {
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   302
      static TypeId tid = TypeId ("ns3::DropTailQueue")
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   303
        .SetParent<Queue> ()
11249
525aab463dac update manual for SetGroupName
Tom Henderson <tomh@tomh.org>
parents: 10868
diff changeset
   304
        .SetGroupName ("Network")
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   305
        .AddConstructor<DropTailQueue> ()
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   306
        .AddAttribute ("MaxPackets", 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   307
                       "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
   308
                       UintegerValue (100),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   309
                       MakeUintegerAccessor (&DropTailQueue::m_maxPackets),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   310
                       MakeUintegerChecker<uint32_t> ())
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
      
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   313
      return tid;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   314
    }
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   315
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   316
The :cpp:func:`AddAttribute ()` method is performing a number of things for the
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   317
:cpp:member:`m_maxPackets` value:
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   318
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   319
* Binding the (usually private) member variable :cpp:member:`m_maxPackets`
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   320
  to a public string ``"MaxPackets"``.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   321
* Providing a default value (100 packets).
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   322
* Providing some help text defining the meaning of the value.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   323
* Providing a "Checker" (not used in this example) that can be used to set
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   324
  bounds on the allowable range of values.
6742
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
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
   327
accessible in the attribute namespace, which is based on strings such as
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   328
``"MaxPackets"`` and :cpp:class:`TypeId` name strings. In the next section,
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   329
we will provide an example script that shows how users may manipulate
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   330
these values.
6742
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
Note that initialization of the attribute relies on the macro
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   333
``NS_OBJECT_ENSURE_REGISTERED (DropTailQueue)`` being called; if you leave this
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   334
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
   335
correctly.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   336
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   337
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
   338
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
   339
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
   340
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
   341
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
   342
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
   343
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   344
Detailed documentation of the actual attributes defined for a type,
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   345
and a global list of all defined attributes, are available in
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   346
the API documentation.  For the rest of this document we are going
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   347
to demonstrate the various ways of getting and setting attribute values.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   348
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   349
Setting Default Values
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   350
++++++++++++++++++++++
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   351
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   352
Config::SetDefault and CommandLine
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   353
==================================
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   354
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   355
Let's look at how a user script might access a specific attribute value.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   356
We're going to use the
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   357
``src/point-to-point/examples/main-attribute-value.cc``
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   358
script for illustration, with some details stripped out.  The ``main``
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   359
function begins::
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   360
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   361
    // 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
   362
    // 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
   363
    // 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
   364
    //
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
    int 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   367
    main (int argc, char *argv[])
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   368
    {
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
      // 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
   371
      // (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
   372
      // 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   373
      // 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
   374
      // a string-based value or a Uinteger value
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   375
      Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("80"));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   376
      // The below function call is redundant
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   377
      Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (80));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   378
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   379
      // Allow the user to override any of the defaults and the above
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   380
      // SetDefaults () at run-time, via command-line arguments
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   381
      // For example, via "--ns3::DropTailQueue::MaxPackets=80"
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   382
      CommandLine cmd;
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   383
      // This provides yet another way to set the value from the command line:
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   384
      cmd.AddValue ("maxPackets", "ns3::DropTailQueue::MaxPackets");
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   385
      cmd.Parse (argc, argv);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   386
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   387
The main thing to notice in the above are the two equivalent calls to 
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   388
:cpp:func:`Config::SetDefault ()`.  This is how we set the default value
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   389
for all subsequently instantiated :cpp:class:`DropTailQueue`\s.  We illustrate
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   390
that two types of ``Value`` classes, a :cpp:class:`StringValue` and
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   391
a :cpp:class:`UintegerValue` class, can be used to assign the value
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   392
to the attribute named by "ns3::DropTailQueue::MaxPackets".
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   393
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   394
It's also possible to manipulate Attributes using the :cpp:class:`CommandLine`;
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   395
we saw some examples early in the Tutorial.  In particular, it is
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   396
straightforward to add a shorthand argument name, such as ``--maxPackets``,
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   397
for an Attribute that is particular relevant for your model, in this case
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   398
``"ns3::DropTailQueue::MaxPackets"``.  This has the additional feature that
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   399
the help string for the Attribute will be printed as part of the usage
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   400
message for the script.  For more information see
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   401
the :cpp:class:`CommandLine` API documentation.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   402
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   403
Now, we will create a few objects using the low-level API.  Our
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   404
newly created queues will not have :cpp:member:`m_maxPackets` initialized to
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   405
100 packets, as defined in the :cpp:func:`DropTailQueue::GetTypeId ()`
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   406
function, but to 80 packets, because of what we did above with
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   407
default values.::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   408
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   409
    Ptr<Node> n0 = CreateObject<Node> ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   410
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   411
    Ptr<PointToPointNetDevice> net0 = CreateObject<PointToPointNetDevice> ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   412
    n0->AddDevice (net0);
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
    Ptr<Queue> q = CreateObject<DropTailQueue> ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   415
    net0->AddQueue(q);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   416
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   417
At this point, we have created a single :cpp:class:`Node` (``n0``)
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   418
and a single :cpp:class:`PointToPointNetDevice` (``net0``),
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   419
and added a :cpp:class:`DropTailQueue` (``q``) to ``net0``.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   420
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   421
Constructors, Helpers and ObjectFactory
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   422
=======================================
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   423
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   424
Arbitrary combinations of attributes can be set and fetched from
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   425
the helper and low-level APIs; either from the constructors themselves::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   426
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   427
    Ptr<GridPositionAllocator> p =
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   428
      CreateObjectWithAttributes<GridPositionAllocator>
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   429
        ("MinX", DoubleValue (-100.0),
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   430
         "MinY", DoubleValue (-100.0),
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   431
         "DeltaX", DoubleValue (5.0),
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   432
         "DeltaY", DoubleValue (20.0),
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   433
         "GridWidth", UintegerValue (20),
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   434
         "LayoutType", StringValue ("RowFirst"));
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   435
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   436
or from the higher-level helper APIs, such as::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   437
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   438
    mobility.SetPositionAllocator
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   439
        ("ns3::GridPositionAllocator",
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   440
         "MinX", DoubleValue (-100.0),
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   441
         "MinY", DoubleValue (-100.0),
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   442
         "DeltaX", DoubleValue (5.0),
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   443
         "DeltaY", DoubleValue (20.0),
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   444
         "GridWidth", UintegerValue (20),
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   445
         "LayoutType", StringValue ("RowFirst"));
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   446
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   447
We don't illustrate it here, but you can also configure an
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   448
:cpp:class:`ObjectFactory` with new values for specific attributes.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   449
Instances created by the :cpp:class:`ObjectFactory` will have those
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   450
attributes set during construction.  This is very similar to using
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   451
one of the helper APIs for the class.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   452
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   453
To review, there are several ways to set values for attributes for
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   454
class instances *to be created in the future:*
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   455
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   456
* :cpp:func:`Config::SetDefault ()`
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   457
* :cpp:func:`CommandLine::AddValue ()`
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   458
* :cpp:func:`CreateObjectWithAttributes<> ()`
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   459
* Various helper APIs
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   460
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   461
But what if you've already created an instance, and you want
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   462
to change the value of the attribute?  In this example, how can we
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   463
manipulate the :cpp:member:`m_maxPackets` value of the already instantiated
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   464
:cpp:class:`DropTailQueue`?  Here are various ways to do that.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   465
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   466
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   467
Changing Values
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   468
+++++++++++++++
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   469
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   470
SmartPointer
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   471
============
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   472
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   473
Assume that a smart pointer (:cpp:class:`Ptr`) to a relevant network device
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   474
is in hand; in the current example, it is the ``net0`` pointer. 
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   475
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   476
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
   477
modify its attribute.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   478
 
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   479
First, we observe that we can get a pointer to the (base class)
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   480
:cpp:class:`Queue` *via* the
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   481
:cpp:class:`PointToPointNetDevice` attributes, where it is called
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   482
``"TxQueue"``::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   483
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   484
    PointerValue tmp;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   485
    net0->GetAttribute ("TxQueue", tmp);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   486
    Ptr<Object> txQueue = tmp.GetObject ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   487
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   488
Using the :cpp:func:`GetObject ()` function, we can perform a safe downcast
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   489
to a :cpp:class:`DropTailQueue`, where ``"MaxPackets"`` is an attribute::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   490
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   491
    Ptr<DropTailQueue> dtq = txQueue->GetObject <DropTailQueue> ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   492
    NS_ASSERT (dtq != 0);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   493
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   494
Next, we can get the value of an attribute on this queue.  We have introduced
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   495
wrapper ``Value`` classes for the underlying data types, similar
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   496
to Java wrappers around these types, since the attribute system stores values
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   497
serialized to strings, and not disparate types.  Here, the attribute value
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   498
is assigned to a :cpp:class:`UintegerValue`, and the :cpp:func:`Get ()`
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   499
method on this value produces the (unwrapped) ``uint32_t``.::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   500
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   501
    UintegerValue limit;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   502
    dtq->GetAttribute ("MaxPackets", limit);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   503
    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
   504
  
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   505
Note that the above downcast is not really needed; we could have gotten
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   506
the attribute value directly from ``txQueue``, which is an :cpp:class:`Object`::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   507
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   508
    txQueue->GetAttribute ("MaxPackets", limit);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   509
    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
   510
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   511
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
   512
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   513
    txQueue->SetAttribute("MaxPackets", UintegerValue (60));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   514
    txQueue->GetAttribute ("MaxPackets", limit);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   515
    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
   516
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   517
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   518
Config Namespace Path
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   519
=====================
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   520
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   521
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
   522
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
   523
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
   524
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
   525
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   526
    Config::Set ("/NodeList/0/DeviceList/0/TxQueue/MaxPackets",
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   527
                 UintegerValue (25));
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   528
    txQueue->GetAttribute ("MaxPackets", limit); 
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   529
    NS_LOG_INFO ("4.  txQueue limit changed through namespace: "
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   530
                 << limit.Get () << " packets");
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   531
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   532
The configuration path often has the form of
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   533
``".../<container name>/<index>/.../<attribute>/<attribute>"``
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   534
to refer to a specific instance by index of an object in the container.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   535
In this case the first container is the list of all :cpp:class:`Node`\s;
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   536
the second container is the list of all :cpp:class:`NetDevice`\s on
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   537
the chosen :cpp:class:`Node`.  Finally, the configuration path usually
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   538
ends with a succession of member attributes, in this case the ``"MaxPackets"``
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   539
attribute of the ``"TxQueue"`` of the chosen :cpp:class:`NetDevice`.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   540
	
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   541
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
   542
devices (which in this simple example has the same effect as the previous
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   543
:cpp:func:`Config::Set ()`)::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   544
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   545
    Config::Set ("/NodeList/*/DeviceList/*/TxQueue/MaxPackets",
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   546
                 UintegerValue (15));
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   547
    txQueue->GetAttribute ("MaxPackets", limit); 
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   548
    NS_LOG_INFO ("5.  txQueue limit changed through wildcarded namespace: "
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   549
                 << limit.Get () << " packets");
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   550
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   551
Object Name Service
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   552
===================
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   553
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   554
Another way to get at the attribute is to use the object name service facility.
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   555
The object name service allows us to add items to the configuration
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   556
namespace under the ``"/Names/"`` path with a user-defined name string.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   557
This approach is useful if one doesn't have access to the underlying
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   558
pointers and it is difficult to determine the required concrete configuration
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   559
namespace path.
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   560
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   561
::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   562
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   563
    Names::Add ("server", n0);
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   564
    Names::Add ("server/eth0", net0);
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   565
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
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   568
    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
   569
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   570
Here we've added the path elements ``"server"`` and ``"eth0"`` under
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   571
the ``"/Names/"`` namespace, then used the resulting configuration path
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   572
to set the attribute.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   573
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   574
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
   575
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   576
Implementation Details
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   577
**********************
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   578
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   579
Value Classes
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   580
+++++++++++++
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   581
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   582
Readers will note the ``TypeValue`` classes which are subclasses of the
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   583
:cpp:class:`AttributeValue` base class. These can be thought of as
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   584
intermediate classes which are used to convert from raw types to the
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   585
:cpp:class:`AttributeValue`\s that are used by the attribute system.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   586
Recall that this database is holding objects of many types serialized
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   587
to strings. Conversions to this type can either be done using
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   588
an intermediate class (such as :cpp:class:`IntegerValue`,
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   589
or :cpp:class:`DoubleValue` for floating point numbers)
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   590
or *via* strings. Direct implicit conversion of types to
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   591
:cpp:class:`AttributeValue` is not really practical.
10409
4533305686ad Remove extra ':'s
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   592
So in the above, users have a choice of using strings or values::
6742
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
    p->Set ("cwnd", StringValue ("100")); // string-based setter
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   595
    p->Set ("cwnd", IntegerValue (100)); // integer-based setter
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   596
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   597
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
   598
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
   599
the attribute system: 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   600
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   601
* ``ATTRIBUTE_HELPER_HEADER``
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   602
* ``ATTRIBUTE_HELPER_CPP``
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   603
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   604
See the API documentation for these constructs for more information.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   605
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   606
Initialization Order
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   607
++++++++++++++++++++
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   608
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   609
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
   610
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
   611
specified, nor enforced, by the system. A specific example of this can be seen
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   612
in automated configuration programs such as :cpp:class:`ConfigStore`.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   613
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
   614
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
   615
change Attributes in, for example, alphabetic order.  
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   616
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   617
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
   618
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
   619
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
   620
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
   621
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   622
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
   623
consistently to allow correct operation. To this end we do allow for consistency
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   624
checking *when the attribute is used* (*cf*. ``NS_ASSERT_MSG``
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   625
or ``NS_ABORT_MSG``).
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   626
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   627
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
   628
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
   629
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
   630
the logic of the constructor? There is a way to do this, used for example in the
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   631
class :cpp:class:`ConfigStore`: call :cpp:func:`ObjectBase::ConstructSelf ()` as
10409
4533305686ad Remove extra ':'s
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   632
follows::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   633
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   634
    ConfigStore::ConfigStore ()
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   635
    {
7818
2a5c861ec2ee typo in manual
Tom Henderson <tomh@tomh.org>
parents: 7662
diff changeset
   636
      ObjectBase::ConstructSelf (AttributeConstructionList ());
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   637
      // continue on with constructor.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   638
    }
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   639
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   640
Beware that the object and all its derived classes must also implement
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   641
a :cpp:func:`GetInstanceTypeId ()` method. Otherwise
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   642
the :cpp:func:`ObjectBase::ConstructSelf ()` will not be able to read
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   643
the attributes.
9698
9d91a3c643b2 Bug 1601 RttEstimator doesn't set m_currentEstimatedRtt fix
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9162
diff changeset
   644
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   645
Adding Attributes
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   646
+++++++++++++++++
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   647
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   648
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
   649
system, but undoubtedly users will want to extend this to pick up ones we have
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   650
missed, or to add their own classes to the system.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   651
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   652
There are three typical use cases:
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   653
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   654
* Making an existing class data member accessible as an Attribute,
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   655
  when it isn't already.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   656
* Making a new class able to expose some data members as Attributes
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   657
  by giving it a TypeId.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   658
* Creating an :cpp:class:`AttributeValue` subclass for a new class
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   659
  so that it can be accessed as an Attribute.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   660
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   661
Existing Member Variable
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   662
========================
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   663
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   664
Consider this variable in :cpp:class:`TcpSocket`::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   665
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   666
    uint32_t m_cWnd;   // Congestion window
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   667
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   668
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
   669
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
   670
the user could declare the following addition in the runtime metadata system (to
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   671
the :cpp:func:`GetTypeId` definition for :cpp:class:`TcpSocket`)::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   672
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   673
    .AddAttribute ("Congestion window", 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   674
                   "Tcp congestion window (bytes)",
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   675
                   UintegerValue (1),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   676
                   MakeUintegerAccessor (&TcpSocket::m_cWnd),
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   677
                   MakeUintegerChecker<uint16_t> ())
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   678
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   679
Now, the user with a pointer to a :cpp:class:`TcpSocket` instance
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   680
can perform operations such as
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   681
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
   682
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
   683
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
   684
applied.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   685
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   686
New Class TypeId
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   687
================
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   688
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   689
Here, we discuss the impact on a user who wants to add a new class to |ns3|.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   690
What additional things must be done to enable it to hold attributes?
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   691
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   692
Let's assume our new class, called :cpp:class:`ns3::MyMobility`,
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   693
is a type of mobility model.  First, the class should inherit from
11680
8ec1579db3a0 fix typos in attribute section of manual
Tom Henderson <tomh@tomh.org>
parents: 11249
diff changeset
   694
its parent class, :cpp:class:`ns3::MobilityModel`.
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   695
In the ``my-mobility.h`` header file::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   696
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   697
    namespace ns3 {
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   698
    
11680
8ec1579db3a0 fix typos in attribute section of manual
Tom Henderson <tomh@tomh.org>
parents: 11249
diff changeset
   699
    class MyMobility : public MobilityModel
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   700
    {
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   701
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   702
This requires we declare the :cpp:func:`GetTypeId ()` function. 
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   703
This is a one-line public function declaration::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   704
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   705
    public:
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   706
      /**
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   707
       *  Register this type.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   708
       *  \return The object TypeId.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   709
       */
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   710
      static TypeId GetTypeId (void);
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   711
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   712
We've already introduced what a :cpp:class:`TypeId` definition will look like
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   713
in the ``my-mobility.cc`` implementation file::
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   714
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   715
    NS_OBJECT_ENSURE_REGISTERED (MyMobility);
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   716
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   717
    TypeId
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   718
    MyMobility::GetTypeId (void)
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   719
    {
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   720
      static TypeId tid = TypeId ("ns3::MyMobility")
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   721
        .SetParent<MobilityModel> ()
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   722
        .SetGroupName ("Mobility")
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   723
        .AddConstructor<MyMobility> ()
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   724
        .AddAttribute ("Bounds",
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   725
                       "Bounds of the area to cruise.",
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   726
                       RectangleValue (Rectangle (0.0, 0.0, 100.0, 100.0)),
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   727
                       MakeRectangleAccessor (&MyMobility::m_bounds),
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   728
                       MakeRectangleChecker ())
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   729
        .AddAttribute ("Time",
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   730
                       "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
   731
                       TimeValue (Seconds (1.0)),
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   732
                       MakeTimeAccessor (&MyMobility::m_modeTime),
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   733
                       MakeTimeChecker ())
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   734
        // etc (more parameters).
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   735
        ;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   736
      return tid;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   737
    }
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   738
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   739
If we don't want to subclass from an existing class, in the header file
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   740
we just inherit from :cpp:class:`ns3::Object`, and in the object file
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   741
we set the parent class to :cpp:class:`ns3::Object` with
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   742
``.SetParent<Object> ()``.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   743
    
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   744
Typical mistakes here involve:
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   745
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   746
* Not calling ``NS_OBJECT_ENSURE_REGISTERED ()``
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   747
* Not calling the :cpp:func:`SetParent ()` method,
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   748
  or calling it with the wrong type.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   749
* Not calling the :cpp:func:`AddConstructor ()` method,
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   750
  or calling it with the wrong type.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   751
* Introducing a typographical error in the name of the :cpp:class:`TypeId`
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   752
  in its constructor.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   753
* Not using the fully-qualified C++ typename of the enclosing C++ class as the
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   754
  name of the :cpp:class:`TypeId`.  Note that ``"ns3::"`` is required.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   755
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   756
None of these mistakes can be detected by the |ns3| codebase, so users
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   757
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
   758
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   759
New AttributeValue Type
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   760
=======================
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   761
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   762
From the perspective of the user who writes a new class in the system and wants
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   763
it to be accessible as an attribute, there is mainly the matter of writing the
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   764
conversions to/from strings and attribute values.  Most of this can be
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   765
copy/pasted with macro-ized code.  For instance, consider a class declaration
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   766
for :cpp:class:`Rectangle` in the ``src/mobility/model`` directory:
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   767
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   768
Header File
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   769
~~~~~~~~~~~
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   770
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   771
::
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   772
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   773
    /**
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   774
     * \brief a 2d rectangle
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   775
     */
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   776
    class Rectangle
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   777
    {
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   778
      ...
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   779
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   780
      double xMin;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   781
      double xMax;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   782
      double yMin;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   783
      double yMax;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   784
    };
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   785
 
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   786
One macro call and two operators, must be added below the class declaration in
10409
4533305686ad Remove extra ':'s
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   787
order to turn a Rectangle into a value usable by the ``Attribute`` system::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   788
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   789
    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
   790
    std::istream &operator >> (std::istream &is, Rectangle &rectangle);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   791
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   792
    ATTRIBUTE_HELPER_HEADER (Rectangle);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   793
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   794
Implementation File
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   795
~~~~~~~~~~~~~~~~~~~
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   796
10409
4533305686ad Remove extra ':'s
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   797
In the class definition (``.cc`` file), the code looks like this::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   798
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   799
    ATTRIBUTE_HELPER_CPP (Rectangle);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   800
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   801
    std::ostream &
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   802
    operator << (std::ostream &os, const Rectangle &rectangle)
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   803
    {
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   804
      os << rectangle.xMin << "|" << rectangle.xMax << "|" << rectangle.yMin << "|"
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   805
         << rectangle.yMax;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   806
      return os;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   807
    }
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   808
    std::istream &
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   809
    operator >> (std::istream &is, Rectangle &rectangle)
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
      char c1, c2, c3;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   812
      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
   813
         >> rectangle.yMax;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   814
      if (c1 != '|' ||
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   815
          c2 != '|' ||
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   816
          c3 != '|')
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   817
        {
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   818
          is.setstate (std::ios_base::failbit);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   819
        }
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   820
      return is;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   821
    }
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   822
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   823
These stream operators simply convert from a string representation of the
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   824
Rectangle (``"xMin|xMax|yMin|yMax"``) to the underlying Rectangle.  The modeler
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   825
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
   826
instance of the new class.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   827
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   828
ConfigStore
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   829
***********
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   830
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   831
Values for |ns3| attributes can be stored in an ASCII or XML text file
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   832
and loaded into a future simulation run.  This feature is known as the
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   833
|ns3| ConfigStore.  The :cpp:class:`ConfigStore` is a specialized database for attribute values and default values.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   834
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   835
Although it is a separately maintained module in the
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   836
``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
   837
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
   838
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   839
We can explore this system by using an example from
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   840
``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
   841
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   842
First, all users of the :cpp:class:`ConfigStore` must include
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   843
the following statement::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   844
6941
9d2c79c992d7 Split contrib module into config-store and tools
Mitch Watrous <watrous@u.washington.edu>
parents: 6766
diff changeset
   845
    #include "ns3/config-store-module.h"
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   846
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   847
Next, this program adds a sample object :cpp:class:`ConfigExample`
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   848
to show how the system is extended::
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   849
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   850
    class ConfigExample : public Object
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   851
    {
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   852
    public:
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   853
      static TypeId GetTypeId (void) {
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   854
        static TypeId tid = TypeId ("ns3::A")
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   855
          .SetParent<Object> ()
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   856
          .AddAttribute ("TestInt16", "help text",
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   857
                         IntegerValue (-2),
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   858
                         MakeIntegerAccessor (&A::m_int16),
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   859
                         MakeIntegerChecker<int16_t> ())
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   860
          ;
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   861
          return tid;
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   862
        }
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   863
      int16_t m_int16;
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   864
    };
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   865
    
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   866
    NS_OBJECT_ENSURE_REGISTERED (ConfigExample);
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   867
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   868
Next, we use the Config subsystem to override the defaults in a couple of
10409
4533305686ad Remove extra ':'s
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   869
ways::
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   870
     
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   871
      Config::SetDefault ("ns3::ConfigExample::TestInt16", IntegerValue (-5));
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   872
    
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   873
      Ptr<ConfigExample> a_obj = CreateObject<ConfigExample> ();
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   874
      NS_ABORT_MSG_UNLESS (a_obj->m_int16 == -5,
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   875
                           "Cannot set ConfigExample's integer attribute via Config::SetDefault");
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   876
    
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   877
      Ptr<ConfigExample> a2_obj = CreateObject<ConfigExample> ();
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   878
      a2_obj->SetAttribute ("TestInt16", IntegerValue (-3));
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   879
      IntegerValue iv;
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   880
      a2_obj->GetAttribute ("TestInt16", iv);
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   881
      NS_ABORT_MSG_UNLESS (iv.Get () == -3,
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   882
                           "Cannot set ConfigExample's integer attribute via SetAttribute");
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   883
    
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   884
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
   885
created is rooted in the configuration namespace as an object instance.
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   886
This normally happens when you aggregate objects to a :cpp:class:`ns3::Node`
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   887
or :cpp:class:`ns3::Channel` instance,
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   888
but here, since we are working at the core level, we need to create a
10409
4533305686ad Remove extra ':'s
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   889
new root namespace object::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   890
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   891
      Config::RegisterRootNamespaceObject (a2_obj);
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   892
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   893
Writing
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   894
+++++++
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   895
      
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   896
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
   897
to do it in two formats, XML and raw text.  In practice, one should perform
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   898
this step just before calling :cpp:func:`Simulator::Run ()` to save the
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   899
final configuration just before running the simulation.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   900
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   901
There are three Attributes that govern the behavior of the ConfigStore:
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   902
``"Mode"``, ``"Filename"``, and ``"FileFormat"``.  The Mode (default ``"None"``)
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   903
configures whether |ns3| should load configuration from a previously saved file
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   904
(specify ``"Mode=Load"``) or save it to a file (specify ``"Mode=Save"``).
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   905
The Filename (default ``""``) is where the ConfigStore should read or write
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   906
its data.  The FileFormat (default ``"RawText"``) governs whether
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   907
the ConfigStore format is plain text or Xml (``"FileFormat=Xml"``)
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   908
10409
4533305686ad Remove extra ':'s
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   909
The example shows::
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   910
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   911
      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
   912
      Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   913
      Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   914
      ConfigStore outputConfig;
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   915
      outputConfig.ConfigureDefaults ();
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   916
      outputConfig.ConfigureAttributes ();
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   917
    
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   918
      // Output config store to txt format
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   919
      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
   920
      Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("RawText"));
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   921
      Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   922
      ConfigStore outputConfig2;
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   923
      outputConfig2.ConfigureDefaults ();
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   924
      outputConfig2.ConfigureAttributes ();
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   925
    
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   926
      Simulator::Run ();
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   927
    
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   928
      Simulator::Destroy ();
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   929
    
10703
3d6f19ee0d30 clarify some points about the ConfigStore
Tom Henderson <tomh@tomh.org>
parents: 10409
diff changeset
   930
Note the placement of these statements just prior to the 
3d6f19ee0d30 clarify some points about the ConfigStore
Tom Henderson <tomh@tomh.org>
parents: 10409
diff changeset
   931
:cpp:func:`Simulator::Run ()` statement.  This output logs all of the
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   932
values in place just prior to starting the simulation (*i.e*. after
10703
3d6f19ee0d30 clarify some points about the ConfigStore
Tom Henderson <tomh@tomh.org>
parents: 10409
diff changeset
   933
all of the configuration has taken place).
3d6f19ee0d30 clarify some points about the ConfigStore
Tom Henderson <tomh@tomh.org>
parents: 10409
diff changeset
   934
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   935
After running, you can open the ``output-attributes.txt`` file and see:
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   936
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   937
.. sourcecode:: text
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   938
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   939
    default ns3::RealtimeSimulatorImpl::SynchronizationMode "BestEffort"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   940
    default ns3::RealtimeSimulatorImpl::HardLimit "+100000000.0ns"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   941
    default ns3::PcapFileWrapper::CaptureSize "65535"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   942
    default ns3::PacketSocket::RcvBufSize "131072"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   943
    default ns3::ErrorModel::IsEnabled "true"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   944
    default ns3::RateErrorModel::ErrorUnit "EU_BYTE"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   945
    default ns3::RateErrorModel::ErrorRate "0"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   946
    default ns3::RateErrorModel::RanVar "Uniform:0:1"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   947
    default ns3::DropTailQueue::Mode "Packets"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   948
    default ns3::DropTailQueue::MaxPackets "100"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   949
    default ns3::DropTailQueue::MaxBytes "6553500"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   950
    default ns3::Application::StartTime "+0.0ns"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   951
    default ns3::Application::StopTime "+0.0ns"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   952
    default ns3::ConfigStore::Mode "Save"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   953
    default ns3::ConfigStore::Filename "output-attributes.txt"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   954
    default ns3::ConfigStore::FileFormat "RawText"
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   955
    default ns3::ConfigExample::TestInt16 "-5"
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   956
    global RngSeed "1"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   957
    global RngRun "1"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   958
    global SimulatorImplementationType "ns3::DefaultSimulatorImpl"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   959
    global SchedulerType "ns3::MapScheduler"
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   960
    global ChecksumEnabled "false"
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   961
    value /$ns3::ConfigExample/TestInt16 "-3"
6766
4caf532b12c3 formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 6751
diff changeset
   962
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   963
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
   964
module are shown.  Then, all the values for the |ns3| global values
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   965
are recorded.  Finally, the value of the instance of :cpp:class:`ConfigExample`
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   966
that was rooted in the configuration namespace is shown.  In a real
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   967
|ns3| program, many more models, attributes, and defaults would be shown.
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   968
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   969
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
   970
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
   971
.. sourcecode:: xml
6766
4caf532b12c3 formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 6751
diff changeset
   972
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   973
    <?xml version="1.0" encoding="UTF-8"?>
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   974
    <ns3>
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   975
     <default name="ns3::RealtimeSimulatorImpl::SynchronizationMode" value="BestEffort"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   976
     <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
   977
     <default name="ns3::PcapFileWrapper::CaptureSize" value="65535"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   978
     <default name="ns3::PacketSocket::RcvBufSize" value="131072"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   979
     <default name="ns3::ErrorModel::IsEnabled" value="true"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   980
     <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
   981
     <default name="ns3::RateErrorModel::ErrorRate" value="0"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   982
     <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
   983
     <default name="ns3::DropTailQueue::Mode" value="Packets"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   984
     <default name="ns3::DropTailQueue::MaxPackets" value="100"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   985
     <default name="ns3::DropTailQueue::MaxBytes" value="6553500"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   986
     <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
   987
     <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
   988
     <default name="ns3::ConfigStore::Mode" value="Save"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   989
     <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
   990
     <default name="ns3::ConfigStore::FileFormat" value="Xml"/>
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   991
     <default name="ns3::ConfigExample::TestInt16" value="-5"/>
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   992
     <global name="RngSeed" value="1"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   993
     <global name="RngRun" value="1"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   994
     <global name="SimulatorImplementationType" value="ns3::DefaultSimulatorImpl"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   995
     <global name="SchedulerType" value="ns3::MapScheduler"/>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   996
     <global name="ChecksumEnabled" value="false"/>
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
   997
     <value path="/$ns3::ConfigExample/TestInt16" value="-3"/>
7438
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   998
    </ns3>
3aeb5ac5af62 Add config-store example and update documentation
Tom Henderson <tomh@tomh.org>
parents: 7429
diff changeset
   999
    
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1000
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
  1001
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1002
Reading
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1003
+++++++
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1004
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1005
Next, we discuss configuring simulations *via* a stored input
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1006
configuration file.  There are a couple of key differences
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1007
compared to writing the final simulation configuration.  First, we
10703
3d6f19ee0d30 clarify some points about the ConfigStore
Tom Henderson <tomh@tomh.org>
parents: 10409
diff changeset
  1008
need to place statements such as these at the beginning of the program,
3d6f19ee0d30 clarify some points about the ConfigStore
Tom Henderson <tomh@tomh.org>
parents: 10409
diff changeset
  1009
before simulation configuration statements are written (so the values
3d6f19ee0d30 clarify some points about the ConfigStore
Tom Henderson <tomh@tomh.org>
parents: 10409
diff changeset
  1010
are registered before being used in object construction).
3d6f19ee0d30 clarify some points about the ConfigStore
Tom Henderson <tomh@tomh.org>
parents: 10409
diff changeset
  1011
3d6f19ee0d30 clarify some points about the ConfigStore
Tom Henderson <tomh@tomh.org>
parents: 10409
diff changeset
  1012
::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1013
10703
3d6f19ee0d30 clarify some points about the ConfigStore
Tom Henderson <tomh@tomh.org>
parents: 10409
diff changeset
  1014
      Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("input-defaults.xml"));
3d6f19ee0d30 clarify some points about the ConfigStore
Tom Henderson <tomh@tomh.org>
parents: 10409
diff changeset
  1015
      Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Load"));
3d6f19ee0d30 clarify some points about the ConfigStore
Tom Henderson <tomh@tomh.org>
parents: 10409
diff changeset
  1016
      Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
3d6f19ee0d30 clarify some points about the ConfigStore
Tom Henderson <tomh@tomh.org>
parents: 10409
diff changeset
  1017
      ConfigStore inputConfig;
3d6f19ee0d30 clarify some points about the ConfigStore
Tom Henderson <tomh@tomh.org>
parents: 10409
diff changeset
  1018
      inputConfig.ConfigureDefaults ();
3d6f19ee0d30 clarify some points about the ConfigStore
Tom Henderson <tomh@tomh.org>
parents: 10409
diff changeset
  1019
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1020
Next, note that loading of input configuration data is limited to Attribute
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1021
default (*i.e*. not instance) values, and global values.  Attribute instance
10703
3d6f19ee0d30 clarify some points about the ConfigStore
Tom Henderson <tomh@tomh.org>
parents: 10409
diff changeset
  1022
values are not supported because at this stage of the simulation, before
3d6f19ee0d30 clarify some points about the ConfigStore
Tom Henderson <tomh@tomh.org>
parents: 10409
diff changeset
  1023
any objects are constructed, there are no such object instances around.
3d6f19ee0d30 clarify some points about the ConfigStore
Tom Henderson <tomh@tomh.org>
parents: 10409
diff changeset
  1024
(Note, future enhancements to the config store may change this behavior).
3d6f19ee0d30 clarify some points about the ConfigStore
Tom Henderson <tomh@tomh.org>
parents: 10409
diff changeset
  1025
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1026
Second, while the output of :cpp:class:`ConfigStore` state
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1027
will list everything in the database, the input file need only contain
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1028
the specific values to be overridden.  So, one way to use this class
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1029
for input file configuration is to generate an initial configuration
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1030
using the output (``"Save"``) ``"Mode"`` described above, extract from
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1031
that configuration file only the elements one wishes to change,
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1032
and move these minimal elements to a new configuration file
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1033
which can then safely be edited and loaded in a subsequent simulation run. 
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1034
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1035
When the :cpp:class:`ConfigStore` object is instantiated, its attributes
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1036
``"Filename"``, ``"Mode"``, and ``"FileFormat"`` must be set,
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1037
either *via* command-line or *via* program statements.  
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1038
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1039
Reading/Writing Example
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1040
+++++++++++++++++++++++
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1041
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1042
As a more complicated example, let's assume that we want to read in a
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1043
configuration of defaults from an input file named ``input-defaults.xml``, and
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1044
write out the resulting attributes to a separate file called
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1045
``output-attributes.xml``.::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1046
6941
9d2c79c992d7 Split contrib module into config-store and tools
Mitch Watrous <watrous@u.washington.edu>
parents: 6766
diff changeset
  1047
    #include "ns3/config-store-module.h"
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1048
    ...
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1049
    int main (...)
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1050
    {
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1051
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1052
      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
  1053
      Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Load"));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1054
      Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1055
      ConfigStore inputConfig;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1056
      inputConfig.ConfigureDefaults ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1057
      
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1058
      //
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1059
      // Allow the user to override any of the defaults and the above Bind () at
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1060
      // run-time, viacommand-line arguments
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1061
      //
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1062
      CommandLine cmd;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1063
      cmd.Parse (argc, argv);
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1064
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1065
      // setup topology
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1066
      ...
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1067
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1068
      // Invoke just before entering Simulator::Run ()
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1069
      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
  1070
      Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1071
      ConfigStore outputConfig;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1072
      outputConfig.ConfigureAttributes ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1073
      Simulator::Run ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1074
    }
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1075
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1076
ConfigStore GUI
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1077
+++++++++++++++
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1078
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1079
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
  1080
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
  1081
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
  1082
presentation.
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1083
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1084
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
  1085
Ubuntu installation command is:
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1086
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
  1087
.. sourcecode:: bash
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
  1088
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
  1089
  $ 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
  1090
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
  1091
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
  1092
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
  1093
.. sourcecode:: bash
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
  1094
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
  1095
  $ ./waf configure --enable-examples --enable-tests
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1096
9162
b587372eb2de Minor fixes and corrections to manual formatting.
Vedran Miletić <rivanvx@gmail.com>
parents: 7818
diff changeset
  1097
  ---- Summary of optional NS-3 features:
b587372eb2de Minor fixes and corrections to manual formatting.
Vedran Miletić <rivanvx@gmail.com>
parents: 7818
diff changeset
  1098
  Python Bindings               : enabled
b587372eb2de Minor fixes and corrections to manual formatting.
Vedran Miletić <rivanvx@gmail.com>
parents: 7818
diff changeset
  1099
  Python API Scanning Support   : enabled
b587372eb2de Minor fixes and corrections to manual formatting.
Vedran Miletić <rivanvx@gmail.com>
parents: 7818
diff changeset
  1100
  NS-3 Click Integration        : enabled
b587372eb2de Minor fixes and corrections to manual formatting.
Vedran Miletić <rivanvx@gmail.com>
parents: 7818
diff changeset
  1101
  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
  1102
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1103
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
  1104
version is installed and:
9162
b587372eb2de Minor fixes and corrections to manual formatting.
Vedran Miletić <rivanvx@gmail.com>
parents: 7818
diff changeset
  1105
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
  1106
.. sourcecode:: bash
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
  1107
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
  1108
  $ ./waf configure --enable-examples --enable-tests
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9912
diff changeset
  1109
  $ ./waf
9162
b587372eb2de Minor fixes and corrections to manual formatting.
Vedran Miletić <rivanvx@gmail.com>
parents: 7818
diff changeset
  1110
b587372eb2de Minor fixes and corrections to manual formatting.
Vedran Miletić <rivanvx@gmail.com>
parents: 7818
diff changeset
  1111
is rerun.
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1112
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1113
Usage is almost the same as the non-GTK-based version, but there
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1114
are no :cpp:class:`ConfigStore` attributes involved::
6742
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1115
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1116
  // Invoke just before entering Simulator::Run ()
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1117
  GtkConfigStore config;
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1118
  config.ConfigureDefaults ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1119
  config.ConfigureAttributes ();
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1120
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1121
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
  1122
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
  1123
when you are done.  
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1124
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1125
Future work
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1126
+++++++++++
a1759a95842c convert manual to sphinx format
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1127
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
  1128
10868
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1129
* Save a unique version number with date and time at start of file.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1130
* Save rng initial seed somewhere.
ef7573b0eb30 [Sphinx] Attributes manual chapter
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10703
diff changeset
  1131
* Make each RandomVariable serialize its own initial seed and re-read it later.