A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
7
*/
8
9
#include "ns3/internet-stack-helper.h"
10
#include "ns3/log.h"
11
#include "ns3/node.h"
12
#include "ns3/test.h"
13
14
#include <string>
15
16
using namespace
ns3
;
17
18
NS_LOG_COMPONENT_DEFINE
(
"InternetStackHelperTestSuite"
);
19
20
/**
21
* @ingroup internet-test
22
*
23
* @brief InternetStackHelper Test
24
*/
25
class
InternetStackHelperTestCase
:
public
TestCase
26
{
27
public
:
28
InternetStackHelperTestCase
();
29
30
private
:
31
void
DoRun
()
override
;
32
void
DoTeardown
()
override
;
33
};
34
35
InternetStackHelperTestCase::InternetStackHelperTestCase
()
36
:
TestCase
(
"InternetStackHelperTestCase"
)
37
{
38
}
39
40
void
41
InternetStackHelperTestCase::DoRun
()
42
{
43
// Checks:
44
// 1. IPv4 only, add IPv4 + IPv6 (result, IPv4 + IPv6)
45
// 2. IPv6 only, add IPv4 + IPv6 (result, IPv4 + IPv6)
46
// 3. IPv4 + IPv6, add IPv4 + IPv6 (result, IPv4 + IPv6)
47
48
Ptr<Node>
nodeIpv4Only =
CreateObject<Node>
();
49
Ptr<Node>
nodeIpv6Only =
CreateObject<Node>
();
50
Ptr<Node>
nodeIpv46 =
CreateObject<Node>
();
51
52
InternetStackHelper
internet;
53
54
internet.SetIpv4StackInstall(
true
);
55
internet.SetIpv6StackInstall(
false
);
56
internet.Install(nodeIpv4Only);
57
58
internet.SetIpv4StackInstall(
false
);
59
internet.SetIpv6StackInstall(
true
);
60
internet.Install(nodeIpv6Only);
61
62
internet.SetIpv4StackInstall(
true
);
63
internet.SetIpv6StackInstall(
true
);
64
internet.Install(nodeIpv46);
65
66
// Check that the three nodes have only the intended IP stack.
67
NS_TEST_EXPECT_MSG_NE
(nodeIpv4Only->GetObject<
Ipv4
>(),
68
nullptr
,
69
"IPv4 not found on IPv4-only node (should have been there)"
);
70
NS_TEST_EXPECT_MSG_EQ
(nodeIpv4Only->GetObject<
Ipv6
>(),
71
nullptr
,
72
"IPv6 found on IPv4-only node (should not have been there)"
);
73
74
NS_TEST_EXPECT_MSG_EQ
(nodeIpv6Only->GetObject<
Ipv4
>(),
75
nullptr
,
76
"IPv4 found on IPv6-only node (should not have been there)"
);
77
NS_TEST_EXPECT_MSG_NE
(nodeIpv6Only->GetObject<
Ipv6
>(),
78
nullptr
,
79
"IPv6 not found on IPv6-only node (should have been there)"
);
80
81
NS_TEST_EXPECT_MSG_NE
(nodeIpv46->GetObject<
Ipv4
>(),
82
nullptr
,
83
"IPv4 not found on dual stack node (should have been there)"
);
84
NS_TEST_EXPECT_MSG_NE
(nodeIpv46->GetObject<
Ipv6
>(),
85
nullptr
,
86
"IPv6 not found on dual stack node (should have been there)"
);
87
88
// Now we install IPv4 and IPv6 on the IPv4-only node
89
// IPv4 is already there, no error should happen.
90
internet.Install(nodeIpv4Only);
91
// Now we install IPv4 and IPv6 on the IPv6-only node,
92
// IPv6 is already there, no error should happen.
93
internet.Install(nodeIpv6Only);
94
// Now we install IPv4 and IPv6 on the dual stack node
95
// IPv4 and IPv6 are already there, no error should happen.
96
internet.Install(nodeIpv46);
97
98
// Check that the three nodes have both IPv4 and IPv6.
99
NS_TEST_EXPECT_MSG_NE
(
100
nodeIpv4Only->GetObject<
Ipv4
>(),
101
nullptr
,
102
"IPv4 not found on IPv4-only, now dual stack node (should have been there)"
);
103
NS_TEST_EXPECT_MSG_NE
(
104
nodeIpv4Only->GetObject<
Ipv6
>(),
105
nullptr
,
106
"IPv6 not found on IPv4-only, now dual stack node (should have been there)"
);
107
108
NS_TEST_EXPECT_MSG_NE
(
109
nodeIpv6Only->GetObject<
Ipv4
>(),
110
nullptr
,
111
"IPv4 not found on IPv6-only, now dual stack node (should have been there)"
);
112
NS_TEST_EXPECT_MSG_NE
(
113
nodeIpv6Only->GetObject<
Ipv6
>(),
114
nullptr
,
115
"IPv6 not found on IPv6-only, now dual stack node (should have been there)"
);
116
117
NS_TEST_EXPECT_MSG_NE
(nodeIpv46->GetObject<
Ipv4
>(),
118
nullptr
,
119
"IPv4 not found on dual stack node (should have been there)"
);
120
NS_TEST_EXPECT_MSG_NE
(nodeIpv46->GetObject<
Ipv6
>(),
121
nullptr
,
122
"IPv6 not found on dual stack node (should have been there)"
);
123
}
124
125
void
126
InternetStackHelperTestCase::DoTeardown
()
127
{
128
Simulator::Destroy
();
129
}
130
131
/**
132
* @ingroup internet-test
133
*
134
* @brief InternetStackHelper TestSuite
135
*/
136
class
InternetStackHelperTestSuite
:
public
TestSuite
137
{
138
public
:
139
InternetStackHelperTestSuite
()
140
:
TestSuite
(
"internet-stack-helper"
,
Type
::
UNIT
)
141
{
142
AddTestCase
(
new
InternetStackHelperTestCase
(), TestCase::Duration::QUICK);
143
}
144
};
145
146
static
InternetStackHelperTestSuite
147
g_internetStackHelperTestSuite
;
//!< Static variable for test initialization
InternetStackHelperTestCase
InternetStackHelper Test.
Definition
internet-stack-helper-test-suite.cc:26
InternetStackHelperTestCase::DoTeardown
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
Definition
internet-stack-helper-test-suite.cc:126
InternetStackHelperTestCase::InternetStackHelperTestCase
InternetStackHelperTestCase()
Definition
internet-stack-helper-test-suite.cc:35
InternetStackHelperTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
internet-stack-helper-test-suite.cc:41
InternetStackHelperTestSuite
InternetStackHelper TestSuite.
Definition
internet-stack-helper-test-suite.cc:137
InternetStackHelperTestSuite::InternetStackHelperTestSuite
InternetStackHelperTestSuite()
Definition
internet-stack-helper-test-suite.cc:139
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition
internet-stack-helper.h:81
ns3::Ipv4
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition
ipv4.h:69
ns3::Ipv6
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition
ipv6.h:71
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition
simulator.cc:131
ns3::TestCase
encapsulates test code
Definition
test.h:1050
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1274
ns3::TestSuite::UNIT
static constexpr auto UNIT
Definition
test.h:1291
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
ns3::CreateObject
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition
object.h:619
NS_TEST_EXPECT_MSG_NE
#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:656
NS_TEST_EXPECT_MSG_EQ
#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:241
g_internetStackHelperTestSuite
static InternetStackHelperTestSuite g_internetStackHelperTestSuite
Static variable for test initialization.
Definition
internet-stack-helper-test-suite.cc:147
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
internet
test
internet-stack-helper-test-suite.cc
Generated on Fri Dec 13 2024 09:20:41 for ns-3 by
1.11.0