bgp4r 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/README.rdoc +21 -15
  2. data/bgp/common.rb +13 -12
  3. data/bgp/iana.rb +28 -205
  4. data/bgp/io.rb +0 -1
  5. data/bgp/messages/capability.rb +1 -1
  6. data/bgp/messages/message.rb +1 -1
  7. data/bgp/messages/open.rb +1 -1
  8. data/bgp/messages/route_refresh.rb +4 -7
  9. data/bgp/messages/update.rb +9 -6
  10. data/bgp/misc/live_feed.rb +1 -2
  11. data/bgp/neighbor/add_path_cap.rb +14 -13
  12. data/bgp/neighbor/neighbor.rb +30 -18
  13. data/bgp/nlris/inet.rb +9 -11
  14. data/bgp/nlris/label.rb +1 -1
  15. data/bgp/nlris/labeled.rb +31 -4
  16. data/bgp/nlris/nlri.rb +23 -183
  17. data/bgp/nlris/nsap.rb +101 -0
  18. data/bgp/nlris/prefix.rb +162 -24
  19. data/bgp/nlris/rd.rb +1 -1
  20. data/bgp/nlris/vpn.rb +23 -5
  21. data/bgp/optional_parameters/add_path.rb +11 -37
  22. data/bgp/optional_parameters/as4.rb +1 -1
  23. data/bgp/optional_parameters/capability.rb +1 -11
  24. data/bgp/optional_parameters/dynamic.rb +1 -1
  25. data/bgp/optional_parameters/graceful_restart.rb +35 -22
  26. data/bgp/optional_parameters/mbgp.rb +23 -37
  27. data/bgp/optional_parameters/orf.rb +1 -1
  28. data/bgp/optional_parameters/route_refresh.rb +1 -1
  29. data/bgp/orfs/prefix_orf.rb +3 -6
  30. data/bgp/path_attributes/aggregator.rb +1 -1
  31. data/bgp/path_attributes/as_path.rb +1 -1
  32. data/bgp/path_attributes/atomic_aggregate.rb +1 -1
  33. data/bgp/path_attributes/cluster_list.rb +1 -1
  34. data/bgp/path_attributes/communities.rb +1 -1
  35. data/bgp/path_attributes/extended_communities.rb +1 -1
  36. data/bgp/path_attributes/extended_community.rb +55 -26
  37. data/bgp/path_attributes/local_pref.rb +1 -1
  38. data/bgp/path_attributes/mp_reach.rb +178 -76
  39. data/bgp/path_attributes/mp_unreach.rb +11 -67
  40. data/bgp/path_attributes/multi_exit_disc.rb +1 -1
  41. data/bgp/path_attributes/next_hop.rb +1 -1
  42. data/bgp/path_attributes/origin.rb +1 -1
  43. data/bgp/path_attributes/originator_id.rb +1 -1
  44. data/bgp/path_attributes/path_attribute.rb +1 -1
  45. data/bgp4r.gemspec +130 -183
  46. data/examples/routegen +0 -1
  47. data/examples/test.rb +15 -0
  48. data/examples/test2.rb +116 -0
  49. data/examples/unit-testing/{malformed_update.rb → malformed_update_test.rb} +6 -6
  50. data/examples/unit-testing/{no_export.rb → no_export_test.rb} +6 -6
  51. data/examples/unit-testing/{prepend_aspath.rb → prepend_aspath_test.rb} +6 -6
  52. data/test/functional/add_path_test.rb +32 -0
  53. data/test/helpers/server.rb +11 -4
  54. data/test/{common_test.rb → unit/common_test.rb} +7 -10
  55. data/test/{iana_test.rb → unit/iana_test.rb} +7 -6
  56. data/test/{messages → unit/messages}/capability_test.rb +26 -9
  57. data/test/{messages → unit/messages}/route_refresh_test.rb +4 -4
  58. data/test/{messages → unit/messages}/update_test.rb +28 -17
  59. data/test/{neighbor → unit/neighbor}/add_path_cap_test.rb +41 -0
  60. data/test/{neighbor → unit/neighbor}/neighbor_test.rb +31 -13
  61. data/test/unit/nlris/labeled_test.rb +30 -0
  62. data/test/unit/nlris/nlri_test.rb +103 -0
  63. data/test/unit/nlris/nsap_test.rb +80 -0
  64. data/test/unit/nlris/prefix_test.rb +136 -0
  65. data/test/{optional_parameters → unit/optional_parameters}/capability_test.rb +0 -5
  66. data/test/unit/optional_parameters/graceful_restart_test.rb +41 -0
  67. data/test/{optional_parameters → unit/optional_parameters}/mbgp_test.rb +20 -0
  68. data/test/unit/path_attributes/aigp.rb +59 -0
  69. data/test/{path_attributes → unit/path_attributes}/extended_communities_test.rb +4 -0
  70. data/test/{path_attributes → unit/path_attributes}/extended_community_test.rb +9 -0
  71. data/test/unit/path_attributes/mp_reach_test.rb +563 -0
  72. data/test/{path_attributes → unit/path_attributes}/path_attribute_test.rb +1 -1
  73. metadata +128 -136
  74. data/examples/unit-testing/test.rb +0 -82
  75. data/examples/unit-testing/test1.rb +0 -82
  76. data/examples/unit-testing/test2.rb +0 -44
  77. data/test/nlris/ext_nlri_test.rb +0 -32
  78. data/test/nlris/nlri_test.rb +0 -130
  79. data/test/optional_parameters/graceful_restart_test.rb +0 -24
  80. data/test/path_attributes/mp_reach_test.rb +0 -305
  81. /data/examples/unit-testing/{unknown_transitive_attr.rb → unknown_transitive_attr_test.rb} +0 -0
  82. /data/test/{misc → functional}/live_feed_test.rb +0 -0
  83. /data/test/{messages → unit/messages}/keepalive_test.rb +0 -0
  84. /data/test/{messages → unit/messages}/markers_test.rb +0 -0
  85. /data/test/{messages → unit/messages}/message_test.rb +0 -0
  86. /data/test/{messages → unit/messages}/notification_test.rb +0 -0
  87. /data/test/{messages → unit/messages}/open_test.rb +0 -0
  88. /data/test/{nlris → unit/nlris}/inet_test.rb +0 -0
  89. /data/test/{nlris/labeled_test.rb → unit/nlris/label_test.rb} +0 -0
  90. /data/test/{nlris → unit/nlris}/rd_test.rb +0 -0
  91. /data/test/{optional_parameters → unit/optional_parameters}/add_path_test.rb +0 -0
  92. /data/test/{optional_parameters → unit/optional_parameters}/as4_test.rb +0 -0
  93. /data/test/{optional_parameters → unit/optional_parameters}/dynamic_test.rb +0 -0
  94. /data/test/{optional_parameters → unit/optional_parameters}/optional_parameter_test.rb +0 -0
  95. /data/test/{optional_parameters → unit/optional_parameters}/orf_test.rb +0 -0
  96. /data/test/{optional_parameters → unit/optional_parameters}/route_refresh_test.rb +0 -0
  97. /data/test/{orfs → unit/orfs}/prefix_orf_test.rb +0 -0
  98. /data/test/{path_attributes → unit/path_attributes}/aggregator_test.rb +0 -0
  99. /data/test/{path_attributes → unit/path_attributes}/as_path_test.rb +0 -0
  100. /data/test/{path_attributes → unit/path_attributes}/atomic_aggregate_test.rb +0 -0
  101. /data/test/{path_attributes → unit/path_attributes}/attribute_test.rb +0 -0
  102. /data/test/{path_attributes → unit/path_attributes}/cluster_list_test.rb +0 -0
  103. /data/test/{path_attributes → unit/path_attributes}/communities_test.rb +0 -0
  104. /data/test/{path_attributes → unit/path_attributes}/local_pref_test.rb +0 -0
  105. /data/test/{path_attributes → unit/path_attributes}/mp_unreach_test.rb +0 -0
  106. /data/test/{path_attributes → unit/path_attributes}/multi_exit_disc_test.rb +0 -0
  107. /data/test/{path_attributes → unit/path_attributes}/next_hop_test.rb +0 -0
  108. /data/test/{path_attributes → unit/path_attributes}/origin_test.rb +0 -0
  109. /data/test/{path_attributes → unit/path_attributes}/originator_id_test.rb +0 -0
