bgp4r 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/README.rdoc +1 -10
  2. data/bgp/io.rb +4 -2
  3. data/bgp/messages/capability.rb +176 -0
  4. data/bgp/messages/keepalive.rb +30 -0
  5. data/bgp/messages/markers.rb +10 -0
  6. data/bgp/messages/message.rb +85 -0
  7. data/bgp/messages/messages.rb +17 -0
  8. data/bgp/messages/notification.rb +116 -0
  9. data/bgp/messages/open.rb +117 -0
  10. data/bgp/messages/route_refresh.rb +181 -0
  11. data/bgp/messages/update.rb +148 -0
  12. data/bgp/neighbor.rb +20 -11
  13. data/bgp/nlris/inet.rb +18 -0
  14. data/bgp/{label.rb → nlris/label.rb} +1 -1
  15. data/bgp/nlris/labeled.rb +39 -0
  16. data/bgp/nlris/nlri.rb +154 -0
  17. data/bgp/{attributes.rb → nlris/nlris.rb} +11 -13
  18. data/bgp/nlris/prefix.rb +33 -0
  19. data/bgp/{rd.rb → nlris/rd.rb} +1 -1
  20. data/bgp/nlris/vpn.rb +68 -0
  21. data/bgp/optional_parameters/as4.rb +59 -0
  22. data/bgp/optional_parameters/capabilities.rb +13 -0
  23. data/bgp/optional_parameters/capability.rb +145 -0
  24. data/bgp/optional_parameters/dynamic.rb +37 -0
  25. data/bgp/optional_parameters/graceful_restart.rb +116 -0
  26. data/bgp/optional_parameters/mbgp.rb +97 -0
  27. data/bgp/optional_parameters/optional_parameter.rb +76 -0
  28. data/bgp/optional_parameters/orf.rb +90 -0
  29. data/bgp/optional_parameters/route_refresh.rb +36 -0
  30. data/bgp/{prefix_orf.rb → orfs/prefix_orf.rb} +4 -10
  31. data/bgp/{aggregator.rb → path_attributes/aggregator.rb} +2 -2
  32. data/bgp/{as_path.rb → path_attributes/as_path.rb} +2 -2
  33. data/bgp/{atomic_aggregate.rb → path_attributes/atomic_aggregate.rb} +2 -2
  34. data/bgp/{attribute.rb → path_attributes/attribute.rb} +2 -2
  35. data/bgp/path_attributes/attributes.rb +21 -0
  36. data/bgp/{cluster_list.rb → path_attributes/cluster_list.rb} +2 -2
  37. data/bgp/{communities.rb → path_attributes/communities.rb} +2 -2
  38. data/bgp/{extended_communities.rb → path_attributes/extended_communities.rb} +3 -3
  39. data/bgp/{extended_community.rb → path_attributes/extended_community.rb} +1 -1
  40. data/bgp/{local_pref.rb → path_attributes/local_pref.rb} +2 -2
  41. data/bgp/{mp_reach.rb → path_attributes/mp_reach.rb} +3 -69
  42. data/bgp/path_attributes/mp_unreach.rb +97 -0
  43. data/bgp/{multi_exit_disc.rb → path_attributes/multi_exit_disc.rb} +2 -2
  44. data/bgp/{next_hop.rb → path_attributes/next_hop.rb} +2 -2
  45. data/bgp/{origin.rb → path_attributes/origin.rb} +2 -2
  46. data/bgp/{originator_id.rb → path_attributes/originator_id.rb} +2 -2
  47. data/bgp/{path_attribute.rb → path_attributes/path_attribute.rb} +6 -7
  48. data/bgp4r.gemspec +127 -67
  49. data/bgp4r.rb +5 -25
  50. data/examples/routegen +1 -1
  51. data/examples/routegen.yml +21 -5
  52. data/examples/simple.rb +4 -4
  53. data/examples/unit-testing/malformed_update.rb +1 -1
  54. data/examples/unit-testing/unknown_transitive_attr.rb +18 -10
  55. data/test/messages/capability_test.rb +113 -0
  56. data/test/messages/keepalive_test.rb +34 -0
  57. data/test/messages/markers_test.rb +33 -0
  58. data/test/messages/message_test.rb +43 -0
  59. data/test/messages/notification_test.rb +49 -0
  60. data/test/messages/open_test.rb +98 -0
  61. data/test/messages/route_refresh_test.rb +77 -0
  62. data/test/messages/update_test.rb +133 -0
  63. data/test/neighbor_test.rb +8 -9
  64. data/test/nlris/inet_test.rb +43 -0
  65. data/test/{label_test.rb → nlris/labeled_test.rb} +1 -1
  66. data/test/{nlri_test.rb → nlris/nlri_test.rb} +5 -1
  67. data/test/{rd_test.rb → nlris/rd_test.rb} +1 -2
  68. data/test/optional_parameters/as4_test.rb +34 -0
  69. data/test/optional_parameters/capability_test.rb +69 -0
  70. data/test/optional_parameters/dynamic_test.rb +34 -0
  71. data/test/optional_parameters/graceful_restart_test.rb +23 -0
  72. data/test/optional_parameters/mbgp_test.rb +35 -0
  73. data/test/optional_parameters/optional_parameter_test.rb +51 -0
  74. data/test/optional_parameters/orf_test.rb +42 -0
  75. data/test/optional_parameters/route_refresh_test.rb +32 -0
  76. data/test/{prefix_orf_test.rb → orfs/prefix_orf_test.rb} +2 -1
  77. data/test/{aggregator_test.rb → path_attributes/aggregator_test.rb} +1 -1
  78. data/test/{as_path_test.rb → path_attributes/as_path_test.rb} +1 -1
  79. data/test/{atomic_aggregate_test.rb → path_attributes/atomic_aggregate_test.rb} +1 -1
  80. data/test/{attribute_test.rb → path_attributes/attribute_test.rb} +2 -2
  81. data/test/{cluster_list_test.rb → path_attributes/cluster_list_test.rb} +1 -1
  82. data/test/{communities_test.rb → path_attributes/communities_test.rb} +1 -1
  83. data/test/{extended_communities_test.rb → path_attributes/extended_communities_test.rb} +1 -1
  84. data/test/{extended_community_test.rb → path_attributes/extended_community_test.rb} +1 -1
  85. data/test/{local_pref_test.rb → path_attributes/local_pref_test.rb} +1 -1
  86. data/test/{mp_reach_test.rb → path_attributes/mp_reach_test.rb} +1 -37
  87. data/test/path_attributes/mp_unreach_test.rb +67 -0
  88. data/test/{multi_exit_disc_test.rb → path_attributes/multi_exit_disc_test.rb} +1 -1
  89. data/test/{next_hop_test.rb → path_attributes/next_hop_test.rb} +1 -1
  90. data/test/{origin_test.rb → path_attributes/origin_test.rb} +2 -1
  91. data/test/{originator_id_test.rb → path_attributes/originator_id_test.rb} +1 -1
  92. data/test/{path_attribute_test.rb → path_attributes/path_attribute_test.rb} +2 -2
  93. metadata +122 -67
  94. data/bgp/message.rb +0 -921
  95. data/bgp/nlri.rb +0 -303
  96. data/bgp/version.rb +0 -3
  97. data/examples/unit-testing/keepalive_set_to_zeo.rb +0 -64
  98. data/test/message_test.rb +0 -347
  99. /data/bgp/{orf.rb → orfs/orf.rb} +0 -0
@@ -0,0 +1,49 @@
1
+ #--
2
+ # Copyright 2008, 2009, 2010 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 Notification_Test < Test::Unit::TestCase
27
+ include BGP
28
+ def test_1
29
+ assert_equal('Undefined', Notification.code_to_s(0))
30
+ assert_equal('Header Error', Notification.code_to_s(1))
31
+ assert_equal('OPEN msg error', Notification.code_to_s(2))
32
+ assert_equal('UPDATE msg error', Notification.code_to_s(3))
33
+ assert_equal('CAPABILITY Message Error', Notification.code_to_s(7))
34
+ assert_equal('Connection Not Synchronized', Notification.code_to_s(1,1))
35
+ assert_equal('Unrecognized Well-known Attribute', Notification.code_to_s(3,2))
36
+ assert_equal('Invalid Capability Length', Notification.code_to_s(7,2))
37
+ assert_equal('Malformed Capability Value', Notification.code_to_s(7,3))
38
+ notif = BGP::Notification.new(1,1)
39
+ assert_match /^(ff){16}0015030101$/, notif.to_shex
40
+ assert_equal(notif.encode, Notification.new(notif).encode)
41
+ notif = BGP::Notification.new(2,2,'some data')
42
+ assert_match /(ff){16}001e030202736f6d652064617461/, notif.to_shex
43
+ assert_equal(notif.encode, Notification.new(notif).encode)
44
+ s = 'ffffffffffffffffffffffffffffffff001e030202736f6d652064617461'
45
+ m = Message.factory([s].pack('H*'))
46
+ assert_equal(Notification, m.class)
47
+ assert_equal(m.encode, Notification.new(m).encode)
48
+ end
49
+ end
@@ -0,0 +1,98 @@
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 Open_Test < Test::Unit::TestCase
27
+ include BGP
28
+ include BGP::OPT_PARM::CAP
29
+ def test_1
30
+ s = "ffffffffffffffffffffffffffffffff001d0104006400c80a00000100"
31
+ sbin = [s].pack('H*')
32
+ assert_equal(Open, Message.factory(sbin).class)
33
+ open = Message.factory(sbin)
34
+ assert_equal(s, open.to_shex)
35
+ assert_equal(s, Open.new(4,100, 200, '10.0.0.1').to_shex)
36
+ # assert_equal(s, Open.new(4,100, 200, '10.0.0.1', []).to_shex)
37
+ assert_equal('00290104006400c80a0000010c020641040000006402020200', Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::As4.new(100), OPT_PARM::CAP::Route_refresh.new).to_shex[32..-1])
38
+ open1 = Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::As4.new(100), OPT_PARM::CAP::Route_refresh.new)
39
+ open2 = Open.new(open1.encode)
40
+ assert_equal('00290104006400c80a0000010c020641040000006402020200', open2.to_shex[32..-1])
41
+ open = Open.new(4,100, 200, '10.0.0.1')
42
+ open << OPT_PARM::CAP::As4.new(100)
43
+ open << OPT_PARM::CAP::Route_refresh.new
44
+ assert_equal('00290104006400c80a0000010c020641040000006402020200', open.to_shex[32..-1])
45
+ s = 'ffffffffffffffffffffffffffffffff002d0104626200b4513411091002060104000100800202800002020200'
46
+ open = BGP::Message.factory([s].pack('H*'))
47
+ assert_equal(s, open.to_shex)
48
+
49
+ s = "ffff ffff ffff ffff ffff
50
+ ffff ffff ffff 0038 0104 0023 00b4 1919
51
+ 1901 1b02 0601 0400 0100 0102 0280 0002
52
+ 0202 0002 0982 0700 0100 0101 8002".split.join
53
+ open = BGP::Message.factory([s].pack('H*'))
54
+ assert_equal(s, open.to_shex)
55
+
56
+ s = "ffffffffffffffffffffffffffffffff003d0104006400b402020202200206010400010001020601040001000202028000020202000206410400000064"
57
+ open = BGP::Message.factory([s].pack('H*'))
58
+ assert_equal(4, open.version)
59
+ assert_equal(100, open.local_as)
60
+ assert_equal('2.2.2.2', open.bgp_id)
61
+ assert_equal(180, open.holdtime)
62
+ assert_equal(5, open.opt_parms.size)
63
+ assert_equal(Mbgp, open.opt_parms[1].class)
64
+ assert_equal(Route_refresh, open.opt_parms[2].class)
65
+ assert_equal(Route_refresh, open.opt_parms[3].class)
66
+ assert_equal(As4, open.opt_parms[4].class)
67
+
68
+ end
69
+ def test_2
70
+ s = "ffffffffffffffffffffffffffffffff003d0104006400b402020202200206010400010001020601040001000202028000020202000206410400000064"
71
+ open = BGP::Message.factory([s].pack('H*'))
72
+ assert_equal(5, open.to_hash[:capabilities].size )
73
+ assert_equal(1, open.to_hash[:capabilities][0][:code])
74
+ assert_equal({:safi=>1, :afi=>1}, open.to_hash[:capabilities][0][:capability])
75
+ assert_equal(1, open.to_hash[:capabilities][1][:code])
76
+ assert_equal({:safi=>2, :afi=>1}, open.to_hash[:capabilities][1][:capability])
77
+ assert_equal(128, open.to_hash[:capabilities][2][:code])
78
+ assert_nil(open.to_hash[:capabilities][2][:capability])
79
+ assert_equal(2, open.to_hash[:capabilities][3][:code])
80
+ assert_nil(open.to_hash[:capabilities][3][:capability])
81
+ assert_equal(65, open.to_hash[:capabilities][4][:code])
82
+ assert_equal(100,open.to_hash[:capabilities][4 ][:capability][:as])
83
+ end
84
+ def test_3
85
+ s = "
86
+ ffff ffff ffff ffff ffff ffff ffff ffff
87
+ 003f 0104 00c8 005a c0a8 7f01 2202 0601
88
+ 0400 0100 0102 0280 0002 0202 0002 0840
89
+ 0600 7800 0101 8002 0641 0400 0000 c8
90
+ ".split.join
91
+ open = BGP::Message.factory([s].pack('H*'))
92
+ assert_equal s, open.to_shex
93
+ end
94
+ def test_4
95
+ end
96
+
97
+
98
+ end
@@ -0,0 +1,77 @@
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 Route_refresh_Test < Test::Unit::TestCase
27
+ include BGP
28
+ def test_1
29
+ s = "ffffffffffffffffffffffffffffffff00170500010001"
30
+ sbin = [s].pack('H*')
31
+ assert_equal(Route_refresh, Message.factory(sbin).class)
32
+ rr = Message.factory(sbin)
33
+ assert_equal(s, rr.to_shex)
34
+ rr.afi, rr.safi=2,2
35
+ assert_equal(2, rr.afi)
36
+ assert_equal(2, rr.safi)
37
+ assert_equal('ffffffffffffffffffffffffffffffff00170500020002', rr.to_shex)
38
+ assert_raise(ArgumentError) { rr.safi=0x100 }
39
+ assert_raise(ArgumentError) { rr.afi=-1 }
40
+ assert_equal(s, Route_refresh.new(1,1).to_shex)
41
+ assert_equal(s, Route_refresh.new(:afi=>1, :safi=>1).to_shex)
42
+ assert_equal({:afi=>1, :safi=>1}, Route_refresh.new(:afi=>1, :safi=>1).to_hash)
43
+ assert_equal(s, Message.route_refresh(1,1).unpack('H*')[0])
44
+ end
45
+ end
46
+
47
+
48
+ class Orf_route_refresh_Test < Test::Unit::TestCase
49
+ include BGP
50
+
51
+ def test_1
52
+ rr = Orf_route_refresh.new
53
+ orf = Prefix_orf.new([
54
+ Prefix_entry.add_and_permit(10,'10.0.0.0/8'),
55
+ Prefix_entry.add_and_permit(20,'20.0.0.0/8'),
56
+ Prefix_entry.add_and_permit(30,'30.0.0.0/8'),
57
+ Prefix_entry.add_and_permit(40,'40.0.0.0/8'),
58
+ Prefix_entry.add_and_permit(50,'50.0.0.0/8'),
59
+ ])
60
+ rr << orf
61
+ rr.afi=1
62
+ rr.safi=1
63
+ assert_equal('0047050001000140002d000000000a0000080a000000001400000814000000001e0000081e000000002800000828000000003200000832',rr.to_shex[32..-1])
64
+ assert_equal('IPv4', rr.afi)
65
+ assert_equal('Unicast', rr.safi)
66
+ assert_equal(1, rr.orfs.size)
67
+ assert_match(/RF Route Refresh \(5\), length: 71\nAFI IPv4 \(1\), SAFI Unicast \(1\)/, rr.to_s)
68
+ end
69
+
70
+ def test_2
71
+ s = "ffffffffffffffffffffffffffffffff0047050001000140002d000000000a0000080a000000001400000814000000001e0000081e000000002800000828000000003200000832"
72
+ sbin = [s].pack('H*')
73
+ assert_equal(Orf_route_refresh, Message.factory(sbin).class)
74
+ rr = Message.factory(sbin)
75
+ assert_equal(s, rr.to_shex)
76
+ end
77
+ end
@@ -0,0 +1,133 @@
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 Update_Test < Test::Unit::TestCase
27
+ include BGP
28
+ def test_1
29
+ s = "ffffffffffffffffffffffffffffffff006b0200000054400101024002009004040000000040050400000064c0100800020c8f04127ee8800a0800000001000000048009045134134d800e1f0001800c00000000000000005134134d00680114d100000c8f041291480a39"
30
+ sbin = [s].pack('H*')
31
+ u = Update.new(sbin)
32
+ assert_equal(Update, Message.factory(sbin).class)
33
+ #TODO: more tests with nrli, with withdrawns....
34
+ end
35
+ def test_2
36
+ s = "
37
+ ffff ffff ffff ffff
38
+ ffff ffff ffff ffff 0070 0200 0000 5940
39
+ 0101 0240 0200 8004 0400 0000 0040 0504
40
+ 0000 0064 c008 0428 2b4e 87c0 1008 0002
41
+ 282b 0000 7530 800a 0400 0000 0180 0904
42
+ 5134 1180 800e 2100 0180 0c00 0000 0000
43
+ 0000 0051 3411 8000 7800 73b1 0000 0c8f
44
+ 0013 b42c ac1f 3ffb
45
+ ".split.join
46
+ m = Message.factory([s].pack('H*'))
47
+ assert_equal(Update, m.class)
48
+ assert_equal(s, m.to_shex)
49
+ assert_equal(9, m.path_attribute.size)
50
+
51
+ s = 'ffffffffffffffffffffffffffffffff0050020000002f40010101400304c0a80105800404000000644005040000006440020402010064c0080c051f00010137003b0af50040200a0a0a0a2020202020'
52
+ m = Message.factory([s].pack('H*'))
53
+ assert_equal(Update, m.class)
54
+ assert_equal(2,m.nlri.size)
55
+ assert_equal("10.10.10.10/32\n32.32.32.32/32", m.nlri.to_s)
56
+ end
57
+ def test_3
58
+ s = 'ffffffffffffffffffffffffffffffff0050020000002f40010101400304c0a80105800404000000644005040000006440020402010064c0080c051f00010137003b0af50040200a0a0a0a2020202020'
59
+ m = Message.factory([s].pack('H*'))
60
+ w = Update.withdrawn(m)
61
+ assert_equal(Update,w.class)
62
+ assert_equal('000a200a0a0a0a2020202020', w.withdrawn.to_shex)
63
+ end
64
+ def test_4
65
+ 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')
75
+ )
76
+ # Ship it!
77
+ assert_equal(3*2, an_update.encode4.size - an_update.encode.size)
78
+ end
79
+
80
+ def test_5
81
+ 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
+ ))
85
+ assert ! an_update.path_attribute.has?(Local_pref), "Should not contain a Local Pref attr."
86
+ an_update << Local_pref.new(113)
87
+ assert an_update.path_attribute.has?(Local_pref), "Should contain a Local Pref attr."
88
+ assert_nil an_update.nlri
89
+ an_update << '77.0.0.0/17'
90
+ assert_equal Nlri, an_update.nlri.class
91
+ assert_equal 1, an_update.nlri.size
92
+ an_update << '88.0.0.0/18'
93
+ assert_equal 2, an_update.nlri.size
94
+ an_update << Nlri.new('21.0.0.0/11', '22.0.0.0/22')
95
+ assert_equal 4, an_update.nlri.size
96
+ end
97
+
98
+ def test_6
99
+ s = 'ffffffffffffffffffffffffffffffff004a02000000274001010040020a0202000000c80000006440030428000101c0080c0137003b051f00010af50040114d0000124e0000134f0000'
100
+ m = Message.factory([s].pack('H*'), true)
101
+ assert_not_nil m
102
+ assert_instance_of(Update, m)
103
+ assert m.as4byte?
104
+ end
105
+
106
+ def test_7
107
+ # build an update from a yaml description
108
+ # advertised 172.18.179.192/27
109
+ # origin igp
110
+ # nexthop 193.251.127.210
111
+ # metric 0
112
+ # locpref 310000
113
+ # community 3215:102 3215:210 3215:522 3215:588 3215:903 3215:7553 3215:8000 3215:8003
114
+ # originatorid 193.252.102.210
115
+ # cluster 0.0.17.49 0.0.29.76 0.0.29.79
116
+ require 'yaml'
117
+ require 'pp'
118
+ s = "
119
+ ---
120
+ prefixes:202.44.2.0/24 202.44.3.0/24 202.44.5.0/24 202.44.6.0/24 202.44.7.0/24
121
+ origin: incomplete
122
+ nexthop: 10.0.0.1
123
+ metric: 0
124
+ localpref: 13000
125
+ community: 3230:10 3230:110 3230:411 3230:912 3230:1010 3230:5911
126
+ originator-id: 10.0.0.2
127
+ cluster: 0.0.0.1
128
+ "
129
+
130
+
131
+ end
132
+
133
+ end
@@ -21,25 +21,24 @@
21
21
  #++
22
22
 
23
23
  require "test/unit"
24
-
25
- require "bgp/neighbor"
26
- require 'bgp/message'
24
+ require 'bgp4r'
27
25
 
28
26
  class TestBgpNeighbor < Test::Unit::TestCase
29
27
  include BGP
28
+ include BGP::OPT_PARM::CAP
30
29
  def test_open_msg
31
30
  neighbor = Neighbor.new \
32
31
  :version=> 4,
33
32
  :my_as=> 100,
34
- :remote_addr => '192.168.1.200',
33
+ :remote_addr => '192.168.1.200',
35
34
  :local_addr => '192.168.1.5',
36
35
  :id=> '1.1.1.1',
37
36
  :holdtime=> 20
38
- neighbor.capability Mbgp_cap.ipv4_unicast
39
- neighbor.capability Mbgp_cap.ipv4_multicast
40
- neighbor.capability Route_refresh_cap.new
41
- neighbor.capability Route_refresh_cap.new 128
42
- neighbor.capability As4_cap.new(100)
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)
43
42
  open_msg = neighbor.open
44
43
  assert_equal(5,open_msg.opt_parms.size)
45
44
  assert_equal(4,open_msg.version)
@@ -0,0 +1,43 @@
1
+ #--
2
+ # Copyright 2008, 2009, 2010 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 'bgp/nlris/nlris'
24
+ require 'test/unit'
25
+
26
+ class Inet_unicast_Test < Test::Unit::TestCase
27
+ include BGP
28
+ def test_1
29
+ assert_equal(1,Inet_unicast.new('192.168.0.0/16').afi)
30
+ assert_equal(1,Inet_unicast.new('192.168.0.0/16').safi)
31
+ assert_equal(2,Inet_unicast.new('2009:4:4::/64').afi)
32
+ assert_equal(1,Inet_unicast.new('2009:4:4::/64').safi)
33
+ end
34
+ end
35
+ class Inet_multicast_Test < Test::Unit::TestCase
36
+ include BGP
37
+ def test_1
38
+ assert_equal(1,Inet_multicast.new('192.168.0.0/16').afi)
39
+ assert_equal(2,Inet_multicast.new('192.168.0.0/16').safi)
40
+ assert_equal(2,Inet_multicast.new('2009:4:4::/64').afi)
41
+ assert_equal(2,Inet_multicast.new('2009:4:4::/64').safi)
42
+ end
43
+ end
@@ -20,7 +20,7 @@
20
20
  # along with BGP4R. If not, see <http://www.gnu.org/licenses/>.
