pio 0.3.0 → 0.4.0

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 (101) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +46 -12
  3. data/README.md +131 -116
  4. data/Rakefile +7 -92
  5. data/examples/arp_new.rb +16 -0
  6. data/examples/arp_read.rb +4 -0
  7. data/examples/dhcp_new.rb +30 -0
  8. data/examples/dhcp_read.rb +4 -0
  9. data/examples/icmp_new.rb +21 -0
  10. data/examples/icmp_read.rb +4 -0
  11. data/examples/lldp_new.rb +4 -0
  12. data/examples/lldp_read.rb +4 -0
  13. data/lib/pio.rb +6 -12
  14. data/lib/pio/arp.rb +7 -19
  15. data/lib/pio/arp/frame.rb +8 -12
  16. data/lib/pio/arp/message.rb +12 -25
  17. data/lib/pio/arp/reply.rb +30 -30
  18. data/lib/pio/arp/request.rb +30 -29
  19. data/lib/pio/dhcp.rb +58 -0
  20. data/lib/pio/dhcp/ack.rb +12 -0
  21. data/lib/pio/dhcp/boot_reply.rb +16 -0
  22. data/lib/pio/dhcp/boot_reply_options.rb +75 -0
  23. data/lib/pio/dhcp/boot_request.rb +16 -0
  24. data/lib/pio/dhcp/boot_request_options.rb +69 -0
  25. data/lib/pio/dhcp/common_options.rb +71 -0
  26. data/lib/pio/dhcp/csum_util.rb +83 -0
  27. data/lib/pio/dhcp/dhcp_field.rb +48 -0
  28. data/lib/pio/dhcp/dhcp_tlv_options.rb +84 -0
  29. data/lib/pio/dhcp/discover.rb +12 -0
  30. data/lib/pio/dhcp/field_util.rb +102 -0
  31. data/lib/pio/dhcp/frame.rb +95 -0
  32. data/lib/pio/dhcp/message.rb +79 -0
  33. data/lib/pio/dhcp/offer.rb +12 -0
  34. data/lib/pio/dhcp/optional_tlv.rb +74 -0
  35. data/lib/pio/dhcp/request.rb +12 -0
  36. data/lib/pio/dhcp/type/dhcp_client_id.rb +21 -0
  37. data/lib/pio/dhcp/type/dhcp_param_list.rb +22 -0
  38. data/lib/pio/dhcp/type/dhcp_string.rb +21 -0
  39. data/lib/pio/icmp.rb +7 -18
  40. data/lib/pio/icmp/frame.rb +38 -40
  41. data/lib/pio/icmp/message.rb +10 -61
  42. data/lib/pio/icmp/options.rb +25 -0
  43. data/lib/pio/icmp/reply.rb +34 -7
  44. data/lib/pio/icmp/request.rb +43 -7
  45. data/lib/pio/ipv4_address.rb +5 -8
  46. data/lib/pio/lldp.rb +22 -62
  47. data/lib/pio/lldp/chassis_id_tlv.rb +7 -13
  48. data/lib/pio/lldp/end_of_lldpdu_value.rb +3 -9
  49. data/lib/pio/lldp/frame.rb +6 -12
  50. data/lib/pio/lldp/management_address_value.rb +4 -10
  51. data/lib/pio/lldp/optional_tlv.rb +5 -10
  52. data/lib/pio/lldp/options.rb +37 -0
  53. data/lib/pio/lldp/organizationally_specific_value.rb +2 -8
  54. data/lib/pio/lldp/port_description_value.rb +2 -8
  55. data/lib/pio/lldp/port_id_tlv.rb +6 -12
  56. data/lib/pio/lldp/system_capabilities_value.rb +2 -8
  57. data/lib/pio/lldp/system_description_value.rb +2 -8
  58. data/lib/pio/lldp/system_name_value.rb +2 -8
  59. data/lib/pio/lldp/ttl_tlv.rb +5 -11
  60. data/lib/pio/mac.rb +4 -9
  61. data/lib/pio/message_type_selector.rb +22 -0
  62. data/lib/pio/options.rb +65 -0
  63. data/lib/pio/parse_error.rb +6 -0
  64. data/lib/pio/type/ethernet_header.rb +3 -2
  65. data/lib/pio/type/ip_address.rb +4 -9
  66. data/lib/pio/type/ipv4_header.rb +12 -17
  67. data/lib/pio/type/mac_address.rb +5 -10
  68. data/lib/pio/type/udp_header.rb +18 -0
  69. data/lib/pio/version.rb +3 -8
  70. data/pio.gemspec +12 -10
  71. data/spec/pio/arp/reply/options_spec.rb +145 -0
  72. data/spec/pio/arp/reply_spec.rb +77 -113
  73. data/spec/pio/arp/request/options_spec.rb +115 -0
  74. data/spec/pio/arp/request_spec.rb +74 -96
  75. data/spec/pio/arp_spec.rb +71 -105
  76. data/spec/pio/dhcp/ack_spec.rb +189 -0
  77. data/spec/pio/dhcp/discover_spec.rb +165 -0
  78. data/spec/pio/dhcp/offer_spec.rb +189 -0
  79. data/spec/pio/dhcp/request_spec.rb +173 -0
  80. data/spec/pio/dhcp_spec.rb +609 -0
  81. data/spec/pio/icmp/reply_spec.rb +102 -95
  82. data/spec/pio/icmp/request_spec.rb +86 -78
  83. data/spec/pio/icmp_spec.rb +153 -146
  84. data/spec/pio/ipv4_address_spec.rb +2 -7
  85. data/spec/pio/lldp/options_spec.rb +188 -0
  86. data/spec/pio/lldp_spec.rb +181 -208
  87. data/spec/pio/mac_spec.rb +3 -8
  88. data/spec/spec_helper.rb +4 -10
  89. metadata +69 -17
  90. data/.gitignore +0 -20
  91. data/.rspec +0 -3
  92. data/.rubocop.yml +0 -1
  93. data/.travis.yml +0 -13
  94. data/Gemfile +0 -37
  95. data/Guardfile +0 -24
  96. data/lib/pio/message_util.rb +0 -19
  97. data/lib/pio/type/config.reek +0 -4
  98. data/lib/pio/util.rb +0 -21
  99. data/pio.org +0 -668
  100. data/pio.org_archive +0 -943
  101. data/rubocop-todo.yml +0 -9
@@ -1,271 +1,244 @@
1
- # -*- coding: utf-8 -*-
1
+ # encoding: utf-8
2
+
2
3
  require 'pio'
3
4
 
4
- describe Pio::Lldp do
5
- context '.new' do
6
- subject do
7
- Pio::Lldp.new(
8
- :dpid => dpid,
9
- :port_number => port_number,
10
- :source_mac => source_mac,
11
- :destination_mac => destination_mac
12
- )
13
- end
5
+ describe Pio::LLDP do
6
+ Then { Pio::LLDP == Pio::Lldp }
7
+ end
14
8
 
9
+ describe Pio::Lldp do
10
+ describe '.new' do
15
11
  context 'with :dpid and :port_number' do
16
- let(:dpid) { 0x192fa7b28d }
17
- let(:port_number) { 1 }
18
- let(:source_mac) { nil }
19
- let(:destination_mac) { nil }
20
- let(:lldp_dump) do
21
- [
22
- # Destination MAC
23
- 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e,
24
- # Source MAC
25
- 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
26
- # Ethertype
27
- 0x88, 0xcc,
28
- # Chassis ID TLV
29
- 0x02, 0x09, 0x07, 0x00, 0x00, 0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d,
30
- # Port ID TLV
31
- 0x04, 0x05, 0x07, 0x00, 0x00, 0x00, 0x01,
32
- # Time to live TLV
33
- 0x06, 0x02, 0x00, 0x78,
34
- # End of LLDPDU TLV
35
- 0x00, 0x00,
36
- # Padding
37
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
38
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
39
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
40
- ]
12
+ Given(:lldp) do
13
+ Pio::Lldp.new(dpid: 0x192fa7b28d, port_number: 1)
41
14
  end
42
15
 
43
- context '#to_binary' do
44
- it 'returns an LLDP binary string' do
45
- expect(subject.to_binary.unpack('C*')).to eq lldp_dump
46
- end
47
-
48
- it 'returns a valid ether frame with size = 64' do
49
- expect(subject.to_binary.size).to eq 64
16
+ describe '#to_binary' do
17
+ When(:result) { lldp.to_binary }
18
+
19
+ Then do
20
+ result ==
21
+ [
22
+ # Destination MAC
23
+ 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e,
24
+ # Source MAC
25
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
26
+ # Ethertype
27
+ 0x88, 0xcc,
28
+ # Chassis ID TLV
29
+ 0x02, 0x09, 0x07, 0x00, 0x00, 0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d,
30
+ # Port ID TLV
31
+ 0x04, 0x05, 0x07, 0x00, 0x00, 0x00, 0x01,
32
+ # Time to live TLV
33
+ 0x06, 0x02, 0x00, 0x78,
34
+ # End of LLDPDU TLV
35
+ 0x00, 0x00,
36
+ # Padding
37
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
38
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
39
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
40
+ ].pack('C*')
50
41
  end
42
+ And { result.size == 64 }
51
43
  end
52
44
  end
53
45
 
54
46
  context 'with :dpid, :port_number and :source_mac' do
55
- let(:dpid) { 0x192fa7b28d }
56
- let(:port_number) { 1 }
57
- let(:source_mac) { '06:05:04:03:02:01' }
58
- let(:destination_mac) { nil }
59
- let(:lldp_dump) do
60
- [
61
- # Destination MAC
62
- 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e,
63
- # Source MAC
64
- 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
65
- # Ethertype
66
- 0x88, 0xcc,
67
- # Chassis ID TLV
68
- 0x02, 0x09, 0x07, 0x00, 0x00, 0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d,
69
- # Port ID TLV
70
- 0x04, 0x05, 0x07, 0x00, 0x00, 0x00, 0x01,
71
- # Time to live TLV
72
- 0x06, 0x02, 0x00, 0x78,
73
- # End of LLDPDU TLV
74
- 0x00, 0x00,
75
- # Padding
76
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
77
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
78
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
79
- ]
47
+ Given(:lldp) do
48
+ Pio::Lldp.new(
49
+ dpid: 0x192fa7b28d,
50
+ port_number: 1,
51
+ source_mac: '06:05:04:03:02:01'
52
+ )
80
53
  end
81
54
 
82
- context '#to_binary' do
83
- it 'returns an LLDP binary string' do
84
- expect(subject.to_binary.unpack('C*')).to eq lldp_dump
85
- end
86
-
87
- it 'returns a valid ether frame with size = 64' do
88
- expect(subject.to_binary.size).to eq 64
55
+ describe '#to_binary' do
56
+ When(:result) { lldp.to_binary }
57
+
58
+ Then do
59
+ result ==
60
+ [
61
+ # Destination MAC
62
+ 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e,
63
+ # Source MAC
64
+ 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
65
+ # Ethertype
66
+ 0x88, 0xcc,
67
+ # Chassis ID TLV
68
+ 0x02, 0x09, 0x07, 0x00, 0x00, 0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d,
69
+ # Port ID TLV
70
+ 0x04, 0x05, 0x07, 0x00, 0x00, 0x00, 0x01,
71
+ # Time to live TLV
72
+ 0x06, 0x02, 0x00, 0x78,
73
+ # End of LLDPDU TLV
74
+ 0x00, 0x00,
75
+ # Padding
76
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
77
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
78
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
79
+ ].pack('C*')
89
80
  end
81
+ And { result.size == 64 }
90
82
  end
91
83
  end
92
84
 
93
85
  context 'with :dpid, :port_number, :source_mac and :destination_mac' do
