2 # NEPI, a framework to manage network experiments
3 # Copyright (C) 2014 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.resource import clsinit_copy, ResourceState
21 from nepi.resources.linux.ns3.ns3dceapplication import LinuxNS3DceApplication
24 class LinuxDcePing(LinuxNS3DceApplication):
25 _rtype = "linux::ns3::dce::Ping"
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.",
35 mark = Attribute("mark",
36 "Sets ping -m option. Uses 'mark' to tag outgoing packets. ",
39 interval = Attribute("interval",
40 "Sets ping -i option. Leaves interval seconds between "
41 "successive ECHO_REUQEST packets. ",
44 address = Attribute("address",
45 "Sets ping -I option. Sets ECHO_REQUEST packets souce address "
46 "to the specified interface address ",
49 preload = Attribute("preload",
50 "Sets ping -l option. Sends preload amount of packets "
51 "without waiting for a reply ",
54 numeric = Attribute("numeric",
55 "Sets ping -n option. Disables resolution of host addresses into "
61 pattern = Attribute("pattern",
62 "Sets ping -p option. Species a up to 16 ''pad'' bytes to fill "
66 printtmp = Attribute("printTimestamp",
67 "Sets ping -D option. Prints timestamp befor each line as: "
68 "unix time + microseconds as in gettimeofday ",
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 ",
78 quiet = Attribute("quiet",
79 "Sets ping -q option. Disables ping standard output ",
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.",
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. ",
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)
104 sendbuff = Attribute("sendBuff",
105 "Sets ping -S option. Specifies the number of packets to buffer. "
107 flags = Flags.Design)
109 ttl = Attribute("ttl",
110 "Sets ping -t option. Specifies the IP Time to Live for the "
112 flags = Flags.Design)
114 timestamp = Attribute("timestamp",
115 "Sets ping -T option. Sets special IP timestamp options. ",
116 flags = Flags.Design)
118 hint = Attribute("hint",
119 "Sets ping -M option. Selects Path MTU Discovery strategy. ",
120 flags = Flags.Design)
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. ",
128 flags = Flags.Design)
130 verbose = Attribute("verbose",
131 "Sets ping -v option. Verbose output. ",
134 flags = Flags.Design)
136 flood = Attribute("flood",
137 "Sets ping -f option. Flood ping. ",
140 flags = Flags.Design)
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)
147 timeout = Attribute("timeout",
148 "Sets ping -W option. Time to wait for a respone in seconds .",
149 flags = Flags.Design)
151 target = Attribute("target",
152 "The host to ping .",
153 flags = Flags.Design)
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)
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)
185 super(LinuxDcePing, self)._instantiate_object()
189 return "http://www.skbuff.net/iputils/iputils-s20101006.tar.bz2"
194 " test -f ${BIN_DCE}/ping && "
195 " echo 'binaries found, nothing to do' "
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 - "
206 def _arguments(self):
209 if self.get("count"):
210 args.append("-c %s" % self.get("count"))
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:
221 if self.get("pattern"):
222 args.append("-p %s" % self.get("pattern"))
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:
229 if self.get("routeBypass") == True:
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"))
236 args.append("-t %s" % self.get("ttl"))
237 if self.get("timestamp"):
238 args.append("-T %s" % self.get("timestamp"))
240 args.append("-M %s" % self.get("hint"))
241 if self.get("fullLatency") == True:
243 if self.get("verbose") == True:
245 if self.get("flood") == True:
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"))
253 return ";".join(args)