View | Details | Raw Unified | Return to bug 215
Collapse All | Expand All

(-)a/examples/csma-star.cc (-3 / +3 lines)
 Lines 23-39    Link Here 
23
23
24
// Network topology (default)
24
// Network topology (default)
25
//
25
//
26
//            n2     +          +     n3          .
26
//            n3     +          +     n2          .
27
//             | ... |\        /| ... |           .
27
//             | ... |\        /| ... |           .
28
//             ======= \      / =======           .
28
//             ======= \      / =======           .
29
//              CSMA    \    /   CSMA             .
29
//              CSMA    \    /   CSMA             .
30
//                       \  /                     .
30
//                       \  /                     .
31
//            n1     +--- n0 ---+     n4          .
31
//            n4     +--- n0 ---+     n1          .
32
//             | ... |   /  \   | ... |           .
32
//             | ... |   /  \   | ... |           .
33
//             =======  /    \  =======           .
33
//             =======  /    \  =======           .
34
//              CSMA   /      \  CSMA             .
34
//              CSMA   /      \  CSMA             .
35
//                    /        \                  .
35
//                    /        \                  .
36
//            n6     +          +     n5          .
36
//            n5     +          +     n6          .
37
//             | ... |          | ... |           .
37
//             | ... |          | ... |           .
38
//             =======          =======           .
38
//             =======          =======           .
39
//              CSMA             CSMA             .
39
//              CSMA             CSMA             .
(-)a/src/core/wscript (+2 lines)
 Lines 73-78   def build(bld): Link Here 
73
        'trace-source-accessor.cc',
73
        'trace-source-accessor.cc',
74
        'config.cc',
74
        'config.cc',
75
        'callback.cc',
75
        'callback.cc',
76
        'name-list.cc',
76
        ]
77
        ]
77
    core.uselib = 'RT'
78
    core.uselib = 'RT'
78
79
 Lines 118-123   def build(bld): Link Here 
118
        'object-vector.h',
119
        'object-vector.h',
119
        'deprecated.h',
120
        'deprecated.h',
120
        'abort.h',
121
        'abort.h',
122
        'name-list.h',
121
        ]
123
        ]
122
124
123
    if sys.platform == 'win32':
125
    if sys.platform == 'win32':
(-)a/src/devices/wifi/dca-txop.cc (-5 / +9 lines)
 Lines 475-480   DcaTxop::MissedCts (void) Link Here 
475
      MY_DEBUG ("Cts Fail");
475
      MY_DEBUG ("Cts Fail");
476
      WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
476
      WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
477
      station->ReportFinalRtsFailed ();
477
      station->ReportFinalRtsFailed ();
478
      if (!m_txFailedCallback.IsNull ()) 
479
        {
480
          m_txFailedCallback (m_currentHdr);
481
        }
478
      // to reset the dcf.
482
      // to reset the dcf.
479
      m_currentPacket = 0;
483
      m_currentPacket = 0;
480
      m_dcf->ResetCw ();
484
      m_dcf->ResetCw ();
 Lines 522-528   DcaTxop::MissedAck (void) Link Here 
522
      MY_DEBUG ("Ack Fail");
526
      MY_DEBUG ("Ack Fail");
523
      WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
527
      WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
524
      station->ReportFinalDataFailed ();
528
      station->ReportFinalDataFailed ();
525
      // to reset the dcf.    
529
      if (!m_txFailedCallback.IsNull ()) 
530
        {
531
          m_txFailedCallback (m_currentHdr);
532
        }
533
      // to reset the dcf.
526
      m_currentPacket = 0;
534
      m_currentPacket = 0;
527
      m_dcf->ResetCw ();
535
      m_dcf->ResetCw ();
528
    } 
536
    } 
 Lines 530-539   DcaTxop::MissedAck (void) Link Here 
530
    {
538
    {
531
      MY_DEBUG ("Retransmit");
539
      MY_DEBUG ("Retransmit");
532
      m_currentHdr.SetRetry ();
540
      m_currentHdr.SetRetry ();
533
      if (!m_txFailedCallback.IsNull ()) 
534
        {
535
          m_txFailedCallback (m_currentHdr);
536
        }
537
      m_dcf->UpdateFailedCw ();
541
      m_dcf->UpdateFailedCw ();
538
    }
542
    }
539
  m_dcf->StartBackoffNow (m_rng->GetNext (0, m_dcf->GetCw ()));
543
  m_dcf->StartBackoffNow (m_rng->GetNext (0, m_dcf->GetCw ()));
