A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
tcp-nsc-zoo.cc
Go to the documentation of this file.
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/applications-module.h"
35
#include "ns3/network-module.h"
36
#include "ns3/csma-module.h"
37
#include "ns3/internet-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
unsigned
int
runtime = 3;
49
50
Config::SetDefault
(
"ns3::OnOffApplication::PacketSize"
,
UintegerValue
(2048));
51
Config::SetDefault
(
"ns3::OnOffApplication::DataRate"
,
StringValue
(
"8kbps"
));
52
CommandLine
cmd;
53
// this allows the user to raise the number of nodes using --nodes=X command-line argument.
54
cmd.
AddValue
(
"nodes"
,
"Number of nodes in the network (must be > 1)"
, MaxNodes);
55
cmd.
AddValue
(
"runtime"
,
"How long the applications should send data (default 3 seconds)"
, runtime);
56
cmd.
Parse
(argc, argv);
57
58
if
(MaxNodes < 2)
59
{
60
std::cerr <<
"--nodes: must be >= 2"
<< std::endl;
61
return
1;
62
}
63
csma.
SetChannelAttribute
(
"DataRate"
,
DataRateValue
(
DataRate
(100 * 1000 * 1000)));
64
csma.
SetChannelAttribute
(
"Delay"
,
TimeValue
(MicroSeconds (200)));
65
66
NodeContainer
n;
67
n.
Create
(MaxNodes);
68
NetDeviceContainer
ethInterfaces = csma.
Install
(n);
69
70
InternetStackHelper
internetStack;
71
internetStack.
SetTcp
(
"ns3::NscTcpL4Protocol"
,
"Library"
,
StringValue
(
"liblinux2.6.26.so"
));
72
// this switches nodes 0 and 1 to NSCs Linux 2.6.26 stack.
73
internetStack.
Install
(n.
Get
(0));
74
internetStack.
Install
(n.
Get
(1));
75
// this disables TCP SACK, wscale and timestamps on node 1 (the attributes represent sysctl-values).
76
Config::Set
(
"/NodeList/1/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_sack"
,
StringValue
(
"0"
));
77
Config::Set
(
"/NodeList/1/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_timestamps"
,
StringValue
(
"0"
));
78
Config::Set
(
"/NodeList/1/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_window_scaling"
,
StringValue
(
"0"
));
79
80
if
(MaxNodes > 2)
81
{
82
internetStack.
Install
(n.
Get
(2));
83
}
84
85
if
(MaxNodes > 3)
86
{
87
// the next statement doesn't change anything for the nodes 0, 1, and 2; since they
88
// already have a stack assigned.
89
internetStack.
SetTcp
(
"ns3::NscTcpL4Protocol"
,
"Library"
,
StringValue
(
"liblinux2.6.26.so"
));
90
// this switches node 3 to NSCs Linux 2.6.26 stack.
91
internetStack.
Install
(n.
Get
(3));
92
// and then agains disables sack/timestamps/wscale on node 3.
93
Config::Set
(
"/NodeList/3/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_sack"
,
StringValue
(
"0"
));
94
Config::Set
(
"/NodeList/3/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_timestamps"
,
StringValue
(
"0"
));
95
Config::Set
(
"/NodeList/3/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_window_scaling"
,
StringValue
(
"0"
));
96
}
97
// the freebsd stack is not yet built by default, so its commented out for now.
98
// internetStack.SetNscStack ("libfreebsd5.so");
99
for
(
unsigned
int
i =4; i < MaxNodes; i++)
100
{
101
internetStack.
Install
(n.
Get
(i));
102
}
103
Ipv4AddressHelper
ipv4;
104
105
ipv4.
SetBase
(
"10.0.0.0"
,
"255.255.255.0"
);
106
Ipv4InterfaceContainer
ipv4Interfaces = ipv4.
Assign
(ethInterfaces);
107
108
Ipv4GlobalRoutingHelper::PopulateRoutingTables
();
109
110
uint16_t servPort = 8080;
111
PacketSinkHelper
sinkHelper (
"ns3::TcpSocketFactory"
,
InetSocketAddress
(
Ipv4Address::GetAny
(), servPort));
112
// start a sink client on all nodes
113
ApplicationContainer
sinkApp = sinkHelper.
Install
(n);
114
sinkApp.
Start
(Seconds (0));
115
sinkApp.
Stop
(Seconds (30.0));
116
117
// This tells every node on the network to start a flow to all other nodes on the network ...
118
for
(
unsigned
int
i = 0; i < MaxNodes; i++)
119
{
120
for
(
unsigned
int
j = 0; j < MaxNodes; j++)
121
{
122
if
(i == j)
123
{
// ...but we don't want a node to talk to itself.
124
continue
;
125
}
126
Address
remoteAddress (
InetSocketAddress
(ipv4Interfaces.
GetAddress
(j), servPort));
127
OnOffHelper
clientHelper (
"ns3::TcpSocketFactory"
, remoteAddress);
128
clientHelper.
SetAttribute
129
(
"OnTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=1]"
));
130
clientHelper.
SetAttribute
131
(
"OffTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=0]"
));
132
ApplicationContainer
clientApp = clientHelper.
Install
(n.
Get
(i));
133
clientApp.
Start
(Seconds (j));
/* delay startup depending on node number */
134
clientApp.
Stop
(Seconds (j + runtime));
135
}
136
}
137
138
csma.
EnablePcapAll
(
"tcp-nsc-zoo"
,
false
);
139
140
Simulator::Stop
(Seconds (100));
141
Simulator::Run
();
142
Simulator::Destroy
();
143
144
return
0;
145
}
examples
tcp
tcp-nsc-zoo.cc
Generated on Fri Aug 30 2013 01:42:44 for ns-3 by
1.8.1.2