/* -*- 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 */ #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" #include "ns3/wifi-module.h" #include "ns3/athstats-helper.h" #include using namespace ns3; static bool g_verbose = true; void DevTxTrace (std::string context, Ptr p) { if (g_verbose) { std::cout << " TX p: " << *p << std::endl; } } void DevRxTrace (std::string context, Ptr p) { if (g_verbose) { std::cout << " RX p: " << *p << std::endl; } } void PhyRxOkTrace (std::string context, Ptr packet, double snr, WifiMode mode, enum WifiPreamble preamble) { if (g_verbose) { std::cout << "PHYRXOK mode=" << mode << " snr=" << snr << " " << *packet << std::endl; } } void PhyRxErrorTrace (std::string context, Ptr packet, double snr) { if (g_verbose) { std::cout << "PHYRXERROR snr=" << snr << " " << *packet << std::endl; } } void PhyTxTrace (std::string context, Ptr packet, WifiMode mode, WifiPreamble preamble, uint8_t txPower) { if (g_verbose) { std::cout << "PHYTX mode=" << mode << " " << *packet << std::endl; } } void PhyStateTrace (std::string context, Time start, Time duration, enum WifiPhy::State state) { if (g_verbose) { std::cout << " state=" << state << " start=" << start << " duration=" << duration << std::endl; } } static void SetPosition (Ptr node, Vector position) { Ptr mobility = node->GetObject (); mobility->SetPosition (position); } static Vector GetPosition (Ptr node) { Ptr mobility = node->GetObject (); return mobility->GetPosition (); } static void AdvancePosition (Ptr node) { Vector pos = GetPosition (node); pos.x += 5.0; if (pos.x >= 210.0) { return; } SetPosition (node, pos); if (g_verbose) { //std::cout << "x="<GetIfIndex ()); socket.SetPhysicalAddress (staDevs.Get (1)->GetAddress ()); socket.SetProtocol (1); OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket)); onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (42))); onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); ApplicationContainer apps = onoff.Install (stas.Get (0)); apps.Start (Seconds (0.5)); apps.Stop (Seconds (43.0)); Simulator::Stop (Seconds (44.0)); Config::Connect ("/NodeList/*/DeviceList/*/Mac/MacTx", MakeCallback (&DevTxTrace)); Config::Connect ("/NodeList/*/DeviceList/*/Mac/MacRx", MakeCallback (&DevRxTrace)); 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)); AthstatsHelper athstats; athstats.EnableAthstats("athstats-sta", stas); athstats.EnableAthstats("athstats-ap", ap); Simulator::Run (); Simulator::Destroy (); return 0; }