ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import time |
Ashlesh Gawande | 792c6aa | 2015-07-10 12:18:36 -0500 | [diff] [blame^] | 4 | from ndn.ndn_application import NdnApplication |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 5 | |
Ashlesh Gawande | 792c6aa | 2015-07-10 12:18:36 -0500 | [diff] [blame^] | 6 | class Nfd(NdnApplication): |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 7 | STRATEGY_BEST_ROUTE_V3 = "best-route/%FD%03" |
| 8 | STRATEGY_NCC = "ncc" |
| 9 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 10 | def __init__(self, node): |
Ashlesh Gawande | 792c6aa | 2015-07-10 12:18:36 -0500 | [diff] [blame^] | 11 | NdnApplication.__init__(self, node) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 12 | |
Ashlesh Gawande | 3a4afb1 | 2015-07-09 09:23:30 -0500 | [diff] [blame] | 13 | self.logLevel = node.params["params"].get("nfd-log-level", "NONE") |
| 14 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 15 | # Create home directory for a node |
| 16 | node.cmd("cd /tmp && mkdir %s" % node.name) |
| 17 | node.cmd("cd %s" % node.name) |
| 18 | |
| 19 | self.homeFolder = "/tmp/%s" % node.name |
| 20 | self.confFile = "%s/%s.conf" % (self.homeFolder, node.name) |
| 21 | self.logFile = "%s/%s.log" % (self.homeFolder, node.name) |
| 22 | self.sockFile = "/var/run/%s.sock" % node.name |
| 23 | self.ndnFolder = "%s/.ndn" % self.homeFolder |
| 24 | self.clientConf = "%s/client.conf" % self.ndnFolder |
| 25 | |
ashu | 2ad32e2 | 2015-05-29 13:37:40 -0500 | [diff] [blame] | 26 | # Copy nfd.conf file from /usr/local/etc/mini-ndn to the node's home |
| 27 | 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] | 28 | |
Ashlesh Gawande | 3a4afb1 | 2015-07-09 09:23:30 -0500 | [diff] [blame] | 29 | # Set log level |
| 30 | node.cmd("sudo sed -i \'s|$LOG_LEVEL|%s|g\' %s" % (self.logLevel, self.confFile)) |
| 31 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 32 | # Open the conf file and change socket file name |
| 33 | node.cmd("sudo sed -i 's|nfd.sock|%s.sock|g' %s" % (node.name, self.confFile)) |
| 34 | |
| 35 | # Make NDN folder |
| 36 | node.cmd("sudo mkdir %s" % self.ndnFolder) |
| 37 | |
| 38 | # Copy the client.conf file and change the unix socket |
ashu | 2ad32e2 | 2015-05-29 13:37:40 -0500 | [diff] [blame] | 39 | 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] | 40 | node.cmd("sudo sed -i 's|nfd.sock|%s.sock|g' %s" % (node.name, self.clientConf)) |
| 41 | |
| 42 | # Change home folder |
| 43 | node.cmd("export HOME=%s" % self.homeFolder) |
| 44 | |
| 45 | def start(self): |
Ashlesh Gawande | 792c6aa | 2015-07-10 12:18:36 -0500 | [diff] [blame^] | 46 | NdnApplication.start(self, "sudo nfd --config %s 2>> %s &" % (self.confFile, self.logFile)) |
| 47 | time.sleep(2) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 48 | |
| 49 | def setStrategy(self, name, strategy): |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 50 | 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] | 51 | time.sleep(0.5) |