blob: eb8cb345fca54ca40d51e67ff3ec4ff2b03c65a4 [file] [log] [blame]
Vince Lehmanb8b18062015-07-14 13:07:22 -05001# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2#
Alexander Lane9944cf52018-05-17 12:16:50 -05003# Copyright (C) 2015-2018, The University of Memphis,
Ashlesh Gawande0cccdb82016-08-15 12:58:06 -05004# Arizona Board of Regents,
5# Regents of the University of California.
Vince Lehmanb8b18062015-07-14 13:07:22 -05006#
7# This file is part of Mini-NDN.
8# See AUTHORS.md for a complete list of Mini-NDN authors and contributors.
9#
10# Mini-NDN is free software: you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# Mini-NDN is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with Mini-NDN, e.g., in COPYING.md file.
22# If not, see <http://www.gnu.org/licenses/>.
ashuef3490b2015-02-17 11:01:04 -060023
Saurab Dulal5d9ba602017-11-29 21:31:13 +000024import time, sys, os
Ashlesh Gawande792c6aa2015-07-10 12:18:36 -050025from ndn.ndn_application import NdnApplication
Alexander Lane4fa88812018-05-23 12:56:52 -050026from ndn.util import copyExistentFile
ashuef3490b2015-02-17 11:01:04 -060027
Ashlesh Gawande792c6aa2015-07-10 12:18:36 -050028class Nfd(NdnApplication):
ashu34c3ee02015-03-25 14:41:14 -050029
Ashlesh Gawande532302b2018-02-15 18:58:20 -060030 def __init__(self, node, csSize):
Ashlesh Gawande792c6aa2015-07-10 12:18:36 -050031 NdnApplication.__init__(self, node)
ashuef3490b2015-02-17 11:01:04 -060032
Saurab Dulal7a6978e2017-11-29 10:50:09 -060033 self.logLevel = node.params["params"].get("nfd-log-level", "INFO")
Ashlesh Gawande3a4afb12015-07-09 09:23:30 -050034
Saurab Dulal092755e2018-01-19 03:36:41 +000035 self.confFile = "{}/nfd.conf".format(node.homeFolder)
36 self.logFile = "{}/nfd.log".format(node.homeFolder)
Saurab Dulal5d9ba602017-11-29 21:31:13 +000037 self.sockFile = "/var/run/{}.sock".format(node.name)
38 self.ndnFolder = "{}/.ndn".format(node.homeFolder)
39 self.clientConf = "{}/client.conf".format(self.ndnFolder)
ashuef3490b2015-02-17 11:01:04 -060040
Alexander Lane4fa88812018-05-23 12:56:52 -050041 # Copy nfd.conf file from /usr/local/etc/ndn or /etc/ndn to the node's home directory
Saurab Dulal5d9ba602017-11-29 21:31:13 +000042 # Use nfd.conf as default configuration for NFD, else use the sample
Alexander Lane4fa88812018-05-23 12:56:52 -050043 possibleConfPaths = ["/usr/local/etc/ndn/nfd.conf.sample", "/usr/local/etc/ndn/nfd.conf",
44 "/etc/ndn/nfd.conf.sample", "/etc/ndn/nfd.conf"]
45 copyExistentFile(node, possibleConfPaths, self.confFile)
ashuef3490b2015-02-17 11:01:04 -060046
Ashlesh Gawande3a4afb12015-07-09 09:23:30 -050047 # Set log level
Saurab Dulal5d9ba602017-11-29 21:31:13 +000048 node.cmd("infoedit -f {} -s log.default_level -v {}".format(self.confFile, self.logLevel))
ashuef3490b2015-02-17 11:01:04 -060049 # Open the conf file and change socket file name
Saurab Dulal5d9ba602017-11-29 21:31:13 +000050 node.cmd("infoedit -f {} -s face_system.unix.path -v /var/run/{}.sock".format(self.confFile, node.name))
ashuef3490b2015-02-17 11:01:04 -060051
Ashlesh Gawande532302b2018-02-15 18:58:20 -060052 # Set CS size
53 node.cmd("infoedit -f {} -s tables.cs_max_packets -v {}".format(self.confFile, csSize))
54
ashuef3490b2015-02-17 11:01:04 -060055 # Make NDN folder
Saurab Dulal5d9ba602017-11-29 21:31:13 +000056 node.cmd("sudo mkdir {}".format(self.ndnFolder))
ashuef3490b2015-02-17 11:01:04 -060057
Alexander Lane4fa88812018-05-23 12:56:52 -050058 # Copy client configuration to host
59 possibleClientConfPaths = ["/usr/local/etc/ndn/client.conf.sample", "/etc/ndn/client.conf.sample"]
60 copyExistentFile(node, possibleClientConfPaths, self.clientConf)
Saurab Dulal5d9ba602017-11-29 21:31:13 +000061
Alexander Lane4fa88812018-05-23 12:56:52 -050062 # Change the unix socket
Saurab Dulal5d9ba602017-11-29 21:31:13 +000063 node.cmd("sudo sed -i 's|nfd.sock|{}.sock|g' {}".format(node.name, self.clientConf))
ashuef3490b2015-02-17 11:01:04 -060064
65 # Change home folder
Saurab Dulal5d9ba602017-11-29 21:31:13 +000066 node.cmd("export HOME={}".format(node.homeFolder))
Ashlesh Gawandea80484e2017-10-17 15:52:23 -050067 node.cmd("ndnsec-keygen /localhost/operator | ndnsec-install-cert -")
ashuef3490b2015-02-17 11:01:04 -060068
69 def start(self):
Ashlesh Gawande532302b2018-02-15 18:58:20 -060070 NdnApplication.start(self, "setsid nfd --config {} > {} 2>&1 &".format(self.confFile, self.logFile))
Ashlesh Gawande792c6aa2015-07-10 12:18:36 -050071 time.sleep(2)