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

(-)04170734fa8b (+142 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 */
16
17
// Network topology
18
//
19
//       n0    n1   n2   n3
20
//       |     |    |    |
21
//       =================
22
//              LAN
23
//
24
25
#include <fstream>
26
#include "ns3/core-module.h"
27
#include "ns3/simulator-module.h"
28
#include "ns3/helper-module.h"
29
30
using namespace ns3;
31
32
NS_LOG_COMPONENT_DEFINE ("NamesExample");
33
34
void 
35
RxEvent (std::string context, Ptr<const Packet> packet)
36
{
37
  NS_LOG_INFO (context << " packet " << packet);
38
}
39
40
int 
41
main (int argc, char *argv[])
42
{
43
  //
44
  // Users may find it convenient to turn on explicit debugging
45
  // for selected modules; the below lines suggest how to do this
46
  //
47
#if 1
48
  LogComponentEnable ("NamesExample", LOG_LEVEL_INFO);
49
#endif
50
51
  //
52
  // Allow the user to override any of the defaults and the above Bind() at
53
  // run-time, via command-line arguments
54
  //
55
  CommandLine cmd;
56
  cmd.Parse (argc, argv);
57
58
  //
59
  // Explicitly create the nodes required by the topology (shown above).
60
  //
61
  NS_LOG_INFO ("Create nodes.");
62
  NodeContainer n;
63
  n.Create (4);
64
65
  //
66
  // We're going to use the zeroth node in the container as the client, and
67
  // the first node as the server.  Add some "human readable" names for these
68
  // nodes.  The first parameter specifies the root of the "/Names" name space
69
  // as the destination, so these will go into the name system as "/Names/client"
70
  // and "/Names/server".  
71
  //
72
  Names::Add ("/Names", "client", n.Get (0));
73
  Names::Add ("/Names", "server", n.Get (1));
74
75
  InternetStackHelper internet;
76
  internet.Install (n);
77
78
  NS_LOG_INFO ("Create devices.");
79
  CsmaHelper csma;
80
  csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate(5000000)));
81
  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
82
  csma.SetDeviceAttribute ("Mtu", UintegerValue (1400));
83
  NetDeviceContainer d = csma.Install (n);
84
85
  //
86
  // Add some human readable names for the devices we'll be interested in.
87
  // We add the names to the name space "under" the nodes we created above.
88
  // This has the effect of making "/Names/client/eth0" and "/Names/server/eth0"
89
  // Note that the first parameter must reference a previously named object,
90
  // and we have, in fact, already named objects "/Names/client" and
91
  // "/Names/server"
92
  //
93
  Names::Add ("/Names/client", "eth0", d.Get (0));
94
  Names::Add ("/Names/server", "eth0", d.Get (1));
95
96
  Ipv4AddressHelper ipv4;
97
98
  //
99
  // We've got the "hardware" in place.  Now we need to add IP addresses.
100
  //
101
  NS_LOG_INFO ("Assign IP Addresses.");
102
  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
103
  Ipv4InterfaceContainer i = ipv4.Assign (d);
104
105
  NS_LOG_INFO ("Create Applications.");
106
107
  //
108
  // Create a UdpEchoServer application on the server node.  Note that we 
109
  // reference the server node by name in the Install method below.
110
  //
111
  uint16_t port = 9;  // well-known echo port number
112
  UdpEchoServerHelper server (port);
113
  ApplicationContainer apps = server.Install (Names::Find<Node> ("/Names/server"));
114
  apps.Start (Seconds (1.0));
115
  apps.Stop (Seconds (10.0));
116
117
  //
118
  // Create a UdpEchoClient application to send UDP datagrams from node zero to
119
  // node one.  Notice that we reference the client node by name in the Install
120
  // method below.
121
  //
122
  uint32_t packetSize = 1024;
123
  uint32_t maxPacketCount = 1;
124
  Time interPacketInterval = Seconds (1.);
125
  UdpEchoClientHelper client (i.GetAddress (1), port);
126
  client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
127
  client.SetAttribute ("Interval", TimeValue (interPacketInterval));
128
  client.SetAttribute ("PacketSize", UintegerValue (packetSize));
129
  apps = client.Install (Names::Find<Node> ("/Names/client"));
130
  apps.Start (Seconds (2.0));
131
  apps.Stop (Seconds (10.0));
132
133
  Config::Connect ("/Names/client/eth0/Rx", MakeCallback (&RxEvent));
134
135
  //
136
  // Now, do the actual simulation.
137
  //
138
  NS_LOG_INFO ("Run Simulation.");
139
  Simulator::Run ();
140
  Simulator::Destroy ();
141
  NS_LOG_INFO ("Done.");
142
}
(-)a/examples/wscript (+4 lines)
 Lines 15-20   def build(bld): Link Here 
15
    obj = bld.create_ns3_program('third',
15
    obj = bld.create_ns3_program('third',
16
                                 ['core', 'simulator', 'point-to-point', 'csma', 'wifi', 'internet-stack'])
16
                                 ['core', 'simulator', 'point-to-point', 'csma', 'wifi', 'internet-stack'])
17
    obj.source = 'third.cc'
17
    obj.source = 'third.cc'
18
        
19
    obj = bld.create_ns3_program('names',
20
                                 ['core', 'simulator', 'csma', 'internet-stack'])
21
    obj.source = 'names.cc'
18
        
22
        
19
    obj = bld.create_ns3_program('mixed-wireless',
23
    obj = bld.create_ns3_program('mixed-wireless',
20
                                 ['core', 'simulator', 'mobility', 'wifi', 'point-to-point', 'internet-stack'])
24
                                 ['core', 'simulator', 'mobility', 'wifi', 'point-to-point', 'internet-stack'])
(-)a/src/core/config.cc (+48 lines)
 Lines 22-27    Link Here 
