Skip to content

Repository files navigation

BGP Simulator

A C++ simulator that models how Internet routes propagate across networks, including security features to detect and prevent route hijacking attacks.

What is BGP?

Border Gateway Protocol (BGP) is the routing protocol that makes the Internet work. It allows different networks (called Autonomous Systems or ASes) to share routing information so data can travel from source to destination.

What Does This Simulator Do?

This tool simulates how route announcements spread across the Internet by modeling:

  • Real network relationships: Providers, customers, and peers (just like real ISPs)
  • Route selection: How networks choose the best path to reach a destination
  • Security (ROV): How Route Origin Validation helps prevent malicious route announcements

Use it to:

  • Study BGP security vulnerabilities
  • Analyze prefix hijacking attacks
  • Test Route Origin Validation effectiveness
  • Learn how Internet routing works

Quick Start

Build the Simulator

# From project root
mkdir -p build && cd build
cmake .. && make

Run a Simulation

# From project root
./bgp_simulator \
    --relationships bench/many/CAIDAASGraphCollector_2025.10.16.txt \
    --announcements bench/many/anns.csv \
    --rov-asns bench/many/rov_asns.csv \
    --output ribs.csv

Input Files

1. AS Relationships (CAIDA Format)

Defines the Internet topology with provider-customer and peer relationships.

# Format: asn1|asn2|relationship|source
# -1 = asn1 provides transit for asn2
#  0 = asn1 and asn2 are peers
25|27|-1|BGP
30|40|0|BGP

2. Announcements (CSV)

Initial route announcements from networks.

seed_asn,prefix,rov_invalid
25,1.2.3.0/24,True
27,1.2.0.0/16,False

3. ROV ASNs (Text)

List of networks that use Route Origin Validation security.

25
100
200

Output

The simulator produces a CSV file showing each network's routing table:

asn,prefix,as_path
25,1.2.3.0/24,"(25,)"
100,1.2.3.0/24,"(100, 25)"

How It Works

Route Propagation

Routes spread in three phases matching real BGP behavior:

  1. Up: Routes go from customers to providers (toward tier-1 ISPs)
  2. Across: Routes shared between peers
  3. Down: Routes sent from providers to customers

Route Selection

Networks choose routes based on:

  1. Relationship: Prefer customer routes (you get paid) over peer routes over provider routes (you pay)
  2. Path length: Shorter paths win
  3. Origin: Networks prefer their own announcements

Security (ROV)

Networks using Route Origin Validation reject announcements marked as invalid, preventing some types of route hijacking attacks.

Testing

Automated Test Suite

Run comprehensive tests using pytest to validate simulator functionality:

# Install test dependencies
pip install -r requirements-test.txt

# Run all tests (17 tests covering functionality, cycle detection, and scenarios)
pytest test_bgp_simulator.py -v

# Run specific test categories
pytest test_bgp_simulator.py::TestCycleDetection -v

The test suite validates route propagation, cycle detection, ROV policy enforcement, and compares output against expected results for multiple hijacking scenarios.

Test Scenarios

Subprefix Hijacking

cd build && make test_subprefix

Simulates an attacker announcing a more specific prefix to hijack traffic.

Prefix Hijacking

cd build && make test_prefix

Two networks announce the same prefix - who wins?

Complex Scenario

cd build && make test_many

Multiple announcements across a large network (70,000+ ASes).

Project Structure

├── include/          # Header files
│   ├── ASGraph.h     # Main graph structure
│   ├── AS.h          # Individual network
│   ├── Policy.h      # BGP and ROV logic
│   └── Announcement.h # Route information
├── src/              # Implementation
├── bench/            # Test cases
└── build/            # Compiled executable

Key Concepts

Autonomous System (AS): A network under single administrative control (like an ISP)

AS Path: The sequence of networks a route passes through

Prefix: An IP address range (e.g., 1.2.3.0/24 = 256 addresses)

ROV (Route Origin Validation): Security mechanism to validate route announcements

Requirements

  • C++17 compiler (GCC 7+, Clang 6+, MSVC 2017+)
  • CMake 3.14+

Data Sources

Get real Internet topology data from CAIDA: https://www.caida.org/catalog/datasets/as-relationships/

License

Educational tool for Internet routing research.

About

C++ BGP network simulator modeling advertisement, path selection, and peer communication using real Internet topology data from the CAIDA AS-relationship dataset.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages