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
fd-emu-onoff.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2012 University of Washington, 2012 INRIA
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19
*
20
*/
21
22
// +----------------------+ +-----------------------+
23
// | client host | | server host |
24
// +----------------------+ +-----------------------+
25
// | ns-3 Node 0 | | ns-3 Node 1 |
26
// | +----------------+ | | +----------------+ |
27
// | | ns-3 TCP | | | | ns-3 TCP | |
28
// | +----------------+ | | +----------------+ |
29
// | | ns-3 IPv4 | | | | ns-3 IPv4 | |
30
// | +----------------+ | | +----------------+ |
31
// | | FdNetDevice | | | | FdNetDevice | |
32
// | | 10.1.1.1 | | | | 10.1.1.2 | |
33
// | +----------------+ | | +----------------+ |
34
// | | raw socket | | | | raw socket | |
35
// | +----------------+ | | +----------------+ |
36
// | | eth0 | | | | eth0 | |
37
// +-------+------+-------+ +--------+------+-------+
38
//
39
// 10.1.1.11 10.1.1.12
40
//
41
// | |
42
// +----------------------------+
43
//
44
// This example is aimed at measuring the throughput of the FdNetDevice
45
// when using the EmuFdNetDeviceHelper. This is achieved by saturating
46
// the channel with TCP traffic. Then the throughput can be obtained from
47
// the generated .pcap files.
48
//
49
// To run this example you will need two hosts (client & server).
50
// Steps to run the experiment:
51
//
52
// 1 - Connect the 2 computers with an Ethernet cable.
53
// 2 - Set the IP addresses on both Ethernet devices.
54
//
55
// client machine: $ sudo ip addr add dev eth0 10.1.1.11/24
56
// server machine: $ sudo ip addr add dev eth0 10.1.1.12/24
57
//
58
// 3 - Set both Ethernet devices to promiscuous mode.
59
//
60
// both machines: $ sudo ip link set eth0 promisc on
61
//
62
// 4 - Give root suid to the raw socket creator binary.
63
// If the --enable-sudo option was used to configure ns-3 with waf, then the following
64
// step will not be necessary.
65
//
66
// both hosts: $ sudo chown root.root build/src/fd-net-device/ns3-dev-raw-sock-creator
67
// both hosts: $ sudo chmod 4755 build/src/fd-net-device/ns3-dev-raw-sock-creator
68
//
69
// 5 - Run the server side:
70
//
71
// server host: $ ./waf --run="fd-emu-onoff --serverMode=1"
72
//
73
// 6 - Run the client side:
74
//
75
// client host: $ ./waf --run="fd-emu-onoff"
76
//
77
78
#include <iostream>
79
#include <fstream>
80
#include <vector>
81
#include <string>
82
83
#include "ns3/core-module.h"
84
#include "ns3/network-module.h"
85
#include "ns3/internet-module.h"
86
#include "ns3/applications-module.h"
87
#include "ns3/config-store-module.h"
88
#include "ns3/fd-net-device-module.h"
89
90
using namespace
ns3;
91
92
NS_LOG_COMPONENT_DEFINE
(
"EmuFdNetDeviceSaturationExample"
);
93
94
int
95
main
(
int
argc,
char
*argv[])
96
{
97
uint16_t sinkPort = 8000;
98
uint32_t packetSize = 10000;
// bytes
99
std::string dataRate(
"1000Mb/s"
);
100
bool
serverMode =
false
;
101
102
std::string deviceName (
"eth0"
);
103
std::string client (
"10.1.1.1"
);
104
std::string server (
"10.1.1.2"
);
105
std::string netmask (
"255.255.255.0"
);
106
std::string macClient (
"00:00:00:00:00:01"
);
107
std::string macServer (
"00:00:00:00:00:02"
);
108
109
CommandLine
cmd;
110
cmd.
AddValue
(
"deviceName"
,
"Device name"
, deviceName);
111
cmd.
AddValue
(
"client"
,
"Local IP address (dotted decimal only please)"
, client);
112
cmd.
AddValue
(
"server"
,
"Remote IP address (dotted decimal only please)"
, server);
113
cmd.
AddValue
(
"localmask"
,
"Local mask address (dotted decimal only please)"
, netmask);
114
cmd.
AddValue
(
"serverMode"
,
"1:true, 0:false, default client"
, serverMode);
115
cmd.
AddValue
(
"mac-client"
,
"Mac Address for Server Client : 00:00:00:00:00:01"
, macClient);
116
cmd.
AddValue
(
"mac-server"
,
"Mac Address for Server Default : 00:00:00:00:00:02"
, macServer);
117
cmd.
AddValue
(
"data-rate"
,
"Data rate defaults to 1000Mb/s"
, dataRate);
118
cmd.
Parse
(argc, argv);
119
120
Ipv4Address
remoteIp;
121
Ipv4Address
localIp;
122
Mac48AddressValue
localMac;
123
124
if
(serverMode)
125
{
126
remoteIp =
Ipv4Address
(client.c_str ());
127
localIp =
Ipv4Address
(server.c_str ());
128
localMac =
Mac48AddressValue
(macServer.c_str ());
129
}
130
else
131
{
132
remoteIp =
Ipv4Address
(server.c_str ());
133
localIp =
Ipv4Address
(client.c_str ());
134
localMac =
Mac48AddressValue
(macClient.c_str ());
135
}
136
137
Ipv4Mask
localMask (netmask.c_str ());
138
139
GlobalValue::Bind
(
"SimulatorImplementationType"
,
StringValue
(
"ns3::RealtimeSimulatorImpl"
));
140
141
GlobalValue::Bind
(
"ChecksumEnabled"
,
BooleanValue
(
true
));
142
143
NS_LOG_INFO
(
"Create Node"
);
144
Ptr<Node>
node = CreateObject<Node> ();
145
146
NS_LOG_INFO
(
"Create Device"
);
147
EmuFdNetDeviceHelper
emu;
148
emu.
SetDeviceName
(deviceName);
149
NetDeviceContainer
devices = emu.
Install
(node);
150
Ptr<NetDevice>
device = devices.
Get
(0);
151
device->
SetAttribute
(
"Address"
, localMac);
152
153
NS_LOG_INFO
(
"Add Internet Stack"
);
154
InternetStackHelper
internetStackHelper;
155
internetStackHelper.
SetIpv4StackInstall
(
true
);
156
internetStackHelper.
Install
(node);
157
158
NS_LOG_INFO
(
"Create IPv4 Interface"
);
159
Ptr<Ipv4>
ipv4 = node->
GetObject
<
Ipv4
> ();
160
uint32_t
interface
= ipv4->AddInterface (device);
161
Ipv4InterfaceAddress
address =
Ipv4InterfaceAddress
(localIp, localMask);
162
ipv4->
AddAddress
(interface, address);
163
ipv4->
SetMetric
(interface, 1);
164
ipv4->
SetUp
(interface);
165
166
if
(serverMode)
167
{
168
Address
sinkLocalAddress (
InetSocketAddress
(localIp, sinkPort));
169
PacketSinkHelper
sinkHelper (
"ns3::TcpSocketFactory"
, sinkLocalAddress);
170
ApplicationContainer
sinkApp = sinkHelper.
Install
(node);
171
sinkApp.
Start
(
Seconds
(1.0));
172
sinkApp.
Stop
(
Seconds
(60.0));
173
174
emu.
EnablePcap
(
"fd-server"
, device);
175
}
176
else
177
{
178
AddressValue
remoteAddress (
InetSocketAddress
(remoteIp, sinkPort));
179
OnOffHelper
onoff (
"ns3::TcpSocketFactory"
,
Address
());
180
onoff.
SetAttribute
(
"Remote"
, remoteAddress);
181
onoff.
SetAttribute
(
"OnTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=1]"
));
182
onoff.
SetAttribute
(
"OffTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=0]"
));
183
onoff.
SetAttribute
(
"DataRate"
,
DataRateValue
(dataRate));
184
onoff.
SetAttribute
(
"PacketSize"
,
UintegerValue
(packetSize));
185
186
ApplicationContainer
clientApps = onoff.
Install
(node);
187
clientApps.
Start
(
Seconds
(4.0));
188
clientApps.
Stop
(
Seconds
(58.0));
189
190
emu.
EnablePcap
(
"fd-client"
, device);
191
}
192
193
Simulator::Stop
(
Seconds
(61.0));
194
Simulator::Run
();
195
Simulator::Destroy
();
196
197
return
0;
198
}
199
src
fd-net-device
examples
fd-emu-onoff.cc
Generated on Tue May 14 2013 11:08:20 for ns-3 by
1.8.1.2