Browse files

Fix broken .feature of learning-switch.

  • Loading branch information...
1 parent 03486f8 commit 158b7f3b2f170f5c1e2482d9e72345098655b24c @yasuhito yasuhito committed Apr 16, 2013
View
3 Gemfile
@@ -6,8 +6,9 @@ gem "paper-house", "~> 0.1.13"
group :development do
+ gem "aruba", "~> 0.5.1"
gem "coveralls", require: false
- gem "cucumber", "~> 1.2.3"
+ gem "cucumber", "~> 1.2.5"
gem "flay", "~> 2.1.0"
gem "flog", "~> 3.2.2"
gem "reek", "~> 1.3.1"
View
52 features/example.learning_switch.feature
@@ -4,39 +4,25 @@ Feature: control one openflow switch using learning-switch controller
I want to control one openflow switch using learning-switch controller
So that I can send and receive packets
+ Background:
+ Given I cd to "../../src/examples/learning_switch/"
- @announce
- Scenario: Send and receive packets (in Ruby)
- Given I try trema run "learning-switch.rb" example with following configuration (backgrounded):
- """
- trema_switch("learning") { datapath_id "0xabc" }
-
- vhost("host1")
- vhost("host2")
-
- link "learning", "host1"
- link "learning", "host2"
- """
+ @slow_process
+ Scenario: Run the Ruby example
+ Given I run `trema run ./learning-switch.rb -c sample.conf -d`
+ And wait until "LearningSwitch" is up
When I send 1 packet from host1 to host2
- And I try to run "./trema show_stats host1 --tx" (log = "host1.LearningSwitch.log")
- And I try to run "./trema show_stats host2 --rx" (log = "host2.LearningSwitch.log")
- Then the content of "host1.LearningSwitch.log" and "host2.LearningSwitch.log" should be identical
-
- @wip
- Scenario: Send and receive packets
- Given I try trema run "learning_switch" example with following configuration (backgrounded):
- """
- trema_switch("learning") { datapath_id "0xabc" }
-
- vhost("host1")
- vhost("host2")
-
- link "learning", "host1"
- link "learning", "host2"
- """
+ And I run `trema show_stats host1 --tx`
+ And I run `trema show_stats host2 --rx`
+ Then the output from "trema show_stats host1 --tx" should contain "192.168.0.2,1,192.168.0.1,1,1,50"
+ And the output from "trema show_stats host2 --rx" should contain "192.168.0.2,1,192.168.0.1,1,1,50"
+
+ @slow_process
+ Scenario: Run the C example
+ Given I compile "learning_switch.c" into "learning_switch"
+ And I run `trema run ./learning_switch -c sample.conf -d`
When I send 1 packet from host1 to host2
- And I try to run "./trema show_stats host1 --tx" (log = "host1.learning_switch.log")
- And I try to run "./trema show_stats host2 --rx" (log = "host2.learning_switch.log")
- Then the content of "host1.learning_switch.log" and "host2.learning_switch.log" should be identical
-
-
+ And I run `trema show_stats host1 --tx`
+ And I run `trema show_stats host2 --rx`
+ Then the output from "trema show_stats host1 --tx" should contain "192.168.0.2,1,192.168.0.1,1,1,50"
+ And the output from "trema show_stats host2 --rx" should contain "192.168.0.2,1,192.168.0.1,1,1,50"
View
8 features/step_definitions/misc_steps.rb
@@ -18,6 +18,14 @@
#
+require "aruba/cucumber"
+
+
+Given /^I compile "(.*?)" into "(.*?)"$/ do | c_source, executable |
+ run_simple "gcc #{ c_source } #{`trema-config -c -l`} -o #{ executable }", true
+end
+
+
When /^\*\*\* sleep (\d+) \*\*\*$/ do | sec |
sleep sec.to_i
end
View
2 features/step_definitions/run_steps.rb
@@ -41,7 +41,7 @@
Tempfile.open( "trema.conf" ) do | f |
f.puts config
f.flush
- run "./trema run \"#{ args }\" -c #{ f.path } #{ verbose } >> #{ @log } 2>&1"
+ run "trema run \"#{ args }\" -c #{ f.path } #{ verbose } >> #{ @log } 2>&1"
end
end
View
4 features/step_definitions/send_packets_steps.rb
@@ -19,7 +19,7 @@
When /^I send (\d+) packets from (.+) to (.+)$/ do | n_packets, host_a, host_b |
- run "./trema send_packets --source #{ host_a } --dest #{ host_b } --n_pkts #{ n_packets }"
+ run "trema send_packets --source #{ host_a } --dest #{ host_b } --n_pkts #{ n_packets }"
sleep 1 # ensure that all packets are sent
end
@@ -30,7 +30,7 @@
When /^I send packets from (.+) to (.+) \(duration = (\d+)\)$/ do | host_a, host_b, duration |
- run "./trema send_packets --source #{ host_a } --dest #{ host_b } --duration #{ duration }"
+ run "trema send_packets --source #{ host_a } --dest #{ host_b } --duration #{ duration }"
sleep 1 # ensure that all packets are sent
end
View
1 features/support/env.rb
@@ -31,6 +31,7 @@
$LOAD_PATH.unshift( File.expand_path( File.dirname( __FILE__ ) + "/../../ruby" ) )
+require "aruba/cucumber"
require "rspec"
require "tempfile"
require "trema/executables"
View
53 features/support/hooks.rb
@@ -1,8 +1,57 @@
+#
+# Copyright (C) 2008-2013 NEC Corporation
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License, version 2, as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+
+
+require "trema/path"
+
+
+def wait_until_all_pid_files_are_deleted timeout = 10
+ elapsed = 0
+ loop do
+ raise "Failed to clean up remaining processes." if elapsed > timeout
+ break if Dir.glob( File.join( Trema.pid, "*.pid" ) ).empty?
+ sleep 1
+ elapsed += 1
+ end
+ sleep 1
+end
+
+
Before do
- run "./trema killall"
+ @aruba_timeout_seconds = 10
+ run "trema killall"
+ wait_until_all_pid_files_are_deleted
+end
+
+
+Before( "@slow_process" ) do
+ @aruba_io_wait_seconds = 1
end
After do
- run "./trema killall"
+ run "trema killall"
+ wait_until_all_pid_files_are_deleted
+ processes.clear
end
+
+
+### Local variables:
+### mode: Ruby
+### coding: utf-8-unix
+### indent-tabs-mode: nil
+### End:
View
4 ruby/trema/trema-switch.rb
@@ -29,7 +29,7 @@ class TremaSwitch < NetworkComponent
log_file { | switch | "switch.#{ switch.dpid }.log" }
-
+
def initialize stanza
@stanza = stanza
TremaSwitch.add self
@@ -54,7 +54,7 @@ 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?
- "export SWITCH_HOME=`pwd`; sudo -E #{ Executables.switch } -i #{ dpid_short } -e #{ ports } > #{ log_file } &"
+ "sudo -E #{ Executables.switch } -i #{ dpid_short } -e #{ ports } > #{ log_file } &"
end
end
end
View
1 src/examples/learning_switch/.gitignore
@@ -0,0 +1 @@
+learning_switch
View
6 src/examples/learning_switch/learning-switch.rb
@@ -39,12 +39,12 @@ def start
def switch_ready datapath_id
@fdb = FDB.new
- action = SendOutPort.new( :port_number => OFPP_CONTROLLER, :max_len => OFPCML_NO_BUFFER )
- ins = ApplyAction.new( :actions => [ action ] )
+ action = SendOutPort.new( :port_number => OFPP_CONTROLLER, :max_len => OFPCML_NO_BUFFER )
+ ins = ApplyAction.new( :actions => [ action ] )
send_flow_mod_add( datapath_id,
:priority => OFP_LOW_PRIORITY,
:buffer_id => OFP_NO_BUFFER,
- :flags => OFPFF_SEND_FLOW_REM,
+ :flags => OFPFF_SEND_FLOW_REM,
:instructions => [ ins ]
)
end
View
0 ...ples/learning_switch/learning_switch.conf → src/examples/learning_switch/sample.conf
File renamed without changes.

0 comments on commit 158b7f3

Please sign in to comment.