Module: Trema::Shell
- Defined in:
- ruby/trema/shell/up.rb,
ruby/trema/shell/run.rb,
ruby/trema/shell/down.rb,
ruby/trema/shell/link.rb,
ruby/trema/shell/vhost.rb,
ruby/trema/shell/killall.rb,
ruby/trema/shell/vswitch.rb,
ruby/trema/shell/show_stats.rb,
ruby/trema/shell/reset_stats.rb,
ruby/trema/shell/send_packets.rb
Class Method Summary collapse
- .send_packets(source, dest, options = {}) ⇒ Object
- .vhost(name = nil, &block) ⇒ Object
- .vswitch(name = nil, &block) ⇒ Object
Instance Method Summary collapse
- #down(name) ⇒ Object
- #killall ⇒ Object
- #link(peer0, peer1) ⇒ Object
- #reset_stats(host_name = nil) ⇒ Object
- #run(controller) ⇒ Object
- #show_stats(host_name, option) ⇒ Object
- #up(name) ⇒ Object
Class Method Details
.send_packets(source, dest, options = {}) ⇒ Object
26 27 28 29 30 |
# File 'ruby/trema/shell/send_packets.rb', line 26 def send_packets source, dest, = {} assert_trema_is_built Cli.new( Host[ source ] ).send_packets( Host[ dest ], ) true end |
.vhost(name = nil, &block) ⇒ Object
26 27 28 29 30 31 32 |
# File 'ruby/trema/shell/vhost.rb', line 26 def vhost name = nil, &block stanza = DSL::Vhost.new( name ) stanza.instance_eval( &block ) if block Host.new stanza $context.dump true end |
.vswitch(name = nil, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'ruby/trema/shell/vswitch.rb', line 26 def vswitch name = nil, &block raise "Not in Trema shell" if $config.nil? raise "No dpid given" if name.nil? and block.nil? stanza = DSL::Vswitch.new( name ) stanza.instance_eval &block if block OpenVswitch.new( stanza, $config.port ).restart! $context.dump true end |
Instance Method Details
#down(name) ⇒ Object
26 27 28 |
# File 'ruby/trema/shell/down.rb', line 26 def down name OpenflowSwitch[ name ].shutdown! end |
#killall ⇒ Object
26 27 28 29 |
# File 'ruby/trema/shell/killall.rb', line 26 def killall cleanup_current_session true end |
#link(peer0, peer1) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'ruby/trema/shell/link.rb', line 26 def link peer0, peer1 stanza = DSL::Link.new( peer0, peer1 ) link = Link.new( stanza ) link.enable! if OpenflowSwitch[ peer0 ] OpenflowSwitch[ peer0 ] << link.name end if OpenflowSwitch[ peer1 ] OpenflowSwitch[ peer1 ] << link.name_peer end if Host[ peer0 ] Host[ peer0 ].interface = link.name Host[ peer0 ].run! end if Host[ peer1 ] Host[ peer1 ].interface = link.name_peer Host[ peer1 ].run! end $context.dump true end |
#reset_stats(host_name = nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'ruby/trema/shell/reset_stats.rb', line 26 def reset_stats host_name = nil assert_trema_is_built if host_name and Host[ host_name ].nil? raise "Host '#{ host_name }' is not defined." end if host_name Cli.new( Host[ host_name ] ).reset_stats else Host.each do | each | Cli.new( each ).reset_stats end end true end |
#run(controller) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'ruby/trema/shell/run.rb', line 26 def run controller assert_trema_is_built if controller if /\.rb\Z/=~ controller.split.first require "trema" include Trema ARGV.replace controller.split $LOAD_PATH << File.dirname( controller ) load controller else # Assume that the controller is written in C stanza = Trema::DSL::Run.new stanza.path controller Trema::App.new( stanza ) end end runner = DSL::Runner.new( $config ) runner.maybe_run_switch_manager $config.switches.each do | name, switch | if switch.running? switch.restart! else switch.run! end end $config.apps.values.last.daemonize! $context.dump true end |
#show_stats(host_name, option) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'ruby/trema/shell/show_stats.rb', line 26 def show_stats host_name, option assert_trema_is_built raise "Host '#{ host_name }' is not defined." if Host[ host_name ].nil? raise "Host '#{ host_name }' is not connected to any link." if Host[ host_name ].interface.nil? if option.to_s == "tx" Cli.new( Host[ host_name ] ).show_tx_stats else Cli.new( Host[ host_name ] ).show_rx_stats end true end |
#up(name) ⇒ Object
26 27 28 29 30 31 32 |
# File 'ruby/trema/shell/up.rb', line 26 def up name if OpenflowSwitch[ name ].running? OpenflowSwitch[ name ].restart! else OpenflowSwitch[ name ].run! end end |