jesnault-bgp4r 0.0.2 → 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.
- data/bgp/aggregator.rb +104 -0
 - data/bgp/as_path.rb +223 -0
 - data/bgp/atomic_aggregate.rb +42 -0
 - data/bgp/attribute.rb +181 -0
 - data/bgp/attributes.rb +34 -0
 - data/bgp/cluster_list.rb +117 -0
 - data/bgp/common.rb +204 -0
 - data/bgp/communities.rb +139 -0
 - data/bgp/extended_communities.rb +107 -0
 - data/bgp/extended_community.rb +254 -0
 - data/bgp/iana.rb +269 -0
 - data/bgp/io.rb +116 -0
 - data/bgp/label.rb +94 -0
 - data/bgp/local_pref.rb +75 -0
 - data/bgp/message.rb +894 -0
 - data/bgp/mp_reach.rb +208 -0
 - data/bgp/multi_exit_disc.rb +76 -0
 - data/bgp/neighbor.rb +291 -0
 - data/bgp/next_hop.rb +63 -0
 - data/bgp/nlri.rb +303 -0
 - data/bgp/orf.rb +88 -0
 - data/bgp/origin.rb +88 -0
 - data/bgp/originator_id.rb +73 -0
 - data/bgp/path_attribute.rb +210 -0
 - data/bgp/prefix_orf.rb +263 -0
 - data/bgp/rd.rb +107 -0
 - data/examples/bgp +65 -0
 - data/examples/routegen +85 -0
 - data/examples/routegen.yml +50 -0
 - data/test/aggregator_test.rb +66 -0
 - data/test/as_path_test.rb +149 -0
 - data/test/atomic_aggregate_test.rb +35 -0
 - data/test/attribute_test.rb +57 -0
 - data/test/cluster_list_test.rb +39 -0
 - data/test/common_test.rb +68 -0
 - data/test/communities_test.rb +75 -0
 - data/test/extended_communities_test.rb +111 -0
 - data/test/extended_community_test.rb +93 -0
 - data/test/label_test.rb +50 -0
 - data/test/local_pref_test.rb +43 -0
 - data/test/message_test.rb +294 -0
 - data/test/mp_reach_test.rb +143 -0
 - data/test/multi_exit_disc_test.rb +46 -0
 - data/test/neighbor_test.rb +50 -0
 - data/test/next_hop_test.rb +37 -0
 - data/test/nlri_test.rb +189 -0
 - data/test/origin_test.rb +57 -0
 - data/test/originator_id_test.rb +38 -0
 - data/test/path_attribute_test.rb +127 -0
 - data/test/prefix_orf_test.rb +97 -0
 - data/test/rd_test.rb +44 -0
 - metadata +84 -11
 
    
        data/bgp/iana.rb
    ADDED
    
    | 
         @@ -0,0 +1,269 @@ 
     | 
|
| 
      
 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 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
            module IANA
         
     | 
| 
      
 25 
     | 
    
         
            +
              def self.afi(afi)
         
     | 
| 
      
 26 
     | 
    
         
            +
                case afi
         
     | 
| 
      
 27 
     | 
    
         
            +
                when AFI::IP   ; 'IPv4'
         
     | 
| 
      
 28 
     | 
    
         
            +
                when AFI::IP6  ; 'IPv6'
         
     | 
| 
      
 29 
     | 
    
         
            +
                else
         
     | 
| 
      
 30 
     | 
    
         
            +
                  ''
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
      
 32 
     | 
    
         
            +
              end
         
     | 
| 
      
 33 
     | 
    
         
            +
              def self.safi(safi)
         
     | 
| 
      
 34 
     | 
    
         
            +
                case safi
         
     | 
| 
      
 35 
     | 
    
         
            +
                when SAFI::UNICAST_NLRI       ; 'Unicast'
         
     | 
| 
      
 36 
     | 
    
         
            +
                when SAFI::MULTICAST_NLRI     ; 'Multicast'
         
     | 
| 
      
 37 
     | 
    
         
            +
                when SAFI::LABEL_NLRI         ; 'Labeled NLRI'
         
     | 
| 
      
 38 
     | 
    
         
            +
                when SAFI::MCAST_VPN          ; 'Multicast VPN'
         
     | 
| 
      
 39 
     | 
    
         
            +
                when SAFI::MPLS_VPN_UNICAST   ; 'Labeled VPN Unicast'
         
     | 
| 
      
 40 
     | 
    
         
            +
                when SAFI::MPLS_VPN_Multicast ; 'Labeled VPN Multicast'
         
     | 
| 
      
 41 
     | 
    
         
            +
                else
         
     | 
| 
      
 42 
     | 
    
         
            +
                  ''
         
     | 
| 
      
 43 
     | 
    
         
            +
                end
         
     | 
| 
      
 44 
     | 
    
         
            +
              end
         
     | 
| 
      
 45 
     | 
    
         
            +
              module AFI
         
     | 
| 
      
 46 
     | 
    
         
            +
                IP = 1
         
     | 
| 
      
 47 
     | 
    
         
            +
                IP6 = 2 
         
     | 
| 
      
 48 
     | 
    
         
            +
                NSAP = 3
         
     | 
| 
      
 49 
     | 
    
         
            +
                HDLC = 4
         
     | 
| 
      
 50 
     | 
    
         
            +
                BBN = 5
         
     | 
| 
      
 51 
     | 
    
         
            +
                IEEE_802 = 6
         
     | 
| 
      
 52 
     | 
    
         
            +
                E163 = 7
         
     | 
| 
      
 53 
     | 
    
         
            +
                E164 = 8
         
     | 
