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 << *item);
66  HigherLayerTxVectorTag datatag;
67  bool found;
68  found = ConstCast<Packet> (item->GetPacket ())->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 (item);
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 ();
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
111  Ptr<Txop> dca)
112 {
113  NS_LOG_FUNCTION (this << *mpdu << params << dca);
115  uint32_t curChannel = phy->GetChannelNumber ();
116  // if current channel access is not AlternatingAccess, just do as MacLow.
117  if (!m_scheduler->IsAlternatingAccessAssigned (curChannel))
118  {
119  MacLow::StartTransmission (mpdu, params, dca);
120  return;
121  }
122 
123  Time transmissionTime = MacLow::CalculateTransmissionTime (mpdu->GetPacket (), &mpdu->GetHeader (), params);
124  Time remainingTime = m_coordinator->NeedTimeToGuardInterval ();
125 
126  if (transmissionTime > remainingTime)
127  {
128  // The attempt for this transmission will be canceled;
129  // and this packet will be pending for next transmission by QosTxop class
130  NS_LOG_DEBUG ("Because the required transmission time = " << transmissionTime.GetMilliSeconds ()
131  << "ms exceeds the remainingTime = " << remainingTime.GetMilliSeconds ()
132  << "ms, currently this packet will not be transmitted.");
133  }
134  else
135  {
136  MacLow::StartTransmission (mpdu, params, dca);
137  }
138 }
139 
140 } // namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
This class is the subclass of MacLow to provide support for MAC extension (1) allows higher layer con...
Definition: wave-mac-low.h:49
#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...
virtual WifiTxVector GetDataTxVector(Ptr< const WifiMacQueueItem > item) const
Return a TXVECTOR for the DATA frame given the destination.
Definition: wave-mac-low.cc:63
#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:205
Time NeedTimeToGuardInterval(Time duration=Seconds(0.0)) const
Ptr< ChannelScheduler > GetChannelScheduler(void) const
static TypeId GetTypeId(void)
Get the type ID.
Definition: wave-mac-low.cc:36
Ptr< ChannelScheduler > m_scheduler
the channel scheduler
Definition: wave-mac-low.h:87
Time CalculateTransmissionTime(Ptr< const Packet > packet, const WifiMacHeader *hdr, const MacLowTransmissionParameters &parameters) const
Definition: mac-low.cc:1469
control how a packet is transmitted.
virtual void StartTransmission(Ptr< WifiMacQueueItem > mpdu, MacLowTransmissionParameters parameters, Ptr< Txop > txop)
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:93
WifiPreamble GetPreambleType(void) const
virtual void StartTransmission(Ptr< WifiMacQueueItem > mpdu, MacLowTransmissionParameters parameters, Ptr< Txop > txop)
Definition: mac-low.cc:427
WifiTxVector GetTxVector(void) const
virtual ~WaveMacLow()
Definition: wave-mac-low.cc:49
WifiMode GetMode(void) const
virtual WifiTxVector GetDataTxVector(Ptr< const WifiMacQueueItem > item) const
Return a TXVECTOR for the Data frame given the destination.
Definition: mac-low.cc:1194
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.
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
handle RTS/CTS/Data/Ack transactions.
Definition: mac-low.h:59
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:383
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
uint8_t GetTxPowerLevel(void) const
uint16_t GetChannelWidth(void) const
Ptr< ChannelCoordinator > m_coordinator
the channel coordinator
Definition: wave-mac-low.h:88
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:119
Ptr< WifiPhy > GetPhy(void) const
Definition: mac-low.cc:263
void SetWaveNetDevice(Ptr< WaveNetDevice > device)
Definition: wave-mac-low.cc:55