A Discrete-Event Network Simulator
API
node.h
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
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * 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
23 
24 #include <vector>
25 
26 #include "ns3/object.h"
27 #include "ns3/callback.h"
28 #include "ns3/ptr.h"
29 #include "ns3/net-device.h"
30 
31 namespace ns3 {
32 
33 class Application;
34 class Packet;
35 class Address;
36 class Time;
37 
38 
56 class Node : public Object
57 {
58 public:
63  static TypeId GetTypeId (void);
64 
65  Node();
69  Node(uint32_t systemId);
70 
71  virtual ~Node();
72 
79  uint32_t GetId (void) const;
80 
89  Time GetLocalTime (void) const;
90 
95  uint32_t GetSystemId (void) const;
96 
104  uint32_t AddDevice (Ptr<NetDevice> device);
111  Ptr<NetDevice> GetDevice (uint32_t index) const;
116  uint32_t GetNDevices (void) const;
117 
125  uint32_t AddApplication (Ptr<Application> application);
132  Ptr<Application> GetApplication (uint32_t index) const;
133 
137  uint32_t GetNApplications (void) const;
138 
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);
184 
204 
205 
206 
210  static bool ChecksumEnabled (void);
211 
212 
213 protected:
219  virtual void DoDispose (void);
220  virtual void DoInitialize (void);
221 private:
222 
227  void NotifyDeviceAdded (Ptr<NetDevice> device);
228 
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);
263 
267  void Construct (void);
268 
276  uint16_t protocol;
277  bool promiscuous;
278  };
279 
281  typedef std::vector<struct Node::ProtocolHandlerEntry> ProtocolHandlerList;
283  typedef std::vector<DeviceAdditionListener> DeviceAdditionListenerList;
284 
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 };
292 
293 } // namespace ns3
294 
295 #endif /* NODE_H */
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
Definition: node.cc:157
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:1176
uint32_t GetId(void) const
Definition: node.cc:107
virtual void DoInitialize(void)
Initialize() implementation.
Definition: node.cc:207
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:142
static bool ChecksumEnabled(void)
Definition: node.cc:276
void NotifyDeviceAdded(Ptr< NetDevice > device)
Notifies all the DeviceAdditionListener about the new device added.
Definition: node.cc:360
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:740
void UnregisterProtocolHandler(ProtocolHandler handler)
Definition: node.cc:261
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:293
uint32_t m_sid
System id for this node.
Definition: node.h:286
virtual void DoDispose(void)
The dispose method.
Definition: node.cc:183
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:168
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:114
ProtocolHandlerList m_handlers
Protocol handlers in the node.
Definition: node.h:289
void RegisterDeviceAdditionListener(DeviceAdditionListener listener)
Definition: node.cc:333
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t GetSystemId(void) const
Definition: node.cc:121
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:227
static TypeId GetTypeId(void)
Get the type ID.
Definition: node.cc:50
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:301
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:128
void UnregisterDeviceAdditionListener(DeviceAdditionListener listener)
Definition: node.cc:345
virtual ~Node()
Definition: node.cc:101
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:176
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
PacketType
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:95
uint32_t GetNDevices(void) const
Definition: node.cc:150
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:285
Node()
Definition: node.cc:78