pio 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.rspec +1 -0
  4. data/lib/pio/arp/frame.rb +3 -3
  5. data/lib/pio/arp/message.rb +5 -4
  6. data/lib/pio/arp/reply.rb +0 -1
  7. data/lib/pio/arp/request.rb +2 -3
  8. data/lib/pio/ipv4_address.rb +149 -0
  9. data/lib/pio/lldp.rb +2 -2
  10. data/lib/pio/lldp/{chassis-id-tlv.rb → chassis_id_tlv.rb} +0 -0
  11. data/lib/pio/lldp/{end-of-lldpdu-value.rb → end_of_lldpdu_value.rb} +0 -0
  12. data/lib/pio/lldp/frame.rb +5 -5
  13. data/lib/pio/lldp/{management-address-value.rb → management_address_value.rb} +0 -0
  14. data/lib/pio/lldp/{optional-tlv.rb → optional_tlv.rb} +7 -7
  15. data/lib/pio/lldp/{organizationally-specific-value.rb → organizationally_specific_value.rb} +0 -0
  16. data/lib/pio/lldp/{port-description-value.rb → port_description_value.rb} +0 -0
  17. data/lib/pio/lldp/{port-id-tlv.rb → port_id_tlv.rb} +0 -0
  18. data/lib/pio/lldp/{system-capabilities-value.rb → system_capabilities_value.rb} +0 -0
  19. data/lib/pio/lldp/{system-description-value.rb → system_description_value.rb} +0 -0
  20. data/lib/pio/lldp/{system-name-value.rb → system_name_value.rb} +0 -0
  21. data/lib/pio/lldp/{ttl-tlv.rb → ttl_tlv.rb} +0 -0
  22. data/lib/pio/mac.rb +4 -4
  23. data/lib/pio/type/{ethernet-header.rb → ethernet_header.rb} +1 -1
  24. data/lib/pio/type/{ip-address.rb → ip_address.rb} +2 -1
  25. data/lib/pio/type/{mac-address.rb → mac_address.rb} +0 -0
  26. data/lib/pio/version.rb +1 -1
  27. data/pio.org +69 -445
  28. data/pio.org_archive +451 -0
  29. data/spec/pio/arp/reply_spec.rb +4 -5
  30. data/spec/pio/arp/request_spec.rb +5 -6
  31. data/spec/pio/arp_spec.rb +0 -1
  32. data/spec/pio/ipv4_address_spec.rb +99 -0
  33. data/spec/pio/lldp_spec.rb +0 -1
  34. data/spec/pio/mac_spec.rb +3 -4
  35. metadata +19 -19
  36. data/lib/pio/ip.rb +0 -90
  37. data/spec/pio/ip_spec.rb +0 -38
@@ -1,4 +1,3 @@
1
- require File.join( File.dirname( __FILE__ ), "..", "..", "spec_helper" )
2
1
  require "pio/arp/reply"
3
2
 
4
3
 
@@ -121,8 +120,8 @@ module Pio
121
120
  let( :sender_protocol_address ) { nil }
122
121
  let( :target_protocol_address ) { "192.168.83.254" }
123
122
 
124
- it "raises an invalid IP address error" do
125
- expect { subject }.to raise_error( "Invalid IP address: nil" )
123
+ it "raises an invalid IPv4 address error" do
124
+ expect { subject }.to raise_error( "Invalid IPv4 address: nil" )
126
125
  end
127
126
  end
128
127
 
@@ -133,8 +132,8 @@ module Pio
133
132
  let( :sender_protocol_address ) { "192.168.83.3" }
134
133
  let( :target_protocol_address ) { nil }
135
134
 
136
- it "raises an invalid IP address error" do
137
- expect { subject }.to raise_error( "Invalid IP address: nil" )
135
+ it "raises an invalid IPv4 address error" do
136
+ expect { subject }.to raise_error( "Invalid IPv4 address: nil" )
138
137
  end
139
138
  end
140
139
  end
@@ -1,4 +1,3 @@
1
- require File.join( File.dirname( __FILE__ ), "..", "..", "spec_helper" )
2
1
  require "pio/arp/request"
3
2
 
4
3
 
@@ -103,8 +102,8 @@ module Pio
103
102
  let( :sender_protocol_address ) { nil }
104
103
  let( :target_protocol_address ) { "192.168.83.254" }
105
104
 
106
- it "raises an invalid IP address error" do
107
- expect { subject }.to raise_error( "Invalid IP address: nil" )
105
+ it "raises an invalid IPv4 address error" do
106
+ expect { subject }.to raise_error( "Invalid IPv4 address: nil" )
108
107
  end
109
108
  end
110
109
 
@@ -113,9 +112,9 @@ module Pio
113
112
  let( :source_mac ) { 0x002682ebead1 }
114
113
  let( :sender_protocol_address ) { "192.168.83.254" }
115
114
  let( :target_protocol_address ) { nil }
116
-
117
- it "raises an invalid IP address error" do
118
- expect { subject }.to raise_error( "Invalid IP address: nil" )
115
+
116
+ it "raises an invalid IPv4 address error" do
117
+ expect { subject }.to raise_error( "Invalid IPv4 address: nil" )
119
118
  end
120
119
  end
121
120
  end
data/spec/pio/arp_spec.rb CHANGED
@@ -1,4 +1,3 @@
1
- require File.join( File.dirname( __FILE__ ), "..", "spec_helper" )
2
1
  require "pio"
3
2
 
4
3
 
@@ -0,0 +1,99 @@
1
+ require "pio/ipv4_address"
2
+
3
+
4
+ module Pio
5
+ describe IPv4Address do
6
+ context ".new" do
7
+ subject( :ipv4 ) { IPv4Address.new( ip_address ) }
8
+
9
+
10
+ context "with 10.1.1.1" do
11
+ let( :ip_address ) { "10.1.1.1" }
12
+
13
+ its( :to_s ) { should eq "10.1.1.1" }
14
+ its( :to_i ) { should eq ( ( 10 * 256 + 1 ) * 256 + 1 ) * 256 + 1 }
15
+ its( :to_ary ) { should eq [ 0x0a, 0x01, 0x01, 0x01 ] }
16
+ its( :class_a? ) { should be_true }
17
+ its( :class_b? ) { should be_false }
18
+ its( :class_c? ) { should be_false }
19
+ its( :class_d? ) { should be_false }
20
+ its( :class_e? ) { should be_false }
21
+ its( :unicast? ) { should be_true }
22
+ its( :multicast? ) { should be_false }
23
+
24
+
25
+ context ".mask!" do
26
+ subject { ipv4.mask!( mask ) }
27
+
28
+ let( :mask ) { 8 }
29
+
30
+ its( :to_s ) { should eq "10.0.0.0" }
31
+ its( :to_i ) { should eq 10 * 256 * 256 * 256 }
32
+ its( :to_ary ) { should eq [ 0x0a, 0x00, 0x00, 0x00 ] }
33
+ its( :class_a? ) { should be_true }
34
+ its( :class_b? ) { should be_false }
35
+ its( :class_c? ) { should be_false }
36
+ its( :class_d? ) { should be_false }
37
+ its( :class_e? ) { should be_false }
38
+ its( :unicast? ) { should be_true }
39
+ its( :multicast? ) { should be_false }
40
+ end
41
+ end
42
+
43
+
44
+ context "with 172.20.1.1" do
45
+ let( :ip_address ) { "172.20.1.1" }
46
+
47
+ its( :to_s ) { should eq "172.20.1.1" }
48
+ its( :to_i ) { should eq ( ( 172 * 256 + 20 ) * 256 + 1 ) * 256 + 1 }
49
+ its( :to_ary ) { should eq [ 0xac, 0x14, 0x01, 0x01 ] }
50
+ its( :class_a? ) { should be_false }
51
+ its( :class_b? ) { should be_true }
52
+ its( :class_c? ) { should be_false }
53
+ its( :class_d? ) { should be_false }
54
+ its( :class_e? ) { should be_false }
55
+ its( :unicast? ) { should be_true }
56
+ its( :multicast? ) { should be_false }
57
+ end
58
+
59
+
60
+ context "with 192.168.1.1" do
61
+ let( :ip_address ) { "192.168.1.1" }
62
+
63
+ its( :to_s ) { should eq "192.168.1.1" }
64
+ its( :to_i ) { should eq 3232235777 }
65
+ its( :to_ary ) { should eq [ 0xc0, 0xa8, 0x01, 0x01 ] }
66
+ its( :class_a? ) { should be_false }
67
+ its( :class_b? ) { should be_false }
68
+ its( :class_c? ) { should be_true }
69
+ its( :class_d? ) { should be_false }
70
+ its( :class_e? ) { should be_false }
71
+ its( :unicast? ) { should be_true }
72
+ its( :multicast? ) { should be_false }
73
+ end
74
+
75
+
76
+ context "with 234.1.1.1" do
77
+ let( :ip_address ) { "234.1.1.1" }
78
+
79
+ its( :to_s ) { should eq "234.1.1.1" }
80
+ its( :to_i ) { should eq ( ( 234 * 256 + 1 ) * 256 + 1 ) * 256 + 1 }
81
+ its( :to_ary ) { should eq [ 0xea, 0x01, 0x01, 0x01 ] }
82
+ its( :class_a? ) { should be_false }
83
+ its( :class_b? ) { should be_false }
84
+ its( :class_c? ) { should be_false }
85
+ its( :class_d? ) { should be_true }
86
+ its( :class_e? ) { should be_false }
87
+ its( :unicast? ) { should be_false }
88
+ its( :multicast? ) { should be_true }
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+
95
+ ### Local variables:
96
+ ### mode: Ruby
97
+ ### coding: utf-8-unix
98
+ ### indent-tabs-mode: nil
99
+ ### End:
@@ -1,4 +1,3 @@
1
- require File.join( File.dirname( __FILE__ ), "..", "spec_helper" )
2
1
  require "pio"
3
2
 
4
3
 
data/spec/pio/mac_spec.rb CHANGED
@@ -1,4 +1,3 @@
1
- require File.join( File.dirname( __FILE__ ), "..", "spec_helper" )
2
1
  require "pio/mac"
3
2
 
4
3
 
@@ -13,7 +12,7 @@ module Pio
13
12
  it { should eq Mac.new( "11:22:33:44:55:66" ) }
14
13
  its( :value ) { should eq 0x112233445566 }
15
14
  its( :to_s ) { should eq "11:22:33:44:55:66" }
16
- its( :to_a ) { should eq [ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 ] }
15
+ its( :to_ary ) { should eq [ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 ] }
17
16
  its( :multicast? ){ should be_true }
18
17
  its( :broadcast? ){ should be_false }
19
18
  end
@@ -24,7 +23,7 @@ module Pio
24
23
  it { should eq Mac.new( 0 ) }
25
24
  its( :value ) { should eq 0 }
26
25
  its( :to_s ) { should eq "00:00:00:00:00:00" }
27
- its( :to_a ) { should eq [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] }
26
+ its( :to_ary ) { should eq [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] }
28
27
  its( :multicast? ){ should be_false }
29
28
  its( :broadcast? ){ should be_false }
30
29
  end
@@ -35,7 +34,7 @@ module Pio
35
34
  it { should eq Mac.new( 0xffffffffffff ) }
36
35
  its( :value ) { should eq 0xffffffffffff }
37
36
  its( :to_s ) { should eq "ff:ff:ff:ff:ff:ff" }
38
- its( :to_a ) { should eq [ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ] }
37
+ its( :to_ary ) { should eq [ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ] }
39
38
  its( :multicast? ){ should be_true }
40
39
  its( :broadcast? ){ should be_true }
41
40
  end
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.1
4
+ version: 0.2.2
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-09-19 00:00:00.000000000 Z
11
+ date: 2013-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata
@@ -46,24 +46,24 @@ files:
46
46
  - lib/pio/arp/message.rb
47
47
  - lib/pio/arp/reply.rb
48
48
  - lib/pio/arp/request.rb
49
- - lib/pio/ip.rb
49
+ - lib/pio/ipv4_address.rb
50
50
  - lib/pio/lldp.rb
51
- - lib/pio/lldp/chassis-id-tlv.rb
52
- - lib/pio/lldp/end-of-lldpdu-value.rb
51
+ - lib/pio/lldp/chassis_id_tlv.rb
52
+ - lib/pio/lldp/end_of_lldpdu_value.rb
53
53
  - lib/pio/lldp/frame.rb
54
- - lib/pio/lldp/management-address-value.rb
55
- - lib/pio/lldp/optional-tlv.rb
56
- - lib/pio/lldp/organizationally-specific-value.rb
57
- - lib/pio/lldp/port-description-value.rb
58
- - lib/pio/lldp/port-id-tlv.rb
59
- - lib/pio/lldp/system-capabilities-value.rb
60
- - lib/pio/lldp/system-description-value.rb
61
- - lib/pio/lldp/system-name-value.rb
62
- - lib/pio/lldp/ttl-tlv.rb
54
+ - lib/pio/lldp/management_address_value.rb
55
+ - lib/pio/lldp/optional_tlv.rb
56
+ - lib/pio/lldp/organizationally_specific_value.rb
57
+ - lib/pio/lldp/port_description_value.rb
58
+ - lib/pio/lldp/port_id_tlv.rb
59
+ - lib/pio/lldp/system_capabilities_value.rb
60
+ - lib/pio/lldp/system_description_value.rb
61
+ - lib/pio/lldp/system_name_value.rb
62
+ - lib/pio/lldp/ttl_tlv.rb
63
63
  - lib/pio/mac.rb
64
- - lib/pio/type/ethernet-header.rb
65
- - lib/pio/type/ip-address.rb
66
- - lib/pio/type/mac-address.rb
64
+ - lib/pio/type/ethernet_header.rb
65
+ - lib/pio/type/ip_address.rb
66
+ - lib/pio/type/mac_address.rb
67
67
  - lib/pio/version.rb
68
68
  - pio.gemspec
69
69
  - pio.org
@@ -71,7 +71,7 @@ files:
71
71
  - spec/pio/arp/reply_spec.rb
72
72
  - spec/pio/arp/request_spec.rb
73
73
  - spec/pio/arp_spec.rb
74
- - spec/pio/ip_spec.rb
74
+ - spec/pio/ipv4_address_spec.rb
75
75
  - spec/pio/lldp_spec.rb
76
76
  - spec/pio/mac_spec.rb
77
77
  - spec/spec_helper.rb
@@ -103,7 +103,7 @@ test_files:
103
103
  - spec/pio/arp/reply_spec.rb
104
104
  - spec/pio/arp/request_spec.rb
105
105
  - spec/pio/arp_spec.rb
106
- - spec/pio/ip_spec.rb
106
+ - spec/pio/ipv4_address_spec.rb
107
107
  - spec/pio/lldp_spec.rb
108
108
  - spec/pio/mac_spec.rb
109
109
  - spec/spec_helper.rb
data/lib/pio/ip.rb DELETED
@@ -1,90 +0,0 @@
1
- module Pio
2
- #
3
- # A wrapper class to IPAddr
4
- #
5
- class IP
6
- require "ipaddr"
7
-
8
-
9
- #
10
- # @return [IPAddr] value object instance of proxied IPAddr.
11
- #
12
- attr_reader :value
13
-
14
-
15
- attr_reader :prefixlen
16
-
17
-
18
- #
19
- # Creates a {IP} instance object as a proxy to IPAddr class.
20
- #
21
- # @overload initialize(addr)
22
- #
23
- # @param [String, Number] addr
24
- # an IPv4 address specified either as a String or Number.
25
- #
26
- # @param [Number] prefixlen
27
- # masking IPv4 address with given prefixlen.
28
- #
29
- # @raise [ArgumentError] invalid address if supplied argument is invalid
30
- # IPv4 address.
31
- #
32
- # @return [IP] self
33
- # a proxy to IPAddr.
34
- #
35
- def initialize addr, prefixlen = 32
36
- @prefixlen = prefixlen
37
- case addr
38
- when Integer
39
- @value = IPAddr.new( addr, Socket::AF_INET )
40
- when String
41
- @value = IPAddr.new( addr )
42
- else
43
- raise TypeError, "Invalid IP address: #{ addr.inspect }"
44
- end
45
- if prefixlen < 32
46
- @value = @value.mask( prefixlen )
47
- end
48
- end
49
-
50
-
51
- #
52
- # @return [String] the IPv4 address in its text representation.
53
- #
54
- def to_s
55
- @value.to_s
56
- end
57
-
58
-
59
- #
60
- # @return [Number] the IPv4 address in its numeric representation.
61
- #
62
- def to_i
63
- @value.to_i
64
- end
65
-
66
-
67
- def == other
68
- to_s == other.to_s
69
- end
70
-
71
-
72
- #
73
- # @return [Array]
74
- # an array of decimal numbers converted from IP address.
75
- #
76
- def to_a
77
- to_s.split( "." ).collect do | each |
78
- each.to_i
79
- end
80
- end
81
- alias :to_array :to_a
82
- end
83
- end
84
-
85
-
86
- ### Local variables:
87
- ### mode: Ruby
88
- ### coding: utf-8-unix
89
- ### indent-tabs-mode: nil
90
- ### End:
data/spec/pio/ip_spec.rb DELETED
@@ -1,38 +0,0 @@
1
- require File.join( File.dirname( __FILE__ ), "..", "spec_helper" )
2
- require "pio/ip"
3
-
4
-
5
- module Pio
6
- describe IP do
7
- context ".new" do
8
- subject { IP.new( ip_address, prefixlen ) }
9
-
10
-
11
- context %{with "192.168.1.1", 32} do
12
- let( :ip_address ) { "192.168.1.1" }
13
- let( :prefixlen ) { 32 }
14
-
15
- its( :to_s ) { should eq "192.168.1.1" }
16
- its( :to_i ) { should eq 3232235777 }
17
- its( :to_a ) { should eq [ 0xc0, 0xa8, 0x01, 0x01 ] }
18
- end
19
-
20
-
21
- context %{with "10.1.1.1", 8} do
22
- let( :ip_address ) { "10.1.1.1" }
23
- let( :prefixlen ) { 8 }
24
-
25
- its( :to_s ) { should eq "10.0.0.0" }
26
- its( :to_i ) { should eq 10 * 256 * 256 * 256 }
27
- its( :to_a ) { should eq [ 0x0a, 0x00, 0x00, 0x00 ] }
28
- end
29
- end
30
- end
31
- end
32
-
33
-
34
- ### Local variables:
35
- ### mode: Ruby
36
- ### coding: utf-8-unix
37
- ### indent-tabs-mode: nil
38
- ### End: