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
data/bgp4r.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bgp4r}
8
- s.version = "0.0.8"
8
+ s.version = "0.0.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jean-Michel Esnault"]
12
- s.date = %q{2010-09-30}
12
+ s.date = %q{2010-10-12}
13
13
  s.description = %q{BGP4R is a BGP-4 ruby library to create, send, and receive BGP messages in an object oriented manner}
14
14
  s.email = %q{jesnault@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -20,64 +20,102 @@ Gem::Specification.new do |s|
20
20
  "COPYING",
21
21
  "LICENSE.txt",
22
22
  "README.rdoc",
23
- "bgp/aggregator.rb",
24
- "bgp/as_path.rb",
25
- "bgp/atomic_aggregate.rb",
26
- "bgp/attribute.rb",
27
- "bgp/attributes.rb",
28
- "bgp/cluster_list.rb",
29
23
  "bgp/common.rb",
30
- "bgp/communities.rb",
31
- "bgp/extended_communities.rb",
32
- "bgp/extended_community.rb",
33
24
  "bgp/iana.rb",
34
25
  "bgp/io.rb",
35
- "bgp/label.rb",
36
- "bgp/local_pref.rb",
37
- "bgp/message.rb",
38
- "bgp/mp_reach.rb",
39
- "bgp/multi_exit_disc.rb",
26
+ "bgp/messages/capability.rb",
27
+ "bgp/messages/keepalive.rb",
28
+ "bgp/messages/markers.rb",
29
+ "bgp/messages/message.rb",
30
+ "bgp/messages/messages.rb",
31
+ "bgp/messages/notification.rb",
32
+ "bgp/messages/open.rb",
33
+ "bgp/messages/route_refresh.rb",
34
+ "bgp/messages/update.rb",
40
35
  "bgp/neighbor.rb",
41
- "bgp/next_hop.rb",
42
- "bgp/nlri.rb",
43
- "bgp/orf.rb",
44
- "bgp/origin.rb",
45
- "bgp/originator_id.rb",
46
- "bgp/path_attribute.rb",
47
- "bgp/prefix_orf.rb",
48
- "bgp/rd.rb",
49
- "bgp/version.rb",
36
+ "bgp/nlris/inet.rb",
37
+ "bgp/nlris/label.rb",
38
+ "bgp/nlris/labeled.rb",
39
+ "bgp/nlris/nlri.rb",
40
+ "bgp/nlris/nlris.rb",
41
+ "bgp/nlris/prefix.rb",
42
+ "bgp/nlris/rd.rb",
43
+ "bgp/nlris/vpn.rb",
44
+ "bgp/optional_parameters/as4.rb",
45
+ "bgp/optional_parameters/capabilities.rb",
46
+ "bgp/optional_parameters/capability.rb",
47
+ "bgp/optional_parameters/dynamic.rb",
48
+ "bgp/optional_parameters/graceful_restart.rb",
49
+ "bgp/optional_parameters/mbgp.rb",
50
+ "bgp/optional_parameters/optional_parameter.rb",
51
+ "bgp/optional_parameters/orf.rb",
52
+ "bgp/optional_parameters/route_refresh.rb",
53
+ "bgp/orfs/orf.rb",
54
+ "bgp/orfs/prefix_orf.rb",
55
+ "bgp/path_attributes/aggregator.rb",
56
+ "bgp/path_attributes/as_path.rb",
57
+ "bgp/path_attributes/atomic_aggregate.rb",
58
+ "bgp/path_attributes/attribute.rb",
59
+ "bgp/path_attributes/attributes.rb",
60
+ "bgp/path_attributes/cluster_list.rb",
61
+ "bgp/path_attributes/communities.rb",
62
+ "bgp/path_attributes/extended_communities.rb",
63
+ "bgp/path_attributes/extended_community.rb",
64
+ "bgp/path_attributes/local_pref.rb",
65
+ "bgp/path_attributes/mp_reach.rb",
66
+ "bgp/path_attributes/mp_unreach.rb",
67
+ "bgp/path_attributes/multi_exit_disc.rb",
68
+ "bgp/path_attributes/next_hop.rb",
69
+ "bgp/path_attributes/origin.rb",
70
+ "bgp/path_attributes/originator_id.rb",
71
+ "bgp/path_attributes/path_attribute.rb",
50
72
  "bgp4r.gemspec",
51
73
  "bgp4r.rb",
52
74
  "examples/routegen",
53
75
  "examples/routegen.yml",
54
76
  "examples/simple.rb",
55
- "examples/unit-testing/keepalive_set_to_zeo.rb",
56
77
  "examples/unit-testing/malformed_update.rb",
57
78
  "examples/unit-testing/prepend_aspath.rb",
58
79
  "examples/unit-testing/unknown_transitive_attr.rb",
59
- "test/aggregator_test.rb",
60
- "test/as_path_test.rb",
61
- "test/atomic_aggregate_test.rb",
62
- "test/attribute_test.rb",
63
- "test/cluster_list_test.rb",
64
80
  "test/common_test.rb",
65
- "test/communities_test.rb",
66
- "test/extended_communities_test.rb",
67
- "test/extended_community_test.rb",
68
- "test/label_test.rb",
69
- "test/local_pref_test.rb",
70
- "test/message_test.rb",
71
- "test/mp_reach_test.rb",
72
- "test/multi_exit_disc_test.rb",
81
+ "test/messages/capability_test.rb",
82
+ "test/messages/keepalive_test.rb",
83
+ "test/messages/markers_test.rb",
84
+ "test/messages/message_test.rb",
85
+ "test/messages/notification_test.rb",
86
+ "test/messages/open_test.rb",
87
+ "test/messages/route_refresh_test.rb",
88
+ "test/messages/update_test.rb",
73
89
  "test/neighbor_test.rb",
74
- "test/next_hop_test.rb",
75
- "test/nlri_test.rb",
76
- "test/origin_test.rb",
77
- "test/originator_id_test.rb",
78
- "test/path_attribute_test.rb",
79
- "test/prefix_orf_test.rb",
80
- "test/rd_test.rb"
90
+ "test/nlris/inet_test.rb",
91
+ "test/nlris/labeled_test.rb",
92
+ "test/nlris/nlri_test.rb",
93
+ "test/nlris/rd_test.rb",
94
+ "test/optional_parameters/as4_test.rb",
95
+ "test/optional_parameters/capability_test.rb",
96
+ "test/optional_parameters/dynamic_test.rb",
97
+ "test/optional_parameters/graceful_restart_test.rb",
98
+ "test/optional_parameters/mbgp_test.rb",
99
+ "test/optional_parameters/optional_parameter_test.rb",
100
+ "test/optional_parameters/orf_test.rb",
101
+ "test/optional_parameters/route_refresh_test.rb",
102
+ "test/orfs/prefix_orf_test.rb",
103
+ "test/path_attributes/aggregator_test.rb",
104
+ "test/path_attributes/as_path_test.rb",
105
+ "test/path_attributes/atomic_aggregate_test.rb",
106
+ "test/path_attributes/attribute_test.rb",
107
+ "test/path_attributes/cluster_list_test.rb",
108
+ "test/path_attributes/communities_test.rb",
109
+ "test/path_attributes/extended_communities_test.rb",
110
+ "test/path_attributes/extended_community_test.rb",
111
+ "test/path_attributes/local_pref_test.rb",
112
+ "test/path_attributes/mp_reach_test.rb",
113
+ "test/path_attributes/mp_unreach_test.rb",
114
+ "test/path_attributes/multi_exit_disc_test.rb",
115
+ "test/path_attributes/next_hop_test.rb",
116
+ "test/path_attributes/origin_test.rb",
117
+ "test/path_attributes/originator_id_test.rb",
118
+ "test/path_attributes/path_attribute_test.rb"
81
119
  ]
