pio 0.10.1 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -13,6 +13,8 @@ describe Pio::PacketIn do
13
13
  end
14
14
 
15
15
  describe '.read' do
16
+ When(:result) { Pio::PacketIn.read(binary) }
17
+
16
18
  context 'with a packet_in message' do
17
19
  Given(:header_dump) do
18
20
  [
@@ -31,28 +33,25 @@ describe Pio::PacketIn do
31
33
  0x00
32
34
  ].pack('C*') + data_dump
33
35
  end
34
-
35
- When(:packet_in) do
36
- Pio::PacketIn.read(header_dump + body_dump)
37
- end
38
-
39
- Then { packet_in.class == Pio::PacketIn }
40
- Then { packet_in.ofp_version == 0x1 }
41
- Then { packet_in.message_type == 0xa }
42
- Then { packet_in.message_length == 0x4e }
43
- Then { packet_in.transaction_id == 0 }
44
- Then { packet_in.xid == 0 }
45
-
46
- Then { !packet_in.body.empty? }
47
- Then { packet_in.buffer_id == 0xffffff00 }
48
- Then { packet_in.total_len == 0x3c }
49
- Then { packet_in.in_port == 1 }
50
- Then { packet_in.reason == :no_match }
51
- Then { packet_in.data == data_dump }
36
+ Given(:binary) { header_dump + body_dump }
37
+
38
+ Then { result.class == Pio::PacketIn }
39
+ Then { result.ofp_version == 0x1 }
40
+ Then { result.message_type == 0xa }
41
+ Then { result.message_length == 0x4e }
42
+ Then { result.transaction_id == 0 }
43
+ Then { result.xid == 0 }
44
+
45
+ Then { !result.body.empty? }
46
+ Then { result.buffer_id == 0xffffff00 }
47
+ Then { result.total_len == 0x3c }
48
+ Then { result.in_port == 1 }
49
+ Then { result.reason == :no_match }
50
+ Then { result.data == data_dump }
52
51
  end
53
52
 
54
- context 'with a packet_in message generated with PacketIn.new' do
55
- Given(:packet_in_dump) do
53
+ context 'with a Packet-In message generated with PacketIn.new' do
54
+ Given(:binary) do
56
55
  Pio::PacketIn.new(
57
56
  transaction_id: 0,
58
57
  buffer_id: 0xffffff00,
@@ -61,30 +60,28 @@ describe Pio::PacketIn do
61
60
  data: data_dump
62
61
  ).to_binary
63
62
  end
64
- When(:packet_in) { Pio::PacketIn.read(packet_in_dump) }
65
-
66
- Then { packet_in.class == Pio::PacketIn }
67
- Then { packet_in.ofp_version == 0x1 }
68
- Then { packet_in.message_type == 0xa }
69
- Then { packet_in.message_length == 0x4e }
70
- Then { packet_in.transaction_id == 0 }
71
- Then { packet_in.xid == 0 }
72
63
 
73
- Then { !packet_in.body.empty? }
74
- Then { packet_in.buffer_id == 0xffffff00 }
75
- Then { packet_in.total_len == 0x3c }
76
- Then { packet_in.in_port == 1 }
77
- Then { packet_in.reason == :no_match }
78
- Then { packet_in.data == data_dump }
64
+ Then { result.class == Pio::PacketIn }
65
+ Then { result.ofp_version == 0x1 }
66
+ Then { result.message_type == 0xa }
67
+ Then { result.message_length == 0x4e }
68
+ Then { result.transaction_id == 0 }
69
+ Then { result.xid == 0 }
70
+
71
+ Then { !result.body.empty? }
72
+ Then { result.buffer_id == 0xffffff00 }
73
+ Then { result.total_len == 0x3c }
74
+ Then { result.in_port == 1 }
75
+ Then { result.reason == :no_match }
76
+ Then { result.data == data_dump }
79
77
  end
80
78
 
81
79
  context 'with a Hello message' do
82
- Given(:hello_dump) { [1, 0, 0, 8, 0, 0, 0, 0].pack('C*') }
83
-
84
- When(:result) { Pio::PacketIn.read(hello_dump) }
80
+ Given(:binary) { [1, 0, 0, 8, 0, 0, 0, 0].pack('C*') }
85
81
 
86
82
  Then do
87
- result == Failure(Pio::ParseError, 'Invalid Packet-In message.')
83
+ result == Failure(Pio::ParseError,
84
+ 'Invalid PacketIn message.')
88
85
  end
89
86
  end
90
87
  end
@@ -9,7 +9,6 @@ describe Pio::PacketOut do
9
9
  0x00, 0x00, 0x00, 0x16
10
10
  ].pack('C*')
11
11
  end
12
-
13
12
  Given(:data_dump) do
14
13
  [
15
14
  0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e, 0x01, 0x02, 0x03, 0x04,
@@ -21,7 +20,6 @@ describe Pio::PacketOut do
21
20
  0x00, 0x00, 0x00, 0x00
22
21
  ].pack('C*')
23
22
  end
24
-
25
23
  Given(:body_dump) do
26
24
  [
27
25
  0xff, 0xff, 0xff, 0xff,
@@ -31,260 +29,323 @@ describe Pio::PacketOut do
31
29
  ].pack('C*') + data_dump
32
30
  end
33
31
 
34
- Given(:packet_out_dump) { header_dump + body_dump }
35
-
36
32
  describe '.read' do
33
+ When(:result) { Pio::PacketOut.read(binary) }
34
+
37
35
  context 'with a Packet-Out message' do
38
- When(:packet_out) do
39
- Pio::PacketOut.read(packet_out_dump)
36
+ When(:binary) { header_dump + body_dump }
37
+
38
+ Then { result.class == Pio::PacketOut }
39
+ Then { result.ofp_version == 0x1 }
40
+ Then { result.message_type == 0xd }
41
+ Then { result.message_length == 0x58 }
42
+ Then { result.transaction_id == 0x16 }
43
+ Then { result.xid == 0x16 }
44
+
45
+ Then { !result.body.empty? }
46
+ Then { result.buffer_id == 0xffffffff }
47
+ Then { result.in_port == 0xffff }
48
+ Then { result.actions_len == 0x8 }
49
+ Then { result.actions.length == 1 }
50
+ Then { result.actions[0].is_a? Pio::SendOutPort }
51
+ Then { result.actions[0].port_number == 2 }
52
+ Then { result.actions[0].max_len == 2**16 - 1 }
53
+ Then { result.data.length == 64 }
54
+ end
55
+
56
+ context 'with a Packet-Out message generated with PacketOut.new' do
57
+ When(:binary) do
58
+ Pio::PacketOut.new(
59
+ transaction_id: 0x16,
60
+ buffer_id: 0xffffffff,
61
+ in_port: 0xffff,
62
+ actions: Pio::SendOutPort.new(2),
63
+ data: data_dump
64
+ ).to_binary
40
65
  end
41
66
 
42
- Then { packet_out.class == Pio::PacketOut }
43
- Then { packet_out.ofp_version == 0x1 }
44
- Then { packet_out.message_type == 0xd }
45
- Then { packet_out.message_length == 0x58 }
46
- Then { packet_out.transaction_id == 0x16 }
47
- Then { packet_out.xid == 0x16 }
48
-
49
- Then { !packet_out.body.empty? }
50
- Then { packet_out.buffer_id == 0xffffffff }
51
- Then { packet_out.in_port == 0xffff }
52
- Then { packet_out.actions_len == 0x8 }
53
- Then { packet_out.actions.length == 1 }
54
- Then { packet_out.actions[0].is_a? Pio::SendOutPort }
55
- Then { packet_out.actions[0].port_number == 2 }
56
- Then { packet_out.actions[0].max_len == 2**16 - 1 }
57
- Then { packet_out.data.length == 64 }
67
+ Then { result.class == Pio::PacketOut }
68
+ Then { result.ofp_version == 0x1 }
69
+ Then { result.message_type == 0xd }
70
+ Then { result.message_length == 0x58 }
71
+ Then { result.transaction_id == 0x16 }
72
+ Then { result.xid == 0x16 }
73
+
74
+ Then { !result.body.empty? }
75
+ Then { result.buffer_id == 0xffffffff }
76
+ Then { result.in_port == 0xffff }
77
+ Then { result.actions_len == 0x8 }
78
+ Then { result.actions.length == 1 }
79
+ Then { result.actions[0].is_a? Pio::SendOutPort }
80
+ Then { result.actions[0].port_number == 2 }
81
+ Then { result.actions[0].max_len == 2**16 - 1 }
82
+ Then { result.data.length == 64 }
83
+ end
84
+
85
+ context 'with a Hello message' do
86
+ When(:binary) { [1, 0, 0, 8, 0, 0, 0, 0].pack('C*') }
87
+
88
+ Then do
89
+ result == Failure(Pio::ParseError,
90
+ 'Invalid PacketOut message.')
91
+ end
58
92
  end
