pio 0.2.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/.travis.yml +1 -0
  4. data/CONTRIBUTING.md +12 -0
  5. data/Gemfile +26 -23
  6. data/Guardfile +5 -0
  7. data/README.md +61 -19
  8. data/Rakefile +54 -56
  9. data/lib/pio/arp/frame.rb +8 -6
  10. data/lib/pio/arp/message.rb +9 -23
  11. data/lib/pio/arp/reply.rb +6 -15
  12. data/lib/pio/arp/request.rb +7 -16
  13. data/lib/pio/arp.rb +14 -17
  14. data/lib/pio/icmp/frame.rb +131 -0
  15. data/lib/pio/icmp/message.rb +100 -0
  16. data/lib/pio/icmp/reply.rb +17 -0
  17. data/lib/pio/icmp/request.rb +17 -0
  18. data/lib/pio/icmp.rb +27 -0
  19. data/lib/pio/ipv4_address.rb +22 -39
  20. data/lib/pio/lldp/chassis_id_tlv.rb +13 -16
  21. data/lib/pio/lldp/end_of_lldpdu_value.rb +4 -5
  22. data/lib/pio/lldp/frame.rb +21 -32
  23. data/lib/pio/lldp/management_address_value.rb +3 -4
  24. data/lib/pio/lldp/optional_tlv.rb +13 -22
  25. data/lib/pio/lldp/organizationally_specific_value.rb +3 -4
  26. data/lib/pio/lldp/port_description_value.rb +3 -4
  27. data/lib/pio/lldp/port_id_tlv.rb +6 -9
  28. data/lib/pio/lldp/system_capabilities_value.rb +3 -4
  29. data/lib/pio/lldp/system_description_value.rb +3 -4
  30. data/lib/pio/lldp/system_name_value.rb +3 -4
  31. data/lib/pio/lldp/ttl_tlv.rb +6 -9
  32. data/lib/pio/lldp.rb +20 -36
  33. data/lib/pio/mac.rb +30 -53
  34. data/lib/pio/message_util.rb +19 -0
  35. data/lib/pio/type/config.reek +4 -0
  36. data/lib/pio/type/ethernet_header.rb +7 -4
  37. data/lib/pio/type/ip_address.rb +5 -8
  38. data/lib/pio/type/ipv4_header.rb +37 -0
  39. data/lib/pio/type/mac_address.rb +7 -8
  40. data/lib/pio/util.rb +21 -0
  41. data/lib/pio/version.rb +2 -2
  42. data/lib/pio.rb +4 -4
  43. data/pio.gemspec +15 -17
  44. data/pio.org +499 -76
  45. data/pio.org_archive +86 -0
  46. data/rubocop-todo.yml +9 -0
  47. data/spec/pio/arp/reply_spec.rb +106 -118
  48. data/spec/pio/arp/request_spec.rb +90 -101
  49. data/spec/pio/arp_spec.rb +105 -113
  50. data/spec/pio/icmp/reply_spec.rb +132 -0
  51. data/spec/pio/icmp/request_spec.rb +131 -0
  52. data/spec/pio/icmp_spec.rb +159 -0
  53. data/spec/pio/ipv4_address_spec.rb +87 -97
  54. data/spec/pio/lldp_spec.rb +237 -186
  55. data/spec/pio/mac_spec.rb +82 -93
  56. data/spec/spec_helper.rb +10 -13
  57. metadata +20 -2
data/spec/pio/mac_spec.rb CHANGED
@@ -1,121 +1,110 @@
1
- require "pio/mac"
2
-
3
-
4
- module Pio
5
- describe Mac do
6
- context ".new" do
7
- subject { Mac.new( value ) }
8
-
9
-
10
- context %{with "11:22:33:44:55:66"} do
11
- let( :value ) { "11:22:33:44:55:66" }
12
-
13
- describe "#==" do
14
- it { should eq Mac.new( "11:22:33:44:55:66" ) }
15
- it { should eq "11:22:33:44:55:66" }
16
- it { should_not eq Mac.new( "66:55:44:33:22:11" ) }
17
- it { should_not eq "66:55:44:33:22:11" }
18
- it { should eq 0x112233445566 }
19
- it { should_not eq 42 }
20
- it { should_not eq "INVALID_MAC_ADDRESS" }
21
- end
22
- describe "#eql?" do
23
- it { expect( subject ).to eql Mac.new( "11:22:33:44:55:66" ) }
24
- it { expect( subject ).to eql "11:22:33:44:55:66" }
25
- it { expect( subject ).not_to eql Mac.new( "66:55:44:33:22:11" ) }
26
- it { expect( subject ).not_to eql "66:55:44:33:22:11" }
27
- it { expect( subject ).to eql 0x112233445566 }
28
- it { expect( subject ).not_to eql 42 }
29
- it { expect( subject ).not_to eql "INVALID_MAC_ADDRESS" }
30
- end
31
-
32
- its( :hash ) { should eq Mac.new( "11:22:33:44:55:66" ).hash }
33
-
34
- its( :to_i ) { should eq 0x112233445566 }
35
- its( :to_a ) { should eq [ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 ] }
36
- its( :to_s ) { should eq "11:22:33:44:55:66" }
37
- describe "#to_str" do
38
- context %{when "MAC = " + subject} do
39
- it { expect( "MAC = " + subject ).to eq "MAC = 11:22:33:44:55:66" }
40
- end
41
- end
42
-
43
- its( :multicast? ){ should be_true }
44
- its( :broadcast? ){ should be_false }
45
- its( :reserved? ){ should be_false }
1
+ # -*- coding: utf-8 -*-
2
+ require 'pio/mac'
3
+
4
+ describe Pio::Mac do
5
+ context '.new' do
6
+ subject { Pio::Mac.new(value) }
7
+
8
+ context 'with "11:22:33:44:55:66"' do
9
+ let(:value) { '11:22:33:44:55:66' }
10
+
11
+ describe '#==' do
12
+ it { should eq Pio::Mac.new('11:22:33:44:55:66') }
13
+ it { should eq '11:22:33:44:55:66' }
14
+ it { should_not eq Pio::Mac.new('66:55:44:33:22:11') }
15
+ it { should_not eq '66:55:44:33:22:11' }
16
+ it { should eq 0x112233445566 }
17
+ it { should_not eq 42 }
18
+ it { should_not eq 'INVALID_MAC_ADDRESS' }
46
19
  end
47
-
48
-
49
- context "with reserved address" do
50
- ( 0x0..0xf ).each do | each |
51
- octet = "%02x" % each
52
- reserved_address = "01:80:c2:00:00:#{ octet }"
53
-
54
- context "when #{ reserved_address }" do
55
- let( :value ) { reserved_address }
56
- its( :reserved? ) { should be_true }
57
- end
58
- end
20
+ describe '#eql?' do
21
+ it { expect(subject).to eql Pio::Mac.new('11:22:33:44:55:66') }
22
+ it { expect(subject).to eql '11:22:33:44:55:66' }
23
+ it { expect(subject).not_to eql Pio::Mac.new('66:55:44:33:22:11') }
24
+ it { expect(subject).not_to eql '66:55:44:33:22:11' }
25
+ it { expect(subject).to eql 0x112233445566 }
26
+ it { expect(subject).not_to eql 42 }
27
+ it { expect(subject).not_to eql 'INVALID_MAC_ADDRESS' }
59
28
  end
60
29
 
30
+ its(:hash) { should eq Pio::Mac.new('11:22:33:44:55:66').hash }
61
31
 
62
- context "with 0" do
63
- let( :value ) { 0 }
64
-
65
- it { should eq Mac.new( 0 ) }
66
- its( :to_i ) { should eq 0 }
67
- its( :to_a ) { should eq [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] }
68
- its( :to_s ) { should eq "00:00:00:00:00:00" }
69
- its( :multicast? ){ should be_false }
70
- its( :broadcast? ){ should be_false }
71
- its( :reserved? ){ should be_false }
32
+ its(:to_i) { should eq 0x112233445566 }
33
+ its(:to_a) { should eq [0x11, 0x22, 0x33, 0x44, 0x55, 0x66] }
34
+ its(:to_s) { should eq '11:22:33:44:55:66' }
35
+ describe '#to_str' do
36
+ context 'when "MAC = " + subject' do
37
+ it { expect('MAC = ' + subject).to eq 'MAC = 11:22:33:44:55:66' }
38
+ end
72
39
  end
73
40
 
41
+ its(:multicast?) { should be_true }
42
+ its(:broadcast?) { should be_false }
43
+ its(:reserved?) { should be_false }
44
+ end
74
45
 
75
- context "with 0xffffffffffff" do
76
- let( :value ) { 0xffffffffffff }
46
+ context 'with reserved address' do
47
+ (0x0..0xf).each do | each |
48
+ octet = sprintf('%02x', each)
49
+ reserved_address = "01:80:c2:00:00:#{ octet }"
77
50
 
78
- it { should eq Mac.new( 0xffffffffffff ) }
79
- its( :to_i ) { should eq 0xffffffffffff }
80
- its( :to_a ) { should eq [ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ] }
81
- its( :to_s ) { should eq "ff:ff:ff:ff:ff:ff" }
82
- its( :multicast? ){ should be_true }
83
- its( :broadcast? ){ should be_true }
84
- its( :reserved? ){ should be_false }
51
+ context "when #{ reserved_address }" do
52
+ let(:value) { reserved_address }
53
+ its(:reserved?) { should be_true }
54
+ end
85
55
  end
56
+ end
86
57
 
58
+ context 'with 0' do
59
+ let(:value) { 0 }
87
60
 
88
- context %{with "INVALID MAC ADDRESS"} do
89
- let( :value ) { "INVALID MAC ADDRESS" }
61
+ it { should eq Pio::Mac.new(0) }
62
+ its(:to_i) { should eq 0 }
63
+ its(:to_a) { should eq [0x00, 0x00, 0x00, 0x00, 0x00, 0x00] }
64
+ its(:to_s) { should eq '00:00:00:00:00:00' }
65
+ its(:multicast?) { should be_false }
66
+ its(:broadcast?) { should be_false }
67
+ its(:reserved?) { should be_false }
68
+ end
90
69
 
91
- it { expect { subject }.to raise_error( Mac::InvalidValueError ) }
92
- end
70
+ context 'with 0xffffffffffff' do
71
+ let(:value) { 0xffffffffffff }
93
72
 
73
+ it { should eq Pio::Mac.new(0xffffffffffff) }
74
+ its(:to_i) { should eq 0xffffffffffff }
75
+ its(:to_a) { should eq [0xff, 0xff, 0xff, 0xff, 0xff, 0xff] }
76
+ its(:to_s) { should eq 'ff:ff:ff:ff:ff:ff' }
77
+ its(:multicast?) { should be_true }
78
+ its(:broadcast?) { should be_true }
79
+ its(:reserved?) { should be_false }
80
+ end
94
81
 
95
- context "with -1" do
96
- let( :value ) { -1 }
82
+ context 'with "INVALID MAC ADDRESS"' do
83
+ let(:value) { 'INVALID MAC ADDRESS' }
97
84
 
98
- it { expect { subject }.to raise_error( Mac::InvalidValueError ) }
99
- end
85
+ it { expect { subject }.to raise_error(Pio::Mac::InvalidValueError) }
86
+ end
100
87
 
88
+ context 'with -1' do
89
+ let(:value) { -1 }
101
90
 
102
- context "with 0x1000000000000" do
103
- let( :value ) { 0x1000000000000 }
91
+ it { expect { subject }.to raise_error(Pio::Mac::InvalidValueError) }
92
+ end
104
93
 
105
- it { expect { subject }.to raise_error( Mac::InvalidValueError ) }
106
- end
94
+ context 'with 0x1000000000000' do
95
+ let(:value) { 0x1000000000000 }
107
96
 
97
+ it { expect { subject }.to raise_error(Pio::Mac::InvalidValueError) }
98
+ end
108
99
 
109
- context "with [ 1, 2, 3 ]" do
110
- let( :value ) { [ 1, 2, 3 ] }
100
+ context 'with [ 1, 2, 3 ]' do
101
+ let(:value) { [1, 2, 3] }
111
102
 
112
- it { expect { subject }.to raise_error( Mac::InvalidValueError ) }
113
- end
103
+ it { expect { subject }.to raise_error(Pio::Mac::InvalidValueError) }
114
104
  end
115
105
  end
116
106
  end
117
107
 
118
-
119
108
  ### Local variables:
120
109
  ### mode: Ruby
121
110
  ### coding: utf-8-unix
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,13 @@
1
- $LOAD_PATH.unshift File.join( File.dirname( __FILE__ ), "..", "lib" )
1
+ # -*- coding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
2
3
 
3
- require "rubygems"
4
+ require 'rubygems'
4
5
 
5
- require "simplecov"
6
+ require 'simplecov'
6
7
  SimpleCov.start
7
8
 
8
- require "rspec"
9
- require "rspec/autorun"
10
-
9
+ require 'rspec'
10
+ require 'rspec/autorun'
11
11
 
12
12
  RSpec.configure do | config |
13
13
  config.expect_with :rspec do | c |
@@ -15,20 +15,17 @@ RSpec.configure do | config |
15
15
  end
16
16
  end
17
17
 
18
-
19
18
  # Requires supporting files with custom matchers and macros, etc,
20
19
  # in ./support/ and its subdirectories.
21
- Dir[ "#{ File.dirname( __FILE__ ) }/support/**/*.rb" ].each do | each |
22
- require File.expand_path( each )
20
+ Dir[ "#{ File.dirname(__FILE__) }/support/**/*.rb"].each do | each |
21
+ require File.expand_path(each)
23
22
  end
24
23
 
25
-
26
- if ENV[ "TRAVIS" ]
27
- require "coveralls"
24
+ if ENV['TRAVIS']
25
+ require 'coveralls'
28
26
  Coveralls.wear!
29
27
  end
30
28
 
31
-
32
29
  ### Local variables:
33
30
  ### mode: Ruby
34
31
  ### coding: utf-8-unix
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.2.7
4
+ version: 0.3.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: 2013-11-11 00:00:00.000000000 Z
11
+ date: 2013-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata
@@ -34,7 +34,9 @@ extra_rdoc_files:
34
34
  files:
35
35
  - .gitignore
36
36
  - .rspec
37
+ - .rubocop.yml
37
38
  - .travis.yml
39
+ - CONTRIBUTING.md
38
40
  - Gemfile
39
41
  - Guardfile
40
42
  - LICENSE
@@ -46,6 +48,11 @@ files:
46
48
  - lib/pio/arp/message.rb
47
49
  - lib/pio/arp/reply.rb
48
50
  - lib/pio/arp/request.rb
51
+ - lib/pio/icmp.rb
52
+ - lib/pio/icmp/frame.rb
53
+ - lib/pio/icmp/message.rb
54
+ - lib/pio/icmp/reply.rb
55
+ - lib/pio/icmp/request.rb
49
56
  - lib/pio/ipv4_address.rb
50
57
  - lib/pio/lldp.rb
51
58
  - lib/pio/lldp/chassis_id_tlv.rb
@@ -61,16 +68,24 @@ files:
61
68
  - lib/pio/lldp/system_name_value.rb
62
69
  - lib/pio/lldp/ttl_tlv.rb
63
70
  - lib/pio/mac.rb
71
+ - lib/pio/message_util.rb
72
+ - lib/pio/type/config.reek
64
73
  - lib/pio/type/ethernet_header.rb
65
74
  - lib/pio/type/ip_address.rb
75
+ - lib/pio/type/ipv4_header.rb
66
76
  - lib/pio/type/mac_address.rb
77
+ - lib/pio/util.rb
67
78
  - lib/pio/version.rb
68
79
  - pio.gemspec
69
80
  - pio.org
70
81
  - pio.org_archive
82
+ - rubocop-todo.yml
71
83
  - spec/pio/arp/reply_spec.rb
72
84
  - spec/pio/arp/request_spec.rb
73
85
  - spec/pio/arp_spec.rb
86
+ - spec/pio/icmp/reply_spec.rb
87
+ - spec/pio/icmp/request_spec.rb
88
+ - spec/pio/icmp_spec.rb
74
89
  - spec/pio/ipv4_address_spec.rb
75
90
  - spec/pio/lldp_spec.rb
76
91
  - spec/pio/mac_spec.rb
@@ -103,6 +118,9 @@ test_files:
103
118
  - spec/pio/arp/reply_spec.rb
104
119
  - spec/pio/arp/request_spec.rb
105
120
  - spec/pio/arp_spec.rb
121
+ - spec/pio/icmp/reply_spec.rb
122
+ - spec/pio/icmp/request_spec.rb
123
+ - spec/pio/icmp_spec.rb
106
124
  - spec/pio/ipv4_address_spec.rb
107
125
  - spec/pio/lldp_spec.rb
108
126
  - spec/pio/mac_spec.rb