src/node/node.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 01 Oct 2007 14:15:56 +0200
changeset 1866 e7dbcc4df546
parent 1412 9ce52d4f530b
child 2182 13c8ebd1a19e
permissions -rw-r--r--
do not use Packet objects directly. Use Ptr<Packet> instead
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1176
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
     2
/*
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
     3
 * Copyright (c) 2006 Georgia Tech Research Corporation, INRIA
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
     4
 *
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
     7
 * published by the Free Software Foundation;
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
     8
 *
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
    12
 * GNU General Public License for more details.
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
    13
 *
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
    14
 * You should have received a copy of the GNU General Public License
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
    15
 * along with this program; if not, write to the Free Software
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
    17
 *
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
    18
 * Authors: George F. Riley<riley@ece.gatech.edu>
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
    19
 *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
    20
 */
729
b5e744285e92 rename i-node to node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
    21
#include "node.h"
358
cefde4f0d6b2 Add nodes to NodeList in static Create method; cut over simple-serial.cc to use this node factory
Tom Henderson <tomh@tomh.org>
parents: 355
diff changeset
    22
#include "node-list.h"
467
319ffa6c5e0a dispose properly from Node::Dispose
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 465
diff changeset
    23
#include "net-device.h"
585
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
    24
#include "application.h"
1186
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1176
diff changeset
    25
#include "packet-socket-factory.h"
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1412
diff changeset
    26
#include "ns3/packet.h"
475
aeadea0cdc82 destroy the Node vector upon Simulator::Destroy rather than wait until the global static destructor of Node::g_nodes is invoked. This fixes a bad assert caught with valgrind.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 474
diff changeset
    27
