Add building options for NS3 module (highly experimental)
diff --git a/model/sync-ns3-name-info.cc b/model/sync-ns3-name-info.cc
index b46d1f6..dfd6179 100644
--- a/model/sync-ns3-name-info.cc
+++ b/model/sync-ns3-name-info.cc
@@ -35,25 +35,35 @@
namespace Sync {
-
NameInfoConstPtr
Ns3NameInfo::FindOrCreate (ns3::Ptr<const ns3::CcnxNameComponents> name)
{
+ mutex::scoped_lock namesLock (m_namesMutex);
+
+ NameInfoConstPtr ret;
string key = lexical_cast<string> (*name);
-
+
NameMap::iterator item = m_names.find (key);
- if (item == m_names.end ())
+ if (item != m_names.end ())
{
- NameInfoPtr value = NameInfoPtr (new Ns3NameInfo (name));
+ ret = item->second.lock ();
+ BOOST_ASSERT (ret != 0);
+ }
+ else
+ {
+ ret = NameInfoPtr (new Ns3NameInfo (name));
+ weak_ptr<const NameInfo> value (ret);
pair<NameMap::iterator,bool> inserted =
m_names.insert (make_pair (key, value));
+
BOOST_ASSERT (inserted.second); // previous call has to insert value
item = inserted.first;
}
- return item->second;
+ return ret;
}
+
Ns3NameInfo::Ns3NameInfo (ns3::Ptr<const ns3::CcnxNameComponents> name)
: m_name (name)
{
@@ -81,6 +91,19 @@
}
}
+bool
+Ns3NameInfo::operator < (const NameInfo &info) const
+{
+ try
+ {
+ return *m_name < *dynamic_cast<const Ns3NameInfo&> (info).m_name;
+ }
+ catch (...)
+ {
+ return false;
+ }
+}
+
Digest &
operator << (Digest &digest, const ns3::CcnxNameComponents &name)
{
diff --git a/model/sync-ns3-name-info.h b/model/sync-ns3-name-info.h
index 9363665..347ba1a 100644
--- a/model/sync-ns3-name-info.h
+++ b/model/sync-ns3-name-info.h
@@ -47,6 +47,9 @@
virtual bool
operator == (const NameInfo &info) const;
+ virtual bool
+ operator < (const NameInfo &info) const;
+
virtual std::string
toString () const;
diff --git a/waf-tools/ns3.py b/waf-tools/ns3.py
new file mode 100644
index 0000000..5f5595e
--- /dev/null
+++ b/waf-tools/ns3.py
@@ -0,0 +1,66 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+import waflib
+from waflib.Configure import conf
+from waflib import Utils,Logs,Errors
+
+@conf
+def _print_optional_features(conf):
+ # Write a summary of optional features status
+ print "---- Summary of optional NS-3 features:"
+ Logs.pprint ('RED', "---- Summary of optional NS-3 features:")
+ # for (name, caption, was_enabled, reason_not_enabled) in conf.env['NS3_OPTIONAL_FEATURES']:
+ # if was_enabled:
+ # status = 'enabled'
+ # else:
+ # status = 'not enabled (%s)' % reason_not_enabled
+ # print "%-30s: %s" % (caption, status)
+
+@conf
+def _check_dependencies(conf, required, mandatory):
+ # Logs.pprint ('CYAN', ' + %s' % required)
+ found = []
+ for module in required:
+ retval = conf.check_cfg(package = 'libns3-dev-%s-debug' % module,
+ args='--cflags --libs', mandatory=mandatory,
+ msg="Checking for ns3-%s" % module,
+ uselib_store='NS3_%s' % module.upper())
+ # Logs.pprint ('CYAN', 'NS3_%s' % module.upper())
+ if not retval is None:
+ found.append(module)
+ import copy
+ if not 'NS3_MODULES_FOUND' in conf.env:
+ conf.env['NS3_MODULES_FOUND'] = []
+ conf.env['NS3_MODULES_FOUND'] = conf.env['NS3_MODULES_FOUND'] + copy.copy(found)
+
+def modules_uselib(bld, names):
+ return ['NS3_%s' % name.upper() for name in names] + \
+ ['NS3_LIBRARY_%s' % name.upper() for name in names] + \
+ ['NS3_HEADERS_%s' % name.upper() for name in names]
+
+def modules_found(bld, needed):
+ for module in needed:
+ if not module in bld.env['NS3_MODULES_FOUND']:
+ return False
+ return True
+
+@conf
+def check_modules(conf, modules, mandatory = True):
+ import os
+
+ if not 'NS3_CHECK_MODULE_ONCE' in conf.env:
+ conf.env['NS3_CHECK_MODULE_ONCE'] = ''
+
+ conf.check_cfg(atleast_pkgconfig_version='0.0.0')
+
+ if conf.options.log4cxx:
+ conf.env.append_value('DEFINES', 'NS3_LOG_ENABLE')
+
+ conf._check_dependencies(modules, mandatory)
+ conf._print_optional_features
+
+@conf
+def print_ns3_feature_summary(conf):
+ Logs.pprint ('CYAN', "---- Summary of optional NS-3 features:")
+ conf._print_optional_features
+
diff --git a/wscript b/wscript
index 6a0a629..ade425a 100644
--- a/wscript
+++ b/wscript
@@ -5,12 +5,13 @@
def options(opt):
opt.add_option('--no-debug',action='store_true',default=False,dest='no_debug',help='''Make an optimized build of the library (remove debugging code)''')
- opt.add_option('--log4cxx',action='store_true',default=False,dest='log4cxx',help='''Compile with log4cxx support''')
+ opt.add_option('--log4cxx', action='store_true',default=False,dest='log4cxx',help='''Compile with log4cxx/native NS3 logging support''')
+ opt.add_option('--ns3', action='store_true',default=False,dest='ns3_enable',help='''Compile as NS-3 module''')
opt.load('compiler_c')
opt.load('compiler_cxx')
opt.load('boost')
opt.load('doxygen')
- opt.load('ccnx tinyxml', tooldir=["waf-tools"])
+ opt.load('ccnx tinyxml ns3', tooldir=["waf-tools"])
def configure(conf):
conf.load("compiler_cxx")
@@ -25,7 +26,23 @@
conf.fatal ("Cannot find SSL libraries")
conf.load('boost')
- conf.check_boost(lib='system iostreams test thread')
+
+ if conf.options.ns3_enable:
+ conf.load('ns3')
+ conf.define('NS3_MODULE', 1)
+ conf.check_modules(['core', 'network', 'internet'], mandatory = True)
+ conf.check_modules(['NDNabstraction'], mandatory = True)
+ conf.check_modules(['point-to-point'], mandatory = False)
+ conf.check_modules(['point-to-point-layout'], mandatory = False)
+
+ conf.check_boost(lib='system iostreams thread')
+ else:
+ conf.check_boost(lib='system iostreams test thread')
+ conf.define ('STANDALONE', 1)
+
+ if not conf.options.no_debug:
+ conf.define ('_DEBUG', 1)
+
try:
conf.load('doxygen')
@@ -36,29 +53,52 @@
conf.check_ccnx (path=conf.options.ccnx_dir)
conf.check_tinyxml (path=conf.options.ccnx_dir)
- conf.define ('STANDALONE', 1)
- if not conf.options.no_debug:
- conf.define ('_DEBUG', 1)
+ # else:
+ # if 'CXXFLAGS' in conf.env:
+ # tmp = conf.env['CXXFLAGS']
+ # else:
+ # tmp = []
+ # conf.env['CXXFLAGS'] = tmp + ['-g']
+ # if 'CFLAGS' in conf.env:
+ # tmp = conf.env['CFLAGS']
+ # else:
+ # tmp = []
+ # conf.env['CFLAGS'] = tmp + ['-g']
+ # _report_optional_feature(conf, "debug", "Debug Symbols", True, '')
if conf.options.log4cxx:
conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX', mandatory=True)
def build (bld):
- libsync = bld.shlib (target=APPNAME,
- features=['cxx', 'cxxshlib'],
- source = bld.path.ant_glob(['model/sync-*.cc',
- 'helper/sync-*.cc']),
- use = 'BOOST BOOST_IOSTREAMS BOOST_THREAD SSL TINYXML CCNX')
+ if bld.get_define ("NS3_MODULE"):
+ sync_ns3 = bld.shlib (
+ target = "sync-ns3",
+ features=['cxx', 'cxxshlib'],
+ use = 'BOOST BOOST_IOSTREAMS SSL TINYXML CCNX ' + ' '.join (['ns3_'+dep for dep in ['core', 'network', 'internet', 'NDNabstraction']]).upper (),
+ source = bld.path.ant_glob(['model/sync-*.cc',
+ 'helper/sync-*.cc']),
+ )
+
+
+ # from waflib import Utils,Logs,Errors
+ # Logs.pprint ('CYAN', program.use)
+
+ else:
+ libsync = bld.shlib (target=APPNAME,
+ features=['cxx', 'cxxshlib'],
+ source = bld.path.ant_glob(['model/sync-*.cc',
+ 'helper/sync-*.cc']),
+ use = 'BOOST BOOST_IOSTREAMS BOOST_THREAD SSL TINYXML CCNX')
- # Unit tests
- unittests = bld.program (target="unit-tests",
+ # Unit tests
+ unittests = bld.program (target="unit-tests",
source = bld.path.ant_glob(['test/**/*.cc']),
features=['cxx', 'cxxprogram'],
use = 'BOOST_TEST sync')
- if bld.get_define ("HAVE_LOG4CXX"):
- libsync.use += ' LOG4CXX'
- unittests.use += ' LOG4CXX'
+ if bld.get_define ("HAVE_LOG4CXX"):
+ libsync.use += ' LOG4CXX'
+ unittests.use += ' LOG4CXX'
# doxygen docs
from waflib.Build import BuildContext