# Control BGP Communities

Control communities allow you to **dictate prefix announcements** and manipulate path attributes dynamically. Attach these communities to routes you announce to AS203314 to control how we propagate them.

> **Traffic Engineering**
>
> These communities give you fine-grained control over route propagation and path prepending outside Hats Network.

## Blackhole & Filtering

| Community      | Action                                 |
| -------------- | -------------------------------------- |
| `203314:0:666` | Do not announce this route (blackhole) |

**Usage**: Stop announcement of a prefix (e.g., during DDoS mitigation or IP address deprecation).

**Note**: Equivalent to standard blackhole community `65535:65281`.

## Propagation Control

Control which types of peers receive your routes:

| Community    | Action                    |
| ------------ | ------------------------- |
| `203314:1:0` | Do not send to Upstream   |
| `203314:1:1` | Do not send to Peering    |
| `203314:1:2` | Do not send to Downstream |

> **Example Use Cases**:
>
> * Use `203314:1:0` to prevent transit from carrying your prefix
> * Use `203314:1:1` to keep traffic limited to IX route servers
> * Use `203314:1:2` to prevent customer leakage

## Geographic Restrictions

Control route propagation based on location:

### Regional

| Community       | Action                                              |
| --------------- | --------------------------------------------------- |
| `203314:2:1`    | Do not send to other regions (Disable Cross Region) |
| `203314:2:2`    | Do not send to other PoPs (Disable Cross PoP)       |
| `203314:201:XX` | Do not send to Region `XX`                          |

**Examples**:

```text
# Keep traffic within Asia only
203314:2:1         # Disable cross-region
203314:201:300     # Exclude North America
203314:201:200     # Exclude Europe
```

### Pop

| Community        | Action                   |
| ---------------- | ------------------------ |
| `203314:202:XXX` | Do not send to PoP `XXX` |

**Examples**:

```text
# Exclude specific PoPs
203314:202:301     # Do not announce via Seattle
203314:202:131     # Do not announce via Tokyo
203314:202:102     # Do not announce via Hong Kong HKG2
```

## Path Prepending

Control AS-path prepending for routes **outside** Hats Network:

> **Scope**: Path prepending only affects routes announced to external peers (upstream, peering, customers)-not internal routing.

| Community      | Action                          |
| -------------- | ------------------------------- |
| `203314:220:1` | Prepend 1x outside Hats Network |
| `203314:220:2` | Prepend 2x outside Hats Network |
| `203314:220:3` | Prepend 3x outside Hats Network |
| `203314:220:4` | Prepend 4x outside Hats Network |
| `203314:220:5` | Prepend 5x outside Hats Network |

**Usage**: Deprioritize specific prefixes for inbound traffic engineering.

## Community Decision Flow

## Usage Examples

### Example 1: Local Traffic Only

Announce a prefix only within a specific region:

```text
# Announce to Asia West only
203314:2:1         # Disable cross-region
```

### Example 2: Deprioritize Backup Prefix

Make a backup prefix less attractive:

```text
# Deprioritize via path prepending
203314:220:3      # Prepend 3x AS203314
```

### Example 3: Selective Peering

Announce only to specific peer types:

```text
# Announce to peering and customers only
203314:1:0        # Do not send to upstream
```

### Example 4: Exclude Location

Prevent announcement via specific location:

```text
# Exclude PoP-specific announcement
203314:202:301    # Do not send via Seattle
```

### Example 5: Combined Control

Combine multiple communities for complex policies:

```text
# Deprioritized, Asia-only, no upstream
203314:1:0        # No upstream
203314:2:1         # Asia only
203314:220:2      # Prepend 2x
```

## Implementation Notes

> **Best Practices**:
>
> 1. **Test before production**: Use `203314:220:1` (1x prepend) to verify communities work
> 2. **Monitor impact**: Check route servers and looking glasses after applying changes
> 3. **Document your policies**: Keep track of which prefixes use which communities
> 4. **Use conservative prepends**: 3x prepend is usually sufficient; 5x is extreme

## Configuration Examples (JunOS / BIRD2)

AS203314 communities are **BGP Large Communities** (RFC 8092). On JunOS they are written with the
`large:` prefix (for example `large:203314:0:666`). In BIRD2 they are handled via
`bgp_large_community` with `(203314, 0, 666)` tuples.

