blob: 17c7b4aa79778c0d165ae13c18b998ea348aab4f [file] [log] [blame]
Vince Lehmanb8b18062015-07-14 13:07:22 -05001# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2#
Ashlesh Gawandeb07ada82016-08-05 14:29:17 -05003# Copyright (C) 2016 The University of Memphis,
Vince Lehmanb8b18062015-07-14 13:07:22 -05004# Arizona Board of Regents,
5# Regents of the University of California.
6#
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
24import time
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
ashuef3490b2015-02-17 11:01:04 -060031 def __init__(self, node):
Ashlesh Gawande792c6aa2015-07-10 12:18:36 -050032 NdnApplication.__init__(self, node)
ashuef3490b2015-02-17 11:01:04 -060033
Ashlesh Gawande3a4afb12015-07-09 09:23:30 -050034 self.logLevel = node.params["params"].get("nfd-log-level", "NONE")
35
Ashlesh Gawande1b663692015-10-14 16:38:10 -050036 self.confFile = "%s/%s.conf" % (node.homeFolder, node.name)
37 self.logFile = "%s/%s.log" % (node.homeFolder, node.name)
ashuef3490b2015-02-17 11:01:04 -060038 self.sockFile = "/var/run/%s.sock" % node.name
Ashlesh Gawande1b663692015-10-14 16:38:10 -050039 self.ndnFolder = "%s/.ndn" % node.homeFolder
ashuef3490b2015-02-17 11:01:04 -060040 self.clientConf = "%s/client.conf" % self.ndnFolder
41
ashu2ad32e22015-05-29 13:37:40 -050042 # Copy nfd.conf file from /usr/local/etc/mini-ndn to the node's home
43 node.cmd("sudo cp /usr/local/etc/mini-ndn/nfd.conf %s" % self.confFile)
ashuef3490b2015-02-17 11:01:04 -060044
Ashlesh Gawande3a4afb12015-07-09 09:23:30 -050045 # Set log level
46 node.cmd("sudo sed -i \'s|$LOG_LEVEL|%s|g\' %s" % (self.logLevel, self.confFile))
47
ashuef3490b2015-02-17 11:01:04 -060048 # Open the conf file and change socket file name
49 node.cmd("sudo sed -i 's|nfd.sock|%s.sock|g' %s" % (node.name, self.confFile))
50
51 # Make NDN folder
52 node.cmd("sudo mkdir %s" % self.ndnFolder)
53
54 # Copy the client.conf file and change the unix socket
ashu2ad32e22015-05-29 13:37:40 -050055 node.cmd("sudo cp /usr/local/etc/mini-ndn/client.conf.sample %s" % self.clientConf)
ashuef3490b2015-02-17 11:01:04 -060056 node.cmd("sudo sed -i 's|nfd.sock|%s.sock|g' %s" % (node.name, self.clientConf))
57
58 # Change home folder
Ashlesh Gawande1b663692015-10-14 16:38:10 -050059 node.cmd("export HOME=%s" % node.homeFolder)
ashuef3490b2015-02-17 11:01:04 -060060
61 def start(self):
Ashlesh Gawandec09c16d2016-08-05 14:13:12 -050062 NdnApplication.start(self, "nfd --config %s 2>> %s &" % (self.confFile, self.logFile))
Ashlesh Gawande792c6aa2015-07-10 12:18:36 -050063 time.sleep(2)
ashuef3490b2015-02-17 11:01:04 -060064
65 def setStrategy(self, name, strategy):
ashu34c3ee02015-03-25 14:41:14 -050066 self.node.cmd("nfdc set-strategy %s ndn:/localhost/nfd/strategy/%s" % (name, strategy))
ashuef3490b2015-02-17 11:01:04 -060067 time.sleep(0.5)