Designing ISP BGP Communities from Scratch (Part 2): Inbound Traffic Engineering & Policy Chaining

In Part 1, we built a baseline dual-homed ISP topology (AS 65000) with Telia (AS 1299), NTT (AS 2914), and a downstream customer (AS 65535). Managing a single /24 with static route filters is straightforward—but once a customer acquires multiple prefixes with distinct inbound routing and suppression requirements, maintaining hardcoded per-peer prefix lists quickly breaks down.

In Part 2, we introduce a modular BGP Community architecture on Juniper Junos that separates inbound prefix classification from outbound per-upstream policy chains (AS-Path prepending and selective suppression).

Customer Traffic Engineering Requirements & Topology

Building on our dual-homed lab from Part 1, Figure 1 illustrates how each customer subnet group maps to specific BGP communities and upstream AS-Path behaviors:

ISP BGP Community traffic engineering topology showing per-prefix path preference and suppression across Telia AS 1299 and NTT AS 2914
Figure 1: Per-prefix BGP Community traffic engineering across 45.1.1.0/24–45.1.10.0/24 over Telia (AS 1299) and NTT (AS 2914).

First, confirm that Littlewolf-Backbone is cleanly receiving the customer’s baseline prefix over eBGP:

root@Littlewolf-Backbone> show route receive-protocol bgp 10.0.0.0

inet.0: 11 destinations, 14 routes (11 active, 0 holddown, 0 hidden)
  Prefix                  Nexthop              MED     Lclpref    AS path
* 45.0.0.0/24             10.0.0.0             0                  65535 I

inet6.0: 1 destinations, 1 routes (1 active, 0 holddown, 0 hidden)

A week later, the customer acquires ten contiguous prefixes (45.1.1.0/24 – 45.1.10.0/24) and submits the following inbound traffic-steering requirements:

  • Announce all ten prefixes: 45.1.1.0/24 through 45.1.10.0/24.
  • 45.1.1.0/24 – 45.1.5.0/24: Prefer Telia for inbound return traffic.
  • 45.1.6.0/24 – 45.1.8.0/24: Prefer NTT for inbound return traffic.
  • 45.1.9.0/24: Leave path selection unmanipulated so the customer can steer it on demand.
  • 45.1.10.0/24: Advertise exclusively to NTT—never to Telia, even during an NTT link failure.

How BGP Communities Work: Match & Action

Aside from a handful of well-known communities with standardized semantics (such as no-export and no-advertise), BGP communities are simply optional transitive metadata tags carried alongside prefixes—they take no action unless a router’s routing policy explicitly matches them.

Conceptually, a BGP community policy behaves just like an if/then block in Bash:

#!/bin/bash
count=100
if [ $count -eq 100 ]
then
  echo "Count is 100"
fi

In Juniper Junos, you declare a named community under policy-options and evaluate it inside a policy-statement:

[edit policy-options]
+   policy-statement community-example {
+       term first-one {
+           from community reject-trigger; // Match routes carrying the defined community value
+           then reject; // Drop matching routes immediately
+       }
+   }
[edit policy-options]
+   community reject-trigger members 65000:6666;

[edit]
  • Any inbound route carrying 65000:6666 matches first-one and is rejected.
  • Routes without 65000:6666 fall through to subsequent terms or default policy behavior.

Designing the Community Schema & Junos Policy Chain

Because our backbone ASN (65000) is a 32-bit (4-byte) ASN that cannot fit into standard RFC 1997 16-bit ASN:NN encoding, we allocate our internal community dictionary under 65535:NN (in production, 4-byte ASNs can also leverage RFC 8092 BGP Large Communities):

  • 65535:6661 (no-telia): Suppress route advertisement toward Telia (AS 1299).
  • 65535:6662 (no-ntt): Suppress route advertisement toward NTT (AS 2914).
  • 65535:7771 (lower-priority-telia): Prepend 65000 three times when advertising to Telia.
  • 65535:7772 (lower-priority-ntt): Prepend 65000 three times when advertising to NTT.
  • 65535:888 (advertise): Internal authorization tag—only routes carrying this community are permitted to leave toward upstreams.

Next, configure the communities, modular export policies, and inbound classification policy on Littlewolf-Backbone:

[edit policy-options] // Define standard communities per routing action
+   community advertise members 65535:888;
+   community lower-priority-ntt members 65535:7772;
+   community lower-priority-telia members 65535:7771;
+   community no-ntt members 65535:6662;
+   community no-telia members 65535:6661;
[edit policy-options]
+   policy-statement ntt-filter { // Suppress routes tagged with no-ntt (65535:6662) toward NTT
+       term filter-term {
+           from community no-ntt;
+           then reject;
+       }
+   }
+   policy-statement ntt-prepend { // Prepend local ASN 3x toward NTT when tagged 65535:7772, then continue chain
+       term prepend-term {
+           from community lower-priority-ntt; 
+           then {
+               as-path-prepend "65000 65000 65000";
+               next term; // Continue evaluation into the next policy in the export chain
+           }
+       }
+   }
+   policy-statement telia-filter { // Suppress routes tagged with no-telia (65535:6661) toward Telia
+       term filter-term {
+           from community no-telia;
+           then reject;
+       }
+   }
+   policy-statement telia-prepend { // Prepend local ASN 3x toward Telia when tagged 65535:7771, then continue chain
+       term prepend-term {
+           from community lower-priority-telia;
+           then {
+               as-path-prepend "65000 65000 65000";
+               next term; // Continue evaluation into the next policy in the export chain
+           }
+       }
+   }
+   policy-statement bgp-announce { // Advertise only routes explicitly authorized with advertise (65535:888)
+       term announce-bgp {
+           from community advertise;
+           then accept;
+       }
+       term default-reject { // Explicit default-deny guardrail against route leaks
+           then reject;
+       }
+   }
+   policy-statement customer-import { // Inbound classification policy on downstream customer session
+       term lower-ntt { // Steer inbound traffic via Telia by deprioritizing NTT
+           from {
+               route-filter 45.1.1.0/24 exact;
+               route-filter 45.1.2.0/24 exact;
+               route-filter 45.1.3.0/24 exact;
+               route-filter 45.1.4.0/24 exact;
+               route-filter 45.1.5.0/24 exact;
+           }
+           then {
+               community add advertise; // Authorize upstream export
+               community add lower-priority-ntt; // Trigger 3x AS-Path prepend toward NTT
+               accept;
+           }
+       }
+       term lower-telia { // Steer inbound traffic via NTT by deprioritizing Telia
+           from {
+               route-filter 45.1.6.0/24 exact;
+               route-filter 45.1.7.0/24 exact;
+               route-filter 45.1.8.0/24 exact;
+           }
+           then {
+               community add advertise; // Authorize upstream export
+               community add lower-priority-telia; // Trigger 3x AS-Path prepend toward Telia
+               accept;
+           }
+       }
+       term accept-rest { // Allow customer-managed steering without backbone TE tags
+           from {
+               route-filter 45.1.9.0/24 exact;
+           }
+           then {
+               community add advertise; // Authorize upstream export
+               accept;
+           }
+       }
+       term no-telia { // Advertise 45.1.10.0/24 to NTT only (suppress on Telia)
+           from {
+               route-filter 45.1.10.0/24 exact;
+           }
+           then {
+               community add no-telia; // Matched and dropped by telia-filter on Telia export
+               community add advertise; // Still permitted on NTT export via bgp-announce
+               accept;
+           }
+       }
+       term reject-rest { // Reject all unauthorized prefixes from customer
+           then reject;
+       }
+   }
[edit protocols bgp group upstream neighbor 47.0.0.1]
-     export export-client; // Remove legacy baseline export policy
+     export [ telia-prepend telia-filter bgp-announce ]; // Evaluated sequentially left-to-right
[edit protocols bgp group upstream neighbor 74.1.0.1]
-     export export-client; // Remove legacy baseline export policy
+     export [ ntt-prepend ntt-filter bgp-announce ]; // Evaluated sequentially left-to-right
[edit protocols bgp group downstream neighbor 10.0.0.0]
-     import export-client; // Remove legacy baseline import policy
+     import customer-import; // Apply community-tagging customer import policy

Policy-Chain Evaluation Walkthrough

Understanding how Junos evaluates chained export policies ([ *-prepend *-filter bgp-announce ]) from left to right is essential before putting this into production. Figure 2 traces every decision branch from eBGP ingress through upstream advertisement:

Junos BGP community policy evaluation flowchart from customer-import tagging through upstream prepend, filter, and bgp-announce export chain
Figure 2: Step-by-step BGP route validation, community tagging, and export policy-chain evaluation on Littlewolf-Backbone.

The architectural win here is clean separation of concerns: customer-import validates prefix legitimacy and attaches policy intent once, while each upstream neighbor evaluates a reusable pipeline—*-prepend modifies AS-Path and continues via next term, *-filter drops suppressed routes immediately, and bgp-announce enforces a strict default-deny boundary unless 65535:888 is present.

Verifying Best-Path Convergence on Internet-Routes

After committing the configuration, inspect the BGP table on upstream core node Internet-Routes to confirm that AS-Path lengths and best-path markers (>) match every requirement:

Internet-Routes#show ip bgp
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal

 *    45.1.1.0/24      101.1.0.1                              0 2914 65000 65000 65000 65000 65535 i
 *>                    101.0.0.1                              0 1299 65000 65535 i
 *    45.1.2.0/24      101.1.0.1                              0 2914 65000 65000 65000 65000 65535 i
 *>                    101.0.0.1                              0 1299 65000 65535 i
 *    45.1.3.0/24      101.1.0.1                              0 2914 65000 65000 65000 65000 65535 i
 *>                    101.0.0.1                              0 1299 65000 65535 i
 *    45.1.4.0/24      101.1.0.1                              0 2914 65000 65000 65000 65000 65535 i
 *>                    101.0.0.1                              0 1299 65000 65535 i
 *    45.1.5.0/24      101.1.0.1                              0 2914 65000 65000 65000 65000 65535 i
 *>                    101.0.0.1                              0 1299 65000 65535 i
 *>   45.1.6.0/24      101.1.0.1                              0 2914 65000 65535 i
 *                     101.0.0.1                              0 1299 65000 65000 65000 65000 65535 i
 *>   45.1.7.0/24      101.1.0.1                              0 2914 65000 65535 i
 *                     101.0.0.1                              0 1299 65000 65000 65000 65000 65535 i
 *>   45.1.8.0/24      101.1.0.1                              0 2914 65000 65535 i
 *                     101.0.0.1                              0 1299 65000 65000 65000 65000 65535 i
 *    45.1.9.0/24      101.1.0.1                              0 2914 65000 65535 i
 *>                    101.0.0.1                              0 1299 65000 65535 i
 *>   45.1.10.0/24     101.1.0.1                              0 2914 65000 65535 i
  • All ten customer prefixes (45.1.1.0/24 – 45.1.10.0/24) are visible on the Internet core router.
  • 45.1.1.0/24 – 45.1.5.0/24 carry three extra 65000 hops via NTT (101.1.0.1), electing Telia (101.0.0.1) as best path (>).
  • 45.1.6.0/24 – 45.1.8.0/24 carry three extra 65000 hops via Telia, electing NTT (101.1.0.1) as best path.
  • 45.1.9.0/24 keeps unmodified AS-Path lengths on both upstreams.
  • 45.1.10.0/24 is reachable exclusively through NTT; Telia receives no announcement.

Next Up: Automated DDoS Mitigation via RTBH

Every customer steering policy is working cleanly—until a few days later, when the customer urgently reports that one server is under a volumetric DDoS attack saturating the entire transit link.

In Part 3, we extend this exact BGP Community framework to support Remote Triggered Black Hole (RTBH) signaling, translating internal blackhole communities into upstream carrier null-routing actions before attack traffic ever reaches our backbone.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.