pio 0.23.1 → 0.24.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/README.md +2 -0
  4. data/Rakefile +1 -1
  5. data/features/open_flow10/barrier_reply.feature +58 -0
  6. data/features/open_flow10/barrier_request.feature +58 -0
  7. data/features/open_flow10/echo_reply.feature +50 -40
  8. data/features/open_flow10/echo_request.feature +54 -51
  9. data/features/open_flow10/features_reply.feature +62 -63
  10. data/features/open_flow10/features_request.feature +2 -19
  11. data/features/open_flow10/flow_mod.feature +1 -0
  12. data/features/open_flow10/hello.feature +38 -44
  13. data/features/open_flow10/packet_in.feature +1 -2
  14. data/features/open_flow10/packet_in.raw +0 -0
  15. data/features/open_flow10/packet_out.feature +14 -14
  16. data/features/open_flow10/port_status.feature +17 -17
  17. data/features/open_flow13/apply_actions.feature +15 -17
  18. data/features/open_flow13/echo_reply.feature +58 -58
  19. data/features/open_flow13/echo_request.feature +58 -58
  20. data/features/open_flow13/features_reply.feature +2 -6
  21. data/features/open_flow13/features_request.feature +3 -23
  22. data/features/open_flow13/flow_mod.feature +86 -93
  23. data/features/open_flow13/goto_table.feature +4 -4
  24. data/features/open_flow13/hello.feature +8 -15
  25. data/features/open_flow13/match.feature +14 -3
  26. data/features/open_flow13/meter.feature +3 -3
  27. data/features/open_flow13/oxm_experimenter_stratos_basic_dot11.raw +0 -0
  28. data/features/open_flow13/oxm_invalid_field.raw +0 -0
  29. data/features/open_flow13/packet_in.feature +15 -20
  30. data/features/open_flow13/packet_out.feature +39 -42
  31. data/features/open_flow13/send_out_port.feature +1 -5
  32. data/features/open_flow13/write_metadata.feature +3 -3
  33. data/features/open_flow_read.feature +43 -0
  34. data/features/open_flow_version.feature +10 -0
  35. data/features/step_definitions/open_flow_steps.rb +10 -2
  36. data/features/step_definitions/packet_data_steps.rb +4 -0
  37. data/features/support/hooks.rb +7 -0
  38. data/lib/pio.rb +1 -1
  39. data/lib/pio/monkey_patch/integer/ranges.rb +4 -0
  40. data/lib/pio/open_flow.rb +54 -16
  41. data/lib/pio/open_flow/datapath_id.rb +26 -0
  42. data/lib/pio/open_flow/echo.rb +44 -0
  43. data/lib/pio/open_flow/format.rb +45 -0
  44. data/lib/pio/open_flow/message.rb +88 -0
  45. data/lib/pio/open_flow/open_flow_header.rb +0 -14
  46. data/lib/pio/open_flow10.rb +3 -8
  47. data/lib/pio/open_flow10/actions.rb +1 -1
  48. data/lib/pio/open_flow10/barrier_reply.rb +21 -0
  49. data/lib/pio/open_flow10/barrier_request.rb +22 -0
  50. data/lib/pio/open_flow10/echo.rb +15 -11
  51. data/lib/pio/open_flow10/features.rb +99 -71
  52. data/lib/pio/open_flow10/flow_mod.rb +73 -66
  53. data/lib/pio/open_flow10/hello.rb +19 -4
  54. data/lib/pio/open_flow10/match.rb +133 -131
  55. data/lib/pio/open_flow10/packet_in.rb +55 -49
  56. data/lib/pio/open_flow10/packet_out.rb +31 -24
  57. data/lib/pio/open_flow10/port_status.rb +54 -27
  58. data/lib/pio/open_flow10/send_out_port.rb +66 -64
  59. data/lib/pio/open_flow13.rb +0 -15
  60. data/lib/pio/open_flow13/echo.rb +11 -68
  61. data/lib/pio/open_flow13/features_reply.rb +48 -77
  62. data/lib/pio/open_flow13/features_request.rb +16 -45
  63. data/lib/pio/open_flow13/flow_mod.rb +125 -148
  64. data/lib/pio/open_flow13/goto_table.rb +1 -0
  65. data/lib/pio/open_flow13/hello.rb +54 -84
  66. data/lib/pio/open_flow13/match.rb +69 -11
  67. data/lib/pio/open_flow13/meter.rb +1 -0
  68. data/lib/pio/open_flow13/packet_in.rb +38 -50
  69. data/lib/pio/open_flow13/packet_out.rb +50 -75
  70. data/lib/pio/open_flow13/send_out_port.rb +34 -34
  71. data/lib/pio/open_flow13/write_metadata.rb +1 -0
  72. data/lib/pio/parser.rb +3 -0
  73. data/lib/pio/version.rb +1 -1
  74. data/pio.gemspec +6 -6
  75. data/spec/pio/open_flow10/echo_reply_spec.rb +7 -0
  76. data/spec/pio/open_flow10/echo_request_spec.rb +7 -0
  77. data/spec/pio/open_flow10/features_reply_spec.rb +8 -0
  78. data/spec/pio/open_flow10/features_request_spec.rb +13 -0
  79. data/spec/pio/open_flow10/flow_mod_spec.rb +17 -16
  80. data/spec/pio/open_flow10/hello_spec.rb +7 -0
  81. data/spec/pio/open_flow10/match_spec.rb +8 -6
  82. data/spec/pio/open_flow10/packet_in_spec.rb +14 -0
  83. data/spec/pio/open_flow10/packet_out_spec.rb +21 -14
  84. data/spec/pio/open_flow10/send_out_port_spec.rb +4 -4
  85. data/spec/pio/open_flow10/wildcards_spec.rb +2 -2
  86. data/spec/pio/open_flow13/echo_reply_spec.rb +7 -0
  87. data/spec/pio/open_flow13/echo_request_spec.rb +7 -0
  88. data/spec/pio/open_flow13/features_reply_spec.rb +8 -0
  89. data/spec/pio/open_flow13/features_request_spec.rb +13 -0
  90. data/spec/pio/open_flow13/hello_spec.rb +14 -59
  91. data/spec/pio/open_flow13/packet_in_spec.rb +14 -0
  92. data/spec/pio/open_flow13/packet_out_spec.rb +7 -0
  93. data/spec/pio/open_flow_spec.rb +34 -0
  94. data/spec/spec_helper.rb +1 -0
  95. data/spec/support/shared_examples_for_openflow_messages.rb +75 -0
  96. metadata +215 -170
  97. data/bin/byebug +0 -16
  98. data/bin/terminal-notifier +0 -16
  99. data/lib/pio/open_flow10/message.rb +0 -78
  100. data/spec/pio/open_flow/type_spec.rb +0 -5
