… | |
… | |
16 | you have to run an event model supported by AnyEvent to use this module. |
16 | you have to run an event model supported by AnyEvent to use this module. |
17 | |
17 | |
18 | Receiving and processing reply packets is not currently supported by this |
18 | Receiving and processing reply packets is not currently supported by this |
19 | module. |
19 | module. |
20 | |
20 | |
|
|
21 | =head1 FUNCTIONS |
|
|
22 | |
21 | =over 4 |
23 | =over 4 |
22 | |
24 | |
23 | =cut |
25 | =cut |
24 | |
26 | |
25 | package Net::FPing; |
27 | package Net::FPing; |
26 | |
28 | |
|
|
29 | use strict; |
|
|
30 | no warnings; |
|
|
31 | |
27 | use AnyEvent; |
32 | use AnyEvent; |
28 | |
33 | |
29 | BEGIN { |
34 | BEGIN { |
30 | $VERSION = '0.01'; |
35 | our $VERSION = '0.01'; |
31 | @ISA = qw(Exporter); |
36 | our @ISA = qw(Exporter); |
32 | |
37 | |
33 | require Exporter; |
38 | require Exporter; |
34 | Exporter::export_ok_tags(keys %EXPORT_TAGS); |
39 | #Exporter::export_ok_tags (keys %EXPORT_TAGS); |
35 | |
40 | |
36 | require XSLoader; |
41 | require XSLoader; |
37 | XSLoader::load __PACKAGE__, $VERSION; |
42 | XSLoader::load (__PACKAGE__, $VERSION); |
38 | } |
43 | } |
|
|
44 | |
|
|
45 | our ($THR_REQ_FD, $THR_RES_FD, $ICMP4_FD, $ICMP6_FD); |
39 | |
46 | |
40 | our $THR_REQ_FH; open $THR_REQ_FH, ">&=$THR_REQ_FD" or die "FATAL: cannot fdopen"; |
47 | our $THR_REQ_FH; open $THR_REQ_FH, ">&=$THR_REQ_FD" or die "FATAL: cannot fdopen"; |
41 | our $THR_RES_FH; open $THR_RES_FH, "<&=$THR_RES_FD" or die "FATAL: cannot fdopen"; |
48 | our $THR_RES_FH; open $THR_RES_FH, "<&=$THR_RES_FD" or die "FATAL: cannot fdopen"; |
42 | |
49 | |
43 | our $THR_REQ_W; |
50 | our $THR_REQ_W; |
… | |
… | |
46 | or return; |
53 | or return; |
47 | |
54 | |
48 | $sv->(); |
55 | $sv->(); |
49 | }); |
56 | }); |
50 | |
57 | |
51 | our @THR_REQ_BUF; |
58 | our $THR_REQ_BUF; |
52 | |
59 | |
53 | sub _send_req($) { |
60 | sub _send_req($) { |
54 | $THR_REQ_BUF .= $_[0]; |
61 | $THR_REQ_BUF .= $_[0]; |
55 | |
62 | |
56 | $THR_REQ_W ||= AnyEvent->io (fh => $THR_REQ_FH, poll => 'w', cb => sub { |
63 | $THR_REQ_W ||= AnyEvent->io (fh => $THR_REQ_FH, poll => 'w', cb => sub { |
… | |
… | |
104 | time. It will at most send one packet every C<$send_interval> seconds. The |
111 | time. It will at most send one packet every C<$send_interval> seconds. The |
105 | algorithm to send each packet is O(log n) on the number of ranges, so even |
112 | algorithm to send each packet is O(log n) on the number of ranges, so even |
106 | a large number of ranges (many thousands) is managable. No storage is |
113 | a large number of ranges (many thousands) is managable. No storage is |
107 | allocated per address. |
114 | allocated per address. |
108 | |
115 | |
109 | Performance: On my 2 GHZ Opteron system with a pretty average nvidia |
116 | Performance: On my 2 GHz Opteron system with a pretty average nvidia |
110 | gigabit network card I can ping around 60k to 200k adresses per second, |
117 | gigabit network card I can ping around 60k to 200k adresses per second, |
111 | depending on routing decisions. |
118 | depending on routing decisions. |
112 | |
119 | |
113 | Example: ping 10.0.0.1-10.0.0.15 with at most 100 packets/s, and |
120 | Example: ping 10.0.0.1-10.0.0.15 with at most 100 packets/s, and |
114 | 11.0.0.1-11.0.255.255 with at most 1000 packets/s. Do not, however, exceed |
121 | 11.0.0.1-11.0.255.255 with at most 1000 packets/s. Do not, however, exceed |
115 | 1000 packets/s overall: |
122 | 1000 packets/s overall: |
116 | |
123 | |
|
|
124 | my $done = AnyEvent->condvar; |
|
|
125 | |
117 | Net::FPing::icmp_ping |
126 | Net::FPing::icmp_ping |
118 | [v10.0.0.1, v10.0.0.15, .01], |
127 | [v10.0.0.1, v10.0.0.15, .01], |
119 | [v11.0.0.1, v11.0.255.255, .001], |
128 | [v11.0.0.1, v11.0.255.255, .001], |
120 | .001, 0x12345678, |
129 | .001, 0x12345678, |
121 | sub { |
130 | sub { |
122 | warn "all ranges pinged\n"; |
131 | warn "all ranges pinged\n"; |
|
|
132 | $done->broadcast; |
123 | } |
133 | } |
124 | ; |
134 | ; |
|
|
135 | |
|
|
136 | $done->wait; |
125 | |
137 | |
126 | =cut |
138 | =cut |
127 | |
139 | |
128 | sub icmp_ping($$$&) { |
140 | sub icmp_ping($$$&) { |
129 | _send_req _req_icmp_ping @_; |
141 | _send_req _req_icmp_ping @_; |