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
|
/*
* The Spread Toolkit.
*
* The contents of this file are subject to the Spread Open-Source
* License, Version 1.0 (the ``License''); you may not use
* this file except in compliance with the License. You may obtain a
* copy of the License at:
*
* http://www.spread.org/license/
*
* or in the file ``license.txt'' found in this distribution.
*
* Software distributed under the License is distributed on an AS IS basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Creators of Spread are:
* Yair Amir, Michal Miskin-Amir, Jonathan Stanton.
*
* Copyright (C) 1993-2004 Spread Concepts LLC <spread@spreadconcepts.com>
*
* All Rights Reserved.
*
* Major Contributor(s):
* ---------------
* Cristina Nita-Rotaru crisn@cs.purdue.edu - group communication security.
* Theo Schlossnagle jesus@omniti.com - Perl, skiplists, autoconf.
* Dan Schoenblum dansch@cnds.jhu.edu - Java interface.
* John Schultz jschultz@cnds.jhu.edu - contribution to process group membership.
*
*/
import spread.*;
import java.net.*;
public class Flooder
{
public Flooder(String user, int numMessages, int numBytes, String address, int port, boolean readOnly, boolean writeOnly)
{
try
{
// Start timer.
///////////////
long startTime = System.currentTimeMillis();
// Connect.
///////////
SpreadConnection connection = new SpreadConnection();
connection.connect(InetAddress.getByName(address), port, user, false, false);
String privateName = connection.getPrivateGroup().toString();
// Join.
////////
SpreadGroup group = new SpreadGroup();
if(readOnly)
{
System.out.println("Only receiving messages");
group.join(connection, "flooder");
}
else if(writeOnly)
{
System.out.println("Starting multicast of " + numMessages + " messages, " + numBytes + " bytes each (self discarding).");
}
else
{
group.join(connection, "flooder");
System.out.println("Starting multicast of " + numMessages + " messages, " + numBytes + " bytes each.");
}
// The outgoing message.
////////////////////////
SpreadMessage out = null;
if(readOnly == false)
{
out = new SpreadMessage();
out.setData(new byte[numBytes]);
out.addGroup("flooder");
}
// Send/Receive.
////////////////
for(int i = 1 ; i <= numMessages ; i++)
{
// Send.
////////
if(readOnly == false)
{
connection.multicast(out);
}
// Receive.
///////////
if((readOnly) || ((i > 50) && (writeOnly == false)))
{
SpreadMessage in;
do
{
in = connection.receive();
}
while((readOnly == false) && (privateName.equals(in.getSender().toString()) == false));
}
// Report.
//////////
if((i % 1000) == 0)
{
System.out.println("Completed " + i + " messages");
}
}
// Stop timer.
//////////////
long stopTime = System.currentTimeMillis();
long time = (stopTime - startTime);
float Mbps = numBytes;
Mbps *= numMessages;
Mbps *= 8;
if((readOnly == false) && (writeOnly == false))
Mbps *= 2;
Mbps *= 1000;
Mbps /= time;
Mbps /= (1024 * 1024);
System.out.println("Time: " + time + "ms (" + (int)Mbps + "." + (((int)(Mbps * 100)) % 100) + " Mbps)");
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
String user = new String("Flooder");
int numMessages = 10000;
int numBytes = 1000;
String address = null;
int port = 0;
boolean readOnly = false;
boolean writeOnly = false;
for(int i = 0 ; i < args.length ; i++)
{
// Check for user.
//////////////////
if((args[i].compareTo("-u") == 0) && (args.length > (i + 1)))
{
// Set user.
////////////
i++;
user = args[i];
}
// Check for numMessages.
/////////////////////////
else if((args[i].compareTo("-m") == 0) && (args.length > (i + 1)))
{
// Set numMessages.
///////////////////
i++;
numMessages = Integer.parseInt(args[i]);
}
// Check for numBytes.
//////////////////////
else if((args[i].compareTo("-b") == 0) && (args.length > (i + 1)))
{
// Set numBytes.
////////////////
i++;
numBytes = Integer.parseInt(args[i]);
}
// Check for address.
/////////////////////
else if((args[i].compareTo("-s") == 0) && (args.length > (i + 1)))
{
// Set address.
///////////////
i++;
address = args[i];
}
// Check for port.
//////////////////
else if((args[i].compareTo("-p") == 0) && (args.length > (i + 1)))
{
// Set port.
////////////
i++;
port = Integer.parseInt(args[i]);
}
// Check for readOnly.
//////////////////////
else if(args[i].compareTo("-ro") == 0)
{
// Set readOnly.
////////////////
readOnly = true;
writeOnly = false;
}
// Check for writeOnly.
///////////////////////
else if(args[i].compareTo("-wo") == 0)
{
// Set writeOnly.
/////////////////
writeOnly = true;
readOnly = false;
}
else
{
System.out.print("Usage: flooder\n" +
"\t[-u <user name>] : unique user name\n" +
"\t[-m <num messages>] : number of messages\n" +
"\t[-b <num bytes>] : number of bytes per message\n" +
"\t[-s <address>] : the name or IP for the daemon\n" +
"\t[-p <port>] : the port for the daemon\n" +
"\t[-ro] : read only (no multicast)\n" +
"\t[-wo] : write only (no receive)\n");
System.exit(0);
}
}
Flooder f = new Flooder(user, numMessages, numBytes, address, port, readOnly, writeOnly);
}
}
|