# Internal BGP Communities

Internal communities indicate **where routes are learned from** and whether they are uniquely announced. These communities help you identify the source and path of routes received from AS203314.

> **Community Format:** `203314:XXX:YY` where `XXX` is the category and `YY` is the specific value.

## Route Origin

These communities indicate **how** a route was learned by Hats Network:

| Community        | Description                          | Unique |
| ---------------- | ------------------------------------ | ------ |
| `203314:110:10`  | Route learned from Upstream          | Yes    |
| `203314:110:20`  | Route learned from Downstream        | Yes    |
| `203314:110:30`  | Route learned from Peering           | Yes    |
| `203314:110:110` | Route originated within Hats Network | Yes    |

**Unique** means this route is only announced via this method-if you see `203314:110:30`, the route is exclusively available via peering.

## PoP-Based Communities

These communities identify **which PoP** a route was learned at or passed through:

### Learned

Routes learned **at** a specific PoP (entry point):

| Community        | Description                | Unique |
| ---------------- | -------------------------- | ------ |
| `203314:120:XXX` | Route learned at PoP `XXX` | Yes    |

**Example**: `203314:120:101` means the route was learned at Hong Kong (HKG1).

### Passed

Routes that **passed through** a PoP (transit):

| Community        | Description                    | Unique |
| ---------------- | ------------------------------ | ------ |
| `203314:125:XXX` | Route passed through PoP `XXX` | No     |

**Example**: `203314:125:101` means the route passed through Hong Kong (HKG1).

## Region-Based Communities

These communities identify **which region** a route was learned in or passed through:

### Learned

Routes learned **within** a specific region:

| Community       | Description                  | Unique |
| --------------- | ---------------------------- | ------ |
| `203314:130:XX` | Route learned in Region `XX` | Yes    |

**Example**: `203314:130:100` means the route was learned in Asia (West).

### Passed

Routes that **passed through** a region:

| Community       | Description                      | Unique |
| --------------- | -------------------------------- | ------ |
| `203314:135:XX` | Route passed through Region `XX` | No     |

**Example**: `203314:135:100` means the route passed through Asia (West).

## Usage Examples

### Identify Route Source

Determine if a route comes from peering, upstream, or our customers:

```bird2
# These large communities are attached by AS203314 on routes you receive.
# You typically match them in your import policy:
filter import_prefer_peering_v4 {
  if (203314, 110, 30) ~ bgp_large_community then bgp_local_pref = 200; # prefer peering-learned routes
  if (203314, 110, 10) ~ bgp_large_community then bgp_local_pref = 80; # de-prioritize upstream-learned routes
  accept;
}
```

### Identify Entry Location

Determine where a route entered our network:

```bird2
filter import_prefer_asia_pops_v4 {
  if (203314, 120, 101) ~ bgp_large_community then bgp_local_pref = 200; # entered at HKG1 (Hong Kong)
  if (203314, 120, 131) ~ bgp_large_community then bgp_local_pref = 180; # entered at TYO2 (Tokyo)
  accept;
}
```

### Filter by Region

Accept routes only from specific regions:

```bird2
# Only accept routes learned in Asia West
filter import_only_asia_west_v4 {
  if (203314, 130, 100) ~ bgp_large_community then accept;
  reject;
}

# Reject routes that passed through Europe (both West=200 and East=250)
filter import_reject_europe_transit_v4 {
  if (203314, 135, 200) ~ bgp_large_community then reject;
  if (203314, 135, 250) ~ bgp_large_community then reject;
  accept;
}
```

## Policy Examples (JunOS / BIRD2)

Internal communities are also **BGP Large Communities**. You can match them in your import policy
to influence local preference, selection, or filtering.

### Junos

**Prefer routes learned in Asia West (`203314:130:100`)**

```bash
set policy-options community HATS-REGION-ASIA-W members large:203314:130:100

set policy-options policy-statement IMPORT-FROM-HATS term ASIA-W from community HATS-REGION-ASIA-W
set policy-options policy-statement IMPORT-FROM-HATS term ASIA-W then local-preference 200
set policy-options policy-statement IMPORT-FROM-HATS term ASIA-W then accept
```

**Reject routes learned from Upstream (`203314:110:10`)**

```bash
set policy-options community HATS-ORIGIN-UPSTREAM members large:203314:110:10

set policy-options policy-statement IMPORT-FROM-HATS term NO-UPSTREAM from community HATS-ORIGIN-UPSTREAM
set policy-options policy-statement IMPORT-FROM-HATS term NO-UPSTREAM then reject
```

### Bird2

**Prefer routes learned in Asia West (`203314:130:100`)**

```bird2
filter import_from_hats_v4 {
  if (203314, 130, 100) ~ bgp_large_community then {
    bgp_local_pref = 200;
    accept;
  }
  accept;
}
```

**Reject routes learned from Upstream (`203314:110:10`)**

```bird2
filter import_from_hats_v4 {
  if (203314, 110, 10) ~ bgp_large_community then reject;
  accept;
}
```

## Related Information

* **[PoP Codes](/docs/community/pop-codes)** - Reference for PoP numbers (XXX)
* **[Region Codes](/docs/community/region-codes)** - Reference for region numbers (XX)
* **[Control Communities](/docs/community/control-communities)** - Traffic engineering communities

> **Tip**: Internal communities are automatically attached to routes we announce to you. Use them to make informed routing decisions based on route origin and location.

---

## License and attribution

- **Canonical source:** [View the human-readable HTML page](https://hatsnet.io/docs/community/internal-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.
