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 
33 #undef NS_LOG_APPEND_CONTEXT
34 #define NS_LOG_APPEND_CONTEXT if (m_low != 0) { std::clog << "[mac=" << m_low->GetAddress () << "] "; }
35 
36 namespace ns3 {
37 
39 
41 
42 TypeId
44 {
45  static TypeId tid = TypeId ("ns3::Txop")
47  .SetGroupName ("Wifi")
48  .AddConstructor<Txop> ()
49  .AddAttribute ("MinCw", "The minimum value of the contention window.",
50  UintegerValue (15),
53  MakeUintegerChecker<uint32_t> ())
54  .AddAttribute ("MaxCw", "The maximum value of the contention window.",
55  UintegerValue (1023),
58  MakeUintegerChecker<uint32_t> ())
59  .AddAttribute ("Aifsn", "The AIFSN: the default value conforms to non-QOS.",
60  UintegerValue (2),
63  MakeUintegerChecker<uint8_t> ())
64  .AddAttribute ("TxopLimit", "The TXOP limit: the default value conforms to non-QoS.",
65  TimeValue (MilliSeconds (0)),
68  MakeTimeChecker ())
69  .AddAttribute ("Queue", "The WifiMacQueue object",
70  PointerValue (),
72  MakePointerChecker<WifiMacQueue> ())
73  .AddTraceSource ("BackoffTrace",
74  "Trace source for backoff values",
76  "ns3::TracedCallback::Uint32Callback")
77  .AddTraceSource ("CwTrace",
78  "Trace source for contention window values",
80  "ns3::TracedValueCallback::Uint32")
81  ;
82  return tid;
83 }
84 
86  : m_channelAccessManager (0),
87  m_cwMin (0),
88  m_cwMax (0),
89  m_cw (0),
90  m_backoff (0),
91  m_accessRequested (false),
92  m_backoffSlots (0),
93  m_backoffStart (Seconds (0.0)),
94  m_currentPacket (0)
95 {
96  NS_LOG_FUNCTION (this);
97  m_queue = CreateObject<WifiMacQueue> ();
98  m_rng = CreateObject<UniformRandomVariable> ();
99 }
100 
102 {
103  NS_LOG_FUNCTION (this);
104 }
105 
106 void
108 {
109  NS_LOG_FUNCTION (this);
110  m_queue = 0;
111  m_low = 0;
112  m_stationManager = 0;
113  m_rng = 0;
114  m_txMiddle = 0;
116 }
117 
118 void
120 {
121  NS_LOG_FUNCTION (this << manager);
122  m_channelAccessManager = manager;
123  m_channelAccessManager->Add (this);
124 }
125 
126 void Txop::SetTxMiddle (const Ptr<MacTxMiddle> txMiddle)
127 {
128  NS_LOG_FUNCTION (this);
129  m_txMiddle = txMiddle;
130 }
131 
132 void
134 {
135  NS_LOG_FUNCTION (this << low);
136  m_low = low;
137 }
138 
139 void
141 {
142  NS_LOG_FUNCTION (this << remoteManager);
143  m_stationManager = remoteManager;
144 }
145 
146 void
148 {
149  NS_LOG_FUNCTION (this << &callback);
150  m_txOkCallback = callback;
151 }
152 
153 void
155 {
156  NS_LOG_FUNCTION (this << &callback);
157  m_txFailedCallback = callback;
158 }
159 
160 void
162 {
163  NS_LOG_FUNCTION (this << &callback);
164  m_txDroppedCallback = callback;
165  m_queue->TraceConnectWithoutContext ("Drop", MakeCallback (&Txop::TxDroppedPacket, this));
166 }
167 
168 void
170 {
171  if (!m_txDroppedCallback.IsNull ())
172  {
173  m_txDroppedCallback (item->GetPacket ());
174  }
175 }
176 
179 {
180  NS_LOG_FUNCTION (this);
181  return m_queue;
182 }
183 
184 void
185 Txop::SetMinCw (uint32_t minCw)
186 {
187  NS_LOG_FUNCTION (this << minCw);
188  bool changed = (m_cwMin != minCw);
189  m_cwMin = minCw;
190  if (changed == true)
191  {
192  ResetCw ();
193  m_cwTrace = GetCw ();
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  m_cwTrace = GetCw ();
207  }
208 }
209 
210 uint32_t
211 Txop::GetCw (void) const
212 {
213  return m_cw;
214 }
215 
216 void
218 {
219  NS_LOG_FUNCTION (this);
220  m_cw = m_cwMin;
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 }
230 
231 uint32_t
233 {
234  return m_backoffSlots;
235 }
236 
237 Time
239 {
240  return m_backoffStart;
241 }
242 
243 void
244 Txop::UpdateBackoffSlotsNow (uint32_t nSlots, Time backoffUpdateBound)
245 {
246  NS_LOG_FUNCTION (this << nSlots << backoffUpdateBound);
247  m_backoffSlots -= nSlots;
248  m_backoffStart = backoffUpdateBound;
249  NS_LOG_DEBUG ("update slots=" << nSlots << " slots, backoff=" << m_backoffSlots);
250 }
251 
252 void
253 Txop::StartBackoffNow (uint32_t nSlots)
254 {
255  NS_LOG_FUNCTION (this << nSlots);
256  if (m_backoffSlots != 0)
257  {
258  NS_LOG_DEBUG ("reset backoff from " << m_backoffSlots << " to " << nSlots << " slots");
259  }
260  else
261  {
262  NS_LOG_DEBUG ("start backoff=" << nSlots << " slots");
263  }
264  m_backoffSlots = nSlots;
266 }
267 
268 void
269 Txop::SetAifsn (uint8_t aifsn)
270 {
271  NS_LOG_FUNCTION (this << +aifsn);
272  m_aifsn = aifsn;
273 }
274 
275 void
277 {
278  NS_LOG_FUNCTION (this << txopLimit);
279  NS_ASSERT_MSG ((txopLimit.GetMicroSeconds () % 32 == 0), "The TXOP limit must be expressed in multiple of 32 microseconds!");
280  m_txopLimit = txopLimit;
281 }
282 
283 uint32_t
284 Txop::GetMinCw (void) const
285 {
286  return m_cwMin;
287 }
288 
289 uint32_t
290 Txop::GetMaxCw (void) const
291 {
292  return m_cwMax;
293 }
294 
295 uint8_t
296 Txop::GetAifsn (void) const
297 {
298  return m_aifsn;
299 }
300 
301 Time
302 Txop::GetTxopLimit (void) const
303 {
304  return m_txopLimit;
305 }
306 
307 bool
309 {
310  bool ret = (m_currentPacket != 0 || !m_queue->IsEmpty ());
311  NS_LOG_FUNCTION (this << ret);
312  return ret;
313 }
314 
315 void
317 {
318  NS_LOG_FUNCTION (this << packet << &hdr);
319  // remove the priority tag attached, if any
320  SocketPriorityTag priorityTag;
321  packet->RemovePacketTag (priorityTag);
322  m_stationManager->PrepareForQueue (hdr.GetAddr1 (), &hdr, packet);
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  {
538 
540  m_currentPacket, dataTxVector)
541  && !m_low->IsCfPeriod ())
542  {
544  }
545  else
546  {
548  }
550  GetLow ()->StartTransmission (Create<WifiMacQueueItem> (m_currentPacket, m_currentHdr),
551  m_currentParams, this);
552  }
553  }
554 }
555 
556 void
558 {
559  NS_LOG_FUNCTION (this);
560  m_backoff = m_rng->GetInteger (0, GetCw ());
563 }
564 
565 void
567 {
568  NS_LOG_FUNCTION (this);
569  GenerateBackoff ();
571 }
572 
573 void
575 {
576  NS_LOG_FUNCTION (this);
577  m_queue->Flush ();
578  m_currentPacket = 0;
579 }
580 
581 void
583 {
584  NS_LOG_FUNCTION (this);
585  if (m_currentPacket != 0)
586  {
587  m_queue->PushFront (Create<WifiMacQueueItem> (m_currentPacket, m_currentHdr));
588  m_currentPacket = 0;
589  }
590 }
591 
592 void
594 {
595  NS_LOG_FUNCTION (this);
596  m_queue->Flush ();
597  m_currentPacket = 0;
598 }
599 
600 void
602 {
603  NS_LOG_FUNCTION (this);
605 }
606 
607 void
609 {
610  NS_LOG_FUNCTION (this);
612 }
613 
614 void
616 {
617  NS_LOG_FUNCTION (this);
618  NS_LOG_DEBUG ("missed cts");
620  {
621  NS_LOG_DEBUG ("Cts Fail");
623  if (!m_txFailedCallback.IsNull ())
624  {
626  }
627  //to reset the dcf.
628  m_currentPacket = 0;
629  ResetCw ();
630  m_cwTrace = GetCw ();
631  }
632  else
633  {
634  UpdateFailedCw ();
635  m_cwTrace = GetCw ();
636  }
637  GenerateBackoff ();
639 }
640 
641 void
643 {
644  NS_LOG_FUNCTION (this);
645  if (!NeedFragmentation ()
646  || IsLastFragment ())
647  {
648  NS_LOG_DEBUG ("got ack. tx done.");
649  if (!m_txOkCallback.IsNull ())
650  {
652  }
653 
654  /* we are not fragmenting or we are done fragmenting
655  * so we can get rid of that packet now.
656  */
657  m_currentPacket = 0;
658  ResetCw ();
659  m_cwTrace = GetCw ();
660  GenerateBackoff ();
662  }
663  else
664  {
665  NS_LOG_DEBUG ("got ack. tx not done, size=" << m_currentPacket->GetSize ());
666  }
667 }
668 
669 void
671 {
672  NS_LOG_FUNCTION (this);
673  NS_LOG_DEBUG ("missed ack");
675  {
676  NS_LOG_DEBUG ("Ack Fail");
679  if (!m_txFailedCallback.IsNull ())
680  {
682  }
683  //to reset the dcf.
684  m_currentPacket = 0;
685  ResetCw ();
686  m_cwTrace = GetCw ();
687  }
688  else
689  {
690  NS_LOG_DEBUG ("Retransmit");
694  UpdateFailedCw ();
695  m_cwTrace = GetCw ();
696  }
697  GenerateBackoff ();
699 }
700 
701 void
703 {
704  NS_LOG_FUNCTION (this);
705  if (m_currentPacket != 0)
706  {
708  }
709  else
710  {
712  }
713 }
714 
715 void
716 Txop::MissedCfPollResponse (bool expectedCfAck)
717 {
718  NS_LOG_FUNCTION (this);
719  NS_LOG_DEBUG ("missed response to CF-POLL");
720  if (expectedCfAck)
721  {
723  {
724  NS_LOG_DEBUG ("Ack Fail");
727  m_currentPacket = 0;
728  }
729  else
730  {
731  NS_LOG_DEBUG ("Retransmit");
733  }
734  }
735  if (!m_txFailedCallback.IsNull ())
736  {
738  }
739 }
740 
741 void
743 {
744  NS_LOG_FUNCTION (this);
745  NS_LOG_DEBUG ("start next packet fragment");
746  /* this callback is used only for fragments. */
747  NextFragment ();
748  WifiMacHeader hdr;
749  Ptr<Packet> fragment = GetFragmentPacket (&hdr);
752  if (IsLastFragment ())
753  {
755  }
756  else
757  {
759  }
760  GetLow ()->StartTransmission (Create<WifiMacQueueItem> (fragment, hdr), m_currentParams, this);
761 }
762 
763 void
765 {
766  NS_LOG_FUNCTION (this);
767  NS_LOG_DEBUG ("transmission cancelled");
768 }
769 
770 void
772 {
773  NS_LOG_FUNCTION (this);
774  NS_LOG_DEBUG ("a transmission that did not require an ACK just finished");
775  m_currentPacket = 0;
776  ResetCw ();
777  m_cwTrace = GetCw ();
778  GenerateBackoff ();
779  if (!m_txOkCallback.IsNull ())
780  {
782  }
784 }
785 
786 void
788 {
789  NS_LOG_FUNCTION (this << frameType << addr);
790  NS_ASSERT (m_low->IsCfPeriod ());
791  if (m_currentPacket != 0 && frameType != WIFI_MAC_CTL_END)
792  {
794  {
797  m_currentPacket = 0;
798  }
799  else
800  {
802  }
803  }
804  else if ((m_queue->GetNPacketsByAddress (addr) > 0) && (frameType != WIFI_MAC_CTL_END)) //if no packet for that dest, send to another dest?
805  {
806  Ptr<WifiMacQueueItem> item = m_queue->DequeueByAddress (addr);
807  NS_ASSERT (item != 0);
808  m_currentPacket = item->GetPacket ();
809  m_currentHdr = item->GetHeader ();
810  uint16_t sequence = m_txMiddle->GetNextSequenceNumberFor (&m_currentHdr);
811  m_currentHdr.SetSequenceNumber (sequence);
815  }
816  else
817  {
818  m_currentPacket = Create<Packet> ();
820  }
821 
822  if (m_currentPacket->GetSize () > 0)
823  {
824  switch (frameType)
825  {
828  break;
829  case WIFI_MAC_DATA_NULL:
831  break;
832  default:
833  NS_ASSERT (false);
834  break;
835  }
836  }
837  else
838  {
839  m_currentHdr.SetType (frameType);
840  }
841  m_currentHdr.SetAddr1 (addr);
842  m_currentHdr.SetAddr2 (m_low->GetAddress ());
843  if (frameType == WIFI_MAC_DATA_NULL)
844  {
845  m_currentHdr.SetAddr3 (m_low->GetBssid ());
848  }
849  else
850  {
851  m_currentHdr.SetAddr3 (m_low->GetAddress ());
854  }
856 }
857 
858 bool
860 {
861  return (!m_channelAccessManager->IsBusy () && GetLow ()->CanTransmitNextCfFrame ());
862 }
863 
864 bool
866 {
867  return false;
868 }
869 
870 void
872 {
873  NS_LOG_WARN ("StartNext should not be called for non QoS!");
874 }
875 
876 void
877 Txop::GotBlockAck (const CtrlBAckResponseHeader *blockAck, Mac48Address recipient, double rxSnr, WifiMode txMode, double dataSnr)
878 {
879  NS_LOG_WARN ("GotBlockAck should not be called for non QoS!");
880 }
881 
882 void
883 Txop::MissedBlockAck (uint8_t nMpdus)
884 {
885  NS_LOG_WARN ("MissedBlockAck should not be called for non QoS!");
886 }
887 
888 Time
890 {
891  NS_LOG_WARN ("GetTxopRemaining should not be called for non QoS!");
892  return Seconds (0);
893 }
894 
895 void
897 {
898  NS_LOG_WARN ("TerminateTxop should not be called for non QoS!");
899 }
900 
901 } //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:102
void SendCfFrame(WifiMacType frameType, Mac48Address addr)
Sends CF frame to sta with address addr.
Definition: txop.cc:787
#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:1273
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
virtual void StartAccessIfNeeded(void)
Request access from DCF manager if needed.
Definition: txop.cc:353
uint8_t GetAifsn(void) const
Return the number of slots that make up an AIFS.
Definition: txop.cc:296
#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.
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
#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:871
virtual void EndTxNoAck(void)
Event handler when a transmission that does not require an ACK has completed.
Definition: txop.cc:771
uint32_t m_backoffSlots
the backoff slots
Definition: txop.h:520
virtual bool HasFramesToTransmit(void)
Check if the DCF has frames to transmit.
Definition: txop.cc:308
virtual void StartNextFragment(void)
Start transmission for the next fragment.
Definition: txop.cc:742
uint32_t m_backoff
the current backoff
Definition: txop.h:518
void SetChannelAccessManager(const Ptr< ChannelAccessManager > manager)
Set ChannelAccessManager this Txop is associated to.
Definition: txop.cc:119
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 DCF that access has been granted.
Definition: txop.cc:476
virtual void MissedAck(void)
Event handler when an ACK is missed.
Definition: txop.cc:670
void SetTxDroppedCallback(TxDropped callback)
Definition: txop.cc:161
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
#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:1072
Time GetBackoffStart(void) const
Return the time when the backoff procedure started.
Definition: txop.cc:238
bool IsBusy(void) const
Check if the device is busy sending or receiving, or NAV or CCA busy.
virtual void Cancel(void)
Cancel the transmission.
Definition: txop.cc:764
bool NeedRts(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, WifiTxVector txVector)
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:244
bool CanStartNextPolling(void) const
Check if the next PCF transmission can fit in the remaining CFP duration.
Definition: txop.cc:859
void PrepareForQueue(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet)
virtual void GenerateBackoff(void)
Generate a new backoff now.
Definition: txop.cc:557
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:284
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
uint32_t m_cwMax
the CW maximum
Definition: txop.h:516
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:593
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:449
void UpdateFailedCw(void)
Update the value of the CW variable to take into account a transmission failure.
Definition: txop.cc:224
virtual uint32_t GetInteger(void)=0
Get the next random value as an integer drawn from the distribution.
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:1126
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:43
bool NeedRetransmission(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet)
Headers for Block ack response.
Definition: ctrl-headers.h:193
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1610
virtual bool IsAccessRequested(void) const
Definition: txop.cc:463
virtual bool IsQosTxop() const
Check for QoS TXOP.
Definition: txop.cc:865
virtual uint32_t GetNextFragmentSize(void) const
Calculate the size of the next fragment.
Definition: txop.cc:426
uint32_t m_cwMin
the CW minimum
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:363
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:702
uint32_t GetCw(void) const
Definition: txop.cc:211
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:582
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:290
virtual void MissedBlockAck(uint8_t nMpdus)
Event handler when a Block ACK timeout has occurred.
Definition: txop.cc:883
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:608
Ptr< WifiMacQueue > m_queue
the wifi MAC queue
Definition: txop.h:509
virtual void DoDispose(void)
Destructor implementation.
Definition: txop.cc:107
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:133
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:1127
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:574
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:193
virtual void NotifyInternalCollision(void)
Notify the DCF that internal collision has occurred.
Definition: txop.cc:566
Ptr< MacLow > m_low
the MacLow
Definition: txop.h:511
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:169
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 CW
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:85
MacLowTransmissionParameters m_currentParams
current transmission parameters
Definition: txop.h:533
WifiTxVector GetDataTxVector(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet)
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:185
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
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:276
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:642
virtual void MissedCts(void)
Event handler when a CTS timeout has occurred.
Definition: txop.cc:615
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Definition: packet.cc:870
#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:126
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1064
uint32_t GetBackoffSlots(void) const
Return the current number of backoff slots.
Definition: txop.cc:232
Ptr< WifiMacQueue > GetWifiMacQueue() const
Return the packet queue associated with this Txop.
Definition: txop.cc:178
virtual Time GetTxopRemaining(void) const
Return the remaining duration in the current TXOP.
Definition: txop.cc:889
void MissedCfPollResponse(bool expectedCfAck)
Event handler when a response to a CF-POLL frame is missed.
Definition: txop.cc:716
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.
virtual void SetWifiRemoteStationManager(const Ptr< WifiRemoteStationManager > remoteManager)
Set WifiRemoteStationsManager this Txop is associated to.
Definition: txop.cc:140
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:269
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:896
void SetTxFailedCallback(TxFailed callback)
Definition: txop.cc:154
virtual ~Txop()
Definition: txop.cc:101
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1372
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:147
virtual void GotBlockAck(const CtrlBAckResponseHeader *blockAck, Mac48Address recipient, double rxSnr, WifiMode txMode, double dataSnr)
Event handler when a Block ACK is received.
Definition: txop.cc:877
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:316
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:217
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:922
void StartBackoffNow(uint32_t nSlots)
Definition: txop.cc:253
void RequestAccess(Ptr< Txop > state, bool isCfPeriod=false)
virtual void NotifyWakeUp(void)
When wake up operation occurs, channel access will be restarted.
Definition: txop.cc:601
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:65
Time GetTxopLimit(void) const
Return the TXOP limit.
Definition: txop.cc:302