View | Details | Raw Unified | Return to bug 385
Collapse All | Expand All

(-)a73c57952833 (+195 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
//
3
// Copyright (c) 2008-2010 INESC Porto
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: Gustavo J. A. M. Carneiro  <gjc@inescporto.pt> <gjcarneiro@gmail.com>
19
//
20
21
#include "sequence-number.h"
22
#include "ns3/test.h"
23
#include "ns3/object.h"
24
#include "ns3/traced-value.h"
25
#include "ns3/trace-source-accessor.h"
26
27
namespace ns3 {
28
29
class SequenceNumberTestObj : public Object
30
{
31
  TracedValue<SequenceNumber32> m_testTracedSequenceNumber;
32
33
34
public:
35
36
  SequenceNumberTestObj () 
37
  {
38
    m_testTracedSequenceNumber = SequenceNumber32 (0);
39
  }
40
  
41
  static TypeId GetTypeId (void)
42
  {
43
    static TypeId tid = TypeId("ns3::SequenceNumberTestObj")
44
      .SetParent<Object> ()
45
      .AddTraceSource ("TestTracedSequenceNumber",
46
                       "A traceable sequence number",
47
                       MakeTraceSourceAccessor (&SequenceNumberTestObj::m_testTracedSequenceNumber))
48
      .AddConstructor<SequenceNumberTestObj> ()
49
      ;
50
    return tid;
51
  }
52
  
53
  TypeId GetInstanceTypeId (void) const
54
  {
55
    return GetTypeId ();
56
  }
57
58
  void IncSequenceNumber ()
59
  {
60
    m_testTracedSequenceNumber += 1;
61
  }
62
  
63
64
};
65
66
class SequenceNumberTestCase : public TestCase
67
{
68
  SequenceNumber32 m_oldval;
69
  SequenceNumber32 m_newval;
70
71
  void SequenceNumberTracer (SequenceNumber32 oldval, SequenceNumber32 newval);
72
73
public:
74
75
  SequenceNumberTestCase ();
76
  virtual ~SequenceNumberTestCase ();
77
  virtual bool DoRun (void);
78
};
79
80
SequenceNumberTestCase::SequenceNumberTestCase ()
81
  : TestCase ("SequenceNumber")
82
{
83
  m_oldval = 0;
84
  m_newval = 0;
85
}
86
87
SequenceNumberTestCase::~SequenceNumberTestCase ()
88
{}
89
90
void
91
SequenceNumberTestCase::SequenceNumberTracer (SequenceNumber32 oldval, SequenceNumber32 newval) 
92
{
93
  m_oldval = oldval;
94
  m_newval = newval;
95
}
96
97
bool SequenceNumberTestCase::DoRun (void)
98
{
99
#define NS_TEST_ASSERT_EQUAL(a,b) NS_TEST_ASSERT_MSG_EQ(a,b, "foo")
100
#define NS_TEST_ASSERT(a) NS_TEST_ASSERT_MSG_EQ(bool(a), true, "foo")
101
102
  {
103
      SequenceNumber32 num1 (3), num2 (5);
104
      uint32_t value;
105
106
      value = (num1 + num2).GetValue ();
107
      NS_TEST_ASSERT_EQUAL (value, 8);
108
109
      num1 += num2.GetValue ();
110
      NS_TEST_ASSERT_EQUAL (num1, SequenceNumber32 (8));
111
      
112
      ++num1;
113
      NS_TEST_ASSERT_EQUAL (num1, SequenceNumber32 (9));
114
115
      --num1;
116
      NS_TEST_ASSERT_EQUAL (num1, SequenceNumber32 (8));
117
118
      num1++;
119
      NS_TEST_ASSERT_EQUAL (num1, SequenceNumber32 (9));
120
121
      num1--;
122
      NS_TEST_ASSERT_EQUAL (num1, SequenceNumber32 (8));
123
      
124
  }
125
126
  {
127
      SequenceNumber16 num1 (60900), num2 (5), num3 (10000);
128
129
      NS_TEST_ASSERT (num1 == num1);
130
131
      NS_TEST_ASSERT (num2 != num1);
132
133
      NS_TEST_ASSERT (num3 > num2);
134
      NS_TEST_ASSERT (num3 >= num2);
135
      NS_TEST_ASSERT (num1 < num3);
136
      NS_TEST_ASSERT (num1 <= num3);
137
138
      NS_TEST_ASSERT (num1 < num2);
139
      NS_TEST_ASSERT (num1 <= num2);
140
      NS_TEST_ASSERT (num2 > num1);
141
      NS_TEST_ASSERT (num2 >= num1);
142
143
      NS_TEST_ASSERT (num1+num2 > num1);
144
      NS_TEST_ASSERT (num1+num2 >= num1);
145
      NS_TEST_ASSERT (num1 < num1+num2);
146
      NS_TEST_ASSERT (num1 <= num1+num2);
147
148
      NS_TEST_ASSERT (num1 < num1+num3);
149
      NS_TEST_ASSERT (num1 <= num1+num3);
150
      NS_TEST_ASSERT (num1+num3 > num1);
151
      NS_TEST_ASSERT (num1+num3 >= num1);
152
  }
153
154
  {
155
    NS_TEST_ASSERT_EQUAL ((SequenceNumber16 (1000) + SequenceNumber16 (6000)) - SequenceNumber16 (1000), 6000);
156
    NS_TEST_ASSERT_EQUAL ((SequenceNumber16 (60000) + SequenceNumber16 (6000)) - SequenceNumber16 (60000), 6000);
157
    NS_TEST_ASSERT_EQUAL (SequenceNumber16 (1000) - SequenceNumber16 (6000), -5000);
158
    NS_TEST_ASSERT_EQUAL ((SequenceNumber16 (60000) + SequenceNumber16 (1000)) - SequenceNumber16 (65000), -4000);
159
  }
160
  
161
  {
162
    SequenceNumber32 num1 (3);
163
    
164
    NS_TEST_ASSERT_EQUAL (num1 + 10, SequenceNumber32 (13));
165
    num1 += -1;
166
    NS_TEST_ASSERT_EQUAL (num1, SequenceNumber32 (2));
167
    
168
    NS_TEST_ASSERT_EQUAL (num1 - (num1 - 100), 100);
169
  }
170
171
  {
172
    Ptr<SequenceNumberTestObj> obj = CreateObject<SequenceNumberTestObj> ();
173
    obj->TraceConnectWithoutContext ("TestTracedSequenceNumber", MakeCallback (&SequenceNumberTestCase::SequenceNumberTracer, this));
174
    obj->IncSequenceNumber ();
175
    NS_TEST_ASSERT_EQUAL (m_oldval, SequenceNumber32 (0));
176
    NS_TEST_ASSERT_EQUAL (m_newval, SequenceNumber32 (1));
177
    obj->Dispose ();
178
  }
179
  
180
181
  return false;
182
}
183
184
static class SequenceNumberTestSuite : public TestSuite
185
{
186
public:
187
  SequenceNumberTestSuite ()
188
    : TestSuite ("SequenceNumber", UNIT) 
189
  {
190
    AddTestCase (new SequenceNumberTestCase ());
191
  }
192
} g_seqNumTests;
193
194
}
195
(-)a73c57952833 (+270 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
//
3
// Copyright (c) 2008-2010 INESC Porto
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: Gustavo J. A. M. Carneiro  <gjc@inescporto.pt> <gjcarneiro@gmail.com>
19
//
20
21
#ifndef __NS3_SEQ_NUM_H__
22
#define __NS3_SEQ_NUM_H__
23
24
#include <limits>
25
#include <iostream>
26
#include <stdint.h>
27
28
namespace ns3 {
29
30
template<typename NUMERIC_TYPE, typename SIGNED_TYPE>
31
class SequenceNumber
32
{
33
public:
34
  SequenceNumber ()
35
    : m_value (0)
36
  {}
37
38
  // contruct from a plain number; but the contructor is _explicit_, so not called automatically, ever.
39
  explicit SequenceNumber (NUMERIC_TYPE value)
40
    : m_value (value)
41
  {}
42
43
  // copy contructor
44
  SequenceNumber (SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> const &value)
45
    : m_value (value.m_value)
46
  {}
47
48
  // assignment from a plain number
49
  SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& operator= (NUMERIC_TYPE value)
50
  {
51
    m_value = value;
52
    return *this;
53
  }
54
55
  // assignment from a sequence number
56
  SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& operator= (SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> const &value)
57
  {
58
    m_value = value.m_value;
59
    return *this;
60
  }
61
62
#if 0
63
  // a SequenceNumber implicitly converts to a plain number, but not the other way around
64
  operator NUMERIC_TYPE () const
65
  {
66
    return m_value;
67
  }
68
#endif
69
70
  NUMERIC_TYPE GetValue () const
71
  {
72
    return m_value;
73
  }
74
75
  // prefix ++
76
  SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator++ ()
77
  {
78
    m_value++;
79
    return *this;
80
  }
81
82
  // postfix ++
83
  SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator++ (int)
84
  {
85
    SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> retval (m_value);
86
    m_value++;
87
    return retval;
88
  }
89
90
  // prefix --
91
  SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator-- ()
92
  {
93
    m_value--;
94
    return *this;
95
  }
96
97
  // postfix --
98
  SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator-- (int)
99
  {
100
    SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> retval (m_value);
101
    m_value--;
102
    return retval;
103
  }
104
105
  SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& operator+= (SIGNED_TYPE value)
106
  {
107
    m_value += value;
108
    return *this;
109
  }
110
111
  SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& operator-= (SIGNED_TYPE value)
112
  {
113
    m_value -= value;
114
    return *this;
115
  }
116
117
  SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator + (const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> &other) const
118
  {
119
    return SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> (m_value + other.m_value);
120
  }
121
122
  SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator + (SIGNED_TYPE delta) const
123
  {
124
    return SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> (m_value + delta);
125
  }
126
127
  SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator - (SIGNED_TYPE delta) const
128
  {
129
    return SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> (m_value - delta);
130
  }
131
132
  SIGNED_TYPE operator - (const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> &other) const
133
  {
134
    static const NUMERIC_TYPE maxValue = std::numeric_limits<NUMERIC_TYPE>::max ();
135
    static const NUMERIC_TYPE halfMaxValue = std::numeric_limits<NUMERIC_TYPE>::max () / 2;
136
    if (m_value > other.m_value)
137
      {
138
        NUMERIC_TYPE diff = m_value - other.m_value;
139
        if (diff < halfMaxValue)
140
          {
141
            return static_cast<SIGNED_TYPE> (diff);
142
          }
143
        else
144
          {
145
            //      |------------|------------|
146
            //       ====                  ===
147
            //          ^                  ^
148
            //       other.m_value      m_value
149
            return -(static_cast<SIGNED_TYPE> (maxValue - m_value + 1 + other.m_value));
150
          }
151
      }
152
    else
153
      {
154
        NUMERIC_TYPE diff = other.m_value - m_value;
155
        if (diff < halfMaxValue)
156
          {
157
            //      |------------|------------|
158
            //          ========
159
            //          ^      ^
160
            //     m_value   other.m_value
161
            return -(static_cast<SIGNED_TYPE> (diff));
162
          }
163
        else
164
          {
165
            //      |------------|------------|
166
            //       ====                  ===
167
            //          ^                  ^
168
            //       m_value      other.m_value
169
            return static_cast<SIGNED_TYPE> (maxValue - other.m_value + 1 + m_value);
170
          }
171
      }
172
  }
173
174
175
  // Here is the critical part, how the comparison is made taking into
176
  // account wrap-around.  From RFC 3626:
177
  //
178
  //   The sequence number S1 is said to be "greater than" the sequence
179
  //    number S2 if:
180
  //
181
  //           S1 > S2 AND S1 - S2 <= MAXVALUE/2 OR
182
  //
183
  //           S2 > S1 AND S2 - S1 > MAXVALUE/2
184
  bool operator > (const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> &other) const
185
  {
186
    static const NUMERIC_TYPE halfMaxValue = std::numeric_limits<NUMERIC_TYPE>::max () / 2;
187
188
    return (((m_value > other.m_value) && (m_value - other.m_value) <= halfMaxValue)
189
            || ((other.m_value > m_value) && (other.m_value - m_value) > halfMaxValue));
190
  }
191
192
  bool operator == (const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> &other) const
193
  {
194
    return (m_value == other.m_value);
195
  }
196
197
  bool operator != (const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> &other) const
198
  {
199
    return (m_value != other.m_value);
200
  }
201
202
  bool operator <= (const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> &other) const
203
  {
204
    return (!this->operator> (other));
205
  }
206
207
  bool operator >= (const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> &other) const
208
  {
209
    return (this->operator> (other) || this->operator== (other));
210
  }
211
212
  bool operator < (const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> &other) const
213
  {
214
    return !this->operator> (other) && m_value != other.m_value;
215
  }
216
217
218
  template<typename NUMERIC_TYPE2, typename SIGNED_TYPE2>
219
  friend std::ostream & operator<< (std::ostream& os, const SequenceNumber<NUMERIC_TYPE2, SIGNED_TYPE2> &val);
220
221
  template<typename NUMERIC_TYPE2, typename SIGNED_TYPE2>
222
  friend std::istream & operator >> (std::istream &is, const SequenceNumber<NUMERIC_TYPE2, SIGNED_TYPE2> &val);
223
224
private: // unimplemented operators
225
  SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& operator+= (SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> const &value);
226
  SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& operator-= (SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> const &value);
227
  SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator* (const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& b) const;
228
  SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator/ (const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& b) const;
229
  SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator% (const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& b) const;
230
  bool operator ! () const;
231
  bool operator && (const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& b) const;
232
  bool operator || (const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& b) const;
233
  SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator~ () const;
234
  SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator& (const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& b) const;
235
  SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator| (const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& b) const;
236
  SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator^ (const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& b) const;
237
  SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator<< (const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& b) const;
238
  SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> operator>> (const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>& b) const;
239
  int operator* ();
240
  SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE>* operator& ();
241
242
private:
243
  NUMERIC_TYPE m_value;
244
};
245
246
247
template<typename NUMERIC_TYPE, typename SIGNED_TYPE>
248
std::ostream &
249
operator<< (std::ostream& os, const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> &val)
250
{
251
  os << val.m_value;
252
  return os;
253
}
254
  
255
template<typename NUMERIC_TYPE, typename SIGNED_TYPE>
256
std::istream & operator >> (std::istream &is, const SequenceNumber<NUMERIC_TYPE, SIGNED_TYPE> &val)
257
{
258
  is >> val.m_value;
259
  return is;
260
}
261
262
263
typedef SequenceNumber<uint32_t, int32_t> SequenceNumber32;
264
typedef SequenceNumber<uint16_t, int16_t> SequenceNumber16;
265
266
} // namespace ns3
267
268
#endif
269
270
(-)a/src/common/wscript (+2 lines)
 Lines 34-39    Link Here 
34
        'spectrum-type.cc',
34
        'spectrum-type.cc',
35
        'spectrum-propagation-loss-model.cc',
35
        'spectrum-propagation-loss-model.cc',
36
        'friis-spectrum-propagation-loss.cc',
36
        'friis-spectrum-propagation-loss.cc',
37
        'sequence-number.cc',
37
        ]
38
        ]
38
39
39
    headers = bld.new_task_gen('ns3header')
40
    headers = bld.new_task_gen('ns3header')
 Lines 67-70    Link Here 
67
        'spectrum-type.h',
68
        'spectrum-type.h',
68
        'spectrum-propagation-loss-model.h',
69
        'spectrum-propagation-loss-model.h',
69
        'friis-spectrum-propagation-loss.h',
70
        'friis-spectrum-propagation-loss.h',
71
        'sequence-number.h',
70
        ]
72
        ]
(-)a/src/devices/wifi/mac-rx-middle.cc (-2 / +2 lines)
 Lines 25-30    Link Here 
25
#include "ns3/log.h"
25
#include "ns3/log.h"
26
#include "ns3/packet.h"
26
#include "ns3/packet.h"
27
#include "ns3/simulator.h"
27
#include "ns3/simulator.h"
28
#include "ns3/sequence-number.h"
28
#include <list>
29
#include <list>
29
30
30
NS_LOG_COMPONENT_DEFINE ("MacRxMiddle");
31
NS_LOG_COMPONENT_DEFINE ("MacRxMiddle");
 Lines 269-276    Link Here 
269
   * So, this check cannot be used to discard old duplicate frames. It is
270
   * So, this check cannot be used to discard old duplicate frames. It is
270
   * thus here only for documentation purposes.
271
   * thus here only for documentation purposes.
271
   */
272
   */
272
  if (!SequenceControlSmaller (originator->GetLastSequenceControl (), 
273
  if (!(SequenceNumber16 (originator->GetLastSequenceControl ()) < SequenceNumber16 (hdr->GetSequenceControl ())))
273
                               hdr->GetSequenceControl ()))
274
    {
274
    {
275
      NS_LOG_DEBUG ("Sequence numbers have looped back. last recorded="<<originator->GetLastSequenceControl ()<<
275
      NS_LOG_DEBUG ("Sequence numbers have looped back. last recorded="<<originator->GetLastSequenceControl ()<<
276
                    " currently seen="<< hdr->GetSequenceControl ());
276
                    " currently seen="<< hdr->GetSequenceControl ());
(-)a/src/internet-stack/nsc-tcp-socket-impl.h (-1 / +1 lines)
 Lines 29-35    Link Here 
29
#include "ns3/event-id.h"
29
#include "ns3/event-id.h"
30
#include "tcp-typedefs.h"
30
#include "tcp-typedefs.h"
31
#include "pending-data.h"
31
#include "pending-data.h"
32
#include "sequence-number.h"
32
#include "ns3/sequence-number.h"
33
33
34
struct INetStreamSocket;
34
struct INetStreamSocket;
35
35
(-)a/src/internet-stack/pending-data.cc (-4 / +4 lines)
 Lines 119-125    Link Here 
119
  size += p->GetSize();
119
  size += p->GetSize();
120
}
120
}
121
121
122
uint32_t PendingData::SizeFromSeq (const SequenceNumber& seqFront, const SequenceNumber& seqOffset)
122
uint32_t PendingData::SizeFromSeq (const SequenceNumber32& seqFront, const SequenceNumber32& seqOffset)
123
{
123
{
124
  NS_LOG_FUNCTION (this << seqFront << seqOffset);
124
  NS_LOG_FUNCTION (this << seqFront << seqOffset);
125
  uint32_t o1 = OffsetFromSeq (seqFront, seqOffset); // Offset to start of unused data
125
  uint32_t o1 = OffsetFromSeq (seqFront, seqOffset); // Offset to start of unused data
 Lines 134-140    Link Here 
134
  return size - offset;            // Available data after offset
134
  return size - offset;            // Available data after offset
135
}
135
}
136
136
137
uint32_t PendingData::OffsetFromSeq (const SequenceNumber& seqFront, const SequenceNumber& seqOffset)
137
uint32_t PendingData::OffsetFromSeq (const SequenceNumber32& seqFront, const SequenceNumber32& seqOffset)
138
{ // f is the first sequence number in this data, o is offset sequence
138
{ // f is the first sequence number in this data, o is offset sequence
139
  NS_LOG_FUNCTION (this << seqFront << seqOffset);
139
  NS_LOG_FUNCTION (this << seqFront << seqOffset);
140
  if (seqOffset < seqFront) 
140
  if (seqOffset < seqFront) 
 Lines 215-228    Link Here 
215
    }
215
    }
216
}
216
}
217
217
218
Ptr<Packet> PendingData::CopyFromSeq (uint32_t s, const SequenceNumber& f, const SequenceNumber& o)
218
Ptr<Packet> PendingData::CopyFromSeq (uint32_t s, const SequenceNumber32& f, const SequenceNumber32& o)
219
{
219
{
220
  NS_LOG_FUNCTION (this << s << f << o);
220
  NS_LOG_FUNCTION (this << s << f << o);
221
  return CopyFromOffset (s, OffsetFromSeq(f,o));
221
  return CopyFromOffset (s, OffsetFromSeq(f,o));
222
}
222
}
223
223
224
uint32_t
224
uint32_t
225
PendingData::RemoveToSeq (const SequenceNumber& seqFront, const SequenceNumber& seqOffset)
225
PendingData::RemoveToSeq (const SequenceNumber32& seqFront, const SequenceNumber32& seqOffset)
226
{
226
{
227
  NS_LOG_FUNCTION (this << seqFront << seqOffset);
227
  NS_LOG_FUNCTION (this << seqFront << seqOffset);
228
  uint32_t count = OffsetFromSeq (seqFront, seqOffset);
228
  uint32_t count = OffsetFromSeq (seqFront, seqOffset);
(-)a/src/internet-stack/pending-data.h (-5 / +5 lines)
 Lines 26-32    Link Here 
26
26
27
#include "ns3/packet.h"
27
#include "ns3/packet.h"
28
#include "pending-data.h"
28
#include "pending-data.h"
29
#include "sequence-number.h"
29
#include "ns3/sequence-number.h"
30
30
31
#include "ns3/ptr.h"
31
#include "ns3/ptr.h"
32
namespace ns3
32
namespace ns3
 Lines 72-78    Link Here 
72
   * \param seqFront sequence number of assumed first byte in the PendingData
72
   * \param seqFront sequence number of assumed first byte in the PendingData
73
   * \param seqOffset sequence number of offset 
73
   * \param seqOffset sequence number of offset 
74
   */
74
   */
75
  virtual uint32_t SizeFromSeq (const SequenceNumber& seqFront, const SequenceNumber& seqOffset);
75
  virtual uint32_t SizeFromSeq (const SequenceNumber32& seqFront, const SequenceNumber32& seqOffset);
76
  // Inquire available data from offset
76
  // Inquire available data from offset
77
  /**
77
  /**
78
   * \return number of bytes in the data buffer beyond the offset specified
78
   * \return number of bytes in the data buffer beyond the offset specified
 Lines 88-97    Link Here 
88
   * \param seqOffset higher sequence number
88
   * \param seqOffset higher sequence number
89
   * \return seqOffset-seqFront
89
   * \return seqOffset-seqFront
90
   */
90
   */
91
  virtual uint32_t OffsetFromSeq (const SequenceNumber& seqFront, const SequenceNumber& seqOffset);
91
  virtual uint32_t OffsetFromSeq (const SequenceNumber32& seqFront, const SequenceNumber32& seqOffset);
92
  virtual Ptr<Packet> CopyFromOffset (uint32_t, uint32_t);  // Size, offset, ret packet
92
  virtual Ptr<Packet> CopyFromOffset (uint32_t, uint32_t);  // Size, offset, ret packet
93
  // Copy data, size, offset specified by sequence difference
93
  // Copy data, size, offset specified by sequence difference
94
  virtual Ptr<Packet> CopyFromSeq (uint32_t, const SequenceNumber&, const SequenceNumber&);
94
  virtual Ptr<Packet> CopyFromSeq (uint32_t, const SequenceNumber32&, const SequenceNumber32&);
95
  /**
95
  /**
96
   * Permits object to clear any pending data between seqFront and 
96
   * Permits object to clear any pending data between seqFront and 
97
   * seqOffset - 1).  Callers should check the return value to determine
97
   * seqOffset - 1).  Callers should check the return value to determine
 Lines 101-107    Link Here 
101
   * \param seqOffset first sequence number in buffer that should be retained
101
   * \param seqOffset first sequence number in buffer that should be retained
102
   * \return number of bytes from the front that were removed from the buffer
102
   * \return number of bytes from the front that were removed from the buffer
103
   */
103
   */
104
  virtual uint32_t RemoveToSeq (const SequenceNumber& seqFront, const SequenceNumber& seqOffset);
104
  virtual uint32_t RemoveToSeq (const SequenceNumber32& seqFront, const SequenceNumber32& seqOffset);
105
  PendingData*   Copy () const;          // Create a copy of this header
105
  PendingData*   Copy () const;          // Create a copy of this header
106
  PendingData*   CopyS (uint32_t);         // Copy with new size
106
  PendingData*   CopyS (uint32_t);         // Copy with new size
107
  PendingData*   CopySD (uint32_t, uint8_t*); // Copy with new size, new data
107
  PendingData*   CopySD (uint32_t, uint8_t*); // Copy with new size, new data
(-)a/src/internet-stack/rtt-estimator.cc (-10 / +10 lines)
 Lines 61-67    Link Here 
61
}
61
}
62
62
63
//RttHistory methods
63
//RttHistory methods
64
RttHistory::RttHistory (SequenceNumber s, uint32_t c, Time t)
64
RttHistory::RttHistory (SequenceNumber32 s, uint32_t c, Time t)
65
  : seq (s), count (c), time (t), retx (false)
65
  : seq (s), count (c), time (t), retx (false)
66
  {
66
  {
67
  }
67
  }
 Lines 89-113    Link Here 
89
{
89
{
90
}
90
}
91
91
92
void RttEstimator::SentSeq (SequenceNumber s, uint32_t c)
92
void RttEstimator::SentSeq (SequenceNumber32 s, uint32_t c)
93
{ // Note that a particular sequence has been sent
93
{ // Note that a particular sequence has been sent
94
  if (s == next)
94
  if (s == next)
95
    { // This is the next expected one, just log at end
95
    { // This is the next expected one, just log at end
96
      history.push_back (RttHistory (s, c, Simulator::Now () ));
96
      history.push_back (RttHistory (s, c, Simulator::Now () ));
97
      next = s + SequenceNumber (c); // Update next expected
97
      next = s + SequenceNumber32 (c); // Update next expected
98
    }
98
    }
99
  else
99
  else
100
    { // This is a retransmit, find in list and mark as re-tx
100
    { // This is a retransmit, find in list and mark as re-tx
101
      for (RttHistory_t::iterator i = history.begin (); i != history.end (); ++i)
101
      for (RttHistory_t::iterator i = history.begin (); i != history.end (); ++i)
102
        {
102
        {
103
          if ((s >= i->seq) && (s < (i->seq + SequenceNumber (i->count))))
103
          if ((s >= i->seq) && (s < (i->seq + SequenceNumber32 (i->count))))
104
            { // Found it
104
            { // Found it
105
              i->retx = true;
105
              i->retx = true;
106
              // One final test..be sure this re-tx does not extend "next"
106
              // One final test..be sure this re-tx does not extend "next"
107
              if ((s + SequenceNumber (c)) > next)
107
              if ((s + SequenceNumber32 (c)) > next)
108
                {
108
                {
109
                  next = s + SequenceNumber (c);
109
                  next = s + SequenceNumber32 (c);
110
                  i->count = ((s + SequenceNumber (c)) - i->seq); // And update count in hist
110
                  i->count = ((s + SequenceNumber32 (c)) - i->seq); // And update count in hist
111
                }
111
                }
112
              break;
112
              break;
113
            }
113
            }
 Lines 115-128    Link Here 
115
    }
115
    }
116
}
116
}
117
117
118
Time RttEstimator::AckSeq (SequenceNumber a)
118
Time RttEstimator::AckSeq (SequenceNumber32 a)
119
{ // An ack has been received, calculate rtt and log this measurement
119
{ // An ack has been received, calculate rtt and log this measurement
120
  // Note we use a linear search (O(n)) for this since for the common
120
  // Note we use a linear search (O(n)) for this since for the common
121
  // case the ack'ed packet will be at the head of the list
121
  // case the ack'ed packet will be at the head of the list
122
  Time m = Seconds (0.0);
122
  Time m = Seconds (0.0);
123
  if (history.size () == 0) return (m);    // No pending history, just exit
123
  if (history.size () == 0) return (m);    // No pending history, just exit
124
  RttHistory& h = history.front ();
124
  RttHistory& h = history.front ();
125
  if (!h.retx && a >= (h.seq + SequenceNumber (h.count)))
125
  if (!h.retx && a >= (h.seq + SequenceNumber32 (h.count)))
126
    { // Ok to use this sample
126
    { // Ok to use this sample
127
      m = Simulator::Now () - h.time; // Elapsed time
127
      m = Simulator::Now () - h.time; // Elapsed time
128
      Measurement(m);                // Log the measurement
128
      Measurement(m);                // Log the measurement
 Lines 132-138    Link Here 
132
  while(history.size() > 0)
132
  while(history.size() > 0)
133
    {
133
    {
134
      RttHistory& h = history.front ();
134
      RttHistory& h = history.front ();
135
      if ((h.seq + SequenceNumber(h.count)) > a) break;                // Done removing
135
      if ((h.seq + SequenceNumber32(h.count)) > a) break;                // Done removing
136
      history.pop_front (); // Remove
136
      history.pop_front (); // Remove
137
    }
137
    }
138
  return m;
138
  return m;
(-)a/src/internet-stack/rtt-estimator.h (-7 / +7 lines)
 Lines 26-32    Link Here 
26
#define __rtt_estimator_h__
26
#define __rtt_estimator_h__
27
27
28
#include <deque>
28
#include <deque>
29
#include "sequence-number.h"
29
#include "ns3/sequence-number.h"
30
#include "ns3/nstime.h"
30
#include "ns3/nstime.h"
31
#include "ns3/object.h"
31
#include "ns3/object.h"
32
32
 Lines 39-48    Link Here 
39
 */
39
 */
40
class RttHistory {
40
class RttHistory {
41
public:
41
public:
42
  RttHistory (SequenceNumber s, uint32_t c, Time t);
42
  RttHistory (SequenceNumber32 s, uint32_t c, Time t);
43
  RttHistory (const RttHistory& h); // Copy constructor
43
  RttHistory (const RttHistory& h); // Copy constructor
44
public:
44
public:
45
  SequenceNumber  seq;    // First sequence number in packet sent
45
  SequenceNumber32  seq;    // First sequence number in packet sent
46
  uint32_t        count;  // Number of bytes sent
46
  uint32_t        count;  // Number of bytes sent
47
  Time            time;   // Time this one was sent
47
  Time            time;   // Time this one was sent
48
  bool            retx;   // True if this has been retransmitted
48
  bool            retx;   // True if this has been retransmitted
 Lines 58-77    Link Here 
58
  RttEstimator(const RttEstimator&); // Copy constructor
58
  RttEstimator(const RttEstimator&); // Copy constructor
59
  virtual ~RttEstimator();
59
  virtual ~RttEstimator();
60
60
61
  virtual void SentSeq(SequenceNumber, uint32_t);
61
  virtual void SentSeq(SequenceNumber32, uint32_t);
62
  virtual Time AckSeq(SequenceNumber);
62
  virtual Time AckSeq(SequenceNumber32);
63
  virtual void ClearSent();
63
  virtual void ClearSent();
64
  virtual void   Measurement(Time t) = 0;
64
  virtual void   Measurement(Time t) = 0;
65
  virtual Time Estimate() = 0;
65
  virtual Time Estimate() = 0;
66
  virtual Time RetransmitTimeout() = 0;
66
  virtual Time RetransmitTimeout() = 0;
67
  void Init(SequenceNumber s) { next = s;}
67
  void Init(SequenceNumber32 s) { next = s;}
68
  virtual Ptr<RttEstimator> Copy() const = 0;
68
  virtual Ptr<RttEstimator> Copy() const = 0;
69
  virtual void IncreaseMultiplier();
69
  virtual void IncreaseMultiplier();
70
  virtual void ResetMultiplier();
70
  virtual void ResetMultiplier();
71
  virtual void Reset();
71
  virtual void Reset();
72
72
73
private:
73
private:
74
  SequenceNumber        next;    // Next expected sequence to be sent
74
  SequenceNumber32        next;    // Next expected sequence to be sent
75
  RttHistory_t history; // List of sent packet
75
  RttHistory_t history; // List of sent packet
76
  double m_maxMultiplier;
76
  double m_maxMultiplier;
77
public:
77
public:
(-)a/src/internet-stack/tcp-header.cc (-6 / +6 lines)
 Lines 59-69    Link Here 
59
{
59
{
60
  m_destinationPort = port;
60
  m_destinationPort = port;
61
}
61
}
62
void TcpHeader::SetSequenceNumber (SequenceNumber sequenceNumber)
62
void TcpHeader::SetSequenceNumber (SequenceNumber32 sequenceNumber)
63
{
63
{
64
  m_sequenceNumber = sequenceNumber;
64
  m_sequenceNumber = sequenceNumber;
65
}
65
}
66
void TcpHeader::SetAckNumber (SequenceNumber ackNumber)
66
void TcpHeader::SetAckNumber (SequenceNumber32 ackNumber)
67
{
67
{
68
  m_ackNumber = ackNumber;
68
  m_ackNumber = ackNumber;
69
}
69
}
 Lines 92-102    Link Here 
92
{
92
{
93
  return m_destinationPort;
93
  return m_destinationPort;
94
}
94
}
95
SequenceNumber TcpHeader::GetSequenceNumber () const
95
SequenceNumber32 TcpHeader::GetSequenceNumber () const
96
{
96
{
97
  return m_sequenceNumber;
97
  return m_sequenceNumber;
98
}
98
}
99
SequenceNumber TcpHeader::GetAckNumber () const
99
SequenceNumber32 TcpHeader::GetAckNumber () const
100
{
100
{
101
  return m_ackNumber;
101
  return m_ackNumber;
102
}
102
}
 Lines 209-216    Link Here 
209
  Buffer::Iterator i = start;
209
  Buffer::Iterator i = start;
210
  i.WriteHtonU16 (m_sourcePort);
210
  i.WriteHtonU16 (m_sourcePort);
211
  i.WriteHtonU16 (m_destinationPort);
211
  i.WriteHtonU16 (m_destinationPort);
212
  i.WriteHtonU32 (m_sequenceNumber);
212
  i.WriteHtonU32 (m_sequenceNumber.GetValue ());
213
  i.WriteHtonU32 (m_ackNumber);
213
  i.WriteHtonU32 (m_ackNumber.GetValue ());
214
  i.WriteHtonU16 (m_length << 12 | m_flags); //reserved bits are all zero
214
  i.WriteHtonU16 (m_length << 12 | m_flags); //reserved bits are all zero
215
  i.WriteHtonU16 (m_windowSize);
215
  i.WriteHtonU16 (m_windowSize);
216
  i.WriteHtonU16 (0);
216
  i.WriteHtonU16 (0);
(-)a/src/internet-stack/tcp-header.h (-6 / +6 lines)
 Lines 61-71    Link Here 
61
  /**
61
  /**
62
   * \param sequenceNumber the sequence number for this TcpHeader
62
   * \param sequenceNumber the sequence number for this TcpHeader
63
   */
63
   */
64
  void SetSequenceNumber (SequenceNumber sequenceNumber);
64
  void SetSequenceNumber (SequenceNumber32 sequenceNumber);
65
  /**
65
  /**
66
   * \param ackNumber the ACK number for this TcpHeader
66
   * \param ackNumber the ACK number for this TcpHeader
67
   */
67
   */
68
  void SetAckNumber (SequenceNumber ackNumber);
68
  void SetAckNumber (SequenceNumber32 ackNumber);
69
  /**
69
  /**
70
   * \param length the length of this TcpHeader
70
   * \param length the length of this TcpHeader
71
   */
71
   */
 Lines 96-106    Link Here 
96
  /**
96
  /**
97
   * \return the sequence number for this TcpHeader
97
   * \return the sequence number for this TcpHeader
98
   */
98
   */
99
  SequenceNumber GetSequenceNumber () const;
99
  SequenceNumber32 GetSequenceNumber () const;
100
  /**
100
  /**
101
   * \return the ACK number for this TcpHeader
101
   * \return the ACK number for this TcpHeader
102
   */
102
   */
103
  SequenceNumber GetAckNumber () const;
103
  SequenceNumber32 GetAckNumber () const;
104
  /**
104
  /**
105
   * \return the length of this TcpHeader
105
   * \return the length of this TcpHeader
106
   */
106
   */
 Lines 153-160    Link Here 
153
  uint16_t CalculateHeaderChecksum (uint16_t size) const;
153
  uint16_t CalculateHeaderChecksum (uint16_t size) const;
154
  uint16_t m_sourcePort;
154
  uint16_t m_sourcePort;
155
  uint16_t m_destinationPort;
155
  uint16_t m_destinationPort;
156
  uint32_t m_sequenceNumber;
156
  SequenceNumber32 m_sequenceNumber;
157
  uint32_t m_ackNumber;
157
  SequenceNumber32 m_ackNumber;
158
  uint8_t m_length; // really a uint4_t
158
  uint8_t m_length; // really a uint4_t
159
  uint8_t m_flags;      // really a uint6_t
159
  uint8_t m_flags;      // really a uint6_t
160
  uint16_t m_windowSize;
160
  uint16_t m_windowSize;
(-)a/src/internet-stack/tcp-l4-protocol.cc (-3 / +3 lines)
 Lines 534-541    Link Here 
534
        else
534
        else
535
          {
535
          {
536
            header.SetFlags (TcpHeader::RST | TcpHeader::ACK);
536
            header.SetFlags (TcpHeader::RST | TcpHeader::ACK);
537
            header.SetSequenceNumber (SequenceNumber (0));
537
            header.SetSequenceNumber (SequenceNumber32 (0));
538
            header.SetAckNumber (header.GetSequenceNumber () + SequenceNumber (1));
538
            header.SetAckNumber (header.GetSequenceNumber () + SequenceNumber32 (1));
539
          }
539
          }
540
        header.SetSourcePort (tcpHeader.GetDestinationPort ());
540
        header.SetSourcePort (tcpHeader.GetDestinationPort ());
541
        header.SetDestinationPort (tcpHeader.GetSourcePort ());
541
        header.SetDestinationPort (tcpHeader.GetSourcePort ());
 Lines 571-577    Link Here 
571
                               daddr,
571
                               daddr,
572
                               PROT_NUMBER);
572
                               PROT_NUMBER);
573
  tcpHeader.SetFlags (TcpHeader::ACK);
573
  tcpHeader.SetFlags (TcpHeader::ACK);
574
  tcpHeader.SetAckNumber (0);
574
  tcpHeader.SetAckNumber (SequenceNumber32 (0));
575
575
576
  packet->AddHeader (tcpHeader);
576
  packet->AddHeader (tcpHeader);
577
577
(-)a/src/internet-stack/tcp-socket-impl.cc (-27 / +27 lines)
 Lines 347-353    Link Here 
347
                   " deferring close, state " << m_state);
347
                   " deferring close, state " << m_state);
348
      return 0;
348
      return 0;
349
    }
349
    }
350
  m_finSequence = m_nextTxSequence + SequenceNumber (1);
350
  m_finSequence = m_nextTxSequence + SequenceNumber32 (1);
351
  Actions_t action  = ProcessEvent (APP_CLOSE);
351
  Actions_t action  = ProcessEvent (APP_CLOSE);
352
  ProcessAction (action);
352
  ProcessAction (action);
353
  return 0;
353
  return 0;
 Lines 548-554    Link Here 
548
        << m_bufferedData.size () 
548
        << m_bufferedData.size () 
549
        << " time " << Simulator::Now ());
549
        << " time " << Simulator::Now ());
550
      i = m_bufferedData.begin ();
550
      i = m_bufferedData.begin ();
551
      SequenceNumber s1 = 0;
551
      SequenceNumber32 s1 (0);
552
      if (i->first > m_nextRxSequence) 
552
      if (i->first > m_nextRxSequence) 
553
        {
553
        {
554
          break;  // we're done, no more in-sequence data exits
554
          break;  // we're done, no more in-sequence data exits
 Lines 588-594    Link Here 
588
      uint32_t avail = maxSize - outPacket->GetSize();
588
      uint32_t avail = maxSize - outPacket->GetSize();
589
      outPacket->AddAtEnd(i->second->CreateFragment(0,avail));
589
      outPacket->AddAtEnd(i->second->CreateFragment(0,avail));
590
      //put the rest back into the buffer
590
      //put the rest back into the buffer
591
      m_bufferedData[i->first+SequenceNumber(avail)] 
591
      m_bufferedData[i->first+SequenceNumber32(avail)] 
592
          = i->second->CreateFragment(avail,i->second->GetSize()-avail);
592
          = i->second->CreateFragment(avail,i->second->GetSize()-avail);
593
      m_rxAvailable += i->second->GetSize()-avail;
593
      m_rxAvailable += i->second->GetSize()-avail;
594
      m_rxBufSize += i->second->GetSize()-avail;
594
      m_rxBufSize += i->second->GetSize()-avail;
 Lines 971-977    Link Here 
971
          // This is the cloned endpoint
971
          // This is the cloned endpoint
972
          // TCP SYN consumes one byte
972
          // TCP SYN consumes one byte
973
          m_nextRxSequence = tcpHeader.GetSequenceNumber () 
973
          m_nextRxSequence = tcpHeader.GetSequenceNumber () 
974
                             + SequenceNumber (1);
974
                             + SequenceNumber32 (1);
975
          SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK);
975
          SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK);
