ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-FastPing/FPing.pm
(Generate patch)

Comparing AnyEvent-FastPing/FPing.pm (file contents):
Revision 1.1 by root, Fri May 4 07:02:19 2007 UTC vs.
Revision 1.2 by root, Fri May 4 07:36:45 2007 UTC

59 59
60 undef $THR_REQ_W unless length $THR_REQ_BUF; 60 undef $THR_REQ_W unless length $THR_REQ_BUF;
61 }); 61 });
62} 62}
63 63
64=item Net::FPing::ipv4_supported
65
66Returns true if IPv4 is supported in this module and on this system.
67
68=item Net::FPing::ipv6_supported
69
70Returns true if IPv6 is supported in this module and on this system.
71
72=item Net::FPing::ipv4_pktsize
73
74Returns the number of bytes each IPv4 ping packet has.
75
76=item Net::FPing::ipv6_pktsize
77
78Returns the number of bytes each IPv4 ping packet has.
79
64=item Net::FPing::ping_ipv4_ranges [ranges...], $send_interval, $payload, \&callback 80=item Net::FPing::icmp_ping [ranges...], $send_interval, $payload, \&callback
65 81
66Ping the given IPv4 address ranges. Each range is an arrayref of the 82Ping the given IPv4 address ranges. Each range is an arrayref of the
67form C<[lo, hi, interval]>, where C<lo> and C<hi> are octet strings with 83form C<[lo, hi, interval]>, where C<lo> and C<hi> are octet strings with
68either 4 octets (for IPv4 addresses) or 16 octets (for IPV6 addresses), 84either 4 octets (for IPv4 addresses) or 16 octets (for IPV6 addresses),
69representing the lowest and highest address to ping (you can convert a 85representing the lowest and highest address to ping (you can convert a
85Algorithm: Each range has an associated "next time to send packet" 101Algorithm: Each range has an associated "next time to send packet"
86time. The algorithm loops as long as there are ranges with hosts to be 102time. The algorithm loops as long as there are ranges with hosts to be
87pinged and always serves the range with the most urgent packet send 103pinged and always serves the range with the most urgent packet send
88time. It will at most send one packet every C<$send_interval> seconds. The 104time. It will at most send one packet every C<$send_interval> seconds. The
89algorithm to send each packet is O(log n) on the number of ranges, so even 105algorithm to send each packet is O(log n) on the number of ranges, so even
90a large number of ranges (many thousands) is managable. 106a large number of ranges (many thousands) is managable. No storage is
107allocated per address.
91 108
92Performance: On my 2 GHZ Opteron system with a pretty average nvidia 109Performance: On my 2 GHZ Opteron system with a pretty average nvidia
93gigabit network card I can ping around 60k to 200k adresses per second, 110gigabit network card I can ping around 60k to 200k adresses per second,
94depending on routing decisions. 111depending on routing decisions.
95 112
96Example: ping 10.0.0.1-10.0.0.15 with at most 100 packets/s, and 113Example: ping 10.0.0.1-10.0.0.15 with at most 100 packets/s, and
9711.0.0.1-11.0.255.255 with at most 1000 packets/s. Do not, however, exceed 11411.0.0.1-11.0.255.255 with at most 1000 packets/s. Do not, however, exceed
981000 packets/s: 1151000 packets/s overall:
99 116
100 Net::FPing::ping_ipv4_ranges 117 Net::FPing::icmp_ping
101 [v10.0.0.1, v10.0.0.15, .01], 118 [v10.0.0.1, v10.0.0.15, .01],
102 [v11.0.0.1, v11.0.255.255, .001], 119 [v11.0.0.1, v11.0.255.255, .001],
103 .001, 0x12345678, 120 .001, 0x12345678,
104 sub { 121 sub {
105 warn "all ranges pinged\n"; 122 warn "all ranges pinged\n";
106 } 123 }
107 ; 124 ;
108 125
109=cut 126=cut
110 127
111sub ping_ipv4_ranges($$$&) { 128sub icmp_ping($$$&) {
112 _send_req _req_ranges4 @_; 129 _send_req _req_icmp_ping @_;
113} 130}
114 131
115our $ICMP4_FH; 132our $ICMP4_FH;
116our $ICMP4_W = (open $ICMP4_FH, "<&=$ICMP4_FD") && AnyEvent->io (fh => $ICMP4_FH, poll => 'r', cb => \&_recv_icmp4); 133our $ICMP4_W = (open $ICMP4_FH, "<&=$ICMP4_FD") && AnyEvent->io (fh => $ICMP4_FH, poll => 'r', cb => \&_recv_icmp4);
117our $ICMP6_FH; 134our $ICMP6_FH;
118our $ICMP6_W = (open $ICMP6_FH, "<&=$ICMP6_FD") && AnyEvent->io (fh => $ICMP6_FH, poll => 'r', cb => \&_recv_icmp6); 135our $ICMP6_W = (open $ICMP6_FH, "<&=$ICMP6_FD") && AnyEvent->io (fh => $ICMP6_FH, poll => 'r', cb => \&_recv_icmp6);
119 136
120#my $t1 = Event::time;
121#my @ranges = map [v127.0.0.1, v127.0.255.255, .000001], 0..0;
122#ping_ipv4_ranges [@ranges, [v11.0.0.2, v11.0.0.15, 1]], 0, 0x12345678, sub { warn "done"; warn +(Event::time - $t1) / 0x100000};
123#
124#AnyEvent->condvar->wait;#d#
125
126=cut
127
1281; 1371;
129 138
130=back 139=back
140
141=head1 BUGS AND SHORTCOMINGS
142
143 - replies are not yet accessible.
144 - ipv6 support has never ever been tested.
131 145
132=head1 AUTHOR 146=head1 AUTHOR
133 147
134 Marc Lehmann <schmorp@schmorp.de> 148 Marc Lehmann <schmorp@schmorp.de>
135 http://home.schmorp.de/ 149 http://home.schmorp.de/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines