pio 0.10.1 → 0.11.0

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 (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/README.md +33 -2
  4. data/examples/echo_read.rb +1 -1
  5. data/examples/features_read.rb +1 -1
  6. data/examples/flow_mod_new.rb +13 -0
  7. data/examples/flow_mod_read.rb +6 -0
  8. data/features/echo_read.feature +27 -3
  9. data/features/features_read.feature +46 -2
  10. data/features/flow_mod_read.feature +186 -0
  11. data/features/hello_read.feature +9 -0
  12. data/features/packet_data/flow_mod_add.raw +0 -0
  13. data/features/packet_data/flow_mod_delete.raw +0 -0
  14. data/features/packet_data/flow_mod_delete_strict.raw +0 -0
  15. data/features/packet_data/flow_mod_modify.raw +0 -0
  16. data/features/packet_data/flow_mod_modify_strict.raw +0 -0
  17. data/features/packet_in_read.feature +13 -0
  18. data/features/packet_out_read.feature +16 -0
  19. data/features/step_definitions/packet_data_steps.rb +10 -1
  20. data/lib/pio.rb +1 -0
  21. data/lib/pio/echo.rb +10 -8
  22. data/lib/pio/enqueue.rb +1 -1
  23. data/lib/pio/features.rb +64 -7
  24. data/lib/pio/flow_mod.rb +86 -0
  25. data/lib/pio/hello.rb +4 -74
  26. data/lib/pio/ipv4_address.rb +1 -1
  27. data/lib/pio/match.rb +167 -0
  28. data/lib/pio/open_flow.rb +1 -0
  29. data/lib/pio/open_flow/actions.rb +65 -0
  30. data/lib/pio/open_flow/flags.rb +12 -9
  31. data/lib/pio/open_flow/message.rb +105 -21
  32. data/lib/pio/open_flow/phy_port.rb +31 -27
  33. data/lib/pio/open_flow/type.rb +1 -0
  34. data/lib/pio/packet_in.rb +2 -12
  35. data/lib/pio/packet_out.rb +4 -74
  36. data/lib/pio/send_out_port.rb +1 -0
  37. data/lib/pio/type/ip_address.rb +2 -7
  38. data/lib/pio/version.rb +1 -1
  39. data/pio.gemspec +8 -8
  40. data/spec/pio/echo/reply_spec.rb +61 -6
  41. data/spec/pio/echo/request_spec.rb +61 -6
  42. data/spec/pio/features/reply_spec.rb +81 -4
  43. data/spec/pio/features/request_spec.rb +88 -41
  44. data/spec/pio/flow_mod_spec.rb +151 -0
  45. data/spec/pio/hello_spec.rb +73 -56
  46. data/spec/pio/match_spec.rb +194 -0
  47. data/spec/pio/packet_in_spec.rb +35 -38
  48. data/spec/pio/packet_out_spec.rb +243 -182
  49. data/spec/pio/wildcards_spec.rb +115 -0
  50. metadata +37 -30
  51. data/features/packet_data/echo.raw +0 -0
  52. data/lib/pio/echo/message.rb +0 -49
  53. data/lib/pio/echo/reply.rb +0 -41
  54. data/lib/pio/echo/request.rb +0 -43
  55. data/lib/pio/features/reply.rb +0 -88
  56. data/lib/pio/features/request.rb +0 -68
  57. data/lib/pio/open_flow/parser.rb +0 -22
  58. data/spec/pio/echo_spec.rb +0 -49
  59. data/spec/pio/features_spec.rb +0 -96
@@ -0,0 +1,115 @@
1
+ require 'bindata'
2
+ require 'pio/match'
3
+
4
+ describe Pio::Match::Wildcards do
5
+ # This class has wildcards field.
6
+ class WildcardTest < BinData::Record
7
+ wildcards :wildcards
8
+ end
9
+
10
+ describe '.new' do
11
+ When(:binary) { WildcardTest.new(wildcards: parameters).to_binary_s }
12
+
13
+ context 'with no wildcard' do
14
+ Given(:parameters) { {} }
15
+
16
+ Then { binary == ['00000000000000000000000000000000'].pack('B*') }
17
+ end
18
+
19
+ context 'with in_port: true' do
20
+ Given(:parameters) { { in_port: true } }
21
+
22
+ Then { binary == ['00000000000000000000000000000001'].pack('B*') }
23
+ end
24
+
25
+ context 'with nw_src: 0b10101' do
26
+ Given(:parameters) { { nw_src: 0b10101 } }
27
+
28
+ Then { binary == ['00000000000000000001010100000000'].pack('B*') }
29
+ end
30
+
31
+ context 'with nw_src_all: true' do
32
+ Given(:parameters) { { nw_src_all: true } }
33
+
34
+ Then { binary == ['00000000000000000010000000000000'].pack('B*') }
35
+ end
36
+
37
+ context 'with nw_dst: 010101' do
38
+ Given(:parameters) { { nw_dst: 0b10101 } }
39
+
40
+ Then { binary == ['00000000000001010100000000000000'].pack('B*') }
41
+ end
42
+
43
+ context 'with nw_dst_all: true' do
44
+ Given(:parameters) { { nw_dst_all: true } }
45
+
46
+ Then { binary == ['00000000000010000000000000000000'].pack('B*') }
47
+ end
48
+
49
+ context 'with in_port: false' do
50
+ Given(:parameters) { { in_port: false } }
51
+
52
+ Then { binary == ['00000000000000000000000000000000'].pack('B*') }
53
+ end
54
+
55
+ context 'with INVALID_FLAG: true' do
56
+ Given(:parameters) { { INVALID_FLAG: true } }
57
+
58
+ Then do
59
+ binary == Failure(KeyError, 'key not found: :INVALID_FLAG')
60
+ end
61
+ end
62
+ end
63
+
64
+ describe '.read' do
65
+ When(:wildcards) { Pio::Match::Wildcards.read(binary) }
66
+
67
+ context 'with all 0' do
68
+ Given(:binary) { ['00000000000000000000000000000000'].pack('B*') }
69
+
70
+ Then { wildcards == {} }
71
+ end
72
+
73
+ context 'with in_port: true' do
74
+ Given(:binary) { ['00000000000000000000000000000001'].pack('B*') }
75
+
76
+ Then { wildcards == { in_port: true } }
77
+ end
78
+
79
+ context 'with dl_vlan: true' do
80
+ Given(:binary) { ['00000000000000000000000000000010'].pack('B*') }
81
+
82
+ Then { wildcards == { dl_vlan: true } }
83
+ end
84
+
85
+ context 'with nw_src: 010101' do
86
+ Given(:binary) { ['00000000000000000001010100000000'].pack('B*') }
87
+
88
+ Then { wildcards == { nw_src: 0b10101 } }
89
+ end
90
+
91
+ context 'with nw_src: 100000' do
92
+ Given(:binary) { ['00000000000000000010000000000000'].pack('B*') }
93
+
94
+ Then { wildcards == { nw_src_all: true } }
95
+ end
96
+
97
+ context 'with nw_dst: 010101' do
98
+ Given(:binary) { ['00000000000001010100000000000000'].pack('B*') }
99
+
100
+ Then { wildcards == { nw_dst: 0b10101 } }
101
+ end
102
+
103
+ context 'with nw_dst: 100000' do
104
+ Given(:binary) { ['00000000000010000000000000000000'].pack('B*') }
105
+
106
+ Then { wildcards == { nw_dst_all: true } }
107
+ end
108
+
109
+ context 'with in_port: true, nw_src: 010101, nw_tos: true' do
110
+ Given(:binary) { ['00000000001000000001010100000001'].pack('B*') }
111
+
112
+ Then { wildcards == { in_port: true, nw_src: 0b10101, nw_tos: true } }
113
+ end
114
+ end
115
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yasuhito Takamiya
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-06 00:00:00.000000000 Z
11
+ date: 2015-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: 1.7.11
47
+ version: 1.7.12
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 1.7.11
54
+ version: 1.7.12
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - ~>
74
74
  - !ruby/object:Gem::Version
75
- version: 2.10.5
75
+ version: 2.11.1
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ~>
81
81
  - !ruby/object:Gem::Version
82
- version: 2.10.5
82
+ version: 2.11.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: guard-bundler
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -198,14 +198,14 @@ dependencies:
198
198
  requirements:
199
199
  - - ~>
200
200
  - !ruby/object:Gem::Version
201
- version: 0.5.8
201
+ version: 0.5.10
202
202
  type: :development
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - ~>
207
207
  - !ruby/object:Gem::Version
208
- version: 0.5.8
208
+ version: 0.5.10
209
209
  - !ruby/object:Gem::Dependency
210
210
  name: yard
211
211
  requirement: !ruby/object:Gem::Requirement
@@ -226,14 +226,14 @@ dependencies:
226
226
  requirements:
227
227
  - - ~>
228
228
  - !ruby/object:Gem::Version
229
- version: 0.4.4
229
+ version: 0.4.5
230
230
  type: :development
231
231
  prerelease: false
232
232
  version_requirements: !ruby/object:Gem::Requirement
233
233
  requirements:
234
234
  - - ~>
235
235
  - !ruby/object:Gem::Version
236
- version: 0.4.4
236
+ version: 0.4.5
237
237
  - !ruby/object:Gem::Dependency
238
238
  name: coveralls
239
239
  requirement: !ruby/object:Gem::Requirement
@@ -268,42 +268,42 @@ dependencies:
268
268
  requirements:
269
269
  - - ~>
270
270
  - !ruby/object:Gem::Version
271
- version: 2.5.0
271
+ version: 2.6.0
272
272
  type: :development
273
273
  prerelease: false
274
274
  version_requirements: !ruby/object:Gem::Requirement
275
275
  requirements:
276
276
  - - ~>
277
277
  - !ruby/object:Gem::Version
278
- version: 2.5.0
278
+ version: 2.6.0
279
279
  - !ruby/object:Gem::Dependency
280
280
  name: flog
281
281
  requirement: !ruby/object:Gem::Requirement
282
282
  requirements:
283
283
  - - ~>
284
284
  - !ruby/object:Gem::Version
285
- version: 4.3.0
285
+ version: 4.3.1
286
286
  type: :development
287
287
  prerelease: false
288
288
  version_requirements: !ruby/object:Gem::Requirement
289
289
  requirements:
290
290
  - - ~>
291
291
  - !ruby/object:Gem::Version
292
- version: 4.3.0
292
+ version: 4.3.1
293
293
  - !ruby/object:Gem::Dependency
294
294
  name: reek
295
295
  requirement: !ruby/object:Gem::Requirement
296
296
  requirements:
297
297
  - - ~>
298
298
  - !ruby/object:Gem::Version
299
- version: 1.5.1
299
+ version: 1.6.2
300
300
  type: :development
301
301
  prerelease: false
302
302
  version_requirements: !ruby/object:Gem::Requirement
303
303
  requirements:
304
304
  - - ~>
305
305
  - !ruby/object:Gem::Version
306
- version: 1.5.1
306
+ version: 1.6.2
307
307
  - !ruby/object:Gem::Dependency
308
308
  name: rspec
309
309
  requirement: !ruby/object:Gem::Requirement
@@ -324,14 +324,14 @@ dependencies:
324
324
  requirements:
325
325
  - - ~>
326
326
  - !ruby/object:Gem::Version
327
- version: 3.5.4
327
+ version: 3.6.0
328
328
  type: :development
329
329
  prerelease: false
330
330
  version_requirements: !ruby/object:Gem::Requirement
331
331
  requirements:
332
332
  - - ~>
333
333
  - !ruby/object:Gem::Version
334
- version: 3.5.4
334
+ version: 3.6.0
335
335
  - !ruby/object:Gem::Dependency
336
336
  name: rubocop
337
337
  requirement: !ruby/object:Gem::Requirement
@@ -370,6 +370,8 @@ files:
370
370
  - examples/echo_read.rb
371
371
  - examples/features_new.rb
372
372
  - examples/features_read.rb
373
+ - examples/flow_mod_new.rb
374
+ - examples/flow_mod_read.rb
373
375
  - examples/hello_new.rb
374
376
  - examples/hello_read.rb
375
377
  - examples/icmp_new.rb
@@ -384,6 +386,7 @@ files:
384
386
  - features/dhcp_read.feature
385
387
  - features/echo_read.feature
386
388
  - features/features_read.feature
389
+ - features/flow_mod_read.feature
387
390
  - features/hello_read.feature
388
391
  - features/icmp_read.feature
389
392
  - features/lldp_read.feature
@@ -396,7 +399,6 @@ files:
396
399
  - features/packet_data/desc_stats_reply.raw
397
400
  - features/packet_data/desc_stats_request.raw
398
401
  - features/packet_data/dhcp.pcap
399
- - features/packet_data/echo.raw
400
402
  - features/packet_data/echo_reply.raw
401
403
  - features/packet_data/echo_request.raw
402
404
  - features/packet_data/error.raw
@@ -404,6 +406,9 @@ files:
404
406
  - features/packet_data/features_request.raw
405
407
  - features/packet_data/flow_mod_add.raw
406
408
  - features/packet_data/flow_mod_delete.raw
409
+ - features/packet_data/flow_mod_delete_strict.raw
410
+ - features/packet_data/flow_mod_modify.raw
411
+ - features/packet_data/flow_mod_modify_strict.raw
407
412
  - features/packet_data/flow_removed.raw
408
413
  - features/packet_data/flow_stats_reply.raw
409
414
  - features/packet_data/flow_stats_request.raw
@@ -457,13 +462,9 @@ files:
457
462
  - lib/pio/dhcp/parameter_list.rb
458
463
  - lib/pio/dhcp/request.rb
459
464
  - lib/pio/echo.rb
460
- - lib/pio/echo/message.rb
461
- - lib/pio/echo/reply.rb
462
- - lib/pio/echo/request.rb
463
465
  - lib/pio/enqueue.rb
464
466
  - lib/pio/features.rb
465
- - lib/pio/features/reply.rb
466
- - lib/pio/features/request.rb
467
+ - lib/pio/flow_mod.rb
467
468
  - lib/pio/hello.rb
468
469
  - lib/pio/icmp.rb
469
470
  - lib/pio/icmp/format.rb
@@ -487,14 +488,15 @@ files:
487
488
  - lib/pio/lldp/system_name_value.rb
488
489
  - lib/pio/lldp/ttl_tlv.rb
489
490
  - lib/pio/mac.rb
491
+ - lib/pio/match.rb
490
492
  - lib/pio/message_type_selector.rb
491
493
  - lib/pio/monkey_patch/integer.rb
492
494
  - lib/pio/monkey_patch/integer/ranges.rb
493
495
  - lib/pio/open_flow.rb
496
+ - lib/pio/open_flow/actions.rb
494
497
  - lib/pio/open_flow/flags.rb
495
498
  - lib/pio/open_flow/message.rb
496
499
  - lib/pio/open_flow/open_flow_header.rb
497
- - lib/pio/open_flow/parser.rb
498
500
  - lib/pio/open_flow/phy_port.rb
499
501
  - lib/pio/open_flow/port_number.rb
500
502
  - lib/pio/open_flow/type.rb
@@ -531,11 +533,10 @@ files:
531
533
  - spec/pio/dhcp_spec.rb
532
534
  - spec/pio/echo/reply_spec.rb
533
535
  - spec/pio/echo/request_spec.rb
534
- - spec/pio/echo_spec.rb
535
536
  - spec/pio/enqueue_spec.rb
536
537
  - spec/pio/features/reply_spec.rb
537
538
  - spec/pio/features/request_spec.rb
538
- - spec/pio/features_spec.rb
539
+ - spec/pio/flow_mod_spec.rb
539
540
  - spec/pio/hello_spec.rb
540
541
  - spec/pio/icmp/reply_spec.rb
541
542
  - spec/pio/icmp/request_spec.rb
@@ -544,6 +545,7 @@ files:
544
545
  - spec/pio/lldp/options_spec.rb
545
546
  - spec/pio/lldp_spec.rb
546
547
  - spec/pio/mac_spec.rb
548
+ - spec/pio/match_spec.rb
547
549
  - spec/pio/open_flow/phy_port_spec.rb
548
550
  - spec/pio/open_flow/type_spec.rb
549
551
  - spec/pio/packet_in_spec.rb
@@ -559,6 +561,7 @@ files:
559
561
  - spec/pio/set_vlan_priority_spec.rb
560
562
  - spec/pio/set_vlan_vid_spec.rb
561
563
  - spec/pio/strip_vlan_header_spec.rb
564
+ - spec/pio/wildcards_spec.rb
562
565
  - spec/spec_helper.rb
563
566
  homepage: http://github.com/trema/pio
564
567
  licenses:
@@ -597,11 +600,10 @@ test_files:
597
600
  - spec/pio/dhcp_spec.rb
598
601
  - spec/pio/echo/reply_spec.rb
599
602
  - spec/pio/echo/request_spec.rb
600
- - spec/pio/echo_spec.rb
601
603
  - spec/pio/enqueue_spec.rb
602
604
  - spec/pio/features/reply_spec.rb
603
605
  - spec/pio/features/request_spec.rb
604
- - spec/pio/features_spec.rb
606
+ - spec/pio/flow_mod_spec.rb
605
607
  - spec/pio/hello_spec.rb
606
608
  - spec/pio/icmp/reply_spec.rb
607
609
  - spec/pio/icmp/request_spec.rb
@@ -610,6 +612,7 @@ test_files:
610
612
  - spec/pio/lldp/options_spec.rb
611
613
  - spec/pio/lldp_spec.rb
612
614
  - spec/pio/mac_spec.rb
615
+ - spec/pio/match_spec.rb
613
616
  - spec/pio/open_flow/phy_port_spec.rb
614
617
  - spec/pio/open_flow/type_spec.rb
615
618
  - spec/pio/packet_in_spec.rb
@@ -625,11 +628,13 @@ test_files:
625
628
  - spec/pio/set_vlan_priority_spec.rb
626
629
  - spec/pio/set_vlan_vid_spec.rb
627
630
  - spec/pio/strip_vlan_header_spec.rb
631
+ - spec/pio/wildcards_spec.rb
628
632
  - spec/spec_helper.rb
629
633
  - features/arp_read.feature
630
634
  - features/dhcp_read.feature
631
635
  - features/echo_read.feature
632
636
  - features/features_read.feature
637
+ - features/flow_mod_read.feature
633
638
  - features/hello_read.feature
634
639
  - features/icmp_read.feature
635
640
  - features/lldp_read.feature
@@ -642,7 +647,6 @@ test_files:
642
647
  - features/packet_data/desc_stats_reply.raw
643
648
  - features/packet_data/desc_stats_request.raw
644
649
  - features/packet_data/dhcp.pcap
645
- - features/packet_data/echo.raw
646
650
  - features/packet_data/echo_reply.raw
647
651
  - features/packet_data/echo_request.raw
648
652
  - features/packet_data/error.raw
@@ -650,6 +654,9 @@ test_files:
650
654
  - features/packet_data/features_request.raw
651
655
  - features/packet_data/flow_mod_add.raw
652
656
  - features/packet_data/flow_mod_delete.raw
657
+ - features/packet_data/flow_mod_delete_strict.raw
658
+ - features/packet_data/flow_mod_modify.raw
659
+ - features/packet_data/flow_mod_modify_strict.raw
653
660
  - features/packet_data/flow_removed.raw
654
661
  - features/packet_data/flow_stats_reply.raw
655
662
  - features/packet_data/flow_stats_request.raw
Binary file
@@ -1,49 +0,0 @@
1
- require 'pio/open_flow'
2
-
3
- module Pio
4
- class Echo
5
- # Base class of Echo request and reply.
6
- class Message < Pio::OpenFlow::Message
7
- # Message body of Echo
8
- class Body < BinData::Record
9
- endian :big
10
-
11
- string :body
12
-
13
- def length
14
- body.length
15
- end
16
-
17
- def empty?
18
- length == 0
19
- end
20
-
21
- def ==(other)
22
- body == other
23
- end
24
- end
25
-
26
- # rubocop:disable MethodLength
27
- # rubocop:disable AbcSize
28
- # This method smells of :reek:FeatureEnvy
29
- def initialize(user_options = {})
30
- if user_options.respond_to?(:to_i)
31
- options = { open_flow_header: { transaction_id: user_options.to_i } }
32
- elsif user_options.respond_to?(:fetch)
33
- header_options = { transaction_id: user_options[:transaction_id] ||
34
- user_options[:xid] || 0 }
35
- options = { open_flow_header: header_options,
36
- body: { body: user_options[:user_data] } }
37
- else
38
- fail TypeError
39
- end
40
- if options[:open_flow_header][:transaction_id] >= 2**32
41
- fail ArgumentError, 'Transaction ID >= 2**32'
42
- end
43
- @format = self.class.const_get(:Format).new(options)
44
- end
45
- # rubocop:enable AbcSize
46
- # rubocop:enable MethodLength
47
- end
48
- end
49
- end