bgp4r 0.0.11 → 0.0.12

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.
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
@@ -30,7 +30,6 @@ class Update_Test < Test::Unit::TestCase
30
30
  sbin = [s].pack('H*')
31
31
  u = Update.new(sbin)
32
32
  assert_equal(Update, Message.factory(sbin).class)
33
- #TODO: more tests with nrli, with withdrawns....
34
33
  end
35
34
  def test_2
36
35
  s = "
@@ -59,29 +58,28 @@ class Update_Test < Test::Unit::TestCase
59
58
  m = Message.factory([s].pack('H*'))
60
59
  w = Update.withdrawn(m)
61
60
  assert_equal(Update,w.class)
62
- assert_equal('000a200a0a0a0a2020202020', w.withdrawn.to_shex)
61
+ assert_equal('200a0a0a0a2020202020', w.withdrawn.to_shex)
63
62
  end
64
63
  def test_4
65
64
  an_update = Update.new(
66
- Path_attribute.new(
67
- Origin.new(1),
68
- Next_hop.new('192.168.1.5'),
69
- Multi_exit_disc.new(100),
70
- Local_pref.new(100),
71
- As_path.new(100,200,300),
72
- Communities.new('1311:1 311:59 2805:64')
73
- ),
74
- Nlri.new('77.0.0.0/17', '78.0.0.0/18', '79.0.0.0/19')
65
+ Path_attribute.new(
66
+ Origin.new(1),
67
+ Next_hop.new('192.168.1.5'),
68
+ Multi_exit_disc.new(100),
69
+ Local_pref.new(100),
70
+ As_path.new(100,200,300),
71
+ Communities.new('1311:1 311:59 2805:64')
72
+ ),
73
+ Nlri.new('77.0.0.0/17', '78.0.0.0/18', '79.0.0.0/19')
75
74
  )
76
- # Ship it!
75
+
77
76
  assert_equal(3*2, an_update.encode4.size - an_update.encode.size)
78
77
  end
79
-
80
78
  def test_5
81
79
  an_update = Update.new( Path_attribute.new( Origin.new(1),
82
- Next_hop.new('10.0.0.1'),
83
- Multi_exit_disc.new(100)
84
- ))
80
+ Next_hop.new('10.0.0.1'),
81
+ Multi_exit_disc.new(100)
82
+ ))
85
83
  assert ! an_update.path_attribute.has?(Local_pref), "Should not contain a Local Pref attr."
86
84
  an_update << Local_pref.new(113)
87
85
  assert an_update.path_attribute.has?(Local_pref), "Should contain a Local Pref attr."
@@ -94,13 +92,13 @@ class Update_Test < Test::Unit::TestCase
94
92
  an_update << Nlri.new('21.0.0.0/11', '22.0.0.0/22')
95
93
  assert_equal 4, an_update.nlri.size
96
94
  end
97
-
95
+
98
96
  def test_6
99
97
  s = 'ffffffffffffffffffffffffffffffff004a02000000274001010040020a0202000000c80000006440030428000101c0080c0137003b051f00010af50040114d0000124e0000134f0000'
100
- m = Message.factory([s].pack('H*'), true)
98
+ m = Message.factory([s].pack('H*'), Update::Info.new(true))
101
99
  assert_not_nil m
102
100
  assert_instance_of(Update, m)
103
- assert m.as4byte?
101
+ assert_equal(s, m.to_shex(Update::Info.new(true)))
104
102
  end
105
103
 
106
104
  def test_7
@@ -127,10 +125,12 @@ class Update_Test < Test::Unit::TestCase
127
125
  cluster: 0.0.0.1
128
126
  "
129
127
  end
130
-
128
+
131
129
  def test_8
130
+ o = Update::Info.new(true)
131
+ def o.recv_inet_unicast? ; false ; end
132
132
  s = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0072020000001F4001010040020A0204212C051319351AFE400304557200D9C00804212C045C175D76D6175D76DE1659299C175929981659235C16592D6417592D6417592D6617592D6217C3D228185D73241859284417C3FE84165C727015592190'
133
- m = Update.new([s].pack('H*'), true)
133
+ m = Update.new([s].pack('H*'), o)
134
134
  pa = m.path_attribute
135
135
  assert_equal '556533011 422910718', pa[As_path].as_path
136
136
  assert_equal '85.114.0.217', pa[Next_hop].next_hop
