Skip to content

ElementaryLesson 4 of 9

Trunks ​

A trunk is a port that carries several VLANs over one cable. On a trunk, each frame carries a small tag with its VLAN number, so the device at the other end knows which VLAN the frame is in.

One cable, many VLANs ​

In VLANs, the router needed one cable for each VLAN. Two switches on two floors have the same problem: three VLANs take three cables, and every new VLAN takes another.

A A port that carries several VLANs at once, with a tag on each frame that says which VLAN it is in. Trunks join switches to each other, and to routers. carries them all on one. Here is what happens to a frame from a camera on the first floor to a recorder on the second:

  1. The camera sends an ordinary frame to its access port, in VLAN 40. It knows nothing about VLANs.
  2. The first switch sends the frame out of its trunk port, and adds a tag that says "VLAN 40" as it goes.
  3. The second switch receives it on its trunk port, reads the tag, and knows the frame is in VLAN 40.
  4. It takes the tag off and sends the frame out of its access port in VLAN 40, to the recorder.

The devices at the ends never see a tag. Only the trunk does.

Tagged and untagged ​

Network people describe a frame by whether it has that tag:

  • An untagged frame is a plain one, with no tag. Laptops, printers, and cameras send and receive only these, and an access port sends only these out.
  • A tagged frame carries a tag with its VLAN number. A trunk carries these, so the far end can tell the VLANs apart.

So the same two kinds of port are often described by what goes over them:

PortAlso calledWhat goes over itIn Circuit
Access portAn untagged portFrames of one VLAN, untaggedaccess_vlan: "cameras"
Trunk portA tagged portFrames of several VLANs, each taggedtrunk_vlans: [...]
Both at onceA trunk with a native VLAN, or a hybrid portSeveral VLANs tagged, and one VLAN untaggedtrunk_vlans and native_vlan

Vendors use both ways of speaking. Some ask whether a port is access or trunk. Others, such as a MikroTik router's bridge, ask VLAN by VLAN which ports carry it tagged and which carry it untagged. Circuit writes it in the form each device expects.

The last row is for a device that sends some frames untagged on a trunk, such as a wireless access point. Its own management traffic comes untagged, and the Wi-Fi networks it offers arrive tagged. The On a trunk, the one VLAN whose frames cross it untagged. Every other VLAN on the trunk is tagged. is the VLAN those untagged frames go into. Leave it out unless the other end needs it. When you use it, both ends must agree on it.

CheckA trunk carries VLANs 20 and 30 tagged, with VLAN 10 as its native VLAN. A frame arrives on it with no tag. Which VLAN is it in?

All the VLANs on a trunk share its speed. If the guests on one floor download a large file, there is that much less room on the trunk for everyone else. So a trunk is usually the fastest port a switch has.

Try itSend frames over a trunk
trunk, port 40g-1 at both endsswitch-a carries 20, 30, 40switch-b carries 20, 30, 40switch-aswitch-bLaptopVLAN 20Guest Wi-Fi AVLAN 30CameraVLAN 40DesktopVLAN 20Guest Wi-Fi BVLAN 30RecorderVLAN 40
1. VLANs switch-a carries on its trunk port
1. VLANs switch-b carries on its trunk port

Send from the camera to the recorder and watch the label over the frame. Then turn VLAN 40 off at one end of the trunk and send again.

switch-a.ts, port 40g-1
"40g-1": {
    description: "switch-b 40GE1/0/1",
    trunk_vlans: ["home", "guests", "cameras"],
    link: { device: "switch-b", port: "40g-1" },
},
switch-b.ts, port 40g-1
"40g-1": {
    description: "switch-a 40GE1/0/1",
    trunk_vlans: ["home", "guests", "cameras"],
    link: { device: "switch-a", port: "40g-1" },
},
Terminal
$ circuit validate
✔ 2 device(s), no errors.

When one end stops carrying a VLAN, nothing tells the camera. Its frames never arrive. So both ends must agree, and a tool should check that they do.

CheckThe camera on switch-a is in VLAN 40. switch-a carries 20, 30, and 40 on its trunk, but switch-b carries only 20 and 30. What happens to the camera’s frames for the recorder on switch-b?

The tag ​

The tag is defined by a standard called The IEEE standard that adds a VLAN tag to an Ethernet frame. People often call it dot1q.. It is 4 bytes, put into the frame header right after the hardware address the frame is from. The VLAN ID is in its last 12 bits.

