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;
43 
59 class CsmaNetDevice : public NetDevice
60 {
61 public:
62 
67  static TypeId GetTypeId (void);
68 
74  DIX,
75  LLC,
76  };
77 
83  CsmaNetDevice ();
84 
90  virtual ~CsmaNetDevice ();
91 
99  void SetInterframeGap (Time t);
100 
112  void SetBackoffParams (Time slotTime, uint32_t minSlots, uint32_t maxSlots,
113  uint32_t maxRetries, uint32_t ceiling);
114 
125  bool Attach (Ptr<CsmaChannel> ch);
126 
138  void SetQueue (Ptr<Queue<Packet> > queue);
139 
145  Ptr<Queue<Packet> > GetQueue (void) const;
146 
157 
170  void Receive (Ptr<Packet> p, Ptr<CsmaNetDevice> sender);
171 
177  bool IsSendEnabled (void);
178 
184  void SetSendEnable (bool enable);
185 
191  bool IsReceiveEnabled (void);
192 
198  void SetReceiveEnable (bool enable);
199 
207 
214 
215  //
216  // The following methods are inherited from NetDevice base class.
217  //
218  virtual void SetIfIndex (const uint32_t index);
219  virtual uint32_t GetIfIndex (void) const;
220  virtual Ptr<Channel> GetChannel (void) const;
221  virtual bool SetMtu (const uint16_t mtu);
222  virtual uint16_t GetMtu (void) const;
223  virtual void SetAddress (Address address);
224  virtual Address GetAddress (void) const;
225  virtual bool IsLinkUp (void) const;
226  virtual void AddLinkChangeCallback (Callback<void> callback);
227  virtual bool IsBroadcast (void) const;
228  virtual Address GetBroadcast (void) const;
229  virtual bool IsMulticast (void) const;
230 
253  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
254 
259  virtual bool IsPointToPoint (void) const;
260 
265  virtual bool IsBridge (void) const;
266 
274  virtual bool Send (Ptr<Packet> packet, const Address& dest,
275  uint16_t protocolNumber);
276 
285  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest,
286  uint16_t protocolNumber);
287 
293  virtual Ptr<Node> GetNode (void) const;
294 
300  virtual void SetNode (Ptr<Node> node);
301 
308  virtual bool NeedsArp (void) const;
309 
317 
325  virtual Address GetMulticast (Ipv6Address addr) const;
326 
327 
329  virtual bool SupportsSendFrom (void) const;
330 
339  int64_t AssignStreams (int64_t stream);
340 
341 protected:
346  virtual void DoDispose (void);
347 
358  void AddHeader (Ptr<Packet> p, Mac48Address source, Mac48Address dest, uint16_t protocolNumber);
359 
360  virtual void DoInitialize (void);
361  virtual void NotifyNewAggregate (void);
362 
363 private:
364 
372 
378  CsmaNetDevice (const CsmaNetDevice &o);
379 
385  void Init (bool sendEnable, bool receiveEnable);
386 
404  void TransmitStart ();
405 
422  void TransmitCompleteEvent (void);
423 
438  void TransmitReadyEvent (void);
439 
447  void TransmitAbort (void);
448 
452  void NotifyLinkUp (void);
453 
459  uint32_t m_deviceId;
460 
465 
470 
475  {
478  GAP,
480  };
481 
487 
494 
501 
508 
515 
522 
529 
538 
545 
553 
561 
570 
579 
588 
597 
605 
613 
621 
629 
637 
644 
664 
684 
689 
694 
699 
704 
709 
714  uint32_t m_ifIndex;
715 
720  bool m_linkUp;
721 
726 
730  static const uint16_t DEFAULT_MTU = 1500;
731 
738  uint32_t m_mtu;
739 };
740 
741 } // namespace ns3
742 
743 #endif /* CSMA_NET_DEVICE_H */
uint32_t m_ifIndex
The interface index (really net evice index) that has been assigned to this network device...
TracedCallback< Ptr< const Packet > > m_phyRxBeginTrace
The trace source fired when a packet begins the reception process from the medium.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
TracedCallback< Ptr< const Packet > > m_phyTxBeginTrace
The trace source fired when a packet begins the transmission process on the medium.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
TxMachineState m_txMachineState
The state of the Net Device transmit state machine.
void SetReceiveEnable(bool enable)
Enable or disable the receive side of the network device.
void SetEncapsulationMode(CsmaNetDevice::EncapsulationMode mode)
Set the encapsulation mode of this device.
CsmaNetDevice::EncapsulationMode GetEncapsulationMode(void)
Get the encapsulation mode of this device.
Ptr< Queue< Packet > > GetQueue(void) const
Get a copy of the attached Queue.
void TransmitReadyEvent(void)
Cause the Transmitter to Become Ready to Send Another Packet.
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...
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
CsmaNetDevice()
Construct a CsmaNetDevice.
TracedCallback< Ptr< const Packet > > m_phyTxEndTrace
The trace source fired when a packet ends the transmission process on the medium. ...
void Receive(Ptr< Packet > p, Ptr< CsmaNetDevice > sender)
Receive a packet from a connected CsmaChannel.
Forward calls to a chain of Callback.
TracedCallback< Ptr< const Packet > > m_macRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
TracedCallback< Ptr< const Packet > > m_phyRxEndTrace
The trace source fired when a packet ends the reception process from the medium.
Ptr< Packet > m_currentPkt
Next packet that will be transmitted (if transmitter is not currently transmitting) or packet that is...
void SetReceiveErrorModel(Ptr< ErrorModel > em)
Attach a receive ErrorModel to the CsmaNetDevice.
The transmitter is busy transmitting a packet.
void TransmitAbort(void)
Aborts the transmission of the current packet.
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.
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
The trace source fired for packets successfully received by the device but dropped before being forwa...
802.2 LLC/SNAP Packet
virtual Address GetBroadcast(void) const
General error model that can be used to corrupt packets.
Definition: error-model.h:115
virtual void SetIfIndex(const uint32_t index)
EncapsulationMode
Enumeration of the types of packets supported in the class.
virtual ~CsmaNetDevice()
Destroy a CsmaNetDevice.
virtual bool NeedsArp(void) const
Does this device need to use the address resolution protocol?
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
A trace source that emulates a promiscuous mode protocol sniffer connected to the device...
a polymophic address class
Definition: address.h:90
Template class for packet Queues.
The backoff class is used for calculating backoff times when many net devices can write to the same c...
Definition: backoff.h:37
Class for representing data rates.
Definition: data-rate.h:88
TracedCallback m_linkChangeCallbacks
List of callbacks to fire if the link changes state (up or down).
The transmitter is waiting for the channel to be free.
TracedCallback< Ptr< const Packet > > m_macTxBackoffTrace
The trace source fired when the mac layer is forced to begin the backoff process for a packet...
DataRate m_bps
The data rate that the Net Device uses to simulate packet transmission timing.
virtual bool IsLinkUp(void) const
TracedCallback< Ptr< const Packet > > m_snifferTrace
A trace source that emulates a non-promiscuous protocol sniffer connected to the device.
static TypeId GetTypeId(void)
Get the type ID.
virtual void NotifyNewAggregate(void)
Notify all Objects aggregated to this one of a new Object being aggregated.
void TransmitCompleteEvent(void)
Stop Sending a Packet Down the Wire and Begin the Interframe Gap.
bool IsReceiveEnabled(void)
Is the receive side of the network device enabled?
uint32_t m_deviceId
Device ID returned by the attached functions.
virtual Ptr< Node > GetNode(void) const
Get the node to which this device is attached.
bool m_sendEnable
Enable net device to send packets.
void NotifyLinkUp(void)
Notify any interested parties that the link has come up.
TxMachineState
Enumeration of the states of the transmit machine of the net device.
Network device transmission queue interface.
void SetInterframeGap(Time t)
Set the interframe gap used to separate packets.
virtual Address GetAddress(void) const
virtual uint32_t GetIfIndex(void) const
virtual uint16_t GetMtu(void) const
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
TracedCallback< Ptr< const Packet > > m_phyTxDropTrace
The trace source fired when the phy layer drops a packet as it tries to transmit it.
Csma Channel.
Definition: csma-channel.h:90
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:343
A Device for a Csma Network Link.
bool m_receiveEnable
Enable net device to receive packets.
Ptr< ErrorModel > m_receiveErrorModel
Error model for receive packet events.
Ptr< NetDeviceQueueInterface > m_queueInterface
NetDevice queue interface.
Ptr< CsmaChannel > m_channel
The CsmaChannel to which this CsmaNetDevice has been attached.
Ptr< Queue< Packet > > m_queue
The Queue which this CsmaNetDevice uses as a packet source.
static const uint16_t DEFAULT_MTU
Default Maximum Transmission Unit (MTU) for the CsmaNetDevice.
an EUI-48 address
Definition: mac48-address.h:43
Time m_tInterframeGap
The interframe gap that the Net Device uses insert time between packet transmission.
virtual Ptr< Channel > GetChannel(void) const
virtual bool IsBridge(void) const
Is this a bridge?
virtual bool SetMtu(const uint16_t mtu)
virtual bool SupportsSendFrom(void) const
CsmaNetDevice & operator=(const CsmaNetDevice &o)
Operator = is declared but not implemented.
void Init(bool sendEnable, bool receiveEnable)
Initialization function used during object construction.
Encapsulation mode not set.
bool m_linkUp
Flag indicating whether or not the link is up.
Mac48Address m_address
The MAC address which has been assigned to this device.
Describes an IPv6 address.
Definition: ipv6-address.h:48
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
EncapsulationMode m_encapMode
The type of packet that should be created by the AddHeader function and that should be processed by t...
NetDevice::ReceiveCallback m_rxCallback
The callback used to notify higher layers that a packet has been received.
uint32_t m_mtu
The Maximum Transmission Unit.
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...
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...
Backoff m_backoff
Holds the backoff parameters and is used to calculate the next backoff time to use when the channel i...
Network layer to device interface.
Definition: net-device.h:95
The transmitter is ready to begin transmission of a packet.
void SetSendEnable(bool enable)
Enable or disable the send side of the network device.
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
Set the callback to be used to notify higher layers when a packet has been received.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
NetDevice::PromiscReceiveCallback m_promiscRxCallback
The callback used to notify higher layers that a packet has been received in promiscuous mode...
virtual void DoInitialize(void)
Initialize() implementation.
virtual void SetAddress(Address address)
Set the address of this interface.
void SetQueue(Ptr< Queue< Packet > > queue)
Attach a queue to the CsmaNetDevice.
bool IsSendEnabled(void)
Is the send side of the network device enabled?
void TransmitStart()
Start Sending a Packet Down the Wire.
tuple address
Definition: first.py:37
Ptr< Node > m_node
The Node to which this device is attached.
virtual void AddLinkChangeCallback(Callback< void > callback)
bool Attach(Ptr< CsmaChannel > ch)
Attach the device to a channel.
virtual void SetNode(Ptr< Node > node)
Set the node to which this device is being attached.
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received.
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
Start sending a packet down the channel.
virtual bool IsMulticast(void) const
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
virtual void DoDispose(void)
Perform any object release functionality required to break reference cycles in reference counted obje...
a unique identifier for an interface.
Definition: type-id.h:58
virtual bool IsBroadcast(void) const
DIX II / Ethernet II packet.
virtual bool IsPointToPoint(void) const
Is this a point to point link?
The transmitter is in the interframe gap time.
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition...