trema 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -48,7 +48,7 @@ GEM
48
48
  sexp_processor (~> 3.0)
49
49
  ruby_parser (2.3.1)
50
50
  sexp_processor (~> 3.0)
51
- sexp_processor (3.0.10)
51
+ sexp_processor (3.1.0)
52
52
  term-ansicolor (1.0.7)
53
53
  yard (0.7.5)
54
54
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -16,6 +16,7 @@ Feature: trema help
16
16
  Available commands:
17
17
  run - runs a trema application.
18
18
  kill - terminates a trema process.
19
+ up - starts a killed trema process again.
19
20
  killall - terminates all trema processes.
20
21
  send_packets - sends UDP packets to destination host.
21
22
  show_stats - shows stats of packets.
@@ -46,7 +46,7 @@ Feature: kill a trema process with `trema kill' command
46
46
  When I try to run "./trema help kill"
47
47
  Then the output should be:
48
48
  """
49
- Usage: ./trema kill NAME [OPTIONS ...]
49
+ Usage: trema kill NAME [OPTIONS ...]
50
50
  -h, --help
51
51
  -v, --verbose
52
52
 
@@ -23,7 +23,7 @@ Feature: kill all trema processes with `trema killall' command
23
23
  When I try to run "./trema help killall"
24
24
  Then the output should be:
25
25
  """
26
- Usage: ./trema killall [OPTIONS ...]
26
+ Usage: trema killall [OPTIONS ...]
27
27
  -h, --help
28
28
  -v, --verbose
29
29
 
@@ -8,7 +8,7 @@ Feature: reset network stats with `trema reset_stats' command
8
8
  When I try to run "./trema help reset_stats"
9
9
  Then the output should be:
10
10
  """
11
- Usage: ./trema reset_stats [OPTIONS ...]
11
+ Usage: trema reset_stats [OPTIONS ...]
12
12
  -h, --help
13
13
  -v, --verbose
14
14
  """
@@ -27,7 +27,7 @@ Feature: Tutorial: Handling packet_in events example
27
27
 
28
28
 
29
29
  Scenario: Handle packet_in in Ruby
30
- When I try trema run "./src/examples/packet_in/packet_in.rb" with following configuration (backgrounded):
30
+ When I try trema run "./src/examples/packet_in/packet-in.rb" with following configuration (backgrounded):
31
31
  """
32
32
  vswitch("packet_in") { dpid "0xabc" }
33
33
 
@@ -29,6 +29,7 @@ require "trema/command/run"
29
29
  require "trema/command/send_packets"
30
30
  require "trema/command/shell"
31
31
  require "trema/command/show_stats"
32
+ require "trema/command/up"
32
33
  require "trema/command/usage"
33
34
  require "trema/command/version"
34
35
 
@@ -37,7 +37,7 @@ module Trema
37
37
  switch = Trema::DSL::Context.load_current.switches[ ARGV[ 0 ] ]
38
38
 
39
39
  options = OptionParser.new
40
- options.banner = "Usage: #{ $PROGRAM_NAME } dump_flows SWITCH [OPTIONS ...]"
40
+ options.banner = "Usage: trema dump_flows SWITCH [OPTIONS ...]"
41
41
 
42
42
  options.on( "-h", "--help" ) do
43
43
  puts options.to_s
@@ -32,7 +32,7 @@ module Trema
32
32
 
33
33
  def kill
34
34
  options = OptionParser.new
35
- options.banner = "Usage: #{ $PROGRAM_NAME } kill NAME [OPTIONS ...]"
35
+ options.banner = "Usage: trema kill NAME [OPTIONS ...]"
36
36
 
37
37
  options.on( "-h", "--help" ) do
38
38
  puts options.to_s
@@ -50,13 +50,22 @@ module Trema
50
50
  pid_file = File.join( Trema.pid, "#{ ARGV[ 0 ] }.pid" )
51
51
  if FileTest.exist?( pid_file )
52
52
  Trema::Process.read( pid_file ).kill!
53
+ return
53
54
  end
54
55
 
55
56
  host = context.hosts[ ARGV[ 0 ] ]
56
- host.shutdown! if host
57
+ if host
58
+ host.shutdown
59
+ return
60
+ end
57
61
 
58
62
  switch = context.switches[ ARGV[ 0 ] ]
59
- switch.shutdown! if switch
63
+ if switch
64
+ switch.shutdown
65
+ return
66
+ end
67
+
68
+ raise "Unknown name: #{ ARGV[ 0 ] }"
60
69
 
61
70
  # [TODO] kill a link by its name. Needs a good naming convension for link.
62
71
  end
@@ -31,7 +31,7 @@ module Trema
31
31
 
32
32
  def killall
33
33
  options = OptionParser.new
34
- options.banner = "Usage: #{ $PROGRAM_NAME } killall [OPTIONS ...]"
34
+ options.banner = "Usage: trema killall [OPTIONS ...]"
35
35
 
36
36
  options.on( "-h", "--help" ) do
37
37
  puts options.to_s
@@ -35,7 +35,7 @@ module Trema
35
35
  sanity_check
36
36
 
37
37
  options = OptionParser.new
38
- options.banner = "Usage: #{ $PROGRAM_NAME } reset_stats [OPTIONS ...]"
38
+ options.banner = "Usage: trema reset_stats [OPTIONS ...]"
39
39
 
40
40
  options.on( "-h", "--help" ) do
41
41
  puts options.to_s
@@ -30,7 +30,7 @@ module Trema
30
30
 
31
31
  def ruby
32
32
  options = OptionParser.new
33
- options.banner = "Usage: #{ $PROGRAM_NAME } ruby [OPTIONS ...]"
33
+ options.banner = "Usage: trema ruby [OPTIONS ...]"
34
34
 
35
35
  options.on( "-h", "--help" ) do
36
36
  puts options.to_s
@@ -0,0 +1,65 @@
1
+ #
2
+ # trema up command.
3
+ #
4
+ # Author: Yasuhito Takamiya <yasuhito@gmail.com>
5
+ #
6
+ # Copyright (C) 2008-2012 NEC Corporation
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License, version 2, as
10
+ # published by the Free Software Foundation.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License along
18
+ # with this program; if not, write to the Free Software Foundation, Inc.,
19
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
+ #
21
+
22
+
23
+ require "optparse"
24
+ require "trema/dsl"
25
+ require "trema/util"
26
+
27
+
28
+ module Trema
29
+ module Command
30
+ include Trema::Util
31
+
32
+
33
+ def up
34
+ options = OptionParser.new
35
+ options.banner = "Usage: trema up NAME [OPTIONS ...]"
36
+
37
+ options.on( "-h", "--help" ) do
38
+ puts options.to_s
39
+ exit 0
40
+ end
41
+ options.on( "-v", "--verbose" ) do
42
+ $verbose = true
43
+ end
44
+
45
+ options.parse! ARGV
46
+
47
+ context = Trema::DSL::Context.load_current
48
+
49
+ switch = context.switches[ ARGV[ 0 ] ]
50
+ if switch
51
+ switch.run
52
+ return
53
+ end
54
+
55
+ raise "Unknown name: #{ ARGV[ 0 ] }"
56
+ end
57
+ end
58
+ end
59
+
60
+
61
+ ### Local variables:
62
+ ### mode: Ruby
63
+ ### coding: utf-8
64
+ ### indent-tabs-mode: nil
65
+ ### End:
@@ -27,16 +27,16 @@ module Trema
27
27
 
28
28
  ARGV.clear << "--help"
29
29
  if command.nil?
30
- trema = File.basename( $PROGRAM_NAME )
31
30
  puts <<-EOL
32
- usage: #{ trema } <COMMAND> [OPTIONS ...]
31
+ usage: trema <COMMAND> [OPTIONS ...]
33
32
 
34
33
  Trema command-line tool
35
- Type '#{ trema } help <COMMAND>' for help on a specific command.
34
+ Type 'trema help <COMMAND>' for help on a specific command.
36
35
 
37
36
  Available commands:
38
37
  run - runs a trema application.
39
38
  kill - terminates a trema process.
39
+ up - starts a killed trema process again.
40
40
  killall - terminates all trema processes.
41
41
  send_packets - sends UDP packets to destination host.
42
42
  show_stats - shows stats of packets.
@@ -47,7 +47,7 @@ EOL
47
47
  elsif method_for( command )
48
48
  __send__ method_for( command )
49
49
  else
50
- STDERR.puts "Type '#{ trema } help' for usage."
50
+ STDERR.puts "Type 'trema help' for usage."
51
51
  exit false
52
52
  end
53
53
  end
data/ruby/trema/daemon.rb CHANGED
@@ -64,8 +64,13 @@ module Trema
64
64
  end
65
65
 
66
66
 
67
- def run!
67
+ def run
68
68
  raise "'#{ name }' is already running!" if running?
69
+ run!
70
+ end
71
+
72
+
73
+ def run!
69
74
  FileUtils.rm_f log_file if log_file
70
75
  command_block = self.class.class_eval do
71
76
  class_variable_get( :@@command )
@@ -87,6 +92,20 @@ module Trema
87
92
  #
88
93
  # @return [undefined]
89
94
  #
95
+ def shutdown
96
+ raise "'#{ name }' is not running!" if not running?
97
+ shutdown!
98
+ end
99
+
100
+
101
+ #
102
+ # Kills running daemon process. Errors are ignored.
103
+ #
104
+ # @example
105
+ # daemon.shutdown!
106
+ #
107
+ # @return [undefined]
108
+ #
90
109
  def shutdown!
91
110
  Trema::Process.read( pid_file, name ).kill!
92
111
  end
@@ -23,6 +23,13 @@
23
23
  class PacketinDumper < Controller
24
24
  def packet_in datapath_id, event
25
25
  puts "received a packet_in"
26
+ info "datapath_id: #{ datapath_id.to_hex }"
27
+ info "transaction_id: #{ event.transaction_id.to_hex }"
28
+ info "buffer_id: #{ event.buffer_id.to_hex }"
29
+ info "total_len: #{ event.total_len }"
30
+ info "in_port: #{ event.in_port }"
31
+ info "reason: #{ event.reason.to_hex }"
32
+ info "data: #{ event.data.unpack "H*" }"
26
33
  end
