bgp4r 0.0.3

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 (55) hide show
  1. data/COPYING +674 -0
  2. data/LICENSE.txt +53 -0
  3. data/README.rdoc +259 -0
  4. data/bgp/aggregator.rb +104 -0
  5. data/bgp/as_path.rb +223 -0
  6. data/bgp/atomic_aggregate.rb +42 -0
  7. data/bgp/attribute.rb +181 -0
  8. data/bgp/attributes.rb +34 -0
  9. data/bgp/cluster_list.rb +117 -0
  10. data/bgp/common.rb +204 -0
  11. data/bgp/communities.rb +139 -0
  12. data/bgp/extended_communities.rb +107 -0
  13. data/bgp/extended_community.rb +254 -0
  14. data/bgp/iana.rb +269 -0
  15. data/bgp/io.rb +116 -0
  16. data/bgp/label.rb +94 -0
  17. data/bgp/local_pref.rb +75 -0
  18. data/bgp/message.rb +894 -0
  19. data/bgp/mp_reach.rb +208 -0
  20. data/bgp/multi_exit_disc.rb +76 -0
  21. data/bgp/neighbor.rb +291 -0
  22. data/bgp/next_hop.rb +63 -0
  23. data/bgp/nlri.rb +303 -0
  24. data/bgp/orf.rb +88 -0
  25. data/bgp/origin.rb +88 -0
  26. data/bgp/originator_id.rb +73 -0
  27. data/bgp/path_attribute.rb +210 -0
  28. data/bgp/prefix_orf.rb +263 -0
  29. data/bgp/rd.rb +107 -0
  30. data/examples/bgp +65 -0
  31. data/examples/routegen +85 -0
  32. data/examples/routegen.yml +50 -0
  33. data/test/aggregator_test.rb +66 -0
  34. data/test/as_path_test.rb +149 -0
  35. data/test/atomic_aggregate_test.rb +35 -0
  36. data/test/attribute_test.rb +57 -0
  37. data/test/cluster_list_test.rb +39 -0
  38. data/test/common_test.rb +68 -0
  39. data/test/communities_test.rb +75 -0
  40. data/test/extended_communities_test.rb +111 -0
  41. data/test/extended_community_test.rb +93 -0
  42. data/test/label_test.rb +50 -0
  43. data/test/local_pref_test.rb +43 -0
  44. data/test/message_test.rb +294 -0
  45. data/test/mp_reach_test.rb +143 -0
  46. data/test/multi_exit_disc_test.rb +46 -0
  47. data/test/neighbor_test.rb +50 -0
  48. data/test/next_hop_test.rb +37 -0
  49. data/test/nlri_test.rb +189 -0
  50. data/test/origin_test.rb +57 -0
  51. data/test/originator_id_test.rb +38 -0
  52. data/test/path_attribute_test.rb +127 -0
  53. data/test/prefix_orf_test.rb +97 -0
  54. data/test/rd_test.rb +44 -0
  55. metadata +133 -0
@@ -0,0 +1,127 @@
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 'bgp/path_attribute'
25
+
26
+ class Path_attribute_Test < Test::Unit::TestCase # :nodoc:
27
+ include BGP
28
+
29
+ def setup
30
+ pa = Path_attribute.new
31
+ pa << Origin.new(1)
32
+ pa << Next_hop.new('10.0.0.1')
33
+ pa << Multi_exit_disc.new(100)
34
+ pa << Local_pref.new(100)
35
+ pa << As_path.new(1,2,3,4,5)
36
+ pa << Communities.new('1311:1 311:59 2805:64')
37
+ @pa = pa
38
+ end
39
+
40
+ def test_1
41
+ assert_equal(100,@pa[:local_pref].to_i)
42
+ assert_equal([BGP::Origin,
43
+ BGP::Next_hop,
44
+ BGP::Multi_exit_disc,
45
+ BGP::Local_pref,
46
+ BGP::As_path,
47
+ BGP::Communities], @pa.has?)
48
+ assert(@pa.has? Multi_exit_disc)
49
+ assert(@pa.has? As_path)
50
+ end
51
+
52
+ def test_2
53
+ ss = '400101014003040a000001800404000000644005040000006440020c020500010002000300040005c0080c051f00010137003b0af50040'
54
+ assert_equal(ss, @pa.to_shex)
55
+ s = @pa.encode
56
+ assert_equal(Origin, Attr.factory(s).class)
57
+ assert_equal(Next_hop, Attr.factory(s).class)
58
+ assert_equal(Multi_exit_disc, Attr.factory(s).class)
59
+ assert_equal(Local_pref, Attr.factory(s).class)
60
+ assert_equal(As_path, Attr.factory(s).class)
61
+ assert_equal(Communities, Attr.factory(s).class)
62
+ assert_equal('',s)
63
+ end
64
+
65
+ def test_3
66
+ # test []
67
+ assert_equal(Origin,@pa[ATTR::ORIGIN].class)
68
+ assert_equal(Origin,@pa[:origin].class)
69
+ assert_equal(As_path,@pa[ATTR::AS_PATH].class)
70
+ assert_equal(As_path,@pa[:as_path].class)
71
+ assert_equal(Next_hop,@pa[ATTR::NEXT_HOP].class)
72
+ assert_equal(Next_hop,@pa[:next_hop].class)
73
+ assert_equal(Local_pref,@pa[ATTR::LOCAL_PREF].class)
74
+ assert_equal(Local_pref,@pa[:local_pref].class)
75
+ assert_equal(Multi_exit_disc,@pa[ATTR::MULTI_EXIT_DISC].class)
76
+ assert_equal(Multi_exit_disc,@pa[:multi_exit_disc].class)
77
+ assert_equal(Communities,@pa[ATTR::COMMUNITIES].class)
78
+ assert_equal(Communities,@pa[:communities].class)
79
+
80
+ # TODO:
81
+ # when ATOMIC_AGGREGATE, :atomic_aggregate
82
+ # when AGGREGATOR, :aggregator
83
+ # when ORIGINATOR_ID, :originator_id
84
+ # when CLUSTER_LIST, :cluster_list
85
+ # when MP_REACH, :mp_reach
86
+ # when MP_UNREACH, :mp_unreach
87
+ # when EXTENDED_COMMUNITY, :extended_community
88
+ # when AS4_PATH, :as4_path
89
+ # when AS4_AGGREGATOR, :as4_aggregator
90
+
91
+ end
92
+
93
+ def test_4
94
+
95
+ path_attr = Path_attribute.new
96
+ path_attr.insert(
97
+ Origin.new,
98
+ As_path.new,
99
+ Local_pref.new(10),
100
+ Multi_exit_disc.new(20)
101
+ )
102
+
103
+ path_attr.replace(
104
+ Origin.new(2),
105
+ As_path.new(100,200),
106
+ Local_pref.new(11),
107
+ Multi_exit_disc.new(21)
108
+ )
109
+
110
+ assert_equal(4,path_attr.size)
111
+ assert_equal(11, path_attr[:local_pref].to_i)
112
+ assert_equal('100 200', path_attr[:as_path].as_path)
113
+ assert_equal(21, path_attr[ATTR::MULTI_EXIT_DISC].to_i)
114
+
115
+ path_attr.delete Local_pref, Next_hop, Origin
116
+ assert_equal(2, path_attr.size)
117
+ assert( ! path_attr.has?(Local_pref),"Local_pref attr not deleted")
118
+ assert( ! path_attr.has?(Origin),"Origin attr not deleted")
119
+
120
+ path_attr.insert(Origin.new(1), Local_pref.new(100))
121
+ assert_equal(4, path_attr.size)
122
+ assert( path_attr.has?(As_path),"Local_pref attr not deleted")
123
+ assert( path_attr.has?(Origin),"Origin attr not deleted")
124
+
125
+ end
126
+
127
+ end
@@ -0,0 +1,97 @@
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 'bgp/prefix_orf'
24
+ require 'test/unit'
25
+ class Prefix_orf_Test < Test::Unit::TestCase
26
+ include BGP
27
+ def test_1
28
+ assert_equal('000000000a0000080a', Prefix_entry.new(0,0,10,0,0,'10.0.0.0/8').to_shex)
29
+ assert_equal('seq 10 add 10.0.0.0/8 permit', Prefix_entry.new(0,0,10,0,0,'10.0.0.0/8').to_s)
30
+ assert_equal('seq 10 add 10.0.0.0/8 permit', Prefix_entry.add(0,10,0,0,'10.0.0.0/8').to_s)
31
+ assert_equal('seq 10 add 10.0.0.0/8 permit', Prefix_entry.add_and_permit(10,0,0,'10.0.0.0/8').to_s)
32
+ assert_equal('seq 10 add 10.0.0.0/8 permit', Prefix_entry.add_and_permit(10,'10.0.0.0/8').to_s)
33
+ assert_equal('400000000a0000080a', Prefix_entry.new(1,0,10,0,0,'10.0.0.0/8').to_shex)
34
+ assert_equal('seq 10 remove 10.0.0.0/8 permit', Prefix_entry.new(1,0,10,0,0,'10.0.0.0/8').to_s)
35
+ assert_equal('600000000a0000080a', Prefix_entry.new(1,1,10,0,0,'10.0.0.0/8').to_shex)
36
+ assert_equal('seq 10 remove 10.0.0.0/8 deny', Prefix_entry.new(1,1,10,0,0,'10.0.0.0/8').to_s)
37
+ assert_equal('600000000a0000080a', Prefix_entry.new(1,1,10,0,0,'10.0.0.0/8').to_shex)
38
+ assert_equal('seq 10 remove 10.0.0.0/8 deny', Prefix_entry.new(1,1,10,0,0,'10.0.0.0/8').to_s)
39
+ assert_equal('seq 10 remove 10.0.0.0/8 deny', Prefix_entry.remove(1,10,0,0,'10.0.0.0/8').to_s)
40
+ assert_equal('seq 10 remove 10.0.0.0/8 deny', Prefix_entry.remove_and_deny(10,0,0,'10.0.0.0/8').to_s)
41
+ assert_equal('seq 10 remove 10.0.0.0/8 deny', Prefix_entry.remove_and_deny(10,'10.0.0.0/8').to_s)
42
+ assert_equal('000000000a0000080a', Prefix_entry.new( Prefix_entry.new(0,0,10,0,0,'10.0.0.0/8').encode).to_shex)
43
+ assert_equal(Prefix_entry, Prefix_entry.new( Prefix_entry.new(0,0,10,0,0,'10.0.0.0/8').encode).class)
44
+ end
45
+
46
+ def test_2
47
+
48
+ orf = Prefix_orf.new([
49
+ Prefix_entry.add_and_permit(10,'10.0.0.0/8'),
50
+ Prefix_entry.add_and_permit(20,'20.0.0.0/8'),
51
+ Prefix_entry.add_and_permit(30,'30.0.0.0/8'),
52
+ Prefix_entry.add_and_permit(40,'40.0.0.0/8'),
53
+ Prefix_entry.add_and_permit(50,'50.0.0.0/8'),
54
+ ])
55
+
56
+ assert_equal(5,orf.entries.size)
57
+ assert_equal('40002d000000000a0000080a000000001400000814000000001e0000081e000000002800000828000000003200000832', orf.to_shex)
58
+ assert_equal(orf.encode, Prefix_orf.new(orf.encode).encode)
59
+ assert_equal(orf.encode, Prefix_orf.new(orf).encode)
60
+
61
+ orf1 = Prefix_orf.new
62
+ orf1 << Prefix_entry.add_and_permit(10,'10.0.0.0/8')
63
+ orf1 << Prefix_entry.add_and_permit(20,'20.0.0.0/8')
64
+ orf1 << Prefix_entry.add_and_permit(30,'30.0.0.0/8')
65
+ orf1 << Prefix_entry.add_and_permit(40,'40.0.0.0/8')
66
+ orf1 << Prefix_entry.add_and_permit(50,'50.0.0.0/8')
67
+
68
+ assert_equal(orf1.encode, orf.encode)
69
+
70
+ orf2 = Prefix_orf.new([
71
+ Prefix_entry.add_and_deny(1, '35.0.0.0/8'),
72
+ Prefix_entry.add_and_permit(2,'2.2.2.2/32')])
73
+ assert_equal('400015200000000100000823000000000200002002020202', orf2.to_shex)
74
+ orf2.cisco_prefix_entry_type
75
+ assert_equal('820015200000000100000823000000000200002002020202', orf2.to_shex)
76
+
77
+ assert_equal(orf2.encode, Prefix_orf.new(orf2.encode).encode)
78
+
79
+ end
80
+
81
+ def test_3
82
+ orf = Prefix_orf.new([
83
+ Prefix_entry.add_and_permit(10,'10.0.0.0/8'),
84
+ Prefix_entry.add_and_permit(20,'20.0.0.0/8'),
85
+ Prefix_entry.add_and_permit(30,'30.0.0.0/8'),
86
+ Prefix_entry.add_and_permit(40,'40.0.0.0/8'),
87
+ Prefix_entry.add_and_permit(50,'50.0.0.0/8'),
88
+ ])
89
+ assert_match(/BGP::Prefix_orf, 5 entries/, orf.to_s)
90
+ assert_match(/\n seq 10 add 10.0.0.0\/8 permit/, orf.to_s)
91
+ assert_match(/\n seq 20 add 20.0.0.0\/8 permit/, orf.to_s)
92
+ assert_match(/\n seq 30 add 30.0.0.0\/8 permit/, orf.to_s)
93
+ assert_match(/\n seq 40 add 40.0.0.0\/8 permit/, orf.to_s)
94
+ assert_match(/\n seq 50 add 50.0.0.0\/8 permit/, orf.to_s)
95
+ end
96
+
97
+ end
data/test/rd_test.rb ADDED
@@ -0,0 +1,44 @@
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 'bgp/rd'
24
+
25
+ require 'test/unit'
26
+ class Rd_Test < Test::Unit::TestCase
27
+ include BGP
28
+ def test_1
29
+ assert_equal('RD=1:1 (0x01 0x0001)',Rd.new(1,1).to_s)
30
+ assert_equal('0000000100000001',Rd.new(1,1).to_shex)
31
+ assert_equal('RD=1.1.1.1:1 (0x1010101 0x01)',Rd.new('1.1.1.1',1).to_s)
32
+ assert_equal('0001010101010001',Rd.new('1.1.1.1',1).to_shex)
33
+ assert_equal('RD=1:16843009 (0x0001 0x1010101)', Rd.new(1,'1.1.1.1').to_s)
34
+ assert_equal('0002000000010101', Rd.new(1,'1.1.1.1').to_shex)
35
+ assert_equal('RD=1:1 (0x01 0x0001)',Rd.new(1,1,0).to_s)
36
+ assert_equal('RD=1:1 (0x0001 0x01)',Rd.new(1,1,2).to_s)
37
+ end
38
+ def test_2
39
+ assert_equal('0000000100000001', Rd.new(['0000000100000001'].pack('H*')).to_shex)
40
+ assert_equal('0001010101010001', Rd.new(['0001010101010001'].pack('H*')).to_shex)
41
+ assert_equal('0002000000010101', Rd.new(['0002000000010101'].pack('H*')).to_shex)
42
+ end
43
+
44
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bgp4r
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Jean-Michel Esnault
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-29 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: BGP4R is a BGP-4 ruby library to create, send, and receive BGP messages in an object oriented manner
17
+ email: jesnault@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE.txt
24
+ - README.rdoc
25
+ files:
26
+ - COPYING
27
+ - LICENSE.txt
28
+ - README.rdoc
29
+ - bgp/aggregator.rb
30
+ - bgp/as_path.rb
31
+ - bgp/atomic_aggregate.rb
32
+ - bgp/attribute.rb
33
+ - bgp/attributes.rb
34
+ - bgp/cluster_list.rb
35
+ - bgp/common.rb
36
+ - bgp/communities.rb
37
+ - bgp/extended_communities.rb
38
+ - bgp/extended_community.rb
39
+ - bgp/iana.rb
40
+ - bgp/io.rb
41
+ - bgp/label.rb
42
+ - bgp/local_pref.rb
43
+ - bgp/message.rb
44
+ - bgp/mp_reach.rb
45
+ - bgp/multi_exit_disc.rb
46
+ - bgp/neighbor.rb
47
+ - bgp/next_hop.rb
48
+ - bgp/nlri.rb
49
+ - bgp/orf.rb
50
+ - bgp/origin.rb
51
+ - bgp/originator_id.rb
52
+ - bgp/path_attribute.rb
53
+ - bgp/prefix_orf.rb
54
+ - bgp/rd.rb
55
+ - examples/bgp
56
+ - examples/routegen
57
+ - examples/routegen.yml
58
+ - test/aggregator_test.rb
59
+ - test/as_path_test.rb
60
+ - test/atomic_aggregate_test.rb
61
+ - test/attribute_test.rb
62
+ - test/cluster_list_test.rb
63
+ - test/common_test.rb
64
+ - test/communities_test.rb
65
+ - test/extended_communities_test.rb
66
+ - test/extended_community_test.rb
67
+ - test/label_test.rb
68
+ - test/local_pref_test.rb
69
+ - test/message_test.rb
70
+ - test/mp_reach_test.rb
71
+ - test/multi_exit_disc_test.rb
72
+ - test/neighbor_test.rb
73
+ - test/next_hop_test.rb
74
+ - test/nlri_test.rb
75
+ - test/origin_test.rb
76
+ - test/originator_id_test.rb
77
+ - test/path_attribute_test.rb
78
+ - test/prefix_orf_test.rb
79
+ - test/rd_test.rb
80
+ has_rdoc: true
81
+ homepage: http://github.com/jesnault/bgp4r/tree/master
82
+ licenses: []
83
+
84
+ post_install_message:
85
+ rdoc_options:
86
+ - --quiet
87
+ - --title
88
+ - A BGP-4 Ruby Library
89
+ - --line-numbers
90
+ require_paths:
91
+ - .
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 1.8.6
97
+ version:
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: "0"
103
+ version:
104
+ requirements: []
105
+
106
+ rubyforge_project: bgp4r
107
+ rubygems_version: 1.3.4
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: A BGP-4 Ruby Library
111
+ test_files:
112
+ - test/aggregator_test.rb
113
+ - test/as_path_test.rb
114
+ - test/atomic_aggregate_test.rb
115
+ - test/attribute_test.rb
116
+ - test/cluster_list_test.rb
117
+ - test/common_test.rb
118
+ - test/communities_test.rb
119
+ - test/extended_communities_test.rb
120
+ - test/extended_community_test.rb
121
+ - test/label_test.rb
122
+ - test/local_pref_test.rb
123
+ - test/message_test.rb
124
+ - test/mp_reach_test.rb
125
+ - test/multi_exit_disc_test.rb
126
+ - test/neighbor_test.rb
127
+ - test/next_hop_test.rb
128
+ - test/nlri_test.rb
129
+ - test/origin_test.rb
130
+ - test/originator_id_test.rb
131
+ - test/path_attribute_test.rb
132
+ - test/prefix_orf_test.rb
133
+ - test/rd_test.rb