trema 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -90,6 +90,7 @@ end
90
90
 
91
91
  * [switch_ready(datapath_id)](http://rubydoc.info/github/trema/trema/master/Trema/Controller:switch_ready)
92
92
  * [switch_disconnected(datapath_id)](http://rubydoc.info/github/trema/trema/master/Trema/Controller:switch_disconnected)
93
+ * [list_switches_reply(datapath_ids)](http://rubydoc.info/github/trema/trema/master/Trema/Controller:list_switches_reply)
93
94
  * [packet_in(datapath_id, message)](http://rubydoc.info/github/trema/trema/master/Trema/Controller:packet_in)
94
95
  * [flow_removed(datapath_id, message)](http://rubydoc.info/github/trema/trema/master/Trema/Controller:flow_removed)
95
96
  * [port_status(datapath_id, message)](http://rubydoc.info/github/trema/trema/master/Trema/Controller:port_status)
data/Rakefile CHANGED
@@ -17,16 +17,23 @@
17
17
 
18
18
 
19
19
  require "rubygems"
20
-
21
-
22
20
  require "rake"
23
21
 
22
+
24
23
  task :default do
25
24
  sh "./build.rb"
26
25
  end
27
26
 
28
27
 
29
- task :travis => [ :default, "spec:travis" ]
28
+ ################################################################################
29
+ # Maintenance Tasks
30
+ ################################################################################
31
+
32
+ # FIXME: Remove dependency to rant
33
+ desc "Generate a monolithic rant file"
34
+ task "build.rb" do
35
+ sh "rant-import --force --auto .mono.rant"
36
+ end
30
37
 
31
38
 
32
39
  begin
@@ -36,6 +43,13 @@ rescue LoadError
36
43
  end
37
44
 
38
45
 
46
+ ################################################################################
47
+ # Tests
48
+ ################################################################################
49
+
50
+ task :travis => [ :default, "spec:travis" ]
51
+
52
+
39
53
  begin
40
54
  require "rspec/core"
41
55
  require "rspec/core/rake_task"
@@ -70,6 +84,18 @@ rescue LoadError
70
84
  end
71
85
 
72
86
 
87
+ ################################################################################
88
+ # Code Quality Tasks
89
+ ################################################################################
90
+
91
+ $ruby_sources = FileList[ "ruby/**/*.rb", "src/**/*.rb" ]
92
+ $quality_targets = if ENV[ "QUALITY_TARGETS" ]
93
+ ENV[ "QUALITY_TARGETS" ].split
94
+ else
95
+ $ruby_sources
96
+ end
97
+
98
+
73
99
  desc "Enforce Ruby code quality with static analysis of code"
74
100
  task :quality => [ :reek, :roodi, :flog, :flay ]
75
101
 
@@ -82,7 +108,7 @@ begin
82
108
  t.verbose = false
83
109
  t.ruby_opts = [ "-rubygems" ]
84
110
  t.reek_opts = "--quiet"
85
- t.source_files = "ruby/**/*.rb"
111
+ t.source_files = $quality_targets
86
112
  end
87
113
  rescue LoadError
88
114
  $stderr.puts $!.to_s
@@ -95,7 +121,7 @@ begin
95
121
 
96
122
  RoodiTask.new do | t |
97
123
  t.verbose = false
98
- t.patterns = %w(ruby/**/*.rb spec/**/*.rb features/**/*.rb)
124
+ t.patterns = $quality_targets
99
125
  end
100
126
  rescue LoadError
101
127
  $stderr.puts $!.to_s
@@ -108,7 +134,7 @@ begin
108
134
  desc "Analyze for code complexity"
109
135
  task :flog do
110
136
  flog = Flog.new( :continue => true )
111
- flog.flog [ "ruby" ]
137
+ flog.flog $quality_targets
112
138
  threshold = 10
113
139
 
114
140
  bad_methods = flog.totals.select do | name, score |
@@ -133,7 +159,9 @@ begin
133
159
  require "flay_task"
134
160
 
135
161
  FlayTask.new do | t |
136
- t.dirs = %w( ruby )
162
+ t.dirs = $ruby_sources.collect do | each |
163
+ each[ /[^\/]+/ ]
164
+ end.uniq
137
165
  t.threshold = 0
138
166
  t.verbose = true
139
167
  end
@@ -142,66 +170,17 @@ rescue LoadError
142
170
  end
143
171
 
144
172
 
145
- desc "Generate a monolithic rant file"
146
- task "build.rb" do
147
- sh "rant-import --force --auto .mono.rant"
148
- end
149
-
173
+ ################################################################################
174
+ # YARD
175
+ ################################################################################
150
176
 
151
177
  begin
152
178
  require "yard"
153
179
 
154
180
  YARD::Rake::YardocTask.new do | t |
155
- t.files = [ "ruby/trema/**/*.c", "ruby/trema/**/*.rb" ]
156
- t.options = [ "--no-private" ]
157
- t.options << "--debug" << "--verbose" if $trace
158
- end
159
-
160
- yardoc_i18n = "./vendor/yard.i18n/bin/yardoc"
161
-
162
- namespace :yard do
163
- desc "Generate YARD Documentation in Japanese"
164
- task :ja => "yard:po" do
165
- sh "#{ yardoc_i18n } --language ja ruby/trema"
166
- end
167
- end
168
-
169
- locale_base_dir = "locale"
170
- locale_dir = "#{ locale_base_dir }/ja"
171
- pot = "#{ locale_base_dir }/yard.pot"
172
- po = "#{ locale_dir }/yard.po"
173
-
174
- namespace :yard do
175
- desc "generate .pot file"
176
- task :pot => pot
177
-
178
- desc "Generate .po file"
179
- task :po => po
180
-
181
- file pot => FileList[ "ruby/trema/**/*.rb", "ruby/trema/**/*.c" ] do
182
- Rake::Task[ "yard:pot:generate" ].invoke
183
- end
184
-
185
- namespace :pot do
186
- task :generate do
187
- sh( yardoc_i18n, "--no-yardopts", "--output", locale_base_dir, "--format", "pot", "ruby/trema" )
188
- end
189
- end
190
-
191
- directory locale_dir
192
- file po => [ locale_dir, pot ] do
193
- Rake::Task[ "yard:po:generate" ].invoke
194
- end
195
-
196
- namespace :po do
197
- task :generate do
198
- if File.exist?( po )
199
- sh( "msgmerge", "--update", "--sort-by-file", po, pot )
200
- else
201
- sh( "msginit", "--input", pot, "--output", po, "--locale", "ja.UTF-8" )
202
- end
203
- end
204
- end
181
+ t.files = [ "ruby/trema/**/*.c", "ruby/trema/**/*.rb" ]
182
+ t.options = [ "--no-private" ]
183
+ t.options << "--debug" << "--verbose" if $trace
205
184
  end
206
185
  rescue LoadError
207
186
  $stderr.puts $!.to_s
data/bin/quality ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (C) 2008-2012 NEC Corporation
4
+ #
5
+ # This program is free software; you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License, version 2, as
7
+ # published by the Free Software Foundation.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License along
15
+ # with this program; if not, write to the Free Software Foundation, Inc.,
16
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
+ #
18
+
19
+
20
+ if ARGV.empty?
21
+ system "rake quality"
22
+ else
23
+ system %Q{rake quality QUALITY_TARGETS="#{ ARGV.join ' ' }"}
24
+ end
25
+
26
+
27
+ ### Local variables:
28
+ ### mode: Ruby
29
+ ### coding: utf-8-unix
30
+ ### indent-tabs-mode: nil
31
+ ### End:
@@ -0,0 +1,35 @@
1
+ Feature: Send a features request message
2
+
3
+ In order to get the list of switch features
4
+ As a Trema user
5
+ I want to send a features request message to openflow switches
6
+
7
+ Background:
8
+ Given a file named "features_request.conf" with:
9
+ """
10
+ vswitch( "features_request" ) { datapath_id "0xabc" }
11
+ """
12
+
13
+ @slow_process
14
+ Scenario: Features Request message in C
15
+ When I run `trema run ../../objects/examples/openflow_message/features_request -c features_request.conf -d`
16
+ And wait until "features_request" is up
17
+ And I run `trema killall`
18
+ Then the file "../../tmp/log/features_request.log" should match /datapath_id: 0xabc/
19
+ And the file "../../tmp/log/features_request.log" should match /n_buffers:/
20
+ And the file "../../tmp/log/features_request.log" should match /n_tables:/
21
+ And the file "../../tmp/log/features_request.log" should match /capabilities:/
22
+ And the file "../../tmp/log/features_request.log" should match /actions:/
23
+ And the file "../../tmp/log/features_request.log" should match /ports:/
24
+
25
+ @slow_process
26
+ Scenario: Feature Request message in Ruby
27
+ When I run `trema run ../../src/examples/openflow_message/features-request.rb -c features_request.conf -d`
28
+ And wait until "FeaturesRequestController" is up
29
+ And I run `trema killall`
30
+ Then the file "../../tmp/log/FeaturesRequestController.log" should match /datapath_id: 0xabc/
31
+ And the file "../../tmp/log/FeaturesRequestController.log" should match /n_buffers:/
32
+ And the file "../../tmp/log/FeaturesRequestController.log" should match /n_tables:/
33
+ And the file "../../tmp/log/FeaturesRequestController.log" should match /capabilities:/
34
+ And the file "../../tmp/log/FeaturesRequestController.log" should match /actions:/
35
+ And the file "../../tmp/log/FeaturesRequestController.log" should match /ports:/
data/ruby/extconf.rb CHANGED
@@ -71,6 +71,7 @@ EOF
71
71
  end
72
72
 
73
73
 
74
+ $CFLAGS << " -Werror" # must be added after find_library
74
75
  create_makefile "trema", "trema"
75
76
 
76
77
 
@@ -62,6 +62,18 @@ module Trema
62
62
  handler :switch_disconnected
63
63
 
64
64
 
65
+
66
+ #
67
+ # @!method list_switches_reply( datapath_ids )
68
+ #
69
+ # @abstract List Switches Reply message handler. Override this to implement a custom handler.
70
+ #
71
+ # @param [Array<Integer>] datapath_ids
72
+ # the datapath IDs of connected OpenFlow switches.
73
+ #
74
+ handler :list_switches_reply
75
+
76
+
65
77
  #
66
78
  # @!method packet_in( datapath_id, message )
67
79
  #
@@ -266,7 +266,7 @@ stats_vendor_id( VALUE self ) {
266
266
 
267
267
  uint32_t
268
268
  get_stats_request_num2uint( VALUE self, const char *field ) {
269
- return NUM2UINT( rb_iv_get( self, field ) );
269
+ return ( uint32_t ) NUM2UINT( rb_iv_get( self, field ) );
270
270
  }
271
271
 
272
272
 
data/ruby/trema/switch.c CHANGED
@@ -16,13 +16,14 @@
16
16
  */
17
17
 
18
18
 
19
- #include "chibach.h"
20
19
  #include "flow-mod.h"
21
20
  #include "logger.h"
22
21
  #include "ruby.h"
23
22
  #include "rubysig.h"
24
23
  #include "switch.h"
25
24
 
25
+ #include "chibach.h" // must be included after ruby.h for undef ruby's xmalloc
26
+
26
27
 
27
28
  VALUE mTrema;
28
29
  VALUE cSwitch;
data/ruby/trema/vendor.c CHANGED
@@ -207,7 +207,7 @@ handle_vendor(
207
207
 
208
208
  if ( data != NULL && data->length > 0 ) {
209
209
  VALUE data_array = rb_ary_new2( ( long ) data->length );
210
- long i;
210
+ size_t i;
211
211
  for ( i = 0; i < data->length; i++ ) {
212
212
  rb_ary_push( data_array, INT2FIX( ( ( uint8_t * ) data->data)[ i ] ) );
213
213
  }
@@ -17,7 +17,7 @@
17
17
 
18
18
 
19
19
  module Trema
20
- VERSION = "0.3.0"
20
+ VERSION = "0.3.1"
21
21
  end
22
22
 
23
23
 
@@ -57,7 +57,7 @@ module Trema
57
57
  vswitch { datapath_id 0xabc }
58
58
  }.run( FlowModAddController ) {
59
59
  controller( "FlowModAddController" ).send_flow_mod_add( 0xabc )
60
- sleep 6 # FIXME: wait to send_flow_mod_add
60
+ sleep 20 # FIXME: wait to send_flow_mod_add
61
61
  vswitch( "0xabc" ).should have( 1 ).flows
62
62
  }
63
63
  end
@@ -67,7 +67,7 @@ describe SetEthDstAddr, ".new( VALID OPTION )" do
67
67
  0xabc,
68
68
  :actions => SetEthDstAddr.new( "52:54:00:a8:ad:8c" )
69
69
  )
70
- sleep 6 # FIXME: wait to send_flow_mod
70
+ sleep 20 # FIXME: wait to send_flow_mod
71
71
  vswitch( "0xabc" ).should have( 1 ).flows
72
72
  vswitch( "0xabc" ).flows[0].actions.should match( /mod_dl_dst:52:54:00:a8:ad:8c/ )
73
73
  }
@@ -64,7 +64,7 @@ describe SetEthSrcAddr, ".new( VALID OPTION )" do
64
64
  vswitch { datapath_id 0xabc }
65
65
  }.run( FlowModAddController ) {
66
66
  controller( "FlowModAddController" ).send_flow_mod_add( 0xabc, :actions => SetEthSrcAddr.new( "52:54:00:a8:ad:8c" ) )
67
- sleep 6 # FIXME: wait to send_flow_mod
67
+ sleep 20 # FIXME: wait to send_flow_mod
68
68
  vswitch( "0xabc" ).should have( 1 ).flows
69
69
  vswitch( "0xabc" ).flows[0].actions.should match( /mod_dl_src:52:54:00:a8:ad:8c/ )
70
70
  }
@@ -2,8 +2,6 @@
2
2
  # A test example program to send a OFPT_FEATURES_REQUEST message and print
3
3
  # the reply.
4
4
  #
5
- # Author: Nick Karanatsios <nickkaranatsios@gmail.com>
6
- #
7
5
  # Copyright (C) 2008-2012 NEC Corporation
8
6
  #
9
7
  # This program is free software; you can redistribute it and/or modify
@@ -75,16 +73,17 @@ class FeaturesRequestController < Controller
75
73
 
76
74
 
77
75
  def print_ports ports
78
- ports.each do | port |
79
- info "port_no: %u" % port.number
80
- info " hw_addr = #{ port.hw_addr.to_s }"
81
- info " name = #{ port.name }"
82
- info " config = #{ port.config.to_hex }"
83
- info " state = #{ port.state.to_hex }"
84
- info " curr = #{ port.curr.to_hex }"
85
- info " advertised = #{ port.advertised.to_hex }"
86
- info " supported = #{ port.supported.to_hex }"
87
- info " peer = #{ port.peer.to_hex }"
76
+ info "ports:"
77
+ ports.each do | each |
78
+ info " port_no: %u" % each.number
79
+ info " hw_addr = #{ each.hw_addr.to_s }"
80
+ info " name = #{ each.name }"
81
+ info " config = #{ each.config.to_hex }"
82
+ info " state = #{ each.state.to_hex }"
83
+ info " curr = #{ each.curr.to_hex }"
84
+ info " advertised = #{ each.advertised.to_hex }"
85
+ info " supported = #{ each.supported.to_hex }"
86
+ info " peer = #{ each.peer.to_hex }"
88
87
  end
89
88
  end
90
89
  end
@@ -1,8 +1,6 @@
1
1
  /*
2
2
  * Sends a features request message.
3
3
  *
4
- * Author: Shin-ya Zenke, Yasuhito Takamiya <yasuhito@gmail.com>
5
- *
6
4
  * Copyright (C) 2008-2012 NEC Corporation
7
5
  *
8
6
  * This program is free software; you can redistribute it and/or modify
@@ -108,13 +106,14 @@ handle_features_reply(
108
106
  info( " OFPAT_VENDOR" );
109
107
  }
110
108
 
109
+ info( "ports:" );
111
110
  list_element ports_list;
112
111
  memcpy( &ports_list, phy_ports, sizeof( list_element ) );
113
112
  for ( list_element *port = &ports_list; port != NULL; port = port->next ) {
114
113
  struct ofp_phy_port *phy_port = port->data;
115
- info( "port_no: %u", phy_port->port_no );
114
+ info( " port_no: %u", phy_port->port_no );
116
115
  info(
117
- " hw_addr = %02x:%02x:%02x:%02x:%02x:%02x",
116
+ " hw_addr = %02x:%02x:%02x:%02x:%02x:%02x",
118
117
  phy_port->hw_addr[ 0 ],
119
118
  phy_port->hw_addr[ 1 ],
120
119
  phy_port->hw_addr[ 2 ],
@@ -122,13 +121,13 @@ handle_features_reply(
122
121
  phy_port->hw_addr[ 4 ],
123
122
  phy_port->hw_addr[ 5 ]
124
123
  );
125
- info( " name = %s", phy_port->name );
126
- info( " config = %#" PRIx32 "", phy_port->config );
127
- info( " state = %#" PRIx32 "", phy_port->state );
128
- info( " curr = %#" PRIx32 "", phy_port->curr );
129
- info( " advertised = %#" PRIx32 "", phy_port->advertised );
130
- info( " supported = %#" PRIx32 "", phy_port->supported );
131
- info( " peer = %#" PRIx32 "", phy_port->peer );
124
+ info( " name = %s", phy_port->name );
125
+ info( " config = %#" PRIx32 "", phy_port->config );
126
+ info( " state = %#" PRIx32 "", phy_port->state );
127
+ info( " curr = %#" PRIx32 "", phy_port->curr );
128
+ info( " advertised = %#" PRIx32 "", phy_port->advertised );
129
+ info( " supported = %#" PRIx32 "", phy_port->supported );
130
+ info( " peer = %#" PRIx32 "", phy_port->peer );
132
131
  }
133
132
  }
134
133
 
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: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
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-01-07 00:00:00 Z
18
+ date: 2013-01-15 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  prerelease: false
@@ -110,6 +110,7 @@ files:
110
110
  - README.md
111
111
  - Rakefile
112
112
  - Rantfile
113
+ - bin/quality
113
114
  - bin/trema
114
115
  - bin/trema-config
115
116
  - build.rb
@@ -118,11 +119,11 @@ files:
118
119
  - features/example.hello_trema.feature
119
120
  - features/example.learning_switch.feature
120
121
  - features/example.list_switches.feature
121
- - features/example.message.features_request.feature
122
122
  - features/example.message.set_config.feature
123
123
  - features/example.message.vendor-action.feature
124
124
  - features/example.multi_learning_switch.feature
125
125
  - features/example.openflow_message.echo.feature
126
+ - features/example.openflow_message.features_request.feature
126
127
  - features/example.openflow_message.hello.feature
127
128
  - features/example.packet_in.feature
128
129
  - features/example.packetin_filter_config.feature
@@ -1,85 +0,0 @@
1
- Feature: Send a features request message
2
-
3
- As a Trema user
4
- I want to send a features request message to openflow switches
5
- So that I can get the list of switch features
6
-
7
- @wip
8
- Scenario: Send a features request
9
- When I try trema run "./objects/examples/openflow_message/features_request" with following configuration (backgrounded):
10
- """
11
- vswitch( "features_request" ) { datapath_id "0xabc" }
12
- """
13
- And wait until "features_request" is up
14
- And I run `trema killall`
15
- Then the output should include:
16
- """
17
- datapath_id: 0xabc
18
- n_buffers: 256
19
- n_tables: 1
20
- capabilities:
21
- OFPC_FLOW_STATS
22
- OFPC_TABLE_STATS
23
- OFPC_PORT_STATS
24
- OFPC_ARP_MATCH_IP
25
- actions:
26
- OFPAT_OUTPUT
27
- OFPAT_SET_VLAN_VID
28
- OFPAT_SET_VLAN_PCP
29
- OFPAT_STRIP_VLAN
30
- OFPAT_SET_DL_SRC
31
- OFPAT_SET_DL_DST
32
- OFPAT_SET_NW_SRC
33
- OFPAT_SET_NW_DST
34
- OFPAT_SET_NW_TOS
35
- OFPAT_SET_TP_SRC
36
- OFPAT_SET_TP_DST
37
- port_no: 65534
38
- name = vsw_0xabc
39
- config = 0x1
40
- state = 0x1
41
- curr = 0x82
42
- advertised = 0
43
- supported = 0
44
- peer = 0
45
- """
46
-
47
- @wip
48
- Scenario: Send a features request in Ruby
49
- When I try trema run "./src/examples/openflow_message/features-request.rb" with following configuration (backgrounded):
50
- """
51
- vswitch( "features-request" ) { datapath_id "0xabc" }
52
- """
53
- And wait until "FeaturesRequestController" is up
54
- And I run `trema killall`
55
- Then the output should include:
56
- """
57
- datapath_id: 0xabc
58
- n_buffers: 256
59
- n_tables: 1
60
- capabilities:
61
- OFPC_FLOW_STATS
62
- OFPC_TABLE_STATS
63
- OFPC_PORT_STATS
64
- OFPC_ARP_MATCH_IP
65
- actions:
66
- OFPAT_OUTPUT
67
- OFPAT_SET_VLAN_VID
68
- OFPAT_SET_VLAN_PCP
69
- OFPAT_STRIP_VLAN
70
- OFPAT_SET_DL_SRC
71
- OFPAT_SET_DL_DST
72
- OFPAT_SET_NW_SRC
73
- OFPAT_SET_NW_DST
74
- OFPAT_SET_NW_TOS
75
- OFPAT_SET_TP_SRC
76
- OFPAT_SET_TP_DST
77
- port_no: 65534
78
- name = vsw_0xabc
79
- config = 0x1
80
- state = 0x1
81
- curr = 0x82
82
- advertised = 0x0
83
- supported = 0x0
84
- peer = 0x0
85
- """