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 
55 class QueueItem : public SimpleRefCount<QueueItem>
56 {
57 public:
63 
64  virtual ~QueueItem ();
65 
69  Ptr<Packet> GetPacket (void) const;
70 
79  virtual uint32_t GetPacketSize (void) const;
80 
85  virtual void Print (std::ostream &os) const;
86 
92  typedef void (* TracedCallback) (Ptr<const QueueItem> item);
93 
94 private:
100  QueueItem ();
106  QueueItem (const QueueItem &);
113  QueueItem &operator = (const QueueItem &);
114 
116 };
117 
125 std::ostream& operator<< (std::ostream& os, const QueueItem &item);
126 
140 class NetDeviceQueue : public SimpleRefCount<NetDeviceQueue>
141 {
142 public:
143  NetDeviceQueue ();
144  virtual ~NetDeviceQueue();
145 
150  virtual void Start (void);
151 
156  virtual void Stop (void);
157 
163  virtual void Wake (void);
164 
172  bool IsStopped (void) const;
173 
176 
187  virtual void SetWakeCallback (WakeCallback cb);
188 
193  virtual bool HasWakeCallbackSet (void) const;
194 
195 private:
196  bool m_stopped;
197  WakeCallback m_wakeCallback;
198 };
199 
200 
217 {
218 public:
223  static TypeId GetTypeId (void);
224 
231  virtual ~NetDeviceQueueInterface ();
232 
239  Ptr<NetDeviceQueue> GetTxQueue (uint8_t i) const;
240 
245  uint8_t GetTxQueuesN (void) const;
246 
256  void SetTxQueuesN (uint8_t numTxQueues);
257 
260 
268  void SetSelectQueueCallback (SelectQueueCallback cb);
269 
278  uint8_t GetSelectedQueue (Ptr<QueueItem> item) const;
279 
284  bool IsQueueDiscInstalled (void) const;
285 
290  void SetQueueDiscInstalled (bool installed);
291 
292 protected:
296  virtual void DoDispose (void);
297 
298 private:
299  std::vector< Ptr<NetDeviceQueue> > m_txQueuesVector;
300  SelectQueueCallback m_selectQueueCallback;
302 };
303 
304 
337 class NetDevice : public Object
338 {
339 public:
344  static TypeId GetTypeId (void);
345  virtual ~NetDevice();
346 
350  virtual void SetIfIndex (const uint32_t index) = 0;
354  virtual uint32_t GetIfIndex (void) const = 0;
355 
356 
364  virtual Ptr<Channel> GetChannel (void) const = 0;
365 
370  virtual void SetAddress (Address address) = 0;
371 
375  virtual Address GetAddress (void) const = 0;
376 
383  virtual bool SetMtu (const uint16_t mtu) = 0;
390  virtual uint16_t GetMtu (void) const = 0;
394  virtual bool IsLinkUp (void) const = 0;
398  typedef void (* LinkChangeTracedCallback) (void);
407  virtual void AddLinkChangeCallback (Callback<void> callback) = 0;
412  virtual bool IsBroadcast (void) const = 0;
420  virtual Address GetBroadcast (void) const = 0;
421 
425  virtual bool IsMulticast (void) const = 0;
426 
454  virtual Address GetMulticast (Ipv4Address multicastGroup) const = 0;
455 
463  virtual Address GetMulticast (Ipv6Address addr) const = 0;
464 
470  virtual bool IsBridge (void) const = 0;
471 
477  virtual bool IsPointToPoint (void) const = 0;
490  virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) = 0;
504  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber) = 0;
513  virtual Ptr<Node> GetNode (void) const = 0;
514 
520  virtual void SetNode (Ptr<Node> node) = 0;
521 
528  virtual bool NeedsArp (void) const = 0;
529 
530 
539  {
548  };
549 
561 
569  virtual void SetReceiveCallback (ReceiveCallback cb) = 0;
570 
571 
584  typedef Callback< bool, Ptr<NetDevice>, Ptr<const Packet>, uint16_t,
586 
597  virtual void SetPromiscReceiveCallback (PromiscReceiveCallback cb) = 0;
598 
602  virtual bool SupportsSendFrom (void) const = 0;
603 
604 };
605 
606 } // namespace ns3
607 
608 #endif /* NET_DEVICE_H */
virtual void SetIfIndex(const uint32_t index)=0
virtual bool HasWakeCallbackSet(void) const
Check whether a wake callback has been set on this device queue.
Definition: net-device.cc:116
Base class to represent items of packet Queues.
Definition: net-device.h:55
virtual Address GetBroadcast(void) const =0
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:560
virtual ~QueueItem()
Definition: net-device.cc:37
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:538
virtual Ptr< Node > GetNode(void) const =0
WakeCallback m_wakeCallback
Wake callback.
Definition: net-device.h:197
Ptr< Packet > m_packet
Definition: net-device.h:115
void SetSelectQueueCallback(SelectQueueCallback cb)
Set the select queue callback.
Definition: net-device.cc:189
Packet addressed to multicast group.
Definition: net-device.h:544
Packet addressed oo us.
Definition: net-device.h:540
virtual bool IsBroadcast(void) const =0
virtual ~NetDevice()
Definition: net-device.cc:229
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:175
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:259
virtual void Start(void)
Called by the device to start this (hardware) transmission queue.
Definition: net-device.cc:86
virtual bool SupportsSendFrom(void) const =0
bool IsStopped(void) const
Get the status of the device transmission queue.
Definition: net-device.cc:80
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:50
static TypeId GetTypeId(void)
Get the type ID.
Definition: net-device.cc:220
uint8_t GetSelectedQueue(Ptr< QueueItem > item) const
Get the id of the transmission queue selected for the given packet.
Definition: net-device.cc:195
void(* LinkChangeTracedCallback)(void)
TracedCallback signature for link changed event.
Definition: net-device.h:398
static TypeId GetTypeId(void)
Get the type ID.
Definition: net-device.cc:124
SelectQueueCallback m_selectQueueCallback
Select queue callback.
Definition: net-device.h:300
Network device transmission queue interface.
Definition: net-device.h:216
void SetQueueDiscInstalled(bool installed)
Set the member variable indicating whether a queue disc is installed or not.
Definition: net-device.cc:211
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
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:585
virtual void Stop(void)
Called by the device to stop this (hardware) transmission queue.
Definition: net-device.cc:92
Packet addressed to someone else.
Definition: net-device.h:546
std::vector< Ptr< NetDeviceQueue > > m_txQueuesVector
Device transmission queues.
Definition: net-device.h:299
uint8_t GetTxQueuesN(void) const
Get the number of device transmission queues.
Definition: net-device.cc:154
virtual void DoDispose(void)
Dispose of the object.
Definition: net-device.cc:160
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)=0
bool m_queueDiscInstalled
Boolean value indicating whether a queue disc is installed or not.
Definition: net-device.h:301
virtual Ptr< Channel > GetChannel(void) const =0
bool IsQueueDiscInstalled(void) const
Return true if a queue disc is installed on the device.
Definition: net-device.cc:205
QueueItem & operator=(const QueueItem &)
Assignment operator.
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)=0
virtual uint32_t GetIfIndex(void) const =0
virtual void Print(std::ostream &os) const
Print the item contents.
Definition: net-device.cc:57
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:133
virtual void Wake(void)
Called by the device to wake the queue disc associated with this (hardware) transmission queue...
Definition: net-device.cc:98
Network layer to device interface.
Definition: net-device.h:337
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:542
Ptr< NetDeviceQueue > GetTxQueue(uint8_t i) const
Get the i-th transmission queue of the device.
Definition: net-device.cc:147
virtual void SetWakeCallback(WakeCallback cb)
Set the wake callback.
Definition: net-device.cc:110
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:74
virtual bool IsLinkUp(void) const =0
virtual bool SetMtu(const uint16_t mtu)=0
bool m_stopped
Status of the transmission queue.
Definition: net-device.h:196
Network device transmission queue.
Definition: net-device.h:140
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.
Definition: net-device.cc:168
Ptr< Packet > GetPacket(void) const
Definition: net-device.cc:44