A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
uan-mac-cw.h
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/uan-address.h"
30 #include "ns3/random-variable-stream.h"
31 
32 namespace ns3 {
33 
43 class UanMacCw : public UanMac,
44  public UanPhyListener
45 {
46 public:
47  UanMacCw ();
48  virtual ~UanMacCw ();
49  static TypeId GetTypeId (void);
50 
54  virtual void SetCw (uint32_t cw);
58  virtual void SetSlotTime (Time duration);
62  virtual uint32_t GetCw (void);
66  virtual Time GetSlotTime (void);
67 
68  // Inherited methods
69  virtual Address GetAddress ();
70  virtual void SetAddress (UanAddress addr);
71  virtual bool Enqueue (Ptr<Packet> pkt, const Address &dest, uint16_t protocolNumber);
72  virtual void SetForwardUpCb (Callback<void, Ptr<Packet>, const UanAddress&> cb);
73  virtual void AttachPhy (Ptr<UanPhy> phy);
74  virtual Address GetBroadcast (void) const;
75  virtual void Clear (void);
76 
77  // PHY listeners
79  virtual void NotifyRxStart (void);
81  virtual void NotifyRxEndOk (void);
83  virtual void NotifyRxEndError (void);
85  virtual void NotifyCcaStart (void);
87  virtual void NotifyCcaEnd (void);
89  virtual void NotifyTxStart (Time duration);
90 
99  int64_t AssignStreams (int64_t stream);
100 
101 private:
102  typedef enum {
103  IDLE, CCABUSY, RUNNING, TX
104  } State;
105 
106  Callback <void, Ptr<Packet>, const UanAddress& > m_forwardUpCb;
107  UanAddress m_address;
108  Ptr<UanPhy> m_phy;
110  TracedCallback<Ptr<const Packet>, uint16_t > m_enqueueLogger;
111  TracedCallback<Ptr<const Packet>, uint16_t > m_dequeueLogger;
112 
113  // Mac parameters
114  uint32_t m_cw;
115  Time m_slotTime;
116 
117  // State variables
118  Time m_sendTime;
119  Time m_savedDelayS;
120  Ptr<Packet> m_pktTx;
121  uint16_t m_pktTxProt;
122  EventId m_sendEvent;
123  EventId m_txEndEvent;
124  State m_state;
125 
126  bool m_cleared;
127 
130 
131  void PhyRxPacketGood (Ptr<Packet> packet, double sinr, UanTxMode mode);
132  void PhyRxPacketError (Ptr<Packet> packet, double sinr);
133  void SaveTimer (void);
134  void StartTimer (void);
135  void SendPacket (void);
136  void EndTx (void);
137 protected:
138  virtual void DoDispose ();
139 };
140 
141 }
142 
143 #endif /* UAN_MAC_CW_H */
CW-MAC A MAC protocol similar in idea to the 802.11 DCF with constant backoff window.
Definition: uan-mac-cw.h:43
keep track of time unit.
Definition: nstime.h:149
virtual Address GetAddress()
Definition: uan-mac-cw.cc:107
Callback template class.
Definition: callback.h:369
forward calls to a chain of CallbackAn ns3::TracedCallback has almost exactly the same API as a norma...
virtual void SetSlotTime(Time duration)
Definition: uan-mac-cw.cc:325
virtual void AttachPhy(Ptr< UanPhy > phy)
Definition: uan-mac-cw.cc:193
virtual void Clear(void)
Definition: uan-mac-cw.cc:52
virtual Address GetBroadcast(void) const
Definition: uan-mac-cw.cc:202
virtual void NotifyRxEndError(void)
Function called by UanPhy object to notify of packet received in error.
Definition: uan-mac-cw.cc:233
a polymophic address class
Definition: address.h:86
virtual void SetAddress(UanAddress addr)
Definition: uan-mac-cw.cc:113
virtual bool Enqueue(Ptr< Packet > pkt, const Address &dest, uint16_t protocolNumber)
Definition: uan-mac-cw.cc:119
Virtual base class for all UAN MAC protocols.
Definition: uan-mac.h:47
virtual void SetCw(uint32_t cw)
Definition: uan-mac-cw.cc:320
virtual void NotifyRxStart(void)
Function called by UanPhy object to notify of packet reception.
Definition: uan-mac-cw.cc:209
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:36
Ptr< UniformRandomVariable > m_rv
Provides uniform random variables.
Definition: uan-mac-cw.h:129
virtual void NotifyRxEndOk(void)
Function called by UanPhy object to notify of packet received successfully.
Definition: uan-mac-cw.cc:221
virtual void NotifyCcaStart(void)
Function called by UanPhy object to notify of channel sensed busy.
Definition: uan-mac-cw.cc:245
Interface for PHY event listener A class which implements this interface may register with Phy object...
Definition: uan-phy.h:128
virtual Time GetSlotTime(void)
Definition: uan-mac-cw.cc:335
virtual void NotifyTxStart(Time duration)
Function called by UanPhy object to notify of outgoing transmission start.
Definition: uan-mac-cw.cc:269
virtual void DoDispose()
Definition: uan-mac-cw.cc:70
virtual uint32_t GetCw(void)
Definition: uan-mac-cw.cc:330
an identifier for simulation events.
Definition: event-id.h:46
int64_t AssignStreams(int64_t stream)
Definition: uan-mac-cw.cc:290
virtual void SetForwardUpCb(Callback< void, Ptr< Packet >, const UanAddress & > cb)
Definition: uan-mac-cw.cc:187
a unique identifier for an interface.
Definition: type-id.h:44
virtual void NotifyCcaEnd(void)
Function called by UanPhy object to notify of channel no longer sensed busy.
Definition: uan-mac-cw.cc:257