trema 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Rantfile +15 -2
- data/bin/trema +17 -0
- data/features/.nav +3 -0
- data/features/handlers/switch_ready.feature +40 -0
- data/features/trema_commands/port_down.feature +70 -0
- data/ruby/trema/command.rb +1 -0
- data/ruby/trema/command/port_down.rb +43 -0
- data/ruby/trema/ofctl.rb +5 -0
- data/ruby/trema/open-vswitch.rb +5 -0
- data/ruby/trema/version.rb +1 -1
- metadata +7 -4
data/Rantfile
CHANGED
@@ -25,6 +25,7 @@ $LOAD_PATH.unshift File.expand_path( File.join File.dirname( __FILE__ ), "vendor
|
|
25
25
|
require "trema/executables"
|
26
26
|
require "trema/path"
|
27
27
|
require "trema/dsl/parser"
|
28
|
+
require "trema/version"
|
28
29
|
|
29
30
|
import "c/dependencies"
|
30
31
|
import "directedrule"
|
@@ -366,7 +367,7 @@ end
|
|
366
367
|
|
367
368
|
|
368
369
|
################################################################################
|
369
|
-
# Build libtrema.a
|
370
|
+
# Build libtrema.{a,so}
|
370
371
|
################################################################################
|
371
372
|
|
372
373
|
build_libtrema_a = Proc.new do | t |
|
@@ -375,6 +376,11 @@ build_libtrema_a = Proc.new do | t |
|
|
375
376
|
sys "ranlib #{ t.name }"
|
376
377
|
end
|
377
378
|
|
379
|
+
build_libtrema_so = Proc.new do | t |
|
380
|
+
soname = File.basename( t.name ).sub( /\.\d+\.\d+\Z/, "" )
|
381
|
+
sys "gcc -shared -Wl,-soname=#{ soname } -o #{ t.name } #{ sys.sp t.prerequisites }"
|
382
|
+
end
|
383
|
+
|
378
384
|
|
379
385
|
task dependency( "libtrema" ) => "vendor:openflow"
|
380
386
|
gen C::Dependencies, dependency( "libtrema" ),
|
@@ -390,6 +396,7 @@ gen Directory, Trema.lib
|
|
390
396
|
gen Directory, "#{ Trema.home }/objects/unittests"
|
391
397
|
|
392
398
|
libtrema = File.join( Trema.lib, "libtrema.a" )
|
399
|
+
libtrema_so = File.join( Trema.lib, "libtrema.so." ) + Trema::VERSION
|
393
400
|
libtrema_gcov = File.join( "#{ Trema.home }/objects/unittests", "libtrema.a" )
|
394
401
|
|
395
402
|
libtrema_o = gen DirectedRule, Trema.lib => [ Trema.include ], :o => :c do | t |
|
@@ -399,12 +406,18 @@ libtrema_gcov_o = gen DirectedRule, "#{ Trema.home }/objects/unittests" => [ Tre
|
|
399
406
|
sys "gcc --coverage -I#{ objects "openflow" } #{ var :CFLAGS } -fPIC -c -o #{ t.name } #{ t.source }"
|
400
407
|
end
|
401
408
|
|
402
|
-
desc "Build trema library."
|
409
|
+
desc "Build trema library (static library)."
|
403
410
|
task :libtrema => libtrema
|
404
411
|
file libtrema => libtrema_o.candidates do | t |
|
405
412
|
build_libtrema_a.call t
|
406
413
|
end
|
407
414
|
|
415
|
+
desc "Build trema library (shared library)."
|
416
|
+
task :libtrema_so => libtrema_so
|
417
|
+
file libtrema_so => libtrema_o.candidates do | t |
|
418
|
+
build_libtrema_so.call t
|
419
|
+
end
|
420
|
+
|
408
421
|
desc "Build trema library (coverage)."
|
409
422
|
task "coverage:libtrema" => libtrema_gcov
|
410
423
|
file libtrema_gcov => libtrema_gcov_o.candidates do | t |
|
data/bin/trema
CHANGED
@@ -148,6 +148,23 @@ command :send_packets do | c |
|
|
148
148
|
end
|
149
149
|
|
150
150
|
|
151
|
+
desc "Brings a switch's specified port down"
|
152
|
+
command :port_down do | c |
|
153
|
+
c.desc "switch name"
|
154
|
+
c.flag [ :s, :switch ]
|
155
|
+
|
156
|
+
c.desc "port"
|
157
|
+
c.flag [ :p, :port ]
|
158
|
+
|
159
|
+
c.action do | global_options, options, args |
|
160
|
+
raise "--switch option is mandatory" if options[ :switch ].nil?
|
161
|
+
raise "--port option is mandatory" if options[ :port ].nil?
|
162
|
+
|
163
|
+
trema_port_down options[ :switch ], options[ :port ]
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
|
151
168
|
desc "Shows stats of packets"
|
152
169
|
arg_name "host"
|
153
170
|
command :show_stats do | c |
|
data/features/.nav
CHANGED
@@ -6,6 +6,7 @@
|
|
6
6
|
- up.feature
|
7
7
|
- killall.feature
|
8
8
|
- send_packets.feature
|
9
|
+
- port_down.feature
|
9
10
|
- show_stats.feature
|
10
11
|
- reset_stats.feature
|
11
12
|
- dump_flows.feature
|
@@ -28,6 +29,8 @@
|
|
28
29
|
- message.set_config.feature
|
29
30
|
- message.vendor-action.feature
|
30
31
|
- packetin_filter_config.feature
|
32
|
+
- handlers:
|
33
|
+
- switch_ready.feature
|
31
34
|
- core:
|
32
35
|
- switch_manager.feature
|
33
36
|
- packetin_filter.feature
|
@@ -0,0 +1,40 @@
|
|
1
|
+
Feature: switch_ready handler
|
2
|
+
|
3
|
+
The switch-ready is a message indicating a successful connection
|
4
|
+
established between a switch and your controller. If one wishes to
|
5
|
+
detect the connection-establishment event one must implement the
|
6
|
+
:switch_ready method in the controller class.
|
7
|
+
|
8
|
+
Note that the switch-ready message is not part of the OpenFlow spec,
|
9
|
+
but is a Trema-specific message. Internally, Trema::Controller
|
10
|
+
executes the following steps to emulate the switch-ready message.
|
11
|
+
|
12
|
+
1. Upon connection establishment with the switch a Hello message is
|
13
|
+
sent that completes a version negotiation sequence.
|
14
|
+
2. A Feature-Request message is sent awaiting for a Features-Reply
|
15
|
+
message from the switch.
|
16
|
+
3. Switch's state and flow tables are cleared/initialized to ensure
|
17
|
+
further correct operation.
|
18
|
+
4. Trema::Controller redirects a :switch_ready message to itself
|
19
|
+
with the switch's datapath-ID as its argument.
|
20
|
+
|
21
|
+
As Trema performs the above steps in the background, users are
|
22
|
+
unaware of such details. Users only need to handle the switch-ready
|
23
|
+
message.
|
24
|
+
|
25
|
+
@slow_process
|
26
|
+
Scenario: switch_ready handler
|
27
|
+
Given a file named "switch-ready-detector.rb" with:
|
28
|
+
"""
|
29
|
+
class SwitchReadyDetector < Controller
|
30
|
+
def switch_ready datapath_id
|
31
|
+
info "Switch #{ datapath_id.to_hex } is UP"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
"""
|
35
|
+
And a file named "sample.conf" with:
|
36
|
+
"""
|
37
|
+
vswitch { datapath_id "0xabc" }
|
38
|
+
"""
|
39
|
+
When I run `trema run ./switch-ready-detector.rb -c sample.conf` interactively
|
40
|
+
Then the output should contain "Switch 0xabc is UP" within the timeout period
|
@@ -0,0 +1,70 @@
|
|
1
|
+
Feature: port_down command
|
2
|
+
|
3
|
+
Use this command to ensure that your controller detects network
|
4
|
+
topology changes i.e., failures in switches.
|
5
|
+
|
6
|
+
Trema emulated network offers a set of commands that can change the
|
7
|
+
status of any arbitrary switch port. The `trema port_down` is one
|
8
|
+
such command and its command syntax is as follows:
|
9
|
+
|
10
|
+
$ trema port_down --switch DATAPATH_ID --port PORT_NUMBER
|
11
|
+
|
12
|
+
The above command brings the switch's specified port down. By using
|
13
|
+
this command one can easily test the :port_status handler defined in
|
14
|
+
controllers.
|
15
|
+
|
16
|
+
Background:
|
17
|
+
Given a file named "sample.conf" with:
|
18
|
+
"""
|
19
|
+
vswitch { datapath_id 0x1 }
|
20
|
+
vswitch { datapath_id 0x2 }
|
21
|
+
|
22
|
+
link "0x1", "0x2"
|
23
|
+
"""
|
24
|
+
And a file named "port-observer.rb" with:
|
25
|
+
"""
|
26
|
+
class PortObserver < Controller
|
27
|
+
def switch_ready dpid
|
28
|
+
info "Switch %#x is UP", dpid
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def port_status dpid, message
|
33
|
+
if message.phy_port.down?
|
34
|
+
info "Port #{ message.phy_port.number } (Switch %#x) is DOWN", dpid
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
"""
|
39
|
+
|
40
|
+
@slow_process
|
41
|
+
Scenario: trema port_down --switch 0x1 --port 1
|
42
|
+
Given I run `trema run ./port-observer.rb -c sample.conf` interactively
|
43
|
+
And I wait for output to contain "Switch 0x1 is UP"
|
44
|
+
When I run `trema port_down --switch 0x1 --port 1`
|
45
|
+
Then the output should contain "Port 1 (Switch 0x1) is DOWN" within the timeout period
|
46
|
+
|
47
|
+
@slow_process
|
48
|
+
Scenario: trema port_down --switch UNKNOWN --port 1 (unknown switch error)
|
49
|
+
Given I run `trema run ./port-observer.rb -c sample.conf -d`
|
50
|
+
When I run `trema port_down --switch UNKNOWN --port 1`
|
51
|
+
Then the output should contain "error: unknown switch: UNKNOWN"
|
52
|
+
|
53
|
+
@slow_process
|
54
|
+
Scenario: trema port_down --switch 0x1 --port 100 (unknown port error)
|
55
|
+
Given I run `trema run ./port-observer.rb -c sample.conf -d`
|
56
|
+
When I run `trema port_down --switch 0x1 --port 100`
|
57
|
+
Then the output should contain "error: ovs-ofctl: vsw_0x1: couldn't find port `100'"
|
58
|
+
|
59
|
+
@slow_process
|
60
|
+
Scenario: trema port_down --switch 0x1 (no --port option error)
|
61
|
+
Given I run `trema run ./port-observer.rb -c sample.conf -d`
|
62
|
+
When I run `trema port_down --switch 0x1`
|
63
|
+
Then the output should contain "error: --port option is mandatory"
|
64
|
+
|
65
|
+
@slow_process
|
66
|
+
Scenario: trema port_down --port 1 (no --switch option error)
|
67
|
+
Given I run `trema run ./port-observer.rb -c sample.conf -d`
|
68
|
+
When I run `trema port_down --port 1`
|
69
|
+
Then the output should contain "error: --switch option is mandatory"
|
70
|
+
|
data/ruby/trema/command.rb
CHANGED
@@ -22,6 +22,7 @@ require "trema/command/dump_flows"
|
|
22
22
|
require "trema/command/kill"
|
23
23
|
require "trema/command/killall"
|
24
24
|
require "trema/command/netns"
|
25
|
+
require "trema/command/port_down"
|
25
26
|
require "trema/command/reset_stats"
|
26
27
|
require "trema/command/ruby"
|
27
28
|
require "trema/command/run"
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2008-2012 NEC Corporation
|
3
|
+
#
|
4
|
+
# This program is free software; you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License, version 2, as
|
6
|
+
# published by the Free Software Foundation.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License along
|
14
|
+
# with this program; if not, write to the Free Software Foundation, Inc.,
|
15
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
16
|
+
#
|
17
|
+
|
18
|
+
|
19
|
+
require "trema/cli"
|
20
|
+
require "trema/util"
|
21
|
+
|
22
|
+
|
23
|
+
module Trema
|
24
|
+
module Command
|
25
|
+
include Trema::Util
|
26
|
+
|
27
|
+
|
28
|
+
def trema_port_down switch_name, port
|
29
|
+
switch = find_switch_by_name( switch_name )
|
30
|
+
raise "unknown switch: #{ switch_name }" if switch.nil?
|
31
|
+
|
32
|
+
error = switch.bring_port_down( port.to_i )
|
33
|
+
raise error if $?.exitstatus != 0
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
### Local variables:
|
40
|
+
### mode: Ruby
|
41
|
+
### coding: utf-8
|
42
|
+
### indent-tabs-mode: nil
|
43
|
+
### End:
|
data/ruby/trema/ofctl.rb
CHANGED
@@ -51,6 +51,11 @@ module Trema
|
|
51
51
|
def dump_flows switch
|
52
52
|
`sudo #{ Executables.ovs_ofctl } dump-flows #{ switch.network_device } 2>&1`
|
53
53
|
end
|
54
|
+
|
55
|
+
|
56
|
+
def bring_port_down switch, port_number
|
57
|
+
`sudo #{ Executables.ovs_ofctl } mod-port #{ switch.network_device } #{ port_number } down 2>&1`
|
58
|
+
end
|
54
59
|
end
|
55
60
|
end
|
56
61
|
|
data/ruby/trema/open-vswitch.rb
CHANGED
@@ -97,6 +97,11 @@ module Trema
|
|
97
97
|
end
|
98
98
|
|
99
99
|
|
100
|
+
def bring_port_down port_number
|
101
|
+
Ofctl.new.bring_port_down self, port_number
|
102
|
+
end
|
103
|
+
|
104
|
+
|
100
105
|
############################################################################
|
101
106
|
private
|
102
107
|
############################################################################
|
data/ruby/trema/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 7
|
10
|
+
version: 0.3.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Yasuhito Takamiya
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: .
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-02-
|
18
|
+
date: 2013-02-06 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
prerelease: false
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- features/examples/repeater_hub.feature
|
151
151
|
- features/examples/switch_info.feature
|
152
152
|
- features/examples/switch_monitor.feature
|
153
|
+
- features/handlers/switch_ready.feature
|
153
154
|
- features/step_definitions/misc_steps.rb
|
154
155
|
- features/step_definitions/send_packets_steps.rb
|
155
156
|
- features/step_definitions/stats_steps.rb
|
@@ -161,6 +162,7 @@ files:
|
|
161
162
|
- features/trema_commands/help_option.feature
|
162
163
|
- features/trema_commands/kill.feature
|
163
164
|
- features/trema_commands/killall.feature
|
165
|
+
- features/trema_commands/port_down.feature
|
164
166
|
- features/trema_commands/reset_stats.feature
|
165
167
|
- features/trema_commands/run.feature
|
166
168
|
- features/trema_commands/send_packets.feature
|
@@ -187,6 +189,7 @@ files:
|
|
187
189
|
- ruby/trema/command/kill.rb
|
188
190
|
- ruby/trema/command/killall.rb
|
189
191
|
- ruby/trema/command/netns.rb
|
192
|
+
- ruby/trema/command/port_down.rb
|
190
193
|
- ruby/trema/command/reset_stats.rb
|
191
194
|
- ruby/trema/command/ruby.rb
|
192
195
|
- ruby/trema/command/run.rb
|