59
93
  end
60
94
 
61
95
  describe '.new' do
96
+ When(:result) { Pio::PacketOut.new(user_options) }
97
+
62
98
  context 'with a SendOutPort action' do
63
- Given(:packet_out) do
64
- Pio::PacketOut.new(transaction_id: 0x16,
65
- buffer_id: 0xffffffff,
66
- in_port: 0xffff,
67
- actions: Pio::SendOutPort.new(2),
68
- data: data_dump)
99
+ When(:user_options) do
100
+ {
101
+ transaction_id: 0x16,
102
+ buffer_id: 0xffffffff,
103
+ in_port: 0xffff,
104
+ actions: Pio::SendOutPort.new(2),
105
+ data: data_dump
106
+ }
69
107
  end
70
108
 
71
- Then { packet_out.ofp_version == 0x1 }
72
- Then { packet_out.message_type == 0xd }
73
- Then { packet_out.message_length == 0x58 }
74
- Then { packet_out.transaction_id == 0x16 }
75
- Then { packet_out.xid == 0x16 }
76
-
77
- Then { !packet_out.body.empty? }
78
- Then { packet_out.buffer_id == 0xffffffff }
79
- Then { packet_out.in_port == 0xffff }
80
- Then { packet_out.actions_len == 0x8 }
81
- Then { packet_out.actions.length == 1 }
82
- Then { packet_out.actions[0].is_a? Pio::SendOutPort }
83
- Then { packet_out.actions[0].port_number == 2 }
84
- Then { packet_out.actions[0].max_len == 2**16 - 1 }
85
- Then { packet_out.data.length == 64 }
109
+ Then { result.ofp_version == 0x1 }
110
+ Then { result.message_type == 0xd }
111
+ Then { result.message_length == 0x58 }
112
+ Then { result.transaction_id == 0x16 }
113
+ Then { result.xid == 0x16 }
114
+
115
+ Then { !result.body.empty? }
116
+ Then { result.buffer_id == 0xffffffff }
117
+ Then { result.in_port == 0xffff }
118
+ Then { result.actions_len == 0x8 }
119
+ Then { result.actions.length == 1 }
120
+ Then { result.actions[0].is_a? Pio::SendOutPort }
121
+ Then { result.actions[0].port_number == 2 }
122
+ Then { result.actions[0].max_len == 2**16 - 1 }
123
+ Then { result.data.length == 64 }
86
124
 
87
125
  context '#to_binary' do
88
- When(:binary) { packet_out.to_binary }
89
- Then { binary == packet_out_dump }
126
+ When(:binary) { result.to_binary }
127
+
128
+ Then { binary == header_dump + body_dump }
90
129
  end
91
130
  end
92
131
 
93
132
  context 'with a SetVlanVid action' do
