nfd: add option to set CS size

Don't append NFD logs b/w runs
Re-factor NFD start from ndn_host.py to bin/minindn

refs: #4469, #4508

Change-Id: I43f594a3353bb92101a0281a4561999cd8406707
diff --git a/ndn/ndn_application.py b/ndn/ndn_application.py
index 7720734..dd9100e 100644
--- a/ndn/ndn_application.py
+++ b/ndn/ndn_application.py
@@ -43,7 +43,7 @@
             self.isRunning = True
 
     def stop(self):
-        if self.isRunning:
-            self.node.cmd("sudo kill %s" % self.processId)
+        if self.isRunning and self.processId != "":
+            self.node.cmd("sudo kill {}".format(self.processId))
 
             self.isRunning = False
diff --git a/ndn/ndn_host.py b/ndn/ndn_host.py
index 7c727ab..7596f5f 100644
--- a/ndn/ndn_host.py
+++ b/ndn/ndn_host.py
@@ -100,8 +100,7 @@
         self.cmd("mkdir -p %s" % self.homeFolder)
         self.cmd("cd %s" % self.homeFolder)
 
-        self.nfd = Nfd(self)
-        self.nfd.start()
+        self.nfd = None
 
         self.peerList = {}
 
@@ -116,7 +115,8 @@
 
     def terminate(self):
         "Stop node."
-        self.nfd.stop()
+        if self.nfd is not None:
+            self.nfd.stop()
         Host.terminate(self)
 
 class CpuLimitedNdnHost(CPULimitedHost, NdnHostCommon):
@@ -134,8 +134,7 @@
         self.cmd("mkdir -p %s" % self.homeFolder)
         self.cmd("cd %s" % self.homeFolder)
 
-        self.nfd = Nfd(self)
-        self.nfd.start()
+        self.nfd = None
 
         self.peerList = {}
 
@@ -150,8 +149,9 @@
 
     def terminate(self):
         "Stop node."
-        self.nfd.stop()
-        Host.terminate(self)
+        if self.nfd is not None:
+            self.nfd.stop()
+        CPULimitedHost.terminate(self)
 
 class RemoteNdnHost(RemoteMixin, NdnHost):
     "A node on a remote server"
diff --git a/ndn/nfd.py b/ndn/nfd.py
index 880d248..09e28d5 100644
--- a/ndn/nfd.py
+++ b/ndn/nfd.py
@@ -24,12 +24,11 @@
 import time, sys, os
 from ndn.ndn_application import NdnApplication
 
-
 class Nfd(NdnApplication):
     STRATEGY_BEST_ROUTE = "best-route"
     STRATEGY_NCC = "ncc"
 
-    def __init__(self, node):
+    def __init__(self, node, csSize):
         NdnApplication.__init__(self, node)
 
         self.logLevel = node.params["params"].get("nfd-log-level", "INFO")
@@ -55,6 +54,9 @@
         # Open the conf file and change socket file name
         node.cmd("infoedit -f {} -s face_system.unix.path -v /var/run/{}.sock".format(self.confFile, node.name))
 
+        # Set CS size
+        node.cmd("infoedit -f {} -s tables.cs_max_packets -v {}".format(self.confFile, csSize))
+
         # Make NDN folder
         node.cmd("sudo mkdir {}".format(self.ndnFolder))
 
@@ -68,7 +70,7 @@
         node.cmd("ndnsec-keygen /localhost/operator | ndnsec-install-cert -")
 
     def start(self):
-        NdnApplication.start(self, "setsid nfd --config {} >> {} 2>&1 &".format(self.confFile, self.logFile))
+        NdnApplication.start(self, "setsid nfd --config {} > {} 2>&1 &".format(self.confFile, self.logFile))
         time.sleep(2)
 
     def setStrategy(self, name, strategy):