This file is indexed.

/usr/bin/polygraph-webaxe4-ips is in polygraph 4.3.2-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#!/usr/bin/perl -w

# Web Polygraph       http://www.web-polygraph.org/
# Copyright 2003-2011 The Measurement Factory
# Licensed under the Apache License, Version 2.0

require 5.003;
use strict;

if (@ARGV == 1 && $ARGV[0] eq '--help') {
	print usage();
	exit;
}

use POSIX;

&web2term();

# default workload configuration
my $CltSide = {
	max_host_load => 500, # maximum host load
	max_agent_load => 0.4,
	y_octet_offset => 0,
};

my $SrvSide = {
	max_host_load => $CltSide->{max_host_load},
	max_agent_load => $CltSide->{max_host_load},
	y_octet_offset => 128,
};

my $OptRoute = 0;

&getOpts();

die(&usage()) unless 2 <= @ARGV && @ARGV <= 3;
$SIG{__WARN__} = sub { print(STDERR &usage()); die $_[0] };

my $Quiet = @ARGV == 3;

my ($Bench, $RR, $Id) = @ARGV;


exit(&main());

sub main {

	&compute($CltSide);
	&compute($SrvSide);

	#die("$CltSide->{theHostCount} != $SrvSide->{theHostCount}") if
	#	$CltSide->{theHostCount} != $SrvSide->{theHostCount};
	#my $Pairs = $CltSide->{theHostCount};

	if (!$Quiet) {
		my $Robots = scalar @{$CltSide->{theIps}};
		my $Servers = scalar @{$SrvSide->{theIps}};

		xprintf("bench:    %6d\n",      $Bench);

		xprintf("req.rate: %6d/sec (actual: %8.2f/sec)\n",
			$RR, $Robots*$CltSide->{max_agent_load});
		xprintf("PCs:      %6d clients + %d servers (%d total)\n", 
			$CltSide->{theHostCount}, $SrvSide->{theHostCount},
			$CltSide->{theHostCount} + $SrvSide->{theHostCount});

		# xprintf("robots:   %6d (%4d/machine)\n", $Robots, $Robots/$CltSide->{theHostCount});
		# xprintf("servers:  %6d (%4d/machine)\n", $Servers, $Servers/$SrvSide->{theHostCount});

		xprintf("\n");

		printSide('clt', $CltSide);
		xprintf("\n");

		printSide('srv', $SrvSide);
		xprintf("\n");
	}

	return 0 unless defined $Id;

	if ($Id =~ /^clts$/) {
		print(&getIps($CltSide));
	}
	elsif ($Id =~ /^srvs$/) {
		print(&getIps($SrvSide));
	}
	elsif ($Id =~ /^clt(\d+)$/) {
		my $id = $1;
		die("there are only $CltSide->{theHostCount} clients, cannot have $Id client\n") if $id > $CltSide->{theHostCount};
		print(&getIps($CltSide, $id-1));
	}
	elsif ($Id =~ /^srv(\d+)$/) {
		my $id = $1;
		die("there are only $
SrvSide->{theHostCount} servers, cannot have $Id server\n") if $id > $SrvSide->{theHostCount};
		print(&getIps($SrvSide, $id-1));
	} else {
		die("$0: cannot parse `$Id'; expected something like clt1 or srv4\n");
	}

	print("\n");

	return 0;
}

sub printSide {
	my ($label, $side) = @_;

	printf("\t%s.%-20s %10s\n", $label, 'max_host_load:', $side->{max_host_load});
	printf("\t%s.%-20s %10s\n", $label, 'max_agent_load:', $side->{max_agent_load});
	printf("\t%s.%-20s %10s\n", $label, 'subnet:', $side->{theSubnet});
	printf("\t%s.%-20s %10s\n", $label, 'max_addr_per_subnet:', $side->{theMaxAddrPerSnet});
	printf("\t%s.%-20s %10s\n", $label, 'host_count:', $side->{theHostCount});
	printf("\t%s.%-20s %10s\n", $label, 'agent_per_host:', $side->{theAgentPerHost});

	for (my $h = 0; $h <= $#{$side->{thePerHostIps}}; ++$h) {
		printf("\t\t%s.%-20s %s\n", $label, 
			sprintf('%s_%02d.ips:', 'host', $h+1),
			getIps($side, $h));
	}
#	@{$side->{theIps}} = @ips;
}

sub compute {
	my $side = shift;

	my $reqRate = $RR or die();
	my $hostLoad = $side->{max_host_load} or die();
	my $agentLoad = $side->{max_agent_load} or die();

	# find min subnet that can fit maxAddrPerHost addresses
	my $maxAddrPerHost = int($hostLoad/$agentLoad);
	my $subnet = 25;
	my $maxAddrPerSnet = -1;
	for (my $i = 1; $maxAddrPerSnet < $maxAddrPerHost && $i <= 128; $i *= 2) {
		$maxAddrPerSnet = $i * 250;
		--$subnet;
	}
	die() if $maxAddrPerSnet < $maxAddrPerHost;
	die() if $subnet == 25;

	# find the number of agents (i.e. the number of a.b.x.y addresses)
	my $hostCnt = int(xceil($reqRate, $hostLoad));
	my $agentCnt = &doubleDiv($hostCnt, $reqRate, $agentLoad);
	my $agentPerHost = $agentCnt / $hostCnt;
	die() unless $agentCnt <= $maxAddrPerHost * $hostCnt;

	# distribute agentCnt agents among subnets (upto maxAddrPerSnet each)
	my @ips = ();
	$side->{thePerHostIps} = [];
	for (my $s = 0; @ips < $agentCnt; ++$s) {
		# one subnet, one host
		my $host = {};
		my $x = $s * int($maxAddrPerSnet/250);
		my $y = 1;
		for (my $a = 0; $a < $agentPerHost; ++$a) {

			die("request rate is too high; ".
				"ran out of IP addresses while accomodating $agentCnt agents") if $x >= 128;
			my $actualX = $x + $side->{y_octet_offset};
			push @ips, "10.$Bench.$actualX.$y";

			$side->{theFirstX} = $actualX unless defined $side->{theFirstX};
			$side->{theFirstY} = $y unless defined $side->{theFirstY};
			$host->{theFirstX} = $actualX unless defined $host->{theFirstX};
			$host->{theFirstY} = $y unless defined $host->{theFirstY};

			$side->{theLastX} = $host->{theLastX} = $actualX;
			$side->{theLastY} = $host->{theLastY} = $y;

			if (++$y == 251) {
				++$x;
				$y = 1;
			}
		}
		push @{$side->{thePerHostIps}}, $host;
	}
	die() unless $agentCnt == @ips;

	@{$side->{theIps}} = @ips;
	$side->{theSubnet} = $subnet;
	$side->{theMaxAddrPerSnet} = $maxAddrPerSnet;
	$side->{theMaxAddrPerHost} = $maxAddrPerHost;
	$side->{theHostCount} = $hostCnt;
	$side->{theAgentPerHost} = $agentCnt / $hostCnt;

	return undef();
}

sub getIps {
	my ($side, $id) = @_;

	return &formatIps($side, $side->{thePerHostIps}->[$id]) if defined $id;
	return &formatIps($side, $side);
}

sub formatIps {
	my ($side, $descr) = @_;

	if ($OptRoute || $descr->{theFirstX} == $descr->{theLastX} || $descr->{theLastY} == 250) {
		return &ipRange2Str($side, $descr->{theFirstX}, $descr->{theLastX}, 
			$descr->{theLastY});
	} else {
		return sprintf('%s;%s',
			&ipRange2Str($side, $descr->{theFirstX}, $descr->{theLastX}-1, 250),
			&ipRange2Str($side, $descr->{theLastX}, $descr->{theLastX}, $descr->{theLastY}));
	}
}

sub ipRange2Str {
	my ($side, $minX, $maxX, $maxY) = @_ or die();
	my $minY = 1;

	if ($OptRoute) {
		my $subnet = $side->{theSubnet};
		return "10.$Bench.$minX.0/$subnet";
	} else {
		my $x = ($minX == $maxX) ? $minX : "$minX-$maxX";
		my $y = ($minY == $maxY) ? $minY : "$minY-$maxY";
		return "10.$Bench.$x.$y"; # /$subnet";
	}
}

sub doubleDiv {
	my ($factor, $n, $d) = @_;
	my $apx = xceil($n, $d);
	return int($factor * xceil($apx, $factor));
}

# try "ceil(700/0.7)" to see why xceil is needed
sub xceil {
	my ($large, $small) = @_;
	my $c = ceil($large/$small);
	return ($c-1)*$small >= $large ? $c-1 : $c;
}

sub xprintf {
	my $fmt = shift;
	#printf(STDERR "$0: $fmt", @_);
	printf("\t$fmt", @_);
}

sub web2term {
	my $query = $ENV{QUERY_STRING};
	return unless defined $query;
	open(STDERR, ">&STDOUT");
	print("Content-type: text/plain\r\n\r\n");
	@ARGV = ($query =~ /=([^&]+)/g);
	printf("./pmix2-ips.pl %s\n\n", join(' ', @ARGV));
}

sub getOpts {

	my @newOpts = ();

	my $sides = {
		'client' => $CltSide,
		'server' => $SrvSide,
	};

	for (my $i = 0; $i <= $#ARGV; ++$i) {
		my $opt = $ARGV[$i];

		if ($opt !~ /^--/) {
			push @newOpts, $opt;
			next;
		}

		if ($opt eq '--route') {
			$OptRoute = 1;
			next;
		}

		if ($opt =~ /^--(client|server)_side\.(max_(?:host|agent)_load)/) {
			die(&usage()) unless 
				defined $sides->{$1} && defined $sides->{$1}->{$2};
			$sides->{$1}->{$2} = $ARGV[++$i] or die(&usage());
			next;
		}

		die("$0: unknown option: $opt\n");
	}

	@ARGV = @newOpts;
}

sub usage {
	return "Usage: $0 [--option] ... <bench_id> <requests/sec> [cltId|srvId]\n\n".
		"Options:\n".
		"  --route                                 show addresses in route-friendly format\n".
		"  --client_side.max_host_load <req/sec>   load per polyclt process\n".
		"  --server_side.max_host_load <req/sec>   load per polysrv process\n".
		"  --client_side.max_agent_load <req/sec>  load per robot agent\n".
		"  --server_side.max_agent_load <req/sec>  load per server agent\n";
}

sub suffix {
	my ($ord) = @_;
	return 'st' if $ord == 1;
	return 'nd' if $ord == 2;
	return 'rd' if $ord == 3;
	return 'th';
}