/* * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
import java.io.*; import java.security.*;
class Traffic
{ private InputStream in; private OutputStream out;
// // By default, traffic streams are predictable and what comes // in is compared with what it's expected to be. // staticprivatebyte fixedSeed [] = { 1, 2, 3, 4};
// optionally provide PRNG for "truly" random data. publicvoid setPRNG (SecureRandom prng)
{ this.prng = prng;
compareRandom = false;
}
// // Basic half-duplex testing, as used for RPC-style systems like // HTTP, RMI, CORBA, ONC, etc. // // parameter 'n' is "0" for some fixed data tests, else is the // number of passes of random data to send. //
if (n == 0)
initiateConst (); elseif (n < 0)
System.out.println ("** ERROR: initiate forever ??"); else for ( ; n > 0; n -= 1) {
initiateRandom ();
}
}
publicvoid respond (int n) throws IOException
{ if (n == 0)
respondConst (); elseif (n < 0) // n < 0 == respond forever while (true)
respondRandom (); else while (n-- > 0)
respondRandom ();
}
// // Test passing of fixed size (and content) data. // // For SSL, one test goal is to ensure that all the basic // block cipher padding sizes get banged on. SSLv3 ciphers // are all the same block size, but there are larger sizes // coming along. (Big blocks in hardware can be fast!!) //
privatevoid initiateConst () throws IOException
{ for (int i = 1; i <= MAX_BLOCKSIZE; i++) {
writeConstData (i);
readConstData (i);
}
}
privatevoid respondConst () throws IOException
{ for (int i = 1; i <= MAX_BLOCKSIZE; i++) {
readConstData (i);
writeConstData (i);
}
}
// // Test passing of random size (and content) data. // // For SSL, one test goal is to ensure that all the basic // record sizes get banged on. Traffic will normally // be bimodal (small packets, and big ones) and we give // a half-hearted effort at emulating that -- no real // statistics to back up this particular distribution. //
privatestaticfinalint MAX_RECORDSIZE = 16384 * 2;
privateint nextRecordSize ()
{ double d = prng.nextGaussian (); int n;
// assume 1/3 traffic is "big", less variance if ((prng.nextInt () % 3) == 0) {
n = (int) (d * 2048);
n += 15 * 1024;
// ... and the rest is smaller, much variance
} else {
n = (int) (d * 4096);
n += 1024;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.