A Discrete-Event Network Simulator
API
node.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006 Georgia Tech Research Corporation, INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Authors: George F. Riley<riley@ece.gatech.edu>
18  * Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #ifndef NODE_H
21 #define NODE_H
22 
23 #include "ns3/callback.h"
24 #include "ns3/net-device.h"
25 #include "ns3/object.h"
26 #include "ns3/ptr.h"
27 
28 #include <vector>
29 
30 namespace ns3
31 {
32 
33 class Application;
34 class Packet;
35 class Address;
36 class Time;
37 
55 class Node : public Object
56 {
57  public:
62  static TypeId GetTypeId();
63 
64  Node();
68  Node(uint32_t systemId);
69 
70  ~Node() override;
71 
78  uint32_t GetId() const;
79 
88  Time GetLocalTime() const;
89 
94  uint32_t GetSystemId() const;
95 
103  uint32_t AddDevice(Ptr<NetDevice> device);
110  Ptr<NetDevice> GetDevice(uint32_t index) const;
115  uint32_t GetNDevices() const;
116 
124  uint32_t AddApplication(Ptr<Application> application);
131  Ptr<Application> GetApplication(uint32_t index) const;
132 
136  uint32_t GetNApplications() const;
137 
157  typedef Callback<void,
160  uint16_t,
161  const Address&,
162  const Address&,
179  uint16_t protocolType,
180  Ptr<NetDevice> device,
181  bool promiscuous = false);
189 
209 
213  static bool ChecksumEnabled();
214 
215  protected:
221  void DoDispose() override;
222  void DoInitialize() override;
223 
224  private:
229  void NotifyDeviceAdded(Ptr<NetDevice> device);
230 
240  Ptr<const Packet> packet,
241  uint16_t protocol,
242  const Address& from);
254  Ptr<const Packet> packet,
255  uint16_t protocol,
256  const Address& from,
257  const Address& to,
258  NetDevice::PacketType packetType);
270  bool ReceiveFromDevice(Ptr<NetDevice> device,
272  uint16_t protocol,
273  const Address& from,
274  const Address& to,
275  NetDevice::PacketType packetType,
276  bool promisc);
277 
281  void Construct();
282 
288  {
291  uint16_t protocol;
292  bool promiscuous;
293  };
294 
296  typedef std::vector<struct Node::ProtocolHandlerEntry> ProtocolHandlerList;
298  typedef std::vector<DeviceAdditionListener> DeviceAdditionListenerList;
299 
300  uint32_t m_id;
301  uint32_t m_sid;
302  std::vector<Ptr<NetDevice>> m_devices;
303  std::vector<Ptr<Application>> m_applications;
306 };
307 
308 } // namespace ns3
309 
310 #endif /* NODE_H */
a polymophic address class
Definition: address.h:100
Callback template class.
Definition: callback.h:443
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:300
A network Node.
Definition: node.h:56
void UnregisterProtocolHandler(ProtocolHandler handler)
Definition: node.cc:276
std::vector< DeviceAdditionListener > DeviceAdditionListenerList
Typedef for NetDevice addition listeners container.
Definition: node.h:298
uint32_t GetSystemId() const
Definition: node.cc:131
void DoDispose() override
The dispose method.
Definition: node.cc:197
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:299
DeviceAdditionListenerList m_deviceAdditionListeners
Device addition listeners in the node.
Definition: node.h:305
std::vector< struct Node::ProtocolHandlerEntry > ProtocolHandlerList
Typedef for protocol handlers container.
Definition: node.h:296
std::vector< Ptr< Application > > m_applications
Applications associated to this node.
Definition: node.h:303
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:138
uint32_t m_id
Node id for this node.
Definition: node.h:300
uint32_t GetNDevices() const
Definition: node.cc:162
Callback< void, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address &, const Address &, NetDevice::PacketType > ProtocolHandler
A protocol handler.
Definition: node.h:164
uint32_t GetNApplications() const
Definition: node.cc:190
Ptr< Application > GetApplication(uint32_t index) const
Retrieve the index-th Application associated to this node.
Definition: node.cc:180
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:327
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:311
uint32_t m_sid
System id for this node.
Definition: node.h:301
ProtocolHandlerList m_handlers
Protocol handlers in the node.
Definition: node.h:304
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
Definition: node.cc:169
void Construct()
Finish node's construction by setting the correct node ID.
Definition: node.cc:105
static TypeId GetTypeId()
Get the type ID.
Definition: node.cc:55
Callback< void, Ptr< NetDevice > > DeviceAdditionListener
A callback invoked whenever a device is added to a node.
Definition: node.h:193
uint32_t GetId() const
Definition: node.cc:117
Node()
Definition: node.cc:88
Time GetLocalTime() const
In the future, ns3 nodes may have clock that returned a local time different from the virtual time Si...
Definition: node.cc:124
void RegisterDeviceAdditionListener(DeviceAdditionListener listener)
Definition: node.cc:364
void DoInitialize() override
Initialize() implementation.
Definition: node.cc:222
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:152
~Node() override
Definition: node.cc:111
void NotifyDeviceAdded(Ptr< NetDevice > device)
Notifies all the DeviceAdditionListener about the new device added.
Definition: node.cc:393
static bool ChecksumEnabled()
Definition: node.cc:290
void UnregisterDeviceAdditionListener(DeviceAdditionListener listener)
Definition: node.cc:377
std::vector< Ptr< NetDevice > > m_devices
Devices associated to this node.
Definition: node.h:302
void RegisterProtocolHandler(ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device, bool promiscuous=false)
Definition: node.cc:242
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:60
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:848
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Protocol handler entry.
Definition: node.h:288
bool promiscuous
true if it is a promiscuous handler
Definition: node.h:292
uint16_t protocol
the protocol number
Definition: node.h:291
Ptr< NetDevice > device
the NetDevice
Definition: node.h:290
ProtocolHandler handler
the protocol handler
Definition: node.h:289