@@ -139,27 +139,124 @@ class Update_Test < Test::Unit::TestCase
139
139
  pa[:as_path].find_sequence.prepend(100)
140
140
  assert_equal '100 556533011 422910718', pa[As_path].as_path
141
141
  end
142
-
142
+
143
143
  def test_9
144
+ # FFFFFFFFFF
145
+ # 0023 02 000C 16D40374 1755C688 16D40830 0000
144
146
  s = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF002302000C16D403741755C68816D408300000'
145
147
  m = Update.new([s].pack('H*'))
146
148
  assert m.withdrawn, "Should contain withdrawn routes."
147
149
  assert_equal 3,m.withdrawn.nlris.size
148
150
  end
151
+
152
+ def test_10
153
+ o = Update::Info.new(true)
154
+ def o.recv_inet_unicast? ; true ; end
155
+ def o.send_inet_unicast? ; true ; end
156
+ upd1 = Update.new(
157
+ Path_attribute.new(
158
+ As_path.new(100)
159
+ ),
160
+ Ext_Nlri.new(100, Nlri.new('77.0.0.0/17'))
161
+ )
162
+ assert_equal('ffffffffffffffffffffffffffffffff0028020000000940020602010000006400000064114d0000', upd1.to_shex(o))
163
+ # Need to tell the factory we are dealing with a ext nlri.
164
+ upd2 = Update.factory(upd1.encode(o), o)
165
+ assert_equal(upd1.to_shex(o), upd2.to_shex(o))
166
+ end
149
167
 
150
- #--
151
- # def test_10
152
- # s = 'ffff ffff ffff ffff ffff ffff ffff ffff
153
- # 005f 0200 0000 4440 0101 0040 020e 0206
154
- # 0064 212c 232a 0ddd 53f9 5ba0 4003 0428
155
- # 0000 01c0 0810 212c 044d 232a 232a 232a
156
- # fc9d 000d 000b f011 1202 0400 0023 2a00
157
- # 000d dd00 0053 f900 0302 9e18 5bd9 c5
158
- # '.split.join
159
- # m = Update.new([s].pack('H*'))
160
- # p m.path_attribute[:next_hop]
161
- # p m.path_attribute[:as_path]
162
- # end
163
- #++
168
+ def test_path_id_and_as4byte
169
+ o = Update::Info.new(true)
170
+ def o.recv_inet_unicast? ; true ; end
171
+ def o.send_inet_unicast? ; true ; end
172
+ upd1 = Update.new(
173
+ Path_attribute.new(
174
+ Origin.new,
175
+ As_path.new(100),
176
+ Local_pref.new(10),
177
+ Multi_exit_disc.new(20),
178
+ Mp_reach.new( :safi=>128, :nexthop=> ['10.0.0.1'], :path_id=> 100, :nlris=> [
179
+ {:rd=> [100,100], :prefix=> '192.168.0.0/24', :label=>101},
180
+ {:rd=> [100,100], :prefix=> '192.168.1.0/24', :label=>102},
181
+ {:rd=> [100,100], :prefix=> '192.168.2.0/24', :label=>103},
182
+ ]))
183
+ )
184
+ assert_match(/ff{16}....020000/, upd1.to_shex)
185
+ assert upd1.path_attribute.has_a_mp_reach_attr?, "Expecting a MP_REACH Attr."
186
+ assert_match(/ID=100, Label Stack=102/,upd1.path_attribute[:mp_reach].to_s)
187
+
188
+ # received as2byte encode aspath attr
189
+ upd2 = Update.factory upd1.encode, :as4byte=> false, :path_id=>true
190
+ # received as4byte encode aspath attr
191
+ upd3 = Update.factory upd1.encode(o), :as4byte=> true, :path_id=>true
192
+ assert_equal upd1.to_shex, upd2.to_shex
193
+ assert_equal upd2.to_shex, upd3.to_shex
194
+
195
+ end
196
+
197
+ # updates with path_id
198
+
199
+ def ext_update(s)
200
+ sbin = [s.split.join].pack('H*')
201
+ o = Update::Info.new(true)
202
+ def o.path_id?(*args) ; true ; end
203
+ def o.recv_inet_unicast? ; true ; end
204
+ def o.send_inet_unicast? ; true ; end
205
+ Update.factory(sbin,o)
206
+ end
207
+
208
+ def test_path_id_inet_unicast
209
+ upd = ext_update "
210
+ ffff ffff ffff ffff ffff ffff ffff ffff
211
+ 003c 0200 0000 1c40 0101 0040 0200 4003
212
+ 040a 0000 0180 0404 0000 0066 4005 0400
213
+ 0000 6500 0000 6419 1400 0000"
214
+ assert_equal(BGP::Update, upd.class)
215
+ assert_equal 'ID: 100, 20.0.0.0/25', upd.nlri.nlris[0].to_s
216
+
217
+ end
218
+
219
+ def test_path_id_inet_mpls_vpn_unicast
220
+ s = "
221
+ ffff ffff ffff ffff ffff ffff ffff ffff
222
+ 005f 0200 0000 4840 0101 0140 0200 8004
223
+ 0400 0000 0040 0504 0000 0001 c010 0800
224
+ 0200 0400 0000 0190 0e00 2400 0180 0c00
225
+ 0000 0000 0000 0001 0101 0100 0000 0001
226
+ 7003 e801 0000 0013 0000 0011 0a01 01"
227
+ upd = ext_update(s)
228
+
229
+ s2 = "
230
+ ffffffffffffffffffffffffffffffff
231
+ 005e
232
+ 02
233
+ 0000
234
+ 0047
235
+ 40010101
236
+ 400200
237
+ 80040400000000
238
+ 40050400000001
239
+ c010080002000400000001
240
+ 800e240001800c00000000000000000101010100000000017003e80100000013000000110a0101
241
+ "
242
+ assert_equal(BGP::Update, upd.class)
243
+ assert upd.path_attribute.has_a_mp_reach_attr?
244
+ assert_equal s2.split.join, upd.to_shex
245
+ assert_equal s2.split.join, ext_update(upd.to_shex).to_shex
246
+
247
+ end
248
+
249
+ def test_path_id_inet_mpls_vpn_unicast_withdrawn
250
+ upd = ext_update "
251
+ ffff ffff ffff ffff ffff ffff ffff ffff
252
+ 0031 0200 0000 1a90 0f00 1600 0180 0000
253
+ 0001 7080 0001 0000 0001 0000 0001 0a01
254
+ 01"
255
+ assert upd.has_a_path_attribute?
256
+ assert upd.path_attribute.has_a_mp_unreach_attr?
257
+ mp_unreach = upd.path_attribute[:mp_unreach]
258
+ assert_equal 1, mp_unreach.nlris[0].path_id
259
+ assert_equal 'ID=1, Label Stack=524288 (bottom) RD=1:1, IPv4=10.1.1.0/24', mp_unreach.nlris[0].to_s
260
+ end
164
261
 
165
262
  end
@@ -0,0 +1,54 @@
1
+
2
+ require "test/unit"
3
+ require 'bgp4r'
4
+
5
+ class TestBgpNeighborAddPathCap < Test::Unit::TestCase
6
+ include BGP
7
+ def setup
8
+ end
9
+ def test_as4_cap
10
+ speaker = Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::As4.new(100))
11
+ peer = Open.new(4,100, 200, '10.0.0.1')
12
+ assert ! Neighbor::Capabilities.new(speaker, peer).as4byte?, "AS 2-Octet encoding expected!"
13
+ peer = Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::As4.new(100))
14
+ speaker = Open.new(4,100, 200, '10.0.0.1')
15
+ assert ! Neighbor::Capabilities.new(speaker, peer).as4byte?, "AS 2-Octet encoding expected!"
16
+ peer = Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::As4.new(100))
17
+ speaker = Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::As4.new(100))
18
+ assert Neighbor::Capabilities.new(speaker, peer).as4byte?, "AS 4-Octet encoding expected!"
19
+ end
20
+ def test_add_path_send_and_recv_inet_unicast
21
+ peer = Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::Add_path.new( :send_and_receive, 1, 1))
22
+ speaker = Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::Add_path.new( :send_and_receive, 1, 1))
23
+ session_cap = Neighbor::Capabilities.new(speaker, peer)
24
+ assert session_cap.send_inet_unicast?
25
+ assert session_cap.path_id_recv?(1,1)
26
+ assert session_cap.path_id_send?(1,1)
27
+ assert ! session_cap.send_inet_multicast?
28
+ end
29
+ def test_add_path_send_and_recv_inet6_multicast
30
+ peer = Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::Add_path.new( :send_and_receive, 2, 2))
31
+ speaker = Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::Add_path.new( :send_and_receive, 2, 2))
32
+ session_cap = Neighbor::Capabilities.new(speaker, peer)
33
+ assert ! session_cap.send_inet_unicast?
34
+ assert session_cap.send_inet6_multicast?
35
+ assert session_cap.recv_inet6_multicast?
36
+ end
37
+ def test_add_path_send_and_recv_inet_mpls_vpn_unicast
38
+ peer = Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::Add_path.new( :send_and_receive, 1, 128))
39
+ speaker = Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::Add_path.new( :send_and_receive, 1, 128))
40
+ session_cap = Neighbor::Capabilities.new(speaker, peer)
41
+ assert session_cap.send_inet_mpls_vpn_unicast?
42
+ assert ! session_cap.send_inet6_multicast?
43
+ assert ! session_cap.recv_inet6_multicast?
44
+ end
45
+ def test_add_path_send_and_recv_inet_mpls_vpn_multicast
46
+ peer = Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::Add_path.new( :send_and_receive, 1, 129))
47
+ speaker = Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::Add_path.new( :send_and_receive, 1, 129))
48
+ session_cap = Neighbor::Capabilities.new(speaker, peer)
49
+ assert session_cap.send_inet_mpls_vpn_multicast?
50
+ assert ! session_cap.send_inet_mpls_vpn_unicast?
51
+ assert ! session_cap.send_inet6_multicast?
52
+ assert ! session_cap.recv_inet6_multicast?
53
+ end
54
+ end
@@ -0,0 +1,161 @@
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
+ require 'test/helpers/server'
26
+
27
+ class TestBgpNeighbor < Test::Unit::TestCase
28
+ include BGP
29
+ include BGP::OPT_PARM::CAP
30
+ include BGP::TestHelpers
31
+ def setup
32
+ end
33
+ def teardown
34
+ end
35
+ def test_open_msg
36
+ neighbor = Neighbor.new \
37
+ :version=> 4,
38
+ :my_as=> 100,
39
+ :remote_addr => '192.168.1.200',
40
+ :local_addr => '192.168.1.5',
41
+ :id=> '1.1.1.1',
42
+ :holdtime=> 20
43
+ neighbor.capability Mbgp.ipv4_unicast
44
+ neighbor.capability Mbgp.ipv4_multicast
45
+ neighbor.capability Route_refresh.new
46
+ neighbor.capability Route_refresh.new 128
47
+ neighbor.capability As4.new(100)
48
+ open_msg = neighbor.open
49
+ assert_equal(5,open_msg.opt_parms.size)
50
+ assert_equal(4,open_msg.version)
51
+ assert_equal(20,open_msg.holdtime)
52
+ assert_equal(100,open_msg.local_as)
53
+ # puts neighbor
54
+ end
55
+ def test_neighbor_state_methods
56
+ neighbor = Neighbor.new \
57
+ :version=> 4,
58
+ :my_as=> 100,
59
+ :remote_addr => '192.168.1.200',
60
+ :local_addr => '192.168.1.5',
61
+ :id=> '1.1.1.1',
62
+ :holdtime=> 20
63
+ assert neighbor.is_idle?
64
+ assert ! neighbor.is_established?
65
+ assert ! neighbor.is_openrecv?
66
+ assert ! neighbor.is_openconfirm?
67
+ end
68
+ def test_start
69
+ start_server(3456)
70
+ @c = Neighbor.new(4, 100, 180, '0.0.0.2', '127.0.0.1', '127.0.0.1')
71
+ @c.start :port=> 3456
72
+ assert_equal('Established', @c.state)
73
+ assert_equal('Established', @s.state)
74
+ stop_server
75
+ end
76
+ def test_start_no_blocking
77
+ start_server(3333)
78
+ @c = Neighbor.new(4, 100, 180, '0.0.0.2', '127.0.0.1', '127.0.0.1')
79
+ @c.start :port=> 3333, :no_blocking=>true
80
+ assert_equal('OpenSent', @c.state)
81
+ assert_match(/(Active|OpenSent)/, @s.state)
82
+ stop_server
83
+ end
84
+ def test_send_and_receive_path_id_afi_1_safi_1
85
+ server_add_path_cap = BGP::OPT_PARM::CAP::Add_path.new
86
+ server_add_path_cap.add(:send_and_recv, 1, 1)
87
+ start_server(3456, server_add_path_cap)
88
+ @c = Neighbor.new(4, 100, 180, '0.0.0.2', '127.0.0.1', '127.0.0.1')
89
+ @c.add_cap server_add_path_cap
90
+ @c.start :port=> 3456
91
+ assert @s.session_info.recv_inet_unicast?,
92
+ "Should have the capability to recv inet unicast reachability path info."
93
+ assert @s.session_info.send_inet_unicast?,
94
+ "Should have the capability to send inet unicast reachability path info."
95
+ assert @c.session_info.recv_inet_unicast?,
96
+ "Should have the capability to recv inet unicast reachability path info."
97
+ assert @c.session_info.send_inet_unicast?,
98
+ "Should have the capability to send inet unicast reachability path info."
99
+ stop_server
100
+ end
101
+ def test_send_path_id_afi_1_safi_1
102
+ server_add_path_cap = BGP::OPT_PARM::CAP::Add_path.new
103
+ server_add_path_cap.add(:send, 1, 1)
104
+ client_add_path_cap = BGP::OPT_PARM::CAP::Add_path.new
105
+ client_add_path_cap.add(:recv, 1, 1)
106
+ start_server(3456, server_add_path_cap)
107
+ @c = Neighbor.new(4, 100, 180, '0.0.0.2', '127.0.0.1', '127.0.0.1')
108
+ @c.add_cap client_add_path_cap
109
+ @c.start :port=> 3456
110
+ assert ! @s.session_info.recv_inet_unicast?,
111
+ "Should NOT have the capability to recv inet unicast reachability path info."
112
+ assert @s.session_info.send_inet_unicast?,
113
+ "Should have the capability to send inet unicast reachability path info."
114
+ assert @c.session_info.recv_inet_unicast?,
115
+ "Should have the capability to recv inet unicast reachability path info."
116
+ assert ! @c.session_info.send_inet_unicast?,
117
+ "Should NOT have the capability to send inet unicast reachability path info."
118
+ stop_server
119
+ end
120
+ def test_recv_path_id_afi_1_safi_1
121
+ server_add_path_cap = BGP::OPT_PARM::CAP::Add_path.new
122
+ server_add_path_cap.add(:recv, 1, 1)
123
+ client_add_path_cap = BGP::OPT_PARM::CAP::Add_path.new
124
+ client_add_path_cap.add(:send, 1, 1)
125
+ start_server(3456, server_add_path_cap)
126
+ @c = Neighbor.new(4, 100, 180, '0.0.0.2', '127.0.0.1', '127.0.0.1')
127
+ @c.add_cap client_add_path_cap
128
+ @c.start :port=> 3456
129
+ assert @s.session_info.recv_inet_unicast?,
130
+ "Should have the capability to recv inet unicast reachability path info."
131
+ assert ! @s.session_info.send_inet_unicast?,
132
+ "Should NOT have the capability to send inet unicast reachability path info."
133
+ assert ! @c.session_info.recv_inet_unicast?,
134
+ "Should NOT have the capability to recv inet unicast reachability path info."
135
+ assert @c.session_info.send_inet_unicast?,
136
+ "Should have the capability to send inet unicast reachability path info."
137
+ stop_server
138
+ end
139
+
140
+ def test_nor_recv_nor_send_path_id_afi_1_safi_1
141
+ server_add_path_cap = BGP::OPT_PARM::CAP::Add_path.new
142
+ server_add_path_cap.add(:recv, 1, 1)
143
+ client_add_path_cap = BGP::OPT_PARM::CAP::Add_path.new
144
+ client_add_path_cap.add(:recv, 1, 1)
145
+ start_server(3456, server_add_path_cap)
146
+ @c = Neighbor.new(4, 100, 180, '0.0.0.2', '127.0.0.1', '127.0.0.1')
147
+ @c.add_cap client_add_path_cap
148
+ @c.start :port=> 3456
149
+ assert ! @s.session_info.recv_inet_unicast?,
150
+ "Should NOT have the capability to recv inet unicast reachability path info."
151
+ assert ! @s.session_info.send_inet_unicast?,
152
+ "Should NOT have the capability to send inet unicast reachability path info."
153
+ assert ! @c.session_info.recv_inet_unicast?,
154
+ "Should NOT have the capability to recv inet unicast reachability path info."
155
+ assert ! @c.session_info.send_inet_unicast?,
156
+ "Should have the capability to send inet unicast reachability path info."
157
+ stop_server
158
+ end
159
+
160
+
161
+ end
@@ -1,67 +1,32 @@
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
- #++
1
+ require "test/unit"
22
2
 
23
- require 'test/unit'
24
- require 'bgp/nlris/nlris'
3
+ require "bgp/nlris/nlri"
4
+ require "bgp/nlris/inet"
5
+ require "bgp/nlris/vpn"
6
+ require "bgp/nlris/labeled"
7
+ require "bgp/nlris/rd"
25
8
 
26
9
  class TestExtNlri < Test::Unit::TestCase
27
10
  include BGP
28
- def test_1
29
- nlri1 = Nlri.new
30
- nlri1 << Nlri::Ip4.new('20.0.0.0/15')
31
- nlri1 << '20.0.0.0/17'
32
- nlri1 << '20.0.0.0/24'
33
- s = '0f140010140011140000'
34
- nlri2 = Nlri.new([s].pack('H*'))
35
- assert_equal('0f140010140011140000', nlri2.to_shex)
36
- assert_raise(ArgumentError) { nlri2.to_shex(true) }
37
- assert_equal(3,nlri2.nlris.size)
11
+ def test_ext_nlri
12
+ ext_nlri = Ext_Nlri.new(100, Nlri.new('10.0.0.0/8'))
13
+ assert_equal '00000064080a', ext_nlri.to_shex
14
+ assert_equal '00000064080a', Ext_Nlri.new_ntop(ext_nlri.encode).to_shex
15
+ assert_equal '00000001200a0a0a0a', Ext_Nlri.new_ntop(['00000001200a0a0a0a'].pack('H*')).to_shex
38
16
  end
39
- end
40
-
41
- class Nlri_Test < Test::Unit::TestCase
42
- include BGP
43
- def test_1
44
- nlri1 = Nlri.new
45
- nlri1 << Nlri::Ip4.new('20.0.0.0/15')
46
- nlri1 << '20.0.0.0/17'
47
- nlri1 << '20.0.0.0/24'
48
- s = '0f140010140011140000'
49
- nlri2 = Nlri.new([s].pack('H*'))
50
- assert_equal('0f140010140011140000', nlri2.to_shex)
51
- assert_raise(ArgumentError) { nlri2.to_shex(true) }
52
- assert_equal(3,nlri2.nlris.size)
53
-
17
+ def _test_ext_nlris
18
+ ext_nlri = Ext_Nlri.new(100, Nlri.new('10.0.0.0/8','20.0.0.0/8'))
19
+ assert_equal '00000064080a', ext_nlri.to_shex
20
+ assert_equal '00000064080a', Ext_Nlri.new_ntop(ext_nlri.encode).to_shex
54
21
  end
55
-
56
- def test_2
57
- nlri1 = Nlri.new
58
- nlri1 << Nlri::Ip4.new('20.0.0.0/15')
59
- nlri1 << '20.0.0.0/17'
60
- nlri1 << '20.0.0.0/24'
61
- s = '0f140010140011140000'
62
- nlri2 = Nlri.new([s].pack('H*'))
63
- assert_equal('0f140010140011140000', nlri2.to_shex)
64
- assert_raise(ArgumentError) { nlri2.to_shex(true) }
65
- assert_equal(3,nlri2.nlris.size)
22
+ def test_ext_inet
23
+ assert_equal '0000006410c0a8', Ext_Nlri.new(100, Inet_multicast.new('192.168.0.0/16')).to_shex
24
+ assert_equal '00000064402011131100000000', Ext_Nlri.new(100, Inet_multicast.new('2011:1311::/64')).to_shex
25
+ end
26
+ def test_ext_labeled
27
+ assert_equal '00000064600000100000200000310a0000', Ext_Nlri.new(100, Labeled.new(Prefix.new('10.0.0.1/24'),1,2,3)).to_shex
28
+ assert_equal '00000064800006500006610000006400000064c0a8', Ext_Nlri.new(100, Labeled.new(Vpn.new('192.168.0.0/16', Rd.new(100,100)),101,102)).to_shex
29
+ assert_equal '00000064b80006500006600006710000006400000064200900040005', Ext_Nlri.new(100, Labeled.new(Vpn.new('2009:4:5::1/48', Rd.new(100,100)),101,102,103)).to_shex
30
+ assert_match(/ID=100, Label Stack=101/, Ext_Nlri.new(100, Labeled.new(Vpn.new('2009:4:5::1/48', Rd.new(100,100)),101,102,103)).to_s)
66
31
  end
67
- end
32
+ end