@@ -1,89 +1,96 @@
1
1
  require 'pio/open_flow'
2
+ require 'pio/open_flow10/actions'
2
3
  require 'pio/open_flow10/match'
3
4
 
4
5
  # Base module.
5
6
  module Pio
6
- # OpenFlow 1.0 Flow Mod message.
7
- class FlowMod
8
- # enum ofp_flow_mod_command
9
- class Command < BinData::Primitive
10
- COMMANDS = {
11
- add: 0,
12
- modify: 1,
13
- modify_strict: 2,
14
- delete: 3,
15
- delete_strict: 4
16
- }
17
-
18
- endian :big
19
- uint16 :command
20
-
21
- def get
22
- COMMANDS.invert.fetch(command)
23
- end
7
+ module OpenFlow10
8
+ # OpenFlow 1.0 Flow Mod message.
9
+ class FlowMod < OpenFlow::Message
10
+ # enum ofp_flow_mod_command
11
+ class Command < BinData::Primitive
12
+ COMMANDS = {
13
+ add: 0,
14
+ modify: 1,
15
+ modify_strict: 2,
16
+ delete: 3,
17
+ delete_strict: 4
18
+ }
24
19
 
25
- def set(value)
26
- self.command = COMMANDS.fetch(value)
27
- end
28
- end
29
-
30
- # Message body of FlowMod.
31
- class Body < BinData::Record
32
- # Pio::MatchFormat wrapper.
33
- class Match < BinData::Primitive
34
20
  endian :big
21
+ uint16 :command
35
22
 
36
- string :match, read_length: 40
37
-
38
- def set(object)
39
- self.match = object.to_binary_s
23
+ def get
24
+ COMMANDS.invert.fetch(command)
40
25
  end
41
26
 
42
- def get
43
- Pio::Match.read match
27
+ def set(value)
28
+ self.command = COMMANDS.fetch(value)
44
29
  end
45
30
  end
46
31
 
47
- extend OpenFlow::Flags
32
+ # Message body of FlowMod.
33
+ class Body < BinData::Record
34
+ # Pio::MatchFormat wrapper.
35
+ class Match < BinData::Primitive
36
+ endian :big
37
+
38
+ string :match, read_length: 40
39
+
40
+ def set(object)
41
+ self.match = object.to_binary_s
42
+ end
43
+
44
+ def get
45
+ Pio::OpenFlow10::Match.read match
46
+ end
47
+ end
48
+
49
+ extend OpenFlow::Flags
48
50
 
49
- flags_16bit :flags,
50
- [:send_flow_rem,
51
- :check_overwrap,
52
- :emerg]
51
+ flags_16bit :flags,
52
+ [:send_flow_rem,
53
+ :check_overwrap,
54
+ :emerg]
53
55
 
54
- endian :big
56
+ endian :big
55
57
 
56
- match :match
57
- uint64 :cookie
58
- command :command
59
- uint16 :idle_timeout
60
- uint16 :hard_timeout
61
- uint16 :priority
62
- uint32 :buffer_id
63
- uint16 :out_port
64
- flags :flags
65
- actions :actions, length: -> { open_flow_header.message_length - 72 }
58
+ match :match
59
+ uint64 :cookie
60
+ command :command
61
+ uint16 :idle_timeout
62
+ uint16 :hard_timeout
63
+ uint16 :priority
64
+ uint32 :buffer_id
65
+ uint16 :out_port
66
+ flags :flags
67
+ actions :actions, length: -> { header.message_length - 72 }
68
+
69
+ def empty?
70
+ false
71
+ end
66
72
 
67
- def empty?
68
- false
73
+ def length
74
+ 64 + actions.binary.length
75
+ end
69
76
  end
70
77
 
71
- def length
72
- 64 + actions.binary.length
78
+ # OpenFlow 1.0 Flow Mod message format.
79
+ class Format < BinData::Record
80
+ extend OpenFlow::Format
81
+
82
+ header version: 1, message_type: 14
83
+ body :body
73
84
  end
74
- end
75
- end
76
85
 
77
- OpenFlow::Message.factory(FlowMod, OpenFlow::FLOW_MOD) do
78
- def_delegators :body, :match
79
- def_delegators :body, :cookie
80
- def_delegators :body, :command
81
- def_delegators :body, :idle_timeout
82
- def_delegators :body, :hard_timeout
83
- def_delegators :body, :priority
84
- def_delegators :body, :buffer_id
85
- def_delegators :body, :out_port
86
- def_delegators :body, :flags
87
- def_delegators :body, :actions
86
+ body_option :actions
87
+ body_option :buffer_id
88
+ body_option :command
89
+ body_option :cookie
90
+ body_option :flags
91
+ body_option :match
92
+ body_option :out_port
93
+ body_option :priority
94
+ end
88
95
  end
89
96
  end
@@ -1,8 +1,23 @@
1
- require 'pio/open_flow'
1
+ require 'pio/open_flow/format'
2
+ require 'pio/open_flow/message'
2
3
 
