A Discrete-Event Network Simulator
API
fd-net-device.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2012 INRIA, 2012 University of Washington
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  * Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19  * Claudio Freire <klaussfreire@sourceforge.net>
20  */
21 
22 #ifndef FD_NET_DEVICE_H
23 #define FD_NET_DEVICE_H
24 
25 #include "ns3/address.h"
26 #include "ns3/callback.h"
27 #include "ns3/data-rate.h"
28 #include "ns3/event-id.h"
29 #include "ns3/mac48-address.h"
30 #include "ns3/net-device.h"
31 #include "ns3/node.h"
32 #include "ns3/packet.h"
33 #include "ns3/ptr.h"
34 #include "ns3/system-condition.h"
35 #include "ns3/traced-callback.h"
36 #include "ns3/unix-fd-reader.h"
37 #include "ns3/system-mutex.h"
38 
39 #include <utility>
40 #include <queue>
41 
42 namespace ns3 {
43 
44 
56 {
57 public:
59 
64  void SetBufferSize (uint32_t bufferSize);
65 
66 private:
67  FdReader::Data DoRead (void);
68 
69  uint32_t m_bufferSize;
70 };
71 
72 class Node;
73 
85 class FdNetDevice : public NetDevice
86 {
87 public:
92  static TypeId GetTypeId (void);
93 
98  {
99  DIX,
100  LLC,
101  DIXPI,
107  };
108 
112  FdNetDevice ();
113 
117  virtual ~FdNetDevice ();
118 
126 
133 
138  void SetFileDescriptor (int fd);
139 
145  void Start (Time tStart);
146 
152  void Stop (Time tStop);
153 
154  // inherited from NetDevice base class.
155  virtual void SetIfIndex (const uint32_t index);
156  virtual uint32_t GetIfIndex (void) const;
157  virtual Ptr<Channel> GetChannel (void) const;
158  virtual void SetAddress (Address address);
159  virtual Address GetAddress (void) const;
160  virtual bool SetMtu (const uint16_t mtu);
161  virtual uint16_t GetMtu (void) const;
162  virtual bool IsLinkUp (void) const;
163  virtual void AddLinkChangeCallback (Callback<void> callback);
164  virtual bool IsBroadcast (void) const;
165  virtual Address GetBroadcast (void) const;
166  virtual bool IsMulticast (void) const;
167  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
168  virtual bool IsPointToPoint (void) const;
169  virtual bool IsBridge (void) const;
170  virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
171  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
172  virtual Ptr<Node> GetNode (void) const;
173  virtual void SetNode (Ptr<Node> node);
174  virtual bool NeedsArp (void) const;
177  virtual bool SupportsSendFrom () const;
178  virtual Address GetMulticast (Ipv6Address addr) const;
179 
184  virtual void SetIsBroadcast (bool broadcast);
189  virtual void SetIsMulticast (bool multicast);
190 
197  virtual ssize_t Write (uint8_t *buffer, size_t length);
198 
199 protected:
203  virtual void DoInitialize (void);
204 
205  virtual void DoDispose (void);
206 
211  int GetFileDescriptor (void) const;
212 
218  virtual uint8_t* AllocateBuffer (size_t len);
219 
224  virtual void FreeBuffer (uint8_t* buf);
225 
231  void ReceiveCallback (uint8_t *buf, ssize_t len);
232 
237 
241  std::queue< std::pair<uint8_t *, ssize_t> > m_pendingQueue;
242 
243 private:
251 
255  void StartDevice (void);
256 
260  void StopDevice (void);
261 
266  virtual Ptr<FdReader> DoCreateFdReader (void);
267 
271  virtual void DoFinishStartingDevice (void);
272 
276  virtual void DoFinishStoppingDevice (void);
277 
281  void ForwardUp (void);
282 
289 
293  void NotifyLinkUp (void);
294 
299 
305  uint32_t m_nodeId;
306 
310  uint32_t m_ifIndex;
311 
315  uint16_t m_mtu;
316 
320  int m_fd;
321 
326 
331 
336 
341  bool m_linkUp;
342 
347 
353 
359 
364 
369 
374 
383 
388 
393 
401 
409 
418 
427 
436 
446 
453 
473 
493 
494 };
495 
496 } // namespace ns3
497 
498 #endif /* FD_NET_DEVICE_H */
499 
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
ns3::FdNetDevice::DoFinishStartingDevice
virtual void DoFinishStartingDevice(void)
Complete additional actions, if any, to spin up down the device.
Definition: fd-net-device.cc:271
ns3::FdNetDevice::SetMtu
virtual bool SetMtu(const uint16_t mtu)
Definition: fd-net-device.cc:710
ns3::FdNetDevice::IsMulticast
virtual bool IsMulticast(void) const
Definition: fd-net-device.cc:759
ns3::FdNetDevice::SetPromiscReceiveCallback
virtual void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb)
Definition: fd-net-device.cc:824
ns3::FdNetDevice::m_fd
int m_fd
The file descriptor used for receive/send network traffic.
Definition: fd-net-device.h:320
ns3::FdNetDevice::IsPointToPoint
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
Definition: fd-net-device.cc:789
ns3::FdNetDevice::m_promiscSnifferTrace
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
A trace source that emulates a promiscuous mode protocol sniffer connected to the device.
Definition: fd-net-device.h:492
ns3::FdNetDevice::GetIfIndex
virtual uint32_t GetIfIndex(void) const
Definition: fd-net-device.cc:698
ns3::EventId
An identifier for simulation events.
Definition: event-id.h:54
ns3::Callback< void >
ns3::FdNetDeviceFdReader::DoRead
FdReader::Data DoRead(void)
The read implementation.
Definition: fd-net-device.cc:59
ns3::FdNetDevice::m_maxPendingReads
uint32_t m_maxPendingReads
Maximum number of packets that can be received and scheduled for read but not yet read.
Definition: fd-net-device.h:363
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::FdNetDevice::ForwardUp
void ForwardUp(void)
Forward the frame to the appropriate callback for processing.
Definition: fd-net-device.cc:418
ns3::FdNetDevice::GetBroadcast
virtual Address GetBroadcast(void) const
Definition: fd-net-device.cc:753
ns3::FdNetDevice::m_tStart
Time m_tStart
Time to start spinning up the device.
Definition: fd-net-device.h:368
ns3::FdNetDevice::m_node
Ptr< Node > m_node
The ns-3 node associated to the net device.
Definition: fd-net-device.h:298
ns3::FdNetDevice::StartDevice
void StartDevice(void)
Spin up the device.
Definition: fd-net-device.cc:241
ns3::FdNetDevice::SetFileDescriptor
void SetFileDescriptor(int fd)
Set the associated file descriptor.
Definition: fd-net-device.cc:658
ns3::FdNetDevice::AddLinkChangeCallback
virtual void AddLinkChangeCallback(Callback< void > callback)
Definition: fd-net-device.cc:735
ns3::FdNetDevice::DoDispose
virtual void DoDispose(void)
Destructor implementation.
Definition: fd-net-device.cc:202
ns3::Node
A network Node.
Definition: node.h:57
ns3::SystemMutex
A class which provides a relatively platform-independent Mutual Exclusion thread synchronization prim...
Definition: system-mutex.h:59
ns3::FdNetDevice::m_ifIndex
uint32_t m_ifIndex
The ns-3 interface index (in the sense of net device index) that has been assigned to this network de...
Definition: fd-net-device.h:310
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
ns3::FdNetDevice::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: fd-net-device.cc:81
ns3::Ipv6Address
Describes an IPv6 address.
Definition: ipv6-address.h:50
ns3::FdNetDevice::FdNetDevice
FdNetDevice()
Constructor for the FdNetDevice.
Definition: fd-net-device.cc:168
ns3::FdNetDevice::m_phyTxDropTrace
TracedCallback< Ptr< const Packet > > m_phyTxDropTrace
The trace source fired when the phy layer drops a packet as it tries to transmit it.
Definition: fd-net-device.h:445
ns3::Mac48Address
an EUI-48 address
Definition: mac48-address.h:44
ns3::FdNetDevice::SetEncapsulationMode
void SetEncapsulationMode(FdNetDevice::EncapsulationMode mode)
Set the link layer encapsulation mode of this device.
Definition: fd-net-device.cc:210
ns3::FdNetDevice::DoCreateFdReader
virtual Ptr< FdReader > DoCreateFdReader(void)
Create the FdReader object.
Definition: fd-net-device.cc:260
ns3::FdNetDeviceFdReader::m_bufferSize
uint32_t m_bufferSize
size of the read buffer
Definition: fd-net-device.h:69
ns3::FdNetDevice::m_rxCallback
NetDevice::ReceiveCallback m_rxCallback
The callback used to notify higher layers that a packet has been received.
Definition: fd-net-device.h:387
ns3::FdNetDevice::m_pendingQueue
std::queue< std::pair< uint8_t *, ssize_t > > m_pendingQueue
Number of packets that were received and scheduled for read but not yet read.
Definition: fd-net-device.h:241
ns3::FdNetDevice::Start
void Start(Time tStart)
Set a start time for the device.
Definition: fd-net-device.cc:225
ns3::FdNetDevice::m_macTxDropTrace
TracedCallback< Ptr< const Packet > > m_macTxDropTrace
The trace source fired when packets coming into the "top" of the device at the L3/L2 transition are d...
Definition: fd-net-device.h:408
ns3::FdNetDevice::m_macTxTrace
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition,...
Definition: fd-net-device.h:400
ns3::FdNetDevice::EncapsulationMode
EncapsulationMode
Enumeration of the types of frames supported in the class.
Definition: fd-net-device.h:98
ns3::FdNetDevice::m_promiscRxCallback
NetDevice::PromiscReceiveCallback m_promiscRxCallback
The callback used to notify higher layers that a packet has been received in promiscuous mode.
Definition: fd-net-device.h:392
ns3::FdNetDevice::StopDevice
void StopDevice(void)
Tear down the device.
Definition: fd-net-device.cc:283
ns3::FdNetDevice::TransmitStart
bool TransmitStart(Ptr< Packet > p)
Start Sending a Packet Down the Wire.
ns3::FdNetDevice::GetMulticast
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
Definition: fd-net-device.cc:771
ns3::FdNetDevice::DIX
@ DIX
DIX II / Ethernet II packet.
Definition: fd-net-device.h:99
ns3::FdNetDevice::GetFileDescriptor
int GetFileDescriptor(void) const
Get the associated file descriptor.
Definition: fd-net-device.cc:667
ns3::FdNetDevice::m_mtu
uint16_t m_mtu
The MTU associated to the file descriptor technology.
Definition: fd-net-device.h:315
ns3::FdNetDevice::m_fdReader
Ptr< FdReader > m_fdReader
Reader for the file descriptor.
Definition: fd-net-device.h:325
ns3::Ptr< Channel >
ns3::FdNetDevice::m_snifferTrace
TracedCallback< Ptr< const Packet > > m_snifferTrace
A trace source that emulates a non-promiscuous protocol sniffer connected to the device.
Definition: fd-net-device.h:472
ns3::FdNetDevice::m_address
Mac48Address m_address
The net device mac address.
Definition: fd-net-device.h:330
ns3::Address
a polymophic address class
Definition: address.h:91
ns3::FdNetDevice::DoFinishStoppingDevice
virtual void DoFinishStoppingDevice(void)
Complete additional actions, if any, to tear down the device.
Definition: fd-net-device.cc:277
ns3::NetDevice::ReceiveCallback
Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address & > ReceiveCallback
Definition: net-device.h:318
ns3::FdNetDevice::IsBridge
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
Definition: fd-net-device.cc:783
ns3::FdNetDevice::SetAddress
virtual void SetAddress(Address address)
Set the address of this interface.
Definition: fd-net-device.cc:673
ns3::FdNetDevice::SupportsSendFrom
virtual bool SupportsSendFrom() const
Definition: fd-net-device.cc:830
ns3::FdNetDevice::GetNode
virtual Ptr< Node > GetNode(void) const
Definition: fd-net-device.cc:795
ns3::FdNetDeviceFdReader::FdNetDeviceFdReader
FdNetDeviceFdReader()
Definition: fd-net-device.cc:47
ns3::FdNetDevice::SetNode
virtual void SetNode(Ptr< Node > node)
Definition: fd-net-device.cc:801
first.address
address
Definition: first.py:44
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::FdNetDevice::m_macRxDropTrace
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
The trace source fired for packets successfully received by the device but which are dropped before b...
Definition: fd-net-device.h:435
ns3::FdNetDevice::IsLinkUp
virtual bool IsLinkUp(void) const
Definition: fd-net-device.cc:729
ns3::FdNetDevice::SetIfIndex
virtual void SetIfIndex(const uint32_t index)
Definition: fd-net-device.cc:692
ns3::FdNetDevice::m_isMulticast
bool m_isMulticast
Flag indicating whether or not the underlying net device supports multicast.
Definition: fd-net-device.h:358
ns3::FdNetDevice::m_phyRxDropTrace
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received.
Definition: fd-net-device.h:452
ns3::FdNetDevice::Send
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
Definition: fd-net-device.cc:561
ns3::FdNetDevice::SendFrom
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
Definition: fd-net-device.cc:568
ns3::FdNetDevice
a NetDevice to read/write network traffic from/into a file descriptor.
Definition: fd-net-device.h:86
ns3::FdNetDevice::FdNetDevice
FdNetDevice(FdNetDevice const &)
Copy constructor.
ns3::FdNetDevice::IsBroadcast
virtual bool IsBroadcast(void) const
Definition: fd-net-device.cc:741
ns3::FdNetDevice::m_pendingReadMutex
SystemMutex m_pendingReadMutex
Mutex to increase pending read counter.
Definition: fd-net-device.h:236
ns3::FdReader
A class that asynchronously reads from a file descriptor.
Definition: unix-fd-reader.h:48
ns3::FdNetDevice::SetIsBroadcast
virtual void SetIsBroadcast(bool broadcast)
Set if the NetDevice is able to send Broadcast messages.
Definition: fd-net-device.cc:747
ns3::FdNetDevice::AllocateBuffer
virtual uint8_t * AllocateBuffer(size_t len)
Allocate packet buffer.
Definition: fd-net-device.cc:406
ns3::FdNetDeviceFdReader::SetBufferSize
void SetBufferSize(uint32_t bufferSize)
Set size of the read buffer.
Definition: fd-net-device.cc:53
ns3::FdNetDevice::m_stopEvent
EventId m_stopEvent
NetDevice stop event.
Definition: fd-net-device.h:382
ns3::FdNetDevice::m_nodeId
uint32_t m_nodeId
a copy of the node id so the read thread doesn't have to GetNode() in in order to find the node ID.
Definition: fd-net-device.h:305
ns3::FdNetDevice::m_isBroadcast
bool m_isBroadcast
Flag indicating whether or not the underlying net device supports broadcast.
Definition: fd-net-device.h:352
ns3::FdNetDevice::DoInitialize
virtual void DoInitialize(void)
Method Initialization for start and stop attributes.
Definition: fd-net-device.cc:189
ns3::FdNetDevice::DIXPI
@ DIXPI
When using TAP devices, if flag IFF_NO_PI is not set on the device, IP packets will have an extra hea...
Definition: fd-net-device.h:101
ns3::FdNetDevice::Write
virtual ssize_t Write(uint8_t *buffer, size_t length)
Write packet data to device.
Definition: fd-net-device.cc:649
ns3::FdNetDevice::GetEncapsulationMode
FdNetDevice::EncapsulationMode GetEncapsulationMode(void) const
Get the link layer encapsulation mode of this device.
Definition: fd-net-device.cc:218
ns3::TracedCallback
Forward calls to a chain of Callback.
Definition: traced-callback.h:53
ns3::FdNetDevice::GetChannel
virtual Ptr< Channel > GetChannel(void) const
Definition: fd-net-device.cc:704
ns3::FdNetDevice::GetMtu
virtual uint16_t GetMtu(void) const
Definition: fd-net-device.cc:723
ns3::FdNetDevice::m_encapMode
EncapsulationMode m_encapMode
The type of encapsulation of the received/transmitted frames.
Definition: fd-net-device.h:335
ns3::FdNetDevice::SetReceiveCallback
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
Definition: fd-net-device.cc:818
ns3::FdNetDevice::m_linkChangeCallbacks
TracedCallback m_linkChangeCallbacks
Callbacks to fire if the link changes state (up or down).
Definition: fd-net-device.h:346
ns3::FdNetDevice::m_startEvent
EventId m_startEvent
NetDevice start event.
Definition: fd-net-device.h:378
ns3::FdNetDevice::FreeBuffer
virtual void FreeBuffer(uint8_t *buf)
Free the given packet buffer.
Definition: fd-net-device.cc:412
ns3::FdNetDevice::~FdNetDevice
virtual ~FdNetDevice()
Destructor for the FdNetDevice.
Definition: fd-net-device.cc:183
ns3::FdNetDevice::m_tStop
Time m_tStop
Time to start tearing down the device.
Definition: fd-net-device.h:373
ns3::FdNetDevice::m_macRxTrace
TracedCallback< Ptr< const Packet > > m_macRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
Definition: fd-net-device.h:426
ns3::FdNetDevice::m_macPromiscRxTrace
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
Definition: fd-net-device.h:417
ns3::FdNetDevice::LLC
@ LLC
802.2 LLC/SNAP Packet
Definition: fd-net-device.h:100
ns3::FdNetDevice::GetAddress
virtual Address GetAddress(void) const
Definition: fd-net-device.cc:679
ns3::FdNetDevice::SetIsMulticast
virtual void SetIsMulticast(bool multicast)
Set if the NetDevice is able to send Multicast messages.
Definition: fd-net-device.cc:765
ns3::FdNetDevice::NeedsArp
virtual bool NeedsArp(void) const
Definition: fd-net-device.cc:812
ns3::FdNetDeviceFdReader
This class performs the actual data reading from the sockets.
Definition: fd-net-device.h:56
ns3::FdNetDevice::Stop
void Stop(Time tStop)
Set a stop time for the device.
Definition: fd-net-device.cc:233
ns3::NetDevice
Network layer to device interface.
Definition: net-device.h:96
ns3::FdReader::Data
A structure representing data read.
Definition: unix-fd-reader.h:77
ns3::FdNetDevice::m_linkUp
bool m_linkUp
Flag indicating whether or not the link is up.
Definition: fd-net-device.h:341
ns3::FdNetDevice::NotifyLinkUp
void NotifyLinkUp(void)
Notify that the link is up and ready.
Definition: fd-net-device.cc:685