A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
uan-mac-cw.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Leonard Tracy <lentracy@gmail.com>
7 */
8
9#ifndef UAN_MAC_CW_H
10#define UAN_MAC_CW_H
11
12#include "uan-mac.h"
13#include "uan-phy.h"
14#include "uan-tx-mode.h"
15
16#include "ns3/mac8-address.h"
17#include "ns3/nstime.h"
18#include "ns3/random-variable-stream.h"
19#include "ns3/simulator.h"
20
21namespace ns3
22{
23
24/**
25 * \ingroup uan
26 *
27 * CW-MAC protocol, similar in idea to the 802.11 DCF with
28 * constant backoff window
29 *
30 * For more information on this MAC protocol, see:
31 * Parrish, N.; Tracy, L.; Roy, S.; Arabshahi, P.; Fox, W.,
32 * "System Design Considerations for Undersea Networks: Link and
33 * Multiple Access Protocols," Selected Areas in Communications,
34 * IEEE Journal on , vol.26, no.9, pp.1720-1730, December 2008
35 */
36class UanMacCw : public UanMac, public UanPhyListener
37{
38 public:
39 /** Default constructor */
40 UanMacCw();
41 /** Dummy destructor, DoDispose. */
42 ~UanMacCw() override;
43 /**
44 * Register this type.
45 * \return The TypeId.
46 */
47 static TypeId GetTypeId();
48
49 /**
50 * Set the contention window size.
51 *
52 * \param cw Contention window size.
53 */
54 virtual void SetCw(uint32_t cw);
55 /**
56 * Set the slot time duration.
57 *
58 * \param duration Slot time duration.
59 */
60 virtual void SetSlotTime(Time duration);
61 /**
62 * Get the contention window size.
63 *
64 * \return Contention window size.
65 */
66 virtual uint32_t GetCw();
67 /**
68 * Get the slot time duration.
69 *
70 * \return Slot time duration.
71 */
72 virtual Time GetSlotTime();
73
74 // Inherited methods from UanMac
75 bool Enqueue(Ptr<Packet> pkt, uint16_t protocolNumber, const Address& dest) override;
76 void SetForwardUpCb(Callback<void, Ptr<Packet>, uint16_t, const Mac8Address&> cb) override;
77 void AttachPhy(Ptr<UanPhy> phy) override;
78 void Clear() override;
79 int64_t AssignStreams(int64_t stream) override;
80
81 // Inherited methods from UanPhyListener
82 void NotifyRxStart() override;
83 void NotifyRxEndOk() override;
84 void NotifyRxEndError() override;
85 void NotifyCcaStart() override;
86 void NotifyCcaEnd() override;
87 void NotifyTxStart(Time duration) override;
88 void NotifyTxEnd() override;
89
90 /**
91 * TracedCallback signature for enqueue/dequeue of a packet.
92 *
93 * \param [in] packet The Packet being received.
94 * \param [in] proto The protocol number.
95 */
96 typedef void (*QueueTracedCallback)(Ptr<const Packet> packet, uint16_t proto);
97
98 private:
99 /** Enum defining possible Phy states. */
100 enum State
101 {
102 IDLE, //!< Idle state.
103 CCABUSY, //!< Channel busy.
104 RUNNING, //!< Delay timer running.
105 TX //!< Transmitting.
106 };
107
108 /** Forwarding up callback. */
110 /** PHY layer attached to this MAC. */
112 /** A packet destined for this MAC was received. */
114 /** A packet arrived at the MAC for transmission. */
116 /** A packet was passed down to the PHY from the MAC. */
118
119 // Mac parameters
120 uint32_t m_cw; //!< Contention window size.
121 Time m_slotTime; //!< Slot time duration.
122
123 // State variables
124 /** Time to send next packet. */
126 /** Remaining delay until next send. */
128 /** Next packet to send. */
130 /** Next packet protocol number (usage varies by MAC). */
131 uint16_t m_pktTxProt;
132 /** Scheduled SendPacket event. */
134 /** Tx is ongoing */
136 /** Current state. */
138
139 /** Flag when we've been cleared */
141
142 /** Provides uniform random variable for contention window. */
144
145 /**
146 * Receive packet from lower layer (passed to PHY as callback).
147 *
148 * \param packet Packet being received.
149 * \param sinr SINR of received packet.
150 * \param mode Mode of received packet.
151 */
152 void PhyRxPacketGood(Ptr<Packet> packet, double sinr, UanTxMode mode);
153 /**
154 * Packet received at lower layer in error.
155 *
156 * \param packet Packet received in error.
157 * \param sinr SINR of received packet.
158 */
159 void PhyRxPacketError(Ptr<Packet> packet, double sinr);
160 /** Cancel SendEvent and save remaining delay. */
161 void SaveTimer();
162 /** Schedule SendPacket after delay. */
163 void StartTimer();
164 /** Send packet on PHY. */
165 void SendPacket();
166 /** End TX state. */
167 void EndTx();
168
169 protected:
170 void DoDispose() override;
171
172}; // class UanMacCw
173
174} // namespace ns3
175
176#endif /* UAN_MAC_CW_H */
a polymophic address class
Definition address.h:90
Callback template class.
Definition callback.h:422
An identifier for simulation events.
Definition event-id.h:45
A class used for addressing MAC8 MAC's.
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:48
CW-MAC protocol, similar in idea to the 802.11 DCF with constant backoff window.
Definition uan-mac-cw.h:37
bool m_txOngoing
Tx is ongoing.
Definition uan-mac-cw.h:135
Time m_sendTime
Time to send next packet.
Definition uan-mac-cw.h:125
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet destined for this MAC was received.
Definition uan-mac-cw.h:113
void NotifyCcaStart() override
Called when UanPhy begins sensing channel is busy.
void Clear() override
Clears all pointer references.
Definition uan-mac-cw.cc:44
Ptr< Packet > m_pktTx
Next packet to send.
Definition uan-mac-cw.h:129
void SaveTimer()
Cancel SendEvent and save remaining delay.
TracedCallback< Ptr< const Packet >, uint16_t > m_dequeueLogger
A packet was passed down to the PHY from the MAC.
Definition uan-mac-cw.h:117
void NotifyRxEndError() override
Called when UanPhy finishes receiving packet in error.
bool m_cleared
Flag when we've been cleared.
Definition uan-mac-cw.h:140
void EndTx()
End TX state.
void SendPacket()
Send packet on PHY.
void NotifyCcaEnd() override
Called when UanPhy stops sensing channel is busy.
virtual void SetSlotTime(Time duration)
Set the slot time duration.
virtual uint32_t GetCw()
Get the contention window size.
static TypeId GetTypeId()
Register this type.
Definition uan-mac-cw.cc:69
UanMacCw()
Default constructor.
Definition uan-mac-cw.cc:27
State m_state
Current state.
Definition uan-mac-cw.h:137
Ptr< UniformRandomVariable > m_rv
Provides uniform random variable for contention window.
Definition uan-mac-cw.h:143
bool Enqueue(Ptr< Packet > pkt, uint16_t protocolNumber, const Address &dest) override
Enqueue packet to be transmitted.
void NotifyRxEndOk() override
Called when UanPhy finishes receiving packet without error.
void DoDispose() override
Destructor implementation.
Definition uan-mac-cw.cc:62
virtual void SetCw(uint32_t cw)
Set the contention window size.
Time m_slotTime
Slot time duration.
Definition uan-mac-cw.h:121
~UanMacCw() override
Dummy destructor, DoDispose.
Definition uan-mac-cw.cc:39
void NotifyTxStart(Time duration) override
Called when transmission starts from Phy object.
EventId m_sendEvent
Scheduled SendPacket event.
Definition uan-mac-cw.h:133
void PhyRxPacketError(Ptr< Packet > packet, double sinr)
Packet received at lower layer in error.
Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > m_forwardUpCb
Forwarding up callback.
Definition uan-mac-cw.h:109
void NotifyRxStart() override
Called when UanPhy begins receiving packet.
void PhyRxPacketGood(Ptr< Packet > packet, double sinr, UanTxMode mode)
Receive packet from lower layer (passed to PHY as callback).
State
Enum defining possible Phy states.
Definition uan-mac-cw.h:101
@ IDLE
Idle state.
Definition uan-mac-cw.h:102
@ RUNNING
Delay timer running.
Definition uan-mac-cw.h:104
@ TX
Transmitting.
Definition uan-mac-cw.h:105
@ CCABUSY
Channel busy.
Definition uan-mac-cw.h:103
TracedCallback< Ptr< const Packet >, uint16_t > m_enqueueLogger
A packet arrived at the MAC for transmission.
Definition uan-mac-cw.h:115
void NotifyTxEnd() override
Function called when Phy object finishes transmitting packet.
Time m_savedDelayS
Remaining delay until next send.
Definition uan-mac-cw.h:127
virtual Time GetSlotTime()
Get the slot time duration.
void StartTimer()
Schedule SendPacket after delay.
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
Definition uan-mac-cw.h:111
uint32_t m_cw
Contention window size.
Definition uan-mac-cw.h:120
void(* QueueTracedCallback)(Ptr< const Packet > packet, uint16_t proto)
TracedCallback signature for enqueue/dequeue of a packet.
Definition uan-mac-cw.h:96
void AttachPhy(Ptr< UanPhy > phy) override
Attach PHY layer to this MAC.
void SetForwardUpCb(Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > cb) override
Set the callback to forward packets up to higher layers.
uint16_t m_pktTxProt
Next packet protocol number (usage varies by MAC).
Definition uan-mac-cw.h:131
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
Virtual base class for all UAN MAC protocols.
Definition uan-mac.h:35
Interface for PHY event listener.
Definition uan-phy.h:134
Abstraction of packet modulation information.
Definition uan-tx-mode.h:32
Every class exported by the ns3 library is enclosed in the ns3 namespace.