src/devices/wifi/dcf-manager.cc
author Andrey Mazo <mazo@iitp.ru>
Mon, 08 Jun 2009 16:30:52 +0400
changeset 5053 87648432f1ca
parent 5028 01f02baebba9
parent 4509 b2654e0f071d
child 5062 cfc9bba09692
permissions -rw-r--r--
Merge changes from ns-3-dev.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
4325
acc6c801f785 bug 548: missing license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4217
diff changeset
     2
/*
acc6c801f785 bug 548: missing license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4217
diff changeset
     3
 * Copyright (c) 2005,2006 INRIA
acc6c801f785 bug 548: missing license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4217
diff changeset
     4
 *
acc6c801f785 bug 548: missing license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4217
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
acc6c801f785 bug 548: missing license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4217
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as 
acc6c801f785 bug 548: missing license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4217
diff changeset
     7
 * published by the Free Software Foundation;
acc6c801f785 bug 548: missing license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4217
diff changeset
     8
 *
acc6c801f785 bug 548: missing license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4217
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
acc6c801f785 bug 548: missing license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4217
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
acc6c801f785 bug 548: missing license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4217
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
acc6c801f785 bug 548: missing license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4217
diff changeset
    12
 * GNU General Public License for more details.
acc6c801f785 bug 548: missing license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4217
diff changeset
    13
 *
acc6c801f785 bug 548: missing license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4217
diff changeset
    14
 * You should have received a copy of the GNU General Public License
acc6c801f785 bug 548: missing license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4217
diff changeset
    15
 * along with this program; if not, write to the Free Software
acc6c801f785 bug 548: missing license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4217
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
acc6c801f785 bug 548: missing license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4217
diff changeset
    17
 *
acc6c801f785 bug 548: missing license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4217
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
acc6c801f785 bug 548: missing license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4217
diff changeset
    19
 */
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    20
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    21
#include "ns3/assert.h"
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    22
#include "ns3/log.h"
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    23
#include "ns3/simulator.h"
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    24
#include <math.h>
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    25
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    26
#include "dcf-manager.h"
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    27
#include "wifi-phy.h"
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    28
#include "wifi-mac.h"
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    29
#include "mac-low.h"
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    30
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    31
NS_LOG_COMPONENT_DEFINE ("DcfManager");
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    32
2107
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
    33
#define MY_DEBUG(x) \
2140
acfd79fc8d65 debugging output is more verbose.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2130
diff changeset
    34
  NS_LOG_DEBUG (Simulator::Now () << " " << this << " " << x)