| 
      
 54 
     | 
    
         
            +
                F69 = 9
         
     | 
| 
      
 55 
     | 
    
         
            +
                X121 = 10
         
     | 
| 
      
 56 
     | 
    
         
            +
                IPX = 11
         
     | 
| 
      
 57 
     | 
    
         
            +
                Appletalk = 12
         
     | 
| 
      
 58 
     | 
    
         
            +
                Decnet_IV = 13
         
     | 
| 
      
 59 
     | 
    
         
            +
                Banyan_Vines = 14
         
     | 
| 
      
 60 
     | 
    
         
            +
                E164_NSAP = 15
         
     | 
| 
      
 61 
     | 
    
         
            +
                DNS = 16
         
     | 
| 
      
 62 
     | 
    
         
            +
                Distinguished_Name = 17
         
     | 
| 
      
 63 
     | 
    
         
            +
                AS_Number = 18
         
     | 
| 
      
 64 
     | 
    
         
            +
                XTPv4 = 19
         
     | 
| 
      
 65 
     | 
    
         
            +
                XTPv6 = 20
         
     | 
| 
      
 66 
     | 
    
         
            +
                XTP = 21
         
     | 
| 
      
 67 
     | 
    
         
            +
                FCWWPN = 22
         
     | 
| 
      
 68 
     | 
    
         
            +
                FCWWNN = 23
         
     | 
| 
      
 69 
     | 
    
         
            +
                GWID = 24
         
     | 
| 
      
 70 
     | 
    
         
            +
                L2VPN = 25
         
     | 
| 
      
 71 
     | 
    
         
            +
              end  
         
     | 
| 
      
 72 
     | 
    
         
            +
              module SAFI
         
     | 
| 
      
 73 
     | 
    
         
            +
                UNICAST_NLRI = 1
         
     | 
| 
      
 74 
     | 
    
         
            +
                MULTICAST_NLRI = 2
         
     | 
| 
      
 75 
     | 
    
         
            +
                LABEL_NLRI = 4
         
     | 
| 
      
 76 
     | 
    
         
            +
                MCAST_VPN = 5
         
     | 
| 
      
 77 
     | 
    
         
            +
                MULTI_SEGMENT_PW_NLRI = 6
         
     | 
| 
      
 78 
     | 
    
         
            +
                ENCASPSULATION_SAFI = 7
         
     | 
| 
      
 79 
     | 
    
         
            +
                TUNNEL = 64
         
     | 
| 
      
 80 
     | 
    
         
            +
                VPLS = 65
         
     | 
| 
      
 81 
     | 
    
         
            +
                BGP_MDT = 66
         
     | 
| 
      
 82 
     | 
    
         
            +
                BGP4over6 = 67
         
     | 
| 
      
 83 
     | 
    
         
            +
                BGP6over4 = 68
         
     | 
| 
      
 84 
     | 
    
         
            +
                L1_VPN_AUTO_DISCOVERY = 69
         
     | 
| 
      
 85 
     | 
    
         
            +
                MPLS_VPN_UNICAST = 128
         
     | 
| 
      
 86 
     | 
    
         
            +
                MPLS_VPN_Multicast = 129
         
     | 
| 
      
 87 
     | 
    
         
            +
                ROUTE_TARGET_CONSTRAINTS = 132
         
     | 
| 
      
 88 
     | 
    
         
            +
                FLOW_SPEC_RULES_1 = 133
         
     | 
| 
      
 89 
     | 
    
         
            +
                FLOW_SPEC_RULES_2 = 134
         
     | 
| 
      
 90 
     | 
    
         
            +
                VPN_AUTO_DISCOVERY = 140
         
     | 
| 
      
 91 
     | 
    
         
            +
              end
         
     | 
| 
      
 92 
     | 
    
         
            +
            end
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
            __END__
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
            http://www.iana.org/assignments/address-family-numbers/
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
            Registry:
         
     | 
| 
      
 101 
     | 
    
         
            +
            Number       Description                                                       Reference
         
     | 
| 
      
 102 
     | 
    
         
            +
            ----------   ----------------------------------------------------------------  -----------------
         
     | 
| 
      
 103 
     | 
    
         
            +
            0            Reserved
         
     | 
| 
      
 104 
     | 
    
         
            +
            1            IP (IP version 4)
         
     | 
| 
      
 105 
     | 
    
         
            +
            2            IP6 (IP version 6)
         
     | 
| 
      
 106 
     | 
    
         
            +
            3            NSAP
         
     | 
| 
      
 107 
     | 
    
         
            +
            4            HDLC (8-bit multidrop)
         
     | 
| 
      
 108 
     | 
    
         
            +
            5            BBN 1822
         
     | 
| 
      
 109 
     | 
    
         
            +
            6            802 (includes all 802 media plus Ethernet "canonical format")
         
     | 
| 
      
 110 
     | 
    
         
            +
            7            E.163
         
     | 
| 
      
 111 
     | 
    
         
            +
            8            E.164 (SMDS, Frame Relay, ATM)
         
     | 
| 
      
 112 
     | 
    
         
            +
            9            F.69 (Telex)
         
     | 
| 
      
 113 
     | 
    
         
            +
            10           X.121 (X.25, Frame Relay)
         
     | 
| 
      
 114 
     | 
    
         
            +
            11           IPX
         
     | 
| 
      
 115 
     | 
    
         
            +
            12           Appletalk
         
     | 
| 
      
 116 
     | 
    
         
            +
            13           Decnet IV
         
     | 
| 
      
 117 
     | 
    
         
            +
            14           Banyan Vines
         
     | 
| 
      
 118 
     | 
    
         
            +
            15           E.164 with NSAP format subaddress                                 [UNI-3.1][Malis]
         
     | 
