rb-wartslib 0.9.10 → 0.9.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #############################################################################
4
+ ## Prints some basic statistics about warts files specified on the command line.
5
+ ##
6
+ ## --------------------------------------------------------------------------
7
+ ## Copyright (C) 2007 The Regents of the University of California.
8
+ ##
9
+ ## This program is free software; you can redistribute it and/or modify
10
+ ## it under the terms of the GNU General Public License as published by
11
+ ## the Free Software Foundation; either version 2 of the License, or
12
+ ## (at your option) any later version.
13
+ ##
14
+ ## This program is distributed in the hope that it will be useful,
15
+ ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ ## GNU General Public License for more details.
18
+ ##
19
+ ## You should have received a copy of the GNU General Public License
20
+ ## along with this program; if not, write to the Free Software
21
+ ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
+ ##
23
+ ## $Id: stat-traces,v 1.1 2007/11/30 01:14:48 youngh Exp $
24
+ #############################################################################
25
+
26
+ require 'rubygems'
27
+ require 'ostruct'
28
+ require 'wartslib'
29
+
30
+ class Stats
31
+ attr_accessor :traces, :responding, :complete, :stop_reason
32
+ attr_accessor :hop_histogram, :zero_dead
33
+
34
+ def initialize
35
+ @traces = 0
36
+ @responding = 0
37
+ @complete = 0
38
+ @stop_reason = Hash.new 0
39
+
40
+ # from scamper_trace.h:SCAMPER_TRACE_STOP_*
41
+ @stop_text = {
42
+ 0 => "none (null reason)",
43
+ 1 => "completed (got an ICMP port unreach)",
44
+ 2 => "unreach (got an other ICMP unreach code)",
45
+ 3 => "icmp (got an ICMP msg, not unreach)",
46
+ 4 => "loop (loop detected)",
47
+ 5 => "dead (unresponsive target)",
48
+ 6 => "error (sendto error)"
49
+ }
50
+ @stop_text.default = "<<UNKNOWN STOP CODE>>"
51
+
52
+ @hop_histogram = Hash.new 0
53
+ @zero_dead = 0
54
+ end
55
+
56
+ def print
57
+ puts "%8d traces" % [@traces]
58
+ puts "%8d responding (%.1f%%)" % [@responding, pct(@responding, @traces)]
59
+ puts "%8d complete (%.1f%%)" % [@complete, pct(@complete, @traces)]
60
+ puts "%8d dead traces with zero hop count (%.1f%%)" %
61
+ [ @zero_dead, pct(@zero_dead, @traces) ]
62
+ puts
63
+ stop_reason.to_a.sort.each do |k, v|
64
+ puts "%8d stop reason %d, %s" % [v, k, @stop_text[k]]
65
+ end
66
+ puts
67
+ @hop_histogram.to_a.sort.each do |k, v|
68
+ puts "%8d %d hops" % [v, k]
69
+ end
70
+ end
71
+
72
+ def add(other)
73
+ @traces += other.traces
74
+ @responding += other.responding
75
+ @complete += other.complete
76
+ other.stop_reason.each { |k,v| @stop_reason[k] += v }
77
+ other.hop_histogram.each { |k,v| @hop_histogram[k] += v }
78
+ @zero_dead += other.zero_dead
79
+ end
80
+
81
+ def pct(x, y)
82
+ return 100.0 if y == 0
83
+ x.quo(y) * 100.0
84
+ end
85
+ end
86
+
87
+ #===========================================================================
88
+
89
+ total = Stats.new
90
+
91
+ ARGV.each do |path|
92
+ stats = Stats.new
93
+ Warts::File.open(path) do |file|
94
+ file.add_filters Warts::File::TRACE
95
+ file.read do |trace|
96
+ stats.traces += 1
97
+ stats.responding += 1 if trace.dest_responded?
98
+ stats.complete += 1 if trace.complete?
99
+ stats.stop_reason[trace.stop_reason] += 1
100
+ stats.hop_histogram[trace.path_length] += 1
101
+ stats.zero_dead += 1 if trace.stop_reason == 5 && trace.hop_count == 0
102
+ end
103
+ end
104
+
105
+ puts "\n"
106
+ puts("-" * 70)
107
+ puts path
108
+ stats.print
109
+
110
+ total.add stats
111
+ end
112
+
113
+ if ARGV.length > 1
114
+ puts "\n"
115
+ puts("=" * 70)
116
+ puts "total"
117
+ total.print
118
+ end
@@ -0,0 +1,159 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #############################################################################
4
+ ## Prints out a histogram of the size of gaps (that is, consecutive
5
+ ## non-responding hops) in traces.
6
+ ##
7
+ ## --------------------------------------------------------------------------
8
+ ## Copyright (C) 2007 The Regents of the University of California.
9
+ ##
10
+ ## This program is free software; you can redistribute it and/or modify
11
+ ## it under the terms of the GNU General Public License as published by
12
+ ## the Free Software Foundation; either version 2 of the License, or
13
+ ## (at your option) any later version.
14
+ ##
15
+ ## This program is distributed in the hope that it will be useful,
16
+ ## but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ ## GNU General Public License for more details.
19
+ ##
20
+ ## You should have received a copy of the GNU General Public License
21
+ ## along with this program; if not, write to the Free Software
22
+ ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
+ ##
24
+ ## $Id: trace-gap-size-hist,v 1.1 2007/11/30 01:14:48 youngh Exp $
25
+ #############################################################################
26
+
27
+ require 'rubygems'
28
+ require 'ostruct'
29
+ require 'optparse'
30
+
31
+ require 'wartslib'
32
+
33
+ $options = OpenStruct.new
34
+ $options.gap_limit = 5
35
+
36
+ opts = OptionParser.new
37
+ opts.banner = "Usage: trace-gap-size-hist [options] <warts-file-1> ..."
38
+
39
+ opts.on("-g", "--gap-limit", "=NUM",
40
+ "gap limit (#{$options.gap_limit})") do |v|
41
+ $options.gap_limit = v.to_i
42
+ end
43
+
44
+ opts.on("-v", "--[no-]verbose", TrueClass, "show detailed progress") do |v|
45
+ $options.verbose = v
46
+ end
47
+
48
+ begin
49
+ ARGV.replace opts.parse(*ARGV)
50
+ rescue OptionParser::ParseError
51
+ $stderr.puts "ERROR: " + $!
52
+ $stderr.puts opts
53
+ exit 1
54
+ end
55
+
56
+
57
+ #===========================================================================
58
+
59
+ # XXX only uses the first response at each hop
60
+ def extract_ippath(trace)
61
+ retval = []
62
+ retval << trace.src
63
+
64
+ dest_response = trace.find_dest_response
65
+
66
+ trace.each_hop do |hop, exists|
67
+ if exists
68
+ break if dest_response && hop == dest_response[0]
69
+ retval << trace.hop_addr(hop, 0)
70
+ else
71
+ retval << "q"
72
+ end
73
+ end
74
+
75
+ retval << trace.dst if dest_response
76
+ retval
77
+ end
78
+
79
+
80
+ def extract_gaps(ippath)
81
+ retval = []
82
+ gap_size = 0
83
+ ippath.each do |addr|
84
+ if addr == "q"
85
+ gap_size += 1
86
+ else
87
+ unless gap_size == 0
88
+ retval << gap_size
89
+ gap_size = 0
90
+ end
91
+ end
92
+ end
93
+ retval << gap_size unless gap_size == 0
94
+ retval
95
+ end
96
+
97
+
98
+ #############################################################################
99
+ # Main
100
+ #############################################################################
101
+
102
+ num_traces = 0
103
+ gap_count_histogram = Hash.new 0 # count of gaps per trace => count
104
+ mid_gap_count_histogram = Hash.new 0 # count of gaps per trace => count
105
+ gap_size_histogram = Hash.new 0 # size => count
106
+
107
+ ARGV.each do |path|
108
+ file = Warts::File.open path
109
+ unless file
110
+ $stderr.puts "ERROR: couldn't open '#{path}'; skipping"
111
+ next
112
+ end
113
+
114
+ file.add_filters Warts::File::TRACE
115
+ file.read do |trace|
116
+ num_traces += 1
117
+ if $options.verbose
118
+ puts "-" * 78
119
+ puts trace.dump
120
+ end
121
+
122
+ ippath = extract_ippath trace
123
+ puts "\n" + ippath.join(" ") + "\n" if $options.verbose
124
+
125
+ gaps = extract_gaps ippath
126
+ if $options.verbose
127
+ puts "\n" + (gaps.length == 0 ? "none" : gaps.join(" ")) + "\n"
128
+ end
129
+
130
+ gap_count_histogram[gaps.length] += 1
131
+
132
+ mid_gap_count = gaps.length
133
+ mid_gap_count -= 1 if mid_gap_count > 0 && gaps[-1] >= $options.gap_limit
134
+ mid_gap_count_histogram[mid_gap_count] += 1
135
+
136
+ gaps.each do |size|
137
+ gap_size_histogram[size] += 1
138
+ end
139
+ end
140
+ end
141
+
142
+ #---------------------------------------------------------------------------
143
+
144
+ puts "#{num_traces} traces"
145
+
146
+ puts "histogram of number of gaps per trace:"
147
+ gap_count_histogram.to_a.sort.each do |gap_count, trace_count|
148
+ puts " #{gap_count} gaps\t#{trace_count} traces"
149
+ end
150
+
151
+ puts "histogram of number of gaps per trace, excluding final limit-exceeding gap:"
152
+ mid_gap_count_histogram.to_a.sort.each do |gap_count, trace_count|
153
+ puts " #{gap_count} gaps\t#{trace_count} traces"
154
+ end
155
+
156
+ puts "histogram of gap sizes:"
157
+ gap_size_histogram.to_a.sort.each do |gap_size, trace_count|
158
+ puts " #{gap_size} hops\t#{trace_count} gaps"
159
+ end
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ############################################################################
4
+ ## Prints a histogram of the delta (in seconds) between successive traces.
5
+ ##
6
+ ## --------------------------------------------------------------------------
7
+ ## Copyright (C) 2007 The Regents of the University of California.
8
+ ##
9
+ ## This program is free software; you can redistribute it and/or modify
10
+ ## it under the terms of the GNU General Public License as published by
11
+ ## the Free Software Foundation; either version 2 of the License, or
12
+ ## (at your option) any later version.
13
+ ##
14
+ ## This program is distributed in the hope that it will be useful,
15
+ ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ ## GNU General Public License for more details.
18
+ ##
19
+ ## You should have received a copy of the GNU General Public License
20
+ ## along with this program; if not, write to the Free Software
21
+ ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
+ ##
23
+ ## $Id: trace-timestamps-hist,v 1.1 2007/11/30 01:14:48 youngh Exp $
24
+ ############################################################################
25
+
26
+ require "rubygems"
27
+ require 'wartslib'
28
+
29
+ histogram = Hash.new 0
30
+
31
+ ARGV.each do |path|
32
+ Warts::File.open(path) do |file|
33
+ file.clear_all_filters
34
+ file.add_filters Warts::File::TRACE
35
+
36
+ previous_value = nil
37
+ while (trace = file.read)
38
+ value = trace.start
39
+ if previous_value
40
+ delta = value - previous_value
41
+ histogram[delta / 10] += 1
42
+ end
43
+ previous_value = value
44
+ end
45
+ end
46
+ end
47
+
48
+ histogram.keys.sort.each do |bin|
49
+ x = bin * 10
50
+ printf "%d to %d: %d\n", x, x + 9, histogram[bin]
51
+ end
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #############################################################################
4
+ ## Prints out warts files in the textual format of the traceroute command.
5
+ ##
6
+ ## --------------------------------------------------------------------------
7
+ ## Copyright (C) 2007 The Regents of the University of California.
8
+ ##
9
+ ## This program is free software; you can redistribute it and/or modify
10
+ ## it under the terms of the GNU General Public License as published by
11
+ ## the Free Software Foundation; either version 2 of the License, or
12
+ ## (at your option) any later version.
13
+ ##
14
+ ## This program is distributed in the hope that it will be useful,
15
+ ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ ## GNU General Public License for more details.
18
+ ##
19
+ ## You should have received a copy of the GNU General Public License
20
+ ## along with this program; if not, write to the Free Software
21
+ ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
+ ##
23
+ ## $Id: w2tr,v 1.1 2007/11/30 00:02:53 youngh Exp $
24
+ #############################################################################
25
+
26
+ require 'rubygems'
27
+ require 'wartslib'
28
+
29
+ out = Warts::File::open $stdout, "w", Warts::File::TRACEROUTE
30
+
31
+ ARGV.each do |path|
32
+ Warts::File::open(path) do |file|
33
+ file.add_filters Warts::File::TRACE
34
+ file.read do |trace|
35
+ puts
36
+ out.write trace
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #############################################################################
4
+ ## Concatenates input warts files.
5
+ ##
6
+ ## --------------------------------------------------------------------------
7
+ ## Copyright (C) 2007 The Regents of the University of California.
8
+ ##
9
+ ## This program is free software; you can redistribute it and/or modify
10
+ ## it under the terms of the GNU General Public License as published by
11
+ ## the Free Software Foundation; either version 2 of the License, or
12
+ ## (at your option) any later version.
13
+ ##
14
+ ## This program is distributed in the hope that it will be useful,
15
+ ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ ## GNU General Public License for more details.
18
+ ##
19
+ ## You should have received a copy of the GNU General Public License
20
+ ## along with this program; if not, write to the Free Software
21
+ ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
+ ##
23
+ ## $Id: wcat,v 1.2 2007/11/30 00:00:05 youngh Exp $
24
+ #############################################################################
25
+
26
+ require 'rubygems'
27
+ require 'ostruct'
28
+ require 'optparse'
29
+ require 'wartslib'
30
+
31
+ $options = OpenStruct.new
32
+ opts = OptionParser.new
33
+ opts.banner = "Usage: wcat [options] <warts-file-1> <warts-file-2> ..."
34
+
35
+ opts.on("-o", "--output", "=FILE", "output warts file") do |v|
36
+ $options.output_file = v
37
+ end
38
+
39
+ opts.on("-v", "--[no-]verbose", TrueClass, "show detailed progress") do |v|
40
+ $options.verbose = v
41
+ end
42
+
43
+ begin
44
+ ARGV.replace opts.parse(*ARGV)
45
+ rescue OptionParser::ParseError
46
+ $stderr.puts "ERROR: " + $!
47
+ $stderr.puts opts
48
+ exit 1
49
+ end
50
+
51
+ unless $options.output_file
52
+ $stderr.puts "ERROR: missing -o <output_file> option"
53
+ exit 1
54
+ end
55
+
56
+ #===========================================================================
57
+
58
+ out = Warts::File::open $options.output_file, "w", Warts::File::WARTS
59
+ unless out
60
+ $stderr.puts "ERROR: couldn't open output file '#{$options.output_file}'"
61
+ exit 1
62
+ end
63
+
64
+ ARGV.each do |path|
65
+ Warts::File::open(path) do |file|
66
+ file.add_all_filters
67
+ file.read do |element|
68
+ out.write element
69
+ end
70
+ end
71
+ end
72
+
73
+ out.close
data/bin/wdump CHANGED
@@ -8,7 +8,24 @@
8
8
  ## replaces sc_analysis_dump, as a more complete demonstration of using
9
9
  ## rb-wartslib.
10
10
  ##
11
- ## $Id: wdump,v 1.9 2007/11/29 20:35:10 youngh Exp $
11
+ ## --------------------------------------------------------------------------
12
+ ## Copyright (C) 2007 The Regents of the University of California.
13
+ ##
14
+ ## This program is free software; you can redistribute it and/or modify
15
+ ## it under the terms of the GNU General Public License as published by
16
+ ## the Free Software Foundation; either version 2 of the License, or
17
+ ## (at your option) any later version.
18
+ ##
19
+ ## This program is distributed in the hope that it will be useful,
20
+ ## but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ ## GNU General Public License for more details.
23
+ ##
24
+ ## You should have received a copy of the GNU General Public License
25
+ ## along with this program; if not, write to the Free Software
26
+ ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
+ ##
28
+ ## $Id: wdump,v 1.10 2007/11/29 23:57:24 youngh Exp $
12
29
  #############################################################################
13
30
 
14
31
  require 'rubygems'