src/internet-stack/ipv4-test.cc
author fmoatamr
Thu, 01 Oct 2009 13:00:04 +0200
changeset 5339 fee694e277da
parent 4571 2c9c600270e0
child 5919 b89ce2e9eed5
permissions -rw-r--r--
Conform ipv4-test with the new test suite
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
/*
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
 * This program is free software; you can redistribute it and/or modify
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
 * it under the terms of the GNU General Public License version 2 as
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
 * published by the Free Software Foundation;
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
 *
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
 * This program is distributed in the hope that it will be useful,
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
 * GNU General Public License for more details.
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
 *
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
 * You should have received a copy of the GNU General Public License
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
 * along with this program; if not, write to the Free Software
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5339
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    15
 * Author: Faker Moatamri <faker.moatamri@sophia.inria.fr>
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
 *
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
 */
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
/**
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
 * This is the test code for ipv4-l3-protocol.cc  
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
 */
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    22
#include "ns3/simulator.h"
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
#include "ns3/test.h"
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    24
#include "ns3/log.h"
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    25
#include "ns3/inet-socket-address.h"
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
#include "ns3/node.h"
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    28
#include "ipv4-l3-protocol.h"
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    29
#include "arp-l3-protocol.h"
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    30
#include "ipv4-interface.h"
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    31
#include "loopback-net-device.h"
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    32
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
namespace ns3 {
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    34
5339
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    35
class Ipv4L3ProtocolTestCase : public TestCase
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    36
{
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    37
public:
5339
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    38
  /**
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    39
   * \brief Constructor.
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    40
   */
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    41
  Ipv4L3ProtocolTestCase ();
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    42
  /**
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    43
   * \brief Destructor.
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    44
   */
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    45
  virtual
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    46
  ~Ipv4L3ProtocolTestCase ();
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    47
  /**
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    48
   * \brief Run unit tests for this class.
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    49
   * \return false if all tests have passed, false otherwise
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    50
   */
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    51
  virtual bool
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    52
  DoRun (void);
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    53
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    54
};
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    55
5339
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    56
Ipv4L3ProtocolTestCase::Ipv4L3ProtocolTestCase () :
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    57
  TestCase ("Verify the IPv4 layer 3 protocol")
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    58
{
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    59
}
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    60
5339
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    61
Ipv4L3ProtocolTestCase::~Ipv4L3ProtocolTestCase ()
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    62
{
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    63
}
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    64
bool
5339
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    65
Ipv4L3ProtocolTestCase::DoRun (void)
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    66
{
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    67
  Ptr<Node> node = CreateObject<Node> ();
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    68
  Ptr<Ipv4L3Protocol> ipv4 = CreateObject<Ipv4L3Protocol> ();
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    69
  Ptr<Ipv4Interface> interface = CreateObject<Ipv4Interface> ();
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    70
  Ptr<LoopbackNetDevice> device = CreateObject<LoopbackNetDevice> ();
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    71
  node->AddDevice (device);
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    72
  interface->SetDevice (device);
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    73
  interface->SetNode (node);
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
  uint32_t index = ipv4->AddIpv4Interface (interface);
5339
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    75
  NS_TEST_ASSERT_MSG_EQ (index, 0, "No interface should be found??");
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    76
  interface->SetUp ();
5339
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    77
  Ipv4InterfaceAddress ifaceAddr1 = Ipv4InterfaceAddress ("192.168.0.1",
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    78
      "255.255.255.0");
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    79
  interface->AddAddress (ifaceAddr1);
5339
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    80
  Ipv4InterfaceAddress ifaceAddr2 = Ipv4InterfaceAddress ("192.168.0.2",
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    81
      "255.255.255.0");
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    82
  interface->AddAddress (ifaceAddr2);
5339
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    83
  Ipv4InterfaceAddress ifaceAddr3 = Ipv4InterfaceAddress ("10.30.0.1",
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    84
      "255.255.255.0");
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    85
  interface->AddAddress (ifaceAddr3);
5339
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    86
  Ipv4InterfaceAddress ifaceAddr4 = Ipv4InterfaceAddress ("250.0.0.1",
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    87
      "255.255.255.0");
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    88
  interface->AddAddress (ifaceAddr4);
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    89
  uint32_t num = interface->GetNAddresses ();
5339
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    90
  NS_TEST_ASSERT_MSG_EQ (num, 4, "Should find 4 interfaces??");
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    91
  interface->RemoveAddress (2);
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    92
  num = interface->GetNAddresses ();
5339
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    93
  NS_TEST_ASSERT_MSG_EQ (num, 3, "Should find 3 interfaces??");
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    94
  Ipv4InterfaceAddress output = interface->GetAddress (2);
5339
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    95
  NS_TEST_ASSERT_MSG_EQ (ifaceAddr4, output,
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    96
      "The addresses should be identical");
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    97
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
    98
  return false;
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    99
}
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   100
5339
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
   101
static class IPv4L3ProtocolTestSuite : public TestSuite
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
   102
{
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
   103
public:
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
   104
  IPv4L3ProtocolTestSuite () :
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
   105
    TestSuite ("ipv4-protocol", UNIT)
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
   106
  {
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
   107
    AddTestCase (new Ipv4L3ProtocolTestCase ());
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
   108
  }
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
   109
} g_ipv4protocolTestSuite;
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   110
5339
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
   111
}
fee694e277da Conform ipv4-test with the new test suite
fmoatamr
parents: 4571
diff changeset
   112
; // namespace ns3