src/core/names.cc
author Craig Dowell <craigdo@ee.washington.edu>
Fri, 30 Jan 2009 17:34:41 -0800
changeset 4153 93bb91eae5cd
parent 4151 682a4cae7a5f
child 4158 2b6dba4062e1
permissions -rw-r--r--
add a Rename function to the object name service to facilitate auto naming
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     1
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     2
/*
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     3
 * Copyright (c) 2009 University of Washington
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     4
 *
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
 *
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
 * GNU General Public License for more details.
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
 *
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    17
 */
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    18
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    19
#include <map>
4145
bb930262e55c add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
Craig Dowell <craigdo@ee.washington.edu>
parents: 4141
diff changeset
    20
#include "object.h"
bb930262e55c add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
Craig Dowell <craigdo@ee.washington.edu>
parents: 4141
diff changeset
    21
#include "log.h"
bb930262e55c add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
Craig Dowell <craigdo@ee.washington.edu>
parents: 4141
diff changeset
    22
#include "assert.h"
bb930262e55c add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
Craig Dowell <craigdo@ee.washington.edu>
parents: 4141
diff changeset
    23
#include "abort.h"
4147
5d8530130930 rename object-names.{cc,h} to names.{cc,h} per convention
Craig Dowell <craigdo@ee.washington.edu>
parents: 4145
diff changeset
    24
#include "names.h"
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
#include "ns3/simulator.h"
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
namespace ns3 {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
NS_LOG_COMPONENT_DEFINE ("Names");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    30
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
class NameNode
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
public:
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
  NameNode ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
  NameNode (const NameNode &nameNode);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    36
  NameNode (NameNode *parent, std::string name, Ptr<Object> object);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
  NameNode &operator = (const NameNode &rhs);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    38
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
 ~NameNode ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
  NameNode *m_parent;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
  std::string m_name;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    43
  Ptr<Object> m_object;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
  std::map<std::string, NameNode *> m_nameMap;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
};
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    47
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    48
NameNode::NameNode ()
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    49
  : m_parent (0), m_name (""), m_object (0)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
NameNode::NameNode (const NameNode &nameNode)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
  m_parent = nameNode.m_parent;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
  m_name = nameNode.m_name;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    57
  m_object = nameNode.m_object;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    58
  m_nameMap = nameNode.m_nameMap;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    59
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
NameNode &
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
NameNode::operator = (const NameNode &rhs)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    63
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
  m_parent = rhs.m_parent;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    65
  m_name = rhs.m_name;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
  m_object = rhs.m_object;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
  m_nameMap = rhs.m_nameMap;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
  return *this;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    69
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    71
NameNode::NameNode (NameNode *parent, std::string name, Ptr<Object> object)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    72
  : m_parent (parent), m_name (name), m_object (object)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    73
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    74
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    76
NameNode::~NameNode ()
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    77
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    78
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    79
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    80
class NamesPriv 
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    81
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
public:
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    83
  NamesPriv ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    84
  ~NamesPriv ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    85
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    86
  bool Add (std::string name, Ptr<Object> obj);
4153
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
    87
  bool Rename (std::string oldname, std::string newname);
4151
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
    88
  bool Add (std::string context, std::string name, Ptr<Object> object);
4153
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
    89
  bool Rename (std::string context, std::string oldname, std::string newname);
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    90
  bool Add (Ptr<Object> context, std::string name, Ptr<Object> object);
4153
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
    91
  bool Rename (Ptr<Object> context, std::string oldname, std::string newname);
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    92
  std::string FindShortName (Ptr<Object> object);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    93
  std::string FindFullName (Ptr<Object> object);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    94
  Ptr<Object> FindObjectFromFullName (std::string name);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    95
  Ptr<Object> FindObjectFromShortName (Ptr<Object> context, std::string name);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    96
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    97
  static NamesPriv *Get (void);
4145
bb930262e55c add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
Craig Dowell <craigdo@ee.washington.edu>
parents: 4141
diff changeset
    98
  static void Delete (void);
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    99
private:
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   100
  static NamesPriv **DoGet (void);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   101
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   102
  NameNode *IsNamed (Ptr<Object>);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   103
  bool IsDuplicateName (NameNode *node, std::string name);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   104
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   105
  NameNode m_root;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   106
  std::map<Ptr<Object>, NameNode *> m_objectMap;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   107
};
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   108
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   109
NamesPriv *
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   110
NamesPriv::Get (void)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   111
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   112
  return *(DoGet ());
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   113
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   114
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   115
NamesPriv **
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   116
NamesPriv::DoGet (void)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   117
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   118
  static NamesPriv *ptr = 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   119
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   120
  if (ptr == 0)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   121
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   122
      ptr = new NamesPriv;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   123
      Simulator::ScheduleDestroy (&NamesPriv::Delete);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   124
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   125
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   126
  return &ptr;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   127
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   128
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   129
void 
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   130
NamesPriv::Delete (void)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   131
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   132
  NS_LOG_FUNCTION_NOARGS ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   133
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   134
  NamesPriv **ptr = DoGet ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   135
  delete *ptr;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   136
  *ptr = 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   137
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   138
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   139
NamesPriv::NamesPriv ()
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   140
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   141
  NS_LOG_FUNCTION_NOARGS ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   142
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   143
  m_root.m_parent = 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   144
  m_root.m_name = "Names";
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   145
  m_root.m_object = 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   146
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   147
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   148
NamesPriv::~NamesPriv ()
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   149
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   150
  NS_LOG_FUNCTION_NOARGS ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   151
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   152
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   153
  // Every name is associated with an object in the object map, so freeing the
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   154
  // NameNodes in this map will free all of the memory allocated for the NameNodes
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   155
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   156
  for (std::map<Ptr<Object>, NameNode *>::iterator i = m_objectMap.begin (); i != m_objectMap.end (); ++i)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   157
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   158
      delete i->second;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   159
      i->second = 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   160
    }
