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,16 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
|
3
|
+
require "lsa/tlv/link_type"
|
4
|
+
|
5
|
+
class TestLsaTlvLinkType < Test::Unit::TestCase
|
6
|
+
include OSPFv2
|
7
|
+
def test_new
|
8
|
+
assert_equal("0001000101000000", LinkType_Tlv.new().to_shex)
|
9
|
+
assert_equal("Link Type : p2p", LinkType_Tlv.new({:link_type=>1}).to_s)
|
10
|
+
assert_equal("Link Type : multiaccess", LinkType_Tlv.new({:link_type=>2}).to_s)
|
11
|
+
assert_equal(1, LinkType_Tlv.new({:link_type=>1}).to_hash[:link_type])
|
12
|
+
assert_equal("0001000101000000", LinkType_Tlv.new({:link_type=>1}).to_shex)
|
13
|
+
assert_equal("0001000101000000", LinkType_Tlv.new(LinkType_Tlv.new({:link_type=>1}).encode).to_shex)
|
14
|
+
assert_equal(true, LinkType_Tlv.new({:link_type=>1}).kind_of?(SubTlv))
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
|
3
|
+
require "lsa/tlv/local_interface"
|
4
|
+
|
5
|
+
class TestTlvLsaLocalInterface < Test::Unit::TestCase
|
6
|
+
include OSPFv2
|
7
|
+
def test_new
|
8
|
+
assert_equal("0003000400000000", LocalInterfaceIpAddress_Tlv.new().to_shex)
|
9
|
+
assert_equal("Interface Address : 1.1.1.1", LocalInterfaceIpAddress_Tlv.new({:ip_address=>"1.1.1.1"}).to_s)
|
10
|
+
assert_equal("1.1.1.1", LocalInterfaceIpAddress_Tlv.new({:ip_address=>"1.1.1.1"}).to_hash[:ip_address])
|
11
|
+
assert_equal("0003000401010101", LocalInterfaceIpAddress_Tlv.new({:ip_address=>"1.1.1.1"}).to_shex)
|
12
|
+
assert_equal("0003000401010101", LocalInterfaceIpAddress_Tlv.new(LocalInterfaceIpAddress_Tlv.new({:ip_address=>"1.1.1.1"}).encode).to_shex)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
|
3
|
+
require "lsa/tlv/maximum_bandwidth"
|
4
|
+
|
5
|
+
class TestLsaTlvMaximumBandwidth < Test::Unit::TestCase
|
6
|
+
include OSPFv2
|
7
|
+
def test_case_name
|
8
|
+
assert_equal("0006000400000000", MaximumBandwidth_Tlv.new().to_shex)
|
9
|
+
assert_equal("Maximum bandwidth : 10000", MaximumBandwidth_Tlv.new( :max_bw=>10_000.0 ).to_s)
|
10
|
+
assert_equal("00060004449c4000", MaximumBandwidth_Tlv.new( :max_bw=>10_000.0 ).to_shex)
|
11
|
+
assert_equal(10000, MaximumBandwidth_Tlv.new( :max_bw=>10_000.0 ).to_hash[:max_bw])
|
12
|
+
assert_equal("00060004449c4000", MaximumBandwidth_Tlv.new(['00060004449c4000'].pack('H*')).to_shex)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
|
3
|
+
require "lsa/tlv/maximum_reservable_bandwidth"
|
4
|
+
|
5
|
+
class TestLsaTlvMaximumReservableBandwitdh < Test::Unit::TestCase
|
6
|
+
include OSPFv2
|
7
|
+
def test_new
|
8
|
+
assert_equal("0007000400000000", MaximumReservableBandwidth_Tlv.new().to_shex)
|
9
|
+
assert_equal("Maximum reservable bandwidth : 10000", MaximumReservableBandwidth_Tlv.new({:max_resv_bw=>10_000}).to_s)
|
10
|
+
assert_equal(255, MaximumReservableBandwidth_Tlv.new({:max_resv_bw=>255}).to_hash[:max_resv_bw])
|
11
|
+
assert_equal("0007000445ffff00", MaximumReservableBandwidth_Tlv.new({:max_resv_bw=>0xffff}).to_shex)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
|
3
|
+
require "lsa/tlv/remote_interface"
|
4
|
+
|
5
|
+
class TestLsaTlvRemoteInterface < Test::Unit::TestCase
|
6
|
+
include OSPFv2
|
7
|
+
def test_new
|
8
|
+
assert_equal("0004000400000000", RemoteInterfaceIpAddress_Tlv.new().to_shex)
|
9
|
+
assert_equal("Neighbor Address : 1.1.1.1", RemoteInterfaceIpAddress_Tlv.new({:ip_address=>"1.1.1.1"}).to_s)
|
10
|
+
assert_equal("1.1.1.1", RemoteInterfaceIpAddress_Tlv.new({:ip_address=>"1.1.1.1"}).to_hash[:ip_address])
|
11
|
+
assert_equal("0004000401010101", RemoteInterfaceIpAddress_Tlv.new({:ip_address=>"1.1.1.1"}).to_shex)
|
12
|
+
assert_equal("0004000401010101", RemoteInterfaceIpAddress_Tlv.new(RemoteInterfaceIpAddress_Tlv.new({:ip_address=>"1.1.1.1"}).encode).to_shex)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
|
3
|
+
require "lsa/tlv/router_address"
|
4
|
+
|
5
|
+
class TestLsaTlvRouterAddress < Test::Unit::TestCase
|
6
|
+
include OSPFv2
|
7
|
+
def test_new
|
8
|
+
assert_equal("0001000400000000", RouterAddress_Tlv.new().to_shex)
|
9
|
+
assert_equal("RouterID TLV: 1.1.1.1", RouterAddress_Tlv.new(:ip_address=>"1.1.1.1").to_s)
|
10
|
+
assert_equal("1.1.1.1", RouterAddress_Tlv.new(:ip_address=>"1.1.1.1").to_hash[:ip_address])
|
11
|
+
assert_equal("0001000401010101", RouterAddress_Tlv.new(:ip_address=>"1.1.1.1").to_shex)
|
12
|
+
assert_equal("0001000401010101", RouterAddress_Tlv.new(RouterAddress_Tlv.new(:ip_address=>"1.1.1.1").encode).to_shex)
|
13
|
+
assert_equal(true, RouterAddress_Tlv.new(:ip_address=>"1.1.1.1").is_a?(Tlv))
|
14
|
+
assert_equal(1, RouterAddress_Tlv.new(:ip_address=>"1.1.1.1").tlv_type)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
|
3
|
+
require "lsa/tlv/tlv_factory"
|
4
|
+
|
5
|
+
class TestLsaTlvTlvFactory < Test::Unit::TestCase
|
6
|
+
include OSPFv2
|
7
|
+
def test_router_address
|
8
|
+
h = {:tlv_type=>1, :ip_address=>"1.1.1.1"}
|
9
|
+
tlv = Tlv.factory(h)
|
10
|
+
assert_equal(h, tlv.to_hash)
|
11
|
+
assert_equal(h, Tlv.factory(tlv.to_hash).to_hash)
|
12
|
+
end
|
13
|
+
def test_link
|
14
|
+
h = {
|
15
|
+
:tlv_type=>2,
|
16
|
+
:tlvs=> [
|
17
|
+
{:tlv_type=>1, :link_type=>1},
|
18
|
+
{:tlv_type=>2, :link_id=>"1.2.3.4"},
|
19
|
+
{:tlv_type=>3, :ip_address=>"1.1.1.1"},
|
20
|
+
{:tlv_type=>4, :ip_address=>"2.2.2.2"},
|
21
|
+
{:tlv_type=>5, :te_metric=>255},
|
22
|
+
{:max_bw=>10000, :tlv_type=>6},
|
23
|
+
{:tlv_type=>7, :max_resv_bw=>0.0},
|
24
|
+
{:tlv_type=>8, :unreserved_bw=>[100, 100, 100, 100, 100, 100, 100, 100]}
|
25
|
+
]}
|
26
|
+
tlv = Tlv.factory(h)
|
27
|
+
assert_equal(h, tlv.to_hash)
|
28
|
+
assert_equal(h, Tlv.factory(tlv.to_hash).to_hash)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
class TestSubTlvFactory < Test::Unit::TestCase
|
34
|
+
include OSPFv2
|
35
|
+
def test_link_type_sub_tlv
|
36
|
+
s = ['0001000101000000'].pack('H*')
|
37
|
+
tlv = SubTlv.factory(s)
|
38
|
+
assert_equal(LinkType_Tlv, tlv.class)
|
39
|
+
assert_equal(s, tlv.encode)
|
40
|
+
tlv = SubTlv.factory(:tlv_type=>1, :link_type=>1)
|
41
|
+
assert_equal(LinkType_Tlv, tlv.class)
|
42
|
+
assert_equal({:link_type=>1, :tlv_type=>1}, tlv.to_hash)
|
43
|
+
assert_equal('0001000101000000', tlv.to_shex)
|
44
|
+
end
|
45
|
+
def test_link_id_sub_tlv
|
46
|
+
s = ['0002000401020304'].pack('H*')
|
47
|
+
tlv = SubTlv.factory(s)
|
48
|
+
assert_equal(LinkId_Tlv, tlv.class)
|
49
|
+
assert_equal(s, tlv.encode)
|
50
|
+
end
|
51
|
+
def test_local_interface_sub_tlv
|
52
|
+
s = ['0003000401020304'].pack('H*')
|
53
|
+
tlv = SubTlv.factory(s)
|
54
|
+
assert_equal(LocalInterfaceIpAddress_Tlv, tlv.class)
|
55
|
+
assert_equal(s, tlv.encode)
|
56
|
+
end
|
57
|
+
def test_remote_interface_sub_tlv
|
58
|
+
s = ['0004000401020304'].pack('H*')
|
59
|
+
tlv = SubTlv.factory(s)
|
60
|
+
assert_equal(RemoteInterfaceIpAddress_Tlv, tlv.class)
|
61
|
+
assert_equal(s, tlv.encode)
|
62
|
+
end
|
63
|
+
def test_te_metric_sub_tlv
|
64
|
+
s = ['0005000400000064'].pack('H*')
|
65
|
+
tlv = SubTlv.factory(s)
|
66
|
+
assert_equal(TrafficEngineeringMetric_Tlv, tlv.class)
|
67
|
+
assert_equal(s, tlv.encode)
|
68
|
+
end
|
69
|
+
def test_max_bw_sub_tlv
|
70
|
+
s = ['000600043f800000'].pack('H*')
|
71
|
+
tlv = SubTlv.factory(s)
|
72
|
+
assert_equal(MaximumBandwidth_Tlv, tlv.class)
|
73
|
+
assert_equal(s, tlv.encode)
|
74
|
+
end
|
75
|
+
def test_max_reserv_bw_sub_tlv
|
76
|
+
s = ['000700043f800000'].pack('H*')
|
77
|
+
tlv = SubTlv.factory(s)
|
78
|
+
assert_equal(MaximumReservableBandwidth_Tlv, tlv.class)
|
79
|
+
assert_equal(s, tlv.encode)
|
80
|
+
end
|
81
|
+
def test_unreserv_bw_sub_tlv
|
82
|
+
s = ['000800203e0000003e8000003ec000003f0000003f2000003f4000003f6000003f800000'].pack('H*')
|
83
|
+
tlv = SubTlv.factory(s)
|
84
|
+
assert_equal(UnreservedBandwidth_Tlv, tlv.class)
|
85
|
+
assert_equal(s, tlv.encode)
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
|
3
|
+
require "lsa/tlv/traffic_engineering_metric"
|
4
|
+
|
5
|
+
class TestLsaTlvTrafficEngineeringMetric < Test::Unit::TestCase
|
6
|
+
include OSPFv2
|
7
|
+
def test_test
|
8
|
+
assert_equal("0005000400000000", TrafficEngineeringMetric_Tlv.new().to_shex)
|
9
|
+
assert_equal("Admin Metric : 254", TrafficEngineeringMetric_Tlv.new({:te_metric=>254}).to_s)
|
10
|
+
assert_equal(255, TrafficEngineeringMetric_Tlv.new({:te_metric=>255}).to_hash[:te_metric])
|
11
|
+
assert_equal("000500040000ffff", TrafficEngineeringMetric_Tlv.new(TrafficEngineeringMetric_Tlv.new({:te_metric=>0xffff}).encode).to_shex)
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
|
3
|
+
require "lsa/traffic_engineering"
|
4
|
+
require 'lsa/tlv/tlv_factory'
|
5
|
+
|
6
|
+
class TestLsaTlvTrafficEngineering < Test::Unit::TestCase
|
7
|
+
include OSPFv2
|
8
|
+
def test_new_from_hash
|
9
|
+
h_lsa = {:ls_age=>0,
|
10
|
+
:ls_type=>:area,
|
11
|
+
:advertising_router=>"0.0.0.0",
|
12
|
+
:sequence_number=>2147483649,
|
13
|
+
:opaque_id=>0,
|
14
|
+
:opaque_type=>:te_lsa,
|
15
|
+
:top_lvl_tlv=>
|
16
|
+
{:tlv_type=>2,
|
17
|
+
:tlvs=>
|
18
|
+
[{:tlv_type=>1, :link_type=>1},
|
19
|
+
{:tlv_type=>2, :link_id=>"1.2.3.4"},
|
20
|
+
{:ip_address=>"1.1.1.1", :tlv_type=>3},
|
21
|
+
{:ip_address=>"2.2.2.2", :tlv_type=>4},
|
22
|
+
{:tlv_type=>5, :te_metric=>255},
|
23
|
+
{:max_bw=>10000, :tlv_type=>6},
|
24
|
+
{:tlv_type=>7, :max_resv_bw=>7000},
|
25
|
+
{:tlv_type=>8,
|
26
|
+
:unreserved_bw=>[100, 100, 100, 100, 100, 100, 100, 100]}]},
|
27
|
+
:options=>0}
|
28
|
+
lsa = TrafficEngineering.new_hash(h_lsa)
|
29
|
+
assert_equal OSPFv2::TrafficEngineering, lsa.class
|
30
|
+
assert_equal h_lsa, lsa.to_hash
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_new_link_tlv
|
34
|
+
link_tlv = Link_Tlv.new
|
35
|
+
|
36
|
+
lsa = TrafficEngineering.new :advertising_router=>1, :opaque_id=>0xff, :top_lvl_tlv=> link_tlv
|
37
|
+
assert_equal('0000000a010000ff00000001800000011444001800020000', lsa.to_shex)
|
38
|
+
|
39
|
+
link_tlv << LinkType_Tlv.new
|
40
|
+
assert_equal('0000000a010000ff000000018000000171d30020000200080001000101000000', lsa.to_shex)
|
41
|
+
link_tlv << LinkId_Tlv.new(:link_id=>'1.2.3.4')
|
42
|
+
assert_equal('0000000a010000ff0000000180000001ec3800280002001000010001010000000002000401020304', lsa.to_shex)
|
43
|
+
link_tlv << LocalInterfaceIpAddress_Tlv.new(:ip_address=>"1.1.1.1")
|
44
|
+
assert_equal('0000000a010000ff000000018000000150b9003000020018000100010100000000020004010203040003000401010101', lsa.to_shex)
|
45
|
+
link_tlv << RemoteInterfaceIpAddress_Tlv.new(:ip_address=>"2.2.2.2")
|
46
|
+
link_tlv << TrafficEngineeringMetric_Tlv.new(:te_metric=>255)
|
47
|
+
link_tlv << MaximumBandwidth_Tlv.new(:max_bw=>10_000)
|
48
|
+
link_tlv << MaximumReservableBandwidth_Tlv.new(:max_resv_bw=>7_000)
|
49
|
+
link_tlv << UnreservedBandwidth_Tlv.new(:unreserved_bw=>[100]*8)
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_new_router_address_tlv
|
54
|
+
router_address = RouterAddress_Tlv.new(:ip_address=>'1.2.3.4')
|
55
|
+
lsa = TrafficEngineering.new :advertising_router=>1, :opaque_id=>0xff, :top_lvl_tlv=> router_address
|
56
|
+
assert_equal('0000000a010000ff00000001800000018abc001c0001000401020304', lsa.to_shex)
|
57
|
+
|
58
|
+
lsa = TrafficEngineering.new :advertising_router=>'255.255.255.255',
|
59
|
+
:opaque_id=>0xdeadff,
|
60
|
+
:top_lvl_tlv=> { :tlv_type=> 1, :ip_address=> '10.11.12.13'}
|
61
|
+
assert_equal('0000000a01deadffffffffff80000001dabc001c000100040a0b0c0d', lsa.to_shex)
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require 'lsa/router'
|
3
|
+
|
4
|
+
require "neighbor/neighbor"
|
5
|
+
|
6
|
+
class TestNeighborNeighbor < Test::Unit::TestCase
|
7
|
+
include OSPFv2
|
8
|
+
def test_states
|
9
|
+
assert Neighbor.new
|
10
|
+
assert_equal :down, Neighbor.new.state
|
11
|
+
assert Neighbor.new.in_state?(:down)
|
12
|
+
assert ! Neighbor.new.in_state?(:full)
|
13
|
+
assert Neighbor.new.in_state?(:full, :down)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_flood
|
17
|
+
|
18
|
+
neighbor = Neighbor.new
|
19
|
+
def neighbor.send(packet,dest)
|
20
|
+
ret=[]
|
21
|
+
[packet].flatten.each { |p|
|
22
|
+
ret << [p.class,dest]
|
23
|
+
}
|
24
|
+
ret
|
25
|
+
end
|
26
|
+
assert_equal [[String, "dest"]], neighbor.send( 'a packet', 'dest')
|
27
|
+
assert_equal [[String, 'dest'], [String, 'dest']], neighbor.send( ['one','two'], 'dest')
|
28
|
+
|
29
|
+
lsas = []
|
30
|
+
lsas << Router.new
|
31
|
+
lsas << Router.new
|
32
|
+
|
33
|
+
assert_equal 1, neighbor.flood(:lsas =>lsas).size
|
34
|
+
assert_equal [OSPFv2::LinkStateUpdate, "224.0.0.5"], neighbor.flood(:lsas =>lsas)[0]
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
__END__
|
40
|
+
|
41
|
+
|
42
|
+
TODO:
|
43
|
+
|
44
|
+
require 'test/unit'
|
45
|
+
require 'ospfv2/neighbor'
|
46
|
+
|
47
|
+
class TestOspfv2Neighbor < Test::Unit::TestCase # :nodoc:
|
48
|
+
def test_init
|
49
|
+
neighbor = OSPFv2::Neighbor.new("1.1.1.1", "0.0.0.0", "10.0.0.1", {:netmask => '255.255.255.0', :options => 0x2})
|
50
|
+
assert_equal(10,neighbor.helloInt)
|
51
|
+
assert_equal(40,neighbor.deadInt)
|
52
|
+
assert_equal("1.1.1.1",neighbor.router_id)
|
53
|
+
end
|
54
|
+
def test_hello_int
|
55
|
+
neighbor = OSPFv2::Neighbor.new("1.1.1.1", "0.0.0.0", "10.0.0.1", {:netmask => '255.255.255.0', :options => 0x2})
|
56
|
+
neighbor.set({:helloInt => 5,})
|
57
|
+
assert_equal(5*4,neighbor.deadInt)
|
58
|
+
neighbor.set({:deadInt => 45,})
|
59
|
+
assert_equal(45,neighbor.deadInt)
|
60
|
+
neighbor.set({:deadInt => 0,})
|
61
|
+
assert_equal(20,neighbor.deadInt)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_states
|
65
|
+
n = OSPFv2::Neighbor.new("1.1.1.1", "0.0.0.0", "10.0.0.1", {:netmask => '255.255.255.0', :options => 0x2})
|
66
|
+
assert_equal(:Down,n.state?)
|
67
|
+
assert_raise(NoMethodError) {n.newState}
|
68
|
+
def n.set_state(state, comment="who cares")
|
69
|
+
newState(state,comment)
|
70
|
+
state?
|
71
|
+
end
|
72
|
+
def n.INFO(s); end
|
73
|
+
assert_equal(:Down,n.state?)
|
74
|
+
assert_equal(:Full,n.set_state(:Full))
|
75
|
+
assert_equal(true,n.state?(:Full))
|
76
|
+
assert_equal(true,n.state?(:Init, :Full, :Exchange))
|
77
|
+
assert_equal(:Loading,n.set_state(:Loading))
|
78
|
+
assert_equal(false,n.state?(:Init, :Full, :Exchange))
|
79
|
+
assert_equal(true,n.state?(:Init, :Loading, :Exchange))
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require 'pp'
|
3
|
+
require "packet/database_description"
|
4
|
+
|
5
|
+
class TestPacketDatabaseDescription < Test::Unit::TestCase
|
6
|
+
include OSPFv2
|
7
|
+
include OSPFv2::LSDB
|
8
|
+
def test_new
|
9
|
+
s = "020200340404040400000002ea7e0000000000000000000005d8000700000080" +
|
10
|
+
"000a00010000001401020304000000c800000000" +
|
11
|
+
"000a00010000001401020304000000c800000000" +
|
12
|
+
"000a00010000001401020304000000c800000000" +
|
13
|
+
"000a00010000001401020304000000c800000000" +
|
14
|
+
"000a00010000001401020304000000c800000000" +
|
15
|
+
"000a00010000001401020304000000c800000000" +
|
16
|
+
"000a00010000001401020304000000c800000000" +
|
17
|
+
"000a00010000001401020304000000c800000000" +
|
18
|
+
"000a00010000001401020304000000c800000000"
|
19
|
+
dd = DatabaseDescription.new([s].pack('H*'))
|
20
|
+
assert_equal dd.to_shex, DatabaseDescription.new(dd).to_shex
|
21
|
+
assert DatabaseDescription.new # dd = DatabaseDescription.new
|
22
|
+
dd1 = DatabaseDescription.new
|
23
|
+
dd1.imms=7
|
24
|
+
dd1.dd_sequence_number= 0xc0aa4f18
|
25
|
+
dd1.options=Options.new 0x42
|
26
|
+
|
27
|
+
#puts dd.to_s
|
28
|
+
|
29
|
+
s1 = '02020020c0a801c80000000008740000000000000000000005dc0007c0a56c70'
|
30
|
+
s2 = '02020020c0a801c80000000025c70000000000000000000005dc0007c0aa4f18'
|
31
|
+
|
32
|
+
dd2 = DatabaseDescription.new([s1].pack('H*'))
|
33
|
+
assert_equal s1, dd2.to_shex
|
34
|
+
dd2 = DatabaseDescription.new([s2].pack('H*'))
|
35
|
+
assert_equal s2, dd2.to_shex
|
36
|
+
assert_equal 3232386840, dd2.dd_sequence_number
|
37
|
+
assert_equal 3232386840, dd2.seqn
|
38
|
+
assert_equal 1500, dd2.interface_mtu.to_i
|
39
|
+
assert dd2.master?
|
40
|
+
assert dd2.init?
|
41
|
+
assert dd2.more?
|
42
|
+
|
43
|
+
h = {:imms=>7,
|
44
|
+
:au_type=>:null,
|
45
|
+
:lsas=>[],
|
46
|
+
:dd_sequence_number=>3232386840,
|
47
|
+
:packet_type=>:dd,
|
48
|
+
:area_id=>"0.0.0.0",
|
49
|
+
:interface_mtu=>1500,
|
50
|
+
:router_id=>"192.168.1.200",
|
51
|
+
:options=> 0,
|
52
|
+
:ospf_version=>2}
|
53
|
+
assert_equal(h, dd2.to_hash)
|
54
|
+
end
|
55
|
+
def _test_recv
|
56
|
+
s = "\002\002\0004\300\250\001\310\000\000\000\000\221\372\000\000\000\000\000\000\000\000\000\000\005\334B\001\300\241\326\356\000\000\"\001\300\250\001\310\300\250\001\310\200\000\000\320\242\r\0000"
|
57
|
+
dd = DatabaseDescription.new s
|
58
|
+
assert_equal 'database_description', dd.packet_name
|
59
|
+
end
|
60
|
+
def test_ls_db
|
61
|
+
ls_db = LinkStateDatabase.new(:area_id=> 0)
|
62
|
+
ls_db.add_loopback :router_id=>'2.2.2.2', :address=>'192.168.1.1', :metric=>10
|
63
|
+
ls_db.add_loopback :router_id=>'3.3.3.3', :address=>'192.168.1.2', :metric=>20
|
64
|
+
ls_db.add_adjacency(1, 2, '192.168.0.1/24', 2)
|
65
|
+
|
66
|
+
assert_equal 3, ls_db.size
|
67
|
+
|
68
|
+
dd = OspfPacket.factory( :packet_type=>:dd, :area_id=>"0.0.0.0", :au_type=>:null, :router_id=>"192.168.1.200", :dd_sequence_number=>3232386840, :ospf_version=>2, :interface_mtu=>1500, :lsas=>[], :options=>0, :ls_db => ls_db, :number_of_lsa=>1)
|
69
|
+
assert_equal 1, dd.instance_eval { @lsas.size }
|
70
|
+
assert_equal 1, ls_db.offset
|
71
|
+
assert_equal '00002201020202020202020280000001a8030024', dd.to_shex[-40.. -1]
|
72
|
+
assert dd.more?
|
73
|
+
|
74
|
+
dd = OspfPacket.factory( :packet_type=>:dd, :area_id=>"0.0.0.0", :au_type=>:null, :router_id=>"192.168.1.200", :dd_sequence_number=>3232386840, :ospf_version=>2, :interface_mtu=>1500, :lsas=>[], :options=>0, :ls_db => ls_db, :number_of_lsa=>1)
|
75
|
+
assert_equal 1, dd.instance_eval { @lsas.size }
|
76
|
+
assert_equal 2, ls_db.offset
|
77
|
+
assert_equal '000022010303030303030303800000011b7d0024', dd.to_shex[-40.. -1]
|
78
|
+
assert dd.more?
|
79
|
+
|
80
|
+
dd = OspfPacket.factory( :packet_type=>:dd, :area_id=>"0.0.0.0", :au_type=>:null, :router_id=>"192.168.1.200", :dd_sequence_number=>3232386840, :ospf_version=>2, :interface_mtu=>1500, :lsas=>[], :options=>0, :ls_db => ls_db, :number_of_lsa=>1)
|
81
|
+
assert_equal 1, dd.instance_eval { @lsas.size }
|
82
|
+
assert_equal 3, ls_db.offset
|
83
|
+
assert_equal '0000220100000001000000018000000158f00030', dd.to_shex[-40.. -1]
|
84
|
+
assert ! dd.more?
|
85
|
+
|
86
|
+
dd = OspfPacket.factory( :packet_type=>:dd, :area_id=>"0.0.0.0", :au_type=>:null, :router_id=>"192.168.1.200", :dd_sequence_number=>3232386840, :ospf_version=>2, :interface_mtu=>1500, :lsas=>[], :options=>0, :ls_db => ls_db, :number_of_lsa=>1)
|
87
|
+
assert_equal 0, dd.instance_eval { @lsas.size }
|
88
|
+
assert_equal 4, ls_db.offset
|
89
|
+
assert ! dd.more?
|
90
|
+
assert_equal 24+8, dd.encode.size # no lsa headers
|
91
|
+
|
92
|
+
ls_db.offset=0
|
93
|
+
dd = OspfPacket.factory( :packet_type=>:dd, :area_id=>"0.0.0.0", :au_type=>:null, :router_id=>"192.168.1.200", :dd_sequence_number=>3232386840, :ospf_version=>2, :interface_mtu=>1500, :lsas=>[], :options=>0, :ls_db => ls_db)
|
94
|
+
assert_equal 3, dd.instance_eval { @lsas.size }
|
95
|
+
assert (ls_db.offset > 50)
|
96
|
+
assert ! dd.more?
|
97
|
+
assert_equal 24+8+3*20, dd.encode.size # 3 lsa headers
|
98
|
+
|
99
|
+
shex = %{0202005cc0a801c8000000000e8b0000000000000000000005dc0000c0aa4f1800002201020202020202020280000001a8030024000022010303030303030303800000011b7d00240000220100000001000000018000000158f00030
|
100
|
+
}.split.join
|
101
|
+
assert_equal shex, dd.to_shex
|
102
|
+
|
103
|
+
end
|
104
|
+
def test_new_from_hash
|
105
|
+
h_dd = {:packet_type=>:dd, :area_id=>"0.0.0.0", :imms=>7, :au_type=>:null, :router_id=>"192.168.1.200", :dd_sequence_number=>3232386840, :ospf_version=>2, :interface_mtu=>1500, :options=>0}
|
106
|
+
dd = DatabaseDescription.new(h_dd)
|
107
|
+
assert_equal DatabaseDescription, dd.class
|
108
|
+
assert_equal h_dd.merge(:lsas=>[]), dd.to_hash()
|
109
|
+
end
|
110
|
+
def test_new_from_hash_with_ls_db
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
end
|