bgp4r 0.0.14 → 0.0.15
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/messages/message.rb +1 -0
- data/bgp/messages/update.rb +5 -0
- data/bgp/path_attributes/aggregator.rb +1 -1
- data/bgp/path_attributes/aigp.rb +3 -3
- data/bgp/path_attributes/attribute.rb +1 -1
- data/bgp/path_attributes/attributes.rb +3 -1
- data/bgp/path_attributes/cluster_list.rb +3 -20
- data/bgp/path_attributes/extended_communities.rb +38 -16
- data/bgp/path_attributes/extended_community.rb +5 -2
- data/bgp/path_attributes/multi_exit_disc.rb +1 -1
- data/bgp/path_attributes/originator_id.rb +2 -2
- data/bgp/path_attributes/path_attribute.rb +30 -39
- data/bgp4r.gemspec +9 -8
- data/test/unit/messages/update_test.rb +129 -8
- data/test/unit/path_attributes/aggregator_test.rb +1 -1
- data/test/unit/path_attributes/aigp_test.rb +3 -3
- data/test/unit/path_attributes/cluster_list_test.rb +2 -2
- data/test/unit/path_attributes/extended_communities_test.rb +27 -3
- data/test/unit/path_attributes/path_attribute_test.rb +84 -2
- metadata +3 -8
- data/bgp/path_attributes/tlvs/tlv.rb +0 -18
- data/examples/test.rb +0 -15
- data/examples/test2.rb +0 -116
- data/test/unit/path_attributes/tlvs/tlv_test.rb +0 -33
data/bgp/messages/message.rb
CHANGED
data/bgp/messages/update.rb
CHANGED
@@ -56,6 +56,7 @@ class BGP::Update < BGP::Message
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def initialize(*args, &block)
|
59
|
+
@msg_type=UPDATE
|
59
60
|
@nlri, @path_attribute, @withdrawn=nil,nil,nil
|
60
61
|
@session_info = Info.new
|
61
62
|
if args[0].is_a?(String) and args[0].is_packed?
|
@@ -66,6 +67,10 @@ class BGP::Update < BGP::Message
|
|
66
67
|
end
|
67
68
|
elsif args[0].is_a?(self.class)
|
68
69
|
parse(args[0].encode, *args[1..-1])
|
70
|
+
elsif args[0].is_a?(Hash)
|
71
|
+
@withdrawn = Withdrawn.new(*args[0][:withdrawns]) if args[0].has_key?(:withdrawns)
|
72
|
+
@path_attribute = Path_attribute.new(args[0][:path_attributes]) if args[0].has_key?(:path_attributes)
|
73
|
+
@nlri = Nlri.new(*args[0][:nlris]) if args[0].has_key?(:nlris)
|
69
74
|
else
|
70
75
|
@msg_type=UPDATE
|
71
76
|
set(*args)
|
data/bgp/path_attributes/aigp.rb
CHANGED
@@ -24,7 +24,7 @@ module BGP
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def to_hash
|
27
|
-
{:
|
27
|
+
{:aigp=> to_i}
|
28
28
|
end
|
29
29
|
|
30
30
|
def accumulated_igp_metric
|
@@ -51,8 +51,8 @@ module BGP
|
|
51
51
|
class Aigp
|
52
52
|
class << self
|
53
53
|
def new_hash(_arg={})
|
54
|
-
arg = {:
|
55
|
-
new arg[:
|
54
|
+
arg = {:aigp=>0}.merge(_arg)
|
55
|
+
new arg[:aigp]
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
@@ -55,6 +55,8 @@ module BGP
|
|
55
55
|
parse(args[0])
|
56
56
|
elsif args[0].is_a?(self.class)
|
57
57
|
parse(args[0].encode, *args[1..-1])
|
58
|
+
elsif args[0].is_a?(Hash)
|
59
|
+
add *args[0][:cluster_list]
|
58
60
|
else
|
59
61
|
add(*args)
|
60
62
|
end
|
@@ -102,7 +104,7 @@ module BGP
|
|
102
104
|
end
|
103
105
|
|
104
106
|
def to_hash
|
105
|
-
{:
|
107
|
+
{:cluster_list=>@cluster_ids.collect { |c| c.to_s }}
|
106
108
|
end
|
107
109
|
|
108
110
|
def sort!
|
@@ -116,25 +118,6 @@ module BGP
|
|
116
118
|
|
117
119
|
end
|
118
120
|
|
119
|
-
class Cluster_list
|
120
|
-
class << self
|
121
|
-
def new_hash(arg={})
|
122
|
-
o = new
|
123
|
-
[:cluster_ids].each do |set_type|
|
124
|
-
next unless arg.has_key? set_type
|
125
|
-
case set_type
|
126
|
-
when :cluster_ids
|
127
|
-
o << arg[set_type]
|
128
|
-
else
|
129
|
-
raise
|
130
|
-
end
|
131
|
-
end
|
132
|
-
o
|
133
|
-
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
121
|
end
|
139
122
|
|
140
123
|
load "../../test/unit/path_attributes/#{ File.basename($0.gsub(/.rb/,'_test.rb'))}" if __FILE__ == $0
|
@@ -29,20 +29,24 @@ module BGP
|
|
29
29
|
class Extended_communities < Attr
|
30
30
|
|
31
31
|
class << self
|
32
|
-
def new_hash(
|
32
|
+
def new_hash(*args)
|
33
|
+
raise unless args[0].is_a?(Hash)
|
33
34
|
o = new
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
35
|
+
args.each do |arg|
|
36
|
+
arg.keys.each do |comm|
|
37
|
+
case comm
|
38
|
+
when :extended_communities ; o = new_hash *args[0][:extended_communities]
|
39
|
+
when :color ; o << Color.new(*arg[comm])
|
40
|
+
when :route_target ; o << Route_target.new(*arg[comm])
|
41
|
+
when :link_bandwidth ; o << Link_bandwidth.new(*arg[comm])
|
42
|
+
when :ospf_domain_id ; o << Ospf_domain_id.new(*arg[comm])
|
43
|
+
when :encapsulation ; o << Encapsulation.new(*arg[comm])
|
44
|
+
when :route_origin ; o << Route_origin.new(*arg[comm])
|
45
|
+
when :ospf_router_id ; o << Ospf_router_id.new(*arg[comm])
|
46
|
+
else
|
47
|
+
raise
|
48
|
+
end
|
49
|
+
end
|
46
50
|
end
|
47
51
|
o
|
48
52
|
end
|
@@ -55,11 +59,13 @@ module BGP
|
|
55
59
|
|
56
60
|
if args[0].is_a?(String) and args[0].is_packed?
|
57
61
|
parse(args[0])
|
62
|
+
return
|
58
63
|
elsif args[0].is_a?(self.class)
|
59
64
|
parse(args[0].encode, *args[1..-1])
|
60
65
|
else
|
61
66
|
add(*args)
|
62
67
|
end
|
68
|
+
yield(self) if block_given?
|
63
69
|
end
|
64
70
|
|
65
71
|
def add(*args)
|
@@ -80,9 +86,7 @@ module BGP
|
|
80
86
|
alias << add
|
81
87
|
|
82
88
|
def to_hash
|
83
|
-
|
84
|
-
@communities.each { |c| h = h.merge( { c.class.to_s.split('::').last.downcase.to_sym => c.instance_eval { value2 } }) }
|
85
|
-
h
|
89
|
+
{:extended_communities=> @communities.collect { |c| c.to_hash }}
|
86
90
|
end
|
87
91
|
|
88
92
|
def extended_communities
|
@@ -94,6 +98,24 @@ module BGP
|
|
94
98
|
s.join("\n")
|
95
99
|
end
|
96
100
|
|
101
|
+
def find(klass)
|
102
|
+
communities.find { |c| c.is_a?(klass) }
|
103
|
+
end
|
104
|
+
|
105
|
+
%w{
|
106
|
+
color
|
107
|
+
route_target
|
108
|
+
link_bandwidth
|
109
|
+
ospf_domain_id
|
110
|
+
encapsulation
|
111
|
+
route_origin
|
112
|
+
ospf_router_id
|
113
|
+
}.each do |ecom|
|
114
|
+
define_method("#{ecom}") do
|
115
|
+
find(BGP.const_get(ecom.capitalize))
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
97
119
|
def to_s(method=:default)
|
98
120
|
super(extended_communities, method)
|
99
121
|
end
|
@@ -47,8 +47,7 @@ module BGP
|
|
47
47
|
FLOAT = -1
|
48
48
|
|
49
49
|
DEFAULT_OPAQUE_ENCODING = 'H12'
|
50
|
-
|
51
|
-
|
50
|
+
|
52
51
|
def encode
|
53
52
|
[@type, @subtype, _encoded_value_].pack('CCa6')
|
54
53
|
end
|
@@ -128,6 +127,10 @@ module BGP
|
|
128
127
|
def to_s
|
129
128
|
"#{name}: #{value}"
|
130
129
|
end
|
130
|
+
|
131
|
+
def to_hash
|
132
|
+
{ self.class.to_s.split('::').last.downcase.to_sym => value2 }
|
133
|
+
end
|
131
134
|
|
132
135
|
private
|
133
136
|
|
@@ -32,7 +32,7 @@ module BGP
|
|
32
32
|
|
33
33
|
class << self
|
34
34
|
def new_hash(arg={})
|
35
|
-
new arg[:
|
35
|
+
new arg[:originator_id]
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -69,7 +69,7 @@ module BGP
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def to_hash
|
72
|
-
{:
|
72
|
+
{:originator_id=> originator_id}
|
73
73
|
end
|
74
74
|
|
75
75
|
def originator_id=(val)
|
@@ -35,6 +35,7 @@ module BGP
|
|
35
35
|
@attributes=[]
|
36
36
|
while s.size>0
|
37
37
|
@attributes << Attr.factory(*args)
|
38
|
+
@attributes
|
38
39
|
end
|
39
40
|
elsif args.size ==1 and args[0].is_a?(Hash)
|
40
41
|
@attributes = []
|
@@ -48,13 +49,15 @@ module BGP
|
|
48
49
|
when :as_path ; As_path.new_hash(args[0][attr])
|
49
50
|
when :as4_path ; As4_path.new_hash(args[0][attr])
|
50
51
|
when :origin ; Origin.new(args[0][attr])
|
52
|
+
when :originator_id ; Originator_id.new(args[0][attr])
|
51
53
|
when :cluster_list ; Cluster_list.new(*args[0][attr])
|
52
54
|
when :aggregator ; Aggregator.new(args[0][attr])
|
53
55
|
when :as4_aggregator ; As4_aggregator.new(args[0][attr])
|
54
56
|
when :originator_id ; Originator_id.new(args[0][attr])
|
55
57
|
when :communities, :community; Communities.new(args[0][attr])
|
58
|
+
when :aigp ; Aigp.new(args[0][attr])
|
56
59
|
when :extended_communities, :extended_community
|
57
|
-
Extended_communities.new_hash(args[0][attr])
|
60
|
+
Extended_communities.new_hash(*args[0][attr])
|
58
61
|
when :atomic_aggregate ; Atomic_aggregate.new
|
59
62
|
# FIXME: add other attr here ...
|
60
63
|
else
|
@@ -192,7 +195,21 @@ module BGP
|
|
192
195
|
self
|
193
196
|
end
|
194
197
|
|
195
|
-
def
|
198
|
+
def sort
|
199
|
+
attributes.sort { |a,b| a.type <=> b.type }
|
200
|
+
Path_attribute.new(*attributes.sort { |a,b| a.type <=> b.type })
|
201
|
+
end
|
202
|
+
|
203
|
+
def sort!
|
204
|
+
attributes.sort! { |a,b| a.type <=> b.type }
|
205
|
+
self
|
206
|
+
end
|
207
|
+
|
208
|
+
def <=>(other)
|
209
|
+
self.sort.to_shex <=> other.sort.to_shex
|
210
|
+
end
|
211
|
+
|
212
|
+
def delete(*klasses)
|
196
213
|
for klass in klasses
|
197
214
|
next unless klass.is_a?(Class)
|
198
215
|
attributes.delete_if { |x| x.class == klass }
|
@@ -214,10 +231,14 @@ module BGP
|
|
214
231
|
mp_reach
|
215
232
|
mp_unreach
|
216
233
|
extended_communities
|
217
|
-
}.each do |attr|
|
234
|
+
}.each do |attr|
|
218
235
|
define_method("has_a_#{attr}_attr?") do
|
219
236
|
has? BGP.const_get(attr.capitalize)
|
220
237
|
end
|
238
|
+
define_method("#{attr}") do
|
239
|
+
k = BGP.const_get(attr.capitalize)
|
240
|
+
@attributes.find { |a| a.is_a?(k) }
|
241
|
+
end
|
221
242
|
eval "alias :has_an_#{attr}? :has_a_#{attr}_attr?" if (attr =~ /^[aeiou]/)
|
222
243
|
end
|
223
244
|
|
@@ -237,6 +258,11 @@ module BGP
|
|
237
258
|
when :communities, :community ; Communities
|
238
259
|
end
|
239
260
|
end
|
261
|
+
|
262
|
+
def method_missing(name, *args, &block)
|
263
|
+
super
|
264
|
+
end
|
265
|
+
|
240
266
|
end
|
241
267
|
end
|
242
268
|
|
@@ -318,39 +344,6 @@ module BGP
|
|
318
344
|
Unknown.new(s)
|
319
345
|
end
|
320
346
|
end
|
321
|
-
|
322
|
-
# def self.new_hash(_arg={:arg=>nil})
|
323
|
-
# #FIXME:
|
324
|
-
#
|
325
|
-
# arg = _arg.delete(:arg)
|
326
|
-
#
|
327
|
-
# if arg.is_a?(Neighbor::Capabilities)
|
328
|
-
# as4byte_flag = arg.as4byte?
|
329
|
-
# path_id_flag = arg
|
330
|
-
# elsif arg.is_a?(Hash)
|
331
|
-
# as4byte_flag=arg[:as4byte]
|
332
|
-
# path_id_flag=arg[:path_id]
|
333
|
-
# elsif arg.is_a?(TrueClass)
|
334
|
-
# as4byte_flag=true
|
335
|
-
# path_id_flag=nil
|
336
|
-
# elsif arg.respond_to? :as4byte?
|
337
|
-
# as4byte_flag = arg.as4byte?
|
338
|
-
# path_id_flag = arg
|
339
|
-
# else
|
340
|
-
# as4byte_flag=nil
|
341
|
-
# path_id_flag=nil
|
342
|
-
# end
|
343
|
-
#
|
344
|
-
# _arg.keys.each { |attr|
|
345
|
-
# case attr
|
346
|
-
# when :local_pref ; Local_pref.new(_arg[attr])
|
347
|
-
# when :next_hop ; Next_hop.new(_arg[attr])
|
348
|
-
# else
|
349
|
-
# end
|
350
|
-
# }
|
351
|
-
# end
|
352
|
-
|
353
|
-
|
354
347
|
|
355
348
|
end
|
356
349
|
|
@@ -360,9 +353,7 @@ module BGP
|
|
360
353
|
#
|
361
354
|
# p = Path_attribute.new :local_pref=>100, :next_hop => '10.0.0.1', :med=>300
|
362
355
|
# # p p
|
363
|
-
# puts p
|
364
|
-
|
365
|
-
|
356
|
+
# puts p
|
366
357
|
|
367
358
|
end
|
368
359
|
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.15"
|
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 = "2012-02-13"
|
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 = [
|
@@ -57,6 +57,7 @@ Gem::Specification.new do |s|
|
|
57
57
|
"bgp/orfs/orf.rb",
|
58
58
|
"bgp/orfs/prefix_orf.rb",
|
59
59
|
"bgp/path_attributes/aggregator.rb",
|
60
|
+
"bgp/path_attributes/aigp.rb",
|
60
61
|
"bgp/path_attributes/as_path.rb",
|
61
62
|
"bgp/path_attributes/atomic_aggregate.rb",
|
62
63
|
"bgp/path_attributes/attribute.rb",
|
@@ -79,8 +80,6 @@ Gem::Specification.new do |s|
|
|
79
80
|
"examples/routegen",
|
80
81
|
"examples/routegen.yml",
|
81
82
|
"examples/simple.rb",
|
82
|
-
"examples/test.rb",
|
83
|
-
"examples/test2.rb",
|
84
83
|
"examples/unit-testing/malformed_update_test.rb",
|
85
84
|
"examples/unit-testing/no_export_test.rb",
|
86
85
|
"examples/unit-testing/prepend_aspath_test.rb",
|
@@ -108,6 +107,7 @@ Gem::Specification.new do |s|
|
|
108
107
|
"test/unit/nlris/nsap_test.rb",
|
109
108
|
"test/unit/nlris/prefix_test.rb",
|
110
109
|
"test/unit/nlris/rd_test.rb",
|
110
|
+
"test/unit/nlris/vpn_test.rb",
|
111
111
|
"test/unit/optional_parameters/add_path_test.rb",
|
112
112
|
"test/unit/optional_parameters/as4_test.rb",
|
113
113
|
"test/unit/optional_parameters/capability_test.rb",
|
@@ -119,7 +119,7 @@ Gem::Specification.new do |s|
|
|
119
119
|
"test/unit/optional_parameters/route_refresh_test.rb",
|
120
120
|
"test/unit/orfs/prefix_orf_test.rb",
|
121
121
|
"test/unit/path_attributes/aggregator_test.rb",
|
122
|
-
"test/unit/path_attributes/
|
122
|
+
"test/unit/path_attributes/aigp_test.rb",
|
123
123
|
"test/unit/path_attributes/as_path_test.rb",
|
124
124
|
"test/unit/path_attributes/atomic_aggregate_test.rb",
|
125
125
|
"test/unit/path_attributes/attribute_test.rb",
|
@@ -134,15 +134,16 @@ Gem::Specification.new do |s|
|
|
134
134
|
"test/unit/path_attributes/next_hop_test.rb",
|
135
135
|
"test/unit/path_attributes/origin_test.rb",
|
136
136
|
"test/unit/path_attributes/originator_id_test.rb",
|
137
|
-
"test/unit/path_attributes/path_attribute_test.rb"
|
137
|
+
"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"
|
138
139
|
]
|
139
140
|
s.homepage = "http://github.com/jesnault/bgp4r/tree/master"
|
140
141
|
s.require_paths = ["."]
|
141
142
|
s.required_ruby_version = Gem::Requirement.new(">= 1.8.6")
|
142
143
|
s.rubyforge_project = "bgp4r"
|
143
|
-
s.rubygems_version = "1.8.
|
144
|
+
s.rubygems_version = "1.8.11"
|
144
145
|
s.summary = "A BGP-4 Ruby Library"
|
145
|
-
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/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/
|
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", "test/unit/path_attributes/tunnel_encapsulation_test (Jean-Michel's Laptop's conflicted copy 2011-11-02).rb"]
|
146
147
|
|
147
148
|
if s.respond_to? :specification_version then
|
148
149
|
s.specification_version = 3
|
@@ -51,12 +51,12 @@ class Update_Test < Test::Unit::TestCase
|
|
51
51
|
:path_attributes=> {
|
52
52
|
:origin=>:incomplete,
|
53
53
|
:as_path=>{},
|
54
|
-
:
|
54
|
+
:med=>0,
|
55
55
|
:local_pref=>100,
|
56
56
|
:communities=>["10283:20103"],
|
57
|
-
:route_target=>[10283, 30000],
|
58
|
-
:
|
59
|
-
:
|
57
|
+
:extended_communities=>[{:route_target=>[10283, 30000]}],
|
58
|
+
:cluster_list=>["0.0.0.1"],
|
59
|
+
:originator_id=>"81.52.17.128",
|
60
60
|
:mp_reach=> {
|
61
61
|
:safi=>128,
|
62
62
|
:afi=>1,
|
@@ -66,8 +66,15 @@ class Update_Test < Test::Unit::TestCase
|
|
66
66
|
}
|
67
67
|
}
|
68
68
|
|
69
|
+
assert_equal(h[:path_attributes][:originator_id], m.to_hash[:path_attributes][:originator_id])
|
70
|
+
assert_equal(h[:path_attributes][:as_path], m.to_hash[:path_attributes][:as_path])
|
71
|
+
assert_equal(h[:path_attributes][:multi_exit_disc], m.to_hash[:path_attributes][:multi_exit_disc])
|
72
|
+
assert_equal(h[:path_attributes][:local_pref], m.to_hash[:path_attributes][:local_pref])
|
73
|
+
assert_equal(h[:path_attributes][:originator_id], m.to_hash[:path_attributes][:originator_id])
|
74
|
+
assert_equal(h[:path_attributes][:mp_unreach], m.to_hash[:path_attributes][:mp_unreach])
|
75
|
+
assert_equal(h[:path_attributes], m.to_hash[:path_attributes])
|
69
76
|
assert_equal(h, m.to_hash)
|
70
|
-
|
77
|
+
|
71
78
|
s = 'ffffffffffffffffffffffffffffffff0050020000002f40010101400304c0a80105800404000000644005040000006440020402010064c0080c051f00010137003b0af50040200a0a0a0a2020202020'
|
72
79
|
m = Message.factory([s].pack('H*'))
|
73
80
|
assert_equal(Update, m.class)
|
@@ -132,6 +139,20 @@ class Update_Test < Test::Unit::TestCase
|
|
132
139
|
assert_equal 2, an_update.nlri.size
|
133
140
|
an_update << Nlri.new('21.0.0.0/11', '22.0.0.0/22')
|
134
141
|
assert_equal 4, an_update.nlri.size
|
142
|
+
|
143
|
+
h = {
|
144
|
+
:path_attributes=> {
|
145
|
+
:multi_exit_disc=>100,
|
146
|
+
:local_pref=>113,
|
147
|
+
:next_hop=>"10.0.0.1",
|
148
|
+
:origin=>:egp
|
149
|
+
},
|
150
|
+
:nlris=> ["77.0.0.0/17", "88.0.0.0/18", "21.0.0.0/11", "22.0.0.0/22"]
|
151
|
+
}
|
152
|
+
|
153
|
+
upd = Update.new h
|
154
|
+
assert_equal(0, an_update.path_attribute <=> upd.path_attribute)
|
155
|
+
|
135
156
|
end
|
136
157
|
|
137
158
|
def test_factory_to_build_update_with_session_info
|
@@ -237,7 +258,7 @@ class Update_Test < Test::Unit::TestCase
|
|
237
258
|
h = {
|
238
259
|
:path_attributes=>{
|
239
260
|
:as_path=>{:sequence=>[100]},
|
240
|
-
:
|
261
|
+
:med=>20,
|
241
262
|
:mp_reach=>{
|
242
263
|
:nexthop=>["10.0.0.1"],
|
243
264
|
:safi=>128,
|
@@ -307,7 +328,7 @@ class Update_Test < Test::Unit::TestCase
|
|
307
328
|
h = {
|
308
329
|
:path_attributes=>{
|
309
330
|
:as_path=>{},
|
310
|
-
:
|
331
|
+
:med=>0,
|
311
332
|
:mp_reach=>{
|
312
333
|
:nexthop=>["1.1.1.1"],
|
313
334
|
:safi=>128,
|
@@ -316,10 +337,14 @@ class Update_Test < Test::Unit::TestCase
|
|
316
337
|
},
|
317
338
|
:local_pref=>1,
|
318
339
|
:origin=>:egp,
|
319
|
-
:route_target=>[4, 1]
|
340
|
+
:extended_communities=>[{:route_target=>[4, 1] }]
|
320
341
|
}
|
321
342
|
}
|
322
343
|
assert_equal(h, upd.to_hash)
|
344
|
+
assert_equal(BGP::Route_target, upd.path_attribute.extended_communities.route_target.class)
|
345
|
+
assert_equal(BGP::Route_target, upd.path_attribute.extended_communities.route_target.to_s)
|
346
|
+
assert_equal(128, upd.path_attribute.mp_reach.safi)
|
347
|
+
assert_equal('Label Stack=16000 (bottom) RD=19:17, ID=1, IPv4=10.1.1.0/24', upd.path_attribute.mp_reach.nlris[0].to_s)
|
323
348
|
end
|
324
349
|
|
325
350
|
def test_factory_to_build_a_withdrawn_update_for_inet_mpls_vpn_unicast_with_path_id
|
@@ -342,6 +367,102 @@ class Update_Test < Test::Unit::TestCase
|
|
342
367
|
}
|
343
368
|
}
|
344
369
|
assert_equal(h, upd.to_hash)
|
370
|
+
upd2 = Update.new upd.to_hash
|
371
|
+
assert_equal(upd2.to_shex, upd.to_shex)
|
345
372
|
end
|
373
|
+
|
374
|
+
def test_to_hash
|
375
|
+
h = {:nlris=>
|
376
|
+
["59.88.128.0/18",
|
377
|
+
"59.88.192.0/18",
|
378
|
+
"59.89.0.0/18",
|
379
|
+
"59.89.192.0/18",
|
380
|
+
"59.90.0.0/18",
|
381
|
+
"59.90.64.0/18",
|
382
|
+
"59.90.128.0/18",
|
383
|
+
"59.90.192.0/18",
|
384
|
+
"59.91.192.0/18",
|
385
|
+
"59.93.128.0/18",
|
386
|
+
"59.93.192.0/18",
|
387
|
+
"59.94.0.0/18",
|
388
|
+
"59.94.64.0/18",
|
389
|
+
"59.94.128.0/18",
|
390
|
+
"59.94.192.0/18",
|
391
|
+
"59.95.0.0/18",
|
392
|
+
"59.95.128.0/18",
|
393
|
+
"59.96.128.0/18",
|
394
|
+
"59.96.192.0/18",
|
395
|
+
"59.97.128.0/18",
|
396
|
+
"59.97.192.0/18",
|
397
|
+
"59.98.192.0/18",
|
398
|
+
"59.99.0.0/18",
|
399
|
+
"59.99.64.0/18",
|
400
|
+
"117.197.0.0/18",
|
401
|
+
"117.197.64.0/18",
|
402
|
+
"117.197.128.0/18",
|
403
|
+
"117.198.128.0/18",
|
404
|
+
"117.198.192.0/18",
|
405
|
+
"117.199.64.0/18",
|
406
|
+
"117.199.128.0/18",
|
407
|
+
"117.199.192.0/18",
|
408
|
+
"117.200.0.0/18",
|
409
|
+
"117.200.64.0/18",
|
410
|
+
"117.201.0.0/18",
|
411
|
+
"117.201.64.0/18",
|
412
|
+
"117.202.192.0/18",
|
413
|
+
"117.203.0.0/18",
|
414
|
+
"117.203.128.0/18",
|
415
|
+
"117.203.192.0/18",
|
416
|
+
"117.205.0.0/18",
|
417
|
+
"117.205.64.0/18",
|
418
|
+
"117.205.192.0/18",
|
419
|
+
"117.206.128.0/18",
|
420
|
+
"117.206.192.0/18",
|
421
|
+
"117.207.0.0/18",
|
422
|
+
"117.207.128.0/18",
|
423
|
+
"117.209.192.0/18",
|
424
|
+
"117.210.0.0/18",
|
425
|
+
"117.210.64.0/18",
|
426
|
+
"117.210.128.0/18",
|
427
|
+
"117.210.192.0/18",
|
428
|
+
"117.212.0.0/18",
|
429
|
+
"117.212.64.0/18",
|
430
|
+
"117.214.0.0/18",
|
431
|
+
"117.214.128.0/18",
|
432
|
+
"117.214.192.0/18",
|
433
|
+
"117.218.0.0/18",
|
434
|
+
"117.239.0.0/18",
|
435
|
+
"117.239.64.0/18",
|
436
|
+
"117.239.128.0/18",
|
437
|
+
"117.239.192.0/18",
|
438
|
+
"117.241.0.0/18",
|
439
|
+
"117.241.64.0/18",
|
440
|
+
"117.241.128.0/18",
|
441
|
+
"117.241.192.0/18",
|
442
|
+
"117.242.0.0/18",
|
443
|
+
"117.242.64.0/18",
|
444
|
+
"117.242.128.0/18",
|
445
|
+
"117.242.192.0/18",
|
446
|
+
"210.212.0.0/18",
|
447
|
+
"210.212.64.0/18",
|
448
|
+
"210.212.128.0/18",
|
449
|
+
"210.212.192.0/18",
|
450
|
+
"218.248.0.0/18",
|
451
|
+
"218.248.128.0/18"],
|
452
|
+
:path_attributes=> {
|
453
|
+
:communities=>["28289:65500"],
|
454
|
+
:origin=>:igp,
|
455
|
+
:as_path=>{:sequence=>[28289, 53131, 16735, 3549, 9829, 9829, 9829]},
|
456
|
+
:next_hop=>"187.121.193.33"
|
457
|
+
}
|
458
|
+
}
|
459
|
+
u = Update.new h
|
460
|
+
assert_equal(h, u.to_hash)
|
461
|
+
|
462
|
+
# s = "ffffffffffffffffffffffffffffffff016c02000000254001010040021002076e81cf8b415f0ddd266526652665400304bb79c121c008046e81ffdc123b5880123b58c0123b5900123b59c0123b5a00123b5a40123b5a80123b5ac0123b5bc0123b5d80123b5dc0123b5e00123b5e40123b5e80123b5ec0123b5f00123b5f80123b6080123b60c0123b6180123b61c0123b62c0123b6300123b63401275c5001275c5401275c5801275c6801275c6c01275c7401275c7801275c7c01275c8001275c8401275c9001275c9401275cac01275cb001275cb801275cbc01275cd001275cd401275cdc01275ce801275cec01275cf001275cf801275d1c01275d2001275d2401275d2801275d2c01275d4001275d4401275d6001275d6801275d6c01275da001275ef001275ef401275ef801275efc01275f1001275f1401275f1801275f1c01275f2001275f2401275f2801275f2c012d2d40012d2d44012d2d48012d2d4c012daf80012daf880"
|
463
|
+
# assert_equal(s, u.to_shex)
|
464
|
+
end
|
465
|
+
|
466
|
+
|
346
467
|
|
347
468
|
end
|
@@ -67,6 +67,6 @@ class Aggregator_Test < Test::Unit::TestCase
|
|
67
67
|
ag1 = Aggregator.new('10.0.0.1', 100)
|
68
68
|
ag2 = Aggregator.new :asn=> 100, :address=> '10.0.0.1'
|
69
69
|
assert_equal(ag1.encode,ag2.encode)
|
70
|
-
assert_equal({:asn=>100, :address=>"10.0.0.1"}, ag2.to_hash)
|
70
|
+
assert_equal({:asn=>100, :address=>"10.0.0.1"}, ag2.to_hash[:aggregator])
|
71
71
|
end
|
72
72
|
end
|
@@ -19,11 +19,11 @@ class TestAigp < Test::Unit::TestCase
|
|
19
19
|
end
|
20
20
|
def test_2
|
21
21
|
assert Aigp.new_hash
|
22
|
-
assert Aigp.new_hash :
|
22
|
+
assert Aigp.new_hash :aigp=> 0x1f2f3f4f5f6f7f8f
|
23
23
|
m1 = Aigp.new 0x1f2f3f4f5f6f7f8f
|
24
|
-
m2 = Aigp.new_hash :
|
24
|
+
m2 = Aigp.new_hash :aigp=> 0x1f2f3f4f5f6f7f8f
|
25
25
|
assert_equal(m1.encode, m2.encode)
|
26
|
-
assert_equal({:
|
26
|
+
assert_equal({:aigp=>2247084349217275791}, m2.to_hash)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -38,7 +38,7 @@ class Cluster_list_Test < Test::Unit::TestCase
|
|
38
38
|
end
|
39
39
|
def test_2
|
40
40
|
cids = ['1.1.1.1', '2.2.2.2', '3.3.3.3']
|
41
|
-
clist1 = Cluster_list.
|
42
|
-
assert_equal( cids, clist1.to_hash[:
|
41
|
+
clist1 = Cluster_list.new :cluster_list=> cids
|
42
|
+
assert_equal( cids, clist1.to_hash[:cluster_list])
|
43
43
|
end
|
44
44
|
end
|
@@ -67,7 +67,10 @@ class Extended_communitiesTest < Test::Unit::TestCase
|
|
67
67
|
ec2 = Extended_communities.new_hash(ec.to_hash)
|
68
68
|
assert_equal(ec.to_hash, Extended_communities.new_hash(ec.to_hash).to_hash)
|
69
69
|
ec = Extended_communities.new_hash :color => 100, :link_bandwidth => 999_999_999, :route_origin => ['10.0.1.2', 10], :encapsulation => :ipip
|
70
|
-
assert_equal(
|
70
|
+
assert_equal(ec.to_hash, Extended_communities.new_hash(ec.to_hash).to_hash)
|
71
|
+
assert_equal({:color=>100}, ec.color.to_hash)
|
72
|
+
ec = Extended_communities.new_hash :extended_communities=>[{:route_target=>[13111, 26054]}]
|
73
|
+
assert_equal({:extended_communities=>[{:route_target=>[13111, 26054]}]}, ec.to_hash)
|
71
74
|
end
|
72
75
|
def test_sort
|
73
76
|
ec = Extended_communities.new
|
@@ -137,7 +140,28 @@ class Extended_communitiesTest < Test::Unit::TestCase
|
|
137
140
|
assert_equal(0, ec <=> ec2)
|
138
141
|
assert(! ec.eql?(ec2))
|
139
142
|
end
|
143
|
+
def test_getters
|
144
|
+
ec = Extended_communities.new do |c|
|
145
|
+
c.add(Color.new(100))
|
146
|
+
c.add(Link_bandwidth.new(999_999_999))
|
147
|
+
c.add(Route_target.new('10.0.1.2',10))
|
148
|
+
c.add(Ospf_domain_id.new('9.1.0.1'))
|
149
|
+
c.add(Route_target.new('11.0.1.1',10))
|
150
|
+
c.add(Route_target.new('8.0.1.1',10))
|
151
|
+
c.add(Route_target.new('7.0.1.1',8))
|
152
|
+
c.add(Encapsulation.new(:l2tpv3))
|
153
|
+
c.add(Ospf_domain_id.new('20.0.0.1'))
|
154
|
+
c.add(Route_origin.new('10.0.3.2',9))
|
155
|
+
c.add(Route_target.new('10.0.3.2',7))
|
156
|
+
c.add(Ospf_router_id.new('10.0.0.1'))
|
157
|
+
end
|
158
|
+
assert_equal('Color: 100',ec.color.to_s)
|
159
|
+
assert_equal('Route target: 10.0.1.2:10',ec.route_target.to_s)
|
160
|
+
assert_equal('Ospf domain id: 9.1.0.1:0',ec.ospf_domain_id.to_s)
|
161
|
+
assert_equal('Encapsulation: 1',ec.encapsulation.to_s)
|
162
|
+
assert_equal('Ospf router id: 10.0.0.1:0',ec.ospf_router_id.to_s)
|
163
|
+
assert_equal('Link bandwidth: 1000000000.0',ec.link_bandwidth.to_s)
|
164
|
+
assert_equal('Route origin: 10.0.3.2:9',ec.route_origin.to_s)
|
165
|
+
end
|
140
166
|
|
141
167
|
end
|
142
|
-
|
143
|
-
#MiniTest::Unit.autorun
|
@@ -180,7 +180,7 @@ class Path_attribute_Test < Test::Unit::TestCase # :nodoc:
|
|
180
180
|
:as_path=> {:set=> [1,2], :sequence=>[3,4], :confed_sequence=>[5,6], :confed_set=>[7,8]},
|
181
181
|
:cluster_list=> ['1.1.1.1', '2.2.2.2', '3.3.3.3'],
|
182
182
|
:communities=> ["145:30", "145:40", "145:50", "145:60", :no_export, :no_advertise,],
|
183
|
-
:extended_communities=>
|
183
|
+
:extended_communities=> [ :color => 100, :link_bandwidth => 999_999_999, :route_origin => ['10.0.1.2', 10], :encapsulation => :ipip ],
|
184
184
|
:aggregator=> { :address=>'1.1.1.1', :asn=>100 },
|
185
185
|
:originator_id=> '2.2.2.2',
|
186
186
|
:as4_aggregator=> { :asn=> 200, :address=> '4.4.4.4' },
|
@@ -204,6 +204,31 @@ class Path_attribute_Test < Test::Unit::TestCase # :nodoc:
|
|
204
204
|
|
205
205
|
end
|
206
206
|
|
207
|
+
def test_9
|
208
|
+
pa1 = Path_attribute.new { |p|
|
209
|
+
p << Multi_exit_disc.new(222)
|
210
|
+
p << Next_hop.new('1.1.1.1')
|
211
|
+
p << Local_pref.new(333)
|
212
|
+
p << As_path.new( :set=> [1,2,3,4], :sequence=> [11,12,13])
|
213
|
+
p << Origin.new(1)
|
214
|
+
}
|
215
|
+
pa2 = Path_attribute.new { |p|
|
216
|
+
p << Next_hop.new('1.1.1.1')
|
217
|
+
p << Origin.new(1)
|
218
|
+
p << Local_pref.new(333)
|
219
|
+
p << As_path.new(:sequence=> [11,12,14], :set=> [1,2,3,4])
|
220
|
+
p << Multi_exit_disc.new(222)
|
221
|
+
}
|
222
|
+
assert_not_equal(pa1.to_shex,pa2.to_shex)
|
223
|
+
assert_equal(pa1.sort.to_shex, pa2.sort.to_shex)
|
224
|
+
assert_equal(0, pa1 <=> pa2)
|
225
|
+
pa1.add(Communities.new("1:1"))
|
226
|
+
assert_equal(1, pa1 <=> pa2)
|
227
|
+
pa2.insert(Communities.new("1:1"))
|
228
|
+
assert_equal(0, pa1 <=> pa2)
|
229
|
+
end
|
230
|
+
|
231
|
+
|
207
232
|
def test_path_attribute_path_id_true_and_as4byte_false
|
208
233
|
path_attr = Path_attribute.new
|
209
234
|
path_attr.insert(
|
@@ -223,6 +248,63 @@ class Path_attribute_Test < Test::Unit::TestCase # :nodoc:
|
|
223
248
|
# TODO: UT: a path attr with mp_unreach w path_id
|
224
249
|
# TODO: UT: a path attr with mp_reach w path_id and as4
|
225
250
|
|
226
|
-
end
|
251
|
+
end
|
227
252
|
|
253
|
+
def test_hash
|
254
|
+
|
255
|
+
h = {
|
256
|
+
:aigp=> 0x1f2f3f4f5f6f7f8f,
|
257
|
+
:aggregator=>{:asn=>100, :address=>"10.0.0.1"},
|
258
|
+
:cluster_list=>["1.0.1.1"],
|
259
|
+
:as_path=>{},
|
260
|
+
:communities=>["1133:2015"],
|
261
|
+
:local_pref=>113,
|
262
|
+
:origin=>:incomplete,
|
263
|
+
:med=>10,
|
264
|
+
:extended_communities=>[{:route_target=>[13111, 26054]}],
|
265
|
+
:originator_id=>"196.168.28.123",
|
266
|
+
:mp_reach=>{
|
267
|
+
:nexthop=>["10.0.0.2"], :afi=>1, :safi=>128,
|
268
|
+
:nlris=>[
|
269
|
+
{:label=>2226, :prefix=>"172.23.21.113/32", :rd=>[1311, 4567814]},
|
270
|
+
{:label=>2151, :prefix=>"10.48.9.175/32", :rd=>[1311, 32117824]},
|
271
|
+
{:label=>3382, :prefix=>"172.33.169.92/32", :rd=>[1311, 80037224]},
|
272
|
+
{:label=>1452, :prefix=>"10.46.52.31/32", :rd=>[1311, 3117824]},
|
273
|
+
{:label=>3785, :prefix=>"172.41.96.104/32", :rd=>[1311, 45657424]},
|
274
|
+
{:label=>5228, :prefix=>"10.46.53.69/32", :rd=>[1311, 59407624]},
|
275
|
+
{:label=>5141, :prefix=>"172.21.55.36/32", :rd=>[1311, 321617824]},
|
276
|
+
{:label=>3724, :prefix=>"10.99.25.81/32", :rd=>[1311, 311197824]},
|
277
|
+
{:label=>2281, :prefix=>"10.35.9.169/32", :rd=>[1311, 321147824]},
|
278
|
+
{:label=>4615, :prefix=>"10.65.128.200/32", :rd=>[1311, 6627884]},
|
279
|
+
{:label=>3404, :prefix=>"172.29.96.8/32", :rd=>[1311, 45657824]},
|
280
|
+
{:label=>3767, :prefix=>"10.32.19.165/32", :rd=>[1311, 44657824]},
|
281
|
+
{:label=>3451, :prefix=>"10.14.186.28/32", :rd=>[1311, 45657824]},
|
282
|
+
{:label=>3027, :prefix=>"10.95.176.91/32", :rd=>[1311, 371197824]},
|
283
|
+
{:label=>5034, :prefix=>"10.24.176.99/32", :rd=>[1311, 321197824]},
|
284
|
+
{:label=>3565, :prefix=>"10.72.83.239/32", :rd=>[1311, 311197824]},
|
285
|
+
{:label=>3551, :prefix=>"10.45.142.161/32", :rd=>[1311, 321157824]},
|
286
|
+
{:label=>5238, :prefix=>"10.32.83.219/32", :rd=>[1311, 351177824]},
|
287
|
+
{:label=>5223, :prefix=>"10.13.142.117/32", :rd=>[1311, 321197824]},
|
288
|
+
{:label=>3360, :prefix=>"172.50.34.141/32", :rd=>[1311, 348987824]},
|
289
|
+
{:label=>3579, :prefix=>"10.26.42.36/32", :rd=>[1311, 325697824]},
|
290
|
+
{:label=>4118, :prefix=>"10.76.42.34/32", :rd=>[1311, 347517824]},
|
291
|
+
{:label=>3971, :prefix=>"172.21.192.24/32", :rd=>[1311, 86627824]},
|
292
|
+
{:label=>4223, :prefix=>"10.12.209.131/32", :rd=>[1311, 42655824]},
|
293
|
+
{:label=>2241, :prefix=>"10.34.186.201/32", :rd=>[1311, 42656824]},
|
294
|
+
],
|
295
|
+
}
|
296
|
+
}
|
297
|
+
|
298
|
+
assert_equal(h[:local_pref], Path_attribute.new(h).to_hash[:local_pref])
|
299
|
+
assert_equal(h[:as_path], Path_attribute.new(h).to_hash[:as_path])
|
300
|
+
assert_equal(h[:extended_communities], Path_attribute.new(h).to_hash[:extended_communities])
|
301
|
+
assert_equal(h[:communities], Path_attribute.new(h).to_hash[:communities])
|
302
|
+
assert_equal(h[:cluster_list], Path_attribute.new(h).to_hash[:cluster_list])
|
303
|
+
assert_equal(h[:aggregator], Path_attribute.new(h).to_hash[:aggregator])
|
304
|
+
assert_equal(h[:mp_reach], Path_attribute.new(h).to_hash[:mp_reach])
|
305
|
+
assert_equal(h, Path_attribute.new(h).to_hash)
|
306
|
+
|
307
|
+
end
|
308
|
+
|
228
309
|
end
|
310
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bgp4r
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.15
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-13 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: BGP4R is a BGP-4 ruby library to create, send, and receive BGP messages
|
15
15
|
in an object oriented manner
|
@@ -77,15 +77,12 @@ files:
|
|
77
77
|
- bgp/path_attributes/origin.rb
|
78
78
|
- bgp/path_attributes/originator_id.rb
|
79
79
|
- bgp/path_attributes/path_attribute.rb
|
80
|
-
- bgp/path_attributes/tlvs/tlv.rb
|
81
80
|
- bgp4r.gemspec
|
82
81
|
- bgp4r.rb
|
83
82
|
- examples/a_live_feed
|
84
83
|
- examples/routegen
|
85
84
|
- examples/routegen.yml
|
86
85
|
- examples/simple.rb
|
87
|
-
- examples/test.rb
|
88
|
-
- examples/test2.rb
|
89
86
|
- examples/unit-testing/malformed_update_test.rb
|
90
87
|
- examples/unit-testing/no_export_test.rb
|
91
88
|
- examples/unit-testing/prepend_aspath_test.rb
|
@@ -141,7 +138,6 @@ files:
|
|
141
138
|
- test/unit/path_attributes/origin_test.rb
|
142
139
|
- test/unit/path_attributes/originator_id_test.rb
|
143
140
|
- test/unit/path_attributes/path_attribute_test.rb
|
144
|
-
- test/unit/path_attributes/tlvs/tlv_test.rb
|
145
141
|
- test/unit/path_attributes/tunnel_encapsulation_test (Jean-Michel's Laptop's conflicted
|
146
142
|
copy 2011-11-02).rb
|
147
143
|
homepage: http://github.com/jesnault/bgp4r/tree/master
|
@@ -164,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
160
|
version: '0'
|
165
161
|
requirements: []
|
166
162
|
rubyforge_project: bgp4r
|
167
|
-
rubygems_version: 1.8.
|
163
|
+
rubygems_version: 1.8.11
|
168
164
|
signing_key:
|
169
165
|
specification_version: 3
|
170
166
|
summary: A BGP-4 Ruby Library
|
@@ -220,6 +216,5 @@ test_files:
|
|
220
216
|
- test/unit/path_attributes/origin_test.rb
|
221
217
|
- test/unit/path_attributes/originator_id_test.rb
|
222
218
|
- test/unit/path_attributes/path_attribute_test.rb
|
223
|
-
- test/unit/path_attributes/tlvs/tlv_test.rb
|
224
219
|
- test/unit/path_attributes/tunnel_encapsulation_test (Jean-Michel's Laptop's conflicted
|
225
220
|
copy 2011-11-02).rb
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module BGP
|
2
|
-
module TLV
|
3
|
-
attr_accessor :tlv_type
|
4
|
-
def encode(value)
|
5
|
-
p 'IN ENCODE TLV'
|
6
|
-
[@tlv_type, value.size, value].pack('nna*')
|
7
|
-
end
|
8
|
-
end
|
9
|
-
module STLV
|
10
|
-
attr_accessor :stlv_type
|
11
|
-
def encode(value)
|
12
|
-
[@stlv_type, value.size, value].pack('CCa*')
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
load "../../../test/unit/path_attributes/tlvs/#{ File.basename($0.gsub(/.rb/,'_test.rb'))}" if __FILE__ == $0
|
18
|
-
|
data/examples/test.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'bgp4r'
|
2
|
-
include BGP
|
3
|
-
Log.create
|
4
|
-
n = Neighbor.new 4, 1, 180, '1.1.1.1','127.0.0.1', '127.0.0.1'
|
5
|
-
# n.start :auto_retry => true
|
6
|
-
n.start :port=> 8090
|
7
|
-
|
8
|
-
sleep(200)
|
9
|
-
|
10
|
-
|
11
|
-
__END__
|
12
|
-
|
13
|
-
|
14
|
-
@c = Neighbor.new(4, 100, 180, '0.0.0.2', '127.0.0.1', '127.0.0.1')
|
15
|
-
@c.add_cap add_path_cap2
|
data/examples/test2.rb
DELETED
@@ -1,116 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'rubygems'
|
3
|
-
require 'eventmachine'
|
4
|
-
require 'bgp4r'
|
5
|
-
|
6
|
-
|
7
|
-
include BGP
|
8
|
-
|
9
|
-
pa = Path_attribute.new(
|
10
|
-
Origin.new,
|
11
|
-
Next_hop.new('10.0.0.1'),
|
12
|
-
Local_pref.new(300),
|
13
|
-
Communities.new('10:1 10:2 10:3'),
|
14
|
-
As_path.new('100 200 300 400')
|
15
|
-
)
|
16
|
-
|
17
|
-
times = 133
|
18
|
-
pack=13
|
19
|
-
nlri = IPAddr.new '11.0.0.1/24'
|
20
|
-
|
21
|
-
nlris = Nlri.new
|
22
|
-
|
23
|
-
updates = Fiber.new do
|
24
|
-
(1..times.to_i).each do |n|
|
25
|
-
nlris << (nlri ^ n)
|
26
|
-
next unless (n % pack) == 0 or (n == times)
|
27
|
-
Fiber.yield Update.new(pa, nlris)
|
28
|
-
nlris = Nlri.new
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
p updates.resume
|
33
|
-
p updates.resume
|
34
|
-
p updates.resume
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
__END__
|
41
|
-
|
42
|
-
|
43
|
-
pa = Path_attribute.new(
|
44
|
-
Origin.new(@origin),
|
45
|
-
Next_hop.new(@nexthop),
|
46
|
-
Local_pref.new(@local_pref),
|
47
|
-
Communities.new(*(@communities.split.map { |com| com.to_i})),
|
48
|
-
As_path.new(*(@as_path.split.map { |as| as.to_i}))
|
49
|
-
)
|
50
|
-
|
51
|
-
|
52
|
-
nlris = Nlri.new
|
53
|
-
(1..@times.to_i).each do |n|
|
54
|
-
nlris << (@nlri ^ n)
|
55
|
-
next unless (n % @pack) == 0 or (n == @times)
|
56
|
-
neighbor.send_message Update.new(pa, nlris)
|
57
|
-
nlris = Nlri.new
|
58
|
-
end
|
59
|
-
|
60
|
-
words = Fiber.new do File.foreach("testfile") do |line|
|
61
|
-
line.scan(/\w+/) do |word| Fiber.yield word.downcase
|
62
|
-
end end
|
63
|
-
end
|
64
|
-
Prepared exclusively for Jean-Michel Esnault
|
65
|
-
FIBERS 176
|
66
|
-
counts = Hash.new(0) while word = words.resume
|
67
|
-
counts[word] += 1
|
68
|
-
end
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
__END__
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
Thread.abort_on_exception = true
|
79
|
-
|
80
|
-
Log.create
|
81
|
-
|
82
|
-
class Session
|
83
|
-
def initialize
|
84
|
-
end
|
85
|
-
def start(arg={})
|
86
|
-
options = {:duration=> 120, :as=> 1, :holdtime=> 180, :id=> '2.2.2.2', :peer=> '127.0.0.1'}.merge(arg)
|
87
|
-
|
88
|
-
Thread.new do
|
89
|
-
EM.run do
|
90
|
-
@c = EM.connect(options[:peer], 8090,
|
91
|
-
BGP::ConnectionHandler, 4,
|
92
|
-
options[:as], options[:holdtime], options[:id], options[:peer])
|
93
|
-
@c.add_observer(self)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def update(*args)
|
99
|
-
end
|
100
|
-
|
101
|
-
def stop
|
102
|
-
EM.stop
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
n = Session.new
|
107
|
-
n.start :duration=> 120, :as=> 1, :holdtime=> 10, :id=> '2.2.2.2', :peer=> '127.0.0.1'
|
108
|
-
|
109
|
-
p 'HERE ABOUT TO SLEEP'
|
110
|
-
sleep(20)
|
111
|
-
p $c
|
112
|
-
p "ABOUT TO SHUT DOWN EM"
|
113
|
-
n.stop
|
114
|
-
|
115
|
-
|
116
|
-
__END__
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require "test/unit"
|
2
|
-
|
3
|
-
require "bgp/path_attributes/tlvs/tlv"
|
4
|
-
require 'bgp/path_attributes/attribute'
|
5
|
-
|
6
|
-
module BGP
|
7
|
-
class MyAttr < Attr
|
8
|
-
include TLV
|
9
|
-
include STLV
|
10
|
-
def initialize(value)
|
11
|
-
@flags, @type = OPTIONAL_NON_TRANSITIVE, 55
|
12
|
-
@value = value
|
13
|
-
@tlv_type=1
|
14
|
-
@stlv_type=2
|
15
|
-
end
|
16
|
-
def encode
|
17
|
-
super(@value)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class TestBgpPathAttributesTlvsTlv < Test::Unit::TestCase
|
23
|
-
include BGP
|
24
|
-
def test_1
|
25
|
-
attr = MyAttr.new([0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef].pack('N*'))
|
26
|
-
assert_equal('803716 0001 0012 02 10 deadbeef deadbeef deadbeef deadbeef'.split.join, attr.to_shex)
|
27
|
-
assert_equal(2, attr.stlv_type)
|
28
|
-
assert_equal(1, attr.tlv_type)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
|