author | Mirko Banchi <mk.banchi@gmail.com> |
Fri, 24 Apr 2009 09:07:00 +0200 | |
changeset 4401 | 427cec7079f3 |
parent 4283 | 5854cddf4493 |
child 4610 | 48dddd9d79ee |
permissions | -rw-r--r-- |
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
2 |
/* |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
3 |
* This program is free software; you can redistribute it and/or modify |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
4 |
* it under the terms of the GNU General Public License version 2 as |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
5 |
* published by the Free Software Foundation; |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
6 |
* |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
7 |
* This program is distributed in the hope that it will be useful, |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
10 |
* GNU General Public License for more details. |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
11 |
* |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
12 |
* You should have received a copy of the GNU General Public License |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
13 |
* along with this program; if not, write to the Free Software |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
15 |
* |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
16 |
*/ |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
17 |
|
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
18 |
// |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
19 |
// Network topology |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
20 |
// |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
21 |
// 10Mb/s, 10ms 10Mb/s, 10ms |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
22 |
// n0-----------------n1-----------------n2 |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
23 |
// |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
24 |
// |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
25 |
// - Tracing of queues and packet receptions to file |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
26 |
// "tcp-large-transfer.tr" |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
27 |
// - pcap traces also generated in the following files |
3294 | 28 |
// "tcp-large-transfer-$n-$i.pcap" where n and i represent node and interface |
29 |
// numbers respectively |
|
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
30 |
// Usage (e.g.): ./waf --run tcp-large-transfer |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
31 |
|
3240
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
32 |
|
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
33 |
#include <ctype.h> |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
34 |
#include <iostream> |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
35 |
#include <fstream> |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
36 |
#include <string> |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
37 |
#include <cassert> |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
38 |
|
2746
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
39 |
#include "ns3/core-module.h" |
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
40 |
#include "ns3/helper-module.h" |
2753
1f03a5531746
fallout from gustavo's header inclusion policy change.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2749
diff
changeset
|
41 |
#include "ns3/node-module.h" |
1f03a5531746
fallout from gustavo's header inclusion policy change.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2749
diff
changeset
|
42 |
#include "ns3/global-route-manager.h" |
1f03a5531746
fallout from gustavo's header inclusion policy change.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2749
diff
changeset
|
43 |
#include "ns3/simulator-module.h" |
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
44 |
|
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
45 |
using namespace ns3; |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
46 |
|
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
47 |
NS_LOG_COMPONENT_DEFINE ("TcpLargeTransfer"); |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
48 |
|
3294 | 49 |
// The number of bytes to send in this simulation. |
50 |
static uint32_t txBytes = 2000000; |
|
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
51 |
|
3294 | 52 |
// These are for starting the writing process, and handling the sending |
53 |
// socket's notification upcalls (events). These two together more or less |
|
54 |
// implement a sending "Application", although not a proper ns3::Application |
|
55 |
// subclass. |
|
56 |
||
57 |
void StartFlow(Ptr<Socket>, Ipv4Address, uint16_t); |
|
3240
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
58 |
void WriteUntilBufferFull (Ptr<Socket>, uint32_t); |
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
59 |
|
4283
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
4264
diff
changeset
|
60 |
static void |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
4264
diff
changeset
|
61 |
CwndTracer (uint32_t oldval, uint32_t newval) |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
4264
diff
changeset
|
62 |
{ |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
4264
diff
changeset
|
63 |
NS_LOG_INFO ("Moving cwnd from " << oldval << " to " << newval); |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
4264
diff
changeset
|
64 |
} |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
4264
diff
changeset
|
65 |
|
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
66 |
int main (int argc, char *argv[]) |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
67 |
{ |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
68 |
// Users may find it convenient to turn on explicit debugging |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
69 |
// for selected modules; the below lines suggest how to do this |
2746
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
70 |
// LogComponentEnable("TcpL4Protocol", LOG_LEVEL_ALL); |
3276
8869a79a391f
Changes for bug 205, unlisted FIN bug
Craig Dowell <craigdo@ee.washington.edu>
parents:
3269
diff
changeset
|
71 |
// LogComponentEnable("TcpSocketImpl", LOG_LEVEL_ALL); |
2746
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
72 |
// LogComponentEnable("PacketSink", LOG_LEVEL_ALL); |
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
73 |
// LogComponentEnable("TcpLargeTransfer", LOG_LEVEL_ALL); |
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
74 |
|
2575
1aae382e65e2
rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2540
diff
changeset
|
75 |
CommandLine cmd; |
1aae382e65e2
rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2540
diff
changeset
|
76 |
cmd.Parse (argc, argv); |
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
77 |
|
3294 | 78 |
// Here, we will explicitly create three nodes. The first container contains |
79 |
// nodes 0 and 1 from the diagram above, and the second one contains nodes |
|
80 |
// 1 and 2. This reflects the channel connectivity, and will be used to |
|
81 |
// install the network interfaces and connect them with a channel. |
|
82 |
NodeContainer n0n1; |
|
83 |
n0n1.Create (2); |
|
2746
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
84 |
|
3294 | 85 |
NodeContainer n1n2; |
86 |
n1n2.Add (n0n1.Get (1)); |
|
87 |
n1n2.Create (1); |
|
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
88 |
|
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
89 |
// We create the channels first without any IP addressing information |
3294 | 90 |
// First make and configure the helper, so that it will put the appropriate |
3381
3cdd9d60f7c7
bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents:
3294
diff
changeset
|
91 |
// attributes on the network interfaces and channels we are about to install. |
2746
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
92 |
PointToPointHelper p2p; |
3381
3cdd9d60f7c7
bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents:
3294
diff
changeset
|
93 |
p2p.SetDeviceAttribute ("DataRate", DataRateValue (DataRate(10000000))); |
3cdd9d60f7c7
bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents:
3294
diff
changeset
|
94 |
p2p.SetChannelAttribute ("Delay", TimeValue (MilliSeconds(10))); |
3294 | 95 |
|
96 |
// And then install devices and channels connecting our topology. |
|
97 |
NetDeviceContainer dev0 = p2p.Install (n0n1); |
|
98 |
NetDeviceContainer dev1 = p2p.Install (n1n2); |
|
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
99 |
|
3294 | 100 |
// Now add ip/tcp stack to all nodes. |
101 |
NodeContainer allNodes = NodeContainer (n0n1, n1n2.Get (1)); |
|
2746
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
102 |
InternetStackHelper internet; |
3294 | 103 |
internet.Install (allNodes); |
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
104 |
|
3294 | 105 |
// Later, we add IP addresses. |
2746
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
106 |
Ipv4AddressHelper ipv4; |
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
107 |
ipv4.SetBase ("10.1.3.0", "255.255.255.0"); |
2888
872dc8466352
Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2887
diff
changeset
|
108 |
ipv4.Assign (dev0); |
2746
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
109 |
ipv4.SetBase ("10.1.2.0", "255.255.255.0"); |
2888
872dc8466352
Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2887
diff
changeset
|
110 |
Ipv4InterfaceContainer ipInterfs = ipv4.Assign (dev1); |
2746
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
111 |
|
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
112 |
// and setup ip routing tables to get total ip-level connectivity. |
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
113 |
GlobalRouteManager::PopulateRoutingTables (); |
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
114 |
|
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
115 |
/////////////////////////////////////////////////////////////////////////// |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
116 |
// Simulation 1 |
3294 | 117 |
// |
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
118 |
// Send 2000000 bytes over a connection to server port 50000 at time 0 |
3294 | 119 |
// Should observe SYN exchange, a lot of data segments and ACKS, and FIN |
120 |
// exchange. FIN exchange isn't quite compliant with TCP spec (see release |
|
121 |
// notes for more info) |
|
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
122 |
// |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
123 |
/////////////////////////////////////////////////////////////////////////// |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
124 |
|
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
125 |
uint16_t servPort = 50000; |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
126 |
|
3294 | 127 |
// Create a packet sink to receive these packets on n2... |
3132
b0b0abb911cd
move Tcp to TcpSocketFactory
Tom Henderson <tomh@tomh.org>
parents:
3116
diff
changeset
|
128 |
PacketSinkHelper sink ("ns3::TcpSocketFactory", |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2890
diff
changeset
|
129 |
InetSocketAddress (Ipv4Address::GetAny (), servPort)); |
2890
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2889
diff
changeset
|
130 |
|
3294 | 131 |
ApplicationContainer apps = sink.Install (n1n2.Get (1)); |
2746
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
132 |
apps.Start (Seconds (0.0)); |
3643
7afa66c2b291
Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3381
diff
changeset
|
133 |
apps.Stop (Seconds (3.0)); |
2746
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
134 |
|
3294 | 135 |
// Create a source to send packets from n0. Instead of a full Application |
136 |
// and the helper APIs you might see in other example files, this example |
|
137 |
// will use sockets directly and register some socket callbacks as a sending |
|
138 |
// "Application". |
|
139 |
||
140 |
// Create and bind the socket... |
|
141 |
Ptr<Socket> localSocket = |
|
142 |
Socket::CreateSocket (n0n1.Get (0), TcpSocketFactory::GetTypeId ()); |
|
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
143 |
localSocket->Bind (); |
3294 | 144 |
|
4283
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
4264
diff
changeset
|
145 |
// Trace changes to the congestion window |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
4264
diff
changeset
|
146 |
Config::ConnectWithoutContext ("/NodeList/0/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow", MakeCallback (&CwndTracer)); |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
4264
diff
changeset
|
147 |
|
3294 | 148 |
// ...and schedule the sending "Application"; This is similar to what an |
149 |
// ns3::Application subclass would do internally. |
|
150 |
Simulator::ScheduleNow (&StartFlow, localSocket, |
|
2749
0aa031496023
use Ipv4InterfaceContainer to avoid hardcoding ip addresses.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2746
diff
changeset
|
151 |
ipInterfs.GetAddress (1), servPort); |
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
152 |
|
3294 | 153 |
// One can toggle the comment for the following line on or off to see the |
154 |
// effects of finite send buffer modelling. One can also change the size of |
|
155 |
// said buffer. |
|
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
156 |
|
3294 | 157 |
//localSocket->SetAttribute("SndBufSize", UintegerValue(4096)); |
158 |
||
159 |
//Ask for ASCII and pcap traces of network traffic |
|
2789
47e92324cf4b
configure tracing post-topology construction, not before.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2788
diff
changeset
|
160 |
std::ofstream ascii; |
47e92324cf4b
configure tracing post-topology construction, not before.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2788
diff
changeset
|
161 |
ascii.open ("tcp-large-transfer.tr"); |
2996
a83b94e277d4
EnablePcap()->EnablePcapAll(); EnableAscii()->EnableAsciiAll()
Tom Henderson <tomh@tomh.org>
parents:
2890
diff
changeset
|
162 |
PointToPointHelper::EnableAsciiAll (ascii); |
3012 | 163 |
PointToPointHelper::EnablePcapAll ("tcp-large-transfer"); |
2789
47e92324cf4b
configure tracing post-topology construction, not before.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2788
diff
changeset
|
164 |
|
3294 | 165 |
// Finally, set up the simulator to run. The 1000 second hard limit is a |
166 |
// failsafe in case some change above causes the simulation to never end |
|
3174
efeb6e5c276d
Make Application::Start/Stop times relative, Simulator::StopAt(time) renamed to Simulator::Stop(time) and time also made relative, to improve consistency of the API which uses relative times everywhere else. Closes bug #191.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3132
diff
changeset
|
167 |
Simulator::Stop (Seconds(1000)); |
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
168 |
Simulator::Run (); |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
169 |
Simulator::Destroy (); |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
170 |
} |
3240
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
171 |
|
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
172 |
|
3294 | 173 |
//----------------------------------------------------------------------------- |
174 |
//----------------------------------------------------------------------------- |
|
175 |
//----------------------------------------------------------------------------- |
|
176 |
//begin implementation of sending "Application" |
|
177 |
void StartFlow(Ptr<Socket> localSocket, |
|
3240
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
178 |
Ipv4Address servAddress, |
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
179 |
uint16_t servPort) |
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
180 |
{ |
3294 | 181 |
NS_LOG_LOGIC("Starting flow at time " << Simulator::Now ().GetSeconds ()); |
3240
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
182 |
localSocket->Connect (InetSocketAddress (servAddress, servPort));//connect |
3294 | 183 |
|
184 |
// tell the tcp implementation to call WriteUntilBufferFull again |
|
185 |
// if we blocked and new tx buffer space becomes available |
|
3240
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
186 |
localSocket->SetSendCallback (MakeCallback (&WriteUntilBufferFull)); |
3294 | 187 |
WriteUntilBufferFull (localSocket, txBytes); |
3240
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
188 |
} |
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
189 |
|
3294 | 190 |
void WriteUntilBufferFull (Ptr<Socket> localSocket, uint32_t txSpace) |
3240
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
191 |
{ |
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
192 |
// Perform series of 1040 byte writes (this is a multiple of 26 since |
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
193 |
// we want to detect data splicing in the output stream) |
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
194 |
uint32_t writeSize = 1040; |
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
195 |
uint8_t data[writeSize]; |
3294 | 196 |
|
197 |
while (txBytes > 0) { |
|
198 |
uint32_t curSize= txBytes > writeSize ? writeSize : txBytes; |
|
199 |
if (curSize > txSpace) |
|
200 |
curSize = txSpace; |
|
3240
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
201 |
for(uint32_t i = 0; i < curSize; ++i) |
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
202 |
{ |
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
203 |
char m = toascii (97 + i % 26); |
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
204 |
data[i] = m; |
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
205 |
} |
3294 | 206 |
int amountSent = localSocket->Send (data, curSize, 0); |
207 |
if(amountSent < 0) |
|
3241
284705f0775f
Use the correct semantics for sendcallback
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3240
diff
changeset
|
208 |
{ |
3294 | 209 |
// we will be called again when new tx space becomes available. |
210 |
std::cout << "Socket blocking, " << txBytes << " left to write, returning" << std::endl; |
|
3241
284705f0775f
Use the correct semantics for sendcallback
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3240
diff
changeset
|
211 |
return; |
284705f0775f
Use the correct semantics for sendcallback
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3240
diff
changeset
|
212 |
} |
3294 | 213 |
txBytes -= curSize; |
214 |
if (amountSent != (int)curSize) |
|
215 |
{ |
|
216 |
std::cout << "Short Write, returning" << std::endl; |
|
217 |
return; |
|
218 |
} |
|
3240
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
219 |
} |
3294 | 220 |
localSocket->Close (); |
3240
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
221 |
} |