bgp4r 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/bgp/common.rb +14 -13
- data/bgp/iana.rb +26 -1
- data/bgp/messages/capability.rb +3 -2
- data/bgp/messages/message.rb +3 -2
- data/bgp/messages/open.rb +2 -1
- data/bgp/messages/update.rb +80 -30
- data/bgp/neighbor/add_path_cap.rb +125 -0
- data/bgp/{neighbor.rb → neighbor/neighbor.rb} +64 -68
- data/bgp/nlris/nlri.rb +289 -15
- data/bgp/nlris/prefix.rb +3 -2
- data/bgp/nlris/vpn.rb +1 -8
- data/bgp/optional_parameters/add_path.rb +160 -0
- data/bgp/optional_parameters/capabilities.rb +1 -0
- data/bgp/optional_parameters/capability.rb +6 -0
- data/bgp/optional_parameters/graceful_restart.rb +6 -6
- data/bgp/optional_parameters/optional_parameter.rb +1 -0
- data/bgp/path_attributes/as_path.rb +1 -1
- data/bgp/path_attributes/attribute.rb +12 -5
- data/bgp/path_attributes/mp_reach.rb +142 -96
- data/bgp/path_attributes/mp_unreach.rb +73 -20
- data/bgp/path_attributes/path_attribute.rb +28 -5
- data/bgp4r.gemspec +21 -6
- data/bgp4r.rb +1 -1
- data/examples/unit-testing/malformed_update.rb +2 -1
- data/examples/unit-testing/test.rb +82 -0
- data/examples/unit-testing/test1.rb +82 -0
- data/examples/unit-testing/test2.rb +44 -0
- data/test/common_test.rb +7 -0
- data/test/helpers/server.rb +20 -0
- data/test/iana_test.rb +43 -0
- data/test/messages/open_test.rb +7 -2
- data/test/messages/update_test.rb +133 -36
- data/test/neighbor/add_path_cap_test.rb +54 -0
- data/test/neighbor/neighbor_test.rb +161 -0
- data/test/nlris/ext_nlri_test.rb +25 -60
- data/test/nlris/nlri_test.rb +93 -115
- data/test/optional_parameters/add_path_test.rb +53 -0
- data/test/optional_parameters/capability_test.rb +10 -0
- data/test/optional_parameters/graceful_restart_test.rb +1 -0
- data/test/path_attributes/mp_reach_test.rb +206 -8
- data/test/path_attributes/mp_unreach_test.rb +113 -5
- data/test/path_attributes/path_attribute_test.rb +34 -2
- metadata +20 -7
- data/test/neighbor_test.rb +0 -62
data/test/nlris/nlri_test.rb
CHANGED
@@ -20,133 +20,111 @@
|
|
20
20
|
# along with BGP4R. If not, see <http://www.gnu.org/licenses/>.
|
21
21
|
#++
|
22
22
|
|
23
|
+
require 'test/unit'
|
23
24
|
require 'bgp/nlris/nlris'
|
24
|
-
# require 'bgp/nlris/vpn'
|
25
|
-
# require 'bgp/nlris/inet'
|
26
|
-
# require 'bgp/nlris/labeled'
|
27
25
|
|
28
|
-
|
29
|
-
class NLRI_Ip4_Test < Test::Unit::TestCase
|
26
|
+
class Nlri_Test < Test::Unit::TestCase
|
30
27
|
include BGP
|
31
|
-
def
|
32
|
-
el =
|
33
|
-
|
34
|
-
assert_equal(
|
35
|
-
assert_equal(
|
36
|
-
assert_equal('
|
37
|
-
assert_equal('
|
38
|
-
assert_equal('
|
39
|
-
assert_equal('
|
40
|
-
assert_equal('
|
41
|
-
assert_equal('
|
42
|
-
assert_equal('
|
28
|
+
def test_ip4_element
|
29
|
+
el = Base_nlri::Ip4.new('10.0.0.8/9')
|
30
|
+
assert_equal('10.0.0.0/9', el.to_s)
|
31
|
+
assert_equal('070a', Base_nlri::Ip4.new('10.0.0.8/7').to_shex)
|
32
|
+
assert_equal('080a', Base_nlri::Ip4.new('10.0.0.8/8').to_shex)
|
33
|
+
assert_equal('090a00', Base_nlri::Ip4.new('10.0.0.8/9').to_shex)
|
34
|
+
assert_equal('0f0a00', Base_nlri::Ip4.new('10.0.0.8/15').to_shex)
|
35
|
+
assert_equal('100a00', Base_nlri::Ip4.new('10.0.0.8/16').to_shex)
|
36
|
+
assert_equal('110a0000', Base_nlri::Ip4.new('10.0.0.8/17').to_shex)
|
37
|
+
assert_equal('170a0000', Base_nlri::Ip4.new('10.0.0.8/23').to_shex)
|
38
|
+
assert_equal('180a0000', Base_nlri::Ip4.new('10.0.0.8/24').to_shex)
|
39
|
+
assert_equal('190a000000', Base_nlri::Ip4.new('10.0.0.8/25').to_shex)
|
40
|
+
assert_equal('200a000008', Base_nlri::Ip4.new('10.0.0.8/32').to_shex)
|
43
41
|
end
|
44
|
-
|
45
|
-
|
46
|
-
assert_equal('
|
47
|
-
assert_equal('
|
48
|
-
|
49
|
-
assert_equal('
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
42
|
+
def test_ext_element
|
43
|
+
assert_equal('ID: 100, 10.0.0.0/7', Base_nlri::Ext_Nlri_element.new(100, '10.0.0.0/7').to_s)
|
44
|
+
assert_equal('00000064070a', Base_nlri::Ext_Nlri_element.new(100, '10.0.0.0/7').to_shex)
|
45
|
+
assert_equal('00000064190a000000', Base_nlri::Ext_Nlri_element.new(100, '10.0.0.0/25').to_shex)
|
46
|
+
sbin = Base_nlri::Ext_Nlri_element.new(100, '10.0.0.0/25').encode
|
47
|
+
assert_equal('00000064190a000000', Base_nlri::Ext_Nlri_element.new(sbin).to_shex)
|
48
|
+
sbin = ['000000650764000000660766000000670766000000680768000000690869'].pack('H*')
|
49
|
+
Base_nlri::Ext_Nlri_element.new(sbin)
|
50
|
+
assert_equal('000000660766000000670766000000680768000000690869', sbin.unpack('H*')[0])
|
51
|
+
Base_nlri::Ext_Nlri_element.new(sbin)
|
52
|
+
assert_equal('000000670766000000680768000000690869', sbin.unpack('H*')[0])
|
53
|
+
Base_nlri::Ext_Nlri_element.new(sbin)
|
54
|
+
assert_equal('000000680768000000690869', sbin.unpack('H*')[0])
|
55
|
+
Base_nlri::Ext_Nlri_element.new(sbin)
|
56
|
+
assert_equal('000000690869', sbin.unpack('H*')[0])
|
57
|
+
Base_nlri::Ext_Nlri_element.new(sbin)
|
58
|
+
assert_equal('', sbin.unpack('H*')[0])
|
59
|
+
|
60
|
+
# sbin=['0f140010140011140000'].pack('H*')
|
61
|
+
# Base_nlri::Nlri_element.new(sbin)
|
62
|
+
# assert_equal('', sbin.unpack('H*')[0])
|
63
|
+
|
64
|
+
|
59
65
|
end
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
def test_1
|
64
|
-
assert_equal('0410',Nlri::Ip6.new('1111:2222:3333:4444:5555:6666:7777:8888/4').to_shex)
|
65
|
-
assert_equal('0510',Nlri::Ip6.new('1111:2222:3333:4444:5555:6666:7777:8888/5').to_shex)
|
66
|
-
assert_equal('0710',Nlri::Ip6.new('1111:2222:3333:4444:5555:6666:7777:8888/7').to_shex)
|
67
|
-
assert_equal('0811',Nlri::Ip6.new('1111:2222:3333:4444:5555:6666:7777:8888/8').to_shex)
|
68
|
-
assert_equal('091100',Nlri::Ip6.new('1111:2222:3333:4444:5555:6666:7777:8888/9').to_shex)
|
69
|
-
assert_equal('30111122223333',Nlri::Ip6.new('1111:2222:3333:4444:5555:6666:7777:8888/48').to_shex)
|
70
|
-
assert_equal('3111112222333300',Nlri::Ip6.new('1111:2222:3333:4444:5555:6666:7777:8888/49').to_shex)
|
71
|
-
assert_equal('401111222233334444',Nlri::Ip6.new('1111:2222:3333:4444:5555:6666:7777:8888/64').to_shex)
|
72
|
-
assert_equal('41111122223333444400',Nlri::Ip6.new('1111:2222:3333:4444:5555:6666:7777:8888/65').to_shex)
|
73
|
-
assert_equal('7f11112222333344445555666677778888',Nlri::Ip6.new('1111:2222:3333:4444:5555:6666:7777:8888/127').to_shex)
|
74
|
-
assert_equal('8011112222333344445555666677778888',Nlri::Ip6.new('1111:2222:3333:4444:5555:6666:7777:8888/128').to_shex)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
class Withdrawn_Test < Test::Unit::TestCase
|
79
|
-
include BGP
|
80
|
-
def test_1
|
81
|
-
nlri1 = Withdrawn.new
|
82
|
-
assert_equal('0000', nlri1.to_shex)
|
83
|
-
nlri1 << Withdrawn::Ip4.new('20.0.0.0/15')
|
66
|
+
def test_nlri
|
67
|
+
nlri1 = Nlri.new
|
68
|
+
nlri1 << Base_nlri::Ip4.new('20.0.0.0/15')
|
84
69
|
nlri1 << '20.0.0.0/17'
|
85
70
|
nlri1 << '20.0.0.0/24'
|
86
71
|
s = '0f140010140011140000'
|
87
|
-
nlri2 =
|
88
|
-
assert_equal('
|
89
|
-
|
90
|
-
assert_equal('0f140010140011140000', nlri2.to_shex(false))
|
72
|
+
nlri2 = Nlri.new([s].pack('H*'))
|
73
|
+
assert_equal('0f140010140011140000', nlri2.to_shex)
|
74
|
+
assert_raise(ArgumentError) { nlri2.to_shex(true) }
|
91
75
|
assert_equal(3,nlri2.nlris.size)
|
92
76
|
end
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
assert_equal('10c0a8',Prefix.new('192.168.0.0/16').to_shex)
|
104
|
-
assert_equal('402009000400040000',Prefix.new('2009:4:4::/64').to_shex)
|
105
|
-
assert Prefix.new('2009:4:4::/64').ipv6?
|
106
|
-
assert_equal('2009:4:4::/64',Prefix.new('2009:4:4::/64').to_s)
|
77
|
+
def test_nlris
|
78
|
+
nlri = Nlri.new
|
79
|
+
nlri << [101, '101.0.0.0/8']
|
80
|
+
nlri << [102, '102.0.0.0/8']
|
81
|
+
nlri << [103, '103.0.0.0/8']
|
82
|
+
nlri << { :path_id=> 104, :nlri_element=> '104.0.0.0/8' }
|
83
|
+
nlri << { :path_id=> 105, :nlri_element=> '105.0.0.0/8' }
|
84
|
+
assert_match(/ID: 102, 102.0/, nlri.to_s)
|
85
|
+
assert_match(/ID: 104, 104.0/, nlri.to_s)
|
86
|
+
assert_match(/ID: 105, 105.0/, nlri.to_s)
|
107
87
|
end
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
assert_equal(true,Vpn.new('10.0.0.1/24', Rd.new(1,1)).ipv4?)
|
119
|
-
assert_equal(false,Vpn.new('10.0.0.1/24', Rd.new(1,1)).ipv6?)
|
120
|
-
assert_equal(2,Vpn.new('2009:4:5::/105', Rd.new(1,1)).afi)
|
121
|
-
assert_equal(false,Vpn.new('2009:4:5::/105', Rd.new(1,1)).ipv4?)
|
122
|
-
assert_equal(true,Vpn.new('2009:4:5::/105', Rd.new(1,1)).ipv6?)
|
123
|
-
assert_equal('RD=1:1, IPv6=2009:4:5::/105',Vpn.new('2009:4:5::/105', Rd.new(1,1)).to_s)
|
124
|
-
assert_equal('700000000100000001200900040005',Vpn.new('2009:4:5::/48', Rd.new(1,1)).to_shex)
|
125
|
-
assert_equal(169,Vpn.new('2009:4:5::/105', Rd.new(1,1)).bit_length)
|
88
|
+
def test_withdrawns_ext
|
89
|
+
nlri = Withdrawn.new
|
90
|
+
nlri << [101, '101.0.0.0/8']
|
91
|
+
nlri << [102, '102.0.0.0/8']
|
92
|
+
nlri << [103, '103.0.0.0/8']
|
93
|
+
nlri << { :path_id=> 104, :nlri_element=> '104.0.0.0/8' }
|
94
|
+
nlri << { :path_id=> 105, :nlri_element=> '105.0.0.0/8' }
|
95
|
+
assert_match(/ID: 102, 102.0/, nlri.to_s)
|
96
|
+
assert_match(/ID: 104, 104.0/, nlri.to_s)
|
97
|
+
assert_match(/ID: 105, 105.0/, nlri.to_s)
|
126
98
|
end
|
127
|
-
def
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
assert_equal(
|
133
|
-
|
134
|
-
|
99
|
+
def test_withdrawns
|
100
|
+
nlri = Withdrawn.new
|
101
|
+
nlri << '101.0.0.0/8'
|
102
|
+
nlri << '102.0.0.0/8'
|
103
|
+
nlri << '103.0.0.0/8'
|
104
|
+
assert_equal('086508660867', nlri.to_shex)
|
105
|
+
assert_match(/102.0/, nlri.to_s)
|
106
|
+
assert_match(/103.0/, nlri.to_s)
|
107
|
+
nlri1 = Withdrawn.new nlri.encode[2..-1].is_packed
|
108
|
+
nlri2 = Nlri.factory nlri.encode[2..-1].is_packed, 1, 1
|
109
|
+
assert_equal(nlri1.to_shex, nlri2.to_shex)
|
110
|
+
|
111
|
+
# 16d403741755c68816d40830
|
135
112
|
end
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
assert_equal(
|
143
|
-
assert_equal(
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
113
|
+
|
114
|
+
def test_factory_ip4_elements
|
115
|
+
s = '07640766076607680869'
|
116
|
+
nlri = Nlri.factory([s].pack('H*'),1,1)
|
117
|
+
s = '0f140010140011140000'
|
118
|
+
nlri = Nlri.factory([s].pack('H*'),1,1)
|
119
|
+
assert_equal("20.0.0.0/15\n20.0.0.0/16\n20.0.0.0/17", nlri.to_s)
|
120
|
+
assert_equal(s, nlri.to_shex)
|
121
|
+
end
|
122
|
+
def test_factory_ip4_elements_extented
|
123
|
+
s = '000000650764000000660766000000670766000000680768000000690869'
|
124
|
+
nlri = Nlri.factory([s].pack('H*'),1,1,true)
|
125
|
+
assert_match(/ID: 102, 102.0/, nlri.to_s)
|
126
|
+
assert_match(/ID: 104, 104.0/, nlri.to_s)
|
127
|
+
assert_match(/ID: 105, 105.0/, nlri.to_s)
|
128
|
+
assert_equal(s, nlri.to_shex)
|
151
129
|
end
|
152
130
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 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 'bgp4r'
|
25
|
+
require "bgp/optional_parameters/add_path"
|
26
|
+
|
27
|
+
class TestBgpOptionalParametersAddPath < Test::Unit::TestCase
|
28
|
+
include BGP::OPT_PARM::CAP
|
29
|
+
def test_1
|
30
|
+
ap = Add_path.new
|
31
|
+
ap.add( :send, 1, 1)
|
32
|
+
assert_equal '0206450400010101', ap.to_shex
|
33
|
+
ap.add( :recv, 2, 128)
|
34
|
+
assert_equal '020a45080001010100028002', ap.to_shex
|
35
|
+
ap.add :send_and_receive, :ipv6, :unicast
|
36
|
+
assert_equal '020e450c000101010002010300028002', ap.to_shex
|
37
|
+
end
|
38
|
+
def test_2
|
39
|
+
ap = Add_path.new
|
40
|
+
ap.add( :send, 1, 1)
|
41
|
+
ap.add( :send, 2, 128)
|
42
|
+
ap.add( :send_and_recv, 2, 128)
|
43
|
+
assert ap.send? 1, 1
|
44
|
+
assert ! ap.send?( 1, 2)
|
45
|
+
assert ap.send?( 2, 128)
|
46
|
+
assert ap.recv?( 2, 128)
|
47
|
+
end
|
48
|
+
def test_3
|
49
|
+
ap1 = Add_path.new_array [[1, 1 ,2 ], [2, 10, 10]]
|
50
|
+
ap2 = Add_path.new_array [[:send, :ipv4 ,:multicast], [:recv, 10, 10]]
|
51
|
+
assert_equal ap1.to_shex, ap2.to_shex
|
52
|
+
end
|
53
|
+
end
|
@@ -38,6 +38,11 @@ class Capability_Test < Test::Unit::TestCase
|
|
38
38
|
cap = Capability.factory([s].pack('H*'))
|
39
39
|
assert_instance_of(Graceful_restart, cap)
|
40
40
|
end
|
41
|
+
def test_factory_add_path
|
42
|
+
s = '020e450c000101010002800200020103'
|
43
|
+
cap = Capability.factory([s].pack('H*'))
|
44
|
+
assert_instance_of(Add_path, cap)
|
45
|
+
end
|
41
46
|
def test_factory_as4
|
42
47
|
s = '0206410400000064'
|
43
48
|
cap = Capability.factory([s].pack('H*'))
|
@@ -61,6 +66,11 @@ class Capability_Test < Test::Unit::TestCase
|
|
61
66
|
cap = Capability.factory([s].pack('H*'))
|
62
67
|
assert_equal(Orf, cap.class)
|
63
68
|
end
|
69
|
+
def test_factory_add_path
|
70
|
+
s = '020e450c000101010002800200020103'
|
71
|
+
cap = Capability.factory([s].pack('H*'))
|
72
|
+
assert_instance_of(Add_path, cap)
|
73
|
+
end
|
64
74
|
def test_factory_unknown
|
65
75
|
s = '0207640576616c7565'
|
66
76
|
cap = Capability.factory([s].pack('H*'))
|
@@ -72,36 +72,234 @@ class Mp_reach_Test < Test::Unit::TestCase
|
|
72
72
|
#puts mpr
|
73
73
|
end
|
74
74
|
def test_6
|
75
|
-
mpr = Mp_reach.new(:safi=>2, :nexthop=> ['2009:9:19::1/128'], :
|
75
|
+
mpr = Mp_reach.new(:safi=>2, :nexthop=> ['2009:9:19::1/128'], :nlris=> ['2009:1::/64', '2009:2::/64', '2009:3::/64'])
|
76
76
|
assert_equal("\n AFI IPv6 (2), SAFI Multicast (2)\n nexthop: 2009:9:19::1\n 2009:1::/64\n 2009:2::/64\n 2009:3::/64", mpr.mp_reach)
|
77
77
|
assert_equal(mpr.to_shex, Mp_reach.new(mpr.encode).to_shex)
|
78
|
-
mpr = Mp_reach.new(:safi=>1, :nexthop=> ['10.0.0.1','10.0.0.2'], :
|
78
|
+
mpr = Mp_reach.new(:safi=>1, :nexthop=> ['10.0.0.1','10.0.0.2'], :nlris=> '192.168.0.0/24')
|
79
79
|
assert_equal("\n AFI IPv4 (1), SAFI Unicast (1)\n nexthop: 10.0.0.1, 10.0.0.2\n 192.168.0.0/24", mpr.mp_reach)
|
80
80
|
assert_equal(mpr.to_shex, Mp_reach.new(mpr.encode).to_shex)
|
81
|
-
mpr = Mp_reach.new(:safi=>4, :nexthop=> ['10.0.0.1','10.0.0.2'], :
|
81
|
+
mpr = Mp_reach.new(:safi=>4, :nexthop=> ['10.0.0.1','10.0.0.2'], :nlris=> {:prefix=> '192.168.0.0/24', :label=>101} )
|
82
82
|
assert_equal("\n AFI IPv4 (1), SAFI Labeled NLRI (4)\n nexthop: 10.0.0.1, 10.0.0.2\n Label Stack=101 (bottom) 192.168.0.0/24", mpr.mp_reach)
|
83
83
|
assert_equal(mpr.to_shex, Mp_reach.new(mpr.encode).to_shex)
|
84
|
-
mpr = Mp_reach.new(:safi=>128, :nexthop=> ['10.0.0.1','10.0.0.2'], :
|
84
|
+
mpr = Mp_reach.new(:safi=>128, :nexthop=> ['10.0.0.1','10.0.0.2'], :nlris=> {:rd=> [100,100], :prefix=> '192.168.0.0/24', :label=>101})
|
85
85
|
assert_equal("\n AFI IPv4 (1), SAFI Labeled VPN Unicast (128)\n nexthop: 10.0.0.1, 10.0.0.2\n Label Stack=101 (bottom) RD=100:100, IPv4=192.168.0.0/24", mpr.mp_reach)
|
86
86
|
assert_equal(mpr.to_shex, Mp_reach.new(mpr.encode).to_shex)
|
87
|
-
mpr = Mp_reach.new(:safi=>128, :nexthop=> ['10.0.0.1','10.0.0.2'], :
|
87
|
+
mpr = Mp_reach.new(:safi=>128, :nexthop=> ['10.0.0.1','10.0.0.2'], :nlris=> {:rd=> Rd.new(100,100), :prefix=> Prefix.new('192.168.0.0/24'), :label=>101})
|
88
88
|
assert_equal("\n AFI IPv4 (1), SAFI Labeled VPN Unicast (128)\n nexthop: 10.0.0.1, 10.0.0.2\n Label Stack=101 (bottom) RD=100:100, IPv4=192.168.0.0/24", mpr.mp_reach)
|
89
89
|
assert_equal(mpr.to_shex, Mp_reach.new(mpr.encode).to_shex)
|
90
90
|
end
|
91
91
|
def test_7
|
92
|
-
mpr = Mp_reach.new(:safi=>2, :nexthop=> '2009:9:19::1/128', :
|
92
|
+
mpr = Mp_reach.new(:safi=>2, :nexthop=> '2009:9:19::1/128', :nlris=> [
|
93
93
|
'2009:1::/64', '2009:2::/64', '2009:3::/64', '2009:4::/64', '2009:5::/64', '2009:6::/64'])
|
94
94
|
assert_equal("\n AFI IPv6 (2), SAFI Multicast (2)\n nexthop: 2009:9:19::1\n 2009:1::/64\n 2009:2::/64\n 2009:3::/64\n 2009:4::/64\n 2009:5::/64\n 2009:6::/64", mpr.mp_reach)
|
95
|
-
mpr = Mp_reach.new(:safi=>1, :nexthop=> '10.0.0.1', :
|
95
|
+
mpr = Mp_reach.new(:safi=>1, :nexthop=> '10.0.0.1', :nlris=> [
|
96
96
|
'192.168.0.0/24', '192.168.1.0/24', '192.168.2.0/24', '192.168.3.0/24', '192.168.4.0/24', '192.168.5.0/24'])
|
97
97
|
assert_equal("\n AFI IPv4 (1), SAFI Unicast (1)\n nexthop: 10.0.0.1\n 192.168.0.0/24\n 192.168.1.0/24\n 192.168.2.0/24\n 192.168.3.0/24\n 192.168.4.0/24\n 192.168.5.0/24", mpr.mp_reach)
|
98
98
|
end
|
99
99
|
def test_8
|
100
|
-
mpr = Mp_reach.new(:safi=>1, :nexthop=> '10.0.0.1', :
|
100
|
+
mpr = Mp_reach.new(:safi=>1, :nexthop=> '10.0.0.1', :nlris=> [
|
101
101
|
'192.168.0.0/24', '192.168.1.0/24', '192.168.2.0/24', '192.168.3.0/24', '192.168.4.0/24', '192.168.5.0/24'])
|
102
102
|
assert_equal(Mp_unreach,mpr.new_unreach.class)
|
103
103
|
mpr2 = Mp_reach.new(mpr)
|
104
104
|
assert_equal(mpr.encode, mpr2.encode)
|
105
105
|
assert_equal(Mp_unreach, Mp_unreach.new(mpr.new_unreach).class)
|
106
106
|
end
|
107
|
+
|
108
|
+
def test_afi_1
|
109
|
+
mpr1 = Mp_reach.new(:safi=>1, :nexthop=> ['10.0.0.1'], :nlris=> '192.168.1.0/24')
|
110
|
+
mpr2 = Mp_reach.new(:safi=>1, :nexthop=> ['10.0.0.1'], :nlris=> '192.168.1.0/24', :path_id=>100)
|
111
|
+
mpr3 = Mp_reach.new(:safi=>2, :nexthop=> ['10.0.0.1'], :nlris=> ['192.168.1.0/24','192.168.2.0/24'])
|
112
|
+
mpr4 = Mp_reach.new(:safi=>2, :nexthop=> ['10.0.0.1'], :nlris=> ['192.168.1.0/24','192.168.2.0/24'], :path_id=>100)
|
113
|
+
mpr5 = Mp_reach.new(:safi=>1, :nexthop=> ['10.0.0.1'], :nlris=> [
|
114
|
+
{:prefix=> '192.168.1.0/24', :path_id=> 100},
|
115
|
+
{:prefix=> '192.168.2.0/24', :path_id=> 101},
|
116
|
+
{:prefix=> '192.168.2.0/24', :path_id=> 102},
|
117
|
+
])
|
118
|
+
|
119
|
+
assert_equal('800e0d000101040a0000010018c0a801', mpr1.to_shex)
|
120
|
+
assert_equal('800e11000101040a000001000000006418c0a801', mpr2.to_shex)
|
121
|
+
assert_equal attr_len(mpr1)+4, attr_len(mpr2)
|
122
|
+
|
123
|
+
assert_equal('800e11000102040a0000010018c0a80118c0a802', mpr3.to_shex)
|
124
|
+
assert_equal('800e19000102040a000001000000006418c0a8010000006418c0a802', mpr4.to_shex)
|
125
|
+
assert_equal attr_len(mpr3)+8, attr_len(mpr4)
|
126
|
+
|
127
|
+
assert_equal('800e21000101040a000001000000006418c0a8010000006518c0a8020000006618c0a802', mpr5.to_shex)
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_afi_1_ntop
|
132
|
+
|
133
|
+
s = '800e11000102040a0000010018c0a80118c0a802'
|
134
|
+
sbin = [s].pack('H*')
|
135
|
+
mpr = Mp_reach.new(sbin, false)
|
136
|
+
assert_match(/^\s+192.168.1.0\/24/, mpr.to_s)
|
137
|
+
assert_match(/^\s+192.168.1.0\/24/, mpr.to_s)
|
138
|
+
|
139
|
+
s = '800e19000102040a000001000000006418c0a8010000006418c0a802'
|
140
|
+
sbin = [s].pack('H*')
|
141
|
+
mpr = Mp_reach.new(sbin, true)
|
142
|
+
assert_match(/^\s+ID=100, 192.168.1.0\/24/, mpr.to_s)
|
143
|
+
assert_match(/^\s+ID=100, 192.168.1.0\/24/, mpr.to_s)
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
def test_afi_2
|
148
|
+
mpr1 = Mp_reach.new(:safi=>1, :nexthop=> ['2011:1:7::1'], :nlris=> '2011:1::/32')
|
149
|
+
mpr2 = Mp_reach.new(:safi=>1, :nexthop=> ['2011:1:7::1'], :nlris=> '2011:1::/32', :path_id=>100)
|
150
|
+
mpr3 = Mp_reach.new(:safi=>2, :nexthop=> ['2011:1:7::1'], :nlris=> ['2011:1::/32','2011:2::/32'])
|
151
|
+
mpr4 = Mp_reach.new(:safi=>2, :nexthop=> ['2011:1:7::1'], :nlris=> ['2011:1::/32','2011:2::/32'], :path_id=>100)
|
152
|
+
mpr5 = Mp_reach.new(:safi=>1, :nexthop=> ['2011:1:7::1'], :nlris=> [
|
153
|
+
{:prefix=> '2011:1::/32', :path_id=> 100},
|
154
|
+
{:prefix=> '2011:2::/32', :path_id=> 101},
|
155
|
+
{:prefix=> '2011:3::/32', :path_id=> 102},
|
156
|
+
])
|
157
|
+
|
158
|
+
assert_equal('800e1a0002011020110001000700000000000000000001002020110001', mpr1.to_shex)
|
159
|
+
assert_equal('800e1e000201102011000100070000000000000000000100000000642020110001', mpr2.to_shex)
|
160
|
+
assert_equal attr_len(mpr1)+4, attr_len(mpr2)
|
161
|
+
|
162
|
+
assert_equal('800e1f00020210201100010007000000000000000000010020201100012020110002', mpr3.to_shex)
|
163
|
+
assert_equal('800e27000202102011000100070000000000000000000100000000642020110001000000642020110002', mpr4.to_shex)
|
164
|
+
assert_equal attr_len(mpr3)+8, attr_len(mpr4)
|
165
|
+
|
166
|
+
assert_equal('800e30000201102011000100070000000000000000000100000000642020110001000000652020110002000000662020110003', mpr5.to_shex)
|
167
|
+
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_afi_2_ntop
|
172
|
+
|
173
|
+
s = '800e1f00020210201100010007000000000000000000010020201100012020110002'
|
174
|
+
sbin = [s].pack('H*')
|
175
|
+
mpr = Mp_reach.new(sbin, false)
|
176
|
+
assert_match(/^\s+2011:1::\/32/, mpr.to_s)
|
177
|
+
assert_match(/^\s+2011:2::\/32/, mpr.to_s)
|
178
|
+
|
179
|
+
s = '800e27000202102011000100070000000000000000000100000000642020110001000000642020110002'
|
180
|
+
sbin = [s].pack('H*')
|
181
|
+
mpr = Mp_reach.new(sbin, true)
|
182
|
+
assert_match(/^\s+ID=100, 2011:1::\/32/, mpr.to_s)
|
183
|
+
assert_match(/^\s+ID=100, 2011:2::\/32/, mpr.to_s)
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_safi_4
|
187
|
+
mpr1 = Mp_reach.new(:safi=>4, :nexthop=> ['10.0.0.1'], :nlris=> {:prefix=> '192.168.0.0/24', :label=>101} )
|
188
|
+
mpr2 = Mp_reach.new(:safi=>4, :nexthop=> ['10.0.0.1'], :nlris=> {:prefix=> '192.168.0.0/24', :label=>101, :path_id=>100} )
|
189
|
+
mpr3 = Mp_reach.new(:safi=>4, :nexthop=> ['10.0.0.1'], :nlris=> [
|
190
|
+
{:prefix=> '192.168.0.0/24', :label=>101,},
|
191
|
+
{:prefix=> '192.168.1.0/24', :label=>102,},
|
192
|
+
{:prefix=> '192.168.1.0/24', :label=>103,}
|
193
|
+
])
|
194
|
+
mpr4 = Mp_reach.new(:safi=>4, :nexthop=> ['10.0.0.1'], :path_id=> 100, :nlris=> [
|
195
|
+
{:prefix=> '192.168.0.0/24', :label=>101,},
|
196
|
+
{:prefix=> '192.168.1.0/24', :label=>102,},
|
197
|
+
{:prefix=> '192.168.1.0/24', :label=>103,}
|
198
|
+
])
|
199
|
+
mpr5 = Mp_reach.new(:safi=>4, :nexthop=> ['10.0.0.1'], :nlris=> [
|
200
|
+
{:prefix=> '192.168.0.0/24', :label=>101, :path_id=>100},
|
201
|
+
{:prefix=> '192.168.1.0/24', :label=>102, :path_id=>101},
|
202
|
+
{:prefix=> '192.168.1.0/24', :label=>103, :path_id=>103},
|
203
|
+
])
|
204
|
+
|
205
|
+
assert_equal('800e10000104040a0000010030000651c0a800', mpr1.to_shex)
|
206
|
+
assert_equal('800e14000104040a000001000000006430000651c0a800', mpr2.to_shex)
|
207
|
+
assert_equal attr_len(mpr1)+4, attr_len(mpr2)
|
208
|
+
|
209
|
+
assert_equal('800e1e000104040a0000010030000651c0a80030000661c0a80130000671c0a801', mpr3.to_shex)
|
210
|
+
assert_equal('800e2a000104040a000001000000006430000651c0a8000000006430000661c0a8010000006430000671c0a801', mpr4.to_shex)
|
211
|
+
assert_equal attr_len(mpr3)+12, attr_len(mpr4)
|
212
|
+
|
213
|
+
assert_equal('800e2a000104040a000001000000006430000651c0a8000000006530000661c0a8010000006730000671c0a801', mpr5.to_shex)
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_safi_128
|
218
|
+
mpr1 = Mp_reach.new :safi=>128, :nexthop=> ['10.0.0.1'], :nlris=> {:rd=> [100,100], :prefix=> '192.168.0.0/24', :label=>101}
|
219
|
+
mpr2 = Mp_reach.new :safi=>128, :nexthop=> ['10.0.0.1'], :nlris=> {:rd=> [100,100], :prefix=> '192.168.0.0/24', :label=>101, :path_id=>100}
|
220
|
+
mpr3 = Mp_reach.new :safi=>128, :nexthop=> ['10.0.0.1'], :nlris=> [
|
221
|
+
{:rd=> [100,100], :prefix=> '192.168.0.0/24', :label=>101},
|
222
|
+
{:rd=> [100,100], :prefix=> '192.168.1.0/24', :label=>102},
|
223
|
+
{:rd=> [100,100], :prefix=> '192.168.2.0/24', :label=>103},
|
224
|
+
]
|
225
|
+
mpr4 = Mp_reach.new :safi=>128, :nexthop=> ['10.0.0.1'], :path_id=> 100, :nlris=> [
|
226
|
+
{:rd=> [100,100], :prefix=> '192.168.0.0/24', :label=>101},
|
227
|
+
{:rd=> [100,100], :prefix=> '192.168.1.0/24', :label=>102},
|
228
|
+
{:rd=> [100,100], :prefix=> '192.168.2.0/24', :label=>103},
|
229
|
+
]
|
230
|
+
mpr5 = Mp_reach.new :safi=>128, :nexthop=> ['10.0.0.1'], :nlris=> [
|
231
|
+
{:rd=> [100,100], :prefix=> '192.168.0.0/24', :label=>101, :path_id=>101},
|
232
|
+
{:rd=> [100,100], :prefix=> '192.168.1.0/24', :label=>102, :path_id=>102},
|
233
|
+
{:rd=> [100,100], :prefix=> '192.168.2.0/24', :label=>103, :path_id=>103},
|
234
|
+
]
|
235
|
+
|
236
|
+
assert_equal('800e200001800c00000000000000000a00000100700006510000006400000064c0a800', mpr1.to_shex)
|
237
|
+
assert_equal('800e240001800c00000000000000000a0000010000000064700006510000006400000064c0a800', mpr2.to_shex)
|
238
|
+
assert_equal attr_len(mpr1)+4, attr_len(mpr2)
|
239
|
+
|
240
|
+
assert_equal('800e3e0001800c00000000000000000a00000100700006510000006400000064c0a800700006610000006400000064c0a801700006710000006400000064c0a802', mpr3.to_shex)
|
241
|
+
assert_equal('800e4a0001800c00000000000000000a0000010000000064700006510000006400000064c0a80000000064700006610000006400000064c0a80100000064700006710000006400000064c0a802', mpr4.to_shex)
|
242
|
+
assert_equal attr_len(mpr3)+12, attr_len(mpr4)
|
243
|
+
|
244
|
+
assert_equal('800e4a0001800c00000000000000000a0000010000000065700006510000006400000064c0a80000000066700006610000006400000064c0a80100000067700006710000006400000064c0a802', mpr5.to_shex)
|
245
|
+
|
246
|
+
# 800e3e 0001 80 0c 00000000000000000a000001 00
|
247
|
+
# 700006510000006400000064c0a800
|
248
|
+
# 700006610000006400000064c0a801
|
249
|
+
# 700006710000006400000064c0a802
|
250
|
+
#
|
251
|
+
#
|
252
|
+
# 800e4a0001800c00000000000000000a000001 00
|
253
|
+
# 00000064 700006510000006400000064c0a800
|
254
|
+
# 00000064 700006610000006400000064c0a801
|
255
|
+
# 00000064 700006710000006400000064c0a802
|
256
|
+
#
|
257
|
+
#
|
258
|
+
# 800e4a 0001 80 0c 00000000000000000a000001 00
|
259
|
+
# 00000065 700006510000006400000064c0a800
|
260
|
+
# 00000066 700006610000006400000064c0a801
|
261
|
+
# 00000067 700006710000006400000064c0a802
|
262
|
+
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_safi_4_ntop
|
266
|
+
|
267
|
+
s = '800e1e000104040a0000010030000651c0a80030000661c0a80130000671c0a801'
|
268
|
+
sbin = [s].pack('H*')
|
269
|
+
mpr = Mp_reach.new(sbin, false)
|
270
|
+
assert_match(/^\s+Label Stack=101 /, mpr.to_s)
|
271
|
+
assert_match(/^\s+Label Stack=102 /, mpr.to_s)
|
272
|
+
assert_match(/^\s+Label Stack=103 /, mpr.to_s)
|
273
|
+
|
274
|
+
s = '800e2a000104040a000001000000006430000651c0a8000000006430000661c0a8010000006430000671c0a801'
|
275
|
+
sbin = [s].pack('H*')
|
276
|
+
mpr = Mp_reach.new(sbin, true)
|
277
|
+
assert_match(/ID=100, Label Stack=101 /, mpr.to_s)
|
278
|
+
assert_match(/ID=100, Label Stack=102 /, mpr.to_s)
|
279
|
+
assert_match(/ID=100, Label Stack=103 /, mpr.to_s)
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_safi_128_ntop
|
283
|
+
|
284
|
+
s = '800e3e0001800c00000000000000000a00000100700006510000006400000064c0a800700006610000006400000064c0a801700006710000006400000064c0a802'
|
285
|
+
sbin = [s].pack('H*')
|
286
|
+
mpr = Mp_reach.new(sbin, false)
|
287
|
+
assert_match(/^\s+Label Stack=101 /, mpr.to_s)
|
288
|
+
assert_match(/^\s+Label Stack=102 /, mpr.to_s)
|
289
|
+
assert_match(/^\s+Label Stack=103 /, mpr.to_s)
|
290
|
+
|
291
|
+
s = '800e4a0001800c00000000000000000a0000010000000065700006510000006400000064c0a80000000066700006610000006400000064c0a80100000067700006710000006400000064c0a802'
|
292
|
+
sbin = [s].pack('H*')
|
293
|
+
mpr = Mp_reach.new(sbin, true)
|
294
|
+
assert_match(/ID=101, Label Stack=101 /, mpr.to_s)
|
295
|
+
assert_match(/ID=102, Label Stack=102 /, mpr.to_s)
|
296
|
+
assert_match(/ID=103, Label Stack=103 /, mpr.to_s)
|
297
|
+
end
|
298
|
+
|
299
|
+
private
|
300
|
+
|
301
|
+
def attr_len(attr)
|
302
|
+
attr.encode[2,1].unpack('C')[0]
|
303
|
+
end
|
304
|
+
|
107
305
|
end
|