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 <string.h>
40 
41 namespace ns3 {
42 
44 {
45 public:
50 
55  void SetBufferSize (uint32_t bufferSize);
56 
57 private:
58  FdReader::Data DoRead (void);
59 
60  uint32_t m_bufferSize;
61 };
62 
63 class Node;
64 
82 class FdNetDevice : public NetDevice
83 {
84 public:
85  static TypeId GetTypeId (void);
86 
91  {
92  DIX,
93  LLC,
100  };
101 
105  FdNetDevice ();
106 
110  virtual ~FdNetDevice ();
111 
119 
126 
131  void SetFileDescriptor (int fd);
132 
138  void Start (Time tStart);
139 
145  void Stop (Time tStop);
146 
147  // inherited from NetDevice base class.
148  virtual void SetIfIndex (const uint32_t index);
149  virtual uint32_t GetIfIndex (void) const;
150  virtual Ptr<Channel> GetChannel (void) const;
151  virtual void SetAddress (Address address);
152  virtual Address GetAddress (void) const;
153  virtual bool SetMtu (const uint16_t mtu);
154  virtual uint16_t GetMtu (void) const;
155  virtual bool IsLinkUp (void) const;
156  virtual void AddLinkChangeCallback (Callback<void> callback);
157  virtual bool IsBroadcast (void) const;
158  virtual Address GetBroadcast (void) const;
159  virtual bool IsMulticast (void) const;
160  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
161  virtual bool IsPointToPoint (void) const;
162  virtual bool IsBridge (void) const;
163  virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
164  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
165  virtual Ptr<Node> GetNode (void) const;
166  virtual void SetNode (Ptr<Node> node);
167  virtual bool NeedsArp (void) const;
170  virtual bool SupportsSendFrom () const;
171  virtual Address GetMulticast (Ipv6Address addr) const;
172 
173  virtual void SetIsBroadcast (bool broadcast);
174  virtual void SetIsMulticast (bool multicast);
175 
176 protected:
177  virtual void DoDispose (void);
178 
179 private:
180  // private copy constructor as sugested in:
181  // http://www.nsnam.org/wiki/NS-3_Python_Bindings#.22invalid_use_of_incomplete_type.22
182  FdNetDevice (FdNetDevice const &);
183 
187  void StartDevice (void);
188 
192  void StopDevice (void);
193 
197  void ReceiveCallback (uint8_t *buf, ssize_t len);
198 
202  void ForwardUp (uint8_t *buf, ssize_t len);
203 
209  bool TransmitStart (Ptr<Packet> p);
210 
211  void NotifyLinkUp (void);
212 
217 
218  /*
219  * a copy of the node id so the read thread doesn't have to GetNode() in
220  * in order to find the node ID. Thread unsafe reference counting in
221  * multithreaded apps is not a good thing.
222  */
223  uint32_t m_nodeId;
224 
228  uint32_t m_ifIndex;
229 
233  uint16_t m_mtu;
234 
238  int m_fd;
239 
244 
249 
254 
259  bool m_linkUp;
260 
265 
271 
277 
282 
287 
288 
293 
298 
303 
306 
311 
316 
324 
332 
341 
350 
359 
367 
374 
394 
414 
415 };
416 
417 } // namespace ns3
418 
419 #endif /* FD_NET_DEVICE_H */
420 
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:95
void StopDevice(void)
Tear down the device.
A structure representing data read.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
uint16_t m_mtu
The MTU associated to the file descriptor technology.
void ForwardUp(uint8_t *buf, ssize_t len)
Forward the frame to the appropriate callback for processing.
void SetFileDescriptor(int fd)
Set the associated file descriptor.
virtual void AddLinkChangeCallback(Callback< void > callback)
virtual bool SupportsSendFrom() const
String attribute value declarations.
EncapsulationMode m_encapMode
The typ of encapsulation of the received/transmited frames.
virtual bool NeedsArp(void) const
TracedCallback< Ptr< const Packet > > m_macRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
Forward calls to a chain of Callback.
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
DIX II / Ethernet II packet.
Definition: fd-net-device.h:92
NetDevice::ReceiveCallback m_rxCallback
The callback used to notify higher layers that a packet has been received.
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...
Time m_tStart
Time to start spinning up the device.
virtual bool IsMulticast(void) const
Ptr< FdNetDeviceFdReader > m_fdReader
Reader for the file descriptor.
void Stop(Time tStop)
Set a stop time for the device.
virtual void SetIsBroadcast(bool broadcast)
virtual uint32_t GetIfIndex(void) const
virtual void SetIfIndex(const uint32_t index)
a polymophic address class
Definition: address.h:90
A class that asynchronously reads from a file descriptor.
void NotifyLinkUp(void)
virtual Ptr< Node > GetNode(void) const
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition...
virtual Ptr< Channel > GetChannel(void) const
bool TransmitStart(Ptr< Packet > p)
Start Sending a Packet Down the Wire.
virtual void SetIsMulticast(bool multicast)
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
uint32_t m_maxPendingReads
Maximum number of packets that can be received and scheduled for read but not yeat read...
virtual Address GetBroadcast(void) const
FdNetDeviceFdReader()
Constructor for the FdNetDevice.
void StartDevice(void)
Spin up the device.
void ReceiveCallback(uint8_t *buf, ssize_t len)
Callback to invoke when a new frame is received.
802.2 LLC/SNAP Packet
Definition: fd-net-device.h:93
Ptr< Node > m_node
The ns-3 node associated to the net device.
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
The trace source fired for packets successfully received by the device but which are dropped before b...
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
virtual bool IsLinkUp(void) const
void SetEncapsulationMode(FdNetDevice::EncapsulationMode mode)
Set the link layer encapsulation mode of this device.
virtual void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb)
int m_fd
The file descriptor used for receive/send network traffic.
TracedCallback m_linkChangeCallbacks
Callbacks to fire if the link changes state (up or down).
Every class exported by the ns3 library is enclosed in the ns3 namespace.
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
A trace source that emulates a promiscuous mode protocol sniffer connected to the device...
virtual bool IsBroadcast(void) const
virtual void SetNode(Ptr< Node > node)
an EUI-48 address
Definition: mac48-address.h:43
A class which provides a relatively platform-independent Mutual Exclusion thread synchronization prim...
Definition: system-mutex.h:58
TracedCallback< Ptr< const Packet > > m_snifferTrace
A trace source that emulates a non-promiscuous protocol sniffer connected to the device.
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:94
FdReader::Data DoRead(void)
The read implementation.
FdNetDevice::EncapsulationMode GetEncapsulationMode(void) const
Get the link layer encapsulation mode of this device.
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received.
uint32_t m_pendingReadCount
Number of packets that were received and scheduled for read but not yeat read.
virtual bool SetMtu(const uint16_t mtu)
Describes an IPv6 address.
Definition: ipv6-address.h:47
uint32_t m_ifIndex
The ns-3 interface index (in the sense of net device index) that has been assigned to this network de...
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
static TypeId GetTypeId(void)
An identifier for simulation events.
Definition: event-id.h:53
virtual Address GetAddress(void) const
Network layer to device interface.
Definition: net-device.h:75
TracedCallback< Ptr< const Packet > > m_phyTxDropTrace
The trace source fired when the phy layer drops a packet as it tries to transmit it.
virtual void SetAddress(Address address)
Set the address of this interface.
void Start(Time tStart)
Set a start time for the device.
A network Node.
Definition: node.h:55
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
NetDevice::PromiscReceiveCallback m_promiscRxCallback
The callback used to notify higher layers that a packet has been received in promiscuous mode...
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
void SetBufferSize(uint32_t bufferSize)
Set size of the read buffer.
a NetDevice to read/write network traffic from/into a file descriptor.
Definition: fd-net-device.h:82
tuple address
Definition: first.py:37
Mac48Address m_address
The net device mac address.
bool m_isBroadcast
Flag indicating whether or not the underlying net device supports broadcast.
EncapsulationMode
Enumeration of the types of frames supported in the class.
Definition: fd-net-device.h:90
virtual uint16_t GetMtu(void) const
virtual void DoDispose(void)
Destructor implementation.
bool m_linkUp
Flag indicating whether or not the link is up.
a unique identifier for an interface.
Definition: type-id.h:51
FdNetDevice()
Constructor for the FdNetDevice.
virtual ~FdNetDevice()
Destructor for the FdNetDevice.
bool m_isMulticast
Flag indicating whether or not the underlying net device supports multicast.
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
Time m_tStop
Time to start tearing down the device.
SystemMutex m_pendingReadMutex
Mutex to increase pending read counter.