22
#include "object.h"
22
#include "object.h"
23
#include "global-value.h"
23
#include "global-value.h"
24
#include "object-vector.h"
24
#include "object-vector.h"
25
#include "object-names.h"
25
#include "pointer.h"
26
#include "pointer.h"
26
#include "log.h"
27
#include "log.h"
27
#include <sstream>
28
#include <sstream>
 Lines 294-299   Resolver::DoResolve (std::string path, P Link Here 
294
  std::string item = path.substr (1, next-1);
295
  std::string item = path.substr (1, next-1);
295
  std::string pathLeft = path.substr (next, path.size ()-next);
296
  std::string pathLeft = path.substr (next, path.size ()-next);
296
297
298
  //
299
  // If root is zero, we're beginning to see if we can use the object name 
300
  // service to resolve this path.  In this case, we must see the name space 
301
  // "/Names" on the front of this path.  There is no object associated with 
302
  // the root of the "/Names" namespace, so we just ignore it and move on to 
303
  // the next segment.
304
  //
305
  if (root == 0)
306
    {
307
      std::string::size_type offset = path.find ("/Names");
308
      if (offset == 0)
309
        {
310
          m_workStack.push_back (item);
311
          DoResolve (pathLeft, root);
312
          m_workStack.pop_back ();
313
          return;
314
        }
315
    }
316
317
  //
318
  // We have an item (possibly a segment of a namespace path.  Check to see if
319
  // we can determine that this segment refers to a named object.  If root is
320
  // zero, this means to look in the root of the "/Names" name space, otherwise
321
  // it refers to a name space context (level).
322
  //
323
  Ptr<Object> namedObject = Names::FindObjectFromShortName<Object> (root, item);
324
  if (namedObject)
325
    {
326
      NS_LOG_DEBUG ("Name system resolved item = " << item << " to " << namedObject);
327
      m_workStack.push_back (item);
328
      DoResolve (pathLeft, namedObject);
329
      m_workStack.pop_back ();
330
      return;
331
    }
332
333
  //
334
  // We're done with the object name service hooks, so proceed down the path
335
  // of types and attributes.
336
  //
297
  std::string::size_type dollarPos = item.find ("$");
337
  std::string::size_type dollarPos = item.find ("$");
298
  if (dollarPos == 0)
338
  if (dollarPos == 0)
299
    {
339
    {
 Lines 480-485   ConfigImpl::LookupMatches (std::string p Link Here 
480
    {
520
    {
481
      resolver.Resolve (*i);
521
      resolver.Resolve (*i);
482
    }
522
    }
523
524
  //
525
  // See if we can do something with the object name service.  Starting with
526
  // the root pointer zeroed indicates to the resolver that it should start
527
  // looking at the root of the "/Names" namespace during this go.
528
  //
529
  resolver.Resolve (0);
530
483
  return Config::MatchContainer (resolver.m_objects, resolver.m_contexts, path);
531
  return Config::MatchContainer (resolver.m_objects, resolver.m_contexts, path);
484
}
532
}
485
533
(-)04170734fa8b (+624 lines)
Added Link Here 
1
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2009 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 <map>
20
#include "ns3/object.h"
21
#include "ns3/log.h"
22
#include "ns3/assert.h"
23
#include "ns3/abort.h"
24
#include "ns3/simulator.h"
25
#include "object-names.h"
26
27
namespace ns3 {
28
29
NS_LOG_COMPONENT_DEFINE ("Names");
30
31
class NameNode
32
{
33
public:
34
  NameNode ();
35
  NameNode (const NameNode &nameNode);
36
  NameNode (NameNode *parent, std::string name, Ptr<Object> object);
37
  NameNode &operator = (const NameNode &rhs);
38
39
 ~NameNode ();
40
41
  NameNode *m_parent;
42
  std::string m_name;
43
  Ptr<Object> m_object;
44
45
  std::map<std::string, NameNode *> m_nameMap;
46
};
47
48
NameNode::NameNode ()
49
  : m_parent (0), m_name (""), m_object (0)
50
{
51
}
52
53
NameNode::NameNode (const NameNode &nameNode)
54
{
55
  m_parent = nameNode.m_parent;
56
  m_name = nameNode.m_name;
57
  m_object = nameNode.m_object;
58
  m_nameMap = nameNode.m_nameMap;
59
}
60
61
NameNode &
62
NameNode::operator = (const NameNode &rhs)
63
{
64
  m_parent = rhs.m_parent;
65
  m_name = rhs.m_name;
66
  m_object = rhs.m_object;
67
  m_nameMap = rhs.m_nameMap;
68
  return *this;
69
}
70
71
NameNode::NameNode (NameNode *parent, std::string name, Ptr<Object> object)
72
  : m_parent (parent), m_name (name), m_object (object)
73
{
74
}
75
76
NameNode::~NameNode ()
77
{
78
}
79
80
class NamesPriv 
81
{
82
public:
83
  NamesPriv ();
84
  ~NamesPriv ();
85
86
  bool Add (std::string name, Ptr<Object> obj);
87
  bool Add (Ptr<Object> context, std::string name, Ptr<Object> object);
88
  bool Add (std::string context, std::string name, Ptr<Object> object);
89
  std::string FindShortName (Ptr<Object> object);
90
  std::string FindFullName (Ptr<Object> object);
91
  Ptr<Object> FindObjectFromFullName (std::string name);
92
  Ptr<Object> FindObjectFromShortName (Ptr<Object> context, std::string name);
93
94
  static NamesPriv *Get (void);
95
  
96
private:
97
  static NamesPriv **DoGet (void);
98
  static void Delete (void);
99
100
  NameNode *IsNamed (Ptr<Object>);
101
  bool IsDuplicateName (NameNode *node, std::string name);
102
103
  NameNode m_root;
104
  std::map<Ptr<Object>, NameNode *> m_objectMap;
105
};
106
107
NamesPriv *
108
NamesPriv::Get (void)
109
{
110
  return *(DoGet ());
111
}
112
113
NamesPriv **
114
NamesPriv::DoGet (void)
115
{
116
  static NamesPriv *ptr = 0;
117
118
  if (ptr == 0)
119
    {
120
      ptr = new NamesPriv;
121
      Simulator::ScheduleDestroy (&NamesPriv::Delete);
122
    }
123
124
  return &ptr;
125
}
126
127
void 
128
NamesPriv::Delete (void)
129
{
130
  NS_LOG_FUNCTION_NOARGS ();
131
132
  NamesPriv **ptr = DoGet ();
133
  delete *ptr;
134
  *ptr = 0;
135
}
136
137
NamesPriv::NamesPriv ()
138
{
139
  NS_LOG_FUNCTION_NOARGS ();
140
141
  m_root.m_parent = 0;
142
  m_root.m_name = "Names";
143
  m_root.m_object = 0;
144
}
145
146
NamesPriv::~NamesPriv ()
147
{
148
  NS_LOG_FUNCTION_NOARGS ();
149
150
  //
151
  // Every name is associated with an object in the object map, so freeing the
152
  // NameNodes in this map will free all of the memory allocated for the NameNodes
153
  //
154
  for (std::map<Ptr<Object>, NameNode *>::iterator i = m_objectMap.begin (); i != m_objectMap.end (); ++i)
155
    {
156
      delete i->second;
157
      i->second = 0;
158
    }
159
}
160
161
bool
162
NamesPriv::Add (std::string name, Ptr<Object> object)
163
{
164
  return Add (Ptr<Object> (0, false), name, object);
165
}
166
167
bool
168
NamesPriv::Add (Ptr<Object> context, std::string name, Ptr<Object> object)
169
{
170
  NS_LOG_FUNCTION (context << name << object);
171
172
  if (IsNamed (object))
173
    {
174
      NS_LOG_LOGIC ("Object is already named");
175
      return false;
176
    }
177
178
  NameNode *node = 0;
179
  if (context)
180
    {
181
      node = IsNamed (context);
182
      NS_ASSERT_MSG (node, "NamesPriv::Name(): context must point to a previously named node");
183
    }
184
  else
185
    {
186
      node = &m_root;
187
    }
188
189
  if (IsDuplicateName (node, name))
190
    {
191
      NS_LOG_LOGIC ("Name is already taken");
192
      return false;
193
    }
194
195
  NameNode *newNode = new NameNode(node, name, object);
196
  node->m_nameMap[name] = newNode;
197
  m_objectMap[object] = newNode;
198
199
  return true;
200
}
201
202
bool
203
NamesPriv::Add (std::string context, std::string name, Ptr<Object> object)
204
{
205
  if (context == "/Names")
206
    {
207
      return Add (name, object);
208
    }
209
  return Add (FindObjectFromFullName (context), name, object);
210
}
211
212
std::string
213
NamesPriv::FindShortName (Ptr<Object> object)
214
{
215
  NS_LOG_FUNCTION (object);
216
217
  std::map<Ptr<Object>, NameNode *>::iterator i = m_objectMap.find (object);
218
  if (i == m_objectMap.end ())
219
    {
220
      NS_LOG_LOGIC ("Object does not exist in object map");
221
      return "";
222
    }
223
  else
224
    {
225
      NS_LOG_LOGIC ("Object exists in object map");
226
      return i->second->m_name;
227
    }
228
}
229
230
std::string
231
NamesPriv::FindFullName (Ptr<Object> object)
232
{
233
  NS_LOG_FUNCTION (object);
234
235
  std::map<Ptr<Object>, NameNode *>::iterator i = m_objectMap.find (object);
236
  if (i == m_objectMap.end ())
237
    {
238
      NS_LOG_LOGIC ("Object does not exist in object map");
239
      return "";
240
    }
241
242
  NameNode *p = i->second;
243
  NS_ASSERT_MSG (p, "NamesPriv::FindFullName(): Internal error: Invalid NameNode pointer from map");
244
245
  std::string fullname;
246
247
  do
248
    {
249
      fullname = "/" + p->m_name + fullname;
250
      NS_LOG_LOGIC ("fullname is " << fullname);
251
    }
252
  while ((p = p->m_parent) != 0);
253
254
  return fullname;
255
}
256
257
258
Ptr<Object>
259
NamesPriv::FindObjectFromFullName (std::string name)
260
{
261
  std::string namespaceName = "/Names/";
262
  std::string::size_type offset = name.find (namespaceName);
263
  if (offset == std::string::npos)
264
    {
265
      NS_LOG_LOGIC (name << " is not in the " << namespaceName << " name space");
266
      return 0;
267
    }
268
269
  std::string remaining = name.substr (namespaceName.size ());
270
  NameNode *node = &m_root;
271
272
  //
273
  // remaining is now composed entirely of path segments in the /Names name space.
274
  // and we have eaten the leading slash. e.g., remaining = "ClientNode/eth0"
275
  // The start of the search is at the root of the name space.
276
  //
277
  for (;;)
278
    {
279
      NS_LOG_LOGIC ("Looking for the object of name " << remaining);
280
      offset = remaining.find ("/");
281
      if (offset == std::string::npos)
282
        {
283
          //
284
          // There are no remaining slashes so this is the last segment of the 
285
          // specified name.  We're done when we find it
286
          //
287
          std::map<std::string, NameNode *>::iterator i = node->m_nameMap.find (remaining);
288
          if (i == node->m_nameMap.end ())
289
            {
290
              NS_LOG_LOGIC ("Name does not exist in name map");
291
              return 0;
292
            }
293
          else
294
            {
295
              NS_LOG_LOGIC ("Name parsed, found object");
296
              return i->second->m_object;
297
            }
298
        }
299
      else
300
        {
301
          //
302
          // There are more slashes so this is an intermediate segment of the 
303
          // specified name.  We need to "recurse" when we find this segment.
304
          //
305
          offset = remaining.find ("/");
306
          std::string segment = remaining.substr(0, offset);
307
308
          std::map<std::string, NameNode *>::iterator i = node->m_nameMap.find (segment);
309
          if (i == node->m_nameMap.end ())
310
            {
311
              NS_LOG_LOGIC ("Name does not exist in name map");
312
              return 0;
313
            }
314
          else
315
            {
316
              node = i->second;
317
              remaining = remaining.substr (offset + 1);
318
              NS_LOG_LOGIC ("Intermediate segment parsed");
319
              continue;
320
            }
321
        }
322
    }
323
324
  NS_ASSERT_MSG (node, "NamesPriv::FindObjectFromFullName(): Internal error:  this can't happen");
325
  return 0;
326
}
327
328
Ptr<Object>
329
NamesPriv::FindObjectFromShortName (Ptr<Object> context, std::string name)
330
{
331
  NS_LOG_FUNCTION (context << name);
332
333
  NameNode *node = 0;
334
335
  if (context == 0)
336
    {
337
      NS_LOG_LOGIC ("Zero context implies root NameNode");
338
      node = &m_root;
339
    }
340
  else
341
    {
342
      node = IsNamed (context);
343
      if (node == 0)
344
        {
345
          NS_LOG_LOGIC ("Context does not point to a previously named node");
346
          return 0;
347
        }
348
    }
349
350
  std::map<std::string, NameNode *>::iterator i = node->m_nameMap.find (name);
351
  if (i == node->m_nameMap.end ())
352
    {
353
      NS_LOG_LOGIC ("Name does not exist in name map");
354
      return 0;
355
    }
356
  else
357
    {
358
      NS_LOG_LOGIC ("Name exists in name map");
359
      return i->second->m_object;
360
    }
361
}
362
363
NameNode *
364
NamesPriv::IsNamed (Ptr<Object> object)
365
{
366
  NS_LOG_FUNCTION (object);
367
368
  std::map<Ptr<Object>, NameNode *>::iterator i = m_objectMap.find (object);
369
  if (i == m_objectMap.end ())
370
    {
371
      NS_LOG_LOGIC ("Object does not exist in object map, returning NameNode 0");
372
      return 0;
373
    }
374
  else
375
    {
376
      NS_LOG_LOGIC ("Object exists in object map, returning NameNode " << &i->second);
377
      return i->second;
378
    }
379
}
380
381
bool
382
NamesPriv::IsDuplicateName (NameNode *node, std::string name)
383
{
384
  NS_LOG_FUNCTION (node << name);
385
386
  std::map<std::string, NameNode *>::iterator i = node->m_nameMap.find (name);
387
  if (i == node->m_nameMap.end ())
388
    {
389
      NS_LOG_LOGIC ("Name does not exist in name map");
390
      return false;
391
    }
392
  else
393
    {
394
      NS_LOG_LOGIC ("Name exists in name map");
395
      return true;
396
    }
397
}
398
399
bool
400
Names::Add (std::string name, Ptr<Object> object)
401
{
402
  return NamesPriv::Get ()->Add (name, object);
403
}
404
405
bool
406
Names::Add (Ptr<Object> context, std::string name, Ptr<Object> object)
407
{
408
  return NamesPriv::Get ()->Add (context, name, object);
409
}
410
411
bool
412
Names::Add (std::string context, std::string name, Ptr<Object> object)
413
{
414
  return NamesPriv::Get ()->Add (context, name, object);
415
}
416
417
std::string
418
Names::FindShortName (Ptr<Object> object)
419
{
420
  return NamesPriv::Get ()->FindShortName (object);
421
}
422
423
std::string
424
Names::FindFullName (Ptr<Object> object)
425
{
426
  return NamesPriv::Get ()->FindFullName (object);
427
}
428
429
Ptr<Object>
430
Names::FindObjectFromFullNameInternal (std::string name)
431
{
432
  return NamesPriv::Get ()->FindObjectFromFullName (name);
433
}
434
435
Ptr<Object>
436
Names::FindObjectFromShortNameInternal (Ptr<Object> context, std::string name)
437
{
438
  return NamesPriv::Get ()->FindObjectFromShortName (context, name);
439
}
440
441
} //namespace ns3
442
443
#ifdef RUN_SELF_TESTS
444
445
#include "test.h"
446
#include "object-factory.h"
447
448
namespace ns3 {
449
450
class TestObject : public Object
451
{
452
public:
453
  static TypeId GetTypeId (void) 
454
  {
455
    static TypeId tid = TypeId ("TestObject")
456
      .SetParent (Object::GetTypeId ())
457
      .HideFromDocumentation ()
458
      .AddConstructor<TestObject> ();
459
    return tid;
460
  }
461
  TestObject () {}
462
  virtual void Dispose (void) {}
463
};
464
465
class NamesTest : public Test
466
{
467
public:
468
  NamesTest ();
469
  virtual bool RunTests (void);
470
};
471
472
NamesTest::NamesTest ()
473
  : Test ("Names")
474
{
475
}
476
477
bool 
478
NamesTest::RunTests (void)
479
{
480
  bool result = true;
481
482
  // 
483
  // Name a couple of objects at the root level
484
  //
485
  Ptr<TestObject> client = CreateObject<TestObject> ();
486
  result = Names::Add ("Client", client);
487
  NS_TEST_ASSERT_EQUAL (result, true);
488
489
  Ptr<TestObject> server = CreateObject<TestObject> ();
490
  result = Names::Add ("Server", server);
491
  NS_TEST_ASSERT_EQUAL (result, true);
492
493
  //
494
  // We shouldn't be able to add another name to a previously named object
495
  //
496
  result = Names::Add ("Not Client", client);
497
  NS_TEST_ASSERT_EQUAL (result, false);
498
499
  //
500
  // We shouldn't be able to duplicate a name at the root level.
501
  //
502
  Ptr<TestObject> secondClient = CreateObject<TestObject> ();
503
  result = Names::Add ("Client", secondClient);
504
  NS_TEST_ASSERT_EQUAL (result, false);
505
506
  //
507
  // We should be able to add a new name in the first object's context
508
  //
509
  Ptr<TestObject> clientEth0 = CreateObject<TestObject> ();
510
  result = Names::Add (client, "eth0", clientEth0);
511
  NS_TEST_ASSERT_EQUAL (result, true);
512
513
  //
514
  // We shouldn't be able to duplicate a name in that context.
515
  //
516
  Ptr<TestObject> secondClientEth0 = CreateObject<TestObject> ();
517
  result = Names::Add (client, "eth0", secondClientEth0);
518
  NS_TEST_ASSERT_EQUAL (result, false);
519
520
  //
521
  // We should be able to add the same name in the second object's context
522
  //
523
  Ptr<TestObject> serverEth0 = CreateObject<TestObject> ();
524
  result = Names::Add (server, "eth0", serverEth0);
525
  NS_TEST_ASSERT_EQUAL (result, true);
526
527
  //
528
  // We should be able to find the short names for the objects we created
529
  //
530
  std::string found;
531
532
  found = Names::FindShortName (client);
533
  NS_TEST_ASSERT_EQUAL (found, "Client");
534
535
  found = Names::FindShortName (server);
536
  NS_TEST_ASSERT_EQUAL (found, "Server");
537
538
  found = Names::FindShortName (clientEth0);
539
  NS_TEST_ASSERT_EQUAL (found, "eth0");
540
541
  found = Names::FindShortName (serverEth0);
542
  NS_TEST_ASSERT_EQUAL (found, "eth0");
543
544
  //
545
  // We should be able to find the full names for the objects we created
546
  //
547
  found = Names::FindFullName (client);
548
  NS_TEST_ASSERT_EQUAL (found, "/Names/Client");
549
550
  found = Names::FindFullName (server);
551
  NS_TEST_ASSERT_EQUAL (found, "/Names/Server");
552
553
  found = Names::FindFullName (clientEth0);
554
  NS_TEST_ASSERT_EQUAL (found, "/Names/Client/eth0");
555
556
  found = Names::FindFullName (serverEth0);
557
  NS_TEST_ASSERT_EQUAL (found, "/Names/Server/eth0");
558
559
  // 
560
  // We should be able to find the objects from the short names
561
  //
562
  Ptr<TestObject> foundObject;
563
564
  foundObject = Names::FindObjectFromShortName<TestObject> (0, "Client");
565
  NS_TEST_ASSERT_EQUAL (foundObject, client);
566
567
  foundObject = Names::FindObjectFromShortName<TestObject> (0, "Server");
568
  NS_TEST_ASSERT_EQUAL (foundObject, server);
569
570
  foundObject = Names::FindObjectFromShortName<TestObject> (client, "eth0");
571
  NS_TEST_ASSERT_EQUAL (foundObject, clientEth0);
572
573
  foundObject = Names::FindObjectFromShortName<TestObject> (server, "eth0");
574
  NS_TEST_ASSERT_EQUAL (foundObject, serverEth0);
575
576
  // 
577
  // We should be able to find the objects from their full names
578
  //
579
  foundObject = Names::Find<TestObject> ("/Names/Client");
580
  NS_TEST_ASSERT_EQUAL (foundObject, client);
581
582
  foundObject = Names::Find<TestObject> ("/Names/Server");
583
  NS_TEST_ASSERT_EQUAL (foundObject, server);
584
585
  foundObject = Names::Find<TestObject> ("/Names/Client/eth0");
586
  NS_TEST_ASSERT_EQUAL (foundObject, clientEth0);
587
588
  foundObject = Names::Find<TestObject> ("/Names/Server/eth0");
589
  NS_TEST_ASSERT_EQUAL (foundObject, serverEth0);
590
591
  //
592
  // We also have some syntactical sugary methods, so make sure they do what
593
  // they should as well.
594
  //
595
  Ptr<TestObject> bridge = CreateObject<TestObject> ();
596
  result = Names::Add ("/Names", "Bridge", client);
597
  NS_TEST_ASSERT_EQUAL (result, true);
598
599
  Ptr<TestObject> bridgeEth0 = CreateObject<TestObject> ();
600
  result = Names::Add ("/Names/Bridge", "eth0", bridgeEth0);
601
  NS_TEST_ASSERT_EQUAL (result, true);
602
603
  foundObject = Names::Find<TestObject> ("/Names/Bridge");
604
  NS_TEST_ASSERT_EQUAL (foundObject, bridge);
605
606
  foundObject = Names::Find<TestObject> ("/Names/Bridge/eth0");
607
  NS_TEST_ASSERT_EQUAL (foundObject, bridgeEth0);
608
609
  //
610
  // Run the simulator and destroy it to get the Destroy method called on the
611
  // private implementation object.  We depend on seeing a valgrind-clean run of
612
  // the unit tests to really determine if the clean up was really successful.
613
  //
614
  Simulator::Run ();
615
  Simulator::Destroy ();
616
  
617
  return true;
618
}
619
620
static NamesTest g_namesTests;
621
622
} // namespace ns3
623
624
#endif /* RUN_SELF_TESTS */
(-)04170734fa8b (+245 lines)
Added Link Here 
1
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2009 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 OBJECT_NAMES_H
20
#define OBJECT_NAMES_H
21
22
#include "ns3/ptr.h"
23
#include "ns3/object.h"
24
25
namespace ns3 {
26
27
/**
28
 * \brief A directory of name and Ptr<Object> associations that allows us to
29
 * give any ns3 Object a name.
30
 */
31
class Names
32
{
33
public:
34
35
  /**
36
   * Add the association between the string "name" and the Ptr<Object> obj
37
   * at the root of the "/Names" name space.  This can be seen as equivalent
38
   * to adding a Pointer Attribute called "name" to the to the root name 
39
   * space object and then assigning the value obj to that attribute.  The 
40
   * config facility will see it that way.
41
   *
42
   * \param name The name of the object you want to associate.
43
   * \param obj A smart pointer to the object itself.
44
   */
45
  static bool Add (std::string name, Ptr<Object> obj);
46
47
  /**
48
   * Add the association between the string "name" and the Ptr<Object> obj
49
   * in the object context given by the Ptr<Object> context.  This can be
50
   * seen as equivalent to adding a Pointer Attribute called "name" to the 
51
   * object given by "context" and then assigning the value obj to that
52
   * attribute.  The config facility will see it that way.
53
   *
54
   * \param context A spart pointer to an object under which you want this
55
   *                name to be defined.
56
   * \param name The name of the object you want to associate.
57
   * \param obj A smart pointer to the object itself.
58
   */
59
  static bool Add (Ptr<Object> context, std::string name, Ptr<Object> object);
60
61
  /**
62
   * Syntactic sugar around the Object context Name method.  Allows you to 
63
   * specify the context with a string instead of the pointer.  If the first
64
   * parameter (context) is "/Names" this turns into a call into Name at the
65
   * root of the name space.  Otherwise it does a FindObjectFromFullNameInternal
66
   * on the context and adds the name to a subspace.
67
   *
68
   * \param context A fully qualified name describing a previously named object.
69
   *                under which you want this name to be defined.
70
   * \param name The name of the object you want to associate.
71
   * \param obj A smart pointer to the object itself.
72
   */
73
  static bool Add (std::string context, std::string name, Ptr<Object> object);
74
75
  /**
76
   * Given a pointer to an object, look to see if that object has a name
77
   * associated with it and return the shortname for the object.
78
   *
79
   * The fullname of an object is a fully qualified namespace name, for example
80
   * if you have a device that you have previously named "eth0" under a node
81
   * you have named "client", the fullname of the device will then be
82
   * "/Names/client/eth0".
83
   *
84
   * The shortname of an object is the name of the object in its parent name
85
   * space.  Using the example above, asking for the shortname of the device
86
   * will result in "eth0" being returned.
87
   *
88
   * \param object A spart pointer to an object for which you want to find
89
   *               its shortname.
90
   */
91
  static std::string FindShortName (Ptr<Object> object);
92
93
  /**
94
   * Given a pointer to an object, look to see if that object has a name
95
   * associated with it and return the fully qualified namespace name
96
   * for the object.
97
   *
98
   * The fullname of an object is a fully qualified namespace name, for example
99
   * if you have a device that you have previously named "eth0" under a node
100
   * you have named "client", the fullname of the device will then be
101
   * "/Names/client/eth0".
102
   *
103
   * The shortname of an object is the name of the object in its parent name
104
   * space.  Using the example above, asking for the shortname of the device
105
   * will result in "eth0" being returned.
106
   *
107
   * \param object A spart pointer to an object for which you want to find
108
   *               its fullname.
109
   */
110
  static std::string FindFullName (Ptr<Object> object);
111
112
  /**
113
   * Given a fullname string, look to see if there's an object in the system
114
   * with a that associated with it.  If there is, do a QueryObject on the 
115
   * resulting object to convert it to the requested typename.  
116
   * 
117
   * The fullname of an object is a fully qualified namespace name, for example
118
   * if you have a device that you have previously named "eth0" under a node
119
   * you have named "client", the fullname of the device will then be
120
   * "/Names/client/eth0".
121
   *
122
   * \param name A string containing a fully qualified name space name 
123
   *             used to locate the object.
124
   */
125
  template <typename T>
126
  static Ptr<T> FindObjectFromFullName (std::string name);
127
128
  /**
129
   * Given a fullname string, look to see if there's an object in the system
130
   * with a that associated with it.  If there is, do a QueryObject on the 
131
   * resulting object to convert it to the requested typename.  
132
   * 
133
   * The fullname of an object is a fully qualified namespace name, for example
134
   * if you have a device that you have previously named "eth0" under a node
135
   * you have named "client", the fullname of the device will then be
136
   * "/Names/client/eth0".
137
   *
138
   * \param name A string containing a fully qualified name space name 
139
   *             used to locate the object.
140
   *
141
   * @comment This method is identical to FindObjectFromFullName, but has a
142
   * short signature since it is a common use and we want it to be easy to 
143
   * type.
144
   */
145
  template <typename T>
146
  static Ptr<T> Find (std::string name);
147
148
  /**
149
   * Given an object context and a shortname string, look through the names 
150
   * associated with the namespace defined by the context object to see if 
151
   * there's an object there with the given shortname.
152
   *
153
   * The fullname of an object is a fully qualified namespace name, for example
154
   * if you have a device that you have previously named "eth0" under a node
155
   * you have named "client", the fullname of the device will then be
156
   * "/Names/client/eth0".
157
   *
158
   * The shortname of an object is the name of the object in its parent name
159
   * space.  Using the example above, asking for the shortname of the device
160
   * will result in "eth0" being returned.
161
   *
162
   * The context object provides a namespace context, in the case of the example
163
   * it would be the "client" object under which we look for the short name.
164
   * In the example above, the context pointer would be the Ptr<Object> to the 
165
   * client node, and the name would be the shortname "eth0"  
166
   *
167
   * \param context A spart pointer to an object under which you want to look 
168
   *                for the provided name.
169
   * \param name A string containing a shortname to look for.
170
   */
171
  template <typename T>
172
  static Ptr<T> FindObjectFromShortName (Ptr<Object> context, std::string name);
173
174
private:
175
176
  /**
177
   * \internal
178
   *
179
   * \brief Non-templated internal version of FindObjectFromLongName
180
   *
181
   * \param name A string containing a longname to look for.
182
   */
183
  static Ptr<Object> FindObjectFromFullNameInternal (std::string name);
184
185
  /**
186
   * \internal
187
   *
188
   * \brief Non-templated internal version of FindObjectFromShortName
189
   *
190
   * \param context A spart pointer to an object under which you want to look 
191
   *                for the provided name.
192
   * \param name A string containing a shortname to look for.
193
   */
194
  static Ptr<Object> FindObjectFromShortNameInternal (Ptr<Object> context, std::string name);
195
};
196
197
/**
198
 * \brief Template definition of corresponding template declaration found in class Names.
199
 */
200
template <typename T>
201
Ptr<T> 
202
Names::Find (std::string name)
203
{
204
  return FindObjectFromFullName<T> (name);
205
}
206
207
/**
208
 * \brief Template definition of corresponding template declaration found in class Names.
209
 */
210
template <typename T>
211
Ptr<T> 
212
Names::FindObjectFromFullName (std::string name)
213
{
214
  Ptr<Object> obj = FindObjectFromFullNameInternal (name);
215
  if (obj)
216
    {
217
      return obj->GetObject<T> ();
218
    }
219
  else
220
    {
221
      return 0;
222
    }
223
}
224
225
/**
226
 * \brief Template definition of corresponding template declaration found in class Names.
227
 */
228
template <typename T>
229
Ptr<T> 
230
Names::FindObjectFromShortName (Ptr<Object> context, std::string name)
231
{
232
  Ptr<Object> obj = FindObjectFromShortNameInternal (context, name);
233
  if (obj)
234
    {
235
      return obj->GetObject<T> ();
236
    }
237
  else
238
    {
239
      return 0;
240
    }
241
}
242
243
}//namespace ns3
244
245
#endif /* OBJECT_NAMES_H */
(-)a/src/core/wscript (+2 lines)
 Lines 53-58   def build(bld): Link Here 
53
        'trace-source-accessor.cc',
53
        'trace-source-accessor.cc',
54
        'config.cc',
54
        'config.cc',
55
        'callback.cc',
55
        'callback.cc',
56
        'object-names.cc',
56
        ]
57
        ]
