bgp4r 0.0.11 → 0.0.12
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.
- data/bgp/common.rb +14 -13
- data/bgp/iana.rb +26 -1
- data/bgp/messages/capability.rb +3 -2
- data/bgp/messages/message.rb +3 -2
- data/bgp/messages/open.rb +2 -1
- data/bgp/messages/update.rb +80 -30
- data/bgp/neighbor/add_path_cap.rb +125 -0
- data/bgp/{neighbor.rb → neighbor/neighbor.rb} +64 -68
- data/bgp/nlris/nlri.rb +289 -15
- data/bgp/nlris/prefix.rb +3 -2
- data/bgp/nlris/vpn.rb +1 -8
- data/bgp/optional_parameters/add_path.rb +160 -0
- data/bgp/optional_parameters/capabilities.rb +1 -0
- data/bgp/optional_parameters/capability.rb +6 -0
- data/bgp/optional_parameters/graceful_restart.rb +6 -6
- data/bgp/optional_parameters/optional_parameter.rb +1 -0
- data/bgp/path_attributes/as_path.rb +1 -1
- data/bgp/path_attributes/attribute.rb +12 -5
- data/bgp/path_attributes/mp_reach.rb +142 -96
- data/bgp/path_attributes/mp_unreach.rb +73 -20
- data/bgp/path_attributes/path_attribute.rb +28 -5
- data/bgp4r.gemspec +21 -6
- data/bgp4r.rb +1 -1
- data/examples/unit-testing/malformed_update.rb +2 -1
- data/examples/unit-testing/test.rb +82 -0
- data/examples/unit-testing/test1.rb +82 -0
- data/examples/unit-testing/test2.rb +44 -0
- data/test/common_test.rb +7 -0
- data/test/helpers/server.rb +20 -0
- data/test/iana_test.rb +43 -0
- data/test/messages/open_test.rb +7 -2
- data/test/messages/update_test.rb +133 -36
- data/test/neighbor/add_path_cap_test.rb +54 -0
- data/test/neighbor/neighbor_test.rb +161 -0
- data/test/nlris/ext_nlri_test.rb +25 -60
- data/test/nlris/nlri_test.rb +93 -115
- data/test/optional_parameters/add_path_test.rb +53 -0
- data/test/optional_parameters/capability_test.rb +10 -0
- data/test/optional_parameters/graceful_restart_test.rb +1 -0
- data/test/path_attributes/mp_reach_test.rb +206 -8
- data/test/path_attributes/mp_unreach_test.rb +113 -5
- data/test/path_attributes/path_attribute_test.rb +34 -2
- metadata +20 -7
- data/test/neighbor_test.rb +0 -62
@@ -30,12 +30,13 @@ module BGP
|
|
30
30
|
attr_reader :safi, :nlris
|
31
31
|
|
32
32
|
def initialize(*args)
|
33
|
-
@safi, @nlris= 1, []
|
33
|
+
@safi, @nexthops, @nlris, @path_id= 1, [], [], nil # default is ipv4/unicast
|
34
34
|
@flags, @type = OPTIONAL, MP_UNREACH
|
35
35
|
if args[0].is_a?(String) and args[0].is_packed?
|
36
|
-
parse(args
|
36
|
+
parse(*args)
|
37
37
|
elsif args[0].is_a?(self.class)
|
38
|
-
|
38
|
+
s = args.shift.encode
|
39
|
+
parse(s, *args)
|
39
40
|
elsif args[0].is_a?(Hash) and args.size==1
|
40
41
|
set(*args)
|
41
42
|
else
|
@@ -43,27 +44,60 @@ module BGP
|
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
46
|
-
|
47
|
+
def afi
|
47
48
|
@afi ||= @nlris[0].afi
|
48
49
|
end
|
49
50
|
|
51
|
+
# FIXME: refactor with mp_reach ....
|
50
52
|
def set(h)
|
51
|
-
|
52
|
-
h[:nlri] ||=[]
|
53
|
-
h[:prefix] ||=[]
|
53
|
+
h[:nlris] ||=[]
|
54
54
|
@afi = h[:afi] if h[:afi]
|
55
|
+
@safi = h[:safi]
|
56
|
+
@path_id = path_id = h[:path_id]
|
55
57
|
case @safi
|
56
|
-
when 1
|
57
|
-
@nlris = [h[:
|
58
|
+
when 1
|
59
|
+
@nlris = [h[:nlris]].flatten.collect do |n|
|
60
|
+
case n
|
61
|
+
when String
|
62
|
+
nlri = Inet_unicast.new(n)
|
63
|
+
path_id ? Ext_Nlri.new(path_id, nlri) : nlri
|
64
|
+
when Hash
|
65
|
+
path_id = n[:path_id] if n[:path_id]
|
66
|
+
nlri = Inet_unicast.new(n[:prefix])
|
67
|
+
path_id ? Ext_Nlri.new(path_id, nlri) : nlri
|
68
|
+
else
|
69
|
+
raise ArgumentError, "Invalid: #{n.inspect}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
when 2
|
73
|
+
@nlris = [h[:nlris]].flatten.collect do |n|
|
74
|
+
case n
|
75
|
+
when String
|
76
|
+
nlri = Inet_multicast.new(n)
|
77
|
+
path_id ? Ext_Nlri.new(path_id, nlri) : nlri
|
78
|
+
when Hash
|
79
|
+
path_id = n[:path_id] if n[:path_id]
|
80
|
+
nlri = Inet_multicast.new(n[:prefix])
|
81
|
+
path_id ? Ext_Nlri.new(path_id, nlri) : nlri
|
82
|
+
else
|
83
|
+
raise ArgumentError, "Invalid: #{n.inspect}"
|
84
|
+
end
|
85
|
+
end
|
58
86
|
when 4
|
59
|
-
@nlris = [h[:
|
87
|
+
@nlris = [h[:nlris]].flatten.collect do |n|
|
88
|
+
path_id = n[:path_id] || @path_id
|
60
89
|
prefix = n[:prefix].is_a?(String) ? Prefix.new(n[:prefix]) : n[:prefix]
|
61
|
-
Labeled.new(prefix, *n[:label])
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
90
|
+
nlri = Labeled.new(prefix, *n[:label])
|
91
|
+
path_id ? Ext_Nlri.new(path_id, nlri) : nlri
|
92
|
+
end
|
93
|
+
when 128,129
|
94
|
+
@nlris = [h[:nlris]].flatten.collect do |n|
|
95
|
+
path_id = n[:path_id] || @path_id
|
96
|
+
prefix = n[:prefix].is_a?(Prefix) ? n[:prefix] : Prefix.new(n[:prefix])
|
97
|
+
rd = n[:rd].is_a?(Rd) ? n[:rd] : Rd.new(*n[:rd])
|
98
|
+
nlri = Labeled.new(Vpn.new(prefix,rd), *n[:label])
|
99
|
+
path_id ? Ext_Nlri.new(path_id, nlri) : nlri
|
100
|
+
end
|
67
101
|
else
|
68
102
|
end
|
69
103
|
end
|
@@ -76,22 +110,41 @@ module BGP
|
|
76
110
|
def to_s(method=:default)
|
77
111
|
super(mp_unreach, method)
|
78
112
|
end
|
79
|
-
|
80
|
-
def parse(s)
|
113
|
+
|
114
|
+
def parse(s,arg=false)
|
115
|
+
|
81
116
|
@flags, @type, len, value = super(s)
|
82
117
|
@afi, @safi = value.slice!(0,3).unpack('nC')
|
118
|
+
|
119
|
+
if arg.respond_to?(:path_id?)
|
120
|
+
path_id_flag = arg.path_id? :recv, @afi, @safi
|
121
|
+
else
|
122
|
+
path_id_flag = arg
|
123
|
+
end
|
124
|
+
|
83
125
|
while value.size>0
|
126
|
+
path_id = value.slice!(0,4).unpack('N')[0] if path_id_flag
|
84
127
|
blen = value.slice(0,1).unpack('C')[0]
|
85
|
-
|
128
|
+
nlri = Nlri.factory(value.slice!(0,(blen+7)/8+1), @afi, @safi)
|
129
|
+
if path_id_flag
|
130
|
+
@nlris << Ext_Nlri.new(path_id, nlri)
|
131
|
+
else
|
132
|
+
@nlris << nlri
|
133
|
+
end
|
86
134
|
end
|
87
135
|
raise RuntimeError, "leftover afer parsing: #{value.unpack('H*')}" if value.size>0
|
88
136
|
end
|
137
|
+
|
89
138
|
|
90
139
|
def encode
|
91
140
|
super([afi, @safi, @nlris.collect { |n| n.encode }.join].pack('nCa*'))
|
141
|
+
rescue => e
|
142
|
+
p nlris[0].prefix
|
143
|
+
raise
|
92
144
|
end
|
93
145
|
|
94
146
|
end
|
147
|
+
|
95
148
|
end
|
96
149
|
|
97
|
-
load "../../test/path_attributes/#{ File.basename($0.gsub(/.rb/,'_test.rb'))}" if __FILE__ == $0
|
150
|
+
load "../../test/path_attributes/#{ File.basename($0.gsub(/.rb/,'_test.rb'))}" if __FILE__ == $0
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright 2008,
|
2
|
+
# Copyright 2008-2009, 2011 Jean-Michel Esnault.
|
3
3
|
# All rights reserved.
|
4
4
|
# See LICENSE.txt for permissions.
|
5
5
|
#
|
@@ -21,6 +21,7 @@
|
|
21
21
|
#++
|
22
22
|
|
23
23
|
require 'bgp/path_attributes/attribute'
|
24
|
+
require 'bgp/neighbor/add_path_cap'
|
24
25
|
|
25
26
|
module BGP
|
26
27
|
|
@@ -39,6 +40,7 @@ module BGP
|
|
39
40
|
add(*args)
|
40
41
|
end
|
41
42
|
end
|
43
|
+
|
42
44
|
def add(*args)
|
43
45
|
@attributes ||=[]
|
44
46
|
args.each { |arg| @attributes << arg if arg.is_a?(BGP::Attr) }
|
@@ -218,13 +220,32 @@ module BGP
|
|
218
220
|
end
|
219
221
|
end
|
220
222
|
include BGP::ATTR
|
221
|
-
def self.factory(s,
|
223
|
+
def self.factory(s, arg=nil)
|
224
|
+
#FIXME:
|
225
|
+
|
226
|
+
if arg.is_a?(Neighbor::Capabilities)
|
227
|
+
as4byte_flag = arg.as4byte?
|
228
|
+
path_id_flag = arg
|
229
|
+
elsif arg.is_a?(Hash)
|
230
|
+
as4byte_flag=arg[:as4byte]
|
231
|
+
path_id_flag=arg[:path_id]
|
232
|
+
elsif arg.is_a?(TrueClass)
|
233
|
+
as4byte_flag=true
|
234
|
+
path_id_flag=nil
|
235
|
+
elsif arg.respond_to? :as4byte?
|
236
|
+
as4byte_flag = arg.as4byte?
|
237
|
+
path_id_flag = arg
|
238
|
+
else
|
239
|
+
as4byte_flag=nil
|
240
|
+
path_id_flag=nil
|
241
|
+
end
|
242
|
+
|
222
243
|
flags, type = s.unpack('CC')
|
223
244
|
case type
|
224
245
|
when ORIGIN
|
225
246
|
Origin.new(s)
|
226
247
|
when AS_PATH
|
227
|
-
As_path.new(s,
|
248
|
+
As_path.new(s,as4byte_flag)
|
228
249
|
when NEXT_HOP
|
229
250
|
Next_hop.new(s)
|
230
251
|
when MULTI_EXIT_DISC
|
@@ -244,12 +265,14 @@ module BGP
|
|
244
265
|
when CLUSTER_LIST
|
245
266
|
Cluster_list.new(s)
|
246
267
|
when MP_REACH
|
247
|
-
Mp_reach.new(s)
|
268
|
+
Mp_reach.new(s,path_id_flag)
|
248
269
|
when MP_UNREACH
|
249
|
-
Mp_unreach.new(s)
|
270
|
+
Mp_unreach.new(s,path_id_flag)
|
250
271
|
when EXTENDED_COMMUNITY
|
251
272
|
Extended_communities.new(s)
|
252
273
|
else
|
274
|
+
#FIXME: raise UnknownPathAttributeError() ....
|
275
|
+
p s
|
253
276
|
Unknown.new(s)
|
254
277
|
end
|
255
278
|
end
|
data/bgp4r.gemspec
CHANGED
@@ -5,13 +5,13 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bgp4r}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.12"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jean-Michel Esnault"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-02-13}
|
13
13
|
s.description = %q{BGP4R is a BGP-4 ruby library to create, send, and receive BGP messages in an object oriented manner}
|
14
|
-
s.email = %q{
|
14
|
+
s.email = %q{bgp4r@esnault.org}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
17
17
|
"README.rdoc"
|
@@ -33,7 +33,8 @@ Gem::Specification.new do |s|
|
|
33
33
|
"bgp/messages/route_refresh.rb",
|
34
34
|
"bgp/messages/update.rb",
|
35
35
|
"bgp/misc/live_feed.rb",
|
36
|
-
"bgp/neighbor.rb",
|
36
|
+
"bgp/neighbor/add_path_cap.rb",
|
37
|
+
"bgp/neighbor/neighbor.rb",
|
37
38
|
"bgp/nlris/inet.rb",
|
38
39
|
"bgp/nlris/label.rb",
|
39
40
|
"bgp/nlris/labeled.rb",
|
@@ -42,6 +43,7 @@ Gem::Specification.new do |s|
|
|
42
43
|
"bgp/nlris/prefix.rb",
|
43
44
|
"bgp/nlris/rd.rb",
|
44
45
|
"bgp/nlris/vpn.rb",
|
46
|
+
"bgp/optional_parameters/add_path.rb",
|
45
47
|
"bgp/optional_parameters/as4.rb",
|
46
48
|
"bgp/optional_parameters/capabilities.rb",
|
47
49
|
"bgp/optional_parameters/capability.rb",
|
@@ -79,8 +81,13 @@ Gem::Specification.new do |s|
|
|
79
81
|
"examples/unit-testing/malformed_update.rb",
|
80
82
|
"examples/unit-testing/no_export.rb",
|
81
83
|
"examples/unit-testing/prepend_aspath.rb",
|
84
|
+
"examples/unit-testing/test.rb",
|
85
|
+
"examples/unit-testing/test1.rb",
|
86
|
+
"examples/unit-testing/test2.rb",
|
82
87
|
"examples/unit-testing/unknown_transitive_attr.rb",
|
83
88
|
"test/common_test.rb",
|
89
|
+
"test/helpers/server.rb",
|
90
|
+
"test/iana_test.rb",
|
84
91
|
"test/messages/capability_test.rb",
|
85
92
|
"test/messages/keepalive_test.rb",
|
86
93
|
"test/messages/markers_test.rb",
|
@@ -91,12 +98,14 @@ Gem::Specification.new do |s|
|
|
91
98
|
"test/messages/update_test.rb",
|
92
99
|
"test/misc/live_feed_test.rb",
|
93
100
|
"test/misc/misc.rb",
|
94
|
-
"test/
|
101
|
+
"test/neighbor/add_path_cap_test.rb",
|
102
|
+
"test/neighbor/neighbor_test.rb",
|
95
103
|
"test/nlris/ext_nlri_test.rb",
|
96
104
|
"test/nlris/inet_test.rb",
|
97
105
|
"test/nlris/labeled_test.rb",
|
98
106
|
"test/nlris/nlri_test.rb",
|
99
107
|
"test/nlris/rd_test.rb",
|
108
|
+
"test/optional_parameters/add_path_test.rb",
|
100
109
|
"test/optional_parameters/as4_test.rb",
|
101
110
|
"test/optional_parameters/capability_test.rb",
|
102
111
|
"test/optional_parameters/dynamic_test.rb",
|
@@ -132,6 +141,9 @@ Gem::Specification.new do |s|
|
|
132
141
|
s.summary = %q{A BGP-4 Ruby Library}
|
133
142
|
s.test_files = [
|
134
143
|
"test/common_test.rb",
|
144
|
+
"test/helpers",
|
145
|
+
"test/helpers/server.rb",
|
146
|
+
"test/iana_test.rb",
|
135
147
|
"test/messages",
|
136
148
|
"test/messages/capability_test.rb",
|
137
149
|
"test/messages/keepalive_test.rb",
|
@@ -144,7 +156,9 @@ Gem::Specification.new do |s|
|
|
144
156
|
"test/misc",
|
145
157
|
"test/misc/live_feed_test.rb",
|
146
158
|
"test/misc/misc.rb",
|
147
|
-
"test/
|
159
|
+
"test/neighbor",
|
160
|
+
"test/neighbor/add_path_cap_test.rb",
|
161
|
+
"test/neighbor/neighbor_test.rb",
|
148
162
|
"test/nlris",
|
149
163
|
"test/nlris/ext_nlri_test.rb",
|
150
164
|
"test/nlris/inet_test.rb",
|
@@ -152,6 +166,7 @@ Gem::Specification.new do |s|
|
|
152
166
|
"test/nlris/nlri_test.rb",
|
153
167
|
"test/nlris/rd_test.rb",
|
154
168
|
"test/optional_parameters",
|
169
|
+
"test/optional_parameters/add_path_test.rb",
|
155
170
|
"test/optional_parameters/as4_test.rb",
|
156
171
|
"test/optional_parameters/capability_test.rb",
|
157
172
|
"test/optional_parameters/dynamic_test.rb",
|
data/bgp4r.rb
CHANGED
@@ -36,6 +36,7 @@ class TestBgp < Test::Unit::TestCase
|
|
36
36
|
msg = recv(queue)
|
37
37
|
assert msg, "Did not receive expected BGP update message."
|
38
38
|
assert_instance_of(Notification, msg)
|
39
|
+
sleep 0.3
|
39
40
|
assert_equal 'Missing Well-known Attribute', msg.to_string
|
40
41
|
assert @n100.is_idle?
|
41
42
|
end
|
@@ -61,7 +62,7 @@ class TestBgp < Test::Unit::TestCase
|
|
61
62
|
nil
|
62
63
|
end
|
63
64
|
end
|
64
|
-
|
65
|
+
|
65
66
|
def malformed_update
|
66
67
|
update = Update.new(
|
67
68
|
Path_attribute.new(
|
@@ -0,0 +1,82 @@
|
|
1
|
+
|
2
|
+
require 'bgp4r'
|
3
|
+
require 'timeout'
|
4
|
+
|
5
|
+
Thread.abort_on_exception=true
|
6
|
+
|
7
|
+
|
8
|
+
include BGP
|
9
|
+
|
10
|
+
Log.create
|
11
|
+
Log.level=Logger::DEBUG
|
12
|
+
|
13
|
+
N100 = Class.new(BGP::Neighbor)
|
14
|
+
|
15
|
+
class RecvMsgHandler
|
16
|
+
def initialize(q)
|
17
|
+
@q = q
|
18
|
+
end
|
19
|
+
def update(bgp_msg)
|
20
|
+
@q.enq bgp_msg
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def setup
|
25
|
+
@n100 = N100.new(:my_as=> 100, :remote_addr => '40.0.0.2', :local_addr => '40.0.0.1', :id=> '13.11.19.59')
|
26
|
+
start_peering
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_verify_missing_well_known_attribute_is_greeting_with_a_notification_from_as200
|
30
|
+
queue = Queue.new
|
31
|
+
@n100.add_observer RecvMsgHandler.new(queue)
|
32
|
+
@n100.send_message malformed_update
|
33
|
+
msg = recv(queue)
|
34
|
+
end
|
35
|
+
|
36
|
+
def teardown
|
37
|
+
@n100.stop
|
38
|
+
sleep(0.5)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def start_peering
|
44
|
+
@n100.capability :as4_byte
|
45
|
+
@n100.start
|
46
|
+
end
|
47
|
+
|
48
|
+
def recv(q, timeout=5)
|
49
|
+
begin
|
50
|
+
Timeout::timeout(timeout) do |t|
|
51
|
+
msg = q.deq
|
52
|
+
end
|
53
|
+
rescue Timeout::Error => e
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def malformed_update
|
59
|
+
update = Update.new(
|
60
|
+
Path_attribute.new(
|
61
|
+
Origin.new(0),
|
62
|
+
Multi_exit_disc.new(100),
|
63
|
+
Local_pref.new(100),
|
64
|
+
As_path.new(100)
|
65
|
+
),
|
66
|
+
Nlri.new('77.0.0.0/17', '78.0.0.0/18', '79.0.0.0/19')
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
setup
|
71
|
+
p @n100.inspect
|
72
|
+
p @n100.inspect
|
73
|
+
p @n100.inspect
|
74
|
+
p @n100.inspect
|
75
|
+
p @n100.inspect
|
76
|
+
p @n100.inspect
|
77
|
+
p @n100.inspect
|
78
|
+
p @n100.inspect
|
79
|
+
p @n100.instance_eval { @cap }
|
80
|
+
|
81
|
+
test_verify_missing_well_known_attribute_is_greeting_with_a_notification_from_as200
|
82
|
+
teardown
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require 'bgp4r'
|
3
|
+
require 'timeout'
|
4
|
+
|
5
|
+
Thread.abort_on_exception=true
|
6
|
+
|
7
|
+
include BGP
|
8
|
+
|
9
|
+
Log.create
|
10
|
+
Log.level=Logger::DEBUG
|
11
|
+
|
12
|
+
N100 = Class.new(BGP::Neighbor)
|
13
|
+
N300 = Class.new(BGP::Neighbor)
|
14
|
+
|
15
|
+
class RecvMsgHandler
|
16
|
+
def initialize(q)
|
17
|
+
@q = q
|
18
|
+
end
|
19
|
+
def update(bgp_msg)
|
20
|
+
@q.enq bgp_msg
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def setup
|
25
|
+
@n100 = N100.new(:my_as=> 100, :remote_addr => '40.0.0.2', :local_addr => '40.0.0.1', :id=> '13.11.19.59')
|
26
|
+
@n300 = N300.new(:my_as=> 300, :remote_addr => '40.0.1.1', :local_addr => '40.0.1.2', :id=> '13.11.19.57')
|
27
|
+
start_peering
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_verify_that_200_is_prepended_to_aspath
|
31
|
+
queue = Queue.new
|
32
|
+
@n300.add_observer RecvMsgHandler.new(queue)
|
33
|
+
send_update_to @n100
|
34
|
+
msg = recv(queue)
|
35
|
+
puts msg
|
36
|
+
end
|
37
|
+
|
38
|
+
def teardown
|
39
|
+
[@n100, @n300].each { |n| n.stop }
|
40
|
+
sleep(0.5)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def start_peering
|
46
|
+
[@n100, @n300].each { |n|
|
47
|
+
n.capability :as4_byte
|
48
|
+
n.start
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def recv(q, timeout=5)
|
53
|
+
begin
|
54
|
+
Timeout::timeout(timeout) do |t|
|
55
|
+
msg = q.deq
|
56
|
+
end
|
57
|
+
rescue Timeout::Error => e
|
58
|
+
nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def update1
|
63
|
+
update = Update.new(
|
64
|
+
Path_attribute.new(
|
65
|
+
Origin.new(0),
|
66
|
+
Next_hop.new('40.0.0.1'),
|
67
|
+
Multi_exit_disc.new(100),
|
68
|
+
Local_pref.new(100),
|
69
|
+
As_path.new(100),
|
70
|
+
Communities.new('1311:1 311:59 2805:64')
|
71
|
+
),
|
72
|
+
Nlri.new('77.0.0.0/17', '78.0.0.0/18', '79.0.0.0/19')
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
def send_update_to(n)
|
77
|
+
n.send_message update1
|
78
|
+
end
|
79
|
+
|
80
|
+
setup
|
81
|
+
test_verify_that_200_is_prepended_to_aspath
|
82
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
require 'bgp4r'
|
3
|
+
require 'test/helpers/server'
|
4
|
+
|
5
|
+
include BGP
|
6
|
+
include BGP::OPT_PARM::CAP
|
7
|
+
include BGP::TestHelpers
|
8
|
+
|
9
|
+
def test_start
|
10
|
+
start_server(3456)
|
11
|
+
@c = Neighbor.new(4, 100, 180, '0.0.0.2', '127.0.0.1', '127.0.0.1')
|
12
|
+
@c.start :port=> 3456
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_start_no_blocking
|
16
|
+
start_server(3333)
|
17
|
+
@c = Neighbor.new(4, 100, 180, '0.0.0.2', '127.0.0.1', '127.0.0.1')
|
18
|
+
@c.start :port=> 3333, :no_blocking=>true
|
19
|
+
assert_equal('OpenSent', @c.state)
|
20
|
+
assert_match(/(Active|OpenSent)/, @s.state)
|
21
|
+
stop_server
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_send_and_receive_path_id_afi_1_safi_1
|
25
|
+
server_add_path_cap = BGP::OPT_PARM::CAP::Add_path.new
|
26
|
+
server_add_path_cap.add(:send_and_recv, 1, 1)
|
27
|
+
start_server(3456, server_add_path_cap)
|
28
|
+
@c = Neighbor.new(4, 100, 180, '0.0.0.2', '127.0.0.1', '127.0.0.1')
|
29
|
+
@c.add_cap server_add_path_cap
|
30
|
+
@c.start :port=> 3456
|
31
|
+
assert @s.session_info.recv_inet_unicast?,
|
32
|
+
"Should have the capability to recv inet unicast reachability path info."
|
33
|
+
assert @s.session_info.send_inet_unicast?,
|
34
|
+
"Should have the capability to send inet unicast reachability path info."
|
35
|
+
assert @c.session_info.recv_inet_unicast?,
|
36
|
+
"Should have the capability to recv inet unicast reachability path info."
|
37
|
+
assert @c.session_info.send_inet_unicast?,
|
38
|
+
"Should have the capability to send inet unicast reachability path info."
|
39
|
+
stop_server
|
40
|
+
end
|
41
|
+
|
42
|
+
start_server(3456)
|
43
|
+
@c = Neighbor.new(4, 100, 180, '0.0.0.2', '127.0.0.1', '127.0.0.1')
|
44
|
+
@c.start :port=> 3456
|
data/test/common_test.rb
CHANGED
@@ -46,6 +46,13 @@ class Common_Test < Test::Unit::TestCase
|
|
46
46
|
assert_equal('255.255.255.254', IPAddr.new('1.1.1.1/31').netmask)
|
47
47
|
assert_equal('255.255.255.252', IPAddr.new('1.1.1.1/30').netmask)
|
48
48
|
assert_equal('255.255.255.248', IPAddr.new('1.1.1.1/29').netmask)
|
49
|
+
assert_equal('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',IPAddr.new('2011:1:18::1').netmask)
|
50
|
+
assert_equal('ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe',IPAddr.new('2011:1:18::1/127').netmask)
|
51
|
+
assert_equal('ffff:ffff:ffff:ffff:8000:0000:0000:0000',IPAddr.new('2011:1:18::1/65').netmask)
|
52
|
+
assert_equal('ffff:ffff:ffff:ffff:0000:0000:0000:0000',IPAddr.new('2011:1:18::1/64').netmask)
|
53
|
+
assert_equal('ffff:ffff:ffff:fffe:0000:0000:0000:0000',IPAddr.new('2011:1:18::1/63').netmask)
|
54
|
+
assert_equal('ffff:ffff:ffff:0000:0000:0000:0000:0000',IPAddr.new('2011:1:18::1/48').netmask)
|
55
|
+
assert_equal('ffff:ffff:0000:0000:0000:0000:0000:0000',IPAddr.new('2011:1:18::1/32').netmask)
|
49
56
|
end
|
50
57
|
def test_ipaddr_4
|
51
58
|
ip1 = IPAddr.new('10.0.0.1/28')
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module BGP
|
2
|
+
module TestHelpers
|
3
|
+
def stop_server
|
4
|
+
@s.stop if @s
|
5
|
+
@c.stop if @c
|
6
|
+
@server.close if @server
|
7
|
+
@thread.kill if @thread
|
8
|
+
end
|
9
|
+
def start_server(port, cap=nil)
|
10
|
+
@server = TCPServer.new(port)
|
11
|
+
@thread = Thread.new do
|
12
|
+
while (session = @server.accept())
|
13
|
+
@s = Neighbor.new(4, 100, 180, '0.0.0.1', '127.0.0.1', '127.0.0.1')
|
14
|
+
@s.add_cap cap if cap
|
15
|
+
@s.start_session(session)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/test/iana_test.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2011 Jean-Michel Esnault.
|
3
|
+
# All rights reserved.
|
4
|
+
# See LICENSE.txt for permissions.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# This file is part of BGP4R.
|
8
|
+
#
|
9
|
+
# BGP4R is free software: you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# BGP4R is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU General Public License
|
20
|
+
# along with BGP4R. If not, see <http://www.gnu.org/licenses/>.
|
21
|
+
#++
|
22
|
+
|
23
|
+
require "bgp/iana"
|
24
|
+
|
25
|
+
require 'test/unit'
|
26
|
+
class TestBgpIana < Test::Unit::TestCase
|
27
|
+
def test_afi?
|
28
|
+
assert_equal 1, IANA.afi?(:ip)
|
29
|
+
assert_equal 2, IANA.afi?(:ip6)
|
30
|
+
assert_equal 5, IANA.afi?(:bbn)
|
31
|
+
assert_equal 12, IANA.afi?(:appletalk)
|
32
|
+
assert_equal 'IP', IANA.afi?(1)
|
33
|
+
assert_equal 'IP6',IANA.afi?(2)
|
34
|
+
end
|
35
|
+
def test_safi?
|
36
|
+
assert_equal 1, IANA.safi?(:unicast_nlri)
|
37
|
+
assert_equal 2, IANA.safi?(:multicast_nlri)
|
38
|
+
assert_equal 4, IANA.safi?(:label_nlri)
|
39
|
+
assert_equal 5, IANA.safi?(:mcast_vpn)
|
40
|
+
assert_equal 64, IANA.safi?(:tunnel)
|
41
|
+
assert_equal 65, IANA.safi?(:vpls)
|
42
|
+
end
|
43
|
+
end
|
data/test/messages/open_test.rb
CHANGED
@@ -92,7 +92,12 @@ class Open_Test < Test::Unit::TestCase
|
|
92
92
|
assert_equal s, open.to_shex
|
93
93
|
end
|
94
94
|
def test_4
|
95
|
+
open = Open.new(4,100, 200, '10.0.0.1')
|
96
|
+
open << OPT_PARM::CAP::As4.new(100)
|
97
|
+
open << OPT_PARM::CAP::Route_refresh.new
|
98
|
+
open << OPT_PARM::CAP::Add_path.new(:recv, 1, 1)
|
99
|
+
assert open.find(As4)
|
100
|
+
assert open.find(Route_refresh)
|
101
|
+
assert open.find(Add_path)
|
95
102
|
end
|
96
|
-
|
97
|
-
|
98
103
|
end
|