2 # NEPI, a framework to manage network experiments
3 # Copyright (C) 2013 INRIA
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License version 2 as
7 # published by the Free Software Foundation;
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19 from nepi.execution.attribute import Attribute, Flags, Types
20 from nepi.execution.resource import ResourceManager, clsinit_copy, \
22 from nepi.resources.linux.ccn.ccnapplication import LinuxCCNApplication
23 from nepi.util.timefuncs import tnow, tdiffsec
28 class LinuxCCNPingServer(LinuxCCNApplication):
29 _rtype = "linux::CCNPingServer"
32 def _register_attributes(cls):
33 daemon = Attribute("d",
34 "Run ccnping server as a daemon in background",
39 freshness = Attribute("x",
40 "Set FreshnessSeconds",
44 prefix = Attribute("prefix",
45 "Prefix to serve content (e.g. ccnx:/name/prefix)",
48 cls._register_attribute(daemon)
49 cls._register_attribute(freshness)
50 cls._register_attribute(prefix)
52 def __init__(self, ec, guid):
53 super(LinuxCCNPingServer, self).__init__(ec, guid)
54 self._home = "ccnping-serv-%s" % self.guid
57 if not self.get("command"):
58 self.set("command", self._start_command)
60 if not self.get("env"):
61 self.set("env", self._environment)
63 if not self.get("depends"):
64 self.set("depends", self._dependencies)
66 if not self.get("build"):
67 self.set("build", self._build)
69 if not self.get("install"):
70 self.set("install", self._install)
72 super(LinuxCCNPingServer, self).do_deploy()
75 def _start_command(self):
77 args.append("ccnpingserver")
78 args.append(self.get("prefix"))
79 if self.get("d") == True:
82 args.append("-x %d" % self.get("x"))
84 command = " ".join(args)
89 def _dependencies(self):
95 # Evaluate if ccnx binaries are already installed
97 " test -f ${BIN}/ccnping && "
98 " echo 'binaries found, nothing to do' "
100 # If not, untar and build
102 " git clone git://github.com/NDN-Routing/ccnping ${SRC}/ccnping "
105 "cd ${SRC}/ccnping && "
107 " ./configure LDFLAGS=-L${SRC}/ccnx-0.7.2/lib CFLAGS=-I${SRC}/ccnx-0.7.2/include "
108 " --prefix=${BIN}/ccnping && make "
115 # Evaluate if ccnx binaries are already installed
117 " test -f ${BIN}/ccnping && "
118 " echo 'binaries found, nothing to do' "
121 " mkdir -p ${BIN}/ccnping && "
122 " mv ${SRC}/ccnping/ccnping ${BIN}/ccnping/ && "
123 " mv ${SRC}/ccnping/ccnpingserver ${BIN}/ccnping/ "
128 def _environment(self):
129 return "%s:%s" % (self.ccnd.path, "${BIN}/ccnping")
131 def valid_connection(self, guid):