@@ -24,18 +24,18 @@ require "bgp/common"
24
24
 
25
25
  require 'test/unit'
26
26
  class Common_Test < Test::Unit::TestCase
27
- def test_ipaddr_1
27
+ def test_array_pack_returns_a_packed_string
28
28
  s = [1,2,3].pack('C*')
29
29
  assert(s.is_packed?)
30
30
  assert( ! "1234".is_packed?)
31
31
  end
32
- def test_ipaddr_2
32
+ def test_ipaddr_create
33
33
  ip = IPAddr.new('10.0.0.1')
34
34
  assert_equal('0a000001', ip.to_shex)
35
35
  assert_equal('0a000001', IPAddr.create(ip.encode).to_shex)
36
36
  assert_equal('0a000001', IPAddr.create(ip.to_i).to_shex)
37
37
  end
38
- def test_ipaddr_3
38
+ def test_ipaddr_netmask
39
39
  assert_equal(32, IPAddr.new('10.0.0.1').mlen)
40
40
  assert_equal(16, IPAddr.new('10.0.0.1/16').mlen)
41
41
  assert_equal(7, IPAddr.new('10.0.0.0/7').mlen)
@@ -54,18 +54,18 @@ class Common_Test < Test::Unit::TestCase
54
54
  assert_equal('ffff:ffff:ffff:0000:0000:0000:0000:0000',IPAddr.new('2011:1:18::1/48').netmask)
55
55
  assert_equal('ffff:ffff:0000:0000:0000:0000:0000:0000',IPAddr.new('2011:1:18::1/32').netmask)
56
56
  end
57
- def test_ipaddr_4
57
+ def test_ipaddr_arithmetic
58
58
  ip1 = IPAddr.new('10.0.0.1/28')
59
59
  ip2 = IPAddr.new('10.0.0.1/24')
60
60
  ip3 = IPAddr.new('10.0.0.1/12')
61
61
  assert_equal('10.0.0.16/28', ip1 ^ 1)
62
62
  assert_equal('10.0.0.32/28', ip1 ^ 2)
63
- assert_equal('10.0.1.0/24', ip2 ^ 1)
64
- assert_equal('10.0.2.0/24', ip2 ^ 2)
63
+ assert_equal('10.0.1.0/24', ip2 ^ 1)
64
+ assert_equal('10.0.2.0/24', ip2 ^ 2)
65
65
  assert_equal('10.16.0.0/12', ip3 ^ 1)
66
66
  assert_equal('10.32.0.0/12', ip3 ^ 2)
67
67
  end
68
- def test_string_1
68
+ def test_string_pack
69
69
  sbin = ['00'].pack('H*')
70
70
  assert_equal '0x0000: 00', sbin.hexlify.join
71
71
  sbin = ['0001'].pack('H*')
@@ -79,7 +79,4 @@ class Common_Test < Test::Unit::TestCase
79
79
  assert_equal '0x0001: 1011 1213 1415 1617 1819 1a1b 1c1d 1e1f', sbin.hexlify[2]
80
80
  assert_equal '0x0002: 20', sbin.hexlify[3]
81
81
  end
82
- def test_nlri
83
- assert_equal('14000000', IPAddr.new_nlri4(['101400'].pack('H*')).to_shex)
84
- end
85
82
  end
@@ -25,16 +25,17 @@ require "bgp/iana"
25
25
  require 'test/unit'
26
26
  class TestBgpIana < Test::Unit::TestCase
27
27
  def test_afi?
28
- assert_equal 1, IANA.afi?(:ip)
29
- assert_equal 2, IANA.afi?(:ip6)
28
+ assert_equal 1, IANA.afi?(:ipv4)
29
+ assert_equal 2, IANA.afi?(:ipv6)
30
30
  assert_equal 5, IANA.afi?(:bbn)
31
31
  assert_equal 12, IANA.afi?(:appletalk)
32
- assert_equal 'IP', IANA.afi?(1)
33
- assert_equal 'IP6',IANA.afi?(2)
32
+ assert_equal 'IPv4', IANA.afi?(1)
33
+ assert_equal 'IPv6', IANA.afi?(2)
34
+ assert_equal 'NSAP', IANA.afi?(3)
34
35
  end
35
36
  def test_safi?
36
- assert_equal 1, IANA.safi?(:unicast_nlri)
37
- assert_equal 2, IANA.safi?(:multicast_nlri)
37
+ assert_equal 1, IANA.safi?(:unicast)
38
+ assert_equal 2, IANA.safi?(:multicast)
38
39
  assert_equal 4, IANA.safi?(:label_nlri)
39
40
  assert_equal 5, IANA.safi?(:mcast_vpn)
40
41
  assert_equal 64, IANA.safi?(:tunnel)
@@ -68,7 +68,7 @@ end
68
68
  class TestBgpMessagesCapability < Test::Unit::TestCase
69
69
  include BGP
70
70
  include BGP::OPT_PARM
71
- def test_capability_1
71
+ def test_adding_dyn_cap_to_message
72
72
  cap_msg = BGP::Capability.new
73
73
  assert_equal('ffffffffffffffffffffffffffffffff001306', cap_msg.to_shex)
74
74
  cap_msg << BGP::Capability::Revision.advertise( 10, DYN_CAP::Mbgp.new(1,1))
@@ -76,14 +76,21 @@ class TestBgpMessagesCapability < Test::Unit::TestCase
76
76
  cap_msg << BGP::Capability::Revision.advertise( 20, DYN_CAP::Mbgp.new(1,2))
77
77
  assert_match(/^(ff){16}002b06\s*000000000a01000400010001\s*000000001401000400010002/, cap_msg.to_shex)
78
78
  end
79
- def test_capability_2
79
+ def test_new_cap_message_with_dyn_caps
80
80
  cap_msg = BGP::Capability.new(
81
81
  BGP::Capability::Revision.advertise( 10, DYN_CAP::Mbgp.new(1,1)),
82
82
  BGP::Capability::Revision.advertise( 20, DYN_CAP::Mbgp.new(1,2))
83
83
  )
84
84
  assert_match(/^(ff){16}002b06\s*000000000a01000400010001\s*000000001401000400010002/, cap_msg.to_shex)
85
85
  end
86
- def test_capability_3
86
+ def test_new_cap_message_with_dyn_caps_verbose
87
+ cap_msg = BGP::Capability.new(
88
+ BGP::Capability::Revision.advertise( 10, DYN_CAP::Mbgp.ipv4_unicast),
89
+ BGP::Capability::Revision.advertise( 20, DYN_CAP::Mbgp.ipv4_multicast)
90
+ )
91
+ assert_match(/^(ff){16}002b06\s*000000000a01000400010001\s*000000001401000400010002/, cap_msg.to_shex)
92
+ end
93
+ def test_capability_advertise_remove_dyn_caps
87
94
 
88
95
  s = 'Capability (6), length: 91
89
96
  Seqn Action Ack bits Capability
@@ -95,14 +102,24 @@ class TestBgpMessagesCapability < Test::Unit::TestCase
95
102
  0x00000020 Withdraw Rsp (0x81) MBGP IPv4, Unicast'
96
103
 
97
104
  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))
105
+ BGP::Capability::Revision.advertise( 10, DYN_CAP::Mbgp.new(1,1)),
106
+ BGP::Capability::Revision.advertise_ack_request( 20, DYN_CAP::Mbgp.new(1,1)),
107
+ BGP::Capability::Revision.advertise_ack_response( 20, DYN_CAP::Mbgp.new(1,1)),
108
+ BGP::Capability::Revision.remove( 10, DYN_CAP::Mbgp.new(1,1)),
109
+ BGP::Capability::Revision.remove_ack_request( 20, DYN_CAP::Mbgp.new(1,1)),
110
+ BGP::Capability::Revision.remove_ack_response( 20, DYN_CAP::Mbgp.new(1,1))
104
111
  )
105
112
  assert_equal s, cap_msg.to_s
113
+
114
+ cap_msg2 = BGP::Capability.new(
115
+ BGP::Capability::Revision.advertise( 10, DYN_CAP::Mbgp.ipv4_unicast),
116
+ BGP::Capability::Revision.advertise_ack_request( 20, DYN_CAP::Mbgp.ipv4_unicast),
117
+ BGP::Capability::Revision.advertise_ack_response( 20, DYN_CAP::Mbgp.ipv4_unicast),
118
+ BGP::Capability::Revision.remove( 10, DYN_CAP::Mbgp.ipv4_unicast),
119
+ BGP::Capability::Revision.remove_ack_request( 20, DYN_CAP::Mbgp.ipv4_unicast),
120
+ BGP::Capability::Revision.remove_ack_response( 20, DYN_CAP::Mbgp.ipv4_unicast)
121
+ )
122
+ assert_equal(cap_msg.to_shex, cap_msg2.to_shex)
106
123
  end
107
124
  def test_factory
108
125
  s = 'ffffffffffffffffffffffffffffffff002b06000000000a01000400010001000000001401000400010002'
@@ -28,7 +28,7 @@ class Route_refresh_Test < Test::Unit::TestCase
28
28
  def test_1
29
29
  s = "ffffffffffffffffffffffffffffffff00170500010001"
30
30
  sbin = [s].pack('H*')
31
- assert_equal(Route_refresh, Message.factory(sbin).class)
31
+ assert_equal(BGP::Route_refresh, Message.factory(sbin).class)
32
32
  rr = Message.factory(sbin)
33
33
  assert_equal(s, rr.to_shex)
34
34
  rr.afi, rr.safi=2,2
@@ -37,9 +37,9 @@ class Route_refresh_Test < Test::Unit::TestCase
37
37
  assert_equal('ffffffffffffffffffffffffffffffff00170500020002', rr.to_shex)
38
38
  assert_raise(ArgumentError) { rr.safi=0x100 }
39
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)
40
+ assert_equal(s, BGP::Route_refresh.new(1,1).to_shex)
41
+ assert_equal(s, BGP::Route_refresh.new(:afi=>1, :safi=>1).to_shex)
42
+ assert_equal({:afi=>1, :safi=>1}, BGP::Route_refresh.new(:afi=>1, :safi=>1).to_hash)
43
43
  assert_equal(s, Message.route_refresh(1,1).unpack('H*')[0])
44
44
  end
45
45
  end
@@ -25,13 +25,13 @@ require 'bgp4r'
25
25
 
26
26
  class Update_Test < Test::Unit::TestCase
27
27
  include BGP
28
- def test_1
28
+ def test_factory_to_create_an_update_message
29
29
  s = "ffffffffffffffffffffffffffffffff006b0200000054400101024002009004040000000040050400000064c0100800020c8f04127ee8800a0800000001000000048009045134134d800e1f0001800c00000000000000005134134d00680114d100000c8f041291480a39"
30
30
  sbin = [s].pack('H*')
31
31
  u = Update.new(sbin)
32
32
  assert_equal(Update, Message.factory(sbin).class)
33
33
  end
34
- def test_2
34
+ def test_factory_to_create_an_update_message_with_multiple_nlris
35
35
  s = "
36
36
  ffff ffff ffff ffff
37
37
  ffff ffff ffff ffff 0070 0200 0000 5940
@@ -53,14 +53,25 @@ class Update_Test < Test::Unit::TestCase
53
53
  assert_equal(2,m.nlri.size)
54
54
  assert_equal("10.10.10.10/32\n32.32.32.32/32", m.nlri.to_s)
55
55
  end
56
- def test_3
56
+ def test_factory_to_create_a_widthdrawn_message
57
57
  s = 'ffffffffffffffffffffffffffffffff0050020000002f40010101400304c0a80105800404000000644005040000006440020402010064c0080c051f00010137003b0af50040200a0a0a0a2020202020'
58
58
  m = Message.factory([s].pack('H*'))
59
59
  w = Update.withdrawn(m)
60
60
  assert_equal(Update,w.class)
61
61
  assert_equal('200a0a0a0a2020202020', w.withdrawn.to_shex)
62
62
  end