57
    core.uselib = 'RT'
58
    core.uselib = 'RT'
58
59
 Lines 98-103   def build(bld): Link Here 
98
        'object-vector.h',
99
        'object-vector.h',
99
        'deprecated.h',
100
        'deprecated.h',
100
        'abort.h',
101
        'abort.h',
102
        'object-names.h',
101
        ]
103
        ]
102
104
103
    if sys.platform == 'win32':
105
    if sys.platform == 'win32':
(-)a/examples/names.cc (-37 / +14 lines)
 Lines 22-28    Link Here 
22
//              LAN
22
//              LAN
23
//
23
//
24
24
25
#include <fstream>
26
#include "ns3/core-module.h"
25
#include "ns3/core-module.h"
27
#include "ns3/simulator-module.h"
26
#include "ns3/simulator-module.h"
28
#include "ns3/helper-module.h"
27
#include "ns3/helper-module.h"
 Lines 40-64   int Link Here 
40
int 
39
int 
41
main (int argc, char *argv[])
40
main (int argc, char *argv[])
42
{
41
{
43
  //
44
  // Users may find it convenient to turn on explicit debugging
45
  // for selected modules; the below lines suggest how to do this
46
  //
47
#if 1
42
#if 1
48
  LogComponentEnable ("NamesExample", LOG_LEVEL_INFO);
43
  LogComponentEnable ("NamesExample", LOG_LEVEL_INFO);
49
#endif
44
#endif
50
45
51
  //
52
  // Allow the user to override any of the defaults and the above Bind() at
53
  // run-time, via command-line arguments
54
  //
55
  CommandLine cmd;
46
  CommandLine cmd;
56
  cmd.Parse (argc, argv);
47
  cmd.Parse (argc, argv);
57
48
58
  //
59
  // Explicitly create the nodes required by the topology (shown above).
60
  //
61
  NS_LOG_INFO ("Create nodes.");
62
  NodeContainer n;
49
  NodeContainer n;
63
  n.Create (4);
50
  n.Create (4);
64
51
 Lines 75-81   main (int argc, char *argv[]) Link Here 
75
  InternetStackHelper internet;
62
  InternetStackHelper internet;
76
  internet.Install (n);
63
  internet.Install (n);
77
64
78
  NS_LOG_INFO ("Create devices.");
79
  CsmaHelper csma;
65
  CsmaHelper csma;
80
  csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate(5000000)));
66
  csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate(5000000)));
81
  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
67
  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
 Lines 94-124   main (int argc, char *argv[]) Link Here 
94
  Names::Add ("/Names/server", "eth0", d.Get (1));
80
  Names::Add ("/Names/server", "eth0", d.Get (1));
95
81
96
  Ipv4AddressHelper ipv4;
82
  Ipv4AddressHelper ipv4;
97
98
  //
99
  // We've got the "hardware" in place.  Now we need to add IP addresses.
100
  //
101
  NS_LOG_INFO ("Assign IP Addresses.");
102
  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
83
  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
103
  Ipv4InterfaceContainer i = ipv4.Assign (d);
84
  Ipv4InterfaceContainer i = ipv4.Assign (d);
104
85
105
  NS_LOG_INFO ("Create Applications.");
86
  uint16_t port = 9;
106
87
  UdpEchoServerHelper server (port);
107
  //
88
  //
108
  // Create a UdpEchoServer application on the server node.  Note that we 
89
  // Install the UdpEchoServer application on the server node using its name
109
  // reference the server node by name in the Install method below.
90
  // directly.
110
  //
91
  //
111
  uint16_t port = 9;  // well-known echo port number
92
  ApplicationContainer apps = server.Install ("/Names/server");
112
  UdpEchoServerHelper server (port);
113
  ApplicationContainer apps = server.Install (Names::Find<Node> ("/Names/server"));
114
  apps.Start (Seconds (1.0));
93
  apps.Start (Seconds (1.0));
115
  apps.Stop (Seconds (10.0));
94
  apps.Stop (Seconds (10.0));
116
95
117
  //
118
  // Create a UdpEchoClient application to send UDP datagrams from node zero to
119
  // node one.  Notice that we reference the client node by name in the Install
120
  // method below.
121
  //
122
  uint32_t packetSize = 1024;
96
  uint32_t packetSize = 1024;
123
  uint32_t maxPacketCount = 1;
97
  uint32_t maxPacketCount = 1;
124
  Time interPacketInterval = Seconds (1.);
98
  Time interPacketInterval = Seconds (1.);
 Lines 126-142   main (int argc, char *argv[]) Link Here 
126
  client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
100
  client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
127
  client.SetAttribute ("Interval", TimeValue (interPacketInterval));
101
  client.SetAttribute ("Interval", TimeValue (interPacketInterval));
128
  client.SetAttribute ("PacketSize", UintegerValue (packetSize));
102
  client.SetAttribute ("PacketSize", UintegerValue (packetSize));
129
  apps = client.Install (Names::Find<Node> ("/Names/client"));
103
  //
104
  // Install the UdpEchoClient application on the server node using its name
105
  // directly.
106
  //
107
  apps = client.Install ("/Names/client");
130
  apps.Start (Seconds (2.0));
108
  apps.Start (Seconds (2.0));
131
  apps.Stop (Seconds (10.0));
109
  apps.Stop (Seconds (10.0));
132
110
111
  //
112
  // Use the config system to connect a trace source using the object name
113
  // system to specify the path.
114
  //
133
  Config::Connect ("/Names/client/eth0/Rx", MakeCallback (&RxEvent));
115
  Config::Connect ("/Names/client/eth0/Rx", MakeCallback (&RxEvent));
134
116
135
  //
136
  // Now, do the actual simulation.
137
  //
138
  NS_LOG_INFO ("Run Simulation.");
139
  Simulator::Run ();
117
  Simulator::Run ();
140
  Simulator::Destroy ();
118
  Simulator::Destroy ();
141
  NS_LOG_INFO ("Done.");
142
}
119
}
(-)a/src/helper/application-container.cc (+15 lines)
 Lines 17-22    Link Here 
17
 *
17
 *
18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
 */
19
 */
20
21
#include "ns3/object-names.h"
20
#include "application-container.h"
22
#include "application-container.h"
21
23
22
namespace ns3 {
24
namespace ns3 {
 Lines 28-33   ApplicationContainer::ApplicationContain Link Here 
28
{
30
{
29
  m_applications.push_back (app);
31
  m_applications.push_back (app);
30
}
32
}
33
34
ApplicationContainer::ApplicationContainer (std::string name)
35
{
36
  Ptr<Application> app = Names::Find<Application> (name);
37
  m_applications.push_back (app);
38
}
39
31
40
32
ApplicationContainer::Iterator 
41
ApplicationContainer::Iterator 
33
ApplicationContainer::Begin (void) const
42
ApplicationContainer::Begin (void) const
 Lines 63-68   ApplicationContainer::Add (Ptr<Applicati Link Here 
63
{
72
{
64
  m_applications.push_back (application);
73
  m_applications.push_back (application);
65
}
74
}
75
void 
76
ApplicationContainer::Add (std::string name)
77
{
78
  Ptr<Application> application = Names::Find<Application> (name);
79
  m_applications.push_back (application);
80
}
66
81
67
void 
82
void 
68
ApplicationContainer::Start (Time start)
83
ApplicationContainer::Start (Time start)
(-)a/src/helper/application-container.h (-7 / +21 lines)
 Lines 17-22    Link Here 
17
 *
17
 *
18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
 */
19
 */
20
20
#ifndef APPLICATION_CONTAINER_H
21
#ifndef APPLICATION_CONTAINER_H
21
#define APPLICATION_CONTAINER_H
22
#define APPLICATION_CONTAINER_H
22
23
 Lines 45-50   public: Link Here 
45
   */
46
   */
46
  ApplicationContainer (Ptr<Application> application);
47
  ApplicationContainer (Ptr<Application> application);
47
48
49
  /**
50
   * Create an ApplicationContainer with exactly one application
51
   *
52
   * \param name The name of the application object to add to the container
53
   */
54
  ApplicationContainer (std::string name);
55
48
  typedef std::vector<Ptr<Application> >::const_iterator Iterator;
56
  typedef std::vector<Ptr<Application> >::const_iterator Iterator;
49
57
50
  /**
58
  /**
 Lines 57-83   public: Link Here 
57
  Iterator End (void) const;
65
  Iterator End (void) const;
58
66
59
  /**
67
  /**
60
   * \returns the number of netdevice pointers stored in this container.
68
   * \returns the number of application pointers stored in this container.
61
   */
69
   */
62
  uint32_t GetN (void) const;
70
  uint32_t GetN (void) const;
63
  /**
71
  /**
64
   * \param i the index of the requested netdevice pointer.
72
   * \param i the index of the requested application pointer.
65
   * \returns the requested netdevice pointer.
73
   * \returns the requested application pointer.
66
   */
74
   */
67
  Ptr<Application> Get (uint32_t i) const;
75
  Ptr<Application> Get (uint32_t i) const;
68
76
69
  /**
77
  /**
70
   * \param other another netdevice container
78
   * Append to the end of this container the other input container.
71
   *
79
   *
72
   * Append to the end of this container the other input container.
80
   * \param other another application container
73
   */
81
   */
74
  void Add (ApplicationContainer other);
82
  void Add (ApplicationContainer other);
75
  /**
83
  /**
84
   * Append to the end of this container the input application pointer.
85
   *
76
   * \param application another netdevice pointer.
86
   * \param application another netdevice pointer.
77
   *
78
   * Append to the end of this container the input netdevice pointer.
79
   */
87
   */
80
  void Add (Ptr<Application> application);
88
  void Add (Ptr<Application> application);
89
  /**
90
   * Append to the end of this container the application specified by the name.
91
   *
92
   * \param name The name of the application object to add to the container.
93
   */
94
  void Add (std::string name);
81
95
82
  void Start (Time start);
96
  void Start (Time start);
83
  void Stop (Time stop);
97
  void Stop (Time stop);
(-)a/src/helper/bridge-helper.cc (+9 lines)
 Lines 20-25    Link Here 
20
#include "ns3/log.h"
20
#include "ns3/log.h"
21
#include "ns3/bridge-net-device.h"
21
#include "ns3/bridge-net-device.h"
22
#include "ns3/node.h"
22
#include "ns3/node.h"
23
#include "ns3/object-names.h"
23
24
24
NS_LOG_COMPONENT_DEFINE ("BridgeHelper");
25
NS_LOG_COMPONENT_DEFINE ("BridgeHelper");
25
26
 Lines 57-60   BridgeHelper::Install (Ptr<Node> node, N Link Here 
57
  return devs;
58
  return devs;
58
}
59
}
59
60
61
NetDeviceContainer
62
BridgeHelper::Install (std::string nodeName, NetDeviceContainer c)
63
{
64
  NS_LOG_FUNCTION_NOARGS ();
65
  Ptr<Node> node = Names::Find<Node> (nodeName);
66
  return Install (node, c);
67
}
68
60
} // namespace ns3
69
} // namespace ns3
(-)a/src/helper/bridge-helper.h (+1 lines)
 Lines 16-21   public: Link Here 
16
  BridgeHelper ();
16
  BridgeHelper ();
17
  void SetDeviceAttribute (std::string n1, const AttributeValue &v1);
17
  void SetDeviceAttribute (std::string n1, const AttributeValue &v1);
18
  NetDeviceContainer Install (Ptr<Node> node, NetDeviceContainer c);
18
  NetDeviceContainer Install (Ptr<Node> node, NetDeviceContainer c);
19
  NetDeviceContainer Install (std::string nodeName, NetDeviceContainer c);
19
private:
20
private:
20
  ObjectFactory m_deviceFactory;
21
  ObjectFactory m_deviceFactory;
21
};
22
};
(-)a/src/helper/csma-helper.cc (+45 lines)
 Lines 26-31    Link Here 
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/packet.h"
28
#include "ns3/packet.h"
29
#include "ns3/object-names.h"
29
#include <string>
30
#include <string>
30
31
31
namespace ns3 {
32
namespace ns3 {
 Lines 181-188   CsmaHelper::Install (Ptr<Node> node) con Link Here 
181
}
182
}
182
183
183
NetDeviceContainer
184
NetDeviceContainer
185
CsmaHelper::Install (std::string nodeName) const
186
{
187
  Ptr<Node> node = Names::Find<Node> (nodeName);
188
  return Install (node);
189
}
190
191
NetDeviceContainer
184
CsmaHelper::Install (Ptr<Node> node, Ptr<CsmaChannel> channel) const
192
CsmaHelper::Install (Ptr<Node> node, Ptr<CsmaChannel> channel) const
185
{
193
{
194
  return NetDeviceContainer (InstallPriv (node, channel));
195
}
196
197
NetDeviceContainer
198
CsmaHelper::Install (Ptr<Node> node, std::string channelName) const
199
{
200
  Ptr<CsmaChannel> channel = Names::Find<CsmaChannel> (channelName);
201
  return NetDeviceContainer (InstallPriv (node, channel));
202
}
203
204
NetDeviceContainer
205
CsmaHelper::Install (std::string nodeName, Ptr<CsmaChannel> channel) const
206
{
207
  Ptr<Node> node = Names::Find<Node> (nodeName);
208
  return NetDeviceContainer (InstallPriv (node, channel));
209
}
210
211
NetDeviceContainer
212
CsmaHelper::Install (std::string nodeName, std::string channelName) const
213
{
214
  Ptr<Node> node = Names::Find<Node> (nodeName);
215
  Ptr<CsmaChannel> channel = Names::Find<CsmaChannel> (channelName);
186
  return NetDeviceContainer (InstallPriv (node, channel));
216
  return NetDeviceContainer (InstallPriv (node, channel));
187
}
217
}
188
218
 Lines 205-210   CsmaHelper::Install (const NodeContainer Link Here 
205
    }
235
    }
206
236
207
  return devs;
237
  return devs;
238
}
239
240
NetDeviceContainer 
241
CsmaHelper::Install (const NodeContainer &c, std::string channelName) const
242
{
243
  Ptr<CsmaChannel> channel = Names::Find<CsmaChannel> (channelName);
244
  return Install (c, channel);
208
}
245
}
209
246
210
Ptr<NetDevice>
247
Ptr<NetDevice>
 Lines 231-236   CsmaHelper::InstallStar (Ptr<Node> hub, Link Here 
231
      hubDevices.Add (nd.Get (0));
268
      hubDevices.Add (nd.Get (0));
232
      spokeDevices.Add (nd.Get (1));
269
      spokeDevices.Add (nd.Get (1));
233
    }
270
    }
271
}
272
273
void 
274
CsmaHelper::InstallStar (std::string hubName, NodeContainer spokes, 
275
                         NetDeviceContainer& hubDevices, NetDeviceContainer& spokeDevices)
276
{
277
  Ptr<Node> hub = Names::Find<Node> (hubName);
278
  InstallStar (hub, spokes, hubDevices, spokeDevices);
234
}
279
}
235
280
236
void 
281
void 
(-)a/src/helper/csma-helper.h (-2 / +90 lines)
 Lines 172-186   public: Link Here 
172
  NetDeviceContainer Install (Ptr<Node> node) const;
172
  NetDeviceContainer Install (Ptr<Node> node) const;
173
173
174
  /**
174
  /**
175
   * This method creates an ns3::CsmaChannel with the attributes configured by
176
   * CsmaHelper::SetChannelAttribute, an ns3::CsmaNetDevice with the attributes
177
   * configured by CsmaHelper::SetDeviceAttribute and then adds the device
178
   * to the node and attaches the channel to the device.
179
   *
180
   * \param name The name of the node to install the device in
181
   * \returns A containter holding the added net device.
182
   */
183
  NetDeviceContainer Install (std::string name) const;
184
185
  /**
175
   * This method creates an ns3::CsmaNetDevice with the attributes configured by
186
   * This method creates an ns3::CsmaNetDevice with the attributes configured by
176
   * CsmaHelper::SetDeviceAttribute and then adds the device to the node and 
187
   * CsmaHelper::SetDeviceAttribute and then adds the device to the node and 
177
   * attaches the provided channel to the device.
188
   * attaches the provided channel to the device.
178
   *
189
   *
179
   * \param node The node to install the device in
190
   * \param node The node to install the device in
191
   * \param channel The channel to attach to the device.
192
   * \returns A containter holding the added net device.
193
   */
194
  NetDeviceContainer Install (Ptr<Node> node, Ptr<CsmaChannel> channel) const;
195
196
  /**
197
   * This method creates an ns3::CsmaNetDevice with the attributes configured by
198
   * CsmaHelper::SetDeviceAttribute and then adds the device to the node and 
199
   * attaches the provided channel to the device.
200
   *
201
   * \param node The node to install the device in
202
   * \param channelName The name of the channel to attach to the device.
203
   * \returns A containter holding the added net device.
204
   */
205
  NetDeviceContainer Install (Ptr<Node> node, std::string channelName) const;
206
207
  /**
208
   * This method creates an ns3::CsmaNetDevice with the attributes configured by
209
   * CsmaHelper::SetDeviceAttribute and then adds the device to the node and 
210
   * attaches the provided channel to the device.
211
   *
212
   * \param nodeName The name of the node to install the device in
180
   * \param channel The chanel to attach to the device.
213
   * \param channel The chanel to attach to the device.
181
   * \returns A containter holding the added net device.
214
   * \returns A containter holding the added net device.
182
   */
215
   */
183
  NetDeviceContainer Install (Ptr<Node> node, Ptr<CsmaChannel> channel) const;
216
  NetDeviceContainer Install (std::string nodeName, Ptr<CsmaChannel> channel) const;
217
218
  /**
219
   * This method creates an ns3::CsmaNetDevice with the attributes configured by
220
   * CsmaHelper::SetDeviceAttribute and then adds the device to the node and 
221
   * attaches the provided channel to the device.
222
   *
223
   * \param nodeName The name of the node to install the device in
224
   * \param channelName The name of the chanel to attach to the device.
225
   * \returns A containter holding the added net device.
226
   */
227
  NetDeviceContainer Install (std::string nodeName, std::string channelName) const;
184
228
185
  /**
229
  /**
186
   * This method creates an ns3::CsmaChannel with the attributes configured by
230
   * This method creates an ns3::CsmaChannel with the attributes configured by
 Lines 205-210   public: Link Here 
205
   * \returns A containter holding the added net devices.
249
   * \returns A containter holding the added net devices.
206
   */
250
   */
207
  NetDeviceContainer Install (const NodeContainer &c, Ptr<CsmaChannel> channel) const;
251
  NetDeviceContainer Install (const NodeContainer &c, Ptr<CsmaChannel> channel) const;
252
253
  /**
254
   * For each Ptr<node> in the provided container, this method creates an 
255
   * ns3::CsmaNetDevice (with the attributes configured by 
256
   * CsmaHelper::SetDeviceAttribute); adds the device to the node; and attaches 
257
   * the provided channel to the device.
258
   *
259
   * \param c The NodeContainer holding the nodes to be changed.
260
   * \param channelName The name of the channel to attach to the devices.
261
   * \returns A containter holding the added net devices.
262
   */
263
  NetDeviceContainer Install (const NodeContainer &c, std::string channelName) const;
208
264
209
  /**
265
  /**
210
   * \brief Make a star network topology.
266
   * \brief Make a star network topology.
 Lines 239-244   public: Link Here 
239
  void InstallStar (Ptr<Node> hub, NodeContainer spokes, 
295
  void InstallStar (Ptr<Node> hub, NodeContainer spokes, 
240
                    NetDeviceContainer& hubDevices, NetDeviceContainer& spokeDevices);
296
                    NetDeviceContainer& hubDevices, NetDeviceContainer& spokeDevices);
241
297
298
  /**
299
   * \brief Make a star network topology.
300
   *
301
   * Given a pointer to a node that  will become the hub of the star, and a 
302
   * NodeContainer containing pointers to the nodes that will become the 
303
   * spokes; we construct CSMA net devices on the hub (corresponding to the 
304
   * spokes) and store them in the hubDevices NetDeviceContainer.  We add a 
305
   * net device to each spoke node and store them in the spokeDevices 
306
   * NetDeviceContainer.  A CSMA is created for each spoke.
307
   *
308
   * Usually when one thinks of a star network, one thinks of point-to-point
309
   * links.  We're just using a single pair of devices on a multi-point-to-point
310
   * network "drops" as the link.  You are free to add any number of other 
311
   * devices on the link if you want.
312
   *
313
   * The ordering of the devices in the hubDevices container is according to
314
   * the order of the spokes container -- that is, hubDevices[0] will be the
315
   * net device used on the hub that talks to spokes[0].  the container entry
316
   * spokeDevices[0] will have the device that hubDevices[0] talks to -- those
317
   * two devices are the ones that connect hub to spokes[0].
318
   *
319
   * \param hubName The name of the central node of the star network
320
   * \param spokes A NodeContainer of the nodes that will be the spoke (leaf)
321
   *               nodes
322
   * \param hubDevices A NetDeviceContainer that will be filled with pointers
323
   *                   to the point-to-point net devices created on the hub.
324
   * \param spokeDevices A NetDeviceContainer that will be filled with pointers
325
   *                     to the point-to-point net devices created on each of 
326
   *                     the spokes.
327
   */
328
  void InstallStar (std::string hubName, NodeContainer spokes, 
329
                    NetDeviceContainer& hubDevices, NetDeviceContainer& spokeDevices);
330
242
private:
331
private:
243
  Ptr<NetDevice> InstallPriv (Ptr<Node> node, Ptr<CsmaChannel> channel) const;
332
  Ptr<NetDevice> InstallPriv (Ptr<Node> node, Ptr<CsmaChannel> channel) const;
244
333
 Lines 253-259   private: Link Here 
253
  ObjectFactory m_channelFactory;
342
  ObjectFactory m_channelFactory;
254
};
343
};
255
344
256
257
} // namespace ns3
345
} // namespace ns3
258
346
259
#endif /* CSMA_HELPER_H */
347
#endif /* CSMA_HELPER_H */
(-)a/src/helper/emu-helper.cc (+8 lines)
 Lines 21-26    Link Here 
21
#include "ns3/log.h"
21
#include "ns3/log.h"
22
#include "ns3/simulator.h"
22
#include "ns3/simulator.h"
23
#include "ns3/object-factory.h"
23
#include "ns3/object-factory.h"
24
#include "ns3/object-names.h"
24
#include "ns3/queue.h"
25
#include "ns3/queue.h"
25
#include "ns3/emu-net-device.h"
26
#include "ns3/emu-net-device.h"
26
#include "ns3/pcap-writer.h"
27
#include "ns3/pcap-writer.h"
 Lines 194-199   EmuHelper::Install (Ptr<Node> node) cons Link Here 
194
  return NetDeviceContainer (InstallPriv (node));
195
  return NetDeviceContainer (InstallPriv (node));
