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 as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
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.
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/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20 from nepi.execution.attribute import Attribute, Flags, Types
21 from nepi.execution.resource import clsinit_copy, ResourceState
22 from nepi.resources.linux.ns3.ns3dceapplication import LinuxNS3DceApplication
25 class LinuxDcePing(LinuxNS3DceApplication):
26 _rtype = "linux::ns3::dce::Ping"
29 def _register_attributes(cls):
30 count = Attribute("count",
31 "Sets ping -c option. Determines the number of ECHO_REQUEST "
32 "packates to send before stopping.",
36 mark = Attribute("mark",
37 "Sets ping -m option. Uses 'mark' to tag outgoing packets. ",
40 interval = Attribute("interval",
41 "Sets ping -i option. Leaves interval seconds between "
42 "successive ECHO_REUQEST packets. ",
45 address = Attribute("address",
46 "Sets ping -I option. Sets ECHO_REQUEST packets souce address "
47 "to the specified interface address ",
50 preload = Attribute("preload",
51 "Sets ping -l option. Sends preload amount of packets "
52 "without waiting for a reply ",
55 numeric = Attribute("numeric",
56 "Sets ping -n option. Disables resolution of host addresses into "
62 pattern = Attribute("pattern",
63 "Sets ping -p option. Species a up to 16 ''pad'' bytes to fill "
67 printtmp = Attribute("printTimestamp",
68 "Sets ping -D option. Prints timestamp befor each line as: "
69 "unix time + microseconds as in gettimeofday ",
74 tos = Attribute("tos",
75 "Sets ping -Q option. Sets Quality of Service related bits in ICMP "
76 "datagrams. tos can be either a decimal or hexadecime number ",
79 quiet = Attribute("quiet",
80 "Sets ping -q option. Disables ping standard output ",
85 rec_route = Attribute("recordRoute",
86 "Sets ping -R option. Includes the RECORD_ROUTE option in the "
87 "ECHO REQUEST packet and displays route buffer on the Disables "
88 "ping standard output.",
93 route_bypass = Attribute("routeBypass",
94 "Sets ping -r option. Bypasses normal routing tables and sends "
95 "ECHO REQUEST packets directly yo a host on an attached interface. ",
100 packetsize = Attribute("packetSize",
101 "Sets ping -s option. Specifies the number of data bytes to be "
102 "sent. Defaults to 56. ",
103 flags = Flags.Design)
105 sendbuff = Attribute("sendBuff",
106 "Sets ping -S option. Specifies the number of packets to buffer. "
108 flags = Flags.Design)
110 ttl = Attribute("ttl",
111 "Sets ping -t option. Specifies the IP Time to Live for the "
113 flags = Flags.Design)
115 timestamp = Attribute("timestamp",
116 "Sets ping -T option. Sets special IP timestamp options. ",
117 flags = Flags.Design)
119 hint = Attribute("hint",
120 "Sets ping -M option. Selects Path MTU Discovery strategy. ",
121 flags = Flags.Design)
123 full_latency = Attribute("fullLatency",
124 "Sets ping -U option. Calculates round trip time taking into "
125 "account the full user-to-user latency instead of only the "
126 "network round trip time. ",
129 flags = Flags.Design)
131 verbose = Attribute("verbose",
132 "Sets ping -v option. Verbose output. ",
135 flags = Flags.Design)
137 flood = Attribute("flood",
138 "Sets ping -f option. Flood ping. ",
141 flags = Flags.Design)
143 deadline = Attribute("deadline",
144 "Sets ping -w option. Specify a timeout, in seconds, before ping "
145 "exits regardless of how many packets have been sent or received.",
146 flags = Flags.Design)
148 timeout = Attribute("timeout",
149 "Sets ping -W option. Time to wait for a respone in seconds .",
150 flags = Flags.Design)
152 target = Attribute("target",
153 "The host to ping .",
154 flags = Flags.Design)
156 cls._register_attribute(count)
157 cls._register_attribute(mark)
158 cls._register_attribute(interval)
159 cls._register_attribute(address)
160 cls._register_attribute(preload)
161 cls._register_attribute(numeric)
162 cls._register_attribute(pattern)
163 cls._register_attribute(printtmp)
164 cls._register_attribute(tos)
165 cls._register_attribute(quiet)
166 cls._register_attribute(rec_route)
167 cls._register_attribute(route_bypass)
168 cls._register_attribute(packetsize)
169 cls._register_attribute(sendbuff)
170 cls._register_attribute(ttl)
171 cls._register_attribute(timestamp)
172 cls._register_attribute(hint)
173 cls._register_attribute(full_latency)
174 cls._register_attribute(verbose)
175 cls._register_attribute(flood)
176 cls._register_attribute(deadline)
177 cls._register_attribute(timeout)
178 cls._register_attribute(target)
180 def _instantiate_object(self):
181 self.set("sources", self._sources)
182 self.set("build", self._build)
183 self.set("binary", "ping")
184 self.set("arguments", self._arguments)
186 super(LinuxDcePing, self)._instantiate_object()
190 return "http://www.skbuff.net/iputils/iputils-s20101006.tar.bz2"
195 " test -f ${BIN_DCE}/ping && "
196 " echo 'binaries found, nothing to do' "
198 "tar xvjf ${SRC}/iputils-s20101006.tar.bz2 && "
199 "cd iputils-s20101006/ && "
200 "sed -i 's/CFLAGS=/CFLAGS+=/g' Makefile && "
201 "make CFLAGS=-fPIC LDFLAGS='-pie -rdynamic' ping && "
202 "cp ping ${BIN_DCE} && cd - "
207 def _arguments(self):
210 if self.get("count"):
211 args.append("-c %s" % self.get("count"))
213 args.append("-m %s" % self.get("mark"))
214 if self.get("interval"):
215 args.append("-i %s" % self.get("interval"))
216 if self.get("address"):
217 args.append("-I %s" % self.get("address"))
218 if self.get("preload"):
219 args.append("-l %s" % self.get("preload"))
220 if self.get("numeric") == True:
222 if self.get("pattern"):
223 args.append("-p %s" % self.get("pattern"))
225 args.append("-Q %s" % self.get("tos"))
226 if self.get("quiet"):
227 args.append("-q %s" % self.get("quiet"))
228 if self.get("recordRoute") == True:
230 if self.get("routeBypass") == True:
232 if self.get("packetSize"):
233 args.append("-s %s" % self.get("packetSize"))
234 if self.get("sendBuff"):
235 args.append("-S %s" % self.get("sendBuff"))
237 args.append("-t %s" % self.get("ttl"))
238 if self.get("timestamp"):
239 args.append("-T %s" % self.get("timestamp"))
241 args.append("-M %s" % self.get("hint"))
242 if self.get("fullLatency") == True:
244 if self.get("verbose") == True:
246 if self.get("flood") == True:
248 if self.get("deadline"):
249 args.append("-w %s" % self.get("deadline"))
250 if self.get("timeout"):
251 args.append("-W %s" % self.get("timeout"))
252 args.append(self.get("target"))
254 return ";".join(args)