63
- def test_4
63
+
64
+ def __test_experiment
65
+ upd = Update.new do
66
+ path_attribute << Local_pref.new
67
+ path_attribute << Origin.new
68
+ path_attribute << Next_hop.new('10.1.1.1')
69
+ 10.times { |i| nlri << "10.0.#{i}.0/24"}
70
+ end
71
+ puts upd
72
+ end
73
+
74
+ def test_verify_as4_byte_encoding
64
75
  an_update = Update.new(
65
76
  Path_attribute.new(
66
77
  Origin.new(1),
@@ -75,7 +86,7 @@ class Update_Test < Test::Unit::TestCase
75
86
 
76
87
  assert_equal(3*2, an_update.encode4.size - an_update.encode.size)
77
88
  end
78
- def test_5
89
+ def test_verify_access_to_update_info
79
90
  an_update = Update.new( Path_attribute.new( Origin.new(1),
80
91
  Next_hop.new('10.0.0.1'),
81
92
  Multi_exit_disc.new(100)
@@ -93,7 +104,7 @@ class Update_Test < Test::Unit::TestCase
93
104
  assert_equal 4, an_update.nlri.size
94
105
  end
95
106
 
96
- def test_6
107
+ def test_factory_to_build_update_with_session_info
97
108
  s = 'ffffffffffffffffffffffffffffffff004a02000000274001010040020a0202000000c80000006440030428000101c0080c0137003b051f00010af50040114d0000124e0000134f0000'
98
109
  m = Message.factory([s].pack('H*'), Update::Info.new(true))
99
110
  assert_not_nil m
@@ -101,7 +112,7 @@ class Update_Test < Test::Unit::TestCase
101
112
  assert_equal(s, m.to_shex(Update::Info.new(true)))
102
113
  end
103
114
 
104
- def test_7
115
+ def _test_7
105
116
  # build an update from a yaml description
106
117
  # advertised 172.18.179.192/27
107
118
  # origin igp
@@ -126,7 +137,7 @@ class Update_Test < Test::Unit::TestCase
126
137
  "
127
138
  end
128
139
 
129
- def test_8
140
+ def test_verify_one_can_modify_update_info
130
141
  o = Update::Info.new(true)
131
142
  def o.recv_inet_unicast? ; false ; end
132
143
  s = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0072020000001F4001010040020A0204212C051319351AFE400304557200D9C00804212C045C175D76D6175D76DE1659299C175929981659235C16592D6417592D6417592D6617592D6217C3D228185D73241859284417C3FE84165C727015592190'
@@ -140,7 +151,7 @@ class Update_Test < Test::Unit::TestCase
140
151
  assert_equal '100 556533011 422910718', pa[As_path].as_path
141
152
  end
142
153
 
143
- def test_9
154
+ def test_crate_a_withdrawn_update_message
144
155
  # FFFFFFFFFF
145
156
  # 0023 02 000C 16D40374 1755C688 16D40830 0000
146
157
  s = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF002302000C16D403741755C68816D408300000'
@@ -149,7 +160,7 @@ class Update_Test < Test::Unit::TestCase
149
160
  assert_equal 3,m.withdrawn.nlris.size
150
161
  end
151
162
 
152
- def test_10
163
+ def test_factory_to_create_an_update_message_witth_ext_inet_unicast_nlris
153
164
  o = Update::Info.new(true)
154
165
  def o.recv_inet_unicast? ; true ; end
155
166
  def o.send_inet_unicast? ; true ; end
@@ -157,7 +168,7 @@ class Update_Test < Test::Unit::TestCase
157
168
  Path_attribute.new(
158
169
  As_path.new(100)
159
170
  ),
160
- Ext_Nlri.new(100, Nlri.new('77.0.0.0/17'))
171
+ Nlri.new([100,'77.0.0.0/17'])
161
172
  )
162
173
  assert_equal('ffffffffffffffffffffffffffffffff0028020000000940020602010000006400000064114d0000', upd1.to_shex(o))
163
174
  # Need to tell the factory we are dealing with a ext nlri.
@@ -183,7 +194,7 @@ class Update_Test < Test::Unit::TestCase
183
194
  )
184
195
  assert_match(/ff{16}....020000/, upd1.to_shex)
185
196
  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)
197
+ assert_match(/ID=100, IPv4/,upd1.path_attribute[:mp_reach].to_s)
187
198
 
188
199
  # received as2byte encode aspath attr
189
200
  upd2 = Update.factory upd1.encode, :as4byte=> false, :path_id=>true
@@ -205,18 +216,18 @@ class Update_Test < Test::Unit::TestCase
205
216
  Update.factory(sbin,o)
206
217
  end
207
218
 
208
- def test_path_id_inet_unicast
219
+ def test_factory_to_build_and_update_for_inet_unicast_with_path_id
209
220
  upd = ext_update "
210
221
  ffff ffff ffff ffff ffff ffff ffff ffff
211
222
  003c 0200 0000 1c40 0101 0040 0200 4003
212
223
  040a 0000 0180 0404 0000 0066 4005 0400
213
224
  0000 6500 0000 6419 1400 0000"
214
225
  assert_equal(BGP::Update, upd.class)
215
- assert_equal 'ID: 100, 20.0.0.0/25', upd.nlri.nlris[0].to_s
226
+ assert_equal 'ID=100, 20.0.0.0/25', upd.nlri.nlris[0].to_s
216
227
 
217
228
  end
218
229
 
219
- def test_path_id_inet_mpls_vpn_unicast
230
+ def test_factory_to_build_and_update_for_inet_mpls_vpn_unicast_with_path_id
220
231
  s = "
221
232
  ffff ffff ffff ffff ffff ffff ffff ffff
222
233
  005f 0200 0000 4840 0101 0140 0200 8004
@@ -246,7 +257,7 @@ class Update_Test < Test::Unit::TestCase
246
257
 
247
258
  end
248
259
 
249
- def test_path_id_inet_mpls_vpn_unicast_withdrawn
260
+ def test_factory_to_build_a_withdrawn_update_for_inet_mpls_vpn_unicast_with_path_id
250
261
  upd = ext_update "
251
262
  ffff ffff ffff ffff ffff ffff ffff ffff
252
263
  0031 0200 0000 1a90 0f00 1600 0180 0000
@@ -256,7 +267,7 @@ class Update_Test < Test::Unit::TestCase
256
267
  assert upd.path_attribute.has_a_mp_unreach_attr?
257
268
  mp_unreach = upd.path_attribute[:mp_unreach]
258
269
  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
270
+ assert_equal 'Label Stack=524288 (bottom) RD=1:1, ID=1, IPv4=10.1.1.0/24', mp_unreach.nlris[0].to_s
260
271
  end
261
272
 
262
273
  end
@@ -26,6 +26,16 @@ class TestBgpNeighborAddPathCap < Test::Unit::TestCase
26
26
  assert session_cap.path_id_send?(1,1)
27
27
  assert ! session_cap.send_inet_multicast?
28
28
  end
29
+ def test_add_path_recv_inet_unicast
30
+ peer = Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::Add_path.new( :send, 1, 1))
31
+ speaker = Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::Add_path.new( :send_and_receive, 1, 1))
32
+ session_cap = Neighbor::Capabilities.new(speaker, peer)
33
+ assert session_cap.recv_inet_unicast?
34
+ assert session_cap.path_id_recv?(1,1)
35
+ assert ! session_cap.send_inet_unicast?
36
+ assert ! session_cap.path_id_send?(1,1)
37
+ assert ! session_cap.send_inet_multicast?
38
+ end
29
39
  def test_add_path_send_and_recv_inet6_multicast
