Files
unison/examples/wireless/wifi-adhoc.cc

288 lines
9.1 KiB
C++
Raw Normal View History

2007-08-24 15:19:20 +02:00
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005,2006,2007 INRIA
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "ns3/core-module.h"
#include "ns3/common-module.h"
#include "ns3/node-module.h"
#include "ns3/helper-module.h"
#include "ns3/mobility-module.h"
#include "ns3/contrib-module.h"
2007-08-24 15:19:20 +02:00
#include <iostream>
2008-03-01 21:21:53 +01:00
NS_LOG_COMPONENT_DEFINE ("Main");
2007-08-24 15:19:20 +02:00
using namespace ns3;
2008-03-01 21:21:53 +01:00
class Experiment
2007-08-24 15:19:20 +02:00
{
2008-03-01 21:21:53 +01:00
public:
Experiment ();
Experiment (std::string name);
2009-04-24 10:01:41 +02:00
Gnuplot2dDataset Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy,
const NqosWifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel);
2008-03-01 21:21:53 +01:00
private:
2008-04-28 21:45:55 -07:00
void ReceivePacket (Ptr<Socket> socket);
2008-03-01 21:21:53 +01:00
void SetPosition (Ptr<Node> node, Vector position);
Vector GetPosition (Ptr<Node> node);
void AdvancePosition (Ptr<Node> node);
Ptr<Socket> SetupPacketReceive (Ptr<Node> node);
uint32_t m_bytesTotal;
2009-01-09 09:54:09 +01:00
Gnuplot2dDataset m_output;
2008-03-01 21:21:53 +01:00
};
Experiment::Experiment ()
{}
Experiment::Experiment (std::string name)
: m_output (name)
{
2009-01-09 09:54:09 +01:00
m_output.SetStyle (Gnuplot2dDataset::LINES);
2007-08-24 15:19:20 +02:00
}
2008-03-01 21:21:53 +01:00
void
Experiment::SetPosition (Ptr<Node> node, Vector position)
2007-08-24 15:19:20 +02:00
{
2008-01-31 22:11:03 +01:00
Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
2007-11-15 10:22:35 +01:00
mobility->SetPosition (position);
2007-08-24 15:19:20 +02:00
}
2008-03-01 21:21:53 +01:00
Vector
Experiment::GetPosition (Ptr<Node> node)
2007-08-24 15:19:20 +02:00
{
2008-01-31 22:11:03 +01:00
Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
2007-11-15 10:22:35 +01:00
return mobility->GetPosition ();
2007-08-24 15:19:20 +02:00
}
2008-03-01 21:21:53 +01:00
void
Experiment::AdvancePosition (Ptr<Node> node)
2007-08-24 15:19:20 +02:00
{
2007-11-15 10:22:35 +01:00
Vector pos = GetPosition (node);
2008-03-01 21:21:53 +01:00
double mbs = ((m_bytesTotal * 8.0) / 1000000);
m_bytesTotal = 0;
m_output.Add (pos.x, mbs);
2007-11-06 15:11:22 +01:00
pos.x += 1.0;
if (pos.x >= 210.0)
{
return;
}
2007-08-24 15:19:20 +02:00
SetPosition (node, pos);
2007-10-16 14:43:40 +02:00
//std::cout << "x="<<pos.x << std::endl;
2008-03-01 21:21:53 +01:00
Simulator::Schedule (Seconds (1.0), &Experiment::AdvancePosition, this, node);
2007-08-24 15:19:20 +02:00
}
2008-03-01 21:21:53 +01:00
void
2008-04-28 21:45:55 -07:00
Experiment::ReceivePacket (Ptr<Socket> socket)
2007-11-05 16:45:22 +01:00
{
2008-04-28 21:45:55 -07:00
Ptr<Packet> packet;
while (packet = socket->Recv ())
2008-04-28 21:45:55 -07:00
{
m_bytesTotal += packet->GetSize ();
}
2007-11-05 16:45:22 +01:00
}
2007-08-24 15:19:20 +02:00
2008-03-01 21:21:53 +01:00
Ptr<Socket>
Experiment::SetupPacketReceive (Ptr<Node> node)
2007-11-05 16:45:22 +01:00
{
TypeId tid = TypeId::LookupByName ("ns3::PacketSocketFactory");
Ptr<Socket> sink = Socket::CreateSocket (node, tid);
sink->Bind ();
2008-05-02 09:21:01 -07:00
sink->SetRecvCallback (MakeCallback (&Experiment::ReceivePacket, this));
2007-11-05 16:45:22 +01:00
return sink;
}
2007-08-24 15:19:20 +02:00
2009-01-09 09:54:09 +01:00
Gnuplot2dDataset
2009-04-24 10:01:41 +02:00
Experiment::Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy,
const NqosWifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel)
2007-08-24 15:19:20 +02:00
{
2008-03-01 21:21:53 +01:00
m_bytesTotal = 0;
NodeContainer c;
c.Create (2);
PacketSocketHelper packetSocket;
2008-04-07 10:38:37 -07:00
packetSocket.Install (c);
2008-11-04 14:06:34 +01:00
YansWifiPhyHelper phy = wifiPhy;
phy.SetChannel (wifiChannel.Create ());
2009-04-24 10:01:41 +02:00
NqosWifiMacHelper mac = wifiMac;
NetDeviceContainer devices = wifi.Install (phy, mac, c);
2008-03-01 21:21:53 +01:00
MobilityHelper mobility;
2008-03-11 13:30:12 -07:00
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
2008-03-01 21:21:53 +01:00
positionAlloc->Add (Vector (0.0, 0.0, 0.0));
positionAlloc->Add (Vector (5.0, 0.0, 0.0));
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
2007-08-24 15:19:20 +02:00
2008-04-13 15:46:17 -07:00
mobility.Install (c);
2008-04-07 18:29:38 -07:00
PacketSocketAddress socket;
socket.SetSingleDevice(devices.Get (0)->GetIfIndex ());
socket.SetPhysicalAddress (devices.Get (1)->GetAddress ());
socket.SetProtocol (1);
OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket));
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (250)));
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
onoff.SetAttribute ("DataRate", DataRateValue (DataRate (60000000)));
onoff.SetAttribute ("PacketSize", UintegerValue (2000));
2008-04-07 18:29:38 -07:00
2008-04-07 10:38:37 -07:00
ApplicationContainer apps = onoff.Install (c.Get (0));
apps.Start (Seconds (0.5));
apps.Stop (Seconds (250.0));
2007-08-24 15:19:20 +02:00
2008-03-01 21:21:53 +01:00
Simulator::Schedule (Seconds (1.5), &Experiment::AdvancePosition, this, c.Get (1));
Ptr<Socket> recvSink = SetupPacketReceive (c.Get (1));
2007-10-16 15:43:26 +02:00
2007-08-24 15:19:20 +02:00
Simulator::Run ();
Simulator::Destroy ();
2008-03-01 21:21:53 +01:00
return m_output;
}
int main (int argc, char *argv[])
{
// disable fragmentation
Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
2008-03-01 21:21:53 +01:00
CommandLine cmd;
cmd.Parse (argc, argv);
Gnuplot gnuplot = Gnuplot ("reference-rates.png");
2008-03-01 21:21:53 +01:00
Experiment experiment;
2008-11-04 14:06:34 +01:00
WifiHelper wifi = WifiHelper::Default ();
2009-08-14 12:31:08 +02:00
wifi.SetStandard (WIFI_PHY_STANDARD_80211a);
2009-04-24 10:01:41 +02:00
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
2008-11-04 14:06:34 +01:00
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
2009-01-09 09:54:09 +01:00
Gnuplot2dDataset dataset;
2008-03-01 21:21:53 +01:00
2009-04-24 10:01:41 +02:00
wifiMac.SetType ("ns3::AdhocWifiMac");
2008-03-01 21:21:53 +01:00
NS_LOG_DEBUG ("54");
experiment = Experiment ("54mb");
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue ("wifia-54mbs"));
2009-04-24 10:01:41 +02:00
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
2008-03-01 21:21:53 +01:00
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("48");
experiment = Experiment ("48mb");
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue ("wifia-48mbs"));
2009-04-24 10:01:41 +02:00
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
2008-03-01 21:21:53 +01:00
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("36");
experiment = Experiment ("36mb");
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue ("wifia-36mbs"));
2009-04-24 10:01:41 +02:00
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
2008-03-01 21:21:53 +01:00
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("24");
experiment = Experiment ("24mb");
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue ("wifia-24mbs"));
2009-04-24 10:01:41 +02:00
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
2008-03-01 21:21:53 +01:00
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("18");
experiment = Experiment ("18mb");
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue ("wifia-18mbs"));
2009-04-24 10:01:41 +02:00
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
2008-03-01 21:21:53 +01:00
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("12");
experiment = Experiment ("12mb");
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue ("wifia-12mbs"));
2009-04-24 10:01:41 +02:00
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
2008-03-01 21:21:53 +01:00
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("9");
experiment = Experiment ("9mb");
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue ("wifia-9mbs"));
2009-04-24 10:01:41 +02:00
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
2008-03-01 21:21:53 +01:00
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("6");
experiment = Experiment ("6mb");
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue ("wifia-6mbs"));
2009-04-24 10:01:41 +02:00
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
2008-03-01 21:21:53 +01:00
gnuplot.AddDataset (dataset);
gnuplot.GenerateOutput (std::cout);
2008-03-01 21:21:53 +01:00
gnuplot = Gnuplot ("rate-control.png");
2009-08-14 12:31:08 +02:00
wifi.SetStandard (WIFI_PHY_STANDARD_holland);
2008-03-01 21:21:53 +01:00
NS_LOG_DEBUG ("arf");
experiment = Experiment ("arf");
wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
2009-04-24 10:01:41 +02:00
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
2008-03-01 21:21:53 +01:00
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("aarf");
experiment = Experiment ("aarf");
wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
2009-04-24 10:01:41 +02:00
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
2008-03-01 21:21:53 +01:00
gnuplot.AddDataset (dataset);
2009-04-17 09:13:14 +02:00
NS_LOG_DEBUG ("aarf-cd");
experiment = Experiment ("aarf-cd");
wifi.SetRemoteStationManager ("ns3::AarfcdWifiManager");
2009-04-24 10:01:41 +02:00
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
2009-04-17 09:13:14 +02:00
gnuplot.AddDataset (dataset);
2009-04-17 10:59:51 +02:00
NS_LOG_DEBUG ("cara");
experiment = Experiment ("cara");
wifi.SetRemoteStationManager ("ns3::CaraWifiManager");
2009-04-24 10:01:41 +02:00
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
2009-04-17 10:59:51 +02:00
gnuplot.AddDataset (dataset);
2009-04-17 14:06:20 +02:00
NS_LOG_DEBUG ("rraa");
experiment = Experiment ("rraa");
wifi.SetRemoteStationManager ("ns3::RraaWifiManager");
2009-04-24 10:01:41 +02:00
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
2009-04-17 14:06:20 +02:00
gnuplot.AddDataset (dataset);
2008-03-01 21:21:53 +01:00
NS_LOG_DEBUG ("ideal");
experiment = Experiment ("ideal");
wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
2009-04-24 10:01:41 +02:00
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
2008-03-01 21:21:53 +01:00
gnuplot.AddDataset (dataset);
gnuplot.GenerateOutput (std::cout);
2007-08-24 15:19:20 +02:00
return 0;
}