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
star.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
#include "ns3/core-module.h"
19
#include "ns3/network-module.h"
20
#include "ns3/netanim-module.h"
21
#include "ns3/internet-module.h"
22
#include "ns3/point-to-point-module.h"
23
#include "ns3/applications-module.h"
24
#include "ns3/point-to-point-layout-module.h"
25
26
// Network topology (default)
27
//
28
// n2 n3 n4 .
29
// \ | / .
30
// \|/ .
31
// n1--- n0---n5 .
32
// /|\ .
33
// / | \ .
34
// n8 n7 n6 .
35
//
36
37
38
using namespace
ns3;
39
40
NS_LOG_COMPONENT_DEFINE
(
"Star"
);
41
42
int
43
main
(
int
argc,
char
*argv[])
44
{
45
46
//
47
// Set up some default values for the simulation.
48
//
49
Config::SetDefault
(
"ns3::OnOffApplication::PacketSize"
,
UintegerValue
(137));
50
51
// ??? try and stick 15kb/s into the data rate
52
Config::SetDefault
(
"ns3::OnOffApplication::DataRate"
,
StringValue
(
"14kb/s"
));
53
54
//
55
// Default number of nodes in the star. Overridable by command line argument.
56
//
57
uint32_t nSpokes = 8;
58
59
CommandLine
cmd;
60
cmd.
AddValue
(
"nSpokes"
,
"Number of nodes to place in the star"
, nSpokes);
61
cmd.
Parse
(argc, argv);
62
63
NS_LOG_INFO
(
"Build star topology."
);
64
PointToPointHelper
pointToPoint
;
65
pointToPoint.
SetDeviceAttribute
(
"DataRate"
,
StringValue
(
"5Mbps"
));
66
pointToPoint.
SetChannelAttribute
(
"Delay"
,
StringValue
(
"2ms"
));
67
PointToPointStarHelper
star (nSpokes, pointToPoint);
68
69
NS_LOG_INFO
(
"Install internet stack on all nodes."
);
70
InternetStackHelper
internet;
71
star.
InstallStack
(internet);
72
73
NS_LOG_INFO
(
"Assign IP Addresses."
);
74
star.
AssignIpv4Addresses
(
Ipv4AddressHelper
(
"10.1.1.0"
,
"255.255.255.0"
));
75
76
NS_LOG_INFO
(
"Create applications."
);
77
//
78
// Create a packet sink on the star "hub" to receive packets.
79
//
80
uint16_t
port
= 50000;
81
Address
hubLocalAddress (
InetSocketAddress
(
Ipv4Address::GetAny
(), port));
82
PacketSinkHelper
packetSinkHelper (
"ns3::TcpSocketFactory"
, hubLocalAddress);
83
ApplicationContainer
hubApp = packetSinkHelper.
Install
(star.
GetHub
());
84
hubApp.
Start
(Seconds (1.0));
85
hubApp.
Stop
(Seconds (10.0));
86
87
//
88
// Create OnOff applications to send TCP to the hub, one on each spoke node.
89
//
90
OnOffHelper
onOffHelper (
"ns3::TcpSocketFactory"
,
Address
());
91
onOffHelper.
SetAttribute
(
"OnTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=1]"
));
92
onOffHelper.
SetAttribute
(
"OffTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=0]"
));
93
94
ApplicationContainer
spokeApps;
95
96
for
(uint32_t i = 0; i < star.
SpokeCount
(); ++i)
97
{
98
AddressValue
remoteAddress (
InetSocketAddress
(star.
GetHubIpv4Address
(i),
port
));
99
onOffHelper.
SetAttribute
(
"Remote"
, remoteAddress);
100
spokeApps.
Add
(onOffHelper.
Install
(star.
GetSpokeNode
(i)));
101
}
102
spokeApps.
Start
(Seconds (1.0));
103
spokeApps.
Stop
(Seconds (10.0));
104
105
NS_LOG_INFO
(
"Enable static global routing."
);
106
//
107
// Turn on global static routing so we can actually be routed across the star.
108
//
109
Ipv4GlobalRoutingHelper::PopulateRoutingTables
();
110
111
NS_LOG_INFO
(
"Enable pcap tracing."
);
112
//
113
// Do pcap tracing on all point-to-point devices on all nodes.
114
//
115
pointToPoint.
EnablePcapAll
(
"star"
);
116
117
NS_LOG_INFO
(
"Run Simulation."
);
118
Simulator::Run
();
119
Simulator::Destroy
();
120
NS_LOG_INFO
(
"Done."
);
121
122
return
0;
123
}
examples
tcp
star.cc
Generated on Fri Aug 30 2013 01:42:44 for ns-3 by
1.8.1.2