A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
emu-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) 2008 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 
19 #ifndef EMU_NET_DEVICE_H
20 #define EMU_NET_DEVICE_H
21 
22 #include <cstring>
23 
24 #include "ns3/address.h"
25 #include "ns3/net-device.h"
26 #include "ns3/node.h"
27 #include "ns3/callback.h"
28 #include "ns3/packet.h"
29 #include "ns3/traced-callback.h"
30 #include "ns3/event-id.h"
31 #include "ns3/nstime.h"
32 #include "ns3/data-rate.h"
33 #include "ns3/ptr.h"
34 #include "ns3/mac48-address.h"
35 #include "ns3/system-thread.h"
36 #include "ns3/system-mutex.h"
37 
38 namespace ns3 {
39 
40 class Queue;
41 
52 class EmuNetDevice : public NetDevice
53 {
54 public:
55  static TypeId GetTypeId (void);
56 
62  DIX,
63  LLC,
64  };
65 
71  EmuNetDevice ();
72 
78  virtual ~EmuNetDevice ();
79 
86  void SetDataRate (DataRate bps);
87 
93  void Start (Time tStart);
94 
100  void Stop (Time tStop);
101 
112  void SetQueue (Ptr<Queue> queue);
113 
119  Ptr<Queue> GetQueue (void) const;
120 
121 
122 //
123 // Pure virtual methods inherited from NetDevice we must implement.
124 //
125  virtual void SetIfIndex (const uint32_t index);
126  virtual uint32_t GetIfIndex (void) const;
127 
128  virtual Ptr<Channel> GetChannel (void) const;
129 
130  virtual void SetAddress (Address address);
131  virtual Address GetAddress (void) const;
132 
133  virtual bool SetMtu (const uint16_t mtu);
134  virtual uint16_t GetMtu (void) const;
135 
136  virtual bool IsLinkUp (void) const;
137 
138  virtual void AddLinkChangeCallback (Callback<void> callback);
139 
140  virtual bool IsBroadcast (void) const;
141  virtual Address GetBroadcast (void) const;
142 
143  virtual bool IsMulticast (void) const;
144 
167  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
168 
176  virtual Address GetMulticast (Ipv6Address addr) const;
177 
182  virtual bool IsPointToPoint (void) const;
183 
188  virtual bool IsBridge (void) const;
189 
190  virtual bool Send (Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber);
191 
192  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
193 
194  virtual Ptr<Node> GetNode (void) const;
195  virtual void SetNode (Ptr<Node> node);
196 
197  virtual bool NeedsArp (void) const;
198 
201 
202  virtual bool SupportsSendFrom (void) const;
203 
212 
219 
220 private:
221  EmuNetDevice (const EmuNetDevice &);
223 
224  virtual void DoDispose (void);
225 
231  void CreateSocket (void);
232 
236  std::string FindCreator (std::string creatorName);
237 
241  void StartDevice (void);
242 
246  void StopDevice (void);
247 
251  void ReadThread (void);
252 
256  void ForwardUp (uint8_t *buf, uint32_t len);
257 
264  void AddHeader (Ptr<Packet> p, uint16_t protocolNumber);
265 
274  bool ProcessHeader (Ptr<Packet> p, uint16_t& param);
275 
281  bool TransmitStart (Ptr<Packet> p);
282 
283  void NotifyLinkUp (void);
284 
293 
301 
309 
318 
327 
336 
344 
352 
360 
368 
376 
384 
391 
411 
431 
436 
441 
444 
445  int32_t m_sock;
446 
448 
453 
458 
463 
468 
472  uint32_t m_ifIndex;
473 
478  int32_t m_sll_ifindex;
479 
486 
491  bool m_linkUp;
492 
498 
504 
509 
513  std::string m_deviceName;
514 
518  uint8_t *m_packetBuffer;
519 
520  /*
521  * a copy of the node id so the read thread doesn't have to GetNode() in
522  * in order to find the node ID. Thread unsafe reference counting in
523  * multithreaded apps is not a good thing.
524  */
525  uint32_t m_nodeId;
526 
530 };
531 
532 } // namespace ns3
533 
534 #endif /* EMU_NET_DEVICE_H */
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
void StopDevice(void)
Tear down the device.
virtual ~EmuNetDevice()
Destroy a EmuNetDevice.
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
SystemMutex m_pendingReadMutex
virtual bool NeedsArp(void) const
Ptr< Queue > m_queue
The Queue which this EmuNetDevice uses as a packet source.
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
A trace source that emulates a promiscuous mode protocol sniffer connected to the device...
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
std::string FindCreator(std::string creatorName)
Figure out where the raw socket creation process lives on the system.
std::string m_deviceName
The unix/linux name of the underlying device (e.g., eth0)
EmuNetDevice & operator=(const EmuNetDevice &)
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
uint8_t * m_packetBuffer
A 64K buffer to hold packet data while it is being sent.
virtual bool IsBroadcast(void) const
forward calls to a chain of CallbackAn ns3::TracedCallback has almost exactly the same API as a norma...
EncapsulationMode
Enumeration of the types of packets supported in the class.
virtual bool SupportsSendFrom(void) const
bool m_isBroadcast
Flag indicating whether or not the underlying net device supports broadcast.
Ptr< Queue > GetQueue(void) const
Get a copy of the attached Queue.
void StartDevice(void)
Spin up the device.
TracedCallback< Ptr< const Packet > > m_snifferTrace
A trace source that emulates a non-promiscuous protocol sniffer connected to the device.
virtual void SetNode(Ptr< Node > node)
TracedCallback< Ptr< const Packet > > m_phyTxDropTrace
The trace source fired when the phy layer drops a packet as it tries to transmit it.
bool TransmitStart(Ptr< Packet > p)
Start Sending a Packet Down the Wire.
void ReadThread(void)
Loop to read and process packets.
TracedCallback< Ptr< const Packet > > m_macRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
virtual void SetIfIndex(const uint32_t index)
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_phyTxBeginTrace
The trace source fired when a packet begins the transmission process on the medium.
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...
Ptr< Node > m_node
The Node to which this device is attached.
void Start(Time tStart)
Set a start time for the device.
static TypeId GetTypeId(void)
a polymophic address class
Definition: address.h:86
virtual uint32_t GetIfIndex(void) const
virtual Address GetAddress(void) const
Class for representing data rates.
Definition: data-rate.h:71
TracedCallback< Ptr< const Packet > > m_phyRxBeginTrace
The trace source fired when a packet begins the reception process from the medium.
bool m_linkUp
Flag indicating whether or not the link is up.
void SetQueue(Ptr< Queue > queue)
Attach a queue to the EmuNetDevice.
bool ProcessHeader(Ptr< Packet > p, uint16_t &param)
Removes, from a packet of data, all headers and trailers that relate to the protocol implemented by t...
virtual uint16_t GetMtu(void) const
virtual Ptr< Node > GetNode(void) const
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
The trace source fired for packets successfully received by the device but which are dropped before b...
virtual Ptr< Channel > GetChannel(void) const
Ptr< SystemThread > m_readThread
EmuNetDevice::EncapsulationMode GetEncapsulationMode(void) const
Get the encapsulation mode of this device.
EmuNetDevice()
Construct a EmuNetDevice.
void SetEncapsulationMode(EmuNetDevice::EncapsulationMode mode)
Set the encapsulation mode of this device.
void Stop(Time tStop)
Set a stop time for the device.
NetDevice::ReceiveCallback m_rxCallback
The callback used to notify higher layers that a packet has been received.
TracedCallback< Ptr< const Packet > > m_phyRxTrace
The trace source fired when a packet ends the reception process from the medium.
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
uint32_t m_ifIndex
The ns-3 interface index (in the sense of net device index) that has been assigned to this network de...
TracedCallback m_linkChangeCallbacks
Callbacks to fire if the link changes state (up or down).
TracedCallback< Ptr< const Packet > > m_phyTxEndTrace
The trace source fired when a packet ends the transmission process on the medium. ...
void ForwardUp(uint8_t *buf, uint32_t len)
Method to handle received packets.
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
virtual bool IsPointToPoint(void) const
Is this a point to point link?
void NotifyLinkUp(void)
Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address &, const Address &, enum PacketType > PromiscReceiveCallback
Definition: net-device.h:315
bool m_isMulticast
Flag indicating whether or not the underlying net device supports multicast.
an EUI-48 address
Definition: mac48-address.h:41
virtual void SetAddress(Address address)
Set the address of this interface.
A class which provides a relatively platform-independent Mutual Exclusion thread synchronization prim...
Definition: system-mutex.h:50
virtual bool IsLinkUp(void) const
802.2 LLC/SNAP Packet
void SetDataRate(DataRate bps)
Set the Data Rate used for transmission of packets.
TracedCallback< Ptr< const Packet > > m_phyRxEndTrace
The trace source fired when a packet begins the reception process from the medium.
uint32_t m_pendingReadCount
Describes an IPv6 address.
Definition: ipv6-address.h:46
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
Time m_tStart
Time to start spinning up the device.
int32_t m_sll_ifindex
The Unix interface index that we got from the system and which corresponds to the interface (e...
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition...
uint32_t m_maxPendingReads
an identifier for simulation events.
Definition: event-id.h:46
Time m_tStop
Time to start tearing down the device.
Network layer to device interface.
Definition: net-device.h:75
void AddHeader(Ptr< Packet > p, uint16_t protocolNumber)
Adds the necessary headers and trailers to a packet of data in order to respect the protocol implemen...
void CreateSocket(void)
Call out to a separate process running as suid root in order to get a raw socket. ...
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Encapsulation mode not set.
DIX II / Ethernet II packet.
virtual void AddLinkChangeCallback(Callback< void > callback)
tuple address
Definition: first.py:37
A Device for an Emu Network Link.
EncapsulationMode m_encapMode
The type of packet that should be created by the AddHeader function and that should be processed by t...
virtual bool SetMtu(const uint16_t mtu)
a unique identifier for an interface.
Definition: type-id.h:49
virtual Address GetBroadcast(void) const
virtual bool IsMulticast(void) const
virtual bool IsBridge(void) const
Is this a bridge?
Mac48Address m_address
The MAC address which has been assigned to this device.
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received.