(-)4aff71a211f5 (+297 lines)
Added Link Here 
1
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2008 University of Washington
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License version 2 as
7
 * published by the Free Software Foundation;
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 */
18
19
#include "ns3/object.h"
20
#include "ns3/log.h"
21
#include "ns3/assert.h"
22
#include "ns3/abort.h"
23
#include "ns3/simulator.h"
24
#include "name-list.h"
25
26
namespace ns3 {
27
28
NS_LOG_COMPONENT_DEFINE ("NameList");
29
30
/**
31
 * \brief private implementation detail of the NameList API.
32
 */
33
class NameListPriv 
34
{
35
public:
36
  NameListPriv ();
37
  ~NameListPriv ();
38
39
  bool Add (Ptr<Object> obj, std::string name);
40
  Ptr<Object> GetObjectOfName (std::string name);
41
42
  static NameListPriv *Get (void);
43
  
44
private:
45
  static NameListPriv **DoGet (void);
46
47
  static void Delete (void);
48
  std::vector<std::pair<Ptr<Object>, std::string> > m_names;
49
};
50
51
NameListPriv *
52
NameListPriv::Get (void)
53
{
54
  return *(DoGet ());
55
}
56
57
NameListPriv **
58
NameListPriv::DoGet (void)
59
{
60
  NS_LOG_FUNCTION_NOARGS ();
61
62
  //
63
  // ptr is declared as a function-local static variable.  This variable is 
64
  // guaranteed to be initialized to zero (by code generated by the compiler)
65
  // the first time the function is called.  Afterward it acts like a global
66
  // variable whose scope is defined by the function.
67
  //
68
  static NameListPriv *ptr = 0;
69
70
  //
71
  // We "piggyback" on the guaranteed initialization of ptr to zero and do
72
  // essentially the same thing the compiler did there in order to create
73
  // the private object one time.  This is a simple way to implement a 
74
  // singleton (a simpleton?).
75
  //
76
  if (ptr == 0)
77
    {
78
      ptr = new NameListPriv;
79
      Simulator::ScheduleDestroy (&NameListPriv::Delete);
80
    }
81
  //
82
  // Returns a pointer to the pointer to the name list implementation object.
83
  // Why?  See NameListPriv::Delete
84
  //
85
  return &ptr;
86
}
87
88
void 
89
NameListPriv::Delete (void)
90
{
91
  NS_LOG_FUNCTION_NOARGS ();
92
93
  //
94
  // DoGet returns a pointer to a pointer to the private implementation.  We
95
  // need to call the destructor on the pointer, and also set the pointer 
96
  // itself to zero to complete the teardown.
97
  //
98
  NameListPriv **ptr = DoGet ();
99
  // 
100
  // This is a sneaky, behind the sheets way to get the object pointed to by the 
101
  // function local variable ptr, with scope up in DoGet, torn down and the 
102
  // pointer set to zero.
103
  //
104
  delete *ptr;
105
  *ptr = 0;
106
}
107
108
NameListPriv::NameListPriv ()
109
{
110
  NS_LOG_FUNCTION_NOARGS ();
111
}
112
113
NameListPriv::~NameListPriv ()
114
{
115
  NS_LOG_FUNCTION_NOARGS ();
116
  
117
  //
118
  // Clean up the list of names we have stored.  This function is expected to be
119
  // called during Simulator::Destroy
120
  //
121
  for (std::vector<std::pair<Ptr<Object>, std::string> >::iterator i = m_names.begin (); i != m_names.end (); ++i)
122
    {
123
      //
124
      // We just decrement the reference count here.  We leave it to others,
125
      // for example the node list, to call dispose.
126
      //
127
      Ptr<Object> object = i->first;
128
      i->first = 0;
129
    }
130
  //
131
  // get rid of all of the <object, name> pairs in the underlying vector.
132
  //
133
  m_names.erase (m_names.begin (), m_names.end ());
134
}
135
136
bool
137
NameListPriv::Add (Ptr<Object> object, std::string name)
138
{
139
  //
140
  // We demand that all objects have a unique name in this particular namespace.
141
  // If the proposed name is unique, we add it to the collection and return true.
142
  // If there is an existing name in the collection, then we refuse to add it 
143
  // and return false.  
144
  //
145
  if (GetObjectOfName (name) == 0)
146
    {
147
      m_names.push_back (std::make_pair (object, name));
148
      return true;
149
    }
150
  else
151
    {
152
      return false;
153
    }
154
}
155
156
Ptr<Object>
157
NameListPriv::GetObjectOfName (std::string name)
158
{
159
  NS_LOG_FUNCTION (name);
160
161
  // 
162
  // Just do a simple, old-fashioned, linear search through the name/object mappings
163
  // for a name match.  If we find an object of the given name, return its Ptr.  The
164
  // inability to find an object/name pair is reflected by returning a zero Ptr.
165
  //
166
  for (std::vector<std::pair<Ptr<Object>, std::string> >::iterator i = m_names.begin (); i != m_names.end (); ++i)
167
    {
168
      if (i->second == name)
169
        {
170
          return i->first;
171
        }
172
    }
173
  return 0;
174
}
175
176
}
177
178
namespace ns3 {
179
180
bool
181
NameList::Add (Ptr<Object> object, std::string name)
182
{
183
  return NameListPriv::Get ()->Add (object, name);
184
}
185
186
Ptr<Object>
187
NameList::GetObjectOfNameInternal (std::string name)
188
{
189
  return NameListPriv::Get ()->GetObjectOfName (name);
190
}
191
192
}//namespace ns3
193
194
#ifdef RUN_SELF_TESTS
195
196
#include "test.h"
197
#include "object-factory.h"
198
199
namespace {
200
201
class TestObject : public ns3::Object
202
{
203
public:
204
  static ns3::TypeId GetTypeId (void) 
205
  {
206
    static ns3::TypeId tid = ns3::TypeId ("TestObject")
207
      .SetParent (Object::GetTypeId ())
208
      .HideFromDocumentation ()
209
      .AddConstructor<TestObject> ();
210
    return tid;
211
  }
212
  TestObject () {}
213
  virtual void Dispose (void) {}
214
};
215
216
class FakeTestObject : public ns3::Object
217
{
218
public:
219
  static ns3::TypeId GetTypeId (void) 
220
  {
221
    static ns3::TypeId tid = ns3::TypeId ("FaleTestObject")
222
      .SetParent (Object::GetTypeId ())
223
      .HideFromDocumentation ()
224
      .AddConstructor<TestObject> ();
225
    return tid;
226
  }
227
  FakeTestObject () {}
228
  virtual void Dispose (void) {}
229
};
230
231
} // namespace anonymous
232
233
namespace ns3 {
234
235
class NameListTest : public Test
236
{
237
public:
238
  NameListTest ();
239
  virtual bool RunTests (void);
240
};
241
242
NameListTest::NameListTest ()
243
  : Test ("NameList")
244
{
245
}
246
247
bool 
248
NameListTest::RunTests (void)
249
{
250
  bool result = true;
251
252
  std::string name1 = "Test Object 1";
253
  Ptr<TestObject> obj1 = CreateObject<TestObject> ();
254
255
  result = NameList::Add (obj1, name1);
256
  NS_TEST_ASSERT_EQUAL (result, true);
257
258
  result = NameList::Add (obj1, name1);
259
  NS_TEST_ASSERT_EQUAL (result, false);
260
261
  std::string name2 = "Test Object 2";
262
  Ptr<TestObject> obj2 = CreateObject<TestObject> ();
263
264
  result = NameList::Add (obj2, name2);
265
  NS_TEST_ASSERT_EQUAL (result, true);
266
267
  Ptr<TestObject> obj = NameList::GetObjectOfName<TestObject> (name1);
268
  NS_TEST_ASSERT_EQUAL (obj, obj1);
269
270
  Ptr<FakeTestObject> fobj = NameList::GetObjectOfName<FakeTestObject> (name1);
271
  NS_TEST_ASSERT_EQUAL (fobj, 0);
272
273
  obj = NameList::GetObjectOfName<TestObject> (name2);
274
  NS_TEST_ASSERT_EQUAL (obj, obj2);
275
276
  obj = NameList::GetObjectOfName<TestObject> ("yadda");
277
  NS_TEST_ASSERT_EQUAL (obj, 0);
278
279
  //
280
  // Run the simulator and destroy it to get the Destroy method called on the
281
  // private implementation object.  We don't hack in a way here to get access
282
  // to the raw pointer and assert that it is zeroed since taht really doesn't
283
  // tell us that the memory allcated during the tests has successfully been 
284
  // released.  Instead we depend on seeing a valgrind-clean run of the unit 
285
  // tests to really determine if the clean up was successful.
286
  //
287
  Simulator::Run ();
288
  Simulator::Destroy ();
289
  
290
  return result;
291
}
292
293
static NameListTest g_nameListTests;
294
295
} // namespace ns3
296
297
#endif /* RUN_SELF_TESTS */
(-)4aff71a211f5 (+80 lines)
Added Link Here 
1
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2008 University of Washington
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License version 2 as
7
 * published by the Free Software Foundation;
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 */
18
19
#ifndef NAME_LIST_H
20
#define NAME_LIST_H
21
22
#include <vector>
23
#include "ns3/ptr.h"
24
#include "ns3/object.h"
25
26
namespace ns3 {
27
28
/**
29
 * \brief A container of name and Ptr<Object> associations that allows us to
30
 * give any ns3 Object a name.  This is a flat namespace and we require all
31
 * names to be unique.
32
 */
33
class NameList
34
{
35
public:
36
  /**
37
   * \brief Add an object to name association to the global name list.  The
38
   * provided name string must be unique in the flat object name space.
39
   *
40
   * \param object Ptr<Object> to the object we want to associate a name with.
41
   * \param name String containing the name of the object.
42
   * \returns True if the <object, name> pair is successfully added or false
43
   * if the name already exists in the namespace.
44
   */
45
  static bool Add (Ptr<Object> object, std::string name);
46
47
  /**
48
   * \brief Retrieve an object of a given name from the global name list.
49
   *
50
   * \param name String containing the name of the object.
51
   * \returns Ptr to the object associated with the parameter name if one 
52
   * exists otherwise the null Ptr.
53
   */
54
  template <typename T>
55
  static Ptr<T> GetObjectOfName (std::string name);
56
57
private:
58
  static Ptr<Object> GetObjectOfNameInternal (std::string name);
59
60
};
61
62
template <typename T>
63
Ptr<T> 
64
NameList::GetObjectOfName (std::string name)
65
{
66
  Ptr<Object> obj = NameList::GetObjectOfNameInternal (name);
67
  if (obj)
68
    {
69
      return obj->GetObject<T> ();
70
    }
71
  else
72
    {
73
      return 0;
74
    }
75
}
76
77
78
}//namespace ns3
79
80
#endif /* NAME_LIST_H */
(-)a/src/core/name-list.cc (-8 / +67 lines)
 Lines 16-21    Link Here 
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 */
17
 */
