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, failtrap
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",
38 flags = Flags.ExecReadOnly)
40 freshness = Attribute("x",
41 "Set FreshnessSeconds",
43 flags = Flags.ExecReadOnly)
45 prefix = Attribute("prefix",
46 "Prefix to serve content (e.g. ccnx:/name/prefix)",
47 flags = Flags.ExecReadOnly)
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
59 if not self.get("command"):
60 self.set("command", self._start_command)
62 if not self.get("env"):
63 self.set("env", self._environment)
65 if not self.get("depends"):
66 self.set("depends", self._dependencies)
68 if not self.get("build"):
69 self.set("build", self._build)
71 if not self.get("install"):
72 self.set("install", self._install)
74 super(LinuxCCNPingServer, self).deploy()
77 def _start_command(self):
79 args.append("ccnpingserver")
80 args.append(self.get("prefix"))
81 if self.get("d") == True:
84 args.append("-x %d" % self.get("x"))
86 command = " ".join(args)
91 def _dependencies(self):
97 # Evaluate if ccnx binaries are already installed
99 " test -f ${BIN}/ccnping && "
100 " echo 'binaries found, nothing to do' "
102 # If not, untar and build
104 " git clone git://github.com/NDN-Routing/ccnping ${SRC}/ccnping "
107 "cd ${SRC}/ccnping && "
109 " ./configure LDFLAGS=-L${SRC}/ccnx-0.7.2/lib CFLAGS=-I${SRC}/ccnx-0.7.2/include "
110 " --prefix=${BIN}/ccnping && make "
117 # Evaluate if ccnx binaries are already installed
119 " test -f ${BIN}/ccnping && "
120 " echo 'binaries found, nothing to do' "
123 " mkdir -p ${BIN}/ccnping && "
124 " mv ${SRC}/ccnping/ccnping ${BIN}/ccnping/ && "
125 " mv ${SRC}/ccnping/ccnpingserver ${BIN}/ccnping/ "
130 def _environment(self):
131 return "%s:%s" % (self.ccnd.path, "${BIN}/ccnping")
133 def valid_connection(self, guid):