OLD | NEW |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2014 Natale Patriciello <natale.patriciello@gmail.com> | 3 * Copyright (c) 2014 Natale Patriciello <natale.patriciello@gmail.com> |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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 | 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 | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 17 * |
18 */ | 18 */ |
19 | 19 |
20 #include "ns3/test.h" | 20 #include "ns3/test.h" |
21 #include "ns3/core-module.h" | 21 #include "ns3/core-module.h" |
22 #include "ns3/tcp-option.h" | 22 #include "ns3/tcp-option.h" |
23 #include "ns3/private/tcp-option-winscale.h" | 23 #include "ns3/private/tcp-option-winscale.h" |
24 #include "ns3/private/tcp-option-ts.h" | 24 #include "ns3/private/tcp-option-ts.h" |
| 25 #include "ns3/private/tcp-option-sack.h" |
| 26 #include "ns3/sequence-number.h" |
25 | 27 |
26 #include <string.h> | 28 #include <string.h> |
27 | 29 |
28 namespace ns3 { | 30 namespace ns3 { |
29 | 31 |
30 class TcpOptionWSTestCase : public TestCase | 32 class TcpOptionWSTestCase : public TestCase |
31 { | 33 { |
32 public: | 34 public: |
33 TcpOptionWSTestCase (std::string name, uint8_t scale); | 35 TcpOptionWSTestCase (std::string name, uint8_t scale); |
34 | 36 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 159 |
158 NS_TEST_EXPECT_MSG_EQ (m_timestamp, opt.GetTimestamp (), "Different TS found")
; | 160 NS_TEST_EXPECT_MSG_EQ (m_timestamp, opt.GetTimestamp (), "Different TS found")
; |
159 NS_TEST_EXPECT_MSG_EQ (m_echo, opt.GetEcho (), "Different echo found"); | 161 NS_TEST_EXPECT_MSG_EQ (m_echo, opt.GetEcho (), "Different echo found"); |
160 } | 162 } |
161 | 163 |
162 void | 164 void |
163 TcpOptionTSTestCase::DoTeardown () | 165 TcpOptionTSTestCase::DoTeardown () |
164 { | 166 { |
165 } | 167 } |
166 | 168 |
| 169 class TcpOptionSackTestCase : public TestCase |
| 170 { |
| 171 typedef std::pair<SequenceNumber32, SequenceNumber32> SackBlock; |
| 172 typedef std::list<SackBlock> SackList; |
| 173 typedef SackList::iterator SackIterator; |
| 174 |
| 175 public: |
| 176 TcpOptionSackTestCase (std::string name); |
| 177 |
| 178 void TestSerialize (); |
| 179 void TestDeserialize (); |
| 180 |
| 181 private: |
| 182 virtual void DoRun (void); |
| 183 virtual void DoTearDown (void); |
| 184 Buffer m_buffer; |
| 185 SackList m_sackList; |
| 186 }; |
| 187 |
| 188 TcpOptionSackTestCase::TcpOptionSackTestCase (std::string name) |
| 189 : TestCase (name) |
| 190 { |
| 191 } |
| 192 |
| 193 void |
| 194 TcpOptionSackTestCase::DoRun () |
| 195 { |
| 196 TestSerialize (); |
| 197 TestDeserialize (); |
| 198 } |
| 199 |
| 200 void |
| 201 TcpOptionSackTestCase::TestSerialize () |
| 202 { |
| 203 TcpOptionSack opt; |
| 204 |
| 205 // Create a random SACK list of size 4 |
| 206 Ptr<UniformRandomVariable> x = CreateObject<UniformRandomVariable> (); |
| 207 SackList list; |
| 208 SequenceNumber32 leftEdge; |
| 209 SequenceNumber32 rightEdge; |
| 210 |
| 211 for (uint8_t i = 0; i < 4; ++i) |
| 212 { |
| 213 leftEdge = SequenceNumber32 (x->GetInteger ()); |
| 214 rightEdge = SequenceNumber32 (x->GetInteger ()); |
| 215 SackBlock block (leftEdge, rightEdge); |
| 216 opt.AddSackBlock (block); |
| 217 m_sackList.push_back (block); |
| 218 } |
| 219 |
| 220 SackList savedList = opt.GetSackList (); |
| 221 |
| 222 NS_TEST_EXPECT_MSG_EQ (m_sackList.size (), savedList.size (), "SACK list isn't
saved correctly"); |
| 223 |
| 224 SackIterator i = m_sackList.begin (); |
| 225 SackIterator j = savedList.begin (); |
| 226 while ( i != m_sackList.end ()) |
| 227 { |
| 228 NS_TEST_EXPECT_MSG_EQ ((*i).first, (*j).first, "Left edge isn't saved corr
ectly"); |
| 229 NS_TEST_EXPECT_MSG_EQ ((*i).second, (*j).second, "Right edge isn't saved c
orrectly"); |
| 230 ++i, ++j; |
| 231 } |
| 232 |
| 233 m_buffer.AddAtStart (opt.GetSerializedSize ()); |
| 234 |
| 235 opt.Serialize (m_buffer.Begin ()); |
| 236 } |
| 237 |
| 238 void |
| 239 TcpOptionSackTestCase::TestDeserialize () |
| 240 { |
| 241 TcpOptionSack opt; |
| 242 |
| 243 Buffer::Iterator start = m_buffer.Begin (); |
| 244 uint8_t kind = start.PeekU8 (); |
| 245 |
| 246 NS_TEST_EXPECT_MSG_EQ (kind, TcpOption::SACK, "Different kind found"); |
| 247 |
| 248 opt.Deserialize (start); |
| 249 |
| 250 SackList savedList = opt.GetSackList (); |
| 251 |
| 252 NS_TEST_EXPECT_MSG_EQ (m_sackList.size (), savedList.size (), "Different SACK
list found"); |
| 253 |
| 254 SackIterator i = m_sackList.begin (); |
| 255 SackIterator j = savedList.begin (); |
| 256 |
| 257 while (i != m_sackList.end ()) |
| 258 { |
| 259 NS_TEST_EXPECT_MSG_EQ ((*i).first, (*j).first, "Different left edge found"
); |
| 260 NS_TEST_EXPECT_MSG_EQ ((*i).second, (*j).second, "Different right edge fou
nd"); |
| 261 ++i, ++j; |
| 262 } |
| 263 } |
| 264 |
| 265 void |
| 266 TcpOptionSackTestCase::DoTearDown () |
| 267 { |
| 268 } |
| 269 |
167 static class TcpOptionTestSuite : public TestSuite | 270 static class TcpOptionTestSuite : public TestSuite |
168 { | 271 { |
169 public: | 272 public: |
170 TcpOptionTestSuite () | 273 TcpOptionTestSuite () |
171 : TestSuite ("tcp-option", UNIT) | 274 : TestSuite ("tcp-option", UNIT) |
172 { | 275 { |
173 for (uint8_t i = 0; i < 15; ++i) | 276 for (uint8_t i = 0; i < 15; ++i) |
174 { | 277 { |
175 AddTestCase (new TcpOptionWSTestCase ("Testing window " | 278 AddTestCase (new TcpOptionWSTestCase ("Testing window " |
176 "scale value", i), TestCase::QUICK
); | 279 "scale value", i), TestCase::QUICK
); |
177 } | 280 } |
178 AddTestCase (new TcpOptionTSTestCase ("Testing serialization of random value
s for timestamp"), TestCase::QUICK); | 281 AddTestCase (new TcpOptionTSTestCase ("Testing serialization of random value
s for timestamp"), TestCase::QUICK); |
| 282 AddTestCase (new TcpOptionSackTestCase ("Testing serialization and deseriali
zation of SACK option"), TestCase::QUICK); |
179 } | 283 } |
180 | 284 |
181 } g_TcpOptionTestSuite; | 285 } g_TcpOptionTestSuite; |
182 | 286 |
183 } // namespace ns3 | 287 } // namespace ns3 |
OLD | NEW |