Project: a colocation
In this project you run the network of a Renting space, power, and cooling in someone else's data center for your own servers and network equipment. business. Customers, the A customer that gets its own networks inside yours, such as a colocation customer with its own servers in your racks., put their servers in your racks, and you give each one its own network.
This is Circuit's colocation example. It adds a switch and tenants to the edge router you already built.
What a tenant buys
A data center rents out room in its racks, measured in The height of one slot in a standard rack: 1.75 inches, or 44.45 mm. Equipment is sold as 1U, 2U, and so on, and a full rack is often 42U.. Power and cooling come with it. To reach anyone outside the rack, a tenant needs a A cable the data center runs between two customers' racks, or between a customer and a network, in the same building. to a network, and in this project that network is yours. You sell this over it:
- Internet access, carried by your edge router to your transit and your exchange.
- Public addresses, a block from your own space, routed to the tenant's VLAN. Your router is the gateway, at the first address.
- Ports on your A switch at the top of a rack of servers. Every server in the rack is cabled to it, and it has a few uplinks to the next layer. ToR for short. switch, one per server.
- A private network, if the tenant wants its servers to talk to each other without going through the router or the internet.
Start the project
Install Circuit, then copy the example's files into the project:
my-network/
circuit.ts your AS, your prefixes, communities, and checks
sites/dc-1/site.ts what both devices share
sites/dc-1/edge-01.ts the router
sites/dc-1/tor-01.ts the top-of-rack switch
tenants/netflix.ts one file per tenant
tenants/index.ts every tenant, merged
lib/checks.ts a check of your ownThe names in this project
As in the edge router, the transit is Hurricane Electric and the exchange is DE-CIX. Replace their addresses, AS numbers, and port names with what your providers give you.
A tenant is one file
// Tenant netflix: its VLANs, its gateway on the router, its servers' ports on the switch, and a cap on UDP toward it.
// Copy this file for a new tenant, and add it to index.ts.
const vlans = literal({
"netflix-internet": { id: 1001, description: "Tenant netflix internet" },
"netflix-private": { id: 2001, description: "Tenant netflix private" },
});
export const netflix = {
parts: {
"edge-01": part("device", {
switching: { vlans: { "netflix-internet": vlans["netflix-internet"] } },
interfaces: {
ethernet: { "100g-1": { trunk_vlans: ["netflix-internet"] } },
vlan_interface: {
"netflix-internet": {
vlan: "netflix-internet",
description: "Tenant netflix",
addresses: ["198.51.100.9/29", "2001:db8:100:1::1/64"],
},
},
},
}),
"tor-01": part("device", {
switching: { vlans },
interfaces: {
ethernet: {
"40g-1": { trunk_vlans: ["netflix-internet"] },
"10g-1": { description: "netflix server 1", trunk_vlans: ["netflix-internet", "netflix-private"] },
"10g-2": { description: "netflix server 2", trunk_vlans: ["netflix-internet", "netflix-private"] },
},
},
}),
},
rules: {
edge_acl: part("acl", [
{
description: "netflix: UDP above 1G",
if: { vlan: ["transit", "exchange"], protocol: "udp", dst: "198.51.100.8/29" },
then: "accept",
rate: "1G",
},
]),
},
};The file of the tenant Netflix holds everything Netflix has, on every device, as parts:
- On the router,
edge-01, it adds the VLANnetflix-internet, carried on the trunk to the switch. It also adds a VLAN interface with the gateways of Netflix, the first address of each of its blocks. - On the switch,
tor-01, it adds both VLANs of Netflix: the public one on the uplink to the router, and both on its two server ports. - A rule for the router's switch chip caps UDP toward the block of Netflix at 1G, so a flood aimed at Netflix can't fill everyone else's uplinks.
The file writes out every name, address, VLAN ID, and port of Netflix by hand, so a search for netflix finds every one.
// Every tenant, merged whole. A new tenant joins the list.
// `empty` holds no tenant. It keeps tenants.parts and tenants.rules there for the devices when the last tenant leaves.
import { netflix } from "./netflix";
const empty = { parts: {}, rules: { edge_acl: part("acl", []) } };
export const tenants = merge([empty, netflix]);tenants/index.ts merges every tenant into one value. A new tenant joins the list.
The router and the switch
// The top-of-rack switch: the tenants' servers, from each tenant's own file, and one uplink to the router.
import { as64500 } from "../../circuit";
import { tenants } from "../../tenants";
import { dc_1 } from "./site";
export default as64500.device({
name: "tor-01",
include: [tenants.parts],
site: "dc-1",
role: "Top-of-rack switch",
platform: "vrp",
model: "CE6855-48S6Q-HI",
connection: { host: "10.0.99.2", user: "operator" },
system: {
timezone: dc_1.timezone,
ntp: { servers: ["10.0.99.1"] },
users: { operator: { role: "admin", password: secret("TOR_01_PASSWORD") } },
},
management: { allow: [dc_1.addresses.management], ssh: {} },
interfaces: {
ethernet: {
"40g-1": { description: "edge-01 qsfp28-1-1", trunk_vlans: ["mgmt"], link: { device: "edge-01", port: "100g-1" } },
},
vlan_interface: {
mgmt: { vlan: "mgmt", addresses: [dc_1.addresses.tor_01] },
},
},
switching: {
vlans: { mgmt: dc_1.vlans.mgmt },
stp: {},
lldp: true,
},
routing: {
static_routes: [{ prefix: presets.default_routes.ipv4, next_hop: "10.0.99.1" }],
},
});The switch writes only what is its own: its management VLAN, its uplink, and its address. include: [tenants.parts] takes from every tenant the part keyed by tor-01, as if it were written there.
// The router: the transit, the exchange, and each tenant's gateway, which comes from the tenant's own file.
import { as64500 } from "../../circuit";
import { tenants } from "../../tenants";
import { dc_1 } from "./site";
export default as64500.device({
name: "edge-01",
include: [tenants.parts],
site: "dc-1",
role: "Edge router",
platform: "routeros",
model: "CCR2216-1G-12XS-2XQ",
connection: { host: "10.0.0.1", user: "operator" },
system: {
timezone: dc_1.timezone,
ntp: { servers: ["pool.ntp.org"] },
users: { operator: { role: "admin", password: secret("EDGE_01_PASSWORD") } },
},
management: { allow: [dc_1.addresses.management], ssh: {} },
interfaces: {
ethernet: {
"1g-1": { description: "Management", addresses: ["10.0.0.1/24"] },
"25g-1": { description: "Hurricane Electric", access_vlan: "transit", ingress_acl: "edge" },
"25g-2": { description: "DE-CIX", access_vlan: "exchange", ingress_acl: "edge" },
"100g-1": {
description: "tor-01 40GE1/0/1",
speed: "40g",
trunk_vlans: ["mgmt"],
link: { device: "tor-01", port: "40g-1" },
},
},
vlan_interface: {
mgmt: { vlan: "mgmt", addresses: [dc_1.addresses.router_on_switches] },
transit: { vlan: "transit", addresses: ["203.0.113.2/30"] },
exchange: { vlan: "exchange", addresses: ["192.0.2.10/24", "2001:db8:ffff::10/64"] },
},
},
switching: {
vlans: {
mgmt: dc_1.vlans.mgmt,
transit: { id: 300, description: "IP transit from Hurricane Electric, AS6939" },
exchange: { id: 200, description: "DE-CIX peering LAN" },
},
// In the switch chip, before a packet reaches the router's CPU. Each tenant's own rules come last.
acls: {
edge: merge([
{ description: "Our own space", if: { vlan: ["transit", "exchange"], src: as64500.prefixes.ours.v4 }, then: "drop" },
{ description: "Private ranges", if: { vlan: ["transit", "exchange"], src: presets.rfc1918 }, then: "drop" },
tenants.rules.edge_acl,
]),
},
},
routing: {
router_id: "203.0.113.2",
static_routes: [
{ prefix: as64500.prefixes.ours.v4, blackhole: true, description: "Originate" },
{ prefix: as64500.prefixes.ours.v6, blackhole: true, description: "Originate" },
],
bgp: {
originated_prefixes: [as64500.prefixes.ours.v4, as64500.prefixes.ours.v6],
neighbors: {
"hurricane-electric": {
address: "203.0.113.1",
remote_as: 6939,
description: "Hurricane Electric",
role: "provider",
max_prefixes: 1_200_000,
import_policy: "transit-import",
export_policy: "export",
communities: { groups: ["transit"] },
},
"de-cix-rs-v4": {
address: "192.0.2.1",
remote_as: 6695,
description: "DE-CIX route server",
role: "rs",
max_prefixes: 100_000,
import_policy: "exchange-import",
export_policy: "export",
communities: { groups: ["exchange"] },
},
},
},
prefix_sets: {
ours: { prefixes: as64500.prefixes.ours },
"bogons-v4": { prefixes: presets.bogons.ipv4 },
"bogons-v6": { prefixes: presets.bogons.ipv6 },
},
policies: {
sanity: presets.bgp_sanity,
"transit-import": [
{ call: "sanity" },
{ description: "Bogons", if: { prefix_set: "bogons-v4" }, then: "reject" },
{ description: "Bogons", if: { prefix_set: "bogons-v6" }, then: "reject" },
{ if: { prefix_set: "ours" }, then: "reject" },
{ communities: "import" },
{ set: { local_pref: 100 }, then: "accept" },
],
"exchange-import": [
{ call: "sanity" },
{ description: "Bogons", if: { prefix_set: "bogons-v4" }, then: "reject" },
{ description: "Bogons", if: { prefix_set: "bogons-v6" }, then: "reject" },
{ if: { prefix_set: "ours" }, then: "reject" },
{ communities: "import" },
{ set: { local_pref: 200 }, then: "accept" },
],
export: [
{ communities: "export" },
{ description: "Our own space", if: { prefix_set: "ours" }, then: "accept" },
{ description: "Nothing else leaves", then: "reject" },
],
},
},
firewall: {
address_sets: {
management: [dc_1.addresses.management],
"bgp-neighbors": bgpNeighbors(),
},
filter: {
input: {
default_action: "drop",
rules: [
{ description: "Replies", if: { connection_state: ["established", "related"] }, then: "accept" },
{ description: "Ping", if: { protocol: "icmp" }, then: "accept" },
{ description: "Management", if: { src_address_set: "management" }, then: "accept" },
{
description: "BGP",
if: { src_address_set: "bgp-neighbors", protocol: "tcp", dst_port: presets.ports.bgp },
then: "accept",
},
],
},
forward: {
rules: presets.bad_tcp_flags,
},
},
},
});The router is the edge router, with include: [tenants.parts] too. The tenants' ACL rules are placed with merge, after the router's own two in edge.
Here a second tenant, Akamai, has joined. It has a public network and a private one.
Pick a packet to send.
The network file and its check
// The network, AS64500: a colocation site whose tenants each get their own VLANs, addresses, and ports.
import { blocksApart } from "./lib/checks";
export const as64500 = circuit({
asn: 64500,
prefixes: {
ours: { v4: "198.51.100.0/24", v6: "2001:db8:100::/48" },
},
communities: {
groups: { transit: { value: 1 }, exchange: { value: 2 } },
learned_from_group: { code: 1 },
},
sites: {
"dc-1": { description: "The data center: one router, and one top-of-rack switch for the tenants' servers." },
},
checks: {
exports_end_in_reject: true,
imports_end_in_accept_or_reject: true,
same_vlan_ids: true,
blocks_apart: blocksApart,
},
});// This network's own checks, beside Circuit's built-in ones. circuit.ts turns them on in `checks`.
import type { Check } from "circuit";
/** No two networks on one device overlap, such as two tenants' blocks: each address belongs to one tenant. */
export const blocksApart: Check = (network) =>
network.devices.flatMap((device) => {
const networks = Object.entries(device.interfaces?.vlan_interface ?? {}).flatMap(([name, vlan_interface]) =>
(vlan_interface?.addresses ?? []).map((entry) => ({ name, prefix: typeof entry === "string" ? entry : entry.address }))
);
return networks.flatMap((one, index) =>
networks
.slice(index + 1)
.filter((other) => other.name !== one.name && address.overlaps(one.prefix, other.prefix))
.map((other) => ({
device: device.name,
path: `interfaces.vlan_interface.${other.name}`,
message: `${other.prefix} overlaps ${one.prefix} on ${one.name}. Give each its own block.`,
}))
);
});Circuit knows nothing about tenants, so it can't know that two tenants' blocks must not overlap. The example says it in a check of its own, blocks_apart, with the address helper: no two networks on one device overlap.
Add a tenant
A new tenant, Akamai, wants one server on its public network. Copy tenants/netflix.ts to tenants/akamai.ts, and change every name, VLAN ID, address, and port to Akamai's. Then add akamai to tenants/index.ts. Each choice can clash with Netflix, and Circuit says how.
0 of 4 decided
const vlans = literal({
"akamai-internet": { id: 1002, description: "Tenant akamai internet" },
"akamai-private": { id: 2002, description: "Tenant akamai private" },
});
export const akamai = {
parts: {
"edge-01": part("device", {
switching: { vlans: { "akamai-internet": vlans["akamai-internet"] } },
interfaces: {
ethernet: { "100g-1": { trunk_vlans: ["akamai-internet"] } },
vlan_interface: {
"akamai-internet": { vlan: "akamai-internet", description: "Tenant akamai", addresses: ["198.51.100.17/29", "2001:db8:100:2::1/64"] },
},
},
}),
"tor-01": part("device", {
switching: { vlans: { "akamai-internet": vlans["akamai-internet"] } },
interfaces: {
ethernet: {
"40g-1": { trunk_vlans: ["akamai-internet"] },
"10g-3": { description: "akamai server 1", access_vlan: "akamai-internet" },
},
},
}),
},
};
Make the decisions, then run validate and diff.
Every clash stops validate, and each message says where it is:
- A port that two tenants write with two values.
- Two tenants' VLANs with one ID.
- Blocks that overlap, from the example's own check.
The port matters most: without the stop, one tenant would silently take the other's port.
When a tenant leaves
A tenant leaves when you remove it from tenants/index.ts. The next apply takes away everything it had, everywhere. Say Akamai has joined, and then Netflix leaves. circuit diff plans 22 commands for the router and 19 for the switch. On the switch:
tor-01: 19 command(s) in 4 step(s)
VLANs no longer used
- vlan 1001
- vlan 2001
- vlan batch 1001 2001
interface 10GE1/0/1
- port trunk allow-pass vlan 1001 2001
- undo port trunk allow-pass vlan 1
- port link-type trunk
- description netflix server 1
+ shutdown
interface 10GE1/0/2
- port trunk allow-pass vlan 1001 2001
- undo port trunk allow-pass vlan 1
- port link-type trunk
- description netflix server 2
+ shutdown
interface 40GE1/0/1
- port trunk allow-pass vlan 99 1001 to 1002
+ port trunk allow-pass vlan 99 1002The ports of Netflix are shut, not left open for whoever plugs in next. On the router, its VLAN, interface, and addresses go. The switch-chip rules are replaced as a whole, because Circuit rewrites an ordered list in its new order rather than editing it in place. The block of Netflix, 198.51.100.8/29, is free again, but wait until its servers are unplugged before you hand it to someone else.
Where to go from here
Another switch is another device file with include: [tenants.parts], and each tenant's file gets a part keyed by that switch. When many tenants share one shape, a function in lib/ may build their parts from their data. Whoever changes that function then needs to read TypeScript.
Further reading
- Data center glossary: colocation, cross-connects, and other words of the trade.
- Rack unit: the size of 1U and the usual 42U rack.
- Data centers 101, from TeleGeography: cross-connects and rack density.