bgp4r 0.0.13 → 0.0.14

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 (50) hide show
  1. data/bgp/messages/update.rb +8 -0
  2. data/bgp/nlris/label.rb +9 -1
  3. data/bgp/nlris/labeled.rb +11 -0
  4. data/bgp/nlris/nlri.rb +15 -4
  5. data/bgp/nlris/prefix.rb +11 -0
  6. data/bgp/nlris/rd.rb +13 -1
  7. data/bgp/nlris/vpn.rb +59 -10
  8. data/bgp/path_attributes/aggregator.rb +19 -0
  9. data/bgp/path_attributes/aigp.rb +63 -0
  10. data/bgp/path_attributes/as_path.rb +57 -0
  11. data/bgp/path_attributes/atomic_aggregate.rb +3 -0
  12. data/bgp/path_attributes/attribute.rb +10 -0
  13. data/bgp/path_attributes/attributes.rb +1 -0
  14. data/bgp/path_attributes/cluster_list.rb +24 -1
  15. data/bgp/path_attributes/communities.rb +32 -1
  16. data/bgp/path_attributes/extended_communities.rb +26 -0
  17. data/bgp/path_attributes/extended_community.rb +101 -16
  18. data/bgp/path_attributes/local_pref.rb +10 -0
  19. data/bgp/path_attributes/mp_reach.rb +21 -2
  20. data/bgp/path_attributes/mp_unreach.rb +5 -1
  21. data/bgp/path_attributes/multi_exit_disc.rb +10 -0
  22. data/bgp/path_attributes/next_hop.rb +20 -0
  23. data/bgp/path_attributes/origin.rb +14 -0
  24. data/bgp/path_attributes/originator_id.rb +17 -6
  25. data/bgp/path_attributes/path_attribute.rb +87 -2
  26. data/bgp/path_attributes/tlvs/tlv.rb +18 -0
  27. data/test/unit/messages/update_test.rb +79 -5
  28. data/test/unit/neighbor/neighbor_test.rb +0 -1
  29. data/test/unit/nlris/label_test.rb +6 -0
  30. data/test/unit/nlris/labeled_test.rb +12 -0
  31. data/test/unit/nlris/prefix_test.rb +5 -1
  32. data/test/unit/nlris/rd_test.rb +2 -0
  33. data/test/unit/nlris/vpn_test.rb +50 -0
  34. data/test/unit/path_attributes/aggregator_test.rb +6 -0
  35. data/test/unit/path_attributes/{aigp.rb → aigp_test.rb} +29 -0
  36. data/test/unit/path_attributes/as_path_test.rb +53 -0
  37. data/test/unit/path_attributes/atomic_aggregate_test.rb +3 -0
  38. data/test/unit/path_attributes/cluster_list_test.rb +15 -10
  39. data/test/unit/path_attributes/communities_test.rb +9 -4
  40. data/test/unit/path_attributes/extended_communities_test.rb +31 -3
  41. data/test/unit/path_attributes/extended_community_test.rb +52 -9
  42. data/test/unit/path_attributes/local_pref_test.rb +5 -0
  43. data/test/unit/path_attributes/mp_reach_test.rb +51 -4
  44. data/test/unit/path_attributes/mp_unreach_test.rb +9 -7
  45. data/test/unit/path_attributes/next_hop_test.rb +3 -0
  46. data/test/unit/path_attributes/origin_test.rb +1 -0
  47. data/test/unit/path_attributes/path_attribute_test.rb +53 -2
  48. data/test/unit/path_attributes/tlvs/tlv_test.rb +33 -0
  49. data/test/unit/path_attributes/tunnel_encapsulation_test (Jean-Michel's Laptop's conflicted copy 2011-11-02).rb +388 -0
  50. metadata +14 -4
@@ -410,7 +410,6 @@ class Mp_reach_Test < Test::Unit::TestCase
410
410
  assert_match(/ID=100, 49.0a10.0b00.0000.0000.0000.0000.0000.0000.0000.00\/32/, mpr.to_s)
411
411
  assert_match(/ID=101, 49.0a20.0b00.0000.0000.0000.0000.0000.0000.0000.00\/32/, mpr.to_s)
412
412
  assert_match(/ID=102, 49.0a30.0b00.0000.0000.0000.0000.0000.0000.0000.00\/32/, mpr.to_s)
413
-
414
413
 
415
414
  end
416
415
 
@@ -436,8 +435,7 @@ class Mp_reach_Test < Test::Unit::TestCase
436
435
 
437
436
  assert_equal('800e10000104040a0000010030000651c0a800', mpr1.to_shex)
438
437
  assert_equal('800e14000104040a000001000000006430000651c0a800', mpr2.to_shex)
439
-
440
-
438
+
441
439
  assert_equal attr_len(mpr1)+4, attr_len(mpr2)
442
440
 
443
441
  assert_equal('800e1e000104040a0000010030000651c0a80030000661c0a80130000671c0a801', mpr3.to_shex)
@@ -474,6 +472,7 @@ class Mp_reach_Test < Test::Unit::TestCase
474
472
  {:rd=> [100,100], :prefix=> '192.168.1.0/24', :label=>102},
475
473
  {:rd=> [100,100], :prefix=> '192.168.2.0/24', :label=>103},
476
474
  ]
475
+
477
476
  mpr4 = Mp_reach.new :safi=>128, :nexthop=> ['10.0.0.1'], :path_id=> 100, :nlris=> [
478
477
  {:rd=> [100,100], :prefix=> '192.168.0.0/24', :label=>101},
479
478
  {:rd=> [100,100], :prefix=> '192.168.1.0/24', :label=>102},
@@ -527,7 +526,9 @@ class Mp_reach_Test < Test::Unit::TestCase
527
526
  assert_match(/^\s+Label Stack=101 /, mpr.to_s)
528
527
  assert_match(/^\s+Label Stack=102 /, mpr.to_s)
529
528
  assert_match(/^\s+Label Stack=103 /, mpr.to_s)
530
-
529
+
530
+ assert_equal(s.split.join, mpr.to_shex)
531
+
531
532
  s = '80 0e 4a 0001 80 0c 00000000000000000a000001 00 00000065 70 000651 0000006400000064 c0a800
532
533
  00000066 70 000661 0000006400000064 c0a801
533
534
  00000067 70 000671 0000006400000064 c0a802'
@@ -537,6 +538,14 @@ class Mp_reach_Test < Test::Unit::TestCase
537
538
  assert_match(/Label Stack=102.*ID=102, /, mpr.to_s)
538
539
  assert_match(/Label Stack=103.*ID=103, /, mpr.to_s)
539
540
 
541
+ s = '80 0e 3b 0001 80 0c 0000000000000000 0a000001 00 70 000651 0000006400000064 c0a800
542
+ 70 000661 0000006400000064 c0a801
543
+ 58 000671 0000006400000064'
544
+ sbin = [s.split.join].pack('H*')
545
+ mpr = Mp_reach.new(sbin, false)
546
+ assert_equal(s.split.join, mpr.to_shex)
547
+ assert_match(/IPv4=0.0.0.0\/0/, mpr.to_s)
548
+
540
549
  end
541
550
 
542
551
  def test_derive_afi_from_nlris
@@ -554,6 +563,44 @@ class Mp_reach_Test < Test::Unit::TestCase
554
563
  ]))
555
564
  end
556
565
 
566
+ def test_to_hash
567
+
568
+ mpr1 = Mp_reach.new :safi=>128, :nexthop=> ['10.0.0.1'],
569
+ :nlris=> {:rd=> [100,100], :prefix=> '192.168.0.0/24', :label=>101}
570
+ mpr2 = Mp_reach.new :safi=>128, :nexthop=> ['10.0.0.1'],
571
+ :nlris=> {:rd=> [100,100], :prefix=> '192.168.0.0/24', :label=>101, :path_id=>100}
572
+ mpr3 = Mp_reach.new :safi=>128, :nexthop=> ['10.0.0.1'], :nlris=> [
573
+ {:rd=> [100,100], :prefix=> '192.168.0.0/24', :label=>101},
574
+ {:rd=> [100,100], :prefix=> '192.168.1.0/24', :label=>102},
575
+ {:rd=> [100,100], :prefix=> '192.168.2.0/24', :label=>103},
576
+ ]
577
+
578
+ h = {:safi=>128, :nexthop=> ['10.0.0.1'],
579
+ :nlris=> {:rd=> [100,100], :prefix=> '192.168.0.0/24', :label=>101}}
580
+
581
+ assert_equal( 128, mpr1.to_hash[:mp_reach][:safi])
582
+ assert_equal( 1, mpr1.to_hash[:mp_reach][:afi])
583
+ assert_equal( h[:nexthop], mpr1.to_hash[:mp_reach][:nexthop])
584
+ assert_equal( h[:nlris], mpr1.to_hash[:mp_reach][:nlris])
585
+
586
+ h = {:safi=>128, :nexthop=> ['10.0.0.1'], :nlris=> [
587
+ {:rd=> [100,100], :prefix=> '192.168.0.0/24', :label=>101},
588
+ {:rd=> [100,100], :prefix=> '192.168.1.0/24', :label=>102},
589
+ {:rd=> [100,100], :prefix=> '192.168.2.0/24', :label=>103},
590
+ ]}
591
+
592
+ assert_equal( 128, mpr3.to_hash[:mp_reach][:safi])
593
+ assert_equal( 1, mpr3.to_hash[:mp_reach][:afi])
594
+ assert_equal( h[:nexthop], mpr3.to_hash[:mp_reach][:nexthop])
595
+ assert_equal( h[:nlris], mpr3.to_hash[:mp_reach][:nlris])
596
+
597
+
598
+ assert_equal(mpr1.to_hash, Mp_reach.new(mpr1.to_hash[:mp_reach]).to_hash)
599
+ assert_equal(mpr2.to_hash, Mp_reach.new(mpr2.to_hash[:mp_reach]).to_hash)
600
+ assert_equal(mpr3.to_hash, Mp_reach.new(mpr3.to_hash[:mp_reach]).to_hash)
601
+
602
+ end
603
+
557
604
  private
558
605
 
559
606
  def attr_len(attr)
@@ -87,14 +87,16 @@ class Mp_unreach_Test < Test::Unit::TestCase
87
87
  {:prefix=> '192.168.2.0/24', :path_id=> 102},
88
88
  ])
89
89
 
90
+ h = {:safi=>1, :nlris=> '192.168.1.0/24', :afi=>1}
91
+ assert_equal(h, mpr1.to_hash[:mp_unreach])
90
92
 
91
- #
92
- # puts mpr1
93
- # puts mpr2
94
- # puts mpr3
95
- # puts mpr4
96
- # puts mpr5
97
- #
93
+ assert_equal({:safi=>1, :nlris=>{:prefix=>"192.168.1.0/24", :path_id=>100}, :afi=>1}, mpr2.to_hash[:mp_unreach])
94
+
95
+ assert_equal(mpr1.to_hash, Mp_unreach.new(mpr1.to_hash[:mp_unreach]).to_hash)
96
+ assert_equal(mpr2.to_hash, Mp_unreach.new(mpr2.to_hash[:mp_unreach]).to_hash)
97
+ assert_equal(mpr3.to_hash, Mp_unreach.new(mpr3.to_hash[:mp_unreach]).to_hash)
98
+ assert_equal(mpr4.to_hash, Mp_unreach.new(mpr4.to_hash[:mp_unreach]).to_hash)
99
+ assert_equal(mpr5.to_hash, Mp_unreach.new(mpr5.to_hash[:mp_unreach]).to_hash)
98
100
  assert_equal('800f0700010118c0a801', mpr1.to_shex)
99
101
  assert_equal('800f0b0001010000006418c0a801', mpr2.to_shex)
100
102
  assert_equal attr_len(mpr1)+4, attr_len(mpr2)
@@ -34,4 +34,7 @@ class Next_hop_Test < Test::Unit::TestCase
34
34
  next_hop1 = Next_hop.new(next_hop)
35
35
  assert_equal(next_hop.encode, next_hop1.encode)
36
36
  end
37
+ def test_2
38
+ next_hop = Next_hop.new :next_hop=> '10.0.0.1'
39
+ end
37
40
  end
@@ -54,5 +54,6 @@ class Origin_Test < Test::Unit::TestCase
54
54
  assert_equal("[wTcr] (1) Origin: [40010100] 'igp'", Origin.new.to_s)
55
55
  assert_equal("[wTcr] (1) Origin: [40010100] 'igp'", Origin.new(:igp).to_s)
56
56
  assert_equal("Origin (1), length: 1, Flags [T]: igp\n 0x0000: 00", Origin.new.to_s(:tcpdump))
57
+ assert_equal({:origin=>:egp}, Origin.new(:egp).to_hash)
57
58
  end
58
59
  end
@@ -48,8 +48,16 @@ class Path_attribute_Test < Test::Unit::TestCase # :nodoc:
48
48
  BGP::Communities], @pa.has?)
49
49
  assert(@pa.has? Multi_exit_disc)
50
50
  assert(@pa.has? As_path)
51
+ pa = Path_attribute.new { |p|
52
+ p << Origin.new(1)
53
+ p << Next_hop.new('1.1.1.1')
54
+ p << Multi_exit_disc.new(222)
55
+ p << Local_pref.new(333)
56
+ p << As_path.new( :set=> [1,2,3,4], :sequence=> [11,12,13])
57
+ }
58
+ assert_equal([BGP::Origin,BGP::Next_hop,BGP::Multi_exit_disc,BGP::Local_pref,BGP::As_path], pa.has?)
51
59
  end
52
-
60
+
53
61
  def test_2
54
62
  ss = '400101014003040a000001800404000000644005040000006440020c020500010002000300040005c0080c051f00010137003b0af50040'
55
63
  assert_equal(ss, @pa.to_shex)
@@ -153,6 +161,49 @@ class Path_attribute_Test < Test::Unit::TestCase # :nodoc:
153
161
  assert_equal(BGP::Mp_reach, Attr.factory(sbin, :path_id=>true).class)
154
162
  end
155
163
 
164
+ def test_8
165
+
166
+ mp_reach = {:safi=>128, :nexthop=> ['10.0.0.1'], :path_id=> 100, :nlris=> [
167
+ {:rd=> [100,100], :prefix=> '192.168.0.0/24', :label=>101},
168
+ {:rd=> [100,100], :prefix=> '192.168.1.0/24', :label=>102},
169
+ {:rd=> [100,100], :prefix=> '192.168.2.0/24', :label=>103},
170
+ ]}
171
+
172
+ mp_unreach = {:safi=>2, :nlris=>['192.168.1.0/24', '192.168.2.0/24']}
173
+
174
+ p = Path_attribute.new :local_pref=>100,
175
+ :next_hop => '10.0.0.1',
176
+ :med=>300,
177
+ :mp_reach=> mp_reach,
178
+ :mp_unreach=> mp_unreach,
179
+ :origin=> :igp,
180
+ :as_path=> {:set=> [1,2], :sequence=>[3,4], :confed_sequence=>[5,6], :confed_set=>[7,8]},
181
+ :cluster_list=> ['1.1.1.1', '2.2.2.2', '3.3.3.3'],
182
+ :communities=> ["145:30", "145:40", "145:50", "145:60", :no_export, :no_advertise,],
183
+ :extended_communities=> { :color => 100, :link_bandwidth => 999_999_999, :route_origin => ['10.0.1.2', 10], :encapsulation => :ipip },
184
+ :aggregator=> { :address=>'1.1.1.1', :asn=>100 },
185
+ :originator_id=> '2.2.2.2',
186
+ :as4_aggregator=> { :asn=> 200, :address=> '4.4.4.4' },
187
+ :as4_path=> {:set=> [11,12], :sequence=>[13,14], :confed_sequence=>[15,16], :confed_set=>[17,18]},
188
+ :atomic_aggregate=> 1
189
+
190
+ assert p.has?(Origin), "Path attributes should have a Origin attr."
191
+ assert p.has?(Local_pref), "Path attributes should have a Local_pref attr."
192
+ assert p.has?(Next_hop), "Path attributes should have a Next_hop attr."
193
+ assert p.has?(Multi_exit_disc), "Path attributes should have a Multi_exit_disc attr."
194
+ assert p.has?(As_path), "Path attributes should have a As_path attr."
195
+ assert p.has?(As4_path), "Path attributes should have a As4_path attr."
196
+ assert p.has?(As4_aggregator), "Path attributes should have a As4_aggregator attr."
197
+ assert p.has?(Mp_reach), "Path attributes should have a Mp_reach attr."
198
+ assert p.has?(Mp_unreach), "Path attributes should have a Mp_unreach attr."
199
+ assert p.has?(Communities), "Path attributes should have a Communities attr."
200
+ assert p.has?(Extended_communities), "Path attributes should have a Extended_communities attr."
201
+ assert p.has?(Atomic_aggregate), "Path attributes should have a Atomic_aggregate attr."
202
+ assert p.has?(Originator_id), "Path attributes should have a Originator_id attr."
203
+ assert p.has?(Cluster_list), "Path attributes should have a Cluster_list attr."
204
+
205
+ end
206
+
156
207
  def test_path_attribute_path_id_true_and_as4byte_false
157
208
  path_attr = Path_attribute.new
158
209
  path_attr.insert(
@@ -172,6 +223,6 @@ class Path_attribute_Test < Test::Unit::TestCase # :nodoc:
172
223
  # TODO: UT: a path attr with mp_unreach w path_id
173
224
  # TODO: UT: a path attr with mp_reach w path_id and as4
174
225
 
175
- end
226
+ end
176
227
 
177
228
  end
@@ -0,0 +1,33 @@
1
+ require "test/unit"
2
+
3
+ require "bgp/path_attributes/tlvs/tlv"
4
+ require 'bgp/path_attributes/attribute'
5
+
6
+ module BGP
7
+ class MyAttr < Attr
8
+ include TLV
9
+ include STLV
10
+ def initialize(value)
11
+ @flags, @type = OPTIONAL_NON_TRANSITIVE, 55
12
+ @value = value
13
+ @tlv_type=1
14
+ @stlv_type=2
15
+ end
16
+ def encode
17
+ super(@value)
18
+ end
19
+ end
20
+ end
21
+
22
+ class TestBgpPathAttributesTlvsTlv < Test::Unit::TestCase
23
+ include BGP
24
+ def test_1
25
+ attr = MyAttr.new([0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef].pack('N*'))
26
+ assert_equal('803716 0001 0012 02 10 deadbeef deadbeef deadbeef deadbeef'.split.join, attr.to_shex)
27
+ assert_equal(2, attr.stlv_type)
28
+ assert_equal(1, attr.tlv_type)
29
+ end
30
+ end
31
+
32
+
33
+
@@ -0,0 +1,388 @@
1
+ require "test/unit"
2
+ require "bgp/path_attributes/tunnel_encapsulation"
3
+ require 'bgp4r'
4
+ require 'test/helpers/server'
5
+
6
+
7
+ class TestTunnelEncapsulation < Test::Unit::TestCase
8
+ include BGP
9
+
10
+ class TestColor < Test::Unit::TestCase
11
+ include BGP
12
+ def test_case_name
13
+ color = Tunnel_encapsulation::Color.new(10)
14
+ assert_equal('0408030b00000000000a',color.to_shex)
15
+ assert_equal(4, color.stlv_type)
16
+ end
17
+ end
18
+
19
+ class TestProtocolTYpe < Test::Unit::TestCase
20
+ include BGP
21
+ def test_case_name
22
+ protocol_type = Tunnel_encapsulation::Protocol_type.new :ipv4
23
+ assert_equal('02020800', protocol_type.to_shex)
24
+ assert_equal(2, protocol_type.stlv_type)
25
+ assert_equal('020286dd', Tunnel_encapsulation::Protocol_type.new(:ipv6).to_shex)
26
+ assert_equal('02028847', Tunnel_encapsulation::Protocol_type.new(:mpls).to_shex)
27
+ end
28
+ end
29
+
30
+ class TestEncapsulationGre < Test::Unit::TestCase
31
+ include BGP
32
+ def test_case_name
33
+ encap = Tunnel_encapsulation::Encap_gre.new(0x12345678)
34
+ assert_equal('010412345678', encap.to_shex)
35
+ end
36
+ end
37
+
38
+ class TestEncapsulationL2tpv3 < Test::Unit::TestCase
39
+ include BGP
40
+ def test_case_name
41
+ encap = Tunnel_encapsulation::Encap_l2tpv3.new(0x1234, '1234567890123456789')
42
+ assert_equal('010e0000123412345678901234567890', encap.to_shex)
43
+ end
44
+ end
45
+
46
+ class TestTunnel < Test::Unit::TestCase
47
+ include BGP
48
+ def test_case_name
49
+ tlv = Tunnel_encapsulation::Tunnel.new(:tunnel_type=> :l2tpv3, :session_id=> 1, :cookie=> 'ffddeeaabb11ee3344', :proto_type=> :ipv4, :color=> 1234)
50
+ assert_equal('0001001d010d00000001ffddeeaabb11ee3344020208000408030b0000000004d2', tlv.to_shex)
51
+ end
52
+ end
53
+
54
+
55
+ def test_case_name
56
+ tunnel_encap = Tunnel_encapsulation.new
57
+ assert_equal('c01700', tunnel_encap.to_shex)
58
+ tunnel_encap.add :tunnel_type=> :l2tpv3, :session_id=> 1, :coockie=> 0x1234, :proto_type=> :ipv4, :color=> 1234
59
+ assert_equal('c01718 0001 0014 01 04 00000001 02 02 0800 04 08 030b0000000004d2'.split.join, tunnel_encap.to_shex)
60
+ tunnel_encap.add :tunnel_type=> :l2tpv3, :session_id=> 2, :coockie=> 0x1234, :proto_type=> :ipv6, :color=> 1234
61
+ assert_equal('c0173000010014010400000001020208000408030b0000000004d200010014010400000002020286dd0408030b0000000004d2'.split.join, tunnel_encap.to_shex)
62
+ tunnel_encap.add :tunnel_type=> :l2tpv3, :session_id=> 3, :coockie=> 0x1234, :proto_type=> :mpls, :color=> 1234
63
+ assert_equal('c0174800010014010400000001020208000408030b0000000004d200010014010400000002020286dd0408030b0000000004d200010014010400000003020288470408030b0000000004d2'.split.join, tunnel_encap.to_shex)
64
+ tunnel_encap.add :tunnel_type=> :gre, :key=> 0x12345678
65
+ assert_equal('c0175200010014010400000001020208000408030b0000000004d200010014010400000002020286dd0408030b0000000004d200010014010400000003020288470408030b0000000004d200020006010412345678', tunnel_encap.to_shex)
66
+ end
67
+ include BGP::TestHelpers
68
+
69
+ # def teardown
70
+ # stop_server
71
+ # end
72
+
73
+ # def test_send_update_with_tunnel_encap_attribute
74
+ #
75
+ # start_server(179)
76
+ #
77
+ # @c = Neighbor.new(4, 100, 180, '0.0.0.2', '127.0.0.1', '127.0.0.1')
78
+ # @c.start :port=> 179
79
+ # assert_equal('Established', @c.state)
80
+ # assert_equal('Established', @s.state)
81
+ #
82
+ # tunnel_encap = Tunnel_encapsulation.new
83
+ # tunnel_encap.add :tunnel_type=> :l2tpv3, :session_id=> 1, :coockie=> 0x1234, :proto_type=> :ipv4, :color=> 1234
84
+ # tunnel_encap.add :tunnel_type=> :l2tpv3, :session_id=> 2, :coockie=> 0x1234, :proto_type=> :ipv6, :color=> 1234
85
+ # tunnel_encap.add :tunnel_type=> :l2tpv3, :session_id=> 3, :coockie=> 0x1234, :proto_type=> :mpls, :color=> 1234
86
+ # tunnel_encap.add :tunnel_type=> :gre, :key=> 0x12345678
87
+ #
88
+ # u = Update.new
89
+ # u << tunnel_encap
90
+ #
91
+ # @c.send_message u
92
+ # @c.send_message u
93
+ # @c.send_message u
94
+ # @c.send_message u
95
+ # @c.send_message u
96
+ # sleep 2
97
+ #
98
+ # end
99
+
100
+
101
+
102
+ end
103
+
104
+
105
+ __END__
106
+
107
+ tunnels=[]
108
+
109
+
110
+
111
+
112
+ Tunnel Type
113
+ L2TPV3 =1
114
+ GRE = 2
115
+ IPIP = 7
116
+
117
+
118
+ tunnel_encap attr:
119
+
120
+ tlv type 1:
121
+ value:
122
+ stlv-type 1 : session_id + coockie
123
+ stlv-proto-type 2 : ipv4 0x0800
124
+ stlv-color 4 : 0x1234
125
+
126
+
127
+ tlv type 1:
128
+ value:
129
+ stlv-type 1: session_id + coockie
130
+ stlv-proto-type 2 : ipv6 0x86dd
131
+ stlv-color 4 : 0x1234
132
+
133
+ tlv type 1:
134
+ value:
135
+ stlv-type 1: session_id + coockie
136
+ stlv-proto-type 2 : mpls 0x8847
137
+ stlv-color 4 : 0x1234
138
+
139
+
140
+
141
+ tlv type 2: (gre)
142
+ value:
143
+ stlv-type 1: gre key (4)
144
+
145
+
146
+
147
+
148
+
149
+
150
+ sub-tlv: session_id + coockie
151
+
152
+
153
+ For example, if we want to use three L2TPv3 sessions, one carrying
154
+ IPv4 packets, one carrying IPv6 packets, and one carrying MPLS
155
+ packets, the egress router will include three TLVs of L2TPv3
156
+ encapsulation type, each specifying a different Session ID and a
157
+ different payload type. The protocol type sub-TLV for these will be
158
+ IPv4 (protocol type = 0x0800), IPv6 (protocol type = 0x86dd), and
159
+ MPLS (protocol type = 0x8847), respectively. This informs the
160
+ ingress routers of the appropriate encapsulation information to use
161
+ with each of the given protocol types. Insertion of the specified
162
+ Session ID at the ingress routers allows the egress to process the
163
+ incoming packets correctly, according to their protocol type.
164
+
165
+
166
+
167
+ TLVs
168
+
169
+ L2TPv3 type = 1
170
+ GRE = 2
171
+ IP in IP = 7
172
+
173
+ Sub-TLVs
174
+
175
+ - Encapsulation: sub-TLV type = 1
176
+
177
+ encap_l2tpv3 : session_id(4) + coockie(v)
178
+ encap_gre: key(4)
179
+
180
+ - Protocol type: sub-TLV tye =2
181
+
182
+ ethertype(2)
183
+
184
+ For example, if we want to use three L2TPv3 sessions, one carrying
185
+ IPv4 packets, one carrying IPv6 packets, and one carrying MPLS
186
+ packets, the egress router will include three TLVs of L2TPv3
187
+ encapsulation type, each specifying a different Session ID and a
188
+ different payload type. The protocol type sub-TLV for these will be
189
+ IPv4 (protocol type = 0x0800), IPv6 (protocol type = 0x86dd), and
190
+ MPLS (protocol type = 0x8847), respectively. This informs the
191
+ ingress routers of the appropriate encapsulation information to use
192
+ with each of the given protocol types. Insertion of the specified
193
+ Session ID at the ingress routers allows the egress to process the
194
+ incoming packets correctly, according to their protocol type.
195
+
196
+ Inclusion of this sub-TLV depends on the tunnel type. It MUST be
197
+ encoded for L2TPv3 tunnel type. On the other hand, the protocol type
198
+ sub-TLV is not required for IP in IP or GRE tunnels.
199
+
200
+
201
+ - Protocol type: sub-TLV type = 2
202
+ - Color: sub-TLV type = 4
203
+
204
+
205
+
206
+ 4. Tunnel Encapsulation Attribute
207
+
208
+ The Tunnel Encapsulation attribute is an optional transitive
209
+ attribute that is composed of a set of Type-Length-Value (TLV)
210
+ encodings. The type code of the attribute is 23. Each TLV contains
211
+ information corresponding to a particular tunnel technology. The TLV
212
+ is structured as follows:
213
+
214
+ 0 1 2 3
215
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
216
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
217
+ | Tunnel Type (2 Octets) | Length (2 Octets) |
218
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
219
+ | |
220
+ | Value |
221
+ | |
222
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
223
+
224
+ * Tunnel Type (2 octets): identifies the type of tunneling technology
225
+ being signaled. This document defines the following types:
226
+
227
+ - L2TPv3 over IP [RFC3931]: Tunnel Type = 1
228
+ - GRE [RFC2784]: Tunnel Type = 2
229
+ - IP in IP [RFC2003] [RFC4213]: Tunnel Type = 7
230
+
231
+ Unknown types are to be ignored and skipped upon receipt.
232
+
233
+ * Length (2 octets): the total number of octets of the value field.
234
+
235
+ * Value (variable): comprised of multiple sub-TLVs. Each sub-TLV
236
+ consists of three fields: a 1-octet type, 1-octet length, and zero
237
+ or more octets of value. The sub-TLV is structured as follows:
238
+
239
+
240
+
241
+
242
+ Mohapatra & Rosen Standards Track [Page 5]
243
+
244
+ RFC 5512 BGP Encapsulation SAFI and Tunnel Encapsulation April 2009
245
+
246
+
247
+ +-----------------------------------+
248
+ | Sub-TLV Type (1 Octet) |
249
+ +-----------------------------------+
250
+ | Sub-TLV Length (1 Octet) |
251
+ +-----------------------------------+
252
+ | Sub-TLV Value (Variable) |
253
+ | |
254
+ +-----------------------------------+
255
+
256
+ * Sub-TLV Type (1 octet): each sub-TLV type defines a certain
257
+ property about the tunnel TLV that contains this sub-TLV. The
258
+ following are the types defined in this document:
259
+
260
+ - Encapsulation: sub-TLV type = 1
261
+ - Protocol type: sub-TLV type = 2
262
+ - Color: sub-TLV type = 4
263
+
264
+ When the TLV is being processed by a BGP speaker that will be
265
+ performing encapsulation, any unknown sub-TLVs MUST be ignored and
266
+ skipped. However, if the TLV is understood, the entire TLV MUST
267
+ NOT be ignored just because it contains an unknown sub-TLV.
268
+
269
+ * Sub-TLV Length (1 octet): the total number of octets of the sub-TLV
270
+ value field.
271
+
272
+ * Sub-TLV Value (variable): encodings of the value field depend on
273
+ the sub-TLV type as enumerated above. The following sub-sections
274
+ define the encoding in detail.
275
+
276
+ 4.1. Encapsulation Sub-TLV
277
+
278
+ The syntax and semantics of the encapsulation sub-TLV is determined
279
+ by the tunnel type of the TLV that contains this sub-TLV.
280
+
281
+ When the tunnel type of the TLV is L2TPv3 over IP, the following is
282
+ the structure of the value field of the encapsulation sub-TLV:
283
+
284
+ 0 1 2 3
285
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
286
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
287
+ | Session ID (4 octets) |
288
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
289
+ | |
290
+ | Cookie (Variable) |
291
+ | |
292
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
293
+
294
+
295
+
296
+
297
+
298
+ Mohapatra & Rosen Standards Track [Page 6]
299
+
300
+ RFC 5512 BGP Encapsulation SAFI and Tunnel Encapsulation April 2009
301
+
302
+
303
+ * Session ID: a non-zero 4-octet value locally assigned by the
304
+ advertising router that serves as a lookup key in the incoming
305
+ packet's context.
306
+
307
+ * Cookie: an optional, variable length (encoded in octets -- 0 to 8
308
+ octets) value used by L2TPv3 to check the association of a received
309
+ data message with the session identified by the Session ID.
310
+ Generation and usage of the cookie value is as specified in
311
+ [RFC3931].
312
+
313
+ The length of the cookie is not encoded explicitly, but can be
314
+ calculated as (sub-TLV length - 4).
315
+
316
+ When the tunnel type of the TLV is GRE, the following is the
317
+ structure of the value field of the encapsulation sub-TLV:
318
+
319
+ 0 1 2 3
320
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
321
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
322
+ | GRE Key (4 octets) |
323
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
324
+
325
+ * GRE Key: 4-octet field [RFC2890] that is generated by the
326
+ advertising router. The actual method by which the key is obtained
327
+ is beyond the scope of this document. The key is inserted into the
328
+ GRE encapsulation header of the payload packets sent by ingress
329
+ routers to the advertising router. It is intended to be used for
330
+ identifying extra context information about the received payload.
331
+
332
+ Note that the key is optional. Unless a key value is being
333
+ advertised, the GRE encapsulation sub-TLV MUST NOT be present.
334
+
335
+ 4.2. Protocol Type Sub-TLV
336
+
337
+ The protocol type sub-TLV MAY be encoded to indicate the type of the
338
+ payload packets that will be encapsulated with the tunnel parameters
339
+ that are being signaled in the TLV. The value field of the sub-TLV
340
+ contains a 2-octet protocol type that is one of the types defined in
341
+ [IANA-AF] as ETHER TYPEs.
342
+
343
+ For example, if we want to use three L2TPv3 sessions, one carrying
344
+ IPv4 packets, one carrying IPv6 packets, and one carrying MPLS
345
+ packets, the egress router will include three TLVs of L2TPv3
346
+ encapsulation type, each specifying a different Session ID and a
347
+ different payload type. The protocol type sub-TLV for these will be
348
+ IPv4 (protocol type = 0x0800), IPv6 (protocol type = 0x86dd), and
349
+ MPLS (protocol type = 0x8847), respectively. This informs the
350
+ ingress routers of the appropriate encapsulation information to use
351
+ with each of the given protocol types. Insertion of the specified
352
+ Session ID at the ingress routers allows the egress to process the
353
+ incoming packets correctly, according to their protocol type.
354
+
355
+ Inclusion of this sub-TLV depends on the tunnel type. It MUST be
356
+ encoded for L2TPv3 tunnel type. On the other hand, the protocol type
357
+ sub-TLV is not required for IP in IP or GRE tunnels.
358
+
359
+ 4.3. Color Sub-TLV
360
+
361
+ The color sub-TLV MAY be encoded as a way to color the corresponding
362
+ tunnel TLV. The value field of the sub-TLV contains an extended
363
+ community that is defined as follows:
364
+
365
+ 4.3.1. Color Extended Community
366
+
367
+ The Color Extended Community is an opaque extended community
368
+ [RFC4360] with the following encoding:
369
+
370
+ 0 1 2 3
371
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
372
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
373
+ | 0x03 | 0x0b | Reserved |
374
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
375
+ | Color Value |
376
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
377
+
378
+ The value of the high-order octet of the extended type field is 0x03,
379
+ which indicates it is transitive. The value of the low-order octet
380
+ of the extended type field for this community is 0x0b. The color
381
+ value is user defined and configured locally on the routers. The
382
+ same Color Extended Community can then be attached to the UPDATE
383
+ messages that contain payload prefixes. This way, the BGP speaker
384
+ can express the fact that it expects the packets corresponding to
385
+ these payload prefixes to be received with a particular tunnel
386
+ encapsulation header.
387
+
388
+