openflow-protocol 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/lib/actions/actions.rb +1 -24
  3. data/lib/helpers/array_of_subclasses.rb +38 -0
  4. data/lib/helpers/superclass_base.rb +2 -0
  5. data/lib/messages/features_reply.rb +2 -2
  6. data/lib/messages/message.rb +1 -1
  7. data/lib/messages/port_mod.rb +2 -0
  8. data/lib/messages/queue_get_config_reply.rb +14 -0
  9. data/lib/messages/queue_get_config_request.rb +11 -0
  10. data/lib/{statistics → messages/statistics}/aggregate_statistics_reply.rb +0 -0
  11. data/lib/{statistics → messages/statistics}/aggregate_statistics_request.rb +0 -0
  12. data/lib/{statistics → messages/statistics}/description_statistics.rb +0 -0
  13. data/lib/{statistics → messages/statistics}/flow_statistics_reply.rb +0 -0
  14. data/lib/{statistics → messages/statistics}/flow_statistics_request.rb +0 -0
  15. data/lib/{statistics → messages/statistics}/port_statistics_reply.rb +1 -1
  16. data/lib/{statistics → messages/statistics}/port_statistics_request.rb +1 -1
  17. data/lib/{statistics → messages/statistics}/queue_statistics_reply.rb +1 -1
  18. data/lib/{statistics → messages/statistics}/queue_statistics_request.rb +1 -1
  19. data/lib/{statistics → messages/statistics}/table_statistics.rb +1 -1
  20. data/lib/{statistics → messages/statistics}/vendor_statistics.rb +0 -0
  21. data/lib/openflow-protocol/version.rb +1 -1
  22. data/lib/structs/packet_queue.rb +10 -0
  23. data/lib/structs/port_number.rb +14 -0
  24. data/lib/structs/queue_properties/queue_properties.rb +5 -0
  25. data/lib/structs/queue_properties/queue_property.rb +16 -0
  26. data/lib/structs/queue_properties/queue_property_min_rate.rb +26 -0
  27. data/lib/structs/queue_properties/queue_property_none.rb +3 -0
  28. data/spec/actions/actions_spec.rb +1 -1
  29. data/spec/messages/barrier_reply_spec.rb +7 -1
  30. data/spec/messages/barrier_request_spec.rb +7 -1
  31. data/spec/messages/echo_reply_spec.rb +7 -1
  32. data/spec/messages/echo_request_spec.rb +7 -1
  33. data/spec/messages/error_spec.rb +10 -2
  34. data/spec/messages/features_reply_spec.rb +50 -39
  35. data/spec/messages/features_request_spec.rb +7 -1
  36. data/spec/messages/flow_mod_spec.rb +10 -2
  37. data/spec/messages/flow_removed_spec.rb +10 -2
  38. data/spec/messages/get_config_reply_spec.rb +10 -2
  39. data/spec/messages/get_config_request_spec.rb +7 -1
  40. data/spec/messages/hello_spec.rb +7 -1
  41. data/spec/messages/packet_in_spec.rb +10 -2
  42. data/spec/messages/packet_out_spec.rb +10 -2
  43. data/spec/messages/port_mod_spec.rb +10 -2
  44. data/spec/messages/port_status_spec.rb +10 -2
  45. data/spec/messages/queue_get_config_reply_spec.rb +68 -0
  46. data/spec/messages/queue_get_config_request_spec.rb +40 -0
  47. data/spec/messages/set_config_spec.rb +10 -2
  48. data/spec/{statistics → messages/statistics}/aggregate_statistics_reply_spec.rb +0 -0
  49. data/spec/{statistics → messages/statistics}/aggregate_statistics_request_spec.rb +0 -0
  50. data/spec/{statistics → messages/statistics}/description_statistics_spec.rb +0 -0
  51. data/spec/{statistics → messages/statistics}/flow_statistics_reply_spec.rb +0 -0
  52. data/spec/{statistics → messages/statistics}/flow_statistics_request_spec.rb +0 -0
  53. data/spec/{statistics → messages/statistics}/port_statistics_reply_spec.rb +0 -0
  54. data/spec/{statistics → messages/statistics}/port_statistics_request_spec.rb +0 -0
  55. data/spec/{statistics → messages/statistics}/queue_statistics_reply_spec.rb +0 -0
  56. data/spec/{statistics → messages/statistics}/queue_statistics_request_spec.rb +0 -0
  57. data/spec/{statistics → messages/statistics}/table_statistics_spec.rb +0 -0
  58. data/spec/{statistics → messages/statistics}/vendor_statistics_spec.rb +0 -0
  59. data/spec/messages/statistics_reply_spec.rb +77 -20
  60. data/spec/messages/statistics_request_spec.rb +13 -5
  61. data/spec/messages/vendor_spec.rb +10 -2
  62. data/spec/structs/packet_queue_spec.rb +37 -0
  63. data/spec/structs/port_number_spec.rb +19 -0
  64. data/spec/structs/queue_properties/queue_properties_spec.rb +29 -0
  65. data/spec/structs/queue_properties/queue_property_min_rate_spec.rb +32 -0
  66. data/spec/structs/queue_properties/queue_property_none_spec.rb +14 -0
  67. metadata +55 -35
@@ -1,13 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OFFeaturesRequest do
4
+ let(:data) { [1, 5, 0, 8, 0, 0, 0, 1].pack('C*') }
5
+
4
6
  it 'should read binary' do
5
- msg = OFFeaturesRequest.read [1, 5, 0, 8, 0, 0, 0, 1].pack('C*')
7
+ msg = OFFeaturesRequest.read(data)
6
8
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
7
9
  expect(msg.type).to eq(:features_request)
8
10
  expect(msg.len).to eq(8)
9
11
  expect(msg.xid).to eq(1)
10
12
  end
13
+ it 'should be parsable' do
14
+ msg = OFParser.read(data)
15
+ expect(msg.class).to eq(OFFeaturesRequest)
16
+ end
11
17
  it 'should initialize with default values' do
12
18
  msg = OFFeaturesRequest.new
13
19
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OFFlowMod do
4
- it 'should read binary' do
5
- msg = OFFlowMod.read [
4
+ let(:data) {
5
+ [
6
6
  1, 14, 0, 80, 0, 0, 0, 1, # header
7
7
 
8
8
  # match
@@ -37,6 +37,10 @@ describe OFFlowMod do
37
37
  0, 1, # port
38
38
  0xff, 0xff, # max_length
39
39
  ].pack('C*')
40
+ }
41
+
42
+ it 'should read binary' do
43
+ msg = OFFlowMod.read(data)
40
44
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
41
45
  expect(msg.type).to eq(:flow_mod)
42
46
  expect(msg.len).to eq(80)
@@ -53,6 +57,10 @@ describe OFFlowMod do
53
57
  expect(msg.actions.length).to eq(1)
54
58
  expect(msg.actions.first.type).to eq(:output)
55
59
  end
60
+ it 'should be parsable' do
61
+ msg = OFParser.read(data)
62
+ expect(msg.class).to eq(OFFlowMod)
63
+ end
56
64
  it 'should initialize with default values' do
57
65
  msg = OFFlowMod.new
58
66
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OFFlowRemoved do
4
- it 'should read binary' do
5
- msg = OFFlowRemoved.read [
4
+ let(:data) {
5
+ [
6
6
  1, 11, 0, 88, 0, 0, 0, 1, # header
7
7
 
8
8
  # match
@@ -33,6 +33,10 @@ describe OFFlowRemoved do
33
33
  0, 0, 0, 0, 0, 0, 0, 10, # packet_count
34
34
  0, 0, 0, 0, 0, 0, 0, 80 # byte_count
35
35
  ].pack('C*')
36
+ }
37
+
38
+ it 'should read binary' do
39
+ msg = OFFlowRemoved.read(data)
36
40
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
37
41
  expect(msg.type).to eq(:flow_removed)
38
42
  expect(msg.len).to eq(88)
@@ -47,6 +51,10 @@ describe OFFlowRemoved do
47
51
  expect(msg.packet_count).to eq(10)
48
52
  expect(msg.byte_count).to eq(80)
49
53
  end
54
+ it 'should be parsable' do
55
+ msg = OFParser.read(data)
56
+ expect(msg.class).to eq(OFFlowRemoved)
57
+ end
50
58
  it 'should initialize with default values' do
51
59
  msg = OFFlowRemoved.new
52
60
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
@@ -1,12 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OFGetConfigReply do
4
- it 'should read binary' do
5
- msg = OFGetConfigReply.read [
4
+ let(:data) {
5
+ [
6
6
  1, 8, 0, 12, 0, 0, 0, 1, # header
7
7
  0, 0, # flags
8
8
  0, 0xff # miss_send_length
9
9
  ].pack('C*')
10
+ }
11
+
12
+ it 'should read binary' do
13
+ msg = OFGetConfigReply.read(data)
10
14
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
11
15
  expect(msg.type).to eq(:get_config_reply)
12
16
  expect(msg.len).to eq(12)
@@ -14,6 +18,10 @@ describe OFGetConfigReply do
14
18
  expect(msg.flags).to eq(:fragments_normal)
15
19
  expect(msg.miss_send_length).to eq(0xff)
16
20
  end
21
+ it 'should be parsable' do
22
+ msg = OFParser.read(data)
23
+ expect(msg.class).to eq(OFGetConfigReply)
24
+ end
17
25
  it 'should initialize with default values' do
18
26
  msg = OFGetConfigReply.new
19
27
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
@@ -1,13 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OFGetConfigRequest do
4
+ let(:data) { [1, 7, 0, 8, 0, 0, 0, 1].pack('C*') }
5
+
4
6
  it 'should read binary' do
5
- msg = OFGetConfigRequest.read [1, 7, 0, 8, 0, 0, 0, 1].pack('C*')
7
+ msg = OFGetConfigRequest.read(data)
6
8
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
7
9
  expect(msg.type).to eq(:get_config_request)
8
10
  expect(msg.len).to eq(8)
9
11
  expect(msg.xid).to eq(1)
10
12
  end
13
+ it 'should be parsable' do
14
+ msg = OFParser.read(data)
15
+ expect(msg.class).to eq(OFGetConfigRequest)
16
+ end
11
17
  it 'should initialize with default values' do
12
18
  msg = OFGetConfigRequest.new
13
19
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
@@ -1,13 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OFHello do
4
+ let(:data) { [1, 0, 0, 8, 0, 0, 0, 1].pack('C*') }
5
+
4
6
  it 'should read binary' do
5
- msg = OFHello.read [1, 0, 0, 8, 0, 0, 0, 1].pack('C*')
7
+ msg = OFHello.read(data)
6
8
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
7
9
  expect(msg.type).to eq(:hello)
8
10
  expect(msg.len).to eq(8)
9
11
  expect(msg.xid).to eq(1)
10
12
  end
13
+ it 'should be parsable' do
14
+ msg = OFParser.read(data)
15
+ expect(msg.class).to eq(OFHello)
16
+ end
11
17
  it 'should initialize with default values' do
12
18
  msg = OFHello.new
13
19
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OFPacketIn do
4
- it 'should read binary' do
5
- msg = OFPacketIn.read [
4
+ let(:data) {
5
+ [
6
6
  1, 10, 0, 64, 0, 0, 0, 1, # header
7
7
  0, 0, 0, 1, # buffer_id
8
8
  0, 46, # total_length
@@ -31,6 +31,10 @@ describe OFPacketIn do
31
31
  0, 0, 0, 0, 0, 2, # mac_destination
32
32
  192, 168, 0, 2 # ip_destination
33
33
  ].pack('C*')
34
+ }
35
+
36
+ it 'should read binary' do
37
+ msg = OFPacketIn.read(data)
34
38
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
35
39
  expect(msg.type).to eq(:packet_in)
36
40
  expect(msg.len).to eq(64)
@@ -43,6 +47,10 @@ describe OFPacketIn do
43
47
  expect(msg.parsed_data.length).to eq(46)
44
48
  expect(msg.parsed_data.mac_destination).to eq('00:00:00:00:00:02')
45
49
  end
50
+ it 'should be parsable' do
51
+ msg = OFParser.read(data)
52
+ expect(msg.class).to eq(OFPacketIn)
53
+ end
46
54
  it 'should initialize with default values' do
47
55
  msg = OFPacketIn.new
48
56
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OFPacketOut do
4
- it 'should read binary' do
5
- msg = OFPacketOut.read [
4
+ let(:data) {
5
+ [
6
6
  1, 13, 0, 26, 0, 0, 0, 1, # header
7
7
  0xff, 0xff, 0xff, 0xff, # buffer_id
8
8
  0, 1, # in_port
@@ -15,6 +15,10 @@ describe OFPacketOut do
15
15
  # data
16
16
  1, 2
17
17
  ].pack('C*')
18
+ }
19
+
20
+ it 'should read binary' do
21
+ msg = OFPacketOut.read(data)
18
22
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
19
23
  expect(msg.type).to eq(:packet_out)
20
24
  expect(msg.len).to eq(26)
@@ -25,6 +29,10 @@ describe OFPacketOut do
25
29
  expect(msg.actions.first.type).to eq(:output)
26
30
  expect(msg.data.length).to eq(2)
27
31
  end
32
+ it 'should be parsable' do
33
+ msg = OFParser.read(data)
34
+ expect(msg.class).to eq(OFPacketOut)
35
+ end
28
36
  it 'should initialize with default values' do
29
37
  msg = OFPacketOut.new
30
38
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OFPortMod do
4
- it 'should read binary' do
5
- msg = OFPortMod.read [
4
+ let(:data) {
5
+ [
6
6
  1, 15, 0, 32, 0, 0, 0, 1, # header
7
7
  0, 1, # port_number
8
8
  0, 0, 0, 0, 0, 1, # hardware_address
@@ -11,6 +11,10 @@ describe OFPortMod do
11
11
  0, 0, 0, 3, # advertise
12
12
  0, 0, 0, 0 # padding
13
13
  ].pack('C*')
14
+ }
15
+
16
+ it 'should read binary' do
17
+ msg = OFPortMod.read(data)
14
18
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
15
19
  expect(msg.type).to eq(:port_mod)
16
20
  expect(msg.len).to eq(32)
@@ -24,6 +28,10 @@ describe OFPortMod do
24
28
  :port_10mb_full_duplex
25
29
  ])
26
30
  end
31
+ it 'should be parsable' do
32
+ msg = OFParser.read(data)
33
+ expect(msg.class).to eq(OFPortMod)
34
+ end
27
35
  it 'should initialize with default values' do
28
36
  msg = OFPortMod.new
29
37
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OFPortStatus do
4
- it 'should read binary' do
5
- msg = OFPortStatus.read [
4
+ let(:data) {
5
+ [
6
6
  1, 12, 0, 64, 0, 0, 0, 1, # header
7
7
  1, # reason
8
8
  0, 0, 0, 0, 0, 0, 0, # padding
@@ -20,6 +20,10 @@ describe OFPortStatus do
20
20
  0, 0, 0x0f, 0xff, # supported_features
21
21
  0, 0, 0x0f, 0xff # peer_features
22
22
  ].pack('C*')
23
+ }
24
+
25
+ it 'should read binary' do
26
+ msg = OFPortStatus.read(data)
23
27
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
24
28
  expect(msg.type).to eq(:port_status)
25
29
  expect(msg.len).to eq(64)
@@ -27,6 +31,10 @@ describe OFPortStatus do
27
31
  expect(msg.reason).to eq(:delete)
28
32
  expect(msg.desc.port_number).to eq(1)
29
33
  end
34
+ it 'should be parsable' do
35
+ msg = OFParser.read(data)
36
+ expect(msg.class).to eq(OFPortStatus)
37
+ end
30
38
  it 'should initialize with default values' do
31
39
  msg = OFPortStatus.new
32
40
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe OFQueueGetConfigReply do
4
+ let(:data) {
5
+ [
6
+ 1, 21, 0, 48, 0, 0, 0, 1, # header
7
+ 0, 1, # port
8
+ 0, 0, 0, 0, 0, 0, # padding
9
+ # queue 1
10
+ 0, 0, 0, 1, # queue_id
11
+ 0, 24, # len
12
+ 0, 0, # padding
13
+ # queue_properties
14
+ # queue_property_min_rate
15
+ 0, 1, 0, 16, 0, 0, 0, 0, # header
16
+ 0, 100, # rate
17
+ 0, 0, 0, 0, 0, 0, # padding
18
+ # queue 2
19
+ 0, 0, 0, 2, # queue_id
20
+ 0, 8, # len
21
+ 0, 0 # padding
22
+ ].pack('C*')
23
+ }
24
+
25
+ it 'should read binary' do
26
+ msg = OFQueueGetConfigReply.read(data)
27
+ expect(msg.version).to eq(OFMessage::OFP_VERSION)
28
+ expect(msg.type).to eq(:queue_get_config_reply)
29
+ expect(msg.len).to eq(48)
30
+ expect(msg.xid).to eq(1)
31
+ expect(msg.port).to eq(1)
32
+ expect(msg.queues.length).to eq(2)
33
+ expect(msg.queues.first.queue_id).to eq(1)
34
+ expect(msg.queues.first.properties.length).to eq(1)
35
+ expect(msg.queues.last.queue_id).to eq(2)
36
+ end
37
+ it 'should be parsable' do
38
+ msg = OFParser.read(data)
39
+ expect(msg.class).to eq(OFQueueGetConfigReply)
40
+ end
41
+ it 'should initialize with default values' do
42
+ msg = OFQueueGetConfigReply.new
43
+ expect(msg.version).to eq(OFMessage::OFP_VERSION)
44
+ expect(msg.type).to eq(:queue_get_config_reply)
45
+ expect(msg.len).to eq(16)
46
+ expect(msg.xid).to eq(0)
47
+ expect(msg.port).to eq(0)
48
+ expect(msg.queues).to be_empty
49
+ end
50
+ it 'should initialize with some values' do
51
+ msg = OFQueueGetConfigReply.new(
52
+ xid: 1,
53
+ port: 2,
54
+ queues: [
55
+ { queue_id: 1 },
56
+ { queue_id: 2 },
57
+ ]
58
+ )
59
+ expect(msg.version).to eq(OFMessage::OFP_VERSION)
60
+ expect(msg.type).to eq(:queue_get_config_reply)
61
+ expect(msg.len).to eq(32)
62
+ expect(msg.xid).to eq(1)
63
+ expect(msg.port).to eq(2)
64
+ expect(msg.queues.length).to eq(2)
65
+ expect(msg.queues.first.queue_id).to eq(1)
66
+ expect(msg.queues.last.queue_id).to eq(2)
67
+ end
68
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe OFQueueGetConfigRequest do
4
+ let(:data) {
5
+ [
6
+ 1, 20, 0, 12, 0, 0, 0, 1, # header
7
+ 0, 1, # port
8
+ 0, 0 # padding
9
+ ].pack('C*')
10
+ }
11
+
12
+ it 'should read binary' do
13
+ msg = OFQueueGetConfigRequest.read(data)
14
+ expect(msg.version).to eq(OFMessage::OFP_VERSION)
15
+ expect(msg.type).to eq(:queue_get_config_request)
16
+ expect(msg.len).to eq(12)
17
+ expect(msg.xid).to eq(1)
18
+ expect(msg.port).to eq(1)
19
+ end
20
+ it 'should be parsable' do
21
+ msg = OFParser.read(data)
22
+ expect(msg.class).to eq(OFQueueGetConfigRequest)
23
+ end
24
+ it 'should initialize with default values' do
25
+ msg = OFQueueGetConfigRequest.new
26
+ expect(msg.version).to eq(OFMessage::OFP_VERSION)
27
+ expect(msg.type).to eq(:queue_get_config_request)
28
+ expect(msg.len).to eq(12)
29
+ expect(msg.xid).to eq(0)
30
+ expect(msg.port).to eq(0)
31
+ end
32
+ it 'should initialize with some values' do
33
+ msg = OFQueueGetConfigRequest.new(xid: 1, port: 2)
34
+ expect(msg.version).to eq(OFMessage::OFP_VERSION)
35
+ expect(msg.type).to eq(:queue_get_config_request)
36
+ expect(msg.len).to eq(12)
37
+ expect(msg.xid).to eq(1)
38
+ expect(msg.port).to eq(2)
39
+ end
40
+ end
@@ -1,12 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OFSetConfig do
4
- it 'should read binary' do
5
- msg = OFSetConfig.read [
4
+ let(:data) {
5
+ [
6
6
  1, 9, 0, 12, 0, 0, 0, 1, # header
7
7
  0, 0, # flags
8
8
  0, 0xff # miss_send_length
9
9
  ].pack('C*')
10
+ }
11
+
12
+ it 'should read binary' do
13
+ msg = OFSetConfig.read(data)
10
14
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
11
15
  expect(msg.type).to eq(:set_config)
12
16
  expect(msg.len).to eq(12)
@@ -14,6 +18,10 @@ describe OFSetConfig do
14
18
  expect(msg.flags).to eq(:fragments_normal)
15
19
  expect(msg.miss_send_length).to eq(0xff)
16
20
  end
21
+ it 'should be parsable' do
22
+ msg = OFParser.read(data)
23
+ expect(msg.class).to eq(OFSetConfig)
24
+ end
17
25
  it 'should initialize with default values' do
18
26
  msg = OFSetConfig.new
19
27
  expect(msg.version).to eq(OFMessage::OFP_VERSION)