30
40
  peer = Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::Add_path.new( :send_and_receive, 2, 2))
31
41
  speaker = Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::Add_path.new( :send_and_receive, 2, 2))
@@ -51,4 +61,35 @@ class TestBgpNeighborAddPathCap < Test::Unit::TestCase
51
61
  assert ! session_cap.send_inet6_multicast?
52
62
  assert ! session_cap.recv_inet6_multicast?
53
63
  end
64
+
65
+ def test_add_path_send_inet_unicast
66
+ peer = Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::Add_path.new( :recv, 1, 1))
67
+ speaker = Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::Add_path.new( :send, 1, 1))
68
+ session_cap = Neighbor::Capabilities.new(speaker, peer)
69
+ assert session_cap.send_inet_unicast?
70
+ assert session_cap.path_id_send?(1,1)
71
+ assert ! session_cap.path_id_recv?(1,1)
72
+ assert ! session_cap.send_inet_multicast?
73
+ end
74
+ def test_add_path_send_inet_unicast_2
75
+ peer = Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::Add_path.new( :send_and_receive, 1, 1))
76
+ speaker = Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::Add_path.new( :send, 1, 1))
77
+ session_cap = Neighbor::Capabilities.new(speaker, peer)
78
+ assert session_cap.send_inet_unicast?
79
+ assert ! session_cap.path_id_recv?(1,1)
80
+ assert session_cap.path_id_send?(1,1)
81
+ assert ! session_cap.send_inet_multicast?
82
+ end
83
+ def test_add_path_recv_inet6_multicast
84
+ peer = Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::Add_path.new( :send, 2, 2))
85
+ speaker = Open.new(4,100, 200, '10.0.0.1', OPT_PARM::CAP::Add_path.new( :recv, 2, 2))
86
+ session_cap = Neighbor::Capabilities.new(speaker, peer)
87
+ assert ! session_cap.path_id_recv?(2,1)
88
+ assert session_cap.path_id_recv?(2,2)
89
+ assert ! session_cap.path_id_send?(2,2)
90
+ assert session_cap.recv_inet6_multicast?
91
+ assert ! session_cap.recv_inet_multicast?
92
+ assert ! session_cap.send_inet_unicast?
93
+ end
94
+
54
95
  end
@@ -23,14 +23,18 @@
23
23
  require "test/unit"
24
24
  require 'bgp4r'
25
25
  require 'test/helpers/server'
26
+ include BGP
27
+ include BGP
28
+ include BGP::OPT_PARM::CAP
29
+ include BGP::TestHelpers
30
+
26
31
 
27
32
  class TestBgpNeighbor < Test::Unit::TestCase
28
33
  include BGP
29
34
  include BGP::OPT_PARM::CAP
30
35
  include BGP::TestHelpers
31
- def setup
32
- end
33
36
  def teardown
37
+ stop_server
34
38
  end
35
39
  def test_open_msg
36
40
  neighbor = Neighbor.new \
@@ -50,7 +54,6 @@ class TestBgpNeighbor < Test::Unit::TestCase
50
54
  assert_equal(4,open_msg.version)
51
55
  assert_equal(20,open_msg.holdtime)
52
56
  assert_equal(100,open_msg.local_as)
53
- # puts neighbor
54
57
  end
55
58
  def test_neighbor_state_methods
56
59
  neighbor = Neighbor.new \
@@ -71,7 +74,6 @@ class TestBgpNeighbor < Test::Unit::TestCase
71
74
  @c.start :port=> 3456
72
75
  assert_equal('Established', @c.state)
73
76
  assert_equal('Established', @s.state)
74
- stop_server
75
77
  end
76
78
  def test_start_no_blocking
77
79
  start_server(3333)
@@ -79,7 +81,6 @@ class TestBgpNeighbor < Test::Unit::TestCase
79
81
  @c.start :port=> 3333, :no_blocking=>true
80
82
  assert_equal('OpenSent', @c.state)
81
83
  assert_match(/(Active|OpenSent)/, @s.state)
