Skip to content

Commit

Permalink
fix issue#28 to allow multiple trema switches to be started
Browse files Browse the repository at this point in the history
  • Loading branch information
nickkaranatsios committed Apr 10, 2013
1 parent f8dd50d commit 4fb1976
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
13 changes: 7 additions & 6 deletions ruby/trema/dsl/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion ruby/trema/dsl/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
11 changes: 10 additions & 1 deletion ruby/trema/trema-switch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4fb1976

Please sign in to comment.