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 * 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
16using namespace ns3;
17
18NS_LOG_COMPONENT_DEFINE("InternetStackHelperTestSuite");
19
20/**
21 * @ingroup internet-test
22 *
23 * @brief InternetStackHelper Test
24 */
26{
27 public:
29
30 private:
31 void DoRun() override;
32 void DoTeardown() override;
33};
34
36 : TestCase("InternetStackHelperTestCase")
37{
38}
39
40void
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.
100 nodeIpv4Only->GetObject<Ipv4>(),
101 nullptr,
102 "IPv4 not found on IPv4-only, now dual stack node (should have been there)");
104 nodeIpv4Only->GetObject<Ipv6>(),
105 nullptr,
106 "IPv6 not found on IPv4-only, now dual stack node (should have been there)");
107
109 nodeIpv6Only->GetObject<Ipv4>(),
110 nullptr,
111 "IPv4 not found on IPv6-only, now dual stack node (should have been there)");
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
125void
130
131/**
132 * @ingroup internet-test
133 *
134 * @brief InternetStackHelper TestSuite
135 */
137{
138 public:
140 : TestSuite("internet-stack-helper", Type::UNIT)
141 {
142 AddTestCase(new InternetStackHelperTestCase(), TestCase::Duration::QUICK);
143 }
144};
145
147 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:69
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition ipv6.h:71
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
static constexpr auto UNIT
Definition test.h:1291
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#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
#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
static InternetStackHelperTestSuite g_internetStackHelperTestSuite
Static variable for test initialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.