195
}
196
}
196
197
198
NetDeviceContainer
199
EmuHelper::Install (std::string nodeName) const
200
{
201
  Ptr<Node> node = Names::Find<Node> (nodeName);
202
  return NetDeviceContainer (InstallPriv (node));
203
}
204
197
NetDeviceContainer 
205
NetDeviceContainer 
198
EmuHelper::Install (const NodeContainer &c) const
206
EmuHelper::Install (const NodeContainer &c) const
199
{
207
{
(-)a/src/helper/emu-helper.h (+9 lines)
 Lines 164-169   public: Link Here 
164
  NetDeviceContainer Install (Ptr<Node> node) const;
164
  NetDeviceContainer Install (Ptr<Node> node) const;
165
165
166
  /**
166
  /**
167
   * This method creates an ns3::EmuNetDevice with the attributes configured by 
168
   * EmuHelper::SetDeviceAttribute and then adds the device to the node.
169
   *
170
   * \param nodeName The name of the node to install the device in
171
   * \returns A containter holding the added net device.
172
   */
173
  NetDeviceContainer Install (std::string nodeName) const;
174
175
  /**
167
   * For each Ptr<node> in the provided container this method creates an 
176
   * For each Ptr<node> in the provided container this method creates an 
168
   * ns3::EmuNetDevice (with the attributes configured by 
177
   * ns3::EmuNetDevice (with the attributes configured by 
169
   * EmuHelper::SetDeviceAttribute); adds the device to the node.
178
   * EmuHelper::SetDeviceAttribute); adds the device to the node.
(-)a/src/helper/internet-stack-helper.cc (+7 lines)
 Lines 21-26    Link Here 
21
#include "ns3/assert.h"
21
#include "ns3/assert.h"
22
#include "ns3/log.h"
22
#include "ns3/log.h"
23
#include "ns3/object.h"
23
#include "ns3/object.h"
24
#include "ns3/object-names.h"
24
#include "ns3/ipv4.h"
25
#include "ns3/ipv4.h"
25
#include "internet-stack-helper.h"
26
#include "internet-stack-helper.h"
26
#include "ns3/internet-stack.h"
27
#include "ns3/internet-stack.h"
 Lines 91-96   InternetStackHelper::Install (Ptr<Node> Link Here 
91
  node->AggregateObject (factory);
92
  node->AggregateObject (factory);
92
}
93
}
93
94
95
void
96
InternetStackHelper::Install (std::string nodeName) const
97
{
98
  Ptr<Node> node = Names::Find<Node> (nodeName);
99
  Install (node);
100
}
94
void
101
void
95
InternetStackHelper::EnableAscii (std::ostream &os, NodeContainer n)
102
InternetStackHelper::EnableAscii (std::ostream &os, NodeContainer n)
96
{
103
{
(-)a/src/helper/internet-stack-helper.h (+9 lines)
 Lines 35-40   class InternetStackHelper Link Here 
35
{
35
{
36
public:
36
public:
37
  InternetStackHelper(void);
37
  InternetStackHelper(void);
38
39
  /**
40
   * Aggregate implementations of the ns3::Ipv4, ns3::Udp, and ns3::Tcp classes
41
   * onto the provided node.  This method will assert if called on a node that 
42
   * already has an Ipv4 object aggregated to it.
43
   * 
44
   * \param nodeName The name of the node on which to install the stack.
45
   */
46
  void Install (std::string nodeName) const;
38
47
39
  /**
48
  /**
40
   * Aggregate implementations of the ns3::Ipv4, ns3::Udp, and ns3::Tcp classes
49
   * Aggregate implementations of the ns3::Ipv4, ns3::Udp, and ns3::Tcp classes
(-)a/src/helper/ipv4-interface-container.cc (+7 lines)
 Lines 1-5    Link Here 
1
#include "ipv4-interface-container.h"
1
#include "ipv4-interface-container.h"
2
#include "ns3/node-list.h"
2
#include "ns3/node-list.h"
3
#include "ns3/object-names.h"
3
4
4
namespace ns3 {
5
namespace ns3 {
5
6
 Lines 40-44   Ipv4InterfaceContainer::Add (Ptr<Ipv4> i Link Here 
40
{
41
{
41
  m_interfaces.push_back (std::make_pair (ipv4, interface));
42
  m_interfaces.push_back (std::make_pair (ipv4, interface));
42
}
43
}
44
void 
45
Ipv4InterfaceContainer::Add (std::string ipv4Name, uint32_t interface)
46
{
47
  Ptr<Ipv4> ipv4 = Names::Find<Ipv4> (ipv4Name);
48
  m_interfaces.push_back (std::make_pair (ipv4, interface));
49
}
43
50
44
} // namespace ns3
51
} // namespace ns3
(-)a/src/helper/ipv4-interface-container.h (+1 lines)
 Lines 34-39   public: Link Here 
34
  void SetMetric (uint32_t i, uint16_t metric);
34
  void SetMetric (uint32_t i, uint16_t metric);
35
35
36
  void Add (Ptr<Ipv4> ipv4, uint32_t interface);
36
  void Add (Ptr<Ipv4> ipv4, uint32_t interface);
37
  void Add (std::string ipv4Name, uint32_t interface);
37
38
38
 private:
39
 private:
39
  
40
  
(-)a/src/helper/mobility-helper.cc (+21 lines)
 Lines 25-30    Link Here 
25
#include "ns3/pointer.h"
25
#include "ns3/pointer.h"
26
#include "ns3/config.h"
26
#include "ns3/config.h"
27
#include "ns3/simulator.h"
27
#include "ns3/simulator.h"
28
#include "ns3/object-names.h"
28
#include <iostream>
29
#include <iostream>
29
30
30
namespace ns3 {
31
namespace ns3 {
 Lines 43-48   void Link Here 
43
void 
44
void 
44
MobilityHelper::SetPositionAllocator (Ptr<PositionAllocator> allocator)
45
MobilityHelper::SetPositionAllocator (Ptr<PositionAllocator> allocator)
45
{
46
{
47
  m_position = allocator;
48
}
49
void 
50
MobilityHelper::SetPositionAllocator (std::string allocatorName)
51
{
52
  Ptr<PositionAllocator> allocator = Names::Find<PositionAllocator> (allocatorName);
46
  m_position = allocator;
53
  m_position = allocator;
47
}
54
}
48
void 
55
void 
 Lines 101-106   MobilityHelper::PushReferenceMobilityMod Link Here 
101
  Ptr<MobilityModel> mobility = reference->GetObject<MobilityModel> ();
108
  Ptr<MobilityModel> mobility = reference->GetObject<MobilityModel> ();
102
  m_mobilityStack.push_back (mobility);
109
  m_mobilityStack.push_back (mobility);
103
}
110
}
111
112
void 
113
MobilityHelper::PushReferenceMobilityModel (std::string referenceName)
114
{
115
  Ptr<MobilityModel> mobility = Names::Find<MobilityModel> (referenceName);
116
  m_mobilityStack.push_back (mobility);
117
}
118
104
void 
119
void 
105
MobilityHelper::PopReferenceMobilityModel (void)
120
MobilityHelper::PopReferenceMobilityModel (void)
106
{
121
{
 Lines 147-152   MobilityHelper::Install (Ptr<Node> node) Link Here 
147
  model->SetPosition (position);
162
  model->SetPosition (position);
148
}
163
}
149
164
165
void
166
MobilityHelper::Install (std::string nodeName) const
167
{
168
  Ptr<Node> node = Names::Find<Node> (nodeName);
169
  Install (node);
170
}
150
void 
171
void 
151
MobilityHelper::Install (NodeContainer c) const
172
MobilityHelper::Install (NodeContainer c) const
152
{
173
{
(-)a/src/helper/mobility-helper.h (+38 lines)
 Lines 50-55   public: Link Here 
50
   * \param allocator allocate initial node positions
50
   * \param allocator allocate initial node positions
51
   */
51
   */
52
  void SetPositionAllocator (Ptr<PositionAllocator> allocator);
52
  void SetPositionAllocator (Ptr<PositionAllocator> allocator);
53
  /**
54
   * Set the position allocator which will be used to allocate the initial 
55
   * position of every node initialized during MobilityModel::Install.
56
   *
57
   * \param allocator allocate initial node positions
58
   */
59
  void SetPositionAllocator (std::string allocatorName);
53
60
54
  /**
61
  /**
55
   * \param type the type of mobility model to use.
62
   * \param type the type of mobility model to use.
 Lines 138-143   public: Link Here 
138
   */
145
   */
139
  void PushReferenceMobilityModel (Ptr<Object> reference);
146
  void PushReferenceMobilityModel (Ptr<Object> reference);
140
  /**
147
  /**
148
   * \param reference item to push.
149
   *
150
   * Push an item on the top of the stack of "reference mobility models".
151
   * The input item should be a node instance to which a mobility model
152
   * has already been aggregated (usually by a call to Install).
153
   *
154
   * If this this stack is not empty when MobilityHelper::Install
155
   * is called, the model from the top of the stack is used
156
   * to create a ns3::HierarchicalMobilityModel to make the
157
   * newly-created models define their positions relative to that
158
   * of the parent mobility model.
159
   *
160
   * This method is typically used to create hierarchical mobility
161
   * patterns and positions by starting with the large-scale mobility
162
   * features, and, then, defining the smaller-scale movements relative
163
   * to a few reference points in the large-scale model.
164
   */
165
  void PushReferenceMobilityModel (std::string referenceName);
166
  /**
141
   * Remove the top item from the top of the stack of
167
   * Remove the top item from the top of the stack of
142
   * "reference mobility models".
168
   * "reference mobility models".
143
   */
169
   */
 Lines 161-166   public: Link Here 
161
   * \param node The node to "layout."
187
   * \param node The node to "layout."
162
   */
188
   */
163
  void Install (Ptr<Node> node) const;
189
  void Install (Ptr<Node> node) const;
190
  /**
191
   * \brief "Layout" a single node according to the current position allocator
192
   * type.
193
   *
194
   * This method creates an instance of a ns3::MobilityModel subclass (the 
195
   * type of which was set with MobilityHelper::SetMobilityModel), aggregates
196
   * it to the provided node, and sets an initial position based on the current
197
   * position allocator (set through MobilityHelper::SetPositionAllocator). 
198
   *
199
   * \param nodeName The name of the node to "layout."
200
   */
201
  void Install (std::string nodeName) const;
164
202
165
  /**
203
  /**
166
   * \brief Layout a collection of nodes according to the current position allocator
204
   * \brief Layout a collection of nodes according to the current position allocator
(-)a/src/helper/net-device-container.cc (+13 lines)
 Lines 17-23    Link Here 
17
 *
17
 *
18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
 */
19
 */
20
20
#include "net-device-container.h"
21
#include "net-device-container.h"
22
#include "ns3/object-names.h"
21
23
22
namespace ns3 {
24
namespace ns3 {
23
25
 Lines 25-30   NetDeviceContainer::NetDeviceContainer ( Link Here 
25
{}
27
{}
26
NetDeviceContainer::NetDeviceContainer (Ptr<NetDevice> dev)
28
NetDeviceContainer::NetDeviceContainer (Ptr<NetDevice> dev)
27
{
29
{
30
  m_devices.push_back (dev);
31
}
32
NetDeviceContainer::NetDeviceContainer (std::string devName)
33
{
34
  Ptr<NetDevice> dev = Names::Find<NetDevice> (devName);
28
  m_devices.push_back (dev);
35
  m_devices.push_back (dev);
29
}
36
}
30
NetDeviceContainer::NetDeviceContainer (const NetDeviceContainer &a, const NetDeviceContainer &b)
37
NetDeviceContainer::NetDeviceContainer (const NetDeviceContainer &a, const NetDeviceContainer &b)
 Lines 68-72   NetDeviceContainer::Add (Ptr<NetDevice> Link Here 
68
{
75
{
69
  m_devices.push_back (device);
76
  m_devices.push_back (device);
70
}
77
}
78
void 
79
NetDeviceContainer::Add (std::string deviceName)
80
{
81
  Ptr<NetDevice> device = Names::Find<NetDevice> (deviceName);
82
  m_devices.push_back (device);
83
}
71
84
72
} // namespace ns3
85
} // namespace ns3
(-)a/src/helper/net-device-container.h (+12 lines)
 Lines 46-51   public: Link Here 
46
   */
46
   */
47
  NetDeviceContainer (Ptr<NetDevice> dev);
47
  NetDeviceContainer (Ptr<NetDevice> dev);
48
  /**
48
  /**
49
   * \param devName The name of a device to add to the container
50
   *
51
   * Create a NetDeviceContainer with exactly one device
52
   */
53
  NetDeviceContainer (std::string devName);
54
  /**
49
   * \param a a device container
55
   * \param a a device container
50
   * \param b another device container
56
   * \param b another device container
51
   *
57
   *
 Lines 93-98   public: Link Here 
93
   * Append to the end of this container the input netdevice pointer.
99
   * Append to the end of this container the input netdevice pointer.
94
   */
100
   */
95
  void Add (Ptr<NetDevice> device);
101
  void Add (Ptr<NetDevice> device);
102
  /**
103
   * \param deviceName The name of another netdevice to add.
104
   *
105
   * Append to the end of this container the input netdevice pointer.
106
   */
107
  void Add (std::string deviceName);
96
108
97
private:
109
private:
98
  std::vector<Ptr<NetDevice> > m_devices;
110
  std::vector<Ptr<NetDevice> > m_devices;
(-)a/src/helper/node-container.cc (+12 lines)
 Lines 19-24    Link Here 
19
 */
19
 */
20
#include "node-container.h"
20
#include "node-container.h"
21
#include "ns3/node-list.h"
21
#include "ns3/node-list.h"
22
#include "ns3/object-names.h"
22
23
23
namespace ns3 {
24
namespace ns3 {
24
25
 Lines 27-32   NodeContainer::NodeContainer () Link Here 
27
28
28
NodeContainer::NodeContainer (Ptr<Node> node)
29
NodeContainer::NodeContainer (Ptr<Node> node)
29
{
30
{
31
  m_nodes.push_back (node);
32
}
33
NodeContainer::NodeContainer (std::string nodeName)
34
{
35
  Ptr<Node> node = Names::Find<Node> (nodeName);
30
  m_nodes.push_back (node);
36
  m_nodes.push_back (node);
31
}
37
}
32
NodeContainer::NodeContainer (const NodeContainer &a, const NodeContainer &b)
38
NodeContainer::NodeContainer (const NodeContainer &a, const NodeContainer &b)
 Lines 103-108   NodeContainer::Add (Ptr<Node> node) Link Here 
103
{
109
{
104
  m_nodes.push_back (node);
110
  m_nodes.push_back (node);
105
}
111
}
112
void 
113
NodeContainer::Add (std::string nodeName)
114
{
115
  Ptr<Node> node = Names::Find<Node> (nodeName);
116
  m_nodes.push_back (node);
117
}
106
118
107
NodeContainer 
119
NodeContainer 
108
NodeContainer::GetGlobal (void)
120
NodeContainer::GetGlobal (void)
(-)a/src/helper/node-container.h (+12 lines)
 Lines 45-50   public: Link Here 
45
   * Create a NodeContainer with exactly one node.
45
   * Create a NodeContainer with exactly one node.
46
   */
46
   */
47
  NodeContainer (Ptr<Node> node);
47
  NodeContainer (Ptr<Node> node);
48
  /**
49
   * \param nodeName The name of a node to add to the container
50
   *
51
   * Create a NodeContainer with exactly one node.
52
   */
53
  NodeContainer (std::string nodeName);
48
  /**
54
  /**
49
   * \param a a node container
55
   * \param a a node container
50
   * \param b another node container
56
   * \param b another node container
 Lines 105-110   public: Link Here 
105
   * Append the input node pointer at the end of this NodeContainer.
111
   * Append the input node pointer at the end of this NodeContainer.
106
   */
112
   */
107
  void Add (Ptr<Node> node);
113
  void Add (Ptr<Node> node);
114
  /**
115
   * \param nodeName The name of a node
116
   *
117
   * Append the input node pointer at the end of this NodeContainer.
118
   */
119
  void Add (std::string nodeName);
108
120
109
  /**
121
  /**
110
   * \returns a container which contains a list of _all_ nodes
122
   * \returns a container which contains a list of _all_ nodes
(-)a/src/helper/olsr-helper.cc (+7 lines)
 Lines 20-25    Link Here 
20
#include "olsr-helper.h"
20
#include "olsr-helper.h"
21
#include "ns3/olsr-agent.h"
21
#include "ns3/olsr-agent.h"
22
#include "ns3/node-list.h"
22
#include "ns3/node-list.h"
23
#include "ns3/object-names.h"
23
24
24
namespace ns3 {
25
namespace ns3 {
25
26
 Lines 74-79   OlsrHelper::Install (Ptr<Node> node) Link Here 
74
  agent->Start ();
75
  agent->Start ();
75
}
76
}
76
void 
77
void 
78
OlsrHelper::Install (std::string nodeName)
79
{
80
  Ptr<Node> node = Names::Find<Node> (nodeName);
81
  Install (node);
82
}
83
void 
77
OlsrHelper::InstallAll (void)
84
OlsrHelper::InstallAll (void)
78
{
85
{
79
  Install (NodeContainer::GetGlobal ());
86
  Install (NodeContainer::GetGlobal ());
(-)a/src/helper/olsr-helper.h (+4 lines)
 Lines 56-61   public: Link Here 
56
   */
56
   */
57
  void Install (Ptr<Node> node);
57
  void Install (Ptr<Node> node);
58
  /**
58
  /**
59
   * \brief Enable OLSR routing for a single node
60
   */
61
  void Install (std::string nodeName);
62
  /**
59
   * \brief Enable OLSR routing for all nodes
63
   * \brief Enable OLSR routing for all nodes
60
   */
64
   */
61
  void InstallAll (void);
65
  void InstallAll (void);
(-)a/src/helper/on-off-helper.cc (+8 lines)
 Lines 21-26    Link Here 
21
#include "ns3/inet-socket-address.h"
21
#include "ns3/inet-socket-address.h"
22
#include "ns3/packet-socket-address.h"
22
#include "ns3/packet-socket-address.h"
23
#include "ns3/string.h"
23
#include "ns3/string.h"
24
#include "ns3/object-names.h"
24
25
25
namespace ns3 {
26
namespace ns3 {
26
27
 Lines 40-45   ApplicationContainer Link Here 
40
ApplicationContainer
41
ApplicationContainer
41
OnOffHelper::Install (Ptr<Node> node) const
42
OnOffHelper::Install (Ptr<Node> node) const
42
{
43
{
44
  return ApplicationContainer (InstallPriv (node));
45
}
46
47
ApplicationContainer
48
OnOffHelper::Install (std::string nodeName) const
49
{
50
  Ptr<Node> node = Names::Find<Node> (nodeName);
43
  return ApplicationContainer (InstallPriv (node));
51
  return ApplicationContainer (InstallPriv (node));
44
}
52
}
45
53
(-)a/src/helper/on-off-helper.h (+9 lines)
 Lines 72-77   public: Link Here 
72
   */
72
   */
73
  ApplicationContainer Install (Ptr<Node> node) const;
73
  ApplicationContainer Install (Ptr<Node> node) const;
74
74
75
  /**
76
   * Install an ns3::OnOffApplication on the node configured with all the 
77
   * attributes set with SetAttribute.
78
   *
79
   * \param node The node on which an OnOffApplication will be installed.
80
   * \returns Container of Ptr to the applications installed.
81
   */
82
  ApplicationContainer Install (std::string nodeName) const;
83
75
private:
84
private:
76
  /**
85
  /**
77
   * Install an ns3::OnOffApplication on the node configured with all the 
86
   * Install an ns3::OnOffApplication on the node configured with all the 
(-)a/src/helper/packet-sink-helper.cc (+8 lines)
 Lines 21-26    Link Here 
21
#include "packet-sink-helper.h"
21
#include "packet-sink-helper.h"
22
#include "ns3/string.h"
22
#include "ns3/string.h"
23
#include "ns3/inet-socket-address.h"
23
#include "ns3/inet-socket-address.h"
24
#include "ns3/object-names.h"
24
25
25
namespace ns3 {
26
namespace ns3 {
26
27
 Lines 56-61   ApplicationContainer Link Here 
56
ApplicationContainer
57
ApplicationContainer
57
PacketSinkHelper::Install (Ptr<Node> node) const
58
PacketSinkHelper::Install (Ptr<Node> node) const
58
{
59
{
60
  return ApplicationContainer (InstallPriv (node));
61
}
62
63
ApplicationContainer
64
PacketSinkHelper::Install (std::string nodeName) const
65
{
66
  Ptr<Node> node = Names::Find<Node> (nodeName);
59
  return ApplicationContainer (InstallPriv (node));
67
  return ApplicationContainer (InstallPriv (node));
60
}
68
}
61
69
(-)a/src/helper/packet-sink-helper.h (-1 / +8 lines)
 Lines 47-55   public: Link Here 
47
   * Install an ns3::PacketSinkApplication on each node of the input container
47
   * Install an ns3::PacketSinkApplication on each node of the input container
48
   * configured with all the attributes set with SetAttribute.
48
   * configured with all the attributes set with SetAttribute.
49
   *
49
   *
50
   * \param c The node on which a PacketSinkApplication will be installed.
50
   * \param node The node on which a PacketSinkApplication will be installed.
51
   */
51
   */
52
  ApplicationContainer Install (Ptr<Node> node) const;
52
  ApplicationContainer Install (Ptr<Node> node) const;
53
  /**
54
   * Install an ns3::PacketSinkApplication on each node of the input container
55
   * configured with all the attributes set with SetAttribute.
56
   *
57
   * \param nodeName The name of the node on which a PacketSinkApplication will be installed.
58
   */
59
  ApplicationContainer Install (std::string nodeName) const;
53
60
54
private:
61
private:
55
  Ptr<Application> InstallPriv (Ptr<Node> node) const;
62
  Ptr<Application> InstallPriv (Ptr<Node> node) const;
(-)a/src/helper/packet-socket-helper.cc (-2 / +10 lines)
 Lines 20-25    Link Here 
20
20
21
#include "packet-socket-helper.h"
21
#include "packet-socket-helper.h"
22
#include "ns3/packet-socket-factory.h"
22
#include "ns3/packet-socket-factory.h"
23
#include "ns3/object-names.h"
23
24
24
namespace ns3 {
25
namespace ns3 {
25
26
 Lines 35-42   void Link Here 
35
void
36
void
36
PacketSocketHelper::Install (Ptr<Node> node) const
37
PacketSocketHelper::Install (Ptr<Node> node) const
37
{
38
{
38
    Ptr<PacketSocketFactory> factory = CreateObject<PacketSocketFactory> ();
39
  Ptr<PacketSocketFactory> factory = CreateObject<PacketSocketFactory> ();
39
    node->AggregateObject (factory);
40
  node->AggregateObject (factory);
41
}
42
43
void
44
PacketSocketHelper::Install (std::string nodeName) const
45
{
46
  Ptr<Node> node = Names::Find<Node> (nodeName);
47
  Install (node);
40
}
48
}
41
49
42
} // namespace ns3
50
} // namespace ns3
(-)a/src/helper/packet-socket-helper.h (+8 lines)
 Lines 40-45   public: Link Here 
40
  void Install (Ptr<Node> node) const;
40
  void Install (Ptr<Node> node) const;
41
41
42
  /**
42
  /**
43
   * Aggregate an instance of a ns3::PacketSocketFactory onto the provided
44
   * node.
45
   *
46
   * \param nodeName The name of the node on which to aggregate the ns3::PacketSocketFactory.
47
   */
48
  void Install (std::string nodeName) const;
49
50
  /**
43
   * For each node in the provided container, aggregate an instance of a
51
   * For each node in the provided container, aggregate an instance of a
44
   * ns3::PacketSocketFactory.
52
   * ns3::PacketSocketFactory.
45
   *
53
   *
(-)a/src/helper/point-to-point-helper.cc (-1 / +31 lines)
 Lines 25-31    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/object-names.h"
29
29
30
namespace ns3 {
30
namespace ns3 {
31
31
 Lines 204-209   PointToPointHelper::Install (Ptr<Node> a Link Here 
204
  return container;
204
  return container;
205
}
205
}
206
206
207
NetDeviceContainer 
208
PointToPointHelper::Install (Ptr<Node> a, std::string bName)
209
{
210
  Ptr<Node> b = Names::Find<Node> (bName);
211
  return Install (a, b);
212
}
213
214
NetDeviceContainer 
215
PointToPointHelper::Install (std::string aName, Ptr<Node> b)
216
{
217
  Ptr<Node> a = Names::Find<Node> (aName);
218
  return Install (a, b);
219
}
220
221
NetDeviceContainer 
222
PointToPointHelper::Install (std::string aName, std::string bName)
223
{
224
  Ptr<Node> a = Names::Find<Node> (aName);
225
  Ptr<Node> b = Names::Find<Node> (bName);
226
  return Install (a, b);
227
}
228
207
void 
229
void 
208
PointToPointHelper::InstallStar (Ptr<Node> hub, NodeContainer spokes, 
230
PointToPointHelper::InstallStar (Ptr<Node> hub, NodeContainer spokes, 
209
                                 NetDeviceContainer& hubDevices, NetDeviceContainer& spokeDevices)
231
                                 NetDeviceContainer& hubDevices, NetDeviceContainer& spokeDevices)
 Lines 214-219   PointToPointHelper::InstallStar (Ptr<Nod Link Here 
214
      hubDevices.Add (nd.Get (0));
236
      hubDevices.Add (nd.Get (0));
215
      spokeDevices.Add (nd.Get (1));
237
      spokeDevices.Add (nd.Get (1));
216
    }
238
    }
239
}
240
241
void 
242
PointToPointHelper::InstallStar (std::string hubName, NodeContainer spokes, 
243
                                 NetDeviceContainer& hubDevices, NetDeviceContainer& spokeDevices)
244
{
245
  Ptr<Node> hub = Names::Find<Node> (hubName);
246
  InstallStar (hub, spokes, hubDevices, spokeDevices);
217
}
247
}
218
248
219
void 
249
void 
(-)a/src/helper/point-to-point-helper.h (+52 lines)
 Lines 180-185   public: Link Here 
180
  NetDeviceContainer Install (Ptr<Node> a, Ptr<Node> b);
180
  NetDeviceContainer Install (Ptr<Node> a, Ptr<Node> b);
181
181
182
  /**
182
  /**
183
   * \param a first node
184
   * \param bName name of second node
185
   *
186
   * Saves you from having to construct a temporary NodeContainer.
187
   */
188
  NetDeviceContainer Install (Ptr<Node> a, std::string bName);
189
190
  /**
191
   * \param aName Name of first node
192
   * \param b second node
193
   *
194
   * Saves you from having to construct a temporary NodeContainer.
195
   */
196
  NetDeviceContainer Install (std::string aName, Ptr<Node> b);
197
198
  /**
199
   * \param aName Name of first node
200
   * \param bName Name of second node
201
   *
202
   * Saves you from having to construct a temporary NodeContainer.
203
   */
204
  NetDeviceContainer Install (std::string aNode, std::string bNode);
205
206
  /**
183
   * \brief Make a star network topology.
207
   * \brief Make a star network topology.
184
   *
208
   *
185
   * Given a pointer to a node that  will become the hub of the star, and a 
209
   * Given a pointer to a node that  will become the hub of the star, and a 
 Lines 207-212   public: Link Here 
207
  void InstallStar (Ptr<Node> hub, NodeContainer spokes, 
231
  void InstallStar (Ptr<Node> hub, NodeContainer spokes, 
208
                    NetDeviceContainer& hubDevices, NetDeviceContainer& spokeDevices);
232
                    NetDeviceContainer& hubDevices, NetDeviceContainer& spokeDevices);
209
233
234
  /**
235
   * \brief Make a star network topology.
236
   *
237
   * Given a pointer to a node that  will become the hub of the star, and a 
238
   * NodeContainer containing pointers to the nodes that will become the 
239
   * spokes; we construct point to point net devices on the hub (corresponding 
240
   * to the spokes) and store them in the hubDevices NetDeviceContainer.  We 
241
   * add a net device to each spoke node and store them in the spokeDevices 
242
   * NetDeviceContainer.  A point-to-point channel is created for each spoke.
243
   *
244
   * The ordering of the devices in the hubDevices container is according to
245
   * the order of the spokes container -- that is, hubDevices[0] will be the
246
   * net device used on the hub that talks to spokes[0].  the container entry
247
   * spokeDevices[0] will have the device that hubDevices[0] talks to -- those
248
   * two devices are the ones that connect hub to spokes[0].
249
   *
250
   * \param hubName The name of the central node of the star network
251
   * \param spokes A NodeContainer of the nodes that will be the spoke (leaf)
252
   *               nodes
253
   * \param hubDevices A NetDeviceContainer that will be filled with pointers
254
   *                   to the point-to-point net devices created on the hub.
255
   * \param spokeDevices A NetDeviceContainer that will be filled with pointers
256
   *                    to the point-to-point net devices created on each of 
257
   *                    the spokes.
258
   */
259
  void InstallStar (std::string hubName, NodeContainer spokes, 
260
                    NetDeviceContainer& hubDevices, NetDeviceContainer& spokeDevices);
261
210
private:
262
private:
211
  void EnablePcap (Ptr<Node> node, Ptr<NetDevice> device, Ptr<Queue> queue);
263
  void EnablePcap (Ptr<Node> node, Ptr<NetDevice> device, Ptr<Queue> queue);
212
  void EnableAscii (Ptr<Node> node, Ptr<NetDevice> device);
264
  void EnableAscii (Ptr<Node> node, Ptr<NetDevice> device);
(-)a/src/helper/static-multicast-route-helper.cc (+76 lines)
 Lines 23-28    Link Here 
23
#include "ns3/assert.h"
23
#include "ns3/assert.h"
24
#include "ns3/ipv4-address.h"
24
#include "ns3/ipv4-address.h"
25
#include "ns3/ipv4.h"
25
#include "ns3/ipv4.h"
26
#include "ns3/object-names.h"
26
#include "static-multicast-route-helper.h"
27
#include "static-multicast-route-helper.h"
27
28
28
namespace ns3 {
29
namespace ns3 {
 Lines 53-58   StaticMulticastRouteHelper::AddMulticast Link Here 
53
  ipv4->AddMulticastRoute (source, group, iifIndex, outputInterfaces);
54
  ipv4->AddMulticastRoute (source, group, iifIndex, outputInterfaces);
54
}
55
}
55
56
57
void  
58
StaticMulticastRouteHelper::AddMulticastRoute (
59
  Ptr<Node> n,
60
  Ipv4Address source, 
61
  Ipv4Address group,  
62
  std::string inputName, 
63
  NetDeviceContainer output)
64
{
65
  Ptr<NetDevice> input = Names::Find<NetDevice> (inputName);
66
  AddMulticastRoute (n, source, group, input, output);
67
}
68
69
void  
70
StaticMulticastRouteHelper::AddMulticastRoute (
71
  std::string nName,
72
  Ipv4Address source, 
73
  Ipv4Address group,  
74
  Ptr<NetDevice> input, 
75
  NetDeviceContainer output)
76
{
77
  Ptr<Node> n = Names::Find<Node> (nName);
78
  AddMulticastRoute (n, source, group, input, output);
79
}
80
81
void  
82
StaticMulticastRouteHelper::AddMulticastRoute (
83
  std::string nName,
84
  Ipv4Address source, 
85
  Ipv4Address group,  
86
  std::string inputName, 
87
  NetDeviceContainer output)
88
{
89
  Ptr<NetDevice> input = Names::Find<NetDevice> (inputName);
90
  Ptr<Node> n = Names::Find<Node> (nName);
91
  AddMulticastRoute (n, source, group, input, output);
92
}
93
56
void
94
void
57
StaticMulticastRouteHelper::SetDefaultMulticastRoute (
95
StaticMulticastRouteHelper::SetDefaultMulticastRoute (
58
  Ptr<Node> n, 
96
  Ptr<Node> n, 
 Lines 61-66   StaticMulticastRouteHelper::SetDefaultMu Link Here 
61
  Ptr<Ipv4> ipv4 = n->GetObject<Ipv4> ();
99
  Ptr<Ipv4> ipv4 = n->GetObject<Ipv4> ();
62
  uint32_t ifIndexSrc = ipv4->FindInterfaceForDevice (nd);
100
  uint32_t ifIndexSrc = ipv4->FindInterfaceForDevice (nd);
63
  ipv4->SetDefaultMulticastRoute (ifIndexSrc);
101
  ipv4->SetDefaultMulticastRoute (ifIndexSrc);
102
}
103
104
void
105
StaticMulticastRouteHelper::SetDefaultMulticastRoute (
106
  Ptr<Node> n, 
107
  std::string ndName)
108
{
109
  Ptr<NetDevice> nd = Names::Find<NetDevice> (ndName);
110
  SetDefaultMulticastRoute (n, nd);
111
}
112
113
void
114
StaticMulticastRouteHelper::SetDefaultMulticastRoute (
115
  std::string nName, 
116
  Ptr<NetDevice> nd)
117
{
118
  Ptr<Node> n = Names::Find<Node> (nName);
119
  SetDefaultMulticastRoute (n, nd);
120
}
121
122
void
123
StaticMulticastRouteHelper::SetDefaultMulticastRoute (
124
  std::string nName, 
125
  std::string ndName)
126
{
127
  Ptr<Node> n = Names::Find<Node> (nName);
128
  Ptr<NetDevice> nd = Names::Find<NetDevice> (ndName);
129
  SetDefaultMulticastRoute (n, nd);
64
}
130
}
65
131
66
void
132
void
 Lines 73-77   StaticMulticastRouteHelper::JoinMulticas Link Here 
73
  ipv4->JoinMulticastGroup (source, group);
139
  ipv4->JoinMulticastGroup (source, group);
74
}
140
}
75
141
142
void
143
StaticMulticastRouteHelper::JoinMulticastGroup (
144
  std::string nName, 
145
  Ipv4Address source, 
146
  Ipv4Address group)
147
{
148
  Ptr<Node> n = Names::Find<Node> (nName);
149
  JoinMulticastGroup (n, source, group);
150
}
151
76
} // namespace ns3
152
} // namespace ns3
77
153
(-)a/src/helper/static-multicast-route-helper.h (-2 / +11 lines)
 Lines 34-46   public: Link Here 
34
public:
34
public:
35
  StaticMulticastRouteHelper ();
35
  StaticMulticastRouteHelper ();
36
36
37
  void AddMulticastRoute (Ptr<Node>, Ipv4Address source, Ipv4Address group,  
37
  void AddMulticastRoute (Ptr<Node> n, Ipv4Address source, Ipv4Address group,  
38
    Ptr<NetDevice> input, NetDeviceContainer output);
38
    Ptr<NetDevice> input, NetDeviceContainer output);
39
  void AddMulticastRoute (std::string n, Ipv4Address source, Ipv4Address group,  
40
    Ptr<NetDevice> input, NetDeviceContainer output);
41
  void AddMulticastRoute (Ptr<Node> n, Ipv4Address source, Ipv4Address group,  
42
    std::string inputName, NetDeviceContainer output);
43
  void AddMulticastRoute (std::string nName, Ipv4Address source, Ipv4Address group,  
44
    std::string inputName, NetDeviceContainer output);
39
45
40
  void SetDefaultMulticastRoute (Ptr<Node> n, Ptr<NetDevice> nd);
46
  void SetDefaultMulticastRoute (Ptr<Node> n, Ptr<NetDevice> nd);
47
  void SetDefaultMulticastRoute (Ptr<Node> n, std::string ndName);
48
  void SetDefaultMulticastRoute (std::string nName, Ptr<NetDevice> nd);
49
  void SetDefaultMulticastRoute (std::string nName, std::string ndName);
41
50
42
  void JoinMulticastGroup (Ptr<Node> n, Ipv4Address source, Ipv4Address group);
51
  void JoinMulticastGroup (Ptr<Node> n, Ipv4Address source, Ipv4Address group);
43
52
  void JoinMulticastGroup (std::string nName, Ipv4Address source, Ipv4Address group);
44
};
53
};
45
54
46
} // namespace ns3
55
} // namespace ns3
(-)a/src/helper/udp-echo-helper.cc (+15 lines)
 Lines 21-26    Link Here 
21
#include "ns3/udp-echo-server.h"
21
#include "ns3/udp-echo-server.h"
22
#include "ns3/udp-echo-client.h"
22
#include "ns3/udp-echo-client.h"
23
#include "ns3/uinteger.h"
23
#include "ns3/uinteger.h"
24
#include "ns3/object-names.h"
24
25
25
namespace ns3 {
26
namespace ns3 {
26
27
 Lines 41-46   ApplicationContainer Link Here 
41
ApplicationContainer
42
ApplicationContainer
42
UdpEchoServerHelper::Install (Ptr<Node> node) const
43
UdpEchoServerHelper::Install (Ptr<Node> node) const
43
{
44
{
45
  return ApplicationContainer (InstallPriv (node));
46
}
47
48
ApplicationContainer
49
UdpEchoServerHelper::Install (std::string nodeName) const
50
{
51
  Ptr<Node> node = Names::Find<Node> (nodeName);
44
  return ApplicationContainer (InstallPriv (node));
52
  return ApplicationContainer (InstallPriv (node));
45
}
53
}
46
54
 Lines 87-92   UdpEchoClientHelper::Install (Ptr<Node> Link Here 
87
}
95
}
88
96
89
ApplicationContainer
97
ApplicationContainer
98
UdpEchoClientHelper::Install (std::string nodeName) const
99
{
100
  Ptr<Node> node = Names::Find<Node> (nodeName);
101
  return ApplicationContainer (InstallPriv (node));
102
}
103
104
ApplicationContainer
90
UdpEchoClientHelper::Install (NodeContainer c) const
105
UdpEchoClientHelper::Install (NodeContainer c) const
91
{
106
{
92
  ApplicationContainer apps;
107
  ApplicationContainer apps;
(-)a/src/helper/udp-echo-helper.h (+2 lines)
 Lines 36-41   public: Link Here 
36
  void SetAttribute (std::string name, const AttributeValue &value);
36
  void SetAttribute (std::string name, const AttributeValue &value);
37
37
38
  ApplicationContainer Install (Ptr<Node> node) const;
38
  ApplicationContainer Install (Ptr<Node> node) const;
39
  ApplicationContainer Install (std::string nodeName) const;
39
  ApplicationContainer Install (NodeContainer c) const;
40
  ApplicationContainer Install (NodeContainer c) const;
40
41
41
private:
42
private:
 Lines 52-57   public: Link Here 
52
  void SetAttribute (std::string name, const AttributeValue &value);
53
  void SetAttribute (std::string name, const AttributeValue &value);
53
54
54
  ApplicationContainer Install (Ptr<Node> node) const;
55
  ApplicationContainer Install (Ptr<Node> node) const;
56
  ApplicationContainer Install (std::string nodeName) const;
55
  ApplicationContainer Install (NodeContainer c) const;
57
  ApplicationContainer Install (NodeContainer c) const;
56
58
57
private:
59
private:
(-)a/src/helper/v4ping-helper.cc (+28 lines)
 Lines 1-5    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2008 INRIA
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
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
 */
20
1
#include "v4ping-helper.h"
21
#include "v4ping-helper.h"
2
#include "ns3/v4ping.h"
22
#include "ns3/v4ping.h"
23
#include "ns3/object-names.h"
3
24
4
namespace ns3 {
25
namespace ns3 {
5
26
 Lines 18-23   ApplicationContainer Link Here 
18
ApplicationContainer
39
ApplicationContainer
19
V4PingHelper::Install (Ptr<Node> node) const
40
V4PingHelper::Install (Ptr<Node> node) const
20
{
41
{
42
  return ApplicationContainer (InstallPriv (node));
43
}
44
45
ApplicationContainer
46
V4PingHelper::Install (std::string nodeName) const
47
{
48
  Ptr<Node> node = Names::Find<Node> (nodeName);
21
  return ApplicationContainer (InstallPriv (node));
49
  return ApplicationContainer (InstallPriv (node));
22
}
50
}
23
51
(-)a/src/helper/v4ping-helper.h (+1 lines)
 Lines 16-21   public: Link Here 
16
16
17
  ApplicationContainer Install (NodeContainer nodes) const;
17
  ApplicationContainer Install (NodeContainer nodes) const;
18
  ApplicationContainer Install (Ptr<Node> node) const;
18
  ApplicationContainer Install (Ptr<Node> node) const;
19
  ApplicationContainer Install (std::string nodeName) const;
19
20
20
private:
21
private:
21
  Ptr<Application> InstallPriv (Ptr<Node> node) const;
22
  Ptr<Application> InstallPriv (Ptr<Node> node) const;
(-)a/src/helper/wifi-helper.cc (-3 / +7 lines)
 Lines 31-38    Link Here 
31
#include "ns3/pcap-writer.h"
31
#include "ns3/pcap-writer.h"
32
#include "ns3/config.h"
32
#include "ns3/config.h"
33
#include "ns3/simulator.h"
33
#include "ns3/simulator.h"
34
34
#include "ns3/object-names.h"
35
36
35
37
NS_LOG_COMPONENT_DEFINE ("WifiHelper");
36
NS_LOG_COMPONENT_DEFINE ("WifiHelper");
38
37
 Lines 126-131   WifiHelper::Install (const WifiPhyHelper Link Here 
126
{
125
{
127
  return Install (phy, NodeContainer (node));
126
  return Install (phy, NodeContainer (node));
128
}
127
}
129
128
NetDeviceContainer 
129
WifiHelper::Install (const WifiPhyHelper &phy, std::string nodeName) const
130
{
131
  Ptr<Node> node = Names::Find<Node> (nodeName);
132
  return Install (phy, NodeContainer (node));
133
}
130
134
131
} // namespace ns3
135
} // namespace ns3
(-)a/src/helper/wifi-helper.h (+6 lines)
 Lines 153-158   public: Link Here 
153
   * \returns a device container which contains all the devices created by this method.
153
   * \returns a device container which contains all the devices created by this method.
154
   */
154
   */
155
  NetDeviceContainer Install (const WifiPhyHelper &phy, Ptr<Node> node) const;
155
  NetDeviceContainer Install (const WifiPhyHelper &phy, Ptr<Node> node) const;
156
  /**
157
   * \param phy the PHY helper to create PHY objects
158
   * \param nodeName the name of node on which a wifi device must be created
159
   * \returns a device container which contains all the devices created by this method.
160
   */
161
  NetDeviceContainer Install (const WifiPhyHelper &phy, std::string nodeName) const;
156
162
157
private:
163
private:
158
  ObjectFactory m_stationManager;
164
  ObjectFactory m_stationManager;
(-)a/src/helper/yans-wifi-helper.cc (-1 / +7 lines)
 Lines 27-32    Link Here 
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/config.h"
29
#include "ns3/config.h"
30
#include "ns3/object-names.h"
30
31
31
namespace ns3 {
32
namespace ns3 {
32
33
 Lines 164-169   YansWifiPhyHelper::SetChannel (Ptr<YansW Link Here 
164
  m_channel = channel;
165
  m_channel = channel;
165
}
166
}
166
void 
167
void 
168
YansWifiPhyHelper::SetChannel (std::string channelName)
169
{
170
  Ptr<YansWifiChannel> channel = Names::Find<YansWifiChannel> (channelName);
171
  m_channel = channel;
172
}
173
void 
167
YansWifiPhyHelper::Set (std::string name, const AttributeValue &v)
174
YansWifiPhyHelper::Set (std::string name, const AttributeValue &v)
168
{
175
{
169
  m_phy.Set (name, v);
176
  m_phy.Set (name, v);
 Lines 191-197   YansWifiPhyHelper::SetErrorRateModel (st Link Here 
191
  m_errorRateModel.Set (n6, v6);
198
  m_errorRateModel.Set (n6, v6);
192
  m_errorRateModel.Set (n7, v7);
199
  m_errorRateModel.Set (n7, v7);
193
}
200
}
194
195
201
196
Ptr<WifiPhy> 
202
Ptr<WifiPhy> 
197
YansWifiPhyHelper::Create (Ptr<Node> node, Ptr<WifiNetDevice> device) const
203
YansWifiPhyHelper::Create (Ptr<Node> node, Ptr<WifiNetDevice> device) const
(-)a/src/helper/yans-wifi-helper.h (+6 lines)
 Lines 155-160   public: Link Here 
155
   */
155
   */
156
  void SetChannel (Ptr<YansWifiChannel> channel);
156
  void SetChannel (Ptr<YansWifiChannel> channel);
157
  /**
157
  /**
158
   * \param channelName The name of the channel to associate to this helper
159
   *
160
   * Every PHY created by a call to Install is associated to this channel.
161
   */
162
  void SetChannel (std::string channelName);
163
  /**
158
   * \param name the name of the attribute to set
164
   * \param name the name of the attribute to set
159
   * \param v the value of the attribute
165
   * \param v the value of the attribute
160
   *
166
   *
(-)a/examples/names.cc (-5 / +5 lines)
 Lines 56-63   main (int argc, char *argv[]) Link Here 
56
  // as the destination, so these will go into the name system as "/Names/client"
56
  // as the destination, so these will go into the name system as "/Names/client"
57
  // and "/Names/server".  
57
  // and "/Names/server".  
58
  //
58
  //
59
  Names::Add ("/Names", "client", n.Get (0));
59
  Names::Add ("/Names/client", n.Get (0));
60
  Names::Add ("/Names", "server", n.Get (1));
60
  Names::Add ("/Names/server", n.Get (1));
61
61
62
  InternetStackHelper internet;
62
  InternetStackHelper internet;
63
  internet.Install (n);
63
  internet.Install (n);
 Lines 72-83   main (int argc, char *argv[]) Link Here 
72
  // Add some human readable names for the devices we'll be interested in.
72
  // Add some human readable names for the devices we'll be interested in.
73
  // We add the names to the name space "under" the nodes we created above.
73
  // We add the names to the name space "under" the nodes we created above.
74
  // This has the effect of making "/Names/client/eth0" and "/Names/server/eth0"
74
  // This has the effect of making "/Names/client/eth0" and "/Names/server/eth0"
75
  // Note that the first parameter must reference a previously named object,
75
  // Note that the first part of the path must reference a previously named object,
76
  // and we have, in fact, already named objects "/Names/client" and
76
  // and we have, in fact, already named objects "/Names/client" and
77
  // "/Names/server"
77
  // "/Names/server"
78
  //
78
  //
79
  Names::Add ("/Names/client", "eth0", d.Get (0));
79
  Names::Add ("/Names/client/eth0", d.Get (0));
80
  Names::Add ("/Names/server", "eth0", d.Get (1));
80
  Names::Add ("/Names/server/eth0", d.Get (1));
81
81
82
  Ipv4AddressHelper ipv4;
82
  Ipv4AddressHelper ipv4;
83
  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
83
  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
(-)a/src/core/object-names.cc (-4 / +66 lines)
 Lines 161-167   bool Link Here 
161
bool
161
bool
162
NamesPriv::Add (std::string name, Ptr<Object> object)
162
NamesPriv::Add (std::string name, Ptr<Object> object)
163
{
163
{
164
  return Add (Ptr<Object> (0, false), name, object);
164
  NS_LOG_FUNCTION (name << object);
165
  //
166
  // This is the simple, easy to use version of Add, so we want it to be flexible.
167
  //
168
  // If we are provided a name that doesn't begin with "/Names", we assume 
169
  // that the caller has given us a shortname that she wants added to the root
170
  // namespace.  This results in a call to the "real" Add with context set to 
171
  // zero, indicating what we want to do.
172
  //
173
  // If we are given a name that begins with "/Names/" we assume that this is a
174
  // fullname to the object we want to create.  We split the fullname into a 
175
  // context string and and a final segment and then call the "Real" Add.
176
  //
177
  std::string namespaceName = "/Names";
178
  std::string::size_type offset = name.find (namespaceName);
179
  if (offset == 0)
180
    {
181
      //
182
      // This must be a fully qualified longname.  All fully qualified names begin
183
      // with "/Names".  We have to split off the final segment which will become
184
      // the shortname of the object.
185
      //
186
      std::string::size_type i = name.rfind ("/");
187
      NS_ASSERT_MSG (i != std::string::npos, "NamesPriv::Add(): Internal error.  Can't find '/' in name");
188
189
      //
190
      // The slash we found cannot be the slash at the start of the namespaceName.
191
      // This would indicate there is no shortname in the path at all.
192
      //
193
      NS_ASSERT_MSG (i != 0, "NamesPriv::Add(): Can't find a shortname in the name string");
194
195
      //
196
      // We now know where the context string starts and ends, and where the
197
      // shortname starts and ends.  All we have to do is to call our available
198
      // function for creating addubg a shortname under a context string.
199
      //
200
      return Add (name.substr (0, i), name.substr (i + 1), object);
201
    }
202
  else
203
    {
204
      //
205
      // This must be a shortname.  Shortnames can't have ANY '/' characters in
206
      // them since they are interpreted as a final segment of a fullname.  A 
207
      // shortname in this context means creating a name in the root namespace.
208
      // We indicate this by passing a zero context to the "real" add.
209
      //
210
      NS_ASSERT_MSG (offset == std::string::npos, "NamesPriv::Add(): Unexpected '/' in shortname");
211
      return Add (Ptr<Object> (0, false), name, object);
212
    }
165
}
213
}
166
214
167
bool
215
bool
 Lines 204-210   NamesPriv::Add (std::string context, std Link Here 
204
{
252
{
205
  if (context == "/Names")
253
  if (context == "/Names")
206
    {
254
    {
207
      return Add (name, object);
255
      return Add (Ptr<Object> (0, false), name, object);
208
    }
256
    }
209
  return Add (FindObjectFromFullName (context), name, object);
257
  return Add (FindObjectFromFullName (context), name, object);
210
}
258
}
 Lines 589-599   NamesTest::RunTests (void) Link Here 
589
  NS_TEST_ASSERT_EQUAL (foundObject, serverEth0);
637
  NS_TEST_ASSERT_EQUAL (foundObject, serverEth0);
590
638
591
  //
639
  //
592
  // We also have some syntactical sugary methods, so make sure they do what
640
  // We also have some syntactically sugary methods, so make sure they do what
593
  // they should as well.
641
  // they should as well.
594
  //
642
  //
595
  Ptr<TestObject> bridge = CreateObject<TestObject> ();
643
  Ptr<TestObject> bridge = CreateObject<TestObject> ();
596
  result = Names::Add ("/Names", "Bridge", client);
644
  result = Names::Add ("/Names", "Bridge", bridge);
597
  NS_TEST_ASSERT_EQUAL (result, true);
645
  NS_TEST_ASSERT_EQUAL (result, true);
598
646
599
  Ptr<TestObject> bridgeEth0 = CreateObject<TestObject> ();
647
  Ptr<TestObject> bridgeEth0 = CreateObject<TestObject> ();
 Lines 605-610   NamesTest::RunTests (void) Link Here 
605
653
606
  foundObject = Names::Find<TestObject> ("/Names/Bridge/eth0");
654
  foundObject = Names::Find<TestObject> ("/Names/Bridge/eth0");
607
  NS_TEST_ASSERT_EQUAL (foundObject, bridgeEth0);
655
  NS_TEST_ASSERT_EQUAL (foundObject, bridgeEth0);
656
657
  Ptr<TestObject> wireless = CreateObject<TestObject> ();
658
  result = Names::Add ("/Names/Wireless", wireless);
659
  NS_TEST_ASSERT_EQUAL (result, true);
660
661
  Ptr<TestObject> wirelessAth0 = CreateObject<TestObject> ();
662
  result = Names::Add ("/Names/Wireless/ath0", wirelessAth0);
663
  NS_TEST_ASSERT_EQUAL (result, true);
664
665
  foundObject = Names::Find<TestObject> ("/Names/Wireless");
666
  NS_TEST_ASSERT_EQUAL (foundObject, wireless);
667
668
  foundObject = Names::Find<TestObject> ("/Names/Wireless/ath0");
669
  NS_TEST_ASSERT_EQUAL (foundObject, wirelessAth0);
608
670
609
  //
671
  //
610
  // Run the simulator and destroy it to get the Destroy method called on the
672
  // Run the simulator and destroy it to get the Destroy method called on the
(-)a/src/core/config.cc (-1 / +8 lines)
 Lines 332-339   Resolver::DoResolve (std::string path, P Link Here 
332
332
333
  //
333
  //
334
  // We're done with the object name service hooks, so proceed down the path
334
  // We're done with the object name service hooks, so proceed down the path
335
  // of types and attributes.
335
  // of types and attributes; but only if root is nonzero.  If root is zero
336
  // and we find ourselves here, we are trying to check in the namespace for
337
  // a path that is not in the "/Names" namespace.  We will have previously
338
  // found any matches, so we just bail out.
336
  //
339
  //
340
  if (root == 0)
341
    {
342
      return;
343
    }
337
  std::string::size_type dollarPos = item.find ("$");
344
  std::string::size_type dollarPos = item.find ("$");
338
  if (dollarPos == 0)
345
  if (dollarPos == 0)
339
    {
346
    {
(-)a/src/core/config.cc (-1 / +13 lines)
 Lines 287-295   Resolver::DoResolve (std::string path, P Link Here 
287
  tmp = path.find ("/");
287
  tmp = path.find ("/");
288
  NS_ASSERT (tmp == 0);
288
  NS_ASSERT (tmp == 0);
289
  std::string::size_type next = path.find ("/", 1);
289
  std::string::size_type next = path.find ("/", 1);
290
290
  if (next == std::string::npos)
291
  if (next == std::string::npos)
291
    {
292
    {
292
      DoResolveOne (root);
293
      //
294
      // If root is zero, we're beginning to see if we can use the object name 
295
      // service to resolve this path.  It is impossible to have a object name 
296
      // associated with the root of the object name service since that root
297
      // is not an object.  This path must be referring to something in another
298
      // namespace and it will have been found already since the name service
299
      // is always consulted last.
300
      // 
301
      if (root)
302
        {
303
          DoResolveOne (root);
304
        }
293
      return;
305
      return;
294
    }
306
    }
295
  std::string item = path.substr (1, next-1);
307
  std::string item = path.substr (1, next-1);
(-)a/examples/names.cc (-2 / +19 lines)
 Lines 79-84   main (int argc, char *argv[]) Link Here 
79
  Names::Add ("/Names/client/eth0", d.Get (0));
79
  Names::Add ("/Names/client/eth0", d.Get (0));
80
  Names::Add ("/Names/server/eth0", d.Get (1));
80
  Names::Add ("/Names/server/eth0", d.Get (1));
81
81
82
  //
83
  // You can use the object names that you've assigned in calls to the Config
84
  // system to set Object Attributes.  For example, you can set the Mtu 
85
  // Attribute of a Csma devices using the object naming service.
86
  //
87
  Config::Set ("/Names/client/eth0/Mtu", UintegerValue (1234));
88
89
  //
90
  // You can mix and match names and Attributes in calls to the Config system.
91
  // For example, if "eth0" is a named object, you can get to its parent through
92
  // a different namespace.  For example, you could use the NodeList namespace
93
  // to get to the server node, and then continue seamlessly adding named objects
94
  // in the path. This is not nearly as readable as the previous version, but it
95
  // illustrates how you can mix and match object names and Attribute names.
96
  //
97
  Config::Set ("/NodeList/1/eth0/Mtu", UintegerValue (1234));
98
82
  Ipv4AddressHelper ipv4;
99
  Ipv4AddressHelper ipv4;
83
  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
100
  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
84
  Ipv4InterfaceContainer i = ipv4.Assign (d);
101
  Ipv4InterfaceContainer i = ipv4.Assign (d);
 Lines 109-116   main (int argc, char *argv[]) Link Here 
109
  apps.Stop (Seconds (10.0));
126
  apps.Stop (Seconds (10.0));
110
127
111
  //
128
  //
112
  // Use the config system to connect a trace source using the object name
129
  // Use the Config system to connect a trace source using the object name
113
  // system to specify the path.
130
  // service to specify the path.
114
  //
131
  //
115
  Config::Connect ("/Names/client/eth0/Rx", MakeCallback (&RxEvent));
132
  Config::Connect ("/Names/client/eth0/Rx", MakeCallback (&RxEvent));
116
133
(-)a/src/core/config.cc (-1 / +6 lines)
 Lines 931-937   ConfigTest::RunTests (void) Link Here 
931
  d1->SetAttribute ("Source", IntegerValue (-4));
931
  d1->SetAttribute ("Source", IntegerValue (-4));
932
  NS_TEST_ASSERT_EQUAL (m_traceNotification, 0);
932
  NS_TEST_ASSERT_EQUAL (m_traceNotification, 0);
933
933
934
934
  //
935
  // The Config system is intertwined with the Names system.  In the process
936
  // of parsing the paths above, we also created a NamesPriv singleton.  In
937
  // order to get a valgrind-clean run we need to clean up that singleton.
938
  //
939
  Names::Delete ();
935
940
936
  return result;
941
  return result;
937
}
942
}
(-)a/src/core/object-names.cc (-7 / +16 lines)
 Lines 17-28    Link Here 
17
 */
17
 */
18
18
19
#include <map>
19
#include <map>
20
#include "ns3/object.h"
20
#include "object.h"
21
#include "ns3/log.h"
21
#include "log.h"
22
#include "ns3/assert.h"
22
#include "assert.h"
23
#include "ns3/abort.h"
23
#include "abort.h"
24
#include "object-names.h"
24
#include "ns3/simulator.h"
25
#include "ns3/simulator.h"
25
#include "object-names.h"
26
26
27
namespace ns3 {
27
namespace ns3 {
28
28
 Lines 92-101   public: Link Here 
92
  Ptr<Object> FindObjectFromShortName (Ptr<Object> context, std::string name);
92
  Ptr<Object> FindObjectFromShortName (Ptr<Object> context, std::string name);
93
93
94
  static NamesPriv *Get (void);
94
  static NamesPriv *Get (void);
95
  
95
  static void Delete (void);
96
private:
96
private:
97
  static NamesPriv **DoGet (void);
97
  static NamesPriv **DoGet (void);
98
  static void Delete (void);
99
98
100
  NameNode *IsNamed (Ptr<Object>);
99
  NameNode *IsNamed (Ptr<Object>);
101
  bool IsDuplicateName (NameNode *node, std::string name);
100
  bool IsDuplicateName (NameNode *node, std::string name);
 Lines 156-161   NamesPriv::~NamesPriv () Link Here 
156
      delete i->second;
155
      delete i->second;
157
      i->second = 0;
156
      i->second = 0;
158
    }
157
    }
158
159
  m_root.m_parent = 0;
160
  m_root.m_name = "";
161
  m_root.m_object = 0;
159
}
162
}
160
163
161
bool
164
bool
 Lines 442-447   NamesPriv::IsDuplicateName (NameNode *no Link Here 
442
      NS_LOG_LOGIC ("Name exists in name map");
445
      NS_LOG_LOGIC ("Name exists in name map");
443
      return true;
446
      return true;
444
    }
447
    }
448
}
449
450
void
451
Names::Delete (void)
452
{
453
  NamesPriv::Delete ();
445
}
454
}
446
455
447
bool
456
bool
(-)a/src/core/object-names.h (-1 / +7 lines)
 Lines 171-178   public: Link Here 
171
  template <typename T>
171
  template <typename T>
172
  static Ptr<T> FindObjectFromShortName (Ptr<Object> context, std::string name);
172
  static Ptr<T> FindObjectFromShortName (Ptr<Object> context, std::string name);
173
173
174
  /**
175
   * Clean up all of the data structures of the implementation and delete the
176
   * underlying singleton.  Used to get valgrind-clean runs if the simulator
177
   * is not run.  Normally singleton cleanup is scheduled on Simulator::Destroy.
178
   */
179
  static void Delete (void);
180
174
private:
181
private:
175
176
  /**
182
  /**
177
   * \internal
183
   * \internal
178
   *
184
   *
(-)a/src/core/object-names.h (+22 lines)
 Lines 55-60   public: Link Here 
55
   *                name to be defined.
55
   *                name to be defined.
56
   * \param name The name of the object you want to associate.
56
   * \param name The name of the object you want to associate.
57
   * \param obj A smart pointer to the object itself.
57
   * \param obj A smart pointer to the object itself.
58
   *
59
   * \returns true if the association was successfully completed, false otherwise
58
   */
60
   */
59
  static bool Add (Ptr<Object> context, std::string name, Ptr<Object> object);
61
  static bool Add (Ptr<Object> context, std::string name, Ptr<Object> object);
60
62
 Lines 69-74   public: Link Here 
69
   *                under which you want this name to be defined.
71
   *                under which you want this name to be defined.
70
   * \param name The name of the object you want to associate.
72
   * \param name The name of the object you want to associate.
71
   * \param obj A smart pointer to the object itself.
73
   * \param obj A smart pointer to the object itself.
74
   *
75
   * \returns true if the association was successfully completed, false otherwise
72
   */
76
   */
73
  static bool Add (std::string context, std::string name, Ptr<Object> object);
77
  static bool Add (std::string context, std::string name, Ptr<Object> object);
74
78
 Lines 87-92   public: Link Here 
87
   *
91
   *
88
   * \param object A spart pointer to an object for which you want to find
92
   * \param object A spart pointer to an object for which you want to find
89
   *               its shortname.
93
   *               its shortname.
94
   *
95
   * \returns a string containing the shortname of the object.
90
   */
96
   */
91
  static std::string FindShortName (Ptr<Object> object);
97
  static std::string FindShortName (Ptr<Object> object);
92
98
 Lines 106-111   public: Link Here 
106
   *
112
   *
107
   * \param object A spart pointer to an object for which you want to find
113
   * \param object A spart pointer to an object for which you want to find
108
   *               its fullname.
114
   *               its fullname.
115
   *
116
   * \returns a string containing the fullname of the object.
109
   */
117
   */
110
  static std::string FindFullName (Ptr<Object> object);
118
  static std::string FindFullName (Ptr<Object> object);
111
119
 Lines 121-126   public: Link Here 
121
   *
129
   *
122
   * \param name A string containing a fully qualified name space name 
130
   * \param name A string containing a fully qualified name space name 
123
   *             used to locate the object.
131
   *             used to locate the object.
132
   *
133
   * \returns a smart pointer to the named object converted to the requested
134
   *          type.
124
   */
135
   */
125
  template <typename T>
136
  template <typename T>
126
  static Ptr<T> FindObjectFromFullName (std::string name);
137
  static Ptr<T> FindObjectFromFullName (std::string name);
 Lines 137-142   public: Link Here 
137
   *
148
   *
138
   * \param name A string containing a fully qualified name space name 
149
   * \param name A string containing a fully qualified name space name 
139
   *             used to locate the object.
150
   *             used to locate the object.
151
   *
152
   *
153
   * \returns a smart pointer to the named object converted to the requested
154
   *          type.
140
   *
155
   *
141
   * @comment This method is identical to FindObjectFromFullName, but has a
156
   * @comment This method is identical to FindObjectFromFullName, but has a
142
   * short signature since it is a common use and we want it to be easy to 
157
   * short signature since it is a common use and we want it to be easy to 
 Lines 167-172   public: Link Here 
167
   * \param context A spart pointer to an object under which you want to look 
182
   * \param context A spart pointer to an object under which you want to look 
168
   *                for the provided name.
183
   *                for the provided name.
169
   * \param name A string containing a shortname to look for.
184
   * \param name A string containing a shortname to look for.
185
   *
186
   * \returns a smart pointer to the named object converted to the requested
187
   *          type.
170
   */
188
   */
171
  template <typename T>
189
  template <typename T>
172
  static Ptr<T> FindObjectFromShortName (Ptr<Object> context, std::string name);
190
  static Ptr<T> FindObjectFromShortName (Ptr<Object> context, std::string name);
 Lines 185-190   private: Link Here 
185
   * \brief Non-templated internal version of FindObjectFromLongName
203
   * \brief Non-templated internal version of FindObjectFromLongName
186
   *
204
   *
187
   * \param name A string containing a longname to look for.
205
   * \param name A string containing a longname to look for.
206
   *
207
   * \returns a smart pointer to the named object.
188
   */
208
   */
189
  static Ptr<Object> FindObjectFromFullNameInternal (std::string name);
209
  static Ptr<Object> FindObjectFromFullNameInternal (std::string name);
190
210
 Lines 196-201   private: Link Here 
196
   * \param context A spart pointer to an object under which you want to look 
216
   * \param context A spart pointer to an object under which you want to look 
197
   *                for the provided name.
217
   *                for the provided name.
198
   * \param name A string containing a shortname to look for.
218
   * \param name A string containing a shortname to look for.
219
   *
220
   * \returns a smart pointer to the named object.
199
   */
221
   */
200
  static Ptr<Object> FindObjectFromShortNameInternal (Ptr<Object> context, std::string name);
222
  static Ptr<Object> FindObjectFromShortNameInternal (Ptr<Object> context, std::string name);
201
};
223
};

Return to bug 215