94
- let(:dpid) { 0x192fa7b28d }
95
- let(:port_number) { 1 }
96
- let(:source_mac) { '06:05:04:03:02:01' }
97
- let(:destination_mac) { '01:02:03:04:05:06' }
98
- let(:lldp_dump) do
99
- [
100
- # Destination MAC
101
- 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
102
- # Source MAC
103
- 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
104
- # Ethertype
105
- 0x88, 0xcc,
106
- # Chassis ID TLV
107
- 0x02, 0x09, 0x07, 0x00, 0x00, 0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d,
108
- # Port ID TLV
109
- 0x04, 0x05, 0x07, 0x00, 0x00, 0x00, 0x01,
110
- # Time to live TLV
111
- 0x06, 0x02, 0x00, 0x78,
112
- # End of LLDPDU TLV
113
- 0x00, 0x00,
114
- # Padding
115
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
116
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
117
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
118
- ]
86
+ Given(:lldp) do
87
+ Pio::Lldp.new(
88
+ dpid: 0x192fa7b28d,
89
+ port_number: 1,
90
+ source_mac: '06:05:04:03:02:01',
91
+ destination_mac: '01:02:03:04:05:06'
92
+ )
119
93
  end
120
94
 
121
- context '#to_binary' do
122
- it 'returns an LLDP binary string' do
123
- expect(subject.to_binary.unpack('C*')).to eq lldp_dump
124
- end
125
-
126
- it 'returns a valid ether frame with size = 64' do
127
- expect(subject.to_binary.size).to eq 64
95
+ describe '#to_binary' do
96
+ When(:result) { lldp.to_binary }
97
+
98
+ Then do
99
+ result ==
100
+ [
101
+ # Destination MAC
102
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
103
+ # Source MAC
104
+ 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
105
+ # Ethertype
106
+ 0x88, 0xcc,
107
+ # Chassis ID TLV
108
+ 0x02, 0x09, 0x07, 0x00, 0x00, 0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d,
109
+ # Port ID TLV
110
+ 0x04, 0x05, 0x07, 0x00, 0x00, 0x00, 0x01,
111
+ # Time to live TLV
112
+ 0x06, 0x02, 0x00, 0x78,
113
+ # End of LLDPDU TLV
114
+ 0x00, 0x00,
115
+ # Padding
116
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
117
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
118
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
119
+ ].pack('C*')
128
120
  end
121
+ And { result.size == 64 }
129
122
  end
130
123
  end
131
-
132
- context 'when :dpid is not set' do
133
- let(:dpid) { nil }
134
- let(:port_number) { 1 }
135
- let(:source_mac) { nil }
136
- let(:destination_mac) { nil }
137
-
138
- it { expect { subject }.to raise_error('Invalid DPID: nil') }
139
- end
140
-
141
- context 'when :port_number is not set' do
142
- let(:dpid) { 0x192fa7b28d }
143
- let(:port_number) { nil }
144
- let(:source_mac) { nil }
145
- let(:destination_mac) { nil }
146
-
147
- it { expect { subject }.to raise_error('Invalid port number: nil') }
148
- end
149
124
  end
150
125
 
151
126
  context '.read' do
152
- subject { Pio::Lldp.read(data.pack('C*')) }
153
-
154
- context 'with a minimal LLDP frame' do
155
- let(:data) do
127
+ context 'with a minimum LLDP frame' do
128
+ Given(:lldp_dump) do
156
129
  [
157
130
  # Destination MAC
158
- 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e,
131
+ 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e,
159
132
  # Source MAC
160
- 0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d,
133
+ 0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d,
161
134
  # Ethertype
162
- 0x88, 0xcc,
135
+ 0x88, 0xcc,
163
136
  # Chassis ID TLV
164
- 0x02, 0x07, 0x04, 0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d,
137
+ 0x02, 0x07, 0x04, 0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d,
165
138
  # Port ID TLV
166
- 0x04, 0x0d, 0x01, 0x55, 0x70, 0x6c, 0x69, 0x6e, 0x6b, 0x20,
167
- 0x74, 0x6f, 0x20, 0x53, 0x31,
139
+ 0x04, 0x0d, 0x01, 0x55, 0x70, 0x6c, 0x69, 0x6e, 0x6b, 0x20,
140
+ 0x74, 0x6f, 0x20, 0x53, 0x31,
168
141
  # Time to live TLV
169
- 0x06, 0x02, 0x00, 0x78,
142
+ 0x06, 0x02, 0x00, 0x78,
170
143
  # End of LLDPDU TLV
171
- 0x00, 0x00
172
- ]
144
+ 0x00, 0x00
145
+ ].pack('C*')
173
146
  end
174
147
 
175
- its('destination_mac.to_s') { should eq '01:80:c2:00:00:0e' }
176
- its('source_mac.to_s') { should eq '00:19:2f:a7:b2:8d' }
177
- its(:ether_type) { should eq 0x88cc }
178
- its(:dpid) { should eq 0x192fa7b28d }
179
- its('dpid.class') { should eq Fixnum }
180
- its(:chassis_id) { should eq 0x192fa7b28d }
181
- its(:port_id) { should eq 'Uplink to S1' }
182
- its(:port_number) { should eq 'Uplink to S1' }
183
- its(:ttl) { should eq 120 }
184
- its(:port_description) { should be_nil }
185
- its(:system_name) { should be_nil }
186
- its(:system_description) { should be_nil }
187
- its(:system_capabilities) { should be_nil }
188
- its(:management_address) { should be_nil }
148
+ When(:lldp) { Pio::Lldp.read(lldp_dump) }
149
+
150
+ Then { lldp.destination_mac.to_s == '01:80:c2:00:00:0e' }
151
+ Then { lldp.source_mac.to_s == '00:19:2f:a7:b2:8d' }
152
+ Then { lldp.ether_type == 0x88cc }
153
+ Then { lldp.dpid == 0x192fa7b28d }
154
+ Then { lldp.dpid.class == Fixnum }
155
+ Then { lldp.chassis_id == 0x192fa7b28d }
156
+ Then { lldp.port_id == 'Uplink to S1' }
157
+ Then { lldp.port_number == 'Uplink to S1' }
158
+ Then { lldp.ttl == 120 }
159
+ Then { lldp.port_description == nil }
160
+ Then { lldp.system_name == nil }
161
+ Then { lldp.system_description == nil }
162
+ Then { lldp.system_capabilities == nil }
163
+ Then { lldp.management_address == nil }
189
164
  end
190
165
 
191
166
  context 'with a detailed LLDP frame' do
192
- let(:data) do
167
+ Given(:lldp_dump) do
193
168
  [
194
169
  # Destination MAC
195
- 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e,
170
+ 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e,
196
171
  # Source MAC
197
- 0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d,
172
+ 0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d,
198
173
  # Ethertype
199
- 0x88, 0xcc,
174
+ 0x88, 0xcc,
200
175
  # Chassis ID TLV
201
- 0x02, 0x07, 0x04, 0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d,
176
+ 0x02, 0x07, 0x04, 0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d,
202
177
  # Port ID TLV
203
- 0x04, 0x0d, 0x01, 0x55, 0x70, 0x6c, 0x69, 0x6e, 0x6b, 0x20,
204
- 0x74, 0x6f, 0x20, 0x53, 0x31,
178
+ 0x04, 0x0d, 0x01, 0x55, 0x70, 0x6c, 0x69, 0x6e, 0x6b, 0x20,
179
+ 0x74, 0x6f, 0x20, 0x53, 0x31,
205
180
  # Time to live TLV
206
- 0x06, 0x02, 0x00, 0x78,
181
+ 0x06, 0x02, 0x00, 0x78,
207
182
  # Port Description
208
- 0x08, 0x17, 0x53, 0x75, 0x6d, 0x6d, 0x69, 0x74, 0x33, 0x30,
209
- 0x30, 0x2d, 0x34, 0x38, 0x2d, 0x50, 0x6f, 0x72, 0x74, 0x20,
210
- 0x31, 0x30, 0x30, 0x31, 0x00,
183
+ 0x08, 0x17, 0x53, 0x75, 0x6d, 0x6d, 0x69, 0x74, 0x33, 0x30,
184
+ 0x30, 0x2d, 0x34, 0x38, 0x2d, 0x50, 0x6f, 0x72, 0x74, 0x20,
185
+ 0x31, 0x30, 0x30, 0x31, 0x00,
211
186
  # System Name
212
- 0x0a, 0x0d, 0x53, 0x75, 0x6d, 0x6d, 0x69, 0x74, 0x33, 0x30,
213
- 0x30, 0x2d, 0x34, 0x38, 0x00,
187
+ 0x0a, 0x0d, 0x53, 0x75, 0x6d, 0x6d, 0x69, 0x74, 0x33, 0x30,
188
+ 0x30, 0x2d, 0x34, 0x38, 0x00,
214
189
  # System Description
215
- 0x0c, 0x4c, 0x53, 0x75, 0x6d, 0x6d, 0x69, 0x74, 0x33, 0x30,
216
- 0x30, 0x2d, 0x34, 0x38, 0x20, 0x2d, 0x20, 0x56, 0x65, 0x72,
217
- 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x37, 0x2e, 0x34, 0x65, 0x2e,
218
- 0x31, 0x20, 0x28, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x20, 0x35,
219
- 0x29, 0x20, 0x62, 0x79, 0x20, 0x52, 0x65, 0x6c, 0x65, 0x61,
220
- 0x73, 0x65, 0x5f, 0x4d, 0x61, 0x73, 0x74, 0x65, 0x72, 0x20,
221
- 0x30, 0x35, 0x2f, 0x32, 0x37, 0x2f, 0x30, 0x35, 0x20, 0x30,
222
- 0x34, 0x3a, 0x35, 0x33, 0x3a, 0x31, 0x31, 0x00,
190
+ 0x0c, 0x4c, 0x53, 0x75, 0x6d, 0x6d, 0x69, 0x74, 0x33, 0x30,
191
+ 0x30, 0x2d, 0x34, 0x38, 0x20, 0x2d, 0x20, 0x56, 0x65, 0x72,
192
+ 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x37, 0x2e, 0x34, 0x65, 0x2e,
193
+ 0x31, 0x20, 0x28, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x20, 0x35,
194
+ 0x29, 0x20, 0x62, 0x79, 0x20, 0x52, 0x65, 0x6c, 0x65, 0x61,
195
+ 0x73, 0x65, 0x5f, 0x4d, 0x61, 0x73, 0x74, 0x65, 0x72, 0x20,
196
+ 0x30, 0x35, 0x2f, 0x32, 0x37, 0x2f, 0x30, 0x35, 0x20, 0x30,
197
+ 0x34, 0x3a, 0x35, 0x33, 0x3a, 0x31, 0x31, 0x00,
223
198
  # System Capabilities
224
- 0x0e, 0x04, 0x00, 0x14, 0x00, 0x14,
199
+ 0x0e, 0x04, 0x00, 0x14, 0x00, 0x14,
225
200
  # Management Address
226
- 0x10, 0x0e, 0x07, 0x06, 0x00, 0x01, 0x30, 0xf9, 0xad, 0xa0,
227
- 0x02, 0x00, 0x00, 0x03, 0xe9, 0x00,
201
+ 0x10, 0x0e, 0x07, 0x06, 0x00, 0x01, 0x30, 0xf9, 0xad, 0xa0,
202
+ 0x02, 0x00, 0x00, 0x03, 0xe9, 0x00,
228
203
  # Organizationally Specific
229
- 0xfe, 0x07, 0x00, 0x12, 0x0f, 0x02, 0x07, 0x01, 0x00,
204
+ 0xfe, 0x07, 0x00, 0x12, 0x0f, 0x02, 0x07, 0x01, 0x00,
230
205
  # End of LLDPDU TLV
231
- 0x00, 0x00
232
- ]
206
+ 0x00, 0x00
207
+ ].pack('C*')
233
208
  end
234
209
 
235
- its('destination_mac.to_s') { should eq '01:80:c2:00:00:0e' }
236
- its('source_mac.to_s') { should eq '00:19:2f:a7:b2:8d' }
237
- its(:ether_type) { should eq 0x88cc }
238
- its(:dpid) { should eq 0x192fa7b28d }
239
- its(:chassis_id) { should eq 0x192fa7b28d }
240
- its(:port_id) { should eq 'Uplink to S1' }
241
- its(:port_number) { should eq 'Uplink to S1' }
242
- its(:ttl) { should eq 120 }
243
- its(:port_description) { should eq 'Summit300-48-Port 1001' }
244
- its(:system_name) { should eq 'Summit300-48' }
245
- its(:system_description) do
246
- should eq 'Summit300-48 - Version 7.4e.1 (Build 5) ' +
247
- 'by Release_Master 05/27/05 04:53:11'
210
+ When(:lldp) { Pio::Lldp.read(lldp_dump) }
211
+
212
+ Then { lldp.destination_mac.to_s == '01:80:c2:00:00:0e' }
213
+ Then { lldp.source_mac.to_s == '00:19:2f:a7:b2:8d' }
214
+ Then { lldp.ether_type == 0x88cc }
215
+ Then { lldp.dpid == 0x192fa7b28d }
216
+ Then { lldp.chassis_id == 0x192fa7b28d }
217
+ Then { lldp.port_id == 'Uplink to S1' }
218
+ Then { lldp.port_number == 'Uplink to S1' }
219
+ Then { lldp.ttl == 120 }
220
+ Then { lldp.port_description == 'Summit300-48-Port 1001' }
221
+ Then { lldp.system_name == 'Summit300-48' }
222
+ Then do
223
+ lldp.system_description ==
224
+ 'Summit300-48 - Version 7.4e.1 (Build 5) ' \
225
+ 'by Release_Master 05/27/05 04:53:11'
248
226
  end
249
- its('system_capabilities.system_capabilities') { should eq 20 }
250
- its('system_capabilities.enabled_capabilities') { should eq 20 }
251
- its(:management_address) do
252
- should eq [0x00, 0x01, 0x30, 0xf9, 0xad, 0xa0].pack('C*')
227
+ Then { lldp.system_capabilities.system_capabilities == 20 }
228
+ Then { lldp.system_capabilities.enabled_capabilities == 20 }
229
+ Then do
230
+ lldp.management_address ==
231
+ [0x00, 0x01, 0x30, 0xf9, 0xad, 0xa0].pack('C*')
253
232
  end
254
- its('organizationally_specific.oui') { should eq 4623 }
255
- its('organizationally_specific.subtype') { should eq 2 }
256
- its('organizationally_specific.information') { should eq "\a\x01" }
233
+ Then { lldp.organizationally_specific.oui == 4623 }
234
+ Then { lldp.organizationally_specific.subtype == 2 }
235
+ Then { lldp.organizationally_specific.information == "\a\x01" }
257
236
  end
258
237
 
259
- context 'with an invalid Lldp frame' do
260
- let(:data) { [] }
238
+ context 'with an invalid LLDP frame' do
239
+ When(:result) { Pio::Lldp.read('') }
261
240
 
262
- it { expect { subject }.to raise_error(Pio::ParseError) }
241
+ Then { result == Failure(Pio::ParseError, 'End of file reached') }
263
242
  end
264
243
  end
265
244
  end
266
-
267
- ### Local variables:
268
- ### mode: Ruby
269
- ### coding: utf-8-unix
270
- ### indent-tabs-mode: nil
271
- ### End:
data/spec/pio/mac_spec.rb CHANGED
@@ -1,4 +1,4 @@
1
- # -*- coding: utf-8 -*-
1
+ # coding: utf-8
2
2
  require 'pio/mac'
3
3
 
4
4
  describe Pio::Mac do
@@ -17,6 +17,7 @@ describe Pio::Mac do
17
17
  it { should_not eq 42 }
18
18
  it { should_not eq 'INVALID_MAC_ADDRESS' }
19
19
  end
20
+
20
21
  describe '#eql?' do
21
22
  it { expect(subject).to eql Pio::Mac.new('11:22:33:44:55:66') }
22
23
  it { expect(subject).to eql '11:22:33:44:55:66' }
@@ -45,7 +46,7 @@ describe Pio::Mac do
45
46
 
46
47
  context 'with reserved address' do
47
48
  (0x0..0xf).each do | each |
48
- octet = sprintf('%02x', each)
49
+ octet = format('%02x', each)
49
50
  reserved_address = "01:80:c2:00:00:#{ octet }"
50
51
 
51
52
  context "when #{ reserved_address }" do
@@ -104,9 +105,3 @@ describe Pio::Mac do
104
105
  end
105
106
  end
106
107
  end
107
-
108
- ### Local variables:
109
- ### mode: Ruby
110
- ### coding: utf-8-unix
111
- ### indent-tabs-mode: nil
112
- ### End: