… | |
… | |
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 | |
|
|
66 | Returns true if IPv4 is supported in this module and on this system. |
|
|
67 | |
|
|
68 | =item Net::FPing::ipv6_supported |
|
|
69 | |
|
|
70 | Returns true if IPv6 is supported in this module and on this system. |
|
|
71 | |
|
|
72 | =item Net::FPing::ipv4_pktsize |
|
|
73 | |
|
|
74 | Returns the number of bytes each IPv4 ping packet has. |
|
|
75 | |
|
|
76 | =item Net::FPing::ipv6_pktsize |
|
|
77 | |
|
|
78 | Returns 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 | |
66 | Ping the given IPv4 address ranges. Each range is an arrayref of the |
82 | Ping the given IPv4 address ranges. Each range is an arrayref of the |
67 | form C<[lo, hi, interval]>, where C<lo> and C<hi> are octet strings with |
83 | form C<[lo, hi, interval]>, where C<lo> and C<hi> are octet strings with |
68 | either 4 octets (for IPv4 addresses) or 16 octets (for IPV6 addresses), |
84 | either 4 octets (for IPv4 addresses) or 16 octets (for IPV6 addresses), |
69 | representing the lowest and highest address to ping (you can convert a |
85 | representing the lowest and highest address to ping (you can convert a |
… | |
… | |
85 | Algorithm: Each range has an associated "next time to send packet" |
101 | Algorithm: Each range has an associated "next time to send packet" |
86 | time. The algorithm loops as long as there are ranges with hosts to be |
102 | time. The algorithm loops as long as there are ranges with hosts to be |
87 | pinged and always serves the range with the most urgent packet send |
103 | pinged and always serves the range with the most urgent packet send |
88 | time. It will at most send one packet every C<$send_interval> seconds. The |
104 | time. It will at most send one packet every C<$send_interval> seconds. The |
89 | algorithm to send each packet is O(log n) on the number of ranges, so even |
105 | algorithm to send each packet is O(log n) on the number of ranges, so even |
90 | a large number of ranges (many thousands) is managable. |
106 | a large number of ranges (many thousands) is managable. No storage is |
|
|
107 | allocated per address. |
91 | |
108 | |
92 | Performance: On my 2 GHZ Opteron system with a pretty average nvidia |
109 | Performance: On my 2 GHZ Opteron system with a pretty average nvidia |
93 | gigabit network card I can ping around 60k to 200k adresses per second, |
110 | gigabit network card I can ping around 60k to 200k adresses per second, |
94 | depending on routing decisions. |
111 | depending on routing decisions. |
95 | |
112 | |
96 | Example: ping 10.0.0.1-10.0.0.15 with at most 100 packets/s, and |
113 | Example: ping 10.0.0.1-10.0.0.15 with at most 100 packets/s, and |
97 | 11.0.0.1-11.0.255.255 with at most 1000 packets/s. Do not, however, exceed |
114 | 11.0.0.1-11.0.255.255 with at most 1000 packets/s. Do not, however, exceed |
98 | 1000 packets/s: |
115 | 1000 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 | |
111 | sub ping_ipv4_ranges($$$&) { |
128 | sub icmp_ping($$$&) { |
112 | _send_req _req_ranges4 @_; |
129 | _send_req _req_icmp_ping @_; |
113 | } |
130 | } |
114 | |
131 | |
115 | our $ICMP4_FH; |
132 | our $ICMP4_FH; |
116 | our $ICMP4_W = (open $ICMP4_FH, "<&=$ICMP4_FD") && AnyEvent->io (fh => $ICMP4_FH, poll => 'r', cb => \&_recv_icmp4); |
133 | our $ICMP4_W = (open $ICMP4_FH, "<&=$ICMP4_FD") && AnyEvent->io (fh => $ICMP4_FH, poll => 'r', cb => \&_recv_icmp4); |
117 | our $ICMP6_FH; |
134 | our $ICMP6_FH; |
118 | our $ICMP6_W = (open $ICMP6_FH, "<&=$ICMP6_FD") && AnyEvent->io (fh => $ICMP6_FH, poll => 'r', cb => \&_recv_icmp6); |
135 | our $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 | |
|
|
128 | 1; |
137 | 1; |
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/ |