94
- Given(:packet_out) do
95
- Pio::PacketOut.new(transaction_id: 0x16,
96
- buffer_id: 0xffffffff,
97
- in_port: 0xffff,
98
- actions: Pio::SetVlanVid.new(10),
99
- data: data_dump)
133
+ When(:user_options) do
134
+ {
135
+ transaction_id: 0x16,
136
+ buffer_id: 0xffffffff,
137
+ in_port: 0xffff,
138
+ actions: Pio::SetVlanVid.new(10),
139
+ data: data_dump
140
+ }
100
141
  end
101
142
 
102
- Then { packet_out.message_length == 0x58 }
103
- Then { packet_out.actions_len == 0x8 }
104
- Then { packet_out.actions.length == 1 }
105
- Then { packet_out.actions[0].is_a? Pio::SetVlanVid }
106
- Then { packet_out.actions[0].vlan_id == 10 }
143
+ Then { result.message_length == 0x58 }
144
+ Then { result.actions_len == 0x8 }
145
+ Then { result.actions.length == 1 }
146
+ Then { result.actions[0].is_a? Pio::SetVlanVid }
147
+ Then { result.actions[0].vlan_id == 10 }
107
148
  end
108
149
 
109
150
  context 'with a SetVlanPriority action' do
110
- Given(:packet_out) do
111
- Pio::PacketOut.new(transaction_id: 0x16,
112
- buffer_id: 0xffffffff,
113
- in_port: 0xffff,
114
- actions: Pio::SetVlanPriority.new(3),
115
- data: data_dump)
151
+ When(:user_options) do
152
+ {
153
+ transaction_id: 0x16,
154
+ buffer_id: 0xffffffff,
155
+ in_port: 0xffff,
156
+ actions: Pio::SetVlanPriority.new(3),
157
+ data: data_dump
158
+ }
116
159
  end
117
160
 
118
- Then { packet_out.message_length == 0x58 }
119
- Then { packet_out.actions_len == 0x8 }
120
- Then { packet_out.actions.length == 1 }
121
- Then { packet_out.actions[0].is_a? Pio::SetVlanPriority }
122
- Then { packet_out.actions[0].vlan_priority == 3 }
161
+ Then { result.message_length == 0x58 }
162
+ Then { result.actions_len == 0x8 }
163
+ Then { result.actions.length == 1 }
164
+ Then { result.actions[0].is_a? Pio::SetVlanPriority }
165
+ Then { result.actions[0].vlan_priority == 3 }
123
166
  end
124
167
 
125
168
  context 'with a StripVlanHeader action' do
126
- Given(:packet_out) do
127
- Pio::PacketOut.new(transaction_id: 0x16,
128
- buffer_id: 0xffffffff,
129
- in_port: 0xffff,
130
- actions: Pio::StripVlanHeader.new,
131
- data: data_dump)
169
+ When(:user_options) do
170
+ {
171
+ transaction_id: 0x16,
172
+ buffer_id: 0xffffffff,
173
+ in_port: 0xffff,
174
+ actions: Pio::StripVlanHeader.new,
175
+ data: data_dump
176
+ }
132
177
  end
133
178
 
134
- Then { packet_out.message_length == 0x58 }
135
- Then { packet_out.actions_len == 0x8 }
136
- Then { packet_out.actions.length == 1 }
137
- Then { packet_out.actions[0].is_a? Pio::StripVlanHeader }
179
+ Then { result.message_length == 0x58 }
180
+ Then { result.actions_len == 0x8 }
181
+ Then { result.actions.length == 1 }
182
+ Then { result.actions[0].is_a? Pio::StripVlanHeader }
138
183
  end
139
184
 
140
185
  context 'with a SetEthSrcAddr action' do
141
- Given(:packet_out) do
142
- Pio::PacketOut.new(transaction_id: 0x16,
143
- buffer_id: 0xffffffff,
144
- in_port: 0xffff,
145
- actions: Pio::SetEthSrcAddr.new('11:22:33:44:55:66'),
146
- data: data_dump)
186
+ When(:user_options) do
187
+ {
188
+ transaction_id: 0x16,
189
+ buffer_id: 0xffffffff,
190
+ in_port: 0xffff,
191
+ actions: Pio::SetEthSrcAddr.new('11:22:33:44:55:66'),
192
+ data: data_dump
193
+ }
147
194
  end
