author | Craig Dowell <craigdo@ee.washington.edu> |
Tue, 06 Oct 2009 19:34:29 -0700 | |
changeset 5369 | 86beb5869f67 |
parent 4616 | examples/tcp-nsc-zoo.cc@a84f60b6cd12 |
child 6009 | e1b696a1ed28 |
permissions | -rw-r--r-- |
3580 | 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 |
||
18 |
||
19 |
// Network topology |
|
20 |
// |
|
21 |
// n0 n1 n2 n3 |
|
22 |
// | | | | |
|
23 |
// ================= |
|
24 |
// LAN |
|
25 |
// |
|
26 |
// - Pcap traces are saved as tcp-nsc-zoo-$n-0.pcap, where $n represents the node number |
|
27 |
// - TCP flows from n0 to n1, n2, n3, from n1 to n0, n2, n3, etc. |
|
3675
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
28 |
// Usage (e.g.): ./waf --run 'tcp-nsc-zoo --nodes=5' |
3580 | 29 |
|
30 |
#include <iostream> |
|
31 |
#include <string> |
|
32 |
||
33 |
#include "ns3/core-module.h" |
|
34 |
#include "ns3/helper-module.h" |
|
35 |
#include "ns3/node-module.h" |
|
36 |
#include "ns3/simulator-module.h" |
|
37 |
||
38 |
using namespace ns3; |
|
39 |
||
40 |
NS_LOG_COMPONENT_DEFINE ("TcpNscZoo"); |
|
41 |
||
42 |
// Simulates a diverse network with various stacks supported by NSC. |
|
43 |
int main(int argc, char *argv[]) |
|
44 |
{ |
|
45 |
CsmaHelper csma; |
|
46 |
unsigned int MaxNodes = 4; |
|
3675
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
47 |
unsigned int runtime = 3; |
3580 | 48 |
|
3675
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
49 |
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (2048)); |
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
50 |
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("8kbps")); |
3580 | 51 |
CommandLine cmd; |
3675
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
52 |
// this allows the user to raise the number of nodes using --nodes=X command-line argument. |
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
53 |
cmd.AddValue("nodes", "Number of nodes in the network (must be > 1)", MaxNodes); |
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
54 |
cmd.AddValue("runtime", "How long the applications should send data (default 3 seconds)", runtime); |
3580 | 55 |
cmd.Parse (argc, argv); |
56 |
||
3675
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
57 |
if (MaxNodes < 2) |
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
58 |
{ |
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
59 |
std::cerr << "--nodes: must be >= 2" << std::endl; |
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
60 |
return 1; |
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
61 |
} |
3580 | 62 |
csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate(100 * 1000 * 1000))); |
63 |
csma.SetChannelAttribute ("Delay", TimeValue (MicroSeconds (200))); |
|
64 |
||
65 |
NodeContainer n; |
|
66 |
n.Create(MaxNodes); |
|
67 |
NetDeviceContainer ethInterfaces = csma.Install (n); |
|
68 |
||
69 |
InternetStackHelper internetStack; |
|
4473
39ac17168023
examples/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4264
diff
changeset
|
70 |
internetStack.SetTcp ("ns3::NscTcpL4Protocol","Library",StringValue("liblinux2.6.26.so")); |
3580 | 71 |
// this switches nodes 0 and 1 to NSCs Linux 2.6.26 stack. |
72 |
internetStack.Install (n.Get(0)); |
|
73 |
internetStack.Install (n.Get(1)); |
|
74 |
// this disables TCP SACK, wscale and timestamps on node 1 (the attributes represent sysctl-values). |
|
75 |
Config::Set ("/NodeList/1/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_sack", StringValue ("0")); |
|
76 |
Config::Set ("/NodeList/1/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_timestamps", StringValue ("0")); |
|
77 |
Config::Set ("/NodeList/1/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_window_scaling", StringValue ("0")); |
|
3675
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
78 |
|
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
79 |
if (MaxNodes > 2) |
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
80 |
{ |
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
81 |
internetStack.Install (n.Get(2)); |
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
82 |
} |
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
83 |
|
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
84 |
if (MaxNodes > 3) |
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
85 |
{ |
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
86 |
// the next statement doesn't change anything for the nodes 0, 1, and 2; since they |
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
87 |
// already have a stack assigned. |
4473
39ac17168023
examples/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4264
diff
changeset
|
88 |
internetStack.SetTcp ("ns3::NscTcpL4Protocol","Library",StringValue("liblinux2.6.18.so")); |
3675
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
89 |
// this switches node 3 to NSCs Linux 2.6.18 stack. |
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
90 |
internetStack.Install (n.Get(3)); |
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
91 |
// and then agains disables sack/timestamps/wscale on node 3. |
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
92 |
Config::Set ("/NodeList/3/$ns3::Ns3NscStack<linux2.6.18>/net.ipv4.tcp_sack", StringValue ("0")); |
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
93 |
Config::Set ("/NodeList/3/$ns3::Ns3NscStack<linux2.6.18>/net.ipv4.tcp_timestamps", StringValue ("0")); |
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
94 |
Config::Set ("/NodeList/3/$ns3::Ns3NscStack<linux2.6.18>/net.ipv4.tcp_window_scaling", StringValue ("0")); |
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
95 |
} |
3580 | 96 |
// the freebsd stack is not yet built by default, so its commented out for now. |
97 |
// internetStack.SetNscStack ("libfreebsd5.so"); |
|
98 |
for (unsigned int i =4; i < MaxNodes; i++) |
|
99 |
{ |
|
100 |
internetStack.Install (n.Get(i)); |
|
101 |
} |
|
102 |
Ipv4AddressHelper ipv4; |
|
103 |
||
104 |
ipv4.SetBase ("10.0.0.0", "255.255.255.0"); |
|
105 |
Ipv4InterfaceContainer ipv4Interfaces = ipv4.Assign (ethInterfaces); |
|
106 |
||
4616
a84f60b6cd12
bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4473
diff
changeset
|
107 |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
3580 | 108 |
|
109 |
uint16_t servPort = 8080; |
|
110 |
PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), servPort)); |
|
111 |
// start a sink client on all nodes |
|
112 |
ApplicationContainer sinkApp = sinkHelper.Install (n); |
|
3675
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
113 |
sinkApp.Start (Seconds (0)); |
3580 | 114 |
sinkApp.Stop (Seconds (30.0)); |
115 |
||
116 |
// This tells every node on the network to start a flow to all other nodes on the network ... |
|
117 |
for (unsigned int i = 0 ; i < MaxNodes;i++) |
|
118 |
{ |
|
119 |
for (unsigned int j = 0 ; j < MaxNodes;j++) |
|
120 |
{ |
|
121 |
if (i == j) |
|
122 |
{ // ...but we don't want a node to talk to itself. |
|
123 |
continue; |
|
124 |
} |
|
125 |
Address remoteAddress(InetSocketAddress(ipv4Interfaces.GetAddress (j), servPort)); |
|
126 |
OnOffHelper clientHelper ("ns3::TcpSocketFactory", remoteAddress); |
|
127 |
clientHelper.SetAttribute |
|
128 |
("OnTime", RandomVariableValue (ConstantVariable (1))); |
|
129 |
clientHelper.SetAttribute |
|
130 |
("OffTime", RandomVariableValue (ConstantVariable (0))); |
|
131 |
ApplicationContainer clientApp = clientHelper.Install(n.Get(i)); |
|
3675
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
132 |
clientApp.Start (Seconds (j)); /* delay startup depending on node number */ |
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
133 |
clientApp.Stop (Seconds (j + runtime)); |
3580 | 134 |
} |
135 |
} |
|
136 |
||
4264
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4225
diff
changeset
|
137 |
CsmaHelper::EnablePcapAll ("tcp-nsc-zoo", false); |
3580 | 138 |
|
3675
266033a58f24
nsc: rework tcp-nsc-zoo example
Florian Westphal <fw@strlen.de>
parents:
3580
diff
changeset
|
139 |
Simulator::Stop (Seconds(100)); |
3580 | 140 |
Simulator::Run (); |
141 |
Simulator::Destroy (); |
|
142 |
||
143 |
return 0; |
|
144 |
} |