pio 0.16.0 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +26 -25
- data/examples/features_new.rb +20 -17
- data/examples/packet_in_new.rb +5 -7
- data/examples/packet_out_new.rb +1 -1
- data/features/packet_in_read.feature +1 -1
- data/features/packet_out_read.feature +1 -2
- data/lib/pio/arp/format.rb +1 -1
- data/lib/pio/dhcp/frame.rb +2 -2
- data/lib/pio/ethernet_header.rb +15 -16
- data/lib/pio/exact_match.rb +1 -1
- data/lib/pio/features.rb +1 -0
- data/lib/pio/icmp/format.rb +2 -2
- data/lib/pio/ipv4_address.rb +8 -0
- data/lib/pio/ipv4_header.rb +6 -3
- data/lib/pio/lldp/frame.rb +1 -1
- data/lib/pio/packet_in.rb +19 -24
- data/lib/pio/packet_out.rb +3 -3
- data/lib/pio/udp.rb +2 -2
- data/lib/pio/udp_header.rb +1 -1
- data/lib/pio/version.rb +1 -1
- data/pio.gemspec +5 -5
- data/spec/pio/arp_spec.rb +2 -2
- data/spec/pio/ipv4_address_spec.rb +200 -232
- data/spec/pio/packet_in_spec.rb +7 -7
- data/spec/pio/packet_out_spec.rb +17 -17
- metadata +90 -90
data/lib/pio/udp.rb
CHANGED
@@ -11,8 +11,8 @@ module Pio
|
|
11
11
|
include UdpHeader
|
12
12
|
|
13
13
|
endian :big
|
14
|
-
ethernet_header ether_type:
|
15
|
-
ipv4_header ip_protocol:
|
14
|
+
ethernet_header ether_type: EtherType::IPV4
|
15
|
+
ipv4_header ip_protocol: ProtocolNumber::UDP
|
16
16
|
udp_header
|
17
17
|
rest :udp_payload
|
18
18
|
end
|
data/lib/pio/udp_header.rb
CHANGED
data/lib/pio/version.rb
CHANGED
data/pio.gemspec
CHANGED
@@ -37,11 +37,11 @@ Gem::Specification.new do |gem|
|
|
37
37
|
gem.add_dependency 'bindata', '~> 2.1.0'
|
38
38
|
|
39
39
|
gem.add_development_dependency 'rake'
|
40
|
-
gem.add_development_dependency 'bundler', '~> 1.8.
|
40
|
+
gem.add_development_dependency 'bundler', '~> 1.8.4'
|
41
41
|
gem.add_development_dependency 'pry', '~> 0.10.1'
|
42
42
|
|
43
43
|
# Guard
|
44
|
-
gem.add_development_dependency 'guard', '~> 2.12.
|
44
|
+
gem.add_development_dependency 'guard', '~> 2.12.4'
|
45
45
|
gem.add_development_dependency 'guard-bundler', '~> 2.1.0'
|
46
46
|
gem.add_development_dependency 'guard-cucumber', '~> 1.5.3'
|
47
47
|
gem.add_development_dependency 'guard-rspec', '~> 4.5.0'
|
@@ -56,12 +56,12 @@ Gem::Specification.new do |gem|
|
|
56
56
|
gem.add_development_dependency 'yard', '~> 0.8.7.6'
|
57
57
|
|
58
58
|
# Test
|
59
|
-
gem.add_development_dependency 'codeclimate-test-reporter', '~> 0.4.
|
60
|
-
gem.add_development_dependency 'coveralls', '~> 0.7.
|
59
|
+
gem.add_development_dependency 'codeclimate-test-reporter', '~> 0.4.7'
|
60
|
+
gem.add_development_dependency 'coveralls', '~> 0.7.11'
|
61
61
|
gem.add_development_dependency 'cucumber', '~> 1.3.19'
|
62
62
|
gem.add_development_dependency 'flay', '~> 2.6.1'
|
63
63
|
gem.add_development_dependency 'flog', '~> 4.3.2'
|
64
|
-
gem.add_development_dependency 'reek', '~> 2.0.
|
64
|
+
gem.add_development_dependency 'reek', '~> 2.0.1'
|
65
65
|
gem.add_development_dependency 'rspec', '~> 3.2.0'
|
66
66
|
gem.add_development_dependency 'rspec-given', '~> 3.7.0'
|
67
67
|
gem.add_development_dependency 'rubocop', '~> 0.29.1'
|
data/spec/pio/arp_spec.rb
CHANGED
@@ -33,7 +33,7 @@ describe Pio::Arp do
|
|
33
33
|
Then { arp_request.source_mac.to_s == '00:26:82:eb:ea:d1' }
|
34
34
|
Then { arp_request.ether_type == 0x0806 }
|
35
35
|
Then { arp_request.hardware_type == 1 }
|
36
|
-
Then { arp_request.protocol_type ==
|
36
|
+
Then { arp_request.protocol_type == 0x0800 }
|
37
37
|
Then { arp_request.hardware_length == 6 }
|
38
38
|
Then { arp_request.protocol_length == 4 }
|
39
39
|
Then { arp_request.operation == 1 }
|
@@ -70,7 +70,7 @@ describe Pio::Arp do
|
|
70
70
|
Then { arp_reply.source_mac.to_s == '00:16:9d:1d:9c:c4' }
|
71
71
|
Then { arp_reply.ether_type == 0x0806 }
|
72
72
|
Then { arp_reply.hardware_type == 1 }
|
73
|
-
Then { arp_reply.protocol_type ==
|
73
|
+
Then { arp_reply.protocol_type == 0x0800 }
|
74
74
|
Then { arp_reply.hardware_length == 6 }
|
75
75
|
Then { arp_reply.protocol_length == 4 }
|
76
76
|
Then { arp_reply.operation == 2 }
|
@@ -1,302 +1,270 @@
|
|
1
1
|
require 'pio/ipv4_address'
|
2
2
|
|
3
3
|
describe Pio::IPv4Address do
|
4
|
-
|
5
|
-
subject(:ipv4) { Pio::IPv4Address.new(ip_address) }
|
4
|
+
Given(:ipv4) { Pio::IPv4Address.new(ip_address) }
|
6
5
|
|
7
|
-
|
8
|
-
|
6
|
+
context ".new('192.168.1.10')" do
|
7
|
+
Given(:ip_address) { '192.168.1.10' }
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
describe '#to_s' do
|
10
|
+
When(:result) { ipv4.to_s }
|
11
|
+
Then { result == '192.168.1.10' }
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
describe '#to_i' do
|
15
|
+
When(:result) { ipv4.to_i }
|
16
|
+
Then { result == (((192 * 256 + 168) * 256 + 1) * 256 + 10) }
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
describe '#to_range' do
|
20
|
+
When(:result) { ipv4.to_range }
|
21
|
+
Then { result == (ipv4..ipv4) }
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
it { is_expected.to eq [0x0a, 0x01, 0x01, 0x01] }
|
28
|
-
end
|
24
|
+
describe '#==' do
|
25
|
+
When(:result) { ipv4 == other }
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
context "with an IPv4Address ('192.168.1.10)" do
|
28
|
+
When(:other) { Pio::IPv4Address.new('192.168.1.10') }
|
29
|
+
Then { result == true }
|
33
30
|
end
|
34
31
|
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
context "with an IPv4Address ('192.168.1.10/255.255.0.0)" do
|
33
|
+
When(:other) { Pio::IPv4Address.new('192.168.1.10/255.255.0.0') }
|
34
|
+
Then { result == false }
|
38
35
|
end
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
context "with an IPv4Address ('10.0.1.1')" do
|
38
|
+
When(:other) { Pio::IPv4Address.new('10.0.1.1') }
|
39
|
+
Then { result == false }
|
43
40
|
end
|
41
|
+
end
|
44
42
|
|
45
|
-
|
46
|
-
|
47
|
-
it { is_expected.to be_falsey }
|
48
|
-
end
|
43
|
+
describe '#eql?' do
|
44
|
+
When(:result) { ipv4.eql? other }
|
49
45
|
|
50
|
-
|
51
|
-
|
52
|
-
|
46
|
+
context "with an IPv4Address ('192.168.1.10)" do
|
47
|
+
When(:other) { Pio::IPv4Address.new('192.168.1.10') }
|
48
|
+
Then { result == true }
|
53
49
|
end
|
54
50
|
|
55
|
-
|
56
|
-
|
57
|
-
|
51
|
+
context "with an IPv4Address ('192.168.1.10/255.255.0.0)" do
|
52
|
+
When(:other) { Pio::IPv4Address.new('192.168.1.10/255.255.0.0') }
|
53
|
+
Then { result == false }
|
58
54
|
end
|
59
55
|
|
60
|
-
|
61
|
-
|
62
|
-
|
56
|
+
context "with an IPv4Address ('10.0.1.1')" do
|
57
|
+
When(:other) { Pio::IPv4Address.new('10.0.1.1') }
|
58
|
+
Then { result == false }
|
63
59
|
end
|
60
|
+
end
|
64
61
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
describe '#to_s' do
|
71
|
-
subject { super().to_s }
|
72
|
-
it { is_expected.to eq '10.0.0.0' }
|
73
|
-
end
|
74
|
-
|
75
|
-
describe '#to_i' do
|
76
|
-
subject { super().to_i }
|
77
|
-
it { is_expected.to eq 10 * 256 * 256 * 256 }
|
78
|
-
end
|
79
|
-
|
80
|
-
describe '#to_ary' do
|
81
|
-
subject { super().to_ary }
|
82
|
-
it { is_expected.to eq [0x0a, 0x00, 0x00, 0x00] }
|
83
|
-
end
|
84
|
-
|
85
|
-
describe '#class_a?' do
|
86
|
-
subject { super().class_a? }
|
87
|
-
it { is_expected.to be_truthy }
|
88
|
-
end
|
89
|
-
|
90
|
-
describe '#class_b?' do
|
91
|
-
subject { super().class_b? }
|
92
|
-
it { is_expected.to be_falsey }
|
93
|
-
end
|
94
|
-
|
95
|
-
describe '#class_c?' do
|
96
|
-
subject { super().class_c? }
|
97
|
-
it { is_expected.to be_falsey }
|
98
|
-
end
|
99
|
-
|
100
|
-
describe '#class_d?' do
|
101
|
-
subject { super().class_d? }
|
102
|
-
it { is_expected.to be_falsey }
|
103
|
-
end
|
104
|
-
|
105
|
-
describe '#class_e?' do
|
106
|
-
subject { super().class_e? }
|
107
|
-
it { is_expected.to be_falsey }
|
108
|
-
end
|
109
|
-
|
110
|
-
describe '#unicast?' do
|
111
|
-
subject { super().unicast? }
|
112
|
-
it { is_expected.to be_truthy }
|
113
|
-
end
|
114
|
-
|
115
|
-
describe '#multicast?' do
|
116
|
-
subject { super().multicast? }
|
117
|
-
it { is_expected.to be_falsey }
|
118
|
-
end
|
119
|
-
end
|
62
|
+
describe '#hash' do
|
63
|
+
When(:result) { ipv4.hash }
|
64
|
+
Then { result == Pio::IPv4Address.new('192.168.1.10').hash }
|
65
|
+
Then { result != Pio::IPv4Address.new('192.168.1.10/255.255.0.0').hash }
|
66
|
+
Then { result != Pio::IPv4Address.new('10.0.1.1').hash }
|
120
67
|
end
|
121
68
|
|
122
|
-
|
123
|
-
|
69
|
+
describe '#to_a' do
|
70
|
+
When(:result) { ipv4.to_a }
|
71
|
+
Then { result == [192, 168, 1, 10] }
|
72
|
+
end
|
124
73
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
74
|
+
describe '#to_ary' do
|
75
|
+
When(:result) { ipv4.to_ary }
|
76
|
+
Then { result == [192, 168, 1, 10] }
|
77
|
+
end
|
129
78
|
|
130
|
-
|
131
|
-
|
132
|
-
it { is_expected.to eq(((172 * 256 + 20) * 256 + 1) * 256 + 1) }
|
133
|
-
end
|
79
|
+
describe '#mask' do
|
80
|
+
When(:result) { ipv4.mask(masklen) }
|
134
81
|
|
135
|
-
|
136
|
-
|
137
|
-
|
82
|
+
context 'with 8' do
|
83
|
+
Given(:masklen) { 8 }
|
84
|
+
Then { result.to_s == '192.0.0.0' }
|
138
85
|
end
|
139
86
|
|
140
|
-
|
141
|
-
|
142
|
-
|
87
|
+
context 'with 16' do
|
88
|
+
Given(:masklen) { 16 }
|
89
|
+
Then { result.to_s == '192.168.0.0' }
|
143
90
|
end
|
144
91
|
|
145
|
-
|
146
|
-
|
147
|
-
|
92
|
+
context 'with 24' do
|
93
|
+
Given(:masklen) { 24 }
|
94
|
+
Then { result.to_s == '192.168.1.0' }
|
148
95
|
end
|
96
|
+
end
|
97
|
+
end
|
149
98
|
|
150
|
-
|
151
|
-
|
152
|
-
it { is_expected.to be_falsey }
|
153
|
-
end
|
99
|
+
describe '#class_a?' do
|
100
|
+
When(:result) { ipv4.class_a? }
|
154
101
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
102
|
+
context 'when IP address = 192.168.0.1' do
|
103
|
+
Given(:ip_address) { '192.168.0.1' }
|
104
|
+
Then { result == false }
|
105
|
+
end
|
159
106
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
107
|
+
context 'when IP address = 0.0.0.0' do
|
108
|
+
Given(:ip_address) { '0.0.0.0' }
|
109
|
+
Then { result == true }
|
110
|
+
end
|
164
111
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
112
|
+
context 'when IP address = 127.255.255.255' do
|
113
|
+
Given(:ip_address) { '127.255.255.255' }
|
114
|
+
Then { result == true }
|
115
|
+
end
|
116
|
+
end
|
169
117
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
118
|
+
describe '#class_b?' do
|
119
|
+
When(:result) { ipv4.class_b? }
|
120
|
+
|
121
|
+
context 'when IP address = 223.255.255.255' do
|
122
|
+
Given(:ip_address) { '223.255.255.255' }
|
123
|
+
Then { result == false }
|
174
124
|
end
|
175
125
|
|
176
|
-
context '
|
177
|
-
|
126
|
+
context 'when IP address = 128.0.0.0' do
|
127
|
+
Given(:ip_address) { '128.0.0.0' }
|
128
|
+
Then { result == true }
|
129
|
+
end
|
178
130
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
131
|
+
context 'when IP address = 191.255.255.255' do
|
132
|
+
Given(:ip_address) { '191.255.255.255' }
|
133
|
+
Then { result == true }
|
134
|
+
end
|
135
|
+
end
|
183
136
|
|
184
|
-
|
185
|
-
|
186
|
-
it { is_expected.to eq 3_232_235_777 }
|
187
|
-
end
|
137
|
+
describe '#class_c?' do
|
138
|
+
When(:result) { ipv4.class_c? }
|
188
139
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
140
|
+
context 'when IP address = 10.1.1.1' do
|
141
|
+
Given(:ip_address) { '10.1.1.1' }
|
142
|
+
Then { result == false }
|
143
|
+
end
|
193
144
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
145
|
+
context 'when IP address = 192.0.0.0' do
|
146
|
+
Given(:ip_address) { '192.0.0.0' }
|
147
|
+
Then { result == true }
|
148
|
+
end
|
198
149
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
150
|
+
context 'when IP address = 223.255.255.255' do
|
151
|
+
Given(:ip_address) { '223.255.255.255' }
|
152
|
+
Then { result == true }
|
153
|
+
end
|
154
|
+
end
|
203
155
|
|
204
|
-
|
205
|
-
|
206
|
-
it { is_expected.to be_truthy }
|
207
|
-
end
|
156
|
+
describe '#class_d?' do
|
157
|
+
When(:result) { ipv4.class_d? }
|
208
158
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
159
|
+
context 'when IP address = 10.1.1.1' do
|
160
|
+
Given(:ip_address) { '10.1.1.1' }
|
161
|
+
Then { result == false }
|
162
|
+
end
|
213
163
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
164
|
+
context 'when IP address = 224.0.0.0' do
|
165
|
+
Given(:ip_address) { '224.0.0.0' }
|
166
|
+
Then { result == true }
|
167
|
+
end
|
218
168
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
169
|
+
context 'when IP address = 239.255.255.255' do
|
170
|
+
Given(:ip_address) { '239.255.255.255' }
|
171
|
+
Then { result == true }
|
172
|
+
end
|
173
|
+
end
|
223
174
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
175
|
+
describe '#class_e?' do
|
176
|
+
When(:result) { ipv4.class_e? }
|
177
|
+
|
178
|
+
context 'when IP address = 10.1.1.1' do
|
179
|
+
Given(:ip_address) { '10.1.1.1' }
|
180
|
+
Then { result == false }
|
228
181
|
end
|
229
182
|
|
230
|
-
context '
|
231
|
-
|
183
|
+
context 'when IP address = 240.0.0.0' do
|
184
|
+
Given(:ip_address) { '240.0.0.0' }
|
185
|
+
Then { result == true }
|
186
|
+
end
|
232
187
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
188
|
+
context 'when IP address = 255.255.255.255' do
|
189
|
+
Given(:ip_address) { '255.255.255.255' }
|
190
|
+
Then { result == true }
|
191
|
+
end
|
192
|
+
end
|
237
193
|
|
238
|
-
|
239
|
-
|
240
|
-
it { is_expected.to eq(((234 * 256 + 1) * 256 + 1) * 256 + 1) }
|
241
|
-
end
|
194
|
+
describe '#unicast?' do
|
195
|
+
When(:result) { ipv4.unicast? }
|
242
196
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
197
|
+
context 'when IP address = 10.1.1.1' do
|
198
|
+
Given(:ip_address) { '10.1.1.1' }
|
199
|
+
Then { result == true }
|
200
|
+
end
|
247
201
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
202
|
+
context 'when IP address = 234.1.1.1' do
|
203
|
+
Given(:ip_address) { '234.1.1.1' }
|
204
|
+
Then { result == false }
|
205
|
+
end
|
206
|
+
end
|
252
207
|
|
253
|
-
|
254
|
-
|
255
|
-
it { is_expected.to be_falsey }
|
256
|
-
end
|
208
|
+
describe '#multicast?' do
|
209
|
+
When(:result) { ipv4.multicast? }
|
257
210
|
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
211
|
+
context 'when IP address = 10.1.1.1' do
|
212
|
+
Given(:ip_address) { '10.1.1.1' }
|
213
|
+
Then { result == false }
|
214
|
+
end
|
262
215
|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
216
|
+
context 'when IP address = 234.1.1.1' do
|
217
|
+
Given(:ip_address) { '234.1.1.1' }
|
218
|
+
Then { result == true }
|
219
|
+
end
|
220
|
+
end
|
267
221
|
|
268
|
-
|
269
|
-
|
270
|
-
it { is_expected.to be_falsey }
|
271
|
-
end
|
222
|
+
describe '#prefixlen' do
|
223
|
+
When(:result) { ipv4.prefixlen }
|
272
224
|
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
225
|
+
context 'IP address = with 10.1.1.1' do
|
226
|
+
Given(:ip_address) { '10.1.1.1' }
|
227
|
+
Then { result == 32 }
|
228
|
+
end
|
277
229
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
end
|
230
|
+
context 'IP address = with 10.1.1.1/255.255.255.255' do
|
231
|
+
Given(:ip_address) { '10.1.1.1/255.255.255.255' }
|
232
|
+
Then { result == 32 }
|
282
233
|
end
|
283
234
|
|
284
|
-
context 'with
|
285
|
-
|
235
|
+
context 'IP address = with 10.1.1.1/32' do
|
236
|
+
Given(:ip_address) { '10.1.1.1/32' }
|
237
|
+
Then { result == 32 }
|
238
|
+
end
|
286
239
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
end
|
240
|
+
context 'when IP address = 192.168.0.1/255.255.255.0' do
|
241
|
+
Given(:ip_address) { '192.168.0.1/255.255.255.0' }
|
242
|
+
Then { result == 24 }
|
291
243
|
end
|
292
244
|
|
293
|
-
context '
|
294
|
-
|
245
|
+
context 'when IP address = 192.168.0.1/24' do
|
246
|
+
Given(:ip_address) { '192.168.0.1/24' }
|
247
|
+
Then { result == 24 }
|
248
|
+
end
|
295
249
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
250
|
+
context 'when IP address = 192.168.0.1/255.255.0.0' do
|
251
|
+
Given(:ip_address) { '192.168.0.1/255.255.0.0' }
|
252
|
+
Then { result == 16 }
|
253
|
+
end
|
254
|
+
|
255
|
+
context 'when IP address = 192.168.0.1/16' do
|
256
|
+
Given(:ip_address) { '192.168.0.1/16' }
|
257
|
+
Then { result == 16 }
|
258
|
+
end
|
259
|
+
|
260
|
+
context 'when IP address = 192.168.0.1/255.0.0.0' do
|
261
|
+
Given(:ip_address) { '192.168.0.1/255.0.0.0' }
|
262
|
+
Then { result == 8 }
|
263
|
+
end
|
264
|
+
|
265
|
+
context 'when IP address = 192.168.0.1/8' do
|
266
|
+
Given(:ip_address) { '192.168.0.1/8' }
|
267
|
+
Then { result == 8 }
|
300
268
|
end
|
301
269
|
end
|
302
270
|
end
|