ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-win32-users
perl-win32-users
Snort Simulator
by Kamal Ahmed other posts by this author
Sep 30 2004 3:46AM messages near this date
view in the new Beta List Site
RE: Perl OO | RE: Snort Simulator
This is a multi-part message in MIME format.

------=_NextPart_000_0000_01C4A67E.86950620
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

Hi List,

I have the following perl script that generates CheckPoint Alerts, and I
want to transform it so it will generate ALL Types of Snort Alerts. Can
someone guide me in the right direction ? I am a beginner in perl, and you
are the experts.

Thanks in advance,

-Kamal.

#!/usr/bin/perl -w

my $TMPDIR = "/tmp";

use Socket;

my $nextArg = shift;
my ($host, $port, $targetRate);
if ($nextArg eq "-socket") {
    $host = shift;
    $port = shift;
    $targetRate = shift;
} else {
    $targetRate = $nextArg;
}

## Error injection: rates are in # / 100000
my $errRateBase = 100000;
my $ipErrorRate = 200;
my $actionErrRate = 100;
my $portErrRate = 100;
my $dateErrRate = 200;

$targetRate = 50 if ! defined $targetRate;
my $count = shift;
$count = 0 if ! defined $count;

my $rate = $targetRate;

my $recNum = intRand(675) * 10000;
my $rateCheck = 0;
my $maxRatio = 1.9;  ## Do not have more than $maxRatio * $rate in any
bucket
my $maxPerSec = int($rate * $maxRatio);

my $SPREAD = 20;
my $BUCKETS = $SPREAD + 5;

my @str1 = ('udp', 'tcp', 'icmp');
my @months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
'Sept', 'Oct', 'Nov', 'Dec');

my @columns = (
               'LogFileID',
               'LogRecNum',
               'time',
               'action',
               'orig',
               'i/f_dir',
               'i/f_name',
               'proto',
               'src',
               'dst',
               'service',
               's_port',
               'len',
               'rule',
               'has_accounting',
);

my $index1 = int(rand() * 1000000);
my $starttime = time;

sub event {
    my $ref = shift;
    my %data = %$ref;
    my $res;
    foreach my $key (@columns) {
        my $val = $data{$key};
        $val = "" if (! defined $val);
        $res .= " " if defined ($res);
        $res .= "$key=\"$val\"";
    }
    return $res;
}

sub intRand {
    my $range = shift;
    return int(rand() * $range);
}

sub needError {
    my $errRate = shift;
    return intRand($errRateBase) < $errRate;
}

sub badString {
    return "bad'Str" if (intRand(20) < 3);
    return "bad|S{tr" if (intRand(20) < 3);
    return "ba}|S{tr" if (intRand(20) < 3);
    return "ba}|S{tr" if (intRand(20) < 3);
    return "ba}(S{tr" if (intRand(20) < 3);
    return "ba`S{tr" if (intRand(20) < 3);
    return "bacS{tr" . chr(3) if (intRand(20) < 3);
    return "bacS{tr" . chr(203) if (intRand(20) < 3);
    return chr(203) . "str" . chr(203) if (intRand(20) < 3);
    return "a|b|'|c|d'::d{d}dd[f]s[]";
}

sub getIp {
    my $num = shift;
    my @a;
    for (my $i=0; $i<4; $i++) {
        $a[$i] = $num % 100;
        $a[$i] = "0" . $a[$i] if (int($a[$i]) < 10);
        $num = int($num / 100);
    }
    if (needError($ipErrorRate)) {
 return "$a[3].$a[2]..$a[0]" if (intRand(10) < 5);
 return "$a[3]:$a[2]:$a[1]:$a[0]" if (intRand(10) < 5);
 return "$a[3]'$a[2]|$a[1]''$a[0]" if (intRand(10) < 5);
 return "This is a test";
    } else {
 return "$a[3].$a[2].$a[1].$a[0]";
    }
}

sub sendToStdout {
    my $msg = shift;
    printf "%s\n", $msg;
}

