# Region Codes

Regions are grouped by **geographic area** with 2-digit codes used in community strings like `203314:130:XX` and `203314:201:XX`.

> **Usage**: These codes identify geographic regions in internal communities (`130:XX`, `135:XX`) and control communities (`201:XX`).

## Region Code Reference

| Region Name | Area  | Code | Notes                        |
| ----------- | ----- | ---- | ---------------------------- |
| Asia        | West  | 100  | Hong Kong, Taiwan            |
| Asia        | East  | 150  | Japan, Singapore             |
| Europe      | West  | 200  | UK, Ireland, France          |
| Europe      | East  | 250  | Germany, Netherlands, Russia |
| Americas    | North | 300  | USA, Canada                  |
| Americas    | South | 350  | Brazil, Argentina            |
| Australia   | West  | 400  | Perth                        |
| Australia   | East  | 450  | Melbourne, Sydney            |
| Antarctica  | -     | 500  | Research networks            |

## Regional Groupings

### Asia (100, 150)

**Asia West (100)**: Hong Kong, Taiwan, mainland China

**Asia East (150)**: Japan, Korea, Singapore, Southeast Asia

### Europe (200, 250)

**Europe West (200)**: UK, Ireland, France, Benelux, Iberia

**Europe East (250)**: Germany, DACH, Netherlands, Nordics, Eastern Europe

### Americas (300, 350)

**North America (300)**: United States, Canada, Mexico

**South America (350)**: Brazil, Argentina, Chile, Colombia

### Oceania (400, 450)

**Australia West (400)**: Western Australia

**Australia East (450)**: Eastern states (NSW, VIC, QLD)

## Using Region Codes

### In Internal Communities

Identify where a route was learned:

```bird2
# Learned-in tags (set by AS203314 on routes you receive):
# (203314, 130, 100) -> Asia West
# (203314, 130, 150) -> Asia East
# (203314, 130, 300) -> North America

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

### In Control Communities

Control geographic propagation:

```bird2
bgp_large_community.add((203314, 2, 1)); # Disable cross-region
bgp_large_community.add((203314, 201, 300)); # Exclude North America
bgp_large_community.add((203314, 201, 200)); # Exclude Europe
```

### Configuration Snippets (JunOS / BIRD2)

Region codes are used in large communities like `203314:201:XX` (exclude region) and
`203314:130:XX` (learned in region). Below are minimal examples you can adapt.

### Junos

**Exclude North America (`203314:201:300`)**

```bash
set policy-options community HATS-NO-NA members large:203314:201:300

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

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

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

set policy-options policy-statement IMPORT-FROM-HATS term ASIA-W from community HATS-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
```

### Bird2

**Exclude North America (`203314:201:300`)**

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

**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;
}
```

### Regional Filtering Examples

**Accept only Asian routes**:

```text
# Allow only Asia West and Asia East
if (community matches 203314:130:1*) then accept
else reject
```

**Prefer local region**:

```text
# Higher local preference for Asia West
if (community matches 203314:130:100) then localpref 200
if (community matches 203314:130:150) then localpref 150
if (community matches 203314:130:300) then localpref 100
```

## Related Information

* **[PoP Codes](/docs/community/pop-codes)** - Specific location codes within regions
* **[Internal Communities](/docs/community/internal-communities)** - Using region codes in location-based communities
* **[Control Communities](/docs/community/control-communities)** - Using region codes in traffic engineering

> **Tip**: Region codes are ideal for high-level geographic traffic engineering when you don't need PoP-level granularity.

---

## License and attribution

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