bgp4r 0.0.15 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 71db0cc737f4499799b737953e4cfa4659601d80
|
4
|
+
data.tar.gz: c002a569edc6e2c77daa7d0fc4288ba675798820
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 61dbb8e76c0191d02ba0080b4e43a54cdb68566516bdba06edb90b7d8610ce86c24b0f151c4a3c97bdca455c5320817fadd45930ef66df28fe7b6ad42c391809
|
7
|
+
data.tar.gz: 65d345be33cae08fea7290cea4ee8d45f78231eaf2afc8169f1ad0e9a8ac08b950e8c644a264cd60ba928cad78b3d50867326fb23cb0aed48403c3b7a979e7b8
|
data/bgp/common.rb
CHANGED
@@ -55,10 +55,21 @@ class IPAddr
|
|
55
55
|
def +(i)
|
56
56
|
[IPAddr.create(to_i + i).to_s, mlen].join("/")
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
|
+
def increment
|
59
60
|
@increment ||= _generate_network_inc_
|
60
|
-
[IPAddr.create(to_i + @increment.call(i)).to_s, mlen].join("/")
|
61
61
|
end
|
62
|
+
|
63
|
+
def ^(i)
|
64
|
+
x = to_i + increment.call(i)
|
65
|
+
if ipv4?
|
66
|
+
[IPAddr.create(x).to_s, mlen].join("/")
|
67
|
+
else
|
68
|
+
y = [(format "%032x",x)].pack('H*')
|
69
|
+
[IPAddr.new_ntoh(y).to_s ,mlen].join("/")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
62
73
|
private :_generate_network_inc_
|
63
74
|
|
64
75
|
def netmask
|
data/bgp/io.rb
CHANGED
data/bgp/messages/keepalive.rb
CHANGED
@@ -22,9 +22,13 @@ module BGP
|
|
22
22
|
class Keepalive < Message
|
23
23
|
def initialize
|
24
24
|
@msg_type=KEEPALIVE
|
25
|
+
@keepalive=[[0xffffffff]*4,"001304"].flatten.pack('NNNNH6')
|
25
26
|
end
|
26
27
|
def to_s
|
27
28
|
"Keepalive Message (#{KEEPALIVE}), length: 19" + ", [#{self.to_shex[32..-1]}]"
|
28
29
|
end
|
30
|
+
def encode
|
31
|
+
@keepalive
|
32
|
+
end
|
29
33
|
end
|
30
34
|
end
|
data/bgp/messages/message.rb
CHANGED
data/bgp/neighbor/neighbor.rb
CHANGED
@@ -243,7 +243,9 @@ module BGP
|
|
243
243
|
|
244
244
|
def send_message(m)
|
245
245
|
raise if m.nil?
|
246
|
-
|
246
|
+
unless @out
|
247
|
+
log_warn "Could not Send#{m.class.to_s.split('::')[-1]} @out is nil"
|
248
|
+
end
|
247
249
|
unless m.is_a?(String)
|
248
250
|
log_info "Send#{m.class.to_s.split('::')[-1]}"
|
249
251
|
log_debug "Send #{m.is_a?(Update) ? m.to_s : m }\n"
|
@@ -0,0 +1,28 @@
|
|
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 'bgp/common'
|
11
|
+
|
12
|
+
module BGP
|
13
|
+
class Ipv4_mapped < IPAddr
|
14
|
+
def initialize(ipaddr)
|
15
|
+
super
|
16
|
+
raise unless ipv4?
|
17
|
+
end
|
18
|
+
def nexthop
|
19
|
+
to_s
|
20
|
+
end
|
21
|
+
def encode(*args)
|
22
|
+
[0,0,0,0xffff,hton].pack('N2n2a*')
|
23
|
+
end
|
24
|
+
alias encode_next_hop encode
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
load "../../test/unit/nlris/#{ File.basename($0.gsub(/.rb/,'_test.rb'))}" if __FILE__ == $0
|
data/bgp/nlris/nlris.rb
CHANGED
@@ -31,18 +31,24 @@ module BGP
|
|
31
31
|
if args[0].is_a?(String) and args[0].is_packed?
|
32
32
|
parse(*args)
|
33
33
|
elsif args.size==2 and
|
34
|
-
args[0].is_a?(String) and
|
34
|
+
args[0].is_a?(String) and args[1].is_a?(Integer)
|
35
35
|
@ip_address = IPAddr.create(args[0])
|
36
|
-
|
36
|
+
self.asn = args[1]
|
37
37
|
elsif args[0].is_a?(self.class)
|
38
38
|
parse(args[0].encode, *args[1..-1])
|
39
39
|
elsif args[0].is_a?(Hash)
|
40
40
|
@ip_address = IPAddr.create(args[0][:address])
|
41
|
-
|
41
|
+
self.asn = args[0][:asn]
|
42
42
|
else
|
43
43
|
raise ArgumentError, "invalid argument, #{args.inspect}"
|
44
44
|
end
|
45
45
|
end
|
46
|
+
|
47
|
+
def asn=(arg)
|
48
|
+
raise unless arg.is_a?(Integer)
|
49
|
+
@as=arg
|
50
|
+
end
|
51
|
+
|
46
52
|
|
47
53
|
def address=(val)
|
48
54
|
@ip_address=IPAddr.create(val)
|
@@ -268,16 +268,16 @@ module BGP
|
|
268
268
|
|
269
269
|
class << self
|
270
270
|
def new_set(*args)
|
271
|
-
new_hash :set=>args
|
271
|
+
new_hash :set=>args.flatten
|
272
272
|
end
|
273
273
|
def new_sequence(*args)
|
274
|
-
new_hash :sequence=>args
|
274
|
+
new_hash :sequence=>args.flatten
|
275
275
|
end
|
276
276
|
def new_confed_set(*args)
|
277
|
-
new_hash :confed_set=>args
|
277
|
+
new_hash :confed_set=>args.flatten
|
278
278
|
end
|
279
279
|
def new_confed_sequence(*args)
|
280
|
-
new_hash :confed_sequence=>args
|
280
|
+
new_hash :confed_sequence=>args.flatten
|
281
281
|
end
|
282
282
|
end
|
283
283
|
end
|
@@ -98,9 +98,42 @@ module BGP
|
|
98
98
|
s.join("\n")
|
99
99
|
end
|
100
100
|
|
101
|
+
def insert(*args)
|
102
|
+
for arg in args
|
103
|
+
next unless arg.is_a?(Extended_community)
|
104
|
+
communities.insert(0,arg)
|
105
|
+
end
|
106
|
+
self
|
107
|
+
end
|
108
|
+
|
109
|
+
def append(*args)
|
110
|
+
for arg in args
|
111
|
+
next unless arg.is_a?(Extended_community)
|
112
|
+
communities << (arg)
|
113
|
+
end
|
114
|
+
self
|
115
|
+
end
|
116
|
+
|
117
|
+
def replace(*args)
|
118
|
+
for arg in args
|
119
|
+
next unless arg.is_a?(Extended_community)
|
120
|
+
ind = communities.find_index { |x| x.class == arg.class }
|
121
|
+
if ind
|
122
|
+
communities[ind] = arg
|
123
|
+
else
|
124
|
+
append(arg)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
self
|
128
|
+
end
|
129
|
+
|
101
130
|
def find(klass)
|
102
131
|
communities.find { |c| c.is_a?(klass) }
|
103
132
|
end
|
133
|
+
|
134
|
+
def find_all(klass)
|
135
|
+
communities.find_all { |c| c.is_a?(klass) }
|
136
|
+
end
|
104
137
|
|
105
138
|
%w{
|
106
139
|
color
|
@@ -112,7 +145,12 @@ module BGP
|
|
112
145
|
ospf_router_id
|
113
146
|
}.each do |ecom|
|
114
147
|
define_method("#{ecom}") do
|
115
|
-
|
148
|
+
ecs = find_all(BGP.const_get(ecom.capitalize))
|
149
|
+
ecs.size==1 ? ecs[0] : ecs
|
150
|
+
end
|
151
|
+
define_method("#{ecom}=") do |*args|
|
152
|
+
k = BGP.const_get(ecom.capitalize)
|
153
|
+
replace(k.new(*args))
|
116
154
|
end
|
117
155
|
end
|
118
156
|
|
@@ -62,7 +62,7 @@ module BGP
|
|
62
62
|
case self
|
63
63
|
when Color
|
64
64
|
_,@global = s.unpack('nN')
|
65
|
-
when Encapsulation
|
65
|
+
# when Encapsulation
|
66
66
|
_,@global = s.unpack('Nn')
|
67
67
|
else
|
68
68
|
@global = s.unpack('H12')
|
@@ -175,8 +175,8 @@ module BGP
|
|
175
175
|
case self
|
176
176
|
when BGP::Color
|
177
177
|
[0,@global].pack('nN')
|
178
|
-
when BGP::Encapsulation
|
179
|
-
|
178
|
+
# when BGP::Encapsulation
|
179
|
+
# [0,@global].pack('Nn')
|
180
180
|
else
|
181
181
|
[@global].pack('H12')
|
182
182
|
end
|
@@ -209,9 +209,10 @@ module BGP
|
|
209
209
|
when BGP_DATA_COLLECT ; Bgp_data_collect.new(s)
|
210
210
|
when LINK_BANDWIDTH ; Link_bandwidth.new(s)
|
211
211
|
when COLOR ; Color.new(s)
|
212
|
-
when ENCAPSULATION ; Encapsulation.new(s)
|
212
|
+
# when ENCAPSULATION ; Encapsulation.new(s)
|
213
213
|
else
|
214
214
|
puts "too bad type #{type.to_s(16)}, subtype #{subtype.to_s(16)} : #{s.unpack('H*')}"
|
215
|
+
raise
|
215
216
|
Extended_community.new(s)
|
216
217
|
end
|
217
218
|
end
|
@@ -248,7 +249,7 @@ module BGP
|
|
248
249
|
if args[0].is_a?(String) and args[0].is_packed?
|
249
250
|
super(*args)
|
250
251
|
else
|
251
|
-
super(0, ROUTE_TARGET, *args)
|
252
|
+
super(*[0, ROUTE_TARGET, *args].flatten)
|
252
253
|
end
|
253
254
|
end
|
254
255
|
end
|
@@ -258,7 +259,7 @@ module BGP
|
|
258
259
|
if args[0].is_a?(String) and args[0].is_packed?
|
259
260
|
super(*args)
|
260
261
|
else
|
261
|
-
super(0,ROUTE_ORIGIN,*args)
|
262
|
+
super(*[0,ROUTE_ORIGIN,*args].flatten)
|
262
263
|
end
|
263
264
|
end
|
264
265
|
end
|
@@ -339,33 +340,38 @@ module BGP
|
|
339
340
|
end
|
340
341
|
end
|
341
342
|
|
342
|
-
class Encapsulation < Opaque
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
end
|
343
|
+
# class Encapsulation < Opaque
|
344
|
+
# def initialize(*args)
|
345
|
+
# args = 0 if args.empty?
|
346
|
+
# if args[0].is_a?(String) and args[0].is_packed?
|
347
|
+
# super(*args)
|
348
|
+
# else
|
349
|
+
# case args[0]
|
350
|
+
# when :l2tpv3 ; tunnel_type = 1
|
351
|
+
# when :gre ; tunnel_type = 2
|
352
|
+
# when :ipip ; tunnel_type = 7
|
353
|
+
# else
|
354
|
+
# tunnel_type = *args
|
355
|
+
# end
|
356
|
+
# super(TRANSITIVE, ENCAPSULATION, tunnel_type)
|
357
|
+
# end
|
358
|
+
# end
|
359
|
+
# def value2
|
360
|
+
# case @global
|
361
|
+
# when 1 ; :l2tpv3
|
362
|
+
# when 2 ; :gre
|
363
|
+
# when 7 ; :ipip
|
364
|
+
# else
|
365
|
+
# @global
|
366
|
+
# end
|
367
|
+
# end
|
368
|
+
# end
|
368
369
|
|
369
370
|
end
|
370
371
|
|
372
|
+
|
373
|
+
|
374
|
+
__END__
|
375
|
+
|
376
|
+
|
371
377
|
load "../../test/unit/path_attributes/#{ File.basename($0.gsub(/.rb/,'_test.rb'))}" if __FILE__ == $0
|
@@ -34,7 +34,7 @@ module BGP
|
|
34
34
|
def set(h)
|
35
35
|
@safi = h[:safi]
|
36
36
|
@path_id = h[:path_id]
|
37
|
-
@afi = h
|
37
|
+
@afi = h[:afi] || self.class.afi_from_nlris(h[:nlris])
|
38
38
|
case safi
|
39
39
|
when 1,2
|
40
40
|
pfx_klass = prefix_klass(afi, safi)
|
@@ -66,7 +66,7 @@ module BGP
|
|
66
66
|
else
|
67
67
|
raise "SAFI #{safi} not implemented!"
|
68
68
|
end
|
69
|
-
@nexthops = [h[:nexthop]].flatten.collect { |nh| nexthop_klass(afi,safi).new(nh) } if h[:nexthop]
|
69
|
+
@nexthops = [h[:nexthop]].flatten.collect { |nh| nexthop_klass(afi,safi,nh).new(nh) } if h[:nexthop]
|
70
70
|
self
|
71
71
|
end
|
72
72
|
|
@@ -106,6 +106,8 @@ module BGP
|
|
106
106
|
when Hash
|
107
107
|
_arg = arg[:prefix]
|
108
108
|
else
|
109
|
+
p "**********************"
|
110
|
+
p arg
|
109
111
|
raise
|
110
112
|
end
|
111
113
|
|
@@ -159,6 +161,7 @@ module BGP
|
|
159
161
|
elsif args[0].is_a?(Hash) and args.size==1
|
160
162
|
set(*args)
|
161
163
|
else
|
164
|
+
p args
|
162
165
|
raise ArgumentError, "invalid argument"
|
163
166
|
end
|
164
167
|
end
|
@@ -286,14 +289,18 @@ module BGP
|
|
286
289
|
|
287
290
|
private
|
288
291
|
|
289
|
-
def nexthop_klass(afi, safi)
|
292
|
+
def nexthop_klass(afi, safi, nh)
|
290
293
|
case afi
|
291
294
|
when 3
|
292
295
|
::BGP::const_get('Iso_ip_mapped')
|
293
296
|
else
|
294
297
|
case safi
|
295
298
|
when 1,2,4
|
296
|
-
|
299
|
+
if afi==2 && IPAddr.new(nh).ipv4?
|
300
|
+
::BGP::const_get('Ipv4_mapped')
|
301
|
+
else
|
302
|
+
::BGP::const_get('Prefix')
|
303
|
+
end
|
297
304
|
when 128,129
|
298
305
|
::BGP::const_get('Vpn')
|
299
306
|
else
|
@@ -240,6 +240,12 @@ module BGP
|
|
240
240
|
@attributes.find { |a| a.is_a?(k) }
|
241
241
|
end
|
242
242
|
eval "alias :has_an_#{attr}? :has_a_#{attr}_attr?" if (attr =~ /^[aeiou]/)
|
243
|
+
|
244
|
+
define_method("#{attr}=") do |*args|
|
245
|
+
k = BGP.const_get(attr.capitalize)
|
246
|
+
replace(k.new(*args))
|
247
|
+
end
|
248
|
+
|
243
249
|
end
|
244
250
|
|
245
251
|
def to_hash
|
@@ -260,7 +266,13 @@ module BGP
|
|
260
266
|
end
|
261
267
|
|
262
268
|
def method_missing(name, *args, &block)
|
263
|
-
|
269
|
+
if name.to_s == 'med='
|
270
|
+
multi_exit_disc= *args
|
271
|
+
elsif name.to_s =~ /^as_path_(.+)=$/
|
272
|
+
replace(As_path, As_path.send("new_#{$1}", *args))
|
273
|
+
else
|
274
|
+
super
|
275
|
+
end
|
264
276
|
end
|
265
277
|
|
266
278
|
end
|
@@ -346,14 +358,6 @@ module BGP
|
|
346
358
|
end
|
347
359
|
|
348
360
|
end
|
349
|
-
|
350
|
-
# require 'bgp/path_attributes/local_pref'
|
351
|
-
# require 'bgp/path_attributes/next_hop'
|
352
|
-
# require 'bgp/path_attributes/multi_exit_disc'
|
353
|
-
#
|
354
|
-
# p = Path_attribute.new :local_pref=>100, :next_hop => '10.0.0.1', :med=>300
|
355
|
-
# # p p
|
356
|
-
# puts p
|
357
361
|
|
358
362
|
end
|
359
363
|
load "../../test/unit/path_attributes/#{ File.basename($0.gsub(/.rb/,'_test.rb'))}" if __FILE__ == $0
|
data/bgp4r.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "bgp4r"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.16"
|
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 = "
|
12
|
+
s.date = "2014-05-07"
|
13
13
|
s.description = "BGP4R is a BGP-4 ruby library to create, send, and receive BGP messages in an object oriented manner"
|
14
14
|
s.email = "bgp4r@esnault.org"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -44,6 +44,7 @@ Gem::Specification.new do |s|
|
|
44
44
|
"bgp/nlris/prefix.rb",
|
45
45
|
"bgp/nlris/rd.rb",
|
46
46
|
"bgp/nlris/vpn.rb",
|
47
|
+
"bgp/nlris/mapped_ipv4.rb",
|
47
48
|
"bgp/optional_parameters/add_path.rb",
|
48
49
|
"bgp/optional_parameters/as4.rb",
|
49
50
|
"bgp/optional_parameters/capabilities.rb",
|
@@ -84,6 +85,7 @@ Gem::Specification.new do |s|
|
|
84
85
|
"examples/unit-testing/no_export_test.rb",
|
85
86
|
"examples/unit-testing/prepend_aspath_test.rb",
|
86
87
|
"examples/unit-testing/unknown_transitive_attr_test.rb",
|
88
|
+
"examples/bgp-vyatta-ipv6.rb",
|
87
89
|
"test/functional/add_path_test.rb",
|
88
90
|
"test/functional/live_feed_test.rb",
|
89
91
|
"test/helpers/server.rb",
|
@@ -108,6 +110,7 @@ Gem::Specification.new do |s|
|
|
108
110
|
"test/unit/nlris/prefix_test.rb",
|
109
111
|
"test/unit/nlris/rd_test.rb",
|
110
112
|
"test/unit/nlris/vpn_test.rb",
|
113
|
+
"test/unit/nlris/mapped_ipv4_test.rb",
|
111
114
|
"test/unit/optional_parameters/add_path_test.rb",
|
112
115
|
"test/unit/optional_parameters/as4_test.rb",
|
113
116
|
"test/unit/optional_parameters/capability_test.rb",
|
@@ -135,7 +138,6 @@ Gem::Specification.new do |s|
|
|
135
138
|
"test/unit/path_attributes/origin_test.rb",
|
136
139
|
"test/unit/path_attributes/originator_id_test.rb",
|
137
140
|
"test/unit/path_attributes/path_attribute_test.rb",
|
138
|
-
"test/unit/path_attributes/tunnel_encapsulation_test (Jean-Michel's Laptop's conflicted copy 2011-11-02).rb"
|
139
141
|
]
|
140
142
|
s.homepage = "http://github.com/jesnault/bgp4r/tree/master"
|
141
143
|
s.require_paths = ["."]
|
@@ -143,7 +145,7 @@ Gem::Specification.new do |s|
|
|
143
145
|
s.rubyforge_project = "bgp4r"
|
144
146
|
s.rubygems_version = "1.8.11"
|
145
147
|
s.summary = "A BGP-4 Ruby Library"
|
146
|
-
s.test_files = ["test/functional", "test/functional/add_path_test.rb", "test/functional/live_feed_test.rb", "test/helpers", "test/helpers/server.rb", "test/misc", "test/misc/misc.rb", "test/unit", "test/unit/common_test.rb", "test/unit/iana_test.rb", "test/unit/messages", "test/unit/messages/capability_test.rb", "test/unit/messages/keepalive_test.rb", "test/unit/messages/markers_test.rb", "test/unit/messages/message_test.rb", "test/unit/messages/notification_test.rb", "test/unit/messages/open_test.rb", "test/unit/messages/route_refresh_test.rb", "test/unit/messages/update_test.rb", "test/unit/neighbor", "test/unit/neighbor/add_path_cap_test.rb", "test/unit/neighbor/neighbor_test.rb", "test/unit/nlris", "test/unit/nlris/inet_test.rb", "test/unit/nlris/label_test.rb", "test/unit/nlris/labeled_test.rb", "test/unit/nlris/nlri_test.rb", "test/unit/nlris/nsap_test.rb", "test/unit/nlris/prefix_test.rb", "test/unit/nlris/rd_test.rb", "test/unit/nlris/vpn_test.rb", "test/unit/optional_parameters", "test/unit/optional_parameters/add_path_test.rb", "test/unit/optional_parameters/as4_test.rb", "test/unit/optional_parameters/capability_test.rb", "test/unit/optional_parameters/dynamic_test.rb", "test/unit/optional_parameters/graceful_restart_test.rb", "test/unit/optional_parameters/mbgp_test.rb", "test/unit/optional_parameters/optional_parameter_test.rb", "test/unit/optional_parameters/orf_test.rb", "test/unit/optional_parameters/route_refresh_test.rb", "test/unit/orfs", "test/unit/orfs/prefix_orf_test.rb", "test/unit/path_attributes", "test/unit/path_attributes/aggregator_test.rb", "test/unit/path_attributes/aigp_test.rb", "test/unit/path_attributes/as_path_test.rb", "test/unit/path_attributes/atomic_aggregate_test.rb", "test/unit/path_attributes/attribute_test.rb", "test/unit/path_attributes/cluster_list_test.rb", "test/unit/path_attributes/communities_test.rb", "test/unit/path_attributes/extended_communities_test.rb", "test/unit/path_attributes/extended_community_test.rb", "test/unit/path_attributes/local_pref_test.rb", "test/unit/path_attributes/mp_reach_test.rb", "test/unit/path_attributes/mp_unreach_test.rb", "test/unit/path_attributes/multi_exit_disc_test.rb", "test/unit/path_attributes/next_hop_test.rb", "test/unit/path_attributes/origin_test.rb", "test/unit/path_attributes/originator_id_test.rb", "test/unit/path_attributes/path_attribute_test.rb"
|
148
|
+
s.test_files = ["test/functional", "test/functional/add_path_test.rb", "test/functional/live_feed_test.rb", "test/helpers", "test/helpers/server.rb", "test/misc", "test/misc/misc.rb", "test/unit", "test/unit/common_test.rb", "test/unit/iana_test.rb", "test/unit/messages", "test/unit/messages/capability_test.rb", "test/unit/messages/keepalive_test.rb", "test/unit/messages/markers_test.rb", "test/unit/messages/message_test.rb", "test/unit/messages/notification_test.rb", "test/unit/messages/open_test.rb", "test/unit/messages/route_refresh_test.rb", "test/unit/messages/update_test.rb", "test/unit/neighbor", "test/unit/neighbor/add_path_cap_test.rb", "test/unit/neighbor/neighbor_test.rb", "test/unit/nlris", "test/unit/nlris/inet_test.rb", "test/unit/nlris/label_test.rb", "test/unit/nlris/labeled_test.rb", "test/unit/nlris/nlri_test.rb", "test/unit/nlris/nsap_test.rb", "test/unit/nlris/prefix_test.rb", "test/unit/nlris/rd_test.rb", "test/unit/nlris/vpn_test.rb", "test/unit/optional_parameters", "test/unit/optional_parameters/add_path_test.rb", "test/unit/optional_parameters/as4_test.rb", "test/unit/optional_parameters/capability_test.rb", "test/unit/optional_parameters/dynamic_test.rb", "test/unit/optional_parameters/graceful_restart_test.rb", "test/unit/optional_parameters/mbgp_test.rb", "test/unit/optional_parameters/optional_parameter_test.rb", "test/unit/optional_parameters/orf_test.rb", "test/unit/optional_parameters/route_refresh_test.rb", "test/unit/orfs", "test/unit/orfs/prefix_orf_test.rb", "test/unit/path_attributes", "test/unit/path_attributes/aggregator_test.rb", "test/unit/path_attributes/aigp_test.rb", "test/unit/path_attributes/as_path_test.rb", "test/unit/path_attributes/atomic_aggregate_test.rb", "test/unit/path_attributes/attribute_test.rb", "test/unit/path_attributes/cluster_list_test.rb", "test/unit/path_attributes/communities_test.rb", "test/unit/path_attributes/extended_communities_test.rb", "test/unit/path_attributes/extended_community_test.rb", "test/unit/path_attributes/local_pref_test.rb", "test/unit/path_attributes/mp_reach_test.rb", "test/unit/path_attributes/mp_unreach_test.rb", "test/unit/path_attributes/multi_exit_disc_test.rb", "test/unit/path_attributes/next_hop_test.rb", "test/unit/path_attributes/origin_test.rb", "test/unit/path_attributes/originator_id_test.rb", "test/unit/path_attributes/path_attribute_test.rb"]
|
147
149
|
|
148
150
|
if s.respond_to? :specification_version then
|
149
151
|
s.specification_version = 3
|
data/bgp4r.rb
CHANGED
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'bgp4r'
|
2
|
+
|
3
|
+
include BGP
|
4
|
+
|
5
|
+
Log.create
|
6
|
+
Log.level=Logger::INFO
|
7
|
+
|
8
|
+
neighbor = Neighbor.new \
|
9
|
+
:version=> 4,
|
10
|
+
:my_as=> 100,
|
11
|
+
:remote_addr => '169.253.253.102',
|
12
|
+
:id=> '20.20.20.20',
|
13
|
+
:holdtime=> 180
|
14
|
+
|
15
|
+
neighbor.capability_mbgp_ipv4_unicast
|
16
|
+
neighbor.capability_mbgp_ipv6_unicast
|
17
|
+
|
18
|
+
nexthop='fe80::20c:29ff:fcab:13b'
|
19
|
+
|
20
|
+
pa = Path_attribute.new(
|
21
|
+
Origin.new(0),
|
22
|
+
Multi_exit_disc.new(0),
|
23
|
+
As_path.new(),
|
24
|
+
)
|
25
|
+
|
26
|
+
# 22 routes, 5 routes per update
|
27
|
+
subnet = Fiber.new do
|
28
|
+
ipaddr = IPAddr.new "2014:13:11::1/65"
|
29
|
+
pack=5
|
30
|
+
prefixes=[]
|
31
|
+
22.times do |i|
|
32
|
+
prefixes << (ipaddr ^ i)
|
33
|
+
next unless (i%pack)==0
|
34
|
+
Fiber.yield prefixes
|
35
|
+
prefixes=[]
|
36
|
+
end
|
37
|
+
Fiber.yield prefixes unless prefixes.empty?
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
|
41
|
+
neighbor.start
|
42
|
+
|
43
|
+
while nets = subnet.resume
|
44
|
+
neighbor.send_message Update.new pa.replace(Mp_reach.new(:afi=>2, :safi=>1, :nexthop=> nexthop, :nlris=> nets))
|
45
|
+
end
|
46
|
+
|
47
|
+
sleep(300)
|
48
|
+
|
49
|
+
__END__
|
50
|
+
|
51
|
+
|
52
|
+
I, [11:26#26571] INFO -- : BGP::Neighbor RecvOpen old state OpenSent new state OpenConfirm
|
53
|
+
I, [11:26#26571] INFO -- : BGP::Neighbor RecvKeepalive
|
54
|
+
D, [11:26#26571] DEBUG -- : BGP::Neighbor Recv Keepalive Message (4), length: 19, [001304]
|
55
|
+
|
56
|
+
I, [11:26#26571] INFO -- : BGP::Neighbor SendKeepalive
|
57
|
+
D, [11:26#26571] DEBUG -- : BGP::Neighbor Send Keepalive Message (4), length: 19, [001304]
|
58
|
+
|
59
|
+
D, [11:26#26571] DEBUG -- : BGP::Neighbor SendKeepAlive state is OpenConfirm
|
60
|
+
I, [11:26#26571] INFO -- : BGP::Neighbor RecvKeepAlive old state OpenConfirm new state Established
|
61
|
+
I, [11:26#26571] INFO -- : BGP::Neighbor RecvKeepalive
|
62
|
+
D, [11:26#26571] DEBUG -- : BGP::Neighbor Recv Keepalive Message (4), length: 19, [001304]
|
63
|
+
|
64
|
+
I, [11:26#26571] INFO -- : BGP::Neighbor version: 4, id: 20.20.20.20, as: 100, holdtime: 180, peer addr: 169.253.253.102, local addr: started
|
65
|
+
I, [11:26#26571] INFO -- : BGP::Neighbor SendUpdate
|
66
|
+
I, [11:26#26571] INFO -- : BGP::Neighbor SendUpdate
|
67
|
+
I, [11:26#26571] INFO -- : BGP::Neighbor SendUpdate
|
68
|
+
I, [11:26#26571] INFO -- : BGP::Neighbor SendUpdate
|
69
|
+
I, [11:26#26571] INFO -- : BGP::Neighbor SendUpdate
|
70
|
+
I, [11:26#26571] INFO -- : BGP::Neighbor SendUpdate
|
71
|
+
I, [11:27#26571] INFO -- : BGP::Neighbor RecvUpdate
|
72
|
+
I, [12:26#26571] INFO -- : BGP::Neighbor SendKeepalive
|
73
|
+
I, [12:26#26571] INFO -- : BGP::Neighbor RecvKeepalive
|
74
|
+
|
75
|
+
|
76
|
+
root@vyatta:~# show ipv6 route
|
77
|
+
Codes: K - kernel route, C - connected, S - static, R - RIPng, O - OSPFv3,
|
78
|
+
I - ISIS, B - BGP, * - FIB route.
|
79
|
+
|
80
|
+
C>* ::1/128 is directly connected, lo
|
81
|
+
B>* 2014:13:11::/65 [200/0] via fe80::20c:29ff:fcab:13b, eth9, 00:01:01
|
82
|
+
B>* 2014:13:11:0:8000::/65 [200/0] via fe80::20c:29ff:fcab:13b, eth9, 00:01:01
|
83
|
+
B>* 2014:13:11:1::/65 [200/0] via fe80::20c:29ff:fcab:13b, eth9, 00:01:01
|
84
|
+
B>* 2014:13:11:1:8000::/65 [200/0] via fe80::20c:29ff:fcab:13b, eth9, 00:01:01
|
85
|
+
B>* 2014:13:11:2::/65 [200/0] via fe80::20c:29ff:fcab:13b, eth9, 00:01:01
|
86
|
+
B>* 2014:13:11:2:8000::/65 [200/0] via fe80::20c:29ff:fcab:13b, eth9, 00:01:01
|
87
|
+
B>* 2014:13:11:3::/65 [200/0] via fe80::20c:29ff:fcab:13b, eth9, 00:01:01
|
88
|
+
B>* 2014:13:11:3:8000::/65 [200/0] via fe80::20c:29ff:fcab:13b, eth9, 00:01:01
|
89
|
+
B>* 2014:13:11:4::/65 [200/0] via fe80::20c:29ff:fcab:13b, eth9, 00:01:01
|
90
|
+
B>* 2014:13:11:4:8000::/65 [200/0] via fe80::20c:29ff:fcab:13b, eth9, 00:01:01
|
91
|
+
B>* 2014:13:11:5::/65 [200/0] via fe80::20c:29ff:fcab:13b, eth9, 00:01:01
|
92
|
+
B>* 2014:13:11:5:8000::/65 [200/0] via fe80::20c:29ff:fcab:13b, eth9, 00:01:01
|
93
|
+
B>* 2014:13:11:6::/65 [200/0] via fe80::20c:29ff:fcab:13b, eth9, 00:01:01
|
94
|
+
B>* 2014:13:11:6:8000::/65 [200/0] via fe80::20c:29ff:fcab:13b, eth9, 00:01:01
|
95
|
+
B>* 2014:13:11:7::/65 [200/0] via fe80::20c:29ff:fcab:13b, eth9, 00:01:01
|
96
|
+
B>* 2014:13:11:7:8000::/65 [200/0] via fe80::20c:29ff:fcab:13b, eth9, 00:01:01
|
97
|
+
B>* 2014:13:11:8::/65 [200/0] via fe80::20c:29ff:fcab:13b, eth9, 00:01:01
|
98
|
+
B>* 2014:13:11:8:8000::/65 [200/0] via fe80::20c:29ff:fcab:13b, eth9, 00:01:01
|
99
|
+
B>* 2014:13:11:9::/65 [200/0] via fe80::20c:29ff:fcab:13b, eth9, 00:01:01
|
100
|
+
B>* 2014:13:11:9:8000::/65 [200/0] via fe80::20c:29ff:fcab:13b, eth9, 00:01:01
|
101
|
+
B>* 2014:13:11:a::/65 [200/0] via fe80::20c:29ff:fcab:13b, eth9, 00:01:01
|
102
|
+
B>* 2014:13:11:a:8000::/65 [200/0] via fe80::20c:29ff:fcab:13b, eth9, 00:01:01
|
103
|
+
C * fe80::/64 is directly connected, eth9
|
104
|
+
C>* fe80::/64 is directly connected, eth6
|
105
|
+
root@vyatta:~#
|
106
|
+
|
107
|
+
|
108
|
+
vyatta@vyatta:~$ show interfaces
|
109
|
+
Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down
|
110
|
+
Interface IP Address S/L Description
|
111
|
+
--------- ---------- --- -----------
|
112
|
+
eth6 192.168.244.153/24 u/u
|
113
|
+
eth9 169.253.253.102/24 u/u
|
114
|
+
lo 127.0.0.1/8 u/u
|
115
|
+
::1/128
|
116
|
+
|
117
|
+
vyatta@vyatta:~$ show configuration
|
118
|
+
interfaces {
|
119
|
+
ethernet eth6 {
|
120
|
+
duplex auto
|
121
|
+
hw-id 00:0c:29:6b:52:a9
|
122
|
+
smp_affinity auto
|
123
|
+
speed auto
|
124
|
+
}
|
125
|
+
ethernet eth9 {
|
126
|
+
address dhcp
|
127
|
+
duplex auto
|
128
|
+
hw-id 00:0c:29:6b:52:9f
|
129
|
+
smp_affinity auto
|
130
|
+
speed auto
|
131
|
+
}
|
132
|
+
loopback lo {
|
133
|
+
}
|
134
|
+
}
|
135
|
+
protocols {
|
136
|
+
bgp 100 {
|
137
|
+
neighbor 169.253.253.1 {
|
138
|
+
address-family {
|
139
|
+
ipv6-unicast {
|
140
|
+
}
|
141
|
+
}
|
142
|
+
remote-as 100
|
143
|
+
}
|
144
|
+
parameters {
|
145
|
+
router-id 1.2.3.4
|
146
|
+
}
|
147
|
+
}
|
148
|
+
}
|