Skip to content

Use Cases Multi Tenant

Thomas Mangin edited this page Oct 1, 2026 · 7 revisions

Multi-Tenant Networking

ExaBGP enables multi-tenant network isolation using VRFs, Route Target filtering, and tenant separation for cloud providers and service providers.

Table of Contents

Overview

Multi-Tenancy Requirements

Multi-tenant networks require:

  • Isolation: Complete separation between tenants
  • Scalability: Support thousands of tenants
  • Flexibility: Different topologies per tenant
  • Security: Prevent cross-tenant traffic
  • Automation: Dynamic tenant provisioning
  • Resource efficiency: Share infrastructure efficiently

ExaBGP Role

ExaBGP enables multi-tenancy by:

  1. VRF route distribution: Advertise tenant routes with Route Distinguishers
  2. Route Target filtering: Control route import/export per tenant
  3. Dynamic provisioning: Create/delete tenant networks via API
  4. Cross-tenant services: Controlled inter-tenant connectivity

Important: ExaBGP announces tenant routes but does NOT create VRFs or manipulate forwarding tables. Your network OS must configure VRFs and route installation.

VRF Isolation

Basic Tenant Separation

Isolate tenants using VRFs. The programs on this page read ExaBGP's answer (done or error) after each command they write, with the send() function from Reading the answers, or skip the answers in the loop which reads their input. ExaBGP 6.0 writes these commands with a peer * selector, see How a program talks to ExaBGP.

#!/usr/bin/env python3
import sys

def send(command):
    """Write one command, then read lines until ExaBGP answers it"""
    sys.stdout.write(command + "\n")
    sys.stdout.flush()
    while True:
        line = sys.stdin.readline()
        if not line:  # ExaBGP closed the pipe: it is stopping
            sys.exit(0)
        answer = line.strip()
        if answer == 'done':
            return True
        if answer == 'error':
            return False

# Tenant configuration
TENANTS = {
    'tenant-001': {
        'vrf': 'TENANT-001',
        'rd': '10.0.0.1:1001',
        'rt_export': '65000:1001',
        'rt_import': '65000:1001',
        'label': 1001,  # the MPLS label of the VRF
        'prefixes': ['192.168.1.0/24', '192.168.2.0/24']
    },
    'tenant-002': {
        'vrf': 'TENANT-002',
        'rd': '10.0.0.1:1002',
        'rt_export': '65000:1002',
        'rt_import': '65000:1002',
        'label': 1002,
        'prefixes': ['192.168.1.0/24', '192.168.3.0/24']  # Can overlap!
    },
    'tenant-003': {
        'vrf': 'TENANT-003',
        'rd': '10.0.0.1:1003',
        'rt_export': '65000:1003',
        'rt_import': '65000:1003',
        'label': 1003,
        'prefixes': ['10.0.0.0/16']
    }
}

NEXT_HOP = "10.0.0.1"

# Announce tenant routes with isolation
for tenant_id, config in TENANTS.items():
    for prefix in config['prefixes']:
        send(f"announce route {prefix} "
             f"next-hop {NEXT_HOP} "
             f"route-distinguisher {config['rd']} "
             f"label {config['label']} "
             f"extended-community [target:{config['rt_export']}]")

while True:
    line = sys.stdin.readline().strip()
    if not line:
        break

Hierarchical Tenants

Support sub-tenants with hierarchical VRFs:

#!/usr/bin/env python3
import sys

def send(command):
    """Write one command, then read lines until ExaBGP answers it"""
    sys.stdout.write(command + "\n")
    sys.stdout.flush()
    while True:
        line = sys.stdin.readline()
        if not line:  # ExaBGP closed the pipe: it is stopping
            sys.exit(0)
        answer = line.strip()
        if answer == 'done':
            return True
        if answer == 'error':
            return False

# Hierarchical tenant structure
HIERARCHY = {
    'enterprise-a': {
        'rd': '10.0.0.1:1000',
        'rt': '65000:1000',
        'label': 1000,  # the MPLS label of the VRF
        'prefixes': ['10.100.0.0/16'],  # Enterprise-wide
        'sub-tenants': {
            'dept-sales': {
                'rd': '10.0.0.1:1001',
                'rt': '65000:1001',
                'rt_import_parent': '65000:1000',  # Import from parent
                'label': 1001,
                'prefixes': ['10.100.1.0/24']
            },
            'dept-eng': {
                'rd': '10.0.0.1:1002',
                'rt': '65000:1002',
                'rt_import_parent': '65000:1000',
                'label': 1002,
                'prefixes': ['10.100.2.0/24']
            }
        }
    }
}

NEXT_HOP = "10.0.0.1"

# Announce parent tenant
for enterprise, config in HIERARCHY.items():
    for prefix in config['prefixes']:
        send(f"announce route {prefix} "
             f"next-hop {NEXT_HOP} "
             f"route-distinguisher {config['rd']} "
             f"label {config['label']} "
             f"extended-community [target:{config['rt']}]")

    # Announce sub-tenants
    for dept, sub_config in config.get('sub-tenants', {}).items():
        for prefix in sub_config['prefixes']:
            # Export both sub-tenant RT and parent RT for selective import
            send(f"announce route {prefix} "
                 f"next-hop {NEXT_HOP} "
                 f"route-distinguisher {sub_config['rd']} "
                 f"label {sub_config['label']} "
                 f"extended-community [target:{sub_config['rt']} "
                 f"target:{sub_config['rt_import_parent']}]")

