2007-05-07 12:01:51 +01:00
|
|
|
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
|
2008-08-29 23:10:00 +02:00
|
|
|
import Params
|
2008-09-05 19:55:21 +01:00
|
|
|
import Task
|
2008-08-29 23:10:00 +02:00
|
|
|
import os
|
2008-09-09 10:15:40 -07:00
|
|
|
import urllib
|
2008-08-29 23:10:00 +02:00
|
|
|
|
|
|
|
|
# Mercurial repository of the network simulation cradle
|
2008-09-09 10:15:40 -07:00
|
|
|
NSC_REPO = "https://secure.wand.net.nz/mercurial/nsc"
|
|
|
|
|
NSC_RELEASE_URL = "http://research.wand.net.nz/software/nsc"
|
2008-11-19 22:41:12 +01:00
|
|
|
NSC_RELEASE_NAME = "nsc-0.5.0"
|
2008-09-05 19:55:21 +01:00
|
|
|
|
|
|
|
|
# directory that contains network simulation cradle source
|
|
|
|
|
# note, this path is relative to the project root
|
|
|
|
|
NSC_DIR = "nsc"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_options(opt):
|
2008-09-06 14:46:01 +01:00
|
|
|
opt.add_option('--enable-nsc',
|
2008-09-05 19:55:21 +01:00
|
|
|
help=('Enable Network Simulation Cradle to allow the use real-world network stacks'),
|
|
|
|
|
action="store_true", default=False,
|
2008-09-06 14:46:01 +01:00
|
|
|
dest='enable_nsc')
|
2008-09-05 19:55:21 +01:00
|
|
|
|
|
|
|
|
|
2008-08-29 23:10:00 +02:00
|
|
|
def nsc_fetch():
|
|
|
|
|
def nsc_clone():
|
2008-09-09 10:15:40 -07:00
|
|
|
print "Retrieving nsc from " + NSC_REPO
|
2008-08-29 23:10:00 +02:00
|
|
|
if os.system("hg version > /dev/null 2>&1") != 0:
|
|
|
|
|
Params.fatal("Mercurial not installed, http fallback not yet implemented")
|
2008-09-09 10:15:40 -07:00
|
|
|
if os.system("hg clone " + NSC_REPO) != 0:
|
|
|
|
|
Params.fatal("hg -q clone %s failed" % NSC_REPO)
|
2008-08-29 23:10:00 +02:00
|
|
|
|
|
|
|
|
def nsc_update():
|
|
|
|
|
if os.system("hg version > /dev/null 2>&1") != 0:
|
|
|
|
|
Params.warning("Mercurial not installed, not updating nsc source")
|
|
|
|
|
|
2008-09-09 10:15:40 -07:00
|
|
|
print "Pulling nsc updates from " + NSC_REPO
|
|
|
|
|
if os.system("cd nsc && hg pull %s && hg update" % NSC_REPO) != 0:
|
2008-08-29 23:10:00 +02:00
|
|
|
Params.warning("Updating nsc using mercurial failed")
|
|
|
|
|
|
2008-09-09 10:15:40 -07:00
|
|
|
def nsc_download():
|
|
|
|
|
local_file = NSC_RELEASE_NAME + ".tar.bz2"
|
|
|
|
|
remote_file = NSC_RELEASE_URL + "/" + local_file
|
|
|
|
|
print "Retrieving nsc from " + remote_file
|
|
|
|
|
urllib.urlretrieve(remote_file, local_file)
|
|
|
|
|
print "Uncompressing " + local_file
|
|
|
|
|
os.system("tar -xjf " + local_file)
|
|
|
|
|
os.system('mv ' + NSC_RELEASE_NAME + ' nsc')
|
|
|
|
|
|
|
|
|
|
if not os.path.exists('.hg'):
|
|
|
|
|
nsc_download ()
|
|
|
|
|
elif not os.path.exists("nsc"):
|
2008-08-29 23:10:00 +02:00
|
|
|
nsc_clone()
|
|
|
|
|
else:
|
|
|
|
|
nsc_update()
|
|
|
|
|
|
|
|
|
|
def configure(conf):
|
2008-09-17 20:04:26 -07:00
|
|
|
conf.env['ENABLE_NSC'] = False
|
|
|
|
|
|
2008-08-29 23:10:00 +02:00
|
|
|
# checks for flex and bison, which is needed to build NSCs globaliser
|
|
|
|
|
def check_nsc_buildutils():
|
|
|
|
|
import flex
|
|
|
|
|
import bison
|
|
|
|
|
conf.check_tool('flex bison')
|
|
|
|
|
e = conf.create_library_configurator()
|
|
|
|
|
e.mandatory = True
|
|
|
|
|
e.name = 'fl'
|
|
|
|
|
e.run()
|
|
|
|
|
|
2008-09-06 14:46:01 +01:00
|
|
|
if not Params.g_options.enable_nsc:
|
2008-09-05 18:16:29 +01:00
|
|
|
conf.report_optional_feature("nsc", "Network Simulation Cradle", False,
|
2008-09-06 14:46:01 +01:00
|
|
|
"--enable-nsc configure option not given")
|
2008-08-29 23:10:00 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
|
|
check_nsc_buildutils()
|
|
|
|
|
|
|
|
|
|
arch = os.uname()[4]
|
|
|
|
|
ok = False
|
|
|
|
|
if arch == 'x86_64' or arch == 'i686' or arch == 'i586' or arch == 'i486' or arch == 'i386':
|
|
|
|
|
conf.env['NSC_ENABLED'] = 'yes'
|
2008-09-09 17:09:37 -07:00
|
|
|
conf.env.append_value('CXXDEFINES', 'NETWORK_SIMULATION_CRADLE')
|
2008-08-29 23:10:00 +02:00
|
|
|
e = conf.create_library_configurator()
|
|
|
|
|
e.mandatory = True
|
|
|
|
|
e.name = 'dl'
|
|
|
|
|
e.define = 'HAVE_DL'
|
|
|
|
|
e.uselib = 'DL'
|
|
|
|
|
e.run()
|
2008-09-17 20:04:26 -07:00
|
|
|
conf.env['ENABLE_NSC'] = True
|
2008-08-29 23:10:00 +02:00
|
|
|
ok = True
|
|
|
|
|
conf.check_message('NSC supported architecture', arch, ok)
|
2008-09-05 18:16:29 +01:00
|
|
|
conf.report_optional_feature("nsc", "Network Simulation Cradle", ok,
|
|
|
|
|
"architecture %r not supported" % arch)
|
2008-08-29 23:10:00 +02:00
|
|
|
nsc_fetch()
|
2007-05-07 12:01:51 +01:00
|
|
|
|
|
|
|
|
|
2008-09-05 19:55:21 +01:00
|
|
|
|
|
|
|
|
class NscBuildTask(Task.TaskBase):
|
|
|
|
|
"""task that builds nsc
|
|
|
|
|
"""
|
|
|
|
|
def __init__(self, builddir):
|
|
|
|
|
self.m_display = 'build-nsc'
|
|
|
|
|
self.prio = 1000 # build after the rest of ns-3
|
|
|
|
|
self.builddir = builddir
|
|
|
|
|
super(NscBuildTask, self).__init__()
|
|
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
|
# XXX: Detect gcc major version(s) available to build supported stacks
|
2008-09-10 13:11:35 +02:00
|
|
|
builddir = self.builddir
|
2008-09-05 19:55:21 +01:00
|
|
|
kernels = [['linux-2.6.18', 'linux2.6.18'],
|
|
|
|
|
['linux-2.6.26', 'linux2.6.26']]
|
|
|
|
|
for dir, name in kernels:
|
|
|
|
|
soname = 'lib' + name + '.so'
|
|
|
|
|
if not os.path.exists(os.path.join("..", NSC_DIR, dir, soname)):
|
|
|
|
|
if os.system('cd ../%s && python scons.py %s' % (NSC_DIR, dir)) != 0:
|
|
|
|
|
Params.fatal("Building NSC stack failed")
|
2008-09-10 12:46:59 +02:00
|
|
|
|
2008-09-10 13:11:35 +02:00
|
|
|
if not os.path.exists(builddir + '/' + soname):
|
|
|
|
|
try:
|
|
|
|
|
os.symlink('../../' + NSC_DIR + '/' + dir + '/' + soname, builddir + '/' + soname)
|
|
|
|
|
except:
|
|
|
|
|
Params.fatal("Error linking " + builddir + '/' + soname)
|
|
|
|
|
|
2008-09-05 19:55:21 +01:00
|
|
|
|
2007-05-07 12:01:51 +01:00
|
|
|
def build(bld):
|
2008-06-09 15:40:22 -07:00
|
|
|
obj = bld.create_ns3_module('internet-stack', ['node'])
|
2007-05-07 12:01:51 +01:00
|
|
|
obj.source = [
|
2008-03-24 11:56:50 -07:00
|
|
|
'internet-stack.cc',
|
2007-05-07 12:01:51 +01:00
|
|
|
'ipv4-l4-protocol.cc',
|
|
|
|
|
'udp-header.cc',
|
2008-01-25 13:57:38 -05:00
|
|
|
'tcp-header.cc',
|
2007-05-07 12:01:51 +01:00
|
|
|
'ipv4-checksum.cc',
|
|
|
|
|
'ipv4-interface.cc',
|
2007-06-12 14:05:01 +01:00
|
|
|
'ipv4-l3-protocol.cc',
|
2007-07-26 12:26:21 +01:00
|
|
|
'ipv4-static-routing.cc',
|
2008-11-30 21:21:23 -08:00
|
|
|
'ipv4-global-routing.cc',
|
2007-05-07 12:01:51 +01:00
|
|
|
'ipv4-end-point.cc',
|
2007-06-12 14:05:01 +01:00
|
|
|
'udp-l4-protocol.cc',
|
2008-01-25 13:57:38 -05:00
|
|
|
'tcp-l4-protocol.cc',
|
2007-05-07 12:01:51 +01:00
|
|
|
'arp-header.cc',
|
|
|
|
|
'arp-cache.cc',
|
|
|
|
|
'arp-ipv4-interface.cc',
|
2007-06-12 14:05:01 +01:00
|
|
|
'arp-l3-protocol.cc',
|
2007-05-07 12:01:51 +01:00
|
|
|
'ipv4-loopback-interface.cc',
|
2008-05-20 10:30:40 -07:00
|
|
|
'udp-socket-impl.cc',
|
2008-05-20 11:52:25 -07:00
|
|
|
'tcp-socket-impl.cc',
|
2007-05-07 12:01:51 +01:00
|
|
|
'ipv4-end-point-demux.cc',
|
2007-06-12 14:05:01 +01:00
|
|
|
'ipv4-impl.cc',
|
2008-05-17 22:02:09 -07:00
|
|
|
'udp-socket-factory-impl.cc',
|
2008-05-20 12:27:30 -07:00
|
|
|
'tcp-socket-factory-impl.cc',
|
2008-01-25 13:57:38 -05:00
|
|
|
'pending-data.cc',
|
|
|
|
|
'sequence-number.cc',
|
|
|
|
|
'rtt-estimator.cc',
|
2008-10-29 11:18:39 -07:00
|
|
|
'ipv4-raw-socket-factory-impl.cc',
|
|
|
|
|
'ipv4-raw-socket-impl.cc',
|
|
|
|
|
'icmpv4.cc',
|
|
|
|
|
'icmpv4-l4-protocol.cc',
|
2007-05-07 12:01:51 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
headers = bld.create_obj('ns3header')
|
2008-06-09 15:40:22 -07:00
|
|
|
headers.module = 'internet-stack'
|
2007-05-07 12:01:51 +01:00
|
|
|
headers.source = [
|
2008-03-24 11:56:50 -07:00
|
|
|
'internet-stack.h',
|
2007-08-08 11:20:35 +02:00
|
|
|
'udp-header.h',
|
2008-01-25 13:57:38 -05:00
|
|
|
'tcp-header.h',
|
2008-02-09 18:37:58 +00:00
|
|
|
'sequence-number.h',
|
2008-07-03 09:44:23 -04:00
|
|
|
'ipv4-interface.h',
|
|
|
|
|
'ipv4-l3-protocol.h',
|
|
|
|
|
'ipv4-static-routing.h',
|
2008-11-30 21:21:23 -08:00
|
|
|
'ipv4-global-routing.h',
|
2008-10-29 11:18:39 -07:00
|
|
|
'icmpv4.h',
|
2007-05-07 12:01:51 +01:00
|
|
|
]
|
2008-08-29 23:10:00 +02:00
|
|
|
|
2008-09-05 21:12:00 -07:00
|
|
|
if bld.env()['NSC_ENABLED']:
|
2008-09-08 09:22:45 -07:00
|
|
|
obj.source.append ('nsc-tcp-socket-impl.cc')
|
|
|
|
|
obj.source.append ('nsc-tcp-l4-protocol.cc')
|
|
|
|
|
obj.source.append ('nsc-tcp-socket-factory-impl.cc')
|
|
|
|
|
obj.source.append ('nsc-sysctl.cc')
|
|
|
|
|
obj.uselib = 'DL'
|
2008-09-05 19:55:21 +01:00
|
|
|
builddir = os.path.abspath(os.path.join(bld.env()['NS3_BUILDDIR'], bld.env ().variant()))
|
|
|
|
|
NscBuildTask(builddir)
|