1.1 --- a/src/helper/internet-stack-helper.cc Fri Aug 29 23:08:18 2008 +0200
1.2 +++ b/src/helper/internet-stack-helper.cc Fri Aug 29 23:10:00 2008 +0200
1.3 @@ -33,6 +33,10 @@
1.4 std::vector<InternetStackHelper::Trace> InternetStackHelper::m_traces;
1.5 std::string InternetStackHelper::m_pcapBaseFilename;
1.6
1.7 +InternetStackHelper::InternetStackHelper() : m_nscLibrary("")
1.8 +{
1.9 +}
1.10 +
1.11 void
1.12 InternetStackHelper::Cleanup (void)
1.13 {
1.14 @@ -48,6 +52,12 @@
1.15 m_traces.clear ();
1.16 }
1.17
1.18 +void
1.19 +InternetStackHelper::SetNscStack(const std::string soname)
1.20 +{
1.21 + m_nscLibrary = soname;
1.22 +}
1.23 +
1.24 void
1.25 InternetStackHelper::Install (NodeContainer c)
1.26 {
1.27 @@ -59,8 +69,12 @@
1.28 NS_FATAL_ERROR ("InternetStackHelper::Install(): Aggregating "
1.29 "an InternetStack to a node with an existing Ipv4 object");
1.30 return;
1.31 - }
1.32 - AddInternetStack (node);
1.33 + }
1.34 + if (m_nscLibrary != "")
1.35 + AddNscInternetStack (node, m_nscLibrary);
1.36 + else
1.37 + AddInternetStack (node);
1.38 +
1.39 Ptr<PacketSocketFactory> factory = CreateObject<PacketSocketFactory> ();
1.40 node->AggregateObject (factory);
1.41 }
2.1 --- a/src/helper/internet-stack-helper.h Fri Aug 29 23:08:18 2008 +0200
2.2 +++ b/src/helper/internet-stack-helper.h Fri Aug 29 23:10:00 2008 +0200
2.3 @@ -33,6 +33,8 @@
2.4 class InternetStackHelper
2.5 {
2.6 public:
2.7 + InternetStackHelper(void);
2.8 +
2.9 /**
2.10 * \param c the set of nodes
2.11 *
2.12 @@ -45,6 +47,13 @@
2.13 void Install (NodeContainer c);
2.14
2.15 /**
2.16 + * \param soname name of the shared library with the nsc tcp stack
2.17 + * to use, e.g. 'liblinux2.6.26.so'. The empty string resets
2.18 + * the InternetStackHelper to use the ns-3 models again.
2.19 + */
2.20 + void SetNscStack(std::string soname);
2.21 +
2.22 + /**
2.23 * \param filename filename prefix to use for pcap files.
2.24 *
2.25 * Enable pcap output on each protocol instance which is of the
2.26 @@ -60,6 +69,7 @@
2.27 static void EnablePcapAll (std::string filename);
2.28
2.29 private:
2.30 + std::string m_nscLibrary;
2.31 static void Cleanup (void);
2.32 static void LogRxIp (std::string context, Ptr<const Packet> packet, uint32_t deviceId);
2.33 static void LogTxIp (std::string context, Ptr<const Packet> packet, uint32_t deviceId);
3.1 --- a/src/internet-stack/internet-stack.cc Fri Aug 29 23:08:18 2008 +0200
3.2 +++ b/src/internet-stack/internet-stack.cc Fri Aug 29 23:10:00 2008 +0200
3.3 @@ -21,6 +21,7 @@
3.4 #include "ns3/net-device.h"
3.5 #include "ns3/callback.h"
3.6 #include "ns3/node.h"
3.7 +#include "ns3/core-config.h"
3.8
3.9 #include "ipv4-l4-demux.h"
3.10 #include "udp-l4-protocol.h"
3.11 @@ -31,41 +32,105 @@
3.12 #include "tcp-socket-factory-impl.h"
3.13 #include "ipv4-impl.h"
3.14
3.15 +#ifdef NETWORK_SIMULATION_CRADLE
3.16 +#include "nsc-tcp-socket-factory-impl.h"
3.17 +#include "nsc-tcp-l4-protocol.h"
3.18 +#endif
3.19 +
3.20 namespace ns3 {
3.21
3.22 -void
3.23 +static void
3.24 +AddArpStack (Ptr<Node> node)
3.25 +{
3.26 + Ptr<ArpL3Protocol> arp = CreateObject<ArpL3Protocol> ();
3.27 + arp->SetNode (node);
3.28 + node->AggregateObject (arp);
3.29 +}
3.30 +
3.31 +static void
3.32 +AddUdpStack(Ptr<Node> node, Ptr<Ipv4L4Demux> ipv4L4Demux)
3.33 +{
3.34 + Ptr<UdpL4Protocol> udp = CreateObject<UdpL4Protocol> ();
3.35 + udp->SetNode (node);
3.36 + ipv4L4Demux->Insert (udp);
3.37 + Ptr<UdpSocketFactoryImpl> udpFactory = CreateObject<UdpSocketFactoryImpl> ();
3.38 + udpFactory->SetUdp (udp);
3.39 + node->AggregateObject (udpFactory);
3.40 +}
3.41 +
3.42 +static void
3.43 +AddTcpStack(Ptr<Node> node, Ptr<Ipv4L4Demux> ipv4L4Demux)
3.44 +{
3.45 + Ptr<TcpL4Protocol> tcp = CreateObject<TcpL4Protocol> ();
3.46 + tcp->SetNode (node);
3.47 + ipv4L4Demux->Insert (tcp);
3.48 + Ptr<TcpSocketFactoryImpl> tcpFactory = CreateObject<TcpSocketFactoryImpl> ();
3.49 + tcpFactory->SetTcp (tcp);
3.50 + node->AggregateObject (tcpFactory);
3.51 +}
3.52 +
3.53 +static void
3.54 +AddIpv4Impl(Ptr<Node> node, Ptr<Ipv4L3Protocol> ipv4)
3.55 +{
3.56 + Ptr<Ipv4Impl> ipv4Impl = CreateObject<Ipv4Impl> ();
3.57 + ipv4Impl->SetIpv4 (ipv4);
3.58 + node->AggregateObject (ipv4);
3.59 + node->AggregateObject (ipv4Impl);
3.60 +}
3.61 +
3.62 +void
3.63 AddInternetStack (Ptr<Node> node)
3.64 {
3.65 + AddArpStack(node);
3.66 Ptr<Ipv4L3Protocol> ipv4 = CreateObject<Ipv4L3Protocol> ();
3.67 - Ptr<ArpL3Protocol> arp = CreateObject<ArpL3Protocol> ();
3.68 ipv4->SetNode (node);
3.69 - arp->SetNode (node);
3.70
3.71 Ptr<Ipv4L4Demux> ipv4L4Demux = CreateObject<Ipv4L4Demux> ();
3.72 - Ptr<UdpL4Protocol> udp = CreateObject<UdpL4Protocol> ();
3.73 - Ptr<TcpL4Protocol> tcp = CreateObject<TcpL4Protocol> ();
3.74 + ipv4L4Demux->SetNode (node);
3.75
3.76 - ipv4L4Demux->SetNode (node);
3.77 - udp->SetNode (node);
3.78 - tcp->SetNode (node);
3.79 + AddUdpStack (node, ipv4L4Demux);
3.80 + AddTcpStack (node, ipv4L4Demux);
3.81
3.82 - ipv4L4Demux->Insert (udp);
3.83 - ipv4L4Demux->Insert (tcp);
3.84 -
3.85 - Ptr<UdpSocketFactoryImpl> udpFactory = CreateObject<UdpSocketFactoryImpl> ();
3.86 - Ptr<TcpSocketFactoryImpl> tcpFactory = CreateObject<TcpSocketFactoryImpl> ();
3.87 - Ptr<Ipv4Impl> ipv4Impl = CreateObject<Ipv4Impl> ();
3.88 -
3.89 - udpFactory->SetUdp (udp);
3.90 - tcpFactory->SetTcp (tcp);
3.91 - ipv4Impl->SetIpv4 (ipv4);
3.92 -
3.93 - node->AggregateObject (ipv4);
3.94 - node->AggregateObject (arp);
3.95 - node->AggregateObject (ipv4Impl);
3.96 - node->AggregateObject (udpFactory);
3.97 - node->AggregateObject (tcpFactory);
3.98 + AddIpv4Impl (node, ipv4);
3.99 node->AggregateObject (ipv4L4Demux);
3.100 }
3.101
3.102 +
3.103 +#ifdef NETWORK_SIMULATION_CRADLE
3.104 +static void
3.105 +AddNscStack(Ptr<Node> node, Ptr<Ipv4L4Demux> ipv4L4Demux, const std::string &soname)
3.106 +{
3.107 + Ptr<NscTcpL4Protocol> tcp = CreateObject<NscTcpL4Protocol> ();
3.108 + tcp->SetNscLibrary(soname);
3.109 + tcp->SetNode (node);
3.110 + ipv4L4Demux->Insert (tcp);
3.111 + Ptr<NscTcpSocketFactoryImpl> tcpFactory = CreateObject<NscTcpSocketFactoryImpl> ();
3.112 + tcpFactory->SetTcp (tcp);
3.113 + node->AggregateObject (tcpFactory);
3.114 +}
3.115 +
3.116 +
3.117 +void
3.118 +AddNscInternetStack (Ptr<Node> node, const std::string &soname)
3.119 +{
3.120 + AddArpStack(node);
3.121 + Ptr<Ipv4L3Protocol> ipv4 = CreateObject<Ipv4L3Protocol> ();
3.122 + ipv4->SetNode (node);
3.123 +
3.124 + Ptr<Ipv4L4Demux> ipv4L4Demux = CreateObject<Ipv4L4Demux> ();
3.125 + ipv4L4Demux->SetNode (node);
3.126 +
3.127 + AddUdpStack (node, ipv4L4Demux);
3.128 + AddNscStack (node, ipv4L4Demux, soname);
3.129 +
3.130 + AddIpv4Impl (node, ipv4);
3.131 + node->AggregateObject (ipv4L4Demux);
3.132 +}
3.133 +#else
3.134 +void
3.135 +AddNscInternetStack (Ptr<Node> node, const std::string &soname)
3.136 +{
3.137 + NS_ASSERT_MSG(false, "ERROR: ns-3 was compiled without Network Simulation Cradle support");
3.138 +}
3.139 +#endif
3.140 }//namespace ns3
4.1 --- a/src/internet-stack/internet-stack.h Fri Aug 29 23:08:18 2008 +0200
4.2 +++ b/src/internet-stack/internet-stack.h Fri Aug 29 23:10:00 2008 +0200
4.3 @@ -27,6 +27,7 @@
4.4 class Node;
4.5
4.6 void AddInternetStack (Ptr<Node> node);
4.7 +void AddNscInternetStack (Ptr<Node> node, const std::string &soname);
4.8
4.9 }//namespace ns3
4.10
5.1 --- a/src/internet-stack/wscript Fri Aug 29 23:08:18 2008 +0200
5.2 +++ b/src/internet-stack/wscript Fri Aug 29 23:10:00 2008 +0200
5.3 @@ -1,4 +1,61 @@
5.4 ## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
5.5 +import Params
5.6 +import os
5.7 +
5.8 +# Mercurial repository of the network simulation cradle
5.9 +NETWORK_SIMULATION_CRADLE_REPO = "https://secure.wand.net.nz/mercurial/nsc"
5.10 +def nsc_fetch():
5.11 + def nsc_clone():
5.12 + print "Retrieving nsc from " + NETWORK_SIMULATION_CRADLE_REPO
5.13 + if os.system("hg version > /dev/null 2>&1") != 0:
5.14 + Params.fatal("Mercurial not installed, http fallback not yet implemented")
5.15 + if os.system("hg -q clone " + NETWORK_SIMULATION_CRADLE_REPO) != 0:
5.16 + Params.fatal("hg -q clone %s failed" % NETWORK_SIMULATION_CRADLE_REPO)
5.17 +
5.18 + def nsc_update():
5.19 + if os.system("hg version > /dev/null 2>&1") != 0:
5.20 + Params.warning("Mercurial not installed, not updating nsc source")
5.21 +
5.22 + print "Pulling nsc updates from " + NETWORK_SIMULATION_CRADLE_REPO
5.23 + if os.system("cd nsc && hg -q pull %s && hg -q update" % NETWORK_SIMULATION_CRADLE_REPO) != 0:
5.24 + Params.warning("Updating nsc using mercurial failed")
5.25 +
5.26 + if not os.path.exists("nsc"):
5.27 + nsc_clone()
5.28 + else:
5.29 + nsc_update()
5.30 +
5.31 +def configure(conf):
5.32 + # checks for flex and bison, which is needed to build NSCs globaliser
5.33 + def check_nsc_buildutils():
5.34 + import flex
5.35 + import bison
5.36 + conf.check_tool('flex bison')
5.37 + e = conf.create_library_configurator()
5.38 + e.mandatory = True
5.39 + e.name = 'fl'
5.40 + e.run()
5.41 +
5.42 + if not Params.g_options.nsc:
5.43 + return
5.44 +
5.45 + check_nsc_buildutils()
5.46 +
5.47 + arch = os.uname()[4]
5.48 + ok = False
5.49 + if arch == 'x86_64' or arch == 'i686' or arch == 'i586' or arch == 'i486' or arch == 'i386':
5.50 + conf.env['NSC_ENABLED'] = 'yes'
5.51 + conf.define('NETWORK_SIMULATION_CRADLE', 1)
5.52 + conf.write_config_header('ns3/core-config.h')
5.53 + e = conf.create_library_configurator()
5.54 + e.mandatory = True
5.55 + e.name = 'dl'
5.56 + e.define = 'HAVE_DL'
5.57 + e.uselib = 'DL'
5.58 + e.run()
5.59 + ok = True
5.60 + conf.check_message('NSC supported architecture', arch, ok)
5.61 + nsc_fetch()
5.62
5.63
5.64 def build(bld):
5.65 @@ -43,3 +100,9 @@
5.66 'ipv4-l3-protocol.h',
5.67 'ipv4-static-routing.h',
5.68 ]
5.69 +
5.70 + if bld.env()['NSC_ENABLED']:
5.71 + obj.source.append ('nsc-tcp-socket-impl.cc')
5.72 + obj.source.append ('nsc-tcp-l4-protocol.cc')
5.73 + obj.source.append ('nsc-tcp-socket-factory-impl.cc')
5.74 + obj.source.append ('nsc-sysctl.cc')
6.1 --- a/src/wscript Fri Aug 29 23:08:18 2008 +0200
6.2 +++ b/src/wscript Fri Aug 29 23:10:00 2008 +0200
6.3 @@ -49,6 +49,7 @@
6.4 conf.sub_config('core')
6.5 conf.sub_config('simulator')
6.6 conf.sub_config('contrib')
6.7 + conf.sub_config('internet-stack')
6.8
6.9 blddir = os.path.abspath(os.path.join(conf.m_blddir, conf.env.variant()))
6.10 conf.env.append_value('NS3_MODULE_PATH', blddir)
7.1 --- a/wscript Fri Aug 29 23:08:18 2008 +0200
7.2 +++ b/wscript Fri Aug 29 23:10:00 2008 +0200
7.3 @@ -55,6 +55,8 @@
7.4 #
7.5 TRACEBALL_SUFFIX = ".tar.bz2"
7.6
7.7 +# directory that contains network simulation cradle source
7.8 +NSC_DIR = "nsc"
7.9
7.10 def dist_hook():
7.11 import tarfile
7.12 @@ -165,6 +167,10 @@
7.13 help=('For regression testing, only run/generate the indicated regression tests, '
7.14 'specified as a comma separated list of test names'),
7.15 dest='regression_tests', type="string")
7.16 + opt.add_option('--nsc',
7.17 + help=('Enable Network Simulation Cradle to allow the use real-world network stacks'),
7.18 + action="store_true", default=False,
7.19 + dest='nsc')
7.20
7.21 # options provided in a script in a subdirectory named "src"
7.22 opt.sub_options('src')
7.23 @@ -193,6 +199,7 @@
7.24
7.25
7.26 def configure(conf):
7.27 + conf.env['NS3_BUILDDIR'] = conf.m_blddir
7.28 conf.check_tool('compiler_cxx')
7.29
7.30 # create the second environment, set the variant and set its name
7.31 @@ -304,6 +311,28 @@
7.32 return stat >> 8
7.33
7.34
7.35 +def nsc_build(bld):
7.36 + # XXX: Detect gcc major version(s) available to build supported stacks
7.37 + kernels = [['linux-2.6.18', 'linux2.6.18'],
7.38 + ['linux-2.6.26', 'linux2.6.26']]
7.39 + for dir,name in kernels:
7.40 + soname = 'lib' + name + '.so'
7.41 + tmp = NSC_DIR + '/' + dir +'/' + soname
7.42 + if not os.path.exists(tmp):
7.43 + if os.system('cd ' + NSC_DIR + ' && python scons.py ' + dir) != 0:
7.44 + Params.fatal("Building NSC stack failed")
7.45 + builddir = os.path.abspath(os.path.join(bld.env()['NS3_BUILDDIR'], bld.env ().variant()))
7.46 + if not os.path.exists(builddir + '/nsc'):
7.47 + try:
7.48 + os.symlink('../../' + NSC_DIR, builddir + '/nsc')
7.49 + except:
7.50 + Params.fatal("Error linkink " + builddir + '/nsc')
7.51 + if not os.path.exists(builddir + '/' + soname):
7.52 + try:
7.53 + os.symlink('../../' + NSC_DIR + '/' + dir + '/' + soname, builddir + '/' + soname)
7.54 + except:
7.55 + Params.fatal("Error linking " + builddir + '/' + soname)
7.56 +
7.57 def build(bld):
7.58 if Params.g_options.no_task_lines:
7.59 import Runner
7.60 @@ -393,6 +422,9 @@
7.61
7.62 bld.add_subdirs('bindings/python')
7.63
7.64 + if env['NSC_ENABLED'] == 'yes':
7.65 + nsc_build(bld)
7.66 +
7.67 def get_command_template():
7.68 if Params.g_options.valgrind:
7.69 if Params.g_options.command_template: