2007-10-19 12:10:01 +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>
|
|
|
|
|
*/
|
|
|
|
|
|
2007-10-31 12:27:20 +01:00
|
|
|
|
2008-03-25 14:16:40 -07:00
|
|
|
#include "ns3/core-module.h"
|
2011-02-21 09:11:37 -08:00
|
|
|
#include "ns3/network-module.h"
|
2011-03-02 13:42:28 -08:00
|
|
|
#include "ns3/applications-module.h"
|
2008-03-25 14:16:40 -07:00
|
|
|
#include "ns3/mobility-module.h"
|
|
|
|
|
#include "ns3/wifi-module.h"
|
2007-10-19 12:10:01 +02:00
|
|
|
|
|
|
|
|
using namespace ns3;
|
|
|
|
|
|
2009-10-01 14:12:56 -07:00
|
|
|
static bool g_verbose = true;
|
|
|
|
|
|
2007-11-08 15:23:06 +01:00
|
|
|
void
|
2009-04-16 11:00:13 +02:00
|
|
|
DevTxTrace (std::string context, Ptr<const Packet> p)
|
2007-10-31 11:45:04 +01:00
|
|
|
{
|
2009-10-01 14:12:56 -07:00
|
|
|
if (g_verbose)
|
|
|
|
|
{
|
|
|
|
|
std::cout << " TX p: " << *p << std::endl;
|
|
|
|
|
}
|
2007-10-31 11:45:04 +01:00
|
|
|
}
|
2007-11-08 15:23:06 +01:00
|
|
|
void
|
2009-04-16 11:00:13 +02:00
|
|
|
DevRxTrace (std::string context, Ptr<const Packet> p)
|
2008-03-19 12:41:06 -07:00
|
|
|
{
|
2009-10-01 14:12:56 -07:00
|
|
|
if (g_verbose)
|
|
|
|
|
{
|
|
|
|
|
std::cout << " RX p: " << *p << std::endl;
|
|
|
|
|
}
|
2008-03-19 12:41:06 -07:00
|
|
|
}
|
|
|
|
|
void
|
|
|
|
|
PhyRxOkTrace (std::string context, Ptr<const Packet> packet, double snr, WifiMode mode, enum WifiPreamble preamble)
|
|
|
|
|
{
|
2009-10-01 14:12:56 -07:00
|
|
|
if (g_verbose)
|
|
|
|
|
{
|
|
|
|
|
std::cout << "PHYRXOK mode=" << mode << " snr=" << snr << " " << *packet << std::endl;
|
|
|
|
|
}
|
2008-03-19 12:41:06 -07:00
|
|
|
}
|
|
|
|
|
void
|
|
|
|
|
PhyRxErrorTrace (std::string context, Ptr<const Packet> packet, double snr)
|
|
|
|
|
{
|
2009-10-01 14:12:56 -07:00
|
|
|
if (g_verbose)
|
|
|
|
|
{
|
|
|
|
|
std::cout << "PHYRXERROR snr=" << snr << " " << *packet << std::endl;
|
|
|
|
|
}
|
2008-03-19 12:41:06 -07:00
|
|
|
}
|
|
|
|
|
void
|
|
|
|
|
PhyTxTrace (std::string context, Ptr<const Packet> packet, WifiMode mode, WifiPreamble preamble, uint8_t txPower)
|
|
|
|
|
{
|
2009-10-01 14:12:56 -07:00
|
|
|
if (g_verbose)
|
|
|
|
|
{
|
|
|
|
|
std::cout << "PHYTX mode=" << mode << " " << *packet << std::endl;
|
|
|
|
|
}
|
2008-03-19 12:41:06 -07:00
|
|
|
}
|
|
|
|
|
void
|
|
|
|
|
PhyStateTrace (std::string context, Time start, Time duration, enum WifiPhy::State state)
|
2007-10-31 12:27:20 +01:00
|
|
|
{
|
2009-10-01 14:12:56 -07:00
|
|
|
if (g_verbose)
|
|
|
|
|
{
|
2009-11-30 18:40:35 +01:00
|
|
|
std::cout << " state=" << state << " start=" << start << " duration=" << duration << std::endl;
|
2009-10-01 14:12:56 -07:00
|
|
|
}
|
2007-10-31 12:27:20 +01:00
|
|
|
}
|
2007-10-31 11:45:04 +01:00
|
|
|
|
2007-10-19 12:10:01 +02:00
|
|
|
static void
|
2007-11-15 10:22:35 +01:00
|
|
|
SetPosition (Ptr<Node> node, Vector position)
|
2007-10-19 12:10:01 +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-10-19 12:10:01 +02:00
|
|
|
}
|
|
|
|
|
|
2007-11-15 10:22:35 +01:00
|
|
|
static Vector
|
2007-10-19 12:10:01 +02:00
|
|
|
GetPosition (Ptr<Node> node)
|
|
|
|
|
{
|
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-10-19 12:10:01 +02:00
|
|
|
}
|
|
|
|
|
|
2017-02-06 20:31:02 +01:00
|
|
|
static void
|
|
|
|
|
AdvancePosition (Ptr<Node> node)
|
2007-10-19 12:10:01 +02:00
|
|
|
{
|
2007-11-15 10:22:35 +01:00
|
|
|
Vector pos = GetPosition (node);
|
2007-10-19 12:10:01 +02:00
|
|
|
pos.x += 5.0;
|
2017-02-06 20:31:02 +01:00
|
|
|
if (pos.x >= 210.0)
|
2007-11-21 11:12:02 +01:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2007-10-19 12:10:01 +02:00
|
|
|
SetPosition (node, pos);
|
2009-10-01 14:12:56 -07:00
|
|
|
|
2007-10-19 12:10:01 +02:00
|
|
|
Simulator::Schedule (Seconds (1.0), &AdvancePosition, node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main (int argc, char *argv[])
|
|
|
|
|
{
|
2009-08-24 13:32:06 +02:00
|
|
|
CommandLine cmd;
|
2009-10-01 14:12:56 -07:00
|
|
|
cmd.AddValue ("verbose", "Print trace information if true", g_verbose);
|
|
|
|
|
|
|
|
|
|
cmd.Parse (argc, argv);
|
2010-12-01 22:13:26 +00:00
|
|
|
|
2008-08-25 15:21:01 -07:00
|
|
|
Packet::EnablePrinting ();
|
2007-10-23 13:40:08 +02:00
|
|
|
|
2007-10-19 12:10:01 +02:00
|
|
|
// enable rts cts all the time.
|
2008-04-17 13:42:25 -07:00
|
|
|
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("0"));
|
2007-10-19 12:10:01 +02:00
|
|
|
// disable fragmentation
|
2008-04-17 13:42:25 -07:00
|
|
|
Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
|
2007-10-19 12:10:01 +02:00
|
|
|
|
2016-02-05 21:48:25 +01:00
|
|
|
WifiHelper wifi;
|
2008-03-02 01:53:26 +01:00
|
|
|
MobilityHelper mobility;
|
|
|
|
|
NodeContainer stas;
|
|
|
|
|
NodeContainer ap;
|
|
|
|
|
NetDeviceContainer staDevs;
|
2008-03-25 14:16:40 -07:00
|
|
|
PacketSocketHelper packetSocket;
|
2007-10-19 12:10:01 +02:00
|
|
|
|
2008-03-02 01:53:26 +01:00
|
|
|
stas.Create (2);
|
|
|
|
|
ap.Create (1);
|
2007-10-19 12:10:01 +02:00
|
|
|
|
2008-03-25 14:16:40 -07:00
|
|
|
// give packet socket powers to nodes.
|
2008-04-07 10:38:37 -07:00
|
|
|
packetSocket.Install (stas);
|
|
|
|
|
packetSocket.Install (ap);
|
2008-03-25 14:16:40 -07:00
|
|
|
|
2016-02-05 21:48:25 +01:00
|
|
|
WifiMacHelper wifiMac;
|
2008-11-04 14:06:34 +01:00
|
|
|
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
|
|
|
|
|
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
|
|
|
|
|
wifiPhy.SetChannel (wifiChannel.Create ());
|
2008-03-02 01:53:26 +01:00
|
|
|
Ssid ssid = Ssid ("wifi-default");
|
2008-03-13 12:56:49 -07:00
|
|
|
wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
|
2008-03-24 19:00:18 +00:00
|
|
|
// setup stas.
|
2010-12-02 07:51:34 +00:00
|
|
|
wifiMac.SetType ("ns3::StaWifiMac",
|
2017-11-04 09:15:01 +01:00
|
|
|
"ActiveProbing", BooleanValue (true),
|
2016-07-02 11:48:13 +02:00
|
|
|
"Ssid", SsidValue (ssid));
|
2009-04-24 10:01:41 +02:00
|
|
|
staDevs = wifi.Install (wifiPhy, wifiMac, stas);
|
2008-03-24 19:00:18 +00:00
|
|
|
// setup ap.
|
2010-12-02 07:51:34 +00:00
|
|
|
wifiMac.SetType ("ns3::ApWifiMac",
|
|
|
|
|
"Ssid", SsidValue (ssid));
|
2009-04-24 10:01:41 +02:00
|
|
|
wifi.Install (wifiPhy, wifiMac, ap);
|
2008-03-02 01:53:26 +01:00
|
|
|
|
|
|
|
|
// mobility.
|
2008-04-13 15:46:17 -07:00
|
|
|
mobility.Install (stas);
|
|
|
|
|
mobility.Install (ap);
|
2008-03-02 01:53:26 +01:00
|
|
|
|
|
|
|
|
Simulator::Schedule (Seconds (1.0), &AdvancePosition, ap.Get (0));
|
2007-10-19 12:10:01 +02:00
|
|
|
|
2008-04-07 18:29:38 -07:00
|
|
|
PacketSocketAddress socket;
|
2011-05-22 23:18:47 -07:00
|
|
|
socket.SetSingleDevice (staDevs.Get (0)->GetIfIndex ());
|
2008-04-07 18:29:38 -07:00
|
|
|
socket.SetPhysicalAddress (staDevs.Get (1)->GetAddress ());
|
|
|
|
|
socket.SetProtocol (1);
|
|
|
|
|
|
2008-05-27 15:57:51 -07:00
|
|
|
OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket));
|
2012-08-23 16:00:17 -07:00
|
|
|
onoff.SetConstantRate (DataRate ("500kb/s"));
|
2008-04-07 18:29:38 -07:00
|
|
|
|
2008-04-07 10:38:37 -07:00
|
|
|
ApplicationContainer apps = onoff.Install (stas.Get (0));
|
2008-03-25 14:16:40 -07:00
|
|
|
apps.Start (Seconds (0.5));
|
|
|
|
|
apps.Stop (Seconds (43.0));
|
2007-10-19 12:10:01 +02:00
|
|
|
|
2008-05-29 11:45:57 +01:00
|
|
|
Simulator::Stop (Seconds (44.0));
|
2008-02-20 19:40:36 +01:00
|
|
|
|
2009-04-16 11:00:13 +02:00
|
|
|
Config::Connect ("/NodeList/*/DeviceList/*/Mac/MacTx", MakeCallback (&DevTxTrace));
|
|
|
|
|
Config::Connect ("/NodeList/*/DeviceList/*/Mac/MacRx", MakeCallback (&DevRxTrace));
|
2008-06-12 11:55:22 -07:00
|
|
|
Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/RxOk", MakeCallback (&PhyRxOkTrace));
|
|
|
|
|
Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/RxError", MakeCallback (&PhyRxErrorTrace));
|
|
|
|
|
Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/Tx", MakeCallback (&PhyTxTrace));
|
|
|
|
|
Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/State", MakeCallback (&PhyStateTrace));
|
2010-12-01 22:13:26 +00:00
|
|
|
|
2009-08-24 13:32:06 +02:00
|
|
|
AthstatsHelper athstats;
|
2011-05-22 23:18:47 -07:00
|
|
|
athstats.EnableAthstats ("athstats-sta", stas);
|
|
|
|
|
athstats.EnableAthstats ("athstats-ap", ap);
|
2007-10-31 11:45:04 +01:00
|
|
|
|
2007-10-19 12:10:01 +02:00
|
|
|
Simulator::Run ();
|
|
|
|
|
|
|
|
|
|
Simulator::Destroy ();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|