A Discrete-Event Network Simulator
API
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) 2005,2006 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  * Modified by Emmanuelle Laprise to remove dependence on LLC headers
20  * Modified by Stefano Avallone to add NetDeviceQueue and NetDeviceQueueInterface
21  */
22 #ifndef NET_DEVICE_H
23 #define NET_DEVICE_H
24 
25 #include <string>
26 #include <vector>
27 #include <stdint.h>
28 #include "ns3/callback.h"
29 #include "ns3/object.h"
30 #include "ns3/ptr.h"
31 #include "address.h"
32 #include "ns3/ipv4-address.h"
33 #include "ns3/ipv6-address.h"
34 
35 namespace ns3 {
36 
37 class Node;
38 class Channel;
39 class Packet;
40 class QueueLimits;
41 
56 class QueueItem : public SimpleRefCount<QueueItem>
57 {
58 public:
64 
65  virtual ~QueueItem ();
66 
70  Ptr<Packet> GetPacket (void) const;
71 
80  virtual uint32_t GetPacketSize (void) const;
81 
87  {
89  };
90 
98  virtual bool GetUint8Value (Uint8Values field, uint8_t &value) const;
99 
104  virtual void Print (std::ostream &os) const;
105 
111  typedef void (* TracedCallback) (Ptr<const QueueItem> item);
112 
113 private:
119  QueueItem ();
125  QueueItem (const QueueItem &);
132  QueueItem &operator = (const QueueItem &);
133 
138 };
139 
147 std::ostream& operator<< (std::ostream& os, const QueueItem &item);
148 
161 class NetDeviceQueue : public SimpleRefCount<NetDeviceQueue>
162 {
163 public:
164  NetDeviceQueue ();
165  virtual ~NetDeviceQueue();
166 
171  virtual void Start (void);
172 
177  virtual void Stop (void);
178 
184  virtual void Wake (void);
185 
193  bool IsStopped (void) const;
194 
197 
208  virtual void SetWakeCallback (WakeCallback cb);
209 
214  void NotifyQueuedBytes (uint32_t bytes);
215 
220  void NotifyTransmittedBytes (uint32_t bytes);
221 
225  void ResetQueueLimits ();
226 
232 
238 
239 private:
243  WakeCallback m_wakeCallback;
244 };
245 
246 
263 {
264 public:
269  static TypeId GetTypeId (void);
270 
277  virtual ~NetDeviceQueueInterface ();
278 
287  Ptr<NetDeviceQueue> GetTxQueue (uint8_t i) const;
288 
293  uint8_t GetNTxQueues (void) const;
294 
303  void SetTxQueuesN (uint8_t numTxQueues);
304 
311  void CreateTxQueues (void);
312 
315 
324  void SetSelectQueueCallback (SelectQueueCallback cb);
325 
333  SelectQueueCallback GetSelectQueueCallback (void) const;
334 
335 protected:
339  virtual void DoDispose (void);
340 
341 private:
342  std::vector< Ptr<NetDeviceQueue> > m_txQueuesVector;
343  SelectQueueCallback m_selectQueueCallback;
344  uint8_t m_numTxQueues;
345 };
346 
347 
405 class NetDevice : public Object
406 {
407 public:
412  static TypeId GetTypeId (void);
413  virtual ~NetDevice();
414 
418  virtual void SetIfIndex (const uint32_t index) = 0;
422  virtual uint32_t GetIfIndex (void) const = 0;
423 
424 
432  virtual Ptr<Channel> GetChannel (void) const = 0;
433 
438  virtual void SetAddress (Address address) = 0;
439 
443  virtual Address GetAddress (void) const = 0;
444 
451  virtual bool SetMtu (const uint16_t mtu) = 0;
458  virtual uint16_t GetMtu (void) const = 0;
462  virtual bool IsLinkUp (void) const = 0;
466  typedef void (* LinkChangeTracedCallback) (void);
475  virtual void AddLinkChangeCallback (Callback<void> callback) = 0;
480  virtual bool IsBroadcast (void) const = 0;
488  virtual Address GetBroadcast (void) const = 0;
489 
493  virtual bool IsMulticast (void) const = 0;
494 
522  virtual Address GetMulticast (Ipv4Address multicastGroup) const = 0;
523 
531  virtual Address GetMulticast (Ipv6Address addr) const = 0;
532 
538  virtual bool IsBridge (void) const = 0;
539 
545  virtual bool IsPointToPoint (void) const = 0;
558  virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) = 0;
572  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber) = 0;
581  virtual Ptr<Node> GetNode (void) const = 0;
582 
588  virtual void SetNode (Ptr<Node> node) = 0;
589 
596  virtual bool NeedsArp (void) const = 0;
597 
598 
607  {
616  };
617 
629 
637  virtual void SetReceiveCallback (ReceiveCallback cb) = 0;
638 
639 
652  typedef Callback< bool, Ptr<NetDevice>, Ptr<const Packet>, uint16_t,
654 
665  virtual void SetPromiscReceiveCallback (PromiscReceiveCallback cb) = 0;
666 
670  virtual bool SupportsSendFrom (void) const = 0;
671 
672 };
673 
674 } // namespace ns3
675 
676 #endif /* NET_DEVICE_H */
virtual void SetIfIndex(const uint32_t index)=0
Base class to represent items of packet Queues.
Definition: net-device.h:56
virtual Address GetBroadcast(void) const =0
uint8_t GetNTxQueues(void) const
Get the number of device transmission queues.
Definition: net-device.cc:216
virtual Address GetMulticast(Ipv4Address multicastGroup) const =0
Make and return a MAC multicast address using the provided multicast group.
QueueItem()
Default constructor.
Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address & > ReceiveCallback
Definition: net-device.h:628
virtual ~QueueItem()
Definition: net-device.cc:38
bool m_stoppedByDevice
True if the queue has been stopped by the device.
Definition: net-device.h:240
void NotifyQueuedBytes(uint32_t bytes)
Called by the netdevice to report the number of bytes queued to the device queue. ...
Definition: net-device.cc:124
bool m_stoppedByQueueLimits
True if the queue has been stopped by a queue limits object.
Definition: net-device.h:241
Forward calls to a chain of Callback.
virtual void SetNode(Ptr< Node > node)=0
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:606
virtual Ptr< Node > GetNode(void) const =0
WakeCallback m_wakeCallback
Wake callback.
Definition: net-device.h:243
Ptr< Packet > m_packet
The packet contained in the queue item.
Definition: net-device.h:137
void SetSelectQueueCallback(SelectQueueCallback cb)
Set the select queue callback.
Definition: net-device.cc:257
Packet addressed to multicast group.
Definition: net-device.h:612
Packet addressed oo us.
Definition: net-device.h:608
virtual bool IsBroadcast(void) const =0
virtual ~NetDevice()
Definition: net-device.cc:279
a polymophic address class
Definition: address.h:90
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)=0
Callback< void > WakeCallback
Callback invoked by netdevices to wake upper layers.
Definition: net-device.h:196
virtual void SetReceiveCallback(ReceiveCallback cb)=0
Callback< uint8_t, Ptr< QueueItem > > SelectQueueCallback
Callback invoked to determine the tx queue selected for a given packet.
Definition: net-device.h:314
virtual void Start(void)
Called by the device to start this device transmission queue.
Definition: net-device.cc:94
virtual bool SupportsSendFrom(void) const =0
bool IsStopped(void) const
Get the status of the device transmission queue.
Definition: net-device.cc:88
virtual uint16_t GetMtu(void) const =0
virtual bool IsMulticast(void) const =0
virtual uint32_t GetPacketSize(void) const
Use this method (instead of GetPacket ()->GetSize ()) to get the packet size.
Definition: net-device.cc:51
static TypeId GetTypeId(void)
Get the type ID.
Definition: net-device.cc:270
void(* LinkChangeTracedCallback)(void)
TracedCallback signature for link changed event.
Definition: net-device.h:466
SelectQueueCallback GetSelectQueueCallback(void) const
Get the select queue callback.
Definition: net-device.cc:263
static TypeId GetTypeId(void)
Get the type ID.
Definition: net-device.cc:188
SelectQueueCallback m_selectQueueCallback
Select queue callback.
Definition: net-device.h:343
Network device transmission queue interface.
Definition: net-device.h:262
uint8_t m_numTxQueues
Number of transmission queues to create.
Definition: net-device.h:344
virtual bool IsBridge(void) const =0
Return true if the net device is acting as a bridge.
virtual bool NeedsArp(void) const =0
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
void ResetQueueLimits()
Reset queue limits state.
Definition: net-device.cc:161
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address &, const Address &, enum PacketType > PromiscReceiveCallback
Definition: net-device.h:653
virtual void Stop(void)
Called by the device to stop this device transmission queue.
Definition: net-device.cc:100
Packet addressed to someone else.
Definition: net-device.h:614
std::vector< Ptr< NetDeviceQueue > > m_txQueuesVector
Device transmission queues.
Definition: net-device.h:342
virtual bool GetUint8Value(Uint8Values field, uint8_t &value) const
Retrieve the value of a given field from the packet, if present.
Definition: net-device.cc:58
virtual void DoDispose(void)
Dispose of the object.
Definition: net-device.cc:222
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)=0
void SetQueueLimits(Ptr< QueueLimits > ql)
Set queue limits to this queue.
Definition: net-device.cc:172
virtual Ptr< Channel > GetChannel(void) const =0
QueueItem & operator=(const QueueItem &)
Assignment operator.
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)=0
void NotifyTransmittedBytes(uint32_t bytes)
Called by the netdevice to report the number of bytes it is going to transmit.
Definition: net-device.cc:140
Uint8Values
1-byte fields of the packet whose value can be retrieved, if present
Definition: net-device.h:86
virtual uint32_t GetIfIndex(void) const =0
virtual void Print(std::ostream &os) const
Print the item contents.
Definition: net-device.cc:64
Ptr< QueueLimits > m_queueLimits
Queue limits object.
Definition: net-device.h:242
Describes an IPv6 address.
Definition: ipv6-address.h:48
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
NetDeviceQueueInterface()
Constructor.
Definition: net-device.cc:197
virtual void Wake(void)
Called by the device to wake the queue disc associated with this device transmission queue...
Definition: net-device.cc:106
Network layer to device interface.
Definition: net-device.h:405
virtual bool IsPointToPoint(void) const =0
Return true if the net device is on a point-to-point link.
Packet addressed to all.
Definition: net-device.h:610
Ptr< NetDeviceQueue > GetTxQueue(uint8_t i) const
Get the i-th transmission queue of the device.
Definition: net-device.cc:209
void CreateTxQueues(void)
Create the device transmission queues.
Definition: net-device.cc:242
Ptr< QueueLimits > GetQueueLimits()
Get queue limits to this queue.
Definition: net-device.cc:179
virtual void SetWakeCallback(WakeCallback cb)
Set the wake callback.
Definition: net-device.cc:118
A base class which provides memory management and object aggregation.
Definition: object.h:87
tuple address
Definition: first.py:37
virtual void SetAddress(Address address)=0
Set the address of this interface.
virtual void AddLinkChangeCallback(Callback< void > callback)=0
virtual ~NetDeviceQueue()
Definition: net-device.cc:82
virtual bool IsLinkUp(void) const =0
virtual bool SetMtu(const uint16_t mtu)=0
Network device transmission queue.
Definition: net-device.h:161
A template-based reference counting class.
a unique identifier for an interface.
Definition: type-id.h:58
virtual Address GetAddress(void) const =0
void SetTxQueuesN(uint8_t numTxQueues)
Set the number of device transmission queues to create.
Definition: net-device.cc:230
Ptr< Packet > GetPacket(void) const
Definition: net-device.cc:45