18
18
19
#include <vector>
19
#include "ns3/object.h"
20
#include "ns3/object.h"
20
#include "ns3/log.h"
21
#include "ns3/log.h"
21
#include "ns3/assert.h"
22
#include "ns3/assert.h"
 Lines 26-31   namespace ns3 { Link Here 
26
namespace ns3 {
27
namespace ns3 {
27
28
28
NS_LOG_COMPONENT_DEFINE ("NameList");
29
NS_LOG_COMPONENT_DEFINE ("NameList");
30
31
class NameListNode
32
{
33
public:
34
  NameListNode () {}
35
  ~NameListNode () {m_children.clear ();}
36
37
  uint32_t GetNChildren () {return m_children.size ();}
38
  NameListNode *GetChild (uint32_t n) {return m_children[n];}
39
  void AddChild (NameListNode *child) {m_children.push_back (child);}
40
  void SetName (std::string name) {m_name = name;}
41
private:
42
  std::vector<NameListNode *> m_children;
43
  std::string m_name;
44
};
29
45
30
/**
46
/**
31
 * \brief private implementation detail of the NameList API.
47
 * \brief private implementation detail of the NameList API.
 Lines 38-43   public: Link Here 
38
54
39
  bool Add (Ptr<Object> obj, std::string name);
55
  bool Add (Ptr<Object> obj, std::string name);
40
  Ptr<Object> GetObjectOfName (std::string name);
56
  Ptr<Object> GetObjectOfName (std::string name);
57
  std::string GetNameOfObject (Ptr<Object> object);
41
58
42
  static NameListPriv *Get (void);
59
  static NameListPriv *Get (void);
43
  
60
  
 Lines 137-148   NameListPriv::Add (Ptr<Object> object, s Link Here 
137
NameListPriv::Add (Ptr<Object> object, std::string name)
154
NameListPriv::Add (Ptr<Object> object, std::string name)
138
{
155
{
139
  //
156
  //
140
  // We demand that all objects have a unique name in this particular namespace.
157
  // This class operates sort of like a bidirectional map, so we demand that all
141
  // If the proposed name is unique, we add it to the collection and return true.
158
  // objects and names are unique..
142
  // If there is an existing name in the collection, then we refuse to add it 
143
  // and return false.  
144
  //
159
  //
145
  if (GetObjectOfName (name) == 0)
160
  if (GetObjectOfName (name) == 0 && GetNameOfObject (object).empty ())
146
    {
161
    {
147
      m_names.push_back (std::make_pair (object, name));
162
      m_names.push_back (std::make_pair (object, name));
148
      return true;
163
      return true;
 Lines 173-181   NameListPriv::GetObjectOfName (std::stri Link Here 
173
  return 0;
188
  return 0;
174
}
189
}
175
190
191
std::string
192
NameListPriv::GetNameOfObject (Ptr<Object> object)
193
{
194
  NS_LOG_FUNCTION (object);
195
196
  // 
197
  // Just do a simple, old-fashioned, linear search through the name/object mappings
198
  // for an object match.  If we find an object of the given name, return its name.  The
199
  // inability to find an object/name pair is reflected by returning an empty string.
200
  //
201
  for (std::vector<std::pair<Ptr<Object>, std::string> >::iterator i = m_names.begin (); i != m_names.end (); ++i)
202
    {
203
      if (i->first == object)
204
        {
205
          return i->second;
206
        }
207
    }
208
  return std::string ();
176
}
209
}
177
178
namespace ns3 {
179
210
180
bool
211
bool
181
NameList::Add (Ptr<Object> object, std::string name)
212
NameList::Add (Ptr<Object> object, std::string name)
 Lines 187-192   NameList::GetObjectOfNameInternal (std:: Link Here 
187
NameList::GetObjectOfNameInternal (std::string name)
218
NameList::GetObjectOfNameInternal (std::string name)
188
{
219
{
189
  return NameListPriv::Get ()->GetObjectOfName (name);
220
  return NameListPriv::Get ()->GetObjectOfName (name);
221
}
222
223
std::string
224
NameList::GetNameOfObject (Ptr<Object> object)
225
{
226
  return NameListPriv::Get ()->GetNameOfObject (object);
190
}
227
}
191
228
192
}//namespace ns3
229
}//namespace ns3
 Lines 252-261   NameListTest::RunTests (void) Link Here 
252
  std::string name1 = "Test Object 1";
289
  std::string name1 = "Test Object 1";
253
  Ptr<TestObject> obj1 = CreateObject<TestObject> ();
290
  Ptr<TestObject> obj1 = CreateObject<TestObject> ();
254
291
292
  // 
293
  // Put an <object, name> pair into the name list
294
  //
255
  result = NameList::Add (obj1, name1);
295
  result = NameList::Add (obj1, name1);
256
  NS_TEST_ASSERT_EQUAL (result, true);
296
  NS_TEST_ASSERT_EQUAL (result, true);
257
297
258
  result = NameList::Add (obj1, name1);
298
  //
299
  // We shouldn't be able to put another pair into the list with either the same
300
  // name or same object in it.
301
  //
302
  Ptr<TestObject> someOtherObject = CreateObject<TestObject> ();
303
304
  result = NameList::Add (someOtherObject, name1);
305
  NS_TEST_ASSERT_EQUAL (result, false);
306
307
  result = NameList::Add (obj1, "Some other name");
259
  NS_TEST_ASSERT_EQUAL (result, false);
308
  NS_TEST_ASSERT_EQUAL (result, false);
260
309
261
  std::string name2 = "Test Object 2";
310
  std::string name2 = "Test Object 2";
 Lines 267-280   NameListTest::RunTests (void) Link Here 
267
  Ptr<TestObject> obj = NameList::GetObjectOfName<TestObject> (name1);
316
  Ptr<TestObject> obj = NameList::GetObjectOfName<TestObject> (name1);
268
  NS_TEST_ASSERT_EQUAL (obj, obj1);
317
  NS_TEST_ASSERT_EQUAL (obj, obj1);
269
318
319
  std::string name = NameList::GetNameOfObject (obj);
320
  NS_TEST_ASSERT_EQUAL (name, name1);
321
270
  Ptr<FakeTestObject> fobj = NameList::GetObjectOfName<FakeTestObject> (name1);
322
  Ptr<FakeTestObject> fobj = NameList::GetObjectOfName<FakeTestObject> (name1);
271
  NS_TEST_ASSERT_EQUAL (fobj, 0);
323
  NS_TEST_ASSERT_EQUAL (fobj, 0);
272
324
273
  obj = NameList::GetObjectOfName<TestObject> (name2);
325
  obj = NameList::GetObjectOfName<TestObject> (name2);
274
  NS_TEST_ASSERT_EQUAL (obj, obj2);
326
  NS_TEST_ASSERT_EQUAL (obj, obj2);
275
327
328
  name = NameList::GetNameOfObject (obj);
329
  NS_TEST_ASSERT_EQUAL (name, name2);
330
276
  obj = NameList::GetObjectOfName<TestObject> ("yadda");
331
  obj = NameList::GetObjectOfName<TestObject> ("yadda");
277
  NS_TEST_ASSERT_EQUAL (obj, 0);
332
  NS_TEST_ASSERT_EQUAL (obj, 0);
333
334
  Ptr<TestObject> objx = CreateObject<TestObject> ();
335
  name = NameList::GetNameOfObject (obj);
336
  NS_TEST_ASSERT_EQUAL (name.empty (), true);
278
337
279
  //
338
  //
280
  // Run the simulator and destroy it to get the Destroy method called on the
339
  // Run the simulator and destroy it to get the Destroy method called on the
(-)a/src/core/name-list.h (+2 lines)
 Lines 54-59   public: Link Here 
54
  template <typename T>
54
  template <typename T>
55
  static Ptr<T> GetObjectOfName (std::string name);
55
  static Ptr<T> GetObjectOfName (std::string name);
56
56
57
  static std::string GetNameOfObject (Ptr<Object> object);
58
57
private:
59
private:
58
  static Ptr<Object> GetObjectOfNameInternal (std::string name);
60
  static Ptr<Object> GetObjectOfNameInternal (std::string name);
59
61
(-)a/examples/csma-one-subnet.cc (-6 / +32 lines)
 Lines 64-69   main (int argc, char *argv[]) Link Here 
64
  NodeContainer nodes;
64
  NodeContainer nodes;
65
  nodes.Create (4);
65
  nodes.Create (4);
66
66
67
//
68
// Associate human readable names with some of the nodes so we can refer to them 
69
// easily.
70
//
71
  NameList::Add (nodes.Get (0), "Node 0");
72
  NameList::Add (nodes.Get (1), "Node 1");
73
  NameList::Add (nodes.Get (3), "Node 3");
74
67
  NS_LOG_INFO ("Build Topology");
75
  NS_LOG_INFO ("Build Topology");
68
  CsmaHelper csma;
76
  CsmaHelper csma;
69
  csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
77
  csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
 Lines 74-82   main (int argc, char *argv[]) Link Here 
74
//
82
//
75
  NetDeviceContainer devices = csma.Install (nodes);
83
  NetDeviceContainer devices = csma.Install (nodes);
76
84
85
//
86
// Associate human readable names with some of the devices so we can refer to them 
87
// easily.  Recall that the CsmaHelper will return a container arranged so the zeroth
88
// device in the returned container corresponds to the zeroth node in the node 
89
// container passed as a parameter.
90
//
91
  NameList::Add (devices.Get (0), "Node 0/eth0");
92
  NameList::Add (devices.Get (1), "Node 1/eth0");
93
  NameList::Add (devices.Get (3), "Node 3/eth0");
94
77
  InternetStackHelper internet;
95
  InternetStackHelper internet;
78
  internet.Install (nodes);
96
  internet.Install (nodes);
79
97
98
//
80
// We've got the "hardware" in place.  Now we need to add IP addresses.
99
// We've got the "hardware" in place.  Now we need to add IP addresses.
81
//
100
//
82
  NS_LOG_INFO ("Assign IP Addresses.");
101
  NS_LOG_INFO ("Assign IP Addresses.");
 Lines 85-91   main (int argc, char *argv[]) Link Here 
85
  Ipv4InterfaceContainer interfaces = ipv4.Assign (devices);
104
  Ipv4InterfaceContainer interfaces = ipv4.Assign (devices);
86
105
87
//
106
//
88
// Create an OnOff application to send UDP datagrams from node zero to node 1.
107
// Associate human readable names with some of the Ipv4 Interfaces so we can 
108
// refer to them easily.
109
//
110
  NameList::Add (interfaces.GetInterface (0), "Node 0/ipv4");
111
  NameList::Add (interfaces.GetInterface (1), "Node 1/ipv4");
112
113
//
114
// Create an OnOff application to send UDP datagrams from "Node 0" to "Node 1".
89
//
115
//
90
  NS_LOG_INFO ("Create Applications.");
116
  NS_LOG_INFO ("Create Applications.");
91
  uint16_t port = 9;   // Discard port (RFC 863)
117
  uint16_t port = 9;   // Discard port (RFC 863)
 Lines 95-101   main (int argc, char *argv[]) Link Here 
95
  onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
121
  onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
96
  onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
122
  onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
97
123
98
  ApplicationContainer app = onoff.Install (nodes.Get (0));
124
  ApplicationContainer app = onoff.Install (NameList::GetObjectOfName<Node> ("Node 0"));
99
  // Start the application
125
  // Start the application
100
  app.Start (Seconds (1.0));
126
  app.Start (Seconds (1.0));
101
  app.Stop (Seconds (10.0));
127
  app.Stop (Seconds (10.0));
 Lines 103-121   main (int argc, char *argv[]) Link Here 
103
  // Create an optional packet sink to receive these packets
129
  // Create an optional packet sink to receive these packets
104
  PacketSinkHelper sink ("ns3::UdpSocketFactory",
130
  PacketSinkHelper sink ("ns3::UdpSocketFactory",
105
    Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
131
    Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
106
  app = sink.Install (nodes.Get (1));
132
  app = sink.Install (NameList::GetObjectOfName<Node> ("Node 1"));
107
  app.Start (Seconds (0.0));
133
  app.Start (Seconds (0.0));
108
134
109
// 
135
// 
110
// Create a similar flow from n3 to n0, starting at time 1.1 seconds
136
// Create a similar flow from "Node 3" to "Node 0", starting at time 1.1 seconds
111
//
137
//
112
  onoff.SetAttribute ("Remote", 
138
  onoff.SetAttribute ("Remote", 
113
                      AddressValue (InetSocketAddress (interfaces.GetAddress (0), port)));
139
                      AddressValue (InetSocketAddress (interfaces.GetAddress (0), port)));
114
  app = onoff.Install (nodes.Get (3));
140
  app = onoff.Install (NameList::GetObjectOfName<Node> ("Node 3"));
115
  app.Start(Seconds (1.1));
141
  app.Start(Seconds (1.1));
116
  app.Stop (Seconds (10.0));
142
  app.Stop (Seconds (10.0));
117
143
118
  app = sink.Install (nodes.Get (0));
144
  app = sink.Install (NameList::GetObjectOfName<Node> ("Node 0"));
119
  app.Start (Seconds (0.0));
145
  app.Start (Seconds (0.0));
120
146
121
//
147
//
(-)a/src/helper/ipv4-interface-container.cc (+7 lines)
 Lines 28-33   Ipv4InterfaceContainer::GetAddress (uint Link Here 
28
  uint32_t interface = m_interfaces[i].second;
28
  uint32_t interface = m_interfaces[i].second;
29
  return ipv4->GetAddress (interface);
29
  return ipv4->GetAddress (interface);
30
}
30
}
31
32
Ptr<Ipv4>
33
Ipv4InterfaceContainer::GetInterface (uint32_t i) const
34
{
35
  return m_interfaces[i].first;
36
}
37
31
void 
38
void 
32
Ipv4InterfaceContainer::SetMetric (uint32_t i, uint16_t metric)
39
Ipv4InterfaceContainer::SetMetric (uint32_t i, uint16_t metric)
33
{
40
{
(-)a/src/helper/ipv4-interface-container.h (+3 lines)
 Lines 31-36   public: Link Here 
31
  uint32_t GetN (void) const;
31
  uint32_t GetN (void) const;
32
32
33
  Ipv4Address GetAddress (uint32_t i) const;
33
  Ipv4Address GetAddress (uint32_t i) const;
34
35
  Ptr<Ipv4> GetInterface (uint32_t i) const;
36
34
  void SetMetric (uint32_t i, uint16_t metric);
37
  void SetMetric (uint32_t i, uint16_t metric);
35
38
36
  void Add (Ptr<Ipv4> ipv4, uint32_t interface);
39
  void Add (Ptr<Ipv4> ipv4, uint32_t interface);
(-)a/examples/csma-one-subnet.cc (-1 / +7 lines)
 Lines 47-62   main (int argc, char *argv[]) Link Here 
47
#if 0 
47
#if 0 
48
  LogComponentEnable ("CsmaOneSubnetExample", LOG_LEVEL_INFO);
48
  LogComponentEnable ("CsmaOneSubnetExample", LOG_LEVEL_INFO);
49
#endif
49
#endif
50
50
//
51
//
51
// Make the random number generators generate reproducible results.
52
// Make the random number generators generate reproducible results.
52
//
53
//
53
  RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8);
54
  RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8);
55
54
//
56
//
55
// Allow the user to override any of the defaults and the above Bind() at
57
// Allow the user to override any of the defaults and the above Bind() at
56
// run-time, via command-line arguments
58
// run-time, via command-line arguments
57
//
59
//
58
  CommandLine cmd;
60
  CommandLine cmd;
59
  cmd.Parse (argc, argv);
61
  cmd.Parse (argc, argv);
62
60
//
63
//
61
// Explicitly create the nodes required by the topology (shown above).
64
// Explicitly create the nodes required by the topology (shown above).
62
//
65
//
 Lines 76-81   main (int argc, char *argv[]) Link Here 
76
  CsmaHelper csma;
79
  CsmaHelper csma;
77
  csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
80
  csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
78
  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
81
  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
82
79
//
83
//
80
// Now fill out the topology by creating the net devices required to connect
84
// Now fill out the topology by creating the net devices required to connect
81
// the nodes to the channels and hooking them up.
85
// the nodes to the channels and hooking them up.
 Lines 159-165   main (int argc, char *argv[]) Link Here 
159
// and can be read by the "tcpdump -r" command (use "-tt" option to
163
// and can be read by the "tcpdump -r" command (use "-tt" option to
160
// display timestamps correctly)
164
// display timestamps correctly)
161
//
165
//
162
  CsmaHelper::EnablePcapAll ("csma-one-subnet");
166
  CsmaHelper::EnablePcap ("csma-one-subnet", "Node 0/eth0");
167
  CsmaHelper::EnablePcap ("csma-one-subnet", "Node 1/eth0");
168
  CsmaHelper::EnablePcap ("csma-one-subnet", "Node 3/eth0");
163
//
169
//
164
// Now, do the actual simulation.
170
// Now, do the actual simulation.
165
//
171
//
(-)a/src/helper/csma-helper.cc (+11 lines)
 Lines 25-31    Link Here 
25
#include "ns3/csma-channel.h"
25
#include "ns3/csma-channel.h"
26
#include "ns3/pcap-writer.h"
26
#include "ns3/pcap-writer.h"
27
#include "ns3/config.h"
27
#include "ns3/config.h"
28
#include "ns3/name-list.h"
28
#include "ns3/packet.h"
29
#include "ns3/packet.h"
30
#include "ns3/abort.h"
29
#include <string>
31
#include <string>
30
32
31
namespace ns3 {
33
namespace ns3 {
 Lines 96-101   CsmaHelper::EnablePcap (std::string file Link Here 
96
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Enqueue";
98
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Enqueue";
97
  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&CsmaHelper::EnqueueEvent, pcap));
99
  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&CsmaHelper::EnqueueEvent, pcap));
98
}
100
}
101
102
void
103
CsmaHelper::EnablePcap (std::string filename, std::string devname)
104
{
105
  Ptr<CsmaNetDevice> device = NameList::GetObjectOfName<CsmaNetDevice> (devname);
106
  NS_ABORT_MSG_UNLESS (device, "CsmaHelper::EnablePcap(): Device name not found");
107
  EnablePcap (filename, device->GetNode ()->GetId (), device->GetIfIndex ());
108
}
109
99
void 
110
void 
100
CsmaHelper::EnablePcap (std::string filename, NetDeviceContainer d)
111
CsmaHelper::EnablePcap (std::string filename, NetDeviceContainer d)
101
{
112
{
(-)a/src/helper/csma-helper.h (+7 lines)
 Lines 96-101   public: Link Here 
96
   * been fully constructed.
96
   * been fully constructed.
97
   */
97
   */
98
  static void EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid);
98
  static void EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid);
99
  /**
100
   * \param filename filename prefix to use for pcap files.
101
   * \param devname the name of a device stored in the NameList.
102
   *
103
   * Enable pcap output on the device specified by name
104
   */
105
  static void EnablePcap (std::string filename, std::string devname);
99
  /**
106
  /**
100
   * \param filename filename prefix to use for pcap files.
107
   * \param filename filename prefix to use for pcap files.
101
   * \param d container of devices of type ns3::CsmaNetDevice
108
   * \param d container of devices of type ns3::CsmaNetDevice
(-)a/src/helper/emu-helper.cc (-1 / +10 lines)
 Lines 25-32    Link Here 
25
#include "ns3/emu-net-device.h"
25
#include "ns3/emu-net-device.h"
26
#include "ns3/pcap-writer.h"
26
#include "ns3/pcap-writer.h"
27
#include "ns3/config.h"
27
#include "ns3/config.h"
28
#include "ns3/name-list.h"
28
#include "ns3/packet.h"
29
#include "ns3/packet.h"
29
30
#include "ns3/abort.h"
30
#include "emu-helper.h"
31
#include "emu-helper.h"
31
32
32
NS_LOG_COMPONENT_DEFINE ("EmuHelper");
33
NS_LOG_COMPONENT_DEFINE ("EmuHelper");
 Lines 87-92   EmuHelper::EnablePcap ( Link Here 
87
    "/$ns3::EmuNetDevice/TxQueue/Enqueue";
88
    "/$ns3::EmuNetDevice/TxQueue/Enqueue";
88
  Config::ConnectWithoutContext (oss.str (), 
89
  Config::ConnectWithoutContext (oss.str (), 
89
    MakeBoundCallback (&EmuHelper::EnqueueEvent, pcap));
90
    MakeBoundCallback (&EmuHelper::EnqueueEvent, pcap));
91
}
92
93
void
94
EmuHelper::EnablePcap (std::string filename, std::string devname)
95
{
96
  Ptr<EmuNetDevice> device = NameList::GetObjectOfName<EmuNetDevice> (devname);
97
  NS_ABORT_MSG_UNLESS (device, "EmuHelper::EnablePcap(): Device name not found");
98
  EnablePcap (filename, device->GetNode ()->GetId (), device->GetIfIndex ());
90
}
99
}
91
100
92
  void 
101
  void 
(-)a/src/helper/emu-helper.h (-2 / +9 lines)
 Lines 81-88   public: Link Here 
81
   * This method should be invoked after the network topology has 
81
   * This method should be invoked after the network topology has 
82
   * been fully constructed.
82
   * been fully constructed.
83
   */
83
   */
84
  static void EnablePcap (std::string filename, uint32_t nodeid, 
84
  static void EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid);
85
    uint32_t deviceid);
