blob: 2b6a9595c921c1a3ddeaf85508ccd2e30dc4ed5c [file] [log] [blame]
Ashlesh Gawande6c86e302019-09-17 22:27:05 -05001# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2#
3# Copyright (C) 2015-2019, 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/>.
23
24from minindn.apps.application import Application
25from minindn.util import copyExistentFile
26from minindn.minindn import Minindn
27
28class Nfd(Application):
29
30 def __init__(self, node, logLevel='NONE', csSize=65536,
31 csPolicy='lru', csUnsolicitedPolicy='drop-all'):
32 Application.__init__(self, node)
33
34 self.logLevel = node.params['params'].get('nfd-log-level', logLevel)
35
36 self.confFile = '{}/nfd.conf'.format(self.homeDir)
37 self.logFile = 'nfd.log'
Ashlesh Gawande76dbe662020-04-15 21:30:34 -070038 self.sockFile = '/run/{}.sock'.format(node.name)
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050039 self.ndnFolder = '{}/.ndn'.format(self.homeDir)
40 self.clientConf = '{}/client.conf'.format(self.ndnFolder)
41
42 # Copy nfd.conf file from /usr/local/etc/ndn or /etc/ndn to the node's home directory
43 # Use nfd.conf as default configuration for NFD, else use the sample
44 possibleConfPaths = ['/usr/local/etc/ndn/nfd.conf.sample', '/usr/local/etc/ndn/nfd.conf',
45 '/etc/ndn/nfd.conf.sample', '/etc/ndn/nfd.conf']
46 copyExistentFile(node, possibleConfPaths, self.confFile)
47
48 # Set log level
49 node.cmd('infoedit -f {} -s log.default_level -v {}'.format(self.confFile, self.logLevel))
50 # Open the conf file and change socket file name
51 node.cmd('infoedit -f {} -s face_system.unix.path -v {}'.format(self.confFile, self.sockFile))
52
53 # Set CS parameters
54 node.cmd('infoedit -f {} -s tables.cs_max_packets -v {}'.format(self.confFile, csSize))
55 node.cmd('infoedit -f {} -s tables.cs_policy -v {}'.format(self.confFile, csPolicy))
56 node.cmd('infoedit -f {} -s tables.cs_unsolicited_policy -v {}'.format(self.confFile, csUnsolicitedPolicy))
57
58 # Make NDN folder
59 node.cmd('mkdir -p {}'.format(self.ndnFolder))
60
61 # Copy client configuration to host
62 possibleClientConfPaths = ['/usr/local/etc/ndn/client.conf.sample', '/etc/ndn/client.conf.sample']
63 copyExistentFile(node, possibleClientConfPaths, self.clientConf)
64
65 # Change the unix socket
Ashlesh Gawande76dbe662020-04-15 21:30:34 -070066 node.cmd('sudo sed -i "s|;transport|transport|g" {}'.format(self.clientConf))
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050067 node.cmd('sudo sed -i "s|nfd.sock|{}.sock|g" {}'.format(node.name, self.clientConf))
68
69 if not Minindn.ndnSecurityDisabled:
70 # Generate key and install cert for /localhost/operator to be used by NFD
71 node.cmd('ndnsec-keygen /localhost/operator | ndnsec-install-cert -')
72
73 def start(self):
74 Application.start(self, 'nfd --config {}'.format(self.confFile), logfile=self.logFile)
75 Minindn.sleep(2)