#include "ns3/simulator.h"
1194
b8e957eb0a94 replace Node::DoCreateTraceResolver with Node::DoFillTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    28
#include "ns3/composite-trace-resolver.h"
232
8cd08910f9a1 initial node base class from george's repo.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
8cd08910f9a1 initial node base class from george's repo.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
namespace ns3{
8cd08910f9a1 initial node base class from george's repo.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
728
95c426b1cb60 rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 710
diff changeset
    32
const InterfaceId Node::iid = MakeInterfaceId ("Node", Object::iid);
512
5404e1e41f82 make Node derive from NsUnknown rather than Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 484
diff changeset
    33
1229
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    34
NodeNetDeviceIndex::NodeNetDeviceIndex ()
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    35
  : m_index (0)
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    36
{}
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    37
NodeNetDeviceIndex::NodeNetDeviceIndex (uint32_t index)
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    38
  : m_index (index)
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    39
{}
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    40
uint32_t 
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    41
NodeNetDeviceIndex::Get (void) const
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    42
{
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    43
  return m_index;
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    44
}
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    45
void 
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    46
NodeNetDeviceIndex::Print (std::ostream &os) const
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    47
{
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    48
  os << "device=" << m_index;
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    49
}
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    50
uint16_t 
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    51
NodeNetDeviceIndex::GetUid (void)
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    52
{
1235
dc52ea3507ff TraceContextElement::Register -> TraceContextElement::AllocateUid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1229
diff changeset
    53
  static uint16_t uid = AllocateUid<NodeNetDeviceIndex> ("NodeNetDeviceIndex");
1229
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    54
  return uid;
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    55
}
1364
7866d4dd9e64 add TraceContextElement::GetName method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1341
diff changeset
    56
std::string 
1401
96a21130865c GetName -> GetTypeName
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1386
diff changeset
    57
NodeNetDeviceIndex::GetTypeName (void) const
1364
7866d4dd9e64 add TraceContextElement::GetName method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1341
diff changeset
    58
{
1401
96a21130865c GetName -> GetTypeName
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1386
diff changeset
    59
  return "ns3::NodeNetDeviceIndex";
1364
7866d4dd9e64 add TraceContextElement::GetName method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1341
diff changeset
    60
}
1229
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    61
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    62
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    63
728
95c426b1cb60 rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 710
diff changeset
    64
Node::Node()
710
2a9c061219a7 port code from Interface to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 607
diff changeset
    65
  : m_id(0), 
484
cf7fbb84d74b rework the Node and NodeList classes to manage reference counts correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 482
diff changeset
    66
    m_sid(0)
244
caff04d90a66 remove SetNodeId and implement GetId and GetSystemId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
    67
{
1186
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1176
diff changeset
    68
  Construct ();
355
d18da75542c7 Add static node factory methods to class Node
Tom Henderson <tomh@tomh.org>
parents: 244
diff changeset
    69
}
d18da75542c7 Add static node factory methods to class Node
Tom Henderson <tomh@tomh.org>
parents: 244
diff changeset
    70
728
95c426b1cb60 rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 710
diff changeset
    71
Node::Node(uint32_t sid)
710
2a9c061219a7 port code from Interface to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 607
diff changeset
    72
  : m_id(0), 
484
cf7fbb84d74b rework the Node and NodeList classes to manage reference counts correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 482
diff changeset
    73
    m_sid(sid)
355
d18da75542c7 Add static node factory methods to class Node
Tom Henderson <tomh@tomh.org>
parents: 244
diff changeset
    74
{ 
1186
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1176
diff changeset
    75
  Construct ();
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1176
diff changeset
    76
}
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1176
diff changeset
    77
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1176
diff changeset
    78
void
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1176
diff changeset
    79
Node::Construct (void)
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1176
diff changeset
    80
{
728
95c426b1cb60 rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 710
diff changeset
    81
  SetInterfaceId (Node::iid);
484
cf7fbb84d74b rework the Node and NodeList classes to manage reference counts correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 482
diff changeset
    82
  m_id = NodeList::Add (this);
1186
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1176
diff changeset
    83
  Ptr<PacketSocketFactory> socketFactory = Create<PacketSocketFactory> ();
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1176
diff changeset
    84
  AddInterface (socketFactory);
244
caff04d90a66 remove SetNodeId and implement GetId and GetSystemId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
    85
}
232
8cd08910f9a1 initial node base class from george's repo.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    86
  
728
95c426b1cb60 rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 710
diff changeset
    87
Node::~Node ()
232
8cd08910f9a1 initial node base class from george's repo.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    88
{}
8cd08910f9a1 initial node base class from george's repo.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    89
1333
c0d66de933e9 convert TraceResolver * to Ptr<TraceResolver>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    90
Ptr<TraceResolver>
1383
12f30b7defb4 constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1364
diff changeset
    91
Node::GetTraceResolver (void) const
594
bf1c6a6ab58d make the Node API more consistent
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 585
diff changeset
    92
{
1333
c0d66de933e9 convert TraceResolver * to Ptr<TraceResolver>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
    93
  Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> ();
1341
f685d4bf320f use the Object::GetTraceResolver tracing support rather than the old adhoc tracing code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1333
diff changeset
    94
  resolver->AddArray ("devices", m_devices.begin (), m_devices.end (), NodeNetDeviceIndex ());
1386
f2ee41c3e788 avoid method naming ambiguity in CompositeTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1383
diff changeset
    95
  resolver->SetParentResolver (Object::GetTraceResolver ());
1194
b8e957eb0a94 replace Node::DoCreateTraceResolver with Node::DoFillTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    96
  return resolver;
594
bf1c6a6ab58d make the Node API more consistent
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 585
diff changeset
    97
}
bf1c6a6ab58d make the Node API more consistent
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 585
diff changeset
    98
244
caff04d90a66 remove SetNodeId and implement GetId and GetSystemId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
    99
uint32_t 
728
95c426b1cb60 rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 710
diff changeset
   100
Node::GetId (void) const
244
caff04d90a66 remove SetNodeId and implement GetId and GetSystemId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   101
{
caff04d90a66 remove SetNodeId and implement GetId and GetSystemId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   102
  return m_id;
caff04d90a66 remove SetNodeId and implement GetId and GetSystemId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   103
}
359
91b7ad7fa784 OnOffApplication functioning; some Node class cleanup
Tom Henderson <tomh@tomh.org>
parents: 358
diff changeset
   104
244
caff04d90a66 remove SetNodeId and implement GetId and GetSystemId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   105
uint32_t 
728
95c426b1cb60 rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 710
diff changeset
   106
Node::GetSystemId (void) const
244
caff04d90a66 remove SetNodeId and implement GetId and GetSystemId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   107
{
caff04d90a66 remove SetNodeId and implement GetId and GetSystemId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   108
  return m_sid;
caff04d90a66 remove SetNodeId and implement GetId and GetSystemId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   109
}
232
8cd08910f9a1 initial node base class from george's repo.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   110
447
180117abfb04 add NetDevice list into Node base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 381
diff changeset
   111
uint32_t 
728
95c426b1cb60 rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 710
diff changeset
   112
Node::AddDevice (Ptr<NetDevice> device)
447
180117abfb04 add NetDevice list into Node base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 381
diff changeset
   113
{
1195
53f1175dbe94 fix tracing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1194
diff changeset
   114
  uint32_t index = m_devices.size ();
1186
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1176
diff changeset
   115
  m_devices.push_back (device);
535
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 525
diff changeset
   116
  device->SetIfIndex(index);
1176
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   117
  device->SetReceiveCallback (MakeCallback (&Node::ReceiveFromDevice, this));
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   118
  NotifyDeviceAdded (device);
447
180117abfb04 add NetDevice list into Node base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 381
diff changeset
   119
  return index;
180117abfb04 add NetDevice list into Node base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 381
diff changeset
   120
}
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 535
diff changeset
   121
Ptr<NetDevice>
728
95c426b1cb60 rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 710
diff changeset
   122
Node::GetDevice (uint32_t index) const
447
180117abfb04 add NetDevice list into Node base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 381
diff changeset
   123
{
1195
53f1175dbe94 fix tracing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1194
diff changeset
   124
  return m_devices[index];
447
180117abfb04 add NetDevice list into Node base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 381
diff changeset
   125
}
180117abfb04 add NetDevice list into Node base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 381
diff changeset
   126
uint32_t 
728
95c426b1cb60 rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 710
diff changeset
   127
Node::GetNDevices (void) const
447
180117abfb04 add NetDevice list into Node base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 381
diff changeset
   128
{
180117abfb04 add NetDevice list into Node base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 381
diff changeset
   129
  return m_devices.size ();
180117abfb04 add NetDevice list into Node base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 381
diff changeset
   130
}
180117abfb04 add NetDevice list into Node base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 381
diff changeset
   131
585
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
   132
uint32_t 
728
95c426b1cb60 rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 710
diff changeset
   133
Node::AddApplication (Ptr<Application> application)
585
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
   134
{
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
   135
  uint32_t index = m_applications.size ();
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
   136
  m_applications.push_back (application);
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
   137
  return index;
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
   138
}
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
   139
Ptr<Application> 
728
95c426b1cb60 rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 710
diff changeset
   140
Node::GetApplication (uint32_t index) const
585
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
   141
{
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
   142
  return m_applications[index];
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
   143
}
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
   144
uint32_t 
728
95c426b1cb60 rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 710
diff changeset
   145
Node::GetNApplications (void) const
585
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
   146
{
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
   147
  return m_applications.size ();
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
   148
}
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
   149
1194
b8e957eb0a94 replace Node::DoCreateTraceResolver with Node::DoFillTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   150
void 
b8e957eb0a94 replace Node::DoCreateTraceResolver with Node::DoFillTraceResolver
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   151
Node::DoDispose()
465
7f620ea278f4 merge in raj's dispose early work
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 448
diff changeset
   152
{
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 535
diff changeset
   153
  for (std::vector<Ptr<NetDevice> >::iterator i = m_devices.begin ();
467
319ffa6c5e0a dispose properly from Node::Dispose
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 465
diff changeset
   154
       i != m_devices.end (); i++)
319ffa6c5e0a dispose properly from Node::Dispose
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 465
diff changeset
   155
    {
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 535
diff changeset
   156
      Ptr<NetDevice> device = *i;
467
319ffa6c5e0a dispose properly from Node::Dispose
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 465
diff changeset
   157
      device->Dispose ();
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 535
diff changeset
   158
      *i = 0;
467
319ffa6c5e0a dispose properly from Node::Dispose
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 465
diff changeset
   159
    }
515
e907146a191e fix valgrind warning: UdpSocket must manage carefully its Ipv4EndPoint to avoid double deleting it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 514
diff changeset
   160
  m_devices.clear ();
585
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
   161
  for (std::vector<Ptr<Application> >::iterator i = m_applications.begin ();
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
   162
       i != m_applications.end (); i++)
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
   163
    {
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
   164
      Ptr<Application> application = *i;
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
   165
      application->Dispose ();
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
   166
      *i = 0;
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
   167
    }
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 580
diff changeset
   168
  m_applications.clear ();
710
2a9c061219a7 port code from Interface to Object
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 607
diff changeset
   169
  Object::DoDispose ();
465
7f620ea278f4 merge in raj's dispose early work
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 448
diff changeset
   170
}
7f620ea278f4 merge in raj's dispose early work
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 448
diff changeset
   171
1176
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   172
void 
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   173
Node::NotifyDeviceAdded (Ptr<NetDevice> device)
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   174
{}
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   175
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   176
void
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   177
Node::RegisterProtocolHandler (ProtocolHandler handler, 
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   178
                               uint16_t protocolType,
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   179
                               Ptr<NetDevice> device)
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   180
{
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   181
  struct Node::ProtocolHandlerEntry entry;
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   182
  entry.handler = handler;
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   183
  entry.protocol = protocolType;
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   184
  entry.device = device;
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   185
  m_handlers.push_back (entry);
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   186
}
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   187
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   188
void
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   189
Node::UnregisterProtocolHandler (ProtocolHandler handler)
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   190
{
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   191
  for (ProtocolHandlerList::iterator i = m_handlers.begin ();
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   192
       i != m_handlers.end (); i++)
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   193
    {
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   194
      if (i->handler.IsEqual (handler))
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   195
        {
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   196
          m_handlers.erase (i);
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   197
          break;
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   198
        }
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   199
    }
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   200
}
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   201
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   202
bool
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1412
diff changeset
   203
Node::ReceiveFromDevice (Ptr<NetDevice> device, Ptr<Packet> packet, 
1186
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1176
diff changeset
   204
                         uint16_t protocol, const Address &from)
1176
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   205
{
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   206
  bool found = false;
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   207
  for (ProtocolHandlerList::iterator i = m_handlers.begin ();
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   208
       i != m_handlers.end (); i++)
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   209
    {
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   210
      if (i->device == 0 ||
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   211
          (i->device != 0 && i->device == device))
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   212
        {
1186
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1176
diff changeset
   213
          if (i->protocol == 0 || 
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1176
diff changeset
   214
              i->protocol == protocol)
1176
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   215
            {
1186
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1176
diff changeset
   216
              i->handler (device, packet, protocol, from);
1176
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   217
              found = true;
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   218
            }
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   219
        }
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   220
    }
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   221
  return found;
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   222
}
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
   223
232
8cd08910f9a1 initial node base class from george's repo.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   224
}//namespace ns3