A Discrete-Event Network Simulator
API
uan-mac-cw.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 University of Washington
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: Leonard Tracy <lentracy@gmail.com>
19  */
20 
21 #ifndef UAN_MAC_CW_H
22 #define UAN_MAC_CW_H
23 
24 #include "ns3/uan-mac.h"
25 #include "ns3/nstime.h"
26 #include "ns3/simulator.h"
27 #include "ns3/uan-phy.h"
28 #include "ns3/uan-tx-mode.h"
29 #include "ns3/mac8-address.h"
30 #include "ns3/random-variable-stream.h"
31 
32 namespace ns3 {
33 
46 class UanMacCw : public UanMac,
47  public UanPhyListener
48 {
49 public:
51  UanMacCw ();
53  virtual ~UanMacCw ();
58  static TypeId GetTypeId (void);
59 
65  virtual void SetCw (uint32_t cw);
71  virtual void SetSlotTime (Time duration);
77  virtual uint32_t GetCw (void);
83  virtual Time GetSlotTime (void);
84 
85  // Inherited methods from UanMac
86  virtual bool Enqueue (Ptr<Packet> pkt, uint16_t protocolNumber, const Address &dest);
87  virtual void SetForwardUpCb (Callback<void, Ptr<Packet>, uint16_t, const Mac8Address&> cb);
88  virtual void AttachPhy (Ptr<UanPhy> phy);
89  virtual void Clear (void);
90  int64_t AssignStreams (int64_t stream);
91 
92  // Inherited methods from UanPhyListener
93  virtual void NotifyRxStart (void);
94  virtual void NotifyRxEndOk (void);
95  virtual void NotifyRxEndError (void);
96  virtual void NotifyCcaStart (void);
97  virtual void NotifyCcaEnd (void);
98  virtual void NotifyTxStart (Time duration);
99  virtual void NotifyTxEnd (void);
100 
107  typedef void (* QueueTracedCallback)(Ptr<const Packet> packet, uint16_t proto);
108 
109 private:
111  typedef enum
112  {
116  TX
117  } State;
118 
129 
130  // Mac parameters
131  uint32_t m_cw;
133 
134  // State variables
142  uint16_t m_pktTxProt;
149 
151  bool m_cleared;
152 
155 
163  void PhyRxPacketGood (Ptr<Packet> packet, double sinr, UanTxMode mode);
170  void PhyRxPacketError (Ptr<Packet> packet, double sinr);
172  void SaveTimer (void);
174  void StartTimer (void);
176  void SendPacket (void);
178  void EndTx (void);
179 
180 protected:
181  virtual void DoDispose ();
182 
183 }; // class UanMacCw
184 
185 } // namespace ns3
186 
187 #endif /* UAN_MAC_CW_H */
CW-MAC protocol, similar in idea to the 802.11 DCF with constant backoff window.
Definition: uan-mac-cw.h:46
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
virtual void SetForwardUpCb(Callback< void, Ptr< Packet >, uint16_t, const Mac8Address &> cb)
Set the callback to forward packets up to higher layers.
Definition: uan-mac-cw.cc:181
Callback template class.
Definition: callback.h:1278
State m_state
Current state.
Definition: uan-mac-cw.h:148
void SendPacket(void)
Send packet on PHY.
Definition: uan-mac-cw.cc:373
virtual void NotifyTxEnd(void)
Function called when Phy object finishes transmitting packet.
Definition: uan-mac-cw.cc:271
uint16_t m_pktTxProt
Next packet protocol number (usage varies by MAC).
Definition: uan-mac-cw.h:142
void(* QueueTracedCallback)(Ptr< const Packet > packet, uint16_t proto)
TracedCallback signature for enqueue/dequeue of a packet.
Definition: uan-mac-cw.h:107
Forward calls to a chain of Callback.
static TypeId GetTypeId(void)
Register this type.
Definition: uan-mac-cw.cc:78
virtual void SetSlotTime(Time duration)
Set the slot time duration.
Definition: uan-mac-cw.cc:314
virtual void AttachPhy(Ptr< UanPhy > phy)
Attach PHY layer to this MAC.
Definition: uan-mac-cw.cc:187
bool m_cleared
Flag when we&#39;ve been cleared.
Definition: uan-mac-cw.h:151
TracedCallback< Ptr< const Packet >, uint16_t > m_enqueueLogger
A packet arrived at the MAC for transmission.
Definition: uan-mac-cw.h:126
virtual void Clear(void)
Clears all pointer references.
Definition: uan-mac-cw.cc:53
Idle state.
Definition: uan-mac-cw.h:113
Time m_savedDelayS
Remaining delay until next send.
Definition: uan-mac-cw.h:138
virtual void NotifyRxEndError(void)
Called when UanPhy finishes receiving packet in error.
Definition: uan-mac-cw.cc:220
a polymophic address class
Definition: address.h:90
phy
Definition: third.py:93
Virtual base class for all UAN MAC protocols.
Definition: uan-mac.h:49
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet destined for this MAC was received.
Definition: uan-mac-cw.h:124
bool m_txOngoing
Tx is ongoing.
Definition: uan-mac-cw.h:146
virtual void SetCw(uint32_t cw)
Set the contention window size.
Definition: uan-mac-cw.cc:309
virtual void NotifyRxStart(void)
Called when UanPhy begins receiving packet.
Definition: uan-mac-cw.cc:196
void EndTx(void)
End TX state.
Definition: uan-mac-cw.cc:287
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:41
UanMacCw()
Default constructor.
Definition: uan-mac-cw.cc:36
A class used for addressing MAC8 MAC&#39;s.
Definition: mac8-address.h:42
Ptr< UniformRandomVariable > m_rv
Provides uniform random variable for contention window.
Definition: uan-mac-cw.h:154
virtual void NotifyRxEndOk(void)
Called when UanPhy finishes receiving packet without error.
Definition: uan-mac-cw.cc:208
void SaveTimer(void)
Cancel SendEvent and save remaining delay.
Definition: uan-mac-cw.cc:346
virtual ~UanMacCw()
Dummy destructor, DoDispose.
Definition: uan-mac-cw.cc:48
virtual void NotifyCcaStart(void)
Called when UanPhy begins sensing channel is busy.
Definition: uan-mac-cw.cc:232
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Interface for PHY event listener.
Definition: uan-phy.h:146
virtual Time GetSlotTime(void)
Get the slot time duration.
Definition: uan-mac-cw.cc:324
virtual void NotifyTxStart(Time duration)
Called when transmission starts from Phy object.
Definition: uan-mac-cw.cc:256
virtual void DoDispose()
Destructor implementation.
Definition: uan-mac-cw.cc:71
Channel busy.
Definition: uan-mac-cw.h:114
EventId m_sendEvent
Scheduled SendPacket event.
Definition: uan-mac-cw.h:144
State
Enum defining possible Phy states.
Definition: uan-mac-cw.h:111
virtual uint32_t GetCw(void)
Get the contention window size.
Definition: uan-mac-cw.cc:319
Time m_sendTime
Time to send next packet.
Definition: uan-mac-cw.h:136
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
Definition: uan-mac-cw.h:122
An identifier for simulation events.
Definition: event-id.h:53
Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > m_forwardUpCb
Forwarding up callback.
Definition: uan-mac-cw.h:120
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: uan-mac-cw.cc:279
Time m_slotTime
Slot time duration.
Definition: uan-mac-cw.h:132
void PhyRxPacketGood(Ptr< Packet > packet, double sinr, UanTxMode mode)
Receive packet from lower layer (passed to PHY as callback).
Definition: uan-mac-cw.cc:329
Ptr< Packet > m_pktTx
Next packet to send.
Definition: uan-mac-cw.h:140
Delay timer running.
Definition: uan-mac-cw.h:115
void StartTimer(void)
Schedule SendPacket after delay.
Definition: uan-mac-cw.cc:357
TracedCallback< Ptr< const Packet >, uint16_t > m_dequeueLogger
A packet was passed down to the PHY from the MAC.
Definition: uan-mac-cw.h:128
void PhyRxPacketError(Ptr< Packet > packet, double sinr)
Packet received at lower layer in error.
Definition: uan-mac-cw.cc:341
a unique identifier for an interface.
Definition: type-id.h:58
uint32_t m_cw
Contention window size.
Definition: uan-mac-cw.h:131
Transmitting.
Definition: uan-mac-cw.h:116
virtual void NotifyCcaEnd(void)
Called when UanPhy stops sensing channel is busy.
Definition: uan-mac-cw.cc:244
virtual bool Enqueue(Ptr< Packet > pkt, uint16_t protocolNumber, const Address &dest)
Enqueue packet to be transmitted.
Definition: uan-mac-cw.cc:112