bgp4r 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/bgp/common.rb +14 -13
  2. data/bgp/iana.rb +26 -1
  3. data/bgp/messages/capability.rb +3 -2
  4. data/bgp/messages/message.rb +3 -2
  5. data/bgp/messages/open.rb +2 -1
  6. data/bgp/messages/update.rb +80 -30
  7. data/bgp/neighbor/add_path_cap.rb +125 -0
  8. data/bgp/{neighbor.rb → neighbor/neighbor.rb} +64 -68
  9. data/bgp/nlris/nlri.rb +289 -15
  10. data/bgp/nlris/prefix.rb +3 -2
  11. data/bgp/nlris/vpn.rb +1 -8
  12. data/bgp/optional_parameters/add_path.rb +160 -0
  13. data/bgp/optional_parameters/capabilities.rb +1 -0
  14. data/bgp/optional_parameters/capability.rb +6 -0
  15. data/bgp/optional_parameters/graceful_restart.rb +6 -6
  16. data/bgp/optional_parameters/optional_parameter.rb +1 -0
  17. data/bgp/path_attributes/as_path.rb +1 -1
  18. data/bgp/path_attributes/attribute.rb +12 -5
  19. data/bgp/path_attributes/mp_reach.rb +142 -96
  20. data/bgp/path_attributes/mp_unreach.rb +73 -20
  21. data/bgp/path_attributes/path_attribute.rb +28 -5
  22. data/bgp4r.gemspec +21 -6
  23. data/bgp4r.rb +1 -1
  24. data/examples/unit-testing/malformed_update.rb +2 -1
  25. data/examples/unit-testing/test.rb +82 -0
  26. data/examples/unit-testing/test1.rb +82 -0
  27. data/examples/unit-testing/test2.rb +44 -0
  28. data/test/common_test.rb +7 -0
  29. data/test/helpers/server.rb +20 -0
  30. data/test/iana_test.rb +43 -0
  31. data/test/messages/open_test.rb +7 -2
  32. data/test/messages/update_test.rb +133 -36
  33. data/test/neighbor/add_path_cap_test.rb +54 -0
  34. data/test/neighbor/neighbor_test.rb +161 -0
  35. data/test/nlris/ext_nlri_test.rb +25 -60
  36. data/test/nlris/nlri_test.rb +93 -115
  37. data/test/optional_parameters/add_path_test.rb +53 -0
  38. data/test/optional_parameters/capability_test.rb +10 -0
  39. data/test/optional_parameters/graceful_restart_test.rb +1 -0
  40. data/test/path_attributes/mp_reach_test.rb +206 -8
  41. data/test/path_attributes/mp_unreach_test.rb +113 -5
  42. data/test/path_attributes/path_attribute_test.rb +34 -2
  43. metadata +20 -7
  44. data/test/neighbor_test.rb +0 -62
@@ -26,36 +26,48 @@ require 'test/unit'
26
26
  class Mp_unreach_Test < Test::Unit::TestCase
27
27
  include BGP
28
28
  def test_1
29
- mpur = Mp_unreach.new(:safi=>1, :prefix=>['10.0.0.0/16', '10.1.0.0/16'])
29
+ mpur = Mp_unreach.new(:safi=>1, :nlris=>['10.0.0.0/16', '10.1.0.0/16'])
30
30
  assert_raise(ArgumentError) { Mp_unreach.new }
31
31
  end
32
32
 
33
33
  def test_2
34
- mpur = Mp_unreach.new(:safi=>2, :prefix=>['192.168.1.0/24', '192.168.2.0/24'])
34
+ mpur = Mp_unreach.new(:safi=>2, :nlris=>['192.168.1.0/24', '192.168.2.0/24'])
35
35
  assert_equal('800f0b00010218c0a80118c0a802', mpur.to_shex)
36
36
 
37
- mpur = Mp_unreach.new(:safi=>2, :prefix=>['2007:1::/64', '2007:2::/64','2007:3::/64'])
37
+ mpur = Mp_unreach.new(:safi=>2, :nlris=>['2007:1::/64', '2007:2::/64','2007:3::/64'])
38
38
  assert_equal('800f1e000202402007000100000000402007000200000000402007000300000000', mpur.to_shex)
39
39
 
40
40
  #mpur = Mp_unreach.new(:safi=>2, :prefix=>['2007:1::/64, 101', '2007:2::/64,102','2007:3::/64, 103'])
41
- mpur = Mp_unreach.new(:safi=>4, :nlri=> [
41
+ mpur = Mp_unreach.new(:safi=>4, :nlris=> [
42
42
  {:prefix=>'2007:1::/64', :label=> 101},
43
43
  {:prefix=>'2007:2::/64', :label=> 102},
44
44
  {:prefix=>'2007:3::/64', :label=> 103},])
45
+
46
+
45
47
  assert_equal('800f27000204580006512007000100000000580006612007000200000000580006712007000300000000', mpur.to_shex)
46
48
  assert_match(/^800f..000204/,mpur.to_shex)
47
49
  assert_match(/58000651200700010000000058/,mpur.to_shex)
48
50
  assert_match(/58000661200700020000000058/,mpur.to_shex)
49
51
  assert_match(/580006712007000300000000$/,mpur.to_shex)
50
52
 
51
- mpur = Mp_unreach.new(:safi=>128, :nlri=> [
53
+ mpur = Mp_unreach.new(:safi=>128, :nlris=> [
52
54
  {:rd=> Rd.new(100,100), :prefix=> Prefix.new('192.168.1.0/24'), :label=>101},
53
55
  {:rd=> Rd.new(100,100), :prefix=> Prefix.new('192.168.2.0/24'), :label=>102},
54
56
  {:rd=> Rd.new(100,100), :prefix=> Prefix.new('192.168.3.0/24'), :label=>103},])
57
+
58
+
55
59
  assert_match(/^800f..000180/,mpur.to_shex)
56
60
  assert_equal("700006510000006400000064c0a801",mpur.nlris[0].to_shex)
57
61
  assert_equal("700006610000006400000064c0a802",mpur.nlris[1].to_shex)
58
62
 
63
+ mpur = Mp_unreach.new(:safi=>128, :nlris=> [
64
+ {:rd=> Rd.new(100,100), :prefix=> '192.168.1.0/24', :label=>101},
65
+ {:rd=> Rd.new(100,100), :prefix=> '192.168.2.0/24', :label=>102},
66
+ {:rd=> Rd.new(100,100), :prefix=> '192.168.3.0/24', :label=>103},])
67
+ assert_match(/^800f..000180/,mpur.to_shex)
68
+ assert_equal("700006510000006400000064c0a801",mpur.nlris[0].to_shex)
69
+ assert_equal("700006610000006400000064c0a802",mpur.nlris[1].to_shex)
70
+
59
71
  end
60
72
 
61
73
  def test_3
@@ -64,4 +76,100 @@ class Mp_unreach_Test < Test::Unit::TestCase
64
76
  assert_equal '800f03000102', Mp_unreach.new(:afi=>1, :safi=>2).to_shex
65
77
  end
66
78
 
79
+ def test_afi_1
80
+ mpr1 = Mp_unreach.new(:safi=>1, :nlris=> '192.168.1.0/24')
81
+ mpr2 = Mp_unreach.new(:safi=>1, :nlris=> '192.168.1.0/24', :path_id=>100)
82
+ mpr3 = Mp_unreach.new(:safi=>2, :nlris=> ['192.168.1.0/24','192.168.2.0/24'])
83
+ mpr4 = Mp_unreach.new(:safi=>2, :nlris=> ['192.168.1.0/24','192.168.2.0/24'], :path_id=>100)
84
+ mpr5 = Mp_unreach.new(:safi=>1, :nlris=> [
85
+ {:prefix=> '192.168.1.0/24', :path_id=> 100},
86
+ {:prefix=> '192.168.2.0/24', :path_id=> 101},
87
+ {:prefix=> '192.168.2.0/24', :path_id=> 102},
88
+ ])
89
+
90
+
91
+ #
92
+ # puts mpr1
93
+ # puts mpr2
94
+ # puts mpr3
95
+ # puts mpr4
96
+ # puts mpr5
97
+ #
98
+ assert_equal('800f0700010118c0a801', mpr1.to_shex)
99
+ assert_equal('800f0b0001010000006418c0a801', mpr2.to_shex)
100
+ assert_equal attr_len(mpr1)+4, attr_len(mpr2)
101
+
102
+ assert_equal('800f0b00010218c0a80118c0a802', mpr3.to_shex)
103
+ assert_equal('800f130001020000006418c0a8010000006418c0a802', mpr4.to_shex)
104
+ assert_equal attr_len(mpr3)+8, attr_len(mpr4)
105
+
106
+ assert_equal('800f1b0001010000006418c0a8010000006518c0a8020000006618c0a802', mpr5.to_shex)
107
+
108
+ end
109
+
110
+ def test_safi_2_afi_2
111
+ unreach1 = Mp_unreach.new( :safi=>2, :nlris=> [
112
+ {:prefix=> '2007:1::/64'},
113
+ {:prefix=> '2007:2::/64'},
114
+ {:prefix=> '2007:3::/64'}
115
+ ]
116
+ )
117
+ assert_equal(3, unreach1.nlris.size)
118
+ assert_equal(2,unreach1.afi)
119
+ assert_equal(2,unreach1.safi)
120
+
121
+ unreach2 = Mp_unreach.new( :safi=>2, :nlris=> [
122
+ {:prefix=> '2007:1::/64', :path_id=> 101},
123
+ {:prefix=> '2007:2::/64', :path_id=> 102},
124
+ {:prefix=> '2007:3::/64', :path_id=> 103}
125
+ ]
126
+ )
127
+
128
+ s1 = '80 0f 1e 0002 02 40 2007000100000000 40 2007000200000000 40 2007000300000000'
129
+ s2 = '80 0f 2a 0002 02 00000065 40 2007000100000000 00000066 40 2007000200000000 00000067 40 2007000300000000'
130
+ assert_equal(s1.split.join,unreach1.to_shex)
131
+ assert_equal(s2.split.join,unreach2.to_shex)
132
+
133
+ assert_equal(s1.split.join, Mp_unreach.new(unreach1.encode).to_shex)
134
+ assert_equal(s2.split.join, Mp_unreach.new(unreach2.encode,true).to_shex)
135
+
136
+ end
137
+
138
+ def test_safi_128
139
+
140
+ # ffff ffff ffff ffff ffff ffff ffff ffff
141
+ # 0031 0200 0000 1a
142
+ # 90 0f 0016 0001 80 00000001 70 800000 00000001000000010a0101
143
+ # 80 0f 12 0001 80 70 03e801 00000001000000010a0101
144
+ # 80 0f 16 0001 80 00000001 70 03e801 00000001000000010a0101
145
+
146
+ # Mp Reach (14), length: 9216, Flags [OE]:
147
+ # AFI IPv4 (1), SAFI Labeled VPN Unicast (128)
148
+ # nexthop: 1.1.1.1
149
+ # ID=1, Label Stack=16000 (bottom) RD=1:1, IPv4=10.1.1.0/24
150
+ # 0x0000: 0180 0c00 0000 0000 0000 0001 0101 0100
151
+ # 0x0001: 0000 0001 7003 e801 0000 0001 0000 0001
152
+ # 0x0002: 0a01 01
153
+
154
+ unreach1 = Mp_unreach.new( :safi=> 128, :nlris => [{:rd=> Rd.new(1,1), :prefix=> '10.1.1.0/24', :label=>16000},])
155
+ unreach2 = Mp_unreach.new( :safi=> 128, :nlris => [{:rd=> Rd.new(1,1), :prefix=> '10.1.1.0/24', :label=>16000, :path_id=> 1},])
156
+
157
+ assert_equal(16000, Label.new(['03e801'].pack('H*')).to_hash[:label])
158
+ assert_equal(524288, Label.new(['800000'].pack('H*')).to_hash[:label])
159
+
160
+ s1 = '80 0f 12 0001 80 70 03e801 000000010000000 10a0101'.split.join
161
+ s2 = '80 0f 16 0001 80 00000001 70 03e801 00000001000000010a0101'.split.join
162
+ assert_equal(s1, unreach1.to_shex)
163
+ assert_equal(s1, Mp_unreach.new(unreach1.encode).to_shex)
164
+ assert_equal(s2, unreach2.to_shex)
165
+ assert_equal(s2, Mp_unreach.new(unreach2.encode,true).to_shex)
166
+
167
+ end
168
+
169
+ private
170
+
171
+ def attr_len(attr)
172
+ attr.encode[2,1].unpack('C')[0]
173
+ end
174
+
67
175
  end
@@ -22,6 +22,7 @@
22
22
 
23
23
  require 'test/unit'
24
24
  require 'bgp/path_attributes/path_attribute'
25
+ require 'bgp/path_attributes/attributes'
25
26
 
26
27
  class Path_attribute_Test < Test::Unit::TestCase # :nodoc:
27
28
  include BGP
@@ -141,5 +142,36 @@ class Path_attribute_Test < Test::Unit::TestCase # :nodoc:
141
142
  assert @pa.has_a_local_pref_attr?
142
143
  assert ! @pa.has_a_aggregator_attr?
143
144
  assert ! @pa.has_a_mp_unreach_attr?
144
- end
145
- end
145
+ end
146
+
147
+ def test_7
148
+ s = '800e1000010404ffffffff0030000651c0a800'
149
+ sbin = [s].pack('H*')
150
+ assert_equal(BGP::Mp_reach, Attr.factory(sbin, :path_id=>false).class)
151
+ s = '800e1400010404ffffffff000000006430000651c0a800'
152
+ sbin = [s].pack('H*')
153
+ assert_equal(BGP::Mp_reach, Attr.factory(sbin, :path_id=>true).class)
154
+ end
155
+
156
+ def test_path_attribute_path_id_true_and_as4byte_false
157
+ path_attr = Path_attribute.new
158
+ path_attr.insert(
159
+ Origin.new,
160
+ As_path.new(100),
161
+ Mp_reach.new( :safi=>128, :nexthop=> ['10.0.0.1'], :path_id=> 100, :nlris=> [
162
+ {:rd=> [100,100], :prefix=> '192.168.0.0/24', :label=>101},
163
+ {:rd=> [100,100], :prefix=> '192.168.1.0/24', :label=>102},
164
+ {:rd=> [100,100], :prefix=> '192.168.2.0/24', :label=>103},
165
+ ])
166
+ )
167
+ assert_match(/ID=100, Label Stack=101/, path_attr.to_s)
168
+ path_attr_new = Path_attribute.new(path_attr.encode(true), :as4byte=> true, :path_id=>true)
169
+ assert_equal(path_attr.to_shex, path_attr_new.to_shex)
170
+
171
+ # TODO: UT: a path attr with mp_reach w path_id and ! as4
172
+ # TODO: UT: a path attr with mp_unreach w path_id
173
+ # TODO: UT: a path attr with mp_reach w path_id and as4
174
+
175
+ end
176
+
177
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 11
9
- version: 0.0.11
8
+ - 12
9
+ version: 0.0.12
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jean-Michel Esnault
@@ -14,12 +14,12 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-08 00:00:00 -08:00
17
+ date: 2011-02-13 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
21
21
  description: BGP4R is a BGP-4 ruby library to create, send, and receive BGP messages in an object oriented manner
22
- email: jesnault@gmail.com
22
+ email: bgp4r@esnault.org
23
23
  executables: []
24
24
 
25
25
  extensions: []
@@ -44,7 +44,8 @@ files:
44
44
  - bgp/messages/route_refresh.rb
45
45
  - bgp/messages/update.rb
46
46
  - bgp/misc/live_feed.rb
47
- - bgp/neighbor.rb
47
+ - bgp/neighbor/add_path_cap.rb
48
+ - bgp/neighbor/neighbor.rb
48
49
  - bgp/nlris/inet.rb
49
50
  - bgp/nlris/label.rb
50
51
  - bgp/nlris/labeled.rb
@@ -53,6 +54,7 @@ files:
53
54
  - bgp/nlris/prefix.rb
54
55
  - bgp/nlris/rd.rb
55
56
  - bgp/nlris/vpn.rb
57
+ - bgp/optional_parameters/add_path.rb
56
58
  - bgp/optional_parameters/as4.rb
57
59
  - bgp/optional_parameters/capabilities.rb
58
60
  - bgp/optional_parameters/capability.rb
@@ -90,8 +92,13 @@ files:
90
92
  - examples/unit-testing/malformed_update.rb
91
93
  - examples/unit-testing/no_export.rb
92
94
  - examples/unit-testing/prepend_aspath.rb
95
+ - examples/unit-testing/test.rb
96
+ - examples/unit-testing/test1.rb
97
+ - examples/unit-testing/test2.rb
93
98
  - examples/unit-testing/unknown_transitive_attr.rb
94
99
  - test/common_test.rb
100
+ - test/helpers/server.rb
101
+ - test/iana_test.rb
95
102
  - test/messages/capability_test.rb
96
103
  - test/messages/keepalive_test.rb
97
104
  - test/messages/markers_test.rb
@@ -102,12 +109,14 @@ files:
102
109
  - test/messages/update_test.rb
103
110
  - test/misc/live_feed_test.rb
104
111
  - test/misc/misc.rb
105
- - test/neighbor_test.rb
112
+ - test/neighbor/add_path_cap_test.rb
113
+ - test/neighbor/neighbor_test.rb
106
114
  - test/nlris/ext_nlri_test.rb
107
115
  - test/nlris/inet_test.rb
108
116
  - test/nlris/labeled_test.rb
109
117
  - test/nlris/nlri_test.rb
110
118
  - test/nlris/rd_test.rb
119
+ - test/optional_parameters/add_path_test.rb
111
120
  - test/optional_parameters/as4_test.rb
112
121
  - test/optional_parameters/capability_test.rb
113
122
  - test/optional_parameters/dynamic_test.rb
@@ -167,6 +176,8 @@ specification_version: 3
167
176
  summary: A BGP-4 Ruby Library
168
177
  test_files:
169
178
  - test/common_test.rb
179
+ - test/helpers/server.rb
180
+ - test/iana_test.rb
170
181
  - test/messages/capability_test.rb
171
182
  - test/messages/keepalive_test.rb
172
183
  - test/messages/markers_test.rb
@@ -177,12 +188,14 @@ test_files:
177
188
  - test/messages/update_test.rb
178
189
  - test/misc/live_feed_test.rb
179
190
  - test/misc/misc.rb
180
- - test/neighbor_test.rb
191
+ - test/neighbor/add_path_cap_test.rb
192
+ - test/neighbor/neighbor_test.rb
181
193
  - test/nlris/ext_nlri_test.rb
182
194
  - test/nlris/inet_test.rb
183
195
  - test/nlris/labeled_test.rb
184
196
  - test/nlris/nlri_test.rb
185
197
  - test/nlris/rd_test.rb
198
+ - test/optional_parameters/add_path_test.rb
186
199
  - test/optional_parameters/as4_test.rb
187
200
  - test/optional_parameters/capability_test.rb
188
201
  - test/optional_parameters/dynamic_test.rb
@@ -1,62 +0,0 @@
1
- #--
2
- # Copyright 2008, 2009 Jean-Michel Esnault.
3
- # All rights reserved.
4
- # See LICENSE.txt for permissions.
5
- #
6
- #
7
- # This file is part of BGP4R.
8
- #
9
- # BGP4R is free software: you can redistribute it and/or modify
10
- # it under the terms of the GNU General Public License as published by
11
- # the Free Software Foundation, either version 3 of the License, or
12
- # (at your option) any later version.
13
- #
14
- # BGP4R is distributed in the hope that it will be useful,
15
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- # GNU General Public License for more details.
18
- #
19
- # You should have received a copy of the GNU General Public License
20
- # along with BGP4R. If not, see <http://www.gnu.org/licenses/>.
21
- #++
22
-
23
- require "test/unit"
24
- require 'bgp4r'
25
-
26
- class TestBgpNeighbor < Test::Unit::TestCase
27
- include BGP
28
- include BGP::OPT_PARM::CAP
29
- def test_open_msg
30
- neighbor = Neighbor.new \
31
- :version=> 4,
32
- :my_as=> 100,
33
- :remote_addr => '192.168.1.200',
34
- :local_addr => '192.168.1.5',
35
- :id=> '1.1.1.1',
36
- :holdtime=> 20
37
- neighbor.capability Mbgp.ipv4_unicast
38
- neighbor.capability Mbgp.ipv4_multicast
39
- neighbor.capability Route_refresh.new
40
- neighbor.capability Route_refresh.new 128
41
- neighbor.capability As4.new(100)
42
- open_msg = neighbor.open
43
- assert_equal(5,open_msg.opt_parms.size)
44
- assert_equal(4,open_msg.version)
45
- assert_equal(20,open_msg.holdtime)
46
- assert_equal(100,open_msg.local_as)
47
- # puts neighbor
48
- end
49
- def test_states
50
- neighbor = Neighbor.new \
51
- :version=> 4,
52
- :my_as=> 100,
53
- :remote_addr => '192.168.1.200',
54
- :local_addr => '192.168.1.5',
55
- :id=> '1.1.1.1',
56
- :holdtime=> 20
57
- assert neighbor.is_idle?
58
- assert ! neighbor.is_established?
59
- assert ! neighbor.is_openrecv?
60
- assert ! neighbor.is_openconfirm?
61
- end
62
- end