openflow-controller 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/ofctl +42 -71
- data/lib/controller.rb +4 -4
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c4acadf7961136eb17add772ffdeefc969d4476
|
4
|
+
data.tar.gz: 9bd7eb4f73e9f23631f561eeb0947619bff9adcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f68d7de83750edb01e19754f52a0f86125958b85d4c81f82acc0bafae6c260d9288416fad3c9406a5fe42e62739b93e01a7143162ad22ee247304731c418fb79
|
7
|
+
data.tar.gz: 3decb0031fe40e9d8e5b1a0010d1f09767639b28b9516ab30479eec65127f07bc77e91a70f922d21d9f37f3c7d4d21736ae49c7020dd936185ede3a7c0c40d9e
|
data/bin/ofctl
CHANGED
@@ -1,91 +1,62 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require '
|
2
|
+
require 'cri'
|
3
3
|
require 'readline'
|
4
4
|
require_relative '../lib/controller'
|
5
5
|
|
6
6
|
PROMPT = '> '
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
command = Cri::Command.define do
|
9
|
+
name 'ofctl'
|
10
|
+
usage 'ofctl [options] [args]'
|
11
|
+
summary 'OpenFlow Controller command-line tool'
|
12
|
+
description 'OpenFlow Controller command-line tool'
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
rescue StandardError => e
|
15
|
-
puts "#{e.class}: #{e.message}"
|
16
|
-
end
|
14
|
+
flag :h, :help, 'show help for this command' do |value, cmd|
|
15
|
+
puts cmd.help
|
16
|
+
exit 0
|
17
17
|
end
|
18
|
-
|
18
|
+
flag :d, :debug, 'run controller in debug mode'
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
option :i, :ip, 'IP address of the controller', argument: :optional
|
21
|
+
option :p, :port, 'port number of the controller', argument: :optional
|
22
|
+
option :c, :controller, 'custom controller file', argument: :optional
|
22
23
|
|
23
|
-
|
24
|
+
run do |opts, args, _cmd|
|
25
|
+
load opts[:controller] unless opts[:controller].nil?
|
24
26
|
|
25
|
-
|
26
|
-
arg_name 'controller', optional: false
|
27
|
-
command :run do |c|
|
28
|
-
c.flag :ip,
|
29
|
-
desc: 'IP Address',
|
30
|
-
must_match: /\d+\.\d+\.\d+\.\d+/,
|
31
|
-
required: false,
|
32
|
-
default_value: OFController::DEFAULT_IP_ADDRESS
|
33
|
-
c.flag :port,
|
34
|
-
desc: 'Port Number',
|
35
|
-
type: Integer,
|
36
|
-
required: false,
|
37
|
-
default_value: OFController::DEFAULT_TCP_PORT
|
38
|
-
c.switch :debug,
|
39
|
-
desc: 'Run in Debug Mode',
|
40
|
-
default_value: false
|
27
|
+
debug = opts[:debug] || false
|
41
28
|
|
42
|
-
|
43
|
-
load args.first
|
44
|
-
controller = if options[:debug]
|
45
|
-
OFController.create(Logger::DEBUG)
|
46
|
-
else
|
47
|
-
OFController.create
|
48
|
-
end
|
49
|
-
controller.run options[:ip], options[:port], args[1..-1]
|
50
|
-
end
|
51
|
-
end
|
29
|
+
ctl = OFController.create(debug)
|
52
30
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
c.flag :port,
|
61
|
-
desc: 'Port Number',
|
62
|
-
type: Integer,
|
63
|
-
required: false,
|
64
|
-
default_value: OFController::DEFAULT_TCP_PORT
|
65
|
-
c.switch :debug,
|
66
|
-
desc: 'Run in Debug Mode',
|
67
|
-
default_value: false
|
31
|
+
init_form = ctl.logger.formatter
|
32
|
+
ctl.logger.formatter = proc do |severity, datetime, progname, msg|
|
33
|
+
buf = PROMPT + Readline::line_buffer
|
34
|
+
"\r" + ' ' * buf.length + "\r" +
|
35
|
+
init_form.call(severity, datetime, progname, msg).blue +
|
36
|
+
buf
|
37
|
+
end
|
68
38
|
|
69
|
-
|
70
|
-
|
71
|
-
OFController.new(Logger::DEBUG)
|
72
|
-
else
|
73
|
-
OFController.new
|
74
|
-
end
|
39
|
+
ip = opts[:ip] || OFController::DEFAULT_IP_ADDRESS
|
40
|
+
port = opts[:port] || OFController::DEFAULT_TCP_PORT
|
75
41
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
42
|
+
Thread.abort_on_exception = true
|
43
|
+
Thread.new do
|
44
|
+
begin
|
45
|
+
ctl.run ip, port, args
|
46
|
+
rescue StandardError => e
|
47
|
+
puts "#{e.class}: #{e.message}".red
|
48
|
+
exit 1
|
82
49
|
end
|
50
|
+
end
|
83
51
|
|
84
|
-
|
52
|
+
loop do
|
53
|
+
begin
|
54
|
+
puts " => #{eval(Readline.readline(PROMPT, true)).inspect}".green
|
55
|
+
rescue StandardError => e
|
56
|
+
puts "#{e.class}: #{e.message}".red
|
57
|
+
end
|
85
58
|
end
|
86
59
|
end
|
87
|
-
|
88
|
-
default_command :help
|
89
|
-
|
90
|
-
exit run(ARGV)
|
91
60
|
end
|
61
|
+
|
62
|
+
command.run(ARGV)
|
data/lib/controller.rb
CHANGED
@@ -15,7 +15,7 @@ class OFController
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.create(*args)
|
18
|
-
@controller_class.new(*args)
|
18
|
+
(@controller_class || self).new(*args)
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.timer_event(handler, options)
|
@@ -29,18 +29,18 @@ class OFController
|
|
29
29
|
|
30
30
|
attr_reader :logger
|
31
31
|
|
32
|
-
def initialize(
|
32
|
+
def initialize(debug = false)
|
33
33
|
@switches = {}
|
34
34
|
@messages = {}
|
35
35
|
@logger = Logger.new($stdout).tap do |logger|
|
36
36
|
logger.formatter = proc do |severity, datetime, _progname, msg|
|
37
37
|
"#{datetime} (#{severity}) -- #{msg}\n"
|
38
38
|
end
|
39
|
-
logger.level =
|
39
|
+
logger.level = debug ? Logger::DEBUG : Logger::INFO
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
def run(ip, port, *args)
|
43
|
+
def run(ip = DEFAULT_IP_ADDRESS, port = DEFAULT_TCP_PORT, *args)
|
44
44
|
maybe_send_handler :start, *args
|
45
45
|
socket = TCPServer.open(ip, port)
|
46
46
|
socket.setsockopt(:SOCKET, :REUSEADDR, true)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openflow-controller
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jérémy Pagé
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: openflow-protocol
|
@@ -25,19 +25,33 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: colored
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '2
|
33
|
+
version: '1.2'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '2
|
40
|
+
version: '1.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: cri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.7'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.7'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|