A Discrete-Event Network Simulator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
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  */
21 #ifndef UAN_MAC_CW_H
22 #define UAN_MAC_CW_H
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/uan-address.h"
30 #include "ns3/random-variable-stream.h"
32 namespace ns3 {
46 class UanMacCw : public UanMac,
47  public UanPhyListener
48 {
49 public:
51  UanMacCw ();
53  virtual ~UanMacCw ();
58  static TypeId GetTypeId (void);
65  virtual void SetCw (uint32_t cw);
71  virtual void SetSlotTime (Time duration);
77  virtual uint32_t GetCw (void);
83  virtual Time GetSlotTime (void);
85  // Inherited methods from UanMac
86  virtual Address GetAddress ();
87  virtual void SetAddress (UanAddress addr);
88  virtual bool Enqueue (Ptr<Packet> pkt, const Address &dest, uint16_t protocolNumber);
89  virtual void SetForwardUpCb (Callback<void, Ptr<Packet>, const UanAddress&> cb);
90  virtual void AttachPhy (Ptr<UanPhy> phy);
91  virtual Address GetBroadcast (void) const;
92  virtual void Clear (void);
93  int64_t AssignStreams (int64_t stream);
95  // Inherited methods from UanPhyListener
96  virtual void NotifyRxStart (void);
97  virtual void NotifyRxEndOk (void);
98  virtual void NotifyRxEndError (void);
99  virtual void NotifyCcaStart (void);
100  virtual void NotifyCcaEnd (void);
101  virtual void NotifyTxStart (Time duration);
104 private:
106  typedef enum {
110  TX
111  } State;
126  // Mac parameters
127  uint32_t m_cw;
130  // State variables
138  uint16_t m_pktTxProt;
147  bool m_cleared;
159  void PhyRxPacketGood (Ptr<Packet> packet, double sinr, UanTxMode mode);
166  void PhyRxPacketError (Ptr<Packet> packet, double sinr);
168  void SaveTimer (void);
170  void StartTimer (void);
172  void SendPacket (void);
174  void EndTx (void);
176 protected:
177  virtual void DoDispose ();
179 }; // class UanMacCw
181 } // namespace ns3
183 #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
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
virtual Address GetAddress()
Get the MAC Address.
Definition: uan-mac-cw.cc:108
Callback template class.
Definition: callback.h:920
State m_state
Current state.
Definition: uan-mac-cw.h:144
void SendPacket(void)
Send packet on PHY.
Definition: uan-mac-cw.cc:384
uint16_t m_pktTxProt
Next packet protocol number (usage varies by MAC).
Definition: uan-mac-cw.h:138
forward calls to a chain of CallbackAn ns3::TracedCallback has almost exactly the same API as a norma...
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:326
virtual void AttachPhy(Ptr< UanPhy > phy)
Attach PHY layer to this MAC.
Definition: uan-mac-cw.cc:194
bool m_cleared
Flag when we've been cleared.
Definition: uan-mac-cw.h:147
TracedCallback< Ptr< const Packet >, uint16_t > m_enqueueLogger
A packet arrived at the MAC for transmission.
Definition: uan-mac-cw.h:122
virtual void Clear(void)
Clears all pointer references.
Definition: uan-mac-cw.cc:53
Idle state.
Definition: uan-mac-cw.h:107
virtual Address GetBroadcast(void) const
Get the broadcast address.
Definition: uan-mac-cw.cc:203
Time m_savedDelayS
Remaining delay until next send.
Definition: uan-mac-cw.h:134
virtual void NotifyRxEndError(void)
Called when UanPhy finishes receiving packet in error.
Definition: uan-mac-cw.cc:234
a polymophic address class
Definition: address.h:86
virtual void SetAddress(UanAddress addr)
Set the address.
Definition: uan-mac-cw.cc:114
virtual bool Enqueue(Ptr< Packet > pkt, const Address &dest, uint16_t protocolNumber)
Enqueue packet to be transmitted.
Definition: uan-mac-cw.cc:120
Virtual base class for all UAN MAC protocols.
Definition: uan-mac.h:47
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet destined for this MAC was received.
Definition: uan-mac-cw.h:120
A class used for addressing UAN MAC's.
Definition: uan-address.h:40
virtual void SetCw(uint32_t cw)
Set the contention window size.
Definition: uan-mac-cw.cc:321
virtual void NotifyRxStart(void)
Called when UanPhy begins receiving packet.
Definition: uan-mac-cw.cc:210
void EndTx(void)
End TX state.
Definition: uan-mac-cw.cc:299
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:41
Default constructor.
Definition: uan-mac-cw.cc:37
Ptr< UniformRandomVariable > m_rv
Provides uniform random variable for contention window.
Definition: uan-mac-cw.h:150
Callback< void, Ptr< Packet >, const UanAddress & > m_forwardUpCb
Forwarding up callback.
Definition: uan-mac-cw.h:114
virtual void NotifyRxEndOk(void)
Called when UanPhy finishes receiving packet without error.
Definition: uan-mac-cw.cc:222
void SaveTimer(void)
Cancel SendEvent and save remaining delay.
Definition: uan-mac-cw.cc:357
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:246
Interface for PHY event listener.
Definition: uan-phy.h:146
virtual Time GetSlotTime(void)
Get the slot time duration.
Definition: uan-mac-cw.cc:336
virtual void NotifyTxStart(Time duration)
Called when transmission starts from Phy object.
Definition: uan-mac-cw.cc:270
virtual void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: uan-mac-cw.cc:71
Channel busy.
Definition: uan-mac-cw.h:108
EventId m_sendEvent
Scheduled SendPacket event.
Definition: uan-mac-cw.h:140
EventId m_txEndEvent
Scheduled EndTx event.
Definition: uan-mac-cw.h:142
Enum defining possible Phy states.
Definition: uan-mac-cw.h:106
virtual uint32_t GetCw(void)
Get the contention window size.
Definition: uan-mac-cw.cc:331
Time m_sendTime
Time to send next packet.
Definition: uan-mac-cw.h:132
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
Definition: uan-mac-cw.h:118
an identifier for simulation events.
Definition: event-id.h:46
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:291
Time m_slotTime
Slot time duration.
Definition: uan-mac-cw.h:128
virtual void SetForwardUpCb(Callback< void, Ptr< Packet >, const UanAddress & > cb)
Set the callback to forward packets up to higher layers.
Definition: uan-mac-cw.cc:188
void PhyRxPacketGood(Ptr< Packet > packet, double sinr, UanTxMode mode)
Receive packet from lower layer (passed to PHY as callback).
Definition: uan-mac-cw.cc:341
Ptr< Packet > m_pktTx
Next packet to send.
Definition: uan-mac-cw.h:136
UanAddress m_address
The MAC address.
Definition: uan-mac-cw.h:116
Delay timer running.
Definition: uan-mac-cw.h:109
void StartTimer(void)
Schedule SendPacket after delay.
Definition: uan-mac-cw.cc:368
TracedCallback< Ptr< const Packet >, uint16_t > m_dequeueLogger
A packet was passed down to the PHY from the MAC.
Definition: uan-mac-cw.h:124
void PhyRxPacketError(Ptr< Packet > packet, double sinr)
Packet received at lower layer in error.
Definition: uan-mac-cw.cc:352
a unique identifier for an interface.
Definition: type-id.h:49
uint32_t m_cw
Contention window size.
Definition: uan-mac-cw.h:127
Definition: uan-mac-cw.h:110
virtual void NotifyCcaEnd(void)
Called when UanPhy stops sensing channel is busy.
Definition: uan-mac-cw.cc:258