A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
119 };
120 
128 std::ostream& operator<< (std::ostream& os, const QueueItem &item);
129 
143 class NetDeviceQueue : public SimpleRefCount<NetDeviceQueue>
144 {
145 public:
146  NetDeviceQueue ();
147  virtual ~NetDeviceQueue();
148 
153  virtual void Start (void);
154 
159  virtual void Stop (void);
160 
166  virtual void Wake (void);
167 
175  bool IsStopped (void) const;
176 
179 
190  virtual void SetWakeCallback (WakeCallback cb);
191 
196  virtual bool HasWakeCallbackSet (void) const;
197 
198 private:
199  bool m_stopped;
201 };
202 
203 
220 {
221 public:
226  static TypeId GetTypeId (void);
227 
234  virtual ~NetDeviceQueueInterface ();
235 
244  Ptr<NetDeviceQueue> GetTxQueue (uint8_t i) const;
245 
250  uint8_t GetTxQueuesN (void) const;
251 
261  void SetTxQueuesN (uint8_t numTxQueues);
262 
265 
274 
285  uint8_t GetSelectedQueue (Ptr<QueueItem> item) const;
286 
287 protected:
291  virtual void DoDispose (void);
292 
293 private:
294  std::vector< Ptr<NetDeviceQueue> > m_txQueuesVector;
296 };
297 
298 
345 class NetDevice : public Object
346 {
347 public:
352  static TypeId GetTypeId (void);
353  virtual ~NetDevice();
354 
358  virtual void SetIfIndex (const uint32_t index) = 0;
362  virtual uint32_t GetIfIndex (void) const = 0;
363 
364 
372  virtual Ptr<Channel> GetChannel (void) const = 0;
373 
378  virtual void SetAddress (Address address) = 0;
379 
383  virtual Address GetAddress (void) const = 0;
384 
391  virtual bool SetMtu (const uint16_t mtu) = 0;
398  virtual uint16_t GetMtu (void) const = 0;
402  virtual bool IsLinkUp (void) const = 0;
406  typedef void (* LinkChangeTracedCallback) (void);
415  virtual void AddLinkChangeCallback (Callback<void> callback) = 0;
420  virtual bool IsBroadcast (void) const = 0;
428  virtual Address GetBroadcast (void) const = 0;
429 
433  virtual bool IsMulticast (void) const = 0;
434 
462  virtual Address GetMulticast (Ipv4Address multicastGroup) const = 0;
463 
471  virtual Address GetMulticast (Ipv6Address addr) const = 0;
472 
478  virtual bool IsBridge (void) const = 0;
479 
485  virtual bool IsPointToPoint (void) const = 0;
498  virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) = 0;
512  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber) = 0;
521  virtual Ptr<Node> GetNode (void) const = 0;
522 
528  virtual void SetNode (Ptr<Node> node) = 0;
529 
536  virtual bool NeedsArp (void) const = 0;
537 
538 
547  {
556  };
557 
569 
577  virtual void SetReceiveCallback (ReceiveCallback cb) = 0;
578 
579 
594 
606 
610  virtual bool SupportsSendFrom (void) const = 0;
611 
612 };
613 
614 } // namespace ns3
615 
616 #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
Packet addressed to someone else.
Definition: net-device.h:554
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:568
virtual ~QueueItem()
Definition: net-device.cc:37
Forward calls to a chain of Callback.
virtual void SetNode(Ptr< Node > node)=0
virtual Ptr< Node > GetNode(void) const =0
WakeCallback m_wakeCallback
Wake callback.
Definition: net-device.h:200
Ptr< Packet > m_packet
The packet contained in the queue item.
Definition: net-device.h:118
void SetSelectQueueCallback(SelectQueueCallback cb)
Set the select queue callback.
Definition: net-device.cc:188
virtual bool IsBroadcast(void) const =0
virtual ~NetDevice()
Definition: net-device.cc:214
a polymophic address class
Definition: address.h:90
void(* LinkChangeTracedCallback)(void)
TracedCallback signature for link changed event.
Definition: net-device.h:406
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)=0
Callback< void > WakeCallback
Callback invoked by netdevices to wake upper layers.
Definition: net-device.h:178
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:264
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:205
uint8_t GetSelectedQueue(Ptr< QueueItem > item) const
Get the id of the transmission queue selected for the given packet.
Definition: net-device.cc:194
static TypeId GetTypeId(void)
Get the type ID.
Definition: net-device.cc:124
SelectQueueCallback m_selectQueueCallback
Select queue callback.
Definition: net-device.h:295
Network device transmission queue interface.
Definition: net-device.h:219
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
Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address &, const Address &, enum PacketType > PromiscReceiveCallback
Definition: net-device.h:593
virtual void Stop(void)
Called by the device to stop this (hardware) transmission queue.
Definition: net-device.cc:92
std::vector< Ptr< NetDeviceQueue > > m_txQueuesVector
Device transmission queues.
Definition: net-device.h:294
uint8_t GetTxQueuesN(void) const
Get the number of device transmission queues.
Definition: net-device.cc:153
virtual void DoDispose(void)
Dispose of the object.
Definition: net-device.cc:159
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)=0
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
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
Packet addressed oo us.
Definition: net-device.h:548
Network layer to device interface.
Definition: net-device.h:345
virtual bool IsPointToPoint(void) const =0
Return true if the net device is on a point-to-point link.
Ptr< NetDeviceQueue > GetTxQueue(uint8_t i) const
Get the i-th transmission queue of the device.
Definition: net-device.cc:146
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.
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:546
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:199
Packet addressed to multicast group.
Definition: net-device.h:552
Network device transmission queue.
Definition: net-device.h:143
A template-based reference counting class.
a unique identifier for an interface.
Definition: type-id.h:58
Packet addressed to all.
Definition: net-device.h:550
virtual Address GetAddress(void) const =0
void SetTxQueuesN(uint8_t numTxQueues)
Set the number of device transmission queues.
Definition: net-device.cc:167
Ptr< Packet > GetPacket(void) const
Definition: net-device.cc:44