A Discrete-Event Network Simulator
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
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: David Gross <gdavid.devel@gmail.com>
19  * Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
20  */
22 // Network topology
23 // //
24 // // n0 r n1
25 // // | _ |
26 // // ====|_|====
27 // // router
28 // //
29 // // - Tracing of queues and packet receptions to file "fragmentation-ipv6.tr"
31 #include <fstream>
32 #include "ns3/core-module.h"
33 #include "ns3/internet-module.h"
34 #include "ns3/csma-module.h"
35 #include "ns3/internet-apps-module.h"
36 #include "ns3/ipv6-static-routing-helper.h"
38 #include "ns3/ipv6-routing-table-entry.h"
40 using namespace ns3;
42 NS_LOG_COMPONENT_DEFINE ("FragmentationIpv6Example");
44 int main (int argc, char** argv)
45 {
46  bool verbose = false;
49  cmd.AddValue ("verbose", "turn on log components", verbose);
50  cmd.Parse (argc, argv);
52  if (verbose)
53  {
54  LogComponentEnable ("Ipv6L3Protocol", LOG_LEVEL_ALL);
55  LogComponentEnable ("Icmpv6L4Protocol", LOG_LEVEL_ALL);
56  LogComponentEnable ("Ipv6StaticRouting", LOG_LEVEL_ALL);
57  LogComponentEnable ("Ipv6Interface", LOG_LEVEL_ALL);
58  LogComponentEnable ("Ping6Application", LOG_LEVEL_ALL);
59  }
61  NS_LOG_INFO ("Create nodes.");
62  Ptr<Node> n0 = CreateObject<Node> ();
63  Ptr<Node> r = CreateObject<Node> ();
64  Ptr<Node> n1 = CreateObject<Node> ();
66  NodeContainer net1 (n0, r);
67  NodeContainer net2 (r, n1);
68  NodeContainer all (n0, r, n1);
70  NS_LOG_INFO ("Create IPv6 Internet Stack");
71  InternetStackHelper internetv6;
72  internetv6.Install (all);
74  NS_LOG_INFO ("Create channels.");
76  csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
77  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
78  NetDeviceContainer d1 = csma.Install (net1);
79  NetDeviceContainer d2 = csma.Install (net2);
81  NS_LOG_INFO ("Create networks and assign IPv6 Addresses.");
82  Ipv6AddressHelper ipv6;
83  ipv6.SetBase (Ipv6Address ("2001:1::"), Ipv6Prefix (64));
84  Ipv6InterfaceContainer i1 = ipv6.Assign (d1);
85  i1.SetForwarding (1, true);
87  ipv6.SetBase (Ipv6Address ("2001:2::"), Ipv6Prefix (64));
88  Ipv6InterfaceContainer i2 = ipv6.Assign (d2);
89  i2.SetForwarding (0, true);
92  Ipv6StaticRoutingHelper routingHelper;
93  Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> (&std::cout);
94  routingHelper.PrintRoutingTableAt (Seconds (0), n0, routingStream);
96  /* Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via r */
97  uint32_t packetSize = 4096;
98  uint32_t maxPacketCount = 5;
99  Time interPacketInterval = Seconds (1.0);
100  Ping6Helper ping6;
102  ping6.SetLocal (i1.GetAddress (0, 1));
103  ping6.SetRemote (i2.GetAddress (1, 1));
105  ping6.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
106  ping6.SetAttribute ("Interval", TimeValue (interPacketInterval));
107  ping6.SetAttribute ("PacketSize", UintegerValue (packetSize));
108  ApplicationContainer apps = ping6.Install (net1.Get (0));
109  apps.Start (Seconds (2.0));
110  apps.Stop (Seconds (20.0));
112  AsciiTraceHelper ascii;
113  csma.EnableAsciiAll (ascii.CreateFileStream ("fragmentation-ipv6.tr"));
114  csma.EnablePcapAll (std::string ("fragmentation-ipv6"), true);
116  NS_LOG_INFO ("Run Simulation.");
117  Simulator::Run ();
119  NS_LOG_INFO ("Done.");
120 }
holds a vector of ns3::Application pointers.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Manage ASCII trace files for device models.
Definition: trace-helper.h:161
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
Definition: csma-helper.cc:71
Keep track of a set of IPv6 interfaces.
void SetDefaultRouteInAllNodes(uint32_t router)
Set the default route for all the devices (except the router itself).
ApplicationContainer Install(NodeContainer c)
Install the application in Nodes.
Definition: ping6-helper.cc:50
static void Run(void)
Run the simulation.
Definition: simulator.cc:226
Define a Log component with a specific name.
Definition: log.h:201
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1001
aggregate IP/TCP/UDP functionality to existing Nodes.
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::CsmaChannel with the attributes configured by CsmaHelper::SetChannelAttri...
Definition: csma-helper.cc:217
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:277
void SetAttribute(std::string name, const AttributeValue &value)
Set some attributes.
Definition: ping6-helper.cc:45
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. ...
tuple cmd
Definition: second.py:35
void SetForwarding(uint32_t i, bool state)
Set the state of the stack (act as a router or as an host) for the specified index.
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:369
void EnablePcapAll(std::string prefix, bool promiscuous=false)
Enable pcap output on each device (which is of the appropriate type) in the set of all nodes created ...
void SetLocal(Ipv6Address ip)
Set the local IPv6 address.
Definition: ping6-helper.cc:35
AttributeValue implementation for Time.
Definition: nstime.h:1055
Hold an unsigned integer type.
Definition: uinteger.h:44
holds a vector of ns3::NetDevice pointers
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Parse command-line arguments.
Definition: command-line.h:205
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:190
static void PrintRoutingTableAt(Time printTime, Ptr< Node > node, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the routing tables of a node at a particular time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
Helper class that adds ns3::Ipv6StaticRouting objects.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
void SetRemote(Ipv6Address ip)
Set the remote IPv6 address.
Definition: ping6-helper.cc:40
build a set of CsmaNetDevice objects
Definition: csma-helper.h:46
Helper class to auto-assign global IPv6 unicast addresses.
Describes an IPv6 address.
Definition: ipv6-address.h:48
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
AttributeValue implementation for DataRate.
Definition: data-rate.h:242
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Definition: command-line.h:498
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:993
Describes an IPv6 prefix.
Definition: ipv6-address.h:394
Print everything.
Definition: log.h:112
void Parse(int argc, char *argv[])
Parse the program arguments.
void EnableAsciiAll(std::string prefix)
Enable ascii trace output on each device (which is of the appropriate type) in the set of all nodes c...
static const uint32_t packetSize
Ping6 application helper.
Definition: ping6-helper.h:38
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
bool verbose
tuple csma
Definition: second.py:63