> **Export Policy Safety Default (Strongly Recommended)**
>
> The BIRD2 examples below are **export policies**. The default action should be `reject;` to prevent
> route leaks if someone copy-pastes into production.\
> For JunOS, it's also recommended to add a final `term REJECT-ALL then reject` as a safety catch-all.

### Junos

**Example: Blackhole (`203314:0:666`)**

```bash
set policy-options community HATS-BLACKHOLE members large:203314:0:666

set policy-options policy-statement EXPORT-TO-HATS term BLACKHOLE from route-filter 203.0.113.0/24 exact
set policy-options policy-statement EXPORT-TO-HATS term BLACKHOLE then community add HATS-BLACKHOLE
set policy-options policy-statement EXPORT-TO-HATS term BLACKHOLE then accept
set policy-options policy-statement EXPORT-TO-HATS term REJECT-ALL then reject
```

**Example: No Upstream (`203314:1:0`) + Prepend 3x (`203314:220:3`)**

```bash
set policy-options community HATS-NO-UPSTREAM members large:203314:1:0
set policy-options community HATS-PREPEND-3X members large:203314:220:3

set policy-options policy-statement EXPORT-TO-HATS term BACKUP from route-filter 203.0.113.0/24 exact
set policy-options policy-statement EXPORT-TO-HATS term BACKUP then community add [ HATS-NO-UPSTREAM HATS-PREPEND-3X ]
set policy-options policy-statement EXPORT-TO-HATS term BACKUP then accept
set policy-options policy-statement EXPORT-TO-HATS term REJECT-ALL then reject
```

**Example: Keep in-region + Exclude a PoP (`203314:2:1` + `203314:202:253`)**

```bash
set policy-options community HATS-NO-CROSS-REGION members large:203314:2:1
set policy-options community HATS-NO-AMS members large:203314:202:253

set policy-options policy-statement EXPORT-TO-HATS term LOCAL-ONLY from route-filter 203.0.113.0/24 exact
set policy-options policy-statement EXPORT-TO-HATS term LOCAL-ONLY then community add [ HATS-NO-CROSS-REGION HATS-NO-AMS ]
set policy-options policy-statement EXPORT-TO-HATS term LOCAL-ONLY then accept
set policy-options policy-statement EXPORT-TO-HATS term REJECT-ALL then reject
```

### Bird2

**Example: Blackhole (`203314:0:666`)**

```bird2
filter export_to_hats_v4 {
  if net = 203.0.113.0/24 then {
    bgp_large_community.add((203314, 0, 666));
    accept;
  }
  reject; # Safety default
}
```

**Example: No Upstream (`203314:1:0`) + Prepend 3x (`203314:220:3`)**

```bird2
filter export_to_hats_v4 {
  if net = 203.0.113.0/24 then {
    bgp_large_community.add((203314, 1, 0));
    bgp_large_community.add((203314, 220, 3));
    accept;
  }
  reject; # Safety default
}
```

**Example: Keep in-region + Exclude a PoP (`203314:2:1` + `203314:202:253`)**

```bird2
filter export_to_hats_v4 {
  if net = 203.0.113.0/24 then {
    bgp_large_community.add((203314, 2, 1));
    bgp_large_community.add((203314, 202, 253));
    accept;
  }
  reject; # Safety default
}
```

## Related Information

* **[PoP Codes](/docs/community/pop-codes)** - Reference for PoP numbers (XXX) in geographic restrictions
* **[Region Codes](/docs/community/region-codes)** - Reference for region numbers (XX) in geographic restrictions
* **[Internal Communities](/docs/community/internal-communities)** - Communities we attach to routes we announce

> **Important**: Control communities are applied to routes **you announce to AS203314**. They do not affect routes we announce to you.

---

## License and attribution

- **Canonical source:** [View the human-readable HTML page](https://hatsnet.io/docs/community/control-communities).
- **Original documentation:** © Hats Network Inc., licensed under [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/).
- **Full terms:** [Content and Data License](https://hatsnet.io/docs/legal/content-and-data-license) — includes attribution requirements, third-party material, trademarks, source code and other exclusions.