while True:
    line = sys.stdin.readline().strip()
    if not line:
        break

Route Target Filtering

RT-Constrain for Scale

Use Route Target Constraint (RFC 4684) to reduce route propagation:

#!/usr/bin/env python3
import sys

def send(command):
    """Write one command, then read lines until ExaBGP answers it"""
    sys.stdout.write(command + "\n")
    sys.stdout.flush()
    while True:
        line = sys.stdin.readline()
        if not line:  # ExaBGP closed the pipe: it is stopping
            sys.exit(0)
        answer = line.strip()
        if answer == 'done':
            return True
        if answer == 'error':
            return False

# Tenant-to-PE mapping
PE_TENANTS = {
    'pe1': ['65000:1001', '65000:1002', '65000:1003'],
    'pe2': ['65000:2001', '65000:2002'],
    'pe3': ['65000:3001', '65000:3002', '65000:3003', '65000:3004']
}

PE_ID = 'pe1'  # Current PE

# Announce RT-Constrain for subscribed tenants
for rt in PE_TENANTS.get(PE_ID, []):
    # RFC 4684 Route Target Constraint (ExaBGP 6.0.0, family ipv4 rtc)
    send(f"announce ipv4 rtc origin-as 65000 route-target {rt} next-hop self")

while True:
    line = sys.stdin.readline().strip()
    if not line:
        break

Selective Route Import

Control which tenant routes are imported:

#!/usr/bin/env python3
import sys
import json

# Tenant route import policy
IMPORT_POLICY = {
    'tenant-001': ['65000:1001', '65000:9999'],  # Import own + shared services
    'tenant-002': ['65000:1002', '65000:9999'],
    'tenant-003': ['65000:1003']  # Isolated, no shared services
}

def should_import_route(tenant_id, route_targets):
    """Determine if route should be imported for tenant"""
    allowed_rts = IMPORT_POLICY.get(tenant_id, [])
    return any(rt in allowed_rts for rt in route_targets)

# Listen for route updates, until ExaBGP closes the pipe
for line in sys.stdin:
    try:
        data = json.loads(line)
    except ValueError:
        continue  # not JSON: the answer to a command
    # Parse and filter routes based on policy
    # This is illustrative - actual filtering happens in router

Tenant Provisioning

Dynamic Tenant Creation

Create tenants on demand. ExaBGP's standard input only carries ExaBGP's own messages and answers, so the requests reach the program another way: here the provisioning system writes the tenants which should exist to a file, /etc/exabgp/tenants.json, and the program reads it every ten seconds, announcing the routes of a new tenant or prefix and withdrawing those which disappeared:

#!/usr/bin/env python3
import sys
import json
import time

TENANT_FILE = '/etc/exabgp/tenants.json'  # written by the provisioning system

# Route Distinguisher allocation
RD_BASE = "10.0.0.1"
RT_BASE = 65000

def send(command):
    """Write one command, then read lines until ExaBGP answers it"""
    sys.stdout.write(command + "\n")
    sys.stdout.flush()
    while True:
        line = sys.stdin.readline()
        if not line:  # ExaBGP closed the pipe: it is stopping
            sys.exit(0)
        answer = line.strip()
        if answer == 'done':
            return True
        if answer == 'error':
            return False

def load_tenants():
    """{"tenant-a": {"id": 1000, "prefixes": ["192.168.10.0/24"]}, ...}, or None"""
    try:
        with open(TENANT_FILE) as f:
            return json.load(f)
    except (OSError, ValueError):
        return None  # keep the current tenants until the file can be read

def vpn_route(tenant_id, prefix):
    """The VPN route of one tenant prefix, without announce or withdraw"""
    return (f"route {prefix} "
            f"next-hop self "
            f"route-distinguisher {RD_BASE}:{tenant_id} "
            f"label {tenant_id} "
            f"extended-community [target:{RT_BASE}:{tenant_id}]")

# Routes currently announced
announced = set()

while True:
    tenants = load_tenants()
    if tenants is not None:
        wanted = {
            vpn_route(config['id'], prefix)
            for config in tenants.values()
            for prefix in config.get('prefixes', [])
        }
        for route in sorted(wanted - announced):
            if send(f"announce {route}"):
                announced.add(route)
            else:
                sys.stderr.write(f"ExaBGP refused: announce {route}\n")
        for route in sorted(announced - wanted):
            if send(f"withdraw {route}"):
                announced.discard(route)
    time.sleep(10)

Integration with Orchestration

Integrate with OpenStack/Kubernetes for automatic tenant provisioning:

#!/usr/bin/env python3
import sys
import json
import time
from neutronclient.v2_0 import client as neutron_client

