[Bug 221] need a scratch directory
This commit is contained in:
9
scratch/multiple-sources/simple-main.cc
Normal file
9
scratch/multiple-sources/simple-main.cc
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
void RunSimulation (void);
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
RunSimulation ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
67
scratch/multiple-sources/simple-simulation.cc
Normal file
67
scratch/multiple-sources/simple-simulation.cc
Normal file
@@ -0,0 +1,67 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "ns3/core-module.h"
|
||||
#include "ns3/helper-module.h"
|
||||
#include "ns3/node-module.h"
|
||||
#include "ns3/simulator-module.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
static void
|
||||
GenerateTraffic (Ptr<Socket> socket, uint32_t size)
|
||||
{
|
||||
std::cout << "at=" << Simulator::Now ().GetSeconds () << "s, tx bytes=" << size << std::endl;
|
||||
socket->Send (Create<Packet> (size));
|
||||
if (size > 0)
|
||||
{
|
||||
Simulator::Schedule (Seconds (0.5), &GenerateTraffic, socket, size - 50);
|
||||
}
|
||||
else
|
||||
{
|
||||
socket->Close ();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
SocketPrinter (Ptr<Socket> socket)
|
||||
{
|
||||
Ptr<Packet> packet;
|
||||
while (packet = socket->Recv ())
|
||||
{
|
||||
std::cout << "at=" << Simulator::Now ().GetSeconds () << "s, rx bytes=" << packet->GetSize () << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
PrintTraffic (Ptr<Socket> 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<Socket> sink = Socket::CreateSocket (c.Get (0), tid);
|
||||
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
|
||||
sink->Bind (local);
|
||||
|
||||
Ptr<Socket> 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 ();
|
||||
}
|
||||
74
scratch/simple.cc
Normal file
74
scratch/simple.cc
Normal file
@@ -0,0 +1,74 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "ns3/core-module.h"
|
||||
#include "ns3/helper-module.h"
|
||||
#include "ns3/node-module.h"
|
||||
#include "ns3/simulator-module.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
static void
|
||||
GenerateTraffic (Ptr<Socket> socket, uint32_t size)
|
||||
{
|
||||
std::cout << "at=" << Simulator::Now ().GetSeconds () << "s, tx bytes=" << size << std::endl;
|
||||
socket->Send (Create<Packet> (size));
|
||||
if (size > 0)
|
||||
{
|
||||
Simulator::Schedule (Seconds (0.5), &GenerateTraffic, socket, size - 50);
|
||||
}
|
||||
else
|
||||
{
|
||||
socket->Close ();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
SocketPrinter (Ptr<Socket> socket)
|
||||
{
|
||||
Ptr<Packet> packet;
|
||||
while (packet = socket->Recv ())
|
||||
{
|
||||
std::cout << "at=" << Simulator::Now ().GetSeconds () << "s, rx bytes=" << packet->GetSize () << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
PrintTraffic (Ptr<Socket> 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<Socket> sink = Socket::CreateSocket (c.Get (0), tid);
|
||||
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
|
||||
sink->Bind (local);
|
||||
|
||||
Ptr<Socket> 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 ();
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
RunSimulation ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
15
wscript
15
wscript
@@ -230,6 +230,19 @@ def create_ns3_program(bld, name, dependencies=('simulator',)):
|
||||
program.ns3_module_dependencies = ['ns3-'+dep for dep in dependencies]
|
||||
return program
|
||||
|
||||
def add_scratch_programs(bld):
|
||||
all_modules = [mod[len("ns3-"):] for mod in bld.env()['NS3_MODULES']]
|
||||
for filename in os.listdir("scratch"):
|
||||
if os.path.isdir(os.path.join("scratch", filename)):
|
||||
obj = bld.create_ns3_program(filename, all_modules)
|
||||
obj.path = obj.path.find_dir('scratch')
|
||||
obj.find_sources_in_dirs(filename)
|
||||
obj.target = os.path.join(filename, filename)
|
||||
elif filename.endswith(".cc"):
|
||||
name = filename[:-len(".cc")]
|
||||
obj = bld.create_ns3_program(name, all_modules)
|
||||
obj.source = "scratch/%s" % filename
|
||||
obj.target = "scratch/%s" % name
|
||||
|
||||
def build(bld):
|
||||
if Params.g_options.no_task_lines:
|
||||
@@ -263,6 +276,8 @@ def build(bld):
|
||||
bld.add_subdirs('src')
|
||||
bld.add_subdirs('samples utils examples tutorial')
|
||||
|
||||
add_scratch_programs(bld)
|
||||
|
||||
## if --enabled-modules option was given, we disable building the
|
||||
## modules that were not enabled, and programs that depend on
|
||||
## disabled modules.
|
||||
|
||||
Reference in New Issue
Block a user