| 
      
 119 
     | 
    
         
            +
            16           DNS (Domain Name System)
         
     | 
| 
      
 120 
     | 
    
         
            +
            17           Distinguished Name                                                [Lynn]
         
     | 
| 
      
 121 
     | 
    
         
            +
            18           AS Number                                                         [Lynn]
         
     | 
| 
      
 122 
     | 
    
         
            +
            19           XTP over IP version 4                                             [Saul] 
         
     | 
| 
      
 123 
     | 
    
         
            +
            20           XTP over IP version 6                                             [Saul]
         
     | 
| 
      
 124 
     | 
    
         
            +
            21           XTP native mode XTP                                               [Saul]
         
     | 
| 
      
 125 
     | 
    
         
            +
            22           Fibre Channel World-Wide Port Name                                [Bakke]
         
     | 
| 
      
 126 
     | 
    
         
            +
            23           Fibre Channel World-Wide Node Name                                [Bakke]
         
     | 
| 
      
 127 
     | 
    
         
            +
            24           GWID                                                              [Hegde]
         
     | 
| 
      
 128 
     | 
    
         
            +
            25           AFI for L2VPN information                                         [RFC4761]
         
     | 
| 
      
 129 
     | 
    
         
            +
            26-16383     Unassigned
         
     | 
| 
      
 130 
     | 
    
         
            +
            16384        EIGRP Common Service Family                                       [Savage]
         
     | 
| 
      
 131 
     | 
    
         
            +
            16385        EIGRP IPv4 Service Family                                         [Savage]
         
     | 
| 
      
 132 
     | 
    
         
            +
            16386        EIGRP IPv6 Service Family                                         [Savage]
         
     | 
| 
      
 133 
     | 
    
         
            +
            16387-32767  Unassigned
         
     | 
| 
      
 134 
     | 
    
         
            +
            32768-65534  Unassigned
         
     | 
| 
      
 135 
     | 
    
         
            +
            65535        Reserved
         
     | 
| 
      
 136 
     | 
    
         
            +
             
     | 
| 
      
 137 
     | 
    
         
            +
             
     | 
| 
      
 138 
     | 
    
         
            +
            http://www.iana.org/assignments/safi-namespace
         
     | 
| 
      
 139 
     | 
    
         
            +
             
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
            Registries included below
         
     | 
| 
      
 142 
     | 
    
         
            +
            - SAFI Values
         
     | 
| 
      
 143 
     | 
    
         
            +
             
     | 
| 
      
 144 
     | 
    
         
            +
             
     | 
| 
      
 145 
     | 
    
         
            +
            Registry Name: SAFI Values
         
     | 
| 
      
 146 
     | 
    
         
            +
            Reference: [RFC4760]
         
     | 
| 
      
 147 
     | 
    
         
            +
            Range      Registration Procedures                              Note
         
     | 
| 
      
 148 
     | 
    
         
            +
            ---------  ---------------------------------------------------  --------------------
         
     | 
| 
      
 149 
     | 
    
         
            +
            1-63       Standards Action or Early Allocation policy
         
     | 
| 
      
 150 
     | 
    
         
            +
            64-127     First Come First Served
         
     | 
| 
      
 151 
     | 
    
         
            +
            128-240    Some recognized assignments below, others Reserved 
         
     | 
| 
      
 152 
     | 
    
         
            +
            241-254    Reserved for Private Use                             Not to be assigned
         
     | 
| 
      
 153 
     | 
    
         
            +
             
     | 
| 
      
 154 
     | 
    
         
            +
            Registry:
         
     | 
| 
      
 155 
     | 
    
         
            +
            Value    Description                                     Reference
         
     | 
| 
      
 156 
     | 
    
         
            +
            -------  ----------------------------------------------  ---------
         
     | 
| 
      
 157 
     | 
    
         
            +
            0        Reserved                                        [RFC4760]
         
     | 
| 
      
 158 
     | 
    
         
            +
             
     | 
| 
      
 159 
     | 
    
         
            +
            1        Network Layer Reachability Information used     [RFC4760]
         
     | 
| 
      
 160 
     | 
    
         
            +
                     for unicast forwarding	
         
     | 
| 
      
 161 
     | 
    
         
            +
             
     | 
| 
      
 162 
     | 
    
         
            +
            2        Network Layer Reachability Information used     [RFC4760] 
         
     | 
| 
      
 163 
     | 
    
         
            +
                     for multicast forwarding
         
     | 
| 
      
 164 
     | 
    
         
            +
            	
         
     | 
| 
      
 165 
     | 
    
         
            +
            3        Reserved                                        [RFC4760]
         
     | 
| 
      
 166 
     | 
    
         
            +
             
     | 
| 
      
 167 
     | 
    
         
            +
            4        Network Layer Reachability Information (NLRI)   [RFC3107]
         
     | 
| 
      
 168 
     | 
    
         
            +
                     with MPLS Labels
         
     | 
| 
      
 169 
     | 
    
         
            +
             
     | 
| 
      
 170 
     | 
    
         
            +
            5        MCAST-VPN                                       [draft-ietf-l3vpn-2547bis-mcast-bgp]
         
     | 
| 
      
 171 
     | 
    
         
            +
                     (TEMPORARY - Expires 2009-06-19)
         
     | 
| 
      
 172 
     | 
    
         
            +
             
     | 
| 
      
 173 
     | 
    
         
            +
            6        Network Layer Reachability Information used     [draft-ietf-pwe3-dynamic-ms-pw]
         
     | 
| 
      
 174 
     | 
    
         
            +
                     for Dynamic Placement of Multi-Segment
         
     | 
| 
      
 175 
     | 
    
         
            +
                     Pseudowires
         
     | 
| 
      
 176 
     | 
    
         
            +
                     (TEMPORARY - Expires 2009-08-23)
         
     | 
| 
      
 177 
     | 
    
         
            +
             
     | 
| 
      
 178 
     | 
    
         
            +
            7        Encapsulation SAFI                              [RFC-ietf-softwire-encaps-safi-05.txt]
         
     | 
| 
      
 179 
     | 
    
         
            +
             
     | 
| 
      
 180 
     | 
    
         
            +
            8-63     Unassigned
         
     | 
| 
      
 181 
     | 
    
         
            +
             
     | 
| 
      
 182 
     | 
    
         
            +
            64       Tunnel SAFI                                     [Nalawade]
         
     | 
| 
      
 183 
     | 
    
         
            +
             
     | 
| 
      
 184 
     | 
    
         
            +
            65       Virtual Private LAN Service (VPLS)              [RFC4761]
         
     | 
| 
      
 185 
     | 
    
         
            +
             
     | 
| 
      
 186 
     | 
    
         
            +
            66       BGP MDT SAFI                                    [Nalawade]
         
     | 
| 
      
 187 
     | 
    
         
            +
             
     | 
| 
      
 188 
     | 
    
         
            +
            67       BGP 4over6 SAFI                                 [Cui]
         
     | 
| 
      
 189 
     | 
    
         
            +
             
     | 
| 
      
 190 
     | 
    
         
            +
            68       BGP 6over4 SAFI                                 [Cui]
         
     | 
| 
      
 191 
     | 
    
         
            +
             
     | 
| 
      
 192 
     | 
    
         
            +
            69       Layer-1 VPN auto-discovery information          [RFC-ietf-l1vpn-bgp-auto-discovery-05.txt]
         
     | 
| 
      
 193 
     | 
    
         
            +
             
     | 
| 
      
 194 
     | 
    
         
            +
            70-127   Unassigned 
         
     | 
| 
      
 195 
     | 
    
         
            +
             
     | 
| 
      
 196 
     | 
    
         
            +
            128      MPLS-labeled VPN address                        [RFC4364]
         
     | 
| 
      
 197 
     | 
    
         
            +
             
     | 
| 
      
 198 
     | 
    
         
            +
            129      Multicast for BGP/MPLS IP Virtual Private       [RFC2547]
         
     | 
| 
      
 199 
     | 
    
         
            +
                     Networks (VPNs)
         
     | 
| 
      
 200 
     | 
    
         
            +
             
     | 
| 
      
 201 
     | 
    
         
            +
            130-131  Reserved                                        [RFC4760]
         
     | 
| 
      
 202 
     | 
    
         
            +
             
     | 
| 
      
 203 
     | 
    
         
            +
            132      Route Target constrains                         [RFC4684]
         
     | 
| 
      
 204 
     | 
    
         
            +
             
     | 
| 
      
 205 
     | 
    
         
            +
            133      Dissemination of flow specification rules       [draft-marques-idr-flow-spec]
         
     | 
| 
      
 206 
     | 
    
         
            +
             
     | 
| 
      
 207 
     | 
    
         
            +
            134      Dissemination of flow specification rules       [draft-marques-idr-flow-spec]
         
     | 
| 
      
 208 
     | 
    
         
            +
             
     | 
| 
      
 209 
     | 
    
         
            +
            135-139  Reserved                                        [RFC4760]
         
     | 
| 
      
 210 
     | 
    
         
            +
             
     | 
| 
      
 211 
     | 
    
         
            +
            140      VPN auto-discovery                              [draft-ietf-l3vpn-bgpvpn-auto]
         
     | 
| 
      
 212 
     | 
    
         
            +
             
     | 
| 
      
 213 
     | 
    
         
            +
            141-240  Reserved                                        [RFC4760]
         
     | 
| 
      
 214 
     | 
    
         
            +
             
     | 
| 
      
 215 
     | 
    
         
            +
            241-254  Private Use                                     [RFC4760]
         
     | 
| 
      
 216 
     | 
    
         
            +
             
     | 
| 
      
 217 
     | 
    
         
            +
            255      Reserved                                        [RFC4760]
         
     | 
| 
      
 218 
     | 
    
         
            +
             
     | 
| 
      
 219 
     | 
    
         
            +
             
     | 
| 
      
 220 
     | 
    
         
            +
            References
         
     | 
| 
      
 221 
     | 
    
         
            +
            ----------
         
     | 
| 
      
 222 
     | 
    
         
            +
            [RFC2547]  E. Rosen and Y. Rekhter, "BGP/MPLS VPNs", RFC 2547, March 1999.
         
     | 
| 
      
 223 
     | 
    
         
            +
             
     | 
| 
      
 224 
     | 
    
         
            +
            [RFC3107]  Y. Rekhter and E. Rosen, "Carrying Label Information in 
         
     | 
| 
      
 225 
     | 
    
         
            +
                       BGP-4", RFC 3107, May 2001.
         
     | 
| 
      
 226 
     | 
    
         
            +
             
     | 
| 
      
 227 
     | 
    
         
            +
            [RFC4364]  E. Rosen and Y. Rekhter, "BGP/MPLS IP VPNs", RFC 4364, February 2006.
         
     | 
| 
      
 228 
     | 
    
         
            +
             
     | 
| 
      
 229 
     | 
    
         
            +
            [RFC4684]  P. Marques, R. Bonica, L. Fang, L. Martini, R. Raszuk, K. Patel
         
     | 
