A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
internet-stack-helper-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Universita' di Firenze
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
18 */
19
20#include "ns3/internet-stack-helper.h"
21#include "ns3/log.h"
22#include "ns3/node.h"
23#include "ns3/test.h"
24
25#include <string>
26
27using namespace ns3;
28
29NS_LOG_COMPONENT_DEFINE("InternetStackHelperTestSuite");
30
31/**
32 * \ingroup internet-test
33 *
34 * \brief InternetStackHelper Test
35 */
37{
38 public:
40
41 private:
42 void DoRun() override;
43 void DoTeardown() override;
44};
45
47 : TestCase("InternetStackHelperTestCase")
48{
49}
50
51void
53{
54 // Checks:
55 // 1. IPv4 only, add IPv4 + IPv6 (result, IPv4 + IPv6)
56 // 2. IPv6 only, add IPv4 + IPv6 (result, IPv4 + IPv6)
57 // 3. IPv4 + IPv6, add IPv4 + IPv6 (result, IPv4 + IPv6)
58
59 Ptr<Node> nodeIpv4Only = CreateObject<Node>();
60 Ptr<Node> nodeIpv6Only = CreateObject<Node>();
61 Ptr<Node> nodeIpv46 = CreateObject<Node>();
62
63 InternetStackHelper internet;
64
65 internet.SetIpv4StackInstall(true);
66 internet.SetIpv6StackInstall(false);
67 internet.Install(nodeIpv4Only);
68
69 internet.SetIpv4StackInstall(false);
70 internet.SetIpv6StackInstall(true);
71 internet.Install(nodeIpv6Only);
72
73 internet.SetIpv4StackInstall(true);
74 internet.SetIpv6StackInstall(true);
75 internet.Install(nodeIpv46);
76
77 // Check that the three nodes have only the intended IP stack.
78 NS_TEST_EXPECT_MSG_NE(nodeIpv4Only->GetObject<Ipv4>(),
79 nullptr,
80 "IPv4 not found on IPv4-only node (should have been there)");
81 NS_TEST_EXPECT_MSG_EQ(nodeIpv4Only->GetObject<Ipv6>(),
82 nullptr,
83 "IPv6 found on IPv4-only node (should not have been there)");
84
85 NS_TEST_EXPECT_MSG_EQ(nodeIpv6Only->GetObject<Ipv4>(),
86 nullptr,
87 "IPv4 found on IPv6-only node (should not have been there)");
88 NS_TEST_EXPECT_MSG_NE(nodeIpv6Only->GetObject<Ipv6>(),
89 nullptr,
90 "IPv6 not found on IPv6-only node (should have been there)");
91
92 NS_TEST_EXPECT_MSG_NE(nodeIpv46->GetObject<Ipv4>(),
93 nullptr,
94 "IPv4 not found on dual stack node (should have been there)");
95 NS_TEST_EXPECT_MSG_NE(nodeIpv46->GetObject<Ipv6>(),
96 nullptr,
97 "IPv6 not found on dual stack node (should have been there)");
98
99 // Now we install IPv4 and IPv6 on the IPv4-only node
100 // IPv4 is already there, no error should happen.
101 internet.Install(nodeIpv4Only);
102 // Now we install IPv4 and IPv6 on the IPv6-only node,
103 // IPv6 is already there, no error should happen.
104 internet.Install(nodeIpv6Only);
105 // Now we install IPv4 and IPv6 on the dual stack node
106 // IPv4 and IPv6 are already there, no error should happen.
107 internet.Install(nodeIpv46);
108
109 // Check that the three nodes have both IPv4 and IPv6.
111 nodeIpv4Only->GetObject<Ipv4>(),
112 nullptr,
113 "IPv4 not found on IPv4-only, now dual stack node (should have been there)");
115 nodeIpv4Only->GetObject<Ipv6>(),
116 nullptr,
117 "IPv6 not found on IPv4-only, now dual stack node (should have been there)");
118
120 nodeIpv6Only->GetObject<Ipv4>(),
121 nullptr,
122 "IPv4 not found on IPv6-only, now dual stack node (should have been there)");
124 nodeIpv6Only->GetObject<Ipv6>(),
125 nullptr,
126 "IPv6 not found on IPv6-only, now dual stack node (should have been there)");
127
128 NS_TEST_EXPECT_MSG_NE(nodeIpv46->GetObject<Ipv4>(),
129 nullptr,
130 "IPv4 not found on dual stack node (should have been there)");
131 NS_TEST_EXPECT_MSG_NE(nodeIpv46->GetObject<Ipv6>(),
132 nullptr,
133 "IPv6 not found on dual stack node (should have been there)");
134}
135
136void
138{
140}
141
142/**
143 * \ingroup internet-test
144 *
145 * \brief InternetStackHelper TestSuite
146 */
148{
149 public:
151 : TestSuite("internet-stack-helper", Type::UNIT)
152 {
153 AddTestCase(new InternetStackHelperTestCase(), TestCase::Duration::QUICK);
154 }
155};
156
158 g_internetStackHelperTestSuite; //!< Static variable for test initialization
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
aggregate IP/TCP/UDP functionality to existing Nodes.
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:80
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:82
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
static constexpr auto UNIT
Definition: test.h:1286
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_TEST_EXPECT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report if not.
Definition: test.h:667
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition: test.h:252
static InternetStackHelperTestSuite g_internetStackHelperTestSuite
Static variable for test initialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.