Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 1 | # -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | # |
| 3 | # Copyright (C) 2015 The University of Memphis, |
| 4 | # 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/>. |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 23 | |
| 24 | import time |
Ashlesh Gawande | 792c6aa | 2015-07-10 12:18:36 -0500 | [diff] [blame] | 25 | from ndn.ndn_application import NdnApplication |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 26 | |
Ashlesh Gawande | 792c6aa | 2015-07-10 12:18:36 -0500 | [diff] [blame] | 27 | class Nfd(NdnApplication): |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 28 | STRATEGY_BEST_ROUTE_V3 = "best-route/%FD%03" |
| 29 | STRATEGY_NCC = "ncc" |
| 30 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 31 | def __init__(self, node): |
Ashlesh Gawande | 792c6aa | 2015-07-10 12:18:36 -0500 | [diff] [blame] | 32 | NdnApplication.__init__(self, node) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 33 | |
Ashlesh Gawande | 3a4afb1 | 2015-07-09 09:23:30 -0500 | [diff] [blame] | 34 | self.logLevel = node.params["params"].get("nfd-log-level", "NONE") |
| 35 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 36 | # Create home directory for a node |
| 37 | node.cmd("cd /tmp && mkdir %s" % node.name) |
| 38 | node.cmd("cd %s" % node.name) |
| 39 | |
| 40 | self.homeFolder = "/tmp/%s" % node.name |
| 41 | self.confFile = "%s/%s.conf" % (self.homeFolder, node.name) |
| 42 | self.logFile = "%s/%s.log" % (self.homeFolder, node.name) |
| 43 | self.sockFile = "/var/run/%s.sock" % node.name |
| 44 | self.ndnFolder = "%s/.ndn" % self.homeFolder |
| 45 | self.clientConf = "%s/client.conf" % self.ndnFolder |
| 46 | |
ashu | 2ad32e2 | 2015-05-29 13:37:40 -0500 | [diff] [blame] | 47 | # Copy nfd.conf file from /usr/local/etc/mini-ndn to the node's home |
| 48 | node.cmd("sudo cp /usr/local/etc/mini-ndn/nfd.conf %s" % self.confFile) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 49 | |
Ashlesh Gawande | 3a4afb1 | 2015-07-09 09:23:30 -0500 | [diff] [blame] | 50 | # Set log level |
| 51 | node.cmd("sudo sed -i \'s|$LOG_LEVEL|%s|g\' %s" % (self.logLevel, self.confFile)) |
| 52 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 53 | # Open the conf file and change socket file name |
| 54 | node.cmd("sudo sed -i 's|nfd.sock|%s.sock|g' %s" % (node.name, self.confFile)) |
| 55 | |
| 56 | # Make NDN folder |
| 57 | node.cmd("sudo mkdir %s" % self.ndnFolder) |
| 58 | |
| 59 | # Copy the client.conf file and change the unix socket |
ashu | 2ad32e2 | 2015-05-29 13:37:40 -0500 | [diff] [blame] | 60 | node.cmd("sudo cp /usr/local/etc/mini-ndn/client.conf.sample %s" % self.clientConf) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 61 | node.cmd("sudo sed -i 's|nfd.sock|%s.sock|g' %s" % (node.name, self.clientConf)) |
| 62 | |
| 63 | # Change home folder |
| 64 | node.cmd("export HOME=%s" % self.homeFolder) |
| 65 | |
| 66 | def start(self): |
Ashlesh Gawande | 792c6aa | 2015-07-10 12:18:36 -0500 | [diff] [blame] | 67 | NdnApplication.start(self, "sudo nfd --config %s 2>> %s &" % (self.confFile, self.logFile)) |
| 68 | time.sleep(2) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 69 | |
| 70 | def setStrategy(self, name, strategy): |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 71 | self.node.cmd("nfdc set-strategy %s ndn:/localhost/nfd/strategy/%s" % (name, strategy)) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 72 | time.sleep(0.5) |