openflow-protocol 0.1.6 → 0.1.7

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.
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
@@ -2,18 +2,23 @@ require 'spec_helper'
2
2
 
3
3
  describe OFStatisticsReply do
4
4
  context 'with description' do
5
- it 'should read binary' do
6
- desc = 'Manufacturer description'.pad(256) +
7
- 'Hardware description'.pad(256) +
8
- 'Software description'.pad(256) +
9
- '123456789'.pad(32) +
10
- 'Datapath description'.pad(256)
11
-
12
- msg = OFStatisticsReply.read [
5
+ let(:desc) {
6
+ 'Manufacturer description'.pad(256) +
7
+ 'Hardware description'.pad(256) +
8
+ 'Software description'.pad(256) +
9
+ '123456789'.pad(32) +
10
+ 'Datapath description'.pad(256)
11
+ }
12
+ let(:data) {
13
+ [
13
14
  1, 17, 0x04, 0x2c, 0, 0, 0, 1, # header
14
15
  0, 0, # statistic_type
15
16
  0, 1, # flags
16
17
  ].pack('C*') + desc
18
+ }
19
+
20
+ it 'should read binary' do
21
+ msg = OFStatisticsReply.read(data)
17
22
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
18
23
  expect(msg.type).to eq(:statistics_reply)
19
24
  expect(msg.len).to eq(1068)
@@ -22,6 +27,10 @@ describe OFStatisticsReply do
22
27
  expect(msg.flags).to eq([:reply_more])
23
28
  expect(msg.statistics.serial_number).to eq('123456789')
24
29
  end
30
+ it 'should be parsable' do
31
+ msg = OFParser.read(data)
32
+ expect(msg.class).to eq(OFStatisticsReply)
33
+ end
25
34
  it 'should initialize with default values' do
26
35
  msg = OFStatisticsReply.new
27
36
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
@@ -52,8 +61,8 @@ describe OFStatisticsReply do
52
61
  end
53
62
 
54
63
  context 'with flow' do
55
- it 'should read binary' do
56
- msg = OFStatisticsReply.read [
64
+ let(:data) {
65
+ [
57
66
  1, 17, 0, 108, 0, 0, 0, 1, # header
58
67
  0, 1, # statistic_type
59
68
  0, 1, # flags
@@ -96,6 +105,10 @@ describe OFStatisticsReply do
96
105
  0, 1, # port
97
106
  0xff, 0xff # max_length
98
107
  ].pack('C*')
108
+ }
109
+
110
+ it 'should read binary' do
111
+ msg = OFStatisticsReply.read(data)
99
112
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
100
113
  expect(msg.type).to eq(:statistics_reply)
101
114
  expect(msg.len).to eq(108)
@@ -105,6 +118,10 @@ describe OFStatisticsReply do
105
118
  expect(msg.statistics.table_id).to eq(1)
106
119
  expect(msg.statistics.actions.length).to eq(1)
107
120
  end
121
+ it 'should be parsable' do
122
+ msg = OFParser.read(data)
123
+ expect(msg.class).to eq(OFStatisticsReply)
124
+ end
108
125
  it 'should initialize with default values' do
109
126
  msg = OFStatisticsReply.new(statistic_type: :flow)
110
127
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
@@ -138,8 +155,8 @@ describe OFStatisticsReply do
138
155
  end
139
156
 
140
157
  context 'with aggregate' do
141
- it 'should read binary' do
142
- msg = OFStatisticsReply.read [
158
+ let(:data) {
159
+ [
143
160
  1, 17, 0, 36, 0, 0, 0, 1, # header
144
161
  0, 2, # statistic_type
145
162
  0, 1, # flags
@@ -150,6 +167,10 @@ describe OFStatisticsReply do
150
167
  0, 0, 0, 4, # flow_count
151
168
  0, 0, 0, 0 # padding
152
169
  ].pack('C*')
170
+ }
171
+
172
+ it 'should read binary' do
173
+ msg = OFStatisticsReply.read(data)
153
174
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
154
175
  expect(msg.type).to eq(:statistics_reply)
155
176
  expect(msg.len).to eq(36)
@@ -168,6 +189,10 @@ describe OFStatisticsReply do
168
189
  expect(msg.flags).to be_empty
169
190
  expect(msg.statistics.packet_count).to eq(0)
170
191
  end
192
+ it 'should be parsable' do
193
+ msg = OFParser.read(data)
194
+ expect(msg.class).to eq(OFStatisticsReply)
195
+ end
171
196
  it 'should initialize with some values' do
172
197
  msg = OFStatisticsReply.new(
173
198
  xid: 1,
@@ -190,8 +215,8 @@ describe OFStatisticsReply do
190
215
  end
191
216
 
192
217
  context 'with table' do
193
- it 'should read binary' do
194
- msg = OFStatisticsReply.read [
218
+ let(:data) {
219
+ [
195
220
  1, 17, 0, 76, 0, 0, 0, 1, # header
196
221
  0, 3, # statistic_type
197
222
  0, 1, # flags
@@ -209,6 +234,10 @@ describe OFStatisticsReply do
209
234
  0, 0, 0, 0, 0, 0, 0, 4, # lookup_count
210
235
  0, 0, 0, 0, 0, 0, 0, 1 # matched_count
211
236
  ].pack('C*')
237
+ }
238
+
239
+ it 'should read binary' do
240
+ msg = OFStatisticsReply.read(data)
212
241
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
213
242
  expect(msg.type).to eq(:statistics_reply)
214
243
  expect(msg.len).to eq(76)
@@ -218,6 +247,10 @@ describe OFStatisticsReply do
218
247
  expect(msg.statistics.length).to eq(1)
219
248
  expect(msg.statistics.first.table_id).to eq(1)
220
249
  end
250
+ it 'should be parsable' do
251
+ msg = OFParser.read(data)
252
+ expect(msg.class).to eq(OFStatisticsReply)
253
+ end
221
254
  it 'should initialize with default values' do
222
255
  msg = OFStatisticsReply.new(statistic_type: :table)
223
256
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
@@ -247,8 +280,8 @@ describe OFStatisticsReply do
247
280
  end
248
281
 
249
282
  context 'with port' do
250
- it 'should read binary' do
251
- msg = OFStatisticsReply.read [
283
+ let(:data) {
284
+ [
252
285
  1, 17, 0, 116, 0, 0, 0, 1, # header
253
286
  0, 4, # statistic_type
254
287
  0, 1, # flags
@@ -269,6 +302,10 @@ describe OFStatisticsReply do
269
302
  0, 0, 0, 0, 0, 0, 0, 1, # receive_crc_errors
270
303
  0, 0, 0, 0, 0, 0, 0, 3 # collisions
271
304
  ].pack('C*')
305
+ }
306
+
307
+ it 'should read binary' do
308
+ msg = OFStatisticsReply.read(data)
272
309
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
273
310
  expect(msg.type).to eq(:statistics_reply)
274
311
  expect(msg.len).to eq(116)
@@ -278,6 +315,10 @@ describe OFStatisticsReply do
278
315
  expect(msg.statistics.length).to eq(1)
279
316
  expect(msg.statistics.first.port_number).to eq(1)
280
317
  end
318
+ it 'should be parsable' do
319
+ msg = OFParser.read(data)
320
+ expect(msg.class).to eq(OFStatisticsReply)
321
+ end
281
322
  it 'should initialize with default values' do
282
323
  msg = OFStatisticsReply.new(statistic_type: :port)
283
324
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
@@ -307,8 +348,8 @@ describe OFStatisticsReply do
307
348
  end
308
349
 
309
350
  context 'with queue' do
310
- it 'should read binary' do
311
- msg = OFStatisticsReply.read [
351
+ let(:data) {
352
+ [
312
353
  1, 17, 0, 44, 0, 0, 0, 1, # header
313
354
  0, 5, # statistic_type
314
355
  0, 1, # flags
@@ -321,6 +362,10 @@ describe OFStatisticsReply do
321
362
  0, 0, 0, 0, 0, 0, 0, 10, # transmit_packets
322
363
  0, 0, 0, 0, 0, 0, 0, 2 # transmit_errors
323
364
  ].pack('C*')
365
+ }
366
+
367
+ it 'should read binary' do
368
+ msg = OFStatisticsReply.read(data)
324
369
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
325
370
  expect(msg.type).to eq(:statistics_reply)
326
371
  expect(msg.len).to eq(44)
@@ -330,6 +375,10 @@ describe OFStatisticsReply do
330
375
  expect(msg.statistics.length).to eq(1)
331
376
  expect(msg.statistics.first.port_number).to eq(1)
332
377
  end
378
+ it 'should be parsable' do
379
+ msg = OFParser.read(data)
380
+ expect(msg.class).to eq(OFStatisticsReply)
381
+ end
333
382
  it 'should initialize with default values' do
334
383
  msg = OFStatisticsReply.new(statistic_type: :queue)
335
384
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
@@ -359,8 +408,8 @@ describe OFStatisticsReply do
359
408
  end
360
409
 
361
410
  context 'with vendor' do
362
- it 'should read binary' do
363
- msg = OFStatisticsReply.read [
411
+ let(:data) {
412
+ [
364
413
  1, 17, 0, 20, 0, 0, 0, 1, # header
365
414
  0xff, 0xff, # statistic_type
366
415
  0, 0, # flags
@@ -369,6 +418,10 @@ describe OFStatisticsReply do
369
418
  0, 0, 0, 1, # vendor
370
419
  1, 2, 3, 4 # body
371
420
  ].pack('C*')
421
+ }
422
+
423
+ it 'should read binary' do
424
+ msg = OFStatisticsReply.read(data)
372
425
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
373
426
  expect(msg.type).to eq(:statistics_reply)
374
427
  expect(msg.len).to eq(20)
@@ -378,6 +431,10 @@ describe OFStatisticsReply do
378
431
  expect(msg.statistics.vendor).to eq(1)
379
432
  expect(msg.statistics.body).to eq([1, 2, 3, 4].pack('C*'))
380
433
  end
434
+ it 'should be parsable' do
435
+ msg = OFParser.read(data)
436
+ expect(msg.class).to eq(OFStatisticsReply)
437
+ end
381
438
  it 'should initialize with default values' do
382
439
  msg = OFStatisticsReply.new(statistic_type: :vendor)
383
440
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
@@ -1,13 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OFStatisticsRequest do
4
+ let(:data) {
5
+ [
6
+ 1, 16, 0, 12, 0, 0, 0, 1, # header
7
+ 0, 0, # statistic_type
8
+ 0, 0, # flags
9
+ ].pack('C*')
10
+ }
11
+
4
12
  context 'with description' do
5
13
  it 'should read binary' do
6
- msg = OFStatisticsRequest.read [
7
- 1, 16, 0, 12, 0, 0, 0, 1, # header
8
- 0, 0, # statistic_type
9
- 0, 0, # flags
10
- ].pack('C*')
14
+ msg = OFStatisticsRequest.read(data)
11
15
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
12
16
  expect(msg.type).to eq(:statistics_request)
13
17
  expect(msg.len).to eq(12)
@@ -16,6 +20,10 @@ describe OFStatisticsRequest do
16
20
  expect(msg.flags).to be_empty
17
21
  expect(msg.statistics).to be_empty
18
22
  end
23
+ it 'should be parsable' do
24
+ msg = OFParser.read(data)
25
+ expect(msg.class).to eq(OFStatisticsRequest)
26
+ end
19
27
  it 'should initialize with default values' do
20
28
  msg = OFStatisticsRequest.new
21
29
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
@@ -1,11 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OFVendor do
4
- it 'should read binary' do
5
- msg = OFVendor.read [
4
+ let(:data) {
5
+ [
6
6
  1, 4, 0, 12, 0, 0, 0, 1, # header
7
7
  0, 0, 0, 1 # vendor
8
8
  ].pack('C*')
9
+ }
10
+
11
+ it 'should read binary' do
12
+ msg = OFVendor.read(data)
9
13
  expect(msg.version).to eq(OFMessage::OFP_VERSION)
10
14
  expect(msg.type).to eq(:vendor)
11
15
  expect(msg.len).to eq(12)
@@ -13,6 +17,10 @@ describe OFVendor do
13
17
  expect(msg.vendor).to eq(1)
14
18
  expect(msg.data).to be_empty
15
19
  end
20
+ it 'should be parsable' do
21
+ msg = OFParser.read(data)
22
+ expect(msg.class).to eq(OFVendor)
23
+ end
16
24
  it 'should read binary with data' do
17
25
  msg = OFVendor.read [
18
26
  1, 4, 0, 14, 0, 0, 0, 1, # header
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe OFPacketQueue do
4
+ it 'should read binary' do
5
+ queue = OFPacketQueue.read [
6
+ 0, 0, 0, 1, # queue_id
7
+ 0, 24, # len
8
+ 0, 0, # padding
9
+ # queue_properties
10
+ # queue_property_min_rate
11
+ 0, 1, 0, 16, 0, 0, 0, 0, # header
12
+ 0, 100, # rate
13
+ 0, 0, 0, 0, 0, 0 # padding
14
+ ].pack('C*')
15
+ expect(queue.queue_id).to eq(1)
16
+ expect(queue.len).to eq(24)
17
+ expect(queue.properties.length).to eq(1)
18
+ expect(queue.properties.first.type).to eq(:min_rate)
19
+ expect(queue.properties.first.rate).to eq(100)
20
+ end
21
+ it 'should initialize with default values' do
22
+ queue = OFPacketQueue.new
23
+ expect(queue.queue_id).to eq(0)
24
+ expect(queue.len).to eq(8)
25
+ end
26
+ it 'should initialize with some values' do
27
+ queue = OFPacketQueue.new(
28
+ queue_id: 1,
29
+ properties: [OFQueuePropertyMinRate.new(rate: 100)]
30
+ )
31
+ expect(queue.queue_id).to eq(1)
32
+ expect(queue.len).to eq(24)
33
+ expect(queue.properties.length).to eq(1)
34
+ expect(queue.properties.first.type).to eq(:min_rate)
35
+ expect(queue.properties.first.rate).to eq(100)
36
+ end
37
+ end
@@ -1,5 +1,24 @@
1
1
  require 'spec_helper'
2
2
 
3
+ describe OFPortNumberStrict do
4
+ it 'should read binary' do
5
+ port_number = OFPortNumberStrict.read [0, 1].pack('C*')
6
+ expect(port_number).to eq(1)
7
+ end
8
+ it 'should initialize with default values' do
9
+ port_number = OFPortNumberStrict.new
10
+ expect(port_number).to eq(0)
11
+ end
12
+ it 'should initialize with some values' do
13
+ port_number = OFPortNumberStrict.new(2)
14
+ expect(port_number).to eq(2)
15
+ end
16
+ it 'should raise an error if greater than max value' do
17
+ expect { OFPortNumberStrict.new(:none) }.to raise_error(ArgumentError)
18
+ expect { OFPortNumberStrict.new(0xff01) }.to raise_error(ArgumentError)
19
+ end
20
+ end
21
+
3
22
  describe OFPortNumber do
4
23
  it 'should read binary' do
5
24
  port_number = OFPortNumber.read [0, 1].pack('C*')
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe OFQueueProperties do
4
+ it 'should read binary' do
5
+ props = OFQueueProperties.read [
6
+ # none
7
+ 0, 0, 0, 8, 0, 0, 0, 0,
8
+ # min_rate
9
+ 0, 1, 0, 8, 0, 0, 0, 0, # header
10
+ 0, 100, # rate
11
+ 0, 0, 0, 0, 0, 0 # padding
12
+ ].pack('C*'), length: 24
13
+ expect(props.length).to eq(2)
14
+ expect(props.first.type).to eq(:none)
15
+ expect(props.last.type).to eq(:min_rate)
16
+ end
17
+ it 'should initialize with default values' do
18
+ props = OFQueueProperties.new
19
+ expect(props).to be_empty
20
+ end
21
+ it 'should initialize with some values' do
22
+ props = OFQueueProperties.new([
23
+ OFQueuePropertyMinRate.new(rate: 100)
24
+ ])
25
+ expect(props.length).to eq(1)
26
+ expect(props.first.type).to eq(:min_rate)
27
+ expect(props.first.rate).to eq(100)
28
+ end
29
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe OFQueuePropertyMinRate do
4
+ it 'should read binary' do
5
+ prop = OFQueuePropertyMinRate.read [
6
+ 0, 1, 0, 16, 0, 0, 0, 0, # header
7
+ 0, 100, # rate
8
+ 0, 0, 0, 0, 0, 0 # padding
9
+ ].pack('C*')
10
+ expect(prop.type).to eq(:min_rate)
11
+ expect(prop.len).to eq(16)
12
+ expect(prop.rate).to eq(100)
13
+ end
14
+ it 'should initialize with default values' do
15
+ prop = OFQueuePropertyMinRate.new
16
+ expect(prop.type).to eq(:min_rate)
17
+ expect(prop.len).to eq(16)
18
+ expect(prop.rate).to eq(0)
19
+ end
20
+ it 'should initialize with some values' do
21
+ prop = OFQueuePropertyMinRate.new(rate: 100)
22
+ expect(prop.type).to eq(:min_rate)
23
+ expect(prop.len).to eq(16)
24
+ expect(prop.rate).to eq(100)
25
+ end
26
+ it 'should disabled rate when > 1000' do
27
+ prop = OFQueuePropertyMinRate.new(rate: 1001)
28
+ expect(prop.type).to eq(:min_rate)
29
+ expect(prop.len).to eq(16)
30
+ expect(prop.rate).to eq(:disabled)
31
+ end
32
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe OFQueuePropertyNone do
4
+ it 'should read binary' do
5
+ prop = OFQueuePropertyNone.read [0, 0, 0, 8, 0, 0, 0, 0].pack('C*')
6
+ expect(prop.type).to eq(:none)
7
+ expect(prop.len).to eq(8)
8
+ end
9
+ it 'should initialize with default values' do
10
+ prop = OFQueuePropertyNone.new
11
+ expect(prop.type).to eq(:none)
12
+ expect(prop.len).to eq(8)
13
+ end
14
+ end