A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
originator-block-ack-agreement.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009, 2010 MIRKO BANCHI
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mirko Banchi <mk.banchi@gmail.com>
19  * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
20  */
21 #include "originator-block-ack-agreement.h"
22 
23 namespace ns3 {
24 
25 OriginatorBlockAckAgreement::OriginatorBlockAckAgreement ()
26  : BlockAckAgreement (),
27  m_state (PENDING),
28  m_sentMpdus (0),
29  m_needBlockAckReq (false)
30 {
31 }
32 OriginatorBlockAckAgreement::OriginatorBlockAckAgreement (Mac48Address recipient, uint8_t tid)
33  : BlockAckAgreement (recipient, tid),
34  m_state (PENDING),
35  m_sentMpdus (0),
36  m_needBlockAckReq (false)
37 {
38 }
39 OriginatorBlockAckAgreement::~OriginatorBlockAckAgreement ()
40 {
41 }
42 void
43 OriginatorBlockAckAgreement::SetState (enum State state)
44 {
45  m_state = state;
46  if (state == INACTIVE)
47  {
48  m_needBlockAckReq = false;
49  m_sentMpdus = 0;
50  }
51 }
52 bool
53 OriginatorBlockAckAgreement::IsPending (void) const
54 {
55  return (m_state == PENDING) ? true : false;
56 }
57 bool
58 OriginatorBlockAckAgreement::IsEstablished (void) const
59 {
60  return (m_state == ESTABLISHED) ? true : false;
61 }
62 bool
63 OriginatorBlockAckAgreement::IsInactive (void) const
64 {
65  return (m_state == INACTIVE) ? true : false;
66 }
67 bool
68 OriginatorBlockAckAgreement::IsUnsuccessful (void) const
69 {
70  return (m_state == UNSUCCESSFUL) ? true : false;
71 }
72 void
74 {
75  NS_ASSERT (m_sentMpdus < m_bufferSize);
76  m_sentMpdus++;
77  uint16_t delta = (nextSeqNumber - m_startingSeq + 4096) % 4096;
78  uint16_t min = m_bufferSize < 64 ? m_bufferSize : 64;
79  if (delta >= min || m_sentMpdus == m_bufferSize)
80  {
81  m_needBlockAckReq = true;
82  }
83 }
84 bool
86 {
87  return m_needBlockAckReq;
88 }
89 void
90 OriginatorBlockAckAgreement::CompleteExchange (void)
91 {
92  m_needBlockAckReq = false;
93  m_sentMpdus = 0;
94 }
95 
96 } // namespace ns3
#define NS_ASSERT(condition)
Definition: assert.h:64
void NotifyMpduTransmission(uint16_t nextSeqNumber)