frame

package
v0.1.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package frame builds the Ethernet frames the examples transmit.

It exists so the examples stay small: what is being measured is the packet path, not packet construction, and a generator that spends its time here is measuring the wrong thing. A frame is built once and copied.

Index

Constants

View Source
const (
	EtherTypeIPv4 = 0x0800
	EtherTypeVLAN = 0x8100
	EtherTypeQinQ = 0x88a8

	// MinFrame is the shortest Ethernet frame, not counting the four-byte
	// frame check sequence the NIC appends.
	MinFrame = 60

	// FCS is what the NIC adds after the bytes handed to it, so a "64-byte
	// frame" is 60 bytes of ours.
	FCS = 4
)

Ethernet and IP constants used here.

Variables

This section is empty.

Functions

This section is empty.

Types

type Frame

type Frame struct {
	// Bytes is the frame, ready to transmit.
	Bytes []byte

	// SrcPortOff and DstPortOff are where the UDP ports are, and SrcIPOff and
	// DstIPOff where the addresses are. Changing an address means fixing two
	// checksums; changing a port means fixing one, or leaving it zero.
	SrcIPOff, DstIPOff     int
	SrcPortOff, DstPortOff int

	// VLANTags is how many tags the frame carries, which is what decides how
	// much of it a device in L2 inline mode must be shown.
	VLANTags int

	// HeaderLen is everything before the UDP payload.
	HeaderLen int
}

Frame is a built frame and the offsets of the fields worth changing between packets, so a generator can vary a flow without rebuilding anything.

func Build

func Build(s Spec) (*Frame, error)

Build lays out a frame.

func (*Frame) SetSrcPort

func (f *Frame) SetSrcPort(p uint16)

SetSrcPort changes the source port of a built frame in place. The UDP checksum stays zero, so nothing else has to be fixed. It is how a generator spreads traffic across a receiver's queues.

type Spec

type Spec struct {
	// SrcMAC and DstMAC are the Ethernet addresses. DstMAC must be the address
	// the far end will accept: with no switch learning involved, sending to a
	// made-up address usually means the frames are never seen again.
	SrcMAC, DstMAC net.HardwareAddr

	// VLAN is the tag to carry, or zero for untagged. Outer, if there are two.
	VLAN int

	// OuterVLAN, when set, makes the frame double tagged: OuterVLAN outside,
	// VLAN inside.
	OuterVLAN int

	// Priority is the priority code point in the tags.
	Priority int

	// SrcIP, DstIP, SrcPort and DstPort are the UDP flow.
	SrcIP, DstIP     netip.Addr
	SrcPort, DstPort uint16

	// Size is the whole frame length in bytes, not counting the frame check
	// sequence. 60 is the shortest legal frame and corresponds to what is
	// usually called a 64-byte packet.
	Size int
}

Spec describes a frame to build.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL