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.
|
|
28 |
// Usage (e.g.): ./waf --run 'tcp-nsc-zoo --Nodes=5'
|
|
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/global-route-manager.h"
|
|
37 |
#include "ns3/simulator-module.h"
|
|
38 |
|
|
39 |
using namespace ns3;
|
|
40 |
|
|
41 |
NS_LOG_COMPONENT_DEFINE ("TcpNscZoo");
|
|
42 |
|
|
43 |
// Simulates a diverse network with various stacks supported by NSC.
|
|
44 |
int main(int argc, char *argv[])
|
|
45 |
{
|
|
46 |
CsmaHelper csma;
|
|
47 |
unsigned int MaxNodes = 4;
|
|
48 |
|
|
49 |
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (4096));
|
|
50 |
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("1Mb/s"));
|
|
51 |
CommandLine cmd;
|
|
52 |
// this allows the user to raise the number of nodes using --Nodes=X command-line argument.
|
|
53 |
cmd.AddValue("Nodes", "Number of nodes in the network", MaxNodes);
|
|
54 |
cmd.Parse (argc, argv);
|
|
55 |
|
|
56 |
csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate(100 * 1000 * 1000)));
|
|
57 |
csma.SetChannelAttribute ("Delay", TimeValue (MicroSeconds (200)));
|
|
58 |
|
|
59 |
NodeContainer n;
|
|
60 |
n.Create(MaxNodes);
|
|
61 |
NetDeviceContainer ethInterfaces = csma.Install (n);
|
|
62 |
|
|
63 |
InternetStackHelper internetStack;
|
|
64 |
|
|
65 |
internetStack.SetNscStack ("liblinux2.6.26.so");
|
|
66 |
// this switches nodes 0 and 1 to NSCs Linux 2.6.26 stack.
|
|
67 |
internetStack.Install (n.Get(0));
|
|
68 |
internetStack.Install (n.Get(1));
|
|
69 |
// this disables TCP SACK, wscale and timestamps on node 1 (the attributes represent sysctl-values).
|
|
70 |
Config::Set ("/NodeList/1/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_sack", StringValue ("0"));
|
|
71 |
Config::Set ("/NodeList/1/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_timestamps", StringValue ("0"));
|
|
72 |
Config::Set ("/NodeList/1/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_window_scaling", StringValue ("0"));
|
|
73 |
internetStack.Install (n.Get(2));
|
|
74 |
// the next statement doesn't change anything for the nodes 0, 1, and 2; since they
|
|
75 |
// already have a stack assigned.
|
|
76 |
internetStack.SetNscStack ("liblinux2.6.18.so");
|
|
77 |
// this switches node 3 to NSCs Linux 2.6.18 stack.
|
|
78 |
internetStack.Install (n.Get(3));
|
|
79 |
// and then agains disables sack/timestamps/wscale on node 3.
|
|
80 |
Config::Set ("/NodeList/3/$ns3::Ns3NscStack<linux2.6.18>/net.ipv4.tcp_sack", StringValue ("0"));
|
|
81 |
Config::Set ("/NodeList/3/$ns3::Ns3NscStack<linux2.6.18>/net.ipv4.tcp_timestamps", StringValue ("0"));
|
|
82 |
Config::Set ("/NodeList/3/$ns3::Ns3NscStack<linux2.6.18>/net.ipv4.tcp_window_scaling", StringValue ("0"));
|
|
83 |
// the freebsd stack is not yet built by default, so its commented out for now.
|
|
84 |
// internetStack.SetNscStack ("libfreebsd5.so");
|
|
85 |
for (unsigned int i =4; i < MaxNodes; i++)
|
|
86 |
{
|
|
87 |
internetStack.Install (n.Get(i));
|
|
88 |
}
|
|
89 |
Ipv4AddressHelper ipv4;
|
|
90 |
|
|
91 |
ipv4.SetBase ("10.0.0.0", "255.255.255.0");
|
|
92 |
Ipv4InterfaceContainer ipv4Interfaces = ipv4.Assign (ethInterfaces);
|
|
93 |
|
|
94 |
GlobalRouteManager::PopulateRoutingTables ();
|
|
95 |
|
|
96 |
uint16_t servPort = 8080;
|
|
97 |
PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), servPort));
|
|
98 |
// start a sink client on all nodes
|
|
99 |
ApplicationContainer sinkApp = sinkHelper.Install (n);
|
|
100 |
sinkApp.Start (Seconds (1.0));
|
|
101 |
sinkApp.Stop (Seconds (30.0));
|
|
102 |
|
|
103 |
// This tells every node on the network to start a flow to all other nodes on the network ...
|
|
104 |
for (unsigned int i = 0 ; i < MaxNodes;i++)
|
|
105 |
{
|
|
106 |
for (unsigned int j = 0 ; j < MaxNodes;j++)
|
|
107 |
{
|
|
108 |
if (i == j)
|
|
109 |
{ // ...but we don't want a node to talk to itself.
|
|
110 |
continue;
|
|
111 |
}
|
|
112 |
Address remoteAddress(InetSocketAddress(ipv4Interfaces.GetAddress (j), servPort));
|
|
113 |
OnOffHelper clientHelper ("ns3::TcpSocketFactory", remoteAddress);
|
|
114 |
clientHelper.SetAttribute
|
|
115 |
("OnTime", RandomVariableValue (ConstantVariable (1)));
|
|
116 |
clientHelper.SetAttribute
|
|
117 |
("OffTime", RandomVariableValue (ConstantVariable (0)));
|
|
118 |
ApplicationContainer clientApp = clientHelper.Install(n.Get(i));
|
|
119 |
clientApp.Start (Seconds (j + 1.0)); /* delay startup depending on node number */
|
|
120 |
clientApp.Stop (Seconds (j + 10.0));
|
|
121 |
}
|
|
122 |
}
|
|
123 |
|
|
124 |
CsmaHelper::EnablePcapAll ("tcp-nsc-zoo");
|
|
125 |
|
|
126 |
Simulator::Stop (Seconds(1000));
|
|
127 |
Simulator::Run ();
|
|
128 |
Simulator::Destroy ();
|
|
129 |
|
|
130 |
return 0;
|
|
131 |
}
|