src/internet-stack/wscript
changeset 4064 10222f483860
parent 3977 4daeb41d7fc1
child 4065 f18c257dd25e
equal deleted inserted replaced
4031:d26a4018a9ef 4064:10222f483860
     1 ## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
     1 ## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
     2 import Params
       
     3 import Task
       
     4 import os
     2 import os
     5 import urllib
     3 import urllib
       
     4 
       
     5 import Options
       
     6 import Logs
       
     7 import Utils
       
     8 import Task
     6 
     9 
     7 # Mercurial repository of the network simulation cradle
    10 # Mercurial repository of the network simulation cradle
     8 NSC_REPO = "https://secure.wand.net.nz/mercurial/nsc"
    11 NSC_REPO = "https://secure.wand.net.nz/mercurial/nsc"
     9 NSC_RELEASE_URL = "http://research.wand.net.nz/software/nsc"
    12 NSC_RELEASE_URL = "http://research.wand.net.nz/software/nsc"
    10 NSC_RELEASE_NAME = "nsc-0.5.0"
    13 NSC_RELEASE_NAME = "nsc-0.5.0"
    23 
    26 
    24 def nsc_fetch():
    27 def nsc_fetch():
    25     def nsc_clone():
    28     def nsc_clone():
    26         print "Retrieving nsc from " + NSC_REPO
    29         print "Retrieving nsc from " + NSC_REPO
    27         if os.system("hg version > /dev/null 2>&1") != 0:
    30         if os.system("hg version > /dev/null 2>&1") != 0:
    28             Params.fatal("Mercurial not installed, http fallback not yet implemented")
    31             raise Utils.WafError("Mercurial not installed, http fallback not yet implemented")
    29         if os.system("hg  clone " + NSC_REPO) != 0:
    32         if os.system("hg  clone " + NSC_REPO) != 0:
    30             Params.fatal("hg -q clone %s failed" % NSC_REPO)
    33             raise Utils.WafError("hg -q clone %s failed" % NSC_REPO)
    31 
    34 
    32     def nsc_update():
    35     def nsc_update():
    33         if os.system("hg version > /dev/null 2>&1") != 0:
    36         if os.system("hg version > /dev/null 2>&1") != 0:
    34             Params.warning("Mercurial not installed, not updating nsc source")
    37             Logs.warn("Mercurial not installed, not updating nsc source")
    35 
    38 
    36         print "Pulling nsc updates from " + NSC_REPO
    39         print "Pulling nsc updates from " + NSC_REPO
    37         if os.system("cd nsc && hg pull %s && hg update" % NSC_REPO) != 0:
    40         if os.system("cd nsc && hg pull %s && hg update" % NSC_REPO) != 0:
    38             Params.warning("Updating nsc using mercurial failed")
    41             Logs.warn("Updating nsc using mercurial failed")
    39 
    42 
    40     def nsc_download():
    43     def nsc_download():
    41         local_file = NSC_RELEASE_NAME + ".tar.bz2"
    44         local_file = NSC_RELEASE_NAME + ".tar.bz2"
    42         remote_file = NSC_RELEASE_URL + "/" + local_file
    45         remote_file = NSC_RELEASE_URL + "/" + local_file
    43         print "Retrieving nsc from " + remote_file
    46         print "Retrieving nsc from " + remote_file
    59     # checks for flex and bison, which is needed to build NSCs globaliser
    62     # checks for flex and bison, which is needed to build NSCs globaliser
    60     def check_nsc_buildutils():
    63     def check_nsc_buildutils():
    61         import flex
    64         import flex
    62         import bison
    65         import bison
    63         conf.check_tool('flex bison')
    66         conf.check_tool('flex bison')
    64         e = conf.create_library_configurator()
    67         conf.check(lib='fl', mandatory=True)
    65         e.mandatory = True
       
    66         e.name = 'fl'
       
    67         e.run()
       
    68 
    68 
    69     if not Params.g_options.enable_nsc:
    69     if not Options.options.enable_nsc:
    70         conf.report_optional_feature("nsc", "Network Simulation Cradle", False,
    70         conf.report_optional_feature("nsc", "Network Simulation Cradle", False,
    71                                      "--enable-nsc configure option not given")
    71                                      "--enable-nsc configure option not given")
    72 	return
    72 	return
    73 
    73 
    74     check_nsc_buildutils()
    74     check_nsc_buildutils()
    76     arch = os.uname()[4]
    76     arch = os.uname()[4]
    77     ok = False
    77     ok = False
    78     if arch == 'x86_64' or arch == 'i686' or arch == 'i586' or arch == 'i486' or arch == 'i386':
    78     if arch == 'x86_64' or arch == 'i686' or arch == 'i586' or arch == 'i486' or arch == 'i386':
    79         conf.env['NSC_ENABLED'] = 'yes'
    79         conf.env['NSC_ENABLED'] = 'yes'
    80         conf.env.append_value('CXXDEFINES', 'NETWORK_SIMULATION_CRADLE')
    80         conf.env.append_value('CXXDEFINES', 'NETWORK_SIMULATION_CRADLE')
    81         e = conf.create_library_configurator()
    81         conf.env['ENABLE_NSC'] = conf.check(mandatory=True, lib='dl', define_name='HAVE_DL', uselib='DL')
    82         e.mandatory = True
       
    83         e.name = 'dl'
       
    84         e.define = 'HAVE_DL'
       
    85         e.uselib = 'DL'
       
    86         e.run()
       
    87         conf.env['ENABLE_NSC'] = True
       
    88         ok = True
    82         ok = True
    89     conf.check_message('NSC supported architecture', arch, ok)
    83     conf.check_message('NSC supported architecture', arch, ok)
    90     conf.report_optional_feature("nsc", "Network Simulation Cradle", ok,
    84     conf.report_optional_feature("nsc", "Network Simulation Cradle", ok,
    91                                  "architecture %r not supported" % arch)
    85                                  "architecture %r not supported" % arch)
    92     nsc_fetch()
    86     nsc_fetch()
    94 
    88 
    95 
    89 
    96 class NscBuildTask(Task.TaskBase):
    90 class NscBuildTask(Task.TaskBase):
    97     """task that builds nsc
    91     """task that builds nsc
    98     """
    92     """
       
    93     after = 'link' # build after the rest of ns-3
    99     def __init__(self, builddir):
    94     def __init__(self, builddir):
   100         self.prio = 1000 # build after the rest of ns-3
       
   101         self.builddir = builddir
    95         self.builddir = builddir
   102         super(NscBuildTask, self).__init__()
    96         super(NscBuildTask, self).__init__()
   103         self.m_display = 'build-nsc\n'
    97         self.display = 'build-nsc\n'
   104 
    98 
   105     def run(self):
    99     def run(self):
   106         # XXX: Detect gcc major version(s) available to build supported stacks
   100         # XXX: Detect gcc major version(s) available to build supported stacks
   107         builddir = self.builddir
   101         builddir = self.builddir
   108         kernels = [['linux-2.6.18', 'linux2.6.18'],
   102         kernels = [['linux-2.6.18', 'linux2.6.18'],
   109                    ['linux-2.6.26', 'linux2.6.26']]
   103                    ['linux-2.6.26', 'linux2.6.26']]
   110         for dir, name in kernels:
   104         for dir, name in kernels:
   111             soname = 'lib' + name + '.so'
   105             soname = 'lib' + name + '.so'
   112             if not os.path.exists(os.path.join("..", NSC_DIR, dir, soname)):
   106             if not os.path.exists(os.path.join("..", NSC_DIR, dir, soname)):
   113                 if os.system('cd ../%s && python scons.py %s' % (NSC_DIR, dir)) != 0:
   107                 if os.system('cd ../%s && python scons.py %s' % (NSC_DIR, dir)) != 0:
   114                     Params.fatal("Building NSC stack failed")
   108                     raise Utils.WafError("Building NSC stack failed")
   115 
   109 
   116             if not os.path.exists(builddir + '/' + soname):
   110             if not os.path.exists(builddir + '/' + soname):
   117                 try:
   111                 try:
   118                     os.symlink('../../' + NSC_DIR + '/' + dir + '/' + soname, builddir +  '/' + soname)
   112                     os.symlink('../../' + NSC_DIR + '/' + dir + '/' + soname, builddir +  '/' + soname)
   119                 except:
   113                 except:
   120                     Params.fatal("Error linking " + builddir + '/' + soname)
   114                     raise Utils.WafError("Error linking " + builddir + '/' + soname)
   121 
   115 
   122 
   116 
   123 def build(bld):
   117 def build(bld):
   124     obj = bld.create_ns3_module('internet-stack', ['node'])
   118     obj = bld.create_ns3_module('internet-stack', ['node'])
   125     obj.source = [
   119     obj.source = [
   153         'ipv4-raw-socket-impl.cc',
   147         'ipv4-raw-socket-impl.cc',
   154         'icmpv4.cc',
   148         'icmpv4.cc',
   155         'icmpv4-l4-protocol.cc',
   149         'icmpv4-l4-protocol.cc',
   156         ]
   150         ]
   157 
   151 
   158     headers = bld.create_obj('ns3header')
   152     headers = bld.new_task_gen('ns3header')
   159     headers.module = 'internet-stack'
   153     headers.module = 'internet-stack'
   160     headers.source = [
   154     headers.source = [
   161         'internet-stack.h',
   155         'internet-stack.h',
   162         'udp-header.h',
   156         'udp-header.h',
   163         'tcp-header.h',
   157         'tcp-header.h',
   167         'ipv4-static-routing.h',
   161         'ipv4-static-routing.h',
   168         'ipv4-global-routing.h',
   162         'ipv4-global-routing.h',
   169         'icmpv4.h',
   163         'icmpv4.h',
   170         ]
   164         ]
   171 
   165 
   172     if bld.env()['NSC_ENABLED']:        
   166     if bld.env['NSC_ENABLED']:        
   173         obj.source.append ('nsc-tcp-socket-impl.cc')
   167         obj.source.append ('nsc-tcp-socket-impl.cc')
   174         obj.source.append ('nsc-tcp-l4-protocol.cc')
   168         obj.source.append ('nsc-tcp-l4-protocol.cc')
   175         obj.source.append ('nsc-tcp-socket-factory-impl.cc')
   169         obj.source.append ('nsc-tcp-socket-factory-impl.cc')
   176         obj.source.append ('nsc-sysctl.cc')
   170         obj.source.append ('nsc-sysctl.cc')
   177         obj.uselib = 'DL'
   171         obj.uselib = 'DL'
   178         builddir = os.path.abspath(os.path.join(bld.env()['NS3_BUILDDIR'], bld.env ().variant()))
   172         builddir = os.path.abspath(os.path.join(bld.env['NS3_BUILDDIR'], bld.env ().variant()))
   179         NscBuildTask(builddir)
   173         NscBuildTask(builddir)