A Discrete-Event Network Simulator
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2006 Georgia Tech Research Corporation, INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Authors: George F. Riley<riley@ece.gatech.edu>
19  * Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20  */
21 #ifndef NODE_H
22 #define NODE_H
24 #include <vector>
26 #include "ns3/object.h"
27 #include "ns3/callback.h"
28 #include "ns3/ptr.h"
29 #include "ns3/net-device.h"
31 namespace ns3 {
33 class Application;
34 class Packet;
35 class Address;
36 class Time;
56 class Node : public Object
57 {
58 public:
63  static TypeId GetTypeId (void);
65  Node();
69  Node(uint32_t systemId);
71  virtual ~Node();
79  uint32_t GetId (void) const;
89  Time GetLocalTime (void) const;
95  uint32_t GetSystemId (void) const;
104  uint32_t AddDevice (Ptr<NetDevice> device);
111  Ptr<NetDevice> GetDevice (uint32_t index) const;
116  uint32_t GetNDevices (void) const;
125  uint32_t AddApplication (Ptr<Application> application);
132  Ptr<Application> GetApplication (uint32_t index) const;
137  uint32_t GetNApplications (void) const;
158  typedef Callback<void,Ptr<NetDevice>, Ptr<const Packet>,uint16_t,const Address &,
174  uint16_t protocolType,
175  Ptr<NetDevice> device,
176  bool promiscuous=false);
210  static bool ChecksumEnabled (void);
213 protected:
219  virtual void DoDispose (void);
220  virtual void DoInitialize (void);
221 private:
227  void NotifyDeviceAdded (Ptr<NetDevice> device);
237  bool NonPromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol, const Address &from);
248  bool PromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
249  const Address &from, const Address &to, NetDevice::PacketType packetType);
261  bool ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol,
262  const Address &from, const Address &to, NetDevice::PacketType packetType, bool promisc);
267  void Construct (void);
276  uint16_t protocol;
277  bool promiscuous;
278  };
281  typedef std::vector<struct Node::ProtocolHandlerEntry> ProtocolHandlerList;
283  typedef std::vector<DeviceAdditionListener> DeviceAdditionListenerList;
285  uint32_t m_id;
286  uint32_t m_sid;
287  std::vector<Ptr<NetDevice> > m_devices;
288  std::vector<Ptr<Application> > m_applications;
291 };
293 } // namespace ns3
295 #endif /* NODE_H */
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
Definition: node.cc:159
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Callback template class.
Definition: callback.h:1278
uint32_t GetId(void) const
Definition: node.cc:109
virtual void DoInitialize(void)
Initialize() implementation.
Definition: node.cc:209
DeviceAdditionListenerList m_deviceAdditionListeners
Device addition listeners in the node.
Definition: node.h:290
std::vector< DeviceAdditionListener > DeviceAdditionListenerList
Typedef for NetDevice addition listeners container.
Definition: node.h:283
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:144
static bool ChecksumEnabled(void)
Definition: node.cc:278
void NotifyDeviceAdded(Ptr< NetDevice > device)
Notifies all the DeviceAdditionListener about the new device added.
Definition: node.cc:362
ProtocolHandler handler
the protocol handler
Definition: node.h:274
std::vector< Ptr< NetDevice > > m_devices
Devices associated to this node.
Definition: node.h:287
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:743
void UnregisterProtocolHandler(ProtocolHandler handler)
Definition: node.cc:263
a polymophic address class
Definition: address.h:90
std::vector< struct Node::ProtocolHandlerEntry > ProtocolHandlerList
Typedef for protocol handlers container.
Definition: node.h:281
bool NonPromiscReceiveFromDevice(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &from)
Receive a packet from a device in non-promiscuous mode.
Definition: node.cc:295
uint32_t m_sid
System id for this node.
Definition: node.h:286
virtual void DoDispose(void)
The dispose method.
Definition: node.cc:185
Ptr< NetDevice > device
the NetDevice
Definition: node.h:275
Ptr< Application > GetApplication(uint32_t index) const
Retrieve the index-th Application associated to this node.
Definition: node.cc:170
uint16_t protocol
the protocol number
Definition: node.h:276
Time GetLocalTime(void) const
In the future, ns3 nodes may have clock that returned a local time different from the virtual time Si...
Definition: node.cc:116
ProtocolHandlerList m_handlers
Protocol handlers in the node.
Definition: node.h:289
void RegisterDeviceAdditionListener(DeviceAdditionListener listener)
Definition: node.cc:335
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t GetSystemId(void) const
Definition: node.cc:123
std::vector< Ptr< Application > > m_applications
Applications associated to this node.
Definition: node.h:288
Protocol handler entry.
Definition: node.h:273
uint32_t m_id
Node id for this node.
Definition: node.h:285
void RegisterProtocolHandler(ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device, bool promiscuous=false)
Definition: node.cc:229
static TypeId GetTypeId(void)
Get the type ID.
Definition: node.cc:52
bool ReceiveFromDevice(Ptr< NetDevice > device, Ptr< const Packet >, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType, bool promisc)
Receive a packet from a device.
Definition: node.cc:303
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:130
void UnregisterDeviceAdditionListener(DeviceAdditionListener listener)
Definition: node.cc:347
virtual ~Node()
Definition: node.cc:103
A network Node.
Definition: node.h:56
Callback< void, Ptr< NetDevice > > DeviceAdditionListener
A callback invoked whenever a device is added to a node.
Definition: node.h:188
uint32_t GetNApplications(void) const
Definition: node.cc:178
A base class which provides memory management and object aggregation.
Definition: object.h:87
Callback< void, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address &, const Address &, NetDevice::PacketType > ProtocolHandler
A protocol handler.
Definition: node.h:159
Packet types are used as they are in Linux.
Definition: net-device.h:296
a unique identifier for an interface.
Definition: type-id.h:58
void Construct(void)
Finish node&#39;s construction by setting the correct node ID.
Definition: node.cc:97
uint32_t GetNDevices(void) const
Definition: node.cc:152
bool promiscuous
true if it is a promiscuous handler
Definition: node.h:277
bool PromiscReceiveFromDevice(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Receive a packet from a device in promiscuous mode.
Definition: node.cc:287
Definition: node.cc:80