author | Tom Henderson <tomh@tomh.org> |
Fri, 18 Feb 2011 16:05:39 -0800 | |
changeset 6821 | 203367ae7433 |
parent 6690 | 3fab9a03dacd |
child 6823 | a27f86fb4e55 |
permissions | -rw-r--r-- |
6690 | 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* This program is free software; you can redistribute it and/or modify |
|
4 |
* it under the terms of the GNU General Public License version 2 as |
|
5 |
* published by the Free Software Foundation; |
|
6 |
* |
|
7 |
* This program is distributed in the hope that it will be useful, |
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10 |
* GNU General Public License for more details. |
|
11 |
* |
|
12 |
* You should have received a copy of the GNU General Public License |
|
13 |
* along with this program; if not, write to the Free Software |
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
15 |
*/ |
|
16 |
||
17 |
// Network topology |
|
18 |
// |
|
19 |
// n0 ----------- n1 |
|
20 |
// 500 Kbps |
|
21 |
// 5 ms |
|
22 |
// |
|
23 |
// - Flow from n0 to n1 using BulkSendApplication. |
|
24 |
// - Tracing of queues and packet receptions to file "tcp-bulk-send.tr" |
|
25 |
// and pcap tracing available when tracing is turned on. |
|
26 |
||
27 |
#include <string> |
|
28 |
#include <fstream> |
|
29 |
#include "ns3/core-module.h" |
|
6821
203367ae7433
merge src/simulator into src/core; move src/core to new module layout
Tom Henderson <tomh@tomh.org>
parents:
6690
diff
changeset
|
30 |
#include "ns3/core-module.h" |
6690 | 31 |
#include "ns3/helper-module.h" |
32 |
#include "ns3/node-module.h" |
|
33 |
#include "ns3/packet-sink.h" |
|
34 |
||
35 |
using namespace ns3; |
|
36 |
||
37 |
NS_LOG_COMPONENT_DEFINE ("TcpBulkSendExample"); |
|
38 |
||
39 |
int |
|
40 |
main (int argc, char *argv[]) |
|
41 |
{ |
|
42 |
||
43 |
bool tracing = false; |
|
44 |
uint32_t maxBytes = 0; |
|
45 |
||
46 |
// |
|
47 |
// Allow the user to override any of the defaults at |
|
48 |
// run-time, via command-line arguments |
|
49 |
// |
|
50 |
CommandLine cmd; |
|
51 |
cmd.AddValue ("tracing", "Flag to enable/disable tracing", tracing); |
|
52 |
cmd.AddValue ("maxBytes", |
|
53 |
"Total number of bytes for application to send", maxBytes); |
|
54 |
cmd.Parse (argc, argv); |
|
55 |
||
56 |
// |
|
57 |
// Explicitly create the nodes required by the topology (shown above). |
|
58 |
// |
|
59 |
NS_LOG_INFO ("Create nodes."); |
|
60 |
NodeContainer nodes; |
|
61 |
nodes.Create (2); |
|
62 |
||
63 |
NS_LOG_INFO ("Create channels."); |
|
64 |
||
65 |
// |
|
66 |
// Explicitly create the point-to-point link required by the topology (shown above). |
|
67 |
// |
|
68 |
PointToPointHelper pointToPoint; |
|
69 |
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("500Kbps")); |
|
70 |
pointToPoint.SetChannelAttribute ("Delay", StringValue ("5ms")); |
|
71 |
||
72 |
NetDeviceContainer devices; |
|
73 |
devices = pointToPoint.Install (nodes); |
|
74 |
||
75 |
// |
|
76 |
// Install the internet stack on the nodes |
|
77 |
// |
|
78 |
InternetStackHelper internet; |
|
79 |
internet.Install (nodes); |
|
80 |
||
81 |
// |
|
82 |
// We've got the "hardware" in place. Now we need to add IP addresses. |
|
83 |
// |
|
84 |
NS_LOG_INFO ("Assign IP Addresses."); |
|
85 |
Ipv4AddressHelper ipv4; |
|
86 |
ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
|
87 |
Ipv4InterfaceContainer i = ipv4.Assign (devices); |
|
88 |
||
89 |
NS_LOG_INFO ("Create Applications."); |
|
90 |
||
91 |
// |
|
92 |
// Create a BulkSendApplication and install it on node 0 |
|
93 |
// |
|
94 |
uint16_t port = 9; // well-known echo port number |
|
95 |
||
96 |
||
97 |
BulkSendHelper source ("ns3::TcpSocketFactory", |
|
98 |
InetSocketAddress (i.GetAddress (1), port)); |
|
99 |
// Set the amount of data to send in bytes. Zero is unlimited. |
|
100 |
source.SetAttribute ("MaxBytes", UintegerValue (maxBytes)); |
|
101 |
ApplicationContainer sourceApps = source.Install (nodes.Get (0)); |
|
102 |
sourceApps.Start (Seconds (0.0)); |
|
103 |
sourceApps.Stop (Seconds (10.0)); |
|
104 |
||
105 |
// |
|
106 |
// Create a PacketSinkApplication and install it on node 1 |
|
107 |
// |
|
108 |
PacketSinkHelper sink ("ns3::TcpSocketFactory", |
|
109 |
InetSocketAddress (Ipv4Address::GetAny (), port)); |
|
110 |
ApplicationContainer sinkApps = sink.Install (nodes.Get (1)); |
|
111 |
sinkApps.Start (Seconds (0.0)); |
|
112 |
sinkApps.Stop (Seconds (10.0)); |
|
113 |
||
114 |
// |
|
115 |
// Set up tracing if enabled |
|
116 |
// |
|
117 |
if (tracing) |
|
118 |
{ |
|
119 |
AsciiTraceHelper ascii; |
|
120 |
pointToPoint.EnableAsciiAll (ascii.CreateFileStream ("tcp-bulk-send.tr")); |
|
121 |
pointToPoint.EnablePcapAll ("tcp-bulk-send", false); |
|
122 |
} |
|
123 |
||
124 |
// |
|
125 |
// Now, do the actual simulation. |
|
126 |
// |
|
127 |
NS_LOG_INFO ("Run Simulation."); |
|
128 |
Simulator::Stop (Seconds (10.0)); |
|
129 |
Simulator::Run (); |
|
130 |
Simulator::Destroy (); |
|
131 |
NS_LOG_INFO ("Done."); |
|
132 |
||
133 |
Ptr<PacketSink> sink1 = DynamicCast<PacketSink> (sinkApps.Get (0)); |
|
134 |
std::cout << "Total Bytes Received: " << sink1->GetTotalRx () << std::endl; |
|
135 |
} |