148
195
 
149
- Then { packet_out.message_length == 0x60 }
150
- Then { packet_out.actions_len == 0x10 }
151
- Then { packet_out.actions.length == 1 }
152
- Then { packet_out.actions[0].is_a? Pio::SetEthSrcAddr }
153
- Then { packet_out.actions[0].mac_address == '11:22:33:44:55:66' }
196
+ Then { result.message_length == 0x60 }
197
+ Then { result.actions_len == 0x10 }
198
+ Then { result.actions.length == 1 }
199
+ Then { result.actions[0].is_a? Pio::SetEthSrcAddr }
200
+ Then { result.actions[0].mac_address == '11:22:33:44:55:66' }
154
201
  end
155
202
 
156
203
  context 'with a SetEthDstAddr action' do
157
- Given(:packet_out) do
158
- Pio::PacketOut.new(transaction_id: 0x16,
159
- buffer_id: 0xffffffff,
160
- in_port: 0xffff,
161
- actions: Pio::SetEthDstAddr.new('11:22:33:44:55:66'),
162
- data: data_dump)
204
+ When(:user_options) do
205
+ {
206
+ transaction_id: 0x16,
207
+ buffer_id: 0xffffffff,
208
+ in_port: 0xffff,
209
+ actions: Pio::SetEthDstAddr.new('11:22:33:44:55:66'),
210
+ data: data_dump
211
+ }
163
212
  end
164
213
 
165
- Then { packet_out.message_length == 0x60 }
166
- Then { packet_out.actions_len == 0x10 }
167
- Then { packet_out.actions.length == 1 }
168
- Then { packet_out.actions[0].is_a? Pio::SetEthDstAddr }
169
- Then { packet_out.actions[0].mac_address == '11:22:33:44:55:66' }
214
+ Then { result.message_length == 0x60 }
215
+ Then { result.actions_len == 0x10 }
216
+ Then { result.actions.length == 1 }
217
+ Then { result.actions[0].is_a? Pio::SetEthDstAddr }
218
+ Then { result.actions[0].mac_address == '11:22:33:44:55:66' }
170
219
  end
171
220
 
172
221
  context 'with a SetIpSrcAddr action' do
173
- Given(:packet_out) do
174
- Pio::PacketOut.new(transaction_id: 0x16,
175
- buffer_id: 0xffffffff,
176
- in_port: 0xffff,
177
- actions: Pio::SetIpSrcAddr.new('1.2.3.4'),
178
- data: data_dump)
222
+ When(:user_options) do
223
+ {
224
+ transaction_id: 0x16,
225
+ buffer_id: 0xffffffff,
226
+ in_port: 0xffff,
227
+ actions: Pio::SetIpSrcAddr.new('1.2.3.4'),
228
+ data: data_dump
229
+ }
179
230
  end
180
231
 
181
- Then { packet_out.message_length == 0x58 }
182
- Then { packet_out.actions_len == 0x8 }
183
- Then { packet_out.actions.length == 1 }
184
- Then { packet_out.actions[0].is_a? Pio::SetIpSrcAddr }
185
- Then { packet_out.actions[0].ip_address == '1.2.3.4' }
232
+ Then { result.message_length == 0x58 }
233
+ Then { result.actions_len == 0x8 }
234
+ Then { result.actions.length == 1 }
235
+ Then { result.actions[0].is_a? Pio::SetIpSrcAddr }
236
+ Then { result.actions[0].ip_address == '1.2.3.4' }
186
237
  end
187
238
 
188
239
  context 'with a SetIpDstAddr action' do
189
- Given(:packet_out) do
190
- Pio::PacketOut.new(transaction_id: 0x16,
191
- buffer_id: 0xffffffff,
192
- in_port: 0xffff,
193
- actions: Pio::SetIpDstAddr.new('1.2.3.4'),
194
- data: data_dump)
240
+ When(:user_options) do
241
+ {
242
+ transaction_id: 0x16,
243
+ buffer_id: 0xffffffff,
244
+ in_port: 0xffff,
245
+ actions: Pio::SetIpDstAddr.new('1.2.3.4'),
246
+ data: data_dump
247
+ }
195
248
  end