Twelve bits can count from 0 to 4095, as you saw in Counting like a computer. The standard keeps two of those values back, which is why a VLAN ID is 1 to 4094. Try some numbers, including 0, 4095, and 5000:

Try itWrite a VLAN ID into the tag

A frame on a trunk, with the tag inside the frame header:

  1. To6 bytes
  2. From6 bytes
  3. VLAN tag4 bytes
  4. Type2 bytes
  5. Packetup to 1500 bytes
  6. Check4 bytes

The tag's 32 bits:

204810245122561286432168421
000000010100

VLAN 20 fits in the tag's twelve bits. That leaves 1 to 4094 for VLANs: 4094 networks on one cable.

switch.ts, the VLANs
switching: {
    vlans: {
        home: { id: 20, description: "Home" },
        guests: { id: 20, description: "Guests" },
        cameras: { id: 40, description: "Cameras" },
    },
},
Terminal
$ circuit validate
  error  switch: switching.vlans home and guests share id 20

1 error(s).
CheckWhy can there be no VLAN 5000?

Trunks in Circuit ​

A trunk port lists its VLANs in trunk_vlans, by name. Here is the whole file of switch-a from the widget. The VLANs come from site.ts, one file both switches share, so the two can never have different numbers for the same VLAN. literal keeps each value exactly as written, so your editor can check the VLAN names where a device uses them.

ts
// sites/office/site.ts
export const office = literal({
    vlans: {
        home: { id: 20, description: "Home" },
        guests: { id: 30, description: "Guests" },
        cameras: { id: 40, description: "Cameras" },
    },
});
ts
// sites/office/switch-a.ts
import { as64500 } from "../../circuit";
import { office } from "./site";

export default as64500.device({
    name: "switch-a",
    site: "office",
    platform: "vrp",
    model: "CE6855-48S6Q-HI",
    connection: { host: "192.168.10.2", user: "operator" },
    system: {
        users: { operator: { role: "admin", password: secret("SWITCH_PASSWORD") } },
    },

    interfaces: {
        ethernet: {
            "10g-1": { description: "Laptop", access_vlan: "home" },
            "10g-2": { description: "Guest access point", access_vlan: "guests" },
            "10g-3": { description: "Camera", access_vlan: "cameras" },
            "40g-1": {
                description: "switch-b 40GE1/0/1",
                trunk_vlans: ["home", "guests", "cameras"],
                link: { device: "switch-b", port: "40g-1" },
            },
        },
    },
    switching: {
        vlans: office.vlans,
    },
});

The link says what is at the other end of the cable: switch-b, port 40g-1. switch-b has the same port with a link back to switch-a. With a link on both ends, circuit validate checks that the two ports carry the same VLANs in the same way. When switch-b leaves out guests, it stops before anything is sent:

text
  error  switch-a: interfaces.ethernet.40g-1.link: interfaces.ethernet.40g-1 carries VLANs 20, 30, 40 tagged, and switch-b interfaces.ethernet.40g-1 carries VLANs 20, 40 tagged
  error  switch-b: interfaces.ethernet.40g-1.link: interfaces.ethernet.40g-1 carries VLANs 20, 40 tagged, and switch-a interfaces.ethernet.40g-1 carries VLANs 20, 30, 40 tagged

2 error(s).

This is the most common trunk mistake: someone adds a new VLAN to the trunk at one end and forgets the other. Each switch on its own is set up correctly, so only a check that reads both ends finds it.

Without link, Circuit cannot know which ports face each other, so it cannot check them. Write it on both ends of every cable between two of your devices. Circuit Studio draws your cables from the same links.

A native VLAN in Circuit

native_vlan says which VLAN the untagged frames on a trunk go into: { trunk_vlans: ["guests", "home"], native_vlan: "mgmt" }. link checks that both ends agree on it, as it does for the tagged VLANs.

A trunk to the router ​

A router can be on a trunk too, so one cable carries every VLAN to it. This is how Circuit's single-site example joins its router and switch:

ts
// router.ts, in interfaces.ethernet
"25g-1": {
    description: "switch 10GE1/0/1",
    speed: "10g",
    trunk_vlans: ["mgmt", "home", "guests"],
    link: { device: "switch", port: "10g-1" },
},

The router still needs an address in each VLAN to be its gateway. With every VLAN on one port, those addresses go on a VLAN interface instead of a port. The DHCP lesson sets them up.

Discussion

Stuck, or found a mistake? Ask here. You sign in with GitHub.

Released under the Business Source License 1.1.