A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
emu-net-device.h
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 &);
222  EmuNetDevice & operator= (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 
442  EventId m_startEvent;
443  EventId m_stopEvent;
444 
445  int32_t m_sock;
446 
447  Ptr<SystemThread> m_readThread;
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 
527  uint32_t m_maxPendingReads;
528  uint32_t m_pendingReadCount;
529  SystemMutex m_pendingReadMutex;
530 };
531 
532 } // namespace ns3
533 
534 #endif /* EMU_NET_DEVICE_H */
keep track of time unit.
Definition: nstime.h:149
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
virtual bool NeedsArp(void) const
Ptr< Queue > m_queue
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
std::string FindCreator(std::string creatorName)
std::string m_deviceName
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
uint8_t * m_packetBuffer
virtual bool IsBroadcast(void) const
forward calls to a chain of CallbackAn ns3::TracedCallback has almost exactly the same API as a norma...
virtual bool SupportsSendFrom(void) const
Ptr< Queue > GetQueue(void) const
void StartDevice(void)
TracedCallback< Ptr< const Packet > > m_snifferTrace
virtual void SetNode(Ptr< Node > node)
TracedCallback< Ptr< const Packet > > m_phyTxDropTrace
bool TransmitStart(Ptr< Packet > p)
TracedCallback< Ptr< const Packet > > m_macRxTrace
virtual void SetIfIndex(const uint32_t index)
NetDevice::PromiscReceiveCallback m_promiscRxCallback
TracedCallback< Ptr< const Packet > > m_phyTxBeginTrace
TracedCallback< Ptr< const Packet > > m_macTxDropTrace
Ptr< Node > m_node
void Start(Time tStart)
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
void SetQueue(Ptr< Queue > queue)
bool ProcessHeader(Ptr< Packet > p, uint16_t &param)
virtual uint16_t GetMtu(void) const
virtual Ptr< Node > GetNode(void) const
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
virtual Ptr< Channel > GetChannel(void) const
EmuNetDevice::EncapsulationMode GetEncapsulationMode(void) const
void SetEncapsulationMode(EmuNetDevice::EncapsulationMode mode)
void Stop(Time tStop)
NetDevice::ReceiveCallback m_rxCallback
TracedCallback< Ptr< const Packet > > m_phyRxTrace
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
TracedCallback m_linkChangeCallbacks
TracedCallback< Ptr< const Packet > > m_phyTxEndTrace
void ForwardUp(uint8_t *buf, uint32_t len)
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
virtual bool IsPointToPoint(void) const
Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address &, const Address &, enum PacketType > PromiscReceiveCallback
Definition: net-device.h:315
an EUI-48 address
Definition: mac48-address.h:41
virtual void SetAddress(Address address)
A class which provides a relatively platform-independent Mutual Exclusion thread synchronization prim...
Definition: system-mutex.h:50
virtual bool IsLinkUp(void) const
void SetDataRate(DataRate bps)
TracedCallback< Ptr< const Packet > > m_phyRxEndTrace
Describes an IPv6 address.
Definition: ipv6-address.h:44
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
TracedCallback< Ptr< const Packet > > m_macTxTrace
an identifier for simulation events.
Definition: event-id.h:46
Network layer to device interface.
Definition: net-device.h:75
void AddHeader(Ptr< Packet > p, uint16_t protocolNumber)
void CreateSocket(void)
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
virtual void DoDispose(void)
virtual void AddLinkChangeCallback(Callback< void > callback)
A Device for an Emu Network Link.
EncapsulationMode m_encapMode
virtual bool SetMtu(const uint16_t mtu)
a unique identifier for an interface.
Definition: type-id.h:44
virtual Address GetBroadcast(void) const
virtual bool IsMulticast(void) const
virtual bool IsBridge(void) const
Mac48Address m_address
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace