Skip to main content

Simple Python BGP implementation

Project description

BGPhoria is an BGP tool developed and sponsored by Interstellio IO (PTY) LTD.

Planning Phase: Under-Construction first initial code / commit.

This project is not ready to be used by any external projects.

TODO:

  • Complete all docstrings / code documentation.

  • Support is needed to advertise IPv4 and IPv6 unicast prefixes for testing and the anycast server use case.

  • Complete the design and implementation of BGPhoria’s core functionality to allow external code to receive updates via callbacks and advertise prefixes via a callback trigger. This will ensure that users can effectively interact with a BGP server using their code.

  • We should also listen for BGP peer connections.

  • Built-in ready-to-use server for advertising anycast ipv4 and ipv6 prefixes. Use cases such as a DNS, WEB or SMTP server running on Linux that need minimalistic tools for anycast session. Will use the YAML configuration file.

  • Complete this README.rst and reference API documentation.

  • Send notification and drop session if it does not match NLRI configuration with Open Message from Peer.

  • Ensure completing unit testing.

Currently testing design against JUNOS/Juniper Router:

Example script using bgphoria:

import asyncio
import sys
import json
import logging

from bgphoria import BGPClient
from bgphoria.constants import ADD_PATH


def configure_default_logger():
    if not logging.getLogger().hasHandlers():
        logging.basicConfig(
            level=logging.INFO,  # Set default logging level
            format="%(asctime)s - %(levelname)s - %(message)s",
            stream=sys.stdout  # Log to stdout
        )


def update_test_cb(update):
    print(json.dumps(update, indent=4))


if __name__ == "__main__":
    PEER_IP = "192.168.1.2"        # Replace with your BGP peer's IP
    LOCAL_AS = 123456                 # Replace with your AS number
    LOCAL_BGP_ID = "192.168.1.1"  # Replace with your BGP identifier

    # Configure module-level logger
    configure_default_logger()
    log = logging.getLogger(__name__)

    try:
        print('starting')
        client = BGPClient("PEER_ID",
                           PEER_IP,
                           LOCAL_AS,
                           LOCAL_AS,
                           LOCAL_BGP_ID,
                           update_callback=update_test_cb,
                           ipv4_unicast=True,
                           ipv4_unicast_add_path=ADD_PATH.RECEIVE_ONLY)
        loop = asyncio.get_event_loop()
        loop.create_task(client.connect())  # Connect Event
        loop.run_forever()  # Keeps the loop running indefinitely
    except KeyboardInterrupt:
        print('stopping')

Overview

BGPhoria is not a full BGP implementation and was never intended to be one. It was created for multiple reasons, primarily to:

  • Test and enhance our internal team’s understanding of the BGP protocol.

  • Experiment with new ideas in a simpler environment, free from the complexities of other implementations.

  • Announce Unicast Route for Anycast from Linux server for redundancy purposes. Applications are DNS, HTTP etc.

This project is a lightweight and simplified BGP implementation that supports:

  • 4 Byte AS Numbers.

  • Unicast prefixes for IPv4 and IPv6.

  • Add-Path capability for these prefixes.

Documentation: https://bgphoria.readthedocs.io

Why BGPhoria?

We understand that there are many more complete BGP projects available. However, their inherent complexity often makes them harder to grasp for beginners or for experimenting with new concepts. BGPhoria was designed to be simple and approachable.

This project was shared with the community because it does not form part of our core projects. Our internal BGP implementations developed for customers are written in C++, and this Python-based project was a standalone experiment.

If BGPhoria aligns with your needs, feel free to use it in your own projects as per the LICENSE.

Contact Interstellio at info@interstellio.io or visit https://www.interstellio.io (we offer professional services that include development of advanced automation, orchestration, monitoring systems and more)

Install

To install BGPhoria via pypi package:

$ pip install bgphoria

To install BGPhoria from source:

$ git clone https://github.com/interstellio/bgphoria.git
$ pip install --editable bgphoria

The –editable flag for pip ensures you can modify the code if neccessary and test it without needing to reinstall again.

We using pytest for unit tests and you can simply run pytest within the root of the cloned repository.

License

This project is licensed under the terms of the GNU General Public License v3 (GPLv3). See the LICENSE file for details.

Development Getting Started

# TODO - EXAMPLE CODE

Anycast Service Example

TODO

Other use cases?

Develop your own python scripts to:

  • Monitor your BGP Prefixes and Alert you.

  • Monitor BGP Updates and understand your upstream connectivity better.

  • Use it in conjunction with netflow data to enhance your view of network traffic beyond just 1 AS number.

Documention

TODO

Contributing

The project goal is to follow minimalist approach with focus on reliability and correctness. Anyone should be able to use this project with ease.

We welcome pull requests from developers of all skill levels. To get started, simply fork the master branch on GitHub to your personal account and then clone the fork into your development environment.

All code should follow the PEP-8 standard as outlined here: https://peps.python.org/pep-0008/ and never break APIs.

This project is still in its infancy, and we prefer to keep it as simple as possible as it grows and expands.

Please don’t hesitate to reach out if you have any questions, or just need a little help getting started. email: opensource@interstellio.io

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bgphoria-0.0.0.tar.gz (31.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bgphoria-0.0.0-py2.py3-none-any.whl (32.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file bgphoria-0.0.0.tar.gz.

File metadata

  • Download URL: bgphoria-0.0.0.tar.gz
  • Upload date:
  • Size: 31.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for bgphoria-0.0.0.tar.gz
Algorithm Hash digest
SHA256 5155b4f7e79ebc199c780c00a261b19f552d2a7602081165de90732cfe91c17e
MD5 43f5314c2a8a82e915580418093bfe46
BLAKE2b-256 5bd3b3d84b058130639a894565f418d3f89e1acdbe25bb419fe8389230822ea0

See more details on using hashes here.

File details

Details for the file bgphoria-0.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: bgphoria-0.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 32.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for bgphoria-0.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 7e779d169a2e40d53ff5a1c315bc009cf373029bacec2837788e8a7d87684869
MD5 d967061dc0bc529892aebc7e585a5bd4
BLAKE2b-256 424ae8e219b3ed4aa138503d6348732ac0de537b09fde626692797b924700018

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page