diff -r 5cc5216a7a85 build.py --- a/build.py Tue Dec 27 13:09:50 2011 -0800 +++ b/build.py Tue May 08 07:41:03 2012 -0700 @@ -13,6 +13,26 @@ run_command([sys.executable, 'scons.py']) +def build_netanim(qmakepath): + qmake = 'qmake' + if qmakepath: + qmake = qmakepath + try: + if sys.platform in ['darwin']: + run_command([qmake, '-spec', 'macx-g++', 'NetAnim.pro']) + else: + run_command([qmake, 'NetAnim.pro']) + run_command(['make']) + except OSError: + print "Error building NetAnim. Ensure the path to qmake is correct" + print "Note: Some systems use qmake-qt4 instead of qmake" + print "Skipping NetAnim ...." + pass + except: + print "Error building NetAnim." + print "Skipping NetAnim ...." + pass + def build_ns3(config, build_examples, build_tests, args, build_options): cmd = [sys.executable, "waf", "configure"] + args @@ -66,6 +86,12 @@ parser.add_option('--disable-nsc', help=("Don't try to build NSC (built by default)"), action="store_true", default=False, dest='disable_nsc') + parser.add_option('--disable-netanim', + help=("Don't try to build NetAnim (built by default)"), action="store_true", default=False, + dest='disable_netanim') + parser.add_option('--qmake-path', + help=("Provide absolute path to qmake executable for NetAnim"), action="store", default='qmake', + dest='qmake_path') parser.add_option('--enable-examples', help=("Do try to build examples (not built by default)"), action="store_true", default=False, dest='enable_examples') @@ -112,6 +138,30 @@ os.chdir(cwd) print "Leaving directory `%s'" % nsc_dir + if options.disable_netanim: + print "# Skip NetAnimC (by user request)" + for node in config.getElementsByTagName("netanim"): + config.documentElement.removeChild(node) + elif sys.platform in ['cygwin', 'win32']: + print "# Skip NetAnim (platform not supported)" + else: + netanim_config_elems = config.getElementsByTagName("netanim") + if netanim_config_elems: + netanim_config, = netanim_config_elems + netanim_dir = netanim_config.getAttribute("dir") + print "# Build NetAnim" + os.chdir(netanim_dir) + print "Entering directory `%s'" % netanim_dir + try: + try: + build_netanim(options.qmake_path) + except CommandError: + print "# Build NetAnim: failure (ignoring NetAnim)" + config.documentElement.removeChild(netanim_config) + finally: + os.chdir(cwd) + print "Leaving directory `%s'" % netanim_dir + if options.enable_examples: print "# Building examples (by user request)" build_examples = True diff -r 5cc5216a7a85 constants.py --- a/constants.py Tue Dec 27 13:09:50 2011 -0800 +++ b/constants.py Tue May 08 07:41:03 2012 -0700 @@ -40,3 +40,9 @@ NSC_RELEASE_URL = "http://research.wand.net.nz/software/nsc" LOCAL_NSC_PATH = "nsc" + +# NetAnim +NETANIM_REPO = "http://code.nsnam.org/jabraham3/netanim" +NETANIM_RELEASE_URL = "http://www.nsnam.org/tools/netanim" + +LOCAL_NETANIM_PATH = "netanim" diff -r 5cc5216a7a85 dist.py --- a/dist.py Tue Dec 27 13:09:50 2011 -0800 +++ b/dist.py Tue May 08 07:41:03 2012 -0700 @@ -98,7 +98,6 @@ print "Adding %s as %s" % (ns3_dir, os.path.join(dist_dir, new_ns3_dir)) tar_add_tree(tar, ns3_dir, os.path.join(dist_dir, new_ns3_dir), dir_excl, file_excl) - # add pybindgen pybindgen_dir = config.getElementsByTagName("pybindgen")[0].getAttribute("dir") new_pybindgen_dir = "pybindgen-%s" % config.getElementsByTagName("pybindgen")[0].getAttribute("version") @@ -120,8 +119,6 @@ print "Adding %s as %s" % (pybindgen_dir, os.path.join(dist_dir, new_pybindgen_dir)) tar_add_tree(tar, pybindgen_dir, os.path.join(dist_dir, new_pybindgen_dir), dir_excl, file_excl) - - # add network simulation cradle nsc_dir = config.getElementsByTagName("nsc")[0].getAttribute("dir") new_nsc_dir = config.getElementsByTagName("nsc")[0].getAttribute("version") @@ -141,6 +138,23 @@ print "Adding %s as %s" % (nsc_dir, os.path.join(dist_dir, new_nsc_dir)) tar_add_tree(tar, nsc_dir, os.path.join(dist_dir, new_nsc_dir), dir_excl, file_excl) + # add NetAnim + netanim_dir = config.getElementsByTagName("netanim")[0].getAttribute("dir"); + new_netanim_dir = config.getElementsByTagName("netanim")[0].getAttribute("version") + assert new_netanim_dir.startswith("netanim") + new_config.getElementsByTagName("netanim")[0].setAttribute("dir", new_netanim_dir) + def dir_excl(reldirpath, dirname): + if dirname[0] == '.': + return True + return False + def file_excl(reldirpath, filename): + if filename.startswith('.'): + return True + if filename.endswith('~'): + return True + return False + print "Adding %s as %s" % (netanim_dir, os.path.join(dist_dir, new_netanim_dir)) + tar_add_tree(tar, netanim_dir, os.path.join(dist_dir, new_netanim_dir), dir_excl, file_excl) # add the build script files print "Adding the build script files" diff -r 5cc5216a7a85 download.py --- a/download.py Tue Dec 27 13:09:50 2011 -0800 +++ b/download.py Tue May 08 07:41:03 2012 -0700 @@ -126,6 +126,63 @@ return (constants.LOCAL_PYBINDGEN_PATH, '.'.join([str(x) for x in required_pybindgen_version])) +def get_netanim(ns3_dir): + print """ + # + # Get NetAnim + # + """ + + if sys.platform in ['cygwin']: + print "Architecture (%s) does not support NetAnim... skipping" % (sys.platform) + raise RuntimeError + + # (peek into the ns-3 wscript and extract the required netanim version) + try: + # For the recent versions + netanim_wscript = open(os.path.join(ns3_dir, "src", "netanim", "wscript"), "rt") + except: + print "Unable to detect NetAnim required version.Skipping download" + pass + return + + required_netanim_version = None + for line in netanim_wscript: + if 'NETANIM_RELEASE_NAME' in line: + required_netanim_version = eval(line.split('=')[1].strip()) + break + netanim_wscript.close() + if required_netanim_version is None: + fatal("Unable to detect NetAnim required version") + print "Required NetAnim version: ", required_netanim_version + + + def netanim_clone(): + print "Retrieving NetAnim from " + constants.NETANIM_REPO + run_command(['hg', 'clone', constants.NETANIM_REPO, constants.LOCAL_NETANIM_PATH]) + + def netanim_update(): + print "Pulling NetAnim updates from " + constants.NETANIM_REPO + run_command(['hg', '--cwd', constants.LOCAL_NETANIM_PATH, 'pull', '-u', constants.NETANIM_REPO]) + + def netanim_download(): + local_file = required_netanim_version + ".tar.bz2" + remote_file = constants.NETANIM_RELEASE_URL + "/" + local_file + print "Retrieving NetAnim from " + remote_file + urllib.urlretrieve(remote_file, local_file) + print "Uncompressing " + local_file + run_command(["tar", "-xjf", local_file]) + print "Rename %s as %s" % (required_netanim_version, constants.LOCAL_NETANIM_PATH) + os.rename(required_netanim_version, constants.LOCAL_NETANIM_PATH) + + if not os.path.exists(os.path.join(ns3_dir, '.hg')): + netanim_download() + elif not os.path.exists(constants.LOCAL_NETANIM_PATH): + netanim_clone() + else: + netanim_update() + + return (constants.LOCAL_NETANIM_PATH, required_netanim_version) def get_nsc(ns3_dir): print """ @@ -228,6 +285,16 @@ pybindgen_config.setAttribute("dir", pybindgen_dir) pybindgen_config.setAttribute("version", pybindgen_version) + # -- download NetAnim -- + try: + netanim_dir, netanim_version = get_netanim(ns3_dir) + except (CommandError, IOError, RuntimeError): + print " *** Did not fetch NetAnim offline animator. Please visit http://www.nsnam.org/wiki/index.php/NetAnim ." + else: + netanim_config = config.documentElement.appendChild(config.createElement("netanim")) + netanim_config.setAttribute("dir", netanim_dir) + netanim_config.setAttribute("version", netanim_version) + # -- download network simulation cradle -- try: nsc_dir, nsc_version = get_nsc(ns3_dir)