A Discrete-Event Network Simulator
API
wave-frame-exchange-manager.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2020 Universita' degli Studi di Napoli Federico II
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Stefano Avallone <stavallo@unina.it>
19  */
20 
21 #include "ns3/log.h"
22 #include "ns3/abort.h"
23 #include "ns3/wifi-protection.h"
24 #include "ns3/wifi-acknowledgment.h"
26 #include "higher-tx-tag.h"
27 
28 
29 namespace ns3 {
30 
31 NS_LOG_COMPONENT_DEFINE ("WaveFrameExchangeManager");
32 
33 NS_OBJECT_ENSURE_REGISTERED (WaveFrameExchangeManager);
34 
35 TypeId
37 {
38  static TypeId tid = TypeId ("ns3::WaveFrameExchangeManager")
40  .AddConstructor<WaveFrameExchangeManager> ()
41  .SetGroupName ("Wave")
42  ;
43  return tid;
44 }
45 
47 {
48  NS_LOG_FUNCTION (this);
49 }
50 
52 {
54 }
55 
56 void
58 {
59  m_scheduler = device->GetChannelScheduler ();
61  NS_ASSERT (m_scheduler != 0 && m_coordinator != 0);
62 }
63 
66 {
67  NS_LOG_FUNCTION (this << *item);
68  HigherLayerTxVectorTag datatag;
69  bool found;
70  found = ConstCast<Packet> (item->GetPacket ())->PeekPacketTag (datatag);
71  // if high layer has not controlled transmit parameters, the real transmit parameters
72  // will be determined by MAC layer itself.
73  if (!found)
74  {
75  return m_mac->GetWifiRemoteStationManager ()->GetDataTxVector (item->GetHeader ());
76  }
77 
78  // if high layer has set the transmit parameters with non-adaption mode,
79  // the real transmit parameters are determined by high layer.
80  if (!datatag.IsAdaptable ())
81  {
82  return datatag.GetTxVector ();
83  }
84 
85  // if high layer has set the transmit parameters with non-adaption mode,
86  // the real transmit parameters are determined by both high layer and MAC layer.
87  WifiTxVector txHigher = datatag.GetTxVector ();
88  WifiTxVector txMac = m_mac->GetWifiRemoteStationManager ()->GetDataTxVector (item->GetHeader ());
89  WifiTxVector txAdapter;
90  txAdapter.SetChannelWidth (10);
91  // the DataRate set by higher layer is the minimum data rate
92  // which is the lower bound for the actual data rate.
93  if (txHigher.GetMode ().GetDataRate (txHigher.GetChannelWidth ()) > txMac.GetMode ().GetDataRate (txMac.GetChannelWidth ()))
94  {
95  txAdapter.SetMode (txHigher.GetMode ());
96  txAdapter.SetPreambleType (txHigher.GetPreambleType ());
97  }
98  else
99  {
100  txAdapter.SetMode (txMac.GetMode ());
101  txAdapter.SetPreambleType (txMac.GetPreambleType ());
102  }
103  // the TxPwr_Level set by higher layer is the maximum transmit
104  // power which is the upper bound for the actual transmit power;
105  txAdapter.SetTxPowerLevel (std::min (txHigher.GetTxPowerLevel (), txMac.GetTxPowerLevel ()));
106 
107  return txAdapter;
108 }
109 
110 bool
112 {
113  NS_LOG_FUNCTION (this << dcf);
114 
115  uint32_t curChannel = m_phy->GetChannelNumber ();
116  // if current channel access is not AlternatingAccess, just do as FrameExchangeManager.
117  if (m_scheduler == 0 || !m_scheduler->IsAlternatingAccessAssigned (curChannel))
118  {
120  }
121 
122  m_txTimer.Cancel ();
123  m_dcf = dcf;
124 
125  Ptr<WifiMacQueue> queue = dcf->GetWifiMacQueue ();
126 
127  if (queue->IsEmpty ())
128  {
129  NS_LOG_DEBUG ("Queue empty");
131  m_dcf = 0;
132  return false;
133  }
134 
136  Ptr<WifiMacQueueItem> mpdu = *queue->Peek ()->GetQueueIterator ();
137  NS_ASSERT (mpdu != 0);
138 
139  // assign a sequence number if this is not a fragment nor a retransmission
140  if (!mpdu->IsFragment () && !mpdu->GetHeader ().IsRetry ())
141  {
142  uint16_t sequence = m_txMiddle->GetNextSequenceNumberFor (&mpdu->GetHeader ());
143  mpdu->GetHeader ().SetSequenceNumber (sequence);
144  }
145 
146  WifiTxParameters txParams;
147  txParams.m_txVector = GetDataTxVector (mpdu);
148  Time remainingTime = m_coordinator->NeedTimeToGuardInterval ();
149 
150  if (!TryAddMpdu (mpdu, txParams, remainingTime))
151  {
152  // The attempt for this transmission will be canceled;
153  // and this packet will be pending for next transmission by QosTxop class
154  NS_LOG_DEBUG ("Because the required transmission time exceeds the remainingTime = "
155  << remainingTime.As (Time::MS)
156  << ", currently this packet will not be transmitted.");
157  }
158  else
159  {
160  SendMpduWithProtection (mpdu, txParams);
161  return true;
162  }
163  return false;
164 }
165 
166 void
168 {
169  NS_LOG_FUNCTION (this);
170  m_scheduler = 0;
171  m_coordinator = 0;
173 }
174 
175 } //namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::FrameExchangeManager::m_txTimer
WifiTxTimer m_txTimer
the timer set upon frame transmission
Definition: frame-exchange-manager.h:379
ns3::WifiTxVector::SetTxPowerLevel
void SetTxPowerLevel(uint8_t powerlevel)
Sets the selected transmission power level.
Definition: wifi-tx-vector.cc:242
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
NS_ASSERT
#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
ns3::FrameExchangeManager::m_phy
Ptr< WifiPhy > m_phy
the PHY layer on this station
Definition: frame-exchange-manager.h:385
min
#define min(a, b)
Definition: 80211b.c:42
ns3::Txop::NotifyChannelReleased
virtual void NotifyChannelReleased(void)
Called by the FrameExchangeManager to notify the completion of the transmissions.
Definition: txop.cc:355
ns3::WifiMacHeader::IsRetry
bool IsRetry(void) const
Return if the Retry bit is set.
Definition: wifi-mac-header.cc:789
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::WifiMacHeader::SetSequenceNumber
void SetSequenceNumber(uint16_t seq)
Set the sequence number of the header.
Definition: wifi-mac-header.cc:312
ns3::WaveFrameExchangeManager::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: wave-frame-exchange-manager.cc:36
ns3::WaveFrameExchangeManager::WaveFrameExchangeManager
WaveFrameExchangeManager()
Definition: wave-frame-exchange-manager.cc:46
ns3::HigherLayerTxVectorTag
This tag will be used to support higher layer control DataRate and TxPwr_Level for transmission.
Definition: higher-tx-tag.h:48
ns3::WifiPhy::GetChannelNumber
uint8_t GetChannelNumber(void) const
Return current channel number.
Definition: wifi-phy.cc:1199
ns3::WifiTxVector::SetMode
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
Definition: wifi-tx-vector.cc:226
ns3::WifiTxVector
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Definition: wifi-tx-vector.h:71
ns3::Time::As
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:429
ns3::WifiTxParameters
This class stores the TX parameters (TX vector, protection mechanism, acknowledgment mechanism,...
Definition: wifi-tx-parameters.h:45
ns3::WaveNetDevice::GetChannelCoordinator
Ptr< ChannelCoordinator > GetChannelCoordinator(void) const
Definition: wave-net-device.cc:491
ns3::WifiMacQueueItem::GetHeader
const WifiMacHeader & GetHeader(void) const
Get the header stored in this item.
Definition: wifi-mac-queue-item.cc:65
ns3::Txop::NotifyChannelAccessed
virtual void NotifyChannelAccessed(Time txopDuration=Seconds(0))
Called by the FrameExchangeManager to notify that channel access has been granted for the given amoun...
Definition: txop.cc:348
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::WaveFrameExchangeManager::m_scheduler
Ptr< ChannelScheduler > m_scheduler
the channel scheduler
Definition: wave-frame-exchange-manager.h:81
ns3::WaveFrameExchangeManager::StartTransmission
virtual bool StartTransmission(Ptr< Txop > dcf)
Request the FrameExchangeManager to start a frame exchange sequence.
Definition: wave-frame-exchange-manager.cc:111
ns3::WaveFrameExchangeManager::SetWaveNetDevice
void SetWaveNetDevice(Ptr< WaveNetDevice > device)
Definition: wave-frame-exchange-manager.cc:57
ns3::Ptr< WaveNetDevice >
ns3::QosFrameExchangeManager
QosFrameExchangeManager handles the frame exchange sequences for QoS stations.
Definition: qos-frame-exchange-manager.h:37
ns3::WaveFrameExchangeManager::GetDataTxVector
virtual WifiTxVector GetDataTxVector(Ptr< const WifiMacQueueItem > item) const
Return a TXVECTOR for the DATA frame given the destination.
Definition: wave-frame-exchange-manager.cc:65
ns3::WaveFrameExchangeManager::DoDispose
virtual void DoDispose(void)
Destructor implementation.
Definition: wave-frame-exchange-manager.cc:167
ns3::WaveNetDevice::GetChannelScheduler
Ptr< ChannelScheduler > GetChannelScheduler(void) const
Definition: wave-net-device.cc:481
wave-frame-exchange-manager.h
ns3::Txop::GetWifiMacQueue
Ptr< WifiMacQueue > GetWifiMacQueue() const
Return the packet queue associated with this Txop.
Definition: txop.cc:154
ns3::WifiTxVector::GetPreambleType
WifiPreamble GetPreambleType(void) const
Definition: wifi-tx-vector.cc:148
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::HigherLayerTxVectorTag::IsAdaptable
bool IsAdaptable(void) const
Definition: higher-tx-tag.cc:72
ns3::WifiTxVector::SetChannelWidth
void SetChannelWidth(uint16_t channelWidth)
Sets the selected channelWidth (in MHz)
Definition: wifi-tx-vector.cc:254
higher-tx-tag.h
ns3::WifiTxVector::GetChannelWidth
uint16_t GetChannelWidth(void) const
Definition: wifi-tx-vector.cc:154
ns3::FrameExchangeManager::StartTransmission
virtual bool StartTransmission(Ptr< Txop > dcf)
Request the FrameExchangeManager to start a frame exchange sequence.
Definition: frame-exchange-manager.cc:259
NS_LOG_FUNCTION_NOARGS
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition: log-macros-enabled.h:209
ns3::WaveFrameExchangeManager::~WaveFrameExchangeManager
virtual ~WaveFrameExchangeManager()
Definition: wave-frame-exchange-manager.cc:51
ns3::FrameExchangeManager::m_txMiddle
Ptr< MacTxMiddle > m_txMiddle
the MAC TX Middle on this station
Definition: frame-exchange-manager.h:382
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
ns3::WifiTxParameters::m_txVector
WifiTxVector m_txVector
TXVECTOR of the frame being prepared.
Definition: wifi-tx-parameters.h:62
ns3::FrameExchangeManager::SendMpduWithProtection
void SendMpduWithProtection(Ptr< WifiMacQueueItem > mpdu, WifiTxParameters &txParams)
Send an MPDU with the given TX parameters (with the specified protection).
Definition: frame-exchange-manager.cc:345
ns3::FrameExchangeManager::m_mac
Ptr< RegularWifiMac > m_mac
the MAC layer on this station
Definition: frame-exchange-manager.h:381
ns3::WifiTxVector::GetTxPowerLevel
uint8_t GetTxPowerLevel(void) const
Definition: wifi-tx-vector.cc:142
ns3::WaveFrameExchangeManager::m_coordinator
Ptr< ChannelCoordinator > m_coordinator
the channel coordinator
Definition: wave-frame-exchange-manager.h:82
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
ns3::FrameExchangeManager::DoDispose
void DoDispose() override
Destructor implementation.
Definition: frame-exchange-manager.cc:83
ns3::QosFrameExchangeManager::TryAddMpdu
bool TryAddMpdu(Ptr< const WifiMacQueueItem > mpdu, WifiTxParameters &txParams, Time availableTime) const
Recompute the protection and acknowledgment methods to use if the given MPDU is added to the frame be...
Definition: qos-frame-exchange-manager.cc:310
ns3::WifiMacQueueItem::IsFragment
bool IsFragment(void) const
Return true if this item contains an MSDU fragment, false otherwise.
Definition: wifi-mac-queue-item.cc:101
ns3::WifiMode::GetDataRate
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:100
ns3::ChannelCoordinator::NeedTimeToGuardInterval
Time NeedTimeToGuardInterval(Time duration=Seconds(0.0)) const
Definition: channel-coordinator.cc:265
ns3::HigherLayerTxVectorTag::GetTxVector
WifiTxVector GetTxVector(void) const
Definition: higher-tx-tag.cc:65
ns3::WifiTxTimer::Cancel
void Cancel(void)
Cancel the timer.
Definition: wifi-tx-timer.cc:100
ns3::WifiTxVector::SetPreambleType
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
Definition: wifi-tx-vector.cc:248
ns3::Time::MS
@ MS
millisecond
Definition: nstime.h:116
ns3::WifiTxVector::GetMode
WifiMode GetMode(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the selected payload transmission mode.
Definition: wifi-tx-vector.cc:112
ns3::FrameExchangeManager::m_dcf
Ptr< Txop > m_dcf
the DCF/EDCAF that gained channel access
Definition: frame-exchange-manager.h:378