utils

package
v0.0.0-...-f275c47 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package utils provides testing utilities for balancer tests.

Index

Constants

View Source
const ICMPBroadcastIdent uint16 = 0x0BDC

ICMPBroadcastIdent is the magic value used to mark broadcasted packets This must match the value in modules/balancer/dataplane/icmp/error/broadcast.h

Variables

View Source
var (
	DeviceName   string = "01:00.0"
	PipelineName string = "pipeline0"
	FunctionName string = "function0"
	ChainName    string = "chain0"
	BalancerName string = "balancer0"
)

Functions

func AllPacketsToSameReal

func AllPacketsToSameReal(packets []*framework.PacketInfo) (netip.Addr, bool)

AllPacketsToSameReal checks if all packets went to the same real server. Returns the real server IP and true if all packets went to the same real, or empty addr and false otherwise.

func CountPacketsPerReal

func CountPacketsPerReal(packets []*framework.PacketInfo) map[netip.Addr]int

CountPacketsPerReal counts how many packets went to each real server. Returns a map from real server IP to packet count.

func EnableAllReals

func EnableAllReals(t *testing.T, ts *TestSetup)

EnableAllReals enables all real servers in the balancer configuration

func ExtractDestinationReal

func ExtractDestinationReal(packet *framework.PacketInfo) (netip.Addr, error)

ExtractDestinationReal extracts the destination IP (real server) from a tunneled packet. Returns the real server IP that the packet was forwarded to.

func InsertOrUpdateMSS

func InsertOrUpdateMSS(
	p gopacket.Packet,
	newMSS uint16,
) (*gopacket.Packet, error)

InsertOrUpdateMSS inserts or updates the MSS option in a TCP packet

func MakeICMPv4DestUnreachable

func MakeICMPv4DestUnreachable(
	srcIP netip.Addr,
	dstIP netip.Addr,
	originalPacket gopacket.Packet,
) []gopacket.SerializableLayer

MakeICMPv4DestUnreachable creates an ICMPv4 Destination Unreachable error packet containing the original packet that triggered the error

func MakeICMPv4DestUnreachableWithIdent

func MakeICMPv4DestUnreachableWithIdent(
	srcIP netip.Addr,
	dstIP netip.Addr,
	originalPacket gopacket.Packet,
	icmpIdent uint16,
) []gopacket.SerializableLayer

MakeICMPv4DestUnreachableWithIdent creates an ICMPv4 Destination Unreachable error packet with a custom icmp_ident value

func MakeICMPv4EchoRequest

func MakeICMPv4EchoRequest(
	srcIP netip.Addr,
	dstIP netip.Addr,
	id uint16,
	seq uint16,
) []gopacket.SerializableLayer

MakeICMPv4EchoRequest creates an ICMPv4 Echo Request packet

func MakeICMPv6DestUnreachable

func MakeICMPv6DestUnreachable(
	srcIP netip.Addr,
	dstIP netip.Addr,
	originalPacket gopacket.Packet,
) []gopacket.SerializableLayer

MakeICMPv6DestUnreachable creates an ICMPv6 Destination Unreachable error packet containing the original packet that triggered the error

func MakeICMPv6DestUnreachableWithIdent

func MakeICMPv6DestUnreachableWithIdent(
	srcIP netip.Addr,
	dstIP netip.Addr,
	originalPacket gopacket.Packet,
	icmpIdent uint16,
) []gopacket.SerializableLayer

MakeICMPv6DestUnreachableWithIdent creates an ICMPv6 Destination Unreachable error packet with a custom icmp_ident value

func MakeICMPv6EchoRequest

func MakeICMPv6EchoRequest(
	srcIP netip.Addr,
	dstIP netip.Addr,
	id uint16,
	seq uint16,
) []gopacket.SerializableLayer

MakeICMPv6EchoRequest creates an ICMPv6 Echo Request packet

func MakePacketLayers

func MakePacketLayers(
	srcIP netip.Addr,
	srcPort uint16,
	dstIP netip.Addr,
	dstPort uint16,
	tcp *layers.TCP,
) []gopacket.SerializableLayer

MakePacketLayers creates packet layers based on whether TCP or UDP is specified. If tcp is nil, creates a UDP packet; otherwise creates a TCP packet.

func MakeTCPPacket

func MakeTCPPacket(
	srcIP netip.Addr,
	srcPort uint16,
	dstIP netip.Addr,
	dstPort uint16,
	tcp *layers.TCP,
) []gopacket.SerializableLayer

MakeTCPPacket creates a TCP packet with the specified parameters. Supports both IPv4 and IPv6.

func MakeTunneledICMPv4DestUnreachable

func MakeTunneledICMPv4DestUnreachable(
	tunnelSrcIP netip.Addr,
	tunnelDstIP netip.Addr,
	icmpSrcIP netip.Addr,
	icmpDstIP netip.Addr,
	originalPacket gopacket.Packet,
	icmpIdent uint16,
) []gopacket.SerializableLayer

MakeTunneledICMPv4DestUnreachable creates an IP-in-IP tunneled ICMPv4 Destination Unreachable packet with a custom icmp_ident

func MakeTunneledICMPv6DestUnreachable

func MakeTunneledICMPv6DestUnreachable(
	tunnelSrcIP netip.Addr,
	tunnelDstIP netip.Addr,
	icmpSrcIP netip.Addr,
	icmpDstIP netip.Addr,
	originalPacket gopacket.Packet,
	icmpIdent uint16,
) []gopacket.SerializableLayer

MakeTunneledICMPv6DestUnreachable creates an IPv6-in-IPv6 tunneled ICMPv6 Destination Unreachable packet with a custom icmp_ident

func MakeUDPPacket

func MakeUDPPacket(
	srcIP netip.Addr,
	srcPort uint16,
	dstIP netip.Addr,
	dstPort uint16,
) []gopacket.SerializableLayer

MakeUDPPacket creates a UDP packet with the specified parameters. Supports both IPv4 and IPv6.

func PacketsDistributedAcrossReals

func PacketsDistributedAcrossReals(packets []*framework.PacketInfo) bool

PacketsDistributedAcrossReals checks if packets are distributed across multiple reals. Returns true if packets went to more than one real server.

func SingleWorkerMockConfig

func SingleWorkerMockConfig(
	cpMemory datasize.ByteSize,
	dpMemory datasize.ByteSize,
) *mock.YanetMockConfig

func ValidatePacket

func ValidatePacket(
	t *testing.T,
	config *balancerpb.BalancerConfig,
	originalGoPacket gopacket.Packet,
	resultPacket *framework.PacketInfo,
)

ValidatePacket validates that a packet has been properly processed by the balancer. It checks that the packet is tunneled and that the inner packet matches the original.

func ValidateWeightDistribution

func ValidateWeightDistribution(
	t *testing.T,
	counts map[netip.Addr]int,
	expectedWeights map[netip.Addr]uint32,
	tolerance float64,
)

ValidateWeightDistribution checks if packet distribution matches expected weights. Uses tolerance-based validation (e.g., 0.15 for 15% tolerance).

func VerifyBroadcastedICMPPacket

func VerifyBroadcastedICMPPacket(
	t *testing.T,
	packet *framework.PacketInfo,
	expectedDstIP net.IP,
)

VerifyBroadcastedICMPPacket checks that a broadcasted packet is properly tunneled and has the ICMP_BROADCAST_IDENT marker set

Types

type TestConfig

type TestConfig struct {
	Mock        *mock.YanetMockConfig
	Balancer    *balancerpb.BalancerConfig
	AgentMemory *datasize.ByteSize
}

type TestSetup

type TestSetup struct {
	Mock     *mock.YanetMock
	Agent    *balancer.BalancerAgent
	Balancer *balancer.BalancerManager
}

func Make

func Make(config *TestConfig) (*TestSetup, error)

func (*TestSetup) Free

func (ts *TestSetup) Free()

Jump to

Keyboard shortcuts

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