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);
319  /*
320  * From section 10.3.4.2 "Basic access" of IEEE 802.11-2016:
321  *
322  * A STA may transmit an MPDU when it is operating under the DCF access
323  * method, either in the absence of a PC, or in the CP of the PCF access
324  * method, when the STA determines that the medium is idle when a frame is
325  * queued for transmission, and remains idle for a period of a DIFS, or an
326  * EIFS (10.3.2.3.7) from the end of the immediately preceding medium-busy
327  * event, whichever is the greater, and the backoff timer is zero. Otherwise
328  * the random backoff procedure described in 10.3.4.3 shall be followed.
329  *
330  * From section 10.22.2.2 "EDCA backoff procedure" of IEEE 802.11-2016:
331  *
332  * The backoff procedure shall be invoked by an EDCAF when any of the following
333  * events occurs:
334  * a) An MA-UNITDATA.request primitive is received that causes a frame with that AC
335  * to be queued for transmission such that one of the transmit queues associated
336  * with that AC has now become non-empty and any other transmit queues
337  * associated with that AC are empty; the medium is busy on the primary channel
338  */
339  if (!HasFramesToTransmit () && !m_low->IsCfPeriod () && m_backoffSlots == 0)
340  {
342  {
343  // medium idle. If this is a DCF, use immediate access (we can transmit
344  // in a DIFS if the medium remains idle). If this is an EDCAF, update
345  // the backoff start time kept by the EDCAF to the current time in order
346  // to correctly align the backoff start time at the next slot boundary
347  // (performed by the next call to ChannelAccessManager::RequestAccess())
348  Time delay = (IsQosTxop () ? Seconds (0) : m_low->GetSifs () + GetAifsn () * m_low->GetSlotTime ());
349  UpdateBackoffSlotsNow (0, Simulator::Now () + delay);
350  }
351  else
352  {
353  // medium busy, generate backoff
354  GenerateBackoff ();
355  }
356  }
357 }
358 
359 void
361 {
362  NS_LOG_FUNCTION (this << packet << &hdr);
363  Ptr<Packet> packetCopy = packet->Copy ();
364  // remove the priority tag attached, if any
365  SocketPriorityTag priorityTag;
366  packetCopy->RemovePacketTag (priorityTag);
367  m_stationManager->PrepareForQueue (hdr.GetAddr1 (), &hdr, packetCopy);
369  m_queue->Enqueue (Create<WifiMacQueueItem> (packetCopy, hdr));
371 }
372 
373 int64_t
374 Txop::AssignStreams (int64_t stream)
375 {
376  NS_LOG_FUNCTION (this << stream);
377  m_rng->SetStream (stream);
378  return 1;
379 }
380 
381 void
383 {
384  NS_LOG_FUNCTION (this);
385  if ((m_currentPacket != 0
386  || !m_queue->IsEmpty ())
387  && !IsAccessRequested ()
388  && !m_low->IsCfPeriod ())
389  {
391  }
392 }
393 
394 void
396 {
397  NS_LOG_FUNCTION (this);
398  if (m_currentPacket == 0
399  && !m_queue->IsEmpty ()
400  && !IsAccessRequested ()
401  && !m_low->IsCfPeriod ())
402  {
404  }
405 }
406 
408 Txop::GetLow (void) const
409 {
410  return m_low;
411 }
412 
413 void
415 {
416  NS_LOG_FUNCTION (this);
417  ResetCw ();
418  m_cwTrace = GetCw ();
419  GenerateBackoff ();
420 }
421 
422 bool
424 {
425  NS_LOG_FUNCTION (this);
426  return m_stationManager->NeedRetransmission (hdr.GetAddr1 (), &hdr, packet);
427 }
428 
429 bool
431 {
432  NS_LOG_FUNCTION (this);
433  return m_stationManager->NeedRetransmission (hdr.GetAddr1 (), &hdr, packet);
434 }
435 
436 bool
438 {
439  NS_LOG_FUNCTION (this);
442 }
443 
444 void
446 {
447  NS_LOG_FUNCTION (this);
449 }
450 
451 uint32_t
453 {
454  NS_LOG_FUNCTION (this);
457 }
458 
459 bool
461 {
462  NS_LOG_FUNCTION (this);
465 }
466 
467 uint32_t
469 {
470  NS_LOG_FUNCTION (this);
473 }
474 
475 uint32_t
477 {
478  NS_LOG_FUNCTION (this);
481 }
482 
485 {
486  NS_LOG_FUNCTION (this << hdr);
487  *hdr = m_currentHdr;
489  uint32_t startOffset = GetFragmentOffset ();
490  Ptr<Packet> fragment;
491  if (IsLastFragment ())
492  {
493  hdr->SetNoMoreFragments ();
494  }
495  else
496  {
497  hdr->SetMoreFragments ();
498  }
499  fragment = m_currentPacket->CreateFragment (startOffset,
500  GetFragmentSize ());
501  return fragment;
502 }
503 
504 bool
506 {
507  return m_accessRequested;
508 }
509 
510 void
512 {
513  NS_LOG_FUNCTION (this);
514  m_accessRequested = true;
515 }
516 
517 void
519 {
520  NS_LOG_FUNCTION (this);
522  m_accessRequested = false;
523  if (m_currentPacket == 0)
524  {
525  if (m_queue->IsEmpty ())
526  {
527  NS_LOG_DEBUG ("queue empty");
528  return;
529  }
530  Ptr<WifiMacQueueItem> item = m_queue->Dequeue ();
531  NS_ASSERT (item != 0);
532  m_currentPacket = item->GetPacket ();
533  m_currentHdr = item->GetHeader ();
534  NS_ASSERT (m_currentPacket != 0);
535  uint16_t sequence = m_txMiddle->GetNextSequenceNumberFor (&m_currentHdr);
536  m_currentHdr.SetSequenceNumber (sequence);
541  m_fragmentNumber = 0;
542  NS_LOG_DEBUG ("dequeued size=" << m_currentPacket->GetSize () <<
543  ", to=" << m_currentHdr.GetAddr1 () <<
544  ", seq=" << m_currentHdr.GetSequenceControl ());
545  }
546  if (m_currentHdr.GetAddr1 ().IsGroup ())
547  {
551  NS_LOG_DEBUG ("tx broadcast");
552  GetLow ()->StartTransmission (Create<WifiMacQueueItem> (m_currentPacket, m_currentHdr),
553  m_currentParams, this);
554  }
555  else
556  {
558  if (NeedFragmentation ())
559  {
561  WifiMacHeader hdr;
562  Ptr<Packet> fragment = GetFragmentPacket (&hdr);
563  if (IsLastFragment ())
564  {
565  NS_LOG_DEBUG ("fragmenting last fragment size=" << fragment->GetSize ());
567  }
568  else
569  {
570  NS_LOG_DEBUG ("fragmenting size=" << fragment->GetSize ());
572  }
573  GetLow ()->StartTransmission (Create<WifiMacQueueItem> (fragment, hdr),
574  m_currentParams, this);
575  }
576  else
577  {
580 
582  m_currentPacket, dataTxVector)
583  && !m_low->IsCfPeriod ())
584  {
586  }
587  else
588  {
590  }
592  GetLow ()->StartTransmission (Create<WifiMacQueueItem> (m_currentPacket, m_currentHdr),
593  m_currentParams, this);
594  }
595  }
596 }
597 
598 void
600 {
601  NS_LOG_FUNCTION (this);
602  m_backoff = m_rng->GetInteger (0, GetCw ());
605 }
606 
607 void
609 {
610  NS_LOG_FUNCTION (this);
611  GenerateBackoff ();
613 }
614 
615 void
617 {
618  NS_LOG_FUNCTION (this);
619  m_queue->Flush ();
620  m_currentPacket = 0;
621 }
622 
623 void
625 {
626  NS_LOG_FUNCTION (this);
627  if (m_currentPacket != 0)
628  {
629  m_queue->PushFront (Create<WifiMacQueueItem> (m_currentPacket, m_currentHdr));
630  m_currentPacket = 0;
631  }
632 }
633 
634 void
636 {
637  NS_LOG_FUNCTION (this);
638  m_queue->Flush ();
639  m_currentPacket = 0;
640 }
641 
642 void
644 {
645  NS_LOG_FUNCTION (this);
647 }
648 
649 void
651 {
652  NS_LOG_FUNCTION (this);
654 }
655 
656 void
658 {
659  NS_LOG_FUNCTION (this);
660  NS_LOG_DEBUG ("missed cts");
662  {
663  NS_LOG_DEBUG ("Cts Fail");
665  if (!m_txFailedCallback.IsNull ())
666  {
668  }
669  //to reset the dcf.
670  m_currentPacket = 0;
671  ResetCw ();
672  m_cwTrace = GetCw ();
673  }
674  else
675  {
676  UpdateFailedCw ();
677  m_cwTrace = GetCw ();
678  }
679  GenerateBackoff ();
681 }
682 
683 void
685 {
686  NS_LOG_FUNCTION (this);
687  if (!NeedFragmentation ()
688  || IsLastFragment ())
689  {
690  NS_LOG_DEBUG ("got ack. tx done.");
691  if (!m_txOkCallback.IsNull ())
692  {
694  }
695 
696  /* we are not fragmenting or we are done fragmenting
697  * so we can get rid of that packet now.
698  */
699  m_currentPacket = 0;
700  ResetCw ();
701  m_cwTrace = GetCw ();
702  GenerateBackoff ();
704  }
705  else
706  {
707  NS_LOG_DEBUG ("got ack. tx not done, size=" << m_currentPacket->GetSize ());
708  }
709 }
710 
711 void
713 {
714  NS_LOG_FUNCTION (this);
715  NS_LOG_DEBUG ("missed ack");
717  {
718  NS_LOG_DEBUG ("Ack Fail");
721  if (!m_txFailedCallback.IsNull ())
722  {
724  }
725  //to reset the dcf.
726  m_currentPacket = 0;
727  ResetCw ();
728  m_cwTrace = GetCw ();
729  }
730  else
731  {
732  NS_LOG_DEBUG ("Retransmit");
736  UpdateFailedCw ();
737  m_cwTrace = GetCw ();
738  }
739  GenerateBackoff ();
741 }
742 
743 void
745 {
746  NS_LOG_FUNCTION (this);
747  if (m_currentPacket != 0)
748  {
750  }
751  else
752  {
754  }
755 }
756 
757 void
758 Txop::MissedCfPollResponse (bool expectedCfAck)
759 {
760  NS_LOG_FUNCTION (this);
761  NS_LOG_DEBUG ("missed response to CF-POLL");
762  if (expectedCfAck)
763  {
765  {
766  NS_LOG_DEBUG ("Ack Fail");
769  m_currentPacket = 0;
770  }
771  else
772  {
773  NS_LOG_DEBUG ("Retransmit");
775  }
776  }
777  if (!m_txFailedCallback.IsNull ())
778  {
780  }
781 }
782 
783 void
785 {
786  NS_LOG_FUNCTION (this);
787  NS_LOG_DEBUG ("start next packet fragment");
788  /* this callback is used only for fragments. */
789  NextFragment ();
790  WifiMacHeader hdr;
791  Ptr<Packet> fragment = GetFragmentPacket (&hdr);
794  if (IsLastFragment ())
795  {
797  }
798  else
799  {
801  }
802  GetLow ()->StartTransmission (Create<WifiMacQueueItem> (fragment, hdr), m_currentParams, this);
803 }
804 
805 void
807 {
808  NS_LOG_FUNCTION (this);
809  NS_LOG_DEBUG ("transmission cancelled");
810 }
811 
812 void
814 {
815  NS_LOG_FUNCTION (this);
816  NS_LOG_DEBUG ("a transmission that did not require an ACK just finished");
817  m_currentPacket = 0;
818  ResetCw ();
819  m_cwTrace = GetCw ();
820  GenerateBackoff ();
821  if (!m_txOkCallback.IsNull ())
822  {
824  }
826 }
827 
828 void
830 {
831  NS_LOG_FUNCTION (this << frameType << addr);
832  NS_ASSERT (m_low->IsCfPeriod ());
833  if (m_currentPacket != 0 && frameType != WIFI_MAC_CTL_END)
834  {
836  {
839  m_currentPacket = 0;
840  }
841  else
842  {
844  }
845  }
846  else if ((m_queue->GetNPacketsByAddress (addr) > 0) && (frameType != WIFI_MAC_CTL_END)) //if no packet for that dest, send to another dest?
847  {
848  Ptr<WifiMacQueueItem> item = m_queue->DequeueByAddress (addr);
849  NS_ASSERT (item != 0);
850  m_currentPacket = item->GetPacket ();
851  m_currentHdr = item->GetHeader ();
852  uint16_t sequence = m_txMiddle->GetNextSequenceNumberFor (&m_currentHdr);
853  m_currentHdr.SetSequenceNumber (sequence);
857  }
858  else
859  {
860  m_currentPacket = Create<Packet> ();
862  }
863 
864  if (m_currentPacket->GetSize () > 0)
865  {
866  switch (frameType)
867  {
870  break;
871  case WIFI_MAC_DATA_NULL:
873  break;
874  default:
875  NS_ASSERT (false);
876  break;
877  }
878  }
879  else
880  {
881  m_currentHdr.SetType (frameType);
882  }
883  m_currentHdr.SetAddr1 (addr);
884  m_currentHdr.SetAddr2 (m_low->GetAddress ());
885  if (frameType == WIFI_MAC_DATA_NULL)
886  {
887  m_currentHdr.SetAddr3 (m_low->GetBssid ());
890  }
891  else
892  {
893  m_currentHdr.SetAddr3 (m_low->GetAddress ());
896  }
898 }
899 
900 bool
902 {
903  return (!m_channelAccessManager->IsBusy () && GetLow ()->CanTransmitNextCfFrame ());
904 }
905 
906 bool
908 {
909  return false;
910 }
911 
912 void
914 {
915  NS_LOG_WARN ("StartNext should not be called for non QoS!");
916 }
917 
918 void
919 Txop::GotBlockAck (const CtrlBAckResponseHeader *blockAck, Mac48Address recipient, double rxSnr, WifiMode txMode, double dataSnr)
920 {
921  NS_LOG_WARN ("GotBlockAck should not be called for non QoS!");
922 }
923 
924 void
925 Txop::MissedBlockAck (uint8_t nMpdus)
926 {
927  NS_LOG_WARN ("MissedBlockAck should not be called for non QoS!");
928 }
929 
930 Time
932 {
933  NS_LOG_WARN ("GetTxopRemaining should not be called for non QoS!");
934  return Seconds (0);
935 }
936 
937 void
939 {
940  NS_LOG_WARN ("TerminateTxop should not be called for non QoS!");
941 }
942 
943 } //namespace ns3
TxFailed m_txFailedCallback
the transmit failed callback
Definition: txop.h:511
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:829
#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:532
Ptr< MacTxMiddle > m_txMiddle
the MacTxMiddle
Definition: txop.h:514
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
Callback template class.
Definition: callback.h:1176
TracedCallback< uint32_t > m_backoffTrace
backoff trace value
Definition: txop.h:539
TracedValue< uint32_t > m_cwTrace
CW trace value.
Definition: txop.h:540
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:533
virtual void RestartAccessIfNeeded(void)
Restart access request if needed.
Definition: txop.cc:382
virtual void StartAccessIfNeeded(void)
Request access from DCF manager if needed.
Definition: txop.cc:395
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:913
virtual void EndTxNoAck(void)
Event handler when a transmission that does not require an ACK has completed.
Definition: txop.cc:813
uint32_t m_backoffSlots
the backoff slots
Definition: txop.h:524
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:784
uint32_t m_backoff
the current backoff
Definition: txop.h:522
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:509
virtual void NotifyAccessGranted(void)
Notify the DCF that access has been granted.
Definition: txop.cc:518
virtual void MissedAck(void)
Event handler when an ACK is missed.
Definition: txop.cc:712
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:414
#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:204
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1070
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:806
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:517
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:901
void PrepareForQueue(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet)
virtual void GenerateBackoff(void)
Generate a new backoff now.
Definition: txop.cc:599
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:520
virtual void GenerateBackoffUponAccessIfNeeded(void)
Generate a new backoff, if needed, when a packet is queued for transmission.
Definition: txop.cc:316
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:635
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:446
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:220
void SetAddr1(Mac48Address address)
Fill the Address 1 field with the given address.
AttributeValue implementation for Time.
Definition: nstime.h:1124
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:374
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:445
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:1489
virtual bool IsAccessRequested(void) const
Definition: txop.cc:505
virtual bool IsQosTxop() const
Check for QoS TXOP.
Definition: txop.cc:907
virtual uint32_t GetNextFragmentSize(void) const
Calculate the size of the next fragment.
Definition: txop.cc:468
uint32_t m_cwMin
the CW minimum
Definition: txop.h:519
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:423
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:408
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:744
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:624
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:925
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:650
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
Ptr< WifiMacQueue > m_queue
the wifi MAC queue
Definition: txop.h:513
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:430
Ptr< const Packet > m_currentPacket
the current packet
Definition: txop.h:535
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:437
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:1125
virtual Ptr< Packet > GetFragmentPacket(WifiMacHeader *hdr)
Get the next fragment from the packet with appropriate Wifi header for the fragment.
Definition: txop.cc:484
virtual void NotifyChannelSwitching(void)
When a channel switching occurs, enqueued packets are removed.
Definition: txop.cc:616
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:608
Ptr< MacLow > m_low
the MacLow
Definition: txop.h:515
virtual bool IsLastFragment(void) const
Check if the current fragment is the last fragment.
Definition: txop.cc:460
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:521
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:537
WifiTxVector GetDataTxVector(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet)
virtual void Queue(Ptr< const Packet > packet, const WifiMacHeader &hdr)
Definition: txop.cc:360
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:264
bool m_accessRequested
flag whether channel access is already requested
Definition: txop.h:523
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:530
virtual void GotAck(void)
Event handler when an ACK is received.
Definition: txop.cc:684
virtual void MissedCts(void)
Event handler when a CTS timeout has occurred.
Definition: txop.cc:657
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:272
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:1062
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:931
void MissedCfPollResponse(bool expectedCfAck)
Event handler when a response to a CF-POLL frame is missed.
Definition: txop.cc:758
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:510
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:538
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:511
WifiMacHeader m_currentHdr
the current header
Definition: txop.h:536
virtual void TerminateTxop(void)
Update backoff and restart access if needed.
Definition: txop.cc:938
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:1270
Ptr< WifiRemoteStationManager > m_stationManager
the wifi remote station manager
Definition: txop.h:516
virtual uint32_t GetFragmentOffset(void) const
Calculate the offset for the current fragment.
Definition: txop.cc:476
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:919
void SetFragmentNumber(uint8_t frag)
Set the fragment number of the header.
void DisableAck(void)
Do not wait for Ack after data transmission.
virtual uint32_t GetFragmentSize(void) const
Calculate the size of the current fragment.
Definition: txop.cc:452
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:915
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:643
Implements the IEEE 802.11 MAC header.
TxDropped m_txDroppedCallback
the packet dropped callback
Definition: txop.h:512
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