A Discrete-Event Network Simulator
API
csma-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) 2007 Emmanuelle Laprise
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: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca
19  */
20 
21 #ifndef CSMA_NET_DEVICE_H
22 #define CSMA_NET_DEVICE_H
23 
24 #include <cstring>
25 #include "ns3/node.h"
26 #include "ns3/backoff.h"
27 #include "ns3/address.h"
28 #include "ns3/net-device.h"
29 #include "ns3/callback.h"
30 #include "ns3/packet.h"
31 #include "ns3/traced-callback.h"
32 #include "ns3/nstime.h"
33 #include "ns3/data-rate.h"
34 #include "ns3/ptr.h"
35 #include "ns3/mac48-address.h"
36 
37 namespace ns3 {
38 
39 template <typename Item> class Queue;
40 class CsmaChannel;
41 class ErrorModel;
42 
58 class CsmaNetDevice : public NetDevice
59 {
60 public:
61 
66  static TypeId GetTypeId (void);
67 
73  DIX,
74  LLC,
75  };
76 
82  CsmaNetDevice ();
83 
89  virtual ~CsmaNetDevice ();
90 
98  void SetInterframeGap (Time t);
99 
111  void SetBackoffParams (Time slotTime, uint32_t minSlots, uint32_t maxSlots,
112  uint32_t maxRetries, uint32_t ceiling);
113 
124  bool Attach (Ptr<CsmaChannel> ch);
125 
137  void SetQueue (Ptr<Queue<Packet> > queue);
138 
144  Ptr<Queue<Packet> > GetQueue (void) const;
145 
156 
169  void Receive (Ptr<Packet> p, Ptr<CsmaNetDevice> sender);
170 
176  bool IsSendEnabled (void);
177 
183  void SetSendEnable (bool enable);
184 
190  bool IsReceiveEnabled (void);
191 
197  void SetReceiveEnable (bool enable);
198 
206 
213 
214  //
215  // The following methods are inherited from NetDevice base class.
216  //
217  virtual void SetIfIndex (const uint32_t index);
218  virtual uint32_t GetIfIndex (void) const;
219  virtual Ptr<Channel> GetChannel (void) const;
220  virtual bool SetMtu (const uint16_t mtu);
221  virtual uint16_t GetMtu (void) const;
222  virtual void SetAddress (Address address);
223  virtual Address GetAddress (void) const;
224  virtual bool IsLinkUp (void) const;
225  virtual void AddLinkChangeCallback (Callback<void> callback);
226  virtual bool IsBroadcast (void) const;
227  virtual Address GetBroadcast (void) const;
228  virtual bool IsMulticast (void) const;
229 
252  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
253 
258  virtual bool IsPointToPoint (void) const;
259 
264  virtual bool IsBridge (void) const;
265 
273  virtual bool Send (Ptr<Packet> packet, const Address& dest,
274  uint16_t protocolNumber);
275 
284  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest,
285  uint16_t protocolNumber);
286 
292  virtual Ptr<Node> GetNode (void) const;
293 
299  virtual void SetNode (Ptr<Node> node);
300 
307  virtual bool NeedsArp (void) const;
308 
316 
324  virtual Address GetMulticast (Ipv6Address addr) const;
325 
326 
328  virtual bool SupportsSendFrom (void) const;
329 
338  int64_t AssignStreams (int64_t stream);
339 
340 protected:
345  virtual void DoDispose (void);
346 
357  void AddHeader (Ptr<Packet> p, Mac48Address source, Mac48Address dest, uint16_t protocolNumber);
358 
359 private:
360 
368 
375 
381  void Init (bool sendEnable, bool receiveEnable);
382 
400  void TransmitStart ();
401 
418  void TransmitCompleteEvent (void);
419 
434  void TransmitReadyEvent (void);
435 
443  void TransmitAbort (void);
444 
448  void NotifyLinkUp (void);
449 
455  uint32_t m_deviceId;
456 
461 
466 
471  {
474  GAP,
475  BACKOFF
476  };
477 
483 
490 
497 
504 
511 
518 
525 
534 
541 
549 
557 
566 
575 
584 
593 
601 
609 
617 
625 
633 
640 
660 
680 
685 
690 
695 
700 
705  uint32_t m_ifIndex;
706 
711  bool m_linkUp;
712 
717 
721  static const uint16_t DEFAULT_MTU = 1500;
722 
729  uint32_t m_mtu;
730 };
731 
732 } // namespace ns3
733 
734 #endif /* CSMA_NET_DEVICE_H */
ns3::CsmaNetDevice::m_bps
DataRate m_bps
The data rate that the Net Device uses to simulate packet transmission timing.
Definition: csma-net-device.h:496
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
ns3::CsmaNetDevice::TransmitStart
void TransmitStart()
Start Sending a Packet Down the Wire.
Definition: csma-net-device.cc:440
ns3::CsmaNetDevice::EncapsulationMode
EncapsulationMode
Enumeration of the types of packets supported in the class.
Definition: csma-net-device.h:71
ns3::CsmaNetDevice::m_channel
Ptr< CsmaChannel > m_channel
The CsmaChannel to which this CsmaNetDevice has been attached.
Definition: csma-net-device.h:524
ns3::CsmaNetDevice::m_address
Mac48Address m_address
The MAC address which has been assigned to this device.
Definition: csma-net-device.h:689
ns3::CsmaNetDevice::~CsmaNetDevice
virtual ~CsmaNetDevice()
Destroy a CsmaNetDevice.
Definition: csma-net-device.cc:208
ns3::CsmaNetDevice::m_queue
Ptr< Queue< Packet > > m_queue
The Queue which this CsmaNetDevice uses as a packet source.
Definition: csma-net-device.h:533
ns3::CsmaNetDevice::CsmaNetDevice
CsmaNetDevice(const CsmaNetDevice &o)
Copy constructor is declared but not implemented.
ns3::CsmaNetDevice::AssignStreams
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: csma-net-device.cc:1052
ns3::Callback< void >
ns3::CsmaNetDevice::m_snifferTrace
TracedCallback< Ptr< const Packet > > m_snifferTrace
A trace source that emulates a non-promiscuous protocol sniffer connected to the device.
Definition: csma-net-device.h:659
ns3::CsmaNetDevice::SupportsSendFrom
virtual bool SupportsSendFrom(void) const
Definition: csma-net-device.cc:1045
ns3::CsmaNetDevice::m_phyTxDropTrace
TracedCallback< Ptr< const Packet > > m_phyTxDropTrace
The trace source fired when the phy layer drops a packet as it tries to transmit it.
Definition: csma-net-device.h:616
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::CsmaNetDevice::m_sendEnable
bool m_sendEnable
Enable net device to send packets.
Definition: csma-net-device.h:460
ns3::CsmaNetDevice::m_macTxTrace
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition,...
Definition: csma-net-device.h:548
ns3::CsmaNetDevice::BACKOFF
@ BACKOFF
The transmitter is waiting for the channel to be free.
Definition: csma-net-device.h:475
ns3::CsmaNetDevice::m_phyRxDropTrace
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received.
Definition: csma-net-device.h:639
ns3::CsmaNetDevice::m_encapMode
EncapsulationMode m_encapMode
The type of packet that should be created by the AddHeader function and that should be processed by t...
Definition: csma-net-device.h:489
ns3::CsmaNetDevice::m_ifIndex
uint32_t m_ifIndex
The interface index (really net evice index) that has been assigned to this network device.
Definition: csma-net-device.h:705
ns3::CsmaNetDevice::Send
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
Start sending a packet down the channel.
Definition: csma-net-device.cc:940
ns3::CsmaNetDevice::m_backoff
Backoff m_backoff
Holds the backoff parameters and is used to calculate the next backoff time to use when the channel i...
Definition: csma-net-device.h:510
ns3::CsmaNetDevice::m_txMachineState
TxMachineState m_txMachineState
The state of the Net Device transmit state machine.
Definition: csma-net-device.h:482
ns3::CsmaNetDevice::SetReceiveEnable
void SetReceiveEnable(bool enable)
Enable or disable the receive side of the network device.
Definition: csma-net-device.cc:270
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
ns3::CsmaNetDevice::SetMtu
virtual bool SetMtu(const uint16_t mtu)
Definition: csma-net-device.cc:243
ns3::Ipv6Address
Describes an IPv6 address.
Definition: ipv6-address.h:50
ns3::CsmaNetDevice::SetNode
virtual void SetNode(Ptr< Node > node)
Set the node to which this device is being attached.
Definition: csma-net-device.cc:1008
ns3::CsmaNetDevice::IsLinkUp
virtual bool IsLinkUp(void) const
Definition: csma-net-device.cc:874
ns3::CsmaNetDevice::GetIfIndex
virtual uint32_t GetIfIndex(void) const
Definition: csma-net-device.cc:846
ns3::Mac48Address
an EUI-48 address
Definition: mac48-address.h:44
ns3::CsmaNetDevice::m_deviceId
uint32_t m_deviceId
Device ID returned by the attached functions.
Definition: csma-net-device.h:455
ns3::CsmaNetDevice::GetMulticast
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
Definition: csma-net-device.cc:909
ns3::CsmaNetDevice::GetChannel
virtual Ptr< Channel > GetChannel(void) const
Definition: csma-net-device.cc:853
ns3::CsmaNetDevice::IsSendEnabled
bool IsSendEnabled(void)
Is the send side of the network device enabled?
Definition: csma-net-device.cc:277
ns3::CsmaNetDevice::NotifyLinkUp
void NotifyLinkUp(void)
Notify any interested parties that the link has come up.
Definition: csma-net-device.cc:831
ns3::CsmaNetDevice::TxMachineState
TxMachineState
Enumeration of the states of the transmit machine of the net device.
Definition: csma-net-device.h:471
ns3::CsmaNetDevice::Attach
bool Attach(Ptr< CsmaChannel > ch)
Attach the device to a channel.
Definition: csma-net-device.cc:647
ns3::CsmaNetDevice::m_receiveErrorModel
Ptr< ErrorModel > m_receiveErrorModel
Error model for receive packet events.
Definition: csma-net-device.h:540
ns3::CsmaNetDevice::IsPointToPoint
virtual bool IsPointToPoint(void) const
Is this a point to point link?
Definition: csma-net-device.cc:926
ns3::CsmaNetDevice::operator=
CsmaNetDevice & operator=(const CsmaNetDevice &o)
Operator = is declared but not implemented.
ns3::CsmaNetDevice::GetEncapsulationMode
CsmaNetDevice::EncapsulationMode GetEncapsulationMode(void)
Get the encapsulation mode of this device.
Definition: csma-net-device.cc:236
ns3::CsmaNetDevice::BUSY
@ BUSY
The transmitter is busy transmitting a packet.
Definition: csma-net-device.h:473
ns3::CsmaNetDevice::m_macPromiscRxTrace
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
Definition: csma-net-device.h:565
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::DataRate
Class for representing data rates.
Definition: data-rate.h:89
ns3::CsmaNetDevice::SetReceiveErrorModel
void SetReceiveErrorModel(Ptr< ErrorModel > em)
Attach a receive ErrorModel to the CsmaNetDevice.
Definition: csma-net-device.cc:680
ns3::CsmaNetDevice::m_macTxDropTrace
TracedCallback< Ptr< const Packet > > m_macTxDropTrace
The trace source fired when packets coming into the "top" of the device at the L3/L2 transition are d...
Definition: csma-net-device.h:556
ns3::CsmaNetDevice::SetIfIndex
virtual void SetIfIndex(const uint32_t index)
Definition: csma-net-device.cc:839
ns3::Backoff
The backoff class is used for calculating backoff times when many net devices can write to the same c...
Definition: backoff.h:37
ns3::Address
a polymophic address class
Definition: address.h:91
ns3::CsmaNetDevice::SetSendEnable
void SetSendEnable(bool enable)
Enable or disable the send side of the network device.
Definition: csma-net-device.cc:263
ns3::CsmaNetDevice::IsBridge
virtual bool IsBridge(void) const
Is this a bridge?
Definition: csma-net-device.cc:933
ns3::NetDevice::PromiscReceiveCallback
Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address &, const Address &, enum PacketType > PromiscReceiveCallback
Definition: net-device.h:343
ns3::CsmaNetDevice::m_promiscRxCallback
NetDevice::PromiscReceiveCallback m_promiscRxCallback
The callback used to notify higher layers that a packet has been received in promiscuous mode.
Definition: csma-net-device.h:699
ns3::CsmaNetDevice::SetQueue
void SetQueue(Ptr< Queue< Packet > > queue)
Attach a queue to the CsmaNetDevice.
Definition: csma-net-device.cc:673
ns3::CsmaNetDevice::SetEncapsulationMode
void SetEncapsulationMode(CsmaNetDevice::EncapsulationMode mode)
Set the encapsulation mode of this device.
Definition: csma-net-device.cc:225
ns3::CsmaNetDevice::GetBroadcast
virtual Address GetBroadcast(void) const
Definition: csma-net-device.cc:895
ns3::CsmaNetDevice::SendFrom
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
Start sending a packet down the channel, with MAC spoofing.
Definition: csma-net-device.cc:947
ns3::CsmaNetDevice::m_node
Ptr< Node > m_node
The Node to which this device is attached.
Definition: csma-net-device.h:684
first.address
address
Definition: first.py:44
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::CsmaNetDevice::READY
@ READY
The transmitter is ready to begin transmission of a packet.
Definition: csma-net-device.h:472
ns3::CsmaNetDevice::ILLEGAL
@ ILLEGAL
Encapsulation mode not set.
Definition: csma-net-device.h:72
ns3::CsmaNetDevice::m_mtu
uint32_t m_mtu
The Maximum Transmission Unit.
Definition: csma-net-device.h:729
ns3::CsmaNetDevice::SetBackoffParams
void SetBackoffParams(Time slotTime, uint32_t minSlots, uint32_t maxSlots, uint32_t maxRetries, uint32_t ceiling)
Set the backoff parameters used to determine the wait to retry transmitting a packet when the channel...
Definition: csma-net-device.cc:298
ns3::CsmaNetDevice::SetAddress
virtual void SetAddress(Address address)
Set the address of this interface.
Definition: csma-net-device.cc:860
Queue< Packet >
ns3::CsmaNetDevice::m_macTxBackoffTrace
TracedCallback< Ptr< const Packet > > m_macTxBackoffTrace
The trace source fired when the mac layer is forced to begin the backoff process for a packet.
Definition: csma-net-device.h:592
ns3::CsmaNetDevice::m_phyTxBeginTrace
TracedCallback< Ptr< const Packet > > m_phyTxBeginTrace
The trace source fired when a packet begins the transmission process on the medium.
Definition: csma-net-device.h:600
ns3::CsmaNetDevice::GetNode
virtual Ptr< Node > GetNode(void) const
Get the node to which this device is attached.
Definition: csma-net-device.cc:1001
ns3::CsmaNetDevice::NeedsArp
virtual bool NeedsArp(void) const
Does this device need to use the address resolution protocol?
Definition: csma-net-device.cc:1016
ns3::CsmaNetDevice::DoDispose
virtual void DoDispose(void)
Perform any object release functionality required to break reference cycles in reference counted obje...
Definition: csma-net-device.cc:215
ns3::CsmaNetDevice::AddHeader
void AddHeader(Ptr< Packet > p, Mac48Address source, Mac48Address dest, uint16_t protocolNumber)
Adds the necessary headers and trailers to a packet of data in order to respect the packet type.
Definition: csma-net-device.cc:309
ns3::CsmaNetDevice::m_phyTxEndTrace
TracedCallback< Ptr< const Packet > > m_phyTxEndTrace
The trace source fired when a packet ends the transmission process on the medium.
Definition: csma-net-device.h:608
ns3::CsmaNetDevice::LLC
@ LLC
802.2 LLC/SNAP Packet
Definition: csma-net-device.h:74
ns3::CsmaNetDevice::CsmaNetDevice
CsmaNetDevice()
Construct a CsmaNetDevice.
Definition: csma-net-device.cc:186
ns3::CsmaNetDevice::Receive
void Receive(Ptr< Packet > p, Ptr< CsmaNetDevice > sender)
Receive a packet from a connected CsmaChannel.
Definition: csma-net-device.cc:687
ns3::CsmaNetDevice::GetQueue
Ptr< Queue< Packet > > GetQueue(void) const
Get a copy of the attached Queue.
Definition: csma-net-device.cc:824
ns3::CsmaNetDevice::TransmitCompleteEvent
void TransmitCompleteEvent(void)
Stop Sending a Packet Down the Wire and Begin the Interframe Gap.
Definition: csma-net-device.cc:578
ns3::CsmaNetDevice::AddLinkChangeCallback
virtual void AddLinkChangeCallback(Callback< void > callback)
Definition: csma-net-device.cc:881
ns3::CsmaNetDevice::m_currentPkt
Ptr< Packet > m_currentPkt
Next packet that will be transmitted (if transmitter is not currently transmitting) or packet that is...
Definition: csma-net-device.h:517
ns3::CsmaNetDevice::m_receiveEnable
bool m_receiveEnable
Enable net device to receive packets.
Definition: csma-net-device.h:465
ns3::CsmaNetDevice::GetAddress
virtual Address GetAddress(void) const
Definition: csma-net-device.cc:867
ns3::CsmaNetDevice::m_phyRxBeginTrace
TracedCallback< Ptr< const Packet > > m_phyRxBeginTrace
The trace source fired when a packet begins the reception process from the medium.
Definition: csma-net-device.h:624
ns3::CsmaNetDevice::m_macRxDropTrace
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
The trace source fired for packets successfully received by the device but dropped before being forwa...
Definition: csma-net-device.h:583
ns3::CsmaNetDevice::DIX
@ DIX
DIX II / Ethernet II packet.
Definition: csma-net-device.h:73
ns3::CsmaNetDevice::IsBroadcast
virtual bool IsBroadcast(void) const
Definition: csma-net-device.cc:888
ns3::CsmaNetDevice
A Device for a Csma Network Link.
Definition: csma-net-device.h:59
ns3::CsmaNetDevice::SetInterframeGap
void SetInterframeGap(Time t)
Set the interframe gap used to separate packets.
Definition: csma-net-device.cc:291
ns3::TracedCallback
Forward calls to a chain of Callback.
Definition: traced-callback.h:53
ns3::CsmaNetDevice::TransmitReadyEvent
void TransmitReadyEvent(void)
Cause the Transmitter to Become Ready to Send Another Packet.
Definition: csma-net-device.cc:610
ns3::CsmaNetDevice::SetPromiscReceiveCallback
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
Definition: csma-net-device.cc:1038
ns3::CsmaNetDevice::m_rxCallback
NetDevice::ReceiveCallback m_rxCallback
The callback used to notify higher layers that a packet has been received.
Definition: csma-net-device.h:694
ns3::CsmaNetDevice::m_macRxTrace
TracedCallback< Ptr< const Packet > > m_macRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
Definition: csma-net-device.h:574
ns3::CsmaNetDevice::GAP
@ GAP
The transmitter is in the interframe gap time.
Definition: csma-net-device.h:474
ns3::CsmaNetDevice::m_phyRxEndTrace
TracedCallback< Ptr< const Packet > > m_phyRxEndTrace
The trace source fired when a packet ends the reception process from the medium.
Definition: csma-net-device.h:632
ns3::CsmaNetDevice::m_linkChangeCallbacks
TracedCallback m_linkChangeCallbacks
List of callbacks to fire if the link changes state (up or down).
Definition: csma-net-device.h:716
ns3::CsmaNetDevice::TransmitAbort
void TransmitAbort(void)
Aborts the transmission of the current packet.
Definition: csma-net-device.cc:533
ns3::CsmaNetDevice::SetReceiveCallback
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
Set the callback to be used to notify higher layers when a packet has been received.
Definition: csma-net-device.cc:1023
ns3::CsmaNetDevice::GetMtu
virtual uint16_t GetMtu(void) const
Definition: csma-net-device.cc:255
ns3::CsmaNetDevice::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: csma-net-device.cc:43
ns3::CsmaNetDevice::Init
void Init(bool sendEnable, bool receiveEnable)
Initialization function used during object construction.
ns3::CsmaNetDevice::m_tInterframeGap
Time m_tInterframeGap
The interframe gap that the Net Device uses insert time between packet transmission.
Definition: csma-net-device.h:503
ns3::CsmaNetDevice::DEFAULT_MTU
static const uint16_t DEFAULT_MTU
Default Maximum Transmission Unit (MTU) for the CsmaNetDevice.
Definition: csma-net-device.h:721
ns3::CsmaNetDevice::IsMulticast
virtual bool IsMulticast(void) const
Definition: csma-net-device.cc:902
ns3::CsmaNetDevice::IsReceiveEnabled
bool IsReceiveEnabled(void)
Is the receive side of the network device enabled?
Definition: csma-net-device.cc:284
ns3::CsmaNetDevice::m_promiscSnifferTrace
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
A trace source that emulates a promiscuous mode protocol sniffer connected to the device.
Definition: csma-net-device.h:679
ns3::CsmaNetDevice::m_linkUp
bool m_linkUp
Flag indicating whether or not the link is up.
Definition: csma-net-device.h:711
ns3::NetDevice
Network layer to device interface.
Definition: net-device.h:96