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 #include "ns3/log.h"
23 #include "wave-mac-low.h"
24 #include "higher-tx-tag.h"
25 
26 namespace ns3 {
27 
28 NS_LOG_COMPONENT_DEFINE ("WaveMacLow");
29 
30 NS_OBJECT_ENSURE_REGISTERED (WaveMacLow);
31 
32 TypeId
34 {
35  static TypeId tid = TypeId ("ns3::WaveMacLow")
36  .SetParent<MacLow> ()
37  .SetGroupName ("Wave")
38  .AddConstructor<WaveMacLow> ()
39  ;
40  return tid;
41 }
43 {
44  NS_LOG_FUNCTION (this);
45 }
47 {
48  NS_LOG_FUNCTION (this);
49 }
50 
51 void
53 {
54  m_scheduler = device->GetChannelScheduler ();
56  NS_ASSERT (m_scheduler != 0 && m_coordinator != 0);
57 }
58 
61 {
62  NS_LOG_FUNCTION (this << packet << hdr);
63  HigherLayerTxVectorTag datatag;
64  bool found;
65  found = ConstCast<Packet> (packet)->PeekPacketTag (datatag);
66  // if high layer has not controlled transmit parameters, the real transmit parameters
67  // will be determined by MAC layer itself.
68  if (!found)
69  {
70  return MacLow::GetDataTxVector (packet, hdr);
71  }
72 
73  // if high layer has set the transmit parameters with non-adaption mode,
74  // the real transmit parameters are determined by high layer.
75  if (!datatag.IsAdaptable ())
76  {
77  return datatag.GetTxVector ();
78  }
79 
80  // if high layer has set the transmit parameters with non-adaption mode,
81  // the real transmit parameters are determined by both high layer and MAC layer.
82  WifiTxVector txHigher = datatag.GetTxVector ();
83  WifiTxVector txMac = MacLow::GetDataTxVector (packet, hdr);
84  WifiTxVector txAdapter;
85  txAdapter.SetChannelWidth (10);
86  // the DataRate set by higher layer is the minimum data rate
87  // which is the lower bound for the actual data rate.
88  if (txHigher.GetMode ().GetDataRate (txHigher.GetChannelWidth ()) > txMac.GetMode ().GetDataRate (txMac.GetChannelWidth ()))
89  {
90  txAdapter.SetMode (txHigher.GetMode ());
91  txAdapter.SetPreambleType (txHigher.GetPreambleType ());
92  }
93  else
94  {
95  txAdapter.SetMode (txMac.GetMode ());
96  txAdapter.SetPreambleType (txMac.GetPreambleType ());
97  }
98  // the TxPwr_Level set by higher layer is the maximum transmit
99  // power which is the upper bound for the actual transmit power;
100  txAdapter.SetTxPowerLevel (std::min (txHigher.GetTxPowerLevel (), txMac.GetTxPowerLevel ()));
101 
102  return txAdapter;
103 }
104 
105 void
107  const WifiMacHeader* hdr,
109  Ptr<DcaTxop> dca)
110 {
111  NS_LOG_FUNCTION (this << packet << hdr << params << dca);
113  uint32_t curChannel = phy->GetChannelNumber ();
114  // if current channel access is not AlternatingAccess, just do as MacLow.
115  if (!m_scheduler->IsAlternatingAccessAssigned (curChannel))
116  {
117  MacLow::StartTransmission (packet, hdr, params, dca);
118  return;
119  }
120 
121  Time transmissionTime = MacLow::CalculateTransmissionTime (packet, hdr, params);
122  Time remainingTime = m_coordinator->NeedTimeToGuardInterval ();
123 
124  if (transmissionTime > remainingTime)
125  {
126  // The attempt for this transmission will be canceled;
127  // and this packet will be pending for next transmission by EdcaTxopN class
128  NS_LOG_DEBUG ("Because the required transmission time = " << transmissionTime.GetMilliSeconds ()
129  << "ms exceeds the remainingTime = " << remainingTime.GetMilliSeconds ()
130  << "ms, currently this packet will not be transmitted.");
131  }
132  else
133  {
134  MacLow::StartTransmission (packet, hdr, params, dca);
135  }
136 }
137 
138 } // namespace ns3
uint8_t GetChannelNumber(void) const
Return current channel number.
Definition: wifi-phy.cc:1496
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 "...
Ptr< WifiPhy > GetPhy(void) const
Definition: mac-low.cc:430
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
virtual void StartTransmission(Ptr< const Packet > packet, const WifiMacHeader *hdr, MacLowTransmissionParameters parameters, Ptr< DcaTxop > dca)
Definition: mac-low.cc:628
#define min(a, b)
Definition: 80211b.c:44
#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:201
static TypeId GetTypeId(void)
Get the type ID.
Definition: wave-mac-low.cc:33
Ptr< ChannelScheduler > m_scheduler
the channel scheduler
Definition: wave-mac-low.h:86
control how a packet is transmitted.
Definition: mac-low.h:54
uint8_t GetTxPowerLevel(void) const
This tag will be used to support higher layer control DataRate and TxPwr_Level for transmission...
Definition: higher-tx-tag.h:47
uint8_t GetChannelWidth(void) const
bool IsAdaptable(void) const
Ptr< ChannelCoordinator > GetChannelCoordinator(void) const
Time NeedTimeToGuardInterval(Time duration=Seconds(0.0)) const
tuple phy
Definition: third.py:86
virtual ~WaveMacLow()
Definition: wave-mac-low.cc:46
uint64_t GetDataRate(uint8_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:143
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:60
WifiTxVector GetTxVector(void) const
virtual void StartTransmission(Ptr< const Packet > packet, const WifiMacHeader *hdr, MacLowTransmissionParameters parameters, Ptr< DcaTxop > dca)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
Time CalculateTransmissionTime(Ptr< const Packet > packet, const WifiMacHeader *hdr, const MacLowTransmissionParameters &parameters) const
Definition: mac-low.cc:1356
void SetTxPowerLevel(uint8_t powerlevel)
Sets the selected transmission power level.
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
WifiPreamble GetPreambleType(void) 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:1269
handle RTS/CTS/DATA/ACK transactions.
Definition: mac-low.h:244
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:269
void SetChannelWidth(uint8_t channelWidth)
Sets the selected channelWidth (in MHz)
Ptr< ChannelCoordinator > m_coordinator
the channel coordinator
Definition: wave-mac-low.h:87
WifiMode GetMode(void) const
Ptr< ChannelScheduler > GetChannelScheduler(void) const
a unique identifier for an interface.
Definition: type-id.h:58
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:345
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914
Implements the IEEE 802.11 MAC header.
void SetWaveNetDevice(Ptr< WaveNetDevice > device)
Definition: wave-mac-low.cc:52