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
@@ -1,112 +1,102 @@
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( :prefixlen ) { should eq 32 }
16
- its( :to_ary ) { should eq [ 0x0a, 0x01, 0x01, 0x01 ] }
17
- its( :class_a? ) { should be_true }
18
- its( :class_b? ) { should be_false }
19
- its( :class_c? ) { should be_false }
20
- its( :class_d? ) { should be_false }
21
- its( :class_e? ) { should be_false }
22
- its( :unicast? ) { should be_true }
23
- its( :multicast? ) { should be_false }
24
-
25
-
26
- context ".mask!" do
27
- subject { ipv4.mask!( mask ) }
28
-
29
- let( :mask ) { 8 }
30
-
31
- its( :to_s ) { should eq "10.0.0.0" }
32
- its( :to_i ) { should eq 10 * 256 * 256 * 256 }
33
- its( :to_ary ) { should eq [ 0x0a, 0x00, 0x00, 0x00 ] }
34
- its( :class_a? ) { should be_true }
35
- its( :class_b? ) { should be_false }
36
- its( :class_c? ) { should be_false }
37
- its( :class_d? ) { should be_false }
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
- context "with 172.20.1.1" do
46
- let( :ip_address ) { "172.20.1.1" }
47
-
48
- its( :to_s ) { should eq "172.20.1.1" }
49
- its( :to_i ) { should eq ( ( ( 172 * 256 + 20 ) * 256 + 1 ) * 256 + 1 ) }
50
- its( :to_ary ) { should eq [ 0xac, 0x14, 0x01, 0x01 ] }
51
- its( :class_a? ) { should be_false }
52
- its( :class_b? ) { should be_true }
53
- its( :class_c? ) { should be_false }
54
- its( :class_d? ) { should be_false }
55
- its( :class_e? ) { should be_false }
56
- its( :unicast? ) { should be_true }
57
- its( :multicast? ) { should be_false }
58
- end
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
- context "with 192.168.0.1/16" do
94
- let( :ip_address ) { "192.168.0.1/16" }
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
- its( :prefixlen ) { should eq 16 }
97
- end
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
- context "with 192.168.0.1/255.255.255.0" do
101
- let( :ip_address ) { "192.168.0.1/255.255.255.0" }
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
- its( :prefixlen ) { should eq 24 }
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
@@ -1,218 +1,269 @@
1
- require "pio"
2
-
3
-
4
- module Pio
5
- describe Lldp do
6
- context ".new" do
7
- subject {
8
- Lldp.new(
9
- :dpid => dpid,
10
- :port_number => port_number,
11
- :source_mac => source_mac,
12
- :destination_mac => destination_mac
13
- )
14
- }
15
-
16
-
17
- context "with :dpid and :port_number" do
18
- let( :dpid ) { 108173701773 }
19
- let( :port_number ) { 1 }
20
- let( :source_mac ) { nil }
21
- let( :destination_mac ) { nil }
22
- let( :lldp_dump ) {
23
- [
24
- 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e, # Destination MAC
25
- 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, # Source MAC
26
- 0x88, 0xcc, # Ethertype
27
- 0x02, 0x09, 0x07, 0x00, 0x00, 0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d, # Chassis ID TLV
28
- 0x04, 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, # Port ID TLV
29
- 0x06, 0x02, 0x00, 0x78, # Time to live TLV
30
- 0x00, 0x00, # End of LLDPDU TLV
31
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # Padding
32
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33
- 0x00, 0x00
34
- ]
35
- }
36
-
37
- context "#to_binary" do
38
- it "returns an LLDP binary string" do
39
- expect( subject.to_binary.unpack( "C*" ) ).to eq lldp_dump
40
- end
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
- context "with :dpid, :port_number and :source_mac" do
50
- let( :dpid ) { 108173701773 }
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
- context "with :dpid, :port_number, :source_mac and :destination_mac" do
82
- let( :dpid ) { 108173701773 }
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 "when :dpid is not set" do
114
- let( :dpid ) { nil }
115
- let( :port_number ) { 1 }
116
- let( :source_mac ) { nil }
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 { expect { subject }.to raise_error( "Invalid DPID: nil" ) }
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
- context "when :port_number is not set" do
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
- context ".read" do
135
- subject { Lldp.read( data.pack( "C*" ) ) }
136
-
137
- context "with a minimal LLDP frame" do
138
- let( :data ) {
139
- [
140
- 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e, # Destination MAC
141
- 0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d, # Source MAC
142
- 0x88, 0xcc, # Ethertype
143
- 0x02, 0x07, 0x04, 0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d, # Chassis ID TLV
144
- 0x04, 0x0d, 0x01, 0x55, 0x70, 0x6c, 0x69, 0x6e, 0x6b, 0x20, 0x74, 0x6f, 0x20, 0x53, 0x31, # Port ID TLV
145
- 0x06, 0x02, 0x00, 0x78, # Time to live TLV
146
- 0x00, 0x00 # End of LLDPDU TLV
147
- ]
148
- }
149
-
150
- its( "destination_mac.to_s" ) { should eq "01:80:c2:00:00:0e" }
151
- its( "source_mac.to_s" ) { should eq "00:19:2f:a7:b2:8d" }
152
- its( :ether_type ) { should eq 0x88cc }
153
- its( :dpid ) { should eq 108173701773 }
154
- its( 'dpid.class' ) { should eq Fixnum }
155
- its( :chassis_id ) { should eq 108173701773 }
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
- context "with a detailed LLDP frame" do
168
- let( :data ) {
169
- [
170
- 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e, # Destination MAC
171
- 0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d, # Source MAC
172
- 0x88, 0xcc, # Ethertype
173
- 0x02, 0x07, 0x04, 0x00, 0x19, 0x2f, 0xa7, 0xb2, 0x8d, # Chassis ID TLV
174
- 0x04, 0x0d, 0x01, 0x55, 0x70, 0x6c, 0x69, 0x6e, 0x6b, 0x20, 0x74, 0x6f, 0x20, 0x53, 0x31, # Port ID TLV
175
- 0x06, 0x02, 0x00, 0x78, # Time to live TLV
176
- 0x08, 0x17, 0x53, 0x75, 0x6d, 0x6d, 0x69, 0x74, 0x33, 0x30, 0x30, 0x2d, 0x34, 0x38, 0x2d, 0x50, 0x6f, 0x72, 0x74, 0x20, 0x31, 0x30, 0x30, 0x31, 0x00, # Port Description
177
- 0x0a, 0x0d, 0x53, 0x75, 0x6d, 0x6d, 0x69, 0x74, 0x33, 0x30, 0x30, 0x2d, 0x34, 0x38, 0x00, # System Name
178
- 0x0c, 0x4c, 0x53, 0x75, 0x6d, 0x6d, 0x69, 0x74, 0x33, 0x30, 0x30, 0x2d, 0x34, 0x38, 0x20, 0x2d, 0x20, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x37, 0x2e, 0x34, 0x65, 0x2e, 0x31, 0x20, 0x28, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x20, 0x35, 0x29, 0x20, 0x62, 0x79, 0x20, 0x52, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x5f, 0x4d, 0x61, 0x73, 0x74, 0x65, 0x72, 0x20, 0x30, 0x35, 0x2f, 0x32, 0x37, 0x2f, 0x30, 0x35, 0x20, 0x30, 0x34, 0x3a, 0x35, 0x33, 0x3a, 0x31, 0x31, 0x00, # System Description
179
- 0x0e, 0x04, 0x00, 0x14, 0x00, 0x14, # System Capabilities
180
- 0x10, 0x0e, 0x07, 0x06, 0x00, 0x01, 0x30, 0xf9, 0xad, 0xa0, 0x02, 0x00, 0x00, 0x03, 0xe9, 0x00, # Management Address
181
- 0xfe, 0x07, 0x00, 0x12, 0x0f, 0x02, 0x07, 0x01, 0x00, # Organizationally Specific
182
- 0x00, 0x00 # End of LLDPDU TLV
183
- ]
184
- }
185
-
186
- its( "destination_mac.to_s" ) { should eq "01:80:c2:00:00:0e" }
187
- its( "source_mac.to_s" ) { should eq "00:19:2f:a7:b2:8d" }
188
- its( :ether_type ) { should eq 0x88cc }
189
- its( :dpid ) { should eq 108173701773 }
190
- its( :chassis_id ) { should eq 108173701773 }
191
- its( :port_id ) { should eq "Uplink to S1" }
192
- its( :port_number ) { should eq "Uplink to S1" }
193
- its( :ttl ) { should eq 120 }
194
- its( :port_description ) { should eq "Summit300-48-Port 1001" }
195
- its( :system_name ) { should eq "Summit300-48" }
196
- its( :system_description ) { should eq "Summit300-48 - Version 7.4e.1 (Build 5) by Release_Master 05/27/05 04:53:11" }
197
- its( "system_capabilities.system_capabilities" ) { should eq 20 }
198
- its( "system_capabilities.enabled_capabilities" ) { should eq 20 }
199
- its( :management_address ) { should eq [ 0x00, 0x01, 0x30, 0xf9, 0xad, 0xa0 ].pack( "C*" ) }
200
- its( "organizationally_specific.oui" ) { should eq 4623 }
201
- its( "organizationally_specific.subtype" ) { should eq 2 }
202
- its( "organizationally_specific.information" ) { should eq "\a\x01" }
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
- context "with an invalid Lldp frame" do
207
- let( :data ) { [] }
259
+ context 'with an invalid Lldp frame' do
260
+ let(:data) { [] }
208
261
 
209
- it { expect { subject }.to raise_error( Pio::ParseError ) }
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