author | Alina Quereilhac <alina.quereilhac@inria.fr> |
Fri, 26 Apr 2013 02:00:09 +0200 | |
changeset 9718 | fe314aeb8ddb |
parent 9271 | 85e753b6676c |
permissions | -rw-r--r-- |
9271 | 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 |
// +----------------------+ +-----------------------+ |
|
9718
fe314aeb8ddb
Fixed compilation problem on the PlanetLabFdNetDeviceHelper and improved documentation for the fd-net-device module.
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
9271
diff
changeset
|
23 |
// | client host | | server host | |
9271 | 24 |
// +----------------------+ +-----------------------+ |
9718
fe314aeb8ddb
Fixed compilation problem on the PlanetLabFdNetDeviceHelper and improved documentation for the fd-net-device module.
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
9271
diff
changeset
|
25 |
// | ns-3 Node 0 | | ns-3 Node 1 | |
9271 | 26 |
// | +----------------+ | | +----------------+ | |
27 |
// | | ns-3 TCP | | | | ns-3 TCP | | |
|
28 |
// | +----------------+ | | +----------------+ | |
|
9718
fe314aeb8ddb
Fixed compilation problem on the PlanetLabFdNetDeviceHelper and improved documentation for the fd-net-device module.
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
9271
diff
changeset
|
29 |
// | | ns-3 IPv4 | | | | ns-3 IPv4 | | |
9271 | 30 |
// | +----------------+ | | +----------------+ | |
9718
fe314aeb8ddb
Fixed compilation problem on the PlanetLabFdNetDeviceHelper and improved documentation for the fd-net-device module.
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
9271
diff
changeset
|
31 |
// | | FdNetDevice | | | | FdNetDevice | | |
fe314aeb8ddb
Fixed compilation problem on the PlanetLabFdNetDeviceHelper and improved documentation for the fd-net-device module.
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
9271
diff
changeset
|
32 |
// | | 10.1.1.1 | | | | 10.1.1.2 | | |
9271 | 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 |
// |
|
9718
fe314aeb8ddb
Fixed compilation problem on the PlanetLabFdNetDeviceHelper and improved documentation for the fd-net-device module.
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
9271
diff
changeset
|
44 |
// This example is aimed at measuring the throughput of the FdNetDevice |
9271 | 45 |
// when using the EmuFdNetDeviceHelper. This is achieved by saturating |
9718
fe314aeb8ddb
Fixed compilation problem on the PlanetLabFdNetDeviceHelper and improved documentation for the fd-net-device module.
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
9271
diff
changeset
|
46 |
// the channel with TCP traffic. Then the throughput can be obtained from |
9271 | 47 |
// the generated .pcap files. |
48 |
// |
|
9718
fe314aeb8ddb
Fixed compilation problem on the PlanetLabFdNetDeviceHelper and improved documentation for the fd-net-device module.
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
9271
diff
changeset
|
49 |
// To run this example you will need two hosts (client & server). |
9271 | 50 |
// Steps to run the experiment: |
51 |
// |
|
9718
fe314aeb8ddb
Fixed compilation problem on the PlanetLabFdNetDeviceHelper and improved documentation for the fd-net-device module.
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
9271
diff
changeset
|
52 |
// 1 - Connect the 2 computers with an Ethernet cable. |
fe314aeb8ddb
Fixed compilation problem on the PlanetLabFdNetDeviceHelper and improved documentation for the fd-net-device module.
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
9271
diff
changeset
|
53 |
// 2 - Set the IP addresses on both Ethernet devices. |
9271 | 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 |
// |
|
9718
fe314aeb8ddb
Fixed compilation problem on the PlanetLabFdNetDeviceHelper and improved documentation for the fd-net-device module.
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
9271
diff
changeset
|
58 |
// 3 - Set both Ethernet devices to promiscuous mode. |
9271 | 59 |
// |
60 |
// both machines: $ sudo ip link set eth0 promisc on |
|
61 |
// |
|
9718
fe314aeb8ddb
Fixed compilation problem on the PlanetLabFdNetDeviceHelper and improved documentation for the fd-net-device module.
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
9271
diff
changeset
|
62 |
// 4 - Give root suid to the raw socket creator binary. |
fe314aeb8ddb
Fixed compilation problem on the PlanetLabFdNetDeviceHelper and improved documentation for the fd-net-device module.
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
9271
diff
changeset
|
63 |
// If the --enable-sudo option was used to configure ns-3 with waf, then the following |
fe314aeb8ddb
Fixed compilation problem on the PlanetLabFdNetDeviceHelper and improved documentation for the fd-net-device module.
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
9271
diff
changeset
|
64 |
// step will not be necessary. |
9271 | 65 |
// |
9718
fe314aeb8ddb
Fixed compilation problem on the PlanetLabFdNetDeviceHelper and improved documentation for the fd-net-device module.
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
9271
diff
changeset
|
66 |
// both hosts: $ sudo chown root.root build/src/fd-net-device/ns3-dev-raw-sock-creator |
fe314aeb8ddb
Fixed compilation problem on the PlanetLabFdNetDeviceHelper and improved documentation for the fd-net-device module.
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
9271
diff
changeset
|
67 |
// both hosts: $ sudo chmod 4755 build/src/fd-net-device/ns3-dev-raw-sock-creator |
9271 | 68 |
// |
69 |
// 5 - Run the server side: |
|
70 |
// |
|
9718
fe314aeb8ddb
Fixed compilation problem on the PlanetLabFdNetDeviceHelper and improved documentation for the fd-net-device module.
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
9271
diff
changeset
|
71 |
// server host: $ ./waf --run="fd-emu-onoff --serverMode=1" |
9271 | 72 |
// |
73 |
// 6 - Run the client side: |
|
74 |
// |
|
9718
fe314aeb8ddb
Fixed compilation problem on the PlanetLabFdNetDeviceHelper and improved documentation for the fd-net-device module.
Alina Quereilhac <alina.quereilhac@inria.fr>
parents:
9271
diff
changeset
|
75 |
// client host: $ ./waf --run="fd-emu-onoff" |
9271 | 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 |