A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
fragmentation-ipv6-two-MTU.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
* Copyright (c) 2013 Universita' di Firenze
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 2 as
8
* published by the Free Software Foundation;
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
*
19
* Author: David Gross <gdavid.devel@gmail.com>
20
* Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
21
* Modified by Tommaso Pecorella <tommaso.pecorella@unifi.it>
22
*/
23
24
// Network topology
25
// //
26
// // Src n0 r n1 Dst
27
// // | _ |
28
// // MTU ====|_|==== MTU
29
// // 5000 router 1500
30
// //
31
// // - Tracing of queues and packet receptions to file "fragmentation-ipv6-two-mtu.tr"
32
33
#include <fstream>
34
#include "ns3/core-module.h"
35
#include "ns3/internet-module.h"
36
#include "ns3/csma-module.h"
37
#include "ns3/applications-module.h"
38
#include "ns3/ipv6-static-routing-helper.h"
39
40
#include "ns3/ipv6-routing-table-entry.h"
41
42
using namespace
ns3;
43
44
NS_LOG_COMPONENT_DEFINE
(
"FragmentationIpv6TwoMtuExample"
);
45
46
int
main
(
int
argc,
char
** argv)
47
{
48
bool
verbose
=
false
;
49
50
CommandLine
cmd;
51
cmd.
AddValue
(
"verbose"
,
"turn on log components"
, verbose);
52
cmd.
Parse
(argc, argv);
53
54
if
(verbose)
55
{
56
LogComponentEnable
(
"Ipv6L3Protocol"
,
LOG_LEVEL_ALL
);
57
LogComponentEnable
(
"Icmpv6L4Protocol"
,
LOG_LEVEL_ALL
);
58
LogComponentEnable
(
"Ipv6StaticRouting"
,
LOG_LEVEL_ALL
);
59
LogComponentEnable
(
"Ipv6Interface"
,
LOG_LEVEL_ALL
);
60
LogComponentEnable
(
"Ping6Application"
,
LOG_LEVEL_ALL
);
61
}
62
63
NS_LOG_INFO
(
"Create nodes."
);
64
Ptr<Node>
n0 = CreateObject<Node> ();
65
Ptr<Node>
r = CreateObject<Node> ();
66
Ptr<Node>
n1 = CreateObject<Node> ();
67
68
NodeContainer
net1 (n0, r);
69
NodeContainer
net2 (r, n1);
70
NodeContainer
all (n0, r, n1);
71
72
NS_LOG_INFO
(
"Create IPv6 Internet Stack"
);
73
InternetStackHelper
internetv6;
74
internetv6.
Install
(all);
75
76
NS_LOG_INFO
(
"Create channels."
);
77
CsmaHelper
csma;
78
csma.
SetChannelAttribute
(
"DataRate"
,
DataRateValue
(5000000));
79
csma.
SetChannelAttribute
(
"Delay"
,
TimeValue
(MilliSeconds (2)));
80
NetDeviceContainer
d2 = csma.
Install
(net2);
81
csma.
SetDeviceAttribute
(
"Mtu"
,
UintegerValue
(5000));
82
NetDeviceContainer
d1 = csma.
Install
(net1);
83
84
NS_LOG_INFO
(
"Create networks and assign IPv6 Addresses."
);
85
Ipv6AddressHelper
ipv6;
86
ipv6.
SetBase
(
Ipv6Address
(
"2001:1::"
),
Ipv6Prefix
(64));
87
Ipv6InterfaceContainer
i1 = ipv6.
Assign
(d1);
88
i1.
SetForwarding
(1,
true
);
89
i1.
SetDefaultRouteInAllNodes
(1);
90
ipv6.
SetBase
(
Ipv6Address
(
"2001:2::"
),
Ipv6Prefix
(64));
91
Ipv6InterfaceContainer
i2 = ipv6.
Assign
(d2);
92
i2.
SetForwarding
(0,
true
);
93
i2.
SetDefaultRouteInAllNodes
(0);
94
95
Ipv6StaticRoutingHelper
routingHelper;
96
Ptr<OutputStreamWrapper>
routingStream = Create<OutputStreamWrapper> (&std::cout);
97
routingHelper.
PrintRoutingTableAt
(Seconds (0), n0, routingStream);
98
99
/* Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via r */
100
uint32_t packetSize = 4096;
101
uint32_t maxPacketCount = 5;
102
Time
interPacketInterval = Seconds (1.0);
103
Ping6Helper
ping6;
104
105
ping6.
SetLocal
(i1.
GetAddress
(0, 1));
106
ping6.
SetRemote
(i2.
GetAddress
(1, 1));
107
108
ping6.
SetAttribute
(
"MaxPackets"
,
UintegerValue
(maxPacketCount));
109
ping6.
SetAttribute
(
"Interval"
,
TimeValue
(interPacketInterval));
110
ping6.
SetAttribute
(
"PacketSize"
,
UintegerValue
(packetSize));
111
ApplicationContainer
apps = ping6.
Install
(net1.Get (0));
112
apps.
Start
(Seconds (2.0));
113
apps.
Stop
(Seconds (20.0));
114
115
AsciiTraceHelper
ascii;
116
csma.
EnableAsciiAll
(ascii.
CreateFileStream
(
"fragmentation-ipv6-two-mtu.tr"
));
117
csma.
EnablePcapAll
(std::string (
"fragmentation-ipv6-two-mtu"
),
true
);
118
119
NS_LOG_INFO
(
"Run Simulation."
);
120
Simulator::Run
();
121
Simulator::Destroy
();
122
NS_LOG_INFO
(
"Done."
);
123
}
124
examples
ipv6
fragmentation-ipv6-two-MTU.cc
Generated on Fri Aug 30 2013 01:42:44 for ns-3 by
1.8.1.2