2107
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
    35
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    36
namespace ns3 {
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    37
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    38
/****************************************************************
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    39
 *      Implement the DCF state holder
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    40
 ****************************************************************/
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    41
2100
1b8cc486edd9 initialize more state variables
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2099
diff changeset
    42
DcfState::DcfState ()
1b8cc486edd9 initialize more state variables
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2099
diff changeset
    43
  : m_backoffSlots (0),
2145
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
    44
    m_backoffStart (Seconds (0.0)),
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    45
    m_cwMin (0),
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    46
    m_cwMax (0),
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    47
    m_cw (0),
2145
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
    48
    m_accessRequested (false)
2100
1b8cc486edd9 initialize more state variables
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2099
diff changeset
    49
{}
1b8cc486edd9 initialize more state variables
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2099
diff changeset
    50
2096
4e282663666c add missing method implementations
mlacage@thira.inria.fr
parents: 2095
diff changeset
    51
DcfState::~DcfState ()
4e282663666c add missing method implementations
mlacage@thira.inria.fr
parents: 2095
diff changeset
    52
{}
4e282663666c add missing method implementations
mlacage@thira.inria.fr
parents: 2095
diff changeset
    53
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    54
void 
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    55
DcfState::SetAifsn (uint32_t aifsn)
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    56
{
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    57
  m_aifsn = aifsn;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    58
}
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    59
void 
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    60
DcfState::SetCwMin (uint32_t minCw)
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    61
{
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    62
  m_cwMin = minCw;
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    63
  ResetCw ();
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    64
}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    65
void 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    66
DcfState::SetCwMax (uint32_t maxCw)
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    67
{
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    68
  m_cwMax = maxCw;
2100
1b8cc486edd9 initialize more state variables
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2099
diff changeset
    69
  ResetCw ();
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    70
}
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    71
uint32_t 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    72
DcfState::GetAifsn (void) const
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    73
{
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    74
  return m_aifsn;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    75
}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    76
uint32_t
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    77
DcfState::GetCwMin (void) const
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    78
{
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    79
  return m_cwMin;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    80
}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    81
uint32_t 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    82
DcfState::GetCwMax (void) const
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    83
{
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    84
  return m_cwMax;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
    85
}
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    86
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    87
void 
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    88
DcfState::ResetCw (void)
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    89
{
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    90
  m_cw = m_cwMin;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    91
}
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    92
void 
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    93
DcfState::UpdateFailedCw (void)
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    94
{
4217
9494663cf1c9 bug 509: backoff CW growth is invalid
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3905
diff changeset
    95
  // see 802.11-2007, section 9.9.1.5
9494663cf1c9 bug 509: backoff CW growth is invalid
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3905
diff changeset
    96
  m_cw = std::min ( 2 * (m_cw + 1) - 1, m_cwMax);
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    97
}
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
    98
void 
2122
ee136bc4f214 keep track of the last time a backoff was updated.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2120
diff changeset
    99
DcfState::UpdateBackoffSlotsNow (uint32_t nSlots, Time backoffUpdateBound)
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   100
{
2142
63c08450a4da avoid decrementing by too many backoff slots
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2140
diff changeset
   101
  m_backoffSlots -= nSlots;
2122
ee136bc4f214 keep track of the last time a backoff was updated.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2120
diff changeset
   102
  m_backoffStart = backoffUpdateBound;
2140
acfd79fc8d65 debugging output is more verbose.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2130
diff changeset
   103
  MY_DEBUG ("update slots="<<nSlots<<" slots, backoff="<<m_backoffSlots);
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   104
}
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   105
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   106
void 
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   107
DcfState::StartBackoffNow (uint32_t nSlots)
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   108
{
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   109
  NS_ASSERT (m_backoffSlots == 0);
2120
9714777a8080 start a backoff only if no backoff is started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2117
diff changeset
   110
  MY_DEBUG ("start backoff="<<nSlots<<" slots");
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   111
  m_backoffSlots = nSlots;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   112
  m_backoffStart = Simulator::Now ();
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   113
}
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   114
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   115
uint32_t
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   116
DcfState::GetCw (void) const
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   117
{
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   118
  return m_cw;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   119
}
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   120
uint32_t 
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   121
DcfState::GetBackoffSlots (void) const
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   122
{
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   123
  return m_backoffSlots;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   124
}
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   125
Time 
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   126
DcfState::GetBackoffStart (void) const
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   127
{
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   128
  return m_backoffStart;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   129
}
2145
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   130
bool 
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   131
DcfState::IsAccessRequested (void) const
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   132
{
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   133
  return m_accessRequested;
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   134
}
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   135
void 
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   136
DcfState::NotifyAccessRequested (void)
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   137
{
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   138
  m_accessRequested = true;
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   139
}
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   140
void 
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   141
DcfState::NotifyAccessGranted (void)
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   142
{
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   143
  NS_ASSERT (m_accessRequested);
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   144
  m_accessRequested = false;
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   145
  DoNotifyAccessGranted ();
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   146
}
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   147
void 
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   148
DcfState::NotifyCollision (void)
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   149
{
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   150
  DoNotifyCollision ();
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   151
}
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   152
void 
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   153
DcfState::NotifyInternalCollision (void)
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   154
{
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   155
  DoNotifyInternalCollision ();
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   156
}
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   157
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   158
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   159
/***************************************************************
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   160
 *         Listener for Nav events. Forwards to DcfManager
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   161
 ***************************************************************/
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   162
4509
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   163
class LowDcfListener : public ns3::MacLowDcfListener {
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   164
public:
4509
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   165
  LowDcfListener (ns3::DcfManager *dcf)
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   166
    : m_dcf (dcf) {}
4509
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   167
  virtual ~LowDcfListener () {}
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   168
  virtual void NavStart (Time duration) {
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   169
    m_dcf->NotifyNavStartNow (duration);
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   170
  }
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   171
  virtual void NavReset (Time duration) {
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   172
    m_dcf->NotifyNavResetNow (duration);
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   173
  }
4509
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   174
  virtual void AckTimeoutStart (Time duration) {
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   175
    m_dcf->NotifyAckTimeoutStartNow (duration);
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   176
  }
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   177
  virtual void AckTimeoutReset () {
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   178
    m_dcf->NotifyAckTimeoutResetNow ();
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   179
  }
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   180
  virtual void CtsTimeoutStart (Time duration) {
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   181
    m_dcf->NotifyCtsTimeoutStartNow (duration);
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   182
  }
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   183
  virtual void CtsTimeoutReset () {
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   184
    m_dcf->NotifyCtsTimeoutResetNow ();
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   185
  }
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   186
private:
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   187
  ns3::DcfManager *m_dcf;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   188
};
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   189
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   190
/***************************************************************
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   191
 *         Listener for PHY events. Forwards to DcfManager
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   192
 ***************************************************************/
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   193
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   194
class PhyListener : public ns3::WifiPhyListener {
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   195
public:
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   196
  PhyListener (ns3::DcfManager *dcf)
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   197
    : m_dcf (dcf) {}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   198
  virtual ~PhyListener () {}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   199
  virtual void NotifyRxStart (Time duration) {
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   200
    m_dcf->NotifyRxStartNow (duration);
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   201
  }
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   202
  virtual void NotifyRxEndOk (void) {
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   203
    m_dcf->NotifyRxEndOkNow ();
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   204
  }
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   205
  virtual void NotifyRxEndError (void) {
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   206
    m_dcf->NotifyRxEndErrorNow ();
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   207
  }
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   208
  virtual void NotifyTxStart (Time duration) {
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   209
    m_dcf->NotifyTxStartNow (duration);
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   210
  }
3905
99c9346b5d71 split interference calculation from YansWifiPhy. Move them to InterferenceHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2524
diff changeset
   211
  virtual void NotifyMaybeCcaBusyStart (Time duration) {
99c9346b5d71 split interference calculation from YansWifiPhy. Move them to InterferenceHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2524
diff changeset
   212
    m_dcf->NotifyMaybeCcaBusyStartNow (duration);
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   213
  }
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   214
private:
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   215
  ns3::DcfManager *m_dcf;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   216
};
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   217
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   218
/****************************************************************
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   219
 *      Implement the DCF manager of all DCF state holders
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   220
 ****************************************************************/
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   221
2099
de25c6d81572 initialize state variables
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2096
diff changeset
   222
DcfManager::DcfManager ()
4509
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   223
  : m_lastAckTimeoutEnd (MicroSeconds (0)),
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   224
    m_lastCtsTimeoutEnd (MicroSeconds (0)),
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   225
    m_lastNavStart (MicroSeconds (0)),
2099
de25c6d81572 initialize state variables
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2096
diff changeset
   226
    m_lastNavDuration (MicroSeconds (0)),
de25c6d81572 initialize state variables
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2096
diff changeset
   227
    m_lastRxStart (MicroSeconds (0)),
de25c6d81572 initialize state variables
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2096
diff changeset
   228
    m_lastRxDuration (MicroSeconds (0)),
de25c6d81572 initialize state variables
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2096
diff changeset
   229
    m_lastRxReceivedOk (true),
de25c6d81572 initialize state variables
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2096
diff changeset
   230
    m_lastRxEnd (MicroSeconds (0)),
de25c6d81572 initialize state variables
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2096
diff changeset
   231
    m_lastTxStart (MicroSeconds (0)),
de25c6d81572 initialize state variables
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2096
diff changeset
   232
    m_lastTxDuration (MicroSeconds (0)),
de25c6d81572 initialize state variables
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2096
diff changeset
   233
    m_lastBusyStart (MicroSeconds (0)),
de25c6d81572 initialize state variables
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2096
diff changeset
   234
    m_lastBusyDuration (MicroSeconds (0)),
2105
e883a100109a get rid of MacParameters from DcfManager
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2104
diff changeset
   235
    m_rxing (false),
e883a100109a get rid of MacParameters from DcfManager
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2104
diff changeset
   236
    m_slotTime (Seconds (0.0)),
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   237
    m_sifs (Seconds (0.0)),
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   238
    m_phyListener (0),
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   239
    m_lowListener (0)
2099
de25c6d81572 initialize state variables
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2096
diff changeset
   240
{}
de25c6d81572 initialize state variables
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2096
diff changeset
   241
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   242
DcfManager::~DcfManager ()
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   243
{
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   244
  delete m_phyListener;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   245
  delete m_lowListener;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   246
  m_phyListener = 0;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   247
  m_lowListener = 0;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   248
}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   249
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   250
void 
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   251
DcfManager::SetupPhyListener (Ptr<WifiPhy> phy)
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   252
{
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   253
  m_phyListener = new PhyListener (this);
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   254
  phy->RegisterListener (m_phyListener);
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   255
}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   256
void 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   257
DcfManager::SetupLowListener (Ptr<MacLow> low)
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   258
{
4509
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   259
  m_lowListener = new LowDcfListener (this);
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   260
  low->RegisterDcfListener (m_lowListener);
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   261
}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   262
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   263
void 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   264
DcfManager::SetSlot (Time slotTime)
2096
4e282663666c add missing method implementations
mlacage@thira.inria.fr
parents: 2095
diff changeset
   265
{
2105
e883a100109a get rid of MacParameters from DcfManager
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2104
diff changeset
   266
  m_slotTime = slotTime;
e883a100109a get rid of MacParameters from DcfManager
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2104
diff changeset
   267
}
e883a100109a get rid of MacParameters from DcfManager
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2104
diff changeset
   268
void 
e883a100109a get rid of MacParameters from DcfManager
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2104
diff changeset
   269
DcfManager::SetSifs (Time sifs)
e883a100109a get rid of MacParameters from DcfManager
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2104
diff changeset
   270
{
e883a100109a get rid of MacParameters from DcfManager
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2104
diff changeset
   271
  m_sifs = sifs;
2096
4e282663666c add missing method implementations
mlacage@thira.inria.fr
parents: 2095
diff changeset
   272
}
4e282663666c add missing method implementations
mlacage@thira.inria.fr
parents: 2095
diff changeset
   273
void 
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   274
DcfManager::SetEifsNoDifs (Time eifsNoDifs)
2096
4e282663666c add missing method implementations
mlacage@thira.inria.fr
parents: 2095
diff changeset
   275
{
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   276
  m_eifsNoDifs = eifsNoDifs;
2096
4e282663666c add missing method implementations
mlacage@thira.inria.fr
parents: 2095
diff changeset
   277
}
4460
d7ad6e210086 move GetEifsNoDifs to DcfManager
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4325
diff changeset
   278
Time
d7ad6e210086 move GetEifsNoDifs to DcfManager
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4325
diff changeset
   279
DcfManager::GetEifsNoDifs () const
d7ad6e210086 move GetEifsNoDifs to DcfManager
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4325
diff changeset
   280
{
d7ad6e210086 move GetEifsNoDifs to DcfManager
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4325
diff changeset
   281
  return m_eifsNoDifs;
d7ad6e210086 move GetEifsNoDifs to DcfManager
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4325
diff changeset
   282
}
2096
4e282663666c add missing method implementations
mlacage@thira.inria.fr
parents: 2095
diff changeset
   283
4e282663666c add missing method implementations
mlacage@thira.inria.fr
parents: 2095
diff changeset
   284
void 
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   285
DcfManager::Add (DcfState *dcf)
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   286
{
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   287
  m_states.push_back (dcf);
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   288
}
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   289
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   290
Time
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   291
DcfManager::MostRecent (Time a, Time b) const
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   292
{
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   293
  return Max (a, b);
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   294
}
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   295
Time
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   296
DcfManager::MostRecent (Time a, Time b, Time c) const
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   297
{
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   298
  Time retval;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   299
  retval = Max (a, b);
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   300
  retval = Max (retval, c);
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   301
  return retval;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   302
}
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   303
Time
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   304
DcfManager::MostRecent (Time a, Time b, Time c, Time d) const
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   305
{
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   306
  Time e = Max (a, b);
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   307
  Time f = Max (c, d);
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   308
  Time retval = Max (e, f);
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   309
  return retval;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   310
}
4509
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   311
Time
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   312
DcfManager::MostRecent (Time a, Time b, Time c, Time d, Time e, Time f) const
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   313
{
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   314
  Time g = Max (a, b);
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   315
  Time h = Max (c, d);
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   316
  Time i = Max (e, f);
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   317
  Time k = Max (g, h);
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   318
  Time retval = Max (k, i);
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   319
  return retval;
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   320
}
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   321
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   322
bool 
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   323
DcfManager::IsBusy (void) const
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   324
{
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   325
  // PHY busy
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   326
  if (m_rxing) 
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   327
    {
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   328
      return true;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   329
    }
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   330
  Time lastTxEnd = m_lastTxStart + m_lastTxDuration;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   331
  if (lastTxEnd > Simulator::Now ()) 
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   332
    {
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   333
      return true;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   334
    }
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   335
  // NAV busy
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   336
  Time lastNavEnd = m_lastNavStart + m_lastNavDuration;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   337
  if (lastNavEnd > Simulator::Now ())
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   338
    {
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   339
      return true;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   340
    }
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   341
  return false;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   342
}
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   343
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   344
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   345
void 
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   346
DcfManager::RequestAccess (DcfState *state)
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   347
{
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   348
  UpdateBackoff ();
2145
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   349
  NS_ASSERT (!state->IsAccessRequested ());
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   350
  state->NotifyAccessRequested ();
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   351
  /**
2127
2707cb71f6dc even if an access timer is running, we need to start a backoff if needed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2122
diff changeset
   352
   * If there is a collision, generate a backoff
2707cb71f6dc even if an access timer is running, we need to start a backoff if needed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2122
diff changeset
   353
   * by notifying the collision to the user.
2707cb71f6dc even if an access timer is running, we need to start a backoff if needed
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2122
diff changeset
   354
   */
2120
9714777a8080 start a backoff only if no backoff is started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2117
diff changeset
   355
  if (state->GetBackoffSlots () == 0 && 
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   356
      IsBusy ())
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   357
    {
2107
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   358
      MY_DEBUG ("medium is busy: collision");
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   359
      /* someone else has accessed the medium.
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   360
       * generate a backoff.
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   361
       */
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   362
      state->NotifyCollision ();
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   363
    }
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   364
  DoGrantAccess ();
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   365
  DoRestartAccessTimeoutIfNeeded ();  
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   366
}
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   367
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   368
void
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   369
DcfManager::DoGrantAccess (void)
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   370
{
2107
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   371
  Time accessGrantStart = GetAccessGrantStart ();
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   372
2103
ae7144199052 add debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2100
diff changeset
   373
  uint32_t k = 0;
ae7144199052 add debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2100
diff changeset
   374
  for (States::const_iterator i = m_states.begin (); i != m_states.end (); k++)
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   375
    {
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   376
      DcfState *state = *i;
2145
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   377
      if (state->IsAccessRequested () && 
4509
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   378
          GetBackoffEndFor (state) <= Simulator::Now () )
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   379
        {
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   380
          /**
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   381
           * This is the first dcf we find with an expired backoff and which
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   382
           * needs access to the medium. i.e., it has data to send.
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   383
           */
2140
acfd79fc8d65 debugging output is more verbose.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2130
diff changeset
   384
          MY_DEBUG ("dcf " << k << " needs access. backoff expired. access granted. slots="<<state->GetBackoffSlots ());
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   385
          i++; // go to the next item in the list.
2103
ae7144199052 add debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2100
diff changeset
   386
          k++;
2130
741d0b976a78 we need to accumulate a record of all changes before applying them in one go.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2129
diff changeset
   387
          std::vector<DcfState *> internalCollisionStates;
2103
ae7144199052 add debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2100
diff changeset
   388
          for (States::const_iterator j = i; j != m_states.end (); j++, k++)
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   389
            {
2130
741d0b976a78 we need to accumulate a record of all changes before applying them in one go.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2129
diff changeset
   390
              DcfState *otherState = *j;
2145
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   391
              if (otherState->IsAccessRequested () &&
2130
741d0b976a78 we need to accumulate a record of all changes before applying them in one go.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2129
diff changeset
   392
                  GetBackoffEndFor (otherState) <= Simulator::Now ())
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   393
                {
2142
63c08450a4da avoid decrementing by too many backoff slots
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2140
diff changeset
   394
                  MY_DEBUG ("dcf " << k << " needs access. backoff expired. internal collision. slots=" << 
63c08450a4da avoid decrementing by too many backoff slots
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2140
diff changeset
   395
                            otherState->GetBackoffSlots ());
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   396
                  /**
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   397
                   * all other dcfs with a lower priority whose backoff
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   398
                   * has expired and which needed access to the medium
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   399
                   * must be notified that we did get an internal collision.
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   400
                   */
2130
741d0b976a78 we need to accumulate a record of all changes before applying them in one go.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2129
diff changeset
   401
                  internalCollisionStates.push_back (otherState);
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   402
                }
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   403
            }
2130
741d0b976a78 we need to accumulate a record of all changes before applying them in one go.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2129
diff changeset
   404
741d0b976a78 we need to accumulate a record of all changes before applying them in one go.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2129
diff changeset
   405
          /**
741d0b976a78 we need to accumulate a record of all changes before applying them in one go.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2129
diff changeset
   406
           * Now, we notify all of these changes in one go. It is necessary to 
741d0b976a78 we need to accumulate a record of all changes before applying them in one go.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2129
diff changeset
   407
           * perform first the calculations of which states are colliding and then
741d0b976a78 we need to accumulate a record of all changes before applying them in one go.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2129
diff changeset
   408
           * only apply the changes because applying the changes through notification
741d0b976a78 we need to accumulate a record of all changes before applying them in one go.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2129
diff changeset
   409
           * could change the global state of the manager, and, thus, could change
741d0b976a78 we need to accumulate a record of all changes before applying them in one go.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2129
diff changeset
   410
           * the result of the calculations. 
741d0b976a78 we need to accumulate a record of all changes before applying them in one go.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2129
diff changeset
   411
           */
741d0b976a78 we need to accumulate a record of all changes before applying them in one go.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2129
diff changeset
   412
          state->NotifyAccessGranted ();
741d0b976a78 we need to accumulate a record of all changes before applying them in one go.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2129
diff changeset
   413
          for (std::vector<DcfState *>::const_iterator k = internalCollisionStates.begin ();
741d0b976a78 we need to accumulate a record of all changes before applying them in one go.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2129
diff changeset
   414
               k != internalCollisionStates.end (); k++)
741d0b976a78 we need to accumulate a record of all changes before applying them in one go.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2129
diff changeset
   415
            {
741d0b976a78 we need to accumulate a record of all changes before applying them in one go.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2129
diff changeset
   416
              (*k)->NotifyInternalCollision ();
741d0b976a78 we need to accumulate a record of all changes before applying them in one go.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2129
diff changeset
   417
            }
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   418
          break;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   419
        }
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   420
      i++;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   421
    }
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   422
}
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   423
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   424
void
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   425
DcfManager::AccessTimeout (void)
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   426
{
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   427
  UpdateBackoff ();
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   428
  DoGrantAccess ();
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   429
  DoRestartAccessTimeoutIfNeeded ();
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   430
}
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   431
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   432
Time
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   433
DcfManager::GetAccessGrantStart (void) const
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   434
{
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   435
  Time rxAccessStart;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   436
  if (m_lastRxEnd >= m_lastRxStart) 
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   437
    {
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   438
      rxAccessStart = m_lastRxEnd;
2099
de25c6d81572 initialize state variables
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2096
diff changeset
   439
      if (!m_lastRxReceivedOk)
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   440
        {
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   441
          rxAccessStart += m_eifsNoDifs;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   442
        }
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   443
      else
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   444
        {
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   445
          rxAccessStart += m_sifs;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2508
diff changeset
   446
        }
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   447
    } 
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   448
  else 
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   449
    {
2105
e883a100109a get rid of MacParameters from DcfManager
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2104
diff changeset
   450
      rxAccessStart = m_lastRxStart + m_lastRxDuration + m_sifs;
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   451
    }
2105
e883a100109a get rid of MacParameters from DcfManager
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2104
diff changeset
   452
  Time busyAccessStart = m_lastBusyStart + m_lastBusyDuration + m_sifs;
e883a100109a get rid of MacParameters from DcfManager
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2104
diff changeset
   453
  Time txAccessStart = m_lastTxStart + m_lastTxDuration + m_sifs;
e883a100109a get rid of MacParameters from DcfManager
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2104
diff changeset
   454
  Time navAccessStart = m_lastNavStart + m_lastNavDuration + m_sifs;
4509
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   455
  Time ackTimeoutAccessStart = m_lastAckTimeoutEnd + m_sifs;
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   456
  Time ctsTimeoutAccessStart = m_lastCtsTimeoutEnd + m_sifs;
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   457
  Time accessGrantedStart = MostRecent (rxAccessStart, 
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   458
                                        busyAccessStart,
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   459
                                        txAccessStart, 
4509
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   460
                                        navAccessStart,
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   461
                                        ackTimeoutAccessStart,
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   462
                                        ctsTimeoutAccessStart
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   463
                                        );
2109
345491373a45 do not use GetBackoffSlots directly anymore
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2108
diff changeset
   464
  NS_LOG_INFO ("access grant start=" << accessGrantedStart <<
345491373a45 do not use GetBackoffSlots directly anymore
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2108
diff changeset
   465
               ", rx access start=" << rxAccessStart <<
345491373a45 do not use GetBackoffSlots directly anymore
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2108
diff changeset
   466
               ", busy access start=" << busyAccessStart <<
345491373a45 do not use GetBackoffSlots directly anymore
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2108
diff changeset
   467
               ", tx access start=" << txAccessStart <<
345491373a45 do not use GetBackoffSlots directly anymore
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2108
diff changeset
   468
               ", nav access start=" << navAccessStart);
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   469
  return accessGrantedStart;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   470
}
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   471
2107
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   472
Time
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   473
DcfManager::GetBackoffStartFor (DcfState *state)
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   474
{
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   475
  Time mostRecentEvent = MostRecent (state->GetBackoffStart (),
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   476
                                     GetAccessGrantStart () + Scalar (state->GetAifsn ()) * m_slotTime);
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   477
  
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   478
  return mostRecentEvent;
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   479
}
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   480
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   481
Time
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   482
DcfManager::GetBackoffEndFor (DcfState *state)
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   483
{
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   484
  return GetBackoffStartFor (state) + Scalar (state->GetBackoffSlots ()) * m_slotTime;
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   485
}
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   486
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   487
void
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   488
DcfManager::UpdateBackoff (void)
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   489
{
2103
ae7144199052 add debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2100
diff changeset
   490
  uint32_t k = 0;
ae7144199052 add debugging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2100
diff changeset
   491
  for (States::const_iterator i = m_states.begin (); i != m_states.end (); i++, k++)
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   492
    {
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   493
      DcfState *state = *i;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   494
2107
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   495
      Time backoffStart = GetBackoffStartFor (state);
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   496
      if (backoffStart <= Simulator::Now ())
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   497
        {
2107
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   498
          Scalar nSlots = (Simulator::Now () - backoffStart) / m_slotTime;
2122
ee136bc4f214 keep track of the last time a backoff was updated.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2120
diff changeset
   499
          uint32_t nIntSlots = lrint (nSlots.GetDouble ());          
2144
415546638869 The AIFSN has been taken into account in GetBackoffStartFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2142
diff changeset
   500
          uint32_t n = std::min (nIntSlots, state->GetBackoffSlots ());
415546638869 The AIFSN has been taken into account in GetBackoffStartFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2142
diff changeset
   501
          MY_DEBUG ("dcf " << k << " dec backoff slots=" << n);
415546638869 The AIFSN has been taken into account in GetBackoffStartFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2142
diff changeset
   502
          Time backoffUpdateBound = backoffStart + Scalar (n) * m_slotTime;
415546638869 The AIFSN has been taken into account in GetBackoffStartFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2142
diff changeset
   503
          state->UpdateBackoffSlotsNow (n, backoffUpdateBound);
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   504
        }
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   505
    }
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   506
}
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   507
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   508
void
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   509
DcfManager::DoRestartAccessTimeoutIfNeeded (void)
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   510
{
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   511
  /**
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   512
   * Is there a DcfState which needs to access the medium, and, 
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   513
   * if there is one, how many slots for AIFS+backoff does it require ?
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   514
   */
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   515
  bool accessTimeoutNeeded = false;
2170
b24ae0343c4f MaxSeconds -> Simulator::GetMaximumSimulationTime
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2145
diff changeset
   516
  Time expectedBackoffEnd = Simulator::GetMaximumSimulationTime ();
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   517
  for (States::const_iterator i = m_states.begin (); i != m_states.end (); i++)
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   518
    {
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   519
      DcfState *state = *i;
2145
8f3c8ef34b0a use a simple request/grant scheme for dcf accesses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2144
diff changeset
   520
      if (state->IsAccessRequested ())
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   521
        {
2129
32f0e5c1a4d6 backoff end time is never in the past.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2128
diff changeset
   522
          Time tmp = GetBackoffEndFor (state);
4989
5f5b321b92d1 Ack timeout patch was merged. HWMP: DO=1 by default, if packet is unresolved -
Kirill Andreev <andreev@iitp.ru>
parents: 4325
diff changeset
   523
          if (tmp.GetTimeStep () > Simulator::Now ().GetTimeStep ())
2129
32f0e5c1a4d6 backoff end time is never in the past.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2128
diff changeset
   524
            {
4989
5f5b321b92d1 Ack timeout patch was merged. HWMP: DO=1 by default, if packet is unresolved -
Kirill Andreev <andreev@iitp.ru>
parents: 4325
diff changeset
   525
              //NS_LOG_UNCOND("Now:"<<Simulator::Now ().GetTimeStep ());
2129
32f0e5c1a4d6 backoff end time is never in the past.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2128
diff changeset
   526
              accessTimeoutNeeded = true;
32f0e5c1a4d6 backoff end time is never in the past.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2128
diff changeset
   527
              expectedBackoffEnd = std::min (expectedBackoffEnd, tmp);
32f0e5c1a4d6 backoff end time is never in the past.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2128
diff changeset
   528
            }
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   529
        }
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   530
    }
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   531
  if (accessTimeoutNeeded)
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   532
    {
2107
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   533
      MY_DEBUG ("expected backoff end="<<expectedBackoffEnd);
2129
32f0e5c1a4d6 backoff end time is never in the past.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2128
diff changeset
   534
      Time expectedBackoffDelay = expectedBackoffEnd - Simulator::Now ();
32f0e5c1a4d6 backoff end time is never in the past.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2128
diff changeset
   535
      if (m_accessTimeout.IsRunning () &&
32f0e5c1a4d6 backoff end time is never in the past.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2128
diff changeset
   536
          Simulator::GetDelayLeft (m_accessTimeout) > expectedBackoffDelay)
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   537
        {
2129
32f0e5c1a4d6 backoff end time is never in the past.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2128
diff changeset
   538
          m_accessTimeout.Cancel ();
32f0e5c1a4d6 backoff end time is never in the past.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2128
diff changeset
   539
        }
32f0e5c1a4d6 backoff end time is never in the past.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2128
diff changeset
   540
      if (m_accessTimeout.IsExpired ())
32f0e5c1a4d6 backoff end time is never in the past.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2128
diff changeset
   541
        {
32f0e5c1a4d6 backoff end time is never in the past.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2128
diff changeset
   542
          m_accessTimeout = Simulator::Schedule (expectedBackoffDelay,
32f0e5c1a4d6 backoff end time is never in the past.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2128
diff changeset
   543
                                                 &DcfManager::AccessTimeout, this);
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   544
        }
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   545
    }
2140
acfd79fc8d65 debugging output is more verbose.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2130
diff changeset
   546
}
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   547
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   548
void 
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   549
DcfManager::NotifyRxStartNow (Time duration)
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   550
{
2107
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   551
  MY_DEBUG ("rx start for="<<duration);
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   552
  UpdateBackoff ();
2107
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   553
  m_lastRxStart = Simulator::Now ();
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   554
  m_lastRxDuration = duration;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   555
  m_rxing = true;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   556
}
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   557
void 
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   558
DcfManager::NotifyRxEndOkNow (void)
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   559
{
2107
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   560
  MY_DEBUG ("rx end ok");
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   561
  m_lastRxEnd = Simulator::Now ();
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   562
  m_lastRxReceivedOk = true;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   563
  m_rxing = false;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   564
}
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   565
void 
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   566
DcfManager::NotifyRxEndErrorNow (void)
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   567
{
2107
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   568
  MY_DEBUG ("rx end error");
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   569
  m_lastRxEnd = Simulator::Now ();
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   570
  m_lastRxReceivedOk = false;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   571
  m_rxing = false;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   572
}
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   573
void 
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   574
DcfManager::NotifyTxStartNow (Time duration)
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   575
{
2107
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   576
  MY_DEBUG ("tx start for "<<duration);
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   577
  UpdateBackoff ();
2107
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   578
  m_lastTxStart = Simulator::Now ();
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   579
  m_lastTxDuration = duration;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   580
}
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   581
void 
3905
99c9346b5d71 split interference calculation from YansWifiPhy. Move them to InterferenceHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2524
diff changeset
   582
DcfManager::NotifyMaybeCcaBusyStartNow (Time duration)
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   583
{
2107
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   584
  MY_DEBUG ("busy start for "<<duration);
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   585
  UpdateBackoff ();
2107
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   586
  m_lastBusyStart = Simulator::Now ();
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   587
  m_lastBusyDuration = duration;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   588
}
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   589
void 
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   590
DcfManager::NotifyNavResetNow (Time duration)
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   591
{
2107
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   592
  MY_DEBUG ("nav reset for="<<duration);
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   593
  UpdateBackoff ();
2107
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   594
  m_lastNavStart = Simulator::Now ();
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   595
  m_lastNavDuration = duration;
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   596
  UpdateBackoff ();
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   597
  /**
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   598
   * If the nav reset indicates an end-of-nav which is earlier
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   599
   * than the previous end-of-nav, the expected end of backoff
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   600
   * might be later than previously thought so, we might need
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   601
   * to restart a new access timeout.
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   602
   */
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   603
  DoRestartAccessTimeoutIfNeeded ();
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   604
}
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   605
void 
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   606
DcfManager::NotifyNavStartNow (Time duration)
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   607
{
2107
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   608
  NS_ASSERT (m_lastNavStart < Simulator::Now ());
9adb9e6d7bc7 improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2105
diff changeset
   609
  MY_DEBUG ("nav start for="<<duration);
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   610
  UpdateBackoff ();
2111
54617d2770c8 handle NAV correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2109
diff changeset
   611
  Time newNavEnd = Simulator::Now () + duration;
54617d2770c8 handle NAV correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2109
diff changeset
   612
  Time lastNavEnd = m_lastNavStart + m_lastNavDuration;
54617d2770c8 handle NAV correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2109
diff changeset
   613
  if (newNavEnd > lastNavEnd)
54617d2770c8 handle NAV correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2109
diff changeset
   614
    {
54617d2770c8 handle NAV correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2109
diff changeset
   615
      m_lastNavStart = Simulator::Now ();
54617d2770c8 handle NAV correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2109
diff changeset
   616
      m_lastNavDuration = duration;
54617d2770c8 handle NAV correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2109
diff changeset
   617
    }
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   618
}
4509
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   619
void
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   620
DcfManager::NotifyAckTimeoutStartNow (Time duration)
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   621
{
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   622
  NS_ASSERT(m_lastAckTimeoutEnd < Simulator::Now ());
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   623
  m_lastAckTimeoutEnd = Simulator::Now () + duration;
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   624
}
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   625
void
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   626
DcfManager::NotifyAckTimeoutResetNow ()
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   627
{
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   628
  m_lastAckTimeoutEnd = Simulator::Now ();
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   629
  DoRestartAccessTimeoutIfNeeded ();
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   630
}
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   631
void
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   632
DcfManager::NotifyCtsTimeoutStartNow (Time duration)
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   633
{
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   634
  m_lastCtsTimeoutEnd = Simulator::Now () + duration;
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   635
}
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   636
void
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   637
DcfManager::NotifyCtsTimeoutResetNow ()
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   638
{
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   639
  m_lastCtsTimeoutEnd = Simulator::Now ();
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   640
  DoRestartAccessTimeoutIfNeeded ();
b2654e0f071d bug 556: DcfManager does not handle AckTimeout properly when there are multiple queues
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4460
diff changeset
   641
}
2095
f6ec39e97e4b a new (wholy untested) Dcf implementation
mlacage@thira.inria.fr
parents:
diff changeset
   642
} // namespace ns3