pio 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +56 -22
  4. data/examples/dhcp_new.rb +22 -18
  5. data/examples/features_new.rb +14 -0
  6. data/examples/features_read.rb +4 -0
  7. data/features/arp_read.feature +4 -4
  8. data/features/dhcp_read.feature +2 -2
  9. data/features/echo_read.feature +5 -0
  10. data/features/features_read.feature +10 -0
  11. data/features/hello_read.feature +5 -0
  12. data/features/icmp_read.feature +2 -2
  13. data/features/lldp_read.feature +4 -4
  14. data/features/{pcap → packet_data}/arp-storm.pcap +0 -0
  15. data/features/{pcap → packet_data}/arp.pcap +0 -0
  16. data/features/{pcap → packet_data}/dhcp.pcap +0 -0
  17. data/features/packet_data/echo.raw +0 -0
  18. data/features/packet_data/features_reply.raw +0 -0
  19. data/features/packet_data/features_request.raw +0 -0
  20. data/features/packet_data/hello.raw +0 -0
  21. data/features/{pcap → packet_data}/icmp.pcap +0 -0
  22. data/features/{pcap → packet_data}/lldp.detailed.pcap +0 -0
  23. data/features/{pcap → packet_data}/lldp.minimal.pcap +0 -0
  24. data/features/step_definitions/packet_data_steps.rb +32 -0
  25. data/features/step_definitions/pending_steps.rb +5 -0
  26. data/lib/pio.rb +1 -0
  27. data/lib/pio/arp.rb +1 -1
  28. data/lib/pio/arp/{frame.rb → format.rb} +2 -2
  29. data/lib/pio/arp/message.rb +2 -2
  30. data/lib/pio/dhcp/dhcp_field.rb +3 -3
  31. data/lib/pio/dhcp/frame.rb +6 -6
  32. data/lib/pio/dhcp/optional_tlv.rb +3 -3
  33. data/lib/pio/echo.rb +4 -11
  34. data/lib/pio/echo/format.rb +5 -5
  35. data/lib/pio/echo/message.rb +13 -4
  36. data/lib/pio/echo/reply.rb +29 -0
  37. data/lib/pio/echo/request.rb +29 -0
  38. data/lib/pio/features.rb +18 -0
  39. data/lib/pio/features/format.rb +18 -0
  40. data/lib/pio/features/message.rb +14 -0
  41. data/lib/pio/features/reply.rb +73 -0
  42. data/lib/pio/features/request.rb +63 -0
  43. data/lib/pio/hello.rb +40 -9
  44. data/lib/pio/icmp.rb +1 -1
  45. data/lib/pio/icmp/{frame.rb → format.rb} +2 -2
  46. data/lib/pio/icmp/message.rb +2 -2
  47. data/lib/pio/icmp/request.rb +30 -14
  48. data/lib/pio/message_type_selector.rb +4 -7
  49. data/lib/pio/type/ethernet_header.rb +0 -2
  50. data/lib/pio/type/ipv4_header.rb +0 -1
  51. data/lib/pio/type/open_flow.rb +34 -0
  52. data/lib/pio/type/udp_header.rb +0 -1
  53. data/lib/pio/version.rb +1 -1
  54. data/pio.gemspec +2 -2
  55. data/spec/pio/dhcp/ack_spec.rb +1 -1
  56. data/spec/pio/dhcp_spec.rb +2 -2
  57. data/spec/pio/echo/reply_spec.rb +69 -4
  58. data/spec/pio/echo/request_spec.rb +48 -10
  59. data/spec/pio/echo_spec.rb +8 -0
  60. data/spec/pio/features/reply_spec.rb +30 -0
  61. data/spec/pio/features/request_spec.rb +70 -0
  62. data/spec/pio/features_spec.rb +78 -0
  63. data/spec/pio/hello_spec.rb +35 -6
  64. data/spec/spec_helper.rb +3 -0
  65. metadata +70 -40
  66. data/features/step_definitions/pcap_steps.rb +0 -18
