pio 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b1a7685cf52cf2c1130a376ecbb0deb4d3bab6f
4
- data.tar.gz: dedeebabbd435531e5937344abd6c774e781b45b
3
+ metadata.gz: b195270747468aaa2b80432c46510f55f1454f48
4
+ data.tar.gz: 2a2ee7694241f4b47f7c55fa29c1fb749a0ef448
5
5
  SHA512:
6
- metadata.gz: e3ec7121d3566f35e7c1b282019fbd38325c4c9910739a29e3407f2c5d58916f8d07306b3a8cf3fe65315c3c68c6a3aebc702a8e9866bf6a589434fdb338a3e6
7
- data.tar.gz: 3844655945ad07e364deab3923dfeb702b96db4c2398e7a9511fbbf4592c381e10143dba62ee4d2cc7d098cb16e0c8ff260c02dbd433409a9d966dc1db96e1f8
6
+ metadata.gz: dfcc2a3f9db6f8e70ea6212883ce08dbfb3a274ed85ab71cc39383cb7a6be32bc2da936b658b80e89618b9788b37f3028c0b7859d455d3f32b672bafaa82f932
7
+ data.tar.gz: 8e87ff8d652dc724a1f64de6bcc65655ed732f60a0ea700e2e63e5a72aa8498192c1d40bf0972d3b13932ef622535bf38fecf3f5b1dc95c18fac12b9e6f1feee
@@ -78,13 +78,22 @@ module Pio
78
78
  # @return [Array]
79
79
  # an array of decimal numbers converted from IPv4 address.
80
80
  #
81
- def to_ary
81
+ def to_a
82
82
  to_s.split( "." ).collect do | each |
83
83
  each.to_i
84
84
  end
85
85
  end
86
86
 
87
87
 
88
+ #
89
+ # @return [Array]
90
+ # an array of decimal numbers converted from IPv4 address.
91
+ #
92
+ def to_ary
93
+ to_a
94
+ end
95
+
96
+
88
97
  #
89
98
  # @return [IPv4Address]
90
99
  # Returns the IPv4 address masked with masklen.
data/lib/pio/lldp.rb CHANGED
@@ -21,8 +21,8 @@ module Pio
21
21
 
22
22
  def to_hash
23
23
  {
24
- :destination_mac => Mac.new( destination_mac ).to_ary,
25
- :source_mac => Mac.new( source_mac ).to_ary,
24
+ :destination_mac => Mac.new( destination_mac ).to_a,
25
+ :source_mac => Mac.new( source_mac ).to_a,
26
26
  :chassis_id => dpid,
27
27
  :port_id => port_id
28
28
  }
@@ -64,6 +64,7 @@ module Pio
64
64
  rescue
65
65
  raise Pio::ParseError, $!.message
66
66
  end
67
+
67
68
  lldp = allocate
68
69
  lldp.instance_variable_set :@frame, frame
69
70
  lldp
data/lib/pio/mac.rb CHANGED
@@ -11,46 +11,45 @@ module Pio
11
11
 
12
12
 
13
13
  #
14
- # Returns an Ethernet address in its numeric presentation.
14
+ # Creates a {Mac} instance that encapsulates Ethernet addresses.
15
15
  #
16
- # @example
17
- # Mac.new("11:22:33:44:55:66") #=> 18838586676582
16
+ # @example address as a hexadecimal string
17
+ # Mac.new("11:22:33:44:55:66")
18
18
  #
19
- # @return [Number] the Ethernet address in numeric format
19
+ # @example address as a hexadecimal number
20
+ # Mac.new(0xffffffffffff)
20
21
  #
21
- attr_reader :value
22
+ def initialize value
23
+ if value.respond_to?( :to_str )
24
+ @value = parse_mac_string( value.to_str )
25
+ elsif value.respond_to?( :to_int )
26
+ @value = value.to_int
27
+ validate_value_range
28
+ else
29
+ raise TypeError, "Invalid MAC address: #{ value.inspect }"
30
+ end
31
+ end
22
32
 
23
33
 
24
34
  #
25
- # Creates a {Mac} instance that encapsulates Ethernet addresses.
26
- #
27
- # @overload initialize(value)
35
+ # Returns an Ethernet address in its numeric presentation.
28
36
  #
29
- # @param [String,Integer] value
30
- # the Ethernet address to set to.
37
+ # @example
38
+ # Mac.new("11:22:33:44:55:66").to_i #=> 18838586676582
31
39
  #
32
- # @example address as a hexadecimal string
33
- # Mac.new("11:22:33:44:55:66")
40
+ def to_i
41
+ @value
42
+ end
43
+
44
+
34
45
  #
35
- # @example address as a hexadecimal number
36
- # Mac.new(0xffffffffffff)
46
+ # @see to_i
37
47
  #
38
- # @raise [ArgumentError] if invalid format is detected.
39
- # @raise [TypeError] if supplied argument is not a String or Integer.
48
+ # @example
49
+ # Mac.new("11:22:33:44:55:66").to_int #=> 18838586676582
40
50
  #
41
- def initialize value
42
- case value
43
- when String
44
- @value = create_from( value )
45
- when Integer
46
- @value = value
47
- validate_value_range
48
- when Mac
49
- @value = create_from( value.to_s )
50
- else
51
- raise TypeError, "Invalid MAC address: #{ value.inspect }"
52
- end
53
- @string = string_format
51
+ def to_int
52
+ to_i
54
53
  end
55
54
 
56
55
 
@@ -61,10 +60,19 @@ module Pio
61
60
  # @example
62
61
  # Mac.new(18838586676582).to_s #=> "11:22:33:44:55:66"
63
62
  #
64
- # @return [String] the Ethernet address in String format
65
- #
66
63
  def to_s
67
- @string
64
+ sprintf( "%012x", @value ).unpack( "a2" * 6 ).join( ":" )
65
+ end
66
+
67
+
68
+ #
69
+ # @see to_s
70
+ #
71
+ # @example
72
+ # Mac.new(18838586676582).to_str #=> "11:22:33:44:55:66"
73
+ #
74
+ def to_str
75
+ to_s
68
76
  end
69
77
 
70
78
 
@@ -73,22 +81,35 @@ module Pio
73
81
  # address string format.
74
82
  #
75
83
  # @example
76
- # Mac.new("11:22:33:44:55:66").to_ary #=> [ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 ]
77
- #
78
- # @return [Array] the Ethernet address in Array format
84
+ # Mac.new("11:22:33:44:55:66").to_a #=> [ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 ]
79
85
  #
80
- def to_ary
81
- @string.split( ":" ).collect do | each |
86
+ def to_a
87
+ to_s.split( ":" ).collect do | each |
82
88
  each.hex
83
89
  end
84
90
  end
85
91
 
86
92
 
93
+ #
94
+ # @see to_a
95
+ #
96
+ # @example
97
+ # Mac.new("11:22:33:44:55:66").to_ary #=> [ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 ]
98
+ #
99
+ def to_ary
100
+ to_a
101
+ end
102
+
103
+
87
104
  #
88
105
  # @private
89
106
  #
90
107
  def == other
91
- to_s == other.to_s
108
+ begin
109
+ to_i == Mac.new( other ).to_i
110
+ rescue
111
+ false
112
+ end
92
113
  end
93
114
  alias :eql? :==
94
115
 
@@ -100,10 +121,8 @@ module Pio
100
121
  # Mac.new("01:00:00:00:00:00").multicast? #=> true
101
122
  # Mac.new("00:00:00:00:00:00").multicast? #=> false
102
123
  #
103
- # @return [Boolean] whether the Ethernet address is multicast
104
- #
105
124
  def multicast?
106
- to_ary[ 0 ] & 1 == 1
125
+ to_a[ 0 ] & 1 == 1
107
126
  end
108
127
 
109
128
 
@@ -113,10 +132,8 @@ module Pio
113
132
  # @example
114
133
  # Mac.new("ff:ff:ff:ff:ff:ff").broadcast? #=> true
115
134
  #
116
- # @return [Boolean] whether the Ethernet address is broadcast
117
- #
118
135
  def broadcast?
119
- to_ary.all? { | each | each == 0xff }
136
+ to_a.all? { | each | each == 0xff }
120
137
  end
121
138
 
122
139
 
@@ -125,12 +142,12 @@ module Pio
125
142
  ################################################################################
126
143
 
127
144
 
128
- def create_from string
145
+ def parse_mac_string mac
129
146
  octet_regex = "[0-9a-fA-F][0-9a-fA-F]"
130
- if /^(#{ octet_regex }:){5}(#{ octet_regex })$/=~ string
131
- string.gsub( ":", "" ).hex
147
+ if /^(#{ octet_regex }:){5}(#{ octet_regex })$/=~ mac
148
+ mac.gsub( ":", "" ).hex
132
149
  else
133
- raise ArgumentError, %{Invalid MAC address: "#{ string }"}
150
+ raise ArgumentError, %{Invalid MAC address: "#{ mac }"}
134
151
  end
135
152
  end
136
153
 
@@ -140,11 +157,6 @@ module Pio
140
157
  raise ArgumentError, "Invalid MAC address: #{ @value }"
141
158
  end
142
159
  end
143
-
144
-
145
- def string_format
146
- sprintf( "%012x", @value ).unpack( "a2" * 6 ).join( ":" )
147
- end
148
160
  end
149
161
  end
150
162
 
data/lib/pio/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # Base module.
2
2
  module Pio
3
3
  # gem version.
4
- VERSION = "0.2.4"
4
+ VERSION = "0.2.5"
5
5
  end
6
6
 
7
7
 
data/pio.org CHANGED
@@ -36,6 +36,20 @@ http://www.zeespencer.com/articles/building-a-remote-pairing-setup/
36
36
  [2013-09-22 日 23:09]
37
37
 
38
38
  http:///www.asahi-net.or.jp/~aa4t-nngk/ipttut/output/icmpheaders.html
39
+ ** [[http://www.ruby-forum.com/topic/217963][any good tools for reading networking data with optional TLV - Ruby Forum]] [2013-06-21 Fri]
40
+ :PROPERTIES:
41
+ :ID: 1670C09A-20C7-45F9-B068-56376DFD864C
42
+ :END:
43
+ BinData での optional TLV の使い方
44
+
45
+ ** Trema/Pioでパケットを作ろう(1) :NOTE:
46
+ [2013-10-06 日 15:55]
47
+
48
+ http://d.hatena.ne.jp/stereocat/20131005/1380977633
49
+ ** Trema/Pioでパケットを作ろう(2) :NOTE:
50
+ [2013-10-06 日 15:55]
51
+
52
+ http://d.hatena.ne.jp/stereocat/20131006/1381028321
39
53
  * Tasks
40
54
  このアイテムをそれぞれのリリースに割り振る。
41
55
  ** NEXT git パスワードを省略できるように
@@ -48,6 +62,18 @@ http:///www.asahi-net.or.jp/~aa4t-nngk/ipttut/output/icmpheaders.html
48
62
  [2013-09-18 水 12:01]
49
63
  ** TODO phost を Pio で書き直す
50
64
  [2013-09-24 火 15:36]
65
+ ** TODO DHCP パーサを作る
66
+ [2013-08-02 金 17:17]
67
+
68
+ 近藤さんがすでにコーディング中。Pull-Request が来たらいっしょにリファ
69
+ クタリングして取り込む予定。
70
+ ** TODO おかしな MAC アドレスはすべて InvalidMAC 例外にまとめる
71
+ :LOGBOOK:
72
+ CLOCK: [2013-10-07 月 10:22]--[2013-10-07 月 10:23] => 0:01
73
+ :END:
74
+ [2013-10-07 月 10:22]
75
+
76
+ ファイルは lib/pio/mac.rb
51
77
  * Releases
52
78
  ** DONE 0.2.2 リリース
53
79
  CLOSED: [2013-09-26 木 15:34]
@@ -85,11 +111,60 @@ CLOSED: [2013-09-26 木 15:35]
85
111
  *** DONE Trema への組込み
86
112
  CLOSED: [2013-09-26 木 15:35]
87
113
  [2013-09-26 木 15:35]
88
- ** TODO 0.2.4 リリース
114
+ *** DONE gem の命名規則に合わせる
115
+ CLOSED: [2013-09-26 木 08:28] SCHEDULED: <2013-09-26 木>
116
+ :LOGBOOK:
117
+ CLOCK: [2013-09-26 木 08:20]--[2013-09-26 木 08:28] => 0:08
118
+ CLOCK: [2013-09-26 木 08:05]--[2013-09-26 木 08:06] => 0:01
119
+ :END:
120
+ :PROPERTIES:
121
+ :Effort: 0:30
122
+ :END:
123
+ [2013-09-26 木 08:05]
124
+ *** DONE 明示的に spec_helper.rb をロードしてる部分をなくす
125
+ CLOSED: [2013-09-26 木 08:18] SCHEDULED: <2013-09-26 木>
126
+ :LOGBOOK:
127
+ CLOCK: [2013-09-26 木 08:14]--[2013-09-26 木 08:15] => 0:01
128
+ :END:
129
+ :PROPERTIES:
130
+ :Effort: 0:30
131
+ :END:
132
+ [2013-09-26 木 08:14]
133
+ ** DONE 0.2.5 リリース
134
+ CLOSED: [2013-10-10 木 15:00]
89
135
  :LOGBOOK:
90
136
  CLOCK: [2013-09-26 木 13:31]--[2013-09-26 木 13:32] => 0:01
91
137
  :END:
92
138
  [2013-09-26 木 13:31]
139
+ *** DONE Trema::Mac を Pio::Mac で置き換え
140
+ CLOSED: [2013-10-10 木 14:57] SCHEDULED: <2013-10-10 木>
141
+ :LOGBOOK:
142
+ CLOCK: [2013-10-10 木 11:38]--[2013-10-10 木 13:30] => 1:52
143
+ :END:
144
+ [2013-10-03 木 09:04]
145
+ **** DONE Trema ソースコード内の Trema::Mac を Pio::Mac で置換
146
+ CLOSED: [2013-10-10 木 13:42]
147
+ [2013-10-03 木 09:05]
148
+ **** DONE Trema::Mac のテストコードを削除
149
+ CLOSED: [2013-10-10 木 13:42]
150
+ :LOGBOOK:
151
+ CLOCK: [2013-10-03 木 09:06]--[2013-10-03 木 09:07] => 0:01
152
+ :END:
153
+ [2013-10-03 木 09:06]
154
+ **** DONE cruise.rb が通ることを確認
155
+ CLOSED: [2013-10-10 木 14:57]
156
+ [2013-10-03 木 09:08]
157
+ *** DONE Pio::Mac のYARD コメントでダブってるやつは @see にする
158
+ CLOSED: [2013-10-10 木 13:37] SCHEDULED: <2013-10-10 木>
159
+ :LOGBOOK:
160
+ CLOCK: [2013-10-10 木 13:30]--[2013-10-10 木 13:37] => 0:07
161
+ CLOCK: [2013-10-07 月 10:23]--[2013-10-07 月 10:24] => 0:01
162
+ :END:
163
+ [2013-10-07 月 10:23]
164
+
165
+ =#to_a= と =#to_ary= のコメントとか.
166
+ ** TODO 0.2.6 リリース
167
+ [2013-10-10 木 13:37]
93
168
  *** TODO 鈴木さんルータの ARP 部分を Pio で書き直してもらう
94
169
  - State "TODO" from "WAITING" [2013-09-19 木 14:18]
95
170
  - State "WAITING" from "TODO" [2013-09-18 水 12:04] \\
@@ -100,24 +175,26 @@ CLOCK: [2013-09-14 土 10:20]--[2013-09-14 土 10:21] => 0:01
100
175
  [2013-09-14 土 10:20]
101
176
 
102
177
  GitHub のチケットはこちら:
178
+ https://github.com/trema/pio/issues/1
179
+ **** NEXT 鈴木さんルータの ARP 部分を試しに自分で書き直してみる
180
+ SCHEDULED: <2013-10-04 金>
181
+ :PROPERTIES:
182
+ :Effort: 1:00
183
+ :END:
184
+ [2013-10-04 金 08:39]
185
+ **** DONE 鈴木さんに ping
186
+ CLOSED: [2013-10-01 火 12:29] SCHEDULED: <2013-10-01 火>
187
+ :LOGBOOK:
188
+ CLOCK: [2013-09-29 日 21:06]--[2013-09-29 日 21:07] => 0:01
189
+ :END:
190
+ [2013-09-29 日 21:06]
191
+
103
192
  https://github.com/trema/pio/issues/1
104
193
  ** TODO 0.3.0 リリース
105
194
  - State "TODO" from "WAITING" [2013-09-19 木 14:16]
106
195
  - State "WAITING" from "TODO" [2013-09-06 金 17:17] \\
107
196
  0.2.0 が無事に出てから
108
197
  [2013-09-05 木 17:29]
109
- *** TODO ICMP パーサを作る
110
- [2013-08-02 金 17:19]
111
- *** DONE gem の命名規則に合わせる
112
- CLOSED: [2013-09-26 木 08:28] SCHEDULED: <2013-09-26 木>
113
- :LOGBOOK:
114
- CLOCK: [2013-09-26 木 08:20]--[2013-09-26 木 08:28] => 0:08
115
- CLOCK: [2013-09-26 木 08:05]--[2013-09-26 木 08:06] => 0:01
116
- :END:
117
- :PROPERTIES:
118
- :Effort: 0:30
119
- :END:
120
- [2013-09-26 木 08:05]
121
198
  *** NEXT YARD の警告をつぶす
122
199
  SCHEDULED: <2014-08-19 火>
123
200
  :PROPERTIES:
@@ -129,21 +206,15 @@ SCHEDULED: <2014-08-19 火>
129
206
  CLOCK: [2013-09-18 水 17:20]--[2013-09-18 水 17:21] => 0:01
130
207
  :END:
131
208
  [2013-09-18 水 17:20]
132
- *** DONE 明示的に spec_helper.rb をロードしてる部分をなくす
133
- CLOSED: [2013-09-26 08:18] SCHEDULED: <2013-09-26 木>
209
+ *** TODO ICMP パーサを作る
210
+ [2013-08-02 17:19]
211
+ **** WAITING 近藤さんに PR 出してもらう :WAITING:
212
+ - State "WAITING" from "TODO" [2013-10-07 月 08:56] \\
213
+ 近藤さんが PR の準備中.
134
214
  :LOGBOOK:
135
- CLOCK: [2013-09-2608:14]--[2013-09-2608:15] => 0:01
136
- :END:
137
- :PROPERTIES:
138
- :Effort: 0:30
215
+ CLOCK: [2013-10-0309:10]--[2013-10-0309:12] => 0:02
139
216
  :END:
140
- [2013-09-2608:14]
141
- ** WAITING 0.4.0 リリース :WAITING:
142
- - State "WAITING" from "TODO" [2013-09-06 金 17:18] \\
143
- 0.3.0 が無事に出てから。
144
- [2013-09-06 金 16:30]
145
- *** TODO DHCP パーサを作る
146
- [2013-08-02 金 17:17]
217
+ [2013-10-0309:10]
147
218
 
148
- 近藤さんがすでにコーディング中。Pull-Request が来たらいっしょにリファ
149
- クタリングして取り込む予定。
219
+ 開発は PR で追跡することにする.マージが可能な状態かとか,テスト成功/失
220
+ 敗も見えるし.
data/pio.org_archive CHANGED
@@ -838,3 +838,20 @@ CLOSED: [2013-09-13 金 14:05] SCHEDULED: <2013-09-13 金>
838
838
  CLOCK: [2013-09-13 金 13:28]--[2013-09-13 金 14:05] => 0:37
839
839
  :END:
840
840
  [2013-09-13 金 13:28]
841
+
842
+ * Archived Tasks
843
+
844
+ ** CANCELED Pio::Mac を Trema に組込む
845
+ CLOSED: [2013-10-10 木 13:41] SCHEDULED: <2013-10-04 金>
846
+ - State "CANCELED" from "NEXT" [2013-10-10 木 13:41] \\
847
+ ダブってたのでキャンセル
848
+ :PROPERTIES:
849
+ :Effort: 0:30
850
+ :ARCHIVE_TIME: 2013-10-10 木 13:41
851
+ :ARCHIVE_FILE: ~/play/pio/pio.org
852
+ :ARCHIVE_OLPATH: Releases/0.2.5 リリース
853
+ :ARCHIVE_CATEGORY: pio
854
+ :ARCHIVE_TODO: CANCELED
855
+ :ARCHIVE_ITAGS: PIO
856
+ :END:
857
+ [2013-10-04 金 08:46]
data/spec/pio/mac_spec.rb CHANGED
@@ -10,8 +10,8 @@ module Pio
10
10
  context %{with "11:22:33:44:55:66"} do
11
11
  let( :value ) { "11:22:33:44:55:66" }
12
12
  it { should eq Mac.new( "11:22:33:44:55:66" ) }
13
- its( :value ) { should eq 0x112233445566 }
14
- its( :to_s ) { should eq "11:22:33:44:55:66" }
13
+ its( :to_int ) { should eq 0x112233445566 }
14
+ its( :to_str ) { should eq "11:22:33:44:55:66" }
15
15
  its( :to_ary ) { should eq [ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 ] }
16
16
  its( :multicast? ){ should be_true }
17
17
  its( :broadcast? ){ should be_false }
@@ -21,8 +21,8 @@ module Pio
21
21
  context "with 0" do
22
22
  let( :value ) { 0 }
23
23
  it { should eq Mac.new( 0 ) }
24
- its( :value ) { should eq 0 }
25
- its( :to_s ) { should eq "00:00:00:00:00:00" }
24
+ its( :to_int ) { should eq 0 }
25
+ its( :to_str ) { should eq "00:00:00:00:00:00" }
26
26
  its( :to_ary ) { should eq [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] }
27
27
  its( :multicast? ){ should be_false }
28
28
  its( :broadcast? ){ should be_false }
@@ -32,8 +32,8 @@ module Pio
32
32
  context "with 0xffffffffffff" do
33
33
  let( :value ) { 0xffffffffffff }
34
34
  it { should eq Mac.new( 0xffffffffffff ) }
35
- its( :value ) { should eq 0xffffffffffff }
36
- its( :to_s ) { should eq "ff:ff:ff:ff:ff:ff" }
35
+ its( :to_int ) { should eq 0xffffffffffff }
36
+ its( :to_str ) { should eq "ff:ff:ff:ff:ff:ff" }
37
37
  its( :to_ary ) { should eq [ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ] }
38
38
  its( :multicast? ){ should be_true }
39
39
  its( :broadcast? ){ should be_true }
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.4
4
+ version: 0.2.5
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-26 00:00:00.000000000 Z
11
+ date: 2013-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata