utils

package
v0.0.0-...-9ec6d29 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License: Apache-2.0, MIT Imports: 15 Imported by: 0

Documentation

Overview

Package utils holds common testing utilities for tcpip.

Index

Constants

View Source
const (
	Host1NICID   = 1
	RouterNICID1 = 2
	RouterNICID2 = 3
	Host2NICID   = 4
)

Common NIC IDs used by tests.

View Source
const (
	Host1NICName   = "host1NIC"
	RouterNIC1Name = "routerNIC1"
	RouterNIC2Name = "routerNIC2"
	Host2NICName   = "host2NIC"
)

Common NIC names used by tests.

View Source
const (
	LinkAddr1 = tcpip.LinkAddress("\x02\x03\x03\x04\x05\x06")
	LinkAddr2 = tcpip.LinkAddress("\x02\x03\x03\x04\x05\x07")
	LinkAddr3 = tcpip.LinkAddress("\x02\x03\x03\x04\x05\x08")
	LinkAddr4 = tcpip.LinkAddress("\x02\x03\x03\x04\x05\x09")
)

Common link addresses used by tests.

View Source
const (
	RemotePort = 5555
	LocalPort  = 80
)

Common ports for testing.

Variables

View Source
var (
	Ipv4Addr = tcpip.AddressWithPrefix{
		Address:   testutil.MustParse4("192.168.1.58"),
		PrefixLen: 24,
	}
	Ipv4Subnet      = Ipv4Addr.Subnet()
	Ipv4SubnetBcast = Ipv4Subnet.Broadcast()

	Ipv6Addr = tcpip.AddressWithPrefix{
		Address:   testutil.MustParse6("200a::1"),
		PrefixLen: 64,
	}
	Ipv6Subnet      = Ipv6Addr.Subnet()
	Ipv6SubnetBcast = Ipv6Subnet.Broadcast()

	Ipv4Addr1 = tcpip.ProtocolAddress{
		Protocol: ipv4.ProtocolNumber,
		AddressWithPrefix: tcpip.AddressWithPrefix{
			Address:   testutil.MustParse4("192.168.0.1"),
			PrefixLen: 24,
		},
	}
	Ipv4Addr2 = tcpip.ProtocolAddress{
		Protocol: ipv4.ProtocolNumber,
		AddressWithPrefix: tcpip.AddressWithPrefix{
			Address:   testutil.MustParse4("192.168.0.2"),
			PrefixLen: 8,
		},
	}
	Ipv4Addr3 = tcpip.ProtocolAddress{
		Protocol: ipv4.ProtocolNumber,
		AddressWithPrefix: tcpip.AddressWithPrefix{
			Address:   testutil.MustParse4("192.168.0.3"),
			PrefixLen: 8,
		},
	}
	Ipv6Addr1 = tcpip.ProtocolAddress{
		Protocol: ipv6.ProtocolNumber,
		AddressWithPrefix: tcpip.AddressWithPrefix{
			Address:   testutil.MustParse6("a::1"),
			PrefixLen: 64,
		},
	}
	Ipv6Addr2 = tcpip.ProtocolAddress{
		Protocol: ipv6.ProtocolNumber,
		AddressWithPrefix: tcpip.AddressWithPrefix{
			Address:   testutil.MustParse6("a::2"),
			PrefixLen: 64,
		},
	}
	Ipv6Addr3 = tcpip.ProtocolAddress{
		Protocol: ipv6.ProtocolNumber,
		AddressWithPrefix: tcpip.AddressWithPrefix{
			Address:   testutil.MustParse6("a::3"),
			PrefixLen: 64,
		},
	}

	// Remote addrs.
	RemoteIPv4Addr = testutil.MustParse4("10.0.0.1")
	RemoteIPv6Addr = testutil.MustParse6("200b::1")
)

Common IP addresses used by tests.

View Source
var (
	Host1IPv4Addr = tcpip.ProtocolAddress{
		Protocol: ipv4.ProtocolNumber,
		AddressWithPrefix: tcpip.AddressWithPrefix{
			Address:   testutil.MustParse4("192.168.0.2"),
			PrefixLen: 24,
		},
	}
	RouterNIC1IPv4Addr = tcpip.ProtocolAddress{
		Protocol: ipv4.ProtocolNumber,
		AddressWithPrefix: tcpip.AddressWithPrefix{
			Address:   testutil.MustParse4("192.168.0.1"),
			PrefixLen: 24,
		},
	}
	RouterNIC2IPv4Addr = tcpip.ProtocolAddress{
		Protocol: ipv4.ProtocolNumber,
		AddressWithPrefix: tcpip.AddressWithPrefix{
			Address:   testutil.MustParse4("10.0.0.3"),
			PrefixLen: 8,
		},
	}
	Host2IPv4Addr = tcpip.ProtocolAddress{
		Protocol: ipv4.ProtocolNumber,
		AddressWithPrefix: tcpip.AddressWithPrefix{
			Address:   testutil.MustParse4("10.0.0.2"),
			PrefixLen: 8,
		},
	}
	Host1IPv6Addr = tcpip.ProtocolAddress{
		Protocol: ipv6.ProtocolNumber,
		AddressWithPrefix: tcpip.AddressWithPrefix{
			Address:   testutil.MustParse6("a::2"),
			PrefixLen: 64,
		},
	}
	RouterNIC1IPv6Addr = tcpip.ProtocolAddress{
		Protocol: ipv6.ProtocolNumber,
		AddressWithPrefix: tcpip.AddressWithPrefix{
			Address:   testutil.MustParse6("a::1"),
			PrefixLen: 64,
		},
	}
	RouterNIC2IPv6Addr = tcpip.ProtocolAddress{
		Protocol: ipv6.ProtocolNumber,
		AddressWithPrefix: tcpip.AddressWithPrefix{
			Address:   testutil.MustParse6("b::1"),
			PrefixLen: 64,
		},
	}
	Host2IPv6Addr = tcpip.ProtocolAddress{
		Protocol: ipv6.ProtocolNumber,
		AddressWithPrefix: tcpip.AddressWithPrefix{
			Address:   testutil.MustParse6("b::2"),
			PrefixLen: 64,
		},
	}
)

Common IP addresses used for testing.

Functions

func ICMPv4Echo

func ICMPv4Echo(src, dst tcpip.Address, ttl uint8, ty header.ICMPv4Type) []byte

ICMPv4Echo returns an ICMPv4 echo packet.

func ICMPv6Echo

func ICMPv6Echo(src, dst tcpip.Address, ttl uint8, ty header.ICMPv6Type) []byte

ICMPv6Echo returns an ICMPv6 echo packet.

func RxICMPv4EchoReply

func RxICMPv4EchoReply(e *channel.Endpoint, src, dst tcpip.Address, ttl uint8)

RxICMPv4EchoReply constructs and injects an ICMPv4 echo reply packet on the provided endpoint.

func RxICMPv4EchoRequest

func RxICMPv4EchoRequest(e *channel.Endpoint, src, dst tcpip.Address, ttl uint8)

RxICMPv4EchoRequest constructs and injects an ICMPv4 echo request packet on the provided endpoint.

func RxICMPv6EchoReply

func RxICMPv6EchoReply(e *channel.Endpoint, src, dst tcpip.Address, ttl uint8)

RxICMPv6EchoReply constructs and injects an ICMPv6 echo reply packet on the provided endpoint.

func RxICMPv6EchoRequest

func RxICMPv6EchoRequest(e *channel.Endpoint, src, dst tcpip.Address, ttl uint8)

RxICMPv6EchoRequest constructs and injects an ICMPv6 echo request packet on the provided endpoint.

func SetupRoutedStacks

func SetupRoutedStacks(t *testing.T, host1Stack, routerStack, host2Stack *stack.Stack)

SetupRoutedStacks creates the NICs, sets forwarding, adds addresses and sets the route tables for the passed stacks.

func SetupRouterStack

func SetupRouterStack(t *testing.T, s *stack.Stack, ep1, ep2 stack.LinkEndpoint)

SetupRouterStack creates the NICs, sets forwarding, adds addresses and sets the route table for a stack that should operate as a router.

Types

type EndpointWithDestinationCheck

type EndpointWithDestinationCheck struct {
	nested.Endpoint
}

EndpointWithDestinationCheck is a link endpoint that checks the destination link address before delivering network packets to the network dispatcher.

func NewEthernetEndpoint

func NewEthernetEndpoint(ep stack.LinkEndpoint) *EndpointWithDestinationCheck

NewEthernetEndpoint returns an ethernet link endpoint that wraps an inner link endpoint and checks the destination link address before delivering network packets to the network dispatcher.

See ethernet.Endpoint for more details.

func (*EndpointWithDestinationCheck) DeliverNetworkPacket

DeliverNetworkPacket implements stack.NetworkDispatcher.

Jump to

Keyboard shortcuts

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