#!d:\perli\bin\perl -w # # UDP example # # # #!/usr/bin/perl -w use strict; use Socket; use Sys::Hostname; my ( $count, $hisiaddr, $hispaddr, $histime, $host, $iaddr, $paddr, $port, $proto, $rin, $rout, $rtime, $SECS_of_70_YEARS); $SECS_of_70_YEARS = 2208988800; # $iaddr = gethostbyname(hostname()); $proto = getprotobyname('udp'); $paddr = sockaddr_in(2345,inet_aton("127.0.0.1")); socket(SOCKET, PF_INET, SOCK_DGRAM, $proto) || die "socket: $!"; bind(SOCKET, $paddr) || die "bind: $!"; $| = 1; printf "%-12s %8s %s\n", "localhost", 0, scalar localtime time; my $message = "Message"; for( $count = 0; $count < 100 ; $count++ ){ $hispaddr = sockaddr_in(2345, inet_aton("127.0.0.1") ); send(SOCKET, "$message $count \r\n", 0, $hispaddr) ; print $count." " ; } # Call Generator simulator code. my $ip; my $now; my $CallsPerSecond = 1/5; my $sum=0; my $interArrivalTime = -log( 1 - rand() ) / $CallsPerSecond; for( $count = 0; $count<1000 ; $count++ ){ $interArrivalTime = -log( 1 - rand() ) / $CallsPerSecond; $sum = $sum + $interArrivalTime; print "$sum $interArrivalTime \r\n" } my $sum = 0; my $StartedAt = time; my $running = 0; my $callType; my $destination; while( 1 ) { # generate a time interval modulated by Neg Exp distribution $interArrivalTime = -log( 1 - rand() ) / $CallsPerSecond; $sum = $sum + $interArrivalTime; $running = time - $StartedAt; # Now pick a call type $callType = int( rand()*10 ); # Now pick a destination $destination = int( rand()*10 ); #print "Call Generator: $running,$sum,$callType,$destination,$interArrivalTime \r\n"; #$ip = ; # Prepare Message # TS,Protocol,OrigID,DestID,Operation,P1,,,CRLF $message = "$sum,0,0,$destination,MAKECAll,,,END\r\n"; if ( rand() < 0.5 ) { $hispaddr = sockaddr_in(2346, inet_aton("127.0.0.1") ); } else { $hispaddr = sockaddr_in(2347, inet_aton("127.0.0.1") ); } send(SOCKET, "CLG:,$message", 0, $hispaddr) ; print "Call Generator: $running,$sum, $message"; # start timer for next inter Arrival Delay $count = select( undef, undef, undef, $interArrivalTime ) ; }