# OpenStack Neutron integration
OS_AUTH_URL = "http://controller:5000/v3"
OS_USERNAME = "admin"
OS_PASSWORD = "secret"
OS_PROJECT = "admin"

RD_BASE = "10.0.0.1"
RT_BASE = 65000

def send(command):
    """Write one command, then read lines until ExaBGP answers it"""
    sys.stdout.write(command + "\n")
    sys.stdout.flush()
    while True:
        line = sys.stdin.readline()
        if not line:  # ExaBGP closed the pipe: it is stopping
            sys.exit(0)
        answer = line.strip()
        if answer == 'done':
            return True
        if answer == 'error':
            return False

def get_neutron_client():
    return neutron_client.Client(
        username=OS_USERNAME,
        password=OS_PASSWORD,
        project_name=OS_PROJECT,
        auth_url=OS_AUTH_URL
    )

def sync_neutron_networks():
    """Sync Neutron networks to BGP VPNs"""
    neutron = get_neutron_client()
    networks = neutron.list_networks()['networks']

    for network in networks:
        network_id = network['id']
        network_name = network['name']

        # Derive VPN parameters from network ID
        tenant_id = int(network_id[:8], 16) % 65535
        rd = f"{RD_BASE}:{tenant_id}"
        rt = f"{RT_BASE}:{tenant_id}"

        # Get subnets for this network
        subnets = neutron.list_subnets(network_id=network_id)['subnets']

        for subnet in subnets:
            cidr = subnet['cidr']

            send(f"announce route {cidr} "
                 f"next-hop self "
                 f"route-distinguisher {rd} "
                 f"label {tenant_id} "
                 f"extended-community [target:{rt}]")

# Initial sync
sync_neutron_networks()

# Periodic sync
while True:
    time.sleep(300)  # Re-sync every 5 minutes
    sync_neutron_networks()

Configuration Examples

Multi-Tenant PE Router

Configuration (/etc/exabgp/multi-tenant-pe.conf):

process tenant-controller {
    run python3 /etc/exabgp/tenant-announce.py;
    encoder json;
}

neighbor 10.0.0.1 {
    router-id 10.1.1.1;
    local-address 10.1.1.1;
    local-as 65001;
    peer-as 65001;

    family {
        ipv4 mpls-vpn;
    }

    api {
        processes [ tenant-controller ];
    }
}

Shared Services VRF

API Program (/etc/exabgp/shared-services.py):

#!/usr/bin/env python3
import sys

def send(command):
    """Write one command, then read lines until ExaBGP answers it"""
    sys.stdout.write(command + "\n")
    sys.stdout.flush()
    while True:
        line = sys.stdin.readline()
        if not line:  # ExaBGP closed the pipe: it is stopping
            sys.exit(0)
        answer = line.strip()
        if answer == 'done':
            return True
        if answer == 'error':
            return False

# Shared services VRF (DNS, NTP, monitoring)
SHARED_SERVICES = {
    'rd': '10.0.0.1:9999',
    'rt_export': '65000:9999',  # All tenants import this
    'label': 9999,  # the MPLS label of the VRF
    'prefixes': [
        '10.255.1.0/24',  # DNS servers
        '10.255.2.0/24',  # NTP servers
        '10.255.3.0/24'   # Monitoring
    ]
}

NEXT_HOP = "10.0.0.1"

# Announce shared services
for prefix in SHARED_SERVICES['prefixes']:
    send(f"announce route {prefix} "
         f"next-hop {NEXT_HOP} "
         f"route-distinguisher {SHARED_SERVICES['rd']} "
         f"label {SHARED_SERVICES['label']} "
         f"extended-community [target:{SHARED_SERVICES['rt_export']}]")

while True:
    line = sys.stdin.readline().strip()
    if not line:
        break

Internet Gateway per Tenant

Different internet gateways per tenant:

#!/usr/bin/env python3
import sys

def send(command):
    """Write one command, then read lines until ExaBGP answers it"""
    sys.stdout.write(command + "\n")
    sys.stdout.flush()
    while True:
        line = sys.stdin.readline()
        if not line:  # ExaBGP closed the pipe: it is stopping
            sys.exit(0)
        answer = line.strip()
        if answer == 'done':
            return True
        if answer == 'error':
            return False

# Tenant internet gateway mappings
TENANT_GATEWAYS = {
    'tenant-001': {
        'gateway': '10.1.1.1',
        'rd': '10.0.0.1:1001',
        'rt': '65000:1001',
        'label': 1001  # the MPLS label of the VRF
    },
    'tenant-002': {
        'gateway': '10.1.2.1',
        'rd': '10.0.0.1:1002',
        'rt': '65000:1002',
        'label': 1002
    }
}

# Announce default route per tenant
for tenant, config in TENANT_GATEWAYS.items():
    send(f"announce route 0.0.0.0/0 "
         f"next-hop {config['gateway']} "
         f"route-distinguisher {config['rd']} "
         f"label {config['label']} "
         f"extended-community [target:{config['rt']}]")

while True:
    line = sys.stdin.readline().strip()
    if not line:
        break

See Also

Address Families

Related Use Cases

Configuration

Features


Clone this wiki locally