196
249
 
197
- Then { packet_out.message_length == 0x58 }
198
- Then { packet_out.actions_len == 0x8 }
199
- Then { packet_out.actions.length == 1 }
200
- Then { packet_out.actions[0].is_a? Pio::SetIpDstAddr }
201
- Then { packet_out.actions[0].ip_address == '1.2.3.4' }
250
+ Then { result.message_length == 0x58 }
251
+ Then { result.actions_len == 0x8 }
252
+ Then { result.actions.length == 1 }
253
+ Then { result.actions[0].is_a? Pio::SetIpDstAddr }
254
+ Then { result.actions[0].ip_address == '1.2.3.4' }
202
255
  end
203
256
 
204
257
  context 'with a SetIpTos action' do
205
- Given(:packet_out) do
206
- Pio::PacketOut.new(transaction_id: 0x16,
207
- buffer_id: 0xffffffff,
208
- in_port: 0xffff,
209
- actions: Pio::SetIpTos.new(32),
210
- data: data_dump)
258
+ When(:user_options) do
259
+ {
260
+ transaction_id: 0x16,
261
+ buffer_id: 0xffffffff,
262
+ in_port: 0xffff,
263
+ actions: Pio::SetIpTos.new(32),
264
+ data: data_dump
265
+ }
211
266
  end
212
267
 
213
- Then { packet_out.message_length == 0x58 }
214
- Then { packet_out.actions_len == 0x8 }
215
- Then { packet_out.actions.length == 1 }
216
- Then { packet_out.actions[0].is_a? Pio::SetIpTos }
217
- Then { packet_out.actions[0].type_of_service == 32 }
268
+ Then { result.message_length == 0x58 }
269
+ Then { result.actions_len == 0x8 }
270
+ Then { result.actions.length == 1 }
271
+ Then { result.actions[0].is_a? Pio::SetIpTos }
272
+ Then { result.actions[0].type_of_service == 32 }
218
273
  end
219
274
 
220
275
  context 'with a SetTransportSrcPort action' do
221
- Given(:packet_out) do
222
- Pio::PacketOut.new(transaction_id: 0x16,
223
- buffer_id: 0xffffffff,
224
- in_port: 0xffff,
225
- actions: Pio::SetTransportSrcPort.new(100),
226
- data: data_dump)
276
+ When(:user_options) do
277
+ {
278
+ transaction_id: 0x16,
279
+ buffer_id: 0xffffffff,
280
+ in_port: 0xffff,
281
+ actions: Pio::SetTransportSrcPort.new(100),
282
+ data: data_dump
283
+ }
227
284
  end
228
285
 
229
- Then { packet_out.message_length == 0x58 }
230
- Then { packet_out.actions_len == 0x8 }
231
- Then { packet_out.actions.length == 1 }
232
- Then { packet_out.actions[0].is_a? Pio::SetTransportSrcPort }
233
- Then { packet_out.actions[0].port_number == 100 }
286
+ Then { result.message_length == 0x58 }
287
+ Then { result.actions_len == 0x8 }
288
+ Then { result.actions.length == 1 }
289
+ Then { result.actions[0].is_a? Pio::SetTransportSrcPort }
290
+ Then { result.actions[0].port_number == 100 }
234
291
  end
235
292
 
236
293
  context 'with a SetTransportDstPort action' do
237
- Given(:packet_out) do
238
- Pio::PacketOut.new(transaction_id: 0x16,
239
- buffer_id: 0xffffffff,
240
- in_port: 0xffff,
241
- actions: Pio::SetTransportDstPort.new(100),
242
- data: data_dump)
294
+ When(:user_options) do
295
+ {
296
+ transaction_id: 0x16,
297
+ buffer_id: 0xffffffff,
298
+ in_port: 0xffff,
299
+ actions: Pio::SetTransportDstPort.new(100),
300
+ data: data_dump
301
+ }
243
302
  end
