57 | | == 1.1 !OpenFlow Statistics Measurement == |
58 | | |
59 | | ofcollect.rb |
60 | | {{{ |
61 | | |
62 | | #!/usr/bin/env ruby |
63 | | require 'rubygems' |
64 | | require 'oml4r' |
65 | | require 'file-tail' |
66 | | APPNAME = "ofstats" |
67 | | class MPThroughput < OML4R::MPBase |
68 | | name :ofthroughput |
69 | | param :pathtype, :type => :string |
70 | | param :numflows, :type => :int64 |
71 | | param :numbytes, :type => :int64 |
72 | | param :numpacket, :type => :int64 |
73 | | param :throughput, :type => :int64 |
74 | | param :units, :type => :string |
75 | | param :instput, :type => :int64 |
76 | | param :units2, :type => :string |
77 | | end |
78 | | class OFStatsWrapper |
79 | | def initialize(args) |
80 | | @addr = nil |
81 | | @if_num = ' ' |
82 | | @trema_port = ' ' |
83 | | @trema_path = ' ' |
84 | | @verbose = true |
85 | | @numeric = ' ' |
86 | | OML4R::init(args, :appName => "#{APPNAME}_wrapper", :domain => 'foo', :collect => 'file:-') { |argParser| |
87 | | argParser.banner = "Reports OpenFlow stat measurements via OML\n\n" |
88 | | argParser.on("-f" , "--file_path ADDRESS", "Path where output is saved"){ |address| @addr = address } |
89 | | argParser.on("-i","--interface IFNUM","Interface number"){ |if_num| @if_num ="#{if_num.to_i()}" } |
90 | | argParser.on("-q", "--no-quiet ","Don't show of stats output on console"){ @verbose = false } |
91 | | argParser.on("-n", "--[no]-numeric ", "No attempt twill be made to look up symbolic names for host addresses"){ @numeric ='-n' } |
92 | | } |
93 | | unless @addr !=nil |
94 | | raise "You did not specify path of file (-p option)" |
95 | | end |
96 | | end |
97 | | class MyFile < File |
98 | | include File::Tail |
99 | | end |
100 | | def start() |
101 | | log = MyFile.new("#{@addr}") |
102 | | log.interval = @if_num |
103 | | log.backward(10) |
104 | | puts "#{@if_num}" |
105 | | log.tail { |line| print line |
106 | | processOutput(line) |
107 | | } |
108 | | end |
109 | | def processOutput(output) |
110 | | column = output.split(" ") |
111 | | puts "Each line process" |
112 | | # Inject the measurements into OML |
113 | | MPThroughput.inject("#{column[0]}", column[1], column[2], |
114 | | column[3], column[4], "#{column[5]}", |
115 | | column[6], "#{column[7]}") |
116 | | end |
117 | | end |
118 | | begin |
119 | | app = OFStatsWrapper.new(ARGV) |
120 | | app.start() |
121 | | rescue SystemExit |
122 | | rescue SignalException |
123 | | puts "OFWrapper stopped." |
124 | | rescue Exception => ex |
125 | | puts "Error - When executing the wrapper application!" |
126 | | puts "Error - Type: #{ex.class}" |
127 | | puts "Error - Message: #{ex}\n\n" |
128 | | # Uncomment the next line to get more info on errors |
129 | | # puts "Trace - #{ex.backtrace.join("\n\t")}" |
130 | | end |
131 | | OML4R::close() |
132 | | # Local Variables: |
133 | | # mode:ruby |
134 | | # End: |
135 | | # vim: ft=ruby:sw=2 |
136 | | }}} |
137 | | |
138 | | OEDL script |
139 | | {{{ |
140 | | |
141 | | defProperty('source1', "nowcastbox-sdxdemo", "ID of a resource") |
142 | | defProperty('intervalcol',"1", "Interval to Tail") |
143 | | |
144 | | defProperty('pathfile', "/tmp/flowstats.out", "Path to file") |
145 | | |
146 | | |
147 | | |
148 | | defApplication('ofstats') do |app| |
149 | | app.description = 'Simple Definition for the of-collect application' |
150 | | # Define the path to the binary executable for this application |
151 | | app.binary_path = '/usr/local/bin/ofcollect.rb' |
152 | | app.defProperty('target', 'Address to output file', '-f', {:type => :string}) |
153 | | app.defProperty("interval","Interval",'-i', {:type => :string}) |
154 | | app.defMeasurement('wrapper_ofthroughput') do |m| |
155 | | m.defMetric(':pathtype', :string) |
156 | | m.defMetric('throughput',:int64) |
157 | | m.defMetric('instput',:int64) |
158 | | end |
159 | | end |
160 | | defGroup('Source1', property.source1) do |node| |
161 | | node.addApplication("ofstats") do |app| |
162 | | app.setProperty('target', property.pathfile) |
163 | | app.setProperty('interval', property.intervalcol) |
164 | | app.measure('wrapper_ofthroughput', :samples => 1) |
165 | | end |
166 | | end |
167 | | |
168 | | |
169 | | onEvent(:ALL_UP_AND_INSTALLED) do |event| |
170 | | info "Starting the collect" |
171 | | after 2 do |
172 | | group('Source1').startApplications |
173 | | end |
174 | | after 800 do |
175 | | info "Stopping the collect" |
176 | | allGroups.stopApplications |
177 | | Experiment.done |
178 | | end |
179 | | end |
180 | | |
181 | | defGraph 'Throughput' do |g| |
182 | | g.ms('wrapper_ofthroughput').select(:oml_ts_client, :throughput, :pathtype) |
183 | | g.caption "Throughput of Flows" |
184 | | g.type 'line_chart3' |
185 | | g.mapping :x_axis => :oml_ts_client, :y_axis => :throughput, :group_by => :pathtype |
186 | | g.xaxis :legend => 'oml_ts' |
187 | | g.yaxis :legend => 'Throughput', :ticks => {:format => 's'} |
188 | | end |
189 | | defGraph 'InstantaneousThroughput' do |g| |
190 | | g.ms('wrapper_ofthroughput').select(:oml_ts_client, :instput, :pathtype) |
191 | | g.caption "Throughput of Flows" |
192 | | g.type 'line_chart3' |
193 | | g.mapping :x_axis => :oml_ts_client, :y_axis => :instput, :group_by => :pathtype |
194 | | g.xaxis :legend => 'oml_ts' |
195 | | g.yaxis :legend => 'Instantaneous Throughput', :ticks => {:format => 's'} |
196 | | end |
197 | | |
198 | | }}} |
199 | | |
200 | | |
201 | | [wiki:GEC20Agenda/LabWiki LabWiki Tutorial] |