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_access (NOT_REQUESTED),
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  }
195 }
196 
197 void
198 Txop::SetMaxCw (uint32_t maxCw)
199 {
200  NS_LOG_FUNCTION (this << maxCw);
201  bool changed = (m_cwMax != maxCw);
202  m_cwMax = maxCw;
203  if (changed == true)
204  {
205  ResetCw ();
206  }
207 }
208 
209 uint32_t
210 Txop::GetCw (void) const
211 {
212  return m_cw;
213 }
214 
215 void
217 {
218  NS_LOG_FUNCTION (this);
219  m_cw = m_cwMin;
220  m_cwTrace = m_cw;
221 }
222 
223 void
225 {
226  NS_LOG_FUNCTION (this);
227  //see 802.11-2012, section 9.19.2.5
228  m_cw = std::min ( 2 * (m_cw + 1) - 1, m_cwMax);
229  m_cwTrace = m_cw;
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  && m_access == NOT_REQUESTED
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  && m_access == NOT_REQUESTED
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  GenerateBackoff ();
377 }
378 
379 bool
381 {
382  NS_LOG_FUNCTION (this);
383  return m_stationManager->NeedRetransmission (Create<const WifiMacQueueItem> (packet, hdr));
384 }
385 
386 bool
388 {
389  NS_LOG_FUNCTION (this);
390  return m_stationManager->NeedRetransmission (Create<const WifiMacQueueItem> (packet, hdr));
391 }
392 
393 bool
395 {
396  NS_LOG_FUNCTION (this);
397  return m_stationManager->NeedFragmentation (Create<const WifiMacQueueItem> (m_currentPacket, m_currentHdr));
398 }
399 
400 void
402 {
403  NS_LOG_FUNCTION (this);
405 }
406 
407 uint32_t
409 {
410  NS_LOG_FUNCTION (this);
411  return m_stationManager->GetFragmentSize (Create<const WifiMacQueueItem> (m_currentPacket,
413 }
414 
415 bool
417 {
418  NS_LOG_FUNCTION (this);
419  return m_stationManager->IsLastFragment (Create<const WifiMacQueueItem> (m_currentPacket,
421 }
422 
423 uint32_t
425 {
426  NS_LOG_FUNCTION (this);
427  return m_stationManager->GetFragmentSize (Create<const WifiMacQueueItem> (m_currentPacket,
429 }
430 
431 uint32_t
433 {
434  NS_LOG_FUNCTION (this);
435  return m_stationManager->GetFragmentOffset (Create<const WifiMacQueueItem> (m_currentPacket,
437 }
438 
441 {
442  NS_LOG_FUNCTION (this << hdr);
443  *hdr = m_currentHdr;
445  uint32_t startOffset = GetFragmentOffset ();
446  Ptr<Packet> fragment;
447  if (IsLastFragment ())
448  {
449  hdr->SetNoMoreFragments ();
450  }
451  else
452  {
453  hdr->SetMoreFragments ();
454  }
455  fragment = m_currentPacket->CreateFragment (startOffset,
456  GetFragmentSize ());
457  return fragment;
458 }
459 
462 {
463  return m_access;
464 }
465 
466 void
468 {
469  NS_LOG_FUNCTION (this);
471 }
472 
473 void
475 {
476  NS_LOG_FUNCTION (this);
477  m_access = GRANTED;
478 }
479 
480 void
482 {
483  NS_LOG_FUNCTION (this);
485  GenerateBackoff ();
486  if (HasFramesToTransmit ())
487  {
489  }
490 }
491 
492 void
494 {
495  if (m_access == NOT_REQUESTED)
496  {
498  }
499 }
500 
501 void
503 {
504  NS_LOG_FUNCTION (this);
505 // NS_ASSERT (m_access == REQUESTED); FEM may have changed m_access to GRANTED
507  if (m_currentPacket == 0)
508  {
509  if (m_queue->IsEmpty ())
510  {
511  NS_LOG_DEBUG ("queue empty");
512  return;
513  }
514  Ptr<WifiMacQueueItem> item = m_queue->Dequeue ();
515  NS_ASSERT (item != 0);
516  m_currentPacket = item->GetPacket ();
517  m_currentHdr = item->GetHeader ();
518  NS_ASSERT (m_currentPacket != 0);
519  uint16_t sequence = m_txMiddle->GetNextSequenceNumberFor (&m_currentHdr);
520  m_currentHdr.SetSequenceNumber (sequence);
525  m_fragmentNumber = 0;
526  NS_LOG_DEBUG ("dequeued size=" << m_currentPacket->GetSize () <<
527  ", to=" << m_currentHdr.GetAddr1 () <<
528  ", seq=" << m_currentHdr.GetSequenceControl ());
529  }
530  if (m_currentHdr.GetAddr1 ().IsGroup ())
531  {
535  NS_LOG_DEBUG ("tx broadcast");
536  GetLow ()->StartTransmission (Create<WifiMacQueueItem> (m_currentPacket, m_currentHdr),
537  m_currentParams, this);
538  }
539  else
540  {
542  if (NeedFragmentation ())
543  {
545  WifiMacHeader hdr;
546  Ptr<Packet> fragment = GetFragmentPacket (&hdr);
547  if (IsLastFragment ())
548  {
549  NS_LOG_DEBUG ("fragmenting last fragment size=" << fragment->GetSize ());
551  }
552  else
553  {
554  NS_LOG_DEBUG ("fragmenting size=" << fragment->GetSize ());
556  }
557  GetLow ()->StartTransmission (Create<WifiMacQueueItem> (fragment, hdr),
558  m_currentParams, this);
559  }
560  else
561  {
563  if (m_stationManager->NeedRts (m_currentHdr, size) && !m_low->IsCfPeriod ())
564  {
566  }
567  else
568  {
570  }
572  GetLow ()->StartTransmission (Create<WifiMacQueueItem> (m_currentPacket, m_currentHdr),
573  m_currentParams, this);
574  }
575  }
576 }
577 
578 void
580 {
581  NS_LOG_FUNCTION (this);
582  m_backoff = m_rng->GetInteger (0, GetCw ());
585 }
586 
587 void
589 {
590  NS_LOG_FUNCTION (this);
591  GenerateBackoff ();
593 }
594 
595 void
597 {
598  NS_LOG_FUNCTION (this);
599  m_queue->Flush ();
600  m_currentPacket = 0;
601 }
602 
603 void
605 {
606  NS_LOG_FUNCTION (this);
607  if (m_currentPacket != 0)
608  {
609  m_queue->PushFront (Create<WifiMacQueueItem> (m_currentPacket, m_currentHdr));
610  m_currentPacket = 0;
611  }
612 }
613 
614 void
616 {
617  NS_LOG_FUNCTION (this);
618  m_queue->Flush ();
619  m_currentPacket = 0;
620 }
621 
622 void
624 {
625  NS_LOG_FUNCTION (this);
627 }
628 
629 void
631 {
632  NS_LOG_FUNCTION (this);
634 }
635 
636 void
638 {
639  NS_LOG_FUNCTION (this);
640  NS_LOG_DEBUG ("missed cts");
642  {
643  NS_LOG_DEBUG ("Cts Fail");
645  if (!m_txFailedCallback.IsNull ())
646  {
648  }
649  //to reset the Txop.
650  m_currentPacket = 0;
651  ResetCw ();
652  }
653  else
654  {
655  UpdateFailedCw ();
656  }
657  GenerateBackoff ();
659 }
660 
661 void
663 {
664  NS_LOG_FUNCTION (this);
665  if (!NeedFragmentation ()
666  || IsLastFragment ())
667  {
668  NS_LOG_DEBUG ("got ack. tx done.");
669  if (!m_txOkCallback.IsNull ())
670  {
672  }
673 
674  /* we are not fragmenting or we are done fragmenting
675  * so we can get rid of that packet now.
676  */
677  m_currentPacket = 0;
678  ResetCw ();
679  GenerateBackoff ();
681  }
682  else
683  {
684  NS_LOG_DEBUG ("got ack. tx not done, size=" << m_currentPacket->GetSize ());
685  }
686 }
687 
688 void
690 {
691  NS_LOG_FUNCTION (this);
692  NS_LOG_DEBUG ("missed ack");
694  {
695  NS_LOG_DEBUG ("Ack Fail");
696  m_stationManager->ReportFinalDataFailed (Create<const WifiMacQueueItem> (m_currentPacket,
697  m_currentHdr));
698  if (!m_txFailedCallback.IsNull ())
699  {
701  }
702  //to reset the Txop.
703  m_currentPacket = 0;
704  ResetCw ();
705  }
706  else
707  {
708  NS_LOG_DEBUG ("Retransmit");
709  m_stationManager->ReportDataFailed (Create<const WifiMacQueueItem> (m_currentPacket,
710  m_currentHdr));
712  UpdateFailedCw ();
713  }
714  GenerateBackoff ();
716 }
717 
718 void
720 {
721  NS_LOG_FUNCTION (this);
722  if (m_currentPacket != 0)
723  {
725  }
726  else
727  {
729  }
730 }
731 
732 void
733 Txop::MissedCfPollResponse (bool expectedCfAck)
734 {
735  NS_LOG_FUNCTION (this);
736  NS_LOG_DEBUG ("missed response to CF-POLL");
737  if (expectedCfAck)
738  {
740  {
741  NS_LOG_DEBUG ("Ack Fail");
742  m_stationManager->ReportFinalDataFailed (Create<const WifiMacQueueItem> (m_currentPacket,
743  m_currentHdr));
744  m_currentPacket = 0;
745  }
746  else
747  {
748  NS_LOG_DEBUG ("Retransmit");
750  }
751  }
752  if (!m_txFailedCallback.IsNull ())
753  {
755  }
756 }
757 
758 void
760 {
761  NS_LOG_FUNCTION (this);
762  NS_LOG_DEBUG ("start next packet fragment");
763  /* this callback is used only for fragments. */
764  NextFragment ();
765  WifiMacHeader hdr;
766  Ptr<Packet> fragment = GetFragmentPacket (&hdr);
769  if (IsLastFragment ())
770  {
772  }
773  else
774  {
776  }
777  GetLow ()->StartTransmission (Create<WifiMacQueueItem> (fragment, hdr), m_currentParams, this);
778 }
779 
780 void
782 {
783  NS_LOG_FUNCTION (this);
784  NS_LOG_DEBUG ("transmission cancelled");
785 }
786 
787 void
789 {
790  NS_LOG_FUNCTION (this);
791  NS_LOG_DEBUG ("a transmission that did not require an ACK just finished");
792  m_currentPacket = 0;
793  ResetCw ();
794  GenerateBackoff ();
795  if (!m_txOkCallback.IsNull ())
796  {
798  }
800 }
801 
802 void
804 {
805  NS_LOG_FUNCTION (this << frameType << addr);
806  NS_ASSERT (m_low->IsCfPeriod ());
807  if (m_currentPacket != 0 && frameType != WIFI_MAC_CTL_END)
808  {
810  {
811  m_stationManager->ReportFinalDataFailed (Create<const WifiMacQueueItem> (m_currentPacket,
812  m_currentHdr));
813  m_currentPacket = 0;
814  }
815  else
816  {
818  }
819  }
820  else if ((m_queue->GetNPacketsByAddress (addr) > 0) && (frameType != WIFI_MAC_CTL_END)) //if no packet for that dest, send to another dest?
821  {
822  Ptr<WifiMacQueueItem> item = m_queue->DequeueByAddress (addr);
823  NS_ASSERT (item != 0);
824  m_currentPacket = item->GetPacket ();
825  m_currentHdr = item->GetHeader ();
826  uint16_t sequence = m_txMiddle->GetNextSequenceNumberFor (&m_currentHdr);
827  m_currentHdr.SetSequenceNumber (sequence);
831  }
832  else
833  {
834  m_currentPacket = Create<Packet> ();
836  }
837 
838  if (m_currentPacket->GetSize () > 0)
839  {
840  switch (frameType)
841  {
844  break;
845  case WIFI_MAC_DATA_NULL:
847  break;
848  default:
849  NS_ASSERT (false);
850  break;
851  }
852  }
853  else
854  {
855  m_currentHdr.SetType (frameType);
856  }
857  m_currentHdr.SetAddr1 (addr);
858  m_currentHdr.SetAddr2 (m_low->GetAddress ());
859  if (frameType == WIFI_MAC_DATA_NULL)
860  {
861  m_currentHdr.SetAddr3 (m_low->GetBssid ());
864  }
865  else
866  {
867  m_currentHdr.SetAddr3 (m_low->GetAddress ());
870  }
872 }
873 
874 bool
876 {
877  return (!m_channelAccessManager->IsBusy () && GetLow ()->CanTransmitNextCfFrame ());
878 }
879 
880 bool
882 {
883  return false;
884 }
885 
886 void
888 {
889  NS_LOG_WARN ("StartNext should not be called for non QoS!");
890 }
891 
892 void
893 Txop::GotBlockAck (const CtrlBAckResponseHeader *blockAck, Mac48Address recipient, double rxSnr, double dataSnr, WifiTxVector dataTxVector)
894 {
895  NS_LOG_WARN ("GotBlockAck should not be called for non QoS!");
896 }
897 
898 void
899 Txop::MissedBlockAck (uint8_t nMpdus)
900 {
901  NS_LOG_WARN ("MissedBlockAck should not be called for non QoS!");
902 }
903 
904 Time
906 {
907  NS_LOG_WARN ("GetTxopRemaining should not be called for non QoS!");
908  return Seconds (0);
909 }
910 
911 void
913 {
914  NS_LOG_WARN ("TerminateTxop should not be called for non QoS!");
915 }
916 
917 } //namespace ns3
TxFailed m_txFailedCallback
the transmit failed callback
Definition: txop.h:531
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:803
#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:552
Ptr< MacTxMiddle > m_txMiddle
the MacTxMiddle
Definition: txop.h:534
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:559
TracedValue< uint32_t > m_cwTrace
CW trace value.
Definition: txop.h:560
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:553
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
#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:887
virtual void EndTxNoAck(void)
Event handler when a transmission that does not require an Ack has completed.
Definition: txop.cc:788
uint32_t m_backoffSlots
the number of backoff slots
Definition: txop.h:544
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:759
uint32_t m_backoff
the current backoff
Definition: txop.h:542
void RequestAccess(void)
Request access to the ChannelAccessManager.
Definition: txop.cc:493
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:529
virtual void NotifyAccessGranted(void)
Notify the Txop that access has been granted.
Definition: txop.cc:502
virtual void MissedAck(void)
Event handler when an Ack is missed.
Definition: txop.cc:689
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
void ReportFinalDataFailed(Ptr< const WifiMacQueueItem > mpdu)
Should be invoked after calling ReportDataFailed if NeedRetransmission returns false.
#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:1297
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 ReportDataFailed(Ptr< const WifiMacQueueItem > mpdu)
Should be invoked whenever the AckTimeout associated to a transmission attempt expires.
void RequestAccess(Ptr< Txop > txop, bool isCfPeriod=false)
virtual void Cancel(void)
Cancel the transmission.
Definition: txop.cc:781
void UpdateFragmentationThreshold(void)
Typically called to update the fragmentation threshold at the start of a new transmission.
Ptr< UniformRandomVariable > m_rng
the random stream
Definition: txop.h:537
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:875
virtual void GenerateBackoff(void)
Generate a new backoff now.
Definition: txop.cc:579
virtual ChannelAccessStatus GetAccessStatus(void) const
Definition: txop.cc:461
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:540
bool NeedFragmentation(Ptr< const WifiMacQueueItem > mpdu)
bool NeedRetransmission(Ptr< const WifiMacQueueItem > mpdu)
virtual void GotBlockAck(const CtrlBAckResponseHeader *blockAck, Mac48Address recipient, double rxSnr, double dataSnr, WifiTxVector dataTxVector)
Event handler when a BlockAck is received.
Definition: txop.cc:893
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:615
ChannelAccessStatus
Enumeration for channel access status.
Definition: txop.h:100
void UpdateFailedCw(void)
Update the value of the CW variable to take into account a transmission failure.
Definition: txop.cc:224
const WifiMacHeader & GetHeader(void) const
Get the header stored in this item.
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.
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition: simulator.h:588
AttributeValue implementation for Time.
Definition: nstime.h:1353
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:401
indicates whether the socket has a priority set.
Definition: socket.h:1307
virtual void NotifyChannelReleased(void)
Called by the FrameExchangeManager to notify the completion of the transmissions. ...
Definition: txop.cc:481
static TypeId GetTypeId(void)
Get the type ID.
Definition: txop.cc:44
Headers for BlockAck response.
Definition: ctrl-headers.h:193
ChannelAccessStatus m_access
channel access status
Definition: txop.h:543
virtual bool IsQosTxop() const
Check for QoS TXOP.
Definition: txop.cc:881
bool NeedRts(const WifiMacHeader &header, uint32_t size)
virtual uint32_t GetNextFragmentSize(void) const
Calculate the size of the next fragment.
Definition: txop.cc:424
uint32_t m_cwMin
the minimum contention window
Definition: txop.h:539
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:388
Ptr< const Packet > GetPacket(void) const
Get the packet stored in this item.
bool NeedRtsRetransmission(Ptr< const Packet > packet, const WifiMacHeader &hdr)
Check if RTS should be re-transmitted if CTS was missed.
Definition: txop.cc:380
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:719
uint32_t GetCw(void) const
Definition: txop.cc:210
bool IsLastFragment(Ptr< const WifiMacQueueItem > mpdu, uint32_t fragmentNumber)
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:604
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:899
virtual void NotifyOn(void)
When on operation occurs, channel access will be started.
Definition: txop.cc:630
Ptr< WifiMacQueue > m_queue
the wifi MAC queue
Definition: txop.h:533
uint32_t GetFragmentOffset(Ptr< const WifiMacQueueItem > mpdu, uint32_t fragmentNumber)
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:387
Ptr< const Packet > m_currentPacket
the current packet
Definition: txop.h:555
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:394
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:1354
virtual Ptr< Packet > GetFragmentPacket(WifiMacHeader *hdr)
Get the next fragment from the packet with appropriate Wifi header for the fragment.
Definition: txop.cc:440
virtual void NotifyChannelSwitching(void)
When a channel switching occurs, enqueued packets are removed.
Definition: txop.cc:596
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:588
Ptr< MacLow > m_low
the MacLow
Definition: txop.h:535
void ReportFinalRtsFailed(const WifiMacHeader &header)
Should be invoked after calling ReportRtsFailed if NeedRetransmission returns false.
#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:416
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:541
Txop()
Definition: txop.cc:86
MacLowTransmissionParameters m_currentParams
current transmission parameters
Definition: txop.h:557
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:198
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:265
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:550
virtual void GotAck(void)
Event handler when an Ack is received.
Definition: txop.cc:662
virtual void MissedCts(void)
Event handler when a CTS timeout has occurred.
Definition: txop.cc:637
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:1289
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:905
void MissedCfPollResponse(bool expectedCfAck)
Event handler when a response to a CF-POLL frame is missed.
Definition: txop.cc:733
void SetDsTo(void)
Set the To DS bit in the Frame Control field.
TxOk m_txOkCallback
the transmit OK callback
Definition: txop.h:530
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:533
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:558
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:467
WifiMacHeader m_currentHdr
the current header
Definition: txop.h:556
virtual void TerminateTxop(void)
Update backoff and restart access if needed.
Definition: txop.cc:912
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:536
virtual uint32_t GetFragmentOffset(void) const
Calculate the offset for the current fragment.
Definition: txop.cc:432
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:408
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:216
uint32_t GetFragmentSize(Ptr< const WifiMacQueueItem > mpdu, uint32_t fragmentNumber)
a unique identifier for an interface.
Definition: type-id.h:58
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:623
Implements the IEEE 802.11 MAC header.
TxDropped m_txDroppedCallback
the packet dropped callback
Definition: txop.h:532
virtual void NotifyChannelAccessed(void)
Called by the FrameExchangeManager to notify that channel access has been granted.
Definition: txop.cc:474
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