src/wifi/model/originator-block-ack-agreement.cc
author Junling Bu <linlinjavaer@gmail.com>
Tue, 03 Dec 2013 11:25:59 -0800
changeset 10459 f2e90c12a44f
parent 7386 2310ed220a61
child 11450 9f4ae69f12b7
permissions -rw-r--r--
base implementation of the IEEE 802.11p standard
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7385
10beb0e53130 standardize emacs c++ mode comments
Vedran Miletić <rivanvx@gmail.com>
parents: 7141
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
5951
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
     2
/*
6592
6ef5141e7bcf Packets that cannot be acknowledged in the block ack bitmap must not be transmitted
Mirko Banchi <mk.banchi@gmail.com>
parents: 5951
diff changeset
     3
 * Copyright (c) 2009, 2010 MIRKO BANCHI
5951
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
     4
 *
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
7141
072fb225b714 run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
5951
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
     8
 *
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    12
 * GNU General Public License for more details.
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    13
 *
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    17
 *
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    18
 * Author: Mirko Banchi <mk.banchi@gmail.com>
6592
6ef5141e7bcf Packets that cannot be acknowledged in the block ack bitmap must not be transmitted
Mirko Banchi <mk.banchi@gmail.com>
parents: 5951
diff changeset
    19
 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
5951
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    20
 */
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    21
#include "originator-block-ack-agreement.h"
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    22
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    23
namespace ns3 {
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    24
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    25
OriginatorBlockAckAgreement::OriginatorBlockAckAgreement ()
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    26
  : BlockAckAgreement (),
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    27
    m_state (PENDING),
6592
6ef5141e7bcf Packets that cannot be acknowledged in the block ack bitmap must not be transmitted
Mirko Banchi <mk.banchi@gmail.com>
parents: 5951
diff changeset
    28
    m_sentMpdus (0),
6ef5141e7bcf Packets that cannot be acknowledged in the block ack bitmap must not be transmitted
Mirko Banchi <mk.banchi@gmail.com>
parents: 5951
diff changeset
    29
    m_needBlockAckReq (false)
7141
072fb225b714 run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
    30
{
072fb225b714 run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
    31
}
5951
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    32
OriginatorBlockAckAgreement::OriginatorBlockAckAgreement (Mac48Address recipient, uint8_t tid)
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    33
  : BlockAckAgreement (recipient, tid),
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    34
    m_state (PENDING),
6592
6ef5141e7bcf Packets that cannot be acknowledged in the block ack bitmap must not be transmitted
Mirko Banchi <mk.banchi@gmail.com>
parents: 5951
diff changeset
    35
    m_sentMpdus (0),
6ef5141e7bcf Packets that cannot be acknowledged in the block ack bitmap must not be transmitted
Mirko Banchi <mk.banchi@gmail.com>
parents: 5951
diff changeset
    36
    m_needBlockAckReq (false)
7141
072fb225b714 run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
    37
{
072fb225b714 run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
    38
}
5951
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    39
OriginatorBlockAckAgreement::~OriginatorBlockAckAgreement ()
7141
072fb225b714 run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
    40
{
072fb225b714 run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
    41
}
5951
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    42
void
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    43
OriginatorBlockAckAgreement::SetState (enum State state)
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    44
{
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    45
  m_state = state;
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    46
  if (state == INACTIVE)
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    47
    {
6592
6ef5141e7bcf Packets that cannot be acknowledged in the block ack bitmap must not be transmitted
Mirko Banchi <mk.banchi@gmail.com>
parents: 5951
diff changeset
    48
      m_needBlockAckReq = false;
5951
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    49
      m_sentMpdus = 0;
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    50
    }
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    51
}
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    52
bool
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    53
OriginatorBlockAckAgreement::IsPending (void) const
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    54
{
7141
072fb225b714 run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
    55
  return (m_state == PENDING) ? true : false;
5951
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    56
}
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    57
bool
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    58
OriginatorBlockAckAgreement::IsEstablished (void) const
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    59
{
7141
072fb225b714 run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
    60
  return (m_state == ESTABLISHED) ? true : false;
5951
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    61
}
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    62
bool
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    63
OriginatorBlockAckAgreement::IsInactive (void) const
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    64
{
7141
072fb225b714 run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
    65
  return (m_state == INACTIVE) ? true : false;
5951
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    66
}
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    67
bool
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    68
OriginatorBlockAckAgreement::IsUnsuccessful (void) const
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    69
{
7141
072fb225b714 run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
    70
  return (m_state == UNSUCCESSFUL) ? true : false;
5951
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    71
}
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    72
void
6592
6ef5141e7bcf Packets that cannot be acknowledged in the block ack bitmap must not be transmitted
Mirko Banchi <mk.banchi@gmail.com>
parents: 5951
diff changeset
    73
OriginatorBlockAckAgreement::NotifyMpduTransmission (uint16_t nextSeqNumber)
5951
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    74
{
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    75
  NS_ASSERT (m_sentMpdus < m_bufferSize);
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    76
  m_sentMpdus++;
6592
6ef5141e7bcf Packets that cannot be acknowledged in the block ack bitmap must not be transmitted
Mirko Banchi <mk.banchi@gmail.com>
parents: 5951
diff changeset
    77
  uint16_t delta = (nextSeqNumber - m_startingSeq + 4096) % 4096;
6ef5141e7bcf Packets that cannot be acknowledged in the block ack bitmap must not be transmitted
Mirko Banchi <mk.banchi@gmail.com>
parents: 5951
diff changeset
    78
  uint16_t min = m_bufferSize < 64 ? m_bufferSize : 64;
6ef5141e7bcf Packets that cannot be acknowledged in the block ack bitmap must not be transmitted
Mirko Banchi <mk.banchi@gmail.com>
parents: 5951
diff changeset
    79
  if (delta >= min || m_sentMpdus == m_bufferSize)
6ef5141e7bcf Packets that cannot be acknowledged in the block ack bitmap must not be transmitted
Mirko Banchi <mk.banchi@gmail.com>
parents: 5951
diff changeset
    80
    {
6ef5141e7bcf Packets that cannot be acknowledged in the block ack bitmap must not be transmitted
Mirko Banchi <mk.banchi@gmail.com>
parents: 5951
diff changeset
    81
      m_needBlockAckReq = true;
6ef5141e7bcf Packets that cannot be acknowledged in the block ack bitmap must not be transmitted
Mirko Banchi <mk.banchi@gmail.com>
parents: 5951
diff changeset
    82
    }
5951
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    83
}
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    84
bool
6592
6ef5141e7bcf Packets that cannot be acknowledged in the block ack bitmap must not be transmitted
Mirko Banchi <mk.banchi@gmail.com>
parents: 5951
diff changeset
    85
OriginatorBlockAckAgreement::IsBlockAckRequestNeeded (void) const
5951
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    86
{
6592
6ef5141e7bcf Packets that cannot be acknowledged in the block ack bitmap must not be transmitted
Mirko Banchi <mk.banchi@gmail.com>
parents: 5951
diff changeset
    87
  return m_needBlockAckReq;
5951
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    88
}
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    89
void
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    90
OriginatorBlockAckAgreement::CompleteExchange (void)
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    91
{
6592
6ef5141e7bcf Packets that cannot be acknowledged in the block ack bitmap must not be transmitted
Mirko Banchi <mk.banchi@gmail.com>
parents: 5951
diff changeset
    92
  m_needBlockAckReq = false;
5951
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    93
  m_sentMpdus = 0;
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    94
}
083b4c1ec98d add BlockAckAgreement and OriginatorBlockAckAgreement objects
Mirko Banchi <mk.banchi@gmail.com>
parents:
diff changeset
    95
7386
2310ed220a61 standardize ns-3 namespace declaration format
Vedran Miletić <rivanvx@gmail.com>
parents: 7385
diff changeset
    96
} // namespace ns3