use infoedit to edit nfd config files

refs: #4038

Change-Id: I193f32f54c0b47f6e2c1803b0bc4cdda9056540a
diff --git a/.gitignore b/.gitignore
index ce2d0ba..45f9e2d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,16 +1,18 @@
-Mini_NDN.egg-info
 build
+crypto
+ChronoSync
 dist
 doc/html
 doc/latex
+.DS_Store
+examples
+infoedit
+Mini_NDN.egg-info
+mininet
 NFD
 NLSR
-crypto
-mininet
 ndn-cxx
 ndn-tools
 openflow
-examples
 util
-.DS_Store
 .vagrant
diff --git a/INSTALL.md b/INSTALL.md
index 1792aa2..b8348ed 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -16,7 +16,7 @@
 
 else if you don't have the dependencies, the following command will install them along with Mini-NDN:
 
-    sudo ./install.sh -mrfti
+    sudo ./install.sh -emrfti
 
 else if you want to install the dependencies manually, follow the instructions below:
 
@@ -56,6 +56,13 @@
 for `Results:` two-thirds of the way down where it will indicate the percentage of dropped packets.
 Your results should show "0% dropped (2/2 received)".
 
+### Installing Infoedit
+
+Infoedit is used to edit configuration files such as NFD configuration file.
+
+To install infoedit:
+https://github.com/NDN-Routing/infoedit
+
 ### Verification
 
 You can use these steps to verify your installation:
diff --git a/bin/minindn b/bin/minindn
index b4ad0c2..930314f 100755
--- a/bin/minindn
+++ b/bin/minindn
@@ -343,18 +343,6 @@
             print("Placement list sum is not equal to number of nodes!")
             sys.exit(1)
 
-    # Use nfd.conf as default configuration for NFD, else use the sample
-
-    nfdConfFile = "%s/nfd.conf" % INSTALL_DIR
-    if os.path.isfile("/usr/local/etc/ndn/nfd.conf") == True:
-        shutil.copy2("/usr/local/etc/ndn/nfd.conf", nfdConfFile)
-    elif os.path.isfile("/usr/local/etc/ndn/nfd.conf.sample") == True:
-        shutil.copy2("/usr/local/etc/ndn/nfd.conf.sample", nfdConfFile)
-    else:
-        sys.exit("nfd.conf or nfd.conf.sample cannot be found in the expected directory. Exit.")
-
-    call(["sudo", "sed", "-i", 's|default_level [A-Z]*$|default_level $LOG_LEVEL|g', nfdConfFile])
-
     # Copy nfd.conf to remote hosts - this assumes that NDN versions across
     # the cluster are at least compatible if not the same
     if options.cluster is not None:
diff --git a/install.sh b/install.sh
index f47f0d6..c9a4b3c 100755
--- a/install.sh
+++ b/install.sh
@@ -205,6 +205,13 @@
     cd ../
 }
 
+function infoedit {
+    git clone --depth 1 https://github.com/NDN-Routing/infoedit.git
+    cd infoedit
+    sudo make install
+    cd ../
+}
+
 function minindn {
     if [[ updated != true ]]; then
         if [ ! -d "build" ]; then
@@ -220,7 +227,6 @@
     install_dir="/usr/local/etc/mini-ndn/"
 
     sudo mkdir -p "$install_dir"
-    sudo cp ndn_utils/client.conf.sample "$install_dir"
     sudo cp ndn_utils/topologies/default-topology.conf "$install_dir"
     sudo cp ndn_utils/topologies/minindn.caida.conf "$install_dir"
     sudo cp ndn_utils/topologies/minindn.ucla.conf "$install_dir"
@@ -228,11 +234,11 @@
     sudo python setup.py clean --all install
 }
 
-
 function usage {
     printf '\nUsage: %s [-mfrti]\n\n' $(basename $0) >&2
 
     printf 'options:\n' >&2
+    printf -- ' -e: install infoedit\n' >&2
     printf -- ' -f: install NFD\n' >&2
     printf -- ' -i: install mini-ndn\n' >&2
     printf -- ' -m: install mininet and dependencies\n' >&2
@@ -244,9 +250,10 @@
 if [[ $# -eq 0 ]]; then
     usage
 else
-    while getopts 'mfrti' OPTION
+    while getopts 'emfrti' OPTION
     do
         case $OPTION in
+        e)    infoedit;;
         f)    forwarder;;
         i)    minindn;;
         m)    mininet;;
diff --git a/ndn/nfd.py b/ndn/nfd.py
index 3e3e9da..0e10ef1 100644
--- a/ndn/nfd.py
+++ b/ndn/nfd.py
@@ -21,9 +21,10 @@
 # along with Mini-NDN, e.g., in COPYING.md file.
 # If not, see <http://www.gnu.org/licenses/>.
 
-import time
+import time, sys, os
 from ndn.ndn_application import NdnApplication
 
+
 class Nfd(NdnApplication):
     STRATEGY_BEST_ROUTE = "best-route"
     STRATEGY_NCC = "ncc"
