A Discrete-Event Network Simulator
API
ping6.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008-2009 Strasbourg University
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: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
18 */
19
20// Network topology
21//
22// n0 n1
23// | |
24// =================
25// LAN
26//
27// - ICMPv6 echo request flows from n0 to n1 and back with ICMPv6 echo reply
28// - DropTail queues
29// - Tracing of queues and packet receptions to file "ping6.tr"
30
31#include "ns3/core-module.h"
32#include "ns3/csma-module.h"
33#include "ns3/internet-apps-module.h"
34#include "ns3/internet-module.h"
35
36#include <fstream>
37
38using namespace ns3;
39
40NS_LOG_COMPONENT_DEFINE("Ping6Example");
41
42int
43main(int argc, char** argv)
44{
45 bool verbose = false;
46
47 CommandLine cmd(__FILE__);
48 cmd.AddValue("verbose", "turn on log components", verbose);
49 cmd.Parse(argc, argv);
50
51 if (verbose)
52 {
53 LogComponentEnable("Ping6Example", LOG_LEVEL_INFO);
54 LogComponentEnable("Ipv6EndPointDemux", LOG_LEVEL_ALL);
55 LogComponentEnable("Ipv6L3Protocol", LOG_LEVEL_ALL);
56 LogComponentEnable("Ipv6StaticRouting", LOG_LEVEL_ALL);
57 LogComponentEnable("Ipv6ListRouting", LOG_LEVEL_ALL);
58 LogComponentEnable("Ipv6Interface", LOG_LEVEL_ALL);
59 LogComponentEnable("Icmpv6L4Protocol", LOG_LEVEL_ALL);
60 LogComponentEnable("Ping6Application", LOG_LEVEL_ALL);
61 LogComponentEnable("NdiscCache", LOG_LEVEL_ALL);
62 }
63
64 NS_LOG_INFO("Create nodes.");
66 n.Create(4);
67
68 /* Install IPv4/IPv6 stack */
69 InternetStackHelper internetv6;
70 internetv6.SetIpv4StackInstall(false);
71 internetv6.Install(n);
72
73 NS_LOG_INFO("Create channels.");
75 csma.SetChannelAttribute("DataRate", DataRateValue(5000000));
76 csma.SetChannelAttribute("Delay", TimeValue(MilliSeconds(2)));
77 NetDeviceContainer d = csma.Install(n);
78
80 NS_LOG_INFO("Assign IPv6 Addresses.");
82
83 NS_LOG_INFO("Create Applications.");
84
85 /* Create a Ping6 application to send ICMPv6 echo request from node zero to
86 * all-nodes (ff02::1).
87 */
88 uint32_t packetSize = 1024;
89 uint32_t maxPacketCount = 5;
90 Time interPacketInterval = Seconds(1.);
91 Ping6Helper ping6;
92
93 /*
94 ping6.SetLocal (i.GetAddress (0, 1));
95 ping6.SetRemote (i.GetAddress (1, 1));
96 */
97 ping6.SetIfIndex(i.GetInterfaceIndex(0));
98 ping6.SetRemote(Ipv6Address::GetAllNodesMulticast());
99
100 ping6.SetAttribute("MaxPackets", UintegerValue(maxPacketCount));
101 ping6.SetAttribute("Interval", TimeValue(interPacketInterval));
102 ping6.SetAttribute("PacketSize", UintegerValue(packetSize));
103 ApplicationContainer apps = ping6.Install(n.Get(0));
104 apps.Start(Seconds(2.0));
105 apps.Stop(Seconds(10.0));
106
107 AsciiTraceHelper ascii;
108 csma.EnableAsciiAll(ascii.CreateFileStream("ping6.tr"));
109 csma.EnablePcapAll(std::string("ping6"), true);
110
111 NS_LOG_INFO("Run Simulation.");
112 Simulator::Run();
113 Simulator::Destroy();
114 NS_LOG_INFO("Done.");
115
116 return 0;
117}
holds a vector of ns3::Application pointers.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
void Stop(Time stop)
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.
Definition: trace-helper.h:173
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.
Definition: command-line.h:232
build a set of CsmaNetDevice objects
Definition: csma-helper.h:48
AttributeValue implementation for DataRate.
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.
Keep track of a set of IPv6 interfaces.
uint32_t GetInterfaceIndex(uint32_t i) const
Get the interface index for the specified node 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.
Ping6 application helper.
Definition: ping6-helper.h:38
void SetRemote(Ipv6Address ip)
Set the remote IPv6 address.
Definition: ping6-helper.cc:41
ApplicationContainer Install(NodeContainer c)
Install the application in Nodes.
Definition: ping6-helper.cc:53
void SetAttribute(std::string name, const AttributeValue &value)
Set some attributes.
Definition: ping6-helper.cc:47
void SetIfIndex(uint32_t ifIndex)
Set the out interface index.
Definition: ping6-helper.cc:71
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
AttributeValue implementation for Time.
Definition: nstime.h:1425
Hold an unsigned integer type.
Definition: uinteger.h:45
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1350
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ LOG_LEVEL_ALL
Print everything.
Definition: log.h:116
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition: log.h:107
void LogComponentEnable(const char *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:358
csma
Definition: second.py:56
cmd
Definition: second.py:33
bool verbose
static const uint32_t packetSize
Packet size generated at the AP.