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  .AddConstructor<WaveMacLow> ()
38  ;
39  return tid;
40 }
42 {
43  NS_LOG_FUNCTION (this);
44 }
46 {
47  NS_LOG_FUNCTION (this);
48 }
49 
50 void
52 {
53  m_scheduler = device->GetChannelScheduler ();
55  NS_ASSERT (m_scheduler != 0 && m_coordinator != 0);
56 }
57 
60 {
61  NS_LOG_FUNCTION (this << packet << hdr);
62  HigherLayerTxVectorTag datatag;
63  bool found;
64  found = ConstCast<Packet> (packet)->PeekPacketTag (datatag);
65  // if high layer has not controlled transmit parameters, the real transmit parameters
66  // will be determined by MAC layer itself.
67  if (!found)
68  {
69  return MacLow::GetDataTxVector (packet, hdr);
70  }
71 
72  // if high layer has set the transmit parameters with non-adaption mode,
73  // the real transmit parameters are determined by high layer.
74  if (!datatag.IsAdaptable ())
75  {
76  return datatag.GetTxVector ();
77  }
78 
79  // if high layer has set the transmit parameters with non-adaption mode,
80  // the real transmit parameters are determined by both high layer and MAC layer.
81  WifiTxVector txHigher = datatag.GetTxVector ();
82  WifiTxVector txMac = MacLow::GetDataTxVector (packet, hdr);
83  WifiTxVector txAdapter;
84  // the DataRate set by higher layer is the minimum data rate
85  // which is the lower bound for the actual data rate.
86  if (txHigher.GetMode ().GetDataRate () > txMac.GetMode ().GetDataRate ())
87  {
88  txAdapter.SetMode (txHigher.GetMode ());
89  }
90  else
91  {
92  txAdapter.SetMode (txMac.GetMode ());
93  }
94  // the TxPwr_Level set by higher layer is the maximum transmit
95  // power which is the upper bound for the actual transmit power;
96  txAdapter.SetTxPowerLevel (std::min (txHigher.GetTxPowerLevel (), txMac.GetTxPowerLevel ()));
97 
98  return txAdapter;
99 }
100 
101 void
103  const WifiMacHeader* hdr,
105  MacLowTransmissionListener *listener)
106 {
107  NS_LOG_FUNCTION (this << packet << hdr << params << listener);
108  Ptr<WifiPhy> phy = MacLow::GetPhy ();
109  uint32_t curChannel = phy->GetChannelNumber ();
110  // if current channel access is not AlternatingAccess, just do as MacLow.
111  if (!m_scheduler->IsAlternatingAccessAssigned (curChannel))
112  {
113  MacLow::StartTransmission (packet, hdr, params, listener);
114  return;
115  }
116 
117  Time transmissionTime = MacLow::CalculateTransmissionTime (packet, hdr, params);
118  Time remainingTime = m_coordinator->NeedTimeToGuardInterval ();
119 
120  if (transmissionTime > remainingTime)
121  {
122  // The attempt for this transmission will be canceled;
123  // and this packet will be pending for next transmission by EdcaTxopN class
124  NS_LOG_DEBUG ("Because the required transmission time = " << transmissionTime.GetMilliSeconds ()
125  << "ms exceeds the remainingTime = " << remainingTime.GetMilliSeconds ()
126  << "ms, currently this packet will not be transmitted.");
127  }
128  else
129  {
130  MacLow::StartTransmission (packet, hdr, params, listener);
131  }
132 }
133 
134 } // namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:95
#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:499
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
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:61
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
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:58
control how a packet is transmitted.
Definition: mac-low.h:285
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
bool IsAdaptable(void) const
Ptr< ChannelCoordinator > GetChannelCoordinator(void) const
Time NeedTimeToGuardInterval(Time duration=Seconds(0.0)) const
virtual ~WaveMacLow()
Definition: wave-mac-low.cc:45
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:59
WifiTxVector GetTxVector(void) const
virtual void StartTransmission(Ptr< const Packet > packet, const WifiMacHeader *hdr, MacLowTransmissionParameters parameters, MacLowTransmissionListener *listener)
Definition: mac-low.cc:667
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:1330
virtual uint16_t GetChannelNumber(void) const =0
Return current channel number.
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:1248
handle RTS/CTS/DATA/ACK transactions.
Definition: mac-low.h:475
#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:51
uint64_t GetDataRate(void) const
Definition: wifi-mode.cc:79
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:331
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
Implements the IEEE 802.11 MAC header.
void SetWaveNetDevice(Ptr< WaveNetDevice > device)
Definition: wave-mac-low.cc:51