976
        }
976
        }
977
977
 Lines 979-985    Link Here 
979
    case ACK_TX_1:
979
    case ACK_TX_1:
980
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action ACK_TX_1");
980
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action ACK_TX_1");
981
      // TCP SYN consumes one byte
981
      // TCP SYN consumes one byte
982
      m_nextRxSequence = tcpHeader.GetSequenceNumber() + SequenceNumber(1);
982
      m_nextRxSequence = tcpHeader.GetSequenceNumber() + SequenceNumber32(1);
983
      m_nextTxSequence = tcpHeader.GetAckNumber ();
983
      m_nextTxSequence = tcpHeader.GetAckNumber ();
984
      m_firstPendingSequence = m_nextTxSequence;  //bug 166
984
      m_firstPendingSequence = m_nextTxSequence;  //bug 166
985
      NS_LOG_DEBUG ("TcpSocketImpl " << this << " ACK_TX_1" <<
985
      NS_LOG_DEBUG ("TcpSocketImpl " << this << " ACK_TX_1" <<
 Lines 1045-1051    Link Here 
1045
          if (m_finSequence != m_nextRxSequence)
1045
          if (m_finSequence != m_nextRxSequence)
1046
            {
1046
            {
1047
              // process close later
1047
              // process close later
1048
              m_finSequence = tcpHeader.GetSequenceNumber () + SequenceNumber (p->GetSize ());
1048
              m_finSequence = tcpHeader.GetSequenceNumber () + SequenceNumber32 (p->GetSize ());
1049
              m_pendingClose = true;
1049
              m_pendingClose = true;
1050
              NS_LOG_LOGIC ("TcpSocketImpl " << this << " setting pendingClose" 
1050
              NS_LOG_LOGIC ("TcpSocketImpl " << this << " setting pendingClose" 
1051
                << " rxseq " << tcpHeader.GetSequenceNumber () 
1051
                << " rxseq " << tcpHeader.GetSequenceNumber () 
 Lines 1168-1177    Link Here 
1168
      uint32_t sz = p->GetSize (); // Size of packet
1168
      uint32_t sz = p->GetSize (); // Size of packet
1169
      uint32_t remainingData = m_pendingData->SizeFromSeq(
1169
      uint32_t remainingData = m_pendingData->SizeFromSeq(
1170
          m_firstPendingSequence,
1170
          m_firstPendingSequence,
1171
          m_nextTxSequence + SequenceNumber (sz));
1171
          m_nextTxSequence + SequenceNumber32 (sz));
1172
      if (m_closeOnEmpty && (remainingData == 0))
1172
      if (m_closeOnEmpty && (remainingData == 0))
1173
        {
1173
        {
1174
          m_finSequence = m_nextTxSequence + SequenceNumber (1 + sz);
1174
          m_finSequence = m_nextTxSequence + SequenceNumber32 (1 + sz);
1175
          flags = TcpHeader::FIN;
1175
          flags = TcpHeader::FIN;
1176
          m_state = FIN_WAIT_1;
1176
          m_state = FIN_WAIT_1;
1177
        }
1177
        }
 Lines 1303-1310    Link Here 
1303
      UnAckData_t::iterator next = m_bufferedData.upper_bound (m_nextRxSequence);
1303
      UnAckData_t::iterator next = m_bufferedData.upper_bound (m_nextRxSequence);
1304
      if (next != m_bufferedData.end ())
1304
      if (next != m_bufferedData.end ())
1305
      {
1305
      {
1306
        SequenceNumber nextBufferedSeq = next->first;
1306
        SequenceNumber32 nextBufferedSeq = next->first;
1307
        if (m_nextRxSequence + SequenceNumber(s) > nextBufferedSeq)
1307
        if (m_nextRxSequence + SequenceNumber32(s) > nextBufferedSeq)
1308
        {//tail end isn't all new, trim enough off the end
1308
        {//tail end isn't all new, trim enough off the end
1309
          s = nextBufferedSeq - m_nextRxSequence;
1309
          s = nextBufferedSeq - m_nextRxSequence;
1310
        }
1310
        }
 Lines 1344-1357    Link Here 
1344
      NS_LOG_LOGIC ("Case 2, buffering " << tcpHeader.GetSequenceNumber () );
1344
      NS_LOG_LOGIC ("Case 2, buffering " << tcpHeader.GetSequenceNumber () );
1345
      UnAckData_t::iterator previous =
1345
      UnAckData_t::iterator previous =
1346
          m_bufferedData.lower_bound (tcpHeader.GetSequenceNumber ());
1346
          m_bufferedData.lower_bound (tcpHeader.GetSequenceNumber ());
1347
      SequenceNumber startSeq = tcpHeader.GetSequenceNumber();
1347
      SequenceNumber32 startSeq = tcpHeader.GetSequenceNumber();
1348
      if (previous != m_bufferedData.begin ())
1348
      if (previous != m_bufferedData.begin ())
1349
        {
1349
        {
1350
          --previous;
1350
          --previous;
1351
          startSeq = previous->first + SequenceNumber(previous->second->GetSize());
1351
          startSeq = previous->first + SequenceNumber32(previous->second->GetSize());
1352
          if (startSeq > tcpHeader.GetSequenceNumber ())
1352
          if (startSeq > tcpHeader.GetSequenceNumber ())
1353
            {
1353
            {
1354
              s = tcpHeader.GetSequenceNumber () + SequenceNumber(s) - startSeq;
1354
              s = tcpHeader.GetSequenceNumber () + SequenceNumber32(s) - startSeq;
1355
            }
1355
            }
1356
          else
1356
          else
1357
            {
1357
            {
 Lines 1362-1369    Link Here 
1362
      UnAckData_t::iterator next = m_bufferedData.upper_bound (tcpHeader.GetSequenceNumber());
1362
      UnAckData_t::iterator next = m_bufferedData.upper_bound (tcpHeader.GetSequenceNumber());
1363
      if (next != m_bufferedData.end ())
1363
      if (next != m_bufferedData.end ())
1364
      {
1364
      {
1365
        SequenceNumber nextBufferedSeq = next->first;
1365
        SequenceNumber32 nextBufferedSeq = next->first;
1366
        if (startSeq + SequenceNumber(s) > nextBufferedSeq)
1366
        if (startSeq + SequenceNumber32(s) > nextBufferedSeq)
1367
        {//tail end isn't all new either, trim enough off the end
1367
        {//tail end isn't all new either, trim enough off the end
1368
          s = nextBufferedSeq - startSeq;
1368
          s = nextBufferedSeq - startSeq;
1369
        }
1369
        }
 Lines 1390-1414    Link Here 
1390
      ++next;
1390
      ++next;
1391
      if(next != m_bufferedData.end())
1391
      if(next != m_bufferedData.end())
1392
        {
1392
        {
1393
          NS_ASSERT(next->first >= i->first + SequenceNumber(i->second->GetSize ()));
1393
          NS_ASSERT(next->first >= i->first + SequenceNumber32(i->second->GetSize ()));
1394
        }
1394
        }
1395
    }
1395
    }
1396
  else if (tcpHeader.GetSequenceNumber () + SequenceNumber(s) > m_nextRxSequence)
1396
  else if (tcpHeader.GetSequenceNumber () + SequenceNumber32(s) > m_nextRxSequence)
1397
    {//parial new data case, only part of the packet is new data
1397
    {//parial new data case, only part of the packet is new data
1398
      //trim the beginning
1398
      //trim the beginning
1399
      s = tcpHeader.GetSequenceNumber () + SequenceNumber(s) - m_nextRxSequence; //how much new
1399
      s = tcpHeader.GetSequenceNumber () + SequenceNumber32(s) - m_nextRxSequence; //how much new
1400
      //possibly trim off the end
1400
      //possibly trim off the end
1401
      UnAckData_t::iterator next = m_bufferedData.upper_bound (m_nextRxSequence);
1401
      UnAckData_t::iterator next = m_bufferedData.upper_bound (m_nextRxSequence);
1402
      if (next != m_bufferedData.end ())
1402
      if (next != m_bufferedData.end ())
1403
      {
1403
      {
1404
        SequenceNumber nextBufferedSeq = next->first;
1404
        SequenceNumber32 nextBufferedSeq = next->first;
1405
        if (m_nextRxSequence + SequenceNumber(s) > nextBufferedSeq)
1405
        if (m_nextRxSequence + SequenceNumber32(s) > nextBufferedSeq)
1406
        {//tail end isn't all new either, trim enough off the end
1406
        {//tail end isn't all new either, trim enough off the end
1407
          s = nextBufferedSeq - m_nextRxSequence;
1407
          s = nextBufferedSeq - m_nextRxSequence;
1408
        }
1408
        }
1409
      }
1409
      }
1410
      p = p->CreateFragment (m_nextRxSequence - tcpHeader.GetSequenceNumber (),s);
1410
      p = p->CreateFragment (m_nextRxSequence - tcpHeader.GetSequenceNumber (),s);
1411
      SequenceNumber start = m_nextRxSequence;
1411
      SequenceNumber32 start = m_nextRxSequence;
1412
      m_nextRxSequence += s;           // Advance next expected sequence
1412
      m_nextRxSequence += s;           // Advance next expected sequence
1413
      //buffer the new fragment, it'll be read by call to Recv
1413
      //buffer the new fragment, it'll be read by call to Recv
1414
      UnAckData_t::iterator i = m_bufferedData.find (start);
1414
      UnAckData_t::iterator i = m_bufferedData.find (start);
 Lines 1449-1455    Link Here 
1449
  }
1449
  }
1450
}
1450
}
1451
1451
1452
void TcpSocketImpl::RxBufFinishInsert (SequenceNumber seq)
1452
void TcpSocketImpl::RxBufFinishInsert (SequenceNumber32 seq)
1453
{
1453
{
1454
  //putting data into the buffer might have filled in a sequence gap so we have
1454
  //putting data into the buffer might have filled in a sequence gap so we have
1455
  //to iterate through the list to find the largest contiguous sequenced chunk,
1455
  //to iterate through the list to find the largest contiguous sequenced chunk,
 Lines 1460-1470    Link Here 
1460
  //make sure the buffer is logically sequenced
1460
  //make sure the buffer is logically sequenced
1461
  if(next != m_bufferedData.end())
1461
  if(next != m_bufferedData.end())
1462
  {
1462
  {
1463
    NS_ASSERT(next->first >= i->first + SequenceNumber(i->second->GetSize ()));
1463
    NS_ASSERT(next->first >= i->first + SequenceNumber32(i->second->GetSize ()));
1464
  }
1464
  }
1465
  while(next != m_bufferedData.end())
1465
  while(next != m_bufferedData.end())
1466
  {
1466
  {
1467
    if(i->first + SequenceNumber(i->second->GetSize ()) == next->first)
1467
    if(i->first + SequenceNumber32(i->second->GetSize ()) == next->first)
1468
    {
1468
    {
1469
      //next packet is in sequence, count it
1469
      //next packet is in sequence, count it
1470
      m_rxAvailable += next->second->GetSize();
1470
      m_rxAvailable += next->second->GetSize();
 Lines 1485-1491    Link Here 
1485
  SendEmptyPacket (TcpHeader::ACK);
1485
  SendEmptyPacket (TcpHeader::ACK);
1486
}
1486
}
1487
1487
1488
void TcpSocketImpl::CommonNewAck (SequenceNumber ack, bool skipTimer)
1488
void TcpSocketImpl::CommonNewAck (SequenceNumber32 ack, bool skipTimer)
1489
{ // CommonNewAck is called only for "New" (non-duplicate) acks
1489
{ // CommonNewAck is called only for "New" (non-duplicate) acks
1490
  // and MUST be called by any subclass, from the NewAck function
1490
  // and MUST be called by any subclass, from the NewAck function
1491
  // Always cancel any pending re-tx timer on new acknowledgement
1491
  // Always cancel any pending re-tx timer on new acknowledgement
 Lines 1566-1572    Link Here 
1566
  return CopyObject<TcpSocketImpl> (this);
1566
  return CopyObject<TcpSocketImpl> (this);
1567
}
1567
}
1568
1568
1569
void TcpSocketImpl::NewAck (SequenceNumber seq)
1569
void TcpSocketImpl::NewAck (SequenceNumber32 seq)
1570
{ // New acknowledgement up to sequence number "seq"
1570
{ // New acknowledgement up to sequence number "seq"
1571
  // Adjust congestion window in response to new ack's received
1571
  // Adjust congestion window in response to new ack's received
1572
  NS_LOG_FUNCTION (this << seq);
1572
  NS_LOG_FUNCTION (this << seq);
 Lines 1704-1710    Link Here 
1704
  // Calculate remaining data for COE check
1704
  // Calculate remaining data for COE check
1705
  uint32_t remainingData = m_pendingData->SizeFromSeq (
1705
  uint32_t remainingData = m_pendingData->SizeFromSeq (
1706
      m_firstPendingSequence,
1706
      m_firstPendingSequence,
1707
      m_nextTxSequence + SequenceNumber(p->GetSize ()));
1707
      m_nextTxSequence + SequenceNumber32(p->GetSize ()));
1708
  if (m_closeOnEmpty && remainingData == 0)
1708
  if (m_closeOnEmpty && remainingData == 0)
1709
    { // Add the FIN flag
1709
    { // Add the FIN flag
1710
      flags = flags | TcpHeader::FIN;
1710
      flags = flags | TcpHeader::FIN;
(-)a/src/internet-stack/tcp-socket-impl.h (-11 / +11 lines)
 Lines 30-36    Link Here 
30
#include "ns3/event-id.h"
30
#include "ns3/event-id.h"
31
#include "tcp-typedefs.h"
31
#include "tcp-typedefs.h"
32
#include "pending-data.h"
32
#include "pending-data.h"
33
#include "sequence-number.h"
33
#include "ns3/sequence-number.h"
34
#include "rtt-estimator.h"
34
#include "rtt-estimator.h"
35
35
36
36
 Lines 133-148    Link Here 
133
133
134
  // Manage data tx/rx
134
  // Manage data tx/rx
135
  void NewRx (Ptr<Packet>, const TcpHeader&, const Address& fromAddress, const Address& toAddress);
135
  void NewRx (Ptr<Packet>, const TcpHeader&, const Address& fromAddress, const Address& toAddress);
136
  void RxBufFinishInsert (SequenceNumber);
136
  void RxBufFinishInsert (SequenceNumber32);
137
  Ptr<TcpSocketImpl> Copy ();
137
  Ptr<TcpSocketImpl> Copy ();
138
  virtual void NewAck (SequenceNumber seq); 
138
  virtual void NewAck (SequenceNumber32 seq); 
139
  virtual void DupAck (const TcpHeader& t, uint32_t count); 
139
  virtual void DupAck (const TcpHeader& t, uint32_t count); 
140
  virtual void ReTxTimeout ();
140
  virtual void ReTxTimeout ();
141
  void DelAckTimeout ();
141
  void DelAckTimeout ();
142
  void LastAckTimeout ();
142
  void LastAckTimeout ();
143
  void PersistTimeout ();
143
  void PersistTimeout ();
144
  void Retransmit ();
144
  void Retransmit ();
145
  void CommonNewAck (SequenceNumber seq, bool skipTimer = false);
145
  void CommonNewAck (SequenceNumber32 seq, bool skipTimer = false);
146
  // All timers are cancelled when the endpoint is deleted, to insure
146
  // All timers are cancelled when the endpoint is deleted, to insure
147
  // we don't have additional activity
147
  // we don't have additional activity
148
  void CancelAllTimers();
148
  void CancelAllTimers();
 Lines 194-209    Link Here 
194
194
195
  
195
  
196
  //sequence info, sender side
196
  //sequence info, sender side
197
  SequenceNumber m_nextTxSequence;
197
  SequenceNumber32 m_nextTxSequence;
198
  SequenceNumber m_highTxMark;
198
  SequenceNumber32 m_highTxMark;
199
  SequenceNumber m_highestRxAck;
199
  SequenceNumber32 m_highestRxAck;
200
  SequenceNumber m_lastRxAck;
200
  SequenceNumber32 m_lastRxAck;
201
  
201
  
202
  //sequence info, receiver side
202
  //sequence info, receiver side
203
  SequenceNumber m_nextRxSequence; //next expected sequence
203
  SequenceNumber32 m_nextRxSequence; //next expected sequence
204
204
205
  //sequence number where fin was sent or received
205
  //sequence number where fin was sent or received
206
  SequenceNumber m_finSequence;
206
  SequenceNumber32 m_finSequence;
207
207
208
  //Rx buffer
208
  //Rx buffer
209
  UnAckData_t m_bufferedData; //buffer which sorts out of sequence data
209
  UnAckData_t m_bufferedData; //buffer which sorts out of sequence data
 Lines 216-222    Link Here 
216
216
217
  //this is kind of the tx buffer
217
  //this is kind of the tx buffer
218
  PendingData* m_pendingData;
218
  PendingData* m_pendingData;
219
  SequenceNumber m_firstPendingSequence;
219
  SequenceNumber32 m_firstPendingSequence;
220
220
221
  // Window management
221
  // Window management
222
  uint32_t                       m_segmentSize;          //SegmentSize
222
  uint32_t                       m_segmentSize;          //SegmentSize
(-)a/src/internet-stack/tcp-typedefs.h (-2 / +2 lines)
 Lines 21-27    Link Here 
21
21
22
#include <vector>
22
#include <vector>
23
#include <map>
23
#include <map>
24
#include "sequence-number.h"
24
#include "ns3/sequence-number.h"
25
25
26
#ifndef TCP_TYPEDEFS_H
26
#ifndef TCP_TYPEDEFS_H
27
#define TCP_TYPEDEFS_H
27
#define TCP_TYPEDEFS_H
 Lines 95-101    Link Here 
95
typedef std::vector<Events_t> EventVec_t;      // For flag events lookup
95
typedef std::vector<Events_t> EventVec_t;      // For flag events lookup
96
96
97
//type for managing buffered out of sequence data
97
//type for managing buffered out of sequence data
98
typedef std::map<SequenceNumber, Ptr<Packet> > UnAckData_t;
98
typedef std::map<SequenceNumber32, Ptr<Packet> > UnAckData_t;
99
99
100
class TcpStateMachine {
100
class TcpStateMachine {
101
  public:
101
  public:
(-)a/src/internet-stack/wscript (-2 lines)
 Lines 93-99    Link Here 
93
        'udp-socket-factory-impl.cc',
93
        'udp-socket-factory-impl.cc',
94
        'tcp-socket-factory-impl.cc',
94
        'tcp-socket-factory-impl.cc',
95
        'pending-data.cc',
95
        'pending-data.cc',
96
        'sequence-number.cc',
97
        'rtt-estimator.cc',
96
        'rtt-estimator.cc',
98
        'ipv4-raw-socket-factory-impl.cc',
97
        'ipv4-raw-socket-factory-impl.cc',
99
        'ipv4-raw-socket-impl.cc',
98
        'ipv4-raw-socket-impl.cc',
 Lines 126-132    Link Here 
126
    headers.source = [
125
    headers.source = [
127
        'udp-header.h',
126
        'udp-header.h',
128
        'tcp-header.h',
127
        'tcp-header.h',
129
        'sequence-number.h',
130
        'icmpv4.h',
128
        'icmpv4.h',
131
        'icmpv6-header.h',
129
        'icmpv6-header.h',
132
        # used by routing
130
        # used by routing

Return to bug 385