src/core/names.cc
author craigdo@ee.washington.edu
Wed, 11 Feb 2009 22:37:00 -0800
changeset 4161 a4747d84fd6a
parent 4159 76a72bc63d06
child 4298 cc2db3e6bcae
permissions -rw-r--r--
endless loops are not a good thing
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);
4159
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
    87
  bool Add (std::string path, std::string name, Ptr<Object> object);
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    88
  bool Add (Ptr<Object> context, std::string name, Ptr<Object> object);
4159
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
    89
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
    90
  bool Rename (std::string oldpath, std::string newname);
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
    91
  bool Rename (std::string path, std::string oldname, std::string newname);
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
    92
  bool Rename (Ptr<Object> context, std::string oldname, std::string newname);
4159
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
    93
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
    94
  std::string FindName (Ptr<Object> object);
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
    95
  std::string FindPath (Ptr<Object> object);
4159
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
    96
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
    97
  Ptr<Object> Find (std::string name);
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
    98
  Ptr<Object> Find (std::string path, std::string name);
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
    99
  Ptr<Object> Find (Ptr<Object> context, std::string name);
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   100
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   101
  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
   102
  static void Delete (void);
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   103
private:
4161
a4747d84fd6a endless loops are not a good thing
craigdo@ee.washington.edu
parents: 4159
diff changeset
   104
  static NamesPriv **DoGet (bool doCreate);
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   105
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   106
  NameNode *IsNamed (Ptr<Object>);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   107
  bool IsDuplicateName (NameNode *node, std::string name);
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
  NameNode m_root;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   110
  std::map<Ptr<Object>, NameNode *> m_objectMap;
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
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   113
NamesPriv *
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   114
NamesPriv::Get (void)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   115
{
4161
a4747d84fd6a endless loops are not a good thing
craigdo@ee.washington.edu
parents: 4159
diff changeset
   116
  return *(DoGet (true));
4139
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
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   119
NamesPriv **
4161
a4747d84fd6a endless loops are not a good thing
craigdo@ee.washington.edu
parents: 4159
diff changeset
   120
NamesPriv::DoGet (bool doCreate)
4139
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
  static NamesPriv *ptr = 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   123
4161
a4747d84fd6a endless loops are not a good thing
craigdo@ee.washington.edu
parents: 4159
diff changeset
   124
  if (ptr == 0 && doCreate)
4139
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
      ptr = new NamesPriv;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   127
      Simulator::ScheduleDestroy (&NamesPriv::Delete);
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
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   130
  return &ptr;
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
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   133
void 
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   134
NamesPriv::Delete (void)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   135
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   136
  NS_LOG_FUNCTION_NOARGS ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   137
4161
a4747d84fd6a endless loops are not a good thing
craigdo@ee.washington.edu
parents: 4159
diff changeset
   138
  NamesPriv **ptr = DoGet (false);
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   139
  delete *ptr;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   140
  *ptr = 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   141
}
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
NamesPriv::NamesPriv ()
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   144
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   145
  NS_LOG_FUNCTION_NOARGS ();
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
  m_root.m_parent = 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   148
  m_root.m_name = "Names";
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   149
  m_root.m_object = 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   150
}
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
NamesPriv::~NamesPriv ()
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   153
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   154
  NS_LOG_FUNCTION_NOARGS ();
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
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   157
  // 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
   158
  // 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
   159
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   160
  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
   161
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   162
      delete i->second;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   163
      i->second = 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   164
    }
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
   165
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
   166
  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
   167
  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
   168
  m_root.m_object = 0;
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   169
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   170
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   171
bool
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   172
NamesPriv::Add (std::string name, Ptr<Object> object)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   173
{
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
   174
  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
   175
  //
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
   176
  // 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
   177
  // 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
   178
  // 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
   179
  // 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
   180
  // 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
   181
  // 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
   182
  //
4151
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   183
  // 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
   184
  // 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
   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
  // If we are given a name that begins with "/Names/" we assume that this is a
4159
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   187
  // fully qualified path name to the object we want to create.  We split the name
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   188
  // into a path string and and a final segment (name) and then call the "Real" Add.
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
  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
   191
  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
   192
  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
   193
    {
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
   194
      //
4151
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   195
      // 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
   196
      // 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
   197
      //
4151
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   198
      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
   199
      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
   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
          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
   202
          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
   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
      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
   206
    }
4151
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   207
  
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   208
  //
4159
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   209
  // There must now be a fully qualified path in the string.  All fully 
4151
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   210
  // qualified names begin with "/Names".  We have to split off the final 
4159
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   211
  // segment which will become the name of the object.  A '/' that
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   212
  // separates the path from the final segment had better be there since
4151
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   213
  // 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
   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
  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
   216
  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
   217
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
  // The slash we found cannot be the slash at the start of the namespaceName.
4159
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   220
  // This would indicate there is no name in the path at all.  It can be
4151
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   221
  // 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
   222
  //
4159
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   223
  NS_ASSERT_MSG (i != 0, "NamesPriv::Add(): Can't find a name in the path string");
4151
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   224
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   225
  //
4159
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   226
  // We now know where the path string starts and ends, and where the
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   227
  // name starts and ends.  All we have to do is to call our available
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   228
  // function for adding a name under a path string.
4151
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   229
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   230
  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
   231
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   232
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   233
bool
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   234
NamesPriv::Add (std::string path, std::string name, Ptr<Object> object)
4148
7f1a5bd869e5 move a function definition in names.cc for a little more clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4147
diff changeset
   235
{
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   236
  if (path == "/Names")
4148
7f1a5bd869e5 move a function definition in names.cc for a little more clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4147
diff changeset
   237
    {
7f1a5bd869e5 move a function definition in names.cc for a little more clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4147
diff changeset
   238
      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
   239
    }
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   240
  return Add (Find (path), name, object);
4148
7f1a5bd869e5 move a function definition in names.cc for a little more clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4147
diff changeset
   241
}
7f1a5bd869e5 move a function definition in names.cc for a little more clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4147
diff changeset
   242
7f1a5bd869e5 move a function definition in names.cc for a little more clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4147
diff changeset
   243
bool
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   244
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
   245
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   246
  NS_LOG_FUNCTION (context << name << object);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   247
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   248
  if (IsNamed (object))
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   249
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   250
      NS_LOG_LOGIC ("Object is already named");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   251
      return false;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   252
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   253
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   254
  NameNode *node = 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   255
  if (context)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   256
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   257
      node = IsNamed (context);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   258
      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
   259
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   260
  else
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   261
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   262
      node = &m_root;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   263
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   264
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   265
  if (IsDuplicateName (node, name))
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   266
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   267
      NS_LOG_LOGIC ("Name is already taken");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   268
      return false;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   269
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   270
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   271
  NameNode *newNode = new NameNode(node, name, object);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   272
  node->m_nameMap[name] = newNode;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   273
  m_objectMap[object] = newNode;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   274
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   275
  return true;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   276
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   277
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
   278
bool
4159
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   279
NamesPriv::Rename (std::string oldpath, std::string newname)
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   280
{
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   281
  NS_LOG_FUNCTION (oldpath << newname);
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   282
  //
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   283
  // This is the simple, easy to use version of Rename, so we want it to be 
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   284
  // flexible.   We don't want to force a user to always type the fully 
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   285
  // qualified namespace name, so we allow the namespace name to be omitted.
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   286
  // For example, calling Rename ("Client/ath0", "eth0") should result in 
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   287
  // exactly the same behavior as Rename ("/Names/Client/ath0", "eth0").
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   288
  // Calling Rename ("Client", "Router") should have the same effect as 
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   289
  // Rename ("Names/Client", "Router")
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   290
  //
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   291
  // The first thing to do, then, is to "canonicalize" the input string to always
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   292
  // be a fully qualified path.
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   293
  //
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   294
  // If we are given a name that begins with "/Names/" we assume that this is a
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   295
  // fully qualified path to the object we want to change.  We split the path into 
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   296
  // path string (cf directory) and and a final segment (cf filename) and then call
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   297
  // the "Real" Rename.
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   298
  //
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   299
  std::string namespaceName = "/Names";
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   300
  std::string::size_type offset = oldpath.find (namespaceName);
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   301
  if (offset != 0)
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   302
    {
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   303
      //
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   304
      // This must be a name that has the "/Names" namespace prefix omitted.  
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   305
      // Do some reasonableness checking on the rest of the name.
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   306
      //
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   307
      offset = oldpath.find ("/");
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   308
      if (offset == 0)
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   309
        {
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   310
          NS_ASSERT_MSG (false, "NamesPriv::Add(): Name begins with '/' but not \"/Names\"");
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   311
          return false;
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   312
        }
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   313
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   314
      oldpath = "/Names/" + oldpath;
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   315
    }
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   316
  
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   317
  //
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   318
  // There must now be a fully qualified path in the oldpath string.  All 
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   319
  // fully qualified names begin with "/Names".  We have to split off the final 
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   320
  // segment which will become the name we want to rename.  A '/' that
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   321
  // separates the path from the final segment (name) had better be there since
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   322
  // we just made sure that at least the namespace name was there.
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   323
  //
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   324
  std::string::size_type i = oldpath.rfind ("/");
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   325
  NS_ASSERT_MSG (i != std::string::npos, "NamesPriv::Add(): Internal error.  Can't find '/' in name");
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   326
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   327
  //
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   328
  // The slash we found cannot be the slash at the start of the namespaceName.
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   329
  // This would indicate there is no name in the path at all.  It can be
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   330
  // any other index.
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   331
  //
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   332
  NS_ASSERT_MSG (i != 0, "NamesPriv::Add(): Can't find a name in the path string");
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   333
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   334
  //
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   335
  // We now know where the path part of the string starts and ends, and where the
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   336
  // name part starts and ends.  All we have to do is to call our available
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   337
  // function for creating adding a name under a path string.
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   338
  //
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   339
  return Rename (oldpath.substr (0, i), oldpath.substr (i + 1), newname);
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   340
}
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   341
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   342
bool
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   343
NamesPriv::Rename (std::string path, std::string oldname, std::string newname)
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   344
{
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   345
  if (path == "/Names")
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   346
    {
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   347
      return Rename (Ptr<Object> (0, false), oldname, newname);
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   348
    }
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   349
  return Rename (Find (path), oldname, newname);
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   350
}
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   351
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   352
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
   353
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
   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
  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
   356
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
  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
   358
  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
   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 = 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
   361
      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
   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
  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
   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
      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
   366
    }
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
  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
   369
    {
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
      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
   371
      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
   372
    }
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
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
  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
   375
  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
   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 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
   378
      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
   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
  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
   381
    {
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
      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
   383
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
      //
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
      // 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
   386
      // 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
   387
      // 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
   388
      // 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
   389
      // 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
   390
      //
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
      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
   392
      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
   393
      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
   394
      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
   395
      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
   396
    }
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   397
}
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   398
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   399
std::string
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   400
NamesPriv::FindName (Ptr<Object> object)
4139
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_FUNCTION (object);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   403
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   404
  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
   405
  if (i == m_objectMap.end ())
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 does not exist in object map");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   408
      return "";
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
  else
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
      NS_LOG_LOGIC ("Object exists in object map");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   413
      return i->second->m_name;
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
}
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::string
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   418
NamesPriv::FindPath (Ptr<Object> object)
4139
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_FUNCTION (object);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   421
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   422
  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
   423
  if (i == m_objectMap.end ())
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   424
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   425
      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
   426
      return "";
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   427
    }
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
  NameNode *p = i->second;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   430
  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
   431
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   432
  std::string path;
