blob: 09e28d5fbe266a29ea191579efc2fa19675a06e9 [file] [log] [blame]
Vince Lehmanb8b18062015-07-14 13:07:22 -05001# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2#
Ashlesh Gawandeda475f02017-03-01 17:20:58 -06003# Copyright (C) 2015-2017, 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
ashuef3490b2015-02-17 11:01:04 -060026
Ashlesh Gawande792c6aa2015-07-10 12:18:36 -050027class Nfd(NdnApplication):
Ashlesh Gawandeb07ada82016-08-05 14:29:17 -050028 STRATEGY_BEST_ROUTE = "best-route"
ashu34c3ee02015-03-25 14:41:14 -050029 STRATEGY_NCC = "ncc"
30
Ashlesh Gawande532302b2018-02-15 18:58:20 -060031 def __init__(self, node, csSize):
Ashlesh Gawande792c6aa2015-07-10 12:18:36 -050032 NdnApplication.__init__(self, node)
ashuef3490b2015-02-17 11:01:04 -060033
Saurab Dulal7a6978e2017-11-29 10:50:09 -060034 self.logLevel = node.params["params"].get("nfd-log-level", "INFO")
Ashlesh Gawande3a4afb12015-07-09 09:23:30 -050035
Saurab Dulal092755e2018-01-19 03:36:41 +000036 self.confFile = "{}/nfd.conf".format(node.homeFolder)
37 self.logFile = "{}/nfd.log".format(node.homeFolder)
Saurab Dulal5d9ba602017-11-29 21:31:13 +000038 self.sockFile = "/var/run/{}.sock".format(node.name)
39 self.ndnFolder = "{}/.ndn".format(node.homeFolder)
40 self.clientConf = "{}/client.conf".format(self.ndnFolder)
ashuef3490b2015-02-17 11:01:04 -060041
Saurab Dulal5d9ba602017-11-29 21:31:13 +000042 # Copy nfd.conf file from /usr/local/etc/ndn to the node's home
43
44 # Use nfd.conf as default configuration for NFD, else use the sample
45 if os.path.isfile("/usr/local/etc/ndn/nfd.conf") == True:
46 node.cmd("sudo cp /usr/local/etc/ndn/nfd.conf {}".format(self.confFile))
47 elif os.path.isfile("/usr/local/etc/ndn/nfd.conf.sample") == True:
48 node.cmd("sudo cp /usr/local/etc/ndn/nfd.conf.sample {}".format(self.confFile))
49 else:
50 sys.exit("nfd.conf or nfd.conf.sample cannot be found in the expected directory. Exit.")
ashuef3490b2015-02-17 11:01:04 -060051
Ashlesh Gawande3a4afb12015-07-09 09:23:30 -050052 # Set log level
Saurab Dulal5d9ba602017-11-29 21:31:13 +000053 node.cmd("infoedit -f {} -s log.default_level -v {}".format(self.confFile, self.logLevel))
ashuef3490b2015-02-17 11:01:04 -060054 # Open the conf file and change socket file name
Saurab Dulal5d9ba602017-11-29 21:31:13 +000055 node.cmd("infoedit -f {} -s face_system.unix.path -v /var/run/{}.sock".format(self.confFile, node.name))
ashuef3490b2015-02-17 11:01:04 -060056
Ashlesh Gawande532302b2018-02-15 18:58:20 -060057 # Set CS size
58 node.cmd("infoedit -f {} -s tables.cs_max_packets -v {}".format(self.confFile, csSize))
59
ashuef3490b2015-02-17 11:01:04 -060060 # Make NDN folder
Saurab Dulal5d9ba602017-11-29 21:31:13 +000061 node.cmd("sudo mkdir {}".format(self.ndnFolder))
ashuef3490b2015-02-17 11:01:04 -060062
63 # Copy the client.conf file and change the unix socket
Saurab Dulal5d9ba602017-11-29 21:31:13 +000064 node.cmd("sudo cp /usr/local/etc/ndn/client.conf.sample {}".format(self.clientConf))
65
66 node.cmd("sudo sed -i 's|nfd.sock|{}.sock|g' {}".format(node.name, self.clientConf))
ashuef3490b2015-02-17 11:01:04 -060067
68 # Change home folder
Saurab Dulal5d9ba602017-11-29 21:31:13 +000069 node.cmd("export HOME={}".format(node.homeFolder))
Ashlesh Gawandea80484e2017-10-17 15:52:23 -050070 node.cmd("ndnsec-keygen /localhost/operator | ndnsec-install-cert -")
ashuef3490b2015-02-17 11:01:04 -060071
72 def start(self):
Ashlesh Gawande532302b2018-02-15 18:58:20 -060073 NdnApplication.start(self, "setsid nfd --config {} > {} 2>&1 &".format(self.confFile, self.logFile))
Ashlesh Gawande792c6aa2015-07-10 12:18:36 -050074 time.sleep(2)
ashuef3490b2015-02-17 11:01:04 -060075
76 def setStrategy(self, name, strategy):
Saurab Dulal5d9ba602017-11-29 21:31:13 +000077 self.node.cmd("nfdc strategy set {} ndn:/localhost/nfd/strategy/{}".format(name, strategy))
ashuef3490b2015-02-17 11:01:04 -060078 time.sleep(0.5)