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) 2011 Yufei Cheng | 3 * Copyright (c) 2011 Yufei Cheng |
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 * Author: Yufei Cheng <yfcheng@ittc.ku.edu> | 18 * Author: Yufei Cheng <yfcheng@ittc.ku.edu> |
19 * | 19 * |
20 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director | 20 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director |
21 * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets | 21 * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets |
22 * Information and Telecommunication Technology Center (ITTC) | 22 * Information and Telecommunication Technology Center (ITTC) |
23 * and Department of Electrical Engineering and Computer Science | 23 * and Department of Electrical Engineering and Computer Science |
24 * The University of Kansas Lawrence, KS USA. | 24 * The University of Kansas Lawrence, KS USA. |
25 * | 25 * |
26 * Work supported in part by NSF FIND (Future Internet Design) Program | 26 * Work supported in part by NSF FIND (Future Internet Design) Program |
27 * under grant CNS-0626918 (Postmodern Internet Architecture), | 27 * under grant CNS-0626918 (Postmodern Internet Architecture), |
28 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimenta
tion on GENI), | 28 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimenta
tion on GENI), |
29 * US Department of Defense (DoD), and ITTC at The University of Kansas. | 29 * US Department of Defense (DoD), and ITTC at The University of Kansas. |
| 30 * |
| 31 * Author of LEAR modification: Tomasz Seweryn <tomasz.seweryn7@gmail.com> |
30 */ | 32 */ |
31 | 33 |
32 #include <vector> | 34 #include <vector> |
33 #include "ns3/ptr.h" | 35 #include "ns3/ptr.h" |
34 #include "ns3/boolean.h" | 36 #include "ns3/boolean.h" |
35 #include "ns3/test.h" | 37 #include "ns3/test.h" |
36 #include "ns3/ipv4-route.h" | 38 #include "ns3/ipv4-route.h" |
37 #include "ns3/mesh-helper.h" | 39 #include "ns3/mesh-helper.h" |
38 #include "ns3/simulator.h" | 40 #include "ns3/simulator.h" |
39 #include "ns3/double.h" | 41 #include "ns3/double.h" |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 header.AddDsrOption (h); | 326 header.AddDsrOption (h); |
325 p->AddHeader (header); | 327 p->AddHeader (header); |
326 p->RemoveAtStart (8); | 328 p->RemoveAtStart (8); |
327 p->AddHeader (header); | 329 p->AddHeader (header); |
328 dsr::DsrOptionAckHeader h2; | 330 dsr::DsrOptionAckHeader h2; |
329 p->RemoveAtStart (8); | 331 p->RemoveAtStart (8); |
330 uint32_t bytes = p->RemoveHeader (h2); | 332 uint32_t bytes = p->RemoveHeader (h2); |
331 NS_TEST_EXPECT_MSG_EQ (bytes, 12, "Total RREP is 12 bytes long"); | 333 NS_TEST_EXPECT_MSG_EQ (bytes, 12, "Total RREP is 12 bytes long"); |
332 } | 334 } |
333 // ----------------------------------------------------------------------------- | 335 // ----------------------------------------------------------------------------- |
| 336 // / Unit test for DROP_RREQ |
| 337 class DsrDropRreqHeaderTest : public TestCase |
| 338 { |
| 339 public: |
| 340 DsrDropRreqHeaderTest (); |
| 341 ~DsrDropRreqHeaderTest (); |
| 342 virtual void |
| 343 DoRun (void); |
| 344 }; |
| 345 DsrDropRreqHeaderTest::DsrDropRreqHeaderTest () |
| 346 : TestCase ("DSR DROP_RREQ") |
| 347 { |
| 348 } |
| 349 DsrDropRreqHeaderTest::~DsrDropRreqHeaderTest () |
| 350 { |
| 351 } |
| 352 void |
| 353 DsrDropRreqHeaderTest::DoRun () |
| 354 { |
| 355 dsr::DsrOptionDropRReqHeader h; |
| 356 std::vector<Ipv4Address> nodeList; |
| 357 nodeList.push_back (Ipv4Address ("1.1.1.0")); |
| 358 nodeList.push_back (Ipv4Address ("1.1.1.1")); |
| 359 nodeList.push_back (Ipv4Address ("1.1.1.2")); |
| 360 |
| 361 h.SetTarget (Ipv4Address ("1.1.1.3")); |
| 362 NS_TEST_EXPECT_MSG_EQ (h.GetTarget (), Ipv4Address ("1.1.1.3"), "trivial"); |
| 363 h.SetNodesAddresses (nodeList); |
| 364 NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (0), Ipv4Address ("1.1.1.0"), "trivial
"); |
| 365 NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (1), Ipv4Address ("1.1.1.1"), "trivial
"); |
| 366 NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (2), Ipv4Address ("1.1.1.2"), "trivial
"); |
| 367 h.SetId (1); |
| 368 NS_TEST_EXPECT_MSG_EQ (h.GetId (), 1, "trivial"); |
| 369 |
| 370 Ptr<Packet> p = Create<Packet> (); |
| 371 dsr::DsrRoutingHeader header; |
| 372 header.AddDsrOption (h); |
| 373 p->AddHeader (header); |
| 374 p->RemoveAtStart (8); |
| 375 dsr::DsrOptionDropRReqHeader h2; |
| 376 h2.SetNumberOfAddresses (3); |
| 377 uint32_t bytes = p->RemoveHeader (h2); |
| 378 NS_TEST_EXPECT_MSG_EQ (bytes, 20, "Total RREP is 20 bytes long"); |
| 379 } |
| 380 // ----------------------------------------------------------------------------- |
| 381 // / Unit test for ROUTE_CACHE |
| 382 class DsrRouteCacheHeaderTest : public TestCase |
| 383 { |
| 384 public: |
| 385 DsrRouteCacheHeaderTest (); |
| 386 ~DsrRouteCacheHeaderTest (); |
| 387 virtual void |
| 388 DoRun (void); |
| 389 }; |
| 390 DsrRouteCacheHeaderTest::DsrRouteCacheHeaderTest () |
| 391 : TestCase ("DSR ROUTE_CACHE") |
| 392 { |
| 393 } |
| 394 DsrRouteCacheHeaderTest::~DsrRouteCacheHeaderTest () |
| 395 { |
| 396 } |
| 397 void |
| 398 DsrRouteCacheHeaderTest::DoRun () |
| 399 { |
| 400 dsr::DsrOptionRCacheHeader h; |
| 401 std::vector<Ipv4Address> nodeList; |
| 402 nodeList.push_back (Ipv4Address ("1.1.1.0")); |
| 403 nodeList.push_back (Ipv4Address ("1.1.1.1")); |
| 404 nodeList.push_back (Ipv4Address ("1.1.1.2")); |
| 405 |
| 406 h.SetMiddle (Ipv4Address ("1.1.1.3")); |
| 407 NS_TEST_EXPECT_MSG_EQ (h.GetMiddle (), Ipv4Address ("1.1.1.3"), "trivial"); |
| 408 h.SetNodesAddresses (nodeList); |
| 409 NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (0), Ipv4Address ("1.1.1.0"), "trivial
"); |
| 410 NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (1), Ipv4Address ("1.1.1.1"), "trivial
"); |
| 411 NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (2), Ipv4Address ("1.1.1.2"), "trivial
"); |
| 412 h.SetId (1); |
| 413 NS_TEST_EXPECT_MSG_EQ (h.GetId (), 1, "trivial"); |
| 414 |
| 415 Ptr<Packet> p = Create<Packet> (); |
| 416 dsr::DsrRoutingHeader header; |
| 417 header.AddDsrOption (h); |
| 418 p->AddHeader (header); |
| 419 p->RemoveAtStart (8); |
| 420 dsr::DsrOptionRCacheHeader h2; |
| 421 h2.SetNumberOfAddresses (3); |
| 422 uint32_t bytes = p->RemoveHeader (h2); |
| 423 NS_TEST_EXPECT_MSG_EQ (bytes, 20, "Total RREP is 20 bytes long"); |
| 424 } |
| 425 // ----------------------------------------------------------------------------- |
| 426 // / Unit test for DROP_ROUTE_CACHE |
| 427 class DsrDropRouteCacheHeaderTest : public TestCase |
| 428 { |
| 429 public: |
| 430 DsrDropRouteCacheHeaderTest (); |
| 431 ~DsrDropRouteCacheHeaderTest (); |
| 432 virtual void |
| 433 DoRun (void); |
| 434 }; |
| 435 DsrDropRouteCacheHeaderTest::DsrDropRouteCacheHeaderTest () |
| 436 : TestCase ("DSR DROP_ROUTE_CACHE") |
| 437 { |
| 438 } |
| 439 DsrDropRouteCacheHeaderTest::~DsrDropRouteCacheHeaderTest () |
| 440 { |
| 441 } |
| 442 void |
| 443 DsrDropRouteCacheHeaderTest::DoRun () |
| 444 { |
| 445 dsr::DsrOptionDropRCacheHeader h; |
| 446 std::vector<Ipv4Address> nodeList; |
| 447 nodeList.push_back (Ipv4Address ("1.1.1.0")); |
| 448 nodeList.push_back (Ipv4Address ("1.1.1.1")); |
| 449 nodeList.push_back (Ipv4Address ("1.1.1.2")); |
| 450 |
| 451 h.SetNodesAddresses (nodeList); |
| 452 NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (0), Ipv4Address ("1.1.1.0"), "trivial
"); |
| 453 NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (1), Ipv4Address ("1.1.1.1"), "trivial
"); |
| 454 NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (2), Ipv4Address ("1.1.1.2"), "trivial
"); |
| 455 h.SetId (1); |
| 456 NS_TEST_EXPECT_MSG_EQ (h.GetId (), 1, "trivial"); |
| 457 |
| 458 Ptr<Packet> p = Create<Packet> (); |
| 459 dsr::DsrRoutingHeader header; |
| 460 header.AddDsrOption (h); |
| 461 p->AddHeader (header); |
| 462 p->RemoveAtStart (8); |
| 463 dsr::DsrOptionDropRCacheHeader h2; |
| 464 h2.SetNumberOfAddresses (3); |
| 465 uint32_t bytes = p->RemoveHeader (h2); |
| 466 NS_TEST_EXPECT_MSG_EQ (bytes, 16, "Total RREP is 16 bytes long"); |
| 467 } |
| 468 // ----------------------------------------------------------------------------- |
| 469 // / Unit test for CANCEL_ROUTE_CACHE |
| 470 class DsrCancelRouteCacheHeaderTest : public TestCase |
| 471 { |
| 472 public: |
| 473 DsrCancelRouteCacheHeaderTest (); |
| 474 ~DsrCancelRouteCacheHeaderTest (); |
| 475 virtual void |
| 476 DoRun (void); |
| 477 }; |
| 478 DsrCancelRouteCacheHeaderTest::DsrCancelRouteCacheHeaderTest () |
| 479 : TestCase ("DSR DROP_ROUTE_CACHE") |
| 480 { |
| 481 } |
| 482 DsrCancelRouteCacheHeaderTest::~DsrCancelRouteCacheHeaderTest () |
| 483 { |
| 484 } |
| 485 void |
| 486 DsrCancelRouteCacheHeaderTest::DoRun () |
| 487 { |
| 488 dsr::DsrOptionCancelRCacheHeader h; |
| 489 std::vector<Ipv4Address> nodeList; |
| 490 nodeList.push_back (Ipv4Address ("1.1.1.0")); |
| 491 nodeList.push_back (Ipv4Address ("1.1.1.1")); |
| 492 nodeList.push_back (Ipv4Address ("1.1.1.2")); |
| 493 |
| 494 h.SetNodesAddresses (nodeList); |
| 495 NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (0), Ipv4Address ("1.1.1.0"), "trivial
"); |
| 496 NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (1), Ipv4Address ("1.1.1.1"), "trivial
"); |
| 497 NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (2), Ipv4Address ("1.1.1.2"), "trivial
"); |
| 498 |
| 499 Ptr<Packet> p = Create<Packet> (); |
| 500 dsr::DsrRoutingHeader header; |
| 501 header.AddDsrOption (h); |
| 502 p->AddHeader (header); |
| 503 p->RemoveAtStart (8); |
| 504 dsr::DsrOptionCancelRCacheHeader h2; |
| 505 h2.SetNumberOfAddresses (3); |
| 506 uint32_t bytes = p->RemoveHeader (h2); |
| 507 NS_TEST_EXPECT_MSG_EQ (bytes, 20, "Total RREP is 20 bytes long"); |
| 508 } |
| 509 // ----------------------------------------------------------------------------- |
334 // / Unit test for DSR route cache entry | 510 // / Unit test for DSR route cache entry |
335 class DsrCacheEntryTest : public TestCase | 511 class DsrCacheEntryTest : public TestCase |
336 { | 512 { |
337 public: | 513 public: |
338 DsrCacheEntryTest (); | 514 DsrCacheEntryTest (); |
339 ~DsrCacheEntryTest (); | 515 ~DsrCacheEntryTest (); |
340 virtual void | 516 virtual void |
341 DoRun (void); | 517 DoRun (void); |
342 }; | 518 }; |
343 DsrCacheEntryTest::DsrCacheEntryTest () | 519 DsrCacheEntryTest::DsrCacheEntryTest () |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 public: | 684 public: |
509 DsrTestSuite () : TestSuite ("routing-dsr", UNIT) | 685 DsrTestSuite () : TestSuite ("routing-dsr", UNIT) |
510 { | 686 { |
511 AddTestCase (new DsrFsHeaderTest, TestCase::QUICK); | 687 AddTestCase (new DsrFsHeaderTest, TestCase::QUICK); |
512 AddTestCase (new DsrRreqHeaderTest, TestCase::QUICK); | 688 AddTestCase (new DsrRreqHeaderTest, TestCase::QUICK); |
513 AddTestCase (new DsrRrepHeaderTest, TestCase::QUICK); | 689 AddTestCase (new DsrRrepHeaderTest, TestCase::QUICK); |
514 AddTestCase (new DsrSRHeaderTest, TestCase::QUICK); | 690 AddTestCase (new DsrSRHeaderTest, TestCase::QUICK); |
515 AddTestCase (new DsrRerrHeaderTest, TestCase::QUICK); | 691 AddTestCase (new DsrRerrHeaderTest, TestCase::QUICK); |
516 AddTestCase (new DsrAckReqHeaderTest, TestCase::QUICK); | 692 AddTestCase (new DsrAckReqHeaderTest, TestCase::QUICK); |
517 AddTestCase (new DsrAckHeaderTest, TestCase::QUICK); | 693 AddTestCase (new DsrAckHeaderTest, TestCase::QUICK); |
| 694 AddTestCase (new DsrDropRreqHeaderTest, TestCase::QUICK); |
| 695 AddTestCase (new DsrRouteCacheHeaderTest, TestCase::QUICK); |
| 696 AddTestCase (new DsrDropRouteCacheHeaderTest, TestCase::QUICK); |
| 697 AddTestCase (new DsrCancelRouteCacheHeaderTest, TestCase::QUICK); |
518 AddTestCase (new DsrCacheEntryTest, TestCase::QUICK); | 698 AddTestCase (new DsrCacheEntryTest, TestCase::QUICK); |
519 AddTestCase (new DsrSendBuffTest, TestCase::QUICK); | 699 AddTestCase (new DsrSendBuffTest, TestCase::QUICK); |
520 } | 700 } |
521 } g_dsrTestSuite; | 701 } g_dsrTestSuite; |
OLD | NEW |