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
32namespace ns3 {
33
46class UanMacCw : public UanMac,
47 public UanPhyListener
48{
49public:
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
109private:
111 typedef enum
112 {
116 TX
118
129
130 // Mac parameters
133
134 // State variables
142 uint16_t m_pktTxProt;
149
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
180protected:
181 virtual void DoDispose ();
182
183}; // class UanMacCw
184
185} // namespace ns3
186
187#endif /* UAN_MAC_CW_H */
a polymophic address class
Definition: address.h:91
Callback template class.
Definition: callback.h:1279
An identifier for simulation events.
Definition: event-id.h:54
A class used for addressing MAC8 MAC's.
Definition: mac8-address.h:43
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
CW-MAC protocol, similar in idea to the 802.11 DCF with constant backoff window.
Definition: uan-mac-cw.h:48
bool m_txOngoing
Tx is ongoing.
Definition: uan-mac-cw.h:146
virtual void NotifyRxStart(void)
Called when UanPhy begins receiving packet.
Definition: uan-mac-cw.cc:196
Time m_sendTime
Time to send next packet.
Definition: uan-mac-cw.h:136
virtual void NotifyTxEnd(void)
Function called when Phy object finishes transmitting packet.
Definition: uan-mac-cw.cc:271
virtual void NotifyRxEndError(void)
Called when UanPhy finishes receiving packet in error.
Definition: uan-mac-cw.cc:220
TracedCallback< Ptr< const Packet >, uint16_t > m_enqueueLogger
A packet arrived at the MAC for transmission.
Definition: uan-mac-cw.h:126
Ptr< Packet > m_pktTx
Next packet to send.
Definition: uan-mac-cw.h:140
virtual void NotifyRxEndOk(void)
Called when UanPhy finishes receiving packet without error.
Definition: uan-mac-cw.cc:208
virtual void NotifyTxStart(Time duration)
Called when transmission starts from Phy object.
Definition: uan-mac-cw.cc:256
void EndTx(void)
End TX state.
Definition: uan-mac-cw.cc:287
bool m_cleared
Flag when we've been cleared.
Definition: uan-mac-cw.h:151
static TypeId GetTypeId(void)
Register this type.
Definition: uan-mac-cw.cc:78
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet destined for this MAC was received.
Definition: uan-mac-cw.h:124
virtual void SetSlotTime(Time duration)
Set the slot time duration.
Definition: uan-mac-cw.cc:314
virtual void NotifyCcaEnd(void)
Called when UanPhy stops sensing channel is busy.
Definition: uan-mac-cw.cc:244
UanMacCw()
Default constructor.
Definition: uan-mac-cw.cc:36
State m_state
Current state.
Definition: uan-mac-cw.h:148
Ptr< UniformRandomVariable > m_rv
Provides uniform random variable for contention window.
Definition: uan-mac-cw.h:154
virtual bool Enqueue(Ptr< Packet > pkt, uint16_t protocolNumber, const Address &dest)
Enqueue packet to be transmitted.
Definition: uan-mac-cw.cc:112
virtual void DoDispose()
Destructor implementation.
Definition: uan-mac-cw.cc:71
virtual void Clear(void)
Clears all pointer references.
Definition: uan-mac-cw.cc:53
void SendPacket(void)
Send packet on PHY.
Definition: uan-mac-cw.cc:371
virtual void SetCw(uint32_t cw)
Set the contention window size.
Definition: uan-mac-cw.cc:309
virtual void NotifyCcaStart(void)
Called when UanPhy begins sensing channel is busy.
Definition: uan-mac-cw.cc:232
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
virtual ~UanMacCw()
Dummy destructor, DoDispose.
Definition: uan-mac-cw.cc:48
Time m_slotTime
Slot time duration.
Definition: uan-mac-cw.h:132
virtual uint32_t GetCw(void)
Get the contention window size.
Definition: uan-mac-cw.cc:319
EventId m_sendEvent
Scheduled SendPacket event.
Definition: uan-mac-cw.h:144
void PhyRxPacketError(Ptr< Packet > packet, double sinr)
Packet received at lower layer in error.
Definition: uan-mac-cw.cc:340
Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > m_forwardUpCb
Forwarding up callback.
Definition: uan-mac-cw.h:120
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
void StartTimer(void)
Schedule SendPacket after delay.
Definition: uan-mac-cw.cc:355
virtual void AttachPhy(Ptr< UanPhy > phy)
Attach PHY layer to this MAC.
Definition: uan-mac-cw.cc:187
State
Enum defining possible Phy states.
Definition: uan-mac-cw.h:112
@ IDLE
Idle state.
Definition: uan-mac-cw.h:113
@ RUNNING
Delay timer running.
Definition: uan-mac-cw.h:115
@ TX
Transmitting.
Definition: uan-mac-cw.h:116
@ CCABUSY
Channel busy.
Definition: uan-mac-cw.h:114
virtual Time GetSlotTime(void)
Get the slot time duration.
Definition: uan-mac-cw.cc:324
Time m_savedDelayS
Remaining delay until next send.
Definition: uan-mac-cw.h:138
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
Definition: uan-mac-cw.h:122
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
uint32_t m_cw
Contention window size.
Definition: uan-mac-cw.h:131
void SaveTimer(void)
Cancel SendEvent and save remaining delay.
Definition: uan-mac-cw.cc:344
void(* QueueTracedCallback)(Ptr< const Packet > packet, uint16_t proto)
TracedCallback signature for enqueue/dequeue of a packet.
Definition: uan-mac-cw.h:107
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
uint16_t m_pktTxProt
Next packet protocol number (usage varies by MAC).
Definition: uan-mac-cw.h:142
Virtual base class for all UAN MAC protocols.
Definition: uan-mac.h:50
Interface for PHY event listener.
Definition: uan-phy.h:147
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:42
Every class exported by the ns3 library is enclosed in the ns3 namespace.
phy
Definition: third.py:93