sub initSocket {
    printf "Init socket $host -- $port\n";
    my $hostname = shift;
    my $lport = shift;
    my ($a1, $a2, $prototype) = getprotobyname ("tcp");
    if (0) {
        my ($b1, $b2, $b3, $b4, $rawserver) = gethostbyname ($hostname);
        my $serveraddr = pack ("Sna4x8", 2, $lport, $rawserver);
        socket (SSOCKET, 2, 1, $prototype) || die ("No socket ($prototype)
$!");
        printf "Binding\n";
        bind (SSOCKET, $serveraddr) || die ("Can't bind");
        printf "Listening\n";
        listen (SSOCKET, 1) || die ("Can't listen");
        printf "Accepting\n";
        (my $clientaddr = accept (SOCKET, SSOCKET)) || die ("Can't accept:
$!");
        printf "Selecting\n";
        select (SOCKET);
        $| = 1;
    } else {
        my $proto = getprotobyname('tcp');

        socket(Server, PF_INET, SOCK_STREAM, $proto)        || die "socket:
$!";
        setsockopt(Server, SOL_SOCKET, SO_REUSEADDR,
                                        pack("l", 1))   || die "setsockopt:
$!";
        bind(Server, sockaddr_in($lport, INADDR_ANY))        || die "bind:
$!";
        printf "Listening\n";
        listen(Server,SOMAXCONN)                            || die "listen:
$!";
        printf "Accepting\n";
        my $paddr = accept(SOCKET,Server);
        my($port,$iaddr) = sockaddr_in($paddr);
        my $name = gethostbyaddr($iaddr,AF_INET);

        printf "%s\n", "connection from $name [" .
                inet_ntoa($iaddr) . "] at port $lport";

        select(SOCKET);
        $| = 1;
    }
}

sub sendToSocket {
    my $msg = shift;
    print SOCKET ("$msg\n");
    ## printf STDOUT "%s\n", $msg;
}

sub sendEvent {
    my $msg = shift;
    if (defined $host) {
 sendToSocket($msg);
    } else {
 sendToStdout($msg);
    }
}

sub getDateStr {
    my $year = 1997 + intRand(5);
    my $mon =  intRand(12);
    my $day =  intRand(28) + 1;

    my $date = "";
    $date .= " " if (int($day) < 10);
    $date .= $day;
    $date .= $months[$mon] . $year;
    if (needError($dateErrRate)) {
 return  "Sunday Jan 15, 14:01" if (intRand(20) < 5);
 return  intRand(10) . $months[$mon] . $year;
    }
    return $date;
}

sub genOne {
    my $index = shift;

    my %data;
    $data{'name'} = "test";

    my $num = int(rand() * 100);
    my $date = getDateStr();

    $data{'LogFileID'} = '1044611703';
    $data{'LogRecNum'} = $recNum++;
    $data{'time'} = "$date";
    $data{'action'} = (intRand(12) < 11) ? 'accept' : 'drop';
my @action = qw/
    accept    drop    allow       authcrypt
    authorize ctl     deauthorize decrypt
    encrypt   keyinst reject
  /;

  $data{action} = $action[intRand(scalar @action)];

    if (needError($actionErrRate)) {
 if (intRand(20) < 3) {
     $data{'action'} = 'deny';
 } elsif (intRand(20) < 5) {
     $data{'action'} = ' accept ';
 } elsif (intRand(20) < 5) {
     $data{'action'} = 'a c c e p t';
 } elsif (intRand(20) < 5) {
     $data{'action'} = 'acc\'eptdeny';
 } else {
     $data{'action'} = badString();
 }
    }
    $data{'orig'} = 'bedm-edn-650-pri';
    $data{'i/f_dir'} = (intRand(6) < 4) ? 'inbound' : 'outbound';
    $data{'i/f_name'} = "eth-s" . intRand(3) . 'p' . intRand(3) . 'c' .
intRand(4);
    $data{'proto'} = intRand(3) < 2 ? 'udp' : 'tcp';
    $data{'src'} = getIp($index);
    $data{'dst'} = "172.16.0.65";
    $data{'service'} = 21;
    #$data{'service'} = intRand(2) + 10;
    $data{'s_port'} = intRand(2);
    if (needError($portErrRate)) {
 if (intRand(20) < 5) {
     $data{'s_port'} += 1000000;
 } else {
     $data{'s_port'} = badString();
 }
    }
    $data{'len'} = intRand(44);
    $data{'rule'} = intRand(20);
    $data{'has_accounting'} = 0;

    my $event = event(\%data);
    return $event;
}

my $logFile = "$TMPDIR/perl_$$.log";
open (LOG, ">  $logFile") or die ("cannot open logfile $logFile");
select(LOG);
$| = 1;
select(STDOUT);
$| = 1;

initSocket($host, $port) if (defined $host);

for (my $i=0; $i<$count or $count == 0; $i++) {
    my $time = time();
    my $timeIdx = $time % $BUCKETS;
    $totals[$timeIdx]++;
    $totals[($time+1) % $BUCKETS] = 0;
    $totals[($time+2) % $BUCKETS] = 0;
    my $spreadSecTotal = 0;
    my @spreads = ();
    my $num = 0;
    for (my $j=0; $j<$SPREAD; $j++) {
        my $idx = ($time - $j) % $BUCKETS;
        if (defined $totals[$idx]) {
     $spreadSecTotal += $totals[$idx];
     $spreads[$j] = $totals[$idx];
     $num++;
        } else {
     $spreads[$j] = 0;
 }
    }
    my $lastOne   = $spreads[0];
    my $lastTwo   = $spreads[1] + $lastOne;

    my $needsToSleep = 0;
    $needsToSleep = 1 if ($spreadSecTotal > = $num * $rate);  ## There are
enough
    $needsToSleep = 1 if ($lastOne   > = $maxPerSec);  ## Not too spikey
    $needsToSleep = 1 if ($lastTwo   > = ($maxPerSec + $rate));

    if ($needsToSleep) {
 my $sleepTime = 1 + (intRand(20) >  18 ? 1 : 0);  ## Occasionally skip a
second
 sleep $sleepTime;
 if ($rateCheck) {
     for (my $i=0; $i<$SPREAD; $i++) {
  my $idx = ($time - $i) % $BUCKETS;
  if (defined $totals[$idx]) {
      printf("%d - ", $totals[$idx]);
  }
     }
     printf("%.2f/sec\n", $spreadSecTotal / $num);
 }
    }
    my $event = genOne($i);
    if ($i % int($rate * 60) == 0) {
        printf LOG "$i @ $time -- $event\n";
    }
    if ($timeIdx == 0 and $totals[$timeIdx] == 1) {  ## Report the rates
every once in a while
 printf LOG "$time: ";
 for (my $i=0; $i<$SPREAD; $i++) {
     my $idx = ($time - $i) % $BUCKETS;
     if (defined $totals[$idx]) {
  printf LOG ("%d - ", $totals[$idx]);
     }
 }
 printf LOG ("%.2f/sec\n", $spreadSecTotal / $num);
    }
    sendEvent($event) if (!$rateCheck);
}


------=_NextPart_000_0000_01C4A67E.86950620
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML> <HEAD>
<META content=3D"text/html; charset=3Dus-ascii" =
http-equiv=3DContent-Type> 
<META content=3D"MSHTML 5.00.3502.5390" name=3DGENERATOR> 
<STYLE> @font-face {
	font-family: Tahoma;
}
P.MsoNormal {
	FONT-FAMILY: "Times New Roman"; FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt
}
LI.MsoNormal {
	FONT-FAMILY: "Times New Roman"; FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt
}
DIV.MsoNormal {
	FONT-FAMILY: "Times New Roman"; FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt
}
A:link {
	COLOR: blue; TEXT-DECORATION: underline
}
SPAN.MsoHyperlink {
	COLOR: blue; TEXT-DECORATION: underline
}
A:visited {
	COLOR: purple; TEXT-DECORATION: underline
}
SPAN.MsoHyperlinkFollowed {
	COLOR: purple; TEXT-DECORATION: underline
}
SPAN.emailstyle17 {
	COLOR: windowtext; FONT-FAMILY: Arial
}
SPAN.EmailStyle18 {
	COLOR: navy; FONT-FAMILY: Arial
}
DIV.Section1 {
	page: Section1
}
</STYLE> 
</HEAD> 
<BODY lang=3DEN-US link=3Dblue vLink=3Dpurple> 
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> Hi=20
List,</SPAN> </FONT></DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D168264303-30092004> </SPAN></FONT>&nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> I have=20
the following perl script that generates CheckPoint Alerts, and I want =
to=20
transform it so it will generate ALL Types of Snort Alerts. Can someone =
guide me=20
in the right direction ? I am a beginner in perl, and you are the=20
experts.</SPAN> </FONT></DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D168264303-30092004> </SPAN></FONT>&nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> Thanks=20
in advance,</SPAN> </FONT></DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D168264303-30092004> </SPAN></FONT>&nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D168264303-30092004> -Kamal.</SPAN></FONT></DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D168264303-30092004> </SPAN></FONT>&nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D168264303-30092004> #!/usr/bin/perl -w</SPAN></FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> my=20
$TMPDIR =3D "/tmp";</SPAN> </FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> use=20
Socket;</SPAN> </FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> my=20
$nextArg =3D shift;<BR> my ($host, $port, $targetRate);<BR>if ($nextArg =
eq=20
"-socket") {<BR> &nbsp;&nbsp;&nbsp; $host =3D =
shift;<BR> &nbsp;&nbsp;&nbsp; $port =3D=20
shift;<BR> &nbsp;&nbsp;&nbsp; $targetRate =3D shift;<BR>} else=20
{<BR> &nbsp;&nbsp;&nbsp; $targetRate =3D =
$nextArg;<BR> }</SPAN></FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> ##=20
Error injection: rates are in # / 100000<BR> my $errRateBase =3D =
100000;<BR> my=20
$ipErrorRate =3D 200;<BR> my $actionErrRate =3D 100;<BR>my $portErrRate =
=3D 100;<BR> my=20
$dateErrRate =3D 200;</SPAN> </FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D168264303-30092004> $targetRate =3D 50 if ! defined =
$targetRate;<BR> my $count=20
=3D shift;<BR> $count =3D 0 if ! defined $count;</SPAN></FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> my=20
$rate =3D $targetRate;</SPAN> </FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> my=20
$recNum =3D intRand(675) * 10000;<BR> my $rateCheck =3D 0;<BR>my =
$maxRatio =3D=20
1.9;&nbsp; ## Do not have more than $maxRatio * $rate in any =
bucket<BR> my=20
$maxPerSec =3D int($rate * $maxRatio);</SPAN> </FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> my=20
$SPREAD =3D 20;<BR> my $BUCKETS =3D $SPREAD + 5;</SPAN></FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> my=20
@str1 =3D ('udp', 'tcp', 'icmp');<BR> my @months =3D ('Jan', 'Feb', =
'Mar', 'Apr',=20
'May', 'Jun', 'Jul', 'Aug',<BR> 'Sept', 'Oct', 'Nov', =
'Dec');</SPAN> </FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> my=20
@columns =3D=20
(<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;=20
'LogFileID',<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;=20
'LogRecNum',<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;=20
'time',<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;=20
'action',<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;=20
'orig',<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;=20
'i/f_dir',<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;=20
'i/f_name',<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;=20
'proto',<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;=20
'src',<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;=20
'dst',<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;=20
'service',<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;=20
's_port',<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;=20
'len',<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;=20
'rule',<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;=20
'has_accounting',<BR> );</SPAN></FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> my=20
$index1 =3D int(rand() * 1000000);<BR> my $starttime =3D =
time;</SPAN> </FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> sub=20
event {<BR> &nbsp;&nbsp;&nbsp; my $ref =3D shift;<BR>&nbsp;&nbsp;&nbsp; =
my %data =3D=20
%$ref;<BR> &nbsp;&nbsp;&nbsp; my $res;<BR>&nbsp;&nbsp;&nbsp; foreach my =
$key=20
(@columns) {<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $val =3D=20
$data{$key};<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $val =3D "" =
if (!=20
defined $val);<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $res .=3D " =
" if=20
defined ($res);<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $res .=3D=20
"$key=3D\"$val\"";<BR> &nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; return=20
$res;<BR> }</SPAN></FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> sub=20
intRand {<BR> &nbsp;&nbsp;&nbsp; my $range =3D =
shift;<BR> &nbsp;&nbsp;&nbsp; return=20
int(rand() * $range);<BR> }</SPAN></FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> sub=20
needError {<BR> &nbsp;&nbsp;&nbsp; my $errRate =3D =
shift;<BR> &nbsp;&nbsp;&nbsp;=20
return intRand($errRateBase) &lt; $errRate;<BR> }</SPAN></FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> sub=20
badString {<BR> &nbsp;&nbsp;&nbsp; return "bad'Str" if (intRand(20) &lt;=20
3);<BR> &nbsp;&nbsp;&nbsp; return "bad|S{tr" if (intRand(20) &lt;=20
3);<BR> &nbsp;&nbsp;&nbsp; return "ba}|S{tr" if (intRand(20) &lt;=20
3);<BR> &nbsp;&nbsp;&nbsp; return "ba}|S{tr" if (intRand(20) &lt;=20
3);<BR> &nbsp;&nbsp;&nbsp; return "ba}(S{tr" if (intRand(20) &lt;=20
3);<BR> &nbsp;&nbsp;&nbsp; return "ba`S{tr" if (intRand(20) &lt;=20
3);<BR> &nbsp;&nbsp;&nbsp; return "bacS{tr" . chr(3) if (intRand(20) &lt; =

3);<BR> &nbsp;&nbsp;&nbsp; return "bacS{tr" . chr(203) if (intRand(20) =
&lt;=20
3);<BR> &nbsp;&nbsp;&nbsp; return chr(203) . "str" . chr(203) if =
(intRand(20)=20
&lt; 3);<BR> &nbsp;&nbsp;&nbsp; return=20
"a|b|'|c|d'::d{d}dd[f]s[]";<BR> }</SPAN></FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> sub=20
getIp {<BR> &nbsp;&nbsp;&nbsp; my $num =3D shift;<BR>&nbsp;&nbsp;&nbsp; =
my=20
@a;<BR> &nbsp;&nbsp;&nbsp; for (my $i=3D0; $i&lt;4; $i++)=20
{<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $a[$i] =3D $num %=20
100;<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $a[$i] =3D "0" . =
$a[$i] if=20
(int($a[$i]) &lt; 10);<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
$num =3D=20
int($num / 100);<BR> &nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; if=20
(needError($ipErrorRate)) {<BR> &nbsp;return "$a[3].$a[2]..$a[0]" if =
(intRand(10)=20
&lt; 5);<BR> &nbsp;return "$a[3]:$a[2]:$a[1]:$a[0]" if (intRand(10) &lt;=20
5);<BR> &nbsp;return "$a[3]'$a[2]|$a[1]''$a[0]" if (intRand(10) &lt;=20
5);<BR> &nbsp;return "This is a test";<BR>&nbsp;&nbsp;&nbsp; } else=20
{<BR> &nbsp;return "$a[3].$a[2].$a[1].$a[0]";<BR>&nbsp;&nbsp;&nbsp;=20
}<BR> }</SPAN></FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> sub=20
sendToStdout {<BR> &nbsp;&nbsp;&nbsp; my $msg =3D =
shift;<BR> &nbsp;&nbsp;&nbsp;=20
printf "%s\n", $msg;<BR> }</SPAN></FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> sub=20
initSocket {<BR> &nbsp;&nbsp;&nbsp; printf "Init socket $host --=20
$port\n";<BR> &nbsp;&nbsp;&nbsp; my $hostname =3D =
shift;<BR> &nbsp;&nbsp;&nbsp; my=20
$lport =3D shift;<BR> &nbsp;&nbsp;&nbsp; my ($a1, $a2, $prototype) =3D =
getprotobyname=20
("tcp"); <BR> &nbsp;&nbsp;&nbsp; if (0)=20
{<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my ($b1, $b2, $b3, $b4,=20
$rawserver) =3D gethostbyname ($hostname);=20
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $serveraddr =3D pack =
("Sna4x8",=20
2, $lport, $rawserver); <BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
socket=20
(SSOCKET, 2, 1, $prototype) || die ("No socket ($prototype) $!");=20
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf=20
"Binding\n";<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bind =
(SSOCKET,=20
$serveraddr) || die ("Can't bind");=20
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf=20
"Listening\n";<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; listen =
(SSOCKET, 1)=20
|| die ("Can't listen"); <BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
printf=20
"Accepting\n";<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (my =
$clientaddr =3D=20
accept (SOCKET, SSOCKET)) || die ("Can't accept: $!");=20
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf=20
"Selecting\n";<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select =
(SOCKET);=20
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $| =3D 1; =
<BR> &nbsp;&nbsp;&nbsp; }=20
else {<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $proto =3D=20
getprotobyname('tcp');</SPAN> </FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D168264303-30092004> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
socket(Server, PF_INET, SOCK_STREAM,=20
$proto)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; || die "socket:=20
$!";<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setsockopt(Server,=20
SOL_SOCKET,=20
SO_REUSEADDR,<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
pack("l", 1))&nbsp;&nbsp; || die "setsockopt:=20
$!";<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bind(Server,=20
sockaddr_in($lport, =
INADDR_ANY))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ||=20
die "bind: $!";<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf=20
"Listening\n";<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
listen(Server,SOMAXCONN)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
|| die "listen: $!";<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
printf=20
"Accepting\n";<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $paddr =
=3D=20
accept(SOCKET,Server);<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
my($port,$iaddr) =3D=20
sockaddr_in($paddr);<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my =
$name =3D=20
gethostbyaddr($iaddr,AF_INET);</SPAN> </FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D168264303-30092004> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
printf=20
"%s\n", "connection from $name [" .=20
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;=20
inet_ntoa($iaddr) . "] at port $lport";</SPAN> </FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D168264303-30092004> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
select(SOCKET);<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $| =3D=20
1;<BR> &nbsp;&nbsp;&nbsp; }<BR>}</SPAN></FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> sub=20
sendToSocket {<BR> &nbsp;&nbsp;&nbsp; my $msg =3D =
shift;<BR> &nbsp;&nbsp;&nbsp;=20
print SOCKET ("$msg\n");<BR> &nbsp;&nbsp;&nbsp; ## printf STDOUT "%s\n",=20
$msg;<BR> }</SPAN></FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> sub=20
sendEvent {<BR> &nbsp;&nbsp;&nbsp; my $msg =3D =
shift;<BR> &nbsp;&nbsp;&nbsp; if=20
(defined $host) {<BR> &nbsp;sendToSocket($msg);<BR>&nbsp;&nbsp;&nbsp; } =
else=20
{<BR> &nbsp;sendToStdout($msg);<BR>&nbsp;&nbsp;&nbsp; =
}<BR> }</SPAN></FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> sub=20
getDateStr {<BR> &nbsp;&nbsp;&nbsp; my $year =3D 1997 +=20
intRand(5);<BR> &nbsp;&nbsp;&nbsp; my $mon =3D&nbsp;=20
intRand(12);<BR> &nbsp;&nbsp;&nbsp; my $day =3D&nbsp; intRand(28) +=20
1;</SPAN> </FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D168264303-30092004> &nbsp;&nbsp;&nbsp; my $date =3D =
"";<BR> &nbsp;&nbsp;&nbsp;=20
$date .=3D " " if (int($day) &lt; 10);<BR> &nbsp;&nbsp;&nbsp; $date .=3D=20
$day;<BR> &nbsp;&nbsp;&nbsp; $date .=3D $months[$mon] .=20
$year;<BR> &nbsp;&nbsp;&nbsp; if (needError($dateErrRate))=20
{<BR> &nbsp;return&nbsp; "Sunday Jan 15, 14:01" if (intRand(20) &lt;=20
5);<BR> &nbsp;return&nbsp; intRand(10) . $months[$mon] .=20
$year;<BR> &nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; return=20
$date;<BR> }</SPAN></FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> sub=20
genOne {<BR> &nbsp;&nbsp;&nbsp; my $index =3D shift;</SPAN></FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D168264303-30092004> &nbsp;&nbsp;&nbsp; my =
%data;<BR> &nbsp;&nbsp;&nbsp;=20
$data{'name'} =3D "test";</SPAN> </FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D168264303-30092004> &nbsp;&nbsp;&nbsp; my $num =3D int(rand() *=20
100);<BR> &nbsp;&nbsp;&nbsp; my $date =3D =
getDateStr();</SPAN> </FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D168264303-30092004> &nbsp;&nbsp;&nbsp; $data{'LogFileID'} =3D=20
'1044611703';<BR> &nbsp;&nbsp;&nbsp; $data{'LogRecNum'} =3D=20
$recNum++;<BR> &nbsp;&nbsp;&nbsp; $data{'time'} =3D =
"$date";<BR> &nbsp;&nbsp;&nbsp;=20
$data{'action'} =3D (intRand(12) &lt; 11) ? 'accept' : 'drop';<BR> my =
@action =3D=20
qw/<BR> &nbsp;&nbsp;&nbsp; accept&nbsp;&nbsp;&nbsp; =
drop&nbsp;&nbsp;&nbsp;=20
allow&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; authcrypt =
<BR> &nbsp;&nbsp;&nbsp;=20
authorize ctl&nbsp;&nbsp;&nbsp;&nbsp; deauthorize decrypt =
<BR> &nbsp;&nbsp;&nbsp;=20
encrypt&nbsp;&nbsp; keyinst reject<BR> &nbsp; /;</SPAN></FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> &nbsp;=20
$data{action} =3D $action[intRand(scalar @action)];</SPAN> </FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D168264303-30092004> &nbsp;&nbsp;&nbsp; if =
(needError($actionErrRate))=20
{<BR> &nbsp;if (intRand(20) &lt; 3) {<BR>&nbsp;&nbsp;&nbsp;&nbsp; =
$data{'action'}=20
=3D 'deny';<BR> &nbsp;} elsif (intRand(20) &lt; 5) =
{<BR> &nbsp;&nbsp;&nbsp;&nbsp;=20
$data{'action'} =3D ' accept ';<BR> &nbsp;} elsif (intRand(20) &lt; 5)=20
{<BR> &nbsp;&nbsp;&nbsp;&nbsp; $data{'action'} =3D 'a c c e p =
t';<BR> &nbsp;} elsif=20
(intRand(20) &lt; 5) {<BR> &nbsp;&nbsp;&nbsp;&nbsp; $data{'action'} =3D=20
'acc\'eptdeny';<BR> &nbsp;} else {<BR>&nbsp;&nbsp;&nbsp;&nbsp; =
$data{'action'} =3D=20
badString();<BR> &nbsp;}<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;=20
$data{'orig'} =3D 'bedm-edn-650-pri';<BR> &nbsp;&nbsp;&nbsp; =
$data{'i/f_dir'} =3D=20
(intRand(6) &lt; 4) ? 'inbound' : 'outbound';<BR> &nbsp;&nbsp;&nbsp;=20
$data{'i/f_name'} =3D "eth-s" . intRand(3) . 'p' . intRand(3) . 'c' .=20
intRand(4);<BR> &nbsp;&nbsp;&nbsp; $data{'proto'} =3D intRand(3) &lt; 2 ? =
'udp' :=20
'tcp';<BR> &nbsp;&nbsp;&nbsp; $data{'src'} =3D =
getIp($index);<BR> &nbsp;&nbsp;&nbsp;=20
$data{'dst'} =3D "172.16.0.65";<BR> &nbsp;&nbsp;&nbsp; $data{'service'} =
=3D=20
21;<BR> &nbsp;&nbsp;&nbsp; #$data{'service'} =3D intRand(2) +=20
10;<BR> &nbsp;&nbsp;&nbsp; $data{'s_port'} =3D =
intRand(2);<BR> &nbsp;&nbsp;&nbsp; if=20
(needError($portErrRate)) {<BR> &nbsp;if (intRand(20) &lt; 5)=20
{<BR> &nbsp;&nbsp;&nbsp;&nbsp; $data{'s_port'} +=3D 1000000;<BR>&nbsp;} =
else=20
{<BR> &nbsp;&nbsp;&nbsp;&nbsp; $data{'s_port'} =3D=20
badString();<BR> &nbsp;}<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;=20
$data{'len'} =3D intRand(44);<BR> &nbsp;&nbsp;&nbsp; $data{'rule'} =3D=20
intRand(20);<BR> &nbsp;&nbsp;&nbsp; $data{'has_accounting'} =3D=20
0;</SPAN> </FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D168264303-30092004> &nbsp;&nbsp;&nbsp; my $event =3D=20
event(\%data);<BR> &nbsp;&nbsp;&nbsp; return =
$event;<BR> }</SPAN></FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> my=20
$logFile =3D "$TMPDIR/perl_$$.log";<BR> open (LOG, "&gt; $logFile") or =
die ("cannot=20
open logfile $logFile");<BR> select(LOG);<BR>$| =3D =
1;<BR> select(STDOUT);<BR>$| =3D=20
1;</SPAN> </FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D168264303-30092004> initSocket($host, $port) if (defined=20
$host);</SPAN> </FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D168264303-30092004> for=20
(my $i=3D0; $i&lt;$count or $count =3D=3D 0; $i++) =
{<BR> &nbsp;&nbsp;&nbsp; my $time =3D=20
time();<BR> &nbsp;&nbsp;&nbsp; my $timeIdx =3D $time %=20
$BUCKETS;<BR> &nbsp;&nbsp;&nbsp; =
$totals[$timeIdx]++;<BR> &nbsp;&nbsp;&nbsp;=20
$totals[($time+1) % $BUCKETS] =3D 0;<BR> &nbsp;&nbsp;&nbsp; =
$totals[($time+2) %=20
$BUCKETS] =3D 0;<BR> &nbsp;&nbsp;&nbsp; my $spreadSecTotal =3D=20
0;<BR> &nbsp;&nbsp;&nbsp; my @spreads =3D ();<BR>&nbsp;&nbsp;&nbsp; my =
$num =3D=20
0;<BR> &nbsp;&nbsp;&nbsp; for (my $j=3D0; $j&lt;$SPREAD; $j++)=20
{<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $idx =3D ($time - $j) =
%=20
$BUCKETS;<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (defined=20
$totals[$idx]) {<BR> &nbsp;&nbsp;&nbsp;&nbsp; $spreadSecTotal +=3D=20
$totals[$idx];<BR> &nbsp;&nbsp;&nbsp;&nbsp; $spreads[$j] =3D=20
$totals[$idx];<BR> &nbsp;&nbsp;&nbsp;&nbsp;=20
$num++;<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else=20
{<BR> &nbsp;&nbsp;&nbsp;&nbsp; $spreads[$j] =3D =
0;<BR> &nbsp;}<BR>&nbsp;&nbsp;&nbsp;=20
}<BR> &nbsp;&nbsp;&nbsp; my $lastOne&nbsp;&nbsp; =3D=20
$spreads[0];<BR> &nbsp;&nbsp;&nbsp; my $lastTwo&nbsp;&nbsp; =3D =
$spreads[1] +=20
$lastOne;</SPAN> </FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D168264303-30092004> &nbsp;&nbsp;&nbsp; my $needsToSleep =3D=20
0;<BR> &nbsp;&nbsp;&nbsp; $needsToSleep =3D 1 if ($spreadSecTotal &gt;=3D =
$num *=20
$rate);&nbsp; ## There are enough<BR> &nbsp;&nbsp;&nbsp; $needsToSleep =
=3D 1 if=20
($lastOne&nbsp;&nbsp; &gt;=3D $maxPerSec);&nbsp; ## Not too=20
spikey<BR> &nbsp;&nbsp;&nbsp; $needsToSleep =3D 1 if =
($lastTwo&nbsp;&nbsp; &gt;=3D=20
($maxPerSec + $rate));</SPAN> </FONT></DIV>
<DIV> &nbsp;</DIV>
<DIV> <FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D168264303-30092004> &nbsp;&nbsp;&nbsp; if ($needsToSleep) =
{<BR> &nbsp;my=20
$sleepTime =3D 1 + (intRand(20) &gt; 18 ? 1 : 0);&nbsp; ## Occasionally =
skip a=20
second<BR> &nbsp;sleep $sleepTime;<BR>&nbsp;if ($rateCheck)=20
{<BR> &nbsp;&nbsp;&nbsp;&nbsp; for (my $i=3D0; $i&lt;$SPREAD; $i++)=20
{<BR> &nbsp;&nbsp;my $idx =3D ($time - $i) % $BUCKETS;<BR>&nbsp;&nbsp;if =
(defined=20
$totals[$idx]) {<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("%d - ",=20
$totals[$idx]);<BR> &nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
}<BR> &nbsp;&nbsp;&nbsp;&nbsp; printf("%.2f/sec\n", $spreadSecTotal /=20
$num);<BR> &nbsp;}<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; my =
$event =3D=20
genOne($i);<BR> &nbsp;&nbsp;&nbsp; if ($i % int($rate * 60) =3D=3D 0)=20
{<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf LOG "$i @ $time =
--=20
$event\n";<BR> &nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; if ($timeIdx =
=3D=3D 0 and=20
$totals[$timeIdx] =3D=3D 1) {&nbsp; ## Report the rates every once in a=20
while<BR> &nbsp;printf LOG "$time: ";<BR>&nbsp;for (my $i=3D0; =
$i&lt;$SPREAD; $i++)=20
{<BR> &nbsp;&nbsp;&nbsp;&nbsp; my $idx =3D ($time - $i) %=20
$BUCKETS;<BR> &nbsp;&nbsp;&nbsp;&nbsp; if (defined $totals[$idx])=20
{<BR> &nbsp;&nbsp;printf LOG ("%d - ",=20
$totals[$idx]);<BR> &nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;}<BR>&nbsp;printf =
LOG=20
("%.2f/sec\n", $spreadSecTotal / $num);<BR> &nbsp;&nbsp;&nbsp;=20
}<BR> &nbsp;&nbsp;&nbsp; sendEvent($event) if=20
(!$rateCheck);<BR> }<BR></SPAN></FONT></DIV></BODY></HTML>

------=_NextPart_000_0000_01C4A67E.86950620--
Attachments:
unknown1

Thread:
Bharucha, Nikhil
Kamal Ahmed
Charles K. Clarkson

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved