Changing reschedule_delay internals
[nepi.git] / src / nepi / resources / linux / ns3 / ccn / ns3ccnddceapplication.py
1 #
2 #    NEPI, a framework to manage network experiments
3 #    Copyright (C) 2014 INRIA
4 #
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.
9 #
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.
14 #
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/>.
17 #
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19
20 from nepi.execution.attribute import Attribute, Flags, Types
21 from nepi.execution.resource import clsinit_copy, ResourceState
22 from nepi.resources.linux.ns3.ccn.ns3ccndceapplication import LinuxNS3CCNDceApplication
23
24 import os
25
26 @clsinit_copy
27 class LinuxNS3DceCCND(LinuxNS3CCNDceApplication):
28     _rtype = "ns3::LinuxDceCCND"
29
30     @classmethod
31     def _register_attributes(cls):
32         debug = Attribute("debug", "Sets the CCND_DEBUG environmental variable. "
33             " Allowed values are : \n"
34             "  0 - no messages \n"
35             "  1 - basic messages (any non-zero value gets these) \n"
36             "  2 - interest messages \n"
37             "  4 - content messages \n"
38             "  8 - matching details \n"
39             "  16 - interest details \n"
40             "  32 - gory interest details \n"
41             "  64 - log occasional human-readable timestamps \n"
42             "  128 - face registration debugging \n"
43             "  -1 - max logging \n"
44             "  Or apply bitwise OR to these values to get combinations of them",
45             type = Types.Integer,
46             flags = Flags.Design)
47
48         port = Attribute("port", "Sets the CCN_LOCAL_PORT environmental variable. "
49             "Defaults to 9695 ", 
50             flags = Flags.Design)
51  
52         sockname = Attribute("sockname",
53             "Sets the CCN_LOCAL_SCOKNAME environmental variable. "
54             "Defaults to /tmp/.ccnd.sock", 
55             flags = Flags.Design)
56
57         capacity = Attribute("capacity",
58             "Sets the CCND_CAP environmental variable. "
59             "Capacity limit in terms of ContentObjects",
60             flags = Flags.Design)
61
62         mtu = Attribute("mtu", "Sets the CCND_MTU environmental variable. ",
63             flags = Flags.Design)
64   
65         data_pause = Attribute("dataPauseMicrosec",
66             "Sets the CCND_DATA_PAUSE_MICROSEC environmental variable. ",
67             flags = Flags.Design)
68
69         default_stale = Attribute("defaultTimeToStale",
70              "Sets the CCND_DEFAULT_TIME_TO_STALE environmental variable. ",
71             flags = Flags.Design)
72
73         max_stale = Attribute("maxTimeToStale",
74             "Sets the CCND_MAX_TIME_TO_STALE environmental variable. ",
75             flags = Flags.Design)
76
77         max_rte = Attribute("maxRteMicrosec",
78             "Sets the CCND_MAX_RTE_MICROSEC environmental variable. ",
79             flags = Flags.Design)
80
81         keystore = Attribute("keyStoreDirectory",
82             "Sets the CCND_KEYSTORE_DIRECTORY environmental variable. ",
83             flags = Flags.Design)
84
85         listen_on = Attribute("listenOn",
86             "Sets the CCND_LISTEN_ON environmental variable. ",
87             flags = Flags.Design)
88
89         autoreg = Attribute("autoreg",
90             "Sets the CCND_AUTOREG environmental variable. ",
91             flags = Flags.Design)
92
93         prefix = Attribute("prefix",
94             "Sets the CCND_PREFIX environmental variable. ",
95             flags = Flags.Design)
96
97         cls._register_attribute(debug)
98         cls._register_attribute(port)
99         cls._register_attribute(sockname)
100         cls._register_attribute(capacity)
101         cls._register_attribute(mtu)
102         cls._register_attribute(data_pause)
103         cls._register_attribute(default_stale)
104         cls._register_attribute(max_stale)
105         cls._register_attribute(max_rte)
106         cls._register_attribute(keystore)
107         cls._register_attribute(listen_on)
108         cls._register_attribute(autoreg)
109         cls._register_attribute(prefix)
110
111     @property
112     def version(self):
113         return self._version
114
115     def _instantiate_object(self):
116         if not self.get("depends"):
117             self.set("depends", self._dependencies)
118
119         if not self.get("sources"):
120             self.set("sources", self._sources)
121
122         sources = self.get("sources")
123         source = sources.split(" ")[0]
124         basename = os.path.basename(source)
125         self._version = ( basename.strip().replace(".tar.gz", "")
126                 .replace(".tar","")
127                 .replace(".gz","")
128                 .replace(".zip","") )
129
130         if not self.get("build"):
131             self.set("build", self._build)
132
133         if not self.get("binary"):
134             self.set("binary", "ccnd")
135
136         if not self.get("environment"):
137             self.set("environment", self._environment)
138         
139         super(LinuxNS3DceCCND, self)._instantiate_object()
140
141     @property
142     def _dependencies(self):
143         if self.simulation.node.use_rpm:
144             return ( " autoconf openssl-devel  expat-devel libpcap-devel "
145                 " ecryptfs-utils-devel libxml2-devel automake gawk " 
146                 " gcc gcc-c++ git pcre-devel make ")
147         elif self.simulation.node.use_deb:
148             return ( " autoconf libssl-dev libexpat1-dev libpcap-dev "
149                 " libecryptfs0 libxml2-utils automake gawk gcc g++ "
150                 " git-core pkg-config libpcre3-dev make ")
151         return ""
152
153     @property
154     def _sources(self):
155         #return "http://www.ccnx.org/releases/ccnx-0.8.1.tar.gz"
156         return "http://www.ccnx.org/releases/ccnx-0.8.2.tar.gz"
157
158     @property
159     def _build(self):
160         sources = self.get("sources")
161         source = sources.split(" ")[0]
162         tar = os.path.basename(source)
163
164         return (
165             # Evaluate if ccnx binaries are already installed
166             " ( "
167                 " test -f ${BIN_DCE}/ccnd && "
168                 " echo 'binaries found, nothing to do' "
169             " ) || "
170             # If not, untar and build
171             " ( "
172                 " tar zxf ${SRC}/%(tar)s  && "
173                 " cd %(version)s && "
174                 " INSTALL_BASE=${BIN_DCE}/.. ./configure && "
175                 " make MORE_LDLIBS='-pie -rdynamic' && "
176                 " make install && "
177                 " cp ${BIN_DCE}/../bin/ccn* ${BIN_DCE} && "
178                 " cd -"
179              " )") % ({ 'tar': tar,
180                         'version': self.version
181                  })
182
183     @property
184     def _environment(self):
185         envs = dict({
186             "debug": "CCND_DEBUG",
187             "port": "CCN_LOCAL_PORT",
188             "sockname" : "CCN_LOCAL_SOCKNAME",
189             "capacity" : "CCND_CAP",
190             "mtu" : "CCND_MTU",
191             "dataPauseMicrosec" : "CCND_DATA_PAUSE_MICROSEC",
192             "defaultTimeToStale" : "CCND_DEFAULT_TIME_TO_STALE",
193             "maxTimeToStale" : "CCND_MAX_TIME_TO_STALE",
194             "maxRteMicrosec" : "CCND_MAX_RTE_MICROSEC",
195             "keyStoreDirectory" : "CCND_KEYSTORE_DIRECTORY",
196             "listenOn" : "CCND_LISTEN_ON",
197             "autoreg" : "CCND_AUTOREG",
198             "prefix" : "CCND_PREFIX",
199             })
200
201         env = ";".join(map(lambda k: "%s=%s" % (envs.get(k), str(self.get(k))), 
202             [k for k in envs.keys() if self.get(k)]))
203
204         return env
205