@@ -0,0 +1,78 @@
1
+ # encoding: utf-8
2
+
3
+ require 'pio'
4
+
5
+ describe Pio::Features do
6
+ describe '.read' do
7
+ context 'with a Features Request message' do
8
+ Given(:features_request_dump) { [1, 5, 0, 8, 0, 0, 0, 0].pack('C*') }
9
+
10
+ When(:features_request) { Pio::Features.read(features_request_dump) }
11
+
12
+ Then { features_request.class == Pio::Features::Request }
13
+ Then { features_request.version == 1 }
14
+ Then { features_request.message_type == Pio::Features::REQUEST }
15
+ Then { features_request.message_length == 8 }
16
+ Then { features_request.transaction_id == 0 }
17
+ Then { features_request.xid == 0 }
18
+ Then { features_request.body.empty? }
19
+ end
20
+
21
+ context 'with a Features Reply message' do
22
+ Given(:features_reply_dump) do
23
+ [0x01, 0x06, 0x01, 0x10, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
24
+ 0xe2, 0xfc, 0x0f, 0xae, 0x66, 0x4d, 0x00, 0x00, 0x01, 0x00,
25
+ 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc7, 0x00, 0x00,
26
+ 0x0f, 0xff, 0x00, 0x03, 0x82, 0xb0, 0xff, 0x6e, 0x51, 0x44,
27
+ 0x76, 0x65, 0x74, 0x68, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
28
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
29
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00,
30
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
31
+ 0x00, 0x01, 0x9e, 0x49, 0x7d, 0x7c, 0x06, 0x8d, 0x76, 0x65,
32
+ 0x74, 0x68, 0x32, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00,
35
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
36
+ 0x12, 0x13, 0xb4, 0x13, 0x4c, 0x19, 0x76, 0x65, 0x74, 0x68,
37
+ 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
38
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
39
+ 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
40
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x86, 0xbd,
41
+ 0xe3, 0xad, 0x3d, 0x73, 0x76, 0x65, 0x74, 0x68, 0x31, 0x62,
42
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
43
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44
+ 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
45
+ 0x00, 0x00, 0x00, 0x00, 0xff, 0xfe, 0xe2, 0xfc, 0x0f, 0xae,
46
+ 0x66, 0x4d, 0x62, 0x72, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
47
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
48
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
49
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
50
+ 0x00, 0x00].pack('C*')
51
+ end
52
+
53
+ When(:features_reply) { Pio::Features.read(features_reply_dump) }
54
+
55
+ Then { features_reply.class == Pio::Features::Reply }
56
+ Then { features_reply.version == 1 }
57
+ Then { features_reply.message_type == Pio::Features::REPLY }
58
+ Then { features_reply.message_length == 272 }
59
+ Then { features_reply.transaction_id == 2 }
60
+ Then { features_reply.xid == 2 }
61
+ Then { !features_reply.body.empty? }
62
+ Then { features_reply.datapath_id == 0xe2fc0fae664d }
63
+ Then { features_reply.n_buffers == 0x100 }
64
+ Then { features_reply.n_tables == 0xfe }
65
+ Then { features_reply.capabilities == 0xc7 }
66
+ Then { features_reply.actions == 0xfff }
67
+ Then { features_reply.ports.size == 7 }
68
+ end
69
+
70
+ context 'with a Hello message' do
71
+ Given(:hello_dump) { [1, 0, 0, 8, 0, 0, 0, 0].pack('C*') }
72
+
73
+ When(:result) { Pio::Features.read(hello_dump) }
74
+
75
+ Then { result == Failure(Pio::ParseError) }
76
+ end
77
+ end
78
+ end
@@ -4,7 +4,7 @@ require 'pio'
4
4
 
5
5
  describe Pio::Hello do
6
6
  describe '.read' do
7
- context 'with an hello message' do
7
+ context 'with a hello message' do
8
8
  Given(:hello_dump) { [1, 0, 0, 8, 0, 0, 0, 0].pack('C*') }
9
9
 
10
10
  When(:hello) { Pio::Hello.read(hello_dump) }
@@ -13,15 +13,17 @@ describe Pio::Hello do
13
13
  Then { hello.version == 1 }
14
14
  Then { hello.message_type == 0 }
15
15
  Then { hello.message_length == 8 }
16
+ Then { hello.transaction_id == 0 }
16
17
  Then { hello.xid == 0 }
17
18
  Then { hello.body.empty? }
18
19
  end
19
20
 
20
- context 'with an features-request message' do
21
+ context 'with a features-request message' do
21
22
  Given(:features_request_dump) { [1, 5, 0, 8, 0, 0, 0, 0].pack('C*') }
22
23
 
23
24
  When(:result) { Pio::Hello.read(features_request_dump) }
24
- Then { result == Failure(BinData::ValidityError) }
25
+
26
+ Then { result == Failure(Pio::ParseError) }
25
27
  end
26
28
  end
27
29
 
@@ -29,22 +31,43 @@ describe Pio::Hello do
29
31
  context 'with no arguments' do
30
32
  When(:hello) { Pio::Hello.new }
31
33
 
32
- Then { hello.class == Pio::Hello }
33
34
  Then { hello.version == 1 }
34
35
  Then { hello.message_type == 0 }
35
36
  Then { hello.message_length == 8 }
37
+ Then { hello.transaction_id == 0 }
36
38
  Then { hello.xid == 0 }
37
39
  Then { hello.body.empty? }
38
40
  Then { hello.to_binary == [1, 0, 0, 8, 0, 0, 0, 0].pack('C*') }
39
41
  end
40
42
 
43
+ context 'with 123' do
44
+ When(:hello) { Pio::Hello.new(123) }
45
+
46
+ Then { hello.version == 1 }
47
+ Then { hello.message_type == 0 }
48
+ Then { hello.message_length == 8 }
49
+ Then { hello.transaction_id == 123 }
50
+ Then { hello.xid == 123 }
51
+ Then { hello.body.empty? }
52
+ Then { hello.to_binary == [1, 0, 0, 8, 0, 0, 0, 123].pack('C*') }
53
+ end
54
+
55
+ context 'with 2**32' do
56
+ When(:result) { Pio::Hello.new(2**32) }
57
+
58
+ Then do
59
+ pending 'check if xid is within 32bit range.'
60
+ result == Failure(ArgumentError)
61
+ end
62
+ end
63
+
41
64
  context 'with transaction_id: 123' do
42
65
  When(:hello) { Pio::Hello.new(transaction_id: 123) }
43
66
 
44
- Then { hello.class == Pio::Hello }
45
67
  Then { hello.version == 1 }
46
68
  Then { hello.message_type == 0 }
47
69
  Then { hello.message_length == 8 }
70
+ Then { hello.transaction_id == 123 }
48
71
  Then { hello.xid == 123 }
49
72
  Then { hello.body.empty? }
50
73
  Then { hello.to_binary == [1, 0, 0, 8, 0, 0, 0, 123].pack('C*') }
@@ -53,13 +76,19 @@ describe Pio::Hello do
53
76
  context 'with xid: 123' do
54
77
  When(:hello) { Pio::Hello.new(xid: 123) }
55
78
 
56
- Then { hello.class == Pio::Hello }
57
79
  Then { hello.version == 1 }
58
80
  Then { hello.message_type == 0 }
59
81
  Then { hello.message_length == 8 }
82
+ Then { hello.transaction_id == 123 }
60
83
  Then { hello.xid == 123 }
61
84
  Then { hello.body.empty? }
62
85
  Then { hello.to_binary == [1, 0, 0, 8, 0, 0, 0, 123].pack('C*') }
63
86
  end
87
+
88
+ context 'with :INVALID_ARGUMENT' do
89
+ When(:result) { Pio::Hello.new(:INVALID_ARGUMENT) }
90
+
91
+ Then { result == Failure(TypeError) }
92
+ end
64
93
  end
65
94
  end
@@ -2,6 +2,9 @@
2
2
 
3
3
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
4
 
5
+ require 'codeclimate-test-reporter'
6
+ CodeClimate::TestReporter.start
7
+
5
8
  require 'simplecov'
6
9
  SimpleCov.start
7
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yasuhito Takamiya
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-15 00:00:00.000000000 Z
11
+ date: 2014-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.0
19
+ version: 2.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 2.0.0
26
+ version: 2.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 1.6.0
33
+ version: 1.6.2
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: 1.6.0
40
+ version: 1.6.2
41
41
  description: Pure ruby packet parser and generator.
42
42
  email:
43
43
  - yasuhito@gmail.com
