Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 1 | # -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | # |
Ashlesh Gawande | da475f0 | 2017-03-01 17:20:58 -0600 | [diff] [blame] | 3 | # Copyright (C) 2015-2017, The University of Memphis, |
Ashlesh Gawande | 0cccdb8 | 2016-08-15 12:58:06 -0500 | [diff] [blame] | 4 | # Arizona Board of Regents, |
| 5 | # Regents of the University of California. |
Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 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/>. |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 23 | |
Saurab Dulal | 5d9ba60 | 2017-11-29 21:31:13 +0000 | [diff] [blame] | 24 | import time, sys, os |
Ashlesh Gawande | 792c6aa | 2015-07-10 12:18:36 -0500 | [diff] [blame] | 25 | from ndn.ndn_application import NdnApplication |
Alexander Lane | 4fa8881 | 2018-05-23 12:56:52 -0500 | [diff] [blame^] | 26 | from ndn.util import copyExistentFile |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 27 | |
Ashlesh Gawande | 792c6aa | 2015-07-10 12:18:36 -0500 | [diff] [blame] | 28 | class Nfd(NdnApplication): |
Ashlesh Gawande | b07ada8 | 2016-08-05 14:29:17 -0500 | [diff] [blame] | 29 | STRATEGY_BEST_ROUTE = "best-route" |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 30 | STRATEGY_NCC = "ncc" |
| 31 | |
Ashlesh Gawande | 532302b | 2018-02-15 18:58:20 -0600 | [diff] [blame] | 32 | def __init__(self, node, csSize): |
Ashlesh Gawande | 792c6aa | 2015-07-10 12:18:36 -0500 | [diff] [blame] | 33 | NdnApplication.__init__(self, node) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 34 | |
Saurab Dulal | 7a6978e | 2017-11-29 10:50:09 -0600 | [diff] [blame] | 35 | self.logLevel = node.params["params"].get("nfd-log-level", "INFO") |
Ashlesh Gawande | 3a4afb1 | 2015-07-09 09:23:30 -0500 | [diff] [blame] | 36 | |
Saurab Dulal | 092755e | 2018-01-19 03:36:41 +0000 | [diff] [blame] | 37 | self.confFile = "{}/nfd.conf".format(node.homeFolder) |
| 38 | self.logFile = "{}/nfd.log".format(node.homeFolder) |
Saurab Dulal | 5d9ba60 | 2017-11-29 21:31:13 +0000 | [diff] [blame] | 39 | self.sockFile = "/var/run/{}.sock".format(node.name) |
| 40 | self.ndnFolder = "{}/.ndn".format(node.homeFolder) |
| 41 | self.clientConf = "{}/client.conf".format(self.ndnFolder) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 42 | |
Alexander Lane | 4fa8881 | 2018-05-23 12:56:52 -0500 | [diff] [blame^] | 43 | # Copy nfd.conf file from /usr/local/etc/ndn or /etc/ndn to the node's home directory |
Saurab Dulal | 5d9ba60 | 2017-11-29 21:31:13 +0000 | [diff] [blame] | 44 | # Use nfd.conf as default configuration for NFD, else use the sample |
Alexander Lane | 4fa8881 | 2018-05-23 12:56:52 -0500 | [diff] [blame^] | 45 | possibleConfPaths = ["/usr/local/etc/ndn/nfd.conf.sample", "/usr/local/etc/ndn/nfd.conf", |
| 46 | "/etc/ndn/nfd.conf.sample", "/etc/ndn/nfd.conf"] |
| 47 | copyExistentFile(node, possibleConfPaths, self.confFile) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 48 | |
Ashlesh Gawande | 3a4afb1 | 2015-07-09 09:23:30 -0500 | [diff] [blame] | 49 | # Set log level |
Saurab Dulal | 5d9ba60 | 2017-11-29 21:31:13 +0000 | [diff] [blame] | 50 | node.cmd("infoedit -f {} -s log.default_level -v {}".format(self.confFile, self.logLevel)) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 51 | # Open the conf file and change socket file name |
Saurab Dulal | 5d9ba60 | 2017-11-29 21:31:13 +0000 | [diff] [blame] | 52 | node.cmd("infoedit -f {} -s face_system.unix.path -v /var/run/{}.sock".format(self.confFile, node.name)) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 53 | |
Ashlesh Gawande | 532302b | 2018-02-15 18:58:20 -0600 | [diff] [blame] | 54 | # Set CS size |
| 55 | node.cmd("infoedit -f {} -s tables.cs_max_packets -v {}".format(self.confFile, csSize)) |
| 56 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 57 | # Make NDN folder |
Saurab Dulal | 5d9ba60 | 2017-11-29 21:31:13 +0000 | [diff] [blame] | 58 | node.cmd("sudo mkdir {}".format(self.ndnFolder)) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 59 | |
Alexander Lane | 4fa8881 | 2018-05-23 12:56:52 -0500 | [diff] [blame^] | 60 | # Copy client configuration to host |
| 61 | possibleClientConfPaths = ["/usr/local/etc/ndn/client.conf.sample", "/etc/ndn/client.conf.sample"] |
| 62 | copyExistentFile(node, possibleClientConfPaths, self.clientConf) |
Saurab Dulal | 5d9ba60 | 2017-11-29 21:31:13 +0000 | [diff] [blame] | 63 | |
Alexander Lane | 4fa8881 | 2018-05-23 12:56:52 -0500 | [diff] [blame^] | 64 | # Change the unix socket |
Saurab Dulal | 5d9ba60 | 2017-11-29 21:31:13 +0000 | [diff] [blame] | 65 | node.cmd("sudo sed -i 's|nfd.sock|{}.sock|g' {}".format(node.name, self.clientConf)) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 66 | |
| 67 | # Change home folder |
Saurab Dulal | 5d9ba60 | 2017-11-29 21:31:13 +0000 | [diff] [blame] | 68 | node.cmd("export HOME={}".format(node.homeFolder)) |
Ashlesh Gawande | a80484e | 2017-10-17 15:52:23 -0500 | [diff] [blame] | 69 | node.cmd("ndnsec-keygen /localhost/operator | ndnsec-install-cert -") |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 70 | |
| 71 | def start(self): |
Ashlesh Gawande | 532302b | 2018-02-15 18:58:20 -0600 | [diff] [blame] | 72 | NdnApplication.start(self, "setsid nfd --config {} > {} 2>&1 &".format(self.confFile, self.logFile)) |
Ashlesh Gawande | 792c6aa | 2015-07-10 12:18:36 -0500 | [diff] [blame] | 73 | time.sleep(2) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 74 | |
| 75 | def setStrategy(self, name, strategy): |
Saurab Dulal | 5d9ba60 | 2017-11-29 21:31:13 +0000 | [diff] [blame] | 76 | self.node.cmd("nfdc strategy set {} ndn:/localhost/nfd/strategy/{}".format(name, strategy)) |
Alexander Lane | 4fa8881 | 2018-05-23 12:56:52 -0500 | [diff] [blame^] | 77 | time.sleep(0.5) |