A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
neighbor-cache-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 ZHIHENG DONG
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Zhiheng Dong <dzh2077@gmail.com>
7 */
8
9#include "ns3/arp-cache.h"
10#include "ns3/icmpv4-l4-protocol.h"
11#include "ns3/icmpv6-l4-protocol.h"
12#include "ns3/internet-stack-helper.h"
13#include "ns3/ipv4-address-helper.h"
14#include "ns3/ipv4-l3-protocol.h"
15#include "ns3/ipv4-routing-helper.h"
16#include "ns3/ipv6-address-helper.h"
17#include "ns3/ipv6-l3-protocol.h"
18#include "ns3/ipv6-routing-helper.h"
19#include "ns3/ndisc-cache.h"
20#include "ns3/neighbor-cache-helper.h"
21#include "ns3/simple-channel.h"
22#include "ns3/simple-net-device-helper.h"
23#include "ns3/simple-net-device.h"
24#include "ns3/simulator.h"
25#include "ns3/socket-factory.h"
26#include "ns3/socket.h"
27#include "ns3/test.h"
28#include "ns3/udp-l4-protocol.h"
29#include "ns3/udp-socket-factory.h"
30
31using namespace ns3;
32
33/**
34 * @ingroup internet-test
35 *
36 * @brief Dynamic Neighbor Cache Test
37 */
39{
40 Ptr<Packet> m_receivedPacket; //!< Received packet
41
42 /**
43 * @brief Send data immediately after being called.
44 * @param socket The sending socket.
45 * @param to IPv4 Destination address.
46 */
47 void DoSendDatav4(Ptr<Socket> socket, Ipv4Address to);
48
49 /**
50 * @brief Send data immediately after being called.
51 * @param socket The sending socket.
52 * @param to IPv6 Destination address.
53 */
54 void DoSendDatav6(Ptr<Socket> socket, Ipv6Address to);
55
56 /**
57 * @brief Schedules the DoSendData () function to send the data.
58 * @param socket The sending socket.
59 * @param to IPv4 Destination address.
60 */
61 void SendData(Ptr<Socket> socket, Ipv4Address to);
62
63 /**
64 * @brief Schedules the DoSendData () function to send the data.
65 * @param socket The sending socket.
66 * @param to IPv6 Destination address.
67 */
68 void SendData(Ptr<Socket> socket, Ipv6Address to);
69
70 /**
71 * @brief Add an IPv4 address to an IPv4 interface
72 * @param ipv4Interface The interface that address will be added.
73 * @param ifaceAddr The added IPv4 address.
74 */
75 void AddIpv4Address(Ptr<Ipv4Interface> ipv4Interface, Ipv4InterfaceAddress ifaceAddr);
76
77 /**
78 * @brief Add an IPv6 address to an IPv6 interface
79 * @param ipv6Interface The interface that address will be added.
80 * @param ifaceAddr The added IPv6 address.
81 */
82 void AddIpv6Address(Ptr<Ipv6Interface> ipv6Interface, Ipv6InterfaceAddress ifaceAddr);
83
84 /**
85 * @brief Remove an IPv4 address from an IPv4 interface
86 * @param ipv4Interface The interface that address will be removed from.
87 * @param index The index of IPv4 address that will be removed.
88 */
89 void RemoveIpv4Address(Ptr<Ipv4Interface> ipv4Interface, uint32_t index);
90
91 /**
92 * @brief Remove an IPv6 address from an IPv6 interface
93 * @param ipv6Interface The interface that address will be removed from.
94 * @param index The index of IPv6 address that will be removed.
95 */
96 void RemoveIpv6Address(Ptr<Ipv6Interface> ipv6Interface, uint32_t index);
97
98 public:
99 void DoRun() override;
100
102
103 /**
104 * @brief Receive data.
105 * @param socket The receiving socket.
106 */
107 void ReceivePkt(Ptr<Socket> socket);
108
109 std::vector<uint32_t> m_receivedPacketSizes; //!< Received packet sizes
110};
111
113 : TestCase(
114 "The DynamicNeighborCacheTestPopulate checks if neighbor caches are correctly populated "
115 "in global scope and updated when there is an IP address added or removed.")
116{
117}
118
119void
121{
122 uint32_t availableData [[maybe_unused]] = socket->GetRxAvailable();
123 m_receivedPacket = socket->Recv(std::numeric_limits<uint32_t>::max(), 0);
124 NS_TEST_ASSERT_MSG_EQ(availableData,
125 m_receivedPacket->GetSize(),
126 "Received Packet size is not equal to the Rx buffer size");
127 m_receivedPacketSizes.push_back(m_receivedPacket->GetSize());
128}
129
130void
132{
133 Address realTo = InetSocketAddress(to, 1234);
134 NS_TEST_EXPECT_MSG_EQ(socket->SendTo(Create<Packet>(123), 0, realTo), 123, "100");
135}
136
137void
139{
140 Address realTo = Inet6SocketAddress(to, 1234);
141 NS_TEST_EXPECT_MSG_EQ(socket->SendTo(Create<Packet>(123), 0, realTo), 123, "100");
142}
143
144void
146{
148 Simulator::ScheduleWithContext(socket->GetNode()->GetId(),
149 Seconds(60),
151 this,
152 socket,
153 to);
154}
155
156void
158{
160 Simulator::ScheduleWithContext(socket->GetNode()->GetId(),
161 Seconds(60),
163 this,
164 socket,
165 to);
166}
167
168void
170 Ipv4InterfaceAddress ifaceAddr)
171{
172 ipv4Interface->AddAddress(ifaceAddr);
173}
174
175void
177 Ipv6InterfaceAddress ifaceAddr)
178{
179 ipv6Interface->AddAddress(ifaceAddr);
180}
181
182void
184{
185 ipv4Interface->RemoveAddress(index);
186}
187
188void
190{
191 ipv6Interface->RemoveAddress(index);
192}
193
194void
196{
197 Ptr<Node> tx1Node = CreateObject<Node>();
198 Ptr<Node> tx2Node = CreateObject<Node>();
199 Ptr<Node> rxNode = CreateObject<Node>();
200 Ptr<Node> snifferNode = CreateObject<Node>();
201
202 NodeContainer all(tx1Node, tx2Node, rxNode, snifferNode);
203
204 std::ostringstream stringStream1v4;
205 Ptr<OutputStreamWrapper> arpStream = Create<OutputStreamWrapper>(&stringStream1v4);
206 std::ostringstream stringStream1v6;
207 Ptr<OutputStreamWrapper> ndiscStream = Create<OutputStreamWrapper>(&stringStream1v6);
208
209 InternetStackHelper internetNodes;
210 internetNodes.Install(all);
211
213 // Sender Node
215 {
217 tx1Dev->SetAddress(Mac48Address("00:00:00:00:00:01"));
218 tx1Node->AddDevice(tx1Dev);
219 }
220 net.Add(tx1Dev);
221
223 {
225 tx2Dev->SetAddress(Mac48Address("00:00:00:00:00:02"));
226 tx2Node->AddDevice(tx2Dev);
227 }
228 net.Add(tx2Dev);
229
230 // Receive node
232 {
234 rxDev->SetAddress(Mac48Address("00:00:00:00:00:03"));
235 rxNode->AddDevice(rxDev);
236 }
237 net.Add(rxDev);
238
239 // Sniffer node
240 Ptr<SimpleNetDevice> snifferDev;
241 {
242 snifferDev = CreateObject<SimpleNetDevice>();
243 snifferDev->SetAddress(Mac48Address("00:00:00:00:00:04"));
244 snifferNode->AddDevice(snifferDev);
245 }
246 net.Add(snifferDev);
247
248 // link the channels
250 tx1Dev->SetChannel(channel);
251 tx2Dev->SetChannel(channel);
252 rxDev->SetChannel(channel);
253 snifferDev->SetChannel(channel);
254
255 // Setup IPv4 addresses
257 ipv4.SetBase(Ipv4Address("10.0.1.0"), Ipv4Mask("255.255.255.0"));
258 Ipv4InterfaceContainer icv4 = ipv4.Assign(net);
259
260 // Add address 10.1.1.5 to rxNode in 0.5 seconds
261 Ptr<Node> n1 = rxNode;
262 uint32_t ipv4ifIndex = 1;
263 Ptr<Ipv4Interface> ipv4Interface = n1->GetObject<Ipv4L3Protocol>()->GetInterface(ipv4ifIndex);
264 Ipv4InterfaceAddress ifaceAddr = Ipv4InterfaceAddress("10.0.1.5", "255.255.255.0");
267 this,
268 ipv4Interface,
269 ifaceAddr);
270
271 // Remove the first address (10.1.1.3) from rxNode in 1.5 seconds
272 uint32_t addressIndex = 0;
275 this,
276 ipv4Interface,
277 addressIndex);
278
279 // Setup IPv6 addresses
281 ipv6.SetBase(Ipv6Address("2001:0::"), Ipv6Prefix(64));
282 Ipv6InterfaceContainer icv6 = ipv6.Assign(net);
283
284 // Add address 2001:1::200:ff:fe00:5 to rxNode in 0.5 seconds
285 uint32_t ipv6ifIndex = 1;
286 Ptr<Ipv6Interface> ipv6Interface = n1->GetObject<Ipv6L3Protocol>()->GetInterface(ipv6ifIndex);
287 Ipv6InterfaceAddress ifaceAddrv6 =
288 Ipv6InterfaceAddress("2001:0::200:ff:fe00:5", Ipv6Prefix(64));
291 this,
292 ipv6Interface,
293 ifaceAddrv6);
294
295 // Remove the second address (2001:1::200:ff:fe00:3) from rxNode in 1.5 seconds
296 addressIndex = 1;
299 this,
300 ipv6Interface,
301 addressIndex);
302
303 // Populate neighbor caches.
304 NeighborCacheHelper neighborCache;
305 neighborCache.SetDynamicNeighborCache(true);
306 neighborCache.PopulateNeighborCache();
307
308 // Print cache.
315
316 // Create the UDP sockets
317 Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory>();
318 Ptr<Socket> rxSocketv4 = rxSocketFactory->CreateSocket();
319 Ptr<Socket> rxSocketv6 = rxSocketFactory->CreateSocket();
320 NS_TEST_EXPECT_MSG_EQ(rxSocketv4->Bind(InetSocketAddress(Ipv4Address("10.0.1.5"), 1234)),
321 0,
322 "trivial");
324 rxSocketv6->Bind(Inet6SocketAddress(Ipv6Address("2001:0::200:ff:fe00:5"), 1234)),
325 0,
326 "trivial");
327 rxSocketv4->SetRecvCallback(MakeCallback(&DynamicNeighborCacheTest::ReceivePkt, this));
328 rxSocketv6->SetRecvCallback(MakeCallback(&DynamicNeighborCacheTest::ReceivePkt, this));
329
330 Ptr<SocketFactory> snifferSocketFactory = snifferNode->GetObject<UdpSocketFactory>();
331 Ptr<Socket> snifferSocketv4 = snifferSocketFactory->CreateSocket();
332 Ptr<Socket> snifferSocketv6 = snifferSocketFactory->CreateSocket();
333 NS_TEST_EXPECT_MSG_EQ(snifferSocketv4->Bind(InetSocketAddress(Ipv4Address("10.0.1.4"), 1234)),
334 0,
335 "trivial");
337 snifferSocketv6->Bind(Inet6SocketAddress(Ipv6Address("2001:0::200:ff:fe00:4"), 1234)),
338 0,
339 "trivial");
340 snifferSocketv4->SetRecvCallback(MakeCallback(&DynamicNeighborCacheTest::ReceivePkt, this));
341 snifferSocketv6->SetRecvCallback(MakeCallback(&DynamicNeighborCacheTest::ReceivePkt, this));
342
343 Ptr<SocketFactory> tx1SocketFactory = tx1Node->GetObject<UdpSocketFactory>();
344 Ptr<Socket> tx1Socket = tx1SocketFactory->CreateSocket();
345 tx1Socket->SetAllowBroadcast(true);
346
347 Ptr<SocketFactory> tx2SocketFactory = tx2Node->GetObject<UdpSocketFactory>();
348 Ptr<Socket> tx2Socket = tx2SocketFactory->CreateSocket();
349 tx2Socket->SetAllowBroadcast(true);
350
351 // ------ Now the tests ------------
352
353 // Unicast test
354
355 // send data to the added address
356 SendData(tx1Socket, Ipv4Address("10.0.1.5"));
357 SendData(tx1Socket, Ipv6Address("2001:0::200:ff:fe00:5"));
358
359 // send data to the removed address
360 SendData(tx1Socket, Ipv4Address("10.0.1.3"));
361 SendData(tx1Socket, Ipv6Address("2001:0::200:ff:fe00:3"));
362
365
366 // Check if all packet are correctly received.
368 123,
369 "Should receive packet sending to the added IPv4 address.");
371 123,
372 "Should receive packet sending to the added IPv6 address.");
375 2,
376 "Should receive only 1 packet from IPv4 interface and only 1 packet from IPv6 interface.");
377
378 // Check if the arp caches are populated correctly at time 0,
379 // Check if the arp caches are updated correctly at time 1 after new IP address is added,
380 // Check if the arp caches are updated correctly at time 2 after an IP address is removed.
381 constexpr auto arpCache =
382 "ARP Cache of node 0 at time 0\n"
383 "10.0.1.2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
384 "10.0.1.3 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
385 "10.0.1.4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
386 "ARP Cache of node 1 at time 0\n"
387 "10.0.1.1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
388 "10.0.1.3 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
389 "10.0.1.4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
390 "ARP Cache of node 2 at time 0\n"
391 "10.0.1.1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
392 "10.0.1.2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
393 "10.0.1.4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
394 "ARP Cache of node 3 at time 0\n"
395 "10.0.1.1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
396 "10.0.1.2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
397 "10.0.1.3 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
398 "ARP Cache of node 0 at time 1\n"
399 "10.0.1.2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
400 "10.0.1.3 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
401 "10.0.1.4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
402 "10.0.1.5 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
403 "ARP Cache of node 1 at time 1\n"
404 "10.0.1.1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
405 "10.0.1.3 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
406 "10.0.1.4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
407 "10.0.1.5 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
408 "ARP Cache of node 2 at time 1\n"
409 "10.0.1.1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
410 "10.0.1.2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
411 "10.0.1.4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
412 "ARP Cache of node 3 at time 1\n"
413 "10.0.1.1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
414 "10.0.1.2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
415 "10.0.1.3 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
416 "10.0.1.5 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
417 "ARP Cache of node 0 at time 2\n"
418 "10.0.1.2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
419 "10.0.1.4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
420 "10.0.1.5 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
421 "ARP Cache of node 1 at time 2\n"
422 "10.0.1.1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
423 "10.0.1.4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
424 "10.0.1.5 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
425 "ARP Cache of node 2 at time 2\n"
426 "10.0.1.1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
427 "10.0.1.2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
428 "10.0.1.4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
429 "ARP Cache of node 3 at time 2\n"
430 "10.0.1.1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
431 "10.0.1.2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
432 "10.0.1.5 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n";
433 NS_TEST_EXPECT_MSG_EQ(stringStream1v4.str(), arpCache, "Arp cache is incorrect.");
434
435 // Check if the ndisc caches are populated correctly at time 0,
436 // Check if the ndisc caches are updated correctly at time 1 after new IP address is added,
437 // Check if the ndisc caches are updated correctly at time 2 after an IP address is removed.
438 constexpr auto NdiscCache =
439 "NDISC Cache of node 0 at time +0s\n"
440 "2001::200:ff:fe00:2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
441 "2001::200:ff:fe00:3 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
442 "2001::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
443 "fe80::200:ff:fe00:2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
444 "fe80::200:ff:fe00:3 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
445 "fe80::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
446 "NDISC Cache of node 1 at time +0s\n"
447 "2001::200:ff:fe00:1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
448 "2001::200:ff:fe00:3 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
449 "2001::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
450 "fe80::200:ff:fe00:1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
451 "fe80::200:ff:fe00:3 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
452 "fe80::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
453 "NDISC Cache of node 2 at time +0s\n"
454 "2001::200:ff:fe00:1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
455 "2001::200:ff:fe00:2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
456 "2001::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
457 "fe80::200:ff:fe00:1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
458 "fe80::200:ff:fe00:2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
459 "fe80::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
460 "NDISC Cache of node 3 at time +0s\n"
461 "2001::200:ff:fe00:1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
462 "2001::200:ff:fe00:2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
463 "2001::200:ff:fe00:3 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
464 "fe80::200:ff:fe00:1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
465 "fe80::200:ff:fe00:2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
466 "fe80::200:ff:fe00:3 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
467 "NDISC Cache of node 0 at time +1s\n"
468 "2001::200:ff:fe00:2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
469 "2001::200:ff:fe00:3 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
470 "2001::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
471 "2001::200:ff:fe00:5 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
472 "fe80::200:ff:fe00:2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
473 "fe80::200:ff:fe00:3 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
474 "fe80::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
475 "NDISC Cache of node 1 at time +1s\n"
476 "2001::200:ff:fe00:1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
477 "2001::200:ff:fe00:3 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
478 "2001::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
479 "2001::200:ff:fe00:5 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
480 "fe80::200:ff:fe00:1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
481 "fe80::200:ff:fe00:3 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
482 "fe80::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
483 "NDISC Cache of node 2 at time +1s\n"
484 "2001::200:ff:fe00:1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
485 "2001::200:ff:fe00:2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
486 "2001::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
487 "fe80::200:ff:fe00:1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
488 "fe80::200:ff:fe00:2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
489 "fe80::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
490 "NDISC Cache of node 3 at time +1s\n"
491 "2001::200:ff:fe00:1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
492 "2001::200:ff:fe00:2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
493 "2001::200:ff:fe00:3 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
494 "2001::200:ff:fe00:5 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
495 "fe80::200:ff:fe00:1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
496 "fe80::200:ff:fe00:2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
497 "fe80::200:ff:fe00:3 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
498 "NDISC Cache of node 0 at time +2s\n"
499 "2001::200:ff:fe00:2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
500 "2001::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
501 "2001::200:ff:fe00:5 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
502 "fe80::200:ff:fe00:2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
503 "fe80::200:ff:fe00:3 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
504 "fe80::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
505 "NDISC Cache of node 1 at time +2s\n"
506 "2001::200:ff:fe00:1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
507 "2001::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
508 "2001::200:ff:fe00:5 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
509 "fe80::200:ff:fe00:1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
510 "fe80::200:ff:fe00:3 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
511 "fe80::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
512 "NDISC Cache of node 2 at time +2s\n"
513 "2001::200:ff:fe00:1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
514 "2001::200:ff:fe00:2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
515 "2001::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
516 "fe80::200:ff:fe00:1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
517 "fe80::200:ff:fe00:2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
518 "fe80::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
519 "NDISC Cache of node 3 at time +2s\n"
520 "2001::200:ff:fe00:1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
521 "2001::200:ff:fe00:2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
522 "2001::200:ff:fe00:5 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
523 "fe80::200:ff:fe00:1 dev 1 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
524 "fe80::200:ff:fe00:2 dev 1 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
525 "fe80::200:ff:fe00:3 dev 1 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n";
526 NS_TEST_EXPECT_MSG_EQ(stringStream1v6.str(), NdiscCache, "Ndisc cache is incorrect.");
527
528 m_receivedPacket->RemoveAllByteTags();
529
531}
532
533/**
534 * @ingroup internet-test
535 *
536 * @brief Neighbor cache on Channel Test
537 */
538class ChannelTest : public TestCase
539{
540 public:
541 void DoRun() override;
542 ChannelTest();
543
544 private:
545 NodeContainer m_nodes; //!< Nodes used in the test.
546};
547
549 : TestCase(
550 "The ChannelTest Check if neighbor caches are correctly populated on specific channel.")
551{
552}
553
554void
556{
557 m_nodes.Create(3);
558
560 SimpleNetDeviceHelper simpleHelper;
561 NetDeviceContainer net = simpleHelper.Install(m_nodes.Get(0), channel);
562 net.Add(simpleHelper.Install(m_nodes.Get(1), channel));
563
565 SimpleNetDeviceHelper simpleHelper2;
566 NetDeviceContainer net2 = simpleHelper.Install(m_nodes.Get(1), channel2);
567 net2.Add(simpleHelper2.Install(m_nodes.Get(2), channel2));
568
569 InternetStackHelper internet;
570 internet.Install(m_nodes);
571
572 // Setup IPv4 addresses
574 ipv4.SetBase("10.1.1.0", "255.255.255.252");
575 Ipv4InterfaceContainer i = ipv4.Assign(net);
576 ipv4.SetBase("10.1.2.0", "255.255.255.252");
577 Ipv4InterfaceContainer i2 = ipv4.Assign(net2);
578
579 // Setup IPv6 addresses
581 ipv6.SetBase(Ipv6Address("2001:0::"), Ipv6Prefix(64));
582 Ipv6InterfaceContainer icv61 = ipv6.Assign(net);
583 ipv6.SetBase(Ipv6Address("2001:1::"), Ipv6Prefix(64));
584 Ipv6InterfaceContainer icv62 = ipv6.Assign(net2);
585
586 // Populate neighbor caches on the first channel
587 NeighborCacheHelper neighborCache;
588 neighborCache.PopulateNeighborCache(channel);
589
590 std::ostringstream stringStream1v4;
591 Ptr<OutputStreamWrapper> arpStream = Create<OutputStreamWrapper>(&stringStream1v4);
592 std::ostringstream stringStream1v6;
593 Ptr<OutputStreamWrapper> ndiscStream = Create<OutputStreamWrapper>(&stringStream1v6);
594
595 // Print cache.
598
600
601 // Check if arp caches are populated correctly in the first channel
602 constexpr auto arpCache = "ARP Cache of node 0 at time 0\n"
603 "10.1.1.2 dev 0 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
604 "ARP Cache of node 1 at time 0\n"
605 "10.1.1.1 dev 0 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
606 "ARP Cache of node 2 at time 0\n";
607 NS_TEST_EXPECT_MSG_EQ(stringStream1v4.str(), arpCache, "Arp cache is incorrect.");
608
609 // Check if ndisc caches are populated correctly in the first channel
610 constexpr auto NdiscCache =
611 "NDISC Cache of node 0 at time +0s\n"
612 "2001::200:ff:fe00:2 dev 0 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
613 "fe80::200:ff:fe00:2 dev 0 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
614 "NDISC Cache of node 1 at time +0s\n"
615 "2001::200:ff:fe00:1 dev 0 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
616 "fe80::200:ff:fe00:1 dev 0 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
617 "NDISC Cache of node 2 at time +0s\n";
618 NS_TEST_EXPECT_MSG_EQ(stringStream1v6.str(), NdiscCache, "Ndisc cache is incorrect.");
620}
621
622/**
623 * @ingroup internet-test
624 *
625 * @brief Neighbor Cache on NetDeviceContainer Test
626 */
628{
629 public:
630 void DoRun() override;
632
633 private:
634 NodeContainer m_nodes; //!< Nodes used in the test.
635};
636
638 : TestCase("The NetDeviceContainerTest check if neighbor caches are populated correctly on "
639 "specific netDeviceContainer.")
640{
641}
642
643void
645{
646 m_nodes.Create(3);
647
649 SimpleNetDeviceHelper simpleHelper;
650 NetDeviceContainer net = simpleHelper.Install(m_nodes.Get(0), channel);
651 net.Add(simpleHelper.Install(m_nodes.Get(1), channel));
652
654 SimpleNetDeviceHelper simpleHelper2;
655 NetDeviceContainer net2 = simpleHelper.Install(m_nodes.Get(1), channel2);
656 net2.Add(simpleHelper2.Install(m_nodes.Get(2), channel2));
657
658 InternetStackHelper internet;
659 internet.Install(m_nodes);
660
661 // Setup IPv4 addresses
663 ipv4.SetBase("10.1.1.0", "255.255.255.252");
664 Ipv4InterfaceContainer i = ipv4.Assign(net);
665 ipv4.SetBase("10.1.2.0", "255.255.255.252");
666 Ipv4InterfaceContainer i2 = ipv4.Assign(net2);
667
668 // Setup IPv6 addresses
670 ipv6.SetBase(Ipv6Address("2001:0::"), Ipv6Prefix(64));
671 Ipv6InterfaceContainer icv61 = ipv6.Assign(net);
672 ipv6.SetBase(Ipv6Address("2001:1::"), Ipv6Prefix(64));
673 Ipv6InterfaceContainer icv62 = ipv6.Assign(net2);
674
675 // Populate neighbor caches on NetDeviceContainer net2.
676 NeighborCacheHelper neighborCache;
677 neighborCache.PopulateNeighborCache(net2);
678
679 std::ostringstream stringStream1v4;
680 Ptr<OutputStreamWrapper> arpStream = Create<OutputStreamWrapper>(&stringStream1v4);
681 std::ostringstream stringStream1v6;
682 Ptr<OutputStreamWrapper> ndiscStream = Create<OutputStreamWrapper>(&stringStream1v6);
683
684 // Print cache.
687
689
690 // Check if arp caches are populated correctly on NetDeviceContainer net2.
691 constexpr auto arpCache =
692 "ARP Cache of node 0 at time 0\n"
693 "ARP Cache of node 1 at time 0\n"
694 "10.1.2.2 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
695 "ARP Cache of node 2 at time 0\n"
696 "10.1.2.1 dev 0 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n";
697 NS_TEST_EXPECT_MSG_EQ(stringStream1v4.str(), arpCache, "Arp cache is incorrect.");
698
699 // Check if ndisc caches are populated correctly on NetDeviceContainer net2.
700 constexpr auto NdiscCache =
701 "NDISC Cache of node 0 at time +0s\n"
702 "NDISC Cache of node 1 at time +0s\n"
703 "2001:1::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
704 "fe80::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
705 "NDISC Cache of node 2 at time +0s\n"
706 "2001:1::200:ff:fe00:3 dev 0 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
707 "fe80::200:ff:fe00:3 dev 0 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n";
708 NS_TEST_EXPECT_MSG_EQ(stringStream1v6.str(), NdiscCache, "Ndisc cache is incorrect.");
710}
711
712/**
713 * @ingroup internet-test
714 *
715 * @brief Neighbor Cache on InterfaceContainer Test
716 */
718{
719 public:
720 void DoRun() override;
722
723 private:
724 NodeContainer m_nodes; //!< Nodes used in the test.
725};
726
728 : TestCase("The InterfaceContainerTest check if neighbor caches are populated correctly on "
729 "specific interfaceContainer.")
730{
731}
732
733void
735{
736 m_nodes.Create(3);
737
739 SimpleNetDeviceHelper simpleHelper;
740 NetDeviceContainer net = simpleHelper.Install(m_nodes.Get(0), channel);
741 net.Add(simpleHelper.Install(m_nodes.Get(1), channel));
742
744 SimpleNetDeviceHelper simpleHelper2;
745 NetDeviceContainer net2 = simpleHelper.Install(m_nodes.Get(1), channel2);
746 net2.Add(simpleHelper2.Install(m_nodes.Get(2), channel2));
747
748 InternetStackHelper internet;
749 internet.Install(m_nodes);
750
751 // Setup IPv4 addresses
753 ipv4.SetBase("10.1.1.0", "255.255.255.252");
754 Ipv4InterfaceContainer i = ipv4.Assign(net);
755 ipv4.SetBase("10.1.2.0", "255.255.255.252");
756 Ipv4InterfaceContainer i2 = ipv4.Assign(net2);
757
758 // Setup IPv6 addresses
760 ipv6.SetBase(Ipv6Address("2001:0::"), Ipv6Prefix(64));
761 Ipv6InterfaceContainer icv61 = ipv6.Assign(net);
762 ipv6.SetBase(Ipv6Address("2001:1::"), Ipv6Prefix(64));
763 Ipv6InterfaceContainer icv62 = ipv6.Assign(net2);
764
765 // Populate neighbor caches on Ipv4InterfaceContainer i and Ipv6InterfaceContainer icv62.
766 NeighborCacheHelper neighborCache;
767 neighborCache.PopulateNeighborCache(i);
768 neighborCache.PopulateNeighborCache(icv62);
769
770 std::ostringstream stringStream1v4;
771 Ptr<OutputStreamWrapper> arpStream = Create<OutputStreamWrapper>(&stringStream1v4);
772 std::ostringstream stringStream1v6;
773 Ptr<OutputStreamWrapper> ndiscStream = Create<OutputStreamWrapper>(&stringStream1v6);
774
775 // Print cache.
778
780
781 // Check if arp caches are populated correctly on Ipv4InterfaceContainer i.
782 constexpr auto arpCache = "ARP Cache of node 0 at time 0\n"
783 "10.1.1.2 dev 0 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
784 "ARP Cache of node 1 at time 0\n"
785 "10.1.1.1 dev 0 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
786 "ARP Cache of node 2 at time 0\n";
787 NS_TEST_EXPECT_MSG_EQ(stringStream1v4.str(), arpCache, "Arp cache is incorrect.");
788
789 // Check if ndisc caches are populated correctly on Ipv6InterfaceContainer icv62.
790 constexpr auto NdiscCache =
791 "NDISC Cache of node 0 at time +0s\n"
792 "NDISC Cache of node 1 at time +0s\n"
793 "2001:1::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
794 "fe80::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
795 "NDISC Cache of node 2 at time +0s\n"
796 "2001:1::200:ff:fe00:3 dev 0 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
797 "fe80::200:ff:fe00:3 dev 0 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n";
798 NS_TEST_EXPECT_MSG_EQ(stringStream1v6.str(), NdiscCache, "Ndisc cache is incorrect.");
800}
801
802/**
803 * @ingroup internet-test
804 *
805 * @brief Neighbor Cache Flush Test
806 */
807class FlushTest : public TestCase
808{
809 public:
810 void DoRun() override;
811 FlushTest();
812
813 private:
814 NodeContainer m_nodes; //!< Nodes used in the test.
815};
816
818 : TestCase("The FlushTest checks that FlushAutoGenerated() will only remove "
819 "STATIC_AUTOGENERATED entries.")
820{
821}
822
823void
825{
826 m_nodes.Create(3);
827
829 SimpleNetDeviceHelper simpleHelper;
830 NetDeviceContainer net = simpleHelper.Install(m_nodes.Get(0), channel);
831 net.Add(simpleHelper.Install(m_nodes.Get(1), channel));
832
834 SimpleNetDeviceHelper simpleHelper2;
835 NetDeviceContainer net2 = simpleHelper.Install(m_nodes.Get(1), channel2);
836 net2.Add(simpleHelper2.Install(m_nodes.Get(2), channel2));
837
838 InternetStackHelper internet;
839 internet.Install(m_nodes);
840
841 // Setup IPv4 addresses
843 ipv4.SetBase("10.1.1.0", "255.255.255.252");
844 Ipv4InterfaceContainer i = ipv4.Assign(net);
845 ipv4.SetBase("10.1.2.0", "255.255.255.252");
846 Ipv4InterfaceContainer i2 = ipv4.Assign(net2);
847
848 // Setup IPv6 addresses
850 ipv6.SetBase(Ipv6Address("2001:0::"), Ipv6Prefix(64));
851 Ipv6InterfaceContainer icv61 = ipv6.Assign(net);
852 ipv6.SetBase(Ipv6Address("2001:1::"), Ipv6Prefix(64));
853 Ipv6InterfaceContainer icv62 = ipv6.Assign(net2);
854
855 // Populate STATIC_AUTOGENERATED neighbor cache
856 NeighborCacheHelper neighborCache;
857 neighborCache.PopulateNeighborCache();
858
859 // Manually add an PERMANENT arp cache entry
860 std::pair<Ptr<Ipv4>, uint32_t> returnValue = i.Get(0);
861 Ptr<Ipv4> v4 = returnValue.first;
862 uint32_t index = returnValue.second;
863 Ptr<Ipv4Interface> iface = DynamicCast<Ipv4L3Protocol>(v4)->GetInterface(index);
864 Ptr<ArpCache> arpCache = iface->GetArpCache();
865 ArpCache::Entry* arpCacheEntry = arpCache->Add(Ipv4Address("10.1.1.4"));
866 arpCacheEntry->SetMacAddress(Mac48Address("00:00:00:00:00:01"));
867 arpCacheEntry->MarkPermanent();
868
869 // Manually add an PERMANENT ndisc entry
870 std::pair<Ptr<Ipv6>, uint32_t> returnValue2 = icv61.Get(0);
871 Ptr<Ipv6> v6 = returnValue2.first;
872 index = returnValue2.second;
873 Ptr<Ipv6Interface> ifacev6 = DynamicCast<Ipv6L3Protocol>(v6)->GetInterface(index);
874 Ptr<NdiscCache> ndiscCache = ifacev6->GetNdiscCache();
875 NdiscCache::Entry* ndiscCacheEntry = ndiscCache->Add(Ipv6Address("2001::200:ff:fe00:4"));
876 ndiscCacheEntry->SetMacAddress(Mac48Address("00:00:00:00:00:01"));
877 ndiscCacheEntry->MarkPermanent();
878
879 // flush auto-generated cache
880 neighborCache.FlushAutoGenerated();
881
882 std::ostringstream stringStream1v4;
883 Ptr<OutputStreamWrapper> arpStream = Create<OutputStreamWrapper>(&stringStream1v4);
884 std::ostringstream stringStream1v6;
885 Ptr<OutputStreamWrapper> ndiscStream = Create<OutputStreamWrapper>(&stringStream1v6);
886
887 // Print cache at time 0.
890
891 // Flush cache at time 1 s.
894
895 // Print cache again at time 2 s.
896 std::ostringstream stringStream2v4;
897 Ptr<OutputStreamWrapper> arpStream2 = Create<OutputStreamWrapper>(&stringStream2v4);
898 std::ostringstream stringStream2v6;
899 Ptr<OutputStreamWrapper> ndiscStream2 = Create<OutputStreamWrapper>(&stringStream2v6);
902
903 // Add autogenerated entries at time 3 s again.
904 Simulator::Schedule(Seconds(3), [&neighborCache]() { neighborCache.PopulateNeighborCache(); });
905
906 // Flush cache again at time 4 s.
909
910 // Print cache again at time 5 s.
911 // Check that the autogenerated entries survived the Flush
912 std::ostringstream stringStream5v4;
913 Ptr<OutputStreamWrapper> arpStream5 = Create<OutputStreamWrapper>(&stringStream5v4);
914 std::ostringstream stringStream5v6;
915 Ptr<OutputStreamWrapper> ndiscStream5 = Create<OutputStreamWrapper>(&stringStream5v6);
916 // Limit the printed output to node 0
919
921
922 // Check the time zero output
923 // Check if the STATIC_AUTOGENERATED entries are flushed and the PERMANENT entry is left.
924 constexpr auto ArpCache = "ARP Cache of node 0 at time 0\n"
925 "10.1.1.4 dev 0 lladdr 04-06-00:00:00:00:00:01 PERMANENT\n"
926 "ARP Cache of node 1 at time 0\n"
927 "ARP Cache of node 2 at time 0\n";
928 NS_TEST_EXPECT_MSG_EQ(stringStream1v4.str(), ArpCache, "Arp cache is incorrect.");
929
930 // Check if the STATIC_AUTOGENERATED entries are flushed and the PERMANENT entry is left.
931 constexpr auto NdiscCache =
932 "NDISC Cache of node 0 at time +0s\n"
933 "2001::200:ff:fe00:4 dev 0 lladdr 04-06-00:00:00:00:00:01 PERMANENT\n"
934 "NDISC Cache of node 1 at time +0s\n"
935 "NDISC Cache of node 2 at time +0s\n";
936 NS_TEST_EXPECT_MSG_EQ(stringStream1v6.str(), NdiscCache, "Ndisc cache is incorrect.");
937
938 // Check output after the first flush-- should be empty
939 constexpr auto ArpCache2 = "ARP Cache of node 0 at time 2\n"
940 "ARP Cache of node 1 at time 2\n"
941 "ARP Cache of node 2 at time 2\n";
942 NS_TEST_EXPECT_MSG_EQ(stringStream2v4.str(),
943 ArpCache2,
944 "Arp cache is incorrect after Flush().");
945 constexpr auto NdiscCache2 = "NDISC Cache of node 0 at time +2s\n"
946 "NDISC Cache of node 1 at time +2s\n"
947 "NDISC Cache of node 2 at time +2s\n";
948 NS_TEST_EXPECT_MSG_EQ(stringStream2v6.str(),
949 NdiscCache2,
950 "Ndisc cache is incorrect after Flush().");
951
952 // Check output after the second flush-- node 0 should still have two
953 // static autogenerated entries for IPv6 and one for IPv4.
954 // This behavior was added in the ns-3.46 release (see issue #851).
955 constexpr auto ArpCache5 =
956 "ARP Cache of node 0 at time 5\n"
957 "10.1.1.2 dev 0 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n";
958 constexpr auto NdiscCache5 =
959 "NDISC Cache of node 0 at time +5s\n"
960 "2001::200:ff:fe00:2 dev 0 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
961 "fe80::200:ff:fe00:2 dev 0 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n";
962 NS_TEST_EXPECT_MSG_EQ(stringStream5v4.str(),
963 ArpCache5,
964 "Arp cache is incorrect after second Flush().");
965 NS_TEST_EXPECT_MSG_EQ(stringStream5v6.str(),
966 NdiscCache5,
967 "Ndisc cache is incorrect after second Flush().");
968
970}
971
972/**
973 * @ingroup internet-test
974 *
975 * @brief Neighbor Cache on Overlapped Scope Test
976 */
978{
979 public:
980 void DoRun() override;
982
983 private:
984 NodeContainer m_nodes; //!< Nodes used in the test.
985};
986
988 : TestCase("The DuplicateTest checks that populate neighbor caches in overlapped scope does "
989 "not raise an error or generate duplicate entries.")
990{
991}
992
993void
995{
996 m_nodes.Create(3);
997
999 SimpleNetDeviceHelper simpleHelper;
1000 NetDeviceContainer net = simpleHelper.Install(m_nodes.Get(0), channel);
1001 net.Add(simpleHelper.Install(m_nodes.Get(1), channel));
1002
1004 SimpleNetDeviceHelper simpleHelper2;
1005 NetDeviceContainer net2 = simpleHelper.Install(m_nodes.Get(1), channel2);
1006 net2.Add(simpleHelper2.Install(m_nodes.Get(2), channel2));
1007
1008 InternetStackHelper internet;
1009 internet.Install(m_nodes);
1010
1011 // Setup IPv4 addresses
1012 Ipv4AddressHelper ipv4;
1013 ipv4.SetBase("10.1.1.0", "255.255.255.252");
1014 Ipv4InterfaceContainer i = ipv4.Assign(net);
1015 ipv4.SetBase("10.1.2.0", "255.255.255.252");
1016 Ipv4InterfaceContainer i2 = ipv4.Assign(net2);
1017
1018 // Setup IPv6 addresses
1019 Ipv6AddressHelper ipv6;
1020 ipv6.SetBase(Ipv6Address("2001:0::"), Ipv6Prefix(64));
1021 Ipv6InterfaceContainer icv61 = ipv6.Assign(net);
1022 ipv6.SetBase(Ipv6Address("2001:1::"), Ipv6Prefix(64));
1023 Ipv6InterfaceContainer icv62 = ipv6.Assign(net2);
1024
1025 // Populate neighbor cache in overlapped scope.
1026 NeighborCacheHelper neighborCache;
1027 neighborCache.PopulateNeighborCache();
1028 neighborCache.PopulateNeighborCache(channel);
1029 neighborCache.PopulateNeighborCache(net2);
1030 neighborCache.PopulateNeighborCache(icv61);
1031 neighborCache.PopulateNeighborCache();
1032
1033 std::ostringstream stringStream1v4;
1034 Ptr<OutputStreamWrapper> arpStream = Create<OutputStreamWrapper>(&stringStream1v4);
1035 std::ostringstream stringStream1v6;
1036 Ptr<OutputStreamWrapper> ndiscStream = Create<OutputStreamWrapper>(&stringStream1v6);
1037
1038 // Print cache.
1041
1043 // Check if the overlapped scope of PopulateNeighborCache() calls did
1044 // not lead to duplicate entries.
1045 constexpr auto ArpCache =
1046 "ARP Cache of node 0 at time 0\n"
1047 "10.1.1.2 dev 0 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
1048 "ARP Cache of node 1 at time 0\n"
1049 "10.1.1.1 dev 0 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
1050 "10.1.2.2 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
1051 "ARP Cache of node 2 at time 0\n"
1052 "10.1.2.1 dev 0 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n";
1053 NS_TEST_EXPECT_MSG_EQ(stringStream1v4.str(), ArpCache, "Arp cache is incorrect.");
1054
1055 // Check if the overlapped scope of PopulateNeighborCache() calls did
1056 // not lead to duplicate entries.
1057 constexpr auto NdiscCache =
1058 "NDISC Cache of node 0 at time +0s\n"
1059 "2001::200:ff:fe00:2 dev 0 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
1060 "fe80::200:ff:fe00:2 dev 0 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
1061 "NDISC Cache of node 1 at time +0s\n"
1062 "2001::200:ff:fe00:1 dev 0 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
1063 "fe80::200:ff:fe00:1 dev 0 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
1064 "2001:1::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
1065 "fe80::200:ff:fe00:4 dev 1 lladdr 04-06-00:00:00:00:00:04 STATIC_AUTOGENERATED\n"
1066 "NDISC Cache of node 2 at time +0s\n"
1067 "2001:1::200:ff:fe00:3 dev 0 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n"
1068 "fe80::200:ff:fe00:3 dev 0 lladdr 04-06-00:00:00:00:00:03 STATIC_AUTOGENERATED\n";
1069 NS_TEST_EXPECT_MSG_EQ(stringStream1v6.str(), NdiscCache, "Ndisc cache is incorrect.");
1071}
1072
1073/**
1074 * @ingroup internet-test
1075 *
1076 * @brief Dynamic Neighbor Cache on Reduced Scope Test
1077 */
1079{
1080 public:
1081 void DoRun() override;
1083
1084 /**
1085 * @brief Add an IPv4 address to an IPv4 interface
1086 * @param ipv4Interface The interface that address will be added.
1087 * @param ifaceAddr The added IPv4 address.
1088 */
1089 void AddIpv4Address(Ptr<Ipv4Interface> ipv4Interface, Ipv4InterfaceAddress ifaceAddr);
1090
1091 /**
1092 * @brief Add an IPv6 address to an IPv6 interface
1093 * @param ipv6Interface The interface that address will be added.
1094 * @param ifaceAddr The added IPv6 address.
1095 */
1096 void AddIpv6Address(Ptr<Ipv6Interface> ipv6Interface, Ipv6InterfaceAddress ifaceAddr);
1097
1098 /**
1099 * @brief Remove an IPv4 address from an IPv4 interface
1100 * @param ipv4Interface The interface that address will be removed from.
1101 * @param index The index of IPv4 address that will be removed.
1102 */
1103 void RemoveIpv4Address(Ptr<Ipv4Interface> ipv4Interface, uint32_t index);
1104
1105 /**
1106 * @brief Remove an IPv6 address from an IPv6 interface
1107 * @param ipv6Interface The interface that address will be removed from.
1108 * @param index The index of IPv6 address that will be removed.
1109 */
1110 void RemoveIpv6Address(Ptr<Ipv6Interface> ipv6Interface, uint32_t index);
1111
1112 private:
1113 NodeContainer m_nodes; //!< Nodes used in the test.
1114};
1115
1117 : TestCase("The DynamicPartialTest checks if dynamic neighbor cache update correctly when "
1118 "generating on a non-global scope.")
1119{
1120}
1121
1122void
1124{
1125 ipv4Interface->AddAddress(ifaceAddr);
1126}
1127
1128void
1130{
1131 ipv6Interface->AddAddress(ifaceAddr);
1132}
1133
1134void
1136{
1137 ipv4Interface->RemoveAddress(index);
1138}
1139
1140void
1142{
1143 ipv6Interface->RemoveAddress(index);
1144}
1145
1146void
1148{
1149 m_nodes.Create(3);
1150
1152 SimpleNetDeviceHelper simpleHelper;
1153 NetDeviceContainer net = simpleHelper.Install(m_nodes.Get(0), channel);
1154 net.Add(simpleHelper.Install(m_nodes.Get(1), channel));
1155
1157 SimpleNetDeviceHelper simpleHelper2;
1158 NetDeviceContainer net2 = simpleHelper.Install(m_nodes.Get(1), channel2);
1159 net2.Add(simpleHelper2.Install(m_nodes.Get(2), channel2));
1160
1161 InternetStackHelper internet;
1162 internet.Install(m_nodes);
1163
1164 // Setup IPv4 addresses
1165 Ipv4AddressHelper ipv4;
1166 ipv4.SetBase("10.1.1.0", "255.255.255.252");
1167 Ipv4InterfaceContainer i = ipv4.Assign(net);
1168 ipv4.SetBase("10.1.2.0", "255.255.255.252");
1169 Ipv4InterfaceContainer i2 = ipv4.Assign(net2);
1170
1171 // Add address 10.1.1.5 to n1 in 0.5 seconds
1172 Ptr<Node> n1 = m_nodes.Get(0);
1173 uint32_t ipv4ifIndex = 1;
1174 Ptr<Ipv4Interface> ipv4Interface = n1->GetObject<Ipv4L3Protocol>()->GetInterface(ipv4ifIndex);
1175 Ipv4InterfaceAddress ifaceAddr = Ipv4InterfaceAddress("10.1.1.5", "255.255.255.0");
1178 this,
1179 ipv4Interface,
1180 ifaceAddr);
1181
1182 // Remove the first address (10.1.1.1) from n1 in 1.5 seconds
1183 uint32_t addressIndex = 0;
1186 this,
1187 ipv4Interface,
1188 addressIndex);
1189
1190 // Setup IPv6 addresses
1191 Ipv6AddressHelper ipv6;
1192 ipv6.SetBase(Ipv6Address("2001:0::"), Ipv6Prefix(64));
1193 Ipv6InterfaceContainer icv61 = ipv6.Assign(net);
1194 ipv6.SetBase(Ipv6Address("2001:1::"), Ipv6Prefix(64));
1195 Ipv6InterfaceContainer icv62 = ipv6.Assign(net2);
1196
1197 // Add address 2001:1::200:ff:fe00:5 to n1 in 0.5 seconds
1198 uint32_t ipv6ifIndex = 1;
1199 Ptr<Ipv6Interface> ipv6Interface = n1->GetObject<Ipv6L3Protocol>()->GetInterface(ipv6ifIndex);
1200 Ipv6InterfaceAddress ifaceAddrv6 =
1201 Ipv6InterfaceAddress("2001:0::200:ff:fe00:5", Ipv6Prefix(64));
1204 this,
1205 ipv6Interface,
1206 ifaceAddrv6);
1207
1208 // Remove the second address (2001:1::200:ff:fe00:1) from n1 in 1.5 seconds
1209 addressIndex = 1;
1212 this,
1213 ipv6Interface,
1214 addressIndex);
1215
1216 // Populate dynamic neighbor cache on the first channel
1217 NeighborCacheHelper neighborCache;
1218 neighborCache.SetDynamicNeighborCache(true);
1219 neighborCache.PopulateNeighborCache(channel);
1220
1221 std::ostringstream stringStream1v4;
1222 Ptr<OutputStreamWrapper> arpStream = Create<OutputStreamWrapper>(&stringStream1v4);
1223 std::ostringstream stringStream1v6;
1224 Ptr<OutputStreamWrapper> ndiscStream = Create<OutputStreamWrapper>(&stringStream1v6);
1225
1226 // Print cache.
1233
1235 // Check if the dynamic neighbor cache doesn't change after an Ip address is added,
1236 // Check if the dynamic neighbor cache update correctly after an Ip address is removed.
1237 constexpr auto ArpCache = "ARP Cache of node 0 at time 0\n"
1238 "10.1.1.2 dev 0 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
1239 "ARP Cache of node 1 at time 0\n"
1240 "10.1.1.1 dev 0 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
1241 "ARP Cache of node 2 at time 0\n"
1242 "ARP Cache of node 0 at time 1\n"
1243 "10.1.1.2 dev 0 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
1244 "ARP Cache of node 1 at time 1\n"
1245 "10.1.1.1 dev 0 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
1246 "ARP Cache of node 2 at time 1\n"
1247 "ARP Cache of node 0 at time 2\n"
1248 "10.1.1.2 dev 0 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
1249 "ARP Cache of node 1 at time 2\n"
1250 "ARP Cache of node 2 at time 2\n";
1251 NS_TEST_EXPECT_MSG_EQ(stringStream1v4.str(), ArpCache, "Arp cache is incorrect.");
1252
1253 // Check if the dynamic neighbor cache doesn't change after an Ip address is added,
1254 // Check if the dynamic neighbor cache update correctly after an Ip address is removed.
1255 constexpr auto NdiscCache =
1256 "NDISC Cache of node 0 at time +0s\n"
1257 "2001::200:ff:fe00:2 dev 0 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
1258 "fe80::200:ff:fe00:2 dev 0 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
1259 "NDISC Cache of node 1 at time +0s\n"
1260 "2001::200:ff:fe00:1 dev 0 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
1261 "fe80::200:ff:fe00:1 dev 0 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
1262 "NDISC Cache of node 2 at time +0s\n"
1263 "NDISC Cache of node 0 at time +1s\n"
1264 "2001::200:ff:fe00:2 dev 0 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
1265 "fe80::200:ff:fe00:2 dev 0 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
1266 "NDISC Cache of node 1 at time +1s\n"
1267 "2001::200:ff:fe00:1 dev 0 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
1268 "fe80::200:ff:fe00:1 dev 0 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
1269 "NDISC Cache of node 2 at time +1s\n"
1270 "NDISC Cache of node 0 at time +2s\n"
1271 "2001::200:ff:fe00:2 dev 0 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
1272 "fe80::200:ff:fe00:2 dev 0 lladdr 04-06-00:00:00:00:00:02 STATIC_AUTOGENERATED\n"
1273 "NDISC Cache of node 1 at time +2s\n"
1274 "fe80::200:ff:fe00:1 dev 0 lladdr 04-06-00:00:00:00:00:01 STATIC_AUTOGENERATED\n"
1275 "NDISC Cache of node 2 at time +2s\n";
1276 NS_TEST_EXPECT_MSG_EQ(stringStream1v6.str(), NdiscCache, "Ndisc cache is incorrect.");
1278}
1279
1280/**
1281 * @ingroup internet-test
1282 *
1283 * @brief NeighborCache TestSuite
1284 */
1300
1301static NeighborCacheTestSuite g_neighborcacheTestSuite; //!< Static variable for test initialization
Neighbor cache on Channel Test.
void DoRun() override
Implementation to actually run this TestCase.
NodeContainer m_nodes
Nodes used in the test.
Neighbor Cache on Overlapped Scope Test.
NodeContainer m_nodes
Nodes used in the test.
void DoRun() override
Implementation to actually run this TestCase.
Dynamic Neighbor Cache Test.
std::vector< uint32_t > m_receivedPacketSizes
Received packet sizes.
void ReceivePkt(Ptr< Socket > socket)
Receive data.
void RemoveIpv4Address(Ptr< Ipv4Interface > ipv4Interface, uint32_t index)
Remove an IPv4 address from an IPv4 interface.
void AddIpv4Address(Ptr< Ipv4Interface > ipv4Interface, Ipv4InterfaceAddress ifaceAddr)
Add an IPv4 address to an IPv4 interface.
void AddIpv6Address(Ptr< Ipv6Interface > ipv6Interface, Ipv6InterfaceAddress ifaceAddr)
Add an IPv6 address to an IPv6 interface.
void DoRun() override
Implementation to actually run this TestCase.
void DoSendDatav4(Ptr< Socket > socket, Ipv4Address to)
Send data immediately after being called.
void RemoveIpv6Address(Ptr< Ipv6Interface > ipv6Interface, uint32_t index)
Remove an IPv6 address from an IPv6 interface.
void DoSendDatav6(Ptr< Socket > socket, Ipv6Address to)
Send data immediately after being called.
void SendData(Ptr< Socket > socket, Ipv4Address to)
Schedules the DoSendData () function to send the data.
Ptr< Packet > m_receivedPacket
Received packet.
Dynamic Neighbor Cache on Reduced Scope Test.
void DoRun() override
Implementation to actually run this TestCase.
void AddIpv6Address(Ptr< Ipv6Interface > ipv6Interface, Ipv6InterfaceAddress ifaceAddr)
Add an IPv6 address to an IPv6 interface.
void RemoveIpv4Address(Ptr< Ipv4Interface > ipv4Interface, uint32_t index)
Remove an IPv4 address from an IPv4 interface.
void RemoveIpv6Address(Ptr< Ipv6Interface > ipv6Interface, uint32_t index)
Remove an IPv6 address from an IPv6 interface.
void AddIpv4Address(Ptr< Ipv4Interface > ipv4Interface, Ipv4InterfaceAddress ifaceAddr)
Add an IPv4 address to an IPv4 interface.
NodeContainer m_nodes
Nodes used in the test.
Neighbor Cache Flush Test.
void DoRun() override
Implementation to actually run this TestCase.
NodeContainer m_nodes
Nodes used in the test.
Neighbor Cache on InterfaceContainer Test.
NodeContainer m_nodes
Nodes used in the test.
void DoRun() override
Implementation to actually run this TestCase.
NeighborCache TestSuite.
Neighbor Cache on NetDeviceContainer Test.
NodeContainer m_nodes
Nodes used in the test.
void DoRun() override
Implementation to actually run this TestCase.
a polymophic address class
Definition address.h:90
A record that that holds information about an ArpCache entry.
Definition arp-cache.h:178
void MarkPermanent()
Changes the state of this entry to Permanent.
Definition arp-cache.cc:449
void SetMacAddress(Address macAddress)
Definition arp-cache.cc:509
An ARP cache.
Definition arp-cache.h:42
void Flush()
Clear the ArpCache of all entries except auto-generated entries.
Definition arp-cache.cc:238
An Inet6 address class.
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Ipv4 addresses are stored in host order in this class.
a class to store IPv4 address information on an interface
holds a vector of std::pair of Ptr<Ipv4> and interface index.
std::pair< Ptr< Ipv4 >, uint32_t > Get(uint32_t i) const
Get the std::pair of an Ptr<Ipv4> and interface stored at the location specified by the index.
Implement the IPv4 layer.
a class to represent an Ipv4 address mask
static void PrintNeighborCacheAt(Time printTime, Ptr< Node > node, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the neighbor cache of a node at a particular time.
static void PrintNeighborCacheAllAt(Time printTime, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the neighbor cache of all nodes at a particular time.
Helper class to auto-assign global IPv6 unicast addresses.
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
Describes an IPv6 address.
IPv6 address associated with an interface.
Keep track of a set of IPv6 interfaces.
std::pair< Ptr< Ipv6 >, uint32_t > Get(uint32_t i) const
Get the std::pair of an Ptr<Ipv6> and interface stored at the location specified by the index.
IPv6 layer implementation.
Describes an IPv6 prefix.
static void PrintNeighborCacheAllAt(Time printTime, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the neighbor cache of all nodes at a particular time.
static void PrintNeighborCacheAt(Time printTime, Ptr< Node > node, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the neighbor cache of a node at a particular time.
an EUI-48 address
A record that holds information about a NdiscCache entry.
void MarkPermanent()
Change the state to this entry to PERMANENT.
void SetMacAddress(Address mac)
Set the MAC address of this entry.
IPv6 Neighbor Discovery cache.
Definition ndisc-cache.h:38
void Flush()
Clear the cache of all entries except auto-generated entries.
A helper class to populate neighbor cache.
void PopulateNeighborCache()
Populate neighbor ARP and NDISC caches for all devices.
void SetDynamicNeighborCache(bool enable)
Enable/disable dynamic neighbor cache, auto-generated neighbor cache will update by IP addresses chan...
void FlushAutoGenerated() const
Remove entries generated from NeighborCacheHelper from ARP cache and NDISC cache.
holds a vector of ns3::NetDevice pointers
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
keep track of a set of node pointers.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:67
build a set of SimpleNetDevice objects
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:561
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition simulator.h:578
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
@ QUICK
Fast test.
Definition test.h:1054
TestCase(const TestCase &)=delete
Type
Type of test.
Definition test.h:1257
@ UNIT
This test suite implements a Unit Test.
Definition test.h:1259
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:490
API to create UDP socket instances.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:439
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition test.h:133
#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:240
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1369
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition callback.h:684
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:585
static NeighborCacheTestSuite g_neighborcacheTestSuite
Static variable for test initialization.