branch merge

This commit is contained in:
Tom Henderson
2008-05-10 20:22:27 -07:00
17 changed files with 93 additions and 56 deletions

View File

@@ -68,7 +68,7 @@ main (int argc, char *argv[])
n0->AddDevice (net0);
Ptr<Queue> q = CreateObject<DropTailQueue> ();
net0->AddQueue(q);
net0->SetQueue(q);
// At this point, we have created a single node (Node 0) and a
// single PointToPointNetDevice (NetDevice 0) and added a

View File

@@ -351,7 +351,7 @@ LogComponentPrintList (void)
}
}
void LogRegisterTimePrinter (LogTimePrinter printer)
void LogSetTimePrinter (LogTimePrinter printer)
{
g_logTimePrinter = printer;
}

View File

@@ -308,7 +308,7 @@ void LogComponentPrintList (void);
typedef void (*LogTimePrinter) (std::ostream &os);
void LogRegisterTimePrinter (LogTimePrinter);
void LogSetTimePrinter (LogTimePrinter);
LogTimePrinter LogGetTimePrinter(void);
@@ -374,6 +374,9 @@ public:
#define LogComponentDisableAll(level)
#define LogRegisterTimePrinter(printer)
#define LogSetTimePrinter(printer)
#define LogGetTimePrinter
#endif /* LOG_ENABLE */
#endif // __LOG_H__

View File

