openflow-protocol 0.1.4 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/messages/echo_reply.rb +6 -0
- data/lib/openflow-protocol/version.rb +5 -0
- data/spec/actions/action_enqueue_spec.rb +30 -0
- data/spec/actions/action_output_spec.rb +29 -0
- data/spec/actions/action_set_destination_port_spec.rb +26 -0
- data/spec/actions/action_set_ip_destination_spec.rb +25 -0
- data/spec/actions/action_set_ip_source_spec.rb +25 -0
- data/spec/actions/action_set_ip_tos_spec.rb +26 -0
- data/spec/actions/action_set_mac_destination_spec.rb +26 -0
- data/spec/actions/action_set_mac_source_spec.rb +26 -0
- data/spec/actions/action_set_source_port_spec.rb +26 -0
- data/spec/actions/action_set_vlan_id_spec.rb +26 -0
- data/spec/actions/action_set_vlan_pcp_spec.rb +26 -0
- data/spec/actions/action_strip_vlan_spec.rb +17 -0
- data/spec/actions/action_vendor_spec.rb +25 -0
- data/spec/actions/actions_spec.rb +33 -0
- data/spec/messages/barrier_reply_spec.rb +25 -0
- data/spec/messages/barrier_request_spec.rb +25 -0
- data/spec/messages/echo_reply_spec.rb +44 -0
- data/spec/messages/echo_request_spec.rb +53 -0
- data/spec/messages/error_spec.rb +56 -0
- data/spec/messages/features_reply_spec.rb +204 -0
- data/spec/messages/features_request_spec.rb +25 -0
- data/spec/messages/flow_mod_spec.rb +139 -0
- data/spec/messages/flow_removed_spec.rb +109 -0
- data/spec/messages/get_config_reply_spec.rb +39 -0
- data/spec/messages/get_config_request_spec.rb +25 -0
- data/spec/messages/hello_spec.rb +25 -0
- data/spec/messages/packet_in_spec.rb +76 -0
- data/spec/messages/packet_out_spec.rb +56 -0
- data/spec/messages/parser_spec.rb +43 -0
- data/spec/messages/port_mod_spec.rb +64 -0
- data/spec/messages/port_status_spec.rb +52 -0
- data/spec/messages/set_config_spec.rb +39 -0
- data/spec/messages/statistics_reply_spec.rb +411 -0
- data/spec/messages/statistics_request_spec.rb +355 -0
- data/spec/messages/vendor_spec.rb +56 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/statistics/aggregate_statistics_reply_spec.rb +31 -0
- data/spec/statistics/aggregate_statistics_request_spec.rb +46 -0
- data/spec/statistics/description_statistics_spec.rb +38 -0
- data/spec/statistics/flow_statistics_reply_spec.rb +74 -0
- data/spec/statistics/flow_statistics_request_spec.rb +46 -0
- data/spec/statistics/port_statistics_reply_spec.rb +81 -0
- data/spec/statistics/port_statistics_request_spec.rb +19 -0
- data/spec/statistics/queue_statistics_reply_spec.rb +42 -0
- data/spec/statistics/queue_statistics_request_spec.rb +26 -0
- data/spec/statistics/table_statistics_spec.rb +54 -0
- data/spec/statistics/vendor_statistics_spec.rb +25 -0
- data/spec/structs/match_spec.rb +143 -0
- data/spec/structs/physical_port_spec.rb +63 -0
- data/spec/structs/port_number_spec.rb +19 -0
- metadata +109 -8
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OFSetConfig do
|
4
|
+
it 'should read binary' do
|
5
|
+
msg = OFSetConfig.read [
|
6
|
+
1, 9, 0, 12, 0, 0, 0, 1, # header
|
7
|
+
0, 0, # flags
|
8
|
+
0, 0xff # miss_send_length
|
9
|
+
].pack('C*')
|
10
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
11
|
+
expect(msg.type).to eq(:set_config)
|
12
|
+
expect(msg.len).to eq(12)
|
13
|
+
expect(msg.xid).to eq(1)
|
14
|
+
expect(msg.flags).to eq(:fragments_normal)
|
15
|
+
expect(msg.miss_send_length).to eq(0xff)
|
16
|
+
end
|
17
|
+
it 'should initialize with default values' do
|
18
|
+
msg = OFSetConfig.new
|
19
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
20
|
+
expect(msg.type).to eq(:set_config)
|
21
|
+
expect(msg.len).to eq(12)
|
22
|
+
expect(msg.xid).to eq(0)
|
23
|
+
expect(msg.flags).to eq(:fragments_normal)
|
24
|
+
expect(msg.miss_send_length).to eq(0)
|
25
|
+
end
|
26
|
+
it 'should initialize with some values' do
|
27
|
+
msg = OFSetConfig.new(
|
28
|
+
xid: 1,
|
29
|
+
flags: :fragments_normal,
|
30
|
+
miss_send_length: 0xff
|
31
|
+
)
|
32
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
33
|
+
expect(msg.type).to eq(:set_config)
|
34
|
+
expect(msg.len).to eq(12)
|
35
|
+
expect(msg.xid).to eq(1)
|
36
|
+
expect(msg.flags).to eq(:fragments_normal)
|
37
|
+
expect(msg.miss_send_length).to eq(0xff)
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,411 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OFStatisticsReply do
|
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 [
|
13
|
+
1, 17, 0x04, 0x2c, 0, 0, 0, 1, # header
|
14
|
+
0, 0, # statistic_type
|
15
|
+
0, 1, # flags
|
16
|
+
].pack('C*') + desc
|
17
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
18
|
+
expect(msg.type).to eq(:statistics_reply)
|
19
|
+
expect(msg.len).to eq(1068)
|
20
|
+
expect(msg.xid).to eq(1)
|
21
|
+
expect(msg.statistic_type).to eq(:description)
|
22
|
+
expect(msg.flags).to eq([:reply_more])
|
23
|
+
expect(msg.statistics.serial_number).to eq('123456789')
|
24
|
+
end
|
25
|
+
it 'should initialize with default values' do
|
26
|
+
msg = OFStatisticsReply.new
|
27
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
28
|
+
expect(msg.type).to eq(:statistics_reply)
|
29
|
+
expect(msg.len).to eq(1068)
|
30
|
+
expect(msg.xid).to eq(0)
|
31
|
+
expect(msg.statistic_type).to eq(:description)
|
32
|
+
expect(msg.flags).to be_empty
|
33
|
+
expect(msg.statistics.serial_number).to eq('')
|
34
|
+
end
|
35
|
+
it 'should initialize with some values' do
|
36
|
+
msg = OFStatisticsReply.new(
|
37
|
+
xid: 1,
|
38
|
+
statistic_type: :description,
|
39
|
+
flags: [:reply_more],
|
40
|
+
statistics: {
|
41
|
+
serial_number: '123456789'
|
42
|
+
}
|
43
|
+
)
|
44
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
45
|
+
expect(msg.type).to eq(:statistics_reply)
|
46
|
+
expect(msg.len).to eq(1068)
|
47
|
+
expect(msg.xid).to eq(1)
|
48
|
+
expect(msg.statistic_type).to eq(:description)
|
49
|
+
expect(msg.flags).to eq([:reply_more])
|
50
|
+
expect(msg.statistics.serial_number).to eq('123456789')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'with flow' do
|
55
|
+
it 'should read binary' do
|
56
|
+
msg = OFStatisticsReply.read [
|
57
|
+
1, 17, 0, 108, 0, 0, 0, 1, # header
|
58
|
+
0, 1, # statistic_type
|
59
|
+
0, 1, # flags
|
60
|
+
|
61
|
+
# flow_statistics_reply
|
62
|
+
0, 96, # len
|
63
|
+
1, # table_id
|
64
|
+
0, # padding
|
65
|
+
|
66
|
+
# match
|
67
|
+
0, 0x30, 0x20, 0x4f, # wildcards
|
68
|
+
0, 0, # in_port
|
69
|
+
0, 0, 0, 0, 0, 0, # mac_source
|
70
|
+
0, 0, 0, 0, 0, 0, # mac_destination
|
71
|
+
0xff, 0xff, # vlan_id
|
72
|
+
0, # vlan_pcp
|
73
|
+
0, # padding
|
74
|
+
8, 0, # mac_protocol
|
75
|
+
0, # ip_tos
|
76
|
+
6, # ip_protocol
|
77
|
+
0, 0, # padding
|
78
|
+
0, 0, 0, 0, # ip_source
|
79
|
+
192, 168, 0, 2, # ip_destination
|
80
|
+
0, 0, # source_port
|
81
|
+
0x0b, 0xb8, # destination_port
|
82
|
+
|
83
|
+
0, 0, 0, 50, # duration_seconds
|
84
|
+
0, 0, 0, 10, # duration_nanoseconds
|
85
|
+
0x0b, 0xb8, # priority
|
86
|
+
0, 100, # idle_timeout
|
87
|
+
1, 0x2c, # hard_timeout
|
88
|
+
0, 0, 0, 0, 0, 0, # padding
|
89
|
+
0, 0, 0, 0, 0, 0, 0, 1, # cookie
|
90
|
+
0, 0, 0, 0, 0, 0, 0, 10, # packet_count
|
91
|
+
0, 0, 0, 0, 0, 0, 0, 80, # byte_count
|
92
|
+
|
93
|
+
# actions
|
94
|
+
# output
|
95
|
+
0, 0, 0, 8, # header
|
96
|
+
0, 1, # port
|
97
|
+
0xff, 0xff # max_length
|
98
|
+
].pack('C*')
|
99
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
100
|
+
expect(msg.type).to eq(:statistics_reply)
|
101
|
+
expect(msg.len).to eq(108)
|
102
|
+
expect(msg.xid).to eq(1)
|
103
|
+
expect(msg.statistic_type).to eq(:flow)
|
104
|
+
expect(msg.flags).to eq([:reply_more])
|
105
|
+
expect(msg.statistics.table_id).to eq(1)
|
106
|
+
expect(msg.statistics.actions.length).to eq(1)
|
107
|
+
end
|
108
|
+
it 'should initialize with default values' do
|
109
|
+
msg = OFStatisticsReply.new(statistic_type: :flow)
|
110
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
111
|
+
expect(msg.type).to eq(:statistics_reply)
|
112
|
+
expect(msg.len).to eq(100)
|
113
|
+
expect(msg.xid).to eq(0)
|
114
|
+
expect(msg.statistic_type).to eq(:flow)
|
115
|
+
expect(msg.flags).to be_empty
|
116
|
+
expect(msg.statistics.table_id).to eq(:all)
|
117
|
+
expect(msg.statistics.actions).to be_empty
|
118
|
+
end
|
119
|
+
it 'should initialize with some values' do
|
120
|
+
msg = OFStatisticsReply.new(
|
121
|
+
xid: 1,
|
122
|
+
statistic_type: :flow,
|
123
|
+
flags: [:reply_more],
|
124
|
+
statistics: {
|
125
|
+
table_id: 1,
|
126
|
+
actions: [OFActionOutput.new(port: 1)]
|
127
|
+
}
|
128
|
+
)
|
129
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
130
|
+
expect(msg.type).to eq(:statistics_reply)
|
131
|
+
expect(msg.len).to eq(108)
|
132
|
+
expect(msg.xid).to eq(1)
|
133
|
+
expect(msg.statistic_type).to eq(:flow)
|
134
|
+
expect(msg.flags).to eq([:reply_more])
|
135
|
+
expect(msg.statistics.table_id).to eq(1)
|
136
|
+
expect(msg.statistics.actions.length).to eq(1)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'with aggregate' do
|
141
|
+
it 'should read binary' do
|
142
|
+
msg = OFStatisticsReply.read [
|
143
|
+
1, 17, 0, 36, 0, 0, 0, 1, # header
|
144
|
+
0, 2, # statistic_type
|
145
|
+
0, 1, # flags
|
146
|
+
|
147
|
+
# aggregate_statistics_reply
|
148
|
+
0, 0, 0, 0, 0, 0, 0, 10, # packet_count
|
149
|
+
0, 0, 0, 0, 0, 0, 0, 80, # byte_count
|
150
|
+
0, 0, 0, 4, # flow_count
|
151
|
+
0, 0, 0, 0 # padding
|
152
|
+
].pack('C*')
|
153
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
154
|
+
expect(msg.type).to eq(:statistics_reply)
|
155
|
+
expect(msg.len).to eq(36)
|
156
|
+
expect(msg.xid).to eq(1)
|
157
|
+
expect(msg.statistic_type).to eq(:aggregate)
|
158
|
+
expect(msg.flags).to eq([:reply_more])
|
159
|
+
expect(msg.statistics.packet_count).to eq(10)
|
160
|
+
end
|
161
|
+
it 'should initialize with default values' do
|
162
|
+
msg = OFStatisticsReply.new(statistic_type: :aggregate)
|
163
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
164
|
+
expect(msg.type).to eq(:statistics_reply)
|
165
|
+
expect(msg.len).to eq(36)
|
166
|
+
expect(msg.xid).to eq(0)
|
167
|
+
expect(msg.statistic_type).to eq(:aggregate)
|
168
|
+
expect(msg.flags).to be_empty
|
169
|
+
expect(msg.statistics.packet_count).to eq(0)
|
170
|
+
end
|
171
|
+
it 'should initialize with some values' do
|
172
|
+
msg = OFStatisticsReply.new(
|
173
|
+
xid: 1,
|
174
|
+
statistic_type: :aggregate,
|
175
|
+
flags: [:reply_more],
|
176
|
+
statistics: {
|
177
|
+
packet_count: 10,
|
178
|
+
byte_count: 80,
|
179
|
+
flow_count: 4
|
180
|
+
}
|
181
|
+
)
|
182
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
183
|
+
expect(msg.type).to eq(:statistics_reply)
|
184
|
+
expect(msg.len).to eq(36)
|
185
|
+
expect(msg.xid).to eq(1)
|
186
|
+
expect(msg.statistic_type).to eq(:aggregate)
|
187
|
+
expect(msg.flags).to eq([:reply_more])
|
188
|
+
expect(msg.statistics.packet_count).to eq(10)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
context 'with table' do
|
193
|
+
it 'should read binary' do
|
194
|
+
msg = OFStatisticsReply.read [
|
195
|
+
1, 17, 0, 76, 0, 0, 0, 1, # header
|
196
|
+
0, 3, # statistic_type
|
197
|
+
0, 1, # flags
|
198
|
+
|
199
|
+
# array of table_statistics
|
200
|
+
1, # table_id
|
201
|
+
0, 0, 0, # padding
|
202
|
+
116, 97, 98, 108, 101, 45, 49, 0, # name
|
203
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
204
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
205
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
206
|
+
0, 8, 0x20, 1, # wildcards
|
207
|
+
0, 0, 0, 10, # max_entries
|
208
|
+
0, 0, 0, 5, # active_count
|
209
|
+
0, 0, 0, 0, 0, 0, 0, 4, # lookup_count
|
210
|
+
0, 0, 0, 0, 0, 0, 0, 1 # matched_count
|
211
|
+
].pack('C*')
|
212
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
213
|
+
expect(msg.type).to eq(:statistics_reply)
|
214
|
+
expect(msg.len).to eq(76)
|
215
|
+
expect(msg.xid).to eq(1)
|
216
|
+
expect(msg.statistic_type).to eq(:table)
|
217
|
+
expect(msg.flags).to eq([:reply_more])
|
218
|
+
expect(msg.statistics.length).to eq(1)
|
219
|
+
expect(msg.statistics.first.table_id).to eq(1)
|
220
|
+
end
|
221
|
+
it 'should initialize with default values' do
|
222
|
+
msg = OFStatisticsReply.new(statistic_type: :table)
|
223
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
224
|
+
expect(msg.type).to eq(:statistics_reply)
|
225
|
+
expect(msg.len).to eq(12)
|
226
|
+
expect(msg.xid).to eq(0)
|
227
|
+
expect(msg.statistic_type).to eq(:table)
|
228
|
+
expect(msg.flags).to be_empty
|
229
|
+
expect(msg.statistics).to be_empty
|
230
|
+
end
|
231
|
+
it 'should initialize with some values' do
|
232
|
+
msg = OFStatisticsReply.new(
|
233
|
+
xid: 1,
|
234
|
+
statistic_type: :table,
|
235
|
+
flags: [:reply_more],
|
236
|
+
statistics: [{table_id: 1}]
|
237
|
+
)
|
238
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
239
|
+
expect(msg.type).to eq(:statistics_reply)
|
240
|
+
expect(msg.len).to eq(76)
|
241
|
+
expect(msg.xid).to eq(1)
|
242
|
+
expect(msg.statistic_type).to eq(:table)
|
243
|
+
expect(msg.flags).to eq([:reply_more])
|
244
|
+
expect(msg.statistics.length).to eq(1)
|
245
|
+
expect(msg.statistics.first.table_id).to eq(1)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
context 'with port' do
|
250
|
+
it 'should read binary' do
|
251
|
+
msg = OFStatisticsReply.read [
|
252
|
+
1, 17, 0, 116, 0, 0, 0, 1, # header
|
253
|
+
0, 4, # statistic_type
|
254
|
+
0, 1, # flags
|
255
|
+
|
256
|
+
# array of port_statistics_reply
|
257
|
+
0, 1, # port_number
|
258
|
+
0, 0, 0, 0, 0, 0, # padding
|
259
|
+
0, 0, 0, 0, 0, 0, 0, 10, # receive_packets
|
260
|
+
0, 0, 0, 0, 0, 0, 0, 10, # transmit_packets
|
261
|
+
0, 0, 0, 0, 0, 0, 0, 80, # receive_bytes
|
262
|
+
0, 0, 0, 0, 0, 0, 0, 80, # transmit_bytes
|
263
|
+
0, 0, 0, 0, 0, 0, 0, 5, # receive_dropped
|
264
|
+
0, 0, 0, 0, 0, 0, 0, 5, # transmit_dropped
|
265
|
+
0, 0, 0, 0, 0, 0, 0, 2, # receive_errors
|
266
|
+
0, 0, 0, 0, 0, 0, 0, 2, # transmit_errors
|
267
|
+
0, 0, 0, 0, 0, 0, 0, 1, # receive_frame_errors
|
268
|
+
0, 0, 0, 0, 0, 0, 0, 0, # receive_overrun_errors
|
269
|
+
0, 0, 0, 0, 0, 0, 0, 1, # receive_crc_errors
|
270
|
+
0, 0, 0, 0, 0, 0, 0, 3 # collisions
|
271
|
+
].pack('C*')
|
272
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
273
|
+
expect(msg.type).to eq(:statistics_reply)
|
274
|
+
expect(msg.len).to eq(116)
|
275
|
+
expect(msg.xid).to eq(1)
|
276
|
+
expect(msg.statistic_type).to eq(:port)
|
277
|
+
expect(msg.flags).to eq([:reply_more])
|
278
|
+
expect(msg.statistics.length).to eq(1)
|
279
|
+
expect(msg.statistics.first.port_number).to eq(1)
|
280
|
+
end
|
281
|
+
it 'should initialize with default values' do
|
282
|
+
msg = OFStatisticsReply.new(statistic_type: :port)
|
283
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
284
|
+
expect(msg.type).to eq(:statistics_reply)
|
285
|
+
expect(msg.len).to eq(12)
|
286
|
+
expect(msg.xid).to eq(0)
|
287
|
+
expect(msg.statistic_type).to eq(:port)
|
288
|
+
expect(msg.flags).to be_empty
|
289
|
+
expect(msg.statistics).to be_empty
|
290
|
+
end
|
291
|
+
it 'should initialize with some values' do
|
292
|
+
msg = OFStatisticsReply.new(
|
293
|
+
xid: 1,
|
294
|
+
statistic_type: :port,
|
295
|
+
flags: [:reply_more],
|
296
|
+
statistics: [{port_number: 1}]
|
297
|
+
)
|
298
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
299
|
+
expect(msg.type).to eq(:statistics_reply)
|
300
|
+
expect(msg.len).to eq(116)
|
301
|
+
expect(msg.xid).to eq(1)
|
302
|
+
expect(msg.statistic_type).to eq(:port)
|
303
|
+
expect(msg.flags).to eq([:reply_more])
|
304
|
+
expect(msg.statistics.length).to eq(1)
|
305
|
+
expect(msg.statistics.first.port_number).to eq(1)
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
context 'with queue' do
|
310
|
+
it 'should read binary' do
|
311
|
+
msg = OFStatisticsReply.read [
|
312
|
+
1, 17, 0, 44, 0, 0, 0, 1, # header
|
313
|
+
0, 5, # statistic_type
|
314
|
+
0, 1, # flags
|
315
|
+
|
316
|
+
# array of queue_statistics_reply
|
317
|
+
0, 1, # port_number
|
318
|
+
0, 0, # padding
|
319
|
+
0, 0, 0, 1, # queue_id
|
320
|
+
0, 0, 0, 0, 0, 0, 0, 80, # transmit_bytes
|
321
|
+
0, 0, 0, 0, 0, 0, 0, 10, # transmit_packets
|
322
|
+
0, 0, 0, 0, 0, 0, 0, 2 # transmit_errors
|
323
|
+
].pack('C*')
|
324
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
325
|
+
expect(msg.type).to eq(:statistics_reply)
|
326
|
+
expect(msg.len).to eq(44)
|
327
|
+
expect(msg.xid).to eq(1)
|
328
|
+
expect(msg.statistic_type).to eq(:queue)
|
329
|
+
expect(msg.flags).to eq([:reply_more])
|
330
|
+
expect(msg.statistics.length).to eq(1)
|
331
|
+
expect(msg.statistics.first.port_number).to eq(1)
|
332
|
+
end
|
333
|
+
it 'should initialize with default values' do
|
334
|
+
msg = OFStatisticsReply.new(statistic_type: :queue)
|
335
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
336
|
+
expect(msg.type).to eq(:statistics_reply)
|
337
|
+
expect(msg.len).to eq(12)
|
338
|
+
expect(msg.xid).to eq(0)
|
339
|
+
expect(msg.statistic_type).to eq(:queue)
|
340
|
+
expect(msg.flags).to be_empty
|
341
|
+
expect(msg.statistics).to be_empty
|
342
|
+
end
|
343
|
+
it 'should initialize with some values' do
|
344
|
+
msg = OFStatisticsReply.new(
|
345
|
+
xid: 1,
|
346
|
+
statistic_type: :queue,
|
347
|
+
flags: [:reply_more],
|
348
|
+
statistics: [{port_number: 1}]
|
349
|
+
)
|
350
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
351
|
+
expect(msg.type).to eq(:statistics_reply)
|
352
|
+
expect(msg.len).to eq(44)
|
353
|
+
expect(msg.xid).to eq(1)
|
354
|
+
expect(msg.statistic_type).to eq(:queue)
|
355
|
+
expect(msg.flags).to eq([:reply_more])
|
356
|
+
expect(msg.statistics.length).to eq(1)
|
357
|
+
expect(msg.statistics.first.port_number).to eq(1)
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
context 'with vendor' do
|
362
|
+
it 'should read binary' do
|
363
|
+
msg = OFStatisticsReply.read [
|
364
|
+
1, 17, 0, 20, 0, 0, 0, 1, # header
|
365
|
+
0xff, 0xff, # statistic_type
|
366
|
+
0, 0, # flags
|
367
|
+
|
368
|
+
# vendor_statistics
|
369
|
+
0, 0, 0, 1, # vendor
|
370
|
+
1, 2, 3, 4 # body
|
371
|
+
].pack('C*')
|
372
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
373
|
+
expect(msg.type).to eq(:statistics_reply)
|
374
|
+
expect(msg.len).to eq(20)
|
375
|
+
expect(msg.xid).to eq(1)
|
376
|
+
expect(msg.statistic_type).to eq(:vendor)
|
377
|
+
expect(msg.flags).to be_empty
|
378
|
+
expect(msg.statistics.vendor).to eq(1)
|
379
|
+
expect(msg.statistics.body).to eq([1, 2, 3, 4].pack('C*'))
|
380
|
+
end
|
381
|
+
it 'should initialize with default values' do
|
382
|
+
msg = OFStatisticsReply.new(statistic_type: :vendor)
|
383
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
384
|
+
expect(msg.type).to eq(:statistics_reply)
|
385
|
+
expect(msg.len).to eq(16)
|
386
|
+
expect(msg.xid).to eq(0)
|
387
|
+
expect(msg.statistic_type).to eq(:vendor)
|
388
|
+
expect(msg.flags).to be_empty
|
389
|
+
expect(msg.statistics.vendor).to eq(0)
|
390
|
+
expect(msg.statistics.body).to be_empty
|
391
|
+
end
|
392
|
+
it 'should initialize with some values' do
|
393
|
+
msg = OFStatisticsReply.new(
|
394
|
+
xid: 1,
|
395
|
+
statistic_type: :vendor,
|
396
|
+
statistics: {
|
397
|
+
vendor: 1,
|
398
|
+
body: [1, 2, 3, 4].pack('C*')
|
399
|
+
}
|
400
|
+
)
|
401
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
402
|
+
expect(msg.type).to eq(:statistics_reply)
|
403
|
+
expect(msg.len).to eq(20)
|
404
|
+
expect(msg.xid).to eq(1)
|
405
|
+
expect(msg.statistic_type).to eq(:vendor)
|
406
|
+
expect(msg.flags).to be_empty
|
407
|
+
expect(msg.statistics.vendor).to eq(1)
|
408
|
+
expect(msg.statistics.body).to eq([1, 2, 3, 4].pack('C*'))
|
409
|
+
end
|
410
|
+
end
|
411
|
+
end
|
@@ -0,0 +1,355 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OFStatisticsRequest do
|
4
|
+
context 'with description' do
|
5
|
+
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*')
|
11
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
12
|
+
expect(msg.type).to eq(:statistics_request)
|
13
|
+
expect(msg.len).to eq(12)
|
14
|
+
expect(msg.xid).to eq(1)
|
15
|
+
expect(msg.statistic_type).to eq(:description)
|
16
|
+
expect(msg.flags).to be_empty
|
17
|
+
expect(msg.statistics).to be_empty
|
18
|
+
end
|
19
|
+
it 'should initialize with default values' do
|
20
|
+
msg = OFStatisticsRequest.new
|
21
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
22
|
+
expect(msg.type).to eq(:statistics_request)
|
23
|
+
expect(msg.len).to eq(12)
|
24
|
+
expect(msg.xid).to eq(0)
|
25
|
+
expect(msg.statistic_type).to eq(:description)
|
26
|
+
expect(msg.flags).to be_empty
|
27
|
+
expect(msg.statistics).to be_empty
|
28
|
+
end
|
29
|
+
it 'should initialize with some values' do
|
30
|
+
msg = OFStatisticsRequest.new(
|
31
|
+
xid: 1,
|
32
|
+
statistic_type: :description
|
33
|
+
)
|
34
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
35
|
+
expect(msg.type).to eq(:statistics_request)
|
36
|
+
expect(msg.len).to eq(12)
|
37
|
+
expect(msg.xid).to eq(1)
|
38
|
+
expect(msg.statistic_type).to eq(:description)
|
39
|
+
expect(msg.flags).to be_empty
|
40
|
+
expect(msg.statistics).to be_empty
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'with flow' do
|
45
|
+
it 'should read binary' do
|
46
|
+
msg = OFStatisticsRequest.read [
|
47
|
+
1, 16, 0, 56, 0, 0, 0, 1, # header
|
48
|
+
0, 1, # statistic_type
|
49
|
+
0, 0, # flags
|
50
|
+
|
51
|
+
# flow_statistics_request
|
52
|
+
# match
|
53
|
+
0, 0x30, 0x20, 0x4f, # wildcards
|
54
|
+
0, 0, # in_port
|
55
|
+
0, 0, 0, 0, 0, 0, # mac_source
|
56
|
+
0, 0, 0, 0, 0, 0, # mac_destination
|
57
|
+
0xff, 0xff, # vlan_id
|
58
|
+
0, # vlan_pcp
|
59
|
+
0, # padding
|
60
|
+
8, 0, # mac_protocol
|
61
|
+
0, # ip_tos
|
62
|
+
6, # ip_protocol
|
63
|
+
0, 0, # padding
|
64
|
+
0, 0, 0, 0, # ip_source
|
65
|
+
192, 168, 0, 2, # ip_destination
|
66
|
+
0, 0, # source_port
|
67
|
+
0x0b, 0xb8, # destination_port
|
68
|
+
|
69
|
+
1, # table_id
|
70
|
+
0, # padding
|
71
|
+
0, 1 # out_port
|
72
|
+
].pack('C*')
|
73
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
74
|
+
expect(msg.type).to eq(:statistics_request)
|
75
|
+
expect(msg.len).to eq(56)
|
76
|
+
expect(msg.xid).to eq(1)
|
77
|
+
expect(msg.statistic_type).to eq(:flow)
|
78
|
+
expect(msg.flags).to be_empty
|
79
|
+
expect(msg.statistics.table_id).to eq(1)
|
80
|
+
end
|
81
|
+
it 'should initialize with default values' do
|
82
|
+
msg = OFStatisticsRequest.new(statistic_type: :flow)
|
83
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
84
|
+
expect(msg.type).to eq(:statistics_request)
|
85
|
+
expect(msg.len).to eq(56)
|
86
|
+
expect(msg.xid).to eq(0)
|
87
|
+
expect(msg.statistic_type).to eq(:flow)
|
88
|
+
expect(msg.flags).to be_empty
|
89
|
+
expect(msg.statistics.table_id).to eq(:all)
|
90
|
+
end
|
91
|
+
it 'should initialize with some values' do
|
92
|
+
msg = OFStatisticsRequest.new(
|
93
|
+
xid: 1,
|
94
|
+
statistic_type: :flow,
|
95
|
+
statistics: {
|
96
|
+
table_id: 1
|
97
|
+
}
|
98
|
+
)
|
99
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
100
|
+
expect(msg.type).to eq(:statistics_request)
|
101
|
+
expect(msg.len).to eq(56)
|
102
|
+
expect(msg.xid).to eq(1)
|
103
|
+
expect(msg.statistic_type).to eq(:flow)
|
104
|
+
expect(msg.flags).to be_empty
|
105
|
+
expect(msg.statistics.table_id).to eq(1)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'with aggregate' do
|
110
|
+
it 'should read binary' do
|
111
|
+
msg = OFStatisticsRequest.read [
|
112
|
+
1, 16, 0, 56, 0, 0, 0, 1, # header
|
113
|
+
0, 2, # statistic_type
|
114
|
+
0, 0, # flags
|
115
|
+
|
116
|
+
# aggregate_statistics_request
|
117
|
+
# match
|
118
|
+
0, 0x30, 0x20, 0x4f, # wildcards
|
119
|
+
0, 0, # in_port
|
120
|
+
0, 0, 0, 0, 0, 0, # mac_source
|
121
|
+
0, 0, 0, 0, 0, 0, # mac_destination
|
122
|
+
0xff, 0xff, # vlan_id
|
123
|
+
0, # vlan_pcp
|
124
|
+
0, # padding
|
125
|
+
8, 0, # mac_protocol
|
126
|
+
0, # ip_tos
|
127
|
+
6, # ip_protocol
|
128
|
+
0, 0, # padding
|
129
|
+
0, 0, 0, 0, # ip_source
|
130
|
+
192, 168, 0, 2, # ip_destination
|
131
|
+
0, 0, # source_port
|
132
|
+
0x0b, 0xb8, # destination_port
|
133
|
+
|
134
|
+
1, # table_id
|
135
|
+
0, # padding
|
136
|
+
0, 1 # out_port
|
137
|
+
].pack('C*')
|
138
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
139
|
+
expect(msg.type).to eq(:statistics_request)
|
140
|
+
expect(msg.len).to eq(56)
|
141
|
+
expect(msg.xid).to eq(1)
|
142
|
+
expect(msg.statistic_type).to eq(:aggregate)
|
143
|
+
expect(msg.flags).to be_empty
|
144
|
+
expect(msg.statistics.table_id).to eq(1)
|
145
|
+
end
|
146
|
+
it 'should initialize with default values' do
|
147
|
+
msg = OFStatisticsRequest.new(statistic_type: :aggregate)
|
148
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
149
|
+
expect(msg.type).to eq(:statistics_request)
|
150
|
+
expect(msg.len).to eq(56)
|
151
|
+
expect(msg.xid).to eq(0)
|
152
|
+
expect(msg.statistic_type).to eq(:aggregate)
|
153
|
+
expect(msg.flags).to be_empty
|
154
|
+
expect(msg.statistics.table_id).to eq(:all)
|
155
|
+
end
|
156
|
+
it 'should initialize with some values' do
|
157
|
+
msg = OFStatisticsRequest.new(
|
158
|
+
xid: 1,
|
159
|
+
statistic_type: :aggregate,
|
160
|
+
statistics: {
|
161
|
+
table_id: 1
|
162
|
+
}
|
163
|
+
)
|
164
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
165
|
+
expect(msg.type).to eq(:statistics_request)
|
166
|
+
expect(msg.len).to eq(56)
|
167
|
+
expect(msg.xid).to eq(1)
|
168
|
+
expect(msg.statistic_type).to eq(:aggregate)
|
169
|
+
expect(msg.flags).to be_empty
|
170
|
+
expect(msg.statistics.table_id).to eq(1)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context 'with table' do
|
175
|
+
it 'should read binary' do
|
176
|
+
msg = OFStatisticsRequest.read [
|
177
|
+
1, 16, 0, 12, 0, 0, 0, 1, # header
|
178
|
+
0, 3, # statistic_type
|
179
|
+
0, 0, # flags
|
180
|
+
].pack('C*')
|
181
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
182
|
+
expect(msg.type).to eq(:statistics_request)
|
183
|
+
expect(msg.len).to eq(12)
|
184
|
+
expect(msg.xid).to eq(1)
|
185
|
+
expect(msg.statistic_type).to eq(:table)
|
186
|
+
expect(msg.flags).to be_empty
|
187
|
+
expect(msg.statistics).to be_empty
|
188
|
+
end
|
189
|
+
it 'should initialize with default values' do
|
190
|
+
msg = OFStatisticsRequest.new(statistic_type: :table)
|
191
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
192
|
+
expect(msg.type).to eq(:statistics_request)
|
193
|
+
expect(msg.len).to eq(12)
|
194
|
+
expect(msg.xid).to eq(0)
|
195
|
+
expect(msg.statistic_type).to eq(:table)
|
196
|
+
expect(msg.flags).to be_empty
|
197
|
+
expect(msg.statistics).to be_empty
|
198
|
+
end
|
199
|
+
it 'should initialize with some values' do
|
200
|
+
msg = OFStatisticsRequest.new(
|
201
|
+
xid: 1,
|
202
|
+
statistic_type: :table
|
203
|
+
)
|
204
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
205
|
+
expect(msg.type).to eq(:statistics_request)
|
206
|
+
expect(msg.len).to eq(12)
|
207
|
+
expect(msg.xid).to eq(1)
|
208
|
+
expect(msg.statistic_type).to eq(:table)
|
209
|
+
expect(msg.flags).to be_empty
|
210
|
+
expect(msg.statistics).to be_empty
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
context 'with port' do
|
215
|
+
it 'should read binary' do
|
216
|
+
msg = OFStatisticsRequest.read [
|
217
|
+
1, 16, 0, 20, 0, 0, 0, 1, # header
|
218
|
+
0, 4, # statistic_type
|
219
|
+
0, 0, # flags
|
220
|
+
|
221
|
+
# port_statistics_request
|
222
|
+
0, 1, # port_number
|
223
|
+
0, 0, 0, 0, 0, 0 # padding
|
224
|
+
].pack('C*')
|
225
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
226
|
+
expect(msg.type).to eq(:statistics_request)
|
227
|
+
expect(msg.len).to eq(20)
|
228
|
+
expect(msg.xid).to eq(1)
|
229
|
+
expect(msg.statistic_type).to eq(:port)
|
230
|
+
expect(msg.flags).to be_empty
|
231
|
+
expect(msg.statistics.port_number).to eq(1)
|
232
|
+
end
|
233
|
+
it 'should initialize with default values' do
|
234
|
+
msg = OFStatisticsRequest.new(statistic_type: :port)
|
235
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
236
|
+
expect(msg.type).to eq(:statistics_request)
|
237
|
+
expect(msg.len).to eq(20)
|
238
|
+
expect(msg.xid).to eq(0)
|
239
|
+
expect(msg.statistic_type).to eq(:port)
|
240
|
+
expect(msg.flags).to be_empty
|
241
|
+
expect(msg.statistics.port_number).to eq(:none)
|
242
|
+
end
|
243
|
+
it 'should initialize with some values' do
|
244
|
+
msg = OFStatisticsRequest.new(
|
245
|
+
xid: 1,
|
246
|
+
statistic_type: :port,
|
247
|
+
statistics: {port_number: 1}
|
248
|
+
)
|
249
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
250
|
+
expect(msg.type).to eq(:statistics_request)
|
251
|
+
expect(msg.len).to eq(20)
|
252
|
+
expect(msg.xid).to eq(1)
|
253
|
+
expect(msg.statistic_type).to eq(:port)
|
254
|
+
expect(msg.flags).to be_empty
|
255
|
+
expect(msg.statistics.port_number).to eq(1)
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
context 'with queue' do
|
260
|
+
it 'should read binary' do
|
261
|
+
msg = OFStatisticsRequest.read [
|
262
|
+
1, 16, 0, 20, 0, 0, 0, 1, # header
|
263
|
+
0, 5, # statistic_type
|
264
|
+
0, 0, # flags
|
265
|
+
|
266
|
+
# queue_statistics_request
|
267
|
+
0, 1, # port_number
|
268
|
+
0, 0, # padding
|
269
|
+
0, 0, 0, 1 # queue_id
|
270
|
+
].pack('C*')
|
271
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
272
|
+
expect(msg.type).to eq(:statistics_request)
|
273
|
+
expect(msg.len).to eq(20)
|
274
|
+
expect(msg.xid).to eq(1)
|
275
|
+
expect(msg.statistic_type).to eq(:queue)
|
276
|
+
expect(msg.flags).to be_empty
|
277
|
+
expect(msg.statistics.port_number).to eq(1)
|
278
|
+
end
|
279
|
+
it 'should initialize with default values' do
|
280
|
+
msg = OFStatisticsRequest.new(statistic_type: :queue)
|
281
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
282
|
+
expect(msg.type).to eq(:statistics_request)
|
283
|
+
expect(msg.len).to eq(20)
|
284
|
+
expect(msg.xid).to eq(0)
|
285
|
+
expect(msg.statistic_type).to eq(:queue)
|
286
|
+
expect(msg.flags).to be_empty
|
287
|
+
expect(msg.statistics.port_number).to eq(:all)
|
288
|
+
end
|
289
|
+
it 'should initialize with some values' do
|
290
|
+
msg = OFStatisticsRequest.new(
|
291
|
+
xid: 1,
|
292
|
+
statistic_type: :queue,
|
293
|
+
statistics: {port_number: 1}
|
294
|
+
)
|
295
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
296
|
+
expect(msg.type).to eq(:statistics_request)
|
297
|
+
expect(msg.len).to eq(20)
|
298
|
+
expect(msg.xid).to eq(1)
|
299
|
+
expect(msg.statistic_type).to eq(:queue)
|
300
|
+
expect(msg.flags).to be_empty
|
301
|
+
expect(msg.statistics.port_number).to eq(1)
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
context 'with vendor' do
|
306
|
+
it 'should read binary' do
|
307
|
+
msg = OFStatisticsRequest.read [
|
308
|
+
1, 16, 0, 20, 0, 0, 0, 1, # header
|
309
|
+
0xff, 0xff, # statistic_type
|
310
|
+
0, 0, # flags
|
311
|
+
|
312
|
+
# vendor_statistics
|
313
|
+
0, 0, 0, 1, # vendor
|
314
|
+
1, 2, 3, 4 # body
|
315
|
+
].pack('C*')
|
316
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
317
|
+
expect(msg.type).to eq(:statistics_request)
|
318
|
+
expect(msg.len).to eq(20)
|
319
|
+
expect(msg.xid).to eq(1)
|
320
|
+
expect(msg.statistic_type).to eq(:vendor)
|
321
|
+
expect(msg.flags).to be_empty
|
322
|
+
expect(msg.statistics.vendor).to eq(1)
|
323
|
+
expect(msg.statistics.body).to eq([1, 2, 3, 4].pack('C*'))
|
324
|
+
end
|
325
|
+
it 'should initialize with default values' do
|
326
|
+
msg = OFStatisticsRequest.new(statistic_type: :vendor)
|
327
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
328
|
+
expect(msg.type).to eq(:statistics_request)
|
329
|
+
expect(msg.len).to eq(16)
|
330
|
+
expect(msg.xid).to eq(0)
|
331
|
+
expect(msg.statistic_type).to eq(:vendor)
|
332
|
+
expect(msg.flags).to be_empty
|
333
|
+
expect(msg.statistics.vendor).to eq(0)
|
334
|
+
expect(msg.statistics.body).to be_empty
|
335
|
+
end
|
336
|
+
it 'should initialize with some values' do
|
337
|
+
msg = OFStatisticsRequest.new(
|
338
|
+
xid: 1,
|
339
|
+
statistic_type: :vendor,
|
340
|
+
statistics: {
|
341
|
+
vendor: 1,
|
342
|
+
body: [1, 2, 3, 4].pack('C*')
|
343
|
+
}
|
344
|
+
)
|
345
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
346
|
+
expect(msg.type).to eq(:statistics_request)
|
347
|
+
expect(msg.len).to eq(20)
|
348
|
+
expect(msg.xid).to eq(1)
|
349
|
+
expect(msg.statistic_type).to eq(:vendor)
|
350
|
+
expect(msg.flags).to be_empty
|
351
|
+
expect(msg.statistics.vendor).to eq(1)
|
352
|
+
expect(msg.statistics.body).to eq([1, 2, 3, 4].pack('C*'))
|
353
|
+
end
|
354
|
+
end
|
355
|
+
end
|