bgp4r 0.0.15 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bgp/common.rb +13 -2
- data/bgp/io.rb +4 -1
- data/bgp/messages/keepalive.rb +4 -0
- data/bgp/messages/message.rb +1 -1
- data/bgp/neighbor/neighbor.rb +3 -1
- data/bgp/nlris/mapped_ipv4.rb +28 -0
- data/bgp/nlris/nlris.rb +2 -1
- data/bgp/path_attributes/aggregator.rb +9 -3
- data/bgp/path_attributes/as_path.rb +4 -4
- data/bgp/path_attributes/extended_communities.rb +39 -1
- data/bgp/path_attributes/extended_community.rb +38 -32
- data/bgp/path_attributes/mp_reach.rb +11 -4
- data/bgp/path_attributes/path_attribute.rb +13 -9
- data/bgp4r.gemspec +6 -4
- data/bgp4r.rb +6 -0
- data/examples/bgp-vyatta-ipv6.rb +148 -0
- data/test/unit/common_test.rb +8 -0
- data/test/unit/messages/update_test.rb +9 -2
- data/test/unit/neighbor/neighbor_test.rb +126 -84
- data/test/unit/nlris/mapped_ipv4_test.rb +19 -0
- data/test/unit/path_attributes/aggregator_test.rb +8 -0
- data/test/unit/path_attributes/extended_communities_test.rb +26 -16
- data/test/unit/path_attributes/extended_community_test.rb +15 -15
- data/test/unit/path_attributes/mp_reach_test.rb +13 -5
- data/test/unit/path_attributes/path_attribute_test.rb +54 -3
- metadata +7 -10
- data/test/unit/path_attributes/tunnel_encapsulation_test (Jean-Michel's Laptop's conflicted copy 2011-11-02).rb +0 -388
data/test/unit/common_test.rb
CHANGED
@@ -65,6 +65,14 @@ class Common_Test < Test::Unit::TestCase
|
|
65
65
|
assert_equal('10.16.0.0/12', ip3 ^ 1)
|
66
66
|
assert_equal('10.32.0.0/12', ip3 ^ 2)
|
67
67
|
end
|
68
|
+
def test_ipaddr_v6_arithmetic
|
69
|
+
ip1 = IPAddr.new('2014:aa:bb:cc::1/126')
|
70
|
+
assert_equal('2014:aa:bb:cc::4/126', ip1 ^ 1)
|
71
|
+
assert_equal('2014:aa:bb:cc::8/126', ip1 ^ 2)
|
72
|
+
assert_equal('2014:aa:bb:cc::c/126', ip1 ^ 3)
|
73
|
+
assert_equal('2014:aa:bb:cc::10/126', ip1 ^ 4)
|
74
|
+
assert_equal('2014:aa:bb:cc::14/126', ip1 ^ 5)
|
75
|
+
end
|
68
76
|
def test_string_pack
|
69
77
|
sbin = ['00'].pack('H*')
|
70
78
|
assert_equal '0x0000: 00', sbin.hexlify.join
|
@@ -342,7 +342,7 @@ class Update_Test < Test::Unit::TestCase
|
|
342
342
|
}
|
343
343
|
assert_equal(h, upd.to_hash)
|
344
344
|
assert_equal(BGP::Route_target, upd.path_attribute.extended_communities.route_target.class)
|
345
|
-
assert_equal(
|
345
|
+
assert_equal("Route target: 4:1", upd.path_attribute.extended_communities.route_target.to_s)
|
346
346
|
assert_equal(128, upd.path_attribute.mp_reach.safi)
|
347
347
|
assert_equal('Label Stack=16000 (bottom) RD=19:17, ID=1, IPv4=10.1.1.0/24', upd.path_attribute.mp_reach.nlris[0].to_s)
|
348
348
|
end
|
@@ -456,9 +456,16 @@ class Update_Test < Test::Unit::TestCase
|
|
456
456
|
:next_hop=>"187.121.193.33"
|
457
457
|
}
|
458
458
|
}
|
459
|
+
|
460
|
+
npfx = h[:nlris].size
|
461
|
+
assert_equal(76, npfx)
|
462
|
+
|
459
463
|
u = Update.new h
|
464
|
+
assert_equal(npfx, u.nlri.size)
|
465
|
+
assert_equal(:igp, u.path_attribute.origin.to_sym)
|
466
|
+
assert_equal('187.121.193.33', u.path_attribute.next_hop.next_hop)
|
460
467
|
assert_equal(h, u.to_hash)
|
461
|
-
|
468
|
+
|
462
469
|
# s = "ffffffffffffffffffffffffffffffff016c02000000254001010040021002076e81cf8b415f0ddd266526652665400304bb79c121c008046e81ffdc123b5880123b58c0123b5900123b59c0123b5a00123b5a40123b5a80123b5ac0123b5bc0123b5d80123b5dc0123b5e00123b5e40123b5e80123b5ec0123b5f00123b5f80123b6080123b60c0123b6180123b61c0123b62c0123b6300123b63401275c5001275c5401275c5801275c6801275c6c01275c7401275c7801275c7c01275c8001275c8401275c9001275c9401275cac01275cb001275cb801275cbc01275cd001275cd401275cdc01275ce801275cec01275cf001275cf801275d1c01275d2001275d2401275d2801275d2c01275d4001275d4401275d6001275d6801275d6c01275da001275ef001275ef401275ef801275efc01275f1001275f1401275f1801275f1c01275f2001275f2401275f2801275f2c012d2d40012d2d44012d2d48012d2d4c012daf80012daf880"
|
463
470
|
# assert_equal(s, u.to_shex)
|
464
471
|
end
|
@@ -23,6 +23,7 @@
|
|
23
23
|
require "test/unit"
|
24
24
|
require 'bgp4r'
|
25
25
|
require 'test/helpers/server'
|
26
|
+
require 'timeout'
|
26
27
|
include BGP
|
27
28
|
include BGP::OPT_PARM::CAP
|
28
29
|
include BGP::TestHelpers
|
@@ -32,17 +33,22 @@ class TestBgpNeighbor < Test::Unit::TestCase
|
|
32
33
|
include BGP
|
33
34
|
include BGP::OPT_PARM::CAP
|
34
35
|
include BGP::TestHelpers
|
36
|
+
def setup
|
37
|
+
# Don't work with jruby: skip
|
38
|
+
skip if RUBY_PLATFORM=='java'
|
39
|
+
super
|
40
|
+
end
|
35
41
|
def teardown
|
36
42
|
stop_server
|
37
43
|
end
|
38
44
|
def test_open_msg
|
39
45
|
neighbor = Neighbor.new \
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
:version=> 4,
|
47
|
+
:my_as=> 100,
|
48
|
+
:remote_addr => '192.168.1.200',
|
49
|
+
:local_addr => '192.168.1.5',
|
50
|
+
:id=> '1.1.1.1',
|
51
|
+
:holdtime=> 20
|
46
52
|
neighbor.capability Mbgp.ipv4_unicast
|
47
53
|
neighbor.capability Mbgp.ipv4_multicast
|
48
54
|
neighbor.capability Route_refresh.new
|
@@ -56,100 +62,136 @@ class TestBgpNeighbor < Test::Unit::TestCase
|
|
56
62
|
end
|
57
63
|
def test_neighbor_state_methods
|
58
64
|
neighbor = Neighbor.new \
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
+
:version=> 4,
|
66
|
+
:my_as=> 100,
|
67
|
+
:remote_addr => '192.168.1.200',
|
68
|
+
:local_addr => '192.168.1.5',
|
69
|
+
:id=> '1.1.1.1',
|
70
|
+
:holdtime=> 20
|
65
71
|
assert neighbor.is_idle?
|
66
72
|
assert ! neighbor.is_established?
|
67
73
|
assert ! neighbor.is_openrecv?
|
68
74
|
assert ! neighbor.is_openconfirm?
|
69
75
|
end
|
70
76
|
def test_start
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
77
|
+
status = Timeout::timeout(4) {
|
78
|
+
start_server(3456)
|
79
|
+
@c = Neighbor.new(4, 100, 180, '0.0.0.2', '127.0.0.1', '127.0.0.1')
|
80
|
+
@c.start :port=> 3456
|
81
|
+
assert_equal('Established', @c.state)
|
82
|
+
assert_equal('Established', @s.state)
|
83
|
+
}
|
84
|
+
rescue Timeout::Error
|
85
|
+
assert false, "Timeout"
|
76
86
|
end
|
77
87
|
def test_start_no_blocking
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
88
|
+
status = Timeout::timeout(4) {
|
89
|
+
start_server(3333)
|
90
|
+
@c = Neighbor.new(4, 100, 180, '0.0.0.2', '127.0.0.1', '127.0.0.1')
|
91
|
+
@c.start :port=> 3333, :no_blocking=>true
|
92
|
+
assert_equal('OpenSent', @c.state)
|
93
|
+
}
|
94
|
+
rescue Timeout::Error
|
95
|
+
assert false, "Timeout"
|
96
|
+
end
|
97
|
+
def test_start_blocking
|
98
|
+
status = Timeout::timeout(4) {
|
99
|
+
start_server(3333)
|
100
|
+
@c = Neighbor.new(4, 100, 180, '0.0.0.2', '127.0.0.1', '127.0.0.1')
|
101
|
+
@c.start :port=> 3333, :no_blocking=>false
|
102
|
+
assert_equal('Established', @c.state)
|
103
|
+
assert_match(/Established/, @s.state)
|
104
|
+
}
|
105
|
+
rescue Timeout::Error
|
106
|
+
assert false, "Timeout"
|
83
107
|
end
|
84
108
|
def test_send_and_receive_path_id_afi_1_safi_1
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
109
|
+
status = Timeout::timeout(4) {
|
110
|
+
server_add_path_cap = BGP::OPT_PARM::CAP::Add_path.new
|
111
|
+
server_add_path_cap.add(:send_and_recv, 1, 1)
|
112
|
+
start_server(3456, server_add_path_cap)
|
113
|
+
@c = Neighbor.new(4, 100, 180, '0.0.0.2', '127.0.0.1', '127.0.0.1')
|
114
|
+
@c.add_cap server_add_path_cap
|
115
|
+
@c.start :port=> 3456
|
116
|
+
assert @s.session_info.recv_inet_unicast?,
|
117
|
+
"Should have the capability to recv inet unicast reachability path info."
|
118
|
+
assert @s.session_info.send_inet_unicast?,
|
119
|
+
"Should have the capability to send inet unicast reachability path info."
|
120
|
+
assert @c.session_info.recv_inet_unicast?,
|
121
|
+
"Should have the capability to recv inet unicast reachability path info."
|
122
|
+
assert @c.session_info.send_inet_unicast?,
|
123
|
+
"Should have the capability to send inet unicast reachability path info."
|
124
|
+
}
|
125
|
+
rescue Timeout::Error => e
|
126
|
+
assert false, "timeout"
|
99
127
|
end
|
100
128
|
def test_send_path_id_afi_1_safi_1
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
129
|
+
status = Timeout::timeout(4) {
|
130
|
+
server_add_path_cap = BGP::OPT_PARM::CAP::Add_path.new
|
131
|
+
server_add_path_cap.add(:send, 1, 1)
|
132
|
+
client_add_path_cap = BGP::OPT_PARM::CAP::Add_path.new
|
133
|
+
client_add_path_cap.add(:recv, 1, 1)
|
134
|
+
start_server(3456, server_add_path_cap)
|
135
|
+
@c = Neighbor.new(4, 100, 180, '0.0.0.2', '127.0.0.1', '127.0.0.1')
|
136
|
+
@c.add_cap client_add_path_cap
|
137
|
+
@c.start :port=> 3456
|
138
|
+
assert ! @s.session_info.recv_inet_unicast?,
|
139
|
+
"Should NOT have the capability to recv inet unicast reachability path info."
|
140
|
+
assert @s.session_info.send_inet_unicast?,
|
141
|
+
"Should have the capability to send inet unicast reachability path info."
|
142
|
+
assert @c.session_info.recv_inet_unicast?,
|
143
|
+
"Should have the capability to recv inet unicast reachability path info."
|
144
|
+
assert ! @c.session_info.send_inet_unicast?,
|
145
|
+
"Should NOT have the capability to send inet unicast reachability path info."
|
146
|
+
}
|
147
|
+
rescue Timeout::Error => e
|
148
|
+
assert false, "timeout"
|
149
|
+
|
117
150
|
end
|
118
151
|
def test_recv_path_id_afi_1_safi_1
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
152
|
+
status = Timeout::timeout(4) {
|
153
|
+
server_add_path_cap = BGP::OPT_PARM::CAP::Add_path.new
|
154
|
+
server_add_path_cap.add(:recv, 1, 1)
|
155
|
+
client_add_path_cap = BGP::OPT_PARM::CAP::Add_path.new
|
156
|
+
client_add_path_cap.add(:send, 1, 1)
|
157
|
+
start_server(3456, server_add_path_cap)
|
158
|
+
@c = Neighbor.new(4, 100, 180, '0.0.0.2', '127.0.0.1', '127.0.0.1')
|
159
|
+
@c.add_cap client_add_path_cap
|
160
|
+
@c.start :port=> 3456
|
161
|
+
assert @s.session_info.recv_inet_unicast?,
|
162
|
+
"Should have the capability to recv inet unicast reachability path info."
|
163
|
+
assert ! @s.session_info.send_inet_unicast?,
|
164
|
+
"Should NOT have the capability to send inet unicast reachability path info."
|
165
|
+
assert ! @c.session_info.recv_inet_unicast?,
|
166
|
+
"Should NOT have the capability to recv inet unicast reachability path info."
|
167
|
+
assert @c.session_info.send_inet_unicast?,
|
168
|
+
"Should have the capability to send inet unicast reachability path info."
|
169
|
+
}
|
170
|
+
rescue Timeout::Error => e
|
171
|
+
assert false, "timeout"
|
172
|
+
|
135
173
|
end
|
136
174
|
def test_nor_recv_nor_send_path_id_afi_1_safi_1
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
175
|
+
status = Timeout::timeout(4) {
|
176
|
+
server_add_path_cap = BGP::OPT_PARM::CAP::Add_path.new
|
177
|
+
server_add_path_cap.add(:recv, 1, 1)
|
178
|
+
client_add_path_cap = BGP::OPT_PARM::CAP::Add_path.new
|
179
|
+
client_add_path_cap.add(:recv, 1, 1)
|
180
|
+
start_server(3456, server_add_path_cap)
|
181
|
+
@c = Neighbor.new(4, 100, 180, '0.0.0.2', '127.0.0.1', '127.0.0.1')
|
182
|
+
@c.add_cap client_add_path_cap
|
183
|
+
@c.start :port=> 3456
|
184
|
+
assert ! @s.session_info.recv_inet_unicast?,
|
185
|
+
"Should NOT have the capability to recv inet unicast reachability path info."
|
186
|
+
assert ! @s.session_info.send_inet_unicast?,
|
187
|
+
"Should NOT have the capability to send inet unicast reachability path info."
|
188
|
+
assert ! @c.session_info.recv_inet_unicast?,
|
189
|
+
"Should NOT have the capability to recv inet unicast reachability path info."
|
190
|
+
assert ! @c.session_info.send_inet_unicast?,
|
191
|
+
"Should have the capability to send inet unicast reachability path info."
|
192
|
+
}
|
193
|
+
rescue Timeout::Error => e
|
194
|
+
assert false, "timeout"
|
153
195
|
end
|
154
196
|
def test_add_capabilities_using_sym
|
155
197
|
neighbor = Neighbor.new(4,100,180,'0.0.0.2')
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2014 Jean-Michel Esnault.
|
3
|
+
# All rights reserved.
|
4
|
+
# See LICENSE.txt for permissions.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# This file is part of BGP4R.
|
8
|
+
#
|
9
|
+
|
10
|
+
require "test/unit"
|
11
|
+
require 'bgp/nlris/mapped_ipv4'
|
12
|
+
|
13
|
+
class TestNlrisIpv4Mapped < Test::Unit::TestCase
|
14
|
+
include BGP
|
15
|
+
def test_ipv4_mapped
|
16
|
+
assert_equal('10.0.0.1', Ipv4_mapped.new('10.0.0.1').to_s)
|
17
|
+
assert_equal('00000000000000000000ffff0a000001', Ipv4_mapped.new('10.0.0.1').to_shex)
|
18
|
+
end
|
19
|
+
end
|
@@ -69,4 +69,12 @@ class Aggregator_Test < Test::Unit::TestCase
|
|
69
69
|
assert_equal(ag1.encode,ag2.encode)
|
70
70
|
assert_equal({:asn=>100, :address=>"10.0.0.1"}, ag2.to_hash[:aggregator])
|
71
71
|
end
|
72
|
+
def test6
|
73
|
+
ag1 = Aggregator.new('10.0.0.1', 100)
|
74
|
+
ag1.asn=200
|
75
|
+
ag1.address='11.0.0.2'
|
76
|
+
assert_equal(200, ag1.asn)
|
77
|
+
assert_equal('11.0.0.2', ag1.address)
|
78
|
+
assert_equal({:asn=>200, :address=>"11.0.0.2"}, ag1.to_hash[:aggregator])
|
79
|
+
end
|
72
80
|
end
|
@@ -60,17 +60,12 @@ class Extended_communitiesTest < Test::Unit::TestCase
|
|
60
60
|
ec = Extended_communities.new_hash :ospf_domain_id=> '9.1.0.1'
|
61
61
|
ec2 = Extended_communities.new_hash(ec.to_hash)
|
62
62
|
assert_equal(ec.to_hash, Extended_communities.new_hash(ec.to_hash).to_hash)
|
63
|
-
ec = Extended_communities.new_hash :encapsulation=> :l2tpv3
|
64
|
-
ec2 = Extended_communities.new_hash(ec.to_hash)
|
65
63
|
assert_equal(ec.to_hash, Extended_communities.new_hash(ec.to_hash).to_hash)
|
66
64
|
ec = Extended_communities.new_hash :route_origin=> ['10.0.1.2', 10]
|
67
65
|
ec2 = Extended_communities.new_hash(ec.to_hash)
|
68
|
-
assert_equal(ec.to_hash, Extended_communities.new_hash(ec.to_hash).to_hash)
|
69
|
-
ec = Extended_communities.new_hash :color => 100, :link_bandwidth => 999_999_999, :route_origin => ['10.0.1.2', 10], :encapsulation => :ipip
|
70
|
-
assert_equal(ec.to_hash, Extended_communities.new_hash(ec.to_hash).to_hash)
|
71
|
-
assert_equal({:color=>100}, ec.color.to_hash)
|
72
66
|
ec = Extended_communities.new_hash :extended_communities=>[{:route_target=>[13111, 26054]}]
|
73
67
|
assert_equal({:extended_communities=>[{:route_target=>[13111, 26054]}]}, ec.to_hash)
|
68
|
+
assert_equal(ec.to_hash, Extended_communities.new_hash(ec.to_hash).to_hash)
|
74
69
|
end
|
75
70
|
def test_sort
|
76
71
|
ec = Extended_communities.new
|
@@ -81,7 +76,7 @@ class Extended_communitiesTest < Test::Unit::TestCase
|
|
81
76
|
ec.add(Route_target.new('11.0.1.1',10))
|
82
77
|
ec.add(Route_target.new('8.0.1.1',10))
|
83
78
|
ec.add(Route_target.new('7.0.1.1',8))
|
84
|
-
ec.add(Encapsulation.new(:l2tpv3))
|
79
|
+
# ec.add(Encapsulation.new(:l2tpv3))
|
85
80
|
ec.add(Ospf_domain_id.new('20.0.0.1'))
|
86
81
|
ec.add(Route_origin.new('10.0.3.2',9))
|
87
82
|
ec.add(Route_target.new('10.0.3.2',7))
|
@@ -96,8 +91,8 @@ class Extended_communitiesTest < Test::Unit::TestCase
|
|
96
91
|
assert_equal("Ospf domain id: 20.0.0.1:0",ec.sort.communities[7].to_s)
|
97
92
|
assert_equal("Ospf router id: 10.0.0.1:0",ec.sort.communities[8].to_s)
|
98
93
|
assert_equal("Color: 100",ec.sort.communities[9].to_s)
|
99
|
-
assert_equal("Encapsulation: 1",ec.sort.communities[10].to_s)
|
100
|
-
assert_equal("Link bandwidth: 1000000000.0",ec.sort.communities[
|
94
|
+
# assert_equal("Encapsulation: 1",ec.sort.communities[10].to_s)
|
95
|
+
assert_equal("Link bandwidth: 1000000000.0",ec.sort.communities[10].to_s)
|
101
96
|
end
|
102
97
|
def test_sort!
|
103
98
|
ec = Extended_communities.new
|
@@ -140,28 +135,43 @@ class Extended_communitiesTest < Test::Unit::TestCase
|
|
140
135
|
assert_equal(0, ec <=> ec2)
|
141
136
|
assert(! ec.eql?(ec2))
|
142
137
|
end
|
143
|
-
def
|
138
|
+
def test_getters_setters
|
144
139
|
ec = Extended_communities.new do |c|
|
145
140
|
c.add(Color.new(100))
|
146
141
|
c.add(Link_bandwidth.new(999_999_999))
|
147
142
|
c.add(Route_target.new('10.0.1.2',10))
|
148
143
|
c.add(Ospf_domain_id.new('9.1.0.1'))
|
149
|
-
c.add(Route_target.new('11.0.1.1',
|
144
|
+
c.add(Route_target.new('11.0.1.1',11))
|
150
145
|
c.add(Route_target.new('8.0.1.1',10))
|
151
146
|
c.add(Route_target.new('7.0.1.1',8))
|
152
|
-
c.add(Encapsulation.new(:l2tpv3))
|
147
|
+
### c.add(Encapsulation.new(:l2tpv3))
|
153
148
|
c.add(Ospf_domain_id.new('20.0.0.1'))
|
154
149
|
c.add(Route_origin.new('10.0.3.2',9))
|
155
|
-
c.add(Route_target.new('10.0.3.2',
|
150
|
+
c.add(Route_target.new('10.0.3.2',12))
|
156
151
|
c.add(Ospf_router_id.new('10.0.0.1'))
|
157
152
|
end
|
158
153
|
assert_equal('Color: 100',ec.color.to_s)
|
159
|
-
assert_equal('Route target: 10.0.1.2:10',ec.route_target.to_s)
|
160
|
-
assert_equal('Ospf domain id: 9.1.0.1:0',ec.ospf_domain_id.to_s)
|
161
|
-
assert_equal('Encapsulation: 1',ec.encapsulation.to_s)
|
154
|
+
assert_equal('Route target: 10.0.1.2:10',ec.route_target[0].to_s)
|
155
|
+
assert_equal('Ospf domain id: 9.1.0.1:0',ec.ospf_domain_id[0].to_s)
|
156
|
+
###assert_equal('Encapsulation: 1',ec.encapsulation.to_s)
|
162
157
|
assert_equal('Ospf router id: 10.0.0.1:0',ec.ospf_router_id.to_s)
|
163
158
|
assert_equal('Link bandwidth: 1000000000.0',ec.link_bandwidth.to_s)
|
164
159
|
assert_equal('Route origin: 10.0.3.2:9',ec.route_origin.to_s)
|
160
|
+
ec.route_target= '20.0.1.2', 20
|
161
|
+
ec.link_bandwidth= 100_000
|
162
|
+
assert_equal('Route target: 20.0.1.2:20',ec.route_target[0].to_s)
|
163
|
+
assert_equal('Link bandwidth: 100000.0',ec.link_bandwidth.to_s)
|
164
|
+
|
165
|
+
ec = Extended_communities.new do |c|
|
166
|
+
c.route_target = '10.0.0.1', 1311
|
167
|
+
c.link_bandwidth = 100_000_000
|
168
|
+
c.ospf_router_id = '1.1.1.1'
|
169
|
+
c.ospf_domain_id = '2.2.2.2'
|
170
|
+
###c.encapsulation = 1
|
171
|
+
c.route_origin = '3.3.3.3', 33
|
172
|
+
c.color = 1311
|
173
|
+
end
|
174
|
+
|
165
175
|
end
|
166
176
|
|
167
177
|
end
|
@@ -108,24 +108,24 @@ class Extended_community_Test < Test::Unit::TestCase
|
|
108
108
|
assert_equal('Color: 10000', Color.new(Color.new(10_000).encode).to_s)
|
109
109
|
end
|
110
110
|
|
111
|
-
def test_encapsulation
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
end
|
111
|
+
# def test_encapsulation
|
112
|
+
# assert_equal('030c000000000000', Encapsulation.new.to_shex)
|
113
|
+
# assert_equal('030c000000000001', Encapsulation.new(1).to_shex)
|
114
|
+
# assert_equal('030c000000000002', Encapsulation.new(2).to_shex)
|
115
|
+
# assert_equal('030c000000000007', Encapsulation.new(7).to_shex)
|
116
|
+
# assert_equal('030c000000000001', Encapsulation.new(:l2tpv3).to_shex)
|
117
|
+
# assert_equal('030c000000000002', Encapsulation.new(:gre).to_shex)
|
118
|
+
# assert_equal('030c000000000007', Encapsulation.new(:ipip).to_shex)
|
119
|
+
# assert_equal('Encapsulation: 1', Encapsulation.new(:l2tpv3).to_s)
|
120
|
+
# assert_equal('Encapsulation: 7', Encapsulation.new(:ipip).to_s)
|
121
|
+
# assert_equal('Encapsulation: 2', Encapsulation.new(:gre).to_s)
|
122
|
+
# assert_equal('Encapsulation: 7', Encapsulation.new(Encapsulation.new(7).encode).to_s)
|
123
|
+
# end
|
124
124
|
|
125
125
|
def test_factory
|
126
126
|
s = '0102070001010008 010208000101000a 01020a000102000a 01020a0003020007 01020b000101000a
|
127
127
|
01030a0003020009 0105090100010000 0105140000010000 01070a0000010000 400400004e6e6b28
|
128
|
-
430b000000000064
|
128
|
+
430b000000000064 '.split.join # 030c000000000007
|
129
129
|
comms = []
|
130
130
|
communities = s.scan(/[0-9a-f]{16}/) { |comm| comms << Extended_community.factory([comm].pack('H*')) }
|
131
131
|
assert_equal BGP::Route_target, comms[0].class
|
@@ -139,7 +139,7 @@ class Extended_community_Test < Test::Unit::TestCase
|
|
139
139
|
assert_equal BGP::Ospf_router_id, comms[8].class
|
140
140
|
assert_equal BGP::Link_bandwidth, comms[9].class
|
141
141
|
assert_equal BGP::Color, comms[10].class
|
142
|
-
assert_equal BGP::Encapsulation, comms[11].class
|
142
|
+
# assert_equal BGP::Encapsulation, comms[11].class
|
143
143
|
end
|
144
144
|
|
145
145
|
end
|
@@ -25,7 +25,7 @@ require 'test/unit'
|
|
25
25
|
|
26
26
|
class Mp_reach_Test < Test::Unit::TestCase
|
27
27
|
include BGP
|
28
|
-
|
28
|
+
|
29
29
|
def test_iso_mapped_ip_addr
|
30
30
|
mapped_addr = Iso_ip_mapped.new('10.0.0.1')
|
31
31
|
assert_equal('470006010a00000100', mapped_addr.to_shex)
|
@@ -171,9 +171,6 @@ class Mp_reach_Test < Test::Unit::TestCase
|
|
171
171
|
assert_equal(smpr.split.join, mpr.to_shex)
|
172
172
|
end
|
173
173
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
174
|
def test_afi_3_safi_1_ipv6_mapped_nexthops_ntoh
|
178
175
|
|
179
176
|
# Mp Reach (14), length: 57, Flags [O]:
|
@@ -198,8 +195,19 @@ class Mp_reach_Test < Test::Unit::TestCase
|
|
198
195
|
|
199
196
|
assert_equal(s.split.join, mpr.to_shex)
|
200
197
|
assert_equal("[Oncr] (14) Mp Reach: [800e3b000301283500002...] '\n AFI NSAP (3), SAFI Unicast (1)\n nexthop: 2011::1, 2011::2\n 49.0001.0002.0003.0004.0005.0006.0000.0000.0000.00/104'", mpr.to_s())
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_afi_2_safi_2_ipv4_mapped
|
201
|
+
s = '800e30000202102009000900190000000000000000000100402009000100000000402009000200000000402009000300000000'
|
202
|
+
sbin = [s].pack('H*')
|
203
|
+
mpr = Mp_reach.new(sbin)
|
204
|
+
assert_equal("\n AFI IPv6 (2), SAFI Multicast (2)\n nexthop: 2009:9:19::1\n 2009:1::/64\n 2009:2::/64\n 2009:3::/64", mpr.mp_reach)
|
205
|
+
assert_equal(2, mpr.afi)
|
206
|
+
assert_equal(2, mpr.safi)
|
207
|
+
assert_equal(s, mpr.to_shex)
|
201
208
|
end
|
202
209
|
|
210
|
+
|
203
211
|
def test_afi_2_safi_2
|
204
212
|
s = '800e30000202102009000900190000000000000000000100402009000100000000402009000200000000402009000300000000'
|
205
213
|
sbin = [s].pack('H*')
|
@@ -600,7 +608,7 @@ class Mp_reach_Test < Test::Unit::TestCase
|
|
600
608
|
assert_equal(mpr3.to_hash, Mp_reach.new(mpr3.to_hash[:mp_reach]).to_hash)
|
601
609
|
|
602
610
|
end
|
603
|
-
|
611
|
+
|
604
612
|
private
|
605
613
|
|
606
614
|
def attr_len(attr)
|
@@ -180,7 +180,7 @@ class Path_attribute_Test < Test::Unit::TestCase # :nodoc:
|
|
180
180
|
:as_path=> {:set=> [1,2], :sequence=>[3,4], :confed_sequence=>[5,6], :confed_set=>[7,8]},
|
181
181
|
:cluster_list=> ['1.1.1.1', '2.2.2.2', '3.3.3.3'],
|
182
182
|
:communities=> ["145:30", "145:40", "145:50", "145:60", :no_export, :no_advertise,],
|
183
|
-
:extended_communities=> [ :color => 100, :link_bandwidth => 999_999_999, :route_origin => ['10.0.1.2', 10],
|
183
|
+
:extended_communities=> [ :color => 100, :link_bandwidth => 999_999_999, :route_origin => ['10.0.1.2', 10], ],
|
184
184
|
:aggregator=> { :address=>'1.1.1.1', :asn=>100 },
|
185
185
|
:originator_id=> '2.2.2.2',
|
186
186
|
:as4_aggregator=> { :asn=> 200, :address=> '4.4.4.4' },
|
@@ -294,7 +294,6 @@ class Path_attribute_Test < Test::Unit::TestCase # :nodoc:
|
|
294
294
|
],
|
295
295
|
}
|
296
296
|
}
|
297
|
-
|
298
297
|
assert_equal(h[:local_pref], Path_attribute.new(h).to_hash[:local_pref])
|
299
298
|
assert_equal(h[:as_path], Path_attribute.new(h).to_hash[:as_path])
|
300
299
|
assert_equal(h[:extended_communities], Path_attribute.new(h).to_hash[:extended_communities])
|
@@ -303,8 +302,60 @@ class Path_attribute_Test < Test::Unit::TestCase # :nodoc:
|
|
303
302
|
assert_equal(h[:aggregator], Path_attribute.new(h).to_hash[:aggregator])
|
304
303
|
assert_equal(h[:mp_reach], Path_attribute.new(h).to_hash[:mp_reach])
|
305
304
|
assert_equal(h, Path_attribute.new(h).to_hash)
|
305
|
+
end
|
306
|
+
|
307
|
+
def test_setters
|
308
|
+
h = {
|
309
|
+
:aigp=> 0x1f2f3f4f5f6f7f8f,
|
310
|
+
:nexthop=> '2.2.2.2',
|
311
|
+
:aggregator=>{:asn=>100, :address=>"10.0.0.1"},
|
312
|
+
:cluster_list=>["1.0.1.1"],
|
313
|
+
:as_path=>{},
|
314
|
+
:communities=>["1133:2015"],
|
315
|
+
:local_pref=>113,
|
316
|
+
:origin=>:incomplete,
|
317
|
+
:med=>10,
|
318
|
+
:extended_communities=>[{:route_target=>[13111, 26054]}, {:ospf_domain_id=>'1.1.1.1'}],
|
319
|
+
:originator_id=>"196.168.28.123",
|
320
|
+
:mp_reach=>{
|
321
|
+
:nexthop=>["10.0.0.2"], :afi=>1, :safi=>128,
|
322
|
+
:nlris=>[
|
323
|
+
{:label=>2226, :prefix=>"172.23.21.113/32", :rd=>[1311, 4567814]},
|
324
|
+
{:label=>2151, :prefix=>"10.48.9.175/32", :rd=>[1311, 32117824]},
|
325
|
+
],
|
326
|
+
}
|
327
|
+
}
|
306
328
|
|
329
|
+
pa = Path_attribute.new h
|
330
|
+
pa.origin=:egp
|
331
|
+
pa.as_path_sequence=[1,2,3,4]
|
332
|
+
pa.next_hop='1.2.3.4'
|
333
|
+
pa.local_pref=20
|
334
|
+
pa.med=30
|
335
|
+
pa.communities="1113:2805"
|
336
|
+
pa.aggregator.asn=200
|
337
|
+
pa.aggregator.address='11.0.0.2'
|
338
|
+
pa.originator_id='2.2.2.2'
|
339
|
+
pa.cluster_list=['11.1.1.1','12.2.2.2']
|
340
|
+
pa.extended_communities.route_target= '10.0.0.1', 1311
|
341
|
+
pa.extended_communities.link_bandwidth= 100_000_000
|
342
|
+
pa.extended_communities.ospf_router_id= '1.1.1.1'
|
343
|
+
pa.extended_communities.ospf_domain_id= '2.2.2.2'
|
344
|
+
# pa.extended_communities.encapsulation=1
|
345
|
+
pa.extended_communities.route_origin= '3.3.3.3', 33
|
346
|
+
pa.extended_communities.color=1311
|
347
|
+
assert_equal(1, pa[Origin].to_i)
|
348
|
+
assert_equal(:egp, pa.origin.to_sym)
|
349
|
+
assert_equal("1 2 3 4", pa.as_path.as_path)
|
350
|
+
assert_equal(200, pa.aggregator.asn)
|
351
|
+
assert_equal("11.0.0.2", pa.aggregator.address)
|
352
|
+
assert_equal("2.2.2.2", pa.originator_id.originator_id)
|
353
|
+
assert_equal("b010101", pa.cluster_list.to_ary[0].to_s(16))
|
354
|
+
assert_equal("c020202", pa.cluster_list.to_ary[1].to_s(16))
|
355
|
+
assert_equal("Route target: 10.0.0.1:1311", pa.extended_communities.route_target.to_s)
|
356
|
+
assert_equal("Ospf domain id: 2.2.2.2:0", pa.extended_communities.ospf_domain_id.to_s)
|
357
|
+
assert_equal("Link bandwidth: 100000000.0", pa.extended_communities.link_bandwidth.to_s)
|
307
358
|
end
|
308
|
-
|
359
|
+
|
309
360
|
end
|
310
361
|
|