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 <string.h>
23 #include "ns3/address.h"
24 #include "ns3/net-device.h"
25 #include "ns3/node.h"
26 #include "ns3/callback.h"
27 #include "ns3/packet.h"
28 #include "ns3/traced-callback.h"
29 #include "ns3/event-id.h"
30 #include "ns3/nstime.h"
31 #include "ns3/data-rate.h"
32 #include "ns3/ptr.h"
33 #include "ns3/mac48-address.h"
34 #include "ns3/system-thread.h"
35 #include "ns3/system-mutex.h"
36 
37 namespace ns3 {
38 
39 class Queue;
40 
51 class EmuNetDevice : public NetDevice
52 {
53 public:
54  static TypeId GetTypeId (void);
55 
61  DIX,
62  LLC,
63  };
64 
70  EmuNetDevice ();
71 
77  virtual ~EmuNetDevice ();
78 
85  void SetDataRate (DataRate bps);
86 
92  void Start (Time tStart);
93 
99  void Stop (Time tStop);
100 
111  void SetQueue (Ptr<Queue> queue);
112 
118  Ptr<Queue> GetQueue (void) const;
119 
120 
121 //
122 // Pure virtual methods inherited from NetDevice we must implement.
123 //
124  virtual void SetIfIndex (const uint32_t index);
125  virtual uint32_t GetIfIndex (void) const;
126 
127  virtual Ptr<Channel> GetChannel (void) const;
128 
129  virtual void SetAddress (Address address);
130  virtual Address GetAddress (void) const;
131 
132  virtual bool SetMtu (const uint16_t mtu);
133  virtual uint16_t GetMtu (void) const;
134 
135  virtual bool IsLinkUp (void) const;
136 
137  virtual void AddLinkChangeCallback (Callback<void> callback);
138 
139  virtual bool IsBroadcast (void) const;
140  virtual Address GetBroadcast (void) const;
141 
142  virtual bool IsMulticast (void) const;
143 
166  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
167 
175  virtual Address GetMulticast (Ipv6Address addr) const;
176 
181  virtual bool IsPointToPoint (void) const;
182 
187  virtual bool IsBridge (void) const;
188 
189  virtual bool Send (Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber);
190 
191  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
192 
193  virtual Ptr<Node> GetNode (void) const;
194  virtual void SetNode (Ptr<Node> node);
195 
196  virtual bool NeedsArp (void) const;
197 
200 
201  virtual bool SupportsSendFrom (void) const;
202 
211 
218 
219 private:
220  EmuNetDevice (const EmuNetDevice &);
222 
223  virtual void DoDispose (void);
224 
230  void CreateSocket (void);
231 
235  std::string FindCreator (std::string creatorName);
236 
240  void StartDevice (void);
241 
245  void StopDevice (void);
246 
250  void ReadThread (void);
251 
255  void ForwardUp (uint8_t *buf, uint32_t len);
256 
263  void AddHeader (Ptr<Packet> p, uint16_t protocolNumber);
264 
273  bool ProcessHeader (Ptr<Packet> p, uint16_t& param);
274 
280  bool TransmitStart (Ptr<Packet> p);
281 
282  void NotifyLinkUp (void);
283 
292 
300 
308 
317 
326 
335 
343 
351 
359 
367 
375 
383 
390 
410 
430 
435 
440 
443 
444  int32_t m_sock;
445 
447 
452 
457 
462 
467 
471  uint32_t m_ifIndex;
472 
477  int32_t m_sll_ifindex;
478 
485 
490  bool m_linkUp;
491 
497 
503 
508 
512  std::string m_deviceName;
513 
517  uint8_t *m_packetBuffer;
518 
519  /*
520  * a copy of the node id so the read thread doesn't have to GetNode() in
521  * in order to find the node ID. Thread unsafe reference counting in
522  * multithreaded apps is not a good thing.
523  */
524  uint32_t m_nodeId;
525 
529 };
530 
531 } // namespace ns3
532 
533 #endif /* EMU_NET_DEVICE_H */