3
4
  # Base module.
4
5
  module Pio
5
- # OpenFlow 1.0 Hello message
6
- class Hello; end
7
- OpenFlow::Message.factory(Hello, OpenFlow::HELLO)
6
+ # OpenFlow 1.0 messages
7
+ module OpenFlow10
8
+ # OpenFlow 1.0 Hello message
9
+ class Hello < OpenFlow::Message
10
+ # OpenFlow 1.0 Hello message format
11
+ class Format < BinData::Record
12
+ extend OpenFlow::Format
13
+
14
+ header version: 1, message_type: 0
15
+ string :body
16
+
17
+ def user_data
18
+ body
19
+ end
20
+ end
21
+ end
22
+ end
8
23
  end
@@ -5,159 +5,161 @@ require 'pio/type/ip_address'
5
5
  require 'pio/type/mac_address'
6
6
 
7
7
  module Pio
8
- # Fields to match against flows
9
- class Match
10
- # Flow wildcards
11
- class Wildcards < BinData::Primitive
12
- BITS = {
13
- in_port: 1 << 0,
14
- vlan_vid: 1 << 1,
15
- ether_source_address: 1 << 2,
16
- ether_destination_address: 1 << 3,
17
- ether_type: 1 << 4,
18
- ip_protocol: 1 << 5,
19
- transport_source_port: 1 << 6,
20
- transport_destination_port: 1 << 7,
21
- ip_source_address: 0,
22
- ip_source_address0: 1 << 8,
23
- ip_source_address1: 1 << 9,
24
- ip_source_address2: 1 << 10,
25
- ip_source_address3: 1 << 11,
26
- ip_source_address4: 1 << 12,
27
- ip_source_address_all: 1 << 13,
28
- ip_destination_address: 0,
29
- ip_destination_address0: 1 << 14,
30
- ip_destination_address1: 1 << 15,
31
- ip_destination_address2: 1 << 16,
32
- ip_destination_address3: 1 << 17,
33
- ip_destination_address4: 1 << 18,
34
- ip_destination_address_all: 1 << 19,
35
- vlan_priority: 1 << 20,
36
- ip_tos: 1 << 21
37
- }
38
- NW_FLAGS = [:ip_source_address, :ip_destination_address]
39
- FLAGS = BITS.keys.select { |each| !(/^ip_(source|destination)/=~ each) }
40
-
41
- endian :big
42
-
43
- uint32 :flags
8
+ module OpenFlow10
9
+ # Fields to match against flows
10
+ class Match
11
+ # Flow wildcards
12
+ class Wildcards < BinData::Primitive
13
+ BITS = {
14
+ in_port: 1 << 0,
15
+ vlan_vid: 1 << 1,
16
+ ether_source_address: 1 << 2,
17
+ ether_destination_address: 1 << 3,
18
+ ether_type: 1 << 4,
19
+ ip_protocol: 1 << 5,
20
+ transport_source_port: 1 << 6,
21
+ transport_destination_port: 1 << 7,
22
+ ip_source_address: 0,
23
+ ip_source_address0: 1 << 8,
24
+ ip_source_address1: 1 << 9,
25
+ ip_source_address2: 1 << 10,
26
+ ip_source_address3: 1 << 11,
27
+ ip_source_address4: 1 << 12,
28
+ ip_source_address_all: 1 << 13,
29
+ ip_destination_address: 0,
30
+ ip_destination_address0: 1 << 14,
31
+ ip_destination_address1: 1 << 15,
32
+ ip_destination_address2: 1 << 16,
33
+ ip_destination_address3: 1 << 17,
34
+ ip_destination_address4: 1 << 18,
35
+ ip_destination_address_all: 1 << 19,
36
+ vlan_priority: 1 << 20,
37
+ ip_tos: 1 << 21
38
+ }
39
+ NW_FLAGS = [:ip_source_address, :ip_destination_address]
40
+ FLAGS = BITS.keys.select { |each| !(/^ip_(source|destination)/=~ each) }
41
+
42
+ endian :big
43
+
44
+ uint32 :flags
45
+
46
+ # This method smells of :reek:FeatureEnvy
47
+ def get
48
+ BITS.each_with_object(Hash.new(0)) do |(key, bit), memo|
49
+ next if flags & bit == 0
50
+ if /(ip_source_address|ip_destination_address)(\d)/=~ key
51
+ memo[$LAST_MATCH_INFO[1].intern] |= 1 << $LAST_MATCH_INFO[2].to_i
52
+ else
53
+ memo[key] = true
54
+ end
55
+ end
56
+ end
44
57
 
45
- # This method smells of :reek:FeatureEnvy
46
- def get
47
- BITS.each_with_object(Hash.new(0)) do |(key, bit), memo|
48
- next if flags & bit == 0
49
- if /(ip_source_address|ip_destination_address)(\d)/=~ key
50
- memo[$LAST_MATCH_INFO[1].intern] |= 1 << $LAST_MATCH_INFO[2].to_i
51
- else
52
- memo[key] = true
58
+ def set(params)
59
+ self.flags = params.inject(0) do |memo, (key, val)|
60
+ memo | case key
61
+ when :ip_source_address, :ip_destination_address
62
+ (params.fetch(key) & 31) <<
63
+ (key == :ip_source_address ? 8 : 14)
64
+ else
65
+ val ? BITS.fetch(key) : 0
66
+ end
53
67
  end
54
68
  end
55
- end
56
69
 
57
- def set(params)
58
- self.flags = params.inject(0) do |memo, (key, val)|
59
- memo | case key
60
- when :ip_source_address, :ip_destination_address
61
- (params.fetch(key) & 31) <<
62
- (key == :ip_source_address ? 8 : 14)
63
- else
64
- val ? BITS.fetch(key) : 0
65
- end
70
+ def ip_source_address
71
+ get.fetch(:ip_source_address)
72
+ rescue KeyError
73
+ 0
66
74
  end
67
- end
68
75
 
69
- def ip_source_address
70
- get.fetch(:ip_source_address)
71
- rescue KeyError
72
- 0
76
+ def ip_destination_address
77
+ get.fetch(:ip_destination_address)
78
+ rescue KeyError
79
+ 0
80
+ end
73
81
  end
74
82
 
75
- def ip_destination_address
76
- get.fetch(:ip_destination_address)
77
- rescue KeyError
78
- 0
79
- end
80
- end
83
+ # IP address
84
+ class MatchIpAddress < BinData::Primitive
85
+ default_parameter bitcount: 0
81
86
 
82
- # IP address
83
- class MatchIpAddress < BinData::Primitive
84
- default_parameter bitcount: 0
87
+ array :octets, type: :uint8, initial_length: 4
85
88
 
86
- array :octets, type: :uint8, initial_length: 4
89
+ def set(value)
90
+ self.octets = IPv4Address.new(value).to_a
91
+ end
87
92
 
88
- def set(value)
89
- self.octets = IPv4Address.new(value).to_a
90
- end
93
+ def get
94
+ ipaddr = octets.map { |each| format('%d', each) }.join('.')
95
+ prefixlen = 32 - eval_parameter(:bitcount)
96
+ IPv4Address.new(ipaddr + "/#{prefixlen}")
97
+ end
91
98
 
92
- def get
93
- ipaddr = octets.map { |each| format('%d', each) }.join('.')
94
- prefixlen = 32 - eval_parameter(:bitcount)
95
- IPv4Address.new(ipaddr + "/#{prefixlen}")
99
+ def ==(other)
100
+ get == other
101
+ end
96
102
  end
97
103
 
