README moves to markdown
[nepi.git] / src / nepi / resources / linux / ns3 / ns3pingdceapplication.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.ns3dceapplication import LinuxNS3DceApplication
22
23 @clsinit_copy
24 class LinuxDcePing(LinuxNS3DceApplication):
25     _rtype = "linux::ns3::dce::Ping"
26
27     @classmethod
28     def _register_attributes(cls):
29         count = Attribute("count",
30             "Sets ping -c option. Determines the number of ECHO_REQUEST "
31             "packates to send before stopping.",
32             type = Types.Integer,
33             flags = Flags.Design)
34
35         mark = Attribute("mark",
36             "Sets ping -m option. Uses 'mark' to tag outgoing packets. ",
37             flags = Flags.Design)
38
39         interval = Attribute("interval",
40             "Sets ping -i option. Leaves interval seconds between "
41             "successive ECHO_REUQEST packets. ",
42             flags = Flags.Design)
43
44         address = Attribute("address",
45             "Sets ping -I option. Sets ECHO_REQUEST packets souce address "
46             "to the specified interface address ",
47             flags = Flags.Design)
48
49         preload = Attribute("preload",
50             "Sets ping -l option. Sends preload amount of packets "
51             "without waiting for a reply ",
52             flags = Flags.Design)
53
54         numeric = Attribute("numeric",
55             "Sets ping -n option. Disables resolution of host addresses into "
56             "symbolic names. ",
57             type = Types.Bool,
58             default = False,
59             flags = Flags.Design)
60
61         pattern = Attribute("pattern",
62             "Sets ping -p option. Species a up to 16 ''pad'' bytes to fill "
63             "out sent packets. ",
64             flags = Flags.Design)
65
66         printtmp = Attribute("printTimestamp",
67             "Sets ping -D option. Prints timestamp befor each line as: "
68             "unix time + microseconds as in gettimeofday ",
69             type = Types.Bool,
70             default = False,
71             flags = Flags.Design)
72
73         tos = Attribute("tos",
74             "Sets ping -Q option. Sets Quality of Service related bits in ICMP "
75             "datagrams. tos can be either a decimal or hexadecime number ",
76             flags = Flags.Design)
77
78         quiet = Attribute("quiet",
79             "Sets ping -q option. Disables ping standard output ",
80             type = Types.Bool,
81             default = False,
82             flags = Flags.Design)
83
84         rec_route = Attribute("recordRoute",
85             "Sets ping -R option. Includes the RECORD_ROUTE option in the "
86             "ECHO REQUEST packet and displays route buffer on the Disables "
87             "ping standard output.",
88             type = Types.Bool,
89             default = False,
90             flags = Flags.Design)
91
92         route_bypass = Attribute("routeBypass",
93             "Sets ping -r option. Bypasses normal routing tables and sends "
94             "ECHO REQUEST packets directly yo a host on an attached interface. ",
95             type = Types.Bool,
96             default = False,
97             flags = Flags.Design)
98
99         packetsize = Attribute("packetSize",
100             "Sets ping -s option. Specifies the number of data bytes to be "
101             "sent. Defaults to 56. ",
102             flags = Flags.Design)
103
104         sendbuff = Attribute("sendBuff",
105             "Sets ping -S option. Specifies the number of packets to buffer. "
106             "Defaults to one. ",
107             flags = Flags.Design)
108
109         ttl = Attribute("ttl",
110             "Sets ping -t option. Specifies the IP Time to Live for the "
111             "packets. ",
112             flags = Flags.Design)
113
114         timestamp = Attribute("timestamp",
115             "Sets ping -T option. Sets special IP timestamp options. ",
116             flags = Flags.Design)
117
118         hint = Attribute("hint",
119             "Sets ping -M option. Selects Path MTU Discovery strategy. ",
120             flags = Flags.Design)
121
122         full_latency = Attribute("fullLatency",
123             "Sets ping -U option. Calculates round trip time taking into "
124             "account the full user-to-user latency instead of only the "
125             "network round trip time. ",
126             type = Types.Bool,
127             default = False,
128             flags = Flags.Design)
129
130         verbose = Attribute("verbose",
131             "Sets ping -v option. Verbose output. ",
132             type = Types.Bool,
133             default = False,
134             flags = Flags.Design)
135
136         flood = Attribute("flood",
137             "Sets ping -f option. Flood ping. ",
138             type = Types.Bool,
139             default = False,
140             flags = Flags.Design)
141
142         deadline = Attribute("deadline",
143             "Sets ping -w option. Specify a timeout, in seconds, before ping "
144             "exits regardless of how many packets have been sent or received.",
145             flags = Flags.Design)
146
147         timeout = Attribute("timeout",
148             "Sets ping -W option. Time to wait for a respone in seconds .",
149             flags = Flags.Design)
150
151         target = Attribute("target",
152             "The host to ping .",
153             flags = Flags.Design)
154
155         cls._register_attribute(count)
156         cls._register_attribute(mark)
157         cls._register_attribute(interval)
158         cls._register_attribute(address)
159         cls._register_attribute(preload)
160         cls._register_attribute(numeric)
161         cls._register_attribute(pattern)
162         cls._register_attribute(printtmp)
163         cls._register_attribute(tos)
164         cls._register_attribute(quiet)
165         cls._register_attribute(rec_route)
166         cls._register_attribute(route_bypass)
167         cls._register_attribute(packetsize)
168         cls._register_attribute(sendbuff)
169         cls._register_attribute(ttl)
170         cls._register_attribute(timestamp)
171         cls._register_attribute(hint)
172         cls._register_attribute(full_latency)
173         cls._register_attribute(verbose)
174         cls._register_attribute(flood)
175         cls._register_attribute(deadline)
176         cls._register_attribute(timeout)
177         cls._register_attribute(target)
178
179     def _instantiate_object(self):
180         self.set("sources", self._sources)
181         self.set("build", self._build)
182         self.set("binary", "ping")
183         self.set("arguments", self._arguments)
184         
185         super(LinuxDcePing, self)._instantiate_object()
186
187     @property
188     def _sources(self):
189         return "http://www.skbuff.net/iputils/iputils-s20101006.tar.bz2"
190
191     @property
192     def _build(self):
193         return  (" ( "
194                 " test -f ${BIN_DCE}/ping && "
195                 " echo 'binaries found, nothing to do' "
196                 " ) || ( "
197                 "tar xvjf ${SRC}/iputils-s20101006.tar.bz2 && "
198                 "cd iputils-s20101006/ && "
199                 "sed -i 's/CFLAGS=/CFLAGS+=/g' Makefile && "
200                 "make CFLAGS=-fPIC LDFLAGS='-pie -rdynamic' ping && "
201                 "cp ping ${BIN_DCE} && cd - "
202                 " )"   
203                 )
204
205     @property
206     def _arguments(self):
207         args = []
208
209         if self.get("count"):
210             args.append("-c %s" % self.get("count"))
211         if self.get("mark"):
212             args.append("-m %s" % self.get("mark"))
213         if self.get("interval"):
214             args.append("-i %s" % self.get("interval"))
215         if self.get("address"):
216             args.append("-I %s" % self.get("address"))
217         if self.get("preload"):
218             args.append("-l %s" % self.get("preload"))
219         if self.get("numeric") == True:
220             args.append("-n")
221         if self.get("pattern"):
222             args.append("-p %s" % self.get("pattern"))
223         if self.get("tos"):
224             args.append("-Q %s" % self.get("tos"))
225         if self.get("quiet"):
226             args.append("-q %s" % self.get("quiet"))
227         if self.get("recordRoute") == True:
228             args.append("-R")
229         if self.get("routeBypass") == True:
230             args.append("-r")
231         if self.get("packetSize"):
232             args.append("-s %s" % self.get("packetSize"))
233         if self.get("sendBuff"):
234             args.append("-S %s" % self.get("sendBuff"))
235         if self.get("ttl"):
236             args.append("-t %s" % self.get("ttl"))
237         if self.get("timestamp"):
238             args.append("-T %s" % self.get("timestamp"))
239         if self.get("hint"):
240             args.append("-M %s" % self.get("hint"))
241         if self.get("fullLatency") == True:
242             args.append("-U")
243         if self.get("verbose") == True:
244             args.append("-v")
245         if self.get("flood") == True:
246             args.append("-f")
247         if self.get("deadline"):
248             args.append("-w %s" % self.get("deadline"))
249         if self.get("timeout"):
250             args.append("-W %s" % self.get("timeout"))
251         args.append(self.get("target"))
252
253         return ";".join(args) 
254