A Discrete-Event Network Simulator
API
wave-mac-low.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 INRIA
4  * Copyright (c) 2013 Dalian University of Technology
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20  * Junling Bu <linlinjavaer@gmail.com>
21  */
22 
23 #include "ns3/log.h"
24 #include "ns3/event-id.h"
25 #include "ns3/wifi-phy.h"
26 #include "wave-mac-low.h"
27 #include "higher-tx-tag.h"
28 
29 namespace ns3 {
30 
31 NS_LOG_COMPONENT_DEFINE ("WaveMacLow");
32 
33 NS_OBJECT_ENSURE_REGISTERED (WaveMacLow);
34 
35 TypeId
37 {
38  static TypeId tid = TypeId ("ns3::WaveMacLow")
39  .SetParent<MacLow> ()
40  .SetGroupName ("Wave")
41  .AddConstructor<WaveMacLow> ()
42  ;
43  return tid;
44 }
46 {
47  NS_LOG_FUNCTION (this);
48 }
50 {
51  NS_LOG_FUNCTION (this);
52 }
53 
54 void
56 {
57  m_scheduler = device->GetChannelScheduler ();
59  NS_ASSERT (m_scheduler != 0 && m_coordinator != 0);
60 }
61 
64 {
65  NS_LOG_FUNCTION (this << packet << hdr);
66  HigherLayerTxVectorTag datatag;
67  bool found;
68  found = ConstCast<Packet> (packet)->PeekPacketTag (datatag);
69  // if high layer has not controlled transmit parameters, the real transmit parameters
70  // will be determined by MAC layer itself.
71  if (!found)
72  {
73  return MacLow::GetDataTxVector (packet, hdr);
74  }
75 
76  // if high layer has set the transmit parameters with non-adaption mode,
77  // the real transmit parameters are determined by high layer.
78  if (!datatag.IsAdaptable ())
79  {
80  return datatag.GetTxVector ();
81  }
82 
83  // if high layer has set the transmit parameters with non-adaption mode,
84  // the real transmit parameters are determined by both high layer and MAC layer.
85  WifiTxVector txHigher = datatag.GetTxVector ();
86  WifiTxVector txMac = MacLow::GetDataTxVector (packet, hdr);
87  WifiTxVector txAdapter;
88  txAdapter.SetChannelWidth (10);
89  // the DataRate set by higher layer is the minimum data rate
90  // which is the lower bound for the actual data rate.
91  if (txHigher.GetMode ().GetDataRate (txHigher.GetChannelWidth ()) > txMac.GetMode ().GetDataRate (txMac.GetChannelWidth ()))
92  {
93  txAdapter.SetMode (txHigher.GetMode ());
94  txAdapter.SetPreambleType (txHigher.GetPreambleType ());
95  }
96  else
97  {
98  txAdapter.SetMode (txMac.GetMode ());
99  txAdapter.SetPreambleType (txMac.GetPreambleType ());
100  }
101  // the TxPwr_Level set by higher layer is the maximum transmit
102  // power which is the upper bound for the actual transmit power;
103  txAdapter.SetTxPowerLevel (std::min (txHigher.GetTxPowerLevel (), txMac.GetTxPowerLevel ()));
104 
105  return txAdapter;
106 }
107 
108 void
110  const WifiMacHeader* hdr,
112  Ptr<Txop> dca)
113 {
114  NS_LOG_FUNCTION (this << packet << hdr << params << dca);
116  uint32_t curChannel = phy->GetChannelNumber ();
117  // if current channel access is not AlternatingAccess, just do as MacLow.
118  if (!m_scheduler->IsAlternatingAccessAssigned (curChannel))
119  {
120  MacLow::StartTransmission (packet, hdr, params, dca);
121  return;
122  }
123 
124  Time transmissionTime = MacLow::CalculateTransmissionTime (packet, hdr, params);
125  Time remainingTime = m_coordinator->NeedTimeToGuardInterval ();
126 
127  if (transmissionTime > remainingTime)
128  {
129  // The attempt for this transmission will be canceled;
130  // and this packet will be pending for next transmission by QosTxop class
131  NS_LOG_DEBUG ("Because the required transmission time = " << transmissionTime.GetMilliSeconds ()
132  << "ms exceeds the remainingTime = " << remainingTime.GetMilliSeconds ()
133  << "ms, currently this packet will not be transmitted.");
134  }
135  else
136  {
137  MacLow::StartTransmission (packet, hdr, params, dca);
138  }
139 }
140 
141 } // namespace ns3
virtual void StartTransmission(Ptr< const Packet > packet, const WifiMacHeader *hdr, MacLowTransmissionParameters parameters, Ptr< Txop > txop)
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
This class is the subclass of MacLow to provide support for MAC extension (1) allows higher layer con...
Definition: wave-mac-low.h:45
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
bool IsAdaptable(void) const
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
void SetChannelWidth(uint16_t channelWidth)
Sets the selected channelWidth (in MHz)
#define min(a, b)
Definition: 80211b.c:42
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Time NeedTimeToGuardInterval(Time duration=Seconds(0.0)) const
virtual WifiTxVector GetDataTxVector(Ptr< const Packet > packet, const WifiMacHeader *hdr) const
Return a TXVECTOR for the DATA frame given the destination.
Definition: mac-low.cc:1144
Ptr< ChannelScheduler > GetChannelScheduler(void) const
static TypeId GetTypeId(void)
Get the type ID.
Definition: wave-mac-low.cc:36
virtual void StartTransmission(Ptr< const Packet > packet, const WifiMacHeader *hdr, MacLowTransmissionParameters parameters, Ptr< Txop > txop)
Definition: mac-low.cc:478
Ptr< ChannelScheduler > m_scheduler
the channel scheduler
Definition: wave-mac-low.h:86
Time CalculateTransmissionTime(Ptr< const Packet > packet, const WifiMacHeader *hdr, const MacLowTransmissionParameters &parameters) const
Definition: mac-low.cc:1215
control how a packet is transmitted.
This tag will be used to support higher layer control DataRate and TxPwr_Level for transmission...
Definition: higher-tx-tag.h:47
phy
Definition: third.py:86
WifiPreamble GetPreambleType(void) const
WifiTxVector GetTxVector(void) const
virtual ~WaveMacLow()
Definition: wave-mac-low.cc:49
WifiMode GetMode(void) const
Ptr< ChannelCoordinator > GetChannelCoordinator(void) const
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
void SetTxPowerLevel(uint8_t powerlevel)
Sets the selected transmission power level.
virtual WifiTxVector GetDataTxVector(Ptr< const Packet > packet, const WifiMacHeader *hdr) const
Return a TXVECTOR for the DATA frame given the destination.
Definition: wave-mac-low.cc:63
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
handle RTS/CTS/DATA/ACK transactions.
Definition: mac-low.h:58
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:359
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:270
uint8_t GetTxPowerLevel(void) const
uint16_t GetChannelWidth(void) const
Ptr< ChannelCoordinator > m_coordinator
the channel coordinator
Definition: wave-mac-low.h:87
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:156
Implements the IEEE 802.11 MAC header.
Ptr< WifiPhy > GetPhy(void) const
Definition: mac-low.cc:259
void SetWaveNetDevice(Ptr< WaveNetDevice > device)
Definition: wave-mac-low.cc:55