| 
      
 230 
     | 
    
         
            +
                       and J. Guichard, "Constrained VPN Route Distribution", RFC 4684,
         
     | 
| 
      
 231 
     | 
    
         
            +
                       November 2006.
         
     | 
| 
      
 232 
     | 
    
         
            +
             
     | 
| 
      
 233 
     | 
    
         
            +
            [RFC4760]  T. Bates, R. Chandra, D. Katz and Y. Rekhter, "Multiprotocol 
         
     | 
| 
      
 234 
     | 
    
         
            +
                       Extensions for BGP-4", RFC 4760, January 2007.
         
     | 
| 
      
 235 
     | 
    
         
            +
             
     | 
| 
      
 236 
     | 
    
         
            +
            [RFC4761]  K. Kompella and Y. Rekhter, "Virtual Private LAN Service 
         
     | 
| 
      
 237 
     | 
    
         
            +
                       (VPLS) Using BGP for Auto-discovery and Signaling", RFC 4761,
         
     | 
| 
      
 238 
     | 
    
         
            +
                       January 2007.
         
     | 
| 
      
 239 
     | 
    
         
            +
             
     | 
| 
      
 240 
     | 
    
         
            +
            [RFC-ietf-l1vpn-bgp-auto-discovery-05.txt] 
         
     | 
| 
      
 241 
     | 
    
         
            +
                       H. Brahim, D. Fedyk, Y. Rekhter, "BGP-based Auto-Discovery for 
         
     | 
| 
      
 242 
     | 
    
         
            +
                       Layer-1 VPNs", RFC XXXX, Month Year.
         
     | 
| 
      
 243 
     | 
    
         
            +
                       
         
     | 
| 
      
 244 
     | 
    
         
            +
            [draft-ietf-l3vpn-bgpvpn-auto]  Work in progress
         
     | 
| 
      
 245 
     | 
    
         
            +
             
     | 
| 
      
 246 
     | 
    
         
            +
            [draft-ietf-pwe3-dynamic-ms-pw] Work in progress
         
     | 
| 
      
 247 
     | 
    
         
            +
             
     | 
| 
      
 248 
     | 
    
         
            +
            [draft-marques-idr-flow-spec]   Work in progress
         
     | 
| 
      
 249 
     | 
    
         
            +
             
     | 
| 
      
 250 
     | 
    
         
            +
            [draft-ietf-l3vpn-2547bis-mcast-bgp] Work in progress
         
     | 
| 
      
 251 
     | 
    
         
            +
             
     | 
| 
      
 252 
     | 
    
         
            +
            [RFC-ietf-softwire-encaps-safi-05.txt]
         
     | 
| 
      
 253 
     | 
    
         
            +
                       P. Mohapatra, E. Rosen, "BGP Encapsulation SAFI and BGP Tunnel 
         
     | 
| 
      
 254 
     | 
    
         
            +
                       Encapsulation Attribute", RFC XXXX, Month Year.
         
     | 
| 
      
 255 
     | 
    
         
            +
             
     | 
| 
      
 256 
     | 
    
         
            +
            People
         
     | 
| 
      
 257 
     | 
    
         
            +
            ------
         
     | 
| 
      
 258 
     | 
    
         
            +
            [Bates] Tony Bates, <tbates&cisco.com>, July 2000. 
         
     | 
| 
      
 259 
     | 
    
         
            +
             
     | 
| 
      
 260 
     | 
    
         
            +
            [Cui]  Yong Cui, <cuiyong&tsinghua.edu.cn>, 15 August 2006, 20 September 2006.
         
     | 
| 
      
 261 
     | 
    
         
            +
             
     | 
| 
      
 262 
     | 
    
         
            +
            [Nalawade]  Gargi Nalawade, <gargi&cisco.com>, January 2004. 
         
     | 
| 
      
 263 
     | 
    
         
            +
                       (draft-nalawade-kapoor-tunnel-safi-01.txt)  
         
     | 
| 
      
 264 
     | 
    
         
            +
                       (draft-nalawade-idr-mdt-safi-00.txt), February 2004.
         
     | 
| 
      
 265 
     | 
    
         
            +
             
     | 
| 
      
 266 
     | 
    
         
            +
            (created 2000-07)
         
     | 
| 
      
 267 
     | 
    
         
            +
             
     | 
| 
      
 268 
     | 
    
         
            +
            [] 
         
     | 
| 
      
 269 
     | 
    
         
            +
             
     | 
    
        data/bgp/io.rb
    ADDED
    
    | 
         @@ -0,0 +1,116 @@ 
     | 
|
| 
      
 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 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
            require 'observer'
         
     | 
| 
      
 25 
     | 
    
         
            +
            require 'thread'
         
     | 
| 
      
 26 
     | 
    
         
            +
            require 'bgp/common'
         
     | 
| 
      
 27 
     | 
    
         
            +
            require 'bgp/message'
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            module BGP
         
     | 
| 
      
 30 
     | 
    
         
            +
              module IO
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                class Output < Queue
         
     | 
| 
      
 33 
     | 
    
         
            +
                  include Observable
         
     | 
| 
      
 34 
     | 
    
         
            +
                  def initialize(session, holdtime, *obs)
         
     | 
| 
      
 35 
     | 
    
         
            +
                    @session, @holdtime = session, holdtime
         
     | 
| 
      
 36 
     | 
    
         
            +
                    obs.each { |o| add_observer(o) }
         
     | 
| 
      
 37 
     | 
    
         
            +
                    @continue = true
         
     | 
| 
      
 38 
     | 
    
         
            +
                    super()
         
     | 
| 
      
 39 
     | 
    
         
            +
                  end
         
     | 
| 
      
 40 
     | 
    
         
            +
                  attr_reader :thread
         
     | 
| 
      
 41 
     | 
    
         
            +
                  attr_writer :holdtime
         
     | 
| 
      
 42 
     | 
    
         
            +
                  def start
         
     | 
| 
      
 43 
     | 
    
         
            +
                    @thread = Thread.new(@session, @holdtime) do |s, h|
         
     | 
| 
      
 44 
     | 
    
         
            +
                      Thread.current['name']='BGP IO Ouput'
         
     | 
| 
      
 45 
     | 
    
         
            +
                      Log.debug "#{self} #{Thread.current} started" 
         
     | 
| 
      
 46 
     | 
    
         
            +
                      begin
         
     | 
| 
      
 47 
     | 
    
         
            +
                        while @continue
         
     | 
| 
      
 48 
     | 
    
         
            +
                          obj = deq
         
     | 
| 
      
 49 
     | 
    
         
            +
                          break unless @continue
         
     | 
| 
      
 50 
     | 
    
         
            +
                          s.write obj.respond_to?(:encode) ? obj.encode : obj
         
     | 
| 
      
 51 
     | 
    
         
            +
                        end
         
     | 
| 
      
 52 
     | 
    
         
            +
                      rescue IOError, Errno::ECONNRESET, Errno::EBADF => e
         
     | 
| 
      
 53 
     | 
    
         
            +
                        puts "ECONNRESET"
         
     | 
| 
      
 54 
     | 
    
         
            +
                        changed and notify_observers(:ev_conn_reset, e)
         
     | 
| 
      
 55 
     | 
    
         
            +
                      ensure
         
     | 
| 
      
 56 
     | 
    
         
            +
                        Log.debug "Exiting #{Thread.current['name']}"
         
     | 
| 
      
 57 
     | 
    
         
            +
                      end
         
     | 
| 
      
 58 
     | 
    
         
            +
                    end
         
     | 
| 
      
 59 
     | 
    
         
            +
                  end
         
     | 
| 
      
 60 
     | 
    
         
            +
                  def exit
         
     | 
| 
      
 61 
     | 
    
         
            +
                    @continue = false
         
     | 
| 
      
 62 
     | 
    
         
            +
                    enq('you\'re done dude!')
         
     | 
| 
      
 63 
     | 
    
         
            +
                  end
         
     | 
| 
      
 64 
     | 
    
         
            +
                end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                class Input
         
     | 
| 
      
 67 
     | 
    
         
            +
                  include Observable
         
     | 
| 
      
 68 
     | 
    
         
            +
                  def initialize(session, holdtime, *obs)
         
     | 
| 
      
 69 
     | 
    
         
            +
                    @session, @holdtime = session, holdtime
         
     | 
| 
      
 70 
     | 
    
         
            +
                    obs.each { |o| add_observer(o) }
         
     | 
| 
      
 71 
     | 
    
         
            +
                  end
         
     | 
| 
      
 72 
     | 
    
         
            +
                  attr_reader :thread
         
     | 
| 
      
 73 
     | 
    
         
            +
                  attr_writer :holdtime
         
     | 
| 
      
 74 
     | 
    
         
            +
                  def recv_msg(s)
         
     | 
| 
      
 75 
     | 
    
         
            +
                    loop do
         
     | 
| 
      
 76 
     | 
    
         
            +
                      if @buf.size<18 or @buf.size <@len
         
     | 
| 
      
 77 
     | 
    
         
            +
                        recv = s.recv(4100) 
         
     | 
| 
      
 78 
     | 
    
         
            +
                        @buf += recv unless recv.nil?
         
     | 
| 
      
 79 
     | 
    
         
            +
                        break unless @continue
         
     | 
| 
      
 80 
     | 
    
         
            +
                      end
         
     | 
| 
      
 81 
     | 
    
         
            +
                      if @buf.size>18
         
     | 
| 
      
 82 
     | 
    
         
            +
                        @len, @type=@buf[16,3].unpack('nC')
         
     | 
| 
      
 83 
     | 
    
         
            +
                        return @buf.slice!(0,@len) if @len<=@buf.size
         
     | 
| 
      
 84 
     | 
    
         
            +
                      end
         
     | 
| 
      
 85 
     | 
    
         
            +
                    end
         
     | 
| 
      
 86 
     | 
    
         
            +
                  end
         
     | 
| 
      
 87 
     | 
    
         
            +
                  
         
     | 
| 
      
 88 
     | 
    
         
            +
                  def start
         
     | 
| 
      
 89 
     | 
    
         
            +
                    @thread = Thread.new(@session, @holdtime) do |s, h|
         
     | 
| 
      
 90 
     | 
    
         
            +
                      Thread.current['name']='BGP IO Input'
         
     | 
| 
      
 91 
     | 
    
         
            +
                      Log.debug "#{self} #{Thread.current} started"
         
     | 
| 
      
 92 
     | 
    
         
            +
                      @buf = ''
         
     | 
| 
      
 93 
     | 
    
         
            +
                      @continue = true
         
     | 
| 
      
 94 
     | 
    
         
            +
                      @len=0
         
     | 
| 
      
 95 
     | 
    
         
            +
                      begin
         
     | 
| 
      
 96 
     | 
    
         
            +
                        while @continue
         
     | 
| 
      
 97 
     | 
    
         
            +
                          begin
         
     | 
| 
      
 98 
     | 
    
         
            +
                            Timeout::timeout(h) do |h| 
         
     | 
| 
      
 99 
     | 
    
         
            +
                              message, type = recv_msg(s)
         
     | 
| 
      
 100 
     | 
    
         
            +
                              break unless @continue
         
     | 
| 
      
 101 
     | 
    
         
            +
                              changed and notify_observers(:ev_msg, @type, message)
         
     | 
| 
      
 102 
     | 
    
         
            +
                            end
         
     | 
| 
      
 103 
     | 
    
         
            +
                          rescue Timeout::Error => e
         
     | 
| 
      
 104 
     | 
    
         
            +
                            changed and notify_observers(:ev_holdtime_expire, e)
         
     | 
| 
      
 105 
     | 
    
         
            +
                            @continue = false
         
     | 
| 
      
 106 
     | 
    
         
            +
                          end
         
     | 
| 
      
 107 
     | 
    
         
            +
                        end
         
     | 
| 
      
 108 
     | 
    
         
            +
                      rescue IOError, Errno::ECONNRESET, Errno::EBADF => e
         
     | 
| 
      
 109 
     | 
    
         
            +
                        changed and notify_observers(:ev_conn_reset, e)
         
     | 
| 
      
 110 
     | 
    
         
            +
                      end
         
     | 
| 
      
 111 
     | 
    
         
            +
                      Log.debug "Exiting #{Thread.current['name']}"
         
     | 
| 
      
 112 
     | 
    
         
            +
                    end 
         
     | 
| 
      
 113 
     | 
    
         
            +
                  end
         
     | 
| 
      
 114 
     | 
    
         
            +
                end
         
     | 
| 
      
 115 
     | 
    
         
            +
              end
         
     | 
| 
      
 116 
     | 
    
         
            +
            end
         
     | 
    
        data/bgp/label.rb
    ADDED
    
    | 
         @@ -0,0 +1,94 @@ 
     | 
|
| 
      
 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/common'
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            module BGP
         
     | 
| 
      
 26 
     | 
    
         
            +
              class Label
         
     | 
| 
      
 27 
     | 
    
         
            +
                attr_reader :label
         
     | 
| 
      
 28 
     | 
    
         
            +
                def initialize(*args)
         
     | 
| 
      
 29 
     | 
    
         
            +
                  @label, @exp = [0]*3
         
     | 
| 
      
 30 
     | 
    
         
            +
                  if args.size==1 and args[0].is_a?(Hash)
         
     | 
| 
      
 31 
     | 
    
         
            +
                    @label=args[0][:label] if args[0][:label]
         
     | 
| 
      
 32 
     | 
    
         
            +
                    @exp=args[0][:exp] if args[0][:exp]
         
     | 
| 
      
 33 
     | 
    
         
            +
                  elsif args.size==1 and args[0].is_a?(String) and args[0].is_packed?
         
     | 
| 
      
 34 
     | 
    
         
            +
                    parse(args[0])
         
     | 
| 
      
 35 
     | 
    
         
            +
                  else args[0].is_a?(Fixnum)
         
     | 
| 
      
 36 
     | 
    
         
            +
                    @label, @exp = args + [0]
         
     | 
| 
      
 37 
     | 
    
         
            +
                  end
         
     | 
| 
      
 38 
     | 
    
         
            +
                end
         
     | 
| 
      
 39 
     | 
    
         
            +
                def encode(bottom=1)
         
     | 
| 
      
 40 
     | 
    
         
            +
                  n = (@label <<4) | (@exp & 0x7)<<1 |(bottom &0x1)
         
     | 
| 
      
 41 
     | 
    
         
            +
                  o1 = (n & 0xff0000) >> 16
         
     | 
| 
      
 42 
     | 
    
         
            +
                  o2 = (n & 0x00ff00) >> 8
         
     | 
| 
      
 43 
     | 
    
         
            +
                  o3 = (n & 0x0000ff)
         
     | 
| 
      
 44 
     | 
    
         
            +
                  [o1,o2,o3].pack('CCC')
         
     | 
| 
      
 45 
     | 
    
         
            +
                end
         
     | 
| 
      
 46 
     | 
    
         
            +
                def parse(s)
         
     | 
| 
      
 47 
     | 
    
         
            +
                  octets = s.slice!(0,3).unpack('CCC')
         
     | 
| 
      
 48 
     | 
    
         
            +
                  n = (octets[0] << 16) + (octets[1] << 8) + octets[2]
         
     | 
| 
      
 49 
     | 
    
         
            +
                  @exp = (n >> 1) & 0x7
         
     | 
| 
      
 50 
     | 
    
         
            +
                  @label = (n >> 4)
         
     | 
| 
      
 51 
     | 
    
         
            +
                end
         
     | 
| 
      
 52 
     | 
    
         
            +
                def to_hash
         
     | 
| 
      
 53 
     | 
    
         
            +
                  {:label=>@label, :exp=>@exp}
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
              end
         
     | 
| 
      
 56 
     | 
    
         
            +
              class Label_stack
         
     | 
| 
      
 57 
     | 
    
         
            +
                def initialize(*args)
         
     | 
| 
      
 58 
     | 
    
         
            +
                  @label_stack=[]
         
     | 
| 
      
 59 
     | 
    
         
            +
                  if args.size==1 and args[0].is_a?(String) and args[0].is_packed?
         
     | 
| 
      
 60 
     | 
    
         
            +
                    parse(args[0])
         
     | 
| 
      
 61 
     | 
    
         
            +
                  else
         
     | 
| 
      
 62 
     | 
    
         
            +
                    args.each { |arg| @label_stack << (arg.is_a?(Label) ? arg : Label.new(arg)) }
         
     | 
| 
      
 63 
     | 
    
         
            +
                  end
         
     | 
| 
      
 64 
     | 
    
         
            +
                end
         
     | 
| 
      
 65 
     | 
    
         
            +
                def size
         
     | 
| 
      
 66 
     | 
    
         
            +
                  @label_stack.size
         
     | 
| 
      
 67 
     | 
    
         
            +
                end
         
     | 
| 
      
 68 
     | 
    
         
            +
                def encode
         
     | 
| 
      
 69 
     | 
    
         
            +
                  enc = @label_stack[0..-2].collect { |l| l.encode(0) }
         
     | 
| 
      
 70 
     | 
    
         
            +
                  enc << @label_stack[-1].encode
         
     | 
| 
      
 71 
     | 
    
         
            +
                  enc.join
         
     | 
| 
      
 72 
     | 
    
         
            +
                end
         
     | 
| 
      
 73 
     | 
    
         
            +
                def parse(s)
         
     | 
| 
      
 74 
     | 
    
         
            +
                  while s.size>0
         
     | 
| 
      
 75 
     | 
    
         
            +
                    bottom = s[2,1].unpack('C')[0]
         
     | 
| 
      
 76 
     | 
    
         
            +
                    @label_stack << label = Label.new(s)
         
     | 
| 
      
 77 
     | 
    
         
            +
                    break if bottom & 1 > 0
         
     | 
| 
      
 78 
     | 
    
         
            +
                  end
         
     | 
| 
      
 79 
     | 
    
         
            +
                end
         
     | 
| 
      
 80 
     | 
    
         
            +
                def to_s
         
     | 
| 
      
 81 
     | 
    
         
            +
                  if @label_stack.empty?
         
     | 
| 
      
 82 
     | 
    
         
            +
                    "Label stack:(empty)"
         
     | 
| 
      
 83 
     | 
    
         
            +
                  else
         
     | 
| 
      
 84 
     | 
    
         
            +
                    "Label Stack=#{@label_stack.collect{ |l| l.label }.join(',')} (bottom)"
         
     | 
| 
      
 85 
     | 
    
         
            +
                  end
         
     | 
| 
      
 86 
     | 
    
         
            +
                end
         
     | 
| 
      
 87 
     | 
    
         
            +
                def bit_length
         
     | 
| 
      
 88 
     | 
    
         
            +
                  @label_stack.compact.size*24
         
     | 
| 
      
 89 
     | 
    
         
            +
                end
         
     | 
| 
      
 90 
     | 
    
         
            +
              end
         
     | 
| 
      
 91 
     | 
    
         
            +
            end
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
            load "../test/#{ File.basename($0.gsub(/.rb/,'_test.rb'))}" if __FILE__ == $0
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
    
        data/bgp/local_pref.rb
    ADDED
    
    | 
         @@ -0,0 +1,75 @@ 
     | 
|
| 
      
 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 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
            require 'bgp/attribute'
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
            module BGP
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
              class Local_pref < Attr
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                def initialize(arg=100)
         
     | 
| 
      
 31 
     | 
    
         
            +
                  @flags, @type = WELL_KNOWN_MANDATORY, LOCAL_PREF
         
     | 
| 
      
 32 
     | 
    
         
            +
                  if arg.is_a?(String) and arg.is_packed?
         
     | 
| 
      
 33 
     | 
    
         
            +
                    parse(arg)
         
     | 
| 
      
 34 
     | 
    
         
            +
                  elsif arg.is_a?(self.class)
         
     | 
| 
      
 35 
     | 
    
         
            +
                    parse(arg.encode)
         
     | 
| 
      
 36 
     | 
    
         
            +
                  elsif arg.is_a?(Fixnum) or arg.is_a?(Bignum)
         
     | 
| 
      
 37 
     | 
    
         
            +
                    self.local_pref = arg
         
     | 
| 
      
 38 
     | 
    
         
            +
                  elsif arg.is_a?(Hash) and arg[:local_pref]
         
     | 
| 
      
 39 
     | 
    
         
            +
                    self.local_pref = arg[:local_pref]
         
     | 
| 
      
 40 
     | 
    
         
            +
                  else
         
     | 
| 
      
 41 
     | 
    
         
            +
                    raise ArgumentError, "invalid argument, #{arg.inspect}"
         
     | 
| 
      
 42 
     | 
    
         
            +
                  end
         
     | 
| 
      
 43 
     | 
    
         
            +
                end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                def local_pref=(val)
         
     | 
| 
      
 46 
     | 
    
         
            +
                  raise ArgumentError, "invalid argument" unless val.is_a?(Integer)
         
     | 
| 
      
 47 
     | 
    
         
            +
                  @local_pref=val
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                def to_i
         
     | 
| 
      
 51 
     | 
    
         
            +
                  @local_pref
         
     | 
| 
      
 52 
     | 
    
         
            +
                end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                def encode
         
     | 
| 
      
 55 
     | 
    
         
            +
                  super([to_i].pack('N'))
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                def local_pref
         
     | 
| 
      
 59 
     | 
    
         
            +
                  format("(0x%4.4x) %d", to_i, to_i)
         
     | 
| 
      
 60 
     | 
    
         
            +
                end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                def to_s(method=:default)
         
     | 
| 
      
 63 
     | 
    
         
            +
                  super(local_pref, method)
         
     | 
| 
      
 64 
     | 
    
         
            +
                end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                private
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                def parse(s)
         
     | 
| 
      
 69 
     | 
    
         
            +
                  @flags, @type, len, @local_pref = super(s,'N')
         
     | 
| 
      
 70 
     | 
    
         
            +
                end
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
              end
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
            end
         
     | 
| 
      
 75 
     | 
    
         
            +
            load "../test/#{ File.basename($0.gsub(/.rb/,'_test.rb'))}" if __FILE__ == $0
         
     |