A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ping6.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008-2009 Strasbourg University
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
19  */
20 
21 // Network topology
22 //
23 // n0 n1
24 // | |
25 // =================
26 // LAN
27 //
28 // - ICMPv6 echo request flows from n0 to n1 and back with ICMPv6 echo reply
29 // - DropTail queues
30 // - Tracing of queues and packet receptions to file "ping6.tr"
31 
32 #include <fstream>
33 #include "ns3/core-module.h"
34 #include "ns3/internet-module.h"
35 #include "ns3/csma-module.h"
36 #include "ns3/applications-module.h"
37 
38 using namespace ns3;
39 
40 NS_LOG_COMPONENT_DEFINE ("Ping6Example");
41 
42 int main (int argc, char **argv)
43 {
44  bool verbose = false;
45 
46  CommandLine cmd;
47  cmd.AddValue ("verbose", "turn on log components", verbose);
48  cmd.Parse (argc, argv);
49 
50  if (verbose)
51  {
52  LogComponentEnable ("Ping6Example", LOG_LEVEL_INFO);
53  LogComponentEnable ("Ipv6EndPointDemux", LOG_LEVEL_ALL);
54  LogComponentEnable ("Ipv6L3Protocol", LOG_LEVEL_ALL);
55  LogComponentEnable ("Ipv6StaticRouting", LOG_LEVEL_ALL);
56  LogComponentEnable ("Ipv6ListRouting", LOG_LEVEL_ALL);
57  LogComponentEnable ("Ipv6Interface", LOG_LEVEL_ALL);
58  LogComponentEnable ("Icmpv6L4Protocol", LOG_LEVEL_ALL);
59  LogComponentEnable ("Ping6Application", LOG_LEVEL_ALL);
60  LogComponentEnable ("NdiscCache", LOG_LEVEL_ALL);
61  }
62 
63  NS_LOG_INFO ("Create nodes.");
64  NodeContainer n;
65  n.Create (4);
66 
67  /* Install IPv4/IPv6 stack */
68  InternetStackHelper internetv6;
69  internetv6.SetIpv4StackInstall (false);
70  internetv6.Install (n);
71 
72  NS_LOG_INFO ("Create channels.");
73  CsmaHelper csma;
74  csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
75  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
76  NetDeviceContainer d = csma.Install (n);
77 
78  Ipv6AddressHelper ipv6;
79  NS_LOG_INFO ("Assign IPv6 Addresses.");
80  Ipv6InterfaceContainer i = ipv6.Assign (d);
81 
82  NS_LOG_INFO ("Create Applications.");
83 
84  /* Create a Ping6 application to send ICMPv6 echo request from node zero to
85  * all-nodes (ff02::1).
86  */
87  uint32_t packetSize = 1024;
88  uint32_t maxPacketCount = 5;
89  Time interPacketInterval = Seconds (1.);
90  Ping6Helper ping6;
91 
92  /*
93  ping6.SetLocal (i.GetAddress (0, 1));
94  ping6.SetRemote (i.GetAddress (1, 1));
95  */
96  ping6.SetIfIndex (i.GetInterfaceIndex (0));
98 
99  ping6.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
100  ping6.SetAttribute ("Interval", TimeValue (interPacketInterval));
101  ping6.SetAttribute ("PacketSize", UintegerValue (packetSize));
102  ApplicationContainer apps = ping6.Install (n.Get (0));
103  apps.Start (Seconds (2.0));
104  apps.Stop (Seconds (10.0));
105 
106  AsciiTraceHelper ascii;
107  csma.EnableAsciiAll (ascii.CreateFileStream ("ping6.tr"));
108  csma.EnablePcapAll (std::string ("ping6"), true);
109 
110  NS_LOG_INFO ("Run Simulation.");
111  Simulator::Run ();
113  NS_LOG_INFO ("Done.");
114 }
115