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.trace import Trace, TraceAttr
22 from nepi.execution.resource import ResourceManager, clsinit_copy, ResourceState, \
24 from nepi.resources.linux.application import LinuxApplication
25 from nepi.resources.linux.ccn.ccnr import LinuxCCNR
26 from nepi.resources.linux.node import OSType
28 from nepi.util.sshfuncs import ProcStatus
29 from nepi.util.timefuncs import strfnow, strfdiff
32 reschedule_delay = "0.5s"
35 class LinuxCCNR(LinuxApplication):
36 _rtype = "LinuxCCNContent"
39 def _register_attributes(cls):
40 content_name = Attribute("contentName",
41 "The name of the content to publish (e.g. ccn:/VIDEO) ",
42 flags = Flags.ExecReadOnly)
43 content = Attribute("content",
44 "The content to publish. It can be a path to a file or plain text ",
45 flags = Flags.ExecReadOnly)
48 cls._register_attribute(content_name)
49 cls._register_attribute(content)
52 def _register_traces(cls):
53 log = Trace("log", "CCND log output")
55 cls._register_trace(log)
57 def __init__(self, ec, guid):
58 super(LinuxCCNContent, self).__init__(ec, guid)
62 ccnr = self.get_connected(LinuxCCNR.rtype())
63 if ccnr: return ccnr[0]
67 if not self.get("command"):
68 self.set("command", self._default_command)
70 if not self.get("env"):
71 self.set("env", self._default_environment)
73 # Wait until associated ccnd is provisioned
76 if not ccnr or ccnr.state < ResourceState.STARTED:
77 self.ec.schedule(reschedule_delay, self.deploy)
79 # Add a start after condition so CCNR will not start
81 self.ec.register_condition(self.guid, ResourceAction.START,
82 ccnd.guid, ResourceState.STARTED)
84 # Invoke the actual deployment
85 super(LinuxCCNContent, self).deploy()
88 def _default_command(self):
89 return "ccnseqwriter -r %s " % self.get("contentName")
92 def _default_environment(self):
93 env = "PATH=$PATH:${EXP_HOME}/ccnx/bin "
96 def valid_connection(self, guid):