82
- stop_server
83
84
  end
84
85
  def test_send_and_receive_path_id_afi_1_safi_1
85
86
  server_add_path_cap = BGP::OPT_PARM::CAP::Add_path.new
@@ -96,7 +97,6 @@ class TestBgpNeighbor < Test::Unit::TestCase
96
97
  "Should have the capability to recv inet unicast reachability path info."
97
98
  assert @c.session_info.send_inet_unicast?,
98
99
  "Should have the capability to send inet unicast reachability path info."
99
- stop_server
100
100
  end
101
101
  def test_send_path_id_afi_1_safi_1
102
102
  server_add_path_cap = BGP::OPT_PARM::CAP::Add_path.new
@@ -115,7 +115,6 @@ class TestBgpNeighbor < Test::Unit::TestCase
115
115
  "Should have the capability to recv inet unicast reachability path info."
116
116
  assert ! @c.session_info.send_inet_unicast?,
117
117
  "Should NOT have the capability to send inet unicast reachability path info."
118
- stop_server
119
118
  end
120
119
  def test_recv_path_id_afi_1_safi_1
121
120
  server_add_path_cap = BGP::OPT_PARM::CAP::Add_path.new
@@ -134,9 +133,7 @@ class TestBgpNeighbor < Test::Unit::TestCase
134
133
  "Should NOT have the capability to recv inet unicast reachability path info."
135
134
  assert @c.session_info.send_inet_unicast?,
136
135
  "Should have the capability to send inet unicast reachability path info."
137
- stop_server
138
136
  end
139
-
140
137
  def test_nor_recv_nor_send_path_id_afi_1_safi_1
141
138
  server_add_path_cap = BGP::OPT_PARM::CAP::Add_path.new
142
139
  server_add_path_cap.add(:recv, 1, 1)
@@ -154,8 +151,29 @@ class TestBgpNeighbor < Test::Unit::TestCase
154
151
  "Should NOT have the capability to recv inet unicast reachability path info."
155
152
  assert ! @c.session_info.send_inet_unicast?,
156
153
  "Should have the capability to send inet unicast reachability path info."
157
- stop_server
158
154
  end
