Git Product home page Git Product logo

bgp4r's Introduction

BGP4R

<img src=“https://travis-ci.org/jesnault/bgp4r.svg?branch=master” alt=“Build Status” />

Description

BGP4R is a ruby library which enables the creation and manipulation of BGP messages. In BGP4R, all well-known BGP constructs are defined in classes.

Using BGP4R, the process of building BGP messages becomes a simple matter of adding objects to their respective containers; i.e. an attribute is added to a Path_attribute container, while a Path_attribute object or Nlri object is added to an Update object.

A Neighbor class is used to describe a BGP peering adjacency.

A Neighbor instance can be started, stopped, and programmed to send BGP messages

Neighbor#start
Neighbor#stop
Neighbor#send_message

Neighbor capabilities such as MBGP or 4-byte AS can be set using Neighbor#capability

e.g.: 

 neighbor = Neighbor.new \
    :version=> 4, 
    :my_as=> 100, 
    :remote_addr => '192.168.1.200', 
    :id=> '1.1.1.1', 
    :holdtime=> 20

 neighbor.capability_mbgp_ipv4_unicast  
 neighbor.capability_mbgp_ipv4_multicast
 neighbor.capability_mbgp_ipv4_mpls_vpn_unicast
 neighbor.capability_mbgp_ipv6_mpls_vpn_multicast
 neighbor.capability_mbgp_nsap_mpls_vpn_unicast
 neighbor.capability_mbgp_nsap_unicast  
 neighbor.capability_route_refresh
 neighbor.capability_route_refresh 128  
 neighbor.capability_four_byte_as

Ruby classes representing BGP messages, attributes, and nlri

Messages:

Open
Update
Notification
Keepalive
Route_refresh

Attributes:

Origin
As_path
Next_hop
Local_pref
Multi_exit_disc
Communities
Atomic_aggregate
Aggregator
Originator_id
Cluster_list
Mp_reach
Mp_unreach
As4_path
As4_aggregator
Extended_communities

Update containers:

Nlri
Path_attribute
Withdrawn

Getting started

Here is an example illustrating how to use this API:

require 'bgp4r'
include BGP

Start loggin

Log.create
Log.level=Logger::DEBUG

Create a Neighbor:

neighbor = Neighbor.new \
  :version=> 4, 
  :my_as=> 100, 
  :remote_addr => '192.168.1.200', 
  :id=> '1.1.1.1', :holdtime=> 20

Set its capabilities:

neighbor.capability_mbgp_ipv4_unicast  
neighbor.capability_mbgp_ipv4_multicast
neighbor.capability_mbgp_ipv4_mpls_vpn_unicast
neighbor.capability_mbgp_ipv6_mpls_vpn_multicast
neighbor.capability_mbgp_nsap_mpls_vpn_unicast
neighbor.capability_mbgp_nsap_unicast  
neighbor.capability_route_refresh
neighbor.capability_route_refresh 128  
neighbor.capability_four_byte_as

Start peering:

neighbor.start :auto_retry=> true

Build an BGP Update object made up of a Path_attribute and a Nlri objects:

an_update = Update.new(
  Path_attribute.new(
    Origin.new(2),
    Next_hop.new('192.168.1.5'),
    Multi_exit_disc.new(100),
    Local_pref.new(100),
    As_path.new(400,300,200),
    Communities.new('1311:1 311:59 2805:64')
  ),
  Nlri.new('77.0.0.0/17', '78.0.0.0/18', '79.0.0.0/19')
)

Ship it!

neighbor.send_message an_update

Produces:

Jean-Michel-Esnaults-MacBook-Pro-17:bgp4r jme$ ruby bgp
I, [56:08#28463]  INFO -- : Open Socket old state Idle new state Active
I, [56:08#28463]  INFO -- : SendOpen
D, [56:08#28463] DEBUG -- : Send Open Message (1), length: 61
  Version 4, my AS 100, Holdtime 20s, ID 1.1.1.1
  Capability(65): 4-octet AS number: 100
  Option Capabilities Advertisement (2): [02020200]
    Route Refresh (2), length: 2
  Option Capabilities Advertisement (2): [02028000]
    Route Refresh (Cisco) (128), length: 2
  Option Capabilities Advertisement (2): [0206010400010001]
    Multiprotocol Extensions (1), length: 4
      AFI IPv4 (1), SAFI Unicast (1)
  Option Capabilities Advertisement (2): [0206010400010002]
    Multiprotocol Extensions (1), length: 4
      AFI IPv4 (1), SAFI Multicast (2)

0x0000: ffff ffff ffff ffff ffff ffff ffff ffff
0x0001: 003d 0104 0064 0014 0101 0101 2002 0641
0x0002: 0400 0000 6402 0202 0002 0280 0002 0601
0x0003: 0400 0100 0102 0601 0400 0100

D, [56:08#28463] DEBUG -- : #<BGP::IO::Input:0x40ab50> #<Thread:0x40a7b8> started
D, [56:08#28463] DEBUG -- : #<BGP::IO::Output:0x40ab14> #<Thread:0x40a754> started
I, [56:08#28463]  INFO -- : ev_send_open old state Active new state OpenSent
I, [56:08#28463]  INFO -- : RecvOpen
D, [56:08#28463] DEBUG -- : Recv Open Message (1), length: 61
  Version 4, my AS 100, Holdtime 180s, ID 2.2.2.2
  Option Capabilities Advertisement (2): [0206010400010001]
    Multiprotocol Extensions (1), length: 4
      AFI IPv4 (1), SAFI Unicast (1)
  Option Capabilities Advertisement (2): [0206010400010002]
    Multiprotocol Extensions (1), length: 4
      AFI IPv4 (1), SAFI Multicast (2)
  Option Capabilities Advertisement (2): [02028000]
    Route Refresh (Cisco) (128), length: 2
  Option Capabilities Advertisement (2): [02020200]
    Route Refresh (2), length: 2
  Capability(65): 4-octet AS number: 100

0x0000: ffff ffff ffff ffff ffff ffff ffff ffff
0x0001: 003d 0104 0064 00b4 0202 0202 2002 0601
0x0002: 0400 0100 0102 0601 0400 0100 0202 0280
0x0003: 0002 0202 0002 0641 0400 0000

I, [56:08#28463]  INFO -- : RecvOpen old state OpenSent new state OpenConfirm
I, [56:08#28463]  INFO -- : RecvKeepalive
D, [56:08#28463] DEBUG -- : Recv Keepalive Message (4), length: 19, [001304]

I, [56:08#28463]  INFO -- : SendKeepalive
D, [56:08#28463] DEBUG -- : Send Keepalive Message (4), length: 19, [001304]

D, [56:08#28463] DEBUG -- : SendKeepAlive
I, [56:08#28463]  INFO -- : RecvKeepAlive old state OpenConfirm new state Established
I, [56:08#28463]  INFO -- : RecvKeepalive
D, [56:08#28463] DEBUG -- : Recv Keepalive Message (4), length: 19, [001304]

I, [56:08#28463]  INFO -- : version: 4, id: 1.1.1.1, as: 100, holdtime: 20, peer addr: 192.168.1.200, local addr: 192.168.1.5 started
I, [56:08#28463]  INFO -- : SendUpdate
D, [56:08#28463] DEBUG -- : Send Update Message (2), 4 bytes AS, length: 92
  Path Attributes:
  Origin (1), length: 1, Flags [T]: incomplete
   0x0000: 
  Next Hop (3), length: 4, Flags [T]: 192.168.1.5
   0x0000: c0a8 0105
  Multi Exit Disc (4), length: 4, Flags [O]: (0x0064) 100
   0x0000: 0000 0064
  Local Pref (5), length: 4, Flags [T]: (0x0064) 100
   0x0000: 0000 0064
  As Path (2), length: 14, Flags [T]: 400 300 200
   0x0000: 0203 0000 0190 0000 012c 0000 00c8
  Communities (8), length: 12, Flags [OT]: 1311:1 311:59 2805:64
   0x0000: 051f 0001 0137 003b 0af5 0040
77.0.0.0/17
78.0.0.0/18
79.0.0.0/19

0x0000: ffff ffff ffff ffff ffff ffff ffff ffff
0x0001: 005c 0200 0000 3940 0101 0240 0304 c0a8
0x0002: 0105 8004 0400 0000 6440 0504 0000 0064
0x0003: 4002 0e02 0300 0001 9000 0001 2c00 0000
0x0004: c8c0 080c 051f 0001 0137 003b 0af5 0040
0x0005: 114d 0000 124e 0000 134f 0000

I, [56:13#28463]  INFO -- : RecvKeepalive
D, [56:13#28463] DEBUG -- : Recv Keepalive Message (4), length: 19, [001304]

I, [56:14#28463]  INFO -- : SendKeepalive
D, [56:14#28463] DEBUG -- : Send Keepalive Message (4), length: 19, [001304]

Source Code

Source code is hosted on github.

Installation

Install the gem

sudo gem install bgp4r

Requirements

License

BGP4R is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

BGP4R is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with BGP4R. If not, see <www.gnu.org/licenses/>.

bgp4r's People

Contributors

jeanmichel-gh avatar ytti avatar

Stargazers

Frampt avatar  avatar  avatar  avatar Stillhart avatar Mikal avatar dmitryck avatar Kent Gruber avatar Anderson Bravalheri avatar Aaron A. Glenn avatar Ivan Semernik avatar Kevin Hatfield avatar .: xav :. avatar David avatar  avatar Yaodong Zhao avatar Thomas Mangin avatar nsiguer avatar GOTOH, Yutaka avatar Samer Abdel-Hafez avatar Jan Brooks avatar Duan Wenbo avatar Richard Hicks avatar  avatar  avatar Mikkel Mondrup Kristensen avatar Atul avatar  avatar

Watchers

 avatar Atul avatar James Cloos avatar nsiguer avatar  avatar

bgp4r's Issues

Origin Validation community

https://tools.ietf.org/html/rfc8097

I tried to implement this but looks like I'm not really understanding what is going on.

It is type 0x43, subtype 0x00, but the case statement only looks at subtypes. I tried ghetto solution, just to understand it better and created condition to punt type == 0x43 && subtype = 0x00 to new Origin_validation class, but I couldn't figure out what the infrastructure wants and ended up getting raised by string/array problems with pack.

It should really be just 0x4300 and then 0,1,3 as last byte.

Many thanks for your work for bgp4r, it is old, but it's still really convenient and there aren not actually many proper library BGP implementations for any language. There are bunch of daemons which are not useable as libraries and have no or bad APIS fit for very few use-cases.

BGP4r has active deadlock

I have been trying to debug for few days why bgp4r spends so much CPU, and it appears it has two threads in active deadlock (most likely). I have not been able to figure out where it exactly is, but

16702 ? - 4119:13 /usr/bin/ruby /opt/bgp-peer/bgp-peer.rb run
- - Ssl 0:02 -
- - Ssl 2055:20 -
- - Ssl 0:33 -
- - Ssl 0:12 -
- - Ssl 0:04 -
- - Rsl 2057:05 -
- - Ssl 0:34 -
- - Ssl 0:12 -
- - Ssl 0:04 -
- - Ssl 2:57 -
- - Ssl 0:24 -
- - Ssl 0:23 -
- - Ssl 0:00 -
- - Ssl 0:00 -
- - Ssl 0:00 -

This shows that two threads are currently competing for some lock. If I try debug this, with, say ruby function tracing, it goes away because the function tracing causes delays. Any ideas or should I try get some more debugging?

as4_byte doesn't work

Hi !

Peering with a Cisco Router an 4-byte AS doesn't work even if i set the option parameter neighbor.capability :as4_byte'.
After looking of your code, it's seem that the attribute :my_as from the Neighbor class is set both in the BGP header (during OPEN message) and in the option parameter.

Considering this document : http://www.cisco.com/web/about/security/intelligence/4byte-as.html

" The NEW speaker will substitute a reserved 2-byte AS number (called AS_TRANS with AS # 23456) for each 4-byte AS so that ASPATH and AGGREGATOR is still 2-byte in length and ASPATH length is still preserved, and at the same time insert the new AS4_PATH and AS4_AGGREGATOR, which will contain the 4-byte encoded copy of the attributes".

I do a small quick patch in the messages/open.rb (replace @local_as when encode by 23456 if there is 4-byte AS in option parameter) in order to continue my test. I'm pretty sure you're gonna fix this better than me :).

link_bandwidth encoding is bogus

Fix is on its way

def test_link_bandwidth

  • assert_equal('04040000461c4000', Link_bandwidth.new(10_000).to_shex)
  • assert_equal('40040000461c4000', Link_bandwidth.new(10_000).to_shex)
    assert_equal('Link bandwidth: 10000.0', Link_bandwidth.new(10_000).to_s)
    assert_equal('Link bandwidth: 10000.0', Link_bandwidth.new(['04040000461c40
  • assert_equal('040400004cbebc20', Link_bandwidth.new(99_999_999).to_shex)
  • assert_equal('400400004cbebc20', Link_bandwidth.new(99_999_999).to_shex)
    assert_equal('Link bandwidth: 100000000.0', Link_bandwidth.new(99_999_999).
    assert_equal('Link bandwidth: 100000000.0', Link_bandwidth.new(['040400004c
    end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.