@@ -33,35 +34,42 @@
 
         self.logLevel = node.params["params"].get("nfd-log-level", "NONE")
 
-        self.confFile = "%s/%s.conf" % (node.homeFolder, node.name)
-        self.logFile = "%s/%s.log" % (node.homeFolder, node.name)
-        self.sockFile = "/var/run/%s.sock" % node.name
-        self.ndnFolder = "%s/.ndn" % node.homeFolder
-        self.clientConf = "%s/client.conf" % self.ndnFolder
+        self.confFile = "{}/{}.conf".format(node.homeFolder, node.name)
+        self.logFile = "{}/{}.log".format(node.homeFolder, node.name)
+        self.sockFile = "/var/run/{}.sock".format(node.name)
+        self.ndnFolder = "{}/.ndn".format(node.homeFolder)
+        self.clientConf = "{}/client.conf".format(self.ndnFolder)
 
-        # Copy nfd.conf file from /usr/local/etc/mini-ndn to the node's home
-        node.cmd("sudo cp /usr/local/etc/mini-ndn/nfd.conf %s" % self.confFile)
+        # Copy nfd.conf file from /usr/local/etc/ndn to the node's home
+
+        # Use nfd.conf as default configuration for NFD, else use the sample
+        if os.path.isfile("/usr/local/etc/ndn/nfd.conf") == True:
+            node.cmd("sudo cp /usr/local/etc/ndn/nfd.conf {}".format(self.confFile))
+        elif os.path.isfile("/usr/local/etc/ndn/nfd.conf.sample") == True:
+            node.cmd("sudo cp /usr/local/etc/ndn/nfd.conf.sample {}".format(self.confFile))
+        else:
+            sys.exit("nfd.conf or nfd.conf.sample cannot be found in the expected directory. Exit.")
 
         # Set log level
-        node.cmd("sudo sed -i \'s|$LOG_LEVEL|%s|g\' %s" % (self.logLevel, self.confFile))
-
+        node.cmd("infoedit -f {} -s log.default_level -v {}".format(self.confFile, self.logLevel))
         # Open the conf file and change socket file name
-        node.cmd("sudo sed -i 's|nfd.sock|%s.sock|g' %s" % (node.name, self.confFile))
+        node.cmd("infoedit -f {} -s face_system.unix.path -v /var/run/{}.sock".format(self.confFile, node.name))
 
         # Make NDN folder
-        node.cmd("sudo mkdir %s" % self.ndnFolder)
+        node.cmd("sudo mkdir {}".format(self.ndnFolder))
 
         # Copy the client.conf file and change the unix socket
-        node.cmd("sudo cp /usr/local/etc/mini-ndn/client.conf.sample %s" % self.clientConf)
-        node.cmd("sudo sed -i 's|nfd.sock|%s.sock|g' %s" % (node.name, self.clientConf))
+        node.cmd("sudo cp /usr/local/etc/ndn/client.conf.sample {}".format(self.clientConf))
+
+        node.cmd("sudo sed -i 's|nfd.sock|{}.sock|g' {}".format(node.name, self.clientConf))
 
         # Change home folder
-        node.cmd("export HOME=%s" % node.homeFolder)
+        node.cmd("export HOME={}".format(node.homeFolder))
 
     def start(self):
-        NdnApplication.start(self, "setsid nfd --config %s >> %s 2>&1 &" % (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):
-        self.node.cmd("nfdc set-strategy %s ndn:/localhost/nfd/strategy/%s" % (name, strategy))
+        self.node.cmd("nfdc strategy set {} ndn:/localhost/nfd/strategy/{}".format(name, strategy))
         time.sleep(0.5)
diff --git a/ndn_utils/client.conf.sample b/ndn_utils/client.conf.sample
deleted file mode 100644
index d911623..0000000
--- a/ndn_utils/client.conf.sample
+++ /dev/null
@@ -1,33 +0,0 @@
-; "transport" specifies Face's default transport connection.
-; The value is a unix or tcp4 scheme Face URI.
-;
-; For example:
-;
-;   unix:///var/run/nfd.sock
-;   tcp://192.0.2.1
-;   tcp4://example.com:6363
-
-transport=unix:///var/run/nfd.sock
-
-; "protocol" determines the protocol for prefix registration
-; it has a value of:
-;   nfd-0.1
-;   nrd-0.1
-;   ndnd-tlv-0.7
-;   ndnx-0.7
-protocol=nrd-0.1
-
-; "pib" determines which Public Info Base (PIB) should used by default in applications.
-; If "pib" is not specified, the default PIB will be used.
-; Note that default PIB could be different on different system.
-; If "pib" is specified, it may have a value of:
-;   sqlite3
-; pib=sqlite3
-
-; "tpm" determines which Trusted Platform Module (TPM) should used by default in applications.
-; If "tpm" is not specified, the default TPM will be used.
-; Note that default TPM could be different on different system.
-; If "tpm" is specified, it may have a value of:
-;   file
-;   osx-keychain
-; tpm=file
\ No newline at end of file