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