A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
37 
55 class Node : public Object
56 {
57 public:
62  static TypeId GetTypeId (void);
63 
64  Node();
68  Node(uint32_t systemId);
69 
70  virtual ~Node();
71 
78  uint32_t GetId (void) const;
79 
84  uint32_t GetSystemId (void) const;
85 
93  uint32_t AddDevice (Ptr<NetDevice> device);
101  Ptr<NetDevice> GetDevice (uint32_t index) const;
106  uint32_t GetNDevices (void) const;
107 
115  uint32_t AddApplication (Ptr<Application> application);
121  Ptr<Application> GetApplication (uint32_t index) const;
122 
126  uint32_t GetNApplications (void) const;
127 
147  typedef Callback<void,Ptr<NetDevice>, Ptr<const Packet>,uint16_t,const Address &,
163  uint16_t protocolType,
164  Ptr<NetDevice> device,
165  bool promiscuous=false);
173 
193 
194 
195 
199  static bool ChecksumEnabled (void);
200 
201 
202 protected:
208  virtual void DoDispose (void);
209  virtual void DoInitialize (void);
210 private:
211 
216  void NotifyDeviceAdded (Ptr<NetDevice> device);
217 
226  bool NonPromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol, const Address &from);
237  bool PromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
238  const Address &from, const Address &to, NetDevice::PacketType packetType);
250  bool ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol,
251  const Address &from, const Address &to, NetDevice::PacketType packetType, bool promisc);
252 
256  void Construct (void);
257 
265  uint16_t protocol;
266  bool promiscuous;
267  };
268 
270  typedef std::vector<struct Node::ProtocolHandlerEntry> ProtocolHandlerList;
272  typedef std::vector<DeviceAdditionListener> DeviceAdditionListenerList;
273 
274  uint32_t m_id;
275  uint32_t m_sid;
276  std::vector<Ptr<NetDevice> > m_devices;
277  std::vector<Ptr<Application> > m_applications;
280 };
281 
282 } // namespace ns3
283 
284 #endif /* NODE_H */
uint32_t AddApplication(Ptr< Application > application)
Definition: node.cc:149
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
Callback template class.
Definition: callback.h:924
uint32_t GetNApplications(void) const
Definition: node.cc:168
virtual void DoInitialize(void)
This method is called only once by Object::Initialize.
Definition: node.cc:199
DeviceAdditionListenerList m_deviceAdditionListeners
Device addition listeners in the node.
Definition: node.h:279
std::vector< DeviceAdditionListener > DeviceAdditionListenerList
Typedef for NetDevice addition listeners container.
Definition: node.h:272
static bool ChecksumEnabled(void)
Definition: node.cc:268
void NotifyDeviceAdded(Ptr< NetDevice > device)
Notifies all the DeviceAdditionListener about the new device added.
Definition: node.cc:352
ProtocolHandler handler
the protocol handler
Definition: node.h:263
std::vector< Ptr< NetDevice > > m_devices
Devices associated to this node.
Definition: node.h:276
uint32_t GetSystemId(void) const
Definition: node.cc:113
void UnregisterProtocolHandler(ProtocolHandler handler)
Definition: node.cc:253
a polymophic address class
Definition: address.h:86
std::vector< struct Node::ProtocolHandlerEntry > ProtocolHandlerList
Typedef for protocol handlers container.
Definition: node.h:270
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:285
uint32_t m_sid
System id for this node.
Definition: node.h:275
Ptr< Application > GetApplication(uint32_t index) const
Definition: node.cc:160
virtual void DoDispose(void)
The dispose method.
Definition: node.cc:175
Ptr< NetDevice > device
the NetDevice
Definition: node.h:264
Ptr< NetDevice > GetDevice(uint32_t index) const
Definition: node.cc:134
uint16_t protocol
the protocol number
Definition: node.h:265
uint32_t GetNDevices(void) const
Definition: node.cc:142
ProtocolHandlerList m_handlers
Protocol handlers in the node.
Definition: node.h:278
void RegisterDeviceAdditionListener(DeviceAdditionListener listener)
Definition: node.cc:325
std::vector< Ptr< Application > > m_applications
Applications associated to this node.
Definition: node.h:277
Protocol handler entry.
Definition: node.h:262
uint32_t m_id
Node id for this node.
Definition: node.h:274
void RegisterProtocolHandler(ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device, bool promiscuous=false)
Definition: node.cc:219
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:293
uint32_t AddDevice(Ptr< NetDevice > device)
Definition: node.cc:120
uint32_t GetId(void) const
Definition: node.cc:106
void UnregisterDeviceAdditionListener(DeviceAdditionListener listener)
Definition: node.cc:337
virtual ~Node()
Definition: node.cc:100
A network Node.
Definition: node.h:55
Callback< void, Ptr< NetDevice > > DeviceAdditionListener
A callback invoked whenever a device is added to a node.
Definition: node.h:177
a base class which provides memory management and object aggregation
Definition: object.h:64
Callback< void, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address &, const Address &, NetDevice::PacketType > ProtocolHandler
A protocol handler.
Definition: node.h:148
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:274
a unique identifier for an interface.
Definition: type-id.h:49
void Construct(void)
Finish node's construction by setting the correct node ID.
Definition: node.cc:94
bool promiscuous
true if it is a promiscuous handler
Definition: node.h:266
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:277
Node()
Definition: node.cc:77