author | fmoatamr |
Thu, 01 Oct 2009 13:00:04 +0200 | |
changeset 5339 | fee694e277da |
parent 4571 | 2c9c600270e0 |
child 5919 | b89ce2e9eed5 |
permissions | -rw-r--r-- |
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 | 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 | 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 | 38 |
/** |
39 |
* \brief Constructor. |
|
40 |
*/ |
|
41 |
Ipv4L3ProtocolTestCase (); |
|
42 |
/** |
|
43 |
* \brief Destructor. |
|
44 |
*/ |
|
45 |
virtual |
|
46 |
~Ipv4L3ProtocolTestCase (); |
|
47 |
/** |
|
48 |
* \brief Run unit tests for this class. |
|
49 |
* \return false if all tests have passed, false otherwise |
|
50 |
*/ |
|
51 |
virtual bool |
|
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 | 56 |
Ipv4L3ProtocolTestCase::Ipv4L3ProtocolTestCase () : |
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 | 61 |
Ipv4L3ProtocolTestCase::~Ipv4L3ProtocolTestCase () |
62 |
{ |
|
63 |
} |
|
4571
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
64 |
bool |
5339 | 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 | 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 | 77 |
Ipv4InterfaceAddress ifaceAddr1 = Ipv4InterfaceAddress ("192.168.0.1", |
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 | 80 |
Ipv4InterfaceAddress ifaceAddr2 = Ipv4InterfaceAddress ("192.168.0.2", |
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 | 83 |
Ipv4InterfaceAddress ifaceAddr3 = Ipv4InterfaceAddress ("10.30.0.1", |
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 | 86 |
Ipv4InterfaceAddress ifaceAddr4 = Ipv4InterfaceAddress ("250.0.0.1", |
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 | 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 | 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 | 95 |
NS_TEST_ASSERT_MSG_EQ (ifaceAddr4, output, |
96 |
"The addresses should be identical"); |
|
97 |
||
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 | 101 |
static class IPv4L3ProtocolTestSuite : public TestSuite |
102 |
{ |
|
103 |
public: |
|
104 |
IPv4L3ProtocolTestSuite () : |
|
105 |
TestSuite ("ipv4-protocol", UNIT) |
|
106 |
{ |
|
107 |
AddTestCase (new Ipv4L3ProtocolTestCase ()); |
|
108 |
} |
|
109 |
} g_ipv4protocolTestSuite; |
|
4571
2c9c600270e0
cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
110 |
|
5339 | 111 |
} |
112 |
; // namespace ns3 |