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.trace import Trace, TraceAttr
21 from nepi.execution.resource import clsinit_copy, ResourceState, \
23 from nepi.resources.linux.application import LinuxApplication
24 from nepi.resources.linux.ccn.ccnd import LinuxCCND
25 from nepi.util.timefuncs import tnow
30 class LinuxCCNR(LinuxApplication):
31 _rtype = "linux::CCNR"
34 def _register_attributes(cls):
35 max_fanout = Attribute("maxFanout",
36 "Sets the CCNR_BTREE_MAX_FANOUT environmental variable. ",
39 max_leaf_entries = Attribute("maxLeafEntries",
40 "Sets the CCNR_BTREE_MAX_LEAF_ENTRIES environmental variable. ",
43 max_node_bytes = Attribute("maxNodeBytes",
44 "Sets the CCNR_BTREE_MAX_NODE_BYTES environmental variable. ",
47 max_node_pool = Attribute("maxNodePool",
48 "Sets the CCNR_BTREE_MAX_NODE_POOL environmental variable. ",
51 content_cache = Attribute("contentCache",
52 "Sets the CCNR_CONTENT_CACHE environmental variable. ",
55 debug = Attribute("debug",
56 "Sets the CCNR_DEBUG environmental variable. "
57 "Logging level for ccnr. Defaults to WARNING.",
58 type = Types.Enumerate,
65 "FINE, FINER, FINEST"],
68 directory = Attribute("directory",
69 "Sets the CCNR_DIRECTORY environmental variable. ",
72 global_prefix = Attribute("globalPrefix",
73 "Sets the CCNR_GLOBAL_PREFIX environmental variable. ",
76 listen_on = Attribute("listenOn",
77 "Sets the CCNR_LISTEN_ON environmental variable. ",
80 min_send_bufsize = Attribute("minSendBufsize",
81 "Sets the CCNR_MIN_SEND_BUFSIZE environmental variable. ",
84 proto = Attribute("proto",
85 "Sets the CCNR_PROTO environmental variable. ",
88 status_port = Attribute("statusPort",
89 "Sets the CCNR_STATUS_PORT environmental variable. ",
92 start_write_scope_limit = Attribute("startWriteScopeLimit",
93 "Sets the CCNR_START_WRITE_SCOPE_LIMIT environmental variable. ",
96 ccns_debug = Attribute("ccnsDebug",
97 "Sets the CCNS_DEBUG environmental variable. ",
100 ccns_enable = Attribute("ccnsEnable",
101 "Sets the CCNS_ENABLE environmental variable. ",
102 flags = Flags.Design)
104 ccns_faux_error = Attribute("ccnsFauxError",
105 "Sets the CCNS_FAUX_ERROR environmental variable. ",
106 flags = Flags.Design)
108 ccns_heartbeat_micros = Attribute("ccnsHeartBeatMicros",
109 "Sets the CCNS_HEART_BEAT_MICROS environmental variable. ",
110 flags = Flags.Design)
112 ccns_max_compares_busy = Attribute("ccnsMaxComparesBusy",
113 "Sets the CCNS_MAX_COMPARES_BUSY environmental variable. ",
114 flags = Flags.Design)
116 ccns_max_fetch_busy = Attribute("ccnsMaxFetchBusy",
117 "Sets the CCNS_MAX_FETCH_BUSY environmental variable. ",
118 flags = Flags.Design)
120 ccns_node_fetch_lifetime = Attribute("ccnsNodeFetchLifetime",
121 "Sets the CCNS_NODE_FETCH_LIFETIME environmental variable. ",
122 flags = Flags.Design)
124 ccns_note_err = Attribute("ccnsNoteErr",
125 "Sets the CCNS_NOTE_ERR environmental variable. ",
126 flags = Flags.Design)
128 ccns_repo_store = Attribute("ccnsRepoStore",
129 "Sets the CCNS_REPO_STORE environmental variable. ",
130 flags = Flags.Design)
132 ccns_root_advise_fresh = Attribute("ccnsRootAdviseFresh",
133 "Sets the CCNS_ROOT_ADVISE_FRESH environmental variable. ",
134 flags = Flags.Design)
136 ccns_root_advise_lifetime = Attribute("ccnsRootAdviseLifetime",
137 "Sets the CCNS_ROOT_ADVISE_LIFETIME environmental variable. ",
138 flags = Flags.Design)
140 ccns_stable_enabled = Attribute("ccnsStableEnabled",
141 "Sets the CCNS_STABLE_ENABLED environmental variable. ",
142 flags = Flags.Design)
144 ccns_sync_scope = Attribute("ccnsSyncScope",
145 "Sets the CCNS_SYNC_SCOPE environmental variable. ",
146 flags = Flags.Design)
148 repo_file = Attribute("repoFile1",
149 "The Repository uses $CCNR_DIRECTORY/repoFile1 for "
150 "persistent storage of CCN Content Objects",
151 flags = Flags.Design)
153 cls._register_attribute(max_fanout)
154 cls._register_attribute(max_leaf_entries)
155 cls._register_attribute(max_node_bytes)
156 cls._register_attribute(max_node_pool)
157 cls._register_attribute(content_cache)
158 cls._register_attribute(debug)
159 cls._register_attribute(directory)
160 cls._register_attribute(global_prefix)
161 cls._register_attribute(listen_on)
162 cls._register_attribute(min_send_bufsize)
163 cls._register_attribute(proto)
164 cls._register_attribute(status_port)
165 cls._register_attribute(start_write_scope_limit)
166 cls._register_attribute(ccns_debug)
167 cls._register_attribute(ccns_enable)
168 cls._register_attribute(ccns_faux_error)
169 cls._register_attribute(ccns_heartbeat_micros)
170 cls._register_attribute(ccns_max_compares_busy)
171 cls._register_attribute(ccns_max_fetch_busy)
172 cls._register_attribute(ccns_node_fetch_lifetime)
173 cls._register_attribute(ccns_note_err)
174 cls._register_attribute(ccns_repo_store)
175 cls._register_attribute(ccns_root_advise_fresh)
176 cls._register_attribute(ccns_root_advise_lifetime)
177 cls._register_attribute(ccns_stable_enabled)
178 cls._register_attribute(ccns_sync_scope)
179 cls._register_attribute(repo_file)
182 def _register_traces(cls):
183 log = Trace("log", "CCND log output")
185 cls._register_trace(log)
187 def __init__(self, ec, guid):
188 super(LinuxCCNR, self).__init__(ec, guid)
189 self._home = "ccnr-%s" % self.guid
193 ccnd = self.get_connected(LinuxCCND.get_rtype())
194 if ccnd: return ccnd[0]
199 if self.ccnd: return self.ccnd.node
203 if not self.ccnd or self.ccnd.state < ResourceState.READY:
204 self.debug("---- RESCHEDULING DEPLOY ---- CCND state %s " % self.ccnd.state )
206 # ccnr needs to wait until ccnd is deployed and running
207 self.ec.schedule(self.reschedule_delay, self.deploy)
209 if not self.get("command"):
210 self.set("command", self._start_command)
212 if not self.get("env"):
213 self.set("env", self._environment)
215 command = self.get("command")
217 self.info("Deploying command '%s' " % command)
224 def upload_start_command(self):
225 command = self.get("command")
226 env = self.get("env")
228 if self.get("repoFile1"):
230 local_file = self.get("repoFile1")
231 remote_file = "${RUN_HOME}/repoFile1"
232 remote_file = self.replace_paths(remote_file)
233 self.node.upload(local_file,
237 # We want to make sure the repository is running
238 # before the experiment starts.
239 # Run the command as a bash script in background,
240 # in the host ( but wait until the command has
241 # finished to continue )
242 env = self.replace_paths(env)
243 command = self.replace_paths(command)
245 shfile = os.path.join(self.app_home, "start.sh")
246 self.node.run_and_wait(command, self.run_home,
252 if self.state == ResourceState.READY:
253 command = self.get("command")
254 self.info("Starting command '%s'" % command)
258 msg = " Failed to execute command '%s'" % command
259 self.error(msg, out, err)
260 raise RuntimeError(msg)
263 def _start_command(self):
267 def _environment(self):
269 "maxFanout": "CCNR_BTREE_MAX_FANOUT",
270 "maxLeafEntries": "CCNR_BTREE_MAX_LEAF_ENTRIES",
271 "maxNodeBytes": "CCNR_BTREE_MAX_NODE_BYTES",
272 "maxNodePool": "CCNR_BTREE_MAX_NODE_POOL",
273 "contentCache": "CCNR_CONTENT_CACHE",
274 "debug": "CCNR_DEBUG",
275 "directory": "CCNR_DIRECTORY",
276 "globalPrefix": "CCNR_GLOBAL_PREFIX",
277 "listenOn": "CCNR_LISTEN_ON",
278 "minSendBufsize": "CCNR_MIN_SEND_BUFSIZE",
279 "proto": "CCNR_PROTO",
280 "statusPort": "CCNR_STATUS_PORT",
281 "startWriteScopeLimit": "CCNR_START_WRITE_SCOPE_LIMIT",
282 "ccnsDebug": "CCNS_DEBUG",
283 "ccnsEnable": "CCNS_ENABLE",
284 "ccnsFauxError": "CCNS_FAUX_ERROR",
285 "ccnsHeartBeatMicros": "CCNS_HEART_BEAT_MICROS",
286 "ccnsMaxComparesBusy": "CCNS_MAX_COMPARES_BUSY",
287 "ccnsMaxFetchBusy": "CCNS_MAX_FETCH_BUSY",
288 "ccnsNodeFetchLifetime": "CCNS_NODE_FETCH_LIFETIME",
289 "ccnsNoteErr": "CCNS_NOTE_ERR",
290 "ccnsRepoStore": "CCNS_REPO_STORE",
291 "ccnsRootAdviseFresh": "CCNS_ROOT_ADVISE_FRESH",
292 "ccnsRootAdviseLifetime": "CCNS_ROOT_ADVISE_LIFETIME",
293 "ccnsStableEnabled": "CCNS_STABLE_ENABLED",
294 "ccnsSyncScope": "CCNS_SYNC_SCOPE",
298 env += " ".join(["%s=%s" % (envs.get(k), self.get(k)) \
299 if self.get(k) else "" for k in list(envs.keys())])
303 def valid_connection(self, guid):