4145
bb930262e55c add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
Craig Dowell <craigdo@ee.washington.edu>
parents: 4141
diff changeset
   161
bb930262e55c add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
Craig Dowell <craigdo@ee.washington.edu>
parents: 4141
diff changeset
   162
  m_root.m_parent = 0;
bb930262e55c add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
Craig Dowell <craigdo@ee.washington.edu>
parents: 4141
diff changeset
   163
  m_root.m_name = "";
bb930262e55c add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
Craig Dowell <craigdo@ee.washington.edu>
parents: 4141
diff changeset
   164
  m_root.m_object = 0;
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   165
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   166
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   167
bool
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   168
NamesPriv::Add (std::string name, Ptr<Object> object)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   169
{
4141
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   170
  NS_LOG_FUNCTION (name << object);
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   171
  //
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   172
  // This is the simple, easy to use version of Add, so we want it to be flexible.
4151
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   173
  // We don't want to force a user to always type the fully qualified namespace 
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   174
  // name, so we allow the namespace name to be omitted.  For example, calling
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   175
  // Add ("Client/ath0", obj) should result in exactly the same behavior as
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   176
  // Add ("/Names/Client/ath0", obj).  Calling Add ("Client", obj) should have
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   177
  // the same effect as Add ("Names/Client", obj)
4141
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   178
  //
4151
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   179
  // The first thing to do, then, is to "canonicalize" the input string to always
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   180
  // be a fully qualified name.
4141
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   181
  //
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   182
  // If we are given a name that begins with "/Names/" we assume that this is a
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   183
  // fullname to the object we want to create.  We split the fullname into a 
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   184
  // context string and and a final segment and then call the "Real" Add.
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   185
  //
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   186
  std::string namespaceName = "/Names";
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   187
  std::string::size_type offset = name.find (namespaceName);
4151
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   188
  if (offset != 0)
4141
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   189
    {
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   190
      //
4151
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   191
      // This must be a name that has the "/Names" namespace prefix omitted.  
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   192
      // Do some reasonableness checking on the rest of the name.
4141
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   193
      //
4151
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   194
      offset = name.find ("/");
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   195
      if (offset == 0)
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   196
        {
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   197
          NS_ASSERT_MSG (false, "NamesPriv::Add(): Name begins with '/' but not \"/Names\"");
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   198
          return false;
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   199
        }
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   200
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   201
      name = "/Names/" + name;
4141
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   202
    }
4151
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   203
  
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   204
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   205
  // There must now be a fully qualified longname in the string.  All fully 
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   206
  // qualified names begin with "/Names".  We have to split off the final 
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   207
  // segment which will become the shortname of the object.  A '/' that
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   208
  // separates the context from the final segment had better be there since
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   209
  // we just made sure that at least the namespace name was there.
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   210
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   211
  std::string::size_type i = name.rfind ("/");
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   212
  NS_ASSERT_MSG (i != std::string::npos, "NamesPriv::Add(): Internal error.  Can't find '/' in name");
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   213
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   214
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   215
  // The slash we found cannot be the slash at the start of the namespaceName.
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   216
  // This would indicate there is no shortname in the path at all.  It can be
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   217
  // any other index.
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   218
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   219
  NS_ASSERT_MSG (i != 0, "NamesPriv::Add(): Can't find a shortname in the name string");
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   220
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   221
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   222
  // We now know where the context string starts and ends, and where the
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   223
  // shortname starts and ends.  All we have to do is to call our available
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   224
  // function for creating addubg a shortname under a context string.
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   225
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   226
  return Add (name.substr (0, i), name.substr (i + 1), object);
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   227
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   228
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   229
bool
4153
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   230
NamesPriv::Rename (std::string oldname, std::string newname)
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   231
{
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   232
  NS_LOG_FUNCTION (oldname << newname);
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   233
  //
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   234
  // This is the simple, easy to use version of Rename, so we want it to be 
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   235
  // flexible.   We don't want to force a user to always type the fully 
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   236
  // qualified namespace name, so we allow the namespace name to be omitted.
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   237
  // For example, calling Rename ("Client/ath0", "eth0") should result in 
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   238
  // exactly the same behavior as Rename ("/Names/Client/ath0", "eth0").
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   239
  // Calling Rename ("Client", "Router") should have the same effect as 
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   240
  // Rename ("Names/Client", "Router")
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   241
  //
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   242
  // The first thing to do, then, is to "canonicalize" the input string to always
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   243
  // be a fully qualified name.
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   244
  //
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   245
  // If we are given a name that begins with "/Names/" we assume that this is a
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   246
  // fullname to the object we want to change.  We split the fullname into a 
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   247
  // context string and and a final segment and then call the "Real" Rename.
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   248
  //
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   249
  std::string namespaceName = "/Names";
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   250
  std::string::size_type offset = oldname.find (namespaceName);
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   251
  if (offset != 0)
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   252
    {
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   253
      //
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   254
      // This must be a name that has the "/Names" namespace prefix omitted.  
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   255
      // Do some reasonableness checking on the rest of the name.
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   256
      //
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   257
      offset = oldname.find ("/");
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   258
      if (offset == 0)
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   259
        {
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   260
          NS_ASSERT_MSG (false, "NamesPriv::Add(): Name begins with '/' but not \"/Names\"");
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   261
          return false;
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   262
        }
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   263
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   264
      oldname = "/Names/" + oldname;
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   265
    }
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   266
  
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   267
  //
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   268
  // There must now be a fully qualified longname in the oldname string.  All 
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   269
  // fully qualified names begin with "/Names".  We have to split off the final 
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   270
  // segment which will become the shortname we want to rename.  A '/' that
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   271
  // separates the context from the final segment had better be there since
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   272
  // we just made sure that at least the namespace name was there.
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   273
  //
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   274
  std::string::size_type i = oldname.rfind ("/");
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   275
  NS_ASSERT_MSG (i != std::string::npos, "NamesPriv::Add(): Internal error.  Can't find '/' in name");
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   276
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   277
  //
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   278
  // The slash we found cannot be the slash at the start of the namespaceName.
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   279
  // This would indicate there is no shortname in the path at all.  It can be
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   280
  // any other index.
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   281
  //
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   282
  NS_ASSERT_MSG (i != 0, "NamesPriv::Add(): Can't find a shortname in the name string");
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   283
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   284
  //
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   285
  // We now know where the context string starts and ends, and where the
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   286
  // shortname starts and ends.  All we have to do is to call our available
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   287
  // function for creating addubg a shortname under a context string.
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   288
  //
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   289
  return Rename (oldname.substr (0, i), oldname.substr (i + 1), newname);
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   290
}
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   291
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   292
bool
4148
7f1a5bd869e5 move a function definition in names.cc for a little more clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4147
diff changeset
   293
NamesPriv::Add (std::string context, std::string name, Ptr<Object> object)
7f1a5bd869e5 move a function definition in names.cc for a little more clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4147
diff changeset
   294
{
7f1a5bd869e5 move a function definition in names.cc for a little more clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4147
diff changeset
   295
  if (context == "/Names")
7f1a5bd869e5 move a function definition in names.cc for a little more clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4147
diff changeset
   296
    {
7f1a5bd869e5 move a function definition in names.cc for a little more clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4147
diff changeset
   297
      return Add (Ptr<Object> (0, false), name, object);
7f1a5bd869e5 move a function definition in names.cc for a little more clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4147
diff changeset
   298
    }
7f1a5bd869e5 move a function definition in names.cc for a little more clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4147
diff changeset
   299
  return Add (FindObjectFromFullName (context), name, object);
7f1a5bd869e5 move a function definition in names.cc for a little more clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4147
diff changeset
   300
}
7f1a5bd869e5 move a function definition in names.cc for a little more clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4147
diff changeset
   301
7f1a5bd869e5 move a function definition in names.cc for a little more clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4147
diff changeset
   302
bool
4153
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   303
NamesPriv::Rename (std::string context, std::string oldname, std::string newname)
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   304
{
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   305
  if (context == "/Names")
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   306
    {
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   307
      return Rename (Ptr<Object> (0, false), oldname, newname);
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   308
    }
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   309
  return Rename (FindObjectFromFullName (context), oldname, newname);
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   310
}
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   311
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   312
bool
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   313
NamesPriv::Add (Ptr<Object> context, std::string name, Ptr<Object> object)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   314
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   315
  NS_LOG_FUNCTION (context << name << object);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   316
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   317
  if (IsNamed (object))
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   318
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   319
      NS_LOG_LOGIC ("Object is already named");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   320
      return false;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   321
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   322
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   323
  NameNode *node = 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   324
  if (context)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   325
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   326
      node = IsNamed (context);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   327
      NS_ASSERT_MSG (node, "NamesPriv::Name(): context must point to a previously named node");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   328
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   329
  else
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   330
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   331
      node = &m_root;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   332
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   333
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   334
  if (IsDuplicateName (node, name))
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   335
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   336
      NS_LOG_LOGIC ("Name is already taken");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   337
      return false;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   338
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   339
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   340
  NameNode *newNode = new NameNode(node, name, object);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   341
  node->m_nameMap[name] = newNode;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   342
  m_objectMap[object] = newNode;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   343
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   344
  return true;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   345
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   346
4153
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   347
bool
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   348
NamesPriv::Rename (Ptr<Object> context, std::string oldname, std::string newname)
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   349
{
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   350
  NS_LOG_FUNCTION (context << oldname << newname);
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   351
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   352
  NameNode *node = 0;
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   353
  if (context)
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   354
    {
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   355
      node = IsNamed (context);
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   356
      NS_ASSERT_MSG (node, "NamesPriv::Name(): context must point to a previously named node");
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   357
    }
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   358
  else
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   359
    {
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   360
      node = &m_root;
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   361
    }
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   362
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   363
  if (IsDuplicateName (node, newname))
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   364
    {
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   365
      NS_LOG_LOGIC ("New name is already taken");
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   366
      return false;
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   367
    }
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   368
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   369
  std::map<std::string, NameNode *>::iterator i = node->m_nameMap.find (oldname);
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   370
  if (i == node->m_nameMap.end ())
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   371
    {
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   372
      NS_LOG_LOGIC ("Old name does not exist in name map");
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   373
      return false;
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   374
    }
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   375
  else
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   376
    {
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   377
      NS_LOG_LOGIC ("Old name exists in name map");
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   378
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   379
      //
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   380
      // The rename process consists of:
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   381
      // 1.  Geting the pointer to the name node from the map and remembering it;
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   382
      // 2.  Removing the map entry corresponding to oldname from the map;
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   383
      // 3.  Changing the name string in the name node;
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   384
      // 4.  Adding the name node back in the map under the newname.
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   385
      //
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   386
      NameNode *changeNode = i->second;
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   387
      node->m_nameMap.erase (i);
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   388
      changeNode->m_name = newname;
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   389
      node->m_nameMap[newname] = changeNode;
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   390
      return true;
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   391
    }
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   392
}
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   393
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   394
std::string
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   395
NamesPriv::FindShortName (Ptr<Object> object)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   396
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   397
  NS_LOG_FUNCTION (object);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   398
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   399
  std::map<Ptr<Object>, NameNode *>::iterator i = m_objectMap.find (object);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   400
  if (i == m_objectMap.end ())
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   401
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   402
      NS_LOG_LOGIC ("Object does not exist in object map");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   403
      return "";
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   404
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   405
  else
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   406
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   407
      NS_LOG_LOGIC ("Object exists in object map");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   408
      return i->second->m_name;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   409
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   410
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   411
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   412
std::string
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   413
NamesPriv::FindFullName (Ptr<Object> object)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   414
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   415
  NS_LOG_FUNCTION (object);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   416
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   417
  std::map<Ptr<Object>, NameNode *>::iterator i = m_objectMap.find (object);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   418
  if (i == m_objectMap.end ())
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   419
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   420
      NS_LOG_LOGIC ("Object does not exist in object map");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   421
      return "";
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   422
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   423
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   424
  NameNode *p = i->second;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   425
  NS_ASSERT_MSG (p, "NamesPriv::FindFullName(): Internal error: Invalid NameNode pointer from map");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   426
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   427
  std::string fullname;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   428
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   429
  do
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   430
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   431
      fullname = "/" + p->m_name + fullname;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   432
      NS_LOG_LOGIC ("fullname is " << fullname);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   433
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   434
  while ((p = p->m_parent) != 0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   435
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   436
  return fullname;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   437
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   438
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   439
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   440
Ptr<Object>
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   441
NamesPriv::FindObjectFromFullName (std::string name)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   442
{
4149
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   443
  //
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   444
  // This is hooked in from simple, easy to use version of Find, so we want it
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   445
  // to be flexible.
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   446
  //
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   447
  // If we are provided a name that doesn't begin with "/Names", we assume 
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   448
  // that the caller has simply given us a path starting with a shortname that
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   449
  // is in the root namespace.  This allows peole to omit the "/Names" prefix.
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   450
  // and simply do a Find ("Client/eth0") instead of having to always do a
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   451
  // Find ("/Names/Client/eth0");
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   452
  //
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   453
  // So, if we are given a name that begins with "/Names/" the upshot is that we
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   454
  // just remove that prefix and treat the rest of the string as starting with a 
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   455
  // shortname in the root namespace.
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   456
  //
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   457
  std::string namespaceName = "/Names/";
4149
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   458
  std::string remaining;
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   459
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   460
  std::string::size_type offset = name.find (namespaceName);
4149
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   461
  if (offset == 0)
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   462
    {
4149
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   463
      NS_LOG_LOGIC (name << " is a fully qualified name");
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   464
      remaining = name.substr (namespaceName.size ());
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   465
    }
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   466
  else
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   467
    {
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   468
      NS_LOG_LOGIC (name << " begins with a relative shortname");
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   469
      remaining = name;
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   470
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   471
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   472
  NameNode *node = &m_root;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   473
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   474
  //
4149
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   475
  // The string <remaining> is now composed entirely of path segments in the
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   476
  // /Names name space and we have eaten the leading slash. e.g., 
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   477
  // remaining = "ClientNode/eth0"
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   478
  //
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   479
  // The start of the search is always at the root of the name space.
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   480
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   481
  for (;;)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   482
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   483
      NS_LOG_LOGIC ("Looking for the object of name " << remaining);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   484
      offset = remaining.find ("/");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   485
      if (offset == std::string::npos)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   486
        {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   487
          //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   488
          // There are no remaining slashes so this is the last segment of the 
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   489
          // specified name.  We're done when we find it
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   490
          //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   491
          std::map<std::string, NameNode *>::iterator i = node->m_nameMap.find (remaining);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   492
          if (i == node->m_nameMap.end ())
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   493
            {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   494
              NS_LOG_LOGIC ("Name does not exist in name map");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   495
              return 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   496
            }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   497
          else
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   498
            {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   499
              NS_LOG_LOGIC ("Name parsed, found object");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   500
              return i->second->m_object;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   501
            }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   502
        }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   503
      else
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   504
        {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   505
          //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   506
          // There are more slashes so this is an intermediate segment of the 
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   507
          // specified name.  We need to "recurse" when we find this segment.
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   508
          //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   509
          offset = remaining.find ("/");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   510
          std::string segment = remaining.substr(0, offset);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   511
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   512
          std::map<std::string, NameNode *>::iterator i = node->m_nameMap.find (segment);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   513
          if (i == node->m_nameMap.end ())
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   514
            {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   515
              NS_LOG_LOGIC ("Name does not exist in name map");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   516
              return 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   517
            }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   518
          else
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   519
            {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   520
              node = i->second;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   521
              remaining = remaining.substr (offset + 1);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   522
              NS_LOG_LOGIC ("Intermediate segment parsed");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   523
              continue;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   524
            }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   525
        }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   526
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   527
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   528
  NS_ASSERT_MSG (node, "NamesPriv::FindObjectFromFullName(): Internal error:  this can't happen");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   529
  return 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   530
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   531
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   532
Ptr<Object>
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   533
NamesPriv::FindObjectFromShortName (Ptr<Object> context, std::string name)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   534
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   535
  NS_LOG_FUNCTION (context << name);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   536
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   537
  NameNode *node = 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   538
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   539
  if (context == 0)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   540
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   541
      NS_LOG_LOGIC ("Zero context implies root NameNode");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   542
      node = &m_root;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   543
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   544
  else
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   545
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   546
      node = IsNamed (context);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   547
      if (node == 0)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   548
        {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   549
          NS_LOG_LOGIC ("Context does not point to a previously named node");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   550
          return 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   551
        }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   552
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   553
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   554
  std::map<std::string, NameNode *>::iterator i = node->m_nameMap.find (name);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   555
  if (i == node->m_nameMap.end ())
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   556
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   557
      NS_LOG_LOGIC ("Name does not exist in name map");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   558
      return 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   559
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   560
  else
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   561
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   562
      NS_LOG_LOGIC ("Name exists in name map");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   563
      return i->second->m_object;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   564
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   565
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   566
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   567
NameNode *
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   568
NamesPriv::IsNamed (Ptr<Object> object)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   569
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   570
  NS_LOG_FUNCTION (object);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   571
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   572
  std::map<Ptr<Object>, NameNode *>::iterator i = m_objectMap.find (object);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   573
  if (i == m_objectMap.end ())
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   574
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   575
      NS_LOG_LOGIC ("Object does not exist in object map, returning NameNode 0");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   576
      return 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   577
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   578
  else
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   579
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   580
      NS_LOG_LOGIC ("Object exists in object map, returning NameNode " << &i->second);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   581
      return i->second;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   582
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   583
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   584
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   585
bool
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   586
NamesPriv::IsDuplicateName (NameNode *node, std::string name)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   587
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   588
  NS_LOG_FUNCTION (node << name);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   589
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   590
  std::map<std::string, NameNode *>::iterator i = node->m_nameMap.find (name);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   591
  if (i == node->m_nameMap.end ())
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   592
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   593
      NS_LOG_LOGIC ("Name does not exist in name map");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   594
      return false;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   595
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   596
  else
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   597
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   598
      NS_LOG_LOGIC ("Name exists in name map");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   599
      return true;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   600
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   601
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   602
4145
bb930262e55c add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
Craig Dowell <craigdo@ee.washington.edu>
parents: 4141
diff changeset
   603
void
bb930262e55c add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
Craig Dowell <craigdo@ee.washington.edu>
parents: 4141
diff changeset
   604
Names::Delete (void)
bb930262e55c add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
Craig Dowell <craigdo@ee.washington.edu>
parents: 4141
diff changeset
   605
{
bb930262e55c add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
Craig Dowell <craigdo@ee.washington.edu>
parents: 4141
diff changeset
   606
  NamesPriv::Delete ();
bb930262e55c add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
Craig Dowell <craigdo@ee.washington.edu>
parents: 4141
diff changeset
   607
}
bb930262e55c add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
Craig Dowell <craigdo@ee.washington.edu>
parents: 4141
diff changeset
   608
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   609
bool
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   610
Names::Add (std::string name, Ptr<Object> object)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   611
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   612
  return NamesPriv::Get ()->Add (name, object);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   613
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   614
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   615
bool
4153
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   616
Names::Rename (std::string oldname, std::string newname)
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   617
{
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   618
  return NamesPriv::Get ()->Rename (oldname, newname);
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   619
}
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   620
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   621
bool
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   622
Names::Add (Ptr<Object> context, std::string name, Ptr<Object> object)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   623
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   624
  return NamesPriv::Get ()->Add (context, name, object);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   625
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   626
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   627
bool
4153
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   628
Names::Rename (Ptr<Object> context, std::string oldname, std::string newname)
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   629
{
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   630
  return NamesPriv::Get ()->Rename (context, oldname, newname);
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   631
}
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   632
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   633
bool
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   634
Names::Add (std::string context, std::string name, Ptr<Object> object)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   635
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   636
  return NamesPriv::Get ()->Add (context, name, object);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   637
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   638
4153
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   639
bool
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   640
Names::Rename (std::string context, std::string oldname, std::string newname)
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   641
{
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   642
  return NamesPriv::Get ()->Rename (context, oldname, newname);
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   643
}
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   644
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   645
std::string
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   646
Names::FindShortName (Ptr<Object> object)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   647
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   648
  return NamesPriv::Get ()->FindShortName (object);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   649
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   650
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   651
std::string
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   652
Names::FindFullName (Ptr<Object> object)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   653
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   654
  return NamesPriv::Get ()->FindFullName (object);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   655
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   656
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   657
Ptr<Object>
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   658
Names::FindObjectFromFullNameInternal (std::string name)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   659
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   660
  return NamesPriv::Get ()->FindObjectFromFullName (name);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   661
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   662
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   663
Ptr<Object>
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   664
Names::FindObjectFromShortNameInternal (Ptr<Object> context, std::string name)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   665
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   666
  return NamesPriv::Get ()->FindObjectFromShortName (context, name);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   667
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   668
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   669
} //namespace ns3
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   670
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   671
#ifdef RUN_SELF_TESTS
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   672
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   673
#include "test.h"
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   674
#include "object-factory.h"
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   675
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   676
namespace ns3 {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   677
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   678
class TestObject : public Object
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   679
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   680
public:
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   681
  static TypeId GetTypeId (void) 
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   682
  {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   683
    static TypeId tid = TypeId ("TestObject")
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   684
      .SetParent (Object::GetTypeId ())
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   685
      .HideFromDocumentation ()
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   686
      .AddConstructor<TestObject> ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   687
    return tid;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   688
  }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   689
  TestObject () {}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   690
  virtual void Dispose (void) {}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   691
};
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   692
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   693
class NamesTest : public Test
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   694
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   695
public:
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   696
  NamesTest ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   697
  virtual bool RunTests (void);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   698
};
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   699
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   700
NamesTest::NamesTest ()
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   701
  : Test ("Names")
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   702
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   703
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   704
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   705
bool 
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   706
NamesTest::RunTests (void)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   707
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   708
  bool result = true;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   709
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   710
  // 
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   711
  // Name a couple of objects at the root level
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   712
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   713
  Ptr<TestObject> client = CreateObject<TestObject> ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   714
  result = Names::Add ("Client", client);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   715
  NS_TEST_ASSERT_EQUAL (result, true);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   716
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   717
  Ptr<TestObject> server = CreateObject<TestObject> ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   718
  result = Names::Add ("Server", server);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   719
  NS_TEST_ASSERT_EQUAL (result, true);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   720
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   721
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   722
  // We shouldn't be able to add another name to a previously named object
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   723
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   724
  result = Names::Add ("Not Client", client);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   725
  NS_TEST_ASSERT_EQUAL (result, false);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   726
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   727
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   728
  // We shouldn't be able to duplicate a name at the root level.
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   729
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   730
  Ptr<TestObject> secondClient = CreateObject<TestObject> ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   731
  result = Names::Add ("Client", secondClient);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   732
  NS_TEST_ASSERT_EQUAL (result, false);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   733
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   734
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   735
  // We should be able to add a new name in the first object's context
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   736
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   737
  Ptr<TestObject> clientEth0 = CreateObject<TestObject> ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   738
  result = Names::Add (client, "eth0", clientEth0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   739
  NS_TEST_ASSERT_EQUAL (result, true);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   740
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   741
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   742
  // We shouldn't be able to duplicate a name in that context.
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   743
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   744
  Ptr<TestObject> secondClientEth0 = CreateObject<TestObject> ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   745
  result = Names::Add (client, "eth0", secondClientEth0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   746
  NS_TEST_ASSERT_EQUAL (result, false);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   747
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   748
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   749
  // We should be able to add the same name in the second object's context
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   750
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   751
  Ptr<TestObject> serverEth0 = CreateObject<TestObject> ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   752
  result = Names::Add (server, "eth0", serverEth0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   753
  NS_TEST_ASSERT_EQUAL (result, true);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   754
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   755
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   756
  // We should be able to find the short names for the objects we created
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   757
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   758
  std::string found;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   759
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   760
  found = Names::FindShortName (client);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   761
  NS_TEST_ASSERT_EQUAL (found, "Client");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   762
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   763
  found = Names::FindShortName (server);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   764
  NS_TEST_ASSERT_EQUAL (found, "Server");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   765
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   766
  found = Names::FindShortName (clientEth0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   767
  NS_TEST_ASSERT_EQUAL (found, "eth0");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   768
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   769
  found = Names::FindShortName (serverEth0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   770
  NS_TEST_ASSERT_EQUAL (found, "eth0");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   771
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   772
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   773
  // We should be able to find the full names for the objects we created
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   774
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   775
  found = Names::FindFullName (client);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   776
  NS_TEST_ASSERT_EQUAL (found, "/Names/Client");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   777
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   778
  found = Names::FindFullName (server);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   779
  NS_TEST_ASSERT_EQUAL (found, "/Names/Server");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   780
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   781
  found = Names::FindFullName (clientEth0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   782
  NS_TEST_ASSERT_EQUAL (found, "/Names/Client/eth0");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   783
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   784
  found = Names::FindFullName (serverEth0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   785
  NS_TEST_ASSERT_EQUAL (found, "/Names/Server/eth0");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   786
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   787
  // 
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   788
  // We should be able to find the objects from the short names
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   789
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   790
  Ptr<TestObject> foundObject;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   791
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   792
  foundObject = Names::FindObjectFromShortName<TestObject> (0, "Client");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   793
  NS_TEST_ASSERT_EQUAL (foundObject, client);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   794
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   795
  foundObject = Names::FindObjectFromShortName<TestObject> (0, "Server");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   796
  NS_TEST_ASSERT_EQUAL (foundObject, server);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   797
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   798
  foundObject = Names::FindObjectFromShortName<TestObject> (client, "eth0");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   799
  NS_TEST_ASSERT_EQUAL (foundObject, clientEth0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   800
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   801
  foundObject = Names::FindObjectFromShortName<TestObject> (server, "eth0");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   802
  NS_TEST_ASSERT_EQUAL (foundObject, serverEth0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   803
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   804
  // 
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   805
  // We should be able to find the objects from their full names
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   806
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   807
  foundObject = Names::Find<TestObject> ("/Names/Client");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   808
  NS_TEST_ASSERT_EQUAL (foundObject, client);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   809
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   810
  foundObject = Names::Find<TestObject> ("/Names/Server");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   811
  NS_TEST_ASSERT_EQUAL (foundObject, server);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   812
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   813
  foundObject = Names::Find<TestObject> ("/Names/Client/eth0");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   814
  NS_TEST_ASSERT_EQUAL (foundObject, clientEth0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   815
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   816
  foundObject = Names::Find<TestObject> ("/Names/Server/eth0");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   817
  NS_TEST_ASSERT_EQUAL (foundObject, serverEth0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   818
4149
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   819
  // 
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   820
  // We should be able to omit the root of the namespace from the full names
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   821
  //
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   822
  foundObject = Names::Find<TestObject> ("Client");
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   823
  NS_TEST_ASSERT_EQUAL (foundObject, client);
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   824
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   825
  foundObject = Names::Find<TestObject> ("Server");
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   826
  NS_TEST_ASSERT_EQUAL (foundObject, server);
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   827
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   828
  foundObject = Names::Find<TestObject> ("Client/eth0");
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   829
  NS_TEST_ASSERT_EQUAL (foundObject, clientEth0);
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   830
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   831
  foundObject = Names::Find<TestObject> ("Server/eth0");
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   832
  NS_TEST_ASSERT_EQUAL (foundObject, serverEth0);
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   833
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   834
  //
4151
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   835
  // We should be able to add objects while including the root of the namespace
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   836
  // in the name.
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   837
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   838
  Ptr<TestObject> router1 = CreateObject<TestObject> ();
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   839
  result = Names::Add ("/Names/Router1", router1);
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   840
  NS_TEST_ASSERT_EQUAL (result, true);
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   841
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   842
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   843
  // We should be able to add objects while not including the root of the namespace
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   844
  // in the name.
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   845
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   846
  Ptr<TestObject> router2 = CreateObject<TestObject> ();
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   847
  result = Names::Add ("Router2", router2);
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   848
  NS_TEST_ASSERT_EQUAL (result, true);
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   849
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   850
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   851
  // We should be able to add sub-objects while including the root of the namespace
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   852
  // in the name.
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   853
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   854
  Ptr<TestObject> router1Eth0 = CreateObject<TestObject> ();
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   855
  result = Names::Add ("/Names/Router1/eth0", router1Eth0);
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   856
  NS_TEST_ASSERT_EQUAL (result, true);
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   857
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   858
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   859
  // We should be able to add sub-objects while not including the root of the namespace
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   860
  // in the name.
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   861
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   862
  Ptr<TestObject> router2Eth0 = CreateObject<TestObject> ();
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   863
  result = Names::Add ("Router2/eth0", router2Eth0);
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   864
  NS_TEST_ASSERT_EQUAL (result, true);
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   865
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   866
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   867
  // We should be able to find these objects in the same two ways
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   868
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   869
  foundObject = Names::Find<TestObject> ("/Names/Router1");
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   870
  NS_TEST_ASSERT_EQUAL (foundObject, router1);
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   871
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   872
  foundObject = Names::Find<TestObject> ("Router1");
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   873
  NS_TEST_ASSERT_EQUAL (foundObject, router1);
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   874
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   875
  foundObject = Names::Find<TestObject> ("/Names/Router2");
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   876
  NS_TEST_ASSERT_EQUAL (foundObject, router2);
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   877
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   878
  foundObject = Names::Find<TestObject> ("Router2");
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   879
  NS_TEST_ASSERT_EQUAL (foundObject, router2);
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   880
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   881
  foundObject = Names::Find<TestObject> ("/Names/Router1/eth0");
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   882
  NS_TEST_ASSERT_EQUAL (foundObject, router1Eth0);
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   883
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   884
  foundObject = Names::Find<TestObject> ("Router1/eth0");
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   885
  NS_TEST_ASSERT_EQUAL (foundObject, router1Eth0);
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   886
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   887
  foundObject = Names::Find<TestObject> ("/Names/Router2/eth0");
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   888
  NS_TEST_ASSERT_EQUAL (foundObject, router2Eth0);
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   889
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   890
  foundObject = Names::Find<TestObject> ("Router2/eth0");
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   891
  NS_TEST_ASSERT_EQUAL (foundObject, router2Eth0);
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   892
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   893
  //
4141
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   894
  // We also have some syntactically sugary methods, so make sure they do what
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   895
  // they should as well.
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   896
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   897
  Ptr<TestObject> bridge = CreateObject<TestObject> ();
4141
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   898
  result = Names::Add ("/Names", "Bridge", bridge);
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   899
  NS_TEST_ASSERT_EQUAL (result, true);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   900
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   901
  Ptr<TestObject> bridgeEth0 = CreateObject<TestObject> ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   902
  result = Names::Add ("/Names/Bridge", "eth0", bridgeEth0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   903
  NS_TEST_ASSERT_EQUAL (result, true);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   904
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   905
  foundObject = Names::Find<TestObject> ("/Names/Bridge");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   906
  NS_TEST_ASSERT_EQUAL (foundObject, bridge);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   907
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   908
  foundObject = Names::Find<TestObject> ("/Names/Bridge/eth0");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   909
  NS_TEST_ASSERT_EQUAL (foundObject, bridgeEth0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   910
4141
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   911
  Ptr<TestObject> wireless = CreateObject<TestObject> ();
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   912
  result = Names::Add ("/Names/Wireless", wireless);
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   913
  NS_TEST_ASSERT_EQUAL (result, true);
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   914
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   915
  Ptr<TestObject> wirelessAth0 = CreateObject<TestObject> ();
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   916
  result = Names::Add ("/Names/Wireless/ath0", wirelessAth0);
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   917
  NS_TEST_ASSERT_EQUAL (result, true);
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   918
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   919
  foundObject = Names::Find<TestObject> ("/Names/Wireless");
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   920
  NS_TEST_ASSERT_EQUAL (foundObject, wireless);
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   921
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   922
  foundObject = Names::Find<TestObject> ("/Names/Wireless/ath0");
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   923
  NS_TEST_ASSERT_EQUAL (foundObject, wirelessAth0);
3f7f08d9daad make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   924
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   925
  //
4153
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   926
  // We have a pile of names defined.  We should be able to rename them in the
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   927
  // usual ways.
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   928
  //
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   929
  result = Names::Rename ("/Names/Router1", "RouterX");
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   930
  NS_TEST_ASSERT_EQUAL (result, true);
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   931
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   932
  foundObject = Names::Find<TestObject> ("/Names/RouterX");
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   933
  NS_TEST_ASSERT_EQUAL (foundObject, router1);
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   934
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   935
  result = Names::Rename ("Router2", "RouterY");
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   936
  NS_TEST_ASSERT_EQUAL (result, true);
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   937
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   938
  foundObject = Names::Find<TestObject> ("RouterY");
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   939
  NS_TEST_ASSERT_EQUAL (foundObject, router2);
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   940
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   941
  result = Names::Rename ("/Names/RouterX/eth0", "ath0");
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   942
  NS_TEST_ASSERT_EQUAL (result, true);
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   943
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   944
  foundObject = Names::Find<TestObject> ("/Names/RouterX/ath0");
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   945
  NS_TEST_ASSERT_EQUAL (foundObject, router1Eth0);
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   946
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   947
  foundObject = Names::Find<TestObject> ("RouterX/ath0");
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   948
  NS_TEST_ASSERT_EQUAL (foundObject, router1Eth0);
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   949
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   950
  //
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   951
  // We should not be able to rename an object into conflict with another
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   952
  // object.
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   953
  //
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   954
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   955
  result = Names::Rename ("/Names/RouterX", "RouterY");
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   956
  NS_TEST_ASSERT_EQUAL (result, false);
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   957
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   958
  //
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   959
  // Run the simulator and destroy it to get the Destroy method called on the
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   960
  // private implementation object.  We depend on seeing a valgrind-clean run of
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   961
  // the unit tests to really determine if the clean up was really successful.
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   962
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   963
  Simulator::Run ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   964
  Simulator::Destroy ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   965
  
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   966
  return true;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   967
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   968
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   969
static NamesTest g_namesTests;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   970
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   971
} // namespace ns3
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   972
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   973
#endif /* RUN_SELF_TESTS */