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,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OFEchoReply do
|
4
|
+
it 'should read binary' do
|
5
|
+
msg = OFEchoReply.read [1, 3, 0, 8, 0, 0, 0, 1].pack('C*')
|
6
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
7
|
+
expect(msg.type).to eq(:echo_reply)
|
8
|
+
expect(msg.len).to eq(8)
|
9
|
+
expect(msg.xid).to eq(1)
|
10
|
+
expect(msg.data).to be_empty
|
11
|
+
end
|
12
|
+
it 'should read binary with data' do
|
13
|
+
msg = OFEchoReply.read [1, 3, 0, 10, 0, 0, 0, 1, 10, 20].pack('C*')
|
14
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
15
|
+
expect(msg.type).to eq(:echo_reply)
|
16
|
+
expect(msg.len).to eq(10)
|
17
|
+
expect(msg.xid).to eq(1)
|
18
|
+
expect(msg.data.length).to eq(2)
|
19
|
+
end
|
20
|
+
it 'should initialize with default values' do
|
21
|
+
msg = OFEchoReply.new
|
22
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
23
|
+
expect(msg.type).to eq(:echo_reply)
|
24
|
+
expect(msg.len).to eq(8)
|
25
|
+
expect(msg.xid).to eq(0)
|
26
|
+
expect(msg.data).to be_empty
|
27
|
+
end
|
28
|
+
it 'should initialize with some values' do
|
29
|
+
msg = OFEchoReply.new(xid: 1)
|
30
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
31
|
+
expect(msg.type).to eq(:echo_reply)
|
32
|
+
expect(msg.len).to eq(8)
|
33
|
+
expect(msg.xid).to eq(1)
|
34
|
+
expect(msg.data).to be_empty
|
35
|
+
end
|
36
|
+
it 'should initialize with data' do
|
37
|
+
msg = OFEchoReply.new(data: [10, 20].pack('C*'))
|
38
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
39
|
+
expect(msg.type).to eq(:echo_reply)
|
40
|
+
expect(msg.len).to eq(10)
|
41
|
+
expect(msg.xid).to eq(0)
|
42
|
+
expect(msg.data.length).to eq(2)
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OFEchoRequest do
|
4
|
+
it 'should read binary' do
|
5
|
+
msg = OFEchoRequest.read [1, 2, 0, 8, 0, 0, 0, 1].pack('C*')
|
6
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
7
|
+
expect(msg.type).to eq(:echo_request)
|
8
|
+
expect(msg.len).to eq(8)
|
9
|
+
expect(msg.xid).to eq(1)
|
10
|
+
expect(msg.data).to be_empty
|
11
|
+
end
|
12
|
+
it 'should read binary with data' do
|
13
|
+
msg = OFEchoRequest.read [1, 2, 0, 10, 0, 0, 0, 1, 10, 20].pack('C*')
|
14
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
15
|
+
expect(msg.type).to eq(:echo_request)
|
16
|
+
expect(msg.len).to eq(10)
|
17
|
+
expect(msg.xid).to eq(1)
|
18
|
+
expect(msg.data.length).to eq(2)
|
19
|
+
end
|
20
|
+
it 'should initialize with default values' do
|
21
|
+
msg = OFEchoRequest.new
|
22
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
23
|
+
expect(msg.type).to eq(:echo_request)
|
24
|
+
expect(msg.len).to eq(8)
|
25
|
+
expect(msg.xid).to eq(0)
|
26
|
+
expect(msg.data).to be_empty
|
27
|
+
end
|
28
|
+
it 'should initialize with some values' do
|
29
|
+
msg = OFEchoRequest.new(xid: 1)
|
30
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
31
|
+
expect(msg.type).to eq(:echo_request)
|
32
|
+
expect(msg.len).to eq(8)
|
33
|
+
expect(msg.xid).to eq(1)
|
34
|
+
expect(msg.data).to be_empty
|
35
|
+
end
|
36
|
+
it 'should initialize with data' do
|
37
|
+
msg = OFEchoRequest.new(data: [10, 20].pack('C*'))
|
38
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
39
|
+
expect(msg.type).to eq(:echo_request)
|
40
|
+
expect(msg.len).to eq(10)
|
41
|
+
expect(msg.xid).to eq(0)
|
42
|
+
expect(msg.data.length).to eq(2)
|
43
|
+
end
|
44
|
+
it 'should convert to OFEchoReply' do
|
45
|
+
msg = OFEchoRequest.new(xid: 1, data: [10, 20].pack('C*'))
|
46
|
+
msg_reply = msg.to_reply
|
47
|
+
expect(msg_reply.version).to eq(OFMessage::OFP_VERSION)
|
48
|
+
expect(msg_reply.type).to eq(:echo_reply)
|
49
|
+
expect(msg.len).to eq(msg_reply.len)
|
50
|
+
expect(msg.xid).to eq(msg_reply.xid)
|
51
|
+
expect(msg.data).to eq(msg_reply.data)
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OFError do
|
4
|
+
it 'should read binary' do
|
5
|
+
msg = OFError.read [
|
6
|
+
1, 1, 0, 16, 0, 0, 0, 1, # header
|
7
|
+
0, 0, # type
|
8
|
+
0, 0, # code
|
9
|
+
1, 2, 3, 4 # data
|
10
|
+
].pack('C*')
|
11
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
12
|
+
expect(msg.type).to eq(:error)
|
13
|
+
expect(msg.len).to eq(16)
|
14
|
+
expect(msg.xid).to eq(1)
|
15
|
+
expect(msg.error_type).to eq(:hello_failed)
|
16
|
+
expect(msg.error_code).to eq(:incompatible)
|
17
|
+
expect(msg.data).to eq([1, 2, 3, 4].pack('C*'))
|
18
|
+
end
|
19
|
+
it 'should read binary' do
|
20
|
+
msg = OFError.read [
|
21
|
+
1, 1, 0, 12, 0, 0, 0, 1, # header
|
22
|
+
0, 2, # type
|
23
|
+
0, 4 # code
|
24
|
+
].pack('C*')
|
25
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
26
|
+
expect(msg.type).to eq(:error)
|
27
|
+
expect(msg.len).to eq(12)
|
28
|
+
expect(msg.xid).to eq(1)
|
29
|
+
expect(msg.error_type).to eq(:bad_action)
|
30
|
+
expect(msg.error_code).to eq(:bad_out_port)
|
31
|
+
expect(msg.data).to be_empty
|
32
|
+
end
|
33
|
+
it 'should initialize with default values' do
|
34
|
+
msg = OFError.new
|
35
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
36
|
+
expect(msg.type).to eq(:error)
|
37
|
+
expect(msg.len).to eq(12)
|
38
|
+
expect(msg.xid).to eq(0)
|
39
|
+
expect(msg.error_type).to eq(:hello_failed)
|
40
|
+
expect(msg.error_code).to eq(:incompatible)
|
41
|
+
expect(msg.data).to be_empty
|
42
|
+
end
|
43
|
+
it 'should initialize with some values' do
|
44
|
+
msg = OFError.new(
|
45
|
+
xid: 1,
|
46
|
+
error_type: :port_mod_failed,
|
47
|
+
error_code: :bad_port
|
48
|
+
)
|
49
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
50
|
+
expect(msg.type).to eq(:error)
|
51
|
+
expect(msg.len).to eq(12)
|
52
|
+
expect(msg.xid).to eq(1)
|
53
|
+
expect(msg.error_type).to eq(:port_mod_failed)
|
54
|
+
expect(msg.error_code).to eq(:bad_port)
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,204 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OFFeaturesReply do
|
4
|
+
it 'should read binary' do
|
5
|
+
msg = OFFeaturesReply.read [
|
6
|
+
1, 6, 0, 128, 0, 0, 0, 1, # header
|
7
|
+
0, 0, 0, 0, 0, 0, 0, 42, # datapath_id
|
8
|
+
0, 0, 0, 10, # n_buffers
|
9
|
+
5, # n_tables
|
10
|
+
0, 0, 0, # padding
|
11
|
+
0, 0, 0, 0xff, # capabilities
|
12
|
+
0, 0, 0x0f, 0xff, # actions
|
13
|
+
# port 1
|
14
|
+
0, 1, # port_number
|
15
|
+
0, 0, 0, 0, 0, 1, # hardware_address
|
16
|
+
112, 111, 114, 116, # name
|
17
|
+
45, 49, 0, 0,
|
18
|
+
0, 0, 0, 0,
|
19
|
+
0, 0, 0, 0,
|
20
|
+
0, 0, 0, 1, # config
|
21
|
+
0, 0, 0, 1, # state
|
22
|
+
0, 0, 0x0f, 0xff, # current_features
|
23
|
+
0, 0, 0x0f, 0xff, # advertised_features
|
24
|
+
0, 0, 0x0f, 0xff, # supported_features
|
25
|
+
0, 0, 0x0f, 0xff, # peer_features
|
26
|
+
# port 2
|
27
|
+
0, 2, # port_number
|
28
|
+
0, 0, 0, 0, 0, 2, # hardware_address
|
29
|
+
112, 111, 114, 116, # name
|
30
|
+
45, 50, 0, 0,
|
31
|
+
0, 0, 0, 0,
|
32
|
+
0, 0, 0, 0,
|
33
|
+
0, 0, 0, 1, # config
|
34
|
+
0, 0, 0, 1, # state
|
35
|
+
0, 0, 0x0f, 0xff, # current_features
|
36
|
+
0, 0, 0x0f, 0xff, # advertised_features
|
37
|
+
0, 0, 0x0f, 0xff, # supported_features
|
38
|
+
0, 0, 0x0f, 0xff # peer_features
|
39
|
+
].pack('C*')
|
40
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
41
|
+
expect(msg.type).to eq(:features_reply)
|
42
|
+
expect(msg.len).to eq(128)
|
43
|
+
expect(msg.xid).to eq(1)
|
44
|
+
expect(msg.datapath_id).to eq(42)
|
45
|
+
expect(msg.n_buffers).to eq(10)
|
46
|
+
expect(msg.n_tables).to eq(5)
|
47
|
+
expect(msg.capabilities).to eq([
|
48
|
+
:flow_stats,
|
49
|
+
:table_stats,
|
50
|
+
:port_stats,
|
51
|
+
:stp,
|
52
|
+
:reserved,
|
53
|
+
:ip_reasm,
|
54
|
+
:queue_stats,
|
55
|
+
:arp_match_ip
|
56
|
+
])
|
57
|
+
expect(msg.actions).to eq([
|
58
|
+
:output,
|
59
|
+
:set_vlan_vid,
|
60
|
+
:set_vlan_pcp,
|
61
|
+
:strip_vlan,
|
62
|
+
:set_dl_src,
|
63
|
+
:set_dl_dst,
|
64
|
+
:set_nw_src,
|
65
|
+
:set_nw_dst,
|
66
|
+
:set_nw_tos,
|
67
|
+
:set_tp_src,
|
68
|
+
:set_tp_dst,
|
69
|
+
:enqueue
|
70
|
+
])
|
71
|
+
expect(msg.ports.length).to eq(2)
|
72
|
+
expect(msg.ports[0].port_number).to eq(1)
|
73
|
+
expect(msg.ports[1].port_number).to eq(2)
|
74
|
+
end
|
75
|
+
it 'should read a real binary message' do
|
76
|
+
msg = OFFeaturesReply.read [
|
77
|
+
1, 6, 0, 176, 0, 0, 0, 0,
|
78
|
+
0, 0, 0, 0, 0, 0, 0, 1,
|
79
|
+
0, 0, 1, 0,
|
80
|
+
255,
|
81
|
+
0, 0, 0,
|
82
|
+
0, 0, 0, 199,
|
83
|
+
0, 0, 15, 255,
|
84
|
+
# port-2
|
85
|
+
0, 2,
|
86
|
+
90, 50, 48, 40, 143, 254,
|
87
|
+
115, 49, 45, 101,
|
88
|
+
116, 104, 50, 0,
|
89
|
+
0, 0, 0, 0,
|
90
|
+
0, 0, 0, 0,
|
91
|
+
0, 0, 0, 0,
|
92
|
+
0, 0, 0, 0,
|
93
|
+
0, 0, 0, 192,
|
94
|
+
0, 0, 0, 0,
|
95
|
+
0, 0, 0, 0,
|
96
|
+
0, 0, 0, 0,
|
97
|
+
# port-local
|
98
|
+
255, 254,
|
99
|
+
226, 183, 195, 44, 245, 74,
|
100
|
+
115, 49, 0, 0,
|
101
|
+
0, 0, 0, 0,
|
102
|
+
0, 0, 0, 0,
|
103
|
+
0, 0, 0, 0,
|
104
|
+
0, 0, 0, 1,
|
105
|
+
0, 0, 0, 1,
|
106
|
+
0, 0, 0, 0,
|
107
|
+
0, 0, 0, 0,
|
108
|
+
0, 0, 0, 0,
|
109
|
+
0, 0, 0, 0,
|
110
|
+
# port-1
|
111
|
+
0, 1,
|
112
|
+
42, 94, 179, 106, 57, 71,
|
113
|
+
115, 49, 45, 101,
|
114
|
+
116, 104, 49, 0,
|
115
|
+
0, 0, 0, 0,
|
116
|
+
0, 0, 0, 0,
|
117
|
+
0, 0, 0, 0,
|
118
|
+
0, 0, 0, 1,
|
119
|
+
0, 0, 0, 192,
|
120
|
+
0, 0, 0, 0,
|
121
|
+
0, 0, 0, 0,
|
122
|
+
0, 0, 0, 0
|
123
|
+
].pack('C*')
|
124
|
+
expect(msg.ports.length).to eq(3)
|
125
|
+
end
|
126
|
+
it 'should initialize with default values' do
|
127
|
+
msg = OFFeaturesReply.new
|
128
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
129
|
+
expect(msg.type).to eq(:features_reply)
|
130
|
+
expect(msg.len).to eq(32)
|
131
|
+
expect(msg.xid).to eq(0)
|
132
|
+
expect(msg.datapath_id).to eq(0)
|
133
|
+
expect(msg.n_buffers).to eq(0)
|
134
|
+
expect(msg.n_tables).to eq(0)
|
135
|
+
expect(msg.capabilities).to eq([])
|
136
|
+
expect(msg.actions).to eq([])
|
137
|
+
expect(msg.ports).to be_empty
|
138
|
+
end
|
139
|
+
it 'should initialize with some values' do
|
140
|
+
msg = OFFeaturesReply.new(
|
141
|
+
xid: 1,
|
142
|
+
datapath_id: 42,
|
143
|
+
n_buffers: 10,
|
144
|
+
n_tables: 5,
|
145
|
+
capabilities: [
|
146
|
+
:flow_stats,
|
147
|
+
:table_stats,
|
148
|
+
:port_stats,
|
149
|
+
:stp,
|
150
|
+
:reserved,
|
151
|
+
:ip_reasm,
|
152
|
+
:queue_stats,
|
153
|
+
:arp_match_ip
|
154
|
+
],
|
155
|
+
actions: [
|
156
|
+
:output,
|
157
|
+
:set_vlan_vid,
|
158
|
+
:set_vlan_pcp,
|
159
|
+
:strip_vlan,
|
160
|
+
:set_dl_src,
|
161
|
+
:set_dl_dst,
|
162
|
+
:set_nw_src,
|
163
|
+
:set_nw_dst,
|
164
|
+
:set_nw_tos,
|
165
|
+
:set_tp_src,
|
166
|
+
:set_tp_dst,
|
167
|
+
:enqueue
|
168
|
+
],
|
169
|
+
ports: [OFPhysicalPort.new]
|
170
|
+
)
|
171
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
172
|
+
expect(msg.type).to eq(:features_reply)
|
173
|
+
expect(msg.len).to eq(80)
|
174
|
+
expect(msg.xid).to eq(1)
|
175
|
+
expect(msg.datapath_id).to eq(42)
|
176
|
+
expect(msg.n_buffers).to eq(10)
|
177
|
+
expect(msg.n_tables).to eq(5)
|
178
|
+
expect(msg.capabilities).to eq([
|
179
|
+
:flow_stats,
|
180
|
+
:table_stats,
|
181
|
+
:port_stats,
|
182
|
+
:stp,
|
183
|
+
:reserved,
|
184
|
+
:ip_reasm,
|
185
|
+
:queue_stats,
|
186
|
+
:arp_match_ip
|
187
|
+
])
|
188
|
+
expect(msg.actions).to eq([
|
189
|
+
:output,
|
190
|
+
:set_vlan_vid,
|
191
|
+
:set_vlan_pcp,
|
192
|
+
:strip_vlan,
|
193
|
+
:set_dl_src,
|
194
|
+
:set_dl_dst,
|
195
|
+
:set_nw_src,
|
196
|
+
:set_nw_dst,
|
197
|
+
:set_nw_tos,
|
198
|
+
:set_tp_src,
|
199
|
+
:set_tp_dst,
|
200
|
+
:enqueue
|
201
|
+
])
|
202
|
+
expect(msg.ports.length).to eq(1)
|
203
|
+
end
|
204
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OFFeaturesRequest do
|
4
|
+
it 'should read binary' do
|
5
|
+
msg = OFFeaturesRequest.read [1, 5, 0, 8, 0, 0, 0, 1].pack('C*')
|
6
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
7
|
+
expect(msg.type).to eq(:features_request)
|
8
|
+
expect(msg.len).to eq(8)
|
9
|
+
expect(msg.xid).to eq(1)
|
10
|
+
end
|
11
|
+
it 'should initialize with default values' do
|
12
|
+
msg = OFFeaturesRequest.new
|
13
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
14
|
+
expect(msg.type).to eq(:features_request)
|
15
|
+
expect(msg.len).to eq(8)
|
16
|
+
expect(msg.xid).to eq(0)
|
17
|
+
end
|
18
|
+
it 'should initialize with some values' do
|
19
|
+
msg = OFFeaturesRequest.new(xid: 1)
|
20
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
21
|
+
expect(msg.type).to eq(:features_request)
|
22
|
+
expect(msg.len).to eq(8)
|
23
|
+
expect(msg.xid).to eq(1)
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OFFlowMod do
|
4
|
+
it 'should read binary' do
|
5
|
+
msg = OFFlowMod.read [
|
6
|
+
1, 14, 0, 80, 0, 0, 0, 1, # header
|
7
|
+
|
8
|
+
# match
|
9
|
+
0, 0x30, 0x20, 0x4f, # wildcards
|
10
|
+
0, 0, # in_port
|
11
|
+
0, 0, 0, 0, 0, 0, # mac_source
|
12
|
+
0, 0, 0, 0, 0, 0, # mac_destination
|
13
|
+
0xff, 0xff, # vlan_id
|
14
|
+
0, # vlan_pcp
|
15
|
+
0, # padding
|
16
|
+
8, 0, # mac_protocol
|
17
|
+
0, # ip_tos
|
18
|
+
6, # ip_protocol
|
19
|
+
0, 0, # padding
|
20
|
+
0, 0, 0, 0, # ip_source
|
21
|
+
192, 168, 0, 2, # ip_destination
|
22
|
+
0, 0, # source_port
|
23
|
+
0x0b, 0xb8, # destination_port
|
24
|
+
|
25
|
+
0, 0, 0, 0, 0, 0, 0, 1, # cookie
|
26
|
+
0, 0, # command
|
27
|
+
0, 100, # idle_timeout
|
28
|
+
1, 0x2c, # hard_timeout
|
29
|
+
0x0b, 0xb8, # priority
|
30
|
+
0, 0, 0, 1, # buffer_id
|
31
|
+
0, 0, # out_port
|
32
|
+
0, 1, # flags
|
33
|
+
|
34
|
+
# actions
|
35
|
+
# output
|
36
|
+
0, 0, 0, 8, # header
|
37
|
+
0, 1, # port
|
38
|
+
0xff, 0xff, # max_length
|
39
|
+
].pack('C*')
|
40
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
41
|
+
expect(msg.type).to eq(:flow_mod)
|
42
|
+
expect(msg.len).to eq(80)
|
43
|
+
expect(msg.xid).to eq(1)
|
44
|
+
expect(msg.match.ip_destination).to eq('192.168.0.2')
|
45
|
+
expect(msg.cookie).to eq(1)
|
46
|
+
expect(msg.command).to eq(:add)
|
47
|
+
expect(msg.idle_timeout).to eq(100)
|
48
|
+
expect(msg.hard_timeout).to eq(300)
|
49
|
+
expect(msg.priority).to eq(3000)
|
50
|
+
expect(msg.buffer_id).to eq(1)
|
51
|
+
expect(msg.out_port).to eq(0)
|
52
|
+
expect(msg.flags).to eq([:send_flow_removed])
|
53
|
+
expect(msg.actions.length).to eq(1)
|
54
|
+
expect(msg.actions.first.type).to eq(:output)
|
55
|
+
end
|
56
|
+
it 'should initialize with default values' do
|
57
|
+
msg = OFFlowMod.new
|
58
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
59
|
+
expect(msg.type).to eq(:flow_mod)
|
60
|
+
expect(msg.len).to eq(72)
|
61
|
+
expect(msg.xid).to eq(0)
|
62
|
+
expect(msg.match.ip_destination).to eq('0.0.0.0')
|
63
|
+
expect(msg.cookie).to eq(0)
|
64
|
+
expect(msg.command).to eq(:add)
|
65
|
+
expect(msg.idle_timeout).to eq(0)
|
66
|
+
expect(msg.hard_timeout).to eq(0)
|
67
|
+
expect(msg.priority).to eq(0)
|
68
|
+
expect(msg.buffer_id).to eq(:none)
|
69
|
+
expect(msg.out_port).to eq(0)
|
70
|
+
expect(msg.flags).to be_empty
|
71
|
+
expect(msg.actions).to be_empty
|
72
|
+
end
|
73
|
+
it 'should initialize with some values' do
|
74
|
+
msg = OFFlowMod.new(
|
75
|
+
xid: 1,
|
76
|
+
match: {
|
77
|
+
wildcards: {
|
78
|
+
in_port: true,
|
79
|
+
mac_source: true,
|
80
|
+
mac_destination: true,
|
81
|
+
vlan_id: true,
|
82
|
+
vlan_pcp: true,
|
83
|
+
ip_tos: true,
|
84
|
+
ip_source_all: true,
|
85
|
+
ip_destination: 16,
|
86
|
+
source_port: true
|
87
|
+
},
|
88
|
+
mac_protocol: :ipv4,
|
89
|
+
ip_protocol: :tcp,
|
90
|
+
ip_destination: '192.168.0.2',
|
91
|
+
destination_port: 3000
|
92
|
+
},
|
93
|
+
cookie: 1,
|
94
|
+
command: :add,
|
95
|
+
idle_timeout: 100,
|
96
|
+
hard_timeout: 300,
|
97
|
+
priority: 3000,
|
98
|
+
buffer_id: 1,
|
99
|
+
flags: [:send_flow_removed],
|
100
|
+
actions: [OFActionOutput.new(port: 1)]
|
101
|
+
)
|
102
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
103
|
+
expect(msg.type).to eq(:flow_mod)
|
104
|
+
expect(msg.len).to eq(80)
|
105
|
+
expect(msg.xid).to eq(1)
|
106
|
+
expect(msg.match.ip_destination).to eq('192.168.0.2')
|
107
|
+
expect(msg.cookie).to eq(1)
|
108
|
+
expect(msg.command).to eq(:add)
|
109
|
+
expect(msg.idle_timeout).to eq(100)
|
110
|
+
expect(msg.hard_timeout).to eq(300)
|
111
|
+
expect(msg.priority).to eq(3000)
|
112
|
+
expect(msg.buffer_id).to eq(1)
|
113
|
+
expect(msg.out_port).to eq(0)
|
114
|
+
expect(msg.flags).to eq([:send_flow_removed])
|
115
|
+
expect(msg.actions.length).to eq(1)
|
116
|
+
expect(msg.actions.first.type).to eq(:output)
|
117
|
+
end
|
118
|
+
it 'should initialize with some other values' do
|
119
|
+
msg = OFFlowMod.new(
|
120
|
+
xid: 1,
|
121
|
+
cookie: 2,
|
122
|
+
command: :delete
|
123
|
+
)
|
124
|
+
expect(msg.version).to eq(OFMessage::OFP_VERSION)
|
125
|
+
expect(msg.type).to eq(:flow_mod)
|
126
|
+
expect(msg.len).to eq(72)
|
127
|
+
expect(msg.xid).to eq(1)
|
128
|
+
expect(msg.match.ip_destination).to eq('0.0.0.0')
|
129
|
+
expect(msg.cookie).to eq(2)
|
130
|
+
expect(msg.command).to eq(:delete)
|
131
|
+
expect(msg.idle_timeout).to eq(0)
|
132
|
+
expect(msg.hard_timeout).to eq(0)
|
133
|
+
expect(msg.priority).to eq(0)
|
134
|
+
expect(msg.buffer_id).to eq(:none)
|
135
|
+
expect(msg.out_port).to eq(:none)
|
136
|
+
expect(msg.flags).to be_empty
|
137
|
+
expect(msg.actions).to be_empty
|
138
|
+
end
|
139
|
+
end
|