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