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 (), txHigher.IsShortGuardInterval (), 1) > txMac.GetMode ().GetDataRate (txMac.GetChannelWidth (), txMac.IsShortGuardInterval (), 1))
89  {
90  txAdapter.SetMode (txHigher.GetMode ());
91  }
92  else
93  {
94  txAdapter.SetMode (txMac.GetMode ());
95  }
96  // the TxPwr_Level set by higher layer is the maximum transmit
97  // power which is the upper bound for the actual transmit power;
98  txAdapter.SetTxPowerLevel (std::min (txHigher.GetTxPowerLevel (), txMac.GetTxPowerLevel ()));
99 
100  return txAdapter;
101 }
102 
103 void
105  const WifiMacHeader* hdr,
107  MacLowTransmissionListener *listener)
108 {
109  NS_LOG_FUNCTION (this << packet << hdr << params << listener);
111  uint32_t curChannel = phy->GetChannelNumber ();
112  // if current channel access is not AlternatingAccess, just do as MacLow.
113  if (!m_scheduler->IsAlternatingAccessAssigned (curChannel))
114  {
115  MacLow::StartTransmission (packet, hdr, params, listener);
116  return;
117  }
118 
119  Time transmissionTime = MacLow::CalculateTransmissionTime (packet, hdr, params);
120  Time remainingTime = m_coordinator->NeedTimeToGuardInterval ();
121 
122  if (transmissionTime > remainingTime)
123  {
124  // The attempt for this transmission will be canceled;
125  // and this packet will be pending for next transmission by EdcaTxopN class
126  NS_LOG_DEBUG ("Because the required transmission time = " << transmissionTime.GetMilliSeconds ()
127  << "ms exceeds the remainingTime = " << remainingTime.GetMilliSeconds ()
128  << "ms, currently this packet will not be transmitted.");
129  }
130  else
131  {
132  MacLow::StartTransmission (packet, hdr, params, listener);
133  }
134 }
135 
136 } // namespace ns3
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:528
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:44
#define min(a, b)
Definition: 80211b.c:44
virtual void StartTransmission(Ptr< const Packet > packet, const WifiMacHeader *hdr, MacLowTransmissionParameters parameters, MacLowTransmissionListener *listener)
#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
bool IsShortGuardInterval(void) const
static TypeId GetTypeId(void)
Definition: wave-mac-low.cc:33
Ptr< ChannelScheduler > m_scheduler
Definition: wave-mac-low.h:82
listen to events coming from ns3::MacLow.
Definition: mac-low.h:63
control how a packet is transmitted.
Definition: mac-low.h:311
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:45
void SetChannelWidth(uint32_t channelWidth)
Sets the selected channelWidth (in MHz)
bool IsAdaptable(void) const
Ptr< ChannelCoordinator > GetChannelCoordinator(void) const
Time NeedTimeToGuardInterval(Time duration=Seconds(0.0)) const
virtual uint16_t GetChannelNumber(void) const
Return current channel number.
Definition: wifi-phy.cc:1329
tuple phy
Definition: third.py:86
virtual ~WaveMacLow()
Definition: wave-mac-low.cc:46
uint32_t GetChannelWidth(void) const
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, MacLowTransmissionListener *listener)
Definition: mac-low.cc:724
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Time CalculateTransmissionTime(Ptr< const Packet > packet, const WifiMacHeader *hdr, const MacLowTransmissionParameters &parameters) const
Definition: mac-low.cc:1477
uint64_t GetDataRate(uint32_t channelWidth, bool isShortGuardInterval, uint8_t nss) const
Definition: wifi-mode.cc:109
void SetTxPowerLevel(uint8_t powerlevel)
Sets the selected transmission power level.
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
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:1381
handle RTS/CTS/DATA/ACK transactions.
Definition: mac-low.h:500
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
Ptr< ChannelCoordinator > m_coordinator
Definition: wave-mac-low.h:83
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:904
Implements the IEEE 802.11 MAC header.
void SetWaveNetDevice(Ptr< WaveNetDevice > device)
Definition: wave-mac-low.cc:52