@@ -60,6 +60,8 @@ files:
60
60
  - examples/dhcp_read.rb
61
61
  - examples/echo_new.rb
62
62
  - examples/echo_read.rb
63
+ - examples/features_new.rb
64
+ - examples/features_read.rb
63
65
  - examples/hello_new.rb
64
66
  - examples/hello_read.rb
65
67
  - examples/icmp_new.rb
@@ -68,19 +70,27 @@ files:
68
70
  - examples/lldp_read.rb
69
71
  - features/arp_read.feature
70
72
  - features/dhcp_read.feature
73
+ - features/echo_read.feature
74
+ - features/features_read.feature
75
+ - features/hello_read.feature
71
76
  - features/icmp_read.feature
72
77
  - features/lldp_read.feature
73
- - features/pcap/arp-storm.pcap
74
- - features/pcap/arp.pcap
75
- - features/pcap/dhcp.pcap
76
- - features/pcap/icmp.pcap
77
- - features/pcap/lldp.detailed.pcap
78
- - features/pcap/lldp.minimal.pcap
79
- - features/step_definitions/pcap_steps.rb
78
+ - features/packet_data/arp-storm.pcap
79
+ - features/packet_data/arp.pcap
80
+ - features/packet_data/dhcp.pcap
81
+ - features/packet_data/echo.raw
82
+ - features/packet_data/features_reply.raw
83
+ - features/packet_data/features_request.raw
84
+ - features/packet_data/hello.raw
85
+ - features/packet_data/icmp.pcap
86
+ - features/packet_data/lldp.detailed.pcap
87
+ - features/packet_data/lldp.minimal.pcap
88
+ - features/step_definitions/packet_data_steps.rb
89
+ - features/step_definitions/pending_steps.rb
80
90
  - features/support/env.rb
81
91
  - lib/pio.rb
82
92
  - lib/pio/arp.rb
83
- - lib/pio/arp/frame.rb
93
+ - lib/pio/arp/format.rb
84
94
  - lib/pio/arp/message.rb
85
95
  - lib/pio/arp/reply.rb
86
96
  - lib/pio/arp/request.rb
@@ -108,10 +118,15 @@ files:
108
118
  - lib/pio/echo/message.rb
109
119
  - lib/pio/echo/reply.rb
110
120
  - lib/pio/echo/request.rb
121
+ - lib/pio/features.rb
122
+ - lib/pio/features/format.rb
123
+ - lib/pio/features/message.rb
124
+ - lib/pio/features/reply.rb
125
+ - lib/pio/features/request.rb
111
126
  - lib/pio/hello.rb
112
127
  - lib/pio/hello/format.rb
113
128
  - lib/pio/icmp.rb
114
- - lib/pio/icmp/frame.rb
129
+ - lib/pio/icmp/format.rb
115
130
  - lib/pio/icmp/message.rb
116
131
  - lib/pio/icmp/options.rb
117
132
  - lib/pio/icmp/reply.rb
@@ -140,6 +155,7 @@ files:
140
155
  - lib/pio/type/ip_address.rb
141
156
  - lib/pio/type/ipv4_header.rb
142
157
  - lib/pio/type/mac_address.rb
158
+ - lib/pio/type/open_flow.rb
143
159
  - lib/pio/type/udp_header.rb
144
160
  - lib/pio/version.rb
145
161
  - pio.gemspec
@@ -156,6 +172,9 @@ files:
156
172
  - spec/pio/echo/reply_spec.rb
157
173
  - spec/pio/echo/request_spec.rb
158
174
  - spec/pio/echo_spec.rb
175
+ - spec/pio/features/reply_spec.rb
176
+ - spec/pio/features/request_spec.rb
177
+ - spec/pio/features_spec.rb
159
178
  - spec/pio/hello_spec.rb
160
179
  - spec/pio/icmp/reply_spec.rb
161
180
  - spec/pio/icmp/request_spec.rb
@@ -190,38 +209,49 @@ signing_key:
190
209
  specification_version: 4
191
210
  summary: Packet parser and generator.
192
211
  test_files:
193
- - spec/pio/ipv4_address_spec.rb
194
- - spec/pio/hello_spec.rb
195
- - spec/pio/dhcp/request_spec.rb
196
- - spec/pio/dhcp/offer_spec.rb
212
+ - spec/pio/arp/reply/options_spec.rb
213
+ - spec/pio/arp/reply_spec.rb
214
+ - spec/pio/arp/request/options_spec.rb
215
+ - spec/pio/arp/request_spec.rb
216
+ - spec/pio/arp_spec.rb
197
217
  - spec/pio/dhcp/ack_spec.rb
198
218
  - spec/pio/dhcp/discover_spec.rb
219
+ - spec/pio/dhcp/offer_spec.rb
220
+ - spec/pio/dhcp/request_spec.rb
221
+ - spec/pio/dhcp_spec.rb
222
+ - spec/pio/echo/reply_spec.rb
223
+ - spec/pio/echo/request_spec.rb
199
224
  - spec/pio/echo_spec.rb
200
- - spec/pio/arp/request_spec.rb
201
- - spec/pio/arp/reply/options_spec.rb
202
- - spec/pio/arp/request/options_spec.rb
203
- - spec/pio/arp/reply_spec.rb
204
- - spec/pio/lldp/options_spec.rb
205
- - spec/pio/mac_spec.rb
206
- - spec/pio/icmp/request_spec.rb
225
+ - spec/pio/features/reply_spec.rb
226
+ - spec/pio/features/request_spec.rb
227
+ - spec/pio/features_spec.rb
228
+ - spec/pio/hello_spec.rb
207
229
  - spec/pio/icmp/reply_spec.rb
230
+ - spec/pio/icmp/request_spec.rb
208
231
  - spec/pio/icmp_spec.rb
209
- - spec/pio/dhcp_spec.rb
232
+ - spec/pio/ipv4_address_spec.rb
233
+ - spec/pio/lldp/options_spec.rb
210
234
  - spec/pio/lldp_spec.rb
211
- - spec/pio/arp_spec.rb
212
- - spec/pio/echo/request_spec.rb
213
- - spec/pio/echo/reply_spec.rb
235
+ - spec/pio/mac_spec.rb
214
236
  - spec/spec_helper.rb
215
- - features/pcap/dhcp.pcap
216
- - features/pcap/arp.pcap
217
- - features/pcap/lldp.minimal.pcap
218
- - features/pcap/icmp.pcap
219
- - features/pcap/arp-storm.pcap
220
- - features/pcap/lldp.detailed.pcap
221
- - features/support/env.rb
222
- - features/icmp_read.feature
223
237
  - features/arp_read.feature
224
- - features/step_definitions/pcap_steps.rb
225
- - features/lldp_read.feature
226
238
  - features/dhcp_read.feature
239
+ - features/echo_read.feature
240
+ - features/features_read.feature
241
+ - features/hello_read.feature
242
+ - features/icmp_read.feature
243
+ - features/lldp_read.feature
244
+ - features/packet_data/arp-storm.pcap
245
+ - features/packet_data/arp.pcap
246
+ - features/packet_data/dhcp.pcap
247
+ - features/packet_data/echo.raw
248
+ - features/packet_data/features_reply.raw
249
+ - features/packet_data/features_request.raw
250
+ - features/packet_data/hello.raw
251
+ - features/packet_data/icmp.pcap
252
+ - features/packet_data/lldp.detailed.pcap
253
+ - features/packet_data/lldp.minimal.pcap
254
+ - features/step_definitions/packet_data_steps.rb
255
+ - features/step_definitions/pending_steps.rb
256
+ - features/support/env.rb
227
257
  has_rdoc:
@@ -1,18 +0,0 @@
1
- # encoding: utf-8
2
-
3
- Given(/^a pcap file "(.*?)"$/) do |pcap|
4
- @pcap = File.join(File.dirname(__FILE__), '..', 'pcap', pcap)
5
- end
6
-
7
- When(/^I try to parse the pcap file with "(.*?)" class$/) do |parser|
8
- File.open(@pcap) do |file|
9
- pcap = Pio::Pcap::Frame.read(file)
10
- pcap.records.each do |each|
11
- Pio.const_get(parser).__send__ :read, each.data
12
- end
13
- end
14
- end
15
-
16
- Then(/^it should finish successfully$/) do
17
- # Noop.
18
- end