bgp4r 0.0.5 → 0.0.7
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 +5 -1
- data/bgp/message.rb +19 -7
- data/bgp/neighbor.rb +59 -34
- data/bgp/path_attribute.rb +3 -3
- data/bgp/version.rb +3 -0
- data/bgp4r.gemspec +12 -4
- data/bgp4r.rb +1 -0
- data/examples/routegen.yml +4 -4
- data/examples/unit-testing/malformed_update.rb +81 -0
- data/examples/unit-testing/prepend_aspath.rb +87 -0
- data/test/message_test.rb +8 -0
- data/test/neighbor_test.rb +14 -1
- data/test/path_attribute_test.rb +11 -0
- metadata +8 -7
- /data/examples/{bgp → simple.rb} +0 -0
data/bgp/common.rb
CHANGED
@@ -130,7 +130,11 @@ class String
|
|
130
130
|
end
|
131
131
|
if l.size%2 >0
|
132
132
|
ns = if l.size>1 then 1 else 0 end
|
133
|
-
|
133
|
+
if RUBY_VERSION.split('.').join[0,2] > "18"
|
134
|
+
ls.last << format("%s%2.2x",' '*ns,l[-1].unpack('C')[0])
|
135
|
+
else
|
136
|
+
ls.last << format("%s%2.2x",' '*ns,l[-1])
|
137
|
+
end
|
134
138
|
end
|
135
139
|
ls
|
136
140
|
end
|
data/bgp/message.rb
CHANGED
@@ -419,8 +419,12 @@ module BGP
|
|
419
419
|
|
420
420
|
|
421
421
|
class Update < Message
|
422
|
+
def as4byte?
|
423
|
+
@as4byte ||= false
|
424
|
+
end
|
422
425
|
def initialize(*args)
|
423
426
|
if args[0].is_a?(String) and args[0].is_packed?
|
427
|
+
@as4byte=false
|
424
428
|
parse(*args)
|
425
429
|
elsif args[0].is_a?(self.class)
|
426
430
|
parse(args[0].encode, *args[1..-1])
|
@@ -454,7 +458,8 @@ module BGP
|
|
454
458
|
@path_attribute=val if val.is_a?(Path_attribute)
|
455
459
|
end
|
456
460
|
|
457
|
-
|
461
|
+
#TODO refactor out passing an argument to encode...
|
462
|
+
def encode(as4byte=@as4byte)
|
458
463
|
withdrawn, path_attribute, nlri = '', '', ''
|
459
464
|
withdrawn = @withdrawn.encode(false) if defined? @withdrawn and @withdrawn
|
460
465
|
path_attribute = @path_attribute.encode(as4byte) if defined?(@path_attribute) and @path_attribute
|
@@ -468,7 +473,9 @@ module BGP
|
|
468
473
|
|
469
474
|
attr_reader :path_attribute, :nlri, :withdrawn
|
470
475
|
|
476
|
+
# CHANGED ME: NO DEFAULT HERE, the factory calling us has to tell what it is giving us.
|
471
477
|
def parse(s, as4byte=false)
|
478
|
+
@as4byte=as4byte
|
472
479
|
update = super(s)
|
473
480
|
len = update.slice!(0,2).unpack('n')[0]
|
474
481
|
self.withdrawn=Withdrawn.new(update.slice!(0,len).is_packed) if len>0
|
@@ -494,12 +501,13 @@ module BGP
|
|
494
501
|
end
|
495
502
|
end
|
496
503
|
|
497
|
-
def to_s(as4byte
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
504
|
+
def to_s(as4byte=@as4byte, fmt=:tcpdump)
|
505
|
+
msg = encode(as4byte)
|
506
|
+
# if as4byte
|
507
|
+
# msg = self.encode(true)
|
508
|
+
# else
|
509
|
+
# msg = self.encode
|
510
|
+
# end
|
503
511
|
s = []
|
504
512
|
s << @withdrawn.to_s if defined?(@withdrawn) and @withdrawn
|
505
513
|
s << @path_attribute.to_s(fmt, as4byte) if defined?(@path_attribute) and @path_attribute
|
@@ -886,6 +894,10 @@ module BGP
|
|
886
894
|
{:code=> @code, :subcode=> @subcode, :data=>@data}
|
887
895
|
end
|
888
896
|
|
897
|
+
def to_string
|
898
|
+
Notification.code_to_s(@code, @subcode)
|
899
|
+
end
|
900
|
+
|
889
901
|
def to_s
|
890
902
|
msg = self.encode
|
891
903
|
s = "Notification (#{MESSAGE::NOTIFICATION}), length: #{msg.size}: "
|
data/bgp/neighbor.rb
CHANGED
@@ -28,6 +28,14 @@ module BGP
|
|
28
28
|
|
29
29
|
class Neighbor
|
30
30
|
include Observable
|
31
|
+
|
32
|
+
def log_info(txt)
|
33
|
+
Log.info "#{self.class} #{txt}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def log_debug(txt)
|
37
|
+
Log.debug "#{self.class} #{txt}"
|
38
|
+
end
|
31
39
|
|
32
40
|
def initialize(*args)
|
33
41
|
@opt_parms = []
|
@@ -49,19 +57,30 @@ module BGP
|
|
49
57
|
event_dispatch
|
50
58
|
end
|
51
59
|
|
52
|
-
|
53
|
-
|
60
|
+
[:Idle, :Established, :OpenRecv, :OpenConfirm, :Active, :OpenSent].each do |state|
|
61
|
+
define_method("is_#{state.to_s.downcase}?") do
|
62
|
+
@state == state
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# neighbor.capability :as4_byte | :as4 | :as4byte
|
67
|
+
# neighbor.capability :route_refresh, :rr
|
54
68
|
# neighbor.capability :route_refresh, 128
|
55
69
|
# neighbor.capability :mbgp, :ipv4, :unicast
|
56
70
|
# neighbor.capability :mbgp, :ipv4, :multicast
|
57
71
|
def capability(*args)
|
58
72
|
@opt_parms << if args[0].is_a?(Symbol)
|
59
73
|
case args[0]
|
60
|
-
when :route_refresh
|
61
|
-
|
62
|
-
when :
|
74
|
+
when :route_refresh, :rr
|
75
|
+
Route_refresh_cap.new(*args[1..-1])
|
76
|
+
when :mbgp
|
77
|
+
Mbgp_cap.new(*args[1..-1])
|
78
|
+
when :as4_byte, :as4byte, :as4
|
79
|
+
As4_cap.new(@my_as)
|
80
|
+
else
|
81
|
+
raise ArgumentError, "Invalid argument #{args.inspect}", caller
|
63
82
|
end
|
64
|
-
elsif args[0].is_a?(Capability)
|
83
|
+
elsif args[0].is_a?(Capability)
|
65
84
|
args[0]
|
66
85
|
else
|
67
86
|
raise ArgumentError, "Invalid argument"
|
@@ -69,7 +88,7 @@ module BGP
|
|
69
88
|
end
|
70
89
|
|
71
90
|
def state
|
72
|
-
@state
|
91
|
+
"#{@state}"
|
73
92
|
end
|
74
93
|
|
75
94
|
def retry_thread(action=:start)
|
@@ -96,10 +115,9 @@ module BGP
|
|
96
115
|
ev, type, m = eventQ.deq
|
97
116
|
case ev
|
98
117
|
when :ev_msg
|
99
|
-
msg = BGP::Message.factory(m)
|
100
|
-
|
101
|
-
|
102
|
-
changed and notify_observers(msg)
|
118
|
+
msg = BGP::Message.factory(m, @as4byte)
|
119
|
+
log_info "Recv#{msg.class.to_s.split('::').last}"
|
120
|
+
log_debug "Recv #{msg}\n"
|
103
121
|
if msg.is_a?(Update)
|
104
122
|
rcv_update(msg)
|
105
123
|
elsif msg.is_a?(Notification)
|
@@ -115,6 +133,7 @@ module BGP
|
|
115
133
|
else
|
116
134
|
Log.error "unexpected message type #{type}"
|
117
135
|
end
|
136
|
+
changed and notify_observers(msg)
|
118
137
|
when :ev_conn_reset
|
119
138
|
Log.warn "#{type}"
|
120
139
|
disable
|
@@ -131,23 +150,28 @@ module BGP
|
|
131
150
|
def clean
|
132
151
|
@threads.list.each { |x|
|
133
152
|
x.exit; x.join
|
134
|
-
|
153
|
+
log_info "#{x['name']}: stopped at #{Time.now.strftime("%I:%M:%S%P")}"
|
135
154
|
}
|
136
155
|
end
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
@open = BGP::Open.new(@version, @my_as, @holdtime, @id, *@opt_parms)
|
156
|
+
|
157
|
+
def open
|
158
|
+
@open ||= BGP::Open.new(version, @my_as, holdtime, @id, *@opt_parms)
|
141
159
|
end
|
142
|
-
|
143
|
-
|
160
|
+
|
161
|
+
def version
|
162
|
+
@version ||= 4
|
163
|
+
end
|
164
|
+
|
165
|
+
def holdtime
|
166
|
+
@holdtime ||= 180
|
167
|
+
end
|
168
|
+
|
144
169
|
def enable(auto_retry=:no_auto_retry, wait= :wait)
|
145
170
|
return if @state == :Established
|
146
171
|
disable unless @state == :Idle
|
147
172
|
|
148
173
|
init_socket
|
149
174
|
init_io
|
150
|
-
@open = _open_msg_
|
151
175
|
|
152
176
|
[@in, @out].each { |io|
|
153
177
|
io.start
|
@@ -166,7 +190,7 @@ module BGP
|
|
166
190
|
sleep(0.3)
|
167
191
|
break if @state == :Established
|
168
192
|
end
|
169
|
-
|
193
|
+
log_info "#{self} started"
|
170
194
|
end
|
171
195
|
|
172
196
|
rescue => e
|
@@ -183,10 +207,11 @@ module BGP
|
|
183
207
|
alias stop disable
|
184
208
|
|
185
209
|
def send_message(m)
|
210
|
+
raise if m.nil?
|
186
211
|
return unless @out
|
187
212
|
unless m.is_a?(String)
|
188
|
-
|
189
|
-
|
213
|
+
log_info "Send#{m.class.to_s.split('::')[-1]}"
|
214
|
+
log_debug "Send #{m.is_a?(Update) ? m.to_s(@as4byte) : m }\n"
|
190
215
|
end
|
191
216
|
if m.is_a?(Update)
|
192
217
|
@out.enq m.encode(@as4byte)
|
@@ -216,21 +241,16 @@ module BGP
|
|
216
241
|
end
|
217
242
|
|
218
243
|
def new_state(state, txt='')
|
219
|
-
|
244
|
+
log_info "#{txt} old state #{@state} new state #{state}"
|
220
245
|
@state = state
|
221
246
|
end
|
222
247
|
|
223
|
-
def _send_open_(open)
|
224
|
-
send_message open
|
225
|
-
end
|
226
|
-
private :_send_open_
|
227
|
-
|
228
248
|
def send_open(ev)
|
229
249
|
case @state
|
230
250
|
when :OpenRecv
|
231
|
-
|
251
|
+
send_message open ; new_state :OpenConfirm, ev
|
232
252
|
when :Active
|
233
|
-
|
253
|
+
send_message open ; new_state :OpenSent, ev
|
234
254
|
else
|
235
255
|
Log.warn "#{self.class}: attempt to send OPEN msg while in #{@state}"
|
236
256
|
end
|
@@ -255,14 +275,13 @@ module BGP
|
|
255
275
|
else
|
256
276
|
Log.warn "#{self.class}: received open message while in state #{@state}"
|
257
277
|
end
|
258
|
-
|
259
|
-
@as4byte = (@open.has?(As4_cap) and o.has?(As4_cap))
|
278
|
+
@as4byte = (open.has?(As4_cap) && o.has?(As4_cap))
|
260
279
|
end
|
261
280
|
|
262
281
|
def rcv_keepalive
|
263
282
|
if @state == :OpenConfirm
|
264
283
|
send_message(BGP::Keepalive.new)
|
265
|
-
|
284
|
+
log_debug "SendKeepAlive state is #{@state}"
|
266
285
|
new_state(:Established, 'RecvKeepAlive')
|
267
286
|
@keepalive_thread = Thread.new(@holdtime/3) do |h|
|
268
287
|
Thread.current['name'] = "BGP Keepalive interval:(#{h})"
|
@@ -276,10 +295,16 @@ module BGP
|
|
276
295
|
end
|
277
296
|
|
278
297
|
def rcv_notification(m)
|
279
|
-
|
298
|
+
log_info "#{m}"
|
280
299
|
disable
|
281
300
|
end
|
282
301
|
|
302
|
+
def rcv_route_refresh(m)
|
303
|
+
end
|
304
|
+
|
305
|
+
def rcv_update(m)
|
306
|
+
end
|
307
|
+
|
283
308
|
def to_s
|
284
309
|
"version: #{@version}, id: #{@id}, as: #{@my_as}, holdtime: #{@holdtime}, peer addr: #{@remote_addr}, local addr: #{@local_addr}"
|
285
310
|
end
|
data/bgp/path_attribute.rb
CHANGED
@@ -32,7 +32,7 @@ module BGP
|
|
32
32
|
s = args[0]
|
33
33
|
@attributes=[]
|
34
34
|
while s.size>0
|
35
|
-
@attributes << Attr.factory(
|
35
|
+
@attributes << Attr.factory(*args)
|
36
36
|
end
|
37
37
|
else
|
38
38
|
add(*args)
|
@@ -160,13 +160,13 @@ module BGP
|
|
160
160
|
|
161
161
|
class Attr
|
162
162
|
include BGP::ATTR
|
163
|
-
def self.factory(s)
|
163
|
+
def self.factory(s, as4byte=false)
|
164
164
|
flags, type = s.unpack('CC')
|
165
165
|
case type
|
166
166
|
when ORIGIN
|
167
167
|
Origin.new(s)
|
168
168
|
when AS_PATH
|
169
|
-
As_path.new(s)
|
169
|
+
As_path.new(s,as4byte)
|
170
170
|
when NEXT_HOP
|
171
171
|
Next_hop.new(s)
|
172
172
|
when MULTI_EXIT_DISC
|
data/bgp/version.rb
ADDED
data/bgp4r.gemspec
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
1
4
|
# -*- encoding: utf-8 -*-
|
2
5
|
|
3
6
|
Gem::Specification.new do |s|
|
4
7
|
s.name = %q{bgp4r}
|
5
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.7"
|
6
9
|
|
7
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
11
|
s.authors = ["Jean-Michel Esnault"]
|
9
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-09-12}
|
10
13
|
s.description = %q{BGP4R is a BGP-4 ruby library to create, send, and receive BGP messages in an object oriented manner}
|
11
14
|
s.email = %q{jesnault@gmail.com}
|
12
15
|
s.extra_rdoc_files = [
|
@@ -43,11 +46,14 @@ Gem::Specification.new do |s|
|
|
43
46
|
"bgp/path_attribute.rb",
|
44
47
|
"bgp/prefix_orf.rb",
|
45
48
|
"bgp/rd.rb",
|
49
|
+
"bgp/version.rb",
|
46
50
|
"bgp4r.gemspec",
|
47
51
|
"bgp4r.rb",
|
48
|
-
"examples/bgp",
|
49
52
|
"examples/routegen",
|
50
53
|
"examples/routegen.yml",
|
54
|
+
"examples/simple.rb",
|
55
|
+
"examples/unit-testing/malformed_update.rb",
|
56
|
+
"examples/unit-testing/prepend_aspath.rb",
|
51
57
|
"test/aggregator_test.rb",
|
52
58
|
"test/as_path_test.rb",
|
53
59
|
"test/atomic_aggregate_test.rb",
|
@@ -76,7 +82,7 @@ Gem::Specification.new do |s|
|
|
76
82
|
s.require_paths = ["."]
|
77
83
|
s.required_ruby_version = Gem::Requirement.new(">= 1.8.6")
|
78
84
|
s.rubyforge_project = %q{bgp4r}
|
79
|
-
s.rubygems_version = %q{1.3.
|
85
|
+
s.rubygems_version = %q{1.3.6}
|
80
86
|
s.summary = %q{A BGP-4 Ruby Library}
|
81
87
|
s.test_files = [
|
82
88
|
"test/aggregator_test.rb",
|
@@ -106,9 +112,11 @@ Gem::Specification.new do |s|
|
|
106
112
|
if s.respond_to? :specification_version then
|
107
113
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
108
114
|
s.specification_version = 3
|
115
|
+
|
109
116
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
110
117
|
else
|
111
118
|
end
|
112
119
|
else
|
113
120
|
end
|
114
121
|
end
|
122
|
+
|
data/bgp4r.rb
CHANGED
data/examples/routegen.yml
CHANGED
@@ -5,16 +5,16 @@ neighbor:
|
|
5
5
|
router id: 1.1.1.1
|
6
6
|
my as: 100
|
7
7
|
holdtime: 180
|
8
|
-
local address:
|
9
|
-
neighbor address:
|
8
|
+
local address: 199.0.0.5
|
9
|
+
neighbor address: 199.0.0.6
|
10
10
|
capabilities:
|
11
11
|
- four byte as
|
12
12
|
routes:
|
13
13
|
nlris: 11.0.0.0/28, 1999, 127
|
14
|
-
next hop:
|
14
|
+
next hop: 199.0.0.5
|
15
15
|
local pref: 100
|
16
16
|
med: 100
|
17
|
-
origin:
|
17
|
+
origin: 0
|
18
18
|
communities: 100:1 200:1 300:1
|
19
19
|
as path: 200 300 400 500
|
20
20
|
|
@@ -0,0 +1,81 @@
|
|
1
|
+
|
2
|
+
require "test/unit"
|
3
|
+
require 'bgp4r'
|
4
|
+
require 'timeout'
|
5
|
+
|
6
|
+
Thread.abort_on_exception=true
|
7
|
+
|
8
|
+
class TestBgp < Test::Unit::TestCase
|
9
|
+
|
10
|
+
include BGP
|
11
|
+
|
12
|
+
# Log.create
|
13
|
+
# Log.level=Logger::DEBUG
|
14
|
+
|
15
|
+
N100 = Class.new(BGP::Neighbor)
|
16
|
+
|
17
|
+
class RecvMsgHandler
|
18
|
+
def initialize(q)
|
19
|
+
@q = q
|
20
|
+
end
|
21
|
+
def update(bgp_msg)
|
22
|
+
@q.enq bgp_msg
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def setup
|
27
|
+
@n100 = N100.new(:my_as=> 100, :remote_addr => '40.0.0.2', :local_addr => '40.0.0.1', :id=> '13.11.19.59')
|
28
|
+
start_peering
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_verify_missing_well_known_attribute_is_greeting_with_a_notification_from_as200
|
32
|
+
assert @n100.is_established?, "Expected to be in Established state. <> #{@n100.state}"
|
33
|
+
queue = Queue.new
|
34
|
+
@n100.add_observer RecvMsgHandler.new(queue)
|
35
|
+
@n100.send_message malformed_update
|
36
|
+
msg = recv(queue)
|
37
|
+
assert msg, "Did not receive expected BGP update message."
|
38
|
+
assert_instance_of(Notification, msg)
|
39
|
+
assert_equal 'Missing Well-known Attribute', msg.to_string
|
40
|
+
assert @n100.is_idle?
|
41
|
+
end
|
42
|
+
|
43
|
+
def teardown
|
44
|
+
@n100.stop
|
45
|
+
sleep(0.5)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def start_peering
|
51
|
+
@n100.capability :as4_byte
|
52
|
+
@n100.start
|
53
|
+
end
|
54
|
+
|
55
|
+
def recv(q, timeout=5)
|
56
|
+
begin
|
57
|
+
Timeout::timeout(timeout) do |t|
|
58
|
+
msg = q.deq
|
59
|
+
end
|
60
|
+
rescue Timeout::Error => e
|
61
|
+
nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def malformed_update
|
66
|
+
update = Update.new(
|
67
|
+
Path_attribute.new(
|
68
|
+
Origin.new(0),
|
69
|
+
Multi_exit_disc.new(100),
|
70
|
+
Local_pref.new(100),
|
71
|
+
As_path.new(100),
|
72
|
+
),
|
73
|
+
Nlri.new('77.0.0.0/17', '78.0.0.0/18', '79.0.0.0/19')
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
def send_update_to(n)
|
78
|
+
n.send_message update1
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require 'bgp4r'
|
3
|
+
require 'timeout'
|
4
|
+
|
5
|
+
Thread.abort_on_exception=true
|
6
|
+
|
7
|
+
class TestBgp < Test::Unit::TestCase
|
8
|
+
|
9
|
+
include BGP
|
10
|
+
|
11
|
+
Log.create
|
12
|
+
Log.level=Logger::DEBUG
|
13
|
+
|
14
|
+
N100 = Class.new(BGP::Neighbor)
|
15
|
+
N300 = Class.new(BGP::Neighbor)
|
16
|
+
|
17
|
+
class RecvMsgHandler
|
18
|
+
def initialize(q)
|
19
|
+
@q = q
|
20
|
+
end
|
21
|
+
def update(bgp_msg)
|
22
|
+
@q.enq bgp_msg
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def setup
|
27
|
+
@n100 = N100.new(:my_as=> 100, :remote_addr => '40.0.0.2', :local_addr => '40.0.0.1', :id=> '13.11.19.59')
|
28
|
+
@n300 = N300.new(:my_as=> 300, :remote_addr => '40.0.1.1', :local_addr => '40.0.1.2', :id=> '13.11.19.57')
|
29
|
+
start_peering
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_verify_that_200_is_prepended_to_aspath
|
33
|
+
assert @n100.is_established?, "Expected to be in Established state. <> #{@n100.state}"
|
34
|
+
assert @n300.is_established?, "Expected to be in Established state. <> #{@n300.state}"
|
35
|
+
queue = Queue.new
|
36
|
+
@n300.add_observer RecvMsgHandler.new(queue)
|
37
|
+
send_update_to @n100
|
38
|
+
msg = recv(queue)
|
39
|
+
assert msg, "Did not receive expected BGP update message."
|
40
|
+
assert msg.path_attribute.has?(As_path)
|
41
|
+
assert_not_nil msg.path_attribute[:as_path]
|
42
|
+
assert_equal '200 100', msg.path_attribute[:as_path].as_path
|
43
|
+
end
|
44
|
+
|
45
|
+
def teardown
|
46
|
+
[@n100, @n300].each { |n| n.stop }
|
47
|
+
sleep(0.5)
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def start_peering
|
53
|
+
[@n100, @n300].each { |n|
|
54
|
+
n.capability :as4_byte
|
55
|
+
n.start
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
def recv(q, timeout=5)
|
60
|
+
begin
|
61
|
+
Timeout::timeout(timeout) do |t|
|
62
|
+
msg = q.deq
|
63
|
+
end
|
64
|
+
rescue Timeout::Error => e
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def update1
|
70
|
+
update = Update.new(
|
71
|
+
Path_attribute.new(
|
72
|
+
Origin.new(0),
|
73
|
+
Next_hop.new('40.0.0.1'),
|
74
|
+
Multi_exit_disc.new(100),
|
75
|
+
Local_pref.new(100),
|
76
|
+
As_path.new(100),
|
77
|
+
Communities.new('1311:1 311:59 2805:64')
|
78
|
+
),
|
79
|
+
Nlri.new('77.0.0.0/17', '78.0.0.0/18', '79.0.0.0/19')
|
80
|
+
)
|
81
|
+
end
|
82
|
+
|
83
|
+
def send_update_to(n)
|
84
|
+
n.send_message update1
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
data/test/message_test.rb
CHANGED
@@ -125,6 +125,14 @@ class Update_Test < Test::Unit::TestCase
|
|
125
125
|
an_update << Nlri.new('21.0.0.0/11', '22.0.0.0/22')
|
126
126
|
assert_equal 4, an_update.nlri.size
|
127
127
|
end
|
128
|
+
|
129
|
+
def test_6
|
130
|
+
s = 'ffffffffffffffffffffffffffffffff004a02000000274001010040020a0202000000c80000006440030428000101c0080c0137003b051f00010af50040114d0000124e0000134f0000'
|
131
|
+
m = Message.factory([s].pack('H*'), true)
|
132
|
+
assert_not_nil m
|
133
|
+
assert_instance_of(Update, m)
|
134
|
+
assert m.as4byte?
|
135
|
+
end
|
128
136
|
|
129
137
|
end
|
130
138
|
|
data/test/neighbor_test.rb
CHANGED
@@ -40,11 +40,24 @@ class TestBgpNeighbor < Test::Unit::TestCase
|
|
40
40
|
neighbor.capability Route_refresh_cap.new
|
41
41
|
neighbor.capability Route_refresh_cap.new 128
|
42
42
|
neighbor.capability As4_cap.new(100)
|
43
|
-
open_msg = neighbor.
|
43
|
+
open_msg = neighbor.open
|
44
44
|
assert_equal(5,open_msg.opt_parms.size)
|
45
45
|
assert_equal(4,open_msg.version)
|
46
46
|
assert_equal(20,open_msg.holdtime)
|
47
47
|
assert_equal(100,open_msg.local_as)
|
48
48
|
# puts neighbor
|
49
49
|
end
|
50
|
+
def test_states
|
51
|
+
neighbor = Neighbor.new \
|
52
|
+
:version=> 4,
|
53
|
+
:my_as=> 100,
|
54
|
+
:remote_addr => '192.168.1.200',
|
55
|
+
:local_addr => '192.168.1.5',
|
56
|
+
:id=> '1.1.1.1',
|
57
|
+
:holdtime=> 20
|
58
|
+
assert neighbor.is_idle?
|
59
|
+
assert ! neighbor.is_established?
|
60
|
+
assert ! neighbor.is_openrecv?
|
61
|
+
assert ! neighbor.is_openconfirm?
|
62
|
+
end
|
50
63
|
end
|
data/test/path_attribute_test.rb
CHANGED
@@ -124,4 +124,15 @@ class Path_attribute_Test < Test::Unit::TestCase # :nodoc:
|
|
124
124
|
|
125
125
|
end
|
126
126
|
|
127
|
+
def test_4
|
128
|
+
s = '4001010040020a0202000000c80000006440030428000101c0080c0137003b051f00010af50040'
|
129
|
+
sbin = [s].pack('H*')
|
130
|
+
assert_instance_of(Origin, attr = Attr.factory(sbin))
|
131
|
+
assert_instance_of(As_path, attr = Attr.factory(sbin,true))
|
132
|
+
assert_equal '200 100', attr.as_path
|
133
|
+
assert_instance_of(Next_hop, Attr.factory(sbin,true))
|
134
|
+
assert_instance_of(Communities, Attr.factory(sbin,true))
|
135
|
+
assert_equal 0, sbin.size
|
136
|
+
end
|
137
|
+
|
127
138
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 7
|
9
|
+
version: 0.0.7
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jean-Michel Esnault
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-09-12 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -57,11 +57,14 @@ files:
|
|
57
57
|
- bgp/path_attribute.rb
|
58
58
|
- bgp/prefix_orf.rb
|
59
59
|
- bgp/rd.rb
|
60
|
+
- bgp/version.rb
|
60
61
|
- bgp4r.gemspec
|
61
62
|
- bgp4r.rb
|
62
|
-
- examples/bgp
|
63
63
|
- examples/routegen
|
64
64
|
- examples/routegen.yml
|
65
|
+
- examples/simple.rb
|
66
|
+
- examples/unit-testing/malformed_update.rb
|
67
|
+
- examples/unit-testing/prepend_aspath.rb
|
65
68
|
- test/aggregator_test.rb
|
66
69
|
- test/as_path_test.rb
|
67
70
|
- test/atomic_aggregate_test.rb
|
@@ -97,7 +100,6 @@ rdoc_options:
|
|
97
100
|
require_paths:
|
98
101
|
- .
|
99
102
|
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
-
none: false
|
101
103
|
requirements:
|
102
104
|
- - ">="
|
103
105
|
- !ruby/object:Gem::Version
|
@@ -107,7 +109,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
109
|
- 6
|
108
110
|
version: 1.8.6
|
109
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
-
none: false
|
111
112
|
requirements:
|
112
113
|
- - ">="
|
113
114
|
- !ruby/object:Gem::Version
|
@@ -117,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
118
|
requirements: []
|
118
119
|
|
119
120
|
rubyforge_project: bgp4r
|
120
|
-
rubygems_version: 1.3.
|
121
|
+
rubygems_version: 1.3.6
|
121
122
|
signing_key:
|
122
123
|
specification_version: 3
|
123
124
|
summary: A BGP-4 Ruby Library
|
/data/examples/{bgp → simple.rb}
RENAMED
File without changes
|