NFD+ci+docs: Attaching NFD as a submodule

Based on NFD:commit:27be0b0d41235609bee703f4f2ef9e5b1978fdce (version 0.2.0-74-g27be0b0)

Change-Id: I7f9117b226aa244e257375f7f4c045dc9c4cd897
Refs: #3124
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..d01dda7
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "NFD"]
+	path = NFD
+	url = https://github.com/named-data-ndnSIM/NFD
diff --git a/.waf-tools/version.py b/.waf-tools/version.py
new file mode 100644
index 0000000..ef734dd
--- /dev/null
+++ b/.waf-tools/version.py
@@ -0,0 +1,60 @@
+# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+from waflib.Configure import conf
+from waflib import Utils
+import os
+
+def splitVersion(version):
+    base = version.split('-')[0]
+    split = [v for v in base.split('.')]
+    return base, version, split
+
+@conf
+def getVersion(conf, submodule, **kw):
+    tagPrefix = kw.get('tag', '%s-' % submodule)
+    baseVersion = kw.get('base_version', '0.0.0')
+    submodule = conf.path.find_node(submodule)
+
+    gitVersion = baseVersion
+
+    didGetVersion = False
+    try:
+        cmd = ['git', 'describe', '--always', '--match', '%s*' % tagPrefix]
+        p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE,
+                                   cwd=submodule.abspath(),
+                                   stderr=None, stdin=None)
+        out = str(p.communicate()[0].strip())
+        didGetVersion = (p.returncode == 0 and out != "")
+        if didGetVersion:
+            if out.startswith(tagPrefix):
+                gitVersion = out[len(tagPrefix):]
+            else:
+                gitVersion = "%s-commit-%s" % (baseVersion, out)
+    except OSError:
+        pass
+
+    versionFile = submodule.find_node('VERSION')
+
+    if not didGetVersion and versionFile is not None:
+        try:
+            return splitVersion(versionFile.read())
+        except (OSError, IOError):
+            pass
+
+    # version was obtained from git, update VERSION file if necessary
+    if versionFile is not None:
+        try:
+            version = versionFile.read()
+            versionFile = None # no need to update
+        except (OSError, IOError):
+            Logs.warn("VERSION file exists, but not readable")
+    else:
+        versionFile = submodule.make_node('VERSION')
+
+    if versionFile:
+        try:
+            versionFile.write(gitVersion)
+        except (OSError, IOError):
+            Logs.warn("VERSION file is not writeable")
+
+    return splitVersion(gitVersion)
diff --git a/NFD b/NFD
new file mode 160000
index 0000000..92f9bb0
--- /dev/null
+++ b/NFD
@@ -0,0 +1 @@
+Subproject commit 92f9bb004266f99d092ac0156fdb7ad951d7f0ee
diff --git a/docs/source/getting-started.rst b/docs/source/getting-started.rst
index 9a5d0aa..cea91d2 100644
--- a/docs/source/getting-started.rst
+++ b/docs/source/getting-started.rst
@@ -124,7 +124,7 @@
     git clone https://github.com/named-data/ndn-cxx.git ndn-cxx
     git clone https://github.com/named-data-ndnSIM/ns-3-dev.git ns-3
     git clone https://github.com/named-data-ndnSIM/pybindgen.git pybindgen
-    git clone https://github.com/named-data-ndnSIM/ndnSIM.git ns-3/src/ndnSIM
+    git clone --recursive https://github.com/named-data-ndnSIM/ndnSIM.git ns-3/src/ndnSIM
 
 The few modification to the base NS-3 code are necessary to run ndnSIM, and the code is
 periodically synchronized with the official developer branch.  Eventually, all the changes will
@@ -256,7 +256,7 @@
         cd ndnSIM
         git clone https://github.com/named-data-ndnSIM/ns-3-dev.git ns-3
         git clone https://github.com/named-data-ndnSIM/pybindgen.git pybindgen
-        git clone https://github.com/named-data-ndnSIM/ndnSIM.git ns-3/src/ndnSIM
+        git clone --recursive https://github.com/named-data-ndnSIM/ndnSIM.git ns-3/src/ndnSIM
 
         # Build and install NS-3 and ndnSIM
         cd ns-3
diff --git a/wscript b/wscript
index a0e0adc..53fc23f 100644
--- a/wscript
+++ b/wscript
@@ -13,12 +13,12 @@
 
 def options(opt):
     opt.load(['dependency-checker',
-              'doxygen', 'sphinx_build', 'type_traits', 'compiler-features'],
+              'doxygen', 'sphinx_build', 'type_traits', 'compiler-features', 'version'],
              tooldir=['%s/.waf-tools' % opt.path.abspath()])
 
 def configure(conf):
     conf.load(['dependency-checker',
-               'doxygen', 'sphinx_build', 'type_traits', 'compiler-features'])
+               'doxygen', 'sphinx_build', 'type_traits', 'compiler-features', 'version'])
 
     conf.env['ENABLE_NDNSIM']=False
 
@@ -72,7 +72,18 @@
 
     conf.report_optional_feature("ndnSIM", "ndnSIM", True, "")
 
+    conf.write_config_header('NFD/config.hpp', remove=False)
+
 def build(bld):
+    (base, build, split) = bld.getVersion('NFD')
+    bld(features="subst",
+        source='NFD/version.hpp.in', target='NFD/version.hpp',
+        install_path=None,
+        VERSION_STRING=base,
+        VERSION_BUILD="%s-ndnSIM" % build,
+        VERSION=int(split[0]) * 1000000 + int(split[1]) * 1000 + int(split[2]),
+        VERSION_MAJOR=split[0], VERSION_MINOR=split[1], VERSION_PATCH=split[2])
+
     deps = ['core', 'network', 'point-to-point', 'topology-read', 'mobility', 'internet']
     if 'ns3-visualizer' in bld.env['NS3_ENABLED_MODULES']:
         deps.append('visualizer')
@@ -95,10 +106,19 @@
         bld.env['MODULES_NOT_BUILT'].append('ndnSIM')
         return
 
-    module_dirs = ['NFD', 'apps', 'helper', 'model', 'utils']
+    module_dirs = ['NFD/core', 'NFD/daemon', 'apps', 'helper', 'model', 'utils']
 
     module.source = bld.path.ant_glob(['%s/**/*.cpp' % dir for dir in module_dirs],
-                                      excl=['model/ip-faces/*'])
+                                      excl=['model/ip-faces/*',
+                                            'NFD/core/network-interface.cpp',
+                                            'NFD/daemon/main.cpp',
+                                            'NFD/daemon/nfd.*',
+                                            'NFD/daemon/face/ethernet*',
+                                            'NFD/daemon/face/multicast-udp*',
+                                            'NFD/daemon/face/tcp*',
+                                            'NFD/daemon/face/udp*',
+                                            'NFD/daemon/face/unix-stream*',
+                                            'NFD/daemon/face/websocket*'])
 
     module.full_headers = [p.path_from(bld.path) for p in bld.path.ant_glob(
         ['%s/**/*.hpp' % dir for dir in module_dirs])]