21
21
  #++
22
22
 
23
- require 'bgp/label'
23
+ require 'bgp/nlris/label'
24
24
  require 'test/unit'
25
25
 
26
26
  class Label_Test < Test::Unit::TestCase
@@ -20,7 +20,11 @@
20
20
  # along with BGP4R. If not, see <http://www.gnu.org/licenses/>.
21
21
  #++
22
22
 
23
- require 'bgp/nlri'
23
+ require 'bgp/nlris/nlris'
24
+ # require 'bgp/nlris/vpn'
25
+ # require 'bgp/nlris/inet'
26
+ # require 'bgp/nlris/labeled'
27
+
24
28
  require 'test/unit'
25
29
  class NLRI_Ip4_Test < Test::Unit::TestCase
26
30
  include BGP
@@ -20,7 +20,7 @@
20
20
  # along with BGP4R. If not, see <http://www.gnu.org/licenses/>.
21
21
  #++
22
22
 
23
- require 'bgp/rd'
23
+ require 'bgp/nlris/rd'
24
24
 
25
25
  require 'test/unit'
26
26
  class Rd_Test < Test::Unit::TestCase
@@ -40,5 +40,4 @@ class Rd_Test < Test::Unit::TestCase
40
40
  assert_equal('0001010101010001', Rd.new(['0001010101010001'].pack('H*')).to_shex)
