A Discrete-Event Network Simulator
API
csma-net-device.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 Emmanuelle Laprise
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca
18  */
19 
20 #ifndef CSMA_NET_DEVICE_H
21 #define CSMA_NET_DEVICE_H
22 
23 #include "ns3/address.h"
24 #include "ns3/backoff.h"
25 #include "ns3/callback.h"
26 #include "ns3/data-rate.h"
27 #include "ns3/mac48-address.h"
28 #include "ns3/net-device.h"
29 #include "ns3/node.h"
30 #include "ns3/nstime.h"
31 #include "ns3/packet.h"
32 #include "ns3/ptr.h"
33 #include "ns3/queue-fwd.h"
34 #include "ns3/traced-callback.h"
35 
36 #include <cstring>
37 
38 namespace ns3
39 {
40 
41 class CsmaChannel;
42 class ErrorModel;
43 
60 class CsmaNetDevice : public NetDevice
61 {
62  public:
67  static TypeId GetTypeId();
68 
73  {
75  DIX,
76  LLC,
77  };
78 
84  CsmaNetDevice();
85 
91  ~CsmaNetDevice() override;
92 
100  void SetInterframeGap(Time t);
101 
113  void SetBackoffParams(Time slotTime,
114  uint32_t minSlots,
115  uint32_t maxSlots,
116  uint32_t maxRetries,
117  uint32_t ceiling);
118 
129  bool Attach(Ptr<CsmaChannel> ch);
130 
142  void SetQueue(Ptr<Queue<Packet>> queue);
143 
149  Ptr<Queue<Packet>> GetQueue() const;
150 
161 
174  void Receive(Ptr<Packet> p, Ptr<CsmaNetDevice> sender);
175 
181  bool IsSendEnabled() const;
182 
188  void SetSendEnable(bool enable);
189 
195  bool IsReceiveEnabled() const;
196 
202  void SetReceiveEnable(bool enable);
203 
211 
218 
219  //
220  // The following methods are inherited from NetDevice base class.
221  //
222  void SetIfIndex(const uint32_t index) override;
223  uint32_t GetIfIndex() const override;
224  Ptr<Channel> GetChannel() const override;
225  bool SetMtu(const uint16_t mtu) override;
226  uint16_t GetMtu() const override;
227  void SetAddress(Address address) override;
228  Address GetAddress() const override;
229  bool IsLinkUp() const override;
230  void AddLinkChangeCallback(Callback<void> callback) override;
231  bool IsBroadcast() const override;
232  Address GetBroadcast() const override;
233  bool IsMulticast() const override;
234 
257  Address GetMulticast(Ipv4Address multicastGroup) const override;
258 
263  bool IsPointToPoint() const override;
264 
269  bool IsBridge() const override;
270 
278  bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) override;
279 
288  bool SendFrom(Ptr<Packet> packet,
289  const Address& source,
290  const Address& dest,
291  uint16_t protocolNumber) override;
292 
298  Ptr<Node> GetNode() const override;
299 
305  void SetNode(Ptr<Node> node) override;
306 
313  bool NeedsArp() const override;
314 
322 
330 
338  Address GetMulticast(Ipv6Address addr) const override;
339 
341  bool SupportsSendFrom() const override;
342 
351  int64_t AssignStreams(int64_t stream);
352 
353  protected:
358  void DoDispose() override;
359 
370  void AddHeader(Ptr<Packet> p, Mac48Address source, Mac48Address dest, uint16_t protocolNumber);
371 
372  private:
380 
387 
393  void Init(bool sendEnable, bool receiveEnable);
394 
412  void TransmitStart();
413 
430  void TransmitCompleteEvent();
431 
446  void TransmitReadyEvent();
447 
455  void TransmitAbort();
456 
460  void NotifyLinkUp();
461 
467  uint32_t m_deviceId;
468 
473 
478 
483  {
486  GAP,
487  BACKOFF
488  };
489 
495 
502 
509 
516 
523 
530 
537 
546 
553 
561 
569 
578 
587 
596 
605 
613 
621 
629 
637 
645 
652 
672 
692 
697 
702 
707 
712 
718 
723  uint32_t m_ifIndex;
724 
729  bool m_linkUp;
730 
735 
739  static const uint16_t DEFAULT_MTU = 1500;
740 
747  uint32_t m_mtu;
748 };
749 
750 } // namespace ns3
751 
752 #endif /* CSMA_NET_DEVICE_H */
a polymophic address class
Definition: address.h:100
The backoff class is used for calculating backoff times when many net devices can write to the same c...
Definition: backoff.h:39
A Device for a Csma Network Link.
void SetInterframeGap(Time t)
Set the interframe gap used to separate packets.
NetDevice::PromiscReceiveCallback m_openFlowRxCallback
The OpenFlow receive callback.
Ptr< Queue< Packet > > GetQueue() const
Get a copy of the attached Queue.
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
The trace source fired for packets successfully received by the device but dropped before being forwa...
Ptr< Node > GetNode() const override
Get the node to which this device is attached.
EncapsulationMode
Enumeration of the types of packets supported in the class.
@ ILLEGAL
Encapsulation mode not set.
@ DIX
DIX II / Ethernet II packet.
@ LLC
802.2 LLC/SNAP Packet
NetDevice::ReceiveCallback m_rxCallback
The callback used to notify higher layers that a packet has been received.
TracedCallback< Ptr< const Packet > > m_macTxBackoffTrace
The trace source fired when the mac layer is forced to begin the backoff process for a packet.
void SetReceiveEnable(bool enable)
Enable or disable the receive side of the network device.
void SetQueue(Ptr< Queue< Packet >> queue)
Attach a queue to the CsmaNetDevice.
Backoff m_backoff
Holds the backoff parameters and is used to calculate the next backoff time to use when the channel i...
DataRate m_bps
The data rate that the Net Device uses to simulate packet transmission timing.
void DoDispose() override
Perform any object release functionality required to break reference cycles in reference counted obje...
~CsmaNetDevice() override
Destroy a CsmaNetDevice.
CsmaNetDevice & operator=(const CsmaNetDevice &o)
Operator = is declared but not implemented.
bool SetMtu(const uint16_t mtu) override
void TransmitAbort()
Aborts the transmission of the current packet.
EncapsulationMode m_encapMode
The type of packet that should be created by the AddHeader function and that should be processed by t...
bool NeedsArp() const override
Does this device need to use the address resolution protocol?
void SetOpenFlowReceiveCallback(NetDevice::PromiscReceiveCallback cb)
Set the callback used to notify the OpenFlow when a packet has been received by this device.
TracedCallback< Ptr< const Packet > > m_macRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
void TransmitStart()
Start Sending a Packet Down the Wire.
void SetIfIndex(const uint32_t index) override
TxMachineState
Enumeration of the states of the transmit machine of the net device.
@ BACKOFF
The transmitter is waiting for the channel to be free.
@ READY
The transmitter is ready to begin transmission of a packet.
@ BUSY
The transmitter is busy transmitting a packet.
@ GAP
The transmitter is in the interframe gap time.
Ptr< Queue< Packet > > m_queue
The Queue which this CsmaNetDevice uses as a packet source.
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
uint32_t m_mtu
The Maximum Transmission Unit.
bool SupportsSendFrom() const override
NetDevice::PromiscReceiveCallback m_promiscRxCallback
The callback used to notify higher layers that a packet has been received in promiscuous mode.
CsmaNetDevice()
Construct a CsmaNetDevice.
void SetPromiscReceiveCallback(PromiscReceiveCallback cb) override
Address GetBroadcast() const override
static TypeId GetTypeId()
Get the type ID.
void Init(bool sendEnable, bool receiveEnable)
Initialization function used during object construction.
bool IsPointToPoint() const override
Is this a point to point link?
Ptr< CsmaChannel > m_channel
The CsmaChannel to which this CsmaNetDevice has been attached.
bool Attach(Ptr< CsmaChannel > ch)
Attach the device to a channel.
bool IsBridge() const override
Is this a bridge?
void TransmitCompleteEvent()
Stop Sending a Packet Down the Wire and Begin the Interframe Gap.
bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber) override
Start sending a packet down the channel, with MAC spoofing.
void Receive(Ptr< Packet > p, Ptr< CsmaNetDevice > sender)
Receive a packet from a connected CsmaChannel.
bool IsMulticast() const override
TracedCallback m_linkChangeCallbacks
List of callbacks to fire if the link changes state (up or down).
TracedCallback< Ptr< const Packet > > m_phyTxBeginTrace
The trace source fired when a packet begins the transmission process on the medium.
CsmaNetDevice::EncapsulationMode GetEncapsulationMode()
Get the encapsulation mode of this device.
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.
uint16_t GetMtu() const override
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
CsmaNetDevice(const CsmaNetDevice &o)
Copy constructor is declared but not implemented.
Ptr< Channel > GetChannel() const override
void NotifyLinkUp()
Notify any interested parties that the link has come up.
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...
Ptr< Packet > m_currentPkt
Next packet that will be transmitted (if transmitter is not currently transmitting) or packet that is...
TracedCallback< Ptr< const Packet > > m_snifferTrace
A trace source that emulates a non-promiscuous protocol sniffer connected to the device.
TracedCallback< Ptr< const Packet > > m_phyTxEndTrace
The trace source fired when a packet ends the transmission process on the medium.
uint32_t m_deviceId
Device ID returned by the attached functions.
bool m_receiveEnable
Enable net device to receive packets.
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received.
Address GetMulticast(Ipv4Address multicastGroup) const override
Make and return a MAC multicast address using the provided multicast group.
Ptr< Node > m_node
The Node to which this device is attached.
void SetReceiveErrorModel(Ptr< ErrorModel > em)
Attach a receive ErrorModel to the CsmaNetDevice.
void SetSendEnable(bool enable)
Enable or disable the send side of the network device.
bool IsLinkUp() const override
void TransmitReadyEvent()
Cause the Transmitter to Become Ready to Send Another Packet.
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
A trace source that emulates a promiscuous mode protocol sniffer connected to the device.
uint32_t GetIfIndex() const override
bool IsBroadcast() const override
static const uint16_t DEFAULT_MTU
Default Maximum Transmission Unit (MTU) for the CsmaNetDevice.
void SetEncapsulationMode(CsmaNetDevice::EncapsulationMode mode)
Set the encapsulation mode of this device.
TracedCallback< Ptr< const Packet > > m_phyRxBeginTrace
The trace source fired when a packet begins the reception process from the medium.
bool m_sendEnable
Enable net device to send packets.
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...
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
Start sending a packet down the channel.
bool IsSendEnabled() const
Is the send side of the network device enabled?
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition,...
void SetReceiveCallback(NetDevice::ReceiveCallback cb) override
Set the callback to be used to notify higher layers when a packet has been received.
TracedCallback< Ptr< const Packet > > m_phyTxDropTrace
The trace source fired when the phy layer drops a packet as it tries to transmit it.
Address GetAddress() const override
void AddLinkChangeCallback(Callback< void > callback) override
void SetNode(Ptr< Node > node) override
Set the node to which this device is being attached.
void SetAddress(Address address) override
Set the address of this interface.
Mac48Address m_address
The MAC address which has been assigned to this device.
Time m_tInterframeGap
The interframe gap that the Net Device uses insert time between packet transmission.
Ptr< ErrorModel > m_receiveErrorModel
Error model for receive packet events.
TxMachineState m_txMachineState
The state of the Net Device transmit state machine.
uint32_t m_ifIndex
The interface index (really net evice index) that has been assigned to this network device.
bool IsReceiveEnabled() const
Is the receive side of the network device enabled?
bool m_linkUp
Flag indicating whether or not the link is up.
TracedCallback< Ptr< const Packet > > m_phyRxEndTrace
The trace source fired when a packet ends the reception process from the medium.
Class for representing data rates.
Definition: data-rate.h:90
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:43
Describes an IPv6 address.
Definition: ipv6-address.h:50
an EUI-48 address
Definition: mac48-address.h:46
Network layer to device interface.
Definition: net-device.h:98
Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address &, const Address &, enum PacketType > PromiscReceiveCallback
Definition: net-device.h:352
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:60
address
Definition: first.py:40
Every class exported by the ns3 library is enclosed in the ns3 namespace.