27
34
  end
28
35
 
data/trema CHANGED
@@ -30,10 +30,35 @@ require "trema/command"
30
30
  require "trema/path"
31
31
 
32
32
 
33
+ def setup_tmp
34
+ if not FileTest.writable?( Trema.tmp )
35
+ # Trema is system widely installed with gem command
36
+ sh "sudo chmod o+w -R #{ Trema.tmp }"
37
+ end
38
+
39
+ FileUtils.mkdir_p Trema.log
40
+ FileUtils.mkdir_p Trema.pid
41
+ FileUtils.mkdir_p Trema.sock
42
+ end
43
+
44
+
33
45
  def method_for command
46
+ case command
47
+ when "version", "-V", "--version"
48
+ return :version
49
+ when "ruby"
50
+ return :ruby
51
+ when "help", "-h", "--help", "/?", "-?"
52
+ return :usage
53
+ end
54
+
55
+ setup_tmp
56
+
34
57
  case command
35
58
  when "run", "start"
36
59
  return :run
60
+ when "up"
61
+ return :up
37
62
  when "kill", "stop", "off", "down"
38
63
  return :kill
39
64
  when "killall"
@@ -44,26 +69,16 @@ def method_for command
44
69
  return :show_stats
45
70
  when "reset_stats"
46
71
  return :reset_stats
47
- when "ruby"
48
- return :ruby
49
72
  when "dump_flows", "dump_flow"
50
73
  return :dump_flows
51
- when "version", "-V", "--version"
52
- return :version
53
74
  when "shell", NilClass
54
75
  return :shell
55
- when "help", "-h", "--help", "/?", "-?"
56
- return :usage
57
76
  else
58
77
  return nil
59
78
  end
60
79
  end
61
80
 
62
81
 
63
- FileUtils.mkdir_p Trema.log
64
- FileUtils.mkdir_p Trema.pid
65
- FileUtils.mkdir_p Trema.sock
66
-
67
82
  command = ARGV.shift
68
83
  if method_for( command )
69
84
  begin
data/trema.gemspec CHANGED
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "trema"
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Yasuhito Takamiya"]
12
12
  s.bindir = ["."]
13
- s.date = "2012-02-29"
13
+ s.date = "2012-03-05"
14
14
  s.description = "Trema is a full-stack, easy-to-use framework for developing OpenFlow controllers in Ruby/C"
15
15
  s.email = "yasuhito@gmail.com"
16
16
  s.executables = ["trema", "trema-config"]
@@ -117,6 +117,7 @@ Gem::Specification.new do |s|
117
117
  "ruby/trema/command/send_packets.rb",
118
118
  "ruby/trema/command/shell.rb",
119
119
  "ruby/trema/command/show_stats.rb",
120
+ "ruby/trema/command/up.rb",
120
121
  "ruby/trema/command/usage.rb",
121
122
  "ruby/trema/command/version.rb",
122
123
  "ruby/trema/controller.c",
@@ -340,9 +341,9 @@ Gem::Specification.new do |s|
340
341
  "src/examples/openflow_message/set-config.rb",
341
342
  "src/examples/openflow_message/set_config.c",
342
343
  "src/examples/packet_in/README",
344
+ "src/examples/packet_in/packet-in.rb",
343
345
  "src/examples/packet_in/packet_in.c",
344
346
  "src/examples/packet_in/packet_in.conf",
345
- "src/examples/packet_in/packet_in.rb",
346
347
  "src/examples/packetin_filter_config/README",
347
348
  "src/examples/packetin_filter_config/add_filter.c",
348
349
  "src/examples/packetin_filter_config/delete_filter.c",
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: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Yasuhito Takamiya
@@ -16,7 +16,7 @@ bindir:
16
16
  - .
17
17
  cert_chain: []
18
18
 
19
- date: 2012-02-29 00:00:00 Z
19
+ date: 2012-03-05 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: bundler
@@ -333,6 +333,7 @@ files:
333
333
  - ruby/trema/command/send_packets.rb
334
334
  - ruby/trema/command/shell.rb
335
335
  - ruby/trema/command/show_stats.rb
336
+ - ruby/trema/command/up.rb
336
337
  - ruby/trema/command/usage.rb
337
338
  - ruby/trema/command/version.rb
338
339
  - ruby/trema/controller.c
@@ -556,9 +557,9 @@ files:
556
557
  - src/examples/openflow_message/set-config.rb
557
558
  - src/examples/openflow_message/set_config.c
558
559
  - src/examples/packet_in/README
560
+ - src/examples/packet_in/packet-in.rb
559
561
  - src/examples/packet_in/packet_in.c
560
562
  - src/examples/packet_in/packet_in.conf
561
- - src/examples/packet_in/packet_in.rb
562
563
  - src/examples/packetin_filter_config/README
563
564
  - src/examples/packetin_filter_config/add_filter.c
564
565
  - src/examples/packetin_filter_config/delete_filter.c