244
303
 
245
- Then { packet_out.message_length == 0x58 }
246
- Then { packet_out.actions_len == 0x8 }
247
- Then { packet_out.actions.length == 1 }
248
- Then { packet_out.actions[0].is_a? Pio::SetTransportDstPort }
249
- Then { packet_out.actions[0].port_number == 100 }
304
+ Then { result.message_length == 0x58 }
305
+ Then { result.actions_len == 0x8 }
306
+ Then { result.actions.length == 1 }
307
+ Then { result.actions[0].is_a? Pio::SetTransportDstPort }
308
+ Then { result.actions[0].port_number == 100 }
250
309
  end
251
310
 
252
311
  context 'with a Enqueue action' do
253
- Given(:packet_out) do
254
- Pio::PacketOut.new(transaction_id: 0x16,
255
- buffer_id: 0xffffffff,
256
- in_port: 0xffff,
257
- actions: Pio::Enqueue.new(port_number: 1,
258
- queue_id: 2),
259
- data: data_dump)
312
+ When(:user_options) do
313
+ {
314
+ transaction_id: 0x16,
315
+ buffer_id: 0xffffffff,
316
+ in_port: 0xffff,
317
+ actions: Pio::Enqueue.new(port_number: 1, queue_id: 2),
318
+ data: data_dump
319
+ }
260
320
  end
261
321
 
262
- Then { packet_out.message_length == 0x60 }
263
- Then { packet_out.actions_len == 0x10 }
264
- Then { packet_out.actions.length == 1 }
265
- Then { packet_out.actions[0].is_a? Pio::Enqueue }
266
- Then { packet_out.actions[0].port_number == 1 }
267
- Then { packet_out.actions[0].queue_id == 2 }
322
+ Then { result.message_length == 0x60 }
323
+ Then { result.actions_len == 0x10 }
324
+ Then { result.actions.length == 1 }
325
+ Then { result.actions[0].is_a? Pio::Enqueue }
326
+ Then { result.actions[0].port_number == 1 }
327
+ Then { result.actions[0].queue_id == 2 }
268
328
  end
269
329
 
270
330
  context 'with SendOutPort and SetVlanVid action' do
271
- Given(:packet_out) do
272
- Pio::PacketOut.new(transaction_id: 0x16,
273
- buffer_id: 0xffffffff,
274
- in_port: 0xffff,
275
- actions: [Pio::SendOutPort.new(2),
276
- Pio::SetVlanVid.new(10)],
277
- data: data_dump)
331
+ When(:user_options) do
332
+ {
333
+ transaction_id: 0x16,
334
+ buffer_id: 0xffffffff,
335
+ in_port: 0xffff,
336
+ actions: [Pio::SendOutPort.new(2), Pio::SetVlanVid.new(10)],
337
+ data: data_dump
338
+ }
278
339
  end
279
340
 
280
- Then { packet_out.message_length == 0x60 }
281
- Then { packet_out.actions_len == 0x10 }
282
- Then { packet_out.actions.length == 2 }
283
- Then { packet_out.actions[0].is_a? Pio::SendOutPort }
284
- Then { packet_out.actions[0].port_number == 2 }
285
- Then { packet_out.actions[0].max_len == 2**16 - 1 }
286
- Then { packet_out.actions[1].is_a? Pio::SetVlanVid }
287
- Then { packet_out.actions[1].vlan_id == 10 }
341
+ Then { result.message_length == 0x60 }
342
+ Then { result.actions_len == 0x10 }
343
+ Then { result.actions.length == 2 }
344
+ Then { result.actions[0].is_a? Pio::SendOutPort }
345
+ Then { result.actions[0].port_number == 2 }
346
+ Then { result.actions[0].max_len == 2**16 - 1 }
347
+ Then { result.actions[1].is_a? Pio::SetVlanVid }
348
+ Then { result.actions[1].vlan_id == 10 }
288
349
  end
289
350
  end
290
351
  end