author | Lalith Suresh <suresh.lalith@gmail.com> |
Thu, 03 Mar 2011 19:54:57 +0000 | |
changeset 6848 | 1f453ad50ef3 |
parent 6847 | 138f00c56381 |
child 6865 | 220373544a6c |
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" |
6847
138f00c56381
Move applications to a single module
Mitch Watrous <watrous@u.washington.edu>
parents:
6834
diff
changeset
|
41 |
#include "ns3/applications-module.h" |
6823
a27f86fb4e55
Merge node and common modules into new network module
Tom Henderson <tomh@tomh.org>
parents:
6821
diff
changeset
|
42 |
#include "ns3/network-module.h" |
6834
036f9a0b9899
Rename internet-stack to internet, and organize module
Tom Henderson <tomh@tomh.org>
parents:
6823
diff
changeset
|
43 |
#include "ns3/internet-module.h" |
6848
1f453ad50ef3
Converts csma, emu, tap-bridge, point-to-point, wifi and wimax modules into modular format
Lalith Suresh <suresh.lalith@gmail.com>
parents:
6847
diff
changeset
|
44 |
#include "ns3/point-to-point-module.h" |
6649
f5413d463948
Missing ipv4-global-routing-helper.h include
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6014
diff
changeset
|
45 |
#include "ns3/ipv4-global-routing-helper.h" |
2224
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 |
using namespace ns3; |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
48 |
|
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
49 |
NS_LOG_COMPONENT_DEFINE ("TcpLargeTransfer"); |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
50 |
|
4610
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
51 |
|
3294 | 52 |
// The number of bytes to send in this simulation. |
4610
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
53 |
static const uint32_t totalTxBytes = 2000000; |
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
54 |
static uint32_t currentTxBytes = 0; |
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
55 |
// Perform series of 1040 byte writes (this is a multiple of 26 since |
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
56 |
// we want to detect data splicing in the output stream) |
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
57 |
static const uint32_t writeSize = 1040; |
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
58 |
uint8_t data[writeSize]; |
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
59 |
|
3294 | 60 |
// These are for starting the writing process, and handling the sending |
61 |
// socket's notification upcalls (events). These two together more or less |
|
62 |
// implement a sending "Application", although not a proper ns3::Application |
|
63 |
// subclass. |
|
64 |
||
65 |
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
|
66 |
void WriteUntilBufferFull (Ptr<Socket>, uint32_t); |
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
67 |
|
4283
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
4264
diff
changeset
|
68 |
static void |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
4264
diff
changeset
|
69 |
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
|
70 |
{ |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
4264
diff
changeset
|
71 |
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
|
72 |
} |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
4264
diff
changeset
|
73 |
|
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
74 |
int main (int argc, char *argv[]) |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
75 |
{ |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
76 |
// 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
|
77 |
// 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
|
78 |
// LogComponentEnable("TcpL4Protocol", LOG_LEVEL_ALL); |
3276
8869a79a391f
Changes for bug 205, unlisted FIN bug
Craig Dowell <craigdo@ee.washington.edu>
parents:
3269
diff
changeset
|
79 |
// LogComponentEnable("TcpSocketImpl", LOG_LEVEL_ALL); |
2746
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
80 |
// LogComponentEnable("PacketSink", LOG_LEVEL_ALL); |
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
81 |
// LogComponentEnable("TcpLargeTransfer", LOG_LEVEL_ALL); |
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
82 |
|
2575
1aae382e65e2
rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2540
diff
changeset
|
83 |
CommandLine cmd; |
1aae382e65e2
rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2540
diff
changeset
|
84 |
cmd.Parse (argc, argv); |
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
85 |
|
4610
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
86 |
// initialize the tx buffer. |
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
87 |
for(uint32_t i = 0; i < writeSize; ++i) |
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
88 |
{ |
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
89 |
char m = toascii (97 + i % 26); |
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
90 |
data[i] = m; |
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
91 |
} |
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
92 |
|
3294 | 93 |
// Here, we will explicitly create three nodes. The first container contains |
94 |
// nodes 0 and 1 from the diagram above, and the second one contains nodes |
|
95 |
// 1 and 2. This reflects the channel connectivity, and will be used to |
|
96 |
// install the network interfaces and connect them with a channel. |
|
97 |
NodeContainer n0n1; |
|
98 |
n0n1.Create (2); |
|
2746
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
99 |
|
3294 | 100 |
NodeContainer n1n2; |
101 |
n1n2.Add (n0n1.Get (1)); |
|
102 |
n1n2.Create (1); |
|
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
103 |
|
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
104 |
// We create the channels first without any IP addressing information |
3294 | 105 |
// 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
|
106 |
// 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
|
107 |
PointToPointHelper p2p; |
3381
3cdd9d60f7c7
bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents:
3294
diff
changeset
|
108 |
p2p.SetDeviceAttribute ("DataRate", DataRateValue (DataRate(10000000))); |
3cdd9d60f7c7
bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents:
3294
diff
changeset
|
109 |
p2p.SetChannelAttribute ("Delay", TimeValue (MilliSeconds(10))); |
3294 | 110 |
|
111 |
// And then install devices and channels connecting our topology. |
|
112 |
NetDeviceContainer dev0 = p2p.Install (n0n1); |
|
113 |
NetDeviceContainer dev1 = p2p.Install (n1n2); |
|
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
114 |
|
3294 | 115 |
// Now add ip/tcp stack to all nodes. |
2746
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
116 |
InternetStackHelper internet; |
4616
a84f60b6cd12
bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4610
diff
changeset
|
117 |
internet.InstallAll (); |
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
118 |
|
3294 | 119 |
// Later, we add IP addresses. |
2746
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
120 |
Ipv4AddressHelper ipv4; |
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
121 |
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
|
122 |
ipv4.Assign (dev0); |
2746
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
123 |
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
|
124 |
Ipv4InterfaceContainer ipInterfs = ipv4.Assign (dev1); |
2746
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
125 |
|
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
126 |
// and setup ip routing tables to get total ip-level connectivity. |
4616
a84f60b6cd12
bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4610
diff
changeset
|
127 |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
128 |
|
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
129 |
/////////////////////////////////////////////////////////////////////////// |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
130 |
// Simulation 1 |
3294 | 131 |
// |
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
132 |
// Send 2000000 bytes over a connection to server port 50000 at time 0 |
3294 | 133 |
// Should observe SYN exchange, a lot of data segments and ACKS, and FIN |
134 |
// exchange. FIN exchange isn't quite compliant with TCP spec (see release |
|
135 |
// notes for more info) |
|
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
136 |
// |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
137 |
/////////////////////////////////////////////////////////////////////////// |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
138 |
|
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
139 |
uint16_t servPort = 50000; |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
140 |
|
3294 | 141 |
// 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
|
142 |
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
|
143 |
InetSocketAddress (Ipv4Address::GetAny (), servPort)); |
2890
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2889
diff
changeset
|
144 |
|
3294 | 145 |
ApplicationContainer apps = sink.Install (n1n2.Get (1)); |
2746
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
146 |
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
|
147 |
apps.Stop (Seconds (3.0)); |
2746
177a8a3f3c65
convert to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
148 |
|
3294 | 149 |
// Create a source to send packets from n0. Instead of a full Application |
150 |
// and the helper APIs you might see in other example files, this example |
|
151 |
// will use sockets directly and register some socket callbacks as a sending |
|
152 |
// "Application". |
|
153 |
||
154 |
// Create and bind the socket... |
|
155 |
Ptr<Socket> localSocket = |
|
156 |
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
|
157 |
localSocket->Bind (); |
3294 | 158 |
|
4283
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
4264
diff
changeset
|
159 |
// Trace changes to the congestion window |
5854cddf4493
Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents:
4264
diff
changeset
|
160 |
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
|
161 |
|
3294 | 162 |
// ...and schedule the sending "Application"; This is similar to what an |
163 |
// ns3::Application subclass would do internally. |
|
164 |
Simulator::ScheduleNow (&StartFlow, localSocket, |
|
2749
0aa031496023
use Ipv4InterfaceContainer to avoid hardcoding ip addresses.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2746
diff
changeset
|
165 |
ipInterfs.GetAddress (1), servPort); |
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
166 |
|
3294 | 167 |
// One can toggle the comment for the following line on or off to see the |
168 |
// effects of finite send buffer modelling. One can also change the size of |
|
169 |
// said buffer. |
|
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
170 |
|
3294 | 171 |
//localSocket->SetAttribute("SndBufSize", UintegerValue(4096)); |
172 |
||
173 |
//Ask for ASCII and pcap traces of network traffic |
|
6014 | 174 |
AsciiTraceHelper ascii; |
175 |
p2p.EnableAsciiAll (ascii.CreateFileStream ("tcp-large-transfer.tr")); |
|
6009
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
5369
diff
changeset
|
176 |
p2p.EnablePcapAll ("tcp-large-transfer"); |
2789
47e92324cf4b
configure tracing post-topology construction, not before.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2788
diff
changeset
|
177 |
|
3294 | 178 |
// Finally, set up the simulator to run. The 1000 second hard limit is a |
179 |
// 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
|
180 |
Simulator::Stop (Seconds(1000)); |
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
181 |
Simulator::Run (); |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
182 |
Simulator::Destroy (); |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff
changeset
|
183 |
} |
3240
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
184 |
|
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
185 |
|
3294 | 186 |
//----------------------------------------------------------------------------- |
187 |
//----------------------------------------------------------------------------- |
|
188 |
//----------------------------------------------------------------------------- |
|
189 |
//begin implementation of sending "Application" |
|
190 |
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
|
191 |
Ipv4Address servAddress, |
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
192 |
uint16_t servPort) |
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
193 |
{ |
3294 | 194 |
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
|
195 |
localSocket->Connect (InetSocketAddress (servAddress, servPort));//connect |
3294 | 196 |
|
197 |
// tell the tcp implementation to call WriteUntilBufferFull again |
|
198 |
// 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
|
199 |
localSocket->SetSendCallback (MakeCallback (&WriteUntilBufferFull)); |
4610
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
200 |
WriteUntilBufferFull (localSocket, localSocket->GetTxAvailable ()); |
3240
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
201 |
} |
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
202 |
|
3294 | 203 |
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
|
204 |
{ |
4610
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
205 |
while (currentTxBytes < totalTxBytes && localSocket->GetTxAvailable () > 0) |
3240
965da7165e78
Tcp large transfer modified to keep sending for 10 seconds
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
3239
diff
changeset
|
206 |
{ |
4610
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
207 |
uint32_t left = totalTxBytes - currentTxBytes; |
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
208 |
uint32_t dataOffset = currentTxBytes % writeSize; |
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
209 |
uint32_t toWrite = writeSize - dataOffset; |
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
210 |
toWrite = std::min (toWrite, left); |
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
211 |
toWrite = std::min (toWrite, localSocket->GetTxAvailable ()); |
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
212 |
int amountSent = localSocket->Send (&data[dataOffset], toWrite, 0); |
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
213 |
if(amountSent < 0) |
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
214 |
{ |
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
215 |
// we will be called again when new tx space becomes available. |
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
216 |
return; |
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
217 |
} |
48dddd9d79ee
rewrite tcp test application to handle short writes correctly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4283
diff
changeset
|
218 |
currentTxBytes += amountSent; |
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 |
} |