blob: 4caceac3f524c67d3c81f309e36e9f9158a62b66 [file] [log] [blame]
ashuef3490b2015-02-17 11:01:04 -06001#!/usr/bin/env python
2
3import time
Ashlesh Gawande792c6aa2015-07-10 12:18:36 -05004from ndn.ndn_application import NdnApplication
ashuef3490b2015-02-17 11:01:04 -06005
Ashlesh Gawande792c6aa2015-07-10 12:18:36 -05006class Nfd(NdnApplication):
ashu34c3ee02015-03-25 14:41:14 -05007 STRATEGY_BEST_ROUTE_V3 = "best-route/%FD%03"
8 STRATEGY_NCC = "ncc"
9
ashuef3490b2015-02-17 11:01:04 -060010 def __init__(self, node):
Ashlesh Gawande792c6aa2015-07-10 12:18:36 -050011 NdnApplication.__init__(self, node)
ashuef3490b2015-02-17 11:01:04 -060012
Ashlesh Gawande3a4afb12015-07-09 09:23:30 -050013 self.logLevel = node.params["params"].get("nfd-log-level", "NONE")
14
ashuef3490b2015-02-17 11:01:04 -060015 # 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
ashu2ad32e22015-05-29 13:37:40 -050026 # 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)
ashuef3490b2015-02-17 11:01:04 -060028
Ashlesh Gawande3a4afb12015-07-09 09:23:30 -050029 # Set log level
30 node.cmd("sudo sed -i \'s|$LOG_LEVEL|%s|g\' %s" % (self.logLevel, self.confFile))
31
ashuef3490b2015-02-17 11:01:04 -060032 # 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
ashu2ad32e22015-05-29 13:37:40 -050039 node.cmd("sudo cp /usr/local/etc/mini-ndn/client.conf.sample %s" % self.clientConf)
ashuef3490b2015-02-17 11:01:04 -060040 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 Gawande792c6aa2015-07-10 12:18:36 -050046 NdnApplication.start(self, "sudo nfd --config %s 2>> %s &" % (self.confFile, self.logFile))
47 time.sleep(2)
ashuef3490b2015-02-17 11:01:04 -060048
49 def setStrategy(self, name, strategy):
ashu34c3ee02015-03-25 14:41:14 -050050 self.node.cmd("nfdc set-strategy %s ndn:/localhost/nfd/strategy/%s" % (name, strategy))
ashuef3490b2015-02-17 11:01:04 -060051 time.sleep(0.5)