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 as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20 from nepi.execution.attribute import Attribute, Flags, Types
21 from nepi.execution.resource import ResourceManager, clsinit_copy, \
22 ResourceState, reschedule_delay
23 from nepi.resources.linux.ccn.ccnapplication import LinuxCCNApplication
24 from nepi.util.timefuncs import tnow, tdiffsec
29 class LinuxCCNPingServer(LinuxCCNApplication):
30 _rtype = "LinuxCCNPingServer"
33 def _register_attributes(cls):
34 daemon = Attribute("d",
35 "Run ccnping server as a daemon in background",
40 freshness = Attribute("x",
41 "Set FreshnessSeconds",
45 prefix = Attribute("prefix",
46 "Prefix to serve content (e.g. ccnx:/name/prefix)",
49 cls._register_attribute(daemon)
50 cls._register_attribute(freshness)
51 cls._register_attribute(prefix)
53 def __init__(self, ec, guid):
54 super(LinuxCCNPingServer, self).__init__(ec, guid)
55 self._home = "ccnping-serv-%s" % self.guid
58 if not self.get("command"):
59 self.set("command", self._start_command)
61 if not self.get("env"):
62 self.set("env", self._environment)
64 if not self.get("depends"):
65 self.set("depends", self._dependencies)
67 if not self.get("build"):
68 self.set("build", self._build)
70 if not self.get("install"):
71 self.set("install", self._install)
73 super(LinuxCCNPingServer, self).do_deploy()
76 def _start_command(self):
78 args.append("ccnpingserver")
79 args.append(self.get("prefix"))
80 if self.get("d") == True:
83 args.append("-x %d" % self.get("x"))
85 command = " ".join(args)
90 def _dependencies(self):
96 # Evaluate if ccnx binaries are already installed
98 " test -f ${BIN}/ccnping && "
99 " echo 'binaries found, nothing to do' "
101 # If not, untar and build
103 " git clone git://github.com/NDN-Routing/ccnping ${SRC}/ccnping "
106 "cd ${SRC}/ccnping && "
108 " ./configure LDFLAGS=-L${SRC}/ccnx-0.7.2/lib CFLAGS=-I${SRC}/ccnx-0.7.2/include "
109 " --prefix=${BIN}/ccnping && make "
116 # Evaluate if ccnx binaries are already installed
118 " test -f ${BIN}/ccnping && "
119 " echo 'binaries found, nothing to do' "
122 " mkdir -p ${BIN}/ccnping && "
123 " mv ${SRC}/ccnping/ccnping ${BIN}/ccnping/ && "
124 " mv ${SRC}/ccnping/ccnpingserver ${BIN}/ccnping/ "
129 def _environment(self):
130 return "%s:%s" % (self.ccnd.path, "${BIN}/ccnping")
132 def valid_connection(self, guid):