openflow-controller 0.1.5 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c4acadf7961136eb17add772ffdeefc969d4476
4
- data.tar.gz: 9bd7eb4f73e9f23631f561eeb0947619bff9adcb
3
+ metadata.gz: d91aedf880f4a2f25f272525c275370cc4e65658
4
+ data.tar.gz: 01467caf6b802b0ce3226ca182b1a031494fbbf7
5
5
  SHA512:
6
- metadata.gz: f68d7de83750edb01e19754f52a0f86125958b85d4c81f82acc0bafae6c260d9288416fad3c9406a5fe42e62739b93e01a7143162ad22ee247304731c418fb79
7
- data.tar.gz: 3decb0031fe40e9d8e5b1a0010d1f09767639b28b9516ab30479eec65127f07bc77e91a70f922d21d9f37f3c7d4d21736ae49c7020dd936185ede3a7c0c40d9e
6
+ metadata.gz: ed99be3a83bb58201cf83320db81c2192708770dc452559de0408c9621413fec4e6b16726ab0ac2b14a8e95b3d3e499a52403441cee9e456ab231df3c5c93f1d
7
+ data.tar.gz: f27fc51af539191953bf3fb4eb3d110431da65ace4925d10ca57264a0c3dbb96584a566eaa5a979c5c1f1a6972354855c2a117b97f4790956dae10298b779330
data/bin/ofctl CHANGED
@@ -4,6 +4,7 @@ require 'readline'
4
4
  require_relative '../lib/controller'
5
5
 
6
6
  PROMPT = '> '
7
+ BYE_MSG = 'Bye!'
7
8
 
8
9
  command = Cri::Command.define do
9
10
  name 'ofctl'
@@ -51,9 +52,18 @@ command = Cri::Command.define do
51
52
 
52
53
  loop do
53
54
  begin
54
- puts " => #{eval(Readline.readline(PROMPT, true)).inspect}".green
55
+ input = Readline.readline(PROMPT, true)
56
+ if input == 'exit'
57
+ puts BYE_MSG
58
+ exit
59
+ end
60
+ output = ctl.eval(input).inspect
61
+ puts " => #{output}".green
55
62
  rescue StandardError => e
56
63
  puts "#{e.class}: #{e.message}".red
64
+ rescue SignalException => e
65
+ puts "\n#{BYE_MSG}"
66
+ exit
57
67
  end
58
68
  end
59
69
  end
data/lib/controller.rb CHANGED
@@ -40,6 +40,10 @@ class OFController
40
40
  end
41
41
  end
42
42
 
43
+ def eval(input)
44
+ binding.eval(input)
45
+ end
46
+
43
47
  def run(ip = DEFAULT_IP_ADDRESS, port = DEFAULT_TCP_PORT, *args)
44
48
  maybe_send_handler :start, *args
45
49
  socket = TCPServer.open(ip, port)
@@ -50,7 +54,11 @@ class OFController
50
54
  end
51
55
 
52
56
  def datapath_ids
53
- @switches.keys
57
+ @switches.keys.map(&:to_i)
58
+ end
59
+
60
+ def switches
61
+ @switches.values
54
62
  end
55
63
 
56
64
  def send_message(datapath_id, msg = nil)
@@ -0,0 +1,5 @@
1
+ module OpenFlow
2
+ module Controller
3
+ VERSION = '0.1.7'
4
+ end
5
+ end
data/lib/switch.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'openflow-protocol'
2
2
 
3
3
  class OFSwitch
4
- attr_reader :controller
4
+ attr_reader :controller, :features_reply
5
5
 
6
6
  def initialize(controller, socket)
7
7
  @controller = controller
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe OFController do
4
+ before(:all) do
5
+ class MyCtl < OFController
6
+ attr_reader :start_args
7
+
8
+ def start(*args)
9
+ @start_args = args
10
+ end
11
+ end
12
+
13
+ @ctl = OFController.create
14
+ Thread.new { @ctl.run('127.0.0.1', 4242, 'Hello World!', 42) }
15
+ end
16
+
17
+ it 'should create a subclass when inherited' do
18
+ expect(@ctl.class).to be(MyCtl)
19
+ expect(@ctl.logger.level).to eq(Logger::INFO)
20
+ end
21
+
22
+ it 'should handle start' do
23
+ expect(@ctl.start_args).to eq(['Hello World!', 42])
24
+ end
25
+
26
+ it 'should start a switch when it receives a connection' do
27
+ socket = TCPSocket.new '127.0.0.1', 4242
28
+
29
+ # Exchange Hello messages
30
+ socket.write OFHello.new.to_binary_s
31
+ msg = OFParser.read socket
32
+ expect(msg.class).to be(OFHello)
33
+
34
+ # Exchange Echo messages
35
+ msg = OFParser.read socket
36
+ expect(msg.class).to be(OFEchoRequest)
37
+ # socket.write msg.to_reply.to_binary_s
38
+ socket.write OFEchoReply.new.to_binary_s
39
+
40
+ # Exchange Features messages
41
+ msg = OFParser.read socket
42
+ expect(msg.class).to be(OFFeaturesRequest)
43
+ socket.write OFFeaturesReply.new(datapath_id: 1).to_binary_s
44
+
45
+ sleep(0.001)
46
+ expect(@ctl.switches.length).to eq(1)
47
+ expect(@ctl.switches.first.datapath_id).to eq(1)
48
+ expect(@ctl.datapath_ids).to eq([1])
49
+ end
50
+ end
@@ -0,0 +1 @@
1
+ require_relative '../lib/openflow-controller'
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openflow-controller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
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-10-07 00:00:00.000000000 Z
11
+ date: 2016-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: openflow-protocol
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: '0.1'
19
+ version: 0.1.6
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: '0.1'
26
+ version: 0.1.6
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: colored
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -77,7 +77,10 @@ files:
77
77
  - bin/ofctl
78
78
  - lib/controller.rb
79
79
  - lib/openflow-controller.rb
80
+ - lib/openflow-controller/version.rb
80
81
  - lib/switch.rb
82
+ - spec/controller_spec.rb
83
+ - spec/spec_helper.rb
81
84
  homepage: https://github.com/jejepage/openflow-controller
82
85
  licenses:
83
86
  - MIT
@@ -98,8 +101,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
101
  version: '0'
99
102
  requirements: []
100
103
  rubyforge_project:
101
- rubygems_version: 2.4.8
104
+ rubygems_version: 2.5.1
102
105
  signing_key:
103
106
  specification_version: 4
104
107
  summary: OpenFlow Controller
105
- test_files: []
108
+ test_files:
109
+ - spec/controller_spec.rb
110
+ - spec/spec_helper.rb