From 010649d7ba9a0f4faca32190d39fca97a6568547 Mon Sep 17 00:00:00 2001 From: Mitch Watrous Date: Sun, 17 Apr 2011 20:06:22 -0700 Subject: [PATCH] Bug 1088 - Code in scratch directory assumes all modules are enabled --- scratch/multiple-sources/simple-main.cc | 9 --- scratch/multiple-sources/simple-simulation.cc | 66 ---------------- scratch/scratch-simulator.cc | 27 +++++++ scratch/simple.cc | 75 ------------------- 4 files changed, 27 insertions(+), 150 deletions(-) delete mode 100644 scratch/multiple-sources/simple-main.cc delete mode 100644 scratch/multiple-sources/simple-simulation.cc create mode 100644 scratch/scratch-simulator.cc delete mode 100644 scratch/simple.cc diff --git a/scratch/multiple-sources/simple-main.cc b/scratch/multiple-sources/simple-main.cc deleted file mode 100644 index 31488d2d1..000000000 --- a/scratch/multiple-sources/simple-main.cc +++ /dev/null @@ -1,9 +0,0 @@ - -void RunSimulation (void); - -int main (int argc, char *argv[]) -{ - RunSimulation (); - - return 0; -} diff --git a/scratch/multiple-sources/simple-simulation.cc b/scratch/multiple-sources/simple-simulation.cc deleted file mode 100644 index 04b0bbe74..000000000 --- a/scratch/multiple-sources/simple-simulation.cc +++ /dev/null @@ -1,66 +0,0 @@ -#include - -#include "ns3/core-module.h" -#include "ns3/network-module.h" -#include "ns3/internet-module.h" - -using namespace ns3; - -static void -GenerateTraffic (Ptr socket, uint32_t size) -{ - std::cout << "at=" << Simulator::Now ().GetSeconds () << "s, tx bytes=" << size << std::endl; - socket->Send (Create (size)); - if (size > 0) - { - Simulator::Schedule (Seconds (0.5), &GenerateTraffic, socket, size - 50); - } - else - { - socket->Close (); - } -} - -static void -SocketPrinter (Ptr socket) -{ - Ptr packet; - while (packet = socket->Recv ()) - { - std::cout << "at=" << Simulator::Now ().GetSeconds () << "s, rx bytes=" << packet->GetSize () << std::endl; - } -} - -static void -PrintTraffic (Ptr socket) -{ - socket->SetRecvCallback (MakeCallback (&SocketPrinter)); -} - -void -RunSimulation (void) -{ - NodeContainer c; - c.Create (1); - - InternetStackHelper internet; - internet.Install (c); - - - TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); - Ptr sink = Socket::CreateSocket (c.Get (0), tid); - InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80); - sink->Bind (local); - - Ptr source = Socket::CreateSocket (c.Get (0), tid); - InetSocketAddress remote = InetSocketAddress (Ipv4Address::GetLoopback (), 80); - source->Connect (remote); - - GenerateTraffic (source, 500); - PrintTraffic (sink); - - - Simulator::Run (); - - Simulator::Destroy (); -} diff --git a/scratch/scratch-simulator.cc b/scratch/scratch-simulator.cc new file mode 100644 index 000000000..f11de3ccd --- /dev/null +++ b/scratch/scratch-simulator.cc @@ -0,0 +1,27 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * 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 + */ + +#include "ns3/core-module.h" + +NS_LOG_COMPONENT_DEFINE ("ScratchSimulator"); + +using namespace ns3; + +int +main (int argc, char *argv[]) +{ + NS_LOG_UNCOND ("Scratch Simulator"); +} diff --git a/scratch/simple.cc b/scratch/simple.cc deleted file mode 100644 index 078500115..000000000 --- a/scratch/simple.cc +++ /dev/null @@ -1,75 +0,0 @@ -#include - -#include "ns3/core-module.h" -#include "ns3/network-module.h" -#include "ns3/internet-module.h" - -using namespace ns3; - -static void -GenerateTraffic (Ptr socket, uint32_t size) -{ - std::cout << "at=" << Simulator::Now ().GetSeconds () << "s, tx bytes=" << size << std::endl; - socket->Send (Create (size)); - if (size > 0) - { - Simulator::Schedule (Seconds (0.5), &GenerateTraffic, socket, size - 50); - } - else - { - socket->Close (); - } -} - -static void -SocketPrinter (Ptr socket) -{ - Ptr packet; - while (packet = socket->Recv ()) - { - std::cout << "at=" << Simulator::Now ().GetSeconds () << "s, rx bytes=" << packet->GetSize () << std::endl; - } -} - -static void -PrintTraffic (Ptr socket) -{ - socket->SetRecvCallback (MakeCallback (&SocketPrinter)); -} - -void -RunSimulation (void) -{ - NodeContainer c; - c.Create (1); - - InternetStackHelper internet; - internet.Install (c); - - - TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); - Ptr sink = Socket::CreateSocket (c.Get (0), tid); - InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80); - sink->Bind (local); - - Ptr source = Socket::CreateSocket (c.Get (0), tid); - InetSocketAddress remote = InetSocketAddress (Ipv4Address::GetLoopback (), 80); - source->Connect (remote); - - Simulator::ScheduleWithContext (source->GetNode ()->GetId (), - Seconds (0.0), - &GenerateTraffic, source, 500); - PrintTraffic (sink); - - - Simulator::Run (); - - Simulator::Destroy (); -} - -int main (int argc, char *argv[]) -{ - RunSimulation (); - - return 0; -}