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 */