85
86
  /**
87
   * \param filename filename prefix to use for pcap files.
88
   * \param devname name of device
89
   *
90
   * Enable pcap output on the named device.
91
   */
92
  static void EnablePcap (std::string filename, std::string devname);
86
93
87
  /**
94
  /**
88
   * \param filename filename prefix to use for pcap files.
95
   * \param filename filename prefix to use for pcap files.
(-)a/src/helper/point-to-point-helper.cc (-2 / +11 lines)
 Lines 25-34    Link Here 
25
#include "ns3/pcap-writer.h"
25
#include "ns3/pcap-writer.h"
26
#include "ns3/config.h"
26
#include "ns3/config.h"
27
#include "ns3/packet.h"
27
#include "ns3/packet.h"
28
28
#include "ns3/name-list.h"
29
#include "ns3/abort.h"
29
30
30
namespace ns3 {
31
namespace ns3 {
31
32
32
33
PointToPointHelper::PointToPointHelper ()
33
PointToPointHelper::PointToPointHelper ()
34
{
34
{
 Lines 96-101   PointToPointHelper::EnablePcap (std::str Link Here 
96
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/TxQueue/Enqueue";
96
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/TxQueue/Enqueue";
97
  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PointToPointHelper::EnqueueEvent, pcap));
97
  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PointToPointHelper::EnqueueEvent, pcap));
98
}
98
}
99
100
void
101
PointToPointHelper::EnablePcap (std::string filename, std::string devname)
102
{
103
  Ptr<PointToPointNetDevice> device = NameList::GetObjectOfName<PointToPointNetDevice> (devname);
104
  NS_ABORT_MSG_UNLESS (device, "PointToPointHelper::EnablePcap(): Device name not found");
105
  EnablePcap (filename, device->GetNode ()->GetId (), device->GetIfIndex ());
106
}
107
99
void 
108
void 
100
PointToPointHelper::EnablePcap (std::string filename, NetDeviceContainer d)
109
PointToPointHelper::EnablePcap (std::string filename, NetDeviceContainer d)
101
{
110
{
(-)a/src/helper/point-to-point-helper.h (+9 lines)
 Lines 95-100   public: Link Here 
95
   * been fully constructed.
95
   * been fully constructed.
96
   */
96
   */
97
  static void EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid);
97
  static void EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid);
98
99
  /**
100
   * \param filename filename prefix to use for pcap files.
101
   * \param devname name of device
102
   *
103
   * Enable pcap output on the named device.
104
   */
105
  static void EnablePcap (std::string filename, std::string devname);
106
98
  /**
107
  /**
99
   * \param filename filename prefix to use for pcap files.
108
   * \param filename filename prefix to use for pcap files.
100
   * \param d container of devices of type ns3::PointToPointNetDevice
109
   * \param d container of devices of type ns3::PointToPointNetDevice
(-)a/src/helper/yans-wifi-phy-helper.cc (+11 lines)
 Lines 26-31    Link Here 
26
#include "ns3/wifi-net-device.h"
26
#include "ns3/wifi-net-device.h"
27
#include "ns3/pcap-writer.h"
27
#include "ns3/pcap-writer.h"
28
#include "ns3/simulator.h"
28
#include "ns3/simulator.h"
29
#include "ns3/name-list.h"
30
#include "ns3/abort.h"
29
#include "ns3/config.h"
31
#include "ns3/config.h"
30
32
31
namespace ns3 {
33
namespace ns3 {
 Lines 229-234   YansWifiPhyHelper::EnablePcap (std::stri Link Here 
229
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/RxOk";
231
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/RxOk";
230
  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PcapPhyRxEvent, pcap));
232
  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PcapPhyRxEvent, pcap));
231
}
233
}
234
235
void
236
YansWifiPhyHelper::EnablePcap (std::string filename, std::string devname)
237
{
238
  Ptr<NetDevice> device = NameList::GetObjectOfName<NetDevice> (devname);
239
  NS_ABORT_MSG_UNLESS (device, "YansWifiPhyHelper::EnablePcap(): Device name not found");
240
  EnablePcap (filename, device->GetNode ()->GetId (), device->GetIfIndex ());
241
}
242
232
void 
243
void 
233
YansWifiPhyHelper::EnablePcap (std::string filename, NetDeviceContainer d)
244
YansWifiPhyHelper::EnablePcap (std::string filename, NetDeviceContainer d)
234
{
245
{
(-)a/src/helper/yans-wifi-phy-helper.h (+9 lines)
 Lines 92-97   public: Link Here 
92
   * been fully constructed.
92
   * been fully constructed.
93
   */
