bin/trema in trema-0.4.6 vs bin/trema in trema-0.4.7
- old
+ new
@@ -17,199 +17,199 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
-$LOAD_PATH.unshift File.expand_path( File.join File.dirname( __FILE__ ), "..", "ruby" )
+$LOAD_PATH.unshift File.expand_path(File.join File.dirname(__FILE__), '..', 'ruby')
-require "rubygems"
-require "bundler/setup"
+require 'rubygems'
+require 'bundler/setup'
-require "gli"
-require "trema/command"
-require "trema/util"
-require "trema/version"
-require "trema/default_openflow_channel_port"
+require 'gli'
+require 'trema/command'
+require 'trema/util'
+require 'trema/version'
+require 'trema/default_openflow_channel_port'
class BinTrema
include Trema::Command
include Trema::Util
include GLI::App
def initialize
- program_desc "Trema command-line tool"
+ program_desc 'Trema command-line tool'
- desc "Displays the current runtime version"
+ desc 'Displays the current runtime version'
version Trema::VERSION
- desc "Be verbose"
- switch [ :v, :verbose ], :negatable => false
+ desc 'Be verbose'
+ switch [:v, :verbose], :negatable => false
- desc "Runs a trema application"
- arg_name "controller"
+ desc 'Runs a trema application'
+ arg_name 'controller'
command :run do | c |
- c.desc "Runs as a daemon"
- c.switch [ :d, :daemonize ], :negatable => false
+ c.desc 'Runs as a daemon'
+ c.switch [:d, :daemonize], :negatable => false
- c.desc "Enables Trema wireshark plugin"
- c.switch [ :s, :tremashark ], :negatable => false
+ c.desc 'Enables Trema wireshark plugin'
+ c.switch [:s, :tremashark], :negatable => false
c.desc "Overrides the default openflow channel port #{Trema::DEFAULT_OPENFLOW_CHANNEL_PORT}"
- c.flag [ :p, :port ]
+ c.flag [:p, :port]
- c.desc "Specifies emulated network configuration"
- c.flag [ :c, :conf ]
+ c.desc 'Specifies emulated network configuration'
+ c.flag [:c, :conf]
- c.desc "Disables initial flow cleanup for a connected switch"
- c.switch [ :r, :no_flow_cleanup ], :negatable => false
+ c.desc 'Disables initial flow cleanup for a connected switch'
+ c.switch [:r, :no_flow_cleanup], :negatable => false
c.action do | global_options, options, args |
trema_run options
end
end
- desc "Terminates a trema process"
- arg_name "name"
+ desc 'Terminates a trema process'
+ arg_name 'name'
command :kill do | c |
c.action do | global_options, options, args |
- help_now!( "name is required" ) if args.empty?
+ help_now!('name is required') if args.empty?
args.each do | each |
trema_kill each
end
end
end
- desc "Starts a killed trema process again"
- arg_name "name"
+ desc 'Starts a killed trema process again'
+ arg_name 'name'
command :up do | c |
c.action do | global_options, options, args |
- trema_up args[ 0 ]
+ trema_up args[ 0]
end
end
- desc "Terminates all trema processes"
+ desc 'Terminates all trema processes'
command :killall do | c |
c.action do
trema_killall
end
end
- desc "Sends UDP packets to destination host"
+ desc 'Sends UDP packets to destination host'
command :send_packets do | c |
- c.desc "host that sends packets"
- c.flag [ :s, :source ]
+ c.desc 'host that sends packets'
+ c.flag [:s, :source]
- c.desc "host that receives packets"
- c.flag [ :d, :dest ]
+ c.desc 'host that receives packets'
+ c.flag [:d, :dest]
- c.desc "number of times to increment the IP source address"
+ c.desc 'number of times to increment the IP source address'
c.default_value nil
- c.flag [ :inc_ip_src ]
+ c.flag [:inc_ip_src]
- c.desc "number of times to increment the IP destination address"
+ c.desc 'number of times to increment the IP destination address'
c.default_value nil
- c.flag [ :inc_ip_dst ]
+ c.flag [:inc_ip_dst]
- c.desc "set the initial UDP source port"
- c.flag [ :tp_src ]
+ c.desc 'set the initial UDP source port'
+ c.flag [:tp_src]
- c.desc "number of times to increment the UDP source port"
+ c.desc 'number of times to increment the UDP source port'
c.default_value nil
- c.flag [ :inc_tp_src ]
+ c.flag [:inc_tp_src]
- c.desc "set the initial UDP destination port"
- c.flag [ :tp_dst ]
+ c.desc 'set the initial UDP destination port'
+ c.flag [:tp_dst]
- c.desc "number of times to increment the UDP destination port"
+ c.desc 'number of times to increment the UDP destination port'
c.default_value nil
- c.flag [ :inc_tp_dst ]
+ c.flag [:inc_tp_dst]
- c.desc "send packet rate - packets per second"
- c.flag [ :pps ]
+ c.desc 'send packet rate - packets per second'
+ c.flag [:pps]
- c.desc "number of packets to send"
- c.flag [ :n_pkts ]
+ c.desc 'number of packets to send'
+ c.flag [:n_pkts]
- c.desc "time duration to send packets"
- c.flag [ :duration ]
+ c.desc 'time duration to send packets'
+ c.flag [:duration]
- c.desc "length of UDP payload"
- c.flag [ :length ]
+ c.desc 'length of UDP payload'
+ c.flag [:length]
- c.desc "increment UDP payload"
+ c.desc 'increment UDP payload'
c.default_value nil
- c.flag [ :inc_payload ]
+ c.flag [:inc_payload]
c.action do | global_options, options, args |
- raise "--source option is mandatory" if options[ :source ].nil?
- raise "--dest option is mandatory" if options[ :dest ].nil?
+ fail '--source option is mandatory' if options[ :source].nil?
+ fail '--dest option is mandatory' if options[ :dest].nil?
- trema_send_packets options[ :source ], options[ :dest ], options
+ trema_send_packets options[ :source], options[ :dest], options
end
end
desc "Brings a switch's specified port up"
command :port_up do | c |
- c.desc "switch name"
- c.flag [ :s, :switch ]
+ c.desc 'switch name'
+ c.flag [:s, :switch]
- c.desc "port"
- c.flag [ :p, :port ]
+ c.desc 'port'
+ c.flag [:p, :port]
c.action do | global_options, options, args |
- raise "--switch option is mandatory" if options[ :switch ].nil?
- raise "--port option is mandatory" if options[ :port ].nil?
+ fail '--switch option is mandatory' if options[ :switch].nil?
+ fail '--port option is mandatory' if options[ :port].nil?
- trema_port_up options[ :switch ], options[ :port ]
+ trema_port_up options[ :switch], options[ :port]
end
end
desc "Brings a switch's specified port down"
command :port_down do | c |
- c.desc "switch name"
- c.flag [ :s, :switch ]
+ c.desc 'switch name'
+ c.flag [:s, :switch]
- c.desc "port"
- c.flag [ :p, :port ]
+ c.desc 'port'
+ c.flag [:p, :port]
c.action do | global_options, options, args |
- raise "--switch option is mandatory" if options[ :switch ].nil?
- raise "--port option is mandatory" if options[ :port ].nil?
+ fail '--switch option is mandatory' if options[ :switch].nil?
+ fail '--port option is mandatory' if options[ :port].nil?
- trema_port_down options[ :switch ], options[ :port ]
+ trema_port_down options[ :switch], options[ :port]
end
end
- desc "Shows stats of packets"
- arg_name "host"
+ desc 'Shows stats of packets'
+ arg_name 'host'
command :show_stats do | c |
- c.desc "Show stats of packets sent"
- c.switch [ :t, :tx ], :negatable => false
- c.desc "Show stats of packets received"
- c.switch [ :r, :rx ], :negatable => false
+ c.desc 'Show stats of packets sent'
+ c.switch [:t, :tx], :negatable => false
+ c.desc 'Show stats of packets received'
+ c.switch [:r, :rx], :negatable => false
c.action do | global_options, options, args |
- help_now!( "host is required" ) if args.empty?
- trema_show_stats args[ 0 ], options[ :tx ], options[ :rx ]
+ help_now!('host is required') if args.empty?
+ trema_show_stats args[ 0], options[ :tx], options[ :rx]
end
end
- desc "Resets stats of packets"
- arg_name "hosts..."
+ desc 'Resets stats of packets'
+ arg_name 'hosts...'
command :reset_stats do | c |
c.action do | global_options, options, args |
hosts = args
if hosts.empty?
hosts = Trema::DSL::Context.load_current.hosts.keys
@@ -219,25 +219,25 @@
end
end
end
- desc "Print all flow entries"
- arg_name "switches..."
+ desc 'Print all flow entries'
+ arg_name 'switches...'
command :dump_flows do | c |
c.action do | global_options, options, args |
- help_now!( "switches is required" ) if args.empty?
+ help_now!('switches is required') if args.empty?
trema_dump_flows args
end
end
- desc "Opens a new shell in the specified network namespace"
- arg_name "name"
+ desc 'Opens a new shell in the specified network namespace'
+ arg_name 'name'
command :netns do | c |
c.action do | global_options, options, args |
- trema_netns args[ 0 ]
+ trema_netns args[ 0]
end
end
desc "Opens in your browser Trema's Ruby API documentation"
@@ -246,11 +246,11 @@
trema_ruby
end
end
- desc "Displays the current runtime version"
+ desc 'Displays the current runtime version'
command :version do | c |
c.action do
trema_version
end
end
@@ -258,22 +258,22 @@
GLI::Commands::Help.skips_pre = false
pre do | global, command, options, args |
- $verbose = global[ :verbose ]
+ $verbose = global[ :verbose]
- if global[ :version ]
+ if global[ :version]
trema_version
exit_now! nil, 0
end
assert_trema_is_built
- if FileTest.exist?( Trema.tmp ) and not FileTest.writable?( Trema.tmp )
+ if FileTest.exist?(Trema.tmp) && !FileTest.writable?(Trema.tmp)
# Trema is system widely installed with gem command
- sh "sudo chmod o+w -R #{ Trema.tmp }"
+ sh "sudo chmod a+w -R #{ Trema.tmp }"
end
FileUtils.mkdir_p Trema.log
FileUtils.mkdir_p Trema.pid
FileUtils.mkdir_p Trema.sock
@@ -288,24 +288,22 @@
true
end
end
- def start argv
- begin
- run argv
- rescue
- puts $!
- $!.backtrace.each do | each |
- puts each
- end
- exit
+ def start(argv)
+ run argv
+ rescue
+ puts $!
+ $!.backtrace.each do | each |
+ puts each
end
+ exit
end
end
-exit BinTrema.new.start( ARGV )
+exit BinTrema.new.start(ARGV)
### Local variables:
### mode: Ruby
### coding: utf-8