1 /*
2 * Copyright (c) 1998-2002 The Jgroup Team.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 *
17 */
18
19 package jgroup.relacs.config;
20
21 import jgroup.core.ConfigurationException;
22
23 /**
24 * The <code>TransportConfig</code> class contains the configuration
25 * parameters needed by the underlying transport protocol used in
26 * Relacs.
27 *
28 * @author Alberto Montresor
29 * @author Hein Meling
30 * @author Marcin Solarski
31 * @since Jgroup 0.1
32 */
33 final public class TransportConfig
34 implements ConfigurationObject
35 {
36
37 ////////////////////////////////////////////////////////////////////////////////////////////
38 // Tags
39 ////////////////////////////////////////////////////////////////////////////////////////////
40
41 private static final String dsPayloadAttrib = "payload";
42 private static final String dsMulticastTTLAttrib = "multicastTTL";
43 private static final String dsAlfaNAttrib = "alfaN";
44 private static final String dsAlfaDAttrib = "alfaD";
45 private static final String dsRoutingTimeoutAttrib = "routingTimeout";
46 private static final String dsCongestionTimeoutAttrib = "congestionTimeout";
47 private static final String dsStartingWindowAttrib = "startingWindow";
48 private static final String dsMaxWindowAttrib = "maxWindow";
49 private static final String dsMinWindowAttrib = "minWindow";
50 private static final String dsMaxTTLAttrib = "maxTTL";
51 private static final String dsTTLWarningAttrib = "TTLWarning";
52 private static final String dsMaxPathLengthAttrib = "maxPathLength";
53 private static final String dsPathLengthWarningAttrib = "pathLengthWarning";
54 private static final String dsLocalPingTimeoutAttrib = "localPingTimeout";
55 private static final String dsdaemonLookupRetryNoAttrib = "daemonLookupRetryNo";
56 private static final String dsdaemonLookupRetryDelayAttrib = "daemonLookupRetryDelay";
57
58
59 ////////////////////////////////////////////////////////////////////////////////////////////
60 // Constants
61 ////////////////////////////////////////////////////////////////////////////////////////////
62
63 /** Default payload */
64 private static final int PAYLOAD = 1024;
65
66 /** Default multicast TTL */
67 private static final int MULTICAST_TTL = 2;
68
69 /** Default alfan */
70 private static final int ALFAN = 7;
71
72 /** Default alfad */
73 private static final int ALFAD = 8;
74
75 /** Default routing timeout */
76 private static final int ROUTING_TIMEOUT = 1000;
77
78 /** Default routing timeout */
79 private static final int CONGESTION_TIMEOUT = 1000;
80
81 /** Default initial size of the window */
82 private static final int STARTING_WINDOW = 100;
83
84 /** Default max size of the window */
85 private static final int MAX_WINDOW = 10;
86
87 /** Default min size of the window */
88 private static final int MIN_WINDOW = 1;
89
90 /** Default max TTL (reachability information) */
91 private static final int MAX_TTL = 6;
92
93 /** Default TTL warning level (reachability information) */
94 private static final int TTL_WARNING = MAX_TTL / 2;
95
96 /** Default delta infinite (routing constants) */
97 private static final int MAX_PATH_LENGTH = 6;
98
99 /** Default delta warning level (routing constants) */
100 private static final int PATH_LENGTH_WARNING = MAX_PATH_LENGTH / 2;
101
102 /** Default local ping timeout */
103 private static final int LOCAL_PING_TIMEOUT = 2000;
104
105 /** The number of retries to find another local daemon. */
106 private static final int RETRIES = 5;
107
108 /** The default delay (in milliseconds) between retries. */
109 private static final int RETRY_DELAY = 2000;
110
111
112 ////////////////////////////////////////////////////////////////////////////////////////////
113 // Fields
114 ////////////////////////////////////////////////////////////////////////////////////////////
115
116 /** Payload length of a mss message */
117 private int payload;
118
119 /** multicast TTL */
120 private int multicastTTL;
121
122 /** Failure detector parameter */
123 private int alfan;
124
125 /** Failure detector parameter */
126 private int alfad;
127
128 /** Routing timeout */
129 private int routingTimeout;
130
131 /** Congestion timeout */
132 private int congestionTimeout;
133
134 /** Initial size of the window */
135 private int startingWindow;
136
137 /** Maximum size of the window */
138 private int maxWindow;
139
140 /** Maximum size of the window */
141 private int minWindow;
142
143 /** Maximum TTL (reachability information) */
144 private int maxTTL;
145
146 /** TTL warning level (reachability information) */
147 private int ttlWarning;
148
149 /** Delta infinite (routing constants) */
150 private int maxPathLength;
151
152 /** Delta warning level (routing constants) */
153 private int pathLengthWarning;
154
155 /** Local ping timeout */
156 private int localPingTimeout;
157
158 /** Number of retries */
159 private int retryNo;
160
161 /** Delay between the retries */
162 private int retryDelay;
163
164
165 ////////////////////////////////////////////////////////////////////////////////////////////
166 // Constructors
167 ////////////////////////////////////////////////////////////////////////////////////////////
168
169 /**
170 * Constructs a <code> TransportConfig </code> object using the
171 * default values.
172 */
173 public TransportConfig()
174 {
175 this(PAYLOAD, MULTICAST_TTL, ALFAN, ALFAD, ROUTING_TIMEOUT, CONGESTION_TIMEOUT,
176 STARTING_WINDOW, MAX_WINDOW, MIN_WINDOW, MAX_TTL, TTL_WARNING,
177 MAX_PATH_LENGTH, PATH_LENGTH_WARNING, LOCAL_PING_TIMEOUT, RETRIES, RETRY_DELAY);
178 }
179
180
181 /**
182 * Constructs a <code> TransportConfig </code> object from the given
183 * parameters.
184 */
185 public TransportConfig(int payload, int multicastTTL, int alfan, int alfad, int congestionTimeout,
186 int routingTimeout, int startingWindow, int maxWindow, int minWindow, int maxTTL,
187 int ttlWarning, int maxPathLength, int pathLengthWarning, int localPingTimeout, int retryNo, int retryDelay)
188 {
189 this.payload = payload;
190 this.multicastTTL = multicastTTL;
191 this.alfan = alfan;
192 this.alfad = alfad;
193 this.congestionTimeout = congestionTimeout;
194 this.routingTimeout = routingTimeout;
195 this.startingWindow = startingWindow;
196 this.maxWindow = maxWindow;
197 this.minWindow = minWindow;
198 this.maxTTL = maxTTL;
199 this.ttlWarning = ttlWarning;
200 this.maxPathLength = maxPathLength;
201 this.pathLengthWarning = pathLengthWarning;
202 this.localPingTimeout = localPingTimeout;
203 this.retryNo = retryNo;
204 this.retryDelay = retryDelay;
205 }
206
207
208 ////////////////////////////////////////////////////////////////////////////////////////////
209 // Methods from ConfigurationObject
210 ////////////////////////////////////////////////////////////////////////////////////////////
211
212 /**
213 * Parses the specified element.
214 */
215 public void parse(org.w3c.dom.Element elm)
216 throws ConfigurationException
217 {
218 payload = ConfigParser.getIntAttrib(elm, dsPayloadAttrib, false);
219 multicastTTL = ConfigParser.getIntAttrib(elm, dsMulticastTTLAttrib, false);
220 alfan = ConfigParser.getIntAttrib(elm, dsAlfaNAttrib, false);
221 alfad = ConfigParser.getIntAttrib(elm, dsAlfaDAttrib, false);
222 routingTimeout = ConfigParser.getIntAttrib(elm, dsRoutingTimeoutAttrib, false);
223 congestionTimeout = ConfigParser.getIntAttrib(elm, dsCongestionTimeoutAttrib, false);
224 startingWindow = ConfigParser.getIntAttrib(elm, dsStartingWindowAttrib, false);
225 maxWindow = ConfigParser.getIntAttrib(elm, dsMaxWindowAttrib, false);
226 minWindow = ConfigParser.getIntAttrib(elm, dsMinWindowAttrib, false);
227 maxTTL = ConfigParser.getIntAttrib(elm, dsMaxTTLAttrib, false);
228 ttlWarning = ConfigParser.getIntAttrib(elm, dsTTLWarningAttrib, false);
229 maxPathLength = ConfigParser.getIntAttrib(elm, dsMaxPathLengthAttrib, false);
230 pathLengthWarning = ConfigParser.getIntAttrib(elm, dsPathLengthWarningAttrib, false);
231 localPingTimeout = ConfigParser.getIntAttrib(elm, dsLocalPingTimeoutAttrib, false);
232 retryNo = ConfigParser.getIntAttrib(elm, dsdaemonLookupRetryNoAttrib, false);
233 retryDelay = ConfigParser.getIntAttrib(elm, dsdaemonLookupRetryDelayAttrib, false);
234 }
235
236
237 ////////////////////////////////////////////////////////////////////////////////////////////
238 // Getter methods
239 ////////////////////////////////////////////////////////////////////////////////////////////
240
241 /**
242 * Get the size of the payload field of application packets.
243 */
244 public int getPayload()
245 {
246 return payload;
247 }
248
249
250 /**
251 * Get the value of the multicast TTL used to send the packets over the
252 * multicast sockets. The TTL determines the administrative
253 * scope of the ip multicast used for group member communication. It can have
254 * value in range from 1 (scope of LAN) to 16 (world-wide scope). Use this
255 * param with care. The default value is set to 2 which allows for deploying
256 * group memebers in adjacent networks (connected to the same router).
257 *
258 * @since Jgroup 2.1
259 */
260 public int getMulticastTTL()
261 {
262 return multicastTTL;
263 }
264
265
266 /**
267 * Returns the <code>alfan</code> parameter, which is used for
268 * computing the average round-trip time (RTT), and it determines the
269 * weight to give to the old values. The formula used is given in
270 * {@link jgroup.relacs.mss.MssHost#updateTimeout updateTimeout}.
271 *
272 * @see jgroup.relacs.mss.MssHost#updateTimeout
273 */
274 public int getAlfan()
275 {
276 return alfan;
277 }
278
279
280 /**
281 * Returns the <code>alfan</code> parameter, which is used for
282 * computing the average round-trip time (RTT), and it determines the
283 * weight to give to the old values. The formula used is given in
284 * {@link jgroup.relacs.mss.MssHost#updateTimeout updateTimeout}.
285 *
286 * @see jgroup.relacs.mss.MssHost#updateTimeout
287 */
288 public int getAlfad()
289 {
290 return alfad;
291 }
292
293
294 /**
295 * Get the time interval between two routing messages sent by a
296 * daemon.
297 */
298 public int getRoutingTimeout()
299 {
300 return routingTimeout;
301 }
302
303
304 /**
305 * Set the time interval between two routing messages sent by a
306 * daemon.
307 */
308 public void setRoutingTimeout(int rt)
309 {
310 routingTimeout = rt;
311 }
312
313
314 /**
315 * Get the time interval between two routing messages sent by a
316 * daemon.
317 */
318 public int getCongestionTimeout()
319 {
320 return congestionTimeout;
321 }
322
323
324 /**
325 * Get the timeout value used to by members to suspect the daemon.
326 * This value is related to the ping frequency of the members.
327 * It is a factor two longer than the local ping frequency.
328 *
329 * @see #getLocalPingRate
330 */
331 public int getDaemonSuspectTimeout()
332 {
333 return localPingTimeout * 2;
334 }
335
336
337 /**
338 * Get the time interval between two ping messages sent by the
339 * daemon to its associated members.
340 */
341 public int getLocalPingRate()
342 {
343 return localPingTimeout;
344 }
345
346
347 /**
348 * Get the size of the starting window
349 */
350 public int getStartingWindow()
351 {
352 return startingWindow;
353 }
354
355
356 /**
357 * Get the maximum size of the window
358 */
359 public int getMaxWindow()
360 {
361 return maxWindow;
362 }
363
364
365 /**
366 * Get the minimum size of the window
367 */
368 public int getMinWindow()
369 {
370 return minWindow;
371 }
372
373
374 /**
375 * Returns the reachability threshold used to evaluate the
376 * reachability of hosts within a cluster for the purpose of
377 * selecting a cluster leader. Currently, the threshold is set to
378 * half the <code>maxTTL</code> value specified in the XML
379 * configuration. Note that this value should never exceed the
380 * <code>maxTTL</code> value.
381 */
382 public int getReachabilityThreshold()
383 {
384 return (maxTTL / 2) + 1;
385 }
386
387
388 /**
389 * Get the maximum TTL value acceptable before considering an
390 * endpoint as unreachable.
391 */
392 public int getMaxTTL()
393 {
394 return maxTTL;
395 }
396
397
398 /**
399 * Get the TTL warning level.
400 */
401 public int getTTLWarning()
402 {
403 return ttlWarning;
404 }
405
406
407 /**
408 * Get the max path length.
409 */
410 public int getMaxPathLength()
411 {
412 return maxPathLength;
413 }
414
415
416 /**
417 * Get the path length warning level.
418 */
419 public int getPathWarning()
420 {
421 return pathLengthWarning;
422 }
423
424 /**
425 * Get the number of retries of checking the reachability of other
426 * Jgroup Daemons.
427 *
428 * An example working value for a LAN environment with Intel Pentium II 333Mhz
429 * amounts to 6.
430 *
431 * @since Jgroup 2.1
432 */
433 public int getRetryNo()
434 {
435 return retryNo;
436 }
437
438 /**
439 * Get the delay [in ms] between the Jgroup daemon reachibility retries.
440 * This parameter allows for tuning the speed of coming to a conclusion
441 * on suspecting other Jgroup daemons to be down. The optimal value of this
442 * parameter strongly depends on the CPU power of the hosts where the
443 * Jgroup daemons (and group memebers) run as well as the network
444 * characteristics of the links between them (max return trip time).
445 * An example working value for a LAN environment with Intel Pentium II 333Mhz
446 * amounts to 300 ms.
447 *
448 * @since Jgroup 2.1
449 */
450 public int getRetryDelay()
451 {
452 return retryDelay;
453 }
454
455 ////////////////////////////////////////////////////////////////////////////////////////////
456 // Override methods in Object
457 ////////////////////////////////////////////////////////////////////////////////////////////
458
459 /**
460 * Returns a string representation of this object
461 */
462 public String toString() {
463 StringBuilder buf = new StringBuilder();
464 buf.append("[p=");
465 buf.append(payload);
466 buf.append(", mTTL=");
467 buf.append(multicastTTL);
468 buf.append(", an=");
469 buf.append(alfan);
470 buf.append(", ad=");
471 buf.append(alfad);
472 buf.append(", rt=");
473 buf.append(routingTimeout);
474 buf.append(", ct=");
475 buf.append(congestionTimeout);
476 buf.append(", sw=");
477 buf.append(startingWindow);
478 buf.append(", maxw=");
479 buf.append(maxWindow);
480 buf.append(", minw=");
481 buf.append(minWindow);
482 buf.append(", maxttl=");
483 buf.append(maxTTL);
484 buf.append(", ttlw=");
485 buf.append(ttlWarning);
486 buf.append(", maxpathl=");
487 buf.append(maxPathLength);
488 buf.append(", pathw=");
489 buf.append(pathLengthWarning);
490 buf.append(", ping=");
491 buf.append(localPingTimeout);
492 buf.append("]");
493 return buf.toString();
494 }
495
496 } // END TransportConfig