93
   */
94
  static void EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid);
94
  static void EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid);
95
96
  /**
97
   * \param filename filename prefix to use for pcap files.
98
   * \param devname name of device
99
   *
100
   * Enable pcap output on the named device.
101
   */
102
  static void EnablePcap (std::string filename, std::string devname);
103
95
  /**
104
  /**
96
   * \param filename filename prefix to use for pcap files.
105
   * \param filename filename prefix to use for pcap files.
97
   * \param d container of devices of type ns3::WifiNetDevice
106
   * \param d container of devices of type ns3::WifiNetDevice
(-)a/src/core/name-list.cc (-15 lines)
 Lines 27-47   namespace ns3 { Link Here 
27
namespace ns3 {
27
namespace ns3 {
28
28
29
NS_LOG_COMPONENT_DEFINE ("NameList");
29
NS_LOG_COMPONENT_DEFINE ("NameList");
30
31
class NameListNode
32
{
33
public:
34
  NameListNode () {}
35
  ~NameListNode () {m_children.clear ();}
36
37
  uint32_t GetNChildren () {return m_children.size ();}
38
  NameListNode *GetChild (uint32_t n) {return m_children[n];}
39
  void AddChild (NameListNode *child) {m_children.push_back (child);}
40
  void SetName (std::string name) {m_name = name;}
41
private:
42
  std::vector<NameListNode *> m_children;
43
  std::string m_name;
44
};
45
30
46
/**
31
/**
47
 * \brief private implementation detail of the NameList API.
32
 * \brief private implementation detail of the NameList API.

Return to bug 215