pio 0.2.7 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/.travis.yml +1 -0
- data/CONTRIBUTING.md +12 -0
- data/Gemfile +26 -23
- data/Guardfile +5 -0
- data/README.md +61 -19
- data/Rakefile +54 -56
- data/lib/pio/arp/frame.rb +8 -6
- data/lib/pio/arp/message.rb +9 -23
- data/lib/pio/arp/reply.rb +6 -15
- data/lib/pio/arp/request.rb +7 -16
- data/lib/pio/arp.rb +14 -17
- data/lib/pio/icmp/frame.rb +131 -0
- data/lib/pio/icmp/message.rb +100 -0
- data/lib/pio/icmp/reply.rb +17 -0
- data/lib/pio/icmp/request.rb +17 -0
- data/lib/pio/icmp.rb +27 -0
- data/lib/pio/ipv4_address.rb +22 -39
- data/lib/pio/lldp/chassis_id_tlv.rb +13 -16
- data/lib/pio/lldp/end_of_lldpdu_value.rb +4 -5
- data/lib/pio/lldp/frame.rb +21 -32
- data/lib/pio/lldp/management_address_value.rb +3 -4
- data/lib/pio/lldp/optional_tlv.rb +13 -22
- data/lib/pio/lldp/organizationally_specific_value.rb +3 -4
- data/lib/pio/lldp/port_description_value.rb +3 -4
- data/lib/pio/lldp/port_id_tlv.rb +6 -9
- data/lib/pio/lldp/system_capabilities_value.rb +3 -4
- data/lib/pio/lldp/system_description_value.rb +3 -4
- data/lib/pio/lldp/system_name_value.rb +3 -4
- data/lib/pio/lldp/ttl_tlv.rb +6 -9
- data/lib/pio/lldp.rb +20 -36
- data/lib/pio/mac.rb +30 -53
- data/lib/pio/message_util.rb +19 -0
- data/lib/pio/type/config.reek +4 -0
- data/lib/pio/type/ethernet_header.rb +7 -4
- data/lib/pio/type/ip_address.rb +5 -8
- data/lib/pio/type/ipv4_header.rb +37 -0
- data/lib/pio/type/mac_address.rb +7 -8
- data/lib/pio/util.rb +21 -0
- data/lib/pio/version.rb +2 -2
- data/lib/pio.rb +4 -4
- data/pio.gemspec +15 -17
- data/pio.org +499 -76
- data/pio.org_archive +86 -0
- data/rubocop-todo.yml +9 -0
- data/spec/pio/arp/reply_spec.rb +106 -118
- data/spec/pio/arp/request_spec.rb +90 -101
- data/spec/pio/arp_spec.rb +105 -113
- data/spec/pio/icmp/reply_spec.rb +132 -0
- data/spec/pio/icmp/request_spec.rb +131 -0
- data/spec/pio/icmp_spec.rb +159 -0
- data/spec/pio/ipv4_address_spec.rb +87 -97
- data/spec/pio/lldp_spec.rb +237 -186
- data/spec/pio/mac_spec.rb +82 -93
- data/spec/spec_helper.rb +10 -13
- metadata +20 -2
@@ -1,112 +1,102 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
its( :class_e? ) { should be_false }
|
39
|
-
its( :unicast? ) { should be_true }
|
40
|
-
its( :multicast? ) { should be_false }
|
41
|
-
end
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'pio/ipv4_address'
|
3
|
+
|
4
|
+
describe Pio::IPv4Address do
|
5
|
+
context '.new' do
|
6
|
+
subject(:ipv4) { Pio::IPv4Address.new(ip_address) }
|
7
|
+
|
8
|
+
context 'with 10.1.1.1' do
|
9
|
+
let(:ip_address) { '10.1.1.1' }
|
10
|
+
|
11
|
+
its(:to_s) { should eq '10.1.1.1' }
|
12
|
+
its(:to_i) { should eq(((10 * 256 + 1) * 256 + 1) * 256 + 1) }
|
13
|
+
its(:prefixlen) { should eq 32 }
|
14
|
+
its(:to_ary) { should eq [0x0a, 0x01, 0x01, 0x01] }
|
15
|
+
its(:class_a?) { should be_true }
|
16
|
+
its(:class_b?) { should be_false }
|
17
|
+
its(:class_c?) { should be_false }
|
18
|
+
its(:class_d?) { should be_false }
|
19
|
+
its(:class_e?) { should be_false }
|
20
|
+
its(:unicast?) { should be_true }
|
21
|
+
its(:multicast?) { should be_false }
|
22
|
+
|
23
|
+
context '.mask!' do
|
24
|
+
subject { ipv4.mask!(mask) }
|
25
|
+
|
26
|
+
let(:mask) { 8 }
|
27
|
+
|
28
|
+
its(:to_s) { should eq '10.0.0.0' }
|
29
|
+
its(:to_i) { should eq 10 * 256 * 256 * 256 }
|
30
|
+
its(:to_ary) { should eq [0x0a, 0x00, 0x00, 0x00] }
|
31
|
+
its(:class_a?) { should be_true }
|
32
|
+
its(:class_b?) { should be_false }
|
33
|
+
its(:class_c?) { should be_false }
|
34
|
+
its(:class_d?) { should be_false }
|
35
|
+
its(:class_e?) { should be_false }
|
36
|
+
its(:unicast?) { should be_true }
|
37
|
+
its(:multicast?) { should be_false }
|
42
38
|
end
|
39
|
+
end
|
43
40
|
|
41
|
+
context 'with 172.20.1.1' do
|
42
|
+
let(:ip_address) { '172.20.1.1' }
|
43
|
+
|
44
|
+
its(:to_s) { should eq '172.20.1.1' }
|
45
|
+
its(:to_i) { should eq(((172 * 256 + 20) * 256 + 1) * 256 + 1) }
|
46
|
+
its(:to_ary) { should eq [0xac, 0x14, 0x01, 0x01] }
|
47
|
+
its(:class_a?) { should be_false }
|
48
|
+
its(:class_b?) { should be_true }
|
49
|
+
its(:class_c?) { should be_false }
|
50
|
+
its(:class_d?) { should be_false }
|
51
|
+
its(:class_e?) { should be_false }
|
52
|
+
its(:unicast?) { should be_true }
|
53
|
+
its(:multicast?) { should be_false }
|
54
|
+
end
|
44
55
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
context "with 192.168.1.1" do
|
62
|
-
let( :ip_address ) { "192.168.1.1" }
|
63
|
-
|
64
|
-
its( :to_s ) { should eq "192.168.1.1" }
|
65
|
-
its( :to_i ) { should eq 3232235777 }
|
66
|
-
its( :to_ary ) { should eq [ 0xc0, 0xa8, 0x01, 0x01 ] }
|
67
|
-
its( :class_a? ) { should be_false }
|
68
|
-
its( :class_b? ) { should be_false }
|
69
|
-
its( :class_c? ) { should be_true }
|
70
|
-
its( :class_d? ) { should be_false }
|
71
|
-
its( :class_e? ) { should be_false }
|
72
|
-
its( :unicast? ) { should be_true }
|
73
|
-
its( :multicast? ) { should be_false }
|
74
|
-
end
|
75
|
-
|
76
|
-
|
77
|
-
context "with 234.1.1.1" do
|
78
|
-
let( :ip_address ) { "234.1.1.1" }
|
79
|
-
|
80
|
-
its( :to_s ) { should eq "234.1.1.1" }
|
81
|
-
its( :to_i ) { should eq ( ( ( 234 * 256 + 1 ) * 256 + 1 ) * 256 + 1 ) }
|
82
|
-
its( :to_ary ) { should eq [ 0xea, 0x01, 0x01, 0x01 ] }
|
83
|
-
its( :class_a? ) { should be_false }
|
84
|
-
its( :class_b? ) { should be_false }
|
85
|
-
its( :class_c? ) { should be_false }
|
86
|
-
its( :class_d? ) { should be_true }
|
87
|
-
its( :class_e? ) { should be_false }
|
88
|
-
its( :unicast? ) { should be_false }
|
89
|
-
its( :multicast? ) { should be_true }
|
90
|
-
end
|
91
|
-
|
56
|
+
context 'with 192.168.1.1' do
|
57
|
+
let(:ip_address) { '192.168.1.1' }
|
58
|
+
|
59
|
+
its(:to_s) { should eq '192.168.1.1' }
|
60
|
+
its(:to_i) { should eq 3_232_235_777 }
|
61
|
+
its(:to_ary) { should eq [0xc0, 0xa8, 0x01, 0x01] }
|
62
|
+
its(:class_a?) { should be_false }
|
63
|
+
its(:class_b?) { should be_false }
|
64
|
+
its(:class_c?) { should be_true }
|
65
|
+
its(:class_d?) { should be_false }
|
66
|
+
its(:class_e?) { should be_false }
|
67
|
+
its(:unicast?) { should be_true }
|
68
|
+
its(:multicast?) { should be_false }
|
69
|
+
end
|
92
70
|
|
93
|
-
|
94
|
-
|
71
|
+
context 'with 234.1.1.1' do
|
72
|
+
let(:ip_address) { '234.1.1.1' }
|
73
|
+
|
74
|
+
its(:to_s) { should eq '234.1.1.1' }
|
75
|
+
its(:to_i) { should eq(((234 * 256 + 1) * 256 + 1) * 256 + 1) }
|
76
|
+
its(:to_ary) { should eq [0xea, 0x01, 0x01, 0x01] }
|
77
|
+
its(:class_a?) { should be_false }
|
78
|
+
its(:class_b?) { should be_false }
|
79
|
+
its(:class_c?) { should be_false }
|
80
|
+
its(:class_d?) { should be_true }
|
81
|
+
its(:class_e?) { should be_false }
|
82
|
+
its(:unicast?) { should be_false }
|
83
|
+
its(:multicast?) { should be_true }
|
84
|
+
end
|
95
85
|
|
96
|
-
|
97
|
-
|
86
|
+
context 'with 192.168.0.1/16' do
|
87
|
+
let(:ip_address) { '192.168.0.1/16' }
|
98
88
|
|
89
|
+
its(:prefixlen) { should eq 16 }
|
90
|
+
end
|
99
91
|
|
100
|
-
|
101
|
-
|
92
|
+
context 'with 192.168.0.1/255.255.255.0' do
|
93
|
+
let(:ip_address) { '192.168.0.1/255.255.255.0' }
|
102
94
|
|
103
|
-
|
104
|
-
end
|
95
|
+
its(:prefixlen) { should eq 24 }
|
105
96
|
end
|
106
97
|
end
|
107
98
|
end
|
108
99
|
|
109
|
-
|
110
100
|
### Local variables:
|
111
101
|
### mode: Ruby
|
112
102
|
### coding: utf-8-unix
|
data/spec/pio/lldp_spec.rb
CHANGED
@@ -1,218 +1,269 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
it "returns a valid ether frame with size = 64" do
|
43
|
-
expect( subject.to_binary.size ).to eq 64
|
44
|
-
end
|
45
|
-
end
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'pio'
|
3
|
+
|
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
|
14
|
+
|
15
|
+
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
|
+
]
|
46
41
|
end
|
47
42
|
|
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
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
let( :port_number ) { 1 }
|
52
|
-
let( :source_mac ) { "06:05:04:03:02:01" }
|
53
|
-
let( :destination_mac ) { nil }
|
54
|
-
let( :lldp_dump ) {
|
55
|
-
[
|
56
|
-
0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e, # Destination MAC
|
57
|
-
0x06, 0x05, 0x04, 0x03, 0x02, 0x01, # Source MAC
|
58
|
-
0x88, 0xcc, # Ethertype
|
59
|
-
0x02, 0x09, 0x07, 0x00, 0x00, 0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d, # Chassis ID TLV
|
60
|
-
0x04, 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, # Port ID TLV
|
61
|
-
0x06, 0x02, 0x00, 0x78, # Time to live TLV
|
62
|
-
0x00, 0x00, # End of LLDPDU TLV
|
63
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # Padding
|
64
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
65
|
-
0x00, 0x00
|
66
|
-
]
|
67
|
-
}
|
68
|
-
|
69
|
-
context "#to_binary" do
|
70
|
-
it "returns an LLDP binary string" do
|
71
|
-
expect( subject.to_binary.unpack( "C*" ) ).to eq lldp_dump
|
72
|
-
end
|
73
|
-
|
74
|
-
it "returns a valid ether frame with size = 64" do
|
75
|
-
expect( subject.to_binary.size ).to eq 64
|
76
|
-
end
|
48
|
+
it 'returns a valid ether frame with size = 64' do
|
49
|
+
expect(subject.to_binary.size).to eq 64
|
77
50
|
end
|
78
51
|
end
|
52
|
+
end
|
53
|
+
|
54
|
+
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
|
+
]
|
80
|
+
end
|
79
81
|
|
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
|
80
86
|
|
81
|
-
|
82
|
-
|
83
|
-
let( :port_number ) { 1 }
|
84
|
-
let( :source_mac ) { "06:05:04:03:02:01" }
|
85
|
-
let( :destination_mac ) { "01:02:03:04:05:06" }
|
86
|
-
let( :lldp_dump ) {
|
87
|
-
[
|
88
|
-
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, # Destination MAC
|
89
|
-
0x06, 0x05, 0x04, 0x03, 0x02, 0x01, # Source MAC
|
90
|
-
0x88, 0xcc, # Ethertype
|
91
|
-
0x02, 0x09, 0x07, 0x00, 0x00, 0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d, # Chassis ID TLV
|
92
|
-
0x04, 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, # Port ID TLV
|
93
|
-
0x06, 0x02, 0x00, 0x78, # Time to live TLV
|
94
|
-
0x00, 0x00, # End of LLDPDU TLV
|
95
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # Padding
|
96
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
97
|
-
0x00, 0x00
|
98
|
-
]
|
99
|
-
}
|
100
|
-
|
101
|
-
context "#to_binary" do
|
102
|
-
it "returns an LLDP binary string" do
|
103
|
-
expect( subject.to_binary.unpack( "C*" ) ).to eq lldp_dump
|
104
|
-
end
|
105
|
-
|
106
|
-
it "returns a valid ether frame with size = 64" do
|
107
|
-
expect( subject.to_binary.size ).to eq 64
|
108
|
-
end
|
87
|
+
it 'returns a valid ether frame with size = 64' do
|
88
|
+
expect(subject.to_binary.size).to eq 64
|
109
89
|
end
|
110
90
|
end
|
91
|
+
end
|
111
92
|
|
93
|
+
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
|
+
]
|
119
|
+
end
|
112
120
|
|
113
|
-
context
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
let( :destination_mac ) { nil }
|
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
|
118
125
|
|
119
|
-
it
|
126
|
+
it 'returns a valid ether frame with size = 64' do
|
127
|
+
expect(subject.to_binary.size).to eq 64
|
128
|
+
end
|
120
129
|
end
|
130
|
+
end
|
121
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 }
|
122
137
|
|
123
|
-
|
124
|
-
let( :dpid ) { 108173701773 }
|
125
|
-
let( :port_number ) { nil }
|
126
|
-
let( :source_mac ) { nil }
|
127
|
-
let( :destination_mac ) { nil }
|
128
|
-
|
129
|
-
it { expect { subject }.to raise_error( "Invalid port number: nil" ) }
|
130
|
-
end
|
138
|
+
it { expect { subject }.to raise_error('Invalid DPID: nil') }
|
131
139
|
end
|
132
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
|
+
end
|
133
150
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
its( :port_id ) { should eq "Uplink to S1" }
|
157
|
-
its( :port_number ) { should eq "Uplink to S1" }
|
158
|
-
its( :ttl ) { should eq 120 }
|
159
|
-
its( :port_description ) { should be_nil }
|
160
|
-
its( :system_name ) { should be_nil }
|
161
|
-
its( :system_description ) { should be_nil }
|
162
|
-
its( :system_capabilities ) { should be_nil }
|
163
|
-
its( :management_address ) { should be_nil }
|
151
|
+
context '.read' do
|
152
|
+
subject { Pio::Lldp.read(data.pack('C*')) }
|
153
|
+
|
154
|
+
context 'with a minimal LLDP frame' do
|
155
|
+
let(:data) do
|
156
|
+
[
|
157
|
+
# Destination MAC
|
158
|
+
0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e,
|
159
|
+
# Source MAC
|
160
|
+
0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d,
|
161
|
+
# Ethertype
|
162
|
+
0x88, 0xcc,
|
163
|
+
# Chassis ID TLV
|
164
|
+
0x02, 0x07, 0x04, 0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d,
|
165
|
+
# Port ID TLV
|
166
|
+
0x04, 0x0d, 0x01, 0x55, 0x70, 0x6c, 0x69, 0x6e, 0x6b, 0x20,
|
167
|
+
0x74, 0x6f, 0x20, 0x53, 0x31,
|
168
|
+
# Time to live TLV
|
169
|
+
0x06, 0x02, 0x00, 0x78,
|
170
|
+
# End of LLDPDU TLV
|
171
|
+
0x00, 0x00
|
172
|
+
]
|
164
173
|
end
|
165
174
|
|
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 }
|
189
|
+
end
|
166
190
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
191
|
+
context 'with a detailed LLDP frame' do
|
192
|
+
let(:data) do
|
193
|
+
[
|
194
|
+
# Destination MAC
|
195
|
+
0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e,
|
196
|
+
# Source MAC
|
197
|
+
0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d,
|
198
|
+
# Ethertype
|
199
|
+
0x88, 0xcc,
|
200
|
+
# Chassis ID TLV
|
201
|
+
0x02, 0x07, 0x04, 0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d,
|
202
|
+
# Port ID TLV
|
203
|
+
0x04, 0x0d, 0x01, 0x55, 0x70, 0x6c, 0x69, 0x6e, 0x6b, 0x20,
|
204
|
+
0x74, 0x6f, 0x20, 0x53, 0x31,
|
205
|
+
# Time to live TLV
|
206
|
+
0x06, 0x02, 0x00, 0x78,
|
207
|
+
# 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,
|
211
|
+
# System Name
|
212
|
+
0x0a, 0x0d, 0x53, 0x75, 0x6d, 0x6d, 0x69, 0x74, 0x33, 0x30,
|
213
|
+
0x30, 0x2d, 0x34, 0x38, 0x00,
|
214
|
+
# 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,
|
223
|
+
# System Capabilities
|
224
|
+
0x0e, 0x04, 0x00, 0x14, 0x00, 0x14,
|
225
|
+
# Management Address
|
226
|
+
0x10, 0x0e, 0x07, 0x06, 0x00, 0x01, 0x30, 0xf9, 0xad, 0xa0,
|
227
|
+
0x02, 0x00, 0x00, 0x03, 0xe9, 0x00,
|
228
|
+
# Organizationally Specific
|
229
|
+
0xfe, 0x07, 0x00, 0x12, 0x0f, 0x02, 0x07, 0x01, 0x00,
|
230
|
+
# End of LLDPDU TLV
|
231
|
+
0x00, 0x00
|
232
|
+
]
|
203
233
|
end
|
204
234
|
|
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'
|
248
|
+
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*')
|
253
|
+
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" }
|
257
|
+
end
|
205
258
|
|
206
|
-
|
207
|
-
|
259
|
+
context 'with an invalid Lldp frame' do
|
260
|
+
let(:data) { [] }
|
208
261
|
|
209
|
-
|
210
|
-
end
|
262
|
+
it { expect { subject }.to raise_error(Pio::ParseError) }
|
211
263
|
end
|
212
264
|
end
|
213
265
|
end
|
214
266
|
|
215
|
-
|
216
267
|
### Local variables:
|
217
268
|
### mode: Ruby
|
218
269
|
### coding: utf-8-unix
|