41
41
  assert_equal('0002000000010101', Rd.new(['0002000000010101'].pack('H*')).to_shex)
42
42
  end
43
-
44
43
  end
@@ -0,0 +1,34 @@
1
+ #--
2
+ # Copyright 2010 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 As4_capability_Test < Test::Unit::TestCase
27
+ include BGP::OPT_PARM::CAP
28
+ def test_1
29
+ cap1 = As4.new(100)
30
+ cap2 = As4.new(['0206410400000064'].pack('H*'))
31
+ cap3 = As4.new(cap1.encode)
32
+ assert_equal(cap2.encode, cap3.encode)
33
+ end
34
+ end
@@ -0,0 +1,69 @@
1
+ #--
2
+ # Copyright 2010 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 Capability_Test < Test::Unit::TestCase
27
+ include BGP::OPT_PARM
28
+ include BGP::OPT_PARM::CAP
29
+ def test_1
30
+ cap = Capability.new(100)
31
+ assert_equal '02026400', cap.to_shex
32
+ assert_equal '0207640576616c7565', cap.to_shex('value')
33
+ assert_equal "Option Capabilities Advertisement (2): [02026400]", cap.to_s
34
+ assert_equal cap.to_shex, Capability.factory(cap.encode).to_shex
35
+ end
36
+ def test_factory_graceful_restart
37
+ s = '020c400a00780001010100010201'
38
+ cap = Capability.factory([s].pack('H*'))
39
+ assert_instance_of(Graceful_restart, cap)
40
+ end
41
+ def test_factory_as4
42
+ s = '0206410400000064'
43
+ cap = Capability.factory([s].pack('H*'))
44
+ assert_instance_of(As4, cap)
45
+ end
46
+ def test_factory_route_refresh
47
+ s = '02020200'
48
+ cap = Capability.factory([s].pack('H*'))
49
+ assert_instance_of(Route_refresh, cap)
50
+ s = '02028000'
51
+ cap = Capability.factory([s].pack('H*'))
52
+ assert_instance_of(Route_refresh, cap)
53
+ end
54
+ def test_factory_mbgp
55
+ s = '0206010400010001'
56
+ cap = Capability.factory([s].pack('H*'))
57
+ assert_instance_of(Mbgp, cap)
58
+ end
59
+ def test_factory_orf
60
+ s = '0218031600010001030101020103010001000203010102010301'
61
+ cap = Capability.factory([s].pack('H*'))
62
+ assert_equal(Orf, cap.class)
63
+ end
64
+ def test_factory_unknown
65
+ s = '0207640576616c7565'
66
+ cap = Capability.factory([s].pack('H*'))
67
+ assert_equal(Capability::Unknown, cap.class)
68
+ end
69
+ end
@@ -0,0 +1,34 @@
1
+ #--
2
+ # Copyright 2010 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 Dynamic_capability_Test < Test::Unit::TestCase
27
+ include BGP::OPT_PARM::CAP
28
+ def test_1
29
+ assert_equal('02024300',Dynamic.new.to_shex)
30
+ end
31
+ def test_2
32
+ assert_equal '02024300', Dynamic.new.to_shex
33
+ end
34
+ end
@@ -0,0 +1,23 @@
1
+ require "test/unit"
2
+ require "bgp/optional_parameters/graceful_restart"
3
+
4
+ class TestBgpOptionalParametersGracefulCapRestart < Test::Unit::TestCase
5
+ include BGP::OPT_PARM::CAP
6
+ def test_1
7
+
8
+ gr = Graceful_restart.new 0, 120
9
+ gr.add( 1, 1, 0x80)
10
+ assert_equal '02084006007800010180', gr.to_shex
11
+ gr2 = Graceful_restart.new(gr.encode)
12
+ assert_equal gr.to_shex, gr2.to_shex
13
+ gr.add( 1, 2, 0x80)
14
+ assert_equal '020c400a00780001018000010280', gr.to_shex
15
+
16
+ gr2 = Graceful_restart.new 0, 120
17
+ gr2.add(:ipv4, :unicast, 1)
18
+ assert_equal '02084006007800010101', gr2.to_shex
19
+ gr2.add( :ipv4, :multicast, 1)
20
+ assert_equal '020c400a00780001018000010280', gr.to_shex
21
+
22
+ end
23
+ end
@@ -0,0 +1,35 @@
1
+ #--
2
+ # Copyright 2010 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 Mbgp_cap_Test < Test::Unit::TestCase
27
+ include BGP::OPT_PARM::CAP
28
+ def test_1
29
+ mbgp1 = Mbgp.new(1,1)
30
+ mbgp2 = Mbgp.new(['0206010400010001'].pack('H*'))
31
+ mbgp3 = Mbgp.new(mbgp1.encode)
32
+ assert_equal(mbgp2.encode, mbgp3.encode)
33
+ assert_equal "Option Capabilities Advertisement (2): [0206010400010001]\n Multiprotocol Extensions (1), length: 4\n AFI IPv4 (1), SAFI Unicast (1)", mbgp2.to_s
34
+ end
35
+ end