A Discrete-Event Network Simulator
API
txop.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #include "ns3/log.h"
22 #include "ns3/pointer.h"
23 #include "ns3/simulator.h"
24 #include "ns3/random-variable-stream.h"
25 #include "ns3/socket.h"
26 #include "txop.h"
27 #include "channel-access-manager.h"
28 #include "wifi-mac-queue.h"
29 #include "mac-tx-middle.h"
30 #include "mac-low.h"
32 #include "wifi-mac-trailer.h"
33 
34 #undef NS_LOG_APPEND_CONTEXT
35 #define NS_LOG_APPEND_CONTEXT if (m_low != 0) { std::clog << "[mac=" << m_low->GetAddress () << "] "; }
36 
37 namespace ns3 {
38 
40 
42 
43 TypeId
45 {
46  static TypeId tid = TypeId ("ns3::Txop")
48  .SetGroupName ("Wifi")
49  .AddConstructor<Txop> ()
50  .AddAttribute ("MinCw", "The minimum value of the contention window.",
51  UintegerValue (15),
54  MakeUintegerChecker<uint32_t> ())
55  .AddAttribute ("MaxCw", "The maximum value of the contention window.",
56  UintegerValue (1023),
59  MakeUintegerChecker<uint32_t> ())
60  .AddAttribute ("Aifsn", "The AIFSN: the default value conforms to non-QOS.",
61  UintegerValue (2),
64  MakeUintegerChecker<uint8_t> ())
65  .AddAttribute ("TxopLimit", "The TXOP limit: the default value conforms to non-QoS.",
66  TimeValue (MilliSeconds (0)),
69  MakeTimeChecker ())
70  .AddAttribute ("Queue", "The WifiMacQueue object",
71  PointerValue (),
73  MakePointerChecker<WifiMacQueue> ())
74  .AddTraceSource ("BackoffTrace",
75  "Trace source for backoff values",
77  "ns3::TracedCallback::Uint32Callback")
78  .AddTraceSource ("CwTrace",
79  "Trace source for contention window values",
81  "ns3::TracedValueCallback::Uint32")
82  ;
83  return tid;
84 }
85 
87  : m_channelAccessManager (0),
88  m_cwMin (0),
89  m_cwMax (0),
90  m_cw (0),
91  m_backoff (0),
92  m_accessRequested (false),
93  m_backoffSlots (0),
94  m_backoffStart (Seconds (0.0)),
95  m_currentPacket (0)
96 {
97  NS_LOG_FUNCTION (this);
98  m_queue = CreateObject<WifiMacQueue> ();
99  m_rng = CreateObject<UniformRandomVariable> ();
100 }
101 
103 {
104  NS_LOG_FUNCTION (this);
105 }
106 
107 void
109 {
110  NS_LOG_FUNCTION (this);
111  m_queue = 0;
112  m_low = 0;
113  m_stationManager = 0;
114  m_rng = 0;
115  m_txMiddle = 0;
117 }
118 
119 void
121 {
122  NS_LOG_FUNCTION (this << manager);
123  m_channelAccessManager = manager;
124  m_channelAccessManager->Add (this);
125 }
126 
127 void Txop::SetTxMiddle (const Ptr<MacTxMiddle> txMiddle)
128 {
129  NS_LOG_FUNCTION (this);
130  m_txMiddle = txMiddle;
131 }
132 
133 void
135 {
136  NS_LOG_FUNCTION (this << low);
137  m_low = low;
138 }
139 
140 void
142 {
143  NS_LOG_FUNCTION (this << remoteManager);
144  m_stationManager = remoteManager;
145 }
146 
147 void
149 {
150  NS_LOG_FUNCTION (this << &callback);
151  m_txOkCallback = callback;
152 }
153 
154 void
156 {
157  NS_LOG_FUNCTION (this << &callback);
158  m_txFailedCallback = callback;
159 }
160 
161 void
163 {
164  NS_LOG_FUNCTION (this << &callback);
165  m_txDroppedCallback = callback;
166  m_queue->TraceConnectWithoutContext ("Drop", MakeCallback (&Txop::TxDroppedPacket, this));
167 }
168 
169 void
171 {
172  if (!m_txDroppedCallback.IsNull ())
173  {
174  m_txDroppedCallback (item->GetPacket ());
175  }
176 }
177 
180 {
181  NS_LOG_FUNCTION (this);
182  return m_queue;
183 }
184 
185 void
186 Txop::SetMinCw (uint32_t minCw)
187 {
188  NS_LOG_FUNCTION (this << minCw);
189  bool changed = (m_cwMin != minCw);
190  m_cwMin = minCw;
191  if (changed == true)
192  {
193  ResetCw ();
194  m_cwTrace = GetCw ();
195  }
196 }
197 
198 void
199 Txop::SetMaxCw (uint32_t maxCw)
200 {
201  NS_LOG_FUNCTION (this << maxCw);
202  bool changed = (m_cwMax != maxCw);
203  m_cwMax = maxCw;
204  if (changed == true)
205  {
206  ResetCw ();
207  m_cwTrace = GetCw ();
208  }
209 }
210 
211 uint32_t
212 Txop::GetCw (void) const
213 {
214  return m_cw;
215 }
216 
217 void
219 {
220  NS_LOG_FUNCTION (this);
221  m_cw = m_cwMin;
222 }
223 
224 void
226 {
227  NS_LOG_FUNCTION (this);
228  //see 802.11-2012, section 9.19.2.5
229  m_cw = std::min ( 2 * (m_cw + 1) - 1, m_cwMax);
230 }
231 
232 uint32_t
234 {
235  return m_backoffSlots;
236 }
237 
238 Time
240 {
241  return m_backoffStart;
242 }
243 
244 void
245 Txop::UpdateBackoffSlotsNow (uint32_t nSlots, Time backoffUpdateBound)
246 {
247  NS_LOG_FUNCTION (this << nSlots << backoffUpdateBound);
248  m_backoffSlots -= nSlots;
249  m_backoffStart = backoffUpdateBound;
250  NS_LOG_DEBUG ("update slots=" << nSlots << " slots, backoff=" << m_backoffSlots);
251 }
252 
253 void
254 Txop::StartBackoffNow (uint32_t nSlots)
255 {
256  NS_LOG_FUNCTION (this << nSlots);
257  if (m_backoffSlots != 0)
258  {
259  NS_LOG_DEBUG ("reset backoff from " << m_backoffSlots << " to " << nSlots << " slots");
260  }
261  else
262  {
263  NS_LOG_DEBUG ("start backoff=" << nSlots << " slots");
264  }
265  m_backoffSlots = nSlots;
267 }
268 
269 void
270 Txop::SetAifsn (uint8_t aifsn)
271 {
272  NS_LOG_FUNCTION (this << +aifsn);
273  m_aifsn = aifsn;
274 }
275 
276 void
278 {
279  NS_LOG_FUNCTION (this << txopLimit);
280  NS_ASSERT_MSG ((txopLimit.GetMicroSeconds () % 32 == 0), "The TXOP limit must be expressed in multiple of 32 microseconds!");
281  m_txopLimit = txopLimit;
282 }
283 
284 uint32_t
285 Txop::GetMinCw (void) const
286 {
287  return m_cwMin;
288 }
289 
290 uint32_t
291 Txop::GetMaxCw (void) const
292 {
293  return m_cwMax;
294 }
295 
296 uint8_t
297 Txop::GetAifsn (void) const
298 {
299  return m_aifsn;
300 }
301 
302 Time
303 Txop::GetTxopLimit (void) const
304 {
305  return m_txopLimit;
306 }
307 
308 bool
310 {
311  bool ret = (m_currentPacket != 0 || !m_queue->IsEmpty ());
312  NS_LOG_FUNCTION (this << ret);
313  return ret;
314 }
315 
316 void
318 {
319  NS_LOG_FUNCTION (this << packet << &hdr);
320  // remove the priority tag attached, if any
321  SocketPriorityTag priorityTag;
322  packet->RemovePacketTag (priorityTag);
324  {
325  GenerateBackoff ();
326  }
327  m_queue->Enqueue (Create<WifiMacQueueItem> (packet, hdr));
329 }
330 
331 int64_t
332 Txop::AssignStreams (int64_t stream)
333 {
334  NS_LOG_FUNCTION (this << stream);
335  m_rng->SetStream (stream);
336  return 1;
337 }
338 
339 void
341 {
342  NS_LOG_FUNCTION (this);
343  if ((m_currentPacket != 0
344  || !m_queue->IsEmpty ())
345  && !IsAccessRequested ()
346  && !m_low->IsCfPeriod ())
347  {
349  }
350 }
351 
352 void
354 {
355  NS_LOG_FUNCTION (this);
356  if (m_currentPacket == 0
357  && !m_queue->IsEmpty ()
358  && !IsAccessRequested ()
359  && !m_low->IsCfPeriod ())
360  {
362  }
363 }
364 
366 Txop::GetLow (void) const
367 {
368  return m_low;
369 }
370 
371 void
373 {
374  NS_LOG_FUNCTION (this);
375  ResetCw ();
376  m_cwTrace = GetCw ();
377  GenerateBackoff ();
378 }
379 
380 bool
382 {
383  NS_LOG_FUNCTION (this);
384  return m_stationManager->NeedRetransmission (hdr.GetAddr1 (), &hdr, packet);
385 }
386 
387 bool
389 {
390  NS_LOG_FUNCTION (this);
391  return m_stationManager->NeedRetransmission (hdr.GetAddr1 (), &hdr, packet);
392 }
393 
394 bool
396 {
397  NS_LOG_FUNCTION (this);
400 }
401 
402 void
404 {
405  NS_LOG_FUNCTION (this);
407 }
408 
409 uint32_t
411 {
412  NS_LOG_FUNCTION (this);
415 }
416 
417 bool
419 {
420  NS_LOG_FUNCTION (this);
423 }
424 
425 uint32_t
427 {
428  NS_LOG_FUNCTION (this);
431 }
432 
433 uint32_t
435 {
436  NS_LOG_FUNCTION (this);
439 }
440 
443 {
444  NS_LOG_FUNCTION (this << hdr);
445  *hdr = m_currentHdr;
447  uint32_t startOffset = GetFragmentOffset ();
448  Ptr<Packet> fragment;
449  if (IsLastFragment ())
450  {
451  hdr->SetNoMoreFragments ();
452  }
453  else
454  {
455  hdr->SetMoreFragments ();
456  }
457  fragment = m_currentPacket->CreateFragment (startOffset,
458  GetFragmentSize ());
459  return fragment;
460 }
461 
462 bool
464 {
465  return m_accessRequested;
466 }
467 
468 void
470 {
471  NS_LOG_FUNCTION (this);
472  m_accessRequested = true;
473 }
474 
475 void
477 {
478  NS_LOG_FUNCTION (this);
480  m_accessRequested = false;
481  if (m_currentPacket == 0)
482  {
483  if (m_queue->IsEmpty ())
484  {
485  NS_LOG_DEBUG ("queue empty");
486  return;
487  }
488  Ptr<WifiMacQueueItem> item = m_queue->Dequeue ();
489  NS_ASSERT (item != 0);
490  m_currentPacket = item->GetPacket ();
491  m_currentHdr = item->GetHeader ();
492  NS_ASSERT (m_currentPacket != 0);
493  uint16_t sequence = m_txMiddle->GetNextSequenceNumberFor (&m_currentHdr);
494  m_currentHdr.SetSequenceNumber (sequence);
499  m_fragmentNumber = 0;
500  NS_LOG_DEBUG ("dequeued size=" << m_currentPacket->GetSize () <<
501  ", to=" << m_currentHdr.GetAddr1 () <<
502  ", seq=" << m_currentHdr.GetSequenceControl ());
503  }
504  if (m_currentHdr.GetAddr1 ().IsGroup ())
505  {
509  NS_LOG_DEBUG ("tx broadcast");
510  GetLow ()->StartTransmission (Create<WifiMacQueueItem> (m_currentPacket, m_currentHdr),
511  m_currentParams, this);
512  }
513  else
514  {
516  if (NeedFragmentation ())
517  {
519  WifiMacHeader hdr;
520  Ptr<Packet> fragment = GetFragmentPacket (&hdr);
521  if (IsLastFragment ())
522  {
523  NS_LOG_DEBUG ("fragmenting last fragment size=" << fragment->GetSize ());
525  }
526  else
527  {
528  NS_LOG_DEBUG ("fragmenting size=" << fragment->GetSize ());
530  }
531  GetLow ()->StartTransmission (Create<WifiMacQueueItem> (fragment, hdr),
532  m_currentParams, this);
533  }
534  else
535  {
537  if (m_stationManager->NeedRts (m_currentHdr, size) && !m_low->IsCfPeriod ())
538  {
540  }
541  else
542  {
544  }
546  GetLow ()->StartTransmission (Create<WifiMacQueueItem> (m_currentPacket, m_currentHdr),
547  m_currentParams, this);
548  }
549  }
550 }
551 
552 void
554 {
555  NS_LOG_FUNCTION (this);
556  m_backoff = m_rng->GetInteger (0, GetCw ());
559 }
560 
561 void
563 {
564  NS_LOG_FUNCTION (this);
565  GenerateBackoff ();
567 }
568 
569 void
571 {
572  NS_LOG_FUNCTION (this);
573  m_queue->Flush ();
574  m_currentPacket = 0;
575 }
576 
577 void
579 {
580  NS_LOG_FUNCTION (this);
581  if (m_currentPacket != 0)
582  {
583  m_queue->PushFront (Create<WifiMacQueueItem> (m_currentPacket, m_currentHdr));
584  m_currentPacket = 0;
585  }
586 }
587 
588 void
590 {
591  NS_LOG_FUNCTION (this);
592  m_queue->Flush ();
593  m_currentPacket = 0;
594 }
595 
596 void
598 {
599  NS_LOG_FUNCTION (this);
601 }
602 
603 void
605 {
606  NS_LOG_FUNCTION (this);
608 }
609 
610 void
612 {
613  NS_LOG_FUNCTION (this);
614  NS_LOG_DEBUG ("missed cts");
616  {
617  NS_LOG_DEBUG ("Cts Fail");
619  if (!m_txFailedCallback.IsNull ())
620  {
622  }
623  //to reset the Txop.
624  m_currentPacket = 0;
625  ResetCw ();
626  m_cwTrace = GetCw ();
627  }
628  else
629  {
630  UpdateFailedCw ();
631  m_cwTrace = GetCw ();
632  }
633  GenerateBackoff ();
635 }
636 
637 void
639 {
640  NS_LOG_FUNCTION (this);
641  if (!NeedFragmentation ()
642  || IsLastFragment ())
643  {
644  NS_LOG_DEBUG ("got ack. tx done.");
645  if (!m_txOkCallback.IsNull ())
646  {
648  }
649 
650  /* we are not fragmenting or we are done fragmenting
651  * so we can get rid of that packet now.
652  */
653  m_currentPacket = 0;
654  ResetCw ();
655  m_cwTrace = GetCw ();
656  GenerateBackoff ();
658  }
659  else
660  {
661  NS_LOG_DEBUG ("got ack. tx not done, size=" << m_currentPacket->GetSize ());
662  }
663 }
664 
665 void
667 {
668  NS_LOG_FUNCTION (this);
669  NS_LOG_DEBUG ("missed ack");
671  {
672  NS_LOG_DEBUG ("Ack Fail");
675  if (!m_txFailedCallback.IsNull ())
676  {
678  }
679  //to reset the Txop.
680  m_currentPacket = 0;
681  ResetCw ();
682  m_cwTrace = GetCw ();
683  }
684  else
685  {
686  NS_LOG_DEBUG ("Retransmit");
690  UpdateFailedCw ();
691  m_cwTrace = GetCw ();
692  }
693  GenerateBackoff ();
695 }
696 
697 void
699 {
700  NS_LOG_FUNCTION (this);
701  if (m_currentPacket != 0)
702  {
704  }
705  else
706  {
708  }
709 }
710 
711 void
712 Txop::MissedCfPollResponse (bool expectedCfAck)
713 {
714  NS_LOG_FUNCTION (this);
715  NS_LOG_DEBUG ("missed response to CF-POLL");
716  if (expectedCfAck)
717  {
719  {
720  NS_LOG_DEBUG ("Ack Fail");
723  m_currentPacket = 0;
724  }
725  else
726  {
727  NS_LOG_DEBUG ("Retransmit");
729  }
730  }
731  if (!m_txFailedCallback.IsNull ())
732  {
734  }
735 }
736 
737 void
739 {
740  NS_LOG_FUNCTION (this);
741  NS_LOG_DEBUG ("start next packet fragment");
742  /* this callback is used only for fragments. */
743  NextFragment ();
744  WifiMacHeader hdr;
745  Ptr<Packet> fragment = GetFragmentPacket (&hdr);
748  if (IsLastFragment ())
749  {
751  }
752  else
753  {
755  }
756  GetLow ()->StartTransmission (Create<WifiMacQueueItem> (fragment, hdr), m_currentParams, this);
757 }
758 
759 void
761 {
762  NS_LOG_FUNCTION (this);
763  NS_LOG_DEBUG ("transmission cancelled");
764 }
765 
766 void
768 {
769  NS_LOG_FUNCTION (this);
770  NS_LOG_DEBUG ("a transmission that did not require an ACK just finished");
771  m_currentPacket = 0;
772  ResetCw ();
773  m_cwTrace = GetCw ();
774  GenerateBackoff ();
775  if (!m_txOkCallback.IsNull ())
776  {
778  }
780 }
781 
782 void
784 {
785  NS_LOG_FUNCTION (this << frameType << addr);
786  NS_ASSERT (m_low->IsCfPeriod ());
787  if (m_currentPacket != 0 && frameType != WIFI_MAC_CTL_END)
788  {
790  {
793  m_currentPacket = 0;
794  }
795  else
796  {
798  }
799  }
800  else if ((m_queue->GetNPacketsByAddress (addr) > 0) && (frameType != WIFI_MAC_CTL_END)) //if no packet for that dest, send to another dest?
801  {
802  Ptr<WifiMacQueueItem> item = m_queue->DequeueByAddress (addr);
803  NS_ASSERT (item != 0);
804  m_currentPacket = item->GetPacket ();
805  m_currentHdr = item->GetHeader ();
806  uint16_t sequence = m_txMiddle->GetNextSequenceNumberFor (&m_currentHdr);
807  m_currentHdr.SetSequenceNumber (sequence);
811  }
812  else
813  {
814  m_currentPacket = Create<Packet> ();
816  }
817 
818  if (m_currentPacket->GetSize () > 0)
819  {
820  switch (frameType)
821  {
824  break;
825  case WIFI_MAC_DATA_NULL:
827  break;
828  default:
829  NS_ASSERT (false);
830  break;
831  }
832  }
833  else
834  {
835  m_currentHdr.SetType (frameType);
836  }
837  m_currentHdr.SetAddr1 (addr);
838  m_currentHdr.SetAddr2 (m_low->GetAddress ());
839  if (frameType == WIFI_MAC_DATA_NULL)
840  {
841  m_currentHdr.SetAddr3 (m_low->GetBssid ());
844  }
845  else
846  {
847  m_currentHdr.SetAddr3 (m_low->GetAddress ());
850  }
852 }
853 
854 bool
856 {
857  return (!m_channelAccessManager->IsBusy () && GetLow ()->CanTransmitNextCfFrame ());
858 }
859 
860 bool
862 {
863  return false;
864 }
865 
866 void
868 {
869  NS_LOG_WARN ("StartNext should not be called for non QoS!");
870 }
871 
872 void
873 Txop::GotBlockAck (const CtrlBAckResponseHeader *blockAck, Mac48Address recipient, double rxSnr, double dataSnr, WifiTxVector dataTxVector)
874 {
875  NS_LOG_WARN ("GotBlockAck should not be called for non QoS!");
876 }
877 
878 void
879 Txop::MissedBlockAck (uint8_t nMpdus)
880 {
881  NS_LOG_WARN ("MissedBlockAck should not be called for non QoS!");
882 }
883 
884 Time
886 {
887  NS_LOG_WARN ("GetTxopRemaining should not be called for non QoS!");
888  return Seconds (0);
889 }
890 
891 void
893 {
894  NS_LOG_WARN ("TerminateTxop should not be called for non QoS!");
895 }
896 
897 } //namespace ns3
TxFailed m_txFailedCallback
the transmit failed callback
Definition: txop.h:507
void SetRetry(void)
Set the Retry bit in the Frame Control field.
void SetMoreFragments(void)
Set the More Fragment bit in the Frame Control field.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
void SendCfFrame(WifiMacType frameType, Mac48Address addr)
Sends CF frame to STA with address addr.
Definition: txop.cc:783
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint8_t m_aifsn
the AIFSN
Definition: txop.h:528
Ptr< MacTxMiddle > m_txMiddle
the MacTxMiddle
Definition: txop.h:510
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
Callback template class.
Definition: callback.h:1278
TracedCallback< uint32_t > m_backoffTrace
backoff trace value
Definition: txop.h:535
TracedValue< uint32_t > m_cwTrace
CW trace value.
Definition: txop.h:536
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Time m_txopLimit
the TXOP limit time
Definition: txop.h:529
virtual void RestartAccessIfNeeded(void)
Restart access request if needed.
Definition: txop.cc:340
uint32_t GetInteger(uint32_t min, uint32_t max)
Get the next random value, as an unsigned integer in the specified range .
virtual void StartAccessIfNeeded(void)
Request access from Txop if needed.
Definition: txop.cc:353
uint8_t GetAifsn(void) const
Return the number of slots that make up an AIFS.
Definition: txop.cc:297
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
void ReportFinalDataFailed(Mac48Address address, const WifiMacHeader *header, uint32_t packetSize)
Should be invoked after calling ReportDataFailed if NeedRetransmission returns false.
#define min(a, b)
Definition: 80211b.c:42
virtual void StartNextPacket(void)
Start transmission for the next packet if allowed by the TxopLimit.
Definition: txop.cc:867
virtual void EndTxNoAck(void)
Event handler when a transmission that does not require an Ack has completed.
Definition: txop.cc:767
uint32_t m_backoffSlots
the number of backoff slots
Definition: txop.h:520
virtual bool HasFramesToTransmit(void)
Check if the Txop has frames to transmit.
Definition: txop.cc:309
virtual void StartNextFragment(void)
Start transmission for the next fragment.
Definition: txop.cc:738
uint32_t m_backoff
the current backoff
Definition: txop.h:518
uint32_t GetSize(void) const
Return the size of the WifiMacHeader in octets.
void SetChannelAccessManager(const Ptr< ChannelAccessManager > manager)
Set ChannelAccessManager this Txop is associated to.
Definition: txop.cc:120
void SetNoMoreFragments(void)
Un-set the More Fragment bit in the Frame Control Field.
Ptr< ChannelAccessManager > m_channelAccessManager
the channel access manager
Definition: txop.h:505
virtual void NotifyAccessGranted(void)
Notify the Txop that access has been granted.
Definition: txop.cc:476
virtual void MissedAck(void)
Event handler when an Ack is missed.
Definition: txop.cc:666
void SetTxDroppedCallback(TxDropped callback)
Definition: txop.cc:162
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
Definition: packet.cc:227
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
virtual void DoInitialize(void)
Initialize() implementation.
Definition: txop.cc:372
#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
static const uint16_t WIFI_MAC_FCS_LENGTH
The length in octects of the IEEE 802.11 MAC FCS field.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1286
Time GetBackoffStart(void) const
Return the time when the backoff procedure started.
Definition: txop.cc:239
bool IsBusy(void) const
Check if the device is busy sending or receiving, or NAV or CCA busy.
void RequestAccess(Ptr< Txop > txop, bool isCfPeriod=false)
virtual void Cancel(void)
Cancel the transmission.
Definition: txop.cc:760
void UpdateFragmentationThreshold(void)
Typically called to update the fragmentation threshold at the start of a new transmission.
bool IsLastFragment(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, uint32_t fragmentNumber)
Ptr< UniformRandomVariable > m_rng
the random stream
Definition: txop.h:513
void UpdateBackoffSlotsNow(uint32_t nSlots, Time backoffUpdateBound)
Update backoff slots that nSlots has passed.
Definition: txop.cc:245
bool CanStartNextPolling(void) const
Check if the next PCF transmission can fit in the remaining CFP duration.
Definition: txop.cc:855
virtual void GenerateBackoff(void)
Generate a new backoff now.
Definition: txop.cc:553
bool NeedBackoffUponAccess(Ptr< Txop > txop)
Determine if a new backoff needs to be generated when a packet is queued for transmission.
uint32_t GetMinCw(void) const
Return the minimum contention window size.
Definition: txop.cc:285
uint32_t m_cwMax
the maximum contention window
Definition: txop.h:516
virtual void GotBlockAck(const CtrlBAckResponseHeader *blockAck, Mac48Address recipient, double rxSnr, double dataSnr, WifiTxVector dataTxVector)
Event handler when a BlockAck is received.
Definition: txop.cc:873
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
virtual void NotifyOff(void)
When off operation occurs, the queue gets cleaned up.
Definition: txop.cc:589
void UpdateFailedCw(void)
Update the value of the CW variable to take into account a transmission failure.
Definition: txop.cc:225
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: pointer.h:227
void SetAddr1(Mac48Address address)
Fill the Address 1 field with the given address.
AttributeValue implementation for Time.
Definition: nstime.h:1342
void SetDsNotTo(void)
Un-set the To DS bit in the Frame Control field.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: txop.cc:332
void SetAddr3(Mac48Address address)
Fill the Address 3 field with the given address.
WifiMacType
Combination of valid MAC header type/subtype.
Hold an unsigned integer type.
Definition: uinteger.h:44
void NextFragment(void)
Continue to the next fragment.
Definition: txop.cc:403
indicates whether the socket has a priority set.
Definition: socket.h:1307
static TypeId GetTypeId(void)
Get the type ID.
Definition: txop.cc:44
bool NeedRetransmission(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet)
Headers for BlockAck response.
Definition: ctrl-headers.h:193
virtual bool IsAccessRequested(void) const
Definition: txop.cc:463
virtual bool IsQosTxop() const
Check for QoS TXOP.
Definition: txop.cc:861
bool NeedRts(const WifiMacHeader &header, uint32_t size)
virtual uint32_t GetNextFragmentSize(void) const
Calculate the size of the next fragment.
Definition: txop.cc:426
uint32_t m_cwMin
the minimum contention window
Definition: txop.h:515
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:387
uint32_t GetFragmentOffset(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, uint32_t fragmentNumber)
bool NeedRtsRetransmission(Ptr< const Packet > packet, const WifiMacHeader &hdr)
Check if RTS should be re-transmitted if CTS was missed.
Definition: txop.cc:381
void SetNoRetry(void)
Un-set the Retry bit in the Frame Control field.
Ptr< MacLow > GetLow(void) const
Return the MacLow associated with this Txop.
Definition: txop.cc:366
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void GotCfEnd(void)
Event handler when a CF-END frame is received.
Definition: txop.cc:698
uint32_t GetCw(void) const
Definition: txop.cc:212
Hold objects of type Ptr<T>.
Definition: pointer.h:36
virtual void NotifySleep(void)
When sleep operation occurs, if there is a pending packet transmission, it will be reinserted to the ...
Definition: txop.cc:578
void EnableAck(void)
Wait ACKTimeout for an Ack.
void SetAddr2(Mac48Address address)
Fill the Address 2 field with the given address.
uint32_t GetMaxCw(void) const
Return the maximum contention window size.
Definition: txop.cc:291
virtual void MissedBlockAck(uint8_t nMpdus)
Event handler when a BlockAck timeout has occurred.
Definition: txop.cc:879
uint32_t GetFragmentSize(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, uint32_t fragmentNumber)
virtual void NotifyOn(void)
When on operation occurs, channel access will be started.
Definition: txop.cc:604
Ptr< WifiMacQueue > m_queue
the wifi MAC queue
Definition: txop.h:509
virtual void DoDispose(void)
Destructor implementation.
Definition: txop.cc:108
an EUI-48 address
Definition: mac48-address.h:43
bool NeedDataRetransmission(Ptr< const Packet > packet, const WifiMacHeader &hdr)
Check if Data should be re-transmitted if Ack was missed.
Definition: txop.cc:388
Ptr< const Packet > m_currentPacket
the current packet
Definition: txop.h:531
void SetMacLow(const Ptr< MacLow > low)
Set MacLow associated with this Txop.
Definition: txop.cc:134
virtual bool NeedFragmentation(void) const
Check if the current packet should be fragmented.
Definition: txop.cc:395
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: nstime.h:1343
virtual Ptr< Packet > GetFragmentPacket(WifiMacHeader *hdr)
Get the next fragment from the packet with appropriate Wifi header for the fragment.
Definition: txop.cc:442
virtual void NotifyChannelSwitching(void)
When a channel switching occurs, enqueued packets are removed.
Definition: txop.cc:570
bool IsGroup(void) const
void DisableRts(void)
Do not send RTS and wait for CTS before sending data.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
virtual void NotifyInternalCollision(void)
Notify the Txop that internal collision has occurred.
Definition: txop.cc:562
Ptr< MacLow > m_low
the MacLow
Definition: txop.h:511
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:88
virtual bool IsLastFragment(void) const
Check if the current fragment is the last fragment.
Definition: txop.cc:418
void TxDroppedPacket(Ptr< const WifiMacQueueItem > item)
Pass the packet included in the wifi MAC queue item to the packet dropped callback.
Definition: txop.cc:170
void SetType(WifiMacType type, bool resetToDsFromDs=true)
Set Type/Subtype values with the correct values depending on the given type.
uint32_t m_cw
the current contention window
Definition: txop.h:517
void ReportDataFailed(Mac48Address address, const WifiMacHeader *header, uint32_t packetSize)
Should be invoked whenever the AckTimeout associated to a transmission attempt expires.
Txop()
Definition: txop.cc:86
MacLowTransmissionParameters m_currentParams
current transmission parameters
Definition: txop.h:533
void SetSequenceNumber(uint16_t seq)
Set the sequence number of the header.
void SetMinCw(uint32_t minCw)
Set the minimum contention window size.
Definition: txop.cc:186
void EnableRts(void)
Send a RTS, and wait CTSTimeout for a CTS.
void SetMaxCw(uint32_t maxCw)
Set the maximum contention window size.
Definition: txop.cc:199
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:265
bool m_accessRequested
flag whether channel access is already requested
Definition: txop.h:519
void SetTxopLimit(Time txopLimit)
Set the TXOP limit.
Definition: txop.cc:277
Time m_backoffStart
the backoffStart variable is used to keep track of the time at which a backoff was started or the tim...
Definition: txop.h:526
virtual void GotAck(void)
Event handler when an Ack is received.
Definition: txop.cc:638
virtual void MissedCts(void)
Event handler when a CTS timeout has occurred.
Definition: txop.cc:611
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Definition: packet.cc:963
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
void SetTxMiddle(const Ptr< MacTxMiddle > txMiddle)
Set MacTxMiddle this Txop is associated to.
Definition: txop.cc:127
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1278
uint32_t GetBackoffSlots(void) const
Return the current number of backoff slots.
Definition: txop.cc:233
Ptr< WifiMacQueue > GetWifiMacQueue() const
Return the packet queue associated with this Txop.
Definition: txop.cc:179
virtual Time GetTxopRemaining(void) const
Return the remaining duration in the current TXOP.
Definition: txop.cc:885
void MissedCfPollResponse(bool expectedCfAck)
Event handler when a response to a CF-POLL frame is missed.
Definition: txop.cc:712
bool NeedFragmentation(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet)
void SetDsTo(void)
Set the To DS bit in the Frame Control field.
TxOk m_txOkCallback
the transmit OK callback
Definition: txop.h:506
void DisableNextData(void)
Do not attempt to send data burst after current transmission.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:472
virtual void SetWifiRemoteStationManager(const Ptr< WifiRemoteStationManager > remoteManager)
Set WifiRemoteStationsManager this Txop is associated to.
Definition: txop.cc:141
void SetDsFrom(void)
Set the From DS bit in the Frame Control field.
uint8_t m_fragmentNumber
the fragment number
Definition: txop.h:534
void SetAifsn(uint8_t aifsn)
Set the number of slots that make up an AIFS.
Definition: txop.cc:270
A base class which provides memory management and object aggregation.
Definition: object.h:87
virtual void NotifyAccessRequested(void)
Notify that access request has been received.
Definition: txop.cc:469
WifiMacHeader m_currentHdr
the current header
Definition: txop.h:532
virtual void TerminateTxop(void)
Update backoff and restart access if needed.
Definition: txop.cc:892
void SetTxFailedCallback(TxFailed callback)
Definition: txop.cc:155
virtual ~Txop()
Definition: txop.cc:102
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1386
Ptr< WifiRemoteStationManager > m_stationManager
the wifi remote station manager
Definition: txop.h:512
virtual uint32_t GetFragmentOffset(void) const
Calculate the offset for the current fragment.
Definition: txop.cc:434
void SetTxOkCallback(TxOk callback)
Definition: txop.cc:148
void SetFragmentNumber(uint8_t frag)
Set the fragment number of the header.
void DisableAck(void)
Do not wait for Ack after data transmission.
virtual void Queue(Ptr< Packet > packet, const WifiMacHeader &hdr)
Definition: txop.cc:317
virtual uint32_t GetFragmentSize(void) const
Calculate the size of the current fragment.
Definition: txop.cc:410
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: uinteger.h:45
void ResetCw(void)
Update the value of the CW variable to take into account a transmission success or a transmission abo...
Definition: txop.cc:218
a unique identifier for an interface.
Definition: type-id.h:58
void ReportFinalRtsFailed(Mac48Address address, const WifiMacHeader *header)
Should be invoked after calling ReportRtsFailed if NeedRetransmission returns false.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
void StartBackoffNow(uint32_t nSlots)
Definition: txop.cc:254
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1642
virtual void NotifyWakeUp(void)
When wake up operation occurs, channel access will be restarted.
Definition: txop.cc:597
Implements the IEEE 802.11 MAC header.
TxDropped m_txDroppedCallback
the packet dropped callback
Definition: txop.h:508
uint16_t GetSequenceControl(void) const
Return the raw Sequence Control field.
void SetDsNotFrom(void)
Un-set the From DS bit in the Frame Control field.
Handle packet fragmentation and retransmissions for data and management frames.
Definition: txop.h:66
Time GetTxopLimit(void) const
Return the TXOP limit.
Definition: txop.cc:303