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 
106  typedef void (* QueueTracedCallback)
107  (Ptr<const Packet> packet, uint16_t proto);
108 
109 private:
111  typedef enum {
115  TX
116  } State;
117 
130 
131  // Mac parameters
132  uint32_t m_cw;
134 
135  // State variables
143  uint16_t m_pktTxProt;
150 
152  bool m_cleared;
153 
156 
164  void PhyRxPacketGood (Ptr<Packet> packet, double sinr, UanTxMode mode);
171  void PhyRxPacketError (Ptr<Packet> packet, double sinr);
173  void SaveTimer (void);
175  void StartTimer (void);
177  void SendPacket (void);
179  void EndTx (void);
180 
181 protected:
182  virtual void DoDispose ();
183 
184 }; // class UanMacCw
185 
186 } // namespace ns3
187 
188 #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:102
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:180
Callback template class.
Definition: callback.h:1176
State m_state
Current state.
Definition: uan-mac-cw.h:149
void SendPacket(void)
Send packet on PHY.
Definition: uan-mac-cw.cc:370
uint16_t m_pktTxProt
Next packet protocol number (usage varies by MAC).
Definition: uan-mac-cw.h:143
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:77
virtual void SetSlotTime(Time duration)
Set the slot time duration.
Definition: uan-mac-cw.cc:311
virtual void AttachPhy(Ptr< UanPhy > phy)
Attach PHY layer to this MAC.
Definition: uan-mac-cw.cc:186
bool m_cleared
Flag when we&#39;ve been cleared.
Definition: uan-mac-cw.h:152
TracedCallback< Ptr< const Packet >, uint16_t > m_enqueueLogger
A packet arrived at the MAC for transmission.
Definition: uan-mac-cw.h:127
virtual void Clear(void)
Clears all pointer references.
Definition: uan-mac-cw.cc:52
Idle state.
Definition: uan-mac-cw.h:112
Time m_savedDelayS
Remaining delay until next send.
Definition: uan-mac-cw.h:139
virtual void NotifyRxEndError(void)
Called when UanPhy finishes receiving packet in error.
Definition: uan-mac-cw.cc:219
a polymophic address class
Definition: address.h:90
phy
Definition: third.py:86
Mac8Address m_address
The MAC address.
Definition: uan-mac-cw.h:121
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:125
virtual void SetCw(uint32_t cw)
Set the contention window size.
Definition: uan-mac-cw.cc:306
virtual void NotifyRxStart(void)
Called when UanPhy begins receiving packet.
Definition: uan-mac-cw.cc:195
void EndTx(void)
End TX state.
Definition: uan-mac-cw.cc:284
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:155
virtual void NotifyRxEndOk(void)
Called when UanPhy finishes receiving packet without error.
Definition: uan-mac-cw.cc:207
void SaveTimer(void)
Cancel SendEvent and save remaining delay.
Definition: uan-mac-cw.cc:343
virtual ~UanMacCw()
Dummy destructor, DoDispose.
Definition: uan-mac-cw.cc:47
virtual void NotifyCcaStart(void)
Called when UanPhy begins sensing channel is busy.
Definition: uan-mac-cw.cc:231
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:321
virtual void NotifyTxStart(Time duration)
Called when transmission starts from Phy object.
Definition: uan-mac-cw.cc:255
virtual void DoDispose()
Destructor implementation.
Definition: uan-mac-cw.cc:70
Channel busy.
Definition: uan-mac-cw.h:113
EventId m_sendEvent
Scheduled SendPacket event.
Definition: uan-mac-cw.h:145
EventId m_txEndEvent
Scheduled EndTx event.
Definition: uan-mac-cw.h:147
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:316
Time m_sendTime
Time to send next packet.
Definition: uan-mac-cw.h:137
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
Definition: uan-mac-cw.h:123
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:119
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:276
Time m_slotTime
Slot time duration.
Definition: uan-mac-cw.h:133
void PhyRxPacketGood(Ptr< Packet > packet, double sinr, UanTxMode mode)
Receive packet from lower layer (passed to PHY as callback).
Definition: uan-mac-cw.cc:326
Ptr< Packet > m_pktTx
Next packet to send.
Definition: uan-mac-cw.h:141
Delay timer running.
Definition: uan-mac-cw.h:114
void StartTimer(void)
Schedule SendPacket after delay.
Definition: uan-mac-cw.cc:354
TracedCallback< Ptr< const Packet >, uint16_t > m_dequeueLogger
A packet was passed down to the PHY from the MAC.
Definition: uan-mac-cw.h:129
void PhyRxPacketError(Ptr< Packet > packet, double sinr)
Packet received at lower layer in error.
Definition: uan-mac-cw.cc:338
a unique identifier for an interface.
Definition: type-id.h:58
uint32_t m_cw
Contention window size.
Definition: uan-mac-cw.h:132
Transmitting.
Definition: uan-mac-cw.h:115
virtual void NotifyCcaEnd(void)
Called when UanPhy stops sensing channel is busy.
Definition: uan-mac-cw.cc:243
virtual bool Enqueue(Ptr< Packet > pkt, uint16_t protocolNumber, const Address &dest)
Enqueue packet to be transmitted.
Definition: uan-mac-cw.cc:111