A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
node.h
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 #include "ns3/common-cognitive-header.h"
31 
32 namespace ns3 {
33 
34 class Application;
35 class Packet;
36 class Address;
37 
38 
56 class Node : public Object
57 {
58 public:
59  static TypeId GetTypeId (void);
60 
61  Node();
65  Node(uint32_t systemId);
66 
67  virtual ~Node();
68 
75  uint32_t GetId (void) const;
76 
81  uint32_t GetSystemId (void) const;
82 
90  uint32_t AddDevice (Ptr<NetDevice> device);
98  Ptr<NetDevice> GetDevice (uint32_t index) const;
103  uint32_t GetNDevices (void) const;
104 
112  uint32_t AddApplication (Ptr<Application> application);
118  Ptr<Application> GetApplication (uint32_t index) const;
119 
123  uint32_t GetNApplications (void) const;
124 
144  typedef Callback<void,Ptr<NetDevice>, Ptr<const Packet>,uint16_t,const Address &,
160  uint16_t protocolType,
161  Ptr<NetDevice> device,
162  bool promiscuous=false);
170 
190 
191 
192 
196  static bool ChecksumEnabled (void);
197  void SetCognitiveRadio(bool isCR);
198  bool IsCognitiveRadio(void);
199 
200 
201 protected:
207  virtual void DoDispose (void);
208  virtual void DoInitialize (void);
209 private:
210  void NotifyDeviceAdded (Ptr<NetDevice> device);
211  bool NonPromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol, const Address &from);
212  bool PromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol,
213  const Address &from, const Address &to, NetDevice::PacketType packetType);
214  bool ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol,
215  const Address &from, const Address &to, NetDevice::PacketType packetType, bool promisc);
216 
217  void Construct (void);
218 
220  ProtocolHandler handler;
221  Ptr<NetDevice> device;
222  uint16_t protocol;
223  bool promiscuous;
224  };
225  typedef std::vector<struct Node::ProtocolHandlerEntry> ProtocolHandlerList;
226  typedef std::vector<DeviceAdditionListener> DeviceAdditionListenerList;
227 
228  uint32_t m_id; // Node id for this node
229  uint32_t m_sid; // System id for this node
230  std::vector<Ptr<NetDevice> > m_devices;
231  std::vector<Ptr<Application> > m_applications;
232  ProtocolHandlerList m_handlers;
233  DeviceAdditionListenerList m_deviceAdditionListeners;
234  bool m_isCognitiveRadio;
235 };
236 
237 } // namespace ns3
238 
239 #endif /* NODE_H */
uint32_t AddApplication(Ptr< Application > application)
Definition: node.cc:148
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
Callback template class.
Definition: callback.h:369
uint32_t GetNApplications(void) const
Definition: node.cc:167
virtual void DoInitialize(void)
Definition: node.cc:198
static bool ChecksumEnabled(void)
Definition: node.cc:267
uint32_t GetSystemId(void) const
Definition: node.cc:112
void UnregisterProtocolHandler(ProtocolHandler handler)
Definition: node.cc:252
a polymophic address class
Definition: address.h:86
Ptr< Application > GetApplication(uint32_t index) const
Definition: node.cc:159
virtual void DoDispose(void)
Definition: node.cc:174
Ptr< NetDevice > GetDevice(uint32_t index) const
Definition: node.cc:133
uint32_t GetNDevices(void) const
Definition: node.cc:141
void RegisterDeviceAdditionListener(DeviceAdditionListener listener)
Definition: node.cc:332
Definition: node.h:219
void RegisterProtocolHandler(ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device, bool promiscuous=false)
Definition: node.cc:218
uint32_t AddDevice(Ptr< NetDevice > device)
Definition: node.cc:119
uint32_t GetId(void) const
Definition: node.cc:105
void UnregisterDeviceAdditionListener(DeviceAdditionListener listener)
Definition: node.cc:344
A network Node.
Definition: node.h:56
Callback< void, Ptr< NetDevice > > DeviceAdditionListener
Definition: node.h:174
a base class which provides memory management and object aggregation
Definition: object.h:63
Callback< void, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address &, const Address &, NetDevice::PacketType > ProtocolHandler
Definition: node.h:145
a unique identifier for an interface.
Definition: type-id.h:44