A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ping6-example.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008-2009 Strasbourg University
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
7 */
8
9// Network topology
10//
11// n0 n1
12// | |
13// =================
14// LAN
15//
16// - ICMPv6 echo request flows from n0 to n1 and back with ICMPv6 echo reply
17// - DropTail queues
18// - Tracing of queues and packet receptions to file "ping6.tr"
19
20#include "ns3/core-module.h"
21#include "ns3/csma-module.h"
22#include "ns3/internet-apps-module.h"
23#include "ns3/internet-module.h"
24
25#include <fstream>
26
27using namespace ns3;
28
29NS_LOG_COMPONENT_DEFINE("Ping6Example");
30
31int
32main(int argc, char** argv)
33{
34 bool verbose = false;
35 bool allNodes = false;
36
37 CommandLine cmd(__FILE__);
38 cmd.AddValue("verbose", "turn on log components", verbose);
39 cmd.AddValue("allNodes", "Ping all the nodes (true) or just one neighbor (false)", allNodes);
40 cmd.Parse(argc, argv);
41
42 if (verbose)
43 {
44 LogComponentEnable("Ping6Example", LOG_LEVEL_INFO);
45 LogComponentEnable("Ipv6EndPointDemux", LOG_LEVEL_ALL);
46 LogComponentEnable("Ipv6L3Protocol", LOG_LEVEL_ALL);
47 LogComponentEnable("Ipv6StaticRouting", LOG_LEVEL_ALL);
48 LogComponentEnable("Ipv6ListRouting", LOG_LEVEL_ALL);
49 LogComponentEnable("Ipv6Interface", LOG_LEVEL_ALL);
50 LogComponentEnable("Icmpv6L4Protocol", LOG_LEVEL_ALL);
52 LogComponentEnable("NdiscCache", LOG_LEVEL_ALL);
53 }
54
55 NS_LOG_INFO("Create nodes.");
57 n.Create(4);
58
59 /* Install IPv4/IPv6 stack */
60 InternetStackHelper internetv6;
61 internetv6.SetIpv4StackInstall(false);
62 internetv6.Install(n);
63
64 NS_LOG_INFO("Create channels.");
66 csma.SetChannelAttribute("DataRate", DataRateValue(5000000));
67 csma.SetChannelAttribute("Delay", TimeValue(MilliSeconds(2)));
68 NetDeviceContainer d = csma.Install(n);
69
71 NS_LOG_INFO("Assign IPv6 Addresses.");
73
74 NS_LOG_INFO("Create Applications.");
75
76 // Create a Ping application to send ICMPv6 echo request from node zero
77 uint32_t packetSize = 1024;
78 uint32_t maxPacketCount = 5;
79
80 Ipv6Address destination = allNodes ? Ipv6Address::GetAllNodesMulticast() : i.GetAddress(1, 0);
81 PingHelper ping(destination);
82
83 ping.SetAttribute("Count", UintegerValue(maxPacketCount));
84 ping.SetAttribute("Size", UintegerValue(packetSize));
85 ping.SetAttribute("InterfaceAddress", AddressValue(i.GetAddress(0, 0)));
86
87 ApplicationContainer apps = ping.Install(n.Get(0));
88 apps.Start(Seconds(2.0));
89 apps.Stop(Seconds(10.0));
90
91 AsciiTraceHelper ascii;
92 csma.EnableAsciiAll(ascii.CreateFileStream("ping6.tr"));
93 csma.EnablePcapAll(std::string("ping6"), true);
94
95 NS_LOG_INFO("Run Simulation.");
98 NS_LOG_INFO("Done.");
99
100 return 0;
101}
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Manage ASCII trace files for device models.
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we'll use to write the traced bits.
Parse command-line arguments.
build a set of CsmaNetDevice objects
Definition csma-helper.h:37
aggregate IP/TCP/UDP functionality to existing Nodes.
void SetIpv4StackInstall(bool enable)
Enable/disable IPv4 stack install.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
Helper class to auto-assign global IPv6 unicast addresses.
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
Describes an IPv6 address.
static Ipv6Address GetAllNodesMulticast()
Get the "all nodes multicast" address.
Keep track of a set of IPv6 interfaces.
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Create a ping application and associate it to a node.
Definition ping-helper.h:31
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
Hold an unsigned integer type.
Definition uinteger.h:34
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1320
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
Definition log.cc:291
@ LOG_LEVEL_ALL
Print everything.
Definition log.h:105
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition log.h:93
bool verbose
static const uint32_t packetSize
Packet size generated at the AP.