82
120
  s.homepage = %q{http://github.com/jesnault/bgp4r/tree/master}
83
121
  s.rdoc_options = ["--quiet", "--title", "A BGP-4 Ruby Library", "--line-numbers"]
@@ -87,28 +125,50 @@ Gem::Specification.new do |s|
87
125
  s.rubygems_version = %q{1.3.6}
88
126
  s.summary = %q{A BGP-4 Ruby Library}
89
127
  s.test_files = [
90
- "test/aggregator_test.rb",
91
- "test/as_path_test.rb",
92
- "test/atomic_aggregate_test.rb",
93
- "test/attribute_test.rb",
94
- "test/cluster_list_test.rb",
95
- "test/common_test.rb",
96
- "test/communities_test.rb",
97
- "test/extended_communities_test.rb",
98
- "test/extended_community_test.rb",
99
- "test/label_test.rb",
100
- "test/local_pref_test.rb",
101
- "test/message_test.rb",
102
- "test/mp_reach_test.rb",
103
- "test/multi_exit_disc_test.rb",
128
+ "test/common_test.rb",
129
+ "test/messages",
130
+ "test/messages/capability_test.rb",
131
+ "test/messages/keepalive_test.rb",
132
+ "test/messages/markers_test.rb",
133
+ "test/messages/message_test.rb",
134
+ "test/messages/notification_test.rb",
135
+ "test/messages/open_test.rb",
136
+ "test/messages/route_refresh_test.rb",
137
+ "test/messages/update_test.rb",
104
138
  "test/neighbor_test.rb",
105
- "test/next_hop_test.rb",
106
- "test/nlri_test.rb",
107
- "test/origin_test.rb",
108
- "test/originator_id_test.rb",
109
- "test/path_attribute_test.rb",
110
- "test/prefix_orf_test.rb",
111
- "test/rd_test.rb"
139
+ "test/nlris",
140
+ "test/nlris/inet_test.rb",
141
+ "test/nlris/labeled_test.rb",
142
+ "test/nlris/nlri_test.rb",
143
+ "test/nlris/rd_test.rb",
144
+ "test/optional_parameters",
145
+ "test/optional_parameters/as4_test.rb",
146
+ "test/optional_parameters/capability_test.rb",
147
+ "test/optional_parameters/dynamic_test.rb",
148
+ "test/optional_parameters/graceful_restart_test.rb",
149
+ "test/optional_parameters/mbgp_test.rb",
150
+ "test/optional_parameters/optional_parameter_test.rb",
151
+ "test/optional_parameters/orf_test.rb",
152
+ "test/optional_parameters/route_refresh_test.rb",
153
+ "test/orfs",
154
+ "test/orfs/prefix_orf_test.rb",
155
+ "test/path_attributes",
156
+ "test/path_attributes/aggregator_test.rb",
157
+ "test/path_attributes/as_path_test.rb",
158
+ "test/path_attributes/atomic_aggregate_test.rb",
159
+ "test/path_attributes/attribute_test.rb",
160
+ "test/path_attributes/cluster_list_test.rb",
161
+ "test/path_attributes/communities_test.rb",
162
+ "test/path_attributes/extended_communities_test.rb",
163
+ "test/path_attributes/extended_community_test.rb",
164
+ "test/path_attributes/local_pref_test.rb",
165
+ "test/path_attributes/mp_reach_test.rb",
166
+ "test/path_attributes/mp_unreach_test.rb",
167
+ "test/path_attributes/multi_exit_disc_test.rb",
168
+ "test/path_attributes/next_hop_test.rb",
169
+ "test/path_attributes/origin_test.rb",
170
+ "test/path_attributes/originator_id_test.rb",
171
+ "test/path_attributes/path_attribute_test.rb"
112
172
  ]
113
173
 
114
174
  if s.respond_to? :specification_version then
data/bgp4r.rb CHANGED
@@ -1,27 +1,7 @@
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
1
  require 'bgp/common'
24
- require 'bgp/io'
2
+ require 'bgp/iana'
3
+ require 'bgp/messages/messages'
4
+ require 'bgp/path_attributes/attributes'
5
+ require 'bgp/nlris/nlris'
6
+ require 'bgp/optional_parameters/capabilities'
25
7
  require 'bgp/neighbor'
26
- require 'bgp/message'
27
- require 'bgp/version'
data/examples/routegen CHANGED
@@ -82,4 +82,4 @@ nlris = Nlri.new
82
82
  nlris = Nlri.new
83
83
  end
84
84
 
85
- Thread.stop
85
+ sleep(200)
@@ -5,23 +5,39 @@ neighbor:
5
5
  router id: 1.1.1.1
6
6
  my as: 100
7
7
  holdtime: 180
8
- local address: 199.0.0.5
9
- neighbor address: 199.0.0.6
8
+ local address: 40.0.0.1
9
+ neighbor address: 40.0.0.2
10
10
  capabilities:
11
11
  - four byte as
12
12
  routes:
13
- nlris: 11.0.0.0/28, 1999, 127
14
- next hop: 199.0.0.5
13
+ nlris: 11.0.0.0/28, 199999, 127
14
+ next hop: 40.0.0.1
15
15
  local pref: 100
16
16
  med: 100
17
17
  origin: 0
18
18
  communities: 100:1 200:1 300:1
19
- as path: 200 300 400 500
19
+ as path: 100 90 80
20
20
 
21
21
  ...
22
22
 
23
23
  produces:
24
24
 
25
+
26
+ junos> show route logical-router Paris terse
27
+
28
+ inet.0: 200004 destinations, 200004 routes (200004 active, 0 holddown, 0 hidden)
29
+ Restart Complete
30
+ + = Active Route, - = Last Active, * = Both
31
+
32
+ A Destination P Prf Metric 1 Metric 2 Next hop AS path
33
+ * 11.0.0.16/28 B 170 100 >40.0.0.1 100 90 80 I
34
+ * 11.0.0.32/28 B 170 100 >40.0.0.1 100 90 80 I
35
+ * 11.0.0.48/28 B 170 100 >40.0.0.1 100 90 80 I
36
+ * 11.0.0.64/28 B 170 100 >40.0.0.1 100 90 80 I
37
+ * 11.0.0.80/28 B 170 100 >40.0.0.1 100 90 80 I
38
+ ...
39
+
40
+
25
41
  ios#show ip route summary | inc bgp
26
42
  bgp 100 0 1999 107946 287856
27
43
  ios#
data/examples/simple.rb CHANGED
@@ -17,8 +17,8 @@ Log.level=Logger::DEBUG
17
17
  neighbor = Neighbor.new \
18
18
  :version=> 4,
19
19
  :my_as=> 100,
20
- :remote_addr => '192.168.1.199',
21
- :local_addr => '192.168.1.5',
20
+ :remote_addr => '40.0.0.2',
21
+ :local_addr => '40.0.0.1',
22
22
  :id=> '1.1.1.1', :holdtime=> 180
23
23
 
24
24
  neighbor.capability :as4_byte
@@ -49,10 +49,10 @@ neighbor.start :auto_retry
49
49
  an_update = Update.new(
50
50
  Path_attribute.new(
51
51
  Origin.new(2),
52
- Next_hop.new('192.168.1.5'),
52
+ Next_hop.new('40.0.0.1'),
53
53
  Multi_exit_disc.new(100),
54
54
  Local_pref.new(100),
55
- As_path.new(400,300,200),
55
+ As_path.new(100, 80, 60),
56
56
  Communities.new('1311:1 311:59 2805:64')
57
57
  ),
58
58
  Nlri.new('77.0.0.0/17', '78.0.0.0/18', '79.0.0.0/19')
@@ -49,7 +49,7 @@ class TestBgp < Test::Unit::TestCase
49
49
 
50
50
  def start_peering
51
51
  @n100.capability :as4_byte
52
- @n100.start
52
+ @n100.start
53
53
  end
54
54
 
55
55
  def recv(q, timeout=5)
@@ -2,14 +2,15 @@ require "test/unit"
2
2
  require 'bgp4r'
3
3
  require 'timeout'
4
4
 
5
+
5
6
  Thread.abort_on_exception=true
6
7
 
7
8
  class TestBgp < Test::Unit::TestCase
8
9
 
9
10
  include BGP
10
11
 
11
- Log.create
12
- Log.level=Logger::DEBUG
12
+ # Log.create
13
+ # Log.level=Logger::DEBUG
13
14
 
14
15
  N100 = Class.new(BGP::Neighbor)
15
16
  N300 = Class.new(BGP::Neighbor)
@@ -26,6 +27,13 @@ class TestBgp < Test::Unit::TestCase
26
27
  def setup
27
28
  @n100 = N100.new(:my_as=> 100, :remote_addr => '40.0.0.2', :local_addr => '40.0.0.1', :id=> '13.11.19.59')
28
29
  @n300 = N300.new(:my_as=> 300, :remote_addr => '40.0.1.1', :local_addr => '40.0.1.2', :id=> '13.11.19.57')
30
+ @n100.capability :mbgp, :ipv4, :unicast
31
+ gr = OPT_PARM::CAP::Graceful_restart.new 3, 120
32
+ gr.add :ipv4, :unicast, 1
33
+ gr.add :ipv4, :multicast, 1
34
+ gr.add :ipv6, :unicast, 1
35
+ gr.add :ipv6, :multicast, 3
36
+ @n100.capability gr
29
37
  start_peering
30
38
  end
31
39
 
@@ -39,7 +47,7 @@ class TestBgp < Test::Unit::TestCase
39
47
  assert msg, "Did not receive expected BGP update message."
40
48
  assert msg.path_attribute.has?(255), "The path attribute was expected to contain an attribute type 255"
41
49
  assert_not_nil msg.path_attribute[255]
42
- assert_equal 'AN OPTIONAL TRANSITIVE ATTR WITH TYPE 999', msg.path_attribute[255].value
50
+ assert_equal 'AN OPTIONAL TRANSITIVE ATTR WITH TYPE 255', msg.path_attribute[255].value
43
51
  end
44
52
 
45
53
  def teardown
@@ -58,12 +66,12 @@ class TestBgp < Test::Unit::TestCase
58
66
 
59
67
  def recv(q, timeout=5)
60
68
  begin
61
- Timeout::timeout(timeout) do |t|
62
- msg = q.deq
63
- end
64
- rescue Timeout::Error => e
65
- nil
66
- end
69
+ Timeout::timeout(timeout) do |t|
70
+ msg = q.deq
71
+ end
72
+ rescue Timeout::Error => e
73
+ nil
74
+ end
67
75
  end
68
76
 
69
77
  def update_with_unknown_transitive_attribute
@@ -92,7 +100,7 @@ class TestBgp < Test::Unit::TestCase
92
100
  Multi_exit_disc.new(100),
93
101
  Local_pref.new(100),
94
102
  As_path.new(100),
95
- my_attr.new(ATTR::OPTIONAL_TRANSITIVE, 255, 'AN OPTIONAL TRANSITIVE ATTR WITH TYPE 999'),
103
+ my_attr.new(ATTR::OPTIONAL_TRANSITIVE, 255, 'AN OPTIONAL TRANSITIVE ATTR WITH TYPE 255'),
96
104
  my_attr.new(ATTR::OPTIONAL_TRANSITIVE, 0, 'AN OPTIONAL TRANSITIVE ATTR WITH TYPE 0')
97
105
  ),
98
106
  Nlri.new('77.0.0.0/17', '78.0.0.0/18', '79.0.0.0/19')
@@ -0,0 +1,113 @@
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
+
24
+ require "test/unit"
25
+ require "bgp/messages/capability"
26
+ require 'bgp4r'
27
+
28
+ class TestOptParmCapabilityEncode < Test::Unit::TestCase
29
+ include BGP::OPT_PARM
30
+ def test_encode_dynamic
31
+ assert_equal '0206010400010001', CAP::Mbgp.new(1,1).to_shex
32
+ assert_equal '01000400010001', DYN_CAP::Mbgp.new(1,1).to_shex
33
+ end
34
+ end
35
+
36
+ class TestBgpMessagesCapabilityRevision < Test::Unit::TestCase
37
+ include BGP::OPT_PARM
38
+ def test_capability_revision
39
+ assert_equal '01000400010001', DYN_CAP::Mbgp.new(1,1).to_shex
40
+ assert_equal '0206010400010001', CAP::Mbgp.new(1,1).to_shex
41
+ revision = BGP::Capability::Revision.new :unset, :set, :advertise, 10, DYN_CAP::Mbgp.new(1,1)
42
+ assert_equal '400000000a01000400010001', revision.to_shex
43
+ assert_equal '0x00000010 Advertise Req (0x40) MBGP IPv4, Unicast',revision.to_s
44
+ rev = BGP::Capability::Revision.advertise( 10, DYN_CAP::Mbgp.new(1,1))
45
+ assert_equal '000000000a01000400010001', rev.to_shex
46
+ rev = BGP::Capability::Revision.advertise_ack_request( 10, DYN_CAP::Mbgp.new(1,1))
47
+ assert_equal '400000000a01000400010001', rev.to_shex
48
+ end
49
+ def test_capability_revision_o1
50
+ r = BGP::Capability::Revision.new :unset, :unset, :advertise, 0, 'a cap'
51
+ assert_equal 0, r.instance_eval { @o1 }
52
+ r = BGP::Capability::Revision.new :set, :unset, :advertise, 0, 'a cap'
53
+ assert_equal 0x80, r.instance_eval { @o1 }
54
+ r = BGP::Capability::Revision.new :set, :set, :advertise, 0, 'a cap'
55
+ assert_equal 0xc0, r.instance_eval { @o1 }
56
+ r = BGP::Capability::Revision.new :unset, :set, :advertise, 0, 'a cap'
57
+ assert_equal 0x40, r.instance_eval { @o1 }
58
+ end
59
+ def test_capability_revision_factory
60
+ s = '400000000a01000400010001'
61
+ sbin = [s].pack('H*')
62
+ r = BGP::Capability::Revision.new(sbin)
63
+ assert_equal s, r.to_shex
64
+ assert_equal '', sbin
65
+ end
66
+ end
67
+
68
+ class TestBgpMessagesCapability < Test::Unit::TestCase
69
+ include BGP
70
+ include BGP::OPT_PARM
71
+ def test_capability_1
72
+ cap_msg = BGP::Capability.new
73
+ assert_equal 'ffffffffffffffffffffffffffffffff001306', cap_msg.to_shex
74
+ cap_msg << BGP::Capability::Revision.advertise( 10, DYN_CAP::Mbgp.new(1,1))
75
+ assert_match /^(ff){16}001f06000000000a01000400010001/, cap_msg.to_shex
76
+ cap_msg << BGP::Capability::Revision.advertise( 20, DYN_CAP::Mbgp.new(1,2))
77
+ assert_match /^(ff){16}002b06\s*000000000a01000400010001\s*000000001401000400010002/, cap_msg.to_shex
78
+ end
79
+ def test_capability_2
80
+ cap_msg = BGP::Capability.new(
81
+ BGP::Capability::Revision.advertise( 10, DYN_CAP::Mbgp.new(1,1)),
82
+ BGP::Capability::Revision.advertise( 20, DYN_CAP::Mbgp.new(1,2))
83
+ )
84
+ assert_match /^(ff){16}002b06\s*000000000a01000400010001\s*000000001401000400010002/, cap_msg.to_shex
85
+ end
86
+ def test_capability_3
87
+
88
+ s = 'Capability (6), length: 91
89
+ Seqn Action Ack bits Capability
90
+ 0x00000010 Advertise (0x00) MBGP IPv4, Unicast
91
+ 0x00000020 Advertise Req (0x40) MBGP IPv4, Unicast
92
+ 0x00000020 Advertise Rsp (0x80) MBGP IPv4, Unicast
93
+ 0x00000010 Withdraw (0x01) MBGP IPv4, Unicast
94
+ 0x00000020 Withdraw Req (0x41) MBGP IPv4, Unicast
95
+ 0x00000020 Withdraw Rsp (0x81) MBGP IPv4, Unicast'
96
+
97
+ cap_msg = BGP::Capability.new(
98
+ BGP::Capability::Revision.advertise( 10, DYN_CAP::Mbgp.new(1,1)),
99
+ BGP::Capability::Revision.advertise_ack_request( 20, DYN_CAP::Mbgp.new(1,1)),
100
+ BGP::Capability::Revision.advertise_ack_response( 20, DYN_CAP::Mbgp.new(1,1)),
101
+ BGP::Capability::Revision.remove( 10, DYN_CAP::Mbgp.new(1,1)),
102
+ BGP::Capability::Revision.remove_ack_request( 20, DYN_CAP::Mbgp.new(1,1)),
103
+ BGP::Capability::Revision.remove_ack_response( 20, DYN_CAP::Mbgp.new(1,1))
104
+ )
105
+ assert_equal s, cap_msg.to_s
106
+ end
107
+ def test_factory
108
+ s = 'ffffffffffffffffffffffffffffffff002b06000000000a01000400010001000000001401000400010002'
109
+ msg = BGP::Message.factory([s].pack('H*'))
110
+ assert_equal(BGP::Capability, msg.class)
111
+ assert_equal s, msg.to_shex
112
+ end
113
+ end
@@ -0,0 +1,34 @@
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 Keepalive_Test < Test::Unit::TestCase
27
+ include BGP
28
+ def test_1
29
+ Keepalive.new
30
+ assert_match(/^(ff){16}001304$/, Keepalive.new.to_shex)
31
+ assert_match(/^(ff){16}001304$/, Message.keepalive.unpack('H*')[0])
32
+ assert_equal(Keepalive, Message.factory(Keepalive.new.encode).class)
33
+ end
34
+ end
@@ -0,0 +1,33 @@
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
+ require 'bgp/messages/markers'
26
+ class End_of_rib_markers_Test < Test::Unit::TestCase
27
+ include BGP
28
+ def test_end_of_rib_maker_messages
29
+ assert_match /(ff){16}00170200000000/, Update.end_of_rib_marker.to_shex
30
+ assert_match /(ff){16}001d0200000006800f03000104/, Update.end_of_rib_marker(:afi=>1, :safi=>4).to_shex
31
+ assert_match /(ff){16}001d0200000006800f03000180/, Update.end_of_rib_marker(:afi=>1, :safi=>128).to_shex
32
+ end
33
+ end
@@ -0,0 +1,43 @@
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 Message_Test < Test::Unit::TestCase
27
+ include BGP
28
+ class MyMessage < Message
29
+ attr_reader :data
30
+ def initialize(s=nil)
31
+ @data= parse(s) if s
32
+ end
33
+ def encode
34
+ @msg_type=0xee
35
+ super('abcdefghihjklmopqrstuvwxyz')
36
+ end
37
+ end
38
+ def test_1
39
+ msg1 = MyMessage.new
40
+ msg2 = MyMessage.new(msg1.encode)
41
+ assert_equal('abcdefghihjklmopqrstuvwxyz',msg2.data)
42
+ end
43
+ end