bgp4r 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/bgp/common.rb +0 -1
- data/bgp/messages/capability.rb +5 -5
- data/bgp/messages/message.rb +2 -1
- data/bgp/messages/messages.rb +8 -20
- data/bgp/messages/notification.rb +1 -1
- data/bgp/messages/update.rb +14 -15
- data/bgp/misc/live_feed.rb +15 -20
- data/bgp/nlris/label.rb +1 -1
- data/bgp/nlris/nlris.rb +8 -32
- data/bgp/nlris/vpn.rb +8 -1
- data/bgp/optional_parameters/capabilities.rb +8 -4
- data/bgp/path_attributes/attributes.rb +16 -21
- data/bgp/path_attributes/communities.rb +6 -0
- data/bgp/path_attributes/path_attribute.rb +0 -1
- data/bgp4r.gemspec +7 -2
- data/test/messages/capability_test.rb +4 -4
- data/test/messages/markers_test.rb +4 -3
- data/test/messages/notification_test.rb +2 -2
- data/test/messages/update_test.rb +13 -9
- data/test/misc/live_feed_test.rb +16 -0
- data/test/misc/misc.rb +13 -0
- data/test/nlris/nlri_test.rb +1 -42
- data/test/optional_parameters/optional_parameter_test.rb +10 -10
- data/test/path_attributes/communities_test.rb +7 -6
- data/test/path_attributes/local_pref_test.rb +0 -8
- data/test/path_attributes/multi_exit_disc_test.rb +0 -8
- metadata +7 -3
data/bgp/common.rb
CHANGED
data/bgp/messages/capability.rb
CHANGED
@@ -69,11 +69,11 @@ module BGP
|
|
69
69
|
@seqn = seqn
|
70
70
|
@cap = cap
|
71
71
|
elsif args.size==1 && args.is_a?(String)
|
72
|
-
|
73
|
-
|
74
|
-
|
72
|
+
else
|
73
|
+
parse args[0]
|
74
|
+
end
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
def encode
|
78
78
|
[@o1,@seqn, @cap.encode].pack('CNa*')
|
79
79
|
end
|
@@ -142,7 +142,7 @@ module BGP
|
|
142
142
|
parse args[0]
|
143
143
|
else
|
144
144
|
@msg_type=CAPABILITY
|
145
|
-
add
|
145
|
+
add(*args)
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
data/bgp/messages/message.rb
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
# along with BGP4R. If not, see <http://www.gnu.org/licenses/>.
|
21
21
|
#++
|
22
22
|
|
23
|
-
module BGP
|
23
|
+
module ::BGP
|
24
24
|
|
25
25
|
# http://www.iana.org/assignments/bgp-parameters/bgp-parameters.xhtml#bgp-parameters-1
|
26
26
|
|
@@ -90,6 +90,7 @@ module BGP
|
|
90
90
|
! has_no_path_attribute?
|
91
91
|
end
|
92
92
|
end
|
93
|
+
|
93
94
|
end
|
94
95
|
|
95
96
|
load "../../test/messages/#{ File.basename($0.gsub(/.rb/,'_test.rb'))}" if __FILE__ == $0
|
data/bgp/messages/messages.rb
CHANGED
@@ -1,21 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
%w{ update keepalive open notification capabity}.each do |m|
|
11
|
-
autoload "#{m}".capitalize.to_sym, "bgp/messages/#{m}"
|
12
|
-
end
|
13
|
-
autoload :Route_refresh, 'bgp/messages/route_refresh'
|
14
|
-
autoload :Orf_route_refresh, 'bgp/messages/route_refresh'
|
15
|
-
autoload :Prefix_orf, 'bgp/orfs/prefix_orf'
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
|
1
|
+
require 'bgp/messages/message'
|
2
|
+
require 'bgp/messages/keepalive'
|
3
|
+
require 'bgp/messages/update'
|
4
|
+
require 'bgp/messages/capability'
|
5
|
+
require 'bgp/messages/notification'
|
6
|
+
require 'bgp/messages/open'
|
7
|
+
require 'bgp/messages/route_refresh'
|
8
|
+
require 'bgp/orfs/prefix_orf'
|
21
9
|
require 'bgp/messages/markers'
|
@@ -108,7 +108,7 @@ class Notification < Message
|
|
108
108
|
msg = self.encode
|
109
109
|
s = "Notification (#{NOTIFICATION}), length: #{msg.size}: "
|
110
110
|
s += "#{Notification.code_to_s(@code)} (#{@code}), #{Notification.code_to_s(@code, @subcode)} (#{@subcode}) "
|
111
|
-
s += "\ndata: [#{@data}]" if @data.size>0
|
111
|
+
s += "\ndata: [#{@data}]" if @data and @data.size>0
|
112
112
|
s
|
113
113
|
end
|
114
114
|
|
data/bgp/messages/update.rb
CHANGED
@@ -40,14 +40,13 @@
|
|
40
40
|
require 'bgp/messages/message'
|
41
41
|
require 'bgp/path_attributes/path_attribute'
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
class Update < Message
|
43
|
+
class BGP::Update < BGP::Message
|
44
|
+
include BGP
|
46
45
|
def as4byte?
|
47
46
|
@as4byte ||= false
|
48
47
|
end
|
49
48
|
alias as4byte as4byte?
|
50
|
-
|
49
|
+
|
51
50
|
def initialize(*args)
|
52
51
|
if args[0].is_a?(String) and args[0].is_packed?
|
53
52
|
@as4byte=false
|
@@ -59,7 +58,7 @@ class Update < Message
|
|
59
58
|
set(*args)
|
60
59
|
end
|
61
60
|
end
|
62
|
-
|
61
|
+
|
63
62
|
def set(*args)
|
64
63
|
args.each { |arg|
|
65
64
|
if arg.is_a?(Withdrawn)
|
@@ -71,19 +70,19 @@ class Update < Message
|
|
71
70
|
end
|
72
71
|
}
|
73
72
|
end
|
74
|
-
|
73
|
+
|
75
74
|
def withdrawn=(val)
|
76
75
|
@withdrawn=val if val.is_a?(Withdrawn)
|
77
76
|
end
|
78
|
-
|
77
|
+
|
79
78
|
def nlri=(val)
|
80
79
|
@nlri=val if val.is_a?(Nlri)
|
81
80
|
end
|
82
|
-
|
81
|
+
|
83
82
|
def path_attribute=(val)
|
84
83
|
@path_attribute=val if val.is_a?(Path_attribute)
|
85
84
|
end
|
86
|
-
|
85
|
+
|
87
86
|
def encode(as4byte=false)
|
88
87
|
@as4byte=as4byte
|
89
88
|
withdrawn, path_attribute, nlri = '', '', ''
|
@@ -92,13 +91,13 @@ class Update < Message
|
|
92
91
|
nlri = @nlri.encode if defined? @nlri and @nlri
|
93
92
|
super([withdrawn.size, withdrawn, path_attribute.size, path_attribute, nlri].pack('na*na*a*'))
|
94
93
|
end
|
95
|
-
|
94
|
+
|
96
95
|
def encode4
|
97
96
|
encode(true)
|
98
97
|
end
|
99
|
-
|
98
|
+
|
100
99
|
attr_reader :path_attribute, :nlri, :withdrawn
|
101
|
-
|
100
|
+
|
102
101
|
# CHANGED ME: NO DEFAULT HERE, the factory calling us has to tell what it is giving us.
|
103
102
|
def parse(s, as4byte=false)
|
104
103
|
@as4byte=as4byte
|
@@ -110,7 +109,7 @@ class Update < Message
|
|
110
109
|
self.path_attribute=Path_attribute.new(enc_path_attribute, as4byte) if len>0
|
111
110
|
self.nlri = Nlri.new(update) if update.size>0
|
112
111
|
end
|
113
|
-
|
112
|
+
|
114
113
|
def <<(val)
|
115
114
|
if val.is_a?(Attr)
|
116
115
|
@path_attribute ||= Path_attribute.new
|
@@ -137,7 +136,7 @@ class Update < Message
|
|
137
136
|
s << @nlri.to_s if defined?(@nlri) and @nlri
|
138
137
|
"Update Message (#{UPDATE}), #{as4byte ? "4 bytes AS, " : ''}length: #{msg.size}\n " + s.join("\n") + "\n" + msg.hexlify.join("\n") + "\n"
|
139
138
|
end
|
140
|
-
|
139
|
+
|
141
140
|
def self.withdrawn(u)
|
142
141
|
if u.nlri and u.nlri.size>0
|
143
142
|
Update.new(Withdrawn.new(*(u.nlri.nlris.collect { |n| n.to_s})))
|
@@ -149,4 +148,4 @@ class Update < Message
|
|
149
148
|
end
|
150
149
|
end
|
151
150
|
|
152
|
-
|
151
|
+
load "../../test/messages/#{ File.basename($0.gsub(/.rb/,'_test.rb'))}" if __FILE__ == $0
|
data/bgp/misc/live_feed.rb
CHANGED
@@ -1,29 +1,23 @@
|
|
1
|
-
require 'net/telnet'
|
1
|
+
#require 'net/telnet'
|
2
2
|
require 'bgp4r'
|
3
3
|
|
4
|
-
|
5
4
|
class LiveFeed
|
6
|
-
def
|
7
|
-
|
8
|
-
@port = '50001'
|
9
|
-
@timeout = 10
|
5
|
+
def self.open
|
6
|
+
new.open
|
10
7
|
end
|
11
|
-
|
12
8
|
def open
|
13
|
-
|
9
|
+
@host = '129.82.138.6'
|
10
|
+
@port = '50001'
|
14
11
|
@buf = ''
|
15
12
|
@queue = Queue.new
|
16
13
|
|
17
14
|
th = Thread.new do
|
18
|
-
feed =
|
19
|
-
'Port' => @port,
|
20
|
-
'Timeout'=> 5,
|
21
|
-
'Telnetmode' => false)
|
15
|
+
@feed = TCPSocket.new @host, @port
|
22
16
|
loop do
|
23
|
-
@buf += feed.recv(
|
17
|
+
@buf += @feed.recv(5000)
|
24
18
|
end
|
25
19
|
end
|
26
|
-
Thread.new do
|
20
|
+
@th=Thread.new do
|
27
21
|
loop do
|
28
22
|
pos = (@buf =~ /<OCTETS length=.*>([^<]*)<\/OCTETS>/)
|
29
23
|
if pos
|
@@ -33,17 +27,18 @@ class LiveFeed
|
|
33
27
|
end
|
34
28
|
end
|
35
29
|
end
|
30
|
+
self
|
31
|
+
end
|
32
|
+
def close
|
33
|
+
@th.kill
|
34
|
+
@feed.close
|
36
35
|
end
|
37
|
-
|
38
36
|
def read
|
39
37
|
@queue.deq
|
40
38
|
end
|
41
|
-
|
42
39
|
alias msg read
|
43
40
|
alias readmessage read
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
41
|
|
42
|
+
end
|
43
|
+
#
|
49
44
|
|
data/bgp/nlris/label.rb
CHANGED
data/bgp/nlris/nlris.rb
CHANGED
@@ -1,32 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
module BGP
|
24
|
-
end
|
25
|
-
|
26
|
-
%w{ nlri prefix labeled vpn rd }.each do |n|
|
27
|
-
BGP.autoload n.capitalize.to_sym,"bgp/nlris/#{n}"
|
28
|
-
end
|
29
|
-
|
30
|
-
BGP.autoload :Inet_unicast, "bgp/nlris/inet"
|
31
|
-
BGP.autoload :Inet_multicast, "bgp/nlris/inet"
|
32
|
-
BGP.autoload :Withdrawn, "bgp/nlris/nlri"
|
1
|
+
%w{
|
2
|
+
nlri
|
3
|
+
prefix
|
4
|
+
inet
|
5
|
+
labeled
|
6
|
+
vpn
|
7
|
+
rd
|
8
|
+
}.each { |n| require "bgp/nlris/#{n}" }
|
data/bgp/nlris/vpn.rb
CHANGED
@@ -52,10 +52,17 @@ module BGP
|
|
52
52
|
@prefix.ipv6?
|
53
53
|
end
|
54
54
|
def parse(s, afi=1)
|
55
|
+
# p "-----------"
|
56
|
+
# p s.unpack('H*')
|
57
|
+
# p afi
|
55
58
|
nbits = s.slice!(0,1).unpack('C')[0]
|
56
59
|
rd,vpn = s.slice!(0,(7+nbits)/8).unpack("a8a*")
|
57
60
|
@rd = Rd.new(rd.is_packed)
|
58
|
-
|
61
|
+
# p @rd
|
62
|
+
# p nbits
|
63
|
+
# p vpn.unpack('H*')
|
64
|
+
raise if nbits-64==0
|
65
|
+
@prefix= Prefix.new([nbits-64,vpn].pack('Ca*'), afi) if nbits-64>0
|
59
66
|
end
|
60
67
|
def nexthop
|
61
68
|
@prefix.nexthop
|
@@ -1,8 +1,12 @@
|
|
1
|
-
require 'bgp/optional_parameters/capability'
|
2
1
|
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
require 'bgp/optional_parameters/capability'
|
3
|
+
require 'bgp/optional_parameters/dynamic'
|
4
|
+
require 'bgp/optional_parameters/graceful_restart'
|
5
|
+
require 'bgp/optional_parameters/mbgp'
|
6
|
+
require 'bgp/optional_parameters/optional_parameter'
|
7
|
+
require 'bgp/optional_parameters/orf'
|
8
|
+
require 'bgp/optional_parameters/route_refresh'
|
9
|
+
require 'bgp/optional_parameters/as4'
|
6
10
|
|
7
11
|
module BGP::OPT_PARM
|
8
12
|
module DYN_CAP
|
@@ -1,22 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
}.each do |attr|
|
18
|
-
autoload attr.capitalize.to_sym,"bgp/path_attributes/#{attr}"
|
19
|
-
end
|
20
|
-
autoload :As4_path, 'bgp/path_attributes/as_path'
|
1
|
+
%w{
|
2
|
+
origin next_hop
|
3
|
+
local_pref
|
4
|
+
multi_exit_disc
|
5
|
+
as_path
|
6
|
+
communities
|
7
|
+
aggregator
|
8
|
+
atomic_aggregate
|
9
|
+
originator_id
|
10
|
+
cluster_list
|
11
|
+
mp_reach
|
12
|
+
mp_unreach
|
13
|
+
extended_communities
|
14
|
+
path_attribute
|
15
|
+
}.each do |attr|
|
16
|
+
require "bgp/path_attributes/#{attr}"
|
21
17
|
end
|
22
|
-
|
@@ -147,6 +147,12 @@ module BGP
|
|
147
147
|
|
148
148
|
%w{ no_export no_advertise no_export_sub_confed no_peer }.each do |wkc|
|
149
149
|
define_method("has_#{wkc}?") do
|
150
|
+
has? Community.const_get(wkc.upcase)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
%w{ no_export no_advertise no_export_sub_confed no_peer }.each do |wkc|
|
155
|
+
define_method("does_not_have_#{wkc}?") do
|
150
156
|
! has? Community.const_get(wkc.upcase)
|
151
157
|
end
|
152
158
|
end
|
data/bgp4r.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
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.11"
|
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{
|
12
|
+
s.date = %q{2011-01-08}
|
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
14
|
s.email = %q{jesnault@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -89,6 +89,8 @@ Gem::Specification.new do |s|
|
|
89
89
|
"test/messages/open_test.rb",
|
90
90
|
"test/messages/route_refresh_test.rb",
|
91
91
|
"test/messages/update_test.rb",
|
92
|
+
"test/misc/live_feed_test.rb",
|
93
|
+
"test/misc/misc.rb",
|
92
94
|
"test/neighbor_test.rb",
|
93
95
|
"test/nlris/ext_nlri_test.rb",
|
94
96
|
"test/nlris/inet_test.rb",
|
@@ -139,6 +141,9 @@ Gem::Specification.new do |s|
|
|
139
141
|
"test/messages/open_test.rb",
|
140
142
|
"test/messages/route_refresh_test.rb",
|
141
143
|
"test/messages/update_test.rb",
|
144
|
+
"test/misc",
|
145
|
+
"test/misc/live_feed_test.rb",
|
146
|
+
"test/misc/misc.rb",
|
142
147
|
"test/neighbor_test.rb",
|
143
148
|
"test/nlris",
|
144
149
|
"test/nlris/ext_nlri_test.rb",
|
@@ -70,18 +70,18 @@ class TestBgpMessagesCapability < Test::Unit::TestCase
|
|
70
70
|
include BGP::OPT_PARM
|
71
71
|
def test_capability_1
|
72
72
|
cap_msg = BGP::Capability.new
|
73
|
-
assert_equal
|
73
|
+
assert_equal('ffffffffffffffffffffffffffffffff001306', cap_msg.to_shex)
|
74
74
|
cap_msg << BGP::Capability::Revision.advertise( 10, DYN_CAP::Mbgp.new(1,1))
|
75
|
-
assert_match
|
75
|
+
assert_match(/^(ff){16}001f06000000000a01000400010001/, cap_msg.to_shex)
|
76
76
|
cap_msg << BGP::Capability::Revision.advertise( 20, DYN_CAP::Mbgp.new(1,2))
|
77
|
-
assert_match
|
77
|
+
assert_match(/^(ff){16}002b06\s*000000000a01000400010001\s*000000001401000400010002/, cap_msg.to_shex)
|
78
78
|
end
|
79
79
|
def test_capability_2
|
80
80
|
cap_msg = BGP::Capability.new(
|
81
81
|
BGP::Capability::Revision.advertise( 10, DYN_CAP::Mbgp.new(1,1)),
|
82
82
|
BGP::Capability::Revision.advertise( 20, DYN_CAP::Mbgp.new(1,2))
|
83
83
|
)
|
84
|
-
assert_match
|
84
|
+
assert_match(/^(ff){16}002b06\s*000000000a01000400010001\s*000000001401000400010002/, cap_msg.to_shex)
|
85
85
|
end
|
86
86
|
def test_capability_3
|
87
87
|
|
@@ -23,11 +23,12 @@
|
|
23
23
|
require 'test/unit'
|
24
24
|
require 'bgp4r'
|
25
25
|
require 'bgp/messages/markers'
|
26
|
+
require 'bgp/nlris/nlris'
|
26
27
|
class End_of_rib_markers_Test < Test::Unit::TestCase
|
27
28
|
include BGP
|
28
29
|
def test_end_of_rib_maker_messages
|
29
|
-
assert_match
|
30
|
-
assert_match
|
31
|
-
assert_match
|
30
|
+
assert_match(/(ff){16}00170200000000/, Update.end_of_rib_marker.to_shex)
|
31
|
+
assert_match(/(ff){16}001d0200000006800f03000104/, Update.end_of_rib_marker(:afi=>1, :safi=>4).to_shex)
|
32
|
+
assert_match(/(ff){16}001d0200000006800f03000180/, Update.end_of_rib_marker(:afi=>1, :safi=>128).to_shex)
|
32
33
|
end
|
33
34
|
end
|
@@ -36,10 +36,10 @@ class Notification_Test < Test::Unit::TestCase
|
|
36
36
|
assert_equal('Invalid Capability Length', Notification.code_to_s(7,2))
|
37
37
|
assert_equal('Malformed Capability Value', Notification.code_to_s(7,3))
|
38
38
|
notif = BGP::Notification.new(1,1)
|
39
|
-
assert_match
|
39
|
+
assert_match(/^(ff){16}0015030101$/, notif.to_shex)
|
40
40
|
assert_equal(notif.encode, Notification.new(notif).encode)
|
41
41
|
notif = BGP::Notification.new(2,2,'some data')
|
42
|
-
assert_match
|
42
|
+
assert_match(/(ff){16}001e030202736f6d652064617461/, notif.to_shex)
|
43
43
|
assert_equal(notif.encode, Notification.new(notif).encode)
|
44
44
|
s = 'ffffffffffffffffffffffffffffffff001e030202736f6d652064617461'
|
45
45
|
m = Message.factory([s].pack('H*'))
|
@@ -128,7 +128,7 @@ class Update_Test < Test::Unit::TestCase
|
|
128
128
|
"
|
129
129
|
end
|
130
130
|
|
131
|
-
def
|
131
|
+
def test_8
|
132
132
|
s = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0072020000001F4001010040020A0204212C051319351AFE400304557200D9C00804212C045C175D76D6175D76DE1659299C175929981659235C16592D6417592D6417592D6617592D6217C3D228185D73241859284417C3FE84165C727015592190'
|
133
133
|
m = Update.new([s].pack('H*'), true)
|
134
134
|
pa = m.path_attribute
|
@@ -140,12 +140,15 @@ class Update_Test < Test::Unit::TestCase
|
|
140
140
|
assert_equal '100 556533011 422910718', pa[As_path].as_path
|
141
141
|
end
|
142
142
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
143
|
+
def test_9
|
144
|
+
s = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF002302000C16D403741755C68816D408300000'
|
145
|
+
m = Update.new([s].pack('H*'))
|
146
|
+
assert m.withdrawn, "Should contain withdrawn routes."
|
147
|
+
assert_equal 3,m.withdrawn.nlris.size
|
148
|
+
end
|
149
|
+
|
150
|
+
#--
|
151
|
+
# def test_10
|
149
152
|
# s = 'ffff ffff ffff ffff ffff ffff ffff ffff
|
150
153
|
# 005f 0200 0000 4440 0101 0040 020e 0206
|
151
154
|
# 0064 212c 232a 0ddd 53f9 5ba0 4003 0428
|
@@ -154,8 +157,9 @@ class Update_Test < Test::Unit::TestCase
|
|
154
157
|
# 000d dd00 0053 f900 0302 9e18 5bd9 c5
|
155
158
|
# '.split.join
|
156
159
|
# m = Update.new([s].pack('H*'))
|
157
|
-
# p m
|
160
|
+
# p m.path_attribute[:next_hop]
|
161
|
+
# p m.path_attribute[:as_path]
|
158
162
|
# end
|
159
|
-
|
163
|
+
#++
|
160
164
|
|
161
165
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "bgp/misc/live_feed"
|
3
|
+
|
4
|
+
class TestBgpMiscLiveFeed < Test::Unit::TestCase
|
5
|
+
def test_feed
|
6
|
+
feed = LiveFeed.open
|
7
|
+
n=0
|
8
|
+
loop do
|
9
|
+
n+=1
|
10
|
+
break if n>20
|
11
|
+
msg_shex = feed.read.unpack('H*')[0]
|
12
|
+
assert_match( /ff{16}....(02|04|05|01)/, msg_shex)
|
13
|
+
end
|
14
|
+
feed.close
|
15
|
+
end
|
16
|
+
end
|
data/test/misc/misc.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
|
3
|
+
require "bgp4r"
|
4
|
+
|
5
|
+
class TestBgp4r < Test::Unit::TestCase
|
6
|
+
def test_1
|
7
|
+
s = "ffffffffffffffffffffffffffffffff0084020000006d400101024002008004040000000040050400000064c00804282b4e87c010080002282b00007530800a080000000100000004800904513411d2800e310001800c0000000000000000513411d2007401c4f100000c8f00126cdcac14b0907801c53100000c8f00126cdcac14b092"
|
8
|
+
msg = BGP::Message.factory([s].pack('H*'))
|
9
|
+
assert_equal BGP::Update, msg.class
|
10
|
+
end
|
11
|
+
def test_2
|
12
|
+
end
|
13
|
+
end
|
data/test/nlris/nlri_test.rb
CHANGED
@@ -92,34 +92,6 @@ class Withdrawn_Test < Test::Unit::TestCase
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
class Nlri_Test < Test::Unit::TestCase
|
96
|
-
include BGP
|
97
|
-
def test_1
|
98
|
-
nlri1 = Nlri.new
|
99
|
-
nlri1 << Nlri::Ip4.new('20.0.0.0/15')
|
100
|
-
nlri1 << '20.0.0.0/17'
|
101
|
-
nlri1 << '20.0.0.0/24'
|
102
|
-
s = '0f140010140011140000'
|
103
|
-
nlri2 = Nlri.new([s].pack('H*'))
|
104
|
-
assert_equal('0f140010140011140000', nlri2.to_shex)
|
105
|
-
assert_raise(ArgumentError) { nlri2.to_shex(true) }
|
106
|
-
assert_equal(3,nlri2.nlris.size)
|
107
|
-
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_2
|
111
|
-
nlri1 = Nlri.new
|
112
|
-
nlri1 << Nlri::Ip4.new('20.0.0.0/15')
|
113
|
-
nlri1 << '20.0.0.0/17'
|
114
|
-
nlri1 << '20.0.0.0/24'
|
115
|
-
s = '0f140010140011140000'
|
116
|
-
nlri2 = Nlri.new([s].pack('H*'))
|
117
|
-
assert_equal('0f140010140011140000', nlri2.to_shex)
|
118
|
-
assert_raise(ArgumentError) { nlri2.to_shex(true) }
|
119
|
-
assert_equal(3,nlri2.nlris.size)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
95
|
class Prefix_Test < Test::Unit::TestCase
|
124
96
|
include BGP
|
125
97
|
def test_1
|
@@ -130,23 +102,10 @@ class Prefix_Test < Test::Unit::TestCase
|
|
130
102
|
assert(Prefix.new('192.168.0.0/16').ipv4?)
|
131
103
|
assert_equal('10c0a8',Prefix.new('192.168.0.0/16').to_shex)
|
132
104
|
assert_equal('402009000400040000',Prefix.new('2009:4:4::/64').to_shex)
|
133
|
-
assert
|
105
|
+
assert Prefix.new('2009:4:4::/64').ipv6?
|
134
106
|
assert_equal('2009:4:4::/64',Prefix.new('2009:4:4::/64').to_s)
|
135
107
|
end
|
136
108
|
end
|
137
|
-
class Inet_unicast_Test < Test::Unit::TestCase
|
138
|
-
include BGP
|
139
|
-
def test_1
|
140
|
-
assert_equal(1,Inet_unicast.new('192.168.0.0/16').afi)
|
141
|
-
assert_equal(1,Inet_unicast.new('192.168.0.0/16').safi)
|
142
|
-
assert_equal(2,Inet_unicast.new('2009:4:4::/64').afi)
|
143
|
-
assert_equal(1,Inet_unicast.new('2009:4:4::/64').safi)
|
144
|
-
assert_equal(1,Inet_multicast.new('192.168.0.0/16').afi)
|
145
|
-
assert_equal(2,Inet_multicast.new('192.168.0.0/16').safi)
|
146
|
-
assert_equal(2,Inet_multicast.new('2009:4:4::/64').afi)
|
147
|
-
assert_equal(2,Inet_multicast.new('2009:4:4::/64').safi)
|
148
|
-
end
|
149
|
-
end
|
150
109
|
|
151
110
|
class Vpn_Test < Test::Unit::TestCase
|
152
111
|
include BGP
|
@@ -30,21 +30,21 @@ class Optional_parameter_Test < Test::Unit::TestCase
|
|
30
30
|
def octet.encode
|
31
31
|
[0xab].pack('C')
|
32
32
|
end
|
33
|
-
assert_match
|
34
|
-
Open.new(4, 100, 120, '1.1.1.1', *([octet]*254)).to_shex
|
35
|
-
assert_match
|
36
|
-
Open.new(4, 100, 120, '1.1.1.1', *([octet]*255)).to_shex
|
37
|
-
assert_match
|
38
|
-
Open.new(4, 100, 120, '1.1.1.1', *([octet]*256)).to_shex
|
39
|
-
assert_match
|
40
|
-
Open.new(4, 100, 120, '1.1.1.1', *([octet]*257)).to_shex
|
33
|
+
assert_match(/^(ff){16}011b01040064007801010101fe(ab){254}$/,
|
34
|
+
Open.new(4, 100, 120, '1.1.1.1', *([octet]*254)).to_shex)
|
35
|
+
assert_match(/^(ff){16}011c01040064007801010101ff(ab){255}$/,
|
36
|
+
Open.new(4, 100, 120, '1.1.1.1', *([octet]*255)).to_shex)
|
37
|
+
assert_match(/^(ff){16}012001040064007801010101ffff0100(ab){256}$/,
|
38
|
+
Open.new(4, 100, 120, '1.1.1.1', *([octet]*256)).to_shex)
|
39
|
+
assert_match(/^(ff){16}012101040064007801010101ffff0101(ab){257}$/,
|
40
|
+
Open.new(4, 100, 120, '1.1.1.1', *([octet]*257)).to_shex)
|
41
41
|
end
|
42
42
|
def test_draft_ietf_idr_ext_opt_param_01_parsing
|
43
43
|
mbgp = OPT_PARM::CAP::Mbgp.new(1,1)
|
44
44
|
open1 = Open.new(4, 100, 120, '1.1.1.1', *[mbgp]*100)
|
45
45
|
open2 = Open.new(4, 100, 120, '1.1.1.1', *[mbgp]*10)
|
46
|
-
assert_match
|
47
|
-
assert_match
|
46
|
+
assert_match(/^(ff){16}034001040064007801010101\s*ffff0320\s*0206010400010001/, open1.to_shex)
|
47
|
+
assert_match(/^(ff){16}006d01040064007801010101\s*50\s*0206010400010001/, open2.to_shex)
|
48
48
|
assert_equal Open.new(open1).to_shex, open1.to_shex
|
49
49
|
assert_equal Open.new(open2).to_shex, open2.to_shex
|
50
50
|
end
|
@@ -79,12 +79,13 @@ class Communities_Test < Test::Unit::TestCase
|
|
79
79
|
assert Communities.new("145:60 145:10 145:30 145:20").has?('145:60')
|
80
80
|
end
|
81
81
|
def test_4
|
82
|
-
assert
|
83
|
-
assert Communities.new("145:60 145:10").
|
84
|
-
assert
|
85
|
-
assert ! Communities.new("145:60 145:10").
|
86
|
-
assert
|
87
|
-
assert
|
82
|
+
assert ! Communities.new("145:60 145:10").has_no_export?, "Not expexted to contain [no_export] community"
|
83
|
+
assert Communities.new("145:60 145:10").does_not_have_no_export?, "Not expexted to contain [no_export] community"
|
84
|
+
assert ! Communities.new("145:60 145:10").has_no_advertise? , 'Not expected to contain [no_advertise] community'
|
85
|
+
assert ! Communities.new("145:60 145:10").has_no_export_sub_confed?, 'Not expected to contain [no_export_sub_confed] community'
|
86
|
+
assert Communities.new("145:60 145:10").add(:no_export_sub_confed).has_no_export_sub_confed?, 'expected to contain [no_export_sub_confed]'
|
87
|
+
assert Communities.new("145:60 145:10").add(:no_export).has_no_export?, 'expected to contain [no_export]'
|
88
|
+
assert Communities.new("145:60 145:10").add(:no_advertise).has_no_advertise?, 'expected to contain [no_advertise]'
|
88
89
|
end
|
89
90
|
end
|
90
91
|
|
@@ -40,12 +40,4 @@ class Local_pref_Test < Test::Unit::TestCase
|
|
40
40
|
lp1 = Local_pref.new(lp)
|
41
41
|
assert_equal(lp.encode, lp1.encode)
|
42
42
|
end
|
43
|
-
def test_3
|
44
|
-
lp = Local_pref.new(200)
|
45
|
-
assert_equal 200, lp.to_i
|
46
|
-
lp + 13
|
47
|
-
assert_equal 213, lp.to_i
|
48
|
-
lp + -13
|
49
|
-
assert_equal 200, lp.to_i
|
50
|
-
end
|
51
43
|
end
|
@@ -43,12 +43,4 @@ class Multi_exit_disc_Test < Test::Unit::TestCase
|
|
43
43
|
mp1 = Multi_exit_disc.new(mp)
|
44
44
|
assert_equal(mp.encode, mp.encode)
|
45
45
|
end
|
46
|
-
def test_3
|
47
|
-
med = Multi_exit_disc.new(200)
|
48
|
-
assert_equal 200, med.to_i
|
49
|
-
med + 13
|
50
|
-
assert_equal 213, med.to_i
|
51
|
-
med + -13
|
52
|
-
assert_equal 200, med.to_i
|
53
|
-
end
|
54
46
|
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
|
+
- 11
|
9
|
+
version: 0.0.11
|
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:
|
17
|
+
date: 2011-01-08 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -100,6 +100,8 @@ files:
|
|
100
100
|
- test/messages/open_test.rb
|
101
101
|
- test/messages/route_refresh_test.rb
|
102
102
|
- test/messages/update_test.rb
|
103
|
+
- test/misc/live_feed_test.rb
|
104
|
+
- test/misc/misc.rb
|
103
105
|
- test/neighbor_test.rb
|
104
106
|
- test/nlris/ext_nlri_test.rb
|
105
107
|
- test/nlris/inet_test.rb
|
@@ -173,6 +175,8 @@ test_files:
|
|
173
175
|
- test/messages/open_test.rb
|
174
176
|
- test/messages/route_refresh_test.rb
|
175
177
|
- test/messages/update_test.rb
|
178
|
+
- test/misc/live_feed_test.rb
|
179
|
+
- test/misc/misc.rb
|
176
180
|
- test/neighbor_test.rb
|
177
181
|
- test/nlris/ext_nlri_test.rb
|
178
182
|
- test/nlris/inet_test.rb
|