A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
fragmentation-ipv6-two-MTU.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008-2009 Strasbourg University
3 * Copyright (c) 2013 Universita' di Firenze
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Author: David Gross <gdavid.devel@gmail.com>
8 * Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
9 * Modified by Tommaso Pecorella <tommaso.pecorella@unifi.it>
10 */
11
12// Network topology
13// //
14// // Src n0 r n1 Dst
15// // | _ |
16// // MTU ====|_|==== MTU
17// // 5000 router 1500
18// //
19// // - Tracing of queues and packet receptions to file "fragmentation-ipv6-two-mtu.tr"
20
21#include "ns3/applications-module.h"
22#include "ns3/core-module.h"
23#include "ns3/csma-module.h"
24#include "ns3/internet-module.h"
25#include "ns3/ipv6-routing-table-entry.h"
26#include "ns3/ipv6-static-routing-helper.h"
27
28#include <fstream>
29
30using namespace ns3;
31
32NS_LOG_COMPONENT_DEFINE("FragmentationIpv6TwoMtuExample");
33
34int
35main(int argc, char** argv)
36{
37 bool verbose = false;
38
39 CommandLine cmd(__FILE__);
40 cmd.AddValue("verbose", "turn on log components", verbose);
41 cmd.Parse(argc, argv);
42
43 if (verbose)
44 {
45 LogComponentEnable("Ipv6L3Protocol", LOG_LEVEL_ALL);
46 LogComponentEnable("Icmpv6L4Protocol", LOG_LEVEL_ALL);
47 LogComponentEnable("Ipv6StaticRouting", LOG_LEVEL_ALL);
48 LogComponentEnable("Ipv6Interface", LOG_LEVEL_ALL);
49 LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
50 LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
51 }
52 LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
53
54 NS_LOG_INFO("Create nodes.");
58
59 NodeContainer net1(n0, r);
60 NodeContainer net2(r, n1);
61 NodeContainer all(n0, r, n1);
62
63 NS_LOG_INFO("Create IPv6 Internet Stack");
64 InternetStackHelper internetv6;
65 internetv6.Install(all);
66
67 NS_LOG_INFO("Create channels.");
69 csma.SetChannelAttribute("DataRate", DataRateValue(5000000));
70 csma.SetChannelAttribute("Delay", TimeValue(MilliSeconds(2)));
71 NetDeviceContainer d2 = csma.Install(net2);
72 csma.SetDeviceAttribute("Mtu", UintegerValue(5000));
73 NetDeviceContainer d1 = csma.Install(net1);
74
75 NS_LOG_INFO("Create networks and assign IPv6 Addresses.");
77 ipv6.SetBase(Ipv6Address("2001:1::"), Ipv6Prefix(64));
78 Ipv6InterfaceContainer i1 = ipv6.Assign(d1);
79 i1.SetForwarding(1, true);
81 ipv6.SetBase(Ipv6Address("2001:2::"), Ipv6Prefix(64));
82 Ipv6InterfaceContainer i2 = ipv6.Assign(d2);
83 i2.SetForwarding(0, true);
85
86 Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper>(&std::cout);
88
89 /* Create a UdpEchoClient and UdpEchoServer application to send packets from n0 to n1 via r */
90 uint32_t packetSize = 4096;
91 uint32_t maxPacketCount = 5;
92
94 echoClient.SetAttribute("PacketSize", UintegerValue(packetSize));
95 echoClient.SetAttribute("MaxPackets", UintegerValue(maxPacketCount));
96 ApplicationContainer clientApps = echoClient.Install(net1.Get(0));
97 clientApps.Start(Seconds(2.0));
98 clientApps.Stop(Seconds(20.0));
99
101 ApplicationContainer serverApps = echoServer.Install(net2.Get(1));
102 serverApps.Start(Seconds(0.0));
103 serverApps.Stop(Seconds(30.0));
104
105 AsciiTraceHelper ascii;
106 csma.EnableAsciiAll(ascii.CreateFileStream("fragmentation-ipv6-two-mtu.tr"));
107 csma.EnablePcapAll(std::string("fragmentation-ipv6-two-mtu"), true);
108
109 NS_LOG_INFO("Run Simulation.");
112 NS_LOG_INFO("Done.");
113
114 return 0;
115}
holds a vector of ns3::Application pointers.
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 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.
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.
Keep track of a set of IPv6 interfaces.
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.
void SetDefaultRouteInAllNodes(uint32_t router)
Set the default route for all the devices (except the router itself).
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
Describes an IPv6 prefix.
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.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
Create an application which sends a UDP packet and waits for an echo of this packet.
Create a server application which waits for input UDP packets and sends them back to the original sen...
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
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:436
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
echoClient
Definition first.py:48
serverApps
Definition first.py:43
echoServer
Definition first.py:41
clientApps
Definition first.py:53
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.