4139
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
  do
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   435
    {
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   436
      path = "/" + p->m_name + path;
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   437
      NS_LOG_LOGIC ("path is " << path);
4139
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
  while ((p = p->m_parent) != 0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   440
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   441
  return path;
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   442
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   443
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   444
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   445
Ptr<Object>
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   446
NamesPriv::Find (std::string path)
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   447
{
4149
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   448
  //
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   449
  // 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
   450
  // to be flexible.
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   451
  //
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   452
  // If we are provided a path that doesn't begin with "/Names", we assume 
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   453
  // that the caller has simply given us a path starting with a name that
4149
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   454
  // 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
   455
  // 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
   456
  // Find ("/Names/Client/eth0");
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   457
  //
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   458
  // 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
   459
  // just remove that prefix and treat the rest of the string as starting with a 
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   460
  // name in the root namespace.
4149
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   461
  //
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   462
  std::string namespaceName = "/Names/";
4149
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   463
  std::string remaining;
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   464
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   465
  std::string::size_type offset = path.find (namespaceName);
4149
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   466
  if (offset == 0)
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   467
    {
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   468
      NS_LOG_LOGIC (path << " is a fully qualified name");
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   469
      remaining = path.substr (namespaceName.size ());
4149
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   470
    }
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   471
  else
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   472
    {
4159
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   473
      NS_LOG_LOGIC (path << " begins with a relative name");
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   474
      remaining = path;
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   475
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   476
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   477
  NameNode *node = &m_root;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   478
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   479
  //
4149
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   480
  // 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
   481
  // /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
   482
  // remaining = "ClientNode/eth0"
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   483
  //
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   484
  // 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
   485
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   486
  for (;;)
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
      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
   489
      offset = remaining.find ("/");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   490
      if (offset == std::string::npos)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   491
        {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   492
          //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   493
          // 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
   494
          // specified name.  We're done when we find it
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   495
          //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   496
          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
   497
          if (i == node->m_nameMap.end ())
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 does not exist in name map");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   500
              return 0;
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
          else
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   503
            {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   504
              NS_LOG_LOGIC ("Name parsed, found object");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   505
              return i->second->m_object;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   506
            }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   507
        }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   508
      else
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   509
        {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   510
          //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   511
          // 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
   512
          // 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
   513
          //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   514
          offset = remaining.find ("/");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   515
          std::string segment = remaining.substr(0, offset);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   516
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   517
          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
   518
          if (i == node->m_nameMap.end ())
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
              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
   521
              return 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   522
            }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   523
          else
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
              node = i->second;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   526
              remaining = remaining.substr (offset + 1);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   527
              NS_LOG_LOGIC ("Intermediate segment parsed");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   528
              continue;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   529
            }
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
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   533
  NS_ASSERT_MSG (node, "NamesPriv::Find(): Internal error:  this can't happen");
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   534
  return 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   535
}
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
Ptr<Object>
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   538
NamesPriv::Find (std::string path, std::string name)
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   539
{
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   540
  NS_LOG_FUNCTION (path << name);
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   541
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   542
  if (path == "/Names")
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   543
    {
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   544
      return Find (Ptr<Object> (0, false), name);
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   545
    }
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   546
  return Find (Find (path), name);
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   547
}
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   548
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   549
Ptr<Object>
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   550
NamesPriv::Find (Ptr<Object> context, std::string name)
4139
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
  NS_LOG_FUNCTION (context << name);
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
  NameNode *node = 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   555
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   556
  if (context == 0)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   557
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   558
      NS_LOG_LOGIC ("Zero context implies root NameNode");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   559
      node = &m_root;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   560
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   561
  else
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   562
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   563
      node = IsNamed (context);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   564
      if (node == 0)
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
          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
   567
          return 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   568
        }
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
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   571
  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
   572
  if (i == node->m_nameMap.end ())
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   573
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   574
      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
   575
      return 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   576
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   577
  else
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   578
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   579
      NS_LOG_LOGIC ("Name exists in name map");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   580
      return i->second->m_object;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   581
    }
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
NameNode *
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   585
NamesPriv::IsNamed (Ptr<Object> object)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   586
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   587
  NS_LOG_FUNCTION (object);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   588
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   589
  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
   590
  if (i == m_objectMap.end ())
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   591
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   592
      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
   593
      return 0;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   594
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   595
  else
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   596
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   597
      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
   598
      return i->second;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   599
    }
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
bool
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   603
NamesPriv::IsDuplicateName (NameNode *node, std::string name)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   604
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   605
  NS_LOG_FUNCTION (node << name);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   606
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   607
  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
   608
  if (i == node->m_nameMap.end ())
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   609
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   610
      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
   611
      return false;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   612
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   613
  else
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
      NS_LOG_LOGIC ("Name exists in name map");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   616
      return true;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   617
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   618
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   619
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
   620
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
   621
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
   622
{
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
   623
  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
   624
}
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
   625
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   626
bool
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   627
Names::Add (std::string name, Ptr<Object> object)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   628
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   629
  return NamesPriv::Get ()->Add (name, object);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   630
}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   631
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   632
bool
4159
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   633
Names::Rename (std::string oldpath, std::string newname)
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
   634
{
4159
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   635
  return NamesPriv::Get ()->Rename (oldpath, newname);
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
   636
}
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   637
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   638
bool
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   639
Names::Add (std::string path, std::string name, Ptr<Object> object)
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   640
{
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   641
  return NamesPriv::Get ()->Add (path, name, object);
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   642
}
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   643
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   644
bool
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   645
Names::Rename (std::string path, std::string oldname, std::string newname)
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   646
{
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   647
  return NamesPriv::Get ()->Rename (path, oldname, newname);
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   648
}
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   649
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   650
bool
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   651
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
   652
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   653
  return NamesPriv::Get ()->Add (context, name, object);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   654
}
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
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
   657
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
   658
{
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   659
  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
   660
}
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   661
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   662
std::string
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   663
Names::FindName (Ptr<Object> object)
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   664
{
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   665
  return NamesPriv::Get ()->FindName (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
   666
}
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   667
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   668
std::string
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   669
Names::FindPath (Ptr<Object> object)
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   670
{
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   671
  return NamesPriv::Get ()->FindPath (object);
4139
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
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   674
Ptr<Object>
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   675
Names::FindInternal (std::string name)
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   676
{
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   677
  return NamesPriv::Get ()->Find (name);
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   678
}
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
Ptr<Object>
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   681
Names::FindInternal (std::string path, std::string name)
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   682
{
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   683
  return NamesPriv::Get ()->Find (path, name);
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   684
}
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   685
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   686
Ptr<Object>
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   687
Names::FindInternal (Ptr<Object> context, std::string name)
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   688
{
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   689
  return NamesPriv::Get ()->Find (context, name);
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   690
}
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
} //namespace ns3
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   693
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   694
#ifdef RUN_SELF_TESTS
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   695
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   696
#include "test.h"
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   697
#include "object-factory.h"
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
namespace ns3 {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   700
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   701
class TestObject : public Object
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
public:
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   704
  static TypeId GetTypeId (void) 
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   705
  {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   706
    static TypeId tid = TypeId ("TestObject")
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   707
      .SetParent (Object::GetTypeId ())
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   708
      .HideFromDocumentation ()
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   709
      .AddConstructor<TestObject> ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   710
    return tid;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   711
  }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   712
  TestObject () {}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   713
  virtual void Dispose (void) {}
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   714
};
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   715
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   716
class NamesTest : public Test
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   717
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   718
public:
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   719
  NamesTest ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   720
  virtual bool RunTests (void);
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
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   723
NamesTest::NamesTest ()
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   724
  : Test ("Names")
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   725
{
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
bool 
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   729
NamesTest::RunTests (void)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   730
{
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   731
  bool result = true;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   732
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
  // Name a couple of objects at the root level
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   735
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   736
  Ptr<TestObject> client = CreateObject<TestObject> ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   737
  result = Names::Add ("Client", client);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   738
  NS_TEST_ASSERT_EQUAL (result, true);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   739
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   740
  Ptr<TestObject> server = CreateObject<TestObject> ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   741
  result = Names::Add ("Server", server);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   742
  NS_TEST_ASSERT_EQUAL (result, true);
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
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   745
  // 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
   746
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   747
  result = Names::Add ("Not Client", client);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   748
  NS_TEST_ASSERT_EQUAL (result, false);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   749
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
  // 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
   752
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   753
  Ptr<TestObject> secondClient = CreateObject<TestObject> ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   754
  result = Names::Add ("Client", secondClient);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   755
  NS_TEST_ASSERT_EQUAL (result, false);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   756
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
  // 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
   759
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   760
  Ptr<TestObject> clientEth0 = CreateObject<TestObject> ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   761
  result = Names::Add (client, "eth0", clientEth0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   762
  NS_TEST_ASSERT_EQUAL (result, true);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   763
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   764
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   765
  // 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
   766
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   767
  Ptr<TestObject> secondClientEth0 = CreateObject<TestObject> ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   768
  result = Names::Add (client, "eth0", secondClientEth0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   769
  NS_TEST_ASSERT_EQUAL (result, false);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   770
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
  // 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
   773
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   774
  Ptr<TestObject> serverEth0 = CreateObject<TestObject> ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   775
  result = Names::Add (server, "eth0", serverEth0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   776
  NS_TEST_ASSERT_EQUAL (result, true);
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
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   779
  // 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
   780
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   781
  std::string found;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   782
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   783
  found = Names::FindName (client);
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   784
  NS_TEST_ASSERT_EQUAL (found, "Client");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   785
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   786
  found = Names::FindName (server);
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   787
  NS_TEST_ASSERT_EQUAL (found, "Server");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   788
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   789
  found = Names::FindName (clientEth0);
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   790
  NS_TEST_ASSERT_EQUAL (found, "eth0");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   791
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   792
  found = Names::FindName (serverEth0);
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   793
  NS_TEST_ASSERT_EQUAL (found, "eth0");
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
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   796
  // 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
   797
  //
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   798
  found = Names::FindPath (client);
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   799
  NS_TEST_ASSERT_EQUAL (found, "/Names/Client");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   800
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   801
  found = Names::FindPath (server);
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   802
  NS_TEST_ASSERT_EQUAL (found, "/Names/Server");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   803
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   804
  found = Names::FindPath (clientEth0);
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   805
  NS_TEST_ASSERT_EQUAL (found, "/Names/Client/eth0");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   806
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   807
  found = Names::FindPath (serverEth0);
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   808
  NS_TEST_ASSERT_EQUAL (found, "/Names/Server/eth0");
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
  // 
4159
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   811
  // We should be able to find the objects from a context and name combination.
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   812
  // Note that the Ptr<Object> (0, false) below is to differentiate a null object
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   813
  // pointer from a null string pointer -- not normally needed in real use-cases.
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   814
  // 
4139
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
  Ptr<TestObject> foundObject;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   817
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   818
  foundObject = Names::Find<TestObject> (Ptr<Object> (0, false), "Client");
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   819
  NS_TEST_ASSERT_EQUAL (foundObject, client);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   820
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   821
  foundObject = Names::Find<TestObject> (Ptr<Object> (0, false), "Server");
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   822
  NS_TEST_ASSERT_EQUAL (foundObject, server);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   823
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   824
  foundObject = Names::Find<TestObject> (client, "eth0");
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   825
  NS_TEST_ASSERT_EQUAL (foundObject, clientEth0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   826
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   827
  foundObject = Names::Find<TestObject> (server, "eth0");
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   828
  NS_TEST_ASSERT_EQUAL (foundObject, serverEth0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   829
4159
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   830
  //
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   831
  // We should be able to do the same thing by providing path strings instead
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   832
  // of context objects.
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   833
  //
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   834
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   835
  foundObject = Names::Find<TestObject> ("/Names", "Client");
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   836
  NS_TEST_ASSERT_EQUAL (foundObject, client);
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   837
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   838
  foundObject = Names::Find<TestObject> ("/Names", "Server");
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   839
  NS_TEST_ASSERT_EQUAL (foundObject, server);
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   840
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   841
  foundObject = Names::Find<TestObject> ("/Names/Client", "eth0");
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   842
  NS_TEST_ASSERT_EQUAL (foundObject, clientEth0);
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   843
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   844
  foundObject = Names::Find<TestObject> ("/Names/Server", "eth0");
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   845
  NS_TEST_ASSERT_EQUAL (foundObject, serverEth0);
76a72bc63d06 a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   846
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   847
  // 
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   848
  // We should be able to find the objects from their full path names
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   849
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   850
  foundObject = Names::Find<TestObject> ("/Names/Client");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   851
  NS_TEST_ASSERT_EQUAL (foundObject, client);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   852
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   853
  foundObject = Names::Find<TestObject> ("/Names/Server");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   854
  NS_TEST_ASSERT_EQUAL (foundObject, server);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   855
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   856
  foundObject = Names::Find<TestObject> ("/Names/Client/eth0");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   857
  NS_TEST_ASSERT_EQUAL (foundObject, clientEth0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   858
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   859
  foundObject = Names::Find<TestObject> ("/Names/Server/eth0");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   860
  NS_TEST_ASSERT_EQUAL (foundObject, serverEth0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   861
4149
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   862
  // 
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4153
diff changeset
   863
  // We should be able to omit the root of the namespace from the full path names
4149
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   864
  //
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   865
  foundObject = Names::Find<TestObject> ("Client");
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   866
  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
   867
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   868
  foundObject = Names::Find<TestObject> ("Server");
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   869
  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
   870
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   871
  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
   872
  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
   873
6a3dbc49cfa9 Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents: 4148
diff changeset
   874
  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
   875
  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
   876
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   877
  //
4151
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   878
  // 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
   879
  // 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
   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
  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
   882
  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
   883
  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
   884
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   885
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   886
  // 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
   887
  // 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
   888
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   889
  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
   890
  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
   891
  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
   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
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   894
  // 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
   895
  // 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
   896
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   897
  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
   898
  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
   899
  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
   900
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   901
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   902
  // 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
   903
  // 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
   904
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   905
  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
   906
  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
   907
  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
   908
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   909
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   910
  // 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
   911
  //
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   912
  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
   913
  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
   914
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   915
  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
   916
  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
   917
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   918
  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
   919
  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
   920
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   921
  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
   922
  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
   923
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   924
  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
   925
  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
   926
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   927
  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
   928
  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
   929
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   930
  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
   931
  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
   932
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   933
  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
   934
  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
   935
682a4cae7a5f Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents: 4149
diff changeset
   936
  //
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
   937
  // 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
   938
  // 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
   939
  //
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
  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
   941
  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
   942
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
  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
   944
  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
   945
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
  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
   947
  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
   948
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
  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
   950
  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
   951
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
  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
   953
  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
   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
  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
   956
  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
   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
  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
   959
  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
   960
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   961
  //
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   962
  // 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
   963
  // 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
   964
  //
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   965
93bb91eae5cd add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents: 4151
diff changeset
   966
  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
   967
  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
   968
4161
a4747d84fd6a endless loops are not a good thing
craigdo@ee.washington.edu
parents: 4159
diff changeset
   969
  Names::Delete ();
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   970
  return true;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   971
}
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
static NamesTest g_namesTests;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   974
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   975
} // namespace ns3
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   976
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   977
#endif /* RUN_SELF_TESTS */