From 4fb19769d9542679bc6803127d845cbf1f6fb0c8 Mon Sep 17 00:00:00 2001 From: Nick Karanatsios Date: Wed, 10 Apr 2013 17:11:10 +0900 Subject: [PATCH] fix issue#28 to allow multiple trema switches to be started --- ruby/trema/dsl/configuration.rb | 13 +++++++------ ruby/trema/dsl/runner.rb | 4 +++- ruby/trema/trema-switch.rb | 11 ++++++++++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/ruby/trema/dsl/configuration.rb b/ruby/trema/dsl/configuration.rb index e1c01d63..0b908bac 100644 --- a/ruby/trema/dsl/configuration.rb +++ b/ruby/trema/dsl/configuration.rb @@ -89,6 +89,12 @@ class Configuration attr_reader :netnss + # + # holds all instances of configured trema switches + # + attr_reader :trema_switches + + # # Creates a new Trema configuration # @@ -104,7 +110,7 @@ def initialize @links = Trema::Link.clear @packetin_filter = Trema::PacketinFilter.clear @switch_manager = Trema::SwitchManager.clear - @trema_switch = Trema::TremaSwitch.clear + @trema_switches = Trema::TremaSwitch.clear @switches = Trema::OpenflowSwitch.clear @netnss = Trema::Netns.clear end @@ -134,11 +140,6 @@ def packetin_filter def switch_manager @switch_manager.values.last end - - - def trema_switch - @trema_switch.values.last - end end end end diff --git a/ruby/trema/dsl/runner.rb b/ruby/trema/dsl/runner.rb index 6b867042..a8534cec 100644 --- a/ruby/trema/dsl/runner.rb +++ b/ruby/trema/dsl/runner.rb @@ -145,7 +145,9 @@ def maybe_run_netnss def maybe_run_trema_switch - @context.trema_switch.run! if @context.trema_switch + @context.trema_switches.each do | name, trema_switch | + trema_switch.run! + end end diff --git a/ruby/trema/trema-switch.rb b/ruby/trema/trema-switch.rb index b6b4029b..9c6f4d46 100644 --- a/ruby/trema/trema-switch.rb +++ b/ruby/trema/trema-switch.rb @@ -53,7 +53,16 @@ def method_missing message, *args def command ports = @stanza[ :ports ] - ports = Trema::Link.instances.values.map.with_index { | each, i | "#{ each.name }/#{ i + 1 }" }.join( ',' ) if @stanza[ :ports ].nil? + if @stanza[ :ports ].nil? + ports = [] + # TODO refactor + Trema::Link.instances.values.map.with_index do | each, i | + if each.peers[ 0 ].split( ':' )[ 0 ] == @stanza[ :name ] || each.peers[ 1 ].split( ':' )[ 0 ] == @stanza[ :name ] + ports << "#{ each.name }/#{ i + 1 }" + end + end + ports = ports.join( ',' ) + end "export TREMA_HOME=`pwd`; sudo -E #{ Executables.switch } -i #{ dpid_short } -e #{ ports } > #{ log_file } &" end end