@@ -404,14 +404,14 @@ CsmaNetDevice::Attach (Ptr<CsmaChannel> ch)
}
void
CsmaNetDevice::AddQueue (Ptr<Queue> q)
CsmaNetDevice::SetQueue (Ptr<Queue> q)
{
NS_LOG_FUNCTION (this << q);
m_queue = q;
}
void CsmaNetDevice::AddReceiveErrorModel (Ptr<ErrorModel> em)
void CsmaNetDevice::SetReceiveErrorModel (Ptr<ErrorModel> em)
{
NS_LOG_FUNCTION (em);

View File

@@ -150,7 +150,7 @@ enum CsmaEncapsulationMode {
* \param queue a pointer to the queue for which object is assuming
* ownership.
*/
void AddQueue (Ptr<Queue> queue);
void SetQueue (Ptr<Queue> queue);
/**
* Attach a receive ErrorModel to the CsmaNetDevice.
*
@@ -160,7 +160,7 @@ enum CsmaEncapsulationMode {
* @see ErrorModel
* @param em a pointer to the ErrorModel
*/
void AddReceiveErrorModel(Ptr<ErrorModel> em);
void SetReceiveErrorModel(Ptr<ErrorModel> em);
/**
* Receive a packet from a connected CsmaChannel.
*

View File

@@ -207,14 +207,14 @@ PointToPointNetDevice::Attach (Ptr<PointToPointChannel> ch)
return true;
}
void PointToPointNetDevice::AddQueue (Ptr<Queue> q)
void PointToPointNetDevice::SetQueue (Ptr<Queue> q)
{
NS_LOG_FUNCTION (this << q);
m_queue = q;
}
void PointToPointNetDevice::AddReceiveErrorModel (Ptr<ErrorModel> em)
void PointToPointNetDevice::SetReceiveErrorModel (Ptr<ErrorModel> em)
{
NS_LOG_FUNCTION ("(" << em << ")");

View File

@@ -121,7 +121,7 @@ public:
* @param queue a pointer to the queue for which object is assuming
* ownership.
*/
void AddQueue (Ptr<Queue> queue);
void SetQueue (Ptr<Queue> queue);
/**
* Attach a receive ErrorModel to the PointToPointNetDevice.
*
@@ -131,7 +131,7 @@ public:
* @see ErrorModel
* @param em a pointer to the ErrorModel
*/
void AddReceiveErrorModel(Ptr<ErrorModel> em);
void SetReceiveErrorModel(Ptr<ErrorModel> em);
/**
* Receive a packet from a connected PointToPointChannel.
*

View File

@@ -44,10 +44,10 @@ PointToPointTest::RunTests (void)
devA->Attach (channel);
devA->SetAddress (Mac48Address::Allocate ());
devA->AddQueue (CreateObject<DropTailQueue> ());
devA->SetQueue (CreateObject<DropTailQueue> ());
devB->Attach (channel);
devB->SetAddress (Mac48Address::Allocate ());
devB->AddQueue (CreateObject<DropTailQueue> ());
devB->SetQueue (CreateObject<DropTailQueue> ());
a->AddDevice (devA);
b->AddDevice (devB);

View File

@@ -174,7 +174,7 @@ CsmaHelper::Install (const NodeContainer &c, Ptr<CsmaChannel> channel)
device->SetAddress (Mac48Address::Allocate ());
node->AddDevice (device);
Ptr<Queue> queue = m_queueFactory.Create<Queue> ();
device->AddQueue (queue);
device->SetQueue (queue);
device->Attach (channel);
container.Add (device);
}

View File

@@ -25,12 +25,28 @@
#include "ns3/internet-stack.h"
#include "ns3/packet-socket-factory.h"
#include "ns3/config.h"
#include "ns3/simulator.h"
namespace ns3 {
std::vector<InternetStackHelper::Trace> InternetStackHelper::m_traces;
std::string InternetStackHelper::m_pcapBaseFilename;
void
InternetStackHelper::Cleanup (void)
{
uint32_t illegal = std::numeric_limits<uint32_t>::max();
for (std::vector<Trace>::iterator i = m_traces.begin ();
i != m_traces.end (); i++)
{
i->nodeId = illegal;
i->interfaceId = illegal;
i->writer = 0;
}
m_traces.clear ();
}
void
InternetStackHelper::Install (NodeContainer c)
{
@@ -52,6 +68,8 @@ InternetStackHelper::Install (NodeContainer c)
void
InternetStackHelper::EnablePcapAll (std::string filename)
{
Simulator::ScheduleDestroy (&InternetStackHelper::Cleanup);
InternetStackHelper::m_pcapBaseFilename = filename;
Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Tx",
MakeCallback (&InternetStackHelper::LogTxIp));

View File

@@ -49,10 +49,18 @@ public:
*
* Enable pcap output on each protocol instance which is of the
* ns3::Ipv4L3Protocol type. Both Tx and Rx events will be logged.
*
* \warning If you perform multiple simulations in a single script,
* each iteration of the simulation will result in the trace files
* being overwritten. We don't attempt to anticipate what a user
* might actually want to do, so we leave it up to them. If you want
* to save any particular data, do so manually at inter-simulation
* time.
*/
static void EnablePcapAll (std::string filename);
private:
static void Cleanup (void);
static void LogRxIp (std::string context, Ptr<const Packet> packet, uint32_t deviceId);
static void LogTxIp (std::string context, Ptr<const Packet> packet, uint32_t deviceId);
static Ptr<PcapWriter> GetStream (uint32_t nodeId, uint32_t interfaceId);

View File

@@ -170,12 +170,12 @@ PointToPointHelper::Install (Ptr<Node> a, Ptr<Node> b)
devA->SetAddress (Mac48Address::Allocate ());
a->AddDevice (devA);
Ptr<Queue> queueA = m_queueFactory.Create<Queue> ();
devA->AddQueue (queueA);
devA->SetQueue (queueA);
Ptr<PointToPointNetDevice> devB = m_deviceFactory.Create<PointToPointNetDevice> ();
devB->SetAddress (Mac48Address::Allocate ());
b->AddDevice (devB);
Ptr<Queue> queueB = m_queueFactory.Create<Queue> ();
devB->AddQueue (queueB);
devB->SetQueue (queueB);
Ptr<PointToPointChannel> channel = m_channelFactory.Create<PointToPointChannel> ();
devA->Attach (channel);
devB->Attach (channel);

View File

@@ -262,12 +262,10 @@ Ipv4AddressGeneratorImpl::AddAllocated (const Ipv4Address address)
NS_ASSERT_MSG (addr, "Ipv4AddressGeneratorImpl::Add(): "
"Allocating the broadcast address is not a good idea");
std::list<Entry>::iterator i;
std::list<Entry>::iterator i, j;
for (i = m_entries.begin (), j = m_entries.begin (), ++j;
i != m_entries.end ();
++i, ++j)
for (i = m_entries.begin (); i != m_entries.end (); ++i)
{
NS_LOG_LOGIC ("examine entry: " << Ipv4Address ((*i).addrLow) <<
" to " << Ipv4Address ((*i).addrHigh));
@@ -277,11 +275,12 @@ Ipv4AddressGeneratorImpl::AddAllocated (const Ipv4Address address)
//
if (addr >= (*i).addrLow && addr <= (*i).addrHigh)
{
NS_LOG_LOGIC ("Ipv4AddressGeneratorImpl::Add(): Address Collision: " << Ipv4Address (addr));
NS_LOG_LOGIC ("Ipv4AddressGeneratorImpl::Add(): "
"Address Collision: " << Ipv4Address (addr));
if (!m_test)
{
NS_ASSERT_MSG (0,
"Ipv4AddressGeneratorImpl::Add(): Address Collision: " << Ipv4Address (addr));
NS_ASSERT_MSG (0, "Ipv4AddressGeneratorImpl::Add(): "
"Address Collision: " << Ipv4Address (addr));
}
return false;
}
@@ -303,6 +302,9 @@ Ipv4AddressGeneratorImpl::AddAllocated (const Ipv4Address address)
//
if (addr == (*i).addrHigh + 1)
{
std::list<Entry>::iterator j = i;
++j;
if (j != m_entries.end ())
{
if (addr == (*j).addrLow)

View File

@@ -428,10 +428,16 @@ Simulator::GetPriv (void)
{
if (m_priv == 0)
{
LogRegisterTimePrinter (&TimePrinter);
/* Note: we call LogSetTimePrinter below _after_ calling CreateObject because
* CreateObject can trigger calls to the logging framework which would call
* the TimePrinter function above which would call Simulator::Now which would
* call Simulator::GetPriv, and, thus, get us in an infinite recursion until the
* stack explodes.
*/
m_priv = CreateObject<SimulatorPrivate> ();
Ptr<Scheduler> scheduler = CreateObject<MapScheduler> ();
m_priv->SetScheduler (scheduler);
LogSetTimePrinter (&TimePrinter);
}
TRACE_S ("priv " << m_priv);
return m_priv;
@@ -444,6 +450,12 @@ Simulator::Destroy (void)
{
return;
}
/* Note: we have to call LogSetTimePrinter (0) below because if we do not do this,
* and restart a simulation after this call to Destroy, (which is legal),
* Simulator::GetPriv will trigger again an infinite recursion until the stack
* explodes.
*/
LogSetTimePrinter (0);
m_priv->Destroy ();
m_priv = 0;
}

View File

@@ -69,33 +69,27 @@ def create_ns3_module(bld, name, dependencies=()):
def build(bld):
Object.register('ns3header', Ns3Header)
#Object.register('ns3header', Ns3Header)
Action.Action('ns3header', func=_ns3_headers_inst, color='BLUE')
Object.register('ns3-module-header', Ns3ModuleHeader)
#Object.register('ns3-module-header', Ns3ModuleHeader)
Action.Action('gen-ns3-module-header', func=gen_ns3_module_header, color='BLUE')
bld.create_ns3_module = types.MethodType(create_ns3_module, bld)
bld.add_subdirs(list(all_modules))
for module in all_modules:
modheader = bld.create_obj('ns3-module-header')
modheader = bld.create_obj('ns3moduleheader')
modheader.module = module.split('/')[-1]
class Ns3Header(Object.genobj):
class ns3header_taskgen(Object.task_gen):
"""A set of NS-3 header files"""
def __init__(self, env=None):
Object.genobj.__init__(self, 'ns3header')
def __init__(self, *features):
Object.task_gen.__init__(self, *features)
self.inst_var = 'INCLUDEDIR'
self.inst_dir = 'ns3'
self.sub_dir = None # if not None, header files will be published as ns3/sub_dir/file.h
self.module = None # module name
self.env = env
if not self.env:
self.env = Params.g_build.m_allenvs['default']
def get_valid_types(self):
return ['ns3header']
def apply(self):
if self.module is None:
@@ -169,17 +163,13 @@ def gen_ns3_module_header(task):
return 0
class Ns3ModuleHeader(Object.genobj):
class ns3moduleheader_taskgen(Object.task_gen):
"""
Generates a 'ns3/foo-module.h' header file that includes all
public ns3 headers of a certain module.
"""
def __init__(self, env=None):
Object.genobj.__init__(self, 'other')
self.install_var = 0
self.env = env
if not self.env:
self.env = Params.g_build.m_allenvs['default'].copy()
def __init__(self, *features):
Object.task_gen.__init__(self, *features)
self.module_name = None
def apply(self):
@@ -187,7 +177,7 @@ class Ns3ModuleHeader(Object.genobj):
ns3_dir_node = Params.g_build.m_srcnode.find_dir("ns3")
all_headers_inputs = []
for ns3headers in Object.g_allobjs:
if ns3headers.m_type == 'ns3header':
if isinstance(ns3headers, ns3header_taskgen):
if ns3headers.module != self.module:
continue
for source in ns3headers.to_list(ns3headers.source):

10
waf vendored

File diff suppressed because one or more lines are too long

16
wscript
View File

@@ -6,9 +6,11 @@ import types
import optparse
import os.path
import pproc as subprocess
import Params
import Object
import pproc as subprocess
import ccroot
Params.g_autoconfig = 1
@@ -218,6 +220,7 @@ def configure(conf):
def create_ns3_program(bld, name, dependencies=('simulator',)):
program = bld.create_obj('cpp', 'program')
program.is_ns3_program = True
program.name = name
program.target = program.name
program.uselib_local = 'ns3'
@@ -252,7 +255,7 @@ def build(bld):
doxygen()
raise SystemExit(0)
print "Entering directory `%s/build'" % Params.g_build.m_curdirnode.abspath()
print "Entering directory `%s'" % os.path.join(Params.g_build.m_curdirnode.abspath(), 'build')
# process subfolders from here
bld.add_subdirs('src')
bld.add_subdirs('samples utils examples tutorial')
@@ -351,7 +354,7 @@ def _run_waf_check():
# --enable-modules=xxx
pass
else:
prog = program_obj.path.find_build(program_obj.get_target_name()).abspath(env)
prog = program_obj.path.find_build(ccroot.get_target_name(program_obj)).abspath(env)
out = open('doc/introspected-doxygen.h', 'w')
if subprocess.Popen([prog], stdout=out, env=proc_env).wait():
raise SystemExit(1)
@@ -359,12 +362,11 @@ def _run_waf_check():
run_program('run-tests', get_command_template())
def _find_program(program_name, env):
launch_dir = os.path.abspath(Params.g_cwd_launch)
found_programs = []
for obj in Object.g_allobjs:
if obj.m_type != 'program' or not obj.target:
if not getattr(obj, 'is_ns3_program', False):
continue
## filter out programs not in the subtree starting at the launch dir
@@ -430,7 +432,7 @@ def run_program(program_string, command_template=None):
Params.fatal(str(ex))
try:
program_node = program_obj.path.find_build(program_obj.get_target_name())
program_node = program_obj.path.find_build(ccroot.get_target_name(program_obj))
except AttributeError:
Params.fatal("%s does not appear to be a program" % (program_name,))
@@ -444,7 +446,7 @@ def run_program(program_string, command_template=None):
except ValueError, ex:
Params.fatal(str(ex))
try:
program_node = program_obj.path.find_build(program_obj.get_target_name())
program_node = program_obj.path.find_build(ccroot.get_target_name(program_obj))
except AttributeError:
Params.fatal("%s does not appear to be a program" % (program_name,))