159
-
160
-
161
- end
155
+ def test_add_capabilities_using_sym
156
+ neighbor = Neighbor.new(4,100,180,'0.0.0.2')
157
+ neighbor.capability :as4_byte
158
+ neighbor.capability :route_refresh
159
+ neighbor.capability :route_refresh, 128
160
+ neighbor.capability :mbgp, :ipv4, :unicast
161
+ neighbor.capability :mbgp, :ipv4, :multicast
162
+ assert_equal('ffffffffffffffffffffffffffffffff003d0104006400b400000002200206410400000064020202000202800002060104000100010206010400010002', neighbor.open.to_shex)
163
+ assert_equal(5, neighbor.instance_eval { @opt_parms}.size)
164
+ end
165
+ def test_add_capabilities_using_method_missing
166
+ n = Neighbor.new(4,100,180,'0.0.0.2')
167
+ n.capability_mbgp_ipv4_unicast
168
+ n.capability_mbgp_ipv4_multicast
169
+ n.capability_mbgp_ipv4_mpls_vpn_unicast
170
+ n.capability_mbgp_ipv6_mpls_vpn_multicast
171
+ n.capability_mbgp_nsap_mpls_vpn_unicast
172
+ n.capability_mbgp_nsap_unicast
173
+ n.capability_route_refresh
174
+ n.capability_route_refresh 128
175
+ n.capability_four_byte_as
176
+ assert_equal(9, n.instance_eval { @opt_parms }.size )
177
+ assert_equal('ffffffffffffffffffffffffffffffff005d0104006400b4000000024002060104000100010206010400010002020601040001008002060104000200810206010400030080020601040003000102020200020280000206410400000064', n.open.to_shex)
178
+ end
179
+ end
@@ -0,0 +1,30 @@
1
+ require "test/unit"
2
+
3
+ require "bgp/nlris/labeled"
4
+ require 'bgp/nlris/prefix'
5
+
6
+ class TestBgpNlrisLabeled < Test::Unit::TestCase
7
+ include BGP
8
+ def test_new
9
+ assert_equal('Label Stack=100 (bottom) 10.0.0.0/8', Labeled.new(Prefix.new('10.0.0.1/8'), 100).to_s)
10
+ assert_equal('Label Stack=100,101 (bottom) 10.0.0.0/8', Labeled.new(Prefix.new('10.0.0.1/8'), 100,101).to_s)
11
+ assert_equal('Label Stack=100,101,102 (bottom) 10.0.0.0/8', Labeled.new(Prefix.new('10.0.0.1/8'), 100,101,102).to_s)
12
+ assert_equal('200006410a', Labeled.new(Prefix.new('10.0.0.1/8'), 100).to_shex)
13
+ assert_equal('380006400006510a', Labeled.new(Prefix.new('10.0.0.1/8'), 100,101).to_shex)
14
+ assert_equal('500006400006500006610a', Labeled.new(Prefix.new('10.0.0.1/8'), 100,101,102).to_shex)
15
+ #FIXME: add labeled and labeled vpn tests
16
+ end
17
+ def test_new_ntop
18
+ assert_equal('Label Stack=100 (bottom) 10.0.0.0/8', Labeled.new_ntop(['200006410a'].pack('H*'), 1, 1).to_s)
19
+ assert_equal('Label Stack=100,101 (bottom) 10.0.0.0/8', Labeled.new_ntop(['380006400006510a'].pack('H*'), 1, 1).to_s)
20
+ assert_equal('Label Stack=100,101,102 (bottom) 10.0.0.0/8', Labeled.new_ntop(['500006400006500006610a'].pack('H*'), 1, 1).to_s)
21
+ assert_equal('200006410a', Labeled.new_ntop(['200006410a'].pack('H*'), 1, 1).to_shex)
22
+ assert_equal('380006400006510a', Labeled.new_ntop(['380006400006510a'].pack('H*'), 1, 1).to_shex)
23
+ assert_equal('500006400006500006610a', Labeled.new_ntop(['500006400006500006610a'].pack('H*'), 1, 1).to_shex)
24
+ #FIXME: add labeled and labeled vpn tests
25
+ end
26
+ def test_new_ntop_path_id
27
+ #FIXME: add labeled and labeled vpn tests
28
+ end
29
+
30
+ end
@@ -0,0 +1,103 @@
1
+ #--
2
+ # Copyright 2008, 2009, 2011 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/nlris/nlris'
25
+
26
+ class Nlri_Test < Test::Unit::TestCase
27
+ include BGP
28
+
29
+ def test_nlri
30
+ nlri1 = Nlri.new
31
+ nlri1 << '20.0.0.0/15'
32
+ nlri1 << '20.0.0.0/17'
33
+ nlri1 << '20.0.0.0/24'
34
+ s = '0f140010140011140000'
35
+ nlri2 = Nlri.new_ntop([s].pack('H*'))
36
+ assert_equal('0f140010140011140000', nlri2.to_shex)
37
+ assert_equal('000a0f140010140011140000', nlri2.to_shex(true))
38
+ assert_equal(3,nlri2.nlris.size)
39
+ end
40
+ def test_nlris
41
+ nlri = Nlri.new
42
+ nlri << [101, '101.0.0.0/8']
43
+ nlri << [102, '102.0.0.0/8']
44
+ nlri << [103, '103.0.0.0/8']
45
+ nlri << { :path_id=> 104, :nlri=> '104.0.0.0/8' }
46
+ nlri << { :path_id=> 105, :nlri=> '105.0.0.0/8' }
47
+ assert_match(/ID=102, 102.0/, nlri.to_s)
48
+ assert_match(/ID=104, 104.0/, nlri.to_s)
49
+ assert_match(/ID=105, 105.0/, nlri.to_s)
50
+
51
+ nlri2 = Nlri.new(
52
+ [101, '101.0.0.0/8'],
53
+ [102, '102.0.0.0/8'],
54
+ [103, '103.0.0.0/8'],
55
+ [104, '104.0.0.0/8'],
56
+ [105, '105.0.0.0/8']
57
+ )
58
+ assert_equal(nlri.to_shex, nlri2.to_shex)
59
+ end
60
+ def test_withdrawns_ext
61
+ nlri = Withdrawn.new
62
+ nlri << [101, '101.0.0.0/8']
63
+ nlri << [102, '102.0.0.0/8']
64
+ nlri << [103, '103.0.0.0/8']
65
+ nlri << { :path_id=> 104, :nlri=> '104.0.0.0/8' }
66
+ nlri << { :path_id=> 105, :nlri=> '105.0.0.0/8' }
67
+ assert_match(/ID=102, 102.0/, nlri.to_s)
68
+ assert_match(/ID=104, 104.0/, nlri.to_s)
69
+ assert_match(/ID=105, 105.0/, nlri.to_s)
70
+ end
71
+ def test_withdrawns
72
+ nlri = Withdrawn.new
73
+ nlri << '101.0.0.0/8'
74
+ nlri << '102.0.0.0/8'
75
+ nlri << '103.0.0.0/8'
76
+ assert_equal('086508660867', nlri.to_shex)
77
+ assert_match(/102.0/, nlri.to_s)
78
+ assert_match(/103.0/, nlri.to_s)
79
+ nlri1 = Withdrawn.new_ntop nlri.encode[2..-1]
80
+ nlri2 = Nlri.factory nlri.encode[2..-1], 1, 1
81
+ assert_equal(nlri1.to_shex, nlri2.to_shex)
82
+
83
+ # 16d403741755c68816d40830
84
+ end
85
+
86
+ def test_nlri_factory
87
+ s = '07640766076607680869'
88
+ nlri = Nlri.factory([s].pack('H*'),1,1)
89
+ s = '0f140010140011140000'
90
+ nlri = Nlri.factory([s].pack('H*'),1,1)
91
+ assert_equal("20.0.0.0/15\n20.0.0.0/16\n20.0.0.0/17", nlri.to_s)
92
+ assert_equal(s, nlri.to_shex)
93
+ end
94
+ #
95
+ def test_nlri_factory_extended
96
+ s = '000000650764000000660766000000670766000000680768000000690869'
97
+ nlri = Nlri.factory([s].pack('H*'),1,1,true)
98
+ assert_match(/ID=102, 102.0/, nlri.to_s)
99
+ assert_match(/ID=104, 104.0/, nlri.to_s)
100
+ assert_match(/ID=105, 105.0/, nlri.to_s)
101
+ assert_equal(s, nlri.to_shex)
102
+ end
103
+ end