98
- def ==(other)
99
- get == other
104
+ # ofp_match format
105
+ class MatchFormat < BinData::Record
106
+ endian :big
107
+
108
+ wildcards :wildcards
109
+ uint16 :in_port
110
+ mac_address :ether_source_address
111
+ mac_address :ether_destination_address
112
+ uint16 :vlan_vid
113
+ uint8 :vlan_priority
114
+ uint8 :padding1
115
+ hide :padding1
116
+ uint16 :ether_type
117
+ uint8 :ip_tos
118
+ uint8 :ip_protocol
119
+ uint16 :padding2
120
+ hide :padding2
121
+ match_ip_address :ip_source_address,
122
+ bitcount: -> { wildcards.ip_source_address }
123
+ match_ip_address :ip_destination_address,
124
+ bitcount: -> { wildcards.ip_destination_address }
125
+ uint16 :transport_source_port
126
+ uint16 :transport_destination_port
100
127
  end
101
- end
102
128
 
103
- # ofp_match format
104
- class MatchFormat < BinData::Record
105
- endian :big
106
-
107
- wildcards :wildcards
108
- uint16 :in_port
109
- mac_address :ether_source_address
110
- mac_address :ether_destination_address
111
- uint16 :vlan_vid
112
- uint8 :vlan_priority
113
- uint8 :padding1
114
- hide :padding1
115
- uint16 :ether_type
116
- uint8 :ip_tos
117
- uint8 :ip_protocol
118
- uint16 :padding2
119
- hide :padding2
120
- match_ip_address :ip_source_address,
121
- bitcount: -> { wildcards.ip_source_address }
122
- match_ip_address :ip_destination_address,
123
- bitcount: -> { wildcards.ip_destination_address }
124
- uint16 :transport_source_port
125
- uint16 :transport_destination_port
126
- end
127
-
128
- def self.read(binary)
129
- MatchFormat.read binary
130
- end
131
-
132
- # rubocop:disable MethodLength
133
- # This method smells of :reek:FeatureEnvy
134
- # This method smells of :reek:DuplicateMethodCall
135
- def initialize(user_options)
136
- flags = Wildcards::FLAGS.each_with_object({}) do |each, memo|
137
- memo[each] = true unless user_options.key?(each)
129
+ def self.read(binary)
130
+ MatchFormat.read binary
138
131
  end
139
- Wildcards::NW_FLAGS.each_with_object(flags) do |each, memo|
140
- if user_options.key?(each)
141
- memo[each] = 32 - IPv4Address.new(user_options[each]).prefixlen
142
- else
143
- memo["#{each}_all".intern] = true
132
+
133
+ # rubocop:disable MethodLength
134
+ # This method smells of :reek:FeatureEnvy
135
+ # This method smells of :reek:DuplicateMethodCall
136
+ def initialize(user_options)
137
+ flags = Wildcards::FLAGS.each_with_object({}) do |each, memo|
138
+ memo[each] = true unless user_options.key?(each)
139
+ end
140
+ Wildcards::NW_FLAGS.each_with_object(flags) do |each, memo|
141
+ if user_options.key?(each)
142
+ memo[each] = 32 - IPv4Address.new(user_options[each]).prefixlen
143
+ else
144
+ memo["#{each}_all".intern] = true
145
+ end
144
146
  end
147
+ @format = MatchFormat.new({ wildcards: flags }.merge user_options)
145
148
  end
146
- @format = MatchFormat.new({ wildcards: flags }.merge user_options)
147
- end
148
- # rubocop:enable MethodLength
149
+ # rubocop:enable MethodLength
149
150
 
150
- def to_binary
151
- @format.to_binary_s
152
- end
151
+ def to_binary
152
+ @format.to_binary_s
153
+ end
153
154
 
154
- def ==(other)
155
- return false unless other
156
- to_binary == other.to_binary
157
- end
155
+ def ==(other)
156
+ return false unless other
157
+ to_binary == other.to_binary
158
+ end
158
159
 
159
- def method_missing(method, *args, &block)
160
- @format.__send__ method, *args, &block
160
+ def method_missing(method, *args, &block)
161
+ @format.__send__ method, *args, &block
162
+ end
161
163
  end
162
164
  end
163
165
  end