ospfv2 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/COPYING +674 -0
- data/LICENSE.txt +53 -0
- data/README +50 -0
- data/bin/ospfv2 +112 -105
- data/changelog.txt +7 -0
- data/gemspec +17 -0
- data/lib/ie/external_route.rb +9 -0
- data/lib/ie/id.rb +3 -4
- data/lib/ie/ie.rb +12 -0
- data/lib/ie/ls_age.rb +35 -5
- data/lib/ie/ls_type.rb +40 -37
- data/lib/ie/opaque_id.rb +46 -0
- data/lib/ie/opaque_type.rb +96 -0
- data/lib/ie/options.rb +5 -3
- data/lib/ie/router_link.rb +30 -7
- data/lib/ie/router_link_type.rb +116 -27
- data/lib/ie/sequence_number.rb +7 -3
- data/lib/infra/ospf_common.rb +1 -12
- data/lib/infra/ospf_io.rb +14 -8
- data/lib/infra/ospf_socket.rb +14 -14
- data/lib/infra/parse_options.rb +69 -25
- data/lib/ls_db/advertised_routers.rb +1 -1
- data/lib/ls_db/link_state_database.rb +74 -39
- data/lib/ls_db/link_state_database_build.rb +3 -3
- data/lib/ls_db/link_state_database_links.rb +7 -2
- data/lib/ls_db/lsdb_ios.rb +59 -0
- data/lib/lsa/external.rb +35 -2
- data/lib/lsa/lsa.rb +128 -35
- data/lib/lsa/lsa_factory.rb +20 -7
- data/lib/lsa/network.rb +44 -9
- data/lib/lsa/router.rb +14 -2
- data/lib/lsa/summary.rb +16 -3
- data/lib/lsa/tlv/color.rb +47 -0
- data/lib/lsa/tlv/link.rb +122 -0
- data/lib/lsa/tlv/link_id.rb +55 -0
- data/lib/lsa/tlv/link_type.rb +44 -0
- data/lib/lsa/tlv/local_interface.rb +56 -0
- data/lib/lsa/tlv/maximum_bandwidth.rb +55 -0
- data/lib/lsa/tlv/maximum_reservable_bandwidth.rb +52 -0
- data/lib/lsa/tlv/remote_interface.rb +58 -0
- data/lib/lsa/tlv/router_address.rb +57 -0
- data/lib/lsa/tlv/tlv.rb +32 -0
- data/lib/lsa/tlv/tlv_factory.rb +72 -0
- data/lib/lsa/tlv/traffic_engineering_metric.rb +52 -0
- data/lib/lsa/tlv/unreserved_bandwidth.rb +55 -0
- data/lib/lsa/traffic_engineering.rb +95 -0
- data/lib/neighbor/neighbor.rb +9 -9
- data/lib/packet/link_state_update.rb +16 -14
- data/lib/packet/ospf_packet.rb +13 -9
- data/test/unit/ie/au_type_test.rb +18 -0
- data/test/unit/ie/external_route_test.rb +51 -0
- data/test/unit/ie/id_test.rb +22 -0
- data/test/unit/ie/interface_mtu_test.rb +23 -0
- data/test/unit/ie/ls_age_test.rb +46 -0
- data/test/unit/ie/ls_type_test.rb +41 -0
- data/test/unit/ie/metric_test.rb +24 -0
- data/test/unit/ie/mt_metric_test.rb +27 -0
- data/test/unit/ie/opaque_id_test.rb +22 -0
- data/test/unit/ie/opaque_type_test.rb +22 -0
- data/test/unit/ie/options_test.rb +142 -0
- data/test/unit/ie/ospf_version_test.rb +0 -0
- data/test/unit/ie/packet_type_test.rb +33 -0
- data/test/unit/ie/router_link_factory_test.rb +26 -0
- data/test/unit/ie/router_link_test.rb +276 -0
- data/test/unit/ie/router_link_type_test.rb +24 -0
- data/test/unit/ie/sequence_number_test.rb +31 -0
- data/test/unit/ie/tos_metric_test.rb +27 -0
- data/test/unit/infra/ospf_common_test.rb +42 -0
- data/test/unit/infra/parse_options_test.rb +58 -0
- data/test/unit/infra/timer_test.rb +94 -0
- data/test/unit/ls_db/all +10 -0
- data/test/unit/ls_db/link_state_database_build_test.rb +140 -0
- data/test/unit/ls_db/link_state_database_links_tests.rb +74 -0
- data/test/unit/ls_db/link_state_database_test.rb +444 -0
- data/test/unit/ls_db/links_test.rb +49 -0
- data/test/unit/lsa/all +10 -0
- data/test/unit/lsa/external_test.rb +218 -0
- data/test/unit/lsa/lsa_factory_test.rb +314 -0
- data/test/unit/lsa/lsa_test.rb +191 -0
- data/test/unit/lsa/network_test.rb +107 -0
- data/test/unit/lsa/router_test.rb +614 -0
- data/test/unit/lsa/summary_test.rb +135 -0
- data/test/unit/lsa/tlv/color_test.rb +39 -0
- data/test/unit/lsa/tlv/link_id_test.rb +14 -0
- data/test/unit/lsa/tlv/link_test.rb +413 -0
- data/test/unit/lsa/tlv/link_type_test.rb +16 -0
- data/test/unit/lsa/tlv/local_interface_test.rb +15 -0
- data/test/unit/lsa/tlv/maximum_bandwidth_test.rb +14 -0
- data/test/unit/lsa/tlv/maximum_reservable_bandwidth_test.rb +13 -0
- data/test/unit/lsa/tlv/remote_interface_test.rb +14 -0
- data/test/unit/lsa/tlv/router_address_test.rb +16 -0
- data/test/unit/lsa/tlv/tlv_factory_test.rb +89 -0
- data/test/unit/lsa/tlv/traffic_engineering_metric_test.rb +15 -0
- data/test/unit/lsa/traffic_engineering_test.rb +65 -0
- data/test/unit/neighbor/neighbor_test.rb +82 -0
- data/test/unit/packet/all +10 -0
- data/test/unit/packet/database_description_test.rb +114 -0
- data/test/unit/packet/hello_test.rb +107 -0
- data/test/unit/packet/link_state_ack_test.rb +64 -0
- data/test/unit/packet/link_state_request_test.rb +168 -0
- data/test/unit/packet/link_state_update_test.rb +62 -0
- data/test/unit/packet/ospf_packet_test.rb +91 -0
- metadata +106 -51
- data/lib/infra/to_s.rb +0 -38
- data/lib/lsa/lsa_base.rb +0 -430
- data/lib/lsa/opaque.rb +0 -143
@@ -0,0 +1,135 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "lsa/summary"
|
3
|
+
|
4
|
+
class TestLsaSummary < Test::Unit::TestCase
|
5
|
+
include OSPFv2
|
6
|
+
|
7
|
+
def setup
|
8
|
+
Summary.reset
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_new
|
12
|
+
h = {
|
13
|
+
:advertising_router=>"1.1.1.1",
|
14
|
+
:ls_id=>"10.0.0.0",
|
15
|
+
:metric =>1,
|
16
|
+
:netmask => "255.255.255.0"
|
17
|
+
}
|
18
|
+
summary = Summary.new h
|
19
|
+
assert_equal "000000030a0000000101010180000001f25d001cffffff0000000001", summary.to_shex
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_mt_metric
|
23
|
+
h = {
|
24
|
+
:advertising_router=>"1.1.1.1",
|
25
|
+
:ls_id=>"10.0.0.0",
|
26
|
+
:metric => 1,
|
27
|
+
:netmask => "255.255.255.0",
|
28
|
+
:mt_metrics => [{:id=>33, :metric=>20}, {:id=>34, :metric=>255}]
|
29
|
+
}
|
30
|
+
summary = Summary.new h
|
31
|
+
assert_equal("000000030a000000010101018000000188680024ffffff000000000121000014220000ff",summary.to_shex)
|
32
|
+
assert_equal summary.to_shex, Summary.new(summary.to_hash).to_shex
|
33
|
+
assert_equal summary.to_shex, Summary.new(summary).to_shex
|
34
|
+
h = summary.to_hash
|
35
|
+
assert_equal 0, h[:ls_age]
|
36
|
+
assert_equal '1.1.1.1', h[:advertising_router]
|
37
|
+
assert_equal '10.0.0.0', h[:ls_id]
|
38
|
+
assert_equal :summary, h[:ls_type]
|
39
|
+
assert_equal 0x80000001, h[:sequence_number]
|
40
|
+
assert_equal '255.255.255.0', h[:netmask]
|
41
|
+
assert_equal 0, h[:options]
|
42
|
+
assert_equal 33, h[:mt_metrics][0][:id]
|
43
|
+
assert_equal 20, h[:mt_metrics][0][:metric]
|
44
|
+
assert_equal 1, h[:metric]
|
45
|
+
s = Summary.new_ntop(summary.encode)
|
46
|
+
assert_equal summary.to_shex, s.to_shex
|
47
|
+
assert_match /Topology \(ID 33\) -> Metric: 20/, summary.to_s_junos_verbose
|
48
|
+
assert_match /Topology \(ID 34\) -> Metric: 255/, summary.to_s_junos_verbose
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_fix_hash
|
52
|
+
h1 = {
|
53
|
+
:advertising_router=>"1.1.1.1",
|
54
|
+
:ls_id=>"10.0.0.0",
|
55
|
+
:metric => 1,
|
56
|
+
:netmask => "255.255.255.0",
|
57
|
+
:mt_metrics => [{:id=>33, :metric=>20}, {:id=>34, :metric=>255}]
|
58
|
+
}
|
59
|
+
summary1 = Summary.new h1
|
60
|
+
h2 = {
|
61
|
+
:advertising_router=>"1.1.1.1",
|
62
|
+
:network=>"10.0.0.0/24",
|
63
|
+
:metric => 1,
|
64
|
+
:mt_metrics => [{:id=>33, :metric=>20}, {:id=>34, :metric=>255}]
|
65
|
+
}
|
66
|
+
summary2 = Summary.new h2
|
67
|
+
assert_equal(summary2.encode, summary1.encode)
|
68
|
+
assert summary1.summary?
|
69
|
+
|
70
|
+
# puts summary1.to_s_ios
|
71
|
+
# puts summary1.to_s_ios_verbose
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_count
|
76
|
+
Summary.new_lsdb
|
77
|
+
assert_equal "30.0.0.#{Summary.count}/24", Summary.network
|
78
|
+
Summary.new_lsdb
|
79
|
+
assert_equal 2, Summary.count
|
80
|
+
assert_equal "30.0.0.#{Summary.count}/24", Summary.network
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_new_lsdb
|
85
|
+
#FIXME: finish the work: what was the intent?
|
86
|
+
# puts Summary.new_lsdb :advertising_router=> 1, :metric => (Summary.count) +1
|
87
|
+
# puts Summary.new_lsdb :advertising_router=> 1, :metric => (Summary.count) +1
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
class TestLsaAsbrSummary < Test::Unit::TestCase
|
94
|
+
include OSPFv2
|
95
|
+
def test_asbr_new
|
96
|
+
asbr_summary = AsbrSummary.new(:advertising_router=>"1.1.1.1", :ls_id=>"1.1.1.1")
|
97
|
+
assert_equal("000000040101010101010101800000012f27001c0000000000000000",asbr_summary.to_shex)
|
98
|
+
assert_equal asbr_summary.to_shex, AsbrSummary.new(asbr_summary.to_hash).to_shex
|
99
|
+
assert_equal asbr_summary.to_shex, AsbrSummary.new(asbr_summary).to_shex
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
__END__
|
105
|
+
|
106
|
+
R1#show ip ospf database summary
|
107
|
+
|
108
|
+
OSPF Router with ID (1.1.1.1) (Process ID 1)
|
109
|
+
|
110
|
+
Summary Net Link States (Area 0)
|
111
|
+
|
112
|
+
Routing Bit Set on this LSA
|
113
|
+
LS age: 67
|
114
|
+
Options: (No TOS-capability, No DC, Upward)
|
115
|
+
LS Type: Summary Links(Network)
|
116
|
+
Link State ID: 30.0.1.0 (summary Network Number)
|
117
|
+
Advertising Router: 0.1.0.1
|
118
|
+
LS Seq Number: 80000001
|
119
|
+
Checksum: 0xE855
|
120
|
+
Length: 28
|
121
|
+
Network Mask: /24
|
122
|
+
TOS: 0 Metric: 0
|
123
|
+
|
124
|
+
Routing Bit Set on this LSA
|
125
|
+
LS age: 67
|
126
|
+
Options: (No TOS-capability, No DC, Upward)
|
127
|
+
LS Type: Summary Links(Network)
|
128
|
+
Link State ID: 30.0.2.0 (summary Network Number)
|
129
|
+
Advertising Router: 0.1.0.1
|
130
|
+
LS Seq Number: 80000001
|
131
|
+
Checksum: 0xDD5F
|
132
|
+
Length: 28
|
133
|
+
Network Mask: /24
|
134
|
+
TOS: 0 Metric: 0
|
135
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#TODO find spec for this TLV and rename it ?
|
2
|
+
# LSA #3
|
3
|
+
# Advertising Router 10.255.245.46, seq 0x8000001e, age 8s, length 104
|
4
|
+
# Area Local Opaque LSA (10), Opaque-Type Traffic Engineering LSA (1), Opaque-ID 5
|
5
|
+
# Options: [External, Demand Circuit]
|
6
|
+
# Link TLV (2), length: 100
|
7
|
+
# Link Type subTLV (1), length: 1, Point-to-point (1)
|
8
|
+
# Link ID subTLV (2), length: 4, 12.1.1.1 (0x0c010101)
|
9
|
+
# Local Interface IP address subTLV (3), length: 4, 192.168.208.88
|
10
|
+
# Remote Interface IP address subTLV (4), length: 4, 192.168.208.89
|
11
|
+
# Traffic Engineering Metric subTLV (5), length: 4, Metric 1
|
12
|
+
# Maximum Bandwidth subTLV (6), length: 4, 155.520 Mbps
|
13
|
+
# Maximum Reservable Bandwidth subTLV (7), length: 4, 155.520 Mbps
|
14
|
+
# Unreserved Bandwidth subTLV (8), length: 32
|
15
|
+
# TE-Class 0: 155.520 Mbps
|
16
|
+
# TE-Class 1: 155.520 Mbps
|
17
|
+
# TE-Class 2: 155.520 Mbps
|
18
|
+
# TE-Class 3: 155.520 Mbps
|
19
|
+
# TE-Class 4: 155.520 Mbps
|
20
|
+
# TE-Class 5: 155.520 Mbps
|
21
|
+
# TE-Class 6: 155.520 Mbps
|
22
|
+
# TE-Class 7: 155.520 Mbps
|
23
|
+
# Administrative Group subTLV (9), length: 4, 0x00000000
|
24
|
+
|
25
|
+
require "test/unit"
|
26
|
+
|
27
|
+
require "lsa/tlv/color"
|
28
|
+
|
29
|
+
class TestLsaTlvColor < Test::Unit::TestCase
|
30
|
+
include OSPFv2
|
31
|
+
def test_new
|
32
|
+
assert_equal("0009000400000000", Color_Tlv.new().to_shex)
|
33
|
+
assert_equal("OSPFv2::Color_Tlv: 254", Color_Tlv.new({:color=>254}).to_s)
|
34
|
+
assert_equal("00090004000000fe", Color_Tlv.new({:color=>254}).to_shex)
|
35
|
+
assert_equal(255, Color_Tlv.new({:color=>255}).to_hash[:color])
|
36
|
+
assert_equal("000900040000ffff", Color_Tlv.new(Color_Tlv.new({:color=>0xffff}).encode).to_shex)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
|
3
|
+
require "lsa/tlv/link_id"
|
4
|
+
|
5
|
+
class TestLsaTlvLinkId < Test::Unit::TestCase
|
6
|
+
include OSPFv2
|
7
|
+
def test_new
|
8
|
+
assert_equal("0002000400000000", LinkId_Tlv.new().to_shex)
|
9
|
+
assert_equal("Link ID : 1.1.1.1", LinkId_Tlv.new({:link_id=>"1.1.1.1"}).to_s)
|
10
|
+
assert_equal("1.1.1.1", LinkId_Tlv.new({:link_id=>"1.1.1.1"}).to_hash[:link_id])
|
11
|
+
assert_equal("0002000401010101", LinkId_Tlv.new({:link_id=>"1.1.1.1"}).to_shex)
|
12
|
+
assert_equal("0002000401010101", LinkId_Tlv.new(LinkId_Tlv.new({:link_id=>"1.1.1.1"}).encode).to_shex)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,413 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
|
3
|
+
require "lsa/tlv/link"
|
4
|
+
require 'lsa/tlv/tlv_factory'
|
5
|
+
|
6
|
+
class TestLsaTlvLink < Test::Unit::TestCase
|
7
|
+
include OSPFv2
|
8
|
+
def test_new
|
9
|
+
|
10
|
+
link_tlv = Link_Tlv.new
|
11
|
+
assert_equal('00020000', link_tlv.to_shex)
|
12
|
+
|
13
|
+
link_tlv << LinkType_Tlv.new
|
14
|
+
assert_equal('000200080001000101000000', link_tlv.to_shex)
|
15
|
+
|
16
|
+
link_tlv << LinkId_Tlv.new(:link_id=>'1.2.3.4')
|
17
|
+
assert_equal('0002001000010001010000000002000401020304', link_tlv.to_shex)
|
18
|
+
|
19
|
+
link_tlv << LocalInterfaceIpAddress_Tlv.new(:ip_address=>"1.1.1.1")
|
20
|
+
assert_equal('00020018000100010100000000020004010203040003000401010101', link_tlv.to_shex)
|
21
|
+
|
22
|
+
link_tlv << RemoteInterfaceIpAddress_Tlv.new(:ip_address=>"2.2.2.2")
|
23
|
+
assert_equal('000200200001000101000000000200040102030400030004010101010004000402020202', link_tlv.to_shex)
|
24
|
+
|
25
|
+
link_tlv << TrafficEngineeringMetric_Tlv.new(:te_metric=>255)
|
26
|
+
s = '0002002800010001010000000002000401020304'
|
27
|
+
s +='0003000401010101000400040202020200050004000000ff'
|
28
|
+
assert_equal(s, link_tlv.to_shex)
|
29
|
+
|
30
|
+
link_tlv << MaximumBandwidth_Tlv.new(:max_bw=>100_000_000)
|
31
|
+
s = '0002003000010001010000000002000401020304'
|
32
|
+
s += '0003000401010101000400040202020200050004000000ff'
|
33
|
+
s += '000600044b3ebc20'
|
34
|
+
assert_equal(s, link_tlv.to_shex)
|
35
|
+
|
36
|
+
link_tlv << MaximumReservableBandwidth_Tlv.new(:max_resv_bw=>100_000_000)
|
37
|
+
s = '000200380001000101000000'
|
38
|
+
s += '0002000401020304'
|
39
|
+
s += '0003000401010101'
|
40
|
+
s += '0004000402020202'
|
41
|
+
s += '00050004000000ff'
|
42
|
+
s += '000600044b3ebc20'
|
43
|
+
s += '000700044b3ebc20'
|
44
|
+
assert_equal(s, link_tlv.to_shex)
|
45
|
+
link_tlv << UnreservedBandwidth_Tlv.new(:unreserved_bw=>[100_000_000]*8)
|
46
|
+
s = '0002 005c
|
47
|
+
0001 0001 01 000000
|
48
|
+
0002 0004 01020304
|
49
|
+
0003 0004 01010101
|
50
|
+
0004 0004 02020202
|
51
|
+
0005 0004 000000ff
|
52
|
+
000600044b3ebc20
|
53
|
+
000700044b3ebc20
|
54
|
+
0008 0020 4b3ebc20 4b3ebc20 4b3ebc20 4b3ebc20 4b3ebc20 4b3ebc20 4b3ebc20 4b3ebc20'
|
55
|
+
assert_equal(s.split.join, link_tlv.to_shex)
|
56
|
+
|
57
|
+
puts link_tlv
|
58
|
+
end
|
59
|
+
def test_tlv_type_6
|
60
|
+
link_type = SubTlv.factory(['0006 0004 4b3e bc20'.split.join].pack('H*'))
|
61
|
+
assert_equal(MaximumBandwidth_Tlv,link_type.class)
|
62
|
+
assert_equal(100000000.0,link_type.max_bw)
|
63
|
+
assert_equal({:tlv_type=>6, :max_bw=>100000000},link_type.to_hash)
|
64
|
+
assert_equal('000600044b3ebc20', SubTlv.factory({:tlv_type=>6, :max_bw=>100_000_000.0}).to_shex)
|
65
|
+
assert_equal(MaximumBandwidth_Tlv,link_type.class)
|
66
|
+
assert_equal(100000000.0,link_type.max_bw)
|
67
|
+
end
|
68
|
+
def test_tlv_type_7
|
69
|
+
link_type = SubTlv.factory(['0007 0004 4b3e bc20'.split.join].pack('H*'))
|
70
|
+
assert_equal(MaximumReservableBandwidth_Tlv,link_type.class)
|
71
|
+
assert_equal('Maximum reservable bandwidth : 100000000',link_type.to_s)
|
72
|
+
assert_equal({:tlv_type=>7, :max_resv_bw=>100000000},link_type.to_hash)
|
73
|
+
assert_equal('000700044b3ebc20', SubTlv.factory({:tlv_type=>7, :max_resv_bw=>100000000}).to_shex)
|
74
|
+
|
75
|
+
|
76
|
+
assert_equal(100000000.0, link_type.max_resv_bw)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_tlv_type_8
|
80
|
+
link_type = SubTlv.factory(['0008 0020 4b3e bc20 4b3e bc20 4b3e bc20 4b3e bc20 4b3e bc20 4b3e bc20 4b3e bc20 4b3e bc20 '.split.join].pack('H*'))
|
81
|
+
assert_equal(100000000.0, link_type.unreserved_bw[0])
|
82
|
+
link_type = SubTlv.factory(['0008 0020 4b94 50c0
|
83
|
+
4b94 50c0 4b94 50c0 4b94 50c0 4b94 50c0
|
84
|
+
4b94 50c0 4b94 50c0 4b94 50c0 '.split.join].pack('H*'))
|
85
|
+
assert_equal(8,link_type.tlv_type)
|
86
|
+
assert_equal(UnreservedBandwidth_Tlv,link_type.class)
|
87
|
+
assert_equal(155520000.0, link_type.unreserved_bw[0])
|
88
|
+
assert_equal("Unreserved bandwidth : 155520000, 155520000, 155520000, 155520000, 155520000, 155520000, 155520000, 155520000", link_type.to_s)
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
__END__
|
95
|
+
|
96
|
+
|
97
|
+
__END__
|
98
|
+
|
99
|
+
|
100
|
+
TODO: to_s_ios
|
101
|
+
|
102
|
+
Type-10 Opaque Link Area Link States (Area 0)
|
103
|
+
|
104
|
+
Link ID ADV Router Age Seq# Checksum Opaque ID
|
105
|
+
1.0.0.0 0.0.0.3 23 0x80000001 0x000D12 0
|
106
|
+
1.0.0.255 0.0.0.1 23 0x80000001 0x00ACB1 255
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
R1#show ip ospf database opaque-area
|
112
|
+
|
113
|
+
OSPF Router with ID (1.1.1.1) (Process ID 1)
|
114
|
+
|
115
|
+
Type-10 Opaque Link Area Link States (Area 0)
|
116
|
+
|
117
|
+
LS age: 44
|
118
|
+
Options: (No TOS-capability, No DC)
|
119
|
+
LS Type: Opaque Area Link
|
120
|
+
Link State ID: 1.0.0.0
|
121
|
+
Opaque Type: 1
|
122
|
+
Opaque ID: 0
|
123
|
+
Advertising Router: 0.0.0.3
|
124
|
+
LS Seq Number: 80000001
|
125
|
+
Checksum: 0xD12
|
126
|
+
Length: 116
|
127
|
+
Fragment number : 0
|
128
|
+
|
129
|
+
Link connected to Point-to-Point network
|
130
|
+
Link ID : 5.6.7.8
|
131
|
+
Interface Address : 111.111.111.111
|
132
|
+
Neighbor Address : 222.222.222.222
|
133
|
+
Admin Metric : 255
|
134
|
+
Maximum bandwidth : 1250
|
135
|
+
Maximum reservable bandwidth : 875
|
136
|
+
Number of Priority : 8
|
137
|
+
Priority 0 : 12 Priority 1 : 12
|
138
|
+
Priority 2 : 12 Priority 3 : 12
|
139
|
+
Priority 4 : 12 Priority 5 : 12
|
140
|
+
Priority 6 : 12 Priority 7 : 12
|
141
|
+
|
142
|
+
Number of Links : 1
|
143
|
+
|
144
|
+
LS age: 45
|
145
|
+
Options: (No TOS-capability, No DC)
|
146
|
+
LS Type: Opaque Area Link
|
147
|
+
Link State ID: 1.0.0.255
|
148
|
+
Opaque Type: 1
|
149
|
+
Opaque ID: 255
|
150
|
+
Advertising Router: 0.0.0.1
|
151
|
+
LS Seq Number: 80000001
|
152
|
+
Checksum: 0xACB1
|
153
|
+
Length: 116
|
154
|
+
Fragment number : 255
|
155
|
+
|
156
|
+
Link connected to Point-to-Point network
|
157
|
+
Link ID : 1.2.3.4
|
158
|
+
Interface Address : 1.1.1.1
|
159
|
+
Neighbor Address : 2.2.2.2
|
160
|
+
Admin Metric : 255
|
161
|
+
Maximum bandwidth : 1250
|
162
|
+
Maximum reservable bandwidth : 875
|
163
|
+
Number of Priority : 8
|
164
|
+
Priority 0 : 12 Priority 1 : 12
|
165
|
+
Priority 2 : 12 Priority 3 : 12
|
166
|
+
Priority 4 : 12 Priority 5 : 12
|
167
|
+
Priority 4 : 12 Priority 5 : 12
|
168
|
+
Priority 6 : 12 Priority 7 : 12
|
169
|
+
|
170
|
+
Number of Links : 1
|
171
|
+
|
172
|
+
LS age: 45
|
173
|
+
Options: (No TOS-capability, No DC)
|
174
|
+
LS Type: Opaque Area Link
|
175
|
+
Link State ID: 1.0.0.255
|
176
|
+
Opaque Type: 1
|
177
|
+
Opaque ID: 255
|
178
|
+
Advertising Router: 0.0.0.1
|
179
|
+
LS Seq Number: 80000001
|
180
|
+
Checksum: 0xACB1
|
181
|
+
Length: 116
|
182
|
+
Fragment number : 255
|
183
|
+
|
184
|
+
Link connected to Point-to-Point network
|
185
|
+
Link ID : 1.2.3.4
|
186
|
+
Interface Address : 1.1.1.1
|
187
|
+
Neighbor Address : 2.2.2.2
|
188
|
+
Admin Metric : 255
|
189
|
+
Maximum bandwidth : 1250
|
190
|
+
Maximum reservable bandwidth : 875
|
191
|
+
Number of Priority : 8
|
192
|
+
Priority 0 : 12 Priority 1 : 12
|
193
|
+
Priority 2 : 12 Priority 3 : 12
|
194
|
+
Priority 4 : 12 Priority 5 : 12
|
195
|
+
Priority 6 : 12 Priority 7 : 12
|
196
|
+
|
197
|
+
Number of Links : 1
|
198
|
+
|
199
|
+
R1#
|
200
|
+
|
201
|
+
|
202
|
+
class LinkTLV_Test < Test::Unit::TestCase # :nodoc:
|
203
|
+
include Ospf
|
204
|
+
|
205
|
+
def setup
|
206
|
+
@link_tlv = LinkTLV.new()
|
207
|
+
link_type = LinkTypeSubTLV.new({:link_type=>1})
|
208
|
+
link_id = LinkID_SubTLV.new({:link_id=>'12.1.1.1'})
|
209
|
+
local_if_addr = LocalInterfaceIP_Address_SubTLV.new({:local_interface_ip_address => '192.168.208.86', })
|
210
|
+
rmt_if_addr = RemoteInterfaceIP_Address_SubTLV.new({:remote_interface_ip_address => '192.168.208.87', })
|
211
|
+
te_metric = TE_MetricSubTLV.new({:te_metric => 1, })
|
212
|
+
max_bw = MaximumBandwidth_SubTLV.new({:max_bw => 155.52*1000000, })
|
213
|
+
max_resv_bw = MaximumReservableBandwidth_SubTLV.new({:max_resv_bw => 155.52*1000000, })
|
214
|
+
unresv_bw = UnreservedBandwidth_SubTLV.new({:unreserved_bw => [155.52*1000000]*8, })
|
215
|
+
@link_tlv << link_type << link_id << local_if_addr << rmt_if_addr << te_metric << max_bw << max_resv_bw << unresv_bw
|
216
|
+
@te_lsa = TrafficEngineeringLSA.new({:advr=>'0.1.0.1',}) # default to area lstype 10
|
217
|
+
@te_lsa << @link_tlv
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_init
|
221
|
+
link_type = SubTLV_Factory.create({:tlv_type=>1, :link_type=>1})
|
222
|
+
link_id = SubTLV_Factory.create({:tlv_type=>2, :link_id=>"1.1.1.1"})
|
223
|
+
# type len type len va filler type len value
|
224
|
+
assert_equal("0002 0010 0001 0001 01 000000 0002 0004 01010101".split.join,
|
225
|
+
(LinkTLV.new() << link_type << link_id).to_shex)
|
226
|
+
link_type = SubTLV_Factory.create({:tlv_type=>1, :link_type=>1})
|
227
|
+
link_id = SubTLV_Factory.create({:tlv_type=>2, :link_id=>"1.1.1.1"})
|
228
|
+
rmt_ip = RemoteInterfaceIP_Address_SubTLV.new({:remote_interface_ip_address=>"1.1.1.1"})
|
229
|
+
l = LinkTLV.new()
|
230
|
+
l << link_type
|
231
|
+
l << link_id
|
232
|
+
l = LinkTLV.new() << link_type << link_id << rmt_ip
|
233
|
+
l.to_shex
|
234
|
+
l.to_hash
|
235
|
+
l1 = LinkTLV.new(l.enc)
|
236
|
+
assert_equal(1,l1.tlvs[0].to_hash[:link_type])
|
237
|
+
assert_equal(l1.to_shex, l.to_shex)
|
238
|
+
end
|
239
|
+
def test_tlv_type_1
|
240
|
+
link_type = SubTLV_Factory.create(['0001000101000000'].pack('H*'))
|
241
|
+
assert_equal(LinkTypeSubTLV,link_type.class)
|
242
|
+
end
|
243
|
+
def test_tlv_type_2
|
244
|
+
link_type = SubTLV_Factory.create(['000200040afff530'].pack('H*'))
|
245
|
+
assert_equal(LinkID_SubTLV,link_type.class)
|
246
|
+
end
|
247
|
+
def test_tlv_type_3
|
248
|
+
link_type = SubTLV_Factory.create(['0003 0004 c0a8 a431'.split.join].pack('H*'))
|
249
|
+
assert_equal(LocalInterfaceIP_Address_SubTLV,link_type.class)
|
250
|
+
assert_match(/192\.168\.164\.49/, link_type.to_s)
|
251
|
+
end
|
252
|
+
def test_tlv_type_4
|
253
|
+
link_type = SubTLV_Factory.create(['0004 0004 c0a8 a430'.split.join].pack('H*'))
|
254
|
+
assert_equal(RemoteInterfaceIP_Address_SubTLV,link_type.class)
|
255
|
+
end
|
256
|
+
def test_tlv_type_5
|
257
|
+
link_type = SubTLV_Factory.create(['0005 0004 0000 0001'.split.join].pack('H*'))
|
258
|
+
assert_equal(TE_MetricSubTLV,link_type.class)
|
259
|
+
end
|
260
|
+
def test_tlv_type_6
|
261
|
+
link_type = SubTLV_Factory.create(['0006 0004 4b3e bc20'.split.join].pack('H*'))
|
262
|
+
assert_equal(MaximumBandwidth_SubTLV,link_type.class)
|
263
|
+
assert_equal(100000000.0,link_type.max_bw)
|
264
|
+
assert_equal({:tlv_type=>6, :max_bw=>100000000.0},link_type.to_hash)
|
265
|
+
assert_equal('000600044b3ebc20', SubTLV_Factory.create({:tlv_type=>6, :max_bw=>100000000.0}).to_shex)
|
266
|
+
assert_equal(MaximumBandwidth_SubTLV,link_type.class)
|
267
|
+
assert_equal(100000000.0,link_type.max_bw)
|
268
|
+
end
|
269
|
+
def test_tlv_type_7
|
270
|
+
link_type = SubTLV_Factory.create(['0007 0004 4b3e bc20'.split.join].pack('H*'))
|
271
|
+
assert_equal(MaximumReservableBandwidth_SubTLV,link_type.class)
|
272
|
+
assert_equal(100000000.0, link_type.max_resv_bw)
|
273
|
+
|
274
|
+
end
|
275
|
+
def test_tlv_type_8
|
276
|
+
link_type = SubTLV_Factory.create(['0008 0020 4b3e bc20 4b3e bc20 4b3e bc20 4b3e bc20 4b3e bc20 4b3e bc20 4b3e bc20 4b3e bc20 '.split.join].pack('H*'))
|
277
|
+
assert_equal(100000000.0, link_type.unreserved_bw[0])
|
278
|
+
link_type = SubTLV_Factory.create(['0008 0020 4b94 50c0
|
279
|
+
4b94 50c0 4b94 50c0 4b94 50c0 4b94 50c0
|
280
|
+
4b94 50c0 4b94 50c0 4b94 50c0 '.split.join].pack('H*'))
|
281
|
+
assert_equal(UnreservedBandwidth_SubTLV,link_type.class)
|
282
|
+
assert_equal(155520000.0, link_type.unreserved_bw[0])
|
283
|
+
assert_equal("Ospf::UnreservedBandwidth_SubTLV: 155520000.0, 155520000.0, 155520000.0, 155520000.0, 155520000.0, 155520000.0, 155520000.0, 155520000.0", link_type.to_s)
|
284
|
+
end
|
285
|
+
def test_tlv_type_9
|
286
|
+
stlv = SubTLV_Factory.create(['0009 0004 0000 0001'.split.join].pack('H*'))
|
287
|
+
assert_equal(Color_SubTLV,stlv.class)
|
288
|
+
assert_equal(1,stlv.color)
|
289
|
+
end
|
290
|
+
def test_link_tlv_has?
|
291
|
+
assert_equal(8, @link_tlv.has?.size)
|
292
|
+
assert_equal(LinkTypeSubTLV,@link_tlv.has?[0])
|
293
|
+
assert_equal(true, @link_tlv.has?(LinkTypeSubTLV))
|
294
|
+
end
|
295
|
+
def test_link_tlv_index
|
296
|
+
assert_equal(LinkTypeSubTLV, @link_tlv[LinkTypeSubTLV].class)
|
297
|
+
assert_equal(LinkTypeSubTLV, @link_tlv.find(LinkTypeSubTLV).class)
|
298
|
+
assert_equal(['192.168.208.87'], @link_tlv[RemoteInterfaceIP_Address_SubTLV].remote_interface_ip_address)
|
299
|
+
end
|
300
|
+
def test_link_tlv_replace
|
301
|
+
rmt_ip = RemoteInterfaceIP_Address_SubTLV.new({:remote_interface_ip_address=>"1.1.1.1"})
|
302
|
+
@link_tlv.replace(rmt_ip)
|
303
|
+
assert_equal(['1.1.1.1'], @link_tlv[RemoteInterfaceIP_Address_SubTLV].remote_interface_ip_address)
|
304
|
+
end
|
305
|
+
def test_link_tlv_remove
|
306
|
+
@link_tlv.remove(RemoteInterfaceIP_Address_SubTLV)
|
307
|
+
assert_nil(@link_tlv[RemoteInterfaceIP_Address_SubTLV])
|
308
|
+
end
|
309
|
+
|
310
|
+
def test_link_tlv_create
|
311
|
+
h={}
|
312
|
+
h.store(:link_type,1)
|
313
|
+
h.store(:link_id,'1.1.1.1')
|
314
|
+
h.store(:local_interface_ip_address,'1.2.3.4')
|
315
|
+
h.store(:remote_interface_ip_address,'5.6.7.8')
|
316
|
+
h.store(:te_metric,10)
|
317
|
+
h.store(:max_bw,1.0*10**9)
|
318
|
+
h.store(:max_resv_bw,1.0*10**9)
|
319
|
+
h.store(:unreserved_bw,[1.0*10**9]*8)
|
320
|
+
link_tlv = Ospf::LinkTLV.create(h)
|
321
|
+
assert_equal(1,link_tlv[LinkTypeSubTLV].link_type)
|
322
|
+
assert_equal('1.1.1.1',link_tlv[LinkID_SubTLV ].link_id)
|
323
|
+
assert_equal(['1.2.3.4'],link_tlv[LocalInterfaceIP_Address_SubTLV].local_interface_ip_address)
|
324
|
+
assert_equal(['5.6.7.8'],link_tlv[RemoteInterfaceIP_Address_SubTLV].remote_interface_ip_address)
|
325
|
+
assert_equal(10,link_tlv[TE_MetricSubTLV].te_metric)
|
326
|
+
assert_equal(1000000000.0,link_tlv[MaximumBandwidth_SubTLV].max_bw)
|
327
|
+
assert_equal(1000000000.0,link_tlv[MaximumReservableBandwidth_SubTLV].max_resv_bw)
|
328
|
+
assert_equal([1000000000.0]*8,link_tlv[UnreservedBandwidth_SubTLV].unreserved_bw)
|
329
|
+
end
|
330
|
+
|
331
|
+
def test_te_lsa_2
|
332
|
+
|
333
|
+
##### LSA #3
|
334
|
+
##### Advertising Router 10.255.245.46, seq 0x8000001e, age 8s, length 104
|
335
|
+
##### Area Local Opaque LSA (10), Opaque-Type Traffic Engineering LSA (1), Opaque-ID 5
|
336
|
+
##### Options: [External, Demand Circuit]
|
337
|
+
##### Link TLV (2), length: 100
|
338
|
+
##### Link Type subTLV (1), length: 1, Point-to-point (1)
|
339
|
+
##### Link ID subTLV (2), length: 4, 12.1.1.1 (0x0c010101)
|
340
|
+
##### Local Interface IP address subTLV (3), length: 4, 192.168.208.88
|
341
|
+
##### Remote Interface IP address subTLV (4), length: 4, 192.168.208.89
|
342
|
+
##### Traffic Engineering Metric subTLV (5), length: 4, Metric 1
|
343
|
+
##### Maximum Bandwidth subTLV (6), length: 4, 155.520 Mbps
|
344
|
+
##### Maximum Reservable Bandwidth subTLV (7), length: 4, 155.520 Mbps
|
345
|
+
##### Unreserved Bandwidth subTLV (8), length: 32
|
346
|
+
##### TE-Class 0: 155.520 Mbps
|
347
|
+
##### TE-Class 1: 155.520 Mbps
|
348
|
+
##### TE-Class 2: 155.520 Mbps
|
349
|
+
##### TE-Class 3: 155.520 Mbps
|
350
|
+
##### TE-Class 4: 155.520 Mbps
|
351
|
+
##### TE-Class 5: 155.520 Mbps
|
352
|
+
##### TE-Class 6: 155.520 Mbps
|
353
|
+
##### TE-Class 7: 155.520 Mbps
|
354
|
+
##### Administrative Group subTLV (9), length: 4, 0x00000000
|
355
|
+
##### 0200 0000 45c0 01b0 d0ff 0000 0159 7520
|
356
|
+
##### c0a8 d067 e000 0005 0204 019c 0aff f531
|
357
|
+
##### 0000 0000 2dde 0000 0000 0000 0000 0000
|
358
|
+
##### 0000 0003 000a 2202 c0a8 a42f 0c01 0101
|
359
|
+
##### 8000 0eba b7e3 0020 ffff fc00 0c01 0101
|
360
|
+
##### 7c01 0001 000a 2201 0c01 0101 0c01 0101
|
361
|
+
##### 8000 3313 0ed3 00e4 0000 0011 c0a8 d043
|
362
|
+
##### c0a8 d044 0200 0001 c0a8 a42f c0a8 a42f
|
363
|
+
##### 0200 0001 0c01 0101 ffff ffff 0300 0000
|
364
|
+
##### 0aff f52f ffff ffff 0300 0000 7c01 0101
|
365
|
+
##### 7c01 0002 0200 0001 7c01 0201 7c01 0003
|
366
|
+
##### 0200 0001 0a01 0000 ffff 0000 0300 0001
|
367
|
+
##### 0a01 0000 ffff 0000 0300 0001 0a02 0000
|
368
|
+
##### ffff 0000 0300 0001 0a01 0000 ffff 0000
|
369
|
+
##### 0300 0001 0a02 0000 ffff 0000 0300 0001
|
370
|
+
##### 0aff f52e c0a8 d05b 0100 0001 c0a8 d05a
|
371
|
+
##### ffff fffe 0300 0001 0aff f52e c0a8 d059
|
372
|
+
##### 0100 0001 c0a8 d058 ffff fffe 0300 0001
|
373
|
+
##### 0aff f52e c0a8 d057 0100 0001 c0a8 d056
|
374
|
+
##### ffff fffe 0300 0001 0008 220a 0100 0005
|
375
|
+
##### 0aff f52e 8000 001e d240 007c 0002 0064
|
376
|
+
##### 0001 0001 0100 0000 0002 0004 0c01 0101
|
377
|
+
##### 0003 0004 c0a8 d058 0004 0004 c0a8 d059
|
378
|
+
##### 0005 0004 0000 0001 0006 0004 4b94 50c0
|
379
|
+
##### 0007 0004 4b94 50c0 0008 0020 4b94 50c0
|
380
|
+
##### 4b94 50c0 4b94 50c0 4b94 50c0 4b94 50c0
|
381
|
+
##### 4b94 50c0 4b94 50c0 4b94 50c0 0009 0004
|
382
|
+
##### 0000 0000
|
383
|
+
|
384
|
+
te_lsa_shex = %{
|
385
|
+
0008 220a 0100 0005
|
386
|
+
0aff f52e 8000 001e d240 007c 0002 0064
|
387
|
+
0001 0001 0100 0000 0002 0004 0c01 0101
|
388
|
+
0003 0004 c0a8 d058 0004 0004 c0a8 d059
|
389
|
+
0005 0004 0000 0001 0006 0004 4b94 50c0
|
390
|
+
0007 0004 4b94 50c0 0008 0020 4b94 50c0
|
391
|
+
4b94 50c0 4b94 50c0 4b94 50c0 4b94 50c0
|
392
|
+
4b94 50c0 4b94 50c0 4b94 50c0 0009 0004
|
393
|
+
0000 0000
|
394
|
+
}.split.join
|
395
|
+
|
396
|
+
link_tlv = LinkTLV.new()
|
397
|
+
link_type = LinkTypeSubTLV.new({:link_type=>1})
|
398
|
+
link_id = LinkID_SubTLV.new({:link_id=>'12.1.1.1'})
|
399
|
+
local_if_addr = LocalInterfaceIP_Address_SubTLV.new({:local_interface_ip_address => '192.168.208.88', })
|
400
|
+
rmt_if_addr = RemoteInterfaceIP_Address_SubTLV.new({:remote_interface_ip_address => '192.168.208.89', })
|
401
|
+
te_metric = TE_MetricSubTLV.new({:te_metric => 1, })
|
402
|
+
max_bw = MaximumBandwidth_SubTLV.new({:max_bw => 155.52*1000000, })
|
403
|
+
max_resv_bw = MaximumReservableBandwidth_SubTLV.new({:max_resv_bw => 155.52*1000000, })
|
404
|
+
unresv_bw = UnreservedBandwidth_SubTLV.new({:unreserved_bw => [155.52*1000000]*8, })
|
405
|
+
color = Color_SubTLV.new({:color=>0})
|
406
|
+
link_tlv << link_type << link_id << local_if_addr << rmt_if_addr << te_metric << max_bw << max_resv_bw << unresv_bw << color
|
407
|
+
te_lsa = TrafficEngineeringLSA.new({:advr=>'10.255.245.46',:lsage=>8, :options => 0x22, :seqn=> 0x8000001e, :opaque_id => 5, }) # default to area lstype 10
|
408
|
+
te_lsa << link_tlv
|
409
|
+
assert_equal(te_lsa_shex, te_lsa.to_shex)
|
410
|
+
#puts te_lsa.to_s_junos